diff --git a/openair3/NAS/NR_UE/5GS/tests/nas_lib_test.c b/openair3/NAS/NR_UE/5GS/tests/nas_lib_test.c index a73ee9b2be..2ccf78fa59 100644 --- a/openair3/NAS/NR_UE/5GS/tests/nas_lib_test.c +++ b/openair3/NAS/NR_UE/5GS/tests/nas_lib_test.c @@ -3,6 +3,7 @@ #include #include #include "common/utils/ds/byte_array.h" +#include "RegistrationAccept.h" #include "fgs_service_request.h" #include "fgmm_service_accept.h" #include "fgmm_service_reject.h" @@ -26,6 +27,65 @@ static bool eq_service_request(const fgs_service_request_msg_t *a, const fgs_ser return result; } +/** @brief Test regression of NAS Registration Accept decoding + * This test verifies that the NAS Registration Accept message + * is correctly decoded. It decodes a message as it received from + * the OAI CN5G and compares the output with the expected Registration Accept structure. + * The purpose of this regression test is to ensure that changes + * to the NAS decoder do not break the existing decoding behavior with OAI CN5G */ +static void test_regression_registration_accept(void) +{ + // Registration Accept message + registration_accept_msg orig = { + .guti = malloc_or_fail(sizeof(*orig.guti)), + .result = 0x01, + .nas_allowed_nssai[0].sst = 0x01, + .nas_allowed_nssai[1].sst = 0x02, + .nas_allowed_nssai[2].sst = 0x03, + .num_allowed_slices = 3, + .config_nssai[0].sst = 0x01, + .config_nssai[1].sst = 0x02, + .config_nssai[2].sst = 0x03, + .num_configured_slices = 3, + }; + + orig.guti->guti.typeofidentity = FGS_MOBILE_IDENTITY_5G_GUTI; + orig.guti->guti.amfpointer = 0x01; + orig.guti->guti.amfregionid = 0x02; + orig.guti->guti.amfsetid = 0x01; + orig.guti->guti.mccdigit1 = 0x00; + orig.guti->guti.mccdigit2 = 0x00; + orig.guti->guti.mccdigit3 = 0x01; + orig.guti->guti.mncdigit1 = 0x00; + orig.guti->guti.mncdigit2 = 0x01; + orig.guti->guti.mncdigit3 = 0x0F; + orig.guti->guti.tmsi = 0xb0207806; + orig.guti->guti.spare = 0b1111; + orig.guti->guti.oddeven = 0; + + // Encoded Registration Accept message from OAI CN5G + uint8_t cn5g_msg[] = {0x01, 0x01, // Registration Result + 0x77, 0x00, 0x0B, 0xF2, 0x00, 0xF1, 0x10, // 5G-GUTI + 0x02, 0x00, 0x41, 0xB0, 0x20, 0x78, 0x06, // 5G-GUTI + 0x15, 0x06, 0x01, 0x01, 0x01, 0x02, 0x01, 0x03, // Allowed N-NSSAI + 0x31, 0x06, 0x01, 0x01, 0x01, 0x02, 0x01, 0x03}; // Configured N-NSSAI + + // Decode NAS Registration Accept + int encoded_length; + registration_accept_msg decoded = {0}; + byte_array_t ba = {.buf = cn5g_msg, .len = sizeof(cn5g_msg)}; + encoded_length = decode_registration_accept(&decoded, ba); + AssertFatal(encoded_length >= 0, "encode_fgs_service_request() failed\n"); + + // Compare the raw encoded buffer with expected encoded data + bool ret = eq_fgmm_registration_accept(&orig, &decoded); + AssertFatal(ret, "Encoding mismatch!\n"); + + // Free dynamic allocated memory + free_fgmm_registration_accept(&orig); + free_fgmm_registration_accept(&decoded); +} + /** * @brief Test NAS Service Request enc/dec */ @@ -172,6 +232,7 @@ static void test_service_reject(void) int main() { + test_regression_registration_accept(); test_service_request(); test_service_accept(); test_service_reject();