PicoWAN SDK Documentation
mac.h
Go to the documentation of this file.
1 
32 #ifndef _MAC_H_
33 #define _MAC_H_
34 
35 #include <stdint.h>
36 
37 #define MAC_PORT_MAC_COMMAND 0
38 #define MAC_PORT_FIRST_APP 1
39 
40 typedef enum {
41  UNDEF_MAC = -1,
42  PICOMAC = 0,
43  LORAMAC = 1,
44 } mac_type_t;
45 
46 typedef enum {
48  DL_ENABLED = 1,
50 
51 enum ack_status {
52  UNDEF_ACK,
53  NO_ACK,
54  ACK
55 };
56 
57 typedef enum e_device_class {
58  CLASS_A,
59  CLASS_B,
60  CLASS_C,
61 } device_class_t;
62 
63 
64 typedef enum {
71 } mac_state_t;
72 
73 typedef enum {
85 
86 typedef enum {
91 
92 typedef enum {
102 } mac_status_t;
103 
107 typedef struct {
108  mac_info_status_t status;
109  enum ack_status ack_status;
110  uint8_t nb_retries;
111 } mac_tx_info_t;
112 
116 typedef struct {
117  mac_info_status_t status;
118  uint8_t port;
119  uint8_t *payload;
120  uint8_t payload_len;
121  int16_t rssi;
122  int8_t snr;
123 } mac_rx_info_t;
124 
128 typedef struct {
129  mac_network_status_t status;
131 
136 typedef struct {
142  void (*mac_tx_done)(mac_tx_info_t *info);
143 
149  void (*mac_rx_done)(mac_rx_info_t *info);
150 
156  void (*mac_network_state)(mac_network_info_t *info);
157 
163  void (*mac_state)(mac_state_t state);
164 
166 
167 typedef struct {
176  uint8_t (*get_battery_level)(void);
178 
179 typedef struct {
185  uint32_t (*get_uplink_counter)(void);
186 
190  void (*save_uplink_counter)(uint32_t uplink_counter);
191 
197  uint32_t (*get_downlink_counter)(void);
198 
202  void (*save_downlink_counter)(uint32_t downlink_counter);
204 
205 
235 
245 
262 mac_status_t mac_init_activation_personalization(uint32_t netid, uint32_t devaddr, uint8_t *nwkskey, uint8_t *appskey);
263 
281 mac_status_t mac_init_activation_on_air(uint8_t *dev_eui, uint8_t *app_eui, uint8_t *app_key);
282 
297 mac_status_t mac_send_when_possible(uint8_t port, uint8_t *payload, uint8_t payload_len, downlink_mode_t dl_mode);
298 
315 mac_status_t mac_send_when_possible_confirmed(uint8_t port, uint8_t *payload, uint8_t payload_len, uint8_t nb_retries, downlink_mode_t dl_mode);
316 
327 
341 mac_status_t mac_set_device_class(device_class_t device_class);
342 
351 mac_status_t mac_get_device_address(uint32_t *device_address);
352 
361 uint16_t mac_message_max_payload_length(void);
362 
369 
370 #endif /* _MAC_H_ */
MAC receive information.
Definition: mac.h:116
mac_status_t mac_init_activation_personalization(uint32_t netid, uint32_t devaddr, uint8_t *nwkskey, uint8_t *appskey)
Initiates the Activation By Personalization (ABP). The session keys must be provided.
Definition: mac.c:93
uint8_t * payload
pointer to received message
Definition: mac.h:119
MAC is waiting an acknowledge.
Definition: mac.h:68
mac_status_t
Definition: mac.h:92
Message header error.
Definition: mac.h:99
MAC is not set.
Definition: mac.h:41
mac_info_status_t
Definition: mac.h:73
Do not wait for downlink.
Definition: mac.h:47
MAC events structure. Used to notify upper layers after each MAC events done.
Definition: mac.h:136
MAC network state information.
Definition: mac.h:128
Message length error.
Definition: mac.h:98
The device is switched off by software (LoRaWAN only)
Definition: mac.h:94
mac_status_t mac_get_device_address(uint32_t *device_address)
Gets device address.
Definition: mac.c:173
MAC is sending data.
Definition: mac.h:67
Too much time to receive a beacon.
Definition: mac.h:80
uint8_t payload_len
length of the message
Definition: mac.h:120
PicoWAN protocol.
Definition: mac.h:42
downlink_mode_t
Definition: mac.h:46
No problem.
Definition: mac.h:82
Definition: mac.h:179
mac_status_t mac_deinit(void)
Deinitializes the MAC.
Definition: mac.c:77
Network unavailable.
Definition: mac.h:87
Payload length exceed the maximum size allowed.
Definition: mac.h:78
Network unknown.
Definition: mac.h:89
MAC not initialized.
Definition: mac.h:97
uint16_t mac_message_max_payload_length(void)
Returns maximum allowed bytes for user payload.
Definition: mac.c:187
Function not implemented for this MAC.
Definition: mac.h:96
Message successfully sent.
Definition: mac.h:101
LoRaWAN protocol.
Definition: mac.h:43
Network is joined.
Definition: mac.h:83
No message received.
Definition: mac.h:76
Impossible to send a message because the network has not been joined.
Definition: mac.h:100
int8_t snr
received signal to noise ratio in dB
Definition: mac.h:122
mac_type_t
Definition: mac.h:40
mac_status_t mac_send_when_possible_confirmed(uint8_t port, uint8_t *payload, uint8_t payload_len, uint8_t nb_retries, downlink_mode_t dl_mode)
Sends data with acknowledge.
Definition: mac.c:133
mac_network_status_t
Definition: mac.h:86
Network available.
Definition: mac.h:88
The MAC has nothing to send.
Definition: mac.h:93
Definition: mac.h:167
Problem while decoding the received message.
Definition: mac.h:75
mac_status_t mac_init(mac_type_t mac, mac_message_callbacks_t *cb, mac_battery_callback_t *battery_cb, mac_flash_callback_t *flash_cbs)
Initializes the MAC.
Definition: mac.c:45
The MAC cannot send right now due to duty cycle limitation.
Definition: mac.h:74
Too much time waiting for TX acknowledge.
Definition: mac.h:81
mac_type_t mac_get_stack(void)
Returns the stack in use.
Definition: mac.c:192
mac_status_t mac_set_device_class(device_class_t device_class)
Sets end-device class. (class A, B or C for LoRaWAN, A or C for PicoWAN)
Definition: mac.c:159
The MAC is busy doing something.
Definition: mac.h:95
Message with the wrong MIC.
Definition: mac.h:79
MAC is waiting to retry.
Definition: mac.h:69
int16_t rssi
received signal strength in dBm
Definition: mac.h:121
mac_state_t
Definition: mac.h:64
Problem in the reception.
Definition: mac.h:77
MAC is in an idle state.
Definition: mac.h:65
MAC is searching network.
Definition: mac.h:66
MAC transmit information.
Definition: mac.h:107
Wait for downlink.
Definition: mac.h:48
uint8_t port
MAC port the message is send to (1..223, while 0 is used for MAC commands)
Definition: mac.h:118
mac_status_t mac_send_when_possible(uint8_t port, uint8_t *payload, uint8_t payload_len, downlink_mode_t dl_mode)
Sends data without acknowledge.
Definition: mac.c:120
mac_status_t mac_init_activation_on_air(uint8_t *dev_eui, uint8_t *app_eui, uint8_t *app_key)
Initiates the Over The Air Activation (OTAA). Sends a request with the device and application EUI...
Definition: mac.c:107
mac_status_t mac_network_available(void)
Reports network availability using callback. It corresponds to the LoRaWAN MAC command Link Check Req...
Definition: mac.c:146
MAC is waiting data.
Definition: mac.h:70