Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions src/mesh/RadioInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1462,10 +1462,18 @@ void RadioInterface::deliverToReceiver(meshtastic_MeshPacket *p)
*/
size_t RadioInterface::beginSending(meshtastic_MeshPacket *p)
{
assert(!sendingPacket);

// LOG_DEBUG("Send queued packet on mesh (txGood=%d,rxGood=%d,rxBad=%d)", rf95.txGood(), rf95.rxGood(), rf95.rxBad());
assert(p->which_payload_variant == meshtastic_MeshPacket_encrypted_tag); // It should have already been encoded by now
// These used to be asserts, which hang forever with no diagnostic on STM32WL. Reject and release
// instead - the caller must treat a 0 return as "not sent, p already released".
if (sendingPacket) {
LOG_ERROR("beginSending called while a send is already in progress");
packetPool.release(p);
return 0;
}
if (p->which_payload_variant != meshtastic_MeshPacket_encrypted_tag) {
LOG_ERROR("beginSending called with an unencrypted packet");
packetPool.release(p);
return 0;
}

radioBuffer.header.from = p->from;
radioBuffer.header.to = p->to;
Expand All @@ -1482,8 +1490,17 @@ size_t RadioInterface::beginSending(meshtastic_MeshPacket *p)
radioBuffer.header.flags |= (p->hop_start << PACKET_FLAGS_HOP_START_SHIFT) & PACKET_FLAGS_HOP_START_MASK;

// if the sender nodenum is zero, that means uninitialized
assert(radioBuffer.header.from);
assert(p->encrypted.size <= sizeof(radioBuffer.payload));
if (!radioBuffer.header.from) {
LOG_ERROR("beginSending called with an unset sender node num");
packetPool.release(p);
return 0;
}
if (p->encrypted.size > sizeof(radioBuffer.payload)) {
LOG_ERROR("beginSending: encrypted size %u exceeds radio buffer capacity %zu", p->encrypted.size,
sizeof(radioBuffer.payload));
packetPool.release(p);
return 0;
}
memcpy(radioBuffer.payload, p->encrypted.bytes, p->encrypted.size);

sendingPacket = p;
Expand Down
2 changes: 2 additions & 0 deletions src/mesh/RadioLibInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,8 @@ bool RadioLibInterface::startSend(meshtastic_MeshPacket *txp)
configHardwareForSend(); // must be after setStandby

size_t numbytes = beginSending(txp);
if (numbytes == 0) // beginSending() already released txp and logged why
return false;

int res = iface->startTransmit((uint8_t *)&radioBuffer, numbytes);
if (res != RADIOLIB_ERR_NONE) {
Expand Down
2 changes: 2 additions & 0 deletions src/platform/portduino/SimRadio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ void SimRadio::startSend(meshtastic_MeshPacket *txp)
printPacket("Start low level send", txp);
isReceiving = false;
size_t numbytes = beginSending(txp);
if (numbytes == 0) // beginSending() already released txp and logged why
return;
meshtastic_MeshPacket *p = packetPool.allocCopy(*txp);
if (!p)
return;
Expand Down