ranap: add non-spec X1001

When the SGSN releases a RANAP connection, it sends a Release Command
and waits for a Release Complete. Use X1001 to release the Iu connection
when the Release Complete is lost/never received.

Change-Id: I39a0169c22a4ac430b3d6f3c281d1f381eaa4756
diff --git a/src/sgsn/gprs_ranap.c b/src/sgsn/gprs_ranap.c
index 9c7a5db..7a33491 100644
--- a/src/sgsn/gprs_ranap.c
+++ b/src/sgsn/gprs_ranap.c
@@ -25,6 +25,7 @@
 #include <gtp.h>
 
 #include <osmocom/core/rate_ctr.h>
+#include <osmocom/core/tdef.h>
 
 #include <osmocom/ranap/ranap_common.h>
 
@@ -162,8 +163,6 @@
 	return rc;
 }
 
-/* TODO: use timers */
-#define TIMEOUT_RANAP_RELEASE_SEC 5
 void sgsn_ranap_iu_free(struct sgsn_mm_ctx *ctx)
 {
 	if (!ctx)
@@ -179,15 +178,19 @@
 void sgsn_ranap_iu_release_free(struct sgsn_mm_ctx *ctx,
 				const struct RANAP_Cause *cause)
 {
+	unsigned long X1001;
+
 	if (!ctx)
 		return;
 
 	if (!ctx->iu.ue_ctx)
 		return;
 
+	X1001 = osmo_tdef_get(sgsn->cfg.T_defs, -1001, OSMO_TDEF_S, -1);
+
 	ranap_iu_tx_release_free(ctx->iu.ue_ctx,
 				 cause,
-				 TIMEOUT_RANAP_RELEASE_SEC);
+				 (int) X1001);
 	ctx->iu.ue_ctx = NULL;
 }
 
diff --git a/src/sgsn/sgsn_vty.c b/src/sgsn/sgsn_vty.c
index 17b64c8..14248d1 100644
--- a/src/sgsn/sgsn_vty.c
+++ b/src/sgsn/sgsn_vty.c
@@ -90,6 +90,9 @@
 #define GSM0408_T3395_SECS	8	/* wait for DEACT PDP CTX ACK */
 #define GSM0408_T3397_SECS	8	/* wait for DEACT AA PDP CTX ACK */
 
+/* Non spec timer */
+#define NONSPEC_X1001_SECS     5       /* wait for a RANAP Release Complete */
+
 
 static struct osmo_tdef sgsn_T_defs[] = {
 	{ .T=3312, .default_val=GSM0408_T3312_SECS, .desc="Periodic RA Update timer (s)" },
@@ -105,6 +108,8 @@
 	{ .T=3395, .default_val=GSM0408_T3395_SECS, .desc="Wait for DEACT PDP CTX ACK timer (s)" },
 	{ .T=3397, .default_val=GSM0408_T3397_SECS, .desc="Wait for DEACT AA PDP CTX ACK timer (s)" },
 	/* non spec timers */
+	{ .T=-1001, .default_val=NONSPEC_X1001_SECS, .desc="RANAP Release timeout. Wait for RANAP Release Complete."
+							   "On expiry release Iu connection (s)" },
 	{ .T=-3314, .default_val=GSM0408_T3314_SECS, .desc="Iu User inactivity timer. On expiry release Iu connection (s)" },
 	{}
 };
diff --git a/tests/test_nodes.vty b/tests/test_nodes.vty
index b9cf91e..18bccc8 100644
--- a/tests/test_nodes.vty
+++ b/tests/test_nodes.vty
@@ -12,6 +12,7 @@
 T3386 = 8 s	Wait for MODIFY PDP CTX ACK timer (s) (default: 8 s)
 T3395 = 8 s	Wait for DEACT PDP CTX ACK timer (s) (default: 8 s)
 T3397 = 8 s	Wait for DEACT AA PDP CTX ACK timer (s) (default: 8 s)
+X1001 = 5 s	RANAP Release timeout. Wait for RANAP Release Complete.On expiry release Iu connection (s) (default: 5 s)
 X3314 = 44 s	Iu User inactivity timer. On expiry release Iu connection (s) (default: 44 s)
 OsmoSGSN# configure terminal
 OsmoSGSN(config)# list