Skip to content

Commit 9a94dbd

Browse files
committed
send want config on MT reboot and clear buffer after bad magic
1 parent aa022a1 commit 9a94dbd

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/mt_protocol.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ bool handle_mesh_packet(meshtastic_MeshPacket *meshPacket) {
201201
return true;
202202
}
203203

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

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

215+
// Be prepared to request a node report to re-establish flow after an MT reboot
216+
meshtastic_ToRadio toRadio = meshtastic_ToRadio_init_default;
217+
toRadio.which_payload_variant = meshtastic_ToRadio_want_config_id_tag;
218+
want_config_id = random(0x7FffFFff); // random() can't handle anything bigger
219+
toRadio.want_config_id = want_config_id;
220+
215221
if (!status) {
216222
d("Decoding failed");
217223
return false;
@@ -226,6 +232,8 @@ bool handle_packet(uint32_t now, size_t payload_len) {
226232
return handle_config_complete_id(now, fromRadio.config_complete_id);
227233
case meshtastic_FromRadio_packet_tag:
228234
return handle_mesh_packet(&fromRadio.packet);
235+
case meshtastic_FromRadio_rebooted_tag:
236+
_mt_send_toRadio(toRadio);
229237
default:
230238
if (mt_debugging) {
231239
// Rate limit
@@ -254,6 +262,8 @@ void mt_protocol_check_packet(uint32_t now) {
254262

255263
if (pb_buf[0] != MT_MAGIC_0 || pb_buf[1] != MT_MAGIC_1) {
256264
d("Got bad magic");
265+
memset(pb_buf, 0, PB_BUFSIZE);
266+
pb_size = 0;
257267
return;
258268
}
259269

0 commit comments

Comments
 (0)