[GPRS] SGSN: properly delete a PDP context after receiving PDP CTX DEACT REQ
diff --git a/openbsc/src/gprs/gprs_sgsn.c b/openbsc/src/gprs/gprs_sgsn.c
index 38056f0..2671796 100644
--- a/openbsc/src/gprs/gprs_sgsn.c
+++ b/openbsc/src/gprs/gprs_sgsn.c
@@ -123,6 +123,7 @@
 	return ctx;
 }
 
+
 struct sgsn_pdp_ctx *sgsn_pdp_ctx_by_nsapi(const struct sgsn_mm_ctx *mm,
 					   uint8_t nsapi)
 {
@@ -135,6 +136,19 @@
 	return NULL;
 }
 
+struct sgsn_pdp_ctx *sgsn_pdp_ctx_by_tid(const struct sgsn_mm_ctx *mm,
+					 uint8_t tid)
+{
+	struct sgsn_pdp_ctx *pdp;
+
+	llist_for_each_entry(pdp, &mm->pdp_list, list) {
+		if (pdp->ti == tid)
+			return pdp;
+	}
+	return NULL;
+}
+
+
 struct sgsn_pdp_ctx *sgsn_pdp_ctx_alloc(struct sgsn_mm_ctx *mm,
 					uint8_t nsapi)
 {
@@ -165,11 +179,11 @@
 
 /* GGSN contexts */
 
-struct ggsn_ctx *ggsn_ctx_alloc(uint32_t id)
+struct sgsn_ggsn_ctx *sgsn_ggsn_ctx_alloc(uint32_t id)
 {
-	struct ggsn_ctx *ggc;
+	struct sgsn_ggsn_ctx *ggc;
 
-	ggc = talloc_zero(tall_bsc_ctx, struct ggsn_ctx);
+	ggc = talloc_zero(tall_bsc_ctx, struct sgsn_ggsn_ctx);
 	if (!ggc)
 		return NULL;
 
@@ -179,9 +193,9 @@
 	return ggc;
 }
 
-struct ggsn_ctx *ggsn_ctx_by_id(uint32_t id)
+struct sgsn_ggsn_ctx *sgsn_ggsn_ctx_by_id(uint32_t id)
 {
-	struct ggsn_ctx *ggc;
+	struct sgsn_ggsn_ctx *ggc;
 
 	llist_for_each_entry(ggc, &sgsn_ggsn_ctxts, list) {
 		if (id == ggc->id)
@@ -190,13 +204,13 @@
 	return NULL;
 }
 
-struct ggsn_ctx *ggsn_ctx_find_alloc(uint32_t id)
+struct sgsn_ggsn_ctx *sgsn_ggsn_ctx_find_alloc(uint32_t id)
 {
-	struct ggsn_ctx *ggc;
+	struct sgsn_ggsn_ctx *ggc;
 
-	ggc = ggsn_ctx_by_id(id);
+	ggc = sgsn_ggsn_ctx_by_id(id);
 	if (!ggc)
-		ggc = ggsn_ctx_alloc(id);
+		ggc = sgsn_ggsn_ctx_alloc(id);
 	return ggc;
 }