Go to the documentation of this file.
18 #ifndef GNRC_LORAWAN_INTERNAL_H
19 #define GNRC_LORAWAN_INTERNAL_H
37 #define MSG_TYPE_TIMEOUT (0x3457)
38 #define MSG_TYPE_MCPS_ACK_TIMEOUT (0x3458)
39 #define MSG_TYPE_MLME_BACKOFF_EXPIRE (0x3459)
41 #define MTYPE_MASK 0xE0
42 #define MTYPE_JOIN_REQUEST 0x0
43 #define MTYPE_JOIN_ACCEPT 0x1
44 #define MTYPE_UNCNF_UPLINK 0x2
45 #define MTYPE_UNCNF_DOWNLINK 0x3
46 #define MTYPE_CNF_UPLINK 0x4
47 #define MTYPE_CNF_DOWNLINK 0x5
48 #define MTYPE_REJOIN_REQ 0x6
49 #define MTYPE_PROPIETARY 0x7
51 #define MAJOR_MASK 0x3
52 #define MAJOR_LRWAN_R1 0x0
54 #define JOIN_REQUEST_SIZE (23U)
56 #define CFLIST_SIZE (16U)
58 #define GNRC_LORAWAN_MAX_CHANNELS (16U)
60 #define LORAWAN_STATE_IDLE (0)
61 #define LORAWAN_STATE_RX_1 (1)
62 #define LORAWAN_STATE_RX_2 (2)
63 #define LORAWAN_STATE_TX (3)
65 #define GNRC_LORAWAN_DIR_UPLINK (0U)
66 #define GNRC_LORAWAN_DIR_DOWNLINK (1U)
68 #define GNRC_LORAWAN_BACKOFF_WINDOW_TICK (3600000000LL)
70 #define GNRC_LORAWAN_BACKOFF_BUDGET_1 (36000000LL)
71 #define GNRC_LORAWAN_BACKOFF_BUDGET_2 (36000000LL)
72 #define GNRC_LORAWAN_BACKOFF_BUDGET_3 (8700000LL)
74 #define GNRC_LORAWAN_MLME_OPTS_LINK_CHECK_REQ (1 << 0)
76 #define GNRC_LORAWAN_CID_SIZE (1U)
77 #define GNRC_LORAWAN_CID_LINK_CHECK_ANS (0x02)
79 #define GNRC_LORAWAN_FOPT_LINK_CHECK_ANS_SIZE (3U)
81 #define GNRC_LORAWAN_JOIN_DELAY_U32_MASK (0x1FFFFF)
83 #define GNRC_LORAWAN_MAX_PAYLOAD_1 (59U)
84 #define GNRC_LORAWAN_MAX_PAYLOAD_2 (123U)
85 #define GNRC_LORAWAN_MAX_PAYLOAD_3 (250U)
87 #define GNRC_LORAWAN_CFLIST_ENTRY_SIZE (3U)
88 #define GNRC_LORAWAN_JOIN_ACCEPT_MAX_SIZE (33U)
90 #define GNRC_LORAWAN_BACKOFF_STATE_1 (0U)
91 #define GNRC_LORAWAN_BACKOFF_STATE_2 (1U)
92 #define GNRC_LORAWAN_BACKOFF_STATE_3 (2U)
94 #define GNRC_LORAWAN_BACKOFF_TIME_1 (1U)
95 #define GNRC_LORAWAN_BACKOFF_TIME_2 (10U)
96 #define GNRC_LORAWAN_BACKOFF_TIME_3 (24U)
98 #define GNRC_LORAWAN_APP_NONCE_SIZE (3U)
99 #define GNRC_LORAWAN_NET_ID_SIZE (3U)
100 #define GNRC_LORAWAN_DEV_NONCE_SIZE (2U)
102 #define GNRC_LORAWAN_FOPTS_MAX_SIZE (15U)
103 #define GNRC_LORAWAN_FPORT_SIZE (1U)
108 #define MHDR_MIC_BUF_SIZE (sizeof(lorawan_hdr_t) + \
109 GNRC_LORAWAN_FOPTS_MAX_SIZE + \
110 GNRC_LORAWAN_FPORT_SIZE + \
172 uint8_t dev_nonce[2];
211 uint32_t fcnt, uint8_t dir,
212 const uint8_t *appskey);
223 int has_clist, uint8_t *out);
238 const uint8_t *dev_nonce,
239 const uint8_t *appkey, uint8_t *nwkskey,
265 int confirmed_data, uint8_t port);
334 uint32_t fcnt, uint8_t ack, uint8_t fopts_length,
uint32_t fcnt_down
downlink frame counter
msg_t msg
MAC layer message descriptor.
A 32 bit integer in little endian.
void gnrc_lorawan_send_pkt(gnrc_lorawan_t *mac, iolist_t *psdu, uint8_t dr)
Send a LoRaWAN packet.
iolist_t * pkt
packet of the request
void gnrc_lorawan_mlme_backoff_expire(gnrc_lorawan_t *mac)
MLME Backoff expiration tick.
void * deveui
pointer to the Device EUI
int32_t backoff_budget
remaining Time On Air budget
void * appeui
pointer to the Application EUI
uint32_t fcnt
uplink framecounter
uint8_t rx_delay
Delay of first reception window.
void gnrc_lorawan_event_ack_timeout(gnrc_lorawan_t *mac)
Mac callback for ACK timeout event.
uint8_t size
size of the buffer
LoRaMAC header definitions.
GNRC LoRaWAN mac descriptor.
uint8_t num_gateways
number of gateways
int waiting_for_ack
true if the MAC layer is waiting for an ACK
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_channels_init(gnrc_lorawan_t *mac)
Init regional channel settings.
Netdev layer helper functions.
void gnrc_lorawan_calculate_mic(const le_uint32_t *dev_addr, uint32_t fcnt, uint8_t dir, iolist_t *frame, const uint8_t *nwkskey, le_uint32_t *out)
Calculate Message Integrity Code for a MCPS message.
uint8_t margin
demodulation margin (in dB)
uint8_t * nwkskey
pointer to Network SKey buffer
gnrc_lorawan_mlme_t mlme
MLME descriptor.
void * appkey
pointer to the Application Key
Messaging API for inter process communication.
uint8_t last_dr
datarate of the last transmission
xtimer_t backoff_timer
timer used for backoff expiration
gnrc_lorawan_mcps_t mcps
MCPS descriptor.
void * mlme_buf
pointer to MLME buffer
iolist scatter / gather IO
uint8_t gnrc_lorawan_region_mac_payload_max(uint8_t datarate)
Get the maximum MAC payload (M value) for a given datarate.
int shutdown_req
MAC Shutdown request.
void gnrc_lorawan_perform_save(gnrc_lorawan_t *mac)
save internal MAC state in non-volatile storage and shutdown the MAC layer gracefully.
void gnrc_lorawan_process_fopts(gnrc_lorawan_t *mac, uint8_t *fopts, size_t size)
Process an fopts frame.
static int gnrc_lorawan_mac_acquire(gnrc_lorawan_t *mac)
Acquire the MAC layer.
uint8_t backoff_state
state in the backoff state machine
uint8_t gnrc_lorawan_build_options(gnrc_lorawan_t *mac, lorawan_buffer_t *buf)
Build fopts header.
void gnrc_lorawan_calculate_join_mic(const uint8_t *buf, size_t len, const uint8_t *key, le_uint32_t *out)
calculate join Message Integrity Code
uint8_t port
port of the request
int nb_trials
holds the remaining number of retransmissions
void gnrc_lorawan_process_pkt(gnrc_lorawan_t *mac, iolist_t *pkt)
Process and dispatch a full LoRaWAN packet.
Definitions low-level network driver interface.
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)
static void gnrc_lorawan_mac_release(gnrc_lorawan_t *mac)
Release the MAC layer.
le_uint32_t dev_addr
Device address.
msg_t backoff_msg
msg for backoff expiration
uint32_t gnrc_lorawan_pick_channel(gnrc_lorawan_t *mac)
pick a random available LoRaWAN channel
MCPS service access point descriptor.
iolist structure definition
buffer helper for parsing and constructing LoRaWAN packets.
int state
state of MAC layer
void * mcps_buf
pointer to MCPS buffer
uint8_t index
current inxed in the buffer
void gnrc_lorawan_event_no_rx(gnrc_lorawan_t *mac)
Mac callback for no RX.
void gnrc_lorawan_mlme_no_rx(gnrc_lorawan_t *mac)
Inform the MAC layer that no packet was received during reception.
uint8_t * appskey
pointer to Application SKey buffer
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.
Interface definition for the global network buffer. Network devices and layers can allocate space for...
#define MHDR_MIC_BUF_SIZE
Size of the internal MHDR-MIC buffer.
void gnrc_lorawan_mlme_process_join(gnrc_lorawan_t *mac, uint8_t *data, size_t size)
Process join accept message.
MLME service access point descriptor.
uint8_t dr
datarate for the Join Request
uint8_t * data
pointer to the beginning of the buffer holding data
void gnrc_lorawan_open_rx_window(gnrc_lorawan_t *mac)
Open a reception window.
uint32_t toa
Time on Air of the last transmission.
size_t gnrc_lorawan_build_uplink(gnrc_lorawan_t *mac, iolist_t *payload, int confirmed_data, uint8_t port)
build uplink frame
Describes a message object which can be sent between threads.
#define GNRC_LORAWAN_MAX_CHANNELS
Maximum number of channels.
void gnrc_lorawan_reset(gnrc_lorawan_t *mac)
Reset MAC parameters.
LoRaWAN header type and helper function definitions.
int ack_requested
whether the network server requested an ACK
uint8_t dr
datarate of the request
int gnrc_lorawan_set_dr(gnrc_lorawan_t *mac, uint8_t datarate)
Set datarate for the next transmission.
uint32_t nid
current Network ID
uint8_t dl_settings
downlink settings
void gnrc_lorawan_generate_session_keys(const uint8_t *app_nonce, const uint8_t *dev_nonce, const uint8_t *appkey, uint8_t *nwkskey, uint8_t *appskey)
Generate LoRaWAN session keys.
int pending_mlme_opts
holds pending mlme opts
void gnrc_lorawan_set_rx2_dr(gnrc_lorawan_t *mac, uint8_t rx2_dr)
Set the datarate of the second reception window.
xtimer interface definitions
iolist_t * msdu
current MSDU
MLME Link Check confirmation data.
void gnrc_lorawan_decrypt_join_accept(const uint8_t *key, uint8_t *pkt, int has_clist, uint8_t *out)
Decrypts join accept message.
LoRa modulation header definitions.
uint8_t activation
Activation mechanism of the MAC layer.