add BSSMAP-LE coding for Location Services

BSSMAP-LE: add Lb-interface messages between BSC and SMLC:
- Reset
- Reset Acknowledge
- Perform Location Request, possibly containing BSSLAP TA Layer3
- Perform Location Response
- Perform Location Abort
- Connection Oriented Information containing any BSSLAP APDU

Add encoding and decoding tests.

Change-Id: I271e59b794bafc0a7ae0eabbf58918f6d7df431d
diff --git a/include/osmocom/gsm/protocol/gsm_49_031.h b/include/osmocom/gsm/protocol/gsm_49_031.h
index b44a07e..c6152e1 100644
--- a/include/osmocom/gsm/protocol/gsm_49_031.h
+++ b/include/osmocom/gsm/protocol/gsm_49_031.h
@@ -29,6 +29,10 @@
 
 #include <stdint.h>
 #include <stdbool.h>
+#include <osmocom/gsm/protocol/gsm_48_071.h>
+#include <osmocom/gsm/protocol/gsm_23_032.h>
+#include <osmocom/gsm/gsm0808_utils.h>
+#include <osmocom/gsm/gsm48.h>
 
 /*! 3GPP TS 49.031 10.13 LCS Cause, also in 3GPP TS 48.008 3.2.2.66, which simply refers to the former. */
 enum lcs_cause {
@@ -58,4 +62,151 @@
 	uint8_t diag_val;
 };
 
+enum bssap_le_msg_discr {
+	BSSAP_LE_MSG_DISCR_BSSMAP_LE = 0,
+};
+
+enum bssmap_le_msgt {
+	BSSMAP_LE_MSGT_PERFORM_LOC_REQ = 0x2b,
+	BSSMAP_LE_MSGT_PERFORM_LOC_RESP = 0x2d,
+	BSSMAP_LE_MSGT_PERFORM_LOC_ABORT = 0x2e,
+	BSSMAP_LE_MSGT_PERFORM_LOC_INFO = 0x2f,
+	BSSMAP_LE_MSGT_ASSIST_INFO_REQ = 0x20,
+	BSSMAP_LE_MSGT_ASSIST_INFO_RESP = 0x21,
+	BSSMAP_LE_MSGT_CONN_ORIENTED_INFO = 0x2a,
+	BSSMAP_LE_MSGT_CONN_LESS_INFO = 0x3a,
+	BSSMAP_LE_MSGT_RESET = 0x30,
+	BSSMAP_LE_MSGT_RESET_ACK = 0x31,
+};
+
+enum bssmap_le_iei {
+	BSSMAP_LE_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_IEI_MLAT_TA = 0x88,
+	BSSMAP_LE_IEI_MS_SYNC_ACC = 0x89,
+	BSSMAP_LE_IEI_SHORT_ID_SET = 0x8a,
+	BSSMAP_LE_IEI_RANDOM_ID_SET = 0x8b,
+	BSSMAP_LE_IEI_SHORT_BSS_ID = 0x8c,
+	BSSMAP_LE_IEI_RANDOM_ID = 0x8d,
+	BSSMAP_LE_IEI_SHORT_ID = 0x8e,
+	BSSMAP_LE_IEI_COVERAGE_CLASS = 0x8f,
+	BSSMAP_LE_IEI_MTA_ACC_SEC_RQD = 0x90,
+};
+
+enum bssmap_le_apdu_proto {
+	BSSMAP_LE_APDU_PROT_RESERVED = 0,
+	BSSMAP_LE_APDU_PROT_BSSLAP = 1,
+	BSSMAP_LE_APDU_PROT_LLP = 2,
+	BSSMAP_LE_APDU_PROT_SMLCPP = 3,
+};
+
+enum bssmap_le_location_information {
+	BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC = 0x0,
+	BSSMAP_LE_LOC_INFO_ASSIST_TARGET_MS = 0x1,
+	BSSMAP_LE_LOC_INFO_BC_DECIPHER_KEYS = 0x2,
+};
+
+enum bssmap_le_positioning_method {
+	BSSMAP_LE_POS_METHOD_OMITTED = 0x0,
+	BSSMAP_LE_POS_METHOD_MOBILE_ASSISTED_E_OTD = 0x1,
+	BSSMAP_LE_POS_METHOD_MOBILE_BASED_E_OTD = 0x2,
+	BSSMAP_LE_POS_METHOD_ASSISTED_GPS = 0x3,
+};
+
+struct bssmap_le_location_type {
+	enum bssmap_le_location_information location_information;
+	enum bssmap_le_positioning_method positioning_method;
+};
+
+enum bssmap_le_lcs_client_type {
+	BSSMAP_LE_LCS_CTYPE_VALUE_ADDED_UNSPECIFIED = 0x0,
+	BSSMAP_LE_LCS_CTYPE_PLMN_OPER_UNSPECIFIED = 0x20,
+	BSSMAP_LE_LCS_CTYPE_PLMN_OPER_BCAST_SERVICE = 0x21,
+	BSSMAP_LE_LCS_CTYPE_PLMN_OPER_OAM = 0x22,
+	BSSMAP_LE_LCS_CTYPE_PLMN_OPER_ANON_STATS = 0x23,
+	BSSMAP_LE_LCS_CTYPE_PLMN_OPER_TGT_MS_SVC = 0x24,
+	BSSMAP_LE_LCS_CTYPE_EMERG_SVC_UNSPECIFIED = 0x30,
+	BSSMAP_LE_LCS_CTYPE_LI_UNSPECIFIED = 0x40,
+};
+
+struct bssmap_le_perform_loc_req {
+	struct bssmap_le_location_type location_type;
+	struct gsm0808_cell_id cell_id;
+
+	bool lcs_client_type_present;
+	enum bssmap_le_lcs_client_type lcs_client_type;
+
+	struct osmo_mobile_identity imsi;
+	struct osmo_mobile_identity imei;
+
+	bool apdu_present;
+	struct bsslap_pdu apdu;
+
+	bool more_items; /*!< always set this to false */
+};
+
+struct bssmap_le_perform_loc_resp {
+	bool location_estimate_present;
+	union gad_raw location_estimate;
+
+	struct lcs_cause_ie lcs_cause;
+
+	bool more_items; /*!< always set this to false */
+};
+
+struct bssmap_le_conn_oriented_info {
+	struct bsslap_pdu apdu;
+
+	bool more_items; /*!< always set this to false */
+};
+
+struct bssmap_le_pdu {
+	enum bssmap_le_msgt msg_type;
+	union {
+		enum gsm0808_cause reset;
+		/* reset_ack consists only of the message type */
+		struct bssmap_le_perform_loc_req perform_loc_req;
+		struct bssmap_le_perform_loc_resp perform_loc_resp;
+		struct lcs_cause_ie perform_loc_abort;
+		struct bssmap_le_conn_oriented_info conn_oriented_info;
+	};
+};
+
+struct bssap_le_pdu {
+	enum bssap_le_msg_discr discr;
+	union {
+		struct bssmap_le_pdu bssmap_le;
+		/* future: add DTAP PDU, currently not implemented */
+	};
+};
+
 /*! @} */