fix _gsm48_cc_trans_free(): send MNCC REL.ind on Clear Request

Calling gsm48_cc_tx_release() before mncc_release_ind() has a side
effect: the former may change CC state to GSM_CSTATE_RELEASE_REQ.
This makes the later send MNCC_REL_CNF instead of MNCC_REL_IND, so
if one of the call leg disconnects due to RF failure, the other one
will not be terminated correctly.

Makes both TC_{mo,mt}_call_clear_request TTCN-3 test cases pass.

Change-Id: I3ad4a99757878de3796027325627c87d9a4e93f1
Related: Id16969fe0de04445d1320a96d35cf1d48cc8cf09
Related: SYS#5340
diff --git a/src/libmsc/gsm_04_08_cc.c b/src/libmsc/gsm_04_08_cc.c
index ed29e84..704e596 100644
--- a/src/libmsc/gsm_04_08_cc.c
+++ b/src/libmsc/gsm_04_08_cc.c
@@ -272,6 +272,13 @@
 
 	/* send release to L4, if callref still exists */
 	if (trans->callref) {
+		/* Send MNCC REL.ind (cause='Resource unavailable') */
+		if (trans->cc.mncc_initiated) {
+			mncc_release_ind(trans->net, trans, trans->callref,
+					 GSM48_CAUSE_LOC_PRN_S_LU,
+					 GSM48_CC_CAUSE_RESOURCE_UNAVAIL);
+		}
+
 		/* FIXME: currently, a CC trans that would not yet be in state GSM_CSTATE_RELEASE_REQ fails to send a
 		 * CC Release to the MS if it gets freed here. Hack it to do so. */
 		if (trans->cc.state != GSM_CSTATE_RELEASE_REQ) {
@@ -280,11 +287,6 @@
 			mncc_set_cause(&rel, GSM48_CAUSE_LOC_PRN_S_LU, GSM48_CC_CAUSE_RESOURCE_UNAVAIL);
 			gsm48_cc_tx_release(trans, &rel);
 		}
-		/* Resource unavailable */
-		if (trans->cc.mncc_initiated)
-			mncc_release_ind(trans->net, trans, trans->callref,
-					 GSM48_CAUSE_LOC_PRN_S_LU,
-					 GSM48_CC_CAUSE_RESOURCE_UNAVAIL);
 		/* This is a final freeing of the transaction. The MNCC release may have triggered the
 		 * T308 release timer, but we don't have the luxury of graceful CC Release here. */
 		gsm48_stop_cc_timer(trans);