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/rs.c
- Committer:
- andrewboyson
- Date:
- 2019-01-29
- Revision:
- 119:8e1a7805b801
- Parent:
- 103:9cf35a5b9d56
- Child:
- 132:db2174b36a6d
File content as of revision 119:8e1a7805b801:
#include <stdint.h>
#include <stdbool.h>
#include "log.h"
#include "net.h"
#include "ndp.h"
#include "ip6.h"
#include "ip6addr.h"
#include "slaac.h"
#include "action.h"
#include "mac.h"
#include "mstimer.h"
bool RsTrace = false;
bool RsSendSolicitation = false;
#define MAX_REPEAT_DELAY_TIME_MS 60000
#define MIN_REPEAT_DELAY_TIME_MS 800
static uint32_t repeatDelayMsTimer = (uint32_t)-MIN_REPEAT_DELAY_TIME_MS; //Initial value ensures no delay at startup
static uint32_t delayMs = MIN_REPEAT_DELAY_TIME_MS; //Doubles on failure up to max; reset to min whenever an IP address request has been acknowledged
__packed struct header
{
uint32_t reserved;
};
static void logHeader(void* pPacket, int size)
{
struct header* pHeader = (struct 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)
{
//Check if time to update
if (NdpIsFresh())
{
delayMs = MIN_REPEAT_DELAY_TIME_MS; //Set the delay time back to minimum
return DO_NOTHING;
}
//Limit retries with a backoff delay
if (!MsTimerHasElapsed(repeatDelayMsTimer, delayMs)) return DO_NOTHING; //Don't retry within the delay time
delayMs <<= 1; //Backoff (double) the delay time after each attempt
if (delayMs > MAX_REPEAT_DELAY_TIME_MS) delayMs = MAX_REPEAT_DELAY_TIME_MS; //Don't go beyond a maximum
repeatDelayMsTimer = MsTimerCount; //Start the delay timer
//Send the renewal request
*pType = 133; //Router solicitation
*pCode = 0;
struct header* pHeader = (struct 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;
if (RsTrace)
{
if (NetTraceNewLine) Log("\r\n");
LogTime("NDP send router solicit\r\n");
logHeader(pPacket, *pSize);
}
return ActionMakeFromDestAndTrace(MULTICAST_ROUTER, RsTrace && NetTraceStack);
}