[PATCH] osmo-bsc[master]: gsm48_ra_id_by_bts(): struct gsm48_ra_id* instead of buf

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Neels Hofmeyr gerrit-no-reply at lists.osmocom.org
Mon Mar 5 04:34:29 UTC 2018


Hello Vadim Yanitskiy, Jenkins Builder,

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

    https://gerrit.osmocom.org/6667

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

gsm48_ra_id_by_bts(): struct gsm48_ra_id* instead of buf

Move from using deprecated gsm48_construct_ra(), which uses a buf, to
gsm48_encode_ra(), which uses a gsm48_ra_id argument. Pass struct gsm48_ra_id
around instead of a buf.

struct gsm48_ra_id is the "encoded" representation of the bytes in a typical
MCC-MNC-LAC-RAC (04.08 Routing Area Id IE, 3GPP TS 24.008 § 10.5.5.15). Using
the struct spares using magic numbers for byte offsets.

In the process, fix a sanitizer warning for unaligned access by using memcpy()
instead of pointer assignment:

  osmo-bsc/src/libbsc/abis_nm.c:2857:27: runtime error: store to misaligned address 0x7ffe8e0d6695 for type 'uint16_t', which requires 2 byte alignment

Change-Id: I0d3908fb8ca1e2e669d257b5d59b40675fa85d06
---
M include/osmocom/bsc/gsm_data.h
M src/libbsc/abis_nm.c
M src/libbsc/gsm_data.c
M tests/gsm0408/gsm0408_test.c
4 files changed, 10 insertions(+), 9 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-bsc refs/changes/67/6667/7

diff --git a/include/osmocom/bsc/gsm_data.h b/include/osmocom/bsc/gsm_data.h
index 3c65c9c..8692469 100644
--- a/include/osmocom/bsc/gsm_data.h
+++ b/include/osmocom/bsc/gsm_data.h
@@ -1353,7 +1353,7 @@
 const char *bts_gprs_mode_name(enum bts_gprs_mode mode);
 int bts_gprs_mode_is_compat(struct gsm_bts *bts, enum bts_gprs_mode mode);
 
-int gsm48_ra_id_by_bts(uint8_t *buf, struct gsm_bts *bts);
+void gsm48_ra_id_by_bts(struct gsm48_ra_id *buf, struct gsm_bts *bts);
 void gprs_ra_id_by_bts(struct gprs_ra_id *raid, struct gsm_bts *bts);
 
 int gsm_btsmodel_set_feature(struct gsm_bts_model *model, enum gsm_bts_features feat);
diff --git a/src/libbsc/abis_nm.c b/src/libbsc/abis_nm.c
index 671c874..435d004 100644
--- a/src/libbsc/abis_nm.c
+++ b/src/libbsc/abis_nm.c
@@ -2850,10 +2850,12 @@
 
 void abis_nm_ipaccess_cgi(uint8_t *buf, struct gsm_bts *bts)
 {
-	/* we simply reuse the GSM48 function and overwrite the RAC
-	 * with the Cell ID */
-	gsm48_ra_id_by_bts(buf, bts);
-	*((uint16_t *)(buf + 5)) = htons(bts->cell_identity);
+	struct gsm48_ra_id *_buf = (struct gsm48_ra_id*)buf;
+	uint16_t ci = htons(bts->cell_identity);
+	/* we simply reuse the GSM48 function and write the Cell ID over the position where the RAC
+	 * starts */
+	gsm48_ra_id_by_bts(_buf, bts);
+	memcpy(&_buf->rac, &ci, sizeof(ci));
 }
 
 void gsm_trx_lock_rf(struct gsm_bts_trx *trx, bool locked, const char *reason)
diff --git a/src/libbsc/gsm_data.c b/src/libbsc/gsm_data.c
index 1594522..d4a6a70 100644
--- a/src/libbsc/gsm_data.c
+++ b/src/libbsc/gsm_data.c
@@ -279,13 +279,12 @@
 	};
 }
 
-int gsm48_ra_id_by_bts(uint8_t *buf, struct gsm_bts *bts)
+void gsm48_ra_id_by_bts(struct gsm48_ra_id *buf, struct gsm_bts *bts)
 {
 	struct gprs_ra_id raid;
 
 	gprs_ra_id_by_bts(&raid, bts);
-
-	return gsm48_construct_ra(buf, &raid);
+	gsm48_encode_ra(buf, &raid);
 }
 
 int gsm_parse_reg(void *ctx, regex_t *reg, char **str, int argc, const char **argv)
diff --git a/tests/gsm0408/gsm0408_test.c b/tests/gsm0408/gsm0408_test.c
index d1d50f1..aeec56f 100644
--- a/tests/gsm0408/gsm0408_test.c
+++ b/tests/gsm0408/gsm0408_test.c
@@ -801,7 +801,7 @@
 		bts.location_area_code = t->lac;
 		bts.gprs.rac = t->rac;
 
-		gsm48_ra_id_by_bts((uint8_t*)&result, &bts);
+		gsm48_ra_id_by_bts(&result, &bts);
 
 		ok = (t->expect.digits[0] == result.digits[0])
 		     && (t->expect.digits[1] == result.digits[1])

-- 
To view, visit https://gerrit.osmocom.org/6667
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I0d3908fb8ca1e2e669d257b5d59b40675fa85d06
Gerrit-PatchSet: 7
Gerrit-Project: osmo-bsc
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Neels Hofmeyr <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: Vadim Yanitskiy <axilirator at gmail.com>



More information about the gerrit-log mailing list