Restructure transport HAL (#1062)

This commit is contained in:
tekka
2018-02-11 16:48:11 +01:00
committed by Henrik Ekblad
parent 8a1f5f4cf9
commit 6794c72ecd
9 changed files with 109 additions and 112 deletions
+10 -18
View File
@@ -6,7 +6,7 @@
* network topology allowing messages to be routed to nodes.
*
* 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
*
* 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)
// We assume that a gateway having a radio also should act as repeater
#define MY_REPEATER_FEATURE
#endif
// GATEWAY - COMMON FUNCTIONS
// We support MQTT Client using W5100, ESP8266 and Linux
#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
#define MY_REPEATER_FEATURE
#endif
#if !defined(MY_PORT)
#error You must define MY_PORT (controller or gatway port to open)
#endif
@@ -268,7 +269,7 @@ MY_DEFAULT_RX_LED_PIN in your sketch instead to enable LEDs
#endif
#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
// RAM ROUTING TABLE
@@ -315,21 +316,15 @@ MY_DEFAULT_RX_LED_PIN in your sketch instead to enable LEDs
// Transport drivers
#if defined(MY_RADIO_RF24)
#if defined(MY_RF24_ENABLE_ENCRYPTION)
#include "drivers/AES/AES.cpp"
#endif
#include "drivers/RF24/RF24.cpp"
#include "hal/transport/MyTransportRF24.cpp"
#include "hal/transport/RF24/MyTransportRF24.cpp"
#elif defined(MY_RADIO_NRF5_ESB)
#if !defined(ARDUINO_ARCH_NRF5)
#error No support for nRF5 radio on this platform
#endif
#if defined(MY_NRF5_ESB_ENABLE_ENCRYPTION)
#include "drivers/AES/AES.cpp"
#endif
#include "drivers/NRF5/Radio.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)
#if !defined(MY_RS485_HWSERIAL)
#if defined(__linux__)
@@ -337,20 +332,17 @@ MY_DEFAULT_RX_LED_PIN in your sketch instead to enable LEDs
#endif
#include "drivers/AltSoftSerial/AltSoftSerial.cpp"
#endif
#include "hal/transport/MyTransportRS485.cpp"
#include "hal/transport/RS485/MyTransportRS485.cpp"
#elif defined(MY_RADIO_RFM69)
#if defined(MY_RFM69_NEW_DRIVER)
#include "drivers/RFM69/new/RFM69_new.cpp"
#else
#include "drivers/RFM69/old/RFM69_old.cpp"
#endif
#include "hal/transport/MyTransportRFM69.cpp"
#include "hal/transport/RFM69/MyTransportRFM69.cpp"
#elif defined(MY_RADIO_RFM95)
#if defined(MY_RFM95_ENABLE_ENCRYPTION)
#include "drivers/AES/AES.cpp"
#endif
#include "drivers/RFM95/RFM95.cpp"
#include "hal/transport/MyTransportRFM95.cpp"
#include "hal/transport/RFM95/MyTransportRFM95.cpp"
#endif
// PASSIVE MODE
@@ -406,7 +398,7 @@ MY_DEFAULT_RX_LED_PIN in your sketch instead to enable LEDs
#elif defined(ARDUINO_ARCH_NRF5)
#include "hal/architecture/NRF5/MyMainNRF5.cpp"
#elif defined(__linux__)
#include "hal/architecture/Linux/MyMainLinux.cpp"
#include "hal/architecture/Linux/MyMainLinuxGeneric.cpp"
#elif defined(ARDUINO_ARCH_STM32F1)
#include "hal/architecture/STM32F1/MyMainSTM32F1.cpp"
#elif defined(TEENSYDUINO)
+1
View File
@@ -20,6 +20,7 @@
#include "MyHwAVR.h"
#include "avr/boot.h"
bool hwInit(void)
{
#if !defined(MY_DISABLED_SERIAL)
+28 -22
View File
@@ -6,7 +6,7 @@
* network topology allowing messages to be routed to nodes.
*
* 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
*
* Documentation: http://www.mysensors.org
@@ -20,10 +20,10 @@
#ifndef MyTransportHAL_h
#define MyTransportHAL_h
#define INVALID_SNR ((int16_t)-256) //!< INVALID_SNR
#define INVALID_RSSI ((int16_t)-256) //!< INVALID_RSSI
#define INVALID_PERCENT ((int16_t)-100) //!< INVALID_PERCENT
#define INVALID_LEVEL ((int16_t)-256) //!< INVALID_LEVEL
#define INVALID_SNR ((int16_t)-256) //!< INVALID_SNR
#define INVALID_RSSI ((int16_t)-256) //!< INVALID_RSSI
#define INVALID_PERCENT ((int16_t)-100) //!< INVALID_PERCENT
#define INVALID_LEVEL ((int16_t)-256) //!< INVALID_LEVEL
#if defined(MY_RX_MESSAGE_BUFFER_FEATURE)
#if defined(MY_RADIO_NRF5_ESB)
@@ -46,14 +46,14 @@
* @brief Signal report selector
*/
typedef enum {
SR_RX_RSSI, //!< SR_RX_RSSI
SR_TX_RSSI, //!< SR_TX_RSSI
SR_RX_SNR, //!< SR_RX_SNR
SR_TX_SNR, //!< SR_TX_SNR
SR_TX_POWER_LEVEL, //!< SR_TX_POWER_LEVEL
SR_TX_POWER_PERCENT, //!< SR_TX_POWER_PERCENT
SR_UPLINK_QUALITY, //!< SR_UPLINK_QUALITY
SR_NOT_DEFINED //!< SR_NOT_DEFINED
SR_RX_RSSI, //!< SR_RX_RSSI
SR_TX_RSSI, //!< SR_TX_RSSI
SR_RX_SNR, //!< SR_RX_SNR
SR_TX_SNR, //!< SR_TX_SNR
SR_TX_POWER_LEVEL, //!< SR_TX_POWER_LEVEL
SR_TX_POWER_PERCENT, //!< SR_TX_POWER_PERCENT
SR_UPLINK_QUALITY, //!< SR_UPLINK_QUALITY
SR_NOT_DEFINED //!< SR_NOT_DEFINED
} signalReport_t;
@@ -69,7 +69,7 @@ void transportSetAddress(const uint8_t address);
/**
* @brief Retrieve node address
*/
uint8_t transportGetAddress(void);
uint8_t transportGetAddress(void) __attribute__((unused));
/**
* @brief Send message
* @param to recipient
@@ -78,7 +78,7 @@ uint8_t transportGetAddress(void);
* @param noACK do not wait for ACK
* @return true if message sent successfully
*/
bool transportSend(const uint8_t to, const void* data, const uint8_t len,
bool transportSend(const uint8_t to, const void *data, const uint8_t len,
const bool noACK = false);
/**
* @brief Verify if RX FIFO has pending messages
@@ -86,7 +86,7 @@ bool transportSend(const uint8_t to, const void* data, const uint8_t len,
*/
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
*/
bool transportSanityCheck(void);
@@ -94,7 +94,7 @@ bool transportSanityCheck(void);
* @brief Receive message from FIFO
* @return length of received message (header + payload)
*/
uint8_t transportReceive(void* data);
uint8_t transportReceive(void *data);
/**
* @brief Power down transport HW (if corresponding MY_XYZ_POWER_PIN defined)
*/
@@ -113,30 +113,36 @@ void transportSleep(void);
void transportStandBy(void);
/**
* @brief transportGetSendingRSSI
* @return RSSI
* @return RSSI of outgoing message (via ACK packet)
*/
int16_t transportGetSendingRSSI(void);
/**
* @brief transportGetReceivingRSSI
* @return RSSI
* @return RSSI of incoming message
*/
int16_t transportGetReceivingRSSI(void);
/**
* @brief transportGetSendingSNR
* @return SNR
* @return SNR of outgoing message (via ACK packet)
*/
int16_t transportGetSendingSNR(void);
/**
* @brief transportGetReceivingSNR
* @return SNR
* @return SNR of incoming message
*/
int16_t transportGetReceivingSNR(void);
/**
* @brief transportGetTxPowerPercent
* @return TX power in percent
* @return TX power level in percent
*/
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
* @return TX power in dBm
*/
@@ -2,12 +2,11 @@
* The MySensors Arduino library handles the wireless radio link and protocol
* between your home built sensors/actuators and HA controller of choice.
* 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
* the
* repeater and gateway builds a routing tables in EEPROM which keeps track of the
* network topology allowing messages to be routed to nodes.
*
* 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
* Full contributor list:
* https://github.com/mysensors/Arduino/graphs/contributors
@@ -20,37 +19,33 @@
* version 2 as published by the Free Software Foundation.
*/
#include "MyTransportHAL.h"
#include "drivers/NRF5/Radio.h"
#include "drivers/NRF5/Radio_ESB.h"
#include "drivers/CircularBuffer/CircularBuffer.h"
#if defined(MY_NRF5_ESB_ENABLE_ENCRYPTION)
#include "drivers/AES/AES.h"
#endif
#if defined(MY_NRF5_ESB_ENABLE_ENCRYPTION)
AES _aes;
uint8_t _dataenc[32] = {0};
uint8_t _psk[16];
#include "drivers/AES/AES.cpp"
AES NRF5_ESB_aes;
uint8_t NRF5_ESB_dataenc[32] = {0};
#endif
bool transportInit(void)
{
#if defined(MY_NRF5_ESB_ENABLE_ENCRYPTION)
uint8_t NRF5_ESB_psk[16];
#ifdef MY_ENCRYPTION_SIMPLE_PASSWD
memset(_psk, 0, 16);
memcpy(_psk, MY_ENCRYPTION_SIMPLE_PASSWD, strnlen(MY_ENCRYPTION_SIMPLE_PASSWD, 16));
(void)memset(NRF5_ESB_psk, 0, 16);
(void)memcpy(NRF5_ESB_psk, MY_ENCRYPTION_SIMPLE_PASSWD, strnlen(MY_ENCRYPTION_SIMPLE_PASSWD, 16));
#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
// 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
memset(_psk, 0, 16);
(void)memset(NRF5_ESB_psk, 0, 16);
#endif
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)
// 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!
_aes.set_IV(0);
NRF5_ESB_aes.set_IV(0);
const uint8_t finalLength = len > 16 ? 32 : 16;
// encrypt data
_aes.cbc_encrypt(_dataenc, _dataenc, finalLength / 16);
return NRF5_ESB_sendMessage(to, _dataenc, finalLength, noACK);
NRF5_ESB_aes.cbc_encrypt(NRF5_ESB_dataenc, NRF5_ESB_dataenc, finalLength / 16);
return NRF5_ESB_sendMessage(to, NRF5_ESB_dataenc, finalLength, noACK);
#else
return NRF5_ESB_sendMessage(to, data, len, noACK);
#endif
@@ -97,10 +92,10 @@ uint8_t transportReceive(void *data)
len = NRF5_ESB_readMessage(data);
#if defined(MY_NRF5_ESB_ENABLE_ENCRYPTION)
// has to be adjusted, WIP!
_aes.set_IV(0);
NRF5_ESB_aes.set_IV(0);
// decrypt data
if (_aes.cbc_decrypt((uint8_t *)(data), (uint8_t *)(data),
len > 16 ? 2 : 1) != AES_SUCCESS) {
if (NRF5_ESB_aes.cbc_decrypt((uint8_t *)(data), (uint8_t *)(data),
len > 16 ? 2 : 1) != AES_SUCCESS) {
len = 0;
}
#endif
@@ -6,7 +6,7 @@
* network topology allowing messages to be routed to nodes.
*
* 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
*
* Documentation: http://www.mysensors.org
@@ -17,11 +17,12 @@
* version 2 as published by the Free Software Foundation.
*/
#include "MyTransportHAL.h"
#include "drivers/RF24/RF24.h"
#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
#if defined(MY_RX_MESSAGE_BUFFER_FEATURE)
@@ -59,25 +60,20 @@ static void transportRxCallback(void)
}
#endif
#if defined(MY_RF24_ENABLE_ENCRYPTION)
AES _aes;
uint8_t _dataenc[32] = {0};
uint8_t _psk[16];
#endif
bool transportInit(void)
{
#if defined(MY_RF24_ENABLE_ENCRYPTION)
uint8_t RF24_psk[16];
#ifdef MY_ENCRYPTION_SIMPLE_PASSWD
memset(_psk, 0, 16);
memcpy(_psk, MY_ENCRYPTION_SIMPLE_PASSWD, strnlen(MY_ENCRYPTION_SIMPLE_PASSWD, 16));
(void)memset(RF24_psk, 0, 16);
(void)memcpy(RF24_psk, MY_ENCRYPTION_SIMPLE_PASSWD, strnlen(MY_ENCRYPTION_SIMPLE_PASSWD, 16));
#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
//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
memset(_psk, 0, 16);
(void)memset(RF24_psk, 0, 16);
#endif
#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)
// copy input data because it is read-only
(void)memcpy(_dataenc,data,len);
(void)memcpy(RF24_dataenc,data,len);
// has to be adjusted, WIP!
_aes.set_IV(0);
RF24_aes.set_IV(0);
const uint8_t finalLength = len > 16 ? 32 : 16;
//encrypt data
_aes.cbc_encrypt(_dataenc, _dataenc, finalLength /16);
return RF24_sendMessage(to, _dataenc, finalLength, noACK);
RF24_aes.cbc_encrypt(RF24_dataenc, RF24_dataenc, finalLength / 16);
return RF24_sendMessage(to, RF24_dataenc, finalLength, noACK);
#else
return RF24_sendMessage(to, data, len, noACK);
#endif
@@ -143,9 +139,9 @@ uint8_t transportReceive(void* data)
#endif
#if defined(MY_RF24_ENABLE_ENCRYPTION)
// has to be adjusted, WIP!
_aes.set_IV(0);
RF24_aes.set_IV(0);
// 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;
}
#endif
@@ -176,6 +172,7 @@ int16_t transportGetSendingRSSI(void)
{
return RF24_getSendingRSSI();
}
int16_t transportGetReceivingRSSI(void)
{
// not available, only bool RPD
@@ -206,5 +203,3 @@ bool transportSetTxPowerPercent(const uint8_t powerPercent)
{
return RF24_setTxPowerPercent(powerPercent);
}
@@ -6,7 +6,7 @@
* network topology allowing messages to be routed to nodes.
*
* 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
*
* Documentation: http://www.mysensors.org
@@ -17,8 +17,6 @@
* version 2 as published by the Free Software Foundation.
*/
#include "MyTransportHAL.h"
#if defined(MY_RFM69_NEW_DRIVER)
#include "drivers/RFM69/new/RFM69_new.h"
@@ -34,17 +32,16 @@ bool transportInit(void)
#endif
#ifdef MY_RFM69_ENABLE_ENCRYPTION
uint8_t _psk[16];
uint8_t RFM69_psk[16];
#ifdef MY_ENCRYPTION_SIMPLE_PASSWD
memset(_psk, 0, 16);
memcpy(_psk, MY_ENCRYPTION_SIMPLE_PASSWD, strnlen(MY_ENCRYPTION_SIMPLE_PASSWD, 16));
(void)memset(RFM69_psk, 0, 16);
(void)memcpy(RFM69_psk, MY_ENCRYPTION_SIMPLE_PASSWD, strnlen(MY_ENCRYPTION_SIMPLE_PASSWD, 16));
#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
RFM69_encrypt((const char*)_psk);
(void)memset(_psk, 0, 16); // Make sure it is purged from memory when set
RFM69_encrypt((const char*)RFM69_psk);
(void)memset(RFM69_psk, 0, 16); // Make sure it is purged from memory when set
#endif
return result;
}
@@ -146,6 +143,7 @@ int16_t transportGetTxPowerLevel(void)
{
return RFM69_getTxPowerLevel();
}
bool transportSetTxPowerPercent(const uint8_t 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)
if (_radio.initialize(MY_RFM69_FREQUENCY, _address, MY_RFM69_NETWORKID)) {
#ifdef MY_RFM69_ENABLE_ENCRYPTION
uint8_t _psk[16];
uint8_t RFM69_psk[16];
#ifdef MY_ENCRYPTION_SIMPLE_PASSWD
memset(_psk, 0, 16);
memcpy(_psk, MY_ENCRYPTION_SIMPLE_PASSWD, strnlen(MY_ENCRYPTION_SIMPLE_PASSWD, 16));
(void)memset(RFM69_psk, 0, 16);
(void)memcpy(RFM69_psk, MY_ENCRYPTION_SIMPLE_PASSWD, strnlen(MY_ENCRYPTION_SIMPLE_PASSWD, 16));
#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
_radio.encrypt((const char*)_psk);
(void)memset(_psk, 0, 16); // Make sure it is purged from memory when set
_radio.encrypt((const char*)RFM69_psk);
(void)memset(RFM69_psk, 0, 16); // Make sure it is purged from memory when set
#endif
return true;
}
@@ -235,10 +233,12 @@ void transportStandBy(void)
{
_radio.standBy();
}
void transportPowerDown(void)
{
_radio.powerDown();
}
void transportPowerUp(void)
{
_radio.powerUp();
@@ -274,4 +274,11 @@ int16_t transportGetTxPowerLevel(void)
return INVALID_LEVEL;
}
bool transportSetTxPowerLevel(const uint8_t powerLevel)
{
// not implemented
(void)powerLevel;
return false;
}
#endif
@@ -6,7 +6,7 @@
* network topology allowing messages to be routed to nodes.
*
* 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
*
* Documentation: http://www.mysensors.org
@@ -15,12 +15,14 @@
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
*
*/
#include "MyTransportHAL.h"
#include "drivers/RFM95/RFM95.h"
#if defined(MY_RFM95_ENABLE_ENCRYPTION)
#include "drivers/AES/AES.cpp"
#endif
bool transportInit(void)
{
const bool result = RFM95_initialise(MY_RFM95_FREQUENCY);
@@ -6,7 +6,7 @@
* network topology allowing messages to be routed to nodes.
*
* 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
*
* Documentation: http://www.mysensors.org
@@ -52,9 +52,6 @@
// Serial Transport
#include "MyTransportHAL.h"
#ifdef __linux__
#include "SerialPort.h"
#endif
@@ -367,15 +364,17 @@ void transportPowerDown(void)
void transportPowerUp(void)
{
// not implemented
}
void transportSleep(void)
{
// not implemented
}
void transportStandBy(void)
{
// not implemented
}
int16_t transportGetSendingRSSI(void)