From f47f65a51cae51c0c1b5c2268f2f2f52b162913b Mon Sep 17 00:00:00 2001 From: Sukchan Lee Date: Tue, 2 Feb 2021 13:33:09 -0500 Subject: [PATCH] fix: asn1c decode problem for NGReset (#773) --- lib/asn1c/common/aper_support.c | 29 +++++--- lib/asn1c/support/README.md | 112 ++++++++++++++++++++++++++++-- lib/ngap/build.c | 75 +++++++------------- src/amf/context.h | 4 ++ src/amf/ngap-handler.c | 119 +++++++++++++++++++++++--------- src/amf/nsmf-handler.c | 37 +++++++++- tests/registration/reset-test.c | 11 ++- tests/unit/abts-main.c | 2 - tests/unit/ngap-message-test.c | 27 ++++---- tests/unit/s1ap-message-test.c | 82 ++++++++++++++++++++++ 10 files changed, 375 insertions(+), 123 deletions(-) diff --git a/lib/asn1c/common/aper_support.c b/lib/asn1c/common/aper_support.c index 67ad9db57..1adbdde6b 100644 --- a/lib/asn1c/common/aper_support.c +++ b/lib/asn1c/common/aper_support.c @@ -22,7 +22,20 @@ aper_get_length(asn_per_data_t *pd, int range, int ebits, int *repeat) { *repeat = 0; - if (range <= 65536 && range >= 0) + /* + * ITU-T X.691(08/2015) + * #11.9.4.2 + * + * If the length determinant "n" to be encoded is a normally small length, + * or a constrained whole number with "ub" greater than or equal to 64K, + * or is a semi-constrained whole number, then "n" shall be encoded + * as specified in 11.9.3.4 to 11.9.3.8.4. + * + * NOTE – Thus, if "ub" is greater than or equal to 64K, + * the encoding of the length determinant is the same as it would be + * if the length were unconstrained. + */ + if (range <= 65535 && range >= 0) return aper_get_nsnnwn(pd, range); if (aper_get_align(pd) < 0) @@ -32,14 +45,14 @@ aper_get_length(asn_per_data_t *pd, int range, int ebits, int *repeat) { value = per_get_few_bits(pd, 8); if(value < 0) return -1; - if((value & 128) == 0) /* #10.9.3.6 */ + if((value & 128) == 0) /* #11.9.3.6 */ return (value & 0x7F); - if((value & 64) == 0) { /* #10.9.3.7 */ + if((value & 64) == 0) { /* #11.9.3.7 */ value = ((value & 63) << 8) | per_get_few_bits(pd, 8); if(value < 0) return -1; return value; } - value &= 63; /* this is "m" from X.691, #10.9.3.8 */ + value &= 63; /* this is "m" from X.691, #11.9.3.8 */ if(value < 1 || value > 4) return -1; *repeat = 1; @@ -162,18 +175,18 @@ aper_put_length(asn_per_outp_t *po, int range, size_t length, int *need_eom) { ASN_DEBUG("APER put length %zu with range %d", length, range); - /* 10.9 X.691 Note 2 */ + /* 11.9 X.691 Note 2 */ if (range <= 65536 && range >= 0) return aper_put_nsnnwn(po, range, length); if (aper_put_align(po) < 0) return -1; - if(length <= 127) /* #10.9.3.6 */{ + if(length <= 127) /* #11.9.3.6 */{ return per_put_few_bits(po, length, 8) ? -1 : (ssize_t)length; } - else if(length < 16384) /* #10.9.3.7 */ + else if(length < 16384) /* #11.9.3.7 */ return per_put_few_bits(po, length|0x8000, 16) ? -1 : (ssize_t)length; @@ -193,7 +206,7 @@ int aper_put_nslength(asn_per_outp_t *po, size_t length) { if(length <= 64) { - /* #10.9.3.4 */ + /* #11.9.3.4 */ if(length == 0) return -1; return per_put_few_bits(po, length-1, 7) ? -1 : 0; } else { diff --git a/lib/asn1c/support/README.md b/lib/asn1c/support/README.md index cbe5fdf26..ca8ff7d16 100644 --- a/lib/asn1c/support/README.md +++ b/lib/asn1c/support/README.md @@ -38,29 +38,131 @@ user@host ~/Documents/git/open5gs/lib/asn1c/ngap$ \ -no-gen-BER -no-gen-XER -no-gen-OER -no-gen-UPER \ ../support/ngap-r16.4.0/38413-g40.asn +Fix aper_support.c +=========================================== +diff --git a/lib/asn1c/common/aper_support.c b/lib/asn1c/common/aper_support.c +index 67ad9db5..1adbdde6 100644 +--- a/lib/asn1c/common/aper_support.c ++++ b/lib/asn1c/common/aper_support.c +@@ -22,7 +22,20 @@ aper_get_length(asn_per_data_t *pd, int range, int ebits, int *repeat) { + + *repeat = 0; + +- if (range <= 65536 && range >= 0) ++ /* ++ * ITU-T X.691(08/2015) ++ * #11.9.4.2 ++ * ++ * If the length determinant "n" to be encoded is a normally small length, ++ * or a constrained whole number with "ub" greater than or equal to 64K, ++ * or is a semi-constrained whole number, then "n" shall be encoded ++ * as specified in 11.9.3.4 to 11.9.3.8.4. ++ * ++ * NOTE – Thus, if "ub" is greater than or equal to 64K, ++ * the encoding of the length determinant is the same as it would be ++ * if the length were unconstrained. ++ */ ++ if (range <= 65535 && range >= 0) + return aper_get_nsnnwn(pd, range); + + if (aper_get_align(pd) < 0) +@@ -32,14 +45,14 @@ aper_get_length(asn_per_data_t *pd, int range, int ebits, int *repeat) { + + value = per_get_few_bits(pd, 8); + if(value < 0) return -1; +- if((value & 128) == 0) /* #10.9.3.6 */ ++ if((value & 128) == 0) /* #11.9.3.6 */ + return (value & 0x7F); +- if((value & 64) == 0) { /* #10.9.3.7 */ ++ if((value & 64) == 0) { /* #11.9.3.7 */ + value = ((value & 63) << 8) | per_get_few_bits(pd, 8); + if(value < 0) return -1; + return value; + } +- value &= 63; /* this is "m" from X.691, #10.9.3.8 */ ++ value &= 63; /* this is "m" from X.691, #11.9.3.8 */ + if(value < 1 || value > 4) + return -1; + *repeat = 1; +@@ -162,18 +175,18 @@ aper_put_length(asn_per_outp_t *po, int range, size_t length, int *need_eom) { + + ASN_DEBUG("APER put length %zu with range %d", length, range); + +- /* 10.9 X.691 Note 2 */ ++ /* 11.9 X.691 Note 2 */ + if (range <= 65536 && range >= 0) + return aper_put_nsnnwn(po, range, length); + + if (aper_put_align(po) < 0) + return -1; + +- if(length <= 127) /* #10.9.3.6 */{ ++ if(length <= 127) /* #11.9.3.6 */{ + return per_put_few_bits(po, length, 8) + ? -1 : (ssize_t)length; + } +- else if(length < 16384) /* #10.9.3.7 */ ++ else if(length < 16384) /* #11.9.3.7 */ + return per_put_few_bits(po, length|0x8000, 16) + ? -1 : (ssize_t)length; + +@@ -193,7 +206,7 @@ int + aper_put_nslength(asn_per_outp_t *po, size_t length) { + + if(length <= 64) { +- /* #10.9.3.4 */ ++ /* #11.9.3.4 */ + if(length == 0) return -1; + return per_put_few_bits(po, length-1, 7) ? -1 : 0; + } else { + + Fix NGAP_ProtocolExtensionField.c =========================================== -$ diff --git a/lib/asn1c/ngap/NGAP_ProtocolExtensionField.c b/lib/asn1c/ngap/NGAP_ProtocolExtensionField.c -index 2d0d96c7..d2e6b114 100644 +diff --git a/lib/asn1c/ngap/NGAP_ProtocolExtensionField.c b/lib/asn1c/ngap/NGAP_ProtocolExtensionField.c +index 4a23d705..3afbede8 100644 --- a/lib/asn1c/ngap/NGAP_ProtocolExtensionField.c +++ b/lib/asn1c/ngap/NGAP_ProtocolExtensionField.c -@@ -31124,11 +31124,7 @@ static asn_TYPE_member_t asn_MBR_NGAP_extensionValue_396[] = { +@@ -48809,11 +48809,7 @@ static asn_TYPE_member_t asn_MBR_NGAP_extensionValue_648[] = { 0, #endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ #if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) +#if 0 /* modified by acetcom */ - &asn_PER_memb_NGAP_OCTET_STRING_CONTAINING_PDUSessionResourceReleaseResponseTransfer__constr_17, + &asn_PER_memb_NGAP_OCTET_STRING_CONTAINING_PDUSessionResourceReleaseResponseTransfer__constr_43, +#else + 0, +#endif #endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ - memb_NGAP_OCTET_STRING_CONTAINING_PDUSessionResourceReleaseResponseTransfer__constraint_396 + memb_NGAP_OCTET_STRING_CONTAINING_PDUSessionResourceReleaseResponseTransfer__constraint_648 }, Check common file =========================================== user@host ~/Documents/git/open5gs/lib/asn1c/common$ \ git diff asn_internal.h +diff --git a/lib/asn1c/common/asn_internal.h b/lib/asn1c/common/asn_internal.h +index 71397a62..0b673a46 100644 +--- a/lib/asn1c/common/asn_internal.h ++++ b/lib/asn1c/common/asn_internal.h +@@ -34,18 +34,11 @@ extern "C" { + #define ASN1C_ENVIRONMENT_VERSION 923 /* Compile-time version */ + int get_asn1c_environment_version(void); /* Run-time version */ + ++#if 0 /* modified by acetcom */ ++#define CALLOC(nmemb, size) calloc(nmemb, size) ++#define MALLOC(size) malloc(size) ++#define REALLOC(oldptr, size) realloc(oldptr, size) ++#define FREEMEM(ptr) free(ptr) ++#else + #include "ogs-core.h" + #define CALLOC(nmemb, size) ogs_calloc(nmemb, size) + #define MALLOC(size) ogs_malloc(size) + #define REALLOC(oldptr, size) ogs_realloc(oldptr, size) + #define FREEMEM(ptr) ogs_free(ptr) ++#endif + + #define asn_debug_indent 0 + #define ASN_DEBUG_INDENT_ADD(i) do{}while(0) Check meson.build =========================================== diff --git a/lib/ngap/build.c b/lib/ngap/build.c index 37da3b3ba..d306a534f 100644 --- a/lib/ngap/build.c +++ b/lib/ngap/build.c @@ -189,9 +189,7 @@ ogs_pkbuf_t *ogs_ngap_build_ng_reset_ack( NGAP_SuccessfulOutcome_t *successfulOutcome = NULL; NGAP_NGResetAcknowledge_t *NGResetAcknowledge = NULL; -#if 0 NGAP_NGResetAcknowledgeIEs_t *ie = NULL; -#endif ogs_debug("Reset acknowledge"); @@ -208,74 +206,51 @@ ogs_pkbuf_t *ogs_ngap_build_ng_reset_ack( NGResetAcknowledge = &successfulOutcome->value.choice.NGResetAcknowledge; ogs_assert(NGResetAcknowledge); -#if 0 if (partOfNG_Interface && partOfNG_Interface->list.count) { int i = 0; - NGAP_UE_associatedLogicalNG_ConnectionListResAck_t *list = NULL; + NGAP_UE_associatedLogicalNG_connectionList_t *list = NULL; ie = CALLOC(1, sizeof(NGAP_NGResetAcknowledgeIEs_t)); + ogs_assert(ie); ASN_SEQUENCE_ADD(&NGResetAcknowledge->protocolIEs, ie); - ie->id = - NGAP_ProtocolIE_ID_id_UE_associatedLogicalNG_ConnectionListResAck; + ie->id = NGAP_ProtocolIE_ID_id_UE_associatedLogicalNG_connectionList; ie->criticality = NGAP_Criticality_ignore; - ie->value.present = NGAP_NGResetAcknowledgeIEs__value_PR_UE_associatedLogicalNG_ConnectionListResAck; + ie->value.present = NGAP_NGResetAcknowledgeIEs__value_PR_UE_associatedLogicalNG_connectionList; - list = &ie->value.choice.UE_associatedLogicalNG_ConnectionListResAck; + list = &ie->value.choice.UE_associatedLogicalNG_connectionList; for (i = 0; i < partOfNG_Interface->list.count; i++) { - NGAP_UE_associatedLogicalNG_ConnectionItemRes_t *ie1 = NULL; - NGAP_UE_associatedLogicalNG_ConnectionItem_t *item1 = NULL; + NGAP_UE_associatedLogicalNG_connectionItem_t *item = NULL; + uint64_t amf_ue_ngap_id = 0; + uint32_t ran_ue_ngap_id = 0; - NGAP_UE_associatedLogicalNG_ConnectionItemResAck_t *ie2 = NULL; - NGAP_UE_associatedLogicalNG_ConnectionItem_t *item2 = NULL; + item = partOfNG_Interface->list.array[i]; + ogs_assert(item); - ie1 = (NGAP_UE_associatedLogicalNG_ConnectionItemRes_t *) - partOfNG_Interface->list.array[i]; - ogs_assert(ie1); - - item1 = &ie1->value.choice.UE_associatedLogicalNG_ConnectionItem; - ogs_assert(item1); - - if (item1->mME_UE_NGAP_ID == NULL && - item1->eNB_UE_NGAP_ID == NULL) { - ogs_warn("No MME_UE_NGAP_ID & ENB_UE_NGAP_ID"); + if (item->aMF_UE_NGAP_ID == NULL && + item->rAN_UE_NGAP_ID == NULL) { + ogs_warn("No AMF_UE_NGAP_ID and RAN_UE_NGAP_ID"); continue; } - ie2 = CALLOC(1, - sizeof(NGAP_UE_associatedLogicalNG_ConnectionItemResAck_t)); - ogs_assert(ie2); - ASN_SEQUENCE_ADD(&list->list, ie2); + if (item->aMF_UE_NGAP_ID) + asn_INTEGER2ulong(item->aMF_UE_NGAP_ID, + (unsigned long *)&amf_ue_ngap_id); - ie2->id = - NGAP_ProtocolIE_ID_id_UE_associatedLogicalNG_ConnectionItem; - ie2->criticality = NGAP_Criticality_ignore; - ie2->value.present = NGAP_UE_associatedLogicalNG_ConnectionItemResAck__value_PR_UE_associatedLogicalNG_ConnectionItem; + if (item->rAN_UE_NGAP_ID) + ran_ue_ngap_id = *item->rAN_UE_NGAP_ID; - item2 = &ie2->value.choice.UE_associatedLogicalNG_ConnectionItem; - ogs_assert(item2); + ogs_ngap_build_part_of_ng_interface( + list, + item->rAN_UE_NGAP_ID ? &ran_ue_ngap_id : NULL, + item->aMF_UE_NGAP_ID ? &amf_ue_ngap_id : NULL); - if (item1->mME_UE_NGAP_ID) { - item2->mME_UE_NGAP_ID = CALLOC(1, - sizeof(NGAP_MME_UE_NGAP_ID_t)); - ogs_assert(item2->mME_UE_NGAP_ID); - *item2->mME_UE_NGAP_ID = *item1->mME_UE_NGAP_ID; - } - - if (item1->eNB_UE_NGAP_ID) { - item2->eNB_UE_NGAP_ID = CALLOC(1, - sizeof(NGAP_ENB_UE_NGAP_ID_t)); - ogs_assert(item2->eNB_UE_NGAP_ID); - *item2->eNB_UE_NGAP_ID = *item1->eNB_UE_NGAP_ID; - } - - ogs_debug(" MME_UE_NGAP_ID[%d] ENB_UE_NGAP_ID[%d]", - item2->mME_UE_NGAP_ID ? (int)*item2->mME_UE_NGAP_ID : -1, - item2->eNB_UE_NGAP_ID ? (int)*item2->eNB_UE_NGAP_ID : -1); + ogs_debug(" RAN_UE_NGAP_ID[%d] AMF_UE_NGAP_ID[%lld]", + item->rAN_UE_NGAP_ID ? ran_ue_ngap_id : -1, + item->aMF_UE_NGAP_ID ? (long long)amf_ue_ngap_id : -1); } } -#endif return ogs_ngap_encode(&pdu); } diff --git a/src/amf/context.h b/src/amf/context.h index d8599a48e..8a0d7d113 100644 --- a/src/amf/context.h +++ b/src/amf/context.h @@ -142,6 +142,8 @@ typedef struct amf_gnb_s { OpenAPI_rat_type_e rat_type; + ogs_pkbuf_t *ng_reset_ack; /* Reset message */ + ogs_list_t ran_ue_list; } amf_gnb_t; @@ -188,6 +190,8 @@ struct ran_ue_s { #define NGAP_UE_CTX_REL_NG_HANDOVER_FAILURE 6 uint8_t ue_ctx_rel_action; + bool part_of_ng_reset_requested; + /* Related Context */ amf_gnb_t *gnb; amf_ue_t *amf_ue; diff --git a/src/amf/ngap-handler.c b/src/amf/ngap-handler.c index 4677f4c16..bf8e7af56 100644 --- a/src/amf/ngap-handler.c +++ b/src/amf/ngap-handler.c @@ -3179,9 +3179,9 @@ void ngap_handle_ng_reset( NGAP_NGResetIEs_t *ie = NULL; NGAP_Cause_t *Cause = NULL; NGAP_ResetType_t *ResetType = NULL; -#if 0 NGAP_UE_associatedLogicalNG_connectionList_t *partOfNG_Interface = NULL; -#endif + + ran_ue_t *iter = NULL; ogs_assert(gnb); ogs_assert(gnb->sctp.sock); @@ -3270,52 +3270,103 @@ void ngap_handle_ng_reset( break; case NGAP_ResetType_PR_partOfNG_Interface: - ogs_fatal("Not implemented"); - ogs_assert_if_reached(); - ogs_warn(" NGAP_ResetType_PR_partOfNG_Interface"); -#if 0 + partOfNG_Interface = ResetType->choice.partOfNG_Interface; ogs_assert(partOfNG_Interface); for (i = 0; i < partOfNG_Interface->list.count; i++) { - NGAP_UE_associatedLogicalNG_ConnectionItemRes_t *ie2 = NULL; - NGAP_UE_associatedLogicalNG_ConnectionItem_t *item = NULL; + NGAP_UE_associatedLogicalNG_connectionItem_t *item = NULL; + uint64_t amf_ue_ngap_id; ran_ue_t *ran_ue = NULL; amf_ue_t *amf_ue = NULL; - ie2 = (NGAP_UE_associatedLogicalNG_ConnectionItemRes_t *) - partOfNG_Interface->list.array[i]; - ogs_assert(ie2); - - item = &ie2->value.choice.UE_associatedLogicalNG_ConnectionItem; - ogs_assert(item); - - ogs_warn(" MME_UE_NGAP_ID[%d] ENB_UE_NGAP_ID[%d]", - item->mME_UE_NGAP_ID ? (int)*item->mME_UE_NGAP_ID : -1, - item->eNB_UE_NGAP_ID ? (int)*item->eNB_UE_NGAP_ID : -1); - - if (item->mME_UE_NGAP_ID) - ran_ue = ran_ue_find_by_amf_ue_ngap_id( *item->mME_UE_NGAP_ID); - else if (item->eNB_UE_NGAP_ID) - ran_ue = ran_ue_find_by_ran_ue_ngap_id(gnb, - *item->eNB_UE_NGAP_ID); - - if (ran_ue == NULL) { - ogs_warn("Cannot find NG Context " - "(MME_UE_NGAP_ID[%d] ENB_UE_NGAP_ID[%d])", - item->mME_UE_NGAP_ID ? (int)*item->mME_UE_NGAP_ID : -1, - item->eNB_UE_NGAP_ID ? (int)*item->eNB_UE_NGAP_ID : -1); - continue; + item = (NGAP_UE_associatedLogicalNG_connectionItem_t *) + partOfNG_Interface->list.array[i]; + if (!item) { + ogs_error("No ResetType"); + ngap_send_error_indication( + gnb, NULL, NULL, + NGAP_Cause_PR_protocol, + NGAP_CauseProtocol_semantic_error); + return; } + if (item->aMF_UE_NGAP_ID) { + if (asn_INTEGER2ulong(item->aMF_UE_NGAP_ID, + (unsigned long *)&amf_ue_ngap_id) != 0) { + ogs_error("Invalid AMF_UE_NGAP_ID"); + ngap_send_error_indication( + gnb, NULL, NULL, + NGAP_Cause_PR_protocol, + NGAP_CauseProtocol_semantic_error); + return; + } + + ran_ue = ran_ue_find_by_amf_ue_ngap_id(amf_ue_ngap_id); + + if (!ran_ue) { + ogs_error("No RAN UE Context : AMF_UE_NGAP_ID[%lld]", + (long long)amf_ue_ngap_id); + ngap_send_error_indication( + gnb, NULL, &amf_ue_ngap_id, + NGAP_Cause_PR_radioNetwork, + NGAP_CauseRadioNetwork_unknown_local_UE_NGAP_ID); + return; + } + + } else if (item->rAN_UE_NGAP_ID) { + + ran_ue = ran_ue_find_by_ran_ue_ngap_id( + gnb, *item->rAN_UE_NGAP_ID); + + if (!ran_ue) { + ogs_error("No RAN UE Context : RAN_UE_NGAP_ID[%d]", + (int)*item->rAN_UE_NGAP_ID); + ngap_send_error_indication( + gnb, NULL, NULL, + NGAP_Cause_PR_radioNetwork, + NGAP_CauseRadioNetwork_unknown_local_UE_NGAP_ID); + return; + } + } + + ogs_assert(ran_ue); + + /* RAN_UE Context where PartOfNG_interface was requested */ + ran_ue->part_of_ng_reset_requested = true; + amf_ue = ran_ue->amf_ue; ogs_assert(amf_ue); - amf_gtp_send_release_access_bearers_request( - amf_ue, OGS_GTP_RELEASE_NG_CONTEXT_REMOVE); + amf_sbi_send_deactivate_all_sessions( + amf_ue, AMF_REMOVE_S1_CONTEXT_BY_RESET_PARTIAL, + NGAP_Cause_PR_radioNetwork, + NGAP_CauseRadioNetwork_failure_in_radio_interface_procedure); } -#endif + + if (gnb->ng_reset_ack) + ogs_pkbuf_free(gnb->ng_reset_ack); + + gnb->ng_reset_ack = ogs_ngap_build_ng_reset_ack(partOfNG_Interface); + ogs_expect_or_return(gnb->ng_reset_ack); + + ogs_list_for_each(&gnb->ran_ue_list, iter) { + if (iter->part_of_ng_reset_requested == true) { + /* The GNB_UE context + * where PartOfNG_interface was requested + * still remains */ + return; + } + } + + /* All GNB_UE context + * where PartOfNG_interface was requested + * REMOVED */ + ngap_send_to_gnb(gnb, gnb->ng_reset_ack, NGAP_NON_UE_SIGNALLING); + + /* Clear NG-Reset Ack Buffer */ + gnb->ng_reset_ack = NULL; break; default: ogs_warn("Invalid ResetType[%d]", ResetType->present); diff --git a/src/amf/nsmf-handler.c b/src/amf/nsmf-handler.c index dc372ef3e..66063242e 100644 --- a/src/amf/nsmf-handler.c +++ b/src/amf/nsmf-handler.c @@ -474,9 +474,42 @@ int amf_nsmf_pdusession_handle_update_sm_context( } } else if (state == AMF_REMOVE_S1_CONTEXT_BY_RESET_PARTIAL) { - ogs_fatal("Not implemented"); - ogs_assert_if_reached(); + if (SESSION_SYNC_DONE(amf_ue, state)) { + ran_ue_t *iter = NULL; + ran_ue_t *ran_ue = ran_ue_cycle(amf_ue->ran_ue); + amf_ue_deassociate(amf_ue); + + if (ran_ue) { + amf_gnb_t *gnb = ran_ue->gnb; + ogs_assert(gnb); + + ogs_debug(" SUPI[%s]", amf_ue->supi); + ran_ue_remove(ran_ue); + + ogs_list_for_each(&gnb->ran_ue_list, iter) { + if (iter->part_of_ng_reset_requested == true) { + /* The GNB_UE context + * where PartOfNG_interface was requested + * still remains */ + return OGS_OK; + } + } + + /* All GNB_UE context + * where PartOfNG_interface was requested + * REMOVED */ + ngap_send_to_gnb( + gnb, gnb->ng_reset_ack, NGAP_NON_UE_SIGNALLING); + + /* Clear NG-Reset Ack Buffer */ + gnb->ng_reset_ack = NULL; + + } else { + ogs_warn("[%s] RAN-NG Context has already been removed", + amf_ue->supi); + } + } } else { ogs_error("Invalid STATE[%d]", state); ogs_assert_if_reached(); diff --git a/tests/registration/reset-test.c b/tests/registration/reset-test.c index dc94acdf3..a548e1e08 100644 --- a/tests/registration/reset-test.c +++ b/tests/registration/reset-test.c @@ -363,7 +363,7 @@ static void test1_func(abts_case *tc, void *data) rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); - /* Receive UEContextReleaseCommand */ + /* Receive ErrorIndication */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); testngap_recv(test_ue, recvbuf); @@ -392,7 +392,6 @@ static void test1_func(abts_case *tc, void *data) test_ue_remove(test_ue); } -#if 0 static void test2_func(abts_case *tc, void *data) { int rv; @@ -674,7 +673,8 @@ static void test2_func(abts_case *tc, void *data) ogs_assert(partOfNG_Interface); ogs_ngap_build_part_of_ng_interface( - partOfNG_Interface, &test_ue->ran_ue_ngap_id, NULL); + partOfNG_Interface, + &test_ue->ran_ue_ngap_id, &test_ue->amf_ue_ngap_id); sendbuf = ogs_ngap_build_ng_reset( NGAP_Cause_PR_radioNetwork, @@ -699,7 +699,7 @@ static void test2_func(abts_case *tc, void *data) rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); - /* Receive UEContextReleaseCommand */ + /* Receive ErrorIndication */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); testngap_recv(test_ue, recvbuf); @@ -727,16 +727,13 @@ static void test2_func(abts_case *tc, void *data) /* Clear Test UE Context */ test_ue_remove(test_ue); } -#endif abts_suite *test_reset(abts_suite *suite) { suite = ADD_SUITE(suite) abts_run_test(suite, test1_func, NULL); -#if 0 abts_run_test(suite, test2_func, NULL); -#endif return suite; } diff --git a/tests/unit/abts-main.c b/tests/unit/abts-main.c index a0cc39847..e4a92605d 100644 --- a/tests/unit/abts-main.c +++ b/tests/unit/abts-main.c @@ -34,9 +34,7 @@ const struct testlist { {test_s1ap_message}, {test_nas_message}, {test_gtp_message}, -#if 0 {test_ngap_message}, -#endif {test_sbi_message}, {test_security}, {test_crash}, diff --git a/tests/unit/ngap-message-test.c b/tests/unit/ngap-message-test.c index c67a78ed0..d13521bf1 100644 --- a/tests/unit/ngap-message-test.c +++ b/tests/unit/ngap-message-test.c @@ -3,7 +3,6 @@ #include "amf/ngap-build.h" #include "test-common.h" -#if 0 static void ngap_message_test1(abts_case *tc, void *data) { ogs_pkbuf_t *pkbuf = NULL; @@ -50,13 +49,8 @@ static void ngap_message_test1(abts_case *tc, void *data) ogs_ngap_build_part_of_ng_interface(UE_associatedLogicalNG_connectionList, &ran_ue_ngap_id, &amf_ue_ngap_id); - ogs_log_install_domain(&__ogs_ngap_domain, "ngap", OGS_LOG_ERROR); - - asn_fprint(stdout, &asn_DEF_NGAP_NGAP_PDU, &pdu); - pkbuf = ogs_ngap_encode(&pdu); ogs_assert(pkbuf); - ogs_log_hexdump(OGS_LOG_FATAL, pkbuf->data, pkbuf->len); struct_ptr = &message; struct_size = sizeof(ogs_ngap_message_t); @@ -64,10 +58,12 @@ static void ngap_message_test1(abts_case *tc, void *data) memset(struct_ptr, 0, struct_size); dec_ret = aper_decode(NULL, &asn_DEF_NGAP_NGAP_PDU, (void **)&struct_ptr, pkbuf->data, pkbuf->len, 0, 0); - ogs_fatal("Failed to decode ASN-PDU [code:%d,consumed:%d]", - dec_ret.code, (int)dec_ret.consumed); + ABTS_INT_EQUAL(tc, 0, dec_ret.code); + ABTS_INT_EQUAL(tc, 128, dec_ret.consumed); + + ogs_ngap_free(&message); + ogs_pkbuf_free(pkbuf); } -#endif static void ngap_message_test2(abts_case *tc, void *data) { @@ -83,8 +79,6 @@ static void ngap_message_test2(abts_case *tc, void *data) size_t struct_size; asn_dec_rval_t dec_ret = {0}; - ogs_log_install_domain(&__ogs_ngap_domain, "ngap", OGS_LOG_ERROR); - pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN); ogs_assert(pkbuf); ogs_pkbuf_put_data(pkbuf, @@ -96,17 +90,20 @@ static void ngap_message_test2(abts_case *tc, void *data) memset(struct_ptr, 0, struct_size); dec_ret = aper_decode(NULL, &asn_DEF_NGAP_NGAP_PDU, (void **)&struct_ptr, pkbuf->data, pkbuf->len, 0, 0); - ogs_fatal("Failed to decode ASN-PDU [code:%d,consumed:%d]", - dec_ret.code, (int)dec_ret.consumed); + ABTS_INT_EQUAL(tc, 0, dec_ret.code); + ABTS_INT_EQUAL(tc, 184, dec_ret.consumed); + + ogs_ngap_free(&message); + ogs_pkbuf_free(pkbuf); } abts_suite *test_ngap_message(abts_suite *suite) { suite = ADD_SUITE(suite) -#if 0 + ogs_log_install_domain(&__ogs_ngap_domain, "ngap", OGS_LOG_ERROR); + abts_run_test(suite, ngap_message_test1, NULL); -#endif abts_run_test(suite, ngap_message_test2, NULL); return suite; diff --git a/tests/unit/s1ap-message-test.c b/tests/unit/s1ap-message-test.c index 1cf7dc269..15b9c68c4 100644 --- a/tests/unit/s1ap-message-test.c +++ b/tests/unit/s1ap-message-test.c @@ -188,6 +188,83 @@ static void s1ap_message_test7(abts_case *tc, void *data) ogs_pkbuf_free(pkbuf); } +#if 0 +static void s1ap_message_test8(abts_case *tc, void *data) +{ + /* ENBDirectInformationTransferRAN-INFORMATION-REQUEST */ + const char *payload = + "0025004a000001007900432036715489 0164f0000100010002548f0264f00000" + "010064f000400000002057974b81054c 84000000204f81005581014d860064f0" + "00000280094064f0000100010002"; + + ogs_s1ap_message_t message; + ogs_pkbuf_t *pkbuf; + int result; + char hexbuf[OGS_MAX_SDU_LEN]; + + pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN); + ogs_assert(pkbuf); + ogs_pkbuf_put_data(pkbuf, + OGS_HEX(payload, strlen(payload), hexbuf), 78); + + result = ogs_s1ap_decode(&message, pkbuf); + ABTS_INT_EQUAL(tc, 0, result); + ogs_s1ap_free(&message); + + ogs_pkbuf_free(pkbuf); +} + +static void s1ap_message_test9(abts_case *tc, void *data) +{ + /* ENBDirectInformationTransferRAN-INFORMATION-REQUEST */ + const char *payload = + "0025004a000001007900432036715489 0164f0000100010001548f0264f00000" + "010064f000400000002057974b81054c 840000001f4f81005581014d860064f0" + "00000180094064f0000100010001"; + + ogs_s1ap_message_t message; + ogs_pkbuf_t *pkbuf; + int result; + char hexbuf[OGS_MAX_SDU_LEN]; + + pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN); + ogs_assert(pkbuf); + ogs_pkbuf_put_data(pkbuf, + OGS_HEX(payload, strlen(payload), hexbuf), 78); + + result = ogs_s1ap_decode(&message, pkbuf); + ABTS_INT_EQUAL(tc, 0, result); + ogs_s1ap_free(&message); + + ogs_pkbuf_free(pkbuf); +} +#endif + +static void s1ap_message_test10(abts_case *tc, void *data) +{ + /* ENBDirectInformationTransferRAN-INFORMATION-REQUEST */ + const char *payload = + "0025004a000001007900432038715489 0064f000170001002d548f0254f42100" + "010054f421400000002057994b81014c 84000000014f81045581014d8864f000" + "170001002d0064f000170001002d"; + + ogs_s1ap_message_t message; + ogs_pkbuf_t *pkbuf; + int result; + char hexbuf[OGS_MAX_SDU_LEN]; + + pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN); + ogs_assert(pkbuf); + ogs_pkbuf_put_data(pkbuf, + OGS_HEX(payload, strlen(payload), hexbuf), 78); + + result = ogs_s1ap_decode(&message, pkbuf); + ABTS_INT_EQUAL(tc, 0, result); + ogs_s1ap_free(&message); + + ogs_pkbuf_free(pkbuf); +} + abts_suite *test_s1ap_message(abts_suite *suite) { suite = ADD_SUITE(suite) @@ -199,6 +276,11 @@ abts_suite *test_s1ap_message(abts_suite *suite) abts_run_test(suite, s1ap_message_test5, NULL); abts_run_test(suite, s1ap_message_test6, NULL); abts_run_test(suite, s1ap_message_test7, NULL); +#if 0 + abts_run_test(suite, s1ap_message_test8, NULL); + abts_run_test(suite, s1ap_message_test9, NULL); +#endif + abts_run_test(suite, s1ap_message_test10, NULL); return suite; }