Change in libosmocore[master]: gsm23003: Add MME domain name related helper functions

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/.

Harald Welte gerrit-no-reply at lists.osmocom.org
Sun Oct 28 13:22:12 UTC 2018


Harald Welte has submitted this change and it was merged. ( https://gerrit.osmocom.org/11411 )

Change subject: gsm23003: Add MME domain name related helper functions
......................................................................

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
---
M include/osmocom/gsm/gsm23003.h
M include/osmocom/gsm/protocol/gsm_23_003.h
M src/gsm/gsm23003.c
M src/gsm/libosmogsm.map
M tests/gsm23003/gsm23003_test.c
M tests/gsm23003/gsm23003_test.ok
6 files changed, 185 insertions(+), 0 deletions(-)

Approvals:
  Jenkins Builder: Verified
  Harald Welte: Looks good to me, approved



diff --git a/include/osmocom/gsm/gsm23003.h b/include/osmocom/gsm/gsm23003.h
index fd4f369..2f380ae 100644
--- a/include/osmocom/gsm/gsm23003.h
+++ b/include/osmocom/gsm/gsm23003.h
@@ -101,6 +101,7 @@
 const char *osmo_lai_name(const struct osmo_location_area_id *lai);
 const char *osmo_cgi_name(const struct osmo_cell_global_id *cgi);
 const char *osmo_cgi_name2(const struct osmo_cell_global_id *cgi);
+const char *osmo_gummei_name(const struct osmo_gummei *gummei);
 
 void osmo_plmn_to_bcd(uint8_t *bcd_dst, const struct osmo_plmn_id *plmn);
 void osmo_plmn_from_bcd(const uint8_t *bcd_src, struct osmo_plmn_id *plmn);
@@ -120,3 +121,9 @@
 
 int osmo_mnc_cmp(uint16_t a_mnc, bool a_mnc_3_digits, uint16_t b_mnc, bool b_mnc_3_digits);
 int osmo_plmn_cmp(const struct osmo_plmn_id *a, const struct osmo_plmn_id *b);
+
+int osmo_gen_home_network_domain(char *out, const struct osmo_plmn_id *plmn);
+int osmo_parse_home_network_domain(struct osmo_plmn_id *out, const char *in);
+int osmo_gen_mme_domain(char *out, const struct osmo_gummei *gummei);
+int osmo_gen_mme_group_domain(char *out, uint16_t mmegi, const struct osmo_plmn_id *plmn);
+int osmo_parse_mme_domain(struct osmo_gummei *out, const char *in);
diff --git a/include/osmocom/gsm/protocol/gsm_23_003.h b/include/osmocom/gsm/protocol/gsm_23_003.h
index 0e66939..ee697ff 100644
--- a/include/osmocom/gsm/protocol/gsm_23_003.h
+++ b/include/osmocom/gsm/protocol/gsm_23_003.h
@@ -24,3 +24,9 @@
 					 GSM23003_IMEI_SNR_NUM_DIGITS + 1)
 #define GSM23003_IMEISV_NUM_DIGITS	(GSM23003_IMEI_TAC_NUM_DIGITS + \
 					 GSM23003_IMEI_SNR_NUM_DIGITS + 2)
+
+/* Chapter 19.2 "epc.mnc000.mcc000.3gppnetwork.org" */
+#define GSM23003_HOME_NETWORK_DOMAIN_LEN	33
+
+/* Chapter 19.4.2.4: "mmec00.mmegi0000.mme.epc.mnc000.mcc000.3gppnetwork.org" */
+#define GSM23003_MME_DOMAIN_LEN			55
diff --git a/src/gsm/gsm23003.c b/src/gsm/gsm23003.c
index 2c3b21e..4fdad48 100644
--- a/src/gsm/gsm23003.c
+++ b/src/gsm/gsm23003.c
@@ -169,6 +169,14 @@
 	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 @@
 		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 3cc2ec5..4813e13 100644
--- a/src/gsm/libosmogsm.map
+++ b/src/gsm/libosmogsm.map
@@ -315,9 +315,15 @@
 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;
diff --git a/tests/gsm23003/gsm23003_test.c b/tests/gsm23003/gsm23003_test.c
index 947aa18..79965cf 100644
--- a/tests/gsm23003/gsm23003_test.c
+++ b/tests/gsm23003/gsm23003_test.c
@@ -24,8 +24,10 @@
 #include <stdio.h>
 #include <errno.h>
 #include <strings.h>
+#include <string.h>
 
 #include <osmocom/gsm/gsm23003.h>
+#include <osmocom/gsm/protocol/gsm_23_003.h>
 #include <osmocom/core/utils.h>
 
 #define BOOL_STR(b) ((b)? "true" : "false")
@@ -170,6 +172,76 @@
 	return pass;
 }
 
+static bool test_gummei_name()
+{
+	static const struct osmo_gummei gummei = {
+		.plmn = { .mcc = 901, .mnc = 70 },
+		.mme = { .group_id = 0xA123, .code = 0xB1 }
+	};
+	const char *out;
+	bool pass = true;
+
+	out = osmo_gummei_name(&gummei);
+	printf("%s\n", out);
+	if (strcmp(out, "901-70-a123-b1"))
+		pass = false;
+
+	return pass;
+}
+
+static bool test_domain_gen()
+{
+	static const struct osmo_gummei gummei = {
+		.plmn = { .mcc = 901, .mnc = 70 },
+		.mme = { .group_id = 0xA123, .code = 0xB1 }
+	};
+	char out[GSM23003_MME_DOMAIN_LEN];
+	bool pass = true;
+	int rc;
+
+	rc = osmo_gen_home_network_domain(out, &gummei.plmn);
+	if (rc < 0)
+		pass = false;
+	printf("%s -> %s\n", osmo_plmn_name(&gummei.plmn), out);
+	if (strcmp(out, "epc.mnc070.mcc901.3gppnetwork.org"))
+		pass = false;
+
+	rc = osmo_gen_mme_domain(out, &gummei);
+	printf("%s -> %s\n", osmo_gummei_name(&gummei), out);
+	if (strcmp(out, "mmecb1.mmegia123.mme.epc.mnc070.mcc901.3gppnetwork.org"))
+		pass = false;
+
+	return pass;
+}
+
+
+static bool test_domain_parse()
+{
+	static const char *mme_dom_valid = "mmec01.mmegiA001.mme.epc.mnc070.mcc901.3gppnetwork.org";
+	static const char *home_dom_valid = "epc.mnc070.mcc901.3gppnetwork.org";
+	struct osmo_gummei gummei;
+	struct osmo_plmn_id plmn;
+	bool pass = true;
+	int rc;
+
+	rc = osmo_parse_home_network_domain(&plmn, home_dom_valid);
+	if (rc < 0)
+		pass = false;
+	printf("%s -> %s\n", home_dom_valid, osmo_plmn_name(&plmn));
+	if (plmn.mcc != 901 || plmn.mnc != 70)
+		pass = false;
+
+	rc = osmo_parse_mme_domain(&gummei, mme_dom_valid);
+	if (rc < 0)
+		pass = false;
+	printf("%s -> %s\n", mme_dom_valid, osmo_gummei_name(&gummei));
+	if (gummei.plmn.mcc != 901 || gummei.plmn.mnc != 70 ||
+	    gummei.mme.group_id != 0xA001 || gummei.mme.code != 1)
+		pass = false;
+
+	return pass;
+}
+
 int main(int argc, char **argv)
 {
 	bool pass = true;
@@ -177,6 +249,9 @@
 	pass = pass && test_valid_imsi();
 	pass = pass && test_valid_msisdn();
 	pass = pass && test_mnc_from_str();
+	pass = pass && test_gummei_name();
+	pass = pass && test_domain_gen();
+	pass = pass && test_domain_parse();
 
 	OSMO_ASSERT(pass);
 
diff --git a/tests/gsm23003/gsm23003_test.ok b/tests/gsm23003/gsm23003_test.ok
index b435f45..c64f515 100644
--- a/tests/gsm23003/gsm23003_test.ok
+++ b/tests/gsm23003/gsm23003_test.ok
@@ -59,3 +59,8 @@
 13: " 023" rc=-22 mnc=0 mnc_3_digits=0 pass
 14: "023 " rc=-22 mnc=0 mnc_3_digits=0 pass
 15: "023 " rc=-22 mnc=0 mnc_3_digits=0 pass
+901-70-a123-b1
+901-70 -> epc.mnc070.mcc901.3gppnetwork.org
+901-70-a123-b1 -> mmecb1.mmegia123.mme.epc.mnc070.mcc901.3gppnetwork.org
+epc.mnc070.mcc901.3gppnetwork.org -> 901-70
+mmec01.mmegiA001.mme.epc.mnc070.mcc901.3gppnetwork.org -> 901-70-a001-01

-- 
To view, visit https://gerrit.osmocom.org/11411
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Ia882d9db05ec0037e593aeebea21bc31adb680bb
Gerrit-Change-Number: 11411
Gerrit-PatchSet: 2
Gerrit-Owner: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder (1000002)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20181028/86f99366/attachment.htm>


More information about the gerrit-log mailing list