[rsl] Implement the T3111 timer to delay the RF Channel release
diff --git a/openbsc/include/openbsc/gsm_data.h b/openbsc/include/openbsc/gsm_data.h
index 5cd43d7..39407e9 100644
--- a/openbsc/include/openbsc/gsm_data.h
+++ b/openbsc/include/openbsc/gsm_data.h
@@ -256,6 +256,7 @@
 	} encr;
 
 	struct timer_list T3101;
+	struct timer_list T3111;
 
 	/* AMR bits */
 	struct gsm48_multi_rate_conf mr_conf;
diff --git a/openbsc/src/abis_rsl.c b/openbsc/src/abis_rsl.c
index e3d778d..d170ff7 100644
--- a/openbsc/src/abis_rsl.c
+++ b/openbsc/src/abis_rsl.c
@@ -987,6 +987,7 @@
 			LOGP(DRSL, LOGL_NOTICE, "%s CHAN REL ACK but state %s\n",
 				gsm_lchan_name(msg->lchan),
 				gsm_lchans_name(msg->lchan->state));
+		bsc_del_timer(&msg->lchan->T3111);
 		rsl_lchan_set_state(msg->lchan, LCHAN_S_NONE);
 		lchan_free(msg->lchan);
 		break;
@@ -1082,6 +1083,14 @@
 	rsl_rf_chan_release(lchan);
 }
 
+/* If T3111 expires, we will send the RF Channel Request */
+static void t3111_expired(void *data)
+{
+	struct gsm_lchan *lchan = data;
+
+	rsl_rf_chan_release(lchan);
+}
+
 /* MS has requested a channel on the RACH */
 static int rsl_rx_chan_rqd(struct msgb *msg)
 {
@@ -1260,16 +1269,18 @@
 
 static void rsl_handle_release(struct gsm_lchan *lchan)
 {
+	struct gsm_bts *bts;
 	if (lchan->state != LCHAN_S_REL_REQ)
 		LOGP(DRSL, LOGL_ERROR, "RF release on %s but state %s\n",
 			gsm_lchan_name(lchan),
 			gsm_lchans_name(lchan->state));
 
 
-	/* we can now releae the channel on the BTS/Abis side */
-	/* FIXME: officially we need to start T3111 and wait for
-	 * some grace period */
-	rsl_rf_chan_release(lchan);
+	/* wait a bit to send the RF Channel Release */
+	lchan->T3111.cb = t3111_expired;
+	lchan->T3111.data = lchan;
+	bts = lchan->ts->trx->bts;
+	bsc_schedule_timer(&lchan->T3111, bts->network->T3111, 0);
 }
 
 /*	ESTABLISH INDICATION, LOCATION AREA UPDATE REQUEST
diff --git a/openbsc/src/bsc_vty.c b/openbsc/src/bsc_vty.c
index a55303b..31304fc 100644
--- a/openbsc/src/bsc_vty.c
+++ b/openbsc/src/bsc_vty.c
@@ -1239,7 +1239,7 @@
 DECLARE_TIMER(3105, "Currently not used.")
 DECLARE_TIMER(3107, "Currently not used.")
 DECLARE_TIMER(3109, "Currently not used.")
-DECLARE_TIMER(3111, "Currently not used.")
+DECLARE_TIMER(3111, "Set the RSL timeout to wait before releasing the RF Channel.")
 DECLARE_TIMER(3113, "Set the time to try paging a subscriber.")
 DECLARE_TIMER(3115, "Currently not used.")
 DECLARE_TIMER(3117, "Currently not used.")