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/icmp6.cpp
- Revision:
- 59:e0e556c8bd46
- Parent:
- 57:e0fb648acf48
--- a/ip6/icmp/icmp6.cpp Thu Dec 07 20:44:32 2017 +0000
+++ b/ip6/icmp/icmp6.cpp Thu Dec 14 20:55:40 2017 +0000
@@ -11,7 +11,6 @@
#include "echo6.h"
#include "dest6.h"
-#define HEADER_LENGTH 4
__packed struct header
{
uint8_t type;
@@ -22,8 +21,6 @@
static uint8_t code;
static uint16_t checksum;
static uint16_t calculatedChecksum;
-static int dataLength;
-static void* pData;
static void logType(uint8_t type)
{
@@ -70,7 +67,6 @@
LogF(" Code %u\r\n", code);
LogF(" Checksum (hex) %04hX\r\n", checksum);
LogF(" Calculated %04hX\r\n", calculatedChecksum);
- LogF(" Data length %d\r\n", dataLength);
}
else
{
@@ -86,8 +82,6 @@
code = pHeader->code;
checksum = NetToHost16(pHeader->checksum);
calculatedChecksum = calculateChecksum(pSrcIp, pDstIp, size, pPacket);
- pData = (char*)pPacket + HEADER_LENGTH;
- dataLength = size - HEADER_LENGTH;
}
static void writeHeader(void* pPacket, int size, char* pSrcIp, char* pDstIp)
{
@@ -105,11 +99,16 @@
pTraceBack();
logHeader();
}
-int Icmp6HandleReceivedPacket(void (*traceback)(void), int scope, char* pSrcIp, char* pDstIp, int* pSize, void* pPacket)
+int Icmp6HandleReceivedPacket(void (*traceback)(void), int scope, void* pPacketRx, int sizeRx, void* pPacketTx, int* pSizeTx, char* pSrcIp, char* pDstIp)
{
pTraceBack = traceback;
+
+ readHeader(pSrcIp, pDstIp, pPacketRx, sizeRx);
- readHeader(pSrcIp, pDstIp, pPacket, *pSize);
+ int dataLengthRx = sizeRx - sizeof(header);
+ int dataLengthTx = *pSizeTx - sizeof(header);
+ char* pPayloadRx = (char*)pPacketRx + sizeof(header);
+ char* pPayloadTx = (char*)pPacketTx + sizeof(header);
int action = DO_NOTHING;
switch (type)
@@ -118,18 +117,18 @@
action = Dest6HandleRequest(trace, &type, &code);
break;
case 128: //Echo request - Ping
- action = Echo6HandleRequest(trace, &type, &code);
+ action = Echo6HandleRequest(trace, &type, &code, pPayloadRx, dataLengthRx, pPayloadTx, &dataLengthTx);
break;
case 133: //Router solicit
return DO_NOTHING; //We are not a router so quietly drop this
case 134: //Router advertisement
- action = RaHandleReceivedAdvertisement(trace, pData, &dataLength);
+ action = RaHandleReceivedAdvertisement(trace, pPayloadRx, &dataLengthRx);
break;
case 135: //Neighbour solicit
- action = NsHandleReceivedSolicitation(trace, pData, &dataLength, &type, &code);
+ action = NsHandleReceivedSolicitation(trace, &type, &code, pPayloadRx, dataLengthRx, pPayloadTx, &dataLengthTx);
break;
case 136: //Neighbour advertisement
- action = NsHandleReceivedAdvertisement(trace, pData, &dataLength);
+ action = NsHandleReceivedAdvertisement(trace, pPayloadRx, &dataLengthRx);
break;
default:
LogTimeF("ICMP6 unknown packet type %d\r\n", type);
@@ -141,9 +140,9 @@
SlaacAddressFromScope(scope, pSrcIp);
Ip6AddressFromDest (ActionGetDestPart(action), pDstIp);
- *pSize = HEADER_LENGTH + dataLength;
+ *pSizeTx = sizeof(header) + dataLengthTx;
- writeHeader(pPacket, *pSize, pSrcIp, pDstIp);
+ writeHeader(pPacketTx, *pSizeTx, pSrcIp, pDstIp);
if (ActionGetTracePart(action)) logHeader();
@@ -151,7 +150,8 @@
}
int Icmp6PollForPacketToSend(void* pPacket, int* pSize, char* pSrcIp, char* pDstIp)
{
- pData = (char*)pPacket + HEADER_LENGTH;
+ char* pData = (char*)pPacket + sizeof(header);
+ int dataLength = *pSize - sizeof(header);
int action = DO_NOTHING;
if (!action) action = RsGetWaitingSolicitation(pData, &dataLength, &type, &code);
if (!action) action = NsGetWaitingSolicitation(pData, &dataLength, &type, &code);
@@ -161,7 +161,7 @@
SlaacAddressFromScope(scope, pSrcIp);
Ip6AddressFromDest (ActionGetDestPart(action), pDstIp);
- *pSize = HEADER_LENGTH + dataLength;
+ *pSize = sizeof(header) + dataLength;
writeHeader(pPacket, *pSize, pSrcIp, pDstIp);