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