diff --git a/srsenb/src/stack/mac/scheduler_ue.cc b/srsenb/src/stack/mac/scheduler_ue.cc index f5c5262d4..e8efa3365 100644 --- a/srsenb/src/stack/mac/scheduler_ue.cc +++ b/srsenb/src/stack/mac/scheduler_ue.cc @@ -444,16 +444,13 @@ int sched_ue::generate_format1(dl_harq_proc* h, data->nof_pdu_elems[0]++; conres_ce_pending = false; Info("SCHED: Added MAC Contention Resolution CE for rnti=0x%x\n", rnti); - } else { - // Add TA CE - // TODO: Can't put it in Msg4 because current srsUE doesn't read it - while (nof_ta_cmd > 0 && rem_tbs > 2) { - data->pdu[0][data->nof_pdu_elems[0]].lcid = srslte::sch_subh::TA_CMD; - data->nof_pdu_elems[0]++; - Info("SCHED: Added MAC TA CMD CE for rnti=0x%x\n", rnti); - nof_ta_cmd--; - rem_tbs -= 2; - } + } + while (nof_ta_cmd > 0 && rem_tbs > 2) { + data->pdu[0][data->nof_pdu_elems[0]].lcid = srslte::sch_subh::TA_CMD; + data->nof_pdu_elems[0]++; + Info("SCHED: Added MAC TA CMD CE for rnti=0x%x\n", rnti); + nof_ta_cmd--; + rem_tbs -= 2; } do { @@ -805,7 +802,7 @@ uint32_t sched_ue::get_pending_dl_new_data_unlocked() pending_data += lch[i].buf_retx + lch[i].buf_tx; } } - if (not is_first_dl_tx() and nof_ta_cmd > 0) { + if (nof_ta_cmd > 0) { pending_data += nof_ta_cmd * 2; } return pending_data; diff --git a/srsue/src/stack/mac/demux.cc b/srsue/src/stack/mac/demux.cc index 1a45a9055..32f2d06da 100644 --- a/srsue/src/stack/mac/demux.cc +++ b/srsue/src/stack/mac/demux.cc @@ -97,12 +97,20 @@ void demux::push_pdu_temp_crnti(uint8_t* buff, uint32_t nof_bytes) pending_mac_msg.init_rx(nof_bytes); pending_mac_msg.parse_packet(buff); - // Look for Contention Resolution UE ID + // Look for Contention Resolution UE ID and TA commands is_uecrid_successful = false; - while (pending_mac_msg.next() && !is_uecrid_successful) { + while (pending_mac_msg.next()) { if (pending_mac_msg.get()->ce_type() == srslte::sch_subh::CON_RES_ID) { Debug("Found Contention Resolution ID CE\n"); is_uecrid_successful = mac->contention_resolution_id_rcv(pending_mac_msg.get()->get_con_res_id()); + } else if (pending_mac_msg.get()->ce_type() == srslte::sch_subh::TA_CMD) { + phy_h->set_timeadv(pending_mac_msg.get()->get_ta_cmd()); + Info("Received TA=%d (%d/%d) \n", pending_mac_msg.get()->get_ta_cmd(), + time_alignment_timer->value(), time_alignment_timer->duration()); + // Start or restart timeAlignmentTimer only if set + if (time_alignment_timer->is_set()) { + time_alignment_timer->run(); + } } } pending_mac_msg.reset();