Merge pull request #6808 from hasnainvirk/state_machine_work

LoRa: State machine work
pull/6856/head
Martin Kojtal 2018-05-09 16:02:53 +01:00 committed by GitHub
commit b5a8ace79a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
30 changed files with 1840 additions and 1818 deletions

View File

@ -154,7 +154,7 @@ typedef struct radio_events {
* FSK : N/A (set to 0)
* LoRa: SNR value in dB
*/
mbed::Callback<void(uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr)> rx_done;
mbed::Callback<void(const uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr)> rx_done;
/**
* Callback when Reception is timed out

View File

@ -301,9 +301,9 @@ public:
* lorawan.connect();
* }
*
* static void my_event_handler(lora_events_t events)
* static void my_event_handler(lorawan_event_t event)
* {
* switch(events) {
* switch(event) {
* case CONNECTED:
* //do something
* break;

View File

@ -34,95 +34,114 @@ LoRaWANInterface::~LoRaWANInterface()
lorawan_status_t LoRaWANInterface::initialize(EventQueue *queue)
{
Lock lock(*this);
return _lw_stack.initialize_mac_layer(queue);
}
lorawan_status_t LoRaWANInterface::connect()
{
Lock lock(*this);
return _lw_stack.connect();
}
lorawan_status_t LoRaWANInterface::connect(const lorawan_connect_t &connect)
{
Lock lock(*this);
return _lw_stack.connect(connect);
}
lorawan_status_t LoRaWANInterface::disconnect()
{
Lock lock(*this);
return _lw_stack.shutdown();
}
lorawan_status_t LoRaWANInterface::add_link_check_request()
{
Lock lock(*this);
return _lw_stack.set_link_check_request();
}
void LoRaWANInterface::remove_link_check_request()
{
Lock lock(*this);
_lw_stack.remove_link_check_request();
}
lorawan_status_t LoRaWANInterface::set_datarate(uint8_t data_rate)
{
Lock lock(*this);
return _lw_stack.set_channel_data_rate(data_rate);
}
lorawan_status_t LoRaWANInterface::set_confirmed_msg_retries(uint8_t count)
{
Lock lock(*this);
return _lw_stack.set_confirmed_msg_retry(count);
}
lorawan_status_t LoRaWANInterface::enable_adaptive_datarate()
{
Lock lock(*this);
return _lw_stack.enable_adaptive_datarate(true);
}
lorawan_status_t LoRaWANInterface::disable_adaptive_datarate()
{
Lock lock(*this);
return _lw_stack.enable_adaptive_datarate(false);
}
lorawan_status_t LoRaWANInterface::set_channel_plan(const lorawan_channelplan_t &channel_plan)
{
Lock lock(*this);
return _lw_stack.add_channels(channel_plan);
}
lorawan_status_t LoRaWANInterface::get_channel_plan(lorawan_channelplan_t &channel_plan)
{
Lock lock(*this);
return _lw_stack.get_enabled_channels(channel_plan);
}
lorawan_status_t LoRaWANInterface::remove_channel(uint8_t id)
{
Lock lock(*this);
return _lw_stack.remove_a_channel(id);
}
lorawan_status_t LoRaWANInterface::remove_channel_plan()
{
Lock lock(*this);
return _lw_stack.drop_channel_list();
}
int16_t LoRaWANInterface::send(uint8_t port, const uint8_t* data, uint16_t length, int flags)
{
Lock lock(*this);
return _lw_stack.handle_tx(port, data, length, flags);
}
int16_t LoRaWANInterface::receive(uint8_t port, uint8_t* data, uint16_t length, int flags)
{
Lock lock(*this);
return _lw_stack.handle_rx(data, length, port, flags, true);
}
int16_t LoRaWANInterface::receive(uint8_t* data, uint16_t length, uint8_t& port, int& flags)
{
Lock lock(*this);
return _lw_stack.handle_rx(data, length, port, flags, false);
}
lorawan_status_t LoRaWANInterface::add_app_callbacks(lorawan_app_callbacks_t *callbacks)
{
Lock lock(*this);
return _lw_stack.set_lora_callbacks(callbacks);
}
lorawan_status_t LoRaWANInterface::set_device_class(const device_class_t device_class)
{
Lock lock(*this);
return _lw_stack.set_device_class(device_class);
}

View File

@ -19,6 +19,7 @@
#define LORAWANINTERFACE_H_
#include "platform/Callback.h"
#include "platform/ScopedLock.h"
#include "LoRaWANStack.h"
#include "LoRaRadio.h"
#include "LoRaWANBase.h"
@ -398,9 +399,9 @@ public:
* lorawan.connect();
* }
*
* static void my_event_handler(lora_events_t events)
* static void my_event_handler(lorawan_event_t event)
* {
* switch(events) {
* switch(event) {
* case CONNECTED:
* //do something
* break;
@ -435,7 +436,13 @@ public:
*/
virtual lorawan_status_t set_device_class(const device_class_t device_class);
void lock(void) { _lw_stack.lock(); }
void unlock(void) { _lw_stack.unlock(); }
private:
typedef mbed::ScopedLock<LoRaWANInterface> Lock;
LoRaWANStack _lw_stack;
};

File diff suppressed because it is too large Load Diff

View File

@ -44,6 +44,7 @@
#include "events/EventQueue.h"
#include "platform/Callback.h"
#include "platform/NonCopyable.h"
#include "platform/ScopedLock.h"
#include "lorastack/mac/LoRaMac.h"
#include "system/LoRaWANTimer.h"
@ -51,23 +52,6 @@
#include "LoRaRadio.h"
class LoRaWANStack: private mbed::NonCopyable<LoRaWANStack> {
private:
/** End-device states.
*
*/
typedef enum device_states {
DEVICE_STATE_NOT_INITIALIZED,
DEVICE_STATE_INIT,
DEVICE_STATE_JOINING,
DEVICE_STATE_ABP_CONNECTING,
DEVICE_STATE_JOINED,
DEVICE_STATE_SEND,
DEVICE_STATE_IDLE,
#if defined(LORAWAN_COMPLIANCE_TEST)
DEVICE_STATE_COMPLIANCE_TEST,
#endif
DEVICE_STATE_SHUTDOWN
} device_states_t;
public:
LoRaWANStack();
@ -85,6 +69,19 @@ public:
*/
void bind_radio_driver(LoRaRadio& radio);
/** End device initialization.
* @param queue A pointer to an EventQueue passed from the application.
* @return LORAWAN_STATUS_OK on success, a negative error code on failure.
*/
lorawan_status_t initialize_mac_layer(events::EventQueue *queue);
/** Sets all callbacks for the application.
*
* @param callbacks A pointer to the structure carrying callbacks.
* @return LORAWAN_STATUS_OK on success, a negative error code on failure.
*/
lorawan_status_t set_lora_callbacks(const lorawan_app_callbacks_t *callbacks);
/** Connect OTAA or ABP using Mbed-OS config system
*
* Connect by Over The Air Activation or Activation By Personalization.
@ -162,19 +159,6 @@ public:
*/
lorawan_status_t connect(const lorawan_connect_t &connect);
/** End device initialization.
* @param queue A pointer to an EventQueue passed from the application.
* @return LORAWAN_STATUS_OK on success, a negative error code on failure.
*/
lorawan_status_t initialize_mac_layer(events::EventQueue *queue);
/** Sets all callbacks for the application.
*
* @param callbacks A pointer to the structure carrying callbacks.
* @return LORAWAN_STATUS_OK on success, a negative error code on failure.
*/
lorawan_status_t set_lora_callbacks(lorawan_app_callbacks_t *callbacks);
/** Adds channels to use.
*
* You can provide a list of channels with appropriate parameters filled
@ -395,7 +379,11 @@ public:
*/
lorawan_status_t set_device_class(const device_class_t& device_class);
void lock(void) { _loramac.lock(); }
void unlock(void) { _loramac.unlock(); }
private:
typedef mbed::ScopedLock<LoRaWANStack> Lock;
/**
* Checks if the user provided port is valid or not
*/
@ -404,37 +392,40 @@ private:
/**
* State machine for stack controller layer.
*/
lorawan_status_t lora_state_machine(device_states_t new_state);
lorawan_status_t state_controller(device_states_t new_state);
/**
* Callback function for MLME indication. Mac layer calls this function once
* an MLME indication is received. This method translates Mac layer data
* structure into stack layer data structure.
* Helpers for state controller
*/
void mlme_indication_handler(loramac_mlme_indication_t *mlmeIndication);
void process_uninitialized_state(lorawan_status_t& op_status);
void process_idle_state(lorawan_status_t& op_status);
void process_connected_state();
void process_connecting_state(lorawan_status_t& op_status);
void process_joining_state(lorawan_status_t& op_status);
void process_scheduling_state(lorawan_status_t& op_status);
void process_status_check_state();
void process_shutdown_state(lorawan_status_t& op_status);
void state_machine_run_to_completion(void);
/**
* Handles an MLME confirmation coming from the Mac layer and uses it to
* update the state for example, a Join Accept triggers an MLME confirmation,
* that eventually comes here and we take necessary steps accordingly.
* Handles MLME indications
*/
void mlme_confirm_handler(loramac_mlme_confirm_t *mlme_confirm);
void mlme_indication_handler(void);
/**
* Handles an MCPS confirmation coming from the Mac layer in response to an
* MCPS request. We take appropriate actions in response to the confirmation,
* e.g., letting the application know that ack was not received in case of
* a CONFIRMED message or scheduling error etc.
* Handles an MLME confirmation
*/
void mcps_confirm_handler(loramac_mcps_confirm_t *mcps_confirm);
void mlme_confirm_handler(void);
/**
* Handles an MCPS indication coming from the Mac layer, e.g., once we
* receive a packet from the Network Server, it is indicated to this handler
* and consequently this handler posts an event to the application that
* there is something available to read.
* Handles an MCPS confirmation
*/
void mcps_indication_handler(loramac_mcps_indication_t *mcps_indication);
void mcps_confirm_handler(void);
/**
* Handles an MCPS indication
*/
void mcps_indication_handler(void);
/**
* Sets up user application port
@ -459,21 +450,44 @@ private:
*
* @param port The event to be sent.
*/
void send_automatic_uplink_message(const uint8_t port);
void send_automatic_uplink_message(uint8_t port);
/**
* TX interrupt handlers and corresponding processors
*/
void tx_interrupt_handler(void);
void tx_timeout_interrupt_handler(void);
void process_transmission(void);
void process_transmission_timeout(void);
/**
* RX interrupt handlers and corresponding processors
*/
void rx_interrupt_handler(const uint8_t *payload, uint16_t size, int16_t rssi,
int8_t snr);
void rx_timeout_interrupt_handler(void);
void rx_error_interrupt_handler(void);
void process_reception(const uint8_t *payload, uint16_t size, int16_t rssi,
int8_t snr);
void process_reception_timeout(bool is_timeout);
int convert_to_msg_flag(const mcps_type_t type);
private:
LoRaMac _loramac;
loramac_primitives_t LoRaMacPrimitives;
radio_events_t radio_events;
device_states_t _device_current_state;
lorawan_app_callbacks_t _callbacks;
lorawan_session_t _lw_session;
loramac_tx_message_t _tx_msg;
loramac_rx_message_t _rx_msg;
uint8_t _num_retry;
uint32_t _ctrl_flags;
uint8_t _app_port;
bool _link_check_requested;
bool _automatic_uplink_ongoing;
volatile bool _ready_for_rx;
uint8_t _rx_payload[LORAMAC_PHY_MAXPAYLOAD];
events::EventQueue *_queue;
#if defined(LORAWAN_COMPLIANCE_TEST)

File diff suppressed because it is too large Load Diff

View File

@ -51,7 +51,11 @@
#include "LoRaMacChannelPlan.h"
#include "LoRaMacCommand.h"
#include "LoRaMacCrypto.h"
#if MBED_CONF_RTOS_PRESENT
#include "rtos/Mutex.h"
#endif
#include "platform/ScopedLock.h"
class LoRaMac {
@ -70,13 +74,8 @@ public:
/**
* @brief LoRaMAC layer initialization
*
* @details In addition to the initialization of the LoRaMAC layer, this
* function initializes the callback primitives of the MCPS and
* MLME services. Every data field of \ref loramac_primitives_t must be
* set to a valid callback function.
* @details Initializes the LoRaMAC layer,
*
* @param primitives [in] A pointer to the structure defining the LoRaMAC
* event functions. Refer to \ref loramac_primitives_t.
*
* @param queue [in] A pointer to the application provided EventQueue.
*
@ -84,8 +83,7 @@ public:
* \ref LORAWAN_STATUS_OK
* \ref LORAWAN_STATUS_PARAMETER_INVALID
*/
lorawan_status_t initialize(loramac_primitives_t *primitives,
events::EventQueue *queue);
lorawan_status_t initialize(events::EventQueue *queue);
/**
* @brief Disconnect LoRaMac layer
@ -246,8 +244,8 @@ public:
* of success and a negative error code in case of
* failure.
*/
lorawan_status_t send(loramac_mhdr_t *mac_hdr, uint8_t fport, void *fbuffer,
uint16_t fbuffer_size);
lorawan_status_t send(loramac_mhdr_t *mac_hdr, const uint8_t fport,
const void *fbuffer, uint16_t fbuffer_size);
/**
* @brief Puts the system in continuous transmission mode
@ -280,12 +278,6 @@ public:
*/
void reset_mac_parameters(void);
/**
* @brief Opens up a continuous RX 2 window. This is used for
* class c devices.
*/
void open_continuous_rx2_window(void);
/**
* @brief get_default_tx_datarate Gets the default TX datarate
* @return default TX datarate.
@ -341,14 +333,14 @@ public:
* @param num_retries Number of retries for a confirmed type message
* @return The number of bytes prepared for sending.
*/
int16_t prepare_ongoing_tx(uint8_t port, const uint8_t* data,
int16_t prepare_ongoing_tx(const uint8_t port, const uint8_t* data,
uint16_t length, uint8_t flags, uint8_t num_retries);
/**
* @brief send_ongoing_tx Sends the ongoing_tx_msg
* @return LORAWAN_STATUS_OK or a negative error code on failure.
*/
lorawan_status_t send_ongoing_tx();
lorawan_status_t send_ongoing_tx(void);
/**
* @brief device_class Returns active device class
@ -362,6 +354,11 @@ public:
*/
void set_device_class(const device_class_t& device_class);
/**
* @brief opens a continuous RX2 window for Class C devices
*/
void open_continuous_rx_window(void);
/**
* @brief setup_link_check_request Adds link check request command
* to be put on next outgoing message (when it fits)
@ -384,59 +381,153 @@ public:
*/
lorawan_status_t join(bool is_otaa);
private:
/**
* Function to be executed on Radio Tx Done event
* MAC operations upon successful transmission
*/
void on_radio_tx_done(void);
/**
* This function prepares the MAC to abort the execution of function
* on_radio_rx_done() in case of a reception error.
* MAC operations upon reception
*/
void prepare_rx_done_abort(void);
void on_radio_rx_done(const uint8_t* const payload, uint16_t size,
int16_t rssi, int8_t snr);
/**
* Function to be executed on Radio Rx Done event
*/
void on_radio_rx_done(uint8_t *payload, uint16_t size, int16_t rssi,
int8_t snr);
/**
* Function executed on Radio Tx Timeout event
* MAC operations upon transmission timeout
*/
void on_radio_tx_timeout(void);
/**
* Function executed on Radio Rx error event
* MAC operations upon empty reception slots
*
* @param is_timeout false when radio encountered an error
* true when the an RX slot went empty
*
* @return current RX slot
*/
void on_radio_rx_error(void);
rx_slot_t on_radio_rx_timeout(bool is_timeout);
/**
* Function executed on Radio Rx Timeout event
* Handles retransmissions of Join requests if an Accept
* was not received.
*
* @returns true if a retry will be made
*/
void on_radio_rx_timeout(void);
bool continue_joining_process(void);
/**
*Function executed on Resend Frame timer event.
* Checks if the CONFIRMED data can be sent again or not.
*/
void on_mac_state_check_timer_event(void);
bool continue_sending_process(void);
/**
* Function executed on duty cycle delayed Tx timer event
* Read-only access to MAC primitive blocks
*/
void on_tx_delayed_timer_event(void);
const loramac_mcps_confirm_t *get_mcps_confirmation() const;
const loramac_mcps_indication_t *get_mcps_indication() const;
const loramac_mlme_confirm_t *get_mlme_confirmation() const;
const loramac_mlme_indication_t *get_mlme_indication() const;
/**
* Function executed on first Rx window timer event
* Post processing steps in response to actions carried out
* by controller layer and Mac
*/
void on_rx_window1_timer_event(void);
void post_process_mcps_req(void);
void post_process_mcps_ind(void);
void post_process_mlme_request(void);
void post_process_mlme_ind(void);
/**
* Function executed on second Rx window timer event
* These locks trample through to the upper layers and make
* the stack thread safe.
*/
void on_rx_window2_timer_event(void);
#if MBED_CONF_RTOS_PRESENT
void lock(void) { osStatus status = _mutex.lock(); MBED_ASSERT(status == osOK); }
void unlock(void) { osStatus status = _mutex.unlock(); MBED_ASSERT(status == osOK); }
#else
void lock(void) { }
void unlock(void) { }
#endif
private:
typedef mbed::ScopedLock<LoRaMac> Lock;
#if MBED_CONF_RTOS_PRESENT
rtos::Mutex _mutex;
#endif
/**
* Aborts reception
*/
void abort_rx(void);
/**
* Handles a Join Accept frame
*/
void handle_join_accept_frame(const uint8_t *payload, uint16_t size);
/**
* Handles data frames
*/
void handle_data_frame(const uint8_t *payload, uint16_t size, uint8_t ptr_pos,
uint8_t msg_type, int16_t rssi, int8_t snr);
/**
* Send a Join Request
*/
lorawan_status_t send_join_request();
/**
* Handles retransmissions
*/
lorawan_status_t handle_retransmission();
/**
* Checks if the frame is valid
*/
void check_frame_size(uint16_t size);
/**
* Performs MIC
*/
bool message_integrity_check(const uint8_t *payload, uint16_t size,
uint8_t *ptr_pos, uint32_t address,
uint32_t *downlink_counter, const uint8_t *nwk_skey);
/**
* Decrypts and extracts data and MAC commands from the received encrypted
* payload
*/
void extract_data_and_mac_commands(const uint8_t *payload, uint16_t size,
uint8_t fopts_len, uint8_t *nwk_skey,
uint8_t *app_skey, uint32_t address,
uint32_t downlink_frame_counter,
int16_t rssi, int8_t snr);
/**
* Decrypts and extracts MAC commands from the received encrypted
* payload if there is no data
*/
void extract_mac_commands_only(const uint8_t *payload, int8_t snr, uint8_t fopts_len);
/**
* Callback function to be executed when the DC backoff timer expires
*/
void on_backoff_timer_expiry(void);
/**
* At the end of an RX1 window timer, an RX1 window is opened using this method.
*/
void open_rx1_window(void);
/**
* At the end of an RX2 window timer, an RX2 window is opened using this method.
*/
void open_rx2_window(void);
/**
* A method to retry a CONFIRMED message after a particular time period
* (ACK_TIMEOUT = TIME_IN_MS) if the ack was not received
*/
void on_ack_timeout_timer_event(void);
/*!
* \brief Check if the OnAckTimeoutTimer has do be disabled. If so, the
@ -454,30 +545,25 @@ private:
uint8_t ack_timeout_retries_counter,
uint8_t ack_timeout_retries);
/**
* Function executed on AckTimeout timer event
*/
void on_ack_timeout_timer_event(void);
/**
* Validates if the payload fits into the frame, taking the datarate
* into account.
*
* Please Refer to chapter 4.3.2 of the LoRaWAN specification, v1.0.2
*/
bool validate_payload_length(uint8_t length, int8_t datarate, uint8_t fopts_len);
bool validate_payload_length(uint16_t length, int8_t datarate, uint8_t fopts_len);
/**
* Prepares MAC frame on the behest of send() API.
*/
lorawan_status_t prepare_frame(loramac_mhdr_t *mac_hdr,
loramac_frame_ctrl_t *fctrl, uint8_t fport,
void *fbuffer, uint16_t fbuffer_size);
loramac_frame_ctrl_t *fctrl, const uint8_t fport,
const void *fbuffer, uint16_t fbuffer_size);
/**
* Schedules a transmission on the behest of send() API.
*/
lorawan_status_t schedule_tx(void);
lorawan_status_t schedule_tx();
/**
* Calculates the back-off time for the band of a channel.
@ -491,14 +577,11 @@ private:
lorawan_status_t send_frame_on_channel(uint8_t channel);
/**
* @brief reset_mcps_confirmation Resets the MCPS confirmation struct
* Resets MAC primitive blocks
*/
void reset_mcps_confirmation();
/**
* @brief reset_mlme_confirmation Resets the MLME confirmation struct
*/
void reset_mlme_confirmation();
void reset_mcps_confirmation(void);
void reset_mlme_confirmation(void);
void reset_mcps_indication(void);
/**
* @brief set_tx_continuous_wave Puts the system in continuous transmission mode
@ -512,17 +595,6 @@ private:
void set_tx_continuous_wave(uint8_t channel, int8_t datarate, int8_t tx_power,
float max_eirp, float antenna_gain, uint16_t timeout);
/**
* Prototypes for ISR handlers
*/
void handle_cad_done(bool cad);
void handle_tx_done(void);
void handle_rx_done(uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr);
void handle_rx_error(void);
void handle_rx_timeout(void);
void handle_tx_timeout(void);
void handle_fhss_change_channel(uint8_t cur_channel);
private:
/**
* Timer subsystem handle
@ -537,12 +609,12 @@ private:
/**
* MAC command handle
*/
LoRaMacCommand mac_commands;
LoRaMacCommand _mac_commands;
/**
* Channel planning subsystem
*/
LoRaMacChannelPlan channel_plan;
LoRaMacChannelPlan _channel_plan;
/**
* Crypto handling subsystem
@ -554,20 +626,10 @@ private:
*/
loramac_protocol_params _params;
/**
* Radio event callback handlers for MAC
*/
radio_events_t radio_events;
/**
* LoRaMac upper layer event functions
*/
loramac_primitives_t *mac_primitives;
/**
* EventQueue object storage
*/
events::EventQueue *ev_queue;
events::EventQueue *_ev_queue;
/**
* Structure to hold MCPS indication data.

View File

@ -40,7 +40,6 @@ void LoRaMacChannelPlan::activate_channelplan_subsystem(LoRaPHY *phy)
lorawan_status_t LoRaMacChannelPlan::set_plan(const lorawan_channelplan_t& plan)
{
channel_params_t mac_layer_ch_params;
lorawan_status_t status;
uint8_t max_num_channels;
@ -57,16 +56,7 @@ lorawan_status_t LoRaMacChannelPlan::set_plan(const lorawan_channelplan_t& plan)
}
for (uint8_t i = 0; i < plan.nb_channels; i++) {
mac_layer_ch_params.band = plan.channels[i].ch_param.band;
mac_layer_ch_params.dr_range.fields.max = plan.channels[i].ch_param.dr_range.fields.max;
mac_layer_ch_params.dr_range.fields.min = plan.channels[i].ch_param.dr_range.fields.min;
mac_layer_ch_params.dr_range.value = plan.channels[i].ch_param.dr_range.value;
mac_layer_ch_params.frequency = plan.channels[i].ch_param.frequency;
mac_layer_ch_params.rx1_frequency = plan.channels[i].ch_param.rx1_frequency;
status = _lora_phy->add_channel(&mac_layer_ch_params, plan.channels[i].id);
status = _lora_phy->add_channel(&plan.channels[i].ch_param, plan.channels[i].id);
if (status != LORAWAN_STATUS_OK) {
return status;

View File

@ -150,7 +150,7 @@ bool LoRaMacCommand::has_sticky_mac_cmd() const
return sticky_mac_cmd;
}
lorawan_status_t LoRaMacCommand::process_mac_commands(uint8_t *payload, uint8_t mac_index,
lorawan_status_t LoRaMacCommand::process_mac_commands(const uint8_t *payload, uint8_t mac_index,
uint8_t commands_size, uint8_t snr,
loramac_mlme_confirm_t& mlme_conf,
lora_mac_system_params_t &mac_sys_params,

View File

@ -126,7 +126,7 @@ public:
*
* @return status Function status. LORAWAN_STATUS_OK if command successful.
*/
lorawan_status_t process_mac_commands(uint8_t *payload, uint8_t mac_index,
lorawan_status_t process_mac_commands(const uint8_t *payload, uint8_t mac_index,
uint8_t commands_size, uint8_t snr,
loramac_mlme_confirm_t& mlme_conf,
lora_mac_system_params_t& mac_params,

View File

@ -307,7 +307,7 @@ lorawan_time_t LoRaPHY::update_band_timeoff(bool joined, bool duty_cycle,
return next_tx_delay;
}
uint8_t LoRaPHY::parse_link_ADR_req(uint8_t* payload, link_adr_params_t* params)
uint8_t LoRaPHY::parse_link_ADR_req(const uint8_t* payload, link_adr_params_t* params)
{
uint8_t ret_index = 0;
@ -808,7 +808,7 @@ void LoRaPHY::compute_rx_win_params(int8_t datarate, uint8_t min_rx_symbols,
&rx_conf_params->window_timeout, &rx_conf_params->window_offset);
}
bool LoRaPHY::rx_config(rx_config_params_t* rx_conf, int8_t* datarate)
bool LoRaPHY::rx_config(rx_config_params_t* rx_conf)
{
radio_modems_t modem;
uint8_t dr = rx_conf->datarate;
@ -868,8 +868,6 @@ bool LoRaPHY::rx_config(rx_config_params_t* rx_conf, int8_t* datarate)
_radio->unlock();
*datarate = phy_dr;
return true;
}

View File

@ -194,11 +194,9 @@ public:
*
* @param [in] config A pointer to the RX configuration.
*
* @param [out] datarate The datarate index set.
*
* @return True, if the configuration was applied successfully.
*/
virtual bool rx_config(rx_config_params_t* config, int8_t* datarate);
virtual bool rx_config(rx_config_params_t* config);
/** Computing Receive Windows
*
@ -578,7 +576,7 @@ protected:
/**
* Parses the parameter of an LinkAdrRequest.
*/
uint8_t parse_link_ADR_req(uint8_t* payload, link_adr_params_t* adr_params);
uint8_t parse_link_ADR_req(const uint8_t* payload, link_adr_params_t* adr_params);
/**
* Verifies and updates the datarate, the TX power and the number of repetitions

View File

@ -249,7 +249,9 @@ LoRaPHYAS923::LoRaPHYAS923(LoRaWANTimeHandler &lora_time)
// Default Channels are always enabled in the channel list,
// rest will be added later
channels[0] = AS923_LC1;
channels[0].band = 0;
channels[1] = AS923_LC2;
channels[1].band = 0;
// Initialize the default channel mask
default_channel_mask[0] = LC(1) + LC(2);
@ -291,7 +293,8 @@ LoRaPHYAS923::LoRaPHYAS923(LoRaWANTimeHandler &lora_time)
phy_params.accept_tx_param_setup_req = true;
phy_params.fsk_supported = true;
phy_params.cflist_supported = true;
phy_params.dl_channel_req_supported = true;
phy_params.custom_channelplans_supported = true;
phy_params.default_channel_cnt = AS923_NUMB_DEFAULT_CHANNELS;
phy_params.max_channel_cnt = AS923_MAX_NB_CHANNELS;
phy_params.cflist_channel_cnt = AS923_NUMB_CHANNELS_CF_LIST;

View File

@ -335,7 +335,7 @@ LoRaPHYAU915::~LoRaPHYAU915()
{
}
bool LoRaPHYAU915::rx_config(rx_config_params_t* params, int8_t* datarate)
bool LoRaPHYAU915::rx_config(rx_config_params_t* params)
{
int8_t dr = params->datarate;
uint8_t max_payload = 0;
@ -374,7 +374,6 @@ bool LoRaPHYAU915::rx_config(rx_config_params_t* params, int8_t* datarate)
_radio->unlock();
*datarate = (uint8_t) dr;
return true;
}

View File

@ -56,7 +56,7 @@ public:
LoRaPHYAU915(LoRaWANTimeHandler &lora_time);
virtual ~LoRaPHYAU915();
virtual bool rx_config(rx_config_params_t* config, int8_t* datarate);
virtual bool rx_config(rx_config_params_t* config);
virtual bool tx_config(tx_config_params_t* config, int8_t* txPower,
lorawan_time_t* txTimeOnAir);

View File

@ -303,7 +303,7 @@ LoRaPHYCN470::~LoRaPHYCN470()
{
}
bool LoRaPHYCN470::rx_config(rx_config_params_t* config, int8_t* datarate)
bool LoRaPHYCN470::rx_config(rx_config_params_t* config)
{
int8_t dr = config->datarate;
uint8_t max_payload = 0;
@ -349,7 +349,6 @@ bool LoRaPHYCN470::rx_config(rx_config_params_t* config, int8_t* datarate)
_radio->set_max_payload_length(MODEM_LORA, max_payload + LORA_MAC_FRMPAYLOAD_OVERHEAD);
_radio->unlock();
*datarate = (uint8_t) dr;
return true;
}

View File

@ -56,7 +56,7 @@ public:
LoRaPHYCN470(LoRaWANTimeHandler &lora_time);
virtual ~LoRaPHYCN470();
virtual bool rx_config(rx_config_params_t* config, int8_t* datarate );
virtual bool rx_config(rx_config_params_t* config);
virtual bool tx_config(tx_config_params_t* config, int8_t* tx_power,
lorawan_time_t* tx_toa);

View File

@ -237,8 +237,11 @@ LoRaPHYCN779::LoRaPHYCN779(LoRaWANTimeHandler &lora_time)
// Channels
channels[0] = CN779_LC1;
channels[0].band = 0;
channels[1] = CN779_LC2;
channels[1].band = 0;
channels[2] = CN779_LC3;
channels[2].band = 0;
// Initialize the channels default mask
default_channel_mask[0] = LC(1) + LC(2) + LC(3);

View File

@ -238,8 +238,11 @@ LoRaPHYEU433::LoRaPHYEU433(LoRaWANTimeHandler &lora_time)
// Channels
channels[0] = EU433_LC1;
channels[1] = EU433_LC2;;
channels[2] = EU433_LC3;;
channels[0].band = 0;
channels[1] = EU433_LC2;
channels[1].band = 0;
channels[2] = EU433_LC3;
channels[2].band = 0;
// Initialize the channels default mask
default_channel_mask[0] = LC(1) + LC(2) + LC(3);

View File

@ -268,8 +268,11 @@ LoRaPHYEU868::LoRaPHYEU868(LoRaWANTimeHandler &lora_time)
// Default Channels are always enabled, rest will be added later
channels[0] = EU868_LC1;
channels[0].band = 1;
channels[1] = EU868_LC2;
channels[1].band = 1;
channels[2] = EU868_LC3;
channels[2].band = 1;
// Initialize the channels default mask
default_channel_mask[0] = LC(1) + LC(2) + LC(3);

View File

@ -239,8 +239,11 @@ LoRaPHYIN865::LoRaPHYIN865(LoRaWANTimeHandler &lora_time)
// Default Channels are always enabled, rest will be added later
channels[0] = IN865_LC1;
channels[0].band = 0;
channels[1] = IN865_LC2;
channels[1].band = 0;
channels[2] = IN865_LC3;
channels[2].band = 0;
// Initialize the channels default mask
default_channel_mask[0] = LC(1) + LC(2) + LC(3);

View File

@ -248,8 +248,11 @@ LoRaPHYKR920::LoRaPHYKR920(LoRaWANTimeHandler &lora_time)
// Channels
channels[0] = KR920_LC1;
channels[0].band = 0;
channels[1] = KR920_LC2;
channels[1].band = 0;
channels[2] = KR920_LC3;
channels[2].band = 0;
// Initialize the channels default mask
default_channel_mask[0] = LC( 1 ) + LC( 2 ) + LC( 3 );

View File

@ -353,7 +353,7 @@ void LoRaPHYUS915::restore_default_channels()
}
}
bool LoRaPHYUS915::rx_config(rx_config_params_t* config, int8_t* datarate)
bool LoRaPHYUS915::rx_config(rx_config_params_t* config)
{
int8_t dr = config->datarate;
uint8_t max_payload = 0;
@ -409,7 +409,6 @@ bool LoRaPHYUS915::rx_config(rx_config_params_t* config, int8_t* datarate)
_radio->unlock();
*datarate = (uint8_t) dr;
return true;
}

View File

@ -56,7 +56,7 @@ public:
virtual void restore_default_channels();
virtual bool rx_config(rx_config_params_t* config, int8_t* datarate);
virtual bool rx_config(rx_config_params_t* config);
virtual bool tx_config(tx_config_params_t* config, int8_t* tx_power,
lorawan_time_t* tx_toa);

View File

@ -369,7 +369,7 @@ bool LoRaPHYUS915Hybrid::get_next_ADR(bool restore_channel_mask, int8_t& dr_out,
return adrAckReq;
}
bool LoRaPHYUS915Hybrid::rx_config(rx_config_params_t* config, int8_t* datarate)
bool LoRaPHYUS915Hybrid::rx_config(rx_config_params_t* config)
{
int8_t dr = config->datarate;
uint8_t max_payload = 0;
@ -416,7 +416,6 @@ bool LoRaPHYUS915Hybrid::rx_config(rx_config_params_t* config, int8_t* datarate)
_radio->set_max_payload_length(MODEM_LORA, max_payload + LORA_MAC_FRMPAYLOAD_OVERHEAD);
_radio->unlock();
*datarate = (uint8_t) dr;
return true;
}

View File

@ -59,7 +59,7 @@ public:
virtual bool get_next_ADR(bool restore_channel_mask, int8_t& dr_out,
int8_t& tx_power_out, uint32_t& adr_ack_cnt);
virtual bool rx_config(rx_config_params_t* rxConfig, int8_t* datarate);
virtual bool rx_config(rx_config_params_t* rxConfig);
virtual bool tx_config(tx_config_params_t* tx_config, int8_t* tx_power,
lorawan_time_t* tx_toa);

View File

@ -564,7 +564,7 @@ typedef struct
/*!
* A pointer to the payload containing the MAC commands.
*/
uint8_t* payload;
const uint8_t* payload;
/*!
* The size of the payload.
*/

View File

@ -34,6 +34,40 @@
#include "platform/Callback.h"
/**
* Option Flags for send(), receive() APIs
*/
#define MSG_UNCONFIRMED_FLAG 0x01
#define MSG_CONFIRMED_FLAG 0x02
#define MSG_MULTICAST_FLAG 0x04
#define MSG_PROPRIETARY_FLAG 0x08
/**
* Bit mask for message flags
*/
#define MSG_FLAG_MASK 0x0F
/**
* Mask for unconfirmed multicast message
*/
#define MSG_UNCONFIRMED_MULTICAST 0x05
/**
* Mask for confirmed multicast message
*/
#define MSG_CONFIRMED_MULTICAST 0x06
/**
* Mask for unconfirmed message proprietary message
*/
#define MSG_UNCONFIRMED_PROPRIETARY 0x09
/**
* Mask for confirmed proprietary message
*/
#define MSG_CONFIRMED_PROPRIETARY 0x0A
/**
* LoRaWAN device classes definition.
*

View File

@ -47,40 +47,6 @@ typedef uint32_t lorawan_time_t;
// Radio wake-up time from sleep - unit ms.
#define RADIO_WAKEUP_TIME 1
/**
* Option Flags for send(), receive() APIs
*/
#define MSG_UNCONFIRMED_FLAG 0x01
#define MSG_CONFIRMED_FLAG 0x02
#define MSG_MULTICAST_FLAG 0x04
#define MSG_PROPRIETARY_FLAG 0x08
/**
* Bit mask for message flags
*/
#define MSG_FLAG_MASK 0x0F
/**
* Mask for unconfirmed multicast message
*/
#define MSG_UNCONFIRMED_MULTICAST 0x05
/**
* Mask for confirmed multicast message
*/
#define MSG_CONFIRMED_MULTICAST 0x06
/**
* Mask for unconfirmed message proprietary message
*/
#define MSG_UNCONFIRMED_PROPRIETARY 0x09
/**
* Mask for confirmed proprietary message
*/
#define MSG_CONFIRMED_PROPRIETARY 0x0A
/*!
* Sets the length of the LoRaMAC footer field.
* Mainly indicates the MIC field length.
@ -570,7 +536,7 @@ typedef enum {
/*!
* The node has lost MAX_FCNT_GAP or more frames.
*/
LORAMAC_EVENT_INFO_STATUS_DOWNLINK_TOO_MANY_FRAMES_LOSS,
LORAMAC_EVENT_INFO_STATUS_DOWNLINK_TOO_MANY_FRAMES_LOST,
/*!
* An address error occurred.
*/
@ -585,46 +551,6 @@ typedef enum {
LORAMAC_EVENT_INFO_STATUS_CRYPTO_FAIL,
} loramac_event_info_status_t;
/*!
* LoRaMac service state flags.
*/
typedef union {
/*!
* Byte-access to the bits.
*/
uint8_t value;
/*!
* The structure containing single access to bits.
*/
struct mac_flag_bits_s
{
/*!
* MCPS-Req pending
*/
uint8_t mcps_req : 1;
/*!
* MCPS-Ind pending
*/
uint8_t mcps_ind : 1;
/*!
* MCPS-Ind pending. Skip indication to the application layer.
*/
uint8_t mcps_ind_skip : 1;
/*!
* MLME-Req pending
*/
uint8_t mlme_req : 1;
/*!
* MLME-Ind pending
*/
uint8_t mlme_ind : 1;
/*!
* MAC cycle done
*/
uint8_t mac_done : 1;
} bits;
} loramac_flags_t;
/*!
*
* \brief LoRaMAC data services
@ -639,14 +565,6 @@ typedef union {
* \ref MCPS_MULTICAST | NO | YES | NO | NO
* \ref MCPS_PROPRIETARY | YES | YES | NO | YES
*
* The following table provides links to the function implementations of the
* related MCPS primitives:
*
* Primitive | Function
* ---------------- | :---------------------:
* MCPS-Request | LoRaMacMlmeRequest
* MCPS-Confirm | MacMcpsConfirm in \ref loramac_primitives_t
* MCPS-Indication | MacMcpsIndication in \ref loramac_primitives_t
*/
typedef enum {
/*!
@ -714,6 +632,10 @@ typedef struct {
* LoRaMAC MCPS-Indication primitive.
*/
typedef struct {
/*!
* True if an MCPS indication was pending
*/
bool pending;
/*!
* MCPS-Indication type.
*/
@ -741,7 +663,7 @@ typedef struct {
/*!
* A pointer to the received data stream.
*/
uint8_t *buffer;
const uint8_t *buffer;
/*!
* The size of the received data stream.
*/
@ -787,14 +709,6 @@ typedef struct {
* \ref MLME_TXCW | YES | NO | NO | YES
* \ref MLME_SCHEDULE_UPLINK | NO | YES | NO | NO
*
* The following table provides links to the function implementations of the
* related MLME primitives.
*
* Primitive | Function
* ---------------- | :---------------------:
* MLME-Request | LoRaMacMlmeRequest
* MLME-Confirm | MacMlmeConfirm in \ref loramac_primitives_t
* MLME-Indication | MacMlmeIndication in \ref loramac_primitives_t
*/
typedef enum {
/*!
@ -879,6 +793,10 @@ typedef struct {
* LoRaMAC MLME-Confirm primitive.
*/
typedef struct {
/*!
* Indicates if a request is pending or not
*/
bool pending;
/*!
* The previously performed MLME-Request. i.e., the request type
* for which the confirmation is being generated
@ -915,41 +833,29 @@ typedef struct {
* MLME-Indication type
*/
mlme_type_t indication_type;
bool pending;
} loramac_mlme_indication_t;
/*!
* LoRaMAC events structure.
* Used to notify upper layers of MAC events.
/**
* End-device states.
*/
typedef struct {
/*!
* \brief MCPS-Confirm primitive.
*
* \param [OUT] MCPS-Confirm parameters.
*/
mbed::Callback<void(loramac_mcps_confirm_t*)> mcps_confirm;
/*!
* \brief MCPS-Indication primitive.
*
* \param [OUT] MCPS-Indication parameters.
*/
mbed::Callback<void(loramac_mcps_indication_t*)> mcps_indication;
/*!
* \brief MLME-Confirm primitive.
*
* \param [OUT] MLME-Confirm parameters.
*/
mbed::Callback<void(loramac_mlme_confirm_t*)> mlme_confirm;
/*!
* \brief MLME-Indication primitive
*
* \param [OUT] MLME-Indication parameters
*/
mbed::Callback<void(loramac_mlme_indication_t*)> mlme_indication;
}loramac_primitives_t;
typedef enum device_states {
DEVICE_STATE_NOT_INITIALIZED,
DEVICE_STATE_JOINING,
DEVICE_STATE_IDLE,
DEVICE_STATE_CONNECTING,
DEVICE_STATE_AWAITING_JOIN_ACCEPT,
DEVICE_STATE_RECEIVING,
DEVICE_STATE_CONNECTED,
DEVICE_STATE_SCHEDULING,
DEVICE_STATE_SENDING,
DEVICE_STATE_AWAITING_ACK,
DEVICE_STATE_STATUS_CHECK,
#if defined(LORAWAN_COMPLIANCE_TEST)
DEVICE_STATE_COMPLIANCE_TEST,
#endif
DEVICE_STATE_SHUTDOWN
} device_states_t;
/**
* Enumeration for LoRaWAN connection type.
@ -1090,70 +996,6 @@ typedef struct lorawan_session {
uint32_t downlink_counter;
} lorawan_session_t;
/** Structure containing the uplink status
*
*/
typedef struct {
/** Is acked
*
*/
uint8_t acked;
/** Uplink data rate
*
*/
int8_t datarate;
/** Uplink counter
*
*/
uint16_t uplink_counter;
/** Port is used by application
*
*/
uint8_t port;
/** Payload
*
*/
uint8_t *buffer;
/** Payload size
*
*/
uint8_t buffer_size;
} loramac_uplink_status_t;
/** A structure containing the downlink status
*
*/
typedef struct {
/** RSSI of downlink
*
*/
int16_t rssi;
/** SNR of downlink
*
*/
int8_t snr;
/** Downlink counter
*
*/
uint16_t downlink_counter;
/** Is RX data received
*
*/
bool rx_data;
/** Port used by application
*
*/
uint8_t port;
/** Payload
*
*/
uint8_t *buffer;
/** Payload size
*
*/
uint8_t buffer_size;
} loramac_downlink_status_t;
/*!
* The parameter structure for the function for regional rx configuration.
*/
@ -1163,7 +1005,7 @@ typedef struct {
*/
uint8_t channel;
/*!
* The RX datarate.
* The RX datarate index.
*/
uint8_t datarate;
/*!
@ -1212,20 +1054,6 @@ typedef struct {
int timer_id;
} timer_event_t;
/*!
* LoRaMac internal states
*/
typedef enum {
LORAMAC_IDLE = 0x00000000,
LORAMAC_TX_RUNNING = 0x00000001,
LORAMAC_RX = 0x00000002,
LORAMAC_ACK_REQ = 0x00000004,
LORAMAC_ACK_RETRY = 0x00000008,
LORAMAC_TX_DELAYED = 0x00000010,
LORAMAC_TX_CONFIG = 0x00000020,
LORAMAC_RX_ABORT = 0x00000040,
} loramac_internal_state;
typedef struct {
/*!
* Device IEEE EUI
@ -1270,21 +1098,15 @@ typedef struct {
*/
lorawan_time_t mac_init_time;
/*!
* Last transmission time on air
*/
lorawan_time_t tx_toa;
/*!
* LoRaMac timer used to check the LoRaMacState (runs every second)
* LoRaMac duty cycle backoff timer
*/
timer_event_t mac_state_check_timer;
/*!
* LoRaMac duty cycle delayed Tx timer
*/
timer_event_t tx_delayed_timer;
timer_event_t backoff_timer;
/*!
* LoRaMac reception windows timers
@ -1375,24 +1197,24 @@ typedef struct {
uint8_t ul_nb_rep_counter;
/*!
* Buffer containing the data to be sent or received.
* TX buffer used for encrypted outgoing frames
*/
uint8_t buffer[LORAMAC_PHY_MAXPAYLOAD];
uint8_t tx_buffer[LORAMAC_PHY_MAXPAYLOAD];
/*!
* Length of packet in LoRaMacBuffer
* Length of TX buffer
*/
uint16_t buffer_pkt_len;
uint16_t tx_buffer_len;
/*!
* Buffer containing the upper layer data.
* Used for storing decrypted RX data.
*/
uint8_t payload[LORAMAC_PHY_MAXPAYLOAD];
uint8_t rx_buffer[LORAMAC_PHY_MAXPAYLOAD];
/*!
* Length of the payload in LoRaMacBuffer
* Length of the RX buffer
*/
uint8_t payload_length;
uint8_t rx_buffer_len;
/*!
* Number of trials to get a frame acknowledged
@ -1419,11 +1241,6 @@ typedef struct {
*/
loramac_keys keys;
/*!
* LoRaMac tx/rx operation state
*/
loramac_flags_t flags;
/*!
* Device nonce is a random value extracted by issuing a sequence of RSSI
* measurements
@ -1457,11 +1274,6 @@ typedef struct {
*/
uint32_t adr_ack_counter;
/*!
* LoRaMac internal state
*/
uint32_t mac_state;
/*!
* LoRaMac reception windows delay
* \remark normal frame: RxWindowXDelay = ReceiveDelayX - RADIO_WAKEUP_TIME