aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilipp Maier <pmaier@sysmocom.de>2017-03-29 11:35:50 +0200
committerHarald Welte <laforge@gnumonks.org>2017-04-08 07:44:46 +0000
commit783047e86ec64677f3894bd22576315eee631275 (patch)
treeaae96bdea3f2588b98e180ee6909bd9efc09d788
parent14e76b9958b6cb93944a991ffaa5125f601f3d20 (diff)
gsm0808: Add utils for Cell Identifier List
The planned support for true A over IP requires the encoding of the a Cell Identifier List element (see also BSS_MAP_MSG_PAGING). This commt adds encoding/decoding functionality and tests for the element mentioned above, however, it is not yet actively used. Change-Id: I625245dd1dd396fc2bc189e8cd2c444a33042528
-rw-r--r--include/osmocom/gsm/gsm0808_utils.h8
-rw-r--r--include/osmocom/gsm/protocol/gsm_08_08.h8
-rw-r--r--src/gsm/gsm0808_utils.c78
-rw-r--r--src/gsm/libosmogsm.map2
-rw-r--r--tests/gsm0808/gsm0808_test.c85
5 files changed, 181 insertions, 0 deletions
diff --git a/include/osmocom/gsm/gsm0808_utils.h b/include/osmocom/gsm/gsm0808_utils.h
index 5bd27c76..e6e55a7e 100644
--- a/include/osmocom/gsm/gsm0808_utils.h
+++ b/include/osmocom/gsm/gsm0808_utils.h
@@ -63,3 +63,11 @@ uint8_t gsm0808_enc_encrypt_info(struct msgb *msg,
/* Decode Encryption Information element */
int gsm0808_dec_encrypt_info(struct gsm0808_encrypt_info *ei,
const uint8_t *elem, uint8_t len);
+
+/* Encode Cell Identifier List element */
+uint8_t gsm0808_enc_cell_id_list(struct msgb *msg,
+ const struct gsm0808_cell_id_list *cil);
+
+/* Decode Cell Identifier List element */
+int gsm0808_dec_cell_id_list(struct gsm0808_cell_id_list *cil,
+ const uint8_t *elem, uint8_t len);
diff --git a/include/osmocom/gsm/protocol/gsm_08_08.h b/include/osmocom/gsm/protocol/gsm_08_08.h
index 3939aedd..e5e7e1ef 100644
--- a/include/osmocom/gsm/protocol/gsm_08_08.h
+++ b/include/osmocom/gsm/protocol/gsm_08_08.h
@@ -457,3 +457,11 @@ struct gsm0808_encrypt_info {
uint8_t key[ENCRY_INFO_KEY_MAXLEN];
unsigned int key_len;
};
+
+/* 3GPP TS 48.008 3.2.2.27 Cell Identifier List */
+#define CELL_ID_LIST_LAC_MAXLEN 127
+struct gsm0808_cell_id_list {
+ uint8_t id_discr;
+ uint16_t id_list_lac[CELL_ID_LIST_LAC_MAXLEN];
+ unsigned int id_list_len;
+};
diff --git a/src/gsm/gsm0808_utils.c b/src/gsm/gsm0808_utils.c
index 19156050..054372aa 100644
--- a/src/gsm/gsm0808_utils.c
+++ b/src/gsm/gsm0808_utils.c
@@ -450,3 +450,81 @@ int gsm0808_dec_encrypt_info(struct gsm0808_encrypt_info *ei,
return (int)(elem - old_elem);
}
+
+/* Encode Cell Identifier List element */
+uint8_t gsm0808_enc_cell_id_list(struct msgb *msg,
+ const struct gsm0808_cell_id_list *cil)
+{
+ uint8_t *old_tail;
+ uint8_t *tlv_len;
+ unsigned int i;
+
+ OSMO_ASSERT(msg);
+ OSMO_ASSERT(cil);
+
+ msgb_put_u8(msg, GSM0808_IE_CELL_IDENTIFIER_LIST);
+ tlv_len = msgb_put(msg, 1);
+ old_tail = msg->tail;
+
+ msgb_put_u8(msg, cil->id_discr & 0x0f);
+
+ switch (cil->id_discr) {
+ case CELL_IDENT_LAC:
+ OSMO_ASSERT(cil->id_list_len <= CELL_ID_LIST_LAC_MAXLEN)
+ for (i=0;i<cil->id_list_len;i++) {
+ msgb_put_u16(msg, cil->id_list_lac[i]);
+ }
+ break;
+ case CELL_IDENT_BSS:
+ /* Does not have any list items */
+ break;
+ default:
+ /* FIXME: Implement support for all identifier list elements */
+ OSMO_ASSERT(false);
+ }
+
+ *tlv_len = (uint8_t) (msg->tail - old_tail);
+ return *tlv_len + 2;
+}
+
+/* Decode Cell Identifier List element */
+int gsm0808_dec_cell_id_list(struct gsm0808_cell_id_list *cil,
+ const uint8_t *elem, uint8_t len)
+{
+ uint8_t id_discr;
+ const uint8_t *old_elem = elem;
+ unsigned int item_count = 0;
+
+ OSMO_ASSERT(cil);
+ if (!elem)
+ return -EINVAL;
+ if (len <= 0)
+ return -EINVAL;
+
+ memset(cil, 0, sizeof(*cil));
+
+ id_discr = *elem & 0x0f;
+ elem++;
+ len--;
+
+ cil->id_discr = id_discr;
+
+ switch (id_discr) {
+ case CELL_IDENT_LAC:
+ while (len >= 2) {
+ cil->id_list_lac[item_count] = osmo_load16be(elem);
+ elem += 2;
+ item_count++;
+ len -= 2;
+ }
+ case CELL_IDENT_BSS:
+ /* Does not have any list items */
+ break;
+ default:
+ /* FIXME: Implement support for all identifier list elements */
+ return -EINVAL;
+ }
+
+ cil->id_list_len = item_count;
+ return (int)(elem - old_elem);
+}
diff --git a/src/gsm/libosmogsm.map b/src/gsm/libosmogsm.map
index 323ad5ad..cf0a7fee 100644
--- a/src/gsm/libosmogsm.map
+++ b/src/gsm/libosmogsm.map
@@ -150,6 +150,8 @@ gsm0808_enc_channel_type;
gsm0808_dec_channel_type;
gsm0808_enc_encrypt_info;
gsm0808_dec_encrypt_info;
+gsm0808_enc_cell_id_list;
+gsm0808_dec_cell_id_list;
gsm0858_rsl_ul_meas_enc;
diff --git a/tests/gsm0808/gsm0808_test.c b/tests/gsm0808/gsm0808_test.c
index 5fe9c876..af457b4d 100644
--- a/tests/gsm0808/gsm0808_test.c
+++ b/tests/gsm0808/gsm0808_test.c
@@ -610,6 +610,88 @@ static void test_gsm0808_enc_dec_encrypt_info()
msgb_free(msg);
}
+static void test_gsm0808_enc_dec_cell_id_list_lac()
+{
+ struct gsm0808_cell_id_list enc_cil;
+ struct gsm0808_cell_id_list dec_cil;
+ struct msgb *msg;
+ uint8_t rc_enc;
+ int rc_dec;
+
+ memset(&enc_cil, 0, sizeof(enc_cil));
+ enc_cil.id_discr = CELL_IDENT_LAC;
+ enc_cil.id_list_lac[0] = 0x0124;
+ enc_cil.id_list_lac[1] = 0xABCD;
+ enc_cil.id_list_lac[2] = 0x5678;
+ enc_cil.id_list_len = 3;
+
+ msg = msgb_alloc(1024, "output buffer");
+ rc_enc = gsm0808_enc_cell_id_list(msg, &enc_cil);
+ OSMO_ASSERT(rc_enc == 9);
+
+ rc_dec = gsm0808_dec_cell_id_list(&dec_cil, msg->data + 2,
+ msg->len - 2);
+ OSMO_ASSERT(rc_dec == 7);
+
+ OSMO_ASSERT(memcmp(&enc_cil, &dec_cil, sizeof(enc_cil)) == 0);
+
+ msgb_free(msg);
+}
+
+static void test_gsm0808_enc_dec_cell_id_list_single_lac()
+{
+ struct gsm0808_cell_id_list enc_cil;
+ struct gsm0808_cell_id_list dec_cil;
+ struct msgb *msg;
+ uint8_t cil_enc_expected[] = { GSM0808_IE_CELL_IDENTIFIER_LIST, 0x03,
+ 0x05, 0x23, 0x42
+ };
+ uint8_t rc_enc;
+ int rc_dec;
+
+ memset(&enc_cil, 0, sizeof(enc_cil));
+ enc_cil.id_discr = CELL_IDENT_LAC;
+ enc_cil.id_list_lac[0] = 0x2342;
+ enc_cil.id_list_len = 1;
+
+ msg = msgb_alloc(1024, "output buffer");
+ rc_enc = gsm0808_enc_cell_id_list(msg, &enc_cil);
+ OSMO_ASSERT(rc_enc == 5);
+ OSMO_ASSERT(memcmp(cil_enc_expected, msg->data, msg->len) == 0);
+
+ rc_dec = gsm0808_dec_cell_id_list(&dec_cil, msg->data + 2,
+ msg->len - 2);
+ OSMO_ASSERT(rc_dec == 3);
+
+ OSMO_ASSERT(memcmp(&enc_cil, &dec_cil, sizeof(enc_cil)) == 0);
+
+ msgb_free(msg);
+}
+
+static void test_gsm0808_enc_dec_cell_id_list_bss()
+{
+ struct gsm0808_cell_id_list enc_cil;
+ struct gsm0808_cell_id_list dec_cil;
+ struct msgb *msg;
+ uint8_t rc_enc;
+ int rc_dec;
+
+ memset(&enc_cil, 0, sizeof(enc_cil));
+ enc_cil.id_discr = CELL_IDENT_LAC;
+
+ msg = msgb_alloc(1024, "output buffer");
+ rc_enc = gsm0808_enc_cell_id_list(msg, &enc_cil);
+ OSMO_ASSERT(rc_enc == 3);
+
+ rc_dec = gsm0808_dec_cell_id_list(&dec_cil, msg->data + 2,
+ msg->len - 2);
+ OSMO_ASSERT(rc_dec == 1);
+
+ OSMO_ASSERT(memcmp(&enc_cil, &dec_cil, sizeof(enc_cil)) == 0);
+
+ msgb_free(msg);
+}
+
int main(int argc, char **argv)
{
printf("Testing generation of GSM0808 messages\n");
@@ -637,6 +719,9 @@ int main(int argc, char **argv)
test_gsm0808_enc_dec_speech_codec_list();
test_gsm0808_enc_dec_channel_type();
test_gsm0808_enc_dec_encrypt_info();
+ test_gsm0808_enc_dec_cell_id_list_lac();
+ test_gsm0808_enc_dec_cell_id_list_single_lac();
+ test_gsm0808_enc_dec_cell_id_list_bss();
printf("Done\n");
return EXIT_SUCCESS;