All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christophe Ronco <c.ronco@kerlink.fr>
To: ofono@ofono.org
Subject: [PATCH] atmodem: use ATD99 to enter data state when needed
Date: Wed, 15 Feb 2017 17:38:37 +0100	[thread overview]
Message-ID: <20170215163837.28766-2-c.ronco@kerlink.fr> (raw)
In-Reply-To: <20170215163837.28766-1-c.ronco@kerlink.fr>

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

Some modems do not support AT+CGDATA="PPP",X to enter data state.
Use AT+CGDATA=? to detect these modems and for them use ATD*99***X#
to enter data state.
---
 drivers/atmodem/gprs-context.c | 44 +++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 43 insertions(+), 1 deletion(-)

diff --git a/drivers/atmodem/gprs-context.c b/drivers/atmodem/gprs-context.c
index f6e6c2ef..bfe0d4b5 100644
--- a/drivers/atmodem/gprs-context.c
+++ b/drivers/atmodem/gprs-context.c
@@ -47,6 +47,7 @@
 
 #define STATIC_IP_NETMASK "255.255.255.255"
 
+static const char *cgdata_prefix[] = { "+CGDATA:", NULL };
 static const char *none_prefix[] = { NULL };
 
 enum state {
@@ -67,6 +68,7 @@ struct gprs_context_data {
 	ofono_gprs_context_cb_t cb;
 	void *cb_data;                                  /* Callback data */
 	unsigned int vendor;
+	gboolean use_atd99;
 };
 
 static void ppp_debug(const char *str, void *data)
@@ -210,7 +212,7 @@ static void at_cgdcont_cb(gboolean ok, GAtResult *result, gpointer user_data)
 		return;
 	}
 
-	if (gcd->vendor == OFONO_VENDOR_SIMCOM_SIM900)
+	if (gcd->use_atd99)
 		sprintf(buf, "ATD*99***%u#", gcd->active_context);
 	else
 		sprintf(buf, "AT+CGDATA=\"PPP\",%u", gcd->active_context);
@@ -378,6 +380,43 @@ static void cgev_notify(GAtResult *result, gpointer user_data)
 		g_at_ppp_shutdown(gcd->ppp);
 }
 
+static void at_cgdata_test_cb(gboolean ok, GAtResult *result,
+				gpointer user_data)
+{
+	struct ofono_gprs_context *gc = user_data;
+	struct gprs_context_data *gcd = ofono_gprs_context_get_data(gc);
+	GAtResultIter iter;
+	const char *data_type;
+	gboolean found = FALSE;
+
+	gcd->use_atd99 = TRUE;
+
+	if (!ok) {
+		DBG("not ok");
+		goto error;
+	}
+
+	g_at_result_iter_init(&iter, result);
+	if (!g_at_result_iter_next(&iter, "+CGDATA:")) {
+		DBG("no +CGDATA line");
+		goto error;
+	}
+
+	if (!g_at_result_iter_open_list(&iter)) {
+		DBG("no list found");
+		goto error;
+	}
+
+	while (!found && g_at_result_iter_next_string(&iter, &data_type)) {
+		if (g_str_equal(data_type, "PPP")) {
+			found = TRUE;
+			gcd->use_atd99 = FALSE;
+		}
+	}
+error:
+	DBG("use_atd99:%d", gcd->use_atd99);
+}
+
 static int at_gprs_context_probe(struct ofono_gprs_context *gc,
 					unsigned int vendor, void *data)
 {
@@ -405,6 +444,9 @@ static int at_gprs_context_probe(struct ofono_gprs_context *gc,
 	if (chat == NULL)
 		return 0;
 
+	g_at_chat_send(chat, "AT+CGDATA=?", cgdata_prefix, at_cgdata_test_cb,
+								gc, NULL);
+
 	g_at_chat_register(chat, "+CGEV:", cgev_notify, FALSE, gc, NULL);
 
 	return 0;
-- 
2.11.0


  reply	other threads:[~2017-02-15 16:38 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-14  9:53 Huawei E3372 Christophe Ronco
2017-02-14 15:47 ` Denis Kenzior
2017-02-14 16:37   ` Christophe Ronco
2017-02-14 16:47     ` Denis Kenzior
2017-02-15 16:38       ` [PATCH 0/1] Use ATD*99 to enter data state when needed Christophe Ronco
2017-02-15 16:38         ` Christophe Ronco [this message]
2017-02-15 20:39           ` [PATCH] atmodem: use ATD99 " Denis Kenzior
2017-02-16  8:40             ` [PATCH v2] " Christophe Ronco
2017-02-16 17:53               ` Denis Kenzior

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=20170215163837.28766-2-c.ronco@kerlink.fr \
    --to=c.ronco@kerlink.fr \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.