Andrew Boyson / net

Dependents:   oldheating gps motorhome heating

Committer:
andrewboyson
Date:
Wed May 15 15:33:15 2019 +0000
Revision:
146:0fc66d610fd6
Parent:
137:cf6e7db0e985
Tidied the http shim

Who changed what in which revision?

UserRevisionLine numberNew 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 137:cf6e7db0e985 15 static uint8_t hdrGetHop (char* pPacket) { return *(pPacket + 0); }
andrewboyson 137:cf6e7db0e985 16 static uint8_t hdrGetMo (char* pPacket) { return *(pPacket + 1); }
andrewboyson 137:cf6e7db0e985 17 static uint16_t hdrGetLifetime (char* pPacket) { uint16_t r; NetInvert16(&r, pPacket + 2); return r; }
andrewboyson 137:cf6e7db0e985 18 static uint32_t hdrGetReachable(char* pPacket) { uint32_t r; NetInvert32(&r, pPacket + 4); return r; }
andrewboyson 137:cf6e7db0e985 19 static uint32_t hdrGetRetrans (char* pPacket) { uint32_t r; NetInvert32(&r, pPacket + 8); return r; }
andrewboyson 137:cf6e7db0e985 20 static const int HEADER_LENGTH = 12;
andrewboyson 137:cf6e7db0e985 21
andrewboyson 137:cf6e7db0e985 22 void logHeader(char* pPacket, int dataLength)
andrewboyson 46:40d33e9037e4 23 {
andrewboyson 137:cf6e7db0e985 24 char* pData = pPacket + HEADER_LENGTH;
andrewboyson 46:40d33e9037e4 25 if (NetTraceVerbose)
andrewboyson 46:40d33e9037e4 26 {
andrewboyson 46:40d33e9037e4 27 Log("RA header\r\n");
andrewboyson 137:cf6e7db0e985 28 LogF(" Hop limit %d\r\n", hdrGetHop (pPacket));
andrewboyson 137:cf6e7db0e985 29 LogF(" M O %x\r\n", hdrGetMo (pPacket));
andrewboyson 137:cf6e7db0e985 30 LogF(" Lifetime %d\r\n", hdrGetLifetime (pPacket));
andrewboyson 137:cf6e7db0e985 31 LogF(" Reachable %d\r\n", hdrGetReachable(pPacket));
andrewboyson 137:cf6e7db0e985 32 LogF(" Retrans %d\r\n", hdrGetRetrans (pPacket));
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 137:cf6e7db0e985 42 int RaHandleReceivedAdvertisement(void (*traceback)(void), char* pPacket, int* pSize)
andrewboyson 46:40d33e9037e4 43 {
andrewboyson 137:cf6e7db0e985 44 char* pData = pPacket + HEADER_LENGTH;
andrewboyson 137:cf6e7db0e985 45 int dataLength = *pSize - HEADER_LENGTH;
andrewboyson 46:40d33e9037e4 46
andrewboyson 137:cf6e7db0e985 47 NdpHopLimit = hdrGetHop (pPacket);
andrewboyson 137:cf6e7db0e985 48 NdpManagedConfiguration = hdrGetMo (pPacket) & 0x80;
andrewboyson 137:cf6e7db0e985 49 NdpOtherConfiguration = hdrGetMo (pPacket) & 0x40;
andrewboyson 137:cf6e7db0e985 50 NdpSetLease (hdrGetLifetime(pPacket)); //This resets the NdpElapsedTimer
andrewboyson 46:40d33e9037e4 51
andrewboyson 46:40d33e9037e4 52 if (RaTrace)
andrewboyson 46:40d33e9037e4 53 {
andrewboyson 46:40d33e9037e4 54 if (NetTraceNewLine) Log("\r\n");
andrewboyson 46:40d33e9037e4 55 LogTimeF("NDP received router advertise\r\n");
andrewboyson 46:40d33e9037e4 56 if (NetTraceStack) traceback();
andrewboyson 137:cf6e7db0e985 57 logHeader(pPacket, dataLength);
andrewboyson 46:40d33e9037e4 58 }
andrewboyson 47:73af5c0b0dc2 59 NdpDecodeOptions(pData, dataLength, NdpRouterMac, NULL);
andrewboyson 46:40d33e9037e4 60
andrewboyson 46:40d33e9037e4 61 return DO_NOTHING;
andrewboyson 46:40d33e9037e4 62
andrewboyson 46:40d33e9037e4 63 }