75 lines
2.5 KiB
C
75 lines
2.5 KiB
C
#include "meshcore.h"
|
|
#include "FreeRTOS.h"
|
|
#include "lib/ed25519/ed_25519.h"
|
|
#include "meshcore/packets/advert.h"
|
|
#include "meshcore/packets/anonymous.h"
|
|
#include "meshcore/packets/control.h"
|
|
#include "meshcore/packets/encrypted.h"
|
|
#include "meshcore/packets/group.h"
|
|
#include "task.h"
|
|
#include "lib/base64.h"
|
|
#include "lib/cifra/aes.h"
|
|
#include "lib/cifra/sha2.h"
|
|
#include "lib/cifra/hmac.h"
|
|
#include "lib/config.h"
|
|
#include "meshframing.h"
|
|
|
|
#define TAG "MeshCore"
|
|
|
|
// requires at least a 256 byte data
|
|
|
|
|
|
void processFrame (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);
|
|
}
|
|
|
|
unsigned char checkSumBuf[10];
|
|
AdvertisementPayload advert;
|
|
GroupTextMessage msg;
|
|
|
|
unsigned char frameType = frame.header & PAYLOAD_TYPE_MASK;
|
|
|
|
unsigned char index = 0;
|
|
|
|
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);
|
|
}
|
|
} 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;
|
|
|
|
} else if (frameType == PAYLOAD_TYPE_ADVERT) {
|
|
advert = decodeAdvertisement (frame);
|
|
printAdvertisement (advert);
|
|
} else if (frameType == PAYLOAD_TYPE_GRP_TXT || frameType == PAYLOAD_TYPE_GRP_DATA) {
|
|
msg = decodeGroupMessage (frame);
|
|
printGroupMessage (msg);
|
|
} else if (frameType == PAYLOAD_TYPE_TRACE) {
|
|
|
|
} else if (frameType == PAYLOAD_TYPE_MULTIPART) {
|
|
|
|
} else if (frameType == PAYLOAD_TYPE_CONTROL) {
|
|
decodeControlFrame (frame);
|
|
|
|
} else if (frameType == PAYLOAD_TYPE_RAW_CUSTOM) {
|
|
// not implemented
|
|
}
|
|
|
|
retransmitFrame (frame);
|
|
}
|