Open Source Telephony
 help / color / mirror / Atom feed
From: Olivier Guiter <olivier.guiter@linux.intel.com>
To: ofono@ofono.org
Subject: [PATCH 1/2] gprs:Add code to handle AT+CGDCONT
Date: Tue, 15 Feb 2011 14:19:22 +0100	[thread overview]
Message-ID: <1297775963-3426-2-git-send-email-olivier.guiter@linux.intel.com> (raw)
In-Reply-To: <1297775963-3426-1-git-send-email-olivier.guiter@linux.intel.com>

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

---
 include/gprs.h |    2 +
 src/gprs.c     |   63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 65 insertions(+), 0 deletions(-)

diff --git a/include/gprs.h b/include/gprs.h
index 157a6f9..1901329 100644
--- a/include/gprs.h
+++ b/include/gprs.h
@@ -73,6 +73,8 @@ void ofono_gprs_remove(struct ofono_gprs *gprs);
 void ofono_gprs_set_data(struct ofono_gprs *gprs, void *data);
 void *ofono_gprs_get_data(struct ofono_gprs *gprs);
 
+void ofono_gprs_add_emulator_handler(void *user);
+
 void ofono_gprs_set_cid_range(struct ofono_gprs *gprs,
 				unsigned int min, unsigned int max);
 void ofono_gprs_add_context(struct ofono_gprs *gprs,
diff --git a/src/gprs.c b/src/gprs.c
index 33711dc..b36f94d 100644
--- a/src/gprs.c
+++ b/src/gprs.c
@@ -45,6 +45,7 @@
 #include "idmap.h"
 #include "simutil.h"
 #include "util.h"
+#include "gatserver.h"
 
 #define GPRS_FLAG_ATTACHING 0x1
 #define GPRS_FLAG_RECHECK 0x2
@@ -2762,3 +2763,65 @@ void *ofono_gprs_get_data(struct ofono_gprs *gprs)
 {
 	return gprs->driver_data;
 }
+
+static void ofono_gprs_list_contexts(struct ofono_gprs *gprs, gpointer user)
+{
+	GAtServer *server = user;
+	GSList *l;
+	char buf[256];
+	int i;
+
+	struct pri_context *ctx;
+
+	i = 1;
+	for (l = gprs->contexts; l; l = l->next) {
+		ctx = l->data;
+
+		snprintf(buf, 255, "+CGDCONT: %d,\"%s\",\"%s\"",
+				i, gprs_proto_to_string(ctx->context.proto),
+				ctx->context.apn);
+
+		g_at_server_send_info(server, buf, FALSE);
+		i += 1 ;
+	}
+}
+
+/* Process the usual AT+CGDCONT command
+ * TODO Create context
+ * TODO Delete: how to map the cid with the correct context
+ * TODO Req. type support: check the range.
+ */
+static void cgdcont_cb(GAtServerRequestType type, GAtResult *cmd, gpointer user)
+{
+	struct ofono_emulator *em = user;
+	GAtServer *server = em->server;
+	void *atom_gprs = __ofono_atom_get_data(em->gprs_atom);
+
+	switch (type) {
+	case G_AT_SERVER_REQUEST_TYPE_SUPPORT:  /* +CGDCONT=? */
+		g_at_server_send_info(server,
+				"+CGDCONT: (1-10),\"IP\",,,(0-2),(0,1,2,3,4)", FALSE);
+		g_at_server_send_info(server,
+				"+CGDCONT: (1-2),\"IPv6\",,,(0-2),(0,1,2,3,4)", TRUE);
+		g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
+		break;
+
+	case G_AT_SERVER_REQUEST_TYPE_QUERY:  /* +CGDCONT? */
+		ofono_gprs_list_contexts(atom_gprs, server);
+		g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
+		break;
+
+	case G_AT_SERVER_REQUEST_TYPE_SET:
+		g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
+		break;
+	default:
+		g_at_server_send_final(server, G_AT_SERVER_RESULT_ERROR);
+	};
+}
+
+void ofono_gprs_add_emulator_handler(void *user)
+{
+	struct ofono_emulator *em = user;
+
+	g_at_server_register(em->server, "+CGDCONT", cgdcont_cb, em, NULL);
+}
-- 
1.7.1


  reply	other threads:[~2011-02-15 13:19 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-15 13:19 [PATCH 0/2] Add AT commands handler in emulator Olivier Guiter
2011-02-15 13:19 ` Olivier Guiter [this message]
2011-02-16  6:32   ` [PATCH 1/2] gprs:Add code to handle AT+CGDCONT Denis Kenzior
2011-02-16  6:50     ` Marcel Holtmann
2011-02-16  8:30       ` Olivier Guiter
2011-02-15 13:19 ` [PATCH 2/2] emulator: Add +CGMI and +CGDCONT commands Olivier Guiter

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=1297775963-3426-2-git-send-email-olivier.guiter@linux.intel.com \
    --to=olivier.guiter@linux.intel.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