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
Diff: ip6/icmp/ndp/ra.c
- Revision:
- 61:aad055f1b0d1
- Parent:
- 47:73af5c0b0dc2
- Child:
- 93:580fc113d9e9
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ip6/icmp/ndp/ra.c Thu Jan 11 17:38:21 2018 +0000 @@ -0,0 +1,66 @@ +#include <stdint.h> +#include <stdbool.h> + +#include "log.h" +#include "clock.h" +#include "net.h" +#include "action.h" +#include "ip6.h" +#include "mac.h" +#include "slaac.h" +#include "ndp.h" + +bool RaTrace = false; + +__packed struct header +{ + uint8_t hop; + uint8_t mo; + uint16_t lifetime; + uint32_t reachable; + uint32_t retrans; +}; +void logHeader(struct header* pHeader, char* pData, int dataLength) +{ + if (NetTraceVerbose) + { + Log("RA header\r\n"); + LogF(" Hop limit %d\r\n", pHeader->hop); + LogF(" M O %x\r\n", pHeader->mo); + LogF(" Lifetime %d\r\n", NetToHost16(pHeader->lifetime)); + LogF(" Reachable %d\r\n", NetToHost32(pHeader->reachable)); + LogF(" Retrans %d\r\n", NetToHost32(pHeader->retrans)); + NdpLogOptionsVerbose(pData, dataLength); + } + else + { + Log("RA header"); + NdpLogOptionsQuiet(pData, dataLength); + Log("\r\n"); + } +} +int RaHandleReceivedAdvertisement(void (*traceback)(void), void* pPacket, int* pSize) +{ + struct header* pHeader = (struct header*)pPacket; + char* pData = (char*)pHeader + sizeof(struct header); + int dataLength = *pSize - sizeof(struct header); + + NdpHopLimit = pHeader->hop; + NdpManagedConfiguration = pHeader->mo & 0x80; + NdpOtherConfiguration = pHeader->mo & 0x40; + NdpLifetime = NetToHost16(pHeader->lifetime); + + if (RaTrace) + { + if (NetTraceNewLine) Log("\r\n"); + LogTimeF("NDP received router advertise\r\n"); + if (NetTraceStack) traceback(); + logHeader(pHeader, pData, dataLength); + } + NdpDecodeOptions(pData, dataLength, NdpRouterMac, NULL); + + NdpElapsedTime = 0; + + return DO_NOTHING; + +}