semtech_loramac.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017 Inria
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 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 #include <inttypes.h>
26 
27 #include "mutex.h"
28 
29 #include "net/netdev.h"
30 #include "net/loramac.h"
31 
36 #define MSG_TYPE_ISR (0x3456)
37 #define MSG_TYPE_RX_TIMEOUT (0x3457)
38 #define MSG_TYPE_TX_TIMEOUT (0x3458)
39 #define MSG_TYPE_MAC_TIMEOUT (0x3459)
40 #define MSG_TYPE_LORAMAC_CMD (0x3460)
41 #define MSG_TYPE_LORAMAC_JOIN_STATUS (0x3461)
42 #define MSG_TYPE_LORAMAC_TX_STATUS (0x3462)
43 #define MSG_TYPE_LORAMAC_MLME_CONFIRM (0x3463)
44 #define MSG_TYPE_LORAMAC_MLME_INDICATION (0x3464)
45 #define MSG_TYPE_LORAMAC_MCPS_CONFIRM (0x3465)
46 #define MSG_TYPE_LORAMAC_MCPS_INDICATION (0x3466)
52 #define LORAWAN_APP_DATA_MAX_SIZE (242U)
53 
57 enum {
72 };
73 
77 enum {
78  SEMTECH_LORAMAC_STATE_IDLE = 0,
79  SEMTECH_LORAMAC_STATE_BUSY
80 };
81 
85 typedef struct {
86  uint32_t frequency;
87  uint8_t datarate;
89 
93 typedef struct {
94  uint8_t payload[LORAWAN_APP_DATA_MAX_SIZE];
95  uint8_t payload_len;
96  uint8_t port;
98 
99 #if defined(MODULE_SEMTECH_LORAMAC_RX) || DOXYGEN
103 typedef struct {
104  uint8_t demod_margin;
105  uint8_t nb_gateways;
107 #endif
108 
112 typedef struct {
115  uint8_t tx_pid;
116 #if defined(MODULE_SEMTECH_LORAMAC_RX) || DOXYGEN
117  uint8_t rx_pid;
118 #endif
119  uint8_t port;
120  uint8_t cnf;
121  uint8_t deveui[LORAMAC_DEVEUI_LEN];
122  uint8_t appeui[LORAMAC_APPEUI_LEN];
123  uint8_t appkey[LORAMAC_APPKEY_LEN];
124 #if defined(MODULE_SEMTECH_LORAMAC_RX) || DOXYGEN
127 #endif
129 
139 
153 uint8_t semtech_loramac_join(semtech_loramac_t *mac, uint8_t type);
154 
176 uint8_t semtech_loramac_send(semtech_loramac_t *mac, uint8_t *data, uint8_t len);
177 
178 #if defined(MODULE_SEMTECH_LORAMAC_RX) || DOXYGEN
203 #endif
204 
213 
214 #if defined(MODULE_SEMTECH_LORAMAC_RX) || DOXYGEN
224 #endif
225 
232 void semtech_loramac_set_deveui(semtech_loramac_t *mac, const uint8_t *eui);
233 
240 void semtech_loramac_get_deveui(const semtech_loramac_t *mac, uint8_t *eui);
241 
248 void semtech_loramac_set_appeui(semtech_loramac_t *mac, const uint8_t *eui);
249 
256 void semtech_loramac_get_appeui(const semtech_loramac_t *mac, uint8_t *eui);
257 
264 void semtech_loramac_set_appkey(semtech_loramac_t *mac, const uint8_t *key);
265 
272 void semtech_loramac_get_appkey(const semtech_loramac_t *mac, uint8_t *key);
273 
280 void semtech_loramac_set_appskey(semtech_loramac_t *mac, const uint8_t *skey);
281 
289 
296 void semtech_loramac_set_nwkskey(semtech_loramac_t *mac, const uint8_t *skey);
297 
305 
312 void semtech_loramac_set_devaddr(semtech_loramac_t *mac, const uint8_t *addr);
313 
321 
329 
337 
345 
353 
361 
369 
377 
385 
392 void semtech_loramac_set_netid(semtech_loramac_t *mac, uint32_t netid);
393 
401 
409 
417 
425 
433 
441 
449 
457 
465 
473 
481 
489 
497 
505 
513 
521 
529 
530 #ifdef MODULE_PERIPH_EEPROM
534 #ifndef SEMTECH_LORAMAC_EEPROM_MAGIC
535 #define SEMTECH_LORAMAC_EEPROM_MAGIC {0x52, 0x49, 0x4F, 0x54} /* RIOT */
536 #endif
537 
541 #ifndef SEMTECH_LORAMAC_EEPROM_MAGIC_LEN
542 #define SEMTECH_LORAMAC_EEPROM_MAGIC_LEN 4
543 #endif
544 
548 #ifndef SEMTECH_LORAMAC_EEPROM_START
549 #define SEMTECH_LORAMAC_EEPROM_START (0)
550 #endif
551 
557 void semtech_loramac_save_config(semtech_loramac_t *mac);
558 
562 void semtech_loramac_erase_config(void);
563 #endif
564 
565 #ifdef __cplusplus
566 }
567 #endif
568 
Definitions low-level network driver interface.
#define LORAMAC_APPKEY_LEN
Application key length in bytes.
Definition: loramac.h:569
#define LORAMAC_APPEUI_LEN
Application EUI length in bytes.
Definition: loramac.h:559
#define LORAMAC_DEVEUI_LEN
Device EUI length in bytes.
Definition: loramac.h:549
loramac_class_t
Device class.
Definition: loramac.h:662
Adds include for missing inttype definitions.
LoRaMAC header definitions.
Mutex for thread synchronization.
#define LORAWAN_APP_DATA_MAX_SIZE
Maximum payload size of a LoRaWAN application data.
loramac_class_t semtech_loramac_get_class(semtech_loramac_t *mac)
Gets the device class.
uint32_t semtech_loramac_get_uplink_counter(semtech_loramac_t *mac)
Gets the Uplink Frame Counter.
@ SEMTECH_LORAMAC_BUSY
Internal MAC is busy.
@ SEMTECH_LORAMAC_RX_DATA
Data received.
@ SEMTECH_LORAMAC_TX_ERROR
Error in TX (invalid param, unknown service)
@ SEMTECH_LORAMAC_JOIN_FAILED
Join procedure failed.
@ SEMTECH_LORAMAC_TX_OK
Transmission is in progress.
@ SEMTECH_LORAMAC_RX_LINK_CHECK
Link check info received.
@ SEMTECH_LORAMAC_NOT_JOINED
MAC is not joined.
@ SEMTECH_LORAMAC_TX_CNF_FAILED
Confirmable transmission failed.
@ SEMTECH_LORAMAC_RX_CONFIRMED
Confirmed ACK received.
@ SEMTECH_LORAMAC_ALREADY_JOINED
MAC is already joined.
@ SEMTECH_LORAMAC_TX_DONE
Transmission completed.
@ SEMTECH_LORAMAC_DUTYCYCLE_RESTRICTED
Restricted access to channels.
@ SEMTECH_LORAMAC_TX_SCHEDULE
TX needs reschedule.
@ SEMTECH_LORAMAC_JOIN_SUCCEEDED
Join procedure succeeded.
uint8_t semtech_loramac_join(semtech_loramac_t *mac, uint8_t type)
Starts a LoRaWAN network join procedure.
void semtech_loramac_set_rx2_dr(semtech_loramac_t *mac, uint8_t dr)
Sets the RX2 datarate.
uint8_t semtech_loramac_get_tx_mode(semtech_loramac_t *mac)
Gets the TX confirmable mode.
void semtech_loramac_set_devaddr(semtech_loramac_t *mac, const uint8_t *addr)
Sets the device address.
void semtech_loramac_get_appeui(const semtech_loramac_t *mac, uint8_t *eui)
Gets the application EUI.
uint8_t semtech_loramac_get_tx_port(semtech_loramac_t *mac)
Gets the TX application port.
void semtech_loramac_get_appkey(const semtech_loramac_t *mac, uint8_t *key)
Gets the application key.
void semtech_loramac_set_deveui(semtech_loramac_t *mac, const uint8_t *eui)
Sets the device EUI.
uint32_t semtech_loramac_get_rx2_freq(semtech_loramac_t *mac)
Gets the RX2 frequency.
void semtech_loramac_set_min_rx_symbols(semtech_loramac_t *mac, uint8_t min_rx)
Sets the minimum required number of symbols to detect a frame.
uint8_t semtech_loramac_recv(semtech_loramac_t *mac)
Wait for a message sent by the LoRaWAN network.
void semtech_loramac_set_appskey(semtech_loramac_t *mac, const uint8_t *skey)
Sets the application session key.
void semtech_loramac_get_nwkskey(semtech_loramac_t *mac, uint8_t *skey)
Gets the network session key.
void semtech_loramac_set_tx_port(semtech_loramac_t *mac, uint8_t port)
Sets the TX application port.
void semtech_loramac_set_class(semtech_loramac_t *mac, loramac_class_t cls)
Sets the device class.
uint8_t semtech_loramac_get_tx_power(semtech_loramac_t *mac)
Gets the channels TX power index.
void semtech_loramac_set_public_network(semtech_loramac_t *mac, bool public)
Enable/disable the public network mode.
void semtech_loramac_get_devaddr(semtech_loramac_t *mac, uint8_t *addr)
Gets the device address.
void semtech_loramac_get_deveui(const semtech_loramac_t *mac, uint8_t *eui)
Gets the device EUI.
uint8_t semtech_loramac_send(semtech_loramac_t *mac, uint8_t *data, uint8_t len)
Sends data to the LoRaWAN network.
bool semtech_loramac_get_adr(semtech_loramac_t *mac)
Checks if adaptive datarate is set.
void semtech_loramac_set_appeui(semtech_loramac_t *mac, const uint8_t *eui)
Sets the application EUI.
void semtech_loramac_set_nwkskey(semtech_loramac_t *mac, const uint8_t *skey)
Sets the network session key.
void semtech_loramac_set_appkey(semtech_loramac_t *mac, const uint8_t *key)
Sets the application key.
void semtech_loramac_set_channels_mask(semtech_loramac_t *mac, uint16_t *mask)
Sets the Channels Mask.
void semtech_loramac_set_tx_mode(semtech_loramac_t *mac, uint8_t mode)
Sets the TX confirmable mode.
int semtech_loramac_init(semtech_loramac_t *mac)
Initializes the semtech loramac mac.
void semtech_loramac_set_dr(semtech_loramac_t *mac, uint8_t dr)
Sets the channels datarate.
uint8_t semtech_loramac_get_dr(semtech_loramac_t *mac)
Gets the channels datarate.
uint32_t semtech_loramac_get_netid(semtech_loramac_t *mac)
Gets the NetID.
void semtech_loramac_set_netid(semtech_loramac_t *mac, uint32_t netid)
Sets the NetID (only useful with ABP join procedure)
void semtech_loramac_get_appskey(semtech_loramac_t *mac, uint8_t *skey)
Gets the application session key.
bool semtech_loramac_is_mac_joined(semtech_loramac_t *mac)
Check if network is already joined.
bool semtech_loramac_get_public_network(semtech_loramac_t *mac)
Checks if public network is set.
void semtech_loramac_set_uplink_counter(semtech_loramac_t *mac, uint32_t counter)
Sets the Uplink Frame Counter.
void semtech_loramac_request_link_check(semtech_loramac_t *mac)
Requests a LoRaWAN link check.
void semtech_loramac_get_channels_mask(semtech_loramac_t *mac, uint16_t *mask)
Gets the Channels Mask.
uint8_t semtech_loramac_get_rx2_dr(semtech_loramac_t *mac)
Gets the RX2 datarate.
void semtech_loramac_set_tx_power(semtech_loramac_t *mac, uint8_t power)
Sets the channels TX power index.
void semtech_loramac_set_rx2_freq(semtech_loramac_t *mac, uint32_t freq)
Sets the RX2 frequency.
void semtech_loramac_set_adr(semtech_loramac_t *mac, bool adr)
Enables/disable adaptive datarate.
void semtech_loramac_set_system_max_rx_error(semtech_loramac_t *mac, uint32_t error)
Sets the maximum system overall timing error for RX (in ms)
Mutex structure.
Definition: mutex.h:39
Structure to hold driver state.
Definition: netdev.h:365
LoRaMAC channel radio parameters.
uint32_t frequency
channel center frequency
uint8_t datarate
channel datarate
Structure containing LoRaWAN RX data.
uint8_t payload_len
Length of the RX payload.
Semtech LoRaMAC descriptor.
uint8_t rx_pid
pid of receiver thread
uint8_t tx_pid
pid of sender thread
uint8_t cnf
enable/disable confirmable messages
mutex_t lock
loramac access lock
netdev_t * netdev
pointer to internal radio device
semtech_loramac_link_check_info_t link_chk
link check information
uint8_t port
application TX port
semtech_loramac_rx_data_t rx_data
struct handling the RX data