Open Source Telephony
 help / color / mirror / Atom feed
From: Giacinto Cifelli <gciofono@gmail.com>
To: ofono@ofono.org
Subject: [PATCH 2/2] atmodem/atutil: at_util_get_cgdcont_command
Date: Mon, 22 Oct 2018 20:56:08 +0200	[thread overview]
Message-ID: <20181022185608.27760-2-gciofono@gmail.com> (raw)
In-Reply-To: <20181022185608.27760-1-gciofono@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2163 bytes --]

The function at_util_get_cgdcont_command computes the AT+CGDCONT
string, as per 3GPP 27.007.
It uses a second function, at_util_gprs_proto_to_pdp_type,
that returns the pdp_type string for the command
---
 drivers/atmodem/atutil.c | 27 +++++++++++++++++++++++++++
 drivers/atmodem/atutil.h | 13 +++++++++++++
 2 files changed, 40 insertions(+)

diff --git a/drivers/atmodem/atutil.c b/drivers/atmodem/atutil.c
index ed57b55a..7725513a 100644
--- a/drivers/atmodem/atutil.c
+++ b/drivers/atmodem/atutil.c
@@ -670,3 +670,30 @@ int at_util_auth_type_from_method(enum ofono_gprs_auth_method auth_method)
 
 	return 0;
 }
+
+const char *at_util_gprs_proto_to_pdp_type(enum ofono_gprs_proto proto)
+{
+	switch (proto) {
+	case OFONO_GPRS_PROTO_IPV6:
+		return "IPV6";
+	case OFONO_GPRS_PROTO_IPV4V6:
+		return "IPV4V6";
+		break;
+	case OFONO_GPRS_PROTO_IP:
+		return "IP";
+	}
+
+	return NULL;
+}
+
+char *at_util_get_cgdcont_command(guint cid, enum ofono_gprs_proto proto,
+								const char *apn)
+{
+	const char *pdp_type = at_util_gprs_proto_to_pdp_type(proto);
+
+	if (!apn)
+		return g_strdup_printf("AT+CGDCONT=%u", cid);
+
+	return g_strdup_printf("AT+CGDCONT=%u,\"%s\",\"%s\"", cid, pdp_type,
+									apn);
+}
diff --git a/drivers/atmodem/atutil.h b/drivers/atmodem/atutil.h
index 006ad65a..a924b6f0 100644
--- a/drivers/atmodem/atutil.h
+++ b/drivers/atmodem/atutil.h
@@ -89,6 +89,19 @@ int at_util_get_ipv4_address_and_netmask(const char *addrnetmask,
 
 int at_util_auth_type_from_method(enum ofono_gprs_auth_method auth_method);
 
+const char *at_util_gprs_proto_to_pdp_type(enum ofono_gprs_proto proto);
+
+/*
+ * at_util_get_cgdcont_command
+ * if the apn pointer is NULL, the context will be removed: the resulting
+ * string will be like: AT+CGDCONT=7
+ * but if apn pointer is not NULL and the string is empty, then
+ * this function will create a normal context with empty apn, like:
+ * AT+CGDCONT=4,"IPV6",""
+ */
+char *at_util_get_cgdcont_command(guint cid, enum ofono_gprs_proto proto,
+							const char *apn);
+
 struct cb_data {
 	void *cb;
 	void *data;
-- 
2.17.1


  reply	other threads:[~2018-10-22 18:56 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-22 18:56 [PATCH 1/2] atmodem/atutil: at_util_gprs_proto_to_pdp_type Giacinto Cifelli
2018-10-22 18:56 ` Giacinto Cifelli [this message]
2018-10-22 20:06   ` [PATCH 2/2] atmodem/atutil: at_util_get_cgdcont_command Denis Kenzior
2018-10-22 20:04 ` [PATCH 1/2] atmodem/atutil: at_util_gprs_proto_to_pdp_type Denis Kenzior
2018-10-23  3:01   ` Giacinto Cifelli

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181022185608.27760-2-gciofono@gmail.com \
    --to=gciofono@gmail.com \
    --cc=ofono@ofono.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox