diff --git a/lib/include/srslte/asn1/rrc_asn1_utils.h b/lib/include/srslte/asn1/rrc_asn1_utils.h index 3bfb92a71..f16341459 100644 --- a/lib/include/srslte/asn1/rrc_asn1_utils.h +++ b/lib/include/srslte/asn1/rrc_asn1_utils.h @@ -34,6 +34,7 @@ namespace rrc { struct plmn_id_s; struct s_tmsi_s; struct rlc_cfg_c; +struct pdcp_cfg_s; struct srb_to_add_mod_s; struct sched_request_cfg_c; struct mac_main_cfg_s; @@ -86,6 +87,8 @@ void to_asn1(asn1::rrc::rlc_cfg_c* asn1_type, const rlc_config_t& cfg); **************************/ srslte::pdcp_config_t make_srb_pdcp_config_t(const uint8_t bearer_id, bool is_ue); srslte::pdcp_config_t make_drb_pdcp_config_t(const uint8_t bearer_id, bool is_ue); +srslte::pdcp_config_t +make_drb_pdcp_config_t(const uint8_t bearer_id, bool is_ue, const asn1::rrc::pdcp_cfg_s& pdcp_cfg); /*************************** * MAC Config diff --git a/lib/src/asn1/rrc_asn1_utils.cc b/lib/src/asn1/rrc_asn1_utils.cc index 3cfea09e4..86e4fb546 100644 --- a/lib/src/asn1/rrc_asn1_utils.cc +++ b/lib/src/asn1/rrc_asn1_utils.cc @@ -213,6 +213,38 @@ srslte::pdcp_config_t make_drb_pdcp_config_t(const uint8_t bearer_id, bool is_ue return cfg; } +srslte::pdcp_config_t make_drb_pdcp_config_t(const uint8_t bearer_id, bool is_ue, const asn1::rrc::pdcp_cfg_s& pdcp_cfg) +{ + pdcp_config_t cfg = make_drb_pdcp_config_t(bearer_id, is_ue); + // TODO: complete config processing + if (pdcp_cfg.discard_timer_present) { + switch (pdcp_cfg.discard_timer.to_number()) { + case 10: + cfg.discard_timer = pdcp_discard_timer_t::ms10; + break; + default: + cfg.discard_timer = pdcp_discard_timer_t::infinity; + break; + } + } + + if (pdcp_cfg.t_reordering_r12_present) { + switch (pdcp_cfg.t_reordering_r12.to_number()) { + case 0: + cfg.t_reordering = pdcp_t_reordering_t::ms0; + break; + default: + cfg.t_reordering = pdcp_t_reordering_t::ms500; + } + } + + if (pdcp_cfg.rlc_am_present) { + // TODO: handle RLC AM config for PDCP + } + + return cfg; +} + /*************************** * MAC Config **************************/ diff --git a/srsenb/src/stack/rrc/rrc.cc b/srsenb/src/stack/rrc/rrc.cc index 20373541a..b946fb21e 100644 --- a/srsenb/src/stack/rrc/rrc.cc +++ b/srsenb/src/stack/rrc/rrc.cc @@ -1413,9 +1413,9 @@ void rrc::ue::setup_erab(uint8_t id, if (nas_pdu) { nas_pending = true; - memcpy(erab_info.buffer, nas_pdu->buffer, nas_pdu->n_octets); + memcpy(erab_info.msg, nas_pdu->buffer, nas_pdu->n_octets); erab_info.N_bytes = nas_pdu->n_octets; - parent->rrc_log->info_hex(erab_info.buffer, erab_info.N_bytes, "setup_erab nas_pdu -> erab_info rnti 0x%x", rnti); + parent->rrc_log->info_hex(erab_info.msg, erab_info.N_bytes, "setup_erab nas_pdu -> erab_info rnti 0x%x", rnti); } else { nas_pending = false; } @@ -1676,12 +1676,12 @@ int rrc::ue::get_drbid_config(drb_to_add_mod_s* drb, int drb_id) if (qci >= MAX_NOF_QCI) { parent->rrc_log->error("Invalid QCI=%d for ERAB_id=%d, DRB_id=%d\n", qci, erab_id, drb_id); - return -1; + return SRSLTE_ERROR; } if (!parent->cfg.qci_cfg[qci].configured) { parent->rrc_log->error("QCI=%d not configured\n", qci); - return -1; + return SRSLTE_ERROR; } // Add DRB1 to the message @@ -1702,7 +1702,7 @@ int rrc::ue::get_drbid_config(drb_to_add_mod_s* drb, int drb_id) drb->rlc_cfg_present = true; drb->rlc_cfg = parent->cfg.qci_cfg[qci].rlc_cfg; - return 0; + return SRSLTE_SUCCESS; } void rrc::ue::send_connection_reconf_upd(srslte::unique_byte_buffer_t pdu) @@ -1865,11 +1865,11 @@ void rrc::ue::send_connection_reconf(srslte::unique_byte_buffer_t pdu) // Add NAS Attach accept if (nas_pending) { parent->rrc_log->info_hex( - erab_info.buffer, erab_info.N_bytes, "connection_reconf erab_info -> nas_info rnti 0x%x\n", rnti); + erab_info.msg, erab_info.N_bytes, "connection_reconf erab_info -> nas_info rnti 0x%x\n", rnti); conn_reconf->ded_info_nas_list_present = true; conn_reconf->ded_info_nas_list.resize(1); conn_reconf->ded_info_nas_list[0].resize(erab_info.N_bytes); - memcpy(conn_reconf->ded_info_nas_list[0].data(), erab_info.buffer, erab_info.N_bytes); + memcpy(conn_reconf->ded_info_nas_list[0].data(), erab_info.msg, erab_info.N_bytes); } else { parent->rrc_log->debug("Not adding NAS message to connection reconfiguration\n"); conn_reconf->ded_info_nas_list.resize(0); @@ -1906,7 +1906,8 @@ void rrc::ue::send_connection_reconf_new_bearer(LIBLTE_S1AP_E_RABTOBESETUPLISTBE drb_to_add_mod_s drb_item; if (get_drbid_config(&drb_item, lcid - 2)) { parent->rrc_log->error("Getting DRB configuration\n"); - parent->rrc_log->console("ERROR: The QCI %d is invalid or not configured.\n", erabs[lcid + 4].qos_params.qCI.QCI); + parent->rrc_log->console("ERROR: The QCI %d is invalid or not configured.\n", erabs[id].qos_params.qCI.QCI); + // TODO: send S1AP response indicating error? return; } @@ -1919,28 +1920,29 @@ void rrc::ue::send_connection_reconf_new_bearer(LIBLTE_S1AP_E_RABTOBESETUPLISTBE parent->rlc->add_bearer(rnti, lcid, srslte::make_rlc_config_t(drb_item.rlc_cfg)); // Configure DRB in PDCP - srslte::pdcp_config_t pdcp_config = { - (uint8_t)(drb_item.drb_id - 1), // TODO: Review all ID mapping LCID DRB ERAB EPSBID Mapping - srslte::PDCP_RB_IS_DRB, - srslte::SECURITY_DIRECTION_DOWNLINK, - srslte::SECURITY_DIRECTION_UPLINK, - srslte::PDCP_SN_LEN_12, - srslte::pdcp_t_reordering_t::ms500, - srslte::pdcp_discard_timer_t::infinity}; - - parent->pdcp->add_bearer(rnti, lcid, pdcp_config); + // TODO: Review all ID mapping LCID DRB ERAB EPSBID Mapping + if (drb_item.pdcp_cfg_present) { + parent->pdcp->add_bearer( + rnti, lcid, srslte::make_drb_pdcp_config_t(drb_item.drb_id - 1, false, drb_item.pdcp_cfg)); + } else { + // use default config + parent->pdcp->add_bearer(rnti, lcid, srslte::make_drb_pdcp_config_t(drb_item.drb_id - 1, false)); + } // DRB has already been configured in GTPU through bearer setup - conn_reconf->rr_cfg_ded.drb_to_add_mod_list.push_back(drb_item); // Add NAS message - parent->rrc_log->info_hex( - erab_info.buffer, erab_info.N_bytes, "reconf_new_bearer erab_info -> nas_info rnti 0x%x\n", rnti); - asn1::dyn_octstring octstr(erab_info.N_bytes); - memcpy(octstr.data(), erab_info.msg, erab_info.N_bytes); - conn_reconf->ded_info_nas_list.push_back(octstr); + if (nas_pending) { + parent->rrc_log->info_hex( + erab_info.msg, erab_info.N_bytes, "reconf_new_bearer erab_info -> nas_info rnti 0x%x\n", rnti); + asn1::dyn_octstring octstr(erab_info.N_bytes); + memcpy(octstr.data(), erab_info.msg, erab_info.N_bytes); + conn_reconf->ded_info_nas_list.push_back(octstr); + conn_reconf->ded_info_nas_list_present = true; + } } + conn_reconf->rr_cfg_ded_present = true; conn_reconf->rr_cfg_ded.drb_to_add_mod_list_present = conn_reconf->rr_cfg_ded.drb_to_add_mod_list.size() > 0; conn_reconf->ded_info_nas_list_present = conn_reconf->ded_info_nas_list.size() > 0; diff --git a/srsenb/test/upper/rrc_mobility_test.cc b/srsenb/test/upper/rrc_mobility_test.cc index 304e38d07..0beabcee9 100644 --- a/srsenb/test/upper/rrc_mobility_test.cc +++ b/srsenb/test/upper/rrc_mobility_test.cc @@ -451,6 +451,85 @@ int test_mobility_class(mobility_test_params test_params) return SRSLTE_SUCCESS; } +int test_erab_setup(bool qci_exists) +{ + printf("\n===== TEST: test_erab_setup() =====\n"); + srslte::scoped_tester_log rrc_log("RRC "); + srslte::timer_handler timers; + srslte::unique_byte_buffer_t pdu; + + srsenb::all_args_t args; + rrc_cfg_t cfg; + TESTASSERT(test_helpers::parse_default_cfg(&cfg, args) == SRSLTE_SUCCESS); + + srsenb::rrc rrc; + mac_dummy mac; + rlc_dummy rlc; + test_dummies::pdcp_mobility_dummy pdcp; + phy_dummy phy; + test_dummies::s1ap_mobility_dummy s1ap; + gtpu_dummy gtpu; + rrc_log.set_level(srslte::LOG_LEVEL_INFO); + rrc_log.set_hex_limit(1024); + rrc.init(&cfg, &phy, &mac, &rlc, &pdcp, &s1ap, >pu, &timers, &rrc_log); + + auto tic = [&timers, &rrc] { + timers.step_all(); + rrc.tti_clock(); + }; + + uint16_t rnti = 0x46; + rrc.add_user(rnti); + + rrc_log.set_level(srslte::LOG_LEVEL_NONE); // mute all the startup log + + // Do all the handshaking until the first RRC Connection Reconf + test_helpers::bring_rrc_to_reconf_state(rrc, timers, rnti); + + rrc_log.set_level(srslte::LOG_LEVEL_DEBUG); + rrc_log.set_hex_limit(1024); + + // MME sends 2nd ERAB Setup request for DRB2 (QCI exists in config) + uint8_t drb2_erab_setup_request_ok[] = { + 0x00, 0x05, 0x00, 0x66, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, 0x08, 0x00, 0x02, 0x00, + 0x02, 0x00, 0x10, 0x00, 0x53, 0x00, 0x00, 0x11, 0x00, 0x4e, 0x0c, 0x00, 0x09, 0x21, 0x0f, 0x80, 0x7f, 0x00, + 0x00, 0x02, 0x00, 0x00, 0x00, 0x13, 0x3f, 0x27, 0x67, 0x90, 0x99, 0xf5, 0x05, 0x62, 0x02, 0xc1, 0x01, 0x09, + 0x09, 0x08, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x05, 0x01, 0x2d, 0x2d, 0x00, 0x0b, 0x27, 0x22, + 0x80, 0x80, 0x21, 0x10, 0x02, 0x00, 0x00, 0x10, 0x81, 0x06, 0x08, 0x08, 0x08, 0x08, 0x83, 0x06, 0x08, 0x08, + 0x04, 0x04, 0x00, 0x0d, 0x04, 0x08, 0x08, 0x08, 0x08, 0x00, 0x0d, 0x04, 0x08, 0x08, 0x04, 0x04}; + + // QCI doesn't exist (in default eNB DRB config) + uint8_t drb2_erab_setup_request_fail[] = { + 0x00, 0x05, 0x00, 0x75, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x64, 0x00, 0x08, 0x00, 0x02, 0x00, + 0x01, 0x00, 0x42, 0x00, 0x0a, 0x18, 0x3b, 0x9a, 0xca, 0x00, 0x60, 0x3b, 0x9a, 0xca, 0x00, 0x00, 0x10, 0x00, + 0x54, 0x00, 0x00, 0x11, 0x00, 0x4f, 0x0c, 0x00, 0x05, 0x3c, 0x0f, 0x80, 0x7f, 0x00, 0x01, 0x64, 0xb3, 0xce, + 0xf1, 0xc9, 0x40, 0x27, 0xfe, 0x2a, 0x3b, 0xd1, 0x03, 0x62, 0x70, 0xc1, 0x01, 0x05, 0x17, 0x03, 0x69, 0x6d, + 0x73, 0x06, 0x6d, 0x6e, 0x63, 0x30, 0x37, 0x30, 0x06, 0x6d, 0x63, 0x63, 0x39, 0x30, 0x31, 0x04, 0x67, 0x70, + 0x72, 0x73, 0x05, 0x01, 0xc0, 0xa8, 0x04, 0x02, 0x27, 0x15, 0x80, 0x80, 0x21, 0x0a, 0x03, 0x00, 0x00, 0x0a, + 0x81, 0x06, 0x08, 0x08, 0x08, 0x08, 0x00, 0x0d, 0x04, 0x08, 0x08, 0x08, 0x08}; + + LIBLTE_S1AP_S1AP_PDU_STRUCT s1ap_pdu; + LIBLTE_BYTE_MSG_STRUCT byte_buf; + if (qci_exists) { + byte_buf.N_bytes = sizeof(drb2_erab_setup_request_ok); + memcpy(byte_buf.msg, drb2_erab_setup_request_ok, byte_buf.N_bytes); + } else { + byte_buf.N_bytes = sizeof(drb2_erab_setup_request_fail); + memcpy(byte_buf.msg, drb2_erab_setup_request_fail, byte_buf.N_bytes); + } + + liblte_s1ap_unpack_s1ap_pdu(&byte_buf, &s1ap_pdu); + rrc.setup_ue_erabs(rnti, &s1ap_pdu.choice.initiatingMessage.choice.E_RABSetupRequest); + + if (qci_exists) { + TESTASSERT(rrc_log.error_counter == 0); + } else { + TESTASSERT(rrc_log.error_counter == 2); + } + + return SRSLTE_SUCCESS; +} + int main(int argc, char** argv) { log_h.set_level(srslte::LOG_LEVEL_INFO); @@ -460,13 +539,14 @@ int main(int argc, char** argv) return -1; } argparse::parse_args(argc, argv); - TESTASSERT(test_correct_insertion() == 0); TESTASSERT(test_correct_meascfg_calculation() == 0); TESTASSERT(test_mobility_class(mobility_test_params{mobility_test_params::test_fail_at::wrong_measreport}) == 0); TESTASSERT(test_mobility_class(mobility_test_params{mobility_test_params::test_fail_at::concurrent_ho}) == 0); TESTASSERT(test_mobility_class(mobility_test_params{mobility_test_params::test_fail_at::ho_prep_failure}) == 0); TESTASSERT(test_mobility_class(mobility_test_params{mobility_test_params::test_fail_at::success}) == 0); + TESTASSERT(test_erab_setup(true) == SRSLTE_SUCCESS); + TESTASSERT(test_erab_setup(false) == SRSLTE_SUCCESS); printf("\nSuccess\n");