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
Diff: ip6/icmp/ndp/rs.cpp
- Revision:
- 47:73af5c0b0dc2
- Parent:
- 46:40d33e9037e4
--- a/ip6/icmp/ndp/rs.cpp Tue Oct 24 07:01:35 2017 +0000
+++ b/ip6/icmp/ndp/rs.cpp Thu Oct 26 14:50:24 2017 +0000
@@ -10,29 +10,45 @@
bool RsTrace = false;
-bool go = false;
+bool RsSendSolicitation = false;
+
+__packed struct header
+{
+ uint32_t reserved;
+};
-#define REPEAT_DELAY_TIME 60
-static uint32_t delayTime = 10000000; //Reset whenever a message is sent and blocks another send until count exceeds REPEAT_DELAY_TIME
-
+static void logHeader(void* pPacket, int size)
+{
+ struct header* pHeader = (header*)pPacket;
+ char* pData = (char*)pHeader + sizeof(struct header);
+ int dataLength = size - sizeof(struct header);
+
+ if (NetTraceVerbose)
+ {
+ Log("RS header\r\n");
+ LogF(" Size %d\r\n", size);
+ NdpLogOptionsVerbose(pData, dataLength);
+ }
+ else
+ {
+ Log("RS header");
+ NdpLogOptionsQuiet(pData, dataLength);
+ Log("\r\n");
+ }
+}
int RsGetWaitingSolicitation(void* pPacket, int* pSize, uint8_t* pType, uint8_t* pCode)
{
- if (!go) return DO_NOTHING;
- go = false;
+ if (!RsSendSolicitation) return DO_NOTHING;
+ RsSendSolicitation = false;
- __packed struct header
- {
- uint32_t reserved;
- };
- struct header* pHeader = (header*)pPacket;
- pHeader->reserved = 0;
- *pSize = sizeof(struct header);
*pType = 133; //Router solicitation
*pCode = 0;
+ struct header* pHeader = (header*)pPacket;
+ pHeader->reserved = 0;
+
char* pData = (char*)pHeader + sizeof(struct header);
char* p = pData;
-
p += NdpAddOptionSourceMac(p, MacLocal);
*pSize = sizeof(struct header) + p - pData;
@@ -41,50 +57,9 @@
{
if (NetTraceNewLine) Log("\r\n");
LogTime("NDP send router solicit\r\n");
- if (NetTraceVerbose)
- {
- Log("RS header\r\n");
- NdpLogOptions(pData, *pSize);
- }
- else
- {
- Log("RS header\r\n");
- }
+ logHeader(pPacket, *pSize);
}
return ActionMakeFromDestAndTrace(MULTICAST_ROUTER, RsTrace && NetTraceStack);
}
-
-static void checkIfGo()
-{
- if (delayTime < REPEAT_DELAY_TIME) return; //Don't retry within the delay time
-
- if (NdpLifetime && NdpElapsedTime < (NdpLifetime >> 1)) return; //Do nothing if within half the life
-
- if (!NdpLifetime || NdpElapsedTime >= NdpLifetime)
- {
- if (RsTrace)
- {
- if (NetTraceNewLine) Log("\r\n");
- LogTime("NDP lifetime has expired: clear global prefix\r\n");
- }
- NdpLifetime = 0;
- Ip6Clear(NdpPrefix);
- SlaacMakeGlobal(NdpPrefix);
- Ip6Clear(NdpDnsServer);
- }
-
- delayTime = 0;
- go = true;
-}
-
-void RsMain()
-{
- if (ClockTicked)
- {
- NdpElapsedTime++;
- delayTime++;
- }
- checkIfGo();
-}