All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 2/2] atmodem: Probe device for previous APN.
@ 2012-12-05 19:02 Forest Bond
  2012-12-05 23:12 ` Marcel Holtmann
  0 siblings, 1 reply; 6+ messages in thread
From: Forest Bond @ 2012-12-05 19:02 UTC (permalink / raw)
  To: ofono

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

From: Forest Bond <forest.bond@rapidrollout.com>

If the device has retained parameters for a previously defined IP
context, is is probed via AT+CGDCONT?.
---
 drivers/atmodem/gprs.c |   55 ++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 53 insertions(+), 2 deletions(-)

diff --git a/drivers/atmodem/gprs.c b/drivers/atmodem/gprs.c
index 3005867..280ca49 100644
--- a/drivers/atmodem/gprs.c
+++ b/drivers/atmodem/gprs.c
@@ -35,6 +35,7 @@
 #include <ofono/log.h>
 #include <ofono/modem.h>
 #include <ofono/gprs.h>
+#include <ofono/gprs-provision.h>
 
 #include "gatchat.h"
 #include "gatresult.h"
@@ -408,6 +409,56 @@ error:
 	ofono_gprs_remove(gprs);
 }
 
+static void at_cgdcont_read_cb(gboolean ok, GAtResult *result,
+				gpointer user_data)
+{
+	struct ofono_gprs *gprs = user_data;
+	struct gprs_data *gd = ofono_gprs_get_data(gprs);
+	GAtResultIter iter;
+	gint cid;
+	const char *pdp_type;
+	const char *apn;
+	struct ofono_gprs_provision_data *ap;
+	gboolean found = FALSE;
+
+	if (!ok)
+		goto done;
+
+	g_at_result_iter_init(&iter, result);
+
+	while (!found && g_at_result_iter_next(&iter, "+CGDCONT:")) {
+		if (!g_at_result_iter_next_number(&iter, &cid))
+			continue;
+
+		if (!g_at_result_iter_next_string(&iter, &pdp_type))
+			continue;
+
+		if (!g_at_result_iter_next_string(&iter, &apn))
+			continue;
+
+		/* We look for IP PDPs */
+		if (g_str_equal(pdp_type, "IP"))
+			found = TRUE;
+	}
+
+	if (found == FALSE)
+		goto done;
+
+	ap = g_try_new0(struct ofono_gprs_provision_data, 1);
+	if (ap == NULL)
+		goto done;
+
+	ap->type = OFONO_GPRS_CONTEXT_TYPE_INTERNET;
+	ap->proto = OFONO_GPRS_PROTO_IP;
+	ap->apn = g_strdup(apn);
+	ofono_info("Probed AP %s from device", apn);
+	ofono_gprs_set_probed_ap(gprs, ap);
+
+done:
+	g_at_chat_send(gd->chat, "AT+CGREG=?", cgreg_prefix,
+			at_cgreg_test_cb, gprs, NULL);
+}
+
 static void at_cgdcont_test_cb(gboolean ok, GAtResult *result,
 				gpointer user_data)
 {
@@ -454,8 +505,8 @@ static void at_cgdcont_test_cb(gboolean ok, GAtResult *result,
 
 	ofono_gprs_set_cid_range(gprs, min, max);
 
-	g_at_chat_send(gd->chat, "AT+CGREG=?", cgreg_prefix,
-			at_cgreg_test_cb, gprs, NULL);
+	g_at_chat_send(gd->chat, "AT+CGDCONT?", cgdcont_prefix,
+			at_cgdcont_read_cb, gprs, NULL);
 
 	return;
 
-- 
1.7.0.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2012-12-06 15:37 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-05 19:02 [PATCH 2/2] atmodem: Probe device for previous APN Forest Bond
2012-12-05 23:12 ` Marcel Holtmann
2012-12-06  2:54   ` Forest Bond
2012-12-04  4:41     ` Denis Kenzior
2012-12-06 11:45       ` Marcel Holtmann
2012-12-06 15:37         ` Forest Bond

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.