From 93c7463fcea24517ef367101609f34264570f1d0 Mon Sep 17 00:00:00 2001 From: Neels Hofmeyr Date: Mon, 2 Apr 2018 23:10:28 +0200 Subject: unify allocation of gsm_subscriber_connection The current msc_subscr_con_allocate() was in fact only used by msc_vlr_tests, while both a_iface_bssap.c and iucs.c did their own duplicate code of allocating the gsm_subscriber_connection struct. Unify. Drop the old msc_subscr_con_allocate(), instead add msc_subscr_conn_alloc(). The new function also takes via_ran and lac arguments directly. The conn allocation will soon be closely tied to the subscr_conn_fsm instance allocation, so place the new function definition alongside the other subscr_conn_fsm API, and match its naming ("conn"). Related: OS#3122 Change-Id: Ia57b42a149a43f9c370b1310e2e1f512183993ea --- include/osmocom/msc/gsm_data.h | 1 - include/osmocom/msc/osmo_msc.h | 3 +++ src/libmsc/a_iface_bssap.c | 7 +------ src/libmsc/iucs.c | 7 +------ src/libmsc/subscr_conn.c | 20 ++++++++++++++++++++ tests/msc_vlr/msc_vlr_test_rest.c | 2 +- tests/msc_vlr/msc_vlr_tests.c | 4 +--- 7 files changed, 27 insertions(+), 17 deletions(-) diff --git a/include/osmocom/msc/gsm_data.h b/include/osmocom/msc/gsm_data.h index 29abd5d20..f3e1b94b1 100644 --- a/include/osmocom/msc/gsm_data.h +++ b/include/osmocom/msc/gsm_data.h @@ -374,7 +374,6 @@ struct gsm_sms { char text[SMS_TEXT_SIZE]; }; -struct gsm_subscriber_connection *msc_subscr_con_allocate(struct gsm_network *network); void msc_subscr_con_free(struct gsm_subscriber_connection *conn); /* control interface handling */ diff --git a/include/osmocom/msc/osmo_msc.h b/include/osmocom/msc/osmo_msc.h index fb525e000..13341382b 100644 --- a/include/osmocom/msc/osmo_msc.h +++ b/include/osmocom/msc/osmo_msc.h @@ -41,6 +41,9 @@ enum msc_compl_l3_rc { MSC_CONN_REJECT = 1, }; +struct gsm_subscriber_connection *msc_subscr_conn_alloc(struct gsm_network *network, + enum ran_type via_ran, uint16_t lac); + void msc_subscr_conn_update_id(struct gsm_subscriber_connection *conn, enum complete_layer3_type from, const char *id); char *msc_subscr_conn_get_conn_id(struct gsm_subscriber_connection *conn); diff --git a/src/libmsc/a_iface_bssap.c b/src/libmsc/a_iface_bssap.c index 743814cd3..1665e2307 100644 --- a/src/libmsc/a_iface_bssap.c +++ b/src/libmsc/a_iface_bssap.c @@ -54,14 +54,10 @@ static struct gsm_subscriber_connection *subscr_conn_allocate_a(const struct a_c LOGP(DMSC, LOGL_DEBUG, "Allocating A-Interface subscriber conn: lac %i, conn_id %i\n", lac, conn_id); - conn = talloc_zero(network, struct gsm_subscriber_connection); + conn = msc_subscr_conn_alloc(network, RAN_GERAN_A, lac); if (!conn) return NULL; - conn->network = network; - conn->via_ran = RAN_GERAN_A; - conn->lac = lac; - conn->a.conn_id = conn_id; conn->a.scu = scu; @@ -69,7 +65,6 @@ static struct gsm_subscriber_connection *subscr_conn_allocate_a(const struct a_c * identify later which BSC is responsible for this subscriber connection */ memcpy(&conn->a.bsc_addr, &a_conn_info->bsc->bsc_addr, sizeof(conn->a.bsc_addr)); - llist_add_tail(&conn->entry, &network->subscr_conns); LOGPCONN(conn, LOGL_DEBUG, "A-Interface subscriber connection successfully allocated!\n"); return conn; } diff --git a/src/libmsc/iucs.c b/src/libmsc/iucs.c index d6da1f795..a3092f86e 100644 --- a/src/libmsc/iucs.c +++ b/src/libmsc/iucs.c @@ -57,17 +57,12 @@ static struct gsm_subscriber_connection *subscr_conn_allocate_iu(struct gsm_netw DEBUGP(DIUCS, "Allocating IuCS subscriber conn: lac %d, conn_id %" PRIx32 "\n", lac, ue->conn_id); - conn = talloc_zero(network, struct gsm_subscriber_connection); + conn = msc_subscr_conn_alloc(network, RAN_UTRAN_IU, lac); if (!conn) return NULL; - conn->network = network; - conn->via_ran = RAN_UTRAN_IU; conn->iu.ue_ctx = ue; conn->iu.ue_ctx->rab_assign_addr_enc = network->iu.rab_assign_addr_enc; - conn->lac = lac; - - llist_add_tail(&conn->entry, &network->subscr_conns); return conn; } diff --git a/src/libmsc/subscr_conn.c b/src/libmsc/subscr_conn.c index fc89a663f..5629d26f9 100644 --- a/src/libmsc/subscr_conn.c +++ b/src/libmsc/subscr_conn.c @@ -369,6 +369,26 @@ void msc_subscr_conn_init(void) osmo_fsm_register(&subscr_conn_fsm); } +/* Allocate a new subscriber conn. */ +struct gsm_subscriber_connection *msc_subscr_conn_alloc(struct gsm_network *network, + enum ran_type via_ran, uint16_t lac) +{ + struct gsm_subscriber_connection *conn; + + conn = talloc_zero(network, struct gsm_subscriber_connection); + if (!conn) + return NULL; + + *conn = (struct gsm_subscriber_connection){ + .network = network, + .via_ran = via_ran, + .lac = lac, + }; + + llist_add_tail(&conn->entry, &network->subscr_conns); + return conn; +} + const struct value_string complete_layer3_type_names[] = { { COMPLETE_LAYER3_NONE, "NONE" }, { COMPLETE_LAYER3_LU, "LU" }, diff --git a/tests/msc_vlr/msc_vlr_test_rest.c b/tests/msc_vlr/msc_vlr_test_rest.c index 3f843f06e..7fd7bae6b 100644 --- a/tests/msc_vlr/msc_vlr_test_rest.c +++ b/tests/msc_vlr/msc_vlr_test_rest.c @@ -31,7 +31,7 @@ static void test_early_stage() EXPECT_ACCEPTED(false); btw("freshly allocated conn"); - g_conn = msc_subscr_con_allocate(net); + g_conn = msc_subscr_conn_alloc(net, RAN_GERAN_A, 123); EXPECT_ACCEPTED(false); btw("conn_fsm present, in state NEW"); diff --git a/tests/msc_vlr/msc_vlr_tests.c b/tests/msc_vlr/msc_vlr_tests.c index 523f74fe4..7c54057ab 100644 --- a/tests/msc_vlr/msc_vlr_tests.c +++ b/tests/msc_vlr/msc_vlr_tests.c @@ -191,9 +191,7 @@ enum ran_type rx_from_ran = RAN_GERAN_A; struct gsm_subscriber_connection *conn_new(void) { struct gsm_subscriber_connection *conn; - conn = msc_subscr_con_allocate(net); - conn->via_ran = rx_from_ran; - conn->lac = 23; + conn = msc_subscr_conn_alloc(net, rx_from_ran, 23); if (conn->via_ran == RAN_UTRAN_IU) { struct ranap_ue_conn_ctx *ue_ctx = talloc_zero(conn, struct ranap_ue_conn_ctx); *ue_ctx = (struct ranap_ue_conn_ctx){ -- cgit v1.2.3