From 31aaea6749c4de950bb868a885208c0f3b4d5e73 Mon Sep 17 00:00:00 2001 From: Hasnain Virk Date: Mon, 30 Jul 2018 14:18:00 +0300 Subject: [PATCH] [IOTCELL-1181] Fixing incorrect NetID causing ABP Failures The issue rose up when using ARMC6. A test case didn't initialize NetID parameter for ABP while using connect(params) API. NetID is the first 7 bits of the Device Address. It makes sense to actually remove the net-id parameter from ABP settings as the stack can deduce it from device address. However, the ABP structure is exposed in public APIs, so we can't really do that at the moment. Simpler fix is to move the mask that helps us to extract first 7 bits of the device address is exposed in lorawan_types.h and the user can use it to deduce correct net-id. --- features/lorawan/lorastack/mac/LoRaMac.cpp | 8 +------- features/lorawan/lorawan_types.h | 5 +++++ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/features/lorawan/lorastack/mac/LoRaMac.cpp b/features/lorawan/lorastack/mac/LoRaMac.cpp index 6d7ed946bd7..c5abe8ab2a5 100644 --- a/features/lorawan/lorastack/mac/LoRaMac.cpp +++ b/features/lorawan/lorastack/mac/LoRaMac.cpp @@ -65,12 +65,6 @@ using namespace mbed; */ #define DOWN_LINK 1 -/** - * A mask for the network ID. - */ -#define LORAWAN_NETWORK_ID_MASK ( uint32_t )0xFE000000 - - LoRaMac::LoRaMac() : _lora_time(), _lora_phy(NULL), @@ -1434,7 +1428,7 @@ lorawan_status_t LoRaMac::prepare_join(const lorawan_connect_t *params, bool is_ const static uint8_t nwk_skey[] = MBED_CONF_LORA_NWKSKEY; const static uint8_t app_skey[] = MBED_CONF_LORA_APPSKEY; - _params.net_id = (MBED_CONF_LORA_DEVICE_ADDRESS & LORAWAN_NETWORK_ID_MASK); + _params.net_id = (MBED_CONF_LORA_DEVICE_ADDRESS & LORAWAN_NETWORK_ID_MASK) >> 25; _params.dev_addr = MBED_CONF_LORA_DEVICE_ADDRESS; memcpy(_params.keys.nwk_skey, nwk_skey, sizeof(_params.keys.nwk_skey)); diff --git a/features/lorawan/lorawan_types.h b/features/lorawan/lorawan_types.h index 72fb199fdd8..eef09f2d625 100644 --- a/features/lorawan/lorawan_types.h +++ b/features/lorawan/lorawan_types.h @@ -34,6 +34,11 @@ #include "platform/Callback.h" +/** + * A mask for the network ID. + */ +#define LORAWAN_NETWORK_ID_MASK (uint32_t) 0xFE000000 + /** * Option Flags for send(), receive() APIs *