hdr.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2016 Fundación Inria Chile
3  * SPDX-FileCopyrightText: 2019 HAW Hamburg
4  * SPDX-License-Identifier: LGPL-2.1-only
5  */
6 
7 #pragma once
8 
21 #include <stdio.h>
22 #include <stdint.h>
23 #include <stdbool.h>
24 
25 #include "byteorder.h"
26 #include "net/loramac.h"
27 
28 #define LORAWAN_HDR_MTYPE_MASK (0xe0)
29 #define LORAWAN_HDR_MTYPE_POS (5U)
30 #define LORAWAN_HDR_MAJOR_MASK (0x03)
31 #define LORAWAN_HDR_MAJOR_POS (0U)
32 #define LORAWAN_HDR_ADR_MASK (0x80)
33 #define LORAWAN_HDR_ADR_POS (7U)
34 #define LORAWAN_HDR_ADR_ACK_MASK (0x40)
35 #define LORAWAN_HDR_ADR_ACK_POS (6U)
36 #define LORAWAN_HDR_ACK_MASK (0x20)
37 #define LORAWAN_HDR_ACK_POS (5U)
38 #define LORAWAN_HDR_FRAME_PENDING_MASK (0x10)
39 #define LORAWAN_HDR_FRAME_PENDING_POS (4U)
40 #define LORAWAN_HDR_FOPTS_LEN_MASK (0x0F)
41 #define LORAWAN_HDR_FOPTS_LEN_POS (0U)
43 #define LORAWAN_JA_HDR_OPTNEG_MASK (0x80)
44 #define LORAWAN_JA_HDR_OPTNEG_POS (7U)
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49 
70 typedef struct __attribute__((packed)) {
83  uint8_t mt_maj;
85  uint8_t fctrl;
88 
92 typedef struct __attribute__((packed)) {
93  uint8_t mt_maj;
99 
103 typedef struct __attribute__((packed)) {
104  uint8_t mt_maj;
105  uint8_t join_nonce[LORAMAC_JOIN_NONCE_LEN];
106  uint8_t net_id[LORAMAC_NETWORK_ID_LEN];
107  uint8_t dev_addr[LORAMAC_DEVADDR_LEN];
108  uint8_t dl_settings;
109  uint8_t rx_delay;
111 
118 static inline void lorawan_hdr_set_mtype(lorawan_hdr_t *hdr, uint8_t mtype)
119 {
122 }
123 
131 static inline uint8_t lorawan_hdr_get_mtype(lorawan_hdr_t *hdr)
132 {
134 }
135 
142 static inline void lorawan_hdr_set_maj(lorawan_hdr_t *hdr, uint8_t maj)
143 {
146 }
147 
155 static inline uint8_t lorawan_hdr_get_maj(lorawan_hdr_t *hdr)
156 {
158 }
159 
166 static inline void lorawan_hdr_set_adr(lorawan_hdr_t *hdr, bool adr)
167 {
168  hdr->fctrl &= ~LORAWAN_HDR_ADR_MASK;
170 }
171 
179 static inline bool lorawan_hdr_get_adr(lorawan_hdr_t *hdr)
180 {
182 }
183 
190 static inline void lorawan_hdr_set_adr_ack_req(lorawan_hdr_t *hdr, bool adr_ack_req)
191 {
193  hdr->fctrl |= (adr_ack_req << LORAWAN_HDR_ADR_ACK_POS) & LORAWAN_HDR_ADR_ACK_MASK;
194 }
195 
204 {
206 }
207 
214 static inline void lorawan_hdr_set_ack(lorawan_hdr_t *hdr, bool ack)
215 {
216  hdr->fctrl &= ~LORAWAN_HDR_ACK_MASK;
218 }
219 
227 static inline bool lorawan_hdr_get_ack(lorawan_hdr_t *hdr)
228 {
230 }
231 
238 static inline void lorawan_hdr_set_frame_pending(lorawan_hdr_t *hdr, bool frame_pending)
239 {
242 }
243 
252 {
254 }
255 
262 static inline void lorawan_hdr_set_frame_opts_len(lorawan_hdr_t *hdr, uint8_t len)
263 {
266 }
267 
276 {
278 }
279 
288 {
290 }
291 
292 #ifdef __cplusplus
293 }
294 #endif
295 
Functions to work with different byte orders.
#define LORAMAC_DEVADDR_LEN
Device address length in bytes.
Definition: loramac.h:551
#define LORAMAC_JOIN_NONCE_LEN
Join nonce length in bytes.
Definition: loramac.h:631
#define LORAMAC_NETWORK_ID_LEN
Network ID length in bytes.
Definition: loramac.h:636
#define LORAWAN_HDR_MAJOR_POS
Major version position.
Definition: hdr.h:31
#define LORAWAN_HDR_FRAME_PENDING_POS
Frame pending bit position.
Definition: hdr.h:39
static void lorawan_hdr_set_ack(lorawan_hdr_t *hdr, bool ack)
Set LoRaWAN header ACK bit.
Definition: hdr.h:214
static void lorawan_hdr_set_frame_pending(lorawan_hdr_t *hdr, bool frame_pending)
Set LoRaWAN header frame pending bit.
Definition: hdr.h:238
static uint8_t lorawan_hdr_get_mtype(lorawan_hdr_t *hdr)
Get LoRaWAN header MType.
Definition: hdr.h:131
#define LORAWAN_HDR_ADR_MASK
ADR mask.
Definition: hdr.h:32
#define LORAWAN_HDR_ADR_ACK_POS
ADR ACK bit position.
Definition: hdr.h:35
static uint8_t lorawan_hdr_get_maj(lorawan_hdr_t *hdr)
Get LoRaWAN major version.
Definition: hdr.h:155
static bool lorawan_hdr_get_adr(lorawan_hdr_t *hdr)
Get LoRaWAN header Adaptive Data Rate bit.
Definition: hdr.h:179
static bool lorawan_ja_hdr_get_optneg(lorawan_join_accept_t *ja_hdr)
Get LoRaWAN join accept message OptNeg bit.
Definition: hdr.h:287
#define LORAWAN_HDR_ADR_ACK_MASK
ADR ACK bit mask.
Definition: hdr.h:34
#define LORAWAN_JA_HDR_OPTNEG_MASK
OptNeg bit mask.
Definition: hdr.h:43
static void lorawan_hdr_set_maj(lorawan_hdr_t *hdr, uint8_t maj)
Set LoRaWAN major version.
Definition: hdr.h:142
#define LORAWAN_HDR_FOPTS_LEN_POS
Frame options position.
Definition: hdr.h:41
#define LORAWAN_JA_HDR_OPTNEG_POS
OptNeg bit position.
Definition: hdr.h:44
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:190
#define LORAWAN_HDR_ADR_POS
ADR position.
Definition: hdr.h:33
static bool lorawan_hdr_get_frame_pending(lorawan_hdr_t *hdr)
Get LoRaWAN header frame pending bit.
Definition: hdr.h:251
#define LORAWAN_HDR_MTYPE_MASK
MType mask.
Definition: hdr.h:28
#define LORAWAN_HDR_ACK_POS
ACK bit position.
Definition: hdr.h:37
#define LORAWAN_HDR_ACK_MASK
ACK bit mask.
Definition: hdr.h:36
#define LORAWAN_HDR_FRAME_PENDING_MASK
Frame pending bit mask.
Definition: hdr.h:38
static bool lorawan_hdr_get_ack(lorawan_hdr_t *hdr)
Get LoRaWAN header ACK bit.
Definition: hdr.h:227
#define LORAWAN_HDR_MAJOR_MASK
Major version mask.
Definition: hdr.h:30
#define LORAWAN_HDR_MTYPE_POS
MType position.
Definition: hdr.h:29
static bool lorawan_hdr_get_adr_ack_req(lorawan_hdr_t *hdr)
Get LoRaWAN header ADR ACK request bit.
Definition: hdr.h:203
static void lorawan_hdr_set_adr(lorawan_hdr_t *hdr, bool adr)
Set LoRaWAN header Adaptive Data Rate bit.
Definition: hdr.h:166
#define LORAWAN_HDR_FOPTS_LEN_MASK
Frame options mask.
Definition: hdr.h:40
static void lorawan_hdr_set_frame_opts_len(lorawan_hdr_t *hdr, uint8_t len)
Set LoRaWAN header FOpts length.
Definition: hdr.h:262
static void lorawan_hdr_set_mtype(lorawan_hdr_t *hdr, uint8_t mtype)
Set LoRaWAN header MType.
Definition: hdr.h:118
static uint8_t lorawan_hdr_get_frame_opts_len(lorawan_hdr_t *hdr)
Get LoRaWAN header FOps length.
Definition: hdr.h:275
LoRaMAC header definitions.
Data type to represent a LoRaWAN packet header.
Definition: hdr.h:70
le_uint16_t fcnt
frame counter
Definition: hdr.h:86
uint8_t mt_maj
message type and major version
Definition: hdr.h:83
uint8_t fctrl
frame control
Definition: hdr.h:85
le_uint32_t addr
32 bit LoRaWAN address
Definition: hdr.h:84
Join accept packet representation.
Definition: hdr.h:103
uint8_t rx_delay
first reception window delay
Definition: hdr.h:109
uint8_t mt_maj
mtype and major version holder
Definition: hdr.h:104
uint8_t dl_settings
downlink settings
Definition: hdr.h:108
Join request packet representation.
Definition: hdr.h:92
le_uint64_t join_eui
join EUI.
Definition: hdr.h:94
le_uint16_t dev_nonce
device nonce
Definition: hdr.h:96
le_uint64_t dev_eui
device EUI
Definition: hdr.h:95
le_uint32_t mic
message integrity code
Definition: hdr.h:97
uint8_t mt_maj
mtype and major version holder
Definition: hdr.h:93
A 16 bit integer in little endian.
Definition: byteorder.h:34
A 32 bit integer in little endian.
Definition: byteorder.h:44
A 64 bit integer in little endian.
Definition: byteorder.h:56