GNRC LoRaWAN internal header. More...
GNRC LoRaWAN internal header.
Definition in file gnrc_lorawan_internal.h.
#include <stdio.h>
#include <string.h>
#include "iolist.h"
#include "net/lora.h"
#include "net/lorawan/hdr.h"
#include "net/gnrc/pktbuf.h"
#include "net/netdev.h"
#include "net/loramac.h"
Go to the source code of this file.
Data Structures | |
struct | lorawan_buffer_t |
buffer helper for parsing and constructing LoRaWAN packets. More... | |
struct | mlme_lorawan_join_t |
MLME Join Request data. More... | |
struct | mlme_link_req_confirm_t |
MLME Link Check confirmation data. More... | |
struct | mcps_data_t |
MCPS data. More... | |
struct | gnrc_lorawan_mcps_t |
MCPS service access point descriptor. More... | |
struct | gnrc_lorawan_mlme_t |
MLME service access point descriptor. More... | |
struct | gnrc_lorawan_key_ctx_t |
GNRC LoRaWAN key context struct. More... | |
struct | gnrc_lorawan_t |
GNRC LoRaWAN mac descriptor. More... | |
struct | gnrc_lorawan_persistent_state_t |
LoRaWAN state that needs to be preserved across reboots. More... | |
#define | MSG_TYPE_TIMEOUT (0x3457) |
Timeout message type. | |
#define | MTYPE_MASK 0xE0 |
MHDR mtype mask. | |
#define | MTYPE_JOIN_REQUEST 0x0 |
Join Request type. | |
#define | MTYPE_JOIN_ACCEPT 0x1 |
Join Accept type. | |
#define | MTYPE_UNCNF_UPLINK 0x2 |
Unconfirmed uplink type. | |
#define | MTYPE_UNCNF_DOWNLINK 0x3 |
Unconfirmed downlink type. | |
#define | MTYPE_CNF_UPLINK 0x4 |
Confirmed uplink type. | |
#define | MTYPE_CNF_DOWNLINK 0x5 |
Confirmed downlink type. | |
#define | MTYPE_REJOIN_REQ 0x6 |
Re-join request type. | |
#define | MTYPE_PROPIETARY 0x7 |
Proprietary frame type. | |
#define | MAJOR_MASK 0x3 |
Major mtype mask. | |
#define | MAJOR_LRWAN_R1 0x0 |
LoRaWAN R1 version type. | |
#define | MINOR_LRWAN 0x1 |
Minor LoRaWAN version of device. | |
#define | JOIN_REQUEST_SIZE (23U) |
Join Request size in bytes. | |
#define | MIC_SIZE (4U) |
MIC size in bytes. | |
#define | CFLIST_SIZE (16U) |
Channel Frequency list size in bytes. | |
#define | GNRC_LORAWAN_MAX_CHANNELS (16U) |
Maximum number of channels. | |
#define | LORAWAN_STATE_IDLE (0) |
MAC state machine in idle. | |
#define | LORAWAN_STATE_RX_1 (1) |
MAC state machine in RX1. | |
#define | LORAWAN_STATE_RX_2 (2) |
MAC state machine in RX2. | |
#define | LORAWAN_STATE_TX (3) |
MAC state machine in TX. | |
#define | LORAWAN_STATE_JOIN (4) |
MAC state machine in Join. | |
#define | GNRC_LORAWAN_DIR_UPLINK (0U) |
uplink frame direction | |
#define | GNRC_LORAWAN_DIR_DOWNLINK (1U) |
downlink frame direction | |
#define | GNRC_LORAWAN_BACKOFF_WINDOW_TICK (3600000000LL) |
backoff expire tick in usecs (set to 1 second) | |
#define | GNRC_LORAWAN_BACKOFF_BUDGET_1 (36000000LL) |
budget of time on air during the first hour | |
#define | GNRC_LORAWAN_BACKOFF_BUDGET_2 (36000000LL) |
budget of time on air between 1-10 hours after boot | |
#define | GNRC_LORAWAN_BACKOFF_BUDGET_3 (8700000LL) |
budget of time on air every 24 hours | |
#define | GNRC_LORAWAN_MLME_OPTS_LINK_CHECK_REQ (1 << 0) |
Internal Link Check request flag. | |
#define | GNRC_LORAWAN_MLME_OPTS_REKEY_IND_REQ (1 << 1) |
Internal Rekey Indication flag. | |
#define | GNRC_LORAWAN_CID_SIZE (1U) |
size of Command ID in FOps | |
#define | GNRC_LORAWAN_CID_LINK_CHECK_ANS (0x02) |
Link Check CID. | |
#define | GNCR_LORAWAN_REKEY_IND_SIZE (1U) |
RekeyInd MAC command size. | |
#define | GNCR_LORAWAN_CID_REKEY_CONF (0x0B) |
Reykey Confirmation CID. | |
#define | GNRC_LORAWAN_FOPT_LINK_CHECK_ANS_SIZE (3U) |
size of Link check answer | |
#define | GNRC_LORAWAN_FOPT_REKEY_CONF_SIZE (2U) |
size of Rekey confirmation | |
#define | GNRC_LORAWAN_JOIN_DELAY_U32_MASK (0x1FFFFF) |
mask for detecting overflow in frame counter | |
#define | GNRC_LORAWAN_MAX_PAYLOAD_1 (59U) |
max MAC payload in DR0, DR1 and DR2 | |
#define | GNRC_LORAWAN_MAX_PAYLOAD_2 (123U) |
max MAC payload in DR3 | |
#define | GNRC_LORAWAN_MAX_PAYLOAD_3 (250U) |
max MAC payload above DR3 | |
#define | GNRC_LORAWAN_CFLIST_ENTRY_SIZE (3U) |
size of Channel Frequency list | |
#define | GNRC_LORAWAN_JOIN_ACCEPT_MAX_SIZE (33U) |
max size of Join Accept frame | |
#define | GNRC_LORAWAN_BACKOFF_STATE_1 (0U) |
backoff state during the first hour after boot | |
#define | GNRC_LORAWAN_BACKOFF_STATE_2 (1U) |
backoff state between 1-10 hours after boot | |
#define | GNRC_LORAWAN_BACKOFF_STATE_3 (2U) |
backoff state past 11 hours after boot | |
#define | GNRC_LORAWAN_BACKOFF_TIME_1 (1U) |
duration of first backoff state (in hours) | |
#define | GNRC_LORAWAN_BACKOFF_TIME_2 (10U) |
duration of second backoff state (in hours) | |
#define | GNRC_LORAWAN_BACKOFF_TIME_3 (24U) |
duration of third backoff state (in hours) | |
#define | GNRC_LORAWAN_APP_NONCE_SIZE (3U) |
App Nonce size. | |
#define | GNRC_LORAWAN_JOIN_NONCE_SIZE (3U) |
Join nonce size. | |
#define | GNRC_LORAWAN_NET_ID_SIZE (3U) |
Net ID size. | |
#define | GNRC_LORAWAN_DEV_NONCE_SIZE (2U) |
Dev Nonce size. | |
#define | GNRC_LORAWAN_FOPTS_MAX_SIZE (15U) |
Maximum size of Fopts field. | |
#define | GNRC_LORAWAN_FPORT_SIZE (1U) |
Size of the Fport field. | |
#define | GNRC_LORAWAN_STATE_FLASHPAGE_NUM (FLASHPAGE_NUMOF - 0x4) |
Flashpage number where to store state. | |
#define | GNRC_LORAWAN_INITIALIZED_MARKER (0x52f94f54U) |
Persistent state initialized marker. | |
#define | MHDR_MIC_BUF_SIZE |
Size of the internal MHDR-MIC buffer. | |
enum | mlme_join_req_type_t { REJOIN_REQ_0 , REJOIN_REQ_1 , REJOIN_REQ_2 , JOIN_REQ = 0xFF } |
MLME Join Request type. More... | |
void | gnrc_lorawan_encrypt_payload (iolist_t *iolist, const le_uint32_t *dev_addr, uint32_t fcnt, uint8_t dir, const uint8_t *appskey) |
Encrypts LoRaWAN payload. | |
void | gnrc_lorawan_encrypt_fopts (uint8_t *fopts, size_t len, const le_uint32_t *dev_addr, uint32_t fcnt, bool afcnt, uint8_t dir, const uint8_t *key) |
Encrypts FOpts field. | |
void | gnrc_lorawan_decrypt_join_accept (const uint8_t *key, uint8_t *pkt, int has_clist, uint8_t *out) |
Decrypts join accept message. | |
void | gnrc_lorawan_generate_session_keys (const uint8_t *join_nonce, const uint8_t *dev_nonce, const uint8_t *joineui, gnrc_lorawan_t *mac) |
Generate LoRaWAN session keys. | |
void | gnrc_lorawan_generate_lifetime_session_keys (const uint8_t *deveui, const uint8_t *nwkkey, uint8_t *jsintkey, uint8_t *jsenckey) |
Generate LoRaWAN 1.1x lifetime session keys. | |
int | gnrc_lorawan_set_dr (gnrc_lorawan_t *mac, uint8_t datarate) |
Set datarate for the next transmission. | |
size_t | gnrc_lorawan_build_uplink (gnrc_lorawan_t *mac, iolist_t *payload, int confirmed_data, uint8_t port) |
build uplink frame | |
uint8_t | gnrc_lorawan_pick_channel (gnrc_lorawan_t *mac) |
pick a random available LoRaWAN channel | |
uint8_t | gnrc_lorawan_build_options (gnrc_lorawan_t *mac, lorawan_buffer_t *buf) |
Build fopts header. | |
void | gnrc_lorawan_process_fopts (gnrc_lorawan_t *mac, uint8_t *fopts, size_t size) |
Process an fopts frame. | |
void | gnrc_lorawan_calculate_join_req_mic (const uint8_t *buf, size_t len, uint8_t *key, le_uint32_t *out) |
Calculate join-request Message Integrity Code. | |
void | gnrc_lorawan_calculate_join_acpt_mic (const uint8_t *buf, size_t len, gnrc_lorawan_t *mac, le_uint32_t *out) |
Calculate join-accept Message Integrity Code. | |
void | gnrc_lorawan_calculate_mic_uplink (iolist_t *frame, uint16_t conf_fcnt, gnrc_lorawan_t *mac, le_uint32_t *out) |
Calculate Message Integrity Code for an uplink MCPS message. | |
void | gnrc_lorawan_calculate_mic_downlink (const le_uint32_t *dev_addr, uint32_t fcnt, uint16_t conf_fcnt, iolist_t *frame, const uint8_t *snwksintkey, le_uint32_t *out) |
Calculate Message Integrity Code for downlink MCPS message. | |
size_t | gnrc_lorawan_build_hdr (uint8_t mtype, le_uint32_t *dev_addr, uint32_t fcnt, uint8_t ack, uint8_t fopts_length, lorawan_buffer_t *buf) |
Build a MCPS LoRaWAN header. | |
void | gnrc_lorawan_mcps_process_downlink (gnrc_lorawan_t *mac, uint8_t *psdu, size_t size) |
Process an MCPS downlink message (confirmable or non comfirmable) | |
void | gnrc_lorawan_channels_init (gnrc_lorawan_t *mac) |
Init regional channel settings. | |
void | gnrc_lorawan_reset (gnrc_lorawan_t *mac) |
Reset MAC parameters. | |
void | gnrc_lorawan_send_pkt (gnrc_lorawan_t *mac, iolist_t *psdu, uint8_t dr, uint32_t chan) |
Send a LoRaWAN packet. | |
void | gnrc_lorawan_mlme_process_join (gnrc_lorawan_t *mac, uint8_t *data, size_t size) |
Process join accept message. | |
void | gnrc_lorawan_mlme_no_rx (gnrc_lorawan_t *mac) |
Inform the MAC layer that no packet was received during reception. | |
void | gnrc_lorawan_event_no_rx (gnrc_lorawan_t *mac) |
Mac callback for no RX. | |
void | gnrc_lorawan_event_retrans_timeout (gnrc_lorawan_t *mac) |
Mac callback for retransmission timeout event. | |
uint8_t | gnrc_lorawan_region_mac_payload_max (uint8_t datarate) |
Get the maximum MAC payload (M value) for a given datarate. | |
void | gnrc_lorawan_mlme_backoff_expire_cb (gnrc_lorawan_t *mac) |
MLME Backoff expiration tick. | |
void | gnrc_lorawan_process_pkt (gnrc_lorawan_t *mac, iolist_t *pkt) |
Process and dispatch a full LoRaWAN packet. | |
void | gnrc_lorawan_open_rx_window (gnrc_lorawan_t *mac) |
Open a reception window. | |
void | gnrc_lorawan_perform_save (gnrc_lorawan_t *mac) |
save internal MAC state in non-volatile storage and shutdown the MAC layer gracefully. | |
static int | gnrc_lorawan_mac_acquire (gnrc_lorawan_t *mac) |
Acquire the MAC layer. | |
static void | gnrc_lorawan_mac_release (gnrc_lorawan_t *mac) |
Release the MAC layer. | |
void | gnrc_lorawan_set_rx2_dr (gnrc_lorawan_t *mac, uint8_t rx2_dr) |
Set the datarate of the second reception window. | |
void | gnrc_lorawan_trigger_join (gnrc_lorawan_t *mac) |
Trigger the transmission of the Join Request packet. | |
void | gnrc_lorawan_store_dev_nonce (uint8_t *dev_nonce) |
Store DevNonce in flash memory. | |
static bool | gnrc_lorawan_optneg_is_set (const gnrc_lorawan_t *mac) |
Check whether OptNeg bit is set. | |
static void | gnrc_lorawan_set_optneg (gnrc_lorawan_t *mac, uint8_t optneg) |
Set OptNeg bit in the MAC descriptor. | |
static uint8_t * | gnrc_lorawan_get_jsintkey (const gnrc_lorawan_t *mac) |
Get the join session integrity key from the MAC descriptor. | |
static uint8_t * | gnrc_lorawan_get_jsenckey (const gnrc_lorawan_t *mac) |
Get the join session encryption key from the MAC descriptor. | |
static uint32_t | gnrc_lorawan_get_afcnt_down (const gnrc_lorawan_t *mac) |
Get the application downlink frame counter from the MAC descriptor. | |
static void | gnrc_lorawan_set_afcnt_down (gnrc_lorawan_t *mac, uint32_t afcnt_down) |
Set the application downlink frame counter in the MAC descriptor. | |
static uint32_t | gnrc_lorawan_get_last_fcnt_down (const gnrc_lorawan_t *mac) |
Get the last downlink frame counter from the MAC descriptor. | |
static void | gnrc_lorawan_set_last_fcnt_down (gnrc_lorawan_t *mac, uint32_t last_fcnt_down) |
Set the last downlink frame counter in the MAC descriptor. | |
static uint8_t * | gnrc_lorawan_mlme_join_get_appkey (const mlme_lorawan_join_t *mlme_join) |
Get the app key from the MLME join request data. | |
static void | gnrc_lorawan_mlme_join_set_appkey (mlme_lorawan_join_t *mlme_join, uint8_t *key) |
Se the app key in the MLME join request data. | |
#define CFLIST_SIZE (16U) |
Channel Frequency list size in bytes.
Definition at line 53 of file gnrc_lorawan_internal.h.
#define GNCR_LORAWAN_CID_REKEY_CONF (0x0B) |
Reykey Confirmation CID.
Definition at line 79 of file gnrc_lorawan_internal.h.
#define GNCR_LORAWAN_REKEY_IND_SIZE (1U) |
RekeyInd MAC command size.
Definition at line 78 of file gnrc_lorawan_internal.h.
#define GNRC_LORAWAN_APP_NONCE_SIZE (3U) |
App Nonce size.
Definition at line 101 of file gnrc_lorawan_internal.h.
#define GNRC_LORAWAN_BACKOFF_BUDGET_1 (36000000LL) |
budget of time on air during the first hour
Definition at line 68 of file gnrc_lorawan_internal.h.
#define GNRC_LORAWAN_BACKOFF_BUDGET_2 (36000000LL) |
budget of time on air between 1-10 hours after boot
Definition at line 69 of file gnrc_lorawan_internal.h.
#define GNRC_LORAWAN_BACKOFF_BUDGET_3 (8700000LL) |
budget of time on air every 24 hours
Definition at line 70 of file gnrc_lorawan_internal.h.
#define GNRC_LORAWAN_BACKOFF_STATE_1 (0U) |
backoff state during the first hour after boot
Definition at line 93 of file gnrc_lorawan_internal.h.
#define GNRC_LORAWAN_BACKOFF_STATE_2 (1U) |
backoff state between 1-10 hours after boot
Definition at line 94 of file gnrc_lorawan_internal.h.
#define GNRC_LORAWAN_BACKOFF_STATE_3 (2U) |
backoff state past 11 hours after boot
Definition at line 95 of file gnrc_lorawan_internal.h.
#define GNRC_LORAWAN_BACKOFF_TIME_1 (1U) |
duration of first backoff state (in hours)
Definition at line 97 of file gnrc_lorawan_internal.h.
#define GNRC_LORAWAN_BACKOFF_TIME_2 (10U) |
duration of second backoff state (in hours)
Definition at line 98 of file gnrc_lorawan_internal.h.
#define GNRC_LORAWAN_BACKOFF_TIME_3 (24U) |
duration of third backoff state (in hours)
Definition at line 99 of file gnrc_lorawan_internal.h.
#define GNRC_LORAWAN_BACKOFF_WINDOW_TICK (3600000000LL) |
backoff expire tick in usecs (set to 1 second)
Definition at line 66 of file gnrc_lorawan_internal.h.
#define GNRC_LORAWAN_CFLIST_ENTRY_SIZE (3U) |
size of Channel Frequency list
Definition at line 90 of file gnrc_lorawan_internal.h.
#define GNRC_LORAWAN_CID_LINK_CHECK_ANS (0x02) |
Link Check CID.
Definition at line 76 of file gnrc_lorawan_internal.h.
#define GNRC_LORAWAN_CID_SIZE (1U) |
size of Command ID in FOps
Definition at line 75 of file gnrc_lorawan_internal.h.
#define GNRC_LORAWAN_DEV_NONCE_SIZE (2U) |
Dev Nonce size.
Definition at line 104 of file gnrc_lorawan_internal.h.
#define GNRC_LORAWAN_DIR_DOWNLINK (1U) |
downlink frame direction
Definition at line 64 of file gnrc_lorawan_internal.h.
#define GNRC_LORAWAN_DIR_UPLINK (0U) |
uplink frame direction
Definition at line 63 of file gnrc_lorawan_internal.h.
#define GNRC_LORAWAN_FOPT_LINK_CHECK_ANS_SIZE (3U) |
size of Link check answer
Definition at line 81 of file gnrc_lorawan_internal.h.
#define GNRC_LORAWAN_FOPT_REKEY_CONF_SIZE (2U) |
size of Rekey confirmation
Definition at line 82 of file gnrc_lorawan_internal.h.
#define GNRC_LORAWAN_FOPTS_MAX_SIZE (15U) |
Maximum size of Fopts field.
Definition at line 106 of file gnrc_lorawan_internal.h.
#define GNRC_LORAWAN_FPORT_SIZE (1U) |
Size of the Fport field.
Definition at line 107 of file gnrc_lorawan_internal.h.
#define GNRC_LORAWAN_INITIALIZED_MARKER (0x52f94f54U) |
Persistent state initialized marker.
Definition at line 115 of file gnrc_lorawan_internal.h.
#define GNRC_LORAWAN_JOIN_ACCEPT_MAX_SIZE (33U) |
max size of Join Accept frame
Definition at line 91 of file gnrc_lorawan_internal.h.
#define GNRC_LORAWAN_JOIN_DELAY_U32_MASK (0x1FFFFF) |
mask for detecting overflow in frame counter
Definition at line 84 of file gnrc_lorawan_internal.h.
#define GNRC_LORAWAN_JOIN_NONCE_SIZE (3U) |
Join nonce size.
Definition at line 102 of file gnrc_lorawan_internal.h.
#define GNRC_LORAWAN_MAX_CHANNELS (16U) |
Maximum number of channels.
Definition at line 55 of file gnrc_lorawan_internal.h.
#define GNRC_LORAWAN_MAX_PAYLOAD_1 (59U) |
max MAC payload in DR0, DR1 and DR2
Definition at line 86 of file gnrc_lorawan_internal.h.
#define GNRC_LORAWAN_MAX_PAYLOAD_2 (123U) |
max MAC payload in DR3
Definition at line 87 of file gnrc_lorawan_internal.h.
#define GNRC_LORAWAN_MAX_PAYLOAD_3 (250U) |
max MAC payload above DR3
Definition at line 88 of file gnrc_lorawan_internal.h.
#define GNRC_LORAWAN_MLME_OPTS_LINK_CHECK_REQ (1 << 0) |
Internal Link Check request flag.
Definition at line 72 of file gnrc_lorawan_internal.h.
#define GNRC_LORAWAN_MLME_OPTS_REKEY_IND_REQ (1 << 1) |
Internal Rekey Indication flag.
Definition at line 73 of file gnrc_lorawan_internal.h.
#define GNRC_LORAWAN_NET_ID_SIZE (3U) |
Net ID size.
Definition at line 103 of file gnrc_lorawan_internal.h.
#define GNRC_LORAWAN_STATE_FLASHPAGE_NUM (FLASHPAGE_NUMOF - 0x4) |
Flashpage number where to store state.
Definition at line 113 of file gnrc_lorawan_internal.h.
#define JOIN_REQUEST_SIZE (23U) |
Join Request size in bytes.
Definition at line 51 of file gnrc_lorawan_internal.h.
#define LORAWAN_STATE_IDLE (0) |
MAC state machine in idle.
Definition at line 57 of file gnrc_lorawan_internal.h.
#define LORAWAN_STATE_JOIN (4) |
MAC state machine in Join.
Definition at line 61 of file gnrc_lorawan_internal.h.
#define LORAWAN_STATE_RX_1 (1) |
MAC state machine in RX1.
Definition at line 58 of file gnrc_lorawan_internal.h.
#define LORAWAN_STATE_RX_2 (2) |
MAC state machine in RX2.
Definition at line 59 of file gnrc_lorawan_internal.h.
#define LORAWAN_STATE_TX (3) |
MAC state machine in TX.
Definition at line 60 of file gnrc_lorawan_internal.h.
#define MAJOR_LRWAN_R1 0x0 |
LoRaWAN R1 version type.
Definition at line 47 of file gnrc_lorawan_internal.h.
#define MAJOR_MASK 0x3 |
Major mtype mask.
Definition at line 46 of file gnrc_lorawan_internal.h.
#define MHDR_MIC_BUF_SIZE |
Size of the internal MHDR-MIC buffer.
Definition at line 120 of file gnrc_lorawan_internal.h.
#define MIC_SIZE (4U) |
MIC size in bytes.
Definition at line 52 of file gnrc_lorawan_internal.h.
#define MINOR_LRWAN 0x1 |
Minor LoRaWAN version of device.
Definition at line 49 of file gnrc_lorawan_internal.h.
#define MSG_TYPE_TIMEOUT (0x3457) |
Timeout message type.
Definition at line 34 of file gnrc_lorawan_internal.h.
#define MTYPE_CNF_DOWNLINK 0x5 |
Confirmed downlink type.
Definition at line 42 of file gnrc_lorawan_internal.h.
#define MTYPE_CNF_UPLINK 0x4 |
Confirmed uplink type.
Definition at line 41 of file gnrc_lorawan_internal.h.
#define MTYPE_JOIN_ACCEPT 0x1 |
Join Accept type.
Definition at line 38 of file gnrc_lorawan_internal.h.
#define MTYPE_JOIN_REQUEST 0x0 |
Join Request type.
Definition at line 37 of file gnrc_lorawan_internal.h.
#define MTYPE_MASK 0xE0 |
MHDR mtype mask.
Definition at line 36 of file gnrc_lorawan_internal.h.
#define MTYPE_PROPIETARY 0x7 |
Proprietary frame type.
Definition at line 44 of file gnrc_lorawan_internal.h.
#define MTYPE_REJOIN_REQ 0x6 |
Re-join request type.
Definition at line 43 of file gnrc_lorawan_internal.h.
#define MTYPE_UNCNF_DOWNLINK 0x3 |
Unconfirmed downlink type.
Definition at line 40 of file gnrc_lorawan_internal.h.
#define MTYPE_UNCNF_UPLINK 0x2 |
Unconfirmed uplink type.
Definition at line 39 of file gnrc_lorawan_internal.h.
enum mlme_join_req_type_t |
MLME Join Request type.
Enumerator | |
---|---|
REJOIN_REQ_0 | Rejoin-request type 0. |
REJOIN_REQ_1 | Rejoin-request type 1. |
REJOIN_REQ_2 | Rejoin-request type 2. |
JOIN_REQ | Join-request type. |
Definition at line 150 of file gnrc_lorawan_internal.h.
size_t gnrc_lorawan_build_hdr | ( | uint8_t | mtype, |
le_uint32_t * | dev_addr, | ||
uint32_t | fcnt, | ||
uint8_t | ack, | ||
uint8_t | fopts_length, | ||
lorawan_buffer_t * | buf | ||
) |
Build a MCPS LoRaWAN header.
[in] | mtype | the MType of the header |
[in] | dev_addr | the Device Address |
[in] | fcnt | frame counter |
[in] | ack | true if ACK bit is set |
[in] | fopts_length | the length of the FOpts field |
[out] | buf | destination buffer of the hdr |
uint8_t gnrc_lorawan_build_options | ( | gnrc_lorawan_t * | mac, |
lorawan_buffer_t * | buf | ||
) |
Build fopts header.
[in] | mac | pointer to MAC descriptor |
[out] | buf | destination buffer of fopts. If NULL, this function just returns the size of the expected fopts frame. |
size_t gnrc_lorawan_build_uplink | ( | gnrc_lorawan_t * | mac, |
iolist_t * | payload, | ||
int | confirmed_data, | ||
uint8_t | port | ||
) |
build uplink frame
[in] | mac | pointer to MAC descriptor |
[in] | payload | packet containing payload |
[in] | confirmed_data | true if confirmed frame |
[in] | port | MAC port |
payload
is released void gnrc_lorawan_calculate_join_acpt_mic | ( | const uint8_t * | buf, |
size_t | len, | ||
gnrc_lorawan_t * | mac, | ||
le_uint32_t * | out | ||
) |
Calculate join-accept Message Integrity Code.
[in] | buf | pointer to the frame |
[in] | len | length of the frame |
[in] | mac | pointer to MAC descriptor |
[out] | out | calculated MIC |
void gnrc_lorawan_calculate_join_req_mic | ( | const uint8_t * | buf, |
size_t | len, | ||
uint8_t * | key, | ||
le_uint32_t * | out | ||
) |
Calculate join-request Message Integrity Code.
[in] | buf | pointer to the frame |
[in] | len | length of the frame |
[in] | key | key to be used to calculate the MIC |
[out] | out | calculated MIC |
void gnrc_lorawan_calculate_mic_downlink | ( | const le_uint32_t * | dev_addr, |
uint32_t | fcnt, | ||
uint16_t | conf_fcnt, | ||
iolist_t * | frame, | ||
const uint8_t * | snwksintkey, | ||
le_uint32_t * | out | ||
) |
Calculate Message Integrity Code for downlink MCPS message.
[in] | dev_addr | the Device Address |
[in] | fcnt | frame counter |
[in] | conf_fcnt | frame counter value of confirmed uplink frame |
[in] | frame | pointer to the PSDU frame (without MIC) |
[in] | snwksintkey | pointer to serving network session integrity key |
[out] | out | calculated MIC |
void gnrc_lorawan_calculate_mic_uplink | ( | iolist_t * | frame, |
uint16_t | conf_fcnt, | ||
gnrc_lorawan_t * | mac, | ||
le_uint32_t * | out | ||
) |
Calculate Message Integrity Code for an uplink MCPS message.
[in] | frame | pointer to the PSDU frame (without MIC) |
[in] | conf_fcnt | frame counter value of confirmed uplink frame. Always zero if using LoRaWAN 1.0x |
[in] | mac | pointer to MAC descriptor |
[out] | out | calculated MIC |
void gnrc_lorawan_channels_init | ( | gnrc_lorawan_t * | mac | ) |
Init regional channel settings.
Intended to be called upon initialization
[in] | mac | pointer to the MAC descriptor |
void gnrc_lorawan_decrypt_join_accept | ( | const uint8_t * | key, |
uint8_t * | pkt, | ||
int | has_clist, | ||
uint8_t * | out | ||
) |
Decrypts join accept message.
[in] | key | key to be used in the decryption |
[in] | pkt | pointer to Join Accept MAC component (next byte after the MHDR) |
[in] | has_clist | true if the Join Accept frame has CFList |
[out] | out | buffer where the decryption is stored |
void gnrc_lorawan_encrypt_fopts | ( | uint8_t * | fopts, |
size_t | len, | ||
const le_uint32_t * | dev_addr, | ||
uint32_t | fcnt, | ||
bool | afcnt, | ||
uint8_t | dir, | ||
const uint8_t * | key | ||
) |
Encrypts FOpts field.
[in] | fopts | pointer to fopts |
[in] | len | length of fopts |
[in] | dev_addr | device address |
[in] | fcnt | frame counter |
[in] | afcnt | flag indicating if aFCntDown is used |
[in] | dir | direction of the packet (0 if uplink, 1 if downlink) |
[in] | key | pointer to key |
void gnrc_lorawan_encrypt_payload | ( | iolist_t * | iolist, |
const le_uint32_t * | dev_addr, | ||
uint32_t | fcnt, | ||
uint8_t | dir, | ||
const uint8_t * | appskey | ||
) |
Encrypts LoRaWAN payload.
[in] | iolist | pointer to the MSDU frame |
[in] | dev_addr | device address |
[in] | fcnt | frame counter |
[in] | dir | direction of the packet (0 if uplink, 1 if downlink) |
[in] | appskey | pointer to the Application Session Key |
void gnrc_lorawan_event_no_rx | ( | gnrc_lorawan_t * | mac | ) |
Mac callback for no RX.
[in] | mac | pointer to the MAC descriptor |
void gnrc_lorawan_event_retrans_timeout | ( | gnrc_lorawan_t * | mac | ) |
Mac callback for retransmission timeout event.
[in] | mac | pointer to the MAC descriptor |
void gnrc_lorawan_generate_lifetime_session_keys | ( | const uint8_t * | deveui, |
const uint8_t * | nwkkey, | ||
uint8_t * | jsintkey, | ||
uint8_t * | jsenckey | ||
) |
Generate LoRaWAN 1.1x lifetime session keys.
Called in order to derive JSIntKey and JSEncKey.
LoRaWAN specification 1.1 section 6.1.1.4
[in] | deveui | pointer to the join_nonce of the Join Accept message |
[in] | nwkkey | pointer to the Network key |
[out] | jsintkey | pointer to the Join session integrity key |
[out] | jsenckey | pointer to the Join session encryption key |
void gnrc_lorawan_generate_session_keys | ( | const uint8_t * | join_nonce, |
const uint8_t * | dev_nonce, | ||
const uint8_t * | joineui, | ||
gnrc_lorawan_t * | mac | ||
) |
Generate LoRaWAN session keys.
Intended to be called after a successful Join Request in order to generate AppSKey, SNwkSIntKey, FNwkSIntKey and NwkSEncKey
[in] | join_nonce | pointer to the join_nonce of the Join Accept message |
[in] | dev_nonce | pointer to the dev_nonce buffer |
[in] | joineui | pointer to the Join EUI. NULL if LoRaWAN 1.0x |
[in,out] | mac | pointer to the LoRaWAN mac descriptor |
|
inlinestatic |
Get the application downlink frame counter from the MAC descriptor.
This getter function exists to allow if (IS_USED(...)) constructs in the LoRaWAN code in order to increase code coverage.
[in] | mac | pointer to the MAC descriptor |
Definition at line 710 of file gnrc_lorawan_internal.h.
|
inlinestatic |
Get the join session encryption key from the MAC descriptor.
This getter function exists to allow if (IS_USED(...)) constructs in the LoRaWAN code in order to increase code coverage.
[in] | mac | pointer to the MAC descriptor |
Definition at line 691 of file gnrc_lorawan_internal.h.
|
inlinestatic |
Get the join session integrity key from the MAC descriptor.
This getter function exists to allow if (IS_USED(...)) constructs in the LoRaWAN code in order to increase code coverage.
[in] | mac | pointer to the MAC descriptor |
Definition at line 672 of file gnrc_lorawan_internal.h.
|
inlinestatic |
Get the last downlink frame counter from the MAC descriptor.
This getter function exists to allow if (IS_USED(...)) constructs in the LoRaWAN code in order to increase code coverage.
[in] | mac | pointer to the MAC descriptor |
Definition at line 747 of file gnrc_lorawan_internal.h.
|
inlinestatic |
Acquire the MAC layer.
[in] | mac | pointer to the MAC descriptor |
Definition at line 578 of file gnrc_lorawan_internal.h.
|
inlinestatic |
Release the MAC layer.
[in] | mac | pointer to the MAC descriptor |
Definition at line 591 of file gnrc_lorawan_internal.h.
void gnrc_lorawan_mcps_process_downlink | ( | gnrc_lorawan_t * | mac, |
uint8_t * | psdu, | ||
size_t | size | ||
) |
Process an MCPS downlink message (confirmable or non comfirmable)
[in] | mac | pointer to the MAC descriptor |
[in] | psdu | pointer to the downlink PSDU |
[in] | size | size of the PSDU |
void gnrc_lorawan_mlme_backoff_expire_cb | ( | gnrc_lorawan_t * | mac | ) |
MLME Backoff expiration tick.
Must be called once an hour (right after calling @ref gnrc_lorawan_init) in order to maintain the Time On Air budget.
[in] | mac | pointer to the MAC descriptor |
|
inlinestatic |
Get the app key from the MLME join request data.
This getter function exists to allow if (IS_USED(...)) constructs in the LoRaWAN code in order to increase code coverage.
[in] | mlme_join | pointer to the MLME join request data |
Definition at line 784 of file gnrc_lorawan_internal.h.
|
inlinestatic |
Se the app key in the MLME join request data.
This getter function exists to allow if (IS_USED(...)) constructs in the LoRaWAN code in order to increase code coverage.
[in] | mlme_join | pointer to the MLME join request data |
[in] | key | pointer to the app key |
Definition at line 804 of file gnrc_lorawan_internal.h.
void gnrc_lorawan_mlme_no_rx | ( | gnrc_lorawan_t * | mac | ) |
Inform the MAC layer that no packet was received during reception.
To be called when the radio reports "NO RX" after the second reception window
[in] | mac | pointer to the MAC descriptor |
void gnrc_lorawan_mlme_process_join | ( | gnrc_lorawan_t * | mac, |
uint8_t * | data, | ||
size_t | size | ||
) |
Process join accept message.
[in] | mac | pointer to the MAC descriptor |
[in] | data | the Join Accept packet |
[in] | size | size of the Join Accept packet |
void gnrc_lorawan_open_rx_window | ( | gnrc_lorawan_t * | mac | ) |
Open a reception window.
This is called by the MAC layer on timeout event.
[in] | mac | pointer to the MAC descriptor |
|
inlinestatic |
Check whether OptNeg bit is set.
When using LoRaWAN 1.1x the OptNeg bit indicates whether the Network Server implements the LoRaWAN1.0 protocol version (unset) or 1.1 and later (set).
This getter function exists to allow if (IS_USED(...)) constructs in the LoRaWAN code in order to increase code coverage.
[in] | mac | pointer to the MAC descriptor |
Definition at line 631 of file gnrc_lorawan_internal.h.
void gnrc_lorawan_perform_save | ( | gnrc_lorawan_t * | mac | ) |
save internal MAC state in non-volatile storage and shutdown the MAC layer gracefully.
mac |
uint8_t gnrc_lorawan_pick_channel | ( | gnrc_lorawan_t * | mac | ) |
pick a random available LoRaWAN channel
[in] | mac | pointer to the MAC descriptor |
void gnrc_lorawan_process_fopts | ( | gnrc_lorawan_t * | mac, |
uint8_t * | fopts, | ||
size_t | size | ||
) |
Process an fopts frame.
[in] | mac | pointer to MAC descriptor |
[in] | fopts | pointer to fopts frame |
[in] | size | size of fopts frame |
void gnrc_lorawan_process_pkt | ( | gnrc_lorawan_t * | mac, |
iolist_t * | pkt | ||
) |
Process and dispatch a full LoRaWAN packet.
Intended to be called right after reception from the radio
[in] | mac | pointer to the MAC descriptor |
[in] | pkt | the received packet |
uint8_t gnrc_lorawan_region_mac_payload_max | ( | uint8_t | datarate | ) |
Get the maximum MAC payload (M value) for a given datarate.
[in] | datarate | datarate |
void gnrc_lorawan_reset | ( | gnrc_lorawan_t * | mac | ) |
Reset MAC parameters.
[in] | mac | pointer to the MAC layer |
void gnrc_lorawan_send_pkt | ( | gnrc_lorawan_t * | mac, |
iolist_t * | psdu, | ||
uint8_t | dr, | ||
uint32_t | chan | ||
) |
Send a LoRaWAN packet.
[in] | mac | pointer to the MAC descriptor |
[in] | psdu | the psdu frame to be sent |
[in] | dr | the datarate used for the transmission |
[in] | chan | the channel used for transmission |
|
inlinestatic |
Set the application downlink frame counter in the MAC descriptor.
This getter function exists to allow if (IS_USED(...)) constructs in the LoRaWAN code in order to increase code coverage.
[in] | mac | pointer to the MAC descriptor |
[in] | afcnt_down | application downlink frame counter |
Definition at line 729 of file gnrc_lorawan_internal.h.
int gnrc_lorawan_set_dr | ( | gnrc_lorawan_t * | mac, |
uint8_t | datarate | ||
) |
Set datarate for the next transmission.
[in] | mac | pointer to the MAC descriptor |
[in] | datarate | desired datarate |
|
inlinestatic |
Set the last downlink frame counter in the MAC descriptor.
This getter function exists to allow if (IS_USED(...)) constructs in the LoRaWAN code in order to increase code coverage.
[in] | mac | pointer to the MAC descriptor |
[in] | last_fcnt_down | last downlink frame counter |
Definition at line 766 of file gnrc_lorawan_internal.h.
|
inlinestatic |
Set OptNeg bit in the MAC descriptor.
When using LoRaWAN 1.1x the OptNeg bit indicates whether the Network Server implements the LoRaWAN1.0 protocol version (unset) or 1.1 and later (set).
This setter function exists to allow if (IS_USED(...)) constructs in the LoRaWAN code in order to increase code coverage.
[in] | mac | pointer to the MAC descriptor |
[in] | optneg | OptNeg bit |
Definition at line 653 of file gnrc_lorawan_internal.h.
void gnrc_lorawan_set_rx2_dr | ( | gnrc_lorawan_t * | mac, |
uint8_t | rx2_dr | ||
) |
Set the datarate of the second reception window.
[in] | mac | pointer to the MAC descriptor |
[in] | rx2_dr | datarate of RX2 |
void gnrc_lorawan_store_dev_nonce | ( | uint8_t * | dev_nonce | ) |
Store DevNonce in flash memory.
[in] | dev_nonce | pointer to the DevNonce |
void gnrc_lorawan_trigger_join | ( | gnrc_lorawan_t * | mac | ) |
Trigger the transmission of the Join Request packet.
[in] | mac | pointer to the MAC descriptor |