Public API and definitions of the Semtech LoRaMAC. More...
Public API and definitions of the Semtech LoRaMAC.
Definition in file semtech_loramac.h.
#include <inttypes.h>
#include "mutex.h"
#include "net/netdev.h"
#include "net/loramac.h"
#include "sx127x.h"
Go to the source code of this file.
Data Structures | |
struct | semtech_loramac_channel_params_t |
LoRaMAC channel radio parameters. More... | |
struct | semtech_loramac_rx_data_t |
Structure containing LoRaWAN RX data. More... | |
struct | semtech_loramac_link_check_info_t |
LoRaMAC link check information. More... | |
struct | semtech_loramac_t |
Semtech LoRaMAC descriptor. More... | |
Macros | |
#define | LORAWAN_APP_DATA_MAX_SIZE (242U) |
Maximum payload size of a LoRaWAN application data. | |
Enumerations | |
enum | { SEMTECH_LORAMAC_JOIN_SUCCEEDED, SEMTECH_LORAMAC_JOIN_FAILED, SEMTECH_LORAMAC_NOT_JOINED, SEMTECH_LORAMAC_ALREADY_JOINED, SEMTECH_LORAMAC_TX_OK, SEMTECH_LORAMAC_TX_SCHEDULE, SEMTECH_LORAMAC_TX_DONE, SEMTECH_LORAMAC_TX_CNF_FAILED, SEMTECH_LORAMAC_TX_ERROR, SEMTECH_LORAMAC_RX_DATA, SEMTECH_LORAMAC_RX_LINK_CHECK, SEMTECH_LORAMAC_RX_CONFIRMED, SEMTECH_LORAMAC_BUSY, SEMTECH_LORAMAC_DUTYCYCLE_RESTRICTED } |
LoRaMAC return status. More... | |
enum | { SEMTECH_LORAMAC_STATE_IDLE = 0, SEMTECH_LORAMAC_STATE_BUSY } |
LoRaMAC internal state. | |
Functions | |
int | semtech_loramac_init (semtech_loramac_t *mac) |
Initializes the semtech loramac mac. More... | |
uint8_t | semtech_loramac_join (semtech_loramac_t *mac, uint8_t type) |
Starts a LoRaWAN network join procedure. More... | |
uint8_t | semtech_loramac_send (semtech_loramac_t *mac, uint8_t *data, uint8_t len) |
Sends data to the LoRaWAN network. More... | |
uint8_t | semtech_loramac_recv (semtech_loramac_t *mac) |
Wait for a message sent by the LoRaWAN network. More... | |
bool | semtech_loramac_is_mac_joined (semtech_loramac_t *mac) |
Check if network is already joined. More... | |
void | semtech_loramac_request_link_check (semtech_loramac_t *mac) |
Requests a LoRaWAN link check. More... | |
void | semtech_loramac_set_deveui (semtech_loramac_t *mac, const uint8_t *eui) |
Sets the device EUI. More... | |
void | semtech_loramac_get_deveui (const semtech_loramac_t *mac, uint8_t *eui) |
Gets the device EUI. More... | |
void | semtech_loramac_set_appeui (semtech_loramac_t *mac, const uint8_t *eui) |
Sets the application EUI. More... | |
void | semtech_loramac_get_appeui (const semtech_loramac_t *mac, uint8_t *eui) |
Gets the application EUI. More... | |
void | semtech_loramac_set_appkey (semtech_loramac_t *mac, const uint8_t *key) |
Sets the application key. More... | |
void | semtech_loramac_get_appkey (const semtech_loramac_t *mac, uint8_t *key) |
Gets the application key. More... | |
void | semtech_loramac_set_appskey (semtech_loramac_t *mac, const uint8_t *skey) |
Sets the application session key. More... | |
void | semtech_loramac_get_appskey (semtech_loramac_t *mac, uint8_t *skey) |
Gets the application session key. More... | |
void | semtech_loramac_set_nwkskey (semtech_loramac_t *mac, const uint8_t *skey) |
Sets the network session key. More... | |
void | semtech_loramac_get_nwkskey (semtech_loramac_t *mac, uint8_t *skey) |
Gets the network session key. More... | |
void | semtech_loramac_set_devaddr (semtech_loramac_t *mac, const uint8_t *addr) |
Sets the device address. More... | |
void | semtech_loramac_get_devaddr (semtech_loramac_t *mac, uint8_t *addr) |
Gets the device address. More... | |
void | semtech_loramac_set_class (semtech_loramac_t *mac, loramac_class_t cls) |
Sets the device class. More... | |
loramac_class_t | semtech_loramac_get_class (semtech_loramac_t *mac) |
Gets the device class. More... | |
void | semtech_loramac_set_dr (semtech_loramac_t *mac, uint8_t dr) |
Sets the channels datarate. More... | |
uint8_t | semtech_loramac_get_dr (semtech_loramac_t *mac) |
Gets the channels datarate. More... | |
void | semtech_loramac_set_adr (semtech_loramac_t *mac, bool adr) |
Enables/disable adaptive datarate. More... | |
bool | semtech_loramac_get_adr (semtech_loramac_t *mac) |
Checks if adaptive datarate is set. More... | |
void | semtech_loramac_set_public_network (semtech_loramac_t *mac, bool public) |
Enable/disable the public network mode. More... | |
bool | semtech_loramac_get_public_network (semtech_loramac_t *mac) |
Checks if public network is set. More... | |
void | semtech_loramac_set_netid (semtech_loramac_t *mac, uint32_t netid) |
Sets the NetID (only useful with ABP join procedure) More... | |
uint32_t | semtech_loramac_get_netid (semtech_loramac_t *mac) |
Gets the NetID. More... | |
void | semtech_loramac_set_tx_power (semtech_loramac_t *mac, uint8_t power) |
Sets the channels TX power index. More... | |
uint8_t | semtech_loramac_get_tx_power (semtech_loramac_t *mac) |
Gets the channels TX power index. More... | |
void | semtech_loramac_set_tx_port (semtech_loramac_t *mac, uint8_t port) |
Sets the TX application port. More... | |
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) More... | |
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. More... | |
uint8_t | semtech_loramac_get_tx_port (semtech_loramac_t *mac) |
Gets the TX application port. More... | |
void | semtech_loramac_set_tx_mode (semtech_loramac_t *mac, uint8_t mode) |
Sets the TX confirmable mode. More... | |
uint8_t | semtech_loramac_get_tx_mode (semtech_loramac_t *mac) |
Gets the TX confirmable mode. More... | |
void | semtech_loramac_set_rx2_freq (semtech_loramac_t *mac, uint32_t freq) |
Sets the RX2 frequency. More... | |
uint32_t | semtech_loramac_get_rx2_freq (semtech_loramac_t *mac) |
Gets the RX2 frequency. More... | |
void | semtech_loramac_set_rx2_dr (semtech_loramac_t *mac, uint8_t dr) |
Sets the RX2 datarate. More... | |
uint8_t | semtech_loramac_get_rx2_dr (semtech_loramac_t *mac) |
Gets the RX2 datarate. More... | |
void | semtech_loramac_set_uplink_counter (semtech_loramac_t *mac, uint32_t counter) |
Sets the Uplink Frame Counter. More... | |
uint32_t | semtech_loramac_get_uplink_counter (semtech_loramac_t *mac) |
Gets the Uplink Frame Counter. More... | |
Definitions for messages exchanged between the MAC and call threads | |
#define | MSG_TYPE_ISR (0x3456) |
radio device ISR | |
#define | MSG_TYPE_RX_TIMEOUT (0x3457) |
radio driver RX timeout | |
#define | MSG_TYPE_TX_TIMEOUT (0x3458) |
radio driver TX timeout | |
#define | MSG_TYPE_MAC_TIMEOUT (0x3459) |
MAC timers timeout. | |
#define | MSG_TYPE_LORAMAC_CMD (0x3460) |
Command sent to the MAC. | |
#define | MSG_TYPE_LORAMAC_JOIN_STATUS (0x3461) |
Join status. | |
#define | MSG_TYPE_LORAMAC_TX_STATUS (0x3462) |
Uplink status. | |
#define | MSG_TYPE_LORAMAC_MLME_CONFIRM (0x3463) |
MAC MLME confirm event. | |
#define | MSG_TYPE_LORAMAC_MLME_INDICATION (0x3464) |
MAC MLME indication event. | |
#define | MSG_TYPE_LORAMAC_MCPS_CONFIRM (0x3465) |
MAC MCPS confirm event. | |
#define | MSG_TYPE_LORAMAC_MCPS_INDICATION (0x3466) |
MAC MCPS indication event. | |
anonymous enum |
LoRaMAC return status.
Definition at line 60 of file semtech_loramac.h.
bool semtech_loramac_get_adr | ( | semtech_loramac_t * | mac | ) |
Checks if adaptive datarate is set.
[in] | mac | Pointer to the mac |
void semtech_loramac_get_appeui | ( | const semtech_loramac_t * | mac, |
uint8_t * | eui | ||
) |
Gets the application EUI.
[in] | mac | Pointer to the mac |
[out] | eui | The application EUI |
void semtech_loramac_get_appkey | ( | const semtech_loramac_t * | mac, |
uint8_t * | key | ||
) |
Gets the application key.
[in] | mac | Pointer to the mac |
[in] | key | The application key |
void semtech_loramac_get_appskey | ( | semtech_loramac_t * | mac, |
uint8_t * | skey | ||
) |
Gets the application session key.
[in] | mac | Pointer to the mac |
[in] | skey | The application session key |
loramac_class_t semtech_loramac_get_class | ( | semtech_loramac_t * | mac | ) |
Gets the device class.
[in] | mac | Pointer to the mac |
void semtech_loramac_get_devaddr | ( | semtech_loramac_t * | mac, |
uint8_t * | addr | ||
) |
Gets the device address.
[in] | mac | Pointer to the mac |
[in] | addr | The device address |
void semtech_loramac_get_deveui | ( | const semtech_loramac_t * | mac, |
uint8_t * | eui | ||
) |
Gets the device EUI.
[in] | mac | Pointer to the mac |
[out] | eui | The device EUI |
uint8_t semtech_loramac_get_dr | ( | semtech_loramac_t * | mac | ) |
Gets the channels datarate.
[in] | mac | Pointer to the mac |
uint32_t semtech_loramac_get_netid | ( | semtech_loramac_t * | mac | ) |
Gets the NetID.
[in] | mac | Pointer to the mac |
void semtech_loramac_get_nwkskey | ( | semtech_loramac_t * | mac, |
uint8_t * | skey | ||
) |
Gets the network session key.
[in] | mac | Pointer to the mac |
[in] | skey | The network session key |
bool semtech_loramac_get_public_network | ( | semtech_loramac_t * | mac | ) |
Checks if public network is set.
[in] | mac | Pointer to the mac |
uint8_t semtech_loramac_get_rx2_dr | ( | semtech_loramac_t * | mac | ) |
Gets the RX2 datarate.
[in] | mac | Pointer to the mac |
uint32_t semtech_loramac_get_rx2_freq | ( | semtech_loramac_t * | mac | ) |
Gets the RX2 frequency.
[in] | mac | Pointer to the mac |
uint8_t semtech_loramac_get_tx_mode | ( | semtech_loramac_t * | mac | ) |
Gets the TX confirmable mode.
[in] | mac | Pointer to the mac |
uint8_t semtech_loramac_get_tx_port | ( | semtech_loramac_t * | mac | ) |
Gets the TX application port.
[in] | mac | Pointer to the mac |
uint8_t semtech_loramac_get_tx_power | ( | semtech_loramac_t * | mac | ) |
Gets the channels TX power index.
[in] | mac | Pointer to the mac |
uint32_t semtech_loramac_get_uplink_counter | ( | semtech_loramac_t * | mac | ) |
Gets the Uplink Frame Counter.
[in] | mac | Pointer to the mac |
int semtech_loramac_init | ( | semtech_loramac_t * | mac | ) |
Initializes the semtech loramac mac.
[in] | mac | Pointer to loramac descriptor |
bool semtech_loramac_is_mac_joined | ( | semtech_loramac_t * | mac | ) |
Check if network is already joined.
[in] | mac | Pointer to the mac |
uint8_t semtech_loramac_join | ( | semtech_loramac_t * | mac, |
uint8_t | type | ||
) |
Starts a LoRaWAN network join procedure.
This function blocks until the join procedure succeeds or fails.
[in] | mac | Pointer to the mac |
[in] | type | The type of join procedure (otaa or abp) |
uint8_t semtech_loramac_recv | ( | semtech_loramac_t * | mac | ) |
Wait for a message sent by the LoRaWAN network.
This function blocks until a single message is received by the mac (RX1 and RX2 windows). With a class A device, a message can only be received after a send. With a class C device, a message can be received at any time. In this case, this function can be used in a dedicated listener thread.
Be sure to call this function before the end of the RX windows otherwise it may block the calling thread.
By default this feature is not available to the user application, enable it by adding USEMODULE += semtech_loramac_rx
to the application Makefile.
[in] | mac | Pointer to the mac |
void semtech_loramac_request_link_check | ( | semtech_loramac_t * | mac | ) |
Requests a LoRaWAN link check.
By default this feature is not available to the user application, enable it by adding USEMODULE += semtech_loramac_rx
to the application Makefile.
[in] | mac | Pointer to the mac |
uint8_t semtech_loramac_send | ( | semtech_loramac_t * | mac, |
uint8_t * | data, | ||
uint8_t | len | ||
) |
Sends data to the LoRaWAN network.
This function returns after TX status is replied from the MAC. To receive potential messages sent from the network an explicit call to semtech_loramac_recv must be done after this function if it returned SEMTECH_LORAMAC_TX_DONE and within the RX windows delays.
[in] | mac | Pointer to the mac |
[in] | data | The TX data |
[in] | len | The length of the TX data |
void semtech_loramac_set_adr | ( | semtech_loramac_t * | mac, |
bool | adr | ||
) |
Enables/disable adaptive datarate.
[in] | mac | Pointer to the mac |
[in] | adr | Adaptive datarate mode |
void semtech_loramac_set_appeui | ( | semtech_loramac_t * | mac, |
const uint8_t * | eui | ||
) |
Sets the application EUI.
[in] | mac | Pointer to the mac |
[in] | eui | The application EUI |
void semtech_loramac_set_appkey | ( | semtech_loramac_t * | mac, |
const uint8_t * | key | ||
) |
Sets the application key.
[in] | mac | Pointer to the mac |
[in] | key | The application key |
void semtech_loramac_set_appskey | ( | semtech_loramac_t * | mac, |
const uint8_t * | skey | ||
) |
Sets the application session key.
[in] | mac | Pointer to the mac |
[in] | skey | The application session key |
void semtech_loramac_set_class | ( | semtech_loramac_t * | mac, |
loramac_class_t | cls | ||
) |
Sets the device class.
[in] | mac | Pointer to the mac |
[in] | cls | The device class |
void semtech_loramac_set_devaddr | ( | semtech_loramac_t * | mac, |
const uint8_t * | addr | ||
) |
Sets the device address.
[in] | mac | Pointer to the mac |
[in] | addr | The device address |
void semtech_loramac_set_deveui | ( | semtech_loramac_t * | mac, |
const uint8_t * | eui | ||
) |
Sets the device EUI.
[in] | mac | Pointer to the mac |
[in] | eui | The device EUI |
void semtech_loramac_set_dr | ( | semtech_loramac_t * | mac, |
uint8_t | dr | ||
) |
Sets the channels datarate.
[in] | mac | Pointer to the mac |
[in] | dr | The datarate (from 1 to 16) |
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.
[in] | mac | Pointer to the mac |
[in] | min_rx | The minimum rx symbols |
void semtech_loramac_set_netid | ( | semtech_loramac_t * | mac, |
uint32_t | netid | ||
) |
Sets the NetID (only useful with ABP join procedure)
[in] | mac | Pointer to the mac |
[in] | netid | The NetID |
void semtech_loramac_set_nwkskey | ( | semtech_loramac_t * | mac, |
const uint8_t * | skey | ||
) |
Sets the network session key.
[in] | mac | Pointer to the mac |
[in] | skey | The network session key |
void semtech_loramac_set_public_network | ( | semtech_loramac_t * | mac, |
bool | public | ||
) |
Enable/disable the public network mode.
[in] | mac | Pointer to the mac |
[in] | public | The public network mode |
void semtech_loramac_set_rx2_dr | ( | semtech_loramac_t * | mac, |
uint8_t | dr | ||
) |
Sets the RX2 datarate.
[in] | mac | Pointer to the mac |
[in] | dr | The RX2 datarate |
void semtech_loramac_set_rx2_freq | ( | semtech_loramac_t * | mac, |
uint32_t | freq | ||
) |
Sets the RX2 frequency.
[in] | mac | Pointer to the mac |
[in] | freq | The RX2 frequency |
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)
[in] | mac | Pointer to the mac |
[in] | error | The maximum rx timing error |
void semtech_loramac_set_tx_mode | ( | semtech_loramac_t * | mac, |
uint8_t | mode | ||
) |
Sets the TX confirmable mode.
[in] | mac | Pointer to the mac |
[in] | mode | The TX mode (confirmable or not confirmable) |
void semtech_loramac_set_tx_port | ( | semtech_loramac_t * | mac, |
uint8_t | port | ||
) |
Sets the TX application port.
[in] | mac | Pointer to the mac |
[in] | port | The TX application port |
void semtech_loramac_set_tx_power | ( | semtech_loramac_t * | mac, |
uint8_t | power | ||
) |
Sets the channels TX power index.
[in] | mac | Pointer to the mac |
[in] | power | The TX power index (from 1 to 16) |
void semtech_loramac_set_uplink_counter | ( | semtech_loramac_t * | mac, |
uint32_t | counter | ||
) |
Sets the Uplink Frame Counter.
[in] | mac | Pointer to the mac |
[in] | counter | Frame counter to set |