Change in libosmocore[master]: Gb/BSSGP: replace hardcoded Tx into NS library by a callback

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/gerrit-log@lists.osmocom.org/.

lynxis lazus gerrit-no-reply at lists.osmocom.org
Tue Aug 4 10:33:09 UTC 2020


lynxis lazus has submitted this change. ( https://gerrit.osmocom.org/c/libosmocore/+/19414 )

Change subject: Gb/BSSGP: replace hardcoded Tx into NS library by a callback
......................................................................

Gb/BSSGP: replace hardcoded Tx into NS library by a callback

Add bssgp_ns_send callback() to set the transmission path into the
NS library. This allows to use the Gb implementation with
the old NS and the new upcoming NS implementation.
Users of the old NS implementation don't have to set the callback as
the default is the old NS implementation.

Only users of the new NS implementation need to set the callback and
the callback data.

Change-Id: I3a498e6a0d68b87fed80c64199b22395796761b4
---
M include/osmocom/gprs/gprs_bssgp.h
M src/gb/Makefile.am
M src/gb/gprs_bssgp.c
M src/gb/gprs_bssgp_bss.c
A src/gb/gprs_bssgp_internal.h
M src/gb/gprs_bssgp_util.c
M src/gb/libosmogb.map
7 files changed, 54 insertions(+), 23 deletions(-)

Approvals:
  laforge: Looks good to me, but someone else must approve
  fixeria: Looks good to me, but someone else must approve
  lynxis lazus: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/include/osmocom/gprs/gprs_bssgp.h b/include/osmocom/gprs/gprs_bssgp.h
index 0f87333..b9d251c 100644
--- a/include/osmocom/gprs/gprs_bssgp.h
+++ b/include/osmocom/gprs/gprs_bssgp.h
@@ -12,7 +12,10 @@
 #include <osmocom/gprs/protocol/gsm_08_18.h>
 
 /* gprs_bssgp_util.c */
+typedef int (*bssgp_bvc_send)(void *ctx, struct msgb *msg);
+
 extern struct gprs_ns_inst *bssgp_nsi;
+void bssgp_set_bssgp_callback(bssgp_bvc_send ns_send, void *data);
 struct msgb *bssgp_msgb_alloc(void);
 struct msgb *bssgp_msgb_copy(const struct msgb *msg, const char *name);
 const char *bssgp_cause_str(enum gprs_bssgp_cause cause);
diff --git a/src/gb/Makefile.am b/src/gb/Makefile.am
index 7248413..125afba 100644
--- a/src/gb/Makefile.am
+++ b/src/gb/Makefile.am
@@ -7,7 +7,7 @@
 AM_CFLAGS = -Wall ${GCC_FVISIBILITY_HIDDEN} -fno-strict-aliasing $(TALLOC_CFLAGS)
 
 # FIXME: this should eventually go into a milenage/Makefile.am
-noinst_HEADERS = common_vty.h gb_internal.h
+noinst_HEADERS = common_vty.h gb_internal.h gprs_bssgp_internal.h
 
 if ENABLE_GB
 lib_LTLIBRARIES = libosmogb.la
diff --git a/src/gb/gprs_bssgp.c b/src/gb/gprs_bssgp.c
index 38794c2..fa4e187 100644
--- a/src/gb/gprs_bssgp.c
+++ b/src/gb/gprs_bssgp.c
@@ -44,6 +44,11 @@
 
 void *bssgp_tall_ctx = NULL;
 
+static int _gprs_ns_sendmsg(void *ctx, struct msgb *msg);
+
+bssgp_bvc_send bssgp_ns_send = _gprs_ns_sendmsg;
+void *bssgp_ns_send_data = NULL;
+
 static const struct rate_ctr_desc bssgp_ctr_description[] = {
 	{ "packets:in",	"Packets at BSSGP Level ( In)" },
 	{ "packets:out","Packets at BSSGP Level (Out)" },
@@ -67,6 +72,13 @@
 static int _bssgp_tx_dl_ud(struct bssgp_flow_control *fc, struct msgb *msg,
 			   uint32_t llc_pdu_len, void *priv);
 
+
+/* callback to be backward compatible with  old users which do not set the bssgp_ns_send function */
+static int _gprs_ns_sendmsg(void *ctx, struct msgb *msg)
+{
+	return gprs_ns_sendmsg(bssgp_nsi, msg);
+}
+
 /* Find a BTS Context based on parsed RA ID and Cell ID */
 struct bssgp_bvc_ctx *btsctx_by_raid_cid(const struct gprs_ra_id *raid, uint16_t cid)
 {
@@ -117,6 +129,12 @@
 	return NULL;
 }
 
+void bssgp_set_bssgp_callback(bssgp_bvc_send ns_send, void *data)
+{
+	bssgp_ns_send = ns_send;
+	bssgp_ns_send_data = data;
+}
+
 struct bssgp_bvc_ctx *btsctx_alloc(uint16_t bvci, uint16_t nsei)
 {
 	struct bssgp_bvc_ctx *ctx;
@@ -163,7 +181,7 @@
 	bgph->pdu_type = BSSGP_PDUT_FLOW_CONTROL_BVC_ACK;
 	msgb_tvlv_put(msg, BSSGP_IE_TAG, 1, &tag);
 
-	return gprs_ns_sendmsg(bssgp_nsi, msg);
+	return bssgp_ns_send(bssgp_ns_send_data, msg);
 }
 
 /* 10.3.7 SUSPEND-ACK PDU */
@@ -182,7 +200,7 @@
 	bssgp_msgb_ra_put(msg, ra_id);
 	msgb_tvlv_put(msg, BSSGP_IE_SUSPEND_REF_NR, 1, &suspend_ref);
 
-	return gprs_ns_sendmsg(bssgp_nsi, msg);
+	return bssgp_ns_send(bssgp_ns_send_data, msg);
 }
 
 /* 10.3.8 SUSPEND-NACK PDU */
@@ -204,7 +222,7 @@
 	if (cause)
 		msgb_tvlv_put(msg, BSSGP_IE_CAUSE, 1, cause);
 
-	return gprs_ns_sendmsg(bssgp_nsi, msg);
+	return bssgp_ns_send(bssgp_ns_send_data, msg);
 }
 
 /* 10.3.10 RESUME-ACK PDU */
@@ -222,7 +240,7 @@
 	bssgp_msgb_tlli_put(msg, tlli);
 	bssgp_msgb_ra_put(msg, ra_id);
 
-	return gprs_ns_sendmsg(bssgp_nsi, msg);
+	return bssgp_ns_send(bssgp_ns_send_data, msg);
 }
 
 /* 10.3.11 RESUME-NACK PDU */
@@ -243,7 +261,7 @@
 	if (cause)
 		msgb_tvlv_put(msg, BSSGP_IE_CAUSE, 1, cause);
 
-	return gprs_ns_sendmsg(bssgp_nsi, msg);
+	return bssgp_ns_send(bssgp_ns_send_data, msg);
 }
 
 uint16_t bssgp_parse_cell_id(struct gprs_ra_id *raid, const uint8_t *buf)
@@ -266,7 +284,7 @@
 }
 
 /* Chapter 8.4 BVC-Reset Procedure */
-static int bssgp_rx_bvc_reset(struct msgb *msg, struct tlv_parsed *tp,	
+static int bssgp_rx_bvc_reset(struct msgb *msg, struct tlv_parsed *tp,
 			      uint16_t ns_bvci)
 {
 	struct osmo_bssgp_prim nmp;
@@ -744,7 +762,7 @@
 static int _bssgp_tx_dl_ud(struct bssgp_flow_control *fc, struct msgb *msg,
 			   uint32_t llc_pdu_len, void *priv)
 {
-	return gprs_ns_sendmsg(bssgp_nsi, msg);
+	return bssgp_ns_send(bssgp_ns_send_data, msg);
 }
 
 /* input function of the flow control implementation, called first
@@ -1286,7 +1304,7 @@
 		msgb_tvlv_put(msg, BSSGP_IE_TMSI, 4, (uint8_t *) &ptmsi);
 	}
 
-	return gprs_ns_sendmsg(bssgp_nsi, msg);
+	return bssgp_ns_send(bssgp_ns_send_data, msg);
 }
 
 void bssgp_set_log_ss(int ss)
diff --git a/src/gb/gprs_bssgp_bss.c b/src/gb/gprs_bssgp_bss.c
index 5a1ffb9..94b1812 100644
--- a/src/gb/gprs_bssgp_bss.c
+++ b/src/gb/gprs_bssgp_bss.c
@@ -34,6 +34,7 @@
 #include <osmocom/gprs/gprs_bssgp_bss.h>
 #include <osmocom/gprs/gprs_ns.h>
 
+#include "gprs_bssgp_internal.h"
 #include "common_vty.h"
 
 #define GSM_IMSI_LENGTH 17
@@ -69,7 +70,7 @@
 	bssgp_msgb_tlli_put(msg, tlli);
 	bssgp_msgb_ra_put(msg, ra_id);
 
-	return gprs_ns_sendmsg(bssgp_nsi, msg);
+	return bssgp_ns_send(bssgp_ns_send_data, msg);
 }
 
 /*! GMM-RESUME.req (Chapter 10.3.9) */
@@ -91,7 +92,7 @@
 
 	msgb_tvlv_put(msg, BSSGP_IE_SUSPEND_REF_NR, 1, &suspend_ref);
 
-	return gprs_ns_sendmsg(bssgp_nsi, msg);
+	return bssgp_ns_send(bssgp_ns_send_data, msg);
 }
 
 /*! Transmit RA-CAPABILITY-UPDATE (10.3.3) */
@@ -113,7 +114,7 @@
 
 	msgb_tvlv_put(msg, BSSGP_IE_TAG, 1, &tag);
 
-	return gprs_ns_sendmsg(bssgp_nsi, msg);
+	return bssgp_ns_send(bssgp_ns_send_data, msg);
 }
 
 /* first common part of RADIO-STATUS */
@@ -141,7 +142,7 @@
 	msgb_tvlv_put(msg, BSSGP_IE_CAUSE, 1, &cause);
 	LOGPC(DBSSGP, LOGL_NOTICE, "CAUSE=%s\n", bssgp_cause_str(cause));
 
-	return gprs_ns_sendmsg(bssgp_nsi, msg);
+	return bssgp_ns_send(bssgp_ns_send_data, msg);
 }
 
 /*! Transmit RADIO-STATUS for TLLI (10.3.5) */
@@ -220,7 +221,7 @@
 		msgb_tvlv_put(msg, BSSGP_IE_BVCI, 2, (uint8_t *) &_bvci_new);
 	msgb_tvlv_put(msg, BSSGP_IE_NUM_OCT_AFF, 3, (uint8_t *) &_oct_aff);
 
-	return gprs_ns_sendmsg(bssgp_nsi, msg);
+	return bssgp_ns_send(bssgp_ns_send_data, msg);
 }
 
 /*! Transmit LLC-DISCARDED (Chapter 10.4.3) */
@@ -246,7 +247,7 @@
 	msgb_tvlv_put(msg, BSSGP_IE_BVCI, 2, (uint8_t *) &_bvci);
 	msgb_tvlv_put(msg, BSSGP_IE_NUM_OCT_AFF, 3, ((uint8_t *) &_oct_aff) + 1);
 
-	return gprs_ns_sendmsg(bssgp_nsi, msg);
+	return bssgp_ns_send(bssgp_ns_send_data, msg);
 }
 
 /*! Transmit a BVC-BLOCK message (Chapter 10.4.8) */
@@ -267,7 +268,7 @@
 	msgb_tvlv_put(msg, BSSGP_IE_BVCI, 2, (uint8_t *) &_bvci);
 	msgb_tvlv_put(msg, BSSGP_IE_CAUSE, 1, &cause);
 
-	return gprs_ns_sendmsg(bssgp_nsi, msg);
+	return bssgp_ns_send(bssgp_ns_send_data, msg);
 }
 
 /*! Transmit a BVC-UNBLOCK message (Chapter 10.4.10) */
@@ -286,7 +287,7 @@
 
 	msgb_tvlv_put(msg, BSSGP_IE_BVCI, 2, (uint8_t *) &_bvci);
 
-	return gprs_ns_sendmsg(bssgp_nsi, msg);
+	return bssgp_ns_send(bssgp_ns_send_data, msg);
 }
 
 /*! Transmit a BVC-RESET message (Chapter 10.4.12) */
@@ -313,7 +314,7 @@
 	}
 	/* Optional: Feature Bitmap */
 
-	return gprs_ns_sendmsg(bssgp_nsi, msg);
+	return bssgp_ns_send(bssgp_ns_send_data, msg);
 }
 int bssgp_tx_bvc_reset(struct bssgp_bvc_ctx *bctx, uint16_t bvci, uint8_t cause)
 {
@@ -389,7 +390,7 @@
 			      sizeof(e_queue_delay),
 			      (uint8_t *) &e_queue_delay);
 
-	return gprs_ns_sendmsg(bssgp_nsi, msg);
+	return bssgp_ns_send(bssgp_ns_send_data, msg);
 }
 
 /*! Transmit a FLOW_CONTROL-MS (Chapter 10.4.6)
@@ -432,7 +433,7 @@
 		msgb_tvlv_put(msg, BSSGP_IE_BUCKET_FULL_RATIO,
 			      1, bucket_full_ratio);
 
-	return gprs_ns_sendmsg(bssgp_nsi, msg);
+	return bssgp_ns_send(bssgp_ns_send_data, msg);
 }
 
 /*! RL-UL-UNITDATA.req (Chapter 10.2.2)
@@ -478,7 +479,7 @@
 	rate_ctr_inc(&bctx->ctrg->ctr[BSSGP_CTR_PKTS_OUT]);
 	rate_ctr_add(&bctx->ctrg->ctr[BSSGP_CTR_BYTES_OUT], msg->len);
 
-	return gprs_ns_sendmsg(bssgp_nsi, msg);
+	return bssgp_ns_send(bssgp_ns_send_data, msg);
 }
 
 /* Parse a single GMM-PAGING.req to a given NSEI/NS-BVCI */
diff --git a/src/gb/gprs_bssgp_internal.h b/src/gb/gprs_bssgp_internal.h
new file mode 100644
index 0000000..2ada027
--- /dev/null
+++ b/src/gb/gprs_bssgp_internal.h
@@ -0,0 +1,7 @@
+
+#pragma once
+
+#include <osmocom/gprs/gprs_bssgp.h>
+
+extern bssgp_bvc_send bssgp_ns_send;
+extern void *bssgp_ns_send_data;
diff --git a/src/gb/gprs_bssgp_util.c b/src/gb/gprs_bssgp_util.c
index 7708949..917f1f3 100644
--- a/src/gb/gprs_bssgp_util.c
+++ b/src/gb/gprs_bssgp_util.c
@@ -32,6 +32,7 @@
 #include <osmocom/gprs/gprs_bssgp.h>
 #include <osmocom/gprs/gprs_ns.h>
 
+#include "gprs_bssgp_internal.h"
 #include "common_vty.h"
 
 struct gprs_ns_inst *bssgp_nsi;
@@ -210,7 +211,7 @@
 	_bvci = osmo_htons(bvci);
 	msgb_tvlv_put(msg, BSSGP_IE_BVCI, 2, (uint8_t *) &_bvci);
 
-	return gprs_ns_sendmsg(bssgp_nsi, msg);
+	return bssgp_ns_send(bssgp_ns_send_data, msg);
 }
 
 /* Chapter 10.4.14: Status */
@@ -248,5 +249,5 @@
 	msgb_tvlv_put(msg, BSSGP_IE_PDU_IN_ERROR,
 		      msgb_bssgp_len(orig_msg), msgb_bssgph(orig_msg));
 
-	return gprs_ns_sendmsg(bssgp_nsi, msg);
+	return bssgp_ns_send(bssgp_ns_send_data, msg);
 }
diff --git a/src/gb/libosmogb.map b/src/gb/libosmogb.map
index 7a231db..0c0c5c4 100644
--- a/src/gb/libosmogb.map
+++ b/src/gb/libosmogb.map
@@ -13,6 +13,7 @@
 bssgp_msgb_tlli_put;
 bssgp_msgb_ra_put;
 bssgp_parse_cell_id;
+bssgp_set_bssgp_callback;
 bssgp_tx_bvc_block;
 bssgp_tx_bvc_reset;
 bssgp_tx_bvc_reset2;

-- 
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/19414
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I3a498e6a0d68b87fed80c64199b22395796761b4
Gerrit-Change-Number: 19414
Gerrit-PatchSet: 6
Gerrit-Owner: lynxis lazus <lynxis at fe80.eu>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy at sysmocom.de>
Gerrit-Reviewer: laforge <laforge at osmocom.org>
Gerrit-Reviewer: lynxis lazus <lynxis at fe80.eu>
Gerrit-Reviewer: pespin <pespin at sysmocom.de>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20200804/38b7305d/attachment.htm>


More information about the gerrit-log mailing list