From 9b4245d92193249e39358b8415a6c05ce005108f Mon Sep 17 00:00:00 2001 From: Guido Casati Date: Tue, 15 Apr 2025 15:39:28 +0200 Subject: [PATCH] Add generation function and handler for NAS Authentication Failure --- openair3/NAS/NR_UE/5GS/NR_NAS_defs.h | 2 ++ openair3/NAS/NR_UE/5GS/fgs_nas_lib.c | 5 +++++ openair3/NAS/NR_UE/nr_nas_msg.c | 18 ++++++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/openair3/NAS/NR_UE/5GS/NR_NAS_defs.h b/openair3/NAS/NR_UE/5GS/NR_NAS_defs.h index 94e7f38a57..ab94925f09 100644 --- a/openair3/NAS/NR_UE/5GS/NR_NAS_defs.h +++ b/openair3/NAS/NR_UE/5GS/NR_NAS_defs.h @@ -35,6 +35,7 @@ #include "RegistrationComplete.h" #include "RegistrationRequest.h" #include "fgs_service_request.h" +#include "fgmm_authentication_failure.h" /* Message types defintions for: (a) 5GS Mobility Management (5GMM) (IDs 0x41 - 0x68) @@ -222,6 +223,7 @@ typedef struct { fgs_service_request_msg_t service_request; fgmm_identity_response_msg fgs_identity_response; fgs_authentication_response_msg fgs_auth_response; + fgmm_auth_failure_t fgmm_auth_failure; fgs_deregistration_request_ue_originating_msg fgs_deregistration_request_ue_originating; fgs_security_mode_complete_msg fgs_security_mode_complete; registration_complete_msg registration_complete; diff --git a/openair3/NAS/NR_UE/5GS/fgs_nas_lib.c b/openair3/NAS/NR_UE/5GS/fgs_nas_lib.c index 16d84f3ad8..ca40131af6 100644 --- a/openair3/NAS/NR_UE/5GS/fgs_nas_lib.c +++ b/openair3/NAS/NR_UE/5GS/fgs_nas_lib.c @@ -73,6 +73,11 @@ int mm_msg_encode(const fgmm_nas_message_plain_t *p, uint8_t *buffer, uint32_t l case FGS_AUTHENTICATION_RESPONSE: enc_msg = encode_fgs_authentication_response(&p->mm_msg.fgs_auth_response, buffer, len); break; + case FGS_AUTHENTICATION_FAILURE: { + byte_array_t ba = {.buf = buffer, .len = len}; + enc_msg = encode_fgmm_auth_failure(&ba, &p->mm_msg.fgmm_auth_failure); + break; + } case FGS_SECURITY_MODE_COMPLETE: enc_msg = encode_fgs_security_mode_complete(&p->mm_msg.fgs_security_mode_complete, buffer, len); break; diff --git a/openair3/NAS/NR_UE/nr_nas_msg.c b/openair3/NAS/NR_UE/nr_nas_msg.c index 941e0d7cdc..3640c40aaa 100644 --- a/openair3/NAS/NR_UE/nr_nas_msg.c +++ b/openair3/NAS/NR_UE/nr_nas_msg.c @@ -838,6 +838,24 @@ static void generateAuthenticationResp(nr_ue_nas_t *nas, as_nas_info_t *initialN free(res.value); } +/** @brief Send Authentication Failure message from the UE to the AMF to + * indicate that authentication of the network has failed */ +static void generateAuthenticationFailure(nr_ue_nas_t *nas, as_nas_info_t *initialNasMsg, cause_id_t cause) +{ + int size = sizeof(fgmm_msg_header_t); + fgmm_nas_message_plain_t plain = {0}; + + // Plain 5GMM header + plain.header = set_mm_header(FGS_AUTHENTICATION_FAILURE, PLAIN_5GS_MSG); + size += sizeof(plain.header); + // 5GMM Cause (Mandatory) + fgmm_auth_failure_t *mm_msg = &plain.mm_msg.fgmm_auth_failure; + mm_msg->cause = cause; + size += 1; + initialNasMsg->nas_data = malloc_or_fail(size * sizeof(*initialNasMsg->nas_data)); + initialNasMsg->length = mm_msg_encode(&plain, initialNasMsg->nas_data, size); +} + int nas_itti_kgnb_refresh_req(instance_t instance, const uint8_t kgnb[32]) { MessageDef *message_p;