A stack which works with or without an Mbed os library. Provides IPv4 or IPv6 with a full 1500 byte buffer.

Dependents:   oldheating gps motorhome heating

Revision:
61:aad055f1b0d1
Parent:
49:1a6336f2b3f9
Child:
80:4ef1500fca1d
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ip6/slaac.c	Thu Jan 11 17:38:21 2018 +0000
@@ -0,0 +1,55 @@
+#include <string.h>
+
+#include  "mac.h"
+#include "ip6addr.h"
+
+char SlaacLinkLocalIp[16];
+char SlaacGlobalIp[16];
+
+int SlaacScope(char* ip)
+{
+    if (Ip6AddressIsSame(ip, SlaacLinkLocalIp)) return SCOPE_LOCAL;
+    if (Ip6AddressIsSame(ip, SlaacGlobalIp   )) return SCOPE_GLOBAL;
+    return SCOPE_NONE;
+}
+void SlaacAddressFromScope(int scope, char* pSrcIp)
+{
+    if (scope == SCOPE_GLOBAL) Ip6AddressCopy(pSrcIp, SlaacGlobalIp   );
+    else                       Ip6AddressCopy(pSrcIp, SlaacLinkLocalIp);
+    //Note that scope could be SCOPE_NONE if source was multicast in which case should return the link local ip.
+}
+
+void SlaacMakeGlobal(char* pPrefix)
+{
+    memcpy(SlaacGlobalIp, pPrefix, 8);
+    char* p = SlaacGlobalIp + 8;
+    *p++ = MacLocal[0] | 0x02; //Modified EUI-64
+    *p++ = MacLocal[1];
+    *p++ = MacLocal[2];
+    *p++ = 0xFF;
+    *p++ = 0xFE;
+    *p++ = MacLocal[3];
+    *p++ = MacLocal[4];
+    *p++ = MacLocal[5];
+    
+}
+void SlaacInit()
+{
+    char* p = SlaacLinkLocalIp; //fe80::::202:f7ff:fef2:7d27
+    *p++ = 0xFE;
+    *p++ = 0x80;
+    *p++ = 0x00;
+    *p++ = 0x00;
+    *p++ = 0x00;
+    *p++ = 0x00;
+    *p++ = 0x00;
+    *p++ = 0x00;
+    *p++ = MacLocal[0] | 0x02; //Modified EUI-64
+    *p++ = MacLocal[1];
+    *p++ = MacLocal[2];
+    *p++ = 0xFF;
+    *p++ = 0xFE;
+    *p++ = MacLocal[3];
+    *p++ = MacLocal[4];
+    *p++ = MacLocal[5];
+}
\ No newline at end of file