add BSSLAP coding for Location Services

BSSLAP: there are APDUs transferred in BSSMAP-LE Connection Oriented
Information messages on Lb between BSC and SMLC.
Add BSSLAP coding for these APDU messages:
- TA Layer3
- TA Request
- TA Response, possibly containing Location Estimate coded in GAD
- Reject
- Reset (for intra-BSS handover during TA Request)
- Abort (for inter-BSS handover)

Add encoding and decoding tests.

Change-Id: I6409c4bcac402dc7626a3afce9081c59cd715fe8
diff --git a/tests/bsslap/bsslap_test.c b/tests/bsslap/bsslap_test.c
new file mode 100644
index 0000000..43ea0d4
--- /dev/null
+++ b/tests/bsslap/bsslap_test.c
@@ -0,0 +1,103 @@
+#include <stdio.h>
+
+#include <osmocom/core/utils.h>
+#include <osmocom/core/msgb.h>
+#include <osmocom/gsm/bsslap.h>
+
+struct bsslap_pdu bsslap_test_pdus[] = {
+	{
+		.msg_type = BSSLAP_MSGT_TA_REQUEST,
+	},
+	{
+		.msg_type = BSSLAP_MSGT_TA_RESPONSE,
+		.ta_response = {
+			.cell_id = 23,
+			.ta = 42,
+		},
+	},
+	{
+		.msg_type = BSSLAP_MSGT_REJECT,
+		.reject = BSSLAP_CAUSE_OTHER_RADIO_EVT_FAIL,
+	},
+	{
+		.msg_type = BSSLAP_MSGT_RESET,
+		.reset = {
+			.cell_id = 23,
+			.ta = 42,
+			.chan_desc =  {
+				.chan_nr = 23,
+				.h0 = {
+					.tsc = 5,
+					.h = 1,
+					.arfcn_high = 2,
+					.arfcn_low = 3,
+				},
+			},
+			.cause = BSSLAP_CAUSE_INTRA_BSS_HO,
+		},
+	},
+	{
+		.msg_type = BSSLAP_MSGT_ABORT,
+		.abort = BSSLAP_CAUSE_LOSS_SIG_CONN_MS,
+	},
+	{
+		.msg_type = BSSLAP_MSGT_TA_LAYER3,
+		.ta_layer3 = {
+			.ta = 23,
+		},
+	},
+};
+
+void test_bsslap_enc_dec()
+{
+	struct bsslap_pdu *pdu;
+	printf("--- %s\n", __func__);
+
+	for (pdu = bsslap_test_pdus; (pdu - bsslap_test_pdus) < ARRAY_SIZE(bsslap_test_pdus); pdu++) {
+		struct msgb *msg = msgb_alloc(1024, __func__);
+		struct bsslap_pdu dec_pdu;
+		struct osmo_bsslap_err *err;
+		int rc;
+		void *loop_ctx = msg;
+		rc = osmo_bsslap_enc(msg, pdu);
+		if (rc <= 0) {
+			printf("[%ld] %s: ERROR: failed to encode pdu\n", (pdu - bsslap_test_pdus),
+			       osmo_bsslap_msgt_name(pdu->msg_type));
+			goto loop_end;
+		}
+		if (rc != msg->len) {
+			printf("[%ld] %s: ERROR: osmo_bsslap_enc() returned length %d but msgb has %d bytes\n",
+			       (pdu - bsslap_test_pdus), osmo_bsslap_msgt_name(pdu->msg_type),
+			       rc, msg->len);
+			goto loop_end;
+		}
+
+		memset(&dec_pdu, 0xff, sizeof(dec_pdu));
+		rc = osmo_bsslap_dec(&dec_pdu, &err, loop_ctx, msg->data, msg->len);
+		if (rc) {
+			printf("[%ld] %s: ERROR: failed to decode pdu: %s\n", (pdu - bsslap_test_pdus),
+			       osmo_bsslap_msgt_name(pdu->msg_type), err->logmsg);
+			printf("     encoded data: %s\n", osmo_hexdump(msg->data, msg->len));
+			goto loop_end;
+		}
+
+		if (memcmp(pdu, &dec_pdu, sizeof(dec_pdu))) {
+			printf("[%ld] %s: ERROR: decoded PDU != encoded PDU\n", (pdu - bsslap_test_pdus),
+			       osmo_bsslap_msgt_name(pdu->msg_type));
+			printf("     original struct: %s\n", osmo_hexdump((void*)pdu, sizeof(*pdu)));
+			printf("      decoded struct: %s\n", osmo_hexdump((void*)&dec_pdu, sizeof(dec_pdu)));
+			goto loop_end;
+		}
+
+		printf("[%ld] %s: ok\n", (pdu - bsslap_test_pdus), osmo_bsslap_msgt_name(pdu->msg_type));
+
+loop_end:
+		msgb_free(msg);
+	}
+}
+
+int main()
+{
+	test_bsslap_enc_dec();
+	return 0;
+}