aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Eversberg <jolly@eversberg.eu>2013-06-30 10:12:01 +0200
committerAndreas Eversberg <jolly@eversberg.eu>2013-06-30 10:12:01 +0200
commit2a2ea42fca583a81e47c101eb0d20f9e83e7b3bf (patch)
tree07b791cc82af68251a5470e8227cfe816e44b8b3
parent65d589bb24dd2f0494f5d791046d6ce63829e49b (diff)
Create NS instance at startup time and open/close it at BTS start/stopjolly/testing
The NS instance must be created at startup time before the config is parsed, so the NS VTY elements will exist at this point. The NS instance must persist. Then during BTS start, the NS instance is opened/bound/connected to the socket that is specified by BTS. Then during BTS stop, the NS instance is closed, but the NS instance sill exists. At PCU stop, the NS instance is completely destroyed.
-rw-r--r--src/gprs_bssgp_pcu.cpp25
-rw-r--r--src/gprs_bssgp_pcu.h2
-rw-r--r--src/pcu_main.cpp10
3 files changed, 20 insertions, 17 deletions
diff --git a/src/gprs_bssgp_pcu.cpp b/src/gprs_bssgp_pcu.cpp
index 54753b8..b067b82 100644
--- a/src/gprs_bssgp_pcu.cpp
+++ b/src/gprs_bssgp_pcu.cpp
@@ -468,7 +468,7 @@ int bssgp_prim_cb(struct osmo_prim_hdr *oph, void *ctx)
return 0;
}
-static int sgsn_ns_cb(enum gprs_ns_evt event, struct gprs_nsvc *nsvc, struct msgb *msg, uint16_t bvci)
+int sgsn_ns_cb(enum gprs_ns_evt event, struct gprs_nsvc *nsvc, struct msgb *msg, uint16_t bvci)
{
int rc = 0;
switch (event) {
@@ -590,18 +590,11 @@ int gprs_bssgp_create(uint16_t local_port, uint32_t sgsn_ip,
if (bctx)
return 0; /* if already created, must return 0: no error */
- bssgp_nsi = gprs_ns_instantiate(&sgsn_ns_cb, tall_pcu_ctx);
- if (!bssgp_nsi) {
- LOGP(DBSSGP, LOGL_ERROR, "Failed to create NS instance\n");
- return -EINVAL;
- }
- gprs_ns_vty_init(bssgp_nsi);
bssgp_nsi->nsip.local_port = local_port;
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 -EINVAL;
}
@@ -612,17 +605,16 @@ int gprs_bssgp_create(uint16_t local_port, uint32_t sgsn_ip,
nsvc = gprs_ns_nsip_connect(bssgp_nsi, &dest, nsei, nsvci);
if (!nsvc) {
LOGP(DBSSGP, LOGL_ERROR, "Failed to create NSVCt\n");
- gprs_ns_destroy(bssgp_nsi);
- bssgp_nsi = NULL;
+ gprs_ns_close(bssgp_nsi);
return -EINVAL;
}
bctx = btsctx_alloc(bvci, nsei);
if (!bctx) {
LOGP(DBSSGP, LOGL_ERROR, "Failed to create BSSGP context\n");
+ gprs_nsvc_delete(nsvc);
nsvc = NULL;
- gprs_ns_destroy(bssgp_nsi);
- bssgp_nsi = NULL;
+ gprs_ns_close(bssgp_nsi);
return -EINVAL;
}
bctx->ra_id.mcc = spoof_mcc ? : mcc;
@@ -637,13 +629,12 @@ int gprs_bssgp_create(uint16_t local_port, uint32_t sgsn_ip,
bvc_timer.cb = bvc_timeout;
-
return 0;
}
void gprs_bssgp_destroy(void)
{
- if (!bssgp_nsi)
+ if (!bctx)
return;
if (osmo_timer_pending(&bvc_timer))
@@ -651,6 +642,7 @@ void gprs_bssgp_destroy(void)
osmo_signal_unregister_handler(SS_L_NS, nsvc_signal_cb, NULL);
+ gprs_nsvc_delete(nsvc);
nsvc = NULL;
/* FIXME: move this to libgb: btsctx_free() */
@@ -660,7 +652,6 @@ void gprs_bssgp_destroy(void)
/* FIXME: blocking... */
- gprs_ns_destroy(bssgp_nsi);
- bssgp_nsi = NULL;
+ gprs_ns_close(bssgp_nsi);
}
diff --git a/src/gprs_bssgp_pcu.h b/src/gprs_bssgp_pcu.h
index d669c3a..9d3e27c 100644
--- a/src/gprs_bssgp_pcu.h
+++ b/src/gprs_bssgp_pcu.h
@@ -51,6 +51,8 @@ int gprs_bssgp_pcu_rx_sign(struct msgb *msg, struct tlv_parsed *tp, struct bssgp
int gprs_bssgp_pcu_rcvmsg(struct msgb *msg);
+int sgsn_ns_cb(enum gprs_ns_evt event, struct gprs_nsvc *nsvc, struct msgb *msg, uint16_t bvci);
+
int gprs_bssgp_create(uint16_t local_port, uint32_t sgsn_ip, uint16_t
sgsn_port, uint16_t nsei, uint16_t nsvci, uint16_t bvci,
uint16_t mcc, uint16_t mnc, uint16_t lac, uint16_t rac,
diff --git a/src/pcu_main.cpp b/src/pcu_main.cpp
index 0a37043..b27daf5 100644
--- a/src/pcu_main.cpp
+++ b/src/pcu_main.cpp
@@ -184,6 +184,13 @@ int main(int argc, char *argv[])
vty_init(&pcu_vty_info);
pcu_vty_init(&gprs_log_info);
+ bssgp_nsi = gprs_ns_instantiate(&sgsn_ns_cb, tall_pcu_ctx);
+ if (!bssgp_nsi) {
+ LOGP(DBSSGP, LOGL_ERROR, "Failed to create NS instance\n");
+ return -EINVAL;
+ }
+ gprs_ns_vty_init(bssgp_nsi);
+
handle_options(argc, argv);
if ((!!spoof_mcc) + (!!spoof_mnc) == 1) {
fprintf(stderr, "--mcc and --mnc must be specified "
@@ -250,6 +257,9 @@ int main(int argc, char *argv[])
pcu_l1if_close();
+ gprs_ns_destroy(bssgp_nsi);
+ bssgp_nsi = NULL;
+
flush_timing_advance();
talloc_free(gprs_rlcmac_bts);