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 
18 #ifndef NET_GNRC_NETIF_LORAWAN_H
19 #define NET_GNRC_NETIF_LORAWAN_H
20 
21 #include "net/gnrc/lorawan.h"
22 
23 #include "ztimer.h"
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
32 #define GNRC_NETIF_LORAWAN_FLAGS_LINK_CHECK (0x1U)
33 
37 typedef struct {
38  uint8_t appskey[LORAMAC_APPSKEY_LEN];
39  uint8_t fnwksintkey[LORAMAC_FNWKSINTKEY_LEN];
40  uint8_t nwkkey[LORAMAC_NWKKEY_LEN];
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
48  uint8_t deveui[LORAMAC_DEVEUI_LEN];
49  uint8_t joineui[LORAMAC_JOINEUI_LEN];
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 
74 static inline int gnrc_netif_lorawan_set_appkey(gnrc_netif_lorawan_t *lw_netif, const uint8_t *key,
75  size_t len)
76 {
77  (void)lw_netif;
78  (void)key;
79  (void)len;
80 
81 #if IS_USED(MODULE_GNRC_LORAWAN_1_1)
82  if (sizeof(lw_netif->appkey) < len) {
83  return -1;
84  }
85  memcpy(lw_netif->appkey, key, len);
86 #endif
87  return 0;
88 }
89 
99 static inline uint8_t * gnrc_netif_lorawan_get_appkey(gnrc_netif_lorawan_t *lw_netif)
100 {
101  (void)lw_netif;
102 
103 #if IS_USED(MODULE_GNRC_LORAWAN_1_1)
104  return lw_netif->appkey;
105 #endif
106  return NULL; /* NO-OP */
107 }
108 
122  const uint8_t *key, size_t len)
123 {
124  (void)lw_netif;
125  (void)key;
126  (void)len;
127 
128 #if IS_USED(MODULE_GNRC_LORAWAN_1_1)
129  if (sizeof(lw_netif->snwksintkey) < len) {
130  return -1;
131  }
132  memcpy(lw_netif->snwksintkey, key, len);
133 #endif
134  return 0;
135 }
136 
150  const uint8_t *key, size_t len)
151 {
152  (void)lw_netif;
153  (void)key;
154  (void)len;
155 
156 #if IS_USED(MODULE_GNRC_LORAWAN_1_1)
157  if (sizeof(lw_netif->nwksenckey) < len) {
158  return -1;
159  }
160  memcpy(lw_netif->nwksenckey, key, len);
161 #endif
162  return 0;
163 }
164 
165 #ifdef __cplusplus
166 }
167 #endif
168 
169 #endif /* NET_GNRC_NETIF_LORAWAN_H */
#define LORAMAC_NWKSENCKEY_LEN
Network session encryption key length in bytes.
Definition: loramac.h:600
#define LORAMAC_FNWKSINTKEY_LEN
Forwarding Network session integrity key length in bytes.
Definition: loramac.h:590
#define LORAMAC_APPKEY_LEN
Application key length in bytes.
Definition: loramac.h:570
#define LORAMAC_JOINEUI_LEN
Join EUI length in bytes.
Definition: loramac.h:565
#define LORAMAC_DEVEUI_LEN
Device EUI length in bytes.
Definition: loramac.h:550
#define LORAMAC_JSINTKEY_LEN
Join session integrity key length in bytes.
Definition: loramac.h:615
#define LORAMAC_JSENCKEY_LEN
Join session encryption key length in bytes.
Definition: loramac.h:610
#define LORAMAC_NWKKEY_LEN
Network key length in bytes.
Definition: loramac.h:575
#define LORAMAC_APPSKEY_LEN
Application session key length in bytes.
Definition: loramac.h:580
#define LORAMAC_SNWKSINTKEY_LEN
Serving Network session integrity key length in bytes.
Definition: loramac.h:595
GNRC LoRaWAN API definition.
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:99
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:121
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:149
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:74
GNRC LoRaWAN mac descriptor.
GNRC LoRaWAN interface descriptor.
Definition: lorawan.h:37
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 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 flags
flags for the LoRaWAN interface
Definition: lorawan.h:53
uint8_t ack_req
Request ACK in the next transmission.
Definition: lorawan.h:58
ztimer structure
Definition: ztimer.h:319
ztimer API