Loading...
Searching...
No Matches
semtech_loramac.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2017 Inria
3 * SPDX-License-Identifier: LGPL-2.1-only
4 */
5
6#pragma once
7
17
18#ifdef __cplusplus
19extern "C" {
20#endif
21
22#include <inttypes.h>
23
24#include "mutex.h"
25
26#include "net/netdev.h"
27#include "net/loramac.h"
28
33#define MSG_TYPE_ISR (0x3456)
34#define MSG_TYPE_RX_TIMEOUT (0x3457)
35#define MSG_TYPE_TX_TIMEOUT (0x3458)
36#define MSG_TYPE_MAC_TIMEOUT (0x3459)
37#define MSG_TYPE_LORAMAC_CMD (0x3460)
38#define MSG_TYPE_LORAMAC_JOIN_STATUS (0x3461)
39#define MSG_TYPE_LORAMAC_TX_STATUS (0x3462)
40#define MSG_TYPE_LORAMAC_MLME_CONFIRM (0x3463)
41#define MSG_TYPE_LORAMAC_MLME_INDICATION (0x3464)
42#define MSG_TYPE_LORAMAC_MCPS_CONFIRM (0x3465)
43#define MSG_TYPE_LORAMAC_MCPS_INDICATION (0x3466)
45
49#define LORAWAN_APP_DATA_MAX_SIZE (242U)
50
54enum {
69};
70
74enum {
75 SEMTECH_LORAMAC_STATE_IDLE = 0,
76 SEMTECH_LORAMAC_STATE_BUSY
77};
78
82typedef struct {
83 uint32_t frequency;
84 uint8_t datarate;
86
95
96#if defined(MODULE_SEMTECH_LORAMAC_RX) || DOXYGEN
104#endif
105
109typedef struct {
112 uint8_t tx_pid;
113#if defined(MODULE_SEMTECH_LORAMAC_RX) || DOXYGEN
114 uint8_t rx_pid;
115#endif
116 uint8_t port;
117 uint8_t cnf;
121#if defined(MODULE_SEMTECH_LORAMAC_RX) || DOXYGEN
124#endif
126
136
150uint8_t semtech_loramac_join(semtech_loramac_t *mac, uint8_t type);
151
173uint8_t semtech_loramac_send(semtech_loramac_t *mac, uint8_t *data, uint8_t len);
174
175#if defined(MODULE_SEMTECH_LORAMAC_RX) || DOXYGEN
200#endif
201
210
211#if defined(MODULE_SEMTECH_LORAMAC_RX) || DOXYGEN
221#endif
222
229void semtech_loramac_set_deveui(semtech_loramac_t *mac, const uint8_t *eui);
230
237void semtech_loramac_get_deveui(const semtech_loramac_t *mac, uint8_t *eui);
238
245void semtech_loramac_set_appeui(semtech_loramac_t *mac, const uint8_t *eui);
246
253void semtech_loramac_get_appeui(const semtech_loramac_t *mac, uint8_t *eui);
254
261void semtech_loramac_set_appkey(semtech_loramac_t *mac, const uint8_t *key);
262
269void semtech_loramac_get_appkey(const semtech_loramac_t *mac, uint8_t *key);
270
277void semtech_loramac_set_appskey(semtech_loramac_t *mac, const uint8_t *skey);
278
286
293void semtech_loramac_set_nwkskey(semtech_loramac_t *mac, const uint8_t *skey);
294
302
309void semtech_loramac_set_devaddr(semtech_loramac_t *mac, const uint8_t *addr);
310
318
326
334
342
350
358
366
374
382
390
398
406
414
422
430
438
446
454
462
470
478
486
494
502
510
518
526
527#ifdef MODULE_PERIPH_EEPROM
531#ifndef SEMTECH_LORAMAC_EEPROM_MAGIC
532#define SEMTECH_LORAMAC_EEPROM_MAGIC {0x52, 0x49, 0x4F, 0x54} /* RIOT */
533#endif
534
538#ifndef SEMTECH_LORAMAC_EEPROM_MAGIC_LEN
539#define SEMTECH_LORAMAC_EEPROM_MAGIC_LEN 4
540#endif
541
545#ifndef SEMTECH_LORAMAC_EEPROM_START
546#define SEMTECH_LORAMAC_EEPROM_START (0)
547#endif
548
554void semtech_loramac_save_config(semtech_loramac_t *mac);
555
559void semtech_loramac_erase_config(void);
560#endif
561
562#ifdef __cplusplus
563}
564#endif
565
Definitions low-level network driver interface.
struct netdev netdev_t
Forward declaration for netdev struct.
Definition netdev.h:285
#define LORAMAC_APPKEY_LEN
Application key length in bytes.
Definition loramac.h:566
#define LORAMAC_APPEUI_LEN
Application EUI length in bytes.
Definition loramac.h:556
#define LORAMAC_DEVEUI_LEN
Device EUI length in bytes.
Definition loramac.h:546
loramac_class_t
Device class.
Definition loramac.h:659
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.
@ 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.
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:36
LoRaMAC channel radio parameters.
uint32_t frequency
channel center frequency
uint8_t datarate
channel datarate
Structure containing LoRaWAN RX data.
uint8_t payload[LORAWAN_APP_DATA_MAX_SIZE]
RX payload buffer.
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
uint8_t appkey[LORAMAC_APPKEY_LEN]
application key
uint8_t deveui[LORAMAC_DEVEUI_LEN]
device EUI
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
uint8_t appeui[LORAMAC_APPEUI_LEN]
application EUI