From 42eb0141d7f41ca4576c92bf694406f9fefa26df Mon Sep 17 00:00:00 2001 From: Neels Hofmeyr Date: Fri, 20 May 2016 17:15:44 +0200 Subject: [PATCH] split subscr_con_allocate()/_free() in bsc_ and msc_ Rename current subscr_con_allocate() and subscr_con_free to bsc_*, and add two separate msc_subscr_con_allocate() and _free(). The msc_subscr_con_free() ignores all lchan members. In libbsc use bsc_*, in libmsc use msc_*. Change-Id: I3cf7c7cafdf4672ec7b26058bba8a77159855257 Future: there will be distinct subscr conns for libbsc and libmsc. --- openbsc/include/openbsc/gsm_data.h | 7 +++++-- openbsc/src/libbsc/bsc_api.c | 11 +++++------ openbsc/src/libmsc/gsm_04_08.c | 27 +++++++++++++++++++++++++++ openbsc/src/libmsc/osmo_msc.c | 2 +- openbsc/src/osmo-bsc/osmo_bsc_api.c | 2 +- openbsc/src/osmo-bsc/osmo_bsc_bssap.c | 2 +- openbsc/src/osmo-bsc/osmo_bsc_sccp.c | 4 ++-- 7 files changed, 42 insertions(+), 13 deletions(-) diff --git a/openbsc/include/openbsc/gsm_data.h b/openbsc/include/openbsc/gsm_data.h index f820ba3cd..04d1126f5 100644 --- a/openbsc/include/openbsc/gsm_data.h +++ b/openbsc/include/openbsc/gsm_data.h @@ -522,8 +522,11 @@ struct gsm_meas_rep *lchan_next_meas_rep(struct gsm_lchan *lchan); int gsm_btsmodel_set_feature(struct gsm_bts_model *model, enum gsm_bts_features feat); int gsm_bts_model_register(struct gsm_bts_model *model); -struct gsm_subscriber_connection *subscr_con_allocate(struct gsm_lchan *lchan); -void subscr_con_free(struct gsm_subscriber_connection *conn); +struct gsm_subscriber_connection *bsc_subscr_con_allocate(struct gsm_lchan *lchan); +void bsc_subscr_con_free(struct gsm_subscriber_connection *conn); + +struct gsm_subscriber_connection *msc_subscr_con_allocate(struct gsm_network *network); +void msc_subscr_con_free(struct gsm_subscriber_connection *conn); struct gsm_bts *gsm_bts_alloc_register(struct gsm_network *net, enum gsm_bts_type type, diff --git a/openbsc/src/libbsc/bsc_api.c b/openbsc/src/libbsc/bsc_api.c index 207e12ad5..395002ada 100644 --- a/openbsc/src/libbsc/bsc_api.c +++ b/openbsc/src/libbsc/bsc_api.c @@ -239,7 +239,7 @@ static int handle_new_assignment(struct gsm_subscriber_connection *conn, int cha return 0; } -struct gsm_subscriber_connection *subscr_con_allocate(struct gsm_lchan *lchan) +struct gsm_subscriber_connection *bsc_subscr_con_allocate(struct gsm_lchan *lchan) { struct gsm_subscriber_connection *conn; struct gsm_network *net = lchan->ts->trx->bts->network; @@ -256,8 +256,7 @@ struct gsm_subscriber_connection *subscr_con_allocate(struct gsm_lchan *lchan) return conn; } -/* TODO: move subscriber put here... */ -void subscr_con_free(struct gsm_subscriber_connection *conn) +void bsc_subscr_con_free(struct gsm_subscriber_connection *conn) { if (!conn) return; @@ -682,7 +681,7 @@ int gsm0408_rcvmsg(struct msgb *msg, uint8_t link_id) } else { /* allocate a new connection */ rc = BSC_API_CONN_POL_REJECT; - lchan->conn = subscr_con_allocate(msg->lchan); + lchan->conn = bsc_subscr_con_allocate(msg->lchan); if (!lchan->conn) { lchan_release(lchan, 1, RSL_REL_NORMAL); return -1; @@ -693,7 +692,7 @@ int gsm0408_rcvmsg(struct msgb *msg, uint8_t link_id) if (rc != BSC_API_CONN_POL_ACCEPT) { lchan->conn->lchan = NULL; - subscr_con_free(lchan->conn); + bsc_subscr_con_free(lchan->conn); lchan_release(lchan, 1, RSL_REL_NORMAL); } } @@ -852,7 +851,7 @@ static void handle_release(struct gsm_subscriber_connection *conn, gsm0808_clear(conn); if (destruct) - subscr_con_free(conn); + bsc_subscr_con_free(conn); } static void handle_chan_ack(struct gsm_subscriber_connection *conn, diff --git a/openbsc/src/libmsc/gsm_04_08.c b/openbsc/src/libmsc/gsm_04_08.c index d10f8cf1e..34492bbea 100644 --- a/openbsc/src/libmsc/gsm_04_08.c +++ b/openbsc/src/libmsc/gsm_04_08.c @@ -3683,6 +3683,33 @@ int gsm0408_new_conn(struct gsm_subscriber_connection *conn) return 0; } +struct gsm_subscriber_connection *msc_subscr_con_allocate(struct gsm_network *network) +{ + struct gsm_subscriber_connection *conn; + + conn = talloc_zero(network, struct gsm_subscriber_connection); + if (!conn) + return NULL; + + conn->network = network; + llist_add_tail(&conn->entry, &network->subscr_conns); + return conn; +} + +void msc_subscr_con_free(struct gsm_subscriber_connection *conn) +{ + if (!conn) + return; + + if (conn->subscr) { + subscr_put(conn->subscr); + conn->subscr = NULL; + } + + llist_del(&conn->entry); + talloc_free(conn); +} + /* Main entry point for GSM 04.08/44.008 Layer 3 data (e.g. from the BSC). */ int gsm0408_dispatch(struct gsm_subscriber_connection *conn, struct msgb *msg) { diff --git a/openbsc/src/libmsc/osmo_msc.c b/openbsc/src/libmsc/osmo_msc.c index 604c100db..12a5117fa 100644 --- a/openbsc/src/libmsc/osmo_msc.c +++ b/openbsc/src/libmsc/osmo_msc.c @@ -173,5 +173,5 @@ void msc_release_connection(struct gsm_subscriber_connection *conn) conn->in_release = 1; gsm0808_clear(conn); - subscr_con_free(conn); + msc_subscr_con_free(conn); } diff --git a/openbsc/src/osmo-bsc/osmo_bsc_api.c b/openbsc/src/osmo-bsc/osmo_bsc_api.c index 7a3ef7050..49e57962a 100644 --- a/openbsc/src/osmo-bsc/osmo_bsc_api.c +++ b/openbsc/src/osmo-bsc/osmo_bsc_api.c @@ -330,7 +330,7 @@ static int move_to_msc(struct gsm_subscriber_connection *_conn, _conn->sccp_con = NULL; if (complete_layer3(_conn, msg, msc) != BSC_API_CONN_POL_ACCEPT) { gsm0808_clear(_conn); - subscr_con_free(_conn); + bsc_subscr_con_free(_conn); return 1; } diff --git a/openbsc/src/osmo-bsc/osmo_bsc_bssap.c b/openbsc/src/osmo-bsc/osmo_bsc_bssap.c index a60940d22..f38c97f19 100644 --- a/openbsc/src/osmo-bsc/osmo_bsc_bssap.c +++ b/openbsc/src/osmo-bsc/osmo_bsc_bssap.c @@ -185,7 +185,7 @@ static int bssmap_handle_clear_command(struct osmo_bsc_sccp_con *conn, if (conn->conn) { LOGP(DMSC, LOGL_INFO, "Releasing all transactions on %p\n", conn); gsm0808_clear(conn->conn); - subscr_con_free(conn->conn); + bsc_subscr_con_free(conn->conn); conn->conn = NULL; } diff --git a/openbsc/src/osmo-bsc/osmo_bsc_sccp.c b/openbsc/src/osmo-bsc/osmo_bsc_sccp.c index 2fafed6a4..a5714386f 100644 --- a/openbsc/src/osmo-bsc/osmo_bsc_sccp.c +++ b/openbsc/src/osmo-bsc/osmo_bsc_sccp.c @@ -84,7 +84,7 @@ static void msc_outgoing_sccp_state(struct sccp_connection *conn, int old_state) LOGP(DMSC, LOGL_ERROR, "ERROR: The lchan is still associated.\n"); gsm0808_clear(con_data->conn); - subscr_con_free(con_data->conn); + bsc_subscr_con_free(con_data->conn); con_data->conn = NULL; } @@ -107,7 +107,7 @@ static void bsc_sccp_force_free(struct osmo_bsc_sccp_con *data) { if (data->conn) { gsm0808_clear(data->conn); - subscr_con_free(data->conn); + bsc_subscr_con_free(data->conn); data->conn = NULL; }