mncc: Add IMSI to gsm_mncc

This allows us to do subscriber lookups based on IMSI and e.g. establish
MT calls to subscribers with no assigned extension.
diff --git a/openbsc/include/openbsc/mncc.h b/openbsc/include/openbsc/mncc.h
index c04a81f..6aa1917 100644
--- a/openbsc/include/openbsc/mncc.h
+++ b/openbsc/include/openbsc/mncc.h
@@ -193,6 +193,7 @@
 	int		more;
 	int		notify; /* 0..127 */
 	int		emergency;
+	char		imsi[16];
 
 	unsigned char	lchan_mode;
 };
diff --git a/openbsc/src/gsm_04_08.c b/openbsc/src/gsm_04_08.c
index 8e5bfe8..117fb12 100644
--- a/openbsc/src/gsm_04_08.c
+++ b/openbsc/src/gsm_04_08.c
@@ -2198,6 +2198,8 @@
 		setup.fields |= MNCC_F_CALLING;
 		strncpy(setup.calling.number, trans->subscr->extension,
 			sizeof(setup.calling.number)-1);
+		strncpy(setup.imsi, trans->subscr->imsi,
+			sizeof(setup.imsi)-1);
 	}
 	/* bearer capability */
 	if (TLVP_PRESENT(&tp, GSM48_IE_BEARER_CAP)) {
@@ -2536,6 +2538,8 @@
 		connect.fields |= MNCC_F_CONNECTED;
 		strncpy(connect.connected.number, trans->subscr->extension,
 			sizeof(connect.connected.number)-1);
+		strncpy(connect.imsi, trans->subscr->imsi,
+			sizeof(connect.imsi)-1);
 	}
 	/* facility */
 	if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) {
@@ -3367,7 +3371,8 @@
 
 	/* Callref unknown */
 	if (!trans) {
-		if (msg_type != MNCC_SETUP_REQ || !data->called.number[0]) {
+		if (msg_type != MNCC_SETUP_REQ ||
+		    (!data->called.number[0] && !data->imsi[0])) {
 			DEBUGP(DCC, "(bts - trx - ts - ti -- sub %s) "
 				"Received '%s' from MNCC with "
 				"unknown callref %d\n", data->called.number,
@@ -3377,8 +3382,20 @@
 						GSM48_CAUSE_LOC_PRN_S_LU,
 						GSM48_CC_CAUSE_INVAL_TRANS_ID);
 		}
+		if (!data->called.number[0] && !data->imsi[0]) {
+			DEBUGP(DCC, "(bts - trx - ts - ti) "
+				"Received '%s' from MNCC with "
+				"no number or IMSI\n", get_mncc_name(msg_type));
+			/* Invalid number */
+			return mncc_release_ind(net, NULL, data->callref,
+						GSM48_CAUSE_LOC_PRN_S_LU,
+						GSM48_CC_CAUSE_INV_NR_FORMAT);
+		}
 		/* New transaction due to setup, find subscriber */
-		subscr = subscr_get_by_extension(data->called.number);
+		if (data->called.number[0])
+			subscr = subscr_get_by_extension(data->called.number);
+		else
+			subscr = subscr_get_by_imsi(data->imsi);
 		/* If subscriber is not found */
 		if (!subscr) {
 			DEBUGP(DCC, "(bts - trx - ts - ti -- sub %s) "