Private network request to ConnMan
cover Private network request to ConnMan
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
PATCH 1/5 gatppp: Add new contructor to use external fd
--- gatchat/gatppp.c | 33 ++++++++++++++++++++++++++++++++- gatchat/gatppp.h | 1 + gatchat/ppp.h | 2 +- gatchat/ppp_net.c | 40 +++++++++++++++++++++++++--------------- 4 files changed, 59 insertions(+), 17 deletions(-)
gatchat/gatppp.c +32 -1
@@ -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; +}
gatchat/gatppp.h +1 -0
@@ -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,
gatchat/ppp.h +1 -1
@@ -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);
gatchat/ppp_net.c +25 -15
@@ -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;
Signature · 1 line
1.7.1
Re: [PATCH_v4 1/5] gatppp: Add new contructor to use external fd
Hi Guillaume,
Quoted 20 lines · Guillaume Zajac
--- gatchat/gatppp.c | 33 ++++++++++++++++++++++++++++++++- gatchat/gatppp.h | 1 + gatchat/ppp.h | 2 +- gatchat/ppp_net.c | 40 +++++++++++++++++++++++++--------------- 4 files changed, 59 insertions(+), 17 deletions(-)gatchat/gatppp.c +1
-0@@ -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)
gatchat/gatppp.c void ppp_auth_notify(GAtPPP *ppp, gboolean success) · line 292
Quoted 5 lines
gatchat/gatppp.c +1
-1@@ -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.
Quoted 133 lines
gatchat/gatppp.c +30
-0if (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; +}gatchat/gatppp.h +1
-0@@ -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,gatchat/ppp.h +1
-1@@ -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);gatchat/ppp_net.c +17
-14@@ -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);
gatchat/ppp_net.c struct ppp_net *ppp_net_new(GAtPPP *ppp) · line 157
Quoted 10 lines
gatchat/ppp_net.c +7
-1+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.
gatchat/ppp_net.c struct ppp_net *ppp_net_new(GAtPPP *ppp) · line 172
Quoted 6 lines
gatchat/ppp_net.c +1
-0/* create a channel for reading and writing to this interface */ channel =g_io_channel_unix_new (fd); +if (channel ==NULL ) goto error;
Regards,
-Denis
PATCH 2/5 private-network: add callback typedef drivers and settings
In reply to Guillaume Zajac--- include/private-network.h | 59 +++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 59 insertions(+), 0 deletions(-) create mode 100644 include/private-network.h
include/private-network.h new file +59 -0
@@ -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 */
Signature · 1 line
1.7.1
Re: [PATCH_v4 2/5] private-network: add callback typedef drivers and settings
Hi Guillaume,
Quoted 5 lines · Guillaume Zajac
--- 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.
Quoted 18 lines
include/private-network.h new file +12
-0@@ -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
include/private-network.h line 22
Quoted 10 lines
include/private-network.h new file +10
-0+* 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?
include/private-network.h line 30
Quoted 8 lines
include/private-network.h new file +8
-0+#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.
include/private-network.h line 40
Quoted 10 lines
include/private-network.h new file +10
-0+ +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?
include/private-network.h line 42
Quoted 2 lines
include/private-network.h new file +2
-0+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?
Quoted 7 lines
include/private-network.h new file +7
-0+ +struct ofono_private_network_driver { +char *name; +int (*request)(ofono_private_network_cb_t cb,void *data); +void (*release)(int uid); +}; +
include/private-network.h line 59
Quoted 10 lines
include/private-network.h new file +10
-0+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
PATCH 3/5 private-network: add request/release functions and new feature to Makefile.am
In reply to Guillaume Zajac--- 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
Makefile.am +4 -3
@@ -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
src/ofono.h +6 -0
@@ -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); +
src/private-network.c new file +89 -0
89 lines not on this page · raw message
Signature · 1 line
1.7.1
Re: [PATCH_v4 3/5] private-network: add request/release functions and new feature to Makefile.am
Hi Guillaume,
Quoted 12 lines · Guillaume Zajac
--- 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.cMakefile.am +0
-0
Makefile.am pkginclude_HEADERS = include/log.h include/plugin.h include/history.h \ · line 20
Quoted 7 lines
Makefile.am +2
-2@@ -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.
Quoted 66 lines
Makefile.am +2
-1nodist_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@ -ldlsrc/ofono.h +6
-0@@ -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); +src/private-network.c new file +33
-0@@ -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) +{
src/private-network.c line 43
Quoted 10 lines
src/private-network.c new file +10
-0+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.
Quoted 10 lines
src/private-network.c new file +10
-0+ driver->release (id); + +break ; + } +} + +ofono_bool_t __ofono_private_network_request (ofono_private_network_cb_t cb, +void *data,int *id) +{ +GSList *d;
src/private-network.c line 63
Quoted 10 lines
src/private-network.c new file +10
-0+ +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.
src/private-network.c line 65
Quoted 2 lines
src/private-network.c new file +2
-0+if (*id <0 ) +continue ;
You might want to always return > 0 for successful cases, and leave 0 as a sentinel value.
Quoted 14 lines
src/private-network.c new file +14
-0+ +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); +
src/private-network.c line 89
Quoted 10 lines
src/private-network.c new file +10
-0+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
PATCH 4/5 emulator: add request/release private network calls
In reply to Guillaume Zajac--- src/emulator.c | 49 +++++++++++++++++++++++++++++++++++++++---------- 1 files changed, 39 insertions(+), 10 deletions(-)
src/emulator.c +39 -10
@@ -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);
Signature · 1 line
1.7.1
PATCH 5/5 connman: add plugin in oFono to request request/release private network
In reply to Guillaume Zajac--- Makefile.am | 3 + plugins/connman.c | 297 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 300 insertions(+), 0 deletions(-) create mode 100644 plugins/connman.c
Makefile.am +3 -0
@@ -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@
plugins/connman.c new file +297 -0
297 lines not on this page · raw message
Signature · 1 line
1.7.1
Re: [PATCH_v4 5/5] connman: add plugin in oFono to request request/release private network
Hi Guillaume,
Quoted 99 lines · Guillaume Zajac
--- Makefile.am | 3 + plugins/connman.c | 297 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 300 insertions(+), 0 deletions(-) create mode 100644 plugins/connman.cMakefile.am +3
-0@@ -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@plugins/connman.c new file +73
-0@@ -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; +
plugins/connman.c line 83
Quoted 10 lines
plugins/connman.c new file +10
-0+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 ;)
Quoted 47 lines
plugins/connman.c new file +47
-0+ +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 ) {
plugins/connman.c line 140
Quoted 10 lines
plugins/connman.c new file +10
-0+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
Quoted 91 lines
plugins/connman.c new file +91
-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);
plugins/connman.c line 241
Quoted 10 lines
plugins/connman.c new file +10
-0+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.
plugins/connman.c line 254
Quoted 13 lines
plugins/connman.c new file +13
-0+ } + + 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.
Quoted 21 lines
plugins/connman.c new file +21
-0+ +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,
plugins/connman.c line 285
Quoted 10 lines
plugins/connman.c new file +10
-0+ .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 ?
plugins/connman.c line 297
Quoted 12 lines
plugins/connman.c new file +12
-0+ +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
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/
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
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.