All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH_v3 0/3] Request private network to ConnMan
@ 2011-05-03 14:44 Guillaume Zajac
  2011-05-03 14:44 ` [PATCH_v3 1/3] gatppp: Add new contructor to use external fd Guillaume Zajac
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Guillaume Zajac @ 2011-05-03 14:44 UTC (permalink / raw)
  To: ofono

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

Hi,

Changelog from v2 is:
	- merge patch 3 and 4
	- calls to ConnMan DBus methods are async
	- setup_ppp() function is called from reply of
	  RequestPrivateNetwork() DBus method
	- pending calls are stored into hash table and can be cancelled
	- there is no more struct private_network_settings

Guillaume Zajac (3):
  gatppp: Add new contructor to use external fd
  emulator: add drivers to request/release private network from ConnMan
  connman: add plugin in oFono to request request/release private
    network

 Makefile.am        |    3 +
 gatchat/gatppp.c   |   48 +++++++++-
 gatchat/gatppp.h   |    1 +
 gatchat/ppp.h      |    2 +-
 gatchat/ppp_net.c  |   55 +++++++----
 include/emulator.h |   18 ++++
 plugins/connman.c  |  255 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/emulator.c     |   83 +++++++++++++----
 8 files changed, 420 insertions(+), 45 deletions(-)
 create mode 100644 plugins/connman.c


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

* [PATCH_v3 1/3] gatppp: Add new contructor to use external fd
  2011-05-03 14:44 [PATCH_v3 0/3] Request private network to ConnMan Guillaume Zajac
@ 2011-05-03 14:44 ` Guillaume Zajac
  2011-05-05  4:04   ` Denis Kenzior
  2011-05-03 14:44 ` [PATCH_v3 2/3] emulator: add drivers to request/release private network from ConnMan Guillaume Zajac
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 9+ messages in thread
From: Guillaume Zajac @ 2011-05-03 14:44 UTC (permalink / raw)
  To: ofono

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

---
 gatchat/gatppp.c  |   48 ++++++++++++++++++++++++++++++++++++++++++---
 gatchat/gatppp.h  |    1 +
 gatchat/ppp.h     |    2 +-
 gatchat/ppp_net.c |   55 +++++++++++++++++++++++++++++++++-------------------
 4 files changed, 81 insertions(+), 25 deletions(-)

diff --git a/gatchat/gatppp.c b/gatchat/gatppp.c
index 993b5ea..c7cc28b 100644
--- a/gatchat/gatppp.c
+++ b/gatchat/gatppp.c
@@ -76,6 +76,7 @@ struct _GAtPPP {
 	gpointer debug_data;
 	gboolean sta_pending;
 	guint ppp_dead_source;
+	int fd;
 };
 
 void ppp_debug(GAtPPP *ppp, const char *str)
@@ -288,7 +289,7 @@ void ppp_auth_notify(GAtPPP *ppp, gboolean success)
 void ppp_ipcp_up_notify(GAtPPP *ppp, const char *local, const char *peer,
 					const char *dns1, const char *dns2)
 {
-	ppp->net = ppp_net_new(ppp);
+	ppp->net = ppp_net_new(ppp, ppp->fd);
 
 	if (ppp->net == NULL) {
 		ppp->disconnect_reason = G_AT_PPP_REASON_NET_FAIL;
@@ -296,8 +297,14 @@ void ppp_ipcp_up_notify(GAtPPP *ppp, const char *local, const char *peer,
 		return;
 	}
 
-	if (ppp_net_set_mtu(ppp->net, ppp->mtu) == FALSE)
-		DBG(ppp, "Unable to set MTU");
+	/*
+	 * If we have opened the tun interface locally,
+	 * we have to set a MTU value.
+	 */
+	if (ppp->fd < 0) {
+		if (ppp_net_set_mtu(ppp->net, ppp->mtu) == FALSE)
+			DBG(ppp, "Unable to set MTU");
+	}
 
 	ppp_enter_phase(ppp, PPP_PHASE_LINK_UP);
 
@@ -314,6 +321,7 @@ void ppp_ipcp_down_notify(GAtPPP *ppp)
 		return;
 
 	ppp_net_free(ppp->net);
+	ppp->fd = -1;
 	ppp->net = NULL;
 }
 
@@ -496,8 +504,13 @@ void g_at_ppp_unref(GAtPPP *ppp)
 	g_at_io_set_disconnect_function(g_at_hdlc_get_io(ppp->hdlc),
 						NULL, NULL);
 
-	if (ppp->net)
+	if (ppp->net) {
 		ppp_net_free(ppp->net);
+	}
+	else {
+		if (ppp->fd >= 0)
+			close(ppp->fd);
+	}
 
 	if (ppp->chap)
 		ppp_chap_free(ppp->chap);
@@ -541,6 +554,8 @@ static GAtPPP *ppp_init_common(GAtHDLC *hdlc, gboolean is_server, guint32 ip)
 
 	ppp->ref_count = 1;
 
+	ppp->fd = -1;
+
 	/* set options to defaults */
 	ppp->mru = DEFAULT_MRU;
 	ppp->mtu = DEFAULT_MTU;
@@ -633,3 +648,28 @@ GAtPPP *g_at_ppp_server_new_from_io(GAtIO *io, const char *local)
 
 	return ppp;
 }
+
+GAtPPP *g_at_ppp_server_new_full(GAtIO *io, const char *local, int fd)
+{
+	GAtHDLC *hdlc;
+	GAtPPP *ppp;
+	guint32 ip;
+
+	if (local == NULL)
+		ip = 0;
+	else if (inet_pton(AF_INET, local, &ip) != 1)
+		return NULL;
+
+	hdlc = g_at_hdlc_new_from_io(io);
+	if (hdlc == NULL)
+		return NULL;
+
+	ppp = ppp_init_common(hdlc, TRUE, ip);
+
+	/* Set the fd value returned by ConnMan */
+	ppp->fd = fd;
+
+	g_at_hdlc_unref(hdlc);
+
+	return ppp;
+}
diff --git a/gatchat/gatppp.h b/gatchat/gatppp.h
index fb5de4c..825c022 100644
--- a/gatchat/gatppp.h
+++ b/gatchat/gatppp.h
@@ -54,6 +54,7 @@ GAtPPP *g_at_ppp_new(GIOChannel *modem);
 GAtPPP *g_at_ppp_new_from_io(GAtIO *io);
 GAtPPP *g_at_ppp_server_new(GIOChannel *modem, const char *local);
 GAtPPP *g_at_ppp_server_new_from_io(GAtIO *io, const char *local);
+GAtPPP *g_at_ppp_server_new_full(GAtIO *io, const char *local, int fd);
 
 void g_at_ppp_open(GAtPPP *ppp);
 void g_at_ppp_set_connect_function(GAtPPP *ppp, GAtPPPConnectFunc callback,
diff --git a/gatchat/ppp.h b/gatchat/ppp.h
index d2786d7..8107820 100644
--- a/gatchat/ppp.h
+++ b/gatchat/ppp.h
@@ -102,7 +102,7 @@ void ppp_chap_free(struct ppp_chap *chap);
 void ppp_chap_process_packet(struct ppp_chap *chap, const guint8 *new_packet);
 
 /* TUN / Network related functions */
-struct ppp_net *ppp_net_new(GAtPPP *ppp);
+struct ppp_net *ppp_net_new(GAtPPP *ppp, int fd);
 const char *ppp_net_get_interface(struct ppp_net *net);
 void ppp_net_process_packet(struct ppp_net *net, const guint8 *packet);
 void ppp_net_free(struct ppp_net *net);
diff --git a/gatchat/ppp_net.c b/gatchat/ppp_net.c
index 1a6cdf7..1a56a3c 100644
--- a/gatchat/ppp_net.c
+++ b/gatchat/ppp_net.c
@@ -123,12 +123,13 @@ const char *ppp_net_get_interface(struct ppp_net *net)
 	return net->if_name;
 }
 
-struct ppp_net *ppp_net_new(GAtPPP *ppp)
+struct ppp_net *ppp_net_new(GAtPPP *ppp, int fd)
 {
 	struct ppp_net *net;
 	GIOChannel *channel = NULL;
 	struct ifreq ifr;
-	int fd, err;
+	int fdesc = -1;
+	int err;
 
 	net = g_try_new0(struct ppp_net, 1);
 	if (net == NULL)
@@ -140,23 +141,37 @@ struct ppp_net *ppp_net_new(GAtPPP *ppp)
 		return NULL;
 	}
 
-	/* open a tun interface */
-	fd = open("/dev/net/tun", O_RDWR);
-	if (fd < 0)
-		goto error;
-
-	memset(&ifr, 0, sizeof(ifr));
-	ifr.ifr_flags = IFF_TUN | IFF_NO_PI;
-	strcpy(ifr.ifr_name, "ppp%d");
-
-	err = ioctl(fd, TUNSETIFF, (void *) &ifr);
-	if (err < 0)
-		goto error;
-
-	net->if_name = strdup(ifr.ifr_name);
+	/*
+	 * If the fd value is still the default one,
+	 * open the tun interface and configure it.
+	 */
+	if (fd < 0) {
+		/* open a tun interface */
+		fdesc = open("/dev/net/tun", O_RDWR);
+		if (fdesc < 0)
+			goto error;
+
+		memset(&ifr, 0, sizeof(ifr));
+		ifr.ifr_flags = IFF_TUN | IFF_NO_PI;
+		strcpy(ifr.ifr_name, "ppp%d");
+
+		err = ioctl(fdesc, TUNSETIFF, (void *) &ifr);
+		if (err < 0)
+			goto error;
+
+		net->if_name = strdup(ifr.ifr_name);
+		/* create a channel for reading and writing to this interface */
+		channel = g_io_channel_unix_new(fdesc);
+	} else {
+		err = ioctl(fd, TUNGETIFF, (void *) &ifr);
+		if (err < 0)
+			goto error;
+
+		net->if_name = strdup(ifr.ifr_name);
+		/* create a channel for reading and writing to this interface */
+		channel = g_io_channel_unix_new(fd);
+	}
 
-	/* create a channel for reading and writing to this interface */
-	channel = g_io_channel_unix_new(fd);
 	if (channel == NULL)
 		goto error;
 
@@ -178,8 +193,8 @@ error:
 	if (channel)
 		g_io_channel_unref(channel);
 
-	if (fd >= 0)
-		close(fd);
+	if (fdesc >= 0)
+		close(fdesc);
 
 	g_free(net->if_name);
 	g_free(net->ppp_packet);
-- 
1.7.1


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

* [PATCH_v3 2/3] emulator: add drivers to request/release private network from ConnMan
  2011-05-03 14:44 [PATCH_v3 0/3] Request private network to ConnMan Guillaume Zajac
  2011-05-03 14:44 ` [PATCH_v3 1/3] gatppp: Add new contructor to use external fd Guillaume Zajac
@ 2011-05-03 14:44 ` Guillaume Zajac
  2011-05-05  4:11   ` Denis Kenzior
  2011-05-03 14:44 ` [PATCH_v3 3/3] connman: add plugin in oFono to request request/release private network Guillaume Zajac
  2011-05-03 15:06 ` Guillaume Zajac
  3 siblings, 1 reply; 9+ messages in thread
From: Guillaume Zajac @ 2011-05-03 14:44 UTC (permalink / raw)
  To: ofono

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

---
 include/emulator.h |   18 +++++++++++
 src/emulator.c     |   83 +++++++++++++++++++++++++++++++++++++++------------
 2 files changed, 81 insertions(+), 20 deletions(-)

diff --git a/include/emulator.h b/include/emulator.h
index 5cd894b..a7fc23b 100644
--- a/include/emulator.h
+++ b/include/emulator.h
@@ -105,6 +105,24 @@ enum ofono_emulator_request_type ofono_emulator_request_get_type(
 void ofono_emulator_set_indicator(struct ofono_emulator *em,
 					const char *name, int value);
 
+ofono_bool_t ofono_emulator_setup_ppp(struct ofono_emulator *em, int fd,
+				const char *server_ip, const char *peer_ip,
+				const char *primary_dns,
+				const char *secondary_dns);
+
+int ofono_emulator_get_uid(struct ofono_emulator *em);
+
+struct emulator_network_provision_driver {
+	char *name;
+	int (*get_settings)(struct ofono_emulator *em);
+	void (*release)(int uid);
+};
+
+int ofono_emulator_network_driver_register(
+			const struct emulator_network_provision_driver *d);
+void ofono_emulator_network_driver_unregister(
+			const struct emulator_network_provision_driver *d);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/src/emulator.c b/src/emulator.c
index 9055909..8850286 100644
--- a/src/emulator.c
+++ b/src/emulator.c
@@ -25,6 +25,7 @@
 
 #include <stdio.h>
 #include <string.h>
+#include <unistd.h>
 
 #include <glib.h>
 
@@ -33,10 +34,7 @@
 #include "gatserver.h"
 #include "gatppp.h"
 
-#define DUN_SERVER_ADDRESS     "192.168.1.1"
-#define DUN_PEER_ADDRESS       "192.168.1.2"
-#define DUN_DNS_SERVER_1       "10.10.10.10"
-#define DUN_DNS_SERVER_2       "10.10.10.11"
+static GSList *g_drivers = NULL;
 
 #define RING_TIMEOUT 3
 
@@ -45,7 +43,6 @@ struct ofono_emulator {
 	enum ofono_emulator_type type;
 	GAtServer *server;
 	GAtPPP *ppp;
-	guint source;
 	gboolean slc;
 	int l_features;
 	int r_features;
@@ -55,6 +52,8 @@ struct ofono_emulator {
 	guint callsetup_source;
 	gboolean clip;
 	gboolean ccwa;
+	int pns_uid;
+	const struct emulator_network_provision_driver *driver;
 };
 
 struct indicator {
@@ -98,6 +97,10 @@ static void ppp_disconnect(GAtPPPDisconnectReason reason, gpointer user_data)
 
 	g_at_ppp_unref(em->ppp);
 	em->ppp = NULL;
+	if (em->driver->release)
+		em->driver->release(em->pns_uid);
+
+	em->pns_uid = 0;
 
 	if (em->server == NULL)
 		return;
@@ -105,27 +108,32 @@ static void ppp_disconnect(GAtPPPDisconnectReason reason, gpointer user_data)
 	g_at_server_resume(em->server);
 }
 
-static gboolean setup_ppp(gpointer user_data)
+ofono_bool_t ofono_emulator_setup_ppp(struct ofono_emulator *em, int fd,
+				const char *server_ip, const char *peer_ip,
+				const char *primary_dns,
+				const char *secondary_dns)
 {
-	struct ofono_emulator *em = user_data;
 	GAtIO *io;
 
 	DBG("");
 
-	em->source = 0;
-
 	io = g_at_server_get_io(em->server);
 
 	g_at_server_suspend(em->server);
 
-	em->ppp = g_at_ppp_server_new_from_io(io, DUN_SERVER_ADDRESS);
+	em->ppp = g_at_ppp_server_new_full(io, server_ip, fd);
 	if (em->ppp == NULL) {
+		close(fd);
+		if (em->driver->release)
+			em->driver->release(em->pns_uid);
+		em->pns_uid = 0;
 		g_at_server_resume(em->server);
 		return FALSE;
 	}
 
-	g_at_ppp_set_server_info(em->ppp, DUN_PEER_ADDRESS,
-					DUN_DNS_SERVER_1, DUN_DNS_SERVER_2);
+	g_at_ppp_set_server_info(em->ppp, peer_ip,
+					primary_dns,
+					secondary_dns);
 
 	g_at_ppp_set_credentials(em->ppp, "", "");
 	g_at_ppp_set_debug(em->ppp, emulator_debug, "PPP");
@@ -133,7 +141,12 @@ static gboolean setup_ppp(gpointer user_data)
 	g_at_ppp_set_connect_function(em->ppp, ppp_connect, em);
 	g_at_ppp_set_disconnect_function(em->ppp, ppp_disconnect, em);
 
-	return FALSE;
+	return TRUE;
+}
+
+int ofono_emulator_get_uid(struct ofono_emulator *em)
+{
+	return em->pns_uid;
 }
 
 static gboolean dial_call(struct ofono_emulator *em, const char *dial_str)
@@ -143,10 +156,16 @@ static gboolean dial_call(struct ofono_emulator *em, const char *dial_str)
 	DBG("dial call %s", dial_str);
 
 	if (c == '*' || c == '#' || c == 'T' || c == 't') {
-		g_at_server_send_intermediate(em->server, "CONNECT");
-		em->source = g_idle_add(setup_ppp, em);
+		if (em->driver->get_settings)
+			em->pns_uid = em->driver->get_settings(em);
+		else 
+			return FALSE;
+		if (em->pns_uid < 0)
+			return FALSE;
 	}
 
+	g_at_server_send_intermediate(em->server, "CONNECT");
+
 	return TRUE;
 }
 
@@ -603,11 +622,6 @@ static void emulator_unregister(struct ofono_atom *atom)
 
 	DBG("%p", em);
 
-	if (em->source) {
-		g_source_remove(em->source);
-		em->source = 0;
-	}
-
 	if (em->callsetup_source) {
 		g_source_remove(em->callsetup_source);
 		em->callsetup_source = 0;
@@ -688,6 +702,7 @@ struct ofono_emulator *ofono_emulator_create(struct ofono_modem *modem,
 {
 	struct ofono_emulator *em;
 	enum ofono_atom_type atom_t;
+	GSList *l;
 
 	DBG("modem: %p, type: %d", modem, type);
 
@@ -711,6 +726,16 @@ struct ofono_emulator *ofono_emulator_create(struct ofono_modem *modem,
 	em->atom = __ofono_modem_add_atom_offline(modem, atom_t,
 							emulator_remove, em);
 
+	for (l = g_drivers; l; l = l->next) {
+		const struct emulator_network_provision_driver *drv = l->data;
+
+		if (g_strcmp0(drv->name, "ConnMan Private Network"))
+			continue;
+
+		em->driver = drv;
+		break;
+	}
+
 	return em;
 }
 
@@ -935,3 +960,21 @@ void ofono_emulator_set_indicator(struct ofono_emulator *em,
 		break;
 	}
 }
+
+int ofono_emulator_network_driver_register(
+			const struct emulator_network_provision_driver *d)
+{
+	DBG("driver: %p, name: %s", d, d->name);
+
+	g_drivers = g_slist_prepend(g_drivers, (void *) d);
+
+	return 0;
+}
+
+void ofono_emulator_network_driver_unregister(
+			const struct emulator_network_provision_driver *d)
+{
+	DBG("driver: %p, name: %s", d, d->name);
+
+	g_drivers = g_slist_remove(g_drivers, (void *) d);
+}
-- 
1.7.1


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

* [PATCH_v3 3/3] connman: add plugin in oFono to request request/release private network
  2011-05-03 14:44 [PATCH_v3 0/3] Request private network to ConnMan Guillaume Zajac
  2011-05-03 14:44 ` [PATCH_v3 1/3] gatppp: Add new contructor to use external fd Guillaume Zajac
  2011-05-03 14:44 ` [PATCH_v3 2/3] emulator: add drivers to request/release private network from ConnMan Guillaume Zajac
@ 2011-05-03 14:44 ` Guillaume Zajac
  2011-05-03 15:06 ` Guillaume Zajac
  3 siblings, 0 replies; 9+ messages in thread
From: Guillaume Zajac @ 2011-05-03 14:44 UTC (permalink / raw)
  To: ofono

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

---
 Makefile.am       |    3 +
 plugins/connman.c |  255 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 258 insertions(+), 0 deletions(-)
 create mode 100644 plugins/connman.c

diff --git a/Makefile.am b/Makefile.am
index a413a47..37f9468 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -339,6 +339,9 @@ builtin_sources += plugins/hfp_ag.c plugins/bluetooth.h
 builtin_modules += dun_gw
 builtin_sources += plugins/dun_gw.c plugins/bluetooth.h
 
+builtin_modules += connman
+builtin_sources += plugins/connman.c
+
 builtin_sources += $(btio_sources)
 builtin_cflags += @BLUEZ_CFLAGS@
 builtin_libadd += @BLUEZ_LIBS@
diff --git a/plugins/connman.c b/plugins/connman.c
new file mode 100644
index 0000000..47d4654
--- /dev/null
+++ b/plugins/connman.c
@@ -0,0 +1,255 @@
+/*
+ *
+ *  oFono - Open Source Telephony
+ *
+ *  Copyright (C) 2008-2011  Intel Corporation. All rights reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <errno.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <gdbus.h>
+#include <string.h>
+
+#include <ofono.h>
+#include <emulator.h>
+
+#define CONNMAN_SERVICE			"net.connman"
+#define CONNMAN_PATH			"/net/connman"
+
+#define CONNMAN_DEBUG_INTERFACE		CONNMAN_SERVICE ".Debug"
+#define CONNMAN_ERROR_INTERFACE		CONNMAN_SERVICE ".Error"
+#define CONNMAN_AGENT_INTERFACE		CONNMAN_SERVICE ".Agent"
+#define CONNMAN_COUNTER_INTERFACE	CONNMAN_SERVICE ".Counter"
+
+#define CONNMAN_MANAGER_INTERFACE	CONNMAN_SERVICE ".Manager"
+#define CONNMAN_MANAGER_PATH		"/"
+
+#define CONNMAN_TASK_INTERFACE		CONNMAN_SERVICE ".Task"
+#define CONNMAN_PROFILE_INTERFACE	CONNMAN_SERVICE ".Profile"
+#define CONNMAN_SERVICE_INTERFACE	CONNMAN_SERVICE ".Service"
+#define CONNMAN_PROVIDER_INTERFACE	CONNMAN_SERVICE ".Provider"
+#define CONNMAN_TECHNOLOGY_INTERFACE	CONNMAN_SERVICE ".Technology"
+#define CONNMAN_SESSION_INTERFACE	CONNMAN_SERVICE ".Session"
+#define CONNMAN_NOTIFICATION_INTERFACE	CONNMAN_SERVICE ".Notification"
+
+static DBusConnection *connection;
+static GHashTable *pending_calls;
+static int id;
+
+static void settings_reply(DBusPendingCall *call, void *user_data)
+{
+	struct ofono_emulator *em = user_data;
+	DBusMessageIter array, dict, entry;
+	DBusMessage *reply;
+	int fd = -1;
+	const char *server_ip = NULL;
+	const char *peer_ip = NULL;
+	const char *primary_dns = NULL;
+	const char *secondary_dns = NULL;
+	int uid = ofono_emulator_get_uid(em);
+
+	reply = dbus_pending_call_steal_reply(call);
+
+	if (!reply) {
+		g_hash_table_remove(pending_calls, &uid);
+		dbus_pending_call_unref(call);
+	}
+
+	if (dbus_message_iter_init(reply, &array) == FALSE)
+		goto done;
+
+	if (dbus_message_iter_get_arg_type(&array) != DBUS_TYPE_UNIX_FD)
+		goto done;
+
+	dbus_message_iter_get_basic(&array, &fd);
+	g_print("Fildescriptor = %d\n", fd);
+
+	dbus_message_iter_next(&array);
+
+	if (dbus_message_iter_get_arg_type(&array) != DBUS_TYPE_ARRAY)
+		goto done;
+
+	dbus_message_iter_recurse(&array, &dict);
+
+	while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
+		DBusMessageIter iter;
+		const char *key;
+		int type;
+
+		dbus_message_iter_recurse(&dict, &entry);
+
+		dbus_message_iter_get_basic(&entry, &key);
+
+		g_print("key %s", key);
+
+		dbus_message_iter_next(&entry);
+		dbus_message_iter_recurse(&entry, &iter);
+
+		type = dbus_message_iter_get_arg_type(&iter);
+		if (type != DBUS_TYPE_STRING)
+			break;
+
+		if (g_str_equal(key, "ServerIPv4")
+				&& type == DBUS_TYPE_STRING) {
+			dbus_message_iter_get_basic(&iter, &server_ip);
+			g_print(" = %s\n", server_ip);
+
+		} else if (g_str_equal(key, "PeerIPv4")
+				&& type == DBUS_TYPE_STRING) {
+			dbus_message_iter_get_basic(&iter, &peer_ip);
+			g_print(" = %s\n", peer_ip);
+
+		} else if (g_str_equal(key, "PrimaryDNS")
+				&& type == DBUS_TYPE_STRING) {
+			dbus_message_iter_get_basic(&iter, &primary_dns);
+			g_print(" = %s\n", primary_dns);
+
+		} else if (g_str_equal(key, "SecondaryDNS")
+				&& type == DBUS_TYPE_STRING) {
+			dbus_message_iter_get_basic(&iter, &secondary_dns);
+			g_print(" = %s\n", secondary_dns);
+		}
+
+		dbus_message_iter_next(&dict);
+	}
+
+	if (server_ip == NULL || peer_ip == NULL ||
+		primary_dns == NULL || secondary_dns == NULL) {
+		ofono_error("Error while reading dictionnary...\n");
+		goto done;
+	}
+
+	ofono_emulator_setup_ppp(em, fd, server_ip, peer_ip, primary_dns,
+					secondary_dns);
+
+done:
+	g_hash_table_remove(pending_calls, &uid);
+	dbus_message_unref(reply);
+	dbus_pending_call_unref(call);
+}
+
+static int pn_get_settings(struct ofono_emulator *em)
+{
+	DBusMessage *message;
+	DBusPendingCall *call;
+
+	DBG("");
+
+	message = dbus_message_new_method_call(CONNMAN_SERVICE,
+				     CONNMAN_MANAGER_PATH,
+				     CONNMAN_MANAGER_INTERFACE,
+				     "RequestPrivateNetwork");
+
+	if (message == NULL)
+		return -ENOMEM;
+
+	if (dbus_connection_send_with_reply(connection,
+				message, &call, 5000) == FALSE) {
+		ofono_error("Error while sending message...");
+		dbus_message_unref(message);
+		return -EIO;
+	}
+
+	dbus_pending_call_set_notify(call, settings_reply,
+							em, NULL);
+
+	id++;
+	g_hash_table_insert(pending_calls, &id, call);
+
+	dbus_message_unref(message);
+
+	return id;
+}
+
+static void release_reply(DBusPendingCall *call, void *user_data)
+{
+	DBusMessage *reply;
+
+	DBG("");
+
+	reply = dbus_pending_call_steal_reply(call);
+	dbus_pending_call_unref(call);
+}
+
+static void pn_release(int uid)
+{
+	DBusMessage *message;
+	DBusPendingCall *pending;
+	DBusPendingCall *call;
+
+	DBG("");
+
+	pending = g_hash_table_lookup(pending_calls, &uid);
+	if (pending) {
+		if (dbus_pending_call_get_completed(pending) == FALSE) {
+			dbus_pending_call_cancel(pending);
+			g_hash_table_remove(pending_calls, &uid);
+			return;
+		}
+	}
+
+	message = dbus_message_new_method_call(CONNMAN_SERVICE,
+				     CONNMAN_MANAGER_PATH,
+				     CONNMAN_MANAGER_INTERFACE,
+				     "ReleasePrivateNetwork");
+
+	if (message == NULL)
+		return;
+
+	if (dbus_connection_send_with_reply(connection,
+				message, &call, 5000) == FALSE) {
+		dbus_message_unref(message);
+		return;
+	}
+
+	dbus_pending_call_set_notify(call, release_reply,
+							NULL, NULL);
+
+	dbus_message_unref(message);
+}
+
+static struct emulator_network_provision_driver pn_driver = {
+	.name		= "ConnMan Private Network",
+	.get_settings	= pn_get_settings,
+	.release	= pn_release,
+};
+
+static int connman_init(void)
+{
+	DBG("");
+
+	id = 0;
+	connection = ofono_dbus_get_connection();
+	pending_calls = g_hash_table_new(g_int_hash, g_int_equal);
+
+	return ofono_emulator_network_driver_register(&pn_driver);
+}
+
+static void connman_exit(void)
+{
+	g_hash_table_destroy(pending_calls);
+	ofono_emulator_network_driver_unregister(&pn_driver);
+}
+
+OFONO_PLUGIN_DEFINE(connman, "ConnMan plugin", VERSION,
+		OFONO_PLUGIN_PRIORITY_DEFAULT, connman_init, connman_exit)
-- 
1.7.1


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

* [PATCH_v3 3/3] connman: add plugin in oFono to request request/release private network
  2011-05-03 14:44 [PATCH_v3 0/3] Request private network to ConnMan Guillaume Zajac
                   ` (2 preceding siblings ...)
  2011-05-03 14:44 ` [PATCH_v3 3/3] connman: add plugin in oFono to request request/release private network Guillaume Zajac
@ 2011-05-03 15:06 ` Guillaume Zajac
  3 siblings, 0 replies; 9+ messages in thread
From: Guillaume Zajac @ 2011-05-03 15:06 UTC (permalink / raw)
  To: ofono

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

---
 Makefile.am       |    3 +
 plugins/connman.c |  255 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 258 insertions(+), 0 deletions(-)
 create mode 100644 plugins/connman.c

diff --git a/Makefile.am b/Makefile.am
index a413a47..37f9468 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -339,6 +339,9 @@ builtin_sources += plugins/hfp_ag.c plugins/bluetooth.h
 builtin_modules += dun_gw
 builtin_sources += plugins/dun_gw.c plugins/bluetooth.h
 
+builtin_modules += connman
+builtin_sources += plugins/connman.c
+
 builtin_sources += $(btio_sources)
 builtin_cflags += @BLUEZ_CFLAGS@
 builtin_libadd += @BLUEZ_LIBS@
diff --git a/plugins/connman.c b/plugins/connman.c
new file mode 100644
index 0000000..47d4654
--- /dev/null
+++ b/plugins/connman.c
@@ -0,0 +1,255 @@
+/*
+ *
+ *  oFono - Open Source Telephony
+ *
+ *  Copyright (C) 2008-2011  Intel Corporation. All rights reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <errno.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <gdbus.h>
+#include <string.h>
+
+#include <ofono.h>
+#include <emulator.h>
+
+#define CONNMAN_SERVICE			"net.connman"
+#define CONNMAN_PATH			"/net/connman"
+
+#define CONNMAN_DEBUG_INTERFACE		CONNMAN_SERVICE ".Debug"
+#define CONNMAN_ERROR_INTERFACE		CONNMAN_SERVICE ".Error"
+#define CONNMAN_AGENT_INTERFACE		CONNMAN_SERVICE ".Agent"
+#define CONNMAN_COUNTER_INTERFACE	CONNMAN_SERVICE ".Counter"
+
+#define CONNMAN_MANAGER_INTERFACE	CONNMAN_SERVICE ".Manager"
+#define CONNMAN_MANAGER_PATH		"/"
+
+#define CONNMAN_TASK_INTERFACE		CONNMAN_SERVICE ".Task"
+#define CONNMAN_PROFILE_INTERFACE	CONNMAN_SERVICE ".Profile"
+#define CONNMAN_SERVICE_INTERFACE	CONNMAN_SERVICE ".Service"
+#define CONNMAN_PROVIDER_INTERFACE	CONNMAN_SERVICE ".Provider"
+#define CONNMAN_TECHNOLOGY_INTERFACE	CONNMAN_SERVICE ".Technology"
+#define CONNMAN_SESSION_INTERFACE	CONNMAN_SERVICE ".Session"
+#define CONNMAN_NOTIFICATION_INTERFACE	CONNMAN_SERVICE ".Notification"
+
+static DBusConnection *connection;
+static GHashTable *pending_calls;
+static int id;
+
+static void settings_reply(DBusPendingCall *call, void *user_data)
+{
+	struct ofono_emulator *em = user_data;
+	DBusMessageIter array, dict, entry;
+	DBusMessage *reply;
+	int fd = -1;
+	const char *server_ip = NULL;
+	const char *peer_ip = NULL;
+	const char *primary_dns = NULL;
+	const char *secondary_dns = NULL;
+	int uid = ofono_emulator_get_uid(em);
+
+	reply = dbus_pending_call_steal_reply(call);
+
+	if (!reply) {
+		g_hash_table_remove(pending_calls, &uid);
+		dbus_pending_call_unref(call);
+	}
+
+	if (dbus_message_iter_init(reply, &array) == FALSE)
+		goto done;
+
+	if (dbus_message_iter_get_arg_type(&array) != DBUS_TYPE_UNIX_FD)
+		goto done;
+
+	dbus_message_iter_get_basic(&array, &fd);
+	g_print("Fildescriptor = %d\n", fd);
+
+	dbus_message_iter_next(&array);
+
+	if (dbus_message_iter_get_arg_type(&array) != DBUS_TYPE_ARRAY)
+		goto done;
+
+	dbus_message_iter_recurse(&array, &dict);
+
+	while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
+		DBusMessageIter iter;
+		const char *key;
+		int type;
+
+		dbus_message_iter_recurse(&dict, &entry);
+
+		dbus_message_iter_get_basic(&entry, &key);
+
+		g_print("key %s", key);
+
+		dbus_message_iter_next(&entry);
+		dbus_message_iter_recurse(&entry, &iter);
+
+		type = dbus_message_iter_get_arg_type(&iter);
+		if (type != DBUS_TYPE_STRING)
+			break;
+
+		if (g_str_equal(key, "ServerIPv4")
+				&& type == DBUS_TYPE_STRING) {
+			dbus_message_iter_get_basic(&iter, &server_ip);
+			g_print(" = %s\n", server_ip);
+
+		} else if (g_str_equal(key, "PeerIPv4")
+				&& type == DBUS_TYPE_STRING) {
+			dbus_message_iter_get_basic(&iter, &peer_ip);
+			g_print(" = %s\n", peer_ip);
+
+		} else if (g_str_equal(key, "PrimaryDNS")
+				&& type == DBUS_TYPE_STRING) {
+			dbus_message_iter_get_basic(&iter, &primary_dns);
+			g_print(" = %s\n", primary_dns);
+
+		} else if (g_str_equal(key, "SecondaryDNS")
+				&& type == DBUS_TYPE_STRING) {
+			dbus_message_iter_get_basic(&iter, &secondary_dns);
+			g_print(" = %s\n", secondary_dns);
+		}
+
+		dbus_message_iter_next(&dict);
+	}
+
+	if (server_ip == NULL || peer_ip == NULL ||
+		primary_dns == NULL || secondary_dns == NULL) {
+		ofono_error("Error while reading dictionnary...\n");
+		goto done;
+	}
+
+	ofono_emulator_setup_ppp(em, fd, server_ip, peer_ip, primary_dns,
+					secondary_dns);
+
+done:
+	g_hash_table_remove(pending_calls, &uid);
+	dbus_message_unref(reply);
+	dbus_pending_call_unref(call);
+}
+
+static int pn_get_settings(struct ofono_emulator *em)
+{
+	DBusMessage *message;
+	DBusPendingCall *call;
+
+	DBG("");
+
+	message = dbus_message_new_method_call(CONNMAN_SERVICE,
+				     CONNMAN_MANAGER_PATH,
+				     CONNMAN_MANAGER_INTERFACE,
+				     "RequestPrivateNetwork");
+
+	if (message == NULL)
+		return -ENOMEM;
+
+	if (dbus_connection_send_with_reply(connection,
+				message, &call, 5000) == FALSE) {
+		ofono_error("Error while sending message...");
+		dbus_message_unref(message);
+		return -EIO;
+	}
+
+	dbus_pending_call_set_notify(call, settings_reply,
+							em, NULL);
+
+	id++;
+	g_hash_table_insert(pending_calls, &id, call);
+
+	dbus_message_unref(message);
+
+	return id;
+}
+
+static void release_reply(DBusPendingCall *call, void *user_data)
+{
+	DBusMessage *reply;
+
+	DBG("");
+
+	reply = dbus_pending_call_steal_reply(call);
+	dbus_pending_call_unref(call);
+}
+
+static void pn_release(int uid)
+{
+	DBusMessage *message;
+	DBusPendingCall *pending;
+	DBusPendingCall *call;
+
+	DBG("");
+
+	pending = g_hash_table_lookup(pending_calls, &uid);
+	if (pending) {
+		if (dbus_pending_call_get_completed(pending) == FALSE) {
+			dbus_pending_call_cancel(pending);
+			g_hash_table_remove(pending_calls, &uid);
+			return;
+		}
+	}
+
+	message = dbus_message_new_method_call(CONNMAN_SERVICE,
+				     CONNMAN_MANAGER_PATH,
+				     CONNMAN_MANAGER_INTERFACE,
+				     "ReleasePrivateNetwork");
+
+	if (message == NULL)
+		return;
+
+	if (dbus_connection_send_with_reply(connection,
+				message, &call, 5000) == FALSE) {
+		dbus_message_unref(message);
+		return;
+	}
+
+	dbus_pending_call_set_notify(call, release_reply,
+							NULL, NULL);
+
+	dbus_message_unref(message);
+}
+
+static struct emulator_network_provision_driver pn_driver = {
+	.name		= "ConnMan Private Network",
+	.get_settings	= pn_get_settings,
+	.release	= pn_release,
+};
+
+static int connman_init(void)
+{
+	DBG("");
+
+	id = 0;
+	connection = ofono_dbus_get_connection();
+	pending_calls = g_hash_table_new(g_int_hash, g_int_equal);
+
+	return ofono_emulator_network_driver_register(&pn_driver);
+}
+
+static void connman_exit(void)
+{
+	g_hash_table_destroy(pending_calls);
+	ofono_emulator_network_driver_unregister(&pn_driver);
+}
+
+OFONO_PLUGIN_DEFINE(connman, "ConnMan plugin", VERSION,
+		OFONO_PLUGIN_PRIORITY_DEFAULT, connman_init, connman_exit)
-- 
1.7.1


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

* Re: [PATCH_v3 1/3] gatppp: Add new contructor to use external fd
  2011-05-03 14:44 ` [PATCH_v3 1/3] gatppp: Add new contructor to use external fd Guillaume Zajac
@ 2011-05-05  4:04   ` Denis Kenzior
  0 siblings, 0 replies; 9+ messages in thread
From: Denis Kenzior @ 2011-05-05  4:04 UTC (permalink / raw)
  To: ofono

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

Hi Guillaume,

On 05/03/2011 09:44 AM, Guillaume Zajac wrote:
> ---
>  gatchat/gatppp.c  |   48 ++++++++++++++++++++++++++++++++++++++++++---
>  gatchat/gatppp.h  |    1 +
>  gatchat/ppp.h     |    2 +-
>  gatchat/ppp_net.c |   55 +++++++++++++++++++++++++++++++++-------------------
>  4 files changed, 81 insertions(+), 25 deletions(-)
> 
> diff --git a/gatchat/gatppp.c b/gatchat/gatppp.c
> index 993b5ea..c7cc28b 100644
> --- a/gatchat/gatppp.c
> +++ b/gatchat/gatppp.c
> @@ -76,6 +76,7 @@ struct _GAtPPP {
>  	gpointer debug_data;
>  	gboolean sta_pending;
>  	guint ppp_dead_source;
> +	int fd;
>  };
>  
>  void ppp_debug(GAtPPP *ppp, const char *str)
> @@ -288,7 +289,7 @@ void ppp_auth_notify(GAtPPP *ppp, gboolean success)
>  void ppp_ipcp_up_notify(GAtPPP *ppp, const char *local, const char *peer,
>  					const char *dns1, const char *dns2)
>  {
> -	ppp->net = ppp_net_new(ppp);
> +	ppp->net = ppp_net_new(ppp, ppp->fd);
>  
>  	if (ppp->net == NULL) {
>  		ppp->disconnect_reason = G_AT_PPP_REASON_NET_FAIL;
> @@ -296,8 +297,14 @@ void ppp_ipcp_up_notify(GAtPPP *ppp, const char *local, const char *peer,
>  		return;
>  	}
>  
> -	if (ppp_net_set_mtu(ppp->net, ppp->mtu) == FALSE)
> -		DBG(ppp, "Unable to set MTU");
> +	/*
> +	 * If we have opened the tun interface locally,
> +	 * we have to set a MTU value.
> +	 */
> +	if (ppp->fd < 0) {
> +		if (ppp_net_set_mtu(ppp->net, ppp->mtu) == FALSE)
> +			DBG(ppp, "Unable to set MTU");
> +	}

I thought we agreed to always set the MTU?

>  
>  	ppp_enter_phase(ppp, PPP_PHASE_LINK_UP);
>  
> @@ -314,6 +321,7 @@ void ppp_ipcp_down_notify(GAtPPP *ppp)
>  		return;
>  
>  	ppp_net_free(ppp->net);
> +	ppp->fd = -1;
>  	ppp->net = NULL;
>  }
>  
> @@ -496,8 +504,13 @@ void g_at_ppp_unref(GAtPPP *ppp)
>  	g_at_io_set_disconnect_function(g_at_hdlc_get_io(ppp->hdlc),
>  						NULL, NULL);
>  
> -	if (ppp->net)
> +	if (ppp->net) {
>  		ppp_net_free(ppp->net);
> +	}
> +	else {
> +		if (ppp->fd >= 0)
> +			close(ppp->fd);
> +	}

Please make sure to follow the proper coding style, see kernel coding
style document for more details.  In this particular case the closing
brace and else should be on the same line.  Things might also be simpler
if you set ppp->fd to -1 after creating ppp_net, and this might become:

if (ppp->net)
	...
else if (ppp->fd >= 0)
	...

>  
>  	if (ppp->chap)
>  		ppp_chap_free(ppp->chap);
> @@ -541,6 +554,8 @@ static GAtPPP *ppp_init_common(GAtHDLC *hdlc, gboolean is_server, guint32 ip)
>  
>  	ppp->ref_count = 1;
>  
> +	ppp->fd = -1;
> +
>  	/* set options to defaults */
>  	ppp->mru = DEFAULT_MRU;
>  	ppp->mtu = DEFAULT_MTU;
> @@ -633,3 +648,28 @@ GAtPPP *g_at_ppp_server_new_from_io(GAtIO *io, const char *local)
>  
>  	return ppp;
>  }
> +
> +GAtPPP *g_at_ppp_server_new_full(GAtIO *io, const char *local, int fd)
> +{
> +	GAtHDLC *hdlc;
> +	GAtPPP *ppp;
> +	guint32 ip;
> +
> +	if (local == NULL)
> +		ip = 0;
> +	else if (inet_pton(AF_INET, local, &ip) != 1)
> +		return NULL;
> +
> +	hdlc = g_at_hdlc_new_from_io(io);
> +	if (hdlc == NULL)
> +		return NULL;
> +
> +	ppp = ppp_init_common(hdlc, TRUE, ip);
> +
> +	/* Set the fd value returned by ConnMan */
> +	ppp->fd = fd;
> +
> +	g_at_hdlc_unref(hdlc);
> +
> +	return ppp;
> +}
> diff --git a/gatchat/gatppp.h b/gatchat/gatppp.h
> index fb5de4c..825c022 100644
> --- a/gatchat/gatppp.h
> +++ b/gatchat/gatppp.h
> @@ -54,6 +54,7 @@ GAtPPP *g_at_ppp_new(GIOChannel *modem);
>  GAtPPP *g_at_ppp_new_from_io(GAtIO *io);
>  GAtPPP *g_at_ppp_server_new(GIOChannel *modem, const char *local);
>  GAtPPP *g_at_ppp_server_new_from_io(GAtIO *io, const char *local);
> +GAtPPP *g_at_ppp_server_new_full(GAtIO *io, const char *local, int fd);
>  
>  void g_at_ppp_open(GAtPPP *ppp);
>  void g_at_ppp_set_connect_function(GAtPPP *ppp, GAtPPPConnectFunc callback,
> diff --git a/gatchat/ppp.h b/gatchat/ppp.h
> index d2786d7..8107820 100644
> --- a/gatchat/ppp.h
> +++ b/gatchat/ppp.h
> @@ -102,7 +102,7 @@ void ppp_chap_free(struct ppp_chap *chap);
>  void ppp_chap_process_packet(struct ppp_chap *chap, const guint8 *new_packet);
>  
>  /* TUN / Network related functions */
> -struct ppp_net *ppp_net_new(GAtPPP *ppp);
> +struct ppp_net *ppp_net_new(GAtPPP *ppp, int fd);
>  const char *ppp_net_get_interface(struct ppp_net *net);
>  void ppp_net_process_packet(struct ppp_net *net, const guint8 *packet);
>  void ppp_net_free(struct ppp_net *net);
> diff --git a/gatchat/ppp_net.c b/gatchat/ppp_net.c
> index 1a6cdf7..1a56a3c 100644
> --- a/gatchat/ppp_net.c
> +++ b/gatchat/ppp_net.c
> @@ -123,12 +123,13 @@ const char *ppp_net_get_interface(struct ppp_net *net)
>  	return net->if_name;
>  }
>  
> -struct ppp_net *ppp_net_new(GAtPPP *ppp)
> +struct ppp_net *ppp_net_new(GAtPPP *ppp, int fd)
>  {
>  	struct ppp_net *net;
>  	GIOChannel *channel = NULL;
>  	struct ifreq ifr;
> -	int fd, err;
> +	int fdesc = -1;

You do realize that you can assign to fd here?  It might make the code
much simpler.

> +	int err;
>  
>  	net = g_try_new0(struct ppp_net, 1);
>  	if (net == NULL)
> @@ -140,23 +141,37 @@ struct ppp_net *ppp_net_new(GAtPPP *ppp)
>  		return NULL;
>  	}
>  
> -	/* open a tun interface */
> -	fd = open("/dev/net/tun", O_RDWR);
> -	if (fd < 0)
> -		goto error;
> -
> -	memset(&ifr, 0, sizeof(ifr));
> -	ifr.ifr_flags = IFF_TUN | IFF_NO_PI;
> -	strcpy(ifr.ifr_name, "ppp%d");
> -
> -	err = ioctl(fd, TUNSETIFF, (void *) &ifr);
> -	if (err < 0)
> -		goto error;
> -
> -	net->if_name = strdup(ifr.ifr_name);
> +	/*
> +	 * If the fd value is still the default one,
> +	 * open the tun interface and configure it.
> +	 */
> +	if (fd < 0) {
> +		/* open a tun interface */
> +		fdesc = open("/dev/net/tun", O_RDWR);
> +		if (fdesc < 0)
> +			goto error;
> +
> +		memset(&ifr, 0, sizeof(ifr));
> +		ifr.ifr_flags = IFF_TUN | IFF_NO_PI;
> +		strcpy(ifr.ifr_name, "ppp%d");
> +
> +		err = ioctl(fdesc, TUNSETIFF, (void *) &ifr);
> +		if (err < 0)
> +			goto error;
> +
> +		net->if_name = strdup(ifr.ifr_name);
> +		/* create a channel for reading and writing to this interface */
> +		channel = g_io_channel_unix_new(fdesc);
> +	} else {
> +		err = ioctl(fd, TUNGETIFF, (void *) &ifr);
> +		if (err < 0)
> +			goto error;
> +
> +		net->if_name = strdup(ifr.ifr_name);
> +		/* create a channel for reading and writing to this interface */
> +		channel = g_io_channel_unix_new(fd);
> +	}
>  
> -	/* create a channel for reading and writing to this interface */
> -	channel = g_io_channel_unix_new(fd);
>  	if (channel == NULL)
>  		goto error;
>  
> @@ -178,8 +193,8 @@ error:
>  	if (channel)
>  		g_io_channel_unref(channel);
>  
> -	if (fd >= 0)
> -		close(fd);
> +	if (fdesc >= 0)
> +		close(fdesc);
>  
>  	g_free(net->if_name);
>  	g_free(net->ppp_packet);

Regards,
-Denis

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

* Re: [PATCH_v3 2/3] emulator: add drivers to request/release private network from ConnMan
  2011-05-03 14:44 ` [PATCH_v3 2/3] emulator: add drivers to request/release private network from ConnMan Guillaume Zajac
@ 2011-05-05  4:11   ` Denis Kenzior
  2011-05-05  8:38     ` Guillaume Zajac
  0 siblings, 1 reply; 9+ messages in thread
From: Denis Kenzior @ 2011-05-05  4:11 UTC (permalink / raw)
  To: ofono

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

Hi Guillaume,

On 05/03/2011 09:44 AM, Guillaume Zajac wrote:
> ---
>  include/emulator.h |   18 +++++++++++
>  src/emulator.c     |   83 +++++++++++++++++++++++++++++++++++++++------------
>  2 files changed, 81 insertions(+), 20 deletions(-)

Please remember to separate patches according to directories whenever
possible.  See HACKING for more details.  This should be two patches,
one for include and one for emulator.

> 
> diff --git a/include/emulator.h b/include/emulator.h
> index 5cd894b..a7fc23b 100644
> --- a/include/emulator.h
> +++ b/include/emulator.h
> @@ -105,6 +105,24 @@ enum ofono_emulator_request_type ofono_emulator_request_get_type(
>  void ofono_emulator_set_indicator(struct ofono_emulator *em,
>  					const char *name, int value);
>  
> +ofono_bool_t ofono_emulator_setup_ppp(struct ofono_emulator *em, int fd,
> +				const char *server_ip, const char *peer_ip,
> +				const char *primary_dns,
> +				const char *secondary_dns);
> +
> +int ofono_emulator_get_uid(struct ofono_emulator *em);
> +

I'm not particularly happy with this, we should try to de-couple the
private network provider from the emulator.  We might end up with other
consumers later.

> +struct emulator_network_provision_driver {
> +	char *name;
> +	int (*get_settings)(struct ofono_emulator *em);
> +	void (*release)(int uid);
> +};
> +

I'd say you're on the right track here, but modeling this even closer to
gprs-provision might be a good idea.  Except you'll need to use a
callback, so something like:

struct ofono_private_network_settings {
	...
};

typedef (ofono_private_network_cb_t)(...);

struct ofono_private_network_driver {
	char *name;
	int (*request)(ofono_private_network_cb_t cb, void *data);
	void (*release)(int id);
};

> +int ofono_emulator_network_driver_register(
> +			const struct emulator_network_provision_driver *d);
> +void ofono_emulator_network_driver_unregister(
> +			const struct emulator_network_provision_driver *d);
> +

And then add __ofono_private_network_request / release to src/ofono.h
for now.  Similar to how gprs_provision does things.

>  #ifdef __cplusplus
>  }
>  #endif

Regards,
-Denis

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

* Re: [PATCH_v3 2/3] emulator: add drivers to request/release private network from ConnMan
  2011-05-05  4:11   ` Denis Kenzior
@ 2011-05-05  8:38     ` Guillaume Zajac
  2011-05-05  8:46       ` Denis Kenzior
  0 siblings, 1 reply; 9+ messages in thread
From: Guillaume Zajac @ 2011-05-05  8:38 UTC (permalink / raw)
  To: ofono

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

Hi Denis,

On 05/05/2011 06:11, Denis Kenzior wrote:
>> diff --git a/include/emulator.h b/include/emulator.h
>> index 5cd894b..a7fc23b 100644
>> --- a/include/emulator.h
>> +++ b/include/emulator.h
>> @@ -105,6 +105,24 @@ enum ofono_emulator_request_type ofono_emulator_request_get_type(
>>   void ofono_emulator_set_indicator(struct ofono_emulator *em,
>>   					const char *name, int value);
>>
>> +ofono_bool_t ofono_emulator_setup_ppp(struct ofono_emulator *em, int fd,
>> +				const char *server_ip, const char *peer_ip,
>> +				const char *primary_dns,
>> +				const char *secondary_dns);
>> +
>> +int ofono_emulator_get_uid(struct ofono_emulator *em);
>> +
> I'm not particularly happy with this, we should try to de-couple the
> private network provider from the emulator.  We might end up with other
> consumers later.
>
>> +struct emulator_network_provision_driver {
>> +	char *name;
>> +	int (*get_settings)(struct ofono_emulator *em);
>> +	void (*release)(int uid);
>> +};
>> +
> I'd say you're on the right track here, but modeling this even closer to
> gprs-provision might be a good idea.  Except you'll need to use a
> callback, so something like:
>
> struct ofono_private_network_settings {
> 	...
> };
>
> typedef (ofono_private_network_cb_t)(...);
>
> struct ofono_private_network_driver {
> 	char *name;
> 	int (*request)(ofono_private_network_cb_t cb, void *data);
> 	void (*release)(int id);
> };
>
>> +int ofono_emulator_network_driver_register(
>> +			const struct emulator_network_provision_driver *d);
>> +void ofono_emulator_network_driver_unregister(
>> +			const struct emulator_network_provision_driver *d);
>> +
> And then add __ofono_private_network_request / release to src/ofono.h
> for now.  Similar to how gprs_provision does things.

Should we add a new src into ofono that would implement those 
request/release functions and register the ofono_private_network_driver?
Something like private-network-provision.c?
Then we would have the driver and callback type definition into 
private-network-provision.h.

Kind regards,
Guillaume




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

* Re: [PATCH_v3 2/3] emulator: add drivers to request/release private network from ConnMan
  2011-05-05  8:38     ` Guillaume Zajac
@ 2011-05-05  8:46       ` Denis Kenzior
  0 siblings, 0 replies; 9+ messages in thread
From: Denis Kenzior @ 2011-05-05  8:46 UTC (permalink / raw)
  To: ofono

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

Hi Guillaume,

>>> +int ofono_emulator_network_driver_register(
>>> +            const struct emulator_network_provision_driver *d);
>>> +void ofono_emulator_network_driver_unregister(
>>> +            const struct emulator_network_provision_driver *d);
>>> +
>> And then add __ofono_private_network_request / release to src/ofono.h
>> for now.  Similar to how gprs_provision does things.
> 
> Should we add a new src into ofono that would implement those
> request/release functions and register the ofono_private_network_driver?
> Something like private-network-provision.c?
> Then we would have the driver and callback type definition into
> private-network-provision.h.
> 

Yep, I think that would be best.  Call it private-network.c for now.

Regards,
-Denis

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

end of thread, other threads:[~2011-05-05  8:46 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-05-03 14:44 [PATCH_v3 0/3] Request private network to ConnMan Guillaume Zajac
2011-05-03 14:44 ` [PATCH_v3 1/3] gatppp: Add new contructor to use external fd Guillaume Zajac
2011-05-05  4:04   ` Denis Kenzior
2011-05-03 14:44 ` [PATCH_v3 2/3] emulator: add drivers to request/release private network from ConnMan Guillaume Zajac
2011-05-05  4:11   ` Denis Kenzior
2011-05-05  8:38     ` Guillaume Zajac
2011-05-05  8:46       ` Denis Kenzior
2011-05-03 14:44 ` [PATCH_v3 3/3] connman: add plugin in oFono to request request/release private network Guillaume Zajac
2011-05-03 15:06 ` Guillaume Zajac

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.