hdr.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016 FundaciĆ³n Inria Chile
3  * Copyright (C) 2019 HAW Hamburg
4  *
5  * This file is subject to the terms and conditions of the GNU Lesser
6  * General Public License v2.1. See the file LICENSE in the top level
7  * directory for more details.
8  */
9 
22 #ifndef NET_LORAWAN_HDR_H
23 #define NET_LORAWAN_HDR_H
24 
25 #include <stdio.h>
26 #include <stdint.h>
27 #include <stdbool.h>
28 
29 #include "byteorder.h"
30 #include "net/loramac.h"
31 
32 #define LORAWAN_HDR_MTYPE_MASK (0xe0)
33 #define LORAWAN_HDR_MTYPE_POS (5U)
34 #define LORAWAN_HDR_MAJOR_MASK (0x03)
35 #define LORAWAN_HDR_MAJOR_POS (0U)
36 #define LORAWAN_HDR_ADR_MASK (0x80)
37 #define LORAWAN_HDR_ADR_POS (7U)
38 #define LORAWAN_HDR_ADR_ACK_MASK (0x40)
39 #define LORAWAN_HDR_ADR_ACK_POS (6U)
40 #define LORAWAN_HDR_ACK_MASK (0x20)
41 #define LORAWAN_HDR_ACK_POS (5U)
42 #define LORAWAN_HDR_FRAME_PENDING_MASK (0x10)
43 #define LORAWAN_HDR_FRAME_PENDING_POS (4U)
44 #define LORAWAN_HDR_FOPTS_LEN_MASK (0x0F)
45 #define LORAWAN_HDR_FOPTS_LEN_POS (0U)
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50 
71 typedef struct __attribute__((packed)) {
84  uint8_t mt_maj;
86  uint8_t fctrl;
89 
93 typedef struct __attribute__((packed)) {
94  uint8_t mt_maj;
100 
104 typedef struct __attribute__((packed)) {
105  uint8_t mt_maj;
106  uint8_t app_nonce[LORAMAC_APP_NONCE_LEN];
107  uint8_t net_id[LORAMAC_NETWORK_ID_LEN];
108  uint8_t dev_addr[LORAMAC_DEVADDR_LEN];
109  uint8_t dl_settings;
110  uint8_t rx_delay;
112 
119 static inline void lorawan_hdr_set_mtype(lorawan_hdr_t *hdr, uint8_t mtype)
120 {
123 }
124 
132 static inline uint8_t lorawan_hdr_get_mtype(lorawan_hdr_t *hdr)
133 {
135 }
136 
143 static inline void lorawan_hdr_set_maj(lorawan_hdr_t *hdr, uint8_t maj)
144 {
147 }
148 
156 static inline uint8_t lorawan_hdr_get_maj(lorawan_hdr_t *hdr)
157 {
159 }
160 
167 static inline void lorawan_hdr_set_adr(lorawan_hdr_t *hdr, bool adr)
168 {
169  hdr->fctrl &= ~LORAWAN_HDR_ADR_MASK;
171 }
172 
180 static inline bool lorawan_hdr_get_adr(lorawan_hdr_t *hdr)
181 {
183 }
184 
191 static inline void lorawan_hdr_set_adr_ack_req(lorawan_hdr_t *hdr, bool adr_ack_req)
192 {
194  hdr->fctrl |= (adr_ack_req << LORAWAN_HDR_ADR_ACK_POS) & LORAWAN_HDR_ADR_ACK_MASK;
195 }
196 
205 {
207 }
208 
215 static inline void lorawan_hdr_set_ack(lorawan_hdr_t *hdr, bool ack)
216 {
217  hdr->fctrl &= ~LORAWAN_HDR_ACK_MASK;
219 }
220 
228 static inline bool lorawan_hdr_get_ack(lorawan_hdr_t *hdr)
229 {
231 }
232 
239 static inline void lorawan_hdr_set_frame_pending(lorawan_hdr_t *hdr, bool frame_pending)
240 {
243 }
244 
253 {
255 }
256 
263 static inline void lorawan_hdr_set_frame_opts_len(lorawan_hdr_t *hdr, uint8_t len)
264 {
267 }
268 
277 {
279 }
280 
281 #ifdef __cplusplus
282 }
283 #endif
284 
285 #endif /* NET_LORAWAN_HDR_H */
286 
le_uint32_t
A 32 bit integer in little endian.
Definition: byteorder.h:51
LORAMAC_DEVADDR_LEN
#define LORAMAC_DEVADDR_LEN
Device address length in bytes.
Definition: loramac.h:310
lorawan_join_request_t::dev_eui
le_uint64_t dev_eui
device EUI
Definition: hdr.h:96
lorawan_hdr_set_frame_pending
static void lorawan_hdr_set_frame_pending(lorawan_hdr_t *hdr, bool frame_pending)
Set LoRaWAN header frame pending bit.
Definition: hdr.h:239
LORAWAN_HDR_ACK_MASK
#define LORAWAN_HDR_ACK_MASK
ACK bit mask.
Definition: hdr.h:40
lorawan_join_request_t::dev_nonce
le_uint16_t dev_nonce
device nonce
Definition: hdr.h:97
le_uint16_t
A 16 bit integer in little endian.
Definition: byteorder.h:41
LORAWAN_HDR_ADR_POS
#define LORAWAN_HDR_ADR_POS
ADR position.
Definition: hdr.h:37
byteorder.h
Functions to work with different byte orders.
lorawan_hdr_t::fctrl
uint8_t fctrl
frame control
Definition: hdr.h:86
lorawan_join_request_t::mic
le_uint32_t mic
message integrity code
Definition: hdr.h:98
loramac.h
LoRaMAC header definitions.
lorawan_join_request_t
Join request packet representation.
Definition: hdr.h:93
lorawan_join_request_t::mt_maj
uint8_t mt_maj
mtype and major version holder
Definition: hdr.h:94
LORAWAN_HDR_MAJOR_MASK
#define LORAWAN_HDR_MAJOR_MASK
Major version mask.
Definition: hdr.h:34
LORAWAN_HDR_ADR_MASK
#define LORAWAN_HDR_ADR_MASK
ADR mask.
Definition: hdr.h:36
LORAMAC_APP_NONCE_LEN
#define LORAMAC_APP_NONCE_LEN
Application Nonce length in bytes.
Definition: loramac.h:345
lorawan_hdr_get_adr_ack_req
static bool lorawan_hdr_get_adr_ack_req(lorawan_hdr_t *hdr)
Get LoRaWAN header ADR ACK request bit.
Definition: hdr.h:204
lorawan_hdr_t::mt_maj
uint8_t mt_maj
message type and major version
Definition: hdr.h:84
LORAWAN_HDR_FOPTS_LEN_POS
#define LORAWAN_HDR_FOPTS_LEN_POS
Frame options position.
Definition: hdr.h:45
lorawan_hdr_get_frame_opts_len
static uint8_t lorawan_hdr_get_frame_opts_len(lorawan_hdr_t *hdr)
Get LoRaWAN header FOps length.
Definition: hdr.h:276
lorawan_hdr_get_frame_pending
static bool lorawan_hdr_get_frame_pending(lorawan_hdr_t *hdr)
Get LoRaWAN header frame pending bit.
Definition: hdr.h:252
lorawan_hdr_get_adr
static bool lorawan_hdr_get_adr(lorawan_hdr_t *hdr)
Get LoRaWAN header Adaptive Data Rate bit.
Definition: hdr.h:180
lorawan_join_accept_t
Join accept packet representation.
Definition: hdr.h:104
lorawan_join_request_t::app_eui
le_uint64_t app_eui
application EUI
Definition: hdr.h:95
lorawan_hdr_t
Data type to represent a LoRaWAN packet header.
Definition: hdr.h:71
LORAWAN_HDR_ADR_ACK_MASK
#define LORAWAN_HDR_ADR_ACK_MASK
ADR ACK bit mask.
Definition: hdr.h:38
lorawan_hdr_set_ack
static void lorawan_hdr_set_ack(lorawan_hdr_t *hdr, bool ack)
Set LoRaWAN header ACK bit.
Definition: hdr.h:215
LORAWAN_HDR_FRAME_PENDING_MASK
#define LORAWAN_HDR_FRAME_PENDING_MASK
Frame pending bit mask.
Definition: hdr.h:42
lorawan_hdr_t::fcnt
le_uint16_t fcnt
frame counter
Definition: hdr.h:87
LORAWAN_HDR_FRAME_PENDING_POS
#define LORAWAN_HDR_FRAME_PENDING_POS
Frame pending bit position.
Definition: hdr.h:43
LORAWAN_HDR_MTYPE_POS
#define LORAWAN_HDR_MTYPE_POS
MType position.
Definition: hdr.h:33
LORAWAN_HDR_MTYPE_MASK
#define LORAWAN_HDR_MTYPE_MASK
MType mask.
Definition: hdr.h:32
lorawan_hdr_t::addr
le_uint32_t addr
32 bit LoRaWAN address
Definition: hdr.h:85
LORAWAN_HDR_ADR_ACK_POS
#define LORAWAN_HDR_ADR_ACK_POS
ADR ACK bit position.
Definition: hdr.h:39
lorawan_join_accept_t::mt_maj
uint8_t mt_maj
mtype and major version holder
Definition: hdr.h:105
LORAWAN_HDR_ACK_POS
#define LORAWAN_HDR_ACK_POS
ACK bit position.
Definition: hdr.h:41
LORAMAC_NETWORK_ID_LEN
#define LORAMAC_NETWORK_ID_LEN
Network ID length in bytes.
Definition: loramac.h:350
LORAWAN_HDR_MAJOR_POS
#define LORAWAN_HDR_MAJOR_POS
Major version position.
Definition: hdr.h:35
lorawan_hdr_set_adr
static void lorawan_hdr_set_adr(lorawan_hdr_t *hdr, bool adr)
Set LoRaWAN header Adaptive Data Rate bit.
Definition: hdr.h:167
lorawan_hdr_get_ack
static bool lorawan_hdr_get_ack(lorawan_hdr_t *hdr)
Get LoRaWAN header ACK bit.
Definition: hdr.h:228
lorawan_join_accept_t::dl_settings
uint8_t dl_settings
downlink settings
Definition: hdr.h:109
le_uint64_t
A 64 bit integer in little endian.
Definition: byteorder.h:63
lorawan_join_accept_t::rx_delay
uint8_t rx_delay
first reception window delay
Definition: hdr.h:110
lorawan_hdr_set_maj
static void lorawan_hdr_set_maj(lorawan_hdr_t *hdr, uint8_t maj)
Set LoRaWAN major version.
Definition: hdr.h:143
lorawan_hdr_set_adr_ack_req
static void lorawan_hdr_set_adr_ack_req(lorawan_hdr_t *hdr, bool adr_ack_req)
Set LoRaWAN header ADR ACK request bit.
Definition: hdr.h:191
lorawan_hdr_set_frame_opts_len
static void lorawan_hdr_set_frame_opts_len(lorawan_hdr_t *hdr, uint8_t len)
Set LoRaWAN header FOpts length.
Definition: hdr.h:263
LORAWAN_HDR_FOPTS_LEN_MASK
#define LORAWAN_HDR_FOPTS_LEN_MASK
Frame options mask.
Definition: hdr.h:44
lorawan_hdr_get_mtype
static uint8_t lorawan_hdr_get_mtype(lorawan_hdr_t *hdr)
Get LoRaWAN header MType.
Definition: hdr.h:132
lorawan_hdr_get_maj
static uint8_t lorawan_hdr_get_maj(lorawan_hdr_t *hdr)
Get LoRaWAN major version.
Definition: hdr.h:156
lorawan_hdr_set_mtype
static void lorawan_hdr_set_mtype(lorawan_hdr_t *hdr, uint8_t mtype)
Set LoRaWAN header MType.
Definition: hdr.h:119