Andrew Boyson / net

Dependents:   oldheating gps motorhome heating

Committer:
andrewboyson
Date:
Thu Jan 11 17:38:21 2018 +0000
Revision:
61:aad055f1b0d1
Parent:
ip6/icmp/ndp/rs.cpp@47:73af5c0b0dc2
Child:
103:9cf35a5b9d56
Removed dependence on Mbed OS

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 46:40d33e9037e4 5 #include "net.h"
andrewboyson 46:40d33e9037e4 6 #include "ndp.h"
andrewboyson 46:40d33e9037e4 7 #include "ip6.h"
andrewboyson 46:40d33e9037e4 8 #include "slaac.h"
andrewboyson 46:40d33e9037e4 9 #include "clock.h"
andrewboyson 46:40d33e9037e4 10 #include "action.h"
andrewboyson 46:40d33e9037e4 11 #include "mac.h"
andrewboyson 46:40d33e9037e4 12
andrewboyson 46:40d33e9037e4 13 bool RsTrace = false;
andrewboyson 46:40d33e9037e4 14
andrewboyson 47:73af5c0b0dc2 15 bool RsSendSolicitation = false;
andrewboyson 47:73af5c0b0dc2 16
andrewboyson 47:73af5c0b0dc2 17 __packed struct header
andrewboyson 47:73af5c0b0dc2 18 {
andrewboyson 47:73af5c0b0dc2 19 uint32_t reserved;
andrewboyson 47:73af5c0b0dc2 20 };
andrewboyson 46:40d33e9037e4 21
andrewboyson 47:73af5c0b0dc2 22 static void logHeader(void* pPacket, int size)
andrewboyson 47:73af5c0b0dc2 23 {
andrewboyson 61:aad055f1b0d1 24 struct header* pHeader = (struct header*)pPacket;
andrewboyson 47:73af5c0b0dc2 25 char* pData = (char*)pHeader + sizeof(struct header);
andrewboyson 47:73af5c0b0dc2 26 int dataLength = size - sizeof(struct header);
andrewboyson 47:73af5c0b0dc2 27
andrewboyson 47:73af5c0b0dc2 28 if (NetTraceVerbose)
andrewboyson 47:73af5c0b0dc2 29 {
andrewboyson 47:73af5c0b0dc2 30 Log("RS header\r\n");
andrewboyson 47:73af5c0b0dc2 31 LogF(" Size %d\r\n", size);
andrewboyson 47:73af5c0b0dc2 32 NdpLogOptionsVerbose(pData, dataLength);
andrewboyson 47:73af5c0b0dc2 33 }
andrewboyson 47:73af5c0b0dc2 34 else
andrewboyson 47:73af5c0b0dc2 35 {
andrewboyson 47:73af5c0b0dc2 36 Log("RS header");
andrewboyson 47:73af5c0b0dc2 37 NdpLogOptionsQuiet(pData, dataLength);
andrewboyson 47:73af5c0b0dc2 38 Log("\r\n");
andrewboyson 47:73af5c0b0dc2 39 }
andrewboyson 47:73af5c0b0dc2 40 }
andrewboyson 46:40d33e9037e4 41 int RsGetWaitingSolicitation(void* pPacket, int* pSize, uint8_t* pType, uint8_t* pCode)
andrewboyson 46:40d33e9037e4 42 {
andrewboyson 47:73af5c0b0dc2 43 if (!RsSendSolicitation) return DO_NOTHING;
andrewboyson 47:73af5c0b0dc2 44 RsSendSolicitation = false;
andrewboyson 46:40d33e9037e4 45
andrewboyson 46:40d33e9037e4 46 *pType = 133; //Router solicitation
andrewboyson 46:40d33e9037e4 47 *pCode = 0;
andrewboyson 46:40d33e9037e4 48
andrewboyson 61:aad055f1b0d1 49 struct header* pHeader = (struct header*)pPacket;
andrewboyson 47:73af5c0b0dc2 50 pHeader->reserved = 0;
andrewboyson 47:73af5c0b0dc2 51
andrewboyson 46:40d33e9037e4 52 char* pData = (char*)pHeader + sizeof(struct header);
andrewboyson 46:40d33e9037e4 53 char* p = pData;
andrewboyson 46:40d33e9037e4 54 p += NdpAddOptionSourceMac(p, MacLocal);
andrewboyson 46:40d33e9037e4 55
andrewboyson 46:40d33e9037e4 56 *pSize = sizeof(struct header) + p - pData;
andrewboyson 46:40d33e9037e4 57
andrewboyson 46:40d33e9037e4 58 if (RsTrace)
andrewboyson 46:40d33e9037e4 59 {
andrewboyson 46:40d33e9037e4 60 if (NetTraceNewLine) Log("\r\n");
andrewboyson 46:40d33e9037e4 61 LogTime("NDP send router solicit\r\n");
andrewboyson 47:73af5c0b0dc2 62 logHeader(pPacket, *pSize);
andrewboyson 46:40d33e9037e4 63 }
andrewboyson 46:40d33e9037e4 64
andrewboyson 46:40d33e9037e4 65 return ActionMakeFromDestAndTrace(MULTICAST_ROUTER, RsTrace && NetTraceStack);
andrewboyson 46:40d33e9037e4 66
andrewboyson 46:40d33e9037e4 67 }