[PATCH 04/10] bssgp: Return the gprs_bssgp_pcu instance from create/connect

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/osmocom-net-gprs@lists.osmocom.org/.

Holger Freyther hfreyther at sysmocom.de
Thu Aug 22 07:16:58 UTC 2013


From: Holger Hans Peter Freyther <holger at moiji-mobile.com>

This can be used to install handlers/testcases to register
callbacks and other data.
---
 src/gprs_bssgp_pcu.cpp | 33 +++++++++------------------------
 src/gprs_bssgp_pcu.h   | 19 ++++++++++++++++++-
 src/pcu_l1_if.cpp      |  5 +++--
 3 files changed, 30 insertions(+), 27 deletions(-)

diff --git a/src/gprs_bssgp_pcu.cpp b/src/gprs_bssgp_pcu.cpp
index acd30a4..c332786 100644
--- a/src/gprs_bssgp_pcu.cpp
+++ b/src/gprs_bssgp_pcu.cpp
@@ -21,23 +21,7 @@
 #include <gprs_bssgp_pcu.h>
 #include <pcu_l1_if.h>
 
-struct osmo_pcu {
-	struct gprs_nsvc *nsvc;
-	struct bssgp_bvc_ctx *bctx;
-
-	struct gprs_rlcmac_bts *bts;
-
-	struct osmo_timer_list bvc_timer;
-
-	int nsvc_unblocked;
-
-	int bvc_sig_reset;
-	int bvc_reset;
-	int bvc_unblocked;
-	int exit_on_destroy;
-};
-
-static struct osmo_pcu the_pcu = { 0, };
+static struct gprs_bssgp_pcu the_pcu = { 0, };
 
 extern void *tall_pcu_ctx;
 extern uint16_t spoof_mcc, spoof_mnc;
@@ -591,7 +575,7 @@ static void bvc_timeout(void *_priv)
 }
 
 /* create BSSGP/NS layer instances */
-int gprs_bssgp_create_and_connect(struct gprs_rlcmac_bts *bts,
+struct gprs_bssgp_pcu *gprs_bssgp_create_and_connect(struct gprs_rlcmac_bts *bts,
 	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,
@@ -604,15 +588,16 @@ int gprs_bssgp_create_and_connect(struct gprs_rlcmac_bts *bts,
 	mnc = ((mnc & 0xf00) >> 8) * 100 + ((mnc & 0x0f0) >> 4) * 10 + (mnc & 0x00f);
 	cell_id = ntohs(cell_id);
 
+	/* if already created... return the current address */
 	if (the_pcu.bctx)
-		return 0; /* if already created, must return 0: no error */
+		return &the_pcu;
 
 	the_pcu.bts = bts;
 
 	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;
+		return NULL;
 	}
 	gprs_ns_vty_init(bssgp_nsi);
 	bssgp_nsi->nsip.local_port = local_port;
@@ -621,7 +606,7 @@ int gprs_bssgp_create_and_connect(struct gprs_rlcmac_bts *bts,
 		LOGP(DBSSGP, LOGL_ERROR, "Failed to create socket\n");
 		gprs_ns_destroy(bssgp_nsi);
 		bssgp_nsi = NULL;
-		return -EINVAL;
+		return NULL;
 	}
 
 	dest.sin_family = AF_INET;
@@ -633,7 +618,7 @@ int gprs_bssgp_create_and_connect(struct gprs_rlcmac_bts *bts,
 		LOGP(DBSSGP, LOGL_ERROR, "Failed to create NSVCt\n");
 		gprs_ns_destroy(bssgp_nsi);
 		bssgp_nsi = NULL;
-		return -EINVAL;
+		return NULL;
 	}
 
 	the_pcu.bctx = btsctx_alloc(bvci, nsei);
@@ -642,7 +627,7 @@ int gprs_bssgp_create_and_connect(struct gprs_rlcmac_bts *bts,
 		the_pcu.nsvc = NULL;
 		gprs_ns_destroy(bssgp_nsi);
 		bssgp_nsi = NULL;
-		return -EINVAL;
+		return NULL;
 	}
 	the_pcu.bctx->ra_id.mcc = spoof_mcc ? : mcc;
 	the_pcu.bctx->ra_id.mnc = spoof_mnc ? : mnc;
@@ -655,7 +640,7 @@ int gprs_bssgp_create_and_connect(struct gprs_rlcmac_bts *bts,
 	the_pcu.bvc_timer.cb = bvc_timeout;
 
 
-	return 0;
+	return &the_pcu;
 }
 
 void gprs_bssgp_destroy_or_exit(void)
diff --git a/src/gprs_bssgp_pcu.h b/src/gprs_bssgp_pcu.h
index 15c8d9f..2d96032 100644
--- a/src/gprs_bssgp_pcu.h
+++ b/src/gprs_bssgp_pcu.h
@@ -41,7 +41,24 @@ struct bssgp_bvc_ctx *btsctx_alloc(uint16_t bvci, uint16_t nsei);
 #define NS_HDR_LEN 4
 #define IE_LLC_PDU 14
 
-int gprs_bssgp_create_and_connect(struct gprs_rlcmac_bts *bts, uint16_t local_port,
+struct gprs_bssgp_pcu {
+	struct gprs_nsvc *nsvc;
+	struct bssgp_bvc_ctx *bctx;
+
+	struct gprs_rlcmac_bts *bts;
+
+	struct osmo_timer_list bvc_timer;
+
+	int nsvc_unblocked;
+
+	int bvc_sig_reset;
+	int bvc_reset;
+	int bvc_unblocked;
+	int exit_on_destroy;
+};
+
+struct gprs_bssgp_pcu *gprs_bssgp_create_and_connect(struct gprs_rlcmac_bts *bts,
+		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, uint16_t cell_id);
diff --git a/src/pcu_l1_if.cpp b/src/pcu_l1_if.cpp
index e53b683..43bd36e 100644
--- a/src/pcu_l1_if.cpp
+++ b/src/pcu_l1_if.cpp
@@ -336,6 +336,7 @@ int flush_pdch(struct gprs_rlcmac_pdch *pdch, uint8_t trx, uint8_t ts)
 static int pcu_rx_info_ind(struct gsm_pcu_if_info_ind *info_ind)
 {
 	struct gprs_rlcmac_bts *bts = gprs_rlcmac_bts;
+	struct gprs_bssgp_pcu *pcu;
 	struct gprs_rlcmac_pdch *pdch;
 	struct in_addr ia;
 	int rc = 0;
@@ -418,12 +419,12 @@ bssgp_failed:
 	ia.s_addr = htonl(info_ind->remote_ip[0]);
 	LOGP(DL1IF, LOGL_DEBUG, " remote_ip=%s\n", inet_ntoa(ia));
 
-	rc = gprs_bssgp_create_and_connect(bts, info_ind->local_port[0],
+	pcu = gprs_bssgp_create_and_connect(bts, info_ind->local_port[0],
 		info_ind->remote_ip[0], info_ind->remote_port[0],
 		info_ind->nsei, info_ind->nsvci[0], info_ind->bvci,
 		info_ind->mcc, info_ind->mnc, info_ind->lac, info_ind->rac,
 		info_ind->cell_id);
-	if (rc < 0) {
+	if (!pcu) {
 		LOGP(DL1IF, LOGL_NOTICE, "SGSN not available\n");
 		goto bssgp_failed;
 	}
-- 
1.8.3.2





More information about the osmocom-net-gprs mailing list