Files
meshcore-wch/User/meshcore/packets/ack.c
2025-12-22 23:02:29 +01:00

42 lines
894 B
C

#include "ack.h"
#include "lib/cifra/sha2.h"
#include "lib/config.h"
#include "meshcore/meshframing.h"
#include <string.h>
#define TAG "Ack"
void sendDiscreteAck (uint8_t *data, const uint8_t len, uint8_t *senderPubKey) {
FrameStruct frame;
memset (&frame, 0, sizeof (frame));
// 1. Header
frame.header =
ROUTE_TYPE_FLOOD | // currently flood
PAYLOAD_TYPE_ACK |
PAYLOAD_VERSION_0;
// Buffer for the digest
uint8_t hash[CF_SHA256_HASHSZ];
// Context
cf_sha256_context ctx;
// 1. Initialize
cf_sha256_init (&ctx);
// 2. Feed in your data
cf_sha256_update (&ctx, data, len);
cf_sha256_update (&ctx, senderPubKey, sizeof (persistent.pubkey));
// 3. Compute digest
cf_sha256_digest (&ctx, hash);
memcpy (frame.payload, hash, 4);
// 5. Finalize
frame.payloadLen = 4;
sendFrame (frame);
}