summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2018-10-08 22:27:04 +0200
committerHarald Welte <laforge@gnumonks.org>2018-10-28 14:16:18 +0100
commitde1da35d51555648b331a7fd619ad02a1630987a (patch)
tree6a15586774b5e86f4bc01d32be24cc7342d0475f /src
parent7acd5d039491a14a05b6aa08890d28590dde8b96 (diff)
gsm23003: Add MME domain name related helper functions
osmo_gen_mme_group_domain(), osmo_gen_mme_group_domain() and osmo_gen_home_network_domain() Change-Id: Ia882d9db05ec0037e593aeebea21bc31adb680bb
Diffstat (limited to 'src')
-rw-r--r--src/gsm/gsm23003.c86
-rw-r--r--src/gsm/libosmogsm.map6
2 files changed, 92 insertions, 0 deletions
diff --git a/src/gsm/gsm23003.c b/src/gsm/gsm23003.c
index 2c3b21e6..4fdad48a 100644
--- a/src/gsm/gsm23003.c
+++ b/src/gsm/gsm23003.c
@@ -169,6 +169,14 @@ static void to_bcd(uint8_t *bcd, uint16_t val)
bcd[0] = val % 10;
}
+const char *osmo_gummei_name(const struct osmo_gummei *gummei)
+{
+ static char buf[32];
+ snprintf(buf, sizeof(buf), "%s-%04x-%02x", osmo_plmn_name(&gummei->plmn),
+ gummei->mme.group_id, gummei->mme.code);
+ return buf;
+}
+
/* Convert MCC + MNC to BCD representation
* \param[out] bcd_dst caller-allocated memory for output
* \param[in] mcc Mobile Country Code
@@ -297,3 +305,81 @@ int osmo_plmn_cmp(const struct osmo_plmn_id *a, const struct osmo_plmn_id *b)
return 1;
return osmo_mnc_cmp(a->mnc, a->mnc_3_digits, b->mnc, b->mnc_3_digits);
}
+
+/*! Generate TS 23.003 Section 19.2 Home Network Realm/Domain (text form)
+ * \param out[out] caller-provided output buffer, at least 33 bytes long
+ * \param plmn[in] Osmocom representation of PLMN ID (MCC + MNC)
+ * \returns number of characters printed (excluding NUL); negative on error */
+int osmo_gen_home_network_domain(char *out, const struct osmo_plmn_id *plmn)
+{
+ if (plmn->mcc > 999)
+ return -EINVAL;
+ if (plmn->mnc > 999)
+ return -EINVAL;
+ return sprintf(out, "epc.mnc%03u.mcc%03u.3gppnetwork.org", plmn->mnc, plmn->mcc);
+}
+
+/*! Parse a TS 23.003 Section 19.2 Home Network Realm/Domain (text form) into a \ref osmo_plmn_id
+ * \param out[out] caller-allocated output structure
+ * \param in[in] character string representation to be parsed
+ * \returns 0 on success; negative on error */
+int osmo_parse_home_network_domain(struct osmo_plmn_id *out, const char *in)
+{
+ int rc;
+
+ memset(out, 0, sizeof(*out));
+ rc = sscanf(in, "epc.mnc%03hu.mcc%03hu.3gppnetwork.org", &out->mnc, &out->mcc);
+ if (rc < 0)
+ return rc;
+ if (rc != 2)
+ return -EINVAL;
+ return 0;
+}
+
+/*! Generate TS 23.003 Section 19.4.2.4 MME Domain (text form)
+ * \param out[out] caller-provided output buffer, at least 56 bytes long
+ * \param gummei[in] Structure representing the Globally Unique MME Identifier
+ * \returns number of characters printed (excluding NUL); negative on error */
+int osmo_gen_mme_domain(char *out, const struct osmo_gummei *gummei)
+{
+ char domain[GSM23003_HOME_NETWORK_DOMAIN_LEN+1];
+ int rc;
+ rc = osmo_gen_home_network_domain(domain, &gummei->plmn);
+ if (rc < 0)
+ return rc;
+ return sprintf(out, "mmec%02x.mmegi%04x.mme.%s", gummei->mme.code, gummei->mme.group_id, domain);
+}
+
+/*! Parse a TS 23.003 Section 19.4.2.4 MME Domain (text form) into a \ref osmo_gummei
+ * \param out[out] caller-allocated output GUMMEI structure
+ * \param in[in] character string representation to be parsed
+ * \returns 0 on success; negative on error */
+int osmo_parse_mme_domain(struct osmo_gummei *out, const char *in)
+{
+ int rc;
+
+ memset(out, 0, sizeof(*out));
+ rc = sscanf(in, "mmec%02hhx.mmegi%04hx.mme.epc.mnc%03hu.mcc%03hu.3gppnetwork.org",
+ &out->mme.code, &out->mme.group_id,
+ &out->plmn.mnc, &out->plmn.mcc);
+ if (rc < 0)
+ return rc;
+ if (rc != 4)
+ return -EINVAL;
+ return 0;
+}
+
+/*! Generate TS 23.003 Section 19.4.2.4 MME Group Domain (text form)
+ * \param out[out] caller-provided output buffer, at least 56 bytes long
+ * \param mmegi[in] MME Group Identifier
+ * \param plmn[in] Osmocom representation of PLMN ID (MCC + MNC)
+ * \returns number of characters printed (excluding NUL); negative on error */
+int osmo_gen_mme_group_domain(char *out, uint16_t mmegi, const struct osmo_plmn_id *plmn)
+{
+ char domain[GSM23003_HOME_NETWORK_DOMAIN_LEN+1];
+ int rc;
+ rc = osmo_gen_home_network_domain(domain, plmn);
+ if (rc < 0)
+ return rc;
+ return sprintf(out, "mmegi%04x.mme.%s", mmegi, domain);
+}
diff --git a/src/gsm/libosmogsm.map b/src/gsm/libosmogsm.map
index 3cc2ec5f..4813e135 100644
--- a/src/gsm/libosmogsm.map
+++ b/src/gsm/libosmogsm.map
@@ -315,9 +315,15 @@ osmo_lai_name;
osmo_rai_name;
osmo_cgi_name;
osmo_cgi_name2;
+osmo_gummei_name;
osmo_mnc_from_str;
osmo_mnc_cmp;
osmo_plmn_cmp;
+osmo_gen_home_network_domain;
+osmo_parse_home_network_domain;
+osmo_gen_mme_domain;
+osmo_parse_mme_domain;
+osmo_gen_mme_group_domain;
gsm48_chan_mode_names;
gsm_chan_t_names;
gsm48_pdisc_names;