lchan: Introduce T3109 handling for the release procedure

T3109 is started when the SACCH is deactivated. It is stopped when
the phones sends the DISC/UA/UM on LAPDm for the main signalling
link. In case of timeout the abnormal release procedure will be
initiated. Make sure to not issue the SACCH Deactivate twice to
avoid confusing the equipment.

This is still not fully spec compliant. In case of a timeout the
abnormal release handling will be started which involves starting
T3111+2. The error handling should be split out of the rf channel
release method, e.g. lchan_release should be called and check if
the channel release was already initiated.
diff --git a/openbsc/src/libbsc/chan_alloc.c b/openbsc/src/libbsc/chan_alloc.c
index a8b15d1..9b59d5d 100644
--- a/openbsc/src/libbsc/chan_alloc.c
+++ b/openbsc/src/libbsc/chan_alloc.c
@@ -362,6 +362,7 @@
 void lchan_reset(struct gsm_lchan *lchan)
 {
 	osmo_timer_del(&lchan->T3101);
+	osmo_timer_del(&lchan->T3109);
 	osmo_timer_del(&lchan->T3111);
 	osmo_timer_del(&lchan->error_timer);
 
@@ -376,7 +377,7 @@
 
 /* Drive the release process of the lchan */
 static void _lchan_handle_release(struct gsm_lchan *lchan,
-				  int sach_deact, int mode)
+				  int sacch_deact, int mode)
 {
 	/* Release all SAPIs on the local end and continue */
 	rsl_release_sapis_from(lchan, 1, RSL_REL_LOCAL_END);
@@ -386,10 +387,15 @@
 	 * release indication from the BTS or just take it down (e.g.
 	 * on assignment requests)
 	 */
-	if (sach_deact)
+	if (sacch_deact) {
 		gsm48_send_rr_release(lchan);
-	else
+
+		/* Deactivate the SACCH on the BTS side */
+		rsl_deact_sacch(lchan);
+		rsl_start_t3109(lchan);
+	} else {
 		rsl_release_request(lchan, 0, mode);
+	}
 }
 
 /* Consider releasing the channel now */