From bbc594330b9cf0b38da8319a4cb908fa9b81637d Mon Sep 17 00:00:00 2001 From: Sukchan Lee Date: Fri, 21 Jun 2019 18:23:29 +0900 Subject: [PATCH] [SGsAP] update it --- lib/base/types.c | 24 ++++++++---------------- lib/base/types.h | 4 ++-- lib/nas/nas-decoder.c | 2 +- lib/nas/nas-encoder.c | 2 +- lib/nas/nas-ies.c | 6 +++--- lib/nas/nas-ies.h | 2 +- lib/nas/nas-message.h | 2 +- lib/nas/support/type-list.py | 4 ++-- src/mme/mme-s11-build.c | 2 +- src/mme/sgsap-build.c | 14 +++++++------- src/mme/sgsap-conv.c | 16 ++++++++++------ src/mme/sgsap-conv.h | 2 +- src/pgw/pgw-context.c | 2 +- src/sgw/sgw-s11-handler.c | 3 ++- tests/complex/attach-test.c | 21 +++++++-------------- tests/complex/handover-test.c | 6 ++---- tests/complex/s1setup-test.c | 18 ++++++------------ tests/complex/volte-test.c | 6 ++---- tests/csfb/csfb-test.c | 13 +++++++++++-- tests/simple/mnc3-test.c | 3 +-- 20 files changed, 70 insertions(+), 82 deletions(-) diff --git a/lib/base/types.c b/lib/base/types.c index 1f86f83b1..377b1552d 100644 --- a/lib/base/types.c +++ b/lib/base/types.c @@ -64,19 +64,15 @@ void *plmn_id_build(plmn_id_t *plmn_id, return plmn_id; } -int apn_build(char *dst, char *src, int length) +int fqdn_build(char *dst, char *src, int length) { int i = 0, j = 0; - for (i = 0, j = 0; i < length; i++, j++) - { - if (src[i] == '.') - { + for (i = 0, j = 0; i < length; i++, j++) { + if (src[i] == '.') { dst[i-j] = j; j = -1; - } - else - { + } else { dst[i+1] = src[i]; } } @@ -85,13 +81,12 @@ int apn_build(char *dst, char *src, int length) return length+1; } -int apn_parse(char *dst, char *src, int length) +int fqdn_parse(char *dst, char *src, int length) { int i = 0, j = 0; uint8_t len = 0; - do - { + do { len = src[i++]; memcpy(&dst[j], &src[i], len); @@ -125,8 +120,7 @@ int pco_parse(pco_t *pco, void *data, int data_len) pco->configuration_protocol = source->configuration_protocol; size++; - while(size < data_len && i < MAX_NUM_OF_PROTOCOL_OR_CONTAINER_ID) - { + while(size < data_len && i < MAX_NUM_OF_PROTOCOL_OR_CONTAINER_ID) { pco_id_t *id = &pco->ids[i]; ogs_assert(size + sizeof(id->id) <= data_len); memcpy(&id->id, data + size, sizeof(id->id)); @@ -164,8 +158,7 @@ int pco_build(void *data, int data_len, pco_t *pco) size += 1; ogs_assert(target.num_of_id <= MAX_NUM_OF_PROTOCOL_OR_CONTAINER_ID); - for (i = 0; i < target.num_of_id; i++) - { + for (i = 0; i < target.num_of_id; i++) { pco_id_t *id = &target.ids[i]; ogs_assert(size + sizeof(id->id) <= data_len); @@ -184,4 +177,3 @@ int pco_build(void *data, int data_len, pco_t *pco) return size; } - diff --git a/lib/base/types.h b/lib/base/types.h index b9c9ebe4d..6f97bd2b7 100644 --- a/lib/base/types.h +++ b/lib/base/types.h @@ -285,8 +285,8 @@ typedef struct pdn_s { ip_t pgw_ip; } pdn_t; -int apn_build(char *dst, char *src, int len); -int apn_parse(char *dst, char *src, int len); +int fqdn_build(char *dst, char *src, int len); +int fqdn_parse(char *dst, char *src, int len); /************************************************** * Protocol Configuration Options Structure diff --git a/lib/nas/nas-decoder.c b/lib/nas/nas-decoder.c index 5d01cdeef..27c7f366a 100644 --- a/lib/nas/nas-decoder.c +++ b/lib/nas/nas-decoder.c @@ -20,7 +20,7 @@ /******************************************************************************* * This file had been created by nas-message.py script v0.1.0 * Please do not modify this file but regenerate it via script. - * Created on: 2019-06-11 17:27:29.685234 by acetcom + * Created on: 2019-06-21 14:10:51.931135 by acetcom * from 24301-d80.docx ******************************************************************************/ diff --git a/lib/nas/nas-encoder.c b/lib/nas/nas-encoder.c index be385c74b..ee565997f 100644 --- a/lib/nas/nas-encoder.c +++ b/lib/nas/nas-encoder.c @@ -20,7 +20,7 @@ /******************************************************************************* * This file had been created by nas-message.py script v0.1.0 * Please do not modify this file but regenerate it via script. - * Created on: 2019-06-11 17:27:29.711227 by acetcom + * Created on: 2019-06-21 14:10:51.957409 by acetcom * from 24301-d80.docx ******************************************************************************/ diff --git a/lib/nas/nas-ies.c b/lib/nas/nas-ies.c index ceaa6125b..6434fa2ff 100644 --- a/lib/nas/nas-ies.c +++ b/lib/nas/nas-ies.c @@ -20,7 +20,7 @@ /******************************************************************************* * This file had been created by nas-message.py script v0.1.0 * Please do not modify this file but regenerate it via script. - * Created on: 2019-06-11 17:27:29.648106 by acetcom + * Created on: 2019-06-21 14:10:51.889878 by acetcom * from 24301-d80.docx ******************************************************************************/ @@ -2123,7 +2123,7 @@ int nas_decode_access_point_name(nas_access_point_name_t *access_point_name, ogs { char apn[MAX_APN_LEN]; - access_point_name->length = apn_parse(apn, access_point_name->apn, access_point_name->length); + access_point_name->length = fqdn_parse(apn, access_point_name->apn, access_point_name->length); ogs_cpystrn(access_point_name->apn, apn, ogs_min(access_point_name->length, MAX_APN_LEN) + 1); } @@ -2139,7 +2139,7 @@ int nas_encode_access_point_name(ogs_pkbuf_t *pkbuf, nas_access_point_name_t *ac nas_access_point_name_t target; memcpy(&target, access_point_name, sizeof(nas_access_point_name_t)); - target.length = apn_build(target.apn, access_point_name->apn, access_point_name->length); + target.length = fqdn_build(target.apn, access_point_name->apn, access_point_name->length); size = target.length + sizeof(target.length); ogs_assert(ogs_pkbuf_pull(pkbuf, size)); diff --git a/lib/nas/nas-ies.h b/lib/nas/nas-ies.h index 1f277633f..663f6f789 100644 --- a/lib/nas/nas-ies.h +++ b/lib/nas/nas-ies.h @@ -20,7 +20,7 @@ /******************************************************************************* * This file had been created by nas-message.py script v0.1.0 * Please do not modify this file but regenerate it via script. - * Created on: 2019-06-11 17:27:29.642367 by acetcom + * Created on: 2019-06-21 14:10:51.884139 by acetcom * from 24301-d80.docx ******************************************************************************/ diff --git a/lib/nas/nas-message.h b/lib/nas/nas-message.h index b5e3067a3..13033d1bc 100644 --- a/lib/nas/nas-message.h +++ b/lib/nas/nas-message.h @@ -20,7 +20,7 @@ /******************************************************************************* * This file had been created by nas-message.py script v0.1.0 * Please do not modify this file but regenerate it via script. - * Created on: 2019-06-11 17:27:29.664161 by acetcom + * Created on: 2019-06-21 14:10:51.908774 by acetcom * from 24301-d80.docx ******************************************************************************/ diff --git a/lib/nas/support/type-list.py b/lib/nas/support/type-list.py index 396d1fc02..5fce6df34 100644 --- a/lib/nas/support/type-list.py +++ b/lib/nas/support/type-list.py @@ -79,10 +79,10 @@ type_list["Short MAC"]["encode"] = \ type_list["Access point name"]["decode"] = \ " {\n" \ " char apn[MAX_APN_LEN];\n" \ -" access_point_name->length = apn_parse(apn, access_point_name->apn, access_point_name->length);\n" \ +" access_point_name->length = fqdn_parse(apn, access_point_name->apn, access_point_name->length);\n" \ " ogs_cpystrn(access_point_name->apn, apn, ogs_min(access_point_name->length, MAX_APN_LEN) + 1);\n" \ " }\n\n" type_list["Access point name"]["encode"] = \ -" target.length = apn_build(target.apn, access_point_name->apn, access_point_name->length);\n" \ +" target.length = fqdn_build(target.apn, access_point_name->apn, access_point_name->length);\n" \ " size = target.length + sizeof(target.length);\n\n" diff --git a/src/mme/mme-s11-build.c b/src/mme/mme-s11-build.c index 45ac8d2fd..4fcb2611d 100644 --- a/src/mme/mme-s11-build.c +++ b/src/mme/mme-s11-build.c @@ -126,7 +126,7 @@ int mme_s11_build_create_session_request( } req->access_point_name.presence = 1; - req->access_point_name.len = apn_build(apn, pdn->apn, strlen(pdn->apn)); + req->access_point_name.len = fqdn_build(apn, pdn->apn, strlen(pdn->apn)); req->access_point_name.data = apn; req->selection_mode.presence = 1; diff --git a/src/mme/sgsap-build.c b/src/mme/sgsap-build.c index e138ec40a..b42b6eef8 100644 --- a/src/mme/sgsap-build.c +++ b/src/mme/sgsap-build.c @@ -30,9 +30,9 @@ ogs_pkbuf_t *sgsap_build_location_update_request(mme_ue_t *mme_ue) ogs_pkbuf_t *pkbuf = NULL; char mme_name[SGSAP_IE_MME_NAME_LEN+1]; + int mme_name_len = 0; served_gummei_t *served_gummei = &mme_self()->served_gummei[0]; char eps_update_type; - uint32_t len; nas_lai_t lai; ogs_assert(mme_ue); @@ -42,11 +42,11 @@ ogs_pkbuf_t *sgsap_build_location_update_request(mme_ue_t *mme_ue) root = ogs_tlv_add(NULL, SGSAP_IE_IMSI_TYPE, SGSAP_IE_IMSI_LEN, 0, (uint8_t *)&mme_ue->nas_mobile_identity_imsi); - mme_name_build(mme_name, SGSAP_IE_MME_NAME_LEN+1, + mme_name_len = mme_name_build(mme_name, served_gummei->mme_code[0], served_gummei->mme_gid[0], - &served_gummei->plmn_id[0]);; - ogs_tlv_add(root, SGSAP_IE_MME_NAME_TYPE, strlen(mme_name), 0, + &served_gummei->plmn_id[0]); + ogs_tlv_add(root, SGSAP_IE_MME_NAME_TYPE, mme_name_len, 0, (uint8_t *)mme_name); eps_update_type = SGSAP_EPS_UPDATE_IMSI_ATTACH; ogs_tlv_add(root, SGSAP_IE_EPS_UPDATE_TYPE, SGSAP_IE_EPS_UPDATE_LEN, 0, @@ -59,11 +59,11 @@ ogs_pkbuf_t *sgsap_build_location_update_request(mme_ue_t *mme_ue) pkbuf = ogs_pkbuf_alloc(NULL, MAX_SDU_LEN); ogs_pkbuf_put_u8(pkbuf, SGSAP_LOCATION_UPDATE_REQUEST); ogs_pkbuf_put(pkbuf, MAX_SDU_LEN-1); - len = ogs_tlv_render(root, - pkbuf->data+1, MAX_SDU_LEN-1, OGS_TLV_MODE_T1_L1); + + ogs_pkbuf_trim(pkbuf, 1+ogs_tlv_render(root, + pkbuf->data+1, MAX_SDU_LEN-1, OGS_TLV_MODE_T1_L1)); ogs_tlv_free_all(root); - ogs_pkbuf_trim(pkbuf, len+1); return pkbuf; } diff --git a/src/mme/sgsap-conv.c b/src/mme/sgsap-conv.c index c9798c554..d384b7a4d 100644 --- a/src/mme/sgsap-conv.c +++ b/src/mme/sgsap-conv.c @@ -17,19 +17,23 @@ * along with this program. If not, see . */ +#include "sgsap-types.h" #include "sgsap-conv.h" -char *mme_name_build(char *buf, size_t size, +int mme_name_build(char *buf, uint32_t mme_code, uint16_t mme_gid, plmn_id_t *plmn_id) { + int len; + char temp[SGSAP_IE_MME_NAME_LEN]; ogs_assert(buf); ogs_assert(plmn_id); - if (ogs_snprintf(buf, size, + + len = ogs_snprintf(temp, SGSAP_IE_MME_NAME_LEN, "mmec%02d.mmegi%04d.mme.epc.mnc%03d.mcc%03d.3gppnetwork.org", - mme_code, mme_gid, plmn_id_mnc(plmn_id), plmn_id_mcc(plmn_id)) < 0) { - ogs_error("Cannot make MME name"); - return NULL; + mme_code, mme_gid, plmn_id_mnc(plmn_id), plmn_id_mcc(plmn_id)); + if (len < 0) { + ogs_assert_if_reached(); } - return buf; + return fqdn_build(buf, temp, len); } diff --git a/src/mme/sgsap-conv.h b/src/mme/sgsap-conv.h index e11b6e4d1..fc92d270e 100644 --- a/src/mme/sgsap-conv.h +++ b/src/mme/sgsap-conv.h @@ -26,7 +26,7 @@ extern "C" { #endif -char *mme_name_build(char *buf, size_t size, +int mme_name_build(char *buf, uint32_t mme_code, uint16_t mme_gid, plmn_id_t *plmn_id); #ifdef __cplusplus diff --git a/src/pgw/pgw-context.c b/src/pgw/pgw-context.c index 6267a00c1..14846bbfc 100644 --- a/src/pgw/pgw-context.c +++ b/src/pgw/pgw-context.c @@ -894,7 +894,7 @@ pgw_sess_t *pgw_sess_add_by_message(gtp_message_t *message) return NULL; } - apn_parse(apn, req->access_point_name.data, req->access_point_name.len); + fqdn_parse(apn, req->access_point_name.data, req->access_point_name.len); ogs_trace("pgw_sess_add_by_message() [APN:%s, PDN:%d, EDI:%d]", apn, req->pdn_type.u8, diff --git a/src/sgw/sgw-s11-handler.c b/src/sgw/sgw-s11-handler.c index 8a619bece..0744b7f84 100644 --- a/src/sgw/sgw-s11-handler.c +++ b/src/sgw/sgw-s11-handler.c @@ -58,7 +58,8 @@ void sgw_s11_handle_create_session_request( return; } - apn_parse(apn, req->access_point_name.data, req->access_point_name.len); + fqdn_parse(apn, + req->access_point_name.data, req->access_point_name.len); sess = sgw_sess_add(sgw_ue, apn, req->bearer_contexts_to_be_created.eps_bearer_id.u8); ogs_assert(sess); diff --git a/tests/complex/attach-test.c b/tests/complex/attach-test.c index 1cc32b7cc..49ac74740 100644 --- a/tests/complex/attach-test.c +++ b/tests/complex/attach-test.c @@ -132,8 +132,7 @@ static void attach_test1(abts_case *tc, void *data) doc = BCON_NEW("imsi", BCON_UTF8("001010123456819")); ABTS_PTR_NOTNULL(tc, doc); - do - { + do { count = mongoc_collection_count ( collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); } while (count == 0); @@ -574,8 +573,7 @@ static void attach_test2(abts_case *tc, void *data) doc = BCON_NEW("imsi", BCON_UTF8("001010123456826")); ABTS_PTR_NOTNULL(tc, doc); - do - { + do { count = mongoc_collection_count ( collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); } while (count == 0); @@ -590,8 +588,7 @@ static void attach_test2(abts_case *tc, void *data) doc = BCON_NEW("imsi", BCON_UTF8("001010000000003")); ABTS_PTR_NOTNULL(tc, doc); - do - { + do { count = mongoc_collection_count ( collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); } while (count == 0); @@ -897,8 +894,7 @@ static void attach_test3(abts_case *tc, void *data) doc = BCON_NEW("imsi", BCON_UTF8("001010123456797")); ABTS_PTR_NOTNULL(tc, doc); - do - { + do { count = mongoc_collection_count ( collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); } while (count == 0); @@ -1194,8 +1190,7 @@ static void attach_test4(abts_case *tc, void *data) doc = BCON_NEW("imsi", BCON_UTF8("001010000000002")); ABTS_PTR_NOTNULL(tc, doc); - do - { + do { count = mongoc_collection_count ( collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); } while (count == 0); @@ -1368,8 +1363,7 @@ static void attach_test5(abts_case *tc, void *data) doc = BCON_NEW("imsi", BCON_UTF8("001010123456937")); ABTS_PTR_NOTNULL(tc, doc); - do - { + do { count = mongoc_collection_count ( collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); } while (count == 0); @@ -1706,8 +1700,7 @@ static void attach_test6(abts_case *tc, void *data) doc = BCON_NEW("imsi", BCON_UTF8("001010000000002")); ABTS_PTR_NOTNULL(tc, doc); - do - { + do { count = mongoc_collection_count ( collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); } while (count == 0); diff --git a/tests/complex/handover-test.c b/tests/complex/handover-test.c index 1cc2d6534..eaa9b0162 100644 --- a/tests/complex/handover-test.c +++ b/tests/complex/handover-test.c @@ -152,8 +152,7 @@ static void handover_test1(abts_case *tc, void *data) doc = BCON_NEW("imsi", BCON_UTF8("001010123456801")); ABTS_PTR_NOTNULL(tc, doc); - do - { + do { count = mongoc_collection_count ( collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); } while (count == 0); @@ -458,8 +457,7 @@ static void handover_test2(abts_case *tc, void *data) doc = BCON_NEW("imsi", BCON_UTF8("001010123456815")); ABTS_PTR_NOTNULL(tc, doc); - do - { + do { count = mongoc_collection_count ( collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); } while (count == 0); diff --git a/tests/complex/s1setup-test.c b/tests/complex/s1setup-test.c index 207af39b6..8692fb56e 100644 --- a/tests/complex/s1setup-test.c +++ b/tests/complex/s1setup-test.c @@ -16,14 +16,12 @@ static void s1setup_test1(abts_case *tc, void *data) s1ap_message_t message; int i; - for (i = 0; i < NUM_OF_TEST_DUPLICATED_ENB; i++) - { + for (i = 0; i < NUM_OF_TEST_DUPLICATED_ENB; i++) { node[i] = testenb_s1ap_client("127.0.0.1"); ABTS_PTR_NOTNULL(tc, node[i]); } - for (i = 0; i < NUM_OF_TEST_DUPLICATED_ENB; i++) - { + for (i = 0; i < NUM_OF_TEST_DUPLICATED_ENB; i++) { rv = tests1ap_build_setup_req( &sendbuf, S1AP_ENB_ID_PR_macroENB_ID, 0x54f64, 12345, 1, 1, 2); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -41,8 +39,7 @@ static void s1setup_test1(abts_case *tc, void *data) ogs_pkbuf_free(recvbuf); } - for (i = 0; i < NUM_OF_TEST_DUPLICATED_ENB; i++) - { + for (i = 0; i < NUM_OF_TEST_DUPLICATED_ENB; i++) { testenb_s1ap_close(node[i]); } @@ -60,14 +57,12 @@ static void s1setup_test2(abts_case *tc, void *data) s1ap_message_t message; int i; - for (i = 0; i < NUM_OF_TEST_ENB; i++) - { + for (i = 0; i < NUM_OF_TEST_ENB; i++) { node[i] = testenb_s1ap_client("127.0.0.1"); ABTS_PTR_NOTNULL(tc, node[i]); } - for (i = 0; i < NUM_OF_TEST_ENB; i++) - { + for (i = 0; i < NUM_OF_TEST_ENB; i++) { rv = tests1ap_build_setup_req( &sendbuf, S1AP_ENB_ID_PR_macroENB_ID, 0x54f64+i, 12345, 1, 1, 2); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -85,8 +80,7 @@ static void s1setup_test2(abts_case *tc, void *data) ogs_pkbuf_free(recvbuf); } - for (i = 0; i < NUM_OF_TEST_ENB; i++) - { + for (i = 0; i < NUM_OF_TEST_ENB; i++) { testenb_s1ap_close(node[i]); } diff --git a/tests/complex/volte-test.c b/tests/complex/volte-test.c index aa626e4fa..295b212e2 100644 --- a/tests/complex/volte-test.c +++ b/tests/complex/volte-test.c @@ -126,8 +126,7 @@ static void volte_test1(abts_case *tc, void *data) doc = BCON_NEW("imsi", BCON_UTF8("001010123456819")); ABTS_PTR_NOTNULL(tc, doc); - do - { + do { count = mongoc_collection_count ( collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); } while (count == 0); @@ -423,8 +422,7 @@ static void volte_test2(abts_case *tc, void *data) doc = BCON_NEW("imsi", BCON_UTF8("001010123456819")); ABTS_PTR_NOTNULL(tc, doc); - do - { + do { count = mongoc_collection_count ( collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); } while (count == 0); diff --git a/tests/csfb/csfb-test.c b/tests/csfb/csfb-test.c index d2d4f825a..8896df322 100644 --- a/tests/csfb/csfb-test.c +++ b/tests/csfb/csfb-test.c @@ -38,6 +38,10 @@ static void test1_func(abts_case *tc, void *data) char *_esm_information_request = "000b401d00000300 0000020001000800 020001001a000a09 27d1237969010234" "d9"; + char *_sgsap_location_update_request = + "0901082926240000 1118930937066d6d 65633031096d6d65 676930303032036d" + "6d6503657063066d 6e63303730066d63 633930310b336770 706e6574776f726b" + "036f72670a010104 0509f1070926"; char *_initial_context_setup_request = "00090080c8000006 0000000200010008 000200010042000a 183d090000603d09" "00000018007a0000 340075450009230f 807f000002000000 01662775a81d1902" @@ -132,8 +136,7 @@ static void test1_func(abts_case *tc, void *data) doc = BCON_NEW("imsi", BCON_UTF8("262420000118139")); ABTS_PTR_NOTNULL(tc, doc); - do - { + do { count = mongoc_collection_count ( collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); } while (count == 0); @@ -204,8 +207,14 @@ static void test1_func(abts_case *tc, void *data) /* Receive SGsAP-Location-Update-Request */ recvbuf = testvlr_sgsap_read(sgsap); ABTS_PTR_NOTNULL(tc, recvbuf); + ABTS_TRUE(tc, memcmp(recvbuf->data, + OGS_HEX(_sgsap_location_update_request, + strlen(_sgsap_location_update_request), tmp), + recvbuf->len) == 0); ogs_pkbuf_free(recvbuf); + /* Send SGsAP-Location-Update-Accept */ + #if 0 /* Receive Initial Context Setup Request + * Attach Accept + diff --git a/tests/simple/mnc3-test.c b/tests/simple/mnc3-test.c index 253fa654b..5a391b130 100644 --- a/tests/simple/mnc3-test.c +++ b/tests/simple/mnc3-test.c @@ -129,8 +129,7 @@ static void test1_func(abts_case *tc, void *data) doc = BCON_NEW("imsi", BCON_UTF8("310014987654004")); ABTS_PTR_NOTNULL(tc, doc); - do - { + do { count = mongoc_collection_count ( collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); } while (count == 0);