Properly parse cause in cipher mode reject

Use appropriate TLV routines to get and log the value of rejection
cause.

Change-Id: I26b3eb0deff6dbd217b23d284bbc6e6a9eebc8e6
Fixes: OS#3187
diff --git a/src/libmsc/a_iface_bssap.c b/src/libmsc/a_iface_bssap.c
index 11d3673..4666ae3 100644
--- a/src/libmsc/a_iface_bssap.c
+++ b/src/libmsc/a_iface_bssap.c
@@ -420,21 +420,22 @@
 	return 0;
 }
 
-/* Endpoint to handle BSSMAP cipher mode reject */
+/* Endpoint to handle BSSMAP cipher mode reject, 3GPP TS 08.08 §3.2.1.48 */
 static int bssmap_rx_ciph_rej(struct gsm_subscriber_connection *conn,
 			      struct msgb *msg, struct tlv_parsed *tp)
 {
-	uint8_t cause;
+	enum gsm0808_cause cause;
 
 	LOGPCONN(conn, LOGL_NOTICE, "RX BSSMAP CIPHER MODE REJECT\n");
 
-	if (!TLVP_PRESENT(tp, BSS_MAP_MSG_CIPHER_MODE_REJECT)) {
+	if (!TLVP_PRES_LEN(tp, GSM0808_IE_CAUSE, 1)) {
 		LOGPCONN(conn, LOGL_ERROR, "Cause code is missing -- discarding message!\n");
 		return -EINVAL;
 	}
 
-	cause = TLVP_VAL(tp, BSS_MAP_MSG_CIPHER_MODE_REJECT)[0];
-	LOGPCONN(conn, LOGL_NOTICE, "Cipher mode rejection cause: %i\n", cause);
+	/* FIXME: add support for 2-byte Cause values using libosmocore functions */
+	cause = *TLVP_VAL(tp, GSM0808_IE_CAUSE);
+	LOGPCONN(conn, LOGL_NOTICE, "Cipher mode rejection cause: %s\n", gsm0808_cause_name(cause));
 
 	/* FIXME: Can we do something meaningful here? e.g. report to the
 	 * msc code somehow that the cipher mode command has failed. */