lorawan.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2019 HAW Hamburg
3  * SPDX-License-Identifier: LGPL-2.1-only
4  */
5 
6 #pragma once
7 
18 #include "net/gnrc/lorawan.h"
19 
20 #include "ztimer.h"
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
29 #define GNRC_NETIF_LORAWAN_FLAGS_LINK_CHECK (0x1U)
30 
34 typedef struct {
35  uint8_t appskey[LORAMAC_APPSKEY_LEN];
36  uint8_t fnwksintkey[LORAMAC_FNWKSINTKEY_LEN];
37  uint8_t nwkkey[LORAMAC_NWKKEY_LEN];
38 #if IS_USED(MODULE_GNRC_LORAWAN_1_1)
39  uint8_t appkey[LORAMAC_APPKEY_LEN];
40  uint8_t snwksintkey[LORAMAC_SNWKSINTKEY_LEN];
41  uint8_t nwksenckey[LORAMAC_NWKSENCKEY_LEN];
42  uint8_t jsintkey[LORAMAC_JSINTKEY_LEN];
43  uint8_t jsenckey[LORAMAC_JSENCKEY_LEN];
44 #endif
45  uint8_t deveui[LORAMAC_DEVEUI_LEN];
46  uint8_t joineui[LORAMAC_JOINEUI_LEN];
50  uint8_t flags;
51  uint8_t demod_margin;
52  uint8_t num_gateways;
53  uint8_t datarate;
54  uint8_t port;
55  uint8_t ack_req;
56  uint8_t otaa;
58 
71 static inline int gnrc_netif_lorawan_set_appkey(gnrc_netif_lorawan_t *lw_netif, const uint8_t *key,
72  size_t len)
73 {
74  (void)lw_netif;
75  (void)key;
76  (void)len;
77 
78 #if IS_USED(MODULE_GNRC_LORAWAN_1_1)
79  if (sizeof(lw_netif->appkey) < len) {
80  return -1;
81  }
82  memcpy(lw_netif->appkey, key, len);
83 #endif
84  return 0;
85 }
86 
96 static inline uint8_t * gnrc_netif_lorawan_get_appkey(gnrc_netif_lorawan_t *lw_netif)
97 {
98  (void)lw_netif;
99 
100 #if IS_USED(MODULE_GNRC_LORAWAN_1_1)
101  return lw_netif->appkey;
102 #endif
103  return NULL; /* NO-OP */
104 }
105 
119  const uint8_t *key, size_t len)
120 {
121  (void)lw_netif;
122  (void)key;
123  (void)len;
124 
125 #if IS_USED(MODULE_GNRC_LORAWAN_1_1)
126  if (sizeof(lw_netif->snwksintkey) < len) {
127  return -1;
128  }
129  memcpy(lw_netif->snwksintkey, key, len);
130 #endif
131  return 0;
132 }
133 
147  const uint8_t *key, size_t len)
148 {
149  (void)lw_netif;
150  (void)key;
151  (void)len;
152 
153 #if IS_USED(MODULE_GNRC_LORAWAN_1_1)
154  if (sizeof(lw_netif->nwksenckey) < len) {
155  return -1;
156  }
157  memcpy(lw_netif->nwksenckey, key, len);
158 #endif
159  return 0;
160 }
161 
162 #ifdef __cplusplus
163 }
164 #endif
165 
#define LORAMAC_NWKSENCKEY_LEN
Network session encryption key length in bytes.
Definition: loramac.h:596
#define LORAMAC_FNWKSINTKEY_LEN
Forwarding Network session integrity key length in bytes.
Definition: loramac.h:586
#define LORAMAC_APPKEY_LEN
Application key length in bytes.
Definition: loramac.h:566
#define LORAMAC_JOINEUI_LEN
Join EUI length in bytes.
Definition: loramac.h:561
#define LORAMAC_DEVEUI_LEN
Device EUI length in bytes.
Definition: loramac.h:546
#define LORAMAC_JSINTKEY_LEN
Join session integrity key length in bytes.
Definition: loramac.h:611
#define LORAMAC_JSENCKEY_LEN
Join session encryption key length in bytes.
Definition: loramac.h:606
#define LORAMAC_NWKKEY_LEN
Network key length in bytes.
Definition: loramac.h:571
#define LORAMAC_APPSKEY_LEN
Application session key length in bytes.
Definition: loramac.h:576
#define LORAMAC_SNWKSINTKEY_LEN
Serving Network session integrity key length in bytes.
Definition: loramac.h:591
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:96
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:118
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:146
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:71
GNRC LoRaWAN mac descriptor.
GNRC LoRaWAN interface descriptor.
Definition: lorawan.h:34
ztimer_t timer
General purpose timer.
Definition: lorawan.h:48
gnrc_lorawan_t mac
gnrc lorawan mac descriptor
Definition: lorawan.h:47
uint8_t num_gateways
number of gateways of last link check
Definition: lorawan.h:52
uint8_t otaa
whether the next transmission is OTAA or not
Definition: lorawan.h:56
uint8_t port
LoRaWAN port for the next transmission.
Definition: lorawan.h:54
ztimer_t backoff_timer
Backoff timer.
Definition: lorawan.h:49
uint8_t datarate
LoRaWAN datarate for the next transmission.
Definition: lorawan.h:53
uint8_t demod_margin
value of last demodulation margin
Definition: lorawan.h:51
uint8_t flags
flags for the LoRaWAN interface
Definition: lorawan.h:50
uint8_t ack_req
Request ACK in the next transmission.
Definition: lorawan.h:55
ztimer structure
Definition: ztimer.h:316
ztimer API