Open Source Telephony
 help / color / mirror / Atom feed
* [PATCH 00/16] Implement DUN server for oFono
@ 2010-08-11  2:26 Zhenhua Zhang
  2010-08-11  2:26 ` [PATCH 01/16] gprs: Rename status_watch to netreg_status_watch Zhenhua Zhang
                   ` (15 more replies)
  0 siblings, 16 replies; 23+ messages in thread
From: Zhenhua Zhang @ 2010-08-11  2:26 UTC (permalink / raw)
  To: ofono

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

Hi,

These patches are based my 6 patches sent on Aug 5th. It implements DUN server logic to manage GPRS context create/destroy per DUN client requests. On DUN client side, you can use 'rfcomm bind 0 xx:xx:xx:xx:xx:xx 1' and then 'gsmdial -n /dev/rfcomm0 -c 1 -a cid -l' to test it.

Review comments are welcome!

Regards,
Zhenhua


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

* [PATCH 01/16] gprs: Rename status_watch to netreg_status_watch
  2010-08-11  2:26 [PATCH 00/16] Implement DUN server for oFono Zhenhua Zhang
@ 2010-08-11  2:26 ` Zhenhua Zhang
  2010-08-11  2:26 ` [PATCH 02/16] emulator: Add status watches for ofono emulator Zhenhua Zhang
                   ` (14 subsequent siblings)
  15 siblings, 0 replies; 23+ messages in thread
From: Zhenhua Zhang @ 2010-08-11  2:26 UTC (permalink / raw)
  To: ofono

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

To be more precise and avoid name conflict with dun_status_watch.
---
 src/gprs.c |   15 ++++++++-------
 1 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/src/gprs.c b/src/gprs.c
index 2c5bb4e..6c6f07e 100644
--- a/src/gprs.c
+++ b/src/gprs.c
@@ -72,7 +72,7 @@ struct ofono_gprs {
 	int netreg_status;
 	struct ofono_netreg *netreg;
 	unsigned int netreg_watch;
-	unsigned int status_watch;
+	unsigned int netreg_status_watch;
 	GKeyFile *settings;
 	char *imsi;
 	DBusMessage *pending;
@@ -1597,10 +1597,10 @@ static void gprs_unregister(struct ofono_atom *atom)
 	}
 
 	if (gprs->netreg_watch) {
-		if (gprs->status_watch) {
+		if (gprs->netreg_status_watch) {
 			__ofono_netreg_remove_status_watch(gprs->netreg,
-							gprs->status_watch);
-			gprs->status_watch = 0;
+						gprs->netreg_status_watch);
+			gprs->netreg_status_watch = 0;
 		}
 
 		__ofono_modem_remove_atom_watch(modem, gprs->netreg_watch);
@@ -1684,15 +1684,16 @@ static void netreg_watch(struct ofono_atom *atom,
 	struct ofono_gprs *gprs = data;
 
 	if (cond == OFONO_ATOM_WATCH_CONDITION_UNREGISTERED) {
-		gprs->status_watch = 0;
+		gprs->netreg_status_watch = 0;
 		gprs->netreg = NULL;
 		return;
 	}
 
 	gprs->netreg = __ofono_atom_get_data(atom);
 	gprs->netreg_status = ofono_netreg_get_status(gprs->netreg);
-	gprs->status_watch = __ofono_netreg_add_status_watch(gprs->netreg,
-					netreg_status_changed, gprs, NULL);
+	gprs->netreg_status_watch = __ofono_netreg_add_status_watch(
+					gprs->netreg, netreg_status_changed,
+					gprs, NULL);
 
 	gprs_netreg_update(gprs);
 }
-- 
1.7.0.4


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

* [PATCH 02/16] emulator: Add status watches for ofono emulator
  2010-08-11  2:26 [PATCH 00/16] Implement DUN server for oFono Zhenhua Zhang
  2010-08-11  2:26 ` [PATCH 01/16] gprs: Rename status_watch to netreg_status_watch Zhenhua Zhang
@ 2010-08-11  2:26 ` Zhenhua Zhang
  2010-08-11  2:26 ` [PATCH 03/16] emulator: Add emulator status watches in gprs atom Zhenhua Zhang
                   ` (13 subsequent siblings)
  15 siblings, 0 replies; 23+ messages in thread
From: Zhenhua Zhang @ 2010-08-11  2:26 UTC (permalink / raw)
  To: ofono

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

The status watches monitor the emulator activities. Other atoms like
gprs, netreg could register notification to watch emulator status
changes.
---
 include/emulator.h |    6 +++++
 src/emulator.c     |   60 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/ofono.h        |   11 +++++++++
 3 files changed, 77 insertions(+), 0 deletions(-)

diff --git a/include/emulator.h b/include/emulator.h
index 1033e59..29e87b9 100644
--- a/include/emulator.h
+++ b/include/emulator.h
@@ -30,6 +30,12 @@ extern "C" {
 
 struct ofono_emulator;
 
+enum ofono_emulator_status {
+	OFONO_EMULATOR_STATUS_IDLE = 0,
+	OFONO_EMULATOR_STATUS_CREATE,
+	OFONO_EMULATOR_STATUS_DESTROY,
+};
+
 struct ofono_emulator *ofono_emulator_create(struct ofono_modem *modem,
 						enum ofono_atom_type type,
 						GIOChannel *io);
diff --git a/src/emulator.c b/src/emulator.c
index 6219bb1..f9e82a0 100644
--- a/src/emulator.c
+++ b/src/emulator.c
@@ -39,6 +39,8 @@ struct ofono_emulator {
 	enum ofono_atom_type type;
 	unsigned int id;
 	GAtServer *server;
+	enum ofono_emulator_status status;
+	struct ofono_watchlist *status_watches;
 };
 
 static unsigned int ofono_emulator_ids;
@@ -69,12 +71,31 @@ static void ofono_emulator_release_id(int id)
 	ofono_emulator_ids &= ~(0x1 << id);
 }
 
+static void notify_status_watches(struct ofono_emulator *e, void *data)
+{
+	struct ofono_watchlist_item *item;
+	ofono_emulator_status_notify_cb_t notify;
+	GSList *l;
+
+	for (l = e->status_watches->items; l; l = l->next) {
+		item = l->data;
+		notify = item->notify;
+
+		notify(e, e->status, data, item->notify_data);
+	}
+}
+
 static void emulator_remove(struct ofono_atom *atom)
 {
 	struct ofono_emulator *e =  __ofono_atom_get_data(atom);
 
 	DBG("");
 
+	e->status = OFONO_EMULATOR_STATUS_DESTROY;
+	notify_status_watches(e, NULL);
+
+	__ofono_watchlist_free(e->status_watches);
+
 	g_at_server_shutdown(e->server);
 	g_at_server_unref(e->server);
 	e->server = NULL;
@@ -84,6 +105,37 @@ static void emulator_remove(struct ofono_atom *atom)
 	e = NULL;
 }
 
+unsigned int __ofono_emulator_add_status_watch(struct ofono_emulator *e,
+				ofono_emulator_status_notify_cb_t notify,
+				void *data, ofono_destroy_func destroy)
+{
+	struct ofono_watchlist_item *item;
+
+	DBG("%p", e);
+
+	if (e == NULL)
+		return 0;
+
+	if (notify == NULL)
+		return 0;
+
+	item = g_new0(struct ofono_watchlist_item, 1);
+
+	item->notify = notify;
+	item->destroy = destroy;
+	item->notify_data = data;
+
+	return __ofono_watchlist_add_item(e->status_watches, item);
+}
+
+gboolean __ofono_emulator_remove_status_watch(struct ofono_emulator *e,
+						unsigned int id)
+{
+	DBG("%p", e);
+
+	return __ofono_watchlist_remove_item(e->status_watches, id);
+}
+
 static void emulator_disconnect(gpointer user_data)
 {
 	struct ofono_emulator *e = user_data;
@@ -91,6 +143,10 @@ static void emulator_disconnect(gpointer user_data)
 	__ofono_atom_free(e->atom);
 }
 
+static void emulator_unregister(struct ofono_atom *atom)
+{
+}
+
 struct ofono_emulator *ofono_emulator_create(struct ofono_modem *modem,
 						enum ofono_atom_type type,
 						GIOChannel *channel)
@@ -115,7 +171,11 @@ struct ofono_emulator *ofono_emulator_create(struct ofono_modem *modem,
 	e->modem = modem;
 	e->type = type;
 	e->id = ofono_emulator_next_id();
+	e->status_watches = __ofono_watchlist_new(g_free);
+	e->status = OFONO_EMULATOR_STATUS_CREATE;
 	e->atom = __ofono_modem_add_atom(modem, type, emulator_remove, e);
 
+	__ofono_atom_register(e->atom, emulator_unregister);
+
 	return e;
 }
diff --git a/src/ofono.h b/src/ofono.h
index 8982a95..a7a9849 100644
--- a/src/ofono.h
+++ b/src/ofono.h
@@ -292,3 +292,14 @@ void __ofono_nettime_info_received(struct ofono_modem *modem,
 					struct ofono_network_time *info);
 
 #include <ofono/emulator.h>
+
+typedef void (*ofono_emulator_status_notify_cb_t)(struct ofono_emulator *e,
+					enum ofono_emulator_status status,
+					void *data, void *user_data);
+
+unsigned int __ofono_emulator_add_status_watch(struct ofono_emulator *e,
+				ofono_emulator_status_notify_cb_t notify,
+				void *data, ofono_destroy_func destroy);
+
+gboolean __ofono_emulator_remove_status_watch(struct ofono_emulator *e,
+						unsigned int id);
-- 
1.7.0.4


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

* [PATCH 03/16] emulator: Add emulator status watches in gprs atom
  2010-08-11  2:26 [PATCH 00/16] Implement DUN server for oFono Zhenhua Zhang
  2010-08-11  2:26 ` [PATCH 01/16] gprs: Rename status_watch to netreg_status_watch Zhenhua Zhang
  2010-08-11  2:26 ` [PATCH 02/16] emulator: Add status watches for ofono emulator Zhenhua Zhang
@ 2010-08-11  2:26 ` Zhenhua Zhang
  2010-08-11  2:26 ` [PATCH 04/16] emulator: Add APIs to send GAtServer result Zhenhua Zhang
                   ` (12 subsequent siblings)
  15 siblings, 0 replies; 23+ messages in thread
From: Zhenhua Zhang @ 2010-08-11  2:26 UTC (permalink / raw)
  To: ofono

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

Add dun_watch to watch emulator status update in gprs atom. So that gprs
atom could get notified when we get request to create new PPP connection
from DUN client;
---
 src/gprs.c |   60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 60 insertions(+), 0 deletions(-)

diff --git a/src/gprs.c b/src/gprs.c
index 6c6f07e..8002cf4 100644
--- a/src/gprs.c
+++ b/src/gprs.c
@@ -80,6 +80,9 @@ struct ofono_gprs {
 	const struct ofono_gprs_driver *driver;
 	void *driver_data;
 	struct ofono_atom *atom;
+	struct ofono_emulator *dun;
+	unsigned int dun_watch;
+	unsigned int dun_status_watch;
 };
 
 struct ofono_gprs_context {
@@ -1459,6 +1462,39 @@ void ofono_gprs_context_deactivated(struct ofono_gprs_context *gc,
 	}
 }
 
+static void dun_status_watch(struct ofono_emulator *e,
+					enum ofono_emulator_status status,
+					void *data, void *user_data)
+{
+	if (e == NULL)
+		return;
+
+	switch (status) {
+	default:
+		break;
+	}
+}
+
+static void dun_watch(struct ofono_atom *atom,
+					enum ofono_atom_watch_condition cond,
+					void *data)
+{
+	struct ofono_gprs *gprs = data;
+	struct ofono_emulator *e = __ofono_atom_get_data(atom);
+
+	if (cond == OFONO_ATOM_WATCH_CONDITION_UNREGISTERED) {
+		gprs->dun_status_watch = 0;
+		gprs->dun = NULL;
+		return;
+	}
+
+	DBG("");
+
+	gprs->dun = e;
+	gprs->dun_status_watch = __ofono_emulator_add_status_watch(e,
+						dun_status_watch, gprs, NULL);
+}
+
 int ofono_gprs_context_driver_register(const struct ofono_gprs_context_driver *d)
 {
 	DBG("driver: %p, name: %s", d, d->name);
@@ -1608,6 +1644,18 @@ static void gprs_unregister(struct ofono_atom *atom)
 		gprs->netreg = NULL;
 	}
 
+	if (gprs->dun_watch) {
+		if (gprs->dun_status_watch) {
+			__ofono_emulator_remove_status_watch(gprs->dun,
+							gprs->dun_status_watch);
+			gprs->dun_status_watch = 0;
+		}
+
+		__ofono_modem_remove_atom_watch(modem, gprs->dun_watch);
+		gprs->dun_watch = 0;
+		gprs->dun = NULL;
+	}
+
 	ofono_modem_remove_interface(modem,
 					OFONO_DATA_CONNECTION_MANAGER_INTERFACE);
 	g_dbus_unregister_interface(conn, path,
@@ -1862,6 +1910,7 @@ void ofono_gprs_register(struct ofono_gprs *gprs)
 	const char *path = __ofono_atom_get_path(gprs->atom);
 	struct ofono_atom *netreg_atom;
 	struct ofono_atom *sim_atom;
+	struct ofono_atom *dun_atom;
 
 	if (!g_dbus_register_interface(conn, path,
 					OFONO_DATA_CONNECTION_MANAGER_INTERFACE,
@@ -1895,6 +1944,17 @@ void ofono_gprs_register(struct ofono_gprs *gprs)
 		netreg_watch(netreg_atom,
 				OFONO_ATOM_WATCH_CONDITION_REGISTERED, gprs);
 
+	gprs->dun_watch = __ofono_modem_add_atom_watch(modem,
+						OFONO_ATOM_TYPE_EMULATOR_DUN,
+						dun_watch, gprs, NULL);
+
+	dun_atom = __ofono_modem_find_atom(modem,
+						OFONO_ATOM_TYPE_EMULATOR_DUN);
+
+	if (dun_atom && __ofono_atom_get_registered(dun_atom))
+		dun_watch(dun_atom,
+				OFONO_ATOM_WATCH_CONDITION_REGISTERED, gprs);
+
 	__ofono_atom_register(gprs->atom, gprs_unregister);
 }
 
-- 
1.7.0.4


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

* [PATCH 04/16] emulator: Add APIs to send GAtServer result
  2010-08-11  2:26 [PATCH 00/16] Implement DUN server for oFono Zhenhua Zhang
                   ` (2 preceding siblings ...)
  2010-08-11  2:26 ` [PATCH 03/16] emulator: Add emulator status watches in gprs atom Zhenhua Zhang
@ 2010-08-11  2:26 ` Zhenhua Zhang
  2010-08-12 11:52   ` Marcel Holtmann
  2010-08-11  2:26 ` [PATCH 05/16] emulator: Implement dialing up for DUN Zhenhua Zhang
                   ` (11 subsequent siblings)
  15 siblings, 1 reply; 23+ messages in thread
From: Zhenhua Zhang @ 2010-08-11  2:26 UTC (permalink / raw)
  To: ofono

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

Defines APIs to send final/intermediate/unsolicited result to DUN
client.
---
 include/emulator.h |    2 ++
 src/emulator.c     |   28 ++++++++++++++++++++++++++++
 src/ofono.h        |   11 +++++++++++
 3 files changed, 41 insertions(+), 0 deletions(-)

diff --git a/include/emulator.h b/include/emulator.h
index 29e87b9..2a45c65 100644
--- a/include/emulator.h
+++ b/include/emulator.h
@@ -36,6 +36,8 @@ enum ofono_emulator_status {
 	OFONO_EMULATOR_STATUS_DESTROY,
 };
 
+enum _GAtServerResult;
+
 struct ofono_emulator *ofono_emulator_create(struct ofono_modem *modem,
 						enum ofono_atom_type type,
 						GIOChannel *io);
diff --git a/src/emulator.c b/src/emulator.c
index f9e82a0..9ecc06c 100644
--- a/src/emulator.c
+++ b/src/emulator.c
@@ -71,6 +71,34 @@ static void ofono_emulator_release_id(int id)
 	ofono_emulator_ids &= ~(0x1 << id);
 }
 
+void ofono_emulator_send_final(struct ofono_emulator *e, GAtServerResult result)
+{
+	g_at_server_send_final(e->server, result);
+}
+
+void ofono_emulator_send_ext_final(struct ofono_emulator *e, const char *result)
+{
+	g_at_server_send_ext_final(e->server, result);
+}
+
+void ofono_emulator_send_intermediate(struct ofono_emulator *e,
+						const char *result)
+{
+	g_at_server_send_intermediate(e->server, result);
+}
+
+void ofono_emulator_send_unsolicited(struct ofono_emulator *e,
+						const char *result)
+{
+	g_at_server_send_unsolicited(e->server, result);
+}
+
+void ofono_emulator_send_info(struct ofono_emulator *e, const char *line,
+						gboolean last)
+{
+	g_at_server_send_info(e->server, line, last);
+}
+
 static void notify_status_watches(struct ofono_emulator *e, void *data)
 {
 	struct ofono_watchlist_item *item;
diff --git a/src/ofono.h b/src/ofono.h
index a7a9849..d5c600d 100644
--- a/src/ofono.h
+++ b/src/ofono.h
@@ -303,3 +303,14 @@ unsigned int __ofono_emulator_add_status_watch(struct ofono_emulator *e,
 
 gboolean __ofono_emulator_remove_status_watch(struct ofono_emulator *e,
 						unsigned int id);
+
+void ofono_emulator_send_final(struct ofono_emulator *e,
+					enum _GAtServerResult result);
+void ofono_emulator_send_ext_final(struct ofono_emulator *e,
+					const char *result);
+void ofono_emulator_send_intermediate(struct ofono_emulator *e,
+					const char *result);
+void ofono_emulator_send_unsolicited(struct ofono_emulator *e,
+					const char *result);
+void ofono_emulator_send_info(struct ofono_emulator *e, const char *line,
+					gboolean last);
-- 
1.7.0.4


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

* [PATCH 05/16] emulator: Implement dialing up for DUN
  2010-08-11  2:26 [PATCH 00/16] Implement DUN server for oFono Zhenhua Zhang
                   ` (3 preceding siblings ...)
  2010-08-11  2:26 ` [PATCH 04/16] emulator: Add APIs to send GAtServer result Zhenhua Zhang
@ 2010-08-11  2:26 ` Zhenhua Zhang
  2010-08-11  2:26 ` [PATCH 06/16] gprs: Make gprs_proto_to/from_string non-static Zhenhua Zhang
                   ` (10 subsequent siblings)
  15 siblings, 0 replies; 23+ messages in thread
From: Zhenhua Zhang @ 2010-08-11  2:26 UTC (permalink / raw)
  To: ofono

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

It handles client ATD*99# request and complete GPRS connection. Pass
client IP address through IPCP packet to client side.
---
 include/emulator.h |   30 +++++++
 src/emulator.c     |  222 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 252 insertions(+), 0 deletions(-)

diff --git a/include/emulator.h b/include/emulator.h
index 2a45c65..641f38c 100644
--- a/include/emulator.h
+++ b/include/emulator.h
@@ -34,10 +34,40 @@ enum ofono_emulator_status {
 	OFONO_EMULATOR_STATUS_IDLE = 0,
 	OFONO_EMULATOR_STATUS_CREATE,
 	OFONO_EMULATOR_STATUS_DESTROY,
+	OFONO_EMULATOR_STATUS_DUN_CONNECT,
+	OFONO_EMULATOR_STATUS_DUN_CONNECTED,
+	OFONO_EMULATOR_STATUS_DUN_DISCONNECTED,
 };
 
 enum _GAtServerResult;
 
+typedef void (*ofono_emulator_cb_t)(enum _GAtServerResult res, void *data);
+
+struct ofono_emulator_req {
+	void *data;
+	ofono_emulator_cb_t cb;
+	void *cb_data;
+};
+
+typedef void (*ofono_emulator_gprs_connect_cb)(const struct ofono_error *error,
+						const char *interface,
+						const char *local,
+						const char *peer,
+						const char **dns, void *data);
+
+struct ofono_emulator_gprs_connect_req {
+	const char *dial_str;
+	ofono_emulator_gprs_connect_cb cb;
+	void *cb_data;
+};
+
+struct ofono_emulator_gprs_context_req {
+	const char *proto;
+	const char *apn;
+	ofono_emulator_cb_t cb;
+	void *cb_data;
+};
+
 struct ofono_emulator *ofono_emulator_create(struct ofono_modem *modem,
 						enum ofono_atom_type type,
 						GIOChannel *io);
diff --git a/src/emulator.c b/src/emulator.c
index 9ecc06c..378426c 100644
--- a/src/emulator.c
+++ b/src/emulator.c
@@ -32,6 +32,22 @@
 #include "ofono.h"
 #include "common.h"
 #include "gatserver.h"
+#include "gatppp.h"
+
+struct context_settings {
+	char *interface;
+	gboolean static_ip;
+	char *ip;
+	char *netmask;
+	char *gateway;
+	char **dns;
+};
+
+struct dun_context {
+	ofono_bool_t active;
+	struct context_settings settings;
+	struct ofono_gprs_primary_context pri_ctx;
+};
 
 struct ofono_emulator {
 	struct ofono_modem *modem;
@@ -39,6 +55,8 @@ struct ofono_emulator {
 	enum ofono_atom_type type;
 	unsigned int id;
 	GAtServer *server;
+	GAtPPP *ppp;
+	struct dun_context context;
 	enum ofono_emulator_status status;
 	struct ofono_watchlist *status_watches;
 };
@@ -113,6 +131,201 @@ static void notify_status_watches(struct ofono_emulator *e, void *data)
 	}
 }
 
+static struct ofono_emulator_req *ofono_emulator_req_new(void *cb,
+							void *cb_data)
+{
+	struct ofono_emulator_req *req;
+
+	req = g_try_new0(struct ofono_emulator_req, 1);
+	if (!req)
+		return req;
+
+	req->cb = cb;
+	req->cb_data = cb_data;
+
+	return req;
+}
+
+static void ppp_connect(const char *interface, const char *local,
+			const char *remote,
+			const char *dns1, const char *dns2,
+			gpointer user_data)
+{
+	struct ofono_emulator *e = user_data;
+	struct dun_context *ctx = &e->context;
+	struct context_settings *settings = &ctx->settings;
+
+	e->status = OFONO_EMULATOR_STATUS_DUN_CONNECTED;
+	ctx->active = TRUE;
+
+	DBG("DUN server connected!\n");
+
+	DBG("Network Device: %s\n", settings->interface);
+	DBG("IP Address: %s\n", settings->ip);
+	DBG("Remote IP Address: %s\n", settings->gateway);
+	DBG("Primary DNS Server: %s\n", settings->dns[0]);
+	DBG("Secondary DNS Server: %s\n", settings->dns[1]);
+}
+
+static void ppp_disconnect(GAtPPPDisconnectReason reason, gpointer user_data)
+{
+	struct ofono_emulator *e = user_data;
+	struct dun_context *ctx = &e->context;
+	struct context_settings *settings = &ctx->settings;
+	struct ofono_emulator_req *req;
+
+	DBG("");
+
+	g_at_ppp_unref(e->ppp);
+	e->ppp = NULL;
+
+	g_at_server_resume(e->server);
+
+	ctx->active = FALSE;
+
+	g_free(settings->interface);
+	g_free(settings->ip);
+	g_free(settings->netmask);
+	g_free(settings->gateway);
+	g_strfreev(settings->dns);
+
+	req = ofono_emulator_req_new(NULL, NULL);
+	if (!req)
+		return;
+
+	e->status = OFONO_EMULATOR_STATUS_DUN_DISCONNECTED;
+	notify_status_watches(e, req);
+
+	g_free(req);
+}
+
+static gboolean setup_ppp(gpointer user_data)
+{
+	struct ofono_emulator *e = user_data;
+	GAtServer *server = e->server;
+	GAtIO *io;
+	struct context_settings *settings = &e->context.settings;
+
+	DBG("");
+
+	io = g_at_server_get_io(server);
+
+	/* suspend server port */
+	g_at_server_suspend(server);
+
+	/* open ppp */
+	e->ppp = g_at_ppp_server_new_from_io(io, settings->ip);
+	if (e->ppp == NULL) {
+		g_at_server_resume(server);
+		return FALSE;
+	}
+
+	g_at_ppp_set_server_info(e->ppp, settings->gateway,
+					settings->dns[0], settings->dns[1]);
+	g_at_ppp_set_credentials(e->ppp, "", "");
+	g_at_ppp_set_debug(e->ppp, ofono_emulator_debug, "PPP");
+
+	/* set connect and disconnect callbacks */
+	g_at_ppp_set_connect_function(e->ppp, ppp_connect, e);
+	g_at_ppp_set_disconnect_function(e->ppp, ppp_disconnect, e);
+
+	return FALSE;
+}
+
+static void gprs_connect_cb(const struct ofono_error *error,
+				const char *interface,
+				const char *local,
+				const char *peer,
+				const char **dns, void *data)
+{
+	struct ofono_emulator *e = data;
+	struct context_settings *settings = &e->context.settings;
+	const char *netmask = "255.255.255.255";
+
+	DBG("");
+
+	if (error->type != OFONO_ERROR_TYPE_NO_ERROR)
+		goto error;
+
+	if (!dns[0] || !dns[1])
+		goto error;
+
+	settings->interface = g_strdup(interface);
+	settings->static_ip = FALSE;
+	settings->ip = g_strdup(local);
+	settings->netmask = g_strdup(netmask);
+	settings->gateway = g_strdup(peer);
+	settings->dns = g_strdupv((char **)dns);
+
+	g_at_server_send_intermediate(e->server, "CONNECT");
+
+	g_idle_add(setup_ppp, e);
+
+	return;
+
+error:
+	g_at_server_send_final(e->server, G_AT_SERVER_RESULT_NO_CARRIER);
+}
+
+static gboolean dial_call(struct ofono_emulator *e, const char *dial_str)
+{
+	char c = *dial_str;
+
+	DBG("dial call %s", dial_str);
+
+	if (c == '*' || c == '#' || c == 'T' || c == 't') {
+		struct ofono_emulator_gprs_connect_req *req;
+
+		req = g_try_new0(struct ofono_emulator_gprs_connect_req, 1);
+		if (!req)
+			return FALSE;
+
+		req->cb = gprs_connect_cb;
+		req->cb_data = e;
+		req->dial_str = dial_str;
+
+		e->status = OFONO_EMULATOR_STATUS_DUN_CONNECT;
+		notify_status_watches(e, req);
+
+		g_free(req);
+	}
+
+	return TRUE;
+}
+
+static void dial_cb(GAtServerRequestType type, GAtResult *result,
+					gpointer user_data)
+{
+	struct ofono_emulator *e = user_data;
+	GAtServer *server = e->server;
+	GAtServerResult res = G_AT_SERVER_RESULT_ERROR;
+	GAtResultIter iter;
+	const char *dial_str;
+
+	if (type != G_AT_SERVER_REQUEST_TYPE_SET)
+		goto error;
+
+	g_at_result_iter_init(&iter, result);
+
+	if (!g_at_result_iter_next(&iter, "D"))
+		goto error;
+
+	dial_str = g_at_result_iter_raw_line(&iter);
+	if (!dial_str)
+		goto error;
+
+	if (e->context.active == TRUE)
+		goto error;
+
+	if (!dial_call(e, dial_str))
+		goto error;
+
+	return;
+
+error:
+	g_at_server_send_final(server, res);
+}
+
 static void emulator_remove(struct ofono_atom *atom)
 {
 	struct ofono_emulator *e =  __ofono_atom_get_data(atom);
@@ -173,6 +386,13 @@ static void emulator_disconnect(gpointer user_data)
 
 static void emulator_unregister(struct ofono_atom *atom)
 {
+	struct ofono_emulator *e =  __ofono_atom_get_data(atom);
+
+	if (e->ppp) {
+		g_at_ppp_shutdown(e->ppp);
+		g_at_ppp_unref(e->ppp);
+		e->ppp = NULL;
+	}
 }
 
 struct ofono_emulator *ofono_emulator_create(struct ofono_modem *modem,
@@ -205,5 +425,7 @@ struct ofono_emulator *ofono_emulator_create(struct ofono_modem *modem,
 
 	__ofono_atom_register(e->atom, emulator_unregister);
 
+	g_at_server_register(e->server, "D", dial_cb, e, NULL);
+
 	return e;
 }
-- 
1.7.0.4


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

* [PATCH 06/16] gprs: Make gprs_proto_to/from_string non-static
  2010-08-11  2:26 [PATCH 00/16] Implement DUN server for oFono Zhenhua Zhang
                   ` (4 preceding siblings ...)
  2010-08-11  2:26 ` [PATCH 05/16] emulator: Implement dialing up for DUN Zhenhua Zhang
@ 2010-08-11  2:26 ` Zhenhua Zhang
  2010-08-11  2:26 ` [PATCH 07/16] emulator: Register mandatory AT command handlers Zhenhua Zhang
                   ` (9 subsequent siblings)
  15 siblings, 0 replies; 23+ messages in thread
From: Zhenhua Zhang @ 2010-08-11  2:26 UTC (permalink / raw)
  To: ofono

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

So DUN server could share gprs_proto_to_string and
gprs_proto_from_string.
---
 include/gprs-context.h |    3 +++
 src/gprs.c             |    5 ++---
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/include/gprs-context.h b/include/gprs-context.h
index f4c7321..de170b8 100644
--- a/include/gprs-context.h
+++ b/include/gprs-context.h
@@ -84,6 +84,9 @@ void *ofono_gprs_context_get_data(struct ofono_gprs_context *gc);
 
 struct ofono_modem *ofono_gprs_context_get_modem(struct ofono_gprs_context *gc);
 
+gboolean gprs_proto_from_string(const char *str, enum ofono_gprs_proto *proto);
+const char *gprs_proto_to_string(enum ofono_gprs_proto proto);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/src/gprs.c b/src/gprs.c
index 8002cf4..677ce81 100644
--- a/src/gprs.c
+++ b/src/gprs.c
@@ -142,7 +142,7 @@ static enum gprs_context_type gprs_context_string_to_type(const char *str)
 	return GPRS_CONTEXT_TYPE_INVALID;
 }
 
-static const char *gprs_proto_to_string(enum ofono_gprs_proto proto)
+const char *gprs_proto_to_string(enum ofono_gprs_proto proto)
 {
 	switch (proto) {
 	case OFONO_GPRS_PROTO_IP:
@@ -154,8 +154,7 @@ static const char *gprs_proto_to_string(enum ofono_gprs_proto proto)
 	return NULL;
 }
 
-static gboolean gprs_proto_from_string(const char *str,
-					enum ofono_gprs_proto *proto)
+gboolean gprs_proto_from_string(const char *str, enum ofono_gprs_proto *proto)
 {
 	if (g_str_equal(str, "ip")) {
 		*proto = OFONO_GPRS_PROTO_IP;
-- 
1.7.0.4


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

* [PATCH 07/16] emulator: Register mandatory AT command handlers
  2010-08-11  2:26 [PATCH 00/16] Implement DUN server for oFono Zhenhua Zhang
                   ` (5 preceding siblings ...)
  2010-08-11  2:26 ` [PATCH 06/16] gprs: Make gprs_proto_to/from_string non-static Zhenhua Zhang
@ 2010-08-11  2:26 ` Zhenhua Zhang
  2010-08-11  2:26 ` [PATCH 08/16] gprs: Refactor to share remove_context method Zhenhua Zhang
                   ` (8 subsequent siblings)
  15 siblings, 0 replies; 23+ messages in thread
From: Zhenhua Zhang @ 2010-08-11  2:26 UTC (permalink / raw)
  To: ofono

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

Register mandatory AT command handlers for DUN server.
---
 include/emulator.h |    2 +
 src/emulator.c     |  381 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 383 insertions(+), 0 deletions(-)

diff --git a/include/emulator.h b/include/emulator.h
index 641f38c..1ff813f 100644
--- a/include/emulator.h
+++ b/include/emulator.h
@@ -37,6 +37,8 @@ enum ofono_emulator_status {
 	OFONO_EMULATOR_STATUS_DUN_CONNECT,
 	OFONO_EMULATOR_STATUS_DUN_CONNECTED,
 	OFONO_EMULATOR_STATUS_DUN_DISCONNECTED,
+	OFONO_EMULATOR_STATUS_SET_CGATT,
+	OFONO_EMULATOR_STATUS_SET_CGDCONT,
 };
 
 enum _GAtServerResult;
diff --git a/src/emulator.c b/src/emulator.c
index 378426c..8811f6c 100644
--- a/src/emulator.c
+++ b/src/emulator.c
@@ -49,6 +49,14 @@ struct dun_context {
 	struct ofono_gprs_primary_context pri_ctx;
 };
 
+struct modem_settings {
+	int mode;
+	int creg;
+	int cgreg;
+	int cops;
+	int attached;
+};
+
 struct ofono_emulator {
 	struct ofono_modem *modem;
 	struct ofono_atom *atom;
@@ -57,6 +65,7 @@ struct ofono_emulator {
 	GAtServer *server;
 	GAtPPP *ppp;
 	struct dun_context context;
+	struct modem_settings settings;
 	enum ofono_emulator_status status;
 	struct ofono_watchlist *status_watches;
 };
@@ -146,6 +155,371 @@ static struct ofono_emulator_req *ofono_emulator_req_new(void *cb,
 	return req;
 }
 
+static void generic_cb(GAtServerResult res, void *user_data)
+{
+	struct ofono_emulator *e = user_data;
+	GAtServer *server = e->server;
+
+	g_at_server_send_final(server, res);
+
+	e->status = OFONO_EMULATOR_STATUS_IDLE;
+
+	notify_status_watches(e, NULL);
+}
+
+static gboolean send_ok(gpointer user_data)
+{
+	struct ofono_emulator *e = user_data;
+
+	ofono_emulator_send_final(e, G_AT_SERVER_RESULT_OK);
+
+	return FALSE;
+}
+
+static void cfun_cb(GAtServerRequestType type, GAtResult *cmd,
+					gpointer user_data)
+{
+	struct ofono_emulator *e = user_data;
+	char buf[50];
+
+	switch (type) {
+	case G_AT_SERVER_REQUEST_TYPE_SUPPORT:
+		ofono_emulator_send_info(e, "+CFUN: (0-1)", TRUE);
+		ofono_emulator_send_final(e, G_AT_SERVER_RESULT_OK);
+		break;
+	case G_AT_SERVER_REQUEST_TYPE_QUERY:
+		snprintf(buf, sizeof(buf), "+CFUN: %d", e->settings.mode);
+		ofono_emulator_send_info(e, buf, TRUE);
+		ofono_emulator_send_final(e, G_AT_SERVER_RESULT_OK);
+		break;
+	case G_AT_SERVER_REQUEST_TYPE_SET:
+	{
+		GAtResultIter iter;
+		int mode;
+
+		g_at_result_iter_init(&iter, cmd);
+		g_at_result_iter_next(&iter, "+CFUN=");
+
+		if (g_at_result_iter_next_number(&iter, &mode) == FALSE)
+			goto error;
+
+		if (mode != 0 && mode != 1)
+			goto error;
+
+		DBG("set CFUN to %d", mode);
+
+		e->settings.mode = mode;
+		g_timeout_add_seconds(1, send_ok, e);
+		break;
+	}
+	default:
+		goto error;
+	};
+
+	return;
+
+error:
+	ofono_emulator_send_final(e, G_AT_SERVER_RESULT_ERROR);
+}
+
+static void cpin_cb(GAtServerRequestType type, GAtResult *result,
+					gpointer user_data)
+{
+	struct ofono_emulator *e = user_data;
+
+	switch (type) {
+	case G_AT_SERVER_REQUEST_TYPE_SUPPORT:
+		ofono_emulator_send_final(e, G_AT_SERVER_RESULT_OK);
+		break;
+	case G_AT_SERVER_REQUEST_TYPE_QUERY:
+		ofono_emulator_send_final(e, G_AT_SERVER_RESULT_OK);
+		break;
+	case G_AT_SERVER_REQUEST_TYPE_SET:
+		/* not implement yet*/
+	default:
+		goto error;
+	};
+
+	return;
+
+error:
+	ofono_emulator_send_final(e, G_AT_SERVER_RESULT_ERROR);
+}
+
+static void creg_cb(GAtServerRequestType type, GAtResult *result,
+					gpointer user_data)
+{
+	struct ofono_emulator *e = user_data;
+
+	switch (type) {
+	case G_AT_SERVER_REQUEST_TYPE_SUPPORT:
+		ofono_emulator_send_final(e, G_AT_SERVER_RESULT_OK);
+		break;
+	case G_AT_SERVER_REQUEST_TYPE_QUERY:
+		ofono_emulator_send_final(e, G_AT_SERVER_RESULT_OK);
+		break;
+	case G_AT_SERVER_REQUEST_TYPE_SET:
+	{
+		GAtResultIter iter;
+		int mode;
+
+		g_at_result_iter_init(&iter, result);
+		g_at_result_iter_next(&iter, "+CREG=");
+
+		if (g_at_result_iter_next_number(&iter, &mode) == FALSE)
+			goto error;
+
+		if (mode < 0 || mode > 2)
+			goto error;
+
+		DBG("set netreg status %d", mode);
+
+		e->settings.creg = mode;
+
+		ofono_emulator_send_final(e, G_AT_SERVER_RESULT_OK);
+
+		break;
+	}
+	default:
+		goto error;
+	};
+
+	return;
+
+error:
+	ofono_emulator_send_final(e, G_AT_SERVER_RESULT_ERROR);
+}
+
+static void cgreg_cb(GAtServerRequestType type, GAtResult *result,
+					gpointer user_data)
+{
+	struct ofono_emulator *e = user_data;
+
+	switch (type) {
+	case G_AT_SERVER_REQUEST_TYPE_SUPPORT:
+		ofono_emulator_send_final(e, G_AT_SERVER_RESULT_OK);
+		break;
+	case G_AT_SERVER_REQUEST_TYPE_QUERY:
+		ofono_emulator_send_final(e, G_AT_SERVER_RESULT_OK);
+		break;
+	case G_AT_SERVER_REQUEST_TYPE_SET:
+	{
+		GAtResultIter iter;
+		int mode;
+
+		g_at_result_iter_init(&iter, result);
+		g_at_result_iter_next(&iter, "+CGREG=");
+
+		if (g_at_result_iter_next_number(&iter, &mode) == FALSE)
+			goto error;
+
+		if (mode < 0 || mode > 2)
+			goto error;
+
+		DBG("set GPRS cgreg status %d", mode);
+
+		e->settings.cgreg = mode;
+
+		ofono_emulator_send_final(e, G_AT_SERVER_RESULT_OK);
+
+		break;
+	}
+	default:
+		goto error;
+	};
+
+	return;
+error:
+	ofono_emulator_send_final(e, G_AT_SERVER_RESULT_ERROR);
+}
+
+static void cops_cb(GAtServerRequestType type, GAtResult *result,
+					gpointer user_data)
+{
+	struct ofono_emulator *e = user_data;
+	char buf[50];
+
+	switch (type) {
+	case G_AT_SERVER_REQUEST_TYPE_SUPPORT:
+		ofono_emulator_send_final(e, G_AT_SERVER_RESULT_OK);
+		break;
+	case G_AT_SERVER_REQUEST_TYPE_QUERY:
+		snprintf(buf, sizeof(buf), "+COPS: %d", e->settings.cops);
+		ofono_emulator_send_info(e, buf, TRUE);
+		ofono_emulator_send_final(e, G_AT_SERVER_RESULT_OK);
+		break;
+	case G_AT_SERVER_REQUEST_TYPE_SET:
+	{
+		GAtResultIter iter;
+		int mode;
+
+		g_at_result_iter_init(&iter, result);
+		g_at_result_iter_next(&iter, "+COPS=");
+
+		if (g_at_result_iter_next_number(&iter, &mode) == FALSE)
+			goto error;
+
+		if (mode < 0 || mode > 2)
+			goto error;
+
+		DBG("set GPRS cops status %d", mode);
+
+		e->settings.cops = mode;
+		ofono_emulator_send_final(e, G_AT_SERVER_RESULT_OK);
+
+		break;
+	}
+	default:
+		goto error;
+	};
+
+	return;
+
+error:
+	ofono_emulator_send_final(e, G_AT_SERVER_RESULT_ERROR);
+}
+
+static void cgatt_cb(GAtServerRequestType type, GAtResult *result,
+					gpointer user_data)
+{
+	struct ofono_emulator *e = user_data;
+	struct ofono_emulator_req *req;
+	char buf[12];
+
+	switch (type) {
+	case G_AT_SERVER_REQUEST_TYPE_SUPPORT:
+		ofono_emulator_send_final(e, G_AT_SERVER_RESULT_OK);
+		break;
+	case G_AT_SERVER_REQUEST_TYPE_QUERY:
+		snprintf(buf, sizeof(buf), "+CGATT: %d", e->settings.attached);
+		ofono_emulator_send_info(e, buf, TRUE);
+		ofono_emulator_send_final(e, G_AT_SERVER_RESULT_OK);
+		break;
+	case G_AT_SERVER_REQUEST_TYPE_SET:
+	{
+		GAtResultIter iter;
+		int attached;
+
+		g_at_result_iter_init(&iter, result);
+		g_at_result_iter_next(&iter, "+CGATT=");
+
+		if (g_at_result_iter_next_number(&iter, &attached) == FALSE)
+			goto error;
+
+		if (attached != 0 && attached != 1)
+			goto error;
+
+		DBG("set GPRS attach status %d", attached);
+
+		req = ofono_emulator_req_new(generic_cb, e);
+		if (!req)
+			goto error;
+
+		req->data = &attached;
+
+		e->status = OFONO_EMULATOR_STATUS_SET_CGATT;
+
+		notify_status_watches(e, req);
+
+		e->settings.attached = attached;
+		g_free(req);
+		break;
+	}
+	default:
+		goto error;
+	};
+
+	return;
+
+error:
+	ofono_emulator_send_final(e, G_AT_SERVER_RESULT_ERROR);
+}
+
+static void cgdcont_cb(GAtServerRequestType type, GAtResult *result,
+					gpointer user_data)
+{
+	struct ofono_emulator *e = user_data;
+	struct ofono_emulator_gprs_context_req *req;
+	struct dun_context *context = &e->context;
+	struct ofono_gprs_primary_context *ctx = &context->pri_ctx;
+	char buf[256];
+
+	switch (type) {
+	case G_AT_SERVER_REQUEST_TYPE_SUPPORT:
+		ofono_emulator_send_final(e, G_AT_SERVER_RESULT_OK);
+		break;
+	case G_AT_SERVER_REQUEST_TYPE_QUERY:
+	{
+		const char *proto = gprs_proto_to_string(ctx->proto);
+
+		snprintf(buf, sizeof(buf), "+CGDCONT: %d, \"%s\", \"%s\"",
+						ctx->cid, proto, ctx->apn);
+		ofono_emulator_send_info(e, buf, TRUE);
+		ofono_emulator_send_final(e, G_AT_SERVER_RESULT_OK);
+		break;
+	}
+	case G_AT_SERVER_REQUEST_TYPE_SET:
+	{
+		GAtResultIter iter;
+		unsigned int cid;
+		const char *proto;
+		const char *apn;
+
+		g_at_result_iter_init(&iter, result);
+		g_at_result_iter_next(&iter, "+CGDCONT=");
+
+		if (g_at_result_iter_next_number(&iter, (gint *)&cid) == FALSE)
+			goto error;
+
+		if (g_at_result_iter_next_string(&iter, &proto) == FALSE)
+			goto error;
+
+		if (g_at_result_iter_next_string(&iter, &apn) == FALSE)
+			goto error;
+
+		DBG("set CGDCONT %d %s %s", cid, proto, apn);
+
+		if (cid <= 0 || proto == NULL || apn == NULL)
+			goto error;
+
+		if (cid == ctx->cid)
+			goto error;
+
+		if (context->active)
+			goto error;
+
+		ctx->cid = cid;
+		gprs_proto_from_string(proto, &ctx->proto);
+		strncpy(ctx->apn, apn, OFONO_GPRS_MAX_APN_LENGTH);
+		ctx->apn[OFONO_GPRS_MAX_APN_LENGTH] = '\0';
+
+		req = g_try_new0(struct ofono_emulator_gprs_context_req, 1);
+		if (!req)
+			goto error;
+
+		req->proto = proto;
+		req->apn = apn;
+		req->cb = generic_cb;
+		req->cb_data = e;
+
+		e->status = OFONO_EMULATOR_STATUS_SET_CGDCONT;
+
+		notify_status_watches(e, req);
+
+		g_free(req);
+		break;
+	}
+	default:
+		goto error;
+	};
+
+	return;
+
+error:
+	ofono_emulator_send_final(e, G_AT_SERVER_RESULT_ERROR);
+	g_free(req);
+}
+
 static void ppp_connect(const char *interface, const char *local,
 			const char *remote,
 			const char *dns1, const char *dns2,
@@ -426,6 +800,13 @@ struct ofono_emulator *ofono_emulator_create(struct ofono_modem *modem,
 	__ofono_atom_register(e->atom, emulator_unregister);
 
 	g_at_server_register(e->server, "D", dial_cb, e, NULL);
+	g_at_server_register(e->server, "+CFUN", cfun_cb, e, NULL);
+	g_at_server_register(e->server, "+CPIN", cpin_cb, e, NULL);
+	g_at_server_register(e->server, "+CREG", creg_cb, e, NULL);
+	g_at_server_register(e->server, "+CGREG", cgreg_cb, e, NULL);
+	g_at_server_register(e->server, "+COPS", cops_cb, e, NULL);
+	g_at_server_register(e->server, "+CGATT", cgatt_cb, e, NULL);
+	g_at_server_register(e->server, "+CGDCONT", cgdcont_cb, e, NULL);
 
 	return e;
 }
-- 
1.7.0.4


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

* [PATCH 08/16] gprs: Refactor to share remove_context method
  2010-08-11  2:26 [PATCH 00/16] Implement DUN server for oFono Zhenhua Zhang
                   ` (6 preceding siblings ...)
  2010-08-11  2:26 ` [PATCH 07/16] emulator: Register mandatory AT command handlers Zhenhua Zhang
@ 2010-08-11  2:26 ` Zhenhua Zhang
  2010-08-11  2:26 ` [PATCH 09/16] gprs: Add DUN +CGATT support in gprs atom Zhenhua Zhang
                   ` (7 subsequent siblings)
  15 siblings, 0 replies; 23+ messages in thread
From: Zhenhua Zhang @ 2010-08-11  2:26 UTC (permalink / raw)
  To: ofono

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

Remove duplicated code in gprs_deactivate_for_remove and
gprs_remove_context. So they could share the same remove_context method.
---
 src/gprs.c |   66 ++++++++++++++++++++++++++---------------------------------
 1 files changed, 29 insertions(+), 37 deletions(-)

diff --git a/src/gprs.c b/src/gprs.c
index 677ce81..f91d0dc 100644
--- a/src/gprs.c
+++ b/src/gprs.c
@@ -1248,24 +1248,12 @@ static DBusMessage *gprs_create_context(DBusConnection *conn,
 					DBUS_TYPE_INVALID);
 }
 
-static void gprs_deactivate_for_remove(const struct ofono_error *error,
-						void *data)
+static void remove_context(struct pri_context *ctx)
 {
-	struct pri_context *ctx = data;
 	struct ofono_gprs *gprs = ctx->gprs;
 	char **objpath_list;
 
-	if (error->type != OFONO_ERROR_TYPE_NO_ERROR) {
-		DBG("Removing context failed with error: %s",
-				telephony_error_to_str(error));
-
-		__ofono_dbus_pending_reply(&gprs->pending,
-					__ofono_error_failed(gprs->pending));
-		return;
-	}
-
-	gprs_cid_release(gprs, ctx->context.cid);
-	ctx->context.cid = 0;
+	DBG("%s", ctx->path);
 
 	if (gprs->settings) {
 		g_key_file_remove_group(gprs->settings, ctx->key, NULL);
@@ -1275,9 +1263,6 @@ static void gprs_deactivate_for_remove(const struct ofono_error *error,
 	context_dbus_unregister(ctx);
 	gprs->contexts = g_slist_remove(gprs->contexts, ctx);
 
-	__ofono_dbus_pending_reply(&gprs->pending,
-				dbus_message_new_method_return(gprs->pending));
-
 	objpath_list = gprs_contexts_path_list(gprs->contexts);
 
 	if (objpath_list) {
@@ -1292,13 +1277,38 @@ static void gprs_deactivate_for_remove(const struct ofono_error *error,
 	}
 }
 
+static void gprs_deactivate_for_remove(const struct ofono_error *error,
+						void *data)
+{
+	struct pri_context *ctx = data;
+	struct ofono_gprs *gprs = ctx->gprs;
+
+	if (error->type != OFONO_ERROR_TYPE_NO_ERROR) {
+		DBG("Removing context failed with error: %s",
+				telephony_error_to_str(error));
+
+		if (gprs->pending)
+			__ofono_dbus_pending_reply(&gprs->pending,
+					__ofono_error_failed(gprs->pending));
+		return;
+	}
+
+	gprs_cid_release(gprs, ctx->context.cid);
+	ctx->context.cid = 0;
+
+	remove_context(ctx);
+
+	if (gprs->pending)
+		__ofono_dbus_pending_reply(&gprs->pending,
+				dbus_message_new_method_return(gprs->pending));
+}
+
 static DBusMessage *gprs_remove_context(DBusConnection *conn,
 					DBusMessage *msg, void *data)
 {
 	struct ofono_gprs *gprs = data;
 	struct pri_context *ctx;
 	const char *path;
-	char **objpath_list;
 
 	if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
 					DBUS_TYPE_INVALID))
@@ -1320,28 +1330,10 @@ static DBusMessage *gprs_remove_context(DBusConnection *conn,
 		return NULL;
 	}
 
-	if (gprs->settings) {
-		g_key_file_remove_group(gprs->settings, ctx->key, NULL);
-		storage_sync(gprs->imsi, SETTINGS_STORE, gprs->settings);
-	}
-
-	DBG("Unregistering context: %s\n", ctx->path);
-	context_dbus_unregister(ctx);
-	gprs->contexts = g_slist_remove(gprs->contexts, ctx);
+	remove_context(ctx);
 
 	g_dbus_send_reply(conn, msg, DBUS_TYPE_INVALID);
 
-	objpath_list = gprs_contexts_path_list(gprs->contexts);
-
-	if (objpath_list) {
-		path = __ofono_atom_get_path(gprs->atom);
-		ofono_dbus_signal_array_property_changed(conn, path,
-					OFONO_DATA_CONNECTION_MANAGER_INTERFACE,
-					"PrimaryContexts",
-					DBUS_TYPE_OBJECT_PATH, &objpath_list);
-		g_strfreev(objpath_list);
-	}
-
 	return NULL;
 }
 
-- 
1.7.0.4


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

* [PATCH 09/16] gprs: Add DUN +CGATT support in gprs atom
  2010-08-11  2:26 [PATCH 00/16] Implement DUN server for oFono Zhenhua Zhang
                   ` (7 preceding siblings ...)
  2010-08-11  2:26 ` [PATCH 08/16] gprs: Refactor to share remove_context method Zhenhua Zhang
@ 2010-08-11  2:26 ` Zhenhua Zhang
  2010-08-11  2:26 ` [PATCH 10/16] gprs: Add ofono_gprs_create_context method Zhenhua Zhang
                   ` (6 subsequent siblings)
  15 siblings, 0 replies; 23+ messages in thread
From: Zhenhua Zhang @ 2010-08-11  2:26 UTC (permalink / raw)
  To: ofono

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

DUN client may request to attach/deattach GPRS network. Use
gprs_netreg_update to set attach/deattach status.
---
 src/gprs.c |   18 ++++++++++++++++++
 1 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/src/gprs.c b/src/gprs.c
index f91d0dc..5d850df 100644
--- a/src/gprs.c
+++ b/src/gprs.c
@@ -39,6 +39,7 @@
 #include "common.h"
 #include "storage.h"
 #include "idmap.h"
+#include "gatserver.h"
 
 #define GPRS_FLAG_ATTACHING 0x1
 #define GPRS_FLAG_RECHECK 0x2
@@ -1453,14 +1454,31 @@ void ofono_gprs_context_deactivated(struct ofono_gprs_context *gc,
 	}
 }
 
+static void ofono_gprs_set_cgatt(struct ofono_gprs *gprs,
+				struct ofono_emulator_req *req)
+{
+	int *mode = req->data;
+
+	gprs->powered = *mode;
+
+	gprs_netreg_update(gprs);
+
+	req->cb(G_AT_SERVER_RESULT_OK, req->cb_data);
+}
+
 static void dun_status_watch(struct ofono_emulator *e,
 					enum ofono_emulator_status status,
 					void *data, void *user_data)
 {
+	struct ofono_gprs *gprs = user_data;
+
 	if (e == NULL)
 		return;
 
 	switch (status) {
+	case OFONO_EMULATOR_STATUS_SET_CGATT:
+		ofono_gprs_set_cgatt(gprs, data);
+		break;
 	default:
 		break;
 	}
-- 
1.7.0.4


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

* [PATCH 10/16] gprs: Add ofono_gprs_create_context method
  2010-08-11  2:26 [PATCH 00/16] Implement DUN server for oFono Zhenhua Zhang
                   ` (8 preceding siblings ...)
  2010-08-11  2:26 ` [PATCH 09/16] gprs: Add DUN +CGATT support in gprs atom Zhenhua Zhang
@ 2010-08-11  2:26 ` Zhenhua Zhang
  2010-08-12 11:57   ` Marcel Holtmann
  2010-08-11  2:26 ` [PATCH 11/16] gprs: Add DUN +CGDCONT support in gprs atom Zhenhua Zhang
                   ` (5 subsequent siblings)
  15 siblings, 1 reply; 23+ messages in thread
From: Zhenhua Zhang @ 2010-08-11  2:26 UTC (permalink / raw)
  To: ofono

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

DUN server may create one primary context if none of contexts existing
on the GPRS atom.
---
 src/gprs.c |   76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 76 insertions(+), 0 deletions(-)

diff --git a/src/gprs.c b/src/gprs.c
index 5d850df..7e85d39 100644
--- a/src/gprs.c
+++ b/src/gprs.c
@@ -1162,6 +1162,82 @@ static DBusMessage *gprs_set_property(DBusConnection *conn,
 	return dbus_message_new_method_return(msg);
 }
 
+static struct pri_context *ofono_gprs_create_context(
+					struct ofono_gprs *gprs,
+					const char *name, const char *typestr)
+{
+	DBusConnection *conn = ofono_dbus_get_connection();
+	struct pri_context *context;
+	const char *path;
+	enum gprs_context_type type;
+	char **objpath_list;
+	unsigned int id;
+
+	if (strlen(name) == 0 || strlen(name) > MAX_CONTEXT_NAME_LENGTH)
+		return NULL;
+
+	type = gprs_context_string_to_type(typestr);
+
+	if (type == GPRS_CONTEXT_TYPE_INVALID)
+		return NULL;
+
+	if (gprs->last_context_id)
+		id = idmap_alloc_next(gprs->pid_map, gprs->last_context_id);
+	else
+		id = idmap_alloc(gprs->pid_map);
+
+	if (id > idmap_get_max(gprs->pid_map))
+		return NULL;
+
+	context = pri_context_create(gprs, name, type);
+	context->id = id;
+
+	if (!context) {
+		ofono_error("Unable to allocate context struct");
+		return NULL;
+	}
+
+	DBG("Registering new context");
+
+	if (!context_dbus_register(context)) {
+		ofono_error("Unable to register primary context");
+		return NULL;
+	}
+
+	gprs->last_context_id = id;
+
+	if (gprs->settings) {
+		g_key_file_set_string(gprs->settings, context->key,
+					"Name", context->name);
+		g_key_file_set_string(gprs->settings, context->key,
+					"AccessPointName",
+					context->context.apn);
+		g_key_file_set_string(gprs->settings, context->key,
+					"Username", context->context.username);
+		g_key_file_set_string(gprs->settings, context->key,
+					"Password", context->context.password);
+		g_key_file_set_string(gprs->settings, context->key, "Type",
+				gprs_context_type_to_string(context->type));
+		storage_sync(gprs->imsi, SETTINGS_STORE, gprs->settings);
+	}
+
+	gprs->contexts = g_slist_append(gprs->contexts, context);
+
+	objpath_list = gprs_contexts_path_list(gprs->contexts);
+
+	if (objpath_list) {
+		path = __ofono_atom_get_path(gprs->atom);
+		ofono_dbus_signal_array_property_changed(conn, path,
+					OFONO_DATA_CONNECTION_MANAGER_INTERFACE,
+					"PrimaryContexts",
+					DBUS_TYPE_OBJECT_PATH, &objpath_list);
+
+		g_strfreev(objpath_list);
+	}
+
+	return context;
+}
+
 static DBusMessage *gprs_create_context(DBusConnection *conn,
 					DBusMessage *msg, void *data)
 {
-- 
1.7.0.4


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

* [PATCH 11/16] gprs: Add DUN +CGDCONT support in gprs atom
  2010-08-11  2:26 [PATCH 00/16] Implement DUN server for oFono Zhenhua Zhang
                   ` (9 preceding siblings ...)
  2010-08-11  2:26 ` [PATCH 10/16] gprs: Add ofono_gprs_create_context method Zhenhua Zhang
@ 2010-08-11  2:26 ` Zhenhua Zhang
  2010-08-11  2:26 ` [PATCH 12/16] gprs: Add DUN server GPRS connect support Zhenhua Zhang
                   ` (4 subsequent siblings)
  15 siblings, 0 replies; 23+ messages in thread
From: Zhenhua Zhang @ 2010-08-11  2:26 UTC (permalink / raw)
  To: ofono

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

DUN client may request to create a new context. Call
ofono_gprs_create_context to create it.
---
 src/gprs.c |   53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 53 insertions(+), 0 deletions(-)

diff --git a/src/gprs.c b/src/gprs.c
index 7e85d39..2313f52 100644
--- a/src/gprs.c
+++ b/src/gprs.c
@@ -59,6 +59,13 @@ enum gprs_context_type {
 	GPRS_CONTEXT_TYPE_INVALID,
 };
 
+struct gprs_dun_data {
+	ofono_emulator_gprs_connect_cb cb;
+	void *cb_data;
+	struct pri_context *context;
+	struct pri_context *dun;
+};
+
 struct ofono_gprs {
 	GSList *contexts;
 	ofono_bool_t attached;
@@ -84,6 +91,7 @@ struct ofono_gprs {
 	struct ofono_emulator *dun;
 	unsigned int dun_watch;
 	unsigned int dun_status_watch;
+	struct gprs_dun_data dun_data;
 };
 
 struct ofono_gprs_context {
@@ -1542,6 +1550,48 @@ static void ofono_gprs_set_cgatt(struct ofono_gprs *gprs,
 	req->cb(G_AT_SERVER_RESULT_OK, req->cb_data);
 }
 
+static void ofono_gprs_set_cgdcont(struct ofono_gprs *gprs,
+				struct ofono_emulator_gprs_context_req *req)
+{
+	struct gprs_dun_data *data = &gprs->dun_data;
+	struct pri_context *context = NULL;
+	enum ofono_gprs_proto proto;
+	GSList *l;
+
+	gprs_proto_from_string(req->proto, &proto);
+
+	for (l = gprs->contexts; l; l = l->next) {
+		struct pri_context *ctx = l->data;
+
+		if (ctx->type != GPRS_CONTEXT_TYPE_INTERNET)
+			continue;
+
+		if (!g_str_equal(req->apn, ctx->context.apn))
+			continue;
+
+		if (proto != ctx->context.proto)
+			continue;
+
+		context = ctx;
+		break;
+	}
+
+	if (context)
+		goto done;
+
+	context = ofono_gprs_create_context(gprs, req->apn, "internet");
+	if (context == NULL) {
+		req->cb(G_AT_SERVER_RESULT_ERROR, req->cb_data);
+		return;
+	}
+
+	strcpy(context->context.apn, req->apn);
+
+done:
+	data->context = context;
+	req->cb(G_AT_SERVER_RESULT_OK, req->cb_data);
+}
+
 static void dun_status_watch(struct ofono_emulator *e,
 					enum ofono_emulator_status status,
 					void *data, void *user_data)
@@ -1555,6 +1605,9 @@ static void dun_status_watch(struct ofono_emulator *e,
 	case OFONO_EMULATOR_STATUS_SET_CGATT:
 		ofono_gprs_set_cgatt(gprs, data);
 		break;
+	case OFONO_EMULATOR_STATUS_SET_CGDCONT:
+		ofono_gprs_set_cgdcont(gprs, data);
+		break;
 	default:
 		break;
 	}
-- 
1.7.0.4


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

* [PATCH 12/16] gprs: Add DUN server GPRS connect support
  2010-08-11  2:26 [PATCH 00/16] Implement DUN server for oFono Zhenhua Zhang
                   ` (10 preceding siblings ...)
  2010-08-11  2:26 ` [PATCH 11/16] gprs: Add DUN +CGDCONT support in gprs atom Zhenhua Zhang
@ 2010-08-11  2:26 ` Zhenhua Zhang
  2010-08-11  2:26 ` [PATCH 13/16] gprs: Add status watch functions Zhenhua Zhang
                   ` (3 subsequent siblings)
  15 siblings, 0 replies; 23+ messages in thread
From: Zhenhua Zhang @ 2010-08-11  2:26 UTC (permalink / raw)
  To: ofono

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

Implement dial up networking in GPRS atom.
---
 src/gprs.c |  232 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 229 insertions(+), 3 deletions(-)

diff --git a/src/gprs.c b/src/gprs.c
index 2313f52..95f7ab2 100644
--- a/src/gprs.c
+++ b/src/gprs.c
@@ -49,6 +49,10 @@
 #define MAX_CONTEXT_NAME_LENGTH 127
 #define MAX_CONTEXTS 256
 
+#define DUN_LOCAL "192.168.1.1"
+#define DUN_PEER "192.168.1.2"
+#define DUN_CONNECT_TIMEOUT 20
+
 static GSList *g_drivers = NULL;
 static GSList *g_context_drivers = NULL;
 
@@ -92,6 +96,9 @@ struct ofono_gprs {
 	unsigned int dun_watch;
 	unsigned int dun_status_watch;
 	struct gprs_dun_data dun_data;
+	int attach_source;
+	int context_source;
+	int timeout_source;
 };
 
 struct ofono_gprs_context {
@@ -124,6 +131,7 @@ struct pri_context {
 };
 
 static void gprs_netreg_update(struct ofono_gprs *gprs);
+static gboolean dun_connect_remove(gpointer user_data);
 
 static const char *gprs_context_type_to_string(int type)
 {
@@ -453,17 +461,24 @@ static void pri_activate_callback(const struct ofono_error *error,
 	if (error->type != OFONO_ERROR_TYPE_NO_ERROR) {
 		DBG("Activating context failed with error: %s",
 				telephony_error_to_str(error));
-		__ofono_dbus_pending_reply(&gc->pending,
+
+		if (gc->pending)
+			__ofono_dbus_pending_reply(&gc->pending,
 					__ofono_error_failed(gc->pending));
 
 		gprs_cid_release(ctx->gprs, ctx->context.cid);
 		ctx->context.cid = 0;
 
+		if (ctx->gprs->dun)
+			dun_connect_remove(ctx->gprs);
+
 		return;
 	}
 
 	ctx->active = TRUE;
-	__ofono_dbus_pending_reply(&gc->pending,
+
+	if (gc->pending)
+		__ofono_dbus_pending_reply(&gc->pending,
 				dbus_message_new_method_return(gc->pending));
 
 	/* If we don't have the interface, don't bother emitting any settings,
@@ -1488,12 +1503,35 @@ void ofono_gprs_set_cid_range(struct ofono_gprs *gprs,
 	gprs->cid_map = idmap_new_from_range(min, max);
 }
 
+static void ofono_gprs_remove_sources(struct ofono_gprs *gprs)
+{
+	if (gprs == NULL)
+		return;
+
+	if (gprs->timeout_source) {
+		g_source_remove(gprs->timeout_source);
+		gprs->timeout_source = 0;
+	}
+
+	if (gprs->attach_source) {
+		g_source_remove(gprs->attach_source);
+		gprs->attach_source = 0;
+	}
+
+	if (gprs->context_source) {
+		g_source_remove(gprs->context_source);
+		gprs->context_source = 0;
+	}
+}
+
 static void gprs_context_unregister(struct ofono_atom *atom)
 {
 	struct ofono_gprs_context *gc = __ofono_atom_get_data(atom);
 
-	if (gc->gprs)
+	if (gc->gprs) {
 		gc->gprs->context_driver = NULL;
+		ofono_gprs_remove_sources(gc->gprs);
+	}
 
 	gc->gprs = NULL;
 }
@@ -1538,6 +1576,183 @@ void ofono_gprs_context_deactivated(struct ofono_gprs_context *gc,
 	}
 }
 
+static ofono_bool_t set_primary_context_powered(struct pri_context *ctx,
+						ofono_bool_t value)
+{
+	struct ofono_gprs_context *gc = ctx->gprs->context_driver;
+
+	if (gc == NULL || gc->driver->activate_primary == NULL ||
+			gc->driver->deactivate_primary == NULL ||
+			ctx->gprs->cid_map == NULL)
+		return FALSE;
+
+	if (gc->pending)
+		return FALSE;
+
+	if (ctx->active == value)
+		return FALSE;
+
+	if (value && !ctx->gprs->attached)
+		return FALSE;
+
+	if (ctx->gprs->flags & GPRS_FLAG_ATTACHING)
+		return FALSE;
+
+	if (value) {
+		ctx->context.cid = gprs_cid_alloc(ctx->gprs);
+
+		if (ctx->context.cid == 0)
+			return FALSE;
+
+		if (ctx->context.cid !=
+				idmap_get_min(ctx->gprs->cid_map)) {
+			ofono_error("Multiple active contexts are"
+					" not yet supported");
+
+			gprs_cid_release(ctx->gprs, ctx->context.cid);
+			ctx->context.cid = 0;
+
+			return FALSE;
+		}
+	}
+
+	if (value)
+		gc->driver->activate_primary(gc, &ctx->context,
+					pri_activate_callback, ctx);
+	else
+		gc->driver->deactivate_primary(gc, ctx->context.cid,
+					pri_deactivate_callback, ctx);
+
+	return TRUE;
+}
+
+static void ofono_gprs_dun_disconnect(struct ofono_gprs *gprs,
+				struct ofono_emulator_req *req)
+{
+	struct pri_context *context = gprs->dun_data.context;
+
+	ofono_gprs_remove_sources(gprs);
+
+	if (context->active) {
+		struct ofono_gprs_context *gc = gprs->context_driver;
+
+		gc->driver->deactivate_primary(gc, context->context.cid,
+					gprs_deactivate_for_remove, context);
+	} else
+		remove_context(context);
+}
+
+static gboolean dun_connect_remove(gpointer user_data)
+{
+	struct ofono_gprs *gprs = user_data;
+	struct gprs_dun_data *data = &gprs->dun_data;
+	struct ofono_error error;
+
+	ofono_gprs_remove_sources(gprs);
+	remove_context(data->context);
+
+	error.type = OFONO_ERROR_TYPE_FAILURE;
+	data->cb(&error, NULL, NULL, NULL, NULL, data->cb_data);
+
+	data->cb = NULL;
+	data->cb_data = NULL;
+	data->context = NULL;
+	data->dun = NULL;
+
+	return FALSE;
+}
+
+static gboolean pri_context_update(gpointer user_data)
+{
+	struct ofono_gprs *gprs = user_data;
+	struct gprs_dun_data *data = &gprs->dun_data;
+	struct pri_context *context = data->context;
+	struct context_settings *settings = context->settings;
+	struct ofono_error error;
+
+	DBG("active %d\n", context->active);
+
+	if (context->active != TRUE)
+		return TRUE;
+
+	gprs->context_source = 0;
+	g_source_remove(gprs->timeout_source);
+
+	error.type = OFONO_ERROR_TYPE_NO_ERROR;
+
+	data->cb(&error, settings->interface, DUN_LOCAL, DUN_PEER,
+					(const char **)settings->dns,
+					data->cb_data);
+
+	return FALSE;
+}
+
+static gboolean gprs_attach_update(gpointer user_data)
+{
+	struct ofono_gprs *gprs = user_data;
+	struct gprs_dun_data *data = &gprs->dun_data;
+	struct pri_context *context = data->context;
+
+	DBG("attached %d driver attached %d\n", gprs->attached,
+						gprs->driver_attached);
+
+	if (gprs->attached != TRUE || gprs->driver_attached != TRUE)
+		return TRUE;
+
+	gprs->attach_source = 0;
+
+	if (context->active != TRUE) {
+		set_primary_context_powered(context, TRUE);
+
+		/* wait until the primary context is actived */
+		gprs->context_source = g_timeout_add_seconds(1,
+						pri_context_update, gprs);
+		return FALSE;
+	}
+
+	pri_context_update(gprs);
+
+	return FALSE;
+}
+
+static void ofono_gprs_dun_connect(struct ofono_gprs *gprs,
+				struct ofono_emulator_gprs_connect_req *req)
+{
+	const char *dial_str = req->dial_str;
+	struct gprs_dun_data *data = &gprs->dun_data;
+	struct ofono_error error;
+
+	DBG("%s", dial_str);
+
+	if (data->context == NULL)
+		goto error;
+
+	data->cb = req->cb;
+	data->cb_data = req->cb_data;
+
+	gprs->timeout_source = g_timeout_add_seconds(DUN_CONNECT_TIMEOUT,
+						dun_connect_remove, gprs);
+
+	/* check gprs attaching status */
+	if (!gprs->powered || !gprs->attached || !gprs->driver_attached) {
+		gprs->powered = TRUE;
+
+		gprs_netreg_update(gprs);
+
+		/* wait until GPRS is attached */
+		gprs->attach_source = g_timeout_add_seconds(1,
+						gprs_attach_update, gprs);
+		return;
+	}
+
+	gprs_attach_update(gprs);
+
+	return;
+error:
+	error.type = OFONO_ERROR_TYPE_FAILURE;
+	req->cb(&error, NULL, NULL, NULL, NULL, req->cb_data);
+}
+
 static void ofono_gprs_set_cgatt(struct ofono_gprs *gprs,
 				struct ofono_emulator_req *req)
 {
@@ -1602,12 +1817,21 @@ static void dun_status_watch(struct ofono_emulator *e,
 		return;
 
 	switch (status) {
+	case OFONO_EMULATOR_STATUS_DUN_CONNECT:
+		ofono_gprs_dun_connect(gprs, data);
+		break;
+	case OFONO_EMULATOR_STATUS_DUN_DISCONNECTED:
+		ofono_gprs_dun_disconnect(gprs, data);
+		break;
 	case OFONO_EMULATOR_STATUS_SET_CGATT:
 		ofono_gprs_set_cgatt(gprs, data);
 		break;
 	case OFONO_EMULATOR_STATUS_SET_CGDCONT:
 		ofono_gprs_set_cgdcont(gprs, data);
 		break;
+	case OFONO_EMULATOR_STATUS_DESTROY:
+		ofono_gprs_remove_sources(gprs);
+		break;
 	default:
 		break;
 	}
@@ -1794,6 +2018,8 @@ static void gprs_unregister(struct ofono_atom *atom)
 		gprs->dun = NULL;
 	}
 
+	ofono_gprs_remove_sources(gprs);
+
 	ofono_modem_remove_interface(modem,
 					OFONO_DATA_CONNECTION_MANAGER_INTERFACE);
 	g_dbus_unregister_interface(conn, path,
-- 
1.7.0.4


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

* [PATCH 13/16] gprs: Add status watch functions
  2010-08-11  2:26 [PATCH 00/16] Implement DUN server for oFono Zhenhua Zhang
                   ` (11 preceding siblings ...)
  2010-08-11  2:26 ` [PATCH 12/16] gprs: Add DUN server GPRS connect support Zhenhua Zhang
@ 2010-08-11  2:26 ` Zhenhua Zhang
  2010-08-11  2:26 ` [PATCH 14/16] gprs: Add gprs_get_status Zhenhua Zhang
                   ` (2 subsequent siblings)
  15 siblings, 0 replies; 23+ messages in thread
From: Zhenhua Zhang @ 2010-08-11  2:26 UTC (permalink / raw)
  To: ofono

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

So DUN server could watch GPRS status changes and notify client
unsolicited results like +CGREG.
---
 include/gprs.h |    9 +++++++++
 src/gprs.c     |   55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 64 insertions(+), 0 deletions(-)

diff --git a/include/gprs.h b/include/gprs.h
index a1cbcd9..c0a0e2f 100644
--- a/include/gprs.h
+++ b/include/gprs.h
@@ -36,6 +36,8 @@ typedef void (*ofono_gprs_status_cb_t)(const struct ofono_error *error,
 
 typedef void (*ofono_gprs_cb_t)(const struct ofono_error *error, void *data);
 
+typedef void (*ofono_gprs_status_notify_cb_t)(const int status, void *data);
+
 struct ofono_gprs_driver {
 	const char *name;
 	int (*probe)(struct ofono_gprs *gprs, unsigned int vendor,
@@ -67,6 +69,13 @@ void ofono_gprs_set_cid_range(struct ofono_gprs *gprs,
 void ofono_gprs_add_context(struct ofono_gprs *gprs,
 				struct ofono_gprs_context *gc);
 
+unsigned int __ofono_gprs_add_status_watch(struct ofono_gprs *gprs,
+				ofono_gprs_status_notify_cb_t cb,
+				void *data, ofono_destroy_func destroy);
+
+gboolean __ofono_gprs_remove_status_watch(struct ofono_gprs *gprs,
+						unsigned int id);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/src/gprs.c b/src/gprs.c
index 95f7ab2..b91a099 100644
--- a/src/gprs.c
+++ b/src/gprs.c
@@ -92,6 +92,7 @@ struct ofono_gprs {
 	const struct ofono_gprs_driver *driver;
 	void *driver_data;
 	struct ofono_atom *atom;
+	struct ofono_watchlist *status_watches;
 	struct ofono_emulator *dun;
 	unsigned int dun_watch;
 	unsigned int dun_status_watch;
@@ -1467,6 +1468,51 @@ static GDBusSignalTable manager_signals[] = {
 	{ }
 };
 
+unsigned int __ofono_gprs_add_status_watch(struct ofono_gprs *gprs,
+				ofono_gprs_status_notify_cb_t notify,
+				void *data, ofono_destroy_func destroy)
+{
+	struct ofono_watchlist_item *item;
+
+	DBG("%p", gprs);
+
+	if (gprs == NULL)
+		return 0;
+
+	if (notify == NULL)
+		return 0;
+
+	item = g_new0(struct ofono_watchlist_item, 1);
+
+	item->notify = notify;
+	item->destroy = destroy;
+	item->notify_data = data;
+
+	return __ofono_watchlist_add_item(gprs->status_watches, item);
+}
+
+gboolean __ofono_gprs_remove_status_watch(struct ofono_gprs *gprs,
+						unsigned int id)
+{
+	DBG("%p", gprs);
+
+	return __ofono_watchlist_remove_item(gprs->status_watches, id);
+}
+
+static void notify_status_watches(struct ofono_gprs *gprs)
+{
+	struct ofono_watchlist_item *item;
+	GSList *l;
+	ofono_gprs_status_notify_cb_t notify;
+
+	for (l = gprs->status_watches->items; l; l = l->next) {
+		item = l->data;
+		notify = item->notify;
+
+		notify(gprs->status, item->notify_data);
+	}
+}
+
 void ofono_gprs_detached_notify(struct ofono_gprs *gprs)
 {
 	if (gprs->driver_attached == FALSE)
@@ -1476,6 +1522,8 @@ void ofono_gprs_detached_notify(struct ofono_gprs *gprs)
 
 	gprs_attached_update(gprs);
 
+	notify_status_watches(gprs);
+
 	/* TODO: The network forced a detach, we should wait for some time
 	 * and try to re-attach
 	 */
@@ -1489,6 +1537,8 @@ void ofono_gprs_status_notify(struct ofono_gprs *gprs, int status)
 
 	gprs->status = status;
 	gprs_attached_update(gprs);
+
+	notify_status_watches(gprs);
 }
 
 void ofono_gprs_set_cid_range(struct ofono_gprs *gprs,
@@ -1972,6 +2022,9 @@ static void gprs_unregister(struct ofono_atom *atom)
 	const char *path = __ofono_atom_get_path(atom);
 	GSList *l;
 
+	__ofono_watchlist_free(gprs->status_watches);
+	gprs->status_watches = NULL;
+
 	if (gprs->settings) {
 		storage_close(gprs->imsi, SETTINGS_STORE,
 				gprs->settings, TRUE);
@@ -2289,6 +2342,8 @@ void ofono_gprs_register(struct ofono_gprs *gprs)
 	ofono_modem_add_interface(modem,
 				OFONO_DATA_CONNECTION_MANAGER_INTERFACE);
 
+	gprs->status_watches = __ofono_watchlist_new(g_free);
+
 	sim_atom = __ofono_modem_find_atom(modem, OFONO_ATOM_TYPE_SIM);
 
 	if (sim_atom) {
-- 
1.7.0.4


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

* [PATCH 14/16] gprs: Add gprs_get_status
  2010-08-11  2:26 [PATCH 00/16] Implement DUN server for oFono Zhenhua Zhang
                   ` (12 preceding siblings ...)
  2010-08-11  2:26 ` [PATCH 13/16] gprs: Add status watch functions Zhenhua Zhang
@ 2010-08-11  2:26 ` Zhenhua Zhang
  2010-08-11  2:26 ` [PATCH 15/16] emulator: Watch GPRS status changes Zhenhua Zhang
  2010-08-11  2:26 ` [PATCH 16/16] emulator: Watch netreg " Zhenhua Zhang
  15 siblings, 0 replies; 23+ messages in thread
From: Zhenhua Zhang @ 2010-08-11  2:26 UTC (permalink / raw)
  To: ofono

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

So that DUN server could get latest GPRS status.
---
 include/gprs.h |    2 ++
 src/gprs.c     |    8 ++++++++
 2 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/include/gprs.h b/include/gprs.h
index c0a0e2f..ca23c45 100644
--- a/include/gprs.h
+++ b/include/gprs.h
@@ -76,6 +76,8 @@ unsigned int __ofono_gprs_add_status_watch(struct ofono_gprs *gprs,
 gboolean __ofono_gprs_remove_status_watch(struct ofono_gprs *gprs,
 						unsigned int id);
 
+int ofono_gprs_get_status(struct ofono_gprs *gprs);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/src/gprs.c b/src/gprs.c
index b91a099..b3fad91 100644
--- a/src/gprs.c
+++ b/src/gprs.c
@@ -1995,6 +1995,14 @@ struct ofono_modem *ofono_gprs_context_get_modem(struct ofono_gprs_context *gc)
 	return __ofono_atom_get_modem(gc->atom);
 }
 
+int ofono_gprs_get_status(struct ofono_gprs *gprs)
+{
+	if (gprs == NULL)
+		return -1;
+
+	return gprs->status;
+}
+
 int ofono_gprs_driver_register(const struct ofono_gprs_driver *d)
 {
 	DBG("driver: %p, name: %s", d, d->name);
-- 
1.7.0.4


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

* [PATCH 15/16] emulator: Watch GPRS status changes
  2010-08-11  2:26 [PATCH 00/16] Implement DUN server for oFono Zhenhua Zhang
                   ` (13 preceding siblings ...)
  2010-08-11  2:26 ` [PATCH 14/16] gprs: Add gprs_get_status Zhenhua Zhang
@ 2010-08-11  2:26 ` Zhenhua Zhang
  2010-08-11  2:26 ` [PATCH 16/16] emulator: Watch netreg " Zhenhua Zhang
  15 siblings, 0 replies; 23+ messages in thread
From: Zhenhua Zhang @ 2010-08-11  2:26 UTC (permalink / raw)
  To: ofono

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

Watch GPRS status update to notify DUN client, such as +CGREG
unsolicited result.
---
 src/emulator.c |   94 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 94 insertions(+), 0 deletions(-)

diff --git a/src/emulator.c b/src/emulator.c
index 8811f6c..c8f3d65 100644
--- a/src/emulator.c
+++ b/src/emulator.c
@@ -55,6 +55,7 @@ struct modem_settings {
 	int cgreg;
 	int cops;
 	int attached;
+	int gprs_status;
 };
 
 struct ofono_emulator {
@@ -68,6 +69,9 @@ struct ofono_emulator {
 	struct modem_settings settings;
 	enum ofono_emulator_status status;
 	struct ofono_watchlist *status_watches;
+	struct ofono_gprs *gprs;
+	unsigned int gprs_watch;
+	unsigned int gprs_status_watch;
 };
 
 static unsigned int ofono_emulator_ids;
@@ -294,12 +298,16 @@ static void cgreg_cb(GAtServerRequestType type, GAtResult *result,
 					gpointer user_data)
 {
 	struct ofono_emulator *e = user_data;
+	char buf[256];
 
 	switch (type) {
 	case G_AT_SERVER_REQUEST_TYPE_SUPPORT:
 		ofono_emulator_send_final(e, G_AT_SERVER_RESULT_OK);
 		break;
 	case G_AT_SERVER_REQUEST_TYPE_QUERY:
+		snprintf(buf, sizeof(buf), "+CGREG: %d, %d", e->settings.cgreg,
+					e->settings.gprs_status);
+		ofono_emulator_send_info(e, buf, TRUE);
 		ofono_emulator_send_final(e, G_AT_SERVER_RESULT_OK);
 		break;
 	case G_AT_SERVER_REQUEST_TYPE_SET:
@@ -720,6 +728,78 @@ static void emulator_remove(struct ofono_atom *atom)
 	e = NULL;
 }
 
+static void emulator_gprs_update(struct ofono_emulator *e)
+{
+	GAtServer *server = e->server;
+	char buf[256];
+
+	switch (e->settings.cgreg) {
+	case 0:
+		break;
+	case 1:
+		snprintf(buf, sizeof(buf), "+CGREG: %d",
+						e->settings.gprs_status);
+		g_at_server_send_unsolicited(server, buf);
+		break;
+	case 2:
+		snprintf(buf, sizeof(buf), "+CGREG: %d",
+						e->settings.gprs_status);
+		g_at_server_send_unsolicited(server, buf);
+		break;
+	default:
+		break;
+	}
+}
+
+static void gprs_status_changed(int status, void *data)
+{
+	struct ofono_emulator *e = data;
+
+	DBG("%d", status);
+
+	e->settings.gprs_status = status;
+
+	emulator_gprs_update(e);
+}
+
+static void gprs_watch(struct ofono_atom *atom,
+				enum ofono_atom_watch_condition cond,
+				void *data)
+{
+	struct ofono_emulator *e = data;
+	struct ofono_gprs *gprs;
+
+	if (cond == OFONO_ATOM_WATCH_CONDITION_UNREGISTERED) {
+		e->gprs_status_watch = 0;
+		e->gprs = NULL;
+		return;
+	}
+
+	gprs = __ofono_atom_get_data(atom);
+	e->gprs = gprs;
+	e->settings.gprs_status = ofono_gprs_get_status(gprs);
+	e->gprs_status_watch = __ofono_gprs_add_status_watch(e->gprs,
+					gprs_status_changed, e, NULL);
+
+	emulator_gprs_update(e);
+}
+
+static void add_gprs_watches(struct ofono_emulator *e)
+{
+	struct ofono_modem *modem = e->modem;
+	struct ofono_atom *gprs_atom;
+
+	e->gprs_watch = __ofono_modem_add_atom_watch(modem,
+					OFONO_ATOM_TYPE_GPRS,
+					gprs_watch, e, NULL);
+
+	gprs_atom = __ofono_modem_find_atom(modem, OFONO_ATOM_TYPE_GPRS);
+
+	if (gprs_atom && __ofono_atom_get_registered(gprs_atom))
+		gprs_watch(gprs_atom,
+				OFONO_ATOM_WATCH_CONDITION_REGISTERED, e);
+}
+
 unsigned int __ofono_emulator_add_status_watch(struct ofono_emulator *e,
 				ofono_emulator_status_notify_cb_t notify,
 				void *data, ofono_destroy_func destroy)
@@ -767,6 +847,18 @@ static void emulator_unregister(struct ofono_atom *atom)
 		g_at_ppp_unref(e->ppp);
 		e->ppp = NULL;
 	}
+
+	if (e->gprs_watch) {
+		if (e->gprs_status_watch) {
+			__ofono_gprs_remove_status_watch(e->gprs,
+						e->gprs_status_watch);
+			e->gprs_status_watch = 0;
+		}
+
+		__ofono_modem_remove_atom_watch(e->modem, e->gprs_watch);
+		e->gprs_watch = 0;
+		e->gprs = NULL;
+	}
 }
 
 struct ofono_emulator *ofono_emulator_create(struct ofono_modem *modem,
@@ -808,5 +900,7 @@ struct ofono_emulator *ofono_emulator_create(struct ofono_modem *modem,
 	g_at_server_register(e->server, "+CGATT", cgatt_cb, e, NULL);
 	g_at_server_register(e->server, "+CGDCONT", cgdcont_cb, e, NULL);
 
+	add_gprs_watches(e);
+
 	return e;
 }
-- 
1.7.0.4


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

* [PATCH 16/16] emulator: Watch netreg status changes
  2010-08-11  2:26 [PATCH 00/16] Implement DUN server for oFono Zhenhua Zhang
                   ` (14 preceding siblings ...)
  2010-08-11  2:26 ` [PATCH 15/16] emulator: Watch GPRS status changes Zhenhua Zhang
@ 2010-08-11  2:26 ` Zhenhua Zhang
  15 siblings, 0 replies; 23+ messages in thread
From: Zhenhua Zhang @ 2010-08-11  2:26 UTC (permalink / raw)
  To: ofono

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

Watch netreg status update to notify DUN client, such as +CREG
unsolicited result.
---
 src/emulator.c |  106 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 106 insertions(+), 0 deletions(-)

diff --git a/src/emulator.c b/src/emulator.c
index c8f3d65..56edab6 100644
--- a/src/emulator.c
+++ b/src/emulator.c
@@ -56,6 +56,9 @@ struct modem_settings {
 	int cops;
 	int attached;
 	int gprs_status;
+	int netreg_status;
+	int netreg_lac;
+	int netreg_ci;
 };
 
 struct ofono_emulator {
@@ -72,6 +75,9 @@ struct ofono_emulator {
 	struct ofono_gprs *gprs;
 	unsigned int gprs_watch;
 	unsigned int gprs_status_watch;
+	struct ofono_netreg *netreg;
+	unsigned int netreg_watch;
+	unsigned int netreg_status_watch;
 };
 
 static unsigned int ofono_emulator_ids;
@@ -254,12 +260,19 @@ static void creg_cb(GAtServerRequestType type, GAtResult *result,
 					gpointer user_data)
 {
 	struct ofono_emulator *e = user_data;
+	char buf[256];
 
 	switch (type) {
 	case G_AT_SERVER_REQUEST_TYPE_SUPPORT:
 		ofono_emulator_send_final(e, G_AT_SERVER_RESULT_OK);
 		break;
 	case G_AT_SERVER_REQUEST_TYPE_QUERY:
+		snprintf(buf, sizeof(buf), "+CREG: %d, %x, %x, %x",
+						e->settings.creg,
+						e->settings.netreg_status,
+						e->settings.netreg_lac,
+						e->settings.netreg_ci);
+		ofono_emulator_send_info(e, buf, TRUE);
 		ofono_emulator_send_final(e, G_AT_SERVER_RESULT_OK);
 		break;
 	case G_AT_SERVER_REQUEST_TYPE_SET:
@@ -800,6 +813,86 @@ static void add_gprs_watches(struct ofono_emulator *e)
 				OFONO_ATOM_WATCH_CONDITION_REGISTERED, e);
 }
 
+static void emulator_netreg_update(struct ofono_emulator *e)
+{
+	GAtServer *server = e->server;
+	char buf[256];
+
+	switch (e->settings.creg) {
+	case 0:
+		break;
+	case 1:
+		snprintf(buf, sizeof(buf), "+CREG: %d",
+						e->settings.netreg_status);
+		g_at_server_send_unsolicited(server, buf);
+		break;
+	case 2:
+		snprintf(buf, sizeof(buf), "+CREG: %d, %x, %x",
+						e->settings.netreg_status,
+						e->settings.netreg_lac,
+						e->settings.netreg_ci);
+		g_at_server_send_unsolicited(server, buf);
+		break;
+	default:
+		break;
+	}
+}
+
+static void netreg_status_changed(int status, int lac, int ci, int tech,
+					const char *mcc, const char *mnc,
+					void *data)
+{
+	struct ofono_emulator *e = data;
+
+	DBG("%d %d %d", status, lac, ci);
+
+	e->settings.netreg_status = status;
+	e->settings.netreg_lac = lac;
+	e->settings.netreg_ci = ci;
+
+	emulator_netreg_update(e);
+}
+
+static void netreg_watch(struct ofono_atom *atom,
+				enum ofono_atom_watch_condition cond,
+				void *data)
+{
+	struct ofono_emulator *e = data;
+	struct ofono_netreg *netreg;
+
+	if (cond == OFONO_ATOM_WATCH_CONDITION_UNREGISTERED) {
+		e->netreg_status_watch = 0;
+		e->netreg = NULL;
+		return;
+	}
+
+	netreg = __ofono_atom_get_data(atom);
+	e->netreg = netreg;
+	e->settings.netreg_status = ofono_netreg_get_status(netreg);
+	e->settings.netreg_lac = ofono_netreg_get_location(netreg);
+	e->settings.netreg_ci = ofono_netreg_get_cellid(netreg);
+	e->netreg_status_watch = __ofono_netreg_add_status_watch(e->netreg,
+					netreg_status_changed, e, NULL);
+
+	emulator_netreg_update(e);
+}
+
+static void add_netreg_watches(struct ofono_emulator *e)
+{
+	struct ofono_modem *modem = e->modem;
+	struct ofono_atom *netreg_atom;
+
+	e->netreg_watch = __ofono_modem_add_atom_watch(modem,
+					OFONO_ATOM_TYPE_NETREG,
+					netreg_watch, e, NULL);
+
+	netreg_atom = __ofono_modem_find_atom(modem, OFONO_ATOM_TYPE_NETREG);
+
+	if (netreg_atom && __ofono_atom_get_registered(netreg_atom))
+		netreg_watch(netreg_atom,
+				OFONO_ATOM_WATCH_CONDITION_REGISTERED, e);
+}
+
 unsigned int __ofono_emulator_add_status_watch(struct ofono_emulator *e,
 				ofono_emulator_status_notify_cb_t notify,
 				void *data, ofono_destroy_func destroy)
@@ -859,6 +952,18 @@ static void emulator_unregister(struct ofono_atom *atom)
 		e->gprs_watch = 0;
 		e->gprs = NULL;
 	}
+
+	if (e->netreg_watch) {
+		if (e->netreg_status_watch) {
+			__ofono_netreg_remove_status_watch(e->netreg,
+						e->netreg_status_watch);
+			e->netreg_status_watch = 0;
+		}
+
+		__ofono_modem_remove_atom_watch(e->modem, e->netreg_watch);
+		e->netreg_watch = 0;
+		e->netreg = NULL;
+	}
 }
 
 struct ofono_emulator *ofono_emulator_create(struct ofono_modem *modem,
@@ -901,6 +1006,7 @@ struct ofono_emulator *ofono_emulator_create(struct ofono_modem *modem,
 	g_at_server_register(e->server, "+CGDCONT", cgdcont_cb, e, NULL);
 
 	add_gprs_watches(e);
+	add_netreg_watches(e);
 
 	return e;
 }
-- 
1.7.0.4


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

* Re: [PATCH 04/16] emulator: Add APIs to send GAtServer result
  2010-08-11  2:26 ` [PATCH 04/16] emulator: Add APIs to send GAtServer result Zhenhua Zhang
@ 2010-08-12 11:52   ` Marcel Holtmann
  2010-08-13  1:08     ` Zhang, Zhenhua
  0 siblings, 1 reply; 23+ messages in thread
From: Marcel Holtmann @ 2010-08-12 11:52 UTC (permalink / raw)
  To: ofono

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

Hi Zhenhua,

> Defines APIs to send final/intermediate/unsolicited result to DUN
> client.
> ---
>  include/emulator.h |    2 ++
>  src/emulator.c     |   28 ++++++++++++++++++++++++++++
>  src/ofono.h        |   11 +++++++++++
>  3 files changed, 41 insertions(+), 0 deletions(-)
> 
> diff --git a/include/emulator.h b/include/emulator.h
> index 29e87b9..2a45c65 100644
> --- a/include/emulator.h
> +++ b/include/emulator.h
> @@ -36,6 +36,8 @@ enum ofono_emulator_status {
>  	OFONO_EMULATOR_STATUS_DESTROY,
>  };
>  
> +enum _GAtServerResult;
> +

this is not good. It should not be needed outside of GAtChat. Why not
just include gatserver.h?

And in addition the _GAt declaration should never be used. Why not use
the typedef one?

Regards

Marcel



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

* Re: [PATCH 10/16] gprs: Add ofono_gprs_create_context method
  2010-08-11  2:26 ` [PATCH 10/16] gprs: Add ofono_gprs_create_context method Zhenhua Zhang
@ 2010-08-12 11:57   ` Marcel Holtmann
  2010-08-13  1:42     ` Zhang, Zhenhua
  0 siblings, 1 reply; 23+ messages in thread
From: Marcel Holtmann @ 2010-08-12 11:57 UTC (permalink / raw)
  To: ofono

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

Hi Zhenhua,

> DUN server may create one primary context if none of contexts existing
> on the GPRS atom.

so Denis and I had a chat about this. And we agreed that oFono core
should just create one Internet context if none exists. If the plugin
driver registers a GPRS atom, we should just create one context anyway.
ConnMan requires this anyway and it makes sense. We can also go one step
ahead and fail to remove this default Internet context. It should be
present all the time.

Regards

Marcel



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

* RE: [PATCH 04/16] emulator: Add APIs to send GAtServer result
  2010-08-12 11:52   ` Marcel Holtmann
@ 2010-08-13  1:08     ` Zhang, Zhenhua
  2010-08-13 13:06       ` Marcel Holtmann
  0 siblings, 1 reply; 23+ messages in thread
From: Zhang, Zhenhua @ 2010-08-13  1:08 UTC (permalink / raw)
  To: ofono

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

Hi Marcel,

Marcel Holtmann wrote:
> Hi Zhenhua,
> 
>> Defines APIs to send final/intermediate/unsolicited result to DUN
>> client. ---
>>  include/emulator.h |    2 ++
>>  src/emulator.c     |   28 ++++++++++++++++++++++++++++
>>  src/ofono.h        |   11 +++++++++++
>>  3 files changed, 41 insertions(+), 0 deletions(-)
>> 
>> diff --git a/include/emulator.h b/include/emulator.h
>> index 29e87b9..2a45c65 100644
>> --- a/include/emulator.h
>> +++ b/include/emulator.h
>> @@ -36,6 +36,8 @@ enum ofono_emulator_status {
>>  	OFONO_EMULATOR_STATUS_DESTROY,
>>  };
>> 
>> +enum _GAtServerResult;
>> +
> 
> this is not good. It should not be needed outside of GAtChat. Why not
> just include gatserver.h?

My original purpose is to avoid including another gatserver header in .h file.
So far, we don't include gatchat.h/gatserver.h in oFono core header file.

> And in addition the _GAt declaration should never be used. Why not use
> the typedef one?

If we allow to include gatserver.h, this problem is gone. We do have typedef
in gatserver.h.

> Regards
> 
> Marcel
> 
> 
> _______________________________________________
> ofono mailing list
> ofono(a)ofono.org
> http://lists.ofono.org/listinfo/ofono

Regards,
Zhenhua

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

* RE: [PATCH 10/16] gprs: Add ofono_gprs_create_context method
  2010-08-12 11:57   ` Marcel Holtmann
@ 2010-08-13  1:42     ` Zhang, Zhenhua
  2010-08-13 13:04       ` Marcel Holtmann
  0 siblings, 1 reply; 23+ messages in thread
From: Zhang, Zhenhua @ 2010-08-13  1:42 UTC (permalink / raw)
  To: ofono

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

Hi Marcel,

Marcel Holtmann wrote:
> Hi Zhenhua,
> 
>> DUN server may create one primary context if none of contexts
>> existing on the GPRS atom.
> 
> so Denis and I had a chat about this. And we agreed that oFono core
> should just create one Internet context if none exists. If the plugin
> driver registers a GPRS atom, we should just create one context
> anyway. ConnMan requires this anyway and it makes sense. We can also
> go one step ahead and fail to remove this default Internet context.
> It should be present all the time.

Thanks for update. I will update my patch to keep this context alive after
DUN client disconnect from us.

> Regards
> 
> Marcel
> 
> 
> _______________________________________________
> ofono mailing list
> ofono(a)ofono.org
> http://lists.ofono.org/listinfo/ofono

Regards,
Zhenhua

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

* RE: [PATCH 10/16] gprs: Add ofono_gprs_create_context method
  2010-08-13  1:42     ` Zhang, Zhenhua
@ 2010-08-13 13:04       ` Marcel Holtmann
  0 siblings, 0 replies; 23+ messages in thread
From: Marcel Holtmann @ 2010-08-13 13:04 UTC (permalink / raw)
  To: ofono

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

Hi Zhenhua,

> >> DUN server may create one primary context if none of contexts
> >> existing on the GPRS atom.
> > 
> > so Denis and I had a chat about this. And we agreed that oFono core
> > should just create one Internet context if none exists. If the plugin
> > driver registers a GPRS atom, we should just create one context
> > anyway. ConnMan requires this anyway and it makes sense. We can also
> > go one step ahead and fail to remove this default Internet context.
> > It should be present all the time.
> 
> Thanks for update. I will update my patch to keep this context alive after
> DUN client disconnect from us.

actually can you just work on a separate patch that just create a
default context when the GPRS atom is supported. We should add this
support first and don't tie it to DUN support.

Regards

Marcel



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

* RE: [PATCH 04/16] emulator: Add APIs to send GAtServer result
  2010-08-13  1:08     ` Zhang, Zhenhua
@ 2010-08-13 13:06       ` Marcel Holtmann
  0 siblings, 0 replies; 23+ messages in thread
From: Marcel Holtmann @ 2010-08-13 13:06 UTC (permalink / raw)
  To: ofono

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

Hi Zhenhua,

> >> Defines APIs to send final/intermediate/unsolicited result to DUN
> >> client. ---
> >>  include/emulator.h |    2 ++
> >>  src/emulator.c     |   28 ++++++++++++++++++++++++++++
> >>  src/ofono.h        |   11 +++++++++++
> >>  3 files changed, 41 insertions(+), 0 deletions(-)
> >> 
> >> diff --git a/include/emulator.h b/include/emulator.h
> >> index 29e87b9..2a45c65 100644
> >> --- a/include/emulator.h
> >> +++ b/include/emulator.h
> >> @@ -36,6 +36,8 @@ enum ofono_emulator_status {
> >>  	OFONO_EMULATOR_STATUS_DESTROY,
> >>  };
> >> 
> >> +enum _GAtServerResult;
> >> +
> > 
> > this is not good. It should not be needed outside of GAtChat. Why not
> > just include gatserver.h?
> 
> My original purpose is to avoid including another gatserver header in .h file.
> So far, we don't include gatchat.h/gatserver.h in oFono core header file.
> 
> > And in addition the _GAt declaration should never be used. Why not use
> > the typedef one?
> 
> If we allow to include gatserver.h, this problem is gone. We do have typedef
> in gatserver.h.

good point here, but your way of avoiding this is not really clean
either. Lets discuss this with Denis and see what he thinks.

Regards

Marcel



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

end of thread, other threads:[~2010-08-13 13:06 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-08-11  2:26 [PATCH 00/16] Implement DUN server for oFono Zhenhua Zhang
2010-08-11  2:26 ` [PATCH 01/16] gprs: Rename status_watch to netreg_status_watch Zhenhua Zhang
2010-08-11  2:26 ` [PATCH 02/16] emulator: Add status watches for ofono emulator Zhenhua Zhang
2010-08-11  2:26 ` [PATCH 03/16] emulator: Add emulator status watches in gprs atom Zhenhua Zhang
2010-08-11  2:26 ` [PATCH 04/16] emulator: Add APIs to send GAtServer result Zhenhua Zhang
2010-08-12 11:52   ` Marcel Holtmann
2010-08-13  1:08     ` Zhang, Zhenhua
2010-08-13 13:06       ` Marcel Holtmann
2010-08-11  2:26 ` [PATCH 05/16] emulator: Implement dialing up for DUN Zhenhua Zhang
2010-08-11  2:26 ` [PATCH 06/16] gprs: Make gprs_proto_to/from_string non-static Zhenhua Zhang
2010-08-11  2:26 ` [PATCH 07/16] emulator: Register mandatory AT command handlers Zhenhua Zhang
2010-08-11  2:26 ` [PATCH 08/16] gprs: Refactor to share remove_context method Zhenhua Zhang
2010-08-11  2:26 ` [PATCH 09/16] gprs: Add DUN +CGATT support in gprs atom Zhenhua Zhang
2010-08-11  2:26 ` [PATCH 10/16] gprs: Add ofono_gprs_create_context method Zhenhua Zhang
2010-08-12 11:57   ` Marcel Holtmann
2010-08-13  1:42     ` Zhang, Zhenhua
2010-08-13 13:04       ` Marcel Holtmann
2010-08-11  2:26 ` [PATCH 11/16] gprs: Add DUN +CGDCONT support in gprs atom Zhenhua Zhang
2010-08-11  2:26 ` [PATCH 12/16] gprs: Add DUN server GPRS connect support Zhenhua Zhang
2010-08-11  2:26 ` [PATCH 13/16] gprs: Add status watch functions Zhenhua Zhang
2010-08-11  2:26 ` [PATCH 14/16] gprs: Add gprs_get_status Zhenhua Zhang
2010-08-11  2:26 ` [PATCH 15/16] emulator: Watch GPRS status changes Zhenhua Zhang
2010-08-11  2:26 ` [PATCH 16/16] emulator: Watch netreg " Zhenhua Zhang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox