gsm0808: Implement helper functions for CONFUSION BSSMAP message decoding.

Also add a test for an actual CONFUSION message parsing.

Change-Id: If8afd2d096fb66c6c2f255a08fc1129de3d09cec
diff --git a/src/gsm/gsm0808.c b/src/gsm/gsm0808.c
index 788f6c3..23468c3 100644
--- a/src/gsm/gsm0808.c
+++ b/src/gsm/gsm0808.c
@@ -21,6 +21,8 @@
  *
  */
 
+#include <string.h>
+
 #include <osmocom/core/byteswap.h>
 #include <osmocom/gsm/gsm0808.h>
 #include <osmocom/gsm/gsm0808_utils.h>
@@ -34,6 +36,9 @@
  *  message generation/encoding.
  */
 
+/*! Char buffer to return strings from functions */
+static __thread char str_buff[512];
+
 /*! Create "Complete L3 Info" for AoIP, legacy implementation.
  * Instead use gsm0808_create_layer3_aoip2(), which is capable of three-digit MNC with leading zeros.
  *  \param[in] msg_l3 msgb containing Layer 3 Message
@@ -1670,6 +1675,39 @@
 	return buf[0];
 }
 
+const char *gsm0808_diagnostics_octet_location_str(uint8_t pointer)
+{
+	switch (pointer) {
+	case 0:
+		return "Error location not determined";
+	case 1:
+		return "The first octet of the message received (i.e. the message type) was found erroneous (unknown)";
+	case 0xfd:
+		return  "The first octet of the BSSAP header (Discrimination) was found erroneous";
+	case 0xfe:
+		return  "(DTAP only) The DLCI (second) octet of the BSSAP header was found erroneous";
+	case 0xff:
+		return  "The last octet of the BSSAP header (length indicator) was found erroneous";
+	default:
+		snprintf(str_buff, sizeof(str_buff), "The %d octet of the message received was found erroneous", pointer);
+		return str_buff;
+	}
+}
+
+const char *gsm0808_diagnostics_bit_location_str(uint8_t bit_pointer)
+{
+	if (bit_pointer == 0) {
+		return "No particular part of the octet is indicated";
+	} else if (bit_pointer > 8) {
+		return "Reserved value";
+	}
+
+	snprintf(str_buff, sizeof(str_buff),
+	         "An error was provoked by the field whose most significant bit is in bit position %d",
+	         bit_pointer);
+	return str_buff;
+}
+
 const struct value_string gsm0808_lcls_config_names[] = {
 	{ GSM0808_LCLS_CFG_BOTH_WAY, "Connect both-way" },
 	{ GSM0808_LCLS_CFG_BOTH_WAY_AND_BICAST_UL,