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
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)