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/ra.cpp
- Committer:
- andrewboyson
- Date:
- 2017-10-24
- Revision:
- 46:40d33e9037e4
- Child:
- 47:73af5c0b0dc2
File content as of revision 46:40d33e9037e4:
#include   "mbed.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)
{
    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));
    }
    else
    {
        Log("RA    header\r\n");
    }
}
int RaHandleReceivedAdvertisement(void (*traceback)(void), void* pPacket, int* pSize)
{
    struct header* pHeader = (header*)pPacket;
    char*    pData = (char*)pHeader + sizeof(struct header);
    int dataLength =         *pSize - sizeof(struct header);
    
    NdpHopLimit                    = pHeader->hop;
    NdpManagedAddressConfiguration = 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);
        NdpLogOptions(pData, dataLength);
    }
    NdpDecodeOptions(pData, dataLength);
    
    NdpElapsedTime = 0;
    
    return DO_NOTHING;
}