Loading...
Searching...
No Matches
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#define LORAWAN_JA_HDR_OPTNEG_MASK (0x80)
48#define LORAWAN_JA_HDR_OPTNEG_POS (7U)
50#ifdef __cplusplus
51extern "C" {
52#endif
53
74typedef struct __attribute__((packed)) {
87 uint8_t mt_maj;
89 uint8_t fctrl;
92
103
107typedef struct __attribute__((packed)) {
108 uint8_t mt_maj;
109 uint8_t join_nonce[LORAMAC_JOIN_NONCE_LEN];
110 uint8_t net_id[LORAMAC_NETWORK_ID_LEN];
111 uint8_t dev_addr[LORAMAC_DEVADDR_LEN];
112 uint8_t dl_settings;
113 uint8_t rx_delay;
115
122static inline void lorawan_hdr_set_mtype(lorawan_hdr_t *hdr, uint8_t mtype)
123{
124 hdr->mt_maj &= ~LORAWAN_HDR_MTYPE_MASK;
126}
127
135static inline uint8_t lorawan_hdr_get_mtype(lorawan_hdr_t *hdr)
136{
138}
139
146static inline void lorawan_hdr_set_maj(lorawan_hdr_t *hdr, uint8_t maj)
147{
148 hdr->mt_maj &= ~LORAWAN_HDR_MAJOR_MASK;
150}
151
159static inline uint8_t lorawan_hdr_get_maj(lorawan_hdr_t *hdr)
160{
162}
163
170static inline void lorawan_hdr_set_adr(lorawan_hdr_t *hdr, bool adr)
171{
172 hdr->fctrl &= ~LORAWAN_HDR_ADR_MASK;
174}
175
183static inline bool lorawan_hdr_get_adr(lorawan_hdr_t *hdr)
184{
186}
187
194static inline void lorawan_hdr_set_adr_ack_req(lorawan_hdr_t *hdr, bool adr_ack_req)
195{
196 hdr->fctrl &= ~LORAWAN_HDR_ADR_ACK_MASK;
197 hdr->fctrl |= (adr_ack_req << LORAWAN_HDR_ADR_ACK_POS) & LORAWAN_HDR_ADR_ACK_MASK;
198}
199
208{
210}
211
218static inline void lorawan_hdr_set_ack(lorawan_hdr_t *hdr, bool ack)
219{
220 hdr->fctrl &= ~LORAWAN_HDR_ACK_MASK;
222}
223
231static inline bool lorawan_hdr_get_ack(lorawan_hdr_t *hdr)
232{
234}
235
242static inline void lorawan_hdr_set_frame_pending(lorawan_hdr_t *hdr, bool frame_pending)
243{
244 hdr->fctrl &= ~LORAWAN_HDR_FRAME_PENDING_MASK;
246}
247
259
266static inline void lorawan_hdr_set_frame_opts_len(lorawan_hdr_t *hdr, uint8_t len)
267{
268 hdr->fctrl &= ~LORAWAN_HDR_FOPTS_LEN_MASK;
270}
271
283
295
296#ifdef __cplusplus
297}
298#endif
299
300#endif /* NET_LORAWAN_HDR_H */
Functions to work with different byte orders.
#define LORAMAC_DEVADDR_LEN
Device address length in bytes.
Definition loramac.h:555
#define LORAMAC_JOIN_NONCE_LEN
Join nonce length in bytes.
Definition loramac.h:635
#define LORAMAC_NETWORK_ID_LEN
Network ID length in bytes.
Definition loramac.h:640
#define LORAWAN_HDR_MAJOR_POS
Major version position.
Definition hdr.h:35
#define LORAWAN_HDR_FRAME_PENDING_POS
Frame pending bit position.
Definition hdr.h:43
static void lorawan_hdr_set_ack(lorawan_hdr_t *hdr, bool ack)
Set LoRaWAN header ACK bit.
Definition hdr.h:218
static void lorawan_hdr_set_frame_pending(lorawan_hdr_t *hdr, bool frame_pending)
Set LoRaWAN header frame pending bit.
Definition hdr.h:242
static uint8_t lorawan_hdr_get_mtype(lorawan_hdr_t *hdr)
Get LoRaWAN header MType.
Definition hdr.h:135
#define LORAWAN_HDR_ADR_MASK
ADR mask.
Definition hdr.h:36
#define LORAWAN_HDR_ADR_ACK_POS
ADR ACK bit position.
Definition hdr.h:39
static uint8_t lorawan_hdr_get_maj(lorawan_hdr_t *hdr)
Get LoRaWAN major version.
Definition hdr.h:159
static bool lorawan_hdr_get_adr(lorawan_hdr_t *hdr)
Get LoRaWAN header Adaptive Data Rate bit.
Definition hdr.h:183
static bool lorawan_ja_hdr_get_optneg(lorawan_join_accept_t *ja_hdr)
Get LoRaWAN join accept message OptNeg bit.
Definition hdr.h:291
#define LORAWAN_HDR_ADR_ACK_MASK
ADR ACK bit mask.
Definition hdr.h:38
#define LORAWAN_JA_HDR_OPTNEG_MASK
OptNeg bit mask.
Definition hdr.h:47
static void lorawan_hdr_set_maj(lorawan_hdr_t *hdr, uint8_t maj)
Set LoRaWAN major version.
Definition hdr.h:146
#define LORAWAN_HDR_FOPTS_LEN_POS
Frame options position.
Definition hdr.h:45
#define LORAWAN_JA_HDR_OPTNEG_POS
OptNeg bit position.
Definition hdr.h:48
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:194
#define LORAWAN_HDR_ADR_POS
ADR position.
Definition hdr.h:37
static bool lorawan_hdr_get_frame_pending(lorawan_hdr_t *hdr)
Get LoRaWAN header frame pending bit.
Definition hdr.h:255
#define LORAWAN_HDR_MTYPE_MASK
MType mask.
Definition hdr.h:32
#define LORAWAN_HDR_ACK_POS
ACK bit position.
Definition hdr.h:41
#define LORAWAN_HDR_ACK_MASK
ACK bit mask.
Definition hdr.h:40
#define LORAWAN_HDR_FRAME_PENDING_MASK
Frame pending bit mask.
Definition hdr.h:42
static bool lorawan_hdr_get_ack(lorawan_hdr_t *hdr)
Get LoRaWAN header ACK bit.
Definition hdr.h:231
#define LORAWAN_HDR_MAJOR_MASK
Major version mask.
Definition hdr.h:34
#define LORAWAN_HDR_MTYPE_POS
MType position.
Definition hdr.h:33
static bool lorawan_hdr_get_adr_ack_req(lorawan_hdr_t *hdr)
Get LoRaWAN header ADR ACK request bit.
Definition hdr.h:207
static void lorawan_hdr_set_adr(lorawan_hdr_t *hdr, bool adr)
Set LoRaWAN header Adaptive Data Rate bit.
Definition hdr.h:170
#define LORAWAN_HDR_FOPTS_LEN_MASK
Frame options mask.
Definition hdr.h:44
static void lorawan_hdr_set_frame_opts_len(lorawan_hdr_t *hdr, uint8_t len)
Set LoRaWAN header FOpts length.
Definition hdr.h:266
static void lorawan_hdr_set_mtype(lorawan_hdr_t *hdr, uint8_t mtype)
Set LoRaWAN header MType.
Definition hdr.h:122
static uint8_t lorawan_hdr_get_frame_opts_len(lorawan_hdr_t *hdr)
Get LoRaWAN header FOps length.
Definition hdr.h:279
LoRaMAC header definitions.
stdio wrapper to extend the C libs stdio
Data type to represent a LoRaWAN packet header.
Definition hdr.h:74
le_uint16_t fcnt
frame counter
Definition hdr.h:90
uint8_t mt_maj
message type and major version
Definition hdr.h:87
uint8_t fctrl
frame control
Definition hdr.h:89
le_uint32_t addr
32 bit LoRaWAN address
Definition hdr.h:88
Join accept packet representation.
Definition hdr.h:107
uint8_t rx_delay
first reception window delay
Definition hdr.h:113
uint8_t mt_maj
mtype and major version holder
Definition hdr.h:108
uint8_t dl_settings
downlink settings
Definition hdr.h:112
Join request packet representation.
Definition hdr.h:96
le_uint64_t join_eui
join EUI.
Definition hdr.h:98
le_uint16_t dev_nonce
device nonce
Definition hdr.h:100
le_uint64_t dev_eui
device EUI
Definition hdr.h:99
le_uint32_t mic
message integrity code
Definition hdr.h:101
uint8_t mt_maj
mtype and major version holder
Definition hdr.h:97
A 16 bit integer in little endian.
Definition byteorder.h:38
A 32 bit integer in little endian.
Definition byteorder.h:48
A 64 bit integer in little endian.
Definition byteorder.h:60