From 9b1b26e381f9ad91fb3e9617a4d692757178bbd7 Mon Sep 17 00:00:00 2001 From: Daniel Willmann Date: Tue, 28 Feb 2017 18:05:01 +0100 Subject: osmo-bsc_nat: Add functions for MSC config struct Add functions to alloc/find/free MSC config structs. Change-Id: I5879d4d9ee0e1a0a6424ee3e9b214afb07319071 Ticket: SYS#3208 Sponsored-by: On-Waves ehf. --- openbsc/include/openbsc/bsc_nat.h | 5 +++ openbsc/src/osmo-bsc_nat/bsc_nat_utils.c | 59 ++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/openbsc/include/openbsc/bsc_nat.h b/openbsc/include/openbsc/bsc_nat.h index 72264f0ce..5f864bd78 100644 --- a/openbsc/include/openbsc/bsc_nat.h +++ b/openbsc/include/openbsc/bsc_nat.h @@ -354,6 +354,11 @@ void bsc_config_add_lac(struct bsc_config *cfg, int lac); void bsc_config_del_lac(struct bsc_config *cfg, int lac); int bsc_config_handles_lac(struct bsc_config *cfg, int lac); +struct msc_config *msc_config_alloc(struct bsc_nat *nat); +struct msc_config *msc_config_by_num(struct bsc_nat *nat, unsigned num); +struct msc_config *msc_config_by_con(struct bsc_nat *nat, const struct bsc_msc_connection *msc_con); +void msc_config_free(struct msc_config *); + struct bsc_nat *bsc_nat_alloc(void); struct bsc_connection *bsc_connection_alloc(struct bsc_nat *nat); void bsc_nat_set_msc_ip(struct bsc_nat *bsc, const char *ip); diff --git a/openbsc/src/osmo-bsc_nat/bsc_nat_utils.c b/openbsc/src/osmo-bsc_nat/bsc_nat_utils.c index c12b29f1f..41156f941 100644 --- a/openbsc/src/osmo-bsc_nat/bsc_nat_utils.c +++ b/openbsc/src/osmo-bsc_nat/bsc_nat_utils.c @@ -210,6 +210,65 @@ void bsc_config_free(struct bsc_config *cfg) talloc_free(cfg); } +struct msc_config *msc_config_alloc(struct bsc_nat *nat) +{ + struct msc_config *conf = talloc_zero(nat, struct msc_config); + if (!conf) + return NULL; + + conf->main_dest = talloc_zero(conf, struct bsc_msc_dest); + if (!conf->main_dest) { + talloc_free(conf); + return NULL; + } + + conf->nr = nat->num_msc; + conf->nat = nat; + + INIT_LLIST_HEAD(&conf->dests); + + llist_add(&conf->main_dest->list, &conf->dests); + conf->main_dest->ip = talloc_strdup(conf, "127.0.0.1"); + conf->main_dest->port = 5000; + + llist_add_tail(&conf->entry, &nat->msc_configs); + ++nat->num_msc; + + + return conf; +} + +struct msc_config *msc_config_by_num(struct bsc_nat *nat, unsigned num) +{ + struct msc_config *conf; + + llist_for_each_entry(conf, &nat->msc_configs, entry) + if (conf->nr == num) + return conf; + + return NULL; +} + +struct msc_config *msc_config_by_con(struct bsc_nat *nat, const struct bsc_msc_connection *msc_con) +{ + struct msc_config *conf; + + llist_for_each_entry(conf, &nat->msc_configs, entry) + if (conf->msc_con == msc_con) + return conf; + + return NULL; +} + +void msc_config_free(struct msc_config *cfg) +{ + llist_del(&cfg->entry); + + /* Shutdown any connections to the MSC? */ + + talloc_free(cfg); +} + static void _add_lac(void *ctx, struct llist_head *list, int _lac) { struct bsc_lac_entry *lac; -- cgit v1.2.3