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
This commit is contained in:
Alexander Couzens 2020-07-18 15:57:07 +02:00 committed by lynxis lazus
parent 44964981c2
commit 85a8fd3911
7 changed files with 54 additions and 23 deletions

View File

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

View File

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

View File

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

View File

@ -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 */

View File

@ -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;

View File

@ -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);
}

View File

@ -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;