libmsc/gsm_09_11.c: properly handle OSMO_GSUP_MSGT_PROC_SS_ERROR

This message can be used by the HLR/EUSE to indicate that something
went wrong, e.g. the connection with EUSE is lost, EUSE or the MS
did not respond in time, etc. OsmoMSC needs to release the SS/USSD
transaction, and send GSM 04.80 RELEASE COMPLETE message to the MS
if there is an active RAN connection.

Change-Id: I076d12ef24d7320eda1df1ee4588da7375ef3d9e
Related: (TTCN-3) I5586a88136c936441a842f49248824680603672e
Related: OS#2931
diff --git a/src/libmsc/gsm_09_11.c b/src/libmsc/gsm_09_11.c
index f58c106..7e1f580 100644
--- a/src/libmsc/gsm_09_11.c
+++ b/src/libmsc/gsm_09_11.c
@@ -436,14 +436,36 @@
 	/* Associate logging messages with this subscriber */
 	log_set_context(LOG_CTX_VLR_SUBSCR, vsub);
 
+	/* Attempt to find DTAP-transaction */
+	trans = trans_find_by_callref(net, gsup_msg->session_id);
+
 	/* Handle errors */
 	if (OSMO_GSUP_IS_MSGT_ERROR(gsup_msg->message_type)) {
-		/* FIXME: handle this error somehow! */
+		LOGP(DSS, LOGL_NOTICE, "Rx %s from HLR/EUSE (cause=0x%02x, sid=0x%x)\n",
+		     osmo_gsup_message_type_name(gsup_msg->message_type),
+		     gsup_msg->cause, gsup_msg->session_id);
+
+		if (!trans) {
+			LOGP(DSS, LOGL_ERROR, "No transaction found for "
+			     "sid=0x%x, nothing to abort\n", gsup_msg->session_id);
+			return -ENODEV;
+		}
+
+		LOG_TRANS(trans, LOGL_NOTICE, "Aborting the session: sending RELEASE COMPLETE\n");
+
+		/* Indicate connection release to subscriber (if active) */
+		if (trans->msc_a != NULL) {
+			/* TODO: implement GSUP - GSM 04.80 cause mapping */
+			msc_send_ussd_release_complete_cause(trans->msc_a, trans->transaction_id,
+				GSM48_CAUSE_LOC_PUN_S_LU, GSM48_CC_CAUSE_TEMP_FAILURE);
+		}
+
+		/* Terminate transaction */
+		trans_free(trans);
+
 		return 0;
 	}
 
-	/* Attempt to find DTAP-transaction */
-	trans = trans_find_by_callref(net, gsup_msg->session_id);
 	if (!trans) {
 		/* Count network-initiated attempts to establish a NC SS/USSD session */
 		rate_ctr_inc(&net->msc_ctrs->ctr[MSC_CTR_NC_SS_MT_REQUESTS]);