Loading...
Searching...
No Matches
lorawan.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2019 HAW Hamburg
3 *
4 * This file is subject to the terms and conditions of the GNU Lesser
5 * General Public License v2.1. See the file LICENSE in the top level
6 * directory for more details.
7 */
8
9#pragma once
10
20
21#include "compiler_hints.h"
22#include "net/gnrc/lorawan.h"
23#include "ztimer.h"
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
32#define GNRC_NETIF_LORAWAN_FLAGS_LINK_CHECK (0x1U)
33
37typedef struct {
41#if IS_USED(MODULE_GNRC_LORAWAN_1_1)
42 uint8_t appkey[LORAMAC_APPKEY_LEN];
43 uint8_t snwksintkey[LORAMAC_SNWKSINTKEY_LEN];
44 uint8_t nwksenckey[LORAMAC_NWKSENCKEY_LEN];
45 uint8_t jsintkey[LORAMAC_JSINTKEY_LEN];
46 uint8_t jsenckey[LORAMAC_JSENCKEY_LEN];
47#endif
53 uint8_t flags;
54 uint8_t demod_margin;
55 uint8_t num_gateways;
56 uint8_t datarate;
57 uint8_t port;
58 uint8_t ack_req;
59 uint8_t otaa;
61
74ACCESS(read_only, 2, 3)
76 const uint8_t *key,
77 size_t len)
78{
79 (void)lw_netif;
80 (void)key;
81 (void)len;
82
83#if IS_USED(MODULE_GNRC_LORAWAN_1_1)
84 if (sizeof(lw_netif->appkey) < len) {
85 return -1;
86 }
87 memcpy(lw_netif->appkey, key, len);
88#endif
89 return 0;
90}
91
101static inline uint8_t * gnrc_netif_lorawan_get_appkey(gnrc_netif_lorawan_t *lw_netif)
102{
103 (void)lw_netif;
104
105#if IS_USED(MODULE_GNRC_LORAWAN_1_1)
106 return lw_netif->appkey;
107#endif
108 return NULL; /* NO-OP */
109}
110
123ACCESS(read_only, 2, 3)
125 const uint8_t *key, size_t len)
126{
127 (void)lw_netif;
128 (void)key;
129 (void)len;
130
131#if IS_USED(MODULE_GNRC_LORAWAN_1_1)
132 if (sizeof(lw_netif->snwksintkey) < len) {
133 return -1;
134 }
135 memcpy(lw_netif->snwksintkey, key, len);
136#endif
137 return 0;
138}
139
152ACCESS(read_only, 2, 3)
154 const uint8_t *key, size_t len)
155{
156 (void)lw_netif;
157 (void)key;
158 (void)len;
159
160#if IS_USED(MODULE_GNRC_LORAWAN_1_1)
161 if (sizeof(lw_netif->nwksenckey) < len) {
162 return -1;
163 }
164 memcpy(lw_netif->nwksenckey, key, len);
165#endif
166 return 0;
167}
168
169#ifdef __cplusplus
170}
171#endif
172
Common macros and compiler attributes/pragmas configuration.
#define ACCESS(mode, ptr_idx, size_idx)
Emit an attribute (if supported by the compiler) that declares how a function will access its paramet...
#define LORAMAC_NWKSENCKEY_LEN
Network session encryption key length in bytes.
Definition loramac.h:599
#define LORAMAC_FNWKSINTKEY_LEN
Forwarding Network session integrity key length in bytes.
Definition loramac.h:589
#define LORAMAC_APPKEY_LEN
Application key length in bytes.
Definition loramac.h:569
#define LORAMAC_JOINEUI_LEN
Join EUI length in bytes.
Definition loramac.h:564
#define LORAMAC_DEVEUI_LEN
Device EUI length in bytes.
Definition loramac.h:549
#define LORAMAC_JSINTKEY_LEN
Join session integrity key length in bytes.
Definition loramac.h:604
#define LORAMAC_JSENCKEY_LEN
Join session encryption key length in bytes.
Definition loramac.h:609
#define LORAMAC_NWKKEY_LEN
Network key length in bytes.
Definition loramac.h:574
#define LORAMAC_APPSKEY_LEN
Application session key length in bytes.
Definition loramac.h:579
#define LORAMAC_SNWKSINTKEY_LEN
Serving Network session integrity key length in bytes.
Definition loramac.h:594
GNRC LoRaWAN API definition.
static int gnrc_netif_lorawan_set_snwksintkey(gnrc_netif_lorawan_t *lw_netif, const uint8_t *key, size_t len)
Set the serving network session integrity key in the interface descriptor.
Definition lorawan.h:124
static int gnrc_netif_lorawan_set_nwksenckey(gnrc_netif_lorawan_t *lw_netif, const uint8_t *key, size_t len)
Set the network session encryption key in the interface descriptor.
Definition lorawan.h:153
static int gnrc_netif_lorawan_set_appkey(gnrc_netif_lorawan_t *lw_netif, const uint8_t *key, size_t len)
Set the app key in the interface descriptor.
Definition lorawan.h:75
static uint8_t * gnrc_netif_lorawan_get_appkey(gnrc_netif_lorawan_t *lw_netif)
Get the app key from the interface descriptor.
Definition lorawan.h:101
GNRC LoRaWAN mac descriptor.
GNRC LoRaWAN interface descriptor.
Definition lorawan.h:37
uint8_t joineui[LORAMAC_JOINEUI_LEN]
Join EUI buffer.
Definition lorawan.h:49
ztimer_t timer
General purpose timer.
Definition lorawan.h:51
gnrc_lorawan_t mac
gnrc lorawan mac descriptor
Definition lorawan.h:50
uint8_t num_gateways
number of gateways of last link check
Definition lorawan.h:55
uint8_t otaa
whether the next transmission is OTAA or not
Definition lorawan.h:59
uint8_t deveui[LORAMAC_DEVEUI_LEN]
Device EUI buffer.
Definition lorawan.h:48
uint8_t port
LoRaWAN port for the next transmission.
Definition lorawan.h:57
ztimer_t backoff_timer
Backoff timer.
Definition lorawan.h:52
uint8_t datarate
LoRaWAN datarate for the next transmission.
Definition lorawan.h:56
uint8_t demod_margin
value of last demodulation margin
Definition lorawan.h:54
uint8_t nwkkey[LORAMAC_NWKKEY_LEN]
Network key buffer.
Definition lorawan.h:40
uint8_t appskey[LORAMAC_APPSKEY_LEN]
App SKey buffer.
Definition lorawan.h:38
uint8_t flags
flags for the LoRaWAN interface
Definition lorawan.h:53
uint8_t ack_req
Request ACK in the next transmission.
Definition lorawan.h:58
uint8_t fnwksintkey[LORAMAC_FNWKSINTKEY_LEN]
Forwarding Network session integrity key buffer.
Definition lorawan.h:39
ztimer structure
Definition ztimer.h:319
ztimer API