From b4158c415da072aa049442a4e94a92dff02d6dee Mon Sep 17 00:00:00 2001 From: hdtuanss Date: Mon, 8 May 2023 19:22:35 +0900 Subject: [PATCH] fixed missing paging --- src/include/MCSTracking.h | 2 +- src/include/Phy.h | 2 +- src/include/SubframeWorker.h | 6 +- src/src/DL_Sniffer_PDSCH.cc | 1582 +++++++++++++++++++--------------- src/src/MCSTracking.cc | 1265 ++++++++++++++++----------- src/src/Phy.cc | 2 +- src/src/SubframeWorker.cc | 391 +++++---- src/src/ULSchedule.cc | 113 ++- src/src/UL_Sniffer_PUSCH.cc | 680 +++++++++------ 9 files changed, 2350 insertions(+), 1693 deletions(-) diff --git a/src/include/MCSTracking.h b/src/include/MCSTracking.h index 006a1c5..51d26f2 100644 --- a/src/include/MCSTracking.h +++ b/src/include/MCSTracking.h @@ -159,7 +159,7 @@ class MCSTracking bool en_debug = false; uint16_t target_rnti = 0; int max_size = DL_SNIFFER_MCSTRACKING_MAX_SIZE; - long double interval = 5.0; // 4 secs + long double interval = 5.0; // 5 secs uint16_t rar_thresold = 3; // number of messages with DCI > 1A after rar response std::mutex tracking_mutex; // std::mutex config_mutex; diff --git a/src/include/Phy.h b/src/include/Phy.h index 77441e9..db2baa2 100644 --- a/src/include/Phy.h +++ b/src/include/Phy.h @@ -43,7 +43,7 @@ class Phy { void joinPending(); PhyCommon& getCommon(); DCIMetaFormats& getMetaFormats(); - std::vector >& getWorkers(); + std::vector>& getWorkers(); bool setCell(srsran_cell_t cell); void setRNTI(uint16_t rnti); void setChestCFOEstimateEnable(bool enable, uint32_t mask); diff --git a/src/include/SubframeWorker.h b/src/include/SubframeWorker.h index c36eb2a..4ce969d 100644 --- a/src/include/SubframeWorker.h +++ b/src/include/SubframeWorker.h @@ -64,12 +64,12 @@ class SubframeWorker { bool updateMetaFormats; bool collision_dw, collision_up; DCIBlindSearchStats stats; - LTESniffer_pcap_writer *pcapwriter; + LTESniffer_pcap_writer *pcapwriter; PDSCH_Decoder *pdschdecoder; int mcs_tracking_mode; MCSTracking *mcs_tracking; - int harq_mode; - HARQ *harq; + int harq_mode; + HARQ *harq; //uplink bool config = false; diff --git a/src/src/DL_Sniffer_PDSCH.cc b/src/src/DL_Sniffer_PDSCH.cc index f7f6442..9643893 100644 --- a/src/src/DL_Sniffer_PDSCH.cc +++ b/src/src/DL_Sniffer_PDSCH.cc @@ -2,60 +2,63 @@ float p_a_array[8]{-6, -4.77, -3, -1.77, 0, 1, 2, 3}; -PDSCH_Decoder::PDSCH_Decoder(uint32_t idx, - LTESniffer_pcap_writer *pcapwriter, +PDSCH_Decoder::PDSCH_Decoder(uint32_t idx, + LTESniffer_pcap_writer *pcapwriter, MCSTracking *mcs_tracking, - RNTIManager& rntiManager, + RNTIManager &rntiManager, HARQ *harq, - int mcs_tracking_mode, - int harq_mode, - int nof_antenna): -idx(idx), -sf_idx(0), -sfn(0), -buffer(), -falcon_ue_dl(), -dl_sf(), -ue_dl_cfg(), -ran_dl_collection(), -pdsch_res(), -pdsch_cfg(), -pcapwriter(pcapwriter), -mcs_tracking(mcs_tracking), -rntiManager(rntiManager), -harq(harq), -mcs_tracking_mode(mcs_tracking_mode), -sib2(), -nof_antenna(nof_antenna), -harq_mode(harq_mode) + int mcs_tracking_mode, + int harq_mode, + int nof_antenna) : idx(idx), + sf_idx(0), + sfn(0), + buffer(), + falcon_ue_dl(), + dl_sf(), + ue_dl_cfg(), + ran_dl_collection(), + pdsch_res(), + pdsch_cfg(), + pcapwriter(pcapwriter), + mcs_tracking(mcs_tracking), + rntiManager(rntiManager), + harq(harq), + mcs_tracking_mode(mcs_tracking_mode), + sib2(), + nof_antenna(nof_antenna), + harq_mode(harq_mode) { - set_debug_mode (mcs_tracking->get_debug_mode()); - set_api_mode (mcs_tracking->get_api_mode()); + set_debug_mode(mcs_tracking->get_debug_mode()); + set_api_mode(mcs_tracking->get_api_mode()); set_target_rnti(mcs_tracking->get_target_rnti()); /* Set algorithm for channel estimation*/ pdsch_cfg = new srsran_pdsch_cfg_t; pdsch_res = new srsran_pdsch_res_t[SRSRAN_MAX_CODEWORDS]; ZERO_OBJECT(*pdsch_cfg); - for (uint32_t i = 0; i < SRSRAN_MAX_CODEWORDS; i++) { - //pdsch_cfg->softbuffers.rx[i] = new srsran_softbuffer_rx_t; - //srsran_softbuffer_rx_init(pdsch_cfg->softbuffers.rx[i], SRSRAN_MAX_PRB); - buffer [i] = new srsran_softbuffer_rx_t; + for (uint32_t i = 0; i < SRSRAN_MAX_CODEWORDS; i++) + { + // pdsch_cfg->softbuffers.rx[i] = new srsran_softbuffer_rx_t; + // srsran_softbuffer_rx_init(pdsch_cfg->softbuffers.rx[i], SRSRAN_MAX_PRB); + buffer[i] = new srsran_softbuffer_rx_t; srsran_softbuffer_rx_init(buffer[i], SRSRAN_MAX_PRB); } - for (int i = 0; i < SRSRAN_MAX_CODEWORDS; i++) { + for (int i = 0; i < SRSRAN_MAX_CODEWORDS; i++) + { pdsch_res[i].payload = srsran_vec_u8_malloc(2000 * 8); - if (!pdsch_res[i].payload) { - ERROR("[PDSCH_Decoder] Allocating data\n"); + if (!pdsch_res[i].payload) + { + ERROR("[PDSCH_Decoder] Allocating data\n"); } } } PDSCH_Decoder::~PDSCH_Decoder() { - for (int i = 0; i < SRSRAN_MAX_CODEWORDS; i++) { + for (int i = 0; i < SRSRAN_MAX_CODEWORDS; i++) + { srsran_vec_u8_zero(pdsch_res[i].payload, 2000 * 8); - delete [] pdsch_res[i].payload; - //srsran_softbuffer_rx_free(pdsch_cfg->softbuffers.rx[i]); + delete[] pdsch_res[i].payload; + // srsran_softbuffer_rx_free(pdsch_cfg->softbuffers.rx[i]); srsran_softbuffer_rx_free(buffer[i]); } delete pdsch_cfg; @@ -69,114 +72,137 @@ int PDSCH_Decoder::init_pdsch_decoder(falcon_ue_dl_t *_falcon_ue_dl, uint32_t _sfn, uint32_t _sf_idx) { - falcon_ue_dl = _falcon_ue_dl; - dl_sf = _dl_sf; - ue_dl_cfg = _ue_dl_cfg; - ran_dl_collection = _ran_dl_collection; - sfn = _sfn; - sf_idx = _sf_idx; + falcon_ue_dl = _falcon_ue_dl; + dl_sf = _dl_sf; + ue_dl_cfg = _ue_dl_cfg; + ran_dl_collection = _ran_dl_collection; + sfn = _sfn; + sf_idx = _sf_idx; return SRSRAN_SUCCESS; } -int PDSCH_Decoder::decode_imsi_tmsi_paging(uint8_t* sdu_ptr, int length){ - int ret = SRSRAN_ERROR; - pcch_msg_s pcch_msg; - asn1::cbit_ref bref(sdu_ptr, length); - if (pcch_msg.unpack(bref) == asn1::SRSASN_SUCCESS or pcch_msg.msg.type().value == pcch_msg_type_c::types_opts::c1) { - paging_s* paging = &pcch_msg.msg.c1().paging(); - if( paging->paging_record_list_present){ - paging_record_list_l paging_record_list = paging->paging_record_list; - int record_size = paging_record_list.size(); - for (int record = 0; record < record_size; record++){ - paging_record_s paging_record = paging_record_list[record]; - if (paging_record.ue_id.type() == paging_ue_id_c::types_opts::imsi){ - std::string imsi_str; - for (int k = 0; k < 15; k++){ - uint8_t temp_imsi = paging_record.ue_id.imsi()[k]; - imsi_str.append(std::to_string(temp_imsi)); - print_api_dl(dl_sf->tti, 65534, ID_IMSI, imsi_str , MSG_PAGING); +int PDSCH_Decoder::decode_imsi_tmsi_paging(uint8_t *sdu_ptr, int length) +{ + int ret = SRSRAN_ERROR; + pcch_msg_s pcch_msg; + asn1::cbit_ref bref(sdu_ptr, length); + if (pcch_msg.unpack(bref) == asn1::SRSASN_SUCCESS or pcch_msg.msg.type().value == pcch_msg_type_c::types_opts::c1) + { + paging_s *paging = &pcch_msg.msg.c1().paging(); + if (paging->paging_record_list_present) + { + paging_record_list_l paging_record_list = paging->paging_record_list; + int record_size = paging_record_list.size(); + for (int record = 0; record < record_size; record++) + { + paging_record_s paging_record = paging_record_list[record]; + if (paging_record.ue_id.type() == paging_ue_id_c::types_opts::imsi) + { + std::string imsi_str; + for (int k = 0; k < 15; k++) + { + uint8_t temp_imsi = paging_record.ue_id.imsi()[k]; + imsi_str.append(std::to_string(temp_imsi)); + print_api_dl(dl_sf->tti, 65534, ID_IMSI, imsi_str, MSG_PAGING); + mcs_tracking->increase_nof_api_msg(); + ret = SRSRAN_SUCCESS; + } + // printf("Found IMSI paging\n"); + ret = SRSRAN_SUCCESS; + } + else if (paging_record.ue_id.type() == paging_ue_id_c::types_opts::s_tmsi) + { + uint32_t m_tmsi = paging_record.ue_id.s_tmsi().m_tmsi.to_number(); + std::stringstream ss; + ss << std::hex << m_tmsi; + std::string m_tmsi_str = ss.str(); + print_api_dl(dl_sf->tti, 65534, ID_TMSI, m_tmsi_str, MSG_PAGING); mcs_tracking->increase_nof_api_msg(); ret = SRSRAN_SUCCESS; } - //printf("Found IMSI paging\n"); - ret = SRSRAN_SUCCESS; - }else if (paging_record.ue_id.type() == paging_ue_id_c::types_opts::s_tmsi){ - uint32_t m_tmsi = paging_record.ue_id.s_tmsi().m_tmsi.to_number(); - std::stringstream ss; - ss << std::hex << m_tmsi; - std::string m_tmsi_str = ss.str(); - print_api_dl(dl_sf->tti, 65534, ID_TMSI, m_tmsi_str , MSG_PAGING); - mcs_tracking->increase_nof_api_msg(); - ret = SRSRAN_SUCCESS; } } } - } - return ret; + return ret; } -int PDSCH_Decoder::decode_rrc_connection_setup(uint8_t* sdu_ptr, int length, ltesniffer_ue_spec_config_t *ue_config){ - dl_ccch_msg_s dl_ccch_msg; - asn1::cbit_ref bref(sdu_ptr, length); - int asn1_result = dl_ccch_msg.unpack(bref); - if (asn1_result == asn1::SRSASN_SUCCESS && dl_ccch_msg.msg.type() == dl_ccch_msg_type_c::types_opts::c1){ - if (dl_ccch_msg.msg.c1().type().value == dl_ccch_msg_type_c::c1_c_::types::rrc_conn_setup){ - asn1::rrc::rrc_conn_setup_s con_setup = dl_ccch_msg.msg.c1().rrc_conn_setup(); - rrc_conn_setup_r8_ies_s* msg_r8 = &con_setup.crit_exts.c1().rrc_conn_setup_r8(); +int PDSCH_Decoder::decode_rrc_connection_setup(uint8_t *sdu_ptr, int length, ltesniffer_ue_spec_config_t *ue_config) +{ + dl_ccch_msg_s dl_ccch_msg; + asn1::cbit_ref bref(sdu_ptr, length); + int asn1_result = dl_ccch_msg.unpack(bref); + if (asn1_result == asn1::SRSASN_SUCCESS && dl_ccch_msg.msg.type() == dl_ccch_msg_type_c::types_opts::c1) + { + if (dl_ccch_msg.msg.c1().type().value == dl_ccch_msg_type_c::c1_c_::types::rrc_conn_setup) + { + asn1::rrc::rrc_conn_setup_s con_setup = dl_ccch_msg.msg.c1().rrc_conn_setup(); + rrc_conn_setup_r8_ies_s *msg_r8 = &con_setup.crit_exts.c1().rrc_conn_setup_r8(); rrc_con_set.rr_cfg_ded.phys_cfg_ded.pusch_cfg_ded.beta_offset_ack_idx = msg_r8->rr_cfg_ded.phys_cfg_ded.pusch_cfg_ded.beta_offset_ack_idx; rrc_con_set.rr_cfg_ded.phys_cfg_ded.pusch_cfg_ded.beta_offset_cqi_idx = msg_r8->rr_cfg_ded.phys_cfg_ded.pusch_cfg_ded.beta_offset_cqi_idx; rrc_con_set.rr_cfg_ded.phys_cfg_ded.pusch_cfg_ded.beta_offset_ri_idx = msg_r8->rr_cfg_ded.phys_cfg_ded.pusch_cfg_ded.beta_offset_ri_idx; /*get UE Specific config*/ - ue_config->p_a = p_a_array[msg_r8->rr_cfg_ded.phys_cfg_ded.pdsch_cfg_ded.p_a]; //convert p_a index to float number + ue_config->p_a = p_a_array[msg_r8->rr_cfg_ded.phys_cfg_ded.pdsch_cfg_ded.p_a]; // convert p_a index to float number ue_config->uci_config.I_offset_ack = msg_r8->rr_cfg_ded.phys_cfg_ded.pusch_cfg_ded.beta_offset_ack_idx; ue_config->uci_config.I_offset_cqi = msg_r8->rr_cfg_ded.phys_cfg_ded.pusch_cfg_ded.beta_offset_cqi_idx; - ue_config->uci_config.I_offset_ri = msg_r8->rr_cfg_ded.phys_cfg_ded.pusch_cfg_ded.beta_offset_ri_idx; - if (msg_r8->rr_cfg_ded.phys_cfg_ded.cqi_report_cfg.cqi_report_mode_aperiodic_present){ + ue_config->uci_config.I_offset_ri = msg_r8->rr_cfg_ded.phys_cfg_ded.pusch_cfg_ded.beta_offset_ri_idx; + if (msg_r8->rr_cfg_ded.phys_cfg_ded.cqi_report_cfg.cqi_report_mode_aperiodic_present) + { asn1::rrc::cqi_report_mode_aperiodic_e aperiodic_mode = msg_r8->rr_cfg_ded.phys_cfg_ded.cqi_report_cfg.cqi_report_mode_aperiodic; - if (aperiodic_mode == cqi_report_mode_aperiodic_opts::rm12){ - ue_config->cqi_config.type = SRSRAN_CQI_TYPE_WIDEBAND; - }else if (aperiodic_mode == cqi_report_mode_aperiodic_opts::rm20 || aperiodic_mode == cqi_report_mode_aperiodic_opts::rm22){ - ue_config->cqi_config.type = SRSRAN_CQI_TYPE_SUBBAND_UE; - } else if (aperiodic_mode == cqi_report_mode_aperiodic_opts::rm30 || aperiodic_mode == cqi_report_mode_aperiodic_opts::rm31){ - ue_config->cqi_config.type = SRSRAN_CQI_TYPE_SUBBAND_HL; + if (aperiodic_mode == cqi_report_mode_aperiodic_opts::rm12) + { + ue_config->cqi_config.type = SRSRAN_CQI_TYPE_WIDEBAND; + } + else if (aperiodic_mode == cqi_report_mode_aperiodic_opts::rm20 || aperiodic_mode == cqi_report_mode_aperiodic_opts::rm22) + { + ue_config->cqi_config.type = SRSRAN_CQI_TYPE_SUBBAND_UE; + } + else if (aperiodic_mode == cqi_report_mode_aperiodic_opts::rm30 || aperiodic_mode == cqi_report_mode_aperiodic_opts::rm31) + { + ue_config->cqi_config.type = SRSRAN_CQI_TYPE_SUBBAND_HL; } } ue_config->has_ue_config = true; - if (!has_default_config){ + if (!has_default_config) + { default_ue_spec_config = *ue_config; default_ue_spec_config.has_ue_config = false; has_default_config = true; } return SRSRAN_SUCCESS; - } else{ + } + else + { return SRSRAN_ERROR; } - } + } return SRSRAN_ERROR; } - -int PDSCH_Decoder::run_decode(int &mimo_ret, - srsran_dci_format_t cur_format, - srsran_dci_dl_t *cur_ran_dci_dl, - srsran_pdsch_grant_t *cur_grant, - uint32_t cur_rnti, - std::string table, - std::string RNTI_name, - uint32_t tti) +int PDSCH_Decoder::run_decode(int &mimo_ret, + srsran_dci_format_t cur_format, + srsran_dci_dl_t *cur_ran_dci_dl, + srsran_pdsch_grant_t *cur_grant, + uint32_t cur_rnti, + std::string table, + std::string RNTI_name, + uint32_t tti) { int ret = 0; mimo_ret = dl_sniffer_config_mimo(&falcon_ue_dl->q->cell, cur_format, cur_ran_dci_dl, cur_grant); - if (mimo_ret == SRSRAN_SUCCESS){ + if (mimo_ret == SRSRAN_SUCCESS) + { /* config pdsch_cfg for decoding pdsch*/ - pdsch_cfg->grant = *cur_grant; //check again here + pdsch_cfg->grant = *cur_grant; // check again here pdsch_cfg->rnti = cur_rnti; - - for (int i = 0; i < SRSRAN_MAX_CODEWORDS; i++) { - if (pdsch_cfg->grant.tb[i].enabled) { - if (pdsch_cfg->grant.tb[i].rv < 0) { - uint32_t k = (sfn / 2) % 4; + + for (int i = 0; i < SRSRAN_MAX_CODEWORDS; i++) + { + if (pdsch_cfg->grant.tb[i].enabled) + { + if (pdsch_cfg->grant.tb[i].rv < 0) + { + uint32_t k = (sfn / 2) % 4; pdsch_cfg->grant.tb[i].rv = ((uint32_t)ceilf((float)1.5 * k)) % 4; } pdsch_cfg->softbuffers.rx[i] = buffer[i]; @@ -184,21 +210,27 @@ int PDSCH_Decoder::run_decode(int &mimo_ret, } } - //main function to decode - if (pdsch_cfg->grant.tb[0].enabled||pdsch_cfg->grant.tb[1].enabled){ - if (srsran_ue_dl_decode_pdsch(falcon_ue_dl->q, dl_sf, pdsch_cfg, pdsch_res)) { - ERROR("ERROR: Decoding PDSCH"); + // main function to decode + if (pdsch_cfg->grant.tb[0].enabled || pdsch_cfg->grant.tb[1].enabled) + { + if (srsran_ue_dl_decode_pdsch(falcon_ue_dl->q, dl_sf, pdsch_cfg, pdsch_res)) + { + ERROR("ERROR: Decoding PDSCH"); } } - //write pcap file - for (uint32_t tb = 0; tb < SRSRAN_MAX_CODEWORDS; tb++) { - if (pdsch_res[tb].crc){ - int result_length = pdsch_cfg->grant.tb[tb].tbs/8; + // write pcap file + for (uint32_t tb = 0; tb < SRSRAN_MAX_CODEWORDS; tb++) + { + if (pdsch_res[tb].crc) + { + int result_length = pdsch_cfg->grant.tb[tb].tbs / 8; write_pcap(RNTI_name, pdsch_res[tb].payload, result_length, cur_rnti, tti, false); - - if (RNTI_name == "P_RNTI" && (api_mode == 2 || api_mode == 3)){ //IMSI catching modes + + if (RNTI_name == "P_RNTI" && (api_mode == 2 || api_mode == 3)) + { // IMSI catching modes int paging_ret = decode_imsi_tmsi_paging(pdsch_res[tb].payload, result_length); - if (paging_ret == SRSRAN_SUCCESS){ + if (paging_ret == SRSRAN_SUCCESS) + { pcapwriter->write_dl_paging_api(pdsch_res[tb].payload, result_length, cur_rnti, true, tti, false); } } @@ -213,109 +245,133 @@ int PDSCH_Decoder::run_decode(int &mimo_ret, bool found_res = false; while (pdu.next() && !found_res) { - if(pdu.get()->is_sdu()){ - int payload_length = pdu.get()->get_payload_size(); - uint8_t* sdu_ptr = pdu.get()->get_sdu_ptr(); + if (pdu.get()->is_sdu()) + { + int payload_length = pdu.get()->get_payload_size(); + uint8_t *sdu_ptr = pdu.get()->get_sdu_ptr(); /* Decode RRC Connection Setup when found valid sdu from MAC pdu*/ ltesniffer_ue_spec_config_t ue_config; int rrc_ret = decode_rrc_connection_setup(sdu_ptr, payload_length, &ue_config); - if (rrc_ret == SRSRAN_SUCCESS){ //success means RRC Connection Setup + if (rrc_ret == SRSRAN_SUCCESS) + { // success means RRC Connection Setup is_rrc_connection_setup = true; - ret = UL_SNIFFER_FOUND_CON_SET; - if (!mcs_tracking->check_default_config()){ + ret = UL_SNIFFER_FOUND_CON_SET; + if (!mcs_tracking->check_default_config()) + { mcs_tracking->update_default_ue_config(ue_config); mcs_tracking->set_has_default_config(); } mcs_tracking->update_ue_config_rnti(cur_rnti, ue_config); } - }else{ + } + else + { sub_header[subh_idx] = *pdu.get(); subh_idx++; } - if(is_rrc_connection_setup && (api_mode == 0 || api_mode == 3)){ - for (int h = 0; h < 4 && !found_res; h++){ - if ((dl_sch_lcid)sub_header[h].lcid_value() == dl_sch_lcid::CON_RES_ID){ + if (is_rrc_connection_setup && (api_mode == 0 || api_mode == 3)) + { + for (int h = 0; h < 4 && !found_res; h++) + { + if ((dl_sch_lcid)sub_header[h].lcid_value() == dl_sch_lcid::CON_RES_ID) + { uint64_t contention_resolution = sub_header[h].get_con_res_id(); std::stringstream ss; ss << std::hex << contention_resolution; std::string temp_con_res_str = ss.str(); - std::string con_res_str = temp_con_res_str.substr(3,8); + std::string con_res_str = temp_con_res_str.substr(3, 8); // printf("[API] SF: %d-%d Found RRC Connection Setup, Contention Resolution = %s, RNTI = %d \n", // tti/10, tti%10, con_res_str.c_str(), cur_rnti); - print_api_dl( tti, cur_rnti, ID_CON_RES , con_res_str, MSG_CON_SET); + print_api_dl(tti, cur_rnti, ID_CON_RES, con_res_str, MSG_CON_SET); mcs_tracking->increase_nof_api_msg(); found_res = true; } } - //write_pcap(RNTI_name, pdsch_res[tb].payload, result_length, cur_rnti, tti, false); + // write_pcap(RNTI_name, pdsch_res[tb].payload, result_length, cur_rnti, tti, false); pcapwriter->write_dl_crnti_api(pdsch_res[tb].payload, result_length, cur_rnti, true, tti, false); } } } } return ret; - } else { - //nothing + } + else + { + // nothing return ret; } } -int PDSCH_Decoder::decode_ul_mode(uint32_t rnti, std::vector *rar_result){ +int PDSCH_Decoder::decode_ul_mode(uint32_t rnti, std::vector *rar_result) +{ uint32_t tti = sfn * 10 + sf_idx; - for (auto decoding_mem:(*ran_dl_collection)){ + for (auto decoding_mem : (*ran_dl_collection)) + { /* set up variable*/ int harq_ret[SRSRAN_MAX_CODEWORDS] = {DL_SNIFFER_NEW_TX, DL_SNIFFER_NEW_TX}; srsran_dci_dl_t *cur_ran_dci_dl = decoding_mem.ran_dci_dl.get(); uint32_t cur_rnti = decoding_mem.rnti; srsran_dci_format_t cur_format = decoding_mem.format; std::string RNTI_name; - if((cur_rnti >= SRSRAN_RARNTI_START) && (cur_rnti <= SRSRAN_RARNTI_END)){ + if ((cur_rnti >= SRSRAN_RARNTI_START) && (cur_rnti <= SRSRAN_RARNTI_END)) + { srsran_pdsch_grant_t *cur_grant; cur_grant = decoding_mem.ran_pdsch_grant.get(); - for (uint32_t tb = 0; tb < SRSRAN_MAX_CODEWORDS; tb++) { - pdsch_res[tb].crc = false; + for (uint32_t tb = 0; tb < SRSRAN_MAX_CODEWORDS; tb++) + { + pdsch_res[tb].crc = false; } bool tb_en[SRSRAN_MAX_CODEWORDS]{cur_grant->tb[0].enabled, cur_grant->tb[1].enabled}; int mimo_ret = SRSRAN_SUCCESS; bool unknown_mcs; - /*try only 64QAM table*/ + /*try only 64QAM table*/ DL_Sniffer_rar_result result; int ret = run_rar_decode(cur_format, cur_ran_dci_dl, cur_grant, cur_rnti, result); - if (ret == SRSRAN_SUCCESS){ - rar_result->push_back(std::move(result)); - } else{ - //do nothing - } - }else if (cur_rnti == rnti || rnti == 0 || (cur_rnti > SRSRAN_RARNTI_END)) { - /* In the uplink sniffing mode, downlink sniffing function + if (ret == SRSRAN_SUCCESS) + { + rar_result->push_back(std::move(result)); + } + else + { + // do nothing + } + } + else if (cur_rnti == rnti || rnti == 0 || (cur_rnti > SRSRAN_RARNTI_END)) + { + /* In the uplink sniffing mode, downlink sniffing function / only decodes PDSCH messages that were detected by DCI 1 and 1A */ - if ((cur_format == SRSRAN_DCI_FORMAT1 || cur_format == SRSRAN_DCI_FORMAT1A)&&(cur_rnti!=SRSRAN_SIRNTI)) + if ((cur_format == SRSRAN_DCI_FORMAT1 || cur_format == SRSRAN_DCI_FORMAT1A) && (cur_rnti != SRSRAN_SIRNTI)) { - if (cur_rnti == SRSRAN_SIRNTI) { + if (cur_rnti == SRSRAN_SIRNTI) + { RNTI_name = "SI_RNTI"; } - else if (cur_rnti == SRSRAN_PRNTI) { + else if (cur_rnti == SRSRAN_PRNTI) + { RNTI_name = "P_RNTI"; - //std::cout << "P_RNTI" << std::endl; + // std::cout << "P_RNTI" << std::endl; } - else if ((cur_rnti > SRSRAN_RARNTI_START) && (cur_rnti < SRSRAN_RARNTI_END)) { + else if ((cur_rnti > SRSRAN_RARNTI_START) && (cur_rnti < SRSRAN_RARNTI_END)) + { RNTI_name = "RA_RNTI"; } - else { - RNTI_name = "C_RNTI" ; + else + { + RNTI_name = "C_RNTI"; } - //mcs + // mcs srsran_pdsch_grant_t *cur_grant; srsran_pdsch_grant_t *cur_grant256; cur_grant = decoding_mem.ran_pdsch_grant.get(); cur_grant256 = decoding_mem.ran_pdsch_grant_256.get(); - for (uint32_t tb = 0; tb < SRSRAN_MAX_CODEWORDS; tb++) { - pdsch_res[tb].crc = false; + for (uint32_t tb = 0; tb < SRSRAN_MAX_CODEWORDS; tb++) + { + pdsch_res[tb].crc = false; } bool tb_en[SRSRAN_MAX_CODEWORDS]{cur_grant->tb[0].enabled, cur_grant->tb[1].enabled}; @@ -323,7 +379,8 @@ int PDSCH_Decoder::decode_ul_mode(uint32_t rnti, std::vectorq->cell, cur_format, cur_ran_dci_dl, cur_grant); - if (mimo_ret == SRSRAN_SUCCESS){ + if (mimo_ret == SRSRAN_SUCCESS) + { /* config pdsch_cfg for decoding pdsch*/ pdsch_cfg->grant = *cur_grant; pdsch_cfg->rnti = cur_rnti; - - for (int i = 0; i < SRSRAN_MAX_CODEWORDS; i++) { - if (pdsch_cfg->grant.tb[i].enabled) { - if (pdsch_cfg->grant.tb[i].rv < 0) { - uint32_t k = (sfn / 2) % 4; + + for (int i = 0; i < SRSRAN_MAX_CODEWORDS; i++) + { + if (pdsch_cfg->grant.tb[i].enabled) + { + if (pdsch_cfg->grant.tb[i].rv < 0) + { + uint32_t k = (sfn / 2) % 4; pdsch_cfg->grant.tb[i].rv = ((uint32_t)ceilf((float)1.5 * k)) % 4; } pdsch_cfg->softbuffers.rx[i] = buffer[i]; @@ -389,30 +457,40 @@ int PDSCH_Decoder::decode_SIB() //change to decode SIB } } - //main function to decode - if (pdsch_cfg->grant.tb[0].enabled||pdsch_cfg->grant.tb[1].enabled){ - if (srsran_ue_dl_decode_pdsch(falcon_ue_dl->q, dl_sf, pdsch_cfg, pdsch_res)) { - ERROR("ERROR: Decoding PDSCH"); + // main function to decode + if (pdsch_cfg->grant.tb[0].enabled || pdsch_cfg->grant.tb[1].enabled) + { + if (srsran_ue_dl_decode_pdsch(falcon_ue_dl->q, dl_sf, pdsch_cfg, pdsch_res)) + { + ERROR("ERROR: Decoding PDSCH"); } } - //write pcap file - for (uint32_t tb = 0; tb < SRSRAN_MAX_CODEWORDS; tb++) { - if (pdsch_res[tb].crc){ - int result_length = pdsch_cfg->grant.tb[tb].tbs/8; + // write pcap file + for (uint32_t tb = 0; tb < SRSRAN_MAX_CODEWORDS; tb++) + { + if (pdsch_res[tb].crc) + { + int result_length = pdsch_cfg->grant.tb[tb].tbs / 8; /*Unpack SIB to get Uplink config from SIB2*/ asn1::rrc::bcch_dl_sch_msg_s dlsch_msg; - asn1::cbit_ref dlsch_bref(pdsch_res[tb].payload, result_length); + asn1::cbit_ref dlsch_bref(pdsch_res[tb].payload, result_length); asn1::SRSASN_CODE err = dlsch_msg.unpack(dlsch_bref); - if (err == asn1::SRSASN_SUCCESS){ - if (dlsch_msg.msg.c1().type() == asn1::rrc::bcch_dl_sch_msg_type_c::c1_c_::types::sib_type1){ + if (err == asn1::SRSASN_SUCCESS) + { + if (dlsch_msg.msg.c1().type() == asn1::rrc::bcch_dl_sch_msg_type_c::c1_c_::types::sib_type1) + { // do nothing - } else { - asn1::rrc::sys_info_r8_ies_s::sib_type_and_info_l_& sib_list = + } + else + { + asn1::rrc::sys_info_r8_ies_s::sib_type_and_info_l_ &sib_list = dlsch_msg.msg.c1().sys_info().crit_exts.sys_info_r8().sib_type_and_info; - for (uint32_t i = 0; i < sib_list.size(); ++i) { + for (uint32_t i = 0; i < sib_list.size(); ++i) + { /*SIB2*/ - if (sib_list[i].type().value==asn1::rrc::sib_info_item_c::types::sib2){ + if (sib_list[i].type().value == asn1::rrc::sib_info_item_c::types::sib2) + { sib2 = sib_list[i].sib2(); /*Write pcap*/ write_pcap(RNTI_name, pdsch_res[tb].payload, result_length, cur_rnti, tti, harq_ret); @@ -421,83 +499,93 @@ int PDSCH_Decoder::decode_SIB() //change to decode SIB } } } - } } - } else { - //nothing + } + else + { + // nothing } } - } //end of decoding loop + } // end of decoding loop return SRSRAN_SUCCESS; } -int PDSCH_Decoder::decode_mac_ce(uint32_t rnti){ +int PDSCH_Decoder::decode_mac_ce(uint32_t rnti) +{ uint32_t tti = sfn * 10 + sf_idx; - for (auto decoding_mem:(*ran_dl_collection)){ + for (auto decoding_mem : (*ran_dl_collection)) + { /* set up variable*/ int harq_ret[SRSRAN_MAX_CODEWORDS] = {DL_SNIFFER_NEW_TX, DL_SNIFFER_NEW_TX}; srsran_dci_dl_t *cur_ran_dci_dl = decoding_mem.ran_dci_dl.get(); uint32_t cur_rnti = decoding_mem.rnti; srsran_dci_format_t cur_format = decoding_mem.format; std::string RNTI_name; - if (cur_rnti == rnti) { + if (cur_rnti == rnti) + { RNTI_name = "C_RNTI"; - //mcs + // mcs srsran_pdsch_grant_t *cur_grant; srsran_pdsch_grant_t *cur_grant256; cur_grant = decoding_mem.ran_pdsch_grant.get(); cur_grant256 = decoding_mem.ran_pdsch_grant_256.get(); - for (uint32_t tb = 0; tb < SRSRAN_MAX_CODEWORDS; tb++) { - pdsch_res[tb].crc = false; + for (uint32_t tb = 0; tb < SRSRAN_MAX_CODEWORDS; tb++) + { + pdsch_res[tb].crc = false; } bool tb_en[SRSRAN_MAX_CODEWORDS]{cur_grant->tb[0].enabled, cur_grant->tb[1].enabled}; int mimo_ret = SRSRAN_SUCCESS; bool unknown_mcs; run_decode(mimo_ret, cur_format, cur_ran_dci_dl, cur_grant, cur_rnti, "64QAM table", RNTI_name, tti); - if (!pdsch_res[0].crc&&!pdsch_res[1].crc) + if (!pdsch_res[0].crc && !pdsch_res[1].crc) { run_decode(mimo_ret, cur_format, cur_ran_dci_dl, cur_grant256, cur_rnti, "256QAM table", RNTI_name, tti); } } - } //end of decoding loop + } // end of decoding loop return SRSRAN_SUCCESS; -} +} -void PDSCH_Decoder::write_pcap(std::string RNTI_name, uint8_t *pdu, uint32_t pdu_len_bytes, uint16_t crnti, uint32_t tti, bool retx){ - - if (RNTI_name == "SI_RNTI"){ - pcapwriter->write_dl_sirnti(pdu, pdu_len_bytes, true, tti); +void PDSCH_Decoder::write_pcap(std::string RNTI_name, uint8_t *pdu, uint32_t pdu_len_bytes, uint16_t crnti, uint32_t tti, bool retx) +{ - }else if (RNTI_name == "P_RNTI"){ + if (RNTI_name == "SI_RNTI") + { + pcapwriter->write_dl_sirnti(pdu, pdu_len_bytes, true, tti); + } + else if (RNTI_name == "P_RNTI") + { pcapwriter->write_dl_pch(pdu, pdu_len_bytes, true, tti); - - }else if (RNTI_name == "RA_RNTI"){ + } + else if (RNTI_name == "RA_RNTI") + { pcapwriter->write_dl_ranti(pdu, pdu_len_bytes, crnti, true, tti); - - } else{ //CRNTI + } + else + { // CRNTI pcapwriter->write_dl_crnti(pdu, pdu_len_bytes, crnti, true, tti, retx); } - } -int PDSCH_Decoder::unpack_rar_response_ul_mode(uint8_t *payload, int length, DL_Sniffer_rar_result &result){ +int PDSCH_Decoder::unpack_rar_response_ul_mode(uint8_t *payload, int length, DL_Sniffer_rar_result &result) +{ int ret = SRSRAN_ERROR; srsran::rar_pdu rar_pdu_msg; rar_pdu_msg.init_rx(length); - if (rar_pdu_msg.parse_packet(payload) == SRSRAN_SUCCESS) //T_note: check here + if (rar_pdu_msg.parse_packet(payload) == SRSRAN_SUCCESS) // T_note: check here { while (rar_pdu_msg.next()) { result.t_crnti = rar_pdu_msg.get()->get_temp_crnti(); result.ta = rar_pdu_msg.get()->get_ta_cmd(); rar_pdu_msg.get()->get_sched_grant(result.grant); - srsran_dci_ul_t dci_ul; + srsran_dci_ul_t dci_ul; srsran_dci_rar_grant_t rar_grant; ul_sniffer_dci_rar_unpack(result.grant, &rar_grant); ul_sniffer_dci_rar_to_ul_dci(&falcon_ue_dl->q->cell, &rar_grant, &dci_ul); @@ -511,7 +599,7 @@ int PDSCH_Decoder::unpack_rar_response_ul_mode(uint8_t *payload, int length, DL_ ul_sf.tdd_config = dl_sf->tdd_config; ul_sf.tti = dl_sf->tti; ul_sniffer_ra_ul_dci_to_grant(&falcon_ue_dl->q->cell, &ul_sf, &hopping_cfg, &dci_ul, &result.ran_ul_grant); - rntiManager.activateAndRefresh(result.t_crnti, 0, ActivationReason::RM_ACT_RAR); //add RNTI in RAR response to active list + rntiManager.activateAndRefresh(result.t_crnti, 0, ActivationReason::RM_ACT_RAR); // add RNTI in RAR response to active list // std::cout << " RAR: " << "TA = " << result.ta; // std::cout << " -- T-CRNTI: " << result.t_crnti; // std::cout << " -- GRANT: "; @@ -519,107 +607,123 @@ int PDSCH_Decoder::unpack_rar_response_ul_mode(uint8_t *payload, int length, DL_ // std::cout << unsigned(result.grant[g]) << " "; // } // std::cout << std::endl; - ret = SRSRAN_SUCCESS; + ret = SRSRAN_SUCCESS; } } return ret; } int PDSCH_Decoder::run_rar_decode(srsran_dci_format_t cur_format, - srsran_dci_dl_t *cur_ran_dci_dl, - srsran_pdsch_grant_t *cur_grant, - uint32_t cur_rnti, - DL_Sniffer_rar_result &result) + srsran_dci_dl_t *cur_ran_dci_dl, + srsran_pdsch_grant_t *cur_grant, + uint32_t cur_rnti, + DL_Sniffer_rar_result &result) { - //std::cout << "Runing table: " << table << std::endl; + // std::cout << "Runing table: " << table << std::endl; std::string RNTI_name = "RA_RNTI"; - uint32_t tti = sfn*10 + sf_idx; - int mimo_ret = SRSRAN_SUCCESS; + uint32_t tti = sfn * 10 + sf_idx; + int mimo_ret = SRSRAN_SUCCESS; mimo_ret = dl_sniffer_config_mimo(&falcon_ue_dl->q->cell, cur_format, cur_ran_dci_dl, cur_grant); - if (mimo_ret == SRSRAN_SUCCESS){ + if (mimo_ret == SRSRAN_SUCCESS) + { /* config pdsch_cfg for decoding pdsch*/ - pdsch_cfg->grant = *cur_grant; //check again here + pdsch_cfg->grant = *cur_grant; // check again here pdsch_cfg->rnti = cur_rnti; - - for (int i = 0; i < SRSRAN_MAX_CODEWORDS; i++) { - if (pdsch_cfg->grant.tb[i].enabled) { - if (pdsch_cfg->grant.tb[i].rv < 0) { - uint32_t k = (sfn / 2) % 4; + + for (int i = 0; i < SRSRAN_MAX_CODEWORDS; i++) + { + if (pdsch_cfg->grant.tb[i].enabled) + { + if (pdsch_cfg->grant.tb[i].rv < 0) + { + uint32_t k = (sfn / 2) % 4; pdsch_cfg->grant.tb[i].rv = ((uint32_t)ceilf((float)1.5 * k)) % 4; } pdsch_cfg->softbuffers.rx[i] = buffer[i]; srsran_softbuffer_rx_reset_tbs(pdsch_cfg->softbuffers.rx[i], (uint32_t)pdsch_cfg->grant.tb[i].tbs); } } - //std::cout << "Runing table: " << table << " -- 0" << std::endl; - //main function to decode - if (pdsch_cfg->grant.tb[0].enabled||pdsch_cfg->grant.tb[1].enabled){ - //std::cout << "Runing table: " << table << " -- 1" << std::endl; - if (srsran_ue_dl_decode_pdsch(falcon_ue_dl->q, dl_sf, pdsch_cfg, pdsch_res)) { - ERROR("ERROR: Decoding PDSCH"); + // std::cout << "Runing table: " << table << " -- 0" << std::endl; + // main function to decode + if (pdsch_cfg->grant.tb[0].enabled || pdsch_cfg->grant.tb[1].enabled) + { + // std::cout << "Runing table: " << table << " -- 1" << std::endl; + if (srsran_ue_dl_decode_pdsch(falcon_ue_dl->q, dl_sf, pdsch_cfg, pdsch_res)) + { + ERROR("ERROR: Decoding PDSCH"); } } - for (uint32_t tb = 0; tb < SRSRAN_MAX_CODEWORDS; tb++) { - if (pdsch_res[tb].crc){ - int result_length = pdsch_cfg->grant.tb[tb].tbs/8; - write_pcap(RNTI_name, pdsch_res[tb].payload, result_length, cur_rnti, tti, false); + for (uint32_t tb = 0; tb < SRSRAN_MAX_CODEWORDS; tb++) + { + if (pdsch_res[tb].crc) + { + int result_length = pdsch_cfg->grant.tb[tb].tbs / 8; + write_pcap(RNTI_name, pdsch_res[tb].payload, result_length, cur_rnti, tti, false); /*Unpack PDSCH msg to receive rar*/ - std::time_t epoch = std::time(nullptr); - char* time = std::asctime(std::localtime(&epoch)); - std::string time_str; - for (int idx = 11; idx < 19; idx++){ - time_str.push_back(time[idx]); - } - time_str = "[" + time_str + "]"; - unpack_rar_response_ul_mode(pdsch_res->payload, result_length, result); + std::time_t epoch = std::time(nullptr); + char *time = std::asctime(std::localtime(&epoch)); + std::string time_str; + for (int idx = 11; idx < 19; idx++) + { + time_str.push_back(time[idx]); + } + time_str = "[" + time_str + "]"; + unpack_rar_response_ul_mode(pdsch_res->payload, result_length, result); return SRSASN_SUCCESS; } } - return SRSRAN_ERROR; - } else { + return SRSRAN_ERROR; + } + else + { // std::cout << "Config MIMO wrong: " << mimo_ret << std::endl; - return SRSRAN_ERROR; + return SRSRAN_ERROR; } } - -int PDSCH_Decoder::decode_rar(DL_Sniffer_rar_result &result){ +int PDSCH_Decoder::decode_rar(DL_Sniffer_rar_result &result) +{ uint32_t tti = sfn * 10 + sf_idx; int ret = SRSRAN_ERROR; - for (auto decoding_mem:(*ran_dl_collection)){ + for (auto decoding_mem : (*ran_dl_collection)) + { /* set up variable*/ int harq_ret[SRSRAN_MAX_CODEWORDS] = {DL_SNIFFER_NEW_TX, DL_SNIFFER_NEW_TX}; srsran_dci_dl_t *cur_ran_dci_dl = decoding_mem.ran_dci_dl.get(); uint32_t cur_rnti = decoding_mem.rnti; srsran_dci_format_t cur_format = decoding_mem.format; std::string RNTI_name; - if (cur_rnti > SRSRAN_RARNTI_START && cur_rnti < SRSRAN_RARNTI_END) { - //std::cout << "Decoding RNTI: " << rnti << std::endl; - //mcs + if (cur_rnti > SRSRAN_RARNTI_START && cur_rnti < SRSRAN_RARNTI_END) + { + // std::cout << "Decoding RNTI: " << rnti << std::endl; + // mcs srsran_pdsch_grant_t *cur_grant; cur_grant = decoding_mem.ran_pdsch_grant.get(); - for (uint32_t tb = 0; tb < SRSRAN_MAX_CODEWORDS; tb++) { - pdsch_res[tb].crc = false; + for (uint32_t tb = 0; tb < SRSRAN_MAX_CODEWORDS; tb++) + { + pdsch_res[tb].crc = false; } bool tb_en[SRSRAN_MAX_CODEWORDS]{cur_grant->tb[0].enabled, cur_grant->tb[1].enabled}; int mimo_ret = SRSRAN_SUCCESS; bool unknown_mcs; - /*rar uses 64QAM table*/ + /*rar uses 64QAM table*/ int decode_ret = run_rar_decode(cur_format, cur_ran_dci_dl, cur_grant, cur_rnti, result); - if (decode_ret == SRSRAN_SUCCESS){ - ret = SRSRAN_SUCCESS; - } + if (decode_ret == SRSRAN_SUCCESS) + { + ret = SRSRAN_SUCCESS; + } } - } //end of decoding loop + } // end of decoding loop return ret; -} +} -void PDSCH_Decoder::unpack_rar_response_dl_mode(uint8_t *ptr, int result_length){ +void PDSCH_Decoder::unpack_rar_response_dl_mode(uint8_t *ptr, int result_length) +{ srsran::rar_pdu rar_pdu_msg; rar_pdu_msg.init_rx(result_length); uint16_t t_crnti = 0; @@ -635,145 +739,173 @@ void PDSCH_Decoder::unpack_rar_response_dl_mode(uint8_t *ptr, int result_length) } } -void print_dl_grant_dci(srsran_dci_dl_t &dl_dci, uint16_t tti, uint16_t rnti){ - std::cout << "[DCI] SF: " << tti/10 << ":" << tti%10 << "-RNTI: " << rnti << " -Format: " << dl_dci.format << " -MCS: " << dl_dci.tb[0].mcs_idx<< \ - " -RV: " << dl_dci.tb[0].rv << std::endl; +void print_dl_grant_dci(srsran_dci_dl_t &dl_dci, uint16_t tti, uint16_t rnti) +{ + std::cout << "[DCI] SF: " << tti / 10 << ":" << tti % 10 << "-RNTI: " << rnti << " -Format: " << dl_dci.format << " -MCS: " << dl_dci.tb[0].mcs_idx << " -RV: " << dl_dci.tb[0].rv << std::endl; } -int PDSCH_Decoder::decode_dl_mode(){ - uint32_t tti = sfn * 10 + sf_idx; - // printf("[%d] SF: %d-%d Nof_DCI = %d \n", idx, sfn, sf_idx, ran_dl_collection->size()); - for (auto decoding_mem:(*ran_dl_collection)){ - if (decoding_mem.ran_pdsch_grant->tb[0].tbs > 0 && decoding_mem.ran_dci_dl->rnti > 0 && //only decode if packet length > 0 and rnti != 0, - !(nof_antenna == 1 && (decoding_mem.ran_pdsch_grant->nof_tb == 2 || decoding_mem.ran_pdsch_grant_256->nof_tb == 2))){ //only decode DCI with 2 TB if having 2 RX antennas, - if (decoding_mem.ran_dci_dl->tb[0].rv < 0){ +int PDSCH_Decoder::decode_dl_mode() +{ + uint32_t tti = sfn * 10 + sf_idx; + // printf("[%d] SF: %d-%d Nof_DCI = %d \n", idx, sfn, sf_idx, ran_dl_collection->size()); + for (auto decoding_mem : (*ran_dl_collection)) + { + if ((decoding_mem.ran_pdsch_grant->tb[0].tbs > 0 && decoding_mem.ran_dci_dl->rnti > 0 && // only decode if packet length > 0 and rnti != 0, + !(nof_antenna == 1 && (decoding_mem.ran_pdsch_grant->nof_tb == 2 || decoding_mem.ran_pdsch_grant_256->nof_tb == 2))) || // only decode DCI with 2 TB if having 2 RX antennas, + (decoding_mem.rnti == 65534)) // always decode DCI with paging RNTI + { + if (decoding_mem.ran_dci_dl->tb[0].rv < 0) + { // print_dl_grant_dci(*decoding_mem.ran_dci_dl.get(), tti, decoding_mem.rnti); - if (decoding_mem.rnti == 65535){ // on some basestations, SIB1 has DCI 1C with rv index = -1, change it to 0 to decode? + if (decoding_mem.rnti == 65535) + { // on some base stations, SIB1 has DCI 1C with rv index = -1, change it to 0 to decode? decoding_mem.ran_pdsch_grant->tb[0].rv = 0; } } - /* set up variable*/ - int harq_ret[SRSRAN_MAX_CODEWORDS] = {DL_SNIFFER_NEW_TX, DL_SNIFFER_NEW_TX}; - srsran_dci_dl_t *cur_ran_dci_dl = decoding_mem.ran_dci_dl.get(); - uint32_t cur_rnti = decoding_mem.rnti; - srsran_dci_format_t cur_format = decoding_mem.format; - std::string RNTI_name = rnti_name(cur_rnti); - - //mcs - srsran_pdsch_grant_t *cur_grant; - srsran_pdsch_grant_t *cur_grant256; - if (decoding_mem.mcs_table == DL_SNIFFER_64QAM_TABLE) - { - cur_grant = decoding_mem.ran_pdsch_grant.get(); - } else if (decoding_mem.mcs_table == DL_SNIFFER_256QAM_TABLE){ - cur_grant = decoding_mem.ran_pdsch_grant_256.get(); - } else { - cur_grant = decoding_mem.ran_pdsch_grant.get(); - cur_grant256 = decoding_mem.ran_pdsch_grant_256.get(); - } - for (uint32_t tb = 0; tb < SRSRAN_MAX_CODEWORDS; tb++) { - pdsch_res[tb].crc = false; - } - ltesniffer_ue_spec_config_t ue_config = mcs_tracking->get_ue_config_rnti(cur_rnti); //find p_a from database - pdsch_cfg->p_a = ue_config.p_a; //update p_a from database - bool tb_en[SRSRAN_MAX_CODEWORDS]{cur_grant->tb[0].enabled, cur_grant->tb[1].enabled}; - int mimo_ret = SRSRAN_SUCCESS; - bool unknown_mcs; - - if ((decoding_mem.mcs_table == DL_SNIFFER_64QAM_TABLE)||(decoding_mem.mcs_table == DL_SNIFFER_256QAM_TABLE)) - { - //prepare decoding - unknown_mcs = false; - mimo_ret = dl_sniffer_config_mimo(&falcon_ue_dl->q->cell, cur_format, cur_ran_dci_dl, cur_grant); - if (mimo_ret == SRSRAN_SUCCESS){ - /* config pdsch_cfg for decoding pdsch*/ - pdsch_cfg->grant = *cur_grant; //check again here - pdsch_cfg->rnti = cur_rnti; - - for (int i = 0; i < SRSRAN_MAX_CODEWORDS; i++) { - if (pdsch_cfg->grant.tb[i].enabled) { - dl_sniffer_harq_grant_t cur_harq_grant = {}; - cur_harq_grant.last_decoded = false; - cur_harq_grant.ndi = cur_ran_dci_dl->tb[i].ndi; - cur_harq_grant.ndi_present = true; - cur_harq_grant.rv = cur_ran_dci_dl->tb[i].rv; - cur_harq_grant.tbs = cur_grant->tb[i].tbs; - cur_harq_grant.is_first_transmission = false; - - if (harq_mode && RNTI_name == "C_RNTI"){ - /*Check is reTX or new TX*/ - harq_ret[i] = harq->is_retransmission(cur_rnti, cur_ran_dci_dl->pid, i, cur_harq_grant, sfn, sf_idx); - - switch (harq_ret[i]){ - case DL_SNIFFER_NEW_TX: - pdsch_cfg->softbuffers.rx[i] = harq->getHARQBuffer(cur_rnti, cur_ran_dci_dl->pid, i); - srsran_softbuffer_rx_reset_tbs(pdsch_cfg->softbuffers.rx[i], (uint32_t)pdsch_cfg->grant.tb[i].tbs); - break; - case DL_SNIFFER_HARQ_FULL_BUFFER: - pdsch_cfg->softbuffers.rx[i] = buffer[i]; - srsran_softbuffer_rx_reset_tbs(pdsch_cfg->softbuffers.rx[i], (uint32_t)pdsch_cfg->grant.tb[i].tbs); - break; - case DL_SNIFFER_DECODED: - pdsch_cfg->grant.tb[i].enabled = false; - break; - case DL_SNIFFER_RE_TX: - pdsch_cfg->softbuffers.rx[i] = harq->getHARQBuffer(cur_rnti, cur_ran_dci_dl->pid, i); - break; - case DL_SNIFFER_HARQ_BUSY: - pdsch_cfg->softbuffers.rx[i] = buffer[i]; - srsran_softbuffer_rx_reset_tbs(pdsch_cfg->softbuffers.rx[i], (uint32_t)pdsch_cfg->grant.tb[i].tbs); - break; - default: - pdsch_cfg->softbuffers.rx[i] = buffer[i]; - srsran_softbuffer_rx_reset_tbs(pdsch_cfg->softbuffers.rx[i], (uint32_t)pdsch_cfg->grant.tb[i].tbs); - break; - } - } else { - pdsch_cfg->softbuffers.rx[i] = buffer[i]; - srsran_softbuffer_rx_reset_tbs(pdsch_cfg->softbuffers.rx[i], (uint32_t)pdsch_cfg->grant.tb[i].tbs); - } - } - } - - //main function to decode - if (pdsch_cfg->grant.tb[0].enabled||pdsch_cfg->grant.tb[1].enabled){ - if (srsran_ue_dl_decode_pdsch(falcon_ue_dl->q, dl_sf, pdsch_cfg, pdsch_res)) { - ERROR("ERROR: Decoding PDSCH"); - } - } - - /* Update HARQ buffer*/ - for (int i = 0; i < SRSRAN_MAX_CODEWORDS; i++){ - if (pdsch_cfg->grant.tb[i].enabled && harq_mode){ - dl_sniffer_harq_grant_t cur_harq_grant = {}; - cur_harq_grant.last_decoded = pdsch_res[i].crc; - cur_harq_grant.ndi = cur_ran_dci_dl->tb[i].ndi; - cur_harq_grant.ndi_present = true; - cur_harq_grant.rv = cur_ran_dci_dl->tb[i].rv; - cur_harq_grant.tbs = cur_grant->tb[i].tbs; - cur_harq_grant.is_first_transmission = false; - if ((RNTI_name == "C_RNTI")&&(harq_ret[i] == DL_SNIFFER_NEW_TX||harq_ret[i] == DL_SNIFFER_RE_TX)&&harq_mode){ - harq->updateHARQRNTI(cur_rnti, cur_ran_dci_dl->pid, i, sfn, sf_idx, cur_harq_grant); - } - } - } - - //write pcap file and unpack RAR, RRC Connection Setup - for (uint32_t tb = 0; tb < SRSRAN_MAX_CODEWORDS; tb++) { - int nof_tb = 1; - if (cur_grant->tb[1].enabled == true){ - nof_tb = 2; - } - int result_length = pdsch_cfg->grant.tb[tb].tbs/8; - std::string dci_fm = dci_format(cur_format); - std::string mod = mod_sche(cur_grant->tb[tb].mod); - std::string table_name = decoding_mem.mcs_table?("256"):("64"); - if (pdsch_res[tb].crc && result_length > 0){ - write_pcap(RNTI_name, pdsch_res[tb].payload, result_length, cur_rnti, tti, 0); - if (RNTI_name == "RA_RNTI"){ + /* set up variable*/ + int harq_ret[SRSRAN_MAX_CODEWORDS] = {DL_SNIFFER_NEW_TX, DL_SNIFFER_NEW_TX}; + srsran_dci_dl_t *cur_ran_dci_dl = decoding_mem.ran_dci_dl.get(); + uint32_t cur_rnti = decoding_mem.rnti; + srsran_dci_format_t cur_format = decoding_mem.format; + std::string RNTI_name = rnti_name(cur_rnti); + + // mcs + srsran_pdsch_grant_t *cur_grant; + srsran_pdsch_grant_t *cur_grant256; + if (decoding_mem.mcs_table == DL_SNIFFER_64QAM_TABLE) + { + cur_grant = decoding_mem.ran_pdsch_grant.get(); + } + else if (decoding_mem.mcs_table == DL_SNIFFER_256QAM_TABLE) + { + cur_grant = decoding_mem.ran_pdsch_grant_256.get(); + } + else + { + cur_grant = decoding_mem.ran_pdsch_grant.get(); + cur_grant256 = decoding_mem.ran_pdsch_grant_256.get(); + } + for (uint32_t tb = 0; tb < SRSRAN_MAX_CODEWORDS; tb++) + { + pdsch_res[tb].crc = false; + } + ltesniffer_ue_spec_config_t ue_config = mcs_tracking->get_ue_config_rnti(cur_rnti); // find p_a from database + pdsch_cfg->p_a = ue_config.p_a; // update p_a from database + bool tb_en[SRSRAN_MAX_CODEWORDS]{cur_grant->tb[0].enabled, cur_grant->tb[1].enabled}; + int mimo_ret = SRSRAN_SUCCESS; + bool unknown_mcs; + + if ((decoding_mem.mcs_table == DL_SNIFFER_64QAM_TABLE) || (decoding_mem.mcs_table == DL_SNIFFER_256QAM_TABLE)) + { + // prepare decoding + unknown_mcs = false; + mimo_ret = dl_sniffer_config_mimo(&falcon_ue_dl->q->cell, cur_format, cur_ran_dci_dl, cur_grant); + if (mimo_ret == SRSRAN_SUCCESS) + { + /* config pdsch_cfg for decoding pdsch*/ + pdsch_cfg->grant = *cur_grant; // check again here + pdsch_cfg->rnti = cur_rnti; + + for (int i = 0; i < SRSRAN_MAX_CODEWORDS; i++) + { + if (pdsch_cfg->grant.tb[i].enabled) + { + dl_sniffer_harq_grant_t cur_harq_grant = {}; + cur_harq_grant.last_decoded = false; + cur_harq_grant.ndi = cur_ran_dci_dl->tb[i].ndi; + cur_harq_grant.ndi_present = true; + cur_harq_grant.rv = cur_ran_dci_dl->tb[i].rv; + cur_harq_grant.tbs = cur_grant->tb[i].tbs; + cur_harq_grant.is_first_transmission = false; + + if (harq_mode && RNTI_name == "C_RNTI") + { + /*Check is reTX or new TX*/ + harq_ret[i] = harq->is_retransmission(cur_rnti, cur_ran_dci_dl->pid, i, cur_harq_grant, sfn, sf_idx); + + switch (harq_ret[i]) + { + case DL_SNIFFER_NEW_TX: + pdsch_cfg->softbuffers.rx[i] = harq->getHARQBuffer(cur_rnti, cur_ran_dci_dl->pid, i); + srsran_softbuffer_rx_reset_tbs(pdsch_cfg->softbuffers.rx[i], (uint32_t)pdsch_cfg->grant.tb[i].tbs); + break; + case DL_SNIFFER_HARQ_FULL_BUFFER: + pdsch_cfg->softbuffers.rx[i] = buffer[i]; + srsran_softbuffer_rx_reset_tbs(pdsch_cfg->softbuffers.rx[i], (uint32_t)pdsch_cfg->grant.tb[i].tbs); + break; + case DL_SNIFFER_DECODED: + pdsch_cfg->grant.tb[i].enabled = false; + break; + case DL_SNIFFER_RE_TX: + pdsch_cfg->softbuffers.rx[i] = harq->getHARQBuffer(cur_rnti, cur_ran_dci_dl->pid, i); + break; + case DL_SNIFFER_HARQ_BUSY: + pdsch_cfg->softbuffers.rx[i] = buffer[i]; + srsran_softbuffer_rx_reset_tbs(pdsch_cfg->softbuffers.rx[i], (uint32_t)pdsch_cfg->grant.tb[i].tbs); + break; + default: + pdsch_cfg->softbuffers.rx[i] = buffer[i]; + srsran_softbuffer_rx_reset_tbs(pdsch_cfg->softbuffers.rx[i], (uint32_t)pdsch_cfg->grant.tb[i].tbs); + break; + } + } + else + { + pdsch_cfg->softbuffers.rx[i] = buffer[i]; + srsran_softbuffer_rx_reset_tbs(pdsch_cfg->softbuffers.rx[i], (uint32_t)pdsch_cfg->grant.tb[i].tbs); + } + } + } + + // main function to decode + if (pdsch_cfg->grant.tb[0].enabled || pdsch_cfg->grant.tb[1].enabled) + { + if (srsran_ue_dl_decode_pdsch(falcon_ue_dl->q, dl_sf, pdsch_cfg, pdsch_res)) + { + ERROR("ERROR: Decoding PDSCH"); + } + } + + /* Update HARQ buffer*/ + for (int i = 0; i < SRSRAN_MAX_CODEWORDS; i++) + { + if (pdsch_cfg->grant.tb[i].enabled && harq_mode) + { + dl_sniffer_harq_grant_t cur_harq_grant = {}; + cur_harq_grant.last_decoded = pdsch_res[i].crc; + cur_harq_grant.ndi = cur_ran_dci_dl->tb[i].ndi; + cur_harq_grant.ndi_present = true; + cur_harq_grant.rv = cur_ran_dci_dl->tb[i].rv; + cur_harq_grant.tbs = cur_grant->tb[i].tbs; + cur_harq_grant.is_first_transmission = false; + if ((RNTI_name == "C_RNTI") && (harq_ret[i] == DL_SNIFFER_NEW_TX || harq_ret[i] == DL_SNIFFER_RE_TX) && harq_mode) + { + harq->updateHARQRNTI(cur_rnti, cur_ran_dci_dl->pid, i, sfn, sf_idx, cur_harq_grant); + } + } + } + + // write pcap file and unpack RAR, RRC Connection Setup + for (uint32_t tb = 0; tb < SRSRAN_MAX_CODEWORDS; tb++) + { + int nof_tb = 1; + if (cur_grant->tb[1].enabled == true) + { + nof_tb = 2; + } + int result_length = pdsch_cfg->grant.tb[tb].tbs / 8; + std::string dci_fm = dci_format(cur_format); + std::string mod = mod_sche(cur_grant->tb[tb].mod); + std::string table_name = decoding_mem.mcs_table ? ("256") : ("64"); + if (pdsch_res[tb].crc && result_length > 0) + { + write_pcap(RNTI_name, pdsch_res[tb].payload, result_length, cur_rnti, tti, 0); + if (RNTI_name == "RA_RNTI") + { unpack_rar_response_dl_mode(pdsch_res[tb].payload, result_length); } - if (RNTI_name == "C_RNTI"){ + if (RNTI_name == "C_RNTI") + { /*Unpack PDSCH msg to receive SDU, SDU and then decode RRC Connection Setup*/ srsran::sch_pdu pdu(20, srslog::fetch_basic_logger("MAC")); pdu.init_rx(result_length, false); @@ -783,14 +915,17 @@ int PDSCH_Decoder::decode_dl_mode(){ sch_subh sub_header[4]; while (pdu.next()) { - if(pdu.get()->is_sdu()){ + if (pdu.get()->is_sdu()) + { int payload_length = pdu.get()->get_payload_size(); - uint8_t* sdu_ptr = pdu.get()->get_sdu_ptr(); + uint8_t *sdu_ptr = pdu.get()->get_sdu_ptr(); /* Decode RRC Connection Setup to obtain UE Specific Configuration*/ ltesniffer_ue_spec_config_t ue_config = {}; int rrc_ret = decode_rrc_connection_setup(sdu_ptr, payload_length, &ue_config); - if (rrc_ret == SRSRAN_SUCCESS){ //success means RRC Connection Setup - if (!mcs_tracking->check_default_config()){ + if (rrc_ret == SRSRAN_SUCCESS) + { // success means RRC Connection Setup + if (!mcs_tracking->check_default_config()) + { mcs_tracking->update_default_ue_config(ue_config); mcs_tracking->set_has_default_config(); } @@ -799,51 +934,65 @@ int PDSCH_Decoder::decode_dl_mode(){ } } } - } - if (cur_rnti != 65535 && cur_grant->tb[tb].enabled && (target_rnti == 0 || cur_rnti == target_rnti) && en_debug){ - print_debug_dl(table_name , tti, decoding_mem.rnti, dci_fm, mod, decoding_mem.ran_dci_dl->tb[0].mcs_idx, harq_ret[tb], - nof_tb, result_length, pdsch_res[tb].crc, &falcon_ue_dl->q->chest_res); - } - } - } else { - //nothing - } - } else{ // If dont know MCS table, try both tables - /*Try 64QAM table first*/ - unknown_mcs = true; - mimo_ret = dl_sniffer_config_mimo(&falcon_ue_dl->q->cell, cur_format, cur_ran_dci_dl, cur_grant); - if (mimo_ret == SRSRAN_SUCCESS){ - /* config pdsch_cfg for decoding pdsch*/ - pdsch_cfg->grant = *cur_grant; //check again here - pdsch_cfg->rnti = cur_rnti; - - for (int i = 0; i < SRSRAN_MAX_CODEWORDS; i++) { - if (pdsch_cfg->grant.tb[i].enabled) { - pdsch_cfg->softbuffers.rx[i] = buffer[i]; - srsran_softbuffer_rx_reset_tbs(pdsch_cfg->softbuffers.rx[i], (uint32_t)pdsch_cfg->grant.tb[i].tbs); - } - } - - /*main function to decode */ - if (srsran_ue_dl_decode_pdsch(falcon_ue_dl->q, dl_sf, pdsch_cfg, pdsch_res)) { - ERROR("ERROR: Decoding PDSCH"); - } - - //write pcap file - for (uint32_t tb = 0; tb < SRSRAN_MAX_CODEWORDS; tb++) { - int nof_tb = 1; - if (cur_grant->tb[1].enabled == true){ - nof_tb = 2; - } - int result_length = pdsch_cfg->grant.tb[tb].tbs/8; - std::string dci_fm = dci_format(cur_format); - std::string mod = mod_sche(cur_grant->tb[tb].mod); - if (pdsch_res[tb].crc && result_length > 0){ - write_pcap(RNTI_name, pdsch_res[tb].payload, result_length, cur_rnti, tti, 0); - if (RNTI_name == "RA_RNTI"){ + } + if (cur_rnti != 65535 && cur_grant->tb[tb].enabled && (target_rnti == 0 || cur_rnti == target_rnti) && en_debug) + { + print_debug_dl(table_name, tti, decoding_mem.rnti, dci_fm, mod, decoding_mem.ran_dci_dl->tb[0].mcs_idx, harq_ret[tb], + nof_tb, result_length, pdsch_res[tb].crc, &falcon_ue_dl->q->chest_res); + } + } + } + else + { + // nothing + } + } + else + { // If dont know MCS table, try both tables + /*Try 64QAM table first*/ + unknown_mcs = true; + mimo_ret = dl_sniffer_config_mimo(&falcon_ue_dl->q->cell, cur_format, cur_ran_dci_dl, cur_grant); + if (mimo_ret == SRSRAN_SUCCESS) + { + /* config pdsch_cfg for decoding pdsch*/ + pdsch_cfg->grant = *cur_grant; // check again here + pdsch_cfg->rnti = cur_rnti; + + for (int i = 0; i < SRSRAN_MAX_CODEWORDS; i++) + { + if (pdsch_cfg->grant.tb[i].enabled) + { + pdsch_cfg->softbuffers.rx[i] = buffer[i]; + srsran_softbuffer_rx_reset_tbs(pdsch_cfg->softbuffers.rx[i], (uint32_t)pdsch_cfg->grant.tb[i].tbs); + } + } + + /*main function to decode */ + if (srsran_ue_dl_decode_pdsch(falcon_ue_dl->q, dl_sf, pdsch_cfg, pdsch_res)) + { + ERROR("ERROR: Decoding PDSCH"); + } + + // write pcap file + for (uint32_t tb = 0; tb < SRSRAN_MAX_CODEWORDS; tb++) + { + int nof_tb = 1; + if (cur_grant->tb[1].enabled == true) + { + nof_tb = 2; + } + int result_length = pdsch_cfg->grant.tb[tb].tbs / 8; + std::string dci_fm = dci_format(cur_format); + std::string mod = mod_sche(cur_grant->tb[tb].mod); + if (pdsch_res[tb].crc && result_length > 0) + { + write_pcap(RNTI_name, pdsch_res[tb].payload, result_length, cur_rnti, tti, 0); + if (RNTI_name == "RA_RNTI") + { unpack_rar_response_dl_mode(pdsch_res[tb].payload, result_length); } - if (RNTI_name == "C_RNTI"){ + if (RNTI_name == "C_RNTI") + { /*Unpack PDSCH msg to receive SDU, SDU and then decode RRC Connection Setup*/ srsran::sch_pdu pdu(20, srslog::fetch_basic_logger("MAC")); pdu.init_rx(result_length, false); @@ -853,14 +1002,17 @@ int PDSCH_Decoder::decode_dl_mode(){ sch_subh sub_header[4]; while (pdu.next()) { - if(pdu.get()->is_sdu()){ + if (pdu.get()->is_sdu()) + { int payload_length = pdu.get()->get_payload_size(); - uint8_t* sdu_ptr = pdu.get()->get_sdu_ptr(); + uint8_t *sdu_ptr = pdu.get()->get_sdu_ptr(); /* Decode RRC Connection Setup to obtain UE Specific Configuration*/ ltesniffer_ue_spec_config_t ue_config = {}; int rrc_ret = decode_rrc_connection_setup(sdu_ptr, payload_length, &ue_config); - if (rrc_ret == SRSRAN_SUCCESS){ //success means RRC Connection Setup - if (!mcs_tracking->check_default_config()){ + if (rrc_ret == SRSRAN_SUCCESS) + { // success means RRC Connection Setup + if (!mcs_tracking->check_default_config()) + { mcs_tracking->update_default_ue_config(ue_config); mcs_tracking->set_has_default_config(); } @@ -869,281 +1021,319 @@ int PDSCH_Decoder::decode_dl_mode(){ } } } - //update mcs table to database only when mcs_idx > 0 (0 index is overlap in both tables): - if (cur_ran_dci_dl->tb[tb].mcs_idx > 0 &&cur_ran_dci_dl->tb[tb].mcs_idx < 29 && decoding_mem.format > SRSRAN_DCI_FORMAT1A && result_length > 0){ - mcs_tracking->update_RNTI_dl(cur_rnti, DL_SNIFFER_64QAM_TABLE); - } - } - if (cur_rnti != 65535 && cur_grant->tb[tb].enabled && (target_rnti == 0 || cur_rnti == target_rnti) && en_debug){ - print_debug_dl("Unkown64" ,tti, decoding_mem.rnti, dci_fm, mod, decoding_mem.ran_dci_dl->tb[0].mcs_idx, harq_ret[tb], - nof_tb, result_length, pdsch_res[tb].crc, &falcon_ue_dl->q->chest_res); - } - } - } else{ - //nothing - } - - // if 64QAM table failed, try 256QAM table: - if (!pdsch_res[0].crc && !pdsch_res[1].crc && mimo_ret == SRSRAN_SUCCESS){ - pdsch_cfg->use_tbs_index_alt = true; - //prepare decoding - mimo_ret = dl_sniffer_config_mimo(&falcon_ue_dl->q->cell, cur_format, cur_ran_dci_dl, cur_grant256); - if (mimo_ret == SRSRAN_SUCCESS){ - /* config pdsch_cfg for decoding pdsch*/ - pdsch_cfg->grant = *cur_grant256; //check again here - pdsch_cfg->rnti = cur_rnti; - - for (int i = 0; i < SRSRAN_MAX_CODEWORDS; i++) { - if (pdsch_cfg->grant.tb[i].enabled) { - pdsch_cfg->softbuffers.rx[i] = buffer[i]; - srsran_softbuffer_rx_reset_tbs(pdsch_cfg->softbuffers.rx[i], (uint32_t)pdsch_cfg->grant.tb[i].tbs); - } - } - - //main function to decode - if (srsran_ue_dl_decode_pdsch(falcon_ue_dl->q, dl_sf, pdsch_cfg, pdsch_res)) { - ERROR("ERROR: Decoding PDSCH"); - } - //write pcap file - for (uint32_t tb = 0; tb < SRSRAN_MAX_CODEWORDS; tb++) { - int nof_tb = 1; - if (cur_grant256->tb[1].enabled == true){ - nof_tb = 2; - } - int result_length = pdsch_cfg->grant.tb[tb].tbs/8; - std::string dci_fm = dci_format(cur_format); - std::string mod = mod_sche(cur_grant256->tb[tb].mod); - if (pdsch_res[tb].crc && result_length > 0){ - write_pcap(RNTI_name, pdsch_res[tb].payload, result_length, cur_rnti, tti, 0); - //update mcs table to database when mcs < 28 because 256QAM table: - //cur_ran_dci_dl->tb[tb].mcs_idx > 0 && cur_ran_dci_dl->tb[tb].mcs_idx < 28 && decoding_mem.format > SRSRAN_DCI_FORMAT1A && result_length > 0 - if (cur_ran_dci_dl->tb[tb].mcs_idx > 0 && cur_ran_dci_dl->tb[tb].mcs_idx < 28 && decoding_mem.format > SRSRAN_DCI_FORMAT1A && result_length > 0){ - mcs_tracking->update_RNTI_dl(cur_rnti, DL_SNIFFER_256QAM_TABLE); - } - } - if (cur_rnti != 65535 && cur_grant256->tb[tb].enabled && (target_rnti == 0 || cur_rnti == target_rnti) && en_debug){ - print_debug_dl( "Unkown256" ,tti, decoding_mem.rnti, dci_fm, mod, decoding_mem.ran_dci_dl->tb[0].mcs_idx, harq_ret[tb], - nof_tb, result_length, pdsch_res[tb].crc, &falcon_ue_dl->q->chest_res); - } - } - } else { - // nothing - } - } - for (int j = 0; j < SRSRAN_MAX_CODEWORDS; j++){ - if (tb_en[j]){ - INFO("[PDSCH] Decoding Unknown table tb[%d]: RNTI: %d, format: %d, mcs_idx: %d -- pid: %d -- pinfo: %d -- sf: %d-%d --", - j, cur_rnti, decoding_mem.format, cur_grant->tb[j].mcs_idx, cur_ran_dci_dl->pid, cur_ran_dci_dl->pinfo, sfn, sf_idx); - if ((pdsch_res[j].crc)){ - INFO("\033[0;32m SUCCESS \n"); - INFO("\033[0m"); - } else{ - INFO("\033[0;31m FAILED \n"); - INFO("\033[0m"); - } - } - } - - } - bool success[SRSRAN_MAX_CODEWORDS]{pdsch_res[0].crc, pdsch_res[1].crc}; - - //update statistic - if (RNTI_name == "C_RNTI" && mcs_tracking_mode){ //T_Note: changed for debuging && mimo_ret == SRSRAN_SUCCESS||| && decoding_mem.format > SRSRAN_DCI_FORMAT1A - srsran_pdsch_grant_t *statistic_grant; - if (decoding_mem.mcs_table == DL_SNIFFER_64QAM_TABLE){ - statistic_grant = decoding_mem.ran_pdsch_grant.get(); - } else if (decoding_mem.mcs_table == DL_SNIFFER_256QAM_TABLE){ - statistic_grant = decoding_mem.ran_pdsch_grant_256.get(); - } else { - statistic_grant = decoding_mem.ran_pdsch_grant.get(); - } - mcs_tracking->update_statistic_dl(cur_rnti, tb_en, harq_ret, success, decoding_mem, mimo_ret, statistic_grant); - - } - bool wrong_detect = (mimo_ret == SRSRAN_SUCCESS)?true:false; - std::time_t cur_time = std::time(nullptr); - //mcs_tracking->write_dci_to_file(cur_time, tti/10, tti%10, cur_rnti, cur_format, wrong_detect); - } - - } //end of decoding loop - - return SRSRAN_SUCCESS; + // update mcs table to database only when mcs_idx > 0 (0 index is overlap in both tables): + if (cur_ran_dci_dl->tb[tb].mcs_idx > 0 && cur_ran_dci_dl->tb[tb].mcs_idx < 29 && decoding_mem.format > SRSRAN_DCI_FORMAT1A && result_length > 0) + { + mcs_tracking->update_RNTI_dl(cur_rnti, DL_SNIFFER_64QAM_TABLE); + } + } + if (cur_rnti != 65535 && cur_grant->tb[tb].enabled && (target_rnti == 0 || cur_rnti == target_rnti) && en_debug) + { + print_debug_dl("Unkown64", tti, decoding_mem.rnti, dci_fm, mod, decoding_mem.ran_dci_dl->tb[0].mcs_idx, harq_ret[tb], + nof_tb, result_length, pdsch_res[tb].crc, &falcon_ue_dl->q->chest_res); + } + } + } + else + { + // nothing + } + + // if 64QAM table failed, try 256QAM table: + if (!pdsch_res[0].crc && !pdsch_res[1].crc && mimo_ret == SRSRAN_SUCCESS) + { + pdsch_cfg->use_tbs_index_alt = true; + // prepare decoding + mimo_ret = dl_sniffer_config_mimo(&falcon_ue_dl->q->cell, cur_format, cur_ran_dci_dl, cur_grant256); + if (mimo_ret == SRSRAN_SUCCESS) + { + /* config pdsch_cfg for decoding pdsch*/ + pdsch_cfg->grant = *cur_grant256; // check again here + pdsch_cfg->rnti = cur_rnti; + + for (int i = 0; i < SRSRAN_MAX_CODEWORDS; i++) + { + if (pdsch_cfg->grant.tb[i].enabled) + { + pdsch_cfg->softbuffers.rx[i] = buffer[i]; + srsran_softbuffer_rx_reset_tbs(pdsch_cfg->softbuffers.rx[i], (uint32_t)pdsch_cfg->grant.tb[i].tbs); + } + } + + // main function to decode + if (srsran_ue_dl_decode_pdsch(falcon_ue_dl->q, dl_sf, pdsch_cfg, pdsch_res)) + { + ERROR("ERROR: Decoding PDSCH"); + } + // write pcap file + for (uint32_t tb = 0; tb < SRSRAN_MAX_CODEWORDS; tb++) + { + int nof_tb = 1; + if (cur_grant256->tb[1].enabled == true) + { + nof_tb = 2; + } + int result_length = pdsch_cfg->grant.tb[tb].tbs / 8; + std::string dci_fm = dci_format(cur_format); + std::string mod = mod_sche(cur_grant256->tb[tb].mod); + if (pdsch_res[tb].crc && result_length > 0) + { + write_pcap(RNTI_name, pdsch_res[tb].payload, result_length, cur_rnti, tti, 0); + // update mcs table to database when mcs < 28 because 256QAM table: + // cur_ran_dci_dl->tb[tb].mcs_idx > 0 && cur_ran_dci_dl->tb[tb].mcs_idx < 28 && decoding_mem.format > SRSRAN_DCI_FORMAT1A && result_length > 0 + if (cur_ran_dci_dl->tb[tb].mcs_idx > 0 && cur_ran_dci_dl->tb[tb].mcs_idx < 28 && decoding_mem.format > SRSRAN_DCI_FORMAT1A && result_length > 0) + { + mcs_tracking->update_RNTI_dl(cur_rnti, DL_SNIFFER_256QAM_TABLE); + } + } + if (cur_rnti != 65535 && cur_grant256->tb[tb].enabled && (target_rnti == 0 || cur_rnti == target_rnti) && en_debug) + { + print_debug_dl("Unkown256", tti, decoding_mem.rnti, dci_fm, mod, decoding_mem.ran_dci_dl->tb[0].mcs_idx, harq_ret[tb], + nof_tb, result_length, pdsch_res[tb].crc, &falcon_ue_dl->q->chest_res); + } + } + } + else + { + // nothing + } + } + for (int j = 0; j < SRSRAN_MAX_CODEWORDS; j++) + { + if (tb_en[j]) + { + INFO("[PDSCH] Decoding Unknown table tb[%d]: RNTI: %d, format: %d, mcs_idx: %d -- pid: %d -- pinfo: %d -- sf: %d-%d --", + j, cur_rnti, decoding_mem.format, cur_grant->tb[j].mcs_idx, cur_ran_dci_dl->pid, cur_ran_dci_dl->pinfo, sfn, sf_idx); + if ((pdsch_res[j].crc)) + { + INFO("\033[0;32m SUCCESS \n"); + INFO("\033[0m"); + } + else + { + INFO("\033[0;31m FAILED \n"); + INFO("\033[0m"); + } + } + } + } + bool success[SRSRAN_MAX_CODEWORDS]{pdsch_res[0].crc, pdsch_res[1].crc}; + + // update statistic + if (RNTI_name == "C_RNTI" && mcs_tracking_mode) + { // T_Note: changed for debuging && mimo_ret == SRSRAN_SUCCESS||| && decoding_mem.format > SRSRAN_DCI_FORMAT1A + srsran_pdsch_grant_t *statistic_grant; + if (decoding_mem.mcs_table == DL_SNIFFER_64QAM_TABLE) + { + statistic_grant = decoding_mem.ran_pdsch_grant.get(); + } + else if (decoding_mem.mcs_table == DL_SNIFFER_256QAM_TABLE) + { + statistic_grant = decoding_mem.ran_pdsch_grant_256.get(); + } + else + { + statistic_grant = decoding_mem.ran_pdsch_grant.get(); + } + mcs_tracking->update_statistic_dl(cur_rnti, tb_en, harq_ret, success, decoding_mem, mimo_ret, statistic_grant); + } + bool wrong_detect = (mimo_ret == SRSRAN_SUCCESS) ? true : false; + std::time_t cur_time = std::time(nullptr); + // mcs_tracking->write_dci_to_file(cur_time, tti/10, tti%10, cur_rnti, cur_format, wrong_detect); + } + + } // end of decoding loop + + return SRSRAN_SUCCESS; } -void PDSCH_Decoder::print_debug_dl( std::string name, - int tti, - uint16_t rnti, - std::string format, - std::string mod, - int mcs_idx, - int retx, - int nof_tb, - int length, - bool result, - srsran_chest_dl_res_t* ce_res) +void PDSCH_Decoder::print_debug_dl(std::string name, + int tti, + uint16_t rnti, + std::string format, + std::string mod, + int mcs_idx, + int retx, + int nof_tb, + int length, + bool result, + srsran_chest_dl_res_t *ce_res) { - std::cout << std::left << std::setw(9) << name; - std::cout << "SF:" << std::left << std::setw(4) << tti/10 << "-" << tti%10; - // std::cout << "[" << std::left << std::setw(2) << idx << "]"; - std::cout << GREEN << " -- RNTI: " << std::left << std::setw(5) << rnti << RESET; - std::cout << WHITE << " -- DCI: " << std::left << std::setw(4) << format << RESET; - std::cout << YELLOW << " -- Mod: " << std::left << std::setw(6) << mod << RESET; - std::cout << " -- MCS: " << std::left << std::setw(3) << mcs_idx; - // std::string re_tx = retx?(" -- reTX"):(" -- NewTX"); - // std::cout << RED << std::left << std::setw(9) << re_tx << RESET; - std::cout << CYAN << " -- nof_TB: " << std::left << pdsch_cfg->grant.nof_tb << RESET; - std::cout << BLUE << " -- Byte: " << std::left << std::setw(5) << length << RESET; - // std::cout << std::setprecision(2) << GREEN << " -- rsrp: " << ce_res->rsrp_dbm << " --rsrq: " \ + std::cout << std::left << std::setw(9) << name; + std::cout << "SF:" << std::left << std::setw(4) << tti / 10 << "-" << tti % 10; + // std::cout << "[" << std::left << std::setw(2) << idx << "]"; + std::cout << GREEN << " -- RNTI: " << std::left << std::setw(5) << rnti << RESET; + std::cout << WHITE << " -- DCI: " << std::left << std::setw(4) << format << RESET; + std::cout << YELLOW << " -- Mod: " << std::left << std::setw(6) << mod << RESET; + std::cout << " -- MCS: " << std::left << std::setw(3) << mcs_idx; + // std::string re_tx = retx?(" -- reTX"):(" -- NewTX"); + // std::cout << RED << std::left << std::setw(9) << re_tx << RESET; + std::cout << CYAN << " -- nof_TB: " << std::left << pdsch_cfg->grant.nof_tb << RESET; + std::cout << BLUE << " -- Byte: " << std::left << std::setw(5) << length << RESET; + // std::cout << std::setprecision(2) << GREEN << " -- rsrp: " << ce_res->rsrp_dbm << " --rsrq: " \ // << ce_res->rsrq_db << " --SNR: " << ce_res->snr_db << " --CFO: " << ce_res->cfo << RESET; - std::cout << " -- Antenna SNR: " << std::left << std::setw(4) << ce_res->snr_ant_port_db[0][0] \ - << "|" << std::setw(4) << ce_res->snr_ant_port_db[1][1] << RESET; - std::cout << " -- SNR: " << std::left << std::setprecision(3) << std::setw(5) << ce_res->snr_db << RESET; - std::cout << RESET << " -- Result: "; - if (result){ - std::cout << std::left << std::setw(8) << GREEN << "SUCCESS"; - } else{ - std::cout << std::left << std::setw(8) << RED << "FAILED"; - } - std::cout << RESET<< std::endl; + std::cout << " -- Antenna SNR: " << std::left << std::setw(4) << ce_res->snr_ant_port_db[0][0] + << "|" << std::setw(4) << ce_res->snr_ant_port_db[1][1] << RESET; + std::cout << " -- SNR: " << std::left << std::setprecision(3) << std::setw(5) << ce_res->snr_db << RESET; + std::cout << RESET << " -- Result: "; + if (result) + { + std::cout << std::left << std::setw(8) << GREEN << "SUCCESS"; + } + else + { + std::cout << std::left << std::setw(8) << RED << "FAILED"; + } + std::cout << RESET << std::endl; } std::string PDSCH_Decoder::dci_format(int format) { std::string ret = "UNKNOWN"; - switch (format) - { - case 0: - ret = "0"; - break; - case 1: - ret = "1"; - break; - case 2: - ret = "1A"; - break; - case 3: - ret = "1B"; - break; - case 4: - ret = "1C"; - break; - case 5: - ret = "1D"; - break; - case 6: - ret = "2"; - break; - case 7: - ret = "2A"; - break; - case 8: - ret = "2B"; - break; - default: - ret = "UNKNOWN"; - break; - } + switch (format) + { + case 0: + ret = "0"; + break; + case 1: + ret = "1"; + break; + case 2: + ret = "1A"; + break; + case 3: + ret = "1B"; + break; + case 4: + ret = "1C"; + break; + case 5: + ret = "1D"; + break; + case 6: + ret = "2"; + break; + case 7: + ret = "2A"; + break; + case 8: + ret = "2B"; + break; + default: + ret = "UNKNOWN"; + break; + } return ret; } std::string PDSCH_Decoder::mod_sche(int sche) { std::string ret = "UNKNOWN"; - switch (sche) - { - case 0: - ret = "BPSK"; - break; - case 1: - ret = "QPSK"; - break; - case 2: - ret = "16QAM"; - break; - case 3: - ret = "64QAM"; - break; - case 4: - ret = "256QAM"; - break; - default: - ret = "UNKNOWN"; - break; - } + switch (sche) + { + case 0: + ret = "BPSK"; + break; + case 1: + ret = "QPSK"; + break; + case 2: + ret = "16QAM"; + break; + case 3: + ret = "64QAM"; + break; + case 4: + ret = "256QAM"; + break; + default: + ret = "UNKNOWN"; + break; + } return ret; } -std::string PDSCH_Decoder::rnti_name(uint16_t rnti){ +std::string PDSCH_Decoder::rnti_name(uint16_t rnti) +{ std::string ret = ""; - if (rnti == SRSRAN_SIRNTI) { - ret = "SI_RNTI"; - }else if (rnti == SRSRAN_PRNTI) { - ret = "P_RNTI"; - }else if ((rnti > SRSRAN_RARNTI_START) && (rnti < SRSRAN_RARNTI_END)) { - ret = "RA_RNTI"; - }else { - ret = "C_RNTI" ; - } + if (rnti == SRSRAN_SIRNTI) + { + ret = "SI_RNTI"; + } + else if (rnti == SRSRAN_PRNTI) + { + ret = "P_RNTI"; + } + else if ((rnti > SRSRAN_RARNTI_START) && (rnti < SRSRAN_RARNTI_END)) + { + ret = "RA_RNTI"; + } + else + { + ret = "C_RNTI"; + } return ret; } - -std::string convert_id_name_dl(int id){ +std::string convert_id_name_dl(int id) +{ std::string ret = "-"; - switch (id) - { - case 0: - ret = "RandomValue"; - break; - case 1: - ret = "TMSI"; - break; - case 2: - ret = "Contention Resolution"; - break; - case 3: - ret = "IMSI"; - break; - default: - ret = "-"; - break; - } + switch (id) + { + case 0: + ret = "RandomValue"; + break; + case 1: + ret = "TMSI"; + break; + case 2: + ret = "Contention Resolution"; + break; + case 3: + ret = "IMSI"; + break; + default: + ret = "-"; + break; + } return ret; } -std::string convert_msg_name_dl(int msg){ +std::string convert_msg_name_dl(int msg) +{ std::string ret = "-"; - switch (msg) - { - case 0: - ret = "RRC Connection Request"; - break; - case 1: - ret = "RRC Connection Setup"; - break; - case 2: - ret = "Attach Request"; - break; - case 3: - ret = "Identity Response"; - break; - case 4: - ret = "UECapability"; - break; + switch (msg) + { + case MSG_CON_REQ: + ret = "RRC Connection Request"; + break; + case MSG_CON_SET: + ret = "RRC Connection Setup"; + break; + case 2: + ret = "Attach Request"; + break; + case 3: + ret = "Identity Response"; + break; + case 4: + ret = "UECapability"; + break; case 5: ret = "Paging"; break; - default: - ret = "-"; - break; - } + default: + ret = "-"; + break; + } return ret; } -void PDSCH_Decoder::print_api_dl(uint32_t tti, uint16_t rnti, int id, std::string value, int msg){ - std::cout << std::left << std::setw(4) << tti/10 << "-" << std::left << std::setw(5) << tti%10; - std::string id_name = convert_id_name_dl(id); - std::cout << std::left << std::setw(26) << id_name; - std::cout << std::left << std::setw(17) << value; - std::cout << std::left << std::setw(11) << rnti; +void PDSCH_Decoder::print_api_dl(uint32_t tti, uint16_t rnti, int id, std::string value, int msg) +{ + std::cout << std::left << std::setw(4) << tti / 10 << "-" << std::left << std::setw(5) << tti % 10; + std::string id_name = convert_id_name_dl(id); + std::cout << std::left << std::setw(26) << id_name; + std::cout << std::left << std::setw(17) << value; + std::cout << std::left << std::setw(11) << rnti; std::string msg_name = convert_msg_name_dl(msg); - std::cout << std::left << std::setw(25) << msg_name; - std::cout << std::endl; + std::cout << std::left << std::setw(25) << msg_name; + std::cout << std::endl; } \ No newline at end of file diff --git a/src/src/MCSTracking.cc b/src/src/MCSTracking.cc index 97ede78..b36ebd2 100644 --- a/src/src/MCSTracking.cc +++ b/src/src/MCSTracking.cc @@ -1,22 +1,25 @@ #include "include/MCSTracking.h" - -MCSTracking::MCSTracking(int tracking_mode, uint16_t target_rnti, bool en_debug, int sniffer_mode, int api_mode, std::atomic &est_cfo): -target_rnti(target_rnti), -tracking_mode(tracking_mode), -en_debug(en_debug), -sniffer_mode(sniffer_mode), -api_mode(api_mode), -est_cfo(est_cfo) +MCSTracking::MCSTracking(int tracking_mode, + uint16_t target_rnti, + bool en_debug, + int sniffer_mode, + int api_mode, + std::atomic &est_cfo) : target_rnti(target_rnti), + tracking_mode(tracking_mode), + en_debug(en_debug), + sniffer_mode(sniffer_mode), + api_mode(api_mode), + est_cfo(est_cfo) { set_default_of_default_config(); csv_file.open(file_name); csv_file << "RNTI, table, total,success,percent,"; - for (int mcs_idx = 0; mcs_idx < DL_SNIFFER_NOF_MCS; mcs_idx ++){ - csv_file << mcs_idx <<','; + for (int mcs_idx = 0; mcs_idx < DL_SNIFFER_NOF_MCS; mcs_idx++) + { + csv_file << mcs_idx << ','; } csv_file << "\n"; - } MCSTracking::~MCSTracking() @@ -26,96 +29,118 @@ MCSTracking::~MCSTracking() /*___________UL 256/64/16QAM tracking implementation__________*/ -ul_sniffer_mod_tracking_t MCSTracking::find_tracking_info_RNTI_ul(uint16_t RNTI){ - +ul_sniffer_mod_tracking_t MCSTracking::find_tracking_info_RNTI_ul(uint16_t RNTI) +{ + std::unique_lock trackinglock(tracking_mutex); std::map::iterator iter; iter = tracking_database_ul_mode.find(RNTI); - if ((nof_RNTI_member_ul() == 0)||(iter == tracking_database_ul_mode.end())){ - if (nof_RNTI_member_ul() < max_size){ - //add_RNTI(RNTI, UL_SNIFFER_UNKNOWN_MOD); - return UL_SNIFFER_UNKNOWN_MOD; - } else { + if ((nof_RNTI_member_ul() == 0) || (iter == tracking_database_ul_mode.end())) + { + if (nof_RNTI_member_ul() < max_size) + { + // add_RNTI(RNTI, UL_SNIFFER_UNKNOWN_MOD); + return UL_SNIFFER_UNKNOWN_MOD; + } + else + { return UL_SNIFFER_FULL_BUFFER; } - } else { + } + else + { clock_t cur_time = clock(); iter->second.time = cur_time; - return iter->second.mcs_mod; + return iter->second.mcs_mod; } trackinglock.unlock(); } -int MCSTracking::add_RNTI_ul(uint16_t RNTI, ul_sniffer_mod_tracking_t mcs_mod){ +int MCSTracking::add_RNTI_ul(uint16_t RNTI, ul_sniffer_mod_tracking_t mcs_mod) +{ clock_t cur_time = clock(); ul_sniffer_tracking_t new_tracking; new_tracking.time = cur_time; new_tracking.mcs_mod = mcs_mod; new_tracking.ue_spec_config = default_ue_spec_config; new_tracking.ue_spec_config.has_ue_config = false; - tracking_database_ul_mode.insert(std::pair(RNTI,(std::move(new_tracking)))); + tracking_database_ul_mode.insert(std::pair(RNTI, (std::move(new_tracking)))); return SRSRAN_SUCCESS; } -void MCSTracking::update_RNTI_ul(uint16_t RNTI, ul_sniffer_mod_tracking_t mcs_mod){ +void MCSTracking::update_RNTI_ul(uint16_t RNTI, ul_sniffer_mod_tracking_t mcs_mod) +{ std::unique_lock trackinglock(tracking_mutex); std::map::iterator iter; iter = tracking_database_ul_mode.find(RNTI); - if (iter!= tracking_database_ul_mode.end()) + if (iter != tracking_database_ul_mode.end()) { iter->second.mcs_mod = mcs_mod; - }else{ - add_RNTI_ul(RNTI, UL_SNIFFER_UNKNOWN_MOD); + } + else + { + add_RNTI_ul(RNTI, UL_SNIFFER_UNKNOWN_MOD); } trackinglock.unlock(); } -void MCSTracking::update_database_ul(){ +void MCSTracking::update_database_ul() +{ std::unique_lock trackinglock(tracking_mutex); std::vector del_list; clock_t cur_time = clock(); long double cur_interval = 0; std::map::iterator iter; - for (iter = tracking_database_ul_mode.begin(); iter != tracking_database_ul_mode.end(); iter++){ + for (iter = tracking_database_ul_mode.begin(); iter != tracking_database_ul_mode.end(); iter++) + { clock_t last_time = iter->second.time; - cur_interval = (long double)((cur_time - last_time)/CLOCKS_PER_SEC); + cur_interval = (long double)((cur_time - last_time) / CLOCKS_PER_SEC); bool wrong_detect = false; // wrong detection if decode wrong mimo multiple times /*Only add to final data base if there was no error when decoding PDSCH and nof_active = 0*/ - if (((iter->second.nof_active == 0)) || (iter->second.nof_active <= 10 && iter->second.nof_success_mgs == 0 && \ - (iter->second.nof_unsupport_mimo > 0 || iter->second.nof_pinfo >0 || iter->second.nof_other_mimo >0))){ - wrong_detect = true; - iter->second.to_all_database = false; + if (((iter->second.nof_active == 0)) || (iter->second.nof_active <= 10 && iter->second.nof_success_mgs == 0 && + (iter->second.nof_unsupport_mimo > 0 || iter->second.nof_pinfo > 0 || iter->second.nof_other_mimo > 0))) + { + wrong_detect = true; + iter->second.to_all_database = false; } - if (cur_interval > interval || wrong_detect || iter->second.nof_active == 0){ + if (cur_interval > interval || wrong_detect || iter->second.nof_active == 0) + { del_list.push_back(iter->first); } } - if (del_list.size()!= 0){ + if (del_list.size() != 0) + { std::vector::iterator iter; std::map::iterator del_iter; - for (iter = del_list.begin(); iter != del_list.end(); iter++){ - del_iter = tracking_database_ul_mode.find(*iter); + for (iter = del_list.begin(); iter != del_list.end(); iter++) + { + del_iter = tracking_database_ul_mode.find(*iter); /*Update RNTI to final database (this database will not be deleted)*/ - if (del_iter->second.to_all_database){ - auto add_iter = all_database_ul_mode.find(*iter); - if (add_iter != all_database_ul_mode.end()){ - add_iter->second.nof_active += del_iter->second.nof_active; - add_iter->second.nof_newtx += del_iter->second.nof_newtx; - add_iter->second.nof_success_mgs += del_iter->second.nof_success_mgs; - add_iter->second.nof_retx += del_iter->second.nof_retx; - add_iter->second.nof_success_retx_nom += del_iter->second.nof_success_retx_nom; - add_iter->second.nof_success_retx_harq += del_iter->second.nof_success_retx_harq; - add_iter->second.nof_success_retx += del_iter->second.nof_success_retx; - add_iter->second.nof_unsupport_mimo += del_iter->second.nof_unsupport_mimo; - for (int mcs_idx = 0; mcs_idx < DL_SNIFFER_NOF_MCS; mcs_idx++){ - add_iter->second.mcs[mcs_idx] += del_iter->second.mcs[mcs_idx]; - add_iter->second.mcs_sc[mcs_idx] += del_iter->second.mcs_sc[mcs_idx]; + if (del_iter->second.to_all_database) + { + auto add_iter = all_database_ul_mode.find(*iter); + if (add_iter != all_database_ul_mode.end()) + { + add_iter->second.nof_active += del_iter->second.nof_active; + add_iter->second.nof_newtx += del_iter->second.nof_newtx; + add_iter->second.nof_success_mgs += del_iter->second.nof_success_mgs; + add_iter->second.nof_retx += del_iter->second.nof_retx; + add_iter->second.nof_success_retx_nom += del_iter->second.nof_success_retx_nom; + add_iter->second.nof_success_retx_harq += del_iter->second.nof_success_retx_harq; + add_iter->second.nof_success_retx += del_iter->second.nof_success_retx; + add_iter->second.nof_unsupport_mimo += del_iter->second.nof_unsupport_mimo; + for (int mcs_idx = 0; mcs_idx < DL_SNIFFER_NOF_MCS; mcs_idx++) + { + add_iter->second.mcs[mcs_idx] += del_iter->second.mcs[mcs_idx]; + add_iter->second.mcs_sc[mcs_idx] += del_iter->second.mcs_sc[mcs_idx]; } float sum_snr = 0; float ave_snr = 0; - if (del_iter->second.snr.size() > 0){ - for (float x: del_iter->second.snr){ + if (del_iter->second.snr.size() > 0) + { + for (float x : del_iter->second.snr) + { sum_snr += x; } ave_snr = sum_snr / del_iter->second.snr.size(); @@ -125,15 +150,18 @@ void MCSTracking::update_database_ul(){ /*TA*/ float sum_ta = 0; float ave_ta = 0; - if (del_iter->second.ta.size() > 0){ - for (float x: del_iter->second.ta){ + if (del_iter->second.ta.size() > 0) + { + for (float x : del_iter->second.ta) + { sum_ta += x; } ave_ta = sum_ta / del_iter->second.ta.size(); } add_iter->second.ta.push_back(ave_ta); } - else{ + else + { ul_sniffer_tracking_t temp_tracking = {}; temp_tracking = del_iter->second; uint16_t temp_rnti = del_iter->first; @@ -141,7 +169,8 @@ void MCSTracking::update_database_ul(){ all_database_ul_mode.insert(std::move(temp_pair)); } } - if (del_iter!=tracking_database_ul_mode.end()){ + if (del_iter != tracking_database_ul_mode.end()) + { tracking_database_ul_mode.erase(del_iter); } } @@ -149,28 +178,34 @@ void MCSTracking::update_database_ul(){ trackinglock.unlock(); } -void MCSTracking::merge_all_database_ul(){ +void MCSTracking::merge_all_database_ul() +{ std::unique_lock trackinglock(tracking_mutex); std::map::iterator merge_iter; - for (merge_iter = tracking_database_ul_mode.begin(); merge_iter != tracking_database_ul_mode.end(); merge_iter ++){ - auto add_iter = all_database_ul_mode.find(merge_iter->first); - if (add_iter != all_database_ul_mode.end()){ - add_iter->second.nof_active += merge_iter->second.nof_active; - add_iter->second.nof_newtx += merge_iter->second.nof_newtx; - add_iter->second.nof_success_mgs += merge_iter->second.nof_success_mgs; - add_iter->second.nof_retx += merge_iter->second.nof_retx; - add_iter->second.nof_success_retx_nom += merge_iter->second.nof_success_retx_nom; - add_iter->second.nof_success_retx_harq += merge_iter->second.nof_success_retx_harq; - add_iter->second.nof_success_retx += merge_iter->second.nof_success_retx; - add_iter->second.nof_unsupport_mimo += merge_iter->second.nof_unsupport_mimo; - for (int mcs_idx = 0; mcs_idx < DL_SNIFFER_NOF_MCS; mcs_idx++){ - add_iter->second.mcs[mcs_idx] += merge_iter->second.mcs[mcs_idx]; - add_iter->second.mcs_sc[mcs_idx] += merge_iter->second.mcs_sc[mcs_idx]; + for (merge_iter = tracking_database_ul_mode.begin(); merge_iter != tracking_database_ul_mode.end(); merge_iter++) + { + auto add_iter = all_database_ul_mode.find(merge_iter->first); + if (add_iter != all_database_ul_mode.end()) + { + add_iter->second.nof_active += merge_iter->second.nof_active; + add_iter->second.nof_newtx += merge_iter->second.nof_newtx; + add_iter->second.nof_success_mgs += merge_iter->second.nof_success_mgs; + add_iter->second.nof_retx += merge_iter->second.nof_retx; + add_iter->second.nof_success_retx_nom += merge_iter->second.nof_success_retx_nom; + add_iter->second.nof_success_retx_harq += merge_iter->second.nof_success_retx_harq; + add_iter->second.nof_success_retx += merge_iter->second.nof_success_retx; + add_iter->second.nof_unsupport_mimo += merge_iter->second.nof_unsupport_mimo; + for (int mcs_idx = 0; mcs_idx < DL_SNIFFER_NOF_MCS; mcs_idx++) + { + add_iter->second.mcs[mcs_idx] += merge_iter->second.mcs[mcs_idx]; + add_iter->second.mcs_sc[mcs_idx] += merge_iter->second.mcs_sc[mcs_idx]; } float sum_snr = 0; float ave_snr = 0; - if (merge_iter->second.snr.size() > 0){ - for (float x: merge_iter->second.snr){ + if (merge_iter->second.snr.size() > 0) + { + for (float x : merge_iter->second.snr) + { sum_snr += x; } ave_snr = sum_snr / merge_iter->second.snr.size(); @@ -180,14 +215,18 @@ void MCSTracking::merge_all_database_ul(){ /*TA*/ float sum_ta = 0; float ave_ta = 0; - if (merge_iter->second.ta.size() > 0){ - for (float x: merge_iter->second.ta){ + if (merge_iter->second.ta.size() > 0) + { + for (float x : merge_iter->second.ta) + { sum_ta += x; } ave_ta = sum_ta / merge_iter->second.ta.size(); } add_iter->second.ta.push_back(ave_ta); - }else{ + } + else + { ul_sniffer_tracking_t temp_tracking = {}; temp_tracking = merge_iter->second; uint16_t temp_rnti = merge_iter->first; @@ -199,16 +238,19 @@ void MCSTracking::merge_all_database_ul(){ trackinglock.unlock(); } -void print_statistic_rnti_ul_mode(std::map::iterator iter, int num, std::string info){ +void print_statistic_rnti_ul_mode(std::map::iterator iter, int num, std::string info) +{ std::cout << std::left << std::setw(5) << num; std::cout << std::left << std::setw(9) << iter->first; - std::cout << std::left << std::setw(12)<< info; + std::cout << std::left << std::setw(12) << info; std::cout << std::left << std::setw(9) << iter->second.nof_active; std::cout << std::left << std::setw(9) << iter->second.nof_success_mgs; float sum_snr = 0; float ave_snr = 0; - if (iter->second.snr.size() > 0){ - for (float x: iter->second.snr){ + if (iter->second.snr.size() > 0) + { + for (float x : iter->second.snr) + { sum_snr += x; } ave_snr = sum_snr / iter->second.snr.size(); @@ -218,16 +260,21 @@ void print_statistic_rnti_ul_mode(std::map::ite /*TA*/ float sum_ta = 0; float ave_ta = 0; - if (iter->second.ta.size() > 0){ - for (float x: iter->second.ta){ + if (iter->second.ta.size() > 0) + { + for (float x : iter->second.ta) + { sum_ta += x; } ave_ta = sum_ta / iter->second.ta.size(); } - if (ave_ta >= 0){ + if (ave_ta >= 0) + { std::cout << "+"; std::cout << std::left << std::setw(17) << std::setprecision(3) << ave_ta; - } else{ + } + else + { std::cout << std::left << std::setw(18) << std::setprecision(3) << ave_ta; } @@ -235,70 +282,84 @@ void print_statistic_rnti_ul_mode(std::map::ite std::cout << std::endl; } -void print_header_ul_mode(){ - std::cout << std::left << std::setw(5) << "Num"; - std::cout << std::left << std::setw(9) << "RNTI"; +void print_header_ul_mode() +{ + std::cout << std::left << std::setw(5) << "Num"; + std::cout << std::left << std::setw(9) << "RNTI"; std::cout << std::left << std::setw(12) << "Max Mod"; - std::cout << std::left << std::setw(9) << "Active"; - std::cout << std::left << std::setw(9) << "Success"; - std::cout << std::left << std::setw(9) << "SNR(dB)"; + std::cout << std::left << std::setw(9) << "Active"; + std::cout << std::left << std::setw(9) << "Success"; + std::cout << std::left << std::setw(9) << "SNR(dB)"; std::cout << std::left << std::setw(18) << "DL-UL_delay(us)"; - std::cout << std::left << std::setw(9) << "Other_Info"; + std::cout << std::left << std::setw(9) << "Other_Info"; std::cout << std::endl; } -void MCSTracking::print_database_ul(){ +void MCSTracking::print_database_ul() +{ std::unique_lock trackinglock(tracking_mutex); std::map::iterator iter; int nof_16qam = 0; int nof_64qam = 0; int nof_256qam = 0; - int nof_unknown = 0; + int nof_unknown = 0; int num = 1; - for (int i = 0; i < 86; i++){ + for (int i = 0; i < 86; i++) + { std::cout << "-"; - } + } std::cout << std::endl; print_header_ul_mode(); - for (int i = 0; i < 86; i++){ + for (int i = 0; i < 86; i++) + { std::cout << "-"; - } + } std::cout << std::endl; - for (iter = tracking_database_ul_mode.begin(); iter != tracking_database_ul_mode.end(); iter++){ - if (iter->second.mcs_mod == UL_SNIFFER_16QAM_MAX && iter->second.nof_active > 0){ + for (iter = tracking_database_ul_mode.begin(); iter != tracking_database_ul_mode.end(); iter++) + { + if (iter->second.mcs_mod == UL_SNIFFER_16QAM_MAX && iter->second.nof_active > 0) + { print_statistic_rnti_ul_mode(iter, num, "16QAM"); nof_16qam++; num++; } } - for (iter = tracking_database_ul_mode.begin(); iter != tracking_database_ul_mode.end(); iter++){ - if (iter->second.mcs_mod == UL_SNIFFER_64QAM_MAX && iter->second.nof_active > 0){ + for (iter = tracking_database_ul_mode.begin(); iter != tracking_database_ul_mode.end(); iter++) + { + if (iter->second.mcs_mod == UL_SNIFFER_64QAM_MAX && iter->second.nof_active > 0) + { print_statistic_rnti_ul_mode(iter, num, "64QAM"); nof_64qam++; num++; } } - for (iter = tracking_database_ul_mode.begin(); iter != tracking_database_ul_mode.end(); iter++){ - if (iter->second.mcs_mod == UL_SNIFFER_256QAM_MAX && iter->second.nof_active > 0){ + for (iter = tracking_database_ul_mode.begin(); iter != tracking_database_ul_mode.end(); iter++) + { + if (iter->second.mcs_mod == UL_SNIFFER_256QAM_MAX && iter->second.nof_active > 0) + { print_statistic_rnti_ul_mode(iter, num, "256QAM"); nof_256qam++; num++; } } - for (int i = 0; i < 86; i++){ + for (int i = 0; i < 86; i++) + { std::cout << "-"; } std::cout << std::endl; print_header_ul_mode(); - for (iter = tracking_database_ul_mode.begin(); iter != tracking_database_ul_mode.end(); iter++){ - if (iter->second.mcs_mod == UL_SNIFFER_UNKNOWN_MOD && iter->second.nof_active > 0){ - if ((iter->second.nof_unsupport_mimo == 0 && iter->second.nof_pinfo==0 && iter->second.nof_other_mimo==0 && iter->second.nof_active > 0)){ + for (iter = tracking_database_ul_mode.begin(); iter != tracking_database_ul_mode.end(); iter++) + { + if (iter->second.mcs_mod == UL_SNIFFER_UNKNOWN_MOD && iter->second.nof_active > 0) + { + if ((iter->second.nof_unsupport_mimo == 0 && iter->second.nof_pinfo == 0 && iter->second.nof_other_mimo == 0 && iter->second.nof_active > 0)) + { print_statistic_rnti_ul_mode(iter, num, "Unknown"); nof_unknown++; num++; @@ -306,71 +367,83 @@ void MCSTracking::print_database_ul(){ } } - for (int i = 0; i < 86; i++){ + for (int i = 0; i < 86; i++) + { std::cout << "-"; - } + } std::cout << std::endl; - for (iter = tracking_database_ul_mode.begin(); iter != tracking_database_ul_mode.end(); iter++){ - if (iter->second.mcs_mod == UL_SNIFFER_UNKNOWN_MOD){ - if ((iter->second.nof_active > 0) && !(iter->second.nof_unsupport_mimo == 0 && iter->second.nof_pinfo==0 && iter->second.nof_other_mimo==0)){ + for (iter = tracking_database_ul_mode.begin(); iter != tracking_database_ul_mode.end(); iter++) + { + if (iter->second.mcs_mod == UL_SNIFFER_UNKNOWN_MOD) + { + if ((iter->second.nof_active > 0) && !(iter->second.nof_unsupport_mimo == 0 && iter->second.nof_pinfo == 0 && iter->second.nof_other_mimo == 0)) + { print_statistic_rnti_ul_mode(iter, num, "Unknown"); nof_unknown++; num++; } } } - printf ("[256Tracking] Total: %d RNTIs are max 16QAM, %d RNTIs are max 64QAM table, %d RNTIs are max 256QAM, %d RNTIs are Unknown \n\n", - nof_16qam, nof_64qam, nof_256qam, nof_unknown); + printf("[256Tracking] Total: %d RNTIs are max 16QAM, %d RNTIs are max 64QAM table, %d RNTIs are max 256QAM, %d RNTIs are Unknown \n\n", + nof_16qam, nof_64qam, nof_256qam, nof_unknown); trackinglock.unlock(); } -void MCSTracking::print_all_database_ul(){ +void MCSTracking::print_all_database_ul() +{ std::unique_lock trackinglock(tracking_mutex); std::map::iterator iter; int nof_16qam = 0; int nof_64qam = 0; int nof_256qam = 0; - int nof_unknown = 0; + int nof_unknown = 0; int num = 1; - for (int i = 0; i < 86; i++){ + for (int i = 0; i < 86; i++) + { std::cout << "-"; - } + } std::cout << std::endl; - std::cout << std::left << std::setw(5) << "Num"; - std::cout << std::left << std::setw(9) << "RNTI"; + std::cout << std::left << std::setw(5) << "Num"; + std::cout << std::left << std::setw(9) << "RNTI"; std::cout << std::left << std::setw(12) << "Max Mod"; - std::cout << std::left << std::setw(9) << "Active"; + std::cout << std::left << std::setw(9) << "Active"; std::cout << BOLDGREEN << std::left << std::setw(13) << "Success" << RESET; - std::cout << std::left << std::setw(9) << "SNR(dB)"; + std::cout << std::left << std::setw(9) << "SNR(dB)"; std::cout << std::left << std::setw(18) << "DL-UL_delay(us)"; - std::cout << std::left << std::setw(9) << "Other_Info"; + std::cout << std::left << std::setw(9) << "Other_Info"; std::cout << std::endl; - for (int i = 0; i < 86; i++){ + for (int i = 0; i < 86; i++) + { std::cout << "-"; - } + } std::cout << std::endl; - for (iter = all_database_ul_mode.begin(); iter != all_database_ul_mode.end(); iter++){ - if (iter->second.mcs_mod == UL_SNIFFER_16QAM_MAX && iter->second.nof_active > 0){ + for (iter = all_database_ul_mode.begin(); iter != all_database_ul_mode.end(); iter++) + { + if (iter->second.mcs_mod == UL_SNIFFER_16QAM_MAX && iter->second.nof_active > 0) + { nof_16qam++; std::cout << std::left << std::setw(5) << num; std::cout << std::left << std::setw(9) << iter->first; - std::cout << std::left << std::setw(12)<< "16QAM"; - std::cout << std::left << std::setw(9) << iter->second.nof_active ; + std::cout << std::left << std::setw(12) << "16QAM"; + std::cout << std::left << std::setw(9) << iter->second.nof_active; int sc_percent = 0; - if (iter->second.nof_active > 0){ - sc_percent = std::roundf(((float)iter->second.nof_success_mgs/(float)iter->second.nof_active)*100); + if (iter->second.nof_active > 0) + { + sc_percent = std::roundf(((float)iter->second.nof_success_mgs / (float)iter->second.nof_active) * 100); } - std::string sc_pc_str =std::to_string(iter->second.nof_success_mgs) + '(' + std::to_string(sc_percent) + "%)"; + std::string sc_pc_str = std::to_string(iter->second.nof_success_mgs) + '(' + std::to_string(sc_percent) + "%)"; std::cout << BOLDGREEN << std::left << std::setw(13) << sc_pc_str << RESET; float sum_snr = 0; float ave_snr = 0; - if (iter->second.snr.size() > 0){ - for (float x: iter->second.snr){ + if (iter->second.snr.size() > 0) + { + for (float x : iter->second.snr) + { sum_snr += x; } ave_snr = sum_snr / iter->second.snr.size(); @@ -380,41 +453,51 @@ void MCSTracking::print_all_database_ul(){ /*TA*/ float sum_ta = 0; float ave_ta = 0; - if (iter->second.ta.size() > 0){ - for (float x: iter->second.ta){ + if (iter->second.ta.size() > 0) + { + for (float x : iter->second.ta) + { sum_ta += x; } ave_ta = sum_ta / iter->second.ta.size(); } - if (ave_ta >= 0){ + if (ave_ta >= 0) + { std::cout << "+"; std::cout << std::left << std::setw(17) << std::setprecision(3) << ave_ta; - } else{ + } + else + { std::cout << std::left << std::setw(18) << std::setprecision(3) << ave_ta; } - std::cout << std::left << std::setw(9) << iter->second.nof_other_mimo; + std::cout << std::left << std::setw(9) << iter->second.nof_other_mimo; std::cout << std::endl; num++; - //write_csv_file(iter->first, iter->second, iter->second.mcs_mod); + // write_csv_file(iter->first, iter->second, iter->second.mcs_mod); } } - for (iter = all_database_ul_mode.begin(); iter != all_database_ul_mode.end(); iter++){ - if (iter->second.mcs_mod == UL_SNIFFER_64QAM_MAX && iter->second.nof_active > 0){ + for (iter = all_database_ul_mode.begin(); iter != all_database_ul_mode.end(); iter++) + { + if (iter->second.mcs_mod == UL_SNIFFER_64QAM_MAX && iter->second.nof_active > 0) + { nof_64qam++; std::cout << std::left << std::setw(5) << num; std::cout << std::left << std::setw(9) << iter->first; std::cout << std::left << std::setw(12) << "64QAM"; - std::cout << std::left << std::setw(9) << iter->second.nof_active ; + std::cout << std::left << std::setw(9) << iter->second.nof_active; int sc_percent = 0; - if (iter->second.nof_active > 0){ - sc_percent = std::roundf(((float)iter->second.nof_success_mgs/(float)iter->second.nof_active)*100); + if (iter->second.nof_active > 0) + { + sc_percent = std::roundf(((float)iter->second.nof_success_mgs / (float)iter->second.nof_active) * 100); } - std::string sc_pc_str =std::to_string(iter->second.nof_success_mgs) + '(' + std::to_string(sc_percent) + "%)"; + std::string sc_pc_str = std::to_string(iter->second.nof_success_mgs) + '(' + std::to_string(sc_percent) + "%)"; std::cout << BOLDGREEN << std::left << std::setw(13) << sc_pc_str << RESET; float sum_snr = 0; float ave_snr = 0; - if (iter->second.snr.size() > 0){ - for (float x: iter->second.snr){ + if (iter->second.snr.size() > 0) + { + for (float x : iter->second.snr) + { sum_snr += x; } ave_snr = sum_snr / iter->second.snr.size(); @@ -424,40 +507,50 @@ void MCSTracking::print_all_database_ul(){ /*TA*/ float sum_ta = 0; float ave_ta = 0; - if (iter->second.ta.size() > 0){ - for (float x: iter->second.ta){ + if (iter->second.ta.size() > 0) + { + for (float x : iter->second.ta) + { sum_ta += x; } ave_ta = sum_ta / iter->second.ta.size(); } - if (ave_ta >= 0){ + if (ave_ta >= 0) + { std::cout << "+"; std::cout << std::left << std::setw(17) << std::setprecision(3) << ave_ta; - } else{ + } + else + { std::cout << std::left << std::setw(18) << std::setprecision(3) << ave_ta; } - std::cout << std::left << std::setw(9) << iter->second.nof_other_mimo; + std::cout << std::left << std::setw(9) << iter->second.nof_other_mimo; std::cout << std::endl; num++; - //write_csv_file(iter->first, iter->second, iter->second.mcs_mod); + // write_csv_file(iter->first, iter->second, iter->second.mcs_mod); } } - for (iter = all_database_ul_mode.begin(); iter != all_database_ul_mode.end(); iter++){ - if (iter->second.mcs_mod == UL_SNIFFER_256QAM_MAX && iter->second.nof_active > 0){ + for (iter = all_database_ul_mode.begin(); iter != all_database_ul_mode.end(); iter++) + { + if (iter->second.mcs_mod == UL_SNIFFER_256QAM_MAX && iter->second.nof_active > 0) + { std::cout << std::left << std::setw(5) << num; std::cout << std::left << std::setw(9) << iter->first; std::cout << std::left << std::setw(12) << "256QAM"; - std::cout << std::left << std::setw(9) << iter->second.nof_active ; + std::cout << std::left << std::setw(9) << iter->second.nof_active; int sc_percent = 0; - if (iter->second.nof_active > 0){ - sc_percent = std::roundf(((float)iter->second.nof_success_mgs/(float)iter->second.nof_active)*100); + if (iter->second.nof_active > 0) + { + sc_percent = std::roundf(((float)iter->second.nof_success_mgs / (float)iter->second.nof_active) * 100); } - std::string sc_pc_str =std::to_string(iter->second.nof_success_mgs) + '(' + std::to_string(sc_percent) + "%)"; + std::string sc_pc_str = std::to_string(iter->second.nof_success_mgs) + '(' + std::to_string(sc_percent) + "%)"; std::cout << BOLDGREEN << std::left << std::setw(13) << sc_pc_str << RESET; float sum_snr = 0; float ave_snr = 0; - if (iter->second.snr.size() > 0){ - for (float x: iter->second.snr){ + if (iter->second.snr.size() > 0) + { + for (float x : iter->second.snr) + { sum_snr += x; } ave_snr = sum_snr / iter->second.snr.size(); @@ -467,57 +560,69 @@ void MCSTracking::print_all_database_ul(){ /*TA*/ float sum_ta = 0; float ave_ta = 0; - if (iter->second.ta.size() > 0){ - for (float x: iter->second.ta){ + if (iter->second.ta.size() > 0) + { + for (float x : iter->second.ta) + { sum_ta += x; } ave_ta = sum_ta / iter->second.ta.size(); } - if (ave_ta >= 0){ + if (ave_ta >= 0) + { std::cout << "+"; std::cout << std::left << std::setw(17) << std::setprecision(3) << ave_ta; - } else{ + } + else + { std::cout << std::left << std::setw(18) << std::setprecision(3) << ave_ta; } - std::cout << std::left << std::setw(9) << iter->second.nof_other_mimo; + std::cout << std::left << std::setw(9) << iter->second.nof_other_mimo; std::cout << std::endl; nof_256qam++; num++; - //write_csv_file(iter->first, iter->second, iter->second.mcs_mod); + // write_csv_file(iter->first, iter->second, iter->second.mcs_mod); } } - for (int i = 0; i < 86; i++){ + for (int i = 0; i < 86; i++) + { std::cout << "-"; } std::cout << std::endl; - std::cout << std::left << std::setw(5) << "Num "; - std::cout << std::left << std::setw(9) << "RNTI"; - std::cout << std::left << std::setw(12) << "Max Mod"; - std::cout << std::left << std::setw(9) << "Active"; + std::cout << std::left << std::setw(5) << "Num "; + std::cout << std::left << std::setw(9) << "RNTI"; + std::cout << std::left << std::setw(12) << "Max Mod"; + std::cout << std::left << std::setw(9) << "Active"; std::cout << BOLDGREEN << std::left << std::setw(13) << "Success" << RESET; - std::cout << std::left << std::setw(9) << "SNR(dB)"; + std::cout << std::left << std::setw(9) << "SNR(dB)"; std::cout << std::left << std::setw(18) << "DL-UL_delay(us)"; std::cout << std::left << std::setw(9) << "Other_Info"; std::cout << std::endl; - for (iter = all_database_ul_mode.begin(); iter != all_database_ul_mode.end(); iter++){ - if (iter->second.mcs_mod == UL_SNIFFER_UNKNOWN_MOD && iter->second.nof_active > 0){ - if ((iter->second.nof_unsupport_mimo == 0 && iter->second.nof_pinfo==0&&iter->second.nof_other_mimo==0)){ + for (iter = all_database_ul_mode.begin(); iter != all_database_ul_mode.end(); iter++) + { + if (iter->second.mcs_mod == UL_SNIFFER_UNKNOWN_MOD && iter->second.nof_active > 0) + { + if ((iter->second.nof_unsupport_mimo == 0 && iter->second.nof_pinfo == 0 && iter->second.nof_other_mimo == 0)) + { std::cout << std::left << std::setw(5) << num; std::cout << std::left << std::setw(9) << iter->first; std::cout << std::left << std::setw(12) << "Unknown"; - std::cout << std::left << std::setw(9) << iter->second.nof_active ; + std::cout << std::left << std::setw(9) << iter->second.nof_active; int sc_percent = 0; - if (iter->second.nof_active > 0){ - sc_percent = std::roundf(((float)iter->second.nof_success_mgs/(float)iter->second.nof_active)*100); + if (iter->second.nof_active > 0) + { + sc_percent = std::roundf(((float)iter->second.nof_success_mgs / (float)iter->second.nof_active) * 100); } - std::string sc_pc_str =std::to_string(iter->second.nof_success_mgs) + '(' + std::to_string(sc_percent) + "%)"; + std::string sc_pc_str = std::to_string(iter->second.nof_success_mgs) + '(' + std::to_string(sc_percent) + "%)"; std::cout << BOLDGREEN << std::left << std::setw(13) << sc_pc_str << RESET; float sum_snr = 0; float ave_snr = 0; - if (iter->second.snr.size() > 0){ - for (float x: iter->second.snr){ + if (iter->second.snr.size() > 0) + { + for (float x : iter->second.snr) + { sum_snr += x; } ave_snr = sum_snr / iter->second.snr.size(); @@ -527,49 +632,61 @@ void MCSTracking::print_all_database_ul(){ /*TA*/ float sum_ta = 0; float ave_ta = 0; - if (iter->second.ta.size() > 0){ - for (float x: iter->second.ta){ + if (iter->second.ta.size() > 0) + { + for (float x : iter->second.ta) + { sum_ta += x; } ave_ta = sum_ta / iter->second.ta.size(); } - if (ave_ta >= 0){ + if (ave_ta >= 0) + { std::cout << "+"; std::cout << std::left << std::setw(17) << std::setprecision(3) << ave_ta; - } else{ + } + else + { std::cout << std::left << std::setw(18) << std::setprecision(3) << ave_ta; } - std::cout << std::left << std::setw(9) << iter->second.nof_other_mimo; + std::cout << std::left << std::setw(9) << iter->second.nof_other_mimo; std::cout << std::endl; nof_unknown++; num++; - //write_csv_file(iter->first, iter->second, iter->second.mcs_mod); + // write_csv_file(iter->first, iter->second, iter->second.mcs_mod); } } } - for (int i = 0; i < 86; i++){ + for (int i = 0; i < 86; i++) + { std::cout << "-"; - } + } std::cout << std::endl; - for (iter = all_database_ul_mode.begin(); iter != all_database_ul_mode.end(); iter++){ - if (iter->second.mcs_mod == UL_SNIFFER_UNKNOWN_MOD && iter->second.nof_active > 0){ - if (!(iter->second.nof_unsupport_mimo == 0&&iter->second.nof_pinfo==0&&iter->second.nof_other_mimo==0)){ + for (iter = all_database_ul_mode.begin(); iter != all_database_ul_mode.end(); iter++) + { + if (iter->second.mcs_mod == UL_SNIFFER_UNKNOWN_MOD && iter->second.nof_active > 0) + { + if (!(iter->second.nof_unsupport_mimo == 0 && iter->second.nof_pinfo == 0 && iter->second.nof_other_mimo == 0)) + { std::cout << std::left << std::setw(5) << num; std::cout << std::left << std::setw(9) << iter->first; std::cout << std::left << std::setw(12) << "Unknown"; - std::cout << std::left << std::setw(9) << iter->second.nof_active ; + std::cout << std::left << std::setw(9) << iter->second.nof_active; int sc_percent = 0; - if (iter->second.nof_newtx > 0){ - sc_percent = std::roundf(((float)iter->second.nof_success_mgs/(float)iter->second.nof_active)*100); + if (iter->second.nof_newtx > 0) + { + sc_percent = std::roundf(((float)iter->second.nof_success_mgs / (float)iter->second.nof_active) * 100); } - std::string sc_pc_str =std::to_string(iter->second.nof_success_mgs) + '(' + std::to_string(sc_percent) + "%)"; + std::string sc_pc_str = std::to_string(iter->second.nof_success_mgs) + '(' + std::to_string(sc_percent) + "%)"; std::cout << BOLDGREEN << std::left << std::setw(13) << sc_pc_str << RESET; float sum_snr = 0; float ave_snr = 0; - if (iter->second.snr.size() > 0){ - for (float x: iter->second.snr){ + if (iter->second.snr.size() > 0) + { + for (float x : iter->second.snr) + { sum_snr += x; } ave_snr = sum_snr / iter->second.snr.size(); @@ -579,48 +696,57 @@ void MCSTracking::print_all_database_ul(){ /*TA*/ float sum_ta = 0; float ave_ta = 0; - if (iter->second.ta.size() > 0){ - for (float x: iter->second.ta){ + if (iter->second.ta.size() > 0) + { + for (float x : iter->second.ta) + { sum_ta += x; } ave_ta = sum_ta / iter->second.ta.size(); } - if (ave_ta >= 0){ + if (ave_ta >= 0) + { std::cout << "+"; std::cout << std::left << std::setw(17) << std::setprecision(3) << ave_ta; - } else{ + } + else + { std::cout << std::left << std::setw(18) << std::setprecision(3) << ave_ta; } - std::cout << std::left << std::setw(9) << iter->second.nof_other_mimo; + std::cout << std::left << std::setw(9) << iter->second.nof_other_mimo; std::cout << std::endl; nof_unknown++; num++; } } } - printf ("[256Tracking] Total: %d RNTIs are max 16QAM table, %d RNTIs are max 64QAM table, %d RNTIs are max 256QAM, %d RNTIs are Unknown \n\n", - nof_16qam,nof_64qam, nof_256qam, nof_unknown); - + printf("[256Tracking] Total: %d RNTIs are max 16QAM table, %d RNTIs are max 64QAM table, %d RNTIs are max 256QAM, %d RNTIs are Unknown \n\n", + nof_16qam, nof_64qam, nof_256qam, nof_unknown); + trackinglock.unlock(); } void MCSTracking::update_statistic_ul(uint16_t RNTI, - bool success, - DCI_UL &decoding_mem, - float snr, - float ta) + bool success, + DCI_UL &decoding_mem, + float snr, + float ta) { std::unique_lock trackinglock(tracking_mutex); std::map::iterator iter; iter = tracking_database_ul_mode.find(RNTI); - if (iter == tracking_database_ul_mode.end()){ - add_RNTI_ul(RNTI, decoding_mem.mcs_mod); + if (iter == tracking_database_ul_mode.end()) + { + add_RNTI_ul(RNTI, decoding_mem.mcs_mod); } iter = tracking_database_ul_mode.find(RNTI); - if (iter!= tracking_database_ul_mode.end()) + if (iter != tracking_database_ul_mode.end()) { iter->second.nof_active++; - if (success) {iter->second.nof_success_mgs++;} + if (success) + { + iter->second.nof_success_mgs++; + } iter->second.snr.push_back(snr); iter->second.ta.push_back(ta); } @@ -629,127 +755,161 @@ void MCSTracking::update_statistic_ul(uint16_t RNTI, /*____________DL 256QAM/64QAM tracking implementation_____________________________*/ -dl_sniffer_mcs_table_t MCSTracking::find_tracking_info_RNTI_dl(uint16_t RNTI){ - +dl_sniffer_mcs_table_t MCSTracking::find_tracking_info_RNTI_dl(uint16_t RNTI) +{ + std::unique_lock trackinglock(tracking_mutex); std::map::iterator iter; iter = tracking_database_dl_mode.find(RNTI); - if ((nof_RNTI_member_dl() == 0)||(iter == tracking_database_dl_mode.end())){ - if (nof_RNTI_member_dl() < max_size){ - //add_RNTI(RNTI, DL_SNIFFER_UNKNOWN_TABLE); - return DL_SNIFFER_UNKNOWN_TABLE; - } else { + if ((nof_RNTI_member_dl() == 0) || (iter == tracking_database_dl_mode.end())) + { + if (nof_RNTI_member_dl() < max_size) + { + // add_RNTI(RNTI, DL_SNIFFER_UNKNOWN_TABLE); + return DL_SNIFFER_UNKNOWN_TABLE; + } + else + { return DL_SNIFFER_FULL_BUFFER; } - } else { + } + else + { clock_t cur_time = clock(); iter->second.time = cur_time; - return iter->second.mcs_table; + return iter->second.mcs_table; } trackinglock.unlock(); } -int MCSTracking::add_RNTI_dl(uint16_t RNTI, dl_sniffer_mcs_table_t mcs_table){ +int MCSTracking::add_RNTI_dl(uint16_t RNTI, dl_sniffer_mcs_table_t mcs_table) +{ clock_t cur_time = clock(); dl_sniffer_mcs_tracking_t new_tracking; new_tracking.time = cur_time; new_tracking.mcs_table = mcs_table; new_tracking.ue_spec_config = default_ue_spec_config; new_tracking.ue_spec_config.has_ue_config = false; - tracking_database_dl_mode.insert(std::pair(RNTI,(std::move(new_tracking)))); + tracking_database_dl_mode.insert(std::pair(RNTI, (std::move(new_tracking)))); return SRSRAN_SUCCESS; } -void MCSTracking::update_RNTI_dl(uint16_t RNTI, dl_sniffer_mcs_table_t mcs_table){ +void MCSTracking::update_RNTI_dl(uint16_t RNTI, dl_sniffer_mcs_table_t mcs_table) +{ std::unique_lock trackinglock(tracking_mutex); std::map::iterator iter; iter = tracking_database_dl_mode.find(RNTI); - if (iter!= tracking_database_dl_mode.end()) + if (iter != tracking_database_dl_mode.end()) { - if (iter->second.has_rar){ - if (iter->second.nof_msg_after_rar > rar_thresold){ + if (iter->second.has_rar) + { + if (iter->second.nof_msg_after_rar > rar_thresold) + { iter->second.mcs_table = mcs_table; - iter->second.has_rar = false; - }else{ + iter->second.has_rar = false; + } + else + { iter->second.mcs_table = DL_SNIFFER_UNKNOWN_TABLE; } - } else { + } + else + { iter->second.mcs_table = mcs_table; } - }else{ - add_RNTI_dl(RNTI, DL_SNIFFER_UNKNOWN_TABLE); + } + else + { + add_RNTI_dl(RNTI, DL_SNIFFER_UNKNOWN_TABLE); } trackinglock.unlock(); } -void MCSTracking::update_rar_time_crnti(uint16_t crnti, clock_t cur_time){ +void MCSTracking::update_rar_time_crnti(uint16_t crnti, clock_t cur_time) +{ std::unique_lock trackinglock(tracking_mutex); std::map::iterator iter; iter = tracking_database_dl_mode.find(crnti); - if (iter!= tracking_database_dl_mode.end()) + if (iter != tracking_database_dl_mode.end()) { - iter->second.has_rar = true; + iter->second.has_rar = true; iter->second.mcs_table = DL_SNIFFER_UNKNOWN_TABLE; // iter->second.rar_time = cur_time; - }else{ + } + else + { add_RNTI_dl(crnti, DL_SNIFFER_UNKNOWN_TABLE); iter = tracking_database_dl_mode.find(crnti); - iter->second.has_rar = true; + iter->second.has_rar = true; iter->second.mcs_table = DL_SNIFFER_UNKNOWN_TABLE; // iter->second.rar_time = cur_time; } trackinglock.unlock(); } -void MCSTracking::update_database_dl(){ +void MCSTracking::update_database_dl() +{ std::unique_lock trackinglock(tracking_mutex); std::vector del_list; clock_t cur_time = clock(); long double cur_interval = 0; std::map::iterator iter; - for (iter = tracking_database_dl_mode.begin(); iter != tracking_database_dl_mode.end(); iter++){ + for (iter = tracking_database_dl_mode.begin(); iter != tracking_database_dl_mode.end(); iter++) + { clock_t last_time = iter->second.time; - cur_interval = (long double)((cur_time - last_time)/CLOCKS_PER_SEC); + cur_interval = (long double)((cur_time - last_time) / CLOCKS_PER_SEC); float cur_success_rate = (float)iter->second.nof_success_mgs / (float)iter->second.nof_active; bool wrong_detect = false; // wrong detection if decode wrong mimo multiple times /*Only add to final data base if there was no error when decoding PDSCH and nof_active = 0*/ - if ((iter->second.nof_active == 0) ||(iter->second.nof_active <= 10 && iter->second.nof_success_mgs == 0 && \ - (iter->second.nof_unsupport_mimo > 0 || iter->second.nof_pinfo >0 || iter->second.nof_other_mimo >0))){ - wrong_detect = true; - iter->second.to_all_database = false; - } + if ((iter->second.nof_active == 0) || (iter->second.nof_active <= 10 && iter->second.nof_success_mgs == 0 && + (iter->second.nof_unsupport_mimo > 0 || iter->second.nof_pinfo > 0 || iter->second.nof_other_mimo > 0))) + { + wrong_detect = true; + iter->second.to_all_database = false; + } /*delete from 10-seconds database if inactive during time interval or wrong detection or nof_active = 0*/ - if (cur_interval > interval || wrong_detect || iter->second.nof_active == 0){ + if (cur_interval > interval || wrong_detect || iter->second.nof_active == 0) + { del_list.push_back(iter->first); - } else { - if (cur_success_rate < (float)0.15 && iter->second.mcs_table != DL_SNIFFER_UNKNOWN_TABLE){ //if success rate lower than 15%, reset mcs table + } + else + { + if (cur_success_rate < (float)0.15 && iter->second.mcs_table != DL_SNIFFER_UNKNOWN_TABLE) + { // if success rate lower than 15%, reset mcs table iter->second.mcs_table = DL_SNIFFER_UNKNOWN_TABLE; } } } - if (del_list.size()!= 0){ + if (del_list.size() != 0) + { std::vector::iterator iter; std::map::iterator del_iter; - for (iter = del_list.begin(); iter != del_list.end(); iter++){ - del_iter = tracking_database_dl_mode.find(*iter); + for (iter = del_list.begin(); iter != del_list.end(); iter++) + { + del_iter = tracking_database_dl_mode.find(*iter); /*Update RNTI to final database (this database will not be deleted)*/ - if (del_iter->second.to_all_database){ - auto add_iter = all_database_dl_mode.find(*iter); - if (add_iter != all_database_dl_mode.end()){ - add_iter->second.nof_active += del_iter->second.nof_active; - add_iter->second.nof_newtx += del_iter->second.nof_newtx; - add_iter->second.nof_success_mgs += del_iter->second.nof_success_mgs; - add_iter->second.nof_retx += del_iter->second.nof_retx; - add_iter->second.nof_success_retx_nom += del_iter->second.nof_success_retx_nom; - add_iter->second.nof_success_retx_harq += del_iter->second.nof_success_retx_harq; - add_iter->second.nof_success_retx += del_iter->second.nof_success_retx; - add_iter->second.nof_unsupport_mimo += del_iter->second.nof_unsupport_mimo; - for (int mcs_idx = 0; mcs_idx < DL_SNIFFER_NOF_MCS; mcs_idx++){ - add_iter->second.mcs[mcs_idx] += del_iter->second.mcs[mcs_idx]; - add_iter->second.mcs_sc[mcs_idx] += del_iter->second.mcs_sc[mcs_idx]; + if (del_iter->second.to_all_database) + { + auto add_iter = all_database_dl_mode.find(*iter); + if (add_iter != all_database_dl_mode.end()) + { + add_iter->second.nof_active += del_iter->second.nof_active; + add_iter->second.nof_newtx += del_iter->second.nof_newtx; + add_iter->second.nof_success_mgs += del_iter->second.nof_success_mgs; + add_iter->second.nof_retx += del_iter->second.nof_retx; + add_iter->second.nof_success_retx_nom += del_iter->second.nof_success_retx_nom; + add_iter->second.nof_success_retx_harq += del_iter->second.nof_success_retx_harq; + add_iter->second.nof_success_retx += del_iter->second.nof_success_retx; + add_iter->second.nof_unsupport_mimo += del_iter->second.nof_unsupport_mimo; + for (int mcs_idx = 0; mcs_idx < DL_SNIFFER_NOF_MCS; mcs_idx++) + { + add_iter->second.mcs[mcs_idx] += del_iter->second.mcs[mcs_idx]; + add_iter->second.mcs_sc[mcs_idx] += del_iter->second.mcs_sc[mcs_idx]; } - }else{ + } + else + { dl_sniffer_mcs_tracking_t temp_tracking = {}; temp_tracking = del_iter->second; uint16_t temp_rnti = del_iter->first; @@ -757,7 +917,8 @@ void MCSTracking::update_database_dl(){ all_database_dl_mode.insert(std::move(temp_pair)); } } - if (del_iter!=tracking_database_dl_mode.end()){ + if (del_iter != tracking_database_dl_mode.end()) + { tracking_database_dl_mode.erase(del_iter); } } @@ -765,25 +926,31 @@ void MCSTracking::update_database_dl(){ trackinglock.unlock(); } -void MCSTracking::merge_all_database_dl(){ +void MCSTracking::merge_all_database_dl() +{ std::unique_lock trackinglock(tracking_mutex); std::map::iterator merge_iter; - for (merge_iter = tracking_database_dl_mode.begin(); merge_iter != tracking_database_dl_mode.end(); merge_iter ++){ - auto add_iter = all_database_dl_mode.find(merge_iter->first); - if (add_iter != all_database_dl_mode.end()){ - add_iter->second.nof_active += merge_iter->second.nof_active; - add_iter->second.nof_newtx += merge_iter->second.nof_newtx; - add_iter->second.nof_success_mgs += merge_iter->second.nof_success_mgs; - add_iter->second.nof_retx += merge_iter->second.nof_retx; - add_iter->second.nof_success_retx_nom += merge_iter->second.nof_success_retx_nom; - add_iter->second.nof_success_retx_harq += merge_iter->second.nof_success_retx_harq; - add_iter->second.nof_success_retx += merge_iter->second.nof_success_retx; - add_iter->second.nof_unsupport_mimo += merge_iter->second.nof_unsupport_mimo; - for (int mcs_idx = 0; mcs_idx < DL_SNIFFER_NOF_MCS; mcs_idx++){ - add_iter->second.mcs[mcs_idx] += merge_iter->second.mcs[mcs_idx]; - add_iter->second.mcs_sc[mcs_idx] += merge_iter->second.mcs_sc[mcs_idx]; + for (merge_iter = tracking_database_dl_mode.begin(); merge_iter != tracking_database_dl_mode.end(); merge_iter++) + { + auto add_iter = all_database_dl_mode.find(merge_iter->first); + if (add_iter != all_database_dl_mode.end()) + { + add_iter->second.nof_active += merge_iter->second.nof_active; + add_iter->second.nof_newtx += merge_iter->second.nof_newtx; + add_iter->second.nof_success_mgs += merge_iter->second.nof_success_mgs; + add_iter->second.nof_retx += merge_iter->second.nof_retx; + add_iter->second.nof_success_retx_nom += merge_iter->second.nof_success_retx_nom; + add_iter->second.nof_success_retx_harq += merge_iter->second.nof_success_retx_harq; + add_iter->second.nof_success_retx += merge_iter->second.nof_success_retx; + add_iter->second.nof_unsupport_mimo += merge_iter->second.nof_unsupport_mimo; + for (int mcs_idx = 0; mcs_idx < DL_SNIFFER_NOF_MCS; mcs_idx++) + { + add_iter->second.mcs[mcs_idx] += merge_iter->second.mcs[mcs_idx]; + add_iter->second.mcs_sc[mcs_idx] += merge_iter->second.mcs_sc[mcs_idx]; } - }else{ + } + else + { dl_sniffer_mcs_tracking_t temp_tracking = {}; temp_tracking = merge_iter->second; uint16_t temp_rnti = merge_iter->first; @@ -795,81 +962,94 @@ void MCSTracking::merge_all_database_dl(){ trackinglock.unlock(); } -void print_statistic_rnti(std::map::iterator iter, int num, std::string info){ - std::cout << std::left << std::setw(5) << num; - std::cout << std::left << std::setw(9) << iter->first; - std::cout << std::left << std::setw(12)<< info; - std::cout << std::left << std::setw(9) << iter->second.nof_active; - std::cout << std::left << std::setw(9) << iter->second.nof_newtx; - std::cout << std::left << std::setw(9) << iter->second.nof_retx; - std::cout << std::left << std::setw(9) << iter->second.nof_success_mgs; - std::cout << std::left << std::setw(9) << iter->second.nof_success_retx_harq; - std::cout << std::left << std::setw(9) << iter->second.nof_success_retx_nom; - std::cout << std::left << std::setw(9) << iter->second.nof_unsupport_mimo; - std::cout << std::left << std::setw(9) << iter->second.nof_pinfo; - std::cout << std::left << std::setw(9) << iter->second.nof_other_mimo; - std::cout << std::endl; +void print_statistic_rnti(std::map::iterator iter, int num, std::string info) +{ + std::cout << std::left << std::setw(5) << num; + std::cout << std::left << std::setw(9) << iter->first; + std::cout << std::left << std::setw(12) << info; + std::cout << std::left << std::setw(9) << iter->second.nof_active; + std::cout << std::left << std::setw(9) << iter->second.nof_newtx; + std::cout << std::left << std::setw(9) << iter->second.nof_retx; + std::cout << std::left << std::setw(9) << iter->second.nof_success_mgs; + std::cout << std::left << std::setw(9) << iter->second.nof_success_retx_harq; + std::cout << std::left << std::setw(9) << iter->second.nof_success_retx_nom; + std::cout << std::left << std::setw(9) << iter->second.nof_unsupport_mimo; + std::cout << std::left << std::setw(9) << iter->second.nof_pinfo; + std::cout << std::left << std::setw(9) << iter->second.nof_other_mimo; + std::cout << std::endl; } -void print_header(){ - std::cout << std::left << std::setw(5) << "Num"; - std::cout << std::left << std::setw(9) << "RNTI"; +void print_header() +{ + std::cout << std::left << std::setw(5) << "Num"; + std::cout << std::left << std::setw(9) << "RNTI"; std::cout << std::left << std::setw(12) << "Table"; - std::cout << std::left << std::setw(9) << "Active"; - std::cout << std::left << std::setw(9) << "New TX"; - std::cout << std::left << std::setw(9) << "ReTX"; - std::cout << std::left << std::setw(9) << "Success"; - std::cout << std::left << std::setw(9) << "HARQ"; - std::cout << std::left << std::setw(9) << "Normal"; - std::cout << std::left << std::setw(9) << "W_MIMO"; - std::cout << std::left << std::setw(9) << "W_pinfor"; - std::cout << std::left << std::setw(9) << "Other "; + std::cout << std::left << std::setw(9) << "Active"; + std::cout << std::left << std::setw(9) << "New TX"; + std::cout << std::left << std::setw(9) << "ReTX"; + std::cout << std::left << std::setw(9) << "Success"; + std::cout << std::left << std::setw(9) << "HARQ"; + std::cout << std::left << std::setw(9) << "Normal"; + std::cout << std::left << std::setw(9) << "W_MIMO"; + std::cout << std::left << std::setw(9) << "W_pinfor"; + std::cout << std::left << std::setw(9) << "Other "; std::cout << std::endl; } -void MCSTracking::print_database_dl(){ +void MCSTracking::print_database_dl() +{ std::unique_lock trackinglock(tracking_mutex); std::map::iterator iter; int nof_64qam = 0; int nof_256qam = 0; - int nof_unknown = 0; + int nof_unknown = 0; int num = 1; - for (int i = 0; i < 104; i++){ + for (int i = 0; i < 104; i++) + { std::cout << "-"; - } + } std::cout << std::endl; print_header(); - for (int i = 0; i < 104; i++){ + for (int i = 0; i < 104; i++) + { std::cout << "-"; - } + } std::cout << std::endl; - for (iter = tracking_database_dl_mode.begin(); iter != tracking_database_dl_mode.end(); iter++){ - if (iter->second.mcs_table == DL_SNIFFER_64QAM_TABLE){ + for (iter = tracking_database_dl_mode.begin(); iter != tracking_database_dl_mode.end(); iter++) + { + if (iter->second.mcs_table == DL_SNIFFER_64QAM_TABLE) + { nof_64qam++; print_statistic_rnti(iter, num, "64QAM"); num++; } } - for (iter = tracking_database_dl_mode.begin(); iter != tracking_database_dl_mode.end(); iter++){ - if (iter->second.mcs_table == DL_SNIFFER_256QAM_TABLE){ + for (iter = tracking_database_dl_mode.begin(); iter != tracking_database_dl_mode.end(); iter++) + { + if (iter->second.mcs_table == DL_SNIFFER_256QAM_TABLE) + { print_statistic_rnti(iter, num, "256QAM"); nof_256qam++; num++; } } - for (int i = 0; i < 104; i++){ + for (int i = 0; i < 104; i++) + { std::cout << "-"; } std::cout << std::endl; print_header(); - for (iter = tracking_database_dl_mode.begin(); iter != tracking_database_dl_mode.end(); iter++){ - if (iter->second.mcs_table == DL_SNIFFER_UNKNOWN_TABLE){ + for (iter = tracking_database_dl_mode.begin(); iter != tracking_database_dl_mode.end(); iter++) + { + if (iter->second.mcs_table == DL_SNIFFER_UNKNOWN_TABLE) + { /*iter->second.nof_active > 0: some RNTIs have nof_active = 0 due to only obatained from rar message only, no other actives*/ - if ((iter->second.nof_unsupport_mimo == 0 && iter->second.nof_pinfo==0 && iter->second.nof_other_mimo==0 && iter->second.nof_active > 0)){ + if ((iter->second.nof_unsupport_mimo == 0 && iter->second.nof_pinfo == 0 && iter->second.nof_other_mimo == 0 && iter->second.nof_active > 0)) + { print_statistic_rnti(iter, num, "Unknown"); nof_unknown++; num++; @@ -877,147 +1057,165 @@ void MCSTracking::print_database_dl(){ } } - for (int i = 0; i < 104; i++){ + for (int i = 0; i < 104; i++) + { std::cout << "-"; - } + } std::cout << std::endl; - for (iter = tracking_database_dl_mode.begin(); iter != tracking_database_dl_mode.end(); iter++){ - if (iter->second.mcs_table == DL_SNIFFER_UNKNOWN_TABLE){ + for (iter = tracking_database_dl_mode.begin(); iter != tracking_database_dl_mode.end(); iter++) + { + if (iter->second.mcs_table == DL_SNIFFER_UNKNOWN_TABLE) + { /*iter->second.nof_active > 0: some RNTIs have nof_active = 0 due to only obatained from rar message only, no other actives*/ - if (!(iter->second.nof_unsupport_mimo == 0 && iter->second.nof_pinfo==0 && iter->second.nof_other_mimo==0) && iter->second.nof_active > 0){ + if (!(iter->second.nof_unsupport_mimo == 0 && iter->second.nof_pinfo == 0 && iter->second.nof_other_mimo == 0) && iter->second.nof_active > 0) + { print_statistic_rnti(iter, num, "Unknown"); nof_unknown++; num++; } } } - printf ("[256Tracking] Total: %d RNTIs are 64QAM table, %d RNTIs are 256QAM table, %d RNTIs are Unknown \n\n", - nof_64qam, nof_256qam, nof_unknown); + printf("[256Tracking] Total: %d RNTIs are 64QAM table, %d RNTIs are 256QAM table, %d RNTIs are Unknown \n\n", + nof_64qam, nof_256qam, nof_unknown); trackinglock.unlock(); } -void MCSTracking::print_all_database_dl(){ +void MCSTracking::print_all_database_dl() +{ std::unique_lock trackinglock(tracking_mutex); std::map::iterator iter; int nof_64qam = 0; int nof_256qam = 0; - int nof_unknown = 0; + int nof_unknown = 0; int num = 1; - for (int i = 0; i < 109; i++){ + for (int i = 0; i < 109; i++) + { std::cout << "-"; - } + } std::cout << std::endl; - std::cout << std::left << std::setw(5) << "Num"; - std::cout << std::left << std::setw(9) << "RNTI"; + std::cout << std::left << std::setw(5) << "Num"; + std::cout << std::left << std::setw(9) << "RNTI"; std::cout << std::left << std::setw(12) << "Table"; - std::cout << std::left << std::setw(9) << "Active"; - std::cout << RED << std::left << std::setw(9) << "New TX" << RESET; - std::cout << std::left << std::setw(9) << "ReTX"; + std::cout << std::left << std::setw(9) << "Active"; + std::cout << RED << std::left << std::setw(9) << "New TX" << RESET; + std::cout << std::left << std::setw(9) << "ReTX"; std::cout << BOLDGREEN << std::left << std::setw(13) << "Success" << RESET; - std::cout << std::left << std::setw(9) << "HARQ"; - std::cout << std::left << std::setw(9) << "Normal"; - std::cout << std::left << std::setw(9) << "W_MIMO"; - std::cout << std::left << std::setw(9) << "W_pinfor"; - std::cout << std::left << std::setw(9) << "Other "; + std::cout << std::left << std::setw(9) << "HARQ"; + std::cout << std::left << std::setw(9) << "Normal"; + std::cout << std::left << std::setw(9) << "W_MIMO"; + std::cout << std::left << std::setw(9) << "W_pinfor"; + std::cout << std::left << std::setw(9) << "Other "; std::cout << std::endl; - for (int i = 0; i < 109; i++){ + for (int i = 0; i < 109; i++) + { std::cout << "-"; - } + } std::cout << std::endl; - for (iter = all_database_dl_mode.begin(); iter != all_database_dl_mode.end(); iter++){ - if (iter->second.mcs_table == DL_SNIFFER_64QAM_TABLE){ + for (iter = all_database_dl_mode.begin(); iter != all_database_dl_mode.end(); iter++) + { + if (iter->second.mcs_table == DL_SNIFFER_64QAM_TABLE) + { nof_64qam++; std::cout << std::left << std::setw(5) << num; std::cout << std::left << std::setw(9) << iter->first; - std::cout << std::left << std::setw(12)<< "64QAM"; - std::cout << std::left << std::setw(9) << iter->second.nof_active ; - std::cout << RED << std::left << std::setw(9) << iter->second.nof_newtx << RESET; + std::cout << std::left << std::setw(12) << "64QAM"; + std::cout << std::left << std::setw(9) << iter->second.nof_active; + std::cout << RED << std::left << std::setw(9) << iter->second.nof_newtx << RESET; std::cout << std::left << std::setw(9) << iter->second.nof_retx; int sc_percent = 0; - if (iter->second.nof_newtx > 0){ - sc_percent = std::roundf(((float)iter->second.nof_success_mgs/(float)iter->second.nof_active)*100); + if (iter->second.nof_newtx > 0) + { + sc_percent = std::roundf(((float)iter->second.nof_success_mgs / (float)iter->second.nof_active) * 100); } - std::string sc_pc_str =std::to_string(iter->second.nof_success_mgs) + '(' + std::to_string(sc_percent) + "%)"; + std::string sc_pc_str = std::to_string(iter->second.nof_success_mgs) + '(' + std::to_string(sc_percent) + "%)"; std::cout << BOLDGREEN << std::left << std::setw(13) << sc_pc_str << RESET; - std::cout << std::left << std::setw(9) << iter->second.nof_success_retx_harq; - std::cout << std::left << std::setw(9) << iter->second.nof_success_retx_nom; - std::cout << std::left << std::setw(9) << iter->second.nof_unsupport_mimo; - std::cout << std::left << std::setw(9) << iter->second.nof_pinfo; - std::cout << std::left << std::setw(9) << iter->second.nof_other_mimo; + std::cout << std::left << std::setw(9) << iter->second.nof_success_retx_harq; + std::cout << std::left << std::setw(9) << iter->second.nof_success_retx_nom; + std::cout << std::left << std::setw(9) << iter->second.nof_unsupport_mimo; + std::cout << std::left << std::setw(9) << iter->second.nof_pinfo; + std::cout << std::left << std::setw(9) << iter->second.nof_other_mimo; std::cout << std::endl; num++; write_csv_file(iter->first, iter->second, iter->second.mcs_table); } } - for (iter = all_database_dl_mode.begin(); iter != all_database_dl_mode.end(); iter++){ - if (iter->second.mcs_table == DL_SNIFFER_256QAM_TABLE){ + for (iter = all_database_dl_mode.begin(); iter != all_database_dl_mode.end(); iter++) + { + if (iter->second.mcs_table == DL_SNIFFER_256QAM_TABLE) + { std::cout << std::left << std::setw(5) << num; std::cout << std::left << std::setw(9) << iter->first; std::cout << std::left << std::setw(12) << "256QAM"; - std::cout << std::left << std::setw(9) << iter->second.nof_active ; - std::cout << RED << std::left << std::setw(9) << iter->second.nof_newtx << RESET; + std::cout << std::left << std::setw(9) << iter->second.nof_active; + std::cout << RED << std::left << std::setw(9) << iter->second.nof_newtx << RESET; std::cout << std::left << std::setw(9) << iter->second.nof_retx; int sc_percent = 0; - if (iter->second.nof_newtx > 0){ - sc_percent = std::roundf(((float)iter->second.nof_success_mgs/(float)iter->second.nof_active)*100); + if (iter->second.nof_newtx > 0) + { + sc_percent = std::roundf(((float)iter->second.nof_success_mgs / (float)iter->second.nof_active) * 100); } - std::string sc_pc_str =std::to_string(iter->second.nof_success_mgs) + '(' + std::to_string(sc_percent) + "%)"; + std::string sc_pc_str = std::to_string(iter->second.nof_success_mgs) + '(' + std::to_string(sc_percent) + "%)"; std::cout << BOLDGREEN << std::left << std::setw(13) << sc_pc_str << RESET; - std::cout << std::left << std::setw(9) << iter->second.nof_success_retx_harq; - std::cout << std::left << std::setw(9) << iter->second.nof_success_retx_nom; - std::cout << std::left << std::setw(9) << iter->second.nof_unsupport_mimo; - std::cout << std::left << std::setw(9) << iter->second.nof_pinfo; - std::cout << std::left << std::setw(9) << iter->second.nof_other_mimo; + std::cout << std::left << std::setw(9) << iter->second.nof_success_retx_harq; + std::cout << std::left << std::setw(9) << iter->second.nof_success_retx_nom; + std::cout << std::left << std::setw(9) << iter->second.nof_unsupport_mimo; + std::cout << std::left << std::setw(9) << iter->second.nof_pinfo; + std::cout << std::left << std::setw(9) << iter->second.nof_other_mimo; std::cout << std::endl; nof_256qam++; num++; write_csv_file(iter->first, iter->second, iter->second.mcs_table); } } - for (int i = 0; i < 109; i++){ + for (int i = 0; i < 109; i++) + { std::cout << "-"; } std::cout << std::endl; - std::cout << std::left << std::setw(5) << "Num "; - std::cout << std::left << std::setw(9) << "RNTI"; + std::cout << std::left << std::setw(5) << "Num "; + std::cout << std::left << std::setw(9) << "RNTI"; std::cout << std::left << std::setw(12) << "Table"; - std::cout << std::left << std::setw(9) << "Active"; - std::cout << RED << std::left << std::setw(9) << "New TX" << RESET; - std::cout << std::left << std::setw(9) << "ReTX"; + std::cout << std::left << std::setw(9) << "Active"; + std::cout << RED << std::left << std::setw(9) << "New TX" << RESET; + std::cout << std::left << std::setw(9) << "ReTX"; std::cout << BOLDGREEN << std::left << std::setw(13) << "Success" << RESET; - std::cout << std::left << std::setw(9) << "HARQ"; - std::cout << std::left << std::setw(9) << "Normal"; - std::cout << std::left << std::setw(9) << "W_MIMO"; - std::cout << std::left << std::setw(9) << "W_pinfor"; - std::cout << std::left << std::setw(9) << "Other"; + std::cout << std::left << std::setw(9) << "HARQ"; + std::cout << std::left << std::setw(9) << "Normal"; + std::cout << std::left << std::setw(9) << "W_MIMO"; + std::cout << std::left << std::setw(9) << "W_pinfor"; + std::cout << std::left << std::setw(9) << "Other"; std::cout << std::endl; - for (iter = all_database_dl_mode.begin(); iter != all_database_dl_mode.end(); iter++){ - if (iter->second.mcs_table == DL_SNIFFER_UNKNOWN_TABLE){ - if ((iter->second.nof_unsupport_mimo == 0 && iter->second.nof_pinfo==0 && iter->second.nof_other_mimo==0 && iter->second.nof_active > 0)){ + for (iter = all_database_dl_mode.begin(); iter != all_database_dl_mode.end(); iter++) + { + if (iter->second.mcs_table == DL_SNIFFER_UNKNOWN_TABLE) + { + if ((iter->second.nof_unsupport_mimo == 0 && iter->second.nof_pinfo == 0 && iter->second.nof_other_mimo == 0 && iter->second.nof_active > 0)) + { std::cout << std::left << std::setw(5) << num; std::cout << std::left << std::setw(9) << iter->first; std::cout << std::left << std::setw(12) << "Unknown"; - std::cout << std::left << std::setw(9) << iter->second.nof_active ; - std::cout << RED << std::left << std::setw(9) << iter->second.nof_newtx << RESET; + std::cout << std::left << std::setw(9) << iter->second.nof_active; + std::cout << RED << std::left << std::setw(9) << iter->second.nof_newtx << RESET; std::cout << std::left << std::setw(9) << iter->second.nof_retx; int sc_percent = 0; - if (iter->second.nof_newtx > 0){ - sc_percent = std::roundf(((float)iter->second.nof_success_mgs/(float)iter->second.nof_active)*100); + if (iter->second.nof_newtx > 0) + { + sc_percent = std::roundf(((float)iter->second.nof_success_mgs / (float)iter->second.nof_active) * 100); } - std::string sc_pc_str =std::to_string(iter->second.nof_success_mgs) + '(' + std::to_string(sc_percent) + "%)"; + std::string sc_pc_str = std::to_string(iter->second.nof_success_mgs) + '(' + std::to_string(sc_percent) + "%)"; std::cout << BOLDGREEN << std::left << std::setw(13) << sc_pc_str << RESET; - std::cout << std::left << std::setw(9) << iter->second.nof_success_retx_harq; - std::cout << std::left << std::setw(9) << iter->second.nof_success_retx_nom; - std::cout << std::left << std::setw(9) << iter->second.nof_unsupport_mimo; - std::cout << std::left << std::setw(9) << iter->second.nof_pinfo; - std::cout << std::left << std::setw(9) << iter->second.nof_other_mimo; + std::cout << std::left << std::setw(9) << iter->second.nof_success_retx_harq; + std::cout << std::left << std::setw(9) << iter->second.nof_success_retx_nom; + std::cout << std::left << std::setw(9) << iter->second.nof_unsupport_mimo; + std::cout << std::left << std::setw(9) << iter->second.nof_pinfo; + std::cout << std::left << std::setw(9) << iter->second.nof_other_mimo; std::cout << std::endl; nof_unknown++; num++; @@ -1026,133 +1224,180 @@ void MCSTracking::print_all_database_dl(){ } } - for (int i = 0; i < 109; i++){ + for (int i = 0; i < 109; i++) + { std::cout << "-"; - } + } std::cout << std::endl; - for (iter = all_database_dl_mode.begin(); iter != all_database_dl_mode.end(); iter++){ - if (iter->second.mcs_table == DL_SNIFFER_UNKNOWN_TABLE){ - if ((iter->second.nof_active > 0) && !(iter->second.nof_unsupport_mimo == 0&&iter->second.nof_pinfo==0&&iter->second.nof_other_mimo==0)){ + for (iter = all_database_dl_mode.begin(); iter != all_database_dl_mode.end(); iter++) + { + if (iter->second.mcs_table == DL_SNIFFER_UNKNOWN_TABLE) + { + if ((iter->second.nof_active > 0) && !(iter->second.nof_unsupport_mimo == 0 && iter->second.nof_pinfo == 0 && iter->second.nof_other_mimo == 0)) + { std::cout << std::left << std::setw(5) << num; std::cout << std::left << std::setw(9) << iter->first; std::cout << std::left << std::setw(12) << "Unknown"; - std::cout << std::left << std::setw(9) << iter->second.nof_active ; - std::cout << RED << std::left << std::setw(9) << iter->second.nof_newtx << RESET; + std::cout << std::left << std::setw(9) << iter->second.nof_active; + std::cout << RED << std::left << std::setw(9) << iter->second.nof_newtx << RESET; std::cout << std::left << std::setw(9) << iter->second.nof_retx; int sc_percent = 0; - if (iter->second.nof_newtx > 0){ - sc_percent = std::roundf(((float)iter->second.nof_success_mgs/(float)iter->second.nof_active)*100); + if (iter->second.nof_newtx > 0) + { + sc_percent = std::roundf(((float)iter->second.nof_success_mgs / (float)iter->second.nof_active) * 100); } - std::string sc_pc_str =std::to_string(iter->second.nof_success_mgs) + '(' + std::to_string(sc_percent) + "%)"; + std::string sc_pc_str = std::to_string(iter->second.nof_success_mgs) + '(' + std::to_string(sc_percent) + "%)"; std::cout << BOLDGREEN << std::left << std::setw(13) << sc_pc_str << RESET; - std::cout << std::left << std::setw(9) << iter->second.nof_success_retx_harq; - std::cout << std::left << std::setw(9) << iter->second.nof_success_retx_nom; - std::cout << std::left << std::setw(9) << iter->second.nof_unsupport_mimo; - std::cout << std::left << std::setw(9) << iter->second.nof_pinfo; - std::cout << std::left << std::setw(9) << iter->second.nof_other_mimo; + std::cout << std::left << std::setw(9) << iter->second.nof_success_retx_harq; + std::cout << std::left << std::setw(9) << iter->second.nof_success_retx_nom; + std::cout << std::left << std::setw(9) << iter->second.nof_unsupport_mimo; + std::cout << std::left << std::setw(9) << iter->second.nof_pinfo; + std::cout << std::left << std::setw(9) << iter->second.nof_other_mimo; std::cout << std::endl; nof_unknown++; num++; } } } - printf ("[256Tracking] Total: %d RNTIs are 64QAM table, %d RNTIs are 256QAM table, %d RNTIs are Unknown \n\n", - nof_64qam, nof_256qam, nof_unknown); - + printf("[256Tracking] Total: %d RNTIs are 64QAM table, %d RNTIs are 256QAM table, %d RNTIs are Unknown \n\n", + nof_64qam, nof_256qam, nof_unknown); + trackinglock.unlock(); } void MCSTracking::update_statistic_dl(uint16_t RNTI, - bool tb_en[SRSRAN_MAX_CODEWORDS], - int transmission_type[SRSRAN_MAX_CODEWORDS], - bool success[SRSRAN_MAX_CODEWORDS], - DL_Sniffer_DCI_DL &decoding_mem, - int mimo_ret, - srsran_pdsch_grant_t *statistic_grant) + bool tb_en[SRSRAN_MAX_CODEWORDS], + int transmission_type[SRSRAN_MAX_CODEWORDS], + bool success[SRSRAN_MAX_CODEWORDS], + DL_Sniffer_DCI_DL &decoding_mem, + int mimo_ret, + srsran_pdsch_grant_t *statistic_grant) { std::unique_lock trackinglock(tracking_mutex); std::map::iterator iter; iter = tracking_database_dl_mode.find(RNTI); - if (iter == tracking_database_dl_mode.end()){ - add_RNTI_dl(RNTI, DL_SNIFFER_UNKNOWN_TABLE); + if (iter == tracking_database_dl_mode.end()) + { + add_RNTI_dl(RNTI, DL_SNIFFER_UNKNOWN_TABLE); } iter = tracking_database_dl_mode.find(RNTI); - if (iter!= tracking_database_dl_mode.end()) + if (iter != tracking_database_dl_mode.end()) { /*Update number of messages with DCI > 1A after RAR*/ - if (decoding_mem.format > SRSRAN_DCI_FORMAT1A && iter->second.has_rar){ + if (decoding_mem.format > SRSRAN_DCI_FORMAT1A && iter->second.has_rar) + { iter->second.nof_msg_after_rar++; } - if (decoding_mem.mcs_table == DL_SNIFFER_64QAM_TABLE || decoding_mem.mcs_table == DL_SNIFFER_256QAM_TABLE){ - for (int i = 0; i < SRSRAN_MAX_CODEWORDS; i++){ - if (tb_en[i]){ + if (decoding_mem.mcs_table == DL_SNIFFER_64QAM_TABLE || decoding_mem.mcs_table == DL_SNIFFER_256QAM_TABLE) + { + for (int i = 0; i < SRSRAN_MAX_CODEWORDS; i++) + { + if (tb_en[i]) + { iter->second.nof_active++; } - if (tb_en[i] &&(transmission_type[i]==DL_SNIFFER_NEW_TX||transmission_type[i]==DL_SNIFFER_HARQ_FULL_BUFFER||transmission_type[i]==DL_SNIFFER_HARQ_BUSY)){ - if (statistic_grant->tb[i].mcs_idx <=28 && decoding_mem.mcs_table == DL_SNIFFER_64QAM_TABLE && harq_mode){ + if (tb_en[i] && (transmission_type[i] == DL_SNIFFER_NEW_TX || transmission_type[i] == DL_SNIFFER_HARQ_FULL_BUFFER || transmission_type[i] == DL_SNIFFER_HARQ_BUSY)) + { + if (statistic_grant->tb[i].mcs_idx <= 28 && decoding_mem.mcs_table == DL_SNIFFER_64QAM_TABLE && harq_mode) + { iter->second.nof_newtx++; - } else if (statistic_grant->tb[i].mcs_idx <=27 && decoding_mem.mcs_table == DL_SNIFFER_256QAM_TABLE && harq_mode){ + } + else if (statistic_grant->tb[i].mcs_idx <= 27 && decoding_mem.mcs_table == DL_SNIFFER_256QAM_TABLE && harq_mode) + { iter->second.nof_newtx++; - } else if (!harq_mode){ + } + else if (!harq_mode) + { iter->second.nof_newtx++; } - } else if (tb_en[i] &&(transmission_type[i]==DL_SNIFFER_RE_TX||transmission_type[i]==DL_SNIFFER_DECODED || \ - (statistic_grant->tb[i].mcs_idx > 28 && decoding_mem.mcs_table == DL_SNIFFER_64QAM_TABLE) || \ - (statistic_grant->tb[i].mcs_idx > 27 && decoding_mem.mcs_table == DL_SNIFFER_256QAM_TABLE))){ + } + else if (tb_en[i] && (transmission_type[i] == DL_SNIFFER_RE_TX || transmission_type[i] == DL_SNIFFER_DECODED || + (statistic_grant->tb[i].mcs_idx > 28 && decoding_mem.mcs_table == DL_SNIFFER_64QAM_TABLE) || + (statistic_grant->tb[i].mcs_idx > 27 && decoding_mem.mcs_table == DL_SNIFFER_256QAM_TABLE))) + { iter->second.nof_retx++; } - if (success[i]){ + if (success[i]) + { iter->second.nof_success_mgs++; - if (transmission_type[i]==DL_SNIFFER_RE_TX){ + if (transmission_type[i] == DL_SNIFFER_RE_TX) + { iter->second.nof_success_retx_harq++; } } - if (transmission_type[i]==DL_SNIFFER_DECODED && success[i] == false){ + if (transmission_type[i] == DL_SNIFFER_DECODED && success[i] == false) + { iter->second.nof_success_mgs++; } - if ((success[i]&&transmission_type[i]==DL_SNIFFER_RE_TX)||(transmission_type[i]==DL_SNIFFER_DECODED)){ + if ((success[i] && transmission_type[i] == DL_SNIFFER_RE_TX) || (transmission_type[i] == DL_SNIFFER_DECODED)) + { iter->second.nof_success_retx++; } - if (transmission_type[i]==DL_SNIFFER_DECODED){ + if (transmission_type[i] == DL_SNIFFER_DECODED) + { iter->second.nof_success_retx_nom++; } - if (mimo_ret == DL_SNIFFER_MIMO_NOT_SUPPORT && tb_en[i]){ + if (mimo_ret == DL_SNIFFER_MIMO_NOT_SUPPORT && tb_en[i]) + { iter->second.nof_unsupport_mimo++; - } else if(mimo_ret == DL_SNIFFER_PMI_WRONG && tb_en[i]){ + } + else if (mimo_ret == DL_SNIFFER_PMI_WRONG && tb_en[i]) + { iter->second.nof_pinfo++; - } else if (mimo_ret == DL_SNIFFER_LAYER_WRONG && tb_en[i]){ + } + else if (mimo_ret == DL_SNIFFER_LAYER_WRONG && tb_en[i]) + { iter->second.nof_other_mimo++; } } - } else if (decoding_mem.mcs_table == DL_SNIFFER_UNKNOWN_TABLE){ - for (int i = 0; i < SRSRAN_MAX_CODEWORDS; i++){ - if (tb_en[i]){ + } + else if (decoding_mem.mcs_table == DL_SNIFFER_UNKNOWN_TABLE) + { + for (int i = 0; i < SRSRAN_MAX_CODEWORDS; i++) + { + if (tb_en[i]) + { iter->second.nof_active++; iter->second.nof_newtx++; } - if (success[i]){ + if (success[i]) + { iter->second.nof_success_mgs++; } - if (mimo_ret == DL_SNIFFER_MIMO_NOT_SUPPORT && tb_en[i]){ + if (mimo_ret == DL_SNIFFER_MIMO_NOT_SUPPORT && tb_en[i]) + { iter->second.nof_unsupport_mimo++; - } else if(mimo_ret == DL_SNIFFER_PMI_WRONG && tb_en[i]){ + } + else if (mimo_ret == DL_SNIFFER_PMI_WRONG && tb_en[i]) + { iter->second.nof_pinfo++; - } else if (mimo_ret == DL_SNIFFER_LAYER_WRONG && tb_en[i]){ + } + else if (mimo_ret == DL_SNIFFER_LAYER_WRONG && tb_en[i]) + { iter->second.nof_other_mimo++; } } } - for (int mcs_idx = 0; mcs_idx < DL_SNIFFER_NOF_MCS; mcs_idx++){ - for (int cw = 0; cw < SRSRAN_MAX_CODEWORDS; cw++){ - if (tb_en[cw]){ - if (statistic_grant->tb[cw].mcs_idx == mcs_idx){ + for (int mcs_idx = 0; mcs_idx < DL_SNIFFER_NOF_MCS; mcs_idx++) + { + for (int cw = 0; cw < SRSRAN_MAX_CODEWORDS; cw++) + { + if (tb_en[cw]) + { + if (statistic_grant->tb[cw].mcs_idx == mcs_idx) + { iter->second.mcs[mcs_idx]++; - if (success[cw]) {iter->second.mcs_sc[mcs_idx]++;} - if (!success[cw] && transmission_type[cw] == DL_SNIFFER_DECODED) {iter->second.mcs_sc[mcs_idx]++;} + if (success[cw]) + { + iter->second.mcs_sc[mcs_idx]++; + } + if (!success[cw] && transmission_type[cw] == DL_SNIFFER_DECODED) + { + iter->second.mcs_sc[mcs_idx]++; + } } - } } } @@ -1160,27 +1405,35 @@ void MCSTracking::update_statistic_dl(uint16_t RNTI, trackinglock.unlock(); } - -bool MCSTracking::get_debug_mode(){ +bool MCSTracking::get_debug_mode() +{ std::unique_lock trackingLock(tracking_mutex); return en_debug; } -void MCSTracking::write_csv_file(uint16_t rnti, dl_sniffer_mcs_tracking_t &statistic, int table){ +void MCSTracking::write_csv_file(uint16_t rnti, dl_sniffer_mcs_tracking_t &statistic, int table) +{ std::string table_str; - if (table == DL_SNIFFER_64QAM_TABLE){ + if (table == DL_SNIFFER_64QAM_TABLE) + { table_str = "64QAM"; - } else if (table == DL_SNIFFER_256QAM_TABLE){ + } + else if (table == DL_SNIFFER_256QAM_TABLE) + { table_str = "256QAM"; - } else if (table == UL_SNIFFER_UNKNOWN_MOD){ + } + else if (table == UL_SNIFFER_UNKNOWN_MOD) + { table_str = "Unknown"; } - int sc_percent = std::roundf(((float)statistic.nof_success_mgs/(float)statistic.nof_newtx)*100); + int sc_percent = std::roundf(((float)statistic.nof_success_mgs / (float)statistic.nof_newtx) * 100); csv_file << rnti << ',' << table_str << ',' << statistic.nof_newtx << ',' << statistic.nof_success_mgs << ',' << sc_percent << ','; - for (int mcs_idx = 0; mcs_idx < DL_SNIFFER_NOF_MCS; mcs_idx++){ + for (int mcs_idx = 0; mcs_idx < DL_SNIFFER_NOF_MCS; mcs_idx++) + { int sc_percent = 0; - if(statistic.mcs[mcs_idx]>0){ - sc_percent = std::roundf(((float)statistic.mcs_sc[mcs_idx]/(float)statistic.mcs[mcs_idx])*100); + if (statistic.mcs[mcs_idx] > 0) + { + sc_percent = std::roundf(((float)statistic.mcs_sc[mcs_idx] / (float)statistic.mcs[mcs_idx]) * 100); } std::string mcs_sc_str = std::to_string(statistic.mcs_sc[mcs_idx]) + '/' + std::to_string(statistic.mcs[mcs_idx]) + '=' + std::to_string(sc_percent) + '%'; csv_file << mcs_sc_str << ','; @@ -1190,24 +1443,34 @@ void MCSTracking::write_csv_file(uint16_t rnti, dl_sniffer_mcs_tracking_t &stati /*__________________Manage UE Specific Configuation___________________*/ -void MCSTracking::update_ue_config_rnti(uint16_t rnti, ltesniffer_ue_spec_config_t ue_spec_config){ +void MCSTracking::update_ue_config_rnti(uint16_t rnti, ltesniffer_ue_spec_config_t ue_spec_config) +{ std::unique_lock trackinglock(tracking_mutex); - if (sniffer_mode == DL_MODE){ + if (sniffer_mode == DL_MODE) + { std::map::iterator dl_iter; dl_iter = tracking_database_dl_mode.find(rnti); - if (dl_iter != tracking_database_dl_mode.end()){ + if (dl_iter != tracking_database_dl_mode.end()) + { dl_iter->second.ue_spec_config = ue_spec_config; - }else{ + } + else + { add_RNTI_dl(rnti, DL_SNIFFER_UNKNOWN_TABLE); dl_iter = tracking_database_dl_mode.find(rnti); dl_iter->second.ue_spec_config = ue_spec_config; } - }else if (sniffer_mode == UL_MODE){ + } + else if (sniffer_mode == UL_MODE) + { std::map::iterator ul_iter; ul_iter = tracking_database_ul_mode.find(rnti); - if (ul_iter != tracking_database_ul_mode.end()){ + if (ul_iter != tracking_database_ul_mode.end()) + { ul_iter->second.ue_spec_config = ue_spec_config; - }else{ + } + else + { add_RNTI_ul(rnti, UL_SNIFFER_UNKNOWN_MOD); ul_iter = tracking_database_ul_mode.find(rnti); ul_iter->second.ue_spec_config = ue_spec_config; @@ -1216,49 +1479,61 @@ void MCSTracking::update_ue_config_rnti(uint16_t rnti, ltesniffer_ue_spec_config trackinglock.unlock(); } -ltesniffer_ue_spec_config_t MCSTracking::get_ue_config_rnti(uint16_t rnti){ +ltesniffer_ue_spec_config_t MCSTracking::get_ue_config_rnti(uint16_t rnti) +{ std::unique_lock trackinglock(tracking_mutex); ltesniffer_ue_spec_config_t ue_spec_config = {}; ue_spec_config = default_ue_spec_config; ue_spec_config.has_ue_config = false; - if (sniffer_mode == DL_MODE){ + if (sniffer_mode == DL_MODE) + { std::map::iterator dl_iter; dl_iter = tracking_database_dl_mode.find(rnti); - if (dl_iter != tracking_database_dl_mode.end()){ + if (dl_iter != tracking_database_dl_mode.end()) + { ue_spec_config = dl_iter->second.ue_spec_config; - }else{ - //nothing } - }else if (sniffer_mode == UL_MODE){ + else + { + // nothing + } + } + else if (sniffer_mode == UL_MODE) + { std::map::iterator ul_iter; ul_iter = tracking_database_ul_mode.find(rnti); - if (ul_iter != tracking_database_ul_mode.end()){ + if (ul_iter != tracking_database_ul_mode.end()) + { ue_spec_config = ul_iter->second.ue_spec_config; - }else{ - //nothing + } + else + { + // nothing } } return ue_spec_config; trackinglock.unlock(); } -void MCSTracking::update_default_ue_config(ltesniffer_ue_spec_config_t ue_spec_config){ +void MCSTracking::update_default_ue_config(ltesniffer_ue_spec_config_t ue_spec_config) +{ std::unique_lock trackinglock(tracking_mutex); - // printf("[CONFIG] Set default UE-specific configuration: P_a = %.2f, UCI Config: %d %d %d, CQI Config: %d\n", - // ue_spec_config.p_a, - // ue_spec_config.uci_config.I_offset_ack, - // ue_spec_config.uci_config.I_offset_cqi, - // ue_spec_config.uci_config.I_offset_ri, + // printf("[CONFIG] Set default UE-specific configuration: P_a = %.2f, UCI Config: %d %d %d, CQI Config: %d\n", + // ue_spec_config.p_a, + // ue_spec_config.uci_config.I_offset_ack, + // ue_spec_config.uci_config.I_offset_cqi, + // ue_spec_config.uci_config.I_offset_ri, // ue_spec_config.cqi_config.type); default_ue_spec_config = ue_spec_config; trackinglock.unlock(); } -void MCSTracking::set_default_of_default_config(){ +void MCSTracking::set_default_of_default_config() +{ std::unique_lock trackinglock(tracking_mutex); - default_ue_spec_config.uci_config.I_offset_ack = 10; // KT + default_ue_spec_config.uci_config.I_offset_ack = 10; // KT default_ue_spec_config.uci_config.I_offset_cqi = 8; - default_ue_spec_config.uci_config.I_offset_ri = 11; + default_ue_spec_config.uci_config.I_offset_ri = 11; default_ue_spec_config.p_a = 0; default_ue_spec_config.cqi_config.type = SRSRAN_CQI_TYPE_SUBBAND_HL; trackinglock.unlock(); diff --git a/src/src/Phy.cc b/src/src/Phy.cc index 130a9e5..5c8e675 100644 --- a/src/src/Phy.cc +++ b/src/src/Phy.cc @@ -49,7 +49,7 @@ Phy::Phy(uint32_t nof_rx_antennas, std::shared_ptr tem_thread(new SnifferThread(avail, pending, *temp_return)); sniffer_thread.push_back(std::move(tem_thread)); } - for (auto i = 0; i< nof_workers; i++){ + for (auto i = 0; i < nof_workers; i++){ sniffer_thread.at(i)->run_thread(); } } diff --git a/src/src/SubframeWorker.cc b/src/src/SubframeWorker.cc index f431119..c8da7be 100644 --- a/src/src/SubframeWorker.cc +++ b/src/src/SubframeWorker.cc @@ -6,45 +6,44 @@ #include /* Buffers for PCH reception (not included in DL HARQ) */ -const static uint32_t pch_payload_buffer_sz = 8*1024; // cf. srsran: srsue/hdr/mac/mac.h +const static uint32_t pch_payload_buffer_sz = 8 * 1024; // cf. srsran: srsue/hdr/mac/mac.h SubframeWorker::SubframeWorker(uint32_t idx, uint32_t max_prb, - PhyCommon& common, - DCIMetaFormats& metaFormats, + PhyCommon &common, + DCIMetaFormats &metaFormats, LTESniffer_pcap_writer *pcapwriter, MCSTracking *mcs_tracking, HARQ *harq, int mcs_tracking_mode, int harq_mode, ULSchedule *ulsche, - int sniffer_mode): - sfb(common.nof_rx_antennas), - idx(idx), - max_prb(max_prb), - common(common), - metaFormats(metaFormats), - sf_idx(0), - sfn(0), - updateMetaFormats(false), - stats(), - pcapwriter(pcapwriter), - mcs_tracking(mcs_tracking), - harq(harq), - harq_mode(harq_mode), - mcs_tracking_mode(mcs_tracking_mode), - ulsche(ulsche), - pdschdecoder(), - puschdecoder(), - sniffer_mode(sniffer_mode), - filesink(), - est_cfo(mcs_tracking->get_est_cfo()) + int sniffer_mode) : sfb(common.nof_rx_antennas), + idx(idx), + max_prb(max_prb), + common(common), + metaFormats(metaFormats), + sf_idx(0), + sfn(0), + updateMetaFormats(false), + stats(), + pcapwriter(pcapwriter), + mcs_tracking(mcs_tracking), + harq(harq), + harq_mode(harq_mode), + mcs_tracking_mode(mcs_tracking_mode), + ulsche(ulsche), + pdschdecoder(), + puschdecoder(), + sniffer_mode(sniffer_mode), + filesink(), + est_cfo(mcs_tracking->get_est_cfo()) { /*Set UE-specific config for UL and DL Decoder, correct value will be set after sniffer decodes RRC Connection Setup*/ set_ue_dl_uecfg(&ue_dl_cfg); set_pdsch_uecfg(&ue_dl_cfg.cfg.pdsch); /*Create new ue_dl*/ - falcon_ue_dl.q = new srsran_ue_dl_t; + falcon_ue_dl.q = new srsran_ue_dl_t; switch (sniffer_mode) { @@ -58,26 +57,27 @@ SubframeWorker::SubframeWorker(uint32_t idx, /* Config for Downlink Sniffing function*/ srsran_ue_dl_init(falcon_ue_dl.q, sfb.sf_buffer, max_prb, 1); // only 1 antenna for DL in the UL Sniffer Mode /* PDSCH decoder (Downlink)*/ - pdschdecoder = new PDSCH_Decoder(idx, - pcapwriter, - mcs_tracking, - common.getRNTIManager(), - harq, - mcs_tracking_mode, - harq_mode, + pdschdecoder = new PDSCH_Decoder(idx, + pcapwriter, + mcs_tracking, + common.getRNTIManager(), + harq, + mcs_tracking_mode, + harq_mode, common.nof_rx_antennas); /* PUSCH decoder (Uplink)*/ - puschdecoder = new PUSCH_Decoder(enb_ul, - ul_sf, - ulsche, - sfb.sf_buffer, - sfb.sf_buffer_offset, - ul_cfg, - pcapwriter, - mcs_tracking, - mcs_tracking->get_debug_mode()); + puschdecoder = new PUSCH_Decoder(enb_ul, + ul_sf, + ulsche, + sfb.sf_buffer, + sfb.sf_buffer_offset, + ul_cfg, + pcapwriter, + mcs_tracking, + mcs_tracking->get_debug_mode()); /*Uplink enb init*/ - if (srsran_enb_ul_init(&enb_ul, sfb.sf_buffer[1], 110)) { //110 = max PRB + if (srsran_enb_ul_init(&enb_ul, sfb.sf_buffer[1], 110)) + { // 110 = max PRB ERROR("Error initiating ENB UL"); return; } @@ -89,38 +89,44 @@ SubframeWorker::SubframeWorker(uint32_t idx, srsran_filesink_init(&filesink, "ul_sample.raw", SRSRAN_COMPLEX_FLOAT_BIN); } -SubframeWorker::~SubframeWorker() { +SubframeWorker::~SubframeWorker() +{ srsran_ue_dl_free(falcon_ue_dl.q); delete pdschdecoder; pdschdecoder = nullptr; srsran_filesink_free(&filesink); } -bool SubframeWorker::setCell(srsran_cell_t cell) { - if (srsran_ue_dl_set_cell(falcon_ue_dl.q, cell)) { +bool SubframeWorker::setCell(srsran_cell_t cell) +{ + if (srsran_ue_dl_set_cell(falcon_ue_dl.q, cell)) + { return false; } return true; } -void SubframeWorker::prepare(uint32_t _sf_idx, uint32_t _sfn, bool updateMetaFormats, - srsran_dl_sf_cfg_t _dl_sf) +void SubframeWorker::prepare(uint32_t _sf_idx, uint32_t _sfn, bool updateMetaFormats, + srsran_dl_sf_cfg_t _dl_sf) { - this->sf_idx = _sf_idx; - this->sfn = _sfn; + this->sf_idx = _sf_idx; + this->sfn = _sfn; this->updateMetaFormats = updateMetaFormats; - dl_sf = _dl_sf; + dl_sf = _dl_sf; } uint16_t get_tti_ul_harq(uint16_t cur_tti) { - uint32_t temp_tti = cur_tti - 4; - if (temp_tti >= 0) { - return temp_tti; - } else { - temp_tti = temp_tti + 10240; - return temp_tti; - } + uint32_t temp_tti = cur_tti - 4; + if (temp_tti >= 0) + { + return temp_tti; + } + else + { + temp_tti = temp_tti + 10240; + return temp_tti; + } } // int update_rv(int old_rv){ @@ -133,21 +139,23 @@ uint16_t get_tti_ul_harq(uint16_t cur_tti) // } // } -void SubframeWorker::work(){ +void SubframeWorker::work() +{ std::string test_string = '[' + std::to_string(idx) + ']' + '[' + std::to_string(sfn) + '-' + std::to_string(sf_idx) + ']'; - //PrintLifetime worker_lifetime(test_string + " Subframe took: "); - uint32_t tti = sfn*10 + sf_idx; + // PrintLifetime worker_lifetime(test_string + " Subframe took: "); + uint32_t tti = sfn * 10 + sf_idx; ul_sf.tti = tti; - if(updateMetaFormats) { + if (updateMetaFormats) + { metaFormats.update_formats(); } - - SubframeInfo subframeInfo(falcon_ue_dl.q->cell, //contain Subframe power and DCI collection only - mcs_tracking_mode, - mcs_tracking, - harq_mode, + + SubframeInfo subframeInfo(falcon_ue_dl.q->cell, // contain Subframe power and DCI collection only + mcs_tracking_mode, + mcs_tracking, + harq_mode, harq, - ulsche); + ulsche); DCISearch dciSearch(falcon_ue_dl, metaFormats, common.getRNTIManager(), @@ -155,31 +163,37 @@ void SubframeWorker::work(){ sf_idx, sfn, &dl_sf, &ue_dl_cfg); dciSearch.setShortcutDiscovery(common.getShortcutDiscovery()); - + int snr_ret = SRSRAN_SUCCESS; switch (sniffer_mode) { case DL_MODE: snr_ret = dciSearch.search(); - if (snr_ret == SRSRAN_SUCCESS){ // only decode when SNR > 5 dB - stats += dciSearch.getStats(); // worker-specific statistics - common.addStats(dciSearch.getStats()); // common statistics + if (snr_ret == SRSRAN_SUCCESS) + { // only decode when SNR > 5 dB + stats += dciSearch.getStats(); // worker-specific statistics + common.addStats(dciSearch.getStats()); // common statistics run_dl_mode(subframeInfo); - }else{ + } + else + { // printf("[SIGNAL] Bad signal quality... \n"); } break; case UL_MODE: - dciSearch.prepareDCISearch(); // set single antenna for DL in the UL Sniffer mode + dciSearch.prepareDCISearch(); // set single antenna for DL in the UL Sniffer mode snr_ret = dciSearch.search(); - if (snr_ret == SRSRAN_SUCCESS){ // only decode when SNR > 5 dB - stats += dciSearch.getStats(); // worker-specific statistics - common.addStats(dciSearch.getStats()); // common statistics + if (snr_ret == SRSRAN_SUCCESS) + { // only decode when SNR > 5 dB + stats += dciSearch.getStats(); // worker-specific statistics + common.addStats(dciSearch.getStats()); // common statistics subframeInfo.getSubframePower().computePower(enb_ul.sf_symbols); run_ul_mode(subframeInfo, tti); - }else{ - // printf("[SIGNAL] Bad signal quality... \n"); + } + else + { + // printf("[SIGNAL] Bad signal quality... \n"); } break; default: @@ -189,98 +203,114 @@ void SubframeWorker::work(){ est_cfo = falcon_ue_dl.q->chest_res.cfo; falcon_ue_dl.q->chest_res.cfo = 0; // common.consumeDCICollection(subframeInfo); //save DCI to file - //print_nof_DCI(subframeInfo, tti); + // print_nof_DCI(subframeInfo, tti); } -void SubframeWorker::printStats() { +void SubframeWorker::printStats() +{ stats.print(common.getStatsFile()); } -DCIBlindSearchStats& SubframeWorker::getStats() { +DCIBlindSearchStats &SubframeWorker::getStats() +{ return stats; } -cf_t* SubframeWorker::getBuffer(uint32_t antenna_idx) { +cf_t *SubframeWorker::getBuffer(uint32_t antenna_idx) +{ return sfb.sf_buffer[antenna_idx]; } -void SubframeWorker::run_dl_mode(SubframeInfo &subframeInfo){ - pdschdecoder->init_pdsch_decoder(&falcon_ue_dl, - &dl_sf, - &ue_dl_cfg, - &subframeInfo.getDCICollection().getDLSnifferDCI_DL(), - sfn, - sf_idx); +void SubframeWorker::run_dl_mode(SubframeInfo &subframeInfo) +{ + pdschdecoder->init_pdsch_decoder(&falcon_ue_dl, + &dl_sf, + &ue_dl_cfg, + &subframeInfo.getDCICollection().getDLSnifferDCI_DL(), + sfn, + sf_idx); /*Start decoding PDSCH*/ pdschdecoder->decode_dl_mode(); } -void SubframeWorker::run_ul_mode(SubframeInfo &subframeInfo, uint32_t tti){ - if (!ulsche->get_config()){ +void SubframeWorker::run_ul_mode(SubframeInfo &subframeInfo, uint32_t tti) +{ + if (!ulsche->get_config()) + { int sib_ret = SRSRAN_SUCCESS; - pdschdecoder->init_pdsch_decoder(&falcon_ue_dl, - &dl_sf, - &ue_dl_cfg, - &subframeInfo.getDCICollection().getDLSnifferDCI_DL(), - sfn, - sf_idx); + pdschdecoder->init_pdsch_decoder(&falcon_ue_dl, + &dl_sf, + &ue_dl_cfg, + &subframeInfo.getDCICollection().getDLSnifferDCI_DL(), + sfn, + sf_idx); sib_ret = pdschdecoder->decode_SIB(); - if (sib_ret == DL_SNIFFER_SIB2_SUCCESS){ + if (sib_ret == DL_SNIFFER_SIB2_SUCCESS) + { ulsche->set_SIB2(pdschdecoder->getSIB2()); ulsche->set_config(); } - } else { + } + else + { // decode uplink pusch - if (config == false){ - ul_cfg.dmrs = ulsche->get_dmrs();; - if (srsran_enb_ul_set_cell(&enb_ul, falcon_ue_dl.q->cell, &ul_cfg.dmrs, nullptr)) { + if (config == false) + { + ul_cfg.dmrs = ulsche->get_dmrs(); + ; + if (srsran_enb_ul_set_cell(&enb_ul, falcon_ue_dl.q->cell, &ul_cfg.dmrs, nullptr)) + { ERROR("Error set cell ENB UL"); return; } set_config(); - //init PUSCH decoder - //ul_cfg.hopping.hopping_enabled = true; - ul_cfg.hopping.hop_mode = srsran_pusch_hopping_cfg_t::SRSRAN_PUSCH_HOP_MODE_INTER_SF; + // init PUSCH decoder + // ul_cfg.hopping.hopping_enabled = true; + ul_cfg.hopping.hop_mode = srsran_pusch_hopping_cfg_t::SRSRAN_PUSCH_HOP_MODE_INTER_SF; ul_cfg.hopping.hopping_offset = ulsche->sib2.rr_cfg_common.pusch_cfg_common.pusch_cfg_basic.pusch_hop_offset; - ul_cfg.hopping.n_sb = ulsche->sib2.rr_cfg_common.pusch_cfg_common.pusch_cfg_basic.n_sb; - ul_cfg.hopping.n_rb_ho = ulsche->sib2.rr_cfg_common.pusch_cfg_common.pusch_cfg_basic.pusch_hop_offset;; + ul_cfg.hopping.n_sb = ulsche->sib2.rr_cfg_common.pusch_cfg_common.pusch_cfg_basic.n_sb; + ul_cfg.hopping.n_rb_ho = ulsche->sib2.rr_cfg_common.pusch_cfg_common.pusch_cfg_basic.pusch_hop_offset; + ; /*RAR decode hopping config to convert dci 0 to ul grant*/ - pdschdecoder->set_hopping(ul_cfg.hopping); + pdschdecoder->set_hopping(ul_cfg.hopping); /*RACH detector config*/ puschdecoder->set_rach_config(ulsche->get_prach_config()); puschdecoder->set_configed(); } - if (puschdecoder->get_configed()){ + if (puschdecoder->get_configed()) + { /*Decode DL messages but only TM1 as only having 1 antenna for DL*/ - pdschdecoder->init_pdsch_decoder(&falcon_ue_dl, - &dl_sf, - &ue_dl_cfg, - &subframeInfo.getDCICollection().getDLSnifferDCI_DL(), - sfn, - sf_idx); - + pdschdecoder->init_pdsch_decoder(&falcon_ue_dl, + &dl_sf, + &ue_dl_cfg, + &subframeInfo.getDCICollection().getDLSnifferDCI_DL(), + sfn, + sf_idx); + /*Create a vector to contain RAR decoding result*/ std::vector rar_result; int ret = pdschdecoder->decode_ul_mode(ulsche->get_rnti(), &rar_result); /*Get Uplink and Downlink dci and grant lists*/ - std::vector dci_ul = subframeInfo.getDCICollection().getULSnifferDCI_UL(); //get UL DCI0 list - std::vector dci_dl = subframeInfo.getDCICollection().getDLSnifferDCI_DL(); //get DL DCI list - - /*UL grant for RRC Connection Request is sent in RAR response (msg 2), + std::vector dci_ul = subframeInfo.getDCICollection().getULSnifferDCI_UL(); // get UL DCI0 list + std::vector dci_dl = subframeInfo.getDCICollection().getDLSnifferDCI_DL(); // get DL DCI list + + /*UL grant for RRC Connection Request is sent in RAR response (msg 2), / so convert UL grant from msg2 to general UL grant*/ std::vector rar_dci_ul_vector; - if (rar_result.size() > 0){ + if (rar_result.size() > 0) + { std::vector::iterator rar_iter; - for (rar_iter = rar_result.begin(); rar_iter!= rar_result.end(); rar_iter++){ - DCI_UL rar_dci_ul = {}; - rar_dci_ul.rnti = (*rar_iter).t_crnti; - *rar_dci_ul.ran_ul_dci.get() = (*rar_iter).ran_dci_ul; - *rar_dci_ul.ran_ul_grant.get() = (*rar_iter).ran_ul_grant; - rar_dci_ul.is_rar_gant = 1; + for (rar_iter = rar_result.begin(); rar_iter != rar_result.end(); rar_iter++) + { + DCI_UL rar_dci_ul = {}; + rar_dci_ul.rnti = (*rar_iter).t_crnti; + *rar_dci_ul.ran_ul_dci.get() = (*rar_iter).ran_dci_ul; + *rar_dci_ul.ran_ul_grant.get() = (*rar_iter).ran_ul_grant; + rar_dci_ul.is_rar_gant = 1; rar_dci_ul_vector.push_back(rar_dci_ul); } } @@ -288,12 +318,18 @@ void SubframeWorker::run_ul_mode(SubframeInfo &subframeInfo, uint32_t tti){ /*check nof_ack for uplink pusch decoder*/ std::vector::iterator iter_ul; std::vector::iterator iter_dl; - for (iter_ul = dci_ul.begin(); iter_ul!=dci_ul.end(); iter_ul++){ - for(iter_dl = dci_dl.begin(); iter_dl!=dci_dl.end(); iter_dl++){ - if (iter_ul->rnti == iter_dl->rnti){ - if (iter_dl->ran_pdsch_grant->nof_tb == 1){ + for (iter_ul = dci_ul.begin(); iter_ul != dci_ul.end(); iter_ul++) + { + for (iter_dl = dci_dl.begin(); iter_dl != dci_dl.end(); iter_dl++) + { + if (iter_ul->rnti == iter_dl->rnti) + { + if (iter_dl->ran_pdsch_grant->nof_tb == 1) + { iter_ul->nof_ack = 1; - } else if (iter_dl->ran_pdsch_grant->nof_tb == 2){ + } + else if (iter_dl->ran_pdsch_grant->nof_tb == 2) + { iter_ul->nof_ack = 2; } } @@ -304,69 +340,70 @@ void SubframeWorker::run_ul_mode(SubframeInfo &subframeInfo, uint32_t tti){ ulsche->pushULSche(tti, dci_ul); /*Push current RAR grant to database to decode 4ms later*/ ulsche->push_rar_ULSche(tti, rar_dci_ul_vector); - puschdecoder->init_pusch_decoder(ulsche->getULSche(tti), - ulsche->get_rar_ULSche(tti), - ul_sf, - &subframeInfo.getSubframePower()); - puschdecoder->decode(); //decode PUSCH - puschdecoder->work_prach(); //decode PRACH - ulsche->deleteULSche(tti); //delete current DCI0 list and uplink grant in the database after decoding - ulsche->delete_rar_ULSche(tti); //also for RAR grant + puschdecoder->init_pusch_decoder(ulsche->getULSche(tti), + ulsche->get_rar_ULSche(tti), + ul_sf, + &subframeInfo.getSubframePower()); + puschdecoder->decode(); // decode PUSCH + puschdecoder->work_prach(); // decode PRACH + ulsche->deleteULSche(tti); // delete current DCI0 list and uplink grant in the database after decoding + ulsche->delete_rar_ULSche(tti); // also for RAR grant } } } -void SubframeWorker::setup_default_ul_cfg(srsran_ul_cfg_t &ul_cfg){ +void SubframeWorker::setup_default_ul_cfg(srsran_ul_cfg_t &ul_cfg) +{ - ul_cfg.pusch.uci_offset.I_offset_ack = 10; + ul_cfg.pusch.uci_offset.I_offset_ack = 10; ul_cfg.pusch.uci_offset.I_offset_cqi = 8; - ul_cfg.pusch.uci_offset.I_offset_ri = 11; - + ul_cfg.pusch.uci_offset.I_offset_ri = 11; } -void SubframeWorker::set_pdsch_uecfg(srsran_pdsch_cfg_t* pdsch_cfg) +void SubframeWorker::set_pdsch_uecfg(srsran_pdsch_cfg_t *pdsch_cfg) { - pdsch_cfg->csi_enable = true; - pdsch_cfg->max_nof_iterations = 12; - pdsch_cfg->meas_evm_en = false; - pdsch_cfg->meas_time_en = false; - pdsch_cfg->power_scale = true; - pdsch_cfg->decoder_type = SRSRAN_MIMO_DECODER_MMSE; - pdsch_cfg->p_a = -3; - - pdsch_cfg->p_b = 1; - pdsch_cfg->rs_power = 0; + pdsch_cfg->csi_enable = true; + pdsch_cfg->max_nof_iterations = 12; + pdsch_cfg->meas_evm_en = false; + pdsch_cfg->meas_time_en = false; + pdsch_cfg->power_scale = true; + pdsch_cfg->decoder_type = SRSRAN_MIMO_DECODER_MMSE; + pdsch_cfg->p_a = -3; + + pdsch_cfg->p_b = 1; + pdsch_cfg->rs_power = 0; } -void SubframeWorker::set_ue_dl_uecfg(srsran_ue_dl_cfg_t* ue_dl_cfg) -{ +void SubframeWorker::set_ue_dl_uecfg(srsran_ue_dl_cfg_t *ue_dl_cfg) +{ /*Set config for channel estimation*/ - srsran_chest_dl_cfg_t* chest_cfg = &ue_dl_cfg->chest_cfg; + srsran_chest_dl_cfg_t *chest_cfg = &ue_dl_cfg->chest_cfg; bzero(chest_cfg, sizeof(srsran_chest_dl_cfg_t)); - chest_cfg->filter_coef[0] = 4; - chest_cfg->filter_coef[1] = 1; - chest_cfg->filter_type = SRSRAN_CHEST_FILTER_GAUSS; - chest_cfg->noise_alg = SRSRAN_NOISE_ALG_REFS; - chest_cfg->rsrp_neighbour = false; - chest_cfg->cfo_estimate_enable = true; + chest_cfg->filter_coef[0] = 4; + chest_cfg->filter_coef[1] = 1; + chest_cfg->filter_type = SRSRAN_CHEST_FILTER_GAUSS; + chest_cfg->noise_alg = SRSRAN_NOISE_ALG_REFS; + chest_cfg->rsrp_neighbour = false; + chest_cfg->cfo_estimate_enable = true; chest_cfg->cfo_estimate_sf_mask = 1023; - chest_cfg->sync_error_enable = false; - chest_cfg->estimator_alg = SRSRAN_ESTIMATOR_ALG_INTERPOLATE; // Change channel estimation algorithm - // SRSRAN_ESTIMATOR_ALG_WIENER = 2 - // SRSRAN_ESTIMATOR_ALG_INTERPOLATE = 1 - // SRSRAN_ESTIMATOR_ALG_AVERAGE = 0 + chest_cfg->sync_error_enable = false; + chest_cfg->estimator_alg = SRSRAN_ESTIMATOR_ALG_INTERPOLATE; // Change channel estimation algorithm + // SRSRAN_ESTIMATOR_ALG_WIENER = 2 + // SRSRAN_ESTIMATOR_ALG_INTERPOLATE = 1 + // SRSRAN_ESTIMATOR_ALG_AVERAGE = 0 /*Set config for DCI search, can config DCI for CA cases*/ ue_dl_cfg->cfg.dci.multiple_csi_request_enabled = false; - ue_dl_cfg->cfg.dci.cif_enabled = false; - ue_dl_cfg->cfg.dci.cif_present = false; - ue_dl_cfg->cfg.dci.is_not_ue_ss = false; - ue_dl_cfg->cfg.dci.ra_format_enabled = false; - ue_dl_cfg->cfg.dci.srs_request_enabled = false; + ue_dl_cfg->cfg.dci.cif_enabled = false; + ue_dl_cfg->cfg.dci.cif_present = false; + ue_dl_cfg->cfg.dci.is_not_ue_ss = false; + ue_dl_cfg->cfg.dci.ra_format_enabled = false; + ue_dl_cfg->cfg.dci.srs_request_enabled = false; } -void SubframeWorker::print_nof_DCI(SubframeInfo &subframeInfo, uint32_t tti){ +void SubframeWorker::print_nof_DCI(SubframeInfo &subframeInfo, uint32_t tti) +{ std::vector dl_dci_test = subframeInfo.getDCICollection().getDLSnifferDCI_DL(); int nof_dl_dci = dl_dci_test.size(); - std::vector dci_ul_test = subframeInfo.getDCICollection().getULSnifferDCI_UL(); + std::vector dci_ul_test = subframeInfo.getDCICollection().getULSnifferDCI_UL(); int nof_ul_dci = dci_ul_test.size(); auto now = std::chrono::system_clock::now(); auto micros = std::chrono::duration_cast(now.time_since_epoch()); @@ -378,5 +415,5 @@ void SubframeWorker::print_nof_DCI(SubframeInfo &subframeInfo, uint32_t tti){ << std::setw(6) << std::setfill('0') << micros.count() % 1000000; std::string time_str = ss.str(); - std::cout << time_str <<"," << tti << "," << nof_dci << std::endl; + std::cout << time_str << "," << tti << "," << nof_dci << std::endl; } \ No newline at end of file diff --git a/src/src/ULSchedule.cc b/src/src/ULSchedule.cc index 6a154d4..94238a8 100644 --- a/src/src/ULSchedule.cc +++ b/src/src/ULSchedule.cc @@ -1,31 +1,31 @@ #include "include/ULSchedule.h" -ULSchedule::ULSchedule(uint32_t rnti, UL_HARQ *ul_harq, bool en_debug): -rnti(rnti), -en_debug(en_debug) +ULSchedule::ULSchedule(uint32_t rnti, UL_HARQ *ul_harq, bool en_debug) : rnti(rnti), + en_debug(en_debug) { - } ULSchedule::~ULSchedule() { } -void ULSchedule::pushULSche(uint32_t tti,const std::vector& dci_ul) +void ULSchedule::pushULSche(uint32_t tti, const std::vector &dci_ul) { std::unique_lock lock(ulsche_mutex); /* Check if there is UL_DCI for this tti in the database*/ std::map>::iterator iter; iter = ulsche_database.find(tti); - if (iter != ulsche_database.end()){ + if (iter != ulsche_database.end()) + { iter->second.insert((*iter).second.end(), dci_ul.begin(), dci_ul.end()); } - else{ // if not create a new one + else + { // if not create a new one ulsche_database.insert(std::pair>(tti, dci_ul)); } lock.unlock(); } -void ULSchedule::push_rar_ULSche(uint32_t tti,const std::vector& rar_dci_ul) +void ULSchedule::push_rar_ULSche(uint32_t tti, const std::vector &rar_dci_ul) { std::unique_lock lock(ulsche_mutex); // std::vector cur_dci_ul; @@ -34,46 +34,53 @@ void ULSchedule::push_rar_ULSche(uint32_t tti,const std::vector& rar_dci lock.unlock(); } - -std::vector* ULSchedule::getULSche(uint32_t tti) +std::vector *ULSchedule::getULSche(uint32_t tti) { std::unique_lock lock(ulsche_mutex); uint32_t ul_tti = get_ul_tti(tti); std::map>::iterator iter; iter = ulsche_database.find(ul_tti); - if (iter != ulsche_database.end()){ + if (iter != ulsche_database.end()) + { return &iter->second; - } else { + } + else + { return nullptr; } lock.unlock(); } -std::vector* ULSchedule::get_rar_ULSche(uint32_t tti) +std::vector *ULSchedule::get_rar_ULSche(uint32_t tti) { std::unique_lock lock(ulsche_mutex); uint32_t ul_tti = get_rar_ul_tti(tti); std::map>::iterator iter; iter = ulsche_rar_database.find(ul_tti); - if (iter != ulsche_rar_database.end()){ + if (iter != ulsche_rar_database.end()) + { return &iter->second; - } else { + } + else + { return nullptr; } lock.unlock(); } - void ULSchedule::deleteULSche(uint32_t tti) { std::unique_lock lock(ulsche_mutex); std::map>::iterator iter; uint32_t ul_tti = get_ul_tti(tti); iter = ulsche_database.find(ul_tti); - if (iter != ulsche_database.end()){ + if (iter != ulsche_database.end()) + { ulsche_database.erase(iter); - } else { - //do nothing + } + else + { + // do nothing } lock.unlock(); } @@ -84,65 +91,78 @@ void ULSchedule::delete_rar_ULSche(uint32_t tti) std::map>::iterator iter; uint32_t ul_tti = get_rar_ul_tti(tti); iter = ulsche_rar_database.find(ul_tti); - if (iter != ulsche_rar_database.end()){ + if (iter != ulsche_rar_database.end()) + { ulsche_rar_database.erase(iter); - } else { - //do nothing + } + else + { + // do nothing } lock.unlock(); } -void ULSchedule::set_SIB2(asn1::rrc::sib_type2_s* sib2_) +void ULSchedule::set_SIB2(asn1::rrc::sib_type2_s *sib2_) { std::unique_lock lock(ulsche_mutex); sib2 = *sib2_; lock.unlock(); } -uint32_t ULSchedule::get_ul_tti(uint32_t cur_tti){ +uint32_t ULSchedule::get_ul_tti(uint32_t cur_tti) +{ uint32_t temp_tti = cur_tti - 4; - if (temp_tti >= 0) { + if (temp_tti >= 0) + { return temp_tti; - } else { + } + else + { temp_tti = temp_tti + 10240; return temp_tti; } } -uint32_t ULSchedule::get_rar_ul_tti(uint32_t cur_tti){ +uint32_t ULSchedule::get_rar_ul_tti(uint32_t cur_tti) +{ uint32_t temp_tti = cur_tti - 6; - if (temp_tti >= 0) { + if (temp_tti >= 0) + { return temp_tti; - } else { + } + else + { temp_tti = temp_tti + 10240; return temp_tti; } } -void ULSchedule::set_config() +void ULSchedule::set_config() { std::unique_lock lock(ulsche_mutex); - dmrs_cfg.cyclic_shift = sib2.rr_cfg_common.pusch_cfg_common.ul_ref_sigs_pusch.cyclic_shift; - dmrs_cfg.group_hopping_en = sib2.rr_cfg_common.pusch_cfg_common.ul_ref_sigs_pusch.group_hop_enabled; - dmrs_cfg.sequence_hopping_en = sib2.rr_cfg_common.pusch_cfg_common.ul_ref_sigs_pusch.seq_hop_enabled; - dmrs_cfg.delta_ss = sib2.rr_cfg_common.pusch_cfg_common.ul_ref_sigs_pusch.group_assign_pusch; + dmrs_cfg.cyclic_shift = sib2.rr_cfg_common.pusch_cfg_common.ul_ref_sigs_pusch.cyclic_shift; + dmrs_cfg.group_hopping_en = sib2.rr_cfg_common.pusch_cfg_common.ul_ref_sigs_pusch.group_hop_enabled; + dmrs_cfg.sequence_hopping_en = sib2.rr_cfg_common.pusch_cfg_common.ul_ref_sigs_pusch.seq_hop_enabled; + dmrs_cfg.delta_ss = sib2.rr_cfg_common.pusch_cfg_common.ul_ref_sigs_pusch.group_assign_pusch; /*set parch config*/ - prach_cfg.is_nr = false; - prach_cfg.root_seq_idx = sib2.rr_cfg_common.prach_cfg.root_seq_idx; - prach_cfg.config_idx = sib2.rr_cfg_common.prach_cfg.prach_cfg_info.prach_cfg_idx; - prach_cfg.hs_flag = sib2.rr_cfg_common.prach_cfg.prach_cfg_info.high_speed_flag; - prach_cfg.zero_corr_zone = sib2.rr_cfg_common.prach_cfg.prach_cfg_info.zero_correlation_zone_cfg; - prach_cfg.freq_offset = sib2.rr_cfg_common.prach_cfg.prach_cfg_info.prach_freq_offset; - - config = true; + prach_cfg.is_nr = false; + prach_cfg.root_seq_idx = sib2.rr_cfg_common.prach_cfg.root_seq_idx; + prach_cfg.config_idx = sib2.rr_cfg_common.prach_cfg.prach_cfg_info.prach_cfg_idx; + prach_cfg.hs_flag = sib2.rr_cfg_common.prach_cfg.prach_cfg_info.high_speed_flag; + prach_cfg.zero_corr_zone = sib2.rr_cfg_common.prach_cfg.prach_cfg_info.zero_correlation_zone_cfg; + prach_cfg.freq_offset = sib2.rr_cfg_common.prach_cfg.prach_cfg_info.prach_freq_offset; + + config = true; lock.unlock(); } -srsran_refsignal_dmrs_pusch_cfg_t ULSchedule::get_dmrs(){ +srsran_refsignal_dmrs_pusch_cfg_t ULSchedule::get_dmrs() +{ std::unique_lock lock(ulsche_mutex); - if (print_get_config){ - //printf("[CONFIG] Configuring DMRS for Subframe Workers \n"); + if (print_get_config) + { + // printf("[CONFIG] Configuring DMRS for Subframe Workers \n"); print_get_config = false; } return dmrs_cfg; @@ -164,7 +184,8 @@ void ULSchedule::clean_database(std::map::i iter->second.avg_success_database.clear(); } -void ULSchedule::set_rrc_con_set(asn1::rrc::rrc_conn_setup_r8_ies_s rrc_con_set_){ +void ULSchedule::set_rrc_con_set(asn1::rrc::rrc_conn_setup_r8_ies_s rrc_con_set_) +{ rrc_con_set = rrc_con_set_; has_rrc_con_set = true; } \ No newline at end of file diff --git a/src/src/UL_Sniffer_PUSCH.cc b/src/src/UL_Sniffer_PUSCH.cc index ea8dace..f18909b 100644 --- a/src/src/UL_Sniffer_PUSCH.cc +++ b/src/src/UL_Sniffer_PUSCH.cc @@ -1,35 +1,34 @@ #include "include/UL_Sniffer_PUSCH.h" -bool valid_prb_ul[101] = {true, true, true, true, true, true, true, false, true, true, true, false, true, - false, false, true, true, false, true, false, true, false, false, false, true, true, - false, true, false, false, true, false, true, false, false, false, true, false, false, - false, true, false, false, false, false, true, false, false, true, false, true, false, - false, false, true, false, false, false, false, false, true, false, false, false, true, - false, false, false, false, false, false, false, true, false, false, true, false, false, - false, false, true, true, false, false, false, false, false, false, false, false, true, - false, false, false, false, false, true, false, false, false, true}; +bool valid_prb_ul[101] = {true, true, true, true, true, true, true, false, true, true, true, false, true, + false, false, true, true, false, true, false, true, false, false, false, true, true, + false, true, false, false, true, false, true, false, false, false, true, false, false, + false, true, false, false, false, false, true, false, false, true, false, true, false, + false, false, true, false, false, false, false, false, true, false, false, false, true, + false, false, false, false, false, false, false, true, false, false, true, false, false, + false, false, true, true, false, false, false, false, false, false, false, false, true, + false, false, false, false, false, true, false, false, false, true}; PUSCH_Decoder::PUSCH_Decoder(srsran_enb_ul_t &enb_ul, srsran_ul_sf_cfg_t &ul_sf, ULSchedule *ulsche, - cf_t** original_buffer, - cf_t** buffer_offset, - srsran_ul_cfg_t &ul_cfg, + cf_t **original_buffer, + cf_t **buffer_offset, + srsran_ul_cfg_t &ul_cfg, LTESniffer_pcap_writer *pcapwriter, - MCSTracking *mcstracking, - bool en_debug): -enb_ul(enb_ul), -ul_sf(ul_sf), -dci_ul(), -ulsche(ulsche), -original_buffer(original_buffer), -buffer_offset(buffer_offset), -ul_cfg(ul_cfg), -pcapwriter(pcapwriter), -sf_power(), -mcstracking(mcstracking), -en_debug(en_debug) -{ + MCSTracking *mcstracking, + bool en_debug) : enb_ul(enb_ul), + ul_sf(ul_sf), + dci_ul(), + ulsche(ulsche), + original_buffer(original_buffer), + buffer_offset(buffer_offset), + ul_cfg(ul_cfg), + pcapwriter(pcapwriter), + sf_power(), + mcstracking(mcstracking), + en_debug(en_debug) +{ set_target_rnti(ulsche->get_rnti()); set_debug_mode(ulsche->get_debug_mode()); set_api_mode(mcstracking->get_api_mode()); @@ -45,39 +44,48 @@ PUSCH_Decoder::~PUSCH_Decoder() srsran_softbuffer_rx_free(ul_cfg.pusch.softbuffers.rx); } -int PUSCH_Decoder::decode_rrc_connection_request(DCI_UL &decoding_mem, uint8_t* sdu_ptr, int length){ +int PUSCH_Decoder::decode_rrc_connection_request(DCI_UL &decoding_mem, uint8_t *sdu_ptr, int length) +{ int ret = SRSRAN_ERROR; ul_ccch_msg_s ul_ccch_msg; asn1::cbit_ref bref(sdu_ptr, length); int asn1_result = ul_ccch_msg.unpack(bref); - if (asn1_result == asn1::SRSASN_SUCCESS && ul_ccch_msg.msg.type() == ul_ccch_msg_type_c::types_opts::c1){ - if (ul_ccch_msg.msg.c1().type().value == ul_ccch_msg_type_c::c1_c_::types::rrc_conn_request){ + if (asn1_result == asn1::SRSASN_SUCCESS && ul_ccch_msg.msg.type() == ul_ccch_msg_type_c::types_opts::c1) + { + if (ul_ccch_msg.msg.c1().type().value == ul_ccch_msg_type_c::c1_c_::types::rrc_conn_request) + { asn1::rrc::rrc_conn_request_s con_request = ul_ccch_msg.msg.c1().rrc_conn_request(); - rrc_conn_request_r8_ies_s* msg_r8 = &con_request.crit_exts.rrc_conn_request_r8(); - if (msg_r8->ue_id.type() == init_ue_id_c::types::s_tmsi) { - uint32_t m_tmsi = msg_r8->ue_id.s_tmsi().m_tmsi.to_number(); - uint8_t mmec = msg_r8->ue_id.s_tmsi().mmec.to_number(); + rrc_conn_request_r8_ies_s *msg_r8 = &con_request.crit_exts.rrc_conn_request_r8(); + if (msg_r8->ue_id.type() == init_ue_id_c::types::s_tmsi) + { + uint32_t m_tmsi = msg_r8->ue_id.s_tmsi().m_tmsi.to_number(); + uint8_t mmec = msg_r8->ue_id.s_tmsi().mmec.to_number(); std::stringstream ss; ss << std::hex << m_tmsi; std::string m_tmsi_str = ss.str(); print_api(ul_sf.tti, decoding_mem.rnti, ID_TMSI, m_tmsi_str, MSG_CON_REQ); mcstracking->increase_nof_api_msg(); ret = SRSRAN_SUCCESS; - } else if (msg_r8->ue_id.type() == init_ue_id_c::types::random_value){ + } + else if (msg_r8->ue_id.type() == init_ue_id_c::types::random_value) + { std::string rd_value_bitstream = msg_r8->ue_id.random_value().to_string(); std::stringstream ss; - for (int i = 0; i < rd_value_bitstream.length(); i += 4) { + for (int i = 0; i < rd_value_bitstream.length(); i += 4) + { std::string hex_str = rd_value_bitstream.substr(i, 4); int hex_value = stoi(hex_str, nullptr, 2); ss << std::hex << hex_value; } std::string random_value_str = ss.str(); - random_value_str = random_value_str.substr(2); + random_value_str = random_value_str.substr(2); print_api(ul_sf.tti, decoding_mem.rnti, ID_RAN_VAL, random_value_str, MSG_CON_REQ); mcstracking->increase_nof_api_msg(); ret = SRSRAN_SUCCESS; } - }else if (ul_ccch_msg.msg.c1().type().value == ul_ccch_msg_type_c::c1_c_::types::rrc_conn_reest_request){ + } + else if (ul_ccch_msg.msg.c1().type().value == ul_ccch_msg_type_c::c1_c_::types::rrc_conn_reest_request) + { // Do nothing } } @@ -85,42 +93,49 @@ int PUSCH_Decoder::decode_rrc_connection_request(DCI_UL &decoding_mem, uint8_t* } /*UEcapability information or RRC Connection Setup Complete + Attach request*/ -int PUSCH_Decoder::decode_ul_dcch(DCI_UL &decoding_mem, uint8_t* sdu_ptr, int length){ +int PUSCH_Decoder::decode_ul_dcch(DCI_UL &decoding_mem, uint8_t *sdu_ptr, int length) +{ int ret = SRSRAN_ERROR; ul_dcch_msg_s ul_dcch_msg; asn1::cbit_ref bref(sdu_ptr, length); int asn1_result = ul_dcch_msg.unpack(bref); - if (asn1_result == asn1::SRSASN_SUCCESS && ul_dcch_msg.msg.type() == ul_dcch_msg_type_c::types_opts::c1){ - if (ul_dcch_msg.msg.c1().type() == ul_dcch_msg_type_c::c1_c_::types::ue_cap_info && (api_mode == 1 || api_mode == 3)){ //&& UECapability - //printf("[API] SF: %d-%d, RNTI: %d, Found UECapabilityInformation messages \n", ul_sf.tti/10, ul_sf.tti%10, decoding_mem.rnti); - print_api(ul_sf.tti, decoding_mem.rnti, -1 , "-", MSG_UE_CAP); + if (asn1_result == asn1::SRSASN_SUCCESS && ul_dcch_msg.msg.type() == ul_dcch_msg_type_c::types_opts::c1) + { + if (ul_dcch_msg.msg.c1().type() == ul_dcch_msg_type_c::c1_c_::types::ue_cap_info && (api_mode == 1 || api_mode == 3)) + { //&& UECapability + // printf("[API] SF: %d-%d, RNTI: %d, Found UECapabilityInformation messages \n", ul_sf.tti/10, ul_sf.tti%10, decoding_mem.rnti); + print_api(ul_sf.tti, decoding_mem.rnti, -1, "-", MSG_UE_CAP); mcstracking->increase_nof_api_msg(); ret = SRSRAN_SUCCESS; - } else if (ul_dcch_msg.msg.c1().type() == ul_dcch_msg_type_c::c1_c_::types::rrc_conn_setup_complete && (api_mode == 2|| api_mode == 3)){ //IMSI catching, IMSI attach - //printf("[API] SF: %d-%d, RNTI: %d, Found RRC Connection Setup Complete \n", ul_sf.tti/10, ul_sf.tti%10, decoding_mem.rnti); + } + else if (ul_dcch_msg.msg.c1().type() == ul_dcch_msg_type_c::c1_c_::types::rrc_conn_setup_complete && (api_mode == 2 || api_mode == 3)) + { // IMSI catching, IMSI attach + // printf("[API] SF: %d-%d, RNTI: %d, Found RRC Connection Setup Complete \n", ul_sf.tti/10, ul_sf.tti%10, decoding_mem.rnti); asn1::rrc::rrc_conn_setup_complete_s msg = ul_dcch_msg.msg.c1().rrc_conn_setup_complete(); - rrc_conn_setup_complete_r8_ies_s* msg_r8 = &msg.crit_exts.c1().rrc_conn_setup_complete_r8(); + rrc_conn_setup_complete_r8_ies_s *msg_r8 = &msg.crit_exts.c1().rrc_conn_setup_complete_r8(); srsran::unique_byte_buffer_t nas_msg = srsran::make_byte_buffer(); nas_msg->N_bytes = msg_r8->ded_info_nas.size(); memcpy(nas_msg->msg, msg_r8->ded_info_nas.data(), nas_msg->N_bytes); - //parse nas_msg inside rrc connection setup complete to nas decoder + // parse nas_msg inside rrc connection setup complete to nas decoder ret = decode_nas_ul(decoding_mem, nas_msg->msg, nas_msg->N_bytes); - } else if (ul_dcch_msg.msg.c1().type() == ul_dcch_msg_type_c::c1_c_::types::ul_info_transfer && (api_mode == 2|| api_mode == 3)){ // IMSI catching, Identity response - //printf("[API] SF: %d-%d, RNTI: %d, Found UL Infor Transfer \n", ul_sf.tti/10, ul_sf.tti%10, decoding_mem.rnti); + } + else if (ul_dcch_msg.msg.c1().type() == ul_dcch_msg_type_c::c1_c_::types::ul_info_transfer && (api_mode == 2 || api_mode == 3)) + { // IMSI catching, Identity response + // printf("[API] SF: %d-%d, RNTI: %d, Found UL Infor Transfer \n", ul_sf.tti/10, ul_sf.tti%10, decoding_mem.rnti); srsran::unique_byte_buffer_t nas_msg = srsran::make_byte_buffer(); - nas_msg->N_bytes = ul_dcch_msg.msg.c1() - .ul_info_transfer() - .crit_exts.c1() - .ul_info_transfer_r8() - .ded_info_type.ded_info_nas() - .size(); + nas_msg->N_bytes = ul_dcch_msg.msg.c1() + .ul_info_transfer() + .crit_exts.c1() + .ul_info_transfer_r8() + .ded_info_type.ded_info_nas() + .size(); memcpy(nas_msg->msg, ul_dcch_msg.msg.c1() - .ul_info_transfer() - .crit_exts.c1() - .ul_info_transfer_r8() - .ded_info_type.ded_info_nas() - .data(), + .ul_info_transfer() + .crit_exts.c1() + .ul_info_transfer_r8() + .ded_info_type.ded_info_nas() + .data(), nas_msg->N_bytes); ret = decode_nas_ul(decoding_mem, nas_msg->msg, nas_msg->N_bytes); } @@ -129,81 +144,100 @@ int PUSCH_Decoder::decode_ul_dcch(DCI_UL &decoding_mem, uint8_t* sdu_ptr, int le } /*Identity response with IMSI/IMEI or IMSI attach*/ -int PUSCH_Decoder::decode_nas_ul(DCI_UL &decoding_mem, uint8_t* sdu_ptr, int length){ +int PUSCH_Decoder::decode_nas_ul(DCI_UL &decoding_mem, uint8_t *sdu_ptr, int length) +{ int ret = SRSRAN_ERROR; - s1ap_pdu_c rx_pdu; //asn1::s1ap::s1ap_pdu_c //using s1ap_pdu_t = asn1::s1ap::s1ap_pdu_c; + s1ap_pdu_c rx_pdu; // asn1::s1ap::s1ap_pdu_c //using s1ap_pdu_t = asn1::s1ap::s1ap_pdu_c; cbit_ref bref(sdu_ptr, length); int asn1_result = rx_pdu.unpack(bref); srsran::unique_byte_buffer_t nas_msg = srsran::make_byte_buffer(); memcpy(nas_msg->msg, sdu_ptr, length); nas_msg->N_bytes = length; - uint8_t pd, msg_type, sec_hdr_type; - LIBLTE_ERROR_ENUM err; - liblte_mme_parse_msg_sec_header((LIBLTE_BYTE_MSG_STRUCT*)nas_msg.get(), &pd, &sec_hdr_type); - if (sec_hdr_type != LIBLTE_MME_SECURITY_HDR_TYPE_INTEGRITY_AND_CIPHERED && - sec_hdr_type != LIBLTE_MME_SECURITY_HDR_TYPE_INTEGRITY_AND_CIPHERED_WITH_NEW_EPS_SECURITY_CONTEXT){ - liblte_mme_parse_msg_header((LIBLTE_BYTE_MSG_STRUCT*)nas_msg.get(), &pd, &msg_type); - - if (msg_type == LIBLTE_MME_MSG_TYPE_IDENTITY_RESPONSE){ + uint8_t pd, msg_type, sec_hdr_type; + LIBLTE_ERROR_ENUM err; + liblte_mme_parse_msg_sec_header((LIBLTE_BYTE_MSG_STRUCT *)nas_msg.get(), &pd, &sec_hdr_type); + if (sec_hdr_type != LIBLTE_MME_SECURITY_HDR_TYPE_INTEGRITY_AND_CIPHERED && + sec_hdr_type != LIBLTE_MME_SECURITY_HDR_TYPE_INTEGRITY_AND_CIPHERED_WITH_NEW_EPS_SECURITY_CONTEXT) + { + liblte_mme_parse_msg_header((LIBLTE_BYTE_MSG_STRUCT *)nas_msg.get(), &pd, &msg_type); + + if (msg_type == LIBLTE_MME_MSG_TYPE_IDENTITY_RESPONSE) + { LIBLTE_MME_ID_RESPONSE_MSG_STRUCT identity_response; LIBLTE_BYTE_MSG_STRUCT msg; memcpy(&msg.msg, nas_msg->msg, nas_msg->N_bytes); msg.N_bytes = nas_msg->N_bytes; err = liblte_mme_unpack_identity_response_msg(&msg, &identity_response); - if (err == LIBLTE_SUCCESS && identity_response.mobile_id.type_of_id == LIBLTE_MME_MOBILE_ID_TYPE_IMSI){ + if (err == LIBLTE_SUCCESS && identity_response.mobile_id.type_of_id == LIBLTE_MME_MOBILE_ID_TYPE_IMSI) + { std::string imsi_str = ""; - for (int z = 0; z < 15; z++){ + for (int z = 0; z < 15; z++) + { imsi_str.append(std::to_string(identity_response.mobile_id.imsi[z])); } print_api(ul_sf.tti, decoding_mem.rnti, ID_IMSI, imsi_str, MSG_ID_RES); mcstracking->increase_nof_api_msg(); ret = SRSRAN_SUCCESS; - } else if (err == LIBLTE_SUCCESS && identity_response.mobile_id.type_of_id == LIBLTE_MME_MOBILE_ID_TYPE_IMEI){ + } + else if (err == LIBLTE_SUCCESS && identity_response.mobile_id.type_of_id == LIBLTE_MME_MOBILE_ID_TYPE_IMEI) + { std::string imei_str = ""; - for (int z = 0; z < 15; z++){ + for (int z = 0; z < 15; z++) + { imei_str.append(std::to_string(identity_response.mobile_id.imei[z])); } print_api(ul_sf.tti, decoding_mem.rnti, ID_IMEI, imei_str, MSG_ID_RES); mcstracking->increase_nof_api_msg(); ret = SRSRAN_SUCCESS; - } else if (err == LIBLTE_SUCCESS && identity_response.mobile_id.type_of_id == LIBLTE_MME_MOBILE_ID_TYPE_IMEISV){ + } + else if (err == LIBLTE_SUCCESS && identity_response.mobile_id.type_of_id == LIBLTE_MME_MOBILE_ID_TYPE_IMEISV) + { std::string imei_str = ""; - for (int z = 0; z < 16; z++){ + for (int z = 0; z < 16; z++) + { imei_str.append(std::to_string(identity_response.mobile_id.imeisv[z])); } print_api(ul_sf.tti, decoding_mem.rnti, ID_IMEISV, imei_str, MSG_ID_RES); mcstracking->increase_nof_api_msg(); ret = SRSRAN_SUCCESS; - } - }else if (err == LIBLTE_SUCCESS && msg_type == LIBLTE_MME_MSG_TYPE_ATTACH_REQUEST){ + } + else if (err == LIBLTE_SUCCESS && msg_type == LIBLTE_MME_MSG_TYPE_ATTACH_REQUEST) + { LIBLTE_MME_ATTACH_REQUEST_MSG_STRUCT attach_req; LIBLTE_BYTE_MSG_STRUCT msg; memcpy(&msg.msg, nas_msg->msg, nas_msg->N_bytes); msg.N_bytes = nas_msg->N_bytes; /*Unpack Attach request*/ err = liblte_mme_unpack_attach_request_msg(&msg, &attach_req); - if (attach_req.eps_mobile_id.type_of_id == LIBLTE_MME_EPS_MOBILE_ID_TYPE_IMSI){ + if (attach_req.eps_mobile_id.type_of_id == LIBLTE_MME_EPS_MOBILE_ID_TYPE_IMSI) + { std::string imsi_str = ""; - for (int z = 0; z < 15; z++){ + for (int z = 0; z < 15; z++) + { imsi_str.append(std::to_string(attach_req.eps_mobile_id.imsi[z])); } - print_api(ul_sf.tti, decoding_mem.rnti, ID_IMSI , imsi_str, MSG_ATT_REQ); + print_api(ul_sf.tti, decoding_mem.rnti, ID_IMSI, imsi_str, MSG_ATT_REQ); mcstracking->increase_nof_api_msg(); ret = SRSRAN_SUCCESS; - } else if (attach_req.eps_mobile_id.type_of_id == LIBLTE_MME_EPS_MOBILE_ID_TYPE_GUTI){ + } + else if (attach_req.eps_mobile_id.type_of_id == LIBLTE_MME_EPS_MOBILE_ID_TYPE_GUTI) + { std::stringstream ss; ss << std::hex << attach_req.eps_mobile_id.guti.m_tmsi; std::string m_tmsi_str = ss.str(); - print_api(ul_sf.tti, decoding_mem.rnti, ID_TMSI , m_tmsi_str, MSG_ATT_REQ); + print_api(ul_sf.tti, decoding_mem.rnti, ID_TMSI, m_tmsi_str, MSG_ATT_REQ); mcstracking->increase_nof_api_msg(); ret = SRSRAN_SUCCESS; - } else if (attach_req.eps_mobile_id.type_of_id == LIBLTE_MME_EPS_MOBILE_ID_TYPE_IMEI){ + } + else if (attach_req.eps_mobile_id.type_of_id == LIBLTE_MME_EPS_MOBILE_ID_TYPE_IMEI) + { std::string imei_str = ""; - for (int z = 0; z < 15; z++){ + for (int z = 0; z < 15; z++) + { imei_str.append(std::to_string(attach_req.eps_mobile_id.imei[z])); } - print_api(ul_sf.tti, decoding_mem.rnti, ID_IMEI , imei_str, MSG_ATT_REQ); + print_api(ul_sf.tti, decoding_mem.rnti, ID_IMEI, imei_str, MSG_ATT_REQ); mcstracking->increase_nof_api_msg(); ret = SRSRAN_SUCCESS; } @@ -220,94 +254,115 @@ void PUSCH_Decoder::decode_run(std::string info, DCI_UL &decoding_mem, std::stri /*Do channel estimation to calculate timing difference between UL & DL subframes, because of diffrent propagation times*/ int ret = srsran_chest_ul_estimate_pusch(&enb_ul.chest, &ul_sf, &ul_cfg.pusch, enb_ul.sf_symbols, &enb_ul.chest_res); - + /*Use channel estimation result to perform channel equalizer to compensate the time delay*/ pusch_res.crc = false; // reset crc result - if (ret == SRSRAN_SUCCESS){ + if (ret == SRSRAN_SUCCESS) + { ret = srsran_pusch_decode(&enb_ul.pusch, &ul_sf, &ul_cfg.pusch, &enb_ul.chest_res, enb_ul.sf_symbols, &pusch_res); } /*Only print debug when SNR of RNTI >= 1 */ - if ((en_debug ) && (enb_ul.chest_res.snr_db >= 1)){ //|| target_rnti !=0 + if ((en_debug) && (enb_ul.chest_res.snr_db >= 1)) + { //|| target_rnti !=0 float signal_power = enb_ul.chest_res.snr_db; float falcon_signal_power = 0.0f; float tmp_sum = 0.0f; - for(uint32_t rb_idx = 0; rb_idx < ul_cfg.pusch.grant.L_prb; rb_idx++) { + for (uint32_t rb_idx = 0; rb_idx < ul_cfg.pusch.grant.L_prb; rb_idx++) + { tmp_sum += sf_power->getRBPowerUL().at(ul_cfg.pusch.grant.n_prb[0] + rb_idx); } - falcon_signal_power = tmp_sum/ul_cfg.pusch.grant.L_prb; + falcon_signal_power = tmp_sum / ul_cfg.pusch.grant.L_prb; print_debug(decoding_mem, info, modulation_mode, signal_power, enb_ul.chest_res.noise_estimate_dbm, falcon_signal_power); } - if (pusch_res.crc == true && ul_cfg.pusch.grant.tb.tbs != 0){ - int length = ul_cfg.pusch.grant.tb.tbs/8; + if (pusch_res.crc == true && ul_cfg.pusch.grant.tb.tbs != 0) + { + int length = ul_cfg.pusch.grant.tb.tbs / 8; pcapwriter->write_ul_crnti(pusch_res.data, length, ul_cfg.pusch.rnti, ul_sf.tti); /*Update max UL modulation scheme 16/64/256QAM when mcs index > 20*/ - if (mcs_idx > 20 && decoding_mem.mcs_mod == UL_SNIFFER_UNKNOWN_MOD){ - if (info == "[PUSCH-16 ]"){ + if (mcs_idx > 20 && decoding_mem.mcs_mod == UL_SNIFFER_UNKNOWN_MOD) + { + if (info == "[PUSCH-16 ]") + { mcstracking->update_RNTI_ul(decoding_mem.rnti, UL_SNIFFER_16QAM_MAX); - }else if ( info == "[PUSCH-64 ]"){ + } + else if (info == "[PUSCH-64 ]") + { mcstracking->update_RNTI_ul(decoding_mem.rnti, UL_SNIFFER_64QAM_MAX); - } else if (info == "[PUSCH-256]"){ + } + else if (info == "[PUSCH-256]") + { mcstracking->update_RNTI_ul(decoding_mem.rnti, UL_SNIFFER_256QAM_MAX); } - /*When mcs index < 20, only 2 possible max modulation scheme 16/256QAM */ - } else if (mcs_idx > 0 && decoding_mem.mcs_mod == UL_SNIFFER_UNKNOWN_MOD && info == "[PUSCH-256]"){ + /*When mcs index < 20, only 2 possible max modulation scheme 16/256QAM */ + } + else if (mcs_idx > 0 && decoding_mem.mcs_mod == UL_SNIFFER_UNKNOWN_MOD && info == "[PUSCH-256]") + { mcstracking->update_RNTI_ul(decoding_mem.rnti, UL_SNIFFER_256QAM_MAX); } decoding_mem.decoded = 1; /* [API] Decode RRC Connection Setup and UECapabilityInformation*/ int api_ret = SRSRAN_ERROR; - if (decoding_mem.is_rar_gant && (api_mode == 0 || api_mode == 3)){ + if (decoding_mem.is_rar_gant && (api_mode == 0 || api_mode == 3)) + { srsran::sch_pdu pdu(10, srslog::fetch_basic_logger("MAC")); pdu.init_rx(length, true); pdu.parse_packet(pusch_res.data); while (pdu.next()) { - if(pdu.get()->is_sdu()){ + if (pdu.get()->is_sdu()) + { int payload_length = pdu.get()->get_payload_size(); - uint8_t* sdu_ptr = pdu.get()->get_sdu_ptr(); + uint8_t *sdu_ptr = pdu.get()->get_sdu_ptr(); /* Decode RRC Connection Request when found valid sdu from MAC pdu*/ - ret = decode_rrc_connection_request (decoding_mem, sdu_ptr, payload_length); + ret = decode_rrc_connection_request(decoding_mem, sdu_ptr, payload_length); } } - if (ret == SRSRAN_SUCCESS){ + if (ret == SRSRAN_SUCCESS) + { pcapwriter->write_ul_crnti_api(pusch_res.data, length, ul_cfg.pusch.rnti, ul_sf.tti); api_ret = SRSRAN_ERROR; - } - } else if (api_mode > 0){ // Decode DCCH (api mode 1,2,3) + } + } + else if (api_mode > 0) + { // Decode DCCH (api mode 1,2,3) srsran::sch_pdu pdu(10, srslog::fetch_basic_logger("MAC")); pdu.init_rx(length, true); pdu.parse_packet(pusch_res.data); while (pdu.next()) { /*LCID 1 & 2*/ - if(pdu.get()->is_sdu() && (pdu.get()->get_sdu_lcid() == 1 || pdu.get()->get_sdu_lcid() == 2)){ + if (pdu.get()->is_sdu() && (pdu.get()->get_sdu_lcid() == 1 || pdu.get()->get_sdu_lcid() == 2)) + { int payload_length = pdu.get()->get_payload_size(); - uint8_t* sdu_ptr = pdu.get()->get_sdu_ptr(); + uint8_t *sdu_ptr = pdu.get()->get_sdu_ptr(); /*Only RLC data pdu*/ - if (!rlc_am_is_control_pdu(sdu_ptr)){ - rlc_amd_pdu_header_t header = {}; - uint32_t payload_len = payload_length; + if (!rlc_am_is_control_pdu(sdu_ptr)) + { + rlc_amd_pdu_header_t header = {}; + uint32_t payload_len = payload_length; rlc_am_read_data_pdu_header(&sdu_ptr, &payload_len, &header); /*Only decode full frame, not fragment of frame (fi == 0 means full RRC frame)*/ - if (!header.rf && header.fi == 0) { + if (!header.rf && header.fi == 0) + { srsran::unique_byte_buffer_t pdcp_pdu = srsran::make_byte_buffer(); pdcp_pdu->N_bytes = payload_len; memcpy(pdcp_pdu->msg, sdu_ptr, pdcp_pdu->N_bytes); /*Discard pdcp header , assume that pdcp header size = 1 byte*/ - pdcp_pdu->msg += 1; - pdcp_pdu->N_bytes -= 1; - uint8_t pd, msg_type, sec_hdr_type; - liblte_mme_parse_msg_sec_header((LIBLTE_BYTE_MSG_STRUCT*)pdcp_pdu.get(), &pd, &sec_hdr_type); + pdcp_pdu->msg += 1; + pdcp_pdu->N_bytes -= 1; + uint8_t pd, msg_type, sec_hdr_type; + liblte_mme_parse_msg_sec_header((LIBLTE_BYTE_MSG_STRUCT *)pdcp_pdu.get(), &pd, &sec_hdr_type); /*Only decode NAS without encryption*/ - if ((sec_hdr_type == LIBLTE_MME_SECURITY_HDR_TYPE_PLAIN_NAS) || - (sec_hdr_type == LIBLTE_MME_SECURITY_HDR_TYPE_INTEGRITY) || - (sec_hdr_type == LIBLTE_MME_SECURITY_HDR_TYPE_INTEGRITY_WITH_NEW_EPS_SECURITY_CONTEXT)){ + if ((sec_hdr_type == LIBLTE_MME_SECURITY_HDR_TYPE_PLAIN_NAS) || + (sec_hdr_type == LIBLTE_MME_SECURITY_HDR_TYPE_INTEGRITY) || + (sec_hdr_type == LIBLTE_MME_SECURITY_HDR_TYPE_INTEGRITY_WITH_NEW_EPS_SECURITY_CONTEXT)) + { // /*Discard pdcp header , assume that pdcp header size = 1 byte*/ - // pdcp_pdu->msg += 1; + // pdcp_pdu->msg += 1; // pdcp_pdu->N_bytes -= 1; /* Decode UL DCCH messages*/ @@ -317,76 +372,89 @@ void PUSCH_Decoder::decode_run(std::string info, DCI_UL &decoding_mem, std::stri } } } - if (api_ret == SRSRAN_SUCCESS){ + if (api_ret == SRSRAN_SUCCESS) + { pcapwriter->write_ul_crnti_api(pusch_res.data, length, ul_cfg.pusch.rnti, ul_sf.tti); api_ret = SRSRAN_ERROR; - } + } } } } -void print_ul_grant_dci_0(srsran_pusch_grant_t &ul_grant, uint16_t tti, uint16_t rnti){ - std::cout << "[DCI] SF: " << tti/10 << ":" << tti%10 << "-RNTI: " << rnti << " -L_prb: " << ul_grant.L_prb << " -MOD: " << ul_grant.tb.mod << \ - " -tbs: " << ul_grant.tb.tbs << " -RV: " << ul_grant.tb.rv << std::endl; +void print_ul_grant_dci_0(srsran_pusch_grant_t &ul_grant, uint16_t tti, uint16_t rnti) +{ + std::cout << "[DCI] SF: " << tti / 10 << ":" << tti % 10 << "-RNTI: " << rnti << " -L_prb: " << ul_grant.L_prb << " -MOD: " << ul_grant.tb.mod << " -tbs: " << ul_grant.tb.tbs << " -RV: " << ul_grant.tb.rv << std::endl; } void PUSCH_Decoder::decode() { enb_ul.in_buffer = original_buffer[1]; // 0 for downlink, 1 for uplink - srsran_enb_ul_fft(&enb_ul); //run FFT to uplink samples + srsran_enb_ul_fft(&enb_ul); // run FFT to uplink samples sf_power->computePower(enb_ul.sf_symbols); /*combine Uplink grant detected from RAR response (msg 2) and Uplink grant detected from DCI0*/ - if (dci_ul != nullptr || rar_dci_ul != nullptr){ - if (rar_dci_ul != nullptr && dci_ul != nullptr){ + if (dci_ul != nullptr || rar_dci_ul != nullptr) + { + if (rar_dci_ul != nullptr && dci_ul != nullptr) + { int rar_size = rar_dci_ul->size(); - if (rar_size > 0){ - for (int rar_idx = 0; rar_idx < rar_size; rar_idx++){ + if (rar_size > 0) + { + for (int rar_idx = 0; rar_idx < rar_size; rar_idx++) + { dci_ul->push_back(rar_dci_ul->at(rar_idx)); } } - } else if(rar_dci_ul != nullptr && dci_ul == nullptr){ + } + else if (rar_dci_ul != nullptr && dci_ul == nullptr) + { dci_ul = rar_dci_ul; } /*Try to decode all member in grant list*/ - for (auto decoding_mem:(*dci_ul)){ + for (auto decoding_mem : (*dci_ul)) + { /*Investigate current decoding member to know it has a valid UL grant or not*/ valid_ul_grant = investigate_valid_ul_grant(decoding_mem); /*Only decode member with valid UL grant*/ - if ((decoding_mem.rnti == target_rnti) || (valid_ul_grant == SRSRAN_SUCCESS)){ + if ((decoding_mem.rnti == target_rnti) || (valid_ul_grant == SRSRAN_SUCCESS)) + { /*Setup uplink config for decoding*/ - ul_cfg.pusch.rnti = decoding_mem.rnti; - ul_cfg.pusch.enable_64qam = false; // check here for 64/16QAM - ul_cfg.pusch.meas_ta_en = true; //enable ta measurement - ul_cfg.pusch.grant = *decoding_mem.ran_ul_grant.get(); - int mcs_idx = ul_cfg.pusch.grant.tb.mcs_idx; - pusch_res.crc = false; + ul_cfg.pusch.rnti = decoding_mem.rnti; + ul_cfg.pusch.enable_64qam = false; // check here for 64/16QAM + ul_cfg.pusch.meas_ta_en = true; // enable ta measurement + ul_cfg.pusch.grant = *decoding_mem.ran_ul_grant.get(); + int mcs_idx = ul_cfg.pusch.grant.tb.mcs_idx; + pusch_res.crc = false; /*Get Number of ack which was calculated in Subframe worker last 4 ms*/ - ul_cfg.pusch.uci_cfg.ack[0].nof_acks = decoding_mem.nof_ack; + ul_cfg.pusch.uci_cfg.ack[0].nof_acks = decoding_mem.nof_ack; // ul_cfg.pusch.uci_cfg.cqi.rank_is_not_one = (decoding_mem.nof_ack == 2)?true:false; /*get UE-specific configuration from database*/ ltesniffer_ue_spec_config_t ue_config = mcstracking->get_ue_config_rnti(decoding_mem.rnti); - ul_cfg.pusch.uci_cfg.cqi.type = ue_config.cqi_config.type; - ul_cfg.pusch.uci_offset = ue_config.uci_config; + ul_cfg.pusch.uci_cfg.cqi.type = ue_config.cqi_config.type; + ul_cfg.pusch.uci_offset = ue_config.uci_config; /*If eNB requests for Aperiodic CSI report*/ - if (decoding_mem.ran_ul_dci->cqi_request == true){ - ul_cfg.pusch.uci_cfg.cqi.four_antenna_ports = false; - ul_cfg.pusch.uci_cfg.cqi.data_enable = true; - ul_cfg.pusch.uci_cfg.cqi.pmi_present = false; - ul_cfg.pusch.uci_cfg.cqi.rank_is_not_one = false; - ul_cfg.pusch.uci_cfg.cqi.N = ul_sniffer_cqi_hl_get_no_subbands(enb_ul.cell.nof_prb); - ul_cfg.pusch.uci_cfg.cqi.ri_len = 1; //only for TM3 and TM4 // srsran_ri_nof_bits(&enb_ul.cell) - } else { - ul_cfg.pusch.uci_cfg.cqi.data_enable = false; - ul_cfg.pusch.uci_cfg.cqi.ri_len = 0; + if (decoding_mem.ran_ul_dci->cqi_request == true) + { + ul_cfg.pusch.uci_cfg.cqi.four_antenna_ports = false; + ul_cfg.pusch.uci_cfg.cqi.data_enable = true; + ul_cfg.pusch.uci_cfg.cqi.pmi_present = false; + ul_cfg.pusch.uci_cfg.cqi.rank_is_not_one = false; + ul_cfg.pusch.uci_cfg.cqi.N = ul_sniffer_cqi_hl_get_no_subbands(enb_ul.cell.nof_prb); + ul_cfg.pusch.uci_cfg.cqi.ri_len = 1; // only for TM3 and TM4 // srsran_ri_nof_bits(&enb_ul.cell) + } + else + { + ul_cfg.pusch.uci_cfg.cqi.data_enable = false; + ul_cfg.pusch.uci_cfg.cqi.ri_len = 0; } /*Find correct mcs table from database*/ ul_sniffer_mod_tracking_t mcs_mod = mcstracking->find_tracking_info_RNTI_ul(decoding_mem.rnti); std::string modulation_mode = "Unknown"; int ret = SRSRAN_ERROR; /*If mcs_idx > 20 then check mcstracking to decode properly*/ - if (mcs_idx > 20 && mcs_idx < 29){ + if (mcs_idx > 20 && mcs_idx < 29) + { switch (mcs_mod) { case UL_SNIFFER_16QAM_MAX: @@ -406,7 +474,8 @@ void PUSCH_Decoder::decode() ul_cfg.pusch.enable_64qam = true; modulation_mode = modulation_mode_string_256(mcs_idx); ul_cfg.pusch.grant = *decoding_mem.ran_ul_grant_256.get(); - if (ul_cfg.pusch.grant.L_prb < 110 && ul_cfg.pusch.grant.L_prb > 0){ + if (ul_cfg.pusch.grant.L_prb < 110 && ul_cfg.pusch.grant.L_prb > 0) + { decode_run("[PUSCH-256]", decoding_mem, modulation_mode, 0); } break; @@ -416,45 +485,55 @@ void PUSCH_Decoder::decode() /* reset buffer and CRC checking */ pusch_res.crc = false; // ret = srsran_chest_ul_estimate_pusch(&enb_ul.chest, &ul_sf, &ul_cfg.pusch, enb_ul.sf_symbols, &enb_ul.chest_res); - if (mcs_idx <= 28){ + if (mcs_idx <= 28) + { /*Compute avg signal power for PRB in UL grant*/ float falcon_signal_power = 0.0f; float tmp_sum = 0.0f; - for(uint32_t rb_idx = 0; rb_idx < ul_cfg.pusch.grant.L_prb; rb_idx++) { + for (uint32_t rb_idx = 0; rb_idx < ul_cfg.pusch.grant.L_prb; rb_idx++) + { tmp_sum += sf_power->getRBPowerUL().at(ul_cfg.pusch.grant.n_prb[0] + rb_idx); } - falcon_signal_power = tmp_sum/ul_cfg.pusch.grant.L_prb; + falcon_signal_power = tmp_sum / ul_cfg.pusch.grant.L_prb; decode_run("[PUSCH-16 ]", decoding_mem, modulation_mode, falcon_signal_power); - if (pusch_res.crc == false && mcs_idx > 20){ + if (pusch_res.crc == false && mcs_idx > 20) + { /* Try 64QAM table if 16QAM failed*/ - ul_cfg.pusch.rnti = decoding_mem.rnti; - ul_cfg.pusch.enable_64qam = true; // 64QAM - ul_cfg.pusch.meas_ta_en = true; //enable ta measurement - ul_cfg.pusch.grant = *decoding_mem.ran_ul_grant.get(); + ul_cfg.pusch.rnti = decoding_mem.rnti; + ul_cfg.pusch.enable_64qam = true; // 64QAM + ul_cfg.pusch.meas_ta_en = true; // enable ta measurement + ul_cfg.pusch.grant = *decoding_mem.ran_ul_grant.get(); decode_run("[PUSCH-64 ]", decoding_mem, modulation_mode, falcon_signal_power); - if (pusch_res.crc == false){ // try 256QAM table if 2 cases above failed + if (pusch_res.crc == false) + { // try 256QAM table if 2 cases above failed ul_cfg.pusch.rnti = decoding_mem.rnti; - ul_cfg.pusch.enable_64qam = true; - ul_cfg.pusch.meas_ta_en = true; //enable ta measurement + ul_cfg.pusch.enable_64qam = true; + ul_cfg.pusch.meas_ta_en = true; // enable ta measurement ul_cfg.pusch.grant = *decoding_mem.ran_ul_grant_256.get(); modulation_mode = modulation_mode_string_256(mcs_idx); - if (ul_cfg.pusch.grant.L_prb < 110 && ul_cfg.pusch.grant.L_prb > 0){ + if (ul_cfg.pusch.grant.L_prb < 110 && ul_cfg.pusch.grant.L_prb > 0) + { decode_run("[PUSCH-256]", decoding_mem, modulation_mode, 0); } } } - } else { + } + else + { // Do nothing if mimo ret error } break; default: break; } - }else if (mcs_idx <= 20){ // if mcs_idx <= 20 then try only 16QAM or 256QAM (64QAM is enabled when mcs idx > 20) - switch (mcs_mod){ + } + else if (mcs_idx <= 20) + { // if mcs_idx <= 20 then try only 16QAM or 256QAM (64QAM is enabled when mcs idx > 20) + switch (mcs_mod) + { case UL_SNIFFER_16QAM_MAX: case UL_SNIFFER_64QAM_MAX: ul_cfg.pusch.enable_64qam = false; @@ -465,7 +544,8 @@ void PUSCH_Decoder::decode() ul_cfg.pusch.enable_64qam = true; ul_cfg.pusch.grant = *decoding_mem.ran_ul_grant_256.get(); modulation_mode = modulation_mode_string_256(mcs_idx); - if (ul_cfg.pusch.grant.L_prb < 110 && ul_cfg.pusch.grant.L_prb > 0){ + if (ul_cfg.pusch.grant.L_prb < 110 && ul_cfg.pusch.grant.L_prb > 0) + { decode_run("[PUSCH-256]", decoding_mem, modulation_mode, 0); } break; @@ -473,34 +553,39 @@ void PUSCH_Decoder::decode() ul_cfg.pusch.enable_64qam = false; modulation_mode = modulation_mode_string(mcs_idx, false); decode_run("[PUSCH-16 ]", decoding_mem, modulation_mode, 0); - if (pusch_res.crc == false){ // try 256QAM table if case above failed + if (pusch_res.crc == false) + { // try 256QAM table if case above failed ul_cfg.pusch.grant = *decoding_mem.ran_ul_grant_256.get(); modulation_mode = modulation_mode_string_256(mcs_idx); - if (ul_cfg.pusch.grant.L_prb < 110 && ul_cfg.pusch.grant.L_prb > 0){ + if (ul_cfg.pusch.grant.L_prb < 110 && ul_cfg.pusch.grant.L_prb > 0) + { ul_cfg.pusch.enable_64qam = true; decode_run("[PUSCH-256]", decoding_mem, modulation_mode, 0); } } default: - //do nothing + // do nothing break; } } /*Update statistic when SNR is higher than 1, the statistic showed on terminal is only for RNTIs with SNR >=1*/ - if (enb_ul.chest_res.snr_db >= 1){ //enb_ul.chest_res.snr_db >= 1 + if (enb_ul.chest_res.snr_db >= 1) + { // enb_ul.chest_res.snr_db >= 1 mcstracking->update_statistic_ul(decoding_mem.rnti, pusch_res.crc, decoding_mem, enb_ul.chest_res.snr_db, enb_ul.chest_res.ta_us); } - }else{ - //Do nothing + } + else + { + // Do nothing } } } } -void PUSCH_Decoder::init_pusch_decoder(std::vector* dci_ul_, - std::vector* rar_dci_ul_, +void PUSCH_Decoder::init_pusch_decoder(std::vector *dci_ul_, + std::vector *rar_dci_ul_, srsran_ul_sf_cfg_t &ul_sf_, - SubframePower* sf_power_) + SubframePower *sf_power_) { dci_ul = dci_ul_; rar_dci_ul = rar_dci_ul_; @@ -508,29 +593,37 @@ void PUSCH_Decoder::init_pusch_decoder(std::vector* dci_ul_, sf_power = sf_power_; } -int PUSCH_Decoder::check_valid_prb_ul(uint32_t nof_prb){ - if (nof_prb <= 100) { - return valid_prb_ul[nof_prb]; - } - return false; +int PUSCH_Decoder::check_valid_prb_ul(uint32_t nof_prb) +{ + if (nof_prb <= 100) + { + return valid_prb_ul[nof_prb]; + } + return false; } std::string PUSCH_Decoder::modulation_mode_string(int idx, bool max_64qam) { std::string ret = ""; - if (idx <= 10){ - ret = "QPSK"; + if (idx <= 10) + { + ret = "QPSK"; + } + else if (idx <= 20) + { + ret = "16QAM"; } - else if (idx <= 20) { - ret = "16QAM"; + else if (idx <= 28 && max_64qam) + { + ret = "64QAM"; } - else if (idx <= 28 && max_64qam){ - ret = "64QAM"; + else if (idx <= 28 && !max_64qam) + { + ret = "16QAM"; } - else if (idx <= 28 && !max_64qam){ - ret = "16QAM"; - }else { - ret = "ReTx"; + else + { + ret = "ReTx"; } return ret; } @@ -538,32 +631,39 @@ std::string PUSCH_Decoder::modulation_mode_string(int idx, bool max_64qam) std::string PUSCH_Decoder::modulation_mode_string_256(int idx) { std::string ret = ""; - if (idx <= 5){ - ret = "QPSK"; + if (idx <= 5) + { + ret = "QPSK"; + } + else if (idx <= 13) + { + ret = "16QAM"; } - else if (idx <= 13) { - ret = "16QAM"; + else if (idx <= 22) + { + ret = "64QAM"; } - else if (idx <= 22){ - ret = "64QAM"; + else if (idx <= 28) + { + ret = "256QAM"; } - else if (idx <= 28){ - ret = "256QAM"; - }else { - ret = "ReTx"; + else + { + ret = "ReTx"; } return ret; } - void PUSCH_Decoder::set_rach_config(srsran_prach_cfg_t prach_cfg_) { prach_cfg = prach_cfg_; - if (srsran_prach_init(&prach, srsran_symbol_sz(enb_ul.cell.nof_prb))) { + if (srsran_prach_init(&prach, srsran_symbol_sz(enb_ul.cell.nof_prb))) + { std::cout << "Init PRACH failed" << std::endl; } - if (srsran_prach_set_cfg(&prach, &prach_cfg, enb_ul.cell.nof_prb)) { - std::cout << "Config PRACH failed" << std::endl; + if (srsran_prach_set_cfg(&prach, &prach_cfg, enb_ul.cell.nof_prb)) + { + std::cout << "Config PRACH failed" << std::endl; } srsran_prach_set_detect_factor(&prach, 60); nof_sf = (uint32_t)ceilf(prach.T_tot * 1000); @@ -572,37 +672,41 @@ void PUSCH_Decoder::set_rach_config(srsran_prach_cfg_t prach_cfg_) void PUSCH_Decoder::work_prach() { uint32_t prach_nof_det = 0; - if (srsran_prach_tti_opportunity(&prach, ul_sf.tti, -1)) { + if (srsran_prach_tti_opportunity(&prach, ul_sf.tti, -1)) + { memcpy(&samples[0], - original_buffer[1], - sizeof(cf_t) * SRSRAN_SF_LEN_PRB(enb_ul.cell.nof_prb)); + original_buffer[1], + sizeof(cf_t) * SRSRAN_SF_LEN_PRB(enb_ul.cell.nof_prb)); // Detect possible PRACHs srsran_prach_detect_offset(&prach, - prach_cfg.freq_offset, - &samples[prach.N_cp], - SRSRAN_SF_LEN_PRB(enb_ul.cell.nof_prb) - prach.N_cp, - prach_indices, - prach_offsets, - prach_p2avg, - &prach_nof_det); - - if (prach_nof_det){ + prach_cfg.freq_offset, + &samples[prach.N_cp], + SRSRAN_SF_LEN_PRB(enb_ul.cell.nof_prb) - prach.N_cp, + prach_indices, + prach_offsets, + prach_p2avg, + &prach_nof_det); + + if (prach_nof_det) + { int max_idx = 0; - float peak = 0; - for (uint32_t i = 0; i < prach_nof_det; i++) { + float peak = 0; + for (uint32_t i = 0; i < prach_nof_det; i++) + { if (prach_p2avg[i] > peak) { peak = prach_p2avg[i]; max_idx = i; } } - if (en_debug){ + if (en_debug) + { printf("PRACH: %d/%d, preamble=%d, offset=%.1f us, peak2avg=%.1f \n", - max_idx + 1, - prach_nof_det, - prach_indices[max_idx], - prach_offsets[max_idx] * 1e6, - prach_p2avg[max_idx]); + max_idx + 1, + prach_nof_det, + prach_indices[max_idx], + prach_offsets[max_idx] * 1e6, + prach_p2avg[max_idx]); } } } @@ -611,30 +715,35 @@ void PUSCH_Decoder::work_prach() void PUSCH_Decoder::print_debug(DCI_UL &decoding_mem, std::string offset_name, std::string modulation_mode, float signal_pw, double noise, double falcon_sgl_pwr) { std::cout << std::left << std::setw(12) << offset_name << " SF: "; - std::cout << std::left << std::setw(4) << (int)ul_sf.tti/10 << "." << (int)ul_sf.tti%10; + std::cout << std::left << std::setw(4) << (int)ul_sf.tti / 10 << "." << (int)ul_sf.tti % 10; std::cout << " -- RNTI: "; std::cout << std::left << std::setw(6) << decoding_mem.rnti; std::cout << GREEN << " -- DL-UL(us): "; - if (enb_ul.chest_res.ta_us > 0){ + if (enb_ul.chest_res.ta_us > 0) + { std::cout << "+"; - } else if (enb_ul.chest_res.ta_us < 0){ + } + else if (enb_ul.chest_res.ta_us < 0) + { std::cout << "-"; - } else{ + } + else + { std::cout << " "; } std::cout << std::left << std::setw(5) << abs(enb_ul.chest_res.ta_us) << RESET; std::cout << " -- SNR(db): "; - std::cout << std::left << std::setw(6) << std::setprecision(3) << enb_ul.chest_res.snr_db ; + std::cout << std::left << std::setw(6) << std::setprecision(3) << enb_ul.chest_res.snr_db; // std::cout << " -- F_Pwr: "; // std::string pwr_sign; // int width = 0; - // if (falcon_sgl_pwr < 0) { + // if (falcon_sgl_pwr < 0) { // pwr_sign = ""; // width = 7; - // } else { + // } else { // pwr_sign = " "; // width = 6; // } @@ -647,38 +756,45 @@ void PUSCH_Decoder::print_debug(DCI_UL &decoding_mem, std::string offset_name, s std::cout << std::left << std::setw(6) << std::setprecision(3) << noise; std::cout << YELLOW << " -- MCS: "; - std::cout << std::left << std::setw(3) << ul_cfg.pusch.grant.tb.mcs_idx << RESET; + std::cout << std::left << std::setw(3) << ul_cfg.pusch.grant.tb.mcs_idx << RESET; std::cout << YELLOW << " -- "; - std::cout << std::left << std::setw(6) << modulation_mode << RESET; + std::cout << std::left << std::setw(6) << modulation_mode << RESET; - std::cout << " -- "; - if (pusch_res.crc == false ){ + std::cout << " -- "; + if (pusch_res.crc == false) + { std::cout << RED << std::setw(7) << "FAILED" << RESET; - std::cout << " -- Len: " << ul_cfg.pusch.grant.tb.tbs/8; - } else{ + std::cout << " -- Len: " << ul_cfg.pusch.grant.tb.tbs / 8; + } + else + { std::cout << BOLDGREEN << std::setw(7) << "SUCCESS" << RESET; - std::cout << " -- Len: " << ul_cfg.pusch.grant.tb.tbs/8; + std::cout << " -- Len: " << ul_cfg.pusch.grant.tb.tbs / 8; } - if (decoding_mem.is_rar_gant){ + if (decoding_mem.is_rar_gant) + { std::cout << " -- RAR"; } if (decoding_mem.is_retx == 1) - { std::cout << " -- ReTX-UL";} + { + std::cout << " -- ReTX-UL"; + } std::cout << std::endl; } void PUSCH_Decoder::print_success(DCI_UL &decoding_mem, std::string offset_name, int table) { - std::cout << offset_name << "------->>>>>>" << " SF: " << (int)ul_sf.tti/10 << "-" << (int)ul_sf.tti%10; + std::cout << offset_name << "------->>>>>>" + << " SF: " << (int)ul_sf.tti / 10 << "-" << (int)ul_sf.tti % 10; std::cout << " Success RNTI: " << decoding_mem.rnti; - std::cout << " -- length: " << ul_cfg.pusch.grant.tb.tbs/8; - std::cout << " -- table: " << (table==1)?"64QAM":"16QAM"; + std::cout << " -- length: " << ul_cfg.pusch.grant.tb.tbs / 8; + std::cout << " -- table: " << (table == 1) ? "64QAM" : "16QAM"; std::cout << " -- TA(us): " << enb_ul.chest_res.ta_us; std::cout << " -- SNR: " << enb_ul.chest_res.snr_db << std::endl; } -void PUSCH_Decoder::print_ul_grant(srsran_pusch_grant_t& grant) +void PUSCH_Decoder::print_ul_grant(srsran_pusch_grant_t &grant) { std::cout << "Decoding PUSCH grant: " << std::endl; std::cout << "L_prb: " << grant.L_prb << std::endl; @@ -688,13 +804,17 @@ void PUSCH_Decoder::print_ul_grant(srsran_pusch_grant_t& grant) std::cout << "nof_re: " << grant.nof_re << std::endl; std::cout << "nof_symb: " << grant.nof_symb << std::endl; std::cout << "n_dmrs: " << grant.n_dmrs << std::endl; - std::cout << "tb: " << "mod: " << grant.tb.mod << " -- tbs: " << grant.tb.tbs << " -- rv: " << grant.tb.rv << "--mcs: " << grant.tb.mcs_idx << std::endl; - std::cout << "last_tb: " << "mod: " << grant.last_tb.mod << " -- tbs: " << grant.last_tb.tbs << " -- rv: " << grant.last_tb.rv << "--mcs: " << grant.last_tb.mcs_idx; + std::cout << "tb: " + << "mod: " << grant.tb.mod << " -- tbs: " << grant.tb.tbs << " -- rv: " << grant.tb.rv << "--mcs: " << grant.tb.mcs_idx << std::endl; + std::cout << "last_tb: " + << "mod: " << grant.last_tb.mod << " -- tbs: " << grant.last_tb.tbs << " -- rv: " << grant.last_tb.rv << "--mcs: " << grant.last_tb.mcs_idx; std::cout << "---------------------------------------" << std::endl; } -void PUSCH_Decoder::print_uci(srsran_uci_value_t *uci){ - if (uci->cqi.data_crc ==true){ +void PUSCH_Decoder::print_uci(srsran_uci_value_t *uci) +{ + if (uci->cqi.data_crc == true) + { std::cout << "[UCI] "; std::cout << " SR: " << uci->scheduling_request; std::cout << " -- RI: " << uci->ri << std::endl; @@ -704,81 +824,95 @@ void PUSCH_Decoder::print_uci(srsran_uci_value_t *uci){ } } -std::string convert_id_name(int id){\ +std::string convert_id_name(int id) +{ std::string ret = "-"; switch (id) { case ID_RAN_VAL: - ret = "RandomValue"; + ret = "RandomValue"; break; case ID_TMSI: - ret = "TMSI"; + ret = "TMSI"; break; case ID_CON_RES: - ret = "Contention Resolution"; + ret = "Contention Resolution"; break; case ID_IMSI: - ret = "IMSI"; + ret = "IMSI"; break; case ID_IMEI: - ret = "IMEI"; + ret = "IMEI"; break; case ID_IMEISV: - ret = "IMEISV"; + ret = "IMEISV"; break; default: - ret = "-"; + ret = "-"; break; } return ret; } -std::string convert_msg_name(int msg){ +std::string convert_msg_name(int msg) +{ std::string ret = "-"; switch (msg) { case 0: - ret = "RRC Connection Request"; + ret = "RRC Connection Request"; break; case 1: - ret = "RRC Connection Setup"; + ret = "RRC Connection Setup"; break; case 2: - ret = "Attach Request"; + ret = "Attach Request"; break; case 3: - ret = "Identity Response"; + ret = "Identity Response"; break; case 4: - ret = "UECapability"; + ret = "UECapability"; break; default: - ret = "-"; + ret = "-"; break; } return ret; } -void PUSCH_Decoder::print_api(uint32_t tti, uint16_t rnti, int id, std::string value, int msg){ - std::cout << std::left << std::setw(4) << tti/10 << "-" << std::left << std::setw(5) << tti%10; +void PUSCH_Decoder::print_api(uint32_t tti, uint16_t rnti, int id, std::string value, int msg) +{ + std::cout << std::left << std::setw(4) << tti / 10 << "-" << std::left << std::setw(5) << tti % 10; std::string id_name = convert_id_name(id); std::cout << std::left << std::setw(26) << id_name; - std::cout << std::left << std::setw(17) << value; + std::cout << std::left << std::setw(17) << value; std::cout << std::left << std::setw(11) << rnti; std::string msg_name = convert_msg_name(msg); std::cout << std::left << std::setw(25) << msg_name; std::cout << std::endl; } -int PUSCH_Decoder::investigate_valid_ul_grant(DCI_UL &decoding_mem){ +int PUSCH_Decoder::investigate_valid_ul_grant(DCI_UL &decoding_mem) +{ int ret = SRSRAN_SUCCESS; - if (decoding_mem.is_rar_gant){ return SRSRAN_SUCCESS;} + if (decoding_mem.is_rar_gant) + { + return SRSRAN_SUCCESS; + } /*if RNTI == 0*/ - if (decoding_mem.rnti == 0) { ret = SRSRAN_ERROR;} + if (decoding_mem.rnti == 0) + { + ret = SRSRAN_ERROR; + } /*if Transport Block size = 0 (wrong DCI detection or retransmission or pdsch for ack and uci)*/ - if (decoding_mem.ran_ul_grant->tb.tbs == 0 || decoding_mem.ran_ul_grant_256->tb.tbs == 0){ + if (decoding_mem.ran_ul_grant->tb.tbs == 0 || decoding_mem.ran_ul_grant_256->tb.tbs == 0) + { ret = SRSRAN_ERROR; } /*if number of PRB is invalid*/ - if (!check_valid_prb_ul(decoding_mem.ran_ul_grant->L_prb)){ ret = SRSRAN_ERROR;} + if (!check_valid_prb_ul(decoding_mem.ran_ul_grant->L_prb)) + { + ret = SRSRAN_ERROR; + } return ret; }