sgsn: Only send Detach Accept (MO) if power_off isn't set

Currently, every time the SGSN received a Detach Request from the MS
via an established logical link, it is answered by a Detach Accept.
This violates the specification (GSM 04.08, 4.7.4.1.2 and .3), which
states, that it should only be sent, if "the detach type IE value
indicates that the detach request has not been sent due to switching
off".

This patch adds a conditional to limit the sending of Detach Accept
accordingly.

Sponsored-by: On-Waves ehf
diff --git a/openbsc/src/gprs/gprs_gmm.c b/openbsc/src/gprs/gprs_gmm.c
index db0c2db..ff852eb 100644
--- a/openbsc/src/gprs/gprs_gmm.c
+++ b/openbsc/src/gprs/gprs_gmm.c
@@ -875,8 +875,12 @@
 		msgb_tlli(msg), get_value_string(gprs_det_t_mo_strs, detach_type),
 		power_off ? "Power-off" : "");
 
-	/* force_stby = 0 */
-	rc = gsm48_tx_gmm_det_ack(ctx, 0);
+	/* Only sent the Detach Accept (MO) if power off isn't indicated,
+	 * see 04.08, 4.7.4.1.2/3 for details */
+	if (!power_off) {
+		/* force_stby = 0 */
+		rc = gsm48_tx_gmm_det_ack(ctx, 0);
+	}
 
 	mm_ctx_cleanup_free(ctx, "GPRS DETACH REQUEST");
 
diff --git a/openbsc/tests/sgsn/sgsn_test.c b/openbsc/tests/sgsn/sgsn_test.c
index 00ee866..cb3c294 100644
--- a/openbsc/tests/sgsn/sgsn_test.c
+++ b/openbsc/tests/sgsn/sgsn_test.c
@@ -213,7 +213,7 @@
 
 	/* verify that no message (and therefore no Detach Accept) has been
 	 * sent by the SGSN */
-	/* OSMO_ASSERT(sgsn_tx_counter_old == sgsn_tx_counter); */
+	OSMO_ASSERT(sgsn_tx_counter_old == sgsn_tx_counter);
 
 	/* verify that things are gone */
 	OSMO_ASSERT(count(gprs_llme_list()) == 0);