From d5b4492cf30155728d4cc79aa7a5085749a06ab9 Mon Sep 17 00:00:00 2001 From: Geovane Fedrecheski Date: Thu, 17 Mar 2022 23:33:34 -0300 Subject: [PATCH 1/3] pkg/semtech-loramac: enable setting channels mask - user can set the channel mask - includes a patch due to LoRa v1.0.3rA spec change --- .../contrib/semtech_loramac_getset.c | 11 +++++++++++ pkg/semtech-loramac/include/semtech_loramac.h | 8 ++++++++ .../0005-relax-channel-mask-rules-in-regi.patch | Bin 0 -> 1437 bytes 3 files changed, 19 insertions(+) create mode 100644 pkg/semtech-loramac/patches/0005-relax-channel-mask-rules-in-regi.patch diff --git a/pkg/semtech-loramac/contrib/semtech_loramac_getset.c b/pkg/semtech-loramac/contrib/semtech_loramac_getset.c index 251060045a..6a449a620e 100644 --- a/pkg/semtech-loramac/contrib/semtech_loramac_getset.c +++ b/pkg/semtech-loramac/contrib/semtech_loramac_getset.c @@ -407,3 +407,14 @@ uint32_t semtech_loramac_get_uplink_counter(semtech_loramac_t *mac) mutex_unlock(&mac->lock); return counter; } + +void semtech_loramac_set_channels_mask(semtech_loramac_t *mac, uint16_t *mask) +{ + mutex_lock(&mac->lock); + DEBUG("[semtech-loramac] setting channels mask\n"); + MibRequestConfirm_t mibReqChannel; + mibReqChannel.Type = MIB_CHANNELS_MASK; + mibReqChannel.Param.ChannelsMask = mask; + LoRaMacMibSetRequestConfirm(&mibReqChannel); + mutex_unlock(&mac->lock); +} diff --git a/pkg/semtech-loramac/include/semtech_loramac.h b/pkg/semtech-loramac/include/semtech_loramac.h index 884e6232e7..d02ef09914 100644 --- a/pkg/semtech-loramac/include/semtech_loramac.h +++ b/pkg/semtech-loramac/include/semtech_loramac.h @@ -504,6 +504,14 @@ uint8_t semtech_loramac_get_rx2_dr(semtech_loramac_t *mac); */ void semtech_loramac_set_uplink_counter(semtech_loramac_t *mac, uint32_t counter); +/** + * @brief Sets the Channels Mask + * + * @param[in] mac Pointer to the mac + * @param[in] mask Mask array, e.g., {0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x0000, 0x0000} + */ +void semtech_loramac_set_channels_mask(semtech_loramac_t *mac, uint16_t *mask); + /** * @brief Gets the Uplink Frame Counter * diff --git a/pkg/semtech-loramac/patches/0005-relax-channel-mask-rules-in-regi.patch b/pkg/semtech-loramac/patches/0005-relax-channel-mask-rules-in-regi.patch new file mode 100644 index 0000000000000000000000000000000000000000..f71194004805f3b8cc93f4b3cafd5acb8d00cb43 GIT binary patch literal 1437 zcmb7D+iu%95Pc`me;A-ZVQ(ypq-0svwm}ScvspAQiaLEN76Bzv78{9jMJh=z`|mqc zY{czDiV}h-4QI}rIh;A~+6Hn#%P5Hw&SJh0yi7zfPh}F7OtQHuBFuZ2??Tvh$V zL#;)JD4YY2GRCqfg@8tsl1-m~QiaRlf&GMR4wkIsDv@9hDO*M==xe&&<4-8 z8rdyBEZB^Yt4doml{Lm&aFv1@Q(6bs;SOy%*xnB@L&yq2*9f>#4$9sX4#CK1ALKJ` zmCxd-rk*StXQXm&XR|QeYFG8SuPnT5I}sS=@Z-H$iy|_-DdL>YSrpo?2pds^4;6(+B&Wsm%XmJNr?9#P)vgb;s1lmXG+7W51Ob7kIKg*d4AAYc2rwvht%jT0Dv6iOK&o1KQSB%g z6C!n4VhAb+;>m&`fAW}UBh@|7WG>iDmeXmH<`HA11V(8R$DaK!GLVy#lV4>yJA)uf z;|VtFiQf}I%WbPA9No@xx2wOb&M&ofBRKkbCpyvCYxf6;M-Lbict#*^+xi&es0~MO z^z(?}d-2eyV?_A&j0AwI*T$vS4ovRDa6T-&+9R*92U@dgd*cpgqv3A$IKk<`><#~z z3D60|F#Z#v_vm4WY*cYGjE(7=Ty?(j1kTCr!#(?qkIu`YXgjIR7F-L<)q3gYv&V75 z4w%55@7~Y7?i2_IwGud(oC4#sHy2+I^KB=f%SS{%!+w~+R-&$VJ)z2~0eSj`U zFgn)arB5)17cce>Ua}t?PQjm}qJx?TRlQrMT;CZeMQxRr#M}PE9mV&{-f34QK420-|f( Date: Fri, 18 Mar 2022 10:30:40 -0300 Subject: [PATCH 2/3] sys/shell: add 'loramac set ch_mask' command --- sys/include/net/loramac.h | 9 +++++++++ sys/shell/commands/sc_loramac.c | 18 +++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/sys/include/net/loramac.h b/sys/include/net/loramac.h index 48b432a802..c602718c49 100644 --- a/sys/include/net/loramac.h +++ b/sys/include/net/loramac.h @@ -547,6 +547,15 @@ extern "C" { */ #define LORAMAC_NETWORK_ID_LEN (3U) +/** + * @brief Maximum length for channel mask + * + * The actual length is set by each region-specific LoRaMac + * implementation (see CHANNELS_MASK_SIZE), which + * automatically slices down the channel array mask. + */ +#define LORAMAC_CHANNELS_MASK_MAX_LEN (6U) + /** @} */ /** diff --git a/sys/shell/commands/sc_loramac.c b/sys/shell/commands/sc_loramac.c index 72cd487f41..540be6620a 100644 --- a/sys/shell/commands/sc_loramac.c +++ b/sys/shell/commands/sc_loramac.c @@ -58,7 +58,7 @@ static void _loramac_tx_usage(void) static void _loramac_set_usage(void) { puts("Usage: loramac set "); + "class|dr|adr|public|netid|tx_power|rx2_freq|rx2_dr|ul_cnt|ch_mask> "); } static void _loramac_get_usage(void) @@ -347,6 +347,22 @@ int _loramac_handler(int argc, char **argv) uint32_t counter = atoi(argv[3]); semtech_loramac_set_uplink_counter(&loramac, counter); } + else if (strcmp("ch_mask", argv[2]) == 0) { + if (argc < 4) { + puts("Usage: loramac set ch_mask "); + puts("Example (sets channels 0-3): loramac set ch_mask 000F00000000000000000000"); + return 1; + } + uint16_t mask[LORAMAC_CHANNELS_MASK_MAX_LEN] = { 0 }; + uint8_t tmp[LORAMAC_CHANNELS_MASK_MAX_LEN*2]; + fmt_hex_bytes(tmp, argv[3]); + for (size_t i = 0, j = 0; i < LORAMAC_CHANNELS_MASK_MAX_LEN; i++, j+=2) { + /* copy over to span a 16-bit -wide unsigned integer */ + mask[i] |= tmp[j] << 8; + mask[i] |= tmp[j+1]; + } + semtech_loramac_set_channels_mask(&loramac, mask); + } else { _loramac_set_usage(); return 1; From eabeee0ebe658b9b2e4ece076c6c799d195f7fac Mon Sep 17 00:00:00 2001 From: Geovane Fedrecheski Date: Fri, 18 Mar 2022 14:26:01 -0300 Subject: [PATCH 3/3] sys/shell+pkg/semtech-loramac: add get ch_mask Also, set LORAMAC_CHANNELS_MASK_LEN based on the selected LORA_REGION configuration. --- .../contrib/semtech_loramac_getset.c | 19 +++++++++++++++---- pkg/semtech-loramac/include/semtech_loramac.h | 14 +++++++++++--- sys/include/net/loramac.h | 12 +++++++----- sys/shell/commands/sc_loramac.c | 17 +++++++++++++---- 4 files changed, 46 insertions(+), 16 deletions(-) diff --git a/pkg/semtech-loramac/contrib/semtech_loramac_getset.c b/pkg/semtech-loramac/contrib/semtech_loramac_getset.c index 6a449a620e..29e65e560a 100644 --- a/pkg/semtech-loramac/contrib/semtech_loramac_getset.c +++ b/pkg/semtech-loramac/contrib/semtech_loramac_getset.c @@ -412,9 +412,20 @@ void semtech_loramac_set_channels_mask(semtech_loramac_t *mac, uint16_t *mask) { mutex_lock(&mac->lock); DEBUG("[semtech-loramac] setting channels mask\n"); - MibRequestConfirm_t mibReqChannel; - mibReqChannel.Type = MIB_CHANNELS_MASK; - mibReqChannel.Param.ChannelsMask = mask; - LoRaMacMibSetRequestConfirm(&mibReqChannel); + MibRequestConfirm_t mibReq; + mibReq.Type = MIB_CHANNELS_MASK; + mibReq.Param.ChannelsMask = mask; + LoRaMacMibSetRequestConfirm(&mibReq); + mutex_unlock(&mac->lock); +} + +void semtech_loramac_get_channels_mask(semtech_loramac_t *mac, uint16_t *mask) +{ + mutex_lock(&mac->lock); + DEBUG("[semtech-loramac] getting channels mask\n"); + MibRequestConfirm_t mibReq; + mibReq.Type = MIB_CHANNELS_MASK; + LoRaMacMibGetRequestConfirm(&mibReq); + memcpy(mask, mibReq.Param.ChannelsMask, LORAMAC_CHANNELS_MASK_LEN); mutex_unlock(&mac->lock); } diff --git a/pkg/semtech-loramac/include/semtech_loramac.h b/pkg/semtech-loramac/include/semtech_loramac.h index d02ef09914..656454f55e 100644 --- a/pkg/semtech-loramac/include/semtech_loramac.h +++ b/pkg/semtech-loramac/include/semtech_loramac.h @@ -504,6 +504,14 @@ uint8_t semtech_loramac_get_rx2_dr(semtech_loramac_t *mac); */ void semtech_loramac_set_uplink_counter(semtech_loramac_t *mac, uint32_t counter); +/** + * @brief Gets the Uplink Frame Counter + * + * @param[in] mac Pointer to the mac + * @return Uplink frame counter + */ +uint32_t semtech_loramac_get_uplink_counter(semtech_loramac_t *mac); + /** * @brief Sets the Channels Mask * @@ -513,12 +521,12 @@ void semtech_loramac_set_uplink_counter(semtech_loramac_t *mac, uint32_t counter void semtech_loramac_set_channels_mask(semtech_loramac_t *mac, uint16_t *mask); /** - * @brief Gets the Uplink Frame Counter + * @brief Gets the Channels Mask * * @param[in] mac Pointer to the mac - * @return Uplink frame counter + * @param[in] mask Mask array pointer */ -uint32_t semtech_loramac_get_uplink_counter(semtech_loramac_t *mac); +void semtech_loramac_get_channels_mask(semtech_loramac_t *mac, uint16_t *mask); #ifdef MODULE_PERIPH_EEPROM /** diff --git a/sys/include/net/loramac.h b/sys/include/net/loramac.h index c602718c49..b857684aa9 100644 --- a/sys/include/net/loramac.h +++ b/sys/include/net/loramac.h @@ -548,13 +548,15 @@ extern "C" { #define LORAMAC_NETWORK_ID_LEN (3U) /** - * @brief Maximum length for channel mask + * @brief Channel mask length * - * The actual length is set by each region-specific LoRaMac - * implementation (see CHANNELS_MASK_SIZE), which - * automatically slices down the channel array mask. + * Must match CHANNELS_MASK_SIZE in src/mac/region/RegionXXYYY.c */ -#define LORAMAC_CHANNELS_MASK_MAX_LEN (6U) +#if defined(REGION_AU915) || defined(REGION_CN470) || defined(REGION_US915) || defined(REGION_US915_HYBRID) || defined(REGION_AS923) +#define LORAMAC_CHANNELS_MASK_LEN (6U) +#else +#define LORAMAC_CHANNELS_MASK_LEN (1U) +#endif /** @} */ diff --git a/sys/shell/commands/sc_loramac.c b/sys/shell/commands/sc_loramac.c index 540be6620a..75a78efef5 100644 --- a/sys/shell/commands/sc_loramac.c +++ b/sys/shell/commands/sc_loramac.c @@ -64,7 +64,7 @@ static void _loramac_set_usage(void) static void _loramac_get_usage(void) { puts("Usage: loramac get "); + "class|dr|adr|public|netid|tx_power|rx2_freq|rx2_dr|ul_cnt|ch_mask>"); } int _loramac_handler(int argc, char **argv) @@ -166,6 +166,15 @@ int _loramac_handler(int argc, char **argv) else if (strcmp("ul_cnt", argv[2]) == 0) { printf("Uplink Counter: %"PRIu32"\n", semtech_loramac_get_uplink_counter(&loramac)); } + else if (strcmp("ch_mask", argv[2]) == 0) { + uint16_t mask[LORAMAC_CHANNELS_MASK_LEN] = { 0 }; + semtech_loramac_get_channels_mask(&loramac, mask); + printf("Channels mask: "); + for (size_t i = 0; i < LORAMAC_CHANNELS_MASK_LEN; i++) { + printf("%04x", mask[i]); + } + printf("\n"); + } else { _loramac_get_usage(); return 1; @@ -353,10 +362,10 @@ int _loramac_handler(int argc, char **argv) puts("Example (sets channels 0-3): loramac set ch_mask 000F00000000000000000000"); return 1; } - uint16_t mask[LORAMAC_CHANNELS_MASK_MAX_LEN] = { 0 }; - uint8_t tmp[LORAMAC_CHANNELS_MASK_MAX_LEN*2]; + uint16_t mask[LORAMAC_CHANNELS_MASK_LEN] = { 0 }; + uint8_t tmp[LORAMAC_CHANNELS_MASK_LEN*2]; fmt_hex_bytes(tmp, argv[3]); - for (size_t i = 0, j = 0; i < LORAMAC_CHANNELS_MASK_MAX_LEN; i++, j+=2) { + for (size_t i = 0, j = 0; i < LORAMAC_CHANNELS_MASK_LEN; i++, j+=2) { /* copy over to span a 16-bit -wide unsigned integer */ mask[i] |= tmp[j] << 8; mask[i] |= tmp[j+1];