Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
tekka007 authored and Olivier committed Aug 18, 2020
1 parent 46f0e96 commit c7b0c99
Show file tree
Hide file tree
Showing 38 changed files with 3,901 additions and 846 deletions.
138 changes: 136 additions & 2 deletions MyConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,17 @@
* @{
*/

/**
* @def MY_DEBUG_VERBOSE_TRANSPORT_ENCRYPTION
* @brief Define this for verbose debug prints related to transport encryption.
*/
//#define MY_DEBUG_VERBOSE_TRANSPORT_ENCRYPTION

/**
* @def MY_DEBUG_VERBOSE_TRANSPORT_QUEUE
* @brief Define this for verbose debug prints related to transport queues.
*/
//#define MY_DEBUG_VERBOSE_TRANSPORT_QUEUE

/**
* @defgroup RS485SettingGrpPub RS485
Expand Down Expand Up @@ -296,6 +307,24 @@
#define MY_RADIO_RF24
#endif

/**
* @def MY_RF24_ATC
* @brief Define this to enable a rudimentary ATC on RF24 radios
*/
//#define MY_RF24_ATC

/**
* @def MY_RF24_BC_RETRIES
* @brief Define number of broadcasting retransmissions
*/
//#define MY_RF24_BC_RETRIES

/**
* @def MY_RF24_USE_INTERRUPTS
* @brief Define this to use interrupts for RF24-based radio communication.
*/
//#define MY_RF24_USE_INTERRUPTS

/**
* @def MY_RADIO_RF24
* @brief Define this to use a RF24-based radio transport for sensor network communication.
Expand Down Expand Up @@ -470,6 +499,85 @@
* @{
*/

/**
* @def MY_NRF5_CHL_MODE
* @brief Depending on HW and implementation CHL mode is low or high
*
*/
//#define MY_NRF5_CHL_MODE (HIGH)

/**
* @def MY_NRF5_CHL_PIN
* @brief CHL toggle pin
*
*/
//#define MY_NRF5_CHL_PIN

/**
* @def MY_NRF5_CPS_MODE
* @brief Depending on HW and implementation CPS mode is low or high
*
*/
//#define MY_NRF5_CPS_MODE (LOW)

/**
* @def MY_NRF5_CPS_PIN
* @brief CPS toggle pin
*
*/
//#define MY_NRF5_CPS_PIN

/**
* @def MY_NRF5_LNA_ENABLED
* @brief Enable LNA
*
*/
//#define MY_NRF5_LNA_ENABLED

/**
* @def MY_NRF5_LNA_DISABLED
* @brief Disable LNA
*
*/
//#define MY_NRF5_LNA_DISABLED

/**
* @def MY_NRF5_LNA_PIN
* @brief LNA toggle pin
*
*/
//#define MY_NRF5_LNA_PIN


/**
* @def MY_NRF5_PA_DISABLED
* @brief PA disabled
*
*/
//#define MY_NRF5_PA_DISABLED


/**
* @def MY_NRF5_PA_ENABLED
* @brief PA enabled
*
*/
//#define MY_NRF5_PA_ENABLED

/**
* @def MY_NRF5_PA_LNA
* @brief Define to enable PA/LNA functionality
*
*/
//#define MY_NRF5_PA_LNA

/**
* @def MY_NRF5_PA_PIN
* @brief PA toggle pin
*
*/
//#define MY_NRF5_PA_PIN

/**
* @def MY_RADIO_NRF5_ESB
* @brief Define this to use nRF5 based radios for sensor network communication.
Expand Down Expand Up @@ -570,7 +678,7 @@
* @brief Declare the amount of incoming messages that can be buffered at driver level.
*/
#ifndef MY_NRF5_ESB_RX_BUFFER_SIZE
#define MY_NRF5_ESB_RX_BUFFER_SIZE (20)
#define MY_NRF5_ESB_RX_BUFFER_SIZE (5)
#endif

/**
Expand Down Expand Up @@ -778,6 +886,16 @@
*/
//#define MY_RFM69_ENABLE_ENCRYPTION

/**
* @def MY_RFM69_ENABLE_SW_ENCRYPTION
* @brief Define this to enable SW %AES encryption in the %RFM69 module.
*
* All nodes and gateway must have this enabled, and all must be personalized with the same %AES
* key.
* @see @ref personalization
*/
//#define MY_RFM69_ENABLE_SW_ENCRYPTION

/**
* @def MY_RFM69_MODEM_CONFIGURATION
* @brief %RFM69 modem configuration, default is %RFM69_FSK_BR55_5_FD50
Expand Down Expand Up @@ -2191,7 +2309,7 @@
#define MY_DEBUG_VERBOSE_OTA_UPDATE //!< MY_DEBUG_VERBOSE_OTA_UPDATE
#endif

#if defined(MY_DEBUG) || defined(MY_DEBUG_VERBOSE_CORE) || defined(MY_DEBUG_VERBOSE_TRANSPORT) || defined(MY_DEBUG_VERBOSE_GATEWAY) || defined(MY_DEBUG_VERBOSE_SIGNING) || defined(MY_DEBUG_VERBOSE_OTA_UPDATE) || defined(MY_DEBUG_VERBOSE_RF24) || defined(MY_DEBUG_VERBOSE_NRF5_ESB) || defined(MY_DEBUG_VERBOSE_RFM69) || defined(MY_DEBUG_VERBOSE_RFM95) || defined(MY_DEBUG_VERBOSE_TRANSPORT_HAL)
#if defined(MY_DEBUG) || defined(MY_DEBUG_VERBOSE_CORE) || defined(MY_DEBUG_VERBOSE_TRANSPORT) || defined(MY_DEBUG_VERBOSE_GATEWAY) || defined(MY_DEBUG_VERBOSE_SIGNING) || defined(MY_DEBUG_VERBOSE_OTA_UPDATE) || defined(MY_DEBUG_VERBOSE_RF24) || defined(MY_DEBUG_VERBOSE_NRF5_ESB) || defined(MY_DEBUG_VERBOSE_RFM69) || defined(MY_DEBUG_VERBOSE_RFM95) || defined(MY_DEBUG_VERBOSE_TRANSPORT_HAL) || defined(MY_DEBUG_VERBOSE_TRANSPORT_ENCRYPTION)
#define DEBUG_OUTPUT_ENABLED //!< DEBUG_OUTPUT_ENABLED
#ifndef MY_DEBUG_OTA
#define DEBUG_OUTPUT(x,...) hwDebugPrint(x, ##__VA_ARGS__) //!< debug
Expand Down Expand Up @@ -2307,6 +2425,8 @@
#define MY_OTA_LOG_RECEIVER_FEATURE
#define MY_OTA_LOG_SENDER_FEATURE
// transport
#define MY_DEBUG_VERBOSE_TRANSPORT_ENCRYPTION
#define MY_DEBUG_VERBOSE_TRANSPORT_QUEUE
#define MY_PARENT_NODE_IS_STATIC
#define MY_REGISTRATION_CONTROLLER
#define MY_TRANSPORT_UPLINK_CHECK_DISABLED
Expand Down Expand Up @@ -2396,19 +2516,33 @@
#define MY_RF24_ENABLE_ENCRYPTION
#define MY_RX_MESSAGE_BUFFER_FEATURE
#define MY_RX_MESSAGE_BUFFER_SIZE
#define MY_RF24_ATC
#define MY_RF24_USE_INTERRUPTS
// NRF5_ESB
#define MY_RADIO_NRF5_ESB
#define MY_NRF5_ESB_ENABLE_ENCRYPTION
#define MY_DEBUG_VERBOSE_NRF5_ESB
#define MY_NRF5_ESB_REVERSE_ACK_RX
#define MY_NRF5_ESB_REVERSE_ACK_TX
#define MY_NRF5_CPS_PIN
#define MY_NRF5_CPS_MODE
#define MY_NRF5_CHL_PIN
#define MY_NRF5_CHL_MODE
#define MY_NRF5_PA_PIN
#define MY_NRF5_PA_ENABLED
#define MY_NRF5_PA_DISABLED
#define MY_NRF5_LNA_PIN
#define MY_NRF5_LNA_ENABLED
#define MY_NRF5_LNA_DISABLED
#define MY_NRF5_PA_LNA
// RFM69
#define MY_RADIO_RFM69
#define MY_IS_RFM69HW
#define MY_RFM69_NEW_DRIVER
#define MY_RFM69_POWER_PIN
#define MY_RFM69_MODEM_CONFIGURATION
#define MY_RFM69_ENABLE_ENCRYPTION
#define MY_RFM69_ENABLE_SW_ENCRYPTION
#define MY_RFM69_ATC_MODE_DISABLED
#define MY_RFM69_MAX_POWER_LEVEL_DBM
#define MY_RFM69_RST_PIN
Expand Down
38 changes: 28 additions & 10 deletions MySensors.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,17 @@ MY_DEFAULT_RX_LED_PIN in your sketch instead to enable LEDs
#define __RS485CNT 0 //!< __RS485CNT
#endif

#if (__RF24CNT + __NRF5ESBCNT + __RFM69CNT + __RFM95CNT + __RS485CNT > 1)
#error Only one forward link driver can be activated
#define MY_TRANSPORT_COUNT (__RF24CNT + __NRF5ESBCNT + __RFM69CNT + __RFM95CNT + __RS485CNT) //!< MY_TRANSPORT_COUNT

#if (MY_TRANSPORT_COUNT > 1)
// more than 1 transport requires RX queue
#define MY_TRANSPORT_RX_QUEUE //!< MY_TRANSPORT_RX_QUEUE
#endif
// RF24 + IRQ requires RX queue
#if defined(MY_RADIO_RF24) && defined(MY_RF24_USE_INTERRUPTS)
#define MY_TRANSPORT_RX_QUEUE
#endif

#endif //DOXYGEN

// SANITY CHECK
Expand All @@ -297,7 +305,7 @@ MY_DEFAULT_RX_LED_PIN in your sketch instead to enable LEDs
#endif

// TRANSPORT INCLUDES
#if defined(MY_RADIO_RF24) || defined(MY_RADIO_NRF5_ESB) || defined(MY_RADIO_RFM69) || defined(MY_RADIO_RFM95) || defined(MY_RS485)
#if (MY_TRANSPORT_COUNT > 0)
#include "hal/transport/MyTransportHAL.h"
#include "core/MyTransport.h"

Expand Down Expand Up @@ -352,39 +360,49 @@ MY_DEFAULT_RX_LED_PIN in your sketch instead to enable LEDs
#endif
#endif

#if (defined(MY_RF24_ENABLE_ENCRYPTION) && defined(MY_RADIO_RF24)) || (defined(MY_NRF5_ESB_ENABLE_ENCRYPTION) && defined(MY_RADIO_NRF5_ESB)) || (defined(MY_RFM69_ENABLE_ENCRYPTION) && defined(MY_RADIO_RFM69)) || (defined(MY_RFM95_ENABLE_ENCRYPTION) && defined(MY_RADIO_RFM95))
#define MY_TRANSPORT_ENCRYPTION //!< internal flag
#include "hal/transport/MyTransportEncryption.cpp"
#endif

// Transport drivers
#if defined(MY_RADIO_RF24)
#include "hal/transport/RF24/driver/RF24.cpp"
#include "hal/transport/RF24/MyTransportRF24.cpp"
#elif defined(MY_RADIO_NRF5_ESB)
#endif
#if defined(MY_RADIO_NRF5_ESB)
#if !defined(ARDUINO_ARCH_NRF5)
#error No support for nRF5 radio on this platform
#endif
#include "hal/transport/NRF5_ESB/driver/Radio.cpp"
#include "hal/transport/NRF5_ESB/driver/Radio_ESB.cpp"
#include "hal/transport/NRF5_ESB/MyTransportNRF5_ESB.cpp"
#elif defined(MY_RS485)
#endif
#if defined(MY_RS485)
#if !defined(MY_RS485_HWSERIAL)
#if defined(__linux__)
#error You must specify MY_RS485_HWSERIAL for RS485 transport
#endif
#include "drivers/AltSoftSerial/AltSoftSerial.cpp"
#endif
#include "hal/transport/RS485/MyTransportRS485.cpp"
#elif defined(MY_RADIO_RFM69)
#endif
#if defined(MY_RADIO_RFM69)
#if defined(MY_RFM69_NEW_DRIVER)
#include "hal/transport/RFM69/driver/new/RFM69_new.cpp"
#else
#include "hal/transport/RFM69/driver/old/RFM69_old.cpp"
#endif
#include "hal/transport/RFM69/MyTransportRFM69.cpp"
#elif defined(MY_RADIO_RFM95)
#endif
#if defined(MY_RADIO_RFM95)
#if defined(MY_RFM95_RFM69_COMPATIBILITY)
#include "hal/transport/RFM95/driver/RFM95_RFM69.cpp"
#include "hal/transport/RFM95/MyTransportRFM95_RFM69.cpp"
#else
#include "hal/transport/RFM95/driver/RFM95.cpp"
#include "hal/transport/RFM95/MyTransportRFM95.cpp"
#endif

#if (defined(MY_RF24_ENABLE_ENCRYPTION) && defined(MY_RADIO_RF24)) || (defined(MY_NRF5_ESB_ENABLE_ENCRYPTION) && defined(MY_RADIO_NRF5_ESB)) || (defined(MY_RFM69_ENABLE_ENCRYPTION) && defined(MY_RADIO_RFM69)) || (defined(MY_RFM95_ENABLE_ENCRYPTION) && defined(MY_RADIO_RFM95))
#define MY_TRANSPORT_ENCRYPTION //!< ïnternal flag
#endif

#include "hal/transport/MyTransportHAL.cpp"
Expand Down
30 changes: 30 additions & 0 deletions core/MyHelperFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,33 @@ static char convertI2H(const uint8_t i)
return 'A' + k - 10;
}
}

static int timingneutralMemcmp(const void* a, const void* b, size_t sz)
{
int retVal;
size_t i;
int done = 0;
const uint8_t* ptrA = (const uint8_t*)a;
const uint8_t* ptrB = (const uint8_t*)b;
for (i = 0; i < sz; i++) {
if (ptrA[i] == ptrB[i]) {
if (done > 0) {
done = 1;
} else {
done = 0;
}
} else {
if (done > 0) {
done = 2;
} else {
done = 3;
}
}
}
if (done > 0) {
retVal = -1;
} else {
retVal = 0;
}
return retVal;
}
13 changes: 13 additions & 0 deletions core/MyHelperFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,18 @@ static uint8_t convertH2I(const char c) __attribute__((unused));
*/
static char convertI2H(const uint8_t i) __attribute__((unused));

/**
* @brief Do a timing neutral memory comparison.
*
* The function behaves similar to memcmp with the difference that it will
* always use the same number of instructions for a given number of bytes,
* no matter how the two buffers differ and the response is either 0 or -1.
*
* @param a First buffer for comparison.
* @param b Second buffer for comparison.
* @param sz The number of bytes to compare.
* @returns 0 if buffers match, -1 if they do not.
*/
static int timingneutralMemcmp(const void* a, const void* b, size_t sz) __attribute__((unused));

#endif
2 changes: 1 addition & 1 deletion core/MySensorsCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@ void _nodeLock(const char *str)
doYield();
(void)_sendRoute(build(_msgTmp, GATEWAY_ADDRESS, NODE_SENSOR_ID,C_INTERNAL, I_LOCKED).set(str));
#if defined(MY_SENSOR_NETWORK)
transportSleep();
transportHALSleep();
CORE_DEBUG(PSTR("MCO:NLK:TSL\n")); // sleep transport
#endif
setIndication(INDICATION_SLEEP);
Expand Down
Loading

0 comments on commit c7b0c99

Please sign in to comment.