Skip to content

Commit

Permalink
fixup! gnrc/lorawan: add basic LoRaWAN 1.1 features
Browse files Browse the repository at this point in the history
  • Loading branch information
Ollrogge committed Apr 5, 2022
1 parent 423bfab commit b7741c5
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 56 deletions.
3 changes: 1 addition & 2 deletions examples/gnrc_lorawan/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ USEMODULE += gnrc_txtsnd

# Uncomment as needed if a board doesn't include a LoRa radio by default
#USEMODULE += sx1272
# USEMODULE += sx1276
#USEMODULE += sx1276

# As there is an 'app.config' we want to explicitly disable Kconfig by setting
# the variable to empty
Expand Down Expand Up @@ -60,7 +60,6 @@ ifndef CONFIG_KCONFIG_USEMODULE_LORAWAN
CFLAGS += -DCONFIG_LORAMAC_JOIN_EUI_DEFAULT=\"BBBBBBBBBBBBBBBB\"
CFLAGS += -DCONFIG_LORAMAC_DEV_EUI_DEFAULT=\"CCCCCCCCCCCCCCCC\"


# Uncomment to use LoRaWAN 1.1
#CFLAGS += -DCONFIG_LORAWAN_1_1

Expand Down
29 changes: 3 additions & 26 deletions sys/include/net/gnrc/lorawan.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,35 +196,12 @@ static inline void gnrc_lorawan_radio_rx_error_cb(gnrc_lorawan_t *mac)
void gnrc_lorawan_timeout_cb(gnrc_lorawan_t *mac);

/**
* @brief Init GNRC LoRaWAN version 1.0x
* @brief Init GNRC LoRaWAN
*
* @param[in] mac pointer to the MAC descriptor
* @param[in] appskey buffer to store the AppsKey. Should be at least 16 bytes long
* @param[in] fnwksintkey buffer to store the Forwarding network session
* integrity key, Serving network session integrity key and
* Network session encryption key (they all are the same for
* LoRaWAN 1.0x). Should be at least 16 bytes long
* @param[in] ctx pointer to LoRaWAN context
*/
void gnrc_lorawan_init_10x(gnrc_lorawan_t *mac, uint8_t *appskey,
uint8_t *fnwksintkey);

/**
* @brief Init GNRC LoRaWAN version 1.1x
*
* @param[in] mac pointer to the MAC descriptor
* @param[in] joineui pointer to the Join EUI
* @param[in] appskey buffer to store the AppsKey. Should be at least 16 bytes long
* @param[in] fnwksintkey buffer to store the Forwarding network session
* integrity key. Should be at least 16 bytes long
* @param[in] snwksintkey buffer to store the Serving network session integrity key. Should be at least 16 bytes long
* @param[in] nwksenckey buffer to store the Network session encryption key. Should be at least 16 bytes long
* @param[in] jsintkey buffer to store the Join session integrity key. Should be at least 16 bytes long
* @param[in] jsenckey buffer to store the Join session encryption key. Should be at least 16 bytes long
*/
void gnrc_lorawan_init_11x(gnrc_lorawan_t *mac, uint8_t *joineui,
uint8_t *appskey, uint8_t *fnwksintkey,
uint8_t *snwksintkey, uint8_t *nwksenckey,
uint8_t *jsintkey, uint8_t *jsenckey);
void gnrc_lorawan_init(gnrc_lorawan_t *mac, const gnrc_lorawan_ctx_t *ctx);

/**
* @brief Perform a MLME request
Expand Down
35 changes: 13 additions & 22 deletions sys/net/gnrc/link_layer/lorawan/gnrc_lorawan.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,34 +76,25 @@ static void _sleep_radio(gnrc_lorawan_t *mac)
dev->driver->set(dev, NETOPT_STATE, &state, sizeof(state));
}

#if IS_ACTIVE(CONFIG_LORAWAN_1_1)
void gnrc_lorawan_init_11x(gnrc_lorawan_t *mac, uint8_t *joineui,
uint8_t *appskey, uint8_t *fnwksintkey,
uint8_t *snwksintkey, uint8_t *nwksenckey,
uint8_t *jsintkey, uint8_t *jsenckey)
void gnrc_lorawan_init(gnrc_lorawan_t *mac, const gnrc_lorawan_ctx_t *ctx)
{
mac->joineui = joineui;
mac->appskey = appskey;
mac->fnwksintkey = fnwksintkey;
mac->snwksintkey = snwksintkey;
mac->nwksenckey = nwksenckey;
mac->jsintkey = jsintkey;
mac->jsenckey = jsenckey;
mac->busy = false;
gnrc_lorawan_mlme_backoff_init(mac);
gnrc_lorawan_reset(mac);
}
mac->joineui = ctx->joineui;
mac->appskey = ctx->appskey;

#if IS_ACTIVE(CONFIG_LORAWAN_1_1)
mac->fnwksintkey = ctx->fnwksintkey;
mac->snwksintkey = ctx->snwksintkey;
mac->nwksenckey = ctx->nwksenckey;
mac->jsintkey = ctx->jsintkey;
mac->jsenckey = ctx->jsenckey;
#else
void gnrc_lorawan_init_10x(gnrc_lorawan_t *mac, uint8_t *appskey,
uint8_t *fnwksintkey)
{
mac->appskey = appskey;
mac->fnwksintkey = mac->snwksintkey = mac->nwksenckey = fnwksintkey;
mac->fnwksintkey = mac->snwksintkey = mac->nwksenckey = ctx->fnwksintkey;
#endif

mac->busy = false;
gnrc_lorawan_mlme_backoff_init(mac);
gnrc_lorawan_reset(mac);
}
#endif

void gnrc_lorawan_reset(gnrc_lorawan_t *mac)
{
Expand Down
12 changes: 12 additions & 0 deletions sys/net/gnrc/link_layer/lorawan/include/gnrc_lorawan_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,18 @@ typedef struct {
uint8_t last_chan_idx; /**< index of channel used for last transmission */
} gnrc_lorawan_t;

typedef struct {
uint8_t *joineui; /**< pointer to Join EUI */
uint8_t *appskey; /**< pointer to Application SKey buffer */
uint8_t *fnwksintkey; /**< pointer to Forwarding Network session integrity key */
#if IS_ACTIVE(CONFIG_LORAWAN_1_1)
uint8_t *snwksintkey; /**< pointer to Serving Network session integrity key */
uint8_t *nwksenckey; /**< pointer to Network session encryption key */
uint8_t *jsintkey; /**< pointer to join session integrity key */
uint8_t *jsenckey; /**< pointer to join session encryption key */
#endif
} gnrc_lorawan_ctx_t;

/**
* @brief Encrypts LoRaWAN payload
*
Expand Down
24 changes: 18 additions & 6 deletions sys/net/gnrc/netif/lorawan/gnrc_netif_lorawan.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,13 +301,25 @@ static int _init(gnrc_netif_t *netif)
_set_be_addr(&netif->lorawan.mac, _devaddr);

#if IS_ACTIVE(CONFIG_LORAWAN_1_1)
gnrc_lorawan_init_11x(&netif->lorawan.mac, netif->lorawan.joineui,
netif->lorawan.appskey, netif->lorawan.fnwksintkey,
netif->lorawan.snwksintkey, netif->lorawan.nwksenckey,
netif->lorawan.jsintkey, netif->lorawan.jsenckey);
const gnrc_lorawan_ctx_t ctx = {
.joineui = netif->lorawan.joineui,
.appskey = netif->lorawan.appskey,
.fnwksintkey = netif->lorawan.fnwksintkey,
.snwksintkey = netif->lorawan.snwksintkey,
.nwksenckey = netif->lorawan.nwksenckey,
.jsintkey = netif->lorawan.jsintkey,
.jsenckey = netif->lorawan.jsenckey
};

gnrc_lorawan_init(&netif->lorawan.mac, &ctx);
#else
gnrc_lorawan_init_10x(&netif->lorawan.mac, netif->lorawan.appskey,
netif->lorawan.fnwksintkey);
const gnrc_lorawan_ctx_t ctx = {
.joineui = netif->lorawan.joineui,
.appskey = netif->lorawan.appskey,
.fnwksintkey = netif->lorawan.fnwksintkey,
};

gnrc_lorawan_init(&netif->lorawan.mac, &ctx);
#endif

ztimer_set_msg(ZTIMER_MSEC, &netif->lorawan.backoff_timer,
Expand Down

0 comments on commit b7741c5

Please sign in to comment.