Restructure transport HAL (#1062)
This commit is contained in:
+10
-18
@@ -6,7 +6,7 @@
|
|||||||
* network topology allowing messages to be routed to nodes.
|
* network topology allowing messages to be routed to nodes.
|
||||||
*
|
*
|
||||||
* Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
|
* Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
|
||||||
* Copyright (C) 2013-2017 Sensnology AB
|
* Copyright (C) 2013-2018 Sensnology AB
|
||||||
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
|
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
|
||||||
*
|
*
|
||||||
* Documentation: http://www.mysensors.org
|
* Documentation: http://www.mysensors.org
|
||||||
@@ -147,8 +147,8 @@ MY_DEFAULT_RX_LED_PIN in your sketch instead to enable LEDs
|
|||||||
#if defined(MY_SENSOR_NETWORK)
|
#if defined(MY_SENSOR_NETWORK)
|
||||||
// We assume that a gateway having a radio also should act as repeater
|
// We assume that a gateway having a radio also should act as repeater
|
||||||
#define MY_REPEATER_FEATURE
|
#define MY_REPEATER_FEATURE
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// GATEWAY - COMMON FUNCTIONS
|
// GATEWAY - COMMON FUNCTIONS
|
||||||
// We support MQTT Client using W5100, ESP8266 and Linux
|
// We support MQTT Client using W5100, ESP8266 and Linux
|
||||||
#if !defined(MY_GATEWAY_CLIENT_MODE)
|
#if !defined(MY_GATEWAY_CLIENT_MODE)
|
||||||
@@ -188,6 +188,7 @@ MY_DEFAULT_RX_LED_PIN in your sketch instead to enable LEDs
|
|||||||
// We assume that a gateway having a radio also should act as repeater
|
// We assume that a gateway having a radio also should act as repeater
|
||||||
#define MY_REPEATER_FEATURE
|
#define MY_REPEATER_FEATURE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(MY_PORT)
|
#if !defined(MY_PORT)
|
||||||
#error You must define MY_PORT (controller or gatway port to open)
|
#error You must define MY_PORT (controller or gatway port to open)
|
||||||
#endif
|
#endif
|
||||||
@@ -268,7 +269,7 @@ MY_DEFAULT_RX_LED_PIN in your sketch instead to enable LEDs
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(MY_TRANSPORT_DONT_CARE_MODE)
|
#if defined(MY_TRANSPORT_DONT_CARE_MODE)
|
||||||
#error This directive is deprecated, set MY_TRANSPORT_WAIT_READY_MS instead!
|
#error MY_TRANSPORT_DONT_CARE_MODE is deprecated, set MY_TRANSPORT_WAIT_READY_MS instead!
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// RAM ROUTING TABLE
|
// RAM ROUTING TABLE
|
||||||
@@ -315,21 +316,15 @@ MY_DEFAULT_RX_LED_PIN in your sketch instead to enable LEDs
|
|||||||
|
|
||||||
// Transport drivers
|
// Transport drivers
|
||||||
#if defined(MY_RADIO_RF24)
|
#if defined(MY_RADIO_RF24)
|
||||||
#if defined(MY_RF24_ENABLE_ENCRYPTION)
|
|
||||||
#include "drivers/AES/AES.cpp"
|
|
||||||
#endif
|
|
||||||
#include "drivers/RF24/RF24.cpp"
|
#include "drivers/RF24/RF24.cpp"
|
||||||
#include "hal/transport/MyTransportRF24.cpp"
|
#include "hal/transport/RF24/MyTransportRF24.cpp"
|
||||||
#elif defined(MY_RADIO_NRF5_ESB)
|
#elif defined(MY_RADIO_NRF5_ESB)
|
||||||
#if !defined(ARDUINO_ARCH_NRF5)
|
#if !defined(ARDUINO_ARCH_NRF5)
|
||||||
#error No support for nRF5 radio on this platform
|
#error No support for nRF5 radio on this platform
|
||||||
#endif
|
#endif
|
||||||
#if defined(MY_NRF5_ESB_ENABLE_ENCRYPTION)
|
|
||||||
#include "drivers/AES/AES.cpp"
|
|
||||||
#endif
|
|
||||||
#include "drivers/NRF5/Radio.cpp"
|
#include "drivers/NRF5/Radio.cpp"
|
||||||
#include "drivers/NRF5/Radio_ESB.cpp"
|
#include "drivers/NRF5/Radio_ESB.cpp"
|
||||||
#include "hal/transport/MyTransportNRF5_ESB.cpp"
|
#include "hal/transport/NRF5_ESB/MyTransportNRF5_ESB.cpp"
|
||||||
#elif defined(MY_RS485)
|
#elif defined(MY_RS485)
|
||||||
#if !defined(MY_RS485_HWSERIAL)
|
#if !defined(MY_RS485_HWSERIAL)
|
||||||
#if defined(__linux__)
|
#if defined(__linux__)
|
||||||
@@ -337,20 +332,17 @@ MY_DEFAULT_RX_LED_PIN in your sketch instead to enable LEDs
|
|||||||
#endif
|
#endif
|
||||||
#include "drivers/AltSoftSerial/AltSoftSerial.cpp"
|
#include "drivers/AltSoftSerial/AltSoftSerial.cpp"
|
||||||
#endif
|
#endif
|
||||||
#include "hal/transport/MyTransportRS485.cpp"
|
#include "hal/transport/RS485/MyTransportRS485.cpp"
|
||||||
#elif defined(MY_RADIO_RFM69)
|
#elif defined(MY_RADIO_RFM69)
|
||||||
#if defined(MY_RFM69_NEW_DRIVER)
|
#if defined(MY_RFM69_NEW_DRIVER)
|
||||||
#include "drivers/RFM69/new/RFM69_new.cpp"
|
#include "drivers/RFM69/new/RFM69_new.cpp"
|
||||||
#else
|
#else
|
||||||
#include "drivers/RFM69/old/RFM69_old.cpp"
|
#include "drivers/RFM69/old/RFM69_old.cpp"
|
||||||
#endif
|
#endif
|
||||||
#include "hal/transport/MyTransportRFM69.cpp"
|
#include "hal/transport/RFM69/MyTransportRFM69.cpp"
|
||||||
#elif defined(MY_RADIO_RFM95)
|
#elif defined(MY_RADIO_RFM95)
|
||||||
#if defined(MY_RFM95_ENABLE_ENCRYPTION)
|
|
||||||
#include "drivers/AES/AES.cpp"
|
|
||||||
#endif
|
|
||||||
#include "drivers/RFM95/RFM95.cpp"
|
#include "drivers/RFM95/RFM95.cpp"
|
||||||
#include "hal/transport/MyTransportRFM95.cpp"
|
#include "hal/transport/RFM95/MyTransportRFM95.cpp"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// PASSIVE MODE
|
// PASSIVE MODE
|
||||||
@@ -406,7 +398,7 @@ MY_DEFAULT_RX_LED_PIN in your sketch instead to enable LEDs
|
|||||||
#elif defined(ARDUINO_ARCH_NRF5)
|
#elif defined(ARDUINO_ARCH_NRF5)
|
||||||
#include "hal/architecture/NRF5/MyMainNRF5.cpp"
|
#include "hal/architecture/NRF5/MyMainNRF5.cpp"
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__)
|
||||||
#include "hal/architecture/Linux/MyMainLinux.cpp"
|
#include "hal/architecture/Linux/MyMainLinuxGeneric.cpp"
|
||||||
#elif defined(ARDUINO_ARCH_STM32F1)
|
#elif defined(ARDUINO_ARCH_STM32F1)
|
||||||
#include "hal/architecture/STM32F1/MyMainSTM32F1.cpp"
|
#include "hal/architecture/STM32F1/MyMainSTM32F1.cpp"
|
||||||
#elif defined(TEENSYDUINO)
|
#elif defined(TEENSYDUINO)
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
#include "MyHwAVR.h"
|
#include "MyHwAVR.h"
|
||||||
#include "avr/boot.h"
|
#include "avr/boot.h"
|
||||||
|
|
||||||
|
|
||||||
bool hwInit(void)
|
bool hwInit(void)
|
||||||
{
|
{
|
||||||
#if !defined(MY_DISABLED_SERIAL)
|
#if !defined(MY_DISABLED_SERIAL)
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
* network topology allowing messages to be routed to nodes.
|
* network topology allowing messages to be routed to nodes.
|
||||||
*
|
*
|
||||||
* Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
|
* Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
|
||||||
* Copyright (C) 2013-2017 Sensnology AB
|
* Copyright (C) 2013-2018 Sensnology AB
|
||||||
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
|
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
|
||||||
*
|
*
|
||||||
* Documentation: http://www.mysensors.org
|
* Documentation: http://www.mysensors.org
|
||||||
@@ -69,7 +69,7 @@ void transportSetAddress(const uint8_t address);
|
|||||||
/**
|
/**
|
||||||
* @brief Retrieve node address
|
* @brief Retrieve node address
|
||||||
*/
|
*/
|
||||||
uint8_t transportGetAddress(void);
|
uint8_t transportGetAddress(void) __attribute__((unused));
|
||||||
/**
|
/**
|
||||||
* @brief Send message
|
* @brief Send message
|
||||||
* @param to recipient
|
* @param to recipient
|
||||||
@@ -86,7 +86,7 @@ bool transportSend(const uint8_t to, const void* data, const uint8_t len,
|
|||||||
*/
|
*/
|
||||||
bool transportAvailable(void);
|
bool transportAvailable(void);
|
||||||
/**
|
/**
|
||||||
* @brief Sanity check for transport: is transport still responsive?
|
* @brief Sanity check for transport: is transport HW still responsive?
|
||||||
* @return true if transport HW is ok
|
* @return true if transport HW is ok
|
||||||
*/
|
*/
|
||||||
bool transportSanityCheck(void);
|
bool transportSanityCheck(void);
|
||||||
@@ -113,30 +113,36 @@ void transportSleep(void);
|
|||||||
void transportStandBy(void);
|
void transportStandBy(void);
|
||||||
/**
|
/**
|
||||||
* @brief transportGetSendingRSSI
|
* @brief transportGetSendingRSSI
|
||||||
* @return RSSI
|
* @return RSSI of outgoing message (via ACK packet)
|
||||||
*/
|
*/
|
||||||
int16_t transportGetSendingRSSI(void);
|
int16_t transportGetSendingRSSI(void);
|
||||||
/**
|
/**
|
||||||
* @brief transportGetReceivingRSSI
|
* @brief transportGetReceivingRSSI
|
||||||
* @return RSSI
|
* @return RSSI of incoming message
|
||||||
*/
|
*/
|
||||||
int16_t transportGetReceivingRSSI(void);
|
int16_t transportGetReceivingRSSI(void);
|
||||||
/**
|
/**
|
||||||
* @brief transportGetSendingSNR
|
* @brief transportGetSendingSNR
|
||||||
* @return SNR
|
* @return SNR of outgoing message (via ACK packet)
|
||||||
*/
|
*/
|
||||||
int16_t transportGetSendingSNR(void);
|
int16_t transportGetSendingSNR(void);
|
||||||
/**
|
/**
|
||||||
* @brief transportGetReceivingSNR
|
* @brief transportGetReceivingSNR
|
||||||
* @return SNR
|
* @return SNR of incoming message
|
||||||
*/
|
*/
|
||||||
int16_t transportGetReceivingSNR(void);
|
int16_t transportGetReceivingSNR(void);
|
||||||
/**
|
/**
|
||||||
* @brief transportGetTxPowerPercent
|
* @brief transportGetTxPowerPercent
|
||||||
* @return TX power in percent
|
* @return TX power level in percent
|
||||||
*/
|
*/
|
||||||
int16_t transportGetTxPowerPercent(void);
|
int16_t transportGetTxPowerPercent(void);
|
||||||
/**
|
/**
|
||||||
|
* @brief transportSetTxPowerPercent
|
||||||
|
* @param powerPercent power level in percent
|
||||||
|
* @return True if power level set
|
||||||
|
*/
|
||||||
|
bool transportSetTxPowerPercent(const uint8_t powerPercent) __attribute__((unused));
|
||||||
|
/**
|
||||||
* @brief transportGetTxPowerLevel
|
* @brief transportGetTxPowerLevel
|
||||||
* @return TX power in dBm
|
* @return TX power in dBm
|
||||||
*/
|
*/
|
||||||
|
|||||||
+18
-23
@@ -2,12 +2,11 @@
|
|||||||
* The MySensors Arduino library handles the wireless radio link and protocol
|
* The MySensors Arduino library handles the wireless radio link and protocol
|
||||||
* between your home built sensors/actuators and HA controller of choice.
|
* between your home built sensors/actuators and HA controller of choice.
|
||||||
* The sensors forms a self healing radio network with optional repeaters. Each
|
* The sensors forms a self healing radio network with optional repeaters. Each
|
||||||
* repeater and gateway builds a routing tables in EEPROM which keeps track of
|
* repeater and gateway builds a routing tables in EEPROM which keeps track of the
|
||||||
* the
|
|
||||||
* network topology allowing messages to be routed to nodes.
|
* network topology allowing messages to be routed to nodes.
|
||||||
*
|
*
|
||||||
* Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
|
* Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
|
||||||
* Copyright (C) 2013-2015 Sensnology AB
|
* Copyright (C) 2013-2018 Sensnology AB
|
||||||
* Copyright (C) 2017 Frank Holtz
|
* Copyright (C) 2017 Frank Holtz
|
||||||
* Full contributor list:
|
* Full contributor list:
|
||||||
* https://github.com/mysensors/Arduino/graphs/contributors
|
* https://github.com/mysensors/Arduino/graphs/contributors
|
||||||
@@ -20,37 +19,33 @@
|
|||||||
* version 2 as published by the Free Software Foundation.
|
* version 2 as published by the Free Software Foundation.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "MyTransportHAL.h"
|
|
||||||
#include "drivers/NRF5/Radio.h"
|
#include "drivers/NRF5/Radio.h"
|
||||||
#include "drivers/NRF5/Radio_ESB.h"
|
#include "drivers/NRF5/Radio_ESB.h"
|
||||||
|
|
||||||
#include "drivers/CircularBuffer/CircularBuffer.h"
|
#include "drivers/CircularBuffer/CircularBuffer.h"
|
||||||
|
|
||||||
#if defined(MY_NRF5_ESB_ENABLE_ENCRYPTION)
|
#if defined(MY_NRF5_ESB_ENABLE_ENCRYPTION)
|
||||||
#include "drivers/AES/AES.h"
|
#include "drivers/AES/AES.cpp"
|
||||||
#endif
|
AES NRF5_ESB_aes;
|
||||||
|
uint8_t NRF5_ESB_dataenc[32] = {0};
|
||||||
#if defined(MY_NRF5_ESB_ENABLE_ENCRYPTION)
|
|
||||||
AES _aes;
|
|
||||||
uint8_t _dataenc[32] = {0};
|
|
||||||
uint8_t _psk[16];
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool transportInit(void)
|
bool transportInit(void)
|
||||||
{
|
{
|
||||||
#if defined(MY_NRF5_ESB_ENABLE_ENCRYPTION)
|
#if defined(MY_NRF5_ESB_ENABLE_ENCRYPTION)
|
||||||
|
uint8_t NRF5_ESB_psk[16];
|
||||||
#ifdef MY_ENCRYPTION_SIMPLE_PASSWD
|
#ifdef MY_ENCRYPTION_SIMPLE_PASSWD
|
||||||
memset(_psk, 0, 16);
|
(void)memset(NRF5_ESB_psk, 0, 16);
|
||||||
memcpy(_psk, MY_ENCRYPTION_SIMPLE_PASSWD, strnlen(MY_ENCRYPTION_SIMPLE_PASSWD, 16));
|
(void)memcpy(NRF5_ESB_psk, MY_ENCRYPTION_SIMPLE_PASSWD, strnlen(MY_ENCRYPTION_SIMPLE_PASSWD, 16));
|
||||||
#else
|
#else
|
||||||
hwReadConfigBlock((void*)_psk, (void*)EEPROM_RF_ENCRYPTION_AES_KEY_ADDRESS, 16);
|
hwReadConfigBlock((void*)NRF5_ESB_psk, (void*)EEPROM_RF_ENCRYPTION_KEY_ADDRESS,
|
||||||
|
16);
|
||||||
#endif
|
#endif
|
||||||
// set up AES-key
|
// set up AES-key
|
||||||
_aes.set_key(_psk, 16);
|
NRF5_ESB_aes.set_key(NRF5_ESB_psk, 16);
|
||||||
// Make sure it is purged from memory when set
|
// Make sure it is purged from memory when set
|
||||||
memset(_psk, 0, 16);
|
(void)memset(NRF5_ESB_psk, 0, 16);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return NRF5_ESB_initialize();
|
return NRF5_ESB_initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,13 +64,13 @@ bool transportSend(const uint8_t to, const void *data, const uint8_t len, const
|
|||||||
{
|
{
|
||||||
#if defined(MY_NRF5_ESB_ENABLE_ENCRYPTION)
|
#if defined(MY_NRF5_ESB_ENABLE_ENCRYPTION)
|
||||||
// copy input data because it is read-only
|
// copy input data because it is read-only
|
||||||
(void)memcpy(_dataenc, data, len);
|
(void)memcpy(NRF5_ESB_dataenc, data, len);
|
||||||
// has to be adjusted, WIP!
|
// has to be adjusted, WIP!
|
||||||
_aes.set_IV(0);
|
NRF5_ESB_aes.set_IV(0);
|
||||||
const uint8_t finalLength = len > 16 ? 32 : 16;
|
const uint8_t finalLength = len > 16 ? 32 : 16;
|
||||||
// encrypt data
|
// encrypt data
|
||||||
_aes.cbc_encrypt(_dataenc, _dataenc, finalLength / 16);
|
NRF5_ESB_aes.cbc_encrypt(NRF5_ESB_dataenc, NRF5_ESB_dataenc, finalLength / 16);
|
||||||
return NRF5_ESB_sendMessage(to, _dataenc, finalLength, noACK);
|
return NRF5_ESB_sendMessage(to, NRF5_ESB_dataenc, finalLength, noACK);
|
||||||
#else
|
#else
|
||||||
return NRF5_ESB_sendMessage(to, data, len, noACK);
|
return NRF5_ESB_sendMessage(to, data, len, noACK);
|
||||||
#endif
|
#endif
|
||||||
@@ -97,9 +92,9 @@ uint8_t transportReceive(void *data)
|
|||||||
len = NRF5_ESB_readMessage(data);
|
len = NRF5_ESB_readMessage(data);
|
||||||
#if defined(MY_NRF5_ESB_ENABLE_ENCRYPTION)
|
#if defined(MY_NRF5_ESB_ENABLE_ENCRYPTION)
|
||||||
// has to be adjusted, WIP!
|
// has to be adjusted, WIP!
|
||||||
_aes.set_IV(0);
|
NRF5_ESB_aes.set_IV(0);
|
||||||
// decrypt data
|
// decrypt data
|
||||||
if (_aes.cbc_decrypt((uint8_t *)(data), (uint8_t *)(data),
|
if (NRF5_ESB_aes.cbc_decrypt((uint8_t *)(data), (uint8_t *)(data),
|
||||||
len > 16 ? 2 : 1) != AES_SUCCESS) {
|
len > 16 ? 2 : 1) != AES_SUCCESS) {
|
||||||
len = 0;
|
len = 0;
|
||||||
}
|
}
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
* network topology allowing messages to be routed to nodes.
|
* network topology allowing messages to be routed to nodes.
|
||||||
*
|
*
|
||||||
* Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
|
* Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
|
||||||
* Copyright (C) 2013-2017 Sensnology AB
|
* Copyright (C) 2013-2018 Sensnology AB
|
||||||
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
|
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
|
||||||
*
|
*
|
||||||
* Documentation: http://www.mysensors.org
|
* Documentation: http://www.mysensors.org
|
||||||
@@ -17,11 +17,12 @@
|
|||||||
* version 2 as published by the Free Software Foundation.
|
* version 2 as published by the Free Software Foundation.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "MyTransportHAL.h"
|
|
||||||
#include "drivers/RF24/RF24.h"
|
#include "drivers/RF24/RF24.h"
|
||||||
|
|
||||||
#if defined(MY_RF24_ENABLE_ENCRYPTION)
|
#if defined(MY_RF24_ENABLE_ENCRYPTION)
|
||||||
#include "drivers/AES/AES.h"
|
#include "drivers/AES/AES.cpp"
|
||||||
|
AES RF24_aes;
|
||||||
|
uint8_t RF24_dataenc[32] = {0};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(MY_RX_MESSAGE_BUFFER_FEATURE)
|
#if defined(MY_RX_MESSAGE_BUFFER_FEATURE)
|
||||||
@@ -59,25 +60,20 @@ static void transportRxCallback(void)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(MY_RF24_ENABLE_ENCRYPTION)
|
|
||||||
AES _aes;
|
|
||||||
uint8_t _dataenc[32] = {0};
|
|
||||||
uint8_t _psk[16];
|
|
||||||
#endif
|
|
||||||
|
|
||||||
bool transportInit(void)
|
bool transportInit(void)
|
||||||
{
|
{
|
||||||
#if defined(MY_RF24_ENABLE_ENCRYPTION)
|
#if defined(MY_RF24_ENABLE_ENCRYPTION)
|
||||||
|
uint8_t RF24_psk[16];
|
||||||
#ifdef MY_ENCRYPTION_SIMPLE_PASSWD
|
#ifdef MY_ENCRYPTION_SIMPLE_PASSWD
|
||||||
memset(_psk, 0, 16);
|
(void)memset(RF24_psk, 0, 16);
|
||||||
memcpy(_psk, MY_ENCRYPTION_SIMPLE_PASSWD, strnlen(MY_ENCRYPTION_SIMPLE_PASSWD, 16));
|
(void)memcpy(RF24_psk, MY_ENCRYPTION_SIMPLE_PASSWD, strnlen(MY_ENCRYPTION_SIMPLE_PASSWD, 16));
|
||||||
#else
|
#else
|
||||||
hwReadConfigBlock((void*)_psk, (void*)EEPROM_RF_ENCRYPTION_AES_KEY_ADDRESS, 16);
|
hwReadConfigBlock((void*)RF24_psk, (void*)EEPROM_RF_ENCRYPTION_AES_KEY_ADDRESS, 16);
|
||||||
#endif
|
#endif
|
||||||
//set up AES-key
|
//set up AES-key
|
||||||
_aes.set_key(_psk, 16);
|
RF24_aes.set_key(RF24_psk, 16);
|
||||||
// Make sure it is purged from memory when set
|
// Make sure it is purged from memory when set
|
||||||
memset(_psk, 0, 16);
|
(void)memset(RF24_psk, 0, 16);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(MY_RX_MESSAGE_BUFFER_FEATURE)
|
#if defined(MY_RX_MESSAGE_BUFFER_FEATURE)
|
||||||
@@ -101,13 +97,13 @@ bool transportSend(const uint8_t to, const void* data, const uint8_t len, const
|
|||||||
{
|
{
|
||||||
#if defined(MY_RF24_ENABLE_ENCRYPTION)
|
#if defined(MY_RF24_ENABLE_ENCRYPTION)
|
||||||
// copy input data because it is read-only
|
// copy input data because it is read-only
|
||||||
(void)memcpy(_dataenc,data,len);
|
(void)memcpy(RF24_dataenc,data,len);
|
||||||
// has to be adjusted, WIP!
|
// has to be adjusted, WIP!
|
||||||
_aes.set_IV(0);
|
RF24_aes.set_IV(0);
|
||||||
const uint8_t finalLength = len > 16 ? 32 : 16;
|
const uint8_t finalLength = len > 16 ? 32 : 16;
|
||||||
//encrypt data
|
//encrypt data
|
||||||
_aes.cbc_encrypt(_dataenc, _dataenc, finalLength /16);
|
RF24_aes.cbc_encrypt(RF24_dataenc, RF24_dataenc, finalLength / 16);
|
||||||
return RF24_sendMessage(to, _dataenc, finalLength, noACK);
|
return RF24_sendMessage(to, RF24_dataenc, finalLength, noACK);
|
||||||
#else
|
#else
|
||||||
return RF24_sendMessage(to, data, len, noACK);
|
return RF24_sendMessage(to, data, len, noACK);
|
||||||
#endif
|
#endif
|
||||||
@@ -143,9 +139,9 @@ uint8_t transportReceive(void* data)
|
|||||||
#endif
|
#endif
|
||||||
#if defined(MY_RF24_ENABLE_ENCRYPTION)
|
#if defined(MY_RF24_ENABLE_ENCRYPTION)
|
||||||
// has to be adjusted, WIP!
|
// has to be adjusted, WIP!
|
||||||
_aes.set_IV(0);
|
RF24_aes.set_IV(0);
|
||||||
// decrypt data
|
// decrypt data
|
||||||
if (_aes.cbc_decrypt((uint8_t*)(data), (uint8_t*)(data), len > 16 ? 2 : 1) != AES_SUCCESS) {
|
if (RF24_aes.cbc_decrypt((uint8_t*)(data), (uint8_t*)(data), len > 16 ? 2 : 1) != AES_SUCCESS) {
|
||||||
len = 0;
|
len = 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -176,6 +172,7 @@ int16_t transportGetSendingRSSI(void)
|
|||||||
{
|
{
|
||||||
return RF24_getSendingRSSI();
|
return RF24_getSendingRSSI();
|
||||||
}
|
}
|
||||||
|
|
||||||
int16_t transportGetReceivingRSSI(void)
|
int16_t transportGetReceivingRSSI(void)
|
||||||
{
|
{
|
||||||
// not available, only bool RPD
|
// not available, only bool RPD
|
||||||
@@ -206,5 +203,3 @@ bool transportSetTxPowerPercent(const uint8_t powerPercent)
|
|||||||
{
|
{
|
||||||
return RF24_setTxPowerPercent(powerPercent);
|
return RF24_setTxPowerPercent(powerPercent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
* network topology allowing messages to be routed to nodes.
|
* network topology allowing messages to be routed to nodes.
|
||||||
*
|
*
|
||||||
* Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
|
* Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
|
||||||
* Copyright (C) 2013-2017 Sensnology AB
|
* Copyright (C) 2013-2018 Sensnology AB
|
||||||
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
|
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
|
||||||
*
|
*
|
||||||
* Documentation: http://www.mysensors.org
|
* Documentation: http://www.mysensors.org
|
||||||
@@ -17,8 +17,6 @@
|
|||||||
* version 2 as published by the Free Software Foundation.
|
* version 2 as published by the Free Software Foundation.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "MyTransportHAL.h"
|
|
||||||
|
|
||||||
#if defined(MY_RFM69_NEW_DRIVER)
|
#if defined(MY_RFM69_NEW_DRIVER)
|
||||||
|
|
||||||
#include "drivers/RFM69/new/RFM69_new.h"
|
#include "drivers/RFM69/new/RFM69_new.h"
|
||||||
@@ -34,17 +32,16 @@ bool transportInit(void)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef MY_RFM69_ENABLE_ENCRYPTION
|
#ifdef MY_RFM69_ENABLE_ENCRYPTION
|
||||||
uint8_t _psk[16];
|
uint8_t RFM69_psk[16];
|
||||||
#ifdef MY_ENCRYPTION_SIMPLE_PASSWD
|
#ifdef MY_ENCRYPTION_SIMPLE_PASSWD
|
||||||
memset(_psk, 0, 16);
|
(void)memset(RFM69_psk, 0, 16);
|
||||||
memcpy(_psk, MY_ENCRYPTION_SIMPLE_PASSWD, strnlen(MY_ENCRYPTION_SIMPLE_PASSWD, 16));
|
(void)memcpy(RFM69_psk, MY_ENCRYPTION_SIMPLE_PASSWD, strnlen(MY_ENCRYPTION_SIMPLE_PASSWD, 16));
|
||||||
#else
|
#else
|
||||||
hwReadConfigBlock((void*)_psk, (void*)EEPROM_RF_ENCRYPTION_AES_KEY_ADDRESS, 16);
|
hwReadConfigBlock((void*)RFM69_psk, (void*)EEPROM_RF_ENCRYPTION_AES_KEY_ADDRESS, 16);
|
||||||
#endif
|
#endif
|
||||||
RFM69_encrypt((const char*)_psk);
|
RFM69_encrypt((const char*)RFM69_psk);
|
||||||
(void)memset(_psk, 0, 16); // Make sure it is purged from memory when set
|
(void)memset(RFM69_psk, 0, 16); // Make sure it is purged from memory when set
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,6 +143,7 @@ int16_t transportGetTxPowerLevel(void)
|
|||||||
{
|
{
|
||||||
return RFM69_getTxPowerLevel();
|
return RFM69_getTxPowerLevel();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool transportSetTxPowerPercent(const uint8_t powerPercent)
|
bool transportSetTxPowerPercent(const uint8_t powerPercent)
|
||||||
{
|
{
|
||||||
return RFM69_setTxPowerPercent(powerPercent);
|
return RFM69_setTxPowerPercent(powerPercent);
|
||||||
@@ -169,15 +167,15 @@ bool transportInit(void)
|
|||||||
// Start up the radio library (_address will be set later by the MySensors library)
|
// Start up the radio library (_address will be set later by the MySensors library)
|
||||||
if (_radio.initialize(MY_RFM69_FREQUENCY, _address, MY_RFM69_NETWORKID)) {
|
if (_radio.initialize(MY_RFM69_FREQUENCY, _address, MY_RFM69_NETWORKID)) {
|
||||||
#ifdef MY_RFM69_ENABLE_ENCRYPTION
|
#ifdef MY_RFM69_ENABLE_ENCRYPTION
|
||||||
uint8_t _psk[16];
|
uint8_t RFM69_psk[16];
|
||||||
#ifdef MY_ENCRYPTION_SIMPLE_PASSWD
|
#ifdef MY_ENCRYPTION_SIMPLE_PASSWD
|
||||||
memset(_psk, 0, 16);
|
(void)memset(RFM69_psk, 0, 16);
|
||||||
memcpy(_psk, MY_ENCRYPTION_SIMPLE_PASSWD, strnlen(MY_ENCRYPTION_SIMPLE_PASSWD, 16));
|
(void)memcpy(RFM69_psk, MY_ENCRYPTION_SIMPLE_PASSWD, strnlen(MY_ENCRYPTION_SIMPLE_PASSWD, 16));
|
||||||
#else
|
#else
|
||||||
hwReadConfigBlock((void*)_psk, (void*)EEPROM_RF_ENCRYPTION_AES_KEY_ADDRESS, 16);
|
hwReadConfigBlock((void*)RFM69_psk, (void*)EEPROM_RF_ENCRYPTION_AES_KEY_ADDRESS, 16);
|
||||||
#endif
|
#endif
|
||||||
_radio.encrypt((const char*)_psk);
|
_radio.encrypt((const char*)RFM69_psk);
|
||||||
(void)memset(_psk, 0, 16); // Make sure it is purged from memory when set
|
(void)memset(RFM69_psk, 0, 16); // Make sure it is purged from memory when set
|
||||||
#endif
|
#endif
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -235,10 +233,12 @@ void transportStandBy(void)
|
|||||||
{
|
{
|
||||||
_radio.standBy();
|
_radio.standBy();
|
||||||
}
|
}
|
||||||
|
|
||||||
void transportPowerDown(void)
|
void transportPowerDown(void)
|
||||||
{
|
{
|
||||||
_radio.powerDown();
|
_radio.powerDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
void transportPowerUp(void)
|
void transportPowerUp(void)
|
||||||
{
|
{
|
||||||
_radio.powerUp();
|
_radio.powerUp();
|
||||||
@@ -274,4 +274,11 @@ int16_t transportGetTxPowerLevel(void)
|
|||||||
return INVALID_LEVEL;
|
return INVALID_LEVEL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool transportSetTxPowerLevel(const uint8_t powerLevel)
|
||||||
|
{
|
||||||
|
// not implemented
|
||||||
|
(void)powerLevel;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
* network topology allowing messages to be routed to nodes.
|
* network topology allowing messages to be routed to nodes.
|
||||||
*
|
*
|
||||||
* Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
|
* Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
|
||||||
* Copyright (C) 2013-2017 Sensnology AB
|
* Copyright (C) 2013-2018 Sensnology AB
|
||||||
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
|
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
|
||||||
*
|
*
|
||||||
* Documentation: http://www.mysensors.org
|
* Documentation: http://www.mysensors.org
|
||||||
@@ -15,12 +15,14 @@
|
|||||||
* This program is free software; you can redistribute it and/or
|
* This program is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU General Public License
|
* modify it under the terms of the GNU General Public License
|
||||||
* version 2 as published by the Free Software Foundation.
|
* version 2 as published by the Free Software Foundation.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "MyTransportHAL.h"
|
|
||||||
#include "drivers/RFM95/RFM95.h"
|
#include "drivers/RFM95/RFM95.h"
|
||||||
|
|
||||||
|
#if defined(MY_RFM95_ENABLE_ENCRYPTION)
|
||||||
|
#include "drivers/AES/AES.cpp"
|
||||||
|
#endif
|
||||||
|
|
||||||
bool transportInit(void)
|
bool transportInit(void)
|
||||||
{
|
{
|
||||||
const bool result = RFM95_initialise(MY_RFM95_FREQUENCY);
|
const bool result = RFM95_initialise(MY_RFM95_FREQUENCY);
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
* network topology allowing messages to be routed to nodes.
|
* network topology allowing messages to be routed to nodes.
|
||||||
*
|
*
|
||||||
* Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
|
* Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
|
||||||
* Copyright (C) 2013-2017 Sensnology AB
|
* Copyright (C) 2013-2018 Sensnology AB
|
||||||
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
|
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
|
||||||
*
|
*
|
||||||
* Documentation: http://www.mysensors.org
|
* Documentation: http://www.mysensors.org
|
||||||
@@ -52,9 +52,6 @@
|
|||||||
|
|
||||||
// Serial Transport
|
// Serial Transport
|
||||||
|
|
||||||
|
|
||||||
#include "MyTransportHAL.h"
|
|
||||||
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
#include "SerialPort.h"
|
#include "SerialPort.h"
|
||||||
#endif
|
#endif
|
||||||
@@ -367,15 +364,17 @@ void transportPowerDown(void)
|
|||||||
|
|
||||||
void transportPowerUp(void)
|
void transportPowerUp(void)
|
||||||
{
|
{
|
||||||
|
// not implemented
|
||||||
}
|
}
|
||||||
|
|
||||||
void transportSleep(void)
|
void transportSleep(void)
|
||||||
{
|
{
|
||||||
|
// not implemented
|
||||||
}
|
}
|
||||||
|
|
||||||
void transportStandBy(void)
|
void transportStandBy(void)
|
||||||
{
|
{
|
||||||
|
// not implemented
|
||||||
}
|
}
|
||||||
|
|
||||||
int16_t transportGetSendingRSSI(void)
|
int16_t transportGetSendingRSSI(void)
|
||||||
Reference in New Issue
Block a user