[PATCH] libosmocore[master]: Support decoding of more cell ID list types in libosmocore.

2018-02-16 Thread Stefan Sperling
Hello Jenkins Builder,

I'd like you to reexamine a change.  Please visit

https://gerrit.osmocom.org/6509

to look at the new patch set (#3).

Support decoding of more cell ID list types in libosmocore.

Extend gsm0808_dec_cell_id_list() with support for more types of
cell identifier lists. The new parsing routines are based on similar
routines used by the paging code in osmo-bsc/osmo_bsc_bssap.c.

There is an API change in struct gsm0808_cell_id_list.
The previous definition was insufficient because it assumed that all
decoded cell ID types could be represented with a single uint16_t.
The only user I am aware of is in osmo-msc, where this struct is used
for one local variable. This API user will be fixed in a follow-up patch.

The function gsm0808_enc_cell_id_list() was adapted to keep the code
compiling but encoding more cell ID list types is left for future work.

Change-Id: Ib7e754f538df0c83298a3c958b4e15a32fcb8abb
Related: OS#2847
---
M include/osmocom/gsm/protocol/gsm_08_08.h
M src/gsm/gsm0808_utils.c
M tests/gsm0808/gsm0808_test.c
3 files changed, 227 insertions(+), 22 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/09/6509/3

diff --git a/include/osmocom/gsm/protocol/gsm_08_08.h 
b/include/osmocom/gsm/protocol/gsm_08_08.h
index ba347ef..75c3c61 100644
--- a/include/osmocom/gsm/protocol/gsm_08_08.h
+++ b/include/osmocom/gsm/protocol/gsm_08_08.h
@@ -502,9 +502,67 @@
 };
 
 /* 3GPP TS 48.008 3.2.2.27 Cell Identifier List */
-#define CELL_ID_LIST_LAC_MAXLEN 127
+
+/*
+ * The structs below are parsed representations of data in the corresponding 
IE.
+ * All fields are in host byte-order.
+ *
+ * The functions gsm0808_dec_cell_id_list() and gsm0808_enc_cell_id_list()
+ * convert these structs from/to a network byte-order data stream.
+ *
+ * XXX TODO: These declarations belong in gsm_0808_utils.h, not here.
+ *   However, moving them there currently breaks the build.
+ */
+
+/* Parsed Cell Global Identification (CELL_IDENT_WHOLE_GLOBAL) */
+struct gsm0808_cell_id_global {
+   uint16_t mcc;
+   uint16_t mnc;
+   uint16_t lac;
+   uint16_t ci;
+}a;
+
+/* Parsed Location Area Code and Cell Identity (CELL_IDENT_LAC_AND_CI) */
+struct gsm0808_cell_id_lac_and_ci {
+   uint16_t lac;
+   uint16_t ci;
+};
+
+/* Parsed Cell Identity (CELL_IDENT_CI) */
+struct gsm0808_cell_id_ci {
+   uint16_t ci;
+};
+
+/* Parsed Location Area Identification and Location Area Code 
(CELL_IDENT_LAI_AND_LAC) */
+struct gsm0808_cell_id_lai_and_lac {
+   uint16_t mcc;
+   uint16_t mnc;
+   uint16_t lac;
+};
+
+/* Parsed Location Area Code (CELL_IDENT_LAC) */
+struct gsm0808_cell_id_lac {
+   uint16_t lac;
+};
+
+#define CELL_ID_LIST_MAXLEN254 /* implementation-defined 
limit, in bytes */
+#define CELL_ID_LIST_GLOBAL_MAXLEN (CELL_ID_LIST_MAXLEN / sizeof(struct 
gsm0808_cell_id_global))
+#define CELL_ID_LIST_LAC_AND_CI_MAXLEN (CELL_ID_LIST_MAXLEN / sizeof(struct 
gsm0808_cell_id_lac_and_ci))
+#define CELL_ID_LIST_CI_MAXLEN (CELL_ID_LIST_MAXLEN / sizeof(struct 
gsm0808_cell_id_ci))
+#define CELL_ID_LIST_LAI_AND_LAC_MAXLEN(CELL_ID_LIST_MAXLEN / 
sizeof(struct gsm0808_cell_id_lai_and_lac))
+#define CELL_ID_LIST_LAC_MAXLEN(CELL_ID_LIST_MAXLEN / 
sizeof(struct gsm0808_cell_id_lac))
 struct gsm0808_cell_id_list {
uint8_t id_discr;
-   uint16_t id_list_lac[CELL_ID_LIST_LAC_MAXLEN];
+   union {
+   /*
+* All struct fields in elements of these arrays are in 
host-byte order,
+* ie. contain parsed representations of the data in the 
corresponding IE.
+*/
+   struct gsm0808_cell_id_global   
id_list_global[CELL_ID_LIST_GLOBAL_MAXLEN];
+   struct gsm0808_cell_id_lac_and_ci   
id_list_lac_and_ci[CELL_ID_LIST_LAC_AND_CI_MAXLEN];
+   struct gsm0808_cell_id_ci   
id_list_ci[CELL_ID_LIST_CI_MAXLEN];
+   struct gsm0808_cell_id_lai_and_lac  
id_list_lai_and_lac[CELL_ID_LIST_LAI_AND_LAC_MAXLEN];
+   struct gsm0808_cell_id_lac  
id_list_lac[CELL_ID_LIST_LAC_MAXLEN];
+   } id_list;
unsigned int id_list_len;
 };
diff --git a/src/gsm/gsm0808_utils.c b/src/gsm/gsm0808_utils.c
index 93e6074..a2311cc 100644
--- a/src/gsm/gsm0808_utils.c
+++ b/src/gsm/gsm0808_utils.c
@@ -27,6 +27,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #define IP_V4_ADDR_LEN 4
 #define IP_V6_ADDR_LEN 16
@@ -590,8 +591,9 @@
switch (cil->id_discr) {
case CELL_IDENT_LAC:
OSMO_ASSERT(cil->id_list_len <= CELL_ID_LIST_LAC_MAXLEN)
-   for (i=0;iid_list_len;i++) {
-   msgb_put_u16(msg, cil->id_list_lac[i]);
+   for (i = 0; i < cil->id_list_len; i++) {
+   const struct gsm0808_cell_id_lac *id_lac = 
>id_list.id_list_lac[i];
+   msgb_put_u16(msg, 

[PATCH] libosmocore[master]: Support decoding of more cell ID list types in libosmocore.

2018-02-16 Thread Stefan Sperling
Hello Jenkins Builder,

I'd like you to reexamine a change.  Please visit

https://gerrit.osmocom.org/6509

to look at the new patch set (#2).

Support decoding of more cell ID list types in libosmocore.

Extend gsm0808_dec_cell_id_list() with support for more types of
cell identifier lists. The new parsing routines are based on similar
routines used by the paging code in osmo-bsc/osmo_bsc_bssap.c.

There is an API change in struct gsm0808_cell_id_list.
The previous definition was insufficient because it assumed that all
decoded cell ID types could be represented with a single uint16_t.
The only user I am aware of is in osmo-msc, where this struct is used
for one local variable. This API user will be fixed in a follow-up patch.

The function gsm0808_enc_cell_id_list() was adapted to keep the code
compiling but encoding more cell ID list types is left for future work.

Change-Id: Ib7e754f538df0c83298a3c958b4e15a32fcb8abb
Related: OS#2847
---
M include/osmocom/gsm/protocol/gsm_08_08.h
M src/gsm/gsm0808_utils.c
M tests/gsm0808/gsm0808_test.c
3 files changed, 227 insertions(+), 22 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/09/6509/2

diff --git a/include/osmocom/gsm/protocol/gsm_08_08.h 
b/include/osmocom/gsm/protocol/gsm_08_08.h
index ba347ef..75c3c61 100644
--- a/include/osmocom/gsm/protocol/gsm_08_08.h
+++ b/include/osmocom/gsm/protocol/gsm_08_08.h
@@ -502,9 +502,67 @@
 };
 
 /* 3GPP TS 48.008 3.2.2.27 Cell Identifier List */
-#define CELL_ID_LIST_LAC_MAXLEN 127
+
+/*
+ * The structs below are parsed representations of data in the corresponding 
IE.
+ * All fields are in host byte-order.
+ *
+ * The functions gsm0808_dec_cell_id_list() and gsm0808_enc_cell_id_list()
+ * convert these structs from/to a network byte-order data stream.
+ *
+ * XXX TODO: These declarations belong in gsm_0808_utils.h, not here.
+ *   However, moving them there currently breaks the build.
+ */
+
+/* Parsed Cell Global Identification (CELL_IDENT_WHOLE_GLOBAL) */
+struct gsm0808_cell_id_global {
+   uint16_t mcc;
+   uint16_t mnc;
+   uint16_t lac;
+   uint16_t ci;
+}a;
+
+/* Parsed Location Area Code and Cell Identity (CELL_IDENT_LAC_AND_CI) */
+struct gsm0808_cell_id_lac_and_ci {
+   uint16_t lac;
+   uint16_t ci;
+};
+
+/* Parsed Cell Identity (CELL_IDENT_CI) */
+struct gsm0808_cell_id_ci {
+   uint16_t ci;
+};
+
+/* Parsed Location Area Identification and Location Area Code 
(CELL_IDENT_LAI_AND_LAC) */
+struct gsm0808_cell_id_lai_and_lac {
+   uint16_t mcc;
+   uint16_t mnc;
+   uint16_t lac;
+};
+
+/* Parsed Location Area Code (CELL_IDENT_LAC) */
+struct gsm0808_cell_id_lac {
+   uint16_t lac;
+};
+
+#define CELL_ID_LIST_MAXLEN254 /* implementation-defined 
limit, in bytes */
+#define CELL_ID_LIST_GLOBAL_MAXLEN (CELL_ID_LIST_MAXLEN / sizeof(struct 
gsm0808_cell_id_global))
+#define CELL_ID_LIST_LAC_AND_CI_MAXLEN (CELL_ID_LIST_MAXLEN / sizeof(struct 
gsm0808_cell_id_lac_and_ci))
+#define CELL_ID_LIST_CI_MAXLEN (CELL_ID_LIST_MAXLEN / sizeof(struct 
gsm0808_cell_id_ci))
+#define CELL_ID_LIST_LAI_AND_LAC_MAXLEN(CELL_ID_LIST_MAXLEN / 
sizeof(struct gsm0808_cell_id_lai_and_lac))
+#define CELL_ID_LIST_LAC_MAXLEN(CELL_ID_LIST_MAXLEN / 
sizeof(struct gsm0808_cell_id_lac))
 struct gsm0808_cell_id_list {
uint8_t id_discr;
-   uint16_t id_list_lac[CELL_ID_LIST_LAC_MAXLEN];
+   union {
+   /*
+* All struct fields in elements of these arrays are in 
host-byte order,
+* ie. contain parsed representations of the data in the 
corresponding IE.
+*/
+   struct gsm0808_cell_id_global   
id_list_global[CELL_ID_LIST_GLOBAL_MAXLEN];
+   struct gsm0808_cell_id_lac_and_ci   
id_list_lac_and_ci[CELL_ID_LIST_LAC_AND_CI_MAXLEN];
+   struct gsm0808_cell_id_ci   
id_list_ci[CELL_ID_LIST_CI_MAXLEN];
+   struct gsm0808_cell_id_lai_and_lac  
id_list_lai_and_lac[CELL_ID_LIST_LAI_AND_LAC_MAXLEN];
+   struct gsm0808_cell_id_lac  
id_list_lac[CELL_ID_LIST_LAC_MAXLEN];
+   } id_list;
unsigned int id_list_len;
 };
diff --git a/src/gsm/gsm0808_utils.c b/src/gsm/gsm0808_utils.c
index 93e6074..18f4e70 100644
--- a/src/gsm/gsm0808_utils.c
+++ b/src/gsm/gsm0808_utils.c
@@ -27,6 +27,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #define IP_V4_ADDR_LEN 4
 #define IP_V6_ADDR_LEN 16
@@ -590,8 +591,9 @@
switch (cil->id_discr) {
case CELL_IDENT_LAC:
OSMO_ASSERT(cil->id_list_len <= CELL_ID_LIST_LAC_MAXLEN)
-   for (i=0;iid_list_len;i++) {
-   msgb_put_u16(msg, cil->id_list_lac[i]);
+   for (i = 0; i < cil->id_list_len; i++) {
+   const struct gsm0808_cell_id_lac *id_lac = 
>id_list.id_list_lac[i];
+   msgb_put_u16(msg, 

[PATCH] libosmocore[master]: Support decoding of more cell ID list types in libosmocore.

2018-02-15 Thread Stefan Sperling

Review at  https://gerrit.osmocom.org/6509

Support decoding of more cell ID list types in libosmocore.

Extend gsm0808_dec_cell_id_list() with support for more types of
cell identifier lists. The new parsing routines are based on similar
routines used by the paging code in osmo-bsc/osmo_bsc_bssap.c.

There is an API change in struct gsm0808_cell_id_list.
The previous definition was insufficient because it assumed that all
decoded cell ID types could be represented with a single uint16_t.
The only user I am aware of is in osmo-msc, where this struct is used
for one local variable. This API user will be fixed in a follow-up patch.

The function gsm0808_enc_cell_id_list() was adapted to keep the code
compiling but encoding more cell ID list types is left for future work.

Change-Id: Ib7e754f538df0c83298a3c958b4e15a32fcb8abb
Related: OS#2847
---
M include/osmocom/gsm/protocol/gsm_08_08.h
M src/gsm/gsm0808_utils.c
2 files changed, 222 insertions(+), 17 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/09/6509/1

diff --git a/include/osmocom/gsm/protocol/gsm_08_08.h 
b/include/osmocom/gsm/protocol/gsm_08_08.h
index ba347ef..75c3c61 100644
--- a/include/osmocom/gsm/protocol/gsm_08_08.h
+++ b/include/osmocom/gsm/protocol/gsm_08_08.h
@@ -502,9 +502,67 @@
 };
 
 /* 3GPP TS 48.008 3.2.2.27 Cell Identifier List */
-#define CELL_ID_LIST_LAC_MAXLEN 127
+
+/*
+ * The structs below are parsed representations of data in the corresponding 
IE.
+ * All fields are in host byte-order.
+ *
+ * The functions gsm0808_dec_cell_id_list() and gsm0808_enc_cell_id_list()
+ * convert these structs from/to a network byte-order data stream.
+ *
+ * XXX TODO: These declarations belong in gsm_0808_utils.h, not here.
+ *   However, moving them there currently breaks the build.
+ */
+
+/* Parsed Cell Global Identification (CELL_IDENT_WHOLE_GLOBAL) */
+struct gsm0808_cell_id_global {
+   uint16_t mcc;
+   uint16_t mnc;
+   uint16_t lac;
+   uint16_t ci;
+}a;
+
+/* Parsed Location Area Code and Cell Identity (CELL_IDENT_LAC_AND_CI) */
+struct gsm0808_cell_id_lac_and_ci {
+   uint16_t lac;
+   uint16_t ci;
+};
+
+/* Parsed Cell Identity (CELL_IDENT_CI) */
+struct gsm0808_cell_id_ci {
+   uint16_t ci;
+};
+
+/* Parsed Location Area Identification and Location Area Code 
(CELL_IDENT_LAI_AND_LAC) */
+struct gsm0808_cell_id_lai_and_lac {
+   uint16_t mcc;
+   uint16_t mnc;
+   uint16_t lac;
+};
+
+/* Parsed Location Area Code (CELL_IDENT_LAC) */
+struct gsm0808_cell_id_lac {
+   uint16_t lac;
+};
+
+#define CELL_ID_LIST_MAXLEN254 /* implementation-defined 
limit, in bytes */
+#define CELL_ID_LIST_GLOBAL_MAXLEN (CELL_ID_LIST_MAXLEN / sizeof(struct 
gsm0808_cell_id_global))
+#define CELL_ID_LIST_LAC_AND_CI_MAXLEN (CELL_ID_LIST_MAXLEN / sizeof(struct 
gsm0808_cell_id_lac_and_ci))
+#define CELL_ID_LIST_CI_MAXLEN (CELL_ID_LIST_MAXLEN / sizeof(struct 
gsm0808_cell_id_ci))
+#define CELL_ID_LIST_LAI_AND_LAC_MAXLEN(CELL_ID_LIST_MAXLEN / 
sizeof(struct gsm0808_cell_id_lai_and_lac))
+#define CELL_ID_LIST_LAC_MAXLEN(CELL_ID_LIST_MAXLEN / 
sizeof(struct gsm0808_cell_id_lac))
 struct gsm0808_cell_id_list {
uint8_t id_discr;
-   uint16_t id_list_lac[CELL_ID_LIST_LAC_MAXLEN];
+   union {
+   /*
+* All struct fields in elements of these arrays are in 
host-byte order,
+* ie. contain parsed representations of the data in the 
corresponding IE.
+*/
+   struct gsm0808_cell_id_global   
id_list_global[CELL_ID_LIST_GLOBAL_MAXLEN];
+   struct gsm0808_cell_id_lac_and_ci   
id_list_lac_and_ci[CELL_ID_LIST_LAC_AND_CI_MAXLEN];
+   struct gsm0808_cell_id_ci   
id_list_ci[CELL_ID_LIST_CI_MAXLEN];
+   struct gsm0808_cell_id_lai_and_lac  
id_list_lai_and_lac[CELL_ID_LIST_LAI_AND_LAC_MAXLEN];
+   struct gsm0808_cell_id_lac  
id_list_lac[CELL_ID_LIST_LAC_MAXLEN];
+   } id_list;
unsigned int id_list_len;
 };
diff --git a/src/gsm/gsm0808_utils.c b/src/gsm/gsm0808_utils.c
index 93e6074..18f4e70 100644
--- a/src/gsm/gsm0808_utils.c
+++ b/src/gsm/gsm0808_utils.c
@@ -27,6 +27,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #define IP_V4_ADDR_LEN 4
 #define IP_V6_ADDR_LEN 16
@@ -590,8 +591,9 @@
switch (cil->id_discr) {
case CELL_IDENT_LAC:
OSMO_ASSERT(cil->id_list_len <= CELL_ID_LIST_LAC_MAXLEN)
-   for (i=0;iid_list_len;i++) {
-   msgb_put_u16(msg, cil->id_list_lac[i]);
+   for (i = 0; i < cil->id_list_len; i++) {
+   const struct gsm0808_cell_id_lac *id_lac = 
>id_list.id_list_lac[i];
+   msgb_put_u16(msg, id_lac->lac);
}
break;
case CELL_IDENT_BSS:
@@ -606,6 +608,134 @@
return *tlv_len + 2;
 }
 
+/*