Max has uploaded this change for review. ( https://gerrit.osmocom.org/12578


Change subject: SMS: remove code duplication in transaction init
......................................................................

SMS: remove code duplication in transaction init

Move code which allocates transaction for SMS and initializes
corresponding FSM into separate function (shared by MT and MO code
paths) to avoid code duplication and simplify further modifications.

Change-Id: I3563e11bebb58e656592df2ff7db96f41deaf735
---
M src/libmsc/gsm_04_11.c
1 file changed, 28 insertions(+), 25 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-msc refs/changes/78/12578/1

diff --git a/src/libmsc/gsm_04_11.c b/src/libmsc/gsm_04_11.c
index 8ef26a7..4dc07bd 100644
--- a/src/libmsc/gsm_04_11.c
+++ b/src/libmsc/gsm_04_11.c
@@ -1007,6 +1007,27 @@
        return rc;
 }

+static struct gsm_trans *gsm411_trans_init(struct gsm_network *net, struct 
vlr_subscr *vsub, struct ran_conn *conn,
+                                          uint8_t tid)
+{
+       /* Allocate a new transaction */
+       struct gsm_trans *trans = trans_alloc(net, vsub, GSM48_PDISC_SMS, tid, 
new_callref++);
+       if (!trans) {
+               LOGP(DLSMS, LOGL_ERROR, "No memory for transaction\n");
+               return NULL;
+       }
+
+       /* Init both SMC and SMR state machines */
+       gsm411_smc_init(&trans->sms.smc_inst, 0, 1, gsm411_mn_recv, 
gsm411_mm_send);
+       gsm411_smr_init(&trans->sms.smr_inst, 0, 1, gsm411_rl_recv, 
gsm411_mn_send);
+
+       /* Associate transaction with connection */
+       if (conn)
+               trans->conn = ran_conn_get(conn, RAN_CONN_USE_TRANS_SMS);
+
+       return trans;
+}
+
 static struct gsm_trans *gsm411_alloc_mt_trans(struct gsm_network *net,
                                               struct vlr_subscr *vsub)
 {
@@ -1023,24 +1044,15 @@
                return NULL;
        }

-       /* Allocate a new transaction */
-       trans = trans_alloc(net, vsub, GSM48_PDISC_SMS, tid, new_callref++);
-       if (!trans) {
-               LOGP(DLSMS, LOGL_ERROR, "No memory for trans\n");
-               return NULL;
-       }
-
-       /* Init both SMC and SMR state machines */
-       gsm411_smc_init(&trans->sms.smc_inst, 0, 1,
-               gsm411_mn_recv, gsm411_mm_send);
-       gsm411_smr_init(&trans->sms.smr_inst, 0, 1,
-               gsm411_rl_recv, gsm411_mn_send);
-
        /* Attempt to find an existing connection */
        conn = connection_for_subscr(vsub);
+
+       /* Allocate a new transaction */
+       trans = gsm411_trans_init(net, vsub, conn, tid);
+       if (!trans)
+               return NULL;
+
        if (conn) {
-               /* Associate transaction with connection */
-               trans->conn = ran_conn_get(conn, RAN_CONN_USE_TRANS_SMS);
                /* Generate unique RP Message Reference */
                trans->sms.sm_rp_mr = conn->next_rp_ref++;
        }
@@ -1192,21 +1204,12 @@
        }

        if (!trans) {
-               DEBUGP(DLSMS, " -> (new transaction)\n");
-               trans = trans_alloc(conn->network, conn->vsub,
-                                   GSM48_PDISC_SMS,
-                                   transaction_id, new_callref++);
+               trans = gsm411_trans_init(conn->network, conn->vsub, conn, 
transaction_id);
                if (!trans) {
-                       DEBUGP(DLSMS, " -> No memory for trans\n");
                        /* FIXME: send some error message */
                        return -ENOMEM;
                }
-               gsm411_smc_init(&trans->sms.smc_inst, 0, 1,
-                       gsm411_mn_recv, gsm411_mm_send);
-               gsm411_smr_init(&trans->sms.smr_inst, 0, 1,
-                       gsm411_rl_recv, gsm411_mn_send);

-               trans->conn = ran_conn_get(conn, RAN_CONN_USE_TRANS_SMS);
                trans->dlci = OMSC_LINKID_CB(msg); /* DLCI as received from BSC 
*/

                new_trans = 1;

--
To view, visit https://gerrit.osmocom.org/12578
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-msc
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I3563e11bebb58e656592df2ff7db96f41deaf735
Gerrit-Change-Number: 12578
Gerrit-PatchSet: 1
Gerrit-Owner: Max <msur...@sysmocom.de>

Reply via email to