[rr] Send a Channel Release before deactivating the channel


After auto releasing a channel the next paging request will
not be immediately answered. The hypothesis was that we do
not release the channel properly. Implementing Channel Release
of GSM 04.08 should have fixed it, but it didn't. According
to the wireshark dissectors the message is correct though.

- Add the RR cause values to gsm_04_08.
- Implement the Channel Release message
- Invoke the release channel function before deallocating
  the lchan.

diff --git a/src/chan_alloc.c b/src/chan_alloc.c
index 4658f12..7edde6e 100644
--- a/src/chan_alloc.c
+++ b/src/chan_alloc.c
@@ -1,7 +1,7 @@
 /* GSM Channel allocation routines
  *
  * (C) 2008 by Harald Welte <laforge@gnumonks.org>
- * (C) 2008 by Holger Hans Peter Freyther <zecke@selfish.org>
+ * (C) 2008, 2009 by Holger Hans Peter Freyther <zecke@selfish.org>
  *
  * All Rights Reserved
  *
@@ -212,6 +212,11 @@
 		return 0;
 	}
 
+	/* Assume we have GSM04.08 running and send a release */
+	if (lchan->subscr) {
+		gsm48_send_rr_release(lchan);
+	}
+
 	/* spoofed? message */
 	if (lchan->use_count < 0) {
 		DEBUGP(DRLL, "Channel count is negative: %d\n", lchan->use_count);
diff --git a/src/gsm_04_08.c b/src/gsm_04_08.c
index 2739b0b..541ff42 100644
--- a/src/gsm_04_08.c
+++ b/src/gsm_04_08.c
@@ -710,6 +710,26 @@
 	return rc;
 }
 
+/* 7.1.7 and 9.1.7 Channel release*/
+int gsm48_send_rr_release(struct gsm_lchan *lchan)
+{
+	struct msgb *msg = gsm48_msgb_alloc();
+	struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
+	u_int8_t *cause;
+
+	msg->lchan = lchan;
+	gh->proto_discr = GSM48_PDISC_RR;
+	gh->msg_type = GSM48_MT_RR_CHAN_REL;
+
+	cause = msgb_put(msg, 1);
+	cause[0] = GSM48_RR_CAUSE_NORMAL;
+
+	DEBUGP(DRR, "Sending Channel Release: Chan: Number: %d Type: %d\n",
+		lchan->nr, lchan->type);
+
+	return gsm48_sendmsg(msg);
+}
+
 /* Call Control */
 
 static int gsm48_cc_tx_status(struct gsm_lchan *lchan)