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

2018-10-28 Thread Harald Welte
Harald Welte has posted comments on this change. ( 
https://gerrit.osmocom.org/11411 )

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


Set Ready For Review


--
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: comment
Gerrit-Change-Id: Ia882d9db05ec0037e593aeebea21bc31adb680bb
Gerrit-Change-Number: 11411
Gerrit-PatchSet: 2
Gerrit-Owner: Harald Welte 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder (102)
Gerrit-Comment-Date: Sun, 28 Oct 2018 13:22:09 +
Gerrit-HasComments: No
Gerrit-HasLabels: No


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

2018-10-28 Thread Harald Welte
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.mmegi.mme.epc.mnc000.mcc000.3gppnetwork.org" 
*/
+#define GSM23003_MME_DOMAIN_LEN55
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(>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", >mnc, 
>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)
+{
+   

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

2018-10-21 Thread Harald Welte
Harald Welte has uploaded this change for review. ( 
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
4 files changed, 61 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/11/11411/1

diff --git a/include/osmocom/gsm/gsm23003.h b/include/osmocom/gsm/gsm23003.h
index fd4f369..0539fc7 100644
--- a/include/osmocom/gsm/gsm23003.h
+++ b/include/osmocom/gsm/gsm23003.h
@@ -120,3 +120,7 @@

 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, uint16_t mcc, uint16_t mnc);
+int osmo_gen_mme_domain(char *out, uint8_t mmec, uint16_t mmegi, uint16_t mcc, 
uint16_t mnc);
+int osmo_gen_mme_group_domain(char *out, uint16_t mmegi, uint16_t mcc, 
uint16_t mnc);
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.mmegi.mme.epc.mnc000.mcc000.3gppnetwork.org" 
*/
+#define GSM23003_MME_DOMAIN_LEN55
diff --git a/src/gsm/gsm23003.c b/src/gsm/gsm23003.c
index 2c3b21e..bb73364 100644
--- a/src/gsm/gsm23003.c
+++ b/src/gsm/gsm23003.c
@@ -297,3 +297,51 @@
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 mcc[in] Mobile Country Code
+ *  \param mnc[in] Mobile Network Code
+ *  \returns number of characters printed (excluding NUL); negative on error */
+int osmo_gen_home_network_domain(char *out, uint16_t mcc, uint16_t mnc)
+{
+   if (mcc > 999)
+   return -EINVAL;
+   if (mnc > 999)
+   return -EINVAL;
+   return sprintf(out, "epc.mnc%03u.mcc%03u.3gppnetwork.org", mcc, mnc);
+}
+
+/*! 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 mmec[in] MME Code
+ *  \param mmegi[in] MME Group Identifier
+ *  \param mcc[in] Mobile Country Code
+ *  \param mnc[in] Mobile Network Code
+ *  \returns number of characters printed (excluding NUL); negative on error */
+int osmo_gen_mme_domain(char *out, uint8_t mmec, uint16_t mmegi, uint16_t mcc, 
uint16_t mnc)
+{
+   char domain[GSM23003_HOME_NETWORK_DOMAIN_LEN+1];
+   int rc;
+   rc = osmo_gen_home_network_domain(domain, mcc, mnc);
+   if (rc < 0)
+   return rc;
+   return sprintf(out, "mmec%02x.mmegi%04x.mme.%s", mmec, mmegi, domain);
+}
+
+/*! 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 mmec[in] MME Code
+ *  \param mmegi[in] MME Group Identifier
+ *  \param mcc[in] Mobile Country Code
+ *  \param mnc[in] Mobile Network Code
+ *  \returns number of characters printed (excluding NUL); negative on error */
+int osmo_gen_mme_group_domain(char *out, uint16_t mmegi, uint16_t mcc, 
uint16_t mnc)
+{
+   char domain[GSM23003_HOME_NETWORK_DOMAIN_LEN+1];
+   int rc;
+   rc = osmo_gen_home_network_domain(domain, mcc, mnc);
+   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 dcc491d..103334b 100644
--- a/src/gsm/libosmogsm.map
+++ b/src/gsm/libosmogsm.map
@@ -318,6 +318,9 @@
 osmo_mnc_from_str;
 osmo_mnc_cmp;
 osmo_plmn_cmp;
+osmo_gen_home_network_domain;
+osmo_gen_mme_domain;
+osmo_gen_mme_group_domain;
 gsm48_chan_mode_names;
 gsm_chan_t_names;
 gsm48_pdisc_names;

--
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: newchange
Gerrit-Change-Id: Ia882d9db05ec0037e593aeebea21bc31adb680bb