]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - tos/lib/net/blip/IPAddressP.nc
- update blip source address setting to be more generic
[tinyos-2.x.git] / tos / lib / net / blip / IPAddressP.nc
index 68b10cb1084b45c8a60f8b2b1730856036057103..0a9bda97af36ba6ffe40fffe94110fe23cff24ac 100644 (file)
@@ -76,6 +76,30 @@ module IPAddressP {
     return globalPrefix;
   }
 
+  command void IPAddress.setSource(struct ip6_hdr *hdr) {
+    enum { LOCAL, GLOBAL } type = GLOBAL;
+      
+    if (hdr->ip6_dst.s6_addr[0] == 0xff) {
+      // link-local multicast sent from local address
+      if ((hdr->ip6_dst.s6_addr[1] & 0x0f) <= 0x2) {
+        type = LOCAL;
+      }
+    } else if (hdr->ip6_dst.s6_addr[0] == 0xfe) {
+      // link-local destinations sent from link-local
+      if ((hdr->ip6_dst.s6_addr[1] & 0xf0) <= 0x80) {
+        type = LOCAL;
+      }
+    }
+
+    if (type == GLOBAL && call IPAddress.haveAddress()) {
+      call IPAddress.getIPAddr(&hdr->ip6_src);
+    } else {
+      call IPAddress.getLLAddr(&hdr->ip6_src);
+    }
+
+  }
+
+
 #ifndef SIM
   async event void ActiveMessageAddress.changed() {