Store GCR when we get the SETUP, don't wait till paging cb

I originally placed this code in the paging callback,
probably only because trans_lcls_compose() wants
to check the msc_a for OSMO_RAT_GERAN_A and get LAC/CI
etc for GCR generation. but we don't need any of that
here.

Change-Id: I32ac4e3da8bb6d44c4aa69fe8a67eedbe20a1c25
diff --git a/src/libmsc/gsm_04_08_cc.c b/src/libmsc/gsm_04_08_cc.c
index a7944b6..d5fd3d2 100644
--- a/src/libmsc/gsm_04_08_cc.c
+++ b/src/libmsc/gsm_04_08_cc.c
@@ -340,18 +340,6 @@
 		trans->msc_a = msc_a;
 		trans->paging_request = NULL;
 
-		/* Get the GCR from the MO call leg (if any). */
-		if (!trans->cc.lcls)
-			trans->cc.lcls = trans_lcls_compose(trans, true);
-		if (trans->cc.lcls && trans->cc.msg.fields & MNCC_F_GCR) {
-			int rc = osmo_dec_gcr(&trans->cc.lcls->gcr,
-					      &trans->cc.msg.gcr[0],
-					      sizeof(trans->cc.msg.gcr));
-			if (rc < 0)
-				LOG_TRANS(trans, LOGL_ERROR, "Failed to parse GCR\n");
-			else
-				trans->cc.lcls->gcr_available = true;
-		}
 
 		osmo_fsm_inst_dispatch(msc_a->c.fi, MSC_A_EV_TRANSACTION_ACCEPTED, trans);
 		/* send SETUP request to called party */
@@ -2291,6 +2279,24 @@
 			/* store setup information until paging succeeds */
 			memcpy(&trans->cc.msg, data, sizeof(struct gsm_mncc));
 
+			/* Store the Global Call Reference in the transaction if MNCC sent it */
+			if (data->fields & MNCC_F_GCR) {
+				/* The trans has no msc_a yet so compose will return NULL
+				// trans->cc.lcls = trans_lcls_compose(trans, true); */
+				trans->cc.lcls = talloc_zero(trans, struct osmo_lcls);
+				int rc = osmo_dec_gcr(&trans->cc.lcls->gcr,
+						      &data->gcr[0],
+						      sizeof(data->gcr));
+				if (rc < 0) {
+					LOG_TRANS_CAT(trans, DCC, LOGL_ERROR, "Failed to parse GCR\n");
+				} else {
+					trans->cc.lcls->config        = GSM0808_LCLS_CFG_BOTH_WAY;
+					trans->cc.lcls->control       = GSM0808_LCLS_CSC_DO_NOT_CONNECT;
+					trans->cc.lcls->corr_needed   = true;
+					trans->cc.lcls->gcr_available = true;
+				}
+			}
+
 			/* Request a channel. If Paging already started, paging_request_start() will append the new
 			 * trans to the already ongoing Paging. */
 			trans->paging_request = paging_request_start(vsub, PAGING_CAUSE_CALL_CONVERSATIONAL,