diff --git a/lib/base/types.h b/lib/base/types.h index 1d81a8a84..e4404280d 100644 --- a/lib/base/types.h +++ b/lib/base/types.h @@ -11,7 +11,7 @@ extern "C" { #define MAX_NUM_OF_ENB 128 #define MAX_NUM_OF_UE (MAX_NUM_OF_ENB * MAX_UE_PER_ENB) -#define MAX_NUM_OF_PDN 4 +#define MAX_NUM_OF_PDN 8 #define MAX_NUM_OF_BEARER 8 #define MAX_NUM_OF_UE_PDN (MAX_NUM_OF_UE * MAX_NUM_OF_PDN) #define MAX_NUM_OF_UE_BEARER (MAX_NUM_OF_UE * MAX_NUM_OF_BEARER) diff --git a/src/hss/hss_db.c b/src/hss/hss_db.c index 90d9cde78..d44268ad4 100644 --- a/src/hss/hss_db.c +++ b/src/hss/hss_db.c @@ -19,6 +19,24 @@ status_t hss_db_init() d_assert(subscriberCollection, return CORE_ERROR, "Couldn't find Subscriber Collection in '%s'", context_self()->db_name) +#if 0 + { + hss_db_subscription_data_t subscription_data; + pdn_t *pdn = &subscription_data.pdn[0]; + hss_db_subscription_data("001010123456819", &subscription_data); + printf("%d, %d, %d\n", + subscription_data.access_restriction_data, + subscription_data.subscriber_status, + subscription_data.network_access_mode); + printf("%d, %d\n", + subscription_data.max_bandwidth_ul, + subscription_data.max_bandwidth_dl); + printf("%s, %d\n", pdn->apn, pdn->s6a_type); + printf("%d, %d\n", pdn->max_bandwidth_ul, pdn->max_bandwidth_dl); + printf("%d, %d\n", pdn->qci, pdn->priority_level); + printf("%d, %d\n", pdn->pre_emption_capability, pdn->pre_emption_vulnerability); + } +#endif } return CORE_OK; @@ -38,26 +56,28 @@ status_t hss_db_auth_info( char *imsi_bcd, hss_db_auth_info_t *auth_info) { mongoc_cursor_t *cursor; - bson_t query; + bson_t *query; bson_error_t error; const bson_t *document; bson_iter_t iter; bson_iter_t inner_iter; + char buf[HSS_DB_KEY_LEN]; + char *utf8 = NULL; + c_uint32_t length = 0; d_assert(imsi_bcd, return CORE_ERROR, "Null param"); d_assert(auth_info, return CORE_ERROR, "Null param"); - bson_init(&query); - BSON_APPEND_UTF8(&query, "imsi", imsi_bcd); + query = BCON_NEW("imsi", BCON_UTF8(imsi_bcd)); cursor = mongoc_collection_find_with_opts( - subscriberCollection, &query, NULL, NULL); + subscriberCollection, query, NULL, NULL); mongoc_cursor_next(cursor, &document); if (mongoc_cursor_error(cursor, &error)) { d_error("Cursor Failure: %s", error.message); - bson_destroy(&query); + bson_destroy(query); return CORE_ERROR; } @@ -65,19 +85,16 @@ status_t hss_db_auth_info( { d_error("No 'security' field in this document"); - bson_destroy(&query); + bson_destroy(query); mongoc_cursor_destroy(cursor); return CORE_ERROR; } + memset(auth_info, 0, sizeof(hss_db_auth_info_t)); bson_iter_recurse(&iter, &inner_iter); while(bson_iter_next(&inner_iter)) { - char buf[HSS_DB_KEY_LEN]; - char *utf8 = NULL; - c_uint32_t length = 0; - const char *key = bson_iter_key(&inner_iter); if (!strcmp(key, "k") && BSON_ITER_HOLDS_UTF8(&inner_iter)) @@ -106,7 +123,7 @@ status_t hss_db_auth_info( } } - bson_destroy(&query); + bson_destroy(query); mongoc_cursor_destroy(cursor); return CORE_OK; @@ -126,7 +143,7 @@ status_t hss_db_update_rand_and_sqn( query = BCON_NEW("imsi", BCON_UTF8(imsi_bcd)); update = BCON_NEW("$set", "{", - "seccurity", "{", + "security", "{", "rand", printable_rand, "sqn", BCON_INT64(sqn), "}", @@ -161,7 +178,7 @@ status_t hss_db_increment_sqn(char *imsi_bcd) query = BCON_NEW("imsi", BCON_UTF8(imsi_bcd)); update = BCON_NEW("$inc", "{", - "seccurity.sqn", BCON_INT64(64), + "security.sqn", BCON_INT64(64), "}"); if (!mongoc_collection_update(subscriberCollection, @@ -179,3 +196,197 @@ status_t hss_db_increment_sqn(char *imsi_bcd) return CORE_OK; } + +status_t hss_db_subscription_data( + char *imsi_bcd, hss_db_subscription_data_t *subscription_data) +{ + mongoc_cursor_t *cursor; + bson_t *query; + bson_error_t error; + const bson_t *document; + bson_iter_t iter; + bson_iter_t child1_iter, child2_iter, child3_iter, child4_iter; + const char *utf8 = NULL; + c_uint32_t length = 0; + + d_assert(imsi_bcd, return CORE_ERROR, "Null param"); + d_assert(subscription_data, return CORE_ERROR, "Null param"); + + query = BCON_NEW("imsi", BCON_UTF8(imsi_bcd)); + cursor = mongoc_collection_find_with_opts( + subscriberCollection, query, NULL, NULL); + + mongoc_cursor_next(cursor, &document); + if (mongoc_cursor_error(cursor, &error)) + { + d_error("Cursor Failure: %s", error.message); + + bson_destroy(query); + return CORE_ERROR; + } + + if (!bson_iter_init(&iter, document)) + { + d_error("bson_iter_init failed in this document"); + + bson_destroy(query); + mongoc_cursor_destroy(cursor); + return CORE_ERROR; + + } + + memset(subscription_data, 0, sizeof(hss_db_subscription_data_t)); + while(bson_iter_next(&iter)) + { + const char *key = bson_iter_key(&iter); + if (!strcmp(key, "access_restriction_data") && + BSON_ITER_HOLDS_INT32(&iter)) + { + subscription_data->access_restriction_data = + bson_iter_int32(&iter); + + } + else if (!strcmp(key, "subscriber_status") && + BSON_ITER_HOLDS_INT32(&iter)) + { + subscription_data->subscriber_status = + bson_iter_int32(&iter); + } + else if (!strcmp(key, "network_access_mode") && + BSON_ITER_HOLDS_INT32(&iter)) + { + subscription_data->network_access_mode = + bson_iter_int32(&iter); + } + else if (!strcmp(key, "ue_ambr") && + BSON_ITER_HOLDS_DOCUMENT(&iter)) + { + bson_iter_recurse(&iter, &child1_iter); + while(bson_iter_next(&child1_iter)) + { + const char *child1_key = bson_iter_key(&child1_iter); + if (!strcmp(child1_key, "max_bandwidth_ul") && + BSON_ITER_HOLDS_INT32(&child1_iter)) + { + subscription_data->max_bandwidth_ul = + bson_iter_int32(&child1_iter); + } + else if (!strcmp(child1_key, "max_bandwidth_dl") && + BSON_ITER_HOLDS_INT32(&child1_iter)) + { + subscription_data->max_bandwidth_dl = + bson_iter_int32(&child1_iter); + } + } + } + else if (!strcmp(key, "pdn") && + BSON_ITER_HOLDS_ARRAY(&iter)) + { + bson_iter_recurse(&iter, &child1_iter); + while(bson_iter_next(&child1_iter)) + { + const char *child1_key = bson_iter_key(&child1_iter); + int pdn_index = 0; + pdn_t *pdn = NULL; + + d_assert(child1_key, return CORE_ERROR, "PDN is not ARRAY"); + pdn_index = atoi(child1_key); + d_assert(pdn_index < MAX_NUM_OF_PDN, + return CORE_ERROR, "Overflow of PDN number(%d>%d)", + pdn_index, MAX_NUM_OF_PDN); + + pdn = &subscription_data->pdn[pdn_index]; + + bson_iter_recurse(&child1_iter, &child2_iter); + while(bson_iter_next(&child2_iter)) + { + const char *child2_key = bson_iter_key(&child2_iter); + if (!strcmp(child2_key, "apn") && + BSON_ITER_HOLDS_UTF8(&child2_iter)) + { + utf8 = bson_iter_utf8(&child2_iter, &length); + core_cpystrn(pdn->apn, utf8, length+1); + } + else if (!strcmp(child2_key, "type") && + BSON_ITER_HOLDS_INT32(&child2_iter)) + { + pdn->s6a_type = bson_iter_int32(&child2_iter); + } + else if (!strcmp(child2_key, "qos") && + BSON_ITER_HOLDS_DOCUMENT(&child2_iter)) + { + bson_iter_recurse(&child2_iter, &child3_iter); + while(bson_iter_next(&child3_iter)) + { + const char *child3_key = + bson_iter_key(&child3_iter); + if (!strcmp(child3_key, "qci") && + BSON_ITER_HOLDS_INT32(&child3_iter)) + { + pdn->qci = bson_iter_int32(&child3_iter); + } + else if (!strcmp(child3_key, "arp") && + BSON_ITER_HOLDS_DOCUMENT(&child3_iter)) + { + bson_iter_recurse(&child3_iter, &child4_iter); + while(bson_iter_next(&child4_iter)) + { + const char *child4_key = + bson_iter_key(&child4_iter); + if (!strcmp(child4_key, "priority_level") && + BSON_ITER_HOLDS_INT32(&child4_iter)) + { + pdn->priority_level = + bson_iter_int32(&child4_iter); + } + else if (!strcmp(child4_key, + "pre_emption_capability") && + BSON_ITER_HOLDS_INT32(&child4_iter)) + { + pdn->pre_emption_capability = + bson_iter_int32(&child4_iter); + } + else if (!strcmp(child4_key, + "pre_emption_vulnerability") && + BSON_ITER_HOLDS_INT32(&child4_iter)) + { + pdn->pre_emption_vulnerability = + bson_iter_int32(&child4_iter); + } + } + } + } + } + else if (!strcmp(child2_key, "pdn_ambr") && + BSON_ITER_HOLDS_DOCUMENT(&child2_iter)) + { + bson_iter_recurse(&child2_iter, &child3_iter); + while(bson_iter_next(&child3_iter)) + { + const char *child3_key = + bson_iter_key(&child3_iter); + if (!strcmp(child3_key, "max_bandwidth_ul") && + BSON_ITER_HOLDS_INT32(&child3_iter)) + { + pdn->max_bandwidth_ul = + bson_iter_int32(&child3_iter); + } + else if (!strcmp(child3_key, "max_bandwidth_dl") && + BSON_ITER_HOLDS_INT32(&child3_iter)) + { + pdn->max_bandwidth_dl = + bson_iter_int32(&child3_iter); + } + } + } + + } + } + } + } + + bson_destroy(query); + mongoc_cursor_destroy(cursor); + + return CORE_OK; +} diff --git a/src/hss/hss_db.h b/src/hss/hss_db.h index 8c69dbf63..b3ce5845b 100644 --- a/src/hss/hss_db.h +++ b/src/hss/hss_db.h @@ -19,6 +19,20 @@ typedef struct _hss_db_auth_info_t { c_uint64_t sqn; } hss_db_auth_info_t; +typedef struct _hss_db_subscription_data_t { + c_uint32_t access_restriction_data; + c_uint32_t subscriber_status; + c_uint32_t network_access_mode; + + c_uint32_t max_bandwidth_ul; /* Kbps */ + c_uint32_t max_bandwidth_dl; /* Kbps */ + + c_uint32_t subscribed_rau_tau_timer; /* minutes */ + + pdn_t pdn[MAX_NUM_OF_PDN]; + int num_of_pdn; +} hss_db_subscription_data_t; + CORE_DECLARE(status_t) hss_db_init(void); CORE_DECLARE(status_t) hss_db_final(void); @@ -28,6 +42,9 @@ CORE_DECLARE(status_t) hss_db_update_rand_and_sqn( char *imsi_bcd, c_uint8_t *rand, c_uint64_t sqn); CORE_DECLARE(status_t) hss_db_increment_sqn(char *imsi_bcd); +CORE_DECLARE(status_t) hss_db_subscription_data( + char *imsi_bcd, hss_db_subscription_data_t *subscription_data); + #ifdef __cplusplus } #endif /* __cplusplus */