From c4fce1425e19d604c199c895e227dc2519110456 Mon Sep 17 00:00:00 2001 From: Neels Hofmeyr Date: Tue, 20 Feb 2018 13:47:08 +0100 Subject: implement support for 3-digit MNC with leading zeros Enable representing three-digit MNC with leading zeros. The MNCs 23 and 023 are actually different; so far we treated both as 23. Re-encode an incoming BCD or string of 023 as it were, i.e. not dropping the leading zero as 23. Break ABI compatibility by changing the size and ordering of structs gprs_ra_id, osmo_plmn_id, osmo_cell_global_id, ... by adding an mnc_3_digits flag. Change ordering in gprs_ra_id because the canonical oder is {Mobile Country Code, Mobile Network Code}, so have the mcc member first. ABI compatibility cannot be maintained for struct gprs_ra_id, since it is a direct member of structs bssgp_bvc_ctx and bssgp_paging_info, and even just adding a flag to the end would cause ABI changes of those structs. Similarly, osmo_plmn_id is a direct member of osmo_location_area_id, and so forth. Add new API to set and read this additional flag to preserve leading zeros: - osmo_plmn_to_bcd(), osmo_plmn_from_bcd() after gsm48_mcc_mnc_to_bcd() and gsm48_mcc_mnc_from_bcd(). - gsm48_decode_lai2(), gsm48_generate_lai2() after gsm48_decode_lai(), gsm48_generate_lai(). - gsm0808_create_layer3_2() after gsm0808_create_layer3() and gsm0808_create_layer3_aoip(). - various osmo_*_name() functions in gsm23003.h (osmo_rai_name() still in gsm48.h close to struct gprs_ra_id definition). The amount and duplication of these may seem a bit overboard, but IMO they do make sense in this way. Though most code will soon see patches unifying the data structures used, in some cases (vty, ctrl) they are required singled out. Without these functions, the formatting ("%0*u", mnc_3_digits ? 3 : 2, mnc) would be duplicated all over our diverse repositories. In various log output, include the leading MNC zeros. Mark one TODO in card_fs_sim.c, I am not sure how to communicate a leading zero to/from a SIM card FS. The focus here is on the core network / BSS. To indicate ABI incompatibility, bump libosmogsm and libosmogb LIBVERSIONs; adjust debian files accordingly. Implementation choices: - The default behavior upon zero-initialization will be the mnc_3_digits flag set to false, which yields exactly the previous behavior. - I decided against packing the mnc with the mnc_3_digits field into a sub-struct because it would immediately break all builds of dependent projects: it would require immediate merging of numerous patches in other repositories, and it would make compiling older code against a newer libosmocore unneccessarily hard. Change-Id: Id2240f7f518494c9df6c8bda52c0d5092f90f221 --- src/gsm/gsm0808.c | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) (limited to 'src/gsm/gsm0808.c') diff --git a/src/gsm/gsm0808.c b/src/gsm/gsm0808.c index c0be374d..b43e0e63 100644 --- a/src/gsm/gsm0808.c +++ b/src/gsm/gsm0808.c @@ -37,7 +37,8 @@ #define BSSMAP_MSG_SIZE 512 #define BSSMAP_MSG_HEADROOM 128 -/*! Create "Complete L3 Info" for AoIP +/*! Create "Complete L3 Info" for AoIP, legacy implementation. + * Instead use gsm0808_create_layer3_aoip2(), which is capable of three-digit MNC with leading zeros. * \param[in] msg_l3 msgb containing Layer 3 Message * \param[in] nc Mobile Network Code * \param[in] cc Mobile Country Code @@ -49,6 +50,27 @@ struct msgb *gsm0808_create_layer3_aoip(const struct msgb *msg_l3, uint16_t nc, uint16_t cc, int lac, uint16_t _ci, const struct gsm0808_speech_codec_list *scl) +{ + struct osmo_cell_global_id cgi = { + .lai = { + .plmn = { + .mcc = cc, + .mnc = nc, + }, + .lac = lac, + }, + .cell_identity = _ci, + }; + return gsm0808_create_layer3_2(msg_l3, &cgi, scl); +} + +/*! Create "Complete L3 Info" for AoIP. + * \param[in] msg_l3 msgb containing Layer 3 Message -- not modified by this call. + * \param[in] cell MCC, MNC, LAC, CI to identify the cell. + * \param[in] scl Speech Codec List, optional. + * \returns newly allocated msgb with Complete L3 Info message */ +struct msgb *gsm0808_create_layer3_2(const struct msgb *msg_l3, const struct osmo_cell_global_id *cell, + const struct gsm0808_speech_codec_list *scl) { struct msgb* msg; struct { @@ -67,8 +89,8 @@ struct msgb *gsm0808_create_layer3_aoip(const struct msgb *msg_l3, uint16_t nc, /* create the cell header */ lai_ci.ident = CELL_IDENT_WHOLE_GLOBAL; - gsm48_generate_lai(&lai_ci.lai, cc, nc, lac); - lai_ci.ci = osmo_htons(_ci); + gsm48_generate_lai2(&lai_ci.lai, &cell->lai); + lai_ci.ci = osmo_htons(cell->cell_identity); msgb_tlv_put(msg, GSM0808_IE_CELL_IDENTIFIER, sizeof(lai_ci), (uint8_t *) &lai_ci); @@ -86,7 +108,9 @@ struct msgb *gsm0808_create_layer3_aoip(const struct msgb *msg_l3, uint16_t nc, return msg; } -/*! Create "Complete L3 Info" for A +/*! Create "Complete L3 Info" for A, legacy implementation. + * Instead use gsm0808_create_layer3_2() with the scl parameter passed as NULL, + * which is capable of three-digit MNC with leading zeros. * \param[in] msg_l3 msgb containing Layer 3 Message * \param[in] nc Mobile Network Code * \param[in] cc Mobile Country Code -- cgit v1.2.3