Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: oldheating gps motorhome heating
ip6/icmp/ndp/ra.c@101:a677d8aee6dd, 2019-01-08 (annotated)
- Committer:
- andrewboyson
- Date:
- Tue Jan 08 15:06:07 2019 +0000
- Revision:
- 101:a677d8aee6dd
- Parent:
- 93:580fc113d9e9
- Child:
- 119:8e1a7805b801
Added links to get and set the NTP LI flags
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| andrewboyson | 61:aad055f1b0d1 | 1 | #include <stdint.h> |
| andrewboyson | 61:aad055f1b0d1 | 2 | #include <stdbool.h> |
| andrewboyson | 61:aad055f1b0d1 | 3 | |
| andrewboyson | 46:40d33e9037e4 | 4 | #include "log.h" |
| andrewboyson | 101:a677d8aee6dd | 5 | #include "clk.h" |
| andrewboyson | 46:40d33e9037e4 | 6 | #include "net.h" |
| andrewboyson | 46:40d33e9037e4 | 7 | #include "action.h" |
| andrewboyson | 46:40d33e9037e4 | 8 | #include "ip6.h" |
| andrewboyson | 46:40d33e9037e4 | 9 | #include "mac.h" |
| andrewboyson | 46:40d33e9037e4 | 10 | #include "slaac.h" |
| andrewboyson | 46:40d33e9037e4 | 11 | #include "ndp.h" |
| andrewboyson | 46:40d33e9037e4 | 12 | |
| andrewboyson | 46:40d33e9037e4 | 13 | bool RaTrace = false; |
| andrewboyson | 46:40d33e9037e4 | 14 | |
| andrewboyson | 46:40d33e9037e4 | 15 | __packed struct header |
| andrewboyson | 46:40d33e9037e4 | 16 | { |
| andrewboyson | 46:40d33e9037e4 | 17 | uint8_t hop; |
| andrewboyson | 46:40d33e9037e4 | 18 | uint8_t mo; |
| andrewboyson | 46:40d33e9037e4 | 19 | uint16_t lifetime; |
| andrewboyson | 46:40d33e9037e4 | 20 | uint32_t reachable; |
| andrewboyson | 46:40d33e9037e4 | 21 | uint32_t retrans; |
| andrewboyson | 46:40d33e9037e4 | 22 | }; |
| andrewboyson | 47:73af5c0b0dc2 | 23 | void logHeader(struct header* pHeader, char* pData, int dataLength) |
| andrewboyson | 46:40d33e9037e4 | 24 | { |
| andrewboyson | 46:40d33e9037e4 | 25 | if (NetTraceVerbose) |
| andrewboyson | 46:40d33e9037e4 | 26 | { |
| andrewboyson | 46:40d33e9037e4 | 27 | Log("RA header\r\n"); |
| andrewboyson | 46:40d33e9037e4 | 28 | LogF(" Hop limit %d\r\n", pHeader->hop); |
| andrewboyson | 46:40d33e9037e4 | 29 | LogF(" M O %x\r\n", pHeader->mo); |
| andrewboyson | 46:40d33e9037e4 | 30 | LogF(" Lifetime %d\r\n", NetToHost16(pHeader->lifetime)); |
| andrewboyson | 46:40d33e9037e4 | 31 | LogF(" Reachable %d\r\n", NetToHost32(pHeader->reachable)); |
| andrewboyson | 46:40d33e9037e4 | 32 | LogF(" Retrans %d\r\n", NetToHost32(pHeader->retrans)); |
| andrewboyson | 47:73af5c0b0dc2 | 33 | NdpLogOptionsVerbose(pData, dataLength); |
| andrewboyson | 46:40d33e9037e4 | 34 | } |
| andrewboyson | 46:40d33e9037e4 | 35 | else |
| andrewboyson | 46:40d33e9037e4 | 36 | { |
| andrewboyson | 47:73af5c0b0dc2 | 37 | Log("RA header"); |
| andrewboyson | 47:73af5c0b0dc2 | 38 | NdpLogOptionsQuiet(pData, dataLength); |
| andrewboyson | 47:73af5c0b0dc2 | 39 | Log("\r\n"); |
| andrewboyson | 46:40d33e9037e4 | 40 | } |
| andrewboyson | 46:40d33e9037e4 | 41 | } |
| andrewboyson | 46:40d33e9037e4 | 42 | int RaHandleReceivedAdvertisement(void (*traceback)(void), void* pPacket, int* pSize) |
| andrewboyson | 46:40d33e9037e4 | 43 | { |
| andrewboyson | 61:aad055f1b0d1 | 44 | struct header* pHeader = (struct header*)pPacket; |
| andrewboyson | 46:40d33e9037e4 | 45 | char* pData = (char*)pHeader + sizeof(struct header); |
| andrewboyson | 46:40d33e9037e4 | 46 | int dataLength = *pSize - sizeof(struct header); |
| andrewboyson | 46:40d33e9037e4 | 47 | |
| andrewboyson | 47:73af5c0b0dc2 | 48 | NdpHopLimit = pHeader->hop; |
| andrewboyson | 47:73af5c0b0dc2 | 49 | NdpManagedConfiguration = pHeader->mo & 0x80; |
| andrewboyson | 47:73af5c0b0dc2 | 50 | NdpOtherConfiguration = pHeader->mo & 0x40; |
| andrewboyson | 47:73af5c0b0dc2 | 51 | NdpLifetime = NetToHost16(pHeader->lifetime); |
| andrewboyson | 46:40d33e9037e4 | 52 | |
| andrewboyson | 46:40d33e9037e4 | 53 | if (RaTrace) |
| andrewboyson | 46:40d33e9037e4 | 54 | { |
| andrewboyson | 46:40d33e9037e4 | 55 | if (NetTraceNewLine) Log("\r\n"); |
| andrewboyson | 46:40d33e9037e4 | 56 | LogTimeF("NDP received router advertise\r\n"); |
| andrewboyson | 46:40d33e9037e4 | 57 | if (NetTraceStack) traceback(); |
| andrewboyson | 47:73af5c0b0dc2 | 58 | logHeader(pHeader, pData, dataLength); |
| andrewboyson | 46:40d33e9037e4 | 59 | } |
| andrewboyson | 47:73af5c0b0dc2 | 60 | NdpDecodeOptions(pData, dataLength, NdpRouterMac, NULL); |
| andrewboyson | 46:40d33e9037e4 | 61 | |
| andrewboyson | 93:580fc113d9e9 | 62 | NdpResetLife(); |
| andrewboyson | 46:40d33e9037e4 | 63 | |
| andrewboyson | 46:40d33e9037e4 | 64 | return DO_NOTHING; |
| andrewboyson | 46:40d33e9037e4 | 65 | |
| andrewboyson | 46:40d33e9037e4 | 66 | } |