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
10#pragma once
11
23
24#include <stdio.h>
25#include <stdint.h>
26#include <stdbool.h>
27
28#include "byteorder.h"
29#include "net/loramac.h"
30
31#define LORAWAN_HDR_MTYPE_MASK (0xe0)
32#define LORAWAN_HDR_MTYPE_POS (5U)
33#define LORAWAN_HDR_MAJOR_MASK (0x03)
34#define LORAWAN_HDR_MAJOR_POS (0U)
35#define LORAWAN_HDR_ADR_MASK (0x80)
36#define LORAWAN_HDR_ADR_POS (7U)
37#define LORAWAN_HDR_ADR_ACK_MASK (0x40)
38#define LORAWAN_HDR_ADR_ACK_POS (6U)
39#define LORAWAN_HDR_ACK_MASK (0x20)
40#define LORAWAN_HDR_ACK_POS (5U)
41#define LORAWAN_HDR_FRAME_PENDING_MASK (0x10)
42#define LORAWAN_HDR_FRAME_PENDING_POS (4U)
43#define LORAWAN_HDR_FOPTS_LEN_MASK (0x0F)
44#define LORAWAN_HDR_FOPTS_LEN_POS (0U)
45
46#define LORAWAN_JA_HDR_OPTNEG_MASK (0x80)
47#define LORAWAN_JA_HDR_OPTNEG_POS (7U)
48
49#ifdef __cplusplus
50extern "C" {
51#endif
52
73typedef struct __attribute__((packed)) {
86 uint8_t mt_maj;
88 uint8_t fctrl;
91
102
106typedef struct __attribute__((packed)) {
107 uint8_t mt_maj;
111 uint8_t dl_settings;
112 uint8_t rx_delay;
114
121static inline void lorawan_hdr_set_mtype(lorawan_hdr_t *hdr, uint8_t mtype)
122{
125}
126
134static inline uint8_t lorawan_hdr_get_mtype(lorawan_hdr_t *hdr)
135{
137}
138
145static inline void lorawan_hdr_set_maj(lorawan_hdr_t *hdr, uint8_t maj)
146{
149}
150
158static inline uint8_t lorawan_hdr_get_maj(lorawan_hdr_t *hdr)
159{
161}
162
169static inline void lorawan_hdr_set_adr(lorawan_hdr_t *hdr, bool adr)
170{
173}
174
182static inline bool lorawan_hdr_get_adr(lorawan_hdr_t *hdr)
183{
185}
186
193static inline void lorawan_hdr_set_adr_ack_req(lorawan_hdr_t *hdr, bool adr_ack_req)
194{
196 hdr->fctrl |= (adr_ack_req << LORAWAN_HDR_ADR_ACK_POS) & LORAWAN_HDR_ADR_ACK_MASK;
197}
198
207{
209}
210
217static inline void lorawan_hdr_set_ack(lorawan_hdr_t *hdr, bool ack)
218{
221}
222
230static inline bool lorawan_hdr_get_ack(lorawan_hdr_t *hdr)
231{
233}
234
241static inline void lorawan_hdr_set_frame_pending(lorawan_hdr_t *hdr, bool frame_pending)
242{
245}
246
258
265static inline void lorawan_hdr_set_frame_opts_len(lorawan_hdr_t *hdr, uint8_t len)
266{
269}
270
282
294
295#ifdef __cplusplus
296}
297#endif
298
Functions to work with different byte orders.
#define LORAMAC_DEVADDR_LEN
Device address length in bytes.
Definition loramac.h:554
#define LORAMAC_JOIN_NONCE_LEN
Join nonce length in bytes.
Definition loramac.h:634
#define LORAMAC_NETWORK_ID_LEN
Network ID length in bytes.
Definition loramac.h:639
#define LORAWAN_HDR_MAJOR_POS
Major version position.
Definition hdr.h:34
#define LORAWAN_HDR_FRAME_PENDING_POS
Frame pending bit position.
Definition hdr.h:42
static void lorawan_hdr_set_ack(lorawan_hdr_t *hdr, bool ack)
Set LoRaWAN header ACK bit.
Definition hdr.h:217
static void lorawan_hdr_set_frame_pending(lorawan_hdr_t *hdr, bool frame_pending)
Set LoRaWAN header frame pending bit.
Definition hdr.h:241
static uint8_t lorawan_hdr_get_mtype(lorawan_hdr_t *hdr)
Get LoRaWAN header MType.
Definition hdr.h:134
#define LORAWAN_HDR_ADR_MASK
ADR mask.
Definition hdr.h:35
#define LORAWAN_HDR_ADR_ACK_POS
ADR ACK bit position.
Definition hdr.h:38
static uint8_t lorawan_hdr_get_maj(lorawan_hdr_t *hdr)
Get LoRaWAN major version.
Definition hdr.h:158
static bool lorawan_hdr_get_adr(lorawan_hdr_t *hdr)
Get LoRaWAN header Adaptive Data Rate bit.
Definition hdr.h:182
static bool lorawan_ja_hdr_get_optneg(lorawan_join_accept_t *ja_hdr)
Get LoRaWAN join accept message OptNeg bit.
Definition hdr.h:290
#define LORAWAN_HDR_ADR_ACK_MASK
ADR ACK bit mask.
Definition hdr.h:37
#define LORAWAN_JA_HDR_OPTNEG_MASK
OptNeg bit mask.
Definition hdr.h:46
static void lorawan_hdr_set_maj(lorawan_hdr_t *hdr, uint8_t maj)
Set LoRaWAN major version.
Definition hdr.h:145
#define LORAWAN_HDR_FOPTS_LEN_POS
Frame options position.
Definition hdr.h:44
#define LORAWAN_JA_HDR_OPTNEG_POS
OptNeg bit position.
Definition hdr.h:47
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:193
#define LORAWAN_HDR_ADR_POS
ADR position.
Definition hdr.h:36
static bool lorawan_hdr_get_frame_pending(lorawan_hdr_t *hdr)
Get LoRaWAN header frame pending bit.
Definition hdr.h:254
#define LORAWAN_HDR_MTYPE_MASK
MType mask.
Definition hdr.h:31
#define LORAWAN_HDR_ACK_POS
ACK bit position.
Definition hdr.h:40
#define LORAWAN_HDR_ACK_MASK
ACK bit mask.
Definition hdr.h:39
#define LORAWAN_HDR_FRAME_PENDING_MASK
Frame pending bit mask.
Definition hdr.h:41
static bool lorawan_hdr_get_ack(lorawan_hdr_t *hdr)
Get LoRaWAN header ACK bit.
Definition hdr.h:230
#define LORAWAN_HDR_MAJOR_MASK
Major version mask.
Definition hdr.h:33
#define LORAWAN_HDR_MTYPE_POS
MType position.
Definition hdr.h:32
static bool lorawan_hdr_get_adr_ack_req(lorawan_hdr_t *hdr)
Get LoRaWAN header ADR ACK request bit.
Definition hdr.h:206
static void lorawan_hdr_set_adr(lorawan_hdr_t *hdr, bool adr)
Set LoRaWAN header Adaptive Data Rate bit.
Definition hdr.h:169
#define LORAWAN_HDR_FOPTS_LEN_MASK
Frame options mask.
Definition hdr.h:43
static void lorawan_hdr_set_frame_opts_len(lorawan_hdr_t *hdr, uint8_t len)
Set LoRaWAN header FOpts length.
Definition hdr.h:265
static void lorawan_hdr_set_mtype(lorawan_hdr_t *hdr, uint8_t mtype)
Set LoRaWAN header MType.
Definition hdr.h:121
static uint8_t lorawan_hdr_get_frame_opts_len(lorawan_hdr_t *hdr)
Get LoRaWAN header FOps length.
Definition hdr.h:278
LoRaMAC header definitions.
Data type to represent a LoRaWAN packet header.
Definition hdr.h:73
le_uint16_t fcnt
frame counter
Definition hdr.h:89
uint8_t mt_maj
message type and major version
Definition hdr.h:86
uint8_t fctrl
frame control
Definition hdr.h:88
le_uint32_t addr
32 bit LoRaWAN address
Definition hdr.h:87
Join accept packet representation.
Definition hdr.h:106
uint8_t dev_addr[LORAMAC_DEVADDR_LEN]
device address
Definition hdr.h:110
uint8_t join_nonce[LORAMAC_JOIN_NONCE_LEN]
join nonce.
Definition hdr.h:108
uint8_t net_id[LORAMAC_NETWORK_ID_LEN]
network id
Definition hdr.h:109
uint8_t rx_delay
first reception window delay
Definition hdr.h:112
uint8_t mt_maj
mtype and major version holder
Definition hdr.h:107
uint8_t dl_settings
downlink settings
Definition hdr.h:111
Join request packet representation.
Definition hdr.h:95
le_uint64_t join_eui
join EUI.
Definition hdr.h:97
le_uint16_t dev_nonce
device nonce
Definition hdr.h:99
le_uint64_t dev_eui
device EUI
Definition hdr.h:98
le_uint32_t mic
message integrity code
Definition hdr.h:100
uint8_t mt_maj
mtype and major version holder
Definition hdr.h:96
A 16 bit integer in little endian.
Definition byteorder.h:37
A 32 bit integer in little endian.
Definition byteorder.h:47
A 64 bit integer in little endian.
Definition byteorder.h:59