diff --git a/src/gprs_bssgp_pcu.cpp b/src/gprs_bssgp_pcu.cpp index 50f10db9..22abc6bd 100644 --- a/src/gprs_bssgp_pcu.cpp +++ b/src/gprs_bssgp_pcu.cpp @@ -875,11 +875,6 @@ static int gprs_ns_reconnect(struct gprs_nsvc *nsvc) { struct gprs_nsvc *nsvc2; - if (!bssgp_nsi) { - LOGP(DBSSGP, LOGL_ERROR, "NS instance does not exist\n"); - return -EINVAL; - } - if (nsvc != the_pcu.nsvc) { LOGP(DBSSGP, LOGL_ERROR, "NSVC is invalid\n"); return -EBADF; @@ -913,12 +908,6 @@ struct gprs_bssgp_pcu *gprs_bssgp_create_and_connect(struct gprs_rlcmac_bts *bts the_pcu.bts = bts; - bssgp_nsi = gprs_ns_instantiate(&gprs_bssgp_ns_cb, tall_pcu_ctx); - if (!bssgp_nsi) { - LOGP(DBSSGP, LOGL_ERROR, "Failed to create NS instance\n"); - return NULL; - } - gprs_ns_vty_init(bssgp_nsi); /* don't specify remote IP/port if SNS dialect is in use; Doing so would * issue a connect() on the socket, which prevents us to dynamically communicate * with any number of IP-SNS endpoints on the SGSN side */ @@ -930,8 +919,7 @@ struct gprs_bssgp_pcu *gprs_bssgp_create_and_connect(struct gprs_rlcmac_bts *bts rc = gprs_ns_nsip_listen(bssgp_nsi); if (rc < 0) { LOGP(DBSSGP, LOGL_ERROR, "Failed to create socket\n"); - gprs_ns_destroy(bssgp_nsi); - bssgp_nsi = NULL; + gprs_ns_close(bssgp_nsi); return NULL; } @@ -945,8 +933,7 @@ struct gprs_bssgp_pcu *gprs_bssgp_create_and_connect(struct gprs_rlcmac_bts *bts the_pcu.nsvc = gprs_ns_nsip_connect(bssgp_nsi, &dest, nsei, nsvci); if (!the_pcu.nsvc) { LOGP(DBSSGP, LOGL_ERROR, "Failed to create NSVCt\n"); - gprs_ns_destroy(bssgp_nsi); - bssgp_nsi = NULL; + gprs_ns_close(bssgp_nsi); return NULL; } @@ -954,8 +941,7 @@ struct gprs_bssgp_pcu *gprs_bssgp_create_and_connect(struct gprs_rlcmac_bts *bts if (!the_pcu.bctx) { LOGP(DBSSGP, LOGL_ERROR, "Failed to create BSSGP context\n"); the_pcu.nsvc = NULL; - gprs_ns_destroy(bssgp_nsi); - bssgp_nsi = NULL; + gprs_ns_close(bssgp_nsi); return NULL; } the_pcu.bctx->ra_id.mcc = spoof_mcc ? : mcc; diff --git a/src/pcu_main.cpp b/src/pcu_main.cpp index 1003e3c4..fa075cdf 100644 --- a/src/pcu_main.cpp +++ b/src/pcu_main.cpp @@ -33,6 +33,8 @@ #include #include #include +#include "gprs_bssgp_pcu.h" + extern "C" { #include "pcu_vty.h" #include @@ -291,6 +293,13 @@ int main(int argc, char *argv[]) else fprintf(stderr, "Failed to initialize GSMTAP for %s\n", gsmtap_addr); + bssgp_nsi = gprs_ns_instantiate(&gprs_bssgp_ns_cb, tall_pcu_ctx); + if (!bssgp_nsi) { + LOGP(DBSSGP, LOGL_ERROR, "Failed to create NS instance\n"); + exit(1); + } + gprs_ns_vty_init(bssgp_nsi); + rc = vty_read_config_file(config_file, NULL); if (rc < 0 && config_given) { fprintf(stderr, "Failed to parse the config file: '%s'\n", diff --git a/tests/emu/pcu_emu.cpp b/tests/emu/pcu_emu.cpp index 354a3286..e0190bfb 100644 --- a/tests/emu/pcu_emu.cpp +++ b/tests/emu/pcu_emu.cpp @@ -113,6 +113,13 @@ int main(int argc, char **argv) msgb_talloc_ctx_init(tall_pcu_ctx, 0); osmo_init_logging2(tall_pcu_ctx, &gprs_log_info); + + bssgp_nsi = gprs_ns_instantiate(&gprs_bssgp_ns_cb, tall_pcu_ctx); + if (!bssgp_nsi) { + LOGP(DBSSGP, LOGL_ERROR, "Failed to create NS instance\n"); + abort(); + } + vty_init(&pcu_vty_info); pcu_vty_init(&gprs_log_info); diff --git a/tests/tbf/TbfTest.cpp b/tests/tbf/TbfTest.cpp index 151e7fac..675cf898 100644 --- a/tests/tbf/TbfTest.cpp +++ b/tests/tbf/TbfTest.cpp @@ -447,6 +447,12 @@ static void test_tbf_exhaustion() printf("=== start %s ===\n", __func__); + bssgp_nsi = gprs_ns_instantiate(&gprs_bssgp_ns_cb, tall_pcu_ctx); + if (!bssgp_nsi) { + LOGP(DBSSGP, LOGL_ERROR, "Failed to create NS instance\n"); + abort(); + } + bts = the_bts.bts_data(); setup_bts(&the_bts, ts_no); gprs_bssgp_create_and_connect(bts, 33001, 0, 33001, 1234, 1234, 1234, 1, 1, false, 0, 0, 0); @@ -485,6 +491,12 @@ static void test_tbf_dl_llc_loss() uint8_t buf[19]; + bssgp_nsi = gprs_ns_instantiate(&gprs_bssgp_ns_cb, tall_pcu_ctx); + if (!bssgp_nsi) { + LOGP(DBSSGP, LOGL_ERROR, "Failed to create NS instance\n"); + abort(); + } + printf("=== start %s ===\n", __func__); bts = the_bts.bts_data(); @@ -2171,6 +2183,12 @@ static void test_tbf_gprs_egprs() printf("=== start %s ===\n", __func__); + bssgp_nsi = gprs_ns_instantiate(&gprs_bssgp_ns_cb, tall_pcu_ctx); + if (!bssgp_nsi) { + LOGP(DBSSGP, LOGL_ERROR, "Failed to create NS instance\n"); + abort(); + } + bts = the_bts.bts_data(); setup_bts(&the_bts, ts_no); @@ -2227,6 +2245,12 @@ static void test_tbf_ws() printf("=== start %s ===\n", __func__); + bssgp_nsi = gprs_ns_instantiate(&gprs_bssgp_ns_cb, tall_pcu_ctx); + if (!bssgp_nsi) { + LOGP(DBSSGP, LOGL_ERROR, "Failed to create NS instance\n"); + abort(); + } + bts = the_bts.bts_data(); setup_bts(&the_bts, ts_no); @@ -2264,6 +2288,12 @@ static void test_tbf_update_ws(void) printf("=== start %s ===\n", __func__); + bssgp_nsi = gprs_ns_instantiate(&gprs_bssgp_ns_cb, tall_pcu_ctx); + if (!bssgp_nsi) { + LOGP(DBSSGP, LOGL_ERROR, "Failed to create NS instance\n"); + abort(); + } + bts = the_bts.bts_data(); setup_bts(&the_bts, ts_no);