diff --git a/src/TypeDef.h b/src/TypeDef.h index 0d250d50..e2d8c914 100644 --- a/src/TypeDef.h +++ b/src/TypeDef.h @@ -218,6 +218,11 @@ */ #define RADIOLIB_ERR_INVALID_RSSI_THRESHOLD (-27) +/*! + \brief A `NULL` pointer has been encountered. If you see this, there may be a potential security vulnerability. +*/ +#define RADIOLIB_ERR_NULL_POINTER (-28) + // RF69-specific status codes /*! diff --git a/src/modules/CC1101/CC1101.cpp b/src/modules/CC1101/CC1101.cpp index 6a5a0f2b..9407523b 100644 --- a/src/modules/CC1101/CC1101.cpp +++ b/src/modules/CC1101/CC1101.cpp @@ -89,7 +89,7 @@ int16_t CC1101::begin(float freq, float br, float freqDev, float rxBw, int8_t po RADIOLIB_ASSERT(state); // set default sync word - uint8_t sw[2] = RADIOLIB_CC1101_DEFAULT_SW; + uint8_t sw[RADIOLIB_CC1101_DEFAULT_SW_LEN] = RADIOLIB_CC1101_DEFAULT_SW; state = setSyncWord(sw[0], sw[1], 0, false); RADIOLIB_ASSERT(state); @@ -490,9 +490,7 @@ int16_t CC1101::setRxBandwidth(float rxBw) { float point = (RADIOLIB_CC1101_CRYSTAL_FREQ * 1000000.0)/(8 * (m + 4) * ((uint32_t)1 << e)); if(fabs((rxBw * 1000.0) - point) <= 1000) { // set Rx channel filter bandwidth - uint16_t state = SPIsetRegValue(RADIOLIB_CC1101_REG_MDMCFG4, (e << 6) | (m << 4), 7, 4); - - return(state); + return(SPIsetRegValue(RADIOLIB_CC1101_REG_MDMCFG4, (e << 6) | (m << 4), 7, 4)); } } @@ -526,6 +524,10 @@ int16_t CC1101::setFrequencyDeviation(float freqDev) { } int16_t CC1101::getFrequencyDeviation(float *freqDev) { + if (freqDev == NULL) { + return(RADIOLIB_ERR_NULL_POINTER); + } + // if ASK/OOK, deviation makes no sense if (_modulation == RADIOLIB_CC1101_MOD_FORMAT_ASK_OOK) { *freqDev = 0.0; @@ -534,7 +536,7 @@ int16_t CC1101::getFrequencyDeviation(float *freqDev) { } // get exponent and mantissa values from registers - uint8_t e = (uint8_t)SPIgetRegValue(RADIOLIB_CC1101_REG_DEVIATN, 6, 4); + uint8_t e = (uint8_t)(SPIgetRegValue(RADIOLIB_CC1101_REG_DEVIATN, 6, 4) >> 4); uint8_t m = (uint8_t)SPIgetRegValue(RADIOLIB_CC1101_REG_DEVIATN, 2, 0); // calculate frequency deviation (pag. 79 of the CC1101 datasheet): @@ -682,9 +684,7 @@ int16_t CC1101::setPreambleLength(uint8_t preambleLength) { return(RADIOLIB_ERR_INVALID_PREAMBLE_LENGTH); } - uint16_t state = SPIsetRegValue(RADIOLIB_CC1101_REG_MDMCFG1, value, 6, 4); - - return(state); + return(SPIsetRegValue(RADIOLIB_CC1101_REG_MDMCFG1, value, 6, 4)); } int16_t CC1101::setNodeAddress(uint8_t nodeAddr, uint8_t numBroadcastAddrs) { diff --git a/src/modules/CC1101/CC1101.h b/src/modules/CC1101/CC1101.h index 8c2100f2..bb245cbe 100644 --- a/src/modules/CC1101/CC1101.h +++ b/src/modules/CC1101/CC1101.h @@ -501,8 +501,8 @@ //Defaults #define RADIOLIB_CC1101_DEFAULT_FREQ 434.0 -#define RADIOLIB_CC1101_DEFAULT_BR 48.0 -#define RADIOLIB_CC1101_DEFAULT_FREQDEV 48.0 +#define RADIOLIB_CC1101_DEFAULT_BR 4.8 +#define RADIOLIB_CC1101_DEFAULT_FREQDEV 5.0 #define RADIOLIB_CC1101_DEFAULT_RXBW 135.0 #define RADIOLIB_CC1101_DEFAULT_POWER 10 #define RADIOLIB_CC1101_DEFAULT_PREAMBLELEN 16 @@ -536,7 +536,7 @@ class CC1101: public PhysicalLayer { /*! \brief Initialization method. - \param freq Carrier frequency in MHz. Defaults to 434.0 MHz. + \param freq Carrier frequency in MHz. Defaults to 434 MHz. \param br Bit rate to be used in kbps. Defaults to 4.8 kbps. @@ -550,7 +550,13 @@ class CC1101: public PhysicalLayer { \returns \ref status_codes */ - int16_t begin(float freq = 434.0, float br = 4.8, float freqDev = 5.0, float rxBw = 135.0, int8_t power = 10, uint8_t preambleLength = 16); + int16_t begin( + float freq = RADIOLIB_CC1101_DEFAULT_FREQ, + float br = RADIOLIB_CC1101_DEFAULT_BR, + float freqDev = RADIOLIB_CC1101_DEFAULT_FREQDEV, + float rxBw = RADIOLIB_CC1101_DEFAULT_RXBW, + int8_t power = RADIOLIB_CC1101_DEFAULT_POWER, + uint8_t preambleLength = RADIOLIB_CC1101_DEFAULT_PREAMBLELEN); /*! \brief Blocking binary transmit method. @@ -1006,7 +1012,6 @@ class CC1101: public PhysicalLayer { bool _crcOn = true; bool _directMode = true; - uint8_t _syncWordLength = RADIOLIB_CC1101_DEFAULT_SW_LEN; int8_t _power = RADIOLIB_CC1101_DEFAULT_POWER; diff --git a/src/modules/RF69/RF69.cpp b/src/modules/RF69/RF69.cpp index 5187c54c..5cfd833a 100644 --- a/src/modules/RF69/RF69.cpp +++ b/src/modules/RF69/RF69.cpp @@ -59,7 +59,7 @@ int16_t RF69::begin(float freq, float br, float freqDev, float rxBw, int8_t powe RADIOLIB_ASSERT(state); // configure bitrate - _rxBw = rxBw; + _rxBw = rxBw; state = setBitRate(br); RADIOLIB_ASSERT(state); @@ -615,7 +615,6 @@ int16_t RF69::setFrequencyDeviation(float freqDev) { setMode(RADIOLIB_RF69_STANDBY); // set frequency deviation from carrier frequency - uint32_t base = 1; uint32_t fdev = (newFreqDev * (uint32_t(1) << RADIOLIB_RF69_DIV_EXPONENT)) / 32000; int16_t state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_FDEV_MSB, (fdev & 0xFF00) >> 8, 5, 0); state |= _mod->SPIsetRegValue(RADIOLIB_RF69_REG_FDEV_LSB, fdev & 0x00FF, 7, 0); @@ -624,6 +623,10 @@ int16_t RF69::setFrequencyDeviation(float freqDev) { } int16_t RF69::getFrequencyDeviation(float *freqDev) { + if (freqDev == NULL) { + return(RADIOLIB_ERR_NULL_POINTER); + } + if (RF69::_ook) { *freqDev = 0.0; @@ -715,9 +718,8 @@ int16_t RF69::setPreambleLength(uint8_t preambleLen) { uint8_t preLenBytes = preambleLen / 8; _mod->SPIwriteRegister(RADIOLIB_RF69_REG_PREAMBLE_MSB, 0x00); - uint16_t state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_PREAMBLE_LSB, preLenBytes); - return (state); + return (_mod->SPIsetRegValue(RADIOLIB_RF69_REG_PREAMBLE_LSB, preLenBytes)); } int16_t RF69::setNodeAddress(uint8_t nodeAddr) { diff --git a/src/modules/RF69/RF69.h b/src/modules/RF69/RF69.h index 777d8d04..7cb41d90 100644 --- a/src/modules/RF69/RF69.h +++ b/src/modules/RF69/RF69.h @@ -464,8 +464,8 @@ // Defaults #define RADIOLIB_RF69_DEFAULT_FREQ 434.0 -#define RADIOLIB_RF69_DEFAULT_BR 48.0 -#define RADIOLIB_RF69_DEFAULT_FREQDEV 50.0 +#define RADIOLIB_RF69_DEFAULT_BR 4.8 +#define RADIOLIB_RF69_DEFAULT_FREQDEV 5.0 #define RADIOLIB_RF69_DEFAULT_RXBW 125.0 #define RADIOLIB_RF69_DEFAULT_POWER 10 #define RADIOLIB_RF69_DEFAULT_PREAMBLELEN 16 @@ -512,14 +512,14 @@ class RF69: public PhysicalLayer { \returns \ref status_codes */ - //int16_t begin(float freq = 434.0, float br = 4.8, float freqDev = 5.0, float rxBw = 125.0, int8_t power = 10, uint8_t preambleLen = 16); int16_t begin( - float freq = RADIOLIB_RF69_DEFAULT_FREQ, - float br = RADIOLIB_RF69_DEFAULT_BR, - float freqDev = RADIOLIB_RF69_DEFAULT_FREQDEV, - float rxBw = RADIOLIB_RF69_DEFAULT_RXBW, - int8_t power = RADIOLIB_RF69_DEFAULT_POWER, - uint8_t preambleLen = RADIOLIB_RF69_DEFAULT_PREAMBLELEN); + float freq = RADIOLIB_RF69_DEFAULT_FREQ, + float br = RADIOLIB_RF69_DEFAULT_BR, + float freqDev = RADIOLIB_RF69_DEFAULT_FREQDEV, + float rxBw = RADIOLIB_RF69_DEFAULT_RXBW, + int8_t power = RADIOLIB_RF69_DEFAULT_POWER, + uint8_t preambleLen = RADIOLIB_RF69_DEFAULT_PREAMBLELEN); + /*! \brief Reset method. Will reset the chip to the default state using RST pin. */ diff --git a/src/modules/nRF24/nRF24.cpp b/src/modules/nRF24/nRF24.cpp index fdc3f6f9..f00f42e3 100644 --- a/src/modules/nRF24/nRF24.cpp +++ b/src/modules/nRF24/nRF24.cpp @@ -254,8 +254,7 @@ int16_t nRF24::setFrequency(float freq) { // set frequency uint8_t freqRaw = (uint16_t)freq - 2400; - //return(_mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_CH, freqRaw, 6, 0)); - uint16_t state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_CH, freqRaw, 6, 0); + int16_t state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_CH, freqRaw, 6, 0); if(state == RADIOLIB_ERR_NONE) { _freq = freq; diff --git a/src/modules/nRF24/nRF24.h b/src/modules/nRF24/nRF24.h index bf3d8b06..72605c6f 100644 --- a/src/modules/nRF24/nRF24.h +++ b/src/modules/nRF24/nRF24.h @@ -215,12 +215,12 @@ class nRF24: public PhysicalLayer { \returns \ref status_codes */ - //int16_t begin(int16_t freq = 2400, int16_t dataRate = 1000, int8_t power = -12, uint8_t addrWidth = 5); int16_t begin( - int16_t freq = RADIOLIB_NRF24_DEFAULT_FREQ, - int16_t dataRate = RADIOLIB_NRF24_DEFAULT_DR, - int8_t power = RADIOLIB_NRF24_DEFAULT_POWER, - uint8_t addrWidth = RADIOLIB_NRF24_DEFAULT_ADDRWIDTH); + int16_t freq = RADIOLIB_NRF24_DEFAULT_FREQ, + int16_t dataRate = RADIOLIB_NRF24_DEFAULT_DR, + int8_t power = RADIOLIB_NRF24_DEFAULT_POWER, + uint8_t addrWidth = RADIOLIB_NRF24_DEFAULT_ADDRWIDTH); + /*! \brief Sets the module to sleep mode. @@ -520,7 +520,6 @@ class nRF24: public PhysicalLayer { protected: #endif - //uint8_t _addrWidth = 0; int16_t _freq = RADIOLIB_NRF24_DEFAULT_FREQ; int16_t _dataRate = RADIOLIB_NRF24_DEFAULT_DR; int8_t _power = RADIOLIB_NRF24_DEFAULT_POWER;