sgsn: Avoid duplicated Attach Accept messages

Currently each received Ident Resp triggers an Attach Accept/Reject
if IMSI and IMEI are known. This has led to duplicated Attach Accept
messages when used with the gbproxy (IMSI acquisition active) and
with certain mobile equipment (iOS).

This patch modifies gsm48_rx_gmm_id_resp to discard Ident Resp messages
if all required information (IMEI and IMSI) has been gathered.

Ticket: OW#1322
Sponsored-by: On-Waves ehf
diff --git a/openbsc/src/gprs/gprs_gmm.c b/openbsc/src/gprs/gprs_gmm.c
index c55c300..99ab276 100644
--- a/openbsc/src/gprs/gprs_gmm.c
+++ b/openbsc/src/gprs/gprs_gmm.c
@@ -626,6 +626,8 @@
 {
 	if (strlen(ctx->imei) && strlen(ctx->imsi)) {
 #ifdef PTMSI_ALLOC
+		ctx->t3370_id_type = GSM_MI_TYPE_NONE;
+
 		/* Start T3350 and re-transmit up to 5 times until ATTACH COMPLETE */
 		ctx->t3350_mode = t3350_mode;
 		mmctx_timer_start(ctx, 3350, GSM0408_T3350_SECS);
@@ -666,6 +668,14 @@
 	LOGMMCTXP(LOGL_DEBUG, ctx, "-> GMM IDENTITY RESPONSE: mi_type=0x%02x MI(%s)\n",
 		mi_type, mi_string);
 
+	if (ctx->t3370_id_type == GSM_MI_TYPE_NONE) {
+		LOGMMCTXP(LOGL_NOTICE, ctx,
+			  "Got unexpected IDENTITY RESPONSE: mi_type=0x%02x MI(%s), "
+			  "ignoring message\n",
+			  mi_type, mi_string);
+		return -EINVAL;
+	}
+
 	if (mi_type == ctx->t3370_id_type)
 		mmctx_timer_stop(ctx, 3370);