[GPRS] SGSN: use GGSN IP address from config file, disable TMSI allocation
diff --git a/openbsc/src/gprs/gprs_sgsn.c b/openbsc/src/gprs/gprs_sgsn.c
index dfc0565..0e87e62 100644
--- a/openbsc/src/gprs/gprs_sgsn.c
+++ b/openbsc/src/gprs/gprs_sgsn.c
@@ -31,6 +31,9 @@
 #include <openbsc/gprs_sgsn.h>
 #include <openbsc/gprs_ns.h>
 #include <openbsc/gprs_bssgp.h>
+#include <openbsc/sgsn.h>
+
+extern struct sgsn_instance *sgsn;
 
 LLIST_HEAD(sgsn_mm_ctxts);
 LLIST_HEAD(sgsn_ggsn_ctxts);
@@ -70,12 +73,24 @@
 					const struct gprs_ra_id *raid)
 {
 	struct sgsn_mm_ctx *ctx;
+	int tlli_type;
 
 	llist_for_each_entry(ctx, &sgsn_mm_ctxts, list) {
 		if (tlli == ctx->tlli &&
 		    ra_id_equals(raid, &ctx->ra))
 			return ctx;
 	}
+
+	tlli_type = gprs_tlli_type(tlli);
+	if (tlli_type == TLLI_LOCAL) {
+		llist_for_each_entry(ctx, &sgsn_mm_ctxts, list) {
+			if ((ctx->p_tmsi | 0xC0000000) == tlli) {
+				ctx->tlli = tlli;
+				return ctx;
+			}
+		}
+	}
+
 	return NULL;
 }
 
@@ -189,6 +204,8 @@
 
 	ggc->id = id;
 	ggc->gtp_version = 1;
+	/* if we are called from config file parse, this gsn doesn't exist yet */
+	ggc->gsn = sgsn->gsn;
 	llist_add(&ggc->list, &sgsn_ggsn_ctxts);
 
 	return ggc;