diff --git a/features/lorawan/LoRaWANStack.cpp b/features/lorawan/LoRaWANStack.cpp index 42f2ba25e0..a73512ebbc 100644 --- a/features/lorawan/LoRaWANStack.cpp +++ b/features/lorawan/LoRaWANStack.cpp @@ -35,6 +35,7 @@ SPDX-License-Identifier: BSD-3-Clause #define INVALID_PORT 0xFF #define MAX_CONFIRMED_MSG_RETRIES 255 +#define COMPLIANCE_TESTING_PORT 224 /** * Control flags for transient states */ @@ -49,16 +50,6 @@ SPDX-License-Identifier: BSD-3-Clause using namespace mbed; using namespace events; -#if defined(LORAWAN_COMPLIANCE_TEST) -#if (MBED_CONF_LORA_PHY == 0 || MBED_CONF_LORA_PHY == 4 || MBED_CONF_LORA_PHY == 6 || MBED_CONF_LORA_PHY == 7) -#define LORAWAN_COMPLIANCE_TEST_DATA_SIZE 16 -#elif (MBED_CONF_LORA_PHY == 1 || MBED_CONF_LORA_PHY == 2 || MBED_CONF_LORA_PHY == 8 || MBED_CONF_LORA_PHY == 9) -#define LORAWAN_COMPLIANCE_TEST_DATA_SIZE 11 -#else -#error "Must set LoRa PHY layer parameters." -#endif -#endif //defined(LORAWAN_COMPLIANCE_TEST) - /** * Bit mask for message flags */ @@ -317,12 +308,6 @@ int16_t LoRaWANStack::handle_tx(const uint8_t port, const uint8_t *data, return LORAWAN_STATUS_WOULD_BLOCK; } -#if defined(LORAWAN_COMPLIANCE_TEST) - if (_compliance_test.running) { - return LORAWAN_STATUS_COMPLIANCE_TEST_ON; - } -#endif - lorawan_status_t status; if (_loramac.nwk_joined() == false) { @@ -373,12 +358,6 @@ int16_t LoRaWANStack::handle_rx(uint8_t *data, uint16_t length, uint8_t &port, i return LORAWAN_STATUS_WOULD_BLOCK; } -#if defined(LORAWAN_COMPLIANCE_TEST) - if (_compliance_test.running) { - return LORAWAN_STATUS_COMPLIANCE_TEST_ON; - } -#endif - if (data == NULL || length == 0) { return LORAWAN_STATUS_PARAMETER_INVALID; } @@ -655,6 +634,11 @@ void LoRaWANStack::process_reception(const uint8_t *const payload, uint16_t size if (_loramac.get_mlme_confirmation()->pending) { _loramac.post_process_mlme_request(); mlme_confirm_handler(); + + if (_loramac.get_mlme_confirmation()->req_type == MLME_JOIN) { + _ready_for_rx = true; + return; + } } if (!_loramac.nwk_joined()) { @@ -785,9 +769,17 @@ bool LoRaWANStack::is_port_valid(const uint8_t port, bool allow_port_0) //Application should not use reserved and illegal port numbers. if (port == 0) { return allow_port_0; + } else if (port == COMPLIANCE_TESTING_PORT){ +#if !defined(LORAWAN_COMPLIANCE_TEST) + return false; +#endif } else { return true; } + + // fallback for compliance testing port if LORAWAN_COMPLIANCE_TEST + // was defined + return true; } lorawan_status_t LoRaWANStack::set_application_port(const uint8_t port, bool allow_port_0) @@ -915,22 +907,16 @@ void LoRaWANStack::mlme_indication_handler() void LoRaWANStack::mlme_confirm_handler() { if (_loramac.get_mlme_confirmation()->req_type == MLME_LINK_CHECK) { - if (_loramac.get_mlme_confirmation()->status == LORAMAC_EVENT_INFO_STATUS_OK) { -#if defined(LORAWAN_COMPLIANCE_TEST) - if (_compliance_test.running == true) { - _compliance_test.link_check = true; - _compliance_test.demod_margin = _loramac.get_mlme_confirmation()->demod_margin; - _compliance_test.nb_gateways = _loramac.get_mlme_confirmation()->nb_gateways; - } else -#endif - { - if (_callbacks.link_check_resp) { - const int ret = _queue->call(_callbacks.link_check_resp, - _loramac.get_mlme_confirmation()->demod_margin, - _loramac.get_mlme_confirmation()->nb_gateways); - MBED_ASSERT(ret != 0); - (void)ret; - } + if (_loramac.get_mlme_confirmation()->status + == LORAMAC_EVENT_INFO_STATUS_OK) { + + if (_callbacks.link_check_resp) { + const int ret = _queue->call( + _callbacks.link_check_resp, + _loramac.get_mlme_confirmation()->demod_margin, + _loramac.get_mlme_confirmation()->nb_gateways); + MBED_ASSERT(ret != 0); + (void) ret; } } } @@ -999,64 +985,61 @@ void LoRaWANStack::mcps_indication_handler() _lw_session.downlink_counter = mcps_indication->dl_frame_counter; -#if defined(LORAWAN_COMPLIANCE_TEST) - if (_compliance_test.running == true) { - _compliance_test.downlink_counter++; + /** + * Check port, if it's compliance testing port and the compliance testing is + * not enabled, give up silently + */ + if (mcps_indication->port == COMPLIANCE_TESTING_PORT) { +#if !defined(LORAWAN_COMPLIANCE_TEST) + return; +#endif } -#endif - if (mcps_indication->port == 224) { -#if defined(LORAWAN_COMPLIANCE_TEST) - tr_debug("Compliance test command received."); - compliance_test_handler(mcps_indication); -#else - tr_info("Compliance test disabled."); -#endif - } else { - if (mcps_indication->is_data_recvd) { - // Valid message arrived. - _rx_msg.type = LORAMAC_RX_MCPS_INDICATION; - _rx_msg.msg.mcps_indication.buffer_size = mcps_indication->buffer_size; - _rx_msg.msg.mcps_indication.port = mcps_indication->port; - _rx_msg.msg.mcps_indication.buffer = mcps_indication->buffer; - _rx_msg.msg.mcps_indication.type = mcps_indication->type; + if (mcps_indication->is_data_recvd) { + // Valid message arrived. + _rx_msg.type = LORAMAC_RX_MCPS_INDICATION; + _rx_msg.msg.mcps_indication.buffer_size = mcps_indication->buffer_size; + _rx_msg.msg.mcps_indication.port = mcps_indication->port; + _rx_msg.msg.mcps_indication.buffer = mcps_indication->buffer; + _rx_msg.msg.mcps_indication.type = mcps_indication->type; - // Notify application about received frame.. - tr_debug("Packet Received %d bytes, Port=%d", - _rx_msg.msg.mcps_indication.buffer_size, - mcps_indication->port); - _rx_msg.receive_ready = true; - send_event_to_application(RX_DONE); - } + // Notify application about received frame.. + tr_debug("Packet Received %d bytes, Port=%d", + _rx_msg.msg.mcps_indication.buffer_size, + mcps_indication->port); + _rx_msg.receive_ready = true; + send_event_to_application(RX_DONE); + } - /* - * If fPending bit is set we try to generate an empty packet - * with CONFIRMED flag set. We always set a CONFIRMED flag so - * that we could retry a certain number of times if the uplink - * failed for some reason - * or - * Class C and node received a confirmed message so we need to - * send an empty packet to acknowledge the message. - * This scenario is unspecified by LoRaWAN 1.0.2 specification, - * but version 1.1.0 says that network SHALL not send any new - * confirmed messages until ack has been sent - */ - if ((_loramac.get_device_class() != CLASS_C && mcps_indication->fpending_status) - || - (_loramac.get_device_class() == CLASS_C && mcps_indication->type == MCPS_CONFIRMED)) { + /* + * If fPending bit is set we try to generate an empty packet + * with CONFIRMED flag set. We always set a CONFIRMED flag so + * that we could retry a certain number of times if the uplink + * failed for some reason + * or + * Class C and node received a confirmed message so we need to + * send an empty packet to acknowledge the message. + * This scenario is unspecified by LoRaWAN 1.0.2 specification, + * but version 1.1.0 says that network SHALL not send any new + * confirmed messages until ack has been sent + */ + if ((_loramac.get_device_class() != CLASS_C + && mcps_indication->fpending_status) + || (_loramac.get_device_class() == CLASS_C + && mcps_indication->type == MCPS_CONFIRMED)) { #if (MBED_CONF_LORA_AUTOMATIC_UPLINK_MESSAGE) - tr_debug("Sending empty uplink message..."); - _automatic_uplink_ongoing = true; - const int ret = _queue->call(this, &LoRaWANStack::send_automatic_uplink_message, mcps_indication->port); - MBED_ASSERT(ret != 0); - (void)ret; + tr_debug("Sending empty uplink message..."); + _automatic_uplink_ongoing = true; + const int ret = _queue->call(this, &LoRaWANStack::send_automatic_uplink_message, mcps_indication->port); + MBED_ASSERT(ret != 0); + (void)ret; #else - send_event_to_application(UPLINK_REQUIRED); + send_event_to_application(UPLINK_REQUIRED); #endif - } } } + lorawan_status_t LoRaWANStack::state_controller(device_states_t new_state) { lorawan_status_t status = LORAWAN_STATUS_OK; @@ -1249,190 +1232,3 @@ void LoRaWANStack::process_uninitialized_state(lorawan_status_t &op_status) _device_current_state = DEVICE_STATE_IDLE; } } - -#if defined(LORAWAN_COMPLIANCE_TEST) - -lorawan_status_t LoRaWANStack::send_compliance_test_frame_to_mac() -{ - loramac_compliance_test_req_t test_req; - - //TODO: What if the port is not 224 ??? - if (_compliance_test.app_port == 224) { - // Clear any normal message stuff before compliance test. - memset(&test_req, 0, sizeof(test_req)); - - if (_compliance_test.link_check == true) { - _compliance_test.link_check = false; - _compliance_test.state = 1; - test_req.f_buffer_size = 3; - test_req.f_buffer[0] = 5; - test_req.f_buffer[1] = _compliance_test.demod_margin; - test_req.f_buffer[2] = _compliance_test.nb_gateways; - } else { - switch (_compliance_test.state) { - case 4: - _compliance_test.state = 1; - test_req.f_buffer_size = _compliance_test.app_data_size; - test_req.f_buffer[0] = _compliance_test.app_data_buffer[0]; - for (uint8_t i = 1; i < MIN(_compliance_test.app_data_size, MBED_CONF_LORA_TX_MAX_SIZE); ++i) { - test_req.f_buffer[i] = _compliance_test.app_data_buffer[i]; - } - break; - case 1: - test_req.f_buffer_size = 2; - test_req.f_buffer[0] = _compliance_test.downlink_counter >> 8; - test_req.f_buffer[1] = _compliance_test.downlink_counter; - break; - } - } - } - - //TODO: If port is not 224, this might not work! - //Is there a test case where same _tx_msg's buffer would be used, when port is not 224??? - if (!_compliance_test.is_tx_confirmed) { - test_req.type = MCPS_UNCONFIRMED; - test_req.fport = _compliance_test.app_port; - test_req.nb_trials = 1; - test_req.data_rate = _loramac.get_default_tx_datarate(); - - tr_info("Transmit unconfirmed compliance test frame %d bytes.", test_req.f_buffer_size); - - for (uint8_t i = 0; i < test_req.f_buffer_size; ++i) { - tr_info("Byte %d, data is 0x%x", i + 1, ((uint8_t *)test_req.f_buffer)[i]); - } - } else if (_compliance_test.is_tx_confirmed) { - test_req.type = MCPS_CONFIRMED; - test_req.fport = _compliance_test.app_port; - test_req.nb_trials = _num_retry; - test_req.data_rate = _loramac.get_default_tx_datarate(); - - tr_info("Transmit confirmed compliance test frame %d bytes.", test_req.f_buffer_size); - - for (uint8_t i = 0; i < test_req.f_buffer_size; ++i) { - tr_info("Byte %d, data is 0x%x", i + 1, ((uint8_t *)test_req.f_buffer)[i]); - } - } else { - return LORAWAN_STATUS_SERVICE_UNKNOWN; - } - - return _loramac.test_request(&test_req); -} - -void LoRaWANStack::compliance_test_handler(loramac_mcps_indication_t *mcps_indication) -{ - if (_compliance_test.running == false) { - // Check compliance test enable command (i) - if ((mcps_indication->buffer_size == 4) && - (mcps_indication->buffer[0] == 0x01) && - (mcps_indication->buffer[1] == 0x01) && - (mcps_indication->buffer[2] == 0x01) && - (mcps_indication->buffer[3] == 0x01)) { - _compliance_test.is_tx_confirmed = false; - _compliance_test.app_port = 224; - _compliance_test.app_data_size = 2; - _compliance_test.downlink_counter = 0; - _compliance_test.link_check = false; - _compliance_test.demod_margin = 0; - _compliance_test.nb_gateways = 0; - _compliance_test.running = true; - _compliance_test.state = 1; - - _loramac.enable_adaptive_datarate(true); - -#if MBED_CONF_LORA_PHY == 0 - _loramac.LoRaMacTestSetDutyCycleOn(false); -#endif - //5000ms - _loramac.LoRaMacSetTxTimer(5000); - - //TODO: Should we call lora_state_machine here instead of just setting the state? - _device_current_state = DEVICE_STATE_COMPLIANCE_TEST; -// lora_state_machine(DEVICE_STATE_COMPLIANCE_TEST); - tr_debug("Compliance test activated."); - } - } else { - _compliance_test.state = mcps_indication->buffer[0]; - switch (_compliance_test.state) { - case 0: // Check compliance test disable command (ii) - _compliance_test.is_tx_confirmed = true; - _compliance_test.app_port = MBED_CONF_LORA_APP_PORT; - _compliance_test.app_data_size = LORAWAN_COMPLIANCE_TEST_DATA_SIZE; - _compliance_test.downlink_counter = 0; - _compliance_test.running = false; - - _loramac.enable_adaptive_datarate(MBED_CONF_LORA_ADR_ON); - -#if MBED_CONF_LORA_PHY == 0 - _loramac.LoRaMacTestSetDutyCycleOn(MBED_CONF_LORA_DUTY_CYCLE_ON); -#endif - // Go to idle state after compliance test mode. - tr_debug("Compliance test disabled."); - _loramac.LoRaMacStopTxTimer(); - - // Clear any compliance test message stuff before going back to normal operation. - _loramac.reset_ongoing_tx(); - lora_state_machine(DEVICE_STATE_IDLE); - break; - case 1: // (iii, iv) - _compliance_test.app_data_size = 2; - break; - case 2: // Enable confirmed messages (v) - _compliance_test.is_tx_confirmed = true; - _compliance_test.state = 1; - break; - case 3: // Disable confirmed messages (vi) - _compliance_test.is_tx_confirmed = false; - _compliance_test.state = 1; - break; - case 4: // (vii) - _compliance_test.app_data_size = mcps_indication->buffer_size; - - _compliance_test.app_data_buffer[0] = 4; - for (uint8_t i = 1; i < MIN(_compliance_test.app_data_size, LORAMAC_PHY_MAXPAYLOAD); ++i) { - _compliance_test.app_data_buffer[i] = mcps_indication->buffer[i] + 1; - } - - send_compliance_test_frame_to_mac(); - break; - case 5: // (viii) - _loramac.setup_link_check_request(); - break; - case 6: // (ix) - // Disable TestMode and revert back to normal operation - _compliance_test.is_tx_confirmed = true; - _compliance_test.app_port = MBED_CONF_LORA_APP_PORT; - _compliance_test.app_data_size = LORAWAN_COMPLIANCE_TEST_DATA_SIZE; - _compliance_test.downlink_counter = 0; - _compliance_test.running = false; - - _loramac.enable_adaptive_datarate(MBED_CONF_LORA_ADR_ON); - -#if MBED_CONF_LORA_PHY == 0 - _loramac.LoRaMacTestSetDutyCycleOn(MBED_CONF_LORA_DUTY_CYCLE_ON); -#endif - _loramac.join(true); - break; - case 7: // (x) - if (mcps_indication->buffer_size == 3) { - loramac_mlme_req_t mlme_req; - mlme_req.type = MLME_TXCW; - mlme_req.cw_tx_mode.timeout = (uint16_t)((mcps_indication->buffer[1] << 8) | mcps_indication->buffer[2]); - _loramac.mlme_request(&mlme_req); - } else if (mcps_indication->buffer_size == 7) { - loramac_mlme_req_t mlme_req; - mlme_req.type = MLME_TXCW_1; - mlme_req.cw_tx_mode.timeout = (uint16_t)((mcps_indication->buffer[1] << 8) - | mcps_indication->buffer[2]); - mlme_req.cw_tx_mode.frequency = (uint32_t)((mcps_indication->buffer[3] << 16) - | (mcps_indication->buffer[4] << 8) - | mcps_indication->buffer[5]) * 100; - mlme_req.cw_tx_mode.power = mcps_indication->buffer[6]; - _loramac.mlme_request(&mlme_req); - } - _compliance_test.state = 1; - break; - } - } -} -#endif - diff --git a/features/lorawan/LoRaWANStack.h b/features/lorawan/LoRaWANStack.h index 4f052d9d1c..d417108b88 100644 --- a/features/lorawan/LoRaWANStack.h +++ b/features/lorawan/LoRaWANStack.h @@ -505,21 +505,6 @@ private: uint8_t _rx_payload[LORAMAC_PHY_MAXPAYLOAD]; events::EventQueue *_queue; lorawan_time_t _tx_timestamp; - -#if defined(LORAWAN_COMPLIANCE_TEST) - - /** - * Used only for compliance testing - */ - void compliance_test_handler(loramac_mcps_indication_t *mcps_indication); - - /** - * Used only for compliance testing - */ - lorawan_status_t send_compliance_test_frame_to_mac(); - - compliance_test_t _compliance_test; -#endif }; #endif /* LORAWANSTACK_H_ */ diff --git a/features/lorawan/lorastack/mac/LoRaMac.cpp b/features/lorawan/lorastack/mac/LoRaMac.cpp index 18bd3ad56c..5d5e0d6899 100644 --- a/features/lorawan/lorastack/mac/LoRaMac.cpp +++ b/features/lorawan/lorastack/mac/LoRaMac.cpp @@ -1106,12 +1106,14 @@ lorawan_status_t LoRaMac::schedule_tx() break; } - tr_debug("TX: Channel=%d, DR=%d", _params.channel, next_channel.current_datarate); - - uint8_t dr_offset = _lora_phy->apply_DR_offset(_params.sys_params.channel_data_rate, + uint8_t rx1_dr = _lora_phy->apply_DR_offset(_params.sys_params.channel_data_rate, _params.sys_params.rx1_dr_offset); - _lora_phy->compute_rx_win_params(dr_offset, MBED_CONF_LORA_DOWNLINK_PREAMBLE_LENGTH, + tr_debug("TX: Channel=%d, TX DR=%d, RX1 DR=%d", + _params.channel, _params.sys_params.channel_data_rate, rx1_dr); + + + _lora_phy->compute_rx_win_params(rx1_dr, MBED_CONF_LORA_DOWNLINK_PREAMBLE_LENGTH, MBED_CONF_LORA_MAX_SYS_RX_ERROR, &_params.rx_window1_config); @@ -1948,147 +1950,3 @@ void LoRaMac::bind_phy(LoRaPHY &phy) { _lora_phy = &phy; } - -#if defined(LORAWAN_COMPLIANCE_TEST) -/*************************************************************************** - * Compliance testing * - **************************************************************************/ - - -lorawan_status_t LoRaMac::mlme_request(loramac_mlme_req_t *mlmeRequest) -{ - if (LORAMAC_IDLE != _params.mac_state) { - return LORAWAN_STATUS_BUSY; - } - - reset_mlme_confirmation(); - - _mlme_confirmation.req_type = mlmeRequest->type; - _params.flags.bits.mlme_req = 1; - - lorawan_status_t status = LORAWAN_STATUS_SERVICE_UNKNOWN; - - if (MLME_TXCW == mlmeRequest->type) { - set_tx_continuous_wave(_params.channel, _params.sys_params.channel_data_rate, _params.sys_params.channel_tx_power, - _params.sys_params.max_eirp, _params.sys_params.antenna_gain, mlmeRequest->cw_tx_mode.timeout); - _lora_time.start(_params.timers.mac_state_check_timer, - MAC_STATE_CHECK_TIMEOUT); - - _params.mac_state |= LORAMAC_TX_RUNNING; - status = LORAWAN_STATUS_OK; - } else if (MLME_TXCW_1 == mlmeRequest->type) { - set_tx_continuous_wave(0, 0, mlmeRequest->cw_tx_mode.power, 0, 0, mlmeRequest->cw_tx_mode.timeout); - _lora_time.start(_params.timers.mac_state_check_timer, - MAC_STATE_CHECK_TIMEOUT); - - _params.mac_state |= LORAMAC_TX_RUNNING; - status = LORAWAN_STATUS_OK; - } - - if (status != LORAWAN_STATUS_OK) { - _params.is_node_ack_requested = false; - _params.flags.bits.mlme_req = 0; - } - - return status; -} - -lorawan_status_t LoRaMac::test_request(loramac_compliance_test_req_t *mcpsRequest) -{ - if (_params.mac_state != LORAMAC_IDLE) { - return LORAWAN_STATUS_BUSY; - } - - loramac_mhdr_t machdr; - int8_t datarate = mcpsRequest->data_rate; - // TODO: The comment is different than the code??? - // Apply the minimum possible datarate. - // Some regions have limitations for the minimum datarate. - datarate = MAX(datarate, (int8_t)_lora_phy->get_minimum_tx_datarate()); - - machdr.value = 0; - - reset_mcps_confirmation(); - - _params.ack_timeout_retry_counter = 1; - _params.max_ack_timeout_retries = 1; - - switch (mcpsRequest->type) { - case MCPS_UNCONFIRMED: { - machdr.bits.mtype = FRAME_TYPE_DATA_UNCONFIRMED_UP; - break; - } - case MCPS_CONFIRMED: { - machdr.bits.mtype = FRAME_TYPE_DATA_CONFIRMED_UP; - _params.max_ack_timeout_retries = mcpsRequest->nb_trials; - break; - } - case MCPS_PROPRIETARY: { - machdr.bits.mtype = FRAME_TYPE_PROPRIETARY; - break; - } - default: - return LORAWAN_STATUS_PARAMETER_INVALID; - } - -// Filter fPorts -// TODO: Does not work with PROPRIETARY messages -// if( IsFPortAllowed( mcpsRequest->fport ) == false ) { -// return LORAWAN_STATUS_PARAMETER_INVALID; -// } - - if (_params.sys_params.adr_on == false) { - if (_lora_phy->verify_tx_datarate(datarate, false) == true) { - _params.sys_params.channel_data_rate = datarate; - } else { - return LORAWAN_STATUS_PARAMETER_INVALID; - } - } - - lorawan_status_t status = send(&machdr, mcpsRequest->fport, mcpsRequest->f_buffer, - mcpsRequest->f_buffer_size); - if (status == LORAWAN_STATUS_OK) { - _mcps_confirmation.req_type = mcpsRequest->type; - _params.flags.bits.mcps_req = 1; - } else { - _params.is_node_ack_requested = false; - } - - return status; -} - -lorawan_status_t LoRaMac::LoRaMacSetTxTimer(uint32_t TxDutyCycleTime) -{ - _lora_time.start(tx_next_packet_timer, TxDutyCycleTime); - return LORAWAN_STATUS_OK; -} - -lorawan_status_t LoRaMac::LoRaMacStopTxTimer() -{ - _lora_time.stop(tx_next_packet_timer); - return LORAWAN_STATUS_OK; -} - -void LoRaMac::LoRaMacTestRxWindowsOn(bool enable) -{ - _params.is_rx_window_enabled = enable; -} - -void LoRaMac::LoRaMacTestSetMic(uint16_t txPacketCounter) -{ - _params.ul_frame_counter = txPacketCounter; - _params.is_ul_frame_counter_fixed = true; -} - -void LoRaMac::LoRaMacTestSetDutyCycleOn(bool enable) -{ - if (_lora_phy->verify_duty_cycle(enable) == true) { - _params.is_dutycycle_on = enable; - } -} - -void LoRaMac::LoRaMacTestSetChannel(uint8_t channel) -{ - _params.channel = channel; -} -#endif diff --git a/features/lorawan/lorastack/mac/LoRaMac.h b/features/lorawan/lorastack/mac/LoRaMac.h index f81e7a7a0a..8ec5a8793f 100644 --- a/features/lorawan/lorastack/mac/LoRaMac.h +++ b/features/lorawan/lorastack/mac/LoRaMac.h @@ -672,136 +672,6 @@ private: bool _continuous_rx2_window_open; device_class_t _device_class; - -#if defined(LORAWAN_COMPLIANCE_TEST) -public: // Test interface - - /** - * @brief Set forth an MLME request. - * - * @details The MAC layer management entity handles the management services. - * - * @param [in] request The MLME request to perform. - * Refer to \ref loramac_mlme_req_t. - * - * @return `lorawan_status_t` The status of the operation. The possible values are: - * \ref LORAWAN_STATUS_OK - * \ref LORAWAN_STATUS_BUSY - * \ref LORAWAN_STATUS_SERVICE_UNKNOWN - * \ref LORAWAN_STATUS_PARAMETER_INVALID - * \ref LORAWAN_STATUS_NO_NETWORK_JOINED - * \ref LORAWAN_STATUS_LENGTH_ERROR - * \ref LORAWAN_STATUS_DEVICE_OFF - */ - lorawan_status_t mlme_request(loramac_mlme_req_t *request); - - /** - * @brief Set forth an MCPS request. - * - * @details The MAC Common Part Sublayer handles the data services. The following - * code-snippet shows how to use the API to send an unconfirmed - * LoRaMAC frame. - * - * @code - * - * uint8_t buffer[] = {1, 2, 3}; - * - * loramac_compliance_test_req_t request; - * request.type = MCPS_UNCONFIRMED; - * request.fport = 1; - * request.f_buffer = buffer; - * request.f_buffer_size = sizeof(buffer); - * - * if (test_request(&request) == LORAWAN_STATUS_OK) { - * // Service started successfully. Waiting for the MCPS-Confirm event - * } - * - * @endcode - * - * @param [in] request The test request to perform. - * Refer to \ref loramac_compliance_test_req_t. - * - * @return `lorawan_status_t` The status of the operation. The possible values are: - * \ref LORAWAN_STATUS_OK - * \ref LORAWAN_STATUS_BUSY - * \ref LORAWAN_STATUS_SERVICE_UNKNOWN - * \ref LORAWAN_STATUS_PARAMETER_INVALID - * \ref LORAWAN_STATUS_NO_NETWORK_JOINED - * \ref LORAWAN_STATUS_LENGTH_ERROR - * \ref LORAWAN_STATUS_DEVICE_OFF - */ - lorawan_status_t test_request(loramac_compliance_test_req_t *request); - - /** - * \brief LoRaMAC set tx timer. - * - * \details Sets up a timer for next transmission (application specific timers). - * - * \param [in] NextTxTime - Periodic time for next uplink. - - * \retval `lorawan_status_t` The status of the operation. The possible values are: - * \ref LORAWAN_STATUS_OK - * \ref LORAWAN_STATUS_PARAMETER_INVALID - */ - lorawan_status_t LoRaMacSetTxTimer(uint32_t NextTxTime); - - /** - * \brief LoRaMAC stop tx timer. - * - * \details Stops the next tx timer. - * - * \retval `lorawan_status_t` The status of the operation. The possible values are: - * \ref LORAWAN_STATUS_OK - * \ref LORAWAN_STATUS_PARAMETER_INVALID - */ - lorawan_status_t LoRaMacStopTxTimer(); - - /** - * \brief Enabled or disables the reception windows - * - * \details This is a test function. It shall be used for testing purposes only. - * Changing this attribute may lead to a non-conformance LoRaMac operation. - * - * \param [in] enable - Enabled or disables the reception windows - */ - void LoRaMacTestRxWindowsOn(bool enable); - - /** - * \brief Enables the MIC field test - * - * \details This is a test function. It shall be used for testing purposes only. - * Changing this attribute may lead to a non-conformance LoRaMac operation. - * - * \param [in] txPacketCounter - Fixed Tx packet counter value - */ - void LoRaMacTestSetMic(uint16_t txPacketCounter); - - /** - * \brief Enabled or disables the duty cycle - * - * \details This is a test function. It shall be used for testing purposes only. - * Changing this attribute may lead to a non-conformance LoRaMac operation. - * - * \param [in] enable - Enabled or disables the duty cycle - */ - void LoRaMacTestSetDutyCycleOn(bool enable); - - /** - * \brief Sets the channel index - * - * \details This is a test function. It shall be used for testing purposes only. - * Changing this attribute may lead to a non-conformance LoRaMac operation. - * - * \param [in] channel - Channel index - */ - void LoRaMacTestSetChannel(uint8_t channel); - -private: - /** - * Timer to handle the application data transmission duty cycle - */ - timer_event_t tx_next_packet_timer; -#endif }; #endif // MBED_LORAWAN_MAC_H__ diff --git a/features/lorawan/lorawan_types.h b/features/lorawan/lorawan_types.h index 6f57c3c061..9d7edb7ae6 100644 --- a/features/lorawan/lorawan_types.h +++ b/features/lorawan/lorawan_types.h @@ -101,6 +101,8 @@ typedef enum lorawan_status { LORAWAN_STATUS_NO_ACTIVE_SESSIONS = -1017, /**< Services not started - No active session */ LORAWAN_STATUS_IDLE = -1018, /**< Services started - Idle at the moment */ #if defined(LORAWAN_COMPLIANCE_TEST) + //Deprecated - will replace the code -1019 with something + //else in future. LORAWAN_STATUS_COMPLIANCE_TEST_ON = -1019, /**< Compliance test - is on-going */ #endif LORAWAN_STATUS_DUTYCYCLE_RESTRICTED = -1020, /**< Transmission will continue after duty cycle backoff*/ diff --git a/features/lorawan/system/lorawan_data_structures.h b/features/lorawan/system/lorawan_data_structures.h index 038248fa8d..e3f2418820 100644 --- a/features/lorawan/system/lorawan_data_structures.h +++ b/features/lorawan/system/lorawan_data_structures.h @@ -838,9 +838,6 @@ typedef enum device_states { 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; @@ -1284,117 +1281,4 @@ typedef struct { } loramac_protocol_params; - -#if defined(LORAWAN_COMPLIANCE_TEST) - -typedef struct { - /*! - * MLME-Request type. - */ - mlme_type_t type; - - mlme_cw_tx_mode_t cw_tx_mode; -} loramac_mlme_req_t; - -typedef struct { - /*! - * Compliance test request - */ - mcps_type_t type; - - /*! - * Frame port field. Must be set if the payload is not empty. Use the - * application-specific frame port values: [1...223]. - * - * LoRaWAN Specification V1.0.2, chapter 4.3.2. - */ - uint8_t fport; - - /*! - * Uplink datarate, if ADR is off. - */ - int8_t data_rate; - /*! - * The number of trials to transmit the frame, if the LoRaMAC layer did not - * receive an acknowledgment. The MAC performs a datarate adaptation - * according to the LoRaWAN Specification V1.0.2, chapter 18.4, as in - * the following table: - * - * Transmission nb | Data Rate - * ----------------|----------- - * 1 (first) | DR - * 2 | DR - * 3 | max(DR-1,0) - * 4 | max(DR-1,0) - * 5 | max(DR-2,0) - * 6 | max(DR-2,0) - * 7 | max(DR-3,0) - * 8 | max(DR-3,0) - * - * Note that if nb_trials is set to 1 or 2, the MAC will not decrease - * the datarate, if the LoRaMAC layer did not receive an acknowledgment. - */ - uint8_t nb_trials; - - /** Payload data - * - * A pointer to the buffer of the frame payload. - */ - uint8_t f_buffer[LORAMAC_PHY_MAXPAYLOAD]; - - /** Payload size - * - * The size of the frame payload. - */ - uint16_t f_buffer_size; - -} loramac_compliance_test_req_t; - -/** LoRaWAN compliance tests support data - * - */ -typedef struct compliance_test { - /** Is test running - * - */ - bool running; - /** State of test - * - */ - uint8_t state; - /** Is TX confirmed - * - */ - bool is_tx_confirmed; - /** Port used by the application - * - */ - uint8_t app_port; - /** Maximum size of data used by application - * - */ - uint8_t app_data_size; - /** Data provided by application - * - */ - uint8_t app_data_buffer[MBED_CONF_LORA_TX_MAX_SIZE]; - /** Downlink counter - * - */ - uint16_t downlink_counter; - /** Is link check required - * - */ - bool link_check; - /** Demodulation margin - * - */ - uint8_t demod_margin; - /** Number of gateways - * - */ - uint8_t nb_gateways; -} compliance_test_t; -#endif - #endif /* LORAWAN_SYSTEM_LORAWAN_DATA_STRUCTURES_H_ */