All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH_v4 0/5] Private network request to ConnMan
@ 2011-05-06 14:01 Guillaume Zajac
  2011-05-06 14:01 ` [PATCH_v4 1/5] gatppp: Add new contructor to use external fd Guillaume Zajac
                   ` (6 more replies)
  0 siblings, 7 replies; 13+ messages in thread
From: Guillaume Zajac @ 2011-05-06 14:01 UTC (permalink / raw)
  To: ofono

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

Hi,

Changelog from v3 is:
	- Add private-network source/include
	- ConnMan plugin is independant from emulator
	- Each application that need VPN will pass a callback as argument
	  when private network is requested. This callback will contain the
	  private network settings.

Guillaume Zajac (5):
  gatppp: Add new contructor to use external fd
  private-network: add callback typedef drivers and settings
  private-network: add request/release functions and new feature to
    Makefile.am
  emulator: add request/release private network calls
  connman: add plugin in oFono to request request/release private
    network

 Makefile.am               |   10 +-
 gatchat/gatppp.c          |   33 +++++-
 gatchat/gatppp.h          |    1 +
 gatchat/ppp.h             |    2 +-
 gatchat/ppp_net.c         |   40 ++++---
 include/private-network.h |   59 +++++++++
 plugins/connman.c         |  297 +++++++++++++++++++++++++++++++++++++++++++++
 src/emulator.c            |   49 ++++++--
 src/ofono.h               |    6 +
 src/private-network.c     |   89 ++++++++++++++
 10 files changed, 556 insertions(+), 30 deletions(-)
 create mode 100644 include/private-network.h
 create mode 100644 plugins/connman.c
 create mode 100644 src/private-network.c


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

* [PATCH_v4 1/5] gatppp: Add new contructor to use external fd
  2011-05-06 14:01 [PATCH_v4 0/5] Private network request to ConnMan Guillaume Zajac
@ 2011-05-06 14:01 ` Guillaume Zajac
  2011-05-09  4:44   ` Denis Kenzior
  2011-05-06 14:01 ` [PATCH_v4 2/5] private-network: add callback typedef drivers and settings Guillaume Zajac
                   ` (5 subsequent siblings)
  6 siblings, 1 reply; 13+ messages in thread
From: Guillaume Zajac @ 2011-05-06 14:01 UTC (permalink / raw)
  To: ofono

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

---
 gatchat/gatppp.c  |   33 ++++++++++++++++++++++++++++++++-
 gatchat/gatppp.h  |    1 +
 gatchat/ppp.h     |    2 +-
 gatchat/ppp_net.c |   40 +++++++++++++++++++++++++---------------
 4 files changed, 59 insertions(+), 17 deletions(-)

diff --git a/gatchat/gatppp.c b/gatchat/gatppp.c
index 993b5ea..c4cad90 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;
@@ -314,6 +315,7 @@ void ppp_ipcp_down_notify(GAtPPP *ppp)
 		return;
 
 	ppp_net_free(ppp->net);
+	ppp->fd = -1;
 	ppp->net = NULL;
 }
 
@@ -498,6 +500,8 @@ void g_at_ppp_unref(GAtPPP *ppp)
 
 	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 +545,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 +639,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..0f25299 100644
--- a/gatchat/ppp_net.c
+++ b/gatchat/ppp_net.c
@@ -123,12 +123,12 @@ 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 err;
 
 	net = g_try_new0(struct ppp_net, 1);
 	if (net == NULL)
@@ -140,23 +140,33 @@ 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;
+	/*
+	 * If the fd value is still the default one,
+	 * open the tun interface and configure it.
+	 */
+	if (fd < 0) {
+		/* 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;
+	} 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);
+
 	if (channel == NULL)
 		goto error;
 
-- 
1.7.1


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

* [PATCH_v4 2/5] private-network: add callback typedef drivers and settings
  2011-05-06 14:01 [PATCH_v4 0/5] Private network request to ConnMan Guillaume Zajac
  2011-05-06 14:01 ` [PATCH_v4 1/5] gatppp: Add new contructor to use external fd Guillaume Zajac
@ 2011-05-06 14:01 ` Guillaume Zajac
  2011-05-09  4:48   ` Denis Kenzior
  2011-05-06 14:01 ` [PATCH_v4 3/5] private-network: add request/release functions and new feature to Makefile.am Guillaume Zajac
                   ` (4 subsequent siblings)
  6 siblings, 1 reply; 13+ messages in thread
From: Guillaume Zajac @ 2011-05-06 14:01 UTC (permalink / raw)
  To: ofono

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

---
 include/private-network.h |   59 +++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 59 insertions(+), 0 deletions(-)
 create mode 100644 include/private-network.h

diff --git a/include/private-network.h b/include/private-network.h
new file mode 100644
index 0000000..ba84a36
--- /dev/null
+++ b/include/private-network.h
@@ -0,0 +1,59 @@
+/*
+ *
+ *  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
+ *
+ */
+
+
+#ifndef __OFONO_PRIVATE_NETWORK_H
+#define __OFONO_PRIVATE_NETWORK_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <glib.h>
+
+struct ofono_private_network_settings {
+	int fd;
+	const char *server_ip;
+	const char *peer_ip;
+	const char *primary_dns;
+	const char *secondary_dns;
+};
+
+
+typedef gboolean (ofono_private_network_cb_t)(
+		void *data, struct ofono_private_network_settings *settings);
+
+struct ofono_private_network_driver {
+	char *name;
+	int (*request)(ofono_private_network_cb_t cb, void *data);
+	void (*release)(int uid);
+};
+
+int ofono_private_network_driver_register(
+			const struct ofono_private_network_driver *d);
+void ofono_private_network_driver_unregister(
+			const struct ofono_private_network_driver *d);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __OFONO_PRIVATE_NETWORK_H */
-- 
1.7.1


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

* [PATCH_v4 3/5] private-network: add request/release functions and new feature to Makefile.am
  2011-05-06 14:01 [PATCH_v4 0/5] Private network request to ConnMan Guillaume Zajac
  2011-05-06 14:01 ` [PATCH_v4 1/5] gatppp: Add new contructor to use external fd Guillaume Zajac
  2011-05-06 14:01 ` [PATCH_v4 2/5] private-network: add callback typedef drivers and settings Guillaume Zajac
@ 2011-05-06 14:01 ` Guillaume Zajac
  2011-05-09  4:52   ` Denis Kenzior
  2011-05-06 14:01 ` [PATCH_v4 4/5] emulator: add request/release private network calls Guillaume Zajac
                   ` (3 subsequent siblings)
  6 siblings, 1 reply; 13+ messages in thread
From: Guillaume Zajac @ 2011-05-06 14:01 UTC (permalink / raw)
  To: ofono

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

---
 Makefile.am           |    7 ++--
 src/ofono.h           |    6 +++
 src/private-network.c |   89 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 99 insertions(+), 3 deletions(-)
 create mode 100644 src/private-network.c

diff --git a/Makefile.am b/Makefile.am
index a413a47..e1eaf15 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -16,8 +16,8 @@ pkginclude_HEADERS = include/log.h include/plugin.h include/history.h \
 			include/cdma-sms.h include/sim-auth.h \
 			include/gprs-provision.h include/emulator.h \
 			include/location-reporting.h \
-			include/cdma-connman.h \
-			include/gnss.h
+			include/cdma-connman.h include/gnss.h \
+			include/private-network.h
 
 nodist_pkginclude_HEADERS = include/version.h
 
@@ -387,7 +387,8 @@ src_ofonod_SOURCES = $(gdbus_sources) $(builtin_sources) src/ofono.ver \
 			src/message.h src/message.c src/gprs-provision.c \
 			src/emulator.c src/location-reporting.c \
 			src/cdma-connman.c src/gnss.c \
-			src/gnssagent.c src/gnssagent.h
+			src/gnssagent.c src/gnssagent.h \
+			src/private-network.c
 
 src_ofonod_LDADD = $(builtin_libadd) @GLIB_LIBS@ @DBUS_LIBS@ @CAPNG_LIBS@ -ldl
 
diff --git a/src/ofono.h b/src/ofono.h
index 82d7e34..7353022 100644
--- a/src/ofono.h
+++ b/src/ofono.h
@@ -468,3 +468,9 @@ void __ofono_gprs_provision_free_settings(
 
 #include <ofono/emulator.h>
 #include <ofono/gnss.h>
+#include <ofono/private-network.h>
+
+void __ofono_private_network_release(int id);
+ofono_bool_t __ofono_private_network_request(ofono_private_network_cb_t cb,
+						void *data, int *id);
+
diff --git a/src/private-network.c b/src/private-network.c
new file mode 100644
index 0000000..03204a5
--- /dev/null
+++ b/src/private-network.c
@@ -0,0 +1,89 @@
+/*
+ *
+ *  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 <string.h>
+#include <glib.h>
+#include "ofono.h"
+
+static GSList *g_drivers = NULL;
+
+void __ofono_private_network_release(int id)
+{
+	GSList *d;
+
+	DBG("");
+
+	for (d = g_drivers; d; d = d->next) {
+		const struct ofono_private_network_driver *driver = d->data;
+
+		if (g_strcmp0(driver->name, "ConnMan Private Network"))
+			continue;
+
+		driver->release(id);
+
+		break;
+	}
+}
+
+ofono_bool_t __ofono_private_network_request(ofono_private_network_cb_t cb,
+						void *data, int *id)
+{
+	GSList *d;
+
+	DBG("");
+
+	for (d = g_drivers; d; d = d->next) {
+		const struct ofono_private_network_driver *driver = d->data;
+
+		if (g_strcmp0(driver->name, "ConnMan Private Network"))
+			continue;
+
+		*id = driver->request(cb, data);
+		if (*id < 0)
+			continue;
+
+		return TRUE;
+	}
+
+	return FALSE;
+}
+
+int ofono_private_network_driver_register(
+			const struct ofono_private_network_driver *d)
+{
+	DBG("driver: %p, name: %s", d, d->name);
+
+	g_drivers = g_slist_prepend(g_drivers, (void *) d);
+
+	return 0;
+}
+
+void ofono_private_network_driver_unregister(
+			const struct ofono_private_network_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] 13+ messages in thread

* [PATCH_v4 4/5] emulator: add request/release private network calls
  2011-05-06 14:01 [PATCH_v4 0/5] Private network request to ConnMan Guillaume Zajac
                   ` (2 preceding siblings ...)
  2011-05-06 14:01 ` [PATCH_v4 3/5] private-network: add request/release functions and new feature to Makefile.am Guillaume Zajac
@ 2011-05-06 14:01 ` Guillaume Zajac
  2011-05-06 14:01 ` [PATCH_v4 5/5] connman: add plugin in oFono to request request/release private network Guillaume Zajac
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 13+ messages in thread
From: Guillaume Zajac @ 2011-05-06 14:01 UTC (permalink / raw)
  To: ofono

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

---
 src/emulator.c |   49 +++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 39 insertions(+), 10 deletions(-)

diff --git a/src/emulator.c b/src/emulator.c
index 9055909..d6b2b1b 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>
 
@@ -32,11 +33,7 @@
 #include "common.h"
 #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"
+#include "private-network.h"
 
 #define RING_TIMEOUT 3
 
@@ -55,6 +52,8 @@ struct ofono_emulator {
 	guint callsetup_source;
 	gboolean clip;
 	gboolean ccwa;
+	int pns_id;
+	struct ofono_private_network_settings *pns;
 };
 
 struct indicator {
@@ -99,6 +98,11 @@ static void ppp_disconnect(GAtPPPDisconnectReason reason, gpointer user_data)
 	g_at_ppp_unref(em->ppp);
 	em->ppp = NULL;
 
+	if (em->pns_id > 0)
+		__ofono_private_network_release(em->pns_id);
+
+	em->pns_id = -1;
+
 	if (em->server == NULL)
 		return;
 
@@ -118,14 +122,19 @@ static gboolean setup_ppp(gpointer user_data)
 
 	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, em->pns->server_ip, em->pns->fd);
 	if (em->ppp == NULL) {
+		close(em->pns->fd);
+		if (em->pns_id > 0)
+			__ofono_private_network_release(em->pns_id);
+		em->pns_id = -1;
 		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, em->pns->peer_ip,
+					em->pns->primary_dns,
+					em->pns->secondary_dns);
 
 	g_at_ppp_set_credentials(em->ppp, "", "");
 	g_at_ppp_set_debug(em->ppp, emulator_debug, "PPP");
@@ -136,6 +145,24 @@ static gboolean setup_ppp(gpointer user_data)
 	return FALSE;
 }
 
+static gboolean setup_ppp_cb(void *data,
+				struct ofono_private_network_settings *pns)
+{
+	struct ofono_emulator *em = data;
+
+	if (pns == NULL) {
+		__ofono_private_network_release(em->pns_id);
+		g_at_server_send_final(em->server, G_AT_SERVER_RESULT_ERROR);
+		return FALSE;
+	}
+
+	em->pns = pns;
+	g_at_server_send_intermediate(em->server, "CONNECT");
+	em->source = g_idle_add(setup_ppp, em);
+
+	return TRUE;
+}
+
 static gboolean dial_call(struct ofono_emulator *em, const char *dial_str)
 {
 	char c = *dial_str;
@@ -143,8 +170,9 @@ 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 (__ofono_private_network_request(setup_ppp_cb, em,
+							&em->pns_id) == FALSE)
+			return FALSE;
 	}
 
 	return TRUE;
@@ -707,6 +735,7 @@ struct ofono_emulator *ofono_emulator_create(struct ofono_modem *modem,
 	/* TODO: Check real local features */
 	em->l_features = 32;
 	em->events_mode = 3;	/* default mode is forwarding events */
+	em->pns_id = -1;
 
 	em->atom = __ofono_modem_add_atom_offline(modem, atom_t,
 							emulator_remove, em);
-- 
1.7.1


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

* [PATCH_v4 5/5] connman: add plugin in oFono to request request/release private network
  2011-05-06 14:01 [PATCH_v4 0/5] Private network request to ConnMan Guillaume Zajac
                   ` (3 preceding siblings ...)
  2011-05-06 14:01 ` [PATCH_v4 4/5] emulator: add request/release private network calls Guillaume Zajac
@ 2011-05-06 14:01 ` Guillaume Zajac
  2011-05-09  5:30   ` Denis Kenzior
  2021-06-03 10:22 ` [PATCH_v4 0/5] Private network request to ConnMan adamsmith.87
  2021-07-21 19:49 ` Kaylee Brown
  6 siblings, 1 reply; 13+ messages in thread
From: Guillaume Zajac @ 2011-05-06 14:01 UTC (permalink / raw)
  To: ofono

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

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

diff --git a/Makefile.am b/Makefile.am
index e1eaf15..ffb85ae 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..cfc1721
--- /dev/null
+++ b/plugins/connman.c
@@ -0,0 +1,297 @@
+/*
+ *
+ *  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 <private-network.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 *requests;
+static unsigned int id;
+
+struct pns_req {
+	int uid;
+	DBusPendingCall *pending;
+	struct ofono_private_network_settings *pns;
+	ofono_private_network_cb_t *cb;
+	void *data;
+};
+
+static void request_reply(DBusPendingCall *call, void *user_data)
+{
+	struct pns_req *req = user_data;
+	struct ofono_private_network_settings *pns;
+	DBusMessageIter array, dict, entry;
+	DBusMessage *reply;
+
+	DBG("");
+
+	req->pending = NULL;
+	reply = dbus_pending_call_steal_reply(call);
+	if (!reply)
+		goto error;
+
+	pns = g_try_new0(struct ofono_private_network_settings, 1);
+	if (pns == NULL)
+		goto error;
+
+	if (dbus_message_iter_init(reply, &array) == FALSE)
+		goto error;
+
+	if (dbus_message_iter_get_arg_type(&array) != DBUS_TYPE_UNIX_FD)
+		goto error;
+
+	dbus_message_iter_get_basic(&array, &pns->fd);
+	DBG("Fildescriptor = %d\n", pns->fd);
+
+	dbus_message_iter_next(&array);
+
+	if (dbus_message_iter_get_arg_type(&array) != DBUS_TYPE_ARRAY)
+		goto error;
+
+	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);
+
+		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, &pns->server_ip);
+
+		} else if (g_str_equal(key, "PeerIPv4")
+				&& type == DBUS_TYPE_STRING) {
+			dbus_message_iter_get_basic(&iter, &pns->peer_ip);
+
+		} else if (g_str_equal(key, "PrimaryDNS")
+				&& type == DBUS_TYPE_STRING) {
+			dbus_message_iter_get_basic(&iter, &pns->primary_dns);
+
+		} else if (g_str_equal(key, "SecondaryDNS")
+				&& type == DBUS_TYPE_STRING) {
+			dbus_message_iter_get_basic(&iter, &pns->secondary_dns);
+		}
+
+		dbus_message_iter_next(&dict);
+	}
+
+	req->pns = pns;
+	if (pns->server_ip == NULL || pns->peer_ip == NULL ||
+		pns->primary_dns == NULL || pns->secondary_dns == NULL ||
+		pns->fd < 0) {
+		ofono_error("Error while reading dictionnary...\n");
+		goto error;
+	}
+
+	req->cb(req->data, req->pns);
+
+	dbus_message_unref(reply);
+	dbus_pending_call_unref(call);
+
+	return;
+
+error:
+	req->cb(req->data, NULL);
+	if (reply)
+		dbus_message_unref(reply);
+
+	dbus_pending_call_unref(call);
+}
+
+static int pns_request(ofono_private_network_cb_t cb, void *data)
+{
+	DBusMessage *message;
+	DBusPendingCall *call;
+	struct pns_req *req;
+
+	DBG("");
+
+	req = g_try_new0(struct pns_req, 1);
+
+	if (req == NULL)
+		return -ENOMEM;
+
+	message = dbus_message_new_method_call(CONNMAN_SERVICE,
+				     CONNMAN_MANAGER_PATH,
+				     CONNMAN_MANAGER_INTERFACE,
+				     "RequestPrivateNetwork");
+
+	if (message == NULL) {
+		g_free(req);
+		return -ENOMEM;
+	}
+
+	if (dbus_connection_send_with_reply(connection,
+				message, &call, 5000) == FALSE) {
+		g_free(req);
+		dbus_message_unref(message);
+		return -EIO;
+	}
+
+	id++;
+	req->pending = call;
+	req->cb = cb;
+	req->data = data;
+	req->uid = id;
+
+	dbus_pending_call_set_notify(call, request_reply,
+							req, NULL);
+	g_hash_table_insert(requests, &req->uid, req);
+	dbus_message_unref(message);
+
+	return req->uid;
+}
+
+static void release_reply(DBusPendingCall *call, void *user_data)
+{
+	DBusMessage *reply;
+	struct pns_req *req = user_data;
+
+	DBG("");
+
+	reply = dbus_pending_call_steal_reply(call);
+	g_hash_table_remove(requests, &req->uid);
+	if (req->pns)
+		g_free(req->pns);
+
+	g_free(req);
+	if (reply)
+		dbus_message_unref(reply);
+
+	dbus_pending_call_unref(call);
+}
+
+static void pns_release(int uid)
+{
+	DBusMessage *message = NULL;
+	struct pns_req *req;
+	DBusPendingCall *call;
+
+	DBG("");
+
+	req = g_hash_table_lookup(requests, &uid);
+	if (!req)
+		return;
+
+	if (req->pending) {
+		if (dbus_pending_call_get_completed(req->pending) == FALSE) {
+			dbus_pending_call_cancel(req->pending);
+			g_hash_table_remove(requests, &uid);
+			g_free(req);
+			return;
+		}
+	}
+
+	message = dbus_message_new_method_call(CONNMAN_SERVICE,
+				     CONNMAN_MANAGER_PATH,
+				     CONNMAN_MANAGER_INTERFACE,
+				     "ReleasePrivateNetwork");
+
+	if (message == NULL)
+		goto error;
+
+	if (dbus_connection_send_with_reply(connection,
+				message, &call, 5000) == FALSE)
+		goto error;
+
+	dbus_pending_call_set_notify(call, release_reply,
+							req, NULL);
+	dbus_message_unref(message);
+	
+	return;
+
+error:
+	if (message)
+		dbus_message_unref(message);
+
+	g_hash_table_remove(requests, &req->uid);
+	if (req->pns)
+		g_free(req->pns);
+
+	g_free(req);
+}
+
+static struct ofono_private_network_driver pn_driver = {
+	.name		= "ConnMan Private Network",
+	.request	= pns_request,
+	.release	= pns_release,
+};
+
+static int connman_init(void)
+{
+	DBG("");
+
+	id = 0;
+	connection = ofono_dbus_get_connection();
+	requests = g_hash_table_new(g_int_hash, g_int_equal);
+
+	return ofono_private_network_driver_register(&pn_driver);
+}
+
+static void connman_exit(void)
+{
+	g_hash_table_destroy(requests);
+	ofono_private_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] 13+ messages in thread

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

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

Hi Guillaume,

On 05/06/2011 09:01 AM, Guillaume Zajac wrote:
> ---
>  gatchat/gatppp.c  |   33 ++++++++++++++++++++++++++++++++-
>  gatchat/gatppp.h  |    1 +
>  gatchat/ppp.h     |    2 +-
>  gatchat/ppp_net.c |   40 +++++++++++++++++++++++++---------------
>  4 files changed, 59 insertions(+), 17 deletions(-)
> 
> diff --git a/gatchat/gatppp.c b/gatchat/gatppp.c
> index 993b5ea..c4cad90 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);

So please be careful here, you're passing in the file descriptor and you
do not establish a clear ownership of it.  Is ppp_net_new responsible to
close the fd in all cases?  Right now there are error cases (e.g.
ppp_net_new returns NULL) in which the fd is closed and others where it
is not.  You have to be extra paranoid when writing a library and make
sure every case has been thought through.

>  
>  	if (ppp->net == NULL) {
>  		ppp->disconnect_reason = G_AT_PPP_REASON_NET_FAIL;
> @@ -314,6 +315,7 @@ void ppp_ipcp_down_notify(GAtPPP *ppp)
>  		return;
>  
>  	ppp_net_free(ppp->net);
> +	ppp->fd = -1;
>  	ppp->net = NULL;
>  }
>  
> @@ -498,6 +500,8 @@ void g_at_ppp_unref(GAtPPP *ppp)
>  
>  	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 +545,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 +639,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..0f25299 100644
> --- a/gatchat/ppp_net.c
> +++ b/gatchat/ppp_net.c
> @@ -123,12 +123,12 @@ 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 err;
>  
>  	net = g_try_new0(struct ppp_net, 1);
>  	if (net == NULL)
> @@ -140,23 +140,33 @@ 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;
> +	/*
> +	 * If the fd value is still the default one,
> +	 * open the tun interface and configure it.
> +	 */
> +	if (fd < 0) {
> +		/* 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;
> +	} else {
> +		err = ioctl(fd, TUNGETIFF, (void *) &ifr);
> +		if (err < 0)
> +			goto error;
> +	}
>  
>  	net->if_name = strdup(ifr.ifr_name);
> -

Please avoid such changes.  Resist the urge to change formatting or
white-spacing when submitting feature patches.  Send a separate patch,
otherwise it confuses the reviewer.

Please note that in this particular case the original formatting is the
preferred style already.

>  	/* create a channel for reading and writing to this interface */
>  	channel = g_io_channel_unix_new(fd);
> +
>  	if (channel == NULL)
>  		goto error;
>  

Regards,
-Denis

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

* Re: [PATCH_v4 2/5] private-network: add callback typedef drivers and settings
  2011-05-06 14:01 ` [PATCH_v4 2/5] private-network: add callback typedef drivers and settings Guillaume Zajac
@ 2011-05-09  4:48   ` Denis Kenzior
  0 siblings, 0 replies; 13+ messages in thread
From: Denis Kenzior @ 2011-05-09  4:48 UTC (permalink / raw)
  To: ofono

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

Hi Guillaume,

On 05/06/2011 09:01 AM, Guillaume Zajac wrote:
> ---
>  include/private-network.h |   59 +++++++++++++++++++++++++++++++++++++++++++++
>  1 files changed, 59 insertions(+), 0 deletions(-)
>  create mode 100644 include/private-network.h
> 

You also need to include this file into the build system, so changes to
Makefile.am should be included here as well.

> diff --git a/include/private-network.h b/include/private-network.h
> new file mode 100644
> index 0000000..ba84a36
> --- /dev/null
> +++ b/include/private-network.h
> @@ -0,0 +1,59 @@
> +/*
> + *
> + *  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
> + *
> + */
> +
> +

Why the double newline?

> +#ifndef __OFONO_PRIVATE_NETWORK_H
> +#define __OFONO_PRIVATE_NETWORK_H
> +
> +#ifdef __cplusplus
> +extern "C" {
> +#endif
> +
> +#include <glib.h>

One of the rules of writing oFono public APIs (e.g. files under include)
is that they should use native C types.  Do not ever use glib types here.

> +
> +struct ofono_private_network_settings {
> +	int fd;
> +	const char *server_ip;
> +	const char *peer_ip;
> +	const char *primary_dns;
> +	const char *secondary_dns;
> +};
> +
> +

Why the double newline?

> +typedef gboolean (ofono_private_network_cb_t)(
> +		void *data, struct ofono_private_network_settings *settings);

What is the purpose of the gboolean return value in this callback?

> +
> +struct ofono_private_network_driver {
> +	char *name;
> +	int (*request)(ofono_private_network_cb_t cb, void *data);
> +	void (*release)(int uid);
> +};
> +
> +int ofono_private_network_driver_register(
> +			const struct ofono_private_network_driver *d);
> +void ofono_private_network_driver_unregister(
> +			const struct ofono_private_network_driver *d);
> +
> +#ifdef __cplusplus
> +}
> +#endif
> +
> +#endif /* __OFONO_PRIVATE_NETWORK_H */

Regards,
-Denis

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

* Re: [PATCH_v4 3/5] private-network: add request/release functions and new feature to Makefile.am
  2011-05-06 14:01 ` [PATCH_v4 3/5] private-network: add request/release functions and new feature to Makefile.am Guillaume Zajac
@ 2011-05-09  4:52   ` Denis Kenzior
  0 siblings, 0 replies; 13+ messages in thread
From: Denis Kenzior @ 2011-05-09  4:52 UTC (permalink / raw)
  To: ofono

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

Hi Guillaume,

On 05/06/2011 09:01 AM, Guillaume Zajac wrote:
> ---
>  Makefile.am           |    7 ++--
>  src/ofono.h           |    6 +++
>  src/private-network.c |   89 +++++++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 99 insertions(+), 3 deletions(-)
>  create mode 100644 src/private-network.c
> 
> diff --git a/Makefile.am b/Makefile.am
> index a413a47..e1eaf15 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -16,8 +16,8 @@ pkginclude_HEADERS = include/log.h include/plugin.h include/history.h \
>  			include/cdma-sms.h include/sim-auth.h \
>  			include/gprs-provision.h include/emulator.h \
>  			include/location-reporting.h \
> -			include/cdma-connman.h \
> -			include/gnss.h
> +			include/cdma-connman.h include/gnss.h \
> +			include/private-network.h

As mentioned previously, this one belongs in the previous commit.

>  
>  nodist_pkginclude_HEADERS = include/version.h
>  
> @@ -387,7 +387,8 @@ src_ofonod_SOURCES = $(gdbus_sources) $(builtin_sources) src/ofono.ver \
>  			src/message.h src/message.c src/gprs-provision.c \
>  			src/emulator.c src/location-reporting.c \
>  			src/cdma-connman.c src/gnss.c \
> -			src/gnssagent.c src/gnssagent.h
> +			src/gnssagent.c src/gnssagent.h \
> +			src/private-network.c
>  
>  src_ofonod_LDADD = $(builtin_libadd) @GLIB_LIBS@ @DBUS_LIBS@ @CAPNG_LIBS@ -ldl
>  
> diff --git a/src/ofono.h b/src/ofono.h
> index 82d7e34..7353022 100644
> --- a/src/ofono.h
> +++ b/src/ofono.h
> @@ -468,3 +468,9 @@ void __ofono_gprs_provision_free_settings(
>  
>  #include <ofono/emulator.h>
>  #include <ofono/gnss.h>
> +#include <ofono/private-network.h>
> +
> +void __ofono_private_network_release(int id);
> +ofono_bool_t __ofono_private_network_request(ofono_private_network_cb_t cb,
> +						void *data, int *id);
> +
> diff --git a/src/private-network.c b/src/private-network.c
> new file mode 100644
> index 0000000..03204a5
> --- /dev/null
> +++ b/src/private-network.c
> @@ -0,0 +1,89 @@
> +/*
> + *
> + *  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 <string.h>
> +#include <glib.h>
> +#include "ofono.h"
> +
> +static GSList *g_drivers = NULL;
> +
> +void __ofono_private_network_release(int id)
> +{
> +	GSList *d;
> +
> +	DBG("");
> +
> +	for (d = g_drivers; d; d = d->next) {
> +		const struct ofono_private_network_driver *driver = d->data;
> +
> +		if (g_strcmp0(driver->name, "ConnMan Private Network"))
> +			continue;
> +

What exactly is the purpose of the above statement?  Also, for now I'd
just assume that you can only ever have a single private network driver
to make things simpler.

> +		driver->release(id);
> +
> +		break;
> +	}
> +}
> +
> +ofono_bool_t __ofono_private_network_request(ofono_private_network_cb_t cb,
> +						void *data, int *id)
> +{
> +	GSList *d;
> +
> +	DBG("");
> +
> +	for (d = g_drivers; d; d = d->next) {
> +		const struct ofono_private_network_driver *driver = d->data;
> +
> +		if (g_strcmp0(driver->name, "ConnMan Private Network"))
> +			continue;
> +
> +		*id = driver->request(cb, data);

In general it is good form not to assign to an out variable unless the
function returns successfully.

> +		if (*id < 0)
> +			continue;

You might want to always return > 0 for successful cases, and leave 0 as
a sentinel value.

> +
> +		return TRUE;
> +	}
> +
> +	return FALSE;
> +}
> +
> +int ofono_private_network_driver_register(
> +			const struct ofono_private_network_driver *d)
> +{
> +	DBG("driver: %p, name: %s", d, d->name);
> +
> +	g_drivers = g_slist_prepend(g_drivers, (void *) d);
> +
> +	return 0;
> +}
> +
> +void ofono_private_network_driver_unregister(
> +			const struct ofono_private_network_driver *d)
> +{
> +	DBG("driver: %p, name: %s", d, d->name);
> +
> +	g_drivers = g_slist_remove(g_drivers, (void *) d);
> +}

Regards,
-Denis

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

* Re: [PATCH_v4 5/5] connman: add plugin in oFono to request request/release private network
  2011-05-06 14:01 ` [PATCH_v4 5/5] connman: add plugin in oFono to request request/release private network Guillaume Zajac
@ 2011-05-09  5:30   ` Denis Kenzior
  0 siblings, 0 replies; 13+ messages in thread
From: Denis Kenzior @ 2011-05-09  5:30 UTC (permalink / raw)
  To: ofono

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

Hi Guillaume,

On 05/06/2011 09:01 AM, Guillaume Zajac wrote:
> ---
>  Makefile.am       |    3 +
>  plugins/connman.c |  297 +++++++++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 300 insertions(+), 0 deletions(-)
>  create mode 100644 plugins/connman.c
> 
> diff --git a/Makefile.am b/Makefile.am
> index e1eaf15..ffb85ae 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..cfc1721
> --- /dev/null
> +++ b/plugins/connman.c
> @@ -0,0 +1,297 @@
> +/*
> + *
> + *  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 <private-network.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 *requests;
> +static unsigned int id;
> +
> +struct pns_req {
> +	int uid;
> +	DBusPendingCall *pending;
> +	struct ofono_private_network_settings *pns;
> +	ofono_private_network_cb_t *cb;
> +	void *data;
> +};
> +
> +static void request_reply(DBusPendingCall *call, void *user_data)
> +{
> +	struct pns_req *req = user_data;
> +	struct ofono_private_network_settings *pns;
> +	DBusMessageIter array, dict, entry;
> +	DBusMessage *reply;
> +
> +	DBG("");
> +
> +	req->pending = NULL;
> +	reply = dbus_pending_call_steal_reply(call);
> +	if (!reply)
> +		goto error;
> +
> +	pns = g_try_new0(struct ofono_private_network_settings, 1);
> +	if (pns == NULL)
> +		goto error;

I question the need to allocate this structure here.  Why can't you
create it on the stack?  Are you trying to keep this structure around so
that the caller can reference its members ?  If so, please don't, it
won't work out.  All pointers you extract from the message will be gone
(*poof*) when you call dbus_message_unref.  If the caller needs to save
the information it receives in the callback, then it should copy the
memory and manage it appropriately.  This is why most oFono callback
definitions use const structures, to avoid this temptation ;)

> +
> +	if (dbus_message_iter_init(reply, &array) == FALSE)
> +		goto error;
> +
> +	if (dbus_message_iter_get_arg_type(&array) != DBUS_TYPE_UNIX_FD)
> +		goto error;
> +
> +	dbus_message_iter_get_basic(&array, &pns->fd);
> +	DBG("Fildescriptor = %d\n", pns->fd);
> +
> +	dbus_message_iter_next(&array);
> +
> +	if (dbus_message_iter_get_arg_type(&array) != DBUS_TYPE_ARRAY)
> +		goto error;
> +
> +	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);
> +
> +		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, &pns->server_ip);
> +
> +		} else if (g_str_equal(key, "PeerIPv4")
> +				&& type == DBUS_TYPE_STRING) {
> +			dbus_message_iter_get_basic(&iter, &pns->peer_ip);
> +
> +		} else if (g_str_equal(key, "PrimaryDNS")
> +				&& type == DBUS_TYPE_STRING) {
> +			dbus_message_iter_get_basic(&iter, &pns->primary_dns);
> +
> +		} else if (g_str_equal(key, "SecondaryDNS")
> +				&& type == DBUS_TYPE_STRING) {
> +			dbus_message_iter_get_basic(&iter, &pns->secondary_dns);
> +		}
> +
> +		dbus_message_iter_next(&dict);
> +	}
> +
> +	req->pns = pns;
> +	if (pns->server_ip == NULL || pns->peer_ip == NULL ||
> +		pns->primary_dns == NULL || pns->secondary_dns == NULL ||
> +		pns->fd < 0) {

doc/coding-style.txt item M4

> +		ofono_error("Error while reading dictionnary...\n");
> +		goto error;
> +	}
> +
> +	req->cb(req->data, req->pns);
> +
> +	dbus_message_unref(reply);
> +	dbus_pending_call_unref(call);
> +
> +	return;
> +
> +error:
> +	req->cb(req->data, NULL);
> +	if (reply)
> +		dbus_message_unref(reply);
> +
> +	dbus_pending_call_unref(call);
> +}
> +
> +static int pns_request(ofono_private_network_cb_t cb, void *data)
> +{
> +	DBusMessage *message;
> +	DBusPendingCall *call;
> +	struct pns_req *req;
> +
> +	DBG("");
> +
> +	req = g_try_new0(struct pns_req, 1);
> +
> +	if (req == NULL)
> +		return -ENOMEM;
> +
> +	message = dbus_message_new_method_call(CONNMAN_SERVICE,
> +				     CONNMAN_MANAGER_PATH,
> +				     CONNMAN_MANAGER_INTERFACE,
> +				     "RequestPrivateNetwork");
> +
> +	if (message == NULL) {
> +		g_free(req);
> +		return -ENOMEM;
> +	}
> +
> +	if (dbus_connection_send_with_reply(connection,
> +				message, &call, 5000) == FALSE) {
> +		g_free(req);
> +		dbus_message_unref(message);
> +		return -EIO;
> +	}
> +
> +	id++;
> +	req->pending = call;
> +	req->cb = cb;
> +	req->data = data;
> +	req->uid = id;
> +
> +	dbus_pending_call_set_notify(call, request_reply,
> +							req, NULL);
> +	g_hash_table_insert(requests, &req->uid, req);
> +	dbus_message_unref(message);
> +
> +	return req->uid;
> +}
> +
> +static void release_reply(DBusPendingCall *call, void *user_data)
> +{
> +	DBusMessage *reply;
> +	struct pns_req *req = user_data;
> +
> +	DBG("");
> +
> +	reply = dbus_pending_call_steal_reply(call);
> +	g_hash_table_remove(requests, &req->uid);
> +	if (req->pns)
> +		g_free(req->pns);
> +
> +	g_free(req);
> +	if (reply)
> +		dbus_message_unref(reply);
> +
> +	dbus_pending_call_unref(call);
> +}
> +
> +static void pns_release(int uid)
> +{
> +	DBusMessage *message = NULL;
> +	struct pns_req *req;
> +	DBusPendingCall *call;
> +
> +	DBG("");
> +
> +	req = g_hash_table_lookup(requests, &uid);
> +	if (!req)
> +		return;
> +
> +	if (req->pending) {
> +		if (dbus_pending_call_get_completed(req->pending) == FALSE) {
> +			dbus_pending_call_cancel(req->pending);
> +			g_hash_table_remove(requests, &uid);
> +			g_free(req);
> +			return;
> +		}

Unfortunately things are not that easy.  If you have a pending request,
then you can't simply use pending_call_cancel on it.  This will require
some thinking, but imagine this situation:

oFono calls RequestPrivateNetwork, and cancels the request before the
reply is received, however, ConnMan has already allocated an IP address
and opened the TUN device, and the reply is in the mail so to speak.

In this situation, ConnMan won't be able to release the private network
resources until oFono exits.  Not good ;)

So unfortunately your life gets a bit tricky, since your plugin must
take care of this case, and keep the request alive (marked redundant)
until ConnMan responds, and then send the appropriate Release method.

> +	}
> +
> +	message = dbus_message_new_method_call(CONNMAN_SERVICE,
> +				     CONNMAN_MANAGER_PATH,
> +				     CONNMAN_MANAGER_INTERFACE,
> +				     "ReleasePrivateNetwork");
> +
> +	if (message == NULL)
> +		goto error;
> +
> +	if (dbus_connection_send_with_reply(connection,
> +				message, &call, 5000) == FALSE)
> +		goto error;

You can make things easier on yourself by sending this message with
NoReply flag set and just immediately removing the request.

> +
> +	dbus_pending_call_set_notify(call, release_reply,
> +							req, NULL);
> +	dbus_message_unref(message);
> +	
> +	return;
> +
> +error:
> +	if (message)
> +		dbus_message_unref(message);
> +
> +	g_hash_table_remove(requests, &req->uid);
> +	if (req->pns)
> +		g_free(req->pns);
> +
> +	g_free(req);
> +}
> +
> +static struct ofono_private_network_driver pn_driver = {
> +	.name		= "ConnMan Private Network",
> +	.request	= pns_request,
> +	.release	= pns_release,
> +};
> +
> +static int connman_init(void)
> +{
> +	DBG("");
> +
> +	id = 0;
> +	connection = ofono_dbus_get_connection();
> +	requests = g_hash_table_new(g_int_hash, g_int_equal);

It is a bad idea to create a hash table with no destructor set.  How are
you going to clean up the entries ?

> +
> +	return ofono_private_network_driver_register(&pn_driver);
> +}
> +
> +static void connman_exit(void)
> +{
> +	g_hash_table_destroy(requests);
> +	ofono_private_network_driver_unregister(&pn_driver);
> +}
> +
> +OFONO_PLUGIN_DEFINE(connman, "ConnMan plugin", VERSION,
> +		OFONO_PLUGIN_PRIORITY_DEFAULT, connman_init, connman_exit)

Regards,
-Denis

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

* Re: [PATCH_v4 0/5] Private network request to ConnMan
  2011-05-06 14:01 [PATCH_v4 0/5] Private network request to ConnMan Guillaume Zajac
                   ` (4 preceding siblings ...)
  2011-05-06 14:01 ` [PATCH_v4 5/5] connman: add plugin in oFono to request request/release private network Guillaume Zajac
@ 2021-06-03 10:22 ` adamsmith.87
  2021-06-15 13:06   ` Jackson.com551
  2021-07-21 19:49 ` Kaylee Brown
  6 siblings, 1 reply; 13+ messages in thread
From: adamsmith.87 @ 2021-06-03 10:22 UTC (permalink / raw)
  To: ofono

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

Install the Ivacy VPN app on all of your devices. All major operating systems, devices, and platforms have apps and browser extensions. There is a free trial available.
https://www.ivacy.com/download-vpn/

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

* Re: [PATCH_v4 0/5] Private network request to ConnMan
  2021-06-03 10:22 ` [PATCH_v4 0/5] Private network request to ConnMan adamsmith.87
@ 2021-06-15 13:06   ` Jackson.com551
  0 siblings, 0 replies; 13+ messages in thread
From: Jackson.com551 @ 2021-06-15 13:06 UTC (permalink / raw)
  To: ofono

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

Students may find the assignment problem and supervisors' expectations difficult to understand or may not have time to work on the complicated requirements of the whole assignment or lack the good writing skills required to work on the assignments. We care for your skills and help you in every aspect to achieve good grades. Get Online coursework help that is focused on providing client satisfaction and instant gratification.  https://www.allassignmenthelp.com/coursework-writing-services.html

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

* Re: [PATCH_v4 0/5] Private network request to ConnMan
  2011-05-06 14:01 [PATCH_v4 0/5] Private network request to ConnMan Guillaume Zajac
                   ` (5 preceding siblings ...)
  2021-06-03 10:22 ` [PATCH_v4 0/5] Private network request to ConnMan adamsmith.87
@ 2021-07-21 19:49 ` Kaylee Brown
  6 siblings, 0 replies; 13+ messages in thread
From: Kaylee Brown @ 2021-07-21 19:49 UTC (permalink / raw)
  To: ofono

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

It would be best if you always went for those solution providers who have a finance assignment expert for helping you to complete the assignment on time and in a proper manner. A reliable solution provider will provide you guarantee for their services and a money-back guarantee. A professional service provider will keep your assignments 100% confidential with excellent quality work. Now, it's easy to hire a professional to complete your finance assignments as you have to fill in specific details about your project. After paying for it, you have to wait for its delivery. You might go onto the wrong site and tend to do more for your assignments which is not done professionally, so always make sure that the site is genuine before hiring it. 

https://www.edumagnate.com/finance-assignment-help.html

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

end of thread, other threads:[~2021-07-21 19:49 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-06 14:01 [PATCH_v4 0/5] Private network request to ConnMan Guillaume Zajac
2011-05-06 14:01 ` [PATCH_v4 1/5] gatppp: Add new contructor to use external fd Guillaume Zajac
2011-05-09  4:44   ` Denis Kenzior
2011-05-06 14:01 ` [PATCH_v4 2/5] private-network: add callback typedef drivers and settings Guillaume Zajac
2011-05-09  4:48   ` Denis Kenzior
2011-05-06 14:01 ` [PATCH_v4 3/5] private-network: add request/release functions and new feature to Makefile.am Guillaume Zajac
2011-05-09  4:52   ` Denis Kenzior
2011-05-06 14:01 ` [PATCH_v4 4/5] emulator: add request/release private network calls Guillaume Zajac
2011-05-06 14:01 ` [PATCH_v4 5/5] connman: add plugin in oFono to request request/release private network Guillaume Zajac
2011-05-09  5:30   ` Denis Kenzior
2021-06-03 10:22 ` [PATCH_v4 0/5] Private network request to ConnMan adamsmith.87
2021-06-15 13:06   ` Jackson.com551
2021-07-21 19:49 ` Kaylee Brown

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.