Loading...
Searching...
No Matches
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
19#ifndef SEMTECH_LORAMAC_H
20#define SEMTECH_LORAMAC_H
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
26#include <inttypes.h>
27
28#include "mutex.h"
29
30#include "net/netdev.h"
31#include "net/loramac.h"
32
37#define MSG_TYPE_ISR (0x3456)
38#define MSG_TYPE_RX_TIMEOUT (0x3457)
39#define MSG_TYPE_TX_TIMEOUT (0x3458)
40#define MSG_TYPE_MAC_TIMEOUT (0x3459)
41#define MSG_TYPE_LORAMAC_CMD (0x3460)
42#define MSG_TYPE_LORAMAC_JOIN_STATUS (0x3461)
43#define MSG_TYPE_LORAMAC_TX_STATUS (0x3462)
44#define MSG_TYPE_LORAMAC_MLME_CONFIRM (0x3463)
45#define MSG_TYPE_LORAMAC_MLME_INDICATION (0x3464)
46#define MSG_TYPE_LORAMAC_MCPS_CONFIRM (0x3465)
47#define MSG_TYPE_LORAMAC_MCPS_INDICATION (0x3466)
53#define LORAWAN_APP_DATA_MAX_SIZE (242U)
54
58enum {
73};
74
78enum {
79 SEMTECH_LORAMAC_STATE_IDLE = 0,
80 SEMTECH_LORAMAC_STATE_BUSY
81};
82
86typedef struct {
87 uint32_t frequency;
88 uint8_t datarate;
90
94typedef struct {
95 uint8_t payload[LORAWAN_APP_DATA_MAX_SIZE];
96 uint8_t payload_len;
97 uint8_t port;
99
100#if defined(MODULE_SEMTECH_LORAMAC_RX) || DOXYGEN
108#endif
109
113typedef struct {
116 uint8_t tx_pid;
117#if defined(MODULE_SEMTECH_LORAMAC_RX) || DOXYGEN
118 uint8_t rx_pid;
119#endif
120 uint8_t port;
121 uint8_t cnf;
122 uint8_t deveui[LORAMAC_DEVEUI_LEN];
123 uint8_t appeui[LORAMAC_APPEUI_LEN];
124 uint8_t appkey[LORAMAC_APPKEY_LEN];
125#if defined(MODULE_SEMTECH_LORAMAC_RX) || DOXYGEN
128#endif
130
140
154uint8_t semtech_loramac_join(semtech_loramac_t *mac, uint8_t type);
155
177uint8_t semtech_loramac_send(semtech_loramac_t *mac, uint8_t *data, uint8_t len);
178
179#if defined(MODULE_SEMTECH_LORAMAC_RX) || DOXYGEN
204#endif
205
214
215#if defined(MODULE_SEMTECH_LORAMAC_RX) || DOXYGEN
225#endif
226
233void semtech_loramac_set_deveui(semtech_loramac_t *mac, const uint8_t *eui);
234
241void semtech_loramac_get_deveui(const semtech_loramac_t *mac, uint8_t *eui);
242
249void semtech_loramac_set_appeui(semtech_loramac_t *mac, const uint8_t *eui);
250
257void semtech_loramac_get_appeui(const semtech_loramac_t *mac, uint8_t *eui);
258
265void semtech_loramac_set_appkey(semtech_loramac_t *mac, const uint8_t *key);
266
273void semtech_loramac_get_appkey(const semtech_loramac_t *mac, uint8_t *key);
274
281void semtech_loramac_set_appskey(semtech_loramac_t *mac, const uint8_t *skey);
282
290
297void semtech_loramac_set_nwkskey(semtech_loramac_t *mac, const uint8_t *skey);
298
306
313void semtech_loramac_set_devaddr(semtech_loramac_t *mac, const uint8_t *addr);
314
322
330
338
346
354
362
370
378
386
394
402
410
418
426
434
442
450
458
466
474
482
490
498
506
514
522
530
531#ifdef MODULE_PERIPH_EEPROM
535#ifndef SEMTECH_LORAMAC_EEPROM_MAGIC
536#define SEMTECH_LORAMAC_EEPROM_MAGIC {0x52, 0x49, 0x4F, 0x54} /* RIOT */
537#endif
538
542#ifndef SEMTECH_LORAMAC_EEPROM_MAGIC_LEN
543#define SEMTECH_LORAMAC_EEPROM_MAGIC_LEN 4
544#endif
545
549#ifndef SEMTECH_LORAMAC_EEPROM_START
550#define SEMTECH_LORAMAC_EEPROM_START (0)
551#endif
552
558void semtech_loramac_save_config(semtech_loramac_t *mac);
559
563void semtech_loramac_erase_config(void);
564#endif
565
566#ifdef __cplusplus
567}
568#endif
569
570#endif /* SEMTECH_LORAMAC_H */
Definitions low-level network driver interface.
#define LORAMAC_APPKEY_LEN
Application key length in bytes.
Definition loramac.h:570
#define LORAMAC_APPEUI_LEN
Application EUI length in bytes.
Definition loramac.h:560
#define LORAMAC_DEVEUI_LEN
Device EUI length in bytes.
Definition loramac.h:550
loramac_class_t
Device class.
Definition loramac.h:663
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.
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.
@ 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.
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:146
Structure to hold driver state.
Definition netdev.h:362
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