]> git.tnoah.ca Git - lora-radio.git/commitdiff
Fix buffer overrun and freezing bugs
authorjacob.eva <x00010@disroot.org>
Tue, 15 Oct 2024 16:34:16 +0000 (17:34 +0100)
committerjacob.eva <x00010@disroot.org>
Tue, 15 Oct 2024 16:34:16 +0000 (17:34 +0100)
Config.h
RNode_Firmware_CE.ino
Radio.cpp
Radio.hpp

index 47980623fd9e574b5b21cc2d67a397853f85dce7..bfa07ffde9782661ea7601fd8d3b5ea1d9f5730c 100644 (file)
--- a/Config.h
+++ b/Config.h
@@ -80,8 +80,7 @@
        bool memory_low    = false;
        uint8_t implicit_l = 0;
 
-    volatile bool packet_ready  = false;
-    volatile uint8_t packet_interface = 0xFF;
+    uint8_t packet_interface = 0xFF;
 
        uint8_t op_mode   = MODE_HOST;
        uint8_t model     = 0x00;
index 48c38e4f900ea3b3dff8b30435e4201dc77121d0..5f80700caa9c4c1aad952fc882726cef3f7d1819 100644 (file)
@@ -79,8 +79,8 @@ typedef struct {
       size_t len;
       int rssi;
       int snr_raw;
-      uint8_t data[];
       uint8_t interface;
+      uint8_t data[];
 } modem_packet_t;
 static xQueueHandle modem_packet_queue = NULL;
 
@@ -392,7 +392,7 @@ inline void getPacketData(RadioInterface* radio, uint16_t len) {
   #endif
 }
 
-inline bool queuePacket(RadioInterface* radio, uint8_t index) {
+inline bool queue_packet(RadioInterface* radio, uint8_t index) {
     // Allocate packet struct, but abort if there
     // is not enough memory available.
     modem_packet_t *modem_packet = (modem_packet_t*)malloc(sizeof(modem_packet_t) + read_len);
@@ -413,7 +413,9 @@ inline bool queuePacket(RadioInterface* radio, uint8_t index) {
     memcpy(modem_packet->data, pbuf, read_len);
     if (!modem_packet_queue || xQueueSendFromISR(modem_packet_queue, &modem_packet, NULL) != pdPASS) {
         free(modem_packet);
+        return false;
     }
+    return true;
 }
 
 void ISR_VECT receive_callback(uint8_t index, int packet_size) {
@@ -500,7 +502,7 @@ void ISR_VECT receive_callback(uint8_t index, int packet_size) {
   }
 
   if (ready) {
-      queuePacket(selected_radio, index);
+      queue_packet(selected_radio, index);
   }
 
   last_rx = millis();
index 07485cef4573f1ebb8cf0439933326a51f155a24..89e68d0175d28425dbea56abefca7189b8dac2b7 100644 (file)
--- a/Radio.cpp
+++ b/Radio.cpp
@@ -129,7 +129,7 @@ sx126x::sx126x(uint8_t index, SPIClass* spi, bool tcxo, bool dio2_as_rf_switch,
   setTimeout(0);
   // TODO, figure out why this has to be done. Using the index to reference the
   // interface_obj list causes a crash otherwise
-  _index = getIndex();
+  //_index = getIndex();
 }
 
 bool sx126x::preInit() {
@@ -1098,7 +1098,7 @@ sx127x::sx127x(uint8_t index, SPIClass* spi, int ss, int sclk, int mosi, int mis
     setTimeout(0); 
     // TODO, figure out why this has to be done. Using the index to reference the
     // interface_obj list causes a crash otherwise
-    _index = getIndex();
+    //_index = getIndex();
 }
 
 void sx127x::setSPIFrequency(uint32_t frequency) { _spiSettings = SPISettings(frequency, MSBFIRST, SPI_MODE0); }
@@ -1628,7 +1628,7 @@ sx128x::sx128x(uint8_t index, SPIClass* spi, bool tcxo, int ss, int sclk, int mo
   setTimeout(0);
   // TODO, figure out why this has to be done. Using the index to reference the
   // interface_obj list causes a crash otherwise
-  _index = getIndex();
+  //_index = getIndex();
 }
 
 bool sx128x::preInit() {
index 8413ebc2a5cf19860e8259b928b88f41b5d520e8..208a3d29db792716e253cd78927411f88bd85c74 100644 (file)
--- a/Radio.hpp
+++ b/Radio.hpp
@@ -451,7 +451,6 @@ private:
   int _fifo_tx_addr_ptr;
   int _fifo_rx_addr_ptr;
   bool _preinit_done;
-  uint8_t _index;
   bool _tcxo;
   bool _dio2_as_rf_switch;
 };
@@ -545,7 +544,6 @@ private:
   int _packetIndex;
   int _implicitHeaderMode;
   bool _preinit_done;
-  uint8_t _index;
   uint8_t _sf;
   uint8_t _cr;
 };
@@ -664,7 +662,6 @@ private:
   int _fifo_rx_addr_ptr;
   bool _preinit_done;
   int _rxPacketLength;
-  uint8_t _index;
   bool _tcxo;
 };
 #endif