58 #include "contiki-conf.h"
63 #ifdef AODV_COMPLIANCE
129 #define BUF ((struct tcpip_hdr *)&uip_buf[UIP_LLH_LEN])
134 #define ICMPBUF ((struct icmpip_hdr *)&uip_buf[UIP_LLH_LEN])
140 struct fwcache_entry {
153 #if UIP_REASSEMBLY > 0
161 #ifdef UIP_CONF_FWCACHE_SIZE
162 #define FWCACHE_SIZE UIP_CONF_FWCACHE_SIZE
164 #define FWCACHE_SIZE 2
172 static struct fwcache_entry fwcache[FWCACHE_SIZE];
190 while(netifs !=
NULL) {
192 netifs = netifs->
next;
214 return (ipaddr->u16[0] & netmask->u16[0]) == (netipaddr->u16[0] & netmask->u16[0]) &&
215 (ipaddr->u16[1] & netmask->u16[1]) == (netipaddr->u16[1] & netmask->u16[1]);
231 if(ICMPBUF->proto == UIP_PROTO_ICMP &&
232 ICMPBUF->type != ICMP_ECHO) {
237 memcpy(&(ICMPBUF->payload[0]), ICMPBUF, UIP_IPH_LEN + 8);
240 ICMPBUF->type = ICMP_TE;
244 ICMPBUF->icmpchksum = 0;
245 ICMPBUF->icmpchksum = ~
uip_chksum((u16_t *)&(ICMPBUF->type), 36);
263 ICMPBUF->ipoffset[0] = ICMPBUF->ipoffset[1] = 0;
265 ICMPBUF->proto = UIP_PROTO_ICMP;
268 ICMPBUF->ipchksum = 0;
281 fwcache_register(
void)
283 struct fwcache_entry *fw;
290 for(i = 0; i < FWCACHE_SIZE; ++i) {
291 if(fwcache[i].
timer == 0) {
294 }
else if(fwcache[i].
timer <= oldest) {
296 oldest = fwcache[i].timer;
301 fw->ipid = BUF->ipid;
304 fw->proto = BUF->proto;
306 fw->payload[0] = BUF->srcport;
307 fw->payload[1] = BUF->destport;
309 #if UIP_REASSEMBLY > 0
311 fw->offset = BUF->ipoffset;
326 for(netif = netifs; netif !=
NULL; netif = netif->
next) {
327 if(ipaddr_maskcmp(&BUF->destipaddr, &netif->
ipaddr,
359 const struct uip_udpip_hdr *udp = (
void *)BUF;
371 if(defaultnetif !=
NULL) {
374 for(netif = netifs; netif !=
NULL; netif = netif->
next) {
381 netif = find_netif();
406 struct fwcache_entry *fw;
414 #ifdef AODV_COMPLIANCE
415 #define udp ((struct uip_udpip_hdr *)&uip_buf[UIP_LLH_LEN])
416 if(udp->proto == UIP_PROTO_UDP && udp->destport ==
UIP_HTONS(UAODV_UDPPORT)) {
425 BUF->proto == UIP_PROTO_ICMP &&
426 ICMPBUF->type == ICMP_ECHO) {
434 for(fw = fwcache; fw < &fwcache[FWCACHE_SIZE]; ++fw) {
437 fw->len == BUF->len &&
438 fw->offset == BUF->ipoffset &&
440 fw->ipid == BUF->ipid &&
444 fw->payload[0] == BUF->srcport &&
445 fw->payload[1] == BUF->destport &&
447 fw->proto == BUF->proto) {
466 BUF->ttl = BUF->ttl - 1;
469 if(BUF->ipchksum >=
UIP_HTONS(0xffff - 0x0100)) {
470 BUF->ipchksum = BUF->ipchksum +
UIP_HTONS(0x0100) + 1;
472 BUF->ipchksum = BUF->ipchksum +
UIP_HTONS(0x0100);
501 netif->
next = netifs;
518 defaultnetif = netif;
528 struct fwcache_entry *fw;
529 for(fw = fwcache; fw < &fwcache[FWCACHE_SIZE]; ++fw) {