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
ip6/slaac.c@151:bde6f7da1755, 2019-07-19 (annotated)
- Committer:
- andrewboyson
- Date:
- Fri Jul 19 17:48:06 2019 +0000
- Revision:
- 151:bde6f7da1755
- Parent:
- 80:4ef1500fca1d
- Child:
- 172:9bc3c7b2cca1
Removed private key and certificate from semihost storage as found to be unreliable (though secure) and moved it into flash storage (reliable, simple, but visible on mbed.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
andrewboyson | 61:aad055f1b0d1 | 1 | #include <string.h> |
andrewboyson | 61:aad055f1b0d1 | 2 | |
andrewboyson | 80:4ef1500fca1d | 3 | #include "mac.h" |
andrewboyson | 49:1a6336f2b3f9 | 4 | #include "ip6addr.h" |
andrewboyson | 7:b794780e33b4 | 5 | |
andrewboyson | 7:b794780e33b4 | 6 | char SlaacLinkLocalIp[16]; |
andrewboyson | 15:6ca6778168b1 | 7 | char SlaacGlobalIp[16]; |
andrewboyson | 7:b794780e33b4 | 8 | |
andrewboyson | 44:83ce5ace337b | 9 | int SlaacScope(char* ip) |
andrewboyson | 35:93c39d260a83 | 10 | { |
andrewboyson | 49:1a6336f2b3f9 | 11 | if (Ip6AddressIsSame(ip, SlaacLinkLocalIp)) return SCOPE_LOCAL; |
andrewboyson | 49:1a6336f2b3f9 | 12 | if (Ip6AddressIsSame(ip, SlaacGlobalIp )) return SCOPE_GLOBAL; |
andrewboyson | 44:83ce5ace337b | 13 | return SCOPE_NONE; |
andrewboyson | 35:93c39d260a83 | 14 | } |
andrewboyson | 49:1a6336f2b3f9 | 15 | void SlaacAddressFromScope(int scope, char* pSrcIp) |
andrewboyson | 49:1a6336f2b3f9 | 16 | { |
andrewboyson | 49:1a6336f2b3f9 | 17 | if (scope == SCOPE_GLOBAL) Ip6AddressCopy(pSrcIp, SlaacGlobalIp ); |
andrewboyson | 49:1a6336f2b3f9 | 18 | else Ip6AddressCopy(pSrcIp, SlaacLinkLocalIp); |
andrewboyson | 49:1a6336f2b3f9 | 19 | //Note that scope could be SCOPE_NONE if source was multicast in which case should return the link local ip. |
andrewboyson | 49:1a6336f2b3f9 | 20 | } |
andrewboyson | 49:1a6336f2b3f9 | 21 | |
andrewboyson | 15:6ca6778168b1 | 22 | void SlaacMakeGlobal(char* pPrefix) |
andrewboyson | 15:6ca6778168b1 | 23 | { |
andrewboyson | 15:6ca6778168b1 | 24 | memcpy(SlaacGlobalIp, pPrefix, 8); |
andrewboyson | 15:6ca6778168b1 | 25 | char* p = SlaacGlobalIp + 8; |
andrewboyson | 15:6ca6778168b1 | 26 | *p++ = MacLocal[0] | 0x02; //Modified EUI-64 |
andrewboyson | 15:6ca6778168b1 | 27 | *p++ = MacLocal[1]; |
andrewboyson | 15:6ca6778168b1 | 28 | *p++ = MacLocal[2]; |
andrewboyson | 15:6ca6778168b1 | 29 | *p++ = 0xFF; |
andrewboyson | 15:6ca6778168b1 | 30 | *p++ = 0xFE; |
andrewboyson | 15:6ca6778168b1 | 31 | *p++ = MacLocal[3]; |
andrewboyson | 15:6ca6778168b1 | 32 | *p++ = MacLocal[4]; |
andrewboyson | 15:6ca6778168b1 | 33 | *p++ = MacLocal[5]; |
andrewboyson | 15:6ca6778168b1 | 34 | |
andrewboyson | 15:6ca6778168b1 | 35 | } |
andrewboyson | 7:b794780e33b4 | 36 | void SlaacInit() |
andrewboyson | 7:b794780e33b4 | 37 | { |
andrewboyson | 37:793b39683406 | 38 | char* p = SlaacLinkLocalIp; //fe80::::202:f7ff:fef2:7d27 |
andrewboyson | 7:b794780e33b4 | 39 | *p++ = 0xFE; |
andrewboyson | 7:b794780e33b4 | 40 | *p++ = 0x80; |
andrewboyson | 7:b794780e33b4 | 41 | *p++ = 0x00; |
andrewboyson | 7:b794780e33b4 | 42 | *p++ = 0x00; |
andrewboyson | 7:b794780e33b4 | 43 | *p++ = 0x00; |
andrewboyson | 7:b794780e33b4 | 44 | *p++ = 0x00; |
andrewboyson | 7:b794780e33b4 | 45 | *p++ = 0x00; |
andrewboyson | 7:b794780e33b4 | 46 | *p++ = 0x00; |
andrewboyson | 13:9cd54f7db57a | 47 | *p++ = MacLocal[0] | 0x02; //Modified EUI-64 |
andrewboyson | 13:9cd54f7db57a | 48 | *p++ = MacLocal[1]; |
andrewboyson | 13:9cd54f7db57a | 49 | *p++ = MacLocal[2]; |
andrewboyson | 7:b794780e33b4 | 50 | *p++ = 0xFF; |
andrewboyson | 7:b794780e33b4 | 51 | *p++ = 0xFE; |
andrewboyson | 13:9cd54f7db57a | 52 | *p++ = MacLocal[3]; |
andrewboyson | 13:9cd54f7db57a | 53 | *p++ = MacLocal[4]; |
andrewboyson | 13:9cd54f7db57a | 54 | *p++ = MacLocal[5]; |
andrewboyson | 7:b794780e33b4 | 55 | } |