From f93970b167aba2805cc67e1326591f31fbe93ada Mon Sep 17 00:00:00 2001 From: Neels Hofmeyr Date: Mon, 5 Mar 2018 02:09:40 +0100 Subject: implement support for 3-digit MNC with leading zeros Add 3-digit flags and use the new RAI and LAI API from libosmocore throughout the code base to be able to handle an MNC < 100 that has three digits (leading zeros). The changes to abis_test and gsm0408_test show that this code now handles 3-digit MNC correctly, by not dropping the leading zero as 0xf in the encoded PLMN. Re-implement CTRL commands 'mcc', 'mnc' and 'mcc-mnc-apply' to preserve the presence of the third digit of the MNC. Always reply with all leading zeros. Adjust the expected results in ctrl_test_runner.py, to show that it works. In VTY and CTRL, the parsing of MCC and MNC is inherently made stricter by use of osmo_{mcc,mnc}_from_str() -- they will no longer allow surplus characters and detect errno returned by strtol() (in contrast to atoi()). Depends: Id2240f7f518494c9df6c8bda52c0d5092f90f221 (libosmocore), Ib7176b1d65a03b76f41f94bc9d3293a8a07d24c6 (libosmocore), I020a4f11791c61742a3d795f782805f7b7e8733e (libosmocore) Change-Id: I8e722103344186fde118b26d8353db95a4581daa --- src/osmo-bsc/osmo_bsc_api.c | 47 +++++++++++++-------------------------------- 1 file changed, 13 insertions(+), 34 deletions(-) (limited to 'src/osmo-bsc/osmo_bsc_api.c') diff --git a/src/osmo-bsc/osmo_bsc_api.c b/src/osmo-bsc/osmo_bsc_api.c index 465832c82..75dae1293 100644 --- a/src/osmo-bsc/osmo_bsc_api.c +++ b/src/osmo-bsc/osmo_bsc_api.c @@ -54,32 +54,20 @@ static int bsc_clear_request(struct gsm_subscriber_connection *conn, uint32_t ca static int complete_layer3(struct gsm_subscriber_connection *conn, struct msgb *msg, struct bsc_msc_data *msc); -static uint16_t get_network_code_for_msc(struct bsc_msc_data *msc) +static struct osmo_cell_global_id *cgi_for_msc(struct bsc_msc_data *msc, struct gsm_bts *bts) { - if (msc->core_mnc != -1) - return msc->core_mnc; - return msc->network->network_code; -} - -static uint16_t get_country_code_for_msc(struct bsc_msc_data *msc) -{ - if (msc->core_mcc != -1) - return msc->core_mcc; - return msc->network->country_code; -} - -static uint16_t get_lac_for_msc(struct bsc_msc_data *msc, struct gsm_bts *bts) -{ - if (msc->core_lac != -1) - return msc->core_lac; - return bts->location_area_code; -} + static struct osmo_cell_global_id cgi; + cgi.lai.plmn = msc->network->plmn; + if (msc->core_plmn.mcc != GSM_MCC_MNC_INVALID) + cgi.lai.plmn.mcc = msc->core_plmn.mcc; + if (msc->core_plmn.mnc != GSM_MCC_MNC_INVALID) { + cgi.lai.plmn.mnc = msc->core_plmn.mnc; + cgi.lai.plmn.mnc_3_digits = msc->core_plmn.mnc_3_digits; + } + cgi.lai.lac = (msc->core_lac != -1) ? msc->core_lac : bts->location_area_code; + cgi.cell_identity = (msc->core_ci != -1) ? msc->core_ci : bts->cell_identity; -static uint16_t get_ci_for_msc(struct bsc_msc_data *msc, struct gsm_bts *bts) -{ - if (msc->core_ci != -1) - return msc->core_ci; - return bts->cell_identity; + return &cgi; } static void bsc_maybe_lu_reject(struct gsm_subscriber_connection *conn, int con_type, int cause) @@ -242,10 +230,6 @@ static int complete_layer3(struct gsm_subscriber_connection *conn, char *imsi = NULL; struct timeval tv; struct msgb *resp; - uint16_t network_code; - uint16_t country_code; - uint16_t lac; - uint16_t ci; enum bsc_con ret; int send_ping = msc->advanced_ping; @@ -285,14 +269,9 @@ static int complete_layer3(struct gsm_subscriber_connection *conn, /* check return value, if failed check msg for and send USSD */ - network_code = get_network_code_for_msc(conn->sccp.msc); - country_code = get_country_code_for_msc(conn->sccp.msc); - lac = get_lac_for_msc(conn->sccp.msc, conn_get_bts(conn)); - ci = get_ci_for_msc(conn->sccp.msc, conn_get_bts(conn)); - bsc_scan_bts_msg(conn, msg); - resp = gsm0808_create_layer3(msg, network_code, country_code, lac, ci); + resp = gsm0808_create_layer3_2(msg, cgi_for_msc(conn->sccp.msc, conn_get_bts(conn)), NULL); if (!resp) { LOGP(DMSC, LOGL_DEBUG, "Failed to create layer3 message.\n"); osmo_bsc_sigtran_del_conn(conn); -- cgit v1.2.3