gbproxy: Parse Detach Request messages

GSM 24.008 also allows a P-TMSI field in Detach request messages.

This patch adds gbprox_parse_gmm_detach_req() to parse Detach Request
messages which sets the ptmsi field if the IE is present.

In addition, when power_off is set to 1 (MO only), the
invalidate_tlli field is set, since Detach Request message is
expected in this case.

The second detach test (see 'RA update') is modified to use
power_off instead of relying on a Detach Accept from the network.
To make this work, the PTMSI of the RA Update Accept is fixed to
match the TLLI of the Detach Request.

Sponsored-by: On-Waves ehf
diff --git a/openbsc/tests/gbproxy/gbproxy_test.c b/openbsc/tests/gbproxy/gbproxy_test.c
index 5363749..27454a2 100644
--- a/openbsc/tests/gbproxy/gbproxy_test.c
+++ b/openbsc/tests/gbproxy/gbproxy_test.c
@@ -221,8 +221,8 @@
 	0x18, 0x00, 0x81, 0x00, 0x0e, 0x9d, 0x41, 0xc0,
 	0x19, 0x08, 0x09, 0x00, 0x49, 0x21, 0x63, 0x54,
 	0x40, 0x50, 0x60, 0x19, 0x54, 0xab, 0xb3, 0x18,
-	0x05, 0xf4, 0xef, 0xe2, 0x81, 0x17, 0x17, 0x16,
-	0xc3, 0xbf, 0xcc
+	0x05, 0xf4, 0xef, 0xe2, 0xb7, 0x00, 0x17, 0x16,
+	0xd7, 0x59, 0x65
 };
 
 /* Base Station Subsystem GPRS Protocol: GSM A-I/F DTAP - Activate PDP Context Request */
@@ -239,7 +239,19 @@
 	0x00, 0x5a, 0xff, 0x02
 };
 
-/* Base Station Subsystem GPRS Protocol: GSM A-I/F DTAP - Detach Request */
+/* Base Station Subsystem GPRS Protocol: GSM A-I/F DTAP - Detach Request (MO) */
+/* normal detach, power_off = 1 */
+static const unsigned char bssgp_detach_po_req[44] = {
+	0x01, 0xef, 0xe2, 0xb7, 0x00, 0x00, 0x00, 0x04,
+	0x08, 0x88, 0x11, 0x22, 0x33, 0x40, 0x50, 0x60,
+	0x75, 0x30, 0x00, 0x80, 0x0e, 0x00, 0x15, 0x01,
+	0xc0, 0x19, 0x08, 0x05, 0x09, 0x18, 0x05, 0xf4,
+	0xef, 0xe2, 0xb7, 0x00, 0x19, 0x03, 0xb9, 0x97,
+	0xcb, 0x84, 0x0c, 0xeb
+};
+
+/* Base Station Subsystem GPRS Protocol: GSM A-I/F DTAP - Detach Request (MO) */
+/* normal detach, power_off = 0 */
 static const unsigned char bssgp_detach_req[44] = {
 	0x01, 0xef, 0xe2, 0xb7, 0x00, 0x00, 0x00, 0x04,
 	0x08, 0x88, 0x11, 0x22, 0x33, 0x40, 0x50, 0x60,
@@ -1060,13 +1072,9 @@
 
 	dump_peers(stdout, 0, 0, &gbcfg);
 
-	/* Detach */
-	send_ns_unitdata(nsi, "DETACH REQ", &bss_peer[0], 0x1002,
-			 bssgp_detach_req, sizeof(bssgp_detach_req));
-
-	send_ns_unitdata(nsi, "DETACH ACC", &sgsn_peer, 0x1002,
-			 bssgp_detach_acc, sizeof(bssgp_detach_acc));
-
+	/* Detach (power off -> no Detach Accept) */
+	send_ns_unitdata(nsi, "DETACH REQ (PWR OFF)", &bss_peer[0], 0x1002,
+			 bssgp_detach_po_req, sizeof(bssgp_detach_po_req));
 
 	dump_global(stdout, 0);
 	dump_peers(stdout, 0, 0, &gbcfg);