All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] Add AT commands handler in emulator
@ 2011-02-15 13:19 Olivier Guiter
  2011-02-15 13:19 ` [PATCH 1/2] gprs:Add code to handle AT+CGDCONT Olivier Guiter
  2011-02-15 13:19 ` [PATCH 2/2] emulator: Add +CGMI and +CGDCONT commands Olivier Guiter
  0 siblings, 2 replies; 6+ messages in thread
From: Olivier Guiter @ 2011-02-15 13:19 UTC (permalink / raw)
  To: ofono

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

Hi,
This series of patches implements a skeleton for handling AT commands.
These handlers can be local to emulator or stored in a specific atom (e.g. gprs).
Registration mechanism is subject to change.

Olivier Guiter (2):
  gprs:Add code to handle AT+CGDCONT
  emulator: Add +CGMI and +CGDCONT commands

 include/emulator.h |    7 +++++-
 include/gprs.h     |    2 +
 src/emulator.c     |   28 +++++++++++++++++++---
 src/gprs.c         |   63 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 95 insertions(+), 5 deletions(-)


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

* [PATCH 1/2] gprs:Add code to handle AT+CGDCONT
  2011-02-15 13:19 [PATCH 0/2] Add AT commands handler in emulator Olivier Guiter
@ 2011-02-15 13:19 ` Olivier Guiter
  2011-02-16  6:32   ` Denis Kenzior
  2011-02-15 13:19 ` [PATCH 2/2] emulator: Add +CGMI and +CGDCONT commands Olivier Guiter
  1 sibling, 1 reply; 6+ messages in thread
From: Olivier Guiter @ 2011-02-15 13:19 UTC (permalink / raw)
  To: ofono

[-- 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


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

* [PATCH 2/2] emulator: Add +CGMI and +CGDCONT commands
  2011-02-15 13:19 [PATCH 0/2] Add AT commands handler in emulator Olivier Guiter
  2011-02-15 13:19 ` [PATCH 1/2] gprs:Add code to handle AT+CGDCONT Olivier Guiter
@ 2011-02-15 13:19 ` Olivier Guiter
  1 sibling, 0 replies; 6+ messages in thread
From: Olivier Guiter @ 2011-02-15 13:19 UTC (permalink / raw)
  To: ofono

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

---
 include/emulator.h |    7 ++++++-
 src/emulator.c     |   28 ++++++++++++++++++++++++----
 2 files changed, 30 insertions(+), 5 deletions(-)

diff --git a/include/emulator.h b/include/emulator.h
index 2334e02..94053f1 100644
--- a/include/emulator.h
+++ b/include/emulator.h
@@ -27,8 +27,13 @@ extern "C" {
 #endif
 
 #include <ofono/types.h>
+#include <gatserver.h>
 
-struct ofono_emulator;
+struct ofono_emulator {
+	struct ofono_atom *atom;
+	GAtServer *server;
+	struct ofono_atom *gprs_atom;
+};
 
 enum ofono_emulator_type {
 	OFONO_EMULATOR_TYPE_DUN,
diff --git a/src/emulator.c b/src/emulator.c
index c49283d..0ed2ae5 100644
--- a/src/emulator.c
+++ b/src/emulator.c
@@ -28,10 +28,23 @@
 #include "ofono.h"
 #include "gatserver.h"
 
-struct ofono_emulator {
-	struct ofono_atom *atom;
-	GAtServer *server;
-};
+static void cgmi_cb(GAtServerRequestType type, GAtResult *cmd, gpointer user)
+{
+	struct ofono_emulator *em = user;
+	GAtServer *server = em->server;
+
+	switch (type) {
+	case G_AT_SERVER_REQUEST_TYPE_COMMAND_ONLY:
+		g_at_server_send_info(server, "oFono", TRUE);
+		g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
+		break;
+	case G_AT_SERVER_REQUEST_TYPE_SUPPORT:
+		g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
+		break;
+	default:
+		g_at_server_send_final(server, G_AT_SERVER_RESULT_ERROR);
+	};
+}
 
 static void emulator_debug(const char *str, void *data)
 {
@@ -76,6 +89,12 @@ void ofono_emulator_register(struct ofono_emulator *em, int fd)
 	g_at_server_set_disconnect_function(em->server,
 						emulator_disconnect, em);
 
+	/* Register local callbacks */
+	g_at_server_register(em->server, "+CGMI", cgmi_cb, em, NULL);
+
+	/* Register external (atoms) callbacks */
+	ofono_gprs_add_emulator_handler(em);
+
 	__ofono_atom_register(em->atom, emulator_unregister);
 }
 
@@ -102,6 +121,7 @@ struct ofono_emulator *ofono_emulator_create(struct ofono_modem *modem,
 
 	em->atom = __ofono_modem_add_atom(modem, OFONO_ATOM_TYPE_EMULATOR_DUN,
 						emulator_remove, em);
+	em->gprs_atom = __ofono_modem_find_atom(modem, OFONO_ATOM_TYPE_GPRS);
 
 	return em;
 }
-- 
1.7.1


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

* Re: [PATCH 1/2] gprs:Add code to handle AT+CGDCONT
  2011-02-15 13:19 ` [PATCH 1/2] gprs:Add code to handle AT+CGDCONT Olivier Guiter
@ 2011-02-16  6:32   ` Denis Kenzior
  2011-02-16  6:50     ` Marcel Holtmann
  0 siblings, 1 reply; 6+ messages in thread
From: Denis Kenzior @ 2011-02-16  6:32 UTC (permalink / raw)
  To: ofono

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

Hi Olivier,

On 02/15/2011 07:19 AM, Olivier Guiter wrote:
> ---
>  include/gprs.h |    2 +
>  src/gprs.c     |   63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 65 insertions(+), 0 deletions(-)
> 

So I went in a slightly different direction with the emulator API.  Can
you please have a look?

Also, I'd really rather hold off trying to implement CGDCONT right now.
 That piece is quite nasty and generally of lower priority.  I'd like to
get the emulator a bit more hashed out first and implement the base BT
DUN & BT HFP profiles.

Regards,
-Denis

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

* Re: [PATCH 1/2] gprs:Add code to handle AT+CGDCONT
  2011-02-16  6:32   ` Denis Kenzior
@ 2011-02-16  6:50     ` Marcel Holtmann
  2011-02-16  8:30       ` Olivier Guiter
  0 siblings, 1 reply; 6+ messages in thread
From: Marcel Holtmann @ 2011-02-16  6:50 UTC (permalink / raw)
  To: ofono

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

Hi Denis,

> > ---
> >  include/gprs.h |    2 +
> >  src/gprs.c     |   63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> >  2 files changed, 65 insertions(+), 0 deletions(-)
> > 
> 
> So I went in a slightly different direction with the emulator API.  Can
> you please have a look?
> 
> Also, I'd really rather hold off trying to implement CGDCONT right now.
>  That piece is quite nasty and generally of lower priority.  I'd like to
> get the emulator a bit more hashed out first and implement the base BT
> DUN & BT HFP profiles.

for the sake of testing, I would be fine with the real basic CGDCONT and
just offering IP and CID 1. And then of course accepting any APN in that
range and rejecting any other command.

Regards

Marcel



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

* Re: [PATCH 1/2] gprs:Add code to handle AT+CGDCONT
  2011-02-16  6:50     ` Marcel Holtmann
@ 2011-02-16  8:30       ` Olivier Guiter
  0 siblings, 0 replies; 6+ messages in thread
From: Olivier Guiter @ 2011-02-16  8:30 UTC (permalink / raw)
  To: ofono

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

Hi Denis and Marcel,

> Hi Denis,
>
>>> ---
>>>   include/gprs.h |    2 +
>>>   src/gprs.c     |   63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>>>   2 files changed, 65 insertions(+), 0 deletions(-)
>> So I went in a slightly different direction with the emulator API.  Can
>> you please have a look?
>>
>> Also, I'd really rather hold off trying to implement CGDCONT right now.
>>   That piece is quite nasty and generally of lower priority.  I'd like to
>> get the emulator a bit more hashed out first and implement the base BT
>> DUN&  BT HFP profiles.
> for the sake of testing, I would be fine with the real basic CGDCONT and
> just offering IP and CID 1. And then of course accepting any APN in that
> range and rejecting any other command.
The submitted code is just an "how-to", and need to be updated to 
implement the complete CGDCONT (up to now, the function displays the 
existings contexts, and the default range values.
The idea behind this code was to provide the complete chain to handle AT 
commands in atoms. I m not sure the current handler mechanism fit with 
Denis's view ;)
Regards,
Olivier

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

end of thread, other threads:[~2011-02-16  8:30 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-02-15 13:19 [PATCH 0/2] Add AT commands handler in emulator Olivier Guiter
2011-02-15 13:19 ` [PATCH 1/2] gprs:Add code to handle AT+CGDCONT Olivier Guiter
2011-02-16  6:32   ` 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

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.