diff --git a/configs/5gc-sample.yaml.in b/configs/5gc-sample.yaml.in new file mode 100644 index 000000000..48d46af60 --- /dev/null +++ b/configs/5gc-sample.yaml.in @@ -0,0 +1,100 @@ +db_uri: mongodb://localhost/open5gs + +logger: + +parameter: + +amf: + sbi: + - addr: 127.0.0.2 + port: 7777 + ngap: + - addr: 127.0.0.2 + guami: + - plmn_id: + mcc: 901 + mnc: 70 + amf_id: + region: 2 + set: 1 + tai: + - plmn_id: + mcc: 901 + mnc: 70 + tac: 1 + plmn: + - plmn_id: + mcc: 901 + mnc: 70 + s_nssai: + - sst: 1 + security: + integrity_order : [ NIA1, NIA2, NIA0 ] + ciphering_order : [ NEA0, NEA1, NEA2 ] + network_name: + full: Open5GS + amf_name: open5gs-amf0 + +smf: + sbi: + - addr: 127.0.0.3 + port: 7777 + gtpc: + - addr: 127.0.0.3 + - addr: ::1 + pfcp: + - addr: 127.0.0.3 + pdn: + - addr: 10.45.0.1/16 + - addr: cafe::1/64 + dns: + - 8.8.8.8 + - 8.8.4.4 + - 2001:4860:4860::8888 + - 2001:4860:4860::8844 + mtu: 1400 + freeDiameter: + identity: pgw.open-ims.test + realm: open-ims.test + listen_on: 127.0.0.3 + load_extension: + - module: @freediameter_extensions_builddir@/dbg_msg_dumps.fdx + conf: 0x8888 + - module: @freediameter_extensions_builddir@/dict_rfc5777.fdx + - module: @freediameter_extensions_builddir@/dict_mip6i.fdx + - module: @freediameter_extensions_builddir@/dict_nasreq.fdx + - module: @freediameter_extensions_builddir@/dict_nas_mipv6.fdx + - module: @freediameter_extensions_builddir@/dict_dcca.fdx + - module: @freediameter_extensions_builddir@/dict_dcca_3gpp.fdx + connect: + - identity: pcrf.open-ims.test + addr: 127.0.0.5 +upf: + pfcp: + - addr: 127.0.0.4 + gtpu: + - addr: + - 127.0.0.4 + - ::1 + pdn: + +ausf: + sbi: + - addr: 127.0.0.5 + port: 7777 + +udm: + sbi: + - addr: 127.0.0.6 + port: 7777 + +udr: + sbi: + - addr: 127.0.0.7 + port: 7777 +nrf: + sbi: + - addr: + - 127.0.0.1 + - ::1 + port: 7777 diff --git a/configs/5gc.yaml.in b/configs/5gc.yaml.in index a6f1ac97e..5bd8bbc63 100644 --- a/configs/5gc.yaml.in +++ b/configs/5gc.yaml.in @@ -11,11 +11,11 @@ amf: ngap: guami: - plmn_id: - mcc: 208 - mnc: 93 + mcc: 901 + mnc: 70 amf_id: - region: 202 - set: 1016 + region: 2 + set: 1 tai: - plmn_id: mcc: 901 @@ -72,9 +72,6 @@ upf: pfcp: addr: 127.0.0.4 gtpu: - - addr: - - 127.0.0.4 - - ::1 pdn: ausf: diff --git a/configs/meson.build b/configs/meson.build index e51947d85..8b30f69a4 100644 --- a/configs/meson.build +++ b/configs/meson.build @@ -35,6 +35,7 @@ endif example_conf = ''' 5gc.yaml + 5gc-sample.yaml minimal.yaml epc.yaml epc-fdconf.yaml diff --git a/configs/minimal.yaml.in b/configs/minimal.yaml.in index 867031906..d39e01f98 100644 --- a/configs/minimal.yaml.in +++ b/configs/minimal.yaml.in @@ -9,7 +9,7 @@ amf: - addr: 127.0.0.2 port: 7777 ngap: - - addr: 127.0.0.1 + - addr: 127.0.0.2 guami: - plmn_id: mcc: 208 diff --git a/configs/open5gs/upf.yaml.in b/configs/open5gs/upf.yaml.in index c1df02fc1..9e5870550 100644 --- a/configs/open5gs/upf.yaml.in +++ b/configs/open5gs/upf.yaml.in @@ -61,9 +61,6 @@ upf: pfcp: - addr: 127.0.0.4 gtpu: - - addr: - - 127.0.0.4 - - ::1 pdn: # diff --git a/lib/asn1c/util/conv.c b/lib/asn1c/util/conv.c index f47b1e8ab..d3811d0b4 100644 --- a/lib/asn1c/util/conv.c +++ b/lib/asn1c/util/conv.c @@ -130,6 +130,8 @@ int ogs_asn_BIT_STRING_to_ip(BIT_STRING_t *bit_string, ogs_ip_t *ip) ogs_assert(bit_string); ogs_assert(ip); + memset(ip, 0, sizeof(*ip)); + if (bit_string->size == OGS_IPV4V6_LEN) { ip->ipv4 = 1; ip->ipv6 = 1; diff --git a/lib/core/ogs-3gpp-types.c b/lib/core/ogs-3gpp-types.c index 365a616dd..756e31cb0 100644 --- a/lib/core/ogs-3gpp-types.c +++ b/lib/core/ogs-3gpp-types.c @@ -159,10 +159,6 @@ uint8_t ogs_amf_pointer(ogs_amf_id_t *amf_id) ogs_amf_id_t *ogs_amf_id_build(ogs_amf_id_t *amf_id, uint8_t region, uint16_t set, uint8_t pointer) { - ogs_assert(amf_id); - ogs_assert(region); - ogs_assert(set); - amf_id->region = region; amf_id->set1 = set >> 2; amf_id->set2 = set & 0x3; diff --git a/lib/core/ogs-3gpp-types.h b/lib/core/ogs-3gpp-types.h index 0dcacabd6..cd4437d5e 100644 --- a/lib/core/ogs-3gpp-types.h +++ b/lib/core/ogs-3gpp-types.h @@ -217,10 +217,10 @@ ogs_uint24_t ogs_s_nssai_sd_from_string(const char *hex); typedef struct ogs_ip_s { uint32_t addr; uint8_t addr6[OGS_IPV6_LEN]; - uint32_t len; -ED3(uint8_t ipv4:1;, - uint8_t ipv6:1;, - uint8_t reserved:6;) + uint32_t len; +ED3(uint8_t ipv4:1;, + uint8_t ipv6:1;, + uint8_t reserved:6;) } ogs_ip_t; int ogs_ip_to_sockaddr(ogs_ip_t *ip, uint16_t port, ogs_sockaddr_t **list); diff --git a/lib/crypt/ogs-crypt.h b/lib/crypt/ogs-crypt.h index e924ac3a6..09f88713c 100644 --- a/lib/crypt/ogs-crypt.h +++ b/lib/crypt/ogs-crypt.h @@ -51,6 +51,7 @@ extern "C" { #define OGS_AUTN_LEN 16 #define OGS_AUTS_LEN 14 #define OGS_MAX_RES_LEN 16 +#define OGS_MAC_S_LEN 8 #define OGS_SQN_XOR_AK_LEN 6 #define OGS_AK_LEN 6 diff --git a/lib/crypt/ogs-kdf.c b/lib/crypt/ogs-kdf.c index 12e1cadb4..274b5f46b 100644 --- a/lib/crypt/ogs-kdf.c +++ b/lib/crypt/ogs-kdf.c @@ -306,3 +306,32 @@ void ogs_kdf_nas_eps(uint8_t algorithm_type_distinguishers, memcpy(knas, output+16, 16); } +/* + * TS33.102 + * 6.3.3 Authentication and key agreement + * Re-use and re-transmission of (RAND, AUTN) + */ +void ogs_auc_sqn( + const uint8_t *opc, const uint8_t *k, + const uint8_t *rand, const uint8_t *conc_sqn_ms, + uint8_t *sqn_ms, uint8_t *mac_s) +{ + int i; + uint8_t ak[OGS_AK_LEN]; + /* + * The AMF used to calculate MAC-S assumes a dummy value of + * all zeros so that it does not need to be transmitted in the clear + * in the re-synch message. + */ + uint8_t amf[2] = { 0, 0 }; + + ogs_assert(opc); + ogs_assert(k); + ogs_assert(rand); + ogs_assert(conc_sqn_ms); + + milenage_f2345(opc, k, rand, NULL, NULL, NULL, NULL, ak); + for (i = 0; i < OGS_SQN_LEN; i++) + sqn_ms[i] = ak[i] ^ conc_sqn_ms[i]; + milenage_f1(opc, k, rand, sqn_ms, amf, NULL, mac_s); +} diff --git a/lib/crypt/ogs-kdf.h b/lib/crypt/ogs-kdf.h index e45aa239b..257fe7cb6 100644 --- a/lib/crypt/ogs-kdf.h +++ b/lib/crypt/ogs-kdf.h @@ -88,6 +88,16 @@ void ogs_kdf_nas_eps(uint8_t algorithm_type_distinguishers, uint8_t algorithm_identity, uint8_t *kasme, uint8_t *knas); +/* + * TS33.102 + * 6.3.3 Authentication and key agreement + * Re-use and re-transmission of (RAND, AUTN) + */ +void ogs_auc_sqn( + const uint8_t *opc, const uint8_t *k, + const uint8_t *rand, const uint8_t *conc_sqn_ms, + uint8_t *sqn_ms, uint8_t *mac_s); + #ifdef __cplusplus } #endif diff --git a/lib/nas/5gs/conv.c b/lib/nas/5gs/conv.c index e760c32db..7bbb60bb6 100644 --- a/lib/nas/5gs/conv.c +++ b/lib/nas/5gs/conv.c @@ -22,7 +22,7 @@ void ogs_nas_5gs_imsi_to_bcd( ogs_nas_5gs_mobile_identity_t *mobile_identity, char *imsi_bcd) { - ogs_nas_5gs_mobile_identity_imsi_t *mobile_identity_imsi = NULL; + ogs_nas_5gs_mobile_identity_suci_t *mobile_identity_suci = NULL; ogs_plmn_id_t plmn_id; char tmp[OGS_MAX_IMSI_BCD_LEN+1]; char *p, *last; @@ -33,11 +33,11 @@ void ogs_nas_5gs_imsi_to_bcd( p = imsi_bcd; last = imsi_bcd + OGS_MAX_IMSI_BCD_LEN + 1; - mobile_identity_imsi = - (ogs_nas_5gs_mobile_identity_imsi_t *)mobile_identity->buffer; - ogs_assert(mobile_identity_imsi); + mobile_identity_suci = + (ogs_nas_5gs_mobile_identity_suci_t *)mobile_identity->buffer; + ogs_assert(mobile_identity_suci); - ogs_nas_to_plmn_id(&plmn_id, &mobile_identity_imsi->nas_plmn_id); + ogs_nas_to_plmn_id(&plmn_id, &mobile_identity_suci->nas_plmn_id); if (ogs_plmn_id_mnc_len(&plmn_id) == 2) p = ogs_slprintf(p, last, "%03d%02d", ogs_plmn_id_mcc(&plmn_id), ogs_plmn_id_mnc(&plmn_id)); @@ -46,7 +46,7 @@ void ogs_nas_5gs_imsi_to_bcd( ogs_plmn_id_mcc(&plmn_id), ogs_plmn_id_mnc(&plmn_id)); ogs_assert(mobile_identity->length > 8); - ogs_buffer_to_bcd(mobile_identity_imsi->scheme_output, + ogs_buffer_to_bcd(mobile_identity_suci->scheme_output, mobile_identity->length - 8, tmp); p = ogs_slprintf(p, last, "%s", tmp); } @@ -54,7 +54,7 @@ void ogs_nas_5gs_imsi_to_bcd( char *ogs_nas_5gs_suci_from_mobile_identity( ogs_nas_5gs_mobile_identity_t *mobile_identity) { - ogs_nas_5gs_mobile_identity_imsi_t *mobile_identity_imsi = NULL; + ogs_nas_5gs_mobile_identity_suci_t *mobile_identity_suci = NULL; ogs_plmn_id_t plmn_id; char tmp[OGS_MAX_IMSI_BCD_LEN+1]; char routing_indicator[5]; @@ -62,14 +62,14 @@ char *ogs_nas_5gs_suci_from_mobile_identity( ogs_assert(mobile_identity); - mobile_identity_imsi = - (ogs_nas_5gs_mobile_identity_imsi_t *)mobile_identity->buffer; - ogs_assert(mobile_identity_imsi); + mobile_identity_suci = + (ogs_nas_5gs_mobile_identity_suci_t *)mobile_identity->buffer; + ogs_assert(mobile_identity_suci); - suci = ogs_msprintf("suci-%d-", mobile_identity_imsi->h.supi_format); + suci = ogs_msprintf("suci-%d-", mobile_identity_suci->h.supi_format); ogs_assert(suci); - ogs_nas_to_plmn_id(&plmn_id, &mobile_identity_imsi->nas_plmn_id); + ogs_nas_to_plmn_id(&plmn_id, &mobile_identity_suci->nas_plmn_id); if (ogs_plmn_id_mnc_len(&plmn_id) == 2) { suci = ogs_mstrcatf(suci, "%03d-%02d-", ogs_plmn_id_mcc(&plmn_id), ogs_plmn_id_mnc(&plmn_id)); @@ -81,31 +81,65 @@ char *ogs_nas_5gs_suci_from_mobile_identity( } memset(routing_indicator, 0, sizeof(routing_indicator)); - if (mobile_identity_imsi->routing_indicator1 != 0xf) { + if (mobile_identity_suci->routing_indicator1 != 0xf) { routing_indicator[0] = - mobile_identity_imsi->routing_indicator1 + '0'; - if (mobile_identity_imsi->routing_indicator2 != 0xf) { + mobile_identity_suci->routing_indicator1 + '0'; + if (mobile_identity_suci->routing_indicator2 != 0xf) { routing_indicator[1] = - mobile_identity_imsi->routing_indicator2 + '0'; - if (mobile_identity_imsi->routing_indicator3 != 0xf) { + mobile_identity_suci->routing_indicator2 + '0'; + if (mobile_identity_suci->routing_indicator3 != 0xf) { routing_indicator[2] = - mobile_identity_imsi->routing_indicator3 + '0'; - if (mobile_identity_imsi->routing_indicator4 != 0xf) + mobile_identity_suci->routing_indicator3 + '0'; + if (mobile_identity_suci->routing_indicator4 != 0xf) routing_indicator[3] = - mobile_identity_imsi->routing_indicator4 + '0'; + mobile_identity_suci->routing_indicator4 + '0'; } } } ogs_assert(mobile_identity->length > 8); - ogs_buffer_to_bcd(mobile_identity_imsi->scheme_output, + ogs_buffer_to_bcd(mobile_identity_suci->scheme_output, mobile_identity->length - 8, tmp); suci = ogs_mstrcatf(suci, "%s-%d-%d-%s", routing_indicator, - mobile_identity_imsi->protection_scheme_id, - mobile_identity_imsi->home_network_pki_value, + mobile_identity_suci->protection_scheme_id, + mobile_identity_suci->home_network_pki_value, tmp); return suci; } + +void ogs_nas_5gs_mobile_identity_guti_to_nas_guti( + ogs_nas_5gs_mobile_identity_guti_t *mobile_identity_guti, + ogs_nas_5gs_guti_t *nas_guti) +{ + ogs_assert(mobile_identity_guti); + ogs_assert(nas_guti); + + memset(nas_guti, 0, sizeof(*nas_guti)); + + memcpy(&nas_guti->nas_plmn_id, + &mobile_identity_guti->nas_plmn_id, OGS_PLMN_ID_LEN); + memcpy(&nas_guti->amf_id, + &mobile_identity_guti->amf_id, sizeof(ogs_amf_id_t)); + nas_guti->m_tmsi = be32toh(mobile_identity_guti->m_tmsi); +} + +void ogs_nas_5gs_nas_guti_to_mobilty_identity_guti( + ogs_nas_5gs_guti_t *nas_guti, + ogs_nas_5gs_mobile_identity_guti_t *mobile_identity_guti) +{ + ogs_assert(nas_guti); + ogs_assert(mobile_identity_guti); + + memset(mobile_identity_guti, 0, sizeof(*mobile_identity_guti)); + + mobile_identity_guti->h.type = OGS_NAS_5GS_MOBILE_IDENTITY_GUTI; + + memcpy(&mobile_identity_guti->nas_plmn_id, + &nas_guti->nas_plmn_id, OGS_PLMN_ID_LEN); + memcpy(&mobile_identity_guti->amf_id, + &nas_guti->amf_id, sizeof(ogs_amf_id_t)); + mobile_identity_guti->m_tmsi = htobe32(nas_guti->m_tmsi); +} diff --git a/lib/nas/5gs/conv.h b/lib/nas/5gs/conv.h index 43cfea499..5e5ea4b4c 100644 --- a/lib/nas/5gs/conv.h +++ b/lib/nas/5gs/conv.h @@ -36,6 +36,13 @@ void ogs_nas_5gs_imsi_to_bcd( char *ogs_nas_5gs_suci_from_mobile_identity( ogs_nas_5gs_mobile_identity_t *mobile_identity); +void ogs_nas_5gs_mobile_identity_guti_to_nas_guti( + ogs_nas_5gs_mobile_identity_guti_t *mobile_identity_guti, + ogs_nas_5gs_guti_t *nas_guti); +void ogs_nas_5gs_nas_guti_to_mobilty_identity_guti( + ogs_nas_5gs_guti_t *nas_guti, + ogs_nas_5gs_mobile_identity_guti_t *mobile_identity_guti); + #ifdef __cplusplus } #endif diff --git a/lib/nas/5gs/decoder.c b/lib/nas/5gs/decoder.c index af76d2693..03055d38c 100644 --- a/lib/nas/5gs/decoder.c +++ b/lib/nas/5gs/decoder.c @@ -28,7 +28,7 @@ /******************************************************************************* * This file had been created by nas-message.py script v0.2.0 * Please do not modify this file but regenerate it via script. - * Created on: 2020-06-15 13:46:04.094836 by acetcom + * Created on: 2020-06-19 19:55:35.949469 by acetcom * from 24501-g41.docx ******************************************************************************/ diff --git a/lib/nas/5gs/encoder.c b/lib/nas/5gs/encoder.c index b50917d2f..598838179 100644 --- a/lib/nas/5gs/encoder.c +++ b/lib/nas/5gs/encoder.c @@ -28,7 +28,7 @@ /******************************************************************************* * This file had been created by nas-message.py script v0.2.0 * Please do not modify this file but regenerate it via script. - * Created on: 2020-06-15 13:46:04.105762 by acetcom + * Created on: 2020-06-19 19:55:35.960740 by acetcom * from 24501-g41.docx ******************************************************************************/ diff --git a/lib/nas/5gs/ies.c b/lib/nas/5gs/ies.c index dba518e44..59719f965 100644 --- a/lib/nas/5gs/ies.c +++ b/lib/nas/5gs/ies.c @@ -28,7 +28,7 @@ /******************************************************************************* * This file had been created by nas-message.py script v0.2.0 * Please do not modify this file but regenerate it via script. - * Created on: 2020-06-15 13:46:04.075315 by acetcom + * Created on: 2020-06-19 19:55:35.932346 by acetcom * from 24501-g41.docx ******************************************************************************/ @@ -473,6 +473,8 @@ int ogs_nas_5gs_decode_allowed_pdu_session_status(ogs_nas_allowed_pdu_session_st ogs_assert(ogs_pkbuf_pull(pkbuf, size)); memcpy(allowed_pdu_session_status, pkbuf->data - size, size); + allowed_pdu_session_status->psi = be16toh(allowed_pdu_session_status->psi); + ogs_trace(" ALLOWED_PDU_SESSION_STATUS - "); ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size); @@ -485,6 +487,8 @@ int ogs_nas_5gs_encode_allowed_pdu_session_status(ogs_pkbuf_t *pkbuf, ogs_nas_al ogs_nas_allowed_pdu_session_status_t target; memcpy(&target, allowed_pdu_session_status, sizeof(ogs_nas_allowed_pdu_session_status_t)); + target.psi = htobe16(allowed_pdu_session_status->psi); + ogs_assert(ogs_pkbuf_pull(pkbuf, size)); memcpy(pkbuf->data - size, &target, size); @@ -1861,6 +1865,8 @@ int ogs_nas_5gs_decode_pdu_session_reactivation_result(ogs_nas_pdu_session_react ogs_assert(ogs_pkbuf_pull(pkbuf, size)); memcpy(pdu_session_reactivation_result, pkbuf->data - size, size); + pdu_session_reactivation_result->psi = be16toh(pdu_session_reactivation_result->psi); + ogs_trace(" PDU_SESSION_REACTIVATION_RESULT - "); ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size); @@ -1873,6 +1879,8 @@ int ogs_nas_5gs_encode_pdu_session_reactivation_result(ogs_pkbuf_t *pkbuf, ogs_n ogs_nas_pdu_session_reactivation_result_t target; memcpy(&target, pdu_session_reactivation_result, sizeof(ogs_nas_pdu_session_reactivation_result_t)); + target.psi = htobe16(pdu_session_reactivation_result->psi); + ogs_assert(ogs_pkbuf_pull(pkbuf, size)); memcpy(pkbuf->data - size, &target, size); @@ -1937,6 +1945,8 @@ int ogs_nas_5gs_decode_pdu_session_status(ogs_nas_pdu_session_status_t *pdu_sess ogs_assert(ogs_pkbuf_pull(pkbuf, size)); memcpy(pdu_session_status, pkbuf->data - size, size); + pdu_session_status->psi = be16toh(pdu_session_status->psi); + ogs_trace(" PDU_SESSION_STATUS - "); ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size); @@ -1949,6 +1959,8 @@ int ogs_nas_5gs_encode_pdu_session_status(ogs_pkbuf_t *pkbuf, ogs_nas_pdu_sessio ogs_nas_pdu_session_status_t target; memcpy(&target, pdu_session_status, sizeof(ogs_nas_pdu_session_status_t)); + target.psi = htobe16(pdu_session_status->psi); + ogs_assert(ogs_pkbuf_pull(pkbuf, size)); memcpy(pkbuf->data - size, &target, size); @@ -2497,6 +2509,8 @@ int ogs_nas_5gs_decode_uplink_data_status(ogs_nas_uplink_data_status_t *uplink_d ogs_assert(ogs_pkbuf_pull(pkbuf, size)); memcpy(uplink_data_status, pkbuf->data - size, size); + uplink_data_status->psi = be16toh(uplink_data_status->psi); + ogs_trace(" UPLINK_DATA_STATUS - "); ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size); @@ -2509,6 +2523,8 @@ int ogs_nas_5gs_encode_uplink_data_status(ogs_pkbuf_t *pkbuf, ogs_nas_uplink_dat ogs_nas_uplink_data_status_t target; memcpy(&target, uplink_data_status, sizeof(ogs_nas_uplink_data_status_t)); + target.psi = htobe16(uplink_data_status->psi); + ogs_assert(ogs_pkbuf_pull(pkbuf, size)); memcpy(pkbuf->data - size, &target, size); diff --git a/lib/nas/5gs/ies.h b/lib/nas/5gs/ies.h index 99cd5b610..1029d333a 100644 --- a/lib/nas/5gs/ies.h +++ b/lib/nas/5gs/ies.h @@ -28,7 +28,7 @@ /******************************************************************************* * This file had been created by nas-message.py script v0.2.0 * Please do not modify this file but regenerate it via script. - * Created on: 2020-06-15 13:46:04.070975 by acetcom + * Created on: 2020-06-19 19:55:35.929537 by acetcom * from 24501-g41.docx ******************************************************************************/ diff --git a/lib/nas/5gs/message.h b/lib/nas/5gs/message.h index b634a3f59..ce4234b25 100644 --- a/lib/nas/5gs/message.h +++ b/lib/nas/5gs/message.h @@ -28,7 +28,7 @@ /******************************************************************************* * This file had been created by nas-message.py script v0.2.0 * Please do not modify this file but regenerate it via script. - * Created on: 2020-06-15 13:46:04.086829 by acetcom + * Created on: 2020-06-19 19:55:35.941362 by acetcom * from 24501-g41.docx ******************************************************************************/ diff --git a/lib/nas/5gs/support/type-list.py b/lib/nas/5gs/support/type-list.py index 27044ba1d..bac40a083 100644 --- a/lib/nas/5gs/support/type-list.py +++ b/lib/nas/5gs/support/type-list.py @@ -44,3 +44,20 @@ type_list["Session-AMBR"]["decode"] = \ type_list["Session-AMBR"]["encode"] = \ " target.downlink.bitrate = htobe16(session_ambr->downlink.bitrate);\n" \ " target.uplink.bitrate = htobe16(session_ambr->uplink.bitrate);\n\n" + +type_list["Uplink data status"]["decode"] = \ +" uplink_data_status->psi = be16toh(uplink_data_status->psi);\n\n" +type_list["Uplink data status"]["encode"] = \ +" target.psi = htobe16(uplink_data_status->psi);\n\n" +type_list["Allowed PDU session status"]["decode"] = \ +" allowed_pdu_session_status->psi = be16toh(allowed_pdu_session_status->psi);\n\n" +type_list["Allowed PDU session status"]["encode"] = \ +" target.psi = htobe16(allowed_pdu_session_status->psi);\n\n" +type_list["PDU session status"]["decode"] = \ +" pdu_session_status->psi = be16toh(pdu_session_status->psi);\n\n" +type_list["PDU session status"]["encode"] = \ +" target.psi = htobe16(pdu_session_status->psi);\n\n" +type_list["PDU session reactivation result"]["decode"] = \ +" pdu_session_reactivation_result->psi = be16toh(pdu_session_reactivation_result->psi);\n\n" +type_list["PDU session reactivation result"]["encode"] = \ +" target.psi = htobe16(pdu_session_reactivation_result->psi);\n\n" diff --git a/lib/nas/5gs/types.h b/lib/nas/5gs/types.h index 6aa0aa460..f643cd21c 100644 --- a/lib/nas/5gs/types.h +++ b/lib/nas/5gs/types.h @@ -149,7 +149,7 @@ ED4(uint8_t spare1:1;, uint8_t odd_even:1;, uint8_t type:3;) } __attribute__ ((packed)) ogs_nas_5gs_mobile_identity_header_t; -typedef struct ogs_nas_5gs_mobile_identity_imsi_s { +typedef struct ogs_nas_5gs_mobile_identity_suci_s { ogs_nas_5gs_mobile_identity_header_t h; ogs_nas_plmn_id_t nas_plmn_id; ED2(uint8_t routing_indicator2:4;, @@ -163,7 +163,7 @@ ED2(uint8_t spare3:4;, uint8_t protection_scheme_id:4;) uint8_t home_network_pki_value; uint8_t scheme_output[OGS_NAS_MAX_SCHEME_OUTPUT_LEN]; -} __attribute__ ((packed)) ogs_nas_5gs_mobile_identity_imsi_t; +} __attribute__ ((packed)) ogs_nas_5gs_mobile_identity_suci_t; typedef struct ogs_nas_5gs_mobile_identity_guti_s { ogs_nas_5gs_mobile_identity_header_t h; ogs_nas_plmn_id_t nas_plmn_id; @@ -172,7 +172,9 @@ typedef struct ogs_nas_5gs_mobile_identity_guti_s { } __attribute__ ((packed)) ogs_nas_5gs_mobile_identity_guti_t; typedef struct ogs_nas_5gs_mobile_identity_s_tmsi_s { ogs_nas_5gs_mobile_identity_header_t h; - ogs_amf_id_t amf_id; + uint8_t set1; +ED2(uint8_t set2:2;, + uint8_t pointer:6;) uint32_t m_tmsi; } __attribute__ ((packed)) ogs_nas_5gs_mobile_identity_s_tmsi_t; typedef struct ogs_nas_5gs_mobile_identity_s { @@ -321,22 +323,7 @@ ED2(uint8_t spare:7;, * O TLV 4-34 */ typedef struct ogs_nas_allowed_pdu_session_status_s { uint8_t length; -ED8(uint8_t psi7:1;, - uint8_t psi6:1;, - uint8_t psi5:1;, - uint8_t psi4:1;, - uint8_t psi3:1;, - uint8_t psi2:1;, - uint8_t psi1:1;, - uint8_t hdr0:1;) -ED8(uint8_t psi15:1;, - uint8_t psi14:1;, - uint8_t psi13:1;, - uint8_t psi12:1;, - uint8_t psi11:1;, - uint8_t psi10:1;, - uint8_t psi9:1;, - uint8_t psi8:1;) + uint16_t psi; } __attribute__ ((packed)) ogs_nas_allowed_pdu_session_status_t; /* 9.11.3.18 Configuration update indication @@ -386,10 +373,11 @@ ED3(uint8_t type:4;, /* 9.11.3.20 De-registration type * M V 1/2 */ typedef struct ogs_nas_de_registration_type_s { -ED4(uint8_t type:4;, +ED5(uint8_t tsc:1;, + uint8_t ksi:3;, uint8_t switch_off:1;, uint8_t re_registration_required:1;, - uint8_t value:1;) + uint8_t access_type:2;) } __attribute__ ((packed)) ogs_nas_de_registration_type_t; /* 9.11.3.24 EPS NAS message container diff --git a/lib/nas/common/conv.c b/lib/nas/common/conv.c index c0551236b..e2ab3ccec 100644 --- a/lib/nas/common/conv.c +++ b/lib/nas/common/conv.c @@ -19,66 +19,6 @@ #include "ogs-nas-common.h" -void ogs_nas_eps_imsi_to_bcd( - ogs_nas_mobile_identity_imsi_t *imsi, uint8_t imsi_len, char *bcd) -{ - int bcd_len; - - bcd[0] = '0' + imsi->digit1; - bcd[1] = '0' + imsi->digit2; - bcd[2] = '0' + imsi->digit3; - bcd[3] = '0' + imsi->digit4; - bcd[4] = '0' + imsi->digit5; - bcd[5] = '0' + imsi->digit6; - bcd[6] = '0' + imsi->digit7; - bcd[7] = '0' + imsi->digit8; - bcd[8] = '0' + imsi->digit9; - bcd[9] = '0' + imsi->digit10; - bcd[10] = '0' + imsi->digit11; - bcd[11] = '0' + imsi->digit12; - bcd[12] = '0' + imsi->digit13; - bcd[13] = '0' + imsi->digit14; - bcd[14] = '0' + imsi->digit15; - - bcd_len = imsi_len * 2 - 1; - if (!imsi->odd_even) { /* if bcd length is even */ - if (imsi->digit15 != 0xf) - ogs_warn("Spec warning : bcd[%d] = 0x%x, 0x%x", - bcd_len-1, imsi->digit15, bcd[bcd_len-1]); - (bcd_len)--; - } - - bcd[bcd_len] = 0; -} - -void ogs_nas_imsi_to_buffer( - ogs_nas_mobile_identity_imsi_t *imsi, uint8_t imsi_len, - uint8_t *buf, uint8_t *buf_len) -{ - buf[0] = ((('0' + imsi->digit2) << 4) & 0xf0) | - (('0' + imsi->digit1) & 0x0f); - buf[1] = ((('0' + imsi->digit4) << 4) & 0xf0) | - (('0' + imsi->digit3) & 0x0f); - buf[2] = ((('0' + imsi->digit6) << 4) & 0xf0) | - (('0' + imsi->digit5) & 0x0f); - buf[3] = ((('0' + imsi->digit8) << 4) & 0xf0) | - (('0' + imsi->digit7) & 0x0f); - buf[4] = ((('0' + imsi->digit10) << 4) & 0xf0) | - (('0' + imsi->digit9) & 0x0f); - buf[5] = ((('0' + imsi->digit12) << 4) & 0xf0) | - (('0' + imsi->digit11) & 0x0f); - buf[6] = ((('0' + imsi->digit14) << 4) & 0xf0) | - (('0' + imsi->digit13) & 0x0f); - buf[7] = ((('0' + imsi->digit15)) & 0x0f); - - *buf_len = imsi_len; - if (!imsi->odd_even) { /* if imsi length is even */ - (*buf_len)--; - if ((buf[*buf_len] & 0xf) != 0xf) - ogs_warn("Spec warning : buf[%d] = 0x%x", *buf_len, buf[*buf_len]); - } -} - void ogs_nas_imeisv_to_bcd( ogs_nas_mobile_identity_imeisv_t *imeisv, uint8_t imeisv_len, char *bcd) { diff --git a/lib/nas/common/conv.h b/lib/nas/common/conv.h index 187c4b626..195f5fee2 100644 --- a/lib/nas/common/conv.h +++ b/lib/nas/common/conv.h @@ -30,13 +30,6 @@ extern "C" { #endif -void ogs_nas_imsi_to_buffer( - ogs_nas_mobile_identity_imsi_t *imsi, uint8_t imsi_len, - uint8_t *buf, uint8_t *buf_len); - -void ogs_nas_eps_imsi_to_bcd( - ogs_nas_mobile_identity_imsi_t *imsi, uint8_t imsi_len, char *bcd); - void ogs_nas_imeisv_to_bcd( ogs_nas_mobile_identity_imeisv_t *imeisv, uint8_t imeisv_len, char *bcd); diff --git a/lib/nas/common/types.h b/lib/nas/common/types.h index 97f21452d..ec6713b6f 100644 --- a/lib/nas/common/types.h +++ b/lib/nas/common/types.h @@ -127,59 +127,6 @@ ED8(uint8_t ebi15:1;, uint8_t ebi8:1;) } __attribute__ ((packed)) ogs_nas_eps_bearer_context_status_t; -/* 9.9.2.3 Mobile identity - * See subclause 10.5.1.4 in 3GPP TS 24.008 [13]. - * O TLV 7-10 */ -#define OGS_NAS_MOBILE_IDENTITY_NONE 0 -#define OGS_NAS_MOBILE_IDENTITY_IMSI 1 -#define OGS_NAS_MOBILE_IDENTITY_IMEI 2 -#define OGS_NAS_MOBILE_IDENTITY_IMEISV 3 -#define OGS_NAS_MOBILE_IDENTITY_TMSI 4 -#define OGS_NAS_MOBILE_IDENTITY_TMGI 5 -#define OGS_NAS_MOBILE_IDENTITY_GUTI 6 - -#define OGS_NAS_MOBILE_IDENTITY_EVEN 0 -#define OGS_NAS_MOBILE_IDENTITY_ODD 1 -typedef struct ogs_nas_mobile_identity_imsi_s { -ED3(uint8_t digit1:4;, - uint8_t odd_even:1;, - uint8_t type:3;) -ED2(uint8_t digit3:4;, - uint8_t digit2:4;) -ED2(uint8_t digit5:4;, - uint8_t digit4:4;) -ED2(uint8_t digit7:4;, - uint8_t digit6:4;) -ED2(uint8_t digit9:4;, - uint8_t digit8:4;) -ED2(uint8_t digit11:4;, - uint8_t digit10:4;) -ED2(uint8_t digit13:4;, - uint8_t digit12:4;) -ED2(uint8_t digit15:4;, - uint8_t digit14:4;) -} __attribute__ ((packed)) ogs_nas_mobile_identity_imsi_t; - -typedef ogs_nas_mobile_identity_imsi_t ogs_nas_mobile_identity_imei_t; - -typedef struct ogs_nas_mobile_identity_tmsi_s { -ED3(uint8_t spare:4;, - uint8_t odd_even:1;, - uint8_t type:3;) - uint32_t tmsi; -} __attribute__ ((packed)) ogs_nas_mobile_identity_tmsi_t; - -typedef struct ogs_nas_mobile_identity_tmgi_s { -ED5(uint8_t spare:2;, - uint8_t mbms_session_id:1;, - uint8_t mcc_mnc:1;, - uint8_t odd_even:1;, - uint8_t type:3;) - uint8_t mbms_servicec_id[3]; - ogs_nas_plmn_id_t nas_plmn_id; - uint8_t mbms_session_identity; -} __attribute__ ((packed)) ogs_nas_mobile_identity_tmgi_t; - typedef struct ogs_nas_mobile_identity_imeisv_s { ED3(uint8_t digit1:4;, uint8_t odd_even:1;, @@ -202,16 +149,6 @@ ED2(uint8_t digit17:4;, uint8_t digit16:4;) } __attribute__ ((packed)) ogs_nas_mobile_identity_imeisv_t; -typedef struct ogs_nas_mobile_identity_s { - uint8_t length; - union { - ogs_nas_mobile_identity_imsi_t imsi; - ogs_nas_mobile_identity_tmsi_t tmsi; - ogs_nas_mobile_identity_tmgi_t tmgi; - ogs_nas_mobile_identity_imeisv_t imeisv; - }; -} ogs_nas_mobile_identity_t; - /* 9.9.2.4 Mobile station classmark 2 * See subclause 10.5.1.6 in 3GPP TS 24.008 * O TLV 5 */ diff --git a/lib/nas/eps/conv.c b/lib/nas/eps/conv.c new file mode 100644 index 000000000..e5ec5a841 --- /dev/null +++ b/lib/nas/eps/conv.c @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2019,2020 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "ogs-nas-eps.h" + +void ogs_nas_eps_imsi_to_bcd( + ogs_nas_mobile_identity_imsi_t *imsi, uint8_t imsi_len, char *bcd) +{ + int bcd_len; + + bcd[0] = '0' + imsi->digit1; + bcd[1] = '0' + imsi->digit2; + bcd[2] = '0' + imsi->digit3; + bcd[3] = '0' + imsi->digit4; + bcd[4] = '0' + imsi->digit5; + bcd[5] = '0' + imsi->digit6; + bcd[6] = '0' + imsi->digit7; + bcd[7] = '0' + imsi->digit8; + bcd[8] = '0' + imsi->digit9; + bcd[9] = '0' + imsi->digit10; + bcd[10] = '0' + imsi->digit11; + bcd[11] = '0' + imsi->digit12; + bcd[12] = '0' + imsi->digit13; + bcd[13] = '0' + imsi->digit14; + bcd[14] = '0' + imsi->digit15; + + bcd_len = imsi_len * 2 - 1; + if (!imsi->odd_even) { /* if bcd length is even */ + if (imsi->digit15 != 0xf) + ogs_warn("Spec warning : bcd[%d] = 0x%x, 0x%x", + bcd_len-1, imsi->digit15, bcd[bcd_len-1]); + (bcd_len)--; + } + + bcd[bcd_len] = 0; +} + +void ogs_nas_imsi_to_buffer( + ogs_nas_mobile_identity_imsi_t *imsi, uint8_t imsi_len, + uint8_t *buf, uint8_t *buf_len) +{ + buf[0] = ((('0' + imsi->digit2) << 4) & 0xf0) | + (('0' + imsi->digit1) & 0x0f); + buf[1] = ((('0' + imsi->digit4) << 4) & 0xf0) | + (('0' + imsi->digit3) & 0x0f); + buf[2] = ((('0' + imsi->digit6) << 4) & 0xf0) | + (('0' + imsi->digit5) & 0x0f); + buf[3] = ((('0' + imsi->digit8) << 4) & 0xf0) | + (('0' + imsi->digit7) & 0x0f); + buf[4] = ((('0' + imsi->digit10) << 4) & 0xf0) | + (('0' + imsi->digit9) & 0x0f); + buf[5] = ((('0' + imsi->digit12) << 4) & 0xf0) | + (('0' + imsi->digit11) & 0x0f); + buf[6] = ((('0' + imsi->digit14) << 4) & 0xf0) | + (('0' + imsi->digit13) & 0x0f); + buf[7] = ((('0' + imsi->digit15)) & 0x0f); + + *buf_len = imsi_len; + if (!imsi->odd_even) { /* if imsi length is even */ + (*buf_len)--; + if ((buf[*buf_len] & 0xf) != 0xf) + ogs_warn("Spec warning : buf[%d] = 0x%x", *buf_len, buf[*buf_len]); + } +} diff --git a/lib/nas/eps/conv.h b/lib/nas/eps/conv.h new file mode 100644 index 000000000..d1b7869b0 --- /dev/null +++ b/lib/nas/eps/conv.h @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2019,2020 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#if !defined(OGS_NAS_INSIDE) && !defined(OGS_NAS_COMPILATION) +#error "This header cannot be included directly." +#endif + +#ifndef OGS_NAS_EPS_CONV_H +#define OGS_NAS_EPS_CONV_H + +#include "ogs-nas-common.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void ogs_nas_imsi_to_buffer( + ogs_nas_mobile_identity_imsi_t *imsi, uint8_t imsi_len, + uint8_t *buf, uint8_t *buf_len); + +void ogs_nas_eps_imsi_to_bcd( + ogs_nas_mobile_identity_imsi_t *imsi, uint8_t imsi_len, char *bcd); + +#ifdef __cplusplus +} +#endif + +#endif /* OGS_NAS_EPS_CONV_H */ + diff --git a/lib/nas/eps/meson.build b/lib/nas/eps/meson.build index 306802235..ad33781a5 100644 --- a/lib/nas/eps/meson.build +++ b/lib/nas/eps/meson.build @@ -17,6 +17,7 @@ libnas_eps_sources = files(''' types.c + conv.c ies.c decoder.c encoder.c diff --git a/lib/nas/eps/ogs-nas-eps.h b/lib/nas/eps/ogs-nas-eps.h index 6d5c0a2dc..05affb8f1 100644 --- a/lib/nas/eps/ogs-nas-eps.h +++ b/lib/nas/eps/ogs-nas-eps.h @@ -25,6 +25,7 @@ #define OGS_NAS_INSIDE #include "nas/eps/types.h" +#include "nas/eps/conv.h" #include "nas/eps/ies.h" #include "nas/eps/message.h" diff --git a/lib/nas/eps/types.h b/lib/nas/eps/types.h index 60632151c..416d0ad46 100644 --- a/lib/nas/eps/types.h +++ b/lib/nas/eps/types.h @@ -56,6 +56,69 @@ typedef struct ogs_nas_location_area_identification_s { typedef ogs_nas_location_area_identification_t ogs_nas_lai_t; +/* 9.9.2.3 Mobile identity + * See subclause 10.5.1.4 in 3GPP TS 24.008 [13]. + * O TLV 7-10 */ +#define OGS_NAS_MOBILE_IDENTITY_NONE 0 +#define OGS_NAS_MOBILE_IDENTITY_IMSI 1 +#define OGS_NAS_MOBILE_IDENTITY_IMEI 2 +#define OGS_NAS_MOBILE_IDENTITY_IMEISV 3 +#define OGS_NAS_MOBILE_IDENTITY_TMSI 4 +#define OGS_NAS_MOBILE_IDENTITY_TMGI 5 +#define OGS_NAS_MOBILE_IDENTITY_GUTI 6 + +#define OGS_NAS_MOBILE_IDENTITY_EVEN 0 +#define OGS_NAS_MOBILE_IDENTITY_ODD 1 +typedef struct ogs_nas_mobile_identity_imsi_s { +ED3(uint8_t digit1:4;, + uint8_t odd_even:1;, + uint8_t type:3;) +ED2(uint8_t digit3:4;, + uint8_t digit2:4;) +ED2(uint8_t digit5:4;, + uint8_t digit4:4;) +ED2(uint8_t digit7:4;, + uint8_t digit6:4;) +ED2(uint8_t digit9:4;, + uint8_t digit8:4;) +ED2(uint8_t digit11:4;, + uint8_t digit10:4;) +ED2(uint8_t digit13:4;, + uint8_t digit12:4;) +ED2(uint8_t digit15:4;, + uint8_t digit14:4;) +} __attribute__ ((packed)) ogs_nas_mobile_identity_imsi_t; + +typedef ogs_nas_mobile_identity_imsi_t ogs_nas_mobile_identity_imei_t; + +typedef struct ogs_nas_mobile_identity_tmsi_s { +ED3(uint8_t spare:4;, + uint8_t odd_even:1;, + uint8_t type:3;) + uint32_t tmsi; +} __attribute__ ((packed)) ogs_nas_mobile_identity_tmsi_t; + +typedef struct ogs_nas_mobile_identity_tmgi_s { +ED5(uint8_t spare:2;, + uint8_t mbms_session_id:1;, + uint8_t mcc_mnc:1;, + uint8_t odd_even:1;, + uint8_t type:3;) + uint8_t mbms_servicec_id[3]; + ogs_nas_plmn_id_t nas_plmn_id; + uint8_t mbms_session_identity; +} __attribute__ ((packed)) ogs_nas_mobile_identity_tmgi_t; + +typedef struct ogs_nas_mobile_identity_s { + uint8_t length; + union { + ogs_nas_mobile_identity_imsi_t imsi; + ogs_nas_mobile_identity_tmsi_t tmsi; + ogs_nas_mobile_identity_tmgi_t tmgi; + ogs_nas_mobile_identity_imeisv_t imeisv; + }; +} ogs_nas_mobile_identity_t; + /*9.9.2.5 Mobile station classmark 3 * See subclause 10.5.1.7 in 3GPP TS 24.008 [13]. * O TLV 2-34 */ diff --git a/lib/sbi/context.h b/lib/sbi/context.h index 0ae57cda5..f80d3a6e1 100644 --- a/lib/sbi/context.h +++ b/lib/sbi/context.h @@ -112,6 +112,8 @@ typedef struct ogs_sbi_object_s { ogs_time_t duration; } client_wait; + bool running; + OpenAPI_nf_type_e nf_type; ogs_sbi_request_t *request; diff --git a/lib/sbi/openapi/model/cause.c b/lib/sbi/openapi/model/cause.c index 15433fca4..9279e0e4c 100644 --- a/lib/sbi/openapi/model/cause.c +++ b/lib/sbi/openapi/model/cause.c @@ -4,82 +4,27 @@ #include #include "cause.h" -OpenAPI_cause_t *OpenAPI_cause_create( - ) +char* OpenAPI_cause_ToString(OpenAPI_cause_e cause) { - OpenAPI_cause_t *cause_local_var = OpenAPI_malloc(sizeof(OpenAPI_cause_t)); - if (!cause_local_var) { - return NULL; - } - - return cause_local_var; + const char *causeArray[] = { "NULL", "REL_DUE_TO_HO", "EPS_FALLBACK", "REL_DUE_TO_UP_SEC", "DNN_CONGESTION", "S_NSSAI_CONGESTION", "REL_DUE_TO_REACTIVATION", "_5G_AN_NOT_RESPONDING", "REL_DUE_TO_SLICE_NOT_AVAILABLE", "REL_DUE_TO_DUPLICATE_SESSION_ID", "PDU_SESSION_STATUS_MISMATCH", "HO_FAILURE", "INSUFFICIENT_UP_RESOURCES", "PDU_SESSION_HANDED_OVER", "PDU_SESSION_RESUMED", "CN_ASSISTED_RAN_PARAMETER_TUNING", "ISMF_CONTEXT_TRANSFER", "SMF_CONTEXT_TRANSFER", "REL_DUE_TO_PS_TO_CS_HO", "REL_DUE_TO_SUBSCRIPTION_CHANGE", "HO_CANCEL", "REL_DUE_TO_SLICE_NOT_AUTHORIZED", "PDU_SESSION_HAND_OVER_FAILURE", "DDN_FAILURE_STATUS" }; + size_t sizeofArray = sizeof(causeArray) / sizeof(causeArray[0]); + if (cause < sizeofArray) + return (char *)causeArray[cause]; + else + return (char *)"Unknown"; } -void OpenAPI_cause_free(OpenAPI_cause_t *cause) +OpenAPI_cause_e OpenAPI_cause_FromString(char* cause) { - if (NULL == cause) { - return; + int stringToReturn = 0; + const char *causeArray[] = { "NULL", "REL_DUE_TO_HO", "EPS_FALLBACK", "REL_DUE_TO_UP_SEC", "DNN_CONGESTION", "S_NSSAI_CONGESTION", "REL_DUE_TO_REACTIVATION", "_5G_AN_NOT_RESPONDING", "REL_DUE_TO_SLICE_NOT_AVAILABLE", "REL_DUE_TO_DUPLICATE_SESSION_ID", "PDU_SESSION_STATUS_MISMATCH", "HO_FAILURE", "INSUFFICIENT_UP_RESOURCES", "PDU_SESSION_HANDED_OVER", "PDU_SESSION_RESUMED", "CN_ASSISTED_RAN_PARAMETER_TUNING", "ISMF_CONTEXT_TRANSFER", "SMF_CONTEXT_TRANSFER", "REL_DUE_TO_PS_TO_CS_HO", "REL_DUE_TO_SUBSCRIPTION_CHANGE", "HO_CANCEL", "REL_DUE_TO_SLICE_NOT_AUTHORIZED", "PDU_SESSION_HAND_OVER_FAILURE", "DDN_FAILURE_STATUS" }; + size_t sizeofArray = sizeof(causeArray) / sizeof(causeArray[0]); + while (stringToReturn < sizeofArray) { + if (strcmp(cause, causeArray[stringToReturn]) == 0) { + return stringToReturn; + } + stringToReturn++; } - OpenAPI_lnode_t *node; - ogs_free(cause); -} - -cJSON *OpenAPI_cause_convertToJSON(OpenAPI_cause_t *cause) -{ - cJSON *item = NULL; - - if (cause == NULL) { - ogs_error("OpenAPI_cause_convertToJSON() failed [Cause]"); - return NULL; - } - - item = cJSON_CreateObject(); -end: - return item; -} - -OpenAPI_cause_t *OpenAPI_cause_parseFromJSON(cJSON *causeJSON) -{ - OpenAPI_cause_t *cause_local_var = NULL; - cause_local_var = OpenAPI_cause_create ( - ); - - return cause_local_var; -end: - return NULL; -} - -OpenAPI_cause_t *OpenAPI_cause_copy(OpenAPI_cause_t *dst, OpenAPI_cause_t *src) -{ - cJSON *item = NULL; - char *content = NULL; - - ogs_assert(src); - item = OpenAPI_cause_convertToJSON(src); - if (!item) { - ogs_error("OpenAPI_cause_convertToJSON() failed"); - return NULL; - } - - content = cJSON_Print(item); - cJSON_Delete(item); - - if (!content) { - ogs_error("cJSON_Print() failed"); - return NULL; - } - - item = cJSON_Parse(content); - ogs_free(content); - if (!item) { - ogs_error("cJSON_Parse() failed"); - return NULL; - } - - OpenAPI_cause_free(dst); - dst = OpenAPI_cause_parseFromJSON(item); - cJSON_Delete(item); - - return dst; + return 0; } diff --git a/lib/sbi/openapi/model/cause.h b/lib/sbi/openapi/model/cause.h index ebafc39c3..d68fb78c9 100644 --- a/lib/sbi/openapi/model/cause.h +++ b/lib/sbi/openapi/model/cause.h @@ -1,7 +1,7 @@ /* * cause.h * - * Possible values are - REL_DUE_TO_HO - EPS_FALLBACK - REL_DUE_TO_UP_SEC - DNN_CONGESTION - S_NSSAI_CONGESTION - REL_DUE_TO_REACTIVATION - 5G_AN_NOT_RESPONDING - REL_DUE_TO_SLICE_NOT_AVAILABLE - REL_DUE_TO_DUPLICATE_SESSION_ID - PDU_SESSION_STATUS_MISMATCH - HO_FAILURE - INSUFFICIENT_UP_RESOURCES - PDU_SESSION_HANDED_OVER - PDU_SESSION_RESUMED - CN_ASSISTED_RAN_PARAMETER_TUNING - ISMF_CONTEXT_TRANSFER - SMF_CONTEXT_TRANSFER - REL_DUE_TO_PS_TO_CS_HO - REL_DUE_TO_SUBSCRIPTION_CHANGE - HO_CANCEL - REL_DUE_TO_SLICE_NOT_AUTHORIZED - PDU_SESSION_HAND_OVER_FAILURE - DDN_FAILURE_STATUS + * */ #ifndef _OpenAPI_cause_H_ @@ -17,16 +17,11 @@ extern "C" { #endif -typedef struct OpenAPI_cause_s OpenAPI_cause_t; -typedef struct OpenAPI_cause_s { -} OpenAPI_cause_t; +typedef enum { OpenAPI_cause_NULL = 0, OpenAPI_cause_REL_DUE_TO_HO, OpenAPI_cause_EPS_FALLBACK, OpenAPI_cause_REL_DUE_TO_UP_SEC, OpenAPI_cause_DNN_CONGESTION, OpenAPI_cause_S_NSSAI_CONGESTION, OpenAPI_cause_REL_DUE_TO_REACTIVATION, OpenAPI_cause__5G_AN_NOT_RESPONDING, OpenAPI_cause_REL_DUE_TO_SLICE_NOT_AVAILABLE, OpenAPI_cause_REL_DUE_TO_DUPLICATE_SESSION_ID, OpenAPI_cause_PDU_SESSION_STATUS_MISMATCH, OpenAPI_cause_HO_FAILURE, OpenAPI_cause_INSUFFICIENT_UP_RESOURCES, OpenAPI_cause_PDU_SESSION_HANDED_OVER, OpenAPI_cause_PDU_SESSION_RESUMED, OpenAPI_cause_CN_ASSISTED_RAN_PARAMETER_TUNING, OpenAPI_cause_ISMF_CONTEXT_TRANSFER, OpenAPI_cause_SMF_CONTEXT_TRANSFER, OpenAPI_cause_REL_DUE_TO_PS_TO_CS_HO, OpenAPI_cause_REL_DUE_TO_SUBSCRIPTION_CHANGE, OpenAPI_cause_HO_CANCEL, OpenAPI_cause_REL_DUE_TO_SLICE_NOT_AUTHORIZED, OpenAPI_cause_PDU_SESSION_HAND_OVER_FAILURE, OpenAPI_cause_DDN_FAILURE_STATUS } OpenAPI_cause_e; -OpenAPI_cause_t *OpenAPI_cause_create( - ); -void OpenAPI_cause_free(OpenAPI_cause_t *cause); -OpenAPI_cause_t *OpenAPI_cause_parseFromJSON(cJSON *causeJSON); -cJSON *OpenAPI_cause_convertToJSON(OpenAPI_cause_t *cause); -OpenAPI_cause_t *OpenAPI_cause_copy(OpenAPI_cause_t *dst, OpenAPI_cause_t *src); +char* OpenAPI_cause_ToString(OpenAPI_cause_e cause); + +OpenAPI_cause_e OpenAPI_cause_FromString(char* cause); #ifdef __cplusplus } diff --git a/lib/sbi/openapi/model/dnn_selection_mode.c b/lib/sbi/openapi/model/dnn_selection_mode.c index 803472933..ed2e332aa 100644 --- a/lib/sbi/openapi/model/dnn_selection_mode.c +++ b/lib/sbi/openapi/model/dnn_selection_mode.c @@ -4,82 +4,27 @@ #include #include "dnn_selection_mode.h" -OpenAPI_dnn_selection_mode_t *OpenAPI_dnn_selection_mode_create( - ) +char* OpenAPI_dnn_selection_mode_ToString(OpenAPI_dnn_selection_mode_e dnn_selection_mode) { - OpenAPI_dnn_selection_mode_t *dnn_selection_mode_local_var = OpenAPI_malloc(sizeof(OpenAPI_dnn_selection_mode_t)); - if (!dnn_selection_mode_local_var) { - return NULL; - } - - return dnn_selection_mode_local_var; + const char *dnn_selection_modeArray[] = { "NULL", "VERIFIED", "UE_DNN_NOT_VERIFIED", "NW_DNN_NOT_VERIFIED" }; + size_t sizeofArray = sizeof(dnn_selection_modeArray) / sizeof(dnn_selection_modeArray[0]); + if (dnn_selection_mode < sizeofArray) + return (char *)dnn_selection_modeArray[dnn_selection_mode]; + else + return (char *)"Unknown"; } -void OpenAPI_dnn_selection_mode_free(OpenAPI_dnn_selection_mode_t *dnn_selection_mode) +OpenAPI_dnn_selection_mode_e OpenAPI_dnn_selection_mode_FromString(char* dnn_selection_mode) { - if (NULL == dnn_selection_mode) { - return; + int stringToReturn = 0; + const char *dnn_selection_modeArray[] = { "NULL", "VERIFIED", "UE_DNN_NOT_VERIFIED", "NW_DNN_NOT_VERIFIED" }; + size_t sizeofArray = sizeof(dnn_selection_modeArray) / sizeof(dnn_selection_modeArray[0]); + while (stringToReturn < sizeofArray) { + if (strcmp(dnn_selection_mode, dnn_selection_modeArray[stringToReturn]) == 0) { + return stringToReturn; + } + stringToReturn++; } - OpenAPI_lnode_t *node; - ogs_free(dnn_selection_mode); -} - -cJSON *OpenAPI_dnn_selection_mode_convertToJSON(OpenAPI_dnn_selection_mode_t *dnn_selection_mode) -{ - cJSON *item = NULL; - - if (dnn_selection_mode == NULL) { - ogs_error("OpenAPI_dnn_selection_mode_convertToJSON() failed [DnnSelectionMode]"); - return NULL; - } - - item = cJSON_CreateObject(); -end: - return item; -} - -OpenAPI_dnn_selection_mode_t *OpenAPI_dnn_selection_mode_parseFromJSON(cJSON *dnn_selection_modeJSON) -{ - OpenAPI_dnn_selection_mode_t *dnn_selection_mode_local_var = NULL; - dnn_selection_mode_local_var = OpenAPI_dnn_selection_mode_create ( - ); - - return dnn_selection_mode_local_var; -end: - return NULL; -} - -OpenAPI_dnn_selection_mode_t *OpenAPI_dnn_selection_mode_copy(OpenAPI_dnn_selection_mode_t *dst, OpenAPI_dnn_selection_mode_t *src) -{ - cJSON *item = NULL; - char *content = NULL; - - ogs_assert(src); - item = OpenAPI_dnn_selection_mode_convertToJSON(src); - if (!item) { - ogs_error("OpenAPI_dnn_selection_mode_convertToJSON() failed"); - return NULL; - } - - content = cJSON_Print(item); - cJSON_Delete(item); - - if (!content) { - ogs_error("cJSON_Print() failed"); - return NULL; - } - - item = cJSON_Parse(content); - ogs_free(content); - if (!item) { - ogs_error("cJSON_Parse() failed"); - return NULL; - } - - OpenAPI_dnn_selection_mode_free(dst); - dst = OpenAPI_dnn_selection_mode_parseFromJSON(item); - cJSON_Delete(item); - - return dst; + return 0; } diff --git a/lib/sbi/openapi/model/dnn_selection_mode.h b/lib/sbi/openapi/model/dnn_selection_mode.h index 0fefd53b0..576528ef0 100644 --- a/lib/sbi/openapi/model/dnn_selection_mode.h +++ b/lib/sbi/openapi/model/dnn_selection_mode.h @@ -1,7 +1,7 @@ /* * dnn_selection_mode.h * - * Possible values are - VERIFIED - UE_DNN_NOT_VERIFIED - NW_DNN_NOT_VERIFIED + * */ #ifndef _OpenAPI_dnn_selection_mode_H_ @@ -17,16 +17,11 @@ extern "C" { #endif -typedef struct OpenAPI_dnn_selection_mode_s OpenAPI_dnn_selection_mode_t; -typedef struct OpenAPI_dnn_selection_mode_s { -} OpenAPI_dnn_selection_mode_t; +typedef enum { OpenAPI_dnn_selection_mode_NULL = 0, OpenAPI_dnn_selection_mode_VERIFIED, OpenAPI_dnn_selection_mode_UE_DNN_NOT_VERIFIED, OpenAPI_dnn_selection_mode_NW_DNN_NOT_VERIFIED } OpenAPI_dnn_selection_mode_e; -OpenAPI_dnn_selection_mode_t *OpenAPI_dnn_selection_mode_create( - ); -void OpenAPI_dnn_selection_mode_free(OpenAPI_dnn_selection_mode_t *dnn_selection_mode); -OpenAPI_dnn_selection_mode_t *OpenAPI_dnn_selection_mode_parseFromJSON(cJSON *dnn_selection_modeJSON); -cJSON *OpenAPI_dnn_selection_mode_convertToJSON(OpenAPI_dnn_selection_mode_t *dnn_selection_mode); -OpenAPI_dnn_selection_mode_t *OpenAPI_dnn_selection_mode_copy(OpenAPI_dnn_selection_mode_t *dst, OpenAPI_dnn_selection_mode_t *src); +char* OpenAPI_dnn_selection_mode_ToString(OpenAPI_dnn_selection_mode_e dnn_selection_mode); + +OpenAPI_dnn_selection_mode_e OpenAPI_dnn_selection_mode_FromString(char* dnn_selection_mode); #ifdef __cplusplus } diff --git a/lib/sbi/openapi/model/eps_interworking_indication.c b/lib/sbi/openapi/model/eps_interworking_indication.c index 10b844c2b..d684a9f36 100644 --- a/lib/sbi/openapi/model/eps_interworking_indication.c +++ b/lib/sbi/openapi/model/eps_interworking_indication.c @@ -4,82 +4,27 @@ #include #include "eps_interworking_indication.h" -OpenAPI_eps_interworking_indication_t *OpenAPI_eps_interworking_indication_create( - ) +char* OpenAPI_eps_interworking_indication_ToString(OpenAPI_eps_interworking_indication_e eps_interworking_indication) { - OpenAPI_eps_interworking_indication_t *eps_interworking_indication_local_var = OpenAPI_malloc(sizeof(OpenAPI_eps_interworking_indication_t)); - if (!eps_interworking_indication_local_var) { - return NULL; - } - - return eps_interworking_indication_local_var; + const char *eps_interworking_indicationArray[] = { "NULL", "NONE", "WITH_N26", "WITHOUT_N26", "IWK_NON_3GPP" }; + size_t sizeofArray = sizeof(eps_interworking_indicationArray) / sizeof(eps_interworking_indicationArray[0]); + if (eps_interworking_indication < sizeofArray) + return (char *)eps_interworking_indicationArray[eps_interworking_indication]; + else + return (char *)"Unknown"; } -void OpenAPI_eps_interworking_indication_free(OpenAPI_eps_interworking_indication_t *eps_interworking_indication) +OpenAPI_eps_interworking_indication_e OpenAPI_eps_interworking_indication_FromString(char* eps_interworking_indication) { - if (NULL == eps_interworking_indication) { - return; + int stringToReturn = 0; + const char *eps_interworking_indicationArray[] = { "NULL", "NONE", "WITH_N26", "WITHOUT_N26", "IWK_NON_3GPP" }; + size_t sizeofArray = sizeof(eps_interworking_indicationArray) / sizeof(eps_interworking_indicationArray[0]); + while (stringToReturn < sizeofArray) { + if (strcmp(eps_interworking_indication, eps_interworking_indicationArray[stringToReturn]) == 0) { + return stringToReturn; + } + stringToReturn++; } - OpenAPI_lnode_t *node; - ogs_free(eps_interworking_indication); -} - -cJSON *OpenAPI_eps_interworking_indication_convertToJSON(OpenAPI_eps_interworking_indication_t *eps_interworking_indication) -{ - cJSON *item = NULL; - - if (eps_interworking_indication == NULL) { - ogs_error("OpenAPI_eps_interworking_indication_convertToJSON() failed [EpsInterworkingIndication]"); - return NULL; - } - - item = cJSON_CreateObject(); -end: - return item; -} - -OpenAPI_eps_interworking_indication_t *OpenAPI_eps_interworking_indication_parseFromJSON(cJSON *eps_interworking_indicationJSON) -{ - OpenAPI_eps_interworking_indication_t *eps_interworking_indication_local_var = NULL; - eps_interworking_indication_local_var = OpenAPI_eps_interworking_indication_create ( - ); - - return eps_interworking_indication_local_var; -end: - return NULL; -} - -OpenAPI_eps_interworking_indication_t *OpenAPI_eps_interworking_indication_copy(OpenAPI_eps_interworking_indication_t *dst, OpenAPI_eps_interworking_indication_t *src) -{ - cJSON *item = NULL; - char *content = NULL; - - ogs_assert(src); - item = OpenAPI_eps_interworking_indication_convertToJSON(src); - if (!item) { - ogs_error("OpenAPI_eps_interworking_indication_convertToJSON() failed"); - return NULL; - } - - content = cJSON_Print(item); - cJSON_Delete(item); - - if (!content) { - ogs_error("cJSON_Print() failed"); - return NULL; - } - - item = cJSON_Parse(content); - ogs_free(content); - if (!item) { - ogs_error("cJSON_Parse() failed"); - return NULL; - } - - OpenAPI_eps_interworking_indication_free(dst); - dst = OpenAPI_eps_interworking_indication_parseFromJSON(item); - cJSON_Delete(item); - - return dst; + return 0; } diff --git a/lib/sbi/openapi/model/eps_interworking_indication.h b/lib/sbi/openapi/model/eps_interworking_indication.h index 760aebfe9..5e4d80621 100644 --- a/lib/sbi/openapi/model/eps_interworking_indication.h +++ b/lib/sbi/openapi/model/eps_interworking_indication.h @@ -1,7 +1,7 @@ /* * eps_interworking_indication.h * - * Possible values are - NONE - WITH_N26 - WITHOUT_N26 - IWK_NON_3GPP + * */ #ifndef _OpenAPI_eps_interworking_indication_H_ @@ -17,16 +17,11 @@ extern "C" { #endif -typedef struct OpenAPI_eps_interworking_indication_s OpenAPI_eps_interworking_indication_t; -typedef struct OpenAPI_eps_interworking_indication_s { -} OpenAPI_eps_interworking_indication_t; +typedef enum { OpenAPI_eps_interworking_indication_NULL = 0, OpenAPI_eps_interworking_indication_NONE, OpenAPI_eps_interworking_indication_WITH_N26, OpenAPI_eps_interworking_indication_WITHOUT_N26, OpenAPI_eps_interworking_indication_IWK_NON_3GPP } OpenAPI_eps_interworking_indication_e; -OpenAPI_eps_interworking_indication_t *OpenAPI_eps_interworking_indication_create( - ); -void OpenAPI_eps_interworking_indication_free(OpenAPI_eps_interworking_indication_t *eps_interworking_indication); -OpenAPI_eps_interworking_indication_t *OpenAPI_eps_interworking_indication_parseFromJSON(cJSON *eps_interworking_indicationJSON); -cJSON *OpenAPI_eps_interworking_indication_convertToJSON(OpenAPI_eps_interworking_indication_t *eps_interworking_indication); -OpenAPI_eps_interworking_indication_t *OpenAPI_eps_interworking_indication_copy(OpenAPI_eps_interworking_indication_t *dst, OpenAPI_eps_interworking_indication_t *src); +char* OpenAPI_eps_interworking_indication_ToString(OpenAPI_eps_interworking_indication_e eps_interworking_indication); + +OpenAPI_eps_interworking_indication_e OpenAPI_eps_interworking_indication_FromString(char* eps_interworking_indication); #ifdef __cplusplus } diff --git a/lib/sbi/openapi/model/ho_state.c b/lib/sbi/openapi/model/ho_state.c index 9a68d7a86..c6de1c06f 100644 --- a/lib/sbi/openapi/model/ho_state.c +++ b/lib/sbi/openapi/model/ho_state.c @@ -4,82 +4,27 @@ #include #include "ho_state.h" -OpenAPI_ho_state_t *OpenAPI_ho_state_create( - ) +char* OpenAPI_ho_state_ToString(OpenAPI_ho_state_e ho_state) { - OpenAPI_ho_state_t *ho_state_local_var = OpenAPI_malloc(sizeof(OpenAPI_ho_state_t)); - if (!ho_state_local_var) { - return NULL; - } - - return ho_state_local_var; + const char *ho_stateArray[] = { "NULL", "NONE", "PREPARING", "PREPARED", "COMPLETED", "CANCELLED" }; + size_t sizeofArray = sizeof(ho_stateArray) / sizeof(ho_stateArray[0]); + if (ho_state < sizeofArray) + return (char *)ho_stateArray[ho_state]; + else + return (char *)"Unknown"; } -void OpenAPI_ho_state_free(OpenAPI_ho_state_t *ho_state) +OpenAPI_ho_state_e OpenAPI_ho_state_FromString(char* ho_state) { - if (NULL == ho_state) { - return; + int stringToReturn = 0; + const char *ho_stateArray[] = { "NULL", "NONE", "PREPARING", "PREPARED", "COMPLETED", "CANCELLED" }; + size_t sizeofArray = sizeof(ho_stateArray) / sizeof(ho_stateArray[0]); + while (stringToReturn < sizeofArray) { + if (strcmp(ho_state, ho_stateArray[stringToReturn]) == 0) { + return stringToReturn; + } + stringToReturn++; } - OpenAPI_lnode_t *node; - ogs_free(ho_state); -} - -cJSON *OpenAPI_ho_state_convertToJSON(OpenAPI_ho_state_t *ho_state) -{ - cJSON *item = NULL; - - if (ho_state == NULL) { - ogs_error("OpenAPI_ho_state_convertToJSON() failed [HoState]"); - return NULL; - } - - item = cJSON_CreateObject(); -end: - return item; -} - -OpenAPI_ho_state_t *OpenAPI_ho_state_parseFromJSON(cJSON *ho_stateJSON) -{ - OpenAPI_ho_state_t *ho_state_local_var = NULL; - ho_state_local_var = OpenAPI_ho_state_create ( - ); - - return ho_state_local_var; -end: - return NULL; -} - -OpenAPI_ho_state_t *OpenAPI_ho_state_copy(OpenAPI_ho_state_t *dst, OpenAPI_ho_state_t *src) -{ - cJSON *item = NULL; - char *content = NULL; - - ogs_assert(src); - item = OpenAPI_ho_state_convertToJSON(src); - if (!item) { - ogs_error("OpenAPI_ho_state_convertToJSON() failed"); - return NULL; - } - - content = cJSON_Print(item); - cJSON_Delete(item); - - if (!content) { - ogs_error("cJSON_Print() failed"); - return NULL; - } - - item = cJSON_Parse(content); - ogs_free(content); - if (!item) { - ogs_error("cJSON_Parse() failed"); - return NULL; - } - - OpenAPI_ho_state_free(dst); - dst = OpenAPI_ho_state_parseFromJSON(item); - cJSON_Delete(item); - - return dst; + return 0; } diff --git a/lib/sbi/openapi/model/ho_state.h b/lib/sbi/openapi/model/ho_state.h index 9b1862f1b..9bd13cbb9 100644 --- a/lib/sbi/openapi/model/ho_state.h +++ b/lib/sbi/openapi/model/ho_state.h @@ -1,7 +1,7 @@ /* * ho_state.h * - * Possible values are - NONE - PREPARING - PREPARED - COMPLETED - CANCELLED + * */ #ifndef _OpenAPI_ho_state_H_ @@ -17,16 +17,11 @@ extern "C" { #endif -typedef struct OpenAPI_ho_state_s OpenAPI_ho_state_t; -typedef struct OpenAPI_ho_state_s { -} OpenAPI_ho_state_t; +typedef enum { OpenAPI_ho_state_NULL = 0, OpenAPI_ho_state_NONE, OpenAPI_ho_state_PREPARING, OpenAPI_ho_state_PREPARED, OpenAPI_ho_state_COMPLETED, OpenAPI_ho_state_CANCELLED } OpenAPI_ho_state_e; -OpenAPI_ho_state_t *OpenAPI_ho_state_create( - ); -void OpenAPI_ho_state_free(OpenAPI_ho_state_t *ho_state); -OpenAPI_ho_state_t *OpenAPI_ho_state_parseFromJSON(cJSON *ho_stateJSON); -cJSON *OpenAPI_ho_state_convertToJSON(OpenAPI_ho_state_t *ho_state); -OpenAPI_ho_state_t *OpenAPI_ho_state_copy(OpenAPI_ho_state_t *dst, OpenAPI_ho_state_t *src); +char* OpenAPI_ho_state_ToString(OpenAPI_ho_state_e ho_state); + +OpenAPI_ho_state_e OpenAPI_ho_state_FromString(char* ho_state); #ifdef __cplusplus } diff --git a/lib/sbi/openapi/model/hsmf_update_data.c b/lib/sbi/openapi/model/hsmf_update_data.c index 68652a52b..4c59cef1c 100644 --- a/lib/sbi/openapi/model/hsmf_update_data.c +++ b/lib/sbi/openapi/model/hsmf_update_data.c @@ -5,7 +5,7 @@ #include "hsmf_update_data.h" OpenAPI_hsmf_update_data_t *OpenAPI_hsmf_update_data_create( - OpenAPI_request_indication_t *request_indication, + OpenAPI_request_indication_e request_indication, char *pei, OpenAPI_tunnel_info_t *vcn_tunnel_info, OpenAPI_tunnel_info_t *icn_tunnel_info, @@ -27,18 +27,18 @@ OpenAPI_hsmf_update_data_t *OpenAPI_hsmf_update_data_create( OpenAPI_list_t *eps_bearer_id, int ho_preparation_indication, OpenAPI_list_t *revoke_ebi_list, - OpenAPI_cause_t *cause, + OpenAPI_cause_e cause, OpenAPI_ng_ap_cause_t *ng_ap_cause, int _5g_mm_cause_value, int always_on_requested, - OpenAPI_eps_interworking_indication_t *eps_interworking_ind, + OpenAPI_eps_interworking_indication_e eps_interworking_ind, OpenAPI_list_t *secondary_rat_usage_report, OpenAPI_list_t *secondary_rat_usage_info, int an_type_can_be_changed, - OpenAPI_ma_release_indication_t *ma_release_ind, + OpenAPI_ma_release_indication_e ma_release_ind, int ma_nw_upgrade_ind, int ma_request_ind, - OpenAPI_unavailable_access_indication_t *unavailable_access_ind, + OpenAPI_unavailable_access_indication_e unavailable_access_ind, OpenAPI_list_t *psa_info, OpenAPI_ulcl_bp_information_t *ulcl_bp_info, OpenAPI_n4_information_t *n4_info, @@ -127,7 +127,6 @@ void OpenAPI_hsmf_update_data_free(OpenAPI_hsmf_update_data_t *hsmf_update_data) return; } OpenAPI_lnode_t *node; - OpenAPI_request_indication_free(hsmf_update_data->request_indication); ogs_free(hsmf_update_data->pei); OpenAPI_tunnel_info_free(hsmf_update_data->vcn_tunnel_info); OpenAPI_tunnel_info_free(hsmf_update_data->icn_tunnel_info); @@ -158,9 +157,7 @@ void OpenAPI_hsmf_update_data_free(OpenAPI_hsmf_update_data_t *hsmf_update_data) ogs_free(node->data); } OpenAPI_list_free(hsmf_update_data->revoke_ebi_list); - OpenAPI_cause_free(hsmf_update_data->cause); OpenAPI_ng_ap_cause_free(hsmf_update_data->ng_ap_cause); - OpenAPI_eps_interworking_indication_free(hsmf_update_data->eps_interworking_ind); OpenAPI_list_for_each(hsmf_update_data->secondary_rat_usage_report, node) { OpenAPI_secondary_rat_usage_report_free(node->data); } @@ -169,8 +166,6 @@ void OpenAPI_hsmf_update_data_free(OpenAPI_hsmf_update_data_t *hsmf_update_data) OpenAPI_secondary_rat_usage_info_free(node->data); } OpenAPI_list_free(hsmf_update_data->secondary_rat_usage_info); - OpenAPI_ma_release_indication_free(hsmf_update_data->ma_release_ind); - OpenAPI_unavailable_access_indication_free(hsmf_update_data->unavailable_access_ind); OpenAPI_list_for_each(hsmf_update_data->psa_info, node) { OpenAPI_psa_information_free(node->data); } @@ -212,13 +207,7 @@ cJSON *OpenAPI_hsmf_update_data_convertToJSON(OpenAPI_hsmf_update_data_t *hsmf_u ogs_error("OpenAPI_hsmf_update_data_convertToJSON() failed [request_indication]"); goto end; } - cJSON *request_indication_local_JSON = OpenAPI_request_indication_convertToJSON(hsmf_update_data->request_indication); - if (request_indication_local_JSON == NULL) { - ogs_error("OpenAPI_hsmf_update_data_convertToJSON() failed [request_indication]"); - goto end; - } - cJSON_AddItemToObject(item, "requestIndication", request_indication_local_JSON); - if (item->child == NULL) { + if (cJSON_AddStringToObject(item, "requestIndication", OpenAPI_request_indication_ToString(hsmf_update_data->request_indication)) == NULL) { ogs_error("OpenAPI_hsmf_update_data_convertToJSON() failed [request_indication]"); goto end; } @@ -476,13 +465,7 @@ cJSON *OpenAPI_hsmf_update_data_convertToJSON(OpenAPI_hsmf_update_data_t *hsmf_u } if (hsmf_update_data->cause) { - cJSON *cause_local_JSON = OpenAPI_cause_convertToJSON(hsmf_update_data->cause); - if (cause_local_JSON == NULL) { - ogs_error("OpenAPI_hsmf_update_data_convertToJSON() failed [cause]"); - goto end; - } - cJSON_AddItemToObject(item, "cause", cause_local_JSON); - if (item->child == NULL) { + if (cJSON_AddStringToObject(item, "cause", OpenAPI_cause_ToString(hsmf_update_data->cause)) == NULL) { ogs_error("OpenAPI_hsmf_update_data_convertToJSON() failed [cause]"); goto end; } @@ -516,13 +499,7 @@ cJSON *OpenAPI_hsmf_update_data_convertToJSON(OpenAPI_hsmf_update_data_t *hsmf_u } if (hsmf_update_data->eps_interworking_ind) { - cJSON *eps_interworking_ind_local_JSON = OpenAPI_eps_interworking_indication_convertToJSON(hsmf_update_data->eps_interworking_ind); - if (eps_interworking_ind_local_JSON == NULL) { - ogs_error("OpenAPI_hsmf_update_data_convertToJSON() failed [eps_interworking_ind]"); - goto end; - } - cJSON_AddItemToObject(item, "epsInterworkingInd", eps_interworking_ind_local_JSON); - if (item->child == NULL) { + if (cJSON_AddStringToObject(item, "epsInterworkingInd", OpenAPI_eps_interworking_indication_ToString(hsmf_update_data->eps_interworking_ind)) == NULL) { ogs_error("OpenAPI_hsmf_update_data_convertToJSON() failed [eps_interworking_ind]"); goto end; } @@ -576,13 +553,7 @@ cJSON *OpenAPI_hsmf_update_data_convertToJSON(OpenAPI_hsmf_update_data_t *hsmf_u } if (hsmf_update_data->ma_release_ind) { - cJSON *ma_release_ind_local_JSON = OpenAPI_ma_release_indication_convertToJSON(hsmf_update_data->ma_release_ind); - if (ma_release_ind_local_JSON == NULL) { - ogs_error("OpenAPI_hsmf_update_data_convertToJSON() failed [ma_release_ind]"); - goto end; - } - cJSON_AddItemToObject(item, "maReleaseInd", ma_release_ind_local_JSON); - if (item->child == NULL) { + if (cJSON_AddStringToObject(item, "maReleaseInd", OpenAPI_ma_release_indication_ToString(hsmf_update_data->ma_release_ind)) == NULL) { ogs_error("OpenAPI_hsmf_update_data_convertToJSON() failed [ma_release_ind]"); goto end; } @@ -603,13 +574,7 @@ cJSON *OpenAPI_hsmf_update_data_convertToJSON(OpenAPI_hsmf_update_data_t *hsmf_u } if (hsmf_update_data->unavailable_access_ind) { - cJSON *unavailable_access_ind_local_JSON = OpenAPI_unavailable_access_indication_convertToJSON(hsmf_update_data->unavailable_access_ind); - if (unavailable_access_ind_local_JSON == NULL) { - ogs_error("OpenAPI_hsmf_update_data_convertToJSON() failed [unavailable_access_ind]"); - goto end; - } - cJSON_AddItemToObject(item, "unavailableAccessInd", unavailable_access_ind_local_JSON); - if (item->child == NULL) { + if (cJSON_AddStringToObject(item, "unavailableAccessInd", OpenAPI_unavailable_access_indication_ToString(hsmf_update_data->unavailable_access_ind)) == NULL) { ogs_error("OpenAPI_hsmf_update_data_convertToJSON() failed [unavailable_access_ind]"); goto end; } @@ -837,9 +802,13 @@ OpenAPI_hsmf_update_data_t *OpenAPI_hsmf_update_data_parseFromJSON(cJSON *hsmf_u goto end; } - OpenAPI_request_indication_t *request_indication_local_nonprim = NULL; + OpenAPI_request_indication_e request_indicationVariable; - request_indication_local_nonprim = OpenAPI_request_indication_parseFromJSON(request_indication); + if (!cJSON_IsString(request_indication)) { + ogs_error("OpenAPI_hsmf_update_data_parseFromJSON() failed [request_indication]"); + goto end; + } + request_indicationVariable = OpenAPI_request_indication_FromString(request_indication->valuestring); cJSON *pei = cJSON_GetObjectItemCaseSensitive(hsmf_update_dataJSON, "pei"); @@ -1086,9 +1055,13 @@ OpenAPI_hsmf_update_data_t *OpenAPI_hsmf_update_data_parseFromJSON(cJSON *hsmf_u cJSON *cause = cJSON_GetObjectItemCaseSensitive(hsmf_update_dataJSON, "cause"); - OpenAPI_cause_t *cause_local_nonprim = NULL; + OpenAPI_cause_e causeVariable; if (cause) { - cause_local_nonprim = OpenAPI_cause_parseFromJSON(cause); + if (!cJSON_IsString(cause)) { + ogs_error("OpenAPI_hsmf_update_data_parseFromJSON() failed [cause]"); + goto end; + } + causeVariable = OpenAPI_cause_FromString(cause->valuestring); } cJSON *ng_ap_cause = cJSON_GetObjectItemCaseSensitive(hsmf_update_dataJSON, "ngApCause"); @@ -1118,9 +1091,13 @@ OpenAPI_hsmf_update_data_t *OpenAPI_hsmf_update_data_parseFromJSON(cJSON *hsmf_u cJSON *eps_interworking_ind = cJSON_GetObjectItemCaseSensitive(hsmf_update_dataJSON, "epsInterworkingInd"); - OpenAPI_eps_interworking_indication_t *eps_interworking_ind_local_nonprim = NULL; + OpenAPI_eps_interworking_indication_e eps_interworking_indVariable; if (eps_interworking_ind) { - eps_interworking_ind_local_nonprim = OpenAPI_eps_interworking_indication_parseFromJSON(eps_interworking_ind); + if (!cJSON_IsString(eps_interworking_ind)) { + ogs_error("OpenAPI_hsmf_update_data_parseFromJSON() failed [eps_interworking_ind]"); + goto end; + } + eps_interworking_indVariable = OpenAPI_eps_interworking_indication_FromString(eps_interworking_ind->valuestring); } cJSON *secondary_rat_usage_report = cJSON_GetObjectItemCaseSensitive(hsmf_update_dataJSON, "secondaryRatUsageReport"); @@ -1180,9 +1157,13 @@ OpenAPI_hsmf_update_data_t *OpenAPI_hsmf_update_data_parseFromJSON(cJSON *hsmf_u cJSON *ma_release_ind = cJSON_GetObjectItemCaseSensitive(hsmf_update_dataJSON, "maReleaseInd"); - OpenAPI_ma_release_indication_t *ma_release_ind_local_nonprim = NULL; + OpenAPI_ma_release_indication_e ma_release_indVariable; if (ma_release_ind) { - ma_release_ind_local_nonprim = OpenAPI_ma_release_indication_parseFromJSON(ma_release_ind); + if (!cJSON_IsString(ma_release_ind)) { + ogs_error("OpenAPI_hsmf_update_data_parseFromJSON() failed [ma_release_ind]"); + goto end; + } + ma_release_indVariable = OpenAPI_ma_release_indication_FromString(ma_release_ind->valuestring); } cJSON *ma_nw_upgrade_ind = cJSON_GetObjectItemCaseSensitive(hsmf_update_dataJSON, "maNwUpgradeInd"); @@ -1205,9 +1186,13 @@ OpenAPI_hsmf_update_data_t *OpenAPI_hsmf_update_data_parseFromJSON(cJSON *hsmf_u cJSON *unavailable_access_ind = cJSON_GetObjectItemCaseSensitive(hsmf_update_dataJSON, "unavailableAccessInd"); - OpenAPI_unavailable_access_indication_t *unavailable_access_ind_local_nonprim = NULL; + OpenAPI_unavailable_access_indication_e unavailable_access_indVariable; if (unavailable_access_ind) { - unavailable_access_ind_local_nonprim = OpenAPI_unavailable_access_indication_parseFromJSON(unavailable_access_ind); + if (!cJSON_IsString(unavailable_access_ind)) { + ogs_error("OpenAPI_hsmf_update_data_parseFromJSON() failed [unavailable_access_ind]"); + goto end; + } + unavailable_access_indVariable = OpenAPI_unavailable_access_indication_FromString(unavailable_access_ind->valuestring); } cJSON *psa_info = cJSON_GetObjectItemCaseSensitive(hsmf_update_dataJSON, "psaInfo"); @@ -1389,7 +1374,7 @@ OpenAPI_hsmf_update_data_t *OpenAPI_hsmf_update_data_parseFromJSON(cJSON *hsmf_u } hsmf_update_data_local_var = OpenAPI_hsmf_update_data_create ( - request_indication_local_nonprim, + request_indicationVariable, pei ? ogs_strdup(pei->valuestring) : NULL, vcn_tunnel_info ? vcn_tunnel_info_local_nonprim : NULL, icn_tunnel_info ? icn_tunnel_info_local_nonprim : NULL, @@ -1411,18 +1396,18 @@ OpenAPI_hsmf_update_data_t *OpenAPI_hsmf_update_data_parseFromJSON(cJSON *hsmf_u eps_bearer_id ? eps_bearer_idList : NULL, ho_preparation_indication ? ho_preparation_indication->valueint : 0, revoke_ebi_list ? revoke_ebi_listList : NULL, - cause ? cause_local_nonprim : NULL, + cause ? causeVariable : 0, ng_ap_cause ? ng_ap_cause_local_nonprim : NULL, _5g_mm_cause_value ? _5g_mm_cause_value->valuedouble : 0, always_on_requested ? always_on_requested->valueint : 0, - eps_interworking_ind ? eps_interworking_ind_local_nonprim : NULL, + eps_interworking_ind ? eps_interworking_indVariable : 0, secondary_rat_usage_report ? secondary_rat_usage_reportList : NULL, secondary_rat_usage_info ? secondary_rat_usage_infoList : NULL, an_type_can_be_changed ? an_type_can_be_changed->valueint : 0, - ma_release_ind ? ma_release_ind_local_nonprim : NULL, + ma_release_ind ? ma_release_indVariable : 0, ma_nw_upgrade_ind ? ma_nw_upgrade_ind->valueint : 0, ma_request_ind ? ma_request_ind->valueint : 0, - unavailable_access_ind ? unavailable_access_ind_local_nonprim : NULL, + unavailable_access_ind ? unavailable_access_indVariable : 0, psa_info ? psa_infoList : NULL, ulcl_bp_info ? ulcl_bp_info_local_nonprim : NULL, n4_info ? n4_info_local_nonprim : NULL, diff --git a/lib/sbi/openapi/model/hsmf_update_data.h b/lib/sbi/openapi/model/hsmf_update_data.h index e595b1c9b..3adcef66c 100644 --- a/lib/sbi/openapi/model/hsmf_update_data.h +++ b/lib/sbi/openapi/model/hsmf_update_data.h @@ -44,7 +44,7 @@ extern "C" { typedef struct OpenAPI_hsmf_update_data_s OpenAPI_hsmf_update_data_t; typedef struct OpenAPI_hsmf_update_data_s { - struct OpenAPI_request_indication_s *request_indication; + OpenAPI_request_indication_e request_indication; char *pei; struct OpenAPI_tunnel_info_s *vcn_tunnel_info; struct OpenAPI_tunnel_info_s *icn_tunnel_info; @@ -66,18 +66,18 @@ typedef struct OpenAPI_hsmf_update_data_s { OpenAPI_list_t *eps_bearer_id; int ho_preparation_indication; OpenAPI_list_t *revoke_ebi_list; - struct OpenAPI_cause_s *cause; + OpenAPI_cause_e cause; struct OpenAPI_ng_ap_cause_s *ng_ap_cause; int _5g_mm_cause_value; int always_on_requested; - struct OpenAPI_eps_interworking_indication_s *eps_interworking_ind; + OpenAPI_eps_interworking_indication_e eps_interworking_ind; OpenAPI_list_t *secondary_rat_usage_report; OpenAPI_list_t *secondary_rat_usage_info; int an_type_can_be_changed; - struct OpenAPI_ma_release_indication_s *ma_release_ind; + OpenAPI_ma_release_indication_e ma_release_ind; int ma_nw_upgrade_ind; int ma_request_ind; - struct OpenAPI_unavailable_access_indication_s *unavailable_access_ind; + OpenAPI_unavailable_access_indication_e unavailable_access_ind; OpenAPI_list_t *psa_info; struct OpenAPI_ulcl_bp_information_s *ulcl_bp_info; struct OpenAPI_n4_information_s *n4_info; @@ -100,7 +100,7 @@ typedef struct OpenAPI_hsmf_update_data_s { } OpenAPI_hsmf_update_data_t; OpenAPI_hsmf_update_data_t *OpenAPI_hsmf_update_data_create( - OpenAPI_request_indication_t *request_indication, + OpenAPI_request_indication_e request_indication, char *pei, OpenAPI_tunnel_info_t *vcn_tunnel_info, OpenAPI_tunnel_info_t *icn_tunnel_info, @@ -122,18 +122,18 @@ OpenAPI_hsmf_update_data_t *OpenAPI_hsmf_update_data_create( OpenAPI_list_t *eps_bearer_id, int ho_preparation_indication, OpenAPI_list_t *revoke_ebi_list, - OpenAPI_cause_t *cause, + OpenAPI_cause_e cause, OpenAPI_ng_ap_cause_t *ng_ap_cause, int _5g_mm_cause_value, int always_on_requested, - OpenAPI_eps_interworking_indication_t *eps_interworking_ind, + OpenAPI_eps_interworking_indication_e eps_interworking_ind, OpenAPI_list_t *secondary_rat_usage_report, OpenAPI_list_t *secondary_rat_usage_info, int an_type_can_be_changed, - OpenAPI_ma_release_indication_t *ma_release_ind, + OpenAPI_ma_release_indication_e ma_release_ind, int ma_nw_upgrade_ind, int ma_request_ind, - OpenAPI_unavailable_access_indication_t *unavailable_access_ind, + OpenAPI_unavailable_access_indication_e unavailable_access_ind, OpenAPI_list_t *psa_info, OpenAPI_ulcl_bp_information_t *ulcl_bp_info, OpenAPI_n4_information_t *n4_info, diff --git a/lib/sbi/openapi/model/ma_release_indication.c b/lib/sbi/openapi/model/ma_release_indication.c index 50033cb68..3e8c96968 100644 --- a/lib/sbi/openapi/model/ma_release_indication.c +++ b/lib/sbi/openapi/model/ma_release_indication.c @@ -4,82 +4,27 @@ #include #include "ma_release_indication.h" -OpenAPI_ma_release_indication_t *OpenAPI_ma_release_indication_create( - ) +char* OpenAPI_ma_release_indication_ToString(OpenAPI_ma_release_indication_e ma_release_indication) { - OpenAPI_ma_release_indication_t *ma_release_indication_local_var = OpenAPI_malloc(sizeof(OpenAPI_ma_release_indication_t)); - if (!ma_release_indication_local_var) { - return NULL; - } - - return ma_release_indication_local_var; + const char *ma_release_indicationArray[] = { "NULL", "REL_MAPDU_OVER_3GPP", "REL_MAPDU_OVER_N3GPP" }; + size_t sizeofArray = sizeof(ma_release_indicationArray) / sizeof(ma_release_indicationArray[0]); + if (ma_release_indication < sizeofArray) + return (char *)ma_release_indicationArray[ma_release_indication]; + else + return (char *)"Unknown"; } -void OpenAPI_ma_release_indication_free(OpenAPI_ma_release_indication_t *ma_release_indication) +OpenAPI_ma_release_indication_e OpenAPI_ma_release_indication_FromString(char* ma_release_indication) { - if (NULL == ma_release_indication) { - return; + int stringToReturn = 0; + const char *ma_release_indicationArray[] = { "NULL", "REL_MAPDU_OVER_3GPP", "REL_MAPDU_OVER_N3GPP" }; + size_t sizeofArray = sizeof(ma_release_indicationArray) / sizeof(ma_release_indicationArray[0]); + while (stringToReturn < sizeofArray) { + if (strcmp(ma_release_indication, ma_release_indicationArray[stringToReturn]) == 0) { + return stringToReturn; + } + stringToReturn++; } - OpenAPI_lnode_t *node; - ogs_free(ma_release_indication); -} - -cJSON *OpenAPI_ma_release_indication_convertToJSON(OpenAPI_ma_release_indication_t *ma_release_indication) -{ - cJSON *item = NULL; - - if (ma_release_indication == NULL) { - ogs_error("OpenAPI_ma_release_indication_convertToJSON() failed [MaReleaseIndication]"); - return NULL; - } - - item = cJSON_CreateObject(); -end: - return item; -} - -OpenAPI_ma_release_indication_t *OpenAPI_ma_release_indication_parseFromJSON(cJSON *ma_release_indicationJSON) -{ - OpenAPI_ma_release_indication_t *ma_release_indication_local_var = NULL; - ma_release_indication_local_var = OpenAPI_ma_release_indication_create ( - ); - - return ma_release_indication_local_var; -end: - return NULL; -} - -OpenAPI_ma_release_indication_t *OpenAPI_ma_release_indication_copy(OpenAPI_ma_release_indication_t *dst, OpenAPI_ma_release_indication_t *src) -{ - cJSON *item = NULL; - char *content = NULL; - - ogs_assert(src); - item = OpenAPI_ma_release_indication_convertToJSON(src); - if (!item) { - ogs_error("OpenAPI_ma_release_indication_convertToJSON() failed"); - return NULL; - } - - content = cJSON_Print(item); - cJSON_Delete(item); - - if (!content) { - ogs_error("cJSON_Print() failed"); - return NULL; - } - - item = cJSON_Parse(content); - ogs_free(content); - if (!item) { - ogs_error("cJSON_Parse() failed"); - return NULL; - } - - OpenAPI_ma_release_indication_free(dst); - dst = OpenAPI_ma_release_indication_parseFromJSON(item); - cJSON_Delete(item); - - return dst; + return 0; } diff --git a/lib/sbi/openapi/model/ma_release_indication.h b/lib/sbi/openapi/model/ma_release_indication.h index 0e6c3407d..abbfbc86b 100644 --- a/lib/sbi/openapi/model/ma_release_indication.h +++ b/lib/sbi/openapi/model/ma_release_indication.h @@ -1,7 +1,7 @@ /* * ma_release_indication.h * - * Possible values are - REL_MAPDU_OVER_3GPP - REL_MAPDU_OVER_N3GPP + * */ #ifndef _OpenAPI_ma_release_indication_H_ @@ -17,16 +17,11 @@ extern "C" { #endif -typedef struct OpenAPI_ma_release_indication_s OpenAPI_ma_release_indication_t; -typedef struct OpenAPI_ma_release_indication_s { -} OpenAPI_ma_release_indication_t; +typedef enum { OpenAPI_ma_release_indication_NULL = 0, OpenAPI_ma_release_indication_REL_MAPDU_OVER_3GPP, OpenAPI_ma_release_indication_REL_MAPDU_OVER_N3GPP } OpenAPI_ma_release_indication_e; -OpenAPI_ma_release_indication_t *OpenAPI_ma_release_indication_create( - ); -void OpenAPI_ma_release_indication_free(OpenAPI_ma_release_indication_t *ma_release_indication); -OpenAPI_ma_release_indication_t *OpenAPI_ma_release_indication_parseFromJSON(cJSON *ma_release_indicationJSON); -cJSON *OpenAPI_ma_release_indication_convertToJSON(OpenAPI_ma_release_indication_t *ma_release_indication); -OpenAPI_ma_release_indication_t *OpenAPI_ma_release_indication_copy(OpenAPI_ma_release_indication_t *dst, OpenAPI_ma_release_indication_t *src); +char* OpenAPI_ma_release_indication_ToString(OpenAPI_ma_release_indication_e ma_release_indication); + +OpenAPI_ma_release_indication_e OpenAPI_ma_release_indication_FromString(char* ma_release_indication); #ifdef __cplusplus } diff --git a/lib/sbi/openapi/model/max_integrity_protected_data_rate.c b/lib/sbi/openapi/model/max_integrity_protected_data_rate.c index 687498fe6..76488f6fb 100644 --- a/lib/sbi/openapi/model/max_integrity_protected_data_rate.c +++ b/lib/sbi/openapi/model/max_integrity_protected_data_rate.c @@ -4,82 +4,27 @@ #include #include "max_integrity_protected_data_rate.h" -OpenAPI_max_integrity_protected_data_rate_t *OpenAPI_max_integrity_protected_data_rate_create( - ) +char* OpenAPI_max_integrity_protected_data_rate_ToString(OpenAPI_max_integrity_protected_data_rate_e max_integrity_protected_data_rate) { - OpenAPI_max_integrity_protected_data_rate_t *max_integrity_protected_data_rate_local_var = OpenAPI_malloc(sizeof(OpenAPI_max_integrity_protected_data_rate_t)); - if (!max_integrity_protected_data_rate_local_var) { - return NULL; - } - - return max_integrity_protected_data_rate_local_var; + const char *max_integrity_protected_data_rateArray[] = { "NULL", "_64_KBPS", "MAX_UE_RATE" }; + size_t sizeofArray = sizeof(max_integrity_protected_data_rateArray) / sizeof(max_integrity_protected_data_rateArray[0]); + if (max_integrity_protected_data_rate < sizeofArray) + return (char *)max_integrity_protected_data_rateArray[max_integrity_protected_data_rate]; + else + return (char *)"Unknown"; } -void OpenAPI_max_integrity_protected_data_rate_free(OpenAPI_max_integrity_protected_data_rate_t *max_integrity_protected_data_rate) +OpenAPI_max_integrity_protected_data_rate_e OpenAPI_max_integrity_protected_data_rate_FromString(char* max_integrity_protected_data_rate) { - if (NULL == max_integrity_protected_data_rate) { - return; + int stringToReturn = 0; + const char *max_integrity_protected_data_rateArray[] = { "NULL", "_64_KBPS", "MAX_UE_RATE" }; + size_t sizeofArray = sizeof(max_integrity_protected_data_rateArray) / sizeof(max_integrity_protected_data_rateArray[0]); + while (stringToReturn < sizeofArray) { + if (strcmp(max_integrity_protected_data_rate, max_integrity_protected_data_rateArray[stringToReturn]) == 0) { + return stringToReturn; + } + stringToReturn++; } - OpenAPI_lnode_t *node; - ogs_free(max_integrity_protected_data_rate); -} - -cJSON *OpenAPI_max_integrity_protected_data_rate_convertToJSON(OpenAPI_max_integrity_protected_data_rate_t *max_integrity_protected_data_rate) -{ - cJSON *item = NULL; - - if (max_integrity_protected_data_rate == NULL) { - ogs_error("OpenAPI_max_integrity_protected_data_rate_convertToJSON() failed [MaxIntegrityProtectedDataRate]"); - return NULL; - } - - item = cJSON_CreateObject(); -end: - return item; -} - -OpenAPI_max_integrity_protected_data_rate_t *OpenAPI_max_integrity_protected_data_rate_parseFromJSON(cJSON *max_integrity_protected_data_rateJSON) -{ - OpenAPI_max_integrity_protected_data_rate_t *max_integrity_protected_data_rate_local_var = NULL; - max_integrity_protected_data_rate_local_var = OpenAPI_max_integrity_protected_data_rate_create ( - ); - - return max_integrity_protected_data_rate_local_var; -end: - return NULL; -} - -OpenAPI_max_integrity_protected_data_rate_t *OpenAPI_max_integrity_protected_data_rate_copy(OpenAPI_max_integrity_protected_data_rate_t *dst, OpenAPI_max_integrity_protected_data_rate_t *src) -{ - cJSON *item = NULL; - char *content = NULL; - - ogs_assert(src); - item = OpenAPI_max_integrity_protected_data_rate_convertToJSON(src); - if (!item) { - ogs_error("OpenAPI_max_integrity_protected_data_rate_convertToJSON() failed"); - return NULL; - } - - content = cJSON_Print(item); - cJSON_Delete(item); - - if (!content) { - ogs_error("cJSON_Print() failed"); - return NULL; - } - - item = cJSON_Parse(content); - ogs_free(content); - if (!item) { - ogs_error("cJSON_Parse() failed"); - return NULL; - } - - OpenAPI_max_integrity_protected_data_rate_free(dst); - dst = OpenAPI_max_integrity_protected_data_rate_parseFromJSON(item); - cJSON_Delete(item); - - return dst; + return 0; } diff --git a/lib/sbi/openapi/model/max_integrity_protected_data_rate.h b/lib/sbi/openapi/model/max_integrity_protected_data_rate.h index ea25235f7..d52531d8e 100644 --- a/lib/sbi/openapi/model/max_integrity_protected_data_rate.h +++ b/lib/sbi/openapi/model/max_integrity_protected_data_rate.h @@ -1,7 +1,7 @@ /* * max_integrity_protected_data_rate.h * - * Possible values are - 64_KBPS - MAX_UE_RATE + * */ #ifndef _OpenAPI_max_integrity_protected_data_rate_H_ @@ -17,16 +17,11 @@ extern "C" { #endif -typedef struct OpenAPI_max_integrity_protected_data_rate_s OpenAPI_max_integrity_protected_data_rate_t; -typedef struct OpenAPI_max_integrity_protected_data_rate_s { -} OpenAPI_max_integrity_protected_data_rate_t; +typedef enum { OpenAPI_max_integrity_protected_data_rate_NULL = 0, OpenAPI_max_integrity_protected_data_rate__64_KBPS, OpenAPI_max_integrity_protected_data_rate_MAX_UE_RATE } OpenAPI_max_integrity_protected_data_rate_e; -OpenAPI_max_integrity_protected_data_rate_t *OpenAPI_max_integrity_protected_data_rate_create( - ); -void OpenAPI_max_integrity_protected_data_rate_free(OpenAPI_max_integrity_protected_data_rate_t *max_integrity_protected_data_rate); -OpenAPI_max_integrity_protected_data_rate_t *OpenAPI_max_integrity_protected_data_rate_parseFromJSON(cJSON *max_integrity_protected_data_rateJSON); -cJSON *OpenAPI_max_integrity_protected_data_rate_convertToJSON(OpenAPI_max_integrity_protected_data_rate_t *max_integrity_protected_data_rate); -OpenAPI_max_integrity_protected_data_rate_t *OpenAPI_max_integrity_protected_data_rate_copy(OpenAPI_max_integrity_protected_data_rate_t *dst, OpenAPI_max_integrity_protected_data_rate_t *src); +char* OpenAPI_max_integrity_protected_data_rate_ToString(OpenAPI_max_integrity_protected_data_rate_e max_integrity_protected_data_rate); + +OpenAPI_max_integrity_protected_data_rate_e OpenAPI_max_integrity_protected_data_rate_FromString(char* max_integrity_protected_data_rate); #ifdef __cplusplus } diff --git a/lib/sbi/openapi/model/n4_information.c b/lib/sbi/openapi/model/n4_information.c index 2ab19c061..3899994a6 100644 --- a/lib/sbi/openapi/model/n4_information.c +++ b/lib/sbi/openapi/model/n4_information.c @@ -5,7 +5,7 @@ #include "n4_information.h" OpenAPI_n4_information_t *OpenAPI_n4_information_create( - OpenAPI_n4_message_type_t *n4_message_type, + OpenAPI_n4_message_type_e n4_message_type, OpenAPI_ref_to_binary_data_t *n4_message_payload, OpenAPI_dnai_information_t *n4_dnai_info ) @@ -27,7 +27,6 @@ void OpenAPI_n4_information_free(OpenAPI_n4_information_t *n4_information) return; } OpenAPI_lnode_t *node; - OpenAPI_n4_message_type_free(n4_information->n4_message_type); OpenAPI_ref_to_binary_data_free(n4_information->n4_message_payload); OpenAPI_dnai_information_free(n4_information->n4_dnai_info); ogs_free(n4_information); @@ -47,13 +46,7 @@ cJSON *OpenAPI_n4_information_convertToJSON(OpenAPI_n4_information_t *n4_informa ogs_error("OpenAPI_n4_information_convertToJSON() failed [n4_message_type]"); goto end; } - cJSON *n4_message_type_local_JSON = OpenAPI_n4_message_type_convertToJSON(n4_information->n4_message_type); - if (n4_message_type_local_JSON == NULL) { - ogs_error("OpenAPI_n4_information_convertToJSON() failed [n4_message_type]"); - goto end; - } - cJSON_AddItemToObject(item, "n4MessageType", n4_message_type_local_JSON); - if (item->child == NULL) { + if (cJSON_AddStringToObject(item, "n4MessageType", OpenAPI_n4_message_type_ToString(n4_information->n4_message_type)) == NULL) { ogs_error("OpenAPI_n4_information_convertToJSON() failed [n4_message_type]"); goto end; } @@ -99,9 +92,13 @@ OpenAPI_n4_information_t *OpenAPI_n4_information_parseFromJSON(cJSON *n4_informa goto end; } - OpenAPI_n4_message_type_t *n4_message_type_local_nonprim = NULL; + OpenAPI_n4_message_type_e n4_message_typeVariable; - n4_message_type_local_nonprim = OpenAPI_n4_message_type_parseFromJSON(n4_message_type); + if (!cJSON_IsString(n4_message_type)) { + ogs_error("OpenAPI_n4_information_parseFromJSON() failed [n4_message_type]"); + goto end; + } + n4_message_typeVariable = OpenAPI_n4_message_type_FromString(n4_message_type->valuestring); cJSON *n4_message_payload = cJSON_GetObjectItemCaseSensitive(n4_informationJSON, "n4MessagePayload"); if (!n4_message_payload) { @@ -121,7 +118,7 @@ OpenAPI_n4_information_t *OpenAPI_n4_information_parseFromJSON(cJSON *n4_informa } n4_information_local_var = OpenAPI_n4_information_create ( - n4_message_type_local_nonprim, + n4_message_typeVariable, n4_message_payload_local_nonprim, n4_dnai_info ? n4_dnai_info_local_nonprim : NULL ); diff --git a/lib/sbi/openapi/model/n4_information.h b/lib/sbi/openapi/model/n4_information.h index 64d8f9025..341e3042e 100644 --- a/lib/sbi/openapi/model/n4_information.h +++ b/lib/sbi/openapi/model/n4_information.h @@ -22,13 +22,13 @@ extern "C" { typedef struct OpenAPI_n4_information_s OpenAPI_n4_information_t; typedef struct OpenAPI_n4_information_s { - struct OpenAPI_n4_message_type_s *n4_message_type; + OpenAPI_n4_message_type_e n4_message_type; struct OpenAPI_ref_to_binary_data_s *n4_message_payload; struct OpenAPI_dnai_information_s *n4_dnai_info; } OpenAPI_n4_information_t; OpenAPI_n4_information_t *OpenAPI_n4_information_create( - OpenAPI_n4_message_type_t *n4_message_type, + OpenAPI_n4_message_type_e n4_message_type, OpenAPI_ref_to_binary_data_t *n4_message_payload, OpenAPI_dnai_information_t *n4_dnai_info ); diff --git a/lib/sbi/openapi/model/n4_message_type.c b/lib/sbi/openapi/model/n4_message_type.c index 433214aa9..fdefd7822 100644 --- a/lib/sbi/openapi/model/n4_message_type.c +++ b/lib/sbi/openapi/model/n4_message_type.c @@ -4,82 +4,27 @@ #include #include "n4_message_type.h" -OpenAPI_n4_message_type_t *OpenAPI_n4_message_type_create( - ) +char* OpenAPI_n4_message_type_ToString(OpenAPI_n4_message_type_e n4_message_type) { - OpenAPI_n4_message_type_t *n4_message_type_local_var = OpenAPI_malloc(sizeof(OpenAPI_n4_message_type_t)); - if (!n4_message_type_local_var) { - return NULL; - } - - return n4_message_type_local_var; + const char *n4_message_typeArray[] = { "NULL", "PFCP_SES_EST_REQ", "PFCP_SES_EST_RSP", "PFCP_SES_MOD_REQ", "PFCP_SES_MOD_RSP", "PFCP_SES_DEL_REQ", "PFCP_SES_DEL_RSP", "PFCP_SES_REP_REQ", "PFCP_SES_REP_RSP" }; + size_t sizeofArray = sizeof(n4_message_typeArray) / sizeof(n4_message_typeArray[0]); + if (n4_message_type < sizeofArray) + return (char *)n4_message_typeArray[n4_message_type]; + else + return (char *)"Unknown"; } -void OpenAPI_n4_message_type_free(OpenAPI_n4_message_type_t *n4_message_type) +OpenAPI_n4_message_type_e OpenAPI_n4_message_type_FromString(char* n4_message_type) { - if (NULL == n4_message_type) { - return; + int stringToReturn = 0; + const char *n4_message_typeArray[] = { "NULL", "PFCP_SES_EST_REQ", "PFCP_SES_EST_RSP", "PFCP_SES_MOD_REQ", "PFCP_SES_MOD_RSP", "PFCP_SES_DEL_REQ", "PFCP_SES_DEL_RSP", "PFCP_SES_REP_REQ", "PFCP_SES_REP_RSP" }; + size_t sizeofArray = sizeof(n4_message_typeArray) / sizeof(n4_message_typeArray[0]); + while (stringToReturn < sizeofArray) { + if (strcmp(n4_message_type, n4_message_typeArray[stringToReturn]) == 0) { + return stringToReturn; + } + stringToReturn++; } - OpenAPI_lnode_t *node; - ogs_free(n4_message_type); -} - -cJSON *OpenAPI_n4_message_type_convertToJSON(OpenAPI_n4_message_type_t *n4_message_type) -{ - cJSON *item = NULL; - - if (n4_message_type == NULL) { - ogs_error("OpenAPI_n4_message_type_convertToJSON() failed [N4MessageType]"); - return NULL; - } - - item = cJSON_CreateObject(); -end: - return item; -} - -OpenAPI_n4_message_type_t *OpenAPI_n4_message_type_parseFromJSON(cJSON *n4_message_typeJSON) -{ - OpenAPI_n4_message_type_t *n4_message_type_local_var = NULL; - n4_message_type_local_var = OpenAPI_n4_message_type_create ( - ); - - return n4_message_type_local_var; -end: - return NULL; -} - -OpenAPI_n4_message_type_t *OpenAPI_n4_message_type_copy(OpenAPI_n4_message_type_t *dst, OpenAPI_n4_message_type_t *src) -{ - cJSON *item = NULL; - char *content = NULL; - - ogs_assert(src); - item = OpenAPI_n4_message_type_convertToJSON(src); - if (!item) { - ogs_error("OpenAPI_n4_message_type_convertToJSON() failed"); - return NULL; - } - - content = cJSON_Print(item); - cJSON_Delete(item); - - if (!content) { - ogs_error("cJSON_Print() failed"); - return NULL; - } - - item = cJSON_Parse(content); - ogs_free(content); - if (!item) { - ogs_error("cJSON_Parse() failed"); - return NULL; - } - - OpenAPI_n4_message_type_free(dst); - dst = OpenAPI_n4_message_type_parseFromJSON(item); - cJSON_Delete(item); - - return dst; + return 0; } diff --git a/lib/sbi/openapi/model/n4_message_type.h b/lib/sbi/openapi/model/n4_message_type.h index b2343e6bb..6bd780fe9 100644 --- a/lib/sbi/openapi/model/n4_message_type.h +++ b/lib/sbi/openapi/model/n4_message_type.h @@ -1,7 +1,7 @@ /* * n4_message_type.h * - * Possible values are - PFCP_SES_EST_REQ - PFCP_SES_EST_RSP - PFCP_SES_MOD_REQ - PFCP_SES_MOD_RSP - PFCP_SES_DEL_REQ - PFCP_SES_DEL_RSP - PFCP_SES_REP_REQ - PFCP_SES_REP_RSP + * */ #ifndef _OpenAPI_n4_message_type_H_ @@ -17,16 +17,11 @@ extern "C" { #endif -typedef struct OpenAPI_n4_message_type_s OpenAPI_n4_message_type_t; -typedef struct OpenAPI_n4_message_type_s { -} OpenAPI_n4_message_type_t; +typedef enum { OpenAPI_n4_message_type_NULL = 0, OpenAPI_n4_message_type_PFCP_SES_EST_REQ, OpenAPI_n4_message_type_PFCP_SES_EST_RSP, OpenAPI_n4_message_type_PFCP_SES_MOD_REQ, OpenAPI_n4_message_type_PFCP_SES_MOD_RSP, OpenAPI_n4_message_type_PFCP_SES_DEL_REQ, OpenAPI_n4_message_type_PFCP_SES_DEL_RSP, OpenAPI_n4_message_type_PFCP_SES_REP_REQ, OpenAPI_n4_message_type_PFCP_SES_REP_RSP } OpenAPI_n4_message_type_e; -OpenAPI_n4_message_type_t *OpenAPI_n4_message_type_create( - ); -void OpenAPI_n4_message_type_free(OpenAPI_n4_message_type_t *n4_message_type); -OpenAPI_n4_message_type_t *OpenAPI_n4_message_type_parseFromJSON(cJSON *n4_message_typeJSON); -cJSON *OpenAPI_n4_message_type_convertToJSON(OpenAPI_n4_message_type_t *n4_message_type); -OpenAPI_n4_message_type_t *OpenAPI_n4_message_type_copy(OpenAPI_n4_message_type_t *dst, OpenAPI_n4_message_type_t *src); +char* OpenAPI_n4_message_type_ToString(OpenAPI_n4_message_type_e n4_message_type); + +OpenAPI_n4_message_type_e OpenAPI_n4_message_type_FromString(char* n4_message_type); #ifdef __cplusplus } diff --git a/lib/sbi/openapi/model/notification_cause.c b/lib/sbi/openapi/model/notification_cause.c index d1e236375..9fbca1390 100644 --- a/lib/sbi/openapi/model/notification_cause.c +++ b/lib/sbi/openapi/model/notification_cause.c @@ -4,82 +4,27 @@ #include #include "notification_cause.h" -OpenAPI_notification_cause_t *OpenAPI_notification_cause_create( - ) +char* OpenAPI_notification_cause_ToString(OpenAPI_notification_cause_e notification_cause) { - OpenAPI_notification_cause_t *notification_cause_local_var = OpenAPI_malloc(sizeof(OpenAPI_notification_cause_t)); - if (!notification_cause_local_var) { - return NULL; - } - - return notification_cause_local_var; + const char *notification_causeArray[] = { "NULL", "QOS_FULFILLED", "QOS_NOT_FULFILLED", "UP_SEC_FULFILLED", "UP_SEC_NOT_FULFILLED" }; + size_t sizeofArray = sizeof(notification_causeArray) / sizeof(notification_causeArray[0]); + if (notification_cause < sizeofArray) + return (char *)notification_causeArray[notification_cause]; + else + return (char *)"Unknown"; } -void OpenAPI_notification_cause_free(OpenAPI_notification_cause_t *notification_cause) +OpenAPI_notification_cause_e OpenAPI_notification_cause_FromString(char* notification_cause) { - if (NULL == notification_cause) { - return; + int stringToReturn = 0; + const char *notification_causeArray[] = { "NULL", "QOS_FULFILLED", "QOS_NOT_FULFILLED", "UP_SEC_FULFILLED", "UP_SEC_NOT_FULFILLED" }; + size_t sizeofArray = sizeof(notification_causeArray) / sizeof(notification_causeArray[0]); + while (stringToReturn < sizeofArray) { + if (strcmp(notification_cause, notification_causeArray[stringToReturn]) == 0) { + return stringToReturn; + } + stringToReturn++; } - OpenAPI_lnode_t *node; - ogs_free(notification_cause); -} - -cJSON *OpenAPI_notification_cause_convertToJSON(OpenAPI_notification_cause_t *notification_cause) -{ - cJSON *item = NULL; - - if (notification_cause == NULL) { - ogs_error("OpenAPI_notification_cause_convertToJSON() failed [NotificationCause]"); - return NULL; - } - - item = cJSON_CreateObject(); -end: - return item; -} - -OpenAPI_notification_cause_t *OpenAPI_notification_cause_parseFromJSON(cJSON *notification_causeJSON) -{ - OpenAPI_notification_cause_t *notification_cause_local_var = NULL; - notification_cause_local_var = OpenAPI_notification_cause_create ( - ); - - return notification_cause_local_var; -end: - return NULL; -} - -OpenAPI_notification_cause_t *OpenAPI_notification_cause_copy(OpenAPI_notification_cause_t *dst, OpenAPI_notification_cause_t *src) -{ - cJSON *item = NULL; - char *content = NULL; - - ogs_assert(src); - item = OpenAPI_notification_cause_convertToJSON(src); - if (!item) { - ogs_error("OpenAPI_notification_cause_convertToJSON() failed"); - return NULL; - } - - content = cJSON_Print(item); - cJSON_Delete(item); - - if (!content) { - ogs_error("cJSON_Print() failed"); - return NULL; - } - - item = cJSON_Parse(content); - ogs_free(content); - if (!item) { - ogs_error("cJSON_Parse() failed"); - return NULL; - } - - OpenAPI_notification_cause_free(dst); - dst = OpenAPI_notification_cause_parseFromJSON(item); - cJSON_Delete(item); - - return dst; + return 0; } diff --git a/lib/sbi/openapi/model/notification_cause.h b/lib/sbi/openapi/model/notification_cause.h index 8ea42cba5..c89e128d8 100644 --- a/lib/sbi/openapi/model/notification_cause.h +++ b/lib/sbi/openapi/model/notification_cause.h @@ -1,7 +1,7 @@ /* * notification_cause.h * - * Possible values are - QOS_FULFILLED - QOS_NOT_FULFILLED - UP_SEC_FULFILLED - UP_SEC_NOT_FULFILLED + * */ #ifndef _OpenAPI_notification_cause_H_ @@ -17,16 +17,11 @@ extern "C" { #endif -typedef struct OpenAPI_notification_cause_s OpenAPI_notification_cause_t; -typedef struct OpenAPI_notification_cause_s { -} OpenAPI_notification_cause_t; +typedef enum { OpenAPI_notification_cause_NULL = 0, OpenAPI_notification_cause_QOS_FULFILLED, OpenAPI_notification_cause_QOS_NOT_FULFILLED, OpenAPI_notification_cause_UP_SEC_FULFILLED, OpenAPI_notification_cause_UP_SEC_NOT_FULFILLED } OpenAPI_notification_cause_e; -OpenAPI_notification_cause_t *OpenAPI_notification_cause_create( - ); -void OpenAPI_notification_cause_free(OpenAPI_notification_cause_t *notification_cause); -OpenAPI_notification_cause_t *OpenAPI_notification_cause_parseFromJSON(cJSON *notification_causeJSON); -cJSON *OpenAPI_notification_cause_convertToJSON(OpenAPI_notification_cause_t *notification_cause); -OpenAPI_notification_cause_t *OpenAPI_notification_cause_copy(OpenAPI_notification_cause_t *dst, OpenAPI_notification_cause_t *src); +char* OpenAPI_notification_cause_ToString(OpenAPI_notification_cause_e notification_cause); + +OpenAPI_notification_cause_e OpenAPI_notification_cause_FromString(char* notification_cause); #ifdef __cplusplus } diff --git a/lib/sbi/openapi/model/pdu_session_create_data.c b/lib/sbi/openapi/model/pdu_session_create_data.c index ff6d3d25f..08768f9af 100644 --- a/lib/sbi/openapi/model/pdu_session_create_data.c +++ b/lib/sbi/openapi/model/pdu_session_create_data.c @@ -14,7 +14,7 @@ OpenAPI_pdu_session_create_data_t *OpenAPI_pdu_session_create_data_create( char *vsmf_id, char *ismf_id, OpenAPI_plmn_id_nid_t *serving_network, - OpenAPI_request_type_t *request_type, + OpenAPI_request_type_e request_type, OpenAPI_list_t *eps_bearer_id, char pgw_s8c_fteid, char *vsmf_pdu_session_uri, @@ -38,11 +38,11 @@ OpenAPI_pdu_session_create_data_t *OpenAPI_pdu_session_create_data_create( char *pcf_group_id, char *pcf_set_id, int ho_preparation_indication, - OpenAPI_dnn_selection_mode_t *sel_mode, + OpenAPI_dnn_selection_mode_e sel_mode, int always_on_requested, char *udm_group_id, char *routing_indicator, - OpenAPI_eps_interworking_indication_t *eps_interworking_ind, + OpenAPI_eps_interworking_indication_e eps_interworking_ind, char *v_smf_service_instance_id, char *i_smf_service_instance_id, char *recovery_time, @@ -144,7 +144,6 @@ void OpenAPI_pdu_session_create_data_free(OpenAPI_pdu_session_create_data_t *pdu ogs_free(pdu_session_create_data->vsmf_id); ogs_free(pdu_session_create_data->ismf_id); OpenAPI_plmn_id_nid_free(pdu_session_create_data->serving_network); - OpenAPI_request_type_free(pdu_session_create_data->request_type); OpenAPI_list_for_each(pdu_session_create_data->eps_bearer_id, node) { ogs_free(node->data); } @@ -166,10 +165,8 @@ void OpenAPI_pdu_session_create_data_free(OpenAPI_pdu_session_create_data_t *pdu ogs_free(pdu_session_create_data->pcf_id); ogs_free(pdu_session_create_data->pcf_group_id); ogs_free(pdu_session_create_data->pcf_set_id); - OpenAPI_dnn_selection_mode_free(pdu_session_create_data->sel_mode); ogs_free(pdu_session_create_data->udm_group_id); ogs_free(pdu_session_create_data->routing_indicator); - OpenAPI_eps_interworking_indication_free(pdu_session_create_data->eps_interworking_ind); ogs_free(pdu_session_create_data->v_smf_service_instance_id); ogs_free(pdu_session_create_data->i_smf_service_instance_id); ogs_free(pdu_session_create_data->recovery_time); @@ -282,13 +279,7 @@ cJSON *OpenAPI_pdu_session_create_data_convertToJSON(OpenAPI_pdu_session_create_ } if (pdu_session_create_data->request_type) { - cJSON *request_type_local_JSON = OpenAPI_request_type_convertToJSON(pdu_session_create_data->request_type); - if (request_type_local_JSON == NULL) { - ogs_error("OpenAPI_pdu_session_create_data_convertToJSON() failed [request_type]"); - goto end; - } - cJSON_AddItemToObject(item, "requestType", request_type_local_JSON); - if (item->child == NULL) { + if (cJSON_AddStringToObject(item, "requestType", OpenAPI_request_type_ToString(pdu_session_create_data->request_type)) == NULL) { ogs_error("OpenAPI_pdu_session_create_data_convertToJSON() failed [request_type]"); goto end; } @@ -515,13 +506,7 @@ cJSON *OpenAPI_pdu_session_create_data_convertToJSON(OpenAPI_pdu_session_create_ } if (pdu_session_create_data->sel_mode) { - cJSON *sel_mode_local_JSON = OpenAPI_dnn_selection_mode_convertToJSON(pdu_session_create_data->sel_mode); - if (sel_mode_local_JSON == NULL) { - ogs_error("OpenAPI_pdu_session_create_data_convertToJSON() failed [sel_mode]"); - goto end; - } - cJSON_AddItemToObject(item, "selMode", sel_mode_local_JSON); - if (item->child == NULL) { + if (cJSON_AddStringToObject(item, "selMode", OpenAPI_dnn_selection_mode_ToString(pdu_session_create_data->sel_mode)) == NULL) { ogs_error("OpenAPI_pdu_session_create_data_convertToJSON() failed [sel_mode]"); goto end; } @@ -549,13 +534,7 @@ cJSON *OpenAPI_pdu_session_create_data_convertToJSON(OpenAPI_pdu_session_create_ } if (pdu_session_create_data->eps_interworking_ind) { - cJSON *eps_interworking_ind_local_JSON = OpenAPI_eps_interworking_indication_convertToJSON(pdu_session_create_data->eps_interworking_ind); - if (eps_interworking_ind_local_JSON == NULL) { - ogs_error("OpenAPI_pdu_session_create_data_convertToJSON() failed [eps_interworking_ind]"); - goto end; - } - cJSON_AddItemToObject(item, "epsInterworkingInd", eps_interworking_ind_local_JSON); - if (item->child == NULL) { + if (cJSON_AddStringToObject(item, "epsInterworkingInd", OpenAPI_eps_interworking_indication_ToString(pdu_session_create_data->eps_interworking_ind)) == NULL) { ogs_error("OpenAPI_pdu_session_create_data_convertToJSON() failed [eps_interworking_ind]"); goto end; } @@ -845,9 +824,13 @@ OpenAPI_pdu_session_create_data_t *OpenAPI_pdu_session_create_data_parseFromJSON cJSON *request_type = cJSON_GetObjectItemCaseSensitive(pdu_session_create_dataJSON, "requestType"); - OpenAPI_request_type_t *request_type_local_nonprim = NULL; + OpenAPI_request_type_e request_typeVariable; if (request_type) { - request_type_local_nonprim = OpenAPI_request_type_parseFromJSON(request_type); + if (!cJSON_IsString(request_type)) { + ogs_error("OpenAPI_pdu_session_create_data_parseFromJSON() failed [request_type]"); + goto end; + } + request_typeVariable = OpenAPI_request_type_FromString(request_type->valuestring); } cJSON *eps_bearer_id = cJSON_GetObjectItemCaseSensitive(pdu_session_create_dataJSON, "epsBearerId"); @@ -1063,9 +1046,13 @@ OpenAPI_pdu_session_create_data_t *OpenAPI_pdu_session_create_data_parseFromJSON cJSON *sel_mode = cJSON_GetObjectItemCaseSensitive(pdu_session_create_dataJSON, "selMode"); - OpenAPI_dnn_selection_mode_t *sel_mode_local_nonprim = NULL; + OpenAPI_dnn_selection_mode_e sel_modeVariable; if (sel_mode) { - sel_mode_local_nonprim = OpenAPI_dnn_selection_mode_parseFromJSON(sel_mode); + if (!cJSON_IsString(sel_mode)) { + ogs_error("OpenAPI_pdu_session_create_data_parseFromJSON() failed [sel_mode]"); + goto end; + } + sel_modeVariable = OpenAPI_dnn_selection_mode_FromString(sel_mode->valuestring); } cJSON *always_on_requested = cJSON_GetObjectItemCaseSensitive(pdu_session_create_dataJSON, "alwaysOnRequested"); @@ -1097,9 +1084,13 @@ OpenAPI_pdu_session_create_data_t *OpenAPI_pdu_session_create_data_parseFromJSON cJSON *eps_interworking_ind = cJSON_GetObjectItemCaseSensitive(pdu_session_create_dataJSON, "epsInterworkingInd"); - OpenAPI_eps_interworking_indication_t *eps_interworking_ind_local_nonprim = NULL; + OpenAPI_eps_interworking_indication_e eps_interworking_indVariable; if (eps_interworking_ind) { - eps_interworking_ind_local_nonprim = OpenAPI_eps_interworking_indication_parseFromJSON(eps_interworking_ind); + if (!cJSON_IsString(eps_interworking_ind)) { + ogs_error("OpenAPI_pdu_session_create_data_parseFromJSON() failed [eps_interworking_ind]"); + goto end; + } + eps_interworking_indVariable = OpenAPI_eps_interworking_indication_FromString(eps_interworking_ind->valuestring); } cJSON *v_smf_service_instance_id = cJSON_GetObjectItemCaseSensitive(pdu_session_create_dataJSON, "vSmfServiceInstanceId"); @@ -1307,7 +1298,7 @@ OpenAPI_pdu_session_create_data_t *OpenAPI_pdu_session_create_data_parseFromJSON vsmf_id ? ogs_strdup(vsmf_id->valuestring) : NULL, ismf_id ? ogs_strdup(ismf_id->valuestring) : NULL, serving_network_local_nonprim, - request_type ? request_type_local_nonprim : NULL, + request_type ? request_typeVariable : 0, eps_bearer_id ? eps_bearer_idList : NULL, pgw_s8c_fteid ? pgw_s8c_fteid->valueint : 0, vsmf_pdu_session_uri ? ogs_strdup(vsmf_pdu_session_uri->valuestring) : NULL, @@ -1331,11 +1322,11 @@ OpenAPI_pdu_session_create_data_t *OpenAPI_pdu_session_create_data_parseFromJSON pcf_group_id ? ogs_strdup(pcf_group_id->valuestring) : NULL, pcf_set_id ? ogs_strdup(pcf_set_id->valuestring) : NULL, ho_preparation_indication ? ho_preparation_indication->valueint : 0, - sel_mode ? sel_mode_local_nonprim : NULL, + sel_mode ? sel_modeVariable : 0, always_on_requested ? always_on_requested->valueint : 0, udm_group_id ? ogs_strdup(udm_group_id->valuestring) : NULL, routing_indicator ? ogs_strdup(routing_indicator->valuestring) : NULL, - eps_interworking_ind ? eps_interworking_ind_local_nonprim : NULL, + eps_interworking_ind ? eps_interworking_indVariable : 0, v_smf_service_instance_id ? ogs_strdup(v_smf_service_instance_id->valuestring) : NULL, i_smf_service_instance_id ? ogs_strdup(i_smf_service_instance_id->valuestring) : NULL, recovery_time ? ogs_strdup(recovery_time->valuestring) : NULL, diff --git a/lib/sbi/openapi/model/pdu_session_create_data.h b/lib/sbi/openapi/model/pdu_session_create_data.h index de1dd93b9..e64baa708 100644 --- a/lib/sbi/openapi/model/pdu_session_create_data.h +++ b/lib/sbi/openapi/model/pdu_session_create_data.h @@ -44,7 +44,7 @@ typedef struct OpenAPI_pdu_session_create_data_s { char *vsmf_id; char *ismf_id; struct OpenAPI_plmn_id_nid_s *serving_network; - struct OpenAPI_request_type_s *request_type; + OpenAPI_request_type_e request_type; OpenAPI_list_t *eps_bearer_id; char pgw_s8c_fteid; char *vsmf_pdu_session_uri; @@ -68,11 +68,11 @@ typedef struct OpenAPI_pdu_session_create_data_s { char *pcf_group_id; char *pcf_set_id; int ho_preparation_indication; - struct OpenAPI_dnn_selection_mode_s *sel_mode; + OpenAPI_dnn_selection_mode_e sel_mode; int always_on_requested; char *udm_group_id; char *routing_indicator; - struct OpenAPI_eps_interworking_indication_s *eps_interworking_ind; + OpenAPI_eps_interworking_indication_e eps_interworking_ind; char *v_smf_service_instance_id; char *i_smf_service_instance_id; char *recovery_time; @@ -105,7 +105,7 @@ OpenAPI_pdu_session_create_data_t *OpenAPI_pdu_session_create_data_create( char *vsmf_id, char *ismf_id, OpenAPI_plmn_id_nid_t *serving_network, - OpenAPI_request_type_t *request_type, + OpenAPI_request_type_e request_type, OpenAPI_list_t *eps_bearer_id, char pgw_s8c_fteid, char *vsmf_pdu_session_uri, @@ -129,11 +129,11 @@ OpenAPI_pdu_session_create_data_t *OpenAPI_pdu_session_create_data_create( char *pcf_group_id, char *pcf_set_id, int ho_preparation_indication, - OpenAPI_dnn_selection_mode_t *sel_mode, + OpenAPI_dnn_selection_mode_e sel_mode, int always_on_requested, char *udm_group_id, char *routing_indicator, - OpenAPI_eps_interworking_indication_t *eps_interworking_ind, + OpenAPI_eps_interworking_indication_e eps_interworking_ind, char *v_smf_service_instance_id, char *i_smf_service_instance_id, char *recovery_time, diff --git a/lib/sbi/openapi/model/pdu_session_created_data.c b/lib/sbi/openapi/model/pdu_session_created_data.c index 69738ce09..44f3cba49 100644 --- a/lib/sbi/openapi/model/pdu_session_created_data.c +++ b/lib/sbi/openapi/model/pdu_session_created_data.c @@ -23,7 +23,7 @@ OpenAPI_pdu_session_created_data_t *OpenAPI_pdu_session_created_data_create( OpenAPI_eps_pdn_cnx_info_t *eps_pdn_cnx_info, OpenAPI_list_t *eps_bearer_info, char *supported_features, - OpenAPI_max_integrity_protected_data_rate_t *max_integrity_protected_data_rate, + OpenAPI_max_integrity_protected_data_rate_e max_integrity_protected_data_rate, int always_on_granted, char *gpsi, OpenAPI_up_security_t *up_security, @@ -104,7 +104,6 @@ void OpenAPI_pdu_session_created_data_free(OpenAPI_pdu_session_created_data_t *p } OpenAPI_list_free(pdu_session_created_data->eps_bearer_info); ogs_free(pdu_session_created_data->supported_features); - OpenAPI_max_integrity_protected_data_rate_free(pdu_session_created_data->max_integrity_protected_data_rate); ogs_free(pdu_session_created_data->gpsi); OpenAPI_up_security_free(pdu_session_created_data->up_security); OpenAPI_roaming_charging_profile_free(pdu_session_created_data->roaming_charging_profile); @@ -328,13 +327,7 @@ cJSON *OpenAPI_pdu_session_created_data_convertToJSON(OpenAPI_pdu_session_create } if (pdu_session_created_data->max_integrity_protected_data_rate) { - cJSON *max_integrity_protected_data_rate_local_JSON = OpenAPI_max_integrity_protected_data_rate_convertToJSON(pdu_session_created_data->max_integrity_protected_data_rate); - if (max_integrity_protected_data_rate_local_JSON == NULL) { - ogs_error("OpenAPI_pdu_session_created_data_convertToJSON() failed [max_integrity_protected_data_rate]"); - goto end; - } - cJSON_AddItemToObject(item, "maxIntegrityProtectedDataRate", max_integrity_protected_data_rate_local_JSON); - if (item->child == NULL) { + if (cJSON_AddStringToObject(item, "maxIntegrityProtectedDataRate", OpenAPI_max_integrity_protected_data_rate_ToString(pdu_session_created_data->max_integrity_protected_data_rate)) == NULL) { ogs_error("OpenAPI_pdu_session_created_data_convertToJSON() failed [max_integrity_protected_data_rate]"); goto end; } @@ -638,9 +631,13 @@ OpenAPI_pdu_session_created_data_t *OpenAPI_pdu_session_created_data_parseFromJS cJSON *max_integrity_protected_data_rate = cJSON_GetObjectItemCaseSensitive(pdu_session_created_dataJSON, "maxIntegrityProtectedDataRate"); - OpenAPI_max_integrity_protected_data_rate_t *max_integrity_protected_data_rate_local_nonprim = NULL; + OpenAPI_max_integrity_protected_data_rate_e max_integrity_protected_data_rateVariable; if (max_integrity_protected_data_rate) { - max_integrity_protected_data_rate_local_nonprim = OpenAPI_max_integrity_protected_data_rate_parseFromJSON(max_integrity_protected_data_rate); + if (!cJSON_IsString(max_integrity_protected_data_rate)) { + ogs_error("OpenAPI_pdu_session_created_data_parseFromJSON() failed [max_integrity_protected_data_rate]"); + goto end; + } + max_integrity_protected_data_rateVariable = OpenAPI_max_integrity_protected_data_rate_FromString(max_integrity_protected_data_rate->valuestring); } cJSON *always_on_granted = cJSON_GetObjectItemCaseSensitive(pdu_session_created_dataJSON, "alwaysOnGranted"); @@ -777,7 +774,7 @@ OpenAPI_pdu_session_created_data_t *OpenAPI_pdu_session_created_data_parseFromJS eps_pdn_cnx_info ? eps_pdn_cnx_info_local_nonprim : NULL, eps_bearer_info ? eps_bearer_infoList : NULL, supported_features ? ogs_strdup(supported_features->valuestring) : NULL, - max_integrity_protected_data_rate ? max_integrity_protected_data_rate_local_nonprim : NULL, + max_integrity_protected_data_rate ? max_integrity_protected_data_rateVariable : 0, always_on_granted ? always_on_granted->valueint : 0, gpsi ? ogs_strdup(gpsi->valuestring) : NULL, up_security ? up_security_local_nonprim : NULL, diff --git a/lib/sbi/openapi/model/pdu_session_created_data.h b/lib/sbi/openapi/model/pdu_session_created_data.h index 70aaa5965..9dd557a25 100644 --- a/lib/sbi/openapi/model/pdu_session_created_data.h +++ b/lib/sbi/openapi/model/pdu_session_created_data.h @@ -48,7 +48,7 @@ typedef struct OpenAPI_pdu_session_created_data_s { struct OpenAPI_eps_pdn_cnx_info_s *eps_pdn_cnx_info; OpenAPI_list_t *eps_bearer_info; char *supported_features; - struct OpenAPI_max_integrity_protected_data_rate_s *max_integrity_protected_data_rate; + OpenAPI_max_integrity_protected_data_rate_e max_integrity_protected_data_rate; int always_on_granted; char *gpsi; struct OpenAPI_up_security_s *up_security; @@ -82,7 +82,7 @@ OpenAPI_pdu_session_created_data_t *OpenAPI_pdu_session_created_data_create( OpenAPI_eps_pdn_cnx_info_t *eps_pdn_cnx_info, OpenAPI_list_t *eps_bearer_info, char *supported_features, - OpenAPI_max_integrity_protected_data_rate_t *max_integrity_protected_data_rate, + OpenAPI_max_integrity_protected_data_rate_e max_integrity_protected_data_rate, int always_on_granted, char *gpsi, OpenAPI_up_security_t *up_security, diff --git a/lib/sbi/openapi/model/pdu_session_notify_item.c b/lib/sbi/openapi/model/pdu_session_notify_item.c index 0b91691e6..651bc3d32 100644 --- a/lib/sbi/openapi/model/pdu_session_notify_item.c +++ b/lib/sbi/openapi/model/pdu_session_notify_item.c @@ -5,7 +5,7 @@ #include "pdu_session_notify_item.h" OpenAPI_pdu_session_notify_item_t *OpenAPI_pdu_session_notify_item_create( - OpenAPI_notification_cause_t *notification_cause + OpenAPI_notification_cause_e notification_cause ) { OpenAPI_pdu_session_notify_item_t *pdu_session_notify_item_local_var = OpenAPI_malloc(sizeof(OpenAPI_pdu_session_notify_item_t)); @@ -23,7 +23,6 @@ void OpenAPI_pdu_session_notify_item_free(OpenAPI_pdu_session_notify_item_t *pdu return; } OpenAPI_lnode_t *node; - OpenAPI_notification_cause_free(pdu_session_notify_item->notification_cause); ogs_free(pdu_session_notify_item); } @@ -41,13 +40,7 @@ cJSON *OpenAPI_pdu_session_notify_item_convertToJSON(OpenAPI_pdu_session_notify_ ogs_error("OpenAPI_pdu_session_notify_item_convertToJSON() failed [notification_cause]"); goto end; } - cJSON *notification_cause_local_JSON = OpenAPI_notification_cause_convertToJSON(pdu_session_notify_item->notification_cause); - if (notification_cause_local_JSON == NULL) { - ogs_error("OpenAPI_pdu_session_notify_item_convertToJSON() failed [notification_cause]"); - goto end; - } - cJSON_AddItemToObject(item, "notificationCause", notification_cause_local_JSON); - if (item->child == NULL) { + if (cJSON_AddStringToObject(item, "notificationCause", OpenAPI_notification_cause_ToString(pdu_session_notify_item->notification_cause)) == NULL) { ogs_error("OpenAPI_pdu_session_notify_item_convertToJSON() failed [notification_cause]"); goto end; } @@ -65,12 +58,16 @@ OpenAPI_pdu_session_notify_item_t *OpenAPI_pdu_session_notify_item_parseFromJSON goto end; } - OpenAPI_notification_cause_t *notification_cause_local_nonprim = NULL; + OpenAPI_notification_cause_e notification_causeVariable; - notification_cause_local_nonprim = OpenAPI_notification_cause_parseFromJSON(notification_cause); + if (!cJSON_IsString(notification_cause)) { + ogs_error("OpenAPI_pdu_session_notify_item_parseFromJSON() failed [notification_cause]"); + goto end; + } + notification_causeVariable = OpenAPI_notification_cause_FromString(notification_cause->valuestring); pdu_session_notify_item_local_var = OpenAPI_pdu_session_notify_item_create ( - notification_cause_local_nonprim + notification_causeVariable ); return pdu_session_notify_item_local_var; diff --git a/lib/sbi/openapi/model/pdu_session_notify_item.h b/lib/sbi/openapi/model/pdu_session_notify_item.h index 01dfcd0ee..3cb07a5f1 100644 --- a/lib/sbi/openapi/model/pdu_session_notify_item.h +++ b/lib/sbi/openapi/model/pdu_session_notify_item.h @@ -20,11 +20,11 @@ extern "C" { typedef struct OpenAPI_pdu_session_notify_item_s OpenAPI_pdu_session_notify_item_t; typedef struct OpenAPI_pdu_session_notify_item_s { - struct OpenAPI_notification_cause_s *notification_cause; + OpenAPI_notification_cause_e notification_cause; } OpenAPI_pdu_session_notify_item_t; OpenAPI_pdu_session_notify_item_t *OpenAPI_pdu_session_notify_item_create( - OpenAPI_notification_cause_t *notification_cause + OpenAPI_notification_cause_e notification_cause ); void OpenAPI_pdu_session_notify_item_free(OpenAPI_pdu_session_notify_item_t *pdu_session_notify_item); OpenAPI_pdu_session_notify_item_t *OpenAPI_pdu_session_notify_item_parseFromJSON(cJSON *pdu_session_notify_itemJSON); diff --git a/lib/sbi/openapi/model/psa_indication.c b/lib/sbi/openapi/model/psa_indication.c index d59a6e400..58e2cad96 100644 --- a/lib/sbi/openapi/model/psa_indication.c +++ b/lib/sbi/openapi/model/psa_indication.c @@ -4,82 +4,27 @@ #include #include "psa_indication.h" -OpenAPI_psa_indication_t *OpenAPI_psa_indication_create( - ) +char* OpenAPI_psa_indication_ToString(OpenAPI_psa_indication_e psa_indication) { - OpenAPI_psa_indication_t *psa_indication_local_var = OpenAPI_malloc(sizeof(OpenAPI_psa_indication_t)); - if (!psa_indication_local_var) { - return NULL; - } - - return psa_indication_local_var; + const char *psa_indicationArray[] = { "NULL", "PSA_INSERTED", "PSA_REMOVED" }; + size_t sizeofArray = sizeof(psa_indicationArray) / sizeof(psa_indicationArray[0]); + if (psa_indication < sizeofArray) + return (char *)psa_indicationArray[psa_indication]; + else + return (char *)"Unknown"; } -void OpenAPI_psa_indication_free(OpenAPI_psa_indication_t *psa_indication) +OpenAPI_psa_indication_e OpenAPI_psa_indication_FromString(char* psa_indication) { - if (NULL == psa_indication) { - return; + int stringToReturn = 0; + const char *psa_indicationArray[] = { "NULL", "PSA_INSERTED", "PSA_REMOVED" }; + size_t sizeofArray = sizeof(psa_indicationArray) / sizeof(psa_indicationArray[0]); + while (stringToReturn < sizeofArray) { + if (strcmp(psa_indication, psa_indicationArray[stringToReturn]) == 0) { + return stringToReturn; + } + stringToReturn++; } - OpenAPI_lnode_t *node; - ogs_free(psa_indication); -} - -cJSON *OpenAPI_psa_indication_convertToJSON(OpenAPI_psa_indication_t *psa_indication) -{ - cJSON *item = NULL; - - if (psa_indication == NULL) { - ogs_error("OpenAPI_psa_indication_convertToJSON() failed [PsaIndication]"); - return NULL; - } - - item = cJSON_CreateObject(); -end: - return item; -} - -OpenAPI_psa_indication_t *OpenAPI_psa_indication_parseFromJSON(cJSON *psa_indicationJSON) -{ - OpenAPI_psa_indication_t *psa_indication_local_var = NULL; - psa_indication_local_var = OpenAPI_psa_indication_create ( - ); - - return psa_indication_local_var; -end: - return NULL; -} - -OpenAPI_psa_indication_t *OpenAPI_psa_indication_copy(OpenAPI_psa_indication_t *dst, OpenAPI_psa_indication_t *src) -{ - cJSON *item = NULL; - char *content = NULL; - - ogs_assert(src); - item = OpenAPI_psa_indication_convertToJSON(src); - if (!item) { - ogs_error("OpenAPI_psa_indication_convertToJSON() failed"); - return NULL; - } - - content = cJSON_Print(item); - cJSON_Delete(item); - - if (!content) { - ogs_error("cJSON_Print() failed"); - return NULL; - } - - item = cJSON_Parse(content); - ogs_free(content); - if (!item) { - ogs_error("cJSON_Parse() failed"); - return NULL; - } - - OpenAPI_psa_indication_free(dst); - dst = OpenAPI_psa_indication_parseFromJSON(item); - cJSON_Delete(item); - - return dst; + return 0; } diff --git a/lib/sbi/openapi/model/psa_indication.h b/lib/sbi/openapi/model/psa_indication.h index ce98f691a..96b9774cc 100644 --- a/lib/sbi/openapi/model/psa_indication.h +++ b/lib/sbi/openapi/model/psa_indication.h @@ -1,7 +1,7 @@ /* * psa_indication.h * - * Possible values are - PSA_INSERTED - PSA_REMOVED + * */ #ifndef _OpenAPI_psa_indication_H_ @@ -17,16 +17,11 @@ extern "C" { #endif -typedef struct OpenAPI_psa_indication_s OpenAPI_psa_indication_t; -typedef struct OpenAPI_psa_indication_s { -} OpenAPI_psa_indication_t; +typedef enum { OpenAPI_psa_indication_NULL = 0, OpenAPI_psa_indication_PSA_INSERTED, OpenAPI_psa_indication_PSA_REMOVED } OpenAPI_psa_indication_e; -OpenAPI_psa_indication_t *OpenAPI_psa_indication_create( - ); -void OpenAPI_psa_indication_free(OpenAPI_psa_indication_t *psa_indication); -OpenAPI_psa_indication_t *OpenAPI_psa_indication_parseFromJSON(cJSON *psa_indicationJSON); -cJSON *OpenAPI_psa_indication_convertToJSON(OpenAPI_psa_indication_t *psa_indication); -OpenAPI_psa_indication_t *OpenAPI_psa_indication_copy(OpenAPI_psa_indication_t *dst, OpenAPI_psa_indication_t *src); +char* OpenAPI_psa_indication_ToString(OpenAPI_psa_indication_e psa_indication); + +OpenAPI_psa_indication_e OpenAPI_psa_indication_FromString(char* psa_indication); #ifdef __cplusplus } diff --git a/lib/sbi/openapi/model/psa_information.c b/lib/sbi/openapi/model/psa_information.c index bd15ac8a6..5e1b74e5a 100644 --- a/lib/sbi/openapi/model/psa_information.c +++ b/lib/sbi/openapi/model/psa_information.c @@ -5,7 +5,7 @@ #include "psa_information.h" OpenAPI_psa_information_t *OpenAPI_psa_information_create( - OpenAPI_psa_indication_t *psa_ind, + OpenAPI_psa_indication_e psa_ind, OpenAPI_list_t *dnai_list, char *ue_ipv6_prefix, char *psa_upf_id @@ -29,7 +29,6 @@ void OpenAPI_psa_information_free(OpenAPI_psa_information_t *psa_information) return; } OpenAPI_lnode_t *node; - OpenAPI_psa_indication_free(psa_information->psa_ind); OpenAPI_list_for_each(psa_information->dnai_list, node) { ogs_free(node->data); } @@ -50,13 +49,7 @@ cJSON *OpenAPI_psa_information_convertToJSON(OpenAPI_psa_information_t *psa_info item = cJSON_CreateObject(); if (psa_information->psa_ind) { - cJSON *psa_ind_local_JSON = OpenAPI_psa_indication_convertToJSON(psa_information->psa_ind); - if (psa_ind_local_JSON == NULL) { - ogs_error("OpenAPI_psa_information_convertToJSON() failed [psa_ind]"); - goto end; - } - cJSON_AddItemToObject(item, "psaInd", psa_ind_local_JSON); - if (item->child == NULL) { + if (cJSON_AddStringToObject(item, "psaInd", OpenAPI_psa_indication_ToString(psa_information->psa_ind)) == NULL) { ogs_error("OpenAPI_psa_information_convertToJSON() failed [psa_ind]"); goto end; } @@ -101,9 +94,13 @@ OpenAPI_psa_information_t *OpenAPI_psa_information_parseFromJSON(cJSON *psa_info OpenAPI_psa_information_t *psa_information_local_var = NULL; cJSON *psa_ind = cJSON_GetObjectItemCaseSensitive(psa_informationJSON, "psaInd"); - OpenAPI_psa_indication_t *psa_ind_local_nonprim = NULL; + OpenAPI_psa_indication_e psa_indVariable; if (psa_ind) { - psa_ind_local_nonprim = OpenAPI_psa_indication_parseFromJSON(psa_ind); + if (!cJSON_IsString(psa_ind)) { + ogs_error("OpenAPI_psa_information_parseFromJSON() failed [psa_ind]"); + goto end; + } + psa_indVariable = OpenAPI_psa_indication_FromString(psa_ind->valuestring); } cJSON *dnai_list = cJSON_GetObjectItemCaseSensitive(psa_informationJSON, "dnaiList"); @@ -145,7 +142,7 @@ OpenAPI_psa_information_t *OpenAPI_psa_information_parseFromJSON(cJSON *psa_info } psa_information_local_var = OpenAPI_psa_information_create ( - psa_ind ? psa_ind_local_nonprim : NULL, + psa_ind ? psa_indVariable : 0, dnai_list ? dnai_listList : NULL, ue_ipv6_prefix ? ogs_strdup(ue_ipv6_prefix->valuestring) : NULL, psa_upf_id ? ogs_strdup(psa_upf_id->valuestring) : NULL diff --git a/lib/sbi/openapi/model/psa_information.h b/lib/sbi/openapi/model/psa_information.h index 7ef31ce08..0c3b59151 100644 --- a/lib/sbi/openapi/model/psa_information.h +++ b/lib/sbi/openapi/model/psa_information.h @@ -20,14 +20,14 @@ extern "C" { typedef struct OpenAPI_psa_information_s OpenAPI_psa_information_t; typedef struct OpenAPI_psa_information_s { - struct OpenAPI_psa_indication_s *psa_ind; + OpenAPI_psa_indication_e psa_ind; OpenAPI_list_t *dnai_list; char *ue_ipv6_prefix; char *psa_upf_id; } OpenAPI_psa_information_t; OpenAPI_psa_information_t *OpenAPI_psa_information_create( - OpenAPI_psa_indication_t *psa_ind, + OpenAPI_psa_indication_e psa_ind, OpenAPI_list_t *dnai_list, char *ue_ipv6_prefix, char *psa_upf_id diff --git a/lib/sbi/openapi/model/qos_flow_access_type.c b/lib/sbi/openapi/model/qos_flow_access_type.c index c5b168bff..6de2b754c 100644 --- a/lib/sbi/openapi/model/qos_flow_access_type.c +++ b/lib/sbi/openapi/model/qos_flow_access_type.c @@ -4,82 +4,27 @@ #include #include "qos_flow_access_type.h" -OpenAPI_qos_flow_access_type_t *OpenAPI_qos_flow_access_type_create( - ) +char* OpenAPI_qos_flow_access_type_ToString(OpenAPI_qos_flow_access_type_e qos_flow_access_type) { - OpenAPI_qos_flow_access_type_t *qos_flow_access_type_local_var = OpenAPI_malloc(sizeof(OpenAPI_qos_flow_access_type_t)); - if (!qos_flow_access_type_local_var) { - return NULL; - } - - return qos_flow_access_type_local_var; + const char *qos_flow_access_typeArray[] = { "NULL", "_3GPP", "NON_3GPP", "_3GPP_AND_NON_3GPP" }; + size_t sizeofArray = sizeof(qos_flow_access_typeArray) / sizeof(qos_flow_access_typeArray[0]); + if (qos_flow_access_type < sizeofArray) + return (char *)qos_flow_access_typeArray[qos_flow_access_type]; + else + return (char *)"Unknown"; } -void OpenAPI_qos_flow_access_type_free(OpenAPI_qos_flow_access_type_t *qos_flow_access_type) +OpenAPI_qos_flow_access_type_e OpenAPI_qos_flow_access_type_FromString(char* qos_flow_access_type) { - if (NULL == qos_flow_access_type) { - return; + int stringToReturn = 0; + const char *qos_flow_access_typeArray[] = { "NULL", "_3GPP", "NON_3GPP", "_3GPP_AND_NON_3GPP" }; + size_t sizeofArray = sizeof(qos_flow_access_typeArray) / sizeof(qos_flow_access_typeArray[0]); + while (stringToReturn < sizeofArray) { + if (strcmp(qos_flow_access_type, qos_flow_access_typeArray[stringToReturn]) == 0) { + return stringToReturn; + } + stringToReturn++; } - OpenAPI_lnode_t *node; - ogs_free(qos_flow_access_type); -} - -cJSON *OpenAPI_qos_flow_access_type_convertToJSON(OpenAPI_qos_flow_access_type_t *qos_flow_access_type) -{ - cJSON *item = NULL; - - if (qos_flow_access_type == NULL) { - ogs_error("OpenAPI_qos_flow_access_type_convertToJSON() failed [QosFlowAccessType]"); - return NULL; - } - - item = cJSON_CreateObject(); -end: - return item; -} - -OpenAPI_qos_flow_access_type_t *OpenAPI_qos_flow_access_type_parseFromJSON(cJSON *qos_flow_access_typeJSON) -{ - OpenAPI_qos_flow_access_type_t *qos_flow_access_type_local_var = NULL; - qos_flow_access_type_local_var = OpenAPI_qos_flow_access_type_create ( - ); - - return qos_flow_access_type_local_var; -end: - return NULL; -} - -OpenAPI_qos_flow_access_type_t *OpenAPI_qos_flow_access_type_copy(OpenAPI_qos_flow_access_type_t *dst, OpenAPI_qos_flow_access_type_t *src) -{ - cJSON *item = NULL; - char *content = NULL; - - ogs_assert(src); - item = OpenAPI_qos_flow_access_type_convertToJSON(src); - if (!item) { - ogs_error("OpenAPI_qos_flow_access_type_convertToJSON() failed"); - return NULL; - } - - content = cJSON_Print(item); - cJSON_Delete(item); - - if (!content) { - ogs_error("cJSON_Print() failed"); - return NULL; - } - - item = cJSON_Parse(content); - ogs_free(content); - if (!item) { - ogs_error("cJSON_Parse() failed"); - return NULL; - } - - OpenAPI_qos_flow_access_type_free(dst); - dst = OpenAPI_qos_flow_access_type_parseFromJSON(item); - cJSON_Delete(item); - - return dst; + return 0; } diff --git a/lib/sbi/openapi/model/qos_flow_access_type.h b/lib/sbi/openapi/model/qos_flow_access_type.h index b6f7d1bd7..846627172 100644 --- a/lib/sbi/openapi/model/qos_flow_access_type.h +++ b/lib/sbi/openapi/model/qos_flow_access_type.h @@ -1,7 +1,7 @@ /* * qos_flow_access_type.h * - * Possible values are - 3GPP - NON_3GPP - 3GPP_AND_NON_3GPP + * */ #ifndef _OpenAPI_qos_flow_access_type_H_ @@ -17,16 +17,11 @@ extern "C" { #endif -typedef struct OpenAPI_qos_flow_access_type_s OpenAPI_qos_flow_access_type_t; -typedef struct OpenAPI_qos_flow_access_type_s { -} OpenAPI_qos_flow_access_type_t; +typedef enum { OpenAPI_qos_flow_access_type_NULL = 0, OpenAPI_qos_flow_access_type__3GPP, OpenAPI_qos_flow_access_type_NON_3GPP, OpenAPI_qos_flow_access_type__3GPP_AND_NON_3GPP } OpenAPI_qos_flow_access_type_e; -OpenAPI_qos_flow_access_type_t *OpenAPI_qos_flow_access_type_create( - ); -void OpenAPI_qos_flow_access_type_free(OpenAPI_qos_flow_access_type_t *qos_flow_access_type); -OpenAPI_qos_flow_access_type_t *OpenAPI_qos_flow_access_type_parseFromJSON(cJSON *qos_flow_access_typeJSON); -cJSON *OpenAPI_qos_flow_access_type_convertToJSON(OpenAPI_qos_flow_access_type_t *qos_flow_access_type); -OpenAPI_qos_flow_access_type_t *OpenAPI_qos_flow_access_type_copy(OpenAPI_qos_flow_access_type_t *dst, OpenAPI_qos_flow_access_type_t *src); +char* OpenAPI_qos_flow_access_type_ToString(OpenAPI_qos_flow_access_type_e qos_flow_access_type); + +OpenAPI_qos_flow_access_type_e OpenAPI_qos_flow_access_type_FromString(char* qos_flow_access_type); #ifdef __cplusplus } diff --git a/lib/sbi/openapi/model/qos_flow_add_modify_request_item.c b/lib/sbi/openapi/model/qos_flow_add_modify_request_item.c index 01d17d2ae..947a86125 100644 --- a/lib/sbi/openapi/model/qos_flow_add_modify_request_item.c +++ b/lib/sbi/openapi/model/qos_flow_add_modify_request_item.c @@ -10,7 +10,7 @@ OpenAPI_qos_flow_add_modify_request_item_t *OpenAPI_qos_flow_add_modify_request_ char qos_rules, char qos_flow_description, OpenAPI_qos_flow_profile_t *qos_flow_profile, - OpenAPI_qos_flow_access_type_t *associated_an_type + OpenAPI_qos_flow_access_type_e associated_an_type ) { OpenAPI_qos_flow_add_modify_request_item_t *qos_flow_add_modify_request_item_local_var = OpenAPI_malloc(sizeof(OpenAPI_qos_flow_add_modify_request_item_t)); @@ -34,7 +34,6 @@ void OpenAPI_qos_flow_add_modify_request_item_free(OpenAPI_qos_flow_add_modify_r } OpenAPI_lnode_t *node; OpenAPI_qos_flow_profile_free(qos_flow_add_modify_request_item->qos_flow_profile); - OpenAPI_qos_flow_access_type_free(qos_flow_add_modify_request_item->associated_an_type); ogs_free(qos_flow_add_modify_request_item); } @@ -92,13 +91,7 @@ cJSON *OpenAPI_qos_flow_add_modify_request_item_convertToJSON(OpenAPI_qos_flow_a } if (qos_flow_add_modify_request_item->associated_an_type) { - cJSON *associated_an_type_local_JSON = OpenAPI_qos_flow_access_type_convertToJSON(qos_flow_add_modify_request_item->associated_an_type); - if (associated_an_type_local_JSON == NULL) { - ogs_error("OpenAPI_qos_flow_add_modify_request_item_convertToJSON() failed [associated_an_type]"); - goto end; - } - cJSON_AddItemToObject(item, "associatedAnType", associated_an_type_local_JSON); - if (item->child == NULL) { + if (cJSON_AddStringToObject(item, "associatedAnType", OpenAPI_qos_flow_access_type_ToString(qos_flow_add_modify_request_item->associated_an_type)) == NULL) { ogs_error("OpenAPI_qos_flow_add_modify_request_item_convertToJSON() failed [associated_an_type]"); goto end; } @@ -159,9 +152,13 @@ OpenAPI_qos_flow_add_modify_request_item_t *OpenAPI_qos_flow_add_modify_request_ cJSON *associated_an_type = cJSON_GetObjectItemCaseSensitive(qos_flow_add_modify_request_itemJSON, "associatedAnType"); - OpenAPI_qos_flow_access_type_t *associated_an_type_local_nonprim = NULL; + OpenAPI_qos_flow_access_type_e associated_an_typeVariable; if (associated_an_type) { - associated_an_type_local_nonprim = OpenAPI_qos_flow_access_type_parseFromJSON(associated_an_type); + if (!cJSON_IsString(associated_an_type)) { + ogs_error("OpenAPI_qos_flow_add_modify_request_item_parseFromJSON() failed [associated_an_type]"); + goto end; + } + associated_an_typeVariable = OpenAPI_qos_flow_access_type_FromString(associated_an_type->valuestring); } qos_flow_add_modify_request_item_local_var = OpenAPI_qos_flow_add_modify_request_item_create ( @@ -170,7 +167,7 @@ OpenAPI_qos_flow_add_modify_request_item_t *OpenAPI_qos_flow_add_modify_request_ qos_rules ? qos_rules->valueint : 0, qos_flow_description ? qos_flow_description->valueint : 0, qos_flow_profile ? qos_flow_profile_local_nonprim : NULL, - associated_an_type ? associated_an_type_local_nonprim : NULL + associated_an_type ? associated_an_typeVariable : 0 ); return qos_flow_add_modify_request_item_local_var; diff --git a/lib/sbi/openapi/model/qos_flow_add_modify_request_item.h b/lib/sbi/openapi/model/qos_flow_add_modify_request_item.h index 472a13e3b..687586560 100644 --- a/lib/sbi/openapi/model/qos_flow_add_modify_request_item.h +++ b/lib/sbi/openapi/model/qos_flow_add_modify_request_item.h @@ -26,7 +26,7 @@ typedef struct OpenAPI_qos_flow_add_modify_request_item_s { char qos_rules; char qos_flow_description; struct OpenAPI_qos_flow_profile_s *qos_flow_profile; - struct OpenAPI_qos_flow_access_type_s *associated_an_type; + OpenAPI_qos_flow_access_type_e associated_an_type; } OpenAPI_qos_flow_add_modify_request_item_t; OpenAPI_qos_flow_add_modify_request_item_t *OpenAPI_qos_flow_add_modify_request_item_create( @@ -35,7 +35,7 @@ OpenAPI_qos_flow_add_modify_request_item_t *OpenAPI_qos_flow_add_modify_request_ char qos_rules, char qos_flow_description, OpenAPI_qos_flow_profile_t *qos_flow_profile, - OpenAPI_qos_flow_access_type_t *associated_an_type + OpenAPI_qos_flow_access_type_e associated_an_type ); void OpenAPI_qos_flow_add_modify_request_item_free(OpenAPI_qos_flow_add_modify_request_item_t *qos_flow_add_modify_request_item); OpenAPI_qos_flow_add_modify_request_item_t *OpenAPI_qos_flow_add_modify_request_item_parseFromJSON(cJSON *qos_flow_add_modify_request_itemJSON); diff --git a/lib/sbi/openapi/model/qos_flow_item.c b/lib/sbi/openapi/model/qos_flow_item.c index bea54fc68..3ed66eff1 100644 --- a/lib/sbi/openapi/model/qos_flow_item.c +++ b/lib/sbi/openapi/model/qos_flow_item.c @@ -6,7 +6,7 @@ OpenAPI_qos_flow_item_t *OpenAPI_qos_flow_item_create( int qfi, - OpenAPI_cause_t *cause + OpenAPI_cause_e cause ) { OpenAPI_qos_flow_item_t *qos_flow_item_local_var = OpenAPI_malloc(sizeof(OpenAPI_qos_flow_item_t)); @@ -25,7 +25,6 @@ void OpenAPI_qos_flow_item_free(OpenAPI_qos_flow_item_t *qos_flow_item) return; } OpenAPI_lnode_t *node; - OpenAPI_cause_free(qos_flow_item->cause); ogs_free(qos_flow_item); } @@ -49,13 +48,7 @@ cJSON *OpenAPI_qos_flow_item_convertToJSON(OpenAPI_qos_flow_item_t *qos_flow_ite } if (qos_flow_item->cause) { - cJSON *cause_local_JSON = OpenAPI_cause_convertToJSON(qos_flow_item->cause); - if (cause_local_JSON == NULL) { - ogs_error("OpenAPI_qos_flow_item_convertToJSON() failed [cause]"); - goto end; - } - cJSON_AddItemToObject(item, "cause", cause_local_JSON); - if (item->child == NULL) { + if (cJSON_AddStringToObject(item, "cause", OpenAPI_cause_ToString(qos_flow_item->cause)) == NULL) { ogs_error("OpenAPI_qos_flow_item_convertToJSON() failed [cause]"); goto end; } @@ -82,14 +75,18 @@ OpenAPI_qos_flow_item_t *OpenAPI_qos_flow_item_parseFromJSON(cJSON *qos_flow_ite cJSON *cause = cJSON_GetObjectItemCaseSensitive(qos_flow_itemJSON, "cause"); - OpenAPI_cause_t *cause_local_nonprim = NULL; + OpenAPI_cause_e causeVariable; if (cause) { - cause_local_nonprim = OpenAPI_cause_parseFromJSON(cause); + if (!cJSON_IsString(cause)) { + ogs_error("OpenAPI_qos_flow_item_parseFromJSON() failed [cause]"); + goto end; + } + causeVariable = OpenAPI_cause_FromString(cause->valuestring); } qos_flow_item_local_var = OpenAPI_qos_flow_item_create ( qfi->valuedouble, - cause ? cause_local_nonprim : NULL + cause ? causeVariable : 0 ); return qos_flow_item_local_var; diff --git a/lib/sbi/openapi/model/qos_flow_item.h b/lib/sbi/openapi/model/qos_flow_item.h index b0a7dcd2d..f07427ac7 100644 --- a/lib/sbi/openapi/model/qos_flow_item.h +++ b/lib/sbi/openapi/model/qos_flow_item.h @@ -21,12 +21,12 @@ extern "C" { typedef struct OpenAPI_qos_flow_item_s OpenAPI_qos_flow_item_t; typedef struct OpenAPI_qos_flow_item_s { int qfi; - struct OpenAPI_cause_s *cause; + OpenAPI_cause_e cause; } OpenAPI_qos_flow_item_t; OpenAPI_qos_flow_item_t *OpenAPI_qos_flow_item_create( int qfi, - OpenAPI_cause_t *cause + OpenAPI_cause_e cause ); void OpenAPI_qos_flow_item_free(OpenAPI_qos_flow_item_t *qos_flow_item); OpenAPI_qos_flow_item_t *OpenAPI_qos_flow_item_parseFromJSON(cJSON *qos_flow_itemJSON); diff --git a/lib/sbi/openapi/model/qos_flow_notify_item.c b/lib/sbi/openapi/model/qos_flow_notify_item.c index b3f475fa0..c64f13e03 100644 --- a/lib/sbi/openapi/model/qos_flow_notify_item.c +++ b/lib/sbi/openapi/model/qos_flow_notify_item.c @@ -6,7 +6,7 @@ OpenAPI_qos_flow_notify_item_t *OpenAPI_qos_flow_notify_item_create( int qfi, - OpenAPI_notification_cause_t *notification_cause + OpenAPI_notification_cause_e notification_cause ) { OpenAPI_qos_flow_notify_item_t *qos_flow_notify_item_local_var = OpenAPI_malloc(sizeof(OpenAPI_qos_flow_notify_item_t)); @@ -25,7 +25,6 @@ void OpenAPI_qos_flow_notify_item_free(OpenAPI_qos_flow_notify_item_t *qos_flow_ return; } OpenAPI_lnode_t *node; - OpenAPI_notification_cause_free(qos_flow_notify_item->notification_cause); ogs_free(qos_flow_notify_item); } @@ -52,13 +51,7 @@ cJSON *OpenAPI_qos_flow_notify_item_convertToJSON(OpenAPI_qos_flow_notify_item_t ogs_error("OpenAPI_qos_flow_notify_item_convertToJSON() failed [notification_cause]"); goto end; } - cJSON *notification_cause_local_JSON = OpenAPI_notification_cause_convertToJSON(qos_flow_notify_item->notification_cause); - if (notification_cause_local_JSON == NULL) { - ogs_error("OpenAPI_qos_flow_notify_item_convertToJSON() failed [notification_cause]"); - goto end; - } - cJSON_AddItemToObject(item, "notificationCause", notification_cause_local_JSON); - if (item->child == NULL) { + if (cJSON_AddStringToObject(item, "notificationCause", OpenAPI_notification_cause_ToString(qos_flow_notify_item->notification_cause)) == NULL) { ogs_error("OpenAPI_qos_flow_notify_item_convertToJSON() failed [notification_cause]"); goto end; } @@ -88,13 +81,17 @@ OpenAPI_qos_flow_notify_item_t *OpenAPI_qos_flow_notify_item_parseFromJSON(cJSON goto end; } - OpenAPI_notification_cause_t *notification_cause_local_nonprim = NULL; + OpenAPI_notification_cause_e notification_causeVariable; - notification_cause_local_nonprim = OpenAPI_notification_cause_parseFromJSON(notification_cause); + if (!cJSON_IsString(notification_cause)) { + ogs_error("OpenAPI_qos_flow_notify_item_parseFromJSON() failed [notification_cause]"); + goto end; + } + notification_causeVariable = OpenAPI_notification_cause_FromString(notification_cause->valuestring); qos_flow_notify_item_local_var = OpenAPI_qos_flow_notify_item_create ( qfi->valuedouble, - notification_cause_local_nonprim + notification_causeVariable ); return qos_flow_notify_item_local_var; diff --git a/lib/sbi/openapi/model/qos_flow_notify_item.h b/lib/sbi/openapi/model/qos_flow_notify_item.h index 817d46e6a..c08871560 100644 --- a/lib/sbi/openapi/model/qos_flow_notify_item.h +++ b/lib/sbi/openapi/model/qos_flow_notify_item.h @@ -21,12 +21,12 @@ extern "C" { typedef struct OpenAPI_qos_flow_notify_item_s OpenAPI_qos_flow_notify_item_t; typedef struct OpenAPI_qos_flow_notify_item_s { int qfi; - struct OpenAPI_notification_cause_s *notification_cause; + OpenAPI_notification_cause_e notification_cause; } OpenAPI_qos_flow_notify_item_t; OpenAPI_qos_flow_notify_item_t *OpenAPI_qos_flow_notify_item_create( int qfi, - OpenAPI_notification_cause_t *notification_cause + OpenAPI_notification_cause_e notification_cause ); void OpenAPI_qos_flow_notify_item_free(OpenAPI_qos_flow_notify_item_t *qos_flow_notify_item); OpenAPI_qos_flow_notify_item_t *OpenAPI_qos_flow_notify_item_parseFromJSON(cJSON *qos_flow_notify_itemJSON); diff --git a/lib/sbi/openapi/model/qos_flow_setup_item.c b/lib/sbi/openapi/model/qos_flow_setup_item.c index 8fd79f7a2..6b1d11ab4 100644 --- a/lib/sbi/openapi/model/qos_flow_setup_item.c +++ b/lib/sbi/openapi/model/qos_flow_setup_item.c @@ -10,7 +10,7 @@ OpenAPI_qos_flow_setup_item_t *OpenAPI_qos_flow_setup_item_create( int ebi, char qos_flow_description, OpenAPI_qos_flow_profile_t *qos_flow_profile, - OpenAPI_qos_flow_access_type_t *associated_an_type + OpenAPI_qos_flow_access_type_e associated_an_type ) { OpenAPI_qos_flow_setup_item_t *qos_flow_setup_item_local_var = OpenAPI_malloc(sizeof(OpenAPI_qos_flow_setup_item_t)); @@ -34,7 +34,6 @@ void OpenAPI_qos_flow_setup_item_free(OpenAPI_qos_flow_setup_item_t *qos_flow_se } OpenAPI_lnode_t *node; OpenAPI_qos_flow_profile_free(qos_flow_setup_item->qos_flow_profile); - OpenAPI_qos_flow_access_type_free(qos_flow_setup_item->associated_an_type); ogs_free(qos_flow_setup_item); } @@ -94,13 +93,7 @@ cJSON *OpenAPI_qos_flow_setup_item_convertToJSON(OpenAPI_qos_flow_setup_item_t * } if (qos_flow_setup_item->associated_an_type) { - cJSON *associated_an_type_local_JSON = OpenAPI_qos_flow_access_type_convertToJSON(qos_flow_setup_item->associated_an_type); - if (associated_an_type_local_JSON == NULL) { - ogs_error("OpenAPI_qos_flow_setup_item_convertToJSON() failed [associated_an_type]"); - goto end; - } - cJSON_AddItemToObject(item, "associatedAnType", associated_an_type_local_JSON); - if (item->child == NULL) { + if (cJSON_AddStringToObject(item, "associatedAnType", OpenAPI_qos_flow_access_type_ToString(qos_flow_setup_item->associated_an_type)) == NULL) { ogs_error("OpenAPI_qos_flow_setup_item_convertToJSON() failed [associated_an_type]"); goto end; } @@ -164,9 +157,13 @@ OpenAPI_qos_flow_setup_item_t *OpenAPI_qos_flow_setup_item_parseFromJSON(cJSON * cJSON *associated_an_type = cJSON_GetObjectItemCaseSensitive(qos_flow_setup_itemJSON, "associatedAnType"); - OpenAPI_qos_flow_access_type_t *associated_an_type_local_nonprim = NULL; + OpenAPI_qos_flow_access_type_e associated_an_typeVariable; if (associated_an_type) { - associated_an_type_local_nonprim = OpenAPI_qos_flow_access_type_parseFromJSON(associated_an_type); + if (!cJSON_IsString(associated_an_type)) { + ogs_error("OpenAPI_qos_flow_setup_item_parseFromJSON() failed [associated_an_type]"); + goto end; + } + associated_an_typeVariable = OpenAPI_qos_flow_access_type_FromString(associated_an_type->valuestring); } qos_flow_setup_item_local_var = OpenAPI_qos_flow_setup_item_create ( @@ -175,7 +172,7 @@ OpenAPI_qos_flow_setup_item_t *OpenAPI_qos_flow_setup_item_parseFromJSON(cJSON * ebi ? ebi->valuedouble : 0, qos_flow_description ? qos_flow_description->valueint : 0, qos_flow_profile ? qos_flow_profile_local_nonprim : NULL, - associated_an_type ? associated_an_type_local_nonprim : NULL + associated_an_type ? associated_an_typeVariable : 0 ); return qos_flow_setup_item_local_var; diff --git a/lib/sbi/openapi/model/qos_flow_setup_item.h b/lib/sbi/openapi/model/qos_flow_setup_item.h index 546b93105..806fac348 100644 --- a/lib/sbi/openapi/model/qos_flow_setup_item.h +++ b/lib/sbi/openapi/model/qos_flow_setup_item.h @@ -26,7 +26,7 @@ typedef struct OpenAPI_qos_flow_setup_item_s { int ebi; char qos_flow_description; struct OpenAPI_qos_flow_profile_s *qos_flow_profile; - struct OpenAPI_qos_flow_access_type_s *associated_an_type; + OpenAPI_qos_flow_access_type_e associated_an_type; } OpenAPI_qos_flow_setup_item_t; OpenAPI_qos_flow_setup_item_t *OpenAPI_qos_flow_setup_item_create( @@ -35,7 +35,7 @@ OpenAPI_qos_flow_setup_item_t *OpenAPI_qos_flow_setup_item_create( int ebi, char qos_flow_description, OpenAPI_qos_flow_profile_t *qos_flow_profile, - OpenAPI_qos_flow_access_type_t *associated_an_type + OpenAPI_qos_flow_access_type_e associated_an_type ); void OpenAPI_qos_flow_setup_item_free(OpenAPI_qos_flow_setup_item_t *qos_flow_setup_item); OpenAPI_qos_flow_setup_item_t *OpenAPI_qos_flow_setup_item_parseFromJSON(cJSON *qos_flow_setup_itemJSON); diff --git a/lib/sbi/openapi/model/release_data.c b/lib/sbi/openapi/model/release_data.c index 0b5d7520a..caad5ef8d 100644 --- a/lib/sbi/openapi/model/release_data.c +++ b/lib/sbi/openapi/model/release_data.c @@ -5,7 +5,7 @@ #include "release_data.h" OpenAPI_release_data_t *OpenAPI_release_data_create( - OpenAPI_cause_t *cause, + OpenAPI_cause_e cause, OpenAPI_ng_ap_cause_t *ng_ap_cause, int _5g_mm_cause_value, OpenAPI_user_location_t *ue_location, @@ -37,7 +37,6 @@ void OpenAPI_release_data_free(OpenAPI_release_data_t *release_data) return; } OpenAPI_lnode_t *node; - OpenAPI_cause_free(release_data->cause); OpenAPI_ng_ap_cause_free(release_data->ng_ap_cause); OpenAPI_user_location_free(release_data->ue_location); ogs_free(release_data->ue_time_zone); @@ -64,13 +63,7 @@ cJSON *OpenAPI_release_data_convertToJSON(OpenAPI_release_data_t *release_data) item = cJSON_CreateObject(); if (release_data->cause) { - cJSON *cause_local_JSON = OpenAPI_cause_convertToJSON(release_data->cause); - if (cause_local_JSON == NULL) { - ogs_error("OpenAPI_release_data_convertToJSON() failed [cause]"); - goto end; - } - cJSON_AddItemToObject(item, "cause", cause_local_JSON); - if (item->child == NULL) { + if (cJSON_AddStringToObject(item, "cause", OpenAPI_cause_ToString(release_data->cause)) == NULL) { ogs_error("OpenAPI_release_data_convertToJSON() failed [cause]"); goto end; } @@ -178,9 +171,13 @@ OpenAPI_release_data_t *OpenAPI_release_data_parseFromJSON(cJSON *release_dataJS OpenAPI_release_data_t *release_data_local_var = NULL; cJSON *cause = cJSON_GetObjectItemCaseSensitive(release_dataJSON, "cause"); - OpenAPI_cause_t *cause_local_nonprim = NULL; + OpenAPI_cause_e causeVariable; if (cause) { - cause_local_nonprim = OpenAPI_cause_parseFromJSON(cause); + if (!cJSON_IsString(cause)) { + ogs_error("OpenAPI_release_data_parseFromJSON() failed [cause]"); + goto end; + } + causeVariable = OpenAPI_cause_FromString(cause->valuestring); } cJSON *ng_ap_cause = cJSON_GetObjectItemCaseSensitive(release_dataJSON, "ngApCause"); @@ -269,7 +266,7 @@ OpenAPI_release_data_t *OpenAPI_release_data_parseFromJSON(cJSON *release_dataJS } release_data_local_var = OpenAPI_release_data_create ( - cause ? cause_local_nonprim : NULL, + cause ? causeVariable : 0, ng_ap_cause ? ng_ap_cause_local_nonprim : NULL, _5g_mm_cause_value ? _5g_mm_cause_value->valuedouble : 0, ue_location ? ue_location_local_nonprim : NULL, diff --git a/lib/sbi/openapi/model/release_data.h b/lib/sbi/openapi/model/release_data.h index ec93b07f3..bf49a4f9a 100644 --- a/lib/sbi/openapi/model/release_data.h +++ b/lib/sbi/openapi/model/release_data.h @@ -24,7 +24,7 @@ extern "C" { typedef struct OpenAPI_release_data_s OpenAPI_release_data_t; typedef struct OpenAPI_release_data_s { - struct OpenAPI_cause_s *cause; + OpenAPI_cause_e cause; struct OpenAPI_ng_ap_cause_s *ng_ap_cause; int _5g_mm_cause_value; struct OpenAPI_user_location_s *ue_location; @@ -35,7 +35,7 @@ typedef struct OpenAPI_release_data_s { } OpenAPI_release_data_t; OpenAPI_release_data_t *OpenAPI_release_data_create( - OpenAPI_cause_t *cause, + OpenAPI_cause_e cause, OpenAPI_ng_ap_cause_t *ng_ap_cause, int _5g_mm_cause_value, OpenAPI_user_location_t *ue_location, diff --git a/lib/sbi/openapi/model/request_indication.c b/lib/sbi/openapi/model/request_indication.c index 940352437..990143c59 100644 --- a/lib/sbi/openapi/model/request_indication.c +++ b/lib/sbi/openapi/model/request_indication.c @@ -4,82 +4,27 @@ #include #include "request_indication.h" -OpenAPI_request_indication_t *OpenAPI_request_indication_create( - ) +char* OpenAPI_request_indication_ToString(OpenAPI_request_indication_e request_indication) { - OpenAPI_request_indication_t *request_indication_local_var = OpenAPI_malloc(sizeof(OpenAPI_request_indication_t)); - if (!request_indication_local_var) { - return NULL; - } - - return request_indication_local_var; + const char *request_indicationArray[] = { "NULL", "UE_REQ_PDU_SES_MOD", "UE_REQ_PDU_SES_REL", "PDU_SES_MOB", "NW_REQ_PDU_SES_AUTH", "NW_REQ_PDU_SES_MOD", "NW_REQ_PDU_SES_REL", "EBI_ASSIGNMENT_REQ" }; + size_t sizeofArray = sizeof(request_indicationArray) / sizeof(request_indicationArray[0]); + if (request_indication < sizeofArray) + return (char *)request_indicationArray[request_indication]; + else + return (char *)"Unknown"; } -void OpenAPI_request_indication_free(OpenAPI_request_indication_t *request_indication) +OpenAPI_request_indication_e OpenAPI_request_indication_FromString(char* request_indication) { - if (NULL == request_indication) { - return; + int stringToReturn = 0; + const char *request_indicationArray[] = { "NULL", "UE_REQ_PDU_SES_MOD", "UE_REQ_PDU_SES_REL", "PDU_SES_MOB", "NW_REQ_PDU_SES_AUTH", "NW_REQ_PDU_SES_MOD", "NW_REQ_PDU_SES_REL", "EBI_ASSIGNMENT_REQ" }; + size_t sizeofArray = sizeof(request_indicationArray) / sizeof(request_indicationArray[0]); + while (stringToReturn < sizeofArray) { + if (strcmp(request_indication, request_indicationArray[stringToReturn]) == 0) { + return stringToReturn; + } + stringToReturn++; } - OpenAPI_lnode_t *node; - ogs_free(request_indication); -} - -cJSON *OpenAPI_request_indication_convertToJSON(OpenAPI_request_indication_t *request_indication) -{ - cJSON *item = NULL; - - if (request_indication == NULL) { - ogs_error("OpenAPI_request_indication_convertToJSON() failed [RequestIndication]"); - return NULL; - } - - item = cJSON_CreateObject(); -end: - return item; -} - -OpenAPI_request_indication_t *OpenAPI_request_indication_parseFromJSON(cJSON *request_indicationJSON) -{ - OpenAPI_request_indication_t *request_indication_local_var = NULL; - request_indication_local_var = OpenAPI_request_indication_create ( - ); - - return request_indication_local_var; -end: - return NULL; -} - -OpenAPI_request_indication_t *OpenAPI_request_indication_copy(OpenAPI_request_indication_t *dst, OpenAPI_request_indication_t *src) -{ - cJSON *item = NULL; - char *content = NULL; - - ogs_assert(src); - item = OpenAPI_request_indication_convertToJSON(src); - if (!item) { - ogs_error("OpenAPI_request_indication_convertToJSON() failed"); - return NULL; - } - - content = cJSON_Print(item); - cJSON_Delete(item); - - if (!content) { - ogs_error("cJSON_Print() failed"); - return NULL; - } - - item = cJSON_Parse(content); - ogs_free(content); - if (!item) { - ogs_error("cJSON_Parse() failed"); - return NULL; - } - - OpenAPI_request_indication_free(dst); - dst = OpenAPI_request_indication_parseFromJSON(item); - cJSON_Delete(item); - - return dst; + return 0; } diff --git a/lib/sbi/openapi/model/request_indication.h b/lib/sbi/openapi/model/request_indication.h index 862158f84..b963a2292 100644 --- a/lib/sbi/openapi/model/request_indication.h +++ b/lib/sbi/openapi/model/request_indication.h @@ -1,7 +1,7 @@ /* * request_indication.h * - * Possible values are - UE_REQ_PDU_SES_MOD - UE_REQ_PDU_SES_REL - PDU_SES_MOB - NW_REQ_PDU_SES_AUTH - NW_REQ_PDU_SES_MOD - NW_REQ_PDU_SES_REL - EBI_ASSIGNMENT_REQ + * */ #ifndef _OpenAPI_request_indication_H_ @@ -17,16 +17,11 @@ extern "C" { #endif -typedef struct OpenAPI_request_indication_s OpenAPI_request_indication_t; -typedef struct OpenAPI_request_indication_s { -} OpenAPI_request_indication_t; +typedef enum { OpenAPI_request_indication_NULL = 0, OpenAPI_request_indication_UE_REQ_PDU_SES_MOD, OpenAPI_request_indication_UE_REQ_PDU_SES_REL, OpenAPI_request_indication_PDU_SES_MOB, OpenAPI_request_indication_NW_REQ_PDU_SES_AUTH, OpenAPI_request_indication_NW_REQ_PDU_SES_MOD, OpenAPI_request_indication_NW_REQ_PDU_SES_REL, OpenAPI_request_indication_EBI_ASSIGNMENT_REQ } OpenAPI_request_indication_e; -OpenAPI_request_indication_t *OpenAPI_request_indication_create( - ); -void OpenAPI_request_indication_free(OpenAPI_request_indication_t *request_indication); -OpenAPI_request_indication_t *OpenAPI_request_indication_parseFromJSON(cJSON *request_indicationJSON); -cJSON *OpenAPI_request_indication_convertToJSON(OpenAPI_request_indication_t *request_indication); -OpenAPI_request_indication_t *OpenAPI_request_indication_copy(OpenAPI_request_indication_t *dst, OpenAPI_request_indication_t *src); +char* OpenAPI_request_indication_ToString(OpenAPI_request_indication_e request_indication); + +OpenAPI_request_indication_e OpenAPI_request_indication_FromString(char* request_indication); #ifdef __cplusplus } diff --git a/lib/sbi/openapi/model/request_type.c b/lib/sbi/openapi/model/request_type.c index 3783318bd..6d14eac47 100644 --- a/lib/sbi/openapi/model/request_type.c +++ b/lib/sbi/openapi/model/request_type.c @@ -4,82 +4,27 @@ #include #include "request_type.h" -OpenAPI_request_type_t *OpenAPI_request_type_create( - ) +char* OpenAPI_request_type_ToString(OpenAPI_request_type_e request_type) { - OpenAPI_request_type_t *request_type_local_var = OpenAPI_malloc(sizeof(OpenAPI_request_type_t)); - if (!request_type_local_var) { - return NULL; - } - - return request_type_local_var; + const char *request_typeArray[] = { "NULL", "INITIAL_REQUEST", "EXISTING_PDU_SESSION", "INITIAL_EMERGENCY_REQUEST", "EXISTING_EMERGENCY_PDU_SESSION" }; + size_t sizeofArray = sizeof(request_typeArray) / sizeof(request_typeArray[0]); + if (request_type < sizeofArray) + return (char *)request_typeArray[request_type]; + else + return (char *)"Unknown"; } -void OpenAPI_request_type_free(OpenAPI_request_type_t *request_type) +OpenAPI_request_type_e OpenAPI_request_type_FromString(char* request_type) { - if (NULL == request_type) { - return; + int stringToReturn = 0; + const char *request_typeArray[] = { "NULL", "INITIAL_REQUEST", "EXISTING_PDU_SESSION", "INITIAL_EMERGENCY_REQUEST", "EXISTING_EMERGENCY_PDU_SESSION" }; + size_t sizeofArray = sizeof(request_typeArray) / sizeof(request_typeArray[0]); + while (stringToReturn < sizeofArray) { + if (strcmp(request_type, request_typeArray[stringToReturn]) == 0) { + return stringToReturn; + } + stringToReturn++; } - OpenAPI_lnode_t *node; - ogs_free(request_type); -} - -cJSON *OpenAPI_request_type_convertToJSON(OpenAPI_request_type_t *request_type) -{ - cJSON *item = NULL; - - if (request_type == NULL) { - ogs_error("OpenAPI_request_type_convertToJSON() failed [RequestType]"); - return NULL; - } - - item = cJSON_CreateObject(); -end: - return item; -} - -OpenAPI_request_type_t *OpenAPI_request_type_parseFromJSON(cJSON *request_typeJSON) -{ - OpenAPI_request_type_t *request_type_local_var = NULL; - request_type_local_var = OpenAPI_request_type_create ( - ); - - return request_type_local_var; -end: - return NULL; -} - -OpenAPI_request_type_t *OpenAPI_request_type_copy(OpenAPI_request_type_t *dst, OpenAPI_request_type_t *src) -{ - cJSON *item = NULL; - char *content = NULL; - - ogs_assert(src); - item = OpenAPI_request_type_convertToJSON(src); - if (!item) { - ogs_error("OpenAPI_request_type_convertToJSON() failed"); - return NULL; - } - - content = cJSON_Print(item); - cJSON_Delete(item); - - if (!content) { - ogs_error("cJSON_Print() failed"); - return NULL; - } - - item = cJSON_Parse(content); - ogs_free(content); - if (!item) { - ogs_error("cJSON_Parse() failed"); - return NULL; - } - - OpenAPI_request_type_free(dst); - dst = OpenAPI_request_type_parseFromJSON(item); - cJSON_Delete(item); - - return dst; + return 0; } diff --git a/lib/sbi/openapi/model/request_type.h b/lib/sbi/openapi/model/request_type.h index a292e246e..2eaee1691 100644 --- a/lib/sbi/openapi/model/request_type.h +++ b/lib/sbi/openapi/model/request_type.h @@ -1,7 +1,7 @@ /* * request_type.h * - * Possible values are - INITIAL_REQUEST - EXISTING_PDU_SESSION - INITIAL_EMERGENCY_REQUEST - EXISTING_EMERGENCY_PDU_SESSION + * */ #ifndef _OpenAPI_request_type_H_ @@ -17,16 +17,11 @@ extern "C" { #endif -typedef struct OpenAPI_request_type_s OpenAPI_request_type_t; -typedef struct OpenAPI_request_type_s { -} OpenAPI_request_type_t; +typedef enum { OpenAPI_request_type_NULL = 0, OpenAPI_request_type_INITIAL_REQUEST, OpenAPI_request_type_EXISTING_PDU_SESSION, OpenAPI_request_type_INITIAL_EMERGENCY_REQUEST, OpenAPI_request_type_EXISTING_EMERGENCY_PDU_SESSION } OpenAPI_request_type_e; -OpenAPI_request_type_t *OpenAPI_request_type_create( - ); -void OpenAPI_request_type_free(OpenAPI_request_type_t *request_type); -OpenAPI_request_type_t *OpenAPI_request_type_parseFromJSON(cJSON *request_typeJSON); -cJSON *OpenAPI_request_type_convertToJSON(OpenAPI_request_type_t *request_type); -OpenAPI_request_type_t *OpenAPI_request_type_copy(OpenAPI_request_type_t *dst, OpenAPI_request_type_t *src); +char* OpenAPI_request_type_ToString(OpenAPI_request_type_e request_type); + +OpenAPI_request_type_e OpenAPI_request_type_FromString(char* request_type); #ifdef __cplusplus } diff --git a/lib/sbi/openapi/model/resource_status.c b/lib/sbi/openapi/model/resource_status.c index 56bdfb41d..13e1b21b0 100644 --- a/lib/sbi/openapi/model/resource_status.c +++ b/lib/sbi/openapi/model/resource_status.c @@ -4,82 +4,27 @@ #include #include "resource_status.h" -OpenAPI_resource_status_t *OpenAPI_resource_status_create( - ) +char* OpenAPI_resource_status_ToString(OpenAPI_resource_status_e resource_status) { - OpenAPI_resource_status_t *resource_status_local_var = OpenAPI_malloc(sizeof(OpenAPI_resource_status_t)); - if (!resource_status_local_var) { - return NULL; - } - - return resource_status_local_var; + const char *resource_statusArray[] = { "NULL", "RELEASED", "UNCHANGED", "TRANSFERRED", "UPDATED" }; + size_t sizeofArray = sizeof(resource_statusArray) / sizeof(resource_statusArray[0]); + if (resource_status < sizeofArray) + return (char *)resource_statusArray[resource_status]; + else + return (char *)"Unknown"; } -void OpenAPI_resource_status_free(OpenAPI_resource_status_t *resource_status) +OpenAPI_resource_status_e OpenAPI_resource_status_FromString(char* resource_status) { - if (NULL == resource_status) { - return; + int stringToReturn = 0; + const char *resource_statusArray[] = { "NULL", "RELEASED", "UNCHANGED", "TRANSFERRED", "UPDATED" }; + size_t sizeofArray = sizeof(resource_statusArray) / sizeof(resource_statusArray[0]); + while (stringToReturn < sizeofArray) { + if (strcmp(resource_status, resource_statusArray[stringToReturn]) == 0) { + return stringToReturn; + } + stringToReturn++; } - OpenAPI_lnode_t *node; - ogs_free(resource_status); -} - -cJSON *OpenAPI_resource_status_convertToJSON(OpenAPI_resource_status_t *resource_status) -{ - cJSON *item = NULL; - - if (resource_status == NULL) { - ogs_error("OpenAPI_resource_status_convertToJSON() failed [ResourceStatus]"); - return NULL; - } - - item = cJSON_CreateObject(); -end: - return item; -} - -OpenAPI_resource_status_t *OpenAPI_resource_status_parseFromJSON(cJSON *resource_statusJSON) -{ - OpenAPI_resource_status_t *resource_status_local_var = NULL; - resource_status_local_var = OpenAPI_resource_status_create ( - ); - - return resource_status_local_var; -end: - return NULL; -} - -OpenAPI_resource_status_t *OpenAPI_resource_status_copy(OpenAPI_resource_status_t *dst, OpenAPI_resource_status_t *src) -{ - cJSON *item = NULL; - char *content = NULL; - - ogs_assert(src); - item = OpenAPI_resource_status_convertToJSON(src); - if (!item) { - ogs_error("OpenAPI_resource_status_convertToJSON() failed"); - return NULL; - } - - content = cJSON_Print(item); - cJSON_Delete(item); - - if (!content) { - ogs_error("cJSON_Print() failed"); - return NULL; - } - - item = cJSON_Parse(content); - ogs_free(content); - if (!item) { - ogs_error("cJSON_Parse() failed"); - return NULL; - } - - OpenAPI_resource_status_free(dst); - dst = OpenAPI_resource_status_parseFromJSON(item); - cJSON_Delete(item); - - return dst; + return 0; } diff --git a/lib/sbi/openapi/model/resource_status.h b/lib/sbi/openapi/model/resource_status.h index 23042b968..86e09b9bb 100644 --- a/lib/sbi/openapi/model/resource_status.h +++ b/lib/sbi/openapi/model/resource_status.h @@ -1,7 +1,7 @@ /* * resource_status.h * - * Possible values are - RELEASED - UNCHANGED - UPDATED + * */ #ifndef _OpenAPI_resource_status_H_ @@ -17,16 +17,11 @@ extern "C" { #endif -typedef struct OpenAPI_resource_status_s OpenAPI_resource_status_t; -typedef struct OpenAPI_resource_status_s { -} OpenAPI_resource_status_t; +typedef enum { OpenAPI_resource_status_NULL = 0, OpenAPI_resource_status_RELEASED, OpenAPI_resource_status_UNCHANGED, OpenAPI_resource_status_TRANSFERRED, OpenAPI_resource_status_UPDATED } OpenAPI_resource_status_e; -OpenAPI_resource_status_t *OpenAPI_resource_status_create( - ); -void OpenAPI_resource_status_free(OpenAPI_resource_status_t *resource_status); -OpenAPI_resource_status_t *OpenAPI_resource_status_parseFromJSON(cJSON *resource_statusJSON); -cJSON *OpenAPI_resource_status_convertToJSON(OpenAPI_resource_status_t *resource_status); -OpenAPI_resource_status_t *OpenAPI_resource_status_copy(OpenAPI_resource_status_t *dst, OpenAPI_resource_status_t *src); +char* OpenAPI_resource_status_ToString(OpenAPI_resource_status_e resource_status); + +OpenAPI_resource_status_e OpenAPI_resource_status_FromString(char* resource_status); #ifdef __cplusplus } diff --git a/lib/sbi/openapi/model/sm_context.c b/lib/sbi/openapi/model/sm_context.c index a6e29e70d..2e022b72e 100644 --- a/lib/sbi/openapi/model/sm_context.c +++ b/lib/sbi/openapi/model/sm_context.c @@ -17,7 +17,7 @@ OpenAPI_sm_context_t *OpenAPI_sm_context_create( char *pcf_id, char *pcf_group_id, char *pcf_set_id, - OpenAPI_dnn_selection_mode_t *sel_mode, + OpenAPI_dnn_selection_mode_e sel_mode, char *udm_group_id, char *routing_indicator, OpenAPI_ambr_t *session_ambr, @@ -29,7 +29,7 @@ OpenAPI_sm_context_t *OpenAPI_sm_context_create( char *ue_ipv6_prefix, OpenAPI_eps_pdn_cnx_info_t *eps_pdn_cnx_info, OpenAPI_list_t *eps_bearer_info, - OpenAPI_max_integrity_protected_data_rate_t *max_integrity_protected_data_rate, + OpenAPI_max_integrity_protected_data_rate_e max_integrity_protected_data_rate, int always_on_granted, OpenAPI_up_security_t *up_security, char *h_smf_service_instance_id, @@ -103,7 +103,6 @@ void OpenAPI_sm_context_free(OpenAPI_sm_context_t *sm_context) ogs_free(sm_context->pcf_id); ogs_free(sm_context->pcf_group_id); ogs_free(sm_context->pcf_set_id); - OpenAPI_dnn_selection_mode_free(sm_context->sel_mode); ogs_free(sm_context->udm_group_id); ogs_free(sm_context->routing_indicator); OpenAPI_ambr_free(sm_context->session_ambr); @@ -120,7 +119,6 @@ void OpenAPI_sm_context_free(OpenAPI_sm_context_t *sm_context) OpenAPI_eps_bearer_info_free(node->data); } OpenAPI_list_free(sm_context->eps_bearer_info); - OpenAPI_max_integrity_protected_data_rate_free(sm_context->max_integrity_protected_data_rate); OpenAPI_up_security_free(sm_context->up_security); ogs_free(sm_context->h_smf_service_instance_id); ogs_free(sm_context->smf_service_instance_id); @@ -247,13 +245,7 @@ cJSON *OpenAPI_sm_context_convertToJSON(OpenAPI_sm_context_t *sm_context) } if (sm_context->sel_mode) { - cJSON *sel_mode_local_JSON = OpenAPI_dnn_selection_mode_convertToJSON(sm_context->sel_mode); - if (sel_mode_local_JSON == NULL) { - ogs_error("OpenAPI_sm_context_convertToJSON() failed [sel_mode]"); - goto end; - } - cJSON_AddItemToObject(item, "selMode", sel_mode_local_JSON); - if (item->child == NULL) { + if (cJSON_AddStringToObject(item, "selMode", OpenAPI_dnn_selection_mode_ToString(sm_context->sel_mode)) == NULL) { ogs_error("OpenAPI_sm_context_convertToJSON() failed [sel_mode]"); goto end; } @@ -379,13 +371,7 @@ cJSON *OpenAPI_sm_context_convertToJSON(OpenAPI_sm_context_t *sm_context) } if (sm_context->max_integrity_protected_data_rate) { - cJSON *max_integrity_protected_data_rate_local_JSON = OpenAPI_max_integrity_protected_data_rate_convertToJSON(sm_context->max_integrity_protected_data_rate); - if (max_integrity_protected_data_rate_local_JSON == NULL) { - ogs_error("OpenAPI_sm_context_convertToJSON() failed [max_integrity_protected_data_rate]"); - goto end; - } - cJSON_AddItemToObject(item, "maxIntegrityProtectedDataRate", max_integrity_protected_data_rate_local_JSON); - if (item->child == NULL) { + if (cJSON_AddStringToObject(item, "maxIntegrityProtectedDataRate", OpenAPI_max_integrity_protected_data_rate_ToString(sm_context->max_integrity_protected_data_rate)) == NULL) { ogs_error("OpenAPI_sm_context_convertToJSON() failed [max_integrity_protected_data_rate]"); goto end; } @@ -619,9 +605,13 @@ OpenAPI_sm_context_t *OpenAPI_sm_context_parseFromJSON(cJSON *sm_contextJSON) cJSON *sel_mode = cJSON_GetObjectItemCaseSensitive(sm_contextJSON, "selMode"); - OpenAPI_dnn_selection_mode_t *sel_mode_local_nonprim = NULL; + OpenAPI_dnn_selection_mode_e sel_modeVariable; if (sel_mode) { - sel_mode_local_nonprim = OpenAPI_dnn_selection_mode_parseFromJSON(sel_mode); + if (!cJSON_IsString(sel_mode)) { + ogs_error("OpenAPI_sm_context_parseFromJSON() failed [sel_mode]"); + goto end; + } + sel_modeVariable = OpenAPI_dnn_selection_mode_FromString(sel_mode->valuestring); } cJSON *udm_group_id = cJSON_GetObjectItemCaseSensitive(sm_contextJSON, "udmGroupId"); @@ -755,9 +745,13 @@ OpenAPI_sm_context_t *OpenAPI_sm_context_parseFromJSON(cJSON *sm_contextJSON) cJSON *max_integrity_protected_data_rate = cJSON_GetObjectItemCaseSensitive(sm_contextJSON, "maxIntegrityProtectedDataRate"); - OpenAPI_max_integrity_protected_data_rate_t *max_integrity_protected_data_rate_local_nonprim = NULL; + OpenAPI_max_integrity_protected_data_rate_e max_integrity_protected_data_rateVariable; if (max_integrity_protected_data_rate) { - max_integrity_protected_data_rate_local_nonprim = OpenAPI_max_integrity_protected_data_rate_parseFromJSON(max_integrity_protected_data_rate); + if (!cJSON_IsString(max_integrity_protected_data_rate)) { + ogs_error("OpenAPI_sm_context_parseFromJSON() failed [max_integrity_protected_data_rate]"); + goto end; + } + max_integrity_protected_data_rateVariable = OpenAPI_max_integrity_protected_data_rate_FromString(max_integrity_protected_data_rate->valuestring); } cJSON *always_on_granted = cJSON_GetObjectItemCaseSensitive(sm_contextJSON, "alwaysOnGranted"); @@ -864,7 +858,7 @@ OpenAPI_sm_context_t *OpenAPI_sm_context_parseFromJSON(cJSON *sm_contextJSON) pcf_id ? ogs_strdup(pcf_id->valuestring) : NULL, pcf_group_id ? ogs_strdup(pcf_group_id->valuestring) : NULL, pcf_set_id ? ogs_strdup(pcf_set_id->valuestring) : NULL, - sel_mode ? sel_mode_local_nonprim : NULL, + sel_mode ? sel_modeVariable : 0, udm_group_id ? ogs_strdup(udm_group_id->valuestring) : NULL, routing_indicator ? ogs_strdup(routing_indicator->valuestring) : NULL, session_ambr_local_nonprim, @@ -876,7 +870,7 @@ OpenAPI_sm_context_t *OpenAPI_sm_context_parseFromJSON(cJSON *sm_contextJSON) ue_ipv6_prefix ? ogs_strdup(ue_ipv6_prefix->valuestring) : NULL, eps_pdn_cnx_info ? eps_pdn_cnx_info_local_nonprim : NULL, eps_bearer_info ? eps_bearer_infoList : NULL, - max_integrity_protected_data_rate ? max_integrity_protected_data_rate_local_nonprim : NULL, + max_integrity_protected_data_rate ? max_integrity_protected_data_rateVariable : 0, always_on_granted ? always_on_granted->valueint : 0, up_security ? up_security_local_nonprim : NULL, h_smf_service_instance_id ? ogs_strdup(h_smf_service_instance_id->valuestring) : NULL, diff --git a/lib/sbi/openapi/model/sm_context.h b/lib/sbi/openapi/model/sm_context.h index c8948e004..877f75824 100644 --- a/lib/sbi/openapi/model/sm_context.h +++ b/lib/sbi/openapi/model/sm_context.h @@ -43,7 +43,7 @@ typedef struct OpenAPI_sm_context_s { char *pcf_id; char *pcf_group_id; char *pcf_set_id; - struct OpenAPI_dnn_selection_mode_s *sel_mode; + OpenAPI_dnn_selection_mode_e sel_mode; char *udm_group_id; char *routing_indicator; struct OpenAPI_ambr_s *session_ambr; @@ -55,7 +55,7 @@ typedef struct OpenAPI_sm_context_s { char *ue_ipv6_prefix; struct OpenAPI_eps_pdn_cnx_info_s *eps_pdn_cnx_info; OpenAPI_list_t *eps_bearer_info; - struct OpenAPI_max_integrity_protected_data_rate_s *max_integrity_protected_data_rate; + OpenAPI_max_integrity_protected_data_rate_e max_integrity_protected_data_rate; int always_on_granted; struct OpenAPI_up_security_s *up_security; char *h_smf_service_instance_id; @@ -82,7 +82,7 @@ OpenAPI_sm_context_t *OpenAPI_sm_context_create( char *pcf_id, char *pcf_group_id, char *pcf_set_id, - OpenAPI_dnn_selection_mode_t *sel_mode, + OpenAPI_dnn_selection_mode_e sel_mode, char *udm_group_id, char *routing_indicator, OpenAPI_ambr_t *session_ambr, @@ -94,7 +94,7 @@ OpenAPI_sm_context_t *OpenAPI_sm_context_create( char *ue_ipv6_prefix, OpenAPI_eps_pdn_cnx_info_t *eps_pdn_cnx_info, OpenAPI_list_t *eps_bearer_info, - OpenAPI_max_integrity_protected_data_rate_t *max_integrity_protected_data_rate, + OpenAPI_max_integrity_protected_data_rate_e max_integrity_protected_data_rate, int always_on_granted, OpenAPI_up_security_t *up_security, char *h_smf_service_instance_id, diff --git a/lib/sbi/openapi/model/sm_context_create_data.c b/lib/sbi/openapi/model/sm_context_create_data.c index a4b694657..58bf21ba3 100644 --- a/lib/sbi/openapi/model/sm_context_create_data.c +++ b/lib/sbi/openapi/model/sm_context_create_data.c @@ -17,7 +17,7 @@ OpenAPI_sm_context_create_data_t *OpenAPI_sm_context_create_data_create( OpenAPI_guami_t *guami, char *service_name, OpenAPI_plmn_id_nid_t *serving_network, - OpenAPI_request_type_t *request_type, + OpenAPI_request_type_e request_type, OpenAPI_ref_to_binary_data_t *n1_sm_msg, OpenAPI_access_type_e an_type, OpenAPI_access_type_e additional_an_type, @@ -34,18 +34,18 @@ OpenAPI_sm_context_create_data_t *OpenAPI_sm_context_create_data_create( int old_pdu_session_id, OpenAPI_list_t *pdu_sessions_activate_list, char *ue_eps_pdn_connection, - OpenAPI_ho_state_t *ho_state, + OpenAPI_ho_state_e ho_state, char *pcf_id, char *pcf_group_id, char *pcf_set_id, char *nrf_uri, char *supported_features, - OpenAPI_dnn_selection_mode_t *sel_mode, + OpenAPI_dnn_selection_mode_e sel_mode, OpenAPI_list_t *backup_amf_info, OpenAPI_trace_data_t *trace_data, char *udm_group_id, char *routing_indicator, - OpenAPI_eps_interworking_indication_t *eps_interworking_ind, + OpenAPI_eps_interworking_indication_e eps_interworking_ind, int indirect_forwarding_flag, OpenAPI_ng_ran_target_id_t *target_id, char *eps_bearer_ctx_status, @@ -59,7 +59,7 @@ OpenAPI_sm_context_create_data_t *OpenAPI_sm_context_create_data_create( OpenAPI_ref_to_binary_data_t *n2_sm_info_ext1, OpenAPI_n2_sm_info_type_e n2_sm_info_type_ext1, char *sm_context_ref, - OpenAPI_up_cnx_state_t *up_cnx_state, + OpenAPI_up_cnx_state_e up_cnx_state, OpenAPI_small_data_rate_status_t *small_data_rate_status, OpenAPI_apn_rate_status_t *apn_rate_status, int extended_nas_sm_timer_ind, @@ -163,7 +163,6 @@ void OpenAPI_sm_context_create_data_free(OpenAPI_sm_context_create_data_t *sm_co OpenAPI_guami_free(sm_context_create_data->guami); ogs_free(sm_context_create_data->service_name); OpenAPI_plmn_id_nid_free(sm_context_create_data->serving_network); - OpenAPI_request_type_free(sm_context_create_data->request_type); OpenAPI_ref_to_binary_data_free(sm_context_create_data->n1_sm_msg); OpenAPI_presence_state_free(sm_context_create_data->presence_in_ladn); OpenAPI_user_location_free(sm_context_create_data->ue_location); @@ -185,13 +184,11 @@ void OpenAPI_sm_context_create_data_free(OpenAPI_sm_context_create_data_t *sm_co } OpenAPI_list_free(sm_context_create_data->pdu_sessions_activate_list); ogs_free(sm_context_create_data->ue_eps_pdn_connection); - OpenAPI_ho_state_free(sm_context_create_data->ho_state); ogs_free(sm_context_create_data->pcf_id); ogs_free(sm_context_create_data->pcf_group_id); ogs_free(sm_context_create_data->pcf_set_id); ogs_free(sm_context_create_data->nrf_uri); ogs_free(sm_context_create_data->supported_features); - OpenAPI_dnn_selection_mode_free(sm_context_create_data->sel_mode); OpenAPI_list_for_each(sm_context_create_data->backup_amf_info, node) { OpenAPI_backup_amf_info_free(node->data); } @@ -199,13 +196,11 @@ void OpenAPI_sm_context_create_data_free(OpenAPI_sm_context_create_data_t *sm_co OpenAPI_trace_data_free(sm_context_create_data->trace_data); ogs_free(sm_context_create_data->udm_group_id); ogs_free(sm_context_create_data->routing_indicator); - OpenAPI_eps_interworking_indication_free(sm_context_create_data->eps_interworking_ind); OpenAPI_ng_ran_target_id_free(sm_context_create_data->target_id); ogs_free(sm_context_create_data->eps_bearer_ctx_status); OpenAPI_ref_to_binary_data_free(sm_context_create_data->n2_sm_info); OpenAPI_ref_to_binary_data_free(sm_context_create_data->n2_sm_info_ext1); ogs_free(sm_context_create_data->sm_context_ref); - OpenAPI_up_cnx_state_free(sm_context_create_data->up_cnx_state); OpenAPI_small_data_rate_status_free(sm_context_create_data->small_data_rate_status); OpenAPI_apn_rate_status_free(sm_context_create_data->apn_rate_status); OpenAPI_ddn_failure_subs_free(sm_context_create_data->ddn_failure_subs); @@ -340,13 +335,7 @@ cJSON *OpenAPI_sm_context_create_data_convertToJSON(OpenAPI_sm_context_create_da } if (sm_context_create_data->request_type) { - cJSON *request_type_local_JSON = OpenAPI_request_type_convertToJSON(sm_context_create_data->request_type); - if (request_type_local_JSON == NULL) { - ogs_error("OpenAPI_sm_context_create_data_convertToJSON() failed [request_type]"); - goto end; - } - cJSON_AddItemToObject(item, "requestType", request_type_local_JSON); - if (item->child == NULL) { + if (cJSON_AddStringToObject(item, "requestType", OpenAPI_request_type_ToString(sm_context_create_data->request_type)) == NULL) { ogs_error("OpenAPI_sm_context_create_data_convertToJSON() failed [request_type]"); goto end; } @@ -520,13 +509,7 @@ cJSON *OpenAPI_sm_context_create_data_convertToJSON(OpenAPI_sm_context_create_da } if (sm_context_create_data->ho_state) { - cJSON *ho_state_local_JSON = OpenAPI_ho_state_convertToJSON(sm_context_create_data->ho_state); - if (ho_state_local_JSON == NULL) { - ogs_error("OpenAPI_sm_context_create_data_convertToJSON() failed [ho_state]"); - goto end; - } - cJSON_AddItemToObject(item, "hoState", ho_state_local_JSON); - if (item->child == NULL) { + if (cJSON_AddStringToObject(item, "hoState", OpenAPI_ho_state_ToString(sm_context_create_data->ho_state)) == NULL) { ogs_error("OpenAPI_sm_context_create_data_convertToJSON() failed [ho_state]"); goto end; } @@ -568,13 +551,7 @@ cJSON *OpenAPI_sm_context_create_data_convertToJSON(OpenAPI_sm_context_create_da } if (sm_context_create_data->sel_mode) { - cJSON *sel_mode_local_JSON = OpenAPI_dnn_selection_mode_convertToJSON(sm_context_create_data->sel_mode); - if (sel_mode_local_JSON == NULL) { - ogs_error("OpenAPI_sm_context_create_data_convertToJSON() failed [sel_mode]"); - goto end; - } - cJSON_AddItemToObject(item, "selMode", sel_mode_local_JSON); - if (item->child == NULL) { + if (cJSON_AddStringToObject(item, "selMode", OpenAPI_dnn_selection_mode_ToString(sm_context_create_data->sel_mode)) == NULL) { ogs_error("OpenAPI_sm_context_create_data_convertToJSON() failed [sel_mode]"); goto end; } @@ -628,13 +605,7 @@ cJSON *OpenAPI_sm_context_create_data_convertToJSON(OpenAPI_sm_context_create_da } if (sm_context_create_data->eps_interworking_ind) { - cJSON *eps_interworking_ind_local_JSON = OpenAPI_eps_interworking_indication_convertToJSON(sm_context_create_data->eps_interworking_ind); - if (eps_interworking_ind_local_JSON == NULL) { - ogs_error("OpenAPI_sm_context_create_data_convertToJSON() failed [eps_interworking_ind]"); - goto end; - } - cJSON_AddItemToObject(item, "epsInterworkingInd", eps_interworking_ind_local_JSON); - if (item->child == NULL) { + if (cJSON_AddStringToObject(item, "epsInterworkingInd", OpenAPI_eps_interworking_indication_ToString(sm_context_create_data->eps_interworking_ind)) == NULL) { ogs_error("OpenAPI_sm_context_create_data_convertToJSON() failed [eps_interworking_ind]"); goto end; } @@ -750,13 +721,7 @@ cJSON *OpenAPI_sm_context_create_data_convertToJSON(OpenAPI_sm_context_create_da } if (sm_context_create_data->up_cnx_state) { - cJSON *up_cnx_state_local_JSON = OpenAPI_up_cnx_state_convertToJSON(sm_context_create_data->up_cnx_state); - if (up_cnx_state_local_JSON == NULL) { - ogs_error("OpenAPI_sm_context_create_data_convertToJSON() failed [up_cnx_state]"); - goto end; - } - cJSON_AddItemToObject(item, "upCnxState", up_cnx_state_local_JSON); - if (item->child == NULL) { + if (cJSON_AddStringToObject(item, "upCnxState", OpenAPI_up_cnx_state_ToString(sm_context_create_data->up_cnx_state)) == NULL) { ogs_error("OpenAPI_sm_context_create_data_convertToJSON() failed [up_cnx_state]"); goto end; } @@ -990,9 +955,13 @@ OpenAPI_sm_context_create_data_t *OpenAPI_sm_context_create_data_parseFromJSON(c cJSON *request_type = cJSON_GetObjectItemCaseSensitive(sm_context_create_dataJSON, "requestType"); - OpenAPI_request_type_t *request_type_local_nonprim = NULL; + OpenAPI_request_type_e request_typeVariable; if (request_type) { - request_type_local_nonprim = OpenAPI_request_type_parseFromJSON(request_type); + if (!cJSON_IsString(request_type)) { + ogs_error("OpenAPI_sm_context_create_data_parseFromJSON() failed [request_type]"); + goto end; + } + request_typeVariable = OpenAPI_request_type_FromString(request_type->valuestring); } cJSON *n1_sm_msg = cJSON_GetObjectItemCaseSensitive(sm_context_create_dataJSON, "n1SmMsg"); @@ -1178,9 +1147,13 @@ OpenAPI_sm_context_create_data_t *OpenAPI_sm_context_create_data_parseFromJSON(c cJSON *ho_state = cJSON_GetObjectItemCaseSensitive(sm_context_create_dataJSON, "hoState"); - OpenAPI_ho_state_t *ho_state_local_nonprim = NULL; + OpenAPI_ho_state_e ho_stateVariable; if (ho_state) { - ho_state_local_nonprim = OpenAPI_ho_state_parseFromJSON(ho_state); + if (!cJSON_IsString(ho_state)) { + ogs_error("OpenAPI_sm_context_create_data_parseFromJSON() failed [ho_state]"); + goto end; + } + ho_stateVariable = OpenAPI_ho_state_FromString(ho_state->valuestring); } cJSON *pcf_id = cJSON_GetObjectItemCaseSensitive(sm_context_create_dataJSON, "pcfId"); @@ -1230,9 +1203,13 @@ OpenAPI_sm_context_create_data_t *OpenAPI_sm_context_create_data_parseFromJSON(c cJSON *sel_mode = cJSON_GetObjectItemCaseSensitive(sm_context_create_dataJSON, "selMode"); - OpenAPI_dnn_selection_mode_t *sel_mode_local_nonprim = NULL; + OpenAPI_dnn_selection_mode_e sel_modeVariable; if (sel_mode) { - sel_mode_local_nonprim = OpenAPI_dnn_selection_mode_parseFromJSON(sel_mode); + if (!cJSON_IsString(sel_mode)) { + ogs_error("OpenAPI_sm_context_create_data_parseFromJSON() failed [sel_mode]"); + goto end; + } + sel_modeVariable = OpenAPI_dnn_selection_mode_FromString(sel_mode->valuestring); } cJSON *backup_amf_info = cJSON_GetObjectItemCaseSensitive(sm_context_create_dataJSON, "backupAmfInfo"); @@ -1285,9 +1262,13 @@ OpenAPI_sm_context_create_data_t *OpenAPI_sm_context_create_data_parseFromJSON(c cJSON *eps_interworking_ind = cJSON_GetObjectItemCaseSensitive(sm_context_create_dataJSON, "epsInterworkingInd"); - OpenAPI_eps_interworking_indication_t *eps_interworking_ind_local_nonprim = NULL; + OpenAPI_eps_interworking_indication_e eps_interworking_indVariable; if (eps_interworking_ind) { - eps_interworking_ind_local_nonprim = OpenAPI_eps_interworking_indication_parseFromJSON(eps_interworking_ind); + if (!cJSON_IsString(eps_interworking_ind)) { + ogs_error("OpenAPI_sm_context_create_data_parseFromJSON() failed [eps_interworking_ind]"); + goto end; + } + eps_interworking_indVariable = OpenAPI_eps_interworking_indication_FromString(eps_interworking_ind->valuestring); } cJSON *indirect_forwarding_flag = cJSON_GetObjectItemCaseSensitive(sm_context_create_dataJSON, "indirectForwardingFlag"); @@ -1407,9 +1388,13 @@ OpenAPI_sm_context_create_data_t *OpenAPI_sm_context_create_data_parseFromJSON(c cJSON *up_cnx_state = cJSON_GetObjectItemCaseSensitive(sm_context_create_dataJSON, "upCnxState"); - OpenAPI_up_cnx_state_t *up_cnx_state_local_nonprim = NULL; + OpenAPI_up_cnx_state_e up_cnx_stateVariable; if (up_cnx_state) { - up_cnx_state_local_nonprim = OpenAPI_up_cnx_state_parseFromJSON(up_cnx_state); + if (!cJSON_IsString(up_cnx_state)) { + ogs_error("OpenAPI_sm_context_create_data_parseFromJSON() failed [up_cnx_state]"); + goto end; + } + up_cnx_stateVariable = OpenAPI_up_cnx_state_FromString(up_cnx_state->valuestring); } cJSON *small_data_rate_status = cJSON_GetObjectItemCaseSensitive(sm_context_create_dataJSON, "smallDataRateStatus"); @@ -1512,7 +1497,7 @@ OpenAPI_sm_context_create_data_t *OpenAPI_sm_context_create_data_parseFromJSON(c guami ? guami_local_nonprim : NULL, service_name ? ogs_strdup(service_name->valuestring) : NULL, serving_network_local_nonprim, - request_type ? request_type_local_nonprim : NULL, + request_type ? request_typeVariable : 0, n1_sm_msg ? n1_sm_msg_local_nonprim : NULL, an_typeVariable, additional_an_type ? additional_an_typeVariable : 0, @@ -1529,18 +1514,18 @@ OpenAPI_sm_context_create_data_t *OpenAPI_sm_context_create_data_parseFromJSON(c old_pdu_session_id ? old_pdu_session_id->valuedouble : 0, pdu_sessions_activate_list ? pdu_sessions_activate_listList : NULL, ue_eps_pdn_connection ? ogs_strdup(ue_eps_pdn_connection->valuestring) : NULL, - ho_state ? ho_state_local_nonprim : NULL, + ho_state ? ho_stateVariable : 0, pcf_id ? ogs_strdup(pcf_id->valuestring) : NULL, pcf_group_id ? ogs_strdup(pcf_group_id->valuestring) : NULL, pcf_set_id ? ogs_strdup(pcf_set_id->valuestring) : NULL, nrf_uri ? ogs_strdup(nrf_uri->valuestring) : NULL, supported_features ? ogs_strdup(supported_features->valuestring) : NULL, - sel_mode ? sel_mode_local_nonprim : NULL, + sel_mode ? sel_modeVariable : 0, backup_amf_info ? backup_amf_infoList : NULL, trace_data ? trace_data_local_nonprim : NULL, udm_group_id ? ogs_strdup(udm_group_id->valuestring) : NULL, routing_indicator ? ogs_strdup(routing_indicator->valuestring) : NULL, - eps_interworking_ind ? eps_interworking_ind_local_nonprim : NULL, + eps_interworking_ind ? eps_interworking_indVariable : 0, indirect_forwarding_flag ? indirect_forwarding_flag->valueint : 0, target_id ? target_id_local_nonprim : NULL, eps_bearer_ctx_status ? ogs_strdup(eps_bearer_ctx_status->valuestring) : NULL, @@ -1554,7 +1539,7 @@ OpenAPI_sm_context_create_data_t *OpenAPI_sm_context_create_data_parseFromJSON(c n2_sm_info_ext1 ? n2_sm_info_ext1_local_nonprim : NULL, n2_sm_info_type_ext1 ? n2_sm_info_type_ext1Variable : 0, sm_context_ref ? ogs_strdup(sm_context_ref->valuestring) : NULL, - up_cnx_state ? up_cnx_state_local_nonprim : NULL, + up_cnx_state ? up_cnx_stateVariable : 0, small_data_rate_status ? small_data_rate_status_local_nonprim : NULL, apn_rate_status ? apn_rate_status_local_nonprim : NULL, extended_nas_sm_timer_ind ? extended_nas_sm_timer_ind->valueint : 0, diff --git a/lib/sbi/openapi/model/sm_context_create_data.h b/lib/sbi/openapi/model/sm_context_create_data.h index e0af23197..db7482bf9 100644 --- a/lib/sbi/openapi/model/sm_context_create_data.h +++ b/lib/sbi/openapi/model/sm_context_create_data.h @@ -54,7 +54,7 @@ typedef struct OpenAPI_sm_context_create_data_s { struct OpenAPI_guami_s *guami; char *service_name; struct OpenAPI_plmn_id_nid_s *serving_network; - struct OpenAPI_request_type_s *request_type; + OpenAPI_request_type_e request_type; struct OpenAPI_ref_to_binary_data_s *n1_sm_msg; OpenAPI_access_type_e an_type; OpenAPI_access_type_e additional_an_type; @@ -71,18 +71,18 @@ typedef struct OpenAPI_sm_context_create_data_s { int old_pdu_session_id; OpenAPI_list_t *pdu_sessions_activate_list; char *ue_eps_pdn_connection; - struct OpenAPI_ho_state_s *ho_state; + OpenAPI_ho_state_e ho_state; char *pcf_id; char *pcf_group_id; char *pcf_set_id; char *nrf_uri; char *supported_features; - struct OpenAPI_dnn_selection_mode_s *sel_mode; + OpenAPI_dnn_selection_mode_e sel_mode; OpenAPI_list_t *backup_amf_info; struct OpenAPI_trace_data_s *trace_data; char *udm_group_id; char *routing_indicator; - struct OpenAPI_eps_interworking_indication_s *eps_interworking_ind; + OpenAPI_eps_interworking_indication_e eps_interworking_ind; int indirect_forwarding_flag; struct OpenAPI_ng_ran_target_id_s *target_id; char *eps_bearer_ctx_status; @@ -96,7 +96,7 @@ typedef struct OpenAPI_sm_context_create_data_s { struct OpenAPI_ref_to_binary_data_s *n2_sm_info_ext1; OpenAPI_n2_sm_info_type_e n2_sm_info_type_ext1; char *sm_context_ref; - struct OpenAPI_up_cnx_state_s *up_cnx_state; + OpenAPI_up_cnx_state_e up_cnx_state; struct OpenAPI_small_data_rate_status_s *small_data_rate_status; struct OpenAPI_apn_rate_status_s *apn_rate_status; int extended_nas_sm_timer_ind; @@ -123,7 +123,7 @@ OpenAPI_sm_context_create_data_t *OpenAPI_sm_context_create_data_create( OpenAPI_guami_t *guami, char *service_name, OpenAPI_plmn_id_nid_t *serving_network, - OpenAPI_request_type_t *request_type, + OpenAPI_request_type_e request_type, OpenAPI_ref_to_binary_data_t *n1_sm_msg, OpenAPI_access_type_e an_type, OpenAPI_access_type_e additional_an_type, @@ -140,18 +140,18 @@ OpenAPI_sm_context_create_data_t *OpenAPI_sm_context_create_data_create( int old_pdu_session_id, OpenAPI_list_t *pdu_sessions_activate_list, char *ue_eps_pdn_connection, - OpenAPI_ho_state_t *ho_state, + OpenAPI_ho_state_e ho_state, char *pcf_id, char *pcf_group_id, char *pcf_set_id, char *nrf_uri, char *supported_features, - OpenAPI_dnn_selection_mode_t *sel_mode, + OpenAPI_dnn_selection_mode_e sel_mode, OpenAPI_list_t *backup_amf_info, OpenAPI_trace_data_t *trace_data, char *udm_group_id, char *routing_indicator, - OpenAPI_eps_interworking_indication_t *eps_interworking_ind, + OpenAPI_eps_interworking_indication_e eps_interworking_ind, int indirect_forwarding_flag, OpenAPI_ng_ran_target_id_t *target_id, char *eps_bearer_ctx_status, @@ -165,7 +165,7 @@ OpenAPI_sm_context_create_data_t *OpenAPI_sm_context_create_data_create( OpenAPI_ref_to_binary_data_t *n2_sm_info_ext1, OpenAPI_n2_sm_info_type_e n2_sm_info_type_ext1, char *sm_context_ref, - OpenAPI_up_cnx_state_t *up_cnx_state, + OpenAPI_up_cnx_state_e up_cnx_state, OpenAPI_small_data_rate_status_t *small_data_rate_status, OpenAPI_apn_rate_status_t *apn_rate_status, int extended_nas_sm_timer_ind, diff --git a/lib/sbi/openapi/model/sm_context_created_data.c b/lib/sbi/openapi/model/sm_context_created_data.c index fd2c85dce..a69ab174e 100644 --- a/lib/sbi/openapi/model/sm_context_created_data.c +++ b/lib/sbi/openapi/model/sm_context_created_data.c @@ -9,11 +9,11 @@ OpenAPI_sm_context_created_data_t *OpenAPI_sm_context_created_data_create( char *smf_uri, int pdu_session_id, OpenAPI_snssai_t *s_nssai, - OpenAPI_up_cnx_state_t *up_cnx_state, + OpenAPI_up_cnx_state_e up_cnx_state, OpenAPI_ref_to_binary_data_t *n2_sm_info, OpenAPI_n2_sm_info_type_e n2_sm_info_type, OpenAPI_list_t *allocated_ebi_list, - OpenAPI_ho_state_t *ho_state, + OpenAPI_ho_state_e ho_state, char *gpsi, char *smf_service_instance_id, char *recovery_time, @@ -50,13 +50,11 @@ void OpenAPI_sm_context_created_data_free(OpenAPI_sm_context_created_data_t *sm_ ogs_free(sm_context_created_data->h_smf_uri); ogs_free(sm_context_created_data->smf_uri); OpenAPI_snssai_free(sm_context_created_data->s_nssai); - OpenAPI_up_cnx_state_free(sm_context_created_data->up_cnx_state); OpenAPI_ref_to_binary_data_free(sm_context_created_data->n2_sm_info); OpenAPI_list_for_each(sm_context_created_data->allocated_ebi_list, node) { OpenAPI_ebi_arp_mapping_free(node->data); } OpenAPI_list_free(sm_context_created_data->allocated_ebi_list); - OpenAPI_ho_state_free(sm_context_created_data->ho_state); ogs_free(sm_context_created_data->gpsi); ogs_free(sm_context_created_data->smf_service_instance_id); ogs_free(sm_context_created_data->recovery_time); @@ -109,13 +107,7 @@ cJSON *OpenAPI_sm_context_created_data_convertToJSON(OpenAPI_sm_context_created_ } if (sm_context_created_data->up_cnx_state) { - cJSON *up_cnx_state_local_JSON = OpenAPI_up_cnx_state_convertToJSON(sm_context_created_data->up_cnx_state); - if (up_cnx_state_local_JSON == NULL) { - ogs_error("OpenAPI_sm_context_created_data_convertToJSON() failed [up_cnx_state]"); - goto end; - } - cJSON_AddItemToObject(item, "upCnxState", up_cnx_state_local_JSON); - if (item->child == NULL) { + if (cJSON_AddStringToObject(item, "upCnxState", OpenAPI_up_cnx_state_ToString(sm_context_created_data->up_cnx_state)) == NULL) { ogs_error("OpenAPI_sm_context_created_data_convertToJSON() failed [up_cnx_state]"); goto end; } @@ -162,13 +154,7 @@ cJSON *OpenAPI_sm_context_created_data_convertToJSON(OpenAPI_sm_context_created_ } if (sm_context_created_data->ho_state) { - cJSON *ho_state_local_JSON = OpenAPI_ho_state_convertToJSON(sm_context_created_data->ho_state); - if (ho_state_local_JSON == NULL) { - ogs_error("OpenAPI_sm_context_created_data_convertToJSON() failed [ho_state]"); - goto end; - } - cJSON_AddItemToObject(item, "hoState", ho_state_local_JSON); - if (item->child == NULL) { + if (cJSON_AddStringToObject(item, "hoState", OpenAPI_ho_state_ToString(sm_context_created_data->ho_state)) == NULL) { ogs_error("OpenAPI_sm_context_created_data_convertToJSON() failed [ho_state]"); goto end; } @@ -245,9 +231,13 @@ OpenAPI_sm_context_created_data_t *OpenAPI_sm_context_created_data_parseFromJSON cJSON *up_cnx_state = cJSON_GetObjectItemCaseSensitive(sm_context_created_dataJSON, "upCnxState"); - OpenAPI_up_cnx_state_t *up_cnx_state_local_nonprim = NULL; + OpenAPI_up_cnx_state_e up_cnx_stateVariable; if (up_cnx_state) { - up_cnx_state_local_nonprim = OpenAPI_up_cnx_state_parseFromJSON(up_cnx_state); + if (!cJSON_IsString(up_cnx_state)) { + ogs_error("OpenAPI_sm_context_created_data_parseFromJSON() failed [up_cnx_state]"); + goto end; + } + up_cnx_stateVariable = OpenAPI_up_cnx_state_FromString(up_cnx_state->valuestring); } cJSON *n2_sm_info = cJSON_GetObjectItemCaseSensitive(sm_context_created_dataJSON, "n2SmInfo"); @@ -293,9 +283,13 @@ OpenAPI_sm_context_created_data_t *OpenAPI_sm_context_created_data_parseFromJSON cJSON *ho_state = cJSON_GetObjectItemCaseSensitive(sm_context_created_dataJSON, "hoState"); - OpenAPI_ho_state_t *ho_state_local_nonprim = NULL; + OpenAPI_ho_state_e ho_stateVariable; if (ho_state) { - ho_state_local_nonprim = OpenAPI_ho_state_parseFromJSON(ho_state); + if (!cJSON_IsString(ho_state)) { + ogs_error("OpenAPI_sm_context_created_data_parseFromJSON() failed [ho_state]"); + goto end; + } + ho_stateVariable = OpenAPI_ho_state_FromString(ho_state->valuestring); } cJSON *gpsi = cJSON_GetObjectItemCaseSensitive(sm_context_created_dataJSON, "gpsi"); @@ -339,11 +333,11 @@ OpenAPI_sm_context_created_data_t *OpenAPI_sm_context_created_data_parseFromJSON smf_uri ? ogs_strdup(smf_uri->valuestring) : NULL, pdu_session_id ? pdu_session_id->valuedouble : 0, s_nssai ? s_nssai_local_nonprim : NULL, - up_cnx_state ? up_cnx_state_local_nonprim : NULL, + up_cnx_state ? up_cnx_stateVariable : 0, n2_sm_info ? n2_sm_info_local_nonprim : NULL, n2_sm_info_type ? n2_sm_info_typeVariable : 0, allocated_ebi_list ? allocated_ebi_listList : NULL, - ho_state ? ho_state_local_nonprim : NULL, + ho_state ? ho_stateVariable : 0, gpsi ? ogs_strdup(gpsi->valuestring) : NULL, smf_service_instance_id ? ogs_strdup(smf_service_instance_id->valuestring) : NULL, recovery_time ? ogs_strdup(recovery_time->valuestring) : NULL, diff --git a/lib/sbi/openapi/model/sm_context_created_data.h b/lib/sbi/openapi/model/sm_context_created_data.h index 169f7fae6..8910085c3 100644 --- a/lib/sbi/openapi/model/sm_context_created_data.h +++ b/lib/sbi/openapi/model/sm_context_created_data.h @@ -29,11 +29,11 @@ typedef struct OpenAPI_sm_context_created_data_s { char *smf_uri; int pdu_session_id; struct OpenAPI_snssai_s *s_nssai; - struct OpenAPI_up_cnx_state_s *up_cnx_state; + OpenAPI_up_cnx_state_e up_cnx_state; struct OpenAPI_ref_to_binary_data_s *n2_sm_info; OpenAPI_n2_sm_info_type_e n2_sm_info_type; OpenAPI_list_t *allocated_ebi_list; - struct OpenAPI_ho_state_s *ho_state; + OpenAPI_ho_state_e ho_state; char *gpsi; char *smf_service_instance_id; char *recovery_time; @@ -45,11 +45,11 @@ OpenAPI_sm_context_created_data_t *OpenAPI_sm_context_created_data_create( char *smf_uri, int pdu_session_id, OpenAPI_snssai_t *s_nssai, - OpenAPI_up_cnx_state_t *up_cnx_state, + OpenAPI_up_cnx_state_e up_cnx_state, OpenAPI_ref_to_binary_data_t *n2_sm_info, OpenAPI_n2_sm_info_type_e n2_sm_info_type, OpenAPI_list_t *allocated_ebi_list, - OpenAPI_ho_state_t *ho_state, + OpenAPI_ho_state_e ho_state, char *gpsi, char *smf_service_instance_id, char *recovery_time, diff --git a/lib/sbi/openapi/model/sm_context_release_data.c b/lib/sbi/openapi/model/sm_context_release_data.c index f8a0bba8d..fa515e0f0 100644 --- a/lib/sbi/openapi/model/sm_context_release_data.c +++ b/lib/sbi/openapi/model/sm_context_release_data.c @@ -5,7 +5,7 @@ #include "sm_context_release_data.h" OpenAPI_sm_context_release_data_t *OpenAPI_sm_context_release_data_create( - OpenAPI_cause_t *cause, + OpenAPI_cause_e cause, OpenAPI_ng_ap_cause_t *ng_ap_cause, int _5g_mm_cause_value, OpenAPI_user_location_t *ue_location, @@ -41,7 +41,6 @@ void OpenAPI_sm_context_release_data_free(OpenAPI_sm_context_release_data_t *sm_ return; } OpenAPI_lnode_t *node; - OpenAPI_cause_free(sm_context_release_data->cause); OpenAPI_ng_ap_cause_free(sm_context_release_data->ng_ap_cause); OpenAPI_user_location_free(sm_context_release_data->ue_location); ogs_free(sm_context_release_data->ue_time_zone); @@ -61,13 +60,7 @@ cJSON *OpenAPI_sm_context_release_data_convertToJSON(OpenAPI_sm_context_release_ item = cJSON_CreateObject(); if (sm_context_release_data->cause) { - cJSON *cause_local_JSON = OpenAPI_cause_convertToJSON(sm_context_release_data->cause); - if (cause_local_JSON == NULL) { - ogs_error("OpenAPI_sm_context_release_data_convertToJSON() failed [cause]"); - goto end; - } - cJSON_AddItemToObject(item, "cause", cause_local_JSON); - if (item->child == NULL) { + if (cJSON_AddStringToObject(item, "cause", OpenAPI_cause_ToString(sm_context_release_data->cause)) == NULL) { ogs_error("OpenAPI_sm_context_release_data_convertToJSON() failed [cause]"); goto end; } @@ -169,9 +162,13 @@ OpenAPI_sm_context_release_data_t *OpenAPI_sm_context_release_data_parseFromJSON OpenAPI_sm_context_release_data_t *sm_context_release_data_local_var = NULL; cJSON *cause = cJSON_GetObjectItemCaseSensitive(sm_context_release_dataJSON, "cause"); - OpenAPI_cause_t *cause_local_nonprim = NULL; + OpenAPI_cause_e causeVariable; if (cause) { - cause_local_nonprim = OpenAPI_cause_parseFromJSON(cause); + if (!cJSON_IsString(cause)) { + ogs_error("OpenAPI_sm_context_release_data_parseFromJSON() failed [cause]"); + goto end; + } + causeVariable = OpenAPI_cause_FromString(cause->valuestring); } cJSON *ng_ap_cause = cJSON_GetObjectItemCaseSensitive(sm_context_release_dataJSON, "ngApCause"); @@ -250,7 +247,7 @@ OpenAPI_sm_context_release_data_t *OpenAPI_sm_context_release_data_parseFromJSON } sm_context_release_data_local_var = OpenAPI_sm_context_release_data_create ( - cause ? cause_local_nonprim : NULL, + cause ? causeVariable : 0, ng_ap_cause ? ng_ap_cause_local_nonprim : NULL, _5g_mm_cause_value ? _5g_mm_cause_value->valuedouble : 0, ue_location ? ue_location_local_nonprim : NULL, diff --git a/lib/sbi/openapi/model/sm_context_release_data.h b/lib/sbi/openapi/model/sm_context_release_data.h index f605d1b32..6445af029 100644 --- a/lib/sbi/openapi/model/sm_context_release_data.h +++ b/lib/sbi/openapi/model/sm_context_release_data.h @@ -24,7 +24,7 @@ extern "C" { typedef struct OpenAPI_sm_context_release_data_s OpenAPI_sm_context_release_data_t; typedef struct OpenAPI_sm_context_release_data_s { - struct OpenAPI_cause_s *cause; + OpenAPI_cause_e cause; struct OpenAPI_ng_ap_cause_s *ng_ap_cause; int _5g_mm_cause_value; struct OpenAPI_user_location_s *ue_location; @@ -37,7 +37,7 @@ typedef struct OpenAPI_sm_context_release_data_s { } OpenAPI_sm_context_release_data_t; OpenAPI_sm_context_release_data_t *OpenAPI_sm_context_release_data_create( - OpenAPI_cause_t *cause, + OpenAPI_cause_e cause, OpenAPI_ng_ap_cause_t *ng_ap_cause, int _5g_mm_cause_value, OpenAPI_user_location_t *ue_location, diff --git a/lib/sbi/openapi/model/sm_context_retrieve_data.c b/lib/sbi/openapi/model/sm_context_retrieve_data.c index 500e30657..6dfdaa8ce 100644 --- a/lib/sbi/openapi/model/sm_context_retrieve_data.c +++ b/lib/sbi/openapi/model/sm_context_retrieve_data.c @@ -6,7 +6,7 @@ OpenAPI_sm_context_retrieve_data_t *OpenAPI_sm_context_retrieve_data_create( OpenAPI_mme_capabilities_t *target_mme_cap, - OpenAPI_sm_context_type_t *sm_context_type, + OpenAPI_sm_context_type_e sm_context_type, OpenAPI_plmn_id_t *serving_network, OpenAPI_list_t *not_to_transfer_ebi_list ) @@ -30,7 +30,6 @@ void OpenAPI_sm_context_retrieve_data_free(OpenAPI_sm_context_retrieve_data_t *s } OpenAPI_lnode_t *node; OpenAPI_mme_capabilities_free(sm_context_retrieve_data->target_mme_cap); - OpenAPI_sm_context_type_free(sm_context_retrieve_data->sm_context_type); OpenAPI_plmn_id_free(sm_context_retrieve_data->serving_network); OpenAPI_list_for_each(sm_context_retrieve_data->not_to_transfer_ebi_list, node) { ogs_free(node->data); @@ -63,13 +62,7 @@ cJSON *OpenAPI_sm_context_retrieve_data_convertToJSON(OpenAPI_sm_context_retriev } if (sm_context_retrieve_data->sm_context_type) { - cJSON *sm_context_type_local_JSON = OpenAPI_sm_context_type_convertToJSON(sm_context_retrieve_data->sm_context_type); - if (sm_context_type_local_JSON == NULL) { - ogs_error("OpenAPI_sm_context_retrieve_data_convertToJSON() failed [sm_context_type]"); - goto end; - } - cJSON_AddItemToObject(item, "smContextType", sm_context_type_local_JSON); - if (item->child == NULL) { + if (cJSON_AddStringToObject(item, "smContextType", OpenAPI_sm_context_type_ToString(sm_context_retrieve_data->sm_context_type)) == NULL) { ogs_error("OpenAPI_sm_context_retrieve_data_convertToJSON() failed [sm_context_type]"); goto end; } @@ -120,9 +113,13 @@ OpenAPI_sm_context_retrieve_data_t *OpenAPI_sm_context_retrieve_data_parseFromJS cJSON *sm_context_type = cJSON_GetObjectItemCaseSensitive(sm_context_retrieve_dataJSON, "smContextType"); - OpenAPI_sm_context_type_t *sm_context_type_local_nonprim = NULL; + OpenAPI_sm_context_type_e sm_context_typeVariable; if (sm_context_type) { - sm_context_type_local_nonprim = OpenAPI_sm_context_type_parseFromJSON(sm_context_type); + if (!cJSON_IsString(sm_context_type)) { + ogs_error("OpenAPI_sm_context_retrieve_data_parseFromJSON() failed [sm_context_type]"); + goto end; + } + sm_context_typeVariable = OpenAPI_sm_context_type_FromString(sm_context_type->valuestring); } cJSON *serving_network = cJSON_GetObjectItemCaseSensitive(sm_context_retrieve_dataJSON, "servingNetwork"); @@ -154,7 +151,7 @@ OpenAPI_sm_context_retrieve_data_t *OpenAPI_sm_context_retrieve_data_parseFromJS sm_context_retrieve_data_local_var = OpenAPI_sm_context_retrieve_data_create ( target_mme_cap ? target_mme_cap_local_nonprim : NULL, - sm_context_type ? sm_context_type_local_nonprim : NULL, + sm_context_type ? sm_context_typeVariable : 0, serving_network ? serving_network_local_nonprim : NULL, not_to_transfer_ebi_list ? not_to_transfer_ebi_listList : NULL ); diff --git a/lib/sbi/openapi/model/sm_context_retrieve_data.h b/lib/sbi/openapi/model/sm_context_retrieve_data.h index da652e1ee..37a01a308 100644 --- a/lib/sbi/openapi/model/sm_context_retrieve_data.h +++ b/lib/sbi/openapi/model/sm_context_retrieve_data.h @@ -23,14 +23,14 @@ extern "C" { typedef struct OpenAPI_sm_context_retrieve_data_s OpenAPI_sm_context_retrieve_data_t; typedef struct OpenAPI_sm_context_retrieve_data_s { struct OpenAPI_mme_capabilities_s *target_mme_cap; - struct OpenAPI_sm_context_type_s *sm_context_type; + OpenAPI_sm_context_type_e sm_context_type; struct OpenAPI_plmn_id_s *serving_network; OpenAPI_list_t *not_to_transfer_ebi_list; } OpenAPI_sm_context_retrieve_data_t; OpenAPI_sm_context_retrieve_data_t *OpenAPI_sm_context_retrieve_data_create( OpenAPI_mme_capabilities_t *target_mme_cap, - OpenAPI_sm_context_type_t *sm_context_type, + OpenAPI_sm_context_type_e sm_context_type, OpenAPI_plmn_id_t *serving_network, OpenAPI_list_t *not_to_transfer_ebi_list ); diff --git a/lib/sbi/openapi/model/sm_context_type.c b/lib/sbi/openapi/model/sm_context_type.c index 9bf8e8bed..e0f54845a 100644 --- a/lib/sbi/openapi/model/sm_context_type.c +++ b/lib/sbi/openapi/model/sm_context_type.c @@ -4,82 +4,27 @@ #include #include "sm_context_type.h" -OpenAPI_sm_context_type_t *OpenAPI_sm_context_type_create( - ) +char* OpenAPI_sm_context_type_ToString(OpenAPI_sm_context_type_e sm_context_type) { - OpenAPI_sm_context_type_t *sm_context_type_local_var = OpenAPI_malloc(sizeof(OpenAPI_sm_context_type_t)); - if (!sm_context_type_local_var) { - return NULL; - } - - return sm_context_type_local_var; + const char *sm_context_typeArray[] = { "NULL", "EPS_PDN_CONNECTION", "SM_CONTEXT" }; + size_t sizeofArray = sizeof(sm_context_typeArray) / sizeof(sm_context_typeArray[0]); + if (sm_context_type < sizeofArray) + return (char *)sm_context_typeArray[sm_context_type]; + else + return (char *)"Unknown"; } -void OpenAPI_sm_context_type_free(OpenAPI_sm_context_type_t *sm_context_type) +OpenAPI_sm_context_type_e OpenAPI_sm_context_type_FromString(char* sm_context_type) { - if (NULL == sm_context_type) { - return; + int stringToReturn = 0; + const char *sm_context_typeArray[] = { "NULL", "EPS_PDN_CONNECTION", "SM_CONTEXT" }; + size_t sizeofArray = sizeof(sm_context_typeArray) / sizeof(sm_context_typeArray[0]); + while (stringToReturn < sizeofArray) { + if (strcmp(sm_context_type, sm_context_typeArray[stringToReturn]) == 0) { + return stringToReturn; + } + stringToReturn++; } - OpenAPI_lnode_t *node; - ogs_free(sm_context_type); -} - -cJSON *OpenAPI_sm_context_type_convertToJSON(OpenAPI_sm_context_type_t *sm_context_type) -{ - cJSON *item = NULL; - - if (sm_context_type == NULL) { - ogs_error("OpenAPI_sm_context_type_convertToJSON() failed [SmContextType]"); - return NULL; - } - - item = cJSON_CreateObject(); -end: - return item; -} - -OpenAPI_sm_context_type_t *OpenAPI_sm_context_type_parseFromJSON(cJSON *sm_context_typeJSON) -{ - OpenAPI_sm_context_type_t *sm_context_type_local_var = NULL; - sm_context_type_local_var = OpenAPI_sm_context_type_create ( - ); - - return sm_context_type_local_var; -end: - return NULL; -} - -OpenAPI_sm_context_type_t *OpenAPI_sm_context_type_copy(OpenAPI_sm_context_type_t *dst, OpenAPI_sm_context_type_t *src) -{ - cJSON *item = NULL; - char *content = NULL; - - ogs_assert(src); - item = OpenAPI_sm_context_type_convertToJSON(src); - if (!item) { - ogs_error("OpenAPI_sm_context_type_convertToJSON() failed"); - return NULL; - } - - content = cJSON_Print(item); - cJSON_Delete(item); - - if (!content) { - ogs_error("cJSON_Print() failed"); - return NULL; - } - - item = cJSON_Parse(content); - ogs_free(content); - if (!item) { - ogs_error("cJSON_Parse() failed"); - return NULL; - } - - OpenAPI_sm_context_type_free(dst); - dst = OpenAPI_sm_context_type_parseFromJSON(item); - cJSON_Delete(item); - - return dst; + return 0; } diff --git a/lib/sbi/openapi/model/sm_context_type.h b/lib/sbi/openapi/model/sm_context_type.h index 34a638c8f..2e38aa725 100644 --- a/lib/sbi/openapi/model/sm_context_type.h +++ b/lib/sbi/openapi/model/sm_context_type.h @@ -1,7 +1,7 @@ /* * sm_context_type.h * - * Possible values are - EPS_PDN_CONNECTION - SM_CONTEXT + * */ #ifndef _OpenAPI_sm_context_type_H_ @@ -17,16 +17,11 @@ extern "C" { #endif -typedef struct OpenAPI_sm_context_type_s OpenAPI_sm_context_type_t; -typedef struct OpenAPI_sm_context_type_s { -} OpenAPI_sm_context_type_t; +typedef enum { OpenAPI_sm_context_type_NULL = 0, OpenAPI_sm_context_type_EPS_PDN_CONNECTION, OpenAPI_sm_context_type_SM_CONTEXT } OpenAPI_sm_context_type_e; -OpenAPI_sm_context_type_t *OpenAPI_sm_context_type_create( - ); -void OpenAPI_sm_context_type_free(OpenAPI_sm_context_type_t *sm_context_type); -OpenAPI_sm_context_type_t *OpenAPI_sm_context_type_parseFromJSON(cJSON *sm_context_typeJSON); -cJSON *OpenAPI_sm_context_type_convertToJSON(OpenAPI_sm_context_type_t *sm_context_type); -OpenAPI_sm_context_type_t *OpenAPI_sm_context_type_copy(OpenAPI_sm_context_type_t *dst, OpenAPI_sm_context_type_t *src); +char* OpenAPI_sm_context_type_ToString(OpenAPI_sm_context_type_e sm_context_type); + +OpenAPI_sm_context_type_e OpenAPI_sm_context_type_FromString(char* sm_context_type); #ifdef __cplusplus } diff --git a/lib/sbi/openapi/model/sm_context_update_data.c b/lib/sbi/openapi/model/sm_context_update_data.c index 46e8550db..69011a844 100644 --- a/lib/sbi/openapi/model/sm_context_update_data.c +++ b/lib/sbi/openapi/model/sm_context_update_data.c @@ -17,8 +17,8 @@ OpenAPI_sm_context_update_data_t *OpenAPI_sm_context_update_data_create( OpenAPI_user_location_t *ue_location, char *ue_time_zone, OpenAPI_user_location_t *add_ue_location, - OpenAPI_up_cnx_state_t *up_cnx_state, - OpenAPI_ho_state_t *ho_state, + OpenAPI_up_cnx_state_e up_cnx_state, + OpenAPI_ho_state_e ho_state, int to_be_switched, int failed_to_be_switched, OpenAPI_ref_to_binary_data_t *n1_sm_msg, @@ -34,16 +34,16 @@ OpenAPI_sm_context_update_data_t *OpenAPI_sm_context_update_data_create( OpenAPI_list_t *eps_bearer_setup, OpenAPI_list_t *revoke_ebi_list, int release, - OpenAPI_cause_t *cause, + OpenAPI_cause_e cause, OpenAPI_ng_ap_cause_t *ng_ap_cause, int _5g_mm_cause_value, OpenAPI_snssai_t *s_nssai, OpenAPI_trace_data_t *trace_data, - OpenAPI_eps_interworking_indication_t *eps_interworking_ind, + OpenAPI_eps_interworking_indication_e eps_interworking_ind, int an_type_can_be_changed, OpenAPI_ref_to_binary_data_t *n2_sm_info_ext1, OpenAPI_n2_sm_info_type_e n2_sm_info_type_ext1, - OpenAPI_ma_release_indication_t *ma_release_ind, + OpenAPI_ma_release_indication_e ma_release_ind, int ma_nw_upgrade_ind, int ma_request_ind, OpenAPI_exemption_ind_t *exemption_ind, @@ -131,8 +131,6 @@ void OpenAPI_sm_context_update_data_free(OpenAPI_sm_context_update_data_t *sm_co OpenAPI_user_location_free(sm_context_update_data->ue_location); ogs_free(sm_context_update_data->ue_time_zone); OpenAPI_user_location_free(sm_context_update_data->add_ue_location); - OpenAPI_up_cnx_state_free(sm_context_update_data->up_cnx_state); - OpenAPI_ho_state_free(sm_context_update_data->ho_state); OpenAPI_ref_to_binary_data_free(sm_context_update_data->n1_sm_msg); OpenAPI_ref_to_binary_data_free(sm_context_update_data->n2_sm_info); OpenAPI_ng_ran_target_id_free(sm_context_update_data->target_id); @@ -155,13 +153,10 @@ void OpenAPI_sm_context_update_data_free(OpenAPI_sm_context_update_data_t *sm_co ogs_free(node->data); } OpenAPI_list_free(sm_context_update_data->revoke_ebi_list); - OpenAPI_cause_free(sm_context_update_data->cause); OpenAPI_ng_ap_cause_free(sm_context_update_data->ng_ap_cause); OpenAPI_snssai_free(sm_context_update_data->s_nssai); OpenAPI_trace_data_free(sm_context_update_data->trace_data); - OpenAPI_eps_interworking_indication_free(sm_context_update_data->eps_interworking_ind); OpenAPI_ref_to_binary_data_free(sm_context_update_data->n2_sm_info_ext1); - OpenAPI_ma_release_indication_free(sm_context_update_data->ma_release_ind); OpenAPI_exemption_ind_free(sm_context_update_data->exemption_ind); ogs_free(sm_context_update_data->supported_features); OpenAPI_mo_exception_data_flag_free(sm_context_update_data->mo_exp_data_ind); @@ -312,26 +307,14 @@ cJSON *OpenAPI_sm_context_update_data_convertToJSON(OpenAPI_sm_context_update_da } if (sm_context_update_data->up_cnx_state) { - cJSON *up_cnx_state_local_JSON = OpenAPI_up_cnx_state_convertToJSON(sm_context_update_data->up_cnx_state); - if (up_cnx_state_local_JSON == NULL) { - ogs_error("OpenAPI_sm_context_update_data_convertToJSON() failed [up_cnx_state]"); - goto end; - } - cJSON_AddItemToObject(item, "upCnxState", up_cnx_state_local_JSON); - if (item->child == NULL) { + if (cJSON_AddStringToObject(item, "upCnxState", OpenAPI_up_cnx_state_ToString(sm_context_update_data->up_cnx_state)) == NULL) { ogs_error("OpenAPI_sm_context_update_data_convertToJSON() failed [up_cnx_state]"); goto end; } } if (sm_context_update_data->ho_state) { - cJSON *ho_state_local_JSON = OpenAPI_ho_state_convertToJSON(sm_context_update_data->ho_state); - if (ho_state_local_JSON == NULL) { - ogs_error("OpenAPI_sm_context_update_data_convertToJSON() failed [ho_state]"); - goto end; - } - cJSON_AddItemToObject(item, "hoState", ho_state_local_JSON); - if (item->child == NULL) { + if (cJSON_AddStringToObject(item, "hoState", OpenAPI_ho_state_ToString(sm_context_update_data->ho_state)) == NULL) { ogs_error("OpenAPI_sm_context_update_data_convertToJSON() failed [ho_state]"); goto end; } @@ -511,13 +494,7 @@ cJSON *OpenAPI_sm_context_update_data_convertToJSON(OpenAPI_sm_context_update_da } if (sm_context_update_data->cause) { - cJSON *cause_local_JSON = OpenAPI_cause_convertToJSON(sm_context_update_data->cause); - if (cause_local_JSON == NULL) { - ogs_error("OpenAPI_sm_context_update_data_convertToJSON() failed [cause]"); - goto end; - } - cJSON_AddItemToObject(item, "cause", cause_local_JSON); - if (item->child == NULL) { + if (cJSON_AddStringToObject(item, "cause", OpenAPI_cause_ToString(sm_context_update_data->cause)) == NULL) { ogs_error("OpenAPI_sm_context_update_data_convertToJSON() failed [cause]"); goto end; } @@ -570,13 +547,7 @@ cJSON *OpenAPI_sm_context_update_data_convertToJSON(OpenAPI_sm_context_update_da } if (sm_context_update_data->eps_interworking_ind) { - cJSON *eps_interworking_ind_local_JSON = OpenAPI_eps_interworking_indication_convertToJSON(sm_context_update_data->eps_interworking_ind); - if (eps_interworking_ind_local_JSON == NULL) { - ogs_error("OpenAPI_sm_context_update_data_convertToJSON() failed [eps_interworking_ind]"); - goto end; - } - cJSON_AddItemToObject(item, "epsInterworkingInd", eps_interworking_ind_local_JSON); - if (item->child == NULL) { + if (cJSON_AddStringToObject(item, "epsInterworkingInd", OpenAPI_eps_interworking_indication_ToString(sm_context_update_data->eps_interworking_ind)) == NULL) { ogs_error("OpenAPI_sm_context_update_data_convertToJSON() failed [eps_interworking_ind]"); goto end; } @@ -610,13 +581,7 @@ cJSON *OpenAPI_sm_context_update_data_convertToJSON(OpenAPI_sm_context_update_da } if (sm_context_update_data->ma_release_ind) { - cJSON *ma_release_ind_local_JSON = OpenAPI_ma_release_indication_convertToJSON(sm_context_update_data->ma_release_ind); - if (ma_release_ind_local_JSON == NULL) { - ogs_error("OpenAPI_sm_context_update_data_convertToJSON() failed [ma_release_ind]"); - goto end; - } - cJSON_AddItemToObject(item, "maReleaseInd", ma_release_ind_local_JSON); - if (item->child == NULL) { + if (cJSON_AddStringToObject(item, "maReleaseInd", OpenAPI_ma_release_indication_ToString(sm_context_update_data->ma_release_ind)) == NULL) { ogs_error("OpenAPI_sm_context_update_data_convertToJSON() failed [ma_release_ind]"); goto end; } @@ -852,16 +817,24 @@ OpenAPI_sm_context_update_data_t *OpenAPI_sm_context_update_data_parseFromJSON(c cJSON *up_cnx_state = cJSON_GetObjectItemCaseSensitive(sm_context_update_dataJSON, "upCnxState"); - OpenAPI_up_cnx_state_t *up_cnx_state_local_nonprim = NULL; + OpenAPI_up_cnx_state_e up_cnx_stateVariable; if (up_cnx_state) { - up_cnx_state_local_nonprim = OpenAPI_up_cnx_state_parseFromJSON(up_cnx_state); + if (!cJSON_IsString(up_cnx_state)) { + ogs_error("OpenAPI_sm_context_update_data_parseFromJSON() failed [up_cnx_state]"); + goto end; + } + up_cnx_stateVariable = OpenAPI_up_cnx_state_FromString(up_cnx_state->valuestring); } cJSON *ho_state = cJSON_GetObjectItemCaseSensitive(sm_context_update_dataJSON, "hoState"); - OpenAPI_ho_state_t *ho_state_local_nonprim = NULL; + OpenAPI_ho_state_e ho_stateVariable; if (ho_state) { - ho_state_local_nonprim = OpenAPI_ho_state_parseFromJSON(ho_state); + if (!cJSON_IsString(ho_state)) { + ogs_error("OpenAPI_sm_context_update_data_parseFromJSON() failed [ho_state]"); + goto end; + } + ho_stateVariable = OpenAPI_ho_state_FromString(ho_state->valuestring); } cJSON *to_be_switched = cJSON_GetObjectItemCaseSensitive(sm_context_update_dataJSON, "toBeSwitched"); @@ -1045,9 +1018,13 @@ OpenAPI_sm_context_update_data_t *OpenAPI_sm_context_update_data_parseFromJSON(c cJSON *cause = cJSON_GetObjectItemCaseSensitive(sm_context_update_dataJSON, "cause"); - OpenAPI_cause_t *cause_local_nonprim = NULL; + OpenAPI_cause_e causeVariable; if (cause) { - cause_local_nonprim = OpenAPI_cause_parseFromJSON(cause); + if (!cJSON_IsString(cause)) { + ogs_error("OpenAPI_sm_context_update_data_parseFromJSON() failed [cause]"); + goto end; + } + causeVariable = OpenAPI_cause_FromString(cause->valuestring); } cJSON *ng_ap_cause = cJSON_GetObjectItemCaseSensitive(sm_context_update_dataJSON, "ngApCause"); @@ -1082,9 +1059,13 @@ OpenAPI_sm_context_update_data_t *OpenAPI_sm_context_update_data_parseFromJSON(c cJSON *eps_interworking_ind = cJSON_GetObjectItemCaseSensitive(sm_context_update_dataJSON, "epsInterworkingInd"); - OpenAPI_eps_interworking_indication_t *eps_interworking_ind_local_nonprim = NULL; + OpenAPI_eps_interworking_indication_e eps_interworking_indVariable; if (eps_interworking_ind) { - eps_interworking_ind_local_nonprim = OpenAPI_eps_interworking_indication_parseFromJSON(eps_interworking_ind); + if (!cJSON_IsString(eps_interworking_ind)) { + ogs_error("OpenAPI_sm_context_update_data_parseFromJSON() failed [eps_interworking_ind]"); + goto end; + } + eps_interworking_indVariable = OpenAPI_eps_interworking_indication_FromString(eps_interworking_ind->valuestring); } cJSON *an_type_can_be_changed = cJSON_GetObjectItemCaseSensitive(sm_context_update_dataJSON, "anTypeCanBeChanged"); @@ -1116,9 +1097,13 @@ OpenAPI_sm_context_update_data_t *OpenAPI_sm_context_update_data_parseFromJSON(c cJSON *ma_release_ind = cJSON_GetObjectItemCaseSensitive(sm_context_update_dataJSON, "maReleaseInd"); - OpenAPI_ma_release_indication_t *ma_release_ind_local_nonprim = NULL; + OpenAPI_ma_release_indication_e ma_release_indVariable; if (ma_release_ind) { - ma_release_ind_local_nonprim = OpenAPI_ma_release_indication_parseFromJSON(ma_release_ind); + if (!cJSON_IsString(ma_release_ind)) { + ogs_error("OpenAPI_sm_context_update_data_parseFromJSON() failed [ma_release_ind]"); + goto end; + } + ma_release_indVariable = OpenAPI_ma_release_indication_FromString(ma_release_ind->valuestring); } cJSON *ma_nw_upgrade_ind = cJSON_GetObjectItemCaseSensitive(sm_context_update_dataJSON, "maNwUpgradeInd"); @@ -1227,8 +1212,8 @@ OpenAPI_sm_context_update_data_t *OpenAPI_sm_context_update_data_parseFromJSON(c ue_location ? ue_location_local_nonprim : NULL, ue_time_zone ? ogs_strdup(ue_time_zone->valuestring) : NULL, add_ue_location ? add_ue_location_local_nonprim : NULL, - up_cnx_state ? up_cnx_state_local_nonprim : NULL, - ho_state ? ho_state_local_nonprim : NULL, + up_cnx_state ? up_cnx_stateVariable : 0, + ho_state ? ho_stateVariable : 0, to_be_switched ? to_be_switched->valueint : 0, failed_to_be_switched ? failed_to_be_switched->valueint : 0, n1_sm_msg ? n1_sm_msg_local_nonprim : NULL, @@ -1244,16 +1229,16 @@ OpenAPI_sm_context_update_data_t *OpenAPI_sm_context_update_data_parseFromJSON(c eps_bearer_setup ? eps_bearer_setupList : NULL, revoke_ebi_list ? revoke_ebi_listList : NULL, release ? release->valueint : 0, - cause ? cause_local_nonprim : NULL, + cause ? causeVariable : 0, ng_ap_cause ? ng_ap_cause_local_nonprim : NULL, _5g_mm_cause_value ? _5g_mm_cause_value->valuedouble : 0, s_nssai ? s_nssai_local_nonprim : NULL, trace_data ? trace_data_local_nonprim : NULL, - eps_interworking_ind ? eps_interworking_ind_local_nonprim : NULL, + eps_interworking_ind ? eps_interworking_indVariable : 0, an_type_can_be_changed ? an_type_can_be_changed->valueint : 0, n2_sm_info_ext1 ? n2_sm_info_ext1_local_nonprim : NULL, n2_sm_info_type_ext1 ? n2_sm_info_type_ext1Variable : 0, - ma_release_ind ? ma_release_ind_local_nonprim : NULL, + ma_release_ind ? ma_release_indVariable : 0, ma_nw_upgrade_ind ? ma_nw_upgrade_ind->valueint : 0, ma_request_ind ? ma_request_ind->valueint : 0, exemption_ind ? exemption_ind_local_nonprim : NULL, diff --git a/lib/sbi/openapi/model/sm_context_update_data.h b/lib/sbi/openapi/model/sm_context_update_data.h index 609d29716..7f3a1665f 100644 --- a/lib/sbi/openapi/model/sm_context_update_data.h +++ b/lib/sbi/openapi/model/sm_context_update_data.h @@ -55,8 +55,8 @@ typedef struct OpenAPI_sm_context_update_data_s { struct OpenAPI_user_location_s *ue_location; char *ue_time_zone; struct OpenAPI_user_location_s *add_ue_location; - struct OpenAPI_up_cnx_state_s *up_cnx_state; - struct OpenAPI_ho_state_s *ho_state; + OpenAPI_up_cnx_state_e up_cnx_state; + OpenAPI_ho_state_e ho_state; int to_be_switched; int failed_to_be_switched; struct OpenAPI_ref_to_binary_data_s *n1_sm_msg; @@ -72,16 +72,16 @@ typedef struct OpenAPI_sm_context_update_data_s { OpenAPI_list_t *eps_bearer_setup; OpenAPI_list_t *revoke_ebi_list; int release; - struct OpenAPI_cause_s *cause; + OpenAPI_cause_e cause; struct OpenAPI_ng_ap_cause_s *ng_ap_cause; int _5g_mm_cause_value; struct OpenAPI_snssai_s *s_nssai; struct OpenAPI_trace_data_s *trace_data; - struct OpenAPI_eps_interworking_indication_s *eps_interworking_ind; + OpenAPI_eps_interworking_indication_e eps_interworking_ind; int an_type_can_be_changed; struct OpenAPI_ref_to_binary_data_s *n2_sm_info_ext1; OpenAPI_n2_sm_info_type_e n2_sm_info_type_ext1; - struct OpenAPI_ma_release_indication_s *ma_release_ind; + OpenAPI_ma_release_indication_e ma_release_ind; int ma_nw_upgrade_ind; int ma_request_ind; struct OpenAPI_exemption_ind_s *exemption_ind; @@ -107,8 +107,8 @@ OpenAPI_sm_context_update_data_t *OpenAPI_sm_context_update_data_create( OpenAPI_user_location_t *ue_location, char *ue_time_zone, OpenAPI_user_location_t *add_ue_location, - OpenAPI_up_cnx_state_t *up_cnx_state, - OpenAPI_ho_state_t *ho_state, + OpenAPI_up_cnx_state_e up_cnx_state, + OpenAPI_ho_state_e ho_state, int to_be_switched, int failed_to_be_switched, OpenAPI_ref_to_binary_data_t *n1_sm_msg, @@ -124,16 +124,16 @@ OpenAPI_sm_context_update_data_t *OpenAPI_sm_context_update_data_create( OpenAPI_list_t *eps_bearer_setup, OpenAPI_list_t *revoke_ebi_list, int release, - OpenAPI_cause_t *cause, + OpenAPI_cause_e cause, OpenAPI_ng_ap_cause_t *ng_ap_cause, int _5g_mm_cause_value, OpenAPI_snssai_t *s_nssai, OpenAPI_trace_data_t *trace_data, - OpenAPI_eps_interworking_indication_t *eps_interworking_ind, + OpenAPI_eps_interworking_indication_e eps_interworking_ind, int an_type_can_be_changed, OpenAPI_ref_to_binary_data_t *n2_sm_info_ext1, OpenAPI_n2_sm_info_type_e n2_sm_info_type_ext1, - OpenAPI_ma_release_indication_t *ma_release_ind, + OpenAPI_ma_release_indication_e ma_release_ind, int ma_nw_upgrade_ind, int ma_request_ind, OpenAPI_exemption_ind_t *exemption_ind, diff --git a/lib/sbi/openapi/model/sm_context_update_error.c b/lib/sbi/openapi/model/sm_context_update_error.c index cdab853a6..365f11275 100644 --- a/lib/sbi/openapi/model/sm_context_update_error.c +++ b/lib/sbi/openapi/model/sm_context_update_error.c @@ -9,7 +9,7 @@ OpenAPI_sm_context_update_error_t *OpenAPI_sm_context_update_error_create( OpenAPI_ref_to_binary_data_t *n1_sm_msg, OpenAPI_ref_to_binary_data_t *n2_sm_info, OpenAPI_n2_sm_info_type_e n2_sm_info_type, - OpenAPI_up_cnx_state_t *up_cnx_state, + OpenAPI_up_cnx_state_e up_cnx_state, char *recovery_time ) { @@ -36,7 +36,6 @@ void OpenAPI_sm_context_update_error_free(OpenAPI_sm_context_update_error_t *sm_ OpenAPI_problem_details_free(sm_context_update_error->error); OpenAPI_ref_to_binary_data_free(sm_context_update_error->n1_sm_msg); OpenAPI_ref_to_binary_data_free(sm_context_update_error->n2_sm_info); - OpenAPI_up_cnx_state_free(sm_context_update_error->up_cnx_state); ogs_free(sm_context_update_error->recovery_time); ogs_free(sm_context_update_error); } @@ -100,13 +99,7 @@ cJSON *OpenAPI_sm_context_update_error_convertToJSON(OpenAPI_sm_context_update_e } if (sm_context_update_error->up_cnx_state) { - cJSON *up_cnx_state_local_JSON = OpenAPI_up_cnx_state_convertToJSON(sm_context_update_error->up_cnx_state); - if (up_cnx_state_local_JSON == NULL) { - ogs_error("OpenAPI_sm_context_update_error_convertToJSON() failed [up_cnx_state]"); - goto end; - } - cJSON_AddItemToObject(item, "upCnxState", up_cnx_state_local_JSON); - if (item->child == NULL) { + if (cJSON_AddStringToObject(item, "upCnxState", OpenAPI_up_cnx_state_ToString(sm_context_update_error->up_cnx_state)) == NULL) { ogs_error("OpenAPI_sm_context_update_error_convertToJSON() failed [up_cnx_state]"); goto end; } @@ -163,9 +156,13 @@ OpenAPI_sm_context_update_error_t *OpenAPI_sm_context_update_error_parseFromJSON cJSON *up_cnx_state = cJSON_GetObjectItemCaseSensitive(sm_context_update_errorJSON, "upCnxState"); - OpenAPI_up_cnx_state_t *up_cnx_state_local_nonprim = NULL; + OpenAPI_up_cnx_state_e up_cnx_stateVariable; if (up_cnx_state) { - up_cnx_state_local_nonprim = OpenAPI_up_cnx_state_parseFromJSON(up_cnx_state); + if (!cJSON_IsString(up_cnx_state)) { + ogs_error("OpenAPI_sm_context_update_error_parseFromJSON() failed [up_cnx_state]"); + goto end; + } + up_cnx_stateVariable = OpenAPI_up_cnx_state_FromString(up_cnx_state->valuestring); } cJSON *recovery_time = cJSON_GetObjectItemCaseSensitive(sm_context_update_errorJSON, "recoveryTime"); @@ -182,7 +179,7 @@ OpenAPI_sm_context_update_error_t *OpenAPI_sm_context_update_error_parseFromJSON n1_sm_msg ? n1_sm_msg_local_nonprim : NULL, n2_sm_info ? n2_sm_info_local_nonprim : NULL, n2_sm_info_type ? n2_sm_info_typeVariable : 0, - up_cnx_state ? up_cnx_state_local_nonprim : NULL, + up_cnx_state ? up_cnx_stateVariable : 0, recovery_time ? ogs_strdup(recovery_time->valuestring) : NULL ); diff --git a/lib/sbi/openapi/model/sm_context_update_error.h b/lib/sbi/openapi/model/sm_context_update_error.h index 072d0ceb7..2fcc91ae5 100644 --- a/lib/sbi/openapi/model/sm_context_update_error.h +++ b/lib/sbi/openapi/model/sm_context_update_error.h @@ -27,7 +27,7 @@ typedef struct OpenAPI_sm_context_update_error_s { struct OpenAPI_ref_to_binary_data_s *n1_sm_msg; struct OpenAPI_ref_to_binary_data_s *n2_sm_info; OpenAPI_n2_sm_info_type_e n2_sm_info_type; - struct OpenAPI_up_cnx_state_s *up_cnx_state; + OpenAPI_up_cnx_state_e up_cnx_state; char *recovery_time; } OpenAPI_sm_context_update_error_t; @@ -36,7 +36,7 @@ OpenAPI_sm_context_update_error_t *OpenAPI_sm_context_update_error_create( OpenAPI_ref_to_binary_data_t *n1_sm_msg, OpenAPI_ref_to_binary_data_t *n2_sm_info, OpenAPI_n2_sm_info_type_e n2_sm_info_type, - OpenAPI_up_cnx_state_t *up_cnx_state, + OpenAPI_up_cnx_state_e up_cnx_state, char *recovery_time ); void OpenAPI_sm_context_update_error_free(OpenAPI_sm_context_update_error_t *sm_context_update_error); diff --git a/lib/sbi/openapi/model/sm_context_updated_data.c b/lib/sbi/openapi/model/sm_context_updated_data.c index 915dce745..b6d2f620f 100644 --- a/lib/sbi/openapi/model/sm_context_updated_data.c +++ b/lib/sbi/openapi/model/sm_context_updated_data.c @@ -5,8 +5,8 @@ #include "sm_context_updated_data.h" OpenAPI_sm_context_updated_data_t *OpenAPI_sm_context_updated_data_create( - OpenAPI_up_cnx_state_t *up_cnx_state, - OpenAPI_ho_state_t *ho_state, + OpenAPI_up_cnx_state_e up_cnx_state, + OpenAPI_ho_state_e ho_state, OpenAPI_list_t *release_ebi_list, OpenAPI_list_t *allocated_ebi_list, OpenAPI_list_t *modified_ebi_list, @@ -17,7 +17,7 @@ OpenAPI_sm_context_updated_data_t *OpenAPI_sm_context_updated_data_create( int data_forwarding, OpenAPI_list_t *n3_dl_forwarding_tnl_list, OpenAPI_list_t *n3_ul_forwarding_tnl_list, - OpenAPI_cause_t *cause, + OpenAPI_cause_e cause, int ma_accepted_ind, char *supported_features, char forwarding_f_teid, @@ -55,8 +55,6 @@ void OpenAPI_sm_context_updated_data_free(OpenAPI_sm_context_updated_data_t *sm_ return; } OpenAPI_lnode_t *node; - OpenAPI_up_cnx_state_free(sm_context_updated_data->up_cnx_state); - OpenAPI_ho_state_free(sm_context_updated_data->ho_state); OpenAPI_list_for_each(sm_context_updated_data->release_ebi_list, node) { ogs_free(node->data); } @@ -83,7 +81,6 @@ void OpenAPI_sm_context_updated_data_free(OpenAPI_sm_context_updated_data_t *sm_ OpenAPI_indirect_data_forwarding_tunnel_info_free(node->data); } OpenAPI_list_free(sm_context_updated_data->n3_ul_forwarding_tnl_list); - OpenAPI_cause_free(sm_context_updated_data->cause); ogs_free(sm_context_updated_data->supported_features); OpenAPI_list_for_each(sm_context_updated_data->forwarding_bearer_contexts, node) { ogs_free(node->data); @@ -103,26 +100,14 @@ cJSON *OpenAPI_sm_context_updated_data_convertToJSON(OpenAPI_sm_context_updated_ item = cJSON_CreateObject(); if (sm_context_updated_data->up_cnx_state) { - cJSON *up_cnx_state_local_JSON = OpenAPI_up_cnx_state_convertToJSON(sm_context_updated_data->up_cnx_state); - if (up_cnx_state_local_JSON == NULL) { - ogs_error("OpenAPI_sm_context_updated_data_convertToJSON() failed [up_cnx_state]"); - goto end; - } - cJSON_AddItemToObject(item, "upCnxState", up_cnx_state_local_JSON); - if (item->child == NULL) { + if (cJSON_AddStringToObject(item, "upCnxState", OpenAPI_up_cnx_state_ToString(sm_context_updated_data->up_cnx_state)) == NULL) { ogs_error("OpenAPI_sm_context_updated_data_convertToJSON() failed [up_cnx_state]"); goto end; } } if (sm_context_updated_data->ho_state) { - cJSON *ho_state_local_JSON = OpenAPI_ho_state_convertToJSON(sm_context_updated_data->ho_state); - if (ho_state_local_JSON == NULL) { - ogs_error("OpenAPI_sm_context_updated_data_convertToJSON() failed [ho_state]"); - goto end; - } - cJSON_AddItemToObject(item, "hoState", ho_state_local_JSON); - if (item->child == NULL) { + if (cJSON_AddStringToObject(item, "hoState", OpenAPI_ho_state_ToString(sm_context_updated_data->ho_state)) == NULL) { ogs_error("OpenAPI_sm_context_updated_data_convertToJSON() failed [ho_state]"); goto end; } @@ -281,13 +266,7 @@ cJSON *OpenAPI_sm_context_updated_data_convertToJSON(OpenAPI_sm_context_updated_ } if (sm_context_updated_data->cause) { - cJSON *cause_local_JSON = OpenAPI_cause_convertToJSON(sm_context_updated_data->cause); - if (cause_local_JSON == NULL) { - ogs_error("OpenAPI_sm_context_updated_data_convertToJSON() failed [cause]"); - goto end; - } - cJSON_AddItemToObject(item, "cause", cause_local_JSON); - if (item->child == NULL) { + if (cJSON_AddStringToObject(item, "cause", OpenAPI_cause_ToString(sm_context_updated_data->cause)) == NULL) { ogs_error("OpenAPI_sm_context_updated_data_convertToJSON() failed [cause]"); goto end; } @@ -339,16 +318,24 @@ OpenAPI_sm_context_updated_data_t *OpenAPI_sm_context_updated_data_parseFromJSON OpenAPI_sm_context_updated_data_t *sm_context_updated_data_local_var = NULL; cJSON *up_cnx_state = cJSON_GetObjectItemCaseSensitive(sm_context_updated_dataJSON, "upCnxState"); - OpenAPI_up_cnx_state_t *up_cnx_state_local_nonprim = NULL; + OpenAPI_up_cnx_state_e up_cnx_stateVariable; if (up_cnx_state) { - up_cnx_state_local_nonprim = OpenAPI_up_cnx_state_parseFromJSON(up_cnx_state); + if (!cJSON_IsString(up_cnx_state)) { + ogs_error("OpenAPI_sm_context_updated_data_parseFromJSON() failed [up_cnx_state]"); + goto end; + } + up_cnx_stateVariable = OpenAPI_up_cnx_state_FromString(up_cnx_state->valuestring); } cJSON *ho_state = cJSON_GetObjectItemCaseSensitive(sm_context_updated_dataJSON, "hoState"); - OpenAPI_ho_state_t *ho_state_local_nonprim = NULL; + OpenAPI_ho_state_e ho_stateVariable; if (ho_state) { - ho_state_local_nonprim = OpenAPI_ho_state_parseFromJSON(ho_state); + if (!cJSON_IsString(ho_state)) { + ogs_error("OpenAPI_sm_context_updated_data_parseFromJSON() failed [ho_state]"); + goto end; + } + ho_stateVariable = OpenAPI_ho_state_FromString(ho_state->valuestring); } cJSON *release_ebi_list = cJSON_GetObjectItemCaseSensitive(sm_context_updated_dataJSON, "releaseEbiList"); @@ -519,9 +506,13 @@ OpenAPI_sm_context_updated_data_t *OpenAPI_sm_context_updated_data_parseFromJSON cJSON *cause = cJSON_GetObjectItemCaseSensitive(sm_context_updated_dataJSON, "cause"); - OpenAPI_cause_t *cause_local_nonprim = NULL; + OpenAPI_cause_e causeVariable; if (cause) { - cause_local_nonprim = OpenAPI_cause_parseFromJSON(cause); + if (!cJSON_IsString(cause)) { + ogs_error("OpenAPI_sm_context_updated_data_parseFromJSON() failed [cause]"); + goto end; + } + causeVariable = OpenAPI_cause_FromString(cause->valuestring); } cJSON *ma_accepted_ind = cJSON_GetObjectItemCaseSensitive(sm_context_updated_dataJSON, "maAcceptedInd"); @@ -572,8 +563,8 @@ OpenAPI_sm_context_updated_data_t *OpenAPI_sm_context_updated_data_parseFromJSON } sm_context_updated_data_local_var = OpenAPI_sm_context_updated_data_create ( - up_cnx_state ? up_cnx_state_local_nonprim : NULL, - ho_state ? ho_state_local_nonprim : NULL, + up_cnx_state ? up_cnx_stateVariable : 0, + ho_state ? ho_stateVariable : 0, release_ebi_list ? release_ebi_listList : NULL, allocated_ebi_list ? allocated_ebi_listList : NULL, modified_ebi_list ? modified_ebi_listList : NULL, @@ -584,7 +575,7 @@ OpenAPI_sm_context_updated_data_t *OpenAPI_sm_context_updated_data_parseFromJSON data_forwarding ? data_forwarding->valueint : 0, n3_dl_forwarding_tnl_list ? n3_dl_forwarding_tnl_listList : NULL, n3_ul_forwarding_tnl_list ? n3_ul_forwarding_tnl_listList : NULL, - cause ? cause_local_nonprim : NULL, + cause ? causeVariable : 0, ma_accepted_ind ? ma_accepted_ind->valueint : 0, supported_features ? ogs_strdup(supported_features->valuestring) : NULL, forwarding_f_teid ? forwarding_f_teid->valueint : 0, diff --git a/lib/sbi/openapi/model/sm_context_updated_data.h b/lib/sbi/openapi/model/sm_context_updated_data.h index 1dcd003fa..55656a39a 100644 --- a/lib/sbi/openapi/model/sm_context_updated_data.h +++ b/lib/sbi/openapi/model/sm_context_updated_data.h @@ -26,8 +26,8 @@ extern "C" { typedef struct OpenAPI_sm_context_updated_data_s OpenAPI_sm_context_updated_data_t; typedef struct OpenAPI_sm_context_updated_data_s { - struct OpenAPI_up_cnx_state_s *up_cnx_state; - struct OpenAPI_ho_state_s *ho_state; + OpenAPI_up_cnx_state_e up_cnx_state; + OpenAPI_ho_state_e ho_state; OpenAPI_list_t *release_ebi_list; OpenAPI_list_t *allocated_ebi_list; OpenAPI_list_t *modified_ebi_list; @@ -38,7 +38,7 @@ typedef struct OpenAPI_sm_context_updated_data_s { int data_forwarding; OpenAPI_list_t *n3_dl_forwarding_tnl_list; OpenAPI_list_t *n3_ul_forwarding_tnl_list; - struct OpenAPI_cause_s *cause; + OpenAPI_cause_e cause; int ma_accepted_ind; char *supported_features; char forwarding_f_teid; @@ -46,8 +46,8 @@ typedef struct OpenAPI_sm_context_updated_data_s { } OpenAPI_sm_context_updated_data_t; OpenAPI_sm_context_updated_data_t *OpenAPI_sm_context_updated_data_create( - OpenAPI_up_cnx_state_t *up_cnx_state, - OpenAPI_ho_state_t *ho_state, + OpenAPI_up_cnx_state_e up_cnx_state, + OpenAPI_ho_state_e ho_state, OpenAPI_list_t *release_ebi_list, OpenAPI_list_t *allocated_ebi_list, OpenAPI_list_t *modified_ebi_list, @@ -58,7 +58,7 @@ OpenAPI_sm_context_updated_data_t *OpenAPI_sm_context_updated_data_create( int data_forwarding, OpenAPI_list_t *n3_dl_forwarding_tnl_list, OpenAPI_list_t *n3_ul_forwarding_tnl_list, - OpenAPI_cause_t *cause, + OpenAPI_cause_e cause, int ma_accepted_ind, char *supported_features, char forwarding_f_teid, diff --git a/lib/sbi/openapi/model/status_info.c b/lib/sbi/openapi/model/status_info.c index ccf9594cf..79b751404 100644 --- a/lib/sbi/openapi/model/status_info.c +++ b/lib/sbi/openapi/model/status_info.c @@ -5,8 +5,8 @@ #include "status_info.h" OpenAPI_status_info_t *OpenAPI_status_info_create( - OpenAPI_resource_status_t *resource_status, - OpenAPI_cause_t *cause, + OpenAPI_resource_status_e resource_status, + OpenAPI_cause_e cause, OpenAPI_cn_assisted_ran_para_t *cn_assisted_ran_para, OpenAPI_access_type_e an_type ) @@ -29,8 +29,6 @@ void OpenAPI_status_info_free(OpenAPI_status_info_t *status_info) return; } OpenAPI_lnode_t *node; - OpenAPI_resource_status_free(status_info->resource_status); - OpenAPI_cause_free(status_info->cause); OpenAPI_cn_assisted_ran_para_free(status_info->cn_assisted_ran_para); ogs_free(status_info); } @@ -49,25 +47,13 @@ cJSON *OpenAPI_status_info_convertToJSON(OpenAPI_status_info_t *status_info) ogs_error("OpenAPI_status_info_convertToJSON() failed [resource_status]"); goto end; } - cJSON *resource_status_local_JSON = OpenAPI_resource_status_convertToJSON(status_info->resource_status); - if (resource_status_local_JSON == NULL) { - ogs_error("OpenAPI_status_info_convertToJSON() failed [resource_status]"); - goto end; - } - cJSON_AddItemToObject(item, "resourceStatus", resource_status_local_JSON); - if (item->child == NULL) { + if (cJSON_AddStringToObject(item, "resourceStatus", OpenAPI_resource_status_ToString(status_info->resource_status)) == NULL) { ogs_error("OpenAPI_status_info_convertToJSON() failed [resource_status]"); goto end; } if (status_info->cause) { - cJSON *cause_local_JSON = OpenAPI_cause_convertToJSON(status_info->cause); - if (cause_local_JSON == NULL) { - ogs_error("OpenAPI_status_info_convertToJSON() failed [cause]"); - goto end; - } - cJSON_AddItemToObject(item, "cause", cause_local_JSON); - if (item->child == NULL) { + if (cJSON_AddStringToObject(item, "cause", OpenAPI_cause_ToString(status_info->cause)) == NULL) { ogs_error("OpenAPI_status_info_convertToJSON() failed [cause]"); goto end; } @@ -106,15 +92,23 @@ OpenAPI_status_info_t *OpenAPI_status_info_parseFromJSON(cJSON *status_infoJSON) goto end; } - OpenAPI_resource_status_t *resource_status_local_nonprim = NULL; + OpenAPI_resource_status_e resource_statusVariable; - resource_status_local_nonprim = OpenAPI_resource_status_parseFromJSON(resource_status); + if (!cJSON_IsString(resource_status)) { + ogs_error("OpenAPI_status_info_parseFromJSON() failed [resource_status]"); + goto end; + } + resource_statusVariable = OpenAPI_resource_status_FromString(resource_status->valuestring); cJSON *cause = cJSON_GetObjectItemCaseSensitive(status_infoJSON, "cause"); - OpenAPI_cause_t *cause_local_nonprim = NULL; + OpenAPI_cause_e causeVariable; if (cause) { - cause_local_nonprim = OpenAPI_cause_parseFromJSON(cause); + if (!cJSON_IsString(cause)) { + ogs_error("OpenAPI_status_info_parseFromJSON() failed [cause]"); + goto end; + } + causeVariable = OpenAPI_cause_FromString(cause->valuestring); } cJSON *cn_assisted_ran_para = cJSON_GetObjectItemCaseSensitive(status_infoJSON, "cnAssistedRanPara"); @@ -136,8 +130,8 @@ OpenAPI_status_info_t *OpenAPI_status_info_parseFromJSON(cJSON *status_infoJSON) } status_info_local_var = OpenAPI_status_info_create ( - resource_status_local_nonprim, - cause ? cause_local_nonprim : NULL, + resource_statusVariable, + cause ? causeVariable : 0, cn_assisted_ran_para ? cn_assisted_ran_para_local_nonprim : NULL, an_type ? an_typeVariable : 0 ); diff --git a/lib/sbi/openapi/model/status_info.h b/lib/sbi/openapi/model/status_info.h index 5b42f6c98..58e5fbc2d 100644 --- a/lib/sbi/openapi/model/status_info.h +++ b/lib/sbi/openapi/model/status_info.h @@ -23,15 +23,15 @@ extern "C" { typedef struct OpenAPI_status_info_s OpenAPI_status_info_t; typedef struct OpenAPI_status_info_s { - struct OpenAPI_resource_status_s *resource_status; - struct OpenAPI_cause_s *cause; + OpenAPI_resource_status_e resource_status; + OpenAPI_cause_e cause; struct OpenAPI_cn_assisted_ran_para_s *cn_assisted_ran_para; OpenAPI_access_type_e an_type; } OpenAPI_status_info_t; OpenAPI_status_info_t *OpenAPI_status_info_create( - OpenAPI_resource_status_t *resource_status, - OpenAPI_cause_t *cause, + OpenAPI_resource_status_e resource_status, + OpenAPI_cause_e cause, OpenAPI_cn_assisted_ran_para_t *cn_assisted_ran_para, OpenAPI_access_type_e an_type ); diff --git a/lib/sbi/openapi/model/unavailable_access_indication.c b/lib/sbi/openapi/model/unavailable_access_indication.c index bce64eec1..3957c0a46 100644 --- a/lib/sbi/openapi/model/unavailable_access_indication.c +++ b/lib/sbi/openapi/model/unavailable_access_indication.c @@ -4,82 +4,27 @@ #include #include "unavailable_access_indication.h" -OpenAPI_unavailable_access_indication_t *OpenAPI_unavailable_access_indication_create( - ) +char* OpenAPI_unavailable_access_indication_ToString(OpenAPI_unavailable_access_indication_e unavailable_access_indication) { - OpenAPI_unavailable_access_indication_t *unavailable_access_indication_local_var = OpenAPI_malloc(sizeof(OpenAPI_unavailable_access_indication_t)); - if (!unavailable_access_indication_local_var) { - return NULL; - } - - return unavailable_access_indication_local_var; + const char *unavailable_access_indicationArray[] = { "NULL", "_3GA_UNAVAILABLE", "N3GA_UNAVAILABLE" }; + size_t sizeofArray = sizeof(unavailable_access_indicationArray) / sizeof(unavailable_access_indicationArray[0]); + if (unavailable_access_indication < sizeofArray) + return (char *)unavailable_access_indicationArray[unavailable_access_indication]; + else + return (char *)"Unknown"; } -void OpenAPI_unavailable_access_indication_free(OpenAPI_unavailable_access_indication_t *unavailable_access_indication) +OpenAPI_unavailable_access_indication_e OpenAPI_unavailable_access_indication_FromString(char* unavailable_access_indication) { - if (NULL == unavailable_access_indication) { - return; + int stringToReturn = 0; + const char *unavailable_access_indicationArray[] = { "NULL", "_3GA_UNAVAILABLE", "N3GA_UNAVAILABLE" }; + size_t sizeofArray = sizeof(unavailable_access_indicationArray) / sizeof(unavailable_access_indicationArray[0]); + while (stringToReturn < sizeofArray) { + if (strcmp(unavailable_access_indication, unavailable_access_indicationArray[stringToReturn]) == 0) { + return stringToReturn; + } + stringToReturn++; } - OpenAPI_lnode_t *node; - ogs_free(unavailable_access_indication); -} - -cJSON *OpenAPI_unavailable_access_indication_convertToJSON(OpenAPI_unavailable_access_indication_t *unavailable_access_indication) -{ - cJSON *item = NULL; - - if (unavailable_access_indication == NULL) { - ogs_error("OpenAPI_unavailable_access_indication_convertToJSON() failed [UnavailableAccessIndication]"); - return NULL; - } - - item = cJSON_CreateObject(); -end: - return item; -} - -OpenAPI_unavailable_access_indication_t *OpenAPI_unavailable_access_indication_parseFromJSON(cJSON *unavailable_access_indicationJSON) -{ - OpenAPI_unavailable_access_indication_t *unavailable_access_indication_local_var = NULL; - unavailable_access_indication_local_var = OpenAPI_unavailable_access_indication_create ( - ); - - return unavailable_access_indication_local_var; -end: - return NULL; -} - -OpenAPI_unavailable_access_indication_t *OpenAPI_unavailable_access_indication_copy(OpenAPI_unavailable_access_indication_t *dst, OpenAPI_unavailable_access_indication_t *src) -{ - cJSON *item = NULL; - char *content = NULL; - - ogs_assert(src); - item = OpenAPI_unavailable_access_indication_convertToJSON(src); - if (!item) { - ogs_error("OpenAPI_unavailable_access_indication_convertToJSON() failed"); - return NULL; - } - - content = cJSON_Print(item); - cJSON_Delete(item); - - if (!content) { - ogs_error("cJSON_Print() failed"); - return NULL; - } - - item = cJSON_Parse(content); - ogs_free(content); - if (!item) { - ogs_error("cJSON_Parse() failed"); - return NULL; - } - - OpenAPI_unavailable_access_indication_free(dst); - dst = OpenAPI_unavailable_access_indication_parseFromJSON(item); - cJSON_Delete(item); - - return dst; + return 0; } diff --git a/lib/sbi/openapi/model/unavailable_access_indication.h b/lib/sbi/openapi/model/unavailable_access_indication.h index c542a55e7..217e3ea86 100644 --- a/lib/sbi/openapi/model/unavailable_access_indication.h +++ b/lib/sbi/openapi/model/unavailable_access_indication.h @@ -1,7 +1,7 @@ /* * unavailable_access_indication.h * - * Possible values are - 3GA_UNAVAILABLE - N3GA_UNAVAILABLE + * */ #ifndef _OpenAPI_unavailable_access_indication_H_ @@ -17,16 +17,11 @@ extern "C" { #endif -typedef struct OpenAPI_unavailable_access_indication_s OpenAPI_unavailable_access_indication_t; -typedef struct OpenAPI_unavailable_access_indication_s { -} OpenAPI_unavailable_access_indication_t; +typedef enum { OpenAPI_unavailable_access_indication_NULL = 0, OpenAPI_unavailable_access_indication__3GA_UNAVAILABLE, OpenAPI_unavailable_access_indication_N3GA_UNAVAILABLE } OpenAPI_unavailable_access_indication_e; -OpenAPI_unavailable_access_indication_t *OpenAPI_unavailable_access_indication_create( - ); -void OpenAPI_unavailable_access_indication_free(OpenAPI_unavailable_access_indication_t *unavailable_access_indication); -OpenAPI_unavailable_access_indication_t *OpenAPI_unavailable_access_indication_parseFromJSON(cJSON *unavailable_access_indicationJSON); -cJSON *OpenAPI_unavailable_access_indication_convertToJSON(OpenAPI_unavailable_access_indication_t *unavailable_access_indication); -OpenAPI_unavailable_access_indication_t *OpenAPI_unavailable_access_indication_copy(OpenAPI_unavailable_access_indication_t *dst, OpenAPI_unavailable_access_indication_t *src); +char* OpenAPI_unavailable_access_indication_ToString(OpenAPI_unavailable_access_indication_e unavailable_access_indication); + +OpenAPI_unavailable_access_indication_e OpenAPI_unavailable_access_indication_FromString(char* unavailable_access_indication); #ifdef __cplusplus } diff --git a/lib/sbi/openapi/model/up_cnx_state.c b/lib/sbi/openapi/model/up_cnx_state.c index da699fac6..ce378ce63 100644 --- a/lib/sbi/openapi/model/up_cnx_state.c +++ b/lib/sbi/openapi/model/up_cnx_state.c @@ -4,82 +4,27 @@ #include #include "up_cnx_state.h" -OpenAPI_up_cnx_state_t *OpenAPI_up_cnx_state_create( - ) +char* OpenAPI_up_cnx_state_ToString(OpenAPI_up_cnx_state_e up_cnx_state) { - OpenAPI_up_cnx_state_t *up_cnx_state_local_var = OpenAPI_malloc(sizeof(OpenAPI_up_cnx_state_t)); - if (!up_cnx_state_local_var) { - return NULL; - } - - return up_cnx_state_local_var; + const char *up_cnx_stateArray[] = { "NULL", "ACTIVATED", "DEACTIVATED", "ACTIVATING", "SUSPENDED" }; + size_t sizeofArray = sizeof(up_cnx_stateArray) / sizeof(up_cnx_stateArray[0]); + if (up_cnx_state < sizeofArray) + return (char *)up_cnx_stateArray[up_cnx_state]; + else + return (char *)"Unknown"; } -void OpenAPI_up_cnx_state_free(OpenAPI_up_cnx_state_t *up_cnx_state) +OpenAPI_up_cnx_state_e OpenAPI_up_cnx_state_FromString(char* up_cnx_state) { - if (NULL == up_cnx_state) { - return; + int stringToReturn = 0; + const char *up_cnx_stateArray[] = { "NULL", "ACTIVATED", "DEACTIVATED", "ACTIVATING", "SUSPENDED" }; + size_t sizeofArray = sizeof(up_cnx_stateArray) / sizeof(up_cnx_stateArray[0]); + while (stringToReturn < sizeofArray) { + if (strcmp(up_cnx_state, up_cnx_stateArray[stringToReturn]) == 0) { + return stringToReturn; + } + stringToReturn++; } - OpenAPI_lnode_t *node; - ogs_free(up_cnx_state); -} - -cJSON *OpenAPI_up_cnx_state_convertToJSON(OpenAPI_up_cnx_state_t *up_cnx_state) -{ - cJSON *item = NULL; - - if (up_cnx_state == NULL) { - ogs_error("OpenAPI_up_cnx_state_convertToJSON() failed [UpCnxState]"); - return NULL; - } - - item = cJSON_CreateObject(); -end: - return item; -} - -OpenAPI_up_cnx_state_t *OpenAPI_up_cnx_state_parseFromJSON(cJSON *up_cnx_stateJSON) -{ - OpenAPI_up_cnx_state_t *up_cnx_state_local_var = NULL; - up_cnx_state_local_var = OpenAPI_up_cnx_state_create ( - ); - - return up_cnx_state_local_var; -end: - return NULL; -} - -OpenAPI_up_cnx_state_t *OpenAPI_up_cnx_state_copy(OpenAPI_up_cnx_state_t *dst, OpenAPI_up_cnx_state_t *src) -{ - cJSON *item = NULL; - char *content = NULL; - - ogs_assert(src); - item = OpenAPI_up_cnx_state_convertToJSON(src); - if (!item) { - ogs_error("OpenAPI_up_cnx_state_convertToJSON() failed"); - return NULL; - } - - content = cJSON_Print(item); - cJSON_Delete(item); - - if (!content) { - ogs_error("cJSON_Print() failed"); - return NULL; - } - - item = cJSON_Parse(content); - ogs_free(content); - if (!item) { - ogs_error("cJSON_Parse() failed"); - return NULL; - } - - OpenAPI_up_cnx_state_free(dst); - dst = OpenAPI_up_cnx_state_parseFromJSON(item); - cJSON_Delete(item); - - return dst; + return 0; } diff --git a/lib/sbi/openapi/model/up_cnx_state.h b/lib/sbi/openapi/model/up_cnx_state.h index dd0f82209..8600345e8 100644 --- a/lib/sbi/openapi/model/up_cnx_state.h +++ b/lib/sbi/openapi/model/up_cnx_state.h @@ -1,7 +1,7 @@ /* * up_cnx_state.h * - * Possible values are - ACTIVATED - DEACTIVATED - ACTIVATING - SUSPENDED + * */ #ifndef _OpenAPI_up_cnx_state_H_ @@ -17,16 +17,11 @@ extern "C" { #endif -typedef struct OpenAPI_up_cnx_state_s OpenAPI_up_cnx_state_t; -typedef struct OpenAPI_up_cnx_state_s { -} OpenAPI_up_cnx_state_t; +typedef enum { OpenAPI_up_cnx_state_NULL = 0, OpenAPI_up_cnx_state_ACTIVATED, OpenAPI_up_cnx_state_DEACTIVATED, OpenAPI_up_cnx_state_ACTIVATING, OpenAPI_up_cnx_state_SUSPENDED } OpenAPI_up_cnx_state_e; -OpenAPI_up_cnx_state_t *OpenAPI_up_cnx_state_create( - ); -void OpenAPI_up_cnx_state_free(OpenAPI_up_cnx_state_t *up_cnx_state); -OpenAPI_up_cnx_state_t *OpenAPI_up_cnx_state_parseFromJSON(cJSON *up_cnx_stateJSON); -cJSON *OpenAPI_up_cnx_state_convertToJSON(OpenAPI_up_cnx_state_t *up_cnx_state); -OpenAPI_up_cnx_state_t *OpenAPI_up_cnx_state_copy(OpenAPI_up_cnx_state_t *dst, OpenAPI_up_cnx_state_t *src); +char* OpenAPI_up_cnx_state_ToString(OpenAPI_up_cnx_state_e up_cnx_state); + +OpenAPI_up_cnx_state_e OpenAPI_up_cnx_state_FromString(char* up_cnx_state); #ifdef __cplusplus } diff --git a/lib/sbi/openapi/model/vsmf_update_data.c b/lib/sbi/openapi/model/vsmf_update_data.c index bde397699..54d784f67 100644 --- a/lib/sbi/openapi/model/vsmf_update_data.c +++ b/lib/sbi/openapi/model/vsmf_update_data.c @@ -5,7 +5,7 @@ #include "vsmf_update_data.h" OpenAPI_vsmf_update_data_t *OpenAPI_vsmf_update_data_create( - OpenAPI_request_indication_t *request_indication, + OpenAPI_request_indication_e request_indication, OpenAPI_ambr_t *session_ambr, OpenAPI_list_t *qos_flows_add_mod_request_list, OpenAPI_list_t *qos_flows_rel_request_list, @@ -18,10 +18,10 @@ OpenAPI_vsmf_update_data_t *OpenAPI_vsmf_update_data_create( int always_on_granted, char *hsmf_pdu_session_uri, char *supported_features, - OpenAPI_cause_t *cause, + OpenAPI_cause_e cause, char *n1sm_cause, int back_off_timer, - OpenAPI_ma_release_indication_t *ma_release_ind, + OpenAPI_ma_release_indication_e ma_release_ind, int ma_accepted_ind, OpenAPI_tunnel_info_t *additional_cn_tunnel_info, OpenAPI_list_t *dnai_list, @@ -67,7 +67,6 @@ void OpenAPI_vsmf_update_data_free(OpenAPI_vsmf_update_data_t *vsmf_update_data) return; } OpenAPI_lnode_t *node; - OpenAPI_request_indication_free(vsmf_update_data->request_indication); OpenAPI_ambr_free(vsmf_update_data->session_ambr); OpenAPI_list_for_each(vsmf_update_data->qos_flows_add_mod_request_list, node) { OpenAPI_qos_flow_add_modify_request_item_free(node->data); @@ -96,9 +95,7 @@ void OpenAPI_vsmf_update_data_free(OpenAPI_vsmf_update_data_t *vsmf_update_data) OpenAPI_ref_to_binary_data_free(vsmf_update_data->n1_sm_info_to_ue); ogs_free(vsmf_update_data->hsmf_pdu_session_uri); ogs_free(vsmf_update_data->supported_features); - OpenAPI_cause_free(vsmf_update_data->cause); ogs_free(vsmf_update_data->n1sm_cause); - OpenAPI_ma_release_indication_free(vsmf_update_data->ma_release_ind); OpenAPI_tunnel_info_free(vsmf_update_data->additional_cn_tunnel_info); OpenAPI_list_for_each(vsmf_update_data->dnai_list, node) { ogs_free(node->data); @@ -124,13 +121,7 @@ cJSON *OpenAPI_vsmf_update_data_convertToJSON(OpenAPI_vsmf_update_data_t *vsmf_u ogs_error("OpenAPI_vsmf_update_data_convertToJSON() failed [request_indication]"); goto end; } - cJSON *request_indication_local_JSON = OpenAPI_request_indication_convertToJSON(vsmf_update_data->request_indication); - if (request_indication_local_JSON == NULL) { - ogs_error("OpenAPI_vsmf_update_data_convertToJSON() failed [request_indication]"); - goto end; - } - cJSON_AddItemToObject(item, "requestIndication", request_indication_local_JSON); - if (item->child == NULL) { + if (cJSON_AddStringToObject(item, "requestIndication", OpenAPI_request_indication_ToString(vsmf_update_data->request_indication)) == NULL) { ogs_error("OpenAPI_vsmf_update_data_convertToJSON() failed [request_indication]"); goto end; } @@ -306,13 +297,7 @@ cJSON *OpenAPI_vsmf_update_data_convertToJSON(OpenAPI_vsmf_update_data_t *vsmf_u } if (vsmf_update_data->cause) { - cJSON *cause_local_JSON = OpenAPI_cause_convertToJSON(vsmf_update_data->cause); - if (cause_local_JSON == NULL) { - ogs_error("OpenAPI_vsmf_update_data_convertToJSON() failed [cause]"); - goto end; - } - cJSON_AddItemToObject(item, "cause", cause_local_JSON); - if (item->child == NULL) { + if (cJSON_AddStringToObject(item, "cause", OpenAPI_cause_ToString(vsmf_update_data->cause)) == NULL) { ogs_error("OpenAPI_vsmf_update_data_convertToJSON() failed [cause]"); goto end; } @@ -333,13 +318,7 @@ cJSON *OpenAPI_vsmf_update_data_convertToJSON(OpenAPI_vsmf_update_data_t *vsmf_u } if (vsmf_update_data->ma_release_ind) { - cJSON *ma_release_ind_local_JSON = OpenAPI_ma_release_indication_convertToJSON(vsmf_update_data->ma_release_ind); - if (ma_release_ind_local_JSON == NULL) { - ogs_error("OpenAPI_vsmf_update_data_convertToJSON() failed [ma_release_ind]"); - goto end; - } - cJSON_AddItemToObject(item, "maReleaseInd", ma_release_ind_local_JSON); - if (item->child == NULL) { + if (cJSON_AddStringToObject(item, "maReleaseInd", OpenAPI_ma_release_indication_ToString(vsmf_update_data->ma_release_ind)) == NULL) { ogs_error("OpenAPI_vsmf_update_data_convertToJSON() failed [ma_release_ind]"); goto end; } @@ -433,9 +412,13 @@ OpenAPI_vsmf_update_data_t *OpenAPI_vsmf_update_data_parseFromJSON(cJSON *vsmf_u goto end; } - OpenAPI_request_indication_t *request_indication_local_nonprim = NULL; + OpenAPI_request_indication_e request_indicationVariable; - request_indication_local_nonprim = OpenAPI_request_indication_parseFromJSON(request_indication); + if (!cJSON_IsString(request_indication)) { + ogs_error("OpenAPI_vsmf_update_data_parseFromJSON() failed [request_indication]"); + goto end; + } + request_indicationVariable = OpenAPI_request_indication_FromString(request_indication->valuestring); cJSON *session_ambr = cJSON_GetObjectItemCaseSensitive(vsmf_update_dataJSON, "sessionAmbr"); @@ -624,9 +607,13 @@ OpenAPI_vsmf_update_data_t *OpenAPI_vsmf_update_data_parseFromJSON(cJSON *vsmf_u cJSON *cause = cJSON_GetObjectItemCaseSensitive(vsmf_update_dataJSON, "cause"); - OpenAPI_cause_t *cause_local_nonprim = NULL; + OpenAPI_cause_e causeVariable; if (cause) { - cause_local_nonprim = OpenAPI_cause_parseFromJSON(cause); + if (!cJSON_IsString(cause)) { + ogs_error("OpenAPI_vsmf_update_data_parseFromJSON() failed [cause]"); + goto end; + } + causeVariable = OpenAPI_cause_FromString(cause->valuestring); } cJSON *n1sm_cause = cJSON_GetObjectItemCaseSensitive(vsmf_update_dataJSON, "n1smCause"); @@ -649,9 +636,13 @@ OpenAPI_vsmf_update_data_t *OpenAPI_vsmf_update_data_parseFromJSON(cJSON *vsmf_u cJSON *ma_release_ind = cJSON_GetObjectItemCaseSensitive(vsmf_update_dataJSON, "maReleaseInd"); - OpenAPI_ma_release_indication_t *ma_release_ind_local_nonprim = NULL; + OpenAPI_ma_release_indication_e ma_release_indVariable; if (ma_release_ind) { - ma_release_ind_local_nonprim = OpenAPI_ma_release_indication_parseFromJSON(ma_release_ind); + if (!cJSON_IsString(ma_release_ind)) { + ogs_error("OpenAPI_vsmf_update_data_parseFromJSON() failed [ma_release_ind]"); + goto end; + } + ma_release_indVariable = OpenAPI_ma_release_indication_FromString(ma_release_ind->valuestring); } cJSON *ma_accepted_ind = cJSON_GetObjectItemCaseSensitive(vsmf_update_dataJSON, "maAcceptedInd"); @@ -712,7 +703,7 @@ OpenAPI_vsmf_update_data_t *OpenAPI_vsmf_update_data_parseFromJSON(cJSON *vsmf_u } vsmf_update_data_local_var = OpenAPI_vsmf_update_data_create ( - request_indication_local_nonprim, + request_indicationVariable, session_ambr ? session_ambr_local_nonprim : NULL, qos_flows_add_mod_request_list ? qos_flows_add_mod_request_listList : NULL, qos_flows_rel_request_list ? qos_flows_rel_request_listList : NULL, @@ -725,10 +716,10 @@ OpenAPI_vsmf_update_data_t *OpenAPI_vsmf_update_data_parseFromJSON(cJSON *vsmf_u always_on_granted ? always_on_granted->valueint : 0, hsmf_pdu_session_uri ? ogs_strdup(hsmf_pdu_session_uri->valuestring) : NULL, supported_features ? ogs_strdup(supported_features->valuestring) : NULL, - cause ? cause_local_nonprim : NULL, + cause ? causeVariable : 0, n1sm_cause ? ogs_strdup(n1sm_cause->valuestring) : NULL, back_off_timer ? back_off_timer->valuedouble : 0, - ma_release_ind ? ma_release_ind_local_nonprim : NULL, + ma_release_ind ? ma_release_indVariable : 0, ma_accepted_ind ? ma_accepted_ind->valueint : 0, additional_cn_tunnel_info ? additional_cn_tunnel_info_local_nonprim : NULL, dnai_list ? dnai_listList : NULL, diff --git a/lib/sbi/openapi/model/vsmf_update_data.h b/lib/sbi/openapi/model/vsmf_update_data.h index e3106fb09..c08c036d8 100644 --- a/lib/sbi/openapi/model/vsmf_update_data.h +++ b/lib/sbi/openapi/model/vsmf_update_data.h @@ -31,7 +31,7 @@ extern "C" { typedef struct OpenAPI_vsmf_update_data_s OpenAPI_vsmf_update_data_t; typedef struct OpenAPI_vsmf_update_data_s { - struct OpenAPI_request_indication_s *request_indication; + OpenAPI_request_indication_e request_indication; struct OpenAPI_ambr_s *session_ambr; OpenAPI_list_t *qos_flows_add_mod_request_list; OpenAPI_list_t *qos_flows_rel_request_list; @@ -44,10 +44,10 @@ typedef struct OpenAPI_vsmf_update_data_s { int always_on_granted; char *hsmf_pdu_session_uri; char *supported_features; - struct OpenAPI_cause_s *cause; + OpenAPI_cause_e cause; char *n1sm_cause; int back_off_timer; - struct OpenAPI_ma_release_indication_s *ma_release_ind; + OpenAPI_ma_release_indication_e ma_release_ind; int ma_accepted_ind; struct OpenAPI_tunnel_info_s *additional_cn_tunnel_info; OpenAPI_list_t *dnai_list; @@ -57,7 +57,7 @@ typedef struct OpenAPI_vsmf_update_data_s { } OpenAPI_vsmf_update_data_t; OpenAPI_vsmf_update_data_t *OpenAPI_vsmf_update_data_create( - OpenAPI_request_indication_t *request_indication, + OpenAPI_request_indication_e request_indication, OpenAPI_ambr_t *session_ambr, OpenAPI_list_t *qos_flows_add_mod_request_list, OpenAPI_list_t *qos_flows_rel_request_list, @@ -70,10 +70,10 @@ OpenAPI_vsmf_update_data_t *OpenAPI_vsmf_update_data_create( int always_on_granted, char *hsmf_pdu_session_uri, char *supported_features, - OpenAPI_cause_t *cause, + OpenAPI_cause_e cause, char *n1sm_cause, int back_off_timer, - OpenAPI_ma_release_indication_t *ma_release_ind, + OpenAPI_ma_release_indication_e ma_release_ind, int ma_accepted_ind, OpenAPI_tunnel_info_t *additional_cn_tunnel_info, OpenAPI_list_t *dnai_list, diff --git a/lib/sbi/path.c b/lib/sbi/path.c index 14fba2820..5a66b4117 100644 --- a/lib/sbi/path.c +++ b/lib/sbi/path.c @@ -91,6 +91,9 @@ bool ogs_sbi_discover_and_send( ogs_assert(nf_type); ogs_assert(build); + ogs_assert(sbi_object->running == false); + sbi_object->running = true; + sbi_object->nf_type = nf_type; if (sbi_object->request) ogs_sbi_request_free(sbi_object->request); diff --git a/lib/sbi/support/modified/TS29502_Nsmf_PDUSession.yaml b/lib/sbi/support/modified/TS29502_Nsmf_PDUSession.yaml index 405245b90..9c55d51b8 100644 --- a/lib/sbi/support/modified/TS29502_Nsmf_PDUSession.yaml +++ b/lib/sbi/support/modified/TS29502_Nsmf_PDUSession.yaml @@ -3073,70 +3073,70 @@ components: # ENUMERATIONS # UpCnxState: - anyOf: - - type: string +# anyOf: +# - type: string enum: - ACTIVATED - DEACTIVATED - ACTIVATING - SUSPENDED - - type: string - description: > - This string provides forward-compatibility with future - extensions to the enumeration but is not used to encode - content defined in the present version of this API. - description: > - Possible values are - - ACTIVATED - - DEACTIVATED - - ACTIVATING - - SUSPENDED + type: string +# description: > +# This string provides forward-compatibility with future +# extensions to the enumeration but is not used to encode +# content defined in the present version of this API. +# description: > +# Possible values are +# - ACTIVATED +# - DEACTIVATED +# - ACTIVATING +# - SUSPENDED HoState: - anyOf: - - type: string +# anyOf: +# - type: string enum: - NONE - PREPARING - PREPARED - COMPLETED - CANCELLED - - type: string - description: > - This string provides forward-compatibility with future - extensions to the enumeration but is not used to encode - content defined in the present version of this API. - description: > - Possible values are - - NONE - - PREPARING - - PREPARED - - COMPLETED - - CANCELLED + type: string +# description: > +# This string provides forward-compatibility with future +# extensions to the enumeration but is not used to encode +# content defined in the present version of this API. +# description: > +# Possible values are +# - NONE +# - PREPARING +# - PREPARED +# - COMPLETED +# - CANCELLED RequestType: - anyOf: - - type: string +# anyOf: +# - type: string enum: - INITIAL_REQUEST - EXISTING_PDU_SESSION - INITIAL_EMERGENCY_REQUEST - EXISTING_EMERGENCY_PDU_SESSION - - type: string - description: > - This string provides forward-compatibility with future - extensions to the enumeration but is not used to encode - content defined in the present version of this API. - description: > - Possible values are - - INITIAL_REQUEST - - EXISTING_PDU_SESSION - - INITIAL_EMERGENCY_REQUEST - - EXISTING_EMERGENCY_PDU_SESSION + type: string +# description: > +# This string provides forward-compatibility with future +# extensions to the enumeration but is not used to encode +# content defined in the present version of this API. +# description: > +# Possible values are +# - INITIAL_REQUEST +# - EXISTING_PDU_SESSION +# - INITIAL_EMERGENCY_REQUEST +# - EXISTING_EMERGENCY_PDU_SESSION RequestIndication: - anyOf: - - type: string +# anyOf: +# - type: string enum: - UE_REQ_PDU_SES_MOD - UE_REQ_PDU_SES_REL @@ -3145,44 +3145,44 @@ components: - NW_REQ_PDU_SES_MOD - NW_REQ_PDU_SES_REL - EBI_ASSIGNMENT_REQ - - type: string - description: > - This string provides forward-compatibility with future - extensions to the enumeration but is not used to encode - content defined in the present version of this API. - description: > - Possible values are - - UE_REQ_PDU_SES_MOD - - UE_REQ_PDU_SES_REL - - PDU_SES_MOB - - NW_REQ_PDU_SES_AUTH - - NW_REQ_PDU_SES_MOD - - NW_REQ_PDU_SES_REL - - EBI_ASSIGNMENT_REQ + type: string +# description: > +# This string provides forward-compatibility with future +# extensions to the enumeration but is not used to encode +# content defined in the present version of this API. +# description: > +# Possible values are +# - UE_REQ_PDU_SES_MOD +# - UE_REQ_PDU_SES_REL +# - PDU_SES_MOB +# - NW_REQ_PDU_SES_AUTH +# - NW_REQ_PDU_SES_MOD +# - NW_REQ_PDU_SES_REL +# - EBI_ASSIGNMENT_REQ NotificationCause: - anyOf: - - type: string +# anyOf: +# - type: string enum: - QOS_FULFILLED - QOS_NOT_FULFILLED - UP_SEC_FULFILLED - UP_SEC_NOT_FULFILLED - - type: string - description: > - This string provides forward-compatibility with future - extensions to the enumeration but is not used to encode - content defined in the present version of this API. - description: > - Possible values are - - QOS_FULFILLED - - QOS_NOT_FULFILLED - - UP_SEC_FULFILLED - - UP_SEC_NOT_FULFILLED + type: string +# description: > +# This string provides forward-compatibility with future +# extensions to the enumeration but is not used to encode +# content defined in the present version of this API. +# description: > +# Possible values are +# - QOS_FULFILLED +# - QOS_NOT_FULFILLED +# - UP_SEC_FULFILLED +# - UP_SEC_NOT_FULFILLED Cause: - anyOf: - - type: string +# anyOf: +# - type: string enum: - REL_DUE_TO_HO - EPS_FALLBACK @@ -3208,93 +3208,93 @@ components: - PDU_SESSION_HAND_OVER_FAILURE - DDN_FAILURE_STATUS - - type: string - description: > - This string provides forward-compatibility with future - extensions to the enumeration but is not used to encode - content defined in the present version of this API. - description: > - Possible values are - - REL_DUE_TO_HO - - EPS_FALLBACK - - REL_DUE_TO_UP_SEC - - DNN_CONGESTION - - S_NSSAI_CONGESTION - - REL_DUE_TO_REACTIVATION - - 5G_AN_NOT_RESPONDING - - REL_DUE_TO_SLICE_NOT_AVAILABLE - - REL_DUE_TO_DUPLICATE_SESSION_ID - - PDU_SESSION_STATUS_MISMATCH - - HO_FAILURE - - INSUFFICIENT_UP_RESOURCES - - PDU_SESSION_HANDED_OVER - - PDU_SESSION_RESUMED - - CN_ASSISTED_RAN_PARAMETER_TUNING - - ISMF_CONTEXT_TRANSFER - - SMF_CONTEXT_TRANSFER - - REL_DUE_TO_PS_TO_CS_HO - - REL_DUE_TO_SUBSCRIPTION_CHANGE - - HO_CANCEL - - REL_DUE_TO_SLICE_NOT_AUTHORIZED - - PDU_SESSION_HAND_OVER_FAILURE - - DDN_FAILURE_STATUS + type: string +# description: > +# This string provides forward-compatibility with future +# extensions to the enumeration but is not used to encode +# content defined in the present version of this API. +# description: > +# Possible values are +# - REL_DUE_TO_HO +# - EPS_FALLBACK +# - REL_DUE_TO_UP_SEC +# - DNN_CONGESTION +# - S_NSSAI_CONGESTION +# - REL_DUE_TO_REACTIVATION +# - 5G_AN_NOT_RESPONDING +# - REL_DUE_TO_SLICE_NOT_AVAILABLE +# - REL_DUE_TO_DUPLICATE_SESSION_ID +# - PDU_SESSION_STATUS_MISMATCH +# - HO_FAILURE +# - INSUFFICIENT_UP_RESOURCES +# - PDU_SESSION_HANDED_OVER +# - PDU_SESSION_RESUMED +# - CN_ASSISTED_RAN_PARAMETER_TUNING +# - ISMF_CONTEXT_TRANSFER +# - SMF_CONTEXT_TRANSFER +# - REL_DUE_TO_PS_TO_CS_HO +# - REL_DUE_TO_SUBSCRIPTION_CHANGE +# - HO_CANCEL +# - REL_DUE_TO_SLICE_NOT_AUTHORIZED +# - PDU_SESSION_HAND_OVER_FAILURE +# - DDN_FAILURE_STATUS ResourceStatus: - anyOf: - - type: string +# anyOf: +# - type: string enum: - RELEASED - UNCHANGED - TRANSFERRED - UPDATED - - type: string - description: > - This string provides forward-compatibility with future - extensions to the enumeration but is not used to encode - content defined in the present version of this API. - description: > - Possible values are - - RELEASED - - UNCHANGED - - UPDATED + type: string +# description: > +# This string provides forward-compatibility with future +# extensions to the enumeration but is not used to encode +# content defined in the present version of this API. +# description: > +# Possible values are +# - RELEASED +# - UNCHANGED +# - UPDATED DnnSelectionMode: - anyOf: - - type: string +# anyOf: +# - type: string enum: - VERIFIED - UE_DNN_NOT_VERIFIED - NW_DNN_NOT_VERIFIED - - type: string - description: > - This string provides forward-compatibility with future - extensions to the enumeration but is not used to encode - content defined in the present version of this API. - description: > - Possible values are - - VERIFIED - - UE_DNN_NOT_VERIFIED - - NW_DNN_NOT_VERIFIED + type: string +# description: > +# This string provides forward-compatibility with future +# extensions to the enumeration but is not used to encode +# content defined in the present version of this API. +# description: > +# Possible values are +# - VERIFIED +# - UE_DNN_NOT_VERIFIED +# - NW_DNN_NOT_VERIFIED EpsInterworkingIndication: - anyOf: - - type: string +# anyOf: +# - type: string enum: - NONE - WITH_N26 - WITHOUT_N26 - IWK_NON_3GPP - - type: string - description: > - This string provides forward-compatibility with future - extensions to the enumeration but is not used to encode - content defined in the present version of this API. - description: > - Possible values are - - NONE - - WITH_N26 - - WITHOUT_N26 - - IWK_NON_3GPP + type: string +# description: > +# This string provides forward-compatibility with future +# extensions to the enumeration but is not used to encode +# content defined in the present version of this API. +# description: > +# Possible values are +# - NONE +# - WITH_N26 +# - WITHOUT_N26 +# - IWK_NON_3GPP N2SmInfoType: # anyOf: @@ -3353,72 +3353,72 @@ components: # - SECONDARY_RAT_USAGE MaxIntegrityProtectedDataRate: - anyOf: - - type: string +# anyOf: +# - type: string enum: - 64_KBPS - MAX_UE_RATE - - type: string - description: > - This string provides forward-compatibility with future - extensions to the enumeration but is not used to encode - content defined in the present version of this API. - description: > - Possible values are - - 64_KBPS - - MAX_UE_RATE + type: string +# description: > +# This string provides forward-compatibility with future +# extensions to the enumeration but is not used to encode +# content defined in the present version of this API. +# description: > +# Possible values are +# - 64_KBPS +# - MAX_UE_RATE MaReleaseIndication: - anyOf: - - type: string +# anyOf: +# - type: string enum: - REL_MAPDU_OVER_3GPP - REL_MAPDU_OVER_N3GPP - - type: string - description: > - This string provides forward-compatibility with future - extensions to the enumeration but is not used to encode - content defined in the present version of this API. - description: > - Possible values are - - REL_MAPDU_OVER_3GPP - - REL_MAPDU_OVER_N3GPP + type: string +# description: > +# This string provides forward-compatibility with future +# extensions to the enumeration but is not used to encode +# content defined in the present version of this API. +# description: > +# Possible values are +# - REL_MAPDU_OVER_3GPP +# - REL_MAPDU_OVER_N3GPP SmContextType: - anyOf: - - type: string +# anyOf: +# - type: string enum: - EPS_PDN_CONNECTION - SM_CONTEXT - - type: string - description: > - This string provides forward-compatibility with future - extensions to the enumeration but is not used to encode - content defined in the present version of this API. - description: > - Possible values are - - EPS_PDN_CONNECTION - - SM_CONTEXT + type: string +# description: > +# This string provides forward-compatibility with future +# extensions to the enumeration but is not used to encode +# content defined in the present version of this API. +# description: > +# Possible values are +# - EPS_PDN_CONNECTION +# - SM_CONTEXT PsaIndication: - anyOf: - - type: string +# anyOf: +# - type: string enum: - PSA_INSERTED - PSA_REMOVED - - type: string - description: > - This string provides forward-compatibility with future - extensions to the enumeration but is not used to encode - content defined in the present version of this API. - description: > - Possible values are - - PSA_INSERTED - - PSA_REMOVED + type: string +# description: > +# This string provides forward-compatibility with future +# extensions to the enumeration but is not used to encode +# content defined in the present version of this API. +# description: > +# Possible values are +# - PSA_INSERTED +# - PSA_REMOVED N4MessageType: - anyOf: - - type: string +# anyOf: +# - type: string enum: - PFCP_SES_EST_REQ - PFCP_SES_EST_RSP @@ -3428,55 +3428,55 @@ components: - PFCP_SES_DEL_RSP - PFCP_SES_REP_REQ - PFCP_SES_REP_RSP - - type: string - description: > - This string provides forward-compatibility with future - extensions to the enumeration but is not used to encode - content defined in the present version of this API. - description: > - Possible values are - - PFCP_SES_EST_REQ - - PFCP_SES_EST_RSP - - PFCP_SES_MOD_REQ - - PFCP_SES_MOD_RSP - - PFCP_SES_DEL_REQ - - PFCP_SES_DEL_RSP - - PFCP_SES_REP_REQ - - PFCP_SES_REP_RSP + type: string +# description: > +# This string provides forward-compatibility with future +# extensions to the enumeration but is not used to encode +# content defined in the present version of this API. +# description: > +# Possible values are +# - PFCP_SES_EST_REQ +# - PFCP_SES_EST_RSP +# - PFCP_SES_MOD_REQ +# - PFCP_SES_MOD_RSP +# - PFCP_SES_DEL_REQ +# - PFCP_SES_DEL_RSP +# - PFCP_SES_REP_REQ +# - PFCP_SES_REP_RSP QosFlowAccessType: - anyOf: - - type: string +# anyOf: +# - type: string enum: - 3GPP - NON_3GPP - 3GPP_AND_NON_3GPP - - type: string - description: > - This string provides forward-compatibility with future - extensions to the enumeration but is not used to encode - content defined in the present version of this API. - description: > - Possible values are - - 3GPP - - NON_3GPP - - 3GPP_AND_NON_3GPP + type: string +# description: > +# This string provides forward-compatibility with future +# extensions to the enumeration but is not used to encode +# content defined in the present version of this API. +# description: > +# Possible values are +# - 3GPP +# - NON_3GPP +# - 3GPP_AND_NON_3GPP UnavailableAccessIndication: - anyOf: - - type: string +# anyOf: +# - type: string enum: - 3GA_UNAVAILABLE - N3GA_UNAVAILABLE - - type: string - description: > - This string provides forward-compatibility with future - extensions to the enumeration but is not used to encode - content defined in the present version of this API. - description: > - Possible values are - - 3GA_UNAVAILABLE - - N3GA_UNAVAILABLE + type: string +# description: > +# This string provides forward-compatibility with future +# extensions to the enumeration but is not used to encode +# content defined in the present version of this API. +# description: > +# Possible values are +# - 3GA_UNAVAILABLE +# - N3GA_UNAVAILABLE # # HTTP request bodies diff --git a/meson.build b/meson.build index d9d015993..8b4919410 100644 --- a/meson.build +++ b/meson.build @@ -16,7 +16,7 @@ # along with this program. If not, see . project('open5gs', 'c', - version : '1.2.5', + version : '1.3.0', license : 'AGPL-3.0-or-later', meson_version : '>= 0.43.0', default_options : [ @@ -24,7 +24,7 @@ project('open5gs', 'c', ], ) -libogslib_version = '1.2.5' +libogslib_version = '1.3.0' prefix = get_option('prefix') bindir = join_paths(prefix, get_option('bindir')) diff --git a/src/amf/amf-path.c b/src/amf/amf-path.c new file mode 100644 index 000000000..dd2741a53 --- /dev/null +++ b/src/amf/amf-path.c @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2019,2020 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "amf-path.h" + +void amf_send_delete_session_or_de_register(amf_ue_t *amf_ue) +{ + ogs_assert(amf_ue); + + if (SESSION_CONTEXT_IS_AVAILABLE(amf_ue)) { + amf_sbi_send_release_all_sm_contexts(amf_ue); + } else { + nas_5gs_send_de_registration_accept(amf_ue); + } +} + +void amf_send_delete_session_or_amf_ue_context_release(amf_ue_t *amf_ue) +{ + ogs_assert(amf_ue); + + if (SESSION_CONTEXT_IS_AVAILABLE(amf_ue)) { + amf_sbi_send_release_all_sm_contexts(amf_ue); + } else { + ran_ue_t *ran_ue = amf_ue->ran_ue; + if (ran_ue) { + ngap_send_ue_context_release_command(ran_ue, + NGAP_Cause_PR_nas, NGAP_CauseNas_normal_release, + NGAP_UE_CTX_REL_UE_CONTEXT_REMOVE, 0); + } else { + ogs_warn("No NG Context"); + } + } +} + +void amf_send_delete_session_or_ran_ue_context_release(ran_ue_t *ran_ue) +{ + amf_ue_t *amf_ue = NULL; + ogs_assert(ran_ue); + + amf_ue = ran_ue->amf_ue; + if (amf_ue && SESSION_CONTEXT_IS_AVAILABLE(amf_ue)) { + amf_sbi_send_release_all_sm_contexts(amf_ue); + } else { + ngap_send_ue_context_release_command(ran_ue, + NGAP_Cause_PR_nas, NGAP_CauseNas_normal_release, + NGAP_UE_CTX_REL_NG_CONTEXT_REMOVE, 0); + } +} diff --git a/src/amf/amf-path.h b/src/amf/amf-path.h new file mode 100644 index 000000000..54f444a60 --- /dev/null +++ b/src/amf/amf-path.h @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2019,2020 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef AMF_PATH_H +#define AMF_PATH_H + +#include "sbi-path.h" +#include "nas-path.h" +#include "ngap-path.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void amf_send_delete_session_or_de_register(amf_ue_t *amf_ue); +void amf_send_delete_session_or_amf_ue_context_release(amf_ue_t *amf_ue); +void amf_send_delete_session_or_ran_ue_context_release(ran_ue_t *ran_ue); + +#ifdef __cplusplus +} +#endif + +#endif /* AMF_PATH_H */ diff --git a/src/amf/amf-sm.c b/src/amf/amf-sm.c index 7902a284a..c0451583a 100644 --- a/src/amf/amf-sm.c +++ b/src/amf/amf-sm.c @@ -18,10 +18,12 @@ */ #include "sbi-path.h" +#include "ngap-path.h" #include "nas-path.h" +#include "amf-path.h" #include "nnrf-handler.h" #include "namf-handler.h" -#include "ngap-path.h" +#include "nsmf-handler.h" #include "nas-security.h" void amf_state_initial(ogs_fsm_t *s, amf_event_t *e) @@ -330,16 +332,16 @@ void amf_state_operational(ogs_fsm_t *s, amf_event_t *e) sbi_object = e->sbi.data; ogs_assert(sbi_object); + sbi_object->running = false; + ogs_timer_stop(sbi_object->client_wait.timer); + SWITCH(sbi_message.h.method) CASE(OGS_SBI_HTTP_METHOD_GET) - if (sbi_message.res_status == OGS_SBI_HTTP_STATUS_OK) { - ogs_timer_stop(sbi_object->client_wait.timer); - + if (sbi_message.res_status == OGS_SBI_HTTP_STATUS_OK) amf_nnrf_handle_nf_discover(sbi_object, &sbi_message); - } else { + else ogs_error("HTTP response error [%d]", sbi_message.res_status); - } break; DEFAULT @@ -365,9 +367,12 @@ void amf_state_operational(ogs_fsm_t *s, amf_event_t *e) e->amf_ue = amf_ue; e->sbi.message = &sbi_message;; + amf_ue->sbi.running = false; + ogs_timer_stop(amf_ue->sbi.client_wait.timer); + ogs_fsm_dispatch(&amf_ue->sm, e); if (OGS_FSM_CHECK(&amf_ue->sm, gmm_state_exception)) { - amf_ue_remove(amf_ue); + amf_send_delete_session_or_amf_ue_context_release(amf_ue); } break; @@ -382,10 +387,21 @@ void amf_state_operational(ogs_fsm_t *s, amf_event_t *e) e->sess = sess; e->sbi.message = &sbi_message;; - ogs_fsm_dispatch(&amf_ue->sm, e); - if (OGS_FSM_CHECK(&amf_ue->sm, gmm_state_exception)) { - amf_ue_remove(amf_ue); - } + sess->sbi.running = false; + ogs_timer_stop(sess->sbi.client_wait.timer); + + SWITCH(sbi_message.h.resource.component[2]) + CASE(OGS_SBI_RESOURCE_NAME_RELEASE) + amf_nsmf_pdu_session_handle_release_sm_context( + sess, &sbi_message); + break; + + DEFAULT + ogs_fsm_dispatch(&amf_ue->sm, e); + if (OGS_FSM_CHECK(&amf_ue->sm, gmm_state_exception)) { + amf_send_delete_session_or_amf_ue_context_release(amf_ue); + } + END break; DEFAULT @@ -430,6 +446,8 @@ void amf_state_operational(ogs_fsm_t *s, amf_event_t *e) sbi_object = e->sbi.data; ogs_assert(sbi_object); + sbi_object->running = false; + switch(sbi_object->nf_type) { case OpenAPI_nf_type_AUSF: case OpenAPI_nf_type_UDM: @@ -576,6 +594,7 @@ void amf_state_operational(ogs_fsm_t *s, amf_event_t *e) ogs_assert(ran_ue); pkbuf = e->pkbuf; ogs_assert(pkbuf); + if (ogs_nas_5gmm_decode(&nas_message, pkbuf) != OGS_OK) { ogs_error("ogs_nas_5gmm_decode() failed"); ogs_pkbuf_free(pkbuf); @@ -613,7 +632,7 @@ void amf_state_operational(ogs_fsm_t *s, amf_event_t *e) /* If NAS(amf_ue_t) has already been associated with * older NG(ran_ue_t) context */ - if (ECM_CONNECTED(amf_ue)) { + if (CM_CONNECTED(amf_ue)) { /* Implcit NG release */ ogs_debug("[%s] Implicit NG release", amf_ue->suci); ogs_debug("[%s] RAN_UE_NGAP_ID[%d] AMF_UE_NGAP_ID[%lld]", @@ -632,11 +651,7 @@ void amf_state_operational(ogs_fsm_t *s, amf_event_t *e) ogs_fsm_dispatch(&amf_ue->sm, e); if (OGS_FSM_CHECK(&amf_ue->sm, gmm_state_exception)) { -#if 0 - mme_send_delete_session_or_amf_ue_context_release(amf_ue); -#else - amf_ue_remove(amf_ue); -#endif + amf_send_delete_session_or_amf_ue_context_release(amf_ue); } ogs_pkbuf_free(pkbuf); diff --git a/src/amf/context.c b/src/amf/context.c index 1648cd0cc..f92f944fb 100644 --- a/src/amf/context.c +++ b/src/amf/context.c @@ -28,7 +28,6 @@ static OGS_POOL(amf_gnb_pool, amf_gnb_t); static OGS_POOL(amf_ue_pool, amf_ue_t); static OGS_POOL(ran_ue_pool, ran_ue_t); static OGS_POOL(amf_sess_pool, amf_sess_t); -static OGS_POOL(amf_bearer_pool, amf_bearer_t); static int context_initialized = 0; @@ -53,7 +52,6 @@ void amf_context_init(void) ogs_pool_init(&amf_ue_pool, ogs_config()->pool.ue); ogs_pool_init(&ran_ue_pool, ogs_config()->pool.ue); ogs_pool_init(&amf_sess_pool, ogs_config()->pool.sess); - ogs_pool_init(&amf_bearer_pool, ogs_config()->pool.bearer); ogs_pool_init(&self.m_tmsi, ogs_config()->pool.ue); ogs_list_init(&self.gnb_list); @@ -91,7 +89,6 @@ void amf_context_final(void) ogs_hash_destroy(self.supi_hash); ogs_pool_final(&self.m_tmsi); - ogs_pool_final(&amf_bearer_pool); ogs_pool_final(&amf_sess_pool); ogs_pool_final(&amf_ue_pool); ogs_pool_final(&ran_ue_pool); @@ -849,8 +846,8 @@ amf_gnb_t *amf_gnb_add(ogs_sock_t *sock, ogs_sockaddr_t *addr) ogs_hash_set(self.gnb_addr_hash, gnb->addr, sizeof(ogs_sockaddr_t), gnb); + memset(&e, 0, sizeof(e)); e.gnb = gnb; - e.id = 0; ogs_fsm_create(&gnb->sm, ngap_state_initial, ngap_state_final); ogs_fsm_init(&gnb->sm, &e); @@ -868,6 +865,7 @@ int amf_gnb_remove(amf_gnb_t *gnb) ogs_list_remove(&self.gnb_list, gnb); + memset(&e, 0, sizeof(e)); e.gnb = gnb; ogs_fsm_fini(&gnb->sm, &e); ogs_fsm_delete(&gnb->sm); @@ -1105,12 +1103,6 @@ amf_ue_t *amf_ue_add(ran_ue_t *ran_ue) /* Create New GUTI */ amf_ue_new_guti(amf_ue); -#if 0 - /* Clear VLR */ - amf_ue->csmap = NULL; - amf_ue->vlr_ostream_id = 0; -#endif - /* Add All Timers */ amf_ue->sbi.client_wait.timer = ogs_timer_add( self.timer_mgr, amf_timer_sbi_client_wait_expire, amf_ue); @@ -1135,6 +1127,7 @@ amf_ue_t *amf_ue_add(ran_ue_t *ran_ue) amf_ue->t3570.pkbuf = NULL; /* Create FSM */ + memset(&e, 0, sizeof(e)); e.amf_ue = amf_ue; ogs_fsm_create(&amf_ue->sm, gmm_state_initial, gmm_state_final); ogs_fsm_init(&amf_ue->sm, &e); @@ -1152,6 +1145,7 @@ void amf_ue_remove(amf_ue_t *amf_ue) ogs_list_remove(&self.amf_ue_list, amf_ue); + memset(&e, 0, sizeof(e)); e.amf_ue = amf_ue; ogs_fsm_fini(&amf_ue->sm, &e); ogs_fsm_delete(&amf_ue->sm); @@ -1199,7 +1193,6 @@ void amf_ue_remove(amf_ue_t *amf_ue) amf_ue_deassociate(amf_ue); amf_sess_remove_all(amf_ue); - amf_pdn_remove_all(amf_ue); ogs_pool_free(&amf_ue_pool, amf_ue); } @@ -1243,7 +1236,6 @@ amf_ue_t *amf_ue_find_by_message(ogs_nas_5gs_message_t *message) ogs_nas_5gs_registration_request_t *registration_request = NULL; #if 0 ogs_nas_5gs_tracking_area_update_request_t *tau_request = NULL; - ogs_nas_5gs_extended_service_request_t *extended_service_request = NULL; #endif ogs_nas_5gs_mobile_identity_t *mobile_identity = NULL; ogs_nas_5gs_mobile_identity_header_t *mobile_identity_header = NULL; @@ -1254,16 +1246,19 @@ amf_ue_t *amf_ue_find_by_message(ogs_nas_5gs_message_t *message) ogs_assert(message); - registration_request = &message->gmm.registration_request; - ogs_assert(registration_request); - mobile_identity = ®istration_request->mobile_identity; - ogs_assert(mobile_identity); - mobile_identity_header = - (ogs_nas_5gs_mobile_identity_header_t *)mobile_identity->buffer; - ogs_assert(mobile_identity_header); - switch (message->gmm.h.message_type) { case OGS_NAS_5GS_REGISTRATION_REQUEST: + registration_request = &message->gmm.registration_request; + ogs_assert(registration_request); + mobile_identity = ®istration_request->mobile_identity; + ogs_assert(mobile_identity); + + if (!mobile_identity->length || !mobile_identity->buffer) + return NULL; + + mobile_identity_header = + (ogs_nas_5gs_mobile_identity_header_t *)mobile_identity->buffer; + switch (mobile_identity_header->type) { case OGS_NAS_5GS_MOBILE_IDENTITY_SUCI: suci = ogs_nas_5gs_suci_from_mobile_identity(mobile_identity); @@ -1275,16 +1270,18 @@ amf_ue_t *amf_ue_find_by_message(ogs_nas_5gs_message_t *message) } ogs_free(suci); break; + case OGS_NAS_5GS_MOBILE_IDENTITY_GUTI: mobile_identity_guti = (ogs_nas_5gs_mobile_identity_guti_t *)mobile_identity->buffer; - ogs_assert(mobile_identity_guti); - memcpy(&nas_guti.nas_plmn_id, - &mobile_identity_guti->nas_plmn_id, OGS_PLMN_ID_LEN); - memcpy(&nas_guti.amf_id, - &mobile_identity_guti->amf_id, sizeof(ogs_amf_id_t)); - nas_guti.m_tmsi = be32toh(mobile_identity_guti->m_tmsi); + if (!mobile_identity_guti) { + ogs_error("No mobile identity"); + return NULL; + } + + ogs_nas_5gs_mobile_identity_guti_to_nas_guti( + mobile_identity_guti, &nas_guti); amf_ue = amf_ue_find_by_guti(&nas_guti); if (amf_ue) { @@ -1297,7 +1294,7 @@ amf_ue_t *amf_ue_find_by_message(ogs_nas_5gs_message_t *message) break; default: ogs_error("Unknown SUCI type [%d]", mobile_identity_header->type); - break; + } break; #if 0 @@ -1332,40 +1329,7 @@ amf_ue_t *amf_ue_find_by_message(ogs_nas_5gs_message_t *message) break; } break; - case OGS_NAS_5GS_EXTENDED_SERVICE_REQUEST: - extended_service_request = &message->gmm.extended_service_request; - mobile_identity = &extended_service_request->m_tmsi; - switch(mobile_identity->tmsi.type) { - case OGS_NAS_MOBILE_IDENTITY_TMSI: - mobile_identity_tmsi = &mobile_identity->tmsi; - served_guami = &amf_self()->served_guami[0]; - - /* Use the first configured plmn_id and amf group id */ - ogs_nas_from_plmn_id( - &ogs_nas_guti.nas_plmn_id, &served_guami->plmn_id[0]); - ogs_nas_guti.amf_gid = served_guami->amf_gid[0]; - ogs_nas_guti.amf_code = served_guami->amf_code[0]; - ogs_nas_guti.m_tmsi = mobile_identity_tmsi->tmsi; - - amf_ue = amf_ue_find_by_guti(&ogs_nas_guti); - if (amf_ue) { - ogs_trace("Known UE by GUTI[G:%d,C:%d,M_TMSI:0x%x]", - ogs_nas_guti.amf_gid, - ogs_nas_guti.amf_code, - ogs_nas_guti.m_tmsi); - } else { - ogs_warn("Unknown UE by GUTI[G:%d,C:%d,M_TMSI:0x%x]", - ogs_nas_guti.amf_gid, - ogs_nas_guti.amf_code, - ogs_nas_guti.m_tmsi); - } - break; - default: - ogs_error("Unknown TMSI type [%d]", mobile_identity->tmsi.type); - break; - } - break; #endif default: break; @@ -1422,47 +1386,14 @@ void amf_ue_set_supi(amf_ue_t *amf_ue, char *supi) ogs_hash_set(self.supi_hash, amf_ue->supi, strlen(amf_ue->supi), amf_ue); } -int amf_ue_have_indirect_tunnel(amf_ue_t *amf_ue) +bool amf_ue_activation_synched(amf_ue_t *amf_ue) { amf_sess_t *sess = NULL; - sess = ogs_list_first(&amf_ue->sess_list); - while (sess) { - amf_bearer_t *bearer = ogs_list_first(&sess->bearer_list); - while (bearer) { - if (AMF_HAVE_GNB_DL_INDIRECT_TUNNEL(bearer) || - AMF_HAVE_GNB_UL_INDIRECT_TUNNEL(bearer) || - AMF_HAVE_SMF_DL_INDIRECT_TUNNEL(bearer) || - AMF_HAVE_SMF_UL_INDIRECT_TUNNEL(bearer)) { - return 1; - } + ogs_list_for_each(&amf_ue->sess_list, sess) + if (sess->ueUpCnxState != sess->smfUpCnxState) return false; - bearer = ogs_list_next(bearer); - } - sess = ogs_list_next(sess); - } - - return 0; -} - -int amf_ue_clear_indirect_tunnel(amf_ue_t *amf_ue) -{ - amf_sess_t *sess = NULL; - - ogs_assert(amf_ue); - - sess = ogs_list_first(&amf_ue->sess_list); - while (sess) { - amf_bearer_t *bearer = ogs_list_first(&sess->bearer_list); - while (bearer) { - CLEAR_INDIRECT_TUNNEL(bearer); - - bearer = ogs_list_next(bearer); - } - sess = ogs_list_next(sess); - } - - return OGS_OK; + return true; } void amf_ue_associate_ran_ue(amf_ue_t *amf_ue, ran_ue_t *ran_ue) @@ -1529,9 +1460,6 @@ void source_ue_deassociate_target_ue(ran_ue_t *ran_ue) amf_sess_t *amf_sess_add(amf_ue_t *amf_ue, uint8_t psi) { amf_sess_t *sess = NULL; -#if 0 - amf_bearer_t *bearer = NULL; -#endif ogs_assert(amf_ue); ogs_assert(psi != OGS_NAS_PDU_SESSION_IDENTITY_UNASSIGNED); @@ -1540,21 +1468,12 @@ amf_sess_t *amf_sess_add(amf_ue_t *amf_ue, uint8_t psi) ogs_assert(sess); memset(sess, 0, sizeof *sess); -#if 0 - ogs_list_init(&sess->bearer_list); -#endif - sess->amf_ue = amf_ue; sess->psi = psi; sess->sbi.client_wait.timer = ogs_timer_add( self.timer_mgr, amf_timer_sbi_client_wait_expire, sess); -#if 0 - bearer = amf_bearer_add(sess); - ogs_assert(bearer); -#endif - ogs_list_add(&amf_ue->sess_list, sess); return sess; @@ -1567,10 +1486,6 @@ void amf_sess_remove(amf_sess_t *sess) ogs_list_remove(&sess->amf_ue->sess_list, sess); -#if 0 - amf_bearer_remove_all(sess); -#endif - /* Free SBI object memory */ ogs_sbi_object_free(&sess->sbi); ogs_timer_delete(sess->sbi.client_wait.timer); @@ -1609,408 +1524,6 @@ amf_sess_t *amf_sess_find_by_psi(amf_ue_t *amf_ue, uint8_t psi) return NULL; } -#if 0 -amf_sess_t *amf_sess_find_by_ebi(amf_ue_t *amf_ue, uint8_t ebi) -{ - amf_bearer_t *bearer = NULL; - - bearer = amf_bearer_find_by_ue_ebi(amf_ue, ebi); - if (bearer) - return bearer->sess; - - return NULL; -} -#endif - -amf_sess_t *amf_sess_find_by_dnn(amf_ue_t *amf_ue, char *dnn) -{ -#if 0 - amf_sess_t *sess = NULL; - - sess = amf_sess_first(amf_ue); - while (sess) { - if (sess->pdn && strcmp(sess->pdn->dnn, dnn) == 0) - return sess; - - sess = amf_sess_next(sess); - } -#endif - - return NULL; -} - -#if 0 -amf_bearer_t *amf_bearer_add(amf_sess_t *sess) -{ - amf_event_t e; - - amf_bearer_t *bearer = NULL; - amf_ue_t *amf_ue = NULL; - - ogs_assert(sess); - amf_ue = sess->amf_ue; - ogs_assert(amf_ue); - - ogs_pool_alloc(&amf_bearer_pool, &bearer); - ogs_assert(bearer); - memset(bearer, 0, sizeof *bearer); - - bearer->ebi = OGS_NEXT_ID(amf_ue->ebi, - MIN_5GS_BEARER_ID, MAX_5GS_BEARER_ID); - - bearer->amf_ue = amf_ue; - bearer->sess = sess; - - ogs_list_add(&sess->bearer_list, bearer); - - bearer->t3589.timer = ogs_timer_add( - self.timer_mgr, amf_timer_t3589_expire, bearer); - bearer->t3589.pkbuf = NULL; - - e.bearer = bearer; - e.id = 0; - ogs_fsm_create(&bearer->sm, gsm_state_initial, gsm_state_final); - ogs_fsm_init(&bearer->sm, &e); - - return bearer; -} - -void amf_bearer_remove(amf_bearer_t *bearer) -{ - amf_event_t e; - - ogs_assert(bearer); - ogs_assert(bearer->sess); - - e.bearer = bearer; - ogs_fsm_fini(&bearer->sm, &e); - ogs_fsm_delete(&bearer->sm); - - CLEAR_BEARER_ALL_TIMERS(bearer); - ogs_timer_delete(bearer->t3589.timer); - - ogs_list_remove(&bearer->sess->bearer_list, bearer); - - OGS_TLV_CLEAR_DATA(&bearer->tft); - - ogs_pool_free(&amf_bearer_pool, bearer); -} - -void amf_bearer_remove_all(amf_sess_t *sess) -{ - amf_bearer_t *bearer = NULL, *next_bearer = NULL; - - ogs_assert(sess); - - bearer = amf_bearer_first(sess); - while (bearer) { - next_bearer = amf_bearer_next(bearer); - - amf_bearer_remove(bearer); - - bearer = next_bearer; - } -} - -amf_bearer_t *amf_bearer_find_by_sess_ebi(amf_sess_t *sess, uint8_t ebi) -{ - amf_bearer_t *bearer = NULL; - - ogs_assert(sess); - - bearer = amf_bearer_first(sess); - while (bearer) { - if (ebi == bearer->ebi) - return bearer; - - bearer = amf_bearer_next(bearer); - } - - return NULL; -} - -amf_bearer_t *amf_bearer_find_by_ue_ebi(amf_ue_t *amf_ue, uint8_t ebi) -{ - amf_sess_t *sess = NULL; - amf_bearer_t *bearer = NULL; - - ogs_assert(amf_ue); - - sess = amf_sess_first(amf_ue); - while (sess) { - bearer = amf_bearer_find_by_sess_ebi(sess, ebi); - if (bearer) { - return bearer; - } - - sess = amf_sess_next(sess); - } - - return NULL; -} - -amf_bearer_t *amf_bearer_find_or_add_by_message( - amf_ue_t *amf_ue, ogs_nas_5gs_message_t *message) -{ -#if 0 - uint8_t pti = OGS_NAS_PROCEDURE_TRANSACTION_IDENTITY_UNASSIGNED; - uint8_t ebi = OGS_NAS_5GS_BEARER_IDENTITY_UNASSIGNED; -#endif - - amf_bearer_t *bearer = NULL; -#if 0 - amf_sess_t *sess = NULL; -#endif - -#if 0 - ogs_assert(amf_ue); - ogs_assert(message); - - pti = message->esm.h.procedure_transaction_identity; - ebi = message->esm.h.eps_bearer_identity; - - ogs_debug("amf_bearer_find_or_add_by_message() [PTI:%d, EBI:%d]", - pti, ebi); - - if (ebi != OGS_NAS_5GS_BEARER_IDENTITY_UNASSIGNED) { - bearer = amf_bearer_find_by_ue_ebi(amf_ue, ebi); - if (!bearer) { - ogs_error("No Bearer : EBI[%d]", ebi); - nas_eps_send_attach_reject(amf_ue, - EMM_CAUSE_PROTOCOL_ERROR_UNSPECIFIED, - ESM_CAUSE_PROTOCOL_ERROR_UNSPECIFIED); - return NULL; - } - - return bearer; - } - - if (pti == OGS_NAS_PROCEDURE_TRANSACTION_IDENTITY_UNASSIGNED) { - ogs_error("Both PTI[%d] and EBI[%d] are 0", pti, ebi); - nas_eps_send_attach_reject(amf_ue, - EMM_CAUSE_PROTOCOL_ERROR_UNSPECIFIED, - ESM_CAUSE_PROTOCOL_ERROR_UNSPECIFIED); - return NULL; - } - - if (message->esm.h.message_type == OGS_NAS_5GS_PDN_DISCONNECT_REQUEST) { - ogs_nas_eps_pdn_disconnect_request_t *pdn_disconnect_request = - &message->esm.pdn_disconnect_request; - ogs_nas_linked_eps_bearer_identity_t *linked_eps_bearer_identity = - &pdn_disconnect_request->linked_eps_bearer_identity; - - bearer = amf_bearer_find_by_ue_ebi(amf_ue, - linked_eps_bearer_identity->eps_bearer_identity); - if (!bearer) { - ogs_error("No Bearer : Linked-EBI[%d]", - linked_eps_bearer_identity->eps_bearer_identity); - nas_eps_send_attach_reject(amf_ue, - EMM_CAUSE_PROTOCOL_ERROR_UNSPECIFIED, - ESM_CAUSE_PROTOCOL_ERROR_UNSPECIFIED); - return NULL; - } - } else if (message->esm.h.message_type == - OGS_NAS_5GS_BEARER_RESOURCE_ALLOCATION_REQUEST) { - ogs_nas_eps_bearer_resource_allocation_request_t - *bearer_allocation_request = - &message->esm.bearer_resource_allocation_request; - ogs_nas_linked_eps_bearer_identity_t *linked_eps_bearer_identity = - &bearer_allocation_request->linked_eps_bearer_identity; - - bearer = amf_bearer_find_by_ue_ebi(amf_ue, - linked_eps_bearer_identity->eps_bearer_identity); - if (!bearer) { - ogs_error("No Bearer : Linked-EBI[%d]", - linked_eps_bearer_identity->eps_bearer_identity); - nas_eps_send_attach_reject(amf_ue, - EMM_CAUSE_PROTOCOL_ERROR_UNSPECIFIED, - ESM_CAUSE_PROTOCOL_ERROR_UNSPECIFIED); - return NULL; - } - } else if (message->esm.h.message_type == - OGS_NAS_5GS_BEARER_RESOURCE_MODIFICATION_REQUEST) { - ogs_nas_eps_bearer_resource_modification_request_t - *bearer_modification_request = - &message->esm.bearer_resource_modification_request; - ogs_nas_linked_eps_bearer_identity_t *linked_eps_bearer_identity = - &bearer_modification_request->eps_bearer_identity_for_packet_filter; - - bearer = amf_bearer_find_by_ue_ebi(amf_ue, - linked_eps_bearer_identity->eps_bearer_identity); - if (!bearer) { - ogs_error("No Bearer : Linked-EBI[%d]", - linked_eps_bearer_identity->eps_bearer_identity); - nas_eps_send_attach_reject(amf_ue, - EMM_CAUSE_PROTOCOL_ERROR_UNSPECIFIED, - ESM_CAUSE_PROTOCOL_ERROR_UNSPECIFIED); - return NULL; - } - } - - if (bearer) { - sess = bearer->sess; - ogs_assert(sess); - sess->pti = pti; - - return bearer; - } - - if (message->esm.h.message_type == OGS_NAS_5GS_PDN_CONNECTIVITY_REQUEST) { - ogs_nas_eps_pdn_connectivity_request_t *pdn_connectivity_request = - &message->esm.pdn_connectivity_request; - if (pdn_connectivity_request->presencemask & - OGS_NAS_5GS_PDN_CONNECTIVITY_REQUEST_ACCESS_POINT_NAME_PRESENT) - sess = amf_sess_find_by_dnn(amf_ue, - pdn_connectivity_request->access_point_name.dnn); - else - sess = amf_sess_first(amf_ue); - - if (!sess) - sess = amf_sess_add(amf_ue, pti); - else - sess->pti = pti; - - ogs_assert(sess); - } else { - sess = amf_sess_find_by_pti(amf_ue, pti); - ogs_assert(sess); - } - - bearer = amf_default_bearer_in_sess(sess); - ogs_assert(bearer); -#endif - - return bearer; -} - -amf_bearer_t *amf_default_bearer_in_sess(amf_sess_t *sess) -{ - ogs_assert(sess); - return amf_bearer_first(sess); -} - -amf_bearer_t *amf_linked_bearer(amf_bearer_t *bearer) -{ - amf_sess_t *sess = NULL; - - ogs_assert(bearer); - sess = bearer->sess; - ogs_assert(sess); - - return amf_default_bearer_in_sess(sess); -} - -amf_bearer_t *amf_bearer_first(amf_sess_t *sess) -{ - ogs_assert(sess); - - return ogs_list_first(&sess->bearer_list); -} - -amf_bearer_t *amf_bearer_next(amf_bearer_t *bearer) -{ - ogs_assert(bearer); - return ogs_list_next(bearer); -} - -int amf_bearer_is_inactive(amf_ue_t *amf_ue) -{ - amf_sess_t *sess = NULL; - ogs_assert(amf_ue); - - sess = amf_sess_first(amf_ue); - while (sess) { - amf_bearer_t *bearer = amf_bearer_first(sess); - while (bearer) { - if (AMF_HAVE_GNB_S1U_PATH(bearer)) { - return 0; - } - - bearer = amf_bearer_next(bearer); - } - sess = amf_sess_next(sess); - } - - return 1; -} - -int amf_bearer_set_inactive(amf_ue_t *amf_ue) -{ - amf_sess_t *sess = NULL; - - ogs_assert(amf_ue); - sess = amf_sess_first(amf_ue); - while (sess) { - amf_bearer_t *bearer = amf_bearer_first(sess); - while (bearer) { - CLEAR_GNB_S1U_PATH(bearer); - - bearer = amf_bearer_next(bearer); - } - sess = amf_sess_next(sess); - } - - return OGS_OK; -} -#endif - -void amf_pdn_remove_all(amf_ue_t *amf_ue) -{ -#if 0 - ogs_diam_s6a_subscription_data_t *subscription_data = NULL; - - ogs_assert(amf_ue); - subscription_data = &amf_ue->subscription_data; - ogs_assert(subscription_data); - - subscription_data->num_of_pdn = 0; -#endif -} - -ogs_pdn_t *amf_pdn_find_by_dnn(amf_ue_t *amf_ue, char *dnn) -{ -#if 0 - ogs_diam_s6a_subscription_data_t *subscription_data = NULL; - ogs_pdn_t *pdn = NULL; - int i = 0; - - ogs_assert(amf_ue); - ogs_assert(dnn); - - subscription_data = &amf_ue->subscription_data; - ogs_assert(subscription_data); - - for (i = 0; i < subscription_data->num_of_pdn; i++) { - pdn = &subscription_data->pdn[i]; - if (strcmp(pdn->dnn, dnn) == 0) - return pdn; - } -#endif - - return NULL; -} - -ogs_pdn_t *amf_default_pdn(amf_ue_t *amf_ue) -{ -#if 0 - ogs_diam_s6a_subscription_data_t *subscription_data = NULL; - ogs_pdn_t *pdn = NULL; - int i = 0; - - ogs_assert(amf_ue); - subscription_data = &amf_ue->subscription_data; - ogs_assert(subscription_data); - - for (i = 0; i < subscription_data->num_of_pdn; i++) { - pdn = &subscription_data->pdn[i]; - if (pdn->context_identifier == subscription_data->context_identifier) - return pdn; - } -#endif - - return NULL; -} - int amf_find_served_tai(ogs_5gs_tai_t *tai) { int i = 0, j = 0, k = 0; diff --git a/src/amf/context.h b/src/amf/context.h index 8931ce855..58a40c54a 100644 --- a/src/amf/context.h +++ b/src/amf/context.h @@ -177,8 +177,8 @@ struct ran_ue_s { /* Store by UE Context Release Command * Retrieve by UE Context Release Complete */ #define NGAP_UE_CTX_REL_INVALID_ACTION 0 -#define NGAP_UE_CTX_REL_S1_CONTEXT_REMOVE 1 -#define NGAP_UE_CTX_REL_S1_REMOVE_AND_UNLINK 2 +#define NGAP_UE_CTX_REL_NG_CONTEXT_REMOVE 1 +#define NGAP_UE_CTX_REL_NG_REMOVE_AND_UNLINK 2 #define NGAP_UE_CTX_REL_UE_CONTEXT_REMOVE 3 #define NGAP_UE_CTX_REL_DELETE_INDIRECT_TUNNEL 4 uint8_t ue_ctx_rel_action; @@ -216,14 +216,10 @@ struct amf_ue_s { struct { ED3(uint8_t tsc:1;, uint8_t ksi:3;, - uint8_t spare:4;) + uint8_t value:4;) }; ogs_nas_5gs_registration_type_t registration; -#if 0 - ogs_5gs_update_type_t update; - ogs_5gs_service_type_t service; - ogs_5gs_detach_type_t detach; -#endif + ogs_nas_de_registration_type_t de_registration; uint8_t data; }; @@ -235,7 +231,7 @@ struct amf_ue_s { ((__aMF) && ((__aMF)->suci)) char *suci; /* TS33.501 : SUCI */ char *supi; /* TS33.501 : SUPI */ - ogs_nas_5gs_mobile_identity_imsi_t nas_mobile_identity_imsi; + ogs_nas_5gs_mobile_identity_suci_t nas_mobile_identity_suci; char *pei; uint8_t imeisv[OGS_MAX_IMEISV_LEN]; @@ -247,10 +243,8 @@ struct amf_ue_s { ogs_nas_5gs_guti_t guti; int guti_present; - uint16_t vlr_ostream_id; /* SCTP output stream id for VLR */ - /* UE Info */ - amf_guami_t *guami; + amf_guami_t *guami; ogs_5gs_tai_t tai; ogs_nr_cgi_t cgi; ogs_plmn_id_t last_visited_plmn_id; @@ -280,10 +274,6 @@ struct amf_ue_s { /* Security Context */ ogs_nas_ue_security_capability_t ue_security_capability; -#if 0 - ogs_nas_ue_network_capability_t ue_network_capability; - ogs_nas_ms_network_capability_t ms_network_capability; -#endif char *confirmation_url_for_5g_aka; uint8_t rand[OGS_RAND_LEN]; uint8_t autn[OGS_AUTN_LEN]; @@ -330,22 +320,10 @@ struct amf_ue_s { ogs_bitrate_t subscribed_ue_ambr; /* UE-AMBR */ - /* ESM Info */ -#define MIN_5GS_BEARER_ID 5 -#define MAX_5GS_BEARER_ID 15 - -#define CLEAR_5GS_BEARER_ID(__aMF) \ - do { \ - ogs_assert((__aMF)); \ - (__aMF)->ebi = MIN_5GS_BEARER_ID - 1; \ - } while(0) - uint8_t ebi; /* 5GS Bearer ID generator */ - ogs_list_t sess_list; - -#define ECM_CONNECTED(__aMF) \ +#define CM_CONNECTED(__aMF) \ ((__aMF) && ((__aMF)->ran_ue != NULL)) -#define ECM_IDLE(__aMF) (!ECM_CONNECTED(__aMF)) - /* S1 UE context */ +#define CM_IDLE(__aMF) (!ECM_CONNECTED(__aMF)) + /* NG UE context */ ran_ue_t *ran_ue; #define CLEAR_AMF_UE_ALL_TIMERS(__aMF) \ @@ -378,38 +356,9 @@ struct amf_ue_s { /* NGAP Transparent Container */ OCTET_STRING_t container; - /* - * If the AMF sends Delete-Session-Request to the SMF for all sessions, - * session_context_will_deleted = 1 - * When the AMF receives a Delete-Session-Response for the last session, - * session_context_will_deleted = 0 - */ - int session_context_will_deleted; + ogs_list_t sess_list; }; -#define AMF_HAVE_SMF_S1U_PATH(__sESS) \ - ((__sESS) && (amf_bearer_first(__sESS)) && \ - ((amf_default_bearer_in_sess(__sESS)->smf_s1u_teid))) -#define CLEAR_SMF_S1U_PATH(__sESS) \ - do { \ - amf_bearer_t *__bEARER = NULL; \ - ogs_assert((__sESS)); \ - __bEARER = amf_default_bearer_in_sess(__sESS); \ - __bEARER->smf_s1u_teid = 0; \ - } while(0) - -#define SESSION_CONTEXT_IS_AVAILABLE(__aMF) \ - ((__aMF) && ((__aMF)->smf_s11_teid)) - -#define SESSION_CONTEXT_WILL_DELETED(__aMF) \ - ((__aMF) && ((__aMF)->session_context_will_deleted)) - -#define CLEAR_SESSION_CONTEXT(__aMF) \ - do { \ - ogs_assert((__aMF)); \ - (__aMF)->smf_s11_teid = 0; \ - (__aMF)->session_context_will_deleted = 0; \ - } while(0) typedef struct amf_sess_s { ogs_sbi_object_t sbi; @@ -418,27 +367,31 @@ typedef struct amf_sess_s { char *sm_context_ref; /* smContextRef from SMF */ +#define SESSION_CONTEXT_IS_AVAILABLE(__aMF) \ + ((__aMF) && (ogs_list_first((&(__aMF)->sess_list))) && \ + (((amf_sess_t *)ogs_list_first((&(__aMF)->sess_list)))->sm_context_ref)) + +#define SESSION_UP_CNX_STATE_SYNCHED(__aMF) \ + (amf_ue_activation_synched(__aMF) == true) + + /* UE session context is activated or not */ + OpenAPI_up_cnx_state_e ueUpCnxState; + /* SMF session context is activated or not */ + OpenAPI_up_cnx_state_e smfUpCnxState; + + OpenAPI_n2_sm_info_type_e n2SmInfoType; + ogs_pkbuf_t *n2smbuf; + /* last payload for sending back to the UE */ uint8_t payload_container_type; ogs_pkbuf_t *payload_container; -#if 0 - /* PDN Connectivity Request */ - ogs_nas_request_type_t request_type; -#endif - /* amf_bearer_first(sess) : Default Bearer Context */ ogs_list_t bearer_list; /* Related Context */ amf_ue_t *amf_ue; -#if 0 -#define AMF_UE_HAVE_APN(__aMF) \ - ((__aMF) && (amf_sess_first(__aMF)) && \ - ((amf_sess_first(__aMF))->pdn)) - ogs_pdn_t *pdn; -#endif ogs_s_nssai_t s_nssai; char *dnn; @@ -452,90 +405,6 @@ typedef struct amf_sess_s { ogs_tlv_octet_t pgw_pco; } amf_sess_t; -#define BEARER_CONTEXT_IS_ACTIVE(__aMF) \ - (amf_bearer_is_inactive(__aMF) == 0) -#define CLEAR_BEARER_CONTEXT(__aMF) \ - amf_bearer_set_inactive(__aMF) - -#define AMF_HAVE_GNB_S1U_PATH(__bEARER) \ - ((__bEARER) && ((__bEARER)->gnb_s1u_teid)) -#define CLEAR_GNB_S1U_PATH(__bEARER) \ - do { \ - ogs_assert((__bEARER)); \ - (__bEARER)->gnb_s1u_teid = 0; \ - } while(0) - -#define AMF_HAVE_GNB_DL_INDIRECT_TUNNEL(__bEARER) \ - ((__bEARER) && ((__bEARER)->gnb_dl_teid)) -#define AMF_HAVE_GNB_UL_INDIRECT_TUNNEL(__bEARER) \ - ((__bEARER) && ((__bEARER)->gnb_ul_teid)) -#define AMF_HAVE_SMF_DL_INDIRECT_TUNNEL(__bEARER) \ - ((__bEARER) && ((__bEARER)->smf_dl_teid)) -#define AMF_HAVE_SMF_UL_INDIRECT_TUNNEL(__bEARER) \ - ((__bEARER) && ((__bEARER)->smf_ul_teid)) -#define CLEAR_INDIRECT_TUNNEL(__bEARER) \ - do { \ - ogs_assert((__bEARER)); \ - (__bEARER)->gnb_dl_teid = 0; \ - (__bEARER)->gnb_ul_teid = 0; \ - (__bEARER)->smf_dl_teid = 0; \ - (__bEARER)->smf_ul_teid = 0; \ - } while(0) -typedef struct amf_bearer_s { - ogs_lnode_t lnode; - ogs_fsm_t sm; /* State Machine */ - - uint8_t ebi; /* 5GS Bearer ID */ - - uint32_t gnb_s1u_teid; - ogs_ip_t gnb_s1u_ip; - uint32_t smf_s1u_teid; - ogs_ip_t smf_s1u_ip; - - uint32_t target_s1u_teid; /* Target S1U TEID from HO-Req-Ack */ - ogs_ip_t target_s1u_ip; /* Target S1U ADDR from HO-Req-Ack */ - - uint32_t gnb_dl_teid; - ogs_ip_t gnb_dl_ip; - uint32_t gnb_ul_teid; - ogs_ip_t gnb_ul_ip; - - uint32_t smf_dl_teid; - ogs_ip_t smf_dl_ip; - uint32_t smf_ul_teid; - ogs_ip_t smf_ul_ip; - - ogs_qos_t qos; - ogs_tlv_octet_t tft; /* Saved TFT */ - -#define CLEAR_BEARER_ALL_TIMERS(__bEARER) \ - do { \ - CLEAR_BEARER_TIMER((__bEARER)->t3589); \ - } while(0); -#define CLEAR_BEARER_TIMER(__bEARER_TIMER) \ - do { \ - ogs_timer_stop((__bEARER_TIMER).timer); \ - if ((__bEARER_TIMER).pkbuf) \ - { \ - ogs_pkbuf_free((__bEARER_TIMER).pkbuf); \ - (__bEARER_TIMER).pkbuf = NULL; \ - } \ - (__bEARER_TIMER).retry_count = 0; \ - } while(0); - struct { - ogs_pkbuf_t *pkbuf; - ogs_timer_t *timer; - uint32_t retry_count;; - } t3589; - - /* Related Context */ - amf_ue_t *amf_ue; - amf_sess_t *sess; -#if 0 - ogs_gtp_xact_t *xact; -#endif -} amf_bearer_t; - void amf_context_init(void); void amf_context_final(void); amf_context_t *amf_self(void); @@ -575,6 +444,8 @@ void amf_ue_set_suci(amf_ue_t *amf_ue, ogs_nas_5gs_mobile_identity_t *mobile_identity); void amf_ue_set_supi(amf_ue_t *amf_ue, char *supi); +bool amf_ue_activation_synched(amf_ue_t *amf_ue); + int amf_ue_have_indirect_tunnel(amf_ue_t *amf_ue); int amf_ue_clear_indirect_tunnel(amf_ue_t *amf_ue); @@ -638,25 +509,6 @@ void amf_sess_remove_all(amf_ue_t *amf_ue); amf_sess_t *amf_sess_find_by_psi(amf_ue_t *amf_ue, uint8_t psi); amf_sess_t *amf_sess_find_by_dnn(amf_ue_t *amf_ue, char *dnn); -amf_bearer_t *amf_bearer_add(amf_sess_t *sess); -void amf_bearer_remove(amf_bearer_t *bearer); -void amf_bearer_remove_all(amf_sess_t *sess); -amf_bearer_t *amf_bearer_find_by_sess_ebi(amf_sess_t *sess, uint8_t ebi); -amf_bearer_t *amf_bearer_find_by_ue_ebi(amf_ue_t *amf_ue, uint8_t ebi); -amf_bearer_t *amf_bearer_find_or_add_by_message( - amf_ue_t *amf_ue, ogs_nas_5gs_message_t *message); -amf_bearer_t *amf_default_bearer_in_sess(amf_sess_t *sess); -amf_bearer_t *amf_linked_bearer(amf_bearer_t *bearer); -amf_bearer_t *amf_bearer_first(amf_sess_t *sess); -amf_bearer_t *amf_bearer_next(amf_bearer_t *bearer); - -int amf_bearer_is_inactive(amf_ue_t *amf_ue); -int amf_bearer_set_inactive(amf_ue_t *amf_ue); - -void amf_pdn_remove_all(amf_ue_t *amf_ue); -ogs_pdn_t *amf_pdn_find_by_dnn(amf_ue_t *amf_ue, char *dnn); -ogs_pdn_t *amf_default_pdn(amf_ue_t *amf_ue); - int amf_find_served_tai(ogs_5gs_tai_t *tai); ogs_s_nssai_t *amf_find_s_nssai( ogs_plmn_id_t *served_plmn_id, ogs_nas_s_nssai_t *s_nssai); diff --git a/src/amf/gmm-build.c b/src/amf/gmm-build.c index 0e322365c..68983df98 100644 --- a/src/amf/gmm-build.c +++ b/src/amf/gmm-build.c @@ -62,15 +62,9 @@ ogs_pkbuf_t *gmm_build_registration_accept(amf_ue_t *amf_ue) ogs_amf_id_hexdump(&amf_ue->guti.amf_id), amf_ue->guti.m_tmsi); if (amf_ue->guti_present) { registration_accept->presencemask |= OGS_NAS_5GS_REGISTRATION_ACCEPT_5G_GUTI_PRESENT; - memset(&mobile_identity_guti, 0, sizeof(mobile_identity_guti)); - mobile_identity_guti.h.type = OGS_NAS_5GS_MOBILE_IDENTITY_GUTI; - - memcpy(&mobile_identity_guti.nas_plmn_id, - &amf_ue->guti.nas_plmn_id, OGS_PLMN_ID_LEN); - memcpy(&mobile_identity_guti.amf_id, - &amf_ue->guti.amf_id, sizeof(ogs_amf_id_t)); - mobile_identity_guti.m_tmsi = htobe32(amf_ue->guti.m_tmsi); + ogs_nas_5gs_nas_guti_to_mobilty_identity_guti( + &amf_ue->guti, &mobile_identity_guti); mobile_identity->length = sizeof(mobile_identity_guti); mobile_identity->buffer = &mobile_identity_guti; @@ -489,8 +483,97 @@ ogs_pkbuf_t *gmm_build_dl_nas_transport(amf_sess_t *sess, return gmmbuf; } -#if 0 -ogs_pkbuf_t *gmm_build_detach_accept(amf_ue_t *amf_ue) +static uint16_t get_pdu_session_status(amf_ue_t *amf_ue, bool reactivation) +{ + amf_sess_t *sess = NULL; + + uint16_t psimask = 0; + uint16_t status = 0; + + ogs_assert(amf_ue); + + ogs_list_for_each(&amf_ue->sess_list, sess) { + if (reactivation) { + if (sess->smfUpCnxState != OpenAPI_up_cnx_state_ACTIVATING) + psimask |= (1 << sess->psi); + } else { + if (sess->smfUpCnxState == OpenAPI_up_cnx_state_ACTIVATING) + psimask |= (1 << sess->psi); + } + } + + status |= (psimask << 8); + status |= (psimask >> 8); + + return status; +} + +ogs_pkbuf_t *gmm_build_service_accept(amf_ue_t *amf_ue) +{ + ogs_nas_5gs_message_t message; + ogs_nas_5gs_service_accept_t *service_accept = &message.gmm.service_accept; + ogs_nas_pdu_session_reactivation_result_t *pdu_session_reactivation_result; + + ogs_assert(amf_ue); + + pdu_session_reactivation_result = &service_accept-> + pdu_session_reactivation_result; + ogs_assert(pdu_session_reactivation_result); + + ogs_debug("[%s] Service accept", amf_ue->supi); + + memset(&message, 0, sizeof(message)); + message.h.security_header_type = + OGS_NAS_SECURITY_HEADER_INTEGRITY_PROTECTED_AND_CIPHERED; + message.h.extended_protocol_discriminator = + OGS_NAS_EXTENDED_PROTOCOL_DISCRIMINATOR_5GMM; + + message.gmm.h.extended_protocol_discriminator = + OGS_NAS_EXTENDED_PROTOCOL_DISCRIMINATOR_5GMM; + message.gmm.h.message_type = OGS_NAS_5GS_SERVICE_ACCEPT; + + if (SESSION_CONTEXT_IS_AVAILABLE(amf_ue)) { + service_accept->presencemask |= + OGS_NAS_5GS_SERVICE_ACCEPT_PDU_SESSION_REACTIVATION_RESULT_PRESENT; + pdu_session_reactivation_result->length = 2; + pdu_session_reactivation_result->psi = + get_pdu_session_status(amf_ue, true); + } + + return nas_5gs_security_encode(amf_ue, &message); +} + +ogs_pkbuf_t *gmm_build_service_reject(amf_ue_t *amf_ue, + ogs_nas_5gmm_cause_t gmm_cause, bool pdu_session_status_present) +{ + ogs_nas_5gs_message_t message; + ogs_nas_5gs_service_reject_t *service_reject = &message.gmm.service_reject; + ogs_nas_pdu_session_status_t *pdu_session_status = NULL; + + ogs_assert(amf_ue); + + pdu_session_status = &service_reject->pdu_session_status; + + ogs_debug("[%s] Service reject", amf_ue->supi); + + memset(&message, 0, sizeof(message)); + message.gmm.h.extended_protocol_discriminator = + OGS_NAS_EXTENDED_PROTOCOL_DISCRIMINATOR_5GMM; + message.gmm.h.message_type = OGS_NAS_5GS_SERVICE_REJECT; + + service_reject->gmm_cause = gmm_cause; + + if (pdu_session_status_present) { + service_reject->presencemask |= + OGS_NAS_5GS_SERVICE_REJECT_PDU_SESSION_STATUS_PRESENT; + pdu_session_status->length = 2; + pdu_session_status->psi = get_pdu_session_status(amf_ue, false); + } + + return ogs_nas_5gs_plain_encode(&message); +} + +ogs_pkbuf_t *gmm_build_de_registration_accept(amf_ue_t *amf_ue) { ogs_nas_5gs_message_t message; @@ -502,16 +585,16 @@ ogs_pkbuf_t *gmm_build_detach_accept(amf_ue_t *amf_ue) message.h.extended_protocol_discriminator = OGS_NAS_EXTENDED_PROTOCOL_DISCRIMINATOR_5GMM; - ogs_debug("Detach accept"); - ogs_debug(" IMSI[%s]", amf_ue->imsi_bcd); + ogs_debug("[%s] De-registration accept", amf_ue->supi); message.gmm.h.extended_protocol_discriminator = OGS_NAS_EXTENDED_PROTOCOL_DISCRIMINATOR_5GMM; - message.gmm.h.message_type = OGS_NAS_5GS_DETACH_ACCEPT; + message.gmm.h.message_type = OGS_NAS_5GS_DEREGISTRATION_ACCEPT; return nas_5gs_security_encode(amf_ue, &message); } +#if 0 ogs_pkbuf_t *gmm_build_tau_accept(amf_ue_t *amf_ue) { ogs_nas_5gs_message_t message; @@ -633,27 +716,6 @@ ogs_pkbuf_t *gmm_build_tau_reject( return ogs_nas_5gs_plain_encode(&message); } -ogs_pkbuf_t *gmm_build_service_reject( - ogs_nas_5gmm_cause_t gmm_cause, amf_ue_t *amf_ue) -{ - ogs_nas_5gs_message_t message; - ogs_nas_5gs_service_reject_t *service_reject = &message.gmm.service_reject; - - ogs_assert(amf_ue); - - ogs_debug("Service reject"); - ogs_debug(" Cause[%d]", gmm_cause); - - memset(&message, 0, sizeof(message)); - message.gmm.h.extended_protocol_discriminator = - OGS_NAS_EXTENDED_PROTOCOL_DISCRIMINATOR_5GMM; - message.gmm.h.message_type = OGS_NAS_5GS_SERVICE_REJECT; - - service_reject->gmm_cause = gmm_cause; - - return ogs_nas_5gs_plain_encode(&message); -} - ogs_pkbuf_t *gmm_build_cs_service_notification(amf_ue_t *amf_ue) { ogs_nas_5gs_message_t message; diff --git a/src/amf/gmm-build.h b/src/amf/gmm-build.h index e46692009..081b20641 100644 --- a/src/amf/gmm-build.h +++ b/src/amf/gmm-build.h @@ -42,15 +42,17 @@ ogs_pkbuf_t *gmm_build_dl_nas_transport(amf_sess_t *sess, uint8_t payload_container_type, ogs_pkbuf_t *payload, ogs_nas_5gmm_cause_t cause, uint8_t backoff_time); -ogs_pkbuf_t *gmm_build_detach_accept(amf_ue_t *amf_ue); +ogs_pkbuf_t *gmm_build_service_accept(amf_ue_t *amf_ue); + +ogs_pkbuf_t *gmm_build_service_reject(amf_ue_t *amf_ue, + ogs_nas_5gmm_cause_t gmm_cause, bool pdu_session_status_present); + +ogs_pkbuf_t *gmm_build_de_registration_accept(amf_ue_t *amf_ue); ogs_pkbuf_t *gmm_build_tau_accept(amf_ue_t *amf_ue); ogs_pkbuf_t *gmm_build_tau_reject( ogs_nas_5gmm_cause_t gmm_cause, amf_ue_t *amf_ue); -ogs_pkbuf_t *gmm_build_service_reject( - ogs_nas_5gmm_cause_t gmm_cause, amf_ue_t *amf_ue); - ogs_pkbuf_t *gmm_build_cs_service_notification(amf_ue_t *amf_ue); ogs_pkbuf_t *gmm_build_downlink_nas_transport( amf_ue_t *amf_ue, uint8_t *buffer, uint8_t length); diff --git a/src/amf/gmm-handler.c b/src/amf/gmm-handler.c index 5e521e027..04994e89f 100644 --- a/src/amf/gmm-handler.c +++ b/src/amf/gmm-handler.c @@ -21,9 +21,10 @@ #include "ngap-path.h" #include "nas-path.h" +#include "amf-path.h" +#include "sbi-path.h" #include "gmm-handler.h" -#include "sbi-path.h" #undef OGS_LOG_DOMAIN #define OGS_LOG_DOMAIN __gmm_log_domain @@ -40,18 +41,25 @@ int gmm_handle_registration_request(amf_ue_t *amf_ue, ogs_nas_5gs_mobile_identity_guti_t *mobile_identity_guti = NULL; ogs_nas_5gs_guti_t nas_guti; + ogs_assert(amf_ue); + ran_ue = amf_ue->ran_ue; + ogs_assert(ran_ue); + ogs_assert(registration_request); registration_type = ®istration_request->registration_type; ogs_assert(registration_type); mobile_identity = ®istration_request->mobile_identity; ogs_assert(mobile_identity); + + if (!mobile_identity->length || !mobile_identity->buffer) { + ogs_error("No Mobile Identity"); + nas_5gs_send_registration_reject(amf_ue, + OGS_5GMM_CAUSE_SEMANTICALLY_INCORRECT_MESSAGE); + return OGS_ERROR; + } + mobile_identity_header = (ogs_nas_5gs_mobile_identity_header_t *)mobile_identity->buffer; - ogs_assert(mobile_identity_header); - - ogs_assert(amf_ue); - ran_ue = amf_ue->ran_ue; - ogs_assert(ran_ue); switch (mobile_identity_header->type) { case OGS_NAS_5GS_MOBILE_IDENTITY_SUCI: @@ -61,13 +69,13 @@ int gmm_handle_registration_request(amf_ue_t *amf_ue, case OGS_NAS_5GS_MOBILE_IDENTITY_GUTI: mobile_identity_guti = (ogs_nas_5gs_mobile_identity_guti_t *)mobile_identity->buffer; - ogs_assert(mobile_identity_guti); + if (!mobile_identity_guti) { + ogs_error("No mobile identity"); + return OGS_ERROR; + } - memcpy(&nas_guti.nas_plmn_id, - &mobile_identity_guti->nas_plmn_id, OGS_PLMN_ID_LEN); - memcpy(&nas_guti.amf_id, - &mobile_identity_guti->amf_id, sizeof(ogs_amf_id_t)); - nas_guti.m_tmsi = be32toh(mobile_identity_guti->m_tmsi); + ogs_nas_5gs_mobile_identity_guti_to_nas_guti( + mobile_identity_guti, &nas_guti); ogs_debug("[%s] 5G-S_GUTI[AMF_ID:0x%x,M_TMSI:0x%x]", AMF_UE_HAVE_SUCI(amf_ue) ? amf_ue->suci : "Unknown ID", @@ -102,7 +110,6 @@ int gmm_handle_registration_request(amf_ue_t *amf_ue, */ CLEAR_AMF_UE_ALL_TIMERS(amf_ue); - CLEAR_5GS_BEARER_ID(amf_ue); if (SECURITY_CONTEXT_IS_VALID(amf_ue)) { ogs_kdf_kgnb_and_kn3iwf( amf_ue->kamf, amf_ue->ul_count.i32, @@ -191,6 +198,56 @@ int gmm_handle_registration_request(amf_ue_t *amf_ue, return OGS_OK; } +int gmm_handle_registration_update(amf_ue_t *amf_ue, + ogs_nas_5gs_registration_request_t *registration_request) +{ + amf_sess_t *sess = NULL; + uint16_t psimask = 0; + bool handled = false; + + amf_nsmf_pdu_session_update_sm_context_param_t param; + ogs_nas_uplink_data_status_t *uplink_data_status = NULL; + + ogs_assert(amf_ue); + ogs_assert(registration_request); + + uplink_data_status = ®istration_request->uplink_data_status; + ogs_assert(uplink_data_status); + + if ((registration_request->presencemask & + OGS_NAS_5GS_REGISTRATION_REQUEST_UPLINK_DATA_STATUS_PRESENT) == 0) { + ogs_error("No Update data status"); + return OGS_ERROR; + } + + psimask = 0; + psimask |= uplink_data_status->psi << 8; + psimask |= uplink_data_status->psi >> 8; + + handled = false; + ogs_list_for_each(&amf_ue->sess_list, sess) { + if (psimask & (1 << sess->psi)) { + /* UPDATE_UpCnxState - UE: ACTIVATING, SMF: DEACTIVATED */ + sess->ueUpCnxState = OpenAPI_up_cnx_state_ACTIVATING; + sess->smfUpCnxState = OpenAPI_up_cnx_state_DEACTIVATED; + + memset(¶m, 0, sizeof(param)); + param.upCnxState = sess->ueUpCnxState; + amf_sess_sbi_discover_and_send( + OpenAPI_nf_type_SMF, sess, ¶m, + amf_nsmf_pdu_session_build_update_sm_context); + handled = true; + } + } + + if (handled == false) { + ogs_error("Cannot find PSI[0x%x]", uplink_data_status->psi); + return OGS_ERROR; + } + + return OGS_OK; +} + int gmm_handle_authentication_response(amf_ue_t *amf_ue, ogs_nas_5gs_authentication_response_t *authentication_response) { @@ -236,13 +293,14 @@ int gmm_handle_authentication_response(amf_ue_t *amf_ue, return OGS_OK; } -#if 0 int gmm_handle_identity_response(amf_ue_t *amf_ue, ogs_nas_5gs_identity_response_t *identity_response) { - ogs_nas_mobile_identity_t *mobile_identity = NULL; ran_ue_t *ran_ue = NULL; + ogs_nas_5gs_mobile_identity_t *mobile_identity = NULL; + ogs_nas_5gs_mobile_identity_header_t *mobile_identity_header = NULL; + ogs_assert(identity_response); ogs_assert(amf_ue); @@ -251,27 +309,20 @@ int gmm_handle_identity_response(amf_ue_t *amf_ue, mobile_identity = &identity_response->mobile_identity; - if (mobile_identity->imsi.type == OGS_NAS_IDENTITY_TYPE_2_IMSI) { - char imsi_bcd[OGS_MAX_IMSI_BCD_LEN+1]; + if (!mobile_identity->length || !mobile_identity->buffer) { + ogs_error("No Mobile Identity"); + return OGS_ERROR; + } - if (sizeof(ogs_nas_mobile_identity_imsi_t) != mobile_identity->length) { - ogs_error("mobile_identity length (%d != %d)", - (int)sizeof(ogs_nas_mobile_identity_imsi_t), - mobile_identity->length); - return OGS_ERROR; - } - memcpy(&amf_ue->nas_mobile_identity_imsi, - &mobile_identity->imsi, mobile_identity->length); - ogs_nas_imsi_to_bcd( - &mobile_identity->imsi, mobile_identity->length, imsi_bcd); - amf_ue_set_imsi(amf_ue, imsi_bcd); + mobile_identity_header = + (ogs_nas_5gs_mobile_identity_header_t *)mobile_identity->buffer; - if (amf_ue->imsi_len != OGS_MAX_IMSI_LEN) { - ogs_error("Invalid IMSI LEN[%d]", amf_ue->imsi_len); - return OGS_ERROR; - } + if (mobile_identity_header->type == OGS_NAS_5GS_MOBILE_IDENTITY_SUCI) { + amf_ue_set_suci(amf_ue, mobile_identity); + ogs_debug("[%s] SUCI", amf_ue->suci); } else { - ogs_warn("Not supported Identity type[%d]", mobile_identity->imsi.type); + ogs_error("Not supported Identity type[%d]", + mobile_identity_header->type); } return OGS_OK; @@ -280,59 +331,55 @@ int gmm_handle_identity_response(amf_ue_t *amf_ue, int gmm_handle_deregistration_request(amf_ue_t *amf_ue, ogs_nas_5gs_deregistration_request_from_ue_t *deregistration_request) { - ogs_nas_deregistration_type_t *deregistration_type = NULL; + ogs_nas_de_registration_type_t *de_registration_type = NULL; - ogs_assert(deregistration_request); ogs_assert(amf_ue); + ogs_assert(deregistration_request); - deregistration_type = &deregistration_request->deregistration_type; + de_registration_type = &deregistration_request->de_registration_type; + + ogs_debug("[%s] Deregistration request", amf_ue->supi); /* Set 5GS Attach Type */ - memcpy(&amf_ue->nas.deregistration, deregistration_type, sizeof(ogs_nas_deregistration_type_t)); - amf_ue->nas.message_type = AMF_5GS_TYPE_DETACH_REQUEST_FROM_UE; - amf_ue->nas.ksi = deregistration_type->nas_key_set_identifier; - ogs_debug(" OGS_NAS_5GS TYPE[%d] TSC[%d] KSI[%d] DETACH[0x%x]", - amf_ue->nas.message_type, amf_ue->nas.tsc, amf_ue->nas.ksi, amf_ue->nas.data); + memcpy(&amf_ue->nas.de_registration, + de_registration_type, sizeof(ogs_nas_de_registration_type_t)); + amf_ue->nas.message_type = OGS_NAS_5GS_DEREGISTRATION_REQUEST; + amf_ue->nas.tsc = de_registration_type->tsc; + amf_ue->nas.ksi = de_registration_type->ksi; + ogs_debug("[%s] OGS_NAS_5GS TYPE[%d] TSC[%d] KSI[%d] " + "DEREGISTRATION[0x%x]", + amf_ue->suci, amf_ue->nas.message_type, + amf_ue->nas.tsc, amf_ue->nas.ksi, amf_ue->nas.data); - switch (deregistration_request->deregistration_type.value) { - /* 0 0 1 : 5GS deregistration */ - case OGS_NAS_DETACH_TYPE_FROM_UE_5GS_DETACH: - ogs_debug(" 5GS Detach"); - break; - /* 0 1 0 : IMSI deregistration */ - case OGS_NAS_DETACH_TYPE_FROM_UE_IMSI_DETACH: - ogs_debug(" IMSI Detach"); - break; - case 6: /* 1 1 0 : reserved */ - case 7: /* 1 1 1 : reserved */ - ogs_warn("Unknown Detach type[%d]", - deregistration_request->deregistration_type.value); - break; - /* 0 1 1 : combined 5GS/IMSI deregistration */ - case OGS_NAS_DETACH_TYPE_FROM_UE_COMBINED_5GS_IMSI_DETACH: - ogs_debug(" Combined 5GS/IMSI Detach"); - default: /* all other values */ - break; - } - if (deregistration_request->deregistration_type.switch_off) + if (deregistration_request->de_registration_type.switch_off) ogs_debug(" Switch-Off"); + amf_send_delete_session_or_de_register(amf_ue); + return OGS_OK; } int gmm_handle_service_request(amf_ue_t *amf_ue, ogs_nas_5gs_service_request_t *service_request) { - ogs_nas_ksi_and_sequence_number_t *ksi_and_sequence_number = - &service_request->ksi_and_sequence_number; + amf_sess_t *sess = NULL; + ogs_nas_key_set_identifier_t *ngksi = NULL; + ogs_nas_uplink_data_status_t *uplink_data_status = NULL; + uint16_t psimask = 0; + bool need_to_activating = false; ogs_assert(amf_ue); - /* Set 5GS Update Type */ - amf_ue->nas.message_type = AMF_5GS_TYPE_SERVICE_REQUEST; - amf_ue->nas.ksi = ksi_and_sequence_number->ksi; - ogs_debug(" OGS_NAS_5GS TYPE[%d] KSI[%d]", - amf_ue->nas.message_type, amf_ue->nas.ksi); + ngksi = &service_request->ngksi; + ogs_assert(ngksi); + uplink_data_status = &service_request->uplink_data_status; + + amf_ue->nas.message_type = OGS_NAS_5GS_SERVICE_REQUEST; + amf_ue->nas.tsc = ngksi->tsc; + amf_ue->nas.ksi = ngksi->value; + ogs_debug("[%s] OGS_NAS_5GS TYPE[%d] TSC[%d] KSI[%d] SERVICE[0x%x]", + amf_ue->suci, amf_ue->nas.message_type, + amf_ue->nas.tsc, amf_ue->nas.ksi, amf_ue->nas.data); /* * REGISTRATION_REQUEST @@ -353,20 +400,105 @@ int gmm_handle_service_request(amf_ue_t *amf_ue, if (SECURITY_CONTEXT_IS_VALID(amf_ue)) { ogs_kdf_kgnb_and_kn3iwf( amf_ue->kamf, amf_ue->ul_count.i32, - OGS_KDF_ACCESS_TYPE_3GPP, amf_ue->kgnb); + amf_ue->nas.access_type, amf_ue->kgnb); ogs_kdf_nh_gnb(amf_ue->kamf, amf_ue->kgnb, amf_ue->nh); amf_ue->nhcc = 1; } - ogs_debug(" GUTI[G:%d,C:%d,M_TMSI:0x%x] IMSI[%s]", - amf_ue->guti.amf_gid, - amf_ue->guti.amf_code, - amf_ue->guti.m_tmsi, - AMF_UE_HAVE_IMSI(amf_ue) ? amf_ue->imsi_bcd : "Unknown"); + ogs_debug("[%s] 5G-S_GUTI[AMF_ID:0x%x,M_TMSI:0x%x]", + AMF_UE_HAVE_SUCI(amf_ue) ? amf_ue->suci : "Unknown ID", + ogs_amf_id_hexdump(&amf_ue->guti.amf_id), amf_ue->guti.m_tmsi); + + if (!AMF_UE_HAVE_SUCI(amf_ue)) { + ogs_debug("Service request : Unknown UE"); + nas_5gs_send_service_reject(amf_ue, + OGS_5GMM_CAUSE_UE_IDENTITY_CANNOT_BE_DERIVED_BY_THE_NETWORK, false); + return OGS_ERROR; + } + + if (!SECURITY_CONTEXT_IS_VALID(amf_ue)) { + ogs_debug("[%s] No Security Context", amf_ue->supi); + nas_5gs_send_service_reject(amf_ue, + OGS_5GMM_CAUSE_UE_IDENTITY_CANNOT_BE_DERIVED_BY_THE_NETWORK, false); + return OGS_ERROR; + } + + if (!SESSION_CONTEXT_IS_AVAILABLE(amf_ue)) { + ogs_debug("[%s] No Session Context", amf_ue->supi); + nas_5gs_send_service_reject(amf_ue, + OGS_5GMM_CAUSE_UE_IDENTITY_CANNOT_BE_DERIVED_BY_THE_NETWORK, false); + return OGS_ERROR; + } + + if ((service_request->presencemask & + OGS_NAS_5GS_SERVICE_REQUEST_UPLINK_DATA_STATUS_PRESENT) == 0) { + ogs_error("No Update data status"); + nas_5gs_send_service_reject(amf_ue, + OGS_5GMM_CAUSE_SEMANTICALLY_INCORRECT_MESSAGE, false); + return OGS_ERROR; + } + + psimask = 0; + psimask |= uplink_data_status->psi << 8; + psimask |= uplink_data_status->psi >> 8; + + /* + * TS24.501 + * 5.6.1.5 Service request procedure not accepted by the network + * + * If the AMF needs to initiate PDU session status synchronisation + * or a PDU session status IE was included in the SERVICE REQUEST message, + * the AMF shall include a PDU session status IE in the SERVICE REJECT + * message to indicate which PDU sessions associated with the access type + * the SERVICE REJECT message is sent over are active in the AMF. + * If the PDU session status IE is included in the SERVICE REJECT message + * and if the message is integrity protected, then the UE shall perform + * a local release of all those PDU sessions which are active + * on the UE side associated with the access type the SERVICE REJECT + * message is sent over, but are indicated by the AMF as being inactive. + */ + need_to_activating = false; + ogs_list_for_each(&amf_ue->sess_list, sess) { + if (psimask & (1 << sess->psi)) { + if (sess->smfUpCnxState == OpenAPI_up_cnx_state_DEACTIVATED) { + need_to_activating = true; + + } else if (sess->smfUpCnxState == OpenAPI_up_cnx_state_ACTIVATED) { + nas_5gs_send_service_reject(amf_ue, + OGS_5GMM_CAUSE_UE_IDENTITY_CANNOT_BE_DERIVED_BY_THE_NETWORK, + true); + return OGS_ERROR; + + } else if (sess->smfUpCnxState == OpenAPI_up_cnx_state_ACTIVATING) { + ogs_warn("Service request has already been received"); + /* Ignore */ + } + } + } + + if (need_to_activating) { + ogs_list_for_each(&amf_ue->sess_list, sess) { + if (psimask & (1 << sess->psi)) { + if (sess->smfUpCnxState == OpenAPI_up_cnx_state_DEACTIVATED) { + amf_nsmf_pdu_session_update_sm_context_param_t param; + + /* UPDATE_UpCnxState - ACTIVATING */ + sess->ueUpCnxState = OpenAPI_up_cnx_state_ACTIVATING; + + memset(¶m, 0, sizeof(param)); + param.upCnxState = OpenAPI_up_cnx_state_ACTIVATING; + amf_sess_sbi_discover_and_send( + OpenAPI_nf_type_SMF, sess, ¶m, + amf_nsmf_pdu_session_build_update_sm_context); + } + } + } + } return OGS_OK; } +#if 0 int gmm_handle_tau_request(amf_ue_t *amf_ue, ogs_nas_5gs_tracking_area_update_request_t *tau_request) { diff --git a/src/amf/gmm-handler.h b/src/amf/gmm-handler.h index 5d4fb6ada..dfbc47855 100644 --- a/src/amf/gmm-handler.h +++ b/src/amf/gmm-handler.h @@ -28,6 +28,8 @@ extern "C" { int gmm_handle_registration_request(amf_ue_t *amf_ue, ogs_nas_5gs_registration_request_t *registration_request); +int gmm_handle_registration_update(amf_ue_t *amf_ue, + ogs_nas_5gs_registration_request_t *registration_request); int gmm_handle_authentication_response(amf_ue_t *amf_ue, ogs_nas_5gs_authentication_response_t *authentication_response); diff --git a/src/amf/gmm-sm.c b/src/amf/gmm-sm.c index 5cbc259e5..c3a2b2fe7 100644 --- a/src/amf/gmm-sm.c +++ b/src/amf/gmm-sm.c @@ -20,17 +20,10 @@ #include "ngap-handler.h" #include "gmm-handler.h" #include "gmm-build.h" -#if 0 -#include "gsm-handler.h" -#endif #include "nas-path.h" #include "nas-security.h" #include "ngap-path.h" -#if 0 -#include "sgsap-types.h" -#include "sgsap-path.h" #include "amf-path.h" -#endif #include "nausf-handler.h" #include "nsmf-handler.h" #include "sbi-path.h" @@ -102,6 +95,7 @@ static void common_register_state(ogs_fsm_t *s, amf_event_t *e) #if 0 NGAP_ProcedureCode_t procedureCode; #endif + ogs_nas_security_header_type_t h; ogs_sbi_response_t *sbi_response = NULL; ogs_sbi_message_t *sbi_message = NULL; @@ -129,51 +123,8 @@ static void common_register_state(ogs_fsm_t *s, amf_event_t *e) ran_ue = amf_ue->ran_ue; ogs_assert(ran_ue); -#if 0 - if (nas_message->gmm.h.security_header_type - == OGS_NAS_SECURITY_HEADER_FOR_SERVICE_REQUEST_MESSAGE) { - ogs_debug("Service request"); - rv = gmm_handle_service_request( - amf_ue, &nas_message->gmm.service_request); - if (rv != OGS_OK) { - ogs_error("gmm_handle_service_request() failed"); - OGS_FSM_TRAN(s, gmm_state_exception); - return; - } - - if (!AMF_UE_HAVE_IMSI(amf_ue)) { - ogs_warn("Service request : Unknown UE"); - nas_5gs_send_service_reject(amf_ue, - GMM_CAUSE_UE_IDENTITY_CANNOT_BE_DERIVED_BY_THE_NETWORK); - OGS_FSM_TRAN(s, &gmm_state_exception); - return; - } - - if (!SECURITY_CONTEXT_IS_VALID(amf_ue)) { - ogs_warn("No Security Context : IMSI[%s]", amf_ue->imsi_bcd); - nas_5gs_send_service_reject(amf_ue, - GMM_CAUSE_UE_IDENTITY_CANNOT_BE_DERIVED_BY_THE_NETWORK); - OGS_FSM_TRAN(s, &gmm_state_exception); - return; - } - - if (!SESSION_CONTEXT_IS_AVAILABLE(amf_ue)) { - ogs_warn("No Session Context : IMSI[%s]", amf_ue->imsi_bcd); - nas_5gs_send_service_reject(amf_ue, - GMM_CAUSE_UE_IDENTITY_CANNOT_BE_DERIVED_BY_THE_NETWORK); - OGS_FSM_TRAN(s, &gmm_state_exception); - return; - } - - ngap_send_initial_context_setup_request(amf_ue); - return; - } -#endif - switch (nas_message->gmm.h.message_type) { -#if 0 case OGS_NAS_5GS_IDENTITY_RESPONSE: - ogs_debug("Identity response"); CLEAR_AMF_UE_TIMER(amf_ue->t3570); rv = gmm_handle_identity_response(amf_ue, @@ -184,15 +135,13 @@ static void common_register_state(ogs_fsm_t *s, amf_event_t *e) return; } - if (!AMF_UE_HAVE_IMSI(amf_ue)) { - ogs_error("No IMSI"); + if (!AMF_UE_HAVE_SUCI(amf_ue)) { + ogs_error("No SUCI"); OGS_FSM_TRAN(s, gmm_state_exception); return; } - ogs_debug(" IMSI[%s]", amf_ue->imsi_bcd); break; -#endif case OGS_NAS_5GS_REGISTRATION_REQUEST: ogs_debug("Registration request"); rv = gmm_handle_registration_request( @@ -203,9 +152,20 @@ static void common_register_state(ogs_fsm_t *s, amf_event_t *e) return; } break; + + case OGS_NAS_5GS_SERVICE_REQUEST: + ogs_debug("[%s] Service request", amf_ue->supi); + rv = gmm_handle_service_request( + amf_ue, &nas_message->gmm.service_request); + if (rv != OGS_OK) { + ogs_error("gmm_handle_service_request() failed"); + OGS_FSM_TRAN(s, gmm_state_exception); + } + return; #if 0 case OGS_NAS_5GS_TRACKING_AREA_UPDATE_REQUEST: - ogs_debug("Tracking area update request"); + ogs_error("[%s] Tracking area update request", + amf_ue->supi); rv = gmm_handle_tau_request( amf_ue, &nas_message->gmm.tracking_area_update_request); if (rv != OGS_OK) { @@ -214,66 +174,30 @@ static void common_register_state(ogs_fsm_t *s, amf_event_t *e) return; } - if (!AMF_UE_HAVE_IMSI(amf_ue)) { + if (!AMF_UE_HAVE_SUCI(amf_ue)) { ogs_warn("TAU request : Unknown UE"); nas_5gs_send_tau_reject(amf_ue, GMM_CAUSE_UE_IDENTITY_CANNOT_BE_DERIVED_BY_THE_NETWORK); OGS_FSM_TRAN(s, &gmm_state_exception); return; } - break; case OGS_NAS_5GS_TRACKING_AREA_UPDATE_COMPLETE: - ogs_debug("Tracking area update complete"); - ogs_debug(" IMSI[%s]", amf_ue->imsi_bcd); + ogs_error("[%s] Tracking area update complete", amf_ue->supi); return; - case OGS_NAS_5GS_EXTENDED_SERVICE_REQUEST: - ogs_debug("Extended service request"); - rv = gmm_handle_extended_service_request( - amf_ue, &nas_message->gmm.extended_service_request); - if (rv != OGS_OK) { - ogs_error("gmm_handle_extended_service_request() failed"); - OGS_FSM_TRAN(s, gmm_state_exception); - return; - } - - if (!AMF_UE_HAVE_IMSI(amf_ue)) { - ogs_warn("Extended Service request : Unknown UE"); - nas_5gs_send_service_reject(amf_ue, - GMM_CAUSE_UE_IDENTITY_CANNOT_BE_DERIVED_BY_THE_NETWORK); - OGS_FSM_TRAN(s, &gmm_state_exception); - return; - } - - break; #endif case OGS_NAS_5GS_5GMM_STATUS: ogs_warn("[%s] 5GMM STATUS : Cause[%d]", amf_ue->suci, nas_message->gmm.gmm_status.gmm_cause); OGS_FSM_TRAN(s, &gmm_state_exception); return; -#if 0 + case OGS_NAS_5GS_DEREGISTRATION_REQUEST: - ogs_debug("Deregistration request"); - ogs_debug(" IMSI[%s]", amf_ue->imsi_bcd); - rv = gmm_handle_deregistration_request( + gmm_handle_deregistration_request( amf_ue, &nas_message->gmm.deregistration_request_from_ue); - if (rv != OGS_OK) - { - ogs_error("gmm_handle_registration_request() failed"); - OGS_FSM_TRAN(s, gmm_state_exception); - return; - } - - if (AMF_P_TMSI_IS_AVAILABLE(amf_ue)) { - sgsap_send_deregistration_indication(amf_ue); - } else { - amf_send_delete_session_or_deregistration(amf_ue); - } - OGS_FSM_TRAN(s, &gmm_state_de_registered); return; -#endif + case OGS_NAS_5GS_CONFIGURATION_UPDATE_COMPLETE: ogs_debug("[%s] Configuration update complete", amf_ue->supi); @@ -301,21 +225,17 @@ static void common_register_state(ogs_fsm_t *s, amf_event_t *e) sbi_message = e->sbi.message; ogs_assert(sbi_message); + ogs_assert(sess); + SWITCH(sbi_message->h.service.name) CASE(OGS_SBI_SERVICE_NAME_NSMF_PDUSESSION) - ogs_assert(sess); - ogs_timer_stop(sess->sbi.client_wait.timer); - SWITCH(sbi_message->h.resource.component[2]) CASE(OGS_SBI_RESOURCE_NAME_MODIFY) amf_nsmf_pdu_session_handle_update_sm_context( sess, sbi_message); break; - CASE(OGS_SBI_RESOURCE_NAME_RELEASE) - ogs_fatal("asdfasdfasdf"); - break; DEFAULT amf_nsmf_pdu_session_handle_create_sm_context( sess, sbi_message); @@ -326,7 +246,7 @@ static void common_register_state(ogs_fsm_t *s, amf_event_t *e) ogs_error("Invalid service name [%s]", sbi_message->h.service.name); ogs_assert_if_reached(); END - break; + return; case AMF_EVT_5GMM_TIMER: switch (e->timer_id) { @@ -349,6 +269,7 @@ static void common_register_state(ogs_fsm_t *s, amf_event_t *e) #endif } break; + case AMF_TIMER_T3555: if (amf_ue->t3555.retry_count >= amf_timer_cfg(AMF_TIMER_T3555)->max_count) { @@ -367,6 +288,7 @@ static void common_register_state(ogs_fsm_t *s, amf_event_t *e) nas_5gs_send_configuration_update_command(amf_ue, 1, 0); } break; + case AMF_TIMER_T3570: if (amf_ue->t3570.retry_count >= amf_timer_cfg(AMF_TIMER_T3570)->max_count) { @@ -376,15 +298,13 @@ static void common_register_state(ogs_fsm_t *s, amf_event_t *e) OGS_FSM_TRAN(&amf_ue->sm, &gmm_state_exception); } else { amf_ue->t3570.retry_count++; -#if 0 nas_5gs_send_identity_request(amf_ue); -#endif } break; + default: ogs_error("Unknown timer[%s:%d]", amf_timer_get_name(e->timer_id), e->timer_id); - break; } return; default: @@ -392,44 +312,37 @@ static void common_register_state(ogs_fsm_t *s, amf_event_t *e) return; } -#if 0 - if (!AMF_UE_HAVE_IMSI(amf_ue)) { + if (!AMF_UE_HAVE_SUCI(amf_ue)) { CLEAR_AMF_UE_TIMER(amf_ue->t3570); nas_5gs_send_identity_request(amf_ue); return; } -#endif ran_ue = amf_ue->ran_ue; ogs_assert(ran_ue); switch (amf_ue->nas.message_type) { case OGS_NAS_5GS_REGISTRATION_REQUEST: - if (SECURITY_CONTEXT_IS_VALID(amf_ue)) { -#if 0 - rv = nas_5gs_send_emm_to_esm(amf_ue, - &amf_ue->pdn_connectivity_request); + h.type = e->nas.type; + if (h.integrity_protected && SECURITY_CONTEXT_IS_VALID(amf_ue)) { + rv = gmm_handle_registration_update( + amf_ue, &nas_message->gmm.registration_request); if (rv != OGS_OK) { - ogs_error("nas_5gs_send_emm_to_esm() failed"); - nas_5gs_send_attach_reject(amf_ue, - GMM_CAUSE_PROTOCOL_ERROR_UNSPECIFIED, - GSM_CAUSE_PROTOCOL_ERROR_UNSPECIFIED); - OGS_FSM_TRAN(s, &gmm_state_exception); - } else { - OGS_FSM_TRAN(s, &gmm_state_initial_context_setup); + ogs_error("gmm_handle_registration_update() failed"); + + amf_sbi_send_release_all_sm_contexts(amf_ue); + OGS_FSM_TRAN(s, &gmm_state_authentication); + break; } -#endif + + OGS_FSM_TRAN(s, &gmm_state_initial_context_setup); } else { -#if 0 if (SESSION_CONTEXT_IS_AVAILABLE(amf_ue)) { - amf_gtp_send_delete_all_sessions(amf_ue); + amf_sbi_send_release_all_sm_contexts(amf_ue); } else { - amf_sbi_send_authenticate(amf_ue); + amf_ue_sbi_discover_and_send(OpenAPI_nf_type_AUSF, amf_ue, NULL, + amf_nausf_auth_build_authenticate); } -#else - amf_ue_sbi_discover_and_send(OpenAPI_nf_type_AUSF, amf_ue, NULL, - amf_nausf_auth_build_authenticate); -#endif OGS_FSM_TRAN(s, &gmm_state_authentication); } break; @@ -468,91 +381,10 @@ static void common_register_state(ogs_fsm_t *s, amf_event_t *e) } else { ogs_fatal("Invalid Procedure Code[%d]", (int)procedureCode); } - break; - case AMF_EPS_TYPE_EXTENDED_SERVICE_REQUEST: - procedureCode = e->ngap_code; - - if (!AMF_P_TMSI_IS_AVAILABLE(amf_ue)) { - ogs_warn("No P-TMSI : UE[%s]", amf_ue->imsi_bcd); - nas_5gs_send_service_reject(amf_ue, - GMM_CAUSE_UE_IDENTITY_CANNOT_BE_DERIVED_BY_THE_NETWORK); - OGS_FSM_TRAN(s, gmm_state_exception); - break; - } - - if (!SESSION_CONTEXT_IS_AVAILABLE(amf_ue)) { - ogs_warn("No PDN Connection : UE[%s]", amf_ue->imsi_bcd); - nas_5gs_send_service_reject(amf_ue, - GMM_CAUSE_UE_IDENTITY_CANNOT_BE_DERIVED_BY_THE_NETWORK); - OGS_FSM_TRAN(s, gmm_state_exception); - break; - } - - if (!SECURITY_CONTEXT_IS_VALID(amf_ue)) { - ogs_warn("No Security Context : IMSI[%s]", amf_ue->imsi_bcd); - nas_5gs_send_service_reject(amf_ue, - GMM_CAUSE_UE_IDENTITY_CANNOT_BE_DERIVED_BY_THE_NETWORK); - OGS_FSM_TRAN(s, &gmm_state_exception); - return; - } - - if (procedureCode == NGAP_ProcedureCode_id_initialUEMessage) { - ogs_debug(" Initial UE Message"); - if (amf_ue->nas_5gs.service.value == - OGS_NAS_SERVICE_TYPE_CS_FALLBACK_FROM_UE || - amf_ue->nas_5gs.service.value == - OGS_NAS_SERVICE_TYPE_CS_FALLBACK_EMERGENCY_CALL_FROM_UE) { - ogs_debug(" MO-CSFB-INDICATION[%d]", - amf_ue->nas_5gs.service.value); - sgsap_send_mo_csfb_indication(amf_ue); - } else if (amf_ue->nas_5gs.service.value == - OGS_NAS_SERVICE_TYPE_CS_FALLBACK_TO_UE) { - ogs_debug(" SERVICE_REQUEST[%d]", - amf_ue->nas_5gs.service.value); - sgsap_send_service_request(amf_ue, SGSAP_EMM_IDLE_MODE); - } else { - ogs_warn(" Unknown CSFB Service Type[%d]", - amf_ue->nas_5gs.service.value); - nas_5gs_send_service_reject(amf_ue, - GMM_CAUSE_UE_IDENTITY_CANNOT_BE_DERIVED_BY_THE_NETWORK); - OGS_FSM_TRAN(s, &gmm_state_exception); - return; - } - - ngap_send_initial_context_setup_request(amf_ue); - - } else if (procedureCode == NGAP_ProcedureCode_id_uplinkNASTransport) { - ogs_debug(" Uplink NAS Transport"); - if (amf_ue->nas_5gs.service.value == - OGS_NAS_SERVICE_TYPE_CS_FALLBACK_FROM_UE || - amf_ue->nas_5gs.service.value == - OGS_NAS_SERVICE_TYPE_CS_FALLBACK_EMERGENCY_CALL_FROM_UE) { - ogs_debug(" MO-CSFB-INDICATION[%d]", - amf_ue->nas_5gs.service.value); - sgsap_send_mo_csfb_indication(amf_ue); - } else if (amf_ue->nas_5gs.service.value == - OGS_NAS_SERVICE_TYPE_CS_FALLBACK_TO_UE) { - ogs_debug(" SERVICE_REQUEST[%d]", - amf_ue->nas_5gs.service.value); - sgsap_send_service_request(amf_ue, SGSAP_EMM_CONNECTED_MODE); - } else { - ogs_warn(" Unknown CSFB Service Type[%d]", - amf_ue->nas_5gs.service.value); - nas_5gs_send_service_reject(amf_ue, - GMM_CAUSE_UE_IDENTITY_CANNOT_BE_DERIVED_BY_THE_NETWORK); - OGS_FSM_TRAN(s, &gmm_state_exception); - return; - } - - ngap_send_ue_context_modification_request(amf_ue); - } else { - ogs_fatal("Invalid Procedure Code[%d]", (int)procedureCode); - } - break; #endif default: - ogs_fatal("Invalid NAS-5GS[%d]", amf_ue->nas.message_type); + ogs_error("Invalid NAS-5GS[%d]", amf_ue->nas.message_type); break; } } @@ -561,8 +393,14 @@ void gmm_state_authentication(ogs_fsm_t *s, amf_event_t *e) { int rv; amf_ue_t *amf_ue = NULL; + amf_sess_t *sess = NULL; + ogs_nas_5gs_message_t *nas_message = NULL; + ogs_nas_5gs_authentication_failure_t *authentication_failure = NULL; + ogs_nas_authentication_failure_parameter_t + *authentication_failure_parameter = NULL; + ogs_sbi_response_t *sbi_response = NULL; ogs_sbi_message_t *sbi_message = NULL; @@ -571,8 +409,14 @@ void gmm_state_authentication(ogs_fsm_t *s, amf_event_t *e) amf_sm_debug(e); - amf_ue = e->amf_ue; - ogs_assert(amf_ue); + if (e->sess) { + sess = e->sess; + amf_ue = sess->amf_ue; + ogs_assert(amf_ue); + } else { + amf_ue = e->amf_ue; + ogs_assert(amf_ue); + } switch (e->id) { case OGS_FSM_ENTRY_SIG: @@ -595,35 +439,35 @@ void gmm_state_authentication(ogs_fsm_t *s, amf_event_t *e) break; case OGS_NAS_5GS_AUTHENTICATION_FAILURE: - { - ogs_fatal("[%s] Not implemented", amf_ue->suci); - ogs_assert_if_reached(); -#if 0 - ogs_nas_5gs_authentication_failure_t *authentication_failure = - &nas_message->gmm.authentication_failure; - ogs_nas_authentication_failure_parameter_t - *authentication_failure_parameter = - &authentication_failure-> - authentication_failure_parameter; + authentication_failure = &nas_message->gmm.authentication_failure; + ogs_assert(authentication_failure); + authentication_failure_parameter = &authentication_failure-> + authentication_failure_parameter; + ogs_assert(authentication_failure_parameter); - ogs_debug("Authentication failure"); - ogs_debug(" IMSI[%s] GMM_CAUSE[%d]", amf_ue->imsi_bcd, + ogs_debug("[%s] Authentication failure [%d]", amf_ue->suci, authentication_failure->gmm_cause); CLEAR_AMF_UE_TIMER(amf_ue->t3560); switch (authentication_failure->gmm_cause) { - case GMM_CAUSE_MAC_FAILURE: + case OGS_5GMM_CAUSE_MAC_FAILURE: ogs_warn("Authentication failure(MAC failure)"); break; - case GMM_CAUSE_NON_EPS_AUTHENTICATION_UNACCEPTABLE: + case OGS_5GMM_CAUSE_NON_5G_AUTHENTICATION_UNACCEPTABLE: ogs_error("Authentication failure" - "(Non-EPS authentication unacceptable)"); + "(Non-5GS authentication unacceptable)"); break; - case GMM_CAUSE_SYNCH_FAILURE: + case OGS_5GMM_CAUSE_SYNCH_FAILURE: ogs_warn("Authentication failure(Synch failure)"); - amf_s6a_send_air(amf_ue, - authentication_failure_parameter); + if (authentication_failure_parameter->length != OGS_AUTS_LEN) { + ogs_error("Invalid AUTS Length [%d]", + authentication_failure_parameter->length); + break; + } + amf_ue_sbi_discover_and_send(OpenAPI_nf_type_AUSF, amf_ue, + authentication_failure_parameter->auts, + amf_nausf_auth_build_authenticate); return; default: ogs_error("Unknown GMM_CAUSE{%d] in Authentication" @@ -634,10 +478,8 @@ void gmm_state_authentication(ogs_fsm_t *s, amf_event_t *e) nas_5gs_send_authentication_reject(amf_ue); OGS_FSM_TRAN(&amf_ue->sm, &gmm_state_exception); -#endif break; - } case OGS_NAS_5GS_REGISTRATION_REQUEST: ogs_warn("Registration request"); rv = gmm_handle_registration_request( @@ -659,20 +501,11 @@ void gmm_state_authentication(ogs_fsm_t *s, amf_event_t *e) break; case OGS_NAS_5GS_DEREGISTRATION_REQUEST: - ogs_debug("[%s] Deregistration request", amf_ue->suci); -#if 0 - rv = gmm_handle_deregistration_request( + gmm_handle_deregistration_request( amf_ue, &nas_message->gmm.deregistration_request_from_ue); - if (rv != OGS_OK) { - ogs_error("gmm_handle_registration_request() failed"); - OGS_FSM_TRAN(s, gmm_state_exception); - return; - } - - amf_send_delete_session_or_deregistration(amf_ue); -#endif OGS_FSM_TRAN(s, &gmm_state_de_registered); break; + default: ogs_warn("Unknown message[%d]", nas_message->gmm.h.message_type); break; @@ -704,52 +537,70 @@ void gmm_state_authentication(ogs_fsm_t *s, amf_event_t *e) sbi_message = e->sbi.message; ogs_assert(sbi_message); - SWITCH(sbi_message->h.resource.component[0]) - CASE(OGS_SBI_RESOURCE_NAME_UE_AUTHENTICATIONS) - ogs_timer_stop(amf_ue->sbi.client_wait.timer); + SWITCH(sbi_message->h.service.name) + CASE(OGS_SBI_SERVICE_NAME_NAUSF_AUTH) + SWITCH(sbi_message->h.resource.component[0]) + CASE(OGS_SBI_RESOURCE_NAME_UE_AUTHENTICATIONS) - if (sbi_message->res_status != OGS_SBI_HTTP_STATUS_CREATED && - sbi_message->res_status != OGS_SBI_HTTP_STATUS_OK) { - ogs_error("[%s] HTTP response error [%d]", - amf_ue->suci, sbi_message->res_status); - nas_5gs_send_authentication_reject(amf_ue); - OGS_FSM_TRAN(&amf_ue->sm, &gmm_state_exception); - break; - } + if (sbi_message->res_status != OGS_SBI_HTTP_STATUS_CREATED && + sbi_message->res_status != OGS_SBI_HTTP_STATUS_OK) { + if (sbi_message->res_status == + OGS_SBI_HTTP_STATUS_NOT_FOUND) { + ogs_warn("[%s] Cannot find SUCI [%d]", + amf_ue->suci, sbi_message->res_status); + } else { + ogs_error("[%s] HTTP response error [%d]", + amf_ue->suci, sbi_message->res_status); + } + nas_5gs_send_gmm_reject_from_sbi( + amf_ue, sbi_message->res_status); + OGS_FSM_TRAN(&amf_ue->sm, &gmm_state_exception); + break; + } - SWITCH(sbi_message->h.method) - CASE(OGS_SBI_HTTP_METHOD_POST) - rv = amf_nausf_auth_handle_authenticate(amf_ue, sbi_message); - if (rv != OGS_OK) { - ogs_error("[%s] Cannot handle SBI message", amf_ue->suci); - nas_5gs_send_authentication_reject(amf_ue); - OGS_FSM_TRAN(&amf_ue->sm, &gmm_state_exception); - } - break; - CASE(OGS_SBI_HTTP_METHOD_PUT) - rv = amf_nausf_auth_handle_authenticate_confirmation( - amf_ue, sbi_message); - if (rv != OGS_OK) { - ogs_error("[%s] Cannot handle SBI message", amf_ue->suci); - nas_5gs_send_authentication_reject(amf_ue); - OGS_FSM_TRAN(&amf_ue->sm, &gmm_state_exception); - } else { - OGS_FSM_TRAN(&amf_ue->sm, &gmm_state_security_mode); - } + SWITCH(sbi_message->h.method) + CASE(OGS_SBI_HTTP_METHOD_POST) + rv = amf_nausf_auth_handle_authenticate( + amf_ue, sbi_message); + if (rv != OGS_OK) { + ogs_error("[%s] Cannot handle SBI message", + amf_ue->suci); + nas_5gs_send_authentication_reject(amf_ue); + OGS_FSM_TRAN(&amf_ue->sm, &gmm_state_exception); + } + break; + CASE(OGS_SBI_HTTP_METHOD_PUT) + rv = amf_nausf_auth_handle_authenticate_confirmation( + amf_ue, sbi_message); + if (rv != OGS_OK) { + ogs_error("[%s] Cannot handle SBI message", + amf_ue->suci); + nas_5gs_send_authentication_reject(amf_ue); + OGS_FSM_TRAN(&amf_ue->sm, &gmm_state_exception); + } else { + OGS_FSM_TRAN(&amf_ue->sm, &gmm_state_security_mode); + } + break; + DEFAULT + ogs_error("[%s] Invalid HTTP method [%s]", + amf_ue->suci, sbi_message->h.method); + ogs_assert_if_reached(); + END break; + DEFAULT - ogs_error("[%s] Invalid HTTP method [%s]", - amf_ue->suci, sbi_message->h.method); + ogs_error("Invalid resource name [%s]", + sbi_message->h.resource.component[0]); ogs_assert_if_reached(); END break; DEFAULT - ogs_error("Invalid resource name [%s]", - sbi_message->h.resource.component[0]); + ogs_error("Invalid service name [%s]", sbi_message->h.service.name); ogs_assert_if_reached(); END break; + default: ogs_error("Unknown event[%s]", amf_event_get_name(e)); break; @@ -782,17 +633,6 @@ void gmm_state_security_mode(ogs_fsm_t *s, amf_event_t *e) nas_message = e->nas.message; ogs_assert(nas_message); -#if 0 - if (nas_message->gmm.h.security_header_type - == OGS_NAS_SECURITY_HEADER_FOR_SERVICE_REQUEST_MESSAGE) { - ogs_debug("Service request"); - nas_5gs_send_service_reject(amf_ue, - GMM_CAUSE_SECURITY_MODE_REJECTED_UNSPECIFIED); - OGS_FSM_TRAN(s, &gmm_state_exception); - return; - } -#endif - switch (nas_message->gmm.h.message_type) { case OGS_NAS_5GS_SECURITY_MODE_COMPLETE: ogs_debug("[%s] Security mode complete", amf_ue->supi); @@ -805,7 +645,7 @@ void gmm_state_security_mode(ogs_fsm_t *s, amf_event_t *e) ogs_error("[%s] Security-mode : No Integrity Protected", amf_ue->supi); - nas_5gs_send_registration_reject(amf_ue, + nas_5gs_send_gmm_reject(amf_ue, OGS_5GMM_CAUSE_SECURITY_MODE_REJECTED_UNSPECIFIED); OGS_FSM_TRAN(s, &gmm_state_exception); break; @@ -813,7 +653,7 @@ void gmm_state_security_mode(ogs_fsm_t *s, amf_event_t *e) if (!SECURITY_CONTEXT_IS_VALID(amf_ue)) { ogs_warn("[%s] No Security Context", amf_ue->supi); - nas_5gs_send_registration_reject(amf_ue, + nas_5gs_send_gmm_reject(amf_ue, OGS_5GMM_CAUSE_SECURITY_MODE_REJECTED_UNSPECIFIED); OGS_FSM_TRAN(s, &gmm_state_exception); break; @@ -833,14 +673,18 @@ void gmm_state_security_mode(ogs_fsm_t *s, amf_event_t *e) if (amf_ue->nas.message_type == OGS_NAS_5GS_REGISTRATION_REQUEST) { OGS_FSM_TRAN(s, &gmm_state_initial_context_setup); + } else if (amf_ue->nas.message_type == + OGS_NAS_5GS_SERVICE_REQUEST) { + OGS_FSM_TRAN(s, &gmm_state_registered); #if 0 } else if (amf_ue->nas.message_type == - AMF_EPS_TYPE_SERVICE_REQUEST || - amf_ue->nas.message_type == AMF_EPS_TYPE_TAU_REQUEST) { + OGS_NAS_5GS_SERVICE_REQUEST || + amf_ue->nas.message_type == + AMF_EPS_TYPE_TAU_REQUEST) { OGS_FSM_TRAN(s, &gmm_state_registered); +#endif } else { ogs_fatal("Invalid OGS_NAS_5GS[%d]", amf_ue->nas.message_type); -#endif } break; case OGS_NAS_5GS_SECURITY_MODE_REJECT: @@ -865,6 +709,13 @@ void gmm_state_security_mode(ogs_fsm_t *s, amf_event_t *e) OGS_FSM_TRAN(s, &gmm_state_authentication); break; + case OGS_NAS_5GS_SERVICE_REQUEST: + ogs_debug("[%s] Service request", amf_ue->supi); + nas_5gs_send_service_reject(amf_ue, + OGS_5GMM_CAUSE_SECURITY_MODE_REJECTED_UNSPECIFIED, false); + OGS_FSM_TRAN(s, &gmm_state_exception); + break; + #if 0 case OGS_NAS_5GS_TRACKING_AREA_UPDATE_REQUEST: ogs_debug("Tracking area update request"); @@ -881,21 +732,11 @@ void gmm_state_security_mode(ogs_fsm_t *s, amf_event_t *e) break; case OGS_NAS_5GS_DEREGISTRATION_REQUEST: -#if 0 - ogs_debug("Deregistration request"); - ogs_debug(" IMSI[%s]", amf_ue->imsi_bcd); - rv = gmm_handle_deregistration_request( + gmm_handle_deregistration_request( amf_ue, &nas_message->gmm.deregistration_request_from_ue); - if (rv != OGS_OK) { - ogs_error("gmm_handle_registration_request() failed"); - OGS_FSM_TRAN(s, gmm_state_exception); - break; - } - - amf_send_delete_session_or_deregistration(amf_ue); OGS_FSM_TRAN(s, &gmm_state_de_registered); -#endif break; + default: ogs_warn("Unknown message[%d]", nas_message->gmm.h.message_type); break; @@ -907,7 +748,7 @@ void gmm_state_security_mode(ogs_fsm_t *s, amf_event_t *e) if (amf_ue->t3560.retry_count >= amf_timer_cfg(AMF_TIMER_T3560)->max_count) { ogs_warn("[%s] Retransmission failed. Stop", amf_ue->supi); - nas_5gs_send_registration_reject(amf_ue, + nas_5gs_send_gmm_reject(amf_ue, OGS_5GMM_CAUSE_SECURITY_MODE_REJECTED_UNSPECIFIED); OGS_FSM_TRAN(&amf_ue->sm, &gmm_state_exception); } else { @@ -931,6 +772,7 @@ void gmm_state_initial_context_setup(ogs_fsm_t *s, amf_event_t *e) { int rv; amf_ue_t *amf_ue = NULL; + amf_sess_t *sess = NULL; ogs_nas_5gs_message_t *nas_message = NULL; ogs_sbi_response_t *sbi_response = NULL; @@ -941,8 +783,14 @@ void gmm_state_initial_context_setup(ogs_fsm_t *s, amf_event_t *e) amf_sm_debug(e); - amf_ue = e->amf_ue; - ogs_assert(amf_ue); + if (e->sess) { + sess = e->sess; + amf_ue = sess->amf_ue; + ogs_assert(amf_ue); + } else { + amf_ue = e->amf_ue; + ogs_assert(amf_ue); + } switch (e->id) { case OGS_FSM_ENTRY_SIG: @@ -956,88 +804,121 @@ void gmm_state_initial_context_setup(ogs_fsm_t *s, amf_event_t *e) sbi_message = e->sbi.message; ogs_assert(sbi_message); - ogs_timer_stop(amf_ue->sbi.client_wait.timer); + SWITCH(sbi_message->h.service.name) + CASE(OGS_SBI_SERVICE_NAME_NUDM_UECM) - SWITCH(sbi_message->h.resource.component[1]) - CASE(OGS_SBI_RESOURCE_NAME_REGISTRATIONS) - if (sbi_message->res_status != OGS_SBI_HTTP_STATUS_CREATED && - sbi_message->res_status != OGS_SBI_HTTP_STATUS_OK) { - ogs_error("[%s] HTTP response error [%d]", - amf_ue->supi, sbi_message->res_status); - nas_5gs_send_registration_reject( - amf_ue, OGS_5GMM_CAUSE_5GS_SERVICES_NOT_ALLOWED); - OGS_FSM_TRAN(&amf_ue->sm, &gmm_state_exception); - break; - } + SWITCH(sbi_message->h.resource.component[1]) + CASE(OGS_SBI_RESOURCE_NAME_REGISTRATIONS) + if (sbi_message->res_status != OGS_SBI_HTTP_STATUS_CREATED && + sbi_message->res_status != OGS_SBI_HTTP_STATUS_OK) { + ogs_error("[%s] HTTP response error [%d]", + amf_ue->supi, sbi_message->res_status); + nas_5gs_send_gmm_reject( + amf_ue, OGS_5GMM_CAUSE_5GS_SERVICES_NOT_ALLOWED); + OGS_FSM_TRAN(&amf_ue->sm, &gmm_state_exception); + break; + } - SWITCH(sbi_message->h.method) - CASE(OGS_SBI_HTTP_METHOD_PUT) - amf_ue_sbi_discover_and_send(OpenAPI_nf_type_UDM, amf_ue, - (char *)OGS_SBI_RESOURCE_NAME_AM_DATA, - amf_nudm_sdm_build_get); + SWITCH(sbi_message->h.method) + CASE(OGS_SBI_HTTP_METHOD_PUT) + amf_ue_sbi_discover_and_send(OpenAPI_nf_type_UDM, amf_ue, + (char *)OGS_SBI_RESOURCE_NAME_AM_DATA, + amf_nudm_sdm_build_get); + break; + + DEFAULT + ogs_error("[%s] Invalid HTTP method [%s]", + amf_ue->suci, sbi_message->h.method); + ogs_assert_if_reached(); + END break; DEFAULT - ogs_error("[%s] Invalid HTTP method [%s]", - amf_ue->suci, sbi_message->h.method); + ogs_error("Invalid resource name [%s]", + sbi_message->h.resource.component[1]); ogs_assert_if_reached(); END break; - CASE(OGS_SBI_RESOURCE_NAME_AM_DATA) - CASE(OGS_SBI_RESOURCE_NAME_SMF_SELECT_DATA) - CASE(OGS_SBI_RESOURCE_NAME_UE_CONTEXT_IN_SMF_DATA) - if (sbi_message->res_status != OGS_SBI_HTTP_STATUS_OK) { - ogs_error("[%s] HTTP response error [%d]", - amf_ue->supi, sbi_message->res_status); - nas_5gs_send_registration_reject( - amf_ue, OGS_5GMM_CAUSE_5GS_SERVICES_NOT_ALLOWED); - OGS_FSM_TRAN(&amf_ue->sm, &gmm_state_exception); - break; - } + CASE(OGS_SBI_SERVICE_NAME_NUDM_SDM) SWITCH(sbi_message->h.resource.component[1]) CASE(OGS_SBI_RESOURCE_NAME_AM_DATA) - if (sbi_message->AccessAndMobilitySubscriptionData) { - OpenAPI_ambr_rm_t *subscribed_ue_ambr = - sbi_message->AccessAndMobilitySubscriptionData-> - subscribed_ue_ambr; - if (subscribed_ue_ambr) { - amf_ue->subscribed_ue_ambr.uplink = - ogs_sbi_bitrate_from_string( - subscribed_ue_ambr->uplink); - amf_ue->subscribed_ue_ambr.downlink = - ogs_sbi_bitrate_from_string( - subscribed_ue_ambr->downlink); - } + CASE(OGS_SBI_RESOURCE_NAME_SMF_SELECT_DATA) + CASE(OGS_SBI_RESOURCE_NAME_UE_CONTEXT_IN_SMF_DATA) + if (sbi_message->res_status != OGS_SBI_HTTP_STATUS_OK) { + ogs_error("[%s] HTTP response error [%d]", + amf_ue->supi, sbi_message->res_status); + nas_5gs_send_gmm_reject( + amf_ue, OGS_5GMM_CAUSE_5GS_SERVICES_NOT_ALLOWED); + OGS_FSM_TRAN(&amf_ue->sm, &gmm_state_exception); + break; } - amf_ue_sbi_discover_and_send(OpenAPI_nf_type_UDM, amf_ue, + SWITCH(sbi_message->h.resource.component[1]) + CASE(OGS_SBI_RESOURCE_NAME_AM_DATA) + if (sbi_message->AccessAndMobilitySubscriptionData) { + OpenAPI_ambr_rm_t *subscribed_ue_ambr = + sbi_message->AccessAndMobilitySubscriptionData-> + subscribed_ue_ambr; + if (subscribed_ue_ambr) { + amf_ue->subscribed_ue_ambr.uplink = + ogs_sbi_bitrate_from_string( + subscribed_ue_ambr->uplink); + amf_ue->subscribed_ue_ambr.downlink = + ogs_sbi_bitrate_from_string( + subscribed_ue_ambr->downlink); + } + } + + amf_ue_sbi_discover_and_send(OpenAPI_nf_type_UDM, amf_ue, (char *)OGS_SBI_RESOURCE_NAME_SMF_SELECT_DATA, amf_nudm_sdm_build_get); - break; + break; - CASE(OGS_SBI_RESOURCE_NAME_SMF_SELECT_DATA) - amf_ue_sbi_discover_and_send(OpenAPI_nf_type_UDM, amf_ue, + CASE(OGS_SBI_RESOURCE_NAME_SMF_SELECT_DATA) + amf_ue_sbi_discover_and_send(OpenAPI_nf_type_UDM, amf_ue, (char *)OGS_SBI_RESOURCE_NAME_UE_CONTEXT_IN_SMF_DATA, amf_nudm_sdm_build_get); - break; + break; - CASE(OGS_SBI_RESOURCE_NAME_UE_CONTEXT_IN_SMF_DATA) - nas_5gs_send_registration_accept(amf_ue); + CASE(OGS_SBI_RESOURCE_NAME_UE_CONTEXT_IN_SMF_DATA) + nas_5gs_send_registration_accept(amf_ue); + break; + + DEFAULT + END break; DEFAULT + ogs_error("Invalid resource name [%s]", + sbi_message->h.resource.component[1]); + ogs_assert_if_reached(); END + break; + CASE(OGS_SBI_SERVICE_NAME_NSMF_PDUSESSION) + + SWITCH(sbi_message->h.resource.component[2]) + CASE(OGS_SBI_RESOURCE_NAME_MODIFY) + amf_nsmf_pdu_session_handle_update_sm_context( + sess, sbi_message); + if (SESSION_UP_CNX_STATE_SYNCHED(amf_ue)) + OGS_FSM_TRAN(&amf_ue->sm, &gmm_state_registered); + break; + + DEFAULT + ogs_error("Invalid resource name [%s]", + sbi_message->h.resource.component[2]); + END break; DEFAULT - ogs_error("Invalid resource name [%s]", - sbi_message->h.resource.component[0]); + ogs_error("Invalid service name [%s]", sbi_message->h.service.name); ogs_assert_if_reached(); END break; + case AMF_EVT_5GMM_MESSAGE: nas_message = e->nas.message; ogs_assert(nas_message); @@ -1063,9 +944,7 @@ void gmm_state_initial_context_setup(ogs_fsm_t *s, amf_event_t *e) break; } -#if 0 - amf_gtp_send_delete_all_sessions(amf_ue); -#endif + amf_sbi_send_release_all_sm_contexts(amf_ue); OGS_FSM_TRAN(s, &gmm_state_authentication); break; @@ -1075,22 +954,12 @@ void gmm_state_initial_context_setup(ogs_fsm_t *s, amf_event_t *e) OGS_FSM_TRAN(s, &gmm_state_exception); break; -#if 0 case OGS_NAS_5GS_DEREGISTRATION_REQUEST: - ogs_debug("Deregistration request"); - ogs_debug(" IMSI[%s]", amf_ue->imsi_bcd); - rv = gmm_handle_deregistration_request( + gmm_handle_deregistration_request( amf_ue, &nas_message->gmm.deregistration_request_from_ue); - if (rv != OGS_OK) { - ogs_error("gmm_handle_registration_request() failed"); - OGS_FSM_TRAN(s, gmm_state_exception); - return; - } - - amf_send_delete_session_or_deregistration(amf_ue); OGS_FSM_TRAN(s, &gmm_state_de_registered); break; -#endif + default: ogs_warn("Unknown message[%d]", nas_message->gmm.h.message_type); break; diff --git a/src/amf/meson.build b/src/amf/meson.build index 2d85751fc..8587a4054 100644 --- a/src/amf/meson.build +++ b/src/amf/meson.build @@ -48,6 +48,7 @@ libamf_sources = files(''' gmm-sm.c amf-sm.c + amf-path.c init.c '''.split()) diff --git a/src/amf/nas-path.c b/src/amf/nas-path.c index d24c821b2..c4852a93c 100644 --- a/src/amf/nas-path.c +++ b/src/amf/nas-path.c @@ -91,6 +91,7 @@ void nas_5gs_send_registration_reject( gmmbuf = gmm_build_registration_reject(gmm_cause); ogs_expect_or_return(gmmbuf); + rv = nas_5gs_send_to_downlink_nas_transport(amf_ue, gmmbuf); ogs_expect_or_return(rv == OGS_OK); } @@ -263,16 +264,13 @@ void nas_5gs_send_gmm_reject( switch(amf_ue->nas.message_type) { case OGS_NAS_5GS_REGISTRATION_REQUEST: - if (OGS_FSM_CHECK(&amf_ue->sm, gmm_state_authentication)) { - nas_5gs_send_authentication_reject(amf_ue); - } else { - nas_5gs_send_registration_reject(amf_ue, gmm_cause); - } + nas_5gs_send_registration_reject(amf_ue, gmm_cause); + break; + case OGS_NAS_5GS_SERVICE_REQUEST: + nas_5gs_send_service_reject(amf_ue, gmm_cause, true); break; default: - ogs_fatal("Unknown type : %d", amf_ue->nas.message_type); - ogs_assert_if_reached(); - break; + ogs_error("Unknown message type [%d]", amf_ue->nas.message_type); } } @@ -366,8 +364,41 @@ void nas_5gs_send_back_5gsm_message_from_sbi(amf_sess_t *sess, int status) nas_5gs_send_back_5gsm_message(sess, gmm_cause_from_sbi(status)); } -#if 0 -void nas_5gs_send_detach_accept(amf_ue_t *amf_ue) +void nas_5gs_send_service_accept(amf_ue_t *amf_ue) +{ + int rv; + ogs_pkbuf_t *gmmbuf = NULL; + ogs_pkbuf_t *ngapbuf = NULL; + + ogs_assert(amf_ue); + + gmmbuf = gmm_build_service_accept(amf_ue); + ogs_expect_or_return(gmmbuf); + + ngapbuf = ngap_build_initial_context_setup_request(amf_ue, gmmbuf); + ogs_expect_or_return(ngapbuf); + + rv = nas_5gs_send_to_gnb(amf_ue, ngapbuf); + ogs_expect_or_return(rv == OGS_OK); +} + +void nas_5gs_send_service_reject(amf_ue_t *amf_ue, + ogs_nas_5gmm_cause_t gmm_cause, bool pdu_session_status_present) +{ + int rv; + ogs_pkbuf_t *gmmbuf = NULL; + + ogs_assert(amf_ue); + + gmmbuf = gmm_build_service_reject(amf_ue, + gmm_cause, pdu_session_status_present); + ogs_expect_or_return(gmmbuf); + + rv = nas_5gs_send_to_downlink_nas_transport(amf_ue, gmmbuf); + ogs_expect(rv == OGS_OK); +} + +void nas_5gs_send_de_registration_accept(amf_ue_t *amf_ue) { ran_ue_t *ran_ue = NULL; ogs_pkbuf_t *gmmbuf = NULL; @@ -376,10 +407,10 @@ void nas_5gs_send_detach_accept(amf_ue_t *amf_ue) ran_ue = amf_ue->ran_ue; ogs_assert(ran_ue); - /* reply with detach accept */ - if (amf_ue->nas_5gs.detach.switch_off == 0) { + if (amf_ue->nas.de_registration.switch_off == 0) { int rv; - gmmbuf = gmm_build_detach_accept(amf_ue); + + gmmbuf = gmm_build_de_registration_accept(amf_ue); ogs_expect_or_return(gmmbuf); rv = nas_5gs_send_to_downlink_nas_transport(amf_ue, gmmbuf); @@ -387,207 +418,11 @@ void nas_5gs_send_detach_accept(amf_ue_t *amf_ue) } ngap_send_ue_context_release_command(ran_ue, - NGAP_Cause_PR_nas, NGAP_CauseNas_detach, + NGAP_Cause_PR_nas, NGAP_CauseNas_deregister, NGAP_UE_CTX_REL_NG_REMOVE_AND_UNLINK, 0); } - -void nas_5gs_send_pdn_connectivity_reject( - amf_sess_t *sess, ogs_nas_gsm_cause_t gsm_cause) -{ - int rv; - amf_ue_t *amf_ue; - ogs_pkbuf_t *gsmbuf = NULL; - - ogs_assert(sess); - amf_ue = sess->amf_ue; - ogs_assert(amf_ue); - - if (OGS_FSM_CHECK(&amf_ue->sm, gmm_state_registered)) { - gsmbuf = esm_build_pdn_connectivity_reject(sess, gsm_cause); - ogs_expect_or_return(gsmbuf); - - rv = nas_5gs_send_to_downlink_nas_transport(amf_ue, gsmbuf); - ogs_expect(rv == OGS_OK); - } else { - /* During the UE-registration process, we'll send Registration-Reject - * with pyggybacking PDN-connectivity-Reject */ - nas_5gs_send_registration_reject(amf_ue, - EMM_CAUSE_EPS_SERVICES_AND_NON_EPS_SERVICES_NOT_ALLOWED, gsm_cause); - } -} - -void nas_5gs_send_esm_information_request(amf_bearer_t *bearer) -{ - int rv; - amf_ue_t *amf_ue = NULL; - ogs_pkbuf_t *gsmbuf = NULL; - - ogs_assert(bearer); - amf_ue = bearer->amf_ue; - ogs_assert(amf_ue); - - if (bearer->t3589.pkbuf) { - gsmbuf = bearer->t3589.pkbuf; - ogs_expect_or_return(gsmbuf); - } else { - gsmbuf = esm_build_information_request(bearer); - ogs_expect_or_return(gsmbuf); - } - - bearer->t3589.pkbuf = ogs_pkbuf_copy(gsmbuf); - ogs_timer_start(bearer->t3589.timer, - amf_timer_cfg(AMF_TIMER_T3589)->duration); - - rv = nas_5gs_send_to_downlink_nas_transport(amf_ue, gsmbuf); - ogs_expect(rv == OGS_OK); -} - -void nas_5gs_send_activate_default_bearer_context_request(amf_bearer_t *bearer) -{ - int rv; - ogs_pkbuf_t *ngapbuf = NULL; - ogs_pkbuf_t *gsmbuf = NULL; - amf_sess_t *sess = NULL; - amf_ue_t *amf_ue = NULL; - - ogs_assert(bearer); - sess = bearer->sess; - ogs_assert(sess); - amf_ue = bearer->amf_ue; - ogs_assert(amf_ue); - - gsmbuf = esm_build_activate_default_bearer_context_request(sess); - ogs_expect_or_return(gsmbuf); - - ngapbuf = ngap_build_e_rab_setup_request(bearer, gsmbuf); - ogs_expect_or_return(ngapbuf); - - rv = nas_5gs_send_to_gnb(amf_ue, ngapbuf); - ogs_expect(rv == OGS_OK); -} - -void nas_5gs_send_activate_dedicated_bearer_context_request( - amf_bearer_t *bearer) -{ - int rv; - ogs_pkbuf_t *ngapbuf = NULL; - ogs_pkbuf_t *gsmbuf = NULL; - amf_ue_t *amf_ue = NULL; - - ogs_assert(bearer); - amf_ue = bearer->amf_ue; - ogs_assert(amf_ue); - - gsmbuf = esm_build_activate_dedicated_bearer_context_request(bearer); - ogs_expect_or_return(gsmbuf); - - ngapbuf = ngap_build_e_rab_setup_request(bearer, gsmbuf); - ogs_expect_or_return(ngapbuf); - - rv = nas_5gs_send_to_gnb(amf_ue, ngapbuf); - ogs_expect(rv == OGS_OK); -} - -void nas_5gs_send_activate_all_dedicated_bearers(amf_bearer_t *default_bearer) -{ - ogs_assert(default_bearer); - - amf_bearer_t *dedicated_bearer = amf_bearer_next(default_bearer); - while (dedicated_bearer) { - nas_5gs_send_activate_dedicated_bearer_context_request( - dedicated_bearer); - dedicated_bearer = amf_bearer_next(dedicated_bearer); - } -} - -void nas_5gs_send_modify_bearer_context_request( - amf_bearer_t *bearer, int qos_presence, int tft_presence) -{ - int rv; - ogs_pkbuf_t *ngapbuf = NULL; - ogs_pkbuf_t *gsmbuf = NULL; - amf_ue_t *amf_ue = NULL; - - ogs_assert(bearer); - amf_ue = bearer->amf_ue; - ogs_assert(amf_ue); - - gsmbuf = esm_build_modify_bearer_context_request( - bearer, qos_presence, tft_presence); - ogs_expect_or_return(gsmbuf); - - if (qos_presence == 1) { - ngapbuf = ngap_build_e_rab_modify_request(bearer, gsmbuf); - ogs_expect_or_return(ngapbuf); - - rv = nas_5gs_send_to_gnb(amf_ue, ngapbuf); - ogs_expect(rv == OGS_OK); - } else { - rv = nas_5gs_send_to_downlink_nas_transport(amf_ue, gsmbuf); - ogs_expect(rv == OGS_OK); - } -} - -void nas_5gs_send_deactivate_bearer_context_request(amf_bearer_t *bearer) -{ - int rv; - ogs_pkbuf_t *ngapbuf = NULL; - ogs_pkbuf_t *gsmbuf = NULL; - amf_ue_t *amf_ue = NULL; - - ogs_assert(bearer); - amf_ue = bearer->amf_ue; - ogs_assert(amf_ue); - - gsmbuf = esm_build_deactivate_bearer_context_request( - bearer, ESM_CAUSE_REGULAR_DEACTIVATION); - ogs_expect_or_return(gsmbuf); - - ngapbuf = ngap_build_e_rab_release_command(bearer, gsmbuf, - NGAP_Cause_PR_nas, NGAP_CauseNas_normal_release); - ogs_expect_or_return(ngapbuf); - - rv = nas_5gs_send_to_gnb(amf_ue, ngapbuf); - ogs_expect(rv == OGS_OK); -} - -void nas_5gs_send_bearer_resource_allocation_reject( - amf_bearer_t *bearer, ogs_nas_gsm_cause_t gsm_cause) -{ - int rv; - amf_ue_t *amf_ue; - ogs_pkbuf_t *gsmbuf = NULL; - - ogs_assert(bearer); - amf_ue = bearer->amf_ue; - ogs_assert(bearer); - - gsmbuf = esm_build_bearer_resource_allocation_reject(bearer, gsm_cause); - ogs_expect_or_return(gsmbuf); - - rv = nas_5gs_send_to_downlink_nas_transport(amf_ue, gsmbuf); - ogs_expect(rv == OGS_OK); -} - -void nas_5gs_send_bearer_resource_modification_reject( - amf_bearer_t *bearer, ogs_nas_gsm_cause_t gsm_cause) -{ - int rv; - amf_ue_t *amf_ue; - ogs_pkbuf_t *gsmbuf = NULL; - - ogs_assert(bearer); - amf_ue = bearer->amf_ue; - ogs_assert(bearer); - - gsmbuf = esm_build_bearer_resource_modification_reject(bearer, gsm_cause); - ogs_expect_or_return(gsmbuf); - - rv = nas_5gs_send_to_downlink_nas_transport(amf_ue, gsmbuf); - ogs_expect(rv == OGS_OK); -} - +#if 0 void nas_5gs_send_tau_accept( amf_ue_t *amf_ue, NGAP_ProcedureCode_t procedureCode) { @@ -616,7 +451,7 @@ void nas_5gs_send_tau_accept( ogs_assert_if_reached(); } -void nas_5gs_send_tau_reject(amf_ue_t *amf_ue, ogs_nas_gmm_cause_t gmm_cause) +void nas_5gs_send_tau_reject(amf_ue_t *amf_ue, ogs_nas_5gmm_cause_t gmm_cause) { int rv; ogs_pkbuf_t *gmmbuf = NULL; @@ -631,22 +466,6 @@ void nas_5gs_send_tau_reject(amf_ue_t *amf_ue, ogs_nas_gmm_cause_t gmm_cause) ogs_expect(rv == OGS_OK); } -void nas_5gs_send_service_reject(amf_ue_t *amf_ue, - ogs_nas_gmm_cause_t gmm_cause) -{ - int rv; - ogs_pkbuf_t *gmmbuf = NULL; - - ogs_assert(amf_ue); - - /* Build Service Reject */ - gmmbuf = gmm_build_service_reject(gmm_cause, amf_ue); - ogs_expect_or_return(gmmbuf); - - rv = nas_5gs_send_to_downlink_nas_transport(amf_ue, gmmbuf); - ogs_expect(rv == OGS_OK); -} - void nas_5gs_send_cs_service_notification(amf_ue_t *amf_ue) { int rv; diff --git a/src/amf/nas-path.h b/src/amf/nas-path.h index 54c16fc3a..7ad9b1509 100644 --- a/src/amf/nas-path.h +++ b/src/amf/nas-path.h @@ -65,31 +65,17 @@ void nas_5gs_send_back_5gsm_message( amf_sess_t *sess, ogs_nas_5gmm_cause_t gmm_cause); void nas_5gs_send_back_5gsm_message_from_sbi(amf_sess_t *sess, int status); +void nas_5gs_send_service_accept(amf_ue_t *amf_ue); +void nas_5gs_send_service_reject(amf_ue_t *amf_ue, + ogs_nas_5gmm_cause_t gmm_cause, bool pdu_session_status_present); + +void nas_5gs_send_de_registration_accept(amf_ue_t *amf_ue); + #if 0 -void nas_5gs_send_detach_accept(amf_ue_t *amf_ue); - -void nas_5gs_send_pdn_connectivity_reject( - amf_sess_t *sess, ogs_nas_5gsm_cause_t gsm_cause); -void nas_5gs_send_gsm_information_request(amf_bearer_t *bearer); -void nas_5gs_send_activate_default_bearer_context_request(amf_bearer_t *bearer); -void nas_5gs_send_activate_dedicated_bearer_context_request( - amf_bearer_t *bearer); -void nas_5gs_send_activate_all_dedicated_bearers(amf_bearer_t *default_bearer); -void nas_5gs_send_modify_bearer_context_request( - amf_bearer_t *bearer, int qos_presence, int tft_presence); -void nas_5gs_send_deactivate_bearer_context_request(amf_bearer_t *bearer); -void nas_5gs_send_bearer_resource_allocation_reject( - amf_bearer_t *bearer, ogs_nas_5gsm_cause_t gsm_cause); -void nas_5gs_send_bearer_resource_modification_reject( - amf_bearer_t *bearer, ogs_nas_5gsm_cause_t gsm_cause); - void nas_5gs_send_tau_accept( amf_ue_t *amf_ue, S1AP_ProcedureCode_t procedureCode); void nas_5gs_send_tau_reject(amf_ue_t *amf_ue, ogs_nas_5gsm_cause_t gmm_cause); -void nas_5gs_send_service_reject( - amf_ue_t *amf_ue, ogs_nas_5gmm_cause_t gmm_cause); - void nas_5gs_send_cs_service_notification(amf_ue_t *amf_ue); void nas_5gs_send_downlink_nas_transport( amf_ue_t *amf_ue, uint8_t *buffer, uint8_t length); diff --git a/src/amf/nausf-build.c b/src/amf/nausf-build.c index f572d1161..0df1a3966 100644 --- a/src/amf/nausf-build.c +++ b/src/amf/nausf-build.c @@ -25,7 +25,12 @@ ogs_sbi_request_t *amf_nausf_auth_build_authenticate( ogs_sbi_message_t message; ogs_sbi_request_t *request = NULL; - OpenAPI_authentication_info_t *AuthenticationInfo = NULL; + OpenAPI_authentication_info_t AuthenticationInfo; + OpenAPI_resynchronization_info_t ResynchronizationInfo; + uint8_t *auts = data; + + char rand_string[OGS_KEYSTRLEN(OGS_RAND_LEN)]; + char auts_string[OGS_KEYSTRLEN(OGS_AUTS_LEN)]; ogs_assert(amf_ue); @@ -39,21 +44,32 @@ ogs_sbi_request_t *amf_nausf_auth_build_authenticate( message.http.accept = (char *)(OGS_SBI_CONTENT_3GPPHAL_TYPE "," OGS_SBI_CONTENT_PROBLEM_TYPE); - AuthenticationInfo = ogs_calloc(1, sizeof(*AuthenticationInfo)); - ogs_assert(AuthenticationInfo); + memset(&AuthenticationInfo, 0, sizeof(AuthenticationInfo)); ogs_assert(amf_ue->suci); - AuthenticationInfo->supi_or_suci = amf_ue->suci; - AuthenticationInfo->serving_network_name = + AuthenticationInfo.supi_or_suci = amf_ue->suci; + AuthenticationInfo.serving_network_name = ogs_serving_network_name_from_plmn_id(&amf_ue->tai.plmn_id); - message.AuthenticationInfo = AuthenticationInfo; + if (auts) { + memset(&ResynchronizationInfo, 0, sizeof(ResynchronizationInfo)); + + ogs_hex_to_ascii(amf_ue->rand, OGS_RAND_LEN, + rand_string, sizeof(rand_string)); + ogs_hex_to_ascii(auts, OGS_AUTS_LEN, auts_string, sizeof(auts_string)); + + ResynchronizationInfo.rand = rand_string; + ResynchronizationInfo.auts = auts_string; + + AuthenticationInfo.resynchronization_info = &ResynchronizationInfo; + } + + message.AuthenticationInfo = &AuthenticationInfo; request = ogs_sbi_build_request(&message); ogs_assert(request); - ogs_free(AuthenticationInfo->serving_network_name); - ogs_free(AuthenticationInfo); + ogs_free(AuthenticationInfo.serving_network_name); return request; } diff --git a/src/amf/nf-sm.c b/src/amf/nf-sm.c index d19a1c6cc..8674a2236 100644 --- a/src/amf/nf-sm.c +++ b/src/amf/nf-sm.c @@ -28,6 +28,7 @@ void amf_nf_fsm_init(ogs_sbi_nf_instance_t *nf_instance) ogs_assert(nf_instance); + memset(&e, 0, sizeof(e)); e.sbi.data = nf_instance; ogs_fsm_create(&nf_instance->sm, @@ -40,6 +41,8 @@ void amf_nf_fsm_fini(ogs_sbi_nf_instance_t *nf_instance) amf_event_t e; ogs_assert(nf_instance); + + memset(&e, 0, sizeof(e)); e.sbi.data = nf_instance; ogs_fsm_fini(&nf_instance->sm, &e); diff --git a/src/amf/ngap-build.c b/src/amf/ngap-build.c index 429d82218..52c8d0249 100644 --- a/src/amf/ngap-build.c +++ b/src/amf/ngap-build.c @@ -293,6 +293,9 @@ ogs_pkbuf_t *ngap_build_initial_context_setup_request( { int i, j; + ran_ue_t *ran_ue = NULL; + amf_sess_t *sess = NULL; + NGAP_NGAP_PDU_t pdu; NGAP_InitiatingMessage_t *initiatingMessage = NULL; NGAP_InitialContextSetupRequest_t *InitialContextSetupRequest = NULL; @@ -300,14 +303,16 @@ ogs_pkbuf_t *ngap_build_initial_context_setup_request( NGAP_InitialContextSetupRequestIEs_t *ie = NULL; NGAP_AMF_UE_NGAP_ID_t *AMF_UE_NGAP_ID = NULL; NGAP_RAN_UE_NGAP_ID_t *RAN_UE_NGAP_ID = NULL; + NGAP_UEAggregateMaximumBitRate_t *UEAggregateMaximumBitRate = NULL; + NGAP_PDUSessionResourceSetupListCxtReq_t *PDUSessionList = NULL; + NGAP_PDUSessionResourceSetupItemCxtReq_t *PDUSessionItem = NULL; NGAP_GUAMI_t *GUAMI = NULL; NGAP_AllowedNSSAI_t *AllowedNSSAI = NULL; NGAP_UESecurityCapabilities_t *UESecurityCapabilities = NULL; NGAP_SecurityKey_t *SecurityKey = NULL; + NGAP_MaskedIMEISV_t *MaskedIMEISV = NULL; NGAP_NAS_PDU_t *NAS_PDU = NULL; - ran_ue_t *ran_ue = NULL; - ogs_assert(amf_ue); ran_ue = amf_ue->ran_ue; ogs_assert(ran_ue); @@ -349,6 +354,26 @@ ogs_pkbuf_t *ngap_build_initial_context_setup_request( RAN_UE_NGAP_ID = &ie->value.choice.RAN_UE_NGAP_ID; + if (amf_ue->subscribed_ue_ambr.downlink || + amf_ue->subscribed_ue_ambr.uplink) { + ie = CALLOC(1, sizeof(NGAP_InitialContextSetupRequestIEs_t)); + ASN_SEQUENCE_ADD(&InitialContextSetupRequest->protocolIEs, ie); + + ie->id = NGAP_ProtocolIE_ID_id_UEAggregateMaximumBitRate; + ie->criticality = NGAP_Criticality_reject; + ie->value.present = + NGAP_InitialContextSetupRequestIEs__value_PR_UEAggregateMaximumBitRate; + + UEAggregateMaximumBitRate = &ie->value.choice.UEAggregateMaximumBitRate; + + asn_uint642INTEGER( + &UEAggregateMaximumBitRate->uEAggregateMaximumBitRateUL, + amf_ue->subscribed_ue_ambr.uplink); + asn_uint642INTEGER( + &UEAggregateMaximumBitRate->uEAggregateMaximumBitRateDL, + amf_ue->subscribed_ue_ambr.downlink); + } + ie = CALLOC(1, sizeof(NGAP_InitialContextSetupRequestIEs_t)); ASN_SEQUENCE_ADD(&InitialContextSetupRequest->protocolIEs, ie); @@ -358,6 +383,48 @@ ogs_pkbuf_t *ngap_build_initial_context_setup_request( GUAMI = &ie->value.choice.GUAMI; + ogs_list_for_each(&amf_ue->sess_list, sess) { + OCTET_STRING_t *transfer = NULL; + NGAP_S_NSSAI_t *s_NSSAI = NULL; + NGAP_SST_t *sST = NULL; + + if (!sess->n2smbuf) continue; + + if (!PDUSessionList) { + ie = CALLOC(1, sizeof(NGAP_InitialContextSetupRequestIEs_t)); + ASN_SEQUENCE_ADD(&InitialContextSetupRequest->protocolIEs, ie); + + ie->id = NGAP_ProtocolIE_ID_id_PDUSessionResourceSetupListCxtReq; + ie->criticality = NGAP_Criticality_reject; + ie->value.present = NGAP_InitialContextSetupRequestIEs__value_PR_PDUSessionResourceSetupListCxtReq; + + PDUSessionList = + &ie->value.choice.PDUSessionResourceSetupListCxtReq; + } + + PDUSessionItem = CALLOC(1, + sizeof(struct NGAP_PDUSessionResourceSetupItemCxtReq)); + ASN_SEQUENCE_ADD(&PDUSessionList->list, PDUSessionItem); + + PDUSessionItem->pDUSessionID = sess->psi; + + s_NSSAI = &PDUSessionItem->s_NSSAI; + sST = &s_NSSAI->sST; + + ogs_asn_uint8_to_OCTET_STRING(sess->s_nssai.sst, sST); + if (sess->s_nssai.sd.v != OGS_S_NSSAI_NO_SD_VALUE) { + s_NSSAI->sD = CALLOC(1, sizeof(ogs_uint24_t)); + ogs_asn_uint24_to_OCTET_STRING(sess->s_nssai.sd, s_NSSAI->sD); + } + + transfer = &PDUSessionItem->pDUSessionResourceSetupRequestTransfer; + transfer->size = sess->n2smbuf->len; + transfer->buf = CALLOC(transfer->size, sizeof(uint8_t)); + memcpy(transfer->buf, sess->n2smbuf->data, transfer->size); + ogs_pkbuf_free(sess->n2smbuf); + sess->n2smbuf = NULL; + } + ie = CALLOC(1, sizeof(NGAP_InitialContextSetupRequestIEs_t)); ASN_SEQUENCE_ADD(&InitialContextSetupRequest->protocolIEs, ie); @@ -388,26 +455,12 @@ ogs_pkbuf_t *ngap_build_initial_context_setup_request( SecurityKey = &ie->value.choice.SecurityKey; - ie = CALLOC(1, sizeof(NGAP_InitialContextSetupRequestIEs_t)); - ASN_SEQUENCE_ADD(&InitialContextSetupRequest->protocolIEs, ie); - - ie->id = NGAP_ProtocolIE_ID_id_NAS_PDU; - ie->criticality = NGAP_Criticality_reject; - ie->value.present = NGAP_InitialContextSetupRequestIEs__value_PR_NAS_PDU; - - NAS_PDU = &ie->value.choice.NAS_PDU; - ogs_debug(" RAN_UE_NGAP_ID[%d] AMF_UE_NGAP_ID[%lld]", ran_ue->ran_ue_ngap_id, (long long)ran_ue->amf_ue_ngap_id); asn_uint642INTEGER(AMF_UE_NGAP_ID, ran_ue->amf_ue_ngap_id); *RAN_UE_NGAP_ID = ran_ue->ran_ue_ngap_id; - NAS_PDU->size = gmmbuf->len; - NAS_PDU->buf = CALLOC(NAS_PDU->size, sizeof(uint8_t)); - memcpy(NAS_PDU->buf, gmmbuf->data, NAS_PDU->size); - ogs_pkbuf_free(gmmbuf); - ogs_assert(amf_ue->guami); ogs_asn_buffer_to_OCTET_STRING(&amf_ue->guami->plmn_id, OGS_PLMN_ID_LEN, &GUAMI->pLMNIdentity); @@ -502,6 +555,42 @@ ogs_pkbuf_t *ngap_build_initial_context_setup_request( UERadioCapability); } + if (amf_ue->imeisv_len) { + ie = CALLOC(1, sizeof(NGAP_InitialContextSetupRequestIEs_t)); + ASN_SEQUENCE_ADD(&InitialContextSetupRequest->protocolIEs, ie); + + ie->id = NGAP_ProtocolIE_ID_id_MaskedIMEISV; + ie->criticality = NGAP_Criticality_ignore; + ie->value.present = + NGAP_InitialContextSetupRequestIEs__value_PR_MaskedIMEISV; + + MaskedIMEISV = &ie->value.choice.MaskedIMEISV; + + MaskedIMEISV->size = amf_ue->imeisv_len; + MaskedIMEISV->buf = CALLOC(MaskedIMEISV->size, sizeof(uint8_t)); + MaskedIMEISV->bits_unused = 0; + memcpy(MaskedIMEISV->buf, amf_ue->imeisv, MaskedIMEISV->size); + MaskedIMEISV->buf[5] = 0xff; + MaskedIMEISV->buf[6] = 0xff; + } + + if (gmmbuf) { + ie = CALLOC(1, sizeof(NGAP_InitialContextSetupRequestIEs_t)); + ASN_SEQUENCE_ADD(&InitialContextSetupRequest->protocolIEs, ie); + + ie->id = NGAP_ProtocolIE_ID_id_NAS_PDU; + ie->criticality = NGAP_Criticality_ignore; + ie->value.present = + NGAP_InitialContextSetupRequestIEs__value_PR_NAS_PDU; + + NAS_PDU = &ie->value.choice.NAS_PDU; + + NAS_PDU->size = gmmbuf->len; + NAS_PDU->buf = CALLOC(NAS_PDU->size, sizeof(uint8_t)); + memcpy(NAS_PDU->buf, gmmbuf->data, NAS_PDU->size); + ogs_pkbuf_free(gmmbuf); + } + return nga_ngap_encode(&pdu); } @@ -647,6 +736,7 @@ ogs_pkbuf_t *ngap_build_ue_context_modification_request(amf_ue_t *amf_ue) return nga_ngap_encode(&pdu); } +#endif ogs_pkbuf_t *ngap_build_ue_context_release_command( ran_ue_t *ran_ue, NGAP_Cause_PR group, long cause) @@ -661,11 +751,6 @@ ogs_pkbuf_t *ngap_build_ue_context_release_command( ogs_assert(ran_ue); - if (ran_ue->amf_ue_ngap_id == 0) { - ogs_error("invalid amf ue ngap id"); - return NULL; - } - memset(&pdu, 0, sizeof (NGAP_NGAP_PDU_t)); pdu.present = NGAP_NGAP_PDU_PR_initiatingMessage; pdu.choice.initiatingMessage = @@ -699,15 +784,17 @@ ogs_pkbuf_t *ngap_build_ue_context_release_command( Cause = &ie->value.choice.Cause; if (ran_ue->ran_ue_ngap_id == INVALID_UE_NGAP_ID) { - UE_NGAP_IDs->present = NGAP_UE_NGAP_IDs_PR_mME_UE_NGAP_ID; - UE_NGAP_IDs->choice.mME_UE_NGAP_ID = ran_ue->amf_ue_ngap_id; + UE_NGAP_IDs->present = NGAP_UE_NGAP_IDs_PR_aMF_UE_NGAP_ID; + asn_uint642INTEGER( + &UE_NGAP_IDs->choice.aMF_UE_NGAP_ID, ran_ue->amf_ue_ngap_id); } else { UE_NGAP_IDs->present = NGAP_UE_NGAP_IDs_PR_uE_NGAP_ID_pair; UE_NGAP_IDs->choice.uE_NGAP_ID_pair = CALLOC(1, sizeof(NGAP_UE_NGAP_ID_pair_t)); - UE_NGAP_IDs->choice.uE_NGAP_ID_pair->mME_UE_NGAP_ID = - ran_ue->amf_ue_ngap_id; - UE_NGAP_IDs->choice.uE_NGAP_ID_pair->RAN_UE_NGAP_ID = + asn_uint642INTEGER( + &UE_NGAP_IDs->choice.uE_NGAP_ID_pair->aMF_UE_NGAP_ID, + ran_ue->amf_ue_ngap_id); + UE_NGAP_IDs->choice.uE_NGAP_ID_pair->rAN_UE_NGAP_ID = ran_ue->ran_ue_ngap_id; } @@ -717,11 +804,12 @@ ogs_pkbuf_t *ngap_build_ue_context_release_command( return nga_ngap_encode(&pdu); } -#endif - ogs_pkbuf_t *ngap_build_pdu_session_resource_setup_request( amf_sess_t *sess, ogs_pkbuf_t *gmmbuf, ogs_pkbuf_t *n2smbuf) { + amf_ue_t *amf_ue = NULL; + ran_ue_t *ran_ue = NULL; + NGAP_NGAP_PDU_t pdu; NGAP_InitiatingMessage_t *initiatingMessage = NULL; NGAP_PDUSessionResourceSetupRequest_t *PDUSessionResourceSetupRequest; @@ -737,9 +825,6 @@ ogs_pkbuf_t *ngap_build_pdu_session_resource_setup_request( NGAP_SST_t *sST = NULL; OCTET_STRING_t *transfer = NULL; - amf_ue_t *amf_ue = NULL; - ran_ue_t *ran_ue = NULL; - ogs_assert(gmmbuf); ogs_assert(n2smbuf); ogs_assert(sess); @@ -829,268 +914,6 @@ ogs_pkbuf_t *ngap_build_pdu_session_resource_setup_request( } #if 0 -ogs_pkbuf_t *ngap_build_e_rab_modify_request( - amf_bearer_t *bearer, ogs_pkbuf_t *gsmbuf) -{ - NGAP_NGAP_PDU_t pdu; - NGAP_InitiatingMessage_t *initiatingMessage = NULL; - NGAP_E_RABModifyRequest_t *E_RABModifyRequest = NULL; - - NGAP_E_RABModifyRequestIEs_t *ie = NULL; - NGAP_AMF_UE_NGAP_ID_t *AMF_UE_NGAP_ID = NULL; - NGAP_RAN_UE_NGAP_ID_t *RAN_UE_NGAP_ID = NULL; - NGAP_E_RABToBeModifiedListBearerModReq_t - *E_RABToBeModifiedListBearerModReq = NULL; - - NGAP_E_RABToBeModifiedItemBearerModReqIEs_t *item = NULL; - NGAP_E_RABToBeModifiedItemBearerModReq_t *e_rab = NULL; - NGAP_GBR_QosInformation_t *gbrQosInformation = NULL; - NGAP_NAS_PDU_t *nasPdu = NULL; - - amf_ue_t *amf_ue = NULL; - ran_ue_t *ran_ue = NULL; - - ogs_assert(gsmbuf); - ogs_assert(bearer); - - amf_ue = bearer->amf_ue; - ogs_assert(amf_ue); - ran_ue = amf_ue->ran_ue; - ogs_assert(ran_ue); - - ogs_debug("E-RAB modify request"); - memset(&pdu, 0, sizeof (NGAP_NGAP_PDU_t)); - pdu.present = NGAP_NGAP_PDU_PR_initiatingMessage; - pdu.choice.initiatingMessage = - CALLOC(1, sizeof(NGAP_InitiatingMessage_t)); - - initiatingMessage = pdu.choice.initiatingMessage; - initiatingMessage->procedureCode = NGAP_ProcedureCode_id_E_RABModify; - initiatingMessage->criticality = NGAP_Criticality_reject; - initiatingMessage->value.present = - NGAP_InitiatingMessage__value_PR_E_RABModifyRequest; - - E_RABModifyRequest = &initiatingMessage->value.choice.E_RABModifyRequest; - - ie = CALLOC(1, sizeof(NGAP_E_RABModifyRequestIEs_t)); - ASN_SEQUENCE_ADD(&E_RABModifyRequest->protocolIEs, ie); - - ie->id = NGAP_ProtocolIE_ID_id_AMF_UE_NGAP_ID; - ie->criticality = NGAP_Criticality_reject; - ie->value.present = NGAP_E_RABModifyRequestIEs__value_PR_AMF_UE_NGAP_ID; - - AMF_UE_NGAP_ID = &ie->value.choice.AMF_UE_NGAP_ID; - - ie = CALLOC(1, sizeof(NGAP_E_RABModifyRequestIEs_t)); - ASN_SEQUENCE_ADD(&E_RABModifyRequest->protocolIEs, ie); - - ie->id = NGAP_ProtocolIE_ID_id_RAN_UE_NGAP_ID; - ie->criticality = NGAP_Criticality_reject; - ie->value.present = NGAP_E_RABModifyRequestIEs__value_PR_RAN_UE_NGAP_ID; - - RAN_UE_NGAP_ID = &ie->value.choice.RAN_UE_NGAP_ID; - - ie = CALLOC(1, sizeof(NGAP_E_RABModifyRequestIEs_t)); - ASN_SEQUENCE_ADD(&E_RABModifyRequest->protocolIEs, ie); - - ie->id = NGAP_ProtocolIE_ID_id_E_RABToBeModifiedListBearerModReq; - ie->criticality = NGAP_Criticality_reject; - ie->value.present = - NGAP_E_RABModifyRequestIEs__value_PR_E_RABToBeModifiedListBearerModReq; - - E_RABToBeModifiedListBearerModReq = - &ie->value.choice.E_RABToBeModifiedListBearerModReq; - - ogs_debug(" RAN_UE_NGAP_ID[%d] AMF_UE_NGAP_ID[%d]", - ran_ue->ran_ue_ngap_id, ran_ue->amf_ue_ngap_id); - - *AMF_UE_NGAP_ID = ran_ue->amf_ue_ngap_id; - *RAN_UE_NGAP_ID = ran_ue->ran_ue_ngap_id; - - item = CALLOC(1, sizeof(NGAP_E_RABToBeModifiedItemBearerModReqIEs_t)); - ASN_SEQUENCE_ADD(&E_RABToBeModifiedListBearerModReq->list, item); - - item->id = NGAP_ProtocolIE_ID_id_E_RABToBeModifiedItemBearerModReq; - item->criticality = NGAP_Criticality_reject; - item->value.present = NGAP_E_RABToBeModifiedItemBearerModReqIEs__value_PR_E_RABToBeModifiedItemBearerModReq; - - e_rab = &item->value.choice.E_RABToBeModifiedItemBearerModReq; - - e_rab->e_RAB_ID = bearer->ebi; - e_rab->e_RABLevelQoSParameters.qCI = bearer->qos.qci; - - ogs_debug(" EBI[%d] QCI[%d]", bearer->ebi, bearer->qos.qci); - - e_rab->e_RABLevelQoSParameters.allocationRetentionPriority. - priorityLevel = bearer->qos.arp.priority_level; - e_rab->e_RABLevelQoSParameters.allocationRetentionPriority. - pre_emptionCapability = !(bearer->qos.arp.pre_emption_capability); - e_rab->e_RABLevelQoSParameters.allocationRetentionPriority. - pre_emptionVulnerability = !(bearer->qos.arp.pre_emption_vulnerability); - - if (bearer->qos.mbr.downlink || bearer->qos.mbr.uplink || - bearer->qos.gbr.downlink || bearer->qos.gbr.uplink) { - if (bearer->qos.mbr.downlink == 0) - bearer->qos.mbr.downlink = MAX_BIT_RATE; - if (bearer->qos.mbr.uplink == 0) - bearer->qos.mbr.uplink = MAX_BIT_RATE; - if (bearer->qos.gbr.downlink == 0) - bearer->qos.gbr.downlink = MAX_BIT_RATE; - if (bearer->qos.gbr.uplink == 0) - bearer->qos.gbr.uplink = MAX_BIT_RATE; - - gbrQosInformation = - CALLOC(1, sizeof(NGAP_GBR_QosInformation_t)); - asn_uint642INTEGER(&gbrQosInformation->e_RAB_MaximumBitrateDL, - bearer->qos.mbr.downlink); - asn_uint642INTEGER(&gbrQosInformation->e_RAB_MaximumBitrateUL, - bearer->qos.mbr.uplink); - asn_uint642INTEGER(&gbrQosInformation->e_RAB_GuaranteedBitrateDL, - bearer->qos.gbr.downlink); - asn_uint642INTEGER(&gbrQosInformation->e_RAB_GuaranteedBitrateUL, - bearer->qos.gbr.uplink); - e_rab->e_RABLevelQoSParameters.gbrQosInformation = gbrQosInformation; - } - - nasPdu = &e_rab->nAS_PDU; - nasPdu->size = gsmbuf->len; - nasPdu->buf = CALLOC(nasPdu->size, sizeof(uint8_t)); - memcpy(nasPdu->buf, gsmbuf->data, nasPdu->size); - ogs_pkbuf_free(gsmbuf); - - return nga_ngap_encode(&pdu); -} - -ogs_pkbuf_t *ngap_build_e_rab_release_command( - amf_bearer_t *bearer, ogs_pkbuf_t *gsmbuf, - NGAP_Cause_PR group, long cause) -{ - NGAP_NGAP_PDU_t pdu; - NGAP_InitiatingMessage_t *initiatingMessage = NULL; - NGAP_E_RABReleaseCommand_t *E_RABReleaseCommand = NULL; - - NGAP_E_RABReleaseCommandIEs_t *ie = NULL; - NGAP_AMF_UE_NGAP_ID_t *AMF_UE_NGAP_ID = NULL; - NGAP_RAN_UE_NGAP_ID_t *RAN_UE_NGAP_ID = NULL; - NGAP_UEAggregateMaximumBitrate_t *UEAggregateMaximumBitrate = NULL; - NGAP_E_RABList_t *E_RABList = NULL; - NGAP_NAS_PDU_t *nasPdu = NULL; - - NGAP_E_RABItemIEs_t *item = NULL; - NGAP_E_RABItem_t *e_rab = NULL; - - amf_ue_t *amf_ue = NULL; - ran_ue_t *ran_ue = NULL; - ogs_diam_s6a_subscription_data_t *subscription_data = NULL; - - ogs_assert(gsmbuf); - ogs_assert(bearer); - - amf_ue = bearer->amf_ue; - ogs_assert(amf_ue); - ran_ue = amf_ue->ran_ue; - ogs_assert(ran_ue); - subscription_data = &amf_ue->subscription_data; - ogs_assert(subscription_data); - - ogs_debug("E-RAB release command"); - - memset(&pdu, 0, sizeof (NGAP_NGAP_PDU_t)); - pdu.present = NGAP_NGAP_PDU_PR_initiatingMessage; - pdu.choice.initiatingMessage = - CALLOC(1, sizeof(NGAP_InitiatingMessage_t)); - - initiatingMessage = pdu.choice.initiatingMessage; - initiatingMessage->procedureCode = NGAP_ProcedureCode_id_E_RABRelease; - initiatingMessage->criticality = NGAP_Criticality_reject; - initiatingMessage->value.present = - NGAP_InitiatingMessage__value_PR_E_RABReleaseCommand; - - E_RABReleaseCommand = &initiatingMessage->value.choice.E_RABReleaseCommand; - - ie = CALLOC(1, sizeof(NGAP_E_RABReleaseCommandIEs_t)); - ASN_SEQUENCE_ADD(&E_RABReleaseCommand->protocolIEs, ie); - - ie->id = NGAP_ProtocolIE_ID_id_AMF_UE_NGAP_ID; - ie->criticality = NGAP_Criticality_reject; - ie->value.present = NGAP_E_RABReleaseCommandIEs__value_PR_AMF_UE_NGAP_ID; - - AMF_UE_NGAP_ID = &ie->value.choice.AMF_UE_NGAP_ID; - - ie = CALLOC(1, sizeof(NGAP_E_RABReleaseCommandIEs_t)); - ASN_SEQUENCE_ADD(&E_RABReleaseCommand->protocolIEs, ie); - - ie->id = NGAP_ProtocolIE_ID_id_RAN_UE_NGAP_ID; - ie->criticality = NGAP_Criticality_reject; - ie->value.present = NGAP_E_RABReleaseCommandIEs__value_PR_RAN_UE_NGAP_ID; - - RAN_UE_NGAP_ID = &ie->value.choice.RAN_UE_NGAP_ID; - - ie = CALLOC(1, sizeof(NGAP_E_RABReleaseCommandIEs_t)); - ASN_SEQUENCE_ADD(&E_RABReleaseCommand->protocolIEs, ie); - - ie->id = NGAP_ProtocolIE_ID_id_uEaggregateMaximumBitrate; - ie->criticality = NGAP_Criticality_reject; - ie->value.present = - NGAP_E_RABReleaseCommandIEs__value_PR_UEAggregateMaximumBitrate; - - UEAggregateMaximumBitrate = &ie->value.choice.UEAggregateMaximumBitrate; - - ie = CALLOC(1, sizeof(NGAP_E_RABReleaseCommandIEs_t)); - ASN_SEQUENCE_ADD(&E_RABReleaseCommand->protocolIEs, ie); - - ie->id = NGAP_ProtocolIE_ID_id_E_RABToBeReleasedList; - ie->criticality = NGAP_Criticality_ignore; - ie->value.present = NGAP_E_RABReleaseCommandIEs__value_PR_E_RABList; - - E_RABList = &ie->value.choice.E_RABList; - - ie = CALLOC(1, sizeof(NGAP_E_RABReleaseCommandIEs_t)); - ASN_SEQUENCE_ADD(&E_RABReleaseCommand->protocolIEs, ie); - - ie->id = NGAP_ProtocolIE_ID_id_NAS_PDU; - ie->criticality = NGAP_Criticality_ignore; - ie->value.present = NGAP_E_RABReleaseCommandIEs__value_PR_NAS_PDU; - - nasPdu = &ie->value.choice.NAS_PDU; - - ogs_debug(" RAN_UE_NGAP_ID[%d] AMF_UE_NGAP_ID[%d]", - ran_ue->ran_ue_ngap_id, ran_ue->amf_ue_ngap_id); - - *AMF_UE_NGAP_ID = ran_ue->amf_ue_ngap_id; - *RAN_UE_NGAP_ID = ran_ue->ran_ue_ngap_id; - - asn_uint642INTEGER( - &UEAggregateMaximumBitrate->uEaggregateMaximumBitRateUL, - subscription_data->ambr.uplink); - asn_uint642INTEGER( - &UEAggregateMaximumBitrate->uEaggregateMaximumBitRateDL, - subscription_data->ambr.downlink); - - item = CALLOC(1, sizeof(NGAP_E_RABItemIEs_t)); - ASN_SEQUENCE_ADD(&E_RABList->list, item); - - item->id = NGAP_ProtocolIE_ID_id_E_RABItem; - item->criticality = NGAP_Criticality_ignore; - item->value.present = NGAP_E_RABItemIEs__value_PR_E_RABItem; - - e_rab = &item->value.choice.E_RABItem; - - e_rab->e_RAB_ID = bearer->ebi; - e_rab->cause.present = group; - e_rab->cause.choice.radioNetwork = cause; - - ogs_debug(" EBI[%d] Gruop[%d] Cause[%d]", - bearer->ebi, group, (int)cause); - - nasPdu->size = gsmbuf->len; - nasPdu->buf = CALLOC(nasPdu->size, sizeof(uint8_t)); - memcpy(nasPdu->buf, gsmbuf->data, nasPdu->size); - ogs_pkbuf_free(gsmbuf); - - return nga_ngap_encode(&pdu); -} - ogs_pkbuf_t *ngap_build_paging( amf_ue_t *amf_ue, NGAP_CNDomain_t cn_domain) { @@ -1798,10 +1621,10 @@ ogs_pkbuf_t *ngap_build_handover_request( Cause->choice.radioNetwork = cause->choice.radioNetwork; asn_uint642INTEGER( - &UEAggregateMaximumBitrate->uEaggregateMaximumBitRateUL, + &UEAggregateMaximumBitrate->uEaggregateMaximumBitRateUL, subscription_data->ambr.uplink); asn_uint642INTEGER( - &UEAggregateMaximumBitrate->uEaggregateMaximumBitRateDL, + &UEAggregateMaximumBitrate->uEaggregateMaximumBitRateDL, subscription_data->ambr.downlink); sess = amf_sess_first(amf_ue); @@ -2042,8 +1865,8 @@ ogs_pkbuf_t *ngap_build_amf_status_transfer( #endif ogs_pkbuf_t *ngap_build_error_indication( + uint32_t *ran_ue_ngap_id, uint64_t *amf_ue_ngap_id, - NGAP_RAN_UE_NGAP_ID_t *ran_ue_ngap_id, NGAP_Cause_PR group, long cause) { NGAP_NGAP_PDU_t pdu; @@ -2201,8 +2024,8 @@ ogs_pkbuf_t *ngap_build_s1_reset_partial( ie2->value.present = NGAP_UE_associatedLogicalNG_ConnectionItemRes__value_PR_UE_associatedLogicalNG_ConnectionItem; item = &ie2->value.choice.UE_associatedLogicalNG_ConnectionItem; - item->mME_UE_NGAP_ID = amf_ue_ngap_id; - item->RAN_UE_NGAP_ID = ran_ue_ngap_id; + item->aMF_UE_NGAP_ID = amf_ue_ngap_id; + item->rAN_UE_NGAP_ID = ran_ue_ngap_id; return ngap_build_s1_reset(group, cause, partOfNG_Interface); } @@ -2259,8 +2082,8 @@ ogs_pkbuf_t *ngap_build_s1_reset_ack( item1 = &ie1->value.choice.UE_associatedLogicalNG_ConnectionItem; ogs_assert(item1); - if (item1->mME_UE_NGAP_ID == NULL && - item1->RAN_UE_NGAP_ID == NULL) { + if (item1->aMF_UE_NGAP_ID == NULL && + item1->rAN_UE_NGAP_ID == NULL) { ogs_warn("No AMF_UE_NGAP_ID & RAN_UE_NGAP_ID"); continue; } @@ -2278,236 +2101,26 @@ ogs_pkbuf_t *ngap_build_s1_reset_ack( item2 = &ie2->value.choice.UE_associatedLogicalNG_ConnectionItem; ogs_assert(item2); - if (item1->mME_UE_NGAP_ID) { - item2->mME_UE_NGAP_ID = CALLOC(1, + if (item1->aMF_UE_NGAP_ID) { + item2->aMF_UE_NGAP_ID = CALLOC(1, sizeof(NGAP_AMF_UE_NGAP_ID_t)); - ogs_assert(item2->mME_UE_NGAP_ID); - *item2->mME_UE_NGAP_ID = *item1->mME_UE_NGAP_ID; + ogs_assert(item2->aMF_UE_NGAP_ID); + *item2->aMF_UE_NGAP_ID = *item1->aMF_UE_NGAP_ID; } - if (item1->RAN_UE_NGAP_ID) { - item2->RAN_UE_NGAP_ID = CALLOC(1, + if (item1->rAN_UE_NGAP_ID) { + item2->rAN_UE_NGAP_ID = CALLOC(1, sizeof(NGAP_RAN_UE_NGAP_ID_t)); - ogs_assert(item2->RAN_UE_NGAP_ID); - *item2->RAN_UE_NGAP_ID = *item1->RAN_UE_NGAP_ID; + ogs_assert(item2->rAN_UE_NGAP_ID); + *item2->rAN_UE_NGAP_ID = *item1->rAN_UE_NGAP_ID; } ogs_debug(" AMF_UE_NGAP_ID[%d] RAN_UE_NGAP_ID[%d]", - item2->mME_UE_NGAP_ID ? (int)*item2->mME_UE_NGAP_ID : -1, - item2->RAN_UE_NGAP_ID ? (int)*item2->RAN_UE_NGAP_ID : -1); + item2->aMF_UE_NGAP_ID ? (int)*item2->aMF_UE_NGAP_ID : -1, + item2->rAN_UE_NGAP_ID ? (int)*item2->rAN_UE_NGAP_ID : -1); } } return nga_ngap_encode(&pdu); } - -ogs_pkbuf_t *ngap_build_write_replace_warning_request(sbc_pws_data_t *sbc_pws) -{ - NGAP_NGAP_PDU_t pdu; - NGAP_InitiatingMessage_t *initiatingMessage = NULL; - NGAP_WriteReplaceWarningRequest_t *WriteReplaceWarningRequest = NULL; - - NGAP_WriteReplaceWarningRequestIEs_t *ie = NULL; - NGAP_MessageIdentifier_t *MessageIdentifier = NULL; - NGAP_SerialNumber_t *SerialNumber = NULL; - NGAP_RepetitionPeriod_t *RepetitionPeriod = NULL; - NGAP_NumberofBroadcastRequest_t *NumberofBroadcastRequest = NULL; - NGAP_DataCodingScheme_t *DataCodingScheme = NULL; - NGAP_WarningMessageContents_t *WarningMessageContents = NULL; - - ogs_debug("Write-replace warning request"); - - ogs_assert(sbc_pws); - - memset(&pdu, 0, sizeof (NGAP_NGAP_PDU_t)); - pdu.present = NGAP_NGAP_PDU_PR_initiatingMessage; - pdu.choice.initiatingMessage = - CALLOC(1, sizeof(NGAP_InitiatingMessage_t)); - - initiatingMessage = pdu.choice.initiatingMessage; - initiatingMessage->procedureCode = - NGAP_ProcedureCode_id_WriteReplaceWarning; - initiatingMessage->criticality = NGAP_Criticality_reject; - initiatingMessage->value.present = - NGAP_InitiatingMessage__value_PR_WriteReplaceWarningRequest; - - WriteReplaceWarningRequest = - &initiatingMessage->value.choice.WriteReplaceWarningRequest; - - ie = CALLOC(1, sizeof(NGAP_WriteReplaceWarningRequestIEs_t)); - ASN_SEQUENCE_ADD(&WriteReplaceWarningRequest->protocolIEs, ie); - - ie->id = NGAP_ProtocolIE_ID_id_MessageIdentifier; - ie->criticality = NGAP_Criticality_reject; - ie->value.present = - NGAP_WriteReplaceWarningRequestIEs__value_PR_MessageIdentifier; - - MessageIdentifier = &ie->value.choice.MessageIdentifier; - - MessageIdentifier->size = (16 / 8); - MessageIdentifier->buf = - CALLOC(MessageIdentifier->size, sizeof(uint8_t)); - MessageIdentifier->bits_unused = 0; - MessageIdentifier->buf[0] = (sbc_pws->message_id >> 8) & 0xFF; - MessageIdentifier->buf[1] = sbc_pws->message_id & 0xFF; - - ie = CALLOC(1, sizeof(NGAP_WriteReplaceWarningRequestIEs_t)); - ASN_SEQUENCE_ADD(&WriteReplaceWarningRequest->protocolIEs, ie); - - ie->id = NGAP_ProtocolIE_ID_id_SerialNumber; - ie->criticality = NGAP_Criticality_reject; - ie->value.present = - NGAP_WriteReplaceWarningRequestIEs__value_PR_SerialNumber; - - SerialNumber = &ie->value.choice.SerialNumber; - - SerialNumber->size = (16 / 8); - SerialNumber->buf = - CALLOC(SerialNumber->size, sizeof(uint8_t)); - SerialNumber->bits_unused = 0; - SerialNumber->buf[0] = (sbc_pws->serial_number >> 8) & 0xFF; - SerialNumber->buf[1] = sbc_pws->serial_number & 0xFF; - - /* TODO: optional Warning Area List */ - - ie = CALLOC(1, sizeof(NGAP_WriteReplaceWarningRequestIEs_t)); - ASN_SEQUENCE_ADD(&WriteReplaceWarningRequest->protocolIEs, ie); - - ie->id = NGAP_ProtocolIE_ID_id_RepetitionPeriod; - ie->criticality = NGAP_Criticality_reject; - ie->value.present = - NGAP_WriteReplaceWarningRequestIEs__value_PR_RepetitionPeriod; - - RepetitionPeriod = &ie->value.choice.RepetitionPeriod; - - *RepetitionPeriod = sbc_pws->repetition_period; - - /* TODO: optional Extended Repetition Period */ - - ie = CALLOC(1, sizeof(NGAP_WriteReplaceWarningRequestIEs_t)); - ASN_SEQUENCE_ADD(&WriteReplaceWarningRequest->protocolIEs, ie); - - ie->id = NGAP_ProtocolIE_ID_id_NumberofBroadcastRequest; - ie->criticality = NGAP_Criticality_reject; - ie->value.present = - NGAP_WriteReplaceWarningRequestIEs__value_PR_NumberofBroadcastRequest; - - NumberofBroadcastRequest = &ie->value.choice.NumberofBroadcastRequest; - - *NumberofBroadcastRequest = sbc_pws->number_of_broadcast; - - /* TODO: optional Warnging Type */ - - /* TODO: optional Warning Security Information */ - - ie = CALLOC(1, sizeof(NGAP_WriteReplaceWarningRequestIEs_t)); - ASN_SEQUENCE_ADD(&WriteReplaceWarningRequest->protocolIEs, ie); - - ie->id = NGAP_ProtocolIE_ID_id_DataCodingScheme; - ie->criticality = NGAP_Criticality_reject; - ie->value.present = - NGAP_WriteReplaceWarningRequestIEs__value_PR_DataCodingScheme; - - DataCodingScheme = &ie->value.choice.DataCodingScheme; - - DataCodingScheme->size = (8 / 8); - DataCodingScheme->buf = - CALLOC(DataCodingScheme->size, sizeof(uint8_t)); - DataCodingScheme->bits_unused = 0; - DataCodingScheme->buf[0] = sbc_pws->data_coding_scheme & 0xFF; - - ie = CALLOC(1, sizeof(NGAP_WriteReplaceWarningRequestIEs_t)); - ASN_SEQUENCE_ADD(&WriteReplaceWarningRequest->protocolIEs, ie); - - ie->id = NGAP_ProtocolIE_ID_id_WarningMessageContents; - ie->criticality = NGAP_Criticality_reject; - ie->value.present = - NGAP_WriteReplaceWarningRequestIEs__value_PR_WarningMessageContents; - - WarningMessageContents = &ie->value.choice.WarningMessageContents; - - WarningMessageContents->size = sbc_pws->message_length;; - WarningMessageContents->buf = - CALLOC(WarningMessageContents->size, sizeof(uint8_t)); - memcpy(WarningMessageContents->buf, - sbc_pws->message_contents, WarningMessageContents->size); - - /* TODO: optional Concurrent Warning Message Indicator */ - - ogs_debug(" Message[%02x,%02x] Serial[%02x,%02x] " - "Repetition[%d] NumBroadcast[%d]", - MessageIdentifier->buf[0], MessageIdentifier->buf[1], - SerialNumber->buf[0], SerialNumber->buf[1], - (int)*RepetitionPeriod, (int)*NumberofBroadcastRequest); - - return nga_ngap_encode(&pdu); -} - -ogs_pkbuf_t *ngap_build_kill_request(sbc_pws_data_t *sbc_pws) -{ - NGAP_NGAP_PDU_t pdu; - NGAP_InitiatingMessage_t *initiatingMessage = NULL; - NGAP_KillRequest_t *KillRequest = NULL; - - NGAP_KillRequestIEs_t *ie = NULL; - NGAP_MessageIdentifier_t *MessageIdentifier = NULL; - NGAP_SerialNumber_t *SerialNumber = NULL; - - ogs_debug("Kill request"); - - ogs_assert(sbc_pws); - - memset(&pdu, 0, sizeof (NGAP_NGAP_PDU_t)); - pdu.present = NGAP_NGAP_PDU_PR_initiatingMessage; - pdu.choice.initiatingMessage = - CALLOC(1, sizeof(NGAP_InitiatingMessage_t)); - - initiatingMessage = pdu.choice.initiatingMessage; - initiatingMessage->procedureCode = NGAP_ProcedureCode_id_Kill; - initiatingMessage->criticality = NGAP_Criticality_reject; - initiatingMessage->value.present = - NGAP_InitiatingMessage__value_PR_KillRequest; - - KillRequest = &initiatingMessage->value.choice.KillRequest; - - ie = CALLOC(1, sizeof(NGAP_KillRequestIEs_t)); - ASN_SEQUENCE_ADD(&KillRequest->protocolIEs, ie); - - ie->id = NGAP_ProtocolIE_ID_id_MessageIdentifier; - ie->criticality = NGAP_Criticality_reject; - ie->value.present = NGAP_KillRequestIEs__value_PR_MessageIdentifier; - - MessageIdentifier = &ie->value.choice.MessageIdentifier; - - MessageIdentifier->size = (16 / 8); - MessageIdentifier->buf = - CALLOC(MessageIdentifier->size, sizeof(uint8_t)); - MessageIdentifier->bits_unused = 0; - MessageIdentifier->buf[0] = (sbc_pws->message_id >> 8) & 0xFF; - MessageIdentifier->buf[1] = sbc_pws->message_id & 0xFF; - - ie = CALLOC(1, sizeof(NGAP_KillRequestIEs_t)); - ASN_SEQUENCE_ADD(&KillRequest->protocolIEs, ie); - - ie->id = NGAP_ProtocolIE_ID_id_SerialNumber; - ie->criticality = NGAP_Criticality_reject; - ie->value.present = NGAP_KillRequestIEs__value_PR_SerialNumber; - - SerialNumber = &ie->value.choice.SerialNumber; - - SerialNumber->size = (16 / 8); - SerialNumber->buf = - CALLOC(SerialNumber->size, sizeof(uint8_t)); - SerialNumber->bits_unused = 0; - SerialNumber->buf[0] = (sbc_pws->serial_number >> 8) & 0xFF; - SerialNumber->buf[1] = sbc_pws->serial_number & 0xFF; - - /* TODO: optional Warning Area List */ - - ogs_debug(" Message[%02x,%02x] Serial[%02x,%02x]", - MessageIdentifier->buf[0], MessageIdentifier->buf[1], - SerialNumber->buf[0], SerialNumber->buf[1]); - - return nga_ngap_encode(&pdu); -} #endif diff --git a/src/amf/ngap-build.h b/src/amf/ngap-build.h index db208ec0a..fb54fcf45 100644 --- a/src/amf/ngap-build.h +++ b/src/amf/ngap-build.h @@ -81,8 +81,8 @@ ogs_pkbuf_t *ngap_build_amf_status_transfer( *gnb_statustransfer_transparentContainer); ogs_pkbuf_t *ngap_build_error_indication( + uint32_t *ran_ue_ngap_id, uint64_t *amf_ue_ngap_id, - NGAP_RAN_UE_NGAP_ID_t *ran_ue_ngap_id, NGAP_Cause_PR group, long cause); ogs_pkbuf_t *ngap_build_s1_reset( diff --git a/src/amf/ngap-handler.c b/src/amf/ngap-handler.c index e0fa69aab..37f8f9949 100644 --- a/src/amf/ngap-handler.c +++ b/src/amf/ngap-handler.c @@ -18,8 +18,7 @@ */ #include "ngap-handler.h" -#include "ngap-path.h" -#include "sbi-path.h" +#include "amf-path.h" static bool served_tai_is_found(amf_gnb_t *gnb) { @@ -207,6 +206,8 @@ void ngap_handle_initial_ue_message(amf_gnb_t *gnb, ogs_ngap_message_t *message) int i; char buf[OGS_ADDRSTRLEN]; + ran_ue_t *ran_ue = NULL; + NGAP_InitiatingMessage_t *initiatingMessage = NULL; NGAP_InitialUEMessage_t *InitialUEMessage = NULL; @@ -216,8 +217,6 @@ void ngap_handle_initial_ue_message(amf_gnb_t *gnb, ogs_ngap_message_t *message) NGAP_UserLocationInformation_t *UserLocationInformation = NULL; NGAP_FiveG_S_TMSI_t *FiveG_S_TMSI = NULL; - ran_ue_t *ran_ue = NULL; - ogs_assert(gnb); ogs_assert(gnb->sock); @@ -253,7 +252,7 @@ void ngap_handle_initial_ue_message(amf_gnb_t *gnb, ogs_ngap_message_t *message) if (!RAN_UE_NGAP_ID) { ogs_error("No RAN_UE_NGAP_ID"); - ngap_send_error_indication(gnb, NULL, RAN_UE_NGAP_ID, + ngap_send_error_indication(gnb, NULL, NULL, NGAP_Cause_PR_protocol, NGAP_CauseProtocol_semantic_error); return; } @@ -263,7 +262,7 @@ void ngap_handle_initial_ue_message(amf_gnb_t *gnb, ogs_ngap_message_t *message) ran_ue = ran_ue_add(gnb, *RAN_UE_NGAP_ID); ogs_assert(ran_ue); - /* Find AMF_UE if S_TMSI included */ + /* Find AMF_UE if 5G-S_TMSI included */ if (FiveG_S_TMSI) { ogs_nas_5gs_guti_t nas_guti; amf_ue_t *amf_ue = NULL; @@ -274,10 +273,10 @@ void ngap_handle_initial_ue_message(amf_gnb_t *gnb, ogs_ngap_message_t *message) memset(&nas_guti, 0, sizeof(ogs_nas_5gs_guti_t)); - ogs_assert(amf_ue->guami); + /* Use the first configured plmn_id and mme group id */ ogs_nas_from_plmn_id(&nas_guti.nas_plmn_id, - &amf_ue->guami->plmn_id); - region = amf_ue->guami->amf_id.region; + &amf_self()->served_guami[0].plmn_id); + region = amf_self()->served_guami[0].amf_id.region; /* Getting from 5G-S_TMSI */ ogs_ngap_AMFSetID_to_uint16(&FiveG_S_TMSI->aMFSetID, &set); @@ -291,7 +290,7 @@ void ngap_handle_initial_ue_message(amf_gnb_t *gnb, ogs_ngap_message_t *message) amf_ue = amf_ue_find_by_guti(&nas_guti); if (!amf_ue) { - ogs_warn("Unknown UE by 5G-S_TMSI[AMF_ID:0x%x,M_TMSI:0x%x]", + ogs_debug("Unknown UE by 5G-S_TMSI[AMF_ID:0x%x,M_TMSI:0x%x]", ogs_amf_id_hexdump(&nas_guti.amf_id), nas_guti.m_tmsi); } else { ogs_debug("[%s] 5G-S_TMSI[AMF_ID:0x%x,M_TMSI:0x%x]", @@ -300,7 +299,7 @@ void ngap_handle_initial_ue_message(amf_gnb_t *gnb, ogs_ngap_message_t *message) amf_ue->guti.m_tmsi); /* If NAS(amf_ue_t) has already been associated with * older NG(ran_ue_t) context */ - if (ECM_CONNECTED(amf_ue)) { + if (CM_CONNECTED(amf_ue)) { /* Implcit NG release */ ogs_debug("Implicit NG release"); ogs_debug(" RAN_UE_NGAP_ID[%d] AMF_UE_NGAP_ID[%lld]", @@ -315,14 +314,14 @@ void ngap_handle_initial_ue_message(amf_gnb_t *gnb, ogs_ngap_message_t *message) if (!UserLocationInformation) { ogs_error("No UserLocationInformation"); - ngap_send_error_indication(gnb, &ran_ue->amf_ue_ngap_id, RAN_UE_NGAP_ID, + ngap_send_error_indication(gnb, &ran_ue->ran_ue_ngap_id, NULL, NGAP_Cause_PR_protocol, NGAP_CauseProtocol_semantic_error); return; } if (!NAS_PDU) { ogs_error("No NAS_PDU"); - ngap_send_error_indication(gnb, &ran_ue->amf_ue_ngap_id, RAN_UE_NGAP_ID, + ngap_send_error_indication(gnb, &ran_ue->ran_ue_ngap_id, NULL, NGAP_Cause_PR_protocol, NGAP_CauseProtocol_semantic_error); return; } @@ -356,15 +355,16 @@ void ngap_handle_uplink_nas_transport( char buf[OGS_ADDRSTRLEN]; int i; + ran_ue_t *ran_ue = NULL; + uint64_t amf_ue_ngap_id; + NGAP_InitiatingMessage_t *initiatingMessage = NULL; NGAP_UplinkNASTransport_t *UplinkNASTransport = NULL; NGAP_UplinkNASTransport_IEs_t *ie = NULL; - NGAP_RAN_UE_NGAP_ID_t *RAN_UE_NGAP_ID = NULL; + NGAP_AMF_UE_NGAP_ID_t *AMF_UE_NGAP_ID = NULL; NGAP_NAS_PDU_t *NAS_PDU = NULL; - ran_ue_t *ran_ue = NULL; - ogs_assert(gnb); ogs_assert(gnb->sock); @@ -379,8 +379,8 @@ void ngap_handle_uplink_nas_transport( for (i = 0; i < UplinkNASTransport->protocolIEs.list.count; i++) { ie = UplinkNASTransport->protocolIEs.list.array[i]; switch (ie->id) { - case NGAP_ProtocolIE_ID_id_RAN_UE_NGAP_ID: - RAN_UE_NGAP_ID = &ie->value.choice.RAN_UE_NGAP_ID; + case NGAP_ProtocolIE_ID_id_AMF_UE_NGAP_ID: + AMF_UE_NGAP_ID = &ie->value.choice.AMF_UE_NGAP_ID; break; case NGAP_ProtocolIE_ID_id_NAS_PDU: NAS_PDU = &ie->value.choice.NAS_PDU; @@ -392,29 +392,36 @@ void ngap_handle_uplink_nas_transport( ogs_debug(" IP[%s] RAN_ID[%d]", OGS_ADDR(gnb->addr, buf), gnb->gnb_id); - if (!RAN_UE_NGAP_ID) { - ogs_error("No RAN_UE_NGAP_ID"); + if (!AMF_UE_NGAP_ID) { + ogs_error("No 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_ran_ue_ngap_id(gnb, *RAN_UE_NGAP_ID); - if (!ran_ue) { - ogs_error("Cannot find RAN_UE Context [%d]", (int)*RAN_UE_NGAP_ID); + if (asn_INTEGER2ulong(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_radioNetwork, - NGAP_CauseRadioNetwork_inconsistent_remote_UE_NGAP_ID); + NGAP_Cause_PR_protocol, NGAP_CauseProtocol_semantic_error); return; } - ogs_debug(" RAN_UE_NGAP_ID[%d] AMF_UE_NGAP_ID[%lld]", - ran_ue->ran_ue_ngap_id, (long long)ran_ue->amf_ue_ngap_id); + 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; + } if (!NAS_PDU) { ogs_error("No NAS_PDU"); - ngap_send_error_indication(gnb, &ran_ue->amf_ue_ngap_id, RAN_UE_NGAP_ID, - NGAP_Cause_PR_protocol, NGAP_CauseProtocol_semantic_error); + ngap_send_error_indication( + gnb, &ran_ue->ran_ue_ngap_id, &ran_ue->amf_ue_ngap_id, + NGAP_Cause_PR_protocol, NGAP_CauseProtocol_semantic_error); return; } @@ -428,16 +435,17 @@ void ngap_handle_ue_radio_capability_info_indication( char buf[OGS_ADDRSTRLEN]; int i; + ran_ue_t *ran_ue = NULL; + uint64_t amf_ue_ngap_id; + NGAP_InitiatingMessage_t *initiatingMessage = NULL; NGAP_UERadioCapabilityInfoIndication_t *UERadioCapabilityInfoIndication = NULL; NGAP_UERadioCapabilityInfoIndicationIEs_t *ie = NULL; - NGAP_RAN_UE_NGAP_ID_t *RAN_UE_NGAP_ID = NULL; + NGAP_AMF_UE_NGAP_ID_t *AMF_UE_NGAP_ID = NULL; NGAP_UERadioCapability_t *UERadioCapability = NULL; - ran_ue_t *ran_ue = NULL; - ogs_assert(gnb); ogs_assert(gnb->sock); @@ -454,8 +462,8 @@ void ngap_handle_ue_radio_capability_info_indication( i < UERadioCapabilityInfoIndication->protocolIEs.list.count; i++) { ie = UERadioCapabilityInfoIndication->protocolIEs.list.array[i]; switch (ie->id) { - case NGAP_ProtocolIE_ID_id_RAN_UE_NGAP_ID: - RAN_UE_NGAP_ID = &ie->value.choice.RAN_UE_NGAP_ID; + case NGAP_ProtocolIE_ID_id_AMF_UE_NGAP_ID: + AMF_UE_NGAP_ID = &ie->value.choice.AMF_UE_NGAP_ID; break; case NGAP_ProtocolIE_ID_id_UERadioCapability: UERadioCapability = &ie->value.choice.UERadioCapability; @@ -467,19 +475,29 @@ void ngap_handle_ue_radio_capability_info_indication( ogs_debug(" IP[%s] RAN_ID[%d]", OGS_ADDR(gnb->addr, buf), gnb->gnb_id); - if (!RAN_UE_NGAP_ID) { - ogs_error("No RAN_UE_NGAP_ID"); + if (!AMF_UE_NGAP_ID) { + ogs_error("No 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_ran_ue_ngap_id(gnb, *RAN_UE_NGAP_ID); - if (!ran_ue) { - ogs_error("Cannot find RAN_UE Context [%d]", (int)*RAN_UE_NGAP_ID); + if (asn_INTEGER2ulong(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, &ran_ue->ran_ue_ngap_id, &ran_ue->amf_ue_ngap_id, NGAP_Cause_PR_radioNetwork, - NGAP_CauseRadioNetwork_inconsistent_remote_UE_NGAP_ID); + NGAP_CauseRadioNetwork_unknown_local_UE_NGAP_ID); return; } @@ -488,7 +506,8 @@ void ngap_handle_ue_radio_capability_info_indication( if (!UERadioCapability) { ogs_error("No UERadioCapability"); - ngap_send_error_indication(gnb, &ran_ue->amf_ue_ngap_id, RAN_UE_NGAP_ID, + ngap_send_error_indication( + gnb, &ran_ue->ran_ue_ngap_id, &ran_ue->amf_ue_ngap_id, NGAP_Cause_PR_protocol, NGAP_CauseProtocol_semantic_error); return; } @@ -504,13 +523,19 @@ void ngap_handle_initial_context_setup_response( char buf[OGS_ADDRSTRLEN]; int i; + amf_ue_t *amf_ue = NULL; + ran_ue_t *ran_ue = NULL; + uint64_t amf_ue_ngap_id; + amf_nsmf_pdu_session_update_sm_context_param_t param; + NGAP_SuccessfulOutcome_t *successfulOutcome = NULL; NGAP_InitialContextSetupResponse_t *InitialContextSetupResponse = NULL; NGAP_InitialContextSetupResponseIEs_t *ie = NULL; - NGAP_RAN_UE_NGAP_ID_t *RAN_UE_NGAP_ID = NULL; - - ran_ue_t *ran_ue = NULL; + NGAP_AMF_UE_NGAP_ID_t *AMF_UE_NGAP_ID = NULL; + NGAP_PDUSessionResourceSetupListCxtRes_t *PDUSessionList = NULL; + NGAP_PDUSessionResourceSetupItemCxtRes_t *PDUSessionItem = NULL; + OCTET_STRING_t *transfer = NULL; ogs_assert(gnb); ogs_assert(gnb->sock); @@ -527,8 +552,12 @@ void ngap_handle_initial_context_setup_response( for (i = 0; i < InitialContextSetupResponse->protocolIEs.list.count; i++) { ie = InitialContextSetupResponse->protocolIEs.list.array[i]; switch (ie->id) { - case NGAP_ProtocolIE_ID_id_RAN_UE_NGAP_ID: - RAN_UE_NGAP_ID = &ie->value.choice.RAN_UE_NGAP_ID; + case NGAP_ProtocolIE_ID_id_AMF_UE_NGAP_ID: + AMF_UE_NGAP_ID = &ie->value.choice.AMF_UE_NGAP_ID; + break; + case NGAP_ProtocolIE_ID_id_PDUSessionResourceSetupListCxtRes: + PDUSessionList = + &ie->value.choice.PDUSessionResourceSetupListCxtRes; break; default: break; @@ -537,29 +566,92 @@ void ngap_handle_initial_context_setup_response( ogs_debug(" IP[%s] RAN_ID[%d]", OGS_ADDR(gnb->addr, buf), gnb->gnb_id); - if (!RAN_UE_NGAP_ID) { - ogs_error("No RAN_UE_NGAP_ID"); + if (!AMF_UE_NGAP_ID) { + ogs_error("No 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_ran_ue_ngap_id(gnb, *RAN_UE_NGAP_ID); - if (!ran_ue) { - ogs_error("Cannot find RAN_UE Context [%d]", (int)*RAN_UE_NGAP_ID); + if (asn_INTEGER2ulong(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, &ran_ue->ran_ue_ngap_id, &ran_ue->amf_ue_ngap_id, NGAP_Cause_PR_radioNetwork, - NGAP_CauseRadioNetwork_inconsistent_remote_UE_NGAP_ID); + NGAP_CauseRadioNetwork_unknown_local_UE_NGAP_ID); return; } ogs_debug(" RAN_UE_NGAP_ID[%d] AMF_UE_NGAP_ID[%lld]", ran_ue->ran_ue_ngap_id, (long long)ran_ue->amf_ue_ngap_id); -#if 0 + if (!PDUSessionList) /* No PDUSessionList */ + return; + amf_ue = ran_ue->amf_ue; ogs_assert(amf_ue); -#endif + + for (i = 0; i < PDUSessionList->list.count; i++) { + amf_sess_t *sess = NULL; + PDUSessionItem = (NGAP_PDUSessionResourceSetupItemCxtRes_t *) + PDUSessionList->list.array[i]; + + if (!PDUSessionItem) { + ogs_error("No PDUSessionResourceSetupItemCxtRes"); + ngap_send_error_indication2(amf_ue, + NGAP_Cause_PR_protocol, NGAP_CauseProtocol_semantic_error); + return; + } + + transfer = &PDUSessionItem->pDUSessionResourceSetupResponseTransfer; + if (!transfer) { + ogs_error("No PDUSessionResourceSetupResponseTransfer"); + ngap_send_error_indication2(amf_ue, + NGAP_Cause_PR_protocol, NGAP_CauseProtocol_semantic_error); + return; + } + + if (PDUSessionItem->pDUSessionID == + OGS_NAS_PDU_SESSION_IDENTITY_UNASSIGNED) { + ogs_error("PDU Session Identity is unassigned"); + ngap_send_error_indication2(amf_ue, + NGAP_Cause_PR_protocol, NGAP_CauseProtocol_semantic_error); + return; + } + + sess = amf_sess_find_by_psi(amf_ue, PDUSessionItem->pDUSessionID); + if (!sess) { + ogs_error("Cannot find PDU Session ID [%d]", + (int)PDUSessionItem->pDUSessionID); + ngap_send_error_indication2(amf_ue, + NGAP_Cause_PR_radioNetwork, + NGAP_CauseRadioNetwork_unknown_PDU_session_ID); + return; + } + + /* UPDATE_UpCnxState - ACTIVATED */ + sess->ueUpCnxState = OpenAPI_up_cnx_state_ACTIVATED; + + memset(¶m, 0, sizeof(param)); + param.n2smbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN); + ogs_pkbuf_put_data(param.n2smbuf, transfer->buf, transfer->size); + + amf_sess_sbi_discover_and_send( + OpenAPI_nf_type_SMF, sess, ¶m, + amf_nsmf_pdu_session_build_update_sm_context); + + ogs_pkbuf_free(param.n2smbuf); + } } void ngap_handle_initial_context_setup_failure( @@ -568,18 +660,16 @@ void ngap_handle_initial_context_setup_failure( char buf[OGS_ADDRSTRLEN]; int i; + ran_ue_t *ran_ue = NULL; + uint64_t amf_ue_ngap_id; + NGAP_UnsuccessfulOutcome_t *unsuccessfulOutcome = NULL; NGAP_InitialContextSetupFailure_t *InitialContextSetupFailure = NULL; NGAP_InitialContextSetupFailureIEs_t *ie = NULL; - NGAP_RAN_UE_NGAP_ID_t *RAN_UE_NGAP_ID = NULL; + NGAP_AMF_UE_NGAP_ID_t *AMF_UE_NGAP_ID = NULL; NGAP_Cause_t *Cause = NULL; -#if 0 - amf_ue_t *amf_ue = NULL; -#endif - ran_ue_t *ran_ue = NULL; - ogs_assert(gnb); ogs_assert(gnb->sock); @@ -595,8 +685,8 @@ void ngap_handle_initial_context_setup_failure( for (i = 0; i < InitialContextSetupFailure->protocolIEs.list.count; i++) { ie = InitialContextSetupFailure->protocolIEs.list.array[i]; switch (ie->id) { - case NGAP_ProtocolIE_ID_id_RAN_UE_NGAP_ID: - RAN_UE_NGAP_ID = &ie->value.choice.RAN_UE_NGAP_ID; + case NGAP_ProtocolIE_ID_id_AMF_UE_NGAP_ID: + AMF_UE_NGAP_ID = &ie->value.choice.AMF_UE_NGAP_ID; break; case NGAP_ProtocolIE_ID_id_Cause: Cause = &ie->value.choice.Cause; @@ -608,35 +698,46 @@ void ngap_handle_initial_context_setup_failure( ogs_debug(" IP[%s] RAN_ID[%d]", OGS_ADDR(gnb->addr, buf), gnb->gnb_id); - if (!RAN_UE_NGAP_ID) { - ogs_error("No RAN_UE_NGAP_ID"); + if (!AMF_UE_NGAP_ID) { + ogs_error("No 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_ran_ue_ngap_id(gnb, *RAN_UE_NGAP_ID); - if (!ran_ue) { - ogs_error("Cannot find RAN_UE Context [%d]", (int)*RAN_UE_NGAP_ID); + if (asn_INTEGER2ulong(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, &ran_ue->ran_ue_ngap_id, &ran_ue->amf_ue_ngap_id, NGAP_Cause_PR_radioNetwork, - NGAP_CauseRadioNetwork_inconsistent_remote_UE_NGAP_ID); + NGAP_CauseRadioNetwork_unknown_local_UE_NGAP_ID); return; } ogs_debug(" RAN_UE_NGAP_ID[%d] AMF_UE_NGAP_ID[%lld]", ran_ue->ran_ue_ngap_id, (long long)ran_ue->amf_ue_ngap_id); + if (!Cause) { ogs_error("No Cause"); - ngap_send_error_indication(gnb, &ran_ue->amf_ue_ngap_id, RAN_UE_NGAP_ID, + ngap_send_error_indication( + gnb, &ran_ue->ran_ue_ngap_id, &ran_ue->amf_ue_ngap_id, NGAP_Cause_PR_protocol, NGAP_CauseProtocol_semantic_error); return; } ogs_debug(" Cause[Group:%d Cause:%d]", Cause->present, (int)Cause->choice.radioNetwork); -#if 0 /* * 19.2.2.3 in Spec 36.300 * @@ -648,139 +749,6 @@ void ngap_handle_initial_context_setup_failure( * that no hanging resources remain at the RAN. */ amf_send_delete_session_or_ran_ue_context_release(ran_ue); -#endif -} - -void ngap_handle_pdu_session_resource_setup_response( - amf_gnb_t *gnb, ogs_ngap_message_t *message) -{ - char buf[OGS_ADDRSTRLEN]; - int i; - - amf_ue_t *amf_ue = NULL; - ran_ue_t *ran_ue = NULL; - ogs_pkbuf_t *n2smbuf = NULL; - - NGAP_SuccessfulOutcome_t *successfulOutcome = NULL; - NGAP_PDUSessionResourceSetupResponse_t *PDUSessionResourceSetupResponse; - - NGAP_PDUSessionResourceSetupResponseIEs_t *ie = NULL; - NGAP_RAN_UE_NGAP_ID_t *RAN_UE_NGAP_ID = NULL; - NGAP_PDUSessionResourceSetupListSURes_t *PDUSessionList = NULL; - NGAP_PDUSessionResourceSetupItemSURes_t *PDUSessionItem = NULL; - OCTET_STRING_t *transfer = NULL; - - ogs_assert(gnb); - ogs_assert(gnb->sock); - - ogs_assert(message); - successfulOutcome = message->choice.successfulOutcome; - ogs_assert(successfulOutcome); - PDUSessionResourceSetupResponse = - &successfulOutcome->value.choice.PDUSessionResourceSetupResponse; - ogs_assert(PDUSessionResourceSetupResponse); - - ogs_debug("PDU session resource setup response"); - - for (i = 0; i < PDUSessionResourceSetupResponse->protocolIEs.list.count; - i++) { - ie = PDUSessionResourceSetupResponse->protocolIEs.list.array[i]; - switch (ie->id) { - case NGAP_ProtocolIE_ID_id_RAN_UE_NGAP_ID: - RAN_UE_NGAP_ID = &ie->value.choice.RAN_UE_NGAP_ID; - break; - case NGAP_ProtocolIE_ID_id_PDUSessionResourceSetupListSURes: - PDUSessionList = &ie->value.choice.PDUSessionResourceSetupListSURes; - break; - default: - break; - } - } - - ogs_debug(" IP[%s] RAN_ID[%d]", OGS_ADDR(gnb->addr, buf), gnb->gnb_id); - - if (!RAN_UE_NGAP_ID) { - ogs_error("No RAN_UE_NGAP_ID"); - ngap_send_error_indication(gnb, NULL, NULL, - NGAP_Cause_PR_protocol, NGAP_CauseProtocol_semantic_error); - return; - } - - if (!PDUSessionList) { - ogs_error("No PDUSessionResourceSetupListSURes"); - ngap_send_error_indication(gnb, NULL, NULL, - NGAP_Cause_PR_protocol, NGAP_CauseProtocol_semantic_error); - return; - } - - ran_ue = ran_ue_find_by_ran_ue_ngap_id(gnb, *RAN_UE_NGAP_ID); - if (!ran_ue) { - ogs_error("Cannot find RAN-UE Context [%d]", (int)*RAN_UE_NGAP_ID); - ngap_send_error_indication(gnb, NULL, NULL, - NGAP_Cause_PR_radioNetwork, - NGAP_CauseRadioNetwork_inconsistent_remote_UE_NGAP_ID); - return; - } - - ogs_debug(" RAN_UE_NGAP_ID[%d] AMF_UE_NGAP_ID[%lld]", - ran_ue->ran_ue_ngap_id, (long long)ran_ue->amf_ue_ngap_id); - - amf_ue = ran_ue->amf_ue; - if (!amf_ue) { - ogs_error("Cannot find AMF-UE Context [%d]", (int)*RAN_UE_NGAP_ID); - ngap_send_error_indication(gnb, NULL, NULL, - NGAP_Cause_PR_radioNetwork, - NGAP_CauseRadioNetwork_unknown_local_UE_NGAP_ID); - return; - } - - for (i = 0; i < PDUSessionList->list.count; i++) { - amf_sess_t *sess = NULL; - PDUSessionItem = (NGAP_PDUSessionResourceSetupItemSURes_t *) - PDUSessionList->list.array[i]; - - if (!PDUSessionItem) { - ogs_error("No PDUSessionResourceSetupItemSURes"); - ngap_send_error_indication(gnb, NULL, NULL, - NGAP_Cause_PR_protocol, NGAP_CauseProtocol_semantic_error); - return; - } - - transfer = &PDUSessionItem->pDUSessionResourceSetupResponseTransfer; - if (!transfer) { - ogs_error("No PDUSessionResourceSetupItemSURes"); - ngap_send_error_indication(gnb, NULL, NULL, - NGAP_Cause_PR_protocol, NGAP_CauseProtocol_semantic_error); - return; - } - - if (PDUSessionItem->pDUSessionID == - OGS_NAS_PDU_SESSION_IDENTITY_UNASSIGNED) { - ogs_error("PDU Session Identity is unassigned"); - ngap_send_error_indication(gnb, NULL, NULL, - NGAP_Cause_PR_protocol, NGAP_CauseProtocol_semantic_error); - return; - } - - sess = amf_sess_find_by_psi(amf_ue, PDUSessionItem->pDUSessionID); - if (!sess) { - ogs_error("Cannot find PDU Session ID [%d]", - (int)PDUSessionItem->pDUSessionID); - ngap_send_error_indication(gnb, NULL, NULL, - NGAP_Cause_PR_radioNetwork, - NGAP_CauseRadioNetwork_unknown_PDU_session_ID); - return; - } - - n2smbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN); - ogs_pkbuf_put_data(n2smbuf, transfer->buf, transfer->size); - - amf_sess_sbi_discover_and_send( - OpenAPI_nf_type_SMF, sess, n2smbuf, - amf_nsmf_pdu_session_build_update_sm_context); - - ogs_pkbuf_free(n2smbuf); - } } #if 0 @@ -822,8 +790,7 @@ void ngap_handle_ue_context_modification_response( } } - ogs_debug(" IP[%s] RAN_ID[%d]", - OGS_ADDR(gnb->addr, buf), gnb->gnb_id); + ogs_debug(" IP[%s] RAN_ID[%d]", OGS_ADDR(gnb->addr, buf), gnb->gnb_id); ogs_assert(RAN_UE_NGAP_ID); ran_ue = ran_ue_find_by_ran_ue_ngap_id(gnb, *RAN_UE_NGAP_ID); @@ -879,8 +846,7 @@ void ngap_handle_ue_context_modification_failure( } } - ogs_debug(" IP[%s] RAN_ID[%d]", - OGS_ADDR(gnb->addr, buf), gnb->gnb_id); + ogs_debug(" IP[%s] RAN_ID[%d]", OGS_ADDR(gnb->addr, buf), gnb->gnb_id); ogs_assert(RAN_UE_NGAP_ID); ogs_assert(Cause); @@ -902,23 +868,28 @@ cleanup: ogs_assert(amf_ue); CLEAR_SERVICE_INDICATOR(amf_ue); } +#endif void ngap_handle_ue_context_release_request( amf_gnb_t *gnb, ogs_ngap_message_t *message) { - char buf[OGS_ADDRSTRLEN]; int i; + char buf[OGS_ADDRSTRLEN]; + uint64_t amf_ue_ngap_id; + bool handled = false; + + ran_ue_t *ran_ue = NULL; + amf_ue_t *amf_ue = NULL; NGAP_InitiatingMessage_t *initiatingMessage = NULL; NGAP_UEContextReleaseRequest_t *UEContextReleaseRequest = NULL; NGAP_UEContextReleaseRequest_IEs_t *ie = NULL; NGAP_AMF_UE_NGAP_ID_t *AMF_UE_NGAP_ID = NULL; - NGAP_RAN_UE_NGAP_ID_t *RAN_UE_NGAP_ID = NULL; + NGAP_PDUSessionResourceListCxtRelReq_t *PDUSessionList = NULL; + NGAP_PDUSessionResourceItemCxtRelReq_t *PDUSessionItem = NULL; NGAP_Cause_t *Cause = NULL; - ran_ue_t *ran_ue = NULL; - ogs_assert(gnb); ogs_assert(gnb->sock); @@ -937,8 +908,8 @@ void ngap_handle_ue_context_release_request( case NGAP_ProtocolIE_ID_id_AMF_UE_NGAP_ID: AMF_UE_NGAP_ID = &ie->value.choice.AMF_UE_NGAP_ID; break; - case NGAP_ProtocolIE_ID_id_RAN_UE_NGAP_ID: - RAN_UE_NGAP_ID = &ie->value.choice.RAN_UE_NGAP_ID; + case NGAP_ProtocolIE_ID_id_PDUSessionResourceListCxtRelReq: + PDUSessionList = &ie->value.choice.PDUSessionResourceListCxtRelReq; break; case NGAP_ProtocolIE_ID_id_Cause: Cause = &ie->value.choice.Cause; @@ -948,25 +919,44 @@ void ngap_handle_ue_context_release_request( } } - ogs_debug(" IP[%s] RAN_ID[%d]", - OGS_ADDR(gnb->addr, buf), gnb->gnb_id); + ogs_debug(" IP[%s] RAN_ID[%d]", OGS_ADDR(gnb->addr, buf), gnb->gnb_id); - ogs_assert(AMF_UE_NGAP_ID); - ran_ue = ran_ue_find_by_amf_ue_ngap_id(*AMF_UE_NGAP_ID); - if (!ran_ue) { - ogs_warn("No RAN UE Context : AMF_UE_NGAP_ID[%d]", - (int)*AMF_UE_NGAP_ID); - ngap_send_error_indication(gnb, - AMF_UE_NGAP_ID, RAN_UE_NGAP_ID, - NGAP_Cause_PR_radioNetwork, - NGAP_CauseRadioNetwork_unknown_amf_ue_ngap_id); + if (!AMF_UE_NGAP_ID) { + ogs_error("No AMF_UE_NGAP_ID"); + ngap_send_error_indication(gnb, NULL, NULL, + NGAP_Cause_PR_protocol, NGAP_CauseProtocol_semantic_error); return; } - ogs_debug(" RAN_UE_NGAP_ID[%d] AMF_UE_NGAP_ID[%d]", - ran_ue->ran_ue_ngap_id, ran_ue->amf_ue_ngap_id); + if (asn_INTEGER2ulong(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; + } + + ogs_debug(" RAN_UE_NGAP_ID[%d] AMF_UE_NGAP_ID[%lld]", + ran_ue->ran_ue_ngap_id, (long long)ran_ue->amf_ue_ngap_id); + + if (!Cause) { + ogs_error("No Cause"); + ngap_send_error_indication( + gnb, &ran_ue->ran_ue_ngap_id, &ran_ue->amf_ue_ngap_id, + NGAP_Cause_PR_protocol, NGAP_CauseProtocol_semantic_error); + return; + } - ogs_assert(Cause); ogs_debug(" Cause[Group:%d Cause:%d]", Cause->present, (int)Cause->choice.radioNetwork); @@ -984,15 +974,86 @@ void ngap_handle_ue_context_release_request( break; } - amf_send_release_access_bearer_or_ue_context_release(ran_ue); + amf_ue = ran_ue->amf_ue; + if (!amf_ue) { + ogs_debug("No UE Context"); + ngap_send_ue_context_release_command(ran_ue, + NGAP_Cause_PR_nas, NGAP_CauseNas_normal_release, + NGAP_UE_CTX_REL_NG_CONTEXT_REMOVE, 0); + return; + } + + if (!PDUSessionList) { + ogs_error("No PDUSessionResourceListCxtRelReq"); + ngap_send_error_indication( + gnb, &ran_ue->ran_ue_ngap_id, &ran_ue->amf_ue_ngap_id, + NGAP_Cause_PR_protocol, NGAP_CauseProtocol_semantic_error); + return; + } + + for (i = 0; i < PDUSessionList->list.count; i++) { + amf_sess_t *sess = NULL; + PDUSessionItem = (NGAP_PDUSessionResourceItemCxtRelReq_t *) + PDUSessionList->list.array[i]; + + if (!PDUSessionItem) { + ogs_error("No PDUSessionResourceSetupItemSURes"); + ngap_send_error_indication2(amf_ue, + NGAP_Cause_PR_protocol, NGAP_CauseProtocol_semantic_error); + return; + } + + if (PDUSessionItem->pDUSessionID == + OGS_NAS_PDU_SESSION_IDENTITY_UNASSIGNED) { + ogs_error("PDU Session Identity is unassigned"); + ngap_send_error_indication2(amf_ue, + NGAP_Cause_PR_protocol, NGAP_CauseProtocol_semantic_error); + return; + } + + sess = amf_sess_find_by_psi(amf_ue, PDUSessionItem->pDUSessionID); + if (!sess) { + ogs_error("Cannot find PDU Session ID [%d]", + (int)PDUSessionItem->pDUSessionID); + ngap_send_error_indication2(amf_ue, + NGAP_Cause_PR_radioNetwork, + NGAP_CauseRadioNetwork_unknown_PDU_session_ID); + return; + } + + /* UPDATE_UpCnxState - DEACTIVATED */ + sess->ueUpCnxState = OpenAPI_up_cnx_state_DEACTIVATED; + + if (sess->smfUpCnxState == OpenAPI_up_cnx_state_ACTIVATED) { + amf_nsmf_pdu_session_update_sm_context_param_t param; + + memset(¶m, 0, sizeof(param)); + param.upCnxState = sess->ueUpCnxState; + param.ngApCause.group = Cause->present; + param.ngApCause.value = (int)Cause->choice.radioNetwork; + amf_sess_sbi_discover_and_send( + OpenAPI_nf_type_SMF, sess, ¶m, + amf_nsmf_pdu_session_build_update_sm_context); + + handled = true; + } + } + + if (!handled) { + ogs_error("SMF has already been deactivated"); + amf_send_delete_session_or_amf_ue_context_release(amf_ue); + } } void ngap_handle_ue_context_release_complete( amf_gnb_t *gnb, ogs_ngap_message_t *message) { - int rv; - char buf[OGS_ADDRSTRLEN]; int i; + char buf[OGS_ADDRSTRLEN]; + uint64_t amf_ue_ngap_id; + + amf_ue_t *amf_ue = NULL; + ran_ue_t *ran_ue = NULL; NGAP_SuccessfulOutcome_t *successfulOutcome = NULL; NGAP_UEContextReleaseComplete_t *UEContextReleaseComplete = NULL; @@ -1000,9 +1061,6 @@ void ngap_handle_ue_context_release_complete( NGAP_UEContextReleaseComplete_IEs_t *ie = NULL; NGAP_AMF_UE_NGAP_ID_t *AMF_UE_NGAP_ID = NULL; - amf_ue_t *amf_ue = NULL; - ran_ue_t *ran_ue = NULL; - ogs_assert(gnb); ogs_assert(gnb->sock); @@ -1026,33 +1084,45 @@ void ngap_handle_ue_context_release_complete( } } - ogs_debug(" IP[%s] RAN_ID[%d]", - OGS_ADDR(gnb->addr, buf), gnb->gnb_id); + ogs_debug(" IP[%s] RAN_ID[%d]", OGS_ADDR(gnb->addr, buf), gnb->gnb_id); - ogs_assert(AMF_UE_NGAP_ID); - ran_ue = ran_ue_find_by_amf_ue_ngap_id(*AMF_UE_NGAP_ID); - if (!ran_ue) { - ogs_warn("No RAN UE Context : AMF_UE_NGAP_ID[%d]", - (int)*AMF_UE_NGAP_ID); - ngap_send_error_indication(gnb, - AMF_UE_NGAP_ID, NULL, - NGAP_Cause_PR_radioNetwork, - NGAP_CauseRadioNetwork_unknown_amf_ue_ngap_id); + if (!AMF_UE_NGAP_ID) { + ogs_error("No AMF_UE_NGAP_ID"); + ngap_send_error_indication(gnb, NULL, NULL, + NGAP_Cause_PR_protocol, NGAP_CauseProtocol_semantic_error); return; } + if (asn_INTEGER2ulong(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; + } + + ogs_debug(" RAN_UE_NGAP_ID[%d] AMF_UE_NGAP_ID[%lld]", + ran_ue->ran_ue_ngap_id, (long long)ran_ue->amf_ue_ngap_id); + amf_ue = ran_ue->amf_ue; - ogs_debug(" RAN_UE_NGAP_ID[%d] AMF_UE_NGAP_ID[%d]", - ran_ue->ran_ue_ngap_id, ran_ue->amf_ue_ngap_id); - switch (ran_ue->ue_ctx_rel_action) { - case NGAP_UE_CTX_REL_S1_CONTEXT_REMOVE: + case NGAP_UE_CTX_REL_NG_CONTEXT_REMOVE: ogs_debug(" No Action"); ran_ue_remove(ran_ue); break; - case NGAP_UE_CTX_REL_S1_REMOVE_AND_UNLINK: - ogs_debug(" Action: S1 normal release"); + case NGAP_UE_CTX_REL_NG_REMOVE_AND_UNLINK: + ogs_debug(" Action: NG normal release"); ran_ue_remove(ran_ue); amf_ue_deassociate(amf_ue); break; @@ -1062,6 +1132,7 @@ void ngap_handle_ue_context_release_complete( amf_ue_remove(amf_ue); break; case NGAP_UE_CTX_REL_DELETE_INDIRECT_TUNNEL: +#if 0 ogs_debug(" Action: Delete indirect tunnel"); source_ue_deassociate_target_ue(ran_ue); @@ -1078,6 +1149,7 @@ void ngap_handle_ue_context_release_complete( rv = amf_ue_clear_indirect_tunnel(amf_ue); ogs_expect(rv == OGS_OK); } +#endif break; default: ogs_error("Invalid Action[%d]", ran_ue->ue_ctx_rel_action); @@ -1085,6 +1157,156 @@ void ngap_handle_ue_context_release_complete( } } +void ngap_handle_pdu_session_resource_setup_response( + amf_gnb_t *gnb, ogs_ngap_message_t *message) +{ + char buf[OGS_ADDRSTRLEN]; + int i; + + amf_ue_t *amf_ue = NULL; + ran_ue_t *ran_ue = NULL; + uint64_t amf_ue_ngap_id; + amf_nsmf_pdu_session_update_sm_context_param_t param; + + NGAP_SuccessfulOutcome_t *successfulOutcome = NULL; + NGAP_PDUSessionResourceSetupResponse_t *PDUSessionResourceSetupResponse; + + NGAP_PDUSessionResourceSetupResponseIEs_t *ie = NULL; + NGAP_AMF_UE_NGAP_ID_t *AMF_UE_NGAP_ID = NULL; + NGAP_PDUSessionResourceSetupListSURes_t *PDUSessionList = NULL; + NGAP_PDUSessionResourceSetupItemSURes_t *PDUSessionItem = NULL; + OCTET_STRING_t *transfer = NULL; + + ogs_assert(gnb); + ogs_assert(gnb->sock); + + ogs_assert(message); + successfulOutcome = message->choice.successfulOutcome; + ogs_assert(successfulOutcome); + PDUSessionResourceSetupResponse = + &successfulOutcome->value.choice.PDUSessionResourceSetupResponse; + ogs_assert(PDUSessionResourceSetupResponse); + + ogs_debug("PDU session resource setup response"); + + for (i = 0; i < PDUSessionResourceSetupResponse->protocolIEs.list.count; + i++) { + ie = PDUSessionResourceSetupResponse->protocolIEs.list.array[i]; + switch (ie->id) { + case NGAP_ProtocolIE_ID_id_AMF_UE_NGAP_ID: + AMF_UE_NGAP_ID = &ie->value.choice.AMF_UE_NGAP_ID; + break; + case NGAP_ProtocolIE_ID_id_PDUSessionResourceSetupListSURes: + PDUSessionList = &ie->value.choice.PDUSessionResourceSetupListSURes; + break; + default: + break; + } + } + + ogs_debug(" IP[%s] RAN_ID[%d]", OGS_ADDR(gnb->addr, buf), gnb->gnb_id); + + if (!AMF_UE_NGAP_ID) { + ogs_error("No AMF_UE_NGAP_ID"); + ngap_send_error_indication(gnb, NULL, NULL, + NGAP_Cause_PR_protocol, NGAP_CauseProtocol_semantic_error); + return; + } + + if (asn_INTEGER2ulong(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, &ran_ue->ran_ue_ngap_id, &ran_ue->amf_ue_ngap_id, + NGAP_Cause_PR_radioNetwork, + NGAP_CauseRadioNetwork_unknown_local_UE_NGAP_ID); + return; + } + + ogs_debug(" RAN_UE_NGAP_ID[%d] AMF_UE_NGAP_ID[%lld]", + ran_ue->ran_ue_ngap_id, (long long)ran_ue->amf_ue_ngap_id); + + amf_ue = ran_ue->amf_ue; + if (!amf_ue) { + ogs_error("Cannot find AMF-UE Context [%lld]", + (long long)amf_ue_ngap_id); + ngap_send_error_indication( + gnb, &ran_ue->ran_ue_ngap_id, &ran_ue->amf_ue_ngap_id, + NGAP_Cause_PR_radioNetwork, + NGAP_CauseRadioNetwork_unknown_local_UE_NGAP_ID); + return; + } + + if (!PDUSessionList) { + ogs_error("No PDUSessionResourceSetupListSURes"); + ngap_send_error_indication2(amf_ue, + NGAP_Cause_PR_protocol, NGAP_CauseProtocol_semantic_error); + return; + } + + for (i = 0; i < PDUSessionList->list.count; i++) { + amf_sess_t *sess = NULL; + PDUSessionItem = (NGAP_PDUSessionResourceSetupItemSURes_t *) + PDUSessionList->list.array[i]; + + if (!PDUSessionItem) { + ogs_error("No PDUSessionResourceSetupItemSURes"); + ngap_send_error_indication2(amf_ue, + NGAP_Cause_PR_protocol, NGAP_CauseProtocol_semantic_error); + return; + } + + transfer = &PDUSessionItem->pDUSessionResourceSetupResponseTransfer; + if (!transfer) { + ogs_error("No PDUSessionResourceSetupResponseTransfer"); + ngap_send_error_indication2(amf_ue, + NGAP_Cause_PR_protocol, NGAP_CauseProtocol_semantic_error); + return; + } + + if (PDUSessionItem->pDUSessionID == + OGS_NAS_PDU_SESSION_IDENTITY_UNASSIGNED) { + ogs_error("PDU Session Identity is unassigned"); + ngap_send_error_indication2(amf_ue, + NGAP_Cause_PR_protocol, NGAP_CauseProtocol_semantic_error); + return; + } + + sess = amf_sess_find_by_psi(amf_ue, PDUSessionItem->pDUSessionID); + if (!sess) { + ogs_error("Cannot find PDU Session ID [%d]", + (int)PDUSessionItem->pDUSessionID); + ngap_send_error_indication2(amf_ue, + NGAP_Cause_PR_radioNetwork, + NGAP_CauseRadioNetwork_unknown_PDU_session_ID); + return; + } + + /* UPDATE_UpCnxState - ACTIVATED */ + sess->ueUpCnxState = OpenAPI_up_cnx_state_ACTIVATED; + + memset(¶m, 0, sizeof(param)); + param.n2smbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN); + ogs_pkbuf_put_data(param.n2smbuf, transfer->buf, transfer->size); + + amf_sess_sbi_discover_and_send( + OpenAPI_nf_type_SMF, sess, ¶m, + amf_nsmf_pdu_session_build_update_sm_context); + + ogs_pkbuf_free(param.n2smbuf); + } +} + +#if 0 void ngap_handle_path_switch_request( amf_gnb_t *gnb, ogs_ngap_message_t *message) { diff --git a/src/amf/ngap-path.c b/src/amf/ngap-path.c index 15f87cce3..51d0e96a8 100644 --- a/src/amf/ngap-path.c +++ b/src/amf/ngap-path.c @@ -296,6 +296,7 @@ void ngap_send_ue_context_modification_request(amf_ue_t *amf_ue) rv = nas_5gs_send_to_gnb(amf_ue, ngapbuf); ogs_expect(rv == OGS_OK); } +#endif void ngap_send_ue_context_release_command( ran_ue_t *ran_ue, NGAP_Cause_PR group, long cause, @@ -306,9 +307,9 @@ void ngap_send_ue_context_release_command( ogs_assert(ran_ue); - ogs_debug("[AMF] UE Context release command"); - ogs_debug(" RAN_UE_NGAP_ID[%d] AMF_UE_NGAP_ID[%d]", - ran_ue->ran_ue_ngap_id, ran_ue->amf_ue_ngap_id); + ogs_debug("UE Context release command"); + ogs_debug(" RAN_UE_NGAP_ID[%d] AMF_UE_NGAP_ID[%lld]", + ran_ue->ran_ue_ngap_id, (long long)ran_ue->amf_ue_ngap_id); if (delay) { ogs_assert(action != NGAP_UE_CTX_REL_INVALID_ACTION); @@ -337,6 +338,7 @@ void ngap_send_ue_context_release_command( } } +#if 0 void ngap_send_paging(amf_ue_t *amf_ue, NGAP_CNDomain_t cn_domain) { ogs_pkbuf_t *ngapbuf = NULL; @@ -512,8 +514,8 @@ void ngap_send_amf_status_transfer( void ngap_send_error_indication( amf_gnb_t *gnb, + uint32_t *ran_ue_ngap_id, uint64_t *amf_ue_ngap_id, - NGAP_RAN_UE_NGAP_ID_t *ran_ue_ngap_id, NGAP_Cause_PR group, long cause) { int rv; @@ -522,7 +524,7 @@ void ngap_send_error_indication( ogs_assert(gnb); ngapbuf = ngap_build_error_indication( - amf_ue_ngap_id, ran_ue_ngap_id, group, cause); + ran_ue_ngap_id, amf_ue_ngap_id, group, cause); ogs_expect_or_return(ngapbuf); rv = ngap_send_to_gnb(gnb, ngapbuf, NGAP_NON_UE_SIGNALLING); @@ -541,8 +543,8 @@ void ngap_send_error_indication2( gnb = ran_ue->gnb; ogs_expect_or_return(gnb); - ngap_send_error_indication(gnb, &ran_ue->amf_ue_ngap_id, - (NGAP_RAN_UE_NGAP_ID_t *)&ran_ue->ran_ue_ngap_id, group, cause); + ngap_send_error_indication( + gnb, &ran_ue->ran_ue_ngap_id, &ran_ue->amf_ue_ngap_id, group, cause); } #if 0 diff --git a/src/amf/ngap-path.h b/src/amf/ngap-path.h index 78034a499..3b2b45dcc 100644 --- a/src/amf/ngap-path.h +++ b/src/amf/ngap-path.h @@ -89,8 +89,8 @@ void ngap_send_amf_status_transfer( *gnb_statustransfer_transparentContainer); void ngap_send_error_indication( amf_gnb_t *gnb, + uint32_t *ran_ue_ngap_id, uint64_t *amf_ue_ngap_id, - NGAP_RAN_UE_NGAP_ID_t *ran_ue_ngap_id, NGAP_Cause_PR group, long cause); void ngap_send_error_indication2( amf_ue_t *amf_ue, NGAP_Cause_PR group, long cause); diff --git a/src/amf/ngap-sm.c b/src/amf/ngap-sm.c index 0a04e0b06..29cdb2c17 100644 --- a/src/amf/ngap-sm.c +++ b/src/amf/ngap-sm.c @@ -84,10 +84,10 @@ void ngap_state_operational(ogs_fsm_t *s, amf_event_t *e) case NGAP_ProcedureCode_id_UERadioCapabilityInfoIndication: ngap_handle_ue_radio_capability_info_indication(gnb, pdu); break; -#if 0 case NGAP_ProcedureCode_id_UEContextReleaseRequest: ngap_handle_ue_context_release_request( gnb, pdu); break; +#if 0 case NGAP_ProcedureCode_id_PathSwitchRequest: ngap_handle_path_switch_request(gnb, pdu); break; @@ -134,10 +134,11 @@ void ngap_state_operational(ogs_fsm_t *s, amf_event_t *e) case NGAP_ProcedureCode_id_UEContextModification: ngap_handle_ue_context_modification_response(gnb, pdu); break; +#endif case NGAP_ProcedureCode_id_UEContextRelease: - ngap_handle_ue_context_release_complete( - gnb, pdu); + ngap_handle_ue_context_release_complete(gnb, pdu); break; +#if 0 case NGAP_ProcedureCode_id_HandoverResourceAllocation: ngap_handle_handover_request_ack(gnb, pdu); break; @@ -178,15 +179,13 @@ void ngap_state_operational(ogs_fsm_t *s, amf_event_t *e) break; case AMF_EVT_NGAP_TIMER: switch (e->timer_id) { -#if 0 - case AMF_TIMER_S1_DELAYED_SEND: - ogs_assert(e->gnb_ue); + case AMF_TIMER_NG_DELAYED_SEND: + ogs_assert(e->ran_ue); ogs_assert(e->pkbuf); - ogs_expect(OGS_OK == ngap_send_to_gnb_ue(e->gnb_ue, e->pkbuf)); + ogs_expect(OGS_OK == ngap_send_to_ran_ue(e->ran_ue, e->pkbuf)); ogs_timer_delete(e->timer); break; -#endif default: ogs_error("Unknown timer[%s:%d]", amf_timer_get_name(e->timer_id), e->timer_id); diff --git a/src/amf/nsmf-build.c b/src/amf/nsmf-build.c index 7627d8831..4a24c2594 100644 --- a/src/amf/nsmf-build.c +++ b/src/amf/nsmf-build.c @@ -121,12 +121,15 @@ ogs_sbi_request_t *amf_nsmf_pdu_session_build_create_sm_context( ogs_sbi_request_t *amf_nsmf_pdu_session_build_update_sm_context( amf_sess_t *sess, void *data) { + amf_nsmf_pdu_session_update_sm_context_param_t *param = data; ogs_sbi_message_t message; ogs_sbi_request_t *request = NULL; OpenAPI_sm_context_update_data_t SmContextUpdateData; OpenAPI_ref_to_binary_data_t n2SmInfo; + OpenAPI_ng_ap_cause_t ngApCause; + ogs_assert(param); ogs_assert(sess); ogs_assert(sess->sm_context_ref); @@ -139,23 +142,39 @@ ogs_sbi_request_t *amf_nsmf_pdu_session_build_update_sm_context( message.h.resource.component[1] = sess->sm_context_ref; message.h.resource.component[2] = (char *)OGS_SBI_RESOURCE_NAME_MODIFY; - memset(&SmContextUpdateData, 0, sizeof(SmContextUpdateData)); - SmContextUpdateData.n2_sm_info_type = - OpenAPI_n2_sm_info_type_PDU_RES_SETUP_RSP; - SmContextUpdateData.n2_sm_info = &n2SmInfo; + if (param->n2smbuf) { + memset(&SmContextUpdateData, 0, sizeof(SmContextUpdateData)); + SmContextUpdateData.n2_sm_info_type = + OpenAPI_n2_sm_info_type_PDU_RES_SETUP_RSP; + SmContextUpdateData.n2_sm_info = &n2SmInfo; - memset(&n2SmInfo, 0, sizeof(n2SmInfo)); - n2SmInfo.content_id = (char *)OGS_SBI_CONTENT_NGAP_SM_ID; + memset(&n2SmInfo, 0, sizeof(n2SmInfo)); + n2SmInfo.content_id = (char *)OGS_SBI_CONTENT_NGAP_SM_ID; - message.SmContextUpdateData = &SmContextUpdateData; + message.part[message.num_of_part].pkbuf = param->n2smbuf; + if (message.part[message.num_of_part].pkbuf) { + message.part[message.num_of_part].content_id = + (char *)OGS_SBI_CONTENT_NGAP_SM_ID; + message.part[message.num_of_part].content_type = + (char *)OGS_SBI_CONTENT_NGAP_TYPE; + message.num_of_part++; + } - message.part[message.num_of_part].pkbuf = data; - if (message.part[message.num_of_part].pkbuf) { - message.part[message.num_of_part].content_id = - (char *)OGS_SBI_CONTENT_NGAP_SM_ID; - message.part[message.num_of_part].content_type = - (char *)OGS_SBI_CONTENT_NGAP_TYPE; - message.num_of_part++; + message.SmContextUpdateData = &SmContextUpdateData; + } + + if (param->upCnxState) { + memset(&SmContextUpdateData, 0, sizeof(SmContextUpdateData)); + SmContextUpdateData.up_cnx_state = param->upCnxState; + + if (param->ngApCause.group) { + SmContextUpdateData.ng_ap_cause = &ngApCause; + memset(&ngApCause, 0, sizeof(ngApCause)); + ngApCause.group = param->ngApCause.group; + ngApCause.value = param->ngApCause.value; + } + + message.SmContextUpdateData = &SmContextUpdateData; } request = ogs_sbi_build_request(&message); @@ -163,3 +182,27 @@ ogs_sbi_request_t *amf_nsmf_pdu_session_build_update_sm_context( return request; } + +ogs_sbi_request_t *amf_nsmf_pdu_session_build_release_sm_context( + amf_sess_t *sess, void *data) +{ + ogs_sbi_message_t message; + ogs_sbi_request_t *request = NULL; + + ogs_assert(sess); + ogs_assert(sess->sm_context_ref); + + memset(&message, 0, sizeof(message)); + message.h.method = (char *)OGS_SBI_HTTP_METHOD_POST; + message.h.service.name = (char *)OGS_SBI_SERVICE_NAME_NSMF_PDUSESSION; + message.h.api.version = (char *)OGS_SBI_API_V1; + message.h.resource.component[0] = + (char *)OGS_SBI_RESOURCE_NAME_SM_CONTEXTS; + message.h.resource.component[1] = sess->sm_context_ref; + message.h.resource.component[2] = (char *)OGS_SBI_RESOURCE_NAME_RELEASE; + + request = ogs_sbi_build_request(&message); + ogs_assert(request); + + return request; +} diff --git a/src/amf/nsmf-build.h b/src/amf/nsmf-build.h index 22aaaa8ee..768f8f524 100644 --- a/src/amf/nsmf-build.h +++ b/src/amf/nsmf-build.h @@ -26,10 +26,21 @@ extern "C" { #endif +typedef struct amf_nsmf_pdu_session_update_sm_context_param_s { + ogs_pkbuf_t *n2smbuf; + OpenAPI_up_cnx_state_e upCnxState; + struct { + int group; + int value; + } ngApCause; +} amf_nsmf_pdu_session_update_sm_context_param_t; + ogs_sbi_request_t *amf_nsmf_pdu_session_build_create_sm_context( amf_sess_t *sess, void *data); ogs_sbi_request_t *amf_nsmf_pdu_session_build_update_sm_context( amf_sess_t *sess, void *data); +ogs_sbi_request_t *amf_nsmf_pdu_session_build_release_sm_context( + amf_sess_t *sess, void *data); #ifdef __cplusplus } diff --git a/src/amf/nsmf-handler.c b/src/amf/nsmf-handler.c index ede66db94..5d77c9f8b 100644 --- a/src/amf/nsmf-handler.c +++ b/src/amf/nsmf-handler.c @@ -20,6 +20,7 @@ #include "nsmf-handler.h" #include "nas-path.h" #include "ngap-path.h" +#include "sbi-path.h" #include "gmm-build.h" @@ -67,6 +68,10 @@ int amf_nsmf_pdu_session_handle_create_sm_context( ogs_free(sess->sm_context_ref); sess->sm_context_ref = ogs_strdup(message.h.resource.component[1]); + /* Update UpCnxState */ + sess->ueUpCnxState = OpenAPI_up_cnx_state_ACTIVATING; + sess->smfUpCnxState = OpenAPI_up_cnx_state_ACTIVATING; + ogs_sbi_header_free(&header); } else { @@ -113,14 +118,121 @@ int amf_nsmf_pdu_session_handle_create_sm_context( int amf_nsmf_pdu_session_handle_update_sm_context( amf_sess_t *sess, ogs_sbi_message_t *recvmsg) { + amf_ue_t *amf_ue = NULL; ogs_assert(sess); + amf_ue = sess->amf_ue; + ogs_assert(amf_ue); ogs_assert(recvmsg); - if (recvmsg->res_status == OGS_SBI_HTTP_STATUS_NO_CONTENT) { - /* Nothing */ + if (recvmsg->res_status == OGS_SBI_HTTP_STATUS_NO_CONTENT || + recvmsg->res_status == OGS_SBI_HTTP_STATUS_OK) { + if (recvmsg->res_status == OGS_SBI_HTTP_STATUS_OK) { + /* Nothing */ + } - } else if (recvmsg->res_status == OGS_SBI_HTTP_STATUS_OK) { - ogs_fatal("TODO"); + /* UPDATE_UpCnxState - SYNC */ + sess->smfUpCnxState = sess->ueUpCnxState; + + if (sess->ueUpCnxState == OpenAPI_up_cnx_state_ACTIVATED) { + /* + * 1. PDUSessionResourceSetupResponse + * 2. /nsmf-pdusession/v1/sm-contexts/{smContextRef}/modify + * 3. PFCP Session Modifcation Request (OuterHeaderCreation) + * 4. PFCP Session Modifcation Response + */ + + /* + * 1. InitialContextSetupResponse + * 2. /nsmf-pdusession/v1/sm-contexts/{smContextRef}/modify + * 3. PFCP Session Modifcation Request (Apply: FORWARD) + * 4. PFCP Session Modifcation Response + */ + + /* Nothing */ + + } else if (sess->ueUpCnxState == OpenAPI_up_cnx_state_DEACTIVATED) { + /* + * 1. UEContextReleaseRequest + * 2. /nsmf-pdusession/v1/sm-contexts/{smContextRef}/modify + * 3. PFCP Session Modifcation Request (Apply:Buff & NOCP) + * 4. PFCP Session Modifcation Response + * 5. UEContextReleaseCommand + * 6. UEContextReleaseComplete + */ + + if (SESSION_UP_CNX_STATE_SYNCHED(amf_ue)) { + ran_ue_t *ran_ue = amf_ue->ran_ue; + ogs_assert(ran_ue); + ngap_send_ue_context_release_command(ran_ue, + NGAP_Cause_PR_nas, NGAP_CauseNas_normal_release, + NGAP_UE_CTX_REL_NG_CONTEXT_REMOVE, 0); + } + + } else if (sess->ueUpCnxState == OpenAPI_up_cnx_state_ACTIVATING) { + + OpenAPI_sm_context_updated_data_t *SmContextUpdatedData = NULL; + OpenAPI_ref_to_binary_data_t *n2SmInfo = NULL; + ogs_pkbuf_t *n2smbuf = NULL; + + /* + * 1. ServiceRequest + * 2. /nsmf-pdusession/v1/sm-contexts/{smContextRef}/modify + */ + + SmContextUpdatedData = recvmsg->SmContextUpdatedData; + if (!SmContextUpdatedData) { + ogs_error("No SmContextUpdatedData"); + nas_5gs_send_gmm_reject(amf_ue, + OGS_5GMM_CAUSE_5GS_SERVICES_NOT_ALLOWED); + return OGS_ERROR; + } + + n2SmInfo = SmContextUpdatedData->n2_sm_info; + if (!n2SmInfo || !n2SmInfo->content_id) { + ogs_error("No SmInfo"); + nas_5gs_send_gmm_reject(amf_ue, + OGS_5GMM_CAUSE_5GS_SERVICES_NOT_ALLOWED); + return OGS_ERROR; + } + + sess->n2SmInfoType = SmContextUpdatedData->n2_sm_info_type; + if (!sess->n2SmInfoType) { + ogs_error("No SmInfoType"); + nas_5gs_send_gmm_reject(amf_ue, + OGS_5GMM_CAUSE_5GS_SERVICES_NOT_ALLOWED); + return OGS_ERROR; + } + + n2smbuf = ogs_sbi_find_part_by_content_id( + recvmsg, n2SmInfo->content_id); + if (!n2smbuf) { + ogs_error("[%s] No N2 SM Content", amf_ue->supi); + nas_5gs_send_gmm_reject(amf_ue, + OGS_5GMM_CAUSE_5GS_SERVICES_NOT_ALLOWED); + return OGS_ERROR; + } + + sess->n2smbuf = ogs_pkbuf_copy(n2smbuf); + ogs_assert(sess->n2smbuf); + + if (SESSION_UP_CNX_STATE_SYNCHED(amf_ue)) { + switch(amf_ue->nas.message_type) { + case OGS_NAS_5GS_REGISTRATION_REQUEST: + nas_5gs_send_registration_accept(amf_ue); + break; + case OGS_NAS_5GS_SERVICE_REQUEST: + nas_5gs_send_service_accept(amf_ue); + break; + default: + ogs_error("Unknown message type [%d]", + amf_ue->nas.message_type); + } + } + + } else { + ogs_error("Invalid UpCnxState [UE:%d,SMF:%d]", + sess->ueUpCnxState, sess->smfUpCnxState); + } } else { amf_ue_t *amf_ue = NULL; @@ -173,3 +285,67 @@ int amf_nsmf_pdu_session_handle_update_sm_context( return OGS_OK; } + +int amf_nsmf_pdu_session_handle_release_sm_context( + amf_sess_t *sess, ogs_sbi_message_t *recvmsg) +{ + amf_ue_t *amf_ue = NULL; + + ogs_assert(sess); + amf_ue = sess->amf_ue; + ogs_assert(amf_ue); + ogs_assert(recvmsg); + + ogs_debug("Release SM Context [%d]", recvmsg->res_status); + + if (OGS_FSM_CHECK(&amf_ue->sm, gmm_state_authentication)) { + if (ogs_list_count(&amf_ue->sess_list) == 1) /* Last Session */ { + amf_ue_sbi_discover_and_send(OpenAPI_nf_type_AUSF, amf_ue, NULL, + amf_nausf_auth_build_authenticate); + } + } else if (OGS_FSM_CHECK(&amf_ue->sm, gmm_state_de_registered)) { + if (ogs_list_count(&amf_ue->sess_list) == 1) /* Last Session */ { + nas_5gs_send_de_registration_accept(amf_ue); + } + } else if (OGS_FSM_CHECK(&amf_ue->sm, gmm_state_registered) || + OGS_FSM_CHECK(&amf_ue->sm, gmm_state_exception)) { + /* + * TODO : PDUSessionResourceReleaseCommand + * + if (OGS_FSM_CHECK(&bearer->sm, esm_state_pdn_will_disconnect)) { + nas_eps_send_deactivate_bearer_context_request(bearer); + + mme_sess_remove() should not be called here. + + Session will be removed if Deactivate bearer context + accept is received + CLEAR_SGW_S1U_PATH(sess); + return; + } else if (OGS_FSM_CHECK(&bearer->sm, esm_state_active) || + OGS_FSM_CHECK(&bearer->sm, esm_state_inactive)) { + } + */ + if (ogs_list_count(&amf_ue->sess_list) == 1) /* Last Session */ { + ran_ue_t *ran_ue = amf_ue->ran_ue; + if (ran_ue) { + ngap_send_ue_context_release_command(ran_ue, + NGAP_Cause_PR_nas, NGAP_CauseNas_normal_release, + NGAP_UE_CTX_REL_UE_CONTEXT_REMOVE, 0); + } else { + ogs_error("gNB-NG Context has already been removed"); + } + } + } else if (OGS_FSM_CHECK(&amf_ue->sm, gmm_state_security_mode)) { + ogs_error("Releasing SM Context in security-mode STATE"); + + } else if (OGS_FSM_CHECK(&amf_ue->sm, gmm_state_initial_context_setup)) { + ogs_error("Releasing SM Context in initial context setup STATE"); + + } else { + ogs_error("Releasing SM Context : INVALID STATE"); + } + + amf_sess_remove(sess); + + return OGS_OK; +} diff --git a/src/amf/sbi-path.c b/src/amf/sbi-path.c index ad51f16e6..8e4abd5cd 100644 --- a/src/amf/sbi-path.c +++ b/src/amf/sbi-path.c @@ -124,6 +124,11 @@ void amf_ue_sbi_discover_and_send( ogs_assert(nf_type); ogs_assert(amf_ue); + if (amf_ue->sbi.running == true) { + ogs_error("amf_ue_sbi_discover_and_send() is running"); + return; + } + amf_ue->sbi.nf_state_registered = amf_nf_state_registered; amf_ue->sbi.client_wait.duration = amf_timer_cfg(AMF_TIMER_SBI_CLIENT_WAIT)->duration; @@ -143,6 +148,11 @@ void amf_sess_sbi_discover_and_send( ogs_assert(sess); ogs_assert(build); + if (sess->sbi.running == true) { + ogs_error("amf_sess_sbi_discover_and_send() is running"); + return; + } + sess->sbi.nf_state_registered = amf_nf_state_registered; sess->sbi.client_wait.duration = amf_timer_cfg(AMF_TIMER_SBI_CLIENT_WAIT)->duration; @@ -153,3 +163,16 @@ void amf_sess_sbi_discover_and_send( OGS_SBI_HTTP_STATUS_GATEWAY_TIMEOUT); } } + +void amf_sbi_send_release_all_sm_contexts(amf_ue_t *amf_ue) +{ + amf_sess_t *sess = NULL; + + ogs_assert(amf_ue); + + ogs_list_for_each(&amf_ue->sess_list, sess) { + amf_sess_sbi_discover_and_send( + OpenAPI_nf_type_SMF, sess, NULL, + amf_nsmf_pdu_session_build_release_sm_context); + } +} diff --git a/src/amf/sbi-path.h b/src/amf/sbi-path.h index 1312069f0..2f571da32 100644 --- a/src/amf/sbi-path.h +++ b/src/amf/sbi-path.h @@ -40,6 +40,8 @@ void amf_sess_sbi_discover_and_send( OpenAPI_nf_type_e nf_type, amf_sess_t *sess, void *data, ogs_sbi_request_t *(*build)(amf_sess_t *sess, void *data)); +void amf_sbi_send_release_all_sm_contexts(amf_ue_t *amf_ue); + #ifdef __cplusplus } #endif diff --git a/src/amf/timer.c b/src/amf/timer.c index 5dedc6f1e..8941409b0 100644 --- a/src/amf/timer.c +++ b/src/amf/timer.c @@ -52,16 +52,10 @@ static amf_timer_cfg_t g_amf_timer_cfg[MAX_NUM_OF_AMF_TIMER] = { /* IDENTITY REQUEST sent */ [AMF_TIMER_T3570] = { .max_count = 4, .duration = ogs_time_from_sec(3) }, - - /* 5GSM INFORMATION REQUEST sent */ - [AMF_TIMER_T3589] = - { .max_count = 2, .duration = ogs_time_from_sec(4) }, }; static void gmm_timer_event_send( amf_timer_e timer_id, amf_ue_t *amf_ue); -static void gsm_timer_event_send( - amf_timer_e timer_id, amf_bearer_t *bearer); amf_timer_cfg_t *amf_timer_cfg(amf_timer_e id) { @@ -98,12 +92,6 @@ const char *amf_timer_get_name(amf_timer_e id) return "AMF_TIMER_T3560"; case AMF_TIMER_T3570: return "AMF_TIMER_T3570"; - case AMF_TIMER_T3589: - return "AMF_TIMER_T3589"; -#if 0 - case AMF_TIMER_SGS_CLI_CONN_TO_SRV: - return "AMF_TIMER_SGS_CLI_CONN_TO_SRV"; -#endif default: break; } @@ -236,30 +224,3 @@ void amf_timer_t3570_expire(void *data) { gmm_timer_event_send(AMF_TIMER_T3570, data); } - -static void gsm_timer_event_send( - amf_timer_e timer_id, amf_bearer_t *bearer) -{ - int rv; - amf_event_t *e = NULL; - amf_ue_t *amf_ue = NULL; - ogs_assert(bearer); - amf_ue = bearer->amf_ue; - ogs_assert(bearer); - - e = amf_event_new(AMF_EVT_5GSM_TIMER); - e->timer_id = timer_id; - e->amf_ue = amf_ue; - e->bearer = bearer; - - rv = ogs_queue_push(amf_self()->queue, e); - if (rv != OGS_OK) { - ogs_warn("ogs_queue_push() failed:%d", (int)rv); - amf_event_free(e); - } -} - -void amf_timer_t3589_expire(void *data) -{ - gsm_timer_event_send(AMF_TIMER_T3589, data); -} diff --git a/src/amf/timer.h b/src/amf/timer.h index b691510eb..f4c24206a 100644 --- a/src/amf/timer.h +++ b/src/amf/timer.h @@ -46,8 +46,6 @@ typedef enum { AMF_TIMER_T3560, AMF_TIMER_T3570, - AMF_TIMER_T3589, - MAX_NUM_OF_AMF_TIMER, } amf_timer_e; @@ -76,7 +74,6 @@ void amf_timer_t3550_expire(void *data); void amf_timer_t3555_expire(void *data); void amf_timer_t3560_expire(void *data); void amf_timer_t3570_expire(void *data); -void amf_timer_t3589_expire(void *data); #ifdef __cplusplus } diff --git a/src/ausf/ausf-sm.c b/src/ausf/ausf-sm.c index 57246ca83..84348af02 100644 --- a/src/ausf/ausf-sm.c +++ b/src/ausf/ausf-sm.c @@ -257,16 +257,17 @@ void ausf_state_operational(ogs_fsm_t *s, ausf_event_t *e) sbi_object = e->sbi.data; ogs_assert(sbi_object); + ogs_timer_stop(sbi_object->client_wait.timer); + + sbi_object->running = false; + SWITCH(message.h.method) CASE(OGS_SBI_HTTP_METHOD_GET) - if (message.res_status == OGS_SBI_HTTP_STATUS_OK) { - ogs_timer_stop(sbi_object->client_wait.timer); - + if (message.res_status == OGS_SBI_HTTP_STATUS_OK) ausf_nnrf_handle_nf_discover(sbi_object, &message); - } else { + else ogs_error("HTTP response error [%d]", message.res_status); - } break; DEFAULT @@ -289,6 +290,9 @@ void ausf_state_operational(ogs_fsm_t *s, ausf_event_t *e) e->ausf_ue = ausf_ue; e->sbi.message = &message; + + ausf_ue->sbi.running = false; + ogs_fsm_dispatch(&ausf_ue->sm, e); if (OGS_FSM_CHECK(&ausf_ue->sm, ausf_ue_state_exception)) { ogs_error("[%s] State machine exception", ausf_ue->suci); @@ -340,6 +344,8 @@ void ausf_state_operational(ogs_fsm_t *s, ausf_event_t *e) session = sbi_object->session; ogs_assert(session); + sbi_object->running = false; + ogs_error("Cannot receive SBI message"); ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_GATEWAY_TIMEOUT, NULL, diff --git a/src/ausf/context.c b/src/ausf/context.c index 5cec22011..9ded260e3 100644 --- a/src/ausf/context.c +++ b/src/ausf/context.c @@ -141,6 +141,7 @@ ausf_ue_t *ausf_ue_add(char *suci) ausf_ue->sbi.client_wait.timer = ogs_timer_add( self.timer_mgr, ausf_timer_sbi_client_wait_expire, ausf_ue); + memset(&e, 0, sizeof(e)); e.ausf_ue = ausf_ue; ogs_fsm_create(&ausf_ue->sm, ausf_ue_state_initial, ausf_ue_state_final); ogs_fsm_init(&ausf_ue->sm, &e); @@ -158,6 +159,7 @@ void ausf_ue_remove(ausf_ue_t *ausf_ue) ogs_list_remove(&self.ausf_ue_list, ausf_ue); + memset(&e, 0, sizeof(e)); e.ausf_ue = ausf_ue; ogs_fsm_fini(&ausf_ue->sm, &e); ogs_fsm_delete(&ausf_ue->sm); diff --git a/src/ausf/nausf-handler.c b/src/ausf/nausf-handler.c index b30eca32f..62b95ea8d 100644 --- a/src/ausf/nausf-handler.c +++ b/src/ausf/nausf-handler.c @@ -54,7 +54,8 @@ bool ausf_nausf_auth_handle_authenticate( ogs_free(ausf_ue->serving_network_name); ausf_ue->serving_network_name = ogs_strdup(serving_network_name); - ausf_sbi_discover_and_send(OpenAPI_nf_type_UDM, ausf_ue, NULL, + ausf_sbi_discover_and_send(OpenAPI_nf_type_UDM, ausf_ue, + AuthenticationInfo->resynchronization_info, ausf_nudm_ueau_build_get); return true; diff --git a/src/ausf/nf-sm.c b/src/ausf/nf-sm.c index 209c1e8f9..da724513a 100644 --- a/src/ausf/nf-sm.c +++ b/src/ausf/nf-sm.c @@ -28,6 +28,7 @@ void ausf_nf_fsm_init(ogs_sbi_nf_instance_t *nf_instance) ogs_assert(nf_instance); + memset(&e, 0, sizeof(e)); e.sbi.data = nf_instance; ogs_fsm_create(&nf_instance->sm, @@ -40,6 +41,8 @@ void ausf_nf_fsm_fini(ogs_sbi_nf_instance_t *nf_instance) ausf_event_t e; ogs_assert(nf_instance); + + memset(&e, 0, sizeof(e)); e.sbi.data = nf_instance; ogs_fsm_fini(&nf_instance->sm, &e); diff --git a/src/ausf/nudm-build.c b/src/ausf/nudm-build.c index 68743d4cb..bc36979f4 100644 --- a/src/ausf/nudm-build.c +++ b/src/ausf/nudm-build.c @@ -24,7 +24,8 @@ ogs_sbi_request_t *ausf_nudm_ueau_build_get(ausf_ue_t *ausf_ue, void *data) ogs_sbi_message_t message; ogs_sbi_request_t *request = NULL; - OpenAPI_authentication_info_request_t *AuthenticationInfoRequest = NULL; + OpenAPI_authentication_info_request_t AuthenticationInfoRequest; + OpenAPI_resynchronization_info_t ResynchronizationInfo; ogs_assert(ausf_ue); @@ -38,22 +39,29 @@ ogs_sbi_request_t *ausf_nudm_ueau_build_get(ausf_ue_t *ausf_ue, void *data) message.h.resource.component[2] = (char *)OGS_SBI_RESOURCE_NAME_GENERATE_AUTH_DATA; - AuthenticationInfoRequest = - ogs_calloc(1, sizeof(*AuthenticationInfoRequest)); - ogs_assert(AuthenticationInfoRequest); + memset(&AuthenticationInfoRequest, 0, sizeof(AuthenticationInfoRequest)); - AuthenticationInfoRequest->serving_network_name = + AuthenticationInfoRequest.serving_network_name = ausf_ue->serving_network_name; - AuthenticationInfoRequest->ausf_instance_id = + AuthenticationInfoRequest.ausf_instance_id = ogs_sbi_self()->nf_instance_id; - message.AuthenticationInfoRequest = AuthenticationInfoRequest; + if (data) { + OpenAPI_resynchronization_info_t *recvinfo = data; + + memset(&ResynchronizationInfo, 0, sizeof(ResynchronizationInfo)); + ResynchronizationInfo.rand = recvinfo->rand; + ResynchronizationInfo.auts = recvinfo->auts; + + AuthenticationInfoRequest.resynchronization_info = + &ResynchronizationInfo; + } + + message.AuthenticationInfoRequest = &AuthenticationInfoRequest; request = ogs_sbi_build_request(&message); ogs_assert(request); - ogs_free(AuthenticationInfoRequest); - return request; } diff --git a/src/ausf/sbi-path.c b/src/ausf/sbi-path.c index a4e96c773..0b2369b4e 100644 --- a/src/ausf/sbi-path.c +++ b/src/ausf/sbi-path.c @@ -125,6 +125,11 @@ void ausf_sbi_discover_and_send( ogs_assert(nf_type); ogs_assert(build); + if (ausf_ue->sbi.running == true) { + ogs_error("ausf_sbi_discover_and_send() is running"); + return; + } + ausf_ue->sbi.nf_state_registered = ausf_nf_state_registered; ausf_ue->sbi.client_wait.duration = ausf_timer_cfg(AUSF_TIMER_SBI_CLIENT_WAIT)->duration; diff --git a/src/ausf/ue-sm.c b/src/ausf/ue-sm.c index a1c43e27c..2b77b7f13 100644 --- a/src/ausf/ue-sm.c +++ b/src/ausf/ue-sm.c @@ -125,8 +125,13 @@ void ausf_ue_state_operational(ogs_fsm_t *s, ausf_event_t *e) if (message->res_status != OGS_SBI_HTTP_STATUS_OK && message->res_status != OGS_SBI_HTTP_STATUS_CREATED) { - ogs_error("[%s] HTTP response error [%d]", - ausf_ue->suci, message->res_status); + if (message->res_status == OGS_SBI_HTTP_STATUS_NOT_FOUND) { + ogs_warn("[%s] Cannot find SUPI [%d]", + ausf_ue->suci, message->res_status); + } else { + ogs_error("[%s] HTTP response error [%d]", + ausf_ue->suci, message->res_status); + } ogs_sbi_server_send_error( session, message->res_status, NULL, "HTTP response error", ausf_ue->suci); diff --git a/src/hss/hss-auc.c b/src/hss/hss-auc.c index 7bc1a6bde..28433c432 100644 --- a/src/hss/hss-auc.c +++ b/src/hss/hss-auc.c @@ -47,19 +47,3 @@ void hss_auc_kasme(const uint8_t *ck, const uint8_t *ik, ogs_hmac_sha256(k, 32, s, 14, kasme, 32); } - -void hss_auc_sqn( - const uint8_t *opc, const uint8_t *k, const uint8_t *auts, - uint8_t *sqn_ms, uint8_t *mac_s) -{ - int i; - uint8_t ak[OGS_AK_LEN]; - uint8_t amf[2] = { 0, 0 }; - const uint8_t *rand = auts; - const uint8_t *conc_sqn_ms = auts + OGS_RAND_LEN; - - milenage_f2345(opc, k, rand, NULL, NULL, NULL, NULL, ak); - for (i = 0; i < OGS_SQN_LEN; i++) - sqn_ms[i] = ak[i] ^ conc_sqn_ms[i]; - milenage_f1(opc, k, auts, sqn_ms, amf, NULL, mac_s); -} diff --git a/src/hss/hss-auc.h b/src/hss/hss-auc.h index 4ca30efc4..10a344b4f 100644 --- a/src/hss/hss-auc.h +++ b/src/hss/hss-auc.h @@ -30,10 +30,6 @@ void hss_auc_kasme(const uint8_t *ck, const uint8_t *ik, const uint8_t plmn_id[3], const uint8_t *sqn, const uint8_t *ak, uint8_t *kasme); -void hss_auc_sqn( - const uint8_t *opc, const uint8_t *k, const uint8_t *auts, - uint8_t *sqn_ms, uint8_t *mac_s); - #ifdef __cplusplus } #endif diff --git a/src/hss/hss-fd-path.c b/src/hss/hss-fd-path.c index 0ced98dc5..15609f175 100644 --- a/src/hss/hss-fd-path.c +++ b/src/hss/hss-fd-path.c @@ -63,8 +63,7 @@ static int hss_ogs_diam_s6a_air_cb( struct msg **msg, struct avp *avp, uint8_t kasme[OGS_SHA256_DIGEST_SIZE]; size_t xres_len = 8; -#define MAC_S_LEN 8 - uint8_t mac_s[MAC_S_LEN]; + uint8_t mac_s[OGS_MAC_S_LEN]; ogs_dbi_auth_info_t auth_info; uint8_t zero[OGS_RAND_LEN]; @@ -113,9 +112,12 @@ static int hss_ogs_diam_s6a_air_cb( struct msg **msg, struct avp *avp, if (avpch) { ret = fd_msg_avp_hdr(avpch, &hdr); ogs_assert(ret == 0); - hss_auc_sqn(opc, auth_info.k, hdr->avp_value->os.data, sqn, mac_s); + ogs_auc_sqn(opc, auth_info.k, + hdr->avp_value->os.data, + hdr->avp_value->os.data + OGS_RAND_LEN, + sqn, mac_s); if (memcmp(mac_s, hdr->avp_value->os.data + - OGS_RAND_LEN + OGS_SQN_LEN, MAC_S_LEN) == 0) { + OGS_RAND_LEN + OGS_SQN_LEN, OGS_MAC_S_LEN) == 0) { ogs_random(auth_info.rand, OGS_RAND_LEN); auth_info.sqn = ogs_buffer_to_uint64(sqn, OGS_SQN_LEN); /* 33.102 C.3.4 Guide : IND + 1 */ @@ -123,11 +125,11 @@ static int hss_ogs_diam_s6a_air_cb( struct msg **msg, struct avp *avp, } else { ogs_error("Re-synch MAC failed for IMSI:`%s`", imsi_bcd); ogs_log_print(OGS_LOG_ERROR, "MAC_S: "); - ogs_log_hexdump(OGS_LOG_ERROR, mac_s, MAC_S_LEN); + ogs_log_hexdump(OGS_LOG_ERROR, mac_s, OGS_MAC_S_LEN); ogs_log_hexdump(OGS_LOG_ERROR, (void*)(hdr->avp_value->os.data + OGS_RAND_LEN + OGS_SQN_LEN), - MAC_S_LEN); + OGS_MAC_S_LEN); ogs_log_print(OGS_LOG_ERROR, "SQN: "); ogs_log_hexdump(OGS_LOG_ERROR, sqn, OGS_SQN_LEN); result_code = OGS_DIAM_S6A_AUTHENTICATION_DATA_UNAVAILABLE; diff --git a/src/mme/mme-context.c b/src/mme/mme-context.c index f51b1983f..5559526f1 100644 --- a/src/mme/mme-context.c +++ b/src/mme/mme-context.c @@ -1942,8 +1942,8 @@ mme_enb_t *mme_enb_add(ogs_sock_t *sock, ogs_sockaddr_t *addr) ogs_hash_set(self.enb_addr_hash, enb->addr, sizeof(ogs_sockaddr_t), enb); + memset(&e, 0, sizeof(e)); e.enb = enb; - e.id = 0; ogs_fsm_create(&enb->sm, s1ap_state_initial, s1ap_state_final); ogs_fsm_init(&enb->sm, &e); @@ -1963,6 +1963,7 @@ int mme_enb_remove(mme_enb_t *enb) ogs_list_remove(&self.enb_list, enb); + memset(&e, 0, sizeof(e)); e.enb = enb; ogs_fsm_fini(&enb->sm, &e); ogs_fsm_delete(&enb->sm); @@ -2395,8 +2396,8 @@ mme_ue_t *mme_ue_add(enb_ue_t *enb_ue) mme_ue->t3470.pkbuf = NULL; /* Create FSM */ + memset(&e, 0, sizeof(e)); e.mme_ue = mme_ue; - e.id = 0; ogs_fsm_create(&mme_ue->sm, emm_state_initial, emm_state_final); ogs_fsm_init(&mme_ue->sm, &e); @@ -2413,6 +2414,7 @@ void mme_ue_remove(mme_ue_t *mme_ue) ogs_list_remove(&self.mme_ue_list, mme_ue); + memset(&e, 0, sizeof(e)); e.mme_ue = mme_ue; ogs_fsm_fini(&mme_ue->sm, &e); ogs_fsm_delete(&mme_ue->sm); @@ -2910,8 +2912,8 @@ mme_bearer_t *mme_bearer_add(mme_sess_t *sess) self.timer_mgr, mme_timer_t3489_expire, bearer); bearer->t3489.pkbuf = NULL; + memset(&e, 0, sizeof(e)); e.bearer = bearer; - e.id = 0; ogs_fsm_create(&bearer->sm, esm_state_initial, esm_state_final); ogs_fsm_init(&bearer->sm, &e); @@ -2925,6 +2927,7 @@ void mme_bearer_remove(mme_bearer_t *bearer) ogs_assert(bearer); ogs_assert(bearer->sess); + memset(&e, 0, sizeof(e)); e.bearer = bearer; ogs_fsm_fini(&bearer->sm, &e); ogs_fsm_delete(&bearer->sm); diff --git a/src/mme/mme-context.h b/src/mme/mme-context.h index dc7999faa..635b53373 100644 --- a/src/mme/mme-context.h +++ b/src/mme/mme-context.h @@ -536,9 +536,6 @@ typedef struct mme_sess_s { /* Related Context */ mme_ue_t *mme_ue; -#define MME_UE_HAVE_APN(__mME) \ - ((__mME) && (mme_sess_first(__mME)) && \ - ((mme_sess_first(__mME))->pdn)) ogs_pdn_t *pdn; /* Save Protocol Configuration Options from UE */ diff --git a/src/mme/sgsap-path.c b/src/mme/sgsap-path.c index c0fbe2e97..d67c36a26 100644 --- a/src/mme/sgsap-path.c +++ b/src/mme/sgsap-path.c @@ -33,8 +33,8 @@ int sgsap_open() ogs_list_for_each(&mme_self()->vlr_list, vlr) { mme_event_t e; + memset(&e, 0, sizeof(e)); e.vlr = vlr; - e.id = 0; ogs_fsm_create(&vlr->sm, sgsap_state_initial, sgsap_state_final); ogs_fsm_init(&vlr->sm, &e); @@ -49,6 +49,7 @@ void sgsap_close() ogs_list_for_each(&mme_self()->vlr_list, vlr) { mme_event_t e; + memset(&e, 0, sizeof(e)); e.vlr = vlr; ogs_fsm_fini(&vlr->sm, &e); diff --git a/src/nrf/nf-sm.c b/src/nrf/nf-sm.c index 649334dcd..1b7b805d7 100644 --- a/src/nrf/nf-sm.c +++ b/src/nrf/nf-sm.c @@ -27,6 +27,7 @@ void nrf_nf_fsm_init(ogs_sbi_nf_instance_t *nf_instance) nrf_event_t e; ogs_assert(nf_instance); + memset(&e, 0, sizeof(e)); e.nf_instance = nf_instance; ogs_fsm_create(&nf_instance->sm, @@ -39,6 +40,7 @@ void nrf_nf_fsm_fini(ogs_sbi_nf_instance_t *nf_instance) nrf_event_t e; ogs_assert(nf_instance); + memset(&e, 0, sizeof(e)); e.nf_instance = nf_instance; ogs_fsm_fini(&nf_instance->sm, &e); diff --git a/src/smf/bearer-binding.c b/src/smf/bearer-binding.c index 46afd49ec..8986866a0 100644 --- a/src/smf/bearer-binding.c +++ b/src/smf/bearer-binding.c @@ -278,8 +278,9 @@ void smf_bearer_binding(smf_sess_t *sess) memset(&h, 0, sizeof(ogs_gtp_header_t)); if (bearer_created == 1) { - memset(&bearer->state, 0, sizeof(bearer->state)); - bearer->state.created = true; + memset(&bearer->pfcp_epc_modify, + 0, sizeof(bearer->pfcp_epc_modify)); + bearer->pfcp_epc_modify.create = true; h.type = OGS_GTP_CREATE_BEARER_REQUEST_TYPE; h.teid = sess->sgw_s5c_teid; @@ -292,11 +293,12 @@ void smf_bearer_binding(smf_sess_t *sess) h.type, bearer, pcc_rule->num_of_flow ? &tft : NULL); ogs_expect_or_return(pkbuf); } else { - memset(&bearer->state, 0, sizeof(bearer->state)); + memset(&bearer->pfcp_epc_modify, + 0, sizeof(bearer->pfcp_epc_modify)); if (pcc_rule->num_of_flow) - bearer->state.tft_updated = true; + bearer->pfcp_epc_modify.tft_update = true; if (qos_presence) - bearer->state.qos_updated = true; + bearer->pfcp_epc_modify.qos_update = true; h.type = OGS_GTP_UPDATE_BEARER_REQUEST_TYPE; h.teid = sess->sgw_s5c_teid; @@ -325,8 +327,9 @@ void smf_bearer_binding(smf_sess_t *sess) return; } - memset(&bearer->state, 0, sizeof(bearer->state)); - bearer->state.removed = true; + memset(&bearer->pfcp_epc_modify, 0, + sizeof(bearer->pfcp_epc_modify)); + bearer->pfcp_epc_modify.remove = true; memset(&h, 0, sizeof(ogs_gtp_header_t)); h.type = OGS_GTP_DELETE_BEARER_REQUEST_TYPE; diff --git a/src/smf/context.c b/src/smf/context.c index 43d3d9184..98b734f34 100644 --- a/src/smf/context.c +++ b/src/smf/context.c @@ -568,7 +568,7 @@ void smf_ue_remove(smf_ue_t *smf_ue) ogs_free(smf_ue->supi); } - if (smf_ue->imsi && smf_ue->imsi_len) { + if (smf_ue->imsi_len) { ogs_hash_set(self.imsi_hash, smf_ue->imsi, smf_ue->imsi_len, NULL); } @@ -1027,6 +1027,7 @@ smf_sess_t *smf_sess_add_by_apn(smf_ue_t *smf_ue, char *apn, sess->sbi.client_wait.timer = ogs_timer_add( self.timer_mgr, smf_timer_sbi_client_wait_expire, sess); + memset(&e, 0, sizeof(e)); e.sess = sess; ogs_fsm_create(&sess->sm, smf_gsm_state_initial, smf_gsm_state_final); ogs_fsm_init(&sess->sm, &e); @@ -1111,7 +1112,7 @@ smf_sess_t *smf_sess_add_by_gtp_message(ogs_gtp_message_t *message) if (sess) { ogs_warn("OLD Session Release [IMSI:%s,APN:%s]", smf_ue->imsi_bcd, sess->pdn.apn); - SMF_SESS_CLEAR(sess); + smf_sess_remove(sess); } sess = smf_sess_add_by_apn(smf_ue, apn, req->pdn_type.u8, @@ -1237,6 +1238,7 @@ smf_sess_t *smf_sess_add_by_psi(smf_ue_t *smf_ue, uint8_t psi) sess->sbi.client_wait.timer = ogs_timer_add( self.timer_mgr, smf_timer_sbi_client_wait_expire, sess); + memset(&e, 0, sizeof(e)); e.sess = sess; ogs_fsm_create(&sess->sm, smf_gsm_state_initial, smf_gsm_state_final); ogs_fsm_init(&sess->sm, &e); @@ -1280,7 +1282,7 @@ smf_sess_t *smf_sess_add_by_sbi_message(ogs_sbi_message_t *message) if (sess) { ogs_warn("OLD Session Release [SUPI:%s,PDU Session identity:%d]", SmContextCreateData->supi, SmContextCreateData->pdu_session_id); - SMF_SESS_CLEAR(sess); + smf_sess_remove(sess); } sess = smf_sess_add_by_psi(smf_ue, SmContextCreateData->pdu_session_id); @@ -1300,6 +1302,7 @@ void smf_sess_remove(smf_sess_t *sess) ogs_list_remove(&smf_ue->sess_list, sess); + memset(&e, 0, sizeof(e)); e.sess = sess; ogs_fsm_fini(&sess->sm, &e); ogs_fsm_delete(&sess->sm); diff --git a/src/smf/context.h b/src/smf/context.h index c33e03138..ddd6c5929 100644 --- a/src/smf/context.h +++ b/src/smf/context.h @@ -164,9 +164,7 @@ typedef struct smf_sess_s { char *sm_context_ref; /* smContextRef */ uint8_t psi; /* PDU session identity */ - - /* Procedure transaction identity */ - uint8_t pti; + uint8_t pti; /* Procedure transaction identity */ /* PLMN ID & NID */ ogs_plmn_id_t plmn_id; @@ -197,13 +195,24 @@ typedef struct smf_sess_s { ogs_pcc_rule_t pcc_rule[OGS_MAX_NUM_OF_PCC_RULE]; /* Saved from Gx */ int num_of_pcc_rule; + struct { + bool create; + bool tft_update; + bool qos_update; + bool outer_header_creation_update; + bool remove; + } pfcp_5gc_modify; + + /* UE session context is activated or not */ + OpenAPI_up_cnx_state_e ueUpCnxState; + /* SMF session context is activated or not */ + OpenAPI_up_cnx_state_e smfUpCnxState; + ogs_list_t bearer_list; - /* Related Context */ ogs_gtp_node_t *gnode; ogs_pfcp_node_t *pfcp_node; - /* Related Context */ smf_ue_t *smf_ue; } smf_sess_t; @@ -228,7 +237,7 @@ typedef struct smf_bearer_s { ogs_sockaddr_t *upf_addr6; /* UPF_N3 IPv6 */ uint32_t gnb_n3_teid; /* gNB_N3 TEID */ - ogs_ip_t gnb_ip; /* gNB_N3 IP */ + ogs_ip_t gnb_n3_ip; /* gNB_N3 IP */ char *name; /* PCC Rule Name */ ogs_qos_t qos; /* QoS Infomration */ @@ -239,12 +248,11 @@ typedef struct smf_bearer_s { ogs_list_t pf_list; struct { - bool created; - bool tft_updated; - bool qos_updated; - bool removed; - bool outer_header_creation_updated; - } state; + bool create; + bool tft_update; + bool qos_update; + bool remove; + } pfcp_epc_modify; smf_sess_t *sess; } smf_bearer_t; diff --git a/src/smf/gx-handler.c b/src/smf/gx-handler.c index 0c5100e67..40a24dd42 100644 --- a/src/smf/gx-handler.c +++ b/src/smf/gx-handler.c @@ -103,7 +103,7 @@ void smf_gx_handle_cca_termination_request( ogs_debug(" SGW_S5C_TEID[0x%x] SMF_N4_TEID[0x%x]", sess->sgw_s5c_teid, sess->smf_n4_teid); - smf_pfcp_send_session_deletion_request(sess, gtp_xact); + smf_epc_pfcp_send_session_deletion_request(sess, gtp_xact); } void smf_gx_handle_re_auth_request( diff --git a/src/smf/n4-build.c b/src/smf/n4-build.c index 427013c41..66433711b 100644 --- a/src/smf/n4-build.c +++ b/src/smf/n4-build.c @@ -249,8 +249,8 @@ static void build_create_far( far->dst_if; if (far->dst_if == OGS_PFCP_INTERFACE_ACCESS) { /* Downlink */ - if (bearer->gnb_ip.ipv4 || bearer->gnb_ip.ipv6) { - ogs_pfcp_ip_to_outer_header_creation(&bearer->gnb_ip, + if (bearer->gnb_n3_ip.ipv4 || bearer->gnb_n3_ip.ipv6) { + ogs_pfcp_ip_to_outer_header_creation(&bearer->gnb_n3_ip, &farbuf[i].outer_header_creation, &len); farbuf[i].outer_header_creation.teid = htobe32(bearer->gnb_n3_teid); @@ -330,8 +330,8 @@ static void build_update_qer( } } -static void build_update_outer_header_creation( - ogs_pfcp_tlv_update_far_t *message, int i, ogs_pfcp_far_t *far) +static void build_update_far(smf_sess_t *sess, + ogs_pfcp_tlv_update_far_t *message, int i, ogs_pfcp_far_t *far) { ogs_pfcp_sess_t *pfcp_sess = NULL; smf_bearer_t *bearer = NULL; @@ -343,24 +343,46 @@ static void build_update_outer_header_creation( ogs_assert(pfcp_sess); bearer = SMF_BEARER(pfcp_sess); ogs_assert(bearer); + ogs_assert(sess); ogs_assert(far->dst_if == OGS_PFCP_INTERFACE_ACCESS); - ogs_assert(bearer->gnb_ip.ipv4 || bearer->gnb_ip.ipv6); + ogs_assert(bearer->gnb_n3_ip.ipv4 || bearer->gnb_n3_ip.ipv6); message->presence = 1; message->far_id.presence = 1; message->far_id.u32 = far->id; - ogs_pfcp_ip_to_outer_header_creation(&bearer->gnb_ip, - &farbuf[i].outer_header_creation, &len); - farbuf[i].outer_header_creation.teid = - htobe32(bearer->gnb_n3_teid); + if (sess->ueUpCnxState == OpenAPI_up_cnx_state_ACTIVATED) { + if (sess->pfcp_5gc_modify.outer_header_creation_update) { + ogs_pfcp_ip_to_outer_header_creation(&bearer->gnb_n3_ip, + &farbuf[i].outer_header_creation, &len); + farbuf[i].outer_header_creation.teid = + htobe32(bearer->gnb_n3_teid); - message->update_forwarding_parameters.presence = 1; - message->update_forwarding_parameters.outer_header_creation.presence = 1; - message->update_forwarding_parameters.outer_header_creation.data = - &farbuf[i].outer_header_creation; - message->update_forwarding_parameters.outer_header_creation.len = len; + message->update_forwarding_parameters.presence = 1; + message->update_forwarding_parameters. + outer_header_creation.presence = 1; + message->update_forwarding_parameters. + outer_header_creation.data = &farbuf[i].outer_header_creation; + message->update_forwarding_parameters. + outer_header_creation.len = len; + } + + if (far->apply_action != OGS_PFCP_APPLY_ACTION_FORW) { + message->apply_action.presence = 1; + far->apply_action = OGS_PFCP_APPLY_ACTION_FORW; + } + } else if (sess->ueUpCnxState == OpenAPI_up_cnx_state_DEACTIVATED) { + message->apply_action.presence = 1; + far->apply_action = + OGS_PFCP_APPLY_ACTION_BUFF | OGS_PFCP_APPLY_ACTION_NOCP; + } else { + ogs_error("Invalid UpCnxState [%d:%d]", + sess->ueUpCnxState, sess->smfUpCnxState); + } + + if (message->apply_action.presence) + message->apply_action.u8 = far->apply_action; } ogs_pkbuf_t *smf_n4_build_session_establishment_request( @@ -456,7 +478,132 @@ ogs_pkbuf_t *smf_n4_build_session_establishment_request( return pkbuf; } -ogs_pkbuf_t *smf_n4_build_session_modification_request( +ogs_pkbuf_t *smf_5gc_n4_build_session_modification_request( + uint8_t type, smf_sess_t *sess) +{ + int i; + + ogs_pfcp_message_t pfcp_message; + ogs_pfcp_session_modification_request_t *req = NULL; + ogs_pfcp_pdr_t *pdr = NULL; + ogs_pfcp_far_t *far = NULL; + ogs_pfcp_qer_t *qer = NULL; + ogs_pkbuf_t *pkbuf = NULL; + smf_bearer_t *bearer = NULL; + + ogs_debug("Session Modification Request"); + ogs_assert(sess); + + req = &pfcp_message.pfcp_session_modification_request; + memset(&pfcp_message, 0, sizeof(ogs_pfcp_message_t)); + + if (!sess->pfcp_5gc_modify.create && + !sess->pfcp_5gc_modify.tft_update && + !sess->pfcp_5gc_modify.qos_update && + !sess->pfcp_5gc_modify.outer_header_creation_update && + !sess->pfcp_5gc_modify.remove && + sess->ueUpCnxState == sess->smfUpCnxState) { + ogs_error("No Session Modification [upCnxState:%d-%d]", + sess->ueUpCnxState,sess->smfUpCnxState); + return NULL; + } + + if (sess->pfcp_5gc_modify.remove) { + ogs_list_for_each(&sess->bearer_list, bearer) { + /* Remove PDR */ + i = 0; + ogs_list_for_each(&bearer->pfcp.pdr_list, pdr) { + ogs_pfcp_tlv_remove_pdr_t *message = &req->remove_pdr[i]; + + message->presence = 1; + message->pdr_id.presence = 1; + message->pdr_id.u16 = pdr->id; + i++; + } + + /* Remove FAR */ + i = 0; + ogs_list_for_each(&bearer->pfcp.far_list, far) { + ogs_pfcp_tlv_remove_far_t *message = &req->remove_far[i]; + + message->presence = 1; + message->far_id.presence = 1; + message->far_id.u32 = far->id; + i++; + } + + /* Remove QER */ + i = 0; + ogs_list_for_each(&bearer->pfcp.qer_list, qer) { + ogs_pfcp_tlv_remove_qer_t *message = &req->remove_qer[i]; + + message->presence = 1; + message->qer_id.presence = 1; + message->qer_id.u32 = qer->id; + i++; + } + } + } else { + if (sess->pfcp_5gc_modify.create) { + pdrbuf_init(); + + ogs_list_for_each(&sess->bearer_list, bearer) { + /* Create PDR */ + i = 0; + ogs_list_for_each(&bearer->pfcp.pdr_list, pdr) { + build_create_pdr(&req->create_pdr[i], i, pdr); + i++; + } + + /* Create FAR */ + i = 0; + ogs_list_for_each(&bearer->pfcp.far_list, far) { + build_create_far(&req->create_far[i], i, far); + i++; + } + + /* Create QER */ + i = 0; + ogs_list_for_each(&bearer->pfcp.qer_list, qer) { + build_create_qer(&req->create_qer[i], i, qer); + i++; + } + } + } + if (sess->pfcp_5gc_modify.qos_update) { + /* Update QER */ + i = 0; + ogs_list_for_each(&sess->bearer_list, bearer) { + ogs_list_for_each(&bearer->pfcp.qer_list, qer) { + build_update_qer(&req->update_qer[i], i, qer); + i++; + } + } + } + if (sess->ueUpCnxState != sess->smfUpCnxState) { + i = 0; + ogs_list_for_each(&sess->bearer_list, bearer) { + ogs_list_for_each(&bearer->pfcp.far_list, far) { + if (far->dst_if == OGS_PFCP_INTERFACE_ACCESS) { + build_update_far(sess, &req->update_far[i], i, far); + i++; + } + } + } + } + } + + pfcp_message.h.type = type; + pkbuf = ogs_pfcp_build_msg(&pfcp_message); + + if (sess->pfcp_5gc_modify.create) { + pdrbuf_clear(); + } + + return pkbuf; +} + +ogs_pkbuf_t *smf_epc_n4_build_session_modification_request( uint8_t type, smf_bearer_t *bearer) { ogs_pfcp_message_t pfcp_message; @@ -477,16 +624,15 @@ ogs_pkbuf_t *smf_n4_build_session_modification_request( req = &pfcp_message.pfcp_session_modification_request; memset(&pfcp_message, 0, sizeof(ogs_pfcp_message_t)); - if (!bearer->state.created && - !bearer->state.tft_updated && - !bearer->state.qos_updated && - !bearer->state.outer_header_creation_updated && - !bearer->state.removed) { + if (!bearer->pfcp_epc_modify.create && + !bearer->pfcp_epc_modify.tft_update && + !bearer->pfcp_epc_modify.qos_update && + !bearer->pfcp_epc_modify.remove) { ogs_error("No Session Modification"); return NULL; } - if (bearer->state.removed) { + if (bearer->pfcp_epc_modify.remove) { /* Remove PDR */ i = 0; ogs_list_for_each(&bearer->pfcp.pdr_list, pdr) { @@ -520,7 +666,7 @@ ogs_pkbuf_t *smf_n4_build_session_modification_request( i++; } } else { - if (bearer->state.created) { + if (bearer->pfcp_epc_modify.create) { pdrbuf_init(); /* Create PDR */ @@ -544,7 +690,7 @@ ogs_pkbuf_t *smf_n4_build_session_modification_request( i++; } } - if (bearer->state.qos_updated) { + if (bearer->pfcp_epc_modify.qos_update) { /* Update QER */ i = 0; ogs_list_for_each(&bearer->pfcp.qer_list, qer) { @@ -552,21 +698,12 @@ ogs_pkbuf_t *smf_n4_build_session_modification_request( i++; } } - if (bearer->state.outer_header_creation_updated) { - i = 0; - ogs_list_for_each(&bearer->pfcp.far_list, far) { - if (far->dst_if == OGS_PFCP_INTERFACE_ACCESS) - build_update_outer_header_creation( - &req->update_far[i], i, far); - i++; - } - } } pfcp_message.h.type = type; pkbuf = ogs_pfcp_build_msg(&pfcp_message); - if (bearer->state.created) { + if (bearer->pfcp_epc_modify.create) { pdrbuf_clear(); } diff --git a/src/smf/n4-build.h b/src/smf/n4-build.h index 7c5cf5325..9e64b0167 100644 --- a/src/smf/n4-build.h +++ b/src/smf/n4-build.h @@ -32,7 +32,9 @@ ogs_pkbuf_t *smf_n4_build_association_setup_response(uint8_t type, ogs_pkbuf_t *smf_n4_build_session_establishment_request( uint8_t type, smf_sess_t *sess); -ogs_pkbuf_t *smf_n4_build_session_modification_request( +ogs_pkbuf_t *smf_5gc_n4_build_session_modification_request( + uint8_t type, smf_sess_t *sess); +ogs_pkbuf_t *smf_epc_n4_build_session_modification_request( uint8_t type, smf_bearer_t *bearer); ogs_pkbuf_t *smf_n4_build_session_deletion_request( uint8_t type, smf_sess_t *sess); diff --git a/src/smf/n4-handler.c b/src/smf/n4-handler.c index 2788e1103..3e4c68cbd 100644 --- a/src/smf/n4-handler.c +++ b/src/smf/n4-handler.c @@ -170,6 +170,10 @@ void smf_5gc_n4_handle_session_establishment_response( ogs_assert(up_f_seid); sess->upf_n4_seid = be64toh(up_f_seid->seid); + /* UPDATE_UpCnxState - ACTIVATING */ + sess->ueUpCnxState = OpenAPI_up_cnx_state_ACTIVATING; + sess->smfUpCnxState = OpenAPI_up_cnx_state_ACTIVATING; + smf_sbi_discover_and_send(OpenAPI_nf_type_AMF, sess, NULL, smf_namf_comm_build_n1_n2_message_transfer); @@ -185,9 +189,6 @@ void smf_5gc_n4_handle_session_modification_response( ogs_sbi_session_t *session = NULL; smf_bearer_t *bearer = NULL; - ogs_sbi_message_t sendmsg; - ogs_sbi_response_t *response = NULL; - ogs_assert(sess); session = sess->sbi.session; ogs_assert(session); @@ -201,32 +202,70 @@ void smf_5gc_n4_handle_session_modification_response( if (rsp->cause.presence) { if (rsp->cause.u8 != OGS_PFCP_CAUSE_REQUEST_ACCEPTED) { - ogs_error("Cause[%d] : No Accepted", rsp->cause.u8); + char *strerror = ogs_msprintf( + "PFCP Cause[%d] : No Accepted", rsp->cause.u8); + ogs_error("%s", strerror); smf_sbi_send_sm_context_update_error(session, - OGS_SBI_HTTP_STATUS_INTERNAL_SERVER_ERROR, - "[PFCP] No Accepted", NULL, NULL); + OGS_SBI_HTTP_STATUS_BAD_REQUEST, strerror, NULL, NULL); + ogs_free(strerror); return; } } else { ogs_error("No Cause"); smf_sbi_send_sm_context_update_error(session, - OGS_SBI_HTTP_STATUS_INTERNAL_SERVER_ERROR, + OGS_SBI_HTTP_STATUS_BAD_REQUEST, "[PFCP] No Cause", NULL, NULL); return; } - memset(&sendmsg, 0, sizeof(sendmsg)); + /* UPDATE_UpCnxState - SYNC */ + sess->smfUpCnxState = sess->ueUpCnxState; - response = ogs_sbi_build_response(&sendmsg, OGS_SBI_HTTP_STATUS_NO_CONTENT); - ogs_assert(response); - ogs_sbi_server_send_response(session, response); + smf_sbi_send_sm_context_updated_data(sess); } void smf_5gc_n4_handle_session_deletion_response( smf_sess_t *sess, ogs_pfcp_xact_t *xact, ogs_pfcp_session_deletion_response_t *rsp) { - ogs_fatal("TODO"); + ogs_sbi_session_t *session = NULL; + + ogs_sbi_message_t sendmsg; + ogs_sbi_response_t *response = NULL; + + ogs_assert(sess); + session = sess->sbi.session; + ogs_assert(session); + ogs_assert(rsp); + + ogs_pfcp_xact_commit(xact); + + if (rsp->cause.presence) { + if (rsp->cause.u8 != OGS_PFCP_CAUSE_REQUEST_ACCEPTED) { + char *strerror = ogs_msprintf( + "PFCP Cause[%d] : No Accepted", rsp->cause.u8); + ogs_error("%s", strerror); + ogs_sbi_server_send_error(session, + OGS_SBI_HTTP_STATUS_BAD_REQUEST, NULL, strerror, NULL); + ogs_free(strerror); + return; + } + } else { + ogs_error("No Cause"); + ogs_sbi_server_send_error(session, + OGS_SBI_HTTP_STATUS_BAD_REQUEST, NULL, + "[PFCP] No Cause", NULL); + return; + } + + memset(&sendmsg, 0, sizeof(sendmsg)); + + response = ogs_sbi_build_response( + &sendmsg, OGS_SBI_HTTP_STATUS_NO_CONTENT); + ogs_assert(response); + ogs_sbi_server_send_response(session, response); + + SMF_SESS_CLEAR(sess); } void smf_epc_n4_handle_session_establishment_response( @@ -299,7 +338,7 @@ void smf_epc_n4_handle_session_modification_response( ogs_pfcp_xact_commit(xact); - if (bearer->state.removed) + if (bearer->pfcp_epc_modify.remove) smf_bearer_remove(bearer); } diff --git a/src/smf/nas-path.c b/src/smf/nas-path.c index 6fd10d46b..515814cd7 100644 --- a/src/smf/nas-path.c +++ b/src/smf/nas-path.c @@ -43,322 +43,3 @@ void nas_5gs_send_to_gsm(smf_sess_t *sess, ogs_pkbuf_t *pkbuf) smf_event_free(e); } } - -#if 0 -void nas_5gs_send_detach_accept(amf_ue_t *amf_ue) -{ - ran_ue_t *ran_ue = NULL; - ogs_pkbuf_t *gmmbuf = NULL; - - ogs_assert(amf_ue); - ran_ue = amf_ue->ran_ue; - ogs_assert(ran_ue); - - /* reply with detach accept */ - if (amf_ue->nas_5gs.detach.switch_off == 0) { - int rv; - gmmbuf = gmm_build_detach_accept(amf_ue); - ogs_expect_or_return(gmmbuf); - - rv = nas_5gs_send_to_downlink_nas_transport(amf_ue, gmmbuf); - ogs_expect_or_return(rv == OGS_OK); - } - - ngap_send_ue_context_release_command(ran_ue, - NGAP_Cause_PR_nas, NGAP_CauseNas_detach, - NGAP_UE_CTX_REL_NG_REMOVE_AND_UNLINK, 0); -} - - -void nas_5gs_send_pdn_connectivity_reject( - amf_sess_t *sess, ogs_nas_gsm_cause_t gsm_cause) -{ - int rv; - amf_ue_t *amf_ue; - ogs_pkbuf_t *gsmbuf = NULL; - - ogs_assert(sess); - amf_ue = sess->amf_ue; - ogs_assert(amf_ue); - - if (OGS_FSM_CHECK(&amf_ue->sm, gmm_state_registered)) { - gsmbuf = esm_build_pdn_connectivity_reject(sess, gsm_cause); - ogs_expect_or_return(gsmbuf); - - rv = nas_5gs_send_to_downlink_nas_transport(amf_ue, gsmbuf); - ogs_expect(rv == OGS_OK); - } else { - /* During the UE-registration process, we'll send Registration-Reject - * with pyggybacking PDN-connectivity-Reject */ - nas_5gs_send_registration_reject(amf_ue, - EMM_CAUSE_EPS_SERVICES_AND_NON_EPS_SERVICES_NOT_ALLOWED, gsm_cause); - } -} - -void nas_5gs_send_esm_information_request(amf_bearer_t *bearer) -{ - int rv; - amf_ue_t *amf_ue = NULL; - ogs_pkbuf_t *gsmbuf = NULL; - - ogs_assert(bearer); - amf_ue = bearer->amf_ue; - ogs_assert(amf_ue); - - if (bearer->t3589.pkbuf) { - gsmbuf = bearer->t3589.pkbuf; - ogs_expect_or_return(gsmbuf); - } else { - gsmbuf = esm_build_information_request(bearer); - ogs_expect_or_return(gsmbuf); - } - - bearer->t3589.pkbuf = ogs_pkbuf_copy(gsmbuf); - ogs_timer_start(bearer->t3589.timer, - amf_timer_cfg(AMF_TIMER_T3589)->duration); - - rv = nas_5gs_send_to_downlink_nas_transport(amf_ue, gsmbuf); - ogs_expect(rv == OGS_OK); -} - -void nas_5gs_send_activate_default_bearer_context_request(amf_bearer_t *bearer) -{ - int rv; - ogs_pkbuf_t *ngapbuf = NULL; - ogs_pkbuf_t *gsmbuf = NULL; - amf_sess_t *sess = NULL; - amf_ue_t *amf_ue = NULL; - - ogs_assert(bearer); - sess = bearer->sess; - ogs_assert(sess); - amf_ue = bearer->amf_ue; - ogs_assert(amf_ue); - - gsmbuf = esm_build_activate_default_bearer_context_request(sess); - ogs_expect_or_return(gsmbuf); - - ngapbuf = ngap_build_e_rab_setup_request(bearer, gsmbuf); - ogs_expect_or_return(ngapbuf); - - rv = nas_5gs_send_to_gnb(amf_ue, ngapbuf); - ogs_expect(rv == OGS_OK); -} - -void nas_5gs_send_activate_dedicated_bearer_context_request( - amf_bearer_t *bearer) -{ - int rv; - ogs_pkbuf_t *ngapbuf = NULL; - ogs_pkbuf_t *gsmbuf = NULL; - amf_ue_t *amf_ue = NULL; - - ogs_assert(bearer); - amf_ue = bearer->amf_ue; - ogs_assert(amf_ue); - - gsmbuf = esm_build_activate_dedicated_bearer_context_request(bearer); - ogs_expect_or_return(gsmbuf); - - ngapbuf = ngap_build_e_rab_setup_request(bearer, gsmbuf); - ogs_expect_or_return(ngapbuf); - - rv = nas_5gs_send_to_gnb(amf_ue, ngapbuf); - ogs_expect(rv == OGS_OK); -} - -void nas_5gs_send_activate_all_dedicated_bearers(amf_bearer_t *default_bearer) -{ - ogs_assert(default_bearer); - - amf_bearer_t *dedicated_bearer = amf_bearer_next(default_bearer); - while (dedicated_bearer) { - nas_5gs_send_activate_dedicated_bearer_context_request( - dedicated_bearer); - dedicated_bearer = amf_bearer_next(dedicated_bearer); - } -} - -void nas_5gs_send_modify_bearer_context_request( - amf_bearer_t *bearer, int qos_presence, int tft_presence) -{ - int rv; - ogs_pkbuf_t *ngapbuf = NULL; - ogs_pkbuf_t *gsmbuf = NULL; - amf_ue_t *amf_ue = NULL; - - ogs_assert(bearer); - amf_ue = bearer->amf_ue; - ogs_assert(amf_ue); - - gsmbuf = esm_build_modify_bearer_context_request( - bearer, qos_presence, tft_presence); - ogs_expect_or_return(gsmbuf); - - if (qos_presence == 1) { - ngapbuf = ngap_build_e_rab_modify_request(bearer, gsmbuf); - ogs_expect_or_return(ngapbuf); - - rv = nas_5gs_send_to_gnb(amf_ue, ngapbuf); - ogs_expect(rv == OGS_OK); - } else { - rv = nas_5gs_send_to_downlink_nas_transport(amf_ue, gsmbuf); - ogs_expect(rv == OGS_OK); - } -} - -void nas_5gs_send_deactivate_bearer_context_request(amf_bearer_t *bearer) -{ - int rv; - ogs_pkbuf_t *ngapbuf = NULL; - ogs_pkbuf_t *gsmbuf = NULL; - amf_ue_t *amf_ue = NULL; - - ogs_assert(bearer); - amf_ue = bearer->amf_ue; - ogs_assert(amf_ue); - - gsmbuf = esm_build_deactivate_bearer_context_request( - bearer, ESM_CAUSE_REGULAR_DEACTIVATION); - ogs_expect_or_return(gsmbuf); - - ngapbuf = ngap_build_e_rab_release_command(bearer, gsmbuf, - NGAP_Cause_PR_nas, NGAP_CauseNas_normal_release); - ogs_expect_or_return(ngapbuf); - - rv = nas_5gs_send_to_gnb(amf_ue, ngapbuf); - ogs_expect(rv == OGS_OK); -} - -void nas_5gs_send_bearer_resource_allocation_reject( - amf_bearer_t *bearer, ogs_nas_gsm_cause_t gsm_cause) -{ - int rv; - amf_ue_t *amf_ue; - ogs_pkbuf_t *gsmbuf = NULL; - - ogs_assert(bearer); - amf_ue = bearer->amf_ue; - ogs_assert(bearer); - - gsmbuf = esm_build_bearer_resource_allocation_reject(bearer, gsm_cause); - ogs_expect_or_return(gsmbuf); - - rv = nas_5gs_send_to_downlink_nas_transport(amf_ue, gsmbuf); - ogs_expect(rv == OGS_OK); -} - -void nas_5gs_send_bearer_resource_modification_reject( - amf_bearer_t *bearer, ogs_nas_gsm_cause_t gsm_cause) -{ - int rv; - amf_ue_t *amf_ue; - ogs_pkbuf_t *gsmbuf = NULL; - - ogs_assert(bearer); - amf_ue = bearer->amf_ue; - ogs_assert(bearer); - - gsmbuf = esm_build_bearer_resource_modification_reject(bearer, gsm_cause); - ogs_expect_or_return(gsmbuf); - - rv = nas_5gs_send_to_downlink_nas_transport(amf_ue, gsmbuf); - ogs_expect(rv == OGS_OK); -} - -void nas_5gs_send_tau_accept( - amf_ue_t *amf_ue, NGAP_ProcedureCode_t procedureCode) -{ - int rv; - ogs_pkbuf_t *gmmbuf = NULL; - - ogs_assert(amf_ue); - - ogs_debug("Tracking area update accept"); - ogs_debug(" IMSI[%s]", amf_ue->imsi_bcd); - - gmmbuf = gmm_build_tau_accept(amf_ue); - ogs_expect_or_return(gmmbuf); - - if (procedureCode == NGAP_ProcedureCode_id_InitialContextSetup) { - ogs_pkbuf_t *ngapbuf = NULL; - ngapbuf = ngap_build_initial_context_setup_request(amf_ue, gmmbuf); - ogs_expect_or_return(ngapbuf); - - rv = nas_5gs_send_to_gnb(amf_ue, ngapbuf); - ogs_expect(rv == OGS_OK); - } else if (procedureCode == NGAP_ProcedureCode_id_downlinkNASTransport) { - rv = nas_5gs_send_to_downlink_nas_transport(amf_ue, gmmbuf); - ogs_expect(rv == OGS_OK); - } else - ogs_assert_if_reached(); -} - -void nas_5gs_send_tau_reject(amf_ue_t *amf_ue, ogs_nas_gmm_cause_t gmm_cause) -{ - int rv; - ogs_pkbuf_t *gmmbuf = NULL; - - ogs_assert(amf_ue); - - /* Build TAU reject */ - gmmbuf = gmm_build_tau_reject(gmm_cause, amf_ue); - ogs_expect_or_return(gmmbuf); - - rv = nas_5gs_send_to_downlink_nas_transport(amf_ue, gmmbuf); - ogs_expect(rv == OGS_OK); -} - -void nas_5gs_send_service_reject(amf_ue_t *amf_ue, - ogs_nas_gmm_cause_t gmm_cause) -{ - int rv; - ogs_pkbuf_t *gmmbuf = NULL; - - ogs_assert(amf_ue); - - /* Build Service Reject */ - gmmbuf = gmm_build_service_reject(gmm_cause, amf_ue); - ogs_expect_or_return(gmmbuf); - - rv = nas_5gs_send_to_downlink_nas_transport(amf_ue, gmmbuf); - ogs_expect(rv == OGS_OK); -} - -void nas_5gs_send_cs_service_notification(amf_ue_t *amf_ue) -{ - int rv; - ogs_pkbuf_t *gmmbuf = NULL; - - ogs_assert(amf_ue); - - ogs_debug("CS Service Notification"); - ogs_debug(" IMSI[%s]", amf_ue->imsi_bcd); - - gmmbuf = gmm_build_cs_service_notification(amf_ue); - ogs_expect_or_return(gmmbuf); - - rv = nas_5gs_send_to_downlink_nas_transport(amf_ue, gmmbuf); - ogs_expect(rv == OGS_OK); -} - -void nas_5gs_send_downlink_nas_transport( - amf_ue_t *amf_ue, uint8_t *buffer, uint8_t length) -{ - int rv; - ogs_pkbuf_t *gmmbuf = NULL; - - ogs_assert(amf_ue); - ogs_assert(buffer); - ogs_assert(length); - - ogs_debug("Downlink NAS transport"); - ogs_debug(" IMSI[%s]", amf_ue->imsi_bcd); - - gmmbuf = gmm_build_downlink_nas_transport(amf_ue, buffer, length); - ogs_expect_or_return(gmmbuf); - - rv = nas_5gs_send_to_downlink_nas_transport(amf_ue, gmmbuf); - ogs_expect(rv == OGS_OK); -} -#endif diff --git a/src/smf/nas-path.h b/src/smf/nas-path.h index 0dad665e0..03bd87779 100644 --- a/src/smf/nas-path.h +++ b/src/smf/nas-path.h @@ -28,36 +28,6 @@ extern "C" { void nas_5gs_send_to_gsm(smf_sess_t *sess, ogs_pkbuf_t *pkbuf); -#if 0 -void nas_5gs_send_detach_accept(amf_ue_t *amf_ue); - -void nas_5gs_send_pdn_connectivity_reject( - amf_sess_t *sess, ogs_nas_5gsm_cause_t gsm_cause); -void nas_5gs_send_gsm_information_request(amf_bearer_t *bearer); -void nas_5gs_send_activate_default_bearer_context_request(amf_bearer_t *bearer); -void nas_5gs_send_activate_dedicated_bearer_context_request( - amf_bearer_t *bearer); -void nas_5gs_send_activate_all_dedicated_bearers(amf_bearer_t *default_bearer); -void nas_5gs_send_modify_bearer_context_request( - amf_bearer_t *bearer, int qos_presence, int tft_presence); -void nas_5gs_send_deactivate_bearer_context_request(amf_bearer_t *bearer); -void nas_5gs_send_bearer_resource_allocation_reject( - amf_bearer_t *bearer, ogs_nas_5gsm_cause_t gsm_cause); -void nas_5gs_send_bearer_resource_modification_reject( - amf_bearer_t *bearer, ogs_nas_5gsm_cause_t gsm_cause); - -void nas_5gs_send_tau_accept( - amf_ue_t *amf_ue, S1AP_ProcedureCode_t procedureCode); -void nas_5gs_send_tau_reject(amf_ue_t *amf_ue, ogs_nas_5gsm_cause_t gmm_cause); - -void nas_5gs_send_service_reject( - amf_ue_t *amf_ue, ogs_nas_5gmm_cause_t gmm_cause); - -void nas_5gs_send_cs_service_notification(amf_ue_t *amf_ue); -void nas_5gs_send_downlink_nas_transport( - amf_ue_t *amf_ue, uint8_t *buffer, uint8_t length); -#endif - #ifdef __cplusplus } #endif diff --git a/src/smf/nf-sm.c b/src/smf/nf-sm.c index cc62b241b..8f271bbe6 100644 --- a/src/smf/nf-sm.c +++ b/src/smf/nf-sm.c @@ -28,6 +28,7 @@ void smf_nf_fsm_init(ogs_sbi_nf_instance_t *nf_instance) ogs_assert(nf_instance); + memset(&e, 0, sizeof(e)); e.sbi.data = nf_instance; ogs_fsm_create(&nf_instance->sm, @@ -40,6 +41,8 @@ void smf_nf_fsm_fini(ogs_sbi_nf_instance_t *nf_instance) smf_event_t e; ogs_assert(nf_instance); + + memset(&e, 0, sizeof(e)); e.sbi.data = nf_instance; ogs_fsm_fini(&nf_instance->sm, &e); diff --git a/src/smf/ngap-build.c b/src/smf/ngap-build.c index 57e5a823d..bb98efd6c 100644 --- a/src/smf/ngap-build.c +++ b/src/smf/ngap-build.c @@ -44,6 +44,7 @@ ogs_pkbuf_t *ngap_build_pdu_session_resource_setup_request_transfer( ogs_assert(bearer); ogs_debug("PDUSessionResourceSetupRequestTransfer"); + memset(&message, 0, sizeof(NGAP_PDUSessionResourceSetupRequestTransfer_t)); ie = CALLOC(1, sizeof(NGAP_PDUSessionResourceSetupRequestTransferIEs_t)); ASN_SEQUENCE_ADD(&message.protocolIEs, ie); diff --git a/src/smf/ngap-handler.c b/src/smf/ngap-handler.c index 4f4637fbd..f9ac6ecd9 100644 --- a/src/smf/ngap-handler.c +++ b/src/smf/ngap-handler.c @@ -29,6 +29,12 @@ int ngap_handle_pdu_session_resource_setup_response_transfer( smf_bearer_t *bearer = NULL; int rv, i; + uint32_t gnb_n3_teid; + ogs_ip_t gnb_n3_ip; + + ogs_pfcp_far_t *far = NULL; + bool far_update = false; + NGAP_PDUSessionResourceSetupResponseTransfer_t message; NGAP_QosFlowPerTNLInformation_t *dLQosFlowPerTNLInformation = NULL; @@ -69,7 +75,8 @@ int ngap_handle_pdu_session_resource_setup_response_transfer( NGAP_UPTransportLayerInformation_PR_gTPTunnel) { ogs_error( "[%s:%d] Unknown NGAP_UPTransportLayerInformation.present [%d]", - smf_ue->supi, sess->psi, uPTransportLayerInformation->present); + smf_ue->supi, sess->psi, + uPTransportLayerInformation->present); smf_sbi_send_sm_context_update_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, "Unknown NGAP_UPTransportLayerInformation.present", @@ -97,11 +104,36 @@ int ngap_handle_pdu_session_resource_setup_response_transfer( } ogs_asn_BIT_STRING_to_ip( - &gTPTunnel->transportLayerAddress, &bearer->gnb_ip); - ogs_asn_OCTET_STRING_to_uint32(&gTPTunnel->gTP_TEID, &bearer->gnb_n3_teid); + &gTPTunnel->transportLayerAddress, &gnb_n3_ip); + ogs_asn_OCTET_STRING_to_uint32(&gTPTunnel->gTP_TEID, &gnb_n3_teid); + + if (memcmp(&bearer->gnb_n3_ip, &gnb_n3_ip, + sizeof(bearer->gnb_n3_ip)) != 0 || + bearer->gnb_n3_teid != gnb_n3_teid) + sess->pfcp_5gc_modify.outer_header_creation_update = true; + else + sess->pfcp_5gc_modify.outer_header_creation_update = false; + + memcpy(&bearer->gnb_n3_ip, &gnb_n3_ip, sizeof(bearer->gnb_n3_ip)); + bearer->gnb_n3_teid = gnb_n3_teid; + + ogs_list_for_each(&bearer->pfcp.far_list, far) { + if (far->dst_if == OGS_PFCP_INTERFACE_ACCESS) { + if (sess->ueUpCnxState == OpenAPI_up_cnx_state_ACTIVATED) { + if (far->apply_action != OGS_PFCP_APPLY_ACTION_FORW) { + far_update = true; + } + } else if (sess->ueUpCnxState == OpenAPI_up_cnx_state_DEACTIVATED) { + far_update = true; + } + } + } + + if (far_update || sess->pfcp_5gc_modify.outer_header_creation_update) + smf_5gc_pfcp_send_session_modification_request(sess); + else + smf_sbi_send_sm_context_updated_data(sess); - bearer->state.outer_header_creation_updated = true; - smf_pfcp_send_session_modification_request(bearer); rv = OGS_OK; cleanup: diff --git a/src/smf/ngap-path.h b/src/smf/ngap-path.h index 39bc3f1b9..e27faffcd 100644 --- a/src/smf/ngap-path.h +++ b/src/smf/ngap-path.h @@ -20,7 +20,7 @@ #ifndef SMF_NGAP_PATH_H #define SMF_NGAP_PATH_H -#include "context.h" +#include "ngap-build.h" #ifdef __cplusplus extern "C" { diff --git a/src/smf/nsmf-handler.c b/src/smf/nsmf-handler.c index 04df0c224..0ce0e8956 100644 --- a/src/smf/nsmf-handler.c +++ b/src/smf/nsmf-handler.c @@ -20,6 +20,7 @@ #include "sbi-path.h" #include "nas-path.h" #include "ngap-path.h" +#include "pfcp-path.h" #include "nsmf-handler.h" bool smf_nsmf_handle_create_sm_context( @@ -45,7 +46,8 @@ bool smf_nsmf_handle_create_sm_context( SmContextCreateData = message->SmContextCreateData; if (!SmContextCreateData) { - ogs_error("[%s:%d] No SmContextCreateData", smf_ue->supi, sess->psi); + ogs_error("[%s:%d] No SmContextCreateData", + smf_ue->supi, sess->psi); n1smbuf = gsm_build_pdu_session_establishment_reject(sess, OGS_5GSM_CAUSE_INVALID_MANDATORY_INFORMATION); smf_sbi_send_sm_context_create_error(session, @@ -67,7 +69,8 @@ bool smf_nsmf_handle_create_sm_context( servingNetwork = SmContextCreateData->serving_network; if (!servingNetwork || !servingNetwork->mnc || !servingNetwork->mcc) { - ogs_error("[%s:%d] No servingNetwork", smf_ue->supi, sess->psi); + ogs_error("[%s:%d] No servingNetwork", + smf_ue->supi, sess->psi); n1smbuf = gsm_build_pdu_session_establishment_reject(sess, OGS_5GSM_CAUSE_INVALID_MANDATORY_INFORMATION); smf_sbi_send_sm_context_create_error(session, @@ -120,10 +123,16 @@ bool smf_nsmf_handle_create_sm_context( bool smf_nsmf_handle_update_sm_context( smf_sess_t *sess, ogs_sbi_message_t *message) { + int i; smf_ue_t *smf_ue = NULL; + ogs_sbi_session_t *session = NULL; + ogs_sbi_message_t sendmsg; + ogs_sbi_response_t *response = NULL; + OpenAPI_sm_context_update_data_t *SmContextUpdateData = NULL; + OpenAPI_sm_context_updated_data_t SmContextUpdatedData; OpenAPI_ref_to_binary_data_t *n2SmMsg = NULL; ogs_pkbuf_t *n2smbuf = NULL; @@ -138,38 +147,203 @@ bool smf_nsmf_handle_update_sm_context( SmContextUpdateData = message->SmContextUpdateData; if (!SmContextUpdateData) { - ogs_error("[%s:%d] No SmContextUpdateData", smf_ue->supi, sess->psi); + ogs_error("[%s:%d] No SmContextUpdateData", + smf_ue->supi, sess->psi); smf_sbi_send_sm_context_update_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, "No SmContextUpdateData", smf_ue->supi, NULL); return false; } - if (!SmContextUpdateData->n2_sm_info_type) { - ogs_error("[%s:%d] No n2SmInfoType", smf_ue->supi, sess->psi); - smf_sbi_send_sm_context_update_error(session, - OGS_SBI_HTTP_STATUS_BAD_REQUEST, - "No N2 SM Info Type", smf_ue->supi, NULL); - return false; - } + if (SmContextUpdateData->n2_sm_info) { - n2SmMsg = SmContextUpdateData->n2_sm_info; - if (!n2SmMsg || !n2SmMsg->content_id) { - smf_sbi_send_sm_context_update_error(session, - OGS_SBI_HTTP_STATUS_BAD_REQUEST, - "No n2SmInfo", smf_ue->supi, NULL); - return false; - } + /********************************************************* + * Handle ACTIVATED + ********************************************************/ - n2smbuf = ogs_sbi_find_part_by_content_id(message, n2SmMsg->content_id); - if (!n2smbuf) { - smf_sbi_send_sm_context_update_error(session, - OGS_SBI_HTTP_STATUS_BAD_REQUEST, - "No N2 SM Content", smf_ue->supi, NULL); - return false; - } + if (!SmContextUpdateData->n2_sm_info_type) { + ogs_error("[%s:%d] No n2SmInfoType", smf_ue->supi, sess->psi); + smf_sbi_send_sm_context_update_error(session, + OGS_SBI_HTTP_STATUS_BAD_REQUEST, + "No n2SmInfoType", smf_ue->supi, NULL); + return false; + } - ngap_send_to_n2sm(sess, SmContextUpdateData->n2_sm_info_type, n2smbuf); + n2SmMsg = SmContextUpdateData->n2_sm_info; + if (!n2SmMsg || !n2SmMsg->content_id) { + ogs_error("[%s:%d] No N2SmInfo.content_id", + smf_ue->supi, sess->psi); + smf_sbi_send_sm_context_update_error(session, + OGS_SBI_HTTP_STATUS_BAD_REQUEST, + "No n2SmInfo.content_id", smf_ue->supi, NULL); + return false; + } + + n2smbuf = ogs_sbi_find_part_by_content_id(message, n2SmMsg->content_id); + if (!n2smbuf) { + ogs_error("[%s:%d] No N2 SM Content", smf_ue->supi, sess->psi); + smf_sbi_send_sm_context_update_error(session, + OGS_SBI_HTTP_STATUS_BAD_REQUEST, + "No N2 SM Content", smf_ue->supi, NULL); + return false; + } + + /* UPDATE_UpCnxState - ACTIVATED */ + sess->ueUpCnxState = OpenAPI_up_cnx_state_ACTIVATED; + + ngap_send_to_n2sm(sess, SmContextUpdateData->n2_sm_info_type, n2smbuf); + + } else { + if (!SmContextUpdateData->up_cnx_state) { + ogs_error("[%s:%d] No upCnxState", smf_ue->supi, sess->psi); + smf_sbi_send_sm_context_update_error(session, + OGS_SBI_HTTP_STATUS_BAD_REQUEST, + "No upCnxState", smf_ue->supi, NULL); + return false; + } + + /* UPDATE_UpCnxState - from SmContextUpdateData */ + sess->ueUpCnxState = SmContextUpdateData->up_cnx_state; + + if (sess->ueUpCnxState == OpenAPI_up_cnx_state_DEACTIVATED) { + + /********************************************************* + * Handle DEACTIVATED + ********************************************************/ + + if (sess->smfUpCnxState == OpenAPI_up_cnx_state_ACTIVATED) { + smf_5gc_pfcp_send_session_modification_request(sess); + + } else if (sess->smfUpCnxState == + OpenAPI_up_cnx_state_DEACTIVATED) { + ogs_warn("[%s:%d] FALLBACK - UpCnxState has already been" + "DEACTIVATED", smf_ue->supi, sess->psi); + + /* No UPDATE_UPCnxState - ueUpCnxState == smfUpCnxState */ + + memset(&sendmsg, 0, sizeof(sendmsg)); + + memset(&SmContextUpdatedData, 0, sizeof(SmContextUpdatedData)); + SmContextUpdatedData.up_cnx_state = sess->smfUpCnxState; + + sendmsg.SmContextUpdatedData = &SmContextUpdatedData; + + response = ogs_sbi_build_response(&sendmsg, + OGS_SBI_HTTP_STATUS_OK); + ogs_assert(response); + ogs_sbi_server_send_response(session, response); + + } else { + char *strerror = ogs_msprintf( + "[%s:%d] Invalid upCnxState [%d:%d]", + smf_ue->supi, sess->psi, + sess->ueUpCnxState, sess->smfUpCnxState); + ogs_error("%s", strerror); + smf_sbi_send_sm_context_update_error(session, + OGS_SBI_HTTP_STATUS_BAD_REQUEST, strerror, NULL, NULL); + ogs_free(strerror); + return false; + } + + } else if (sess->ueUpCnxState == OpenAPI_up_cnx_state_ACTIVATING) { + + /********************************************************* + * Handle ACTIVATING + ********************************************************/ + + if (sess->smfUpCnxState == OpenAPI_up_cnx_state_ACTIVATED) { + ogs_warn("[%s:%d] FALLBACK - UpCnxState has already been " + "ACTIVATED", smf_ue->supi, sess->psi); + /* + * TODO : + * + * TS29.502 5.2.2.3.2.2 + * Activation of User Plane connectivity of PDU session + * + * 2b. If the request does not include the "UE presence + * in LADN service area" indication and the SMF determines + * that the DNN corresponds to a LADN, then the SMF shall + * consider that the UE is outside of the LADN service area. + * + * The SMF shall reject the request if the UE is outside + * of the LADN service area. If the SMF cannot proceed + * with activating the user plane connection of the PDU session + * (e.g. if the PDU session corresponds to a PDU session + * of SSC mode 2 and the SMF decides to change + * the PDU Session Anchor), the SMF shall return an error response, + * as specified for step 2b of figure 5.2.2.3.1-1. + * + * For a 4xx/5xx response, the SmContextUpdateError structure + * shall include the following additional information: + * + * upCnxState attribute set to DEACTIVATED. + * + * + * TS23.502 4.2.3 + * Service Request Procedures + * + * 8a. If the SMF find the PDU Session is activated + * when receiving the Nsmf_PDUSession_UpdateSMContext Request + * in step 4 with Operation Type set to "UP activate" + * to indicate establishment of User Plane resources + * for the PDU Session(s), it deletes the AN Tunnel Info + * and initiates an N4 Session Modification procedure + * to remove Tunnel Info of AN in the UPF. + */ + } else if (sess->smfUpCnxState == OpenAPI_up_cnx_state_ACTIVATING) { + ogs_warn("[%s:%d] FALLBACK - UpCnxState has already been " + "ACTIVATING", smf_ue->supi, sess->psi); + } + + OpenAPI_sm_context_updated_data_t SmContextUpdatedData; + OpenAPI_ref_to_binary_data_t n2SmInfo; + + /* UPDATE_UpCnxState - SYNC */ + sess->smfUpCnxState = sess->ueUpCnxState; + + memset(&sendmsg, 0, sizeof(sendmsg)); + sendmsg.SmContextUpdatedData = &SmContextUpdatedData; + + memset(&SmContextUpdatedData, 0, sizeof(SmContextUpdatedData)); + SmContextUpdatedData.up_cnx_state = sess->smfUpCnxState; + SmContextUpdatedData.n2_sm_info_type = + OpenAPI_n2_sm_info_type_PDU_RES_SETUP_REQ; + SmContextUpdatedData.n2_sm_info = &n2SmInfo; + + memset(&n2SmInfo, 0, sizeof(n2SmInfo)); + n2SmInfo.content_id = (char *)OGS_SBI_CONTENT_NGAP_SM_ID; + + sendmsg.num_of_part = 0; + + sendmsg.part[sendmsg.num_of_part].pkbuf = + ngap_build_pdu_session_resource_setup_request_transfer(sess); + if (sendmsg.part[sendmsg.num_of_part].pkbuf) { + sendmsg.part[sendmsg.num_of_part].content_id = + (char *)OGS_SBI_CONTENT_NGAP_SM_ID; + sendmsg.part[sendmsg.num_of_part].content_type = + (char *)OGS_SBI_CONTENT_NGAP_TYPE; + sendmsg.num_of_part++; + } + + response = ogs_sbi_build_response(&sendmsg, OGS_SBI_HTTP_STATUS_OK); + ogs_assert(response); + ogs_sbi_server_send_response(session, response); + + for (i = 0; i < sendmsg.num_of_part; i++) + if (sendmsg.part[i].pkbuf) + ogs_pkbuf_free(sendmsg.part[i].pkbuf); + + } else { + char *strerror = ogs_msprintf("[%s:%d] Invalid upCnxState [%d:%d]", + smf_ue->supi, sess->psi, + sess->ueUpCnxState, sess->smfUpCnxState); + ogs_error("%s", strerror); + smf_sbi_send_sm_context_update_error(session, + OGS_SBI_HTTP_STATUS_BAD_REQUEST, strerror, NULL, NULL); + ogs_free(strerror); + return false; + } + } return true; } @@ -177,6 +351,9 @@ bool smf_nsmf_handle_update_sm_context( bool smf_nsmf_handle_release_sm_context( smf_sess_t *sess, ogs_sbi_message_t *message) { - ogs_fatal("TODO"); + ogs_assert(sess); + + smf_5gc_pfcp_send_session_deletion_request(sess); + return true; } diff --git a/src/smf/pfcp-path.c b/src/smf/pfcp-path.c index ae1bef913..212099046 100644 --- a/src/smf/pfcp-path.c +++ b/src/smf/pfcp-path.c @@ -27,6 +27,8 @@ static void pfcp_node_fsm_init(ogs_pfcp_node_t *node, bool try_to_assoicate) smf_event_t e; ogs_assert(node); + + memset(&e, 0, sizeof(e)); e.pfcp_node = node; if (try_to_assoicate == true) { @@ -42,6 +44,10 @@ static void pfcp_node_fsm_init(ogs_pfcp_node_t *node, bool try_to_assoicate) static void pfcp_node_fsm_fini(ogs_pfcp_node_t *node) { smf_event_t e; + + ogs_assert(node); + + memset(&e, 0, sizeof(e)); e.pfcp_node = node; ogs_fsm_fini(&node->sm, &e); @@ -269,6 +275,36 @@ void smf_5gc_pfcp_send_session_establishment_request(smf_sess_t *sess) smf_epc_pfcp_send_session_establishment_request(sess, NULL); } +void smf_5gc_pfcp_send_session_modification_request(smf_sess_t *sess) +{ + int rv; + ogs_pkbuf_t *n4buf = NULL; + ogs_pfcp_header_t h; + ogs_pfcp_xact_t *xact = NULL; + smf_bearer_t *bearer = NULL; + + ogs_assert(sess); + + memset(&h, 0, sizeof(ogs_pfcp_header_t)); + h.type = OGS_PFCP_SESSION_MODIFICATION_REQUEST_TYPE; + h.seid = sess->upf_n4_seid; + + n4buf = smf_5gc_n4_build_session_modification_request(h.type, sess); + ogs_expect_or_return(n4buf); + + xact = ogs_pfcp_xact_local_create( + sess->pfcp_node, &h, n4buf, timeout, bearer); + ogs_expect_or_return(xact); + + rv = ogs_pfcp_xact_commit(xact); + ogs_expect(rv == OGS_OK); +} + +void smf_5gc_pfcp_send_session_deletion_request(smf_sess_t *sess) +{ + smf_epc_pfcp_send_session_deletion_request(sess, NULL); +} + void smf_epc_pfcp_send_session_establishment_request( smf_sess_t *sess, void *gtp_xact) { @@ -295,7 +331,7 @@ void smf_epc_pfcp_send_session_establishment_request( ogs_expect(rv == OGS_OK); } -void smf_pfcp_send_session_modification_request(smf_bearer_t *bearer) +void smf_epc_pfcp_send_session_modification_request(smf_bearer_t *bearer) { int rv; ogs_pkbuf_t *n4buf = NULL; @@ -311,7 +347,7 @@ void smf_pfcp_send_session_modification_request(smf_bearer_t *bearer) h.type = OGS_PFCP_SESSION_MODIFICATION_REQUEST_TYPE; h.seid = sess->upf_n4_seid; - n4buf = smf_n4_build_session_modification_request(h.type, bearer); + n4buf = smf_epc_n4_build_session_modification_request(h.type, bearer); ogs_expect_or_return(n4buf); xact = ogs_pfcp_xact_local_create( @@ -322,7 +358,8 @@ void smf_pfcp_send_session_modification_request(smf_bearer_t *bearer) ogs_expect(rv == OGS_OK); } -void smf_pfcp_send_session_deletion_request(smf_sess_t *sess, void *gtp_xact) +void smf_epc_pfcp_send_session_deletion_request( + smf_sess_t *sess, void *gtp_xact) { int rv; ogs_pkbuf_t *n4buf = NULL; diff --git a/src/smf/pfcp-path.h b/src/smf/pfcp-path.h index bdcdb5bec..d4be7d9ba 100644 --- a/src/smf/pfcp-path.h +++ b/src/smf/pfcp-path.h @@ -35,10 +35,13 @@ void smf_pfcp_send_association_setup_response(ogs_pfcp_xact_t *xact, void smf_pfcp_send_heartbeat_request(ogs_pfcp_node_t *node); void smf_5gc_pfcp_send_session_establishment_request(smf_sess_t *sess); +void smf_5gc_pfcp_send_session_modification_request(smf_sess_t *sess); +void smf_5gc_pfcp_send_session_deletion_request(smf_sess_t *sess); + void smf_epc_pfcp_send_session_establishment_request( smf_sess_t *sess, void *gtp_xact); -void smf_pfcp_send_session_modification_request(smf_bearer_t *bearer); -void smf_pfcp_send_session_deletion_request( +void smf_epc_pfcp_send_session_modification_request(smf_bearer_t *bearer); +void smf_epc_pfcp_send_session_deletion_request( smf_sess_t *sess, void *gtp_xact); #ifdef __cplusplus diff --git a/src/smf/s5c-handler.c b/src/smf/s5c-handler.c index 9f90b2f19..480e0cf8f 100644 --- a/src/smf/s5c-handler.c +++ b/src/smf/s5c-handler.c @@ -119,7 +119,7 @@ void smf_s5c_handle_create_session_request( gnb_n3_teid = req->bearer_contexts_to_be_created.s5_s8_u_sgw_f_teid.data; ogs_assert(gnb_n3_teid); bearer->gnb_n3_teid = be32toh(gnb_n3_teid->teid); - rv = ogs_gtp_f_teid_to_ip(gnb_n3_teid, &bearer->gnb_ip); + rv = ogs_gtp_f_teid_to_ip(gnb_n3_teid, &bearer->gnb_n3_ip); ogs_assert(rv == OGS_OK); ogs_debug(" SGW_S5C_TEID[0x%x] SMF_N4_TEID[0x%x]", @@ -274,7 +274,7 @@ void smf_s5c_handle_create_bearer_response( gnb_n3_teid = rsp->bearer_contexts.s5_s8_u_sgw_f_teid.data; ogs_assert(gnb_n3_teid); bearer->gnb_n3_teid = be32toh(gnb_n3_teid->teid); - rv = ogs_gtp_f_teid_to_ip(gnb_n3_teid, &bearer->gnb_ip); + rv = ogs_gtp_f_teid_to_ip(gnb_n3_teid, &bearer->gnb_n3_ip); ogs_assert(rv == OGS_OK); ogs_debug("[SMF] Create Bearer Response : SGW[0x%x] --> SMF[0x%x]", @@ -302,7 +302,7 @@ void smf_s5c_handle_create_bearer_response( qer->gbr.downlink = bearer->qos.gbr.downlink; } - smf_pfcp_send_session_modification_request(bearer); + smf_epc_pfcp_send_session_modification_request(bearer); } void smf_s5c_handle_update_bearer_response( @@ -354,7 +354,7 @@ void smf_s5c_handle_update_bearer_response( ogs_debug("[SMF] Update Bearer Response : SGW[0x%x] --> SMF[0x%x]", sess->sgw_s5c_teid, sess->smf_n4_teid); - if (bearer->state.qos_updated) { + if (bearer->pfcp_epc_modify.qos_update) { ogs_pfcp_qer_t *qer = NULL; /* Only 1 QER is used per bearer */ @@ -368,15 +368,16 @@ void smf_s5c_handle_update_bearer_response( } } - if (bearer->state.tft_updated) + if (bearer->pfcp_epc_modify.tft_update) ogs_warn("Not Implemented"); #if 0 /* FIXME */ - if (bearer->state.qos_updated || bearer->state.tft_updated) { + if (bearer->pfcp_epc_modify.qos_update || + bearer->pfcp_epc_modify.tft_update) { #else - if (bearer->state.qos_updated) { + if (bearer->pfcp_epc_modify.qos_update) { #endif - smf_pfcp_send_session_modification_request(bearer); + smf_epc_pfcp_send_session_modification_request(bearer); } } @@ -429,7 +430,7 @@ void smf_s5c_handle_delete_bearer_response( ogs_debug("[SMF] Delete Bearer Response : SGW[0x%x] --> SMF[0x%x]", sess->sgw_s5c_teid, sess->smf_n4_teid); - smf_pfcp_send_session_modification_request(bearer); + smf_epc_pfcp_send_session_modification_request(bearer); } static int reconfigure_packet_filter(smf_pf_t *pf, ogs_gtp_tft_t *tft, int i) @@ -659,19 +660,19 @@ void smf_s5c_handle_bearer_resource_command( h.teid = sess->sgw_s5c_teid; if (tft_delete) { - memset(&bearer->state, 0, sizeof(bearer->state)); - bearer->state.removed = true; + memset(&bearer->pfcp_epc_modify, 0, sizeof(bearer->pfcp_epc_modify)); + bearer->pfcp_epc_modify.remove = true; h.type = OGS_GTP_DELETE_BEARER_REQUEST_TYPE; pkbuf = smf_s5c_build_delete_bearer_request( h.type, bearer, cmd->procedure_transaction_id.u8); ogs_expect_or_return(pkbuf); } else { - memset(&bearer->state, 0, sizeof(bearer->state)); + memset(&bearer->pfcp_epc_modify, 0, sizeof(bearer->pfcp_epc_modify)); if (tft_update) - bearer->state.tft_updated = true; + bearer->pfcp_epc_modify.tft_update = true; if (qos_update) - bearer->state.qos_updated = true; + bearer->pfcp_epc_modify.qos_update = true; h.type = OGS_GTP_UPDATE_BEARER_REQUEST_TYPE; pkbuf = smf_s5c_build_update_bearer_request( diff --git a/src/smf/sbi-path.c b/src/smf/sbi-path.c index 25ccc977b..e5ef527ee 100644 --- a/src/smf/sbi-path.c +++ b/src/smf/sbi-path.c @@ -131,6 +131,11 @@ void smf_sbi_discover_and_send( smf_ue = sess->smf_ue; ogs_assert(smf_ue); + if (sess->sbi.running == true) { + ogs_error("smf_sbi_discover_and_send() is running"); + return; + } + sess->sbi.nf_state_registered = smf_nf_state_registered; sess->sbi.client_wait.duration = smf_timer_cfg(SMF_TIMER_SBI_CLIENT_WAIT)->duration; @@ -186,6 +191,38 @@ void smf_sbi_send_sm_context_create_error( ogs_pkbuf_free(n1smbuf); } +void smf_sbi_send_sm_context_updated_data(smf_sess_t *sess) +{ + ogs_sbi_session_t *session = NULL; + int status; + + ogs_sbi_message_t sendmsg; + ogs_sbi_response_t *response = NULL; + + OpenAPI_sm_context_updated_data_t SmContextUpdatedData; + + ogs_assert(sess); + session = sess->sbi.session; + ogs_assert(session); + + memset(&sendmsg, 0, sizeof(sendmsg)); + + if (sess->smfUpCnxState == OpenAPI_up_cnx_state_ACTIVATED && + sess->pfcp_5gc_modify.outer_header_creation_update == true) { + status = OGS_SBI_HTTP_STATUS_NO_CONTENT; + } else { + memset(&SmContextUpdatedData, 0, sizeof(SmContextUpdatedData)); + SmContextUpdatedData.up_cnx_state = sess->smfUpCnxState; + + sendmsg.SmContextUpdatedData = &SmContextUpdatedData; + status = OGS_SBI_HTTP_STATUS_OK; + } + + response = ogs_sbi_build_response(&sendmsg, status); + ogs_assert(response); + ogs_sbi_server_send_response(session, response); +} + void smf_sbi_send_sm_context_update_error( ogs_sbi_session_t *session, int status, const char *title, const char *detail, diff --git a/src/smf/sbi-path.h b/src/smf/sbi-path.h index aa29732e5..8f7df71f9 100644 --- a/src/smf/sbi-path.h +++ b/src/smf/sbi-path.h @@ -42,6 +42,7 @@ void smf_sbi_send_sm_context_create_error( ogs_sbi_session_t *session, int status, const char *title, const char *detail, ogs_pkbuf_t *n1smbuf); +void smf_sbi_send_sm_context_updated_data(smf_sess_t *sess); void smf_sbi_send_sm_context_update_error( ogs_sbi_session_t *session, int status, const char *title, const char *detail, diff --git a/src/smf/smf-sm.c b/src/smf/smf-sm.c index c63e0f5c3..abad5de69 100644 --- a/src/smf/smf-sm.c +++ b/src/smf/smf-sm.c @@ -490,16 +490,17 @@ void smf_state_operational(ogs_fsm_t *s, smf_event_t *e) sbi_object = e->sbi.data; ogs_assert(sbi_object); + ogs_timer_stop(sbi_object->client_wait.timer); + + sbi_object->running = false; + SWITCH(sbi_message.h.method) CASE(OGS_SBI_HTTP_METHOD_GET) - if (sbi_message.res_status == OGS_SBI_HTTP_STATUS_OK) { - ogs_timer_stop(sbi_object->client_wait.timer); - + if (sbi_message.res_status == OGS_SBI_HTTP_STATUS_OK) smf_nnrf_handle_nf_discover(sbi_object, &sbi_message); - } else { + else ogs_error("HTTP response error [%d]", sbi_message.res_status); - } break; DEFAULT @@ -525,6 +526,9 @@ void smf_state_operational(ogs_fsm_t *s, smf_event_t *e) e->sess = sess; e->sbi.message = &sbi_message;; + + sess->sbi.running = false; + ogs_fsm_dispatch(&sess->sm, e); if (OGS_FSM_CHECK(&sess->sm, smf_gsm_state_exception)) { ogs_error("[%s] State machine exception", smf_ue->supi); @@ -575,6 +579,8 @@ void smf_state_operational(ogs_fsm_t *s, smf_event_t *e) session = sbi_object->session; ogs_assert(session); + sbi_object->running = false; + ogs_error("Cannot receive SBI message"); ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_GATEWAY_TIMEOUT, NULL, diff --git a/src/udm/context.c b/src/udm/context.c index 7e5b52771..294194dcd 100644 --- a/src/udm/context.c +++ b/src/udm/context.c @@ -141,6 +141,7 @@ udm_ue_t *udm_ue_add(char *suci) udm_ue->sbi.client_wait.timer = ogs_timer_add(udm_self()->timer_mgr, udm_timer_sbi_client_wait_expire, udm_ue); + memset(&e, 0, sizeof(e)); e.udm_ue = udm_ue; ogs_fsm_create(&udm_ue->sm, udm_ue_state_initial, udm_ue_state_final); ogs_fsm_init(&udm_ue->sm, &e); @@ -158,6 +159,7 @@ void udm_ue_remove(udm_ue_t *udm_ue) ogs_list_remove(&self.udm_ue_list, udm_ue); + memset(&e, 0, sizeof(e)); e.udm_ue = udm_ue; ogs_fsm_fini(&udm_ue->sm, &e); ogs_fsm_delete(&udm_ue->sm); diff --git a/src/udm/context.h b/src/udm/context.h index 0e165b265..6df42fed4 100644 --- a/src/udm/context.h +++ b/src/udm/context.h @@ -68,6 +68,12 @@ struct udm_ue_s { char *dereg_callback_uri; + uint8_t k[OGS_KEY_LEN]; + uint8_t opc[OGS_KEY_LEN]; + uint8_t amf[OGS_AMF_LEN]; + uint8_t rand[OGS_RAND_LEN]; + uint8_t sqn[OGS_SQN_LEN]; + ogs_amf_id_t amf_id; ogs_plmn_id_t serving_plmn_id; diff --git a/src/udm/nf-sm.c b/src/udm/nf-sm.c index 80215655b..9e0323bce 100644 --- a/src/udm/nf-sm.c +++ b/src/udm/nf-sm.c @@ -28,6 +28,7 @@ void udm_nf_fsm_init(ogs_sbi_nf_instance_t *nf_instance) ogs_assert(nf_instance); + memset(&e, 0, sizeof(e)); e.sbi.data = nf_instance; ogs_fsm_create(&nf_instance->sm, @@ -40,6 +41,8 @@ void udm_nf_fsm_fini(ogs_sbi_nf_instance_t *nf_instance) udm_event_t e; ogs_assert(nf_instance); + + memset(&e, 0, sizeof(e)); e.sbi.data = nf_instance; ogs_fsm_fini(&nf_instance->sm, &e); diff --git a/src/udm/nudm-handler.c b/src/udm/nudm-handler.c index 40ee6aeb9..387d78dd7 100644 --- a/src/udm/nudm-handler.c +++ b/src/udm/nudm-handler.c @@ -21,11 +21,12 @@ #include "nnrf-handler.h" #include "nudm-handler.h" -bool udm_nudm_ueau_handle_get(udm_ue_t *udm_ue, ogs_sbi_message_t *message) +bool udm_nudm_ueau_handle_get(udm_ue_t *udm_ue, ogs_sbi_message_t *recvmsg) { ogs_sbi_session_t *session = NULL; OpenAPI_authentication_info_request_t *AuthenticationInfoRequest = NULL; + OpenAPI_resynchronization_info_t *ResynchronizationInfo = NULL; char *serving_network_name = NULL; char *ausf_instance_id = NULL; @@ -33,13 +34,13 @@ bool udm_nudm_ueau_handle_get(udm_ue_t *udm_ue, ogs_sbi_message_t *message) session = udm_ue->sbi.session; ogs_assert(session); - ogs_assert(message); + ogs_assert(recvmsg); - AuthenticationInfoRequest = message->AuthenticationInfoRequest; + AuthenticationInfoRequest = recvmsg->AuthenticationInfoRequest; if (!AuthenticationInfoRequest) { ogs_error("[%s] No AuthenticationInfoRequest", udm_ue->suci); ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, - message, "No AuthenticationInfoRequest", udm_ue->suci); + recvmsg, "No AuthenticationInfoRequest", udm_ue->suci); return false; } @@ -47,15 +48,7 @@ bool udm_nudm_ueau_handle_get(udm_ue_t *udm_ue, ogs_sbi_message_t *message) if (!AuthenticationInfoRequest) { ogs_error("[%s] No servingNetworkName", udm_ue->suci); ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, - message, "No servingNetworkName", udm_ue->suci); - return false; - } - - ausf_instance_id = AuthenticationInfoRequest->ausf_instance_id; - if (!AuthenticationInfoRequest) { - ogs_error("[%s] No ausfInstanceId", udm_ue->suci); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, - message, "No ausfInstanceId", udm_ue->suci); + recvmsg, "No servingNetworkName", udm_ue->suci); return false; } @@ -63,12 +56,92 @@ bool udm_nudm_ueau_handle_get(udm_ue_t *udm_ue, ogs_sbi_message_t *message) ogs_free(udm_ue->serving_network_name); udm_ue->serving_network_name = ogs_strdup(serving_network_name); + ausf_instance_id = AuthenticationInfoRequest->ausf_instance_id; + if (!AuthenticationInfoRequest) { + ogs_error("[%s] No ausfInstanceId", udm_ue->suci); + ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + recvmsg, "No ausfInstanceId", udm_ue->suci); + return false; + } + if (udm_ue->ausf_instance_id) ogs_free(udm_ue->ausf_instance_id); udm_ue->ausf_instance_id = ogs_strdup(ausf_instance_id); - udm_sbi_discover_and_send(OpenAPI_nf_type_UDR, udm_ue, NULL, - udm_nudr_dr_build_query_authentication); + ResynchronizationInfo = AuthenticationInfoRequest->resynchronization_info; + if (!ResynchronizationInfo) { + + udm_sbi_discover_and_send(OpenAPI_nf_type_UDR, udm_ue, NULL, + udm_nudr_dr_build_authentication_subscription); + + } else { + uint8_t rand[OGS_RAND_LEN]; + uint8_t auts[OGS_AUTS_LEN]; + uint8_t sqn_ms[OGS_SQN_LEN]; + uint8_t mac_s[OGS_MAC_S_LEN]; + uint64_t sqn = 0; + + if (!ResynchronizationInfo->rand) { + ogs_error("[%s] No RAND", udm_ue->suci); + ogs_sbi_server_send_error(session, + OGS_SBI_HTTP_STATUS_BAD_REQUEST, + recvmsg, "No RAND", udm_ue->suci); + return false; + } + + if (!ResynchronizationInfo->auts) { + ogs_error("[%s] No AUTS", udm_ue->suci); + ogs_sbi_server_send_error(session, + OGS_SBI_HTTP_STATUS_BAD_REQUEST, + recvmsg, "No AUTS", udm_ue->suci); + return false; + } + + ogs_ascii_to_hex( + ResynchronizationInfo->rand, strlen(ResynchronizationInfo->rand), + rand, sizeof(rand)); + ogs_ascii_to_hex( + ResynchronizationInfo->auts, strlen(ResynchronizationInfo->auts), + auts, sizeof(auts)); + + if (memcmp(udm_ue->rand, rand, OGS_RAND_LEN) != 0) { + ogs_error("[%s] Invalid RAND", udm_ue->suci); + ogs_log_hexdump(OGS_LOG_ERROR, udm_ue->rand, sizeof(udm_ue)->rand); + ogs_log_hexdump(OGS_LOG_ERROR, rand, sizeof(rand)); + + ogs_sbi_server_send_error(session, + OGS_SBI_HTTP_STATUS_BAD_REQUEST, + recvmsg, "Invalid RAND", udm_ue->suci); + return false; + } + + ogs_auc_sqn(udm_ue->opc, udm_ue->k, rand, auts, sqn_ms, mac_s); + + if (memcmp(auts + OGS_SQN_LEN, mac_s, OGS_MAC_S_LEN) != 0) { + ogs_error("[%s] Re-synch MAC failed", udm_ue->suci); + ogs_log_print(OGS_LOG_ERROR, "[MAC_S] "); + ogs_log_hexdump(OGS_LOG_ERROR, mac_s, OGS_MAC_S_LEN); + ogs_log_hexdump(OGS_LOG_ERROR, auts + OGS_SQN_LEN, OGS_MAC_S_LEN); + ogs_log_print(OGS_LOG_ERROR, "[SQN] UDM 0x%llx UE ", + (long long)udm_ue->sqn); + ogs_log_hexdump(OGS_LOG_ERROR, sqn_ms, OGS_SQN_LEN); + ogs_sbi_server_send_error(session, + OGS_SBI_HTTP_STATUS_UNAUTHORIZED, + recvmsg, "Re-sync MAC failed", udm_ue->suci); + return false; + + } + + sqn = ogs_buffer_to_uint64(sqn_ms, OGS_SQN_LEN); + + /* 33.102 C.3.4 Guide : IND + 1 */ + sqn = (sqn + 32 + 1) & OGS_MAX_SQN; + + ogs_uint64_to_buffer(sqn, OGS_SQN_LEN, udm_ue->sqn); + + udm_sbi_discover_and_send(OpenAPI_nf_type_UDR, udm_ue, udm_ue->sqn, + udm_nudr_dr_build_authentication_subscription); + } return true; } @@ -95,7 +168,7 @@ bool udm_nudm_ueau_handle_result_confirmation_inform( udm_ue->auth_event, message->AuthEvent); udm_sbi_discover_and_send(OpenAPI_nf_type_UDR, udm_ue, NULL, - udm_nudr_dr_build_update_authentication); + udm_nudr_dr_build_update_authentication_status); return true; } @@ -183,7 +256,7 @@ bool udm_nudm_uecm_handle_registration( message->Amf3GppAccessRegistration); udm_sbi_discover_and_send(OpenAPI_nf_type_UDR, udm_ue, NULL, - udm_nudr_dr_build_update_context); + udm_nudr_dr_build_update_amf_context); return true; } diff --git a/src/udm/nudr-build.c b/src/udm/nudr-build.c index 0530f1e36..c712a45b8 100644 --- a/src/udm/nudr-build.c +++ b/src/udm/nudr-build.c @@ -19,16 +19,20 @@ #include "nudr-build.h" -ogs_sbi_request_t *udm_nudr_dr_build_query_authentication( +ogs_sbi_request_t *udm_nudr_dr_build_authentication_subscription( udm_ue_t *udm_ue, void *data) { ogs_sbi_message_t message; ogs_sbi_request_t *request = NULL; + OpenAPI_list_t *PatchItemList = NULL; + OpenAPI_patch_item_t item; + uint8_t *sqn = data; + char sqn_string[OGS_KEYSTRLEN(OGS_SQN_LEN)]; + ogs_assert(udm_ue); memset(&message, 0, sizeof(message)); - message.h.method = (char *)OGS_SBI_HTTP_METHOD_GET; message.h.service.name = (char *)OGS_SBI_SERVICE_NAME_NUDR_DR; message.h.api.version = (char *)OGS_SBI_API_V1; message.h.resource.component[0] = @@ -39,13 +43,38 @@ ogs_sbi_request_t *udm_nudr_dr_build_query_authentication( message.h.resource.component[3] = (char *)OGS_SBI_RESOURCE_NAME_AUTHENTICATION_SUBSCRIPTION; + if (!sqn) { + message.h.method = (char *)OGS_SBI_HTTP_METHOD_GET; + + } else { + message.h.method = (char *)OGS_SBI_HTTP_METHOD_PATCH; + message.http.content_type = (char *)OGS_SBI_CONTENT_PATCH_TYPE; + + PatchItemList = OpenAPI_list_create(); + ogs_assert(PatchItemList); + + ogs_hex_to_ascii(sqn, OGS_SQN_LEN, sqn_string, sizeof(sqn_string)); + + memset(&item, 0, sizeof(item)); + item.op = OpenAPI_patch_operation_replace; + item.path = (char *)"/sequenceNumber/sqn"; + item.value = sqn_string; + + OpenAPI_list_add(PatchItemList, &item); + + message.PatchItemList = PatchItemList; + } + request = ogs_sbi_build_request(&message); ogs_assert(request); + if (PatchItemList) + OpenAPI_list_free(PatchItemList); + return request; } -ogs_sbi_request_t *udm_nudr_dr_build_update_authentication( +ogs_sbi_request_t *udm_nudr_dr_build_update_authentication_status( udm_ue_t *udm_ue, void *data) { ogs_sbi_message_t message; @@ -77,7 +106,7 @@ ogs_sbi_request_t *udm_nudr_dr_build_update_authentication( return request; } -ogs_sbi_request_t *udm_nudr_dr_build_update_context( +ogs_sbi_request_t *udm_nudr_dr_build_update_amf_context( udm_ue_t *udm_ue, void *data) { ogs_sbi_message_t message; @@ -112,7 +141,7 @@ ogs_sbi_request_t *udm_nudr_dr_build_update_context( return request; } -ogs_sbi_request_t *udm_nudr_dr_build_query_provisioned( +ogs_sbi_request_t *udm_nudr_dr_build_query_subscription_provisioned( udm_ue_t *udm_ue, void *data) { char buf[OGS_PLMNIDSTRLEN]; diff --git a/src/udm/nudr-build.h b/src/udm/nudr-build.h index 9d0516762..7859c826b 100644 --- a/src/udm/nudr-build.h +++ b/src/udm/nudr-build.h @@ -26,13 +26,13 @@ extern "C" { #endif -ogs_sbi_request_t *udm_nudr_dr_build_query_authentication( +ogs_sbi_request_t *udm_nudr_dr_build_authentication_subscription( udm_ue_t *udm_ue, void *data); -ogs_sbi_request_t *udm_nudr_dr_build_query_provisioned( +ogs_sbi_request_t *udm_nudr_dr_build_query_subscription_provisioned( udm_ue_t *udm_ue, void *data); -ogs_sbi_request_t *udm_nudr_dr_build_update_authentication( +ogs_sbi_request_t *udm_nudr_dr_build_update_authentication_status( udm_ue_t *udm_ue, void *data); -ogs_sbi_request_t *udm_nudr_dr_build_update_context( +ogs_sbi_request_t *udm_nudr_dr_build_update_amf_context( udm_ue_t *udm_ue, void *data); #ifdef __cplusplus diff --git a/src/udm/nudr-handler.c b/src/udm/nudr-handler.c index f24983775..dbaa82c1f 100644 --- a/src/udm/nudr-handler.c +++ b/src/udm/nudr-handler.c @@ -33,11 +33,6 @@ bool udm_nudr_dr_handle_subscription_authentication( const char *tmp = "de8ca9df474091fe4e9263c5daa907e9"; const char *tmp = "cc3766b98a8031a7286a68c7f577ed2e"; /* For test */ #endif - uint8_t k[OGS_KEY_LEN]; - uint8_t opc[OGS_KEY_LEN]; - uint8_t amf[OGS_AMF_LEN]; - uint8_t sqn[OGS_SQN_LEN]; - uint8_t rand[OGS_RAND_LEN]; uint8_t autn[OGS_AUTN_LEN]; uint8_t ik[OGS_KEY_LEN]; uint8_t ck[OGS_KEY_LEN]; @@ -66,150 +61,154 @@ bool udm_nudr_dr_handle_subscription_authentication( SWITCH(recvmsg->h.resource.component[3]) CASE(OGS_SBI_RESOURCE_NAME_AUTHENTICATION_SUBSCRIPTION) + SWITCH(recvmsg->h.method) + CASE(OGS_SBI_HTTP_METHOD_GET) - AuthenticationSubscription = recvmsg->AuthenticationSubscription; - if (!AuthenticationSubscription) { - ogs_error("[%s] No AuthenticationSubscription", udm_ue->suci); - ogs_sbi_server_send_error(session, - OGS_SBI_HTTP_STATUS_INTERNAL_SERVER_ERROR, - recvmsg, "No AuthenticationSubscription", udm_ue->suci); - return false; - } + AuthenticationSubscription = recvmsg->AuthenticationSubscription; + if (!AuthenticationSubscription) { + ogs_error("[%s] No AuthenticationSubscription", udm_ue->suci); + ogs_sbi_server_send_error(session, + OGS_SBI_HTTP_STATUS_INTERNAL_SERVER_ERROR, + recvmsg, "No AuthenticationSubscription", udm_ue->suci); + return false; + } - if (AuthenticationSubscription->authentication_method != - OpenAPI_auth_method_5G_AKA) { - ogs_error("[%s] Not supported Auth Method [%d]", - udm_ue->suci, - AuthenticationSubscription->authentication_method); - ogs_sbi_server_send_error(session, - OGS_SBI_HTTP_STATUS_FORBIDDEN, - recvmsg, "Not supported Auth Method", udm_ue->suci); - return false; + if (AuthenticationSubscription->authentication_method != + OpenAPI_auth_method_5G_AKA) { + ogs_error("[%s] Not supported Auth Method [%d]", + udm_ue->suci, + AuthenticationSubscription->authentication_method); + ogs_sbi_server_send_error(session, + OGS_SBI_HTTP_STATUS_FORBIDDEN, + recvmsg, "Not supported Auth Method", udm_ue->suci); + return false; - } + } - if (!AuthenticationSubscription->enc_permanent_key) { - ogs_error("[%s] No encPermanentKey", udm_ue->suci); - ogs_sbi_server_send_error(session, + if (!AuthenticationSubscription->enc_permanent_key) { + ogs_error("[%s] No encPermanentKey", udm_ue->suci); + ogs_sbi_server_send_error(session, + OGS_SBI_HTTP_STATUS_INTERNAL_SERVER_ERROR, + recvmsg, "No encPermanentKey", udm_ue->suci); + return false; + } + if (!AuthenticationSubscription->enc_opc_key) { + ogs_error("[%s] No encPermanentKey", udm_ue->suci); + ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_INTERNAL_SERVER_ERROR, recvmsg, "No encPermanentKey", udm_ue->suci); - return false; - } - if (!AuthenticationSubscription->enc_opc_key) { - ogs_error("[%s] No encPermanentKey", udm_ue->suci); - ogs_sbi_server_send_error(session, - OGS_SBI_HTTP_STATUS_INTERNAL_SERVER_ERROR, - recvmsg, "No encPermanentKey", udm_ue->suci); - return false; - } - if (!AuthenticationSubscription->authentication_management_field) { - ogs_error("[%s] No authenticationManagementField", - udm_ue->suci); - ogs_sbi_server_send_error(session, - OGS_SBI_HTTP_STATUS_INTERNAL_SERVER_ERROR, - recvmsg, "No authenticationManagementField", udm_ue->suci); - return false; - } - if (!AuthenticationSubscription->sequence_number) { - ogs_error("[%s] No SequenceNumber", udm_ue->suci); - ogs_sbi_server_send_error(session, - OGS_SBI_HTTP_STATUS_INTERNAL_SERVER_ERROR, - recvmsg, "No SequenceNumber", udm_ue->suci); - return false; - } - if (AuthenticationSubscription->sequence_number->sqn_scheme != - OpenAPI_sqn_scheme_NON_TIME_BASED) { - ogs_error("[%s] No SequenceNumber.sqnScheme [%d]", udm_ue->suci, - AuthenticationSubscription->sequence_number->sqn_scheme); - ogs_sbi_server_send_error(session, - OGS_SBI_HTTP_STATUS_FORBIDDEN, - recvmsg, "No SequenceNumber.sqnScheme", udm_ue->suci); - return false; - } - if (!AuthenticationSubscription->sequence_number->sqn) { - ogs_error("[%s] No SequenceNumber.sqn", udm_ue->suci); - ogs_sbi_server_send_error(session, - OGS_SBI_HTTP_STATUS_INTERNAL_SERVER_ERROR, - recvmsg, "No SequenceNumber.sqn", udm_ue->suci); - return false; - } + return false; + } + if (!AuthenticationSubscription->authentication_management_field) { + ogs_error("[%s] No authenticationManagementField", + udm_ue->suci); + ogs_sbi_server_send_error(session, + OGS_SBI_HTTP_STATUS_INTERNAL_SERVER_ERROR, + recvmsg, "No authenticationManagementField", udm_ue->suci); + return false; + } + if (!AuthenticationSubscription->sequence_number) { + ogs_error("[%s] No SequenceNumber", udm_ue->suci); + ogs_sbi_server_send_error(session, + OGS_SBI_HTTP_STATUS_INTERNAL_SERVER_ERROR, + recvmsg, "No SequenceNumber", udm_ue->suci); + return false; + } + if (!AuthenticationSubscription->sequence_number->sqn) { + ogs_error("[%s] No SequenceNumber.sqn", udm_ue->suci); + ogs_sbi_server_send_error(session, + OGS_SBI_HTTP_STATUS_INTERNAL_SERVER_ERROR, + recvmsg, "No SequenceNumber.sqn", udm_ue->suci); + return false; + } - udm_ue->auth_type = OpenAPI_auth_type_5G_AKA; + udm_ue->auth_type = OpenAPI_auth_type_5G_AKA; - memset(&AuthenticationInfoResult, - 0, sizeof(AuthenticationInfoResult)); + ogs_ascii_to_hex( + AuthenticationSubscription->enc_opc_key, + strlen(AuthenticationSubscription->enc_opc_key), + udm_ue->opc, sizeof(udm_ue->opc)); + ogs_ascii_to_hex( + AuthenticationSubscription->authentication_management_field, + strlen(AuthenticationSubscription-> + authentication_management_field), + udm_ue->amf, sizeof(udm_ue->amf)); + ogs_ascii_to_hex( + AuthenticationSubscription->enc_permanent_key, + strlen(AuthenticationSubscription->enc_permanent_key), + udm_ue->k, sizeof(udm_ue->k)); + ogs_ascii_to_hex( + AuthenticationSubscription->sequence_number->sqn, + strlen(AuthenticationSubscription->sequence_number->sqn), + udm_ue->sqn, sizeof(udm_ue->sqn)); - AuthenticationInfoResult.auth_type = udm_ue->auth_type; + CASE(OGS_SBI_HTTP_METHOD_PATCH) - /* FIX IT! TODO! NEW! */ - ogs_random(rand, OGS_RAND_LEN); + memset(&AuthenticationInfoResult, + 0, sizeof(AuthenticationInfoResult)); + + AuthenticationInfoResult.auth_type = udm_ue->auth_type; + + ogs_random(udm_ue->rand, OGS_RAND_LEN); #if 0 - OGS_HEX(tmp, strlen(tmp), rand); + /* FIX IT! TODO! NEW! */ + OGS_HEX(tmp, strlen(tmp), udm_ue->rand); #endif - ogs_ascii_to_hex( - AuthenticationSubscription->enc_opc_key, - strlen(AuthenticationSubscription->enc_opc_key), - opc, sizeof(opc)); - ogs_ascii_to_hex( - AuthenticationSubscription->authentication_management_field, - strlen(AuthenticationSubscription-> - authentication_management_field), - amf, sizeof(amf)); - ogs_ascii_to_hex( - AuthenticationSubscription->enc_permanent_key, - strlen(AuthenticationSubscription->enc_permanent_key), - k, sizeof(k)); - ogs_ascii_to_hex( - AuthenticationSubscription->sequence_number->sqn, - strlen(AuthenticationSubscription->sequence_number->sqn), - sqn, sizeof(sqn)); - milenage_generate(opc, amf, k, sqn, rand, autn, ik, ck, ak, - xres, &xres_len); + milenage_generate(udm_ue->opc, udm_ue->amf, udm_ue->k, udm_ue->sqn, + udm_ue->rand, autn, ik, ck, ak, xres, &xres_len); - ogs_assert(udm_ue->serving_network_name); + ogs_assert(udm_ue->serving_network_name); - /* TS33.501 Annex A.2 : Kausf derviation function */ - ogs_kdf_kausf( - ck, ik, - udm_ue->serving_network_name, autn, - kausf); + /* TS33.501 Annex A.2 : Kausf derviation function */ + ogs_kdf_kausf( + ck, ik, + udm_ue->serving_network_name, autn, + kausf); - /* TS33.501 Annex A.4 : RES* and XRES* derivation function */ - ogs_kdf_xres_star( - ck, ik, - udm_ue->serving_network_name, rand, xres, xres_len, - xres_star); + /* TS33.501 Annex A.4 : RES* and XRES* derivation function */ + ogs_kdf_xres_star( + ck, ik, + udm_ue->serving_network_name, udm_ue->rand, xres, xres_len, + xres_star); - memset(&AuthenticationVector, 0, sizeof(AuthenticationVector)); - AuthenticationVector.av_type = OpenAPI_av_type_5G_HE_AKA; + memset(&AuthenticationVector, 0, sizeof(AuthenticationVector)); + AuthenticationVector.av_type = OpenAPI_av_type_5G_HE_AKA; - ogs_hex_to_ascii(rand, sizeof(rand), - rand_string, sizeof(rand_string)); - AuthenticationVector.rand = rand_string; - ogs_hex_to_ascii(xres_star, sizeof(xres_star), - xres_star_string, sizeof(xres_star_string)); - AuthenticationVector.xres_star = xres_star_string; - ogs_hex_to_ascii(autn, sizeof(autn), - autn_string, sizeof(autn_string)); - AuthenticationVector.autn = autn_string; - ogs_hex_to_ascii(kausf, sizeof(kausf), - kausf_string, sizeof(kausf_string)); - AuthenticationVector.kausf = kausf_string; + ogs_hex_to_ascii(udm_ue->rand, sizeof(udm_ue->rand), + rand_string, sizeof(rand_string)); + AuthenticationVector.rand = rand_string; + ogs_hex_to_ascii(xres_star, sizeof(xres_star), + xres_star_string, sizeof(xres_star_string)); + AuthenticationVector.xres_star = xres_star_string; + ogs_hex_to_ascii(autn, sizeof(autn), + autn_string, sizeof(autn_string)); + AuthenticationVector.autn = autn_string; + ogs_hex_to_ascii(kausf, sizeof(kausf), + kausf_string, sizeof(kausf_string)); + AuthenticationVector.kausf = kausf_string; - AuthenticationInfoResult.authentication_vector = - &AuthenticationVector; + AuthenticationInfoResult.authentication_vector = + &AuthenticationVector; - memset(&sendmsg, 0, sizeof(sendmsg)); + memset(&sendmsg, 0, sizeof(sendmsg)); - ogs_assert(AuthenticationInfoResult.auth_type); - sendmsg.AuthenticationInfoResult = &AuthenticationInfoResult; + ogs_assert(AuthenticationInfoResult.auth_type); + sendmsg.AuthenticationInfoResult = &AuthenticationInfoResult; - response = ogs_sbi_build_response(&sendmsg, OGS_SBI_HTTP_STATUS_OK); - ogs_assert(response); - ogs_sbi_server_send_response(session, response); + response = ogs_sbi_build_response(&sendmsg, OGS_SBI_HTTP_STATUS_OK); + ogs_assert(response); + ogs_sbi_server_send_response(session, response); - return true; + return true; + + DEFAULT + ogs_error("Invalid HTTP method [%s]", recvmsg->h.method); + ogs_sbi_server_send_error(session, + OGS_SBI_HTTP_STATUS_FORBIDDEN, recvmsg, + "Invalid HTTP method", recvmsg->h.method); + END + break; CASE(OGS_SBI_RESOURCE_NAME_AUTHENTICATION_STATUS) memset(&sendmsg, 0, sizeof(sendmsg)); diff --git a/src/udm/sbi-path.c b/src/udm/sbi-path.c index 29ce90a7b..7e582c80a 100644 --- a/src/udm/sbi-path.c +++ b/src/udm/sbi-path.c @@ -135,6 +135,11 @@ void udm_sbi_discover_and_send( ogs_assert(nf_type); ogs_assert(build); + if (udm_ue->sbi.running == true) { + ogs_error("udm_sbi_discover_and_send() is running"); + return; + } + udm_ue->sbi.nf_state_registered = udm_nf_state_registered; udm_ue->sbi.client_wait.duration = udm_timer_cfg(UDM_TIMER_SBI_CLIENT_WAIT)->duration; diff --git a/src/udm/udm-sm.c b/src/udm/udm-sm.c index e612b8aa4..0c4838d7f 100644 --- a/src/udm/udm-sm.c +++ b/src/udm/udm-sm.c @@ -284,16 +284,17 @@ void udm_state_operational(ogs_fsm_t *s, udm_event_t *e) sbi_object = e->sbi.data; ogs_assert(sbi_object); + ogs_timer_stop(sbi_object->client_wait.timer); + + sbi_object->running = false; + SWITCH(message.h.method) CASE(OGS_SBI_HTTP_METHOD_GET) - if (message.res_status == OGS_SBI_HTTP_STATUS_OK) { - ogs_timer_stop(sbi_object->client_wait.timer); - + if (message.res_status == OGS_SBI_HTTP_STATUS_OK) udm_nnrf_handle_nf_discover(sbi_object, &message); - } else { + else ogs_error("HTTP response error [%d]", message.res_status); - } break; DEFAULT @@ -317,6 +318,9 @@ void udm_state_operational(ogs_fsm_t *s, udm_event_t *e) e->udm_ue = udm_ue; e->sbi.message = &message; + + udm_ue->sbi.running = false; + ogs_fsm_dispatch(&udm_ue->sm, e); if (OGS_FSM_CHECK(&udm_ue->sm, udm_ue_state_exception)) { ogs_error("[%s] State machine exception", udm_ue->suci); @@ -375,6 +379,8 @@ void udm_state_operational(ogs_fsm_t *s, udm_event_t *e) session = sbi_object->session; ogs_assert(session); + sbi_object->running = false; + ogs_error("Cannot receive SBI message"); ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_GATEWAY_TIMEOUT, NULL, diff --git a/src/udm/ue-sm.c b/src/udm/ue-sm.c index 1a40d9cfe..e65daa340 100644 --- a/src/udm/ue-sm.c +++ b/src/udm/ue-sm.c @@ -124,8 +124,9 @@ void udm_ue_state_operational(ogs_fsm_t *s, udm_event_t *e) CASE(OGS_SBI_RESOURCE_NAME_AM_DATA) CASE(OGS_SBI_RESOURCE_NAME_SMF_SELECT_DATA) CASE(OGS_SBI_RESOURCE_NAME_SM_DATA) - udm_sbi_discover_and_send(OpenAPI_nf_type_UDR, udm_ue, - message, udm_nudr_dr_build_query_provisioned); + udm_sbi_discover_and_send( + OpenAPI_nf_type_UDR, udm_ue, message, + udm_nudr_dr_build_query_subscription_provisioned); break; CASE(OGS_SBI_RESOURCE_NAME_UE_CONTEXT_IN_SMF_DATA) @@ -176,8 +177,14 @@ void udm_ue_state_operational(ogs_fsm_t *s, udm_event_t *e) CASE(OGS_SBI_RESOURCE_NAME_AUTHENTICATION_DATA) if (message->res_status != OGS_SBI_HTTP_STATUS_OK && message->res_status != OGS_SBI_HTTP_STATUS_NO_CONTENT) { - ogs_error("[%s] HTTP response error [%d]", - udm_ue->suci, message->res_status); + if (message->res_status == + OGS_SBI_HTTP_STATUS_NOT_FOUND) { + ogs_warn("[%s] Cannot find SUPI [%d]", + udm_ue->suci, message->res_status); + } else { + ogs_error("[%s] HTTP response error [%d]", + udm_ue->suci, message->res_status); + } ogs_sbi_server_send_error( session, message->res_status, NULL, "HTTP response error", udm_ue->suci); diff --git a/src/udr/nf-sm.c b/src/udr/nf-sm.c index 1be523be9..d81efd7a2 100644 --- a/src/udr/nf-sm.c +++ b/src/udr/nf-sm.c @@ -28,6 +28,7 @@ void udr_nf_fsm_init(ogs_sbi_nf_instance_t *nf_instance) ogs_assert(nf_instance); + memset(&e, 0, sizeof(e)); e.sbi.data = nf_instance; ogs_fsm_create(&nf_instance->sm, @@ -40,6 +41,8 @@ void udr_nf_fsm_fini(ogs_sbi_nf_instance_t *nf_instance) udr_event_t e; ogs_assert(nf_instance); + + memset(&e, 0, sizeof(e)); e.sbi.data = nf_instance; ogs_fsm_fini(&nf_instance->sm, &e); diff --git a/src/udr/nudr-handler.c b/src/udr/nudr-handler.c index 3631b1629..56c14800b 100644 --- a/src/udr/nudr-handler.c +++ b/src/udr/nudr-handler.c @@ -41,6 +41,8 @@ bool udr_nudr_dr_handle_subscription_authentication( OpenAPI_authentication_subscription_t AuthenticationSubscription; OpenAPI_sequence_number_t SequenceNumber; OpenAPI_auth_event_t *AuthEvent = NULL; + OpenAPI_list_t *PatchItemList = NULL; + OpenAPI_lnode_t *node = NULL; ogs_assert(session); ogs_assert(recvmsg); @@ -63,7 +65,7 @@ bool udr_nudr_dr_handle_subscription_authentication( rv = ogs_dbi_auth_info(supi, &auth_info); if (rv != OGS_OK) { - ogs_fatal("[%s] Cannot find SUPI in DB", supi); + ogs_warn("[%s] Cannot find SUPI in DB", supi); ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_NOT_FOUND, recvmsg, "Cannot find SUPI Type", supi); return false; @@ -99,7 +101,6 @@ bool udr_nudr_dr_handle_subscription_authentication( ogs_hex_to_ascii(sqn, sizeof(sqn), sqn_string, sizeof(sqn_string)); memset(&SequenceNumber, 0, sizeof(SequenceNumber)); - SequenceNumber.sqn_scheme = OpenAPI_sqn_scheme_NON_TIME_BASED; SequenceNumber.sqn = sqn_string; AuthenticationSubscription.sequence_number = &SequenceNumber; @@ -116,6 +117,64 @@ bool udr_nudr_dr_handle_subscription_authentication( return true; + CASE(OGS_SBI_HTTP_METHOD_PATCH) + char *sqn_string = NULL; + uint8_t sqn_ms[OGS_SQN_LEN]; + uint64_t sqn = 0; + + PatchItemList = recvmsg->PatchItemList; + if (!PatchItemList) { + ogs_sbi_server_send_error(session, + OGS_SBI_HTTP_STATUS_BAD_REQUEST, + recvmsg, "No PatchItemList Array", NULL); + return false; + } + + OpenAPI_list_for_each(PatchItemList, node) { + if (node->data) { + OpenAPI_patch_item_t *patch_item = node->data; + sqn_string = patch_item->value; + } + } + + if (!sqn_string) { + ogs_sbi_server_send_error(session, + OGS_SBI_HTTP_STATUS_BAD_REQUEST, + recvmsg, "No PatchItemList", NULL); + return false; + } + + ogs_ascii_to_hex(sqn_string, strlen(sqn_string), + sqn_ms, sizeof(sqn_ms)); + sqn = ogs_buffer_to_uint64(sqn_ms, OGS_SQN_LEN); + + rv = ogs_dbi_update_sqn(supi, sqn); + if (rv != OGS_OK) { + ogs_fatal("[%s] Cannot update SQN", supi); + ogs_sbi_server_send_error(session, + OGS_SBI_HTTP_STATUS_INTERNAL_SERVER_ERROR, + recvmsg, "Cannot update SQN", supi); + return false; + } + + rv = ogs_dbi_increment_sqn(supi); + if (rv != OGS_OK) { + ogs_fatal("[%s] Cannot increment SQN", supi); + ogs_sbi_server_send_error(session, + OGS_SBI_HTTP_STATUS_INTERNAL_SERVER_ERROR, + recvmsg, "Cannot increment SQN", supi); + return false; + } + + memset(&sendmsg, 0, sizeof(sendmsg)); + + response = ogs_sbi_build_response( + &sendmsg, OGS_SBI_HTTP_STATUS_NO_CONTENT); + ogs_assert(response); + ogs_sbi_server_send_response(session, response); + + return true; + DEFAULT ogs_error("Invalid HTTP method [%s]", recvmsg->h.method); ogs_sbi_server_send_error(session, @@ -285,6 +344,14 @@ bool udr_nudr_dr_handle_subscription_provisioned( return false; } + if (!subscription_data.ambr.uplink && !subscription_data.ambr.downlink) { + ogs_error("[%s] No UE-AMBR", supi); + ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_NOT_FOUND, + recvmsg, "No UE-AMBR", supi); + + return false; + } + SWITCH(recvmsg->h.resource.component[4]) CASE(OGS_SBI_RESOURCE_NAME_AM_DATA) OpenAPI_access_and_mobility_subscription_data_t @@ -369,7 +436,7 @@ bool udr_nudr_dr_handle_subscription_provisioned( if (!pdn->ambr.uplink && !pdn->ambr.downlink) { if (!subscription_data.ambr.uplink && - subscription_data.ambr.downlink) { + !subscription_data.ambr.downlink) { ogs_error("No Session-AMBR"); ogs_error("No UE-AMBR"); continue; diff --git a/src/upf/gtp-path.c b/src/upf/gtp-path.c index 0fbbe9312..d77833b70 100644 --- a/src/upf/gtp-path.c +++ b/src/upf/gtp-path.c @@ -41,6 +41,7 @@ #define UPF_GTP_HANDLED 1 +static void upf_gtp_send_to_gnb(ogs_pfcp_far_t *far, ogs_pkbuf_t *sendbuf); static int upf_gtp_handle_multicast(ogs_pkbuf_t *recvbuf); static int upf_gtp_handle_slaac(upf_sess_t *sess, ogs_pkbuf_t *recvbuf); static int upf_gtp_handle_pdr(ogs_pfcp_pdr_t *pdr, ogs_pkbuf_t *recvbuf); @@ -250,7 +251,23 @@ void upf_gtp_close(void) } } -void upf_gtp_send_to_gnb(ogs_pfcp_far_t *far, ogs_pkbuf_t *sendbuf) +void upf_gtp_send_buffered_packet(ogs_pfcp_far_t *far) +{ + int i; + + ogs_assert(far); + + if (far->gnode) { + if (far->apply_action & OGS_PFCP_APPLY_ACTION_FORW) { + for (i = 0; i < far->num_of_buffered_packet; i++) { + upf_gtp_send_to_gnb(far, far->buffered_packet[i]); + } + far->num_of_buffered_packet = 0; + } + } +} + +static void upf_gtp_send_to_gnb(ogs_pfcp_far_t *far, ogs_pkbuf_t *sendbuf) { char buf[OGS_ADDRSTRLEN]; int rv; @@ -293,6 +310,46 @@ void upf_gtp_send_to_gnb(ogs_pfcp_far_t *far, ogs_pkbuf_t *sendbuf) ogs_pkbuf_free(sendbuf); } +static int upf_gtp_handle_pdr(ogs_pfcp_pdr_t *pdr, ogs_pkbuf_t *recvbuf) +{ + ogs_pfcp_far_t *far = NULL; + ogs_pkbuf_t *sendbuf = NULL; + + ogs_assert(recvbuf); + ogs_assert(pdr); + + if (pdr->src_if != OGS_PFCP_INTERFACE_CORE) { + ogs_error("PDR is NOT Downlink"); + return OGS_ERROR; + } + + far = pdr->far; + ogs_assert(far); + + sendbuf = ogs_pkbuf_copy(recvbuf); + ogs_assert(sendbuf); + if (!far->gnode) { + /* Default apply action : buffering */ + if (far->num_of_buffered_packet < MAX_NUM_OF_PACKET_BUFFER) { + far->buffered_packet[far->num_of_buffered_packet++] = sendbuf; + return UPF_GTP_HANDLED; + } + } else { + if (far->apply_action & OGS_PFCP_APPLY_ACTION_FORW) { + upf_gtp_send_to_gnb(far, sendbuf); + } else if (far->apply_action & OGS_PFCP_APPLY_ACTION_BUFF) { + if (far->num_of_buffered_packet < MAX_NUM_OF_PACKET_BUFFER) { + far->buffered_packet[far->num_of_buffered_packet++] = sendbuf; + return UPF_GTP_HANDLED; + } + } + return UPF_GTP_HANDLED; + } + + ogs_pkbuf_free(sendbuf); + return OGS_OK; +} + static int upf_gtp_handle_multicast(ogs_pkbuf_t *recvbuf) { struct ip *ip_h = NULL; @@ -360,38 +417,6 @@ static int upf_gtp_handle_slaac(upf_sess_t *sess, ogs_pkbuf_t *recvbuf) return OGS_OK; } -static int upf_gtp_handle_pdr(ogs_pfcp_pdr_t *pdr, ogs_pkbuf_t *recvbuf) -{ - ogs_pfcp_far_t *far = NULL; - ogs_pkbuf_t *sendbuf = NULL; - - ogs_assert(recvbuf); - ogs_assert(pdr); - - if (pdr->src_if != OGS_PFCP_INTERFACE_CORE) { - ogs_error("PDR is NOT Downlink"); - return OGS_ERROR; - } - - far = pdr->far; - ogs_assert(far); - - sendbuf = ogs_pkbuf_copy(recvbuf); - ogs_assert(sendbuf); - if (!far->gnode) { - if (far->num_of_buffered_packet < MAX_NUM_OF_PACKET_BUFFER) { - far->buffered_packet[far->num_of_buffered_packet++] = sendbuf; - return UPF_GTP_HANDLED; - } - } else { - upf_gtp_send_to_gnb(far, sendbuf); - return UPF_GTP_HANDLED; - } - - ogs_pkbuf_free(sendbuf); - return OGS_OK; -} - static int upf_gtp_send_router_advertisement( upf_sess_t *sess, uint8_t *ip6_dst) { diff --git a/src/upf/gtp-path.h b/src/upf/gtp-path.h index 9a94bf47b..edfdc72c6 100644 --- a/src/upf/gtp-path.h +++ b/src/upf/gtp-path.h @@ -30,7 +30,7 @@ extern "C" { int upf_gtp_open(void); void upf_gtp_close(void); -void upf_gtp_send_to_gnb(ogs_pfcp_far_t *far, ogs_pkbuf_t *sendbuf); +void upf_gtp_send_buffered_packet(ogs_pfcp_far_t *far); #ifdef __cplusplus } diff --git a/src/upf/n4-handler.c b/src/upf/n4-handler.c index 5090e85d9..f72d1d81d 100644 --- a/src/upf/n4-handler.c +++ b/src/upf/n4-handler.c @@ -264,7 +264,7 @@ static ogs_pfcp_far_t *handle_create_far(ogs_pfcp_sess_t *sess, far->dst_if = message->forwarding_parameters.destination_interface.u8; if (far->dst_if == OGS_PFCP_INTERFACE_ACCESS) { /* Downlink */ - int rv, i; + int rv; ogs_ip_t ip; ogs_gtp_node_t *gnode = NULL; @@ -294,11 +294,10 @@ static ogs_pfcp_far_t *handle_create_far(ogs_pfcp_sess_t *sess, ogs_assert(rv == OGS_OK); } OGS_SETUP_GTP_NODE(far, gnode); - - for (i = 0; i < far->num_of_buffered_packet; i++) - upf_gtp_send_to_gnb(far, far->buffered_packet[i]); - far->num_of_buffered_packet = 0; } + + upf_gtp_send_buffered_packet(far); + } else if (far->dst_if == OGS_PFCP_INTERFACE_CORE) { /* Uplink */ /* Nothing */ @@ -349,7 +348,7 @@ static ogs_pfcp_far_t *handle_update_far(ogs_pfcp_sess_t *sess, destination_interface.u8; if (far->dst_if == OGS_PFCP_INTERFACE_ACCESS) { /* Downlink */ - int rv, i; + int rv; ogs_ip_t ip; ogs_gtp_node_t *gnode = NULL; @@ -382,11 +381,10 @@ static ogs_pfcp_far_t *handle_update_far(ogs_pfcp_sess_t *sess, ogs_assert(rv == OGS_OK); } OGS_SETUP_GTP_NODE(far, gnode); - - for (i = 0; i < far->num_of_buffered_packet; i++) - upf_gtp_send_to_gnb(far, far->buffered_packet[i]); - far->num_of_buffered_packet = 0; } + + upf_gtp_send_buffered_packet(far); + } else if (far->dst_if == OGS_PFCP_INTERFACE_CORE) { /* Uplink */ /* Nothing */ diff --git a/src/upf/pfcp-path.c b/src/upf/pfcp-path.c index 9649a7cd2..0b910d9de 100644 --- a/src/upf/pfcp-path.c +++ b/src/upf/pfcp-path.c @@ -27,6 +27,8 @@ static void pfcp_node_fsm_init(ogs_pfcp_node_t *node, bool try_to_assoicate) upf_event_t e; ogs_assert(node); + + memset(&e, 0, sizeof(e)); e.pfcp_node = node; if (try_to_assoicate == true) { @@ -42,6 +44,10 @@ static void pfcp_node_fsm_init(ogs_pfcp_node_t *node, bool try_to_assoicate) static void pfcp_node_fsm_fini(ogs_pfcp_node_t *node) { upf_event_t e; + + ogs_assert(node); + + memset(&e, 0, sizeof(e)); e.pfcp_node = node; ogs_fsm_fini(&node->sm, &e); diff --git a/tests/common/context.c b/tests/common/context.c index 6e8008288..e08d7b52b 100644 --- a/tests/common/context.c +++ b/tests/common/context.c @@ -480,6 +480,34 @@ void test_ue_set_mobile_identity(test_ue_t *test_ue, test_ue->imsi = ogs_supi_get_id(test_ue->supi); } +void test_ue_set_mobile_identity_suci(test_ue_t *test_ue, + ogs_nas_5gs_mobile_identity_suci_t *mobile_identity_suci, + uint16_t mobile_identity_suci_length) +{ + ogs_nas_5gs_mobile_identity_t mobile_identity; + + ogs_assert(test_ue); + ogs_assert(mobile_identity_suci); + ogs_assert(mobile_identity_suci_length); + + test_ue->mobile_identity_suci_length = mobile_identity_suci_length; + memcpy(&test_ue->mobile_identity_suci, mobile_identity_suci, + mobile_identity_suci_length); + + mobile_identity.length = test_ue->mobile_identity_suci_length; + mobile_identity.buffer = &test_ue->mobile_identity_suci; + + if (test_ue->suci) + ogs_free(test_ue->suci); + test_ue->suci = ogs_nas_5gs_suci_from_mobile_identity(&mobile_identity); + if (test_ue->supi) + ogs_free(test_ue->supi); + test_ue->supi = ogs_supi_from_suci(test_ue->suci); + if (test_ue->imsi) + ogs_free(test_ue->imsi); + test_ue->imsi = ogs_supi_get_id(test_ue->supi); +} + void test_ue_remove(test_ue_t *test_ue) { if (test_ue->suci) diff --git a/tests/common/context.h b/tests/common/context.h index 2ae83f66f..639d11fe4 100644 --- a/tests/common/context.h +++ b/tests/common/context.h @@ -67,6 +67,10 @@ typedef struct test_ue_s { char *suci; /* TS33.501 : SUCI */ char *supi; /* TS33.501 : SUPI */ + ogs_nas_5gs_mobile_identity_suci_t mobile_identity_suci; + uint16_t mobile_identity_suci_length; + ogs_nas_5gs_guti_t nas_guti; + uint8_t k[OGS_KEY_LEN]; uint8_t opc[OGS_KEY_LEN]; @@ -84,9 +88,11 @@ typedef struct test_ue_s { struct { ED3(uint8_t tsc:1;, uint8_t ksi:3;, - uint8_t spare:4;) + uint8_t value:4;) }; ogs_nas_5gs_registration_type_t registration; + ogs_nas_de_registration_type_t de_registration; + uint8_t data; }; @@ -123,7 +129,7 @@ typedef struct test_ue_s { int security_context_available; int mac_failed; - ogs_nas_5gs_guti_t nas_guti; + uint8_t gmm_message_type; /* Last received 5GMM message type */ test_sess_t *sess; } test_ue_t; @@ -152,6 +158,9 @@ int test_context_parse_config(void); void test_ue_set_mobile_identity(test_ue_t *test_ue, ogs_nas_5gs_mobile_identity_t *mobile_identity); +void test_ue_set_mobile_identity_suci(test_ue_t *test_ue, + ogs_nas_5gs_mobile_identity_suci_t *mobile_identity_suci, + uint16_t mobile_identity_suci_length); void test_ue_remove(test_ue_t *test_ue); #ifdef __cplusplus diff --git a/tests/common/gmm-build.c b/tests/common/gmm-build.c index fcca4d93d..a3746951e 100644 --- a/tests/common/gmm-build.c +++ b/tests/common/gmm-build.c @@ -19,9 +19,12 @@ #include "test-common.h" -ogs_pkbuf_t *testgmm_build_registration_request(test_ue_t *test_ue, - ogs_nas_5gs_mobile_identity_t *mobile_identity) +ogs_pkbuf_t *testgmm_build_registration_request( + test_ue_t *test_ue, bool update) { + test_sess_t *sess = NULL; + uint16_t psimask = 0; + ogs_nas_5gs_message_t message; ogs_pkbuf_t *pkbuf = NULL; ogs_nas_5gs_registration_request_t *registration_request = @@ -32,19 +35,48 @@ ogs_pkbuf_t *testgmm_build_registration_request(test_ue_t *test_ue, ®istration_request->gmm_capability; ogs_nas_ue_security_capability_t *ue_security_capability = ®istration_request->ue_security_capability; + ogs_nas_uplink_data_status_t *uplink_data_status = + ®istration_request->uplink_data_status; + ogs_nas_5gs_mobile_identity_guti_t mobile_identity_guti; ogs_assert(test_ue); - ogs_assert(mobile_identity); + sess = test_ue->sess; + ogs_assert(sess); memset(&message, 0, sizeof(message)); + if (update) { + message.h.security_header_type = + OGS_NAS_SECURITY_HEADER_INTEGRITY_PROTECTED_AND_CIPHERED; + message.h.extended_protocol_discriminator = + OGS_NAS_EXTENDED_PROTOCOL_DISCRIMINATOR_5GMM; + } message.gmm.h.extended_protocol_discriminator = OGS_NAS_EXTENDED_PROTOCOL_DISCRIMINATOR_5GMM; message.gmm.h.message_type = OGS_NAS_5GS_REGISTRATION_REQUEST; registration_type->data = test_ue->nas.data; - registration_request->mobile_identity.length = mobile_identity->length; - registration_request->mobile_identity.buffer = mobile_identity->buffer; + if (update) { + ogs_nas_5gs_nas_guti_to_mobilty_identity_guti( + &test_ue->nas_guti, &mobile_identity_guti); + registration_request->mobile_identity.length = + sizeof(ogs_nas_5gs_mobile_identity_guti_t); + registration_request->mobile_identity.buffer = + &mobile_identity_guti; + + registration_request->presencemask |= + OGS_NAS_5GS_REGISTRATION_REQUEST_UPLINK_DATA_STATUS_PRESENT; + psimask = 1 << sess->psi; + uplink_data_status->length = 2; + uplink_data_status->psi |= psimask << 8; + uplink_data_status->psi |= psimask >> 8; + + } else { + registration_request->mobile_identity.length = + test_ue->mobile_identity_suci_length; + registration_request->mobile_identity.buffer = + &test_ue->mobile_identity_suci; + } registration_request->presencemask |= OGS_NAS_5GS_REGISTRATION_REQUEST_5GMM_CAPABILITY_PRESENT; @@ -61,6 +93,31 @@ ogs_pkbuf_t *testgmm_build_registration_request(test_ue_t *test_ue, ue_security_capability->eps_ea = 0xff; ue_security_capability->eps_ia = 0xff; + if (update) + return test_nas_5gs_security_encode(test_ue, &message); + else + return ogs_nas_5gs_plain_encode(&message); +} + +ogs_pkbuf_t *testgmm_build_identity_response(test_ue_t *test_ue) +{ + ogs_nas_5gs_message_t message; + ogs_pkbuf_t *pkbuf = NULL; + ogs_nas_5gs_identity_response_t *identity_response = + &message.gmm.identity_response; + + ogs_assert(test_ue); + + memset(&message, 0, sizeof(message)); + message.gmm.h.extended_protocol_discriminator = + OGS_NAS_EXTENDED_PROTOCOL_DISCRIMINATOR_5GMM; + message.gmm.h.message_type = OGS_NAS_5GS_IDENTITY_RESPONSE; + + identity_response->mobile_identity.length = + test_ue->mobile_identity_suci_length; + identity_response->mobile_identity.buffer = + &test_ue->mobile_identity_suci; + return ogs_nas_5gs_plain_encode(&message); } @@ -70,7 +127,9 @@ ogs_pkbuf_t *testgmm_build_authentication_response(test_ue_t *test_ue) ogs_pkbuf_t *pkbuf = NULL; ogs_nas_5gs_authentication_response_t *authentication_response = &message.gmm.authentication_response; - ogs_nas_authentication_response_parameter_t *authentication_response_parameter = &authentication_response->authentication_response_parameter; + ogs_nas_authentication_response_parameter_t + *authentication_response_parameter = + &authentication_response->authentication_response_parameter; uint8_t ik[OGS_KEY_LEN]; uint8_t ck[OGS_KEY_LEN]; @@ -100,7 +159,7 @@ ogs_pkbuf_t *testgmm_build_authentication_response(test_ue_t *test_ue) serving_network_name, test_ue->rand, res, 8, authentication_response_parameter->res); - authentication_response_parameter->length = 16; + authentication_response_parameter->length = OGS_AUTN_LEN; memcpy(res_star, authentication_response_parameter->res, authentication_response_parameter->length); @@ -114,6 +173,54 @@ ogs_pkbuf_t *testgmm_build_authentication_response(test_ue_t *test_ue) return ogs_nas_5gs_plain_encode(&message); } +ogs_pkbuf_t *testgmm_build_authentication_failure( + test_ue_t *test_ue, ogs_nas_5gmm_cause_t gmm_cause) + +{ + ogs_nas_5gs_message_t message; + ogs_pkbuf_t *pkbuf = NULL; + ogs_nas_5gs_authentication_failure_t *authentication_failure = + &message.gmm.authentication_failure; + ogs_nas_authentication_failure_parameter_t + *authentication_failure_parameter = + &authentication_failure->authentication_failure_parameter; + + uint8_t ak[OGS_AK_LEN]; + uint8_t sqn_ms[OGS_SQN_LEN] = "\x00\x00\x11\x22\x33\x44"; + uint8_t mac_s[OGS_MAC_S_LEN]; + uint8_t amf[2] = { 0, 0 }; + uint8_t auts[OGS_AUTS_LEN]; + int i = 0; + + ogs_assert(test_ue); + + memset(&message, 0, sizeof(message)); + message.gmm.h.extended_protocol_discriminator = + OGS_NAS_EXTENDED_PROTOCOL_DISCRIMINATOR_5GMM; + message.gmm.h.message_type = OGS_NAS_5GS_AUTHENTICATION_FAILURE; + + authentication_failure->gmm_cause = gmm_cause; + + if (gmm_cause == OGS_5GMM_CAUSE_SYNCH_FAILURE) { + authentication_failure->presencemask |= + OGS_NAS_5GS_AUTHENTICATION_RESPONSE_AUTHENTICATION_RESPONSE_PARAMETER_PRESENT; + + milenage_f2345(test_ue->opc, test_ue->k, test_ue->rand, + NULL, NULL, NULL, NULL, ak); + + milenage_f1(test_ue->opc, test_ue->k, test_ue->rand, + sqn_ms, amf, NULL, auts + OGS_SQN_LEN); + for (i = 0; i < OGS_SQN_LEN; i++) + auts[i] = sqn_ms[i] ^ ak[i]; + + authentication_failure_parameter->length = OGS_AUTS_LEN; + memcpy(authentication_failure_parameter->auts, auts, + authentication_failure_parameter->length); + } + + return ogs_nas_5gs_plain_encode(&message); +} + ogs_pkbuf_t *testgmm_build_security_mode_complete( test_ue_t *test_ue, ogs_pkbuf_t *nasbuf) { @@ -157,6 +264,7 @@ ogs_pkbuf_t *testgmm_build_security_mode_complete( OGS_NAS_5GS_SECURITY_MODE_COMPLETE_NAS_MESSAGE_CONTAINER_PRESENT; nas_message_container->length = nasbuf->len; nas_message_container->buffer = nasbuf->data; + ogs_pkbuf_free(nasbuf); } return test_nas_5gs_security_encode(test_ue, &message); @@ -184,6 +292,59 @@ ogs_pkbuf_t *testgmm_build_registration_complete(test_ue_t *test_ue) return test_nas_5gs_security_encode(test_ue, &message); } +ogs_pkbuf_t *testgmm_build_service_request(test_ue_t *test_ue) +{ + ogs_nas_5gs_message_t message; + ogs_pkbuf_t *pkbuf = NULL; + ogs_nas_5gs_service_request_t *service_request = + &message.gmm.service_request; + ogs_nas_5gs_mobile_identity_s_tmsi_t mobile_identity_s_tmsi; + ogs_nas_uplink_data_status_t *uplink_data_status = NULL; + + test_sess_t *sess = NULL; + uint16_t psimask = 0; + + ogs_assert(test_ue); + sess = test_ue->sess; + ogs_assert(sess); + + uplink_data_status = &service_request->uplink_data_status; + + memset(&message, 0, sizeof(message)); + message.h.security_header_type = + OGS_NAS_SECURITY_HEADER_INTEGRITY_PROTECTED_AND_CIPHERED; + message.h.extended_protocol_discriminator = + OGS_NAS_EXTENDED_PROTOCOL_DISCRIMINATOR_5GMM; + + message.gmm.h.extended_protocol_discriminator = + OGS_NAS_EXTENDED_PROTOCOL_DISCRIMINATOR_5GMM; + message.gmm.h.message_type = OGS_NAS_5GS_SERVICE_REQUEST; + + service_request->ngksi.type = OGS_NAS_SERVICE_TYPE_DATA; + service_request->ngksi.tsc = test_ue->nas.tsc; + service_request->ngksi.value = test_ue->nas.ksi; + + ogs_assert(test_ue->nas_guti.m_tmsi); + memset(&mobile_identity_s_tmsi, 0, sizeof(mobile_identity_s_tmsi)); + + mobile_identity_s_tmsi.h.type = OGS_NAS_5GS_MOBILE_IDENTITY_S_TMSI; + mobile_identity_s_tmsi.m_tmsi = htobe32(test_ue->nas_guti.m_tmsi); + mobile_identity_s_tmsi.set1 = test_ue->nas_guti.amf_id.set1; + mobile_identity_s_tmsi.set2 = test_ue->nas_guti.amf_id.set2; + mobile_identity_s_tmsi.pointer = test_ue->nas_guti.amf_id.pointer; + service_request->s_tmsi.length = sizeof(mobile_identity_s_tmsi); + service_request->s_tmsi.buffer = &mobile_identity_s_tmsi; + + service_request->presencemask |= + OGS_NAS_5GS_SERVICE_REQUEST_UPLINK_DATA_STATUS_PRESENT; + psimask = 1 << sess->psi; + uplink_data_status->length = 2; + uplink_data_status->psi |= psimask << 8; + uplink_data_status->psi |= psimask >> 8; + + return test_nas_5gs_security_encode(test_ue, &message); +} + ogs_pkbuf_t *testgmm_build_configuration_update_complete(test_ue_t *test_ue) { ogs_nas_5gs_message_t message; @@ -194,7 +355,8 @@ ogs_pkbuf_t *testgmm_build_configuration_update_complete(test_ue_t *test_ue) ogs_assert(test_ue); - control_plane_service_type = &configuration_update_complete->control_plane_service_type; + control_plane_service_type = + &configuration_update_complete->control_plane_service_type; memset(&message, 0, sizeof(message)); message.h.security_header_type = @@ -280,3 +442,68 @@ ogs_pkbuf_t *testgmm_build_ul_nas_transport(test_sess_t *test_sess, return pkbuf; } + +ogs_pkbuf_t *testgmm_build_de_registration_request( + test_ue_t *test_ue, bool switch_off) +{ + ogs_nas_5gs_message_t message; + ogs_pkbuf_t *pkbuf = NULL; + ogs_nas_5gs_deregistration_request_from_ue_t + *deregistration_request_from_ue = + &message.gmm.deregistration_request_from_ue; + ogs_nas_de_registration_type_t *de_registration_type = + &deregistration_request_from_ue->de_registration_type; + ogs_nas_5gs_mobile_identity_guti_t mobile_identity_guti; + + ogs_assert(test_ue); + + memset(&message, 0, sizeof(message)); + message.h.security_header_type = + OGS_NAS_SECURITY_HEADER_INTEGRITY_PROTECTED_AND_CIPHERED; + message.h.extended_protocol_discriminator = + OGS_NAS_EXTENDED_PROTOCOL_DISCRIMINATOR_5GMM; + + message.gmm.h.extended_protocol_discriminator = + OGS_NAS_EXTENDED_PROTOCOL_DISCRIMINATOR_5GMM; + message.gmm.h.message_type = OGS_NAS_5GS_DEREGISTRATION_REQUEST; + + de_registration_type->ksi = test_ue->nas.ksi; + de_registration_type->switch_off = switch_off; + de_registration_type->access_type = test_ue->nas.access_type; + + if (test_ue->nas_guti.m_tmsi) { + ogs_nas_5gs_nas_guti_to_mobilty_identity_guti( + &test_ue->nas_guti, &mobile_identity_guti); + deregistration_request_from_ue->mobile_identity.length = + sizeof(ogs_nas_5gs_mobile_identity_guti_t); + deregistration_request_from_ue->mobile_identity.buffer = + &mobile_identity_guti; + } else { + deregistration_request_from_ue->mobile_identity.length = + test_ue->mobile_identity_suci_length; + deregistration_request_from_ue->mobile_identity.buffer = + &test_ue->mobile_identity_suci; + } + + return test_nas_5gs_security_encode(test_ue, &message); +} + +ogs_pkbuf_t *testgmm_build_gmm_status( + test_ue_t *test_ue, ogs_nas_5gmm_cause_t gmm_cause) +{ + ogs_nas_5gs_message_t message; + ogs_pkbuf_t *pkbuf = NULL; + ogs_nas_5gs_5gmm_status_t *gmm_status = &message.gmm.gmm_status; + + ogs_assert(test_ue); + ogs_assert(gmm_status); + + memset(&message, 0, sizeof(message)); + message.gmm.h.extended_protocol_discriminator = + OGS_NAS_EXTENDED_PROTOCOL_DISCRIMINATOR_5GMM; + message.gmm.h.message_type = OGS_NAS_5GS_5GMM_STATUS; + + gmm_status->gmm_cause = gmm_cause; + + return ogs_nas_5gs_plain_encode(&message); +} diff --git a/tests/common/gmm-build.h b/tests/common/gmm-build.h index 0a6126e31..f8012e5d5 100644 --- a/tests/common/gmm-build.h +++ b/tests/common/gmm-build.h @@ -24,15 +24,23 @@ extern "C" { #endif -ogs_pkbuf_t *testgmm_build_registration_request(test_ue_t *test_ue, - ogs_nas_5gs_mobile_identity_t *mobile_identity); +ogs_pkbuf_t *testgmm_build_registration_request( + test_ue_t *test_ue, bool update); +ogs_pkbuf_t *testgmm_build_identity_response(test_ue_t *test_ue); ogs_pkbuf_t *testgmm_build_authentication_response(test_ue_t *test_ue); +ogs_pkbuf_t *testgmm_build_authentication_failure( + test_ue_t *test_ue, ogs_nas_5gmm_cause_t gmm_cause); ogs_pkbuf_t *testgmm_build_security_mode_complete( test_ue_t *test_ue, ogs_pkbuf_t *nasbuf); ogs_pkbuf_t *testgmm_build_registration_complete(test_ue_t *test_ue); +ogs_pkbuf_t *testgmm_build_service_request(test_ue_t *test_ue); ogs_pkbuf_t *testgmm_build_configuration_update_complete(test_ue_t *test_ue); ogs_pkbuf_t *testgmm_build_ul_nas_transport(test_sess_t *test_sess, uint8_t payload_type, ogs_pkbuf_t *payload); +ogs_pkbuf_t *testgmm_build_de_registration_request( + test_ue_t *test_ue, bool switch_off); +ogs_pkbuf_t *testgmm_build_gmm_status( + test_ue_t *test_ue, ogs_nas_5gmm_cause_t gmm_cause); #ifdef __cplusplus } diff --git a/tests/common/gmm-handler.c b/tests/common/gmm-handler.c index 0f9d66dc7..e7f3afa74 100644 --- a/tests/common/gmm-handler.c +++ b/tests/common/gmm-handler.c @@ -19,6 +19,22 @@ #include "test-common.h" +void testgmm_handle_identity_request(test_ue_t *test_ue, + ogs_nas_5gs_identity_request_t *identity_request) +{ + ogs_assert(test_ue); + ogs_assert(identity_request); + + switch (identity_request->identity_type.value) { + case OGS_NAS_5GS_MOBILE_IDENTITY_SUCI: + break; + default: + ogs_error("Not implemented [%d]", + identity_request->identity_type.value); + break; + } +} + void testgmm_handle_authentication_request(test_ue_t *test_ue, ogs_nas_5gs_authentication_request_t *authentication_request) { diff --git a/tests/common/gmm-handler.h b/tests/common/gmm-handler.h index e03f3acb8..40a2b3138 100644 --- a/tests/common/gmm-handler.h +++ b/tests/common/gmm-handler.h @@ -24,6 +24,8 @@ extern "C" { #endif +void testgmm_handle_identity_request(test_ue_t *test_ue, + ogs_nas_5gs_identity_request_t *identity_request); void testgmm_handle_authentication_request(test_ue_t *test_ue, ogs_nas_5gs_authentication_request_t *authentication_request); void testgmm_handle_security_mode_command(test_ue_t *test_ue, diff --git a/tests/common/meson.build b/tests/common/meson.build index bb2b947d5..de3ea8a57 100644 --- a/tests/common/meson.build +++ b/tests/common/meson.build @@ -35,6 +35,7 @@ libtestcommon_sources = files(''' gsm-build.c gsm-handler.c nas-path.c + nas-encoder.c nas-security.c '''.split()) diff --git a/tests/common/nas-encoder.c b/tests/common/nas-encoder.c new file mode 100644 index 000000000..7017d64a8 --- /dev/null +++ b/tests/common/nas-encoder.c @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2019,2020 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "test-common.h" + +int ogs_nas_5gs_encode_deregistration_request_from_ue( + ogs_pkbuf_t *pkbuf, ogs_nas_5gs_message_t *message); + +ogs_pkbuf_t *test_nas_5gmm_encode(ogs_nas_5gs_message_t *message) +{ + ogs_pkbuf_t *pkbuf = NULL; + int size = 0; + int encoded = 0; + + ogs_assert(message); + + /* The Packet Buffer(ogs_pkbuf_t) for NAS message MUST make a HEADROOM. + * When calculating AES_CMAC, we need to use the headroom of the packet. */ + pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN); + ogs_assert(pkbuf); + ogs_pkbuf_reserve(pkbuf, OGS_NAS_HEADROOM); + ogs_pkbuf_put(pkbuf, OGS_MAX_SDU_LEN-OGS_NAS_HEADROOM); + + size = sizeof(ogs_nas_5gmm_header_t); + ogs_assert(ogs_pkbuf_pull(pkbuf, size)); + + memcpy(pkbuf->data - size, &message->gmm.h, size); + encoded += size; + + switch(message->gmm.h.message_type) { + case OGS_NAS_5GS_DEREGISTRATION_REQUEST: + size = ogs_nas_5gs_encode_deregistration_request_from_ue( + pkbuf, message); + ogs_assert(size >= 0); + encoded += size; + break; + default: + ogs_error("Unknown message type (0x%x) or not implemented", + message->gmm.h.message_type); + ogs_pkbuf_free(pkbuf); + return NULL; + } + + ogs_assert(ogs_pkbuf_push(pkbuf, encoded)); + + pkbuf->len = encoded; + + return pkbuf; +} + +ogs_pkbuf_t *test_nas_5gs_plain_encode(ogs_nas_5gs_message_t *message) +{ + ogs_assert(message); + + ogs_assert(message->gmm.h.extended_protocol_discriminator == + message->gsm.h.extended_protocol_discriminator); + + if (message->gmm.h.extended_protocol_discriminator == + OGS_NAS_EXTENDED_PROTOCOL_DISCRIMINATOR_5GMM) + return test_nas_5gmm_encode(message); + + ogs_error("Unknown discriminator [%d]", + message->gmm.h.extended_protocol_discriminator); + + return NULL; +} diff --git a/tests/common/nas-encoder.h b/tests/common/nas-encoder.h new file mode 100644 index 000000000..9852f49f3 --- /dev/null +++ b/tests/common/nas-encoder.h @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2019,2020 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef TEST_NAS_5GS_ENCODER_H +#define TEST_NAS_5GS_ENCODER_H + +#ifdef __cplusplus +extern "C" { +#endif + +ogs_pkbuf_t *test_nas_5gmm_encode(ogs_nas_5gs_message_t *message); +ogs_pkbuf_t *test_nas_5gs_plain_encode(ogs_nas_5gs_message_t *message); + +#ifdef __cplusplus +} +#endif + +#endif /* TEST_NAS_5GS_ENCODER_H */ + diff --git a/tests/common/nas-path.c b/tests/common/nas-path.c index 9c7d54eac..48947b146 100644 --- a/tests/common/nas-path.c +++ b/tests/common/nas-path.c @@ -30,17 +30,27 @@ void testgmm_recv(test_ue_t *test_ue, ogs_pkbuf_t *pkbuf) rv = ogs_nas_5gmm_decode(&message, pkbuf); ogs_assert(rv == OGS_OK); + test_ue->gmm_message_type = message.gmm.h.message_type; switch (message.gmm.h.message_type) { + case OGS_NAS_5GS_IDENTITY_REQUEST: + testgmm_handle_identity_request(test_ue, &message.gmm.identity_request); + break; + case OGS_NAS_5GS_REGISTRATION_REJECT: + break; case OGS_NAS_5GS_AUTHENTICATION_REQUEST: testgmm_handle_authentication_request(test_ue, &message.gmm.authentication_request); break; + case OGS_NAS_5GS_AUTHENTICATION_REJECT: + break; case OGS_NAS_5GS_SECURITY_MODE_COMMAND: break; case OGS_NAS_5GS_REGISTRATION_ACCEPT: testgmm_handle_registration_accept(test_ue, &message.gmm.authentication_request); break; + case OGS_NAS_5GS_SERVICE_ACCEPT: + break; case OGS_NAS_5GS_CONFIGURATION_UPDATE_COMMAND: break; case OGS_NAS_5GS_DL_NAS_TRANSPORT: diff --git a/tests/common/nas-security.c b/tests/common/nas-security.c index c825fb78b..c9838ec90 100644 --- a/tests/common/nas-security.c +++ b/tests/common/nas-security.c @@ -88,7 +88,10 @@ ogs_pkbuf_t *test_nas_5gs_security_encode( message->h.extended_protocol_discriminator; h.sequence_number = (test_ue->ul_count & 0xff); - new = ogs_nas_5gs_plain_encode(message); + if (message->gmm.h.message_type == OGS_NAS_5GS_DEREGISTRATION_REQUEST) + new = test_nas_5gs_plain_encode(message); + else + new = ogs_nas_5gs_plain_encode(message); if (!new) { ogs_error("ogs_nas_5gs_plain_encode() failed"); return NULL; diff --git a/tests/common/ngap-build.c b/tests/common/ngap-build.c index 0a427a83a..9059b738f 100644 --- a/tests/common/ngap-build.c +++ b/tests/common/ngap-build.c @@ -19,6 +19,9 @@ #include "test-ngap.h" +static ogs_pkbuf_t *testngap_build_pdu_session_resource_response_trasfer( + test_sess_t *sess); + ogs_pkbuf_t *testngap_build_ng_setup_request(uint32_t gnb_id) { ogs_pkbuf_t *pkbuf = NULL; @@ -93,7 +96,8 @@ ogs_pkbuf_t *testngap_build_ng_setup_request(uint32_t gnb_id) SupportedTAItem = CALLOC(1, sizeof(NGAP_SupportedTAItem_t)); if (test_self()->served_tai[0].list2.num) ogs_asn_uint24_to_OCTET_STRING( - test_self()->served_tai[0].list2.tai[0].tac, &SupportedTAItem->tAC); + test_self()->served_tai[0].list2.tai[0].tac, + &SupportedTAItem->tAC); else if (test_self()->served_tai[0].list0.tai[0].num) ogs_asn_uint24_to_OCTET_STRING( test_self()->served_tai[0].list0.tai[0].tac[0], @@ -136,7 +140,8 @@ ogs_pkbuf_t *testngap_build_ng_setup_request(uint32_t gnb_id) return nga_ngap_encode(&pdu); } -ogs_pkbuf_t *testngap_build_initial_ue_message(ogs_pkbuf_t *gmmbuf) +ogs_pkbuf_t *testngap_build_initial_ue_message( + test_ue_t *test_ue, ogs_pkbuf_t *gmmbuf) { ogs_pkbuf_t *pkbuf = NULL; int i, j; @@ -155,6 +160,9 @@ ogs_pkbuf_t *testngap_build_initial_ue_message(ogs_pkbuf_t *gmmbuf) NGAP_TAI_t *tAI = NULL; NGAP_RRCEstablishmentCause_t *RRCEstablishmentCause = NULL; NGAP_UEContextRequest_t *UEContextRequest = NULL; + NGAP_FiveG_S_TMSI_t *FiveG_S_TMSI = NULL; + + ogs_assert(test_ue); memset(&pdu, 0, sizeof (NGAP_NGAP_PDU_t)); pdu.present = NGAP_NGAP_PDU_PR_initiatingMessage; @@ -207,17 +215,8 @@ ogs_pkbuf_t *testngap_build_initial_ue_message(ogs_pkbuf_t *gmmbuf) RRCEstablishmentCause = &ie->value.choice.RRCEstablishmentCause; - ie = CALLOC(1, sizeof(NGAP_InitialUEMessage_IEs_t)); - ASN_SEQUENCE_ADD(&InitialUEMessage->protocolIEs, ie); - - ie->id = NGAP_ProtocolIE_ID_id_UEContextRequest; - ie->criticality = NGAP_Criticality_ignore; - ie->value.present = - NGAP_InitialUEMessage_IEs__value_PR_UEContextRequest; - - UEContextRequest = &ie->value.choice.UEContextRequest; - - *RAN_UE_NGAP_ID = 1; + test_ue->ran_ue_ngap_id++; + *RAN_UE_NGAP_ID = test_ue->ran_ue_ngap_id; NAS_PDU->size = gmmbuf->len; NAS_PDU->buf = CALLOC(NAS_PDU->size, sizeof(uint8_t)); @@ -240,6 +239,42 @@ ogs_pkbuf_t *testngap_build_initial_ue_message(ogs_pkbuf_t *gmmbuf) *RRCEstablishmentCause = NGAP_RRCEstablishmentCause_mt_Access; + if (test_ue->nas_guti.m_tmsi) { + NGAP_AMFSetID_t *aMFSetID = NULL; + NGAP_AMFPointer_t *aMFPointer = NULL; + NGAP_FiveG_TMSI_t *fiveG_TMSI = NULL; + + ie = CALLOC(1, sizeof(NGAP_InitialUEMessage_IEs_t)); + ASN_SEQUENCE_ADD(&InitialUEMessage->protocolIEs, ie); + + ie->id = NGAP_ProtocolIE_ID_id_FiveG_S_TMSI; + ie->criticality = NGAP_Criticality_ignore; + ie->value.present = + NGAP_InitialUEMessage_IEs__value_PR_FiveG_S_TMSI; + + FiveG_S_TMSI = &ie->value.choice.FiveG_S_TMSI; + + aMFSetID = &FiveG_S_TMSI->aMFSetID; + aMFPointer = &FiveG_S_TMSI->aMFPointer; + fiveG_TMSI = &FiveG_S_TMSI->fiveG_TMSI; + + ogs_ngap_uint16_to_AMFSetID( + ogs_amf_set_id(&test_ue->nas_guti.amf_id), aMFSetID); + ogs_ngap_uint8_to_AMFPointer( + ogs_amf_set_id(&test_ue->nas_guti.amf_id), aMFPointer); + ogs_asn_uint32_to_OCTET_STRING(test_ue->nas_guti.m_tmsi, fiveG_TMSI); + } + + ie = CALLOC(1, sizeof(NGAP_InitialUEMessage_IEs_t)); + ASN_SEQUENCE_ADD(&InitialUEMessage->protocolIEs, ie); + + ie->id = NGAP_ProtocolIE_ID_id_UEContextRequest; + ie->criticality = NGAP_Criticality_ignore; + ie->value.present = + NGAP_InitialUEMessage_IEs__value_PR_UEContextRequest; + + UEContextRequest = &ie->value.choice.UEContextRequest; + *UEContextRequest = NGAP_UEContextRequest_requested; return nga_ngap_encode(&pdu); @@ -341,7 +376,8 @@ ogs_pkbuf_t *testngap_build_uplink_nas_transport( return nga_ngap_encode(&pdu); } -ogs_pkbuf_t *testngap_build_initial_context_setup_response(test_ue_t *test_ue) +ogs_pkbuf_t *testngap_build_initial_context_setup_response( + test_ue_t *test_ue, test_sess_t *sess) { int rv; @@ -390,6 +426,37 @@ ogs_pkbuf_t *testngap_build_initial_context_setup_response(test_ue_t *test_ue) asn_uint642INTEGER(AMF_UE_NGAP_ID, test_ue->amf_ue_ngap_id); *RAN_UE_NGAP_ID = test_ue->ran_ue_ngap_id; + if (sess) { + NGAP_PDUSessionResourceSetupListCxtRes_t *PDUSessionList = NULL; + NGAP_PDUSessionResourceSetupItemCxtRes_t *PDUSessionItem = NULL; + OCTET_STRING_t *transfer = NULL; + ogs_pkbuf_t *n2smbuf = NULL; + + ie = CALLOC(1, sizeof(NGAP_InitialContextSetupResponseIEs_t)); + ASN_SEQUENCE_ADD(&InitialContextSetupResponse->protocolIEs, ie); + + ie->id = NGAP_ProtocolIE_ID_id_PDUSessionResourceSetupListCxtRes; + ie->criticality = NGAP_Criticality_ignore; + ie->value.present = NGAP_InitialContextSetupResponseIEs__value_PR_PDUSessionResourceSetupListCxtRes; + + PDUSessionList = &ie->value.choice.PDUSessionResourceSetupListCxtRes; + + PDUSessionItem = + CALLOC(1, sizeof(struct NGAP_PDUSessionResourceSetupItemCxtRes)); + ASN_SEQUENCE_ADD(&PDUSessionList->list, PDUSessionItem); + + PDUSessionItem->pDUSessionID = sess->psi; + + n2smbuf = testngap_build_pdu_session_resource_response_trasfer(sess); + ogs_assert(n2smbuf); + transfer = &PDUSessionItem->pDUSessionResourceSetupResponseTransfer; + + transfer->size = n2smbuf->len; + transfer->buf = CALLOC(transfer->size, sizeof(uint8_t)); + memcpy(transfer->buf, n2smbuf->data, transfer->size); + ogs_pkbuf_free(n2smbuf); + } + return nga_ngap_encode(&pdu); } @@ -466,7 +533,8 @@ ogs_pkbuf_t *testngap_build_ue_radio_capability_info_indication( { NGAP_NGAP_PDU_t pdu; NGAP_InitiatingMessage_t *initiatingMessage = NULL; - NGAP_UERadioCapabilityInfoIndication_t *UERadioCapabilityInfoIndication = NULL; + NGAP_UERadioCapabilityInfoIndication_t *UERadioCapabilityInfoIndication = + NULL; NGAP_UERadioCapabilityInfoIndicationIEs_t *ie = NULL; NGAP_AMF_UE_NGAP_ID_t *AMF_UE_NGAP_ID = NULL; @@ -517,7 +585,8 @@ ogs_pkbuf_t *testngap_build_ue_radio_capability_info_indication( ie->id = NGAP_ProtocolIE_ID_id_UERadioCapability; ie->criticality = NGAP_Criticality_reject; - ie->value.present = NGAP_UERadioCapabilityInfoIndicationIEs__value_PR_UERadioCapability; + ie->value.present = + NGAP_UERadioCapabilityInfoIndicationIEs__value_PR_UERadioCapability; UERadioCapability = &ie->value.choice.UERadioCapability; @@ -531,45 +600,144 @@ ogs_pkbuf_t *testngap_build_ue_radio_capability_info_indication( return nga_ngap_encode(&pdu); } -static ogs_pkbuf_t *testngap_build_pdu_session_resource_response_trasfer( - test_sess_t *sess) +ogs_pkbuf_t *testngap_build_ue_context_release_request(test_ue_t *test_ue, + NGAP_Cause_PR group, long cause) { - ogs_ip_t gnb_n3_ip; + int rv; + test_sess_t *sess = NULL; - NGAP_PDUSessionResourceSetupResponseTransfer_t message; + NGAP_NGAP_PDU_t pdu; + NGAP_InitiatingMessage_t *initiatingMessage = NULL; + NGAP_UEContextReleaseRequest_t *UEContextReleaseRequest = NULL; - NGAP_QosFlowPerTNLInformation_t *dLQosFlowPerTNLInformation = NULL; + NGAP_UEContextReleaseRequest_IEs_t *ie = NULL; + NGAP_AMF_UE_NGAP_ID_t *AMF_UE_NGAP_ID = NULL; + NGAP_RAN_UE_NGAP_ID_t *RAN_UE_NGAP_ID = NULL; + NGAP_PDUSessionResourceListCxtRelReq_t *PDUSessionList = NULL; + NGAP_PDUSessionResourceItemCxtRelReq_t *PDUSessionItem = NULL; + NGAP_Cause_t *Cause = NULL; - NGAP_UPTransportLayerInformation_t *uPTransportLayerInformation = NULL; - NGAP_GTPTunnel_t *gTPTunnel = NULL; + memset(&pdu, 0, sizeof (NGAP_NGAP_PDU_t)); + pdu.present = NGAP_NGAP_PDU_PR_initiatingMessage; + pdu.choice.initiatingMessage = CALLOC(1, sizeof(NGAP_InitiatingMessage_t)); - NGAP_AssociatedQosFlowList_t *associatedQosFlowList = NULL; - NGAP_AssociatedQosFlowItem_t *associatedQosFlowItem = NULL; + initiatingMessage = pdu.choice.initiatingMessage; + initiatingMessage->procedureCode = + NGAP_ProcedureCode_id_UEContextReleaseRequest; + initiatingMessage->criticality = NGAP_Criticality_ignore; + initiatingMessage->value.present = + NGAP_InitiatingMessage__value_PR_UEContextReleaseRequest; - memset(&message, 0, sizeof(message)); + UEContextReleaseRequest = + &initiatingMessage->value.choice.UEContextReleaseRequest; - dLQosFlowPerTNLInformation = &message.dLQosFlowPerTNLInformation; - uPTransportLayerInformation = - &dLQosFlowPerTNLInformation->uPTransportLayerInformation; + ie = CALLOC(1, sizeof(NGAP_UEContextReleaseRequest_IEs_t)); + ASN_SEQUENCE_ADD(&UEContextReleaseRequest->protocolIEs, ie); - gTPTunnel = CALLOC(1, sizeof(struct NGAP_GTPTunnel)); - uPTransportLayerInformation->present = - NGAP_UPTransportLayerInformation_PR_gTPTunnel; - uPTransportLayerInformation->choice.gTPTunnel = gTPTunnel; + ie->id = NGAP_ProtocolIE_ID_id_AMF_UE_NGAP_ID; + ie->criticality = NGAP_Criticality_reject; + ie->value.present = + NGAP_UEContextReleaseRequest_IEs__value_PR_AMF_UE_NGAP_ID; - ogs_asn_ip_to_BIT_STRING(&sess->gnb_n3_ip, - &gTPTunnel->transportLayerAddress); - ogs_asn_uint32_to_OCTET_STRING(sess->gnb_n3_teid, &gTPTunnel->gTP_TEID); + AMF_UE_NGAP_ID = &ie->value.choice.AMF_UE_NGAP_ID; - associatedQosFlowList = &dLQosFlowPerTNLInformation->associatedQosFlowList; - associatedQosFlowItem = - CALLOC(1, sizeof(struct NGAP_AssociatedQosFlowItem)); - ASN_SEQUENCE_ADD(&associatedQosFlowList->list, associatedQosFlowItem); + ie = CALLOC(1, sizeof(NGAP_UEContextReleaseRequest_IEs_t)); + ASN_SEQUENCE_ADD(&UEContextReleaseRequest->protocolIEs, ie); - associatedQosFlowItem->qosFlowIdentifier = 1; + ie->id = NGAP_ProtocolIE_ID_id_RAN_UE_NGAP_ID; + ie->criticality = NGAP_Criticality_reject; + ie->value.present = + NGAP_UEContextReleaseRequest_IEs__value_PR_RAN_UE_NGAP_ID; - return ogs_asn_encode( - &asn_DEF_NGAP_PDUSessionResourceSetupResponseTransfer, &message); + RAN_UE_NGAP_ID = &ie->value.choice.RAN_UE_NGAP_ID; + + ie = CALLOC(1, sizeof(NGAP_UEContextReleaseRequest_IEs_t)); + ASN_SEQUENCE_ADD(&UEContextReleaseRequest->protocolIEs, ie); + + ie->id = NGAP_ProtocolIE_ID_id_PDUSessionResourceListCxtRelReq; + ie->criticality = NGAP_Criticality_reject; + ie->value.present = + NGAP_UEContextReleaseRequest_IEs__value_PR_PDUSessionResourceListCxtRelReq; + + PDUSessionList = &ie->value.choice.PDUSessionResourceListCxtRelReq; + + ie = CALLOC(1, sizeof(NGAP_UEContextReleaseRequest_IEs_t)); + ASN_SEQUENCE_ADD(&UEContextReleaseRequest->protocolIEs, ie); + + ie->id = NGAP_ProtocolIE_ID_id_Cause; + ie->criticality = NGAP_Criticality_ignore; + ie->value.present = NGAP_UEContextReleaseRequest_IEs__value_PR_Cause; + + Cause = &ie->value.choice.Cause; + + asn_uint642INTEGER(AMF_UE_NGAP_ID, test_ue->amf_ue_ngap_id); + *RAN_UE_NGAP_ID = test_ue->ran_ue_ngap_id; + + PDUSessionItem = + CALLOC(1, sizeof(struct NGAP_PDUSessionResourceSetupItemSURes)); + ASN_SEQUENCE_ADD(&PDUSessionList->list, PDUSessionItem); + + sess = test_ue->sess; + ogs_assert(sess); + + PDUSessionItem->pDUSessionID = sess->psi; + + Cause->present = group; + Cause->choice.radioNetwork = cause; + + return nga_ngap_encode(&pdu); +} + +ogs_pkbuf_t *testngap_build_ue_context_release_complete(test_ue_t *test_ue) +{ + int rv; + + NGAP_NGAP_PDU_t pdu; + NGAP_SuccessfulOutcome_t *successfulOutcome = NULL; + NGAP_UEContextReleaseComplete_t *UEContextReleaseComplete = NULL; + + NGAP_UEContextReleaseComplete_IEs_t *ie = NULL; + NGAP_AMF_UE_NGAP_ID_t *AMF_UE_NGAP_ID = NULL; + NGAP_RAN_UE_NGAP_ID_t *RAN_UE_NGAP_ID = NULL; + + memset(&pdu, 0, sizeof (NGAP_NGAP_PDU_t)); + pdu.present = NGAP_NGAP_PDU_PR_successfulOutcome; + pdu.choice.successfulOutcome = CALLOC(1, sizeof(NGAP_SuccessfulOutcome_t)); + + successfulOutcome = pdu.choice.successfulOutcome; + successfulOutcome->procedureCode = + NGAP_ProcedureCode_id_UEContextRelease; + successfulOutcome->criticality = NGAP_Criticality_reject; + successfulOutcome->value.present = + NGAP_SuccessfulOutcome__value_PR_UEContextReleaseComplete; + + UEContextReleaseComplete = + &successfulOutcome->value.choice.UEContextReleaseComplete; + + ie = CALLOC(1, sizeof(NGAP_UEContextReleaseComplete_IEs_t)); + ASN_SEQUENCE_ADD(&UEContextReleaseComplete->protocolIEs, ie); + + ie->id = NGAP_ProtocolIE_ID_id_AMF_UE_NGAP_ID; + ie->criticality = NGAP_Criticality_ignore; + ie->value.present = + NGAP_UEContextReleaseComplete_IEs__value_PR_AMF_UE_NGAP_ID; + + AMF_UE_NGAP_ID = &ie->value.choice.AMF_UE_NGAP_ID; + + ie = CALLOC(1, sizeof(NGAP_UEContextReleaseComplete_IEs_t)); + ASN_SEQUENCE_ADD(&UEContextReleaseComplete->protocolIEs, ie); + + ie->id = NGAP_ProtocolIE_ID_id_RAN_UE_NGAP_ID; + ie->criticality = NGAP_Criticality_ignore; + ie->value.present = + NGAP_UEContextReleaseComplete_IEs__value_PR_RAN_UE_NGAP_ID; + + RAN_UE_NGAP_ID = &ie->value.choice.RAN_UE_NGAP_ID; + + asn_uint642INTEGER(AMF_UE_NGAP_ID, test_ue->amf_ue_ngap_id); + *RAN_UE_NGAP_ID = test_ue->ran_ue_ngap_id; + + return nga_ngap_encode(&pdu); } ogs_pkbuf_t *testngap_build_pdu_session_resource_setup_response( @@ -658,3 +826,44 @@ ogs_pkbuf_t *testngap_build_pdu_session_resource_setup_response( return nga_ngap_encode(&pdu); } + +static ogs_pkbuf_t *testngap_build_pdu_session_resource_response_trasfer( + test_sess_t *sess) +{ + ogs_ip_t gnb_n3_ip; + + NGAP_PDUSessionResourceSetupResponseTransfer_t message; + + NGAP_QosFlowPerTNLInformation_t *dLQosFlowPerTNLInformation = NULL; + + NGAP_UPTransportLayerInformation_t *uPTransportLayerInformation = NULL; + NGAP_GTPTunnel_t *gTPTunnel = NULL; + + NGAP_AssociatedQosFlowList_t *associatedQosFlowList = NULL; + NGAP_AssociatedQosFlowItem_t *associatedQosFlowItem = NULL; + + memset(&message, 0, sizeof(message)); + + dLQosFlowPerTNLInformation = &message.dLQosFlowPerTNLInformation; + uPTransportLayerInformation = + &dLQosFlowPerTNLInformation->uPTransportLayerInformation; + + gTPTunnel = CALLOC(1, sizeof(struct NGAP_GTPTunnel)); + uPTransportLayerInformation->present = + NGAP_UPTransportLayerInformation_PR_gTPTunnel; + uPTransportLayerInformation->choice.gTPTunnel = gTPTunnel; + + ogs_asn_ip_to_BIT_STRING(&sess->gnb_n3_ip, + &gTPTunnel->transportLayerAddress); + ogs_asn_uint32_to_OCTET_STRING(sess->gnb_n3_teid, &gTPTunnel->gTP_TEID); + + associatedQosFlowList = &dLQosFlowPerTNLInformation->associatedQosFlowList; + associatedQosFlowItem = + CALLOC(1, sizeof(struct NGAP_AssociatedQosFlowItem)); + ASN_SEQUENCE_ADD(&associatedQosFlowList->list, associatedQosFlowItem); + + associatedQosFlowItem->qosFlowIdentifier = 1; + + return ogs_asn_encode( + &asn_DEF_NGAP_PDUSessionResourceSetupResponseTransfer, &message); +} diff --git a/tests/common/ngap-build.h b/tests/common/ngap-build.h index aac955266..14ab86032 100644 --- a/tests/common/ngap-build.h +++ b/tests/common/ngap-build.h @@ -25,17 +25,23 @@ extern "C" { #endif ogs_pkbuf_t *testngap_build_ng_setup_request(uint32_t gnb_id); -ogs_pkbuf_t *testngap_build_initial_ue_message(ogs_pkbuf_t *gmmbuf); +ogs_pkbuf_t *testngap_build_initial_ue_message( + test_ue_t *test_ue, ogs_pkbuf_t *gmmbuf); ogs_pkbuf_t *testngap_build_uplink_nas_transport( test_ue_t *test_ue, ogs_pkbuf_t *gmmbuf); -ogs_pkbuf_t *testngap_build_initial_context_setup_response(test_ue_t *test_ue); +ogs_pkbuf_t *testngap_build_initial_context_setup_response( + test_ue_t *test_ue, test_sess_t *sess); ogs_pkbuf_t *testngap_build_initial_context_setup_failure(test_ue_t *test_ue, NGAP_Cause_PR group, long cause); ogs_pkbuf_t *testngap_build_ue_radio_capability_info_indication( test_ue_t *test_ue); +ogs_pkbuf_t *testngap_build_ue_context_release_request(test_ue_t *test_ue, + NGAP_Cause_PR group, long cause); +ogs_pkbuf_t *testngap_build_ue_context_release_complete(test_ue_t *test_ue); + ogs_pkbuf_t *testngap_build_pdu_session_resource_setup_response( test_sess_t *sess); diff --git a/tests/common/ngap-handler.c b/tests/common/ngap-handler.c index 7b9d15b82..4b168338f 100644 --- a/tests/common/ngap-handler.c +++ b/tests/common/ngap-handler.c @@ -76,7 +76,6 @@ void testngap_handle_downlink_nas_transport( NGAP_InitialContextSetupRequestIEs_t *ie = NULL; NGAP_AMF_UE_NGAP_ID_t *AMF_UE_NGAP_ID = NULL; - NGAP_RAN_UE_NGAP_ID_t *RAN_UE_NGAP_ID = NULL; NGAP_NAS_PDU_t *NAS_PDU = NULL; ogs_assert(test_ue); @@ -91,9 +90,6 @@ void testngap_handle_downlink_nas_transport( for (i = 0; i < InitialContextSetupRequest->protocolIEs.list.count; i++) { ie = InitialContextSetupRequest->protocolIEs.list.array[i]; switch (ie->id) { - case NGAP_ProtocolIE_ID_id_RAN_UE_NGAP_ID: - RAN_UE_NGAP_ID = &ie->value.choice.RAN_UE_NGAP_ID; - break; case NGAP_ProtocolIE_ID_id_AMF_UE_NGAP_ID: AMF_UE_NGAP_ID = &ie->value.choice.AMF_UE_NGAP_ID; break; @@ -105,7 +101,6 @@ void testngap_handle_downlink_nas_transport( } } - test_ue->ran_ue_ngap_id = *RAN_UE_NGAP_ID; asn_INTEGER2ulong(AMF_UE_NGAP_ID, &test_ue->amf_ue_ngap_id); if (NAS_PDU) @@ -123,6 +118,7 @@ void testngap_handle_initial_context_setup_request( NGAP_InitialContextSetupRequest_t *InitialContextSetupRequest = NULL; NGAP_InitialContextSetupRequestIEs_t *ie = NULL; + NGAP_AMF_UE_NGAP_ID_t *AMF_UE_NGAP_ID = NULL; NGAP_NAS_PDU_t *NAS_PDU = NULL; ogs_assert(test_ue); @@ -137,6 +133,9 @@ void testngap_handle_initial_context_setup_request( for (i = 0; i < InitialContextSetupRequest->protocolIEs.list.count; i++) { ie = InitialContextSetupRequest->protocolIEs.list.array[i]; switch (ie->id) { + case NGAP_ProtocolIE_ID_id_AMF_UE_NGAP_ID: + AMF_UE_NGAP_ID = &ie->value.choice.AMF_UE_NGAP_ID; + break; case NGAP_ProtocolIE_ID_id_NAS_PDU: NAS_PDU = &ie->value.choice.NAS_PDU; break; @@ -145,6 +144,12 @@ void testngap_handle_initial_context_setup_request( } } + if (AMF_UE_NGAP_ID) { + uint64_t amf_ue_ngap_id; + asn_INTEGER2ulong(AMF_UE_NGAP_ID, (unsigned long *)&amf_ue_ngap_id); + test_ue->amf_ue_ngap_id = (uint64_t)amf_ue_ngap_id; + } + if (NAS_PDU) testngap_send_to_nas(test_ue, NAS_PDU); } diff --git a/tests/common/ngap-path.c b/tests/common/ngap-path.c index a8c1d09ca..3a2dc5930 100644 --- a/tests/common/ngap-path.c +++ b/tests/common/ngap-path.c @@ -53,6 +53,9 @@ void testngap_recv(test_ue_t *test_ue, ogs_pkbuf_t *pkbuf) case NGAP_ProcedureCode_id_PDUSessionResourceSetup: testngap_handle_pdu_session_resource_setup_request(test_ue, pdu); break; + case NGAP_ProcedureCode_id_UEContextRelease: + /* Nothing */ + break; default: ogs_error("Not implemented(choice:%d, proc:%d)", pdu->present, (int)initiatingMessage->procedureCode); diff --git a/tests/common/test-common.h b/tests/common/test-common.h index 53119ea82..5398bb11a 100644 --- a/tests/common/test-common.h +++ b/tests/common/test-common.h @@ -45,6 +45,7 @@ extern "C" { #include "common/gsm-build.h" #include "common/gsm-handler.h" #include "common/nas-path.h" +#include "common/nas-encoder.h" #include "common/nas-security.h" #undef OGS_TEST_INSIDE diff --git a/tests/meson.build b/tests/meson.build index 95bd6bba4..37eebbb1d 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -29,3 +29,4 @@ subdir('volte') subdir('csfb') subdir('cups') subdir('minimal') +subdir('registration') diff --git a/tests/minimal/minimal-test.c b/tests/minimal/minimal-test.c index 0b53a28fb..c2788503c 100644 --- a/tests/minimal/minimal-test.c +++ b/tests/minimal/minimal-test.c @@ -33,8 +33,7 @@ static void test1_func(abts_case *tc, void *data) int i; int msgindex = 0; - ogs_nas_5gs_mobile_identity_t mobile_identity; - ogs_nas_5gs_mobile_identity_imsi_t mobile_identity_imsi; + ogs_nas_5gs_mobile_identity_suci_t mobile_identity_suci; test_ue_t test_ue; test_sess_t test_sess; @@ -100,26 +99,24 @@ static void test1_func(abts_case *tc, void *data) test_ue.nas.registration.follow_on_request = 1; test_ue.nas.registration.value = 1; /* Initial Registration */ - memset(&mobile_identity_imsi, 0, sizeof(mobile_identity_imsi)); - mobile_identity.length = 12; - mobile_identity.buffer = &mobile_identity_imsi; + memset(&mobile_identity_suci, 0, sizeof(mobile_identity_suci)); - mobile_identity_imsi.h.supi_format = OGS_NAS_5GS_SUPI_FORMAT_IMSI; - mobile_identity_imsi.h.type = OGS_NAS_5GS_MOBILE_IDENTITY_SUCI; - ogs_nas_from_plmn_id(&mobile_identity_imsi.nas_plmn_id, + mobile_identity_suci.h.supi_format = OGS_NAS_5GS_SUPI_FORMAT_IMSI; + mobile_identity_suci.h.type = OGS_NAS_5GS_MOBILE_IDENTITY_SUCI; + ogs_nas_from_plmn_id(&mobile_identity_suci.nas_plmn_id, &test_self()->tai.plmn_id); - mobile_identity_imsi.routing_indicator1 = 0; - mobile_identity_imsi.routing_indicator2 = 0xf; - mobile_identity_imsi.routing_indicator3 = 0xf; - mobile_identity_imsi.routing_indicator4 = 0xf; - mobile_identity_imsi.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME; - mobile_identity_imsi.home_network_pki_value = 0; - mobile_identity_imsi.scheme_output[0] = 0; - mobile_identity_imsi.scheme_output[1] = 0; - mobile_identity_imsi.scheme_output[2] = 0x47; - mobile_identity_imsi.scheme_output[3] = 0x78; + mobile_identity_suci.routing_indicator1 = 0; + mobile_identity_suci.routing_indicator2 = 0xf; + mobile_identity_suci.routing_indicator3 = 0xf; + mobile_identity_suci.routing_indicator4 = 0xf; + mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME; + mobile_identity_suci.home_network_pki_value = 0; + mobile_identity_suci.scheme_output[0] = 0; + mobile_identity_suci.scheme_output[1] = 0; + mobile_identity_suci.scheme_output[2] = 0x47; + mobile_identity_suci.scheme_output[3] = 0x78; - test_ue_set_mobile_identity(&test_ue, &mobile_identity); + test_ue_set_mobile_identity_suci(&test_ue, &mobile_identity_suci, 12); test_ue.nas.access_type = OGS_ACCESS_TYPE_3GPP; test_ue.abba_len = 2; @@ -132,12 +129,13 @@ static void test1_func(abts_case *tc, void *data) test_sess.pdu_session_type = OGS_PDU_SESSION_TYPE_IPV4; test_sess.dnn = (char *)"internet"; + memset(&test_sess.gnb_n3_ip, 0, sizeof(test_sess.gnb_n3_ip)); test_sess.gnb_n3_ip.ipv4 = true; test_sess.gnb_n3_ip.addr = inet_addr("127.0.0.5"); test_sess.gnb_n3_teid = 3; /* gNB connects to AMF */ - ngap = testgnb_ngap_client("127.0.0.1"); + ngap = testgnb_ngap_client("127.0.0.2"); ABTS_PTR_NOTNULL(tc, ngap); /* gNB connects to UPF */ @@ -159,6 +157,16 @@ static void test1_func(abts_case *tc, void *data) collection = mongoc_client_get_collection( ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); ABTS_PTR_NOTNULL(tc, collection); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + ABTS_PTR_NOTNULL(tc, doc); + + count = mongoc_collection_count ( + collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); + if (count) { + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + } + bson_destroy(doc); doc = bson_new_from_json((const uint8_t *)json, -1, &error);; ABTS_PTR_NOTNULL(tc, doc); @@ -175,9 +183,9 @@ static void test1_func(abts_case *tc, void *data) bson_destroy(doc); /* Send Registration request */ - gmmbuf = testgmm_build_registration_request(&test_ue, &mobile_identity); + gmmbuf = testgmm_build_registration_request(&test_ue, false); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_initial_ue_message(gmmbuf); + sendbuf = testngap_build_initial_ue_message(&test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -201,7 +209,7 @@ static void test1_func(abts_case *tc, void *data) testngap_recv(&test_ue, recvbuf); /* Send Security mode complete */ - nasbuf = testgmm_build_registration_request(&test_ue, &mobile_identity); + nasbuf = testgmm_build_registration_request(&test_ue, false); ABTS_PTR_NOTNULL(tc, nasbuf); gmmbuf = testgmm_build_security_mode_complete(&test_ue, nasbuf); ABTS_PTR_NOTNULL(tc, gmmbuf); @@ -222,10 +230,8 @@ static void test1_func(abts_case *tc, void *data) rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); - ogs_msleep(50); - /* Send Initial context setup response */ - sendbuf = testngap_build_initial_context_setup_response(&test_ue); + sendbuf = testngap_build_initial_context_setup_response(&test_ue, NULL); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -265,8 +271,6 @@ static void test1_func(abts_case *tc, void *data) rv = testgnb_gtpu_send(gtpu, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); - ogs_msleep(50); - /* Send PDU session resource setup response */ sendbuf = testngap_build_pdu_session_resource_setup_response(&test_sess); ABTS_PTR_NOTNULL(tc, sendbuf); diff --git a/tests/registration/abts-main.c b/tests/registration/abts-main.c new file mode 100644 index 000000000..bb991a990 --- /dev/null +++ b/tests/registration/abts-main.c @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2019,2020 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "test-5gc.h" + +abts_suite *test_guti(abts_suite *suite); +abts_suite *test_auth(abts_suite *suite); +abts_suite *test_idle(abts_suite *suite); +abts_suite *test_dereg(abts_suite *suite); +abts_suite *test_identity(abts_suite *suite); +abts_suite *test_gmm_status(abts_suite *suite); +abts_suite *test_ue_context(abts_suite *suite); + +const struct testlist { + abts_suite *(*func)(abts_suite *suite); +} alltests[] = { + {test_guti}, + {test_auth}, + {test_idle}, + {test_dereg}, + {test_identity}, + {test_ue_context}, + {NULL}, +}; + +static void terminate(void) +{ + ogs_msleep(50); + + test_child_terminate(); + app_terminate(); + + test_5gc_final(); + ogs_app_terminate(); +} + +static void initialize(const char *const argv[]) +{ + int rv; + + rv = ogs_app_initialize(NULL, argv); + ogs_assert(rv == OGS_OK); + test_5gc_init(); + + rv = app_initialize(argv); + ogs_assert(rv == OGS_OK); +} + +int main(int argc, const char *const argv[]) +{ + int i; + abts_suite *suite = NULL; + + atexit(terminate); + test_5gc_run(argc, argv, "5gc-sample.yaml", initialize); + + for (i = 0; alltests[i].func; i++) + suite = alltests[i].func(suite); + + return abts_report(suite); +} diff --git a/tests/registration/auth-test.c b/tests/registration/auth-test.c new file mode 100644 index 000000000..321e9f6b2 --- /dev/null +++ b/tests/registration/auth-test.c @@ -0,0 +1,265 @@ +/* + * Copyright (C) 2019,2020 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "test-5gc.h" + +static void test1_func(abts_case *tc, void *data) +{ + int rv; + ogs_socknode_t *ngap; + ogs_socknode_t *gtpu; + ogs_pkbuf_t *gmmbuf; + ogs_pkbuf_t *gsmbuf; + ogs_pkbuf_t *nasbuf; + ogs_pkbuf_t *sendbuf; + ogs_pkbuf_t *recvbuf; + ogs_ngap_message_t message; + int i; + int msgindex = 0; + + ogs_nas_5gs_mobile_identity_suci_t mobile_identity_suci; + test_ue_t test_ue; + test_sess_t test_sess; + + uint8_t tmp[OGS_MAX_SDU_LEN]; + + const char *_k_string = "70d49a71dd1a2b806a25abe0ef749f1e"; + uint8_t k[OGS_KEY_LEN]; + const char *_opc_string = "6f1bf53d624b3a43af6592854e2444c7"; + uint8_t opc[OGS_KEY_LEN]; + + mongoc_collection_t *collection = NULL; + bson_t *doc = NULL; + int64_t count = 0; + bson_error_t error; + const char *json = + "{" + "\"_id\" : { \"$oid\" : \"597223158b8861d7605378c6\" }, " + "\"imsi\" : \"901700000021309\"," + "\"ambr\" : { " + "\"uplink\" : { \"$numberLong\" : \"1024000\" }, " + "\"downlink\" : { \"$numberLong\" : \"1024000\" } " + "}," + "\"pdn\" : [" + "{" + "\"apn\" : \"internet\", " + "\"_id\" : { \"$oid\" : \"597223158b8861d7605378c7\" }, " + "\"ambr\" : {" + "\"uplink\" : { \"$numberLong\" : \"1024000\" }, " + "\"downlink\" : { \"$numberLong\" : \"1024000\" } " + "}," + "\"qos\" : { " + "\"qci\" : 9, " + "\"arp\" : { " + "\"priority_level\" : 8," + "\"pre_emption_vulnerability\" : 1, " + "\"pre_emption_capability\" : 1" + "} " + "}, " + "\"type\" : 2" + "}" + "]," + "\"security\" : { " + "\"k\" : \"70d49a71dd1a2b806a25abe0ef749f1e\", " + "\"opc\" : \"6f1bf53d624b3a43af6592854e2444c7\", " + "\"amf\" : \"8000\", " + "\"sqn\" : { \"$numberLong\" : \"25235952177090\" } " + "}, " + "\"subscribed_rau_tau_timer\" : 12," + "\"network_access_mode\" : 2, " + "\"subscriber_status\" : 0, " + "\"access_restriction_data\" : 32, " + "\"__v\" : 0 " + "}"; + + /* Setup Test UE & Session Context */ + memset(&test_ue, 0, sizeof(test_ue)); + memset(&test_sess, 0, sizeof(test_sess)); + test_sess.test_ue = &test_ue; + test_ue.sess = &test_sess; + + test_ue.nas.registration.type = 1; /* TSC[0], KSI[1] */ + test_ue.nas.registration.follow_on_request = 1; + test_ue.nas.registration.value = 1; /* Initial Registration */ + + memset(&mobile_identity_suci, 0, sizeof(mobile_identity_suci)); + + mobile_identity_suci.h.supi_format = OGS_NAS_5GS_SUPI_FORMAT_IMSI; + mobile_identity_suci.h.type = OGS_NAS_5GS_MOBILE_IDENTITY_SUCI; + ogs_nas_from_plmn_id(&mobile_identity_suci.nas_plmn_id, + &test_self()->tai.plmn_id); + mobile_identity_suci.routing_indicator1 = 0; + mobile_identity_suci.routing_indicator2 = 0xf; + mobile_identity_suci.routing_indicator3 = 0xf; + mobile_identity_suci.routing_indicator4 = 0xf; + mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME; + mobile_identity_suci.home_network_pki_value = 0; + mobile_identity_suci.scheme_output[0] = 0; + mobile_identity_suci.scheme_output[1] = 0; + mobile_identity_suci.scheme_output[2] = 0x20; + mobile_identity_suci.scheme_output[3] = 0x31; + mobile_identity_suci.scheme_output[4] = 0x90; + + test_ue_set_mobile_identity_suci(&test_ue, &mobile_identity_suci, 13); + + test_ue.nas.access_type = OGS_ACCESS_TYPE_3GPP; + test_ue.abba_len = 2; + + OGS_HEX(_k_string, strlen(_k_string), test_ue.k); + OGS_HEX(_opc_string, strlen(_opc_string), test_ue.opc); + + test_sess.psi = 1; + test_sess.pti = 1; + test_sess.pdu_session_type = OGS_PDU_SESSION_TYPE_IPV4V6; + test_sess.dnn = (char *)"internet"; + + memset(&test_sess.gnb_n3_ip, 0, sizeof(test_sess.gnb_n3_ip)); + test_sess.gnb_n3_ip.ipv4 = true; + test_sess.gnb_n3_ip.addr = inet_addr("127.0.0.5"); + test_sess.gnb_n3_teid = 0; + + /* gNB connects to AMF */ + ngap = testgnb_ngap_client("127.0.0.2"); + ABTS_PTR_NOTNULL(tc, ngap); + + /* gNB connects to UPF */ + gtpu = testgnb_gtpu_server("127.0.0.5"); + ABTS_PTR_NOTNULL(tc, gtpu); + + /* Send NG-Setup Reqeust */ + sendbuf = testngap_build_ng_setup_request(0x000102); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive NG-Setup Response */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(&test_ue, recvbuf); + + /********** Insert Subscriber in Database */ + collection = mongoc_client_get_collection( + ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); + ABTS_PTR_NOTNULL(tc, collection); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + ABTS_PTR_NOTNULL(tc, doc); + + count = mongoc_collection_count ( + collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); + if (count) { + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + } + bson_destroy(doc); + + doc = bson_new_from_json((const uint8_t *)json, -1, &error);; + ABTS_PTR_NOTNULL(tc, doc); + ABTS_TRUE(tc, mongoc_collection_insert(collection, + MONGOC_INSERT_NONE, doc, NULL, &error)); + bson_destroy(doc); + + doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + ABTS_PTR_NOTNULL(tc, doc); + do { + count = mongoc_collection_count ( + collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); + } while (count == 0); + bson_destroy(doc); + + /* Send Registration request */ + gmmbuf = testgmm_build_registration_request(&test_ue, false); + ABTS_PTR_NOTNULL(tc, gmmbuf); + sendbuf = testngap_build_initial_ue_message(&test_ue, gmmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Authentication request */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(&test_ue, recvbuf); + + /* Send Authentication failure - SYNCH failure */ + gmmbuf = testgmm_build_authentication_failure( + &test_ue, OGS_5GMM_CAUSE_SYNCH_FAILURE); + ABTS_PTR_NOTNULL(tc, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Authentication request */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(&test_ue, recvbuf); + + /* Send Authentication failure - MAC failure */ + gmmbuf = testgmm_build_authentication_failure( + &test_ue, OGS_5GMM_CAUSE_MAC_FAILURE); + ABTS_PTR_NOTNULL(tc, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Authentication reject */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(&test_ue, recvbuf); + + /* Receive UE context release command */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(&test_ue, recvbuf); + + /* Send UE context release complete */ + sendbuf = testngap_build_ue_context_release_complete(&test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + ogs_msleep(50); + + /********** Remove Subscriber in Database */ + doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + ABTS_PTR_NOTNULL(tc, doc); + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + bson_destroy(doc); + + mongoc_collection_destroy(collection); + + /* gNB disonncect from UPF */ + testgnb_gtpu_close(gtpu); + + /* gNB disonncect from AMF */ + testgnb_ngap_close(ngap); + + /* Clear Test UE Context */ + test_ue_remove(&test_ue); +} + +abts_suite *test_auth(abts_suite *suite) +{ + suite = ADD_SUITE(suite) + + abts_run_test(suite, test1_func, NULL); + + return suite; +} diff --git a/tests/registration/dereg-test.c b/tests/registration/dereg-test.c new file mode 100644 index 000000000..cc2e8394b --- /dev/null +++ b/tests/registration/dereg-test.c @@ -0,0 +1,350 @@ +/* + * Copyright (C) 2019,2020 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "test-5gc.h" + +static void test1_func(abts_case *tc, void *data) +{ + int rv; + ogs_socknode_t *ngap; + ogs_socknode_t *gtpu; + ogs_pkbuf_t *gmmbuf; + ogs_pkbuf_t *gsmbuf; + ogs_pkbuf_t *nasbuf; + ogs_pkbuf_t *sendbuf; + ogs_pkbuf_t *recvbuf; + ogs_ngap_message_t message; + int i; + int msgindex = 0; + + ogs_nas_5gs_mobile_identity_suci_t mobile_identity_suci; + test_ue_t test_ue; + test_sess_t test_sess; + + uint8_t tmp[OGS_MAX_SDU_LEN]; + + const char *_k_string = "70d49a71dd1a2b806a25abe0ef749f1e"; + uint8_t k[OGS_KEY_LEN]; + const char *_opc_string = "6f1bf53d624b3a43af6592854e2444c7"; + uint8_t opc[OGS_KEY_LEN]; + + mongoc_collection_t *collection = NULL; + bson_t *doc = NULL; + int64_t count = 0; + bson_error_t error; + const char *json = + "{" + "\"_id\" : { \"$oid\" : \"597223158b8861d7605378c6\" }, " + "\"imsi\" : \"901700000021309\"," + "\"ambr\" : { " + "\"uplink\" : { \"$numberLong\" : \"1024000\" }, " + "\"downlink\" : { \"$numberLong\" : \"1024000\" } " + "}," + "\"pdn\" : [" + "{" + "\"apn\" : \"internet\", " + "\"_id\" : { \"$oid\" : \"597223158b8861d7605378c7\" }, " + "\"ambr\" : {" + "\"uplink\" : { \"$numberLong\" : \"1024000\" }, " + "\"downlink\" : { \"$numberLong\" : \"1024000\" } " + "}," + "\"qos\" : { " + "\"qci\" : 9, " + "\"arp\" : { " + "\"priority_level\" : 8," + "\"pre_emption_vulnerability\" : 1, " + "\"pre_emption_capability\" : 1" + "} " + "}, " + "\"type\" : 2" + "}" + "]," + "\"security\" : { " + "\"k\" : \"70d49a71dd1a2b806a25abe0ef749f1e\", " + "\"opc\" : \"6f1bf53d624b3a43af6592854e2444c7\", " + "\"amf\" : \"8000\", " + "\"sqn\" : { \"$numberLong\" : \"25235952177090\" } " + "}, " + "\"subscribed_rau_tau_timer\" : 12," + "\"network_access_mode\" : 2, " + "\"subscriber_status\" : 0, " + "\"access_restriction_data\" : 32, " + "\"__v\" : 0 " + "}"; + + /* Setup Test UE & Session Context */ + memset(&test_ue, 0, sizeof(test_ue)); + memset(&test_sess, 0, sizeof(test_sess)); + test_sess.test_ue = &test_ue; + test_ue.sess = &test_sess; + + test_ue.nas.registration.type = 1; /* TSC[0], KSI[1] */ + test_ue.nas.registration.follow_on_request = 1; + test_ue.nas.registration.value = 1; /* Initial Registration */ + + memset(&mobile_identity_suci, 0, sizeof(mobile_identity_suci)); + + mobile_identity_suci.h.supi_format = OGS_NAS_5GS_SUPI_FORMAT_IMSI; + mobile_identity_suci.h.type = OGS_NAS_5GS_MOBILE_IDENTITY_SUCI; + ogs_nas_from_plmn_id(&mobile_identity_suci.nas_plmn_id, + &test_self()->tai.plmn_id); + mobile_identity_suci.routing_indicator1 = 0; + mobile_identity_suci.routing_indicator2 = 0xf; + mobile_identity_suci.routing_indicator3 = 0xf; + mobile_identity_suci.routing_indicator4 = 0xf; + mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME; + mobile_identity_suci.home_network_pki_value = 0; + mobile_identity_suci.scheme_output[0] = 0; + mobile_identity_suci.scheme_output[1] = 0; + mobile_identity_suci.scheme_output[2] = 0x20; + mobile_identity_suci.scheme_output[3] = 0x31; + mobile_identity_suci.scheme_output[4] = 0x90; + + test_ue_set_mobile_identity_suci(&test_ue, &mobile_identity_suci, 13); + + test_ue.nas.access_type = OGS_ACCESS_TYPE_3GPP; + test_ue.abba_len = 2; + + OGS_HEX(_k_string, strlen(_k_string), test_ue.k); + OGS_HEX(_opc_string, strlen(_opc_string), test_ue.opc); + + test_sess.psi = 1; + test_sess.pti = 1; + test_sess.pdu_session_type = OGS_PDU_SESSION_TYPE_IPV4V6; + test_sess.dnn = (char *)"internet"; + + memset(&test_sess.gnb_n3_ip, 0, sizeof(test_sess.gnb_n3_ip)); + test_sess.gnb_n3_ip.ipv4 = true; + test_sess.gnb_n3_ip.addr = inet_addr("127.0.0.5"); + test_sess.gnb_n3_teid = 0; + + /* gNB connects to AMF */ + ngap = testgnb_ngap_client("127.0.0.2"); + ABTS_PTR_NOTNULL(tc, ngap); + + /* gNB connects to UPF */ + gtpu = testgnb_gtpu_server("127.0.0.5"); + ABTS_PTR_NOTNULL(tc, gtpu); + + /* Send NG-Setup Reqeust */ + sendbuf = testngap_build_ng_setup_request(0x000102); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive NG-Setup Response */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(&test_ue, recvbuf); + + /********** Insert Subscriber in Database */ + collection = mongoc_client_get_collection( + ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); + ABTS_PTR_NOTNULL(tc, collection); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + ABTS_PTR_NOTNULL(tc, doc); + + count = mongoc_collection_count ( + collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); + if (count) { + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + } + bson_destroy(doc); + + doc = bson_new_from_json((const uint8_t *)json, -1, &error);; + ABTS_PTR_NOTNULL(tc, doc); + ABTS_TRUE(tc, mongoc_collection_insert(collection, + MONGOC_INSERT_NONE, doc, NULL, &error)); + bson_destroy(doc); + + doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + ABTS_PTR_NOTNULL(tc, doc); + do { + count = mongoc_collection_count ( + collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); + } while (count == 0); + bson_destroy(doc); + + /* Send Registration request */ + gmmbuf = testgmm_build_registration_request(&test_ue, false); + ABTS_PTR_NOTNULL(tc, gmmbuf); + sendbuf = testngap_build_initial_ue_message(&test_ue, gmmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Authentication request */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(&test_ue, recvbuf); + + /* Send Authentication response */ + gmmbuf = testgmm_build_authentication_response(&test_ue); + ABTS_PTR_NOTNULL(tc, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Security mode command */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(&test_ue, recvbuf); + + /* Send Security mode complete */ + nasbuf = testgmm_build_registration_request(&test_ue, false); + ABTS_PTR_NOTNULL(tc, nasbuf); + gmmbuf = testgmm_build_security_mode_complete(&test_ue, nasbuf); + ABTS_PTR_NOTNULL(tc, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Initial context setup request */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(&test_ue, recvbuf); + + /* Send UE radio capability info indication */ + sendbuf = testngap_build_ue_radio_capability_info_indication(&test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Initial context setup response */ + sendbuf = testngap_build_initial_context_setup_response(&test_ue, NULL); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + ogs_msleep(50); + + /* Send Registration complete */ + gmmbuf = testgmm_build_registration_complete(&test_ue); + ABTS_PTR_NOTNULL(tc, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Configuration update command */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(&test_ue, recvbuf); + + /* Send PDU session establishment request */ + gsmbuf = testgsm_build_pdu_session_establishment_request(&test_sess); + ABTS_PTR_NOTNULL(tc, gsmbuf); + gmmbuf = testgmm_build_ul_nas_transport(&test_sess, + OGS_NAS_PAYLOAD_CONTAINER_N1_SM_INFORMATION, gsmbuf); + ABTS_PTR_NOTNULL(tc, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive PDU session establishment accept */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(&test_ue, recvbuf); + + /* Send GTP-U ICMP Packet */ + rv = test_gtpu_build_ping(&sendbuf, &test_sess, "10.45.0.1"); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + rv = testgnb_gtpu_send(gtpu, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + ogs_msleep(50); + + /* Send PDU session resource setup response */ + sendbuf = testngap_build_pdu_session_resource_setup_response(&test_sess); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + ogs_msleep(50); + + /* Receive GTP-U ICMP Packet */ + recvbuf = testgnb_gtpu_read(gtpu); + ABTS_PTR_NOTNULL(tc, recvbuf); + ogs_pkbuf_free(recvbuf); + + /* Send GTP-U ICMP Packet */ + rv = test_gtpu_build_ping(&sendbuf, &test_sess, "10.45.0.1"); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + rv = testgnb_gtpu_send(gtpu, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive GTP-U ICMP Packet */ + recvbuf = testgnb_gtpu_read(gtpu); + ABTS_PTR_NOTNULL(tc, recvbuf); + ogs_pkbuf_free(recvbuf); + + ogs_msleep(50); + + /* Send De-registration request */ + gmmbuf = testgmm_build_de_registration_request(&test_ue, 1); + ABTS_PTR_NOTNULL(tc, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive UE context release command */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(&test_ue, recvbuf); + + /* Send UE context release complete */ + sendbuf = testngap_build_ue_context_release_complete(&test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + ogs_msleep(50); + + /********** Remove Subscriber in Database */ + doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + ABTS_PTR_NOTNULL(tc, doc); + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + bson_destroy(doc); + + mongoc_collection_destroy(collection); + + /* gNB disonncect from UPF */ + testgnb_gtpu_close(gtpu); + + /* gNB disonncect from AMF */ + testgnb_ngap_close(ngap); + + /* Clear Test UE Context */ + test_ue_remove(&test_ue); +} + +abts_suite *test_dereg(abts_suite *suite) +{ + suite = ADD_SUITE(suite) + + abts_run_test(suite, test1_func, NULL); + + return suite; +} diff --git a/tests/registration/gmm-status-test.c b/tests/registration/gmm-status-test.c new file mode 100644 index 000000000..d234765cc --- /dev/null +++ b/tests/registration/gmm-status-test.c @@ -0,0 +1,309 @@ +/* + * Copyright (C) 2019,2020 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "test-5gc.h" + +static void test1_func(abts_case *tc, void *data) +{ + int rv; + ogs_socknode_t *ngap; + ogs_socknode_t *gtpu; + ogs_pkbuf_t *gmmbuf; + ogs_pkbuf_t *gsmbuf; + ogs_pkbuf_t *nasbuf; + ogs_pkbuf_t *sendbuf; + ogs_pkbuf_t *recvbuf; + ogs_ngap_message_t message; + int i; + int msgindex = 0; + + ogs_nas_5gs_mobile_identity_suci_t mobile_identity_suci; + test_ue_t test_ue; + test_sess_t test_sess; + + uint8_t tmp[OGS_MAX_SDU_LEN]; + + const char *_k_string = "70d49a71dd1a2b806a25abe0ef749f1e"; + uint8_t k[OGS_KEY_LEN]; + const char *_opc_string = "6f1bf53d624b3a43af6592854e2444c7"; + uint8_t opc[OGS_KEY_LEN]; + + mongoc_collection_t *collection = NULL; + bson_t *doc = NULL; + int64_t count = 0; + bson_error_t error; + const char *json = + "{" + "\"_id\" : { \"$oid\" : \"597223158b8861d7605378c6\" }, " + "\"imsi\" : \"901700000021309\"," + "\"ambr\" : { " + "\"uplink\" : { \"$numberLong\" : \"1024000\" }, " + "\"downlink\" : { \"$numberLong\" : \"1024000\" } " + "}," + "\"pdn\" : [" + "{" + "\"apn\" : \"internet\", " + "\"_id\" : { \"$oid\" : \"597223158b8861d7605378c7\" }, " + "\"ambr\" : {" + "\"uplink\" : { \"$numberLong\" : \"1024000\" }, " + "\"downlink\" : { \"$numberLong\" : \"1024000\" } " + "}," + "\"qos\" : { " + "\"qci\" : 9, " + "\"arp\" : { " + "\"priority_level\" : 8," + "\"pre_emption_vulnerability\" : 1, " + "\"pre_emption_capability\" : 1" + "} " + "}, " + "\"type\" : 2" + "}" + "]," + "\"security\" : { " + "\"k\" : \"70d49a71dd1a2b806a25abe0ef749f1e\", " + "\"opc\" : \"6f1bf53d624b3a43af6592854e2444c7\", " + "\"amf\" : \"8000\", " + "\"sqn\" : { \"$numberLong\" : \"25235952177090\" } " + "}, " + "\"subscribed_rau_tau_timer\" : 12," + "\"network_access_mode\" : 2, " + "\"subscriber_status\" : 0, " + "\"access_restriction_data\" : 32, " + "\"__v\" : 0 " + "}"; + + /* Setup Test UE & Session Context */ + memset(&test_ue, 0, sizeof(test_ue)); + memset(&test_sess, 0, sizeof(test_sess)); + test_sess.test_ue = &test_ue; + test_ue.sess = &test_sess; + + test_ue.nas.registration.type = 1; /* TSC[0], KSI[1] */ + test_ue.nas.registration.follow_on_request = 1; + test_ue.nas.registration.value = OGS_NAS_5GS_REGISTRATION_TYPE_INITIAL; + + memset(&mobile_identity_suci, 0, sizeof(mobile_identity_suci)); + + mobile_identity_suci.h.supi_format = OGS_NAS_5GS_SUPI_FORMAT_IMSI; + mobile_identity_suci.h.type = OGS_NAS_5GS_MOBILE_IDENTITY_SUCI; + ogs_nas_from_plmn_id(&mobile_identity_suci.nas_plmn_id, + &test_self()->tai.plmn_id); + mobile_identity_suci.routing_indicator1 = 0; + mobile_identity_suci.routing_indicator2 = 0xf; + mobile_identity_suci.routing_indicator3 = 0xf; + mobile_identity_suci.routing_indicator4 = 0xf; + mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME; + mobile_identity_suci.home_network_pki_value = 0; + mobile_identity_suci.scheme_output[0] = 0; + mobile_identity_suci.scheme_output[1] = 0; + mobile_identity_suci.scheme_output[2] = 0x20; + mobile_identity_suci.scheme_output[3] = 0x31; + mobile_identity_suci.scheme_output[4] = 0x90; + + test_ue_set_mobile_identity_suci(&test_ue, &mobile_identity_suci, 13); + + test_ue.nas.access_type = OGS_ACCESS_TYPE_3GPP; + test_ue.abba_len = 2; + + OGS_HEX(_k_string, strlen(_k_string), test_ue.k); + OGS_HEX(_opc_string, strlen(_opc_string), test_ue.opc); + + test_sess.psi = 1; + test_sess.pti = 1; + test_sess.pdu_session_type = OGS_PDU_SESSION_TYPE_IPV4V6; + test_sess.dnn = (char *)"internet"; + + memset(&test_sess.gnb_n3_ip, 0, sizeof(test_sess.gnb_n3_ip)); + test_sess.gnb_n3_ip.ipv4 = true; + test_sess.gnb_n3_ip.addr = inet_addr("127.0.0.5"); + test_sess.gnb_n3_teid = 0; + + /* gNB connects to AMF */ + ngap = testgnb_ngap_client("127.0.0.2"); + ABTS_PTR_NOTNULL(tc, ngap); + + /* gNB connects to UPF */ + gtpu = testgnb_gtpu_server("127.0.0.5"); + ABTS_PTR_NOTNULL(tc, gtpu); + + /* Send NG-Setup Reqeust */ + sendbuf = testngap_build_ng_setup_request(0x000102); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive NG-Setup Response */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(&test_ue, recvbuf); + + /********** Insert Subscriber in Database */ + collection = mongoc_client_get_collection( + ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); + ABTS_PTR_NOTNULL(tc, collection); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + ABTS_PTR_NOTNULL(tc, doc); + + count = mongoc_collection_count ( + collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); + if (count) { + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + } + bson_destroy(doc); + + doc = bson_new_from_json((const uint8_t *)json, -1, &error);; + ABTS_PTR_NOTNULL(tc, doc); + ABTS_TRUE(tc, mongoc_collection_insert(collection, + MONGOC_INSERT_NONE, doc, NULL, &error)); + bson_destroy(doc); + + doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + ABTS_PTR_NOTNULL(tc, doc); + do { + count = mongoc_collection_count ( + collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); + } while (count == 0); + bson_destroy(doc); + + /* Send Registration request */ + gmmbuf = testgmm_build_registration_request(&test_ue, false); + ABTS_PTR_NOTNULL(tc, gmmbuf); + sendbuf = testngap_build_initial_ue_message(&test_ue, gmmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Authentication request */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(&test_ue, recvbuf); + + /* Send Authentication response */ + gmmbuf = testgmm_build_authentication_response(&test_ue); + ABTS_PTR_NOTNULL(tc, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Security mode command */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(&test_ue, recvbuf); + + /* Send Security mode complete */ + nasbuf = testgmm_build_registration_request(&test_ue, false); + ABTS_PTR_NOTNULL(tc, nasbuf); + gmmbuf = testgmm_build_security_mode_complete(&test_ue, nasbuf); + ABTS_PTR_NOTNULL(tc, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Initial context setup request */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(&test_ue, recvbuf); + + /* Send Initial context setup response */ + sendbuf = testngap_build_initial_context_setup_response(&test_ue, NULL); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Registration complete */ + gmmbuf = testgmm_build_registration_complete(&test_ue); + ABTS_PTR_NOTNULL(tc, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Configuration update command */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(&test_ue, recvbuf); + + /* Send PDU session establishment request */ + gsmbuf = testgsm_build_pdu_session_establishment_request(&test_sess); + ABTS_PTR_NOTNULL(tc, gsmbuf); + gmmbuf = testgmm_build_ul_nas_transport(&test_sess, + OGS_NAS_PAYLOAD_CONTAINER_N1_SM_INFORMATION, gsmbuf); + ABTS_PTR_NOTNULL(tc, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive PDU session establishment accept */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(&test_ue, recvbuf); + + /* Send GMM Status */ + gmmbuf = testgmm_build_gmm_status(&test_ue, + OGS_5GMM_CAUSE_MESSAGE_NOT_COMPATIBLE_WITH_THE_PROTOCOL_STATE); + ABTS_PTR_NOTNULL(tc, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive UE context release command */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(&test_ue, recvbuf); + + /* Send UE context release complete */ + sendbuf = testngap_build_ue_context_release_complete(&test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + ogs_msleep(50); + + /********** Remove Subscriber in Database */ + doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + ABTS_PTR_NOTNULL(tc, doc); + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + bson_destroy(doc); + + mongoc_collection_destroy(collection); + + /* gNB disonncect from UPF */ + testgnb_gtpu_close(gtpu); + + /* gNB disonncect from AMF */ + testgnb_ngap_close(ngap); + + /* Clear Test UE Context */ + test_ue_remove(&test_ue); +} + +abts_suite *test_gmm_status(abts_suite *suite) +{ + suite = ADD_SUITE(suite) + + abts_run_test(suite, test1_func, NULL); + + return suite; +} diff --git a/tests/registration/guti-test.c b/tests/registration/guti-test.c new file mode 100644 index 000000000..3e2fd3b68 --- /dev/null +++ b/tests/registration/guti-test.c @@ -0,0 +1,485 @@ +/* + * Copyright (C) 2019,2020 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "test-5gc.h" + +static void test1_func(abts_case *tc, void *data) +{ + int rv; + ogs_socknode_t *ngap; + ogs_socknode_t *gtpu; + ogs_pkbuf_t *gmmbuf; + ogs_pkbuf_t *gsmbuf; + ogs_pkbuf_t *nasbuf; + ogs_pkbuf_t *sendbuf; + ogs_pkbuf_t *recvbuf; + ogs_ngap_message_t message; + int i; + int msgindex = 0; + + ogs_nas_5gs_mobile_identity_suci_t mobile_identity_suci; + test_ue_t test_ue; + test_sess_t test_sess; + + uint8_t tmp[OGS_MAX_SDU_LEN]; + + const char *_k_string = "70d49a71dd1a2b806a25abe0ef749f1e"; + uint8_t k[OGS_KEY_LEN]; + const char *_opc_string = "6f1bf53d624b3a43af6592854e2444c7"; + uint8_t opc[OGS_KEY_LEN]; + + mongoc_collection_t *collection = NULL; + bson_t *doc = NULL; + int64_t count = 0; + bson_error_t error; + const char *json = + "{" + "\"_id\" : { \"$oid\" : \"597223158b8861d7605378c6\" }, " + "\"imsi\" : \"901700000021309\"," + "\"ambr\" : { " + "\"uplink\" : { \"$numberLong\" : \"1024000\" }, " + "\"downlink\" : { \"$numberLong\" : \"1024000\" } " + "}," + "\"pdn\" : [" + "{" + "\"apn\" : \"internet\", " + "\"_id\" : { \"$oid\" : \"597223158b8861d7605378c7\" }, " + "\"ambr\" : {" + "\"uplink\" : { \"$numberLong\" : \"1024000\" }, " + "\"downlink\" : { \"$numberLong\" : \"1024000\" } " + "}," + "\"qos\" : { " + "\"qci\" : 9, " + "\"arp\" : { " + "\"priority_level\" : 8," + "\"pre_emption_vulnerability\" : 1, " + "\"pre_emption_capability\" : 1" + "} " + "}, " + "\"type\" : 2" + "}" + "]," + "\"security\" : { " + "\"k\" : \"70d49a71dd1a2b806a25abe0ef749f1e\", " + "\"opc\" : \"6f1bf53d624b3a43af6592854e2444c7\", " + "\"amf\" : \"8000\", " + "\"sqn\" : { \"$numberLong\" : \"25235952177090\" } " + "}, " + "\"subscribed_rau_tau_timer\" : 12," + "\"network_access_mode\" : 2, " + "\"subscriber_status\" : 0, " + "\"access_restriction_data\" : 32, " + "\"__v\" : 0 " + "}"; + + /* Setup Test UE & Session Context */ + memset(&test_ue, 0, sizeof(test_ue)); + memset(&test_sess, 0, sizeof(test_sess)); + test_sess.test_ue = &test_ue; + test_ue.sess = &test_sess; + + test_ue.nas.registration.type = 1; /* TSC[0], KSI[1] */ + test_ue.nas.registration.follow_on_request = 1; + test_ue.nas.registration.value = OGS_NAS_5GS_REGISTRATION_TYPE_INITIAL; + + memset(&mobile_identity_suci, 0, sizeof(mobile_identity_suci)); + + mobile_identity_suci.h.supi_format = OGS_NAS_5GS_SUPI_FORMAT_IMSI; + mobile_identity_suci.h.type = OGS_NAS_5GS_MOBILE_IDENTITY_SUCI; + ogs_nas_from_plmn_id(&mobile_identity_suci.nas_plmn_id, + &test_self()->tai.plmn_id); + mobile_identity_suci.routing_indicator1 = 0; + mobile_identity_suci.routing_indicator2 = 0xf; + mobile_identity_suci.routing_indicator3 = 0xf; + mobile_identity_suci.routing_indicator4 = 0xf; + mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME; + mobile_identity_suci.home_network_pki_value = 0; + mobile_identity_suci.scheme_output[0] = 0; + mobile_identity_suci.scheme_output[1] = 0; + mobile_identity_suci.scheme_output[2] = 0x20; + mobile_identity_suci.scheme_output[3] = 0x31; + mobile_identity_suci.scheme_output[4] = 0x90; + + test_ue_set_mobile_identity_suci(&test_ue, &mobile_identity_suci, 13); + + test_ue.nas.access_type = OGS_ACCESS_TYPE_3GPP; + test_ue.abba_len = 2; + + OGS_HEX(_k_string, strlen(_k_string), test_ue.k); + OGS_HEX(_opc_string, strlen(_opc_string), test_ue.opc); + + test_sess.psi = 1; + test_sess.pti = 1; + test_sess.pdu_session_type = OGS_PDU_SESSION_TYPE_IPV4V6; + test_sess.dnn = (char *)"internet"; + + memset(&test_sess.gnb_n3_ip, 0, sizeof(test_sess.gnb_n3_ip)); + test_sess.gnb_n3_ip.ipv4 = true; + test_sess.gnb_n3_ip.addr = inet_addr("127.0.0.5"); + test_sess.gnb_n3_teid = 0; + + /* gNB connects to AMF */ + ngap = testgnb_ngap_client("127.0.0.2"); + ABTS_PTR_NOTNULL(tc, ngap); + + /* gNB connects to UPF */ + gtpu = testgnb_gtpu_server("127.0.0.5"); + ABTS_PTR_NOTNULL(tc, gtpu); + + /* Send NG-Setup Reqeust */ + sendbuf = testngap_build_ng_setup_request(0x000102); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive NG-Setup Response */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(&test_ue, recvbuf); + + /********** Insert Subscriber in Database */ + collection = mongoc_client_get_collection( + ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); + ABTS_PTR_NOTNULL(tc, collection); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + ABTS_PTR_NOTNULL(tc, doc); + + count = mongoc_collection_count ( + collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); + if (count) { + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + } + bson_destroy(doc); + + doc = bson_new_from_json((const uint8_t *)json, -1, &error);; + ABTS_PTR_NOTNULL(tc, doc); + ABTS_TRUE(tc, mongoc_collection_insert(collection, + MONGOC_INSERT_NONE, doc, NULL, &error)); + bson_destroy(doc); + + doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + ABTS_PTR_NOTNULL(tc, doc); + do { + count = mongoc_collection_count ( + collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); + } while (count == 0); + bson_destroy(doc); + + /* Send Registration request */ + gmmbuf = testgmm_build_registration_request(&test_ue, false); + ABTS_PTR_NOTNULL(tc, gmmbuf); + sendbuf = testngap_build_initial_ue_message(&test_ue, gmmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Authentication request */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(&test_ue, recvbuf); + + /* Send Authentication response */ + gmmbuf = testgmm_build_authentication_response(&test_ue); + ABTS_PTR_NOTNULL(tc, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Security mode command */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(&test_ue, recvbuf); + + /* Send Security mode complete */ + nasbuf = testgmm_build_registration_request(&test_ue, false); + ABTS_PTR_NOTNULL(tc, nasbuf); + gmmbuf = testgmm_build_security_mode_complete(&test_ue, nasbuf); + ABTS_PTR_NOTNULL(tc, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Initial context setup request */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(&test_ue, recvbuf); + + /* Send UE radio capability info indication */ + sendbuf = testngap_build_ue_radio_capability_info_indication(&test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Initial context setup response */ + sendbuf = testngap_build_initial_context_setup_response(&test_ue, NULL); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + ogs_msleep(50); + + /* Send Registration complete */ + gmmbuf = testgmm_build_registration_complete(&test_ue); + ABTS_PTR_NOTNULL(tc, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Configuration update command */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(&test_ue, recvbuf); + + /* Send PDU session establishment request */ + gsmbuf = testgsm_build_pdu_session_establishment_request(&test_sess); + ABTS_PTR_NOTNULL(tc, gsmbuf); + gmmbuf = testgmm_build_ul_nas_transport(&test_sess, + OGS_NAS_PAYLOAD_CONTAINER_N1_SM_INFORMATION, gsmbuf); + ABTS_PTR_NOTNULL(tc, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive PDU session establishment accept */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(&test_ue, recvbuf); + + /* Send GTP-U ICMP Packet */ + rv = test_gtpu_build_ping(&sendbuf, &test_sess, "10.45.0.1"); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + rv = testgnb_gtpu_send(gtpu, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + ogs_msleep(50); + + /* Send PDU session resource setup response */ + sendbuf = testngap_build_pdu_session_resource_setup_response(&test_sess); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive GTP-U ICMP Packet */ + recvbuf = testgnb_gtpu_read(gtpu); + ABTS_PTR_NOTNULL(tc, recvbuf); + ogs_pkbuf_free(recvbuf); + + /* Send GTP-U ICMP Packet */ + rv = test_gtpu_build_ping(&sendbuf, &test_sess, "10.45.0.1"); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + rv = testgnb_gtpu_send(gtpu, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive GTP-U ICMP Packet */ + recvbuf = testgnb_gtpu_read(gtpu); + ABTS_PTR_NOTNULL(tc, recvbuf); + ogs_pkbuf_free(recvbuf); + + /* Update Registration request type */ + test_ue.nas.registration.value = + OGS_NAS_5GS_REGISTRATION_TYPE_MOBILITY_UPDATING; + + ogs_msleep(50); + + /* Send Registration request */ + gmmbuf = testgmm_build_registration_request(&test_ue, true); + ABTS_PTR_NOTNULL(tc, gmmbuf); + sendbuf = testngap_build_initial_ue_message(&test_ue, gmmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Initial context setup request */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(&test_ue, recvbuf); + + /* Send Initial context setup response */ + sendbuf = testngap_build_initial_context_setup_response( + &test_ue, &test_sess); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + ogs_msleep(50); + + /* Send GTP-U ICMP Packet */ + rv = test_gtpu_build_ping(&sendbuf, &test_sess, "10.45.0.1"); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + rv = testgnb_gtpu_send(gtpu, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive GTP-U ICMP Packet */ + recvbuf = testgnb_gtpu_read(gtpu); + ABTS_PTR_NOTNULL(tc, recvbuf); + ogs_pkbuf_free(recvbuf); + + ogs_msleep(50); + + /* Update Registration request type */ + test_ue.nas.registration.value = + OGS_NAS_5GS_REGISTRATION_TYPE_PERIODIC_UPDATING; + + /* Send Registration request - INVALID_GUTI */ + test_ue.nas_guti.m_tmsi = 0x1234; + gmmbuf = testgmm_build_registration_request(&test_ue, true); + ABTS_PTR_NOTNULL(tc, gmmbuf); + sendbuf = testngap_build_initial_ue_message(&test_ue, gmmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Identity request */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(&test_ue, recvbuf); + + /* Send Identity response */ + gmmbuf = testgmm_build_identity_response(&test_ue); + ABTS_PTR_NOTNULL(tc, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Authentication request */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(&test_ue, recvbuf); + + /* Send Authentication response */ + gmmbuf = testgmm_build_authentication_response(&test_ue); + ABTS_PTR_NOTNULL(tc, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Security mode command */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(&test_ue, recvbuf); + + /* Send Security mode complete */ + nasbuf = testgmm_build_registration_request(&test_ue, false); + ABTS_PTR_NOTNULL(tc, nasbuf); + gmmbuf = testgmm_build_security_mode_complete(&test_ue, nasbuf); + ABTS_PTR_NOTNULL(tc, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Initial context setup request */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(&test_ue, recvbuf); + + /* Send Initial context setup response */ + sendbuf = testngap_build_initial_context_setup_response(&test_ue, NULL); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + ogs_msleep(50); + + /* Send Registration complete */ + gmmbuf = testgmm_build_registration_complete(&test_ue); + ABTS_PTR_NOTNULL(tc, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Configuration update command */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(&test_ue, recvbuf); + + /* Send PDU session establishment request */ + gsmbuf = testgsm_build_pdu_session_establishment_request(&test_sess); + ABTS_PTR_NOTNULL(tc, gsmbuf); + gmmbuf = testgmm_build_ul_nas_transport(&test_sess, + OGS_NAS_PAYLOAD_CONTAINER_N1_SM_INFORMATION, gsmbuf); + ABTS_PTR_NOTNULL(tc, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive PDU session establishment accept */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(&test_ue, recvbuf); + + ogs_msleep(50); + + /* Send PDU session resource setup response */ + sendbuf = testngap_build_pdu_session_resource_setup_response(&test_sess); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + ogs_msleep(50); + + /* Send GTP-U ICMP Packet */ + rv = test_gtpu_build_ping(&sendbuf, &test_sess, "10.45.0.1"); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + rv = testgnb_gtpu_send(gtpu, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive GTP-U ICMP Packet */ + recvbuf = testgnb_gtpu_read(gtpu); + ABTS_PTR_NOTNULL(tc, recvbuf); + ogs_pkbuf_free(recvbuf); + + ogs_msleep(50); + + /********** Remove Subscriber in Database */ + doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + ABTS_PTR_NOTNULL(tc, doc); + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + bson_destroy(doc); + + mongoc_collection_destroy(collection); + + /* gNB disonncect from UPF */ + testgnb_gtpu_close(gtpu); + + /* gNB disonncect from AMF */ + testgnb_ngap_close(ngap); + + /* Clear Test UE Context */ + test_ue_remove(&test_ue); +} + +abts_suite *test_guti(abts_suite *suite) +{ + suite = ADD_SUITE(suite) + + abts_run_test(suite, test1_func, NULL); + + return suite; +} diff --git a/tests/registration/identity-test.c b/tests/registration/identity-test.c new file mode 100644 index 000000000..6faa1b92e --- /dev/null +++ b/tests/registration/identity-test.c @@ -0,0 +1,394 @@ +/* + * Copyright (C) 2019,2020 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "test-5gc.h" + +static void test1_func(abts_case *tc, void *data) +{ + int rv; + ogs_socknode_t *ngap; + ogs_socknode_t *gtpu; + ogs_pkbuf_t *gmmbuf; + ogs_pkbuf_t *gsmbuf; + ogs_pkbuf_t *nasbuf; + ogs_pkbuf_t *sendbuf; + ogs_pkbuf_t *recvbuf; + ogs_ngap_message_t message; + int i; + int msgindex = 0; + + ogs_nas_5gs_mobile_identity_suci_t mobile_identity_suci; + test_ue_t test_ue; + test_sess_t test_sess; + + uint8_t tmp[OGS_MAX_SDU_LEN]; + + const char *_k_string = "70d49a71dd1a2b806a25abe0ef749f1e"; + uint8_t k[OGS_KEY_LEN]; + const char *_opc_string = "6f1bf53d624b3a43af6592854e2444c7"; + uint8_t opc[OGS_KEY_LEN]; + + mongoc_collection_t *collection = NULL; + bson_t *doc = NULL; + int64_t count = 0; + bson_error_t error; + const char *json = + "{" + "\"_id\" : { \"$oid\" : \"597223158b8861d7605378c6\" }, " + "\"imsi\" : \"901700000021309\"," + "\"ambr\" : { " + "\"uplink\" : { \"$numberLong\" : \"1024000\" }, " + "\"downlink\" : { \"$numberLong\" : \"1024000\" } " + "}," + "\"pdn\" : [" + "{" + "\"apn\" : \"internet\", " + "\"_id\" : { \"$oid\" : \"597223158b8861d7605378c7\" }, " + "\"ambr\" : {" + "\"uplink\" : { \"$numberLong\" : \"1024000\" }, " + "\"downlink\" : { \"$numberLong\" : \"1024000\" } " + "}," + "\"qos\" : { " + "\"qci\" : 9, " + "\"arp\" : { " + "\"priority_level\" : 8," + "\"pre_emption_vulnerability\" : 1, " + "\"pre_emption_capability\" : 1" + "} " + "}, " + "\"type\" : 2" + "}" + "]," + "\"security\" : { " + "\"k\" : \"70d49a71dd1a2b806a25abe0ef749f1e\", " + "\"opc\" : \"6f1bf53d624b3a43af6592854e2444c7\", " + "\"amf\" : \"8000\", " + "\"sqn\" : { \"$numberLong\" : \"25235952177090\" } " + "}, " + "\"subscribed_rau_tau_timer\" : 12," + "\"network_access_mode\" : 2, " + "\"subscriber_status\" : 0, " + "\"access_restriction_data\" : 32, " + "\"__v\" : 0 " + "}"; + + /* Setup Test UE & Session Context */ + memset(&test_ue, 0, sizeof(test_ue)); + memset(&test_sess, 0, sizeof(test_sess)); + test_sess.test_ue = &test_ue; + test_ue.sess = &test_sess; + + test_ue.nas.registration.type = 1; /* TSC[0], KSI[1] */ + test_ue.nas.registration.follow_on_request = 1; + test_ue.nas.registration.value = OGS_NAS_5GS_REGISTRATION_TYPE_INITIAL; + + memset(&mobile_identity_suci, 0, sizeof(mobile_identity_suci)); + + mobile_identity_suci.h.supi_format = OGS_NAS_5GS_SUPI_FORMAT_IMSI; + mobile_identity_suci.h.type = OGS_NAS_5GS_MOBILE_IDENTITY_SUCI; + ogs_nas_from_plmn_id(&mobile_identity_suci.nas_plmn_id, + &test_self()->tai.plmn_id); + mobile_identity_suci.routing_indicator1 = 0; + mobile_identity_suci.routing_indicator2 = 0xf; + mobile_identity_suci.routing_indicator3 = 0xf; + mobile_identity_suci.routing_indicator4 = 0xf; + mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME; + mobile_identity_suci.home_network_pki_value = 0; + mobile_identity_suci.scheme_output[0] = 0; + mobile_identity_suci.scheme_output[1] = 0; + mobile_identity_suci.scheme_output[2] = 0x20; + mobile_identity_suci.scheme_output[3] = 0x31; + mobile_identity_suci.scheme_output[4] = 0x90; + + test_ue_set_mobile_identity_suci(&test_ue, &mobile_identity_suci, 13); + + test_ue.nas.access_type = OGS_ACCESS_TYPE_3GPP; + test_ue.abba_len = 2; + + OGS_HEX(_k_string, strlen(_k_string), test_ue.k); + OGS_HEX(_opc_string, strlen(_opc_string), test_ue.opc); + + test_sess.psi = 1; + test_sess.pti = 1; + test_sess.pdu_session_type = OGS_PDU_SESSION_TYPE_IPV4V6; + test_sess.dnn = (char *)"internet"; + + memset(&test_sess.gnb_n3_ip, 0, sizeof(test_sess.gnb_n3_ip)); + test_sess.gnb_n3_ip.ipv4 = true; + test_sess.gnb_n3_ip.addr = inet_addr("127.0.0.5"); + test_sess.gnb_n3_teid = 0; + + /* gNB connects to AMF */ + ngap = testgnb_ngap_client("127.0.0.2"); + ABTS_PTR_NOTNULL(tc, ngap); + + /* gNB connects to UPF */ + gtpu = testgnb_gtpu_server("127.0.0.5"); + ABTS_PTR_NOTNULL(tc, gtpu); + + /* Send NG-Setup Reqeust */ + sendbuf = testngap_build_ng_setup_request(0x000102); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive NG-Setup Response */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(&test_ue, recvbuf); + + /********** Insert Subscriber in Database */ + collection = mongoc_client_get_collection( + ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); + ABTS_PTR_NOTNULL(tc, collection); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + ABTS_PTR_NOTNULL(tc, doc); + + count = mongoc_collection_count ( + collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); + if (count) { + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + } + bson_destroy(doc); + + doc = bson_new_from_json((const uint8_t *)json, -1, &error);; + ABTS_PTR_NOTNULL(tc, doc); + ABTS_TRUE(tc, mongoc_collection_insert(collection, + MONGOC_INSERT_NONE, doc, NULL, &error)); + bson_destroy(doc); + + doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + ABTS_PTR_NOTNULL(tc, doc); + do { + count = mongoc_collection_count ( + collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); + } while (count == 0); + bson_destroy(doc); + + /* Send Registration request */ + gmmbuf = testgmm_build_registration_request(&test_ue, false); + ABTS_PTR_NOTNULL(tc, gmmbuf); + sendbuf = testngap_build_initial_ue_message(&test_ue, gmmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Authentication request */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(&test_ue, recvbuf); + + /* Send Authentication response */ + gmmbuf = testgmm_build_authentication_response(&test_ue); + ABTS_PTR_NOTNULL(tc, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Security mode command */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(&test_ue, recvbuf); + + /* Send Security mode complete */ + nasbuf = testgmm_build_registration_request(&test_ue, false); + ABTS_PTR_NOTNULL(tc, nasbuf); + gmmbuf = testgmm_build_security_mode_complete(&test_ue, nasbuf); + ABTS_PTR_NOTNULL(tc, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Initial context setup request */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(&test_ue, recvbuf); + + /* Send UE radio capability info indication */ + sendbuf = testngap_build_ue_radio_capability_info_indication(&test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Initial context setup response */ + sendbuf = testngap_build_initial_context_setup_response(&test_ue, NULL); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + ogs_msleep(50); + + /* Send Registration complete */ + gmmbuf = testgmm_build_registration_complete(&test_ue); + ABTS_PTR_NOTNULL(tc, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Configuration update command */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(&test_ue, recvbuf); + + /* Send PDU session establishment request */ + gsmbuf = testgsm_build_pdu_session_establishment_request(&test_sess); + ABTS_PTR_NOTNULL(tc, gsmbuf); + gmmbuf = testgmm_build_ul_nas_transport(&test_sess, + OGS_NAS_PAYLOAD_CONTAINER_N1_SM_INFORMATION, gsmbuf); + ABTS_PTR_NOTNULL(tc, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive PDU session establishment accept */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(&test_ue, recvbuf); + + /* Send PDU session resource setup response */ + sendbuf = testngap_build_pdu_session_resource_setup_response(&test_sess); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Update Registration request type */ + test_ue.nas.registration.value = + OGS_NAS_5GS_REGISTRATION_TYPE_MOBILITY_UPDATING; + + ogs_msleep(50); + + /* Send Registration request */ + gmmbuf = testgmm_build_registration_request(&test_ue, true); + ABTS_PTR_NOTNULL(tc, gmmbuf); + sendbuf = testngap_build_initial_ue_message(&test_ue, gmmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Initial context setup request */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(&test_ue, recvbuf); + + /* Send Initial context setup response */ + sendbuf = testngap_build_initial_context_setup_response( + &test_ue, &test_sess); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + ogs_msleep(50); + + /* Send De-registration request */ + gmmbuf = testgmm_build_de_registration_request(&test_ue, 1); + ABTS_PTR_NOTNULL(tc, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive UE context release command */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(&test_ue, recvbuf); + + /* Send UE context release complete */ + sendbuf = testngap_build_ue_context_release_complete(&test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + ogs_msleep(50); + + /* Update Registration request type */ + test_ue.nas.registration.value = + OGS_NAS_5GS_REGISTRATION_TYPE_PERIODIC_UPDATING; + + /* INVALID GUTI */ + test_ue.nas_guti.m_tmsi = 0x1234; + + /* Send Registration request */ + gmmbuf = testgmm_build_registration_request(&test_ue, true); + ABTS_PTR_NOTNULL(tc, gmmbuf); + sendbuf = testngap_build_initial_ue_message(&test_ue, gmmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Identity request */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(&test_ue, recvbuf); + + /* INVALID SUCI */ + test_ue.mobile_identity_suci.scheme_output[0] = 0x99; + + /* Send Identity response */ + gmmbuf = testgmm_build_identity_response(&test_ue); + ABTS_PTR_NOTNULL(tc, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive UE context release command */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(&test_ue, recvbuf); + + /* Send UE context release complete */ + sendbuf = testngap_build_ue_context_release_complete(&test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + ogs_msleep(50); + + /********** Remove Subscriber in Database */ + doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + ABTS_PTR_NOTNULL(tc, doc); + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + bson_destroy(doc); + + mongoc_collection_destroy(collection); + + /* gNB disonncect from UPF */ + testgnb_gtpu_close(gtpu); + + /* gNB disonncect from AMF */ + testgnb_ngap_close(ngap); + + /* Clear Test UE Context */ + test_ue_remove(&test_ue); +} + +abts_suite *test_identity(abts_suite *suite) +{ + suite = ADD_SUITE(suite) + + abts_run_test(suite, test1_func, NULL); + + return suite; +} diff --git a/tests/registration/idle-test.c b/tests/registration/idle-test.c new file mode 100644 index 000000000..8585178fa --- /dev/null +++ b/tests/registration/idle-test.c @@ -0,0 +1,455 @@ +/* + * Copyright (C) 2019,2020 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "test-5gc.h" + +static void test1_func(abts_case *tc, void *data) +{ + int rv; + ogs_socknode_t *ngap; + ogs_socknode_t *gtpu; + ogs_pkbuf_t *gmmbuf; + ogs_pkbuf_t *gsmbuf; + ogs_pkbuf_t *nasbuf; + ogs_pkbuf_t *sendbuf; + ogs_pkbuf_t *recvbuf; + ogs_ngap_message_t message; + int i; + int msgindex = 0; + + ogs_nas_5gs_mobile_identity_suci_t mobile_identity_suci; + test_ue_t test_ue; + test_sess_t test_sess; + + uint8_t tmp[OGS_MAX_SDU_LEN]; + + const char *_k_string = "70d49a71dd1a2b806a25abe0ef749f1e"; + uint8_t k[OGS_KEY_LEN]; + const char *_opc_string = "6f1bf53d624b3a43af6592854e2444c7"; + uint8_t opc[OGS_KEY_LEN]; + + mongoc_collection_t *collection = NULL; + bson_t *doc = NULL; + int64_t count = 0; + bson_error_t error; + const char *json = + "{" + "\"_id\" : { \"$oid\" : \"597223158b8861d7605378c6\" }, " + "\"imsi\" : \"901700000021309\"," + "\"ambr\" : { " + "\"uplink\" : { \"$numberLong\" : \"1024000\" }, " + "\"downlink\" : { \"$numberLong\" : \"1024000\" } " + "}," + "\"pdn\" : [" + "{" + "\"apn\" : \"internet\", " + "\"_id\" : { \"$oid\" : \"597223158b8861d7605378c7\" }, " + "\"ambr\" : {" + "\"uplink\" : { \"$numberLong\" : \"1024000\" }, " + "\"downlink\" : { \"$numberLong\" : \"1024000\" } " + "}," + "\"qos\" : { " + "\"qci\" : 9, " + "\"arp\" : { " + "\"priority_level\" : 8," + "\"pre_emption_vulnerability\" : 1, " + "\"pre_emption_capability\" : 1" + "} " + "}, " + "\"type\" : 2" + "}" + "]," + "\"security\" : { " + "\"k\" : \"70d49a71dd1a2b806a25abe0ef749f1e\", " + "\"opc\" : \"6f1bf53d624b3a43af6592854e2444c7\", " + "\"amf\" : \"8000\", " + "\"sqn\" : { \"$numberLong\" : \"25235952177090\" } " + "}, " + "\"subscribed_rau_tau_timer\" : 12," + "\"network_access_mode\" : 2, " + "\"subscriber_status\" : 0, " + "\"access_restriction_data\" : 32, " + "\"__v\" : 0 " + "}"; + + /* Setup Test UE & Session Context */ + memset(&test_ue, 0, sizeof(test_ue)); + memset(&test_sess, 0, sizeof(test_sess)); + test_sess.test_ue = &test_ue; + test_ue.sess = &test_sess; + + test_ue.nas.registration.type = 1; /* TSC[0], KSI[1] */ + test_ue.nas.registration.follow_on_request = 1; + test_ue.nas.registration.value = 1; /* Initial Registration */ + + memset(&mobile_identity_suci, 0, sizeof(mobile_identity_suci)); + + mobile_identity_suci.h.supi_format = OGS_NAS_5GS_SUPI_FORMAT_IMSI; + mobile_identity_suci.h.type = OGS_NAS_5GS_MOBILE_IDENTITY_SUCI; + ogs_nas_from_plmn_id(&mobile_identity_suci.nas_plmn_id, + &test_self()->tai.plmn_id); + mobile_identity_suci.routing_indicator1 = 0; + mobile_identity_suci.routing_indicator2 = 0xf; + mobile_identity_suci.routing_indicator3 = 0xf; + mobile_identity_suci.routing_indicator4 = 0xf; + mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME; + mobile_identity_suci.home_network_pki_value = 0; + mobile_identity_suci.scheme_output[0] = 0; + mobile_identity_suci.scheme_output[1] = 0; + mobile_identity_suci.scheme_output[2] = 0x20; + mobile_identity_suci.scheme_output[3] = 0x31; + mobile_identity_suci.scheme_output[4] = 0x90; + + test_ue_set_mobile_identity_suci(&test_ue, &mobile_identity_suci, 13); + + test_ue.nas.access_type = OGS_ACCESS_TYPE_3GPP; + test_ue.abba_len = 2; + + OGS_HEX(_k_string, strlen(_k_string), test_ue.k); + OGS_HEX(_opc_string, strlen(_opc_string), test_ue.opc); + + test_sess.psi = 1; + test_sess.pti = 1; + test_sess.pdu_session_type = OGS_PDU_SESSION_TYPE_IPV4V6; + test_sess.dnn = (char *)"internet"; + + memset(&test_sess.gnb_n3_ip, 0, sizeof(test_sess.gnb_n3_ip)); + test_sess.gnb_n3_ip.ipv4 = true; + test_sess.gnb_n3_ip.addr = inet_addr("127.0.0.5"); + test_sess.gnb_n3_teid = 3; + + /* gNB connects to AMF */ + ngap = testgnb_ngap_client("127.0.0.2"); + ABTS_PTR_NOTNULL(tc, ngap); + + /* gNB connects to UPF */ + gtpu = testgnb_gtpu_server("127.0.0.5"); + ABTS_PTR_NOTNULL(tc, gtpu); + + /* Send NG-Setup Reqeust */ + sendbuf = testngap_build_ng_setup_request(0x000102); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive NG-Setup Response */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(&test_ue, recvbuf); + + /********** Insert Subscriber in Database */ + collection = mongoc_client_get_collection( + ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); + ABTS_PTR_NOTNULL(tc, collection); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + ABTS_PTR_NOTNULL(tc, doc); + + count = mongoc_collection_count ( + collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); + if (count) { + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + } + bson_destroy(doc); + + doc = bson_new_from_json((const uint8_t *)json, -1, &error);; + ABTS_PTR_NOTNULL(tc, doc); + ABTS_TRUE(tc, mongoc_collection_insert(collection, + MONGOC_INSERT_NONE, doc, NULL, &error)); + bson_destroy(doc); + + doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + ABTS_PTR_NOTNULL(tc, doc); + do { + count = mongoc_collection_count ( + collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); + } while (count == 0); + bson_destroy(doc); + + /* Send Registration request */ + gmmbuf = testgmm_build_registration_request(&test_ue, false); + ABTS_PTR_NOTNULL(tc, gmmbuf); + sendbuf = testngap_build_initial_ue_message(&test_ue, gmmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Authentication request */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(&test_ue, recvbuf); + + /* Send Authentication response */ + gmmbuf = testgmm_build_authentication_response(&test_ue); + ABTS_PTR_NOTNULL(tc, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Security mode command */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(&test_ue, recvbuf); + + /* Send Security mode complete */ + nasbuf = testgmm_build_registration_request(&test_ue, false); + ABTS_PTR_NOTNULL(tc, nasbuf); + gmmbuf = testgmm_build_security_mode_complete(&test_ue, nasbuf); + ABTS_PTR_NOTNULL(tc, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Initial context setup request */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(&test_ue, recvbuf); + + /* Send UE radio capability info indication */ + sendbuf = testngap_build_ue_radio_capability_info_indication(&test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Initial context setup response */ + sendbuf = testngap_build_initial_context_setup_response(&test_ue, NULL); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + ogs_msleep(50); + + /* Send Registration complete */ + gmmbuf = testgmm_build_registration_complete(&test_ue); + ABTS_PTR_NOTNULL(tc, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Configuration update command */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(&test_ue, recvbuf); + + /* Send PDU session establishment request */ + gsmbuf = testgsm_build_pdu_session_establishment_request(&test_sess); + ABTS_PTR_NOTNULL(tc, gsmbuf); + gmmbuf = testgmm_build_ul_nas_transport(&test_sess, + OGS_NAS_PAYLOAD_CONTAINER_N1_SM_INFORMATION, gsmbuf); + ABTS_PTR_NOTNULL(tc, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive PDU session establishment accept */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(&test_ue, recvbuf); + + /* Send GTP-U ICMP Packet */ + rv = test_gtpu_build_ping(&sendbuf, &test_sess, "10.45.0.1"); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + rv = testgnb_gtpu_send(gtpu, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + ogs_msleep(50); + + /* Send PDU session resource setup response */ + sendbuf = testngap_build_pdu_session_resource_setup_response(&test_sess); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + ogs_msleep(50); + + /* Receive GTP-U ICMP Packet */ + recvbuf = testgnb_gtpu_read(gtpu); + ABTS_PTR_NOTNULL(tc, recvbuf); + ogs_pkbuf_free(recvbuf); + + /* Send GTP-U ICMP Packet */ + rv = test_gtpu_build_ping(&sendbuf, &test_sess, "10.45.0.1"); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + rv = testgnb_gtpu_send(gtpu, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive GTP-U ICMP Packet */ + recvbuf = testgnb_gtpu_read(gtpu); + ABTS_PTR_NOTNULL(tc, recvbuf); + ogs_pkbuf_free(recvbuf); + + ogs_msleep(50); + + /* Send UE context release request */ + sendbuf = testngap_build_ue_context_release_request(&test_ue, + NGAP_Cause_PR_radioNetwork, NGAP_CauseRadioNetwork_user_inactivity); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive UE context release command */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(&test_ue, recvbuf); + + /* Send UE context release complete */ + sendbuf = testngap_build_ue_context_release_complete(&test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send GTP-U ICMP Packet */ + rv = test_gtpu_build_ping(&sendbuf, &test_sess, "10.45.0.1"); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + rv = testgnb_gtpu_send(gtpu, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Service request */ + gmmbuf = testgmm_build_service_request(&test_ue); + ABTS_PTR_NOTNULL(tc, gmmbuf); + sendbuf = testngap_build_initial_ue_message(&test_ue, gmmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Service accept */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(&test_ue, recvbuf); + + /* Send Initial context setup response */ + sendbuf = testngap_build_initial_context_setup_response( + &test_ue, &test_sess); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive GTP-U ICMP Packet */ + recvbuf = testgnb_gtpu_read(gtpu); + ABTS_PTR_NOTNULL(tc, recvbuf); + ogs_pkbuf_free(recvbuf); + + /* Send GTP-U ICMP Packet */ + rv = test_gtpu_build_ping(&sendbuf, &test_sess, "10.45.0.1"); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + rv = testgnb_gtpu_send(gtpu, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive GTP-U ICMP Packet */ + recvbuf = testgnb_gtpu_read(gtpu); + ABTS_PTR_NOTNULL(tc, recvbuf); + ogs_pkbuf_free(recvbuf); + + ogs_msleep(50); + + /* Send UE context release request */ + sendbuf = testngap_build_ue_context_release_request(&test_ue, + NGAP_Cause_PR_radioNetwork, NGAP_CauseRadioNetwork_user_inactivity); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive UE context release command */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(&test_ue, recvbuf); + + /* Send GTP-U ICMP Packet */ + rv = test_gtpu_build_ping(&sendbuf, &test_sess, "10.45.0.1"); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + rv = testgnb_gtpu_send(gtpu, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send UE context release complete */ + sendbuf = testngap_build_ue_context_release_complete(&test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Service request */ + gmmbuf = testgmm_build_service_request(&test_ue); + ABTS_PTR_NOTNULL(tc, gmmbuf); + sendbuf = testngap_build_initial_ue_message(&test_ue, gmmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Service accept */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(&test_ue, recvbuf); + + test_sess.gnb_n3_teid = 5; + + /* Send Initial context setup response */ + sendbuf = testngap_build_initial_context_setup_response( + &test_ue, &test_sess); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive GTP-U ICMP Packet */ + recvbuf = testgnb_gtpu_read(gtpu); + ABTS_PTR_NOTNULL(tc, recvbuf); + ogs_pkbuf_free(recvbuf); + + /* Send GTP-U ICMP Packet */ + rv = test_gtpu_build_ping(&sendbuf, &test_sess, "10.45.0.1"); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + rv = testgnb_gtpu_send(gtpu, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive GTP-U ICMP Packet */ + recvbuf = testgnb_gtpu_read(gtpu); + ABTS_PTR_NOTNULL(tc, recvbuf); + ogs_pkbuf_free(recvbuf); + + ogs_msleep(50); + + /********** Remove Subscriber in Database */ + doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + ABTS_PTR_NOTNULL(tc, doc); + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + bson_destroy(doc); + + mongoc_collection_destroy(collection); + + /* gNB disonncect from UPF */ + testgnb_gtpu_close(gtpu); + + /* gNB disonncect from AMF */ + testgnb_ngap_close(ngap); + + /* Clear Test UE Context */ + test_ue_remove(&test_ue); +} + +abts_suite *test_idle(abts_suite *suite) +{ + suite = ADD_SUITE(suite) + + abts_run_test(suite, test1_func, NULL); + + return suite; +} diff --git a/tests/registration/meson.build b/tests/registration/meson.build new file mode 100644 index 000000000..5ae7b4297 --- /dev/null +++ b/tests/registration/meson.build @@ -0,0 +1,32 @@ +# Copyright (C) 2019,2020 by Sukchan Lee + +# This file is part of Open5GS. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +testregistration_sources = files(''' + abts-main.c + guti-test.c + auth-test.c + idle-test.c + dereg-test.c + identity-test.c + gmm-status-test.c + ue-context-test.c +'''.split()) + +testregistration_exe = executable('registration', + sources : testregistration_sources, + c_args : testcore_cc_flags, + dependencies : libtest5gc_dep) diff --git a/tests/registration/ue-context-test.c b/tests/registration/ue-context-test.c new file mode 100644 index 000000000..02da1c5d2 --- /dev/null +++ b/tests/registration/ue-context-test.c @@ -0,0 +1,268 @@ +/* + * Copyright (C) 2019,2020 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "test-5gc.h" + +static void test1_func(abts_case *tc, void *data) +{ + int rv; + ogs_socknode_t *ngap; + ogs_socknode_t *gtpu; + ogs_pkbuf_t *gmmbuf; + ogs_pkbuf_t *gsmbuf; + ogs_pkbuf_t *sendbuf; + ogs_pkbuf_t *recvbuf; + ogs_ngap_message_t message; + int i; + int msgindex = 0; + + ogs_nas_5gs_mobile_identity_suci_t mobile_identity_suci; + test_ue_t test_ue; + test_sess_t test_sess; + + uint8_t tmp[OGS_MAX_SDU_LEN]; + + const char *_k_string = "70d49a71dd1a2b806a25abe0ef749f1e"; + uint8_t k[OGS_KEY_LEN]; + const char *_opc_string = "6f1bf53d624b3a43af6592854e2444c7"; + uint8_t opc[OGS_KEY_LEN]; + + mongoc_collection_t *collection = NULL; + bson_t *doc = NULL; + int64_t count = 0; + bson_error_t error; + const char *json = + "{" + "\"_id\" : { \"$oid\" : \"597223158b8861d7605378c6\" }, " + "\"imsi\" : \"901700000021309\"," + "\"ambr\" : { " + "\"uplink\" : { \"$numberLong\" : \"1024000\" }, " + "\"downlink\" : { \"$numberLong\" : \"1024000\" } " + "}," + "\"pdn\" : [" + "{" + "\"apn\" : \"internet\", " + "\"_id\" : { \"$oid\" : \"597223158b8861d7605378c7\" }, " + "\"ambr\" : {" + "\"uplink\" : { \"$numberLong\" : \"1024000\" }, " + "\"downlink\" : { \"$numberLong\" : \"1024000\" } " + "}," + "\"qos\" : { " + "\"qci\" : 9, " + "\"arp\" : { " + "\"priority_level\" : 8," + "\"pre_emption_vulnerability\" : 1, " + "\"pre_emption_capability\" : 1" + "} " + "}, " + "\"type\" : 2" + "}" + "]," + "\"security\" : { " + "\"k\" : \"70d49a71dd1a2b806a25abe0ef749f1e\", " + "\"opc\" : \"6f1bf53d624b3a43af6592854e2444c7\", " + "\"amf\" : \"8000\", " + "\"sqn\" : { \"$numberLong\" : \"25235952177090\" } " + "}, " + "\"subscribed_rau_tau_timer\" : 12," + "\"network_access_mode\" : 2, " + "\"subscriber_status\" : 0, " + "\"access_restriction_data\" : 32, " + "\"__v\" : 0 " + "}"; + + /* Setup Test UE & Session Context */ + memset(&test_ue, 0, sizeof(test_ue)); + memset(&test_sess, 0, sizeof(test_sess)); + test_sess.test_ue = &test_ue; + test_ue.sess = &test_sess; + + test_ue.nas.registration.type = 1; /* TSC[0], KSI[1] */ + test_ue.nas.registration.follow_on_request = 1; + test_ue.nas.registration.value = OGS_NAS_5GS_REGISTRATION_TYPE_INITIAL; + + memset(&mobile_identity_suci, 0, sizeof(mobile_identity_suci)); + + mobile_identity_suci.h.supi_format = OGS_NAS_5GS_SUPI_FORMAT_IMSI; + mobile_identity_suci.h.type = OGS_NAS_5GS_MOBILE_IDENTITY_SUCI; + ogs_nas_from_plmn_id(&mobile_identity_suci.nas_plmn_id, + &test_self()->tai.plmn_id); + mobile_identity_suci.routing_indicator1 = 0; + mobile_identity_suci.routing_indicator2 = 0xf; + mobile_identity_suci.routing_indicator3 = 0xf; + mobile_identity_suci.routing_indicator4 = 0xf; + mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME; + mobile_identity_suci.home_network_pki_value = 0; + mobile_identity_suci.scheme_output[0] = 0; + mobile_identity_suci.scheme_output[1] = 0; + mobile_identity_suci.scheme_output[2] = 0x20; + mobile_identity_suci.scheme_output[3] = 0x31; + mobile_identity_suci.scheme_output[4] = 0x90; + + test_ue_set_mobile_identity_suci(&test_ue, &mobile_identity_suci, 13); + + test_ue.nas.access_type = OGS_ACCESS_TYPE_3GPP; + test_ue.abba_len = 2; + + OGS_HEX(_k_string, strlen(_k_string), test_ue.k); + OGS_HEX(_opc_string, strlen(_opc_string), test_ue.opc); + + test_sess.psi = 1; + test_sess.pti = 1; + test_sess.pdu_session_type = OGS_PDU_SESSION_TYPE_IPV4V6; + test_sess.dnn = (char *)"internet"; + + memset(&test_sess.gnb_n3_ip, 0, sizeof(test_sess.gnb_n3_ip)); + test_sess.gnb_n3_ip.ipv4 = true; + test_sess.gnb_n3_ip.addr = inet_addr("127.0.0.5"); + test_sess.gnb_n3_teid = 0; + + /* gNB connects to AMF */ + ngap = testgnb_ngap_client("127.0.0.2"); + ABTS_PTR_NOTNULL(tc, ngap); + + /* gNB connects to UPF */ + gtpu = testgnb_gtpu_server("127.0.0.5"); + ABTS_PTR_NOTNULL(tc, gtpu); + + /* Send NG-Setup Reqeust */ + sendbuf = testngap_build_ng_setup_request(0x000102); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive NG-Setup Response */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(&test_ue, recvbuf); + + /********** Insert Subscriber in Database */ + collection = mongoc_client_get_collection( + ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); + ABTS_PTR_NOTNULL(tc, collection); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + ABTS_PTR_NOTNULL(tc, doc); + + count = mongoc_collection_count ( + collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); + if (count) { + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + } + bson_destroy(doc); + + doc = bson_new_from_json((const uint8_t *)json, -1, &error);; + ABTS_PTR_NOTNULL(tc, doc); + ABTS_TRUE(tc, mongoc_collection_insert(collection, + MONGOC_INSERT_NONE, doc, NULL, &error)); + bson_destroy(doc); + + doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + ABTS_PTR_NOTNULL(tc, doc); + do { + count = mongoc_collection_count ( + collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); + } while (count == 0); + bson_destroy(doc); + + /* Send Registration request */ + gmmbuf = testgmm_build_registration_request(&test_ue, false); + ABTS_PTR_NOTNULL(tc, gmmbuf); + sendbuf = testngap_build_initial_ue_message(&test_ue, gmmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Authentication request */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(&test_ue, recvbuf); + + /* Send Authentication response */ + gmmbuf = testgmm_build_authentication_response(&test_ue); + ABTS_PTR_NOTNULL(tc, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Security mode command */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(&test_ue, recvbuf); + + /* Send Security mode complete */ + gmmbuf = testgmm_build_security_mode_complete(&test_ue, NULL); + ABTS_PTR_NOTNULL(tc, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + + /* Receive Initial context setup request */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(&test_ue, recvbuf); + + /* Send Initial context setup failure */ + sendbuf = testngap_build_initial_context_setup_failure(&test_ue, + NGAP_Cause_PR_radioNetwork, + NGAP_CauseRadioNetwork_radio_connection_with_ue_lost); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + + /* Receive UE context release command */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(&test_ue, recvbuf); + + /* Send UE context release complete */ + sendbuf = testngap_build_ue_context_release_complete(&test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + ogs_msleep(50); + + /********** Remove Subscriber in Database */ + doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + ABTS_PTR_NOTNULL(tc, doc); + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + bson_destroy(doc); + + mongoc_collection_destroy(collection); + + /* gNB disonncect from UPF */ + testgnb_gtpu_close(gtpu); + + /* gNB disonncect from AMF */ + testgnb_ngap_close(ngap); + + /* Clear Test UE Context */ + test_ue_remove(&test_ue); +} + +abts_suite *test_ue_context(abts_suite *suite) +{ + suite = ADD_SUITE(suite) + + abts_run_test(suite, test1_func, NULL); + + return suite; +} diff --git a/webui/package-lock.json b/webui/package-lock.json index 97a9005f8..0c87c8df0 100644 --- a/webui/package-lock.json +++ b/webui/package-lock.json @@ -1,6 +1,6 @@ { "name": "open5gs", - "version": "1.2.0", + "version": "1.3.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/webui/package.json b/webui/package.json index 8d860fd8f..a9131913a 100644 --- a/webui/package.json +++ b/webui/package.json @@ -1,6 +1,6 @@ { "name": "open5gs", - "version": "1.2.0", + "version": "1.3.0", "description": "Open5gs", "main": "index.js", "repository": "https://github.com/open5gs/webui",