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.cpp@47:73af5c0b0dc2, 2017-10-26 (annotated)
- Committer:
- andrewboyson
- Date:
- Thu Oct 26 14:50:24 2017 +0000
- Revision:
- 47:73af5c0b0dc2
- Parent:
- 46:40d33e9037e4
Replaced a number of temporary buffers with direct writes to the Log or HTTP.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| andrewboyson | 46:40d33e9037e4 | 1 | #include "mbed.h" |
| andrewboyson | 46:40d33e9037e4 | 2 | #include "log.h" |
| andrewboyson | 46:40d33e9037e4 | 3 | #include "clock.h" |
| andrewboyson | 46:40d33e9037e4 | 4 | #include "net.h" |
| andrewboyson | 46:40d33e9037e4 | 5 | #include "action.h" |
| andrewboyson | 46:40d33e9037e4 | 6 | #include "ip6.h" |
| andrewboyson | 46:40d33e9037e4 | 7 | #include "mac.h" |
| andrewboyson | 46:40d33e9037e4 | 8 | #include "slaac.h" |
| andrewboyson | 46:40d33e9037e4 | 9 | #include "ndp.h" |
| andrewboyson | 46:40d33e9037e4 | 10 | |
| andrewboyson | 46:40d33e9037e4 | 11 | bool RaTrace = false; |
| andrewboyson | 46:40d33e9037e4 | 12 | |
| andrewboyson | 46:40d33e9037e4 | 13 | __packed struct header |
| andrewboyson | 46:40d33e9037e4 | 14 | { |
| andrewboyson | 46:40d33e9037e4 | 15 | uint8_t hop; |
| andrewboyson | 46:40d33e9037e4 | 16 | uint8_t mo; |
| andrewboyson | 46:40d33e9037e4 | 17 | uint16_t lifetime; |
| andrewboyson | 46:40d33e9037e4 | 18 | uint32_t reachable; |
| andrewboyson | 46:40d33e9037e4 | 19 | uint32_t retrans; |
| andrewboyson | 46:40d33e9037e4 | 20 | }; |
| andrewboyson | 47:73af5c0b0dc2 | 21 | void logHeader(struct header* pHeader, char* pData, int dataLength) |
| andrewboyson | 46:40d33e9037e4 | 22 | { |
| andrewboyson | 46:40d33e9037e4 | 23 | if (NetTraceVerbose) |
| andrewboyson | 46:40d33e9037e4 | 24 | { |
| andrewboyson | 46:40d33e9037e4 | 25 | Log("RA header\r\n"); |
| andrewboyson | 46:40d33e9037e4 | 26 | LogF(" Hop limit %d\r\n", pHeader->hop); |
| andrewboyson | 46:40d33e9037e4 | 27 | LogF(" M O %x\r\n", pHeader->mo); |
| andrewboyson | 46:40d33e9037e4 | 28 | LogF(" Lifetime %d\r\n", NetToHost16(pHeader->lifetime)); |
| andrewboyson | 46:40d33e9037e4 | 29 | LogF(" Reachable %d\r\n", NetToHost32(pHeader->reachable)); |
| andrewboyson | 46:40d33e9037e4 | 30 | LogF(" Retrans %d\r\n", NetToHost32(pHeader->retrans)); |
| andrewboyson | 47:73af5c0b0dc2 | 31 | NdpLogOptionsVerbose(pData, dataLength); |
| andrewboyson | 46:40d33e9037e4 | 32 | } |
| andrewboyson | 46:40d33e9037e4 | 33 | else |
| andrewboyson | 46:40d33e9037e4 | 34 | { |
| andrewboyson | 47:73af5c0b0dc2 | 35 | Log("RA header"); |
| andrewboyson | 47:73af5c0b0dc2 | 36 | NdpLogOptionsQuiet(pData, dataLength); |
| andrewboyson | 47:73af5c0b0dc2 | 37 | Log("\r\n"); |
| andrewboyson | 46:40d33e9037e4 | 38 | } |
| andrewboyson | 46:40d33e9037e4 | 39 | } |
| andrewboyson | 46:40d33e9037e4 | 40 | int RaHandleReceivedAdvertisement(void (*traceback)(void), void* pPacket, int* pSize) |
| andrewboyson | 46:40d33e9037e4 | 41 | { |
| andrewboyson | 46:40d33e9037e4 | 42 | struct header* pHeader = (header*)pPacket; |
| andrewboyson | 46:40d33e9037e4 | 43 | char* pData = (char*)pHeader + sizeof(struct header); |
| andrewboyson | 46:40d33e9037e4 | 44 | int dataLength = *pSize - sizeof(struct header); |
| andrewboyson | 46:40d33e9037e4 | 45 | |
| andrewboyson | 47:73af5c0b0dc2 | 46 | NdpHopLimit = pHeader->hop; |
| andrewboyson | 47:73af5c0b0dc2 | 47 | NdpManagedConfiguration = pHeader->mo & 0x80; |
| andrewboyson | 47:73af5c0b0dc2 | 48 | NdpOtherConfiguration = pHeader->mo & 0x40; |
| andrewboyson | 47:73af5c0b0dc2 | 49 | NdpLifetime = NetToHost16(pHeader->lifetime); |
| andrewboyson | 46:40d33e9037e4 | 50 | |
| andrewboyson | 46:40d33e9037e4 | 51 | if (RaTrace) |
| andrewboyson | 46:40d33e9037e4 | 52 | { |
| andrewboyson | 46:40d33e9037e4 | 53 | if (NetTraceNewLine) Log("\r\n"); |
| andrewboyson | 46:40d33e9037e4 | 54 | LogTimeF("NDP received router advertise\r\n"); |
| andrewboyson | 46:40d33e9037e4 | 55 | if (NetTraceStack) traceback(); |
| andrewboyson | 47:73af5c0b0dc2 | 56 | logHeader(pHeader, pData, dataLength); |
| andrewboyson | 46:40d33e9037e4 | 57 | } |
| andrewboyson | 47:73af5c0b0dc2 | 58 | NdpDecodeOptions(pData, dataLength, NdpRouterMac, NULL); |
| andrewboyson | 46:40d33e9037e4 | 59 | |
| andrewboyson | 46:40d33e9037e4 | 60 | NdpElapsedTime = 0; |
| andrewboyson | 46:40d33e9037e4 | 61 | |
| andrewboyson | 46:40d33e9037e4 | 62 | return DO_NOTHING; |
| andrewboyson | 46:40d33e9037e4 | 63 | |
| andrewboyson | 46:40d33e9037e4 | 64 | } |