aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Couzens <lynxis@fe80.eu>2020-07-18 15:57:07 +0200
committerlynxis lazus <lynxis@fe80.eu>2020-08-04 10:33:09 +0000
commit85a8fd3911137bc7e32ad08b4030d578cd2d66ee (patch)
tree8588c2929ce0aec46be69f7dab4517e2592e753c
parent44964981c29d2251a5fed88ca4f87d0732826dfc (diff)
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
-rw-r--r--include/osmocom/gprs/gprs_bssgp.h3
-rw-r--r--src/gb/Makefile.am2
-rw-r--r--src/gb/gprs_bssgp.c34
-rw-r--r--src/gb/gprs_bssgp_bss.c25
-rw-r--r--src/gb/gprs_bssgp_internal.h7
-rw-r--r--src/gb/gprs_bssgp_util.c5
-rw-r--r--src/gb/libosmogb.map1
7 files changed, 54 insertions, 23 deletions
diff --git a/include/osmocom/gprs/gprs_bssgp.h b/include/osmocom/gprs/gprs_bssgp.h
index 0f87333a..b9d251cc 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 7248413a..125afbaf 100644
--- a/src/gb/Makefile.am
+++ b/src/gb/Makefile.am
@@ -7,7 +7,7 @@ AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_builddir)/include
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 38794c28..fa4e187a 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 @@ LLIST_HEAD(bssgp_bvc_ctxts);
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 @@ struct bssgp_bvc_ctx *btsctx_by_bvci_nsei(uint16_t bvci, uint16_t nsei)
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 @@ static int bssgp_tx_fc_bvc_ack(uint16_t nsei, uint8_t tag, uint16_t ns_bvci)
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 @@ int bssgp_tx_suspend_ack(uint16_t nsei, uint32_t tlli,
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 @@ int bssgp_tx_suspend_nack(uint16_t nsei, uint32_t tlli,
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 @@ int bssgp_tx_resume_ack(uint16_t nsei, uint32_t tlli,
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 @@ int bssgp_tx_resume_nack(uint16_t nsei, uint32_t tlli,
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 @@ int bssgp_create_cell_id(uint8_t *buf, const struct gprs_ra_id *raid,
}
/* 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_fc_needs_queueing(struct bssgp_flow_control *fc, uint32_t pdu_l
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 @@ int bssgp_tx_paging(uint16_t nsei, uint16_t ns_bvci,
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 5a1ffb92..94b18126 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 @@ int bssgp_tx_suspend(uint16_t nsei, uint32_t tlli,
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 @@ int bssgp_tx_resume(uint16_t nsei, uint32_t tlli,
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 @@ int bssgp_tx_ra_capa_upd(struct bssgp_bvc_ctx *bctx, uint32_t tlli, uint8_t tag)
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 @@ static int common_tx_radio_status2(struct msgb *msg, uint8_t cause)
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 @@ int bssgp_tx_flush_ll_ack(struct bssgp_bvc_ctx *bctx, uint32_t tlli,
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 @@ int bssgp_tx_llc_discarded(struct bssgp_bvc_ctx *bctx, uint32_t tlli,
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 @@ int bssgp_tx_bvc_block(struct bssgp_bvc_ctx *bctx, uint8_t cause)
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 @@ int bssgp_tx_bvc_unblock(struct bssgp_bvc_ctx *bctx)
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 @@ int bssgp_tx_bvc_reset2(struct bssgp_bvc_ctx *bctx, uint16_t bvci, uint8_t cause
}
/* 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 @@ int bssgp_tx_fc_bvc(struct bssgp_bvc_ctx *bctx, uint8_t tag,
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 @@ int bssgp_tx_fc_ms(struct bssgp_bvc_ctx *bctx, uint32_t tlli, uint8_t tag,
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 @@ int bssgp_tx_ul_ud(struct bssgp_bvc_ctx *bctx, uint32_t tlli,
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 00000000..2ada027c
--- /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 77089491..917f1f32 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 @@ int bssgp_tx_simple_bvci(uint8_t pdu_type, uint16_t nsei,
_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 @@ int bssgp_tx_status(uint8_t cause, uint16_t *bvci, struct msgb *orig_msg)
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 7a231db5..0c0c5c43 100644
--- a/src/gb/libosmogb.map
+++ b/src/gb/libosmogb.map
@@ -13,6 +13,7 @@ bssgp_msgb_copy;
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;