Update 3GPP TS 08.08 Cause handling

* add Class definitions
* add helper to check for extended bit
* add helper to get Cause's Class
* use enum in gsm0808_cause_name() and gsm0808_create_cipher_reject() to
  avoid confusion between class and cause
* update gsm0808_create_cipher_reject() comments

Change-Id: I31b31dfc22eb4b6b07089e1255246ac458125340
Related: OS#3187
diff --git a/src/gsm/gsm0808.c b/src/gsm/gsm0808.c
index e5c3e30..791ebc2 100644
--- a/src/gsm/gsm0808.c
+++ b/src/gsm/gsm0808.c
@@ -265,18 +265,18 @@
 }
 
 /*! Create BSSMAP Cipher Mode Reject message
- *  \param[in] cause TS 08.08 cause value
+ *  \param[in] cause 3GPP TS 08.08 §3.2.2.5 cause value
  *  \returns callee-allocated msgb with BSSMAP Cipher Mode Reject message */
-struct msgb *gsm0808_create_cipher_reject(uint8_t cause)
+struct msgb *gsm0808_create_cipher_reject(enum gsm0808_cause cause)
 {
 	struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
-					       "bssmap: clear complete");
+					       "bssmap: cipher mode reject");
 	if (!msg)
 		return NULL;
 
 	msgb_v_put(msg, BSS_MAP_MSG_CIPHER_MODE_REJECT);
-	/* FIXME: support 2-byte cause value as per 3GPP TS 08.08 §3.2.2.5 */
-	msgb_tlv_put(msg, GSM0808_IE_CAUSE, 1, &cause);
+
+	msgb_tlv_put(msg, GSM0808_IE_CAUSE, 1, (const uint8_t *)&cause);
 
 	msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
 
@@ -1271,8 +1271,26 @@
 	{ 0, NULL }
 };
 
+static const struct value_string gsm0808_cause_class_names[] = {
+	{ GSM0808_CAUSE_CLASS_NORM0,		"Normal event" },
+	{ GSM0808_CAUSE_CLASS_NORM1,		"Normal event" },
+	{ GSM0808_CAUSE_CLASS_RES_UNAVAIL,	"Resource unavailable" },
+	{ GSM0808_CAUSE_CLASS_SRV_OPT_NA,	"Service or option not available" },
+	{ GSM0808_CAUSE_CLASS_SRV_OPT_NIMPL,	"Service or option not implemented" },
+	{ GSM0808_CAUSE_CLASS_INVAL,		"Invalid message" },
+	{ GSM0808_CAUSE_CLASS_PERR,		"Protocol error" },
+	{ GSM0808_CAUSE_CLASS_INTW,		"Interworking" },
+	{ 0, NULL }
+};
+
+/*! Return string name of BSSMAP Cause Class name */
+const char *gsm0808_cause_class_name(enum gsm0808_cause_class class)
+{
+	return get_value_string(gsm0808_cause_class_names, class);
+}
+
 /*! Return string name of BSSMAP Cause name */
-const char *gsm0808_cause_name(uint8_t cause)
+const char *gsm0808_cause_name(enum gsm0808_cause cause)
 {
 	return get_value_string(gsm0808_cause_names, cause);
 }