[LoRaWAN] Improve FPort checks, add TS009 option
This commit is contained in:
parent
ceb91c91c7
commit
237531c9a0
3 changed files with 39 additions and 9 deletions
|
@ -499,7 +499,7 @@
|
||||||
#define RADIOLIB_ERR_INVALID_REVISION (-1103)
|
#define RADIOLIB_ERR_INVALID_REVISION (-1103)
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Invalid LoRaWAN uplink port requested by user.
|
\brief Invalid LoRaWAN uplink port requested by user, or downlink received at invalid port.
|
||||||
*/
|
*/
|
||||||
#define RADIOLIB_ERR_INVALID_PORT (-1104)
|
#define RADIOLIB_ERR_INVALID_PORT (-1104)
|
||||||
|
|
||||||
|
|
|
@ -877,9 +877,13 @@ int16_t LoRaWANNode::uplink(uint8_t* data, size_t len, uint8_t fPort, bool isCon
|
||||||
}
|
}
|
||||||
|
|
||||||
// check destination fPort
|
// check destination fPort
|
||||||
if(fPort > 0xDF) {
|
if(fPort > RADIOLIB_LORAWAN_FPORT_RESERVED) {
|
||||||
|
RADIOLIB_DEBUG_PROTOCOL_PRINTLN("Requested uplink at FPort %d - rejected! This FPort is RFU.", fPort);
|
||||||
return(RADIOLIB_ERR_INVALID_PORT);
|
return(RADIOLIB_ERR_INVALID_PORT);
|
||||||
}
|
}
|
||||||
|
if(fPort == RADIOLIB_LORAWAN_FPORT_TS009 && this->TS009 == false) {
|
||||||
|
RADIOLIB_DEBUG_PROTOCOL_PRINTLN("Requested uplink at FPort %d - rejected! TS009 was not enabled.", fPort);
|
||||||
|
}
|
||||||
// fPort 0 is only allowed for MAC-only payloads
|
// fPort 0 is only allowed for MAC-only payloads
|
||||||
if(fPort == RADIOLIB_LORAWAN_FPORT_MAC_COMMAND) {
|
if(fPort == RADIOLIB_LORAWAN_FPORT_MAC_COMMAND) {
|
||||||
if (!this->isMACPayload) {
|
if (!this->isMACPayload) {
|
||||||
|
@ -900,9 +904,12 @@ int16_t LoRaWANNode::uplink(uint8_t* data, size_t len, uint8_t fPort, bool isCon
|
||||||
|
|
||||||
// check maximum payload len as defined in phy
|
// check maximum payload len as defined in phy
|
||||||
if(len > this->band->payloadLenMax[this->dataRates[RADIOLIB_LORAWAN_CHANNEL_DIR_UPLINK]]) {
|
if(len > this->band->payloadLenMax[this->dataRates[RADIOLIB_LORAWAN_CHANNEL_DIR_UPLINK]]) {
|
||||||
return(RADIOLIB_ERR_PACKET_TOO_LONG);
|
// normally, throw an error if the packet is too long
|
||||||
// if testing with TS009 specification verification protocol, don't throw error but clip the message
|
if(this->TS009 == false) {
|
||||||
// len = this->band->payloadLenMax[this->dataRates[RADIOLIB_LORAWAN_CHANNEL_DIR_UPLINK]];
|
return(RADIOLIB_ERR_PACKET_TOO_LONG);
|
||||||
|
}
|
||||||
|
// if testing with TS009 Specification Verification Protocol, don't throw error but clip the message
|
||||||
|
len = this->band->payloadLenMax[this->dataRates[RADIOLIB_LORAWAN_CHANNEL_DIR_UPLINK]];
|
||||||
}
|
}
|
||||||
|
|
||||||
bool adrAckReq = false;
|
bool adrAckReq = false;
|
||||||
|
@ -1383,6 +1390,22 @@ int16_t LoRaWANNode::downlink(uint8_t* data, size_t* len, LoRaWANEvent_t* event)
|
||||||
if(payLen > 0) {
|
if(payLen > 0) {
|
||||||
payLen -= 1; // subtract one as fPort is set
|
payLen -= 1; // subtract one as fPort is set
|
||||||
fPort = downlinkMsg[RADIOLIB_LORAWAN_FHDR_FPORT_POS(fOptsLen)];
|
fPort = downlinkMsg[RADIOLIB_LORAWAN_FHDR_FPORT_POS(fOptsLen)];
|
||||||
|
// check if fPort value is actually allowed
|
||||||
|
if(fPort > RADIOLIB_LORAWAN_FPORT_RESERVED) {
|
||||||
|
RADIOLIB_DEBUG_PROTOCOL_PRINTLN("Received downlink at FPort %d - rejected! This FPort is RFU!", fPort);
|
||||||
|
#if !RADIOLIB_STATIC_ONLY
|
||||||
|
delete[] downlinkMsg;
|
||||||
|
#endif
|
||||||
|
return(RADIOLIB_ERR_INVALID_PORT);
|
||||||
|
}
|
||||||
|
if(fPort == RADIOLIB_LORAWAN_FPORT_TS009 && this->TS009 == false) {
|
||||||
|
RADIOLIB_DEBUG_PROTOCOL_PRINTLN("Received downlink at FPort %d - rejected! TS009 was not enabled.", fPort);
|
||||||
|
#if !RADIOLIB_STATIC_ONLY
|
||||||
|
delete[] downlinkMsg;
|
||||||
|
#endif
|
||||||
|
return(RADIOLIB_ERR_INVALID_PORT);
|
||||||
|
}
|
||||||
|
|
||||||
if(fPort > RADIOLIB_LORAWAN_FPORT_MAC_COMMAND) {
|
if(fPort > RADIOLIB_LORAWAN_FPORT_MAC_COMMAND) {
|
||||||
isAppDownlink = true;
|
isAppDownlink = true;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -41,7 +41,8 @@
|
||||||
|
|
||||||
// fPort field
|
// fPort field
|
||||||
#define RADIOLIB_LORAWAN_FPORT_MAC_COMMAND (0x00 << 0) // 7 0 payload contains MAC commands only
|
#define RADIOLIB_LORAWAN_FPORT_MAC_COMMAND (0x00 << 0) // 7 0 payload contains MAC commands only
|
||||||
#define RADIOLIB_LORAWAN_FPORT_RESERVED (0xE0 << 0) // 7 0 reserved fPort values
|
#define RADIOLIB_LORAWAN_FPORT_TS009 (0xE0 << 0) // 7 0 fPort used for TS009 testing
|
||||||
|
#define RADIOLIB_LORAWAN_FPORT_RESERVED (0xE0 << 0) // 7 0 fPort values equal to and larger than this are reserved
|
||||||
|
|
||||||
// MAC commands - only those sent from end-device to gateway
|
// MAC commands - only those sent from end-device to gateway
|
||||||
#define RADIOLIB_LORAWAN_LINK_CHECK_REQ (0x02 << 0) // 7 0 MAC command: request to check connectivity to network
|
#define RADIOLIB_LORAWAN_LINK_CHECK_REQ (0x02 << 0) // 7 0 MAC command: request to check connectivity to network
|
||||||
|
@ -849,10 +850,16 @@ class LoRaWANNode {
|
||||||
uint64_t getDevAddr();
|
uint64_t getDevAddr();
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Get the Time-on-air of the last uplink message
|
\brief Get the Time-on-air of the last uplink message.
|
||||||
\returns (RadioLibTime_t) time-on-air (ToA) of last uplink message
|
\returns (RadioLibTime_t) time-on-air (ToA) of last uplink message.
|
||||||
*/
|
*/
|
||||||
RadioLibTime_t getLastToA();
|
RadioLibTime_t getLastToA();
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\brief TS009 Protocol Specification Verification switch
|
||||||
|
(allows FPort 224 and cuts off uplink payload instead of rejecting if maximum length exceeded).
|
||||||
|
*/
|
||||||
|
bool TS009 = false;
|
||||||
|
|
||||||
#if !RADIOLIB_GODMODE
|
#if !RADIOLIB_GODMODE
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Add table
Reference in a new issue