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];