Skip to content

Commit a3e7786

Browse files
tekka007Olivier
authored and
Olivier
committed
Initial commit
1 parent 46f0e96 commit a3e7786

36 files changed

+3899
-844
lines changed

MyConfig.h

+136-2
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,17 @@
204204
* @{
205205
*/
206206

207+
/**
208+
* @def MY_DEBUG_VERBOSE_TRANSPORT_ENCRYPTION
209+
* @brief Define this for verbose debug prints related to transport encryption.
210+
*/
211+
//#define MY_DEBUG_VERBOSE_TRANSPORT_ENCRYPTION
212+
213+
/**
214+
* @def MY_DEBUG_VERBOSE_TRANSPORT_QUEUE
215+
* @brief Define this for verbose debug prints related to transport queues.
216+
*/
217+
//#define MY_DEBUG_VERBOSE_TRANSPORT_QUEUE
207218

208219
/**
209220
* @defgroup RS485SettingGrpPub RS485
@@ -296,6 +307,24 @@
296307
#define MY_RADIO_RF24
297308
#endif
298309

310+
/**
311+
* @def MY_RF24_ATC
312+
* @brief Define this to enable a rudimentary ATC on RF24 radios
313+
*/
314+
//#define MY_RF24_ATC
315+
316+
/**
317+
* @def MY_RF24_BC_RETRIES
318+
* @brief Define number of broadcasting retransmissions
319+
*/
320+
//#define MY_RF24_BC_RETRIES
321+
322+
/**
323+
* @def MY_RF24_USE_INTERRUPTS
324+
* @brief Define this to use interrupts for RF24-based radio communication.
325+
*/
326+
//#define MY_RF24_USE_INTERRUPTS
327+
299328
/**
300329
* @def MY_RADIO_RF24
301330
* @brief Define this to use a RF24-based radio transport for sensor network communication.
@@ -470,6 +499,85 @@
470499
* @{
471500
*/
472501

502+
/**
503+
* @def MY_NRF5_CHL_MODE
504+
* @brief Depending on HW and implementation CHL mode is low or high
505+
*
506+
*/
507+
//#define MY_NRF5_CHL_MODE (HIGH)
508+
509+
/**
510+
* @def MY_NRF5_CHL_PIN
511+
* @brief CHL toggle pin
512+
*
513+
*/
514+
//#define MY_NRF5_CHL_PIN
515+
516+
/**
517+
* @def MY_NRF5_CPS_MODE
518+
* @brief Depending on HW and implementation CPS mode is low or high
519+
*
520+
*/
521+
//#define MY_NRF5_CPS_MODE (LOW)
522+
523+
/**
524+
* @def MY_NRF5_CPS_PIN
525+
* @brief CPS toggle pin
526+
*
527+
*/
528+
//#define MY_NRF5_CPS_PIN
529+
530+
/**
531+
* @def MY_NRF5_LNA_ENABLED
532+
* @brief Enable LNA
533+
*
534+
*/
535+
//#define MY_NRF5_LNA_ENABLED
536+
537+
/**
538+
* @def MY_NRF5_LNA_DISABLED
539+
* @brief Disable LNA
540+
*
541+
*/
542+
//#define MY_NRF5_LNA_DISABLED
543+
544+
/**
545+
* @def MY_NRF5_LNA_PIN
546+
* @brief LNA toggle pin
547+
*
548+
*/
549+
//#define MY_NRF5_LNA_PIN
550+
551+
552+
/**
553+
* @def MY_NRF5_PA_DISABLED
554+
* @brief PA disabled
555+
*
556+
*/
557+
//#define MY_NRF5_PA_DISABLED
558+
559+
560+
/**
561+
* @def MY_NRF5_PA_ENABLED
562+
* @brief PA enabled
563+
*
564+
*/
565+
//#define MY_NRF5_PA_ENABLED
566+
567+
/**
568+
* @def MY_NRF5_PA_LNA
569+
* @brief Define to enable PA/LNA functionality
570+
*
571+
*/
572+
//#define MY_NRF5_PA_LNA
573+
574+
/**
575+
* @def MY_NRF5_PA_PIN
576+
* @brief PA toggle pin
577+
*
578+
*/
579+
//#define MY_NRF5_PA_PIN
580+
473581
/**
474582
* @def MY_RADIO_NRF5_ESB
475583
* @brief Define this to use nRF5 based radios for sensor network communication.
@@ -570,7 +678,7 @@
570678
* @brief Declare the amount of incoming messages that can be buffered at driver level.
571679
*/
572680
#ifndef MY_NRF5_ESB_RX_BUFFER_SIZE
573-
#define MY_NRF5_ESB_RX_BUFFER_SIZE (20)
681+
#define MY_NRF5_ESB_RX_BUFFER_SIZE (5)
574682
#endif
575683

576684
/**
@@ -778,6 +886,16 @@
778886
*/
779887
//#define MY_RFM69_ENABLE_ENCRYPTION
780888

889+
/**
890+
* @def MY_RFM69_ENABLE_SW_ENCRYPTION
891+
* @brief Define this to enable SW %AES encryption in the %RFM69 module.
892+
*
893+
* All nodes and gateway must have this enabled, and all must be personalized with the same %AES
894+
* key.
895+
* @see @ref personalization
896+
*/
897+
//#define MY_RFM69_ENABLE_SW_ENCRYPTION
898+
781899
/**
782900
* @def MY_RFM69_MODEM_CONFIGURATION
783901
* @brief %RFM69 modem configuration, default is %RFM69_FSK_BR55_5_FD50
@@ -2191,7 +2309,7 @@
21912309
#define MY_DEBUG_VERBOSE_OTA_UPDATE //!< MY_DEBUG_VERBOSE_OTA_UPDATE
21922310
#endif
21932311

2194-
#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)
2312+
#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)
21952313
#define DEBUG_OUTPUT_ENABLED //!< DEBUG_OUTPUT_ENABLED
21962314
#ifndef MY_DEBUG_OTA
21972315
#define DEBUG_OUTPUT(x,...) hwDebugPrint(x, ##__VA_ARGS__) //!< debug
@@ -2307,6 +2425,8 @@
23072425
#define MY_OTA_LOG_RECEIVER_FEATURE
23082426
#define MY_OTA_LOG_SENDER_FEATURE
23092427
// transport
2428+
#define MY_DEBUG_VERBOSE_TRANSPORT_ENCRYPTION
2429+
#define MY_DEBUG_VERBOSE_TRANSPORT_QUEUE
23102430
#define MY_PARENT_NODE_IS_STATIC
23112431
#define MY_REGISTRATION_CONTROLLER
23122432
#define MY_TRANSPORT_UPLINK_CHECK_DISABLED
@@ -2396,19 +2516,33 @@
23962516
#define MY_RF24_ENABLE_ENCRYPTION
23972517
#define MY_RX_MESSAGE_BUFFER_FEATURE
23982518
#define MY_RX_MESSAGE_BUFFER_SIZE
2519+
#define MY_RF24_ATC
2520+
#define MY_RF24_USE_INTERRUPTS
23992521
// NRF5_ESB
24002522
#define MY_RADIO_NRF5_ESB
24012523
#define MY_NRF5_ESB_ENABLE_ENCRYPTION
24022524
#define MY_DEBUG_VERBOSE_NRF5_ESB
24032525
#define MY_NRF5_ESB_REVERSE_ACK_RX
24042526
#define MY_NRF5_ESB_REVERSE_ACK_TX
2527+
#define MY_NRF5_CPS_PIN
2528+
#define MY_NRF5_CPS_MODE
2529+
#define MY_NRF5_CHL_PIN
2530+
#define MY_NRF5_CHL_MODE
2531+
#define MY_NRF5_PA_PIN
2532+
#define MY_NRF5_PA_ENABLED
2533+
#define MY_NRF5_PA_DISABLED
2534+
#define MY_NRF5_LNA_PIN
2535+
#define MY_NRF5_LNA_ENABLED
2536+
#define MY_NRF5_LNA_DISABLED
2537+
#define MY_NRF5_PA_LNA
24052538
// RFM69
24062539
#define MY_RADIO_RFM69
24072540
#define MY_IS_RFM69HW
24082541
#define MY_RFM69_NEW_DRIVER
24092542
#define MY_RFM69_POWER_PIN
24102543
#define MY_RFM69_MODEM_CONFIGURATION
24112544
#define MY_RFM69_ENABLE_ENCRYPTION
2545+
#define MY_RFM69_ENABLE_SW_ENCRYPTION
24122546
#define MY_RFM69_ATC_MODE_DISABLED
24132547
#define MY_RFM69_MAX_POWER_LEVEL_DBM
24142548
#define MY_RFM69_RST_PIN

MySensors.h

+28-10
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,17 @@ MY_DEFAULT_RX_LED_PIN in your sketch instead to enable LEDs
286286
#define __RS485CNT 0 //!< __RS485CNT
287287
#endif
288288

289-
#if (__RF24CNT + __NRF5ESBCNT + __RFM69CNT + __RFM95CNT + __RS485CNT > 1)
290-
#error Only one forward link driver can be activated
289+
#define MY_TRANSPORT_COUNT (__RF24CNT + __NRF5ESBCNT + __RFM69CNT + __RFM95CNT + __RS485CNT) //!< MY_TRANSPORT_COUNT
290+
291+
#if (MY_TRANSPORT_COUNT > 1)
292+
// more than 1 transport requires RX queue
293+
#define MY_TRANSPORT_RX_QUEUE //!< MY_TRANSPORT_RX_QUEUE
294+
#endif
295+
// RF24 + IRQ requires RX queue
296+
#if defined(MY_RADIO_RF24) && defined(MY_RF24_USE_INTERRUPTS)
297+
#define MY_TRANSPORT_RX_QUEUE
291298
#endif
299+
292300
#endif //DOXYGEN
293301

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

299307
// TRANSPORT INCLUDES
300-
#if defined(MY_RADIO_RF24) || defined(MY_RADIO_NRF5_ESB) || defined(MY_RADIO_RFM69) || defined(MY_RADIO_RFM95) || defined(MY_RS485)
308+
#if (MY_TRANSPORT_COUNT > 0)
301309
#include "hal/transport/MyTransportHAL.h"
302310
#include "core/MyTransport.h"
303311

@@ -352,39 +360,49 @@ MY_DEFAULT_RX_LED_PIN in your sketch instead to enable LEDs
352360
#endif
353361
#endif
354362

363+
#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))
364+
#define MY_TRANSPORT_ENCRYPTION //!< internal flag
365+
#include "hal/transport/MyTransportEncryption.cpp"
366+
#endif
367+
355368
// Transport drivers
356369
#if defined(MY_RADIO_RF24)
357370
#include "hal/transport/RF24/driver/RF24.cpp"
358371
#include "hal/transport/RF24/MyTransportRF24.cpp"
359-
#elif defined(MY_RADIO_NRF5_ESB)
372+
#endif
373+
#if defined(MY_RADIO_NRF5_ESB)
360374
#if !defined(ARDUINO_ARCH_NRF5)
361375
#error No support for nRF5 radio on this platform
362376
#endif
363377
#include "hal/transport/NRF5_ESB/driver/Radio.cpp"
364378
#include "hal/transport/NRF5_ESB/driver/Radio_ESB.cpp"
365379
#include "hal/transport/NRF5_ESB/MyTransportNRF5_ESB.cpp"
366-
#elif defined(MY_RS485)
380+
#endif
381+
#if defined(MY_RS485)
367382
#if !defined(MY_RS485_HWSERIAL)
368383
#if defined(__linux__)
369384
#error You must specify MY_RS485_HWSERIAL for RS485 transport
370385
#endif
371386
#include "drivers/AltSoftSerial/AltSoftSerial.cpp"
372387
#endif
373388
#include "hal/transport/RS485/MyTransportRS485.cpp"
374-
#elif defined(MY_RADIO_RFM69)
389+
#endif
390+
#if defined(MY_RADIO_RFM69)
375391
#if defined(MY_RFM69_NEW_DRIVER)
376392
#include "hal/transport/RFM69/driver/new/RFM69_new.cpp"
377393
#else
378394
#include "hal/transport/RFM69/driver/old/RFM69_old.cpp"
379395
#endif
380396
#include "hal/transport/RFM69/MyTransportRFM69.cpp"
381-
#elif defined(MY_RADIO_RFM95)
397+
#endif
398+
#if defined(MY_RADIO_RFM95)
399+
#if defined(MY_RFM95_RFM69_COMPATIBILITY)
400+
#include "hal/transport/RFM95/driver/RFM95_RFM69.cpp"
401+
#include "hal/transport/RFM95/MyTransportRFM95_RFM69.cpp"
402+
#else
382403
#include "hal/transport/RFM95/driver/RFM95.cpp"
383404
#include "hal/transport/RFM95/MyTransportRFM95.cpp"
384405
#endif
385-
386-
#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))
387-
#define MY_TRANSPORT_ENCRYPTION //!< ïnternal flag
388406
#endif
389407

390408
#include "hal/transport/MyTransportHAL.cpp"

core/MyHelperFunctions.cpp

+30
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,33 @@ static char convertI2H(const uint8_t i)
3939
return 'A' + k - 10;
4040
}
4141
}
42+
43+
static int timingneutralMemcmp(const void* a, const void* b, size_t sz)
44+
{
45+
int retVal;
46+
size_t i;
47+
int done = 0;
48+
const uint8_t* ptrA = (const uint8_t*)a;
49+
const uint8_t* ptrB = (const uint8_t*)b;
50+
for (i = 0; i < sz; i++) {
51+
if (ptrA[i] == ptrB[i]) {
52+
if (done > 0) {
53+
done = 1;
54+
} else {
55+
done = 0;
56+
}
57+
} else {
58+
if (done > 0) {
59+
done = 2;
60+
} else {
61+
done = 3;
62+
}
63+
}
64+
}
65+
if (done > 0) {
66+
retVal = -1;
67+
} else {
68+
retVal = 0;
69+
}
70+
return retVal;
71+
}

core/MyHelperFunctions.h

+13
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,18 @@ static uint8_t convertH2I(const char c) __attribute__((unused));
3434
*/
3535
static char convertI2H(const uint8_t i) __attribute__((unused));
3636

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

3851
#endif

core/MySensorsCore.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,7 @@ void _nodeLock(const char *str)
804804
doYield();
805805
(void)_sendRoute(build(_msgTmp, GATEWAY_ADDRESS, NODE_SENSOR_ID,C_INTERNAL, I_LOCKED).set(str));
806806
#if defined(MY_SENSOR_NETWORK)
807-
transportSleep();
807+
transportHALSleep();
808808
CORE_DEBUG(PSTR("MCO:NLK:TSL\n")); // sleep transport
809809
#endif
810810
setIndication(INDICATION_SLEEP);

0 commit comments

Comments
 (0)