Skip to contentSkip to conversation

types.h: auth_method and proto enumerations

PATCH In review Giacinto Cifelli 2 participants 3 messages Oct 9, 2018 – Oct 10, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 types.h: auth_method and proto enumerations

ofono_gprs_proto and ofono_gprs_auth_method, and related length consts, moved to types.h from gprs-context.h,
so that they can be shared also with lte core functions

---
 include/gprs-context.h | 21 ---------------------
 include/types.h        | 21 +++++++++++++++++++++
 2 files changed, 21 insertions(+), 21 deletions(-)
include/gprs-context.h +0 -21
index 8869c12e..965cefc2 100644
@@ -31,21 +31,6 @@ extern "C" {
 struct ofono_gprs_context;
 struct ofono_modem;
 
-/*
- * ETSI 123.003, Section 9.1:
- * the APN has, after encoding as defined in the paragraph below, a maximum
- * length of 100 octets
- */
-#define OFONO_GPRS_MAX_APN_LENGTH 100
-#define OFONO_GPRS_MAX_USERNAME_LENGTH 63
-#define OFONO_GPRS_MAX_PASSWORD_LENGTH 255
-
-enum ofono_gprs_proto {
-	OFONO_GPRS_PROTO_IP = 0,
-	OFONO_GPRS_PROTO_IPV6,
-	OFONO_GPRS_PROTO_IPV4V6,
-};
-
 enum ofono_gprs_context_type {
 	OFONO_GPRS_CONTEXT_TYPE_ANY = 0,
 	OFONO_GPRS_CONTEXT_TYPE_INTERNET,
@@ -54,12 +39,6 @@ enum ofono_gprs_context_type {
 	OFONO_GPRS_CONTEXT_TYPE_IMS,
 };
 
-enum ofono_gprs_auth_method {
-	OFONO_GPRS_AUTH_METHOD_CHAP = 0,
-	OFONO_GPRS_AUTH_METHOD_PAP,
-	OFONO_GPRS_AUTH_METHOD_NONE,
-};
-
 struct ofono_gprs_primary_context {
 	unsigned int cid;
 	char apn[OFONO_GPRS_MAX_APN_LENGTH + 1];
include/types.h +21 -0
index 90d8c2c9..7e356185 100644
@@ -122,6 +122,27 @@ struct ofono_uuid {
 	unsigned char uuid[OFONO_SHA1_UUID_LEN];
 };
 
+/*
+ * ETSI 123.003, Section 9.1:
+ * the APN has, after encoding as defined in the paragraph below, a maximum
+ * length of 100 octets
+ */
+#define OFONO_GPRS_MAX_APN_LENGTH 100
+#define OFONO_GPRS_MAX_USERNAME_LENGTH 63
+#define OFONO_GPRS_MAX_PASSWORD_LENGTH 255
+
+enum ofono_gprs_proto {
+	OFONO_GPRS_PROTO_IP = 0,
+	OFONO_GPRS_PROTO_IPV6,
+	OFONO_GPRS_PROTO_IPV4V6,
+};
+
+enum ofono_gprs_auth_method {
+	OFONO_GPRS_AUTH_METHOD_CHAP = 0,
+	OFONO_GPRS_AUTH_METHOD_PAP,
+	OFONO_GPRS_AUTH_METHOD_NONE,
+};
+
 const char *ofono_uuid_to_str(const struct ofono_uuid *uuid);
 void ofono_call_init(struct ofono_call *call);
 
Signature · 1 line
2.17.1
#1 lore raw

PATCH 2/2 common: proto and auth_method conversion functions

the following functions:
gprs_proto_to_string
gprs_proto_from_string
gprs_auth_method_to_string
gprs_auth_method_from_string

are moved from gprs.c to common.c, with related declaration in common.h so that they can also be accessed from lte core functions

---
 src/common.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/common.h |  8 +++++++
 src/gprs.c   | 62 ----------------------------------------------------
 3 files changed, 70 insertions(+), 62 deletions(-)
src/common.c +62 -0
index 0db412a6..0328a98a 100644
@@ -769,3 +769,65 @@ const char *call_status_to_string(enum call_status status)
 
 	return "unknown";
 }
+
+const char *gprs_proto_to_string(enum ofono_gprs_proto proto)
+{
+	switch (proto) {
+	case OFONO_GPRS_PROTO_IP:
+		return "ip";
+	case OFONO_GPRS_PROTO_IPV6:
+		return "ipv6";
+	case OFONO_GPRS_PROTO_IPV4V6:
+		return "dual";
+	};
+
+	return NULL;
+}
+
+gboolean gprs_proto_from_string(const char *str, enum ofono_gprs_proto *proto)
+{
+	if (g_str_equal(str, "ip")) {
+		*proto = OFONO_GPRS_PROTO_IP;
+		return TRUE;
+	} else if (g_str_equal(str, "ipv6")) {
+		*proto = OFONO_GPRS_PROTO_IPV6;
+		return TRUE;
+	} else if (g_str_equal(str, "dual")) {
+		*proto = OFONO_GPRS_PROTO_IPV4V6;
+		return TRUE;
+	}
+
+	return FALSE;
+}
+
+const char *gprs_auth_method_to_string(enum ofono_gprs_auth_method auth)
+{
+	switch (auth) {
+	case OFONO_GPRS_AUTH_METHOD_CHAP:
+		return "chap";
+	case OFONO_GPRS_AUTH_METHOD_PAP:
+		return "pap";
+	case OFONO_GPRS_AUTH_METHOD_NONE:
+		return "none";
+	};
+
+	return NULL;
+}
+
+gboolean gprs_auth_method_from_string(const char *str,
+					enum ofono_gprs_auth_method *auth)
+{
+	if (g_str_equal(str, "chap")) {
+		*auth = OFONO_GPRS_AUTH_METHOD_CHAP;
+		return TRUE;
+	} else if (g_str_equal(str, "pap")) {
+		*auth = OFONO_GPRS_AUTH_METHOD_PAP;
+		return TRUE;
+	} else if (g_str_equal(str, "none")) {
+		*auth = OFONO_GPRS_AUTH_METHOD_NONE;
+		return TRUE;
+	}
+
+	return FALSE;
+}
+
src/common.h +8 -0
index 923470f5..79c05fc4 100644
@@ -187,3 +187,11 @@ const char *packet_bearer_to_string(int bearer);
 
 gboolean is_valid_apn(const char *apn);
 const char *call_status_to_string(enum call_status status);
+
+const char *gprs_proto_to_string(enum ofono_gprs_proto proto);
+gboolean gprs_proto_from_string(const char *str, enum ofono_gprs_proto *proto);
+
+const char *gprs_auth_method_to_string(enum ofono_gprs_auth_method auth);
+gboolean gprs_auth_method_from_string(const char *str,
+					enum ofono_gprs_auth_method *auth);
+
src/gprs.c +0 -62

68 lines not on this page · raw message

Signature · 1 line
2.17.1
#2 lore raw
In reply to Giacinto Cifelli

Hi Giacinto,

Quoted 8 lines · Giacinto Cifelli

ofono_gprs_proto and ofono_gprs_auth_method, and related length consts, moved to types.h from gprs-context.h,
so that they can be shared also with lte core functions

---
  include/gprs-context.h | 21 ---------------------
  include/types.h        | 21 +++++++++++++++++++++
  2 files changed, 21 insertions(+), 21 deletions(-)

Both applied, thanks.

Regards,
-Denis