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@200:5acbc41bf469, 2021-05-20 (annotated)
- Committer:
- andrewboyson
- Date:
- Thu May 20 14:32:52 2021 +0000
- Revision:
- 200:5acbc41bf469
- Parent:
- 172:9bc3c7b2cca1
Increased number of arp entries from 20 to 30 to accommodate the number of WIZ devices plus a few incoming port 80 calls from the internet.
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 | 172:9bc3c7b2cca1 | 7 | char SlaacUniqueLocalIp[16]; |
andrewboyson | 15:6ca6778168b1 | 8 | char SlaacGlobalIp[16]; |
andrewboyson | 7:b794780e33b4 | 9 | |
andrewboyson | 44:83ce5ace337b | 10 | int SlaacScope(char* ip) |
andrewboyson | 35:93c39d260a83 | 11 | { |
andrewboyson | 172:9bc3c7b2cca1 | 12 | if (Ip6AddrIsSame(ip, SlaacLinkLocalIp)) return SCOPE_LINK_LOCAL; |
andrewboyson | 172:9bc3c7b2cca1 | 13 | if (Ip6AddrIsSame(ip, SlaacGlobalIp )) return SCOPE_GLOBAL; |
andrewboyson | 44:83ce5ace337b | 14 | return SCOPE_NONE; |
andrewboyson | 35:93c39d260a83 | 15 | } |
andrewboyson | 49:1a6336f2b3f9 | 16 | void SlaacAddressFromScope(int scope, char* pSrcIp) |
andrewboyson | 49:1a6336f2b3f9 | 17 | { |
andrewboyson | 172:9bc3c7b2cca1 | 18 | switch (scope) |
andrewboyson | 172:9bc3c7b2cca1 | 19 | { |
andrewboyson | 172:9bc3c7b2cca1 | 20 | case SCOPE_GLOBAL: Ip6AddrCopy(pSrcIp, SlaacGlobalIp ); break; |
andrewboyson | 172:9bc3c7b2cca1 | 21 | case SCOPE_UNIQUE_LOCAL: Ip6AddrCopy(pSrcIp, SlaacUniqueLocalIp); break; |
andrewboyson | 172:9bc3c7b2cca1 | 22 | default: Ip6AddrCopy(pSrcIp, SlaacLinkLocalIp ); break; |
andrewboyson | 172:9bc3c7b2cca1 | 23 | } |
andrewboyson | 49:1a6336f2b3f9 | 24 | //Note that scope could be SCOPE_NONE if source was multicast in which case should return the link local ip. |
andrewboyson | 49:1a6336f2b3f9 | 25 | } |
andrewboyson | 49:1a6336f2b3f9 | 26 | |
andrewboyson | 15:6ca6778168b1 | 27 | void SlaacMakeGlobal(char* pPrefix) |
andrewboyson | 15:6ca6778168b1 | 28 | { |
andrewboyson | 15:6ca6778168b1 | 29 | memcpy(SlaacGlobalIp, pPrefix, 8); |
andrewboyson | 15:6ca6778168b1 | 30 | char* p = SlaacGlobalIp + 8; |
andrewboyson | 15:6ca6778168b1 | 31 | *p++ = MacLocal[0] | 0x02; //Modified EUI-64 |
andrewboyson | 15:6ca6778168b1 | 32 | *p++ = MacLocal[1]; |
andrewboyson | 15:6ca6778168b1 | 33 | *p++ = MacLocal[2]; |
andrewboyson | 15:6ca6778168b1 | 34 | *p++ = 0xFF; |
andrewboyson | 15:6ca6778168b1 | 35 | *p++ = 0xFE; |
andrewboyson | 15:6ca6778168b1 | 36 | *p++ = MacLocal[3]; |
andrewboyson | 15:6ca6778168b1 | 37 | *p++ = MacLocal[4]; |
andrewboyson | 15:6ca6778168b1 | 38 | *p++ = MacLocal[5]; |
andrewboyson | 15:6ca6778168b1 | 39 | |
andrewboyson | 15:6ca6778168b1 | 40 | } |
andrewboyson | 172:9bc3c7b2cca1 | 41 | void SlaacMakeUniqueLocal(char* pPrefix) |
andrewboyson | 172:9bc3c7b2cca1 | 42 | { |
andrewboyson | 172:9bc3c7b2cca1 | 43 | memcpy(SlaacUniqueLocalIp, pPrefix, 8); |
andrewboyson | 172:9bc3c7b2cca1 | 44 | char* p = SlaacUniqueLocalIp + 8; |
andrewboyson | 172:9bc3c7b2cca1 | 45 | *p++ = MacLocal[0] | 0x02; //Modified EUI-64 |
andrewboyson | 172:9bc3c7b2cca1 | 46 | *p++ = MacLocal[1]; |
andrewboyson | 172:9bc3c7b2cca1 | 47 | *p++ = MacLocal[2]; |
andrewboyson | 172:9bc3c7b2cca1 | 48 | *p++ = 0xFF; |
andrewboyson | 172:9bc3c7b2cca1 | 49 | *p++ = 0xFE; |
andrewboyson | 172:9bc3c7b2cca1 | 50 | *p++ = MacLocal[3]; |
andrewboyson | 172:9bc3c7b2cca1 | 51 | *p++ = MacLocal[4]; |
andrewboyson | 172:9bc3c7b2cca1 | 52 | *p++ = MacLocal[5]; |
andrewboyson | 172:9bc3c7b2cca1 | 53 | |
andrewboyson | 172:9bc3c7b2cca1 | 54 | } |
andrewboyson | 7:b794780e33b4 | 55 | void SlaacInit() |
andrewboyson | 7:b794780e33b4 | 56 | { |
andrewboyson | 37:793b39683406 | 57 | char* p = SlaacLinkLocalIp; //fe80::::202:f7ff:fef2:7d27 |
andrewboyson | 7:b794780e33b4 | 58 | *p++ = 0xFE; |
andrewboyson | 7:b794780e33b4 | 59 | *p++ = 0x80; |
andrewboyson | 7:b794780e33b4 | 60 | *p++ = 0x00; |
andrewboyson | 7:b794780e33b4 | 61 | *p++ = 0x00; |
andrewboyson | 7:b794780e33b4 | 62 | *p++ = 0x00; |
andrewboyson | 7:b794780e33b4 | 63 | *p++ = 0x00; |
andrewboyson | 7:b794780e33b4 | 64 | *p++ = 0x00; |
andrewboyson | 7:b794780e33b4 | 65 | *p++ = 0x00; |
andrewboyson | 13:9cd54f7db57a | 66 | *p++ = MacLocal[0] | 0x02; //Modified EUI-64 |
andrewboyson | 13:9cd54f7db57a | 67 | *p++ = MacLocal[1]; |
andrewboyson | 13:9cd54f7db57a | 68 | *p++ = MacLocal[2]; |
andrewboyson | 7:b794780e33b4 | 69 | *p++ = 0xFF; |
andrewboyson | 7:b794780e33b4 | 70 | *p++ = 0xFE; |
andrewboyson | 13:9cd54f7db57a | 71 | *p++ = MacLocal[3]; |
andrewboyson | 13:9cd54f7db57a | 72 | *p++ = MacLocal[4]; |
andrewboyson | 13:9cd54f7db57a | 73 | *p++ = MacLocal[5]; |
andrewboyson | 7:b794780e33b4 | 74 | } |