open5gs/src/hss/hss_context.c

794 lines
29 KiB
C
Raw Normal View History

2017-04-06 11:44:52 +00:00
#define TRACE_MODULE _hss_context
2017-03-02 02:43:26 +00:00
#include "core_debug.h"
2017-03-02 13:47:43 +00:00
#include "core_lib.h"
2017-12-15 04:47:57 +00:00
#include "core_network.h"
2017-03-02 02:43:26 +00:00
2017-07-22 04:05:43 +00:00
#include <mongoc.h>
2017-11-29 00:51:34 +00:00
#include <yaml.h>
2018-08-14 08:28:22 +00:00
#include "common/yaml_helper.h"
2017-07-22 04:05:43 +00:00
2018-01-04 11:38:22 +00:00
#include "fd/fd_lib.h"
2017-07-30 13:29:27 +00:00
2018-08-14 08:28:22 +00:00
#include "common/context.h"
2017-04-06 10:20:33 +00:00
#include "hss_context.h"
2017-03-02 02:43:26 +00:00
2017-04-06 11:44:52 +00:00
static hss_context_t self;
static fd_config_t g_fd_conf;
2017-07-22 00:44:42 +00:00
static int context_initialized = 0;
2017-03-02 02:43:26 +00:00
2017-04-06 11:44:52 +00:00
hss_context_t* hss_self()
2017-03-02 13:47:43 +00:00
{
return &self;
}
2017-04-06 11:44:52 +00:00
status_t hss_context_init(void)
2017-03-02 02:43:26 +00:00
{
status_t rv;
2017-07-22 00:44:42 +00:00
d_assert(context_initialized == 0, return CORE_ERROR,
"HSS context already has been context_initialized");
2017-03-02 13:47:43 +00:00
/* Initial FreeDiameter Config */
memset(&g_fd_conf, 0, sizeof(fd_config_t));
2017-07-22 00:44:42 +00:00
/* Initialize HSS context */
2017-04-06 11:44:52 +00:00
memset(&self, 0, sizeof(hss_context_t));
self.fd_config = &g_fd_conf;
2017-03-02 13:47:43 +00:00
rv = mutex_create(&self.db_lock, MUTEX_DEFAULT);
d_assert(rv == CORE_OK, return CORE_ERROR,);
2017-07-22 01:52:13 +00:00
2017-07-22 00:44:42 +00:00
context_initialized = 1;
2017-07-21 08:38:25 +00:00
2017-03-02 02:43:26 +00:00
return CORE_OK;
}
2017-07-22 00:44:42 +00:00
status_t hss_context_final(void)
2017-04-10 06:56:01 +00:00
{
2017-07-22 00:44:42 +00:00
d_assert(context_initialized == 1, return CORE_ERROR,
"HSS context already has been finalized");
2017-04-10 06:56:01 +00:00
2017-07-22 01:52:13 +00:00
mutex_delete(self.db_lock);
2017-07-22 00:44:42 +00:00
context_initialized = 0;
2017-04-10 06:56:01 +00:00
2017-07-22 00:44:42 +00:00
return CORE_OK;
2017-04-10 06:56:01 +00:00
}
2017-07-30 13:29:27 +00:00
static status_t hss_context_prepare()
{
self.fd_config->cnf_port = DIAMETER_PORT;
self.fd_config->cnf_port_tls = DIAMETER_SECURE_PORT;
2017-07-30 13:29:27 +00:00
return CORE_OK;
}
static status_t hss_context_validation()
{
if (self.fd_conf_path == NULL &&
(self.fd_config->cnf_diamid == NULL ||
self.fd_config->cnf_diamrlm == NULL ||
self.fd_config->cnf_addr == NULL))
2017-07-30 13:29:27 +00:00
{
d_error("No hss.freeDiameter in '%s'", context_self()->config.path);
return CORE_ERROR;
2017-07-30 13:29:27 +00:00
}
return CORE_OK;
}
status_t hss_context_parse_config()
{
status_t rv;
config_t *config = &context_self()->config;
2017-11-29 00:51:34 +00:00
yaml_document_t *document = NULL;
yaml_iter_t root_iter;
2017-07-30 13:29:27 +00:00
2017-11-29 00:51:34 +00:00
d_assert(config, return CORE_ERROR,);
document = config->document;
d_assert(document, return CORE_ERROR,);
2017-07-30 13:29:27 +00:00
rv = hss_context_prepare();
if (rv != CORE_OK) return rv;
2017-11-29 00:51:34 +00:00
yaml_iter_init(&root_iter, document);
while(yaml_iter_next(&root_iter))
2017-07-30 13:29:27 +00:00
{
2017-11-29 00:51:34 +00:00
const char *root_key = yaml_iter_key(&root_iter);
d_assert(root_key, return CORE_ERROR,);
if (!strcmp(root_key, "hss"))
2017-07-30 13:29:27 +00:00
{
2017-11-29 00:51:34 +00:00
yaml_iter_t hss_iter;
yaml_iter_recurse(&root_iter, &hss_iter);
while(yaml_iter_next(&hss_iter))
2017-07-30 13:29:27 +00:00
{
2017-11-29 00:51:34 +00:00
const char *hss_key = yaml_iter_key(&hss_iter);
d_assert(hss_key, return CORE_ERROR,);
if (!strcmp(hss_key, "freeDiameter"))
2017-07-30 13:29:27 +00:00
{
yaml_node_t *node =
yaml_document_get_node(document, hss_iter.pair->value);
d_assert(node, return CORE_ERROR,);
if (node->type == YAML_SCALAR_NODE)
{
self.fd_conf_path = yaml_iter_value(&hss_iter);
}
else if (node->type == YAML_MAPPING_NODE)
{
yaml_iter_t fd_iter;
yaml_iter_recurse(&hss_iter, &fd_iter);
while(yaml_iter_next(&fd_iter))
{
const char *fd_key = yaml_iter_key(&fd_iter);
d_assert(fd_key, return CORE_ERROR,);
if (!strcmp(fd_key, "identity"))
{
self.fd_config->cnf_diamid =
yaml_iter_value(&fd_iter);
}
else if (!strcmp(fd_key, "realm"))
{
self.fd_config->cnf_diamrlm =
yaml_iter_value(&fd_iter);
}
else if (!strcmp(fd_key, "port"))
{
const char *v = yaml_iter_value(&fd_iter);
if (v) self.fd_config->cnf_port = atoi(v);
}
else if (!strcmp(fd_key, "sec_port"))
{
const char *v = yaml_iter_value(&fd_iter);
if (v) self.fd_config->cnf_port_tls = atoi(v);
}
else if (!strcmp(fd_key, "no_sctp"))
{
self.fd_config->cnf_flags.no_sctp =
yaml_iter_bool(&fd_iter);
}
else if (!strcmp(fd_key, "listen_on"))
{
self.fd_config->cnf_addr =
yaml_iter_value(&fd_iter);
}
else if (!strcmp(fd_key, "load_extension"))
{
yaml_iter_t ext_array, ext_iter;
yaml_iter_recurse(&fd_iter, &ext_array);
do
{
const char *module = NULL;
const char *conf = NULL;
if (yaml_iter_type(&ext_array) ==
YAML_MAPPING_NODE)
{
memcpy(&ext_iter, &ext_array,
sizeof(yaml_iter_t));
}
else if (yaml_iter_type(&ext_array) ==
YAML_SEQUENCE_NODE)
{
if (!yaml_iter_next(&ext_array))
break;
yaml_iter_recurse(
&ext_array, &ext_iter);
}
else if (yaml_iter_type(&ext_array) ==
YAML_SCALAR_NODE)
{
break;
}
else
d_assert(0, return CORE_ERROR,);
while(yaml_iter_next(&ext_iter))
{
const char *ext_key =
yaml_iter_key(&ext_iter);
d_assert(ext_key,
return CORE_ERROR,);
if (!strcmp(ext_key, "module"))
{
module = yaml_iter_value(&ext_iter);
}
else if (!strcmp(ext_key, "conf"))
{
conf = yaml_iter_value(&ext_iter);
}
else
d_warn("unknown key `%s`", ext_key);
}
if (module)
{
self.fd_config->
ext[self.fd_config->num_of_ext].
module = module;
self.fd_config->
ext[self.fd_config->num_of_ext].
conf = conf;
self.fd_config->num_of_ext++;
}
} while(yaml_iter_type(&ext_array) ==
YAML_SEQUENCE_NODE);
}
else if (!strcmp(fd_key, "connect"))
{
yaml_iter_t conn_array, conn_iter;
yaml_iter_recurse(&fd_iter, &conn_array);
do
{
const char *identity = NULL;
const char *addr = NULL;
c_uint16_t port = 0;
if (yaml_iter_type(&conn_array) ==
YAML_MAPPING_NODE)
{
memcpy(&conn_iter, &conn_array,
sizeof(yaml_iter_t));
}
else if (yaml_iter_type(&conn_array) ==
YAML_SEQUENCE_NODE)
{
if (!yaml_iter_next(&conn_array))
break;
yaml_iter_recurse(&conn_array, &conn_iter);
}
else if (yaml_iter_type(&conn_array) ==
YAML_SCALAR_NODE)
{
break;
}
else
d_assert(0, return CORE_ERROR,);
while(yaml_iter_next(&conn_iter))
{
const char *conn_key =
yaml_iter_key(&conn_iter);
d_assert(conn_key,
return CORE_ERROR,);
if (!strcmp(conn_key, "identity"))
{
identity = yaml_iter_value(&conn_iter);
}
else if (!strcmp(conn_key, "addr"))
{
addr = yaml_iter_value(&conn_iter);
}
else if (!strcmp(conn_key, "port"))
{
const char *v =
yaml_iter_value(&conn_iter);
if (v) port = atoi(v);
}
else
d_warn("unknown key `%s`", conn_key);
}
if (identity && addr)
{
self.fd_config->
conn[self.fd_config->num_of_conn].
identity = identity;
self.fd_config->
conn[self.fd_config->num_of_conn].
addr = addr;
self.fd_config->
conn[self.fd_config->num_of_conn].
port = port;
self.fd_config->num_of_conn++;
}
} while(yaml_iter_type(&conn_array) ==
YAML_SEQUENCE_NODE);
}
else
d_warn("unknown key `%s`", fd_key);
}
}
2017-07-30 13:29:27 +00:00
}
2017-11-29 00:51:34 +00:00
else
d_warn("unknown key `%s`", hss_key);
2017-07-30 13:29:27 +00:00
}
}
}
rv = hss_context_validation();
if (rv != CORE_OK) return rv;
return CORE_OK;
}
2017-07-31 13:35:25 +00:00
status_t hss_context_setup_trace_module()
{
2018-01-23 07:02:35 +00:00
int app = context_self()->logger.trace.app;
2017-11-29 05:44:14 +00:00
int diameter = context_self()->logger.trace.diameter;
2018-01-23 07:02:35 +00:00
if (app)
{
extern int _hss_context;
d_trace_level(&_hss_context, app);
}
2017-07-31 13:35:25 +00:00
2017-11-29 05:44:14 +00:00
if (diameter)
2017-07-31 13:35:25 +00:00
{
2017-08-25 11:31:08 +00:00
extern int _hss_fd_path;
2017-11-29 05:44:14 +00:00
d_trace_level(&_hss_fd_path, diameter);
extern int _fd_init;
2017-11-29 05:44:14 +00:00
d_trace_level(&_fd_init, diameter);
extern int _fd_logger;
2017-11-29 05:44:14 +00:00
d_trace_level(&_fd_logger, diameter);
}
2017-07-31 13:35:25 +00:00
return CORE_OK;
}
2017-07-22 00:44:42 +00:00
status_t hss_db_init()
2017-04-10 06:56:01 +00:00
{
2017-07-22 00:44:42 +00:00
if (context_self()->db_client && context_self()->db_name)
2017-04-10 06:56:01 +00:00
{
2017-07-22 00:44:42 +00:00
self.subscriberCollection = mongoc_client_get_collection(
context_self()->db_client,
context_self()->db_name, "subscribers");
d_assert(self.subscriberCollection, return CORE_ERROR,
"Couldn't find Subscriber Collection in '%s'",
2017-08-24 08:05:10 +00:00
context_self()->db_name);
2017-04-10 06:56:01 +00:00
}
return CORE_OK;
}
2017-07-22 00:44:42 +00:00
status_t hss_db_final()
2017-04-10 06:56:01 +00:00
{
2017-07-22 00:44:42 +00:00
if (self.subscriberCollection)
2017-04-10 06:56:01 +00:00
{
2017-07-22 00:44:42 +00:00
mongoc_collection_destroy(self.subscriberCollection);
2017-04-10 06:56:01 +00:00
}
2017-07-22 00:44:42 +00:00
return CORE_OK;
2017-04-10 06:56:01 +00:00
}
2017-07-22 00:44:42 +00:00
status_t hss_db_auth_info(
char *imsi_bcd, hss_db_auth_info_t *auth_info)
2017-04-10 06:56:01 +00:00
{
2017-07-22 01:52:13 +00:00
status_t rv = CORE_OK;
mongoc_cursor_t *cursor = NULL;
bson_t *query = NULL;
2017-07-22 00:44:42 +00:00
bson_error_t error;
const bson_t *document;
bson_iter_t iter;
bson_iter_t inner_iter;
char buf[HSS_KEY_LEN];
char *utf8 = NULL;
c_uint32_t length = 0;
2017-04-10 06:56:01 +00:00
2017-07-22 00:44:42 +00:00
d_assert(imsi_bcd, return CORE_ERROR, "Null param");
d_assert(auth_info, return CORE_ERROR, "Null param");
2017-04-10 06:56:01 +00:00
2017-07-22 01:52:13 +00:00
mutex_lock(self.db_lock);
2017-07-22 00:44:42 +00:00
query = BCON_NEW("imsi", BCON_UTF8(imsi_bcd));
#if MONGOC_MAJOR_VERSION >= 1 && MONGOC_MINOR_VERSION >= 5
2017-07-22 00:44:42 +00:00
cursor = mongoc_collection_find_with_opts(
self.subscriberCollection, query, NULL, NULL);
#else
cursor = mongoc_collection_find(self.subscriberCollection,
MONGOC_QUERY_NONE, 0, 0, 0, query, NULL, NULL);
#endif
2017-04-10 02:29:46 +00:00
if (!mongoc_cursor_next(cursor, &document))
{
2018-01-23 06:38:07 +00:00
d_warn("Cannot find IMSI in DB : %s", imsi_bcd);
rv = CORE_ERROR;
goto out;
}
2017-08-24 08:05:10 +00:00
2017-07-22 00:44:42 +00:00
if (mongoc_cursor_error(cursor, &error))
{
d_error("Cursor Failure: %s", error.message);
2017-04-10 02:29:46 +00:00
2017-07-22 01:52:13 +00:00
rv = CORE_ERROR;
goto out;
2017-07-22 00:44:42 +00:00
}
2017-04-10 02:29:46 +00:00
2017-07-22 00:44:42 +00:00
if (!bson_iter_init_find(&iter, document, "security"))
{
d_error("No 'security' field in this document");
2017-04-10 02:29:46 +00:00
2017-07-22 01:52:13 +00:00
rv = CORE_ERROR;
goto out;
2017-07-22 00:44:42 +00:00
}
2017-04-10 02:29:46 +00:00
2017-07-22 00:44:42 +00:00
memset(auth_info, 0, sizeof(hss_db_auth_info_t));
bson_iter_recurse(&iter, &inner_iter);
while(bson_iter_next(&inner_iter))
{
const char *key = bson_iter_key(&inner_iter);
if (!strcmp(key, "k") && BSON_ITER_HOLDS_UTF8(&inner_iter))
{
utf8 = (char *)bson_iter_utf8(&inner_iter, &length);
memcpy(auth_info->k, CORE_HEX(utf8, length, buf), HSS_KEY_LEN);
}
2017-10-25 05:37:12 +00:00
else if (!strcmp(key, "opc") && BSON_ITER_HOLDS_UTF8(&inner_iter))
{
utf8 = (char *)bson_iter_utf8(&inner_iter, &length);
auth_info->use_opc = 1;
memcpy(auth_info->opc, CORE_HEX(utf8, length, buf), HSS_KEY_LEN);
}
2017-07-22 00:44:42 +00:00
else if (!strcmp(key, "op") && BSON_ITER_HOLDS_UTF8(&inner_iter))
{
utf8 = (char *)bson_iter_utf8(&inner_iter, &length);
memcpy(auth_info->op, CORE_HEX(utf8, length, buf), HSS_KEY_LEN);
}
else if (!strcmp(key, "amf") && BSON_ITER_HOLDS_UTF8(&inner_iter))
{
utf8 = (char *)bson_iter_utf8(&inner_iter, &length);
memcpy(auth_info->amf, CORE_HEX(utf8, length, buf), HSS_AMF_LEN);
}
else if (!strcmp(key, "rand") && BSON_ITER_HOLDS_UTF8(&inner_iter))
{
utf8 = (char *)bson_iter_utf8(&inner_iter, &length);
memcpy(auth_info->rand, CORE_HEX(utf8, length, buf), RAND_LEN);
}
else if (!strcmp(key, "sqn") && BSON_ITER_HOLDS_INT64(&inner_iter))
{
auth_info->sqn = bson_iter_int64(&inner_iter);
}
}
2017-07-22 01:52:13 +00:00
out:
if (query) bson_destroy(query);
if (cursor) mongoc_cursor_destroy(cursor);
2017-04-10 02:29:46 +00:00
2017-07-22 01:52:13 +00:00
mutex_unlock(self.db_lock);
return rv;
2017-04-10 02:29:46 +00:00
}
2017-07-22 00:44:42 +00:00
status_t hss_db_update_rand_and_sqn(
char *imsi_bcd, c_uint8_t *rand, c_uint64_t sqn)
2017-04-10 02:29:46 +00:00
{
2017-07-22 01:52:13 +00:00
status_t rv = CORE_OK;
bson_t *query = NULL;
bson_t *update = NULL;
2017-07-22 00:44:42 +00:00
bson_error_t error;
char printable_rand[128];
d_assert(rand, return CORE_ERROR, "Null param");
core_hex_to_ascii(rand, RAND_LEN, printable_rand, sizeof(printable_rand));
2017-07-22 01:52:13 +00:00
mutex_lock(self.db_lock);
2017-07-22 00:44:42 +00:00
query = BCON_NEW("imsi", BCON_UTF8(imsi_bcd));
update = BCON_NEW("$set",
"{",
"security.rand", printable_rand,
"security.sqn", BCON_INT64(sqn),
"}");
if (!mongoc_collection_update(self.subscriberCollection,
MONGOC_UPDATE_NONE, query, update, NULL, &error))
2017-04-10 02:29:46 +00:00
{
2017-07-22 00:44:42 +00:00
d_error("mongoc_collection_update() failure: %s", error.message);
2017-04-10 02:29:46 +00:00
2017-07-22 01:52:13 +00:00
rv = CORE_ERROR;
2017-04-10 02:29:46 +00:00
}
2017-07-22 01:52:13 +00:00
if (query) bson_destroy(query);
if (update) bson_destroy(update);
2017-07-22 00:44:42 +00:00
2017-07-22 01:52:13 +00:00
mutex_unlock(self.db_lock);
return rv;
2017-04-10 02:29:46 +00:00
}
2017-07-22 00:44:42 +00:00
status_t hss_db_increment_sqn(char *imsi_bcd)
2017-04-10 02:29:46 +00:00
{
2017-07-22 01:52:13 +00:00
status_t rv = CORE_OK;
bson_t *query = NULL;
bson_t *update = NULL;
2017-07-22 00:44:42 +00:00
bson_error_t error;
c_uint64_t max_sqn = HSS_MAX_SQN;
2017-07-22 00:44:42 +00:00
2017-07-22 01:52:13 +00:00
mutex_lock(self.db_lock);
2017-07-22 00:44:42 +00:00
2017-07-22 01:52:13 +00:00
query = BCON_NEW("imsi", BCON_UTF8(imsi_bcd));
2017-07-22 00:44:42 +00:00
update = BCON_NEW("$inc",
"{",
"security.sqn", BCON_INT64(32),
"}");
if (!mongoc_collection_update(self.subscriberCollection,
MONGOC_UPDATE_NONE, query, update, NULL, &error))
2017-04-10 02:29:46 +00:00
{
2017-07-22 00:44:42 +00:00
d_error("mongoc_collection_update() failure: %s", error.message);
2017-04-10 02:29:46 +00:00
2017-07-22 01:52:13 +00:00
rv = CORE_ERROR;
goto out;
2017-04-10 02:29:46 +00:00
}
2017-07-22 00:44:42 +00:00
bson_destroy(update);
update = BCON_NEW("$bit",
"{",
"security.sqn",
"{", "and", BCON_INT64(max_sqn), "}",
"}");
if (!mongoc_collection_update(self.subscriberCollection,
MONGOC_UPDATE_NONE, query, update, NULL, &error))
2017-04-10 02:29:46 +00:00
{
2017-07-22 00:44:42 +00:00
d_error("mongoc_collection_update() failure: %s", error.message);
2017-04-10 02:29:46 +00:00
2017-07-22 01:52:13 +00:00
rv = CORE_ERROR;
2017-04-10 02:29:46 +00:00
}
2017-07-22 01:52:13 +00:00
out:
if (query) bson_destroy(query);
if (update) bson_destroy(update);
mutex_unlock(self.db_lock);
2017-03-02 02:43:26 +00:00
2017-07-22 04:05:43 +00:00
return rv;
2017-03-02 02:43:26 +00:00
}
2017-07-22 00:44:42 +00:00
status_t hss_db_subscription_data(
2017-08-25 11:31:08 +00:00
char *imsi_bcd, s6a_subscription_data_t *subscription_data)
2017-03-02 02:43:26 +00:00
{
2017-07-22 04:05:43 +00:00
status_t rv = CORE_OK;
2017-07-22 01:52:13 +00:00
mongoc_cursor_t *cursor = NULL;
bson_t *query = NULL;
2017-07-22 00:44:42 +00:00
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");
2017-07-22 01:52:13 +00:00
mutex_lock(self.db_lock);
2017-07-22 00:44:42 +00:00
query = BCON_NEW("imsi", BCON_UTF8(imsi_bcd));
#if MONGOC_MAJOR_VERSION >= 1 && MONGOC_MINOR_VERSION >= 5
2017-07-22 00:44:42 +00:00
cursor = mongoc_collection_find_with_opts(
self.subscriberCollection, query, NULL, NULL);
#else
cursor = mongoc_collection_find(self.subscriberCollection,
MONGOC_QUERY_NONE, 0, 0, 0, query, NULL, NULL);
#endif
2017-07-22 00:44:42 +00:00
2017-08-24 08:05:10 +00:00
if (!mongoc_cursor_next(cursor, &document))
{
d_error("Cannot find IMSI in DB : %s", imsi_bcd);
rv = CORE_ERROR;
goto out;
}
2017-07-22 00:44:42 +00:00
if (mongoc_cursor_error(cursor, &error))
2017-03-02 02:43:26 +00:00
{
2017-07-22 00:44:42 +00:00
d_error("Cursor Failure: %s", error.message);
2017-03-02 02:43:26 +00:00
2017-07-22 01:52:13 +00:00
rv = CORE_ERROR;
goto out;
2017-03-02 02:43:26 +00:00
}
2017-07-22 00:44:42 +00:00
if (!bson_iter_init(&iter, document))
2017-03-02 02:43:26 +00:00
{
2017-07-22 00:44:42 +00:00
d_error("bson_iter_init failed in this document");
2017-07-22 01:52:13 +00:00
rv = CORE_ERROR;
goto out;
2017-03-02 02:43:26 +00:00
}
2017-08-25 11:31:08 +00:00
memset(subscription_data, 0, sizeof(s6a_subscription_data_t));
2017-07-22 00:44:42 +00:00
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, "subscribed_rau_tau_timer") &&
BSON_ITER_HOLDS_INT32(&iter))
{
subscription_data->subscribed_rau_tau_timer =
bson_iter_int32(&iter);
}
2017-08-22 04:47:20 +00:00
else if (!strcmp(key, "ambr") &&
2017-07-22 00:44:42 +00:00
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);
2017-08-22 04:47:20 +00:00
if (!strcmp(child1_key, "uplink") &&
BSON_ITER_HOLDS_INT64(&child1_iter))
2017-07-22 00:44:42 +00:00
{
subscription_data->ambr.uplink =
bson_iter_int64(&child1_iter) * 1024;
2017-07-22 00:44:42 +00:00
}
2017-08-22 04:47:20 +00:00
else if (!strcmp(child1_key, "downlink") &&
BSON_ITER_HOLDS_INT64(&child1_iter))
2017-07-22 00:44:42 +00:00
{
subscription_data->ambr.downlink =
bson_iter_int64(&child1_iter) * 1024;
2017-07-22 00:44:42 +00:00
}
}
}
else if (!strcmp(key, "pdn") &&
BSON_ITER_HOLDS_ARRAY(&iter))
{
2017-08-11 08:16:35 +00:00
int pdn_index = 0;
2017-07-22 00:44:42 +00:00
bson_iter_recurse(&iter, &child1_iter);
while(bson_iter_next(&child1_iter))
{
const char *child1_key = bson_iter_key(&child1_iter);
2017-08-11 10:34:27 +00:00
pdn_t *pdn = NULL;
2017-07-22 00:44:42 +00:00
2017-07-22 01:52:13 +00:00
d_assert(child1_key, goto out, "PDN is not ARRAY");
2017-08-11 08:16:35 +00:00
pdn_index = atoi(child1_key);
d_assert(pdn_index < MAX_NUM_OF_SESS,
2017-07-22 01:52:13 +00:00
goto out, "Overflow of PDN number(%d>%d)",
pdn_index, MAX_NUM_OF_SESS);
2017-07-22 00:44:42 +00:00
2017-08-11 08:16:35 +00:00
pdn = &subscription_data->pdn[pdn_index];
2017-07-22 00:44:42 +00:00
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);
2017-08-19 07:49:44 +00:00
core_cpystrn(pdn->apn, utf8,
c_min(length, MAX_APN_LEN)+1);
2017-07-22 00:44:42 +00:00
}
else if (!strcmp(child2_key, "type") &&
BSON_ITER_HOLDS_INT32(&child2_iter))
{
2017-08-11 08:16:35 +00:00
pdn->pdn_type = bson_iter_int32(&child2_iter);
2017-07-22 00:44:42 +00:00
}
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))
{
2017-08-11 08:16:35 +00:00
pdn->qos.qci = bson_iter_int32(&child3_iter);
2017-07-22 00:44:42 +00:00
}
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->qos.arp.priority_level =
2017-07-22 00:44:42 +00:00
bson_iter_int32(&child4_iter);
}
else if (!strcmp(child4_key,
"pre_emption_capability") &&
BSON_ITER_HOLDS_INT32(&child4_iter))
{
pdn->qos.arp.pre_emption_capability =
2017-07-22 00:44:42 +00:00
bson_iter_int32(&child4_iter);
}
else if (!strcmp(child4_key,
"pre_emption_vulnerability") &&
BSON_ITER_HOLDS_INT32(&child4_iter))
{
pdn->qos.arp.pre_emption_vulnerability =
2017-07-22 00:44:42 +00:00
bson_iter_int32(&child4_iter);
}
}
}
}
}
2017-08-22 04:47:20 +00:00
else if (!strcmp(child2_key, "ambr") &&
2017-07-22 00:44:42 +00:00
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);
2017-08-22 04:47:20 +00:00
if (!strcmp(child3_key, "uplink") &&
BSON_ITER_HOLDS_INT64(&child3_iter))
2017-07-22 00:44:42 +00:00
{
pdn->ambr.uplink =
bson_iter_int64(&child3_iter) * 1024;
2017-07-22 00:44:42 +00:00
}
2017-08-22 04:47:20 +00:00
else if (!strcmp(child3_key, "downlink") &&
BSON_ITER_HOLDS_INT64(&child3_iter))
2017-07-22 00:44:42 +00:00
{
pdn->ambr.downlink =
bson_iter_int64(&child3_iter) * 1024;
2017-07-22 00:44:42 +00:00
}
}
}
else if (!strcmp(child2_key, "pgw") &&
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);
2017-12-15 04:47:57 +00:00
if (!strcmp(child3_key, "addr") &&
BSON_ITER_HOLDS_UTF8(&child3_iter))
{
2017-12-15 04:47:57 +00:00
ipsubnet_t ipsub;
const char *v =
bson_iter_utf8(&child3_iter, &length);
rv = core_ipsubnet(&ipsub, v, NULL);
if (rv == CORE_OK)
{
pdn->pgw_ip.ipv4 = 1;
pdn->pgw_ip.both.addr = ipsub.sub[0];
}
}
else if (!strcmp(child3_key, "addr6") &&
BSON_ITER_HOLDS_UTF8(&child3_iter))
{
ipsubnet_t ipsub;
const char *v =
bson_iter_utf8(&child3_iter, &length);
rv = core_ipsubnet(&ipsub, v, NULL);
if (rv == CORE_OK)
{
pdn->pgw_ip.ipv6 = 1;
memcpy(pdn->pgw_ip.both.addr6,
ipsub.sub, sizeof(ipsub.sub));
}
}
}
}
2017-07-22 00:44:42 +00:00
}
2017-08-24 08:05:10 +00:00
pdn_index++;
2017-07-22 00:44:42 +00:00
}
2017-08-24 08:05:10 +00:00
subscription_data->num_of_pdn = pdn_index;
2017-07-22 00:44:42 +00:00
}
}
2017-03-02 02:43:26 +00:00
2017-07-22 01:52:13 +00:00
out:
if (query) bson_destroy(query);
if (cursor) mongoc_cursor_destroy(cursor);
mutex_unlock(self.db_lock);
2017-03-02 02:43:26 +00:00
2017-07-22 04:05:43 +00:00
return rv;
2017-03-02 02:43:26 +00:00
}