summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/gsm/gsm0808_utils.c15
-rw-r--r--tests/gsm0808/gsm0808_test.c57
2 files changed, 63 insertions, 9 deletions
diff --git a/src/gsm/gsm0808_utils.c b/src/gsm/gsm0808_utils.c
index 2d95ec68..ac1e8520 100644
--- a/src/gsm/gsm0808_utils.c
+++ b/src/gsm/gsm0808_utils.c
@@ -677,16 +677,15 @@ uint8_t gsm0808_enc_cell_id_list(struct msgb *msg,
return *tlv_len + 2;
}
-/* Decode 5-byte LAI list element data (see TS 08.08 3.2.2.27) into MCC/MNC/LAC.
- * Return 0 if successful, negative on error. */
-static int decode_lai(const uint8_t *data, uint16_t *mcc, uint16_t *mnc, uint16_t *lac)
+/* Decode 5-byte LAI list element data (see TS 08.08 3.2.2.27) into MCC/MNC/LAC. */
+static void decode_lai(const uint8_t *data, struct osmo_location_area_id *decoded)
{
struct gsm48_loc_area_id lai;
- /* Copy data to stack to prevent unaligned access in gsm48_decode_lai(). */
+ /* Copy data to stack to prevent unaligned access in gsm48_decode_lai2(). */
memcpy(&lai, data, sizeof(lai)); /* don't byte swap yet */
- return gsm48_decode_lai(&lai, mcc, mnc, lac) ? -1 : 0;
+ gsm48_decode_lai2(&lai, decoded);
}
static int parse_cell_id_global_list(struct gsm0808_cell_id_list2 *cil, const uint8_t *data, size_t remain,
@@ -704,8 +703,7 @@ static int parse_cell_id_global_list(struct gsm0808_cell_id_list2 *cil, const ui
return -ENOSPC;
id = &cil->id_list[i].global;
lai_offset = i * elemlen;
- if (decode_lai(&data[lai_offset], &id->lai.plmn.mcc, &id->lai.plmn.mnc, &id->lai.lac) != 0)
- return -EINVAL;
+ decode_lai(&data[lai_offset], &id->lai);
ci_be = (uint16_t *)(&data[lai_offset + sizeof(struct gsm48_loc_area_id)]);
id->cell_identity = osmo_load16be(ci_be);
*consumed += elemlen;
@@ -776,8 +774,7 @@ static int parse_cell_id_lai_and_lac(struct gsm0808_cell_id_list2 *cil, const ui
if (i >= GSM0808_CELL_ID_LIST2_MAXLEN)
return -ENOSPC;
id = &cil->id_list[i].lai_and_lac;
- if (decode_lai(&data[i * elemlen], &id->plmn.mcc, &id->plmn.mnc, &id->lac) != 0)
- return -EINVAL;
+ decode_lai(&data[i * elemlen], id);
*consumed += elemlen;
remain -= elemlen;
i++;
diff --git a/tests/gsm0808/gsm0808_test.c b/tests/gsm0808/gsm0808_test.c
index 8e21b0cb..4da39294 100644
--- a/tests/gsm0808/gsm0808_test.c
+++ b/tests/gsm0808/gsm0808_test.c
@@ -864,6 +864,62 @@ static void test_gsm0808_enc_dec_cell_id_list_bss()
msgb_free(msg);
}
+static void test_gsm0808_enc_dec_cell_id_list_multi_lai_and_lac()
+{
+ struct gsm0808_cell_id_list2 enc_cil;
+ struct gsm0808_cell_id_list2 dec_cil;
+ struct osmo_location_area_id id;
+ struct msgb *msg;
+ uint8_t cil_enc_expected[] = { GSM0808_IE_CELL_IDENTIFIER_LIST, 0x10, 0x04,
+ 0x92, 0x61, 0x54, 0x23, 0x42,
+ 0x92, 0x72, 0x54, 0x24, 0x43,
+ 0x92, 0x83, 0x54, 0x25, 0x44
+ };
+ uint8_t rc_enc;
+ int rc_dec, i;
+
+ memset(&enc_cil, 0, sizeof(enc_cil));
+ enc_cil.id_discr = CELL_IDENT_LAI_AND_LAC;
+
+ id.plmn.mcc = 0x123;
+ osmo_mnc_from_str("456", &id.plmn.mnc, &id.plmn.mnc_3_digits);
+ id.lac = 0x2342;
+ memcpy(&enc_cil.id_list[0].lai_and_lac, &id, sizeof(id));
+
+ id.plmn.mcc = 0x124;
+ osmo_mnc_from_str("457", &id.plmn.mnc, &id.plmn.mnc_3_digits);
+ id.lac = 0x2443;
+ memcpy(&enc_cil.id_list[1].lai_and_lac, &id, sizeof(id));
+
+ id.plmn.mcc = 0x125;
+ osmo_mnc_from_str("458", &id.plmn.mnc, &id.plmn.mnc_3_digits);
+ id.lac = 0x2544;
+ memcpy(&enc_cil.id_list[2].lai_and_lac, &id, sizeof(id));
+
+ enc_cil.id_list_len = 3;
+
+ msg = msgb_alloc(1024, "output buffer");
+ rc_enc = gsm0808_enc_cell_id_list2(msg, &enc_cil);
+ OSMO_ASSERT(rc_enc == sizeof(cil_enc_expected));
+ OSMO_ASSERT(memcmp(cil_enc_expected, msg->data, msg->len) == 0);
+
+ rc_dec = gsm0808_dec_cell_id_list2(&dec_cil, msg->data + 2, msg->len - 2);
+ OSMO_ASSERT(rc_dec == msg->len - 2);
+
+ OSMO_ASSERT(dec_cil.id_list_len == 3);
+ /* Check MAXLEN elements to ensure everything has been initialized. */
+ for (i = 0; i < GSM0808_CELL_ID_LIST2_MAXLEN; i++) {
+ struct osmo_location_area_id *enc_id;
+ struct osmo_location_area_id *dec_id;
+ enc_id = &enc_cil.id_list[i].lai_and_lac;
+ dec_id = &dec_cil.id_list[i].lai_and_lac;
+ OSMO_ASSERT(osmo_plmn_cmp(&enc_id->plmn, &dec_id->plmn) == 0);
+ OSMO_ASSERT(enc_id->lac == dec_id->lac);
+ }
+
+ msgb_free(msg);
+}
+
int main(int argc, char **argv)
{
printf("Testing generation of GSM0808 messages\n");
@@ -899,6 +955,7 @@ int main(int argc, char **argv)
test_gsm0808_enc_dec_cell_id_list_single_lac();
test_gsm0808_enc_dec_cell_id_list_multi_lac();
test_gsm0808_enc_dec_cell_id_list_bss();
+ test_gsm0808_enc_dec_cell_id_list_multi_lai_and_lac();
printf("Done\n");
return EXIT_SUCCESS;