diff --git a/openair2/LAYER2/NR_MAC_UE/config_ue.c b/openair2/LAYER2/NR_MAC_UE/config_ue.c index d4515ac235dbbec04744a3fb88bb44b2e5603922..46b6397cdf2d95a9b42273af983b47cf06331382 100644 --- a/openair2/LAYER2/NR_MAC_UE/config_ue.c +++ b/openair2/LAYER2/NR_MAC_UE/config_ue.c @@ -511,16 +511,26 @@ void configure_ss_coreset(NR_UE_MAC_INST_t *mac, mac->BWP_coresets[i] = NULL; } -// todo handle mac_LogicalChannelConfig -int nr_rrc_mac_config_req_ue_logicalChannelBearer( - module_id_t module_id, - int cc_idP, - uint8_t gNB_index, - long logicalChannelIdentity, - bool status){ - NR_UE_MAC_INST_t *mac = get_mac_inst(module_id); - mac->logicalChannelBearer_exist[logicalChannelIdentity] = status; - return 0; +void nr_rrc_mac_config_req_ue_logicalChannelBearer(module_id_t module_id, + struct NR_CellGroupConfig__rlc_BearerToAddModList *rlc_toadd_list, + struct NR_CellGroupConfig__rlc_BearerToReleaseList *rlc_torelease_list) +{ + NR_UE_MAC_INST_t *mac = get_mac_inst(module_id); + if(rlc_toadd_list) { + for (int i = 0; i < rlc_toadd_list->list.count; i++) { + NR_RLC_BearerConfig_t *rlc_bearer = rlc_toadd_list->list.array[i]; + int id = rlc_bearer->logicalChannelIdentity - 1; + mac->active_RLC_bearer[id] = true; + } + } + if (rlc_torelease_list) { + for (int i = 0; i < rlc_torelease_list->list.count; i++) { + if(rlc_torelease_list->list.array[i]) { + int id = *rlc_torelease_list->list.array[i] - 1; + mac->active_RLC_bearer[id] = false; + } + } + } } diff --git a/openair2/LAYER2/NR_MAC_UE/mac_defs.h b/openair2/LAYER2/NR_MAC_UE/mac_defs.h index 96a968b33a0fbe50b9fa3eea2d8cb8f91688b7e3..77a948469537cf728ae5e9e68985044fde9f9874 100644 --- a/openair2/LAYER2/NR_MAC_UE/mac_defs.h +++ b/openair2/LAYER2/NR_MAC_UE/mac_defs.h @@ -503,8 +503,8 @@ typedef struct { uint8_t BSR_reporting_active; /// LogicalChannelConfig has bearer. - bool logicalChannelBearer_exist[NR_MAX_NUM_LCID]; - NR_UE_SCHEDULING_INFO scheduling_info; + bool active_RLC_bearer[NR_MAX_NUM_LCID]; + NR_UE_SCHEDULING_INFO scheduling_info; /// PHR uint8_t PHR_reporting_active; diff --git a/openair2/LAYER2/NR_MAC_UE/mac_proto.h b/openair2/LAYER2/NR_MAC_UE/mac_proto.h index adc9353adaaac2e0f9c4218ed384ffa4fed911f6..1817a67a0c3e132a8297cf9968f2e3aa4391719d 100644 --- a/openair2/LAYER2/NR_MAC_UE/mac_proto.h +++ b/openair2/LAYER2/NR_MAC_UE/mac_proto.h @@ -63,17 +63,9 @@ int8_t nr_ue_decode_BCCH_DL_SCH(module_id_t module_id, uint8_t *pduP, uint32_t pdu_len); -/**\brief primitive from RRC layer to MAC layer to set if bearer exists for a logical channel. todo handle mac_LogicalChannelConfig - \param module_id module id - \param cc_id component carrier id - \param gNB_index gNB index - \param long logicalChannelIdentity - \param bool status*/ -int nr_rrc_mac_config_req_ue_logicalChannelBearer(module_id_t module_id, - int cc_idP, - uint8_t gNB_index, - long logicalChannelIdentity, - bool status); +void nr_rrc_mac_config_req_ue_logicalChannelBearer(module_id_t module_id, + struct NR_CellGroupConfig__rlc_BearerToAddModList *rlc_toadd_list, + struct NR_CellGroupConfig__rlc_BearerToReleaseList *rlc_torelease_list); void nr_rrc_mac_config_req_scg(module_id_t module_id, int cc_idP, diff --git a/openair2/LAYER2/NR_MAC_UE/main_ue_nr.c b/openair2/LAYER2/NR_MAC_UE/main_ue_nr.c index 3d23ce273b2b18b91bd78cdc7f7952cdc3ab8caa..3f540f5b130ddec4779a87ca899d31f1062db284 100644 --- a/openair2/LAYER2/NR_MAC_UE/main_ue_nr.c +++ b/openair2/LAYER2/NR_MAC_UE/main_ue_nr.c @@ -78,7 +78,10 @@ NR_UE_MAC_INST_t * nr_l2_init_ue(NR_UE_RRC_INST_t* rrc_inst) { nr_pdcp_layer_init(); nr_pdcp_add_drbs(ENB_FLAG_NO, nr_ue_mac_inst->crnti, rbconfig->drb_ToAddModList, 0, NULL, NULL); nr_rlc_add_drb(nr_ue_mac_inst->crnti, rbconfig->drb_ToAddModList->list.array[0]->drb_Identity, rlc_rbconfig); - nr_ue_mac_inst->logicalChannelBearer_exist[4] = true; + struct NR_CellGroupConfig__rlc_BearerToAddModList rlc_toadd_list; + rlc_toadd_list.list.count = 1; + rlc_toadd_list.list.array[0] = rlc_rbconfig; + nr_rrc_mac_config_req_ue_logicalChannelBearer(0, &rlc_toadd_list, NULL); // free memory free_nr_noS1_bearer_config(&rbconfig, &rlc_rbconfig); diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c b/openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c index 0323dd90d3e34884dc38815048d62cfadd363a5e..334462bb1b704ed1187355e9656e3fb75d5ae06a 100644 --- a/openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c +++ b/openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c @@ -1119,8 +1119,6 @@ void nr_ue_ul_scheduler(nr_uplink_indication_t *ul_info) bool nr_update_bsr(module_id_t module_idP, frame_t frameP, slot_t slotP, uint8_t gNB_index) { bool bsr_regular_triggered = false; - uint8_t lcid; - uint8_t lcgid; uint8_t num_lcid_with_data = 0; // for LCID with data only if LCGID is defined uint32_t lcgid_buffer_remain[NR_MAX_NUM_LCGID] = {0,0,0,0,0,0,0,0}; int32_t lcid_bytes_in_buffer[NR_MAX_NUM_LCID]; @@ -1137,37 +1135,38 @@ bool nr_update_bsr(module_id_t module_idP, frame_t frameP, slot_t slotP, uint8_t // Reset All BSR Infos lcid_bytes_in_buffer[0] = 0; NR_UE_MAC_INST_t *mac = get_mac_inst(module_idP); - for (lcid=DCCH; lcid < NR_MAX_NUM_LCID; lcid++) { + // TO BE NOTED LCID = 0 is excluded from buffers + // so they need to be addressed with lcid - 1 + for (int lcid = 1; lcid <= NR_MAX_NUM_LCID; lcid++) { // Reset transmission status - lcid_bytes_in_buffer[lcid] = 0; - mac->scheduling_info.LCID_status[lcid]=LCID_EMPTY; + lcid_bytes_in_buffer[lcid - 1] = 0; + mac->scheduling_info.LCID_status[lcid - 1] = LCID_EMPTY; } - for (lcgid=0; lcgid < NR_MAX_NUM_LCGID; lcgid++) { + for (int lcgid = 0; lcgid < NR_MAX_NUM_LCGID; lcgid++) { // Reset Buffer Info - mac->scheduling_info.BSR[lcgid]=0; - mac->scheduling_info.BSR_bytes[lcgid]=0; + mac->scheduling_info.BSR[lcgid] = 0; + mac->scheduling_info.BSR_bytes[lcgid] = 0; } //Get Buffer Occupancy and fill lcid_reordered_array - for (lcid=DCCH; lcid < NR_MAX_NUM_LCID; lcid++) { - //if (mac->logicalChannelConfig[lcid]) { - if (mac->logicalChannelBearer_exist[lcid] ) { // todo - lcgid = mac->scheduling_info.LCGID[lcid]; + for (int lcid = 1; lcid <= NR_MAX_NUM_LCID; lcid++) { + if (mac->active_RLC_bearer[lcid - 1]) { // todo + int lcgid = mac->scheduling_info.LCGID[lcid - 1]; // Store already available data to transmit per Group if (lcgid < NR_MAX_NUM_LCGID) { - lcgid_buffer_remain[lcgid] += mac->scheduling_info.LCID_buffer_remain[lcid]; + lcgid_buffer_remain[lcgid] += mac->scheduling_info.LCID_buffer_remain[lcid - 1]; } mac_rlc_status_resp_t rlc_status = mac_rlc_status_ind(module_idP, mac->crnti,gNB_index,frameP,slotP,ENB_FLAG_NO,MBMS_FLAG_NO, lcid, 0, 0); - lcid_bytes_in_buffer[lcid] = rlc_status.bytes_in_buffer; + lcid_bytes_in_buffer[lcid - 1] = rlc_status.bytes_in_buffer; if (rlc_status.bytes_in_buffer > 0) { LOG_D(NR_MAC,"[UE %d] PDCCH Tick : LCID%d LCGID%d has data to transmit =%d bytes at frame %d slot %d\n", module_idP, lcid,lcgid,rlc_status.bytes_in_buffer,frameP,slotP); - mac->scheduling_info.LCID_status[lcid] = LCID_NOT_EMPTY; + mac->scheduling_info.LCID_status[lcid - 1] = LCID_NOT_EMPTY; //Update BSR_bytes and position in lcid_reordered_array only if Group is defined if (lcgid < NR_MAX_NUM_LCGID) { @@ -1181,7 +1180,7 @@ bool nr_update_bsr(module_id_t module_idP, frame_t frameP, slot_t slotP, uint8_t //if (mac->logicalChannelConfig[lcid]->ul_SpecificParameters->priority <= highest_priority) { if (1) { // todo //Insert if priority is higher or equal (lower or equal in value) - for (pos_next=num_lcid_with_data-1; pos_next > array_index; pos_next--) { + for (pos_next = num_lcid_with_data - 1; pos_next > array_index; pos_next--) { lcid_reordered_array[pos_next] = lcid_reordered_array[pos_next - 1]; } @@ -1190,7 +1189,7 @@ bool nr_update_bsr(module_id_t module_idP, frame_t frameP, slot_t slotP, uint8_t } array_index ++; - } while ((array_index < num_lcid_with_data) && (array_index < NR_MAX_NUM_LCID)); + } while ((array_index < num_lcid_with_data) && (array_index <= NR_MAX_NUM_LCID)); } } } @@ -1204,7 +1203,7 @@ bool nr_update_bsr(module_id_t module_idP, frame_t frameP, slot_t slotP, uint8_t lcid_reordered_array[2]); for (array_index = 0; array_index < num_lcid_with_data; array_index++) { - lcid = lcid_reordered_array[array_index]; + int lcid = lcid_reordered_array[array_index]; /* UL data, for a logical channel which belongs to a LCG, becomes available for transmission in the RLC entity either the data belongs to a logical channel with higher priority than the priorities of the logical channels @@ -1214,7 +1213,7 @@ bool nr_update_bsr(module_id_t module_idP, frame_t frameP, slot_t slotP, uint8_t bsr_regular_triggered = true; LOG_D(NR_MAC, "[UE %d] PDCCH Tick : MAC BSR Triggered LCID%d LCGID%d data become available at frame %d slot %d\n", module_idP, lcid, - mac->scheduling_info.LCGID[lcid], + mac->scheduling_info.LCGID[lcid - 1], frameP, slotP); break; } @@ -1232,8 +1231,8 @@ bool nr_update_bsr(module_id_t module_idP, frame_t frameP, slot_t slotP, uint8_t } //Store Buffer Occupancy in remain buffers for next TTI - for (lcid = DCCH; lcid < NR_MAX_NUM_LCID; lcid++) { - mac->scheduling_info.LCID_buffer_remain[lcid] = lcid_bytes_in_buffer[lcid]; + for (int lcid = 1; lcid <= NR_MAX_NUM_LCID; lcid++) { + mac->scheduling_info.LCID_buffer_remain[lcid - 1] = lcid_bytes_in_buffer[lcid - 1]; } return bsr_regular_triggered; @@ -2694,21 +2693,21 @@ void nr_ue_get_sdu_mac_ce_post(module_id_t module_idP, uint8_t gNB_index, uint8_t *ulsch_buffer, uint16_t buflen, - NR_UE_MAC_CE_INFO *mac_ce_p) { + NR_UE_MAC_CE_INFO *mac_ce_p) +{ NR_UE_MAC_INST_t *mac = get_mac_inst(module_idP); // Compute BSR Values and update Nb LCGID with data after multiplexing unsigned short padding_len = 0; - uint8_t lcid = 0; int lcg_id = 0; int num_lcg_id_with_data = 0; int lcg_id_bsr_trunc = 0; for (lcg_id = 0; lcg_id < NR_MAX_NUM_LCGID; lcg_id++) { - if (mac_ce_p->bsr_ce_len == sizeof(NR_BSR_SHORT)) { + if (mac_ce_p->bsr_ce_len == sizeof(NR_BSR_SHORT)) { mac->scheduling_info.BSR[lcg_id] = nr_locate_BsrIndexByBufferSize(NR_SHORT_BSR_TABLE, NR_SHORT_BSR_TABLE_SIZE, mac->scheduling_info.BSR_bytes[lcg_id]); - } else { + } else { mac->scheduling_info.BSR[lcg_id] = nr_locate_BsrIndexByBufferSize(NR_LONG_BSR_TABLE, NR_LONG_BSR_TABLE_SIZE, mac->scheduling_info.BSR_bytes[lcg_id]); - } + } if (mac->scheduling_info.BSR_bytes[lcg_id]) { num_lcg_id_with_data++; lcg_id_bsr_trunc = lcg_id; @@ -2742,8 +2741,8 @@ void nr_ue_get_sdu_mac_ce_post(module_id_t module_idP, if (num_lcg_id_with_data > 1) { // REPORT SHORT TRUNCATED BSR //Get LCGID of highest priority LCID with data (todo) - for (lcid = DCCH; lcid < NR_MAX_NUM_LCID; lcid++) { - lcg_id = mac->scheduling_info.LCGID[lcid]; + for (int lcid = 1; lcid <= NR_MAX_NUM_LCID; lcid++) { + lcg_id = mac->scheduling_info.LCGID[lcid - 1]; if ((lcg_id < NR_MAX_NUM_LCGID) && (mac->scheduling_info.BSR_bytes[lcg_id])) { lcg_id_bsr_trunc = lcg_id; } @@ -2855,7 +2854,8 @@ uint8_t nr_ue_get_sdu(module_id_t module_idP, sub_frame_t subframe, uint8_t gNB_index, uint8_t *ulsch_buffer, - uint16_t buflen) { + uint16_t buflen) +{ NR_UE_MAC_CE_INFO mac_ce_info; NR_UE_MAC_CE_INFO *mac_ce_p=&mac_ce_info; int16_t buflen_remain = 0; @@ -2891,11 +2891,12 @@ uint8_t nr_ue_get_sdu(module_id_t module_idP, // Check for DCCH first // TO DO: Multiplex in the order defined by the logical channel prioritization - for (int lcid = UL_SCH_LCID_SRB1; lcid < NR_MAX_NUM_LCID; lcid++) { + for (int lcid = 1; lcid <= NR_MAX_NUM_LCID; lcid++) { + if (!mac->active_RLC_bearer[lcid - 1]) + continue; buflen_remain = buflen - (mac_ce_p->total_mac_pdu_header_len + mac_ce_p->sdu_length_total + sh_size); - LOG_D(NR_MAC, "In %s: [UE %d] [%d.%d] UL-DXCH -> ULSCH, RLC with LCID 0x%02x (TBS %d bytes, sdu_length_total %d bytes, MAC header len %d bytes, buflen_remain %d bytes)\n", - __FUNCTION__, + LOG_D(NR_MAC, "[UE %d] [%d.%d] UL-DXCH -> ULSCH, RLC with LCID 0x%02x (TBS %d bytes, sdu_length_total %d bytes, MAC header len %d bytes, buflen_remain %d bytes)\n", module_idP, frameP, subframe, @@ -2905,7 +2906,7 @@ uint8_t nr_ue_get_sdu(module_id_t module_idP, mac_ce_p->tot_mac_ce_len, buflen_remain); - while (buflen_remain > 0){ + while (buflen_remain > 0) { // Pointer used to build the MAC sub-PDU headers in the ULSCH buffer for each SDU NR_MAC_SUBHEADER_LONG *header = (NR_MAC_SUBHEADER_LONG *) pdu; @@ -2924,16 +2925,14 @@ uint8_t nr_ue_get_sdu(module_id_t module_idP, 0, 0); - AssertFatal(buflen_remain >= sdu_length, "In %s: LCID = 0x%02x RLC has segmented %d bytes but MAC has max %d remaining bytes\n", - __FUNCTION__, + AssertFatal(buflen_remain >= sdu_length, "LCID = 0x%02x RLC has segmented %d bytes but MAC has max %d remaining bytes\n", lcid, sdu_length, buflen_remain); if (sdu_length > 0) { - LOG_D(NR_MAC, "In %s: [UE %d] [%d.%d] UL-DXCH -> ULSCH, Generating UL MAC sub-PDU for SDU %d, length %d bytes, RB with LCID 0x%02x (buflen (TBS) %d bytes)\n", - __FUNCTION__, + LOG_D(NR_MAC, "[UE %d] [%d.%d] UL-DXCH -> ULSCH, Generating UL MAC sub-PDU for SDU %d, length %d bytes, RB with LCID 0x%02x (buflen (TBS) %d bytes)\n", module_idP, frameP, subframe, @@ -2962,20 +2961,20 @@ uint8_t nr_ue_get_sdu(module_id_t module_idP, } else { pdu -= sh_size; - LOG_D(NR_MAC, "In %s: no data to transmit for RB with LCID 0x%02x\n", __FUNCTION__, lcid); + LOG_D(NR_MAC, "no data to transmit for RB with LCID 0x%02x\n", lcid); break; } buflen_remain = buflen - (mac_ce_p->total_mac_pdu_header_len + mac_ce_p->sdu_length_total + sh_size); //Update Buffer remain and BSR bytes after transmission - mac->scheduling_info.LCID_buffer_remain[lcid] -= sdu_length; - mac->scheduling_info.BSR_bytes[mac->scheduling_info.LCGID[lcid]] -= sdu_length; + mac->scheduling_info.LCID_buffer_remain[lcid - 1] -= sdu_length; + mac->scheduling_info.BSR_bytes[mac->scheduling_info.LCGID[lcid- 1]] -= sdu_length; LOG_D(NR_MAC, "[UE %d] Update BSR [%d.%d] BSR_bytes for LCG%d=%d\n", - module_idP, frameP, subframe, mac->scheduling_info.LCGID[lcid], - mac->scheduling_info.BSR_bytes[mac->scheduling_info.LCGID[lcid]]); - if (mac->scheduling_info.BSR_bytes[mac->scheduling_info.LCGID[lcid]] < 0) - mac->scheduling_info.BSR_bytes[mac->scheduling_info.LCGID[lcid]] = 0; + module_idP, frameP, subframe, mac->scheduling_info.LCGID[lcid - 1], + mac->scheduling_info.BSR_bytes[mac->scheduling_info.LCGID[lcid - 1]]); + if (mac->scheduling_info.BSR_bytes[mac->scheduling_info.LCGID[lcid - 1]] < 0) + mac->scheduling_info.BSR_bytes[mac->scheduling_info.LCGID[lcid - 1]] = 0; } } diff --git a/openair2/RRC/NR_UE/rrc_UE.c b/openair2/RRC/NR_UE/rrc_UE.c index 6c7d277583e664599fc2a565244cf2cf796e4d08..cde5e0f13b53fcebe16fe2274493f349cf3b1e6a 100644 --- a/openair2/RRC/NR_UE/rrc_UE.c +++ b/openair2/RRC/NR_UE/rrc_UE.c @@ -163,7 +163,8 @@ int8_t nr_rrc_ue_process_rrcReconfiguration(const module_id_t module_id, NR_RRCR return -1; } - nr_rrc_manage_rlc_bearers(cellGroupConfig, &NR_UE_rrc_inst[module_id], 0, NR_UE_rrc_inst[module_id].rnti); + if(get_softmodem_params()->sa || get_softmodem_params()->nsa) + nr_rrc_manage_rlc_bearers(cellGroupConfig, &NR_UE_rrc_inst[module_id], 0, module_id, NR_UE_rrc_inst[module_id].rnti); if(get_softmodem_params()->sa || get_softmodem_params()->nsa) { if (LOG_DEBUGFLAG(DEBUG_ASN1)) { @@ -222,7 +223,8 @@ int8_t nr_rrc_ue_process_meas_config(NR_MeasConfig_t *meas_config){ } -void process_nsa_message(NR_UE_RRC_INST_t *rrc, nsa_message_t nsa_message_type, void *message,int msg_len) { +void process_nsa_message(NR_UE_RRC_INST_t *rrc, nsa_message_t nsa_message_type, void *message,int msg_len) +{ module_id_t module_id=0; // TODO switch (nsa_message_type) { case nr_SecondaryCellGroupConfig_r15: @@ -338,8 +340,7 @@ NR_UE_RRC_INST_t* openair_rrc_top_init_ue_nr(char* uecap_file, char* reconfig_fi fclose(fd); process_nsa_message(NR_UE_rrc_inst, nr_RadioBearerConfigX_r15, buffer,msg_len); } - else if (get_softmodem_params()->nsa) - { + else if (get_softmodem_params()->nsa) { LOG_D(NR_RRC, "In NSA mode \n"); } @@ -755,6 +756,7 @@ static int8_t nr_rrc_ue_decode_NR_BCCH_DL_SCH_Message(module_id_t module_id, void nr_rrc_manage_rlc_bearers(const NR_CellGroupConfig_t *cellGroupConfig, NR_UE_RRC_INST_t *rrc, int gNB_index, + module_id_t module_id, int rnti) { if(cellGroupConfig->rlc_BearerToReleaseList != NULL) { @@ -790,6 +792,9 @@ void nr_rrc_manage_rlc_bearers(const NR_CellGroupConfig_t *cellGroupConfig, } } } + nr_rrc_mac_config_req_ue_logicalChannelBearer(module_id, + cellGroupConfig->rlc_BearerToAddModList, + cellGroupConfig->rlc_BearerToReleaseList); } void nr_rrc_ue_process_masterCellGroup(const protocol_ctxt_t *const ctxt_pP, @@ -814,7 +819,7 @@ void nr_rrc_ue_process_masterCellGroup(const protocol_ctxt_t *const ctxt_pP, rrc->cell_group_config = calloc(1,sizeof(NR_CellGroupConfig_t)); } - nr_rrc_manage_rlc_bearers(cellGroupConfig, rrc, gNB_index, ctxt_pP->rntiMaybeUEid); + nr_rrc_manage_rlc_bearers(cellGroupConfig, rrc, gNB_index, ctxt_pP->module_id, ctxt_pP->rntiMaybeUEid); if(cellGroupConfig->mac_CellGroupConfig != NULL){ //TODO (configure the MAC entity of this cell group as specified in 5.3.5.5.5) diff --git a/openair2/RRC/NR_UE/rrc_proto.h b/openair2/RRC/NR_UE/rrc_proto.h index 248c3601fdcf142b784ac5533dc4f2626b622ee4..d04830192c362b6e00a5b488b1c1d6c987e1e68e 100644 --- a/openair2/RRC/NR_UE/rrc_proto.h +++ b/openair2/RRC/NR_UE/rrc_proto.h @@ -166,6 +166,7 @@ void nr_rrc_handle_SetupRelease_RLF_TimersAndConstants(NR_UE_RRC_INST_t *rrc, void nr_rrc_manage_rlc_bearers(const NR_CellGroupConfig_t *cellGroupConfig, NR_UE_RRC_INST_t *rrc, int gNB_index, + module_id_t module_id, int rnti); int configure_NR_SL_Preconfig(int sync_source);