Skip to content

Commit

Permalink
fix(amf): Registration reject handling for mimatching plmn
Browse files Browse the repository at this point in the history
Signed-off-by: Sathyaj27 <sathya.jayadev@wavelabs.ai>
  • Loading branch information
Sathyaj27 committed May 16, 2022
1 parent 3d097e6 commit dadf1c7
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
30 changes: 30 additions & 0 deletions lte/gateway/c/core/oai/tasks/amf/amf_recv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,36 @@ int amf_handle_registration_request(
* Extract the SUPI from SUCI directly as scheme is NULL */
if (msg->m5gs_mobile_identity.mobile_identity.imsi.type_of_identity ==
M5GSMobileIdentityMsg_SUCI_IMSI) {
bool is_plmn_present = false;
for (uint8_t i = 0; i < amf_config.guamfi.nb; i++) {
if ((msg->m5gs_mobile_identity.mobile_identity.imsi.mcc_digit2 ==
amf_config.guamfi.guamfi[i].plmn.mcc_digit2) &&
(msg->m5gs_mobile_identity.mobile_identity.imsi.mcc_digit1 ==
amf_config.guamfi.guamfi[i].plmn.mcc_digit1) &&
(msg->m5gs_mobile_identity.mobile_identity.imsi.mnc_digit3 ==
amf_config.guamfi.guamfi[i].plmn.mnc_digit3) &&
(msg->m5gs_mobile_identity.mobile_identity.imsi.mcc_digit3 ==
amf_config.guamfi.guamfi[i].plmn.mcc_digit3) &&
(msg->m5gs_mobile_identity.mobile_identity.imsi.mnc_digit2 ==
amf_config.guamfi.guamfi[i].plmn.mnc_digit2) &&
(msg->m5gs_mobile_identity.mobile_identity.imsi.mnc_digit1 ==
amf_config.guamfi.guamfi[i].plmn.mnc_digit1)) {
is_plmn_present = true;
}
}
if (!is_plmn_present) {
delete params;
amf_cause = AMF_CAUSE_INVALID_MANDATORY_INFO;
OAILOG_ERROR(LOG_NAS_AMF,
"UE PLMN mismatch"
"AMF rejecting the initial registration with "
"cause : %d for UE "
"ID: " AMF_UE_NGAP_ID_FMT,
amf_cause, ue_id);
rc = amf_proc_registration_reject(ue_id, amf_cause);
amf_free_ue_context(ue_context);
OAILOG_FUNC_RETURN(LOG_NAS_AMF, rc);
}
// Only considering protection scheme as NULL else return error.
if (msg->m5gs_mobile_identity.mobile_identity.imsi.protect_schm_id ==
MOBILE_IDENTITY_PROTECTION_SCHEME_NULL) {
Expand Down
15 changes: 15 additions & 0 deletions lte/gateway/c/core/oai/test/amf/test_amf_procedures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ class AMFAppProcedureTest : public ::testing::Test {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x2e,
0x08, 0x80, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

const uint8_t initial_ue_plmn_mismatch_message_hexbuf[23] = {
0x7e, 0x00, 0x41, 0x79, 0x00, 0x0d, 0x01, 0x00, 0x91, 0x10, 0xf0, 0xff,
0x00, 0x00, 0x79, 0x56, 0x54, 0x66, 0xf4, 0x2e, 0x02, 0xf0, 0xf0};

/* Guti based initial registration message */
const uint8_t guti_initial_ue_message_hexbuf[98] = {
0x7e, 0x01, 0x67, 0xb7, 0x6f, 0xc6, 0x03, 0x7e, 0x00, 0x41, 0x09,
Expand Down Expand Up @@ -394,6 +398,17 @@ TEST_F(AMFAppProcedureTest, TestRegistrationAuthSecurityCapabilityMismatch) {
EXPECT_TRUE(ue_context_p == nullptr);
}

TEST_F(AMFAppProcedureTest, TestRegistrationPlmnMismatch) {
amf_ue_ngap_id_t ue_id = 0;
/* Send the initial UE message */
imsi64_t imsi64 = 0;
imsi64 = send_initial_ue_message_no_tmsi(
amf_app_desc_p, 36, 1, 1, 0, plmn,
initial_ue_plmn_mismatch_message_hexbuf,
sizeof(initial_ue_plmn_mismatch_message_hexbuf));
EXPECT_EQ(get_ue_id_from_imsi(amf_app_desc_p, imsi64, &ue_id), 0);
}

TEST_F(AMFAppProcedureTest, TestRegistrationProcNoTMSI) {
amf_ue_ngap_id_t ue_id = 0;
std::vector<MessagesIds> expected_Ids{
Expand Down
7 changes: 7 additions & 0 deletions lte/gateway/c/core/oai/test/amf/test_amf_stateless.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,13 @@ class AMFAppStatelessTest : public ::testing::Test {
amf_config.use_stateless = true;
amf_nas_state_init(&amf_config);
create_state_matrix();
amf_config.guamfi.nb = 1;
amf_config.guamfi.guamfi[0].plmn = {.mcc_digit2 = 2,
.mcc_digit1 = 2,
.mnc_digit3 = 6,
.mcc_digit3 = 2,
.mnc_digit2 = 5,
.mnc_digit1 = 4};

init_task_context(TASK_MAIN, nullptr, 0, NULL, &amf_app_task_zmq_ctx);

Expand Down

0 comments on commit dadf1c7

Please sign in to comment.