Skip to content

Commit

Permalink
send want config on MT reboot and clear buffer after bad magic
Browse files Browse the repository at this point in the history
  • Loading branch information
pdxlocations committed Dec 9, 2024
1 parent aa022a1 commit 9a94dbd
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/mt_protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ bool handle_mesh_packet(meshtastic_MeshPacket *meshPacket) {
return true;
}

// Parse a packet that came in, and handle it. Return true iff we were able to parse it.
// Parse a packet that came in, and handle it. Return true if we were able to parse it.
bool handle_packet(uint32_t now, size_t payload_len) {
meshtastic_FromRadio fromRadio = meshtastic_FromRadio_init_zero;

Expand All @@ -212,6 +212,12 @@ bool handle_packet(uint32_t now, size_t payload_len) {
memmove(pb_buf, pb_buf+4+payload_len, PB_BUFSIZE-4-payload_len);
pb_size -= 4 + payload_len;

// Be prepared to request a node report to re-establish flow after an MT reboot
meshtastic_ToRadio toRadio = meshtastic_ToRadio_init_default;
toRadio.which_payload_variant = meshtastic_ToRadio_want_config_id_tag;
want_config_id = random(0x7FffFFff); // random() can't handle anything bigger
toRadio.want_config_id = want_config_id;

if (!status) {
d("Decoding failed");
return false;
Expand All @@ -226,6 +232,8 @@ bool handle_packet(uint32_t now, size_t payload_len) {
return handle_config_complete_id(now, fromRadio.config_complete_id);
case meshtastic_FromRadio_packet_tag:
return handle_mesh_packet(&fromRadio.packet);
case meshtastic_FromRadio_rebooted_tag:
_mt_send_toRadio(toRadio);
default:
if (mt_debugging) {
// Rate limit
Expand Down Expand Up @@ -254,6 +262,8 @@ void mt_protocol_check_packet(uint32_t now) {

if (pb_buf[0] != MT_MAGIC_0 || pb_buf[1] != MT_MAGIC_1) {
d("Got bad magic");
memset(pb_buf, 0, PB_BUFSIZE);
pb_size = 0;
return;
}

Expand Down

0 comments on commit 9a94dbd

Please sign in to comment.