Fix buffer overrun and freezing bugs

This commit is contained in:
jacob.eva 2024-10-15 17:34:16 +01:00
parent 858a35b2f9
commit f6fe7e2b5f
No known key found for this signature in database
GPG Key ID: 0B92E083BBCCAA1E
4 changed files with 9 additions and 11 deletions

View File

@ -80,8 +80,7 @@
bool memory_low = false; bool memory_low = false;
uint8_t implicit_l = 0; uint8_t implicit_l = 0;
volatile bool packet_ready = false; uint8_t packet_interface = 0xFF;
volatile uint8_t packet_interface = 0xFF;
uint8_t op_mode = MODE_HOST; uint8_t op_mode = MODE_HOST;
uint8_t model = 0x00; uint8_t model = 0x00;

View File

@ -79,8 +79,8 @@ typedef struct {
size_t len; size_t len;
int rssi; int rssi;
int snr_raw; int snr_raw;
uint8_t data[];
uint8_t interface; uint8_t interface;
uint8_t data[];
} modem_packet_t; } modem_packet_t;
static xQueueHandle modem_packet_queue = NULL; static xQueueHandle modem_packet_queue = NULL;
@ -392,7 +392,7 @@ inline void getPacketData(RadioInterface* radio, uint16_t len) {
#endif #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 // Allocate packet struct, but abort if there
// is not enough memory available. // is not enough memory available.
modem_packet_t *modem_packet = (modem_packet_t*)malloc(sizeof(modem_packet_t) + read_len); 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); memcpy(modem_packet->data, pbuf, read_len);
if (!modem_packet_queue || xQueueSendFromISR(modem_packet_queue, &modem_packet, NULL) != pdPASS) { if (!modem_packet_queue || xQueueSendFromISR(modem_packet_queue, &modem_packet, NULL) != pdPASS) {
free(modem_packet); free(modem_packet);
return false;
} }
return true;
} }
void ISR_VECT receive_callback(uint8_t index, int packet_size) { 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) { if (ready) {
queuePacket(selected_radio, index); queue_packet(selected_radio, index);
} }
last_rx = millis(); last_rx = millis();

View File

@ -129,7 +129,7 @@ sx126x::sx126x(uint8_t index, SPIClass* spi, bool tcxo, bool dio2_as_rf_switch,
setTimeout(0); setTimeout(0);
// TODO, figure out why this has to be done. Using the index to reference the // TODO, figure out why this has to be done. Using the index to reference the
// interface_obj list causes a crash otherwise // interface_obj list causes a crash otherwise
_index = getIndex(); //_index = getIndex();
} }
bool sx126x::preInit() { bool sx126x::preInit() {
@ -1098,7 +1098,7 @@ sx127x::sx127x(uint8_t index, SPIClass* spi, int ss, int sclk, int mosi, int mis
setTimeout(0); setTimeout(0);
// TODO, figure out why this has to be done. Using the index to reference the // TODO, figure out why this has to be done. Using the index to reference the
// interface_obj list causes a crash otherwise // interface_obj list causes a crash otherwise
_index = getIndex(); //_index = getIndex();
} }
void sx127x::setSPIFrequency(uint32_t frequency) { _spiSettings = SPISettings(frequency, MSBFIRST, SPI_MODE0); } 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); setTimeout(0);
// TODO, figure out why this has to be done. Using the index to reference the // TODO, figure out why this has to be done. Using the index to reference the
// interface_obj list causes a crash otherwise // interface_obj list causes a crash otherwise
_index = getIndex(); //_index = getIndex();
} }
bool sx128x::preInit() { bool sx128x::preInit() {

View File

@ -451,7 +451,6 @@ private:
int _fifo_tx_addr_ptr; int _fifo_tx_addr_ptr;
int _fifo_rx_addr_ptr; int _fifo_rx_addr_ptr;
bool _preinit_done; bool _preinit_done;
uint8_t _index;
bool _tcxo; bool _tcxo;
bool _dio2_as_rf_switch; bool _dio2_as_rf_switch;
}; };
@ -545,7 +544,6 @@ private:
int _packetIndex; int _packetIndex;
int _implicitHeaderMode; int _implicitHeaderMode;
bool _preinit_done; bool _preinit_done;
uint8_t _index;
uint8_t _sf; uint8_t _sf;
uint8_t _cr; uint8_t _cr;
}; };
@ -664,7 +662,6 @@ private:
int _fifo_rx_addr_ptr; int _fifo_rx_addr_ptr;
bool _preinit_done; bool _preinit_done;
int _rxPacketLength; int _rxPacketLength;
uint8_t _index;
bool _tcxo; bool _tcxo;
}; };
#endif #endif