really still wip

This commit is contained in:
2025-12-28 12:23:11 +01:00
parent a48ef9d5e0
commit 31dda62474
33 changed files with 1721 additions and 589 deletions

View File

@@ -6,6 +6,7 @@
#include "meshcore/packets/control.h"
#include "meshcore/packets/encrypted.h"
#include "meshcore/packets/group.h"
#include "meshcore/stats.h"
#include "task.h"
#include "lib/base64.h"
#include "lib/cifra/aes.h"
@@ -13,52 +14,54 @@
#include "lib/cifra/hmac.h"
#include "lib/config.h"
#include "meshframing.h"
#include "meshcore/packetstructs.h"
#define TAG "MeshCore"
// requires at least a 256 byte data
void processFrame (FrameStruct frame) {
void processFrame (const FrameStruct *frame) {
printFrameHeader (frame);
if (frame.header & PAYLOAD_VERSION_3) { // more than the version 0
ESP_LOGW (TAG, "Frame too new, got version %d instead of 0", (frame.header & PAYLOAD_VERSION_3) >> 6);
if (frame->header & PAYLOAD_VERSION_3) { // more than the version 0
MESH_LOGW (TAG, "Frame too new, got version %d instead of 0", (frame->header & PAYLOAD_VERSION_3) >> 6);
}
unsigned char checkSumBuf[10];
AdvertisementPayload advert;
GroupTextMessage msg;
unsigned char frameType = frame.header & PAYLOAD_TYPE_MASK;
unsigned char frameType = frame->header & PAYLOAD_TYPE_MASK;
unsigned char index = 0;
stats.packetsReceivedCount++;
if ((frame->header & ROUTE_TYPE_MASK) == ROUTE_TYPE_FLOOD ||
(frame->header & ROUTE_TYPE_MASK) == ROUTE_TYPE_TRANSPORT_FLOOD) {
stats.receivedFloodCount++;
}
if ((frame->header & ROUTE_TYPE_MASK) == ROUTE_TYPE_DIRECT ||
(frame->header & ROUTE_TYPE_MASK) == ROUTE_TYPE_TRANSPORT_DIRECT) {
stats.receivedDirectCount++;
}
if (frameType == PAYLOAD_TYPE_ANON_REQ) {
decodeAnonReq (frame);
} else if (frameType == PAYLOAD_TYPE_PATH || frameType == PAYLOAD_TYPE_REQ || frameType == PAYLOAD_TYPE_RESPONSE || frameType == PAYLOAD_TYPE_TXT_MSG) {
printf (" Typexd: 0x%02X\n", frameType);
EncryptedPayloadStruct enc = decodeEncryptedPayload (frame);
printf (" Typexdd: 0x%02X\n", enc.type);
if (enc.payloadLen > 0) {
parseEncryptedPayload (enc);
}
decodeEncryptedPayload (frame);
} else if (frameType == PAYLOAD_TYPE_ACK) {
memset (checkSumBuf, 0, sizeof (checkSumBuf));
base64_encode (frame.payload, 4, checkSumBuf);
printf ("Checksum: %s\n", checkSumBuf);
} else if (frameType == PAYLOAD_TYPE_ACK) {
uint32_t checkSum = frame.payload[index++];
checkSum |= frame.payload[index++] << 8;
checkSum |= frame.payload[index++] << 16;
checkSum |= frame.payload[index++] << 24;
uint32_t checkSum = frame->payload[index++];
checkSum |= frame->payload[index++] << 8;
checkSum |= frame->payload[index++] << 16;
checkSum |= frame->payload[index++] << 24;
// TODO add checking
} else if (frameType == PAYLOAD_TYPE_ADVERT) {
advert = decodeAdvertisement (frame);
printAdvertisement (advert);
decodeAdvertisement (frame);
} else if (frameType == PAYLOAD_TYPE_GRP_TXT || frameType == PAYLOAD_TYPE_GRP_DATA) {
msg = decodeGroupMessage (frame);
printGroupMessage (msg);
decodeGroupMessage (frame);
} else if (frameType == PAYLOAD_TYPE_TRACE) {
} else if (frameType == PAYLOAD_TYPE_MULTIPART) {
@@ -68,7 +71,8 @@ void processFrame (FrameStruct frame) {
} else if (frameType == PAYLOAD_TYPE_RAW_CUSTOM) {
// not implemented
} else {
stats.packetsReceivedCount--;
}
retransmitFrame (frame);
MESH_LOGD(TAG, "Processed frame");
}