diff --git a/README.txt b/README.txt index 33c0df9d8d..b0cad5f011 100644 --- a/README.txt +++ b/README.txt @@ -62,3 +62,4 @@ v1.0.0 -> January 2019. This version first implements the architectural split de New tools: config library, telnet server, ... A lot of bugfixes and a proper automated Continuous Integration process validates contributions. v1.0.1 -> February 2019: Bug fix for the UE L1 simulator. +v1.0.2 -> February 2019: Full OAI support for 3.13.1 UHD diff --git a/ci-scripts/buildOnVM.sh b/ci-scripts/buildOnVM.sh index f9fb3b776f..ad77d39eb7 100755 --- a/ci-scripts/buildOnVM.sh +++ b/ci-scripts/buildOnVM.sh @@ -94,15 +94,22 @@ function build_on_vm { echo "############################################################" echo "Creating VM ($VM_NAME) on Ubuntu Cloud Image base" echo "############################################################" + acquire_vm_create_lock uvt-kvm create $VM_NAME release=xenial --memory $VM_MEMORY --cpu $VM_CPU --unsafe-caching --template ci-scripts/template-host.xml + echo "Waiting for VM to be started" + uvt-kvm wait $VM_NAME --insecure + + VM_IP_ADDR=`uvt-kvm ip $VM_NAME` + echo "$VM_NAME has for IP addr = $VM_IP_ADDR" + release_vm_create_lock + else + echo "Waiting for VM to be started" + uvt-kvm wait $VM_NAME --insecure + + VM_IP_ADDR=`uvt-kvm ip $VM_NAME` + echo "$VM_NAME has for IP addr = $VM_IP_ADDR" fi - echo "Waiting for VM to be started" - uvt-kvm wait $VM_NAME --insecure - - VM_IP_ADDR=`uvt-kvm ip $VM_NAME` - echo "$VM_NAME has for IP addr = $VM_IP_ADDR" - echo "############################################################" echo "Copying GIT repo into VM ($VM_NAME)" echo "############################################################" diff --git a/ci-scripts/cppcheck_suppressions.list b/ci-scripts/cppcheck_suppressions.list index d5aea7ae9d..007d8555e2 100644 --- a/ci-scripts/cppcheck_suppressions.list +++ b/ci-scripts/cppcheck_suppressions.list @@ -67,6 +67,15 @@ syntaxError:openair1/SIMULATION/LTE_PHY/dlsim_tm4.c // omg, otg commented out in cmakelist to be cleaned up definitely? arrayIndexOutOfBounds:openair2/UTIL/OMG/omg.c uninitvar:openair2/UTIL/OTG/otg_rx_socket.c +//----------------------------------------------------------------------------- +// cppcheck is not able to understand that buf is initialized at the first +// iteration of the loop. +nullPointer:common/utils/T/local_tracer.c:243 +//----------------------------------------------------------------------------- +// once again cppcheck is not to understand that fds is initialized in the +// first iteration of the loop +nullPointer:common/utils/T/tracer/multi.c:264 +nullPointer:common/utils/T/tracer/multi.c:265 // //***************************************************************************** // diff --git a/ci-scripts/createVM.sh b/ci-scripts/createVM.sh index 192008d867..e693b07b91 100755 --- a/ci-scripts/createVM.sh +++ b/ci-scripts/createVM.sh @@ -49,6 +49,35 @@ function create_usage { echo "" } +function acquire_vm_create_lock { + local FlockFile="/tmp/vmclone.lck" + local unlocked="0" + touch ${FlockFile} 2>/dev/null + if [[ $? -ne 0 ]] + then + echo "Cannot access lock file ${FlockFile}" + exit 2 + fi + while [ $unlocked -eq 0 ] + do + exec 5>${FlockFile} + flock -nx 5 + if [[ $? -ne 0 ]] + then + echo "Another instance of VM creation is running" + sleep 10 + else + unlocked="1" + fi + done + chmod 666 ${FlockFile} 2>/dev/null +} + +function release_vm_create_lock { + local FlockFile="/tmp/vmclone.lck" + rm -Rf ${FlockFile} +} + function create_vm { echo "############################################################" echo "OAI CI VM script" @@ -60,10 +89,12 @@ function create_vm { echo "############################################################" echo "Creating VM ($VM_NAME) on Ubuntu Cloud Image base" echo "############################################################" + acquire_vm_create_lock uvt-kvm create $VM_NAME release=xenial --memory $VM_MEMORY --cpu $VM_CPU --unsafe-caching --template ci-scripts/template-host.xml echo "Waiting for VM to be started" uvt-kvm wait $VM_NAME --insecure VM_IP_ADDR=`uvt-kvm ip $VM_NAME` echo "$VM_NAME has for IP addr = $VM_IP_ADDR" + release_vm_create_lock } diff --git a/ci-scripts/runTestOnVM.sh b/ci-scripts/runTestOnVM.sh index 9aa6606eea..b3eac341a9 100755 --- a/ci-scripts/runTestOnVM.sh +++ b/ci-scripts/runTestOnVM.sh @@ -317,11 +317,18 @@ function install_epc_on_vm { echo "############################################################" echo "Creating test EPC VM ($LOC_EPC_VM_NAME) on Ubuntu Cloud Image base" echo "############################################################" + acquire_vm_create_lock uvt-kvm create $LOC_EPC_VM_NAME release=xenial --unsafe-caching + echo "Waiting for VM to be started" + uvt-kvm wait $LOC_EPC_VM_NAME --insecure + release_vm_create_lock + else + echo "Waiting for VM to be started" + uvt-kvm wait $LOC_EPC_VM_NAME --insecure fi - uvt-kvm wait $LOC_EPC_VM_NAME --insecure local LOC_EPC_VM_IP_ADDR=`uvt-kvm ip $LOC_EPC_VM_NAME` + echo "$LOC_EPC_VM_NAME has for IP addr = $LOC_EPC_VM_IP_ADDR" scp -o StrictHostKeyChecking=no /etc/apt/apt.conf.d/01proxy ubuntu@$LOC_EPC_VM_IP_ADDR:/home/ubuntu diff --git a/common/utils/T/tracer/gui/notify.c b/common/utils/T/tracer/gui/notify.c index 84fb161b6e..5798a01219 100644 --- a/common/utils/T/tracer/gui/notify.c +++ b/common/utils/T/tracer/gui/notify.c @@ -46,7 +46,7 @@ void unregister_notifier(gui *_g, unsigned long notifier_id) { if (g->notifiers[i].id == notifier_id) break; if (i == g->notifiers_count) - ERR("%s:%d: notifier_id %ld not found\n", __FILE__,__LINE__,notifier_id); + ERR("%s:%d: notifier_id %lu not found\n", __FILE__,__LINE__,notifier_id); free(g->notifiers[i].notification); memmove(g->notifiers + i, g->notifiers + i + 1, diff --git a/common/utils/T/tracer/textlog.c b/common/utils/T/tracer/textlog.c index a123bf9bf5..f83cc7efd3 100644 --- a/common/utils/T/tracer/textlog.c +++ b/common/utils/T/tracer/textlog.c @@ -195,5 +195,8 @@ int main(int n, char **v) handle_event(h, e); } + free(on_off_name); + free(on_off_action); + return 0; } diff --git a/common/utils/T/tracer/utils.c b/common/utils/T/tracer/utils.c index 2452254cf9..39e04fb973 100644 --- a/common/utils/T/tracer/utils.c +++ b/common/utils/T/tracer/utils.c @@ -273,6 +273,6 @@ void PUTX2(OBUF *o, int i) { void PUTUL(OBUF *o, unsigned long l) { char s[128]; - sprintf(s, "%ld", l); + sprintf(s, "%lu", l); PUTS(o, s); } diff --git a/openair1/PHY/TOOLS/lte_phy_scope_tm4.c b/openair1/PHY/TOOLS/lte_phy_scope_tm4.c index 8dd41548ab..5c7322e2e9 100644 --- a/openair1/PHY/TOOLS/lte_phy_scope_tm4.c +++ b/openair1/PHY/TOOLS/lte_phy_scope_tm4.c @@ -812,9 +812,6 @@ void phy_scope_UE(FD_lte_phy_scope_ue *form, free(bit1); free(bit_pdcch); free(llr_pdcch); - for (arx=0;arxtransmission_mode[eNB_id]==3 && phy_vars_ue->transmission_mode[eNB_id]==4){ diff --git a/openair2/LAYER2/MAC/eNB_scheduler_RA.c b/openair2/LAYER2/MAC/eNB_scheduler_RA.c index bd98edacf8..35fdca5877 100644 --- a/openair2/LAYER2/MAC/eNB_scheduler_RA.c +++ b/openair2/LAYER2/MAC/eNB_scheduler_RA.c @@ -239,21 +239,27 @@ add_msg3(module_id_t module_idP, int CC_id, RA_t * ra, frame_t frameP, } // non-BL/CE UE case } -void -generate_Msg2(module_id_t module_idP, int CC_idP, frame_t frameP, - sub_frame_t subframeP, RA_t * ra) +//------------------------------------------------------------------------------ +/* + * Generate the RAR (message2) + */ +void generate_Msg2(module_id_t module_idP, + int CC_idP, + frame_t frameP, + sub_frame_t subframeP, + RA_t *ra) +//------------------------------------------------------------------------------ { - - eNB_MAC_INST *mac = RC.mac[module_idP]; COMMON_channels_t *cc = mac->common_channels; - uint8_t *vrb_map; - int first_rb; - int N_RB_DL; - nfapi_dl_config_request_pdu_t *dl_config_pdu; - nfapi_tx_request_pdu_t *TX_req; - nfapi_dl_config_request_body_t *dl_req_body; + uint8_t *vrb_map = NULL; + int first_rb = 0; + int N_RB_DL = 0; + + nfapi_dl_config_request_pdu_t *dl_config_pdu = NULL; + nfapi_tx_request_pdu_t *TX_req = NULL; + nfapi_dl_config_request_body_t *dl_req_body = NULL; vrb_map = cc[CC_idP].vrb_map; dl_req_body = &mac->DL_req[CC_idP].dl_config_request_body; @@ -261,74 +267,81 @@ generate_Msg2(module_id_t module_idP, int CC_idP, frame_t frameP, N_RB_DL = to_prb(cc[CC_idP].mib->message.dl_Bandwidth); #if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0)) - int rmax = 0; - int rep = 0; - int reps = 0; - int num_nb = 0; + int rmax = 0; + int rep = 0; + int reps = 0; + int num_nb = 0; first_rb = 0; - struct LTE_PRACH_ConfigSIB_v1310 *ext4_prach; - LTE_PRACH_ParametersListCE_r13_t *prach_ParametersListCE_r13; + struct LTE_PRACH_ConfigSIB_v1310 *ext4_prach = NULL; + LTE_PRACH_ParametersListCE_r13_t *prach_ParametersListCE_r13 = NULL; LTE_PRACH_ParametersCE_r13_t *p[4] = { NULL, NULL, NULL, NULL }; - uint16_t absSF = (10 * frameP) + subframeP; - uint16_t absSF_Msg2 = (10 * ra->Msg2_frame) + ra->Msg2_subframe; + uint16_t absSF = (10 * frameP) + subframeP; + uint16_t absSF_Msg2 = (10 * ra->Msg2_frame) + ra->Msg2_subframe; - if (absSF > absSF_Msg2) - return; // we're not ready yet, need to be to start == - - if (cc[CC_idP].mib->message.schedulingInfoSIB1_BR_r13 > 0 && - cc[CC_idP].radioResourceConfigCommon_BR) { + if (absSF > absSF_Msg2) { + return; // we're not ready yet + } + if (cc[CC_idP].mib->message.schedulingInfoSIB1_BR_r13 > 0 && cc[CC_idP].radioResourceConfigCommon_BR) { ext4_prach = cc[CC_idP].radioResourceConfigCommon_BR->ext4->prach_ConfigCommon_v1310; prach_ParametersListCE_r13 = &ext4_prach->prach_ParametersListCE_r13; switch (prach_ParametersListCE_r13->list.count) { - case 4: - p[3] = prach_ParametersListCE_r13->list.array[3]; - case 3: - p[2] = prach_ParametersListCE_r13->list.array[2]; - case 2: - p[1] = prach_ParametersListCE_r13->list.array[1]; - case 1: - p[0] = prach_ParametersListCE_r13->list.array[0]; - break; - default: - AssertFatal (1 == 0, "Illegal count for prach_ParametersListCE_r13 %d\n", (int) prach_ParametersListCE_r13->list.count); - break; - + case 4: + p[3] = prach_ParametersListCE_r13->list.array[3]; + case 3: + p[2] = prach_ParametersListCE_r13->list.array[2]; + case 2: + p[1] = prach_ParametersListCE_r13->list.array[1]; + case 1: + p[0] = prach_ParametersListCE_r13->list.array[0]; + break; + default: + AssertFatal (1 == 0, "Illegal count for prach_ParametersListCE_r13 %d\n", (int) prach_ParametersListCE_r13->list.count); + break; } } if (ra->rach_resource_type > 0) { + /* This uses an MPDCCH Type 2 common allocation according to Section 9.1.5 36-213 + * Parameters: + * p = 2 + 4 PRB set (number of PRB pairs 3) + * rmax = mpdcch-NumRepetition-RA-r13 => Table 9.1.5-3 + * if CELevel = 0,1 => Table 9.1.5-1b for MPDCCH candidates + * if CELevel = 2,3 => Table 9.1.5-2b for MPDCCH candidates + * distributed transmission + */ - // This uses an MPDCCH Type 2 common allocation according to Section 9.1.5 36-213 - // Parameters: - // p=2+4 PRB set (number of PRB pairs 3) - // rmax = mpdcch-NumRepetition-RA-r13 => Table 9.1.5-3 - // if CELevel = 0,1 => Table 9.1.5-1b for MPDCCH candidates - // if CELevel = 2,3 => Table 9.1.5-2b for MPDCCH candidates - // distributed transmission - - // rmax from SIB2 information - AssertFatal (rmax < 9, "rmax>8!\n"); + /* rmax from SIB2 information */ + AssertFatal (rmax < 9, "rmax > 8!\n"); // not sure of this assertion rmax = 1 << p[ra->rach_resource_type - 1]->mpdcch_NumRepetition_RA_r13; - // choose r1 by default for RAR (Table 9.1.5-5) + + /* Choose r1 by default for RAR (Table 9.1.5-5) */ rep = 0; - // get actual repetition count from Table 9.1.5-3 + + /* Get actual repetition count from Table 9.1.5-3 */ reps = (rmax <= 8) ? (1 << rep) : (rmax >> (3 - rep)); - // get narrowband according to higher-layer config + + /* Get narrowband according to higher-layer config */ num_nb = p[ra->rach_resource_type - 1]->mpdcch_NarrowbandsToMonitor_r13.list.count; - ra->msg2_narrowband = *p[ra->rach_resource_type - 1]->mpdcch_NarrowbandsToMonitor_r13.list.array[ra->preamble_index % num_nb]-1; - first_rb = narrowband_to_first_rb (&cc[CC_idP], ra->msg2_narrowband); + ra->msg2_narrowband = *p[ra->rach_resource_type - 1]->mpdcch_NarrowbandsToMonitor_r13.list.array[ra->preamble_index % num_nb] - 1; + first_rb = narrowband_to_first_rb(&cc[CC_idP], ra->msg2_narrowband); - if ((ra->msg2_mpdcch_repetition_cnt == 0) && (mpdcch_sf_condition (mac, CC_idP, frameP, subframeP, rmax, TYPE2, -1) > 0)) { + if ((ra->msg2_mpdcch_repetition_cnt == 0) && (mpdcch_sf_condition(mac, CC_idP, frameP, subframeP, rmax, TYPE2, -1) > 0)) { ra->msg2_mpdcch_done = 0; - // MPDCCH configuration for RAR - LOG_I (MAC, "[eNB %d][RAPROC] Frame %d, Subframe %d : In generate_Msg2 for CE Level %d, Programming MPDCCH %d repetitions\n", module_idP, frameP, subframeP, ra->rach_resource_type-1,reps); + /* MPDCCH configuration for RAR */ + LOG_I(MAC, "[eNB %d][RAPROC] Frame %d, Subframe %d : In generate_Msg2 for CE Level %d, Programming MPDCCH %d repetitions\n", + module_idP, + frameP, + subframeP, + ra->rach_resource_type - 1, + reps); memset ((void *) dl_config_pdu, 0, sizeof (nfapi_dl_config_request_pdu_t)); + dl_config_pdu->pdu_type = NFAPI_DL_CONFIG_MPDCCH_PDU_TYPE; dl_config_pdu->pdu_size = (uint8_t) (2 + sizeof (nfapi_dl_config_mpdcch_pdu)); dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.dci_format = (ra->rach_resource_type > 1) ? 11 : 10; @@ -336,7 +349,9 @@ generate_Msg2(module_id_t module_idP, int CC_idP, frame_t frameP, dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.number_of_prb_pairs = 6; dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.resource_block_assignment = 0; // Note: this can be dynamic dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.mpdcch_tansmission_type = 1; // imposed (9.1.5 in 213) for Type 2 Common search space + AssertFatal (cc[CC_idP].sib1_v13ext->bandwidthReducedAccessRelatedInfo_r13 != NULL, "cc[CC_idP].sib1_v13ext->bandwidthReducedAccessRelatedInfo_r13 is null\n"); + dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.start_symbol = cc[CC_idP].sib1_v13ext->bandwidthReducedAccessRelatedInfo_r13->startSymbolBR_r13; dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.ecce_index = 0; // Note: this should be dynamic dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.aggregation_level = 24; // OK for CEModeA r1-3 (9.1.5-1b) or CEModeB r1-4 @@ -346,7 +361,7 @@ generate_Msg2(module_id_t module_idP, int CC_idP, frame_t frameP, dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.drms_scrambling_init = cc[CC_idP].physCellId; dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.initial_transmission_sf_io = (frameP * 10) + subframeP; dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.transmission_power = 6000; // 0dB - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.resource_block_coding = getRIV (6, 0, 6) | (ra->msg2_narrowband<<5); + dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.resource_block_coding = getRIV(6, 0, 6) | (ra->msg2_narrowband<<5); dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.mcs = 0; // adjust according to size of RAR, 208 bits with N1A_PRB=3 dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.pdsch_reptition_levels = 0; // fix to 4 for now dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.redundancy_version = 0; @@ -373,51 +388,64 @@ generate_Msg2(module_id_t module_idP, int CC_idP, frame_t frameP, dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.direct_indication = 0; dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.total_dci_length_including_padding = 0; // this is not needed by OAI L1, but should be filled in dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.number_of_tx_antenna_ports = 1; + ra->msg2_mpdcch_repetition_cnt++; dl_req_body->number_pdu++; ra->Msg2_subframe = (ra->Msg2_subframe + 9) % 10; + } // repetition_count == 0 && SF condition met - } //repetition_count==0 && SF condition met if (ra->msg2_mpdcch_repetition_cnt > 0) { // we're in a stream of repetitions + if ((ra->msg2_mpdcch_repetition_cnt == reps) && (ra->msg2_mpdcch_done == 0)) { // this is the last mpdcch repetition + ra->msg2_mpdcch_done = 1; - - if ((ra->msg2_mpdcch_repetition_cnt == reps)&& - (ra->msg2_mpdcch_done == 0)){ // this is the last mpdcch repetition - ra->msg2_mpdcch_done = 1; - if (cc[CC_idP].tdd_Config == NULL) { // FDD case + if (cc[CC_idP].tdd_Config == NULL) { // FDD case // wait 2 subframes for PDSCH transmission if (subframeP > 7) ra->Msg2_frame = (frameP + 1) & 1023; else ra->Msg2_frame = frameP; - ra->Msg2_subframe = (subframeP + 2) % 10; // +2 is the "n+x" from Section 7.1.11 in 36.213 - LOG_I(MAC,"[eNB %d][RAPROC] Frame %d, Subframe %d : In generate_Msg2, programmed Msg2 for %d.%d\n", module_idP, frameP, subframeP, ra->Msg2_frame,ra->Msg2_subframe); + ra->Msg2_subframe = (subframeP + 2) % 10; // +2 is the "n+x" from Section 7.1.11 in 36.213 + + LOG_I(MAC, "[eNB %d][RAPROC] Frame %d, Subframe %d : In generate_Msg2, programmed Msg2 for %d.%d\n", + module_idP, + frameP, + subframeP, + ra->Msg2_frame, + ra->Msg2_subframe); } else { - AssertFatal (1 == 0, "TDD case not done yet\n"); + AssertFatal(1 == 0, "TDD case not done yet\n"); } - } // mpdcch_repetition_count == reps - else if (ra->msg2_mpdcch_done == 0) { - LOG_I (MAC, "[eNB %d][RAPROC] Frame %d, Subframe %d : In generate_Msg2, MPDCCH repetition %d\n", module_idP, frameP, subframeP, ra->msg2_mpdcch_repetition_cnt); + } else if (ra->msg2_mpdcch_done == 0) { // mpdcch_repetition_count != reps + LOG_I(MAC,"[eNB %d][RAPROC] Frame %d, Subframe %d : In generate_Msg2, MPDCCH repetition %d\n", + module_idP, + frameP, + subframeP, + ra->msg2_mpdcch_repetition_cnt); + ra->msg2_mpdcch_repetition_cnt++; } - - if ((ra->Msg2_frame == frameP) && (ra->Msg2_subframe == subframeP)) { - // Program PDSCH - LOG_I (MAC, "[eNB %d][RAPROC] Frame %d, Subframe %d : In generate_Msg2, Programming PDSCH\n", module_idP, frameP, subframeP); + if((ra->Msg2_frame == frameP) && (ra->Msg2_subframe == subframeP)) { + /* Program PDSCH */ + LOG_I(MAC, "[eNB %d][RAPROC] Frame %d, Subframe %d : In generate_Msg2, Programming PDSCH\n", + module_idP, + frameP, + subframeP); dl_config_pdu = &dl_req_body->dl_config_pdu_list[dl_req_body->number_pdu]; + memset ((void *) dl_config_pdu, 0, sizeof (nfapi_dl_config_request_pdu_t)); + dl_config_pdu->pdu_type = NFAPI_DL_CONFIG_DLSCH_PDU_TYPE; dl_config_pdu->pdu_size = (uint8_t) (2 + sizeof (nfapi_dl_config_dlsch_pdu)); dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.pdu_index = mac->pdu_index[CC_idP]; dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.rnti = ra->RA_rnti; dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.resource_allocation_type = 2; - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.virtual_resource_block_assignment_flag = 0; // localized - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.resource_block_coding = getRIV (N_RB_DL, first_rb, 6); - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.modulation = 2; //QPSK + dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.virtual_resource_block_assignment_flag = 0; // localized + dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.resource_block_coding = getRIV(N_RB_DL, first_rb, 6); + dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.modulation = 2; // QPSK dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.redundancy_version = 0; - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.transport_blocks = 1; // first block + dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.transport_blocks = 1; // first block dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.transport_block_to_codeword_swap_flag = 0; dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.transmission_scheme = (cc[CC_idP].p_eNB == 1) ? 0 : 1; dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.number_of_layers = 1; @@ -427,28 +455,36 @@ generate_Msg2(module_id_t module_idP, int CC_idP, frame_t frameP, dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.pa = 4; // 0 dB dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.delta_power_offset_index = 0; dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.ngap = 0; - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.nprb = get_subbandsize (cc[CC_idP].mib->message.dl_Bandwidth); // ignored + dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.nprb = get_subbandsize(cc[CC_idP].mib->message.dl_Bandwidth); // ignored dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.transmission_mode = (cc[CC_idP].p_eNB == 1) ? 1 : 2; dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.num_bf_prb_per_subband = 1; dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.num_bf_vector = 1; // dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.bf_vector = ; - // Rel10 fields + /* Rel10 fields */ dl_config_pdu->dlsch_pdu.dlsch_pdu_rel10.pdsch_start = cc[CC_idP].sib1_v13ext->bandwidthReducedAccessRelatedInfo_r13->startSymbolBR_r13; - // Rel13 fields + + /* Rel13 fields */ dl_config_pdu->dlsch_pdu.dlsch_pdu_rel13.ue_type = (ra->rach_resource_type < 3) ? 1 : 2;; - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel13.pdsch_payload_type = 2; // not SI message + dl_config_pdu->dlsch_pdu.dlsch_pdu_rel13.pdsch_payload_type = 2; // not SI message dl_config_pdu->dlsch_pdu.dlsch_pdu_rel13.initial_transmission_sf_io = (10 * frameP) + subframeP; dl_config_pdu->dlsch_pdu.dlsch_pdu_rel13.drms_table_flag = 0; dl_req_body->number_pdu++; - fill_rar_br (mac, CC_idP, ra, frameP, subframeP, cc[CC_idP].RAR_pdu.payload, ra->rach_resource_type - 1) ; -// Program UL processing for Msg3, same as regular LTE + fill_rar_br(mac, CC_idP, ra, frameP, subframeP, cc[CC_idP].RAR_pdu.payload, ra->rach_resource_type - 1); + + /* Program UL processing for Msg3, same as regular LTE */ get_Msg3alloc (&cc[CC_idP], subframeP, frameP, &ra->Msg3_frame, &ra->Msg3_subframe); add_msg3 (module_idP, CC_idP, ra, frameP, subframeP); - ra->state = WAITMSG3; - // DL request - LOG_I (MAC, "[eNB %d][RAPROC] Frame %d, Subframe %d : In generate_Msg2, Programming TX Req\n", module_idP, frameP, subframeP); + + ra->state = WAITMSG3; + + /* DL request */ + LOG_I(MAC, "[eNB %d][RAPROC] Frame %d, Subframe %d : In generate_Msg2, Programming TX Req\n", + module_idP, + frameP, + subframeP); + mac->TX_req[CC_idP].sfn_sf = (frameP << 4) + subframeP; TX_req = &mac->TX_req[CC_idP].tx_request_body.tx_pdu_list[mac->TX_req[CC_idP].tx_request_body.number_of_pdus]; TX_req->pdu_length = 7; // This should be changed if we have more than 1 preamble @@ -459,7 +495,6 @@ generate_Msg2(module_id_t module_idP, int CC_idP, frame_t frameP, mac->TX_req[CC_idP].tx_request_body.number_of_pdus++; } } - } else #endif @@ -571,104 +606,115 @@ generate_Msg2(module_id_t module_idP, int CC_idP, frame_t frameP, } // Msg2 frame/subframe condition } // else BL/CE } -void -generate_Msg4(module_id_t module_idP, int CC_idP, frame_t frameP, - sub_frame_t subframeP, RA_t * ra) -{ - +//------------------------------------------------------------------------------ +/* + * Generate message 4 of RA procedure (RRC connection setup) + */ +void +generate_Msg4(module_id_t module_idP, + int CC_idP, + frame_t frameP, + sub_frame_t subframeP, + RA_t * ra) +//------------------------------------------------------------------------------ +{ eNB_MAC_INST *mac = RC.mac[module_idP]; COMMON_channels_t *cc = mac->common_channels; - int16_t rrc_sdu_length; + UE_list_t *UE_list = &(mac->UE_list); + + int16_t rrc_sdu_length = 0; + uint16_t msg4_padding = 0; + uint16_t msg4_post_padding = 0; + uint16_t msg4_header = 0; int UE_id = -1; - uint16_t msg4_padding; - uint16_t msg4_post_padding; - uint16_t msg4_header; + int first_rb = 0; + int N_RB_DL = 0; + uint8_t lcid = 0; + uint8_t offset = 0; + uint8_t *vrb_map = NULL; - uint8_t *vrb_map; - int first_rb; - int N_RB_DL; - nfapi_dl_config_request_pdu_t *dl_config_pdu; - nfapi_ul_config_request_pdu_t *ul_config_pdu; - nfapi_tx_request_pdu_t *TX_req; - UE_list_t *UE_list=&mac->UE_list; - nfapi_dl_config_request_t *dl_req; - nfapi_dl_config_request_body_t *dl_req_body; - nfapi_ul_config_request_body_t *ul_req_body; - uint8_t lcid; - uint8_t offset; - + nfapi_dl_config_request_pdu_t *dl_config_pdu = NULL; + nfapi_ul_config_request_pdu_t *ul_config_pdu = NULL; + nfapi_tx_request_pdu_t *TX_req = NULL; + nfapi_dl_config_request_t *dl_req = NULL; + nfapi_dl_config_request_body_t *dl_req_body = NULL; + nfapi_ul_config_request_body_t *ul_req_body = NULL; #if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0)) - int rmax = 0; - int rep = 0; - int reps = 0; - + int rmax = 0; + int rep = 0; + int reps = 0; first_rb = 0; - struct LTE_PRACH_ConfigSIB_v1310 *ext4_prach; - struct LTE_PUCCH_ConfigCommon_v1310 *ext4_pucch; - LTE_PRACH_ParametersListCE_r13_t *prach_ParametersListCE_r13; - struct LTE_N1PUCCH_AN_InfoList_r13 *pucch_N1PUCCH_AN_InfoList_r13; + + struct LTE_PRACH_ConfigSIB_v1310 *ext4_prach = NULL; + struct LTE_PUCCH_ConfigCommon_v1310 *ext4_pucch = NULL; + LTE_PRACH_ParametersListCE_r13_t *prach_ParametersListCE_r13 = NULL; + struct LTE_N1PUCCH_AN_InfoList_r13 *pucch_N1PUCCH_AN_InfoList_r13 = NULL; LTE_PRACH_ParametersCE_r13_t *p[4] = { NULL, NULL, NULL, NULL }; int pucchreps[4] = { 1, 1, 1, 1 }; int n1pucchan[4] = { 0, 0, 0, 0 }; - if (cc[CC_idP].mib->message.schedulingInfoSIB1_BR_r13 > 0 && - cc[CC_idP].radioResourceConfigCommon_BR) { + if (cc[CC_idP].mib->message.schedulingInfoSIB1_BR_r13 > 0 && cc[CC_idP].radioResourceConfigCommon_BR) { ext4_prach = cc[CC_idP].radioResourceConfigCommon_BR->ext4->prach_ConfigCommon_v1310; - ext4_pucch = cc[CC_idP].radioResourceConfigCommon_BR->ext4->pucch_ConfigCommon_v1310; prach_ParametersListCE_r13 = &ext4_prach->prach_ParametersListCE_r13; + + ext4_pucch = cc[CC_idP].radioResourceConfigCommon_BR->ext4->pucch_ConfigCommon_v1310; pucch_N1PUCCH_AN_InfoList_r13 = ext4_pucch->n1PUCCH_AN_InfoList_r13; + AssertFatal (prach_ParametersListCE_r13 != NULL, "prach_ParametersListCE_r13 is null\n"); AssertFatal (pucch_N1PUCCH_AN_InfoList_r13 != NULL, "pucch_N1PUCCH_AN_InfoList_r13 is null\n"); - // check to verify CE-Level compatibility in SIB2_BR + + /* Check to verify CE-Level compatibility in SIB2_BR */ AssertFatal (prach_ParametersListCE_r13->list.count == pucch_N1PUCCH_AN_InfoList_r13->list.count, "prach_ParametersListCE_r13->list.count!= pucch_N1PUCCH_AN_InfoList_r13->list.count\n"); switch (prach_ParametersListCE_r13->list.count) { - case 4: - p[3] = prach_ParametersListCE_r13->list.array[3]; - n1pucchan[3] = *pucch_N1PUCCH_AN_InfoList_r13->list.array[3]; - AssertFatal (ext4_pucch->pucch_NumRepetitionCE_Msg4_Level3_r13 != NULL, "pucch_NumRepetitionCE_Msg4_Level3 shouldn't be NULL\n"); - pucchreps[3] = (int) (4 << *ext4_pucch->pucch_NumRepetitionCE_Msg4_Level3_r13); - - case 3: - p[2] = prach_ParametersListCE_r13->list.array[2]; - n1pucchan[2] = *pucch_N1PUCCH_AN_InfoList_r13->list.array[2]; - AssertFatal (ext4_pucch->pucch_NumRepetitionCE_Msg4_Level2_r13 != NULL, "pucch_NumRepetitionCE_Msg4_Level2 shouldn't be NULL\n"); - pucchreps[2] = (int) (4 << *ext4_pucch->pucch_NumRepetitionCE_Msg4_Level2_r13); - case 2: - p[1] = prach_ParametersListCE_r13->list.array[1]; - n1pucchan[1] = *pucch_N1PUCCH_AN_InfoList_r13->list.array[1]; - AssertFatal (ext4_pucch->pucch_NumRepetitionCE_Msg4_Level1_r13 != NULL, "pucch_NumRepetitionCE_Msg4_Level1 shouldn't be NULL\n"); - pucchreps[1] = (int) (1 << *ext4_pucch->pucch_NumRepetitionCE_Msg4_Level1_r13); - case 1: - p[0] = prach_ParametersListCE_r13->list.array[0]; - n1pucchan[0] = *pucch_N1PUCCH_AN_InfoList_r13->list.array[0]; - AssertFatal (ext4_pucch->pucch_NumRepetitionCE_Msg4_Level0_r13 != NULL, "pucch_NumRepetitionCE_Msg4_Level0 shouldn't be NULL\n"); - pucchreps[0] = (int) (1 << *ext4_pucch->pucch_NumRepetitionCE_Msg4_Level0_r13); - break; - default: - AssertFatal (1 == 0, "Illegal count for prach_ParametersListCE_r13 %d\n", prach_ParametersListCE_r13->list.count); + case 4: + p[3] = prach_ParametersListCE_r13->list.array[3]; + n1pucchan[3] = *pucch_N1PUCCH_AN_InfoList_r13->list.array[3]; + AssertFatal(ext4_pucch->pucch_NumRepetitionCE_Msg4_Level3_r13 != NULL, "pucch_NumRepetitionCE_Msg4_Level3 shouldn't be NULL\n"); + pucchreps[3] = (int) (4 << *ext4_pucch->pucch_NumRepetitionCE_Msg4_Level3_r13); + case 3: + p[2] = prach_ParametersListCE_r13->list.array[2]; + n1pucchan[2] = *pucch_N1PUCCH_AN_InfoList_r13->list.array[2]; + AssertFatal(ext4_pucch->pucch_NumRepetitionCE_Msg4_Level2_r13 != NULL, "pucch_NumRepetitionCE_Msg4_Level2 shouldn't be NULL\n"); + pucchreps[2] = (int) (4 << *ext4_pucch->pucch_NumRepetitionCE_Msg4_Level2_r13); + case 2: + p[1] = prach_ParametersListCE_r13->list.array[1]; + n1pucchan[1] = *pucch_N1PUCCH_AN_InfoList_r13->list.array[1]; + AssertFatal(ext4_pucch->pucch_NumRepetitionCE_Msg4_Level1_r13 != NULL, "pucch_NumRepetitionCE_Msg4_Level1 shouldn't be NULL\n"); + pucchreps[1] = (int) (1 << *ext4_pucch->pucch_NumRepetitionCE_Msg4_Level1_r13); + case 1: + p[0] = prach_ParametersListCE_r13->list.array[0]; + n1pucchan[0] = *pucch_N1PUCCH_AN_InfoList_r13->list.array[0]; + AssertFatal(ext4_pucch->pucch_NumRepetitionCE_Msg4_Level0_r13 != NULL, "pucch_NumRepetitionCE_Msg4_Level0 shouldn't be NULL\n"); + pucchreps[0] = (int) (1 << *ext4_pucch->pucch_NumRepetitionCE_Msg4_Level0_r13); + break; + default: + AssertFatal(1 == 0, "Illegal count for prach_ParametersListCE_r13 %d\n", prach_ParametersListCE_r13->list.count); } } #endif - vrb_map = cc[CC_idP].vrb_map; dl_req = &mac->DL_req[CC_idP]; dl_req_body = &dl_req->dl_config_request_body; dl_config_pdu = &dl_req_body->dl_config_pdu_list[dl_req_body->number_pdu]; + N_RB_DL = to_prb(cc[CC_idP].mib->message.dl_Bandwidth); UE_id = find_UE_id(module_idP, ra->rnti); + if (UE_id < 0) { - LOG_E(MAC,"Can't find UE for t-crnti %x, kill RA procedure for this UE\n",ra->rnti); + LOG_E(MAC, "Can't find UE for t-crnti %x, kill RA procedure for this UE\n", + ra->rnti); + cancel_ra_proc(module_idP, CC_idP, frameP, ra->rnti); return; } diff --git a/openair2/LAYER2/MAC/eNB_scheduler_dlsch.c b/openair2/LAYER2/MAC/eNB_scheduler_dlsch.c index 737f4dfe74..2e45495e88 100644 --- a/openair2/LAYER2/MAC/eNB_scheduler_dlsch.c +++ b/openair2/LAYER2/MAC/eNB_scheduler_dlsch.c @@ -70,37 +70,39 @@ extern uint8_t nfapi_mode; void add_ue_dlsch_info(module_id_t module_idP, int CC_id, - int UE_id, sub_frame_t subframeP, UE_DLSCH_STATUS status) + int UE_id, + sub_frame_t subframeP, + UE_DLSCH_STATUS status, + rnti_t rnti) //------------------------------------------------------------------------------ { - //LOG_D(MAC, "%s(module_idP:%d, CC_id:%d, UE_id:%d, subframeP:%d, status:%d) serving_num:%d rnti:%x\n", __FUNCTION__, module_idP, CC_id, UE_id, subframeP, status, eNB_dlsch_info[module_idP][CC_id][UE_id].serving_num, UE_RNTI(module_idP,UE_id)); - eNB_dlsch_info[module_idP][CC_id][UE_id].rnti = - UE_RNTI(module_idP, UE_id); - // eNB_dlsch_info[module_idP][CC_id][ue_mod_idP].weight = weight; - eNB_dlsch_info[module_idP][CC_id][UE_id].subframe = subframeP; - eNB_dlsch_info[module_idP][CC_id][UE_id].status = status; - eNB_dlsch_info[module_idP][CC_id][UE_id].serving_num++; + eNB_DLSCH_INFO *info = &eNB_dlsch_info[module_idP][CC_id][UE_id]; + // LOG_D(MAC, "%s(module_idP:%d, CC_id:%d, UE_id:%d, subframeP:%d, status:%d) serving_num:%d rnti:%x\n", __FUNCTION__, module_idP, CC_id, UE_id, subframeP, status, eNB_dlsch_info[module_idP][CC_id][UE_id].serving_num, UE_RNTI(module_idP,UE_id)); + info->rnti = rnti; + // info->weight = weight; + info->subframe = subframeP; + info->status = status; + info->serving_num++; + return; } //------------------------------------------------------------------------------ int -schedule_next_dlue(module_id_t module_idP, int CC_id, +schedule_next_dlue(module_id_t module_idP, + int CC_id, sub_frame_t subframeP) //------------------------------------------------------------------------------ { int next_ue; UE_list_t *UE_list = &RC.mac[module_idP]->UE_list; - for (next_ue = UE_list->head; next_ue >= 0; - next_ue = UE_list->next[next_ue]) { - if (eNB_dlsch_info[module_idP][CC_id][next_ue].status == - S_DL_WAITING) { + for (next_ue = UE_list->head; next_ue >= 0; next_ue = UE_list->next[next_ue]) { + if (eNB_dlsch_info[module_idP][CC_id][next_ue].status == S_DL_WAITING) { return next_ue; } } - for (next_ue = UE_list->head; next_ue >= 0; - next_ue = UE_list->next[next_ue]) { + for (next_ue = UE_list->head; next_ue >= 0; next_ue = UE_list->next[next_ue]) { if (eNB_dlsch_info[module_idP][CC_id][next_ue].status == S_DL_BUFFERED) { eNB_dlsch_info[module_idP][CC_id][next_ue].status = S_DL_WAITING; } @@ -129,7 +131,7 @@ generate_dlsch_header(unsigned char *mac_header, // compute header components - if ((short_padding == 1) || (short_padding == 2)) { + if (short_padding == 1 || short_padding == 2) { mac_header_ptr->R = 0; mac_header_ptr->E = 0; mac_header_ptr->LCID = SHORT_PADDING; @@ -153,7 +155,6 @@ generate_dlsch_header(unsigned char *mac_header, } else { first_element = 1; } - mac_header_ptr->R = 0; mac_header_ptr->E = 0; mac_header_ptr->LCID = DRX_CMD; @@ -167,17 +168,17 @@ generate_dlsch_header(unsigned char *mac_header, } else { first_element = 1; } - mac_header_ptr->R = 0; mac_header_ptr->E = 0; mac_header_ptr->LCID = TIMING_ADV_CMD; last_size = 1; // msg("last_size %d,mac_header_ptr %p\n",last_size,mac_header_ptr); ((TIMING_ADVANCE_CMD *) ce_ptr)->R = 0; - AssertFatal(timing_advance_cmd < 64, - "timing_advance_cmd %d > 63\n", timing_advance_cmd); + AssertFatal(timing_advance_cmd < 64, "timing_advance_cmd %d > 63\n", + timing_advance_cmd); ((TIMING_ADVANCE_CMD *) ce_ptr)->TA = timing_advance_cmd; //(timing_advance_cmd+31)&0x3f; - LOG_D(MAC, "timing advance =%d (%d)\n", timing_advance_cmd, + LOG_D(MAC, "timing advance =%d (%d)\n", + timing_advance_cmd, ((TIMING_ADVANCE_CMD *) ce_ptr)->TA); ce_ptr += sizeof(TIMING_ADVANCE_CMD); //msg("offset %d\n",ce_ptr-mac_header_control_elements); @@ -201,11 +202,16 @@ generate_dlsch_header(unsigned char *mac_header, mac_header_ptr->E = 0; mac_header_ptr->LCID = UE_CONT_RES; last_size = 1; - LOG_T(MAC, - "[eNB ][RAPROC] Generate contention resolution msg: %x.%x.%x.%x.%x.%x\n", - ue_cont_res_id[0], ue_cont_res_id[1], ue_cont_res_id[2], - ue_cont_res_id[3], ue_cont_res_id[4], ue_cont_res_id[5]); - memcpy(ce_ptr, ue_cont_res_id, 6); + LOG_T(MAC, "[eNB ][RAPROC] Generate contention resolution msg: %x.%x.%x.%x.%x.%x\n", + ue_cont_res_id[0], + ue_cont_res_id[1], + ue_cont_res_id[2], + ue_cont_res_id[3], + ue_cont_res_id[4], + ue_cont_res_id[5]); + memcpy(ce_ptr, + ue_cont_res_id, + 6); ce_ptr += 6; // msg("(cont_res) : offset %d\n",ce_ptr-mac_header_control_elements); } @@ -214,7 +220,8 @@ generate_dlsch_header(unsigned char *mac_header, for (i = 0; i < num_sdus; i++) { LOG_T(MAC, "[eNB] Generate DLSCH header num sdu %d len sdu %d\n", - num_sdus, sdu_lengths[i]); + num_sdus, + sdu_lengths[i]); if (first_element > 0) { mac_header_ptr->E = 1; @@ -246,8 +253,7 @@ generate_dlsch_header(unsigned char *mac_header, ((SCH_SUBHEADER_LONG *) mac_header_ptr)->padding = 0x00; last_size = 3; #ifdef DEBUG_HEADER_PARSING - LOG_D(MAC, - "[eNB] generate long sdu, size %x (MSB %x, LSB %x)\n", + LOG_D(MAC, "[eNB] generate long sdu, size %x (MSB %x, LSB %x)\n", sdu_lengths[i], ((SCH_SUBHEADER_LONG *) mac_header_ptr)->L_MSB, ((SCH_SUBHEADER_LONG *) mac_header_ptr)->L_LSB); @@ -289,10 +295,10 @@ generate_dlsch_header(unsigned char *mac_header, if ((ce_ptr - mac_header_control_elements) > 0) { // printf("Copying %d bytes for control elements\n",ce_ptr-mac_header_control_elements); - memcpy((void *) mac_header_ptr, mac_header_control_elements, + memcpy((void *) mac_header_ptr, + mac_header_control_elements, ce_ptr - mac_header_control_elements); - mac_header_ptr += - (unsigned char) (ce_ptr - mac_header_control_elements); + mac_header_ptr += (unsigned char) (ce_ptr - mac_header_control_elements); } //msg("After CEs %d\n",(uint8_t*)mac_header_ptr - mac_header); @@ -301,7 +307,10 @@ generate_dlsch_header(unsigned char *mac_header, //------------------------------------------------------------------------------ void -set_ul_DAI(int module_idP, int UE_idP, int CC_idP, int frameP, +set_ul_DAI(int module_idP, + int UE_idP, + int CC_idP, + int frameP, int subframeP) //------------------------------------------------------------------------------ { @@ -312,9 +321,13 @@ set_ul_DAI(int module_idP, int UE_idP, int CC_idP, int frameP, if (cc->tdd_Config != NULL) { //TDD DAI = (UE_list->UE_template[CC_idP][UE_idP].DAI - 1) & 3; - LOG_D(MAC, - "[eNB %d] CC_id %d Frame %d, subframe %d: DAI %d for UE %d\n", - module_idP, CC_idP, frameP, subframeP, DAI, UE_idP); + LOG_D(MAC, "[eNB %d] CC_id %d Frame %d, subframe %d: DAI %d for UE %d\n", + module_idP, + CC_idP, + frameP, + subframeP, + DAI, + UE_idP); // Save DAI for Format 0 DCI switch (cc->tdd_Config->subframeAssignment) { @@ -398,6 +411,8 @@ set_ul_DAI(int module_idP, int UE_idP, int CC_idP, int frameP, break; } } + + return; } //------------------------------------------------------------------------------ @@ -409,7 +424,11 @@ schedule_dlsch(module_id_t module_idP, frame_t frameP, sub_frame_t subframeP, in for (i = 0; i < sli->n_dl; i++) { // Run each enabled slice-specific schedulers one by one - sli->dl[i].sched_cb(module_idP, i, frameP, subframeP, mbsfn_flag/*, dl_info*/); + sli->dl[i].sched_cb(module_idP, + i, + frameP, + subframeP, + mbsfn_flag/*, dl_info*/); } } @@ -437,1082 +456,13 @@ void getRepetition(UE_TEMPLATE * pue_template,unsigned int *maxRep , unsigned i } - - -/*void -schedule_ue_spec_br( - module_id_t module_idP, - frame_t frameP, - sub_frame_t subframeP, - int* mbsfn_flag -) -//------------------------------------------------------------------------------ -{ - uint8_t CC_id; - int UE_id; - unsigned char aggregation; - mac_rlc_status_resp_t rlc_status; - unsigned char header_len_dcch = 0, header_len_dcch_tmp = 0; - unsigned char header_len_dtch = 0, header_len_dtch_tmp = 0, header_len_dtch_last = 0; - unsigned char ta_len = 0; - unsigned char sdu_lcids[NB_RB_MAX], lcid, offset, num_sdus = 0; - uint16_t nb_rb, nb_rb_temp, nb_available_rb; - uint16_t TBS, j, sdu_lengths[NB_RB_MAX], rnti, padding = 0, post_padding = 0; - unsigned char dlsch_buffer[MAX_DLSCH_PAYLOAD_BYTES]; - unsigned char round = 0; - unsigned char harq_pid = 0; - eNB_UE_STATS *eNB_UE_stats = NULL; - uint16_t sdu_length_total = 0; - - eNB_MAC_INST *eNB = RC.mac[module_idP]; - COMMON_channels_t *cc = eNB->common_channels; - UE_list_t *UE_list = &eNB->UE_list; - int continue_flag = 0; - int32_t normalized_rx_power, target_rx_power; - int32_t tpc = 1; - static int32_t tpc_accumulated = 0; - UE_sched_ctrl *ue_sched_ctl; - int mcs; - int i; - int min_rb_unit[MAX_NUM_CCs]; - int N_RB_DL[MAX_NUM_CCs]; - int total_nb_available_rb[MAX_NUM_CCs]; - int N_RBG[MAX_NUM_CCs]; - nfapi_dl_config_request_body_t *dl_req; - nfapi_dl_config_request_pdu_t *dl_config_pdu; - nfapi_tx_request_pdu_t *TX_req; - int tdd_sfa; - -#if 0 - if (UE_list->head == -1) { - return; - } -#endif - - uint8_t *vrb_map; - int first_rb; - start_meas(&eNB->schedule_dlsch); - VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_SCHEDULE_DLSCH, VCD_FUNCTION_IN); - - - - aggregation = 2; - for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) { - N_RB_DL[CC_id] = to_prb(cc[CC_id].mib->message.dl_Bandwidth); - min_rb_unit[CC_id] = get_min_rb_unit(module_idP, CC_id); - // get number of PRBs less those used by common channels - total_nb_available_rb[CC_id] = N_RB_DL[CC_id]; - for (i = 0; i < N_RB_DL[CC_id]; i++) - if (cc[CC_id].vrb_map[i] != 0) - total_nb_available_rb[CC_id]--; - - N_RBG[CC_id] = to_rbg(cc[CC_id].mib->message.dl_Bandwidth); - - // store the global enb stats: - eNB->eNB_stats[CC_id].num_dlactive_UEs = UE_list->num_UEs; - eNB->eNB_stats[CC_id].available_prbs = total_nb_available_rb[CC_id]; - eNB->eNB_stats[CC_id].total_available_prbs += total_nb_available_rb[CC_id]; - eNB->eNB_stats[CC_id].dlsch_bytes_tx = 0; - eNB->eNB_stats[CC_id].dlsch_pdus_tx = 0; - } - - /// CALLING Pre_Processor for downlink scheduling (Returns estimation of RBs required by each UE and the allocation on sub-band) - - VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_DLSCH_PREPROCESSOR, VCD_FUNCTION_IN); - //start_meas(&eNB->schedule_dlsch_preprocessor); - //dlsch_scheduler_pre_processor(module_idP, - // frameP, - // subframeP, - // N_RBG, - // mbsfn_flag); - //stop_meas(&eNB->schedule_dlsch_preprocessor); - VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_DLSCH_PREPROCESSOR, VCD_FUNCTION_OUT); - - - for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) - { - vrb_map = cc[CC_id].vrb_map; - - LOG_D(MAC, "doing schedule_ue_spec for CC_id %d\n", CC_id); - - dl_req = &eNB->DL_req[CC_id].dl_config_request_body; - - if (mbsfn_flag[CC_id] > 0) - continue; - - unsigned int rmax; - unsigned int narrowBandindex_index; - unsigned int first_rb, rep, reps; - - // rmax from RRC connection setup - getRepetition(&UE_list->UE_template[CC_id][UE_id], &rmax, &narrowBandindex_index); - - first_rb = narrowband_to_first_rb(cc,narrowBandindex_index); - - if (vrb_map[first_rb] == 1) // skip scheduling emtc UEs if first RB is taken - continue ; - - for (UE_id = UE_list->head; UE_id >= 0; UE_id = UE_list->next[UE_id]) - { - - if (UE_list->UE_template[CC_id][UE_id].rach_resource_type ==0 ) // do the following scheduling only if the UE is emtc - continue ; - - //[khalid] ******** allocate here the vrb_map - // 1st check on the vrb_map[] and allocate the one that is next to them - - // at the end of the scheduler make sure the right subbands coresponding to these RBs are allocated the UE in UE_template directely - // also check on the fill_DCI function - - - - vrb_map[first_rb] = 1; - vrb_map[first_rb + 1] = 1; - vrb_map[first_rb + 2] = 1; - vrb_map[first_rb + 3] = 1; - vrb_map[first_rb + 4] = 1; - vrb_map[first_rb + 5] = 1; - - - - - - continue_flag = 0; // reset the flag to allow allocation for the remaining UEs - rnti = UE_RNTI(module_idP, UE_id); - eNB_UE_stats = &UE_list->eNB_UE_stats[CC_id][UE_id]; - ue_sched_ctl = &UE_list->UE_sched_ctrl[UE_id]; - - //[khalid] allocate the middle RB subbands in sf 1,5 for synch signals and PBCH - - - - - if (rnti == NOT_A_RNTI) { - LOG_D(MAC, "Cannot find rnti for UE_id %d (num_UEs %d)\n", UE_id, UE_list->num_UEs); - continue_flag = 1; - } - - if (eNB_UE_stats == NULL) { - LOG_D(MAC, "[eNB] Cannot find eNB_UE_stats\n"); - continue_flag = 1; - } - - //if (continue_flag != 1) { - // switch (get_tmode(module_idP, CC_id, UE_id)) { - // case 1: - // case 2: - // case 7: - // aggregation = get_aggregation(get_bw_index(module_idP, CC_id), - // eNB_UE_stats->dl_cqi, - // format1); - // break; - // case 3: - // aggregation = get_aggregation(get_bw_index(module_idP, CC_id), - // eNB_UE_stats->dl_cqi, - // format2A); - // break; - // default: - // LOG_W(MAC, "Unsupported transmission mode %d\n", get_tmode(module_idP, CC_id, UE_id)); - // aggregation = 2; - // } - //} - - if ((ue_sched_ctl->pre_nb_available_rbs[CC_id] == 0) || // no RBs allocated - CCE_allocation_infeasible(module_idP, CC_id, 0, subframeP, aggregation, rnti) - ) { - LOG_D(MAC, "[eNB %d] Frame %d : no RB allocated for UE %d on CC_id %d: continue \n", - module_idP, frameP, UE_id, CC_id); - continue_flag = 1; //to next user (there might be rbs availiable for other UEs in TM5 - } - - //if (cc[CC_id].tdd_Config != NULL) { //TDD - // set_ue_dai(subframeP, - // UE_id, - // CC_id, - // cc[CC_id].tdd_Config->subframeAssignment, - // UE_list); - // // update UL DAI after DLSCH scheduling - // set_ul_DAI(module_idP, UE_id, CC_id, frameP, subframeP); - //} - - //if (continue_flag == 1) { - // add_ue_dlsch_info(module_idP, - // CC_id, - // UE_id, - // subframeP, - // S_DL_NONE); - // continue; - // } - - nb_available_rb = 6; // to be checked - harq_pid = ue_sched_ctl->harq_pid[CC_id]; - round = ue_sched_ctl->round[CC_id]; - UE_list->eNB_UE_stats[CC_id][UE_id].crnti = rnti; - UE_list->eNB_UE_stats[CC_id][UE_id].rrc_status = mac_eNB_get_rrc_status(module_idP, rnti);x - UE_list->eNB_UE_stats[CC_id][UE_id].harq_pid = harq_pid; - UE_list->eNB_UE_stats[CC_id][UE_id].harq_round = round; - - sdu_length_total = 0; - num_sdus = 0; - - - //DevCheck(((eNB_UE_stats->dl_cqi < MIN_CQI_VALUE) || (eNB_UE_stats->dl_cqi > MAX_CQI_VALUE)), - //eNB_UE_stats->dl_cqi, MIN_CQI_VALUE, MAX_CQI_VALUE); - - eNB_UE_stats->dlsch_mcs1 = cqi_to_mcs[eNB_UE_stats->dl_cqi]; //to be checked - eNB_UE_stats->dlsch_mcs1 = cmin(eNB_UE_stats->dlsch_mcs1, 15); - - - // store stats - UE_list->eNB_UE_stats[CC_id][UE_id].dl_cqi = eNB_UE_stats->dl_cqi; - - // initializing the rb allocation indicator for each UE - //to be checked - for (j = 0; j < N_RBG[CC_id]; j++) { - UE_list->UE_template[CC_id][UE_id].rballoc_subband[harq_pid][j] = 0; - } - - LOG_D(MAC, "[eNB %d] Frame %d: Scheduling UE %d on CC_id %d (rnti %x, harq_pid %d, round %d, rb %d, cqi %d, mcs %d, rrc %d)\n", - module_idP, frameP, UE_id, CC_id, rnti, harq_pid, round, nb_available_rb, - eNB_UE_stats->dl_cqi, eNB_UE_stats->dlsch_mcs1, - UE_list->eNB_UE_stats[CC_id][UE_id].rrc_status); - - - - // process retransmission - - if (round > 0) - { - - - // choose r3 by default for RAR (Table 9.1.5-5) - rep = 2; - // get actual repetition count from Table 9.1.5-3 - reps = (rmax <= 8) ? (1 << rep) : (rmax >> (3 - rep)); - - - // get freq_allocation - nb_rb = 6;//UE_list->UE_template[CC_id][UE_id].nb_rb[harq_pid]; - - if (nb_rb <= nb_available_rb) - { - - - //if (nb_rb == ue_sched_ctl->pre_nb_available_rbs[CC_id]) { - for (j = 0; j < N_RBG[CC_id]; j++) { // for indicating the rballoc for each sub-band - UE_list->UE_template[CC_id][UE_id].rballoc_subband[harq_pid][j] = ue_sched_ctl->rballoc_sub_UE[CC_id][j]; - } - //} - //else { - // nb_rb_temp = nb_rb; - // j = 0; - - // while ((nb_rb_temp > 0) && (j < N_RBG[CC_id])) { - // if (ue_sched_ctl->rballoc_sub_UE[CC_id][j] == 1) { - // UE_list->UE_template[CC_id][UE_id].rballoc_subband[harq_pid][j] = ue_sched_ctl->rballoc_sub_UE[CC_id][j]; - - // if ((j == N_RBG[CC_id] - 1) && - // ((N_RB_DL[CC_id] == 25) || - // (N_RB_DL[CC_id] == 50))) { - // nb_rb_temp = nb_rb_temp - min_rb_unit[CC_id] + 1; - // } - // else { - // nb_rb_temp = nb_rb_temp - min_rb_unit[CC_id]; - // } - // } - - // j = j + 1; - // } - //} - - nb_available_rb -= nb_rb; - - //eNB->mu_mimo_mode[UE_id].pre_nb_available_rbs = nb_rb; - //eNB->mu_mimo_mode[UE_id].dl_pow_off = ue_sched_ctl->dl_pow_off[CC_id]; - - //for(j=0; jmu_mimo_mode[UE_id].rballoc_sub[j] = UE_list->UE_template[CC_id][UE_id].rballoc_subband[harq_pid][j]; - //} - - - switch (get_tmode(module_idP, CC_id, UE_id)) { - case 1: - case 2: - case 7: - default: - { - - if ((UE_list->UE_template[CC_id][UE_id].mpdcch_repetition_cnt == 0) && - (mpdcch_sf_condition(eNB, CC_id, frameP, subframeP, rmax, TYPEUESPEC,UE_id) > 0)) - { - // MPDCCH configuration for RAR - dl_config_pdu = &dl_req->dl_config_pdu_list[dl_req->number_pdu]; - memset((void*)dl_config_pdu, 0, sizeof(nfapi_dl_config_request_pdu_t)); - dl_config_pdu->pdu_type = NFAPI_DL_CONFIG_MPDCCH_PDU_TYPE; - dl_config_pdu->pdu_size = (uint8_t)(2 + sizeof(nfapi_dl_config_mpdcch_pdu)); - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.dci_format = (UE_list->UE_template[CC_id][UE_id].rach_resource_type > 1) ? 11 : 10; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.mpdcch_narrow_band = narrowBandindex_index; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.number_of_prb_pairs = 6; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.resource_block_assignment = 0; // Note: this can be dynamic - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.mpdcch_tansmission_type = 1; // imposed (9.1.5 in 213) for Type 2 Common search space - AssertFatal(cc[CC_id].sib1_v13ext->bandwidthReducedAccessRelatedInfo_r13 != NULL, - "cc[CC_id].sib1_v13ext->bandwidthReducedAccessRelatedInfo_r13 is null\n"); - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.start_symbol = cc[CC_id].sib1_v13ext->bandwidthReducedAccessRelatedInfo_r13->startSymbolBR_r13; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.ecce_index = 0; // Note: this should be dynamic - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.aggregation_level = 16; // OK for CEModeA r1-3 (9.1.5-1b) or CEModeB r1-4 - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.rnti_type = 4; // other-RNTI - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.rnti = rnti; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.ce_mode = (UE_list->UE_template[CC_id][UE_id].rach_resource_type < 3) ? 1 : 2; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.drms_scrambling_init = cc[CC_id].physCellId; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.initial_transmission_sf_io = (frameP * 10) + subframeP; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.transmission_power = 6000; // 0dB - - //[khalid] missing DCI format should be 10 for 6-1A - - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.resource_block_coding = getRIV(6, 0, 6); // Note: still to be checked if it should not be (getRIV(N_RB_DL,first_rb,6)) : Check nFAPI specifications and what is done L1 with this parameter - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.mcs = UE_list->UE_template[CC_id][UE_id].oldmcs1[harq_pid]; // adjust according to size of RAR, 208 bits with N1A_PRB=3 - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.pdsch_reptition_levels = 4; // fix to 4 for now - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.redundancy_version = (round & 3); - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.new_data_indicator = UE_list->UE_template[CC_id][UE_id].oldNDI[harq_pid]; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.harq_process = harq_pid; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.tpmi_length = 0; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.tpmi = 0; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.pmi_flag = 0; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.pmi = 0; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.harq_resource_offset = 0; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.dci_subframe_repetition_number = rep; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.tpc = 1;// N1A_PRB=3 (36.212); => 208 bits for mcs=4, choose mcs according t message size TBD - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.downlink_assignment_index_length = 0; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.downlink_assignment_index = 0; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.allocate_prach_flag = 0; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.preamble_index = 0; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.prach_mask_index = 0; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.starting_ce_level = 0; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.srs_request = 0; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.antenna_ports_and_scrambling_identity_flag = 0; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.antenna_ports_and_scrambling_identity = 0; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.frequency_hopping_enabled_flag = 0; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.paging_direct_indication_differentiation_flag = 0; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.direct_indication = 0; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.total_dci_length_including_padding = 0; // this is not needed by OAI L1, but should be filled in - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.number_of_tx_antenna_ports = 1; - UE_list->UE_template[CC_id][UE_id].mpdcch_repetition_cnt++; - dl_req->number_pdu++; - - - - - //eNB_UE_stats->dlsch_trials[round]++; - UE_list->eNB_UE_stats[CC_id][UE_id].num_retransmission += 1; - UE_list->eNB_UE_stats[CC_id][UE_id].rbs_used_retx = nb_rb; - UE_list->eNB_UE_stats[CC_id][UE_id].total_rbs_used_retx += nb_rb; - UE_list->eNB_UE_stats[CC_id][UE_id].dlsch_mcs1 = eNB_UE_stats->dlsch_mcs1; - UE_list->eNB_UE_stats[CC_id][UE_id].dlsch_mcs2 = eNB_UE_stats->dlsch_mcs1; - - add_ue_dlsch_info(module_idP, - CC_id, - UE_id, - subframeP, - S_DL_SCHEDULED); - - } //repetition_count==0 && SF condition met - else if (UE_list->UE_template[CC_id][UE_id].mpdcch_repetition_cnt > 0) - { - // we're in a stream of repetitions - UE_list->UE_template[CC_id][UE_id].mpdcch_repetition_cnt++; - if (UE_list->UE_template[CC_id][UE_id].mpdcch_repetition_cnt == reps) - { - // this is the last mpdcch repetition - if (cc[CC_id].tdd_Config == NULL) { // FDD case - // wait 2 subframes for PDSCH transmission - if (subframeP > 7) UE_list->UE_template[CC_id][UE_id].Msg2_frame = (frameP + 1) & 1023; - else UE_list->UE_template[CC_id][UE_id].Msg2_frame = frameP; - UE_list->UE_template[CC_id][UE_id].Msg2_subframe = (subframeP + 2) % 10; // +2 is the "n+x" from Section 7.1.11 in 36.213 - } - else { - AssertFatal(1 == 0, "TDD case not done yet\n"); - } - } // mpdcch_repetition_count == reps - if ((UE_list->UE_template[CC_id][UE_id].Msg2_frame == frameP) && (UE_list->UE_template[CC_id][UE_id].Msg2_subframe == subframeP)) { - // Program PDSCH - - dl_config_pdu = &dl_req->dl_config_pdu_list[dl_req->number_pdu]; - memset((void*)dl_config_pdu, 0, sizeof(nfapi_dl_config_request_pdu_t)); - dl_config_pdu->pdu_type = NFAPI_DL_CONFIG_DLSCH_PDU_TYPE; - dl_config_pdu->pdu_size = (uint8_t)(2 + sizeof(nfapi_dl_config_dlsch_pdu)); - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.pdu_index = eNB->pdu_index[CC_id]; - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.rnti = rnti; - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.resource_allocation_type = 4; // format 6-1A - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.virtual_resource_block_assignment_flag = 0; // localized - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.resource_block_coding = getRIV(N_RB_DL, first_rb, 6); - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.modulation = 2; //QPSK - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.redundancy_version = (round & 3); - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.transport_blocks = 1;// first block - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.transport_block_to_codeword_swap_flag = 0; - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.transmission_scheme = (cc->p_eNB == 1) ? 0 : 1; - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.number_of_layers = 1; - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.number_of_subbands = 1; - // dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.codebook_index = ; - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.ue_category_capacity = 1; - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.pa = 4; // 0 dB - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.delta_power_offset_index = 0; - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.ngap = 0; - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.nprb = get_subbandsize(cc->mib->message.dl_Bandwidth); // ignored - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.transmission_mode = (cc->p_eNB == 1) ? 1 : 2; - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.num_bf_prb_per_subband = 1; - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.num_bf_vector = 1; - // dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.bf_vector = ; - - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel13.ue_type = (UE_list->UE_template[CC_id][UE_id].rach_resource_type < 3) ? 1 : 2;; - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel13.pdsch_payload_type = 2; // not SI message - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel13.initial_transmission_sf_io = (10 * frameP) + subframeP; - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel13.drms_table_flag = 0; - dl_req->number_pdu++; - - - } - } - - } - - - - - } - - - - - } - else { - LOG_D(MAC, "[eNB %d] Frame %d CC_id %d : don't schedule UE %d, its retransmission takes more resources than we have\n", - module_idP, frameP, CC_id, UE_id); - } - } - else - { - // This is a potentially new SDU opportunity // - - rlc_status.bytes_in_buffer = 0; - // Now check RLC information to compute number of required RBs - // get maximum TBS size for RLC request - - - - TBS = 408; - // check first for RLC data on DCCH - // add the length for all the control elements (timing adv, drx, etc) : header + payload - - ta_len = (ue_sched_ctl->ta_update != 0) ? 2 : 0; - - header_len_dcch = 2; // 2 bytes DCCH SDU subheader - - if (TBS - ta_len - header_len_dcch > 0) { - rlc_status = mac_rlc_status_ind( - module_idP, - rnti, - module_idP, - frameP, - subframeP, - ENB_FLAG_YES, - MBMS_FLAG_NO, - DCCH, - (TBS - ta_len - header_len_dcch)); // transport block set size - - sdu_lengths[0] = 0; - - if (rlc_status.bytes_in_buffer > 0) { // There is DCCH to transmit - LOG_D(MAC, "[eNB %d] Frame %d, DL-DCCH->DLSCH CC_id %d, Requesting %d bytes from RLC (RRC message)\n", - module_idP, frameP, CC_id, TBS - header_len_dcch); - sdu_lengths[0] = mac_rlc_data_req( - module_idP, - rnti, - module_idP, - frameP, - ENB_FLAG_YES, - MBMS_FLAG_NO, - DCCH, - TBS, //not used - (char *)&dlsch_buffer[0]); - - T(T_ENB_MAC_UE_DL_SDU, T_INT(module_idP), T_INT(CC_id), T_INT(rnti), T_INT(frameP), T_INT(subframeP), - T_INT(harq_pid), T_INT(DCCH), T_INT(sdu_lengths[0])); - - LOG_D(MAC, "[eNB %d][DCCH] CC_id %d Got %d bytes from RLC\n", module_idP, CC_id, sdu_lengths[0]); - sdu_length_total = sdu_lengths[0]; - sdu_lcids[0] = DCCH; - UE_list->eNB_UE_stats[CC_id][UE_id].num_pdu_tx[DCCH] += 1; - UE_list->eNB_UE_stats[CC_id][UE_id].num_bytes_tx[DCCH] += sdu_lengths[0]; - num_sdus = 1; -#ifdef DEBUG_eNB_SCHEDULER - LOG_T(MAC, "[eNB %d][DCCH] CC_id %d Got %d bytes :", module_idP, CC_id, sdu_lengths[0]); - - for (j = 0; j < sdu_lengths[0]; j++) { - LOG_T(MAC, "%x ", dlsch_buffer[j]); - } - - LOG_T(MAC, "\n"); -#endif - } - else { - header_len_dcch = 0; - sdu_length_total = 0; - } - } - - // check for DCCH1 and update header information (assume 2 byte sub-header) - if (TBS - ta_len - header_len_dcch - sdu_length_total > 0) { - rlc_status = mac_rlc_status_ind( - module_idP, - rnti, - module_idP, - frameP, - subframeP, - ENB_FLAG_YES, - MBMS_FLAG_NO, - DCCH + 1, - (TBS - ta_len - header_len_dcch - sdu_length_total)); // transport block set size less allocations for timing advance and - // DCCH SDU - sdu_lengths[num_sdus] = 0; - - if (rlc_status.bytes_in_buffer > 0) { - LOG_I(MAC, "[eNB %d], Frame %d, DCCH1->DLSCH, CC_id %d, Requesting %d bytes from RLC (RRC message)\n", - module_idP, frameP, CC_id, TBS - header_len_dcch - sdu_length_total); - sdu_lengths[num_sdus] += mac_rlc_data_req( - module_idP, - rnti, - module_idP, - frameP, - ENB_FLAG_YES, - MBMS_FLAG_NO, - DCCH + 1, - TBS, //not used - (char *)&dlsch_buffer[sdu_length_total]); - - T(T_ENB_MAC_UE_DL_SDU, T_INT(module_idP), T_INT(CC_id), T_INT(rnti), T_INT(frameP), T_INT(subframeP), - T_INT(harq_pid), T_INT(DCCH + 1), T_INT(sdu_lengths[num_sdus])); - - sdu_lcids[num_sdus] = DCCH1; - sdu_length_total += sdu_lengths[num_sdus]; - header_len_dcch += 2; - UE_list->eNB_UE_stats[CC_id][UE_id].num_pdu_tx[DCCH1] += 1; - UE_list->eNB_UE_stats[CC_id][UE_id].num_bytes_tx[DCCH1] += sdu_lengths[num_sdus]; - num_sdus++; -#ifdef DEBUG_eNB_SCHEDULER - LOG_T(MAC, "[eNB %d][DCCH1] CC_id %d Got %d bytes :", module_idP, CC_id, sdu_lengths[num_sdus]); - - for (j = 0; j < sdu_lengths[num_sdus]; j++) { - LOG_T(MAC, "%x ", dlsch_buffer[j]); - } - - LOG_T(MAC, "\n"); -#endif - - } - } - - // assume the max dtch header size, and adjust it later - header_len_dtch = 0; - header_len_dtch_last = 0; // the header length of the last mac sdu - // lcid has to be sorted before the actual allocation (similar struct as ue_list). - for (lcid = NB_RB_MAX - 1; lcid >= DTCH; lcid--) { - // TBD: check if the lcid is active - - header_len_dtch += 3; - header_len_dtch_last = 3; - LOG_D(MAC, "[eNB %d], Frame %d, DTCH%d->DLSCH, Checking RLC status (tbs %d, len %d)\n", - module_idP, frameP, lcid, TBS, - TBS - ta_len - header_len_dcch - sdu_length_total - header_len_dtch); - - if (TBS - ta_len - header_len_dcch - sdu_length_total - header_len_dtch > 0) { // NN: > 2 ? - rlc_status = mac_rlc_status_ind(module_idP, - rnti, - module_idP, - frameP, - subframeP, - ENB_FLAG_YES, - MBMS_FLAG_NO, - lcid, - TBS - ta_len - header_len_dcch - sdu_length_total - header_len_dtch); - - - if (rlc_status.bytes_in_buffer > 0) { - - LOG_D(MAC, "[eNB %d][USER-PLANE DEFAULT DRB] Frame %d : DTCH->DLSCH, Requesting %d bytes from RLC (lcid %d total hdr len %d)\n", - module_idP, frameP, TBS - header_len_dcch - sdu_length_total - header_len_dtch, lcid, header_len_dtch); - sdu_lengths[num_sdus] = mac_rlc_data_req(module_idP, - rnti, - module_idP, - frameP, - ENB_FLAG_YES, - MBMS_FLAG_NO, - lcid, - TBS, //not used - (char*)&dlsch_buffer[sdu_length_total]); - T(T_ENB_MAC_UE_DL_SDU, T_INT(module_idP), T_INT(CC_id), T_INT(rnti), T_INT(frameP), T_INT(subframeP), - T_INT(harq_pid), T_INT(lcid), T_INT(sdu_lengths[num_sdus])); - - LOG_D(MAC, "[eNB %d][USER-PLANE DEFAULT DRB] Got %d bytes for DTCH %d \n", module_idP, sdu_lengths[num_sdus], lcid); - sdu_lcids[num_sdus] = lcid; - sdu_length_total += sdu_lengths[num_sdus]; - UE_list->eNB_UE_stats[CC_id][UE_id].num_pdu_tx[lcid] += 1; - UE_list->eNB_UE_stats[CC_id][UE_id].num_bytes_tx[lcid] += sdu_lengths[num_sdus]; - if (sdu_lengths[num_sdus] < 128) { - header_len_dtch--; - header_len_dtch_last--; - } - num_sdus++; - } // no data for this LCID - else { - header_len_dtch -= 3; - } - } // no TBS left - else { - header_len_dtch -= 3; - break; - } - } - if (header_len_dtch == 0) - header_len_dtch_last = 0; - // there is at least one SDU - // if (num_sdus > 0 ){ - if ((sdu_length_total + header_len_dcch + header_len_dtch) > 0) { - - // Now compute number of required RBs for total sdu length - // Assume RAH format 2 - // adjust header lengths - header_len_dcch_tmp = header_len_dcch; - header_len_dtch_tmp = header_len_dtch; - if (header_len_dtch == 0) { - header_len_dcch = (header_len_dcch > 0) ? 1 : 0;//header_len_dcch; // remove length field - } - else { - header_len_dtch_last -= 1; // now use it to find how many bytes has to be removed for the last MAC SDU - header_len_dtch = (header_len_dtch > 0) ? header_len_dtch - header_len_dtch_last : header_len_dtch; // remove length field for the last SDU - } - - //mcs = eNB_UE_stats->dlsch_mcs1; - //if (mcs == 0) { - // nb_rb = 4; // don't let the TBS get too small - //} - //else { - // nb_rb = min_rb_unit[CC_id]; - //} - - //[khalid]: maximum MCS (7 or 15) depend on the DCI formate used from UE_list->UE_template[CC_id [UE_id].rach_resource_type - - mcs = 4; - nb_rb = 6; - - - TBS = 408;//get_TBS_DL(mcs, nb_rb); - - //while (TBS < (sdu_length_total + header_len_dcch + header_len_dtch + ta_len)) { - // nb_rb += min_rb_unit[CC_id]; // - - // if (nb_rb > nb_available_rb) { // if we've gone beyond the maximum number of RBs - // // (can happen if N_RB_DL is odd) - // TBS = get_TBS_DL(eNB_UE_stats->dlsch_mcs1, nb_available_rb); - // nb_rb = nb_available_rb; - // break; - // } - - // TBS = get_TBS_DL(eNB_UE_stats->dlsch_mcs1, nb_rb); - //} - - //if (nb_rb == ue_sched_ctl->pre_nb_available_rbs[CC_id]) { - for (j = 0; j < N_RBG[CC_id]; j++) { // for indicating the rballoc for each sub-band - UE_list->UE_template[CC_id][UE_id].rballoc_subband[harq_pid][j] = ue_sched_ctl->rballoc_sub_UE[CC_id][j]; - } - //} - //else - //{ - // nb_rb_temp = nb_rb; - // j = 0; - - // while ((nb_rb_temp > 0) && (j < N_RBG[CC_id])) { - // if (ue_sched_ctl->rballoc_sub_UE[CC_id][j] == 1) { - // UE_list->UE_template[CC_id][UE_id].rballoc_subband[harq_pid][j] = ue_sched_ctl->rballoc_sub_UE[CC_id][j]; - - // if ((j == N_RBG[CC_id] - 1) && - // ((N_RB_DL[CC_id] == 25) || - // (N_RB_DL[CC_id] == 50))) { - // nb_rb_temp = nb_rb_temp - min_rb_unit[CC_id] + 1; - // } - // else { - // nb_rb_temp = nb_rb_temp - min_rb_unit[CC_id]; - // } - // } - - // j = j + 1; - // } - //} - - //RC.eNB[module_idP][CC_id]->mu_mimo_mode[UE_id].pre_nb_available_rbs = nb_rb; - //RC.eNB[module_idP][CC_id]->mu_mimo_mode[UE_id].dl_pow_off = ue_sched_ctl->dl_pow_off[CC_id]; - - //for(j=0; jmu_mimo_mode[UE_id].rballoc_sub[j] = UE_list->UE_template[CC_id][UE_id].rballoc_subband[harq_pid][j]; - - //} - // - // decrease mcs until TBS falls below required length - //while ((TBS > (sdu_length_total + header_len_dcch + header_len_dtch + ta_len)) && (mcs > 0)) { - // mcs--; - // TBS = get_TBS_DL(mcs, nb_rb); - //} - - // if we have decreased too much or we don't have enough RBs, increase MCS - //while ((TBS < (sdu_length_total + header_len_dcch + header_len_dtch + ta_len)) && (((ue_sched_ctl->dl_pow_off[CC_id] > 0) && (mcs < 28)) - // || ((ue_sched_ctl->dl_pow_off[CC_id] == 0) && (mcs <= 15)))) { - // mcs++; - // TBS = get_TBS_DL(mcs, nb_rb); - //} - - LOG_D(MAC, "dlsch_mcs before and after the rate matching = (%d, %d)\n", eNB_UE_stats->dlsch_mcs1, mcs); - -#ifdef DEBUG_eNB_SCHEDULER - LOG_D(MAC, "[eNB %d] CC_id %d Generated DLSCH header (mcs %d, TBS %d, nb_rb %d)\n", - module_idP, CC_id, mcs, TBS, nb_rb); - // msg("[MAC][eNB ] Reminder of DLSCH with random data %d %d %d %d \n", - // TBS, sdu_length_total, offset, TBS-sdu_length_total-offset); -#endif - - if ((TBS - header_len_dcch - header_len_dtch - sdu_length_total - ta_len) <= 2) { - padding = (TBS - header_len_dcch - header_len_dtch - sdu_length_total - ta_len); - post_padding = 0; - } - else { - padding = 0; - - // adjust the header len - if (header_len_dtch == 0) { - header_len_dcch = header_len_dcch_tmp; - } - else { //if (( header_len_dcch==0)&&((header_len_dtch==1)||(header_len_dtch==2))) - header_len_dtch = header_len_dtch_tmp; - } - - post_padding = TBS - sdu_length_total - header_len_dcch - header_len_dtch - ta_len; // 1 is for the postpadding header - } - - - offset = generate_dlsch_header((unsigned char*)UE_list->DLSCH_pdu[CC_id][0][UE_id].payload[0], - num_sdus, //num_sdus - sdu_lengths, // - sdu_lcids, - 255, // no drx - ue_sched_ctl->ta_update, // timing advance - NULL, // contention res id - padding, - post_padding); - - //#ifdef DEBUG_eNB_SCHEDULER - if (ue_sched_ctl->ta_update) { - LOG_I(MAC, - "[eNB %d][DLSCH] Frame %d Generate header for UE_id %d on CC_id %d: sdu_length_total %d, num_sdus %d, sdu_lengths[0] %d, sdu_lcids[0] %d => payload offset %d,timing advance value : %d, padding %d,post_padding %d,(mcs %d, TBS %d, nb_rb %d),header_dcch %d, header_dtch %d\n", - module_idP, frameP, UE_id, CC_id, sdu_length_total, num_sdus, sdu_lengths[0], sdu_lcids[0], offset, - ue_sched_ctl->ta_update, padding, post_padding, mcs, TBS, nb_rb, header_len_dcch, header_len_dtch); - } - //#endif -#ifdef DEBUG_eNB_SCHEDULER - LOG_T(MAC, "[eNB %d] First 16 bytes of DLSCH : \n"); - - for (i = 0; i < 16; i++) { - LOG_T(MAC, "%x.", dlsch_buffer[i]); - } - - LOG_T(MAC, "\n"); -#endif - // cycle through SDUs and place in dlsch_buffer - memcpy(&UE_list->DLSCH_pdu[CC_id][0][UE_id].payload[0][offset], dlsch_buffer, sdu_length_total); - // memcpy(RC.mac[0].DLSCH_pdu[0][0].payload[0][offset],dcch_buffer,sdu_lengths[0]); - - // fill remainder of DLSCH with random data - for (j = 0; j < (TBS - sdu_length_total - offset); j++) { - UE_list->DLSCH_pdu[CC_id][0][UE_id].payload[0][offset + sdu_length_total + j] = (char)(taus() & 0xff); - } - - - if (opt_enabled == 1) { - trace_pdu(1, (uint8_t *)UE_list->DLSCH_pdu[CC_id][0][UE_id].payload[0], - TBS, module_idP, 3, UE_RNTI(module_idP, UE_id), - eNB->frame, eNB->subframe, 0, 0); - LOG_D(OPT, "[eNB %d][DLSCH] CC_id %d Frame %d rnti %x with size %d\n", - module_idP, CC_id, frameP, UE_RNTI(module_idP, UE_id), TBS); - } - - T(T_ENB_MAC_UE_DL_PDU_WITH_DATA, T_INT(module_idP), T_INT(CC_id), T_INT(rnti), T_INT(frameP), T_INT(subframeP), - T_INT(harq_pid), T_BUFFER(UE_list->DLSCH_pdu[CC_id][0][UE_id].payload[0], TBS)); - - UE_list->UE_template[CC_id][UE_id].nb_rb[harq_pid] = nb_rb; - - add_ue_dlsch_info(module_idP, - CC_id, - UE_id, - subframeP, - S_DL_SCHEDULED); - // store stats - eNB->eNB_stats[CC_id].dlsch_bytes_tx += sdu_length_total; - eNB->eNB_stats[CC_id].dlsch_pdus_tx += 1; - - UE_list->eNB_UE_stats[CC_id][UE_id].rbs_used = nb_rb; - UE_list->eNB_UE_stats[CC_id][UE_id].total_rbs_used += nb_rb; - UE_list->eNB_UE_stats[CC_id][UE_id].dlsch_mcs1 = 4;//eNB_UE_stats->dlsch_mcs1; - UE_list->eNB_UE_stats[CC_id][UE_id].dlsch_mcs2 = mcs; - UE_list->eNB_UE_stats[CC_id][UE_id].TBS = TBS; - - UE_list->eNB_UE_stats[CC_id][UE_id].overhead_bytes = TBS - sdu_length_total; - UE_list->eNB_UE_stats[CC_id][UE_id].total_sdu_bytes += sdu_length_total; - UE_list->eNB_UE_stats[CC_id][UE_id].total_pdu_bytes += TBS; - UE_list->eNB_UE_stats[CC_id][UE_id].total_num_pdus += 1; - - - - // do PUCCH power control - // this is the normalized RX power - eNB_UE_stats = &UE_list->eNB_UE_stats[CC_id][UE_id]; - normalized_rx_power = eNB_UE_stats->Po_PUCCH_dBm; - target_rx_power = get_target_pucch_rx_power(module_idP, CC_id) + 20; - - // this assumes accumulated tpc - // make sure that we are only sending a tpc update once a frame, otherwise the control loop will freak out - //int32_t framex10psubframe = UE_list->UE_template[CC_id][UE_id].pucch_tpc_tx_frame * 10 + UE_list->UE_template[CC_id][UE_id].pucch_tpc_tx_subframe; - //if (((framex10psubframe + 10) <= (frameP * 10 + subframeP)) || //normal case - // ((framex10psubframe > (frameP * 10 + subframeP)) && (((10240 - framex10psubframe + frameP * 10 + subframeP) >= 10)))) //frame wrap-around - // if (eNB_UE_stats->Po_PUCCH_update == 1) { - // eNB_UE_stats->Po_PUCCH_update = 0; - - // UE_list->UE_template[CC_id][UE_id].pucch_tpc_tx_frame = frameP; - // UE_list->UE_template[CC_id][UE_id].pucch_tpc_tx_subframe = subframeP; - - // if (normalized_rx_power > (target_rx_power + 1)) { - // tpc = 0; //-1 - // tpc_accumulated--; - // } - // else if (normalized_rx_power < (target_rx_power - 1)) { - // tpc = 2; //+1 - // tpc_accumulated++; - // } - // else { - // tpc = 1; //0 - // } - // - // - - // } // Po_PUCCH has been updated - // else { - // tpc = 1; //0 - // } // time to do TPC update - //else { - // tpc = 1; //0 - //} - - { - - // choose r3 by default for RAR (Table 9.1.5-5) - rep = 2; - // get actual repetition count from Table 9.1.5-3 - reps = (rmax <= 8) ? (1 << rep) : (rmax >> (3 - rep)); - - - - if ((UE_list->UE_template[CC_id][UE_id].mpdcch_repetition_cnt == 0) && - (mpdcch_sf_condition(eNB, CC_id, frameP, subframeP, rmax, TYPEUESPEC,UE_id) > 0)) - { - // MPDCCH configuration for RAR - dl_config_pdu = &dl_req->dl_config_pdu_list[dl_req->number_pdu]; - memset((void*)dl_config_pdu, 0, sizeof(nfapi_dl_config_request_pdu_t)); - dl_config_pdu->pdu_type = NFAPI_DL_CONFIG_MPDCCH_PDU_TYPE; - dl_config_pdu->pdu_size = (uint8_t)(2 + sizeof(nfapi_dl_config_mpdcch_pdu)); - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.dci_format = (UE_list->UE_template[CC_id][UE_id].rach_resource_type > 1) ? 11 : 10; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.mpdcch_narrow_band = narrowBandindex_index; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.number_of_prb_pairs = 6; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.resource_block_assignment = 0; // Note: this can be dynamic - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.mpdcch_tansmission_type = 1; // imposed (9.1.5 in 213) for Type 2 Common search space - AssertFatal(cc[CC_id].sib1_v13ext->bandwidthReducedAccessRelatedInfo_r13 != NULL, - "cc[CC_id].sib1_v13ext->bandwidthReducedAccessRelatedInfo_r13 is null\n"); - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.start_symbol = cc[CC_id].sib1_v13ext->bandwidthReducedAccessRelatedInfo_r13->startSymbolBR_r13; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.ecce_index = 0; // Note: this should be dynamic - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.aggregation_level = 16; // OK for CEModeA r1-3 (9.1.5-1b) or CEModeB r1-4 - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.rnti_type = 4; // other-RNTI - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.rnti = rnti; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.ce_mode = (UE_list->UE_template[CC_id][UE_id].rach_resource_type < 3) ? 1 : 2; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.drms_scrambling_init = cc[CC_id].physCellId; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.initial_transmission_sf_io = (frameP * 10) + subframeP; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.transmission_power = 6000; // 0dB - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.resource_block_coding = getRIV(6, 0, 6); // Note: still to be checked if it should not be (getRIV(N_RB_DL,first_rb,6)) : Check nFAPI specifications and what is done L1 with this parameter - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.mcs = 4; // adjust according to size of RAR, 208 bits with N1A_PRB=3 - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.pdsch_reptition_levels = 4; // fix to 4 for now - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.redundancy_version = 0; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.new_data_indicator = 1 - UE_list->UE_template[CC_id][UE_id].oldNDI[harq_pid]; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.harq_process = harq_pid; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.tpmi_length = 0; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.tpmi = 0; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.pmi_flag = 0; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.pmi = 0; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.harq_resource_offset = 0; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.dci_subframe_repetition_number = rep; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.tpc = 1;// N1A_PRB=3 (36.212); => 208 bits for mcs=4, choose mcs according t message size TBD - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.downlink_assignment_index_length = 0; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.downlink_assignment_index = 0; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.allocate_prach_flag = 0; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.preamble_index = 0; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.prach_mask_index = 0; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.starting_ce_level = 0; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.srs_request = 0; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.antenna_ports_and_scrambling_identity_flag = 0; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.antenna_ports_and_scrambling_identity = 0; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.frequency_hopping_enabled_flag = 0; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.paging_direct_indication_differentiation_flag = 0; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.direct_indication = 0; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.total_dci_length_including_padding = 0; // this is not needed by OAI L1, but should be filled in - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.number_of_tx_antenna_ports = 1; - UE_list->UE_template[CC_id][UE_id].mpdcch_repetition_cnt++; - dl_req->number_pdu++; - - - // Toggle NDI for next time - LOG_D(MAC, "CC_id %d Frame %d, subframeP %d: Toggling Format1 NDI for UE %d (rnti %x/%d) oldNDI %d\n", - CC_id, frameP, subframeP, UE_id, - UE_list->UE_template[CC_id][UE_id].rnti, harq_pid, UE_list->UE_template[CC_id][UE_id].oldNDI[harq_pid]); - - UE_list->UE_template[CC_id][UE_id].oldNDI[harq_pid] = 1 - UE_list->UE_template[CC_id][UE_id].oldNDI[harq_pid]; - UE_list->UE_template[CC_id][UE_id].oldmcs1[harq_pid] = mcs; - UE_list->UE_template[CC_id][UE_id].oldmcs2[harq_pid] = 0; - - eNB->TX_req[CC_id].sfn_sf = (frameP << 3) + subframeP; - TX_req = &eNB->TX_req[CC_id].tx_request_body.tx_pdu_list[eNB->TX_req[CC_id].tx_request_body.number_of_pdus]; - TX_req->pdu_length = TBS; - TX_req->pdu_index = eNB->pdu_index[CC_id]++; - TX_req->num_segments = 1; - TX_req->segments[0].segment_length = TBS; - TX_req->segments[0].segment_data = eNB->UE_list.DLSCH_pdu[CC_id][0][(unsigned char)UE_id].payload[harq_pid]; - eNB->TX_req[CC_id].tx_request_body.number_of_pdus++; - - } //repetition_count==0 && SF condition met - else if (UE_list->UE_template[CC_id][UE_id].mpdcch_repetition_cnt > 0) - { - // we're in a stream of repetitions - UE_list->UE_template[CC_id][UE_id].mpdcch_repetition_cnt++; - if (UE_list->UE_template[CC_id][UE_id].mpdcch_repetition_cnt == reps) - { - // this is the last mpdcch repetition - if (cc[CC_id].tdd_Config == NULL) { // FDD case - // wait 2 subframes for PDSCH transmission - if (subframeP > 7) UE_list->UE_template[CC_id][UE_id].Msg2_frame = (frameP + 1) & 1023; - else UE_list->UE_template[CC_id][UE_id].Msg2_frame = frameP; - UE_list->UE_template[CC_id][UE_id].Msg2_subframe = (subframeP + 2) % 10; // +2 is the "n+x" from Section 7.1.11 in 36.213 - } - else { - AssertFatal(1 == 0, "TDD case not done yet\n"); - } - } // mpdcch_repetition_count == reps - if ((UE_list->UE_template[CC_id][UE_id].Msg2_frame == frameP) && (UE_list->UE_template[CC_id][UE_id].Msg2_subframe == subframeP)) { - // Program PDSCH - - dl_config_pdu = &dl_req->dl_config_pdu_list[dl_req->number_pdu]; - memset((void*)dl_config_pdu, 0, sizeof(nfapi_dl_config_request_pdu_t)); - dl_config_pdu->pdu_type = NFAPI_DL_CONFIG_DLSCH_PDU_TYPE; - dl_config_pdu->pdu_size = (uint8_t)(2 + sizeof(nfapi_dl_config_dlsch_pdu)); - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.pdu_index = eNB->pdu_index[CC_id]; - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.rnti = rnti; - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.resource_allocation_type = 4; // format 6-1A - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.virtual_resource_block_assignment_flag = 0; // localized - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.resource_block_coding = getRIV(N_RB_DL, first_rb, 6); - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.modulation = 2; //QPSK - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.redundancy_version = 0; - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.transport_blocks = 1;// first block - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.transport_block_to_codeword_swap_flag = 0; - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.transmission_scheme = (cc->p_eNB == 1) ? 0 : 1; - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.number_of_layers = 1; - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.number_of_subbands = 1; - // dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.codebook_index = ; - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.ue_category_capacity = 1; - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.pa = 4; // 0 dB - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.delta_power_offset_index = 0; - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.ngap = 0; - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.nprb = get_subbandsize(cc->mib->message.dl_Bandwidth); // ignored - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.transmission_mode = (cc->p_eNB == 1) ? 1 : 2; - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.num_bf_prb_per_subband = 1; - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.num_bf_vector = 1; - // dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.bf_vector = ; - - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel13.ue_type = (UE_list->UE_template[CC_id][UE_id].rach_resource_type < 3) ? 1 : 2;; - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel13.pdsch_payload_type = 2; // not SI message - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel13.initial_transmission_sf_io = (10 * frameP) + subframeP; - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel13.drms_table_flag = 0; - dl_req->number_pdu++; - - // Program UL processing for Msg3, same as regular LTE - //get_Msg3alloc(&cc[CC_idP], subframeP, frameP, &RA_template->Msg3_frame, &RA_template->Msg3_subframe); - - - //fill_rar_br(eNB, CC_idP, RA_template, frameP, subframeP, cc[CC_idP].RAR_pdu.payload, RA_template->rach_resource_type - 1); - //// DL request - //eNB->TX_req[CC_idP].sfn_sf = (frameP << 3) + subframeP; - //TX_req = &eNB->TX_req[CC_idP].tx_request_body.tx_pdu_list[eNB->TX_req[CC_idP].tx_request_body.number_of_pdus]; - //TX_req->pdu_length = 7; // This should be changed if we have more than 1 preamble - //TX_req->pdu_index = eNB->pdu_index[CC_idP]++; - //TX_req->num_segments = 1; - //TX_req->segments[0].segment_length = 7; - //TX_req->segments[0].segment_data = cc[CC_idP].RAR_pdu.payload; - //eNB->TX_req[CC_idP].tx_request_body.number_of_pdus++; - } - } - - } - - //dl_config_pdu = &dl_req->dl_config_pdu_list[dl_req->number_pdu]; - //memset((void*)dl_config_pdu, 0, sizeof(nfapi_dl_config_request_pdu_t)); - //dl_config_pdu->pdu_type = NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE; - //dl_config_pdu->pdu_size = (uint8_t)(2 + sizeof(nfapi_dl_config_dci_dl_pdu)); - //dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.dci_format = NFAPI_DL_DCI_FORMAT_1; - //dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level = get_aggregation(get_bw_index(module_idP, CC_id), eNB_UE_stats->dl_cqi, format1); - //dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti = rnti; - //dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti_type = 1; // CRNTI : see Table 4-10 from SCF082 - nFAPI specifications - //dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.transmission_power = 6000; // equal to RS power - - //dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.harq_process = harq_pid; - //dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.tpc = tpc; // dont adjust power when retransmitting - //dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.new_data_indicator_1 = 1 - UE_list->UE_template[CC_id][UE_id].oldNDI[harq_pid]; - //dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.mcs_1 = mcs; - //dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.redundancy_version_1 = 0; - ////deactivate second codeword - //dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.mcs_2 = 0; - //dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.redundancy_version_2 = 1; - - //dl_req->number_dci++; - //dl_req->number_pdu++; - - - } - else { // There is no data from RLC or MAC header, so don't schedule - - } - } - - if (cc[CC_id].tdd_Config != NULL) { // TDD - set_ul_DAI(module_idP, UE_id, CC_id, frameP, subframeP); - } - - } // UE_id loop - } // CC_id loop - - - fill_DLSCH_dci(module_idP, frameP, subframeP, mbsfn_flag); - - stop_meas(&eNB->schedule_dlsch); - VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_SCHEDULE_DLSCH, VCD_FUNCTION_OUT); - -} -*/ - - //------------------------------------------------------------------------------ void -schedule_ue_spec(module_id_t module_idP, int slice_idxP, - frame_t frameP, sub_frame_t subframeP, int *mbsfn_flag) +schedule_ue_spec(module_id_t module_idP, + int slice_idxP, + frame_t frameP, + sub_frame_t subframeP, + int *mbsfn_flag) //------------------------------------------------------------------------------ { int CC_id; @@ -1524,11 +474,19 @@ schedule_ue_spec(module_id_t module_idP, int slice_idxP, int lcid, offset, num_sdus = 0; int nb_rb, nb_rb_temp, nb_available_rb; uint16_t sdu_lengths[NB_RB_MAX]; - int TBS, j, rnti, padding = 0, post_padding = 0; + int TBS, j, padding = 0, post_padding = 0; + rnti_t rnti; unsigned char dlsch_buffer[MAX_DLSCH_PAYLOAD_BYTES]; int round = 0; int harq_pid = 0; + uint16_t release_num; + uint8_t ra_ii; eNB_UE_STATS *eNB_UE_stats = NULL; + UE_TEMPLATE *ue_template = NULL; + eNB_STATS *eNB_stats = NULL; + RRC_release_ctrl *release_ctrl = NULL; + DLSCH_PDU *dlsch_pdu = NULL; + RA_t *ra = NULL; int sdu_length_total = 0; eNB_MAC_INST *eNB = RC.mac[module_idP]; COMMON_channels_t *cc = eNB->common_channels; @@ -1536,7 +494,7 @@ schedule_ue_spec(module_id_t module_idP, int slice_idxP, int continue_flag = 0; int32_t normalized_rx_power, target_rx_power; int tpc = 1; - UE_sched_ctrl *ue_sched_ctl; + UE_sched_ctrl *ue_sched_ctrl; int mcs; int i; int min_rb_unit[NFAPI_CC_MAX]; @@ -1550,8 +508,12 @@ schedule_ue_spec(module_id_t module_idP, int slice_idxP, int header_length_last; int header_length_total; rrc_eNB_ue_context_t *ue_contextP = NULL; + int nb_mac_CC = RC.nb_mac_CC[module_idP]; + long dl_Bandwidth; + start_meas(&eNB->schedule_dlsch); - VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_SCHEDULE_DLSCH, VCD_FUNCTION_IN); + VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_SCHEDULE_DLSCH, + VCD_FUNCTION_IN); // for TDD: check that we have to act here, otherwise return if (cc[0].tdd_Config) { @@ -1563,22 +525,17 @@ schedule_ue_spec(module_id_t module_idP, int slice_idxP, break; case 1: - return; - break; - case 2: return; - break; case 3: - if ((tdd_sfa != 2) && (tdd_sfa != 5)) + if (tdd_sfa != 2 && tdd_sfa != 5) return; break; case 4: - if ((tdd_sfa != 1) && (tdd_sfa != 2) && (tdd_sfa != 4) - && (tdd_sfa != 5)) + if (tdd_sfa != 1 && tdd_sfa != 2 && tdd_sfa != 4 && tdd_sfa != 5) return; break; @@ -1588,14 +545,13 @@ schedule_ue_spec(module_id_t module_idP, int slice_idxP, case 6: case 7: - if ((tdd_sfa != 3) && (tdd_sfa != 4) && (tdd_sfa != 5)) + if (tdd_sfa != 3 && tdd_sfa != 4 && tdd_sfa != 5) return; break; case 8: - if ((tdd_sfa != 2) && (tdd_sfa != 3) && (tdd_sfa != 4) - && (tdd_sfa != 5)) + if (tdd_sfa != 2 && tdd_sfa != 3 && tdd_sfa != 4 && tdd_sfa != 5) return; break; @@ -1611,9 +567,11 @@ schedule_ue_spec(module_id_t module_idP, int slice_idxP, //weight = get_ue_weight(module_idP,UE_id); aggregation = 2; - for (CC_id = 0; CC_id < RC.nb_mac_CC[module_idP]; CC_id++) { - N_RB_DL[CC_id] = to_prb(cc[CC_id].mib->message.dl_Bandwidth); - min_rb_unit[CC_id] = get_min_rb_unit(module_idP, CC_id); + for (CC_id = 0, eNB_stats = &eNB->eNB_stats[0]; CC_id < nb_mac_CC; CC_id++, eNB_stats++) { + dl_Bandwidth = cc[CC_id].mib->message.dl_Bandwidth; + N_RB_DL[CC_id] = to_prb(dl_Bandwidth); + min_rb_unit[CC_id] = get_min_rb_unit(module_idP, + CC_id); // get number of PRBs less those used by common channels total_nb_available_rb[CC_id] = N_RB_DL[CC_id]; @@ -1621,18 +579,19 @@ schedule_ue_spec(module_id_t module_idP, int slice_idxP, if (cc[CC_id].vrb_map[i] != 0) total_nb_available_rb[CC_id]--; - N_RBG[CC_id] = to_rbg(cc[CC_id].mib->message.dl_Bandwidth); + N_RBG[CC_id] = to_rbg(dl_Bandwidth); // store the global enb stats: - eNB->eNB_stats[CC_id].num_dlactive_UEs = UE_list->num_UEs; - eNB->eNB_stats[CC_id].available_prbs = total_nb_available_rb[CC_id]; - eNB->eNB_stats[CC_id].total_available_prbs += total_nb_available_rb[CC_id]; - eNB->eNB_stats[CC_id].dlsch_bytes_tx = 0; - eNB->eNB_stats[CC_id].dlsch_pdus_tx = 0; + eNB_stats->num_dlactive_UEs = UE_list->num_UEs; + eNB_stats->available_prbs = total_nb_available_rb[CC_id]; + eNB_stats->total_available_prbs += total_nb_available_rb[CC_id]; + eNB_stats->dlsch_bytes_tx = 0; + eNB_stats->dlsch_pdus_tx = 0; } // CALLING Pre_Processor for downlink scheduling // (Returns estimation of RBs required by each UE and the allocation on sub-band) - VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_DLSCH_PREPROCESSOR, VCD_FUNCTION_IN); + VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_DLSCH_PREPROCESSOR, + VCD_FUNCTION_IN); start_meas(&eNB->schedule_dlsch_preprocessor); dlsch_scheduler_pre_processor(module_idP, slice_idxP, @@ -1641,7 +600,8 @@ schedule_ue_spec(module_id_t module_idP, int slice_idxP, mbsfn_flag, eNB->slice_info.rballoc_sub); stop_meas(&eNB->schedule_dlsch_preprocessor); - VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_DLSCH_PREPROCESSOR, VCD_FUNCTION_OUT); + VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_DLSCH_PREPROCESSOR, + VCD_FUNCTION_OUT); //RC.mac[module_idP]->slice_info.slice_counter--; // Do the multiplexing and actual allocation only when all slices have been pre-processed. @@ -1652,75 +612,84 @@ schedule_ue_spec(module_id_t module_idP, int slice_idxP, //} if (RC.mac[module_idP]->slice_info.interslice_share_active) { - dlsch_scheduler_interslice_multiplexing(module_idP, frameP, subframeP, eNB->slice_info.rballoc_sub); + dlsch_scheduler_interslice_multiplexing(module_idP, + frameP, + subframeP, + eNB->slice_info.rballoc_sub); /* the interslice multiplexing re-sorts the UE_list for the slices it tries * to multiplex, so we need to sort it for the current slice again */ - sort_UEs(module_idP, slice_idxP, frameP, subframeP); + sort_UEs(module_idP, + slice_idxP, + frameP, + subframeP); } - for (CC_id = 0; CC_id < RC.nb_mac_CC[module_idP]; CC_id++) { - LOG_D(MAC, "doing schedule_ue_spec for CC_id %d\n", CC_id); + for (CC_id = 0; CC_id < nb_mac_CC; CC_id++) { + LOG_D(MAC, "doing schedule_ue_spec for CC_id %d\n", + CC_id); dl_req = &eNB->DL_req[CC_id].dl_config_request_body; if (mbsfn_flag[CC_id] > 0) continue; for (UE_id = UE_list->head; UE_id >= 0; UE_id = UE_list->next[UE_id]) { - LOG_D(MAC, "doing schedule_ue_spec for CC_id %d UE %d\n", CC_id, UE_id); + LOG_D(MAC, "doing schedule_ue_spec for CC_id %d UE %d\n", + CC_id, + UE_id); continue_flag = 0; // reset the flag to allow allocation for the remaining UEs rnti = UE_RNTI(module_idP, UE_id); - eNB_UE_stats = &UE_list->eNB_UE_stats[CC_id][UE_id]; - ue_sched_ctl = &UE_list->UE_sched_ctrl[UE_id]; + ue_sched_ctrl = &UE_list->UE_sched_ctrl[UE_id]; + ue_template = &UE_list->UE_template[CC_id][UE_id]; - if (rnti == NOT_A_RNTI) { - LOG_D(MAC, "Cannot find rnti for UE_id %d (num_UEs %d)\n", UE_id, UE_list->num_UEs); - continue_flag = 1; - } - - if (UE_list->UE_template[CC_id][UE_id].rach_resource_type > 0) continue_flag=1; + if (ue_template->rach_resource_type > 0) continue_flag = 1; - if (eNB_UE_stats == NULL) { + if (&(UE_list->eNB_UE_stats[CC_id][UE_id]) == NULL) { LOG_D(MAC, "[eNB] Cannot find eNB_UE_stats\n"); continue_flag = 1; - } - - if (!ue_dl_slice_membership(module_idP, UE_id, slice_idxP)) { - LOG_D(MAC, "UE%d is not part of slice %d ID %d\n", - UE_id, slice_idxP, RC.mac[module_idP]->slice_info.dl[slice_idxP].id); - /* prevent execution of add_ue_dlsch_info(), it is done by the other - * slice */ - continue; + } else { + eNB_UE_stats = &(UE_list->eNB_UE_stats[CC_id][UE_id]); } if (continue_flag != 1) { - switch (get_tmode(module_idP, CC_id, UE_id)) { + switch (get_tmode(module_idP, + CC_id, + UE_id)) { case 1: case 2: case 7: - aggregation = get_aggregation(get_bw_index(module_idP, CC_id), - ue_sched_ctl->dl_cqi[CC_id], + aggregation = get_aggregation(get_bw_index(module_idP, + CC_id), + ue_sched_ctrl->dl_cqi[CC_id], format1); break; case 3: - aggregation = get_aggregation(get_bw_index(module_idP, CC_id), - ue_sched_ctl->dl_cqi[CC_id], + aggregation = get_aggregation(get_bw_index(module_idP, + CC_id), + ue_sched_ctrl->dl_cqi[CC_id], format2A); break; default: AssertFatal(1==0,"Unsupported transmission mode %d\n", get_tmode(module_idP, CC_id, UE_id)); aggregation = 2; + break; } } /* if (continue_flag != 1 */ - if ((ue_sched_ctl->pre_nb_available_rbs[CC_id] == 0) || // no RBs allocated - CCE_allocation_infeasible(module_idP, CC_id, 1, subframeP, - aggregation, rnti)) { - LOG_D(MAC, - "[eNB %d] Frame %d : no RB allocated for UE %d on CC_id %d: continue \n", - module_idP, frameP, UE_id, CC_id); + if (ue_sched_ctrl->pre_nb_available_rbs[CC_id] == 0 || // no RBs allocated + CCE_allocation_infeasible(module_idP, + CC_id, + 1, + subframeP, + aggregation, + rnti)) { + LOG_D(MAC, "[eNB %d] Frame %d : no RB allocated for UE %d on CC_id %d: continue \n", + module_idP, + frameP, + UE_id, + CC_id); continue_flag = 1; //to next user (there might be rbs availiable for other UEs in TM5 } @@ -1732,24 +701,36 @@ schedule_ue_spec(module_id_t module_idP, int slice_idxP, cc[CC_id].tdd_Config->subframeAssignment, UE_list); // update UL DAI after DLSCH scheduling - set_ul_DAI(module_idP, UE_id, CC_id, frameP, subframeP); + set_ul_DAI(module_idP, + UE_id, + CC_id, + frameP, + subframeP); } if (continue_flag == 1) { - add_ue_dlsch_info(module_idP, CC_id, UE_id, subframeP, S_DL_NONE); + add_ue_dlsch_info(module_idP, + CC_id, + UE_id, + subframeP, + S_DL_NONE, + rnti); continue; } - nb_available_rb = ue_sched_ctl->pre_nb_available_rbs[CC_id]; - harq_pid = frame_subframe2_dl_harq_pid(cc->tdd_Config,frameP,subframeP); - round = ue_sched_ctl->round[CC_id][harq_pid]; - UE_list->eNB_UE_stats[CC_id][UE_id].crnti = rnti; - UE_list->eNB_UE_stats[CC_id][UE_id].rrc_status = mac_eNB_get_rrc_status(module_idP, rnti); - UE_list->eNB_UE_stats[CC_id][UE_id].harq_pid = harq_pid; - UE_list->eNB_UE_stats[CC_id][UE_id].harq_round = round; + nb_available_rb = ue_sched_ctrl->pre_nb_available_rbs[CC_id]; + harq_pid = frame_subframe2_dl_harq_pid(cc->tdd_Config, + frameP, + subframeP); + round = ue_sched_ctrl->round[CC_id][harq_pid]; + eNB_UE_stats->crnti = rnti; + eNB_UE_stats->rrc_status = mac_eNB_get_rrc_status(module_idP, rnti); + eNB_UE_stats->harq_pid = harq_pid; + eNB_UE_stats->harq_round = round; - if (UE_list->eNB_UE_stats[CC_id][UE_id].rrc_status < RRC_CONNECTED) { - LOG_D(MAC, "UE %d is not in RRC_CONNECTED\n", UE_id); + if (eNB_UE_stats->rrc_status < RRC_CONNECTED) { + LOG_D(MAC, "UE %d is not in RRC_CONNECTED\n", + UE_id); continue; } @@ -1763,77 +744,84 @@ schedule_ue_spec(module_id_t module_idP, int slice_idxP, eNB_UE_stats->dl_cqi, MIN_CQI_VALUE, MAX_CQI_VALUE); */ if (nfapi_mode) { - eNB_UE_stats->dlsch_mcs1 = 10; // cqi_to_mcs[ue_sched_ctl->dl_cqi[CC_id]]; + eNB_UE_stats->dlsch_mcs1 = 10; // cqi_to_mcs[ue_sched_ctrl->dl_cqi[CC_id]]; } else { // this operation is also done in the preprocessor eNB_UE_stats->dlsch_mcs1 = cmin(eNB_UE_stats->dlsch_mcs1, eNB->slice_info.dl[slice_idxP].maxmcs); // cmin(eNB_UE_stats->dlsch_mcs1, openair_daq_vars.target_ue_dl_mcs); } // Store stats - // UE_list->eNB_UE_stats[CC_id][UE_id].dl_cqi= eNB_UE_stats->dl_cqi; + // eNB_UE_stats->dl_cqi= eNB_UE_stats->dl_cqi; // Initializing the rb allocation indicator for each UE for (j = 0; j < N_RBG[CC_id]; j++) { - UE_list->UE_template[CC_id][UE_id].rballoc_subband[harq_pid][j] = 0; + ue_template->rballoc_subband[harq_pid][j] = 0; } - LOG_D(MAC, - "[eNB %d] Frame %d: Scheduling UE %d on CC_id %d (rnti %x, harq_pid %d, round %d, rb %d, cqi %d, mcs %d, rrc %d)\n", - module_idP, frameP, UE_id, CC_id, rnti, harq_pid, round, - nb_available_rb, ue_sched_ctl->dl_cqi[CC_id], + LOG_D(MAC, "[eNB %d] Frame %d: Scheduling UE %d on CC_id %d (rnti %x, harq_pid %d, round %d, rb %d, cqi %d, mcs %d, rrc %d)\n", + module_idP, + frameP, UE_id, + CC_id, + rnti, + harq_pid, + round, + nb_available_rb, + ue_sched_ctrl->dl_cqi[CC_id], eNB_UE_stats->dlsch_mcs1, - UE_list->eNB_UE_stats[CC_id][UE_id].rrc_status); + eNB_UE_stats->rrc_status); /* process retransmission */ if (round != 8) { // get freq_allocation - nb_rb = UE_list->UE_template[CC_id][UE_id].nb_rb[harq_pid]; - TBS = get_TBS_DL(UE_list->UE_template[CC_id][UE_id].oldmcs1[harq_pid], nb_rb); + nb_rb = ue_template->nb_rb[harq_pid]; + TBS = get_TBS_DL(ue_template->oldmcs1[harq_pid], + nb_rb); if (nb_rb <= nb_available_rb) { if (cc[CC_id].tdd_Config != NULL) { - UE_list->UE_template[CC_id][UE_id].DAI++; - update_ul_dci(module_idP, CC_id, rnti, - UE_list->UE_template[CC_id][UE_id].DAI, subframeP); - LOG_D(MAC, - "DAI update: CC_id %d subframeP %d: UE %d, DAI %d\n", - CC_id, subframeP, UE_id, - UE_list->UE_template[CC_id][UE_id].DAI); + ue_template->DAI++; + update_ul_dci(module_idP, + CC_id, + rnti, + ue_template->DAI, + subframeP); + LOG_D(MAC, "DAI update: CC_id %d subframeP %d: UE %d, DAI %d\n", + CC_id, + subframeP, + UE_id, + ue_template->DAI); } - if (nb_rb == ue_sched_ctl->pre_nb_available_rbs[CC_id]) { - for (j = 0; j < N_RBG[CC_id]; ++j) { // for indicating the rballoc for each sub-band - UE_list->UE_template[CC_id][UE_id].rballoc_subband[harq_pid][j] = ue_sched_ctl->rballoc_sub_UE[CC_id][j]; + if (nb_rb == ue_sched_ctrl->pre_nb_available_rbs[CC_id]) { + for (j = 0; j < N_RBG[CC_id]; j++) { // for indicating the rballoc for each sub-band + ue_template->rballoc_subband[harq_pid][j] = ue_sched_ctrl->rballoc_sub_UE[CC_id][j]; } } else { nb_rb_temp = nb_rb; j = 0; while ((nb_rb_temp > 0) && (j < N_RBG[CC_id])) { - if (ue_sched_ctl->rballoc_sub_UE[CC_id][j] == 1) { - if (UE_list->UE_template[CC_id][UE_id].rballoc_subband[harq_pid][j]) - printf("WARN: rballoc_subband not free for retrans?\n"); + if (ue_sched_ctrl->rballoc_sub_UE[CC_id][j] == 1) { + if (ue_template->rballoc_subband[harq_pid][j]) + LOG_W(MAC, "WARN: rballoc_subband not free for retrans?\n"); - UE_list->UE_template[CC_id][UE_id].rballoc_subband[harq_pid][j] = ue_sched_ctl->rballoc_sub_UE[CC_id][j]; + ue_template->rballoc_subband[harq_pid][j] = ue_sched_ctrl->rballoc_sub_UE[CC_id][j]; - if ((j == N_RBG[CC_id] - 1) && ((N_RB_DL[CC_id] == 25) || (N_RB_DL[CC_id] == 50))) { - nb_rb_temp = nb_rb_temp - min_rb_unit[CC_id] + 1; - } else { - nb_rb_temp = nb_rb_temp - min_rb_unit[CC_id]; - } + nb_rb_temp -= min_rb_unit[CC_id]; + if ((j == N_RBG[CC_id] - 1) && (N_RB_DL[CC_id] == 25 || N_RB_DL[CC_id] == 50)) + nb_rb_temp++; } - - j = j + 1; + j++; } } nb_available_rb -= nb_rb; /* eNB->mu_mimo_mode[UE_id].pre_nb_available_rbs = nb_rb; - eNB->mu_mimo_mode[UE_id].dl_pow_off = ue_sched_ctl->dl_pow_off[CC_id]; + eNB->mu_mimo_mode[UE_id].dl_pow_off = ue_sched_ctrl->dl_pow_off[CC_id]; for(j = 0; j < N_RBG[CC_id]; ++j) { - eNB->mu_mimo_mode[UE_id].rballoc_sub[j] = UE_list->UE_template[CC_id][UE_id].rballoc_subband[harq_pid][j]; + eNB->mu_mimo_mode[UE_id].rballoc_sub[j] = ue_template->rballoc_subband[harq_pid][j]; } */ @@ -1842,55 +830,69 @@ schedule_ue_spec(module_id_t module_idP, int slice_idxP, case 2: case 7: default: - LOG_D(MAC, "retransmission DL_REQ: rnti:%x\n", rnti); + LOG_D(MAC, "retransmission DL_REQ: rnti:%x\n", + rnti); dl_config_pdu = &dl_req->dl_config_pdu_list[dl_req->number_pdu]; - memset((void *) dl_config_pdu, 0, sizeof(nfapi_dl_config_request_pdu_t)); + memset((void *) dl_config_pdu, + 0, + sizeof(nfapi_dl_config_request_pdu_t)); dl_config_pdu->pdu_type = NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE; dl_config_pdu->pdu_size = (uint8_t) (2 + sizeof(nfapi_dl_config_dci_dl_pdu)); dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.tl.tag = NFAPI_DL_CONFIG_REQUEST_DCI_DL_PDU_REL8_TAG; dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.dci_format = NFAPI_DL_DCI_FORMAT_1; dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level = - get_aggregation(get_bw_index(module_idP, CC_id), - ue_sched_ctl->dl_cqi[CC_id], + get_aggregation(get_bw_index(module_idP, + CC_id), + ue_sched_ctrl->dl_cqi[CC_id], format1); dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti = rnti; dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti_type = 1; // CRNTI: see Table 4-10 from SCF082 - nFAPI specifications dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.transmission_power = 6000; // equal to RS power dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.harq_process = harq_pid; dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.tpc = 1; // Don't adjust power when retransmitting - dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.new_data_indicator_1 = UE_list->UE_template[CC_id][UE_id].oldNDI[harq_pid]; - dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.mcs_1 = UE_list->UE_template[CC_id][UE_id].oldmcs1[harq_pid]; + dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.new_data_indicator_1 = ue_template->oldNDI[harq_pid]; + dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.mcs_1 = ue_template->oldmcs1[harq_pid]; dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.redundancy_version_1 = round & 3; // TDD if (cc[CC_id].tdd_Config != NULL) { - dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.downlink_assignment_index = - (UE_list->UE_template[CC_id][UE_id].DAI - 1) & 3; - LOG_D(MAC, - "[eNB %d] Retransmission CC_id %d : harq_pid %d, round %d, dai %d, mcs %d\n", - module_idP, CC_id, harq_pid, round, - (UE_list->UE_template[CC_id][UE_id].DAI - 1), - UE_list->UE_template[CC_id][UE_id].oldmcs1[harq_pid]); + dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.downlink_assignment_index = (ue_template->DAI - 1) & 3; + LOG_D(MAC, "[eNB %d] Retransmission CC_id %d : harq_pid %d, round %d, dai %d, mcs %d\n", + module_idP, + CC_id, + harq_pid, + round, + ue_template->DAI - 1, + ue_template->oldmcs1[harq_pid]); } else { - LOG_D(MAC, - "[eNB %d] Retransmission CC_id %d : harq_pid %d, round %d, mcs %d\n", - module_idP, CC_id, harq_pid, round, - UE_list->UE_template[CC_id][UE_id].oldmcs1[harq_pid]); + LOG_D(MAC, "[eNB %d] Retransmission CC_id %d : harq_pid %d, round %d, mcs %d\n", + module_idP, + CC_id, + harq_pid, + round, + ue_template->oldmcs1[harq_pid]); } - if (!CCE_allocation_infeasible(module_idP, CC_id, 1, subframeP, - dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level, rnti)) { + if (!CCE_allocation_infeasible(module_idP, + CC_id, + 1, + subframeP, + dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level, + rnti)) { dl_req->number_dci++; dl_req->number_pdu++; dl_req->tl.tag = NFAPI_DL_CONFIG_REQUEST_BODY_TAG; eNB->DL_req[CC_id].sfn_sf = frameP<<4 | subframeP; eNB->DL_req[CC_id].header.message_id = NFAPI_DL_CONFIG_REQUEST; - fill_nfapi_dlsch_config(eNB, dl_req, TBS, -1, - /* retransmission, no pdu_index */ - rnti, 0, // type 0 allocation from 7.1.6 in 36.213 + fill_nfapi_dlsch_config(eNB, + dl_req, + TBS, + -1, // retransmission, no pdu_index + rnti, + 0, // type 0 allocation from 7.1.6 in 36.213 0, // virtual_resource_block_assignment_flag, unused here 0, // resource_block_coding, to be filled in later - getQm(UE_list->UE_template[CC_id][UE_id].oldmcs1[harq_pid]), + getQm(ue_template->oldmcs1[harq_pid]), round & 3, // redundancy version 1, // transport blocks 0, // transport block to codeword swap flag @@ -1899,56 +901,69 @@ schedule_ue_spec(module_id_t module_idP, int slice_idxP, 1, // number of subbands // uint8_t codebook_index, 4, // UE category capacity - UE_list->UE_template[CC_id][UE_id].physicalConfigDedicated->pdsch_ConfigDedicated->p_a, + ue_template->physicalConfigDedicated->pdsch_ConfigDedicated->p_a, 0, // delta_power_offset for TM5 0, // ngap 0, // nprb cc[CC_id].p_eNB == 1 ? 1 : 2, // transmission mode 0, //number of PRBs treated as one subband, not used here - 0 // number of beamforming vectors, not used here - ); - LOG_D(MAC, - "Filled NFAPI configuration for DCI/DLSCH %d, retransmission round %d\n", - eNB->pdu_index[CC_id], round); - program_dlsch_acknak(module_idP, CC_id, UE_id, frameP, subframeP, + 0); // number of beamforming vectors, not used here + + LOG_D(MAC, "Filled NFAPI configuration for DCI/DLSCH %d, retransmission round %d\n", + eNB->pdu_index[CC_id], + round); + program_dlsch_acknak(module_idP, + CC_id, + UE_id, + frameP, + subframeP, dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.cce_idx); // No TX request for retransmission (check if null request for FAPI) } else { - LOG_W(MAC, - "Frame %d, Subframe %d: Dropping DLSCH allocation for UE %d\%x, infeasible CCE allocation\n", - frameP, subframeP, UE_id, rnti); + LOG_W(MAC, "Frame %d, Subframe %d: Dropping DLSCH allocation for UE %d\%x, infeasible CCE allocation\n", + frameP, + subframeP, + UE_id, + rnti); } } - add_ue_dlsch_info(module_idP, CC_id, UE_id, subframeP, S_DL_SCHEDULED); + add_ue_dlsch_info(module_idP, + CC_id, UE_id, + subframeP, + S_DL_SCHEDULED, + rnti); //eNB_UE_stats->dlsch_trials[round]++; - UE_list->eNB_UE_stats[CC_id][UE_id].num_retransmission += 1; - UE_list->eNB_UE_stats[CC_id][UE_id].rbs_used_retx = nb_rb; - UE_list->eNB_UE_stats[CC_id][UE_id].total_rbs_used_retx += nb_rb; - UE_list->eNB_UE_stats[CC_id][UE_id].dlsch_mcs1 = eNB_UE_stats->dlsch_mcs1; - UE_list->eNB_UE_stats[CC_id][UE_id].dlsch_mcs2 = eNB_UE_stats->dlsch_mcs1; + eNB_UE_stats->num_retransmission += 1; + eNB_UE_stats->rbs_used_retx = nb_rb; + eNB_UE_stats->total_rbs_used_retx += nb_rb; + eNB_UE_stats->dlsch_mcs2 = eNB_UE_stats->dlsch_mcs1; } else { LOG_D(MAC, "[eNB %d] Frame %d CC_id %d : don't schedule UE %d, its retransmission takes more resources than we have\n", - module_idP, frameP, CC_id, UE_id); + module_idP, + frameP, + CC_id, + UE_id); } } else { /* This is a potentially new SDU opportunity */ rlc_status.bytes_in_buffer = 0; // Now check RLC information to compute number of required RBs // get maximum TBS size for RLC request - TBS = get_TBS_DL(eNB_UE_stats->dlsch_mcs1, nb_available_rb); + TBS = get_TBS_DL(eNB_UE_stats->dlsch_mcs1, + nb_available_rb); // add the length for all the control elements (timing adv, drx, etc) : header + payload - if (ue_sched_ctl->ta_timer == 0) { - ta_update = ue_sched_ctl->ta_update; + if (ue_sched_ctrl->ta_timer == 0) { + ta_update = ue_sched_ctrl->ta_update; /* if we send TA then set timer to not send it for a while */ - if (ta_update != 31) - ue_sched_ctl->ta_timer = 20; - + if (ta_update != 31) { + ue_sched_ctrl->ta_timer = 20; + } /* reset ta_update */ - ue_sched_ctl->ta_update = 31; + ue_sched_ctrl->ta_update = 31; } else { ta_update = 31; } @@ -1957,55 +972,83 @@ schedule_ue_spec(module_id_t module_idP, int slice_idxP, // RLC data on DCCH if (TBS - ta_len - header_length_total - sdu_length_total - 3 > 0) { - rlc_status = mac_rlc_status_ind(module_idP, rnti, module_idP, frameP, subframeP, ENB_FLAG_YES, MBMS_FLAG_NO, DCCH, + rlc_status = mac_rlc_status_ind(module_idP, + rnti, + module_idP, + frameP, + subframeP, + ENB_FLAG_YES, + MBMS_FLAG_NO, + DCCH, TBS - ta_len - header_length_total - sdu_length_total - 3 #if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0)) - ,0, 0 + , 0 + , 0 #endif ); sdu_lengths[0] = 0; if (rlc_status.bytes_in_buffer > 0) { LOG_D(MAC, "[eNB %d] SFN/SF %d.%d, DL-DCCH->DLSCH CC_id %d, Requesting %d bytes from RLC (RRC message)\n", - module_idP, frameP, subframeP, CC_id, + module_idP, + frameP, + subframeP, + CC_id, TBS - ta_len - header_length_total - sdu_length_total - 3); - sdu_lengths[0] = mac_rlc_data_req(module_idP, rnti, module_idP, frameP, ENB_FLAG_YES, MBMS_FLAG_NO, DCCH, + sdu_lengths[0] = mac_rlc_data_req(module_idP, + rnti, + module_idP, + frameP, + ENB_FLAG_YES, + MBMS_FLAG_NO, + DCCH, TBS, //not used (char *)&dlsch_buffer[0] #if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0)) - ,0, 0 + , 0 + , 0 #endif - ); + ); pthread_mutex_lock(&rrc_release_freelist); if((rrc_release_info.num_UEs > 0) && (rlc_am_mui.rrc_mui_num > 0)) { uint16_t release_total = 0; - for(uint16_t release_num = 0; release_num < NUMBER_OF_UE_MAX; release_num++) { - if(rrc_release_info.RRC_release_ctrl[release_num].flag > 0) { + for (release_num = 0, release_ctrl = &rrc_release_info.RRC_release_ctrl[0]; + release_num < NUMBER_OF_UE_MAX; + release_num++, release_ctrl++) { + if(release_ctrl->flag > 0) { release_total++; } else { continue; } - if(rrc_release_info.RRC_release_ctrl[release_num].flag == 1) { - if(rrc_release_info.RRC_release_ctrl[release_num].rnti == rnti) { + if(release_ctrl->flag == 1) { + if(release_ctrl->rnti == rnti) { for(uint16_t mui_num = 0; mui_num < rlc_am_mui.rrc_mui_num; mui_num++) { - if(rrc_release_info.RRC_release_ctrl[release_num].rrc_eNB_mui == rlc_am_mui.rrc_mui[mui_num]) { - rrc_release_info.RRC_release_ctrl[release_num].flag = 3; - LOG_D(MAC,"DLSCH Release send:index %d rnti %x mui %d mui_num %d flag 1->3\n",release_num,rnti,rlc_am_mui.rrc_mui[mui_num],mui_num); + if(release_ctrl->rrc_eNB_mui == rlc_am_mui.rrc_mui[mui_num]) { + release_ctrl->flag = 3; + LOG_D(MAC,"DLSCH Release send:index %d rnti %x mui %d mui_num %d flag 1->3\n", + release_num, + rnti, + rlc_am_mui.rrc_mui[mui_num], + mui_num); break; } } } } - if(rrc_release_info.RRC_release_ctrl[release_num].flag == 2) { - if(rrc_release_info.RRC_release_ctrl[release_num].rnti == rnti) { - for(uint16_t mui_num = 0; mui_num < rlc_am_mui.rrc_mui_num; mui_num++) { - if(rrc_release_info.RRC_release_ctrl[release_num].rrc_eNB_mui == rlc_am_mui.rrc_mui[mui_num]) { - rrc_release_info.RRC_release_ctrl[release_num].flag = 4; - LOG_D(MAC,"DLSCH Release send:index %d rnti %x mui %d mui_num %d flag 2->4\n",release_num,rnti,rlc_am_mui.rrc_mui[mui_num],mui_num); + if(release_ctrl->flag == 2) { + if(release_ctrl->rnti == rnti) { + for (uint16_t mui_num = 0; mui_num < rlc_am_mui.rrc_mui_num; mui_num++) { + if(release_ctrl->rrc_eNB_mui == rlc_am_mui.rrc_mui[mui_num]) { + release_ctrl->flag = 4; + LOG_D(MAC, "DLSCH Release send:index %d rnti %x mui %d mui_num %d flag 2->4\n", + release_num, + rnti, + rlc_am_mui.rrc_mui[mui_num], + mui_num); break; } } @@ -2018,44 +1061,50 @@ schedule_ue_spec(module_id_t module_idP, int slice_idxP, } pthread_mutex_unlock(&rrc_release_freelist); - RA_t *ra = &eNB->common_channels[CC_id].ra[0]; - for (uint8_t ra_ii = 0; ra_ii < NB_RA_PROC_MAX; ra_ii++) { - if((ra[ra_ii].rnti == rnti) && (ra[ra_ii].state == MSGCRNTI)) { - for(uint16_t mui_num = 0; mui_num < rlc_am_mui.rrc_mui_num; mui_num++) { - if(ra[ra_ii].crnti_rrc_mui == rlc_am_mui.rrc_mui[mui_num]) { - ra[ra_ii].crnti_harq_pid = harq_pid; - ra[ra_ii].state = MSGCRNTI_ACK; + for (ra_ii = 0, ra = &eNB->common_channels[CC_id].ra[0]; ra_ii < NB_RA_PROC_MAX; ra_ii++, ra++) { + if ((ra->rnti == rnti) && (ra->state == MSGCRNTI)) { + for (uint16_t mui_num = 0; mui_num < rlc_am_mui.rrc_mui_num; mui_num++) { + if (ra->crnti_rrc_mui == rlc_am_mui.rrc_mui[mui_num]) { + ra->crnti_harq_pid = harq_pid; + ra->state = MSGCRNTI_ACK; break; } } } } - T(T_ENB_MAC_UE_DL_SDU, T_INT(module_idP), - T_INT(CC_id), T_INT(rnti), T_INT(frameP), - T_INT(subframeP), T_INT(harq_pid), T_INT(DCCH), + T(T_ENB_MAC_UE_DL_SDU, + T_INT(module_idP), + T_INT(CC_id), + T_INT(rnti), + T_INT(frameP), + T_INT(subframeP), + T_INT(harq_pid), + T_INT(DCCH), T_INT(sdu_lengths[0])); LOG_D(MAC, "[eNB %d][DCCH] CC_id %d Got %d bytes from RLC\n", - module_idP, CC_id, sdu_lengths[0]); + module_idP, + CC_id, + sdu_lengths[0]); sdu_length_total = sdu_lengths[0]; sdu_lcids[0] = DCCH; - UE_list->eNB_UE_stats[CC_id][UE_id].lcid_sdu[0] = DCCH; - UE_list->eNB_UE_stats[CC_id][UE_id].sdu_length_tx[DCCH] = sdu_lengths[0]; - UE_list->eNB_UE_stats[CC_id][UE_id].num_pdu_tx[DCCH] += 1; - UE_list->eNB_UE_stats[CC_id][UE_id].num_bytes_tx[DCCH] += sdu_lengths[0]; + eNB_UE_stats->lcid_sdu[0] = DCCH; + eNB_UE_stats->sdu_length_tx[DCCH] = sdu_lengths[0]; + eNB_UE_stats->num_pdu_tx[DCCH] += 1; + eNB_UE_stats->num_bytes_tx[DCCH] += sdu_lengths[0]; header_length_last = 1 + 1 + (sdu_lengths[0] >= 128); header_length_total += header_length_last; num_sdus = 1; #ifdef DEBUG_eNB_SCHEDULER - LOG_T(MAC, - "[eNB %d][DCCH] CC_id %d Got %d bytes :", - module_idP, CC_id, sdu_lengths[0]); - + LOG_T(MAC, "[eNB %d][DCCH] CC_id %d Got %d bytes :", + module_idP, + CC_id, + sdu_lengths[0]); for (j = 0; j < sdu_lengths[0]; ++j) { - LOG_T(MAC, "%x ", dlsch_buffer[j]); + LOG_T(MAC, "%x ", + dlsch_buffer[j]); } - LOG_T(MAC, "\n"); #endif } @@ -2063,12 +1112,20 @@ schedule_ue_spec(module_id_t module_idP, int slice_idxP, // RLC data on DCCH1 if (TBS - ta_len - header_length_total - sdu_length_total - 3 > 0) { - rlc_status = mac_rlc_status_ind(module_idP, rnti, module_idP, frameP, subframeP, ENB_FLAG_YES, MBMS_FLAG_NO, DCCH + 1, + rlc_status = mac_rlc_status_ind(module_idP, + rnti, + module_idP, + frameP, + subframeP, + ENB_FLAG_YES, + MBMS_FLAG_NO, + DCCH + 1, TBS - ta_len - header_length_total - sdu_length_total - 3 #if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0)) - ,0, 0 + , 0 + , 0 #endif - ); + ); // DCCH SDU sdu_lengths[num_sdus] = 0; @@ -2076,35 +1133,46 @@ schedule_ue_spec(module_id_t module_idP, int slice_idxP, LOG_D(MAC, "[eNB %d], Frame %d, DCCH1->DLSCH, CC_id %d, Requesting %d bytes from RLC (RRC message)\n", module_idP, frameP, CC_id, TBS - ta_len - header_length_total - sdu_length_total - 3); - sdu_lengths[num_sdus] += mac_rlc_data_req(module_idP, rnti, module_idP, frameP, ENB_FLAG_YES, MBMS_FLAG_NO, DCCH + 1, - TBS, //not used - (char *)&dlsch_buffer[sdu_length_total] + sdu_lengths[num_sdus] += mac_rlc_data_req(module_idP, + rnti, + module_idP, + frameP, + ENB_FLAG_YES, + MBMS_FLAG_NO, DCCH + 1, + TBS, //not used + (char *) &dlsch_buffer[sdu_length_total] #if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0)) - ,0, 0 + , 0 + , 0 #endif - ); - T(T_ENB_MAC_UE_DL_SDU, T_INT(module_idP), - T_INT(CC_id), T_INT(rnti), T_INT(frameP), - T_INT(subframeP), T_INT(harq_pid), - T_INT(DCCH + 1), T_INT(sdu_lengths[num_sdus])); + ); + T(T_ENB_MAC_UE_DL_SDU, + T_INT(module_idP), + T_INT(CC_id), + T_INT(rnti), + T_INT(frameP), + T_INT(subframeP), + T_INT(harq_pid), + T_INT(DCCH + 1), + T_INT(sdu_lengths[num_sdus])); sdu_lcids[num_sdus] = DCCH1; sdu_length_total += sdu_lengths[num_sdus]; - UE_list->eNB_UE_stats[CC_id][UE_id].lcid_sdu[num_sdus] = DCCH1; - UE_list->eNB_UE_stats[CC_id][UE_id].sdu_length_tx[DCCH1] = sdu_lengths[num_sdus]; - UE_list->eNB_UE_stats[CC_id][UE_id].num_pdu_tx[DCCH1] += 1; - UE_list->eNB_UE_stats[CC_id][UE_id].num_bytes_tx[DCCH1] += sdu_lengths[num_sdus]; + eNB_UE_stats->lcid_sdu[num_sdus] = DCCH1; + eNB_UE_stats->sdu_length_tx[DCCH1] = sdu_lengths[num_sdus]; + eNB_UE_stats->num_pdu_tx[DCCH1] += 1; + eNB_UE_stats->num_bytes_tx[DCCH1] += sdu_lengths[num_sdus]; header_length_last = 1 + 1 + (sdu_lengths[num_sdus] >= 128); header_length_total += header_length_last; num_sdus++; #ifdef DEBUG_eNB_SCHEDULER - LOG_T(MAC, - "[eNB %d][DCCH1] CC_id %d Got %d bytes :", - module_idP, CC_id, sdu_lengths[num_sdus]); - + LOG_T(MAC, "[eNB %d][DCCH1] CC_id %d Got %d bytes :", + module_idP, + CC_id, + sdu_lengths[num_sdus]); for (j = 0; j < sdu_lengths[num_sdus]; ++j) { - LOG_T(MAC, "%x ", dlsch_buffer[j]); + LOG_T(MAC, "%x ", + dlsch_buffer[j]); } - LOG_T(MAC, "\n"); #endif } @@ -2131,9 +1199,10 @@ schedule_ue_spec(module_id_t module_idP, int slice_idxP, lcid, TBS - ta_len - header_length_total - sdu_length_total - 3 #if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0)) - , 0, 0 + , 0 + , 0 #endif - ); + ); if (rlc_status.bytes_in_buffer > 0) { LOG_D(MAC, "[eNB %d][USER-PLANE DEFAULT DRB] Frame %d : DTCH->DLSCH, Requesting %d bytes from RLC (lcid %d total hdr len %d)\n", @@ -2143,18 +1212,19 @@ schedule_ue_spec(module_id_t module_idP, int slice_idxP, lcid, header_length_total); sdu_lengths[num_sdus] = mac_rlc_data_req(module_idP, - rnti, - module_idP, - frameP, - ENB_FLAG_YES, - MBMS_FLAG_NO, - lcid, - TBS, //not used - (char *)&dlsch_buffer[sdu_length_total] + rnti, + module_idP, + frameP, + ENB_FLAG_YES, + MBMS_FLAG_NO, + lcid, + TBS, //not used + (char *) &dlsch_buffer[sdu_length_total] #if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0)) - , 0, 0 + , 0 + , 0 #endif - ); + ); T(T_ENB_MAC_UE_DL_SDU, T_INT(module_idP), T_INT(CC_id), @@ -2170,16 +1240,17 @@ schedule_ue_spec(module_id_t module_idP, int slice_idxP, lcid); sdu_lcids[num_sdus] = lcid; sdu_length_total += sdu_lengths[num_sdus]; - UE_list->eNB_UE_stats[CC_id][UE_id].num_pdu_tx[lcid]++; - UE_list->eNB_UE_stats[CC_id][UE_id].lcid_sdu[num_sdus] = lcid; - UE_list->eNB_UE_stats[CC_id][UE_id].sdu_length_tx[lcid] = sdu_lengths[num_sdus]; - UE_list->eNB_UE_stats[CC_id][UE_id].num_bytes_tx[lcid] += sdu_lengths[num_sdus]; + eNB_UE_stats->num_pdu_tx[lcid]++; + eNB_UE_stats->lcid_sdu[num_sdus] = lcid; + eNB_UE_stats->sdu_length_tx[lcid] = sdu_lengths[num_sdus]; + eNB_UE_stats->num_bytes_tx[lcid] += sdu_lengths[num_sdus]; header_length_last = 1 + 1 + (sdu_lengths[num_sdus] >= 128); header_length_total += header_length_last; num_sdus++; - UE_list->UE_sched_ctrl[UE_id].uplane_inactivity_timer = 0; + ue_sched_ctrl->uplane_inactivity_timer = 0; // reset RRC inactivity timer after uplane activity ue_contextP = rrc_eNB_get_ue_context(RC.rrc[module_idP], rnti); + if (ue_contextP != NULL) { ue_contextP->ue_context.ue_rrc_inactivity_timer = 1; } else { @@ -2220,25 +1291,27 @@ schedule_ue_spec(module_id_t module_idP, int slice_idxP, if (nb_rb > nb_available_rb) { // if we've gone beyond the maximum number of RBs // (can happen if N_RB_DL is odd) - TBS = get_TBS_DL(eNB_UE_stats->dlsch_mcs1, nb_available_rb); + TBS = get_TBS_DL(eNB_UE_stats->dlsch_mcs1, + nb_available_rb); nb_rb = nb_available_rb; break; } - TBS = get_TBS_DL(eNB_UE_stats->dlsch_mcs1, nb_rb); + TBS = get_TBS_DL(eNB_UE_stats->dlsch_mcs1, + nb_rb); } - if (nb_rb == ue_sched_ctl->pre_nb_available_rbs[CC_id]) { + if (nb_rb == ue_sched_ctrl->pre_nb_available_rbs[CC_id]) { for (j = 0; j < N_RBG[CC_id]; ++j) { // for indicating the rballoc for each sub-band - UE_list->UE_template[CC_id][UE_id].rballoc_subband[harq_pid][j] = ue_sched_ctl->rballoc_sub_UE[CC_id][j]; + ue_template->rballoc_subband[harq_pid][j] = ue_sched_ctrl->rballoc_sub_UE[CC_id][j]; } } else { nb_rb_temp = nb_rb; j = 0; while ((nb_rb_temp > 0) && (j < N_RBG[CC_id])) { - if (ue_sched_ctl->rballoc_sub_UE[CC_id][j] == 1) { - UE_list->UE_template[CC_id][UE_id].rballoc_subband[harq_pid][j] = ue_sched_ctl->rballoc_sub_UE[CC_id][j]; + if (ue_sched_ctrl->rballoc_sub_UE[CC_id][j] == 1) { + ue_template->rballoc_subband[harq_pid][j] = ue_sched_ctrl->rballoc_sub_UE[CC_id][j]; if ((j == N_RBG[CC_id] - 1) && ((N_RB_DL[CC_id] == 25) || (N_RB_DL[CC_id] == 50))) { nb_rb_temp = nb_rb_temp - min_rb_unit[CC_id] + 1; @@ -2247,33 +1320,34 @@ schedule_ue_spec(module_id_t module_idP, int slice_idxP, } } - j = j + 1; + j++; } } // decrease mcs until TBS falls below required length while ((TBS > sdu_length_total + header_length_total + ta_len) && (mcs > 0)) { mcs--; - TBS = get_TBS_DL(mcs, nb_rb); + TBS = get_TBS_DL(mcs, + nb_rb); } // if we have decreased too much or we don't have enough RBs, increase MCS - while ((TBS < sdu_length_total + header_length_total + ta_len) - && (((ue_sched_ctl->dl_pow_off[CC_id] > 0) - && (mcs < 28)) - || ((ue_sched_ctl->dl_pow_off[CC_id] == 0) - && (mcs <= 15)))) { + while (TBS < sdu_length_total + header_length_total + ta_len && + ((ue_sched_ctrl->dl_pow_off[CC_id] > 0 && mcs < 28) || (ue_sched_ctrl->dl_pow_off[CC_id] == 0 && mcs <= 15))) { mcs++; - TBS = get_TBS_DL(mcs, nb_rb); + TBS = get_TBS_DL(mcs, + nb_rb); } - LOG_D(MAC, - "dlsch_mcs before and after the rate matching = (%d, %d)\n", - eNB_UE_stats->dlsch_mcs1, mcs); + LOG_D(MAC, "dlsch_mcs before and after the rate matching = (%d, %d)\n", + eNB_UE_stats->dlsch_mcs1, + mcs); #ifdef DEBUG_eNB_SCHEDULER - LOG_D(MAC, - "[eNB %d] CC_id %d Generated DLSCH header (mcs %d, TBS %d, nb_rb %d)\n", - module_idP, CC_id, mcs, TBS, nb_rb); + LOG_D(MAC, "[eNB %d] CC_id %d Generated DLSCH header (mcs %d, TBS %d, nb_rb %d)\n", + module_idP, + CC_id, + mcs, TBS, + nb_rb); // msg("[MAC][eNB ] Reminder of DLSCH with random data %d %d %d %d \n", // TBS, sdu_length_total, offset, TBS-sdu_length_total-offset); #endif @@ -2289,97 +1363,131 @@ schedule_ue_spec(module_id_t module_idP, int slice_idxP, offset = generate_dlsch_header((unsigned char *) UE_list->DLSCH_pdu[CC_id][0][UE_id].payload[0], num_sdus, //num_sdus sdu_lengths, // - sdu_lcids, 255, // no drx + sdu_lcids, + 255, // no drx ta_update, // timing advance NULL, // contention res id - padding, post_padding); + padding, + post_padding); //#ifdef DEBUG_eNB_SCHEDULER if (ta_update != 31) { - LOG_D(MAC, + LOG_D(MAC, "[eNB %d][DLSCH] Frame %d Generate header for UE_id %d on CC_id %d: sdu_length_total %d, num_sdus %d, sdu_lengths[0] %d, sdu_lcids[0] %d => payload offset %d,timing advance value : %d, padding %d,post_padding %d,(mcs %d, TBS %d, nb_rb %d),header_length %d\n", - module_idP, frameP, UE_id, CC_id, - sdu_length_total, num_sdus, sdu_lengths[0], - sdu_lcids[0], offset, ta_update, padding, - post_padding, mcs, TBS, nb_rb, + module_idP, + frameP, + UE_id, + CC_id, + sdu_length_total, + num_sdus, + sdu_lengths[0], + sdu_lcids[0], + offset, + ta_update, + padding, + post_padding, + mcs, + TBS, + nb_rb, header_length_total); } //#endif #ifdef DEBUG_eNB_SCHEDULER LOG_T(MAC, "[eNB %d] First 16 bytes of DLSCH : \n"); - - for (i = 0; i < 16; ++i) { - LOG_T(MAC, "%x.", dlsch_buffer[i]); + for (i = 0; i < 16; i++) { + LOG_T(MAC, "%x.", + dlsch_buffer[i]); } - LOG_T(MAC, "\n"); #endif // cycle through SDUs and place in dlsch_buffer - memcpy(&UE_list->DLSCH_pdu[CC_id][0][UE_id].payload[0][offset], dlsch_buffer, sdu_length_total); + dlsch_pdu = &UE_list->DLSCH_pdu[CC_id][0][UE_id]; + memcpy(&dlsch_pdu->payload[0][offset], + dlsch_buffer, + sdu_length_total); // memcpy(RC.mac[0].DLSCH_pdu[0][0].payload[0][offset],dcch_buffer,sdu_lengths[0]); // fill remainder of DLSCH with 0 for (j = 0; j < (TBS - sdu_length_total - offset); j++) { - UE_list->DLSCH_pdu[CC_id][0][UE_id].payload[0][offset + sdu_length_total + j] = 0; + dlsch_pdu->payload[0][offset + sdu_length_total + j] = 0; } if (opt_enabled == 1) { trace_pdu(DIRECTION_DOWNLINK, - (uint8_t *) UE_list->DLSCH_pdu[CC_id][0][UE_id].payload[0], - TBS, module_idP, WS_C_RNTI, - UE_RNTI(module_idP, UE_id), eNB->frame, - eNB->subframe, 0, 0); - LOG_D(OPT, - "[eNB %d][DLSCH] CC_id %d Frame %d rnti %x with size %d\n", - module_idP, CC_id, frameP, - UE_RNTI(module_idP, UE_id), TBS); + (uint8_t *) dlsch_pdu->payload[0], + TBS, + module_idP, + WS_C_RNTI, + UE_RNTI(module_idP, + UE_id), + eNB->frame, + eNB->subframe, + 0, + 0); + LOG_D(OPT, "[eNB %d][DLSCH] CC_id %d Frame %d rnti %x with size %d\n", + module_idP, + CC_id, + frameP, + UE_RNTI(module_idP, + UE_id), + TBS); } - T(T_ENB_MAC_UE_DL_PDU_WITH_DATA, T_INT(module_idP), - T_INT(CC_id), T_INT(rnti), T_INT(frameP), - T_INT(subframeP), T_INT(harq_pid), - T_BUFFER(UE_list->DLSCH_pdu[CC_id][0][UE_id].payload[0], TBS)); - UE_list->UE_template[CC_id][UE_id].nb_rb[harq_pid] = nb_rb; - add_ue_dlsch_info(module_idP, CC_id, UE_id, subframeP, S_DL_SCHEDULED); + T(T_ENB_MAC_UE_DL_PDU_WITH_DATA, + T_INT(module_idP), + T_INT(CC_id), + T_INT(rnti), + T_INT(frameP), + T_INT(subframeP), + T_INT(harq_pid), + T_BUFFER(dlsch_pdu->payload[0], + TBS)); + ue_template->nb_rb[harq_pid] = nb_rb; + add_ue_dlsch_info(module_idP, + CC_id, + UE_id, + subframeP, + S_DL_SCHEDULED, + rnti); // store stats eNB->eNB_stats[CC_id].dlsch_bytes_tx += sdu_length_total; eNB->eNB_stats[CC_id].dlsch_pdus_tx += 1; - UE_list->eNB_UE_stats[CC_id][UE_id].rbs_used = nb_rb; - UE_list->eNB_UE_stats[CC_id][UE_id].num_mac_sdu_tx = num_sdus; - UE_list->eNB_UE_stats[CC_id][UE_id].total_rbs_used += nb_rb; - UE_list->eNB_UE_stats[CC_id][UE_id].dlsch_mcs1 = eNB_UE_stats->dlsch_mcs1; - UE_list->eNB_UE_stats[CC_id][UE_id].dlsch_mcs2 = mcs; - UE_list->eNB_UE_stats[CC_id][UE_id].TBS = TBS; - UE_list->eNB_UE_stats[CC_id][UE_id].overhead_bytes = TBS - sdu_length_total; - UE_list->eNB_UE_stats[CC_id][UE_id].total_sdu_bytes += sdu_length_total; - UE_list->eNB_UE_stats[CC_id][UE_id].total_pdu_bytes += TBS; - UE_list->eNB_UE_stats[CC_id][UE_id].total_num_pdus += 1; + eNB_UE_stats->rbs_used = nb_rb; + eNB_UE_stats->num_mac_sdu_tx = num_sdus; + eNB_UE_stats->total_rbs_used += nb_rb; + eNB_UE_stats->dlsch_mcs2 = mcs; + eNB_UE_stats->TBS = TBS; + eNB_UE_stats->overhead_bytes = TBS - sdu_length_total; + eNB_UE_stats->total_sdu_bytes += sdu_length_total; + eNB_UE_stats->total_pdu_bytes += TBS; + eNB_UE_stats->total_num_pdus += 1; if (cc[CC_id].tdd_Config != NULL) { // TDD - UE_list->UE_template[CC_id][UE_id].DAI++; - update_ul_dci(module_idP, CC_id, rnti, - UE_list->UE_template[CC_id][UE_id].DAI, + ue_template->DAI++; + update_ul_dci(module_idP, + CC_id, + rnti, + ue_template->DAI, subframeP); } // do PUCCH power control // this is the normalized RX power - eNB_UE_stats = &UE_list->eNB_UE_stats[CC_id][UE_id]; - /* unit is not dBm, it's special from nfapi */ + // unit is not dBm, it's special from nfapi // converting to dBm: ToDo: Noise power hard coded to 30 - normalized_rx_power = (5*ue_sched_ctl->pucch1_snr[CC_id]-640)/10+30; - target_rx_power= eNB->puCch10xSnr/10 + 30; + normalized_rx_power = (((5 * ue_sched_ctrl->pucch1_snr[CC_id]) - 640) / 10) + 30; + target_rx_power= (eNB->puCch10xSnr / 10) + 30; // this assumes accumulated tpc // make sure that we are only sending a tpc update once a frame, otherwise the control loop will freak out - int32_t framex10psubframe = UE_list->UE_template[CC_id][UE_id].pucch_tpc_tx_frame * 10 + UE_list->UE_template[CC_id][UE_id].pucch_tpc_tx_subframe; + int32_t framex10psubframe = ue_template->pucch_tpc_tx_frame * 10 + ue_template->pucch_tpc_tx_subframe; - if (((framex10psubframe + 10) <= (frameP * 10 + subframeP)) || //normal case - ((framex10psubframe > (frameP * 10 + subframeP)) && (((10240 - framex10psubframe + frameP * 10 + subframeP) >= 10)))) //frame wrap-around - if (ue_sched_ctl->pucch1_cqi_update[CC_id] == 1) { - ue_sched_ctl->pucch1_cqi_update[CC_id] = 0; - UE_list->UE_template[CC_id][UE_id].pucch_tpc_tx_frame = frameP; - UE_list->UE_template[CC_id][UE_id].pucch_tpc_tx_subframe = subframeP; + if (framex10psubframe + 10 <= (frameP * 10) + subframeP || //normal case + (framex10psubframe > (frameP * 10) + subframeP && 10240 - framex10psubframe + (frameP * 10) + subframeP >= 10)) //frame wrap-around + if (ue_sched_ctrl->pucch1_cqi_update[CC_id] == 1) { + ue_sched_ctrl->pucch1_cqi_update[CC_id] = 0; + ue_template->pucch_tpc_tx_frame = frameP; + ue_template->pucch_tpc_tx_subframe = subframeP; if (normalized_rx_power > (target_rx_power + 4)) { tpc = 0; //-1 @@ -2389,10 +1497,14 @@ schedule_ue_spec(module_id_t module_idP, int slice_idxP, tpc = 1; //0 } - LOG_D(MAC, - "[eNB %d] DLSCH scheduler: frame %d, subframe %d, harq_pid %d, tpc %d, normalized/target rx power %d/%d\n", - module_idP, frameP, subframeP, harq_pid, tpc, - normalized_rx_power, target_rx_power); + LOG_D(MAC, "[eNB %d] DLSCH scheduler: frame %d, subframe %d, harq_pid %d, tpc %d, normalized/target rx power %d/%d\n", + module_idP, + frameP, + subframeP, + harq_pid, + tpc, + normalized_rx_power, + target_rx_power); } // Po_PUCCH has been updated else { tpc = 1; //0 @@ -2402,20 +1514,24 @@ schedule_ue_spec(module_id_t module_idP, int slice_idxP, } dl_config_pdu = &dl_req->dl_config_pdu_list[dl_req->number_pdu]; - memset((void *) dl_config_pdu, 0, sizeof(nfapi_dl_config_request_pdu_t)); + memset((void *) dl_config_pdu, + 0, + sizeof(nfapi_dl_config_request_pdu_t)); dl_config_pdu->pdu_type = NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE; dl_config_pdu->pdu_size = (uint8_t) (2 + sizeof(nfapi_dl_config_dci_dl_pdu)); dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.dci_format = NFAPI_DL_DCI_FORMAT_1; dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level = - get_aggregation(get_bw_index(module_idP, CC_id), ue_sched_ctl->dl_cqi[CC_id], format1); + get_aggregation(get_bw_index(module_idP, + CC_id), + ue_sched_ctrl->dl_cqi[CC_id], + format1); dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.tl.tag = NFAPI_DL_CONFIG_REQUEST_DCI_DL_PDU_REL8_TAG; dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti = rnti; dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti_type = 1; // CRNTI : see Table 4-10 from SCF082 - nFAPI specifications dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.transmission_power = 6000; // equal to RS power dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.harq_process = harq_pid; dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.tpc = tpc; // dont adjust power when retransmitting - dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.new_data_indicator_1 = - 1 - UE_list->UE_template[CC_id][UE_id].oldNDI[harq_pid]; + dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.new_data_indicator_1 = 1 - ue_template->oldNDI[harq_pid]; dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.mcs_1 = mcs; dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.redundancy_version_1 = 0; //deactivate second codeword @@ -2423,47 +1539,61 @@ schedule_ue_spec(module_id_t module_idP, int slice_idxP, dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.redundancy_version_2 = 1; if (cc[CC_id].tdd_Config != NULL) { //TDD - dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.downlink_assignment_index = - (UE_list->UE_template[CC_id][UE_id].DAI - 1) & 3; - LOG_D(MAC, - "[eNB %d] Initial transmission CC_id %d : harq_pid %d, dai %d, mcs %d\n", - module_idP, CC_id, harq_pid, - (UE_list->UE_template[CC_id][UE_id].DAI - 1), + dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.downlink_assignment_index = (ue_template->DAI - 1) & 3; + LOG_D(MAC, "[eNB %d] Initial transmission CC_id %d : harq_pid %d, dai %d, mcs %d\n", + module_idP, + CC_id, + harq_pid, + (ue_template->DAI - 1), mcs); } else { - LOG_D(MAC, - "[eNB %d] Initial transmission CC_id %d : harq_pid %d, mcs %d\n", - module_idP, CC_id, harq_pid, mcs); + LOG_D(MAC, "[eNB %d] Initial transmission CC_id %d : harq_pid %d, mcs %d\n", + module_idP, + CC_id, + harq_pid, + mcs); } LOG_D(MAC, "Checking feasibility pdu %d (new sdu)\n", dl_req->number_pdu); - if (!CCE_allocation_infeasible(module_idP, CC_id, 1, subframeP, - dl_config_pdu->dci_dl_pdu. - dci_dl_pdu_rel8.aggregation_level, rnti)) { - ue_sched_ctl->round[CC_id][harq_pid] = 0; + if (!CCE_allocation_infeasible(module_idP, + CC_id, + 1, + subframeP, + dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level, + rnti)) { + ue_sched_ctrl->round[CC_id][harq_pid] = 0; dl_req->number_dci++; dl_req->number_pdu++; dl_req->tl.tag = NFAPI_DL_CONFIG_REQUEST_BODY_TAG; eNB->DL_req[CC_id].sfn_sf = frameP << 4 | subframeP; eNB->DL_req[CC_id].header.message_id = NFAPI_DL_CONFIG_REQUEST; // Toggle NDI for next time - LOG_D(MAC, - "CC_id %d Frame %d, subframeP %d: Toggling Format1 NDI for UE %d (rnti %x/%d) oldNDI %d\n", - CC_id, frameP, subframeP, UE_id, rnti, harq_pid, - UE_list->UE_template[CC_id][UE_id].oldNDI[harq_pid]); - UE_list->UE_template[CC_id][UE_id].oldNDI[harq_pid] = 1 - UE_list->UE_template[CC_id][UE_id].oldNDI[harq_pid]; - UE_list->UE_template[CC_id][UE_id].oldmcs1[harq_pid] = mcs; - UE_list->UE_template[CC_id][UE_id].oldmcs2[harq_pid] = 0; - AssertFatal(UE_list->UE_template[CC_id][UE_id].physicalConfigDedicated != NULL, - "physicalConfigDedicated is NULL\n"); - AssertFatal(UE_list->UE_template[CC_id][UE_id].physicalConfigDedicated->pdsch_ConfigDedicated != NULL, + LOG_D(MAC, "CC_id %d Frame %d, subframeP %d: Toggling Format1 NDI for UE %d (rnti %x/%d) oldNDI %d\n", + CC_id, + frameP, + subframeP, + UE_id, + rnti, + harq_pid, + ue_template->oldNDI[harq_pid]); + ue_template->oldNDI[harq_pid] = 1 - ue_template->oldNDI[harq_pid]; + ue_template->oldmcs1[harq_pid] = mcs; + ue_template->oldmcs2[harq_pid] = 0; + AssertFatal(ue_template->physicalConfigDedicated != NULL, "physicalConfigDedicated is NULL\n"); + AssertFatal(ue_template->physicalConfigDedicated->pdsch_ConfigDedicated != NULL, "physicalConfigDedicated->pdsch_ConfigDedicated is NULL\n"); - fill_nfapi_dlsch_config(eNB, dl_req, TBS, eNB->pdu_index[CC_id], rnti, 0, // type 0 allocation from 7.1.6 in 36.213 + fill_nfapi_dlsch_config(eNB, + dl_req, + TBS, + eNB->pdu_index[CC_id], + rnti, + 0, // type 0 allocation from 7.1.6 in 36.213 0, // virtual_resource_block_assignment_flag, unused here 0, // resource_block_coding, to be filled in later - getQm(mcs), 0, // redundancy version + getQm(mcs), + 0, // redundancy version 1, // transport blocks 0, // transport block to codeword swap flag cc[CC_id].p_eNB == 1 ? 0 : 1, // transmission_scheme @@ -2471,57 +1601,74 @@ schedule_ue_spec(module_id_t module_idP, int slice_idxP, 1, // number of subbands // uint8_t codebook_index, 4, // UE category capacity - UE_list->UE_template[CC_id][UE_id].physicalConfigDedicated->pdsch_ConfigDedicated->p_a, 0, // delta_power_offset for TM5 + ue_template->physicalConfigDedicated->pdsch_ConfigDedicated->p_a, + 0, // delta_power_offset for TM5 0, // ngap 0, // nprb cc[CC_id].p_eNB == 1 ? 1 : 2, // transmission mode 0, //number of PRBs treated as one subband, not used here - 0 // number of beamforming vectors, not used here - ); + 0); // number of beamforming vectors, not used here + eNB->TX_req[CC_id].sfn_sf = fill_nfapi_tx_req(&eNB->TX_req[CC_id].tx_request_body, - (frameP * 10) + subframeP, - TBS, eNB->pdu_index[CC_id], - eNB->UE_list.DLSCH_pdu[CC_id][0][UE_id].payload[0]); - LOG_D(MAC, - "Filled NFAPI configuration for DCI/DLSCH/TXREQ %d, new SDU\n", + (frameP * 10) + subframeP, + TBS, + eNB->pdu_index[CC_id], + dlsch_pdu->payload[0]); + LOG_D(MAC, "Filled NFAPI configuration for DCI/DLSCH/TXREQ %d, new SDU\n", eNB->pdu_index[CC_id]); eNB->pdu_index[CC_id]++; - program_dlsch_acknak(module_idP, CC_id, UE_id, - frameP, subframeP, + program_dlsch_acknak(module_idP, + CC_id, + UE_id, + frameP, + subframeP, dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.cce_idx); } else { - LOG_W(MAC, - "Frame %d, Subframe %d: Dropping DLSCH allocation for UE %d/%x, infeasible CCE allocations\n", - frameP, subframeP, UE_id, rnti); + LOG_W(MAC, "Frame %d, Subframe %d: Dropping DLSCH allocation for UE %d/%x, infeasible CCE allocations\n", + frameP, + subframeP, + UE_id, + rnti); } } else { // There is no data from RLC or MAC header, so don't schedule } } if (cc[CC_id].tdd_Config != NULL) { // TDD - set_ul_DAI(module_idP, UE_id, CC_id, frameP, subframeP); + set_ul_DAI(module_idP, + UE_id, + CC_id, + frameP, + subframeP); } } // UE_id loop } // CC_id loop - fill_DLSCH_dci(module_idP, frameP, subframeP, mbsfn_flag); + fill_DLSCH_dci(module_idP, + frameP, + subframeP, + mbsfn_flag); stop_meas(&eNB->schedule_dlsch); - VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_SCHEDULE_DLSCH, VCD_FUNCTION_OUT); + VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_SCHEDULE_DLSCH, + VCD_FUNCTION_OUT); } //------------------------------------------------------------------------------ -void dlsch_scheduler_interslice_multiplexing(module_id_t Mod_id, - int frameP, - sub_frame_t subframeP, - uint8_t rballoc_sub[NFAPI_CC_MAX][N_RBG_MAX]) +void +dlsch_scheduler_interslice_multiplexing(module_id_t Mod_id, + int frameP, + sub_frame_t subframeP, + uint8_t rballoc_sub[NFAPI_CC_MAX][N_RBG_MAX]) //------------------------------------------------------------------------------ { // FIXME: I'm prototyping the algorithm, so there may be arrays and variables that carry redundant information here and in pre_processor_results struct. int UE_id, CC_id, rbg, i; int N_RB_DL, min_rb_unit, tm; int owned, used; - UE_list_t *UE_list = &RC.mac[Mod_id]->UE_list; - slice_info_t *sli = &RC.mac[Mod_id]->slice_info; + eNB_MAC_INST *eNB = RC.mac[Mod_id]; + int nb_mac_CC = RC.nb_mac_CC[Mod_id]; + UE_list_t *UE_list = &eNB->UE_list; + slice_info_t *sli = &eNB->slice_info; UE_sched_ctrl *ue_sched_ctl; COMMON_channels_t *cc; int N_RBG[NFAPI_CC_MAX]; @@ -2533,17 +1680,17 @@ void dlsch_scheduler_interslice_multiplexing(module_id_t Mod_id, uint16_t (*nb_rbs_remaining)[MAX_MOBILES_PER_ENB]; uint16_t (*nb_rbs_required)[MAX_MOBILES_PER_ENB]; uint8_t (*MIMO_mode_indicator)[N_RBG_MAX]; - + // Initialize the free RBGs map // free_rbgs_map[CC_id][rbg] = -1 if RBG is allocated, // otherwise it contains the id of the slice it belongs to. // (Information about slicing must be retained to deal with isolation). // FIXME: This method does not consider RBGs that are free and belong to no slices - for (CC_id = 0; CC_id < RC.nb_mac_CC[Mod_id]; ++CC_id) { - cc = &RC.mac[Mod_id]->common_channels[CC_id]; + for (CC_id = 0; CC_id < nb_mac_CC; CC_id++) { + cc = &eNB->common_channels[CC_id]; N_RBG[CC_id] = to_rbg(cc->mib->message.dl_Bandwidth); - for (rbg = 0; rbg < N_RBG[CC_id]; ++rbg) { + for (rbg = 0; rbg < N_RBG[CC_id]; rbg++) { for (i = 0; i < sli->n_dl; ++i) { owned = sli->pre_processor_results[i].slice_allocation_mask[CC_id][rbg]; @@ -2558,11 +1705,11 @@ void dlsch_scheduler_interslice_multiplexing(module_id_t Mod_id, // Find out which slices need other resources. // FIXME: I don't think is really needed since we check nb_rbs_remaining later - for (CC_id = 0; CC_id < RC.nb_mac_CC[Mod_id]; ++CC_id) { - for (i = 0; i < sli->n_dl; ++i) { + for (CC_id = 0; CC_id < nb_mac_CC; CC_id++) { + for (i = 0; i < sli->n_dl; i++) { has_traffic[CC_id][i] = 0; - for (UE_id = 0; UE_id < MAX_MOBILES_PER_ENB; ++UE_id) { + for (UE_id = 0; UE_id < MAX_MOBILES_PER_ENB; UE_id++) { if (sli->pre_processor_results[i].nb_rbs_remaining[CC_id][UE_id] > 0) { has_traffic[CC_id][i] = 1; break; @@ -2571,13 +1718,15 @@ void dlsch_scheduler_interslice_multiplexing(module_id_t Mod_id, } } - slice_priority_sort(Mod_id, slice_sorted_list); + slice_priority_sort(Mod_id, + slice_sorted_list); // MULTIPLEXING // This part is an adaptation of dlsch_scheduler_pre_processor_allocate() code - for (CC_id = 0; CC_id < RC.nb_mac_CC[Mod_id]; ++CC_id) { - N_RB_DL = to_prb(RC.mac[Mod_id]->common_channels[CC_id].mib->message.dl_Bandwidth); - min_rb_unit = get_min_rb_unit(Mod_id, CC_id); + for (CC_id = 0; CC_id < nb_mac_CC; ++CC_id) { + N_RB_DL = to_prb(eNB->common_channels[CC_id].mib->message.dl_Bandwidth); + min_rb_unit = get_min_rb_unit(Mod_id, + CC_id); for (i = 0; i < sli->n_dl; ++i) { slice_idx = slice_sorted_list[i]; @@ -2605,7 +1754,10 @@ void dlsch_scheduler_interslice_multiplexing(module_id_t Mod_id, // Sort UE again // (UE list gets sorted every time pre_processor is called so it is probably dirty at this point) // FIXME: There is only one UE_list for all slices, so it must be sorted again each time we use it - sort_UEs(Mod_id, slice_idx, frameP, subframeP); + sort_UEs(Mod_id, + slice_idx, + frameP, + subframeP); nb_rbs_remaining = sli->pre_processor_results[slice_idx].nb_rbs_remaining; nb_rbs_required = sli->pre_processor_results[slice_idx].nb_rbs_required; MIMO_mode_indicator = sli->pre_processor_results[slice_idx].MIMO_mode_indicator; @@ -2613,7 +1765,9 @@ void dlsch_scheduler_interslice_multiplexing(module_id_t Mod_id, // Allocation for (UE_id = UE_list->head; UE_id >= 0; UE_id = UE_list->next[UE_id]) { ue_sched_ctl = &UE_list->UE_sched_ctrl[UE_id]; - tm = get_tmode(Mod_id, CC_id, UE_id); + tm = get_tmode(Mod_id, + CC_id, + UE_id); for (rbg = 0; rbg < N_RBG[CC_id]; ++rbg) { // FIXME: I think that some of these checks are redundant @@ -2641,8 +1795,8 @@ void dlsch_scheduler_interslice_multiplexing(module_id_t Mod_id, ue_sched_ctl->dl_pow_off[CC_id] = 1; } - nb_rbs_remaining[CC_id][UE_id] = nb_rbs_remaining[CC_id][UE_id] - min_rb_unit + 1; - ue_sched_ctl->pre_nb_available_rbs[CC_id] = ue_sched_ctl->pre_nb_available_rbs[CC_id] + min_rb_unit - 1; + nb_rbs_remaining[CC_id][UE_id] -= (min_rb_unit - 1); + ue_sched_ctl->pre_nb_available_rbs[CC_id] += (min_rb_unit - 1); } } else { // Allocating a standard-sized RBG @@ -2656,36 +1810,42 @@ void dlsch_scheduler_interslice_multiplexing(module_id_t Mod_id, ue_sched_ctl->dl_pow_off[CC_id] = 1; } - nb_rbs_remaining[CC_id][UE_id] = nb_rbs_remaining[CC_id][UE_id] - min_rb_unit; - ue_sched_ctl->pre_nb_available_rbs[CC_id] = ue_sched_ctl->pre_nb_available_rbs[CC_id] + min_rb_unit; + nb_rbs_remaining[CC_id][UE_id] -= min_rb_unit; + ue_sched_ctl->pre_nb_available_rbs[CC_id] += min_rb_unit; } } } } } } + return; } //------------------------------------------------------------------------------ void dlsch_scheduler_qos_multiplexing(module_id_t Mod_id, int frameP, sub_frame_t subframeP) //------------------------------------------------------------------------------ { - int UE_id, CC_id, i; - UE_list_t *UE_list = &RC.mac[Mod_id]->UE_list; + // int UE_id; + int CC_id, i; + // UE_list_t *UE_list = &RC.mac[Mod_id]->UE_list; slice_info_t *sli = &RC.mac[Mod_id]->slice_info; //UE_sched_ctrl *ue_sched_ctl; - for (CC_id = 0; CC_id < RC.nb_mac_CC[Mod_id]; ++CC_id) { - for (i = 0; i < sli->n_dl; ++i) { + for (CC_id = 0; CC_id < RC.nb_mac_CC[Mod_id]; CC_id++) { + for (i = 0; i < sli->n_dl; i++) { // Sort UE again // FIXME: There is only one UE_list for all slices, so it must be sorted again each time we use it - sort_UEs(Mod_id, (uint8_t)i, frameP, subframeP); - + sort_UEs(Mod_id, + (uint8_t)i, + frameP, + subframeP); + /* for (UE_id = UE_list->head; UE_id >= 0; UE_id = UE_list->next[UE_id]) { //ue_sched_ctl = &UE_list->UE_sched_ctrl[UE_id]; // TODO: Do something here // ue_sched_ctl->pre_nb_available_rbs[CC_id]; } + */ } } } @@ -2693,151 +1853,178 @@ void dlsch_scheduler_qos_multiplexing(module_id_t Mod_id, int frameP, sub_frame_ #if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0)) //------------------------------------------------------------------------------ +/* + * Default DLSCH scheduler for LTE-M + */ void -schedule_ue_spec_br( - module_id_t module_idP, - frame_t frameP, - sub_frame_t subframeP - ) { - int CC_id = 0,UE_id; - eNB_MAC_INST *mac = RC.mac[module_idP]; - COMMON_channels_t *cc = mac->common_channels; - UE_list_t *UE_list = &mac->UE_list; - UE_TEMPLATE *UE_template; - UE_sched_ctrl *ue_sched_ctl; - int32_t tpc=1; +schedule_ue_spec_br(module_id_t module_idP, + frame_t frameP, + sub_frame_t subframeP) +//------------------------------------------------------------------------------ +{ + int CC_id = 0; + int UE_id = -1; int rvseq[4] = {0,2,3,1}; - mac_rlc_status_resp_t rlc_status; - unsigned char header_len_dcch=0, header_len_dcch_tmp=0; - unsigned char header_len_dtch=0, header_len_dtch_tmp=0, header_len_dtch_last=0; - unsigned char ta_len=0; - unsigned char sdu_lcids[NB_RB_MAX],lcid,offset,num_sdus=0; - uint16_t TBS,j,sdu_lengths[NB_RB_MAX],rnti,padding=0,post_padding=0; - unsigned char dlsch_buffer[MAX_DLSCH_PAYLOAD_BYTES]; - int round; - int ta_update; - uint16_t sdu_length_total = 0; - int mcs; - int32_t normalized_rx_power, target_rx_power; + int mcs = 0; + int round_DL = 0; + int ta_update = 0; + int32_t tpc = 1; + int32_t normalized_rx_power = 0; + int32_t target_rx_power = 0; + uint16_t TBS = 0; + uint16_t j = 0; + uint16_t sdu_lengths[NB_RB_MAX]; + uint16_t rnti = 0; + uint16_t padding = 0; + uint16_t post_padding = 0; + uint16_t sdu_length_total = 0; - nfapi_dl_config_request_pdu_t *dl_config_pdu; - nfapi_ul_config_request_pdu_t *ul_config_pdu; - nfapi_tx_request_pdu_t *TX_req; - nfapi_dl_config_request_body_t *dl_req; - nfapi_ul_config_request_body_t *ul_req; + mac_rlc_status_resp_t rlc_status; + rrc_eNB_ue_context_t *ue_contextP = NULL; - struct LTE_PRACH_ConfigSIB_v1310 *ext4_prach; - struct LTE_PUCCH_ConfigCommon_v1310 *ext4_pucch; - LTE_PRACH_ParametersListCE_r13_t *prach_ParametersListCE_r13; - struct LTE_N1PUCCH_AN_InfoList_r13 *pucch_N1PUCCH_AN_InfoList_r13; - int pucchreps[4] = { 1, 1, 1, 1 }; - int n1pucchan[4] = { 0, 0, 0, 0 }; - uint32_t ackNAK_absSF; - int first_rb; + unsigned char header_len_dcch = 0; + unsigned char header_len_dcch_tmp = 0; + unsigned char header_len_dtch = 0; + unsigned char header_len_dtch_tmp = 0; + unsigned char header_len_dtch_last = 0; + unsigned char ta_len = 0; + unsigned char sdu_lcids[NB_RB_MAX]; + unsigned char lcid = 0; + unsigned char offset,num_sdus=0; + unsigned char dlsch_buffer[MAX_DLSCH_PAYLOAD_BYTES]; - dl_req = &mac->DL_req[CC_id].dl_config_request_body; - dl_config_pdu = &dl_req->dl_config_pdu_list[dl_req->number_pdu]; + eNB_MAC_INST *mac = RC.mac[module_idP]; + COMMON_channels_t *cc = mac->common_channels; + UE_list_t *UE_list = &mac->UE_list; + UE_TEMPLATE *UE_template = NULL; + UE_sched_ctrl *ue_sched_ctl = NULL; - if ((frameP&1) == 0) return; + nfapi_dl_config_request_pdu_t *dl_config_pdu = NULL; + nfapi_ul_config_request_pdu_t *ul_config_pdu = NULL; + nfapi_tx_request_pdu_t *TX_req = NULL; + nfapi_dl_config_request_body_t *dl_req = NULL; + nfapi_ul_config_request_body_t *ul_req = NULL; - if (cc[CC_id].mib->message.schedulingInfoSIB1_BR_r13 ==0) return; + struct LTE_PRACH_ConfigSIB_v1310 *ext4_prach = NULL; + struct LTE_PUCCH_ConfigCommon_v1310 *ext4_pucch = NULL; + LTE_PRACH_ParametersListCE_r13_t *prach_ParametersListCE_r13 = NULL; + struct LTE_N1PUCCH_AN_InfoList_r13 *pucch_N1PUCCH_AN_InfoList_r13 = NULL; + int pucchreps[4] = { 1, 1, 1, 1 }; + int n1pucchan[4] = { 0, 0, 0, 0 }; + uint32_t ackNAK_absSF; + int first_rb; + + dl_req = &(mac->DL_req[CC_id].dl_config_request_body); + dl_config_pdu = &(dl_req->dl_config_pdu_list[dl_req->number_pdu]); + + /* Return if frame is even */ + if ((frameP & 1) == 0) { + return; + } + + if (cc[CC_id].mib->message.schedulingInfoSIB1_BR_r13 == 0) { + return; + } if (cc[CC_id].radioResourceConfigCommon_BR) { - ext4_prach = cc[CC_id].radioResourceConfigCommon_BR->ext4->prach_ConfigCommon_v1310; ext4_pucch = cc[CC_id].radioResourceConfigCommon_BR->ext4->pucch_ConfigCommon_v1310; prach_ParametersListCE_r13 = &ext4_prach->prach_ParametersListCE_r13; pucch_N1PUCCH_AN_InfoList_r13 = ext4_pucch->n1PUCCH_AN_InfoList_r13; + AssertFatal (prach_ParametersListCE_r13 != NULL, "prach_ParametersListCE_r13 is null\n"); AssertFatal (pucch_N1PUCCH_AN_InfoList_r13 != NULL, "pucch_N1PUCCH_AN_InfoList_r13 is null\n"); - // check to verify CE-Level compatibility in SIB2_BR + /* Check to verify CE-Level compatibility in SIB2_BR */ AssertFatal (prach_ParametersListCE_r13->list.count == pucch_N1PUCCH_AN_InfoList_r13->list.count, "prach_ParametersListCE_r13->list.count!= pucch_N1PUCCH_AN_InfoList_r13->list.count\n"); switch (prach_ParametersListCE_r13->list.count) { - case 4: - n1pucchan[3] = *pucch_N1PUCCH_AN_InfoList_r13->list.array[3]; - AssertFatal (ext4_pucch->pucch_NumRepetitionCE_Msg4_Level3_r13 != NULL, "pucch_NumRepetitionCE_Msg4_Level3 shouldn't be NULL\n"); - pucchreps[3] = (int) (4 << *ext4_pucch->pucch_NumRepetitionCE_Msg4_Level3_r13); + case 4: + n1pucchan[3] = *pucch_N1PUCCH_AN_InfoList_r13->list.array[3]; + AssertFatal (ext4_pucch->pucch_NumRepetitionCE_Msg4_Level3_r13 != NULL, "pucch_NumRepetitionCE_Msg4_Level3 shouldn't be NULL\n"); + pucchreps[3] = (int) (4 << *ext4_pucch->pucch_NumRepetitionCE_Msg4_Level3_r13); - case 3: - n1pucchan[2] = *pucch_N1PUCCH_AN_InfoList_r13->list.array[2]; - AssertFatal (ext4_pucch->pucch_NumRepetitionCE_Msg4_Level2_r13 != NULL, "pucch_NumRepetitionCE_Msg4_Level2 shouldn't be NULL\n"); - pucchreps[2] = (int) (4 << *ext4_pucch->pucch_NumRepetitionCE_Msg4_Level2_r13); - case 2: - n1pucchan[1] = *pucch_N1PUCCH_AN_InfoList_r13->list.array[1]; - AssertFatal (ext4_pucch->pucch_NumRepetitionCE_Msg4_Level1_r13 != NULL, "pucch_NumRepetitionCE_Msg4_Level1 shouldn't be NULL\n"); - pucchreps[1] = (int) (1 << *ext4_pucch->pucch_NumRepetitionCE_Msg4_Level1_r13); - case 1: - n1pucchan[0] = *pucch_N1PUCCH_AN_InfoList_r13->list.array[0]; - AssertFatal (ext4_pucch->pucch_NumRepetitionCE_Msg4_Level0_r13 != NULL, "pucch_NumRepetitionCE_Msg4_Level0 shouldn't be NULL\n"); - pucchreps[0] = (int) (1 << *ext4_pucch->pucch_NumRepetitionCE_Msg4_Level0_r13); - break; - default: - AssertFatal (1 == 0, "Illegal count for prach_ParametersListCE_r13 %d\n", prach_ParametersListCE_r13->list.count); + case 3: + n1pucchan[2] = *pucch_N1PUCCH_AN_InfoList_r13->list.array[2]; + AssertFatal (ext4_pucch->pucch_NumRepetitionCE_Msg4_Level2_r13 != NULL, "pucch_NumRepetitionCE_Msg4_Level2 shouldn't be NULL\n"); + pucchreps[2] = (int) (4 << *ext4_pucch->pucch_NumRepetitionCE_Msg4_Level2_r13); + case 2: + n1pucchan[1] = *pucch_N1PUCCH_AN_InfoList_r13->list.array[1]; + AssertFatal (ext4_pucch->pucch_NumRepetitionCE_Msg4_Level1_r13 != NULL, "pucch_NumRepetitionCE_Msg4_Level1 shouldn't be NULL\n"); + pucchreps[1] = (int) (1 << *ext4_pucch->pucch_NumRepetitionCE_Msg4_Level1_r13); + case 1: + n1pucchan[0] = *pucch_N1PUCCH_AN_InfoList_r13->list.array[0]; + AssertFatal (ext4_pucch->pucch_NumRepetitionCE_Msg4_Level0_r13 != NULL, "pucch_NumRepetitionCE_Msg4_Level0 shouldn't be NULL\n"); + pucchreps[0] = (int) (1 << *ext4_pucch->pucch_NumRepetitionCE_Msg4_Level0_r13); + break; + default: + AssertFatal (1 == 0, "Illegal count for prach_ParametersListCE_r13 %d\n", prach_ParametersListCE_r13->list.count); } } - for (UE_id=UE_list->head; UE_id>=0; UE_id=UE_list->next[UE_id]) { - + for (UE_id = UE_list->head; UE_id >= 0; UE_id = UE_list->next[UE_id]) { int harq_pid = 0; - rnti = UE_RNTI(module_idP,UE_id); - if (rnti==NOT_A_RNTI) continue; + rnti = UE_RNTI(module_idP, UE_id); - ue_sched_ctl = &UE_list->UE_sched_ctrl[UE_id]; - UE_template = &UE_list->UE_template[CC_id][UE_id]; + if (rnti==NOT_A_RNTI) { + continue; + } - if (UE_template->rach_resource_type == 0) continue; + ue_sched_ctl = &(UE_list->UE_sched_ctrl[UE_id]); + UE_template = &(UE_list->UE_template[CC_id][UE_id]); + + if (UE_template->rach_resource_type == 0) { + continue; + } + uint8_t rrc_status = mac_eNB_get_rrc_status(module_idP, rnti); - if (rrc_status < RRC_CONNECTED) continue; + if (rrc_status < RRC_CONNECTED) { + continue; + } - round = ue_sched_ctl->round[CC_id][harq_pid]; + round_DL = ue_sched_ctl->round[CC_id][harq_pid]; - AssertFatal (UE_template->physicalConfigDedicated != NULL, - "UE_template->physicalConfigDedicated is null\n"); - AssertFatal (UE_template->physicalConfigDedicated->ext4 != NULL, - "UE_template->physicalConfigDedicated->ext4 is null\n"); - AssertFatal (UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11 != NULL, - "UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11 is null\n"); + AssertFatal (UE_template->physicalConfigDedicated != NULL, "UE_template->physicalConfigDedicated is null\n"); + AssertFatal (UE_template->physicalConfigDedicated->ext4 != NULL, "UE_template->physicalConfigDedicated->ext4 is null\n"); + AssertFatal (UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11 != NULL, "UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11 is null\n"); AssertFatal (UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.present == LTE_EPDCCH_Config_r11__config_r11_PR_setup, - "UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.present != setup\n"); + "UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.present != setup\n"); AssertFatal (UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.setConfigToAddModList_r11 != NULL, - "UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.setConfigToAddModList_r11 = NULL\n"); + "UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.setConfigToAddModList_r11 = NULL\n"); LTE_EPDCCH_SetConfig_r11_t *epdcch_setconfig_r11 = UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.setConfigToAddModList_r11->list.array[0]; AssertFatal(epdcch_setconfig_r11 != NULL, "epdcch_setconfig_r11 is null\n"); - AssertFatal(epdcch_setconfig_r11->ext2!=NULL, "epdcch_setconfig_r11->ext2 is null\n"); - AssertFatal(epdcch_setconfig_r11->ext2->mpdcch_config_r13!=NULL, - "epdcch_setconfig_r11->ext2->mpdcch_config_r13 is null"); - AssertFatal(epdcch_setconfig_r11->ext2->mpdcch_config_r13!=NULL, - "epdcch_setconfig_r11->ext2->mpdcch_config_r13 is null"); - AssertFatal(epdcch_setconfig_r11->ext2->mpdcch_config_r13->present==LTE_EPDCCH_SetConfig_r11__ext2__mpdcch_config_r13_PR_setup, - "epdcch_setconfig_r11->ext2->mpdcch_config_r13->present is not setup\n"); - AssertFatal(epdcch_setconfig_r11->ext2->numberPRB_Pairs_v1310!=NULL, - "epdcch_setconfig_r11->ext2->numberPRB_Pairs_v1310 is null"); - AssertFatal(epdcch_setconfig_r11->ext2->numberPRB_Pairs_v1310->present==LTE_EPDCCH_SetConfig_r11__ext2__numberPRB_Pairs_v1310_PR_setup, - "epdcch_setconfig_r11->ext2->numberPRB_Pairs_v1310->present is not setup\n"); + AssertFatal(epdcch_setconfig_r11->ext2 != NULL, "epdcch_setconfig_r11->ext2 is null\n"); + AssertFatal(epdcch_setconfig_r11->ext2->mpdcch_config_r13 != NULL, "epdcch_setconfig_r11->ext2->mpdcch_config_r13 is null"); + AssertFatal(epdcch_setconfig_r11->ext2->mpdcch_config_r13 != NULL, "epdcch_setconfig_r11->ext2->mpdcch_config_r13 is null"); + AssertFatal(epdcch_setconfig_r11->ext2->mpdcch_config_r13->present == LTE_EPDCCH_SetConfig_r11__ext2__mpdcch_config_r13_PR_setup, + "epdcch_setconfig_r11->ext2->mpdcch_config_r13->present is not setup\n"); + AssertFatal(epdcch_setconfig_r11->ext2->numberPRB_Pairs_v1310 != NULL, "epdcch_setconfig_r11->ext2->numberPRB_Pairs_v1310 is null"); + AssertFatal(epdcch_setconfig_r11->ext2->numberPRB_Pairs_v1310->present == LTE_EPDCCH_SetConfig_r11__ext2__numberPRB_Pairs_v1310_PR_setup, + "epdcch_setconfig_r11->ext2->numberPRB_Pairs_v1310->present is not setup\n"); - - // simple scheduler for 1 repetition, 1 HARQ + /* Simple scheduler for 1 repetition, 1 HARQ */ if (subframeP == 5) { // MPDCCH - - if (round == 8) { + if (round_DL == 8) { rlc_status.bytes_in_buffer = 0; - // Now check RLC information to compute number of required RBs - // get maximum TBS size for RLC request + + /* Now check RLC information to compute number of required RBs */ + + /* Get maximum TBS size for RLC request */ TBS = get_TBS_DL(9,6); - // check first for RLC data on DCCH - // add the length for all the control elements (timing adv, drx, etc) : header + payload + + /* Check first for RLC data on DCCH */ + + /* Add the length for all the control elements (timing adv, drx, etc) : header + payload */ if (ue_sched_ctl->ta_timer == 0) { ta_update = ue_sched_ctl->ta_update; - /* if we send TA then set timer to not send it for a while */ + /* If we send TA then set timer to not send it for a while */ if (ta_update != 31) ue_sched_ctl->ta_timer = 20; - /* reset ta_update */ + /* Reset ta_update */ ue_sched_ctl->ta_update = 31; } else { ta_update = 31; @@ -2847,43 +2034,57 @@ schedule_ue_spec_br( header_len_dcch = 2; // 2 bytes DCCH SDU subheader - if ( TBS-ta_len-header_len_dcch > 0 ) { - LOG_I(MAC,"Calling mac_rlc_status_ind for DCCH\n"); - rlc_status = mac_rlc_status_ind( - module_idP, - rnti, - module_idP, - frameP, - subframeP, - ENB_FLAG_YES, - MBMS_FLAG_NO, - DCCH, - (TBS-ta_len-header_len_dcch) - ,0, 0 - ); // transport block set size + if (TBS - ta_len-header_len_dcch > 0 ) { + LOG_I(MAC,"Calling mac_rlc_status_ind for DCCH\n"); + + rlc_status = mac_rlc_status_ind(module_idP, + rnti, + module_idP, + frameP, + subframeP, + ENB_FLAG_YES, + MBMS_FLAG_NO, + DCCH, + (TBS-ta_len-header_len_dcch), + 0, + 0); // transport block set size - sdu_lengths[0]=0; + sdu_lengths[0] = 0; if (rlc_status.bytes_in_buffer > 0) { // There is DCCH to transmit - LOG_I(MAC,"[eNB %d] Frame %d, DL-DCCH->DLSCH CC_id %d, Requesting %d bytes from RLC (RRC message)\n", - module_idP,frameP,CC_id,TBS-header_len_dcch); - sdu_lengths[0] = mac_rlc_data_req( - module_idP, - rnti, - module_idP, - frameP, - ENB_FLAG_YES, - MBMS_FLAG_NO, - DCCH, - TBS, //not used - (char *)&dlsch_buffer[0] - ,0, 0 -); + LOG_I(MAC, "[eNB %d] Frame %d, DL-DCCH->DLSCH CC_id %d, Requesting %d bytes from RLC (RRC message)\n", + module_idP, + frameP, + CC_id, + TBS-header_len_dcch); - T(T_ENB_MAC_UE_DL_SDU, T_INT(module_idP), T_INT(CC_id), T_INT(rnti), T_INT(frameP), T_INT(subframeP), - T_INT(harq_pid), T_INT(DCCH), T_INT(sdu_lengths[0])); + sdu_lengths[0] = mac_rlc_data_req(module_idP, + rnti, + module_idP, + frameP, + ENB_FLAG_YES, + MBMS_FLAG_NO, + DCCH, + TBS, //not used + (char *)&dlsch_buffer[0], + 0, + 0); + + T(T_ENB_MAC_UE_DL_SDU, + T_INT(module_idP), + T_INT(CC_id), + T_INT(rnti), + T_INT(frameP), + T_INT(subframeP), + T_INT(harq_pid), + T_INT(DCCH), + T_INT(sdu_lengths[0])); + + LOG_I(MAC,"[eNB %d][DCCH] CC_id %d Got %d bytes from RLC\n", + module_idP, + CC_id, + sdu_lengths[0]); - LOG_I(MAC,"[eNB %d][DCCH] CC_id %d Got %d bytes from RLC\n",module_idP,CC_id,sdu_lengths[0]); sdu_length_total = sdu_lengths[0]; sdu_lcids[0] = DCCH; UE_list->eNB_UE_stats[CC_id][UE_id].num_pdu_tx[DCCH]+=1; @@ -2895,406 +2096,510 @@ schedule_ue_spec_br( } } - // check for DCCH1 and update header information (assume 2 byte sub-header) - if (TBS-ta_len-header_len_dcch-sdu_length_total > 0 ) { - rlc_status = mac_rlc_status_ind( - module_idP, - rnti, - module_idP, - frameP, - subframeP, - ENB_FLAG_YES, - MBMS_FLAG_NO, - DCCH+1, - (TBS-ta_len-header_len_dcch-sdu_length_total) - ,0, 0); // transport block set size less allocations for timing advance and - // DCCH SDU - sdu_lengths[num_sdus] = 0; + /* Check for DCCH1 and update header information (assume 2 byte sub-header) */ + if (TBS - ta_len-header_len_dcch - sdu_length_total > 0) { + rlc_status = mac_rlc_status_ind(module_idP, + rnti, + module_idP, + frameP, + subframeP, + ENB_FLAG_YES, + MBMS_FLAG_NO, + DCCH + 1, + (TBS-ta_len-header_len_dcch-sdu_length_total), + 0, + 0); // transport block set size less allocations for timing advance and DCCH SDU + + sdu_lengths[num_sdus] = 0; if (rlc_status.bytes_in_buffer > 0) { LOG_I(MAC,"[eNB %d], Frame %d, DCCH1->DLSCH, CC_id %d, Requesting %d bytes from RLC (RRC message)\n", - module_idP,frameP,CC_id,TBS-header_len_dcch-sdu_length_total); - sdu_lengths[num_sdus] += mac_rlc_data_req( - module_idP, - rnti, - module_idP, - frameP, - ENB_FLAG_YES, - MBMS_FLAG_NO, - DCCH+1, - TBS, //not used - (char *)&dlsch_buffer[sdu_length_total] - ,0, 0 - ); + module_idP, + frameP, + CC_id, + TBS-header_len_dcch - sdu_length_total); + + sdu_lengths[num_sdus] += mac_rlc_data_req(module_idP, + rnti, + module_idP, + frameP, + ENB_FLAG_YES, + MBMS_FLAG_NO, + DCCH+1, + TBS, //not used + (char *)&dlsch_buffer[sdu_length_total], + 0, + 0); - T(T_ENB_MAC_UE_DL_SDU, T_INT(module_idP), T_INT(CC_id), T_INT(rnti), T_INT(frameP), T_INT(subframeP), - T_INT(harq_pid), T_INT(DCCH+1), T_INT(sdu_lengths[num_sdus])); + T(T_ENB_MAC_UE_DL_SDU, + T_INT(module_idP), + T_INT(CC_id), + T_INT(rnti), + T_INT(frameP), + T_INT(subframeP), + T_INT(harq_pid), + T_INT(DCCH+1), + T_INT(sdu_lengths[num_sdus])); sdu_lcids[num_sdus] = DCCH1; sdu_length_total += sdu_lengths[num_sdus]; header_len_dcch += 2; - UE_list->eNB_UE_stats[CC_id][UE_id].num_pdu_tx[DCCH1]+=1; - UE_list->eNB_UE_stats[CC_id][UE_id].num_bytes_tx[DCCH1]+=sdu_lengths[num_sdus]; - num_sdus++; - } + UE_list->eNB_UE_stats[CC_id][UE_id].num_pdu_tx[DCCH1] += 1; + UE_list->eNB_UE_stats[CC_id][UE_id].num_bytes_tx[DCCH1] += sdu_lengths[num_sdus]; + num_sdus++; + } } - // assume the max dtch header size, and adjust it later - header_len_dtch=0; - header_len_dtch_last=0; // the header length of the last mac sdu - // lcid has to be sorted before the actual allocation (similar struct as ue_list). - for (lcid=NB_RB_MAX-1; lcid>=DTCH ; lcid--){ - // TBD: check if the lcid is active - - header_len_dtch+=3; - header_len_dtch_last=3; - LOG_D(MAC,"[eNB %d], Frame %d, DTCH%d->DLSCH, Checking RLC status (tbs %d, len %d)\n", - module_idP,frameP,lcid,TBS, - TBS-ta_len-header_len_dcch-sdu_length_total-header_len_dtch); - - if (TBS-ta_len-header_len_dcch-sdu_length_total-header_len_dtch > 0 ) { // NN: > 2 ? - rlc_status = mac_rlc_status_ind(module_idP, - rnti, - module_idP, - frameP, - subframeP, - ENB_FLAG_YES, - MBMS_FLAG_NO, - lcid, - TBS-ta_len-header_len_dcch-sdu_length_total-header_len_dtch - ,0, 0); - + /* Assume the max dtch header size, and adjust it later */ + header_len_dtch = 0; + header_len_dtch_last = 0; // the header length of the last mac sdu + + /* lcid has to be sorted before the actual allocation (similar struct as ue_list) */ + for (lcid = NB_RB_MAX-1; lcid >= DTCH ; lcid--){ + /* TBD: check if the lcid is active */ + header_len_dtch += 3; + header_len_dtch_last = 3; - if (rlc_status.bytes_in_buffer > 0) { - - LOG_I(MAC,"[eNB %d][USER-PLANE DEFAULT DRB] Frame %d : DTCH->DLSCH, Requesting %d bytes from RLC (lcid %d total hdr len %d)\n", - module_idP,frameP,TBS-header_len_dcch-sdu_length_total-header_len_dtch,lcid, header_len_dtch); - sdu_lengths[num_sdus] = mac_rlc_data_req(module_idP, - rnti, - module_idP, - frameP, - ENB_FLAG_YES, - MBMS_FLAG_NO, - lcid, - TBS, //not used - (char*)&dlsch_buffer[sdu_length_total] - ,0, 0); - T(T_ENB_MAC_UE_DL_SDU, T_INT(module_idP), T_INT(CC_id), T_INT(rnti), T_INT(frameP), T_INT(subframeP), - T_INT(harq_pid), T_INT(lcid), T_INT(sdu_lengths[num_sdus])); + LOG_D(MAC,"[eNB %d], Frame %d, DTCH%d->DLSCH, Checking RLC status (tbs %d, len %d)\n", + module_idP, + frameP, + lcid, + TBS, + TBS - ta_len-header_len_dcch - sdu_length_total - header_len_dtch); + + if (TBS - ta_len - header_len_dcch - sdu_length_total - header_len_dtch > 0) { // NN: > 2 ? + rlc_status = mac_rlc_status_ind(module_idP, + rnti, + module_idP, + frameP, + subframeP, + ENB_FLAG_YES, + MBMS_FLAG_NO, + lcid, + TBS - ta_len - header_len_dcch - sdu_length_total - header_len_dtch, + 0, + 0); + + if (rlc_status.bytes_in_buffer > 0) { + /* RRC inactivity LTE-M */ + /* Reset RRC inactivity timer after uplane activity */ + ue_contextP = rrc_eNB_get_ue_context(RC.rrc[module_idP], rnti); - LOG_I(MAC,"[eNB %d][USER-PLANE DEFAULT DRB] Got %d bytes for DTCH %d \n",module_idP,sdu_lengths[num_sdus],lcid); - sdu_lcids[num_sdus] = lcid; - sdu_length_total += sdu_lengths[num_sdus]; + if (ue_contextP != NULL) { + ue_contextP->ue_context.ue_rrc_inactivity_timer = 1; + } else { + LOG_E(MAC, "[eNB %d] CC_id %d Couldn't find the context associated to UE (RNTI %d) and reset RRC inactivity timer\n", + module_idP, + CC_id, + rnti); + } + + LOG_I(MAC,"[eNB %d][USER-PLANE DEFAULT DRB] Frame %d : DTCH->DLSCH, Requesting %d bytes from RLC (lcid %d total hdr len %d)\n", + module_idP, + frameP, + TBS - header_len_dcch - sdu_length_total - header_len_dtch, + lcid, + header_len_dtch); + + sdu_lengths[num_sdus] = mac_rlc_data_req(module_idP, + rnti, + module_idP, + frameP, + ENB_FLAG_YES, + MBMS_FLAG_NO, + lcid, + TBS, //not used + (char*) &dlsch_buffer[sdu_length_total], + 0, + 0); - if (sdu_lengths[num_sdus] < 128) { - header_len_dtch--; - header_len_dtch_last--; - } - num_sdus++; - } // no data for this LCID - else { - header_len_dtch-=3; - } - } // no TBS left - else { - header_len_dtch-=3; - break; - } - } - if (header_len_dtch == 0 ) - header_len_dtch_last= 0; - // there is at least one SDU - // if (num_sdus > 0 ){ - if ((sdu_length_total + header_len_dcch + header_len_dtch )> 0) { - - // Now compute number of required RBs for total sdu length - // Assume RAH format 2 - // adjust header lengths - header_len_dcch_tmp = header_len_dcch; - header_len_dtch_tmp = header_len_dtch; - if (header_len_dtch==0) { - header_len_dcch = (header_len_dcch >0) ? 1 : 0;//header_len_dcch; // remove length field - } else { - header_len_dtch_last-=1; // now use it to find how many bytes has to be removed for the last MAC SDU - header_len_dtch = (header_len_dtch > 0) ? header_len_dtch - header_len_dtch_last :header_len_dtch; // remove length field for the last SDU - } + T(T_ENB_MAC_UE_DL_SDU, + T_INT(module_idP), + T_INT(CC_id), + T_INT(rnti), + T_INT(frameP), + T_INT(subframeP), + T_INT(harq_pid), + T_INT(lcid), + T_INT(sdu_lengths[num_sdus])); - mcs = 9; + LOG_I(MAC,"[eNB %d][USER-PLANE DEFAULT DRB] Got %d bytes for DTCH %d \n", + module_idP, + sdu_lengths[num_sdus], + lcid); - // decrease mcs until TBS falls below required length - while ((TBS > (sdu_length_total + header_len_dcch + header_len_dtch + ta_len)) && (mcs>0)) { - mcs--; - TBS = get_TBS_DL(mcs,6); - } + sdu_lcids[num_sdus] = lcid; + sdu_length_total += sdu_lengths[num_sdus]; - // if we have decreased too much or we don't have enough RBs, increase MCS - while (TBS < (sdu_length_total + header_len_dcch + header_len_dtch + ta_len)) { - mcs++; - TBS = get_TBS_DL(mcs,6); - } - - //#ifdef DEBUG_eNB_SCHEDULER - LOG_I(MAC,"[eNB %d] CC_id %d Generated DLSCH header (mcs %d, TBS %d, nb_rb %d)\n", - module_idP,CC_id,mcs,TBS,6); - // msg("[MAC][eNB ] Reminder of DLSCH with random data %d %d %d %d \n", - // TBS, sdu_length_total, offset, TBS-sdu_length_total-offset); - - - if ((TBS - header_len_dcch - header_len_dtch - sdu_length_total - ta_len) <= 2) { - padding = (TBS - header_len_dcch - header_len_dtch - sdu_length_total - ta_len); - post_padding = 0; - } else { - padding = 0; - - // adjust the header len - if (header_len_dtch==0) { - header_len_dcch = header_len_dcch_tmp; - } else { //if (( header_len_dcch==0)&&((header_len_dtch==1)||(header_len_dtch==2))) - header_len_dtch = header_len_dtch_tmp; + if (sdu_lengths[num_sdus] < 128) { + header_len_dtch--; + header_len_dtch_last--; } - post_padding = TBS - sdu_length_total - header_len_dcch - header_len_dtch - ta_len ; // 1 is for the postpadding header + num_sdus++; + } else { // no data for this LCID + header_len_dtch -= 3; } + } else { // no TBS left + header_len_dtch -= 3; + break; + } + } // for loop LCID - - offset = generate_dlsch_header((unsigned char*)UE_list->DLSCH_pdu[CC_id][0][UE_id].payload[0], - num_sdus, //num_sdus - sdu_lengths, // - sdu_lcids, - 255, // no drx - ta_update, // timing advance - NULL, // contention res id - padding, - post_padding); - - - if (ta_update != 31) { - LOG_D(MAC, - "[eNB %d][DLSCH] Frame %d Generate header for UE_id %d on CC_id %d: sdu_length_total %d, num_sdus %d, sdu_lengths[0] %d, sdu_lcids[0] %d => payload offset %d,timing advance value : %d, padding %d,post_padding %d,(mcs %d, TBS %d, nb_rb %d),header_dcch %d, header_dtch %d\n", - module_idP,frameP, UE_id, CC_id, sdu_length_total,num_sdus,sdu_lengths[0],sdu_lcids[0],offset, - ta_update,padding,post_padding,mcs,TBS,6,header_len_dcch,header_len_dtch); - } - - - - // cycle through SDUs and place in dlsch_buffer - memcpy(&UE_list->DLSCH_pdu[CC_id][0][UE_id].payload[0][offset],dlsch_buffer,sdu_length_total); - // memcpy(RC.mac[0].DLSCH_pdu[0][0].payload[0][offset],dcch_buffer,sdu_lengths[0]); - - // fill remainder of DLSCH with random data - for (j=0; j<(TBS-sdu_length_total-offset); j++) { - UE_list->DLSCH_pdu[CC_id][0][UE_id].payload[0][offset+sdu_length_total+j] = (char)(taus()&0xff); - } - - - if (opt_enabled == 1) { - trace_pdu(1, (uint8_t *)UE_list->DLSCH_pdu[CC_id][0][UE_id].payload[0], - TBS, module_idP, 3, UE_RNTI(module_idP,UE_id), - mac->frame, mac->subframe,0,0); - LOG_D(OPT,"[eNB %d][DLSCH] CC_id %d Frame %d rnti %x with size %d\n", - module_idP, CC_id, frameP, UE_RNTI(module_idP,UE_id), TBS); - } - - T(T_ENB_MAC_UE_DL_PDU_WITH_DATA, T_INT(module_idP), T_INT(CC_id), T_INT(rnti), T_INT(frameP), T_INT(subframeP), - T_INT(harq_pid), T_BUFFER(UE_list->DLSCH_pdu[CC_id][0][UE_id].payload[0], TBS)); - - // do PUCCH power control - // this is the normalized RX power - - /* TODO: fix how we deal with power, unit is not dBm, it's special from nfapi */ - normalized_rx_power = (5*ue_sched_ctl->pucch1_snr[CC_id]-640)/10+30; - target_rx_power = mac->puCch10xSnr/10+30; - - // this assumes accumulated tpc - // make sure that we are only sending a tpc update once a frame, otherwise the control loop will freak out - int32_t framex10psubframe = UE_list->UE_template[CC_id][UE_id].pucch_tpc_tx_frame*10+UE_list->UE_template[CC_id][UE_id].pucch_tpc_tx_subframe; - if (((framex10psubframe+10)<=(frameP*10+subframeP)) || //normal case - ((framex10psubframe>(frameP*10+subframeP)) && (((10240-framex10psubframe+frameP*10+subframeP)>=10)))) //frame wrap-around - if (ue_sched_ctl->pucch1_cqi_update[CC_id] == 1) { - ue_sched_ctl->pucch1_cqi_update[CC_id] = 0; - - UE_list->UE_template[CC_id][UE_id].pucch_tpc_tx_frame=frameP; - UE_list->UE_template[CC_id][UE_id].pucch_tpc_tx_subframe=subframeP; - - if (normalized_rx_power>(target_rx_power+4)) { - tpc = 0; //-1 - } else if (normalized_rx_power<(target_rx_power-4)) { - tpc = 2; //+1 - } else { - tpc = 1; //0 - } - - LOG_D(MAC,"[eNB %d] DLSCH scheduler: frame %d, subframe %d, harq_pid %d, tpc %d, normalized/target rx power %d/%d\n", - module_idP,frameP, subframeP,harq_pid,tpc, - normalized_rx_power,target_rx_power); - - } // Po_PUCCH has been updated - else { - tpc = 1; //0 - } // time to do TPC update - else { - tpc = 1; //0 - } - - // Toggle NDI in first round - UE_template->oldNDI[harq_pid] = 1-UE_template->oldNDI[harq_pid]; - ue_sched_ctl->round[CC_id][harq_pid] = 0; - round=0; - } - - } - - if (round < 8) { - // fill in MDPDCCH - memset ((void *) dl_config_pdu, 0, sizeof (nfapi_dl_config_request_pdu_t)); - dl_config_pdu->pdu_type = NFAPI_DL_CONFIG_MPDCCH_PDU_TYPE; - dl_config_pdu->pdu_size = (uint8_t) (2 + sizeof (nfapi_dl_config_mpdcch_pdu)); - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.dci_format = (UE_template->rach_resource_type > 1) ? 11 : 10; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.mpdcch_narrow_band = epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_Narrowband_r13-1; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.number_of_prb_pairs = 6; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.resource_block_assignment = 0; // Note: this can be dynamic - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.mpdcch_tansmission_type = epdcch_setconfig_r11->transmissionType_r11; - AssertFatal(UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.startSymbol_r11!=NULL, - "UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.startSymbol_r11 is null\n"); - - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.start_symbol = *UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.startSymbol_r11; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.ecce_index = 0; // Note: this should be dynamic - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.aggregation_level = 24; // OK for CEModeA r1-3 (9.1.5-1b) or CEModeB r1-4 - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.rnti_type = 4; // t-CRNTI - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.rnti = rnti; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.ce_mode = (UE_template->rach_resource_type < 3) ? 1 : 2; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.drms_scrambling_init = epdcch_setconfig_r11->dmrs_ScramblingSequenceInt_r11; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.initial_transmission_sf_io = (frameP * 10) + subframeP; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.transmission_power = 6000; // 0dB - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.resource_block_coding = getRIV (6, 0, 6) | ((epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_Narrowband_r13-1)<<5); - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.mcs = 9; // adjust according to size of RAR, 208 bits with N1A_PRB=3 - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.pdsch_reptition_levels = 0; // fix to 4 for now - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.redundancy_version = rvseq[round&3]; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.new_data_indicator = UE_template->oldNDI[harq_pid]; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.harq_process = 0; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.tpmi_length = 0; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.tpmi = 0; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.pmi_flag = 0; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.pmi = 0; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.harq_resource_offset = 0; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.dci_subframe_repetition_number = 0; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.tpc = 3; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.downlink_assignment_index_length = 0; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.downlink_assignment_index = 0; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.allocate_prach_flag = 0; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.preamble_index = 0; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.prach_mask_index = 0; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.starting_ce_level = 0; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.srs_request = 0; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.antenna_ports_and_scrambling_identity_flag = 0; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.antenna_ports_and_scrambling_identity = 0; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.frequency_hopping_enabled_flag = 0; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.paging_direct_indication_differentiation_flag = 0; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.direct_indication = 0; - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.total_dci_length_including_padding = 0; // this is not needed by OAI L1, but should be filled in - dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.number_of_tx_antenna_ports = 1; - dl_req->number_pdu++; - UE_template->mcs[harq_pid] = dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.mcs; - } + if (header_len_dtch == 0) { + header_len_dtch_last = 0; } - else if ((subframeP == 7)&&(round<8)) { // DLSCH - - int absSF = (frameP * 10) + subframeP; - - // Have to check that MPDCCH was generated - LOG_I (MAC, "[eNB %d][RAPROC] CC_id %d Frame %d, subframeP %d: Generating DLSCH (ce_level %d RNTI %x)\n", - module_idP, CC_id, frameP, subframeP, UE_template->rach_resource_type - 1,rnti); - - first_rb = narrowband_to_first_rb (&cc[CC_id], epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_Narrowband_r13-1); - dl_config_pdu = &dl_req->dl_config_pdu_list[dl_req->number_pdu]; - memset ((void *) dl_config_pdu, 0, sizeof (nfapi_dl_config_request_pdu_t)); - dl_config_pdu->pdu_type = NFAPI_DL_CONFIG_DLSCH_PDU_TYPE; - dl_config_pdu->pdu_size = (uint8_t) (2 + sizeof (nfapi_dl_config_dlsch_pdu)); - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.pdu_index = mac->pdu_index[CC_id]; - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.rnti = rnti; - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.resource_allocation_type = 2; // format 1A/1B/1D - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.virtual_resource_block_assignment_flag = 0; // localized - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.resource_block_coding = getRIV (to_prb (cc[CC_id].mib->message.dl_Bandwidth), first_rb, 6); // check that this isn't getRIV(6,0,6) - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.modulation = 2; //QPSK - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.redundancy_version = 0; - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.transport_blocks = 1; // first block - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.transport_block_to_codeword_swap_flag = 0; - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.transmission_scheme = (cc[CC_id].p_eNB == 1) ? 0 : 1; - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.number_of_layers = 1; - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.number_of_subbands = 1; - // dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.codebook_index = ; - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.ue_category_capacity = 1; - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.pa = 4; // 0 dB - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.delta_power_offset_index = 0; - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.ngap = 0; - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.nprb = get_subbandsize (cc[CC_id].mib->message.dl_Bandwidth); // ignored - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.transmission_mode = (cc[CC_id].p_eNB == 1) ? 1 : 2; - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.num_bf_prb_per_subband = 1; - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.num_bf_vector = 1; - // dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.bf_vector = ; - - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel10.pdsch_start = *UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.startSymbol_r11; - - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel13.ue_type = (UE_template->rach_resource_type < 3) ? 1 : 2; - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel13.pdsch_payload_type = 2; // not SI message - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel13.initial_transmission_sf_io = (10 * frameP) + subframeP; - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel13.drms_table_flag = 0; - dl_req->number_pdu++; - // DL request - mac->TX_req[CC_id].sfn_sf = (frameP << 4) + subframeP; - TX_req = &mac->TX_req[CC_id].tx_request_body.tx_pdu_list[mac->TX_req[CC_id].tx_request_body.number_of_pdus]; - TX_req->pdu_length = get_TBS_DL(UE_template->mcs[harq_pid], - 6); - TX_req->pdu_index = mac->pdu_index[CC_id]++; - TX_req->num_segments = 1; - TX_req->segments[0].segment_length = TX_req->pdu_length; - TX_req->segments[0].segment_data = mac->UE_list.DLSCH_pdu[CC_id][0][(unsigned char) UE_id].payload[0]; - mac->TX_req[CC_id].tx_request_body.number_of_pdus++; - - ackNAK_absSF = absSF + 4; - ul_req = &mac->UL_req_tmp[CC_id][ackNAK_absSF % 10].ul_config_request_body; - ul_config_pdu = &ul_req->ul_config_pdu_list[ul_req->number_of_pdus]; + /* There is at least one SDU */ + if ((sdu_length_total + header_len_dcch + header_len_dtch) > 0) { + /* Now compute number of required RBs for total sdu length */ + /* Assume RAH format 2 */ + /* Adjust header lengths */ + header_len_dcch_tmp = header_len_dcch; + header_len_dtch_tmp = header_len_dtch; - ul_config_pdu->pdu_type = NFAPI_UL_CONFIG_UCI_HARQ_PDU_TYPE; - ul_config_pdu->pdu_size = (uint8_t) (2 + sizeof (nfapi_ul_config_uci_harq_pdu)); - ul_config_pdu->uci_harq_pdu.ue_information.ue_information_rel8.handle = 0; // don't know how to use this - ul_config_pdu->uci_harq_pdu.ue_information.ue_information_rel8.rnti = rnti; - ul_config_pdu->uci_harq_pdu.ue_information.ue_information_rel13.ue_type = (UE_template->rach_resource_type < 3) ? 1 : 2; - ul_config_pdu->uci_harq_pdu.ue_information.ue_information_rel13.empty_symbols = 0; - ul_config_pdu->uci_harq_pdu.ue_information.ue_information_rel13.total_number_of_repetitions = pucchreps[UE_template->rach_resource_type - 1]; - ul_config_pdu->uci_harq_pdu.ue_information.ue_information_rel13.repetition_number = 0; - - if (cc[CC_id].tdd_Config == NULL) { // FDD case - ul_config_pdu->uci_harq_pdu.harq_information.harq_information_rel9_fdd.n_pucch_1_0 = n1pucchan[UE_template->rach_resource_type - 1]; - // NOTE: How to fill in the rest of the n_pucch_1_0 information 213 Section 10.1.2.1 in the general case - // = N_ECCE_q + Delta_ARO + n1pucchan[ce_level] - // higher in the MPDCCH configuration, N_ECCE_q is hard-coded to 0, and harq resource offset to 0 => - // Delta_ARO = 0 from Table 10.1.2.1-1 - ul_config_pdu->uci_harq_pdu.harq_information.harq_information_rel9_fdd.harq_size = 1; // 1-bit ACK/NAK - ul_config_pdu->uci_harq_pdu.harq_information.harq_information_rel9_fdd.number_of_pucch_resources = 1; + if (header_len_dtch == 0) { + header_len_dcch = (header_len_dcch > 0) ? 1 : 0; // remove length field } else { - AssertFatal (1 == 0, "PUCCH configuration for ACK/NAK not handled yet for TDD BL/CE case\n"); + header_len_dtch_last -= 1; // now use it to find how many bytes has to be removed for the last MAC SDU + header_len_dtch = (header_len_dtch > 0) ? header_len_dtch - header_len_dtch_last : header_len_dtch; // remove length field for the last SDU } + + mcs = 9; + + /* Decrease mcs until TBS falls below required length */ + while ((TBS > (sdu_length_total + header_len_dcch + header_len_dtch + ta_len)) && (mcs>0)) { + mcs--; + TBS = get_TBS_DL(mcs,6); + } + + /* If we have decreased too much or we don't have enough RBs, increase MCS */ + while (TBS < (sdu_length_total + header_len_dcch + header_len_dtch + ta_len)) { + mcs++; + TBS = get_TBS_DL(mcs,6); + } + + LOG_I(MAC, "[eNB %d] CC_id %d Generated DLSCH header (mcs %d, TBS %d, nb_rb %d)\n", + module_idP, + CC_id, + mcs, + TBS, + 6); + + if ((TBS - header_len_dcch - header_len_dtch - sdu_length_total - ta_len) <= 2) { + padding = (TBS - header_len_dcch - header_len_dtch - sdu_length_total - ta_len); + post_padding = 0; + } else { + padding = 0; + + /* Adjust the header len */ + if (header_len_dtch == 0) { + header_len_dcch = header_len_dcch_tmp; + } else { // if ((header_len_dcch==0)&&((header_len_dtch==1)||(header_len_dtch==2))) + header_len_dtch = header_len_dtch_tmp; + } + + post_padding = TBS - sdu_length_total - header_len_dcch - header_len_dtch - ta_len; // 1 is for the postpadding header + } + + offset = generate_dlsch_header((unsigned char*)UE_list->DLSCH_pdu[CC_id][0][UE_id].payload[0], + num_sdus, //num_sdus + sdu_lengths, // + sdu_lcids, + 255, // no drx + ta_update, // timing advance + NULL, // contention res id + padding, + post_padding); + + + if (ta_update != 31) { + LOG_D(MAC,"[eNB %d][DLSCH] Frame %d Generate header for UE_id %d on CC_id %d: sdu_length_total %d, num_sdus %d, sdu_lengths[0] %d, sdu_lcids[0] %d => payload offset %d,timing advance value : %d, padding %d,post_padding %d,(mcs %d, TBS %d, nb_rb %d),header_dcch %d, header_dtch %d\n", + module_idP, + frameP, + UE_id, + CC_id, + sdu_length_total, + num_sdus, + sdu_lengths[0], + sdu_lcids[0], + offset, + ta_update, + padding, + post_padding, + mcs, + TBS, + 6, + header_len_dcch, + header_len_dtch); + } + + /* Cycle through SDUs and place in dlsch_buffer */ + memcpy(&UE_list->DLSCH_pdu[CC_id][0][UE_id].payload[0][offset], dlsch_buffer, sdu_length_total); + + /* Fill remainder of DLSCH with random data */ + for (j = 0; j < (TBS - sdu_length_total - offset); j++) { + UE_list->DLSCH_pdu[CC_id][0][UE_id].payload[0][offset + sdu_length_total + j] = (char)(taus()&0xff); + } + + if (opt_enabled == 1) { + trace_pdu(1, + (uint8_t *)UE_list->DLSCH_pdu[CC_id][0][UE_id].payload[0], + TBS, + module_idP, + 3, + UE_RNTI(module_idP,UE_id), + mac->frame, + mac->subframe, + 0, + 0); + + LOG_D(OPT,"[eNB %d][DLSCH] CC_id %d Frame %d rnti %x with size %d\n", + module_idP, + CC_id, + frameP, + UE_RNTI(module_idP, UE_id), + TBS); + } + + T(T_ENB_MAC_UE_DL_PDU_WITH_DATA, + T_INT(module_idP), + T_INT(CC_id), + T_INT(rnti), + T_INT(frameP), + T_INT(subframeP), + T_INT(harq_pid), + T_BUFFER(UE_list->DLSCH_pdu[CC_id][0][UE_id].payload[0], TBS)); + + /* Do PUCCH power control */ + /* This is the normalized RX power */ + /* TODO: fix how we deal with power, unit is not dBm, it's special from nfapi */ + normalized_rx_power = (5 * ue_sched_ctl->pucch1_snr[CC_id]-640) / 10 + 30; + target_rx_power = mac->puCch10xSnr / 10 + 30; + + /* This assumes accumulated tpc */ + /* Make sure that we are only sending a tpc update once a frame, otherwise the control loop will freak out */ + int32_t framex10psubframe = UE_list->UE_template[CC_id][UE_id].pucch_tpc_tx_frame * 10 + UE_list->UE_template[CC_id][UE_id].pucch_tpc_tx_subframe; + + if (((framex10psubframe + 10) <= (frameP * 10 + subframeP)) || // normal case + ((framex10psubframe > (frameP * 10 + subframeP)) && + (((10240 - framex10psubframe +frameP * 10 + subframeP) >= 10)))) { // frame wrap-around + if (ue_sched_ctl->pucch1_cqi_update[CC_id] == 1) { + ue_sched_ctl->pucch1_cqi_update[CC_id] = 0; + + UE_list->UE_template[CC_id][UE_id].pucch_tpc_tx_frame = frameP; + UE_list->UE_template[CC_id][UE_id].pucch_tpc_tx_subframe = subframeP; + + if (normalized_rx_power > (target_rx_power + 4)) { + tpc = 0; //-1 + } else if (normalized_rx_power<(target_rx_power - 4)) { + tpc = 2; //+1 + } else { + tpc = 1; //0 + } + + LOG_D(MAC,"[eNB %d] DLSCH scheduler: frame %d, subframe %d, harq_pid %d, tpc %d, normalized/target rx power %d/%d\n", + module_idP, + frameP, + subframeP, + harq_pid, + tpc, + normalized_rx_power, + target_rx_power); + } else { // Po_PUCCH has been updated + tpc = 1; // 0 + } + } else { // time to do TPC update + tpc = 1; //0 + } + + // Toggle NDI in first round + UE_template->oldNDI[harq_pid] = 1 - UE_template->oldNDI[harq_pid]; + ue_sched_ctl->round[CC_id][harq_pid] = 0; + round_DL = 0; + } // if ((sdu_length_total + header_len_dcch + header_len_dtch) > 0) + } + + if (round_DL < 8) { + /* Fill in MDPDCCH */ + memset ((void *) dl_config_pdu, 0, sizeof (nfapi_dl_config_request_pdu_t)); + + dl_config_pdu->pdu_type = NFAPI_DL_CONFIG_MPDCCH_PDU_TYPE; + dl_config_pdu->pdu_size = (uint8_t) (2 + sizeof (nfapi_dl_config_mpdcch_pdu)); + dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.dci_format = (UE_template->rach_resource_type > 1) ? 11 : 10; + dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.mpdcch_narrow_band = epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_Narrowband_r13-1; + dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.number_of_prb_pairs = 6; + dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.resource_block_assignment = 0; // Note: this can be dynamic + dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.mpdcch_tansmission_type = epdcch_setconfig_r11->transmissionType_r11; + + AssertFatal(UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.startSymbol_r11 != NULL, + "UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.startSymbol_r11 is null\n"); + + dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.start_symbol = *UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.startSymbol_r11; + dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.ecce_index = 0; // Note: this should be dynamic + dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.aggregation_level = 24; // OK for CEModeA r1-3 (9.1.5-1b) or CEModeB r1-4 + dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.rnti_type = 4; // t-CRNTI + dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.rnti = rnti; + dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.ce_mode = (UE_template->rach_resource_type < 3) ? 1 : 2; + dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.drms_scrambling_init = epdcch_setconfig_r11->dmrs_ScramblingSequenceInt_r11; + dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.initial_transmission_sf_io = (frameP * 10) + subframeP; + dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.transmission_power = 6000; // 0dB + dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.resource_block_coding = getRIV (6, 0, 6) | ((epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_Narrowband_r13-1)<<5); + dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.mcs = 9; // adjust according to size of RAR, 208 bits with N1A_PRB=3 + dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.pdsch_reptition_levels = 0; // fix to 4 for now + dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.redundancy_version = rvseq[round_DL&3]; + dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.new_data_indicator = UE_template->oldNDI[harq_pid]; + dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.harq_process = 0; + dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.tpmi_length = 0; + dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.tpmi = 0; + dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.pmi_flag = 0; + dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.pmi = 0; + dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.harq_resource_offset = 0; + dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.dci_subframe_repetition_number = 0; + dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.tpc = 3; + dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.downlink_assignment_index_length = 0; + dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.downlink_assignment_index = 0; + dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.allocate_prach_flag = 0; + dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.preamble_index = 0; + dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.prach_mask_index = 0; + dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.starting_ce_level = 0; + dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.srs_request = 0; + dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.antenna_ports_and_scrambling_identity_flag = 0; + dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.antenna_ports_and_scrambling_identity = 0; + dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.frequency_hopping_enabled_flag = 0; + dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.paging_direct_indication_differentiation_flag = 0; + dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.direct_indication = 0; + dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.total_dci_length_including_padding = 0; // this is not needed by OAI L1, but should be filled in + dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.number_of_tx_antenna_ports = 1; + dl_req->number_pdu++; + UE_template->mcs[harq_pid] = dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.mcs; + } + } else if ((subframeP == 7) && (round_DL < 8)) { // DLSCH + + int absSF = (frameP * 10) + subframeP; + + /* Have to check that MPDCCH was generated */ + LOG_I (MAC, "[eNB %d][RAPROC] CC_id %d Frame %d, subframeP %d: Generating DLSCH (ce_level %d RNTI %x)\n", + module_idP, + CC_id, + frameP, + subframeP, + UE_template->rach_resource_type - 1, + rnti); + + first_rb = narrowband_to_first_rb(&cc[CC_id], epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_Narrowband_r13 - 1); + + dl_config_pdu = &dl_req->dl_config_pdu_list[dl_req->number_pdu]; + + memset ((void *) dl_config_pdu, 0, sizeof (nfapi_dl_config_request_pdu_t)); + + dl_config_pdu->pdu_type = NFAPI_DL_CONFIG_DLSCH_PDU_TYPE; + dl_config_pdu->pdu_size = (uint8_t) (2 + sizeof (nfapi_dl_config_dlsch_pdu)); + dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.pdu_index = mac->pdu_index[CC_id]; + dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.rnti = rnti; + dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.resource_allocation_type = 2; // format 1A/1B/1D + dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.virtual_resource_block_assignment_flag = 0; // localized + dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.resource_block_coding = getRIV (to_prb (cc[CC_id].mib->message.dl_Bandwidth), first_rb, 6); // check that this isn't getRIV(6,0,6) + dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.modulation = 2; //QPSK + dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.redundancy_version = 0; + dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.transport_blocks = 1; // first block + dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.transport_block_to_codeword_swap_flag = 0; + dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.transmission_scheme = (cc[CC_id].p_eNB == 1) ? 0 : 1; + dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.number_of_layers = 1; + dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.number_of_subbands = 1; + // dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.codebook_index = ; + dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.ue_category_capacity = 1; + dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.pa = 4; // 0 dB + dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.delta_power_offset_index = 0; + dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.ngap = 0; + dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.nprb = get_subbandsize (cc[CC_id].mib->message.dl_Bandwidth); // ignored + dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.transmission_mode = (cc[CC_id].p_eNB == 1) ? 1 : 2; + dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.num_bf_prb_per_subband = 1; + dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.num_bf_vector = 1; + // dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.bf_vector = ; + dl_config_pdu->dlsch_pdu.dlsch_pdu_rel10.pdsch_start = *UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.startSymbol_r11; + dl_config_pdu->dlsch_pdu.dlsch_pdu_rel13.ue_type = (UE_template->rach_resource_type < 3) ? 1 : 2; + dl_config_pdu->dlsch_pdu.dlsch_pdu_rel13.pdsch_payload_type = 2; // not SI message + dl_config_pdu->dlsch_pdu.dlsch_pdu_rel13.initial_transmission_sf_io = (10 * frameP) + subframeP; + dl_config_pdu->dlsch_pdu.dlsch_pdu_rel13.drms_table_flag = 0; + dl_req->number_pdu++; + + // DL request + mac->TX_req[CC_id].sfn_sf = (frameP << 4) + subframeP; + TX_req = &mac->TX_req[CC_id].tx_request_body.tx_pdu_list[mac->TX_req[CC_id].tx_request_body.number_of_pdus]; + TX_req->pdu_length = get_TBS_DL(UE_template->mcs[harq_pid], 6); + TX_req->pdu_index = mac->pdu_index[CC_id]++; + TX_req->num_segments = 1; + TX_req->segments[0].segment_length = TX_req->pdu_length; + TX_req->segments[0].segment_data = mac->UE_list.DLSCH_pdu[CC_id][0][(unsigned char) UE_id].payload[0]; + mac->TX_req[CC_id].tx_request_body.number_of_pdus++; + + ackNAK_absSF = absSF + 4; + ul_req = &mac->UL_req_tmp[CC_id][ackNAK_absSF % 10].ul_config_request_body; + ul_config_pdu = &ul_req->ul_config_pdu_list[ul_req->number_of_pdus]; + + ul_config_pdu->pdu_type = NFAPI_UL_CONFIG_UCI_HARQ_PDU_TYPE; + ul_config_pdu->pdu_size = (uint8_t) (2 + sizeof (nfapi_ul_config_uci_harq_pdu)); + ul_config_pdu->uci_harq_pdu.ue_information.ue_information_rel8.handle = 0; // don't know how to use this + ul_config_pdu->uci_harq_pdu.ue_information.ue_information_rel8.rnti = rnti; + ul_config_pdu->uci_harq_pdu.ue_information.ue_information_rel13.ue_type = (UE_template->rach_resource_type < 3) ? 1 : 2; + ul_config_pdu->uci_harq_pdu.ue_information.ue_information_rel13.empty_symbols = 0; + ul_config_pdu->uci_harq_pdu.ue_information.ue_information_rel13.total_number_of_repetitions = pucchreps[UE_template->rach_resource_type - 1]; + ul_config_pdu->uci_harq_pdu.ue_information.ue_information_rel13.repetition_number = 0; + + if (cc[CC_id].tdd_Config == NULL) { // FDD case + ul_config_pdu->uci_harq_pdu.harq_information.harq_information_rel9_fdd.n_pucch_1_0 = n1pucchan[UE_template->rach_resource_type - 1]; + // NOTE: How to fill in the rest of the n_pucch_1_0 information 213 Section 10.1.2.1 in the general case + // = N_ECCE_q + Delta_ARO + n1pucchan[ce_level] + // higher in the MPDCCH configuration, N_ECCE_q is hard-coded to 0, and harq resource offset to 0 => + // Delta_ARO = 0 from Table 10.1.2.1-1 + ul_config_pdu->uci_harq_pdu.harq_information.harq_information_rel9_fdd.harq_size = 1; // 1-bit ACK/NAK + ul_config_pdu->uci_harq_pdu.harq_information.harq_information_rel9_fdd.number_of_pucch_resources = 1; + } else { + AssertFatal (1 == 0, "PUCCH configuration for ACK/NAK not handled yet for TDD BL/CE case\n"); + } + ul_req->number_of_pdus++; - T (T_ENB_MAC_UE_DL_PDU_WITH_DATA, T_INT (module_idP), T_INT (CC_id), T_INT (rnti), T_INT (frameP), T_INT (subframeP), - T_INT (0 /*harq_pid always 0? */ ), T_BUFFER (&mac->UE_list.DLSCH_pdu[CC_id][0][UE_id].payload[0], TX_req->pdu_length)); + + T(T_ENB_MAC_UE_DL_PDU_WITH_DATA, + T_INT (module_idP), + T_INT (CC_id), + T_INT (rnti), + T_INT (frameP), + T_INT (subframeP), + T_INT (0 /* harq_pid always 0? */ ), + T_BUFFER (&mac->UE_list.DLSCH_pdu[CC_id][0][UE_id].payload[0], TX_req->pdu_length)); if (opt_enabled == 1) { - trace_pdu (1, (uint8_t *) mac->UE_list.DLSCH_pdu[CC_id][0][(unsigned char) UE_id].payload[0], TX_req->pdu_length , UE_id, 3, rnti, frameP, subframeP, 0, 0); - LOG_D (OPT, "[eNB %d][DLSCH] CC_id %d Frame %d trace pdu for rnti %x with size %d\n", module_idP, CC_id, frameP, rnti, TX_req->pdu_length ); + trace_pdu(1, + (uint8_t *) mac->UE_list.DLSCH_pdu[CC_id][0][(unsigned char) UE_id].payload[0], + TX_req->pdu_length, + UE_id, + 3, + rnti, + frameP, + subframeP, + 0, + 0); + + LOG_D(OPT, "[eNB %d][DLSCH] CC_id %d Frame %d trace pdu for rnti %x with size %d\n", + module_idP, + CC_id, + frameP, + rnti, + TX_req->pdu_length); } - - } - } - + } // end else if ((subframeP == 7) && (round_DL < 8)) + } // end loop on UE_id } #endif //------------------------------------------------------------------------------ void fill_DLSCH_dci(module_id_t module_idP, - frame_t frameP, sub_frame_t subframeP, int *mbsfn_flagP) + frame_t frameP, + sub_frame_t subframeP, + int *mbsfn_flagP) //------------------------------------------------------------------------------ { // loop over all allocated UEs and compute frequency allocations for PDSCH @@ -3313,12 +2618,16 @@ fill_DLSCH_dci(module_id_t module_idP, int N_RBG; int N_RB_DL; COMMON_channels_t *cc; + eNB_DLSCH_INFO *dlsch_info; + UE_TEMPLATE *ue_template; + start_meas(&eNB->fill_DLSCH_dci); - VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME - (VCD_SIGNAL_DUMPER_FUNCTIONS_FILL_DLSCH_DCI, VCD_FUNCTION_IN); + VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_FILL_DLSCH_DCI, + VCD_FUNCTION_IN); for (CC_id = 0; CC_id < RC.nb_mac_CC[module_idP]; CC_id++) { - LOG_D(MAC, "Doing fill DCI for CC_id %d\n", CC_id); + LOG_D(MAC, "Doing fill DCI for CC_id %d\n", + CC_id); if (mbsfn_flagP[CC_id] > 0) continue; @@ -3328,42 +2637,48 @@ fill_DLSCH_dci(module_id_t module_idP, N_RB_DL = to_prb(cc->mib->message.dl_Bandwidth); // UE specific DCIs - for (UE_id = UE_list->head; UE_id >= 0; - UE_id = UE_list->next[UE_id]) { - LOG_T(MAC, "CC_id %d, UE_id: %d => status %d\n", CC_id, UE_id, - eNB_dlsch_info[module_idP][CC_id][UE_id].status); + for (UE_id = UE_list->head; UE_id >= 0; UE_id = UE_list->next[UE_id]) { + dlsch_info = &eNB_dlsch_info[module_idP][CC_id][UE_id]; + LOG_T(MAC, "CC_id %d, UE_id: %d => status %d\n", + CC_id, + UE_id, + dlsch_info->status); - if (eNB_dlsch_info[module_idP][CC_id][UE_id].status == S_DL_SCHEDULED) { + if (dlsch_info->status == S_DL_SCHEDULED) { // clear scheduling flag - eNB_dlsch_info[module_idP][CC_id][UE_id].status = S_DL_WAITING; + dlsch_info->status = S_DL_WAITING; rnti = UE_RNTI(module_idP, UE_id); - harq_pid = frame_subframe2_dl_harq_pid(cc->tdd_Config,frameP,subframeP); - nb_rb = UE_list->UE_template[CC_id][UE_id].nb_rb[harq_pid]; + harq_pid = frame_subframe2_dl_harq_pid(cc->tdd_Config,frameP, + subframeP); + ue_template = &UE_list->UE_template[CC_id][UE_id]; + nb_rb = ue_template->nb_rb[harq_pid]; /// Synchronizing rballoc with rballoc_sub for (i = 0; i < N_RBG; i++) { - rballoc_sub[i] = UE_list->UE_template[CC_id][UE_id].rballoc_subband[harq_pid][i]; + rballoc_sub[i] = ue_template->rballoc_subband[harq_pid][i]; } - nfapi_dl_config_request_t *DL_req = &RC.mac[module_idP]->DL_req[0]; + nfapi_dl_config_request_body_t *dl_config_request_body = &RC.mac[module_idP]->DL_req[CC_id].dl_config_request_body; nfapi_dl_config_request_pdu_t *dl_config_pdu; - for (i = 0; - i < DL_req[CC_id].dl_config_request_body.number_pdu; - i++) { - dl_config_pdu = &DL_req[CC_id].dl_config_request_body.dl_config_pdu_list[i]; + for (i = 0; i < dl_config_request_body->number_pdu; i++) { + dl_config_pdu = &dl_config_request_body->dl_config_pdu_list[i]; - if ((dl_config_pdu->pdu_type == NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE) - && (dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti == rnti) - && (dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.dci_format != 1)) { - dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.resource_block_coding = allocate_prbs_sub(nb_rb, N_RB_DL, N_RBG, - rballoc_sub); + if (dl_config_pdu->pdu_type == NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE && + dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti == rnti && + dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.dci_format != 1) { + dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.resource_block_coding = allocate_prbs_sub(nb_rb, + N_RB_DL, + N_RBG, + rballoc_sub); dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.resource_allocation_type = 0; - } else if ((dl_config_pdu->pdu_type == NFAPI_DL_CONFIG_DLSCH_PDU_TYPE) - && (dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.rnti == rnti) - && (dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.resource_allocation_type == 0)) { - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.resource_block_coding = allocate_prbs_sub(nb_rb, N_RB_DL, N_RBG, - rballoc_sub); + } else if (dl_config_pdu->pdu_type == NFAPI_DL_CONFIG_DLSCH_PDU_TYPE && + dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.rnti == rnti && + dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.resource_allocation_type == 0) { + dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.resource_block_coding = allocate_prbs_sub(nb_rb, + N_RB_DL, + N_RBG, + rballoc_sub); } } } @@ -3371,12 +2686,15 @@ fill_DLSCH_dci(module_id_t module_idP, } stop_meas(&eNB->fill_DLSCH_dci); - VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_FILL_DLSCH_DCI, VCD_FUNCTION_OUT); + VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_FILL_DLSCH_DCI, + VCD_FUNCTION_OUT); } //------------------------------------------------------------------------------ unsigned char *get_dlsch_sdu(module_id_t module_idP, - int CC_id, frame_t frameP, rnti_t rntiP, + int CC_id, + frame_t frameP, + rnti_t rntiP, uint8_t TBindex) //------------------------------------------------------------------------------ { @@ -3385,96 +2703,106 @@ unsigned char *get_dlsch_sdu(module_id_t module_idP, if (rntiP == SI_RNTI) { LOG_D(MAC, "[eNB %d] CC_id %d Frame %d Get DLSCH sdu for BCCH \n", - module_idP, CC_id, frameP); + module_idP, + CC_id, + frameP); return ((unsigned char *) &eNB->common_channels[CC_id].BCCH_pdu.payload[0]); } if (rntiP == P_RNTI) { - LOG_D(MAC, "[eNB %d] CC_id %d Frame %d Get PCH sdu for PCCH \n", module_idP, CC_id, frameP); + LOG_D(MAC, "[eNB %d] CC_id %d Frame %d Get PCH sdu for PCCH \n", + module_idP, + CC_id, + frameP); return ((unsigned char *) &eNB->common_channels[CC_id].PCCH_pdu.payload[0]); } UE_id = find_UE_id(module_idP, rntiP); if (UE_id != -1) { - LOG_D(MAC, - "[eNB %d] Frame %d: CC_id %d Get DLSCH sdu for rnti %x => UE_id %d\n", - module_idP, frameP, CC_id, rntiP, UE_id); + LOG_D(MAC, "[eNB %d] Frame %d: CC_id %d Get DLSCH sdu for rnti %x => UE_id %d\n", + module_idP, + frameP, + CC_id, + rntiP, + UE_id); return ((unsigned char *) &eNB->UE_list.DLSCH_pdu[CC_id][TBindex][UE_id].payload[0]); - } else { - LOG_E(MAC, - "[eNB %d] Frame %d: CC_id %d UE with RNTI %x does not exist\n", - module_idP, frameP, CC_id, rntiP); - return NULL; - } + } + + LOG_E(MAC, "[eNB %d] Frame %d: CC_id %d UE with RNTI %x does not exist\n", + module_idP, + frameP, + CC_id, + rntiP); + return NULL; } //------------------------------------------------------------------------------ void update_ul_dci(module_id_t module_idP, - uint8_t CC_idP, rnti_t rntiP, uint8_t daiP, sub_frame_t subframe) + uint8_t CC_idP, + rnti_t rntiP, + uint8_t daiP, + sub_frame_t subframe) //------------------------------------------------------------------------------ { - nfapi_hi_dci0_request_t *HI_DCI0_req = - &RC.mac[module_idP]->HI_DCI0_req[CC_idP][subframe]; - nfapi_hi_dci0_request_pdu_t *hi_dci0_pdu = - &HI_DCI0_req->hi_dci0_request_body.hi_dci0_pdu_list[0]; - COMMON_channels_t *cc = &RC.mac[module_idP]->common_channels[CC_idP]; - int i; - + eNB_MAC_INST *eNB = RC.mac[module_idP]; + COMMON_channels_t *cc = &eNB->common_channels[CC_idP]; + if (cc->tdd_Config != NULL) { // TDD - for (i = 0; - i hi_dci0_request_body.number_of_dci + HI_DCI0_req->hi_dci0_request_body.number_of_hi; - i++) { - if ((hi_dci0_pdu[i].pdu_type == NFAPI_HI_DCI0_DCI_PDU_TYPE) && - (hi_dci0_pdu[i].dci_pdu.dci_pdu_rel8.rnti == rntiP)) - hi_dci0_pdu[i].dci_pdu.dci_pdu_rel8.dl_assignment_index = (daiP - 1) & 3; + nfapi_hi_dci0_request_t *HI_DCI0_req = &eNB->HI_DCI0_req[CC_idP][subframe]; + nfapi_hi_dci0_request_pdu_t *hi_dci0_pdu = &HI_DCI0_req->hi_dci0_request_body.hi_dci0_pdu_list[0]; + int limit = HI_DCI0_req->hi_dci0_request_body.number_of_dci + HI_DCI0_req->hi_dci0_request_body.number_of_hi; + for (int i = 0; i < limit; i++, hi_dci0_pdu++) { + if (hi_dci0_pdu->pdu_type == NFAPI_HI_DCI0_DCI_PDU_TYPE && hi_dci0_pdu->dci_pdu.dci_pdu_rel8.rnti == rntiP) + hi_dci0_pdu->dci_pdu.dci_pdu_rel8.dl_assignment_index = (daiP - 1) & 3; } } + return; } //------------------------------------------------------------------------------ void set_ue_dai(sub_frame_t subframeP, - int UE_id, uint8_t CC_id, uint8_t tdd_config, + int UE_id, + uint8_t CC_id, + uint8_t tdd_config, UE_list_t *UE_list) //------------------------------------------------------------------------------ { switch (tdd_config) { case 0: - if ((subframeP == 0) || (subframeP == 1) || (subframeP == 3) - || (subframeP == 5) || (subframeP == 6) || (subframeP == 8)) { + if (subframeP == 0 || subframeP == 1 || subframeP == 3 || subframeP == 5 || subframeP == 6 || subframeP == 8) { UE_list->UE_template[CC_id][UE_id].DAI = 0; } break; case 1: - if ((subframeP == 0) || (subframeP == 4) || (subframeP == 5) - || (subframeP == 9)) { + if (subframeP == 0 || subframeP == 4 || subframeP == 5 || subframeP == 9) { UE_list->UE_template[CC_id][UE_id].DAI = 0; } break; case 2: - if ((subframeP == 4) || (subframeP == 5)) { + if (subframeP == 4 || subframeP == 5) { UE_list->UE_template[CC_id][UE_id].DAI = 0; } break; case 3: - if ((subframeP == 5) || (subframeP == 7) || (subframeP == 9)) { + if (subframeP == 5 || subframeP == 7 || subframeP == 9) { UE_list->UE_template[CC_id][UE_id].DAI = 0; } break; case 4: - if ((subframeP == 0) || (subframeP == 6)) { + if (subframeP == 0 || subframeP == 6) { UE_list->UE_template[CC_id][UE_id].DAI = 0; } @@ -3488,8 +2816,7 @@ set_ue_dai(sub_frame_t subframeP, break; case 6: - if ((subframeP == 0) || (subframeP == 1) || (subframeP == 5) - || (subframeP == 6) || (subframeP == 9)) { + if (subframeP == 0 || subframeP == 1 || subframeP == 5 || subframeP == 6 || subframeP == 9) { UE_list->UE_template[CC_id][UE_id].DAI = 0; } @@ -3497,12 +2824,19 @@ set_ue_dai(sub_frame_t subframeP, default: UE_list->UE_template[CC_id][UE_id].DAI = 0; - LOG_I(MAC, "unknown TDD config %d\n", tdd_config); + LOG_I(MAC, "unknown TDD config %d\n", + tdd_config); break; } + + return; } -void schedule_PCH(module_id_t module_idP, frame_t frameP, sub_frame_t subframeP) { +void +schedule_PCH(module_id_t module_idP, + frame_t frameP, + sub_frame_t subframeP) +{ /* DCI:format 1A/1C P-RNTI:0xFFFE */ /* PDU:eNB_rrc_inst[Mod_idP].common_channels[CC_id].PCCH_pdu.payload */ uint16_t pcch_sdu_length; @@ -3516,9 +2850,10 @@ void schedule_PCH(module_id_t module_idP, frame_t frameP, sub_frame_t subframeP) nfapi_dl_config_request_pdu_t *dl_config_pdu; nfapi_tx_request_pdu_t *TX_req; nfapi_dl_config_request_body_t *dl_req; + UE_PF_PO_t *ue_pf_po; #ifdef FORMAT1C - int gap_index = 0; /* indicate which gap(1st or 2nd) is used (0:1st) */ - const int GAP_MAP [9][2] = { + int gap_index = 0; /* indicate which gap(1st or 2nd) is used (0:1st) */ + const int GAP_MAP [9][2] = { {-1, 0}, /* N_RB_DL [6-10] -1: |N_RB/2| 0: N/A*/ {4, 0}, /* N_RB_DL [11] */ {8, 0}, /* N_RB_DL [12-19] */ @@ -3529,12 +2864,13 @@ void schedule_PCH(module_id_t module_idP, frame_t frameP, sub_frame_t subframeP) {32, 16}, /* N_RB_DL [64-79] */ {48, 16} /* N_RB_DL [80-110] */ }; - uint8_t n_rb_step = 0; - uint8_t n_gap = 0; - uint8_t n_vrb_dl = 0; - uint8_t Lcrbs = 0; - uint16_t rb_bit = 168; /* RB bit number value is unsure */ + uint8_t n_rb_step = 0; + uint8_t n_gap = 0; + uint8_t n_vrb_dl = 0; + uint8_t Lcrbs = 0; + uint16_t rb_bit = 168; /* RB bit number value is unsure */ #endif + start_meas(&eNB->schedule_pch); for (CC_id = 0; CC_id < RC.nb_mac_CC[module_idP]; CC_id++) { @@ -3544,27 +2880,37 @@ void schedule_PCH(module_id_t module_idP, frame_t frameP, sub_frame_t subframeP) dl_req = &eNB->DL_req[CC_id].dl_config_request_body; for (uint16_t i = 0; i < MAX_MOBILES_PER_ENB; i++) { - if (UE_PF_PO[CC_id][i].enable_flag != TRUE) { + ue_pf_po = &UE_PF_PO[CC_id][i]; + if (ue_pf_po->enable_flag != TRUE) { continue; } - if (frameP % UE_PF_PO[CC_id][i].T == UE_PF_PO[CC_id][i].PF_min && subframeP == UE_PF_PO[CC_id][i].PO) { + if (frameP % ue_pf_po->T == ue_pf_po->PF_min && subframeP == ue_pf_po->PO) { pcch_sdu_length = mac_rrc_data_req(module_idP, CC_id, frameP, - PCCH, 1, + PCCH, + 1, &cc->PCCH_pdu.payload[0], i); // used for ue index if (pcch_sdu_length == 0) { - LOG_D(MAC, "[eNB %d] Frame %d subframe %d: PCCH not active(size = 0 byte)\n", module_idP, frameP, subframeP); + LOG_D(MAC, "[eNB %d] Frame %d subframe %d: PCCH not active(size = 0 byte)\n", + module_idP, + frameP, + subframeP); continue; } - LOG_D(MAC, "[eNB %d] Frame %d subframe %d: PCCH->PCH CC_id %d UE_id %d, Received %d bytes \n", module_idP, - frameP, subframeP, CC_id, i, pcch_sdu_length); -#ifdef FORMAT1C + LOG_D(MAC, "[eNB %d] Frame %d subframe %d: PCCH->PCH CC_id %d UE_id %d, Received %d bytes \n", + module_idP, + frameP, + subframeP, + CC_id, + i, + pcch_sdu_length); +#ifdef FORMAT1C //NO SIB if ((subframeP == 0 || subframeP == 1 || subframeP == 2 || subframeP == 4 || subframeP == 6 || subframeP == 9) || (subframeP == 5 && ((frameP % 2) != 0 && (frameP % 8) != 1))) { @@ -3657,7 +3003,10 @@ void schedule_PCH(module_id_t module_idP, frame_t frameP, sub_frame_t subframeP) } else { /* unexpected: pcch sdb size is over max value*/ LOG_E(MAC,"[eNB %d] Frame %d : PCCH->PCH CC_id %d, Received %d bytes is over max length(256) \n", - module_idP, frameP,CC_id, pcch_sdu_length); + module_idP, + frameP, + CC_id, + pcch_sdu_length); return; } @@ -3740,7 +3089,9 @@ void schedule_PCH(module_id_t module_idP, frame_t frameP, sub_frame_t subframeP) #endif dl_config_pdu = &dl_req->dl_config_pdu_list[dl_req->number_pdu]; - memset((void *) dl_config_pdu, 0, sizeof(nfapi_dl_config_request_pdu_t)); + memset((void *) dl_config_pdu, + 0, + sizeof(nfapi_dl_config_request_pdu_t)); dl_config_pdu->pdu_type = NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE; dl_config_pdu->pdu_size = (uint8_t) (2 + sizeof(nfapi_dl_config_dci_dl_pdu)); #ifdef FORMAT1C @@ -3748,12 +3099,14 @@ void schedule_PCH(module_id_t module_idP, frame_t frameP, sub_frame_t subframeP) dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.resource_block_coding = getRIV(n_vrb_dl/n_rb_step, first_rb/n_rb_step, Lcrbs/n_rb_step); dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.ngap = n_gap; #else - dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.dci_format = NFAPI_DL_DCI_FORMAT_1A; - dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.harq_process = 0; - dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.tpc = 1; // no TPC - dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.new_data_indicator_1 = 1; - dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.redundancy_version_1 = 1; - dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.resource_block_coding = getRIV(n_rb_dl, first_rb, 4); + dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.dci_format = NFAPI_DL_DCI_FORMAT_1A; + dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.harq_process = 0; + dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.tpc = 1; // no TPC + dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.new_data_indicator_1 = 1; + dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.redundancy_version_1 = 1; + dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.resource_block_coding = getRIV(n_rb_dl, + first_rb, + 4); dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.virtual_resource_block_assignment_flag = 0; #endif dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level = 4; @@ -3762,25 +3115,39 @@ void schedule_PCH(module_id_t module_idP, frame_t frameP, sub_frame_t subframeP) dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.transmission_power = 6000; // equal to RS power dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.mcs_1 = mcs; - if (!CCE_allocation_infeasible(module_idP, CC_id, 0, subframeP, dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level, P_RNTI)) { - LOG_D(MAC,"Frame %d: Subframe %d : Adding common DCI for P_RNTI\n", frameP,subframeP); + if (!CCE_allocation_infeasible(module_idP, + CC_id, + 0, + subframeP, + dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level, + P_RNTI)) { + LOG_D(MAC,"Frame %d: Subframe %d : Adding common DCI for P_RNTI\n", + frameP, + subframeP); dl_req->number_dci++; dl_req->number_pdu++; dl_req->tl.tag = NFAPI_DL_CONFIG_REQUEST_BODY_TAG; eNB->DL_req[CC_id].sfn_sf = frameP<<4 | subframeP; eNB->DL_req[CC_id].header.message_id = NFAPI_DL_CONFIG_REQUEST; + dl_config_pdu = &dl_req->dl_config_pdu_list[dl_req->number_pdu]; - memset((void *)dl_config_pdu,0,sizeof(nfapi_dl_config_request_pdu_t)); + memset((void *)dl_config_pdu, + 0, + sizeof(nfapi_dl_config_request_pdu_t)); dl_config_pdu->pdu_type = NFAPI_DL_CONFIG_DLSCH_PDU_TYPE; - dl_config_pdu->pdu_size = (uint8_t)(2+sizeof(nfapi_dl_config_dlsch_pdu)); + dl_config_pdu->pdu_size = (uint8_t)(2 + sizeof(nfapi_dl_config_dlsch_pdu)); dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.pdu_index = eNB->pdu_index[CC_id]; dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.rnti = 0xFFFE; #ifdef FORMAT1C dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.resource_allocation_type = 3; // format 1C - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.resource_block_coding = getRIV(n_vrb_dl/n_rb_step, first_rb/n_rb_step, Lcrbs/n_rb_step); + dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.resource_block_coding = getRIV(n_vrb_dl / n_rb_step, + first_rb / n_rb_step, + Lcrbs / n_rb_step); #else - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.resource_allocation_type = 2; // format 1A/1B/1D - dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.resource_block_coding = getRIV(n_rb_dl, first_rb, 4); + dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.resource_allocation_type = 2; // format 1A/1B/1D + dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.resource_block_coding = getRIV(n_rb_dl, + first_rb, + 4); dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.virtual_resource_block_assignment_flag = 0; // localized #endif dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.modulation = 2; //QPSK @@ -3811,17 +3178,21 @@ void schedule_PCH(module_id_t module_idP, frame_t frameP, sub_frame_t subframeP) dl_config_pdu->dlsch_pdu.dlsch_pdu_rel13.initial_transmission_sf_io = 0xFFFF; #endif dl_req->number_pdu++; - eNB->TX_req[CC_id].sfn_sf = (frameP<<4)+subframeP; - TX_req = &eNB->TX_req[CC_id].tx_request_body.tx_pdu_list[eNB->TX_req[CC_id].tx_request_body.number_of_pdus]; + eNB->TX_req[CC_id].sfn_sf = (frameP<<4)+subframeP; + TX_req = &eNB->TX_req[CC_id].tx_request_body.tx_pdu_list[eNB->TX_req[CC_id].tx_request_body.number_of_pdus]; TX_req->pdu_length = pcch_sdu_length; TX_req->pdu_index = eNB->pdu_index[CC_id]++; TX_req->num_segments = 1; TX_req->segments[0].segment_length = pcch_sdu_length; TX_req->segments[0].segment_data = cc[CC_id].PCCH_pdu.payload; - eNB->TX_req[CC_id].tx_request_body.tl.tag = NFAPI_TX_REQUEST_BODY_TAG; + eNB->TX_req[CC_id].tx_request_body.tl.tag = NFAPI_TX_REQUEST_BODY_TAG; eNB->TX_req[CC_id].tx_request_body.number_of_pdus++; } else { - LOG_E(MAC,"[eNB %d] CCid %d Frame %d, subframe %d : Cannot add DCI 1A/1C for Paging\n",module_idP, CC_id, frameP, subframeP); + LOG_E(MAC,"[eNB %d] CCid %d Frame %d, subframe %d : Cannot add DCI 1A/1C for Paging\n", + module_idP, + CC_id, + frameP, + subframeP); continue; } @@ -3837,18 +3208,30 @@ void schedule_PCH(module_id_t module_idP, frame_t frameP, sub_frame_t subframeP) 0, 0); LOG_D(OPT,"[eNB %d][PCH] Frame %d trace pdu for CC_id %d rnti %x with size %d\n", - module_idP, frameP, CC_id, 0xffff, pcch_sdu_length); + module_idP, + frameP, + CC_id, + 0xffff, + pcch_sdu_length); } - eNB->eNB_stats[CC_id].total_num_pcch_pdu+=1; - eNB->eNB_stats[CC_id].pcch_buffer=pcch_sdu_length; - eNB->eNB_stats[CC_id].total_pcch_buffer+=pcch_sdu_length; - eNB->eNB_stats[CC_id].pcch_mcs=mcs; + eNB->eNB_stats[CC_id].total_num_pcch_pdu++; + eNB->eNB_stats[CC_id].pcch_buffer = pcch_sdu_length; + eNB->eNB_stats[CC_id].total_pcch_buffer += pcch_sdu_length; + eNB->eNB_stats[CC_id].pcch_mcs = mcs; //paging first_rb log LOG_D(MAC,"[eNB %d] Frame %d subframe %d PCH: paging_ue_index %d pcch_sdu_length %d mcs %d first_rb %d\n", - module_idP, frameP, subframeP, UE_PF_PO[CC_id][i].ue_index_value, pcch_sdu_length, mcs, first_rb); + module_idP, + frameP, + subframeP, + ue_pf_po->ue_index_value, + pcch_sdu_length, + mcs, + first_rb); pthread_mutex_lock(&ue_pf_po_mutex); - memset(&UE_PF_PO[CC_id][i], 0, sizeof(UE_PF_PO_t)); + memset(ue_pf_po, + 0, + sizeof(UE_PF_PO_t)); pthread_mutex_unlock(&ue_pf_po_mutex); } } @@ -3859,7 +3242,11 @@ void schedule_PCH(module_id_t module_idP, frame_t frameP, sub_frame_t subframeP) return; } -static int slice_priority_compare(const void *_a, const void *_b, void *_c) { +static int +slice_priority_compare(const void *_a, + const void *_b, + void *_c) +{ const int slice_id1 = *(const int *) _a; const int slice_id2 = *(const int *) _b; const module_id_t Mod_id = *(int *) _c; @@ -3872,13 +3259,20 @@ static int slice_priority_compare(const void *_a, const void *_b, void *_c) { return 1; } -void slice_priority_sort(module_id_t Mod_id, int slice_list[MAX_NUM_SLICES]) { +void +slice_priority_sort(module_id_t Mod_id, + int slice_list[MAX_NUM_SLICES]) +{ int i; - - for (i = 0; i < RC.mac[Mod_id]->slice_info.n_dl; ++i) { + int n_dl = RC.mac[Mod_id]->slice_info.n_dl; + for (i = 0; i < n_dl; i++) { slice_list[i] = i; } - qsort_r(slice_list, RC.mac[Mod_id]->slice_info.n_dl, sizeof(int), - slice_priority_compare, &Mod_id); + qsort_r(slice_list, + n_dl, + sizeof(int), + slice_priority_compare, + &Mod_id); + return; } diff --git a/openair2/LAYER2/MAC/eNB_scheduler_fairRR.c b/openair2/LAYER2/MAC/eNB_scheduler_fairRR.c index b612700889..db98335527 100644 --- a/openair2/LAYER2/MAC/eNB_scheduler_fairRR.c +++ b/openair2/LAYER2/MAC/eNB_scheduler_fairRR.c @@ -295,7 +295,8 @@ void dlsch_scheduler_pre_ue_select_fairRR( CC_id, UE_id, subframeP, - S_DL_NONE); + S_DL_NONE, + rnti); end_flag[CC_id] = 1; break; } @@ -418,7 +419,8 @@ void dlsch_scheduler_pre_ue_select_fairRR( CC_id, UE_id, subframeP, - S_DL_NONE); + S_DL_NONE, + rnti); end_flag[CC_id] = 1; break; } @@ -541,7 +543,8 @@ void dlsch_scheduler_pre_ue_select_fairRR( CC_id, UE_id, subframeP, - S_DL_NONE); + S_DL_NONE, + rnti); end_flag[CC_id] = 1; break; } @@ -810,7 +813,8 @@ schedule_ue_spec_fairRR(module_id_t module_idP, unsigned char ta_len = 0; unsigned char sdu_lcids[NB_RB_MAX], lcid, offset, num_sdus = 0; uint16_t nb_rb, nb_rb_temp, nb_available_rb; - uint16_t TBS, j, sdu_lengths[NB_RB_MAX], rnti, padding = 0, post_padding = 0; + uint16_t TBS, j, sdu_lengths[NB_RB_MAX], padding = 0, post_padding = 0; + rnti_t rnti = 0; unsigned char dlsch_buffer[MAX_DLSCH_PAYLOAD_BYTES]; unsigned char round = 0; unsigned char harq_pid = 0; @@ -1215,8 +1219,11 @@ schedule_ue_spec_fairRR(module_id_t module_idP, } add_ue_dlsch_info(module_idP, - CC_id, UE_id, subframeP, - S_DL_SCHEDULED); + CC_id, + UE_id, + subframeP, + S_DL_SCHEDULED, + rnti); //eNB_UE_stats->dlsch_trials[round]++; UE_list->eNB_UE_stats[CC_id][UE_id]. num_retransmission += 1; @@ -1678,10 +1685,10 @@ schedule_ue_spec_fairRR(module_id_t module_idP, if (opt_enabled == 1) { trace_pdu(DIRECTION_DOWNLINK, (uint8_t *)UE_list->DLSCH_pdu[CC_id][0][UE_id].payload[0], - TBS, module_idP, WS_RA_RNTI, UE_RNTI(module_idP,UE_id), + TBS, module_idP, WS_RA_RNTI, UE_RNTI(module_idP, UE_id), eNB->frame, eNB->subframe,0,0); LOG_D(OPT,"[eNB %d][DLSCH] CC_id %d Frame %d rnti %x with size %d\n", - module_idP, CC_id, frameP, UE_RNTI(module_idP,UE_id), TBS); + module_idP, CC_id, frameP, UE_RNTI(module_idP, UE_id), TBS); } T(T_ENB_MAC_UE_DL_PDU_WITH_DATA, T_INT(module_idP), T_INT(CC_id), T_INT(rnti), T_INT(frameP), T_INT(subframeP), @@ -1691,7 +1698,8 @@ schedule_ue_spec_fairRR(module_id_t module_idP, CC_id, UE_id, subframeP, - S_DL_SCHEDULED); + S_DL_SCHEDULED, + rnti); // store stats eNB->eNB_stats[CC_id].dlsch_bytes_tx+=sdu_length_total; eNB->eNB_stats[CC_id].dlsch_pdus_tx+=1; diff --git a/openair2/LAYER2/MAC/eNB_scheduler_primitives.c b/openair2/LAYER2/MAC/eNB_scheduler_primitives.c index deb766e7fe..219b288fd3 100644 --- a/openair2/LAYER2/MAC/eNB_scheduler_primitives.c +++ b/openair2/LAYER2/MAC/eNB_scheduler_primitives.c @@ -63,7 +63,12 @@ extern uint16_t frame_cnt; extern RAN_CONTEXT_t RC; extern uint8_t nfapi_mode; -int choose(int n, int k) { +//------------------------------------------------------------------------------ +int +choose(int n, + int k) +//------------------------------------------------------------------------------ +{ int res = 1; int res2 = 1; int i; @@ -83,8 +88,14 @@ int choose(int n, int k) { return (res / res2); } +//------------------------------------------------------------------------------ // Patented algorithm from Yang et al, US Patent 2009, "Channel Quality Indexing and Reverse Indexing" -void reverse_index(int N, int M, int r, int *v) { +void reverse_index(int N, + int M, + int r, + int *v) +//------------------------------------------------------------------------------ +{ int BaseValue = 0; int IncreaseValue, ThresholdValue; int sumV; @@ -95,66 +106,90 @@ void reverse_index(int N, int M, int r, int *v) { i = M; while (i > 0 && r > 0) { - IncreaseValue = choose(N - M + 1 - sumV - v[i - 1] + i - 2, i - 1); + IncreaseValue = choose(N - M + 1 - sumV - v[i - 1] + i - 2, + i - 1); ThresholdValue = BaseValue + IncreaseValue; if (r >= ThresholdValue) { v[i - 1]++; BaseValue = ThresholdValue; } else { - r = r - BaseValue; - sumV += v[i - 1]; - i--; + r -= BaseValue; + sumV += v[--i]; BaseValue = 0; } } } -int to_prb(int dl_Bandwidth) { +//------------------------------------------------------------------------------ +int +to_prb(int dl_Bandwidth) +//------------------------------------------------------------------------------ +{ int prbmap[6] = { 6, 15, 25, 50, 75, 100 }; AssertFatal(dl_Bandwidth < 6, "dl_Bandwidth is 0..5\n"); return (prbmap[dl_Bandwidth]); } -int to_rbg(int dl_Bandwidth) { +//------------------------------------------------------------------------------ +int +to_rbg(int dl_Bandwidth) +//------------------------------------------------------------------------------ +{ int rbgmap[6] = { 6, 8, 13, 17, 19, 25 }; AssertFatal(dl_Bandwidth < 6, "dl_Bandwidth is 0..5\n"); return (rbgmap[dl_Bandwidth]); } -int get_phich_resource_times6(COMMON_channels_t *cc) { +//------------------------------------------------------------------------------ +int +get_phich_resource_times6(COMMON_channels_t *cc) +//------------------------------------------------------------------------------ +{ int phichmap[4] = { 1, 3, 6, 12 }; AssertFatal(cc != NULL, "cc is null\n"); AssertFatal(cc->mib != NULL, "cc->mib is null\n"); - AssertFatal((cc->mib->message.phich_Config.phich_Resource >= 0) && - (cc->mib->message.phich_Config.phich_Resource < 4), - "phich_Resource %d not in 0..3\n", - (int) cc->mib->message.phich_Config.phich_Resource); - return (phichmap[cc->mib->message.phich_Config.phich_Resource]); + int phich_Resource = (int) cc->mib->message.phich_Config.phich_Resource; + AssertFatal(phich_Resource >= 0 && phich_Resource < 4, "phich_Resource %d not in 0..3\n", + phich_Resource); + return (phichmap[phich_Resource]); } -uint16_t mac_computeRIV(uint16_t N_RB_DL, uint16_t RBstart, uint16_t Lcrbs) { - uint16_t RIV; - - if (Lcrbs <= (1 + (N_RB_DL >> 1))) RIV = (N_RB_DL * (Lcrbs - 1)) + RBstart; - else RIV = (N_RB_DL * (N_RB_DL + 1 - Lcrbs)) + (N_RB_DL - 1 - RBstart); - - return (RIV); +//------------------------------------------------------------------------------ +uint16_t +mac_computeRIV(uint16_t N_RB_DL, + uint16_t RBstart, + uint16_t Lcrbs) +//------------------------------------------------------------------------------ +{ + if (Lcrbs <= (1 + (N_RB_DL >> 1))) { + return (N_RB_DL * (Lcrbs - 1)) + RBstart; + } + return (N_RB_DL * (N_RB_DL + 1 - Lcrbs)) + (N_RB_DL - 1 - RBstart); } -uint8_t getQm(uint8_t mcs) { +//------------------------------------------------------------------------------ +uint8_t +getQm(uint8_t mcs) +//------------------------------------------------------------------------------ +{ if (mcs < 10) return (2); else if (mcs < 17) return (4); - else return (6); + return (6); } +//------------------------------------------------------------------------------ void get_Msg3alloc(COMMON_channels_t *cc, sub_frame_t current_subframe, frame_t current_frame, frame_t *frame, - sub_frame_t *subframe) { + sub_frame_t *subframe) +//------------------------------------------------------------------------------ +{ // Fill in other TDD Configuration!!!! + int subframeAssignment; + if (cc->tdd_Config == NULL) { // FDD *subframe = current_subframe + 6; @@ -165,7 +200,8 @@ get_Msg3alloc(COMMON_channels_t *cc, *frame = current_frame; } } else { // TDD - if (cc->tdd_Config->subframeAssignment == 1) { + subframeAssignment = (int) cc->tdd_Config->subframeAssignment; + if (subframeAssignment == 1) { switch (current_subframe) { case 0: *subframe = 7; @@ -187,7 +223,7 @@ get_Msg3alloc(COMMON_channels_t *cc, *frame = (current_frame + 1) & 1023; break; } - } else if (cc->tdd_Config->subframeAssignment == 3) { + } else if (subframeAssignment == 3) { switch (current_subframe) { case 0: case 5: @@ -211,7 +247,7 @@ get_Msg3alloc(COMMON_channels_t *cc, *frame = (current_frame + 2) & 1023; break; } - } else if (cc->tdd_Config->subframeAssignment == 4) { + } else if (subframeAssignment == 4) { switch (current_subframe) { case 0: case 4: @@ -232,7 +268,7 @@ get_Msg3alloc(COMMON_channels_t *cc, *frame = (current_frame + 2) & 1023; break; } - } else if (cc->tdd_Config->subframeAssignment == 5) { + } else if (subframeAssignment == 5) { switch (current_subframe) { case 0: case 4: @@ -251,15 +287,20 @@ get_Msg3alloc(COMMON_channels_t *cc, } } } + return; } - - +//------------------------------------------------------------------------------ void get_Msg3allocret(COMMON_channels_t *cc, sub_frame_t current_subframe, frame_t current_frame, - frame_t *frame, sub_frame_t *subframe) { + frame_t *frame, + sub_frame_t *subframe) +//------------------------------------------------------------------------------ +{ + int subframeAssignment; + if (cc->tdd_Config == NULL) { //FDD /* always retransmit in n+8 */ *subframe = current_subframe + 8; @@ -271,32 +312,36 @@ get_Msg3allocret(COMMON_channels_t *cc, *frame = current_frame; } } else { - if (cc->tdd_Config->subframeAssignment == 1) { + subframeAssignment = (int) cc->tdd_Config->subframeAssignment; + if (subframeAssignment == 1) { // original PUSCH in 2, PHICH in 6 (S), ret in 2 // original PUSCH in 3, PHICH in 9, ret in 3 // original PUSCH in 7, PHICH in 1 (S), ret in 7 // original PUSCH in 8, PHICH in 4, ret in 8 *frame = (current_frame + 1) & 1023; - } else if (cc->tdd_Config->subframeAssignment == 3) { + } else if (subframeAssignment == 3) { // original PUSCH in 2, PHICH in 8, ret in 2 next frame // original PUSCH in 3, PHICH in 9, ret in 3 next frame // original PUSCH in 4, PHICH in 0, ret in 4 next frame *frame = (current_frame + 1) & 1023; - } else if (cc->tdd_Config->subframeAssignment == 4) { + } else if (subframeAssignment == 4) { // original PUSCH in 2, PHICH in 8, ret in 2 next frame // original PUSCH in 3, PHICH in 9, ret in 3 next frame *frame = (current_frame + 1) & 1023; - } else if (cc->tdd_Config->subframeAssignment == 5) { + } else if (subframeAssignment == 5) { // original PUSCH in 2, PHICH in 8, ret in 2 next frame *frame = (current_frame + 1) & 1023; } } + return; } +//------------------------------------------------------------------------------ uint8_t subframe2harqpid(COMMON_channels_t *cc, frame_t frame, sub_frame_t subframe) +//------------------------------------------------------------------------------ { uint8_t ret = 255; AssertFatal(cc != NULL, "cc is null\n"); @@ -306,72 +351,77 @@ subframe2harqpid(COMMON_channels_t *cc, } else { switch (cc->tdd_Config->subframeAssignment) { case 1: - switch (subframe) { - case 2: - case 3: - ret = (subframe - 2); - break; + if (subframe == 2 || subframe == 3 || subframe == 7 || subframe == 8) { + switch (subframe) { + case 2: + case 3: + ret = (subframe - 2); + break; - case 7: - case 8: - ret = (subframe - 5); - break; + case 7: + case 8: + ret = (subframe - 5); + break; - default: - AssertFatal(1 == 0, "subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n", - subframe, (int) cc->tdd_Config->subframeAssignment); - break; + default: + AssertFatal(1 == 0, "subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n", + subframe, + (int) cc->tdd_Config->subframeAssignment); + break; + } } break; case 2: - AssertFatal((subframe == 2) || (subframe == 7), - "subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n", - subframe, (int) cc->tdd_Config->subframeAssignment); + AssertFatal(subframe == 2 || subframe == 7, "subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n", + subframe, + (int) cc->tdd_Config->subframeAssignment); ret = (subframe / 7); break; case 3: - AssertFatal((subframe > 1) && (subframe < 5), - "subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n", - subframe, (int) cc->tdd_Config->subframeAssignment); + AssertFatal(subframe > 1 && subframe < 5, "subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n", + subframe, + (int) cc->tdd_Config->subframeAssignment); ret = (subframe - 2); break; case 4: - AssertFatal((subframe > 1) && (subframe < 4), - "subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n", - subframe, (int) cc->tdd_Config->subframeAssignment); + AssertFatal(subframe > 1 && subframe < 4, "subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n", + subframe, + (int) cc->tdd_Config->subframeAssignment); ret = (subframe - 2); break; case 5: - AssertFatal(subframe == 2, - "subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n", - subframe, (int) cc->tdd_Config->subframeAssignment); + AssertFatal(subframe == 2, "subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n", + subframe, + (int) cc->tdd_Config->subframeAssignment); ret = (subframe - 2); break; default: - AssertFatal(1 == 0, - "subframe2_harq_pid, Unsupported TDD mode %d\n", + AssertFatal(1 == 0, "subframe2_harq_pid, Unsupported TDD mode %d\n", (int) cc->tdd_Config->subframeAssignment); break; } } + return ret; } +//------------------------------------------------------------------------------ uint8_t get_Msg3harqpid(COMMON_channels_t *cc, - frame_t frame, sub_frame_t current_subframe) { + frame_t frame, + sub_frame_t current_subframe) +//------------------------------------------------------------------------------ +{ uint8_t ul_subframe = 0; uint32_t ul_frame = 0; if (cc->tdd_Config == NULL) { // FDD - ul_subframe = - (current_subframe > - 3) ? (current_subframe - 4) : (current_subframe + 6); + ul_subframe = (current_subframe > 3) ? (current_subframe - 4) : (current_subframe + 6); ul_frame = (current_subframe > 3) ? ((frame + 1) & 1023) : frame; } else { switch (cc->tdd_Config->subframeAssignment) { @@ -435,60 +485,80 @@ get_Msg3harqpid(COMMON_channels_t *cc, break; default: - LOG_E(PHY, - "get_Msg3_harq_pid: Unsupported TDD configuration %d\n", + LOG_E(PHY, "get_Msg3_harq_pid: Unsupported TDD configuration %d\n", (int) cc->tdd_Config->subframeAssignment); - AssertFatal(1 == 0, - "get_Msg3_harq_pid: Unsupported TDD configuration"); + AssertFatal(1 == 0, "get_Msg3_harq_pid: Unsupported TDD configuration"); break; } } - return (subframe2harqpid(cc, ul_frame, ul_subframe)); + return (subframe2harqpid(cc, + ul_frame, + ul_subframe)); } +//------------------------------------------------------------------------------ uint32_t -pdcchalloc2ulframe(COMMON_channels_t *ccP, uint32_t frame, uint8_t n) { - uint32_t ul_frame; +pdcchalloc2ulframe(COMMON_channels_t *ccP, + uint32_t frame, + uint8_t n) +//------------------------------------------------------------------------------ +{ + uint32_t ul_frame = (frame + (n >= 6 ? 1 : 0)); - if ((ccP->tdd_Config) && (ccP->tdd_Config->subframeAssignment == 1) && ((n == 1) || (n == 6))) // tdd_config 0,1 SF 1,5 - ul_frame = (frame + (n == 1 ? 0 : 1)); - else if ((ccP->tdd_Config) && - (ccP->tdd_Config->subframeAssignment == 6) && - ((n == 0) || (n == 1) || (n == 5) || (n == 6))) - ul_frame = (frame + (n >= 5 ? 1 : 0)); - else if ((ccP->tdd_Config) && (ccP->tdd_Config->subframeAssignment == 6) && (n == 9)) // tdd_config 6 SF 9 - ul_frame = (frame + 1); - else - ul_frame = (frame + (n >= 6 ? 1 : 0)); - - LOG_D(PHY, "frame %d subframe %d: PUSCH frame = %d\n", frame, n, + if (ccP->tdd_Config) { + if (ccP->tdd_Config->subframeAssignment == 1) { + if (n == 1 || n == 6) { + ul_frame = (frame + (n == 1 ? 0 : 1)); + } + } else if (ccP->tdd_Config->subframeAssignment == 6) { + if (n == 0 || n == 1 || n == 5 || n == 6) { + ul_frame = (frame + (n >= 5 ? 1 : 0)); + } else if (n == 9) { + ul_frame = (frame + 1); + } + } + } + LOG_D(PHY, "frame %d subframe %d: PUSCH frame = %d\n", + frame, + n, ul_frame); + return ul_frame; } -uint8_t pdcchalloc2ulsubframe(COMMON_channels_t *ccP, uint8_t n) { +//------------------------------------------------------------------------------ +uint8_t +pdcchalloc2ulsubframe(COMMON_channels_t *ccP, + uint8_t n) +//------------------------------------------------------------------------------ +{ uint8_t ul_subframe; - if ((ccP->tdd_Config) && (ccP->tdd_Config->subframeAssignment == 1) && ((n == 1) || (n == 6))) // tdd_config 0,1 SF 1,5 + if (ccP->tdd_Config && ccP->tdd_Config->subframeAssignment == 1 && (n == 1 || n == 6)) // tdd_config 0,1 SF 1,5 ul_subframe = ((n + 6) % 10); - else if ((ccP->tdd_Config) && - (ccP->tdd_Config->subframeAssignment == 6) && - ((n == 0) || (n == 1) || (n == 5) || (n == 6))) + else if (ccP->tdd_Config && ccP->tdd_Config->subframeAssignment == 6 && (n == 0 || n == 1 || n == 5 || n == 6)) ul_subframe = ((n + 7) % 10); - else if ((ccP->tdd_Config) && (ccP->tdd_Config->subframeAssignment == 6) && (n == 9)) // tdd_config 6 SF 9 + else if (ccP->tdd_Config && ccP->tdd_Config->subframeAssignment == 6 && n == 9) // tdd_config 6 SF 9 ul_subframe = ((n + 5) % 10); else ul_subframe = ((n + 4) % 10); - LOG_D(PHY, "subframe %d: PUSCH subframe = %d\n", n, ul_subframe); + LOG_D(PHY, "subframe %d: PUSCH subframe = %d\n", + n, + ul_subframe); return ul_subframe; } -int is_UL_sf(COMMON_channels_t *ccP, sub_frame_t subframeP) { +//------------------------------------------------------------------------------ +int +is_UL_sf(COMMON_channels_t *ccP, + sub_frame_t subframeP) +//------------------------------------------------------------------------------ +{ // if FDD return dummy value if (ccP->tdd_Config == NULL) - return (0); + return 0; switch (ccP->tdd_Config->subframeAssignment) { case 1: @@ -497,19 +567,16 @@ int is_UL_sf(COMMON_channels_t *ccP, sub_frame_t subframeP) { case 4: case 5: case 9: - return (0); - break; + return 0; case 2: case 3: case 7: case 8: - return (1); - break; + return 1; default: - return (0); - break; + return 0; } break; @@ -550,34 +617,43 @@ int is_UL_sf(COMMON_channels_t *ccP, sub_frame_t subframeP) { subframeP, (int) ccP->tdd_Config->subframeAssignment); break; } + return 0; } -int is_S_sf(COMMON_channels_t *ccP, sub_frame_t subframeP) { +//------------------------------------------------------------------------------ +int +is_S_sf(COMMON_channels_t *ccP, + sub_frame_t subframeP) +//------------------------------------------------------------------------------ +{ // if FDD return dummy value if (ccP->tdd_Config == NULL) - return (0); + return 0; switch (subframeP) { case 1: - return (1); - break; + return 1; case 6: - if(ccP->tdd_Config->subframeAssignment == 0 || ccP->tdd_Config->subframeAssignment == 1 - || ccP->tdd_Config->subframeAssignment == 2 || ccP->tdd_Config->subframeAssignment == 6) - return (1); + if (ccP->tdd_Config->subframeAssignment == 0 || ccP->tdd_Config->subframeAssignment == 1 || + ccP->tdd_Config->subframeAssignment == 2 || ccP->tdd_Config->subframeAssignment == 6) + return 1; break; default: - return (0); break; } return 0; } -uint8_t ul_subframe2_k_phich(COMMON_channels_t *cc, sub_frame_t ul_subframe) { +//------------------------------------------------------------------------------ +uint8_t +ul_subframe2_k_phich(COMMON_channels_t *cc, + sub_frame_t ul_subframe) +//------------------------------------------------------------------------------ +{ if(cc->tdd_Config) { //TODO fill other tdd config switch(cc->tdd_Config->subframeAssignment) { case 0: @@ -588,19 +664,11 @@ uint8_t ul_subframe2_k_phich(COMMON_channels_t *cc, sub_frame_t ul_subframe) { return 4; else if(ul_subframe == 3 || ul_subframe == 8) return 6; - else return 255; - - break; + return 255; case 2: - break; - case 3: - break; - case 4: - break; - case 5: break; } @@ -609,162 +677,131 @@ uint8_t ul_subframe2_k_phich(COMMON_channels_t *cc, sub_frame_t ul_subframe) { return 4; //idk sf_ahead? } -uint16_t get_pucch1_absSF(COMMON_channels_t *cc, uint16_t dlsch_absSF) { +//------------------------------------------------------------------------------ +uint16_t +get_pucch1_absSF(COMMON_channels_t *cc, + uint16_t dlsch_absSF) +//------------------------------------------------------------------------------ +{ uint16_t sf, f, nextf; + LTE_TDD_Config_t *tdd_Config = cc->tdd_Config; - if (cc->tdd_Config == NULL) { //FDD n+4 - return ((dlsch_absSF + 4) % 10240); - } else { - sf = dlsch_absSF % 10; - f = dlsch_absSF / 10; - nextf = (f + 1) & 1023; + if (tdd_Config == NULL) { //FDD n+4 + return (dlsch_absSF + 4) % 10240; + } - switch (cc->tdd_Config->subframeAssignment) { - case 0: - if ((sf == 0) || (sf == 5)) - return ((10 * f) + sf + 4)% 10240; // ACK/NAK in SF 4,9 same frame - else if (sf == 6) - return ((10 * nextf) + 2)% 10240; // ACK/NAK in SF 2 next frame - else if (sf == 1) - return ((10 * f) + 7)% 10240; // ACK/NAK in SF 7 same frame - else - AssertFatal(1 == 0, - "Impossible dlsch subframe %d for TDD configuration 0\n", - sf); + sf = dlsch_absSF % 10; + f = dlsch_absSF / 10; + nextf = (f + 1) & 1023; - break; + switch (tdd_Config->subframeAssignment) { + case 0: + if (sf == 0 || sf == 5) + return ((10 * f) + sf + 4) % 10240; // ACK/NAK in SF 4,9 same frame + if (sf == 6) + return ((10 * nextf) + 2) % 10240; // ACK/NAK in SF 2 next frame + if (sf == 1) + return ((10 * f) + 7) % 10240; // ACK/NAK in SF 7 same frame - case 1: - if ((sf == 5) || (sf == 6)) - return ((10 * nextf) + 2)% 10240; // ACK/NAK in SF 2 next frame - else if (sf == 9) - return ((10 * nextf) + 3)% 10240; // ACK/NAK in SF 3 next frame - else if ((sf == 0) || (sf == 1)) - return ((10 * f) + 7)% 10240; // ACK/NAK in SF 7 same frame - else if (sf == 4) - return ((10 * f) + 8)% 10240; // ACK/NAK in SF 8 same frame - else - AssertFatal(1 == 0, - "Impossible dlsch subframe %d for TDD configuration 1\n", - sf); + break; - break; + case 1: + if (sf == 5 || sf == 6) + return ((10 * nextf) + 2) % 10240; // ACK/NAK in SF 2 next frame + if (sf == 9) + return ((10 * nextf) + 3) % 10240; // ACK/NAK in SF 3 next frame + if ((sf == 0) || (sf == 1)) + return ((10 * f) + 7) % 10240; // ACK/NAK in SF 7 same frame + if (sf == 4) + return ((10 * f) + 8) % 10240; // ACK/NAK in SF 8 same frame - case 2: - if ((sf == 4) || (sf == 5) || (sf == 6) || (sf == 8)) - return ((10 * nextf) + 2)% 10240; // ACK/NAK in SF 2 next frame - else if (sf == 9) - return ((10 * nextf) + 7)% 10240; // ACK/NAK in SF 7 next frame - else if ((sf == 0) || (sf == 1) || (sf == 3)) - return ((10 * f) + 7)% 10240; // ACK/NAK in SF 7 same frame - else - AssertFatal(1 == 0, - "Impossible dlsch subframe %d for TDD configuration 2\n", - sf); + break; - break; + case 2: + if (sf == 4 || sf == 5 || sf == 6 || sf == 8) + return ((10 * nextf) + 2) % 10240; // ACK/NAK in SF 2 next frame + if (sf == 9) + return ((10 * nextf) + 7) % 10240; // ACK/NAK in SF 7 next frame + if (sf == 0 || sf == 1 || sf == 3) + return ((10 * f) + 7)% 10240; // ACK/NAK in SF 7 same frame - case 3: - if ((sf == 5) || (sf == 6) || (sf == 7) || (sf == 8) - || (sf == 9)) - return ((10 * nextf) + ((sf-1) >> 1))% 10240; // ACK/NAK in 2,3,4 resp. next frame - else if (sf == 1) - return ((10 * nextf) + 2)% 10240; // ACK/NAK in 2 next frame - else if (sf == 0) - return ((10 * f) + 4)% 10240; // ACK/NAK in 4 same frame - else - AssertFatal(1 == 0, - "Impossible dlsch subframe %d for TDD configuration 3\n", - sf); + break; - break; + case 3: + if (sf == 5 || sf == 6 || sf == 7 || sf == 8 || sf == 9) + return ((10 * nextf) + ((sf - 1) >> 1)) % 10240; // ACK/NAK in 2,3,4 resp. next frame + if (sf == 1) + return ((10 * nextf) + 2) % 10240; // ACK/NAK in 2 next frame + if (sf == 0) + return ((10 * f) + 4) % 10240; // ACK/NAK in 4 same frame - case 4: - if ((sf == 6) || (sf == 7) || (sf == 8) || (sf == 9)) - return (((10 * nextf) + 3) % 10240); // ACK/NAK in SF 3 next frame - else if ((sf == 0) || (sf == 1) || (sf == 4) || (sf == 5)) - return (((10 * nextf) + 2) % 10240); // ACK/NAK in SF 2 next frame - else - AssertFatal(1 == 0, - "Impossible dlsch subframe %d for TDD configuration 4\n", - sf); + break; - break; + case 4: + if (sf == 6 || sf == 7 || sf == 8 || sf == 9) + return ((10 * nextf) + 3) % 10240; // ACK/NAK in SF 3 next frame + else if (sf == 0 || sf == 1 || sf == 4 || sf == 5) + return ((10 * nextf) + 2) % 10240; // ACK/NAK in SF 2 next frame - case 5: - if ((sf == 0) || (sf == 1) || (sf == 3) || (sf == 4) - || (sf == 5) || (sf == 6) || (sf == 7) || (sf == 8)) - return (((10 * nextf) + 2) % 10240); // ACK/NAK in SF 3 next frame - else if (sf == 9) - return (((10 * (1 + nextf)) + 2) % 10240); // ACK/NAK in SF 2 next frame - else - AssertFatal(1 == 0, - "Impossible dlsch subframe %d for TDD configuration 5\n", - sf); + break; - break; + case 5: + if (sf == 0 || sf == 1 || sf == 3 || sf == 4 || sf == 5 || sf == 6 || sf == 7 || sf == 8) + return ((10 * nextf) + 2) % 10240; // ACK/NAK in SF 3 next frame + if (sf == 9) + return ((10 * (1 + nextf)) + 2) % 10240; // ACK/NAK in SF 2 next frame - case 6: - if ((sf == 5) || (sf == 6)) - return ((10 * f) + sf + 7)% 10240; // ACK/NAK in SF 2,3 next frame - else if (sf == 9) - return ((10 * nextf) + 4)% 10240; // ACK/NAK in SF 4 next frame - else if ((sf == 1) || (sf == 0)) - return ((10 * f) + sf + 7)% 10240; // ACK/NAK in SF 7 same frame - else - AssertFatal(1 == 0, - "Impossible dlsch subframe %d for TDD configuration 6\n", - sf); + break; - break; + case 6: + if (sf == 5 || sf == 6) + return ((10 * f) + sf + 7) % 10240; // ACK/NAK in SF 2,3 next frame + if (sf == 9) + return ((10 * nextf) + 4) % 10240; // ACK/NAK in SF 4 next frame + if (sf == 1 || sf == 0) + return ((10 * f) + sf + 7) % 10240; // ACK/NAK in SF 7 same frame - default: - AssertFatal(1 == 0, "Illegal TDD subframe Assigment %d\n", - (int) cc->tdd_Config->subframeAssignment); - break; - } + break; + + default: + AssertFatal(1 == 0, "Illegal TDD subframe Assigment %ld\n", + tdd_Config->subframeAssignment); + return 0; } - + AssertFatal(1 == 0, "Shouldn't get here\n"); } +//------------------------------------------------------------------------------ void -get_srs_pos(COMMON_channels_t *cc, uint16_t isrs, - uint16_t *psrsPeriodicity, uint16_t *psrsOffset) { +get_srs_pos(COMMON_channels_t *cc, + uint16_t isrs, + uint16_t *psrsPeriodicity, + uint16_t *psrsOffset) +//------------------------------------------------------------------------------ +{ if (cc->tdd_Config) { // TDD AssertFatal(isrs >= 10, "2 ms SRS periodicity not supported"); - if ((isrs > 9) && (isrs < 15)) { + if (isrs > 9 && isrs < 15) { *psrsPeriodicity = 5; *psrsOffset = isrs - 10; - } - - if ((isrs > 14) && (isrs < 25)) { + } else if (isrs > 14 && isrs < 25) { *psrsPeriodicity = 10; *psrsOffset = isrs - 15; - } - - if ((isrs > 24) && (isrs < 45)) { + } else if (isrs > 24 && isrs < 45) { *psrsPeriodicity = 20; *psrsOffset = isrs - 25; - } - - if ((isrs > 44) && (isrs < 85)) { + } else if (isrs > 44 && isrs < 85) { *psrsPeriodicity = 40; *psrsOffset = isrs - 45; - } - - if ((isrs > 84) && (isrs < 165)) { + } else if (isrs > 84 && isrs < 165) { *psrsPeriodicity = 80; *psrsOffset = isrs - 85; - } - - if ((isrs > 164) && (isrs < 325)) { + } else if (isrs > 164 && isrs < 325) { *psrsPeriodicity = 160; *psrsOffset = isrs - 165; - } - - if ((isrs > 324) && (isrs < 645)) { + } else if (isrs > 324 && isrs < 645) { *psrsPeriodicity = 320; *psrsOffset = isrs - 325; } @@ -775,56 +812,46 @@ get_srs_pos(COMMON_channels_t *cc, uint16_t isrs, if (isrs < 2) { *psrsPeriodicity = 2; *psrsOffset = isrs; - } - - if ((isrs > 1) && (isrs < 7)) { + } else if (isrs > 1 && isrs < 7) { *psrsPeriodicity = 5; *psrsOffset = isrs - 2; - } - - if ((isrs > 6) && (isrs < 17)) { + } else if (isrs > 6 && isrs < 17) { *psrsPeriodicity = 10; *psrsOffset = isrs - 7; - } - - if ((isrs > 16) && (isrs < 37)) { + } else if (isrs > 16 && isrs < 37) { *psrsPeriodicity = 20; *psrsOffset = isrs - 17; - } - - if ((isrs > 36) && (isrs < 77)) { + } else if (isrs > 36 && isrs < 77) { *psrsPeriodicity = 40; *psrsOffset = isrs - 37; - } - - if ((isrs > 76) && (isrs < 157)) { + } else if (isrs > 76 && isrs < 157) { *psrsPeriodicity = 80; *psrsOffset = isrs - 77; - } - - if ((isrs > 156) && (isrs < 317)) { + } else if (isrs > 156 && isrs < 317) { *psrsPeriodicity = 160; *psrsOffset = isrs - 157; - } - - if ((isrs > 316) && (isrs < 637)) { + } else if (isrs > 316 && isrs < 637) { *psrsPeriodicity = 320; *psrsOffset = isrs - 317; } AssertFatal(isrs <= 636, "Isrs out of range %d>636\n", isrs); } + return; } +//------------------------------------------------------------------------------ void get_csi_params(COMMON_channels_t *cc, struct LTE_CQI_ReportPeriodic *cqi_ReportPeriodic, - uint16_t *Npd, uint16_t *N_OFFSET_CQI, int *H) { - AssertFatal(cqi_ReportPeriodic != NULL, - "cqi_ReportPeriodic is null!\n"); + uint16_t *Npd, + uint16_t *N_OFFSET_CQI, + int *H) +//------------------------------------------------------------------------------ +{ + AssertFatal(cqi_ReportPeriodic != NULL, "cqi_ReportPeriodic is null!\n"); - uint16_t cqi_PMI_ConfigIndex = - cqi_ReportPeriodic->choice.setup.cqi_pmi_ConfigIndex; + uint16_t cqi_PMI_ConfigIndex = cqi_ReportPeriodic->choice.setup.cqi_pmi_ConfigIndex; uint8_t Jtab[6] = { 0, 2, 2, 3, 4, 4 }; if (cc->tdd_Config == NULL) { //FDD @@ -887,71 +914,58 @@ get_csi_params(COMMON_channels_t *cc, } // get H - if (cqi_ReportPeriodic->choice.setup.cqi_FormatIndicatorPeriodic. - present == - LTE_CQI_ReportPeriodic__setup__cqi_FormatIndicatorPeriodic_PR_subbandCQI) - *H = 1 + - (Jtab[cc->mib->message.dl_Bandwidth] * - cqi_ReportPeriodic->choice.setup. - cqi_FormatIndicatorPeriodic.choice.subbandCQI.k); - else + if (cqi_ReportPeriodic->choice.setup.cqi_FormatIndicatorPeriodic.present == LTE_CQI_ReportPeriodic__setup__cqi_FormatIndicatorPeriodic_PR_subbandCQI) { + *H = 1 + (Jtab[cc->mib->message.dl_Bandwidth] * cqi_ReportPeriodic->choice.setup.cqi_FormatIndicatorPeriodic.choice.subbandCQI.k); + } else { *H = 1; + } + return; } +//------------------------------------------------------------------------------ uint8_t -get_dl_cqi_pmi_size_pusch(COMMON_channels_t *cc, uint8_t tmode, +get_dl_cqi_pmi_size_pusch(COMMON_channels_t *cc, + uint8_t tmode, uint8_t ri, - LTE_CQI_ReportModeAperiodic_t * - cqi_ReportModeAperiodic) { + LTE_CQI_ReportModeAperiodic_t *cqi_ReportModeAperiodic) +//------------------------------------------------------------------------------ +{ int Ntab[6] = { 0, 4, 7, 9, 10, 13 }; int N = Ntab[cc->mib->message.dl_Bandwidth]; int Ltab_uesel[6] = { 0, 6, 9, 13, 15, 18 }; int L = Ltab_uesel[cc->mib->message.dl_Bandwidth]; - AssertFatal(cqi_ReportModeAperiodic != NULL, - "cqi_ReportPeriodic is null!\n"); + + AssertFatal(cqi_ReportModeAperiodic != NULL, "cqi_ReportPeriodic is null!\n"); switch (*cqi_ReportModeAperiodic) { case LTE_CQI_ReportModeAperiodic_rm12: - AssertFatal(tmode == 4 || tmode == 6 || tmode == 8 || tmode == 9 - || tmode == 10, - "Illegal TM (%d) for CQI_ReportModeAperiodic_rm12\n", + AssertFatal(tmode == 4 || tmode == 6 || tmode == 8 || tmode == 9 || tmode == 10, "Illegal TM (%d) for CQI_ReportModeAperiodic_rm12\n", tmode); - AssertFatal(cc->p_eNB <= 4, - "only up to 4 antenna ports supported here\n"); + AssertFatal(cc->p_eNB <= 4, "only up to 4 antenna ports supported here\n"); if (ri == 1 && cc->p_eNB == 2) return (4 + (N << 1)); - else if (ri == 2 && cc->p_eNB == 2) + if (ri == 2 && cc->p_eNB == 2) return (8 + N); - else if (ri == 1 && cc->p_eNB == 4) + if (ri == 1 && cc->p_eNB == 4) return (4 + (N << 2)); - else if (ri > 1 && cc->p_eNB == 4) + if (ri > 1 && cc->p_eNB == 4) return (8 + (N << 2)); break; case LTE_CQI_ReportModeAperiodic_rm20: // Table 5.2.2.6.3-1 (36.212) - AssertFatal(tmode == 1 || tmode == 2 || tmode == 3 || tmode == 7 - || tmode == 9 - || tmode == 10, - "Illegal TM (%d) for CQI_ReportModeAperiodic_rm20\n", + AssertFatal(tmode == 1 || tmode == 2 || tmode == 3 || tmode == 7 || tmode == 9 || tmode == 10, "Illegal TM (%d) for CQI_ReportModeAperiodic_rm20\n", tmode); - AssertFatal(tmode != 9 - && tmode != 10, - "TM9/10 will be handled later for CQI_ReportModeAperiodic_rm20\n"); + AssertFatal(tmode != 9 && tmode != 10, "TM9/10 will be handled later for CQI_ReportModeAperiodic_rm20\n"); return (4 + 2 + L); - break; case LTE_CQI_ReportModeAperiodic_rm22: // Table 5.2.2.6.3-2 (36.212) - AssertFatal(tmode == 4 || tmode == 6 || tmode == 8 || tmode == 9 - || tmode == 10, - "Illegal TM (%d) for CQI_ReportModeAperiodic_rm22\n", + AssertFatal(tmode == 4 || tmode == 6 || tmode == 8 || tmode == 9 || tmode == 10, "Illegal TM (%d) for CQI_ReportModeAperiodic_rm22\n", tmode); - AssertFatal(tmode != 9 - && tmode != 10, - "TM9/10 will be handled later for CQI_ReportModeAperiodic_rm22\n"); + AssertFatal(tmode != 9 && tmode != 10, "TM9/10 will be handled later for CQI_ReportModeAperiodic_rm22\n"); if (ri == 1 && cc->p_eNB == 2) return (4 + 2 + 0 + 0 + L + 4); @@ -969,98 +983,84 @@ get_dl_cqi_pmi_size_pusch(COMMON_channels_t *cc, uint8_t tmode, case LTE_CQI_ReportModeAperiodic_rm30: // Table 5.2.2.6.2-1 (36.212) - AssertFatal(tmode == 1 || tmode == 2 || tmode == 3 || tmode == 7 - || tmode == 8 || tmode == 9 - || tmode == 10, + AssertFatal(tmode == 1 || tmode == 2 || tmode == 3 || tmode == 7 || tmode == 8 || tmode == 9 || tmode == 10, "Illegal TM (%d) for CQI_ReportModeAperiodic_rm30\n", tmode); - AssertFatal(tmode != 8 && tmode != 9 - && tmode != 10, - "TM8/9/10 will be handled later for CQI_ReportModeAperiodic_rm30\n"); + AssertFatal(tmode != 8 && tmode != 9 && tmode != 10, "TM8/9/10 will be handled later for CQI_ReportModeAperiodic_rm30\n"); return (4 + (N << 1)); - break; case LTE_CQI_ReportModeAperiodic_rm31: // Table 5.2.2.6.2-2 (36.212) - AssertFatal(tmode == 4 || tmode == 6 || tmode == 8 || tmode == 9 - || tmode == 10, - "Illegal TM (%d) for CQI_ReportModeAperiodic_rm31\n", + AssertFatal(tmode == 4 || tmode == 6 || tmode == 8 || tmode == 9 || tmode == 10, "Illegal TM (%d) for CQI_ReportModeAperiodic_rm31\n", tmode); - AssertFatal(tmode != 8 && tmode != 9 - && tmode != 10, - "TM8/9/10 will be handled later for CQI_ReportModeAperiodic_rm31\n"); + AssertFatal(tmode != 8 && tmode != 9 && tmode != 10, "TM8/9/10 will be handled later for CQI_ReportModeAperiodic_rm31\n"); if (ri == 1 && cc->p_eNB == 2) return (4 + (N << 1) + 0 + 0 + 2); - else if (ri == 2 && cc->p_eNB == 2) + if (ri == 2 && cc->p_eNB == 2) return (4 + (N << 1) + 4 + (N << 1) + 1); - else if (ri == 1 && cc->p_eNB == 4) + if (ri == 1 && cc->p_eNB == 4) return (4 + (N << 1) + 0 + 0 + 4); - else if (ri >= 2 && cc->p_eNB == 4) + if (ri >= 2 && cc->p_eNB == 4) return (4 + (N << 1) + 4 + (N << 1) + 4); break; -#if (LTE_RRC_VERSION >= MAKE_VERSION(12, 5, 0)) +#if (LTE_RRC_VERSION >= MAKE_VERSION(12, 5, 0)) case LTE_CQI_ReportModeAperiodic_rm32_v1250: - AssertFatal(tmode == 4 || tmode == 6 || tmode == 8 || tmode == 9 - || tmode == 10, - "Illegal TM (%d) for CQI_ReportModeAperiodic_rm32\n", + AssertFatal(tmode == 4 || tmode == 6 || tmode == 8 || tmode == 9 || tmode == 10, "Illegal TM (%d) for CQI_ReportModeAperiodic_rm32\n", tmode); - AssertFatal(1 == 0, - "CQI_ReportModeAperiodic_rm32_v1250 not supported yet\n"); + AssertFatal(1 == 0, "CQI_ReportModeAperiodic_rm32_v1250 not supported yet\n"); break; case LTE_CQI_ReportModeAperiodic_rm10_v1310: // Table 5.2.2.6.1-1F/G (36.212) if (ri == 1) - return (4); // F - else - return (7); // G - - break; + return 4; // F + return 7; // G case LTE_CQI_ReportModeAperiodic_rm11_v1310: // Table 5.2.2.6.1-1H (36.212) - AssertFatal(tmode == 4 || tmode == 6 || tmode == 8 || tmode == 9 - || tmode == 10, - "Illegal TM (%d) for CQI_ReportModeAperiodic_rm11\n", + AssertFatal(tmode == 4 || tmode == 6 || tmode == 8 || tmode == 9 || tmode == 10, "Illegal TM (%d) for CQI_ReportModeAperiodic_rm11\n", tmode); - AssertFatal(cc->p_eNB <= 4, - "only up to 4 antenna ports supported here\n"); + AssertFatal(cc->p_eNB <= 4, "only up to 4 antenna ports supported here\n"); if (ri == 1 && cc->p_eNB == 2) return (4 + 0 + 2); - else if (ri == 2 && cc->p_eNB == 2) + if (ri == 2 && cc->p_eNB == 2) return (4 + 4 + 1); - else if (ri == 1 && cc->p_eNB == 4) + if (ri == 1 && cc->p_eNB == 4) return (4 + 0 + 4); - else if (ri > 1 && cc->p_eNB == 4) + if (ri > 1 && cc->p_eNB == 4) return (4 + 4 + 4); break; #endif /* #if (LTE_RRC_VERSION >= MAKE_VERSION(12, 5, 0)) */ + } AssertFatal(1 == 0, "Shouldn't get here\n"); - return (0); + return 0; } +//------------------------------------------------------------------------------ uint8_t -get_rel8_dl_cqi_pmi_size(UE_sched_ctrl *sched_ctl, int CC_idP, - COMMON_channels_t *cc, uint8_t tmode, - struct LTE_CQI_ReportPeriodic *cqi_ReportPeriodic) { +get_rel8_dl_cqi_pmi_size(UE_sched_ctrl *sched_ctl, + int CC_idP, + COMMON_channels_t *cc, + uint8_t tmode, + struct LTE_CQI_ReportPeriodic *cqi_ReportPeriodic) +//------------------------------------------------------------------------------ +{ int no_pmi = 0; // Ltab[6] = {0,log2(15/4/2),log2(25/4/2),log2(50/6/3),log2(75/8/4),log2(100/8/4)}; uint8_t Ltab[6] = { 0, 1, 2, 2, 2, 2 }; uint8_t ri = sched_ctl->periodic_ri_received[CC_idP]; - AssertFatal(cqi_ReportPeriodic != NULL, - "cqi_ReportPeriodic is null!\n"); - AssertFatal(cqi_ReportPeriodic->present != LTE_CQI_ReportPeriodic_PR_NOTHING, - "cqi_ReportPeriodic->present == CQI_ReportPeriodic_PR_NOTHING!\n"); - AssertFatal(cqi_ReportPeriodic->choice. - setup.cqi_FormatIndicatorPeriodic.present != LTE_CQI_ReportPeriodic__setup__cqi_FormatIndicatorPeriodic_PR_NOTHING, + + AssertFatal(cqi_ReportPeriodic != NULL, "cqi_ReportPeriodic is null!\n"); + AssertFatal(cqi_ReportPeriodic->present != LTE_CQI_ReportPeriodic_PR_NOTHING, "cqi_ReportPeriodic->present == CQI_ReportPeriodic_PR_NOTHING!\n"); + AssertFatal(cqi_ReportPeriodic->choice.setup.cqi_FormatIndicatorPeriodic.present != LTE_CQI_ReportPeriodic__setup__cqi_FormatIndicatorPeriodic_PR_NOTHING, "cqi_ReportPeriodic->cqi_FormatIndicatorPeriodic.choice.setup.present == CQI_ReportPeriodic__setup__cqi_FormatIndicatorPeriodic_PR_NOTHING!\n"); switch (tmode) { @@ -1074,32 +1074,32 @@ get_rel8_dl_cqi_pmi_size(UE_sched_ctrl *sched_ctl, int CC_idP, default: no_pmi = 0; + break; } - if ((cqi_ReportPeriodic->choice.setup.cqi_FormatIndicatorPeriodic.present == LTE_CQI_ReportPeriodic__setup__cqi_FormatIndicatorPeriodic_PR_widebandCQI) - || (sched_ctl->feedback_cnt[CC_idP] == 0)) { + if (cqi_ReportPeriodic->choice.setup.cqi_FormatIndicatorPeriodic.present == LTE_CQI_ReportPeriodic__setup__cqi_FormatIndicatorPeriodic_PR_widebandCQI || + sched_ctl->feedback_cnt[CC_idP] == 0) { // send wideband report every opportunity if wideband reporting mode is selected, else every H opportunities - if (no_pmi == 1) return (4); - else if ((cc->p_eNB == 2) && (ri == 1)) return (6); - else if ((cc->p_eNB == 2) && (ri == 2)) return (8); - else if ((cc->p_eNB == 4) && (ri == 1)) return (8); - else if ((cc->p_eNB == 4) && (ri == 2)) return (11); - else - AssertFatal(1 == 0, - "illegal combination p %d, ri %d, no_pmi %d\n", - cc->p_eNB, ri, no_pmi); + if (no_pmi == 1) return 4; + if (cc->p_eNB == 2 && ri == 1) return 6; + if (cc->p_eNB == 2 && ri == 2) return 8; + if (cc->p_eNB == 4 && ri == 1) return 8; + if (cc->p_eNB == 4 && ri == 2) return 11; + AssertFatal(1 == 0, "illegal combination p %d, ri %d, no_pmi %d\n", + cc->p_eNB, + ri, + no_pmi); } else if (cqi_ReportPeriodic->choice.setup.cqi_FormatIndicatorPeriodic.present == LTE_CQI_ReportPeriodic__setup__cqi_FormatIndicatorPeriodic_PR_subbandCQI) { - if ((no_pmi == 1) || ri == 1) return (4 + Ltab[cc->mib->message.dl_Bandwidth]); - else return (7 + Ltab[cc->mib->message.dl_Bandwidth]); + if (no_pmi == 1 || ri == 1) return (4 + Ltab[cc->mib->message.dl_Bandwidth]); + return (7 + Ltab[cc->mib->message.dl_Bandwidth]); } - AssertFatal(1 == 0, - "Shouldn't get here : cqi_ReportPeriodic->present %d\n", + AssertFatal(1 == 0, "Shouldn't get here : cqi_ReportPeriodic->present %d\n", cqi_ReportPeriodic->choice.setup.cqi_FormatIndicatorPeriodic.present); + return 0; } - - +//------------------------------------------------------------------------------ void fill_nfapi_dl_dci_1A(nfapi_dl_config_request_pdu_t *dl_config_pdu, uint8_t aggregation_level, @@ -1111,9 +1111,11 @@ fill_nfapi_dl_dci_1A(nfapi_dl_config_request_pdu_t *dl_config_pdu, uint8_t mcs, uint8_t ndi, uint8_t rv, - uint8_t vrb_flag) { - memset((void *) dl_config_pdu, 0, - sizeof(nfapi_dl_config_request_pdu_t)); + uint8_t vrb_flag) +//------------------------------------------------------------------------------ +{ + memset((void *) dl_config_pdu, 0,sizeof(nfapi_dl_config_request_pdu_t)); + dl_config_pdu->pdu_type = NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE; dl_config_pdu->pdu_size = (uint8_t) (2 + sizeof(nfapi_dl_config_dci_dl_pdu)); dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.tl.tag = NFAPI_DL_CONFIG_REQUEST_DCI_DL_PDU_REL8_TAG; @@ -1129,12 +1131,19 @@ fill_nfapi_dl_dci_1A(nfapi_dl_config_request_pdu_t *dl_config_pdu, dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.new_data_indicator_1 = ndi; dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.redundancy_version_1 = rv; dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.virtual_resource_block_assignment_flag = vrb_flag; + return; } +//------------------------------------------------------------------------------ void -program_dlsch_acknak(module_id_t module_idP, int CC_idP, int UE_idP, - frame_t frameP, sub_frame_t subframeP, - uint8_t cce_idx) { +program_dlsch_acknak(module_id_t module_idP, + int CC_idP, + int UE_idP, + frame_t frameP, + sub_frame_t subframeP, + uint8_t cce_idx) +//------------------------------------------------------------------------------ +{ eNB_MAC_INST *eNB = RC.mac[module_idP]; COMMON_channels_t *cc = eNB->common_channels; UE_list_t *UE_list = &eNB->UE_list; @@ -1145,27 +1154,33 @@ program_dlsch_acknak(module_id_t module_idP, int CC_idP, int UE_idP, nfapi_ul_config_ulsch_harq_information *ulsch_harq_information = NULL; nfapi_ul_config_harq_information *harq_information = NULL; #if (LTE_RRC_VERSION >= MAKE_VERSION(10, 2, 0)) - - if ((UE_list->UE_template[CC_idP][UE_idP].physicalConfigDedicated->ext2) - && (UE_list->UE_template[CC_idP][UE_idP].physicalConfigDedicated->ext2->pucch_ConfigDedicated_v1020) - && (UE_list->UE_template[CC_idP][UE_idP].physicalConfigDedicated->ext2->pucch_ConfigDedicated_v1020->simultaneousPUCCH_PUSCH_r10) - && (*UE_list->UE_template[CC_idP][UE_idP].physicalConfigDedicated->ext2->pucch_ConfigDedicated_v1020->simultaneousPUCCH_PUSCH_r10 == LTE_PUCCH_ConfigDedicated_v1020__simultaneousPUCCH_PUSCH_r10_true)) + struct LTE_PhysicalConfigDedicated__ext2 *ext2 = UE_list->UE_template[CC_idP][UE_idP].physicalConfigDedicated->ext2; + if (ext2 && + ext2->pucch_ConfigDedicated_v1020 && + ext2->pucch_ConfigDedicated_v1020->simultaneousPUCCH_PUSCH_r10 && + *ext2->pucch_ConfigDedicated_v1020->simultaneousPUCCH_PUSCH_r10 == LTE_PUCCH_ConfigDedicated_v1020__simultaneousPUCCH_PUSCH_r10_true) use_simultaneous_pucch_pusch = 1; #endif // pucch1 and pusch feedback is similar, namely in n+k subframes from now // This is used in the following "if/else" condition to check if there isn't or is already an UL grant in n+k - int16_t ul_absSF = get_pucch1_absSF(&cc[CC_idP], subframeP + (10 * frameP)); + int16_t ul_absSF = get_pucch1_absSF(&cc[CC_idP], + subframeP + (10 * frameP)); - if ((ul_config_pdu = has_ul_grant(module_idP, CC_idP,ul_absSF, rnti)) == NULL) { + if ((ul_config_pdu = has_ul_grant(module_idP, + CC_idP, + ul_absSF, + rnti)) == NULL) { // no UL grant so // Program ACK/NAK alone Format 1a/b or 3 - ul_req = &RC.mac[module_idP]->UL_req_tmp[CC_idP][ul_absSF %10].ul_config_request_body; + ul_req = &eNB->UL_req_tmp[CC_idP][ul_absSF % 10].ul_config_request_body; ul_config_pdu = &ul_req->ul_config_pdu_list[ul_req->number_of_pdus]; // Do PUCCH - fill_nfapi_uci_acknak(module_idP, - CC_idP, - rnti, (frameP * 10) + subframeP, cce_idx); + fill_nfapi_uci_acknak(module_idP, + CC_idP, + rnti, + subframeP + (10 * frameP), + cce_idx); } else { /* there is already an existing UL grant so update it if needed * on top of some other UL resource (PUSCH,combined SR/CQI/HARQ on PUCCH, etc) @@ -1175,41 +1190,40 @@ program_dlsch_acknak(module_id_t module_idP, int CC_idP, int UE_idP, case NFAPI_UL_CONFIG_ULSCH_PDU_TYPE: if (use_simultaneous_pucch_pusch == 1) { // Convert it to an NFAPI_UL_CONFIG_ULSCH_UCI_HARQ_PDU_TYPE - harq_information = &ul_config_pdu->ulsch_uci_harq_pdu.harq_information; + harq_information = &ul_config_pdu->ulsch_uci_harq_pdu.harq_information; ul_config_pdu->pdu_type = NFAPI_UL_CONFIG_ULSCH_UCI_HARQ_PDU_TYPE; - LOG_D(MAC, - "Frame %d, Subframe %d: Switched UCI HARQ to ULSCH UCI HARQ\n", - frameP, subframeP); + LOG_D(MAC, "Frame %d, Subframe %d: Switched UCI HARQ to ULSCH UCI HARQ\n", + frameP, + subframeP); } else { // Convert it to an NFAPI_UL_CONFIG_ULSCH_HARQ_PDU_TYPE - ulsch_harq_information = &ul_config_pdu->ulsch_harq_pdu.harq_information; + ulsch_harq_information = &ul_config_pdu->ulsch_harq_pdu.harq_information; ul_config_pdu->pdu_type = NFAPI_UL_CONFIG_ULSCH_HARQ_PDU_TYPE; - ul_config_pdu->ulsch_harq_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.tl.tag = NFAPI_UL_CONFIG_REQUEST_INITIAL_TRANSMISSION_PARAMETERS_REL8_TAG; - ul_config_pdu->ulsch_harq_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.n_srs_initial = 0; // last symbol not punctured - ul_config_pdu->ulsch_harq_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.initial_number_of_resource_blocks = - ul_config_pdu->ulsch_harq_pdu.ulsch_pdu.ulsch_pdu_rel8.number_of_resource_blocks; // we don't change the number of resource blocks across retransmissions yet - LOG_D(MAC, - "Frame %d, Subframe %d: Switched UCI HARQ to ULSCH HARQ\n", - frameP, subframeP); + ul_config_pdu->ulsch_harq_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.tl.tag + = NFAPI_UL_CONFIG_REQUEST_INITIAL_TRANSMISSION_PARAMETERS_REL8_TAG; + ul_config_pdu->ulsch_harq_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.n_srs_initial = 0; // last symbol not punctured + ul_config_pdu->ulsch_harq_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.initial_number_of_resource_blocks + = ul_config_pdu->ulsch_harq_pdu.ulsch_pdu.ulsch_pdu_rel8.number_of_resource_blocks; // we don't change the number of resource blocks across retransmissions yet + LOG_D(MAC,"Frame %d, Subframe %d: Switched UCI HARQ to ULSCH HARQ\n", + frameP, + subframeP); } break; case NFAPI_UL_CONFIG_ULSCH_HARQ_PDU_TYPE: - AssertFatal(use_simultaneous_pucch_pusch == 0, - "Cannot be NFAPI_UL_CONFIG_ULSCH_HARQ_PDU_TYPE, simultaneous_pucch_pusch is active"); + AssertFatal(use_simultaneous_pucch_pusch == 0, "Cannot be NFAPI_UL_CONFIG_ULSCH_HARQ_PDU_TYPE, simultaneous_pucch_pusch is active"); break; case NFAPI_UL_CONFIG_ULSCH_UCI_HARQ_PDU_TYPE: - AssertFatal(use_simultaneous_pucch_pusch == 1, - "Cannot be NFAPI_UL_CONFIG_ULSCH_UCI_PDU_TYPE, simultaneous_pucch_pusch is inactive\n"); + AssertFatal(use_simultaneous_pucch_pusch == 1, "Cannot be NFAPI_UL_CONFIG_ULSCH_UCI_PDU_TYPE, simultaneous_pucch_pusch is inactive\n"); break; /* [ulsch + cqi] to [ulsch + cqi + harq] */ case NFAPI_UL_CONFIG_ULSCH_CQI_RI_PDU_TYPE: // Convert it to an NFAPI_UL_CONFIG_ULSCH_CQI_HARQ_RI_PDU_TYPE - ulsch_harq_information = &ul_config_pdu->ulsch_cqi_harq_ri_pdu.harq_information; + ulsch_harq_information = &ul_config_pdu->ulsch_cqi_harq_ri_pdu.harq_information; ul_config_pdu->pdu_type = NFAPI_UL_CONFIG_ULSCH_CQI_HARQ_RI_PDU_TYPE; /* TODO: check this - when converting from nfapi_ul_config_ulsch_cqi_ri_pdu to * nfapi_ul_config_ulsch_cqi_harq_ri_pdu, shouldn't we copy initial_transmission_parameters @@ -1217,29 +1231,27 @@ program_dlsch_acknak(module_id_t module_idP, int CC_idP, int UE_idP, * Those two types are not compatible. 'initial_transmission_parameters' is not at the * place in both. */ - ul_config_pdu->ulsch_cqi_harq_ri_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.tl.tag = - NFAPI_UL_CONFIG_REQUEST_INITIAL_TRANSMISSION_PARAMETERS_REL8_TAG; - ul_config_pdu->ulsch_cqi_harq_ri_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.n_srs_initial = 0; // last symbol not punctured - ul_config_pdu->ulsch_cqi_harq_ri_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.initial_number_of_resource_blocks = - ul_config_pdu->ulsch_harq_pdu.ulsch_pdu.ulsch_pdu_rel8.number_of_resource_blocks; // we don't change the number of resource blocks across retransmissions yet + ul_config_pdu->ulsch_cqi_harq_ri_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.tl.tag + = NFAPI_UL_CONFIG_REQUEST_INITIAL_TRANSMISSION_PARAMETERS_REL8_TAG; + ul_config_pdu->ulsch_cqi_harq_ri_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.n_srs_initial = 0; // last symbol not punctured + ul_config_pdu->ulsch_cqi_harq_ri_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.initial_number_of_resource_blocks + = ul_config_pdu->ulsch_harq_pdu.ulsch_pdu.ulsch_pdu_rel8.number_of_resource_blocks; // we don't change the number of resource blocks across retransmissions yet break; case NFAPI_UL_CONFIG_ULSCH_CQI_HARQ_RI_PDU_TYPE: - AssertFatal(use_simultaneous_pucch_pusch == 0, - "Cannot be NFAPI_UL_CONFIG_ULSCH_CQI_HARQ_RI_PDU_TYPE, simultaneous_pucch_pusch is active\n"); + AssertFatal(use_simultaneous_pucch_pusch == 0, "Cannot be NFAPI_UL_CONFIG_ULSCH_CQI_HARQ_RI_PDU_TYPE, simultaneous_pucch_pusch is active\n"); break; /* [ulsch + cqi on pucch] to [ulsch + cqi on pucch + harq on pucch] */ case NFAPI_UL_CONFIG_ULSCH_UCI_CSI_PDU_TYPE: // convert it to an NFAPI_UL_CONFIG_ULSCH_CSI_UCI_HARQ_PDU_TYPE - harq_information = &ul_config_pdu->ulsch_csi_uci_harq_pdu.harq_information; + harq_information = &ul_config_pdu->ulsch_csi_uci_harq_pdu.harq_information; ul_config_pdu->pdu_type = NFAPI_UL_CONFIG_ULSCH_CSI_UCI_HARQ_PDU_TYPE; break; case NFAPI_UL_CONFIG_ULSCH_CSI_UCI_HARQ_PDU_TYPE: - AssertFatal(use_simultaneous_pucch_pusch == 1, - "Cannot be NFAPI_UL_CONFIG_ULSCH_CSI_UCI_HARQ_PDU_TYPE, simultaneous_pucch_pusch is inactive\n"); + AssertFatal(use_simultaneous_pucch_pusch == 1, "Cannot be NFAPI_UL_CONFIG_ULSCH_CSI_UCI_HARQ_PDU_TYPE, simultaneous_pucch_pusch is inactive\n"); break; /* [sr] to [sr + harq] */ @@ -1247,7 +1259,7 @@ program_dlsch_acknak(module_id_t module_idP, int CC_idP, int UE_idP, case NFAPI_UL_CONFIG_UCI_SR_PDU_TYPE: // convert to NFAPI_UL_CONFIG_UCI_SR_HARQ_PDU_TYPE ul_config_pdu->pdu_type = NFAPI_UL_CONFIG_UCI_SR_HARQ_PDU_TYPE; - harq_information = &ul_config_pdu->uci_sr_harq_pdu.harq_information; + harq_information = &ul_config_pdu->uci_sr_harq_pdu.harq_information; break; case NFAPI_UL_CONFIG_UCI_SR_HARQ_PDU_TYPE: @@ -1278,50 +1290,70 @@ program_dlsch_acknak(module_id_t module_idP, int CC_idP, int UE_idP, } } - if (ulsch_harq_information) fill_nfapi_ulsch_harq_information(module_idP, CC_idP, rnti, ulsch_harq_information, subframeP); - - if (harq_information) fill_nfapi_harq_information(module_idP, CC_idP, - rnti, - (frameP * 10) + subframeP, - harq_information, cce_idx); + if (ulsch_harq_information) { + fill_nfapi_ulsch_harq_information(module_idP, + CC_idP, + rnti, + ulsch_harq_information, + subframeP); + } + if (harq_information) { + fill_nfapi_harq_information(module_idP, + CC_idP, + rnti, + harq_information, + cce_idx); + } + return; } -uint8_t get_V_UL_DAI(module_id_t module_idP, int CC_idP, uint16_t rntiP,sub_frame_t subframeP) { +//------------------------------------------------------------------------------ +uint8_t +get_V_UL_DAI(module_id_t module_idP, + int CC_idP, + uint16_t rntiP, + sub_frame_t subframeP) +//------------------------------------------------------------------------------ +{ nfapi_hi_dci0_request_body_t *HI_DCI0_req = &RC.mac[module_idP]->HI_DCI0_req[CC_idP][subframeP].hi_dci0_request_body; nfapi_hi_dci0_request_pdu_t *hi_dci0_pdu = &HI_DCI0_req->hi_dci0_pdu_list[0]; for (int i = 0; i < HI_DCI0_req->number_of_dci; i++) { - if ((hi_dci0_pdu[i].pdu_type == NFAPI_HI_DCI0_DCI_PDU_TYPE) && - (hi_dci0_pdu[i].dci_pdu.dci_pdu_rel8.rnti == rntiP)) - return (hi_dci0_pdu[i].dci_pdu.dci_pdu_rel8.dl_assignment_index); + if (hi_dci0_pdu[i].pdu_type == NFAPI_HI_DCI0_DCI_PDU_TYPE && + hi_dci0_pdu[i].dci_pdu.dci_pdu_rel8.rnti == rntiP) { + return hi_dci0_pdu[i].dci_pdu.dci_pdu_rel8.dl_assignment_index; + } } - return (4); // this is rule from Section 7.3 in 36.213 + return 4; // this is rule from Section 7.3 in 36.213 } +//------------------------------------------------------------------------------ void fill_nfapi_ulsch_harq_information(module_id_t module_idP, int CC_idP, uint16_t rntiP, nfapi_ul_config_ulsch_harq_information *harq_information, sub_frame_t subframeP) +//------------------------------------------------------------------------------ { eNB_MAC_INST *eNB = RC.mac[module_idP]; COMMON_channels_t *cc = &eNB->common_channels[CC_idP]; UE_list_t *UE_list = &eNB->UE_list; int UE_id = find_UE_id(module_idP, rntiP); - LTE_PUSCH_ConfigDedicated_t *puschConfigDedicated; - // PUSCH_ConfigDedicated_v1020_t *puschConfigDedicated_v1020; - // PUSCH_ConfigDedicated_v1130_t *puschConfigDedicated_v1130; - // PUSCH_ConfigDedicated_v1250_t *puschConfigDedicated_v1250; + nfapi_ul_config_ulsch_harq_information_rel10_t* harq_information_rel10 = &harq_information->harq_information_rel10; + AssertFatal(UE_id >= 0, "UE_id cannot be found, impossible\n"); AssertFatal(UE_list != NULL, "UE_list is null\n"); - AssertFatal(UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated != NULL, - "physicalConfigDedicated for rnti %x is null\n", rntiP); - AssertFatal((puschConfigDedicated = (LTE_PUSCH_ConfigDedicated_t *) - UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->pusch_ConfigDedicated) != NULL, - "physicalConfigDedicated->puschConfigDedicated for rnti %x is null\n", + + LTE_PhysicalConfigDedicated_t *physicalConfigDedicated = UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated; + AssertFatal(physicalConfigDedicated != NULL, "physicalConfigDedicated for rnti %x is null\n", rntiP); + + struct LTE_PUSCH_ConfigDedicated *puschConfigDedicated = physicalConfigDedicated->pusch_ConfigDedicated; + AssertFatal(puschConfigDedicated != NULL, "physicalConfigDedicated->puschConfigDedicated for rnti %x is null\n", + rntiP); + #if (LTE_RRC_VERSION >= MAKE_VERSION(10, 2, 0)) /* if (UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->ext2) puschConfigDedicated_v1020 = UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->ext2->pusch_ConfigDedicated_v1020; #endif @@ -1333,16 +1365,18 @@ fill_nfapi_ulsch_harq_information(module_id_t module_ #endif */ #endif - harq_information->harq_information_rel10.delta_offset_harq = puschConfigDedicated->betaOffset_ACK_Index; - harq_information->harq_information_rel10.tl.tag = NFAPI_UL_CONFIG_REQUEST_ULSCH_HARQ_INFORMATION_REL10_TAG; - AssertFatal(UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->pucch_ConfigDedicated != NULL, - "pucch_ConfigDedicated is null!\n"); - if ((UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->pucch_ConfigDedicated->tdd_AckNackFeedbackMode != NULL) - && (*UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->pucch_ConfigDedicated->tdd_AckNackFeedbackMode == LTE_PUCCH_ConfigDedicated__tdd_AckNackFeedbackMode_multiplexing)) - harq_information->harq_information_rel10.ack_nack_mode = 1; // multiplexing + harq_information_rel10->delta_offset_harq = puschConfigDedicated->betaOffset_ACK_Index; + harq_information_rel10->tl.tag = NFAPI_UL_CONFIG_REQUEST_ULSCH_HARQ_INFORMATION_REL10_TAG; + + struct LTE_PUCCH_ConfigDedicated *pucch_ConfigDedicated = physicalConfigDedicated->pucch_ConfigDedicated; + AssertFatal(pucch_ConfigDedicated != NULL, "pucch_ConfigDedicated is null!\n"); + + if (pucch_ConfigDedicated->tdd_AckNackFeedbackMode != NULL && + *pucch_ConfigDedicated->tdd_AckNackFeedbackMode == LTE_PUCCH_ConfigDedicated__tdd_AckNackFeedbackMode_multiplexing) + harq_information_rel10->ack_nack_mode = 1; // multiplexing else - harq_information->harq_information_rel10.ack_nack_mode = 0; // bundling + harq_information_rel10->ack_nack_mode = 0; // bundling switch (get_tmode(module_idP, CC_idP, UE_id)) { case 1: @@ -1351,66 +1385,96 @@ fill_nfapi_ulsch_harq_information(module_id_t module_ case 6: case 7: if (cc->tdd_Config == NULL) // FDD - harq_information->harq_information_rel10.harq_size = 1; + harq_information_rel10->harq_size = 1; else { - if (harq_information->harq_information_rel10.ack_nack_mode == 1) - harq_information->harq_information_rel10.harq_size = get_V_UL_DAI(module_idP, CC_idP, rntiP, subframeP); + if (harq_information_rel10->ack_nack_mode == 1) + harq_information_rel10->harq_size = get_V_UL_DAI(module_idP, + CC_idP, + rntiP, + subframeP); else - harq_information->harq_information_rel10.harq_size = 1; + harq_information_rel10->harq_size = 1; } + break; default: // for any other TM we need 2 bits harq if (cc->tdd_Config == NULL) { - harq_information->harq_information_rel10.harq_size = 2; + harq_information_rel10->harq_size = 2; } else { - if (harq_information->harq_information_rel10.ack_nack_mode == 1) - harq_information->harq_information_rel10.harq_size = get_V_UL_DAI(module_idP, CC_idP, rntiP, subframeP); + if (harq_information_rel10->ack_nack_mode == 1) + harq_information_rel10->harq_size = get_V_UL_DAI(module_idP, + CC_idP, + rntiP, + subframeP); else - harq_information->harq_information_rel10.harq_size = 2; + harq_information_rel10->harq_size = 2; } + break; } // get Tmode return; } -uint8_t Np[6][4]= {{0,1,3,5}, - {0,3,8,13}, - {0,5,13,22}, - {0,11,27,44}, - {0,16,41,66}, - {0,22,55,88} +//------------------------------------------------------------------------------ +uint8_t +Np[6][4] = { + {0, 1, 3, 5}, + {0, 3, 8, 13}, + {0, 5, 13, 22}, + {0, 11, 27, 44}, + {0, 16, 41, 66}, + {0, 22, 55, 88} }; +//------------------------------------------------------------------------------ // This is part of the PUCCH allocation procedure (see Section 10.1 36.213) -uint16_t getNp(int dl_Bandwidth,uint8_t nCCE,uint8_t plus1) { - AssertFatal(dl_Bandwidth<6,"dl_Bandwidth %d>5\n",dl_Bandwidth); +//------------------------------------------------------------------------------ +uint16_t +getNp(int dl_Bandwidth, + uint8_t nCCE, + uint8_t plus1) +//------------------------------------------------------------------------------ +{ + AssertFatal(dl_Bandwidth < 6, "dl_Bandwidth %d>5\n", dl_Bandwidth); - if (nCCE>=Np[dl_Bandwidth][2]) - return(Np[dl_Bandwidth][2+plus1]); - else if (nCCE>=Np[dl_Bandwidth][1]) + if (nCCE >= Np[dl_Bandwidth][2]) { + return(Np[dl_Bandwidth][2+plus1]); + } + if (nCCE >= Np[dl_Bandwidth][1]) { return(Np[dl_Bandwidth][1+plus1]); - else - return(Np[dl_Bandwidth][0+plus1]); + } + return(Np[dl_Bandwidth][0+plus1]); } +//------------------------------------------------------------------------------ void fill_nfapi_harq_information(module_id_t module_idP, int CC_idP, uint16_t rntiP, - uint16_t absSFP, nfapi_ul_config_harq_information *harq_information, - uint8_t cce_idxP) { + uint8_t cce_idxP) +//------------------------------------------------------------------------------ +{ eNB_MAC_INST *eNB = RC.mac[module_idP]; COMMON_channels_t *cc = &eNB->common_channels[CC_idP]; UE_list_t *UE_list = &eNB->UE_list; - int UE_id = find_UE_id(module_idP, rntiP); + + int UE_id = find_UE_id(module_idP, + rntiP); + AssertFatal(UE_id >= 0, "UE_id cannot be found, impossible\n"); AssertFatal(UE_list != NULL, "UE_list is null\n"); harq_information->harq_information_rel11.tl.tag = NFAPI_UL_CONFIG_REQUEST_HARQ_INFORMATION_REL11_TAG; harq_information->harq_information_rel11.num_ant_ports = 1; + + LTE_PhysicalConfigDedicated_t *physicalConfigDedicated = UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated; + struct LTE_PUCCH_ConfigDedicated *pucch_ConfigDedicated = NULL; + if (physicalConfigDedicated != NULL) pucch_ConfigDedicated = physicalConfigDedicated->pucch_ConfigDedicated; - switch (get_tmode(module_idP, CC_idP, UE_id)) { + switch (get_tmode(module_idP, + CC_idP, + UE_id)) { case 1: case 2: case 5: @@ -1419,10 +1483,9 @@ fill_nfapi_harq_information(module_id_t module_idP, if (cc->tdd_Config != NULL) { // AssertFatal(UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->pucch_ConfigDedicated != NULL, // "pucch_ConfigDedicated is null for TDD!\n"); - if (UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated != NULL - && UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->pucch_ConfigDedicated != NULL - && (UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->pucch_ConfigDedicated->tdd_AckNackFeedbackMode != NULL) - && (*UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->pucch_ConfigDedicated->tdd_AckNackFeedbackMode == LTE_PUCCH_ConfigDedicated__tdd_AckNackFeedbackMode_multiplexing)) { + if (physicalConfigDedicated != NULL && pucch_ConfigDedicated != NULL && + pucch_ConfigDedicated->tdd_AckNackFeedbackMode != NULL && + *pucch_ConfigDedicated->tdd_AckNackFeedbackMode == LTE_PUCCH_ConfigDedicated__tdd_AckNackFeedbackMode_multiplexing) { harq_information->harq_information_rel10_tdd.harq_size = 2; // 2-bit ACK/NAK harq_information->harq_information_rel10_tdd.ack_nack_mode = 1; // multiplexing } else { @@ -1431,8 +1494,8 @@ fill_nfapi_harq_information(module_id_t module_idP, } harq_information->harq_information_rel10_tdd.tl.tag = NFAPI_UL_CONFIG_REQUEST_HARQ_INFORMATION_REL10_TDD_TAG; - harq_information->harq_information_rel10_tdd.n_pucch_1_0 = getNp(cc->mib->message.dl_Bandwidth,cce_idxP,0) + - cc->radioResourceConfigCommon->pucch_ConfigCommon.n1PUCCH_AN + cce_idxP; + harq_information->harq_information_rel10_tdd.n_pucch_1_0 + = getNp(cc->mib->message.dl_Bandwidth, cce_idxP, 0) + cc->radioResourceConfigCommon->pucch_ConfigCommon.n1PUCCH_AN + cce_idxP; harq_information->harq_information_rel10_tdd.number_of_pucch_resources = 1; } else { harq_information->harq_information_rel9_fdd.tl.tag = NFAPI_UL_CONFIG_REQUEST_HARQ_INFORMATION_REL9_FDD_TAG; @@ -1445,11 +1508,10 @@ fill_nfapi_harq_information(module_id_t module_idP, default: // for any other TM we need 2 bits harq if (cc->tdd_Config != NULL) { - AssertFatal(UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->pucch_ConfigDedicated != NULL, - "pucch_ConfigDedicated is null for TDD!\n"); + AssertFatal(pucch_ConfigDedicated != NULL, "pucch_ConfigDedicated is null for TDD!\n"); - if ((UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->pucch_ConfigDedicated->tdd_AckNackFeedbackMode != NULL) - && (*UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->pucch_ConfigDedicated->tdd_AckNackFeedbackMode == LTE_PUCCH_ConfigDedicated__tdd_AckNackFeedbackMode_multiplexing)) { + if (pucch_ConfigDedicated->tdd_AckNackFeedbackMode != NULL && + *pucch_ConfigDedicated->tdd_AckNackFeedbackMode == LTE_PUCCH_ConfigDedicated__tdd_AckNackFeedbackMode_multiplexing) { harq_information->harq_information_rel10_tdd.ack_nack_mode = 1; // multiplexing } else { harq_information->harq_information_rel10_tdd.ack_nack_mode = 0; // bundling @@ -1469,14 +1531,18 @@ fill_nfapi_harq_information(module_id_t module_idP, break; } // get Tmode + return; } +//------------------------------------------------------------------------------ uint16_t fill_nfapi_uci_acknak(module_id_t module_idP, int CC_idP, uint16_t rntiP, uint16_t absSFP, - uint8_t cce_idxP) { + uint8_t cce_idxP) +//------------------------------------------------------------------------------ +{ eNB_MAC_INST *eNB = RC.mac[module_idP]; COMMON_channels_t *cc = &eNB->common_channels[CC_idP]; int ackNAK_absSF = get_pucch1_absSF(cc, absSFP); @@ -1484,21 +1550,27 @@ fill_nfapi_uci_acknak(module_id_t module_idP, nfapi_ul_config_request_body_t *ul_req_body = &ul_req->ul_config_request_body; nfapi_ul_config_request_pdu_t *ul_config_pdu = &ul_req_body->ul_config_pdu_list[ul_req_body->number_of_pdus]; memset((void *) ul_config_pdu, 0, sizeof(nfapi_ul_config_request_pdu_t)); + ul_config_pdu->pdu_type = NFAPI_UL_CONFIG_UCI_HARQ_PDU_TYPE; ul_config_pdu->pdu_size = (uint8_t) (2 + sizeof(nfapi_ul_config_uci_harq_pdu)); ul_config_pdu->uci_harq_pdu.ue_information.ue_information_rel8.tl.tag = NFAPI_UL_CONFIG_REQUEST_UE_INFORMATION_REL8_TAG; ul_config_pdu->uci_harq_pdu.ue_information.ue_information_rel8.handle = 0; // don't know how to use this ul_config_pdu->uci_harq_pdu.ue_information.ue_information_rel8.rnti = rntiP; - fill_nfapi_harq_information(module_idP, CC_idP, + + fill_nfapi_harq_information(module_idP, + CC_idP, rntiP, - absSFP, - &ul_config_pdu->uci_harq_pdu.harq_information, cce_idxP); - LOG_D(MAC, - "Filled in UCI HARQ request for rnti %x SF %d.%d acknakSF %d.%d, cce_idxP %d-> n1_pucch %d\n", - rntiP, absSFP / 10, absSFP % 10, ackNAK_absSF / 10, - ackNAK_absSF % 10, cce_idxP, - ul_config_pdu->uci_harq_pdu. - harq_information.harq_information_rel9_fdd.n_pucch_1_0); + &ul_config_pdu->uci_harq_pdu.harq_information, + cce_idxP); + LOG_D(MAC, "Filled in UCI HARQ request for rnti %x SF %d.%d acknakSF %d.%d, cce_idxP %d-> n1_pucch %d\n", + rntiP, + absSFP / 10, + absSFP % 10, + ackNAK_absSF / 10, + ackNAK_absSF % 10, + cce_idxP, + ul_config_pdu->uci_harq_pdu.harq_information.harq_information_rel9_fdd.n_pucch_1_0); + ul_req_body->number_of_pdus++; ul_req_body->tl.tag = NFAPI_UL_CONFIG_REQUEST_BODY_TAG; ul_req->header.message_id = NFAPI_UL_CONFIG_REQUEST; @@ -1506,6 +1578,7 @@ fill_nfapi_uci_acknak(module_id_t module_idP, return (((ackNAK_absSF / 10) << 4) + (ackNAK_absSF % 10)); } +//------------------------------------------------------------------------------ void fill_nfapi_dlsch_config(eNB_MAC_INST *eNB, nfapi_dl_config_request_body_t *dl_req, @@ -1522,8 +1595,8 @@ fill_nfapi_dlsch_config(eNB_MAC_INST *eNB, uint8_t transport_block_to_codeword_swap_flag, uint8_t transmission_scheme, uint8_t number_of_layers, - uint8_t number_of_subbands, - // uint8_t codebook_index, + uint8_t number_of_subbands, + // uint8_t codebook_index, uint8_t ue_category_capacity, uint8_t pa, uint8_t delta_power_offset_index, @@ -1531,11 +1604,12 @@ fill_nfapi_dlsch_config(eNB_MAC_INST *eNB, uint8_t nprb, uint8_t transmission_mode, uint8_t num_bf_prb_per_subband, - uint8_t num_bf_vector) { - nfapi_dl_config_request_pdu_t *dl_config_pdu = - &dl_req->dl_config_pdu_list[dl_req->number_pdu]; - memset((void *) dl_config_pdu, 0, - sizeof(nfapi_dl_config_request_pdu_t)); + uint8_t num_bf_vector) +//------------------------------------------------------------------------------ +{ + nfapi_dl_config_request_pdu_t *dl_config_pdu = &dl_req->dl_config_pdu_list[dl_req->number_pdu]; + memset((void *) dl_config_pdu, 0, sizeof(nfapi_dl_config_request_pdu_t)); + dl_config_pdu->pdu_type = NFAPI_DL_CONFIG_DLSCH_PDU_TYPE; dl_config_pdu->pdu_size = (uint8_t) (2 + sizeof(nfapi_dl_config_dlsch_pdu)); dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.tl.tag = NFAPI_DL_CONFIG_REQUEST_DLSCH_PDU_REL8_TAG; @@ -1552,7 +1626,7 @@ fill_nfapi_dlsch_config(eNB_MAC_INST *eNB, dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.transmission_scheme = transmission_scheme; dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.number_of_layers = number_of_layers; dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.number_of_subbands = number_of_subbands; - // dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.codebook_index = codebook_index; + // dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.codebook_index = codebook_index; dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.ue_category_capacity = ue_category_capacity; dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.pa = pa; dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.delta_power_offset_index = delta_power_offset_index; @@ -1561,18 +1635,26 @@ fill_nfapi_dlsch_config(eNB_MAC_INST *eNB, dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.transmission_mode = transmission_mode; dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.num_bf_prb_per_subband = num_bf_prb_per_subband; dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.num_bf_vector = num_bf_vector; + dl_req->number_pdu++; + return; } +//------------------------------------------------------------------------------ uint16_t fill_nfapi_tx_req(nfapi_tx_request_body_t *tx_req_body, uint16_t absSF, uint16_t pdu_length, int16_t pdu_index, - uint8_t *pdu) { + uint8_t *pdu) +//------------------------------------------------------------------------------ +{ nfapi_tx_request_pdu_t *TX_req = &tx_req_body->tx_pdu_list[tx_req_body->number_of_pdus]; + LOG_D(MAC, "Filling TX_req %d for pdu length %d\n", - tx_req_body->number_of_pdus, pdu_length); + tx_req_body->number_of_pdus, + pdu_length); + TX_req->pdu_length = pdu_length; TX_req->pdu_index = pdu_index; TX_req->num_segments = 1; @@ -1583,6 +1665,7 @@ fill_nfapi_tx_req(nfapi_tx_request_body_t *tx_req_body, return (((absSF / 10) << 4) + (absSF % 10)); } +//------------------------------------------------------------------------------ void fill_nfapi_ulsch_config_request_rel8(nfapi_ul_config_request_pdu_t *ul_config_pdu, uint8_t cqi_req, @@ -1639,7 +1722,8 @@ fill_nfapi_ulsch_config_request_rel8(nfapi_ul_config_request_pdu_t *ul_config_pd ul_config_pdu->ulsch_cqi_ri_pdu.cqi_ri_information.cqi_ri_information_rel9.tl.tag = NFAPI_UL_CONFIG_REQUEST_CQI_RI_INFORMATION_REL9_TAG; ul_config_pdu->ulsch_cqi_ri_pdu.cqi_ri_information.cqi_ri_information_rel9.report_type = 1; ul_config_pdu->ulsch_cqi_ri_pdu.cqi_ri_information.cqi_ri_information_rel9.aperiodic_cqi_pmi_ri_report.number_of_cc = 1; - LOG_D(MAC, "report_type %d\n",ul_config_pdu->ulsch_cqi_ri_pdu.cqi_ri_information.cqi_ri_information_rel9.report_type); + LOG_D(MAC, "report_type %d\n", + ul_config_pdu->ulsch_cqi_ri_pdu.cqi_ri_information.cqi_ri_information_rel9.report_type); if (cc->p_eNB <= 2 && (tmode == 3 || tmode == 4 || tmode == 8 || tmode == 9 || tmode == 10)) ri_size = 1; else if (cc->p_eNB <= 2) ri_size = 0; @@ -1650,26 +1734,30 @@ fill_nfapi_ulsch_config_request_rel8(nfapi_ul_config_request_pdu_t *ul_config_pd AssertFatal(physicalConfigDedicated->cqi_ReportConfig->cqi_ReportModeAperiodic != NULL,"physicalConfigDedicated->cqi_ReportModeAperiodic is null!\n"); AssertFatal(physicalConfigDedicated->pusch_ConfigDedicated != NULL,"physicalConfigDedicated->puschConfigDedicated is null!\n"); - for (int ri = 0; ri < (1 << ri_size); ri++) { - ul_config_pdu->ulsch_cqi_ri_pdu.cqi_ri_information.cqi_ri_information_rel9.aperiodic_cqi_pmi_ri_report.cc[0].dl_cqi_pmi_size[ri] = - get_dl_cqi_pmi_size_pusch(cc,tmode,1 + ri, physicalConfigDedicated->cqi_ReportConfig->cqi_ReportModeAperiodic); + nfapi_ul_config_cqi_ri_information_rel9_t *ri_information = &ul_config_pdu->ulsch_cqi_ri_pdu.cqi_ri_information.cqi_ri_information_rel9; + int max_ri = (1 << ri_information->aperiodic_cqi_pmi_ri_report.cc[0].ri_size); + for (int ri = 0; ri < max_ri; ri++) { + ri_information->aperiodic_cqi_pmi_ri_report.cc[0].dl_cqi_pmi_size[ri] + = get_dl_cqi_pmi_size_pusch(cc, + tmode, + 1 + ri, + physicalConfigDedicated->cqi_ReportConfig->cqi_ReportModeAperiodic); } - - ul_config_pdu->ulsch_cqi_ri_pdu.cqi_ri_information.cqi_ri_information_rel9.delta_offset_cqi = - physicalConfigDedicated->pusch_ConfigDedicated->betaOffset_CQI_Index; - ul_config_pdu->ulsch_cqi_ri_pdu.cqi_ri_information.cqi_ri_information_rel9.delta_offset_ri = - physicalConfigDedicated->pusch_ConfigDedicated->betaOffset_RI_Index; + ri_information->delta_offset_cqi = physicalConfigDedicated->pusch_ConfigDedicated->betaOffset_CQI_Index; + ri_information->delta_offset_ri = physicalConfigDedicated->pusch_ConfigDedicated->betaOffset_RI_Index; } + return; } #if (LTE_RRC_VERSION >= MAKE_VERSION(13, 0, 0)) +//------------------------------------------------------------------------------ void -fill_nfapi_ulsch_config_request_emtc(nfapi_ul_config_request_pdu_t * - ul_config_pdu, uint8_t ue_type, - uint16_t - total_number_of_repetitions, +fill_nfapi_ulsch_config_request_emtc(nfapi_ul_config_request_pdu_t *ul_config_pdu, + uint8_t ue_type, + uint16_t total_number_of_repetitions, uint16_t repetition_number, uint16_t initial_transmission_sf_io) +//------------------------------------------------------------------------------ { // Re13 fields ul_config_pdu->ulsch_pdu.ulsch_pdu_rel13.tl.tag = NFAPI_UL_CONFIG_REQUEST_ULSCH_PDU_REL13_TAG; @@ -1677,31 +1765,52 @@ fill_nfapi_ulsch_config_request_emtc(nfapi_ul_config_request_pdu_t * ul_config_pdu->ulsch_pdu.ulsch_pdu_rel13.total_number_of_repetitions = total_number_of_repetitions; ul_config_pdu->ulsch_pdu.ulsch_pdu_rel13.repetition_number = repetition_number; ul_config_pdu->ulsch_pdu.ulsch_pdu_rel13.initial_transmission_sf_io = initial_transmission_sf_io; + return; } -int get_numnarrowbands(long dl_Bandwidth) { +//------------------------------------------------------------------------------ +int +get_numnarrowbands(long dl_Bandwidth) +//------------------------------------------------------------------------------ +{ int nb_tab[6] = { 1, 2, 4, 8, 12, 16 }; AssertFatal(dl_Bandwidth < 7 || dl_Bandwidth >= 0, "dl_Bandwidth not in [0..6]\n"); return (nb_tab[dl_Bandwidth]); } -int get_numnarrowbandbits(long dl_Bandwidth) { +//------------------------------------------------------------------------------ +int +get_numnarrowbandbits(long dl_Bandwidth) +//------------------------------------------------------------------------------ +{ int nbbits_tab[6] = { 0, 1, 2, 3, 4, 4 }; AssertFatal(dl_Bandwidth < 7 || dl_Bandwidth >= 0, "dl_Bandwidth not in [0..6]\n"); return (nbbits_tab[dl_Bandwidth]); } //This implements the frame/subframe condition for first subframe of MPDCCH transmission (Section 9.1.5 36.213, Rel 13/14) -int startSF_fdd_RA_times2[8] = { 2, 3, 4, 5, 8, 10, 16, 20 }; -int startSF_tdd_RA[7] = { 1, 2, 4, 5, 8, 10, 20 }; +//------------------------------------------------------------------------------ +int +startSF_fdd_RA_times2[8] = { 2, 3, 4, 5, 8, 10, 16, 20 }; +//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ +int +startSF_tdd_RA[7] = { 1, 2, 4, 5, 8, 10, 20 }; +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ int -mpdcch_sf_condition(eNB_MAC_INST *eNB, int CC_id, frame_t frameP, - sub_frame_t subframeP, int rmax, - MPDCCH_TYPES_t mpdcch_type, int UE_id) { - struct LTE_PRACH_ConfigSIB_v1310 *ext4_prach = - eNB->common_channels[CC_id].radioResourceConfigCommon_BR-> - ext4->prach_ConfigCommon_v1310; +mpdcch_sf_condition(eNB_MAC_INST *eNB, + int CC_id, + frame_t frameP, + sub_frame_t subframeP, + int rmax, + MPDCCH_TYPES_t mpdcch_type, + int UE_id) +//------------------------------------------------------------------------------ +{ + struct LTE_PRACH_ConfigSIB_v1310 *ext4_prach = eNB->common_channels[CC_id].radioResourceConfigCommon_BR-> ext4->prach_ConfigCommon_v1310; int T; LTE_EPDCCH_SetConfig_r11_t *epdcch_setconfig_r11; @@ -1719,17 +1828,13 @@ mpdcch_sf_condition(eNB_MAC_INST *eNB, int CC_id, frame_t frameP, break; case TYPE2: // RAR - AssertFatal(ext4_prach->mpdcch_startSF_CSS_RA_r13 != NULL, - "mpdcch_startSF_CSS_RA_r13 is null\n"); + AssertFatal(ext4_prach->mpdcch_startSF_CSS_RA_r13 != NULL, "mpdcch_startSF_CSS_RA_r13 is null\n"); AssertFatal(rmax > 0, "rmax is 0!\b"); if (eNB->common_channels[CC_id].tdd_Config == NULL) //FDD - T = rmax *startSF_fdd_RA_times2[ext4_prach-> - mpdcch_startSF_CSS_RA_r13-> - choice.fdd_r13] >> 1; + T = (rmax * startSF_fdd_RA_times2[ext4_prach->mpdcch_startSF_CSS_RA_r13->choice.fdd_r13]) >> 1; else //TDD - T = rmax *startSF_tdd_RA[ext4_prach-> - mpdcch_startSF_CSS_RA_r13->choice.tdd_r13]; + T = rmax * startSF_tdd_RA[ext4_prach->mpdcch_startSF_CSS_RA_r13->choice.tdd_r13]; break; @@ -1740,76 +1845,69 @@ mpdcch_sf_condition(eNB_MAC_INST *eNB, int CC_id, frame_t frameP, case TYPEUESPEC: epdcch_setconfig_r11 = eNB->UE_list.UE_template[CC_id][UE_id].physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.setConfigToAddModList_r11->list.array[0]; - AssertFatal(epdcch_setconfig_r11 != NULL, - " epdcch_setconfig_r11 is null for UE specific \n"); - AssertFatal(epdcch_setconfig_r11->ext2 != NULL, - " ext2 doesn't exist in epdcch config ' \n"); + AssertFatal(epdcch_setconfig_r11 != NULL, " epdcch_setconfig_r11 is null for UE specific \n"); + AssertFatal(epdcch_setconfig_r11->ext2 != NULL, " ext2 doesn't exist in epdcch config ' \n"); if (eNB->common_channels[CC_id].tdd_Config == NULL) //FDD - T = rmax *startSF_fdd_RA_times2[epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_StartSF_UESS_r13.choice.fdd_r13] >> 1; + T = (rmax * startSF_fdd_RA_times2[epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_StartSF_UESS_r13.choice.fdd_r13]) >> 1; else //TDD - T = rmax *startSF_tdd_RA[epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_StartSF_UESS_r13.choice.tdd_r13]; + T = rmax * startSF_tdd_RA[epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_StartSF_UESS_r13.choice.tdd_r13]; break; default: - return (0); + return 0; } AssertFatal(T > 0, "T is 0!\n"); - if (((10 * frameP) + subframeP) % T == 0) return (1); - else return (0); + if (((10 * frameP) + subframeP) % T == 0) return 1; + return 0; } -int narrowband_to_first_rb(COMMON_channels_t *cc, int nb_index) { +//------------------------------------------------------------------------------ +int +narrowband_to_first_rb(COMMON_channels_t *cc, + int nb_index) +//------------------------------------------------------------------------------ +{ switch (cc->mib->message.dl_Bandwidth) { case 0: // 6 PRBs, N_NB=1, i_0=0 - return (0); - break; + return 0; case 3: // 50 PRBs, N_NB=8, i_0=1 - return ((int) (1 + (6 * nb_index))); - break; + return (1 + (6 * nb_index)); case 5: // 100 PRBs, N_NB=16, i_0=2 - return ((int) (2 + (6 * nb_index))); - break; + return (2 + (6 * nb_index)); case 1: // 15 PRBs N_NB=2, i_0=1 if (nb_index > 0) - return (1); - else - return (0); - - break; + return 1; + return 0; case 2: // 25 PRBs, N_NB=4, i_0=0 if (nb_index > 1) return (1 + (6 * nb_index)); - else - return ((6 * nb_index)); - - break; + return ((6 * nb_index)); case 4: // 75 PRBs, N_NB=12, i_0=1 if (nb_index > 5) return (2 + (6 * nb_index)); - else - return (1 + (6 * nb_index)); - - break; + return (1 + (6 * nb_index)); default: AssertFatal(1 == 0, "Impossible dl_Bandwidth %d\n", (int) cc->mib->message.dl_Bandwidth); break; } + return 0; } #endif //------------------------------------------------------------------------------ -void init_ue_sched_info(void) +void +init_ue_sched_info(void) //------------------------------------------------------------------------------ { module_id_t i, j, k; @@ -1829,67 +1927,77 @@ void init_ue_sched_info(void) } } } + return; } - - //------------------------------------------------------------------------------ -unsigned char get_ue_weight(module_id_t module_idP, int CC_idP, int ue_idP) +unsigned char +get_ue_weight(module_id_t module_idP, + int CC_idP, + int ue_idP) //------------------------------------------------------------------------------ { return (eNB_dlsch_info[module_idP][CC_idP][ue_idP].weight); } //------------------------------------------------------------------------------ -int find_UE_id(module_id_t mod_idP, rnti_t rntiP) +int +find_UE_id(module_id_t mod_idP, + rnti_t rntiP) //------------------------------------------------------------------------------ { int UE_id; UE_list_t *UE_list = &RC.mac[mod_idP]->UE_list; for (UE_id = 0; UE_id < MAX_MOBILES_PER_ENB; UE_id++) { - if (UE_list->active[UE_id] != TRUE) - continue; - - if (UE_list->UE_template[UE_PCCID(mod_idP, UE_id)][UE_id].rnti == - rntiP) { - return (UE_id); + if (UE_list->active[UE_id] == TRUE) { + if (UE_list->UE_template[UE_PCCID(mod_idP, + UE_id)][UE_id].rnti == rntiP) { + return UE_id; + } } } - return (-1); + return -1; } //------------------------------------------------------------------------------ -int find_RA_id(module_id_t mod_idP, int CC_idP, rnti_t rntiP) +int +find_RA_id(module_id_t mod_idP, + int CC_idP, + rnti_t rntiP) //------------------------------------------------------------------------------ { int RA_id; AssertFatal(RC.mac[mod_idP], "RC.mac[%d] is null\n", mod_idP); - RA_t *ra = (RA_t *) & RC.mac[mod_idP]->common_channels[CC_idP].ra[0]; + RA_t *ra = (RA_t *) &RC.mac[mod_idP]->common_channels[CC_idP].ra[0]; for (RA_id = 0; RA_id < NB_RA_PROC_MAX; RA_id++) { - LOG_D(MAC, - "Checking RA_id %d for %x : state %d\n", - RA_id, rntiP, ra[RA_id].state); + LOG_D(MAC, "Checking RA_id %d for %x : state %d\n", + RA_id, + rntiP, + ra[RA_id].state); - if (ra[RA_id].state != IDLE && - ra[RA_id].rnti == rntiP) - return (RA_id); + if (ra[RA_id].state != IDLE && ra[RA_id].rnti == rntiP) + return RA_id; } - return (-1); + return -1; } //------------------------------------------------------------------------------ -int UE_num_active_CC(UE_list_t *listP, int ue_idP) +int +UE_num_active_CC(UE_list_t *listP, + int ue_idP) //------------------------------------------------------------------------------ { return (listP->numactiveCCs[ue_idP]); } //------------------------------------------------------------------------------ -int UE_PCCID(module_id_t mod_idP, int ue_idP) +int +UE_PCCID(module_id_t mod_idP, + int ue_idP) //------------------------------------------------------------------------------ { if (!RC.mac || !RC.mac[mod_idP]) return 0; @@ -1898,14 +2006,15 @@ int UE_PCCID(module_id_t mod_idP, int ue_idP) } //------------------------------------------------------------------------------ -rnti_t UE_RNTI(module_id_t mod_idP, int ue_idP) +rnti_t +UE_RNTI(module_id_t mod_idP, + int ue_idP) //------------------------------------------------------------------------------ { if (!RC.mac || !RC.mac[mod_idP]) return 0; - rnti_t rnti = - RC.mac[mod_idP]-> - UE_list.UE_template[UE_PCCID(mod_idP, ue_idP)][ue_idP].rnti; + rnti_t rnti = RC.mac[mod_idP]->UE_list.UE_template[UE_PCCID(mod_idP, + ue_idP)][ue_idP].rnti; if (rnti > 0) { return (rnti); @@ -1917,7 +2026,9 @@ rnti_t UE_RNTI(module_id_t mod_idP, int ue_idP) } //------------------------------------------------------------------------------ -boolean_t is_UE_active(module_id_t mod_idP, int ue_idP) +boolean_t +is_UE_active(module_id_t mod_idP, + int ue_idP) //------------------------------------------------------------------------------ { if (!RC.mac || !RC.mac[mod_idP]) return 0; @@ -1925,8 +2036,13 @@ boolean_t is_UE_active(module_id_t mod_idP, int ue_idP) return (RC.mac[mod_idP]->UE_list.active[ue_idP]); } +//------------------------------------------------------------------------------ unsigned char -get_aggregation(uint8_t bw_index, uint8_t cqi, uint8_t dci_fmt) { +get_aggregation(uint8_t bw_index, + uint8_t cqi, + uint8_t dci_fmt) +//------------------------------------------------------------------------------ +{ unsigned char aggregation = 3; switch (dci_fmt) { @@ -1955,38 +2071,67 @@ get_aggregation(uint8_t bw_index, uint8_t cqi, uint8_t dci_fmt) { case format3A: case format4: default: - LOG_W(MAC, "unsupported DCI format %d\n", dci_fmt); + LOG_W(MAC, "unsupported DCI format %d\n", + dci_fmt); + break; } - LOG_D(MAC, "Aggregation level %d (cqi %d, bw_index %d, format %d)\n", 1 << aggregation, cqi, bw_index, dci_fmt); + LOG_D(MAC, "Aggregation level %d (cqi %d, bw_index %d, format %d)\n", + 1 << aggregation, + cqi, + bw_index, + dci_fmt); + return 1 << aggregation; } -void dump_ue_list(UE_list_t *listP, int ul_flag) { +//------------------------------------------------------------------------------ +void +dump_ue_list(UE_list_t *listP, + int ul_flag) +//------------------------------------------------------------------------------ +{ int j; if (ul_flag == 0) { for (j = listP->head; j >= 0; j = listP->next[j]) { - LOG_T(MAC, "node %d => %d\n", j, listP->next[j]); + LOG_T(MAC, "node %d => %d\n", + j, + listP->next[j]); } } else { for (j = listP->head_ul; j >= 0; j = listP->next_ul[j]) { - LOG_T(MAC, "node %d => %d\n", j, listP->next_ul[j]); + LOG_T(MAC, "node %d => %d\n", + j, + listP->next_ul[j]); } } + return; } -int add_new_ue(module_id_t mod_idP, int cc_idP, rnti_t rntiP, int harq_pidP +//------------------------------------------------------------------------------ +int +add_new_ue(module_id_t mod_idP, + int cc_idP, + rnti_t rntiP, + int harq_pidP #if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0)) - , uint8_t rach_resource_type + , uint8_t rach_resource_type #endif - ) { + ) +//------------------------------------------------------------------------------ +{ int UE_id; int i, j; UE_list_t *UE_list = &RC.mac[mod_idP]->UE_list; - LOG_D(MAC, - "[eNB %d, CC_id %d] Adding UE with rnti %x (next avail %d, num_UEs %d)\n", - mod_idP, cc_idP, rntiP, UE_list->avail, UE_list->num_UEs); + + LOG_D(MAC, "[eNB %d, CC_id %d] Adding UE with rnti %x (next avail %d, num_UEs %d)\n", + mod_idP, + cc_idP, + rntiP, + UE_list->avail, + UE_list->num_UEs); + dump_ue_list(UE_list, 0); for (i = 0; i < MAX_MOBILES_PER_ENB; i++) { @@ -1994,8 +2139,8 @@ int add_new_ue(module_id_t mod_idP, int cc_idP, rnti_t rntiP, int harq_pidP continue; UE_id = i; - memset(&UE_list->UE_template[cc_idP][UE_id], 0, - sizeof(UE_TEMPLATE)); + memset(&UE_list->UE_template[cc_idP][UE_id], 0, sizeof(UE_TEMPLATE)); + UE_list->UE_template[cc_idP][UE_id].rnti = rntiP; UE_list->UE_template[cc_idP][UE_id].configured = FALSE; UE_list->numactiveCCs[UE_id] = 1; @@ -2005,16 +2150,19 @@ int add_new_ue(module_id_t mod_idP, int cc_idP, rnti_t rntiP, int harq_pidP UE_list->ordered_ULCCids[0][UE_id] = cc_idP; UE_list->num_UEs++; UE_list->active[UE_id] = TRUE; + #if defined(USRP_REC_PLAY) // not specific to record/playback ? UE_list->UE_template[cc_idP][UE_id].pre_assigned_mcs_ul = 0; #endif #if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0)) - UE_list->UE_template[cc_idP][UE_id].rach_resource_type = - rach_resource_type; + UE_list->UE_template[cc_idP][UE_id].rach_resource_type = rach_resource_type; #endif - memset((void *) &UE_list->UE_sched_ctrl[UE_id], 0, + + memset((void *) &UE_list->UE_sched_ctrl[UE_id], + 0, sizeof(UE_sched_ctrl)); - memset((void *) &UE_list->eNB_UE_stats[cc_idP][UE_id], 0, + memset((void *) &UE_list->eNB_UE_stats[cc_idP][UE_id], + 0, sizeof(eNB_UE_STATS)); UE_list->UE_sched_ctrl[UE_id].ue_reestablishment_reject_timer = 0; /* default slice in case there was something different */ @@ -2032,43 +2180,61 @@ int add_new_ue(module_id_t mod_idP, int cc_idP, rnti_t rntiP, int harq_pidP eNB_ulsch_info[mod_idP][cc_idP][UE_id].status = S_UL_WAITING; eNB_dlsch_info[mod_idP][cc_idP][UE_id].status = S_DL_WAITING; LOG_D(MAC, "[eNB %d] Add UE_id %d on Primary CC_id %d: rnti %x\n", - mod_idP, UE_id, cc_idP, rntiP); - dump_ue_list(UE_list, 0); + mod_idP, + UE_id, + cc_idP, + rntiP); + dump_ue_list(UE_list, + 0); return (UE_id); } - printf("MAC: cannot add new UE for rnti %x\n", rntiP); - LOG_E(MAC, - "error in add_new_ue(), could not find space in UE_list, Dumping UE list\n"); - dump_ue_list(UE_list, 0); - return (-1); + // printf("MAC: cannot add new UE for rnti %x\n", rntiP); + LOG_E(MAC, "error in add_new_ue(), could not find space in UE_list, Dumping UE list\n"); + dump_ue_list(UE_list, + 0); + return -1; } //------------------------------------------------------------------------------ -int rrc_mac_remove_ue(module_id_t mod_idP, rnti_t rntiP) +int +rrc_mac_remove_ue(module_id_t mod_idP, + rnti_t rntiP) //------------------------------------------------------------------------------ { int j; UE_list_t *UE_list = &RC.mac[mod_idP]->UE_list; - int UE_id = find_UE_id(mod_idP,rntiP); + int UE_id = find_UE_id(mod_idP, + rntiP); int pCC_id; + eNB_UE_STATS *ue_stats; if (UE_id == -1) { - LOG_W(MAC,"rrc_mac_remove_ue: UE %x not found\n", rntiP); + LOG_W(MAC,"rrc_mac_remove_ue: UE %x not found\n", + rntiP); return 0; } - pCC_id = UE_PCCID(mod_idP,UE_id); - LOG_I(MAC,"Removing UE %d from Primary CC_id %d (rnti %x)\n",UE_id,pCC_id, rntiP); - dump_ue_list(UE_list,0); + pCC_id = UE_PCCID(mod_idP, + UE_id); + LOG_I(MAC,"Removing UE %d from Primary CC_id %d (rnti %x)\n", + UE_id, + pCC_id, + rntiP); + dump_ue_list(UE_list, + 0); UE_list->active[UE_id] = FALSE; UE_list->num_UEs--; - if (UE_list->head == UE_id) UE_list->head=UE_list->next[UE_id]; - else UE_list->next[prev(UE_list,UE_id,0)]=UE_list->next[UE_id]; + if (UE_list->head == UE_id) UE_list->head = UE_list->next[UE_id]; + else UE_list->next[prev(UE_list, + UE_id, + 0)] = UE_list->next[UE_id]; - if (UE_list->head_ul == UE_id) UE_list->head_ul=UE_list->next_ul[UE_id]; - else UE_list->next_ul[prev(UE_list,UE_id,0)]=UE_list->next_ul[UE_id]; + if (UE_list->head_ul == UE_id) UE_list->head_ul = UE_list->next_ul[UE_id]; + else UE_list->next_ul[prev(UE_list, + UE_id, + 0)] = UE_list->next_ul[UE_id]; // clear all remaining pending transmissions /* UE_list->UE_template[pCC_id][UE_id].bsr_info[LCGID0] = 0; @@ -2080,30 +2246,34 @@ int rrc_mac_remove_ue(module_id_t mod_idP, rnti_t rntiP) UE_list->UE_template[pCC_id][UE_id].rnti = NOT_A_RNTI; UE_list->UE_template[pCC_id][UE_id].ul_active = FALSE; */ - memset (&UE_list->UE_template[pCC_id][UE_id],0,sizeof(UE_TEMPLATE)); - UE_list->eNB_UE_stats[pCC_id][UE_id].total_rbs_used = 0; - UE_list->eNB_UE_stats[pCC_id][UE_id].total_rbs_used_retx = 0; + memset (&UE_list->UE_template[pCC_id][UE_id], + 0, + sizeof(UE_TEMPLATE)); + + ue_stats = &UE_list->eNB_UE_stats[pCC_id][UE_id]; + ue_stats->total_rbs_used = 0; + ue_stats->total_rbs_used_retx = 0; for ( j = 0; j < NB_RB_MAX; j++ ) { - UE_list->eNB_UE_stats[pCC_id][UE_id].num_pdu_tx[j] = 0; - UE_list->eNB_UE_stats[pCC_id][UE_id].num_bytes_tx[j] = 0; + ue_stats->num_pdu_tx[j] = 0; + ue_stats->num_bytes_tx[j] = 0; } - UE_list->eNB_UE_stats[pCC_id][UE_id].num_retransmission = 0; - UE_list->eNB_UE_stats[pCC_id][UE_id].total_sdu_bytes = 0; - UE_list->eNB_UE_stats[pCC_id][UE_id].total_pdu_bytes = 0; - UE_list->eNB_UE_stats[pCC_id][UE_id].total_num_pdus = 0; - UE_list->eNB_UE_stats[pCC_id][UE_id].total_rbs_used_rx = 0; + ue_stats->num_retransmission = 0; + ue_stats->total_sdu_bytes = 0; + ue_stats->total_pdu_bytes = 0; + ue_stats->total_num_pdus = 0; + ue_stats->total_rbs_used_rx = 0; for ( j = 0; j < NB_RB_MAX; j++ ) { - UE_list->eNB_UE_stats[pCC_id][UE_id].num_pdu_rx[j] = 0; - UE_list->eNB_UE_stats[pCC_id][UE_id].num_bytes_rx[j] = 0; + ue_stats->num_pdu_rx[j] = 0; + ue_stats->num_bytes_rx[j] = 0; } - UE_list->eNB_UE_stats[pCC_id][UE_id].num_errors_rx = 0; - UE_list->eNB_UE_stats[pCC_id][UE_id].total_pdu_bytes_rx = 0; - UE_list->eNB_UE_stats[pCC_id][UE_id].total_num_pdus_rx = 0; - UE_list->eNB_UE_stats[pCC_id][UE_id].total_num_errors_rx = 0; + ue_stats->num_errors_rx = 0; + ue_stats->total_pdu_bytes_rx = 0; + ue_stats->total_num_pdus_rx = 0; + ue_stats->total_num_errors_rx = 0; eNB_ulsch_info[mod_idP][pCC_id][UE_id].rnti = NOT_A_RNTI; eNB_ulsch_info[mod_idP][pCC_id][UE_id].status = S_UL_NONE; eNB_dlsch_info[mod_idP][pCC_id][UE_id].rnti = NOT_A_RNTI; @@ -2112,29 +2282,34 @@ int rrc_mac_remove_ue(module_id_t mod_idP, rnti_t rntiP) eNB_dlsch_info[mod_idP][pCC_id][UE_id].serving_num = 0; // check if this has an RA process active - if(find_RA_id(mod_idP, pCC_id, rntiP) != -1) { - cancel_ra_proc(mod_idP, pCC_id, 0, rntiP); + if (find_RA_id(mod_idP, + pCC_id, + rntiP) != -1) { + cancel_ra_proc(mod_idP, + pCC_id, + 0, + rntiP); } pthread_mutex_lock(&rrc_release_freelist); - if(rrc_release_info.num_UEs > 0) { + if (rrc_release_info.num_UEs > 0) { uint16_t release_total = 0; - for(uint16_t release_num = 0; release_num < NUMBER_OF_UE_MAX; release_num++) { - if(rrc_release_info.RRC_release_ctrl[release_num].flag > 0) { + for (uint16_t release_num = 0; release_num < NUMBER_OF_UE_MAX; release_num++) { + if (rrc_release_info.RRC_release_ctrl[release_num].flag > 0) { release_total++; } else { continue; } - if(rrc_release_info.RRC_release_ctrl[release_num].rnti == rntiP) { + if (rrc_release_info.RRC_release_ctrl[release_num].rnti == rntiP) { rrc_release_info.RRC_release_ctrl[release_num].flag = 0; rrc_release_info.num_UEs--; release_total--; } - if(release_total >= rrc_release_info.num_UEs) { + if (release_total >= rrc_release_info.num_UEs) { break; } } @@ -2144,44 +2319,65 @@ int rrc_mac_remove_ue(module_id_t mod_idP, rnti_t rntiP) return 0; } -int prev(UE_list_t *listP, int nodeP, int ul_flag) { +//------------------------------------------------------------------------------ +int +prev(UE_list_t *listP, + int nodeP, + int ul_flag) +//------------------------------------------------------------------------------ +{ int j; if (ul_flag == 0) { if (nodeP == listP->head) { - return (nodeP); + return nodeP; } for (j = listP->head; j >= 0; j = listP->next[j]) { if (listP->next[j] == nodeP) { - return (j); + return j; } } } else { if (nodeP == listP->head_ul) { - return (nodeP); + return nodeP; } for (j = listP->head_ul; j >= 0; j = listP->next_ul[j]) { if (listP->next_ul[j] == nodeP) { - return (j); + return j; } } } - LOG_E(MAC, - "error in prev(), could not find previous to %d in UE_list %s, should never happen, Dumping UE list\n", - nodeP, (ul_flag == 0) ? "DL" : "UL"); - dump_ue_list(listP, ul_flag); - return (-1); + LOG_E(MAC, "error in prev(), could not find previous to %d in UE_list %s, should never happen, Dumping UE list\n", + nodeP, + (ul_flag == 0) ? "DL" : "UL"); + dump_ue_list(listP, + ul_flag); + return -1; } -void swap_UEs(UE_list_t *listP, int nodeiP, int nodejP, int ul_flag) { +//------------------------------------------------------------------------------ +void +swap_UEs(UE_list_t *listP, + int nodeiP, + int nodejP, + int ul_flag) +//------------------------------------------------------------------------------ +{ int prev_i, prev_j, next_i, next_j; - LOG_T(MAC, "Swapping UE %d,%d\n", nodeiP, nodejP); - dump_ue_list(listP, ul_flag); - prev_i = prev(listP, nodeiP, ul_flag); - prev_j = prev(listP, nodejP, ul_flag); + LOG_T(MAC, "Swapping UE %d,%d\n", + nodeiP, + nodejP); + dump_ue_list(listP, + ul_flag); + prev_i = prev(listP, + nodeiP, + ul_flag); + prev_j = prev(listP, + nodejP, + ul_flag); AssertFatal((prev_i >= 0) && (prev_j >= 0), "swap_UEs: problem"); if (ul_flag == 0) { @@ -2193,12 +2389,14 @@ void swap_UEs(UE_list_t *listP, int nodeiP, int nodejP, int ul_flag) { } LOG_T(MAC, "[%s] next_i %d, next_i, next_j %d, head %d \n", - (ul_flag == 0) ? "DL" : "UL", next_i, next_j, listP->head); + (ul_flag == 0) ? "DL" : "UL", + next_i, + next_j, + listP->head); if (ul_flag == 0) { if (next_i == nodejP) { // case ... p(i) i j n(j) ... => ... p(j) j i n(i) ... - LOG_T(MAC, - "Case ... p(i) i j n(j) ... => ... p(j) j i n(i) ...\n"); + LOG_T(MAC, "Case ... p(i) i j n(j) ... => ... p(j) j i n(i) ...\n"); listP->next[nodeiP] = next_j; listP->next[nodejP] = nodeiP; @@ -2208,8 +2406,7 @@ void swap_UEs(UE_list_t *listP, int nodeiP, int nodejP, int ul_flag) { listP->next[prev_i] = nodejP; } } else if (next_j == nodeiP) { // case ... p(j) j i n(i) ... => ... p(i) i j n(j) ... - LOG_T(MAC, - "Case ... p(j) j i n(i) ... => ... p(i) i j n(j) ...\n"); + LOG_T(MAC, "Case ... p(j) j i n(i) ... => ... p(i) i j n(j) ...\n"); listP->next[nodejP] = next_i; listP->next[nodeiP] = nodejP; @@ -2223,11 +2420,13 @@ void swap_UEs(UE_list_t *listP, int nodeiP, int nodejP, int ul_flag) { listP->next[nodeiP] = next_j; if (nodeiP == listP->head) { - LOG_T(MAC, "changing head to %d\n", nodejP); + LOG_T(MAC, "changing head to %d\n", + nodejP); listP->head = nodejP; listP->next[prev_j] = nodeiP; } else if (nodejP == listP->head) { - LOG_D(MAC, "changing head to %d\n", nodeiP); + LOG_D(MAC, "changing head to %d\n", + nodeiP); listP->head = nodeiP; listP->next[prev_i] = nodejP; } else { @@ -2237,8 +2436,7 @@ void swap_UEs(UE_list_t *listP, int nodeiP, int nodejP, int ul_flag) { } } else { // ul_flag if (next_i == nodejP) { // case ... p(i) i j n(j) ... => ... p(j) j i n(i) ... - LOG_T(MAC, - "[UL] Case ... p(i) i j n(j) ... => ... p(j) j i n(i) ...\n"); + LOG_T(MAC, "[UL] Case ... p(i) i j n(j) ... => ... p(j) j i n(i) ...\n"); listP->next_ul[nodeiP] = next_j; listP->next_ul[nodejP] = nodeiP; @@ -2248,8 +2446,7 @@ void swap_UEs(UE_list_t *listP, int nodeiP, int nodejP, int ul_flag) { listP->next_ul[prev_i] = nodejP; } } else if (next_j == nodeiP) { // case ... p(j) j i n(i) ... => ... p(i) i j n(j) ... - LOG_T(MAC, - "[UL]Case ... p(j) j i n(i) ... => ... p(i) i j n(j) ...\n"); + LOG_T(MAC, "[UL]Case ... p(j) j i n(i) ... => ... p(i) i j n(j) ...\n"); listP->next_ul[nodejP] = next_i; listP->next_ul[nodeiP] = nodejP; @@ -2263,11 +2460,13 @@ void swap_UEs(UE_list_t *listP, int nodeiP, int nodejP, int ul_flag) { listP->next_ul[nodeiP] = next_j; if (nodeiP == listP->head_ul) { - LOG_T(MAC, "[UL]changing head to %d\n", nodejP); + LOG_T(MAC, "[UL]changing head to %d\n", + nodejP); listP->head_ul = nodejP; listP->next_ul[prev_j] = nodeiP; } else if (nodejP == listP->head_ul) { - LOG_T(MAC, "[UL]changing head to %d\n", nodeiP); + LOG_T(MAC, "[UL]changing head to %d\n", + nodeiP); listP->head_ul = nodeiP; listP->next_ul[prev_i] = nodejP; } else { @@ -2278,14 +2477,18 @@ void swap_UEs(UE_list_t *listP, int nodeiP, int nodejP, int ul_flag) { } LOG_T(MAC, "After swap\n"); - dump_ue_list(listP, ul_flag); + dump_ue_list(listP, + ul_flag); + return; } // This has to be updated to include BSR information +//------------------------------------------------------------------------------ uint8_t UE_is_to_be_scheduled(module_id_t module_idP, int CC_id, uint8_t UE_id) +//------------------------------------------------------------------------------ { UE_TEMPLATE *UE_template = &RC.mac[module_idP]->UE_list.UE_template[CC_id][UE_id]; UE_sched_ctrl *UE_sched_ctl = &RC.mac[module_idP]->UE_list.UE_sched_ctrl[UE_id]; @@ -2294,62 +2497,82 @@ UE_is_to_be_scheduled(module_id_t module_idP, if (UE_sched_ctl->ul_failure_timer > 0 || UE_sched_ctl->ul_out_of_sync > 0) return 0; + rnti_t ue_rnti = UE_RNTI(module_idP, + UE_id); LOG_D(MAC, "[eNB %d][PUSCH] Checking UL requirements UE %d/%x\n", - module_idP, UE_id, UE_RNTI(module_idP, UE_id)); + module_idP, + UE_id, + ue_rnti); - if ((UE_template->scheduled_ul_bytes < UE_template->estimated_ul_buffer) || - (UE_template->ul_SR > 0) || // uplink scheduling request - ((UE_sched_ctl->ul_inactivity_timer > 20) && (UE_sched_ctl->ul_scheduled == 0)) || // every 2 frames when RRC_CONNECTED - ((UE_sched_ctl->ul_inactivity_timer > 10) && (UE_sched_ctl->ul_scheduled == 0) && - (mac_eNB_get_rrc_status(module_idP, UE_RNTI(module_idP, UE_id)) < RRC_CONNECTED))) { // every Frame when not RRC_CONNECTED - LOG_D(MAC, - "[eNB %d][PUSCH] UE %d/%x should be scheduled (BSR0 estimated size %d, SR %d)\n", - module_idP, UE_id, UE_RNTI(module_idP, UE_id), + if (UE_template->scheduled_ul_bytes < UE_template->estimated_ul_buffer || + UE_template->ul_SR > 0 || // uplink scheduling request + (UE_sched_ctl->ul_inactivity_timer > 20 && UE_sched_ctl->ul_scheduled == 0) || // every 2 frames when RRC_CONNECTED + (UE_sched_ctl->ul_inactivity_timer > 10 && + UE_sched_ctl->ul_scheduled == 0 && + mac_eNB_get_rrc_status(module_idP, + ue_rnti) < RRC_CONNECTED)) { // every Frame when not RRC_CONNECTED + LOG_D(MAC, "[eNB %d][PUSCH] UE %d/%x should be scheduled (BSR0 estimated size %d, SR %d)\n", + module_idP, + UE_id, + ue_rnti, UE_template->ul_buffer_info[LCGID0], UE_template->ul_SR); return 1; - } + } return 0; } -uint8_t -get_tmode(module_id_t module_idP, - int CC_idP, +//------------------------------------------------------------------------------ +uint8_t +get_tmode(module_id_t module_idP, + int CC_idP, int UE_idP) +//------------------------------------------------------------------------------ { eNB_MAC_INST *eNB = RC.mac[module_idP]; COMMON_channels_t *cc = &eNB->common_channels[CC_idP]; - struct LTE_PhysicalConfigDedicated *physicalConfigDedicated = eNB->UE_list.UE_template[CC_idP][UE_idP].physicalConfigDedicated; if (physicalConfigDedicated == NULL) { // RRCConnectionSetup not received by UE yet - AssertFatal(cc->p_eNB <= 2, "p_eNB is %d, should be <2\n", cc->p_eNB); + AssertFatal(cc->p_eNB <= 2, "p_eNB is %d, should be <2\n", + cc->p_eNB); return (cc->p_eNB); - } + } - AssertFatal(physicalConfigDedicated->antennaInfo != NULL, + AssertFatal(physicalConfigDedicated->antennaInfo != NULL, "antennaInfo (mod_id %d) is null for CCId %d, UEid %d, physicalConfigDedicated %p\n", - module_idP, CC_idP, UE_idP,physicalConfigDedicated); - + module_idP, + CC_idP, + UE_idP, + physicalConfigDedicated); + AssertFatal(physicalConfigDedicated->antennaInfo->present != LTE_PhysicalConfigDedicated__antennaInfo_PR_NOTHING, - "antennaInfo (mod_id %d, CC_id %d) is set to NOTHING\n", module_idP, CC_idP); + "antennaInfo (mod_id %d, CC_id %d) is set to NOTHING\n", + module_idP, + CC_idP); if (physicalConfigDedicated->antennaInfo->present == LTE_PhysicalConfigDedicated__antennaInfo_PR_explicitValue) { return (1 + physicalConfigDedicated->antennaInfo->choice.explicitValue.transmissionMode); - } + } if (physicalConfigDedicated->antennaInfo->present == LTE_PhysicalConfigDedicated__antennaInfo_PR_defaultValue) { - AssertFatal(cc->p_eNB <= 2, "p_eNB is %d, should be <2\n", cc->p_eNB); + AssertFatal(cc->p_eNB <= 2, "p_eNB is %d, should be <2\n", + cc->p_eNB); return (cc->p_eNB); - } + } AssertFatal(1 == 0, "Shouldn't be here\n"); return 0; } +//------------------------------------------------------------------------------ int8_t -get_ULharq(module_id_t module_idP, int CC_idP, uint16_t frameP, - uint8_t subframeP) { - uint8_t ret = -1; +get_ULharq(module_id_t module_idP, + int CC_idP, + uint16_t frameP, + uint8_t subframeP) +//------------------------------------------------------------------------------ +{ + int8_t ret = -1; eNB_MAC_INST *eNB = RC.mac[module_idP]; COMMON_channels_t *cc = &eNB->common_channels[CC_idP]; @@ -2358,77 +2581,74 @@ get_ULharq(module_id_t module_idP, int CC_idP, uint16_t frameP, } else { switch (cc->tdd_Config->subframeAssignment) { case 1: - if ((subframeP == 2) || - (subframeP == 3) || (subframeP == 7) || (subframeP == 8)) - switch (subframeP) { - case 2: - case 3: - ret = (subframeP - 2); - break; + switch (subframeP) { + case 2: + case 3: + ret = (subframeP - 2); + break; - case 7: - case 8: - ret = (subframeP - 5); - break; + case 7: + case 8: + ret = (subframeP - 5); + break; - default: - AssertFatal(1 == 0, - "subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n", - subframeP, - (int) cc->tdd_Config->subframeAssignment); - break; - } + default: + AssertFatal(1 == 0, "subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n", + subframeP, + (int) cc->tdd_Config->subframeAssignment); + break; + } break; case 2: - AssertFatal((subframeP == 2) || (subframeP == 7), - "subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n", + AssertFatal((subframeP == 2) || (subframeP == 7), "subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n", subframeP, (int) cc->tdd_Config->subframeAssignment); ret = (subframeP / 7); break; case 3: - AssertFatal((subframeP > 1) && (subframeP < 5), - "subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n", + AssertFatal((subframeP > 1) && (subframeP < 5), "subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n", subframeP, (int) cc->tdd_Config->subframeAssignment); ret = (subframeP - 2); break; case 4: - AssertFatal((subframeP > 1) && (subframeP < 4), - "subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n", + AssertFatal((subframeP > 1) && (subframeP < 4), "subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n", subframeP, (int) cc->tdd_Config->subframeAssignment); ret = (subframeP - 2); break; case 5: - AssertFatal(subframeP == 2, - "subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n", + AssertFatal(subframeP == 2, "subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n", subframeP, (int) cc->tdd_Config->subframeAssignment); ret = (subframeP - 2); break; default: - AssertFatal(1 == 0, - "subframe2_harq_pid, Unsupported TDD mode %d\n", + AssertFatal(1 == 0, "subframe2_harq_pid, Unsupported TDD mode %d\n", (int) cc->tdd_Config->subframeAssignment); break; } } - AssertFatal(ret != -1, - "invalid harq_pid(%d) at SFN/SF = %d/%d\n", (int8_t) ret, - frameP, subframeP); + AssertFatal(ret != -1, "invalid harq_pid(%d) at SFN/SF = %d/%d\n", (int8_t) ret, + frameP, + subframeP); return ret; } - -uint16_t getRIV(uint16_t N_RB_DL, uint16_t RBstart, uint16_t Lcrbs) { +//------------------------------------------------------------------------------ +uint16_t +getRIV(uint16_t N_RB_DL, + uint16_t RBstart, + uint16_t Lcrbs) +//------------------------------------------------------------------------------ +{ uint16_t RIV; if (Lcrbs <= (1 + (N_RB_DL >> 1))) @@ -2436,12 +2656,17 @@ uint16_t getRIV(uint16_t N_RB_DL, uint16_t RBstart, uint16_t Lcrbs) { else RIV = (N_RB_DL * (N_RB_DL + 1 - Lcrbs)) + (N_RB_DL - 1 - RBstart); - return (RIV); + return RIV; } +//------------------------------------------------------------------------------ uint32_t -allocate_prbs(int UE_id, unsigned char nb_rb, int N_RB_DL, - uint32_t *rballoc) { +allocate_prbs(int UE_id, + unsigned char nb_rb, + int N_RB_DL, + uint32_t *rballoc) +//------------------------------------------------------------------------------ +{ int i; uint32_t rballoc_dci = 0; unsigned char nb_rb_alloc = 0; @@ -2468,7 +2693,12 @@ allocate_prbs(int UE_id, unsigned char nb_rb, int N_RB_DL, return (rballoc_dci); } -int get_bw_index(module_id_t module_id, uint8_t CC_id) { +//------------------------------------------------------------------------------ +int +get_bw_index(module_id_t module_id, + uint8_t CC_id) +//------------------------------------------------------------------------------ +{ int bw_index = 0; int N_RB_DL = to_prb(RC.mac[module_id]->common_channels[CC_id].mib->message.dl_Bandwidth); @@ -2491,16 +2721,22 @@ int get_bw_index(module_id_t module_id, uint8_t CC_id) { default: bw_index = 1; - LOG_W(MAC, - "[eNB %d] N_RB_DL %d unknown for CC_id %d, setting bw_index to 1\n", - module_id, N_RB_DL, CC_id); + LOG_W(MAC, "[eNB %d] N_RB_DL %d unknown for CC_id %d, setting bw_index to 1\n", + module_id, + N_RB_DL, + CC_id); break; } return bw_index; } -int get_min_rb_unit(module_id_t module_id, uint8_t CC_id) { +//------------------------------------------------------------------------------ +int +get_min_rb_unit(module_id_t module_id, + uint8_t CC_id) +//------------------------------------------------------------------------------ +{ int min_rb_unit = 0; int N_RB_DL = to_prb(RC.mac[module_id]->common_channels[CC_id].mib->message.dl_Bandwidth); @@ -2523,24 +2759,36 @@ int get_min_rb_unit(module_id_t module_id, uint8_t CC_id) { default: min_rb_unit = 2; - LOG_W(MAC, - "[eNB %d] N_DL_RB %d unknown for CC_id %d, setting min_rb_unit to 2\n", - module_id, N_RB_DL, CC_id); + LOG_W(MAC, "[eNB %d] N_DL_RB %d unknown for CC_id %d, setting min_rb_unit to 2\n", + module_id, + N_RB_DL, + CC_id); break; } return min_rb_unit; } +//------------------------------------------------------------------------------ uint32_t -allocate_prbs_sub(int nb_rb, int N_RB_DL, int N_RBG, uint8_t *rballoc) { +allocate_prbs_sub(int nb_rb, + int N_RB_DL, + int N_RBG, + uint8_t *rballoc) +//------------------------------------------------------------------------------ +{ int check = 0; //check1=0,check2=0; uint32_t rballoc_dci = 0; //uint8_t number_of_subbands=13; LOG_T(MAC, "*****Check1RBALLOC****: %d%d%d%d (nb_rb %d,N_RBG %d)\n", - rballoc[3], rballoc[2], rballoc[1], rballoc[0], nb_rb, N_RBG); + rballoc[3], + rballoc[2], + rballoc[1], + rballoc[0], + nb_rb, + N_RBG); - while ((nb_rb > 0) && (check < N_RBG)) { + while (nb_rb > 0 && check < N_RBG) { //printf("rballoc[%d] %d\n",check,rballoc[check]); if (rballoc[check] == 1) { rballoc_dci |= (1 << ((N_RBG - 1) - check)); @@ -2556,7 +2804,6 @@ allocate_prbs_sub(int nb_rb, int N_RB_DL, int N_RBG, uint8_t *rballoc) { } else { nb_rb -= 2; } - break; case 50: @@ -2565,7 +2812,6 @@ allocate_prbs_sub(int nb_rb, int N_RB_DL, int N_RBG, uint8_t *rballoc) { } else { nb_rb -= 3; } - break; case 100: @@ -2575,24 +2821,33 @@ allocate_prbs_sub(int nb_rb, int N_RB_DL, int N_RBG, uint8_t *rballoc) { } // printf("rb_alloc %x\n",rballoc_dci); - check = check + 1; + check++; // check1 = check1+2; } // rballoc_dci = (rballoc_dci)&(0x1fff); - LOG_T(MAC, "*********RBALLOC : %x\n", rballoc_dci); + LOG_T(MAC, "*********RBALLOC : %x\n", + rballoc_dci); // exit(-1); - return (rballoc_dci); + return rballoc_dci; } -int get_subbandsize(uint8_t dl_Bandwidth) { +//------------------------------------------------------------------------------ +int +get_subbandsize(uint8_t dl_Bandwidth) +//------------------------------------------------------------------------------ +{ uint8_t ss[6] = { 6, 4, 4, 6, 8, 8 }; AssertFatal(dl_Bandwidth < 6, "dl_Bandwidth %d is out of bounds\n", dl_Bandwidth); return (ss[dl_Bandwidth]); } -int get_nb_subband(int N_RB_DL) { +//------------------------------------------------------------------------------ +int +get_nb_subband(int N_RB_DL) +//------------------------------------------------------------------------------ +{ int nb_sb = 0; switch (N_RB_DL) { @@ -2632,7 +2887,9 @@ void init_CCE_table(int module_idP, int CC_idP) { - memset(RC.mac[module_idP]->CCE_table[CC_idP], 0, 800 * sizeof(int)); + memset(RC.mac[module_idP]->CCE_table[CC_idP], + 0, + 800 * sizeof(int)); } */ void @@ -2641,12 +2898,16 @@ init_CCE_table(int *CCE_table) memset(CCE_table, 0, 800 * sizeof(int)); } +//------------------------------------------------------------------------------ int get_nCCE_offset(int *CCE_table, const unsigned char L, const int nCCE, const int common_dci, - const unsigned short rnti, const unsigned char subframe) { + const unsigned short rnti, + const unsigned char subframe) +//------------------------------------------------------------------------------ +{ int search_space_free, m, nb_candidates = 0, l, i; unsigned int Yk; @@ -2676,70 +2937,82 @@ get_nCCE_offset(int *CCE_table, if (search_space_free == 1) { // printf("returning %d\n",m*L); - for (l = 0; l < L; l++) + for (l = 0; l < L; l++) { CCE_table[(m * L) + l] = 1; - + } return (m * L); } } - return (-1); - } else { // Find first available in ue specific search space - // according to procedure in Section 9.1.1 of 36.213 (v. 8.6) - // compute Yk - Yk = (unsigned int) rnti; + return -1; + } + // Find first available in ue specific search space + // according to procedure in Section 9.1.1 of 36.213 (v. 8.6) + // compute Yk + Yk = (unsigned int) rnti; - for (i = 0; i <= subframe; i++) - Yk = (Yk * 39827) % 65537; - - Yk = Yk % (nCCE / L); - - switch (L) { - case 1: - case 2: - nb_candidates = 6; - break; - - case 4: - case 8: - nb_candidates = 2; - break; - - default: - DevParam(L, nCCE, rnti); - break; - } - - LOG_D(MAC, "rnti %x, Yk = %d, nCCE %d (nCCE/L %d),nb_cand %d\n", - rnti, Yk, nCCE, nCCE / L, nb_candidates); - - for (m = 0; m < nb_candidates; m++) { - search_space_free = 1; - - for (l = 0; l < L; l++) { - int cce = (((Yk + m) % (nCCE / L)) * L) + l; - - if (cce >= nCCE || CCE_table[cce] == 1) { - search_space_free = 0; - break; - } - } - - if (search_space_free == 1) { - for (l = 0; l < L; l++) - CCE_table[(((Yk + m) % (nCCE / L)) * L) + l] = 1; - - return (((Yk + m) % (nCCE / L)) * L); - } - } - - return (-1); + for (i = 0; i <= subframe; i++) { + Yk = (Yk * 39827) % 65537; } + Yk = Yk % (nCCE / L); + + switch (L) { + case 1: + case 2: + nb_candidates = 6; + break; + + case 4: + case 8: + nb_candidates = 2; + break; + + default: + DevParam(L, + nCCE, + rnti); + break; + } + + LOG_D(MAC, "rnti %x, Yk = %d, nCCE %d (nCCE/L %d),nb_cand %d\n", + rnti, + Yk, + nCCE, + nCCE / L, + nb_candidates); + + for (m = 0; m < nb_candidates; m++) { + search_space_free = 1; + + for (l = 0; l < L; l++) { + int cce = (((Yk + m) % (nCCE / L)) * L) + l; + + if (cce >= nCCE || CCE_table[cce] == 1) { + search_space_free = 0; + break; + } + } + + if (search_space_free == 1) { + for (l = 0; l < L; l++) { + CCE_table[(((Yk + m) % (nCCE / L)) * L) + l] = 1; + } + return (((Yk + m) % (nCCE / L)) * L); + } + } + + return -1; } +//------------------------------------------------------------------------------ void -dump_CCE_table(int *CCE_table, const int nCCE, - const unsigned short rnti, const int subframe, int L) { +dump_CCE_table(int *CCE_table, + const int nCCE, + const unsigned short rnti, + const int subframe, + int L) +//------------------------------------------------------------------------------ +{ int nb_candidates = 0, i; unsigned int Yk; printf("CCE 0: "); @@ -2748,14 +3021,15 @@ dump_CCE_table(int *CCE_table, const int nCCE, printf("%1d.", CCE_table[i]); if ((i & 7) == 7) - printf("\n CCE %d: ", i); + printf("\n CCE %d: ", + i); } Yk = (unsigned int) rnti; - for (i = 0; i <= subframe; i++) + for (i = 0; i <= subframe; i++) { Yk = (Yk * 39827) % 65537; - + } Yk = Yk % (nCCE / L); switch (L) { @@ -2774,12 +3048,21 @@ dump_CCE_table(int *CCE_table, const int nCCE, break; } - printf("rnti %x, Yk*L = %u, nCCE %d (nCCE/L %d),nb_cand*L %d\n", rnti, - Yk * L, nCCE, nCCE / L, nb_candidates * L); + LOG_I(PHY, "rnti %x, Yk*L = %u, nCCE %d (nCCE/L %d),nb_cand*L %d\n", + rnti, + Yk * L, + nCCE, + nCCE / L, + nb_candidates * L); } +//------------------------------------------------------------------------------ uint16_t -getnquad(COMMON_channels_t *cc, uint8_t num_pdcch_symbols, uint8_t mi) { +getnquad(COMMON_channels_t *cc, + uint8_t num_pdcch_symbols, + uint8_t mi) +//------------------------------------------------------------------------------ +{ uint16_t Nreg = 0; AssertFatal(cc != NULL, "cc is null\n"); AssertFatal(cc->mib != NULL, "cc->mib is null\n"); @@ -2787,16 +3070,16 @@ getnquad(COMMON_channels_t *cc, uint8_t num_pdcch_symbols, uint8_t mi) { int phich_resource = get_phich_resource_times6(cc); uint8_t Ngroup_PHICH = (phich_resource * N_RB_DL) / 48; - if (((phich_resource * N_RB_DL) % 48) > 0) + if (((phich_resource * N_RB_DL) % 48) > 0) { Ngroup_PHICH++; - + } if (cc->Ncp == 1) { Ngroup_PHICH <<= 1; } Ngroup_PHICH *= mi; - if ((num_pdcch_symbols > 0) && (num_pdcch_symbols < 4)) + if (num_pdcch_symbols > 0 && num_pdcch_symbols < 4) switch (N_RB_DL) { case 6: Nreg = 12 + (num_pdcch_symbols - 1) * 18; @@ -2815,20 +3098,32 @@ getnquad(COMMON_channels_t *cc, uint8_t num_pdcch_symbols, uint8_t mi) { break; default: - return (0); + return 0; } // printf("Nreg %d (%d)\n",Nreg,Nreg - 4 - (3*Ngroup_PHICH)); return (Nreg - 4 - (3 * Ngroup_PHICH)); } +//------------------------------------------------------------------------------ uint16_t -getnCCE(COMMON_channels_t *cc, uint8_t num_pdcch_symbols, uint8_t mi) { +getnCCE(COMMON_channels_t *cc, + uint8_t num_pdcch_symbols, + uint8_t mi) +//------------------------------------------------------------------------------ +{ AssertFatal(cc != NULL, "cc is null\n"); - return (getnquad(cc, num_pdcch_symbols, mi) / 9); + return (getnquad(cc, + num_pdcch_symbols, + mi) / 9); } -uint8_t getmi(COMMON_channels_t *cc, int subframe) { +//------------------------------------------------------------------------------ +uint8_t +getmi(COMMON_channels_t *cc, + int subframe) +//------------------------------------------------------------------------------ +{ AssertFatal(cc != NULL, "cc is null\n"); // for FDD @@ -2838,75 +3133,73 @@ uint8_t getmi(COMMON_channels_t *cc, int subframe) { // for TDD switch (cc->tdd_Config->subframeAssignment) { case 0: - if ((subframe == 0) || (subframe == 5)) - return (2); - else - return (1); - - break; + if (subframe == 0 || subframe == 5) { + return 2; + } + return 1; case 1: - if ((subframe == 0) || (subframe == 5)) - return (0); - else - return (1); - - break; + if (subframe == 0 || subframe == 5) { + return 0; + } + return 1; case 2: - if ((subframe == 3) || (subframe == 8)) - return (1); - else - return (0); - - break; + if (subframe == 3 || subframe == 8) { + return 0; + } + return 1; case 3: - if ((subframe == 0) || (subframe == 8) || (subframe == 9)) - return (1); - else - return (0); - - break; + if (subframe == 0 || subframe == 8 || subframe == 9) { + return 1; + } + return 0; case 4: - if ((subframe == 8) || (subframe == 9)) - return (1); - else - return (0); - - break; + if (subframe == 8 || subframe == 9) { + return 1; + } + return 0; case 5: - if (subframe == 8) - return (1); - else - return (0); - - break; + if (subframe == 8) { + return 1; + } + return 0; case 6: - return (1); - break; + return 1; default: - return (0); + break; } + return 0; } +//------------------------------------------------------------------------------ uint16_t -get_nCCE_max(COMMON_channels_t *cc, int num_pdcch_symbols, int subframe) { +get_nCCE_max(COMMON_channels_t *cc, + int num_pdcch_symbols, + int subframe) +//------------------------------------------------------------------------------ +{ AssertFatal(cc != NULL, "cc is null\n"); - return (getnCCE(cc, num_pdcch_symbols, getmi(cc, subframe))); + return (getnCCE(cc, + num_pdcch_symbols, + getmi(cc, + subframe))); } // Allocate the CCEs +//------------------------------------------------------------------------------ int allocate_CCEs(int module_idP, int CC_idP, frame_t frameP, sub_frame_t subframeP, int test_onlyP) +//------------------------------------------------------------------------------ { eNB_MAC_INST *eNB = RC.mac[module_idP]; int *CCE_table = eNB->CCE_table[CC_idP]; @@ -3204,89 +3497,85 @@ try_again: return 0; } -nfapi_ul_config_request_pdu_t *has_ul_grant(module_id_t module_idP, - int CC_idP, uint16_t absSFP, - uint16_t rnti) { - nfapi_ul_config_request_body_t *ul_req; - nfapi_ul_config_request_pdu_t *ul_config_pdu; - ul_req = &RC.mac[module_idP]->UL_req_tmp[CC_idP][absSFP % 10].ul_config_request_body; - ul_config_pdu = &ul_req->ul_config_pdu_list[0]; - LOG_D(MAC, - "Checking for rnti %x UL grant in subframeP %d (num pdu %d)\n", - rnti, absSFP % 10, ul_req->number_of_pdus); +//------------------------------------------------------------------------------ +nfapi_ul_config_request_pdu_t * +has_ul_grant(module_id_t module_idP, + int CC_idP, + uint16_t absSFP, + uint16_t rnti) +//------------------------------------------------------------------------------ +{ + nfapi_ul_config_request_body_t *ul_req = &RC.mac[module_idP]->UL_req_tmp[CC_idP][absSFP % 10].ul_config_request_body; + nfapi_ul_config_request_pdu_t *ul_config_pdu = &ul_req->ul_config_pdu_list[0]; + uint8_t pdu_type; - for (int i = 0; i < ul_req->number_of_pdus; i++) { - LOG_D(MAC, "PDU %d : type %d,rnti %x\n", i,ul_config_pdu[i].pdu_type, rnti); + LOG_D(MAC, "Checking for rnti %x UL grant in subframeP %d (num pdu %d)\n", + rnti, + absSFP % 10, + ul_req->number_of_pdus); - if ((ul_config_pdu[i].pdu_type == NFAPI_UL_CONFIG_ULSCH_PDU_TYPE) - && (ul_config_pdu[i].ulsch_pdu.ulsch_pdu_rel8.rnti == rnti)) - return (&ul_config_pdu[i]); + for (int i = 0; i < ul_req->number_of_pdus; i++, ul_config_pdu++) { + pdu_type = ul_config_pdu->pdu_type; + LOG_D(MAC, "PDU %d : type %d,rnti %x\n", + i, + pdu_type, + rnti); - if ((ul_config_pdu[i].pdu_type == NFAPI_UL_CONFIG_ULSCH_CQI_RI_PDU_TYPE) - && (ul_config_pdu[i].ulsch_cqi_ri_pdu.ulsch_pdu.ulsch_pdu_rel8.rnti == rnti)) - return (&ul_config_pdu[i]); + if (pdu_type == NFAPI_UL_CONFIG_ULSCH_PDU_TYPE && ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.rnti == rnti) + return ul_config_pdu; - if ((ul_config_pdu[i].pdu_type == NFAPI_UL_CONFIG_ULSCH_HARQ_PDU_TYPE) - && (ul_config_pdu[i].ulsch_harq_pdu.ulsch_pdu.ulsch_pdu_rel8.rnti == rnti)) - return (&ul_config_pdu[i]); + if (pdu_type == NFAPI_UL_CONFIG_ULSCH_CQI_RI_PDU_TYPE && ul_config_pdu->ulsch_cqi_ri_pdu.ulsch_pdu.ulsch_pdu_rel8.rnti == rnti) + return ul_config_pdu; - if ((ul_config_pdu[i].pdu_type == NFAPI_UL_CONFIG_ULSCH_CQI_HARQ_RI_PDU_TYPE) - && (ul_config_pdu[i].ulsch_cqi_harq_ri_pdu.ulsch_pdu.ulsch_pdu_rel8.rnti == rnti)) - return (&ul_config_pdu[i]); + if (pdu_type == NFAPI_UL_CONFIG_ULSCH_HARQ_PDU_TYPE && ul_config_pdu->ulsch_harq_pdu.ulsch_pdu.ulsch_pdu_rel8.rnti == rnti) + return ul_config_pdu; - if ((ul_config_pdu[i].pdu_type == NFAPI_UL_CONFIG_UCI_CQI_PDU_TYPE) - && (ul_config_pdu[i].uci_cqi_pdu.ue_information.ue_information_rel8.rnti == rnti)) - return (&ul_config_pdu[i]); + if (pdu_type == NFAPI_UL_CONFIG_ULSCH_CQI_HARQ_RI_PDU_TYPE && ul_config_pdu->ulsch_cqi_harq_ri_pdu.ulsch_pdu.ulsch_pdu_rel8.rnti == rnti) + return ul_config_pdu; - if ((ul_config_pdu[i].pdu_type == NFAPI_UL_CONFIG_UCI_SR_PDU_TYPE) - && (ul_config_pdu[i].uci_sr_pdu.ue_information.ue_information_rel8.rnti == rnti)) - return (&ul_config_pdu[i]); + if (pdu_type == NFAPI_UL_CONFIG_UCI_CQI_PDU_TYPE && ul_config_pdu->uci_cqi_pdu.ue_information.ue_information_rel8.rnti == rnti) + return ul_config_pdu; - if ((ul_config_pdu[i].pdu_type == NFAPI_UL_CONFIG_UCI_HARQ_PDU_TYPE) - && (ul_config_pdu[i].uci_harq_pdu.ue_information.ue_information_rel8.rnti == rnti)) - return (&ul_config_pdu[i]); + if (pdu_type == NFAPI_UL_CONFIG_UCI_SR_PDU_TYPE && ul_config_pdu->uci_sr_pdu.ue_information.ue_information_rel8.rnti == rnti) + return ul_config_pdu; - if ((ul_config_pdu[i].pdu_type == NFAPI_UL_CONFIG_UCI_SR_HARQ_PDU_TYPE) - && (ul_config_pdu[i].uci_sr_harq_pdu.ue_information.ue_information_rel8.rnti == rnti)) - return (&ul_config_pdu[i]); + if (pdu_type == NFAPI_UL_CONFIG_UCI_HARQ_PDU_TYPE && ul_config_pdu->uci_harq_pdu.ue_information.ue_information_rel8.rnti == rnti) + return ul_config_pdu; - if ((ul_config_pdu[i].pdu_type == NFAPI_UL_CONFIG_UCI_CQI_HARQ_PDU_TYPE) - && (ul_config_pdu[i].uci_cqi_harq_pdu.ue_information.ue_information_rel8.rnti == rnti)) - return (&ul_config_pdu[i]); + if (pdu_type == NFAPI_UL_CONFIG_UCI_SR_HARQ_PDU_TYPE && ul_config_pdu->uci_sr_harq_pdu.ue_information.ue_information_rel8.rnti == rnti) + return ul_config_pdu; - if ((ul_config_pdu[i].pdu_type == NFAPI_UL_CONFIG_UCI_CQI_SR_PDU_TYPE) - && (ul_config_pdu[i].uci_cqi_sr_pdu.ue_information.ue_information_rel8.rnti == rnti)) - return (&ul_config_pdu[i]); + if (pdu_type == NFAPI_UL_CONFIG_UCI_CQI_HARQ_PDU_TYPE && ul_config_pdu->uci_cqi_harq_pdu.ue_information.ue_information_rel8.rnti == rnti) + return ul_config_pdu; - if ((ul_config_pdu[i].pdu_type == NFAPI_UL_CONFIG_UCI_CQI_SR_HARQ_PDU_TYPE) - && (ul_config_pdu[i].uci_cqi_sr_harq_pdu.ue_information.ue_information_rel8.rnti == rnti)) - return (&ul_config_pdu[i]); + if (pdu_type == NFAPI_UL_CONFIG_UCI_CQI_SR_PDU_TYPE && ul_config_pdu->uci_cqi_sr_pdu.ue_information.ue_information_rel8.rnti == rnti) + return ul_config_pdu; - if ((ul_config_pdu[i].pdu_type == NFAPI_UL_CONFIG_ULSCH_UCI_CSI_PDU_TYPE) - && (ul_config_pdu[i].ulsch_uci_csi_pdu.ulsch_pdu.ulsch_pdu_rel8.rnti == rnti)) - return (&ul_config_pdu[i]); + if (pdu_type == NFAPI_UL_CONFIG_UCI_CQI_SR_HARQ_PDU_TYPE && ul_config_pdu->uci_cqi_sr_harq_pdu.ue_information.ue_information_rel8.rnti == rnti) + return ul_config_pdu; - if ((ul_config_pdu[i].pdu_type == NFAPI_UL_CONFIG_ULSCH_UCI_HARQ_PDU_TYPE) - && (ul_config_pdu[i].ulsch_uci_harq_pdu.ulsch_pdu.ulsch_pdu_rel8.rnti == rnti)) - return (&ul_config_pdu[i]); + if (pdu_type == NFAPI_UL_CONFIG_ULSCH_UCI_CSI_PDU_TYPE && ul_config_pdu->ulsch_uci_csi_pdu.ulsch_pdu.ulsch_pdu_rel8.rnti == rnti) + return ul_config_pdu; - if ((ul_config_pdu[i].pdu_type == NFAPI_UL_CONFIG_ULSCH_CSI_UCI_HARQ_PDU_TYPE) - && (ul_config_pdu[i].ulsch_csi_uci_harq_pdu.ulsch_pdu.ulsch_pdu_rel8.rnti == rnti)) - return (&ul_config_pdu[i]); + if (pdu_type == NFAPI_UL_CONFIG_ULSCH_UCI_HARQ_PDU_TYPE && ul_config_pdu->ulsch_uci_harq_pdu.ulsch_pdu.ulsch_pdu_rel8.rnti == rnti) + return ul_config_pdu; + + if (pdu_type == NFAPI_UL_CONFIG_ULSCH_CSI_UCI_HARQ_PDU_TYPE && ul_config_pdu->ulsch_csi_uci_harq_pdu.ulsch_pdu.ulsch_pdu_rel8.rnti == rnti) + return ul_config_pdu; } return (NULL); // no ul grant at all for this UE } -//----------------------------------------------------------------------------- +//------------------------------------------------------------------------------ boolean_t CCE_allocation_infeasible(int module_idP, int CC_idP, int format_flag, - int subframe, - int aggregation, - int rnti) -//----------------------------------------------------------------------------- + int subframe, + int aggregation, + int rnti) +//------------------------------------------------------------------------------ { nfapi_dl_config_request_body_t *DL_req = &RC.mac[module_idP]->DL_req[CC_idP].dl_config_request_body; nfapi_dl_config_request_pdu_t *dl_config_pdu = &DL_req->dl_config_pdu_list[DL_req->number_pdu]; @@ -3330,207 +3619,247 @@ CCE_allocation_infeasible(int module_idP, return res; } -void get_retransmission_timing(LTE_TDD_Config_t *tdd_Config, frame_t *frameP, - sub_frame_t *subframeP) { +//------------------------------------------------------------------------------ +void +get_retransmission_timing(LTE_TDD_Config_t *tdd_Config, + frame_t *frameP, + sub_frame_t *subframeP) +//------------------------------------------------------------------------------ +{ if (tdd_Config == NULL) { - if (*subframeP > 1) + if (*subframeP > 1) { *frameP = (*frameP + 1) % 1024; - + } *subframeP = (*subframeP + 8) % 10; } else { switch (tdd_Config->subframeAssignment) { //TODO fill in other TDD configs default: - printf("%s:%d: TODO\n", __FILE__, __LINE__); + printf("%s:%d: TODO\n", + __FILE__, + __LINE__); abort(); + break; case 1: if (*subframeP == 0 || *subframeP == 5) { *subframeP += 19; - *frameP = (*frameP + *subframeP/10) % 1024; + *frameP = (*frameP + (*subframeP / 10)) % 1024; *subframeP %= 10; } else if (*subframeP == 4 || *subframeP == 9) { *subframeP += 16; - *frameP = (*frameP + *subframeP/10) % 1024; + *frameP = (*frameP + (*subframeP / 10)) % 1024; *subframeP %= 10; } else { - AssertFatal(2 == 1, - "Illegal dl subframe %d for tdd config %ld\n", *subframeP, + AssertFatal(2 == 1, "Illegal dl subframe %d for tdd config %ld\n", + *subframeP, tdd_Config->subframeAssignment); } - break; } } + return; } -uint8_t get_dl_subframe_count(int tdd_config_sfa, sub_frame_t subframeP) { - uint8_t tdd1[10] = {1,-1,-1,-1,2,3,-1,-1,-1,4}; // special subframes 1,6 are excluded +//------------------------------------------------------------------------------ +uint8_t +get_dl_subframe_count(int tdd_config_sfa, + sub_frame_t subframeP) +//------------------------------------------------------------------------------ +{ + uint8_t tdd1[10] = {1, -1, -1, -1, 2, 3, -1, -1, -1, 4}; // special subframes 1,6 are excluded - switch(tdd_config_sfa) { // TODO fill in other tdd configs - case 1 : + switch (tdd_config_sfa) {// TODO fill in other tdd configs + case 1: return tdd1[subframeP]; + } + + return -1; +} + +//------------------------------------------------------------------------------ +uint8_t +frame_subframe2_dl_harq_pid(LTE_TDD_Config_t *tdd_Config, + int abs_frameP, + sub_frame_t subframeP) +//------------------------------------------------------------------------------ +{ + int harq_pid; + uint8_t count; + + if (tdd_Config) { + switch(tdd_Config->subframeAssignment) { //TODO fill in other tdd config + case 1: + count = get_dl_subframe_count(tdd_Config->subframeAssignment, + subframeP); + harq_pid = (((frame_cnt * 1024 + abs_frameP) * 4) - 1 + count) % 7;//4 dl subframe in a frame + + if (harq_pid < 0) { + harq_pid += 7; + } + + LOG_D(MAC,"[frame_subframe2_dl_harq_pid] (%d,%d) calculate harq_pid ((( %d * 1024 + %d) *4) - 1 + %d) = %d \n", + (abs_frameP + 1024) % 1024, + subframeP, + frame_cnt, + abs_frameP, + count, + harq_pid); + return harq_pid; + } + } else { + return ((abs_frameP * 10) + subframeP) & 7; + } + + return -1; +} + +//------------------------------------------------------------------------------ +unsigned char +ul_ACK_subframe2M(LTE_TDD_Config_t *tdd_Config, + unsigned char subframe) +//------------------------------------------------------------------------------ +{ + if (tdd_Config == NULL) { + return 1; + } + switch (tdd_Config->subframeAssignment) { + case 1: + return 1; // don't ACK special subframe for now + /* + if (subframe == 2) { // ACK subframes 5 and 6 + return(2); + } else if (subframe == 3) { // ACK subframe 9 + return(1); // To be updated + } else if (subframe == 7) { // ACK subframes 0 and 1 + return(2); // To be updated + } else if (subframe == 8) { // ACK subframe 4 + return(1); // To be updated + } else { + AssertFatal(1==0,"illegal subframe %d for tdd_config %ld\n", + subframe,tdd_Config->subframeAssignment); + } + break; + */ + case 3: + if (subframe == 2) { // ACK subframes 5 and 6 + return 2; // should be 3 + } + if (subframe == 3) { // ACK subframes 7 and 8 + return 2; // To be updated + } + if (subframe == 4) { // ACK subframes 9 and 0 + return 2; + } + AssertFatal(1==0,"illegal subframe %d for tdd_config %ld\n", + subframe, + tdd_Config->subframeAssignment); + break; + + case 4: + if (subframe == 2) { // ACK subframes 0,4 and 5 + return 3; // should be 4 + } + if (subframe == 3) { // ACK subframes 6,7,8 and 9 + return 4; + } + AssertFatal(1==0,"illegal subframe %d for tdd_config %ld\n", + subframe, + tdd_Config->subframeAssignment); + break; + + case 5: + if (subframe == 2) { // ACK subframes 0,3,4,5,6,7,8 and 9 + return 8; // should be 3 + } + AssertFatal(1==0,"illegal subframe %d for tdd_config %ld\n", + subframe, + tdd_Config->subframeAssignment); break; } - return -1; + return 0; } -uint8_t frame_subframe2_dl_harq_pid(LTE_TDD_Config_t *tdd_Config, int abs_frameP, sub_frame_t subframeP) { - int harq_pid; - - if(tdd_Config) { - switch(tdd_Config->subframeAssignment) { //TODO fill in other tdd config - case 1: - harq_pid = (((frame_cnt*1024 + abs_frameP) * 4) - 1 + get_dl_subframe_count(tdd_Config->subframeAssignment,subframeP))%7;//4 dl subframe in a frame - - if(harq_pid < 0) - harq_pid += 7; - - LOG_D(MAC,"[frame_subframe2_dl_harq_pid] (%d,%d) calculate harq_pid ((( %d * 1024 + %d) *4) - 1 + %d) = %d \n", - (abs_frameP+1024)%1024,subframeP,frame_cnt,abs_frameP, - get_dl_subframe_count(tdd_Config->subframeAssignment,subframeP),harq_pid); - return harq_pid; - break; - } - } else { - return ((abs_frameP*10)+subframeP)&7; - } - - return -1; -} - -unsigned char ul_ACK_subframe2M(LTE_TDD_Config_t *tdd_Config,unsigned char subframe) { +//------------------------------------------------------------------------------ +unsigned char +ul_ACK_subframe2dl_subframe(LTE_TDD_Config_t *tdd_Config, + unsigned char subframe, + unsigned char ACK_index) +//------------------------------------------------------------------------------ +{ if (tdd_Config == NULL) { - return(1); - } else { - switch (tdd_Config->subframeAssignment) { - case 1: - return 1; // don't ACK special subframe for now + return ((subframe < 4) ? subframe + 6 : subframe - 4); + } - if (subframe == 2) { // ACK subframes 5 and 6 - return(2); - } else if (subframe == 3) { // ACK subframe 9 - return(1); // To be updated - } else if (subframe == 7) { // ACK subframes 0 and 1 - return(2); // To be updated - } else if (subframe == 8) { // ACK subframe 4 - return(1); // To be updated - } else { - AssertFatal(1==0,"illegal subframe %d for tdd_config %ld\n", - subframe,tdd_Config->subframeAssignment); - } + switch (tdd_Config->subframeAssignment) { + case 3: + if (subframe == 2) { // ACK subframes 5 and 6 + if (ACK_index == 2) return 1; + return (5 + ACK_index); + } + if (subframe == 3) { // ACK subframes 7 and 8 + return (7 + ACK_index); // To be updated + } + if (subframe == 4) { // ACK subframes 9 and 0 + return ((9 + ACK_index) % 10); + } + AssertFatal(1==0, "illegal subframe %d for tdd_config->subframeAssignment %ld\n", + subframe, + tdd_Config->subframeAssignment); + break; - break; + case 4: + if (subframe == 2) { // ACK subframes 0, 4 and 5 + //if (ACK_index==2) + // return(1); TBC + if (ACK_index == 2) return 0; + return (4 + ACK_index); + } + if (subframe == 3) { // ACK subframes 6, 7 8 and 9 + return (6 + ACK_index); // To be updated + } + AssertFatal(1 == 0, "illegal subframe %d for tdd_config %ld\n", + subframe, + tdd_Config->subframeAssignment); + break; - case 3: - if (subframe == 2) { // ACK subframes 5 and 6 - return(2); // should be 3 - } else if (subframe == 3) { // ACK subframes 7 and 8 - return(2); // To be updated - } else if (subframe == 4) { // ACK subframes 9 and 0 - return(2); - } else { - AssertFatal(1==0,"illegal subframe %d for tdd_config %ld\n", - subframe,tdd_Config->subframeAssignment); - } - - break; - - case 4: - if (subframe == 2) { // ACK subframes 0,4 and 5 - return(3); // should be 4 - } else if (subframe == 3) { // ACK subframes 6,7,8 and 9 - return(4); - } else { - AssertFatal(1==0,"illegal subframe %d for tdd_config %ld\n", - subframe,tdd_Config->subframeAssignment); - } - - break; - - case 5: - if (subframe == 2) { // ACK subframes 0,3,4,5,6,7,8 and 9 - return(8); // should be 3 - } else { - AssertFatal(1==0,"illegal subframe %d for tdd_config %ld\n", - subframe,tdd_Config->subframeAssignment); - } - - break; - } + case 1: + if (subframe == 2) { // ACK subframes 5 and 6 + return (5 + ACK_index); + } + if (subframe == 3) { // ACK subframe 9 + return 9; // To be updated + } + if (subframe == 7) { // ACK subframes 0 and 1 + return ACK_index; // To be updated + } + if (subframe == 8) { // ACK subframe 4 + return 4; // To be updated + } + AssertFatal(1 == 0, "illegal subframe %d for tdd_config %ld\n", + subframe, + tdd_Config->subframeAssignment); + break; } - - return(0); -} - -unsigned char ul_ACK_subframe2dl_subframe(LTE_TDD_Config_t *tdd_Config,unsigned char subframe,unsigned char ACK_index) { - if (tdd_Config == NULL) { - return((subframe<4) ? subframe+6 : subframe-4); - } else { - switch (tdd_Config->subframeAssignment) { - case 3: - if (subframe == 2) { // ACK subframes 5 and 6 - if (ACK_index==2) - return(1); - - return(5+ACK_index); - } else if (subframe == 3) { // ACK subframes 7 and 8 - return(7+ACK_index); // To be updated - } else if (subframe == 4) { // ACK subframes 9 and 0 - return((9+ACK_index)%10); - } else { - AssertFatal(1==0,"illegal subframe %d for tdd_config->subframeAssignment %ld\n", - subframe,tdd_Config->subframeAssignment); - } - - break; - - case 4: - if (subframe == 2) { // ACK subframes 0, 4 and 5 - //if (ACK_index==2) - // return(1); TBC - if (ACK_index==2) - return(0); - - return(4+ACK_index); - } else if (subframe == 3) { // ACK subframes 6, 7 8 and 9 - return(6+ACK_index); // To be updated - } else { - AssertFatal(1==0,"illegal subframe %d for tdd_config %ld\n", - subframe,tdd_Config->subframeAssignment); - } - - break; - - case 1: - if (subframe == 2) { // ACK subframes 5 and 6 - return(5+ACK_index); - } else if (subframe == 3) { // ACK subframe 9 - return(9); // To be updated - } else if (subframe == 7) { // ACK subframes 0 and 1 - return(ACK_index); // To be updated - } else if (subframe == 8) { // ACK subframe 4 - return(4); // To be updated - } else { - AssertFatal(1==0,"illegal subframe %d for tdd_config %ld\n", - subframe,tdd_Config->subframeAssignment); - } - - break; - } - } - - return(0); + return 0; } +//------------------------------------------------------------------------------ void -extract_harq(module_id_t mod_idP, int CC_idP, int UE_id, - frame_t frameP, sub_frame_t subframeP, - void *harq_indication, int format) { - UE_list_t *UE_list = &RC.mac[mod_idP]->UE_list; +extract_harq(module_id_t mod_idP, + int CC_idP, + int UE_id, + frame_t frameP, + sub_frame_t subframeP, + void *harq_indication, + int format) +//------------------------------------------------------------------------------ +{ + eNB_MAC_INST *eNB = RC.mac[mod_idP]; + UE_list_t *UE_list = &eNB->UE_list; UE_sched_ctrl *sched_ctl = &UE_list->UE_sched_ctrl[UE_id]; rnti_t rnti = UE_RNTI(mod_idP, UE_id); - COMMON_channels_t *cc = &RC.mac[mod_idP]->common_channels[CC_idP]; + COMMON_channels_t *cc = &eNB->common_channels[CC_idP]; nfapi_harq_indication_fdd_rel13_t *harq_indication_fdd; nfapi_harq_indication_tdd_rel13_t *harq_indication_tdd; uint16_t num_ack_nak; @@ -3543,22 +3872,22 @@ extract_harq(module_id_t mod_idP, int CC_idP, int UE_id, sub_frame_t subframe_tx; int frame_tx; uint8_t harq_pid; + #if (LTE_RRC_VERSION >= MAKE_VERSION(13, 0, 0)) - - if (UE_list->UE_template[pCCid][UE_id].physicalConfigDedicated != NULL && - UE_list->UE_template[pCCid][UE_id].physicalConfigDedicated->pucch_ConfigDedicated != NULL && - (UE_list->UE_template[pCCid][UE_id].physicalConfigDedicated->ext7) - && (UE_list->UE_template[pCCid][UE_id].physicalConfigDedicated->ext7->pucch_ConfigDedicated_r13) - && (((UE_list->UE_template[pCCid][UE_id].physicalConfigDedicated->ext7->pucch_ConfigDedicated_r13->spatialBundlingPUCCH_r13) && (format == 0)) - || ((UE_list->UE_template[pCCid][UE_id].physicalConfigDedicated->ext7->pucch_ConfigDedicated_r13->spatialBundlingPUSCH_r13) - && (format == 1)))) + LTE_PhysicalConfigDedicated_t *physicalConfigDedicated = UE_list->UE_template[pCCid][UE_id].physicalConfigDedicated; + if (physicalConfigDedicated != NULL && physicalConfigDedicated->pucch_ConfigDedicated != NULL && + physicalConfigDedicated->ext7 != NULL && physicalConfigDedicated->ext7->pucch_ConfigDedicated_r13 != NULL && + ((physicalConfigDedicated->ext7->pucch_ConfigDedicated_r13->spatialBundlingPUCCH_r13 && format == 0) || + (physicalConfigDedicated->ext7->pucch_ConfigDedicated_r13->spatialBundlingPUSCH_r13 && format == 1))) { spatial_bundling = 1; - -#endif - - for (i = 0; i < numCC; i++) - tmode[i] = get_tmode(mod_idP, i, UE_id); - + } +#endif + + for (i = 0; i < numCC; i++) { + tmode[i] = get_tmode(mod_idP, + i, + UE_id); + } if (cc->tdd_Config) { harq_indication_tdd = (nfapi_harq_indication_tdd_rel13_t *) harq_indication; // pdu = &harq_indication_tdd->harq_tb_n[0]; @@ -3566,42 +3895,61 @@ extract_harq(module_id_t mod_idP, int CC_idP, int UE_id, switch (harq_indication_tdd->mode) { case 0: // Format 1a/b bundling - AssertFatal(numCC == 1, "numCC %d > 1, should not be using Format1a/b\n", numCC); - int M = ul_ACK_subframe2M(cc->tdd_Config,subframeP); + AssertFatal(numCC == 1, "numCC %d > 1, should not be using Format1a/b\n", + numCC); + int M = ul_ACK_subframe2M(cc->tdd_Config, + subframeP); - for(m=0; mtdd_Config,subframeP,m); + for (m=0; mtdd_Config, + subframeP, + m); - if(frameP==1023&&subframeP>5) - frame_tx=-1; - else - frame_tx = subframeP < 4 ? frameP -1 : frameP; + if (frameP==1023&&subframeP>5) frame_tx=-1; + else frame_tx = subframeP < 4 ? frameP -1 : frameP; - harq_pid = frame_subframe2_dl_harq_pid(cc->tdd_Config,frame_tx,subframe_tx); - RA_t *ra = &RC.mac[mod_idP]->common_channels[CC_idP].ra[0]; + harq_pid = frame_subframe2_dl_harq_pid(cc->tdd_Config, + frame_tx, + subframe_tx); + RA_t *ra = &eNB->common_channels[CC_idP].ra[0]; - if(num_ack_nak==1) { - if(harq_indication_tdd->harq_data[0].bundling.value_0==1) { //ack + if(num_ack_nak == 1) { + if (harq_indication_tdd->harq_data[0].bundling.value_0 == 1) { //ack sched_ctl->round[CC_idP][harq_pid] = 8; // release HARQ process sched_ctl->tbcnt[CC_idP][harq_pid] = 0; - LOG_D(MAC,"frame %d subframe %d Acking (%d,%d) harq_pid %d round %d\n",frameP,subframeP,frame_tx,subframe_tx,harq_pid,sched_ctl->round[CC_idP][harq_pid]); + LOG_D(MAC, "frame %d subframe %d Acking (%d,%d) harq_pid %d round %d\n", + frameP, + subframeP, + frame_tx, + subframe_tx, + harq_pid, + sched_ctl->round[CC_idP][harq_pid]); } else { //nack - if( sched_ctl->round[CC_idP][harq_pid]<8) sched_ctl->round[CC_idP][harq_pid]++; + if (sched_ctl->round[CC_idP][harq_pid] < 8) sched_ctl->round[CC_idP][harq_pid]++; if (sched_ctl->round[CC_idP][harq_pid] == 4) { sched_ctl->round[CC_idP][harq_pid] = 8; // release HARQ process sched_ctl->tbcnt[CC_idP][harq_pid] = 0; } - LOG_D(MAC,"frame %d subframe %d Nacking (%d,%d) harq_pid %d round %d\n",frameP,subframeP,frame_tx,subframe_tx,harq_pid,sched_ctl->round[CC_idP][harq_pid]); + LOG_D(MAC,"frame %d subframe %d Nacking (%d,%d) harq_pid %d round %d\n", + frameP, + subframeP, + frame_tx, + subframe_tx, + harq_pid, + sched_ctl->round[CC_idP][harq_pid]); - if(sched_ctl->round[CC_idP][harq_pid] == 8) { + if (sched_ctl->round[CC_idP][harq_pid] == 8) { for (uint8_t ra_i = 0; ra_i < NB_RA_PROC_MAX; ra_i++) { - if((ra[ra_i].rnti == rnti) && (ra[ra_i].state == WAITMSG4ACK)) { + if (ra[ra_i].rnti == rnti && ra[ra_i].state == WAITMSG4ACK) { //Msg NACK num to MAC ,remove UE // add UE info to freeList - LOG_I(RRC, "put UE %x into freeList\n", rnti); - put_UE_in_freelist(mod_idP, rnti, 1); + LOG_I(RRC, "put UE %x into freeList\n", + rnti); + put_UE_in_freelist(mod_idP, + rnti, + 1); } } } @@ -3609,17 +3957,27 @@ extract_harq(module_id_t mod_idP, int CC_idP, int UE_id, } for (uint8_t ra_i = 0; ra_i < NB_RA_PROC_MAX; ra_i++) { - if ((ra[ra_i].rnti == rnti) && (ra[ra_i].state == MSGCRNTI_ACK) && (ra[ra_i].crnti_harq_pid == harq_pid)) { - LOG_D(MAC,"CRNTI Reconfiguration: ACK %d rnti %x round %d frame %d subframe %d \n",harq_indication_tdd->harq_data[0].bundling.value_0,rnti,sched_ctl->round[CC_idP][harq_pid],frameP,subframeP); + if (ra[ra_i].rnti == rnti && ra[ra_i].state == MSGCRNTI_ACK && ra[ra_i].crnti_harq_pid == harq_pid) { + LOG_D(MAC,"CRNTI Reconfiguration: ACK %d rnti %x round %d frame %d subframe %d \n", + harq_indication_tdd->harq_data[0].bundling.value_0, + rnti, + sched_ctl->round[CC_idP][harq_pid], + frameP, + subframeP); - if(num_ack_nak == 1 && harq_indication_tdd->harq_data[0].bundling.value_0 == 1) { - cancel_ra_proc(mod_idP, CC_idP, frameP, ra[ra_i].rnti); + if (num_ack_nak == 1 && harq_indication_tdd->harq_data[0].bundling.value_0 == 1) { + cancel_ra_proc(mod_idP, + CC_idP, + frameP, + ra[ra_i].rnti); } else { if(sched_ctl->round[CC_idP][harq_pid] == 7) { - cancel_ra_proc(mod_idP, CC_idP, frameP, ra[ra_i].rnti); + cancel_ra_proc(mod_idP, + CC_idP, + frameP, + ra[ra_i].rnti); } } - break; } } @@ -3628,14 +3986,8 @@ extract_harq(module_id_t mod_idP, int CC_idP, int UE_id, break; case 1: // Channel Selection - break; - case 2: // Format 3 - break; - case 3: // Format 4 - break; - case 4: // Format 5 break; } @@ -3644,58 +3996,81 @@ extract_harq(module_id_t mod_idP, int CC_idP, int UE_id, num_ack_nak = harq_indication_fdd->number_of_ack_nack; pdu = &harq_indication_fdd->harq_tb_n[0]; harq_pid = ((10 * frameP) + subframeP + 10236) & 7; - LOG_D(MAC,"frame %d subframe %d harq_pid %d mode %d tmode[0] %d num_ack_nak %d round %d\n",frameP,subframeP,harq_pid,harq_indication_fdd->mode,tmode[0],num_ack_nak,sched_ctl->round[CC_idP][harq_pid]); + LOG_D(MAC, "frame %d subframe %d harq_pid %d mode %d tmode[0] %d num_ack_nak %d round %d\n", + frameP, + subframeP, + harq_pid, + harq_indication_fdd->mode, + tmode[0], + num_ack_nak, + sched_ctl->round[CC_idP][harq_pid]); // use 1 HARQ proces of BL/CE UE for now if (UE_list->UE_template[pCCid][UE_id].rach_resource_type > 0) harq_pid = 0; switch (harq_indication_fdd->mode) { - case 0: // Format 1a/b (10.1.2.1) - AssertFatal(numCC == 1, "numCC %d > 1, should not be using Format1a/b\n", numCC); - if (tmode[0] == 1 || tmode[0] == 2 || tmode[0] == 5 || tmode[0] == 6 || tmode[0] == 7) { // NOTE: have to handle the case of TM9-10 with 1 antenna port + case 0: // Format 1a/b (10.1.2.1) + AssertFatal(numCC == 1, "numCC %d > 1, should not be using Format1a/b\n", + numCC); + + if (tmode[0] == 1 || tmode[0] == 2 || tmode[0] == 5 || tmode[0] == 6 || tmode[0] == 7) { // NOTE: have to handle the case of TM9-10 with 1 antenna port // single ACK/NAK bit - AssertFatal(num_ack_nak == 1, "num_ack_nak %d > 1 for 1 CC and single-layer transmission frame:%d subframe:%d\n", num_ack_nak,frameP,subframeP); + AssertFatal(num_ack_nak == 1, "num_ack_nak %d > 1 for 1 CC and single-layer transmission frame:%d subframe:%d\n", + num_ack_nak, + frameP, + subframeP); // In case of nFAPI, sometimes timing of eNB and UE become different. - // So if nfapi_mode == 2(VNF) , this function don't check assertion to avoid process exit. + // So if nfapi_mode == 2(VNF), this function don't check assertion to avoid process exit. if (nfapi_mode != 2) { AssertFatal(sched_ctl->round[CC_idP][harq_pid] < 8, "Got ACK/NAK for inactive harq_pid %d for UE %d/%x\n", - harq_pid, - UE_id, - rnti); + harq_pid, + UE_id, + rnti); } else { if (sched_ctl->round[CC_idP][harq_pid] == 8) { - LOG_E(MAC,"Got ACK/NAK for inactive harq_pid %d for UE %d/%x\n", harq_pid, UE_id, rnti); + LOG_E(MAC,"Got ACK/NAK for inactive harq_pid %d for UE %d/%x\n", + harq_pid, + UE_id, + rnti); return; } } AssertFatal(pdu[0] == 1 || pdu[0] == 2 || pdu[0] == 4, "Received ACK/NAK %d which is not 1 or 2 for harq_pid %d from UE %d/%x\n", - pdu[0], - harq_pid, - UE_id, - rnti); + pdu[0], + harq_pid, + UE_id, + rnti); - LOG_D(MAC, "Received %d for harq_pid %d\n", pdu[0], harq_pid); + LOG_D(MAC, "Received %d for harq_pid %d\n", + pdu[0], + harq_pid); - RA_t *ra = &RC.mac[mod_idP]->common_channels[CC_idP].ra[0]; + RA_t *ra = &eNB->common_channels[CC_idP].ra[0]; for (uint8_t ra_i = 0; ra_i < NB_RA_PROC_MAX; ra_i++) { - if ((ra[ra_i].rnti == rnti) && (ra[ra_i].state == MSGCRNTI_ACK) && (ra[ra_i].crnti_harq_pid == harq_pid)) { + if (ra[ra_i].rnti == rnti && ra[ra_i].state == MSGCRNTI_ACK && ra[ra_i].crnti_harq_pid == harq_pid) { LOG_D(MAC,"CRNTI Reconfiguration: ACK %d rnti %x round %d frame %d subframe %d \n", pdu[0], rnti, sched_ctl->round[CC_idP][harq_pid], - frameP,subframeP); + frameP, + subframeP); if (pdu[0] == 1) { - cancel_ra_proc(mod_idP, CC_idP, frameP, ra[ra_i].rnti); + cancel_ra_proc(mod_idP, + CC_idP, + frameP, + ra[ra_i].rnti); } else { - if(sched_ctl->round[CC_idP][harq_pid] == 7) { - cancel_ra_proc(mod_idP, CC_idP, frameP, ra[ra_i].rnti); + if (sched_ctl->round[CC_idP][harq_pid] == 7) { + cancel_ra_proc(mod_idP, + CC_idP, + frameP, + ra[ra_i].rnti); } } - break; } } @@ -3716,22 +4091,21 @@ extract_harq(module_id_t mod_idP, int CC_idP, int UE_id, if((ra[ra_i].rnti == rnti) && (ra[ra_i].state == WAITMSG4ACK)) { //Msg NACK num to MAC ,remove UE // add UE info to freeList - LOG_I(RRC, "put UE %x into freeList\n", rnti); - put_UE_in_freelist(mod_idP, rnti, 1); + LOG_I(RRC, "put UE %x into freeList\n", + rnti); + put_UE_in_freelist(mod_idP, + rnti, + 1); } } } } } else { // one or two ACK/NAK bits - AssertFatal(num_ack_nak <= 2, - "num_ack_nak %d > 2 for 1 CC and TM3/4/8/9/10\n", + AssertFatal(num_ack_nak <= 2, "num_ack_nak %d > 2 for 1 CC and TM3/4/8/9/10\n", num_ack_nak); - if ((num_ack_nak == 2) - && (sched_ctl->round[CC_idP][harq_pid] < 8) - && (sched_ctl->tbcnt[CC_idP][harq_pid] == 1) - && (pdu[0] == 1) && (pdu[1] == 1)) { + if (num_ack_nak == 2 && sched_ctl->round[CC_idP][harq_pid] < 8 && sched_ctl->tbcnt[CC_idP][harq_pid] == 1 && pdu[0] == 1 && pdu[1] == 1) { sched_ctl->round[CC_idP][harq_pid] = 8; sched_ctl->tbcnt[CC_idP][harq_pid] = 0; } @@ -3772,19 +4146,21 @@ extract_harq(module_id_t mod_idP, int CC_idP, int UE_id, sched_ctl->tbcnt[CC_idP][harq_pid] = 0; } } else - AssertFatal(1 == 0, - "Illegal ACK/NAK/round combination (%d,%d,%d,%d,%d) for harq_pid %d, UE %d/%x\n", + AssertFatal(1 == 0, "Illegal ACK/NAK/round combination (%d,%d,%d,%d,%d) for harq_pid %d, UE %d/%x\n", num_ack_nak, sched_ctl->round[CC_idP][harq_pid], - sched_ctl->round[CC_idP][harq_pid], pdu[0], - pdu[1], harq_pid, UE_id, rnti); + sched_ctl->round[CC_idP][harq_pid], + pdu[0], + pdu[1], + harq_pid, + UE_id, + rnti); } break; case 1: // FDD Channel Selection (10.1.2.2.1), must be received for 2 serving cells - AssertFatal(numCC == 2, - "Should not receive harq indication with channel selection with %d active CCs\n", + AssertFatal(numCC == 2, "Should not receive harq indication with channel selection with %d active CCs\n", numCC); if ((num_ack_nak == 2) @@ -3826,18 +4202,21 @@ extract_harq(module_id_t mod_idP, int CC_idP, int UE_id, pdu[1]); AssertFatal(pdu[2] <= 3, "pdu[2] %d is not ACK/NAK/DTX\n", pdu[2]); - AssertFatal(sched_ctl->tbcnt[pCCid][harq_pid] == 2, - "sched_ctl->tbcnt[%d][%d] != 2 for UE %d/%x\n", - pCCid, harq_pid, UE_id, rnti); - AssertFatal(sched_ctl->tbcnt[1 - pCCid][harq_pid] == 1, - "sched_ctl->tbcnt[%d][%d] != 1 for UE %d/%x\n", - 1 - pCCid, harq_pid, UE_id, rnti); + AssertFatal(sched_ctl->tbcnt[pCCid][harq_pid] == 2, "sched_ctl->tbcnt[%d][%d] != 2 for UE %d/%x\n", + pCCid, + harq_pid, + UE_id, + rnti); + AssertFatal(sched_ctl->tbcnt[1 - pCCid][harq_pid] == 1, "sched_ctl->tbcnt[%d][%d] != 1 for UE %d/%x\n", + 1 - pCCid, + harq_pid, + UE_id, + rnti); - if ((pdu[0] == 1) && (pdu[1] == 1)) { // both ACK + if (pdu[0] == 1 && pdu[1] == 1) { // both ACK sched_ctl->round[pCCid][harq_pid] = 8; sched_ctl->tbcnt[pCCid][harq_pid] = 0; - } else if (((pdu[0] == 2) && (pdu[1] == 1)) || - ((pdu[0] == 1) && (pdu[1] == 2))) { + } else if ((pdu[0] == 2 && pdu[1] == 1) || (pdu[0] == 1 && pdu[1] == 2)) { sched_ctl->round[pCCid][harq_pid]++; sched_ctl->tbcnt[pCCid][harq_pid] = 1; @@ -3854,8 +4233,7 @@ extract_harq(module_id_t mod_idP, int CC_idP, int UE_id, } } - if (pdu[2] == 1) - sched_ctl->round[1 - pCCid][harq_pid] = 8; + if (pdu[2] == 1) sched_ctl->round[1 - pCCid][harq_pid] = 8; else { sched_ctl->round[1 - pCCid][harq_pid]++; @@ -3875,18 +4253,21 @@ extract_harq(module_id_t mod_idP, int CC_idP, int UE_id, pdu[1]); AssertFatal(pdu[2] <= 3, "pdu[2] %d is not ACK/NAK/DTX\n", pdu[2]); - AssertFatal(sched_ctl->tbcnt[1 - pCCid][harq_pid] == 2, - "sched_ctl->tbcnt[%d][%d] != 2 for UE %d/%x\n", - 1 - pCCid, harq_pid, UE_id, rnti); - AssertFatal(sched_ctl->tbcnt[pCCid][harq_pid] == 1, - "sched_ctl->tbcnt[%d][%d] != 1 for UE %d/%x\n", - pCCid, harq_pid, UE_id, rnti); + AssertFatal(sched_ctl->tbcnt[1 - pCCid][harq_pid] == 2, "sched_ctl->tbcnt[%d][%d] != 2 for UE %d/%x\n", + 1 - pCCid, + harq_pid, + UE_id, + rnti); + AssertFatal(sched_ctl->tbcnt[pCCid][harq_pid] == 1, "sched_ctl->tbcnt[%d][%d] != 1 for UE %d/%x\n", + pCCid, + harq_pid, + UE_id, + rnti); - if ((pdu[0] == 1) && (pdu[1] == 1)) { // both ACK + if (pdu[0] == 1 && pdu[1] == 1) { // both ACK sched_ctl->round[1 - pCCid][harq_pid] = 8; sched_ctl->tbcnt[1 - pCCid][harq_pid] = 0; - } else if (((pdu[0] >= 2) && (pdu[1] == 1)) - || ((pdu[0] == 1) && (pdu[1] >= 2))) { // one ACK + } else if ((pdu[0] >= 2 && pdu[1] == 1) || (pdu[0] == 1 && pdu[1] >= 2)) { // one ACK sched_ctl->round[1 - pCCid][harq_pid]++; sched_ctl->tbcnt[1 - pCCid][harq_pid] = 1; @@ -3903,8 +4284,7 @@ extract_harq(module_id_t mod_idP, int CC_idP, int UE_id, } } - if (pdu[2] == 1) - sched_ctl->round[pCCid][harq_pid] = 8; + if (pdu[2] == 1) sched_ctl->round[pCCid][harq_pid] = 8; else { sched_ctl->round[pCCid][harq_pid]++; @@ -3928,18 +4308,19 @@ extract_harq(module_id_t mod_idP, int CC_idP, int UE_id, pdu[2]); AssertFatal(pdu[3] <= 3, "pdu[3] %d is not ACK/NAK/DTX\n", pdu[3]); - AssertFatal(sched_ctl->tbcnt[0][harq_pid] == 2, - "sched_ctl->tbcnt[0][%d] != 2 for UE %d/%x\n", - harq_pid, UE_id, rnti); - AssertFatal(sched_ctl->tbcnt[1][harq_pid] == 2, - "sched_ctl->tbcnt[1][%d] != 2 for UE %d/%x\n", - harq_pid, UE_id, rnti); + AssertFatal(sched_ctl->tbcnt[0][harq_pid] == 2, "sched_ctl->tbcnt[0][%d] != 2 for UE %d/%x\n", + harq_pid, + UE_id, + rnti); + AssertFatal(sched_ctl->tbcnt[1][harq_pid] == 2, "sched_ctl->tbcnt[1][%d] != 2 for UE %d/%x\n", + harq_pid, + UE_id, + rnti); - if ((pdu[0] == 1) && (pdu[1] == 1)) { // both ACK + if (pdu[0] == 1 && pdu[1] == 1) { // both ACK sched_ctl->round[0][harq_pid] = 8; sched_ctl->tbcnt[0][harq_pid] = 0; - } else if (((pdu[0] >= 2) && (pdu[1] == 1)) - || ((pdu[0] == 1) && (pdu[1] >= 2))) { // one ACK + } else if ((pdu[0] >= 2 && pdu[1] == 1) || (pdu[0] == 1 && pdu[1] >= 2)) { // one ACK sched_ctl->round[0][harq_pid]++; sched_ctl->tbcnt[0][harq_pid] = 1; @@ -3956,11 +4337,10 @@ extract_harq(module_id_t mod_idP, int CC_idP, int UE_id, } } - if ((pdu[2] == 1) && (pdu[3] == 1)) { // both ACK + if (pdu[2] == 1 && pdu[3] == 1) { // both ACK sched_ctl->round[1][harq_pid] = 8; sched_ctl->tbcnt[1][harq_pid] = 0; - } else if (((pdu[2] >= 2) && (pdu[3] == 1)) - || ((pdu[2] == 1) && (pdu[3] >= 2))) { // one ACK + } else if ((pdu[2] >= 2 && pdu[3] == 1) || (pdu[2] == 1 && pdu[3] >= 2)) { // one ACK sched_ctl->round[1][harq_pid]++; sched_ctl->tbcnt[1][harq_pid] = 1; @@ -3982,14 +4362,12 @@ extract_harq(module_id_t mod_idP, int CC_idP, int UE_id, break; case 2: // Format 3 - AssertFatal(numCC > 2, - "Should not receive harq indication with FDD format 3 with %d < 3 active CCs\n", + AssertFatal(numCC > 2, "Should not receive harq indication with FDD format 3 with %d < 3 active CCs\n", numCC); for (i = 0, j = 0; i < numCC; i++) { - if ((sched_ctl->round[i][harq_pid] < 8)) { - if (tmode[i] == 1 || tmode[i] == 2 || tmode[0] == 5 - || tmode[0] == 6 || tmode[0] == 7) { + if (sched_ctl->round[i][harq_pid] < 8) { + if (tmode[i] == 1 || tmode[i] == 2 || tmode[0] == 5 || tmode[0] == 6 || tmode[0] == 7) { if (pdu[j] == 1) { sched_ctl->round[i][harq_pid] = 8; sched_ctl->tbcnt[i][harq_pid] = 0; @@ -4001,18 +4379,19 @@ extract_harq(module_id_t mod_idP, int CC_idP, int UE_id, sched_ctl->tbcnt[i][harq_pid] = 0; } } else - AssertFatal(1 == 0, - "Illegal harq_ack value for CC %d harq_pid %d (%d) UE %d/%x\n", - i, harq_pid, pdu[j], UE_id, rnti); + AssertFatal(1 == 0, "Illegal harq_ack value for CC %d harq_pid %d (%d) UE %d/%x\n", + i, + harq_pid, + pdu[j], + UE_id, + rnti); j++; } else if (spatial_bundling == 0) { - if ((sched_ctl->tbcnt[i][harq_pid] == 2) - && (pdu[j] == 1) && (pdu[j + 1] == 1)) { + if (sched_ctl->tbcnt[i][harq_pid] == 2 && pdu[j] == 1 && pdu[j + 1] == 1) { sched_ctl->round[i][harq_pid] = 8; sched_ctl->tbcnt[i][harq_pid] = 0; - } else if ((sched_ctl->tbcnt[i][harq_pid] == 2) - && (pdu[j] == 1) && (pdu[j + 1] == 2)) { + } else if (sched_ctl->tbcnt[i][harq_pid] == 2 && pdu[j] == 1 && pdu[j + 1] == 2) { sched_ctl->round[i][harq_pid]++; sched_ctl->tbcnt[i][harq_pid] = 1; @@ -4020,8 +4399,7 @@ extract_harq(module_id_t mod_idP, int CC_idP, int UE_id, sched_ctl->round[i][harq_pid] = 8; sched_ctl->tbcnt[i][harq_pid] = 0; } - } else if ((sched_ctl->tbcnt[i][harq_pid] == 2) - && (pdu[j] == 2) && (pdu[j + 1] == 1)) { + } else if (sched_ctl->tbcnt[i][harq_pid] == 2 && pdu[j] == 2 && pdu[j + 1] == 1) { sched_ctl->round[i][harq_pid]++; sched_ctl->tbcnt[i][harq_pid] = 1; @@ -4029,8 +4407,7 @@ extract_harq(module_id_t mod_idP, int CC_idP, int UE_id, sched_ctl->round[i][harq_pid] = 8; sched_ctl->tbcnt[i][harq_pid] = 0; } - } else if ((sched_ctl->tbcnt[i][harq_pid] == 2) - && (pdu[j] == 2) && (pdu[j + 1] == 2)) { + } else if (sched_ctl->tbcnt[i][harq_pid] == 2 && pdu[j] == 2 && pdu[j + 1] == 2) { sched_ctl->round[i][harq_pid]++; if (sched_ctl->round[i][harq_pid] == 4) { @@ -4038,11 +4415,14 @@ extract_harq(module_id_t mod_idP, int CC_idP, int UE_id, sched_ctl->tbcnt[i][harq_pid] = 0; } } else - AssertFatal(1 == 0, - "Illegal combination for CC %d harq_pid %d (%d,%d,%d) UE %d/%x\n", - i, harq_pid, + AssertFatal(1 == 0, "Illegal combination for CC %d harq_pid %d (%d,%d,%d) UE %d/%x\n", + i, + harq_pid, sched_ctl->tbcnt[i][harq_pid], - pdu[j], pdu[j + 1], UE_id, rnti); + pdu[j], + pdu[j + 1], + UE_id, + rnti); j += 2; } else if (spatial_bundling == 1) { @@ -4056,73 +4436,86 @@ extract_harq(module_id_t mod_idP, int CC_idP, int UE_id, sched_ctl->round[i][harq_pid] = 8; sched_ctl->tbcnt[i][harq_pid] = 0; } - } else - AssertFatal(1 == 0, - "Illegal hack_nak value %d for CC %d harq_pid %d UE %d/%x\n", - pdu[j], i, harq_pid, UE_id, rnti); - + } else { + AssertFatal(1 == 0, "Illegal hack_nak value %d for CC %d harq_pid %d UE %d/%x\n", + pdu[j], + i, + harq_pid, + UE_id, + rnti); + } j++; - } else - AssertFatal(1 == 0, - "Illegal value for spatial_bundling %d\n", + } else { + AssertFatal(1 == 0, "Illegal value for spatial_bundling %d\n", spatial_bundling); + } } } break; case 3: // Format 4 - AssertFatal(1 == 0, - "Should not receive harq indication with Format 4\n"); + AssertFatal(1 == 0, "Should not receive harq indication with Format 4\n"); break; case 4: // Format 5 - AssertFatal(1 == 0, - "Should not receive harq indication with Format 5\n"); + AssertFatal(1 == 0, "Should not receive harq indication with Format 5\n"); break; } } + return; } +//------------------------------------------------------------------------------ void -extract_pucch_csi(module_id_t mod_idP, int CC_idP, int UE_id, - frame_t frameP, sub_frame_t subframeP, - uint8_t *pdu, uint8_t length) { +extract_pucch_csi(module_id_t mod_idP, + int CC_idP, + int UE_id, + frame_t frameP, + sub_frame_t subframeP, + uint8_t *pdu, + uint8_t length) +//------------------------------------------------------------------------------ +{ UE_list_t *UE_list = &RC.mac[mod_idP]->UE_list; UE_sched_ctrl *sched_ctl = &UE_list->UE_sched_ctrl[UE_id]; COMMON_channels_t *cc = &RC.mac[mod_idP]->common_channels[CC_idP]; - struct LTE_CQI_ReportPeriodic *cqi_ReportPeriodic; int no_pmi; uint8_t Ltab[6] = { 0, 2, 4, 4, 4, 4 }; uint8_t Jtab[6] = { 0, 2, 2, 3, 4, 4 }; int feedback_cnt; - AssertFatal(UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated != NULL, - "physicalConfigDedicated is null for UE %d\n", UE_id); - AssertFatal(UE_list-> - UE_template[CC_idP][UE_id].physicalConfigDedicated->cqi_ReportConfig != NULL, - "cqi_ReportConfig is null for UE %d\n", UE_id); - AssertFatal((cqi_ReportPeriodic = UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->cqi_ReportConfig->cqi_ReportPeriodic) != NULL, - "cqi_ReportPeriodic is null for UE %d\n", UE_id); + + AssertFatal(UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated != NULL, "physicalConfigDedicated is null for UE %d\n", + UE_id); + AssertFatal(UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->cqi_ReportConfig != NULL, "cqi_ReportConfig is null for UE %d\n", + UE_id); + struct LTE_CQI_ReportPeriodic *cqi_ReportPeriodic = UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->cqi_ReportConfig->cqi_ReportPeriodic; + AssertFatal(cqi_ReportPeriodic != NULL, "cqi_ReportPeriodic is null for UE %d\n", + UE_id); // determine feedback mode - AssertFatal(cqi_ReportPeriodic->present != LTE_CQI_ReportPeriodic_PR_NOTHING, - "cqi_ReportPeriodic->present == LTE_CQI_ReportPeriodic_PR_NOTHING!\n"); + AssertFatal(cqi_ReportPeriodic->present != LTE_CQI_ReportPeriodic_PR_NOTHING, "cqi_ReportPeriodic->present == LTE_CQI_ReportPeriodic_PR_NOTHING!\n"); AssertFatal(cqi_ReportPeriodic->choice.setup.cqi_FormatIndicatorPeriodic.present != LTE_CQI_ReportPeriodic__setup__cqi_FormatIndicatorPeriodic_PR_NOTHING, "cqi_ReportPeriodic->cqi_FormatIndicatorPeriodic.choice.setup.present == LTE_CQI_ReportPeriodic__setup__cqi_FormatIndicatorPeriodic_PR_NOTHING!\n"); uint16_t Npd, N_OFFSET_CQI; int H, K, bandwidth_part, L, Lmask; int ri = sched_ctl->periodic_ri_received[CC_idP]; - get_csi_params(cc, cqi_ReportPeriodic, &Npd, &N_OFFSET_CQI, &H); + + get_csi_params(cc, + cqi_ReportPeriodic, + &Npd, + &N_OFFSET_CQI, + &H); K = (H - 1) / Jtab[cc->mib->message.dl_Bandwidth]; L = Ltab[cc->mib->message.dl_Bandwidth]; Lmask = L - 1; feedback_cnt = (((frameP * 10) + subframeP) / Npd) % H; - if (feedback_cnt > 0) - bandwidth_part = (feedback_cnt - 1) % K; - else - bandwidth_part = 0; + if (feedback_cnt > 0) bandwidth_part = (feedback_cnt - 1) % K; + else bandwidth_part = 0; - switch (get_tmode(mod_idP, CC_idP, UE_id)) { + switch (get_tmode(mod_idP, + CC_idP, + UE_id)) { case 1: case 2: case 3: @@ -4139,40 +4532,38 @@ extract_pucch_csi(module_id_t mod_idP, int CC_idP, int UE_id, default: // note: need to check TM8-10 without PMI/RI or with 1 antenna port (see Section 5.2.3.3.1 from 36.213) no_pmi = 0; - } + break; +} - if ((cqi_ReportPeriodic->choice.setup.cqi_FormatIndicatorPeriodic.present == LTE_CQI_ReportPeriodic__setup__cqi_FormatIndicatorPeriodic_PR_widebandCQI) - || (feedback_cnt == 0)) { + if (cqi_ReportPeriodic->choice.setup.cqi_FormatIndicatorPeriodic.present == LTE_CQI_ReportPeriodic__setup__cqi_FormatIndicatorPeriodic_PR_widebandCQI || + feedback_cnt == 0) { // Note: This implements only Tables: 5.3.3.1-1,5.3.3.1-1A and 5.3.3.1-2 from 36.213 (1,2,4 antenna ports Wideband CQI/PMI) if (no_pmi == 1) { // get spatial_diffcqi if needed sched_ctl->periodic_wideband_cqi[CC_idP] = pdu[0] & 0xF; - sched_ctl->periodic_wideband_spatial_diffcqi[CC_idP] = - (pdu[0] >> 4) & 7; - } else if ((cc->p_eNB == 2) && (ri == 1)) { + sched_ctl->periodic_wideband_spatial_diffcqi[CC_idP] = (pdu[0] >> 4) & 7; + } else if (cc->p_eNB == 2 && ri == 1) { // p=2 Rank 1 wideband CQI/PMI 6 bits sched_ctl->periodic_wideband_cqi[CC_idP] = pdu[0] & 0xF; sched_ctl->periodic_wideband_pmi[CC_idP] = (pdu[0] >> 4) & 3; - } else if ((cc->p_eNB == 2) && (ri > 1)) { + } else if (cc->p_eNB == 2 && ri > 1) { // p=2 Rank 2 wideband CQI/PMI 8 bits sched_ctl->periodic_wideband_cqi[CC_idP] = pdu[0] & 0xF; - sched_ctl->periodic_wideband_spatial_diffcqi[CC_idP] = - (pdu[0] >> 4) & 7; + sched_ctl->periodic_wideband_spatial_diffcqi[CC_idP] = (pdu[0] >> 4) & 7; sched_ctl->periodic_wideband_pmi[CC_idP] = (pdu[0] >> 7) & 1; - } else if ((cc->p_eNB == 4) && (ri == 1)) { + } else if (cc->p_eNB == 4 && ri == 1) { // p=4 Rank 1 wideband CQI/PMI 8 bits sched_ctl->periodic_wideband_cqi[CC_idP] = pdu[0] & 0xF; - sched_ctl->periodic_wideband_pmi[CC_idP] = - (pdu[0] >> 4) & 0x0F; - } else if ((cc->p_eNB == 4) && (ri > 1)) { + sched_ctl->periodic_wideband_pmi[CC_idP] = (pdu[0] >> 4) & 0x0F; + } else if (cc->p_eNB == 4 && ri > 1) { // p=4 Rank 2 wideband CQI/PMI 11 bits sched_ctl->periodic_wideband_cqi[CC_idP] = pdu[0] & 0xF; - sched_ctl->periodic_wideband_spatial_diffcqi[CC_idP] = - (pdu[0] >> 4) & 7; + sched_ctl->periodic_wideband_spatial_diffcqi[CC_idP] = (pdu[0] >> 4) & 7; sched_ctl->periodic_wideband_pmi[CC_idP] = (pdu[0] >> 7) & 0xF; } else - AssertFatal(1 == 0, - "illegal combination p %d, ri %d, no_pmi %d\n", - cc->p_eNB, ri, no_pmi); + AssertFatal(1 == 0, "illegal combination p %d, ri %d, no_pmi %d\n", + cc->p_eNB, + ri, + no_pmi); } else if (cqi_ReportPeriodic->choice.setup.cqi_FormatIndicatorPeriodic.present == LTE_CQI_ReportPeriodic__setup__cqi_FormatIndicatorPeriodic_PR_subbandCQI) { // This is Table 5.2.3.3.2-2 for 36.213 if (ri == 1) { @@ -4181,16 +4572,23 @@ extract_pucch_csi(module_id_t mod_idP, int CC_idP, int UE_id, } else if (ri > 1) { //7+Ltab[cc->mib->message.dl_Bandwidth] bits; sched_ctl->periodic_subband_spatial_diffcqi[CC_idP][(bandwidth_part * L) + ((pdu[0] >> 7) & Lmask)] = (pdu[0] >> 4) & 7; - sched_ctl->periodic_subband_cqi[CC_idP][(bandwidth_part * L) + ((pdu[0] >> 7) & Lmask)] = - pdu[0] & 0xF; + sched_ctl->periodic_subband_cqi[CC_idP][(bandwidth_part * L) + ((pdu[0] >> 7) & Lmask)] = pdu[0] & 0xF; } } + return; } +//------------------------------------------------------------------------------ void -extract_pusch_csi(module_id_t mod_idP, int CC_idP, int UE_id, - frame_t frameP, sub_frame_t subframeP, - uint8_t *pdu, uint8_t length) { +extract_pusch_csi(module_id_t mod_idP, + int CC_idP, + int UE_id, + frame_t frameP, + sub_frame_t subframeP, + uint8_t *pdu, + uint8_t length) +//------------------------------------------------------------------------------ +{ UE_list_t *UE_list = &RC.mac[mod_idP]->UE_list; COMMON_channels_t *cc = &RC.mac[mod_idP]->common_channels[CC_idP]; UE_sched_ctrl *sched_ctl = &UE_list->UE_sched_ctrl[UE_id]; @@ -4202,13 +4600,14 @@ extract_pusch_csi(module_id_t mod_idP, int CC_idP, int UE_id, int i; uint64_t p = *(uint64_t *) pdu; int curbyte, curbit; - LTE_CQI_ReportModeAperiodic_t *cqi_ReportModeAperiodic; - AssertFatal(UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated != NULL, - "physicalConfigDedicated is null for UE %d\n", UE_id); - AssertFatal(UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->cqi_ReportConfig != NULL, - "cqi_ReportConfig is null for UE %d\n", UE_id); - AssertFatal((cqi_ReportModeAperiodic = UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->cqi_ReportConfig->cqi_ReportModeAperiodic) != NULL, - "cqi_ReportModeAperiodic is null for UE %d\n", UE_id); + AssertFatal(UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated != NULL, "physicalConfigDedicated is null for UE %d\n", + UE_id); + AssertFatal(UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->cqi_ReportConfig != NULL, "cqi_ReportConfig is null for UE %d\n", + UE_id); + LTE_CQI_ReportModeAperiodic_t *cqi_ReportModeAperiodic + = UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->cqi_ReportConfig->cqi_ReportModeAperiodic; + AssertFatal(cqi_ReportModeAperiodic != NULL, "cqi_ReportModeAperiodic is null for UE %d\n", + UE_id); int N = Ntab[cc->mib->message.dl_Bandwidth]; int tmode = get_tmode(mod_idP, CC_idP, UE_id); int ri = sched_ctl->aperiodic_ri_received[CC_idP]; @@ -4220,13 +4619,12 @@ extract_pusch_csi(module_id_t mod_idP, int CC_idP, int UE_id, case LTE_CQI_ReportModeAperiodic_rm12: AssertFatal(0 == 1, "to be fixed, don't use p but pdu directly\n"); // wideband multiple PMI (TM4/6), Table 5.2.2.6.1-1 (for TM4/6) - AssertFatal(tmode == 4 || tmode == 6 || tmode == 8 || tmode == 9 || tmode == 10, - "Illegal transmission mode %d for CQI_ReportModeAperiodic_rm12\n", + AssertFatal(tmode == 4 || tmode == 6 || tmode == 8 || tmode == 9 || tmode == 10, "Illegal transmission mode %d for CQI_ReportModeAperiodic_rm12\n", tmode); if (tmode <= 6) { //Table 5.2.2.6.1-1 36.213 - if ((ri == 1) && (cc->p_eNB == 2)) { - sched_ctl->aperiodic_wideband_cqi0[CC_idP] = (uint8_t) (p & 0x0F); + if (ri == 1 && cc->p_eNB == 2) { + sched_ctl->aperiodic_wideband_cqi0[CC_idP] = (uint8_t) (p & 0x0F); p >>= 4; for (i = 0; i < N; i++) { @@ -4235,10 +4633,10 @@ extract_pusch_csi(module_id_t mod_idP, int CC_idP, int UE_id, } } - if ((ri == 2) && (cc->p_eNB == 2)) { - sched_ctl->aperiodic_wideband_cqi0[CC_idP] = (uint8_t) (p & 0x0F); + if (ri == 2 && cc->p_eNB == 2) { + sched_ctl->aperiodic_wideband_cqi0[CC_idP] = (uint8_t) (p & 0x0F); p >>= 4; - sched_ctl->aperiodic_wideband_cqi1[CC_idP] = (uint8_t) (p & 0x0F); + sched_ctl->aperiodic_wideband_cqi1[CC_idP] = (uint8_t) (p & 0x0F); p >>= 4; for (i = 0; i < N; i++) { @@ -4247,8 +4645,8 @@ extract_pusch_csi(module_id_t mod_idP, int CC_idP, int UE_id, } } - if ((ri == 1) && (cc->p_eNB == 4)) { - sched_ctl->aperiodic_wideband_cqi0[CC_idP] = (uint8_t) (p & 0x0F); + if (ri == 1 && cc->p_eNB == 4) { + sched_ctl->aperiodic_wideband_cqi0[CC_idP] = (uint8_t) (p & 0x0F); p >>= 4; for (i = 0; i < N; i++) { @@ -4257,10 +4655,10 @@ extract_pusch_csi(module_id_t mod_idP, int CC_idP, int UE_id, } } - if ((ri == 2) && (cc->p_eNB == 4)) { - sched_ctl->aperiodic_wideband_cqi0[CC_idP] = (uint8_t) (p & 0x0F); + if (ri == 2 && cc->p_eNB == 4) { + sched_ctl->aperiodic_wideband_cqi0[CC_idP] = (uint8_t) (p & 0x0F); p >>= 4; - sched_ctl->aperiodic_wideband_cqi1[CC_idP] = (uint8_t) (p & 0x0F); + sched_ctl->aperiodic_wideband_cqi1[CC_idP] = (uint8_t) (p & 0x0F); p >>= 4; for (i = 0; i < N; i++) { @@ -4278,28 +4676,28 @@ extract_pusch_csi(module_id_t mod_idP, int CC_idP, int UE_id, case LTE_CQI_ReportModeAperiodic_rm20: AssertFatal(0 == 1, "to be fixed, don't use p but pdu directly\n"); // UE-selected subband CQI no PMI (TM1/2/3/7) , Table 5.2.2.6.3-1 from 36.213 - AssertFatal(tmode == 1 || tmode == 2 || tmode == 3 - || tmode == 7, - "Illegal transmission mode %d for CQI_ReportModeAperiodic_rm20\n", + AssertFatal(tmode == 1 || tmode == 2 || tmode == 3 || tmode == 7, "Illegal transmission mode %d for CQI_ReportModeAperiodic_rm20\n", tmode); sched_ctl->aperiodic_wideband_cqi0[CC_idP] = (uint8_t) (p & 0x0F); p >>= 4; diffcqi0 = (uint8_t) (p & 0x03); p >>= 2; r = (uint8_t) (p & ((1 >> Ltab_uesel[bw]) - 1)); - reverse_index(Ntab_uesel[bw], Mtab_uesel[bw], r, v); + reverse_index(Ntab_uesel[bw], + Mtab_uesel[bw], + r, + v); - for (m = 0; m < Mtab_uesel[bw]; m++) + for (m = 0; m < Mtab_uesel[bw]; m++) { sched_ctl->aperiodic_subband_diffcqi0[CC_idP][v[m]] = diffcqi0; + } break; case LTE_CQI_ReportModeAperiodic_rm22: AssertFatal(0 == 1, "to be fixed, don't use p but pdu directly\n"); // UE-selected subband CQI multiple PMI (TM4/6) Table 5.2.2.6.3-2 from 36.213 - AssertFatal(tmode == 4 || tmode == 6 || tmode == 8 || tmode == 9 - || tmode == 10, - "Illegal transmission mode %d for CQI_ReportModeAperiodic_rm22\n", + AssertFatal(tmode == 4 || tmode == 6 || tmode == 8 || tmode == 9 || tmode == 10, "Illegal transmission mode %d for CQI_ReportModeAperiodic_rm22\n", tmode); sched_ctl->aperiodic_wideband_cqi0[CC_idP] = (uint8_t) (p & 0x0F); p >>= 4; @@ -4316,13 +4714,16 @@ extract_pusch_csi(module_id_t mod_idP, int CC_idP, int UE_id, r = (uint8_t) (p & ((1 >> Ltab_uesel[bw]) - 1)); p >>= Ltab_uesel[bw]; - reverse_index(Ntab_uesel[bw], Mtab_uesel[bw], r, v); + reverse_index(Ntab_uesel[bw], + Mtab_uesel[bw], + r, + v); - if ((ri == 1) && (cc->p_eNB == 2)) { + if (ri == 1 && cc->p_eNB == 2) { pmi_uesel = p & 0x3; p >>= 2; sched_ctl->aperiodic_wideband_pmi[CC_idP] = p & 0x3; - } else if ((ri == 2) && (cc->p_eNB == 2)) { + } else if (ri == 2 && cc->p_eNB == 2) { pmi_uesel = p & 0x1; p >>= 1; sched_ctl->aperiodic_wideband_pmi[CC_idP] = p & 0x1; @@ -4335,9 +4736,7 @@ extract_pusch_csi(module_id_t mod_idP, int CC_idP, int UE_id, for (m = 0; m < Mtab_uesel[bw]; m++) { sched_ctl->aperiodic_subband_diffcqi0[CC_idP][v[m]] = diffcqi0; - if (ri > 1) - sched_ctl->aperiodic_subband_diffcqi1[CC_idP][v[m]] = - diffcqi1; + if (ri > 1) sched_ctl->aperiodic_subband_diffcqi1[CC_idP][v[m]] = diffcqi1; sched_ctl->aperiodic_subband_pmi[CC_idP][v[m]] = pmi_uesel; } @@ -4346,9 +4745,7 @@ extract_pusch_csi(module_id_t mod_idP, int CC_idP, int UE_id, case LTE_CQI_ReportModeAperiodic_rm30: //subband CQI no PMI (TM1/2/3/7) - AssertFatal(tmode == 1 || tmode == 2 || tmode == 3 - || tmode == 7, - "Illegal transmission mode %d for CQI_ReportModeAperiodic_rm30\n", + AssertFatal(tmode == 1 || tmode == 2 || tmode == 3 || tmode == 7, "Illegal transmission mode %d for CQI_ReportModeAperiodic_rm30\n", tmode); sched_ctl->aperiodic_wideband_cqi0[CC_idP] = pdu[0] >> 4; curbyte = 0; @@ -4365,89 +4762,75 @@ extract_pusch_csi(module_id_t mod_idP, int CC_idP, int UE_id, } } - sched_ctl->dl_cqi[CC_idP] = - sched_ctl->aperiodic_wideband_cqi0[CC_idP]; + sched_ctl->dl_cqi[CC_idP] = sched_ctl->aperiodic_wideband_cqi0[CC_idP]; + break; case LTE_CQI_ReportModeAperiodic_rm31: AssertFatal(0 == 1, "to be fixed, don't use p but pdu directly\n"); //subband CQI single PMI (TM4/5/6) - AssertFatal(tmode == 4 || tmode == 5 || tmode == 6 || tmode == 8 - || tmode == 9 - || tmode == 10, + AssertFatal(tmode == 4 || tmode == 5 || tmode == 6 || tmode == 8 || tmode == 9 || tmode == 10, "Illegal transmission mode %d for CQI_ReportModeAperiodic_rm31\n", tmode); - if ((ri == 1) && (cc->p_eNB == 2)) { - sched_ctl->aperiodic_wideband_cqi0[CC_idP] = - (uint8_t) (p & 0x0F); + if (ri == 1 && cc->p_eNB == 2) { + sched_ctl->aperiodic_wideband_cqi0[CC_idP] = (uint8_t) (p & 0x0F); p >>= 4; for (i = 0; i < N; i++) { - sched_ctl->aperiodic_subband_diffcqi0[CC_idP][i] = - (uint8_t) (p & 0x03); + sched_ctl->aperiodic_subband_diffcqi0[CC_idP][i] = (uint8_t) (p & 0x03); p >>= 2; } sched_ctl->aperiodic_wideband_pmi[CC_idP] = p & 0x03; } - if ((ri == 2) && (cc->p_eNB == 2)) { - sched_ctl->aperiodic_wideband_cqi0[CC_idP] = - (uint8_t) (p & 0x0F); + if (ri == 2 && cc->p_eNB == 2) { + sched_ctl->aperiodic_wideband_cqi0[CC_idP] = (uint8_t) (p & 0x0F); p >>= 4; for (i = 0; i < N; i++) { - sched_ctl->aperiodic_subband_pmi[CC_idP][i] = - (uint8_t) (p & 0x01); + sched_ctl->aperiodic_subband_pmi[CC_idP][i] = (uint8_t) (p & 0x01); p >>= 1; } - sched_ctl->aperiodic_wideband_cqi1[CC_idP] = - (uint8_t) (p & 0x0F); + sched_ctl->aperiodic_wideband_cqi1[CC_idP] = (uint8_t) (p & 0x0F); p >>= 4; for (i = 0; i < N; i++) { - sched_ctl->aperiodic_subband_pmi[CC_idP][i] = - (uint8_t) (p & 0x01); + sched_ctl->aperiodic_subband_pmi[CC_idP][i] = (uint8_t) (p & 0x01); p >>= 1; } sched_ctl->aperiodic_wideband_pmi[CC_idP] = p & 0x01; } - if ((ri == 1) && (cc->p_eNB == 4)) { - sched_ctl->aperiodic_wideband_cqi0[CC_idP] = - (uint8_t) (p & 0x0F); + if (ri == 1 && cc->p_eNB == 4) { + sched_ctl->aperiodic_wideband_cqi0[CC_idP] = (uint8_t) (p & 0x0F); p >>= 4; for (i = 0; i < N; i++) { - sched_ctl->aperiodic_subband_diffcqi0[CC_idP][i] = - (uint8_t) (p & 0x03); + sched_ctl->aperiodic_subband_diffcqi0[CC_idP][i] = (uint8_t) (p & 0x03); p >>= 2; } sched_ctl->aperiodic_wideband_pmi[CC_idP] = p & 0x0F; } - if ((ri > 1) && (cc->p_eNB == 4)) { // Note : 64 bits for 20 MHz - sched_ctl->aperiodic_wideband_cqi0[CC_idP] = - (uint8_t) (p & 0x0F); + if (ri > 1 && cc->p_eNB == 4) { // Note : 64 bits for 20 MHz + sched_ctl->aperiodic_wideband_cqi0[CC_idP] = (uint8_t) (p & 0x0F); p >>= 4; for (i = 0; i < N; i++) { - sched_ctl->aperiodic_subband_pmi[CC_idP][i] = - (uint8_t) (p & 0x01); + sched_ctl->aperiodic_subband_pmi[CC_idP][i] = (uint8_t) (p & 0x01); p >>= 1; } - sched_ctl->aperiodic_wideband_cqi1[CC_idP] = - (uint8_t) (p & 0x0F); + sched_ctl->aperiodic_wideband_cqi1[CC_idP] = (uint8_t) (p & 0x0F); p >>= 4; for (i = 0; i < N; i++) { - sched_ctl->aperiodic_subband_pmi[CC_idP][i] = - (uint8_t) (p & 0x01); + sched_ctl->aperiodic_subband_pmi[CC_idP][i] = (uint8_t) (p & 0x01); p >>= 2; } @@ -4455,44 +4838,47 @@ extract_pusch_csi(module_id_t mod_idP, int CC_idP, int UE_id, } break; -#if (LTE_RRC_VERSION >= MAKE_VERSION(12, 5, 0)) +#if (LTE_RRC_VERSION >= MAKE_VERSION(12, 5, 0)) case LTE_CQI_ReportModeAperiodic_rm32_v1250: - AssertFatal(tmode == 4 || tmode == 5 || tmode == 6 || tmode == 8 - || tmode == 9 - || tmode == 10, + AssertFatal(tmode == 4 || tmode == 5 || tmode == 6 || tmode == 8 || tmode == 9 || tmode == 10, "Illegal transmission mode %d for CQI_ReportModeAperiodic_rm32\n", tmode); AssertFatal(1 == 0, "CQI_ReportModeAperiodic_rm32 to be done\n"); break; #endif -#if (LTE_RRC_VERSION >= MAKE_VERSION(13, 1, 0)) +#if (LTE_RRC_VERSION >= MAKE_VERSION(13, 1, 0)) case LTE_CQI_ReportModeAperiodic_rm10_v1310: - AssertFatal(tmode == 1 || tmode == 2 || tmode == 3 - || tmode == 7, - "Illegal transmission mode %d for CQI_ReportModeAperiodic_rm10\n", + AssertFatal(tmode == 1 || tmode == 2 || tmode == 3 || tmode == 7, "Illegal transmission mode %d for CQI_ReportModeAperiodic_rm10\n", tmode); AssertFatal(1 == 0, "CQI_ReportModeAperiodic_rm10 to be done\n"); break; case LTE_CQI_ReportModeAperiodic_rm11_v1310: - AssertFatal(tmode == 4 || tmode == 5 || tmode == 6 || tmode == 8 - || tmode == 9 - || tmode == 10, + AssertFatal(tmode == 4 || tmode == 5 || tmode == 6 || tmode == 8 || tmode == 9 || tmode == 10, "Illegal transmission mode %d for CQI_ReportModeAperiodic_rm11\n", tmode); AssertFatal(1 == 0, "CQI_ReportModeAperiodic_rm11 to be done\n"); break; #endif /* #if (LTE_RRC_VERSION >= MAKE_VERSION(13, 1, 0)) */ + } + return; } +//------------------------------------------------------------------------------ void -cqi_indication(module_id_t mod_idP, int CC_idP, frame_t frameP, - sub_frame_t subframeP, rnti_t rntiP, - nfapi_cqi_indication_rel9_t *rel9, uint8_t *pdu, - nfapi_ul_cqi_information_t *ul_cqi_information) { +cqi_indication(module_id_t mod_idP, + int CC_idP, + frame_t frameP, + sub_frame_t subframeP, + rnti_t rntiP, + nfapi_cqi_indication_rel9_t *rel9, + uint8_t *pdu, + nfapi_ul_cqi_information_t *ul_cqi_information) +//------------------------------------------------------------------------------ +{ int UE_id = find_UE_id(mod_idP, rntiP); UE_list_t *UE_list = &RC.mac[mod_idP]->UE_list; @@ -4504,22 +4890,40 @@ cqi_indication(module_id_t mod_idP, int CC_idP, frame_t frameP, UE_sched_ctrl *sched_ctl = &UE_list->UE_sched_ctrl[UE_id]; if (UE_id >= 0) { - LOG_D(MAC,"%s() UE_id:%d channel:%d cqi:%d\n", __FUNCTION__, UE_id, ul_cqi_information->channel, ul_cqi_information->ul_cqi); + LOG_D(MAC,"%s() UE_id:%d channel:%d cqi:%d\n", + __FUNCTION__, + UE_id, + ul_cqi_information->channel, + ul_cqi_information->ul_cqi); if (ul_cqi_information->channel == 0) { // PUCCH // extract pucch csi information before changing RI information - extract_pucch_csi(mod_idP, CC_idP, UE_id, frameP, subframeP, + extract_pucch_csi(mod_idP, + CC_idP, + UE_id, + frameP, + subframeP, pdu, rel9->length); memcpy((void *) sched_ctl->periodic_ri_received, - (void *) rel9->ri, rel9->number_of_cc_reported); + (void *) rel9->ri, + rel9->number_of_cc_reported); // SNR for PUCCH2 sched_ctl->pucch2_snr[CC_idP] = ul_cqi_information->ul_cqi; } else { //PUSCH memcpy((void *) sched_ctl->aperiodic_ri_received, - (void *) rel9->ri, rel9->number_of_cc_reported); - extract_pusch_csi(mod_idP, CC_idP, UE_id, frameP, subframeP, - pdu, rel9->length); - LOG_D(MAC,"Frame %d Subframe %d update CQI:%d\n",frameP,subframeP,sched_ctl->dl_cqi[CC_idP]); + (void *) rel9->ri, + rel9->number_of_cc_reported); + extract_pusch_csi(mod_idP, + CC_idP, + UE_id, + frameP, + subframeP, + pdu, + rel9->length); + LOG_D(MAC,"Frame %d Subframe %d update CQI:%d\n", + frameP, + subframeP, + sched_ctl->dl_cqi[CC_idP]); sched_ctl->cqi_req_flag &= (~(1 << subframeP)); sched_ctl->cqi_received = 1; } @@ -4528,96 +4932,136 @@ cqi_indication(module_id_t mod_idP, int CC_idP, frame_t frameP, sched_ctl->timing_advance = rel9->timing_advance; sched_ctl->timing_advance_r9 = rel9->timing_advance_r9; } + return; } +//------------------------------------------------------------------------------ void -SR_indication(module_id_t mod_idP, int cc_idP, frame_t frameP, - sub_frame_t subframeP, rnti_t rntiP, uint8_t ul_cqi) { - T(T_ENB_MAC_SCHEDULING_REQUEST, T_INT(mod_idP), T_INT(cc_idP), - T_INT(frameP), T_INT(subframeP), T_INT(rntiP)); +SR_indication(module_id_t mod_idP, + int cc_idP, + frame_t frameP, + sub_frame_t subframeP, + rnti_t rntiP, + uint8_t ul_cqi) +//------------------------------------------------------------------------------ +{ + T(T_ENB_MAC_SCHEDULING_REQUEST, + T_INT(mod_idP), + T_INT(cc_idP), + T_INT(frameP), + T_INT(subframeP), + T_INT(rntiP)); int UE_id = find_UE_id(mod_idP, rntiP); UE_list_t *UE_list = &RC.mac[mod_idP]->UE_list; if (UE_id != -1) { - if (mac_eNB_get_rrc_status(mod_idP, UE_RNTI(mod_idP, UE_id)) < - RRC_CONNECTED) - LOG_D(MAC, - "[eNB %d][SR %x] Frame %d subframeP %d Signaling SR for UE %d on CC_id %d\n", - mod_idP, rntiP, frameP, subframeP, UE_id, cc_idP); - + if (mac_eNB_get_rrc_status(mod_idP, UE_RNTI(mod_idP, UE_id)) < RRC_CONNECTED) { + LOG_D(MAC, "[eNB %d][SR %x] Frame %d subframeP %d Signaling SR for UE %d on CC_id %d\n", + mod_idP, + rntiP, + frameP, + subframeP, + UE_id, + cc_idP); + } UE_list->UE_template[cc_idP][UE_id].ul_SR = 1; UE_list->UE_template[cc_idP][UE_id].ul_active = TRUE; - VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME - (VCD_SIGNAL_DUMPER_FUNCTIONS_SR_INDICATION, 1); - VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME - (VCD_SIGNAL_DUMPER_FUNCTIONS_SR_INDICATION, 0); + VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_SR_INDICATION, 1); + VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_SR_INDICATION, 0); } else { // AssertFatal(0, "find_UE_id(%u,rnti %d) not found", enb_mod_idP, rntiP); // AssertError(0, 0, "Frame %d: find_UE_id(%u,rnti %d) not found\n", frameP, enb_mod_idP, rntiP); - LOG_D(MAC, - "[eNB %d][SR %x] Frame %d subframeP %d Signaling SR for UE %d (unknown UEid) on CC_id %d\n", - mod_idP, rntiP, frameP, subframeP, UE_id, cc_idP); + LOG_D(MAC, "[eNB %d][SR %x] Frame %d subframeP %d Signaling SR for UE %d (unknown UEid) on CC_id %d\n", + mod_idP, + rntiP, + frameP, + subframeP, + UE_id, + cc_idP); } + return; } +//------------------------------------------------------------------------------ void -UL_failure_indication(module_id_t mod_idP, int cc_idP, frame_t frameP, - rnti_t rntiP, sub_frame_t subframeP) { +UL_failure_indication(module_id_t mod_idP, + int cc_idP, + frame_t frameP, + rnti_t rntiP, + sub_frame_t subframeP) +//------------------------------------------------------------------------------ +{ int UE_id = find_UE_id(mod_idP, rntiP); UE_list_t *UE_list = &RC.mac[mod_idP]->UE_list; if (UE_id != -1) { - LOG_D(MAC, - "[eNB %d][UE %d/%x] Frame %d subframeP %d Signaling UL Failure for UE %d on CC_id %d (timer %d)\n", - mod_idP, UE_id, rntiP, frameP, subframeP, UE_id, cc_idP, + LOG_D(MAC, "[eNB %d][UE %d/%x] Frame %d subframeP %d Signaling UL Failure for UE %d on CC_id %d (timer %d)\n", + mod_idP, + UE_id, + rntiP, + frameP, + subframeP, + UE_id, + cc_idP, UE_list->UE_sched_ctrl[UE_id].ul_failure_timer); - if (UE_list->UE_sched_ctrl[UE_id].ul_failure_timer == 0) - UE_list->UE_sched_ctrl[UE_id].ul_failure_timer = 1; + if (UE_list->UE_sched_ctrl[UE_id].ul_failure_timer == 0) UE_list->UE_sched_ctrl[UE_id].ul_failure_timer = 1; } else { // AssertFatal(0, "find_UE_id(%u,rnti %d) not found", enb_mod_idP, rntiP); // AssertError(0, 0, "Frame %d: find_UE_id(%u,rnti %d) not found\n", frameP, enb_mod_idP, rntiP); - LOG_W(MAC, - "[eNB %d][SR %x] Frame %d subframeP %d Signaling UL Failure for UE %d (unknown UEid) on CC_id %d\n", - mod_idP, rntiP, frameP, subframeP, UE_id, cc_idP); + LOG_W(MAC, "[eNB %d][SR %x] Frame %d subframeP %d Signaling UL Failure for UE %d (unknown UEid) on CC_id %d\n", + mod_idP, + rntiP, + frameP, + subframeP, + UE_id, + cc_idP); } } -static int nack_or_dtx_reported( - COMMON_channels_t *cc, - nfapi_harq_indication_pdu_t *harq_pdu) { +//------------------------------------------------------------------------------ +static int +nack_or_dtx_reported(COMMON_channels_t *cc, + nfapi_harq_indication_pdu_t *harq_pdu) +//------------------------------------------------------------------------------ +{ int i; if (cc->tdd_Config) { nfapi_harq_indication_tdd_rel13_t *hi = &harq_pdu->harq_indication_tdd_rel13; - for (i = 0; i < hi->number_of_ack_nack; hi++) + for (i = 0; i < hi->number_of_ack_nack; hi++) { if (hi->harq_data[0].bundling.value_0 != 1) //only bundling is used for tdd for now return 1; - + } return 0; - } else { - nfapi_harq_indication_fdd_rel13_t *hi = &harq_pdu->harq_indication_fdd_rel13; + } - for (i = 0; i < hi->number_of_ack_nack; hi++) - if (hi->harq_tb_n[i] != 1) - return 1; - - return 0; + nfapi_harq_indication_fdd_rel13_t *hi = &harq_pdu->harq_indication_fdd_rel13; + for (i = 0; i < hi->number_of_ack_nack; hi++) { + if (hi->harq_tb_n[i] != 1) + return 1; } + return 0; } +//------------------------------------------------------------------------------ void -harq_indication(module_id_t mod_idP, int CC_idP, frame_t frameP, +harq_indication(module_id_t mod_idP, + int CC_idP, + frame_t frameP, sub_frame_t subframeP, - nfapi_harq_indication_pdu_t *harq_pdu) { + nfapi_harq_indication_pdu_t *harq_pdu) +//------------------------------------------------------------------------------ +{ rnti_t rnti = harq_pdu->rx_ue_information.rnti; uint8_t ul_cqi = harq_pdu->ul_cqi_information.ul_cqi; uint8_t channel = harq_pdu->ul_cqi_information.channel; int UE_id = find_UE_id(mod_idP, rnti); if (UE_id == -1) { - LOG_W(MAC, "harq_indication: UE %x not found\n", rnti); + LOG_W(MAC, "harq_indication: UE %x not found\n", + rnti); return; } @@ -4625,53 +5069,85 @@ harq_indication(module_id_t mod_idP, int CC_idP, frame_t frameP, UE_sched_ctrl *sched_ctl = &UE_list->UE_sched_ctrl[UE_id]; COMMON_channels_t *cc = &RC.mac[mod_idP]->common_channels[CC_idP]; // extract HARQ Information - LOG_D(MAC, - "Frame %d, subframe %d: Received harq indication (%d) from UE %d/%x, ul_cqi %d\n", - frameP, subframeP, channel, UE_id, rnti, ul_cqi); + LOG_D(MAC, "Frame %d, subframe %d: Received harq indication (%d) from UE %d/%x, ul_cqi %d\n", + frameP, + subframeP, + channel, + UE_id, + rnti, + ul_cqi); - if (cc->tdd_Config) - extract_harq(mod_idP, CC_idP, UE_id, frameP, subframeP, + if (cc->tdd_Config) { + extract_harq(mod_idP, + CC_idP, + UE_id, + frameP, + subframeP, (void *) &harq_pdu->harq_indication_tdd_rel13, channel); - else - extract_harq(mod_idP, CC_idP, UE_id, frameP, subframeP, + } + else { + extract_harq(mod_idP, + CC_idP, + UE_id, + frameP, + subframeP, (void *) &harq_pdu->harq_indication_fdd_rel13, channel); - + } /* don't care about cqi reporting if NACK/DTX is there */ - if (channel == 0 && !nack_or_dtx_reported(cc, harq_pdu)) { + if (channel == 0 && !nack_or_dtx_reported(cc, + harq_pdu)) { sched_ctl->pucch1_snr[CC_idP] = ul_cqi; sched_ctl->pucch1_cqi_update[CC_idP] = 1; } + return; } // Flexran Slicing functions - -uint16_t nb_rbs_allowed_slice(float rb_percentage, int total_rbs) { +//------------------------------------------------------------------------------ +uint16_t +nb_rbs_allowed_slice(float rb_percentage, + int total_rbs) +//------------------------------------------------------------------------------ +{ return (uint16_t) floor(rb_percentage * total_rbs); } -int ue_dl_slice_membership(module_id_t mod_id, int UE_id, int slice_idx) { - if ((slice_idx < 0) - || (slice_idx >= RC.mac[mod_id]->slice_info.n_dl)) { - LOG_W(MAC, "out of range slice index %d (slice ID %d)\n", - slice_idx, RC.mac[mod_id]->slice_info.dl[slice_idx].id); - return 0; - } - - return RC.mac[mod_id]->UE_list.active[UE_id] == TRUE - && RC.mac[mod_id]->UE_list.assoc_dl_slice_idx[UE_id] == slice_idx; -} - -int ue_ul_slice_membership(module_id_t mod_id, - int UE_id, - int slice_idx) +//------------------------------------------------------------------------------ +int +ue_dl_slice_membership(module_id_t mod_id, + int UE_id, + int slice_idx) +//------------------------------------------------------------------------------ { - if ((slice_idx < 0) || (slice_idx >= RC.mac[mod_id]->slice_info.n_ul)) { + eNB_MAC_INST *eNB = RC.mac[mod_id]; + + if (slice_idx < 0 || slice_idx >= eNB->slice_info.n_dl) { LOG_W(MAC, "out of range slice index %d (slice ID %d)\n", - slice_idx, RC.mac[mod_id]->slice_info.dl[slice_idx].id); + slice_idx, + eNB->slice_info.dl[slice_idx].id); return 0; } - return RC.mac[mod_id]->UE_list.active[UE_id] == TRUE && RC.mac[mod_id]->UE_list.assoc_ul_slice_idx[UE_id] == slice_idx; + return eNB->UE_list.active[UE_id] == TRUE && eNB->UE_list.assoc_dl_slice_idx[UE_id] == slice_idx; +} + +//------------------------------------------------------------------------------ +int +ue_ul_slice_membership(module_id_t mod_id, + int UE_id, + int slice_idx) +//------------------------------------------------------------------------------ +{ + eNB_MAC_INST *eNB = RC.mac[mod_id]; + + if (slice_idx < 0 || slice_idx >= eNB->slice_info.n_ul) { + LOG_W(MAC, "out of range slice index %d (slice ID %d)\n", + slice_idx, + eNB->slice_info.dl[slice_idx].id); + return 0; + } + + return eNB->UE_list.active[UE_id] == TRUE && eNB->UE_list.assoc_ul_slice_idx[UE_id] == slice_idx; } diff --git a/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c b/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c index 10d4fc1523..1542b2d416 100644 --- a/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c +++ b/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c @@ -686,7 +686,7 @@ rx_sdu(const module_id_t enb_mod_idP, rx_lengths[i], payload_ptr - sduP); - if ((UE_id = add_new_ue(enb_mod_idP, CC_idP, mac->common_channels[CC_idP].ra->rnti, harq_pid + if ((UE_id = add_new_ue(enb_mod_idP, CC_idP, ra->rnti, harq_pid #if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0)) , mac->common_channels[CC_idP].ra->rach_resource_type #endif @@ -1909,426 +1909,486 @@ schedule_ulsch_rnti(module_id_t module_idP, } #if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0)) +//----------------------------------------------------------------------------- +/* + * default ULSCH scheduler for LTE-M + */ void schedule_ulsch_rnti_emtc(module_id_t module_idP, - frame_t frameP, - sub_frame_t subframeP, - unsigned char sched_subframeP, - int *emtc_active) + frame_t frameP, + sub_frame_t subframeP, + unsigned char sched_subframeP, + int *emtc_active) +//----------------------------------------------------------------------------- { - int UE_id; + int UE_id = -1; rnti_t rnti = -1; - uint8_t round = 0; + uint8_t round_UL = 0; uint8_t harq_pid = 0; uint8_t status = 0; - uint32_t cshift,ndi; - int32_t normalized_rx_power; - int32_t target_rx_power=-90; - int n; - int CC_id = 0; - int N_RB_UL; + uint32_t cshift = 0; + uint32_t ndi = 0; + int32_t normalized_rx_power = 0; + int32_t target_rx_power = -90; + int n = 0; + int CC_id = 0; + int N_RB_UL = 0; + int sched_frame = frameP; + int rvidx_tab[4] = {0,2,3,1}; + int tpc = 0; + int cqi_req = 0; eNB_MAC_INST *eNB = RC.mac[module_idP]; COMMON_channels_t *cc = eNB->common_channels; - UE_list_t *UE_list=&eNB->UE_list; - UE_TEMPLATE *UE_template; - UE_sched_ctrl *UE_sched_ctrl; - int sched_frame=frameP; - int rvidx_tab[4] = {0,2,3,1}; - int tpc=0; - int cqi_req=0; + UE_list_t *UE_list = &(eNB->UE_list); + UE_TEMPLATE *UE_template = NULL; + UE_sched_ctrl *UE_sched_ctrl = NULL; - if (sched_subframePHI_DCI0_req[CC_id][subframeP].hi_dci0_request_body; - nfapi_hi_dci0_request_pdu_t *hi_dci0_pdu; + nfapi_hi_dci0_request_body_t *hi_dci0_req = &(eNB->HI_DCI0_req[CC_id][subframeP].hi_dci0_request_body); + nfapi_hi_dci0_request_pdu_t *hi_dci0_pdu = NULL; - nfapi_ul_config_request_body_t *ul_req_tmp = &eNB->UL_req_tmp[CC_id][sched_subframeP].ul_config_request_body; + nfapi_ul_config_request_body_t *ul_req_tmp = &(eNB->UL_req_tmp[CC_id][sched_subframeP].ul_config_request_body); - // loop over all active UEs - if ((frameP&1) == 1) return; + /* If frameP odd don't schedule */ + if ((frameP & 1) == 1) { + return; + } - for (UE_id=UE_list->head_ul; UE_id>=0; UE_id=UE_list->next_ul[UE_id]) { + /* Loop over all active UEs */ + for (UE_id = UE_list->head_ul; UE_id >= 0; UE_id = UE_list->next_ul[UE_id]) { + UE_template = &(UE_list->UE_template[UE_PCCID(module_idP, UE_id)][UE_id]); - if (UE_list->UE_template[UE_PCCID(module_idP,UE_id)][UE_id].rach_resource_type == 0) continue; - - // don't schedule if Msg4 is not received yet - if (UE_list->UE_template[UE_PCCID(module_idP,UE_id)][UE_id].configured==FALSE) { - LOG_D(MAC,"[eNB %d] frame %d subfarme %d, UE %d: not configured, skipping UE scheduling \n", - module_idP,frameP,subframeP,UE_id); + /* LTE-M device */ + if (UE_template->rach_resource_type == 0) { continue; } - rnti = UE_RNTI(module_idP,UE_id); - - if (rnti==NOT_A_RNTI) { - LOG_W(MAC,"[eNB %d] frame %d subfarme %d, UE %d: no RNTI \n", module_idP,frameP,subframeP,UE_id); + /* Don't schedule if Msg4 is not received yet */ + if (UE_template->configured == FALSE) { + LOG_D(MAC,"[eNB %d] frame %d subframe %d, UE %d: not configured, skipping UE scheduling \n", + module_idP, + frameP, + subframeP, + UE_id); continue; } - // loop over all active UL CC_ids for this UE - for (n=0; nnumactiveULCCs[UE_id]; n++) { - // This is the actual CC_id in the list - CC_id = UE_list->ordered_ULCCids[n][UE_id]; - N_RB_UL = to_prb(cc[CC_id].ul_Bandwidth); + rnti = UE_RNTI(module_idP, UE_id); + if (rnti == NOT_A_RNTI) { + LOG_W(MAC,"[eNB %d] frame %d subframe %d, UE %d: no RNTI \n", + module_idP, + frameP, + subframeP, + UE_id); - UE_template = &UE_list->UE_template[CC_id][UE_id]; - UE_sched_ctrl = &UE_list->UE_sched_ctrl[UE_id]; + continue; + } + + /* Loop over all active UL CC_ids for this UE */ + for (n = 0; n < UE_list->numactiveULCCs[UE_id]; n++) { + /* This is the actual CC_id in the list */ + CC_id = UE_list->ordered_ULCCids[n][UE_id]; + N_RB_UL = to_prb(cc[CC_id].ul_Bandwidth); + + UE_template = &(UE_list->UE_template[CC_id][UE_id]); harq_pid = 0; - round = UE_sched_ctrl->round_UL[CC_id][harq_pid]; - AssertFatal(round<8,"round %d > 7 for UE %d/%x\n",round,UE_id,rnti); + round_UL = UE_sched_ctrl->round_UL[CC_id][harq_pid]; + + AssertFatal(round_UL < 8,"round_UL %d > 7 for UE %d/%x\n", + round_UL, + UE_id, + rnti); + LOG_D(MAC,"[eNB %d] frame %d subframe %d,Checking PUSCH %d for BL/CE UE %d/%x CC %d : aggregation level %d, N_RB_UL %d\n", - module_idP,frameP,subframeP,harq_pid,UE_id,rnti,CC_id, 24,N_RB_UL); + module_idP, + frameP, + subframeP, + harq_pid, + UE_id, + rnti, + CC_id, + 24, // agregation level + N_RB_UL); RC.eNB[module_idP][CC_id]->pusch_stats_BO[UE_id][(frameP*10)+subframeP] = UE_template->estimated_ul_buffer; - VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_UE0_BO,RC.eNB[module_idP][CC_id]->pusch_stats_BO[UE_id][(frameP*10)+subframeP]); - if ((UE_template->ul_SR >0 || round > 0 || status < RRC_CONNECTED)&&(subframeP==5)) - // if there is information on bsr of DCCH, DTCH or if there is UL_SR, or if there is a packet to retransmit, or we want to schedule a periodic feedback every 10 frames - { - LOG_I(MAC,"[eNB %d][PUSCH %d] Frame %d subframe %d Scheduling UE %d/%x in round %d(SR %d,UL_inactivity timer %d,UL_failure timer %d,cqi_req_timer %d)\n", - module_idP,harq_pid,frameP,subframeP,UE_id,rnti,round,UE_template->ul_SR, - UE_sched_ctrl->ul_inactivity_timer, + VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_UE0_BO, UE_template->estimated_ul_buffer); + + if ((UE_template->ul_SR > 0 || round_UL > 0 || status < RRC_CONNECTED) && (subframeP == 5)) { + /* + * if there is information on bsr of DCCH, DTCH, + * or if there is UL_SR, + * or if there is a packet to retransmit, + * or we want to schedule a periodic feedback every frame + */ + + LOG_I(MAC,"[eNB %d][PUSCH %d] Frame %d subframe %d Scheduling UE %d/%x in round_UL %d(SR %d,UL_inactivity timer %d,UL_failure timer %d,cqi_req_timer %d)\n", + module_idP, + harq_pid, + frameP, + subframeP, + UE_id, + rnti, + round_UL, + UE_template->ul_SR, + UE_sched_ctrl->ul_inactivity_timer, + UE_sched_ctrl->ul_failure_timer, + UE_sched_ctrl->cqi_req_timer); - UE_sched_ctrl->ul_failure_timer, + /* Reset the scheduling request */ + emtc_active[CC_id] = 1; + UE_template->ul_SR = 0; + status = mac_eNB_get_rrc_status(module_idP,rnti); + cqi_req = 0; - UE_sched_ctrl->cqi_req_timer); - // reset the scheduling request - emtc_active[CC_id]=1; - UE_template->ul_SR = 0; - status = mac_eNB_get_rrc_status(module_idP,rnti); + /* Power control: compute the expected ULSCH RX power (for the stats) */ + /* This is the normalized RX power and this should be constant (regardless of mcs) */ + normalized_rx_power = UE_sched_ctrl->pusch_snr[CC_id]; + target_rx_power = 178; - /* - if (status < RRC_CONNECTED) - cqi_req = 0; - else if (UE_sched_ctrl->cqi_req_timer>300) { - cqi_req = 1; - UE_sched_ctrl->cqi_req_timer=0; - - } - else - cqi_req = 0; - */ - cqi_req = 0; - - - //power control - //compute the expected ULSCH RX power (for the stats) - - // this is the normalized RX power and this should be constant (regardless of mcs - normalized_rx_power = UE_sched_ctrl->pusch_snr[CC_id]; - target_rx_power = 178; - - // this assumes accumulated tpc - // make sure that we are only sending a tpc update once a frame, otherwise the control loop will freak out - int32_t framex10psubframe = UE_template->pusch_tpc_tx_frame*10+UE_template->pusch_tpc_tx_subframe; - if (((framex10psubframe+10)<=(frameP*10+subframeP)) || //normal case - ((framex10psubframe>(frameP*10+subframeP)) && (((10240-framex10psubframe+frameP*10+subframeP)>=10)))) //frame wrap-around - { - UE_template->pusch_tpc_tx_frame=frameP; - UE_template->pusch_tpc_tx_subframe=subframeP; - if (normalized_rx_power>(target_rx_power+4)) { - tpc = 0; //-1 - UE_sched_ctrl->tpc_accumulated[CC_id]--; - } else if (normalized_rx_power<(target_rx_power-4)) { - tpc = 2; //+1 - UE_sched_ctrl->tpc_accumulated[CC_id]++; - } else { - tpc = 1; //0 - } + /* This assumes accumulated tpc */ + /* Make sure that we are only sending a tpc update once a frame, otherwise the control loop will freak out */ + int32_t framex10psubframe = UE_template->pusch_tpc_tx_frame * 10 + UE_template->pusch_tpc_tx_subframe; + if (((framex10psubframe + 10) <= (frameP * 10 + subframeP)) || // normal case + ((framex10psubframe > (frameP * 10 + subframeP)) && (((10240 - framex10psubframe + frameP * 10 + subframeP) >= 10)))) // frame wrap-around + { + UE_template->pusch_tpc_tx_frame = frameP; + UE_template->pusch_tpc_tx_subframe = subframeP; + if (normalized_rx_power > (target_rx_power + 4)) { + tpc = 0; //-1 + UE_sched_ctrl->tpc_accumulated[CC_id]--; + } else if (normalized_rx_power < (target_rx_power - 4)) { + tpc = 2; //+1 + UE_sched_ctrl->tpc_accumulated[CC_id]++; } else { + tpc = 1; //0 + } + } else { tpc = 1; //0 - } - //tpc = 1; + } + if (tpc != 1) { + LOG_D(MAC,"[eNB %d] ULSCH scheduler: frame %d, subframe %d, harq_pid %d, tpc %d, accumulated %d, normalized/target rx power %d/%d\n", + module_idP, + frameP, + subframeP, + harq_pid, + tpc, + UE_sched_ctrl->tpc_accumulated[CC_id], + normalized_rx_power, + target_rx_power); + } - if (tpc!=1) { - LOG_D(MAC,"[eNB %d] ULSCH scheduler: frame %d, subframe %d, harq_pid %d, tpc %d, accumulated %d, normalized/target rx power %d/%d\n", - module_idP,frameP,subframeP,harq_pid,tpc, - UE_sched_ctrl->tpc_accumulated[CC_id],normalized_rx_power,target_rx_power); + /* New transmission */ + if (round_UL == 0) { + ndi = 1 - UE_template->oldNDI_UL[harq_pid]; + + UE_template->oldNDI_UL[harq_pid] = ndi; + UE_template->mcs_UL[harq_pid] = 4; + UE_template->TBS_UL[harq_pid] = get_TBS_UL(UE_template->mcs_UL[harq_pid], 6); + + UE_list->eNB_UE_stats[CC_id][UE_id].normalized_rx_power = normalized_rx_power; + UE_list->eNB_UE_stats[CC_id][UE_id].target_rx_power = target_rx_power; + UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_mcs1 = 4; + UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_mcs2 = UE_template->mcs_UL[harq_pid]; + UE_list->eNB_UE_stats[CC_id][UE_id].total_rbs_used_rx += 6; + UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_TBS = UE_template->TBS_UL[harq_pid]; + + T(T_ENB_MAC_UE_UL_SCHEDULE, + T_INT(module_idP), + T_INT(CC_id), + T_INT(rnti), + T_INT(frameP), + T_INT(subframeP), + T_INT(harq_pid), + T_INT(UE_template->mcs_UL[harq_pid]), + T_INT(0), + T_INT(6), + T_INT(UE_template->TBS_UL[harq_pid]), + T_INT(ndi)); + + /* Store for possible retransmission */ + UE_template->nb_rb_ul[harq_pid] = 6; + UE_sched_ctrl->ul_scheduled |= (1 << harq_pid); + + if (UE_id == UE_list->head) { + VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_UE0_SCHEDULED, UE_sched_ctrl->ul_scheduled); } - // new transmission - if (round==0) { + /* Adjust total UL buffer status by TBS, wait for UL sdus to do final update */ + UE_template->scheduled_ul_bytes += UE_template->TBS_UL[harq_pid]; - ndi = 1-UE_template->oldNDI_UL[harq_pid]; - UE_template->oldNDI_UL[harq_pid]=ndi; - UE_list->eNB_UE_stats[CC_id][UE_id].normalized_rx_power=normalized_rx_power; - UE_list->eNB_UE_stats[CC_id][UE_id].target_rx_power=target_rx_power; - UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_mcs1=4; - UE_template->mcs_UL[harq_pid] = 4; + LOG_D(MAC, "scheduled_ul_bytes, new %d\n", UE_template->scheduled_ul_bytes); + /* Cyclic shift for DMRS */ + cshift = 0; // values from 0 to 7 can be used for mapping the cyclic shift (36.211 , Table 5.5.2.1.1-1) + /* save it for a potential retransmission */ + UE_template->cshift[harq_pid] = cshift; - UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_mcs2=UE_template->mcs_UL[harq_pid]; - // buffer_occupancy = UE_template->ul_total_buffer; + AssertFatal (UE_template->physicalConfigDedicated != NULL, "UE_template->physicalConfigDedicated is null\n"); + AssertFatal (UE_template->physicalConfigDedicated->ext4 != NULL, "UE_template->physicalConfigDedicated->ext4 is null\n"); + AssertFatal (UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11 != NULL, "UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11 is null\n"); + AssertFatal (UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.present == LTE_EPDCCH_Config_r11__config_r11_PR_setup, + "UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.present != setup\n"); + AssertFatal (UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.setConfigToAddModList_r11 != NULL, + "UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.setConfigToAddModList_r11 = NULL\n"); + + LTE_EPDCCH_SetConfig_r11_t *epdcch_setconfig_r11 = UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.setConfigToAddModList_r11->list.array[0]; + AssertFatal(epdcch_setconfig_r11 != NULL, "epdcch_setconfig_r11 is null\n"); + AssertFatal(epdcch_setconfig_r11->ext2 != NULL, "epdcch_setconfig_r11->ext2 is null\n"); + AssertFatal(epdcch_setconfig_r11->ext2->mpdcch_config_r13 != NULL, "epdcch_setconfig_r11->ext2->mpdcch_config_r13 is null"); + AssertFatal(epdcch_setconfig_r11->ext2->mpdcch_config_r13->present == LTE_EPDCCH_SetConfig_r11__ext2__mpdcch_config_r13_PR_setup, + "epdcch_setconfig_r11->ext2->mpdcch_config_r13->present is not setup\n"); + AssertFatal(epdcch_setconfig_r11->ext2->numberPRB_Pairs_v1310 != NULL, "epdcch_setconfig_r11->ext2->numberPRB_Pairs_v1310 is null"); + AssertFatal(epdcch_setconfig_r11->ext2->numberPRB_Pairs_v1310->present == LTE_EPDCCH_SetConfig_r11__ext2__numberPRB_Pairs_v1310_PR_setup, + "epdcch_setconfig_r11->ext2->numberPRB_Pairs_v1310->present is not setup\n"); + LOG_I(MAC,"[PUSCH %d] Frame %d, Subframe %d: Adding UL 6-0A MPDCCH for BL/CE UE %d/%x, ulsch_frame %d, ulsch_subframe %d, UESS MPDCCH Narrowband %d\n", + harq_pid, + frameP, + subframeP, + UE_id, + rnti, + sched_frame, + sched_subframeP, + (int)epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_Narrowband_r13 - 1); - UE_template->TBS_UL[harq_pid] = get_TBS_UL(UE_template->mcs_UL[harq_pid],6); - UE_list->eNB_UE_stats[CC_id][UE_id].total_rbs_used_rx+=6; - UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_TBS=UE_template->TBS_UL[harq_pid]; - // buffer_occupancy -= TBS; + UE_template->first_rb_ul[harq_pid] = narrowband_to_first_rb (cc, epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_Narrowband_r13 - 1); + + hi_dci0_pdu = &(hi_dci0_req->hi_dci0_pdu_list[hi_dci0_req->number_of_dci + hi_dci0_req->number_of_hi]); + memset((void*) hi_dci0_pdu, 0, sizeof(nfapi_hi_dci0_request_pdu_t)); - T(T_ENB_MAC_UE_UL_SCHEDULE, T_INT(module_idP), T_INT(CC_id), T_INT(rnti), T_INT(frameP), - T_INT(subframeP), T_INT(harq_pid), T_INT(UE_template->mcs_UL[harq_pid]), T_INT(0), T_INT(6), - T_INT(UE_template->TBS_UL[harq_pid]), T_INT(ndi)); + hi_dci0_pdu->pdu_type = NFAPI_HI_DCI0_MPDCCH_DCI_PDU_TYPE; + hi_dci0_pdu->pdu_size = (uint8_t) (2 + sizeof (nfapi_dl_config_mpdcch_pdu)); + hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.dci_format = (UE_template->rach_resource_type > 1) ? 5 : 4; + hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.ce_mode = (UE_template->rach_resource_type > 1) ? 2 : 1; + hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.mpdcch_narrowband = epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_Narrowband_r13 - 1; + hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.number_of_prb_pairs = 6; // checked above that it has to be this + hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.resource_block_assignment = 0; // Note: this can be dynamic + hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.mpdcch_transmission_type = epdcch_setconfig_r11->transmissionType_r11; // distibuted - // bad indices : 20 (40 PRB), 21 (45 PRB), 22 (48 PRB) - //store for possible retransmission - UE_template->nb_rb_ul[harq_pid] = 6; + AssertFatal(UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.startSymbol_r11 != NULL, + "UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.startSymbol_r11 is null\n"); + hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.start_symbol = *UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.startSymbol_r11; + hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.ecce_index = 0; // Note: this should be dynamic + hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.aggreagation_level = 24; // OK for CEModeA r1-3 (9.1.5-1b) or CEModeB r1-4 + hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.rnti_type = 4; // other + hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.rnti = rnti; + hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.ce_mode = (UE_template->rach_resource_type < 3) ? 1 : 2; // already set above... + hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.drms_scrambling_init = epdcch_setconfig_r11->dmrs_ScramblingSequenceInt_r11; + hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.initial_transmission_sf_io = (frameP * 10) + subframeP; + hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.transmission_power = 6000; // 0dB + hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.resource_block_start = UE_template->first_rb_ul[harq_pid]; + hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.number_of_resource_blocks = 6; + hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.mcs = 4; // adjust according to size of RAR, 208 bits with N1A_PRB = 3 + hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.pusch_repetition_levels = 0; - UE_sched_ctrl->ul_scheduled |= (1<head) - VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_UE0_SCHEDULED,UE_sched_ctrl->ul_scheduled); + AssertFatal(epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_pdsch_HoppingConfig_r13 == LTE_EPDCCH_SetConfig_r11__ext2__mpdcch_config_r13__setup__mpdcch_pdsch_HoppingConfig_r13_off, + "epdcch_setconfig_r11->ext2->mpdcch_config_r13->mpdcch_pdsch_HoppingConfig_r13 is not off\n"); + + hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.frequency_hopping_flag = 1 - epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_pdsch_HoppingConfig_r13; + hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.redudency_version = 0; + hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.new_data_indication = UE_template->oldNDI_UL[harq_pid]; + hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.harq_process = 0; + hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.tpc = tpc; + hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.csi_request = cqi_req; + hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.ul_inex = 0; + hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.dai_presence_flag = 0; + hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.dl_assignment_index = 0; + hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.srs_request = 0; + hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.dci_subframe_repetition_number = 0; + hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.tcp_bitmap = 0; + hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.total_dci_length_include_padding = 29; // hard-coded for 10 MHz + hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.number_of_tx_antenna_ports = 1; - // adjust total UL buffer status by TBS, wait for UL sdus to do final update - UE_template->scheduled_ul_bytes += UE_template->TBS_UL[harq_pid]; + hi_dci0_req->number_of_dci++; - LOG_D(MAC, "scheduled_ul_bytes, new %d\n", UE_template->scheduled_ul_bytes); + LOG_I(MAC,"[PUSCH %d] Frame %d, Subframe %d: Adding UL CONFIG. Request for BL/CE UE %d/%x, ulsch_frame %d, ulsch_subframe %d, UESS mpdcch narrowband %d\n", + harq_pid, + frameP, + subframeP, + UE_id, + rnti, + sched_frame, + sched_subframeP, + (int)epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_Narrowband_r13 - 1); + fill_nfapi_ulsch_config_request_rel8(&ul_req_tmp->ul_config_pdu_list[ul_req_tmp->number_of_pdus], + cqi_req, + cc, + UE_template->physicalConfigDedicated, + get_tmode(module_idP,CC_id,UE_id), + eNB->ul_handle, + rnti, + UE_template->first_rb_ul[harq_pid], // resource_block_start + UE_template->nb_rb_ul[harq_pid], // number_of_resource_blocks + UE_template->mcs_UL[harq_pid], + cshift, // cyclic_shift_2_for_drms + 0, // frequency_hopping_enabled_flag + 0, // frequency_hopping_bits + UE_template->oldNDI_UL[harq_pid], // new_data_indication + rvidx_tab[round_UL&3], // redundancy_version + harq_pid, // harq_process_number + 0, // ul_tx_mode + 0, // current_tx_nb + 0, // n_srs + UE_template->TBS_UL[harq_pid] + ); - // Cyclic shift for DM RS - cshift = 0;// values from 0 to 7 can be used for mapping the cyclic shift (36.211 , Table 5.5.2.1.1-1) - // save it for a potential retransmission - UE_template->cshift[harq_pid] = cshift; + fill_nfapi_ulsch_config_request_emtc(&ul_req_tmp->ul_config_pdu_list[ul_req_tmp->number_of_pdus], + UE_template->rach_resource_type > 2 ? 2 : 1, + 1, // total_number_of_repetitions + 1, // repetition_number + (frameP * 10) + subframeP); + + ul_req_tmp->number_of_pdus++; + eNB->ul_handle++; - AssertFatal (UE_template->physicalConfigDedicated != NULL, - "UE_template->physicalConfigDedicated is null\n"); - AssertFatal (UE_template->physicalConfigDedicated->ext4 != NULL, - "UE_template->physicalConfigDedicated->ext4 is null\n"); - AssertFatal (UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11 != NULL, - "UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11 is null\n"); - AssertFatal (UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.present == LTE_EPDCCH_Config_r11__config_r11_PR_setup, - "UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.present != setup\n"); - AssertFatal (UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.setConfigToAddModList_r11 != NULL, - "UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.setConfigToAddModList_r11 = NULL\n"); - LTE_EPDCCH_SetConfig_r11_t *epdcch_setconfig_r11 = UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.setConfigToAddModList_r11->list.array[0]; - AssertFatal(epdcch_setconfig_r11 != NULL, "epdcch_setconfig_r11 is null\n"); - AssertFatal(epdcch_setconfig_r11->ext2!=NULL, "epdcch_setconfig_r11->ext2 is null\n"); - AssertFatal(epdcch_setconfig_r11->ext2->mpdcch_config_r13!=NULL, - "epdcch_setconfig_r11->ext2->mpdcch_config_r13 is null"); - AssertFatal(epdcch_setconfig_r11->ext2->mpdcch_config_r13!=NULL, - "epdcch_setconfig_r11->ext2->mpdcch_config_r13 is null"); - AssertFatal(epdcch_setconfig_r11->ext2->mpdcch_config_r13->present==LTE_EPDCCH_SetConfig_r11__ext2__mpdcch_config_r13_PR_setup, - "epdcch_setconfig_r11->ext2->mpdcch_config_r13->present is not setup\n"); - AssertFatal(epdcch_setconfig_r11->ext2->numberPRB_Pairs_v1310!=NULL, - "epdcch_setconfig_r11->ext2->numberPRB_Pairs_v1310 is null"); - AssertFatal(epdcch_setconfig_r11->ext2->numberPRB_Pairs_v1310->present==LTE_EPDCCH_SetConfig_r11__ext2__numberPRB_Pairs_v1310_PR_setup, - "epdcch_setconfig_r11->ext2->numberPRB_Pairs_v1310->present is not setup\n"); + add_ue_ulsch_info(module_idP, + CC_id, + UE_id, + subframeP, + S_UL_SCHEDULED); - LOG_I(MAC,"[PUSCH %d] Frame %d, Subframe %d: Adding UL 6-0A MPDCCH for BL/CE UE %d/%x, ulsch_frame %d, ulsch_subframe %d,UESS MPDCCH Narrowband %d\n", - harq_pid,frameP,subframeP,UE_id,rnti,sched_frame,sched_subframeP,(int)epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_Narrowband_r13-1); + LOG_D(MAC,"[eNB %d] CC_id %d Frame %d, subframeP %d: Generated ULSCH DCI for next UE_id %d, format 0\n", + module_idP, + CC_id, + frameP, + subframeP, + UE_id); - UE_template->first_rb_ul[harq_pid] = narrowband_to_first_rb (cc, - epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_Narrowband_r13-1); - hi_dci0_pdu = &hi_dci0_req->hi_dci0_pdu_list[hi_dci0_req->number_of_dci+hi_dci0_req->number_of_hi]; - memset((void*)hi_dci0_pdu,0,sizeof(nfapi_hi_dci0_request_pdu_t)); + } else { // round_UL > 0 => retransmission + /* In LTE-M the UL HARQ process is asynchronous */ + T(T_ENB_MAC_UE_UL_SCHEDULE_RETRANSMISSION, + T_INT(module_idP), + T_INT(CC_id), + T_INT(rnti), + T_INT(frameP), + T_INT(subframeP), + T_INT(harq_pid), + T_INT(UE_template->mcs_UL[harq_pid]), + T_INT(0), + T_INT(6), + T_INT(round_UL)); - hi_dci0_pdu->pdu_type = NFAPI_HI_DCI0_MPDCCH_DCI_PDU_TYPE; - hi_dci0_pdu->pdu_size = (uint8_t) (2 + sizeof (nfapi_dl_config_mpdcch_pdu)); - hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.dci_format = (UE_template->rach_resource_type > 1) ? 5 : 4; - hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.ce_mode = (UE_template->rach_resource_type > 1) ? 2 : 1; - hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.mpdcch_narrowband = epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_Narrowband_r13-1; + AssertFatal (UE_template->physicalConfigDedicated != NULL, "UE_template->physicalConfigDedicated is null\n"); + AssertFatal (UE_template->physicalConfigDedicated->ext4 != NULL, "UE_template->physicalConfigDedicated->ext4 is null\n"); + AssertFatal (UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11 != NULL, "UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11 is null\n"); + AssertFatal (UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.present == LTE_EPDCCH_Config_r11__config_r11_PR_setup, + "UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.present != setup\n"); + AssertFatal (UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.setConfigToAddModList_r11 != NULL, + "UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.setConfigToAddModList_r11 = NULL\n"); + + LTE_EPDCCH_SetConfig_r11_t *epdcch_setconfig_r11 = UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.setConfigToAddModList_r11->list.array[0]; + + AssertFatal(epdcch_setconfig_r11 != NULL, "epdcch_setconfig_r11 is null\n"); + AssertFatal(epdcch_setconfig_r11->ext2 != NULL, "epdcch_setconfig_r11->ext2 is null\n"); + AssertFatal(epdcch_setconfig_r11->ext2->mpdcch_config_r13 != NULL, "epdcch_setconfig_r11->ext2->mpdcch_config_r13 is null"); + AssertFatal(epdcch_setconfig_r11->ext2->mpdcch_config_r13 != NULL, "epdcch_setconfig_r11->ext2->mpdcch_config_r13 is null"); + AssertFatal(epdcch_setconfig_r11->ext2->mpdcch_config_r13->present == LTE_EPDCCH_SetConfig_r11__ext2__mpdcch_config_r13_PR_setup, + "epdcch_setconfig_r11->ext2->mpdcch_config_r13->present is not setup\n"); + AssertFatal(epdcch_setconfig_r11->ext2->numberPRB_Pairs_v1310 != NULL, "epdcch_setconfig_r11->ext2->numberPRB_Pairs_v1310 is null"); + AssertFatal(epdcch_setconfig_r11->ext2->numberPRB_Pairs_v1310->present == LTE_EPDCCH_SetConfig_r11__ext2__numberPRB_Pairs_v1310_PR_setup, + "epdcch_setconfig_r11->ext2->numberPRB_Pairs_v1310->present is not setup\n"); - hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.number_of_prb_pairs = 6; // checked above that it has to be this - hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.resource_block_assignment = 0; // Note: this can be dynamic - hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.mpdcch_transmission_type = epdcch_setconfig_r11->transmissionType_r11; // distibuted + LOG_I(MAC,"[PUSCH %d] Frame %d, Subframe %d: Adding UL 6-0A MPDCCH for BL/CE UE %d/%x, ulsch_frame %d, ulsch_subframe %d,UESS MPDCCH Narrowband %d\n", + harq_pid, + frameP, + subframeP, + UE_id, + rnti, + sched_frame, + sched_subframeP, + (int)epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_Narrowband_r13 - 1); - AssertFatal(UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.startSymbol_r11!=NULL, - "UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.startSymbol_r11 is null\n"); + UE_template->first_rb_ul[harq_pid] = narrowband_to_first_rb(cc, epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_Narrowband_r13-1); + + hi_dci0_pdu = &(hi_dci0_req->hi_dci0_pdu_list[hi_dci0_req->number_of_dci+hi_dci0_req->number_of_hi]); + + memset((void*) hi_dci0_pdu, 0, sizeof(nfapi_hi_dci0_request_pdu_t)); - hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.start_symbol = *UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.startSymbol_r11; - hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.ecce_index = 0; // Note: this should be dynamic - hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.aggreagation_level = 24; // OK for CEModeA r1-3 (9.1.5-1b) or CEModeB r1-4 - hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.rnti_type = 4; // other - hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.rnti = rnti; - hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.ce_mode = (UE_template->rach_resource_type < 3) ? 1 : 2; - hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.drms_scrambling_init = epdcch_setconfig_r11->dmrs_ScramblingSequenceInt_r11; - hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.initial_transmission_sf_io = (frameP * 10) + subframeP; - hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.transmission_power = 6000; // 0dB - hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.resource_block_start = UE_template->first_rb_ul[harq_pid]; - hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.number_of_resource_blocks = 6; - hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.mcs = 4; // adjust according to size of RAR, 208 bits with N1A_PRB=3 - hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.pusch_repetition_levels = 0; - AssertFatal(epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_pdsch_HoppingConfig_r13== - LTE_EPDCCH_SetConfig_r11__ext2__mpdcch_config_r13__setup__mpdcch_pdsch_HoppingConfig_r13_off, - "epdcch_setconfig_r11->ext2->mpdcch_config_r13->mpdcch_pdsch_HoppingConfig_r13 is not off\n"); - hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.frequency_hopping_flag = 1-epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_pdsch_HoppingConfig_r13; - hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.redudency_version = 0; - hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.new_data_indication = UE_template->oldNDI_UL[harq_pid]; - hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.harq_process = 0; - hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.tpc = tpc; - hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.csi_request = cqi_req; - hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.ul_inex = 0; - hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.dai_presence_flag = 0; - hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.dl_assignment_index = 0; - hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.srs_request = 0; - hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.dci_subframe_repetition_number = 0; - hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.tcp_bitmap = 0; - hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.total_dci_length_include_padding = 29; // hard-coded for 10 MHz - hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.number_of_tx_antenna_ports = 1; + hi_dci0_pdu->pdu_type = NFAPI_HI_DCI0_MPDCCH_DCI_PDU_TYPE; + hi_dci0_pdu->pdu_size = (uint8_t) (2 + sizeof (nfapi_dl_config_mpdcch_pdu)); + hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.dci_format = (UE_template->rach_resource_type > 1) ? 5 : 4; + hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.ce_mode = (UE_template->rach_resource_type > 1) ? 2 : 1; + hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.mpdcch_narrowband = epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_Narrowband_r13 - 1; + hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.number_of_prb_pairs = 6; // checked above that it has to be this + hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.resource_block_assignment = 0; // Note: this can be dynamic + hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.mpdcch_transmission_type = epdcch_setconfig_r11->transmissionType_r11; // distibuted - hi_dci0_req->number_of_dci++; + AssertFatal(UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.startSymbol_r11 != NULL, + "UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.startSymbol_r11 is null\n"); + hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.start_symbol = *UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.startSymbol_r11; + hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.ecce_index = 0; // Note: this should be dynamic + hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.aggreagation_level = 24; // OK for CEModeA r1-3 (9.1.5-1b) or CEModeB r1-4 + hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.rnti_type = 4; // other + hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.rnti = rnti; + hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.ce_mode = (UE_template->rach_resource_type < 3) ? 1 : 2; + hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.drms_scrambling_init = epdcch_setconfig_r11->dmrs_ScramblingSequenceInt_r11; + hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.initial_transmission_sf_io = (frameP * 10) + subframeP; + hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.transmission_power = 6000; // 0dB + hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.resource_block_start = UE_template->first_rb_ul[harq_pid]; + hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.number_of_resource_blocks = 6; + hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.mcs = 4; // adjust according to size of RAR, 208 bits with N1A_PRB=3 + hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.pusch_repetition_levels = 0; - LOG_I(MAC,"[PUSCH %d] Frame %d, Subframe %d: Adding UL CONFIG.Request for BL/CE UE %d/%x, ulsch_frame %d, ulsch_subframe %d, UESS mpdcch narrowband %d\n", - harq_pid,frameP,subframeP,UE_id,rnti,sched_frame,sched_subframeP, - (int)epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_Narrowband_r13-1); + AssertFatal(epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_pdsch_HoppingConfig_r13 == LTE_EPDCCH_SetConfig_r11__ext2__mpdcch_config_r13__setup__mpdcch_pdsch_HoppingConfig_r13_off, + "epdcch_setconfig_r11->ext2->mpdcch_config_r13->mpdcch_pdsch_HoppingConfig_r13 is not off\n"); + + hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.frequency_hopping_flag = 1 - epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_pdsch_HoppingConfig_r13; + hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.redudency_version = rvidx_tab[round_UL&3]; + hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.new_data_indication = UE_template->oldNDI_UL[harq_pid]; + hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.harq_process = harq_pid; + hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.tpc = tpc; + hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.csi_request = cqi_req; + hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.ul_inex = 0; + hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.dai_presence_flag = 0; + hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.dl_assignment_index = 0; + hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.srs_request = 0; + hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.dci_subframe_repetition_number = 0; + hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.tcp_bitmap = 0; + hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.total_dci_length_include_padding = 29; // hard-coded for 10 MHz + hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.number_of_tx_antenna_ports = 1; + hi_dci0_req->number_of_dci++; - fill_nfapi_ulsch_config_request_rel8(&ul_req_tmp->ul_config_pdu_list[ul_req_tmp->number_of_pdus], - cqi_req, - cc, - UE_template->physicalConfigDedicated, - get_tmode(module_idP,CC_id,UE_id), - eNB->ul_handle, - rnti, - UE_template->first_rb_ul[harq_pid], // resource_block_start - UE_template->nb_rb_ul[harq_pid], // number_of_resource_blocks - UE_template->mcs_UL[harq_pid], - cshift, // cyclic_shift_2_for_drms - 0, // frequency_hopping_enabled_flag - 0, // frequency_hopping_bits - UE_template->oldNDI_UL[harq_pid], // new_data_indication - rvidx_tab[round&3], // redundancy_version - harq_pid, // harq_process_number - 0, // ul_tx_mode - 0, // current_tx_nb - 0, // n_srs - UE_template->TBS_UL[harq_pid] - ); - fill_nfapi_ulsch_config_request_emtc(&ul_req_tmp->ul_config_pdu_list[ul_req_tmp->number_of_pdus], - UE_template->rach_resource_type>2 ? 2 : 1, - 1, //total_number_of_repetitions - 1, //repetition_number - (frameP*10)+subframeP); - + fill_nfapi_ulsch_config_request_rel8(&ul_req_tmp->ul_config_pdu_list[ul_req_tmp->number_of_pdus], + cqi_req, + cc, + UE_template->physicalConfigDedicated, + get_tmode(module_idP,CC_id,UE_id), + eNB->ul_handle, + rnti, + UE_template->first_rb_ul[harq_pid], // resource_block_start + UE_template->nb_rb_ul[harq_pid], // number_of_resource_blocks + UE_template->mcs_UL[harq_pid], + cshift, // cyclic_shift_2_for_drms + 0, // frequency_hopping_enabled_flag + 0, // frequency_hopping_bits + UE_template->oldNDI_UL[harq_pid], // new_data_indication + rvidx_tab[round_UL&3], // redundancy_version + harq_pid, // harq_process_number + 0, // ul_tx_mode + 0, // current_tx_nb + 0, // n_srs + UE_template->TBS_UL[harq_pid] + ); - ul_req_tmp->number_of_pdus++; - eNB->ul_handle++; - - add_ue_ulsch_info(module_idP, - CC_id, - UE_id, - subframeP, - S_UL_SCHEDULED); - - LOG_D(MAC,"[eNB %d] CC_id %d Frame %d, subframeP %d: Generated ULSCH DCI for next UE_id %d, format 0\n", module_idP,CC_id,frameP,subframeP,UE_id); - - } - else { // round > 0 => retransmission - T(T_ENB_MAC_UE_UL_SCHEDULE_RETRANSMISSION, T_INT(module_idP), T_INT(CC_id), T_INT(rnti), T_INT(frameP), - T_INT(subframeP), T_INT(harq_pid), T_INT(UE_template->mcs_UL[harq_pid]), T_INT(0), T_INT(6), - T_INT(round)); - - AssertFatal (UE_template->physicalConfigDedicated != NULL, - "UE_template->physicalConfigDedicated is null\n"); - AssertFatal (UE_template->physicalConfigDedicated->ext4 != NULL, - "UE_template->physicalConfigDedicated->ext4 is null\n"); - AssertFatal (UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11 != NULL, - "UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11 is null\n"); - AssertFatal (UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.present == LTE_EPDCCH_Config_r11__config_r11_PR_setup, - "UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.present != setup\n"); - AssertFatal (UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.setConfigToAddModList_r11 != NULL, - "UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.setConfigToAddModList_r11 = NULL\n"); - LTE_EPDCCH_SetConfig_r11_t *epdcch_setconfig_r11 = UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.setConfigToAddModList_r11->list.array[0]; - AssertFatal(epdcch_setconfig_r11 != NULL, "epdcch_setconfig_r11 is null\n"); - AssertFatal(epdcch_setconfig_r11->ext2!=NULL, "epdcch_setconfig_r11->ext2 is null\n"); - AssertFatal(epdcch_setconfig_r11->ext2->mpdcch_config_r13!=NULL, - "epdcch_setconfig_r11->ext2->mpdcch_config_r13 is null"); - AssertFatal(epdcch_setconfig_r11->ext2->mpdcch_config_r13!=NULL, - "epdcch_setconfig_r11->ext2->mpdcch_config_r13 is null"); - AssertFatal(epdcch_setconfig_r11->ext2->mpdcch_config_r13->present==LTE_EPDCCH_SetConfig_r11__ext2__mpdcch_config_r13_PR_setup, - "epdcch_setconfig_r11->ext2->mpdcch_config_r13->present is not setup\n"); - AssertFatal(epdcch_setconfig_r11->ext2->numberPRB_Pairs_v1310!=NULL, - "epdcch_setconfig_r11->ext2->numberPRB_Pairs_v1310 is null"); - AssertFatal(epdcch_setconfig_r11->ext2->numberPRB_Pairs_v1310->present==LTE_EPDCCH_SetConfig_r11__ext2__numberPRB_Pairs_v1310_PR_setup, - "epdcch_setconfig_r11->ext2->numberPRB_Pairs_v1310->present is not setup\n"); - - LOG_I(MAC,"[PUSCH %d] Frame %d, Subframe %d: Adding UL 6-0A MPDCCH for BL/CE UE %d/%x, ulsch_frame %d, ulsch_subframe %d,UESS MPDCCH Narrowband %d\n", - harq_pid,frameP,subframeP,UE_id,rnti,sched_frame,sched_subframeP,(int)epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_Narrowband_r13-1); - - UE_template->first_rb_ul[harq_pid] = narrowband_to_first_rb (cc, - epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_Narrowband_r13-1); - hi_dci0_pdu = &hi_dci0_req->hi_dci0_pdu_list[hi_dci0_req->number_of_dci+hi_dci0_req->number_of_hi]; - memset((void*)hi_dci0_pdu,0,sizeof(nfapi_hi_dci0_request_pdu_t)); - - hi_dci0_pdu->pdu_type = NFAPI_HI_DCI0_MPDCCH_DCI_PDU_TYPE; - hi_dci0_pdu->pdu_size = (uint8_t) (2 + sizeof (nfapi_dl_config_mpdcch_pdu)); - hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.dci_format = (UE_template->rach_resource_type > 1) ? 5 : 4; - hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.ce_mode = (UE_template->rach_resource_type > 1) ? 2 : 1; - hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.mpdcch_narrowband = epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_Narrowband_r13-1; - - hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.number_of_prb_pairs = 6; // checked above that it has to be this - hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.resource_block_assignment = 0; // Note: this can be dynamic - hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.mpdcch_transmission_type = epdcch_setconfig_r11->transmissionType_r11; // distibuted - - AssertFatal(UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.startSymbol_r11!=NULL, - "UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.startSymbol_r11 is null\n"); - - hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.start_symbol = *UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.startSymbol_r11; - hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.ecce_index = 0; // Note: this should be dynamic - hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.aggreagation_level = 24; // OK for CEModeA r1-3 (9.1.5-1b) or CEModeB r1-4 - hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.rnti_type = 4; // other - hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.rnti = rnti; - hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.ce_mode = (UE_template->rach_resource_type < 3) ? 1 : 2; - hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.drms_scrambling_init = epdcch_setconfig_r11->dmrs_ScramblingSequenceInt_r11; - hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.initial_transmission_sf_io = (frameP * 10) + subframeP; - hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.transmission_power = 6000; // 0dB - hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.resource_block_start = UE_template->first_rb_ul[harq_pid]; - hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.number_of_resource_blocks = 6; - hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.mcs = 4; // adjust according to size of RAR, 208 bits with N1A_PRB=3 - hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.pusch_repetition_levels = 0; - AssertFatal(epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_pdsch_HoppingConfig_r13== - LTE_EPDCCH_SetConfig_r11__ext2__mpdcch_config_r13__setup__mpdcch_pdsch_HoppingConfig_r13_off, - "epdcch_setconfig_r11->ext2->mpdcch_config_r13->mpdcch_pdsch_HoppingConfig_r13 is not off\n"); - hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.frequency_hopping_flag = 1-epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_pdsch_HoppingConfig_r13; - hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.redudency_version = rvidx_tab[round&3]; - hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.new_data_indication = UE_template->oldNDI_UL[harq_pid]; - hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.harq_process = harq_pid; - hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.tpc = tpc; - hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.csi_request = cqi_req; - hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.ul_inex = 0; - hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.dai_presence_flag = 0; - hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.dl_assignment_index = 0; - hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.srs_request = 0; - hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.dci_subframe_repetition_number = 0; - hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.tcp_bitmap = 0; - hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.total_dci_length_include_padding = 29; // hard-coded for 10 MHz - hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.number_of_tx_antenna_ports = 1; - - hi_dci0_req->number_of_dci++; - fill_nfapi_ulsch_config_request_rel8(&ul_req_tmp->ul_config_pdu_list[ul_req_tmp->number_of_pdus], - cqi_req, - cc, - UE_template->physicalConfigDedicated, - get_tmode(module_idP,CC_id,UE_id), - eNB->ul_handle, - rnti, - UE_template->first_rb_ul[harq_pid], // resource_block_start - UE_template->nb_rb_ul[harq_pid], // number_of_resource_blocks - UE_template->mcs_UL[harq_pid], - cshift, // cyclic_shift_2_for_drms - 0, // frequency_hopping_enabled_flag - 0, // frequency_hopping_bits - UE_template->oldNDI_UL[harq_pid], // new_data_indication - rvidx_tab[round&3], // redundancy_version - harq_pid, // harq_process_number - 0, // ul_tx_mode - 0, // current_tx_nb - 0, // n_srs - UE_template->TBS_UL[harq_pid] - ); - fill_nfapi_ulsch_config_request_emtc(&ul_req_tmp->ul_config_pdu_list[ul_req_tmp->number_of_pdus], - UE_template->rach_resource_type>2 ? 2 : 1, - 1, //total_number_of_repetitions - 1, //repetition_number - (frameP*10)+subframeP); - - ul_req_tmp->number_of_pdus++; - eNB->ul_handle++; - - } - } // UE_is_to_be_scheduled + fill_nfapi_ulsch_config_request_emtc(&ul_req_tmp->ul_config_pdu_list[ul_req_tmp->number_of_pdus], + UE_template->rach_resource_type>2 ? 2 : 1, + 1, //total_number_of_repetitions + 1, //repetition_number + (frameP * 10) + subframeP); + + ul_req_tmp->number_of_pdus++; + eNB->ul_handle++; + } + } // UE_is_to_be_scheduled } // ULCCs } // loop over UE_id } diff --git a/openair2/LAYER2/MAC/mac_proto.h b/openair2/LAYER2/MAC/mac_proto.h index 6824e1b056..d29debb2a3 100644 --- a/openair2/LAYER2/MAC/mac_proto.h +++ b/openair2/LAYER2/MAC/mac_proto.h @@ -441,7 +441,7 @@ void init_ue_sched_info(void); void add_ue_ulsch_info(module_id_t module_idP, int CC_id, int UE_id, sub_frame_t subframe, UE_ULSCH_STATUS status); void add_ue_dlsch_info(module_id_t module_idP, int CC_id, int UE_id, - sub_frame_t subframe, UE_DLSCH_STATUS status); + sub_frame_t subframe, UE_DLSCH_STATUS status, rnti_t rnti); int find_UE_id(module_id_t module_idP, rnti_t rnti); int find_RA_id(module_id_t mod_idP, int CC_idP, rnti_t rntiP); rnti_t UE_RNTI(module_id_t module_idP, int UE_id); @@ -1209,7 +1209,6 @@ void fill_nfapi_dlsch_config(eNB_MAC_INST * eNB, void fill_nfapi_harq_information(module_id_t module_idP, int CC_idP, uint16_t rntiP, - uint16_t absSFP, nfapi_ul_config_harq_information * harq_information, uint8_t cce_idxP); @@ -1221,9 +1220,10 @@ void fill_nfapi_ulsch_harq_information(module_id_t module_idP, sub_frame_t subframeP); uint16_t fill_nfapi_uci_acknak(module_id_t module_idP, - int CC_idP, - uint16_t rntiP, - uint16_t absSFP, uint8_t cce_idxP); + int CC_idP, + uint16_t rntiP, + uint16_t absSFP, + uint8_t cce_idxP); void fill_nfapi_dl_dci_1A(nfapi_dl_config_request_pdu_t * dl_config_pdu, uint8_t aggregation_level, diff --git a/openair2/LAYER2/MAC/pre_processor.c b/openair2/LAYER2/MAC/pre_processor.c index 608321d71d..88c7db83c0 100644 --- a/openair2/LAYER2/MAC/pre_processor.c +++ b/openair2/LAYER2/MAC/pre_processor.c @@ -460,7 +460,12 @@ void decode_slice_positioning(module_id_t Mod_idP, // This fuction sorts the UE in order their dlsch buffer and CQI -void sort_UEs(module_id_t Mod_idP, int slice_idx, int frameP, sub_frame_t subframeP) { +void +sort_UEs(module_id_t Mod_idP, + int slice_idx, + int frameP, + sub_frame_t subframeP) +{ int i; int list[MAX_MOBILES_PER_ENB]; int list_size = 0; @@ -468,16 +473,13 @@ void sort_UEs(module_id_t Mod_idP, int slice_idx, int frameP, sub_frame_t subfra UE_list_t *UE_list = &RC.mac[Mod_idP]->UE_list; for (i = 0; i < MAX_MOBILES_PER_ENB; i++) { - if (UE_list->active[i] == FALSE) continue; - if (UE_RNTI(Mod_idP, i) == NOT_A_RNTI) continue; - - if (UE_list->UE_sched_ctrl[i].ul_out_of_sync == 1) continue; - - if (!ue_dl_slice_membership(Mod_idP, i, slice_idx)) continue; - - list[list_size] = i; - list_size++; + if (UE_list->active[i] == TRUE && + UE_RNTI(Mod_idP, i) != NOT_A_RNTI && + UE_list->UE_sched_ctrl[i].ul_out_of_sync != 1 && + ue_dl_slice_membership(Mod_idP, i, slice_idx)) { + list[list_size++] = i; + } } decode_sorting_policy(Mod_idP, slice_idx); @@ -1170,12 +1172,15 @@ dlsch_scheduler_pre_processor(module_id_t Mod_id, uint8_t CC_id; uint16_t i, j; int min_rb_unit[NFAPI_CC_MAX]; - slice_info_t *sli = &RC.mac[Mod_id]->slice_info; + + eNB_MAC_INST *eNB = RC.mac[Mod_id]; + slice_info_t *sli = &eNB->slice_info; uint16_t (*nb_rbs_required)[MAX_MOBILES_PER_ENB] = sli->pre_processor_results[slice_idx].nb_rbs_required; uint16_t (*nb_rbs_accounted)[MAX_MOBILES_PER_ENB] = sli->pre_processor_results[slice_idx].nb_rbs_accounted; uint16_t (*nb_rbs_remaining)[MAX_MOBILES_PER_ENB] = sli->pre_processor_results[slice_idx].nb_rbs_remaining; uint8_t (*MIMO_mode_indicator)[N_RBG_MAX] = sli->pre_processor_results[slice_idx].MIMO_mode_indicator; - UE_list_t *UE_list = &RC.mac[Mod_id]->UE_list; + + UE_list_t *UE_list = &eNB->UE_list; UE_sched_ctrl *ue_sched_ctl; // int rrc_status = RRC_IDLE; #ifdef TM5 @@ -1191,7 +1196,10 @@ dlsch_scheduler_pre_processor(module_id_t Mod_id, // Initialize scheduling information for all active UEs memset(&sli->pre_processor_results[slice_idx], 0, sizeof(sli->pre_processor_results[slice_idx])); // FIXME: After the memset above, some of the resets in reset() are redundant - dlsch_scheduler_pre_processor_reset(Mod_id, slice_idx, frameP, subframeP, + dlsch_scheduler_pre_processor_reset(Mod_id, + slice_idx, + frameP, + subframeP, min_rb_unit, nb_rbs_required, rballoc_sub, @@ -1199,44 +1207,63 @@ dlsch_scheduler_pre_processor(module_id_t Mod_id, mbsfn_flag); // FIXME: Not sure if useful // STATUS // Store the DLSCH buffer for each logical channel - store_dlsch_buffer(Mod_id, slice_idx, frameP, subframeP); + store_dlsch_buffer(Mod_id, + slice_idx, + frameP, + subframeP); + // Calculate the number of RBs required by each UE on the basis of logical channel's buffer - assign_rbs_required(Mod_id, slice_idx, frameP, subframeP, nb_rbs_required, min_rb_unit); + assign_rbs_required(Mod_id, + slice_idx, + frameP, + subframeP, + nb_rbs_required, + min_rb_unit); + // Sorts the user on the basis of dlsch logical channel buffer and CQI - sort_UEs(Mod_id, slice_idx, frameP, subframeP); + sort_UEs(Mod_id, + slice_idx, + frameP, + subframeP); + // ACCOUNTING // This procedure decides the number of RBs to allocate - dlsch_scheduler_pre_processor_accounting(Mod_id, slice_idx, frameP, subframeP, - min_rb_unit, - nb_rbs_required, - nb_rbs_accounted); + dlsch_scheduler_pre_processor_accounting(Mod_id, + slice_idx, + frameP, + subframeP, + min_rb_unit, + nb_rbs_required, + nb_rbs_accounted); // POSITIONING // This procedure does the main allocation of the RBs - dlsch_scheduler_pre_processor_positioning(Mod_id, slice_idx, - min_rb_unit, - nb_rbs_required, - nb_rbs_accounted, - nb_rbs_remaining, - rballoc_sub, - MIMO_mode_indicator); + dlsch_scheduler_pre_processor_positioning(Mod_id, + slice_idx, + min_rb_unit, + nb_rbs_required, + nb_rbs_accounted, + nb_rbs_remaining, + rballoc_sub, + MIMO_mode_indicator); // SHARING // If there are available RBs left in the slice, allocate them to the highest priority UEs - if (RC.mac[Mod_id]->slice_info.intraslice_share_active) { - dlsch_scheduler_pre_processor_intraslice_sharing(Mod_id, slice_idx, - min_rb_unit, - nb_rbs_required, - nb_rbs_accounted, - nb_rbs_remaining, - rballoc_sub, - MIMO_mode_indicator); + if (eNB->slice_info.intraslice_share_active) { + dlsch_scheduler_pre_processor_intraslice_sharing(Mod_id, + slice_idx, + min_rb_unit, + nb_rbs_required, + nb_rbs_accounted, + nb_rbs_remaining, + rballoc_sub, + MIMO_mode_indicator); } #ifdef TM5 // This has to be revisited!!!! for (CC_id = 0; CC_id < RC.nb_mac_CC[Mod_id]; CC_id++) { - COMMON_channels_t *cc = &RC.mac[Mod_id]->common_channels[CC_id]; + COMMON_channels_t *cc = &eNB->common_channels[CC_id]; int N_RBG = to_rbg(cc->mib->message.dl_Bandwidth); i1 = 0; i2 = 0; @@ -1244,35 +1271,25 @@ dlsch_scheduler_pre_processor(module_id_t Mod_id, for (j = 0; j < N_RBG; j++) { if (MIMO_mode_indicator[CC_id][j] == 2) { - i1 = i1 + 1; + i1++; } else if (MIMO_mode_indicator[CC_id][j] == 1) { - i2 = i2 + 1; + i2++; } else if (MIMO_mode_indicator[CC_id][j] == 0) { - i3 = i3 + 1; + i3++; } } - if ((i1 < N_RBG) && (i2 > 0) && (i3 == 0)) { - PHY_vars_eNB_g[Mod_id][CC_id]->check_for_SUMIMO_transmissions = - PHY_vars_eNB_g[Mod_id][CC_id]-> - check_for_SUMIMO_transmissions + 1; + if (i1 < N_RBG) { + if (i2 > 0 && i3 == 0) { + PHY_vars_eNB_g[Mod_id][CC_id]->check_for_SUMIMO_transmissions = PHY_vars_eNB_g[Mod_id][CC_id]->check_for_SUMIMO_transmissions + 1; + } else if (i3 > 0) { + PHY_vars_eNB_g[Mod_id][CC_id]->check_for_MUMIMO_transmissions = PHY_vars_eNB_g[Mod_id][CC_id]->check_for_MUMIMO_transmissions + 1; + } + } else if (i3 == N_RBG && i1 == 0 && i2 == 0) { + PHY_vars_eNB_g[Mod_id][CC_id]->FULL_MUMIMO_transmissions = PHY_vars_eNB_g[Mod_id][CC_id]->FULL_MUMIMO_transmissions + 1; } + PHY_vars_eNB_g[Mod_id][CC_id]->check_for_total_transmissions = PHY_vars_eNB_g[Mod_id][CC_id]->check_for_total_transmissions + 1; - if (i3 == N_RBG && i1 == 0 && i2 == 0) { - PHY_vars_eNB_g[Mod_id][CC_id]->FULL_MUMIMO_transmissions = - PHY_vars_eNB_g[Mod_id][CC_id]->FULL_MUMIMO_transmissions + - 1; - } - - if ((i1 < N_RBG) && (i3 > 0)) { - PHY_vars_eNB_g[Mod_id][CC_id]->check_for_MUMIMO_transmissions = - PHY_vars_eNB_g[Mod_id][CC_id]-> - check_for_MUMIMO_transmissions + 1; - } - - PHY_vars_eNB_g[Mod_id][CC_id]->check_for_total_transmissions = - PHY_vars_eNB_g[Mod_id][CC_id]->check_for_total_transmissions + - 1; } #endif @@ -1283,22 +1300,30 @@ dlsch_scheduler_pre_processor(module_id_t Mod_id, for (i = 0; i < UE_num_active_CC(UE_list, UE_id); i++) { CC_id = UE_list->ordered_CCids[i][UE_id]; //PHY_vars_eNB_g[Mod_id]->mu_mimo_mode[UE_id].dl_pow_off = dl_pow_off[UE_id]; - COMMON_channels_t *cc = &RC.mac[Mod_id]->common_channels[CC_id]; + COMMON_channels_t *cc = &eNB->common_channels[CC_id]; int N_RBG = to_rbg(cc->mib->message.dl_Bandwidth); if (ue_sched_ctl->pre_nb_available_rbs[CC_id] > 0) { - LOG_D(MAC, "******************DL Scheduling Information for UE%d ************************\n", UE_id); - LOG_D(MAC, "dl power offset UE%d = %d \n", UE_id, ue_sched_ctl->dl_pow_off[CC_id]); - LOG_D(MAC, "***********RB Alloc for every subband for UE%d ***********\n", UE_id); + LOG_D(MAC, "******************DL Scheduling Information for UE%d ************************\n", + UE_id); + LOG_D(MAC, "dl power offset UE%d = %d \n", + UE_id, + ue_sched_ctl->dl_pow_off[CC_id]); + LOG_D(MAC, "***********RB Alloc for every subband for UE%d ***********\n", + UE_id); for (j = 0; j < N_RBG; j++) { //PHY_vars_eNB_g[Mod_id]->mu_mimo_mode[UE_id].rballoc_sub[UE_id] = rballoc_sub_UE[CC_id][UE_id][UE_id]; - LOG_D(MAC, "RB Alloc for UE%d and Subband%d = %d\n", UE_id, j, ue_sched_ctl->rballoc_sub_UE[CC_id][j]); + LOG_D(MAC, "RB Alloc for UE%d and Subband%d = %d\n", + UE_id, j, + ue_sched_ctl->rballoc_sub_UE[CC_id][j]); } //PHY_vars_eNB_g[Mod_id]->mu_mimo_mode[UE_id].pre_nb_available_rbs = pre_nb_available_rbs[CC_id][UE_id]; LOG_D(MAC, "[eNB %d][SLICE %d]Total RBs allocated for UE%d = %d\n", - Mod_id, RC.mac[Mod_id]->slice_info.dl[slice_idx].id, UE_id, + Mod_id, + eNB->slice_info.dl[slice_idx].id, + UE_id, ue_sched_ctl->pre_nb_available_rbs[CC_id]); } } diff --git a/openair2/LAYER2/MAC/rar_tools.c b/openair2/LAYER2/MAC/rar_tools.c index 2fa13fc98c..284c0af19e 100644 --- a/openair2/LAYER2/MAC/rar_tools.c +++ b/openair2/LAYER2/MAC/rar_tools.c @@ -110,98 +110,124 @@ fill_rar(const module_id_t module_idP, #if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0)) //------------------------------------------------------------------------------ - +/* + * Fill the RAR buffer (header + PDU) for LTE-M devices + */ unsigned short fill_rar_br(eNB_MAC_INST *eNB, - int CC_id, - RA_t *ra, - const frame_t frameP, - const sub_frame_t subframeP, - uint8_t* const dlsch_buffer, - const uint8_t ce_level - ) + int CC_id, + RA_t *ra, + const frame_t frameP, + const sub_frame_t subframeP, + uint8_t* const dlsch_buffer, + const uint8_t ce_level) //------------------------------------------------------------------------------ { - - RA_HEADER_RAPID *rarh = (RA_HEADER_RAPID *)dlsch_buffer; + RA_HEADER_RAPID *rarh = (RA_HEADER_RAPID *) dlsch_buffer; COMMON_channels_t *cc = &eNB->common_channels[CC_id]; - uint8_t *rar = (uint8_t *)(dlsch_buffer+1); - - uint32_t rballoc,reps; - uint32_t TPC,ULdelay,cqireq,mpdcch_nb_index; - int input_buffer_length; + uint8_t *rar = (uint8_t *)(dlsch_buffer + 1); + uint32_t rballoc = 0; + uint32_t reps = 0; + uint32_t ULdelay = 0; + uint32_t cqireq = 0; + uint32_t mpdcch_nb_index = 0; + uint32_t TPC = 0; + int input_buffer_length = 0; + int N_NB_index = 0; AssertFatal(ra != NULL, "RA is null \n"); - // subheader fixed + /* Subheader fixed */ rarh->E = 0; // First and last RAR rarh->T = 1; // 0 for E/T/R/R/BI subheader, 1 for E/T/RAPID subheader - rarh->RAPID = ra->preamble_index; // Respond to Preamble 0 only for the moment - ra->timing_offset /= 16; //T_A = N_TA/16, where N_TA should be on a 30.72Msps - rar[0] = (uint8_t) (ra->timing_offset >> (2 + 4)); // 7 MSBs of timing advance + divide by 4 - rar[1] = (uint8_t) (ra->timing_offset << (4 - 2)) & 0xf0; // 4 LSBs of timing advance + divide by 4 + rarh->RAPID = ra->preamble_index; // Respond to Preamble + + /* RAR PDU */ + /* TA Command */ + ra->timing_offset /= 16; // T_A = N_TA/16, where N_TA should be on a 30.72Msps + rar[0] = (uint8_t) (ra->timing_offset >> 4) & 0x7f; // 7 MSBs of timing advance + rar[1] = (uint8_t) (ra->timing_offset & 0x0f) << 4; // 4 LSBs of timing advance - int N_NB_index; - - // Copy the Msg2 narrowband + /* Copy the Msg2 narrowband */ ra->msg34_narrowband = ra->msg2_narrowband; ra->msg3_first_rb = 0; ra->msg3_nb_rb = 2; - - if (ce_level < 2) { //CE Level 0,1, CEmodeA + if (ce_level < 2) { // CE Level 0, 1 (CEmodeA) input_buffer_length = 6; N_NB_index = get_numnarrowbandbits(cc->mib->message.dl_Bandwidth); - rar[4] = (uint8_t)(ra->rnti>>8); - rar[5] = (uint8_t)(ra->rnti&0xff); - //cc->ra[ra_idx].timing_offset = 0; - + /* UL Grant */ reps = 0; ra->msg3_mcs = 7; TPC = 3; // no power increase ULdelay = 0; cqireq = 0; mpdcch_nb_index = 0; - rballoc = mac_computeRIV(6,ra->msg3_first_rb,ra->msg3_nb_rb); + rballoc = mac_computeRIV(6, ra->msg3_first_rb, ra->msg3_nb_rb); uint32_t buffer = 0; buffer |= ra->msg34_narrowband << (16 + (4 - N_NB_index)); - buffer |= ((rballoc & 0xFF) << (12 + (4 - N_NB_index))); + buffer |= ((rballoc & 0x0F) << (12 + (4 - N_NB_index))); buffer |= ((reps & 0x03) << (10 + (4 - N_NB_index))); buffer |= ((ra->msg3_mcs & 0x07) << (7 + (4 - N_NB_index))); buffer |= ((TPC & 0x07) << (4 + (4 - N_NB_index))); buffer |= ((cqireq & 0x01) << (3 + (4 - N_NB_index))); buffer |= ((ULdelay & 0x01) << (2 + (4 - N_NB_index))); buffer |= (mpdcch_nb_index << (4 - N_NB_index)); - rar[1] = (buffer>>16) & 0x0F; - rar[2] = (buffer>>8) & 0xFF; - rar[3] = buffer&0xFF; + + rar[1] |= (uint8_t) (buffer >> 16) & 0x0F; + rar[2] = (uint8_t) (buffer >> 8) & 0xFF; + rar[3] = (uint8_t) buffer & 0xFF; + + /* RA CRNTI */ + rar[4] = (uint8_t)(ra->rnti >> 8); + rar[5] = (uint8_t)(ra->rnti & 0xff); + + } else { // CE level 2, 3 (CEModeB) + + AssertFatal(1 == 0, "Shouldn't get here ...\n"); + + input_buffer_length = 5; + + rar[3] = (uint8_t)(ra->rnti >> 8); + rar[4] = (uint8_t)(ra->rnti & 0xff); } - else { // CE level 2,3 => CEModeB - AssertFatal(1==0,"Shouldn't get here ...\n"); - input_buffer_length =5; - - - rar[3] = (uint8_t)(ra->rnti>>8); - rar[4] = (uint8_t)(ra->rnti&0xff); - } - LOG_I(MAC,"[RAPROC] Frame %d Subframe %d : Generating RAR BR (%02x|%02x.%02x.%02x.%02x.%02x.%02x) for ce_level %d, CRNTI %x,preamble %d/%d,TIMING OFFSET %d\n", - frameP,subframeP, - *(uint8_t*)rarh,rar[0],rar[1],rar[2],rar[3],rar[4],rar[5], + LOG_I(MAC, "[RAPROC] Frame %d Subframe %d : Generating RAR BR (%02x|%02x.%02x.%02x.%02x.%02x.%02x) for ce_level %d, CRNTI %x, preamble %d/%d, TIMING OFFSET %d\n", + frameP, + subframeP, + *(uint8_t*) rarh, + rar[0], + rar[1], + rar[2], + rar[3], + rar[4], + rar[5], ce_level, ra->rnti, - rarh->RAPID,ra->preamble_index, + rarh->RAPID, + ra->preamble_index, ra->timing_offset); if (opt_enabled) { - trace_pdu(DIRECTION_DOWNLINK , dlsch_buffer, input_buffer_length, eNB->Mod_id, WS_RA_RNTI , 1, - eNB->frame, eNB->subframe, 0, 0); - LOG_D(OPT, - "[RAPROC] RAR Frame %d trace pdu for rnti %x and rapid %d size %d\n", - frameP, ra->rnti, rarh->RAPID, input_buffer_length); + trace_pdu(DIRECTION_DOWNLINK, + dlsch_buffer, + input_buffer_length, + eNB->Mod_id, + WS_RA_RNTI, + 1, + eNB->frame, + eNB->subframe, + 0, + 0); + + LOG_D(OPT, "[RAPROC] RAR Frame %d trace pdu for rnti %x and rapid %d size %d\n", + frameP, + ra->rnti, + rarh->RAPID, + input_buffer_length); } return (ra->rnti); diff --git a/openair3/S1AP/s1ap_eNB_trace.c b/openair3/S1AP/s1ap_eNB_trace.c index 03c0ea4fb2..543ea9c511 100644 --- a/openair3/S1AP/s1ap_eNB_trace.c +++ b/openair3/S1AP/s1ap_eNB_trace.c @@ -107,7 +107,7 @@ int s1ap_eNB_handle_trace_start(uint32_t assoc_id, { S1AP_TraceStart_t *container; S1AP_TraceStartIEs_t *ie; - struct s1ap_eNB_ue_context_s *ue_desc_p; + struct s1ap_eNB_ue_context_s *ue_desc_p = NULL; struct s1ap_eNB_mme_data_s *mme_ref_p; DevAssert(pdu != NULL); diff --git a/openair3/TEST/EPC_TEST/generate_scenario.c b/openair3/TEST/EPC_TEST/generate_scenario.c index b8d9d9c588..b1a3297866 100644 --- a/openair3/TEST/EPC_TEST/generate_scenario.c +++ b/openair3/TEST/EPC_TEST/generate_scenario.c @@ -270,7 +270,7 @@ static void enb_config_display(void) printf( " ENB CONFIG FILE CONTENT LOADED:\n"); printf( "----------------------------------------------------------------------\n"); for (i = 0; i < g_enb_properties.number; i++) { - printf( "ENB CONFIG for instance %u:\n\n", i); + printf( "ENB CONFIG for instance %d:\n\n", i); printf( "\teNB name: \t%s\n",g_enb_properties.properties[i]->eNB_name); printf( "\teNB ID: \t%"PRIu32"\n",g_enb_properties.properties[i]->eNB_id); printf( "\tCell type: \t%s\n",g_enb_properties.properties[i]->cell_type == CELL_MACRO_ENB ? "CELL_MACRO_ENB":"CELL_HOME_ENB"); diff --git a/openair3/TEST/EPC_TEST/play_scenario.c b/openair3/TEST/EPC_TEST/play_scenario.c index 5928ab017f..a50eac95cf 100644 --- a/openair3/TEST/EPC_TEST/play_scenario.c +++ b/openair3/TEST/EPC_TEST/play_scenario.c @@ -1103,7 +1103,7 @@ et_config_parse_opt_line ( fprintf(stderr, "Please provide a valid -D/--delay-on-exit argument, %s is not a valid value\n", delay_on_exit); exit(1); } - printf("Delay on exit is %u\n", delay_on_exit); + printf("Delay on exit is %d\n", (int) delay_on_exit); } break; diff --git a/targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp b/targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp index f3094a4baa..bfdc80f9b5 100644 --- a/targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp +++ b/targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp @@ -28,7 +28,12 @@ #include #include #include +#include +#if UHD_VERSION < 3110000 #include +#else +#include +#endif #include #include #include @@ -183,7 +188,7 @@ static int sync_to_gps(openair0_device *device) { num_gps_locked++; std::cout << boost::format("GPS Locked\n"); } else { - std::cerr << "WARNING: GPS not locked - time will not be accurate until locked" << std::endl; + LOG_W(HW,"WARNING: GPS not locked - time will not be accurate until locked\n"); } //Set to GPS time @@ -724,6 +729,7 @@ void *freq_thread(void *arg) { usrp_state_t *s = (usrp_state_t *)device->priv; s->usrp->set_tx_freq(device->openair0_cfg[0].tx_freq[0]); s->usrp->set_rx_freq(device->openair0_cfg[0].rx_freq[0]); + return NULL; } /*! \brief Set frequencies (TX/RX). Spawns a thread to handle the frequency change to not block the calling thread * \param device the hardware to use @@ -1073,16 +1079,16 @@ extern "C" { uhd::device_addrs_t device_adds = uhd::device::find(args); if (device_adds.size() == 0) { - std::cerr<<"No USRP Device Found. " << std::endl; + LOG_E(HW,"No USRP Device Found.\n "); free(s); return -1; } else if (device_adds.size() > 1) { - std::cerr<<"More than one USRP Device Found. Please specify device more precisely in config file." << std::endl; + LOG_E(HW,"More than one USRP Device Found. Please specify device more precisely in config file.\n"); free(s); return -1; } - std::cerr << "Found USRP " << device_adds[0].get("type") << "\n"; + LOG_I(HW,"Found USRP %s\n", device_adds[0].get("type").c_str()); double usrp_master_clock; if (device_adds[0].get("type") == "b200") { @@ -1090,7 +1096,7 @@ extern "C" { device->type = USRP_B200_DEV; usrp_master_clock = 30.72e6; args += boost::str(boost::format(",master_clock_rate=%f") % usrp_master_clock); - args += ",num_send_frames=256,num_recv_frames=256, send_frame_size=15360, recv_frame_size=15360" ; + args += ",num_send_frames=256,num_recv_frames=256, send_frame_size=7680, recv_frame_size=7680" ; } if (device_adds[0].get("type") == "n3xx") { @@ -1287,8 +1293,9 @@ extern "C" { samples/=10000; LOG_I(PHY,"RF board max packet size %u, size for 100µs jitter %d \n", max, samples); - if ( samples < max ) + if ( samples < max ) { stream_args_rx.args["spp"] = str(boost::format("%d") % samples ); + } LOG_I(PHY,"rx_max_num_samps %zu\n", s->usrp->get_rx_stream(stream_args_rx)->get_max_num_samps()); diff --git a/targets/RT/USER/lte-ru.c b/targets/RT/USER/lte-ru.c index ce978d8b1a..5ac8a77f87 100644 --- a/targets/RT/USER/lte-ru.c +++ b/targets/RT/USER/lte-ru.c @@ -1,31 +1,23 @@ -/******************************************************************************* - OpenAirInterface - Copyright(c) 1999 - 2014 Eurecom - - OpenAirInterface is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - - OpenAirInterface is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with OpenAirInterface.The full GNU General Public License is - included in this distribution in the file called "COPYING". If not, - see . - - Contact Information - OpenAirInterface Admin: openair_admin@eurecom.fr - OpenAirInterface Tech : openair_tech@eurecom.fr - OpenAirInterface Dev : openair4g-devel@lists.eurecom.fr - - Address : Eurecom, Campus SophiaTech, 450 Route des Chappes, CS 50193 - 06904 Biot Sophia Antipolis cedex, FRANCE - -*******************************************************************************/ +/* + * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The OpenAirInterface Software Alliance licenses this file to You under + * the OAI Public License, Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.openairinterface.org/?page_id=698 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *------------------------------------------------------------------------------- + * For more information about the OpenAirInterface (OAI) Software Alliance: + * contact@openairinterface.org + */ /*! \file lte-enb.c * \brief Top-level threads for eNodeB