From 04831581277d488d3b1c63f061f108926e978e63 Mon Sep 17 00:00:00 2001 From: sdhsdh Date: Fri, 11 Sep 2009 21:44:25 +0000 Subject: [PATCH] - fix last nits needed to compile - a few bug-fixes --- apps/UDPEcho/UDPEchoC.nc | 2 ++ support/make/blip.extra | 3 +- support/sdk/c/blip/lib6lowpan/6lowpan.h | 7 +++- support/sdk/c/blip/lib6lowpan/ip.h | 4 ++- support/sdk/c/blip/lib6lowpan/lib6lowpanIP.c | 10 +++--- tos/lib/net/blip/ICMPResponderP.nc | 36 ++++++++++++-------- tos/lib/net/blip/IPRoutingP.nc | 34 ++++++++++++------ 7 files changed, 63 insertions(+), 33 deletions(-) diff --git a/apps/UDPEcho/UDPEchoC.nc b/apps/UDPEcho/UDPEchoC.nc index 984f55d9..8cc47ab9 100644 --- a/apps/UDPEcho/UDPEchoC.nc +++ b/apps/UDPEcho/UDPEchoC.nc @@ -21,7 +21,9 @@ */ #include <6lowpan.h> +#ifdef DBG_TRACK_FLOWS #include "TestDriver.h" +#endif configuration UDPEchoC { diff --git a/support/make/blip.extra b/support/make/blip.extra index 06c0c7f6..ae486254 100644 --- a/support/make/blip.extra +++ b/support/make/blip.extra @@ -10,7 +10,8 @@ endif PFLAGS+=-DENABLE_SPI0_DMA -PFLAGS+=-I$(LOWPAN_ROOT)/support/sdk/c/blip/include/ +PFLAGS+=-I$(TOSROOT)/tos/lib/net/ +PFLAGS+=-I$(LOWPAN_ROOT)/support/sdk/c/blip/lib6lowpan/ PFLAGS+=-I$(LOWPAN_ROOT)/support/sdk/c/blip/libtcp/ PFLAGS+=-I$(LOWPAN_ROOT)/tos/lib/net/blip/ PFLAGS+=-I$(LOWPAN_ROOT)/tos/lib/net/blip/interfaces/ diff --git a/support/sdk/c/blip/lib6lowpan/6lowpan.h b/support/sdk/c/blip/lib6lowpan/6lowpan.h index 81056fe0..c93d6cf3 100644 --- a/support/sdk/c/blip/lib6lowpan/6lowpan.h +++ b/support/sdk/c/blip/lib6lowpan/6lowpan.h @@ -38,6 +38,7 @@ typedef uint8_t ip6_addr_t [16]; typedef uint16_t cmpr_ip6_addr_t; #ifdef PC +#include "../config.h" typedef uint16_t ieee154_saddr_t; typedef uint16_t hw_pan_t; enum { @@ -189,7 +190,11 @@ enum { }; #ifndef BLIP_L2_RETRIES -#define BLIP_L2_RETRIES 10 +#define BLIP_L2_RETRIES 5 +#endif + +#ifndef BLIP_L2_DELAY +#define BLIP_L2_DELAY 15 #endif #endif diff --git a/support/sdk/c/blip/lib6lowpan/ip.h b/support/sdk/c/blip/lib6lowpan/ip.h index 666cc1f2..87006255 100644 --- a/support/sdk/c/blip/lib6lowpan/ip.h +++ b/support/sdk/c/blip/lib6lowpan/ip.h @@ -152,6 +152,7 @@ enum { // option message. TLV_TYPE_INSTALL = 0x0b, TLV_TYPE_FLOW = 0x0c, + TLV_TYPE_MCASTSEQ = 0x0d, }; struct ip6_route { @@ -298,7 +299,8 @@ struct generic_header { }; enum { - IP_NOHEADERS = 1, + IP_NOHEADERS = 1 << 0, + IP_MCAST = 1 << 1, }; struct split_ip_msg { diff --git a/support/sdk/c/blip/lib6lowpan/lib6lowpanIP.c b/support/sdk/c/blip/lib6lowpan/lib6lowpanIP.c index 54a70e89..2cf73577 100644 --- a/support/sdk/c/blip/lib6lowpan/lib6lowpanIP.c +++ b/support/sdk/c/blip/lib6lowpan/lib6lowpanIP.c @@ -30,7 +30,6 @@ */ uint8_t linklocal_prefix [] = {0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; -uint8_t multicast_prefix [] = {0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; struct in6_addr __my_address = {{{0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x65}}}; @@ -134,8 +133,10 @@ static inline int decompressShortAddress(uint8_t dispatch, uint8_t *s_addr, uint } // otherwise we either have an invalid compression, or else it's a // multicast address - ip_memcpy(dest, multicast_prefix, 8); - ip_memclr(dest + 8, 8); + // ip_memcpy(dest, multicast_prefix, 8); + ip_memclr(dest, 16); + dest[0] = 0xff; + dest[1] = 0x02; switch (*s_addr & LOWPAN_IPHC_SHORT_LONG_MASK) { case LOWPAN_IPHC_HC1_MCAST: dest[14] = (*s_addr) & ~LOWPAN_IPHC_SHORT_LONG_MASK; @@ -483,7 +484,8 @@ uint8_t packHeaders(struct split_ip_msg *msg, } nxt_hdr = hdr->nxt_hdr; - if (hdr->nxt_hdr == IANA_UDP /* or other compressed values... */) { + if (hdr->nxt_hdr == IANA_UDP && /* or other compressed values... */ + msg->headers != NULL) { // we will add the HCNH encoding at the end of the header *encoding |= LOWPAN_IPHC_NH_MASK; } else { diff --git a/tos/lib/net/blip/ICMPResponderP.nc b/tos/lib/net/blip/ICMPResponderP.nc index 5f2f0187..3975c1b4 100644 --- a/tos/lib/net/blip/ICMPResponderP.nc +++ b/tos/lib/net/blip/ICMPResponderP.nc @@ -58,10 +58,9 @@ module ICMPResponderP { uint16_t ping_seq, ping_n, ping_rcv, ping_ident; struct in6_addr ping_dest; -#ifndef SIM -#define CHECK_NODE_ID -#else -#define CHECK_NODE_ID if (TOS_NODE_ID == BASESTATION_ID) return +#ifdef PRINTFUART_ENABLED +#undef dbg +#define dbg(X, fmt, args ...) printfUART(fmt, ## args) #endif command uint16_t ICMP.cksum(struct split_ip_msg *msg, uint8_t nxt_hdr) { @@ -71,7 +70,6 @@ module ICMPResponderP { command void ICMP.sendSolicitations() { uint16_t jitter = (call Random.rand16()) % TRICKLE_JITTER; - CHECK_NODE_ID; if (call Solicitation.isRunning()) return; solicitation_period = TRICKLE_PERIOD; call Solicitation.startOneShot(jitter); @@ -81,7 +79,6 @@ module ICMPResponderP { uint16_t jitter = (call Random.rand16()) % TRICKLE_JITTER; - CHECK_NODE_ID; if (call Advertisement.isRunning()) return; advertisement_period = TRICKLE_PERIOD; call Advertisement.startOneShot(jitter); @@ -156,8 +153,7 @@ module ICMPResponderP { if (ipmsg == NULL) return; - dbg("ICMPResponder", "Solicitation\n"); - //BLIP_STATS_INCR(stats.sol_tx); + BLIP_STATS_INCR(stats.sol_tx); msg->type = ICMP_TYPE_ROUTER_SOL; msg->code = 0; @@ -244,7 +240,7 @@ module ICMPResponderP { } - dbg("ICMPResponder", " * beacon cost: 0x%x\n", cost); + dbg("ICMPResponder", " * beacon cost: 0x%x\n", beacon->metric); } else { dbg("ICMPResponder", " * no beacon cost\n"); } @@ -269,6 +265,7 @@ module ICMPResponderP { ip_free(ipmsg); return; } + BLIP_STATS_INCR(stats.adv_tx); r->type = ICMP_TYPE_ROUTER_ADV; r->code = 0; @@ -332,14 +329,15 @@ module ICMPResponderP { switch (req->type) { case ICMP_TYPE_ROUTER_ADV: - handleRouterAdv(payload, len, meta); - //BLIP_STATS_INCR(stats.adv_rx); - break; + handleRouterAdv(payload, len, meta); + BLIP_STATS_INCR(stats.adv_rx); + break; case ICMP_TYPE_ROUTER_SOL: // only reply to solicitations if we have established a default route. if (call IPRouting.hasRoute()) { call ICMP.sendAdvertisements(); } + BLIP_STATS_INCR(stats.sol_rx); break; case ICMP_TYPE_ECHO_REPLY: { @@ -350,6 +348,7 @@ module ICMPResponderP { p_stat.rtt = (call LocalTime.get()) - (*sendTime); signal ICMPPing.pingReply[req->ident](&iph->ip6_src, &p_stat); ping_rcv++; + BLIP_STATS_INCR(stats.echo_rx); } break; case ICMP_TYPE_ECHO_REQUEST: @@ -359,7 +358,11 @@ module ICMPResponderP { msg.headers = NULL; msg.data = payload; msg.data_len = len; - call IPAddress.getIPAddr(&msg.hdr.ip6_src); + if (iph->ip6_src.s6_addr[0] == 0xfe) { + call IPAddress.getLLAddr(&msg.hdr.ip6_src); + } else { + call IPAddress.getIPAddr(&msg.hdr.ip6_src); + } memcpy(&msg.hdr.ip6_dst, &iph->ip6_src, 16); req->type = ICMP_TYPE_ECHO_REPLY; @@ -369,15 +372,18 @@ module ICMPResponderP { // remember, this can't really fail in a way we care about call IP.send(&msg); + BLIP_STATS_INCR(stats.echo_tx); break; } + default: + BLIP_STATS_INCR(stats.unk_rx); } } event void Solicitation.fired() { sendSolicitation(); - dbg("ICMPResponder", "solicitation period: 0x%x max: 0x%x\n", solicitation_period, TRICKLE_MAX); + dbg("ICMPResponder", "solicitation period: 0x%x max: 0x%x seq: %i\n", solicitation_period, TRICKLE_MAX, nd_seqno); solicitation_period <<= 1; if (solicitation_period < TRICKLE_MAX) { call Solicitation.startOneShot(solicitation_period); @@ -423,7 +429,7 @@ module ICMPResponderP { command void Statistics.get(icmp_statistics_t *statistics) { - statistics = &stats; + memcpy(statistics, &stats, sizeof(icmp_statistics_t)); } command void Statistics.clear() { diff --git a/tos/lib/net/blip/IPRoutingP.nc b/tos/lib/net/blip/IPRoutingP.nc index a348d7f0..10ed1b0f 100644 --- a/tos/lib/net/blip/IPRoutingP.nc +++ b/tos/lib/net/blip/IPRoutingP.nc @@ -44,8 +44,8 @@ module IPRoutingP { } implementation { #ifdef PRINTFUART_ENABLED -/* #undef dbg */ -/* #define dbg(X, fmt, args...) printfUART(fmt, ## args) */ +// #undef dbg +// #define dbg(X, fmt, args...) printfUART(fmt, ## args) #endif enum { @@ -127,9 +127,12 @@ module IPRoutingP { event void TrafficGenTimer.fired() { struct split_ip_msg *msg; if (traffic_sent) goto done; - traffic_sent = FALSE; msg = (struct split_ip_msg *)ip_malloc(sizeof(struct split_ip_msg)); - if (msg == NULL) goto done; + if (msg == NULL) { + printfUART("malloc fail\n"); + goto done; + } + traffic_sent = FALSE; ip_memclr((uint8_t *)&msg->hdr, sizeof(struct ip6_hdr)); inet_pton6("ff05::1", &msg->hdr.ip6_dst); @@ -204,9 +207,11 @@ module IPRoutingP { // me. struct in6_addr *my_address = call IPAddress.getPublicAddr(); return (((cmpPfx(my_address->s6_addr, hdr->ip6_dst.s6_addr) || - cmpPfx(linklocal_prefix, hdr->ip6_dst.s6_addr)) - && cmpPfx(&my_address->s6_addr[8], &hdr->ip6_dst.s6_addr[8])) - || cmpPfx(multicast_prefix, hdr->ip6_dst.s6_addr)); + cmpPfx(linklocal_prefix, hdr->ip6_dst.s6_addr)) && + cmpPfx(&my_address->s6_addr[8], &hdr->ip6_dst.s6_addr[8])) || + (hdr->ip6_dst.s6_addr[0] == 0xff && + (hdr->ip6_dst.s6_addr[1] & 0x0f) <= 3)) +; } #ifdef CENTRALIZED_ROUTING @@ -783,8 +788,8 @@ module IPRoutingP { struct flow_entry *r = getFlowEntry_Header(hdr); #endif prev_hop = 0; - ret->retries = N_RETRIES;; - ret->delay = 30; + ret->retries = BLIP_L2_RETRIES; + ret->delay = (BLIP_L2_DELAY % (call Random.rand16())) + BLIP_L2_DELAY; ret->current = 0; ret->nchoices = 0; @@ -808,7 +813,8 @@ module IPRoutingP { ret->dest[0] = ntohs(sh->hops[ROUTE_NENTRIES(sh) - sh->segs_remain]); ret->nchoices = 1; - } else if (hdr->ip6_dst.s6_addr16[0] == htons(0xff02)) { + } else if (hdr->ip6_dst.s6_addr[0] == 0xff && + (hdr->ip6_dst.s6_addr[1] & 0xf) <= 0x03) { //hdr->dst_addr[0] == 0xff && (hdr->dst_addr[1] & 0xf) == 0x2) { // if it's multicast, for now, we send it to the local broadcast ret->dest[0] = 0xffff; @@ -1165,6 +1171,11 @@ module IPRoutingP { tlv->len = sizeof(struct tlv_hdr) + sizeof(struct topology_header); tlv->type = TLV_TYPE_TOPOLOGY; + if (iph->ip6_dst.s6_addr[0] == 0xff && + (iph->ip6_dst.s6_addr[1] & 0xf) <= 3) { + return NULL; + } + printfUART("inserting destination options header\n"); // AT: We theoretically only want to attach this topology header if we're @@ -1175,7 +1186,8 @@ module IPRoutingP { // only attach the topology information if we are. This still isn't // perfect since somebody further down the tree may have a route and the // packet might not get to the controller. - if (iph->nxt_hdr == IANA_UDP || iph->nxt_hdr == IPV6_NONEXT) { + if (iph->nxt_hdr == IANA_UDP || + iph->nxt_hdr == IPV6_NONEXT) { int i,j = 0; if (iph->ip6_dst.s6_addr16[0] == htons(0xff02)) return NULL; if (traffic_sent) return NULL; -- 2.39.2