A stack which works with or without an Mbed os library. Provides IPv4 or IPv6 with a full 1500 byte buffer.

Dependents:   oldheating gps motorhome heating

ip6/icmp/ndp/ra.c

Committer:
andrewboyson
Date:
2018-12-02
Revision:
93:580fc113d9e9
Parent:
61:aad055f1b0d1
Child:
101:a677d8aee6dd

File content as of revision 93:580fc113d9e9:

#include <stdint.h>
#include <stdbool.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, char* pData, int dataLength)
{
    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));
        NdpLogOptionsVerbose(pData, dataLength);
    }
    else
    {
        Log("RA    header");
        NdpLogOptionsQuiet(pData, dataLength);
        Log("\r\n");
    }
}
int RaHandleReceivedAdvertisement(void (*traceback)(void), void* pPacket, int* pSize)
{
    struct header* pHeader = (struct header*)pPacket;
    char*    pData = (char*)pHeader + sizeof(struct header);
    int dataLength =         *pSize - sizeof(struct header);
    
    NdpHopLimit             = pHeader->hop;
    NdpManagedConfiguration = 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, pData, dataLength);
    }
    NdpDecodeOptions(pData, dataLength, NdpRouterMac, NULL);
    
    NdpResetLife();
    
    return DO_NOTHING;

}