From 341b5e15665fcda9aa22cbc3de05e7584d5d650d Mon Sep 17 00:00:00 2001 From: Hasnain Virk Date: Sun, 21 Oct 2018 20:59:00 +0300 Subject: [PATCH] Managing Confirmed traffic based on NbTrans In 1.1, NbTrans governs both unconfirmed and confirmed traffic. We cannot set number of retries ourselves. Based upon NbTrans received in linkADRReq command, we will retry. If NbTrans is 1, we will send only one message and if ack is not received we will generate TX error event. Its the NS now which controls how many retransmission a device can do without incrementing Frame counter. When we fail with TX error after not receiving an ack, we increment the frame counter. This is necessary as the NS will drop anything with the previous counter and it can happen that the NS may have sent an ack but we didn't receive it. --- features/lorawan/lorastack/mac/LoRaMac.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/features/lorawan/lorastack/mac/LoRaMac.cpp b/features/lorawan/lorastack/mac/LoRaMac.cpp index 9f64113a5e..4b34d6d391 100644 --- a/features/lorawan/lorastack/mac/LoRaMac.cpp +++ b/features/lorawan/lorastack/mac/LoRaMac.cpp @@ -155,6 +155,10 @@ void LoRaMac::post_process_mcps_req() _mcps_confirmation.ack_received = false; _mcps_indication.is_ack_recvd = false; } else { + if (_params.server_type == LW1_1) { + // because network server will not accept un-incremented fcnt + _params.ul_frame_counter++; + } _mcps_confirmation.status = LORAMAC_EVENT_INFO_STATUS_ERROR; } @@ -567,7 +571,7 @@ void LoRaMac::handle_data_frame(const uint8_t *const payload, multicast_params_t *cur_multicast_params; uint32_t address = 0; uint32_t downlink_counter = 0; - seq_counter_type_t cnt_type; + seq_counter_type_t cnt_type = NFCNT_DOWN; uint8_t *nwk_skey = _params.keys.nwk_skey; uint8_t *mic_key = _params.keys.nwk_skey; uint8_t *app_skey = _params.keys.app_skey; @@ -954,7 +958,7 @@ bool LoRaMac::continue_joining_process() bool LoRaMac::continue_sending_process() { - if (_params.ack_timeout_retry_counter > _params.max_ack_timeout_retries) { + if (_params.ack_timeout_retry_counter >= _params.max_ack_timeout_retries) { _lora_time.stop(_params.timers.ack_timeout_timer); return false; } @@ -1323,7 +1327,6 @@ lorawan_status_t LoRaMac::schedule_tx() 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); @@ -1517,7 +1520,7 @@ int16_t LoRaMac::prepare_ongoing_tx(const uint8_t port, if (flags & MSG_PROPRIETARY_FLAG) { _ongoing_tx_msg.type = MCPS_PROPRIETARY; _ongoing_tx_msg.fport = port; - _ongoing_tx_msg.nb_trials = _params.sys_params.nb_trans; + _ongoing_tx_msg.nb_trials = _params.sys_params.nb_trans > 0 ? _params.sys_params.nb_trans : 1; // a proprietary frame only includes an MHDR field which contains MTYPE field. // Everything else is at the discretion of the implementer fopts_len = 0; @@ -1572,7 +1575,11 @@ lorawan_status_t LoRaMac::send_ongoing_tx() machdr.bits.mtype = FRAME_TYPE_DATA_UNCONFIRMED_UP; } else if (_ongoing_tx_msg.type == MCPS_CONFIRMED) { machdr.bits.mtype = FRAME_TYPE_DATA_CONFIRMED_UP; - _params.max_ack_timeout_retries = _ongoing_tx_msg.nb_trials; + if (_params.server_type == LW1_1) { + _params.max_ack_timeout_retries = _params.sys_params.nb_trans; + } else { + _params.max_ack_timeout_retries = _ongoing_tx_msg.nb_trials; + } } else if (_ongoing_tx_msg.type == MCPS_PROPRIETARY) { machdr.bits.mtype = FRAME_TYPE_PROPRIETARY; } else { @@ -2332,7 +2339,7 @@ lorawan_status_t LoRaMac::calculate_userdata_mic() if (_params.is_srv_ack_requested) { args = _params.counterForAck; } - args |= _params.sys_params.channel_data_rate << 16; + args |= ((uint8_t) _params.sys_params.channel_data_rate) << 16; args |= _params.channel << 24; if (0 != _lora_crypto.compute_mic(_params.tx_buffer, _params.tx_buffer_len,