support for more cell ID list types in libosmocore

Introduce gsm0808_dec_cell_id_list2() with supports additional types of
cell identifier lists. The new parsing routines are based on similar
routines used by the paging code in osmo-bsc's osmo_bsc_bssap.c.

Likewise, introduce gsm0808_enc_cell_id_list2() with support for the
same additional types of cell identifier lists.

The old API using struct gsm0808_cell_id_list is deprecated.
The previous definition was insufficient because it assumed that all
decoded cell ID types could be represented with a single uint16_t.
It was declared in a GSM protocol header (gsm/protocol/gsm_08_08.h)
despite being a host-side representation of data in an IE.
The only user I am aware of is in osmo-msc, where this struct is used
for one local variable. osmo-msc releases >= 1.1.0 make use of this API.

While here, fix a small bug in a test:
test_gsm0808_enc_dec_cell_id_list_bss() set the cell ID type to 'LAC'
but obviously wants to use type 'BSS'.

Change-Id: Ib7e754f538df0c83298a3c958b4e15a32fcb8abb
Related: OS#2847
diff --git a/src/gsm/gsm0808.c b/src/gsm/gsm0808.c
index b43e0e6..3003284 100644
--- a/src/gsm/gsm0808.c
+++ b/src/gsm/gsm0808.c
@@ -521,16 +521,16 @@
  *  \param[in] cil Cell Identity List (where to page)
  *  \param[in] chan_needed Channel Type needed
  *  \returns callee-allocated msgb with BSSMAP PAGING message */
-struct msgb *gsm0808_create_paging(const char *imsi, const uint32_t *tmsi,
-				   const struct gsm0808_cell_id_list *cil,
-				   const uint8_t *chan_needed)
+struct msgb *gsm0808_create_paging2(const char *imsi, const uint32_t *tmsi,
+				    const struct gsm0808_cell_id_list2 *cil,
+				    const uint8_t *chan_needed)
 {
 	struct msgb *msg;
 	uint8_t mid_buf[GSM48_MI_SIZE + 2];
 	int mid_len;
 	uint32_t tmsi_sw;
 
-	/* Mandatory emelents! */
+	/* Mandatory elements! */
 	OSMO_ASSERT(imsi);
 	OSMO_ASSERT(cil);
 
@@ -558,7 +558,7 @@
 
 	/* Cell Identifier List 3.2.2.27 */
 	if (cil)
-		gsm0808_enc_cell_id_list(msg, cil);
+		gsm0808_enc_cell_id_list2(msg, cil);
 
 	/* Channel Needed 3.2.2.36 */
 	if (chan_needed) {
@@ -573,6 +573,32 @@
 	return msg;
 }
 
+/*! DEPRECATED: Use gsm0808_create_paging2 instead.
+ * Create BSSMAP PAGING message.
+ *  \param[in] imsi Mandatory paged IMSI in string representation
+ *  \param[in] tmsi Optional paged TMSI
+ *  \param[in] cil Cell Identity List (where to page)
+ *  \param[in] chan_needed Channel Type needed
+ *  \returns callee-allocated msgb with BSSMAP PAGING message */
+struct msgb *gsm0808_create_paging(const char *imsi, const uint32_t *tmsi,
+				   const struct gsm0808_cell_id_list *cil,
+				   const uint8_t *chan_needed)
+{
+	struct gsm0808_cell_id_list2 cil2 = {};
+
+	/* Mandatory emelents! */
+	OSMO_ASSERT(cil);
+
+	if (cil->id_list_len > GSM0808_CELL_ID_LIST2_MAXLEN)
+		return NULL;
+
+	cil2.id_discr = cil->id_discr;
+	memcpy(cil2.id_list, cil->id_list_lac, cil->id_list_len * sizeof(cil2.id_list[0].lac));
+	cil2.id_list_len = cil->id_list_len;
+
+	return gsm0808_create_paging2(imsi, tmsi, &cil2, chan_needed);
+}
+
 /*! Prepend a DTAP header to given Message Buffer
  *  \param[in] msgb Message Buffer
  *  \param[in] link_id Link Identifier */