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

Note that (besides removing a now unnecessary cast) the gsm0408_test and
abis_test tests of RAI / CGI encoding remain stable, which indicates that the
new code is still correct.

Change-Id: I0d3908fb8ca1e2e669d257b5d59b40675fa85d06
This commit is contained in:
Neels Hofmeyr 2018-02-22 03:19:05 +01:00
parent 7cdd069b7a
commit 4d358c00e1
4 changed files with 10 additions and 9 deletions

View File

@ -1353,7 +1353,7 @@ enum bts_gprs_mode bts_gprs_mode_parse(const char *arg, int *valid);
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);

View File

@ -2850,10 +2850,12 @@ int abis_nm_ipaccess_set_attr(struct gsm_bts *bts, uint8_t obj_class,
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)

View File

@ -279,13 +279,12 @@ void gprs_ra_id_by_bts(struct gprs_ra_id *raid, struct gsm_bts *bts)
};
}
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)

View File

@ -801,7 +801,7 @@ static void test_gsm48_ra_id_by_bts()
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])