Skip to content

Commit b9528ca

Browse files
FabianEckermanncodebot
authored andcommitted
cu_cp,rrc: await security mode command complete before sending rrc reconfiguration
1 parent c7df7f2 commit b9528ca

File tree

5 files changed

+47
-2
lines changed

5 files changed

+47
-2
lines changed

include/srsran/rrc/rrc_ue.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,11 @@ class rrc_ue_control_message_handler
198198
/// \returns The Security Mode Command context.
199199
virtual rrc_ue_security_mode_command_context get_security_mode_command_context() = 0;
200200

201+
/// \brief Await a RRC Security Mode Command Complete for a handover.
202+
/// \param[in] transaction_id The transaction ID of the RRC Security Mode Command Complete.
203+
/// \returns True if the RRC Security Mode Command Complete was received, false otherwise.
204+
virtual async_task<bool> handle_security_mode_command_complete_expected(uint8_t transaction_id) = 0;
205+
201206
/// \brief Handle an RRC Reconfiguration Request.
202207
/// \param[in] msg The new RRC Reconfiguration Request.
203208
/// \returns The result of the rrc reconfiguration.

lib/cu_cp/routines/initial_context_setup_routine.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,16 @@ void initial_context_setup_routine::operator()(
7676
}
7777
}
7878

79+
// Await Security Mode Command Complete from RRC UE
80+
{
81+
CORO_AWAIT_VALUE(security_mode_command_result,
82+
rrc_ue.handle_security_mode_command_complete_expected(rrc_smc_ctxt.transaction_id));
83+
if (!security_mode_command_result) {
84+
handle_failure();
85+
CORO_EARLY_RETURN(make_unexpected(fail_msg));
86+
}
87+
}
88+
7989
// Start UE Capability Enquiry Procedure
8090
{
8191
/// TODO: Move UE Capability Enquiry Procedure here

lib/cu_cp/routines/initial_context_setup_routine.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ class initial_context_setup_routine
5252
// (sub-)routine results
5353
f1ap_ue_context_setup_response ue_context_setup_response;
5454
cu_cp_pdu_session_resource_setup_response pdu_session_setup_response;
55-
bool rrc_reconfig_result = false; // the final UE reconfiguration
55+
bool security_mode_command_result = false;
56+
bool rrc_reconfig_result = false; // the final UE reconfiguration
5657
ngap_init_context_setup_failure fail_msg;
5758
ngap_init_context_setup_response resp_msg;
5859
};

lib/rrc/ue/rrc_ue_impl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class rrc_ue_impl final : public rrc_ue_interface, public rrc_ue_controller
6262

6363
// rrc_ue_control_message_handler
6464
rrc_ue_security_mode_command_context get_security_mode_command_context() override;
65+
async_task<bool> handle_security_mode_command_complete_expected(uint8_t transaction_id) override;
6566
async_task<bool> handle_rrc_reconfiguration_request(const rrc_reconfiguration_procedure_request& msg) override;
6667
rrc_ue_handover_reconfiguration_context
6768
get_rrc_ue_handover_reconfiguration_context(const rrc_reconfiguration_procedure_request& request) override;

lib/rrc/ue/rrc_ue_message_handlers.cpp

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ void rrc_ue_impl::handle_pdu(const srb_id_t srb_id, byte_buffer rrc_pdu)
150150
handle_rrc_transaction_complete(ul_dcch_msg, ul_dcch_msg.msg.c1().rrc_setup_complete().rrc_transaction_id);
151151
break;
152152
case ul_dcch_msg_type_c::c1_c_::types_opts::security_mode_complete:
153-
handle_security_mode_complete(ul_dcch_msg.msg.c1().security_mode_complete());
153+
handle_rrc_transaction_complete(ul_dcch_msg, ul_dcch_msg.msg.c1().security_mode_complete().rrc_transaction_id);
154154
break;
155155
case ul_dcch_msg_type_c::c1_c_::types_opts::ue_cap_info:
156156
handle_rrc_transaction_complete(ul_dcch_msg, ul_dcch_msg.msg.c1().ue_cap_info().rrc_transaction_id);
@@ -309,6 +309,34 @@ rrc_ue_security_mode_command_context rrc_ue_impl::get_security_mode_command_cont
309309
return smc_ctxt;
310310
}
311311

312+
async_task<bool> rrc_ue_impl::handle_security_mode_command_complete_expected(uint8_t transaction_id)
313+
{
314+
// arbitrary timeout for RRC Reconfig procedure, UE will be removed if timer fires
315+
const std::chrono::milliseconds timeout_ms{1000};
316+
317+
return launch_async(
318+
[this, timeout_ms, transaction_id, transaction = rrc_transaction{}](coro_context<async_task<bool>>& ctx) mutable {
319+
CORO_BEGIN(ctx);
320+
321+
logger.log_debug("Awaiting RRC Security Mode Command Complete (timeout={}ms)", timeout_ms.count());
322+
// create new transaction for RRC Security Mode Command procedure
323+
transaction = event_mng->transactions.create_transaction(transaction_id, timeout_ms);
324+
325+
CORO_AWAIT(transaction);
326+
327+
bool procedure_result = false;
328+
if (transaction.has_response()) {
329+
logger.log_debug("Received RRC Security Mode Command Complete");
330+
procedure_result = true;
331+
handle_security_mode_complete(transaction.response().msg.c1().security_mode_complete());
332+
} else {
333+
logger.log_debug("Did not receive RRC Security Mode Command Complete. Cause: timeout");
334+
}
335+
336+
CORO_RETURN(procedure_result);
337+
});
338+
}
339+
312340
async_task<bool> rrc_ue_impl::handle_rrc_reconfiguration_request(const rrc_reconfiguration_procedure_request& msg)
313341
{
314342
return launch_async<rrc_reconfiguration_procedure>(

0 commit comments

Comments
 (0)