Project import
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..968eb6c
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,192 @@
+#
+#    Copyright (c) 2010-2011 Nest, Inc.
+#    All rights reserved.
+#
+#    This document is the property of Nest. It is considered
+#    confidential and proprietary information.
+#
+#    This document may not be reproduced or transmitted in any form,
+#    in whole or in part, without the express written permission of
+#    Nest.
+#
+#    Description:
+#      This file is the make file for connman, a daemon for managing
+#      network connections within embedded devices running the Linux
+#      operating system.
+#
+
+BuildConfigSpecialized	:= No
+BuildProductSpecialized	:= No
+
+include pre.mak
+
+PackageRoot		:= .
+
+PackageName		:= connman
+
+PackageSeparator	:=
+
+PackageSourceDir	:= $(PackageRoot)/$(PackageName)
+
+PackageBuildMakefile	= $(call GenerateBuildPaths,Makefile)
+
+LicenseSourceFile	:= $(PackageSourceDir)/COPYING
+
+CleanPaths		+= $(PackageLicenseFile)
+
+DbusDir			:= sw/tps/dbus
+DbusIncDirs		:= $(call GenerateResultPaths,$(DbusDir),usr/include/dbus-1.0 usr/lib/dbus-1.0/include)
+DbusLibDir		:= $(call GenerateResultPaths,$(DbusDir),usr/lib)
+
+GlibDir			:= sw/tps/glib
+GlibIncDirs		:= $(call GenerateResultPaths,$(GlibDir),usr/include/glib-2.0 usr/lib/glib-2.0/include)
+GlibLibDir		:= $(call GenerateResultPaths,$(GlibDir),usr/lib)
+
+IptablesDir		:= sw/tps/iptables
+IptablesIncDir		:= $(call GenerateResultPaths,$(IptablesDir),usr/include)
+IptablesLibDir		:= $(call GenerateResultPaths,$(IptablesDir),usr/lib)
+
+LinuxDir		:= sw/tps/linux
+LinuxIncDir		:= $(call GenerateResultPaths,$(LinuxDir),include)
+
+# The following libraries are for connmanctl
+
+LibEditDir		:= sw/tps/libedit
+LibEditIncDirs		:= $(call GenerateResultPaths,$(LibEditDir),usr/include usr/include/editline)
+LibEditLibDir		:= $(call GenerateResultPaths,$(LibEditDir),usr/lib)
+
+NCursesDir		:= sw/tps/ncurses
+NCursesIncDir		:= $(call GenerateResultPaths,$(NCursesDir),usr/include)
+NCursesLibDir		:= $(call GenerateResultPaths,$(NCursesDir),usr/lib)
+
+
+
+all: $(PackageDefaultGoal)
+
+# Generate the package license contents.
+
+$(LicenseSourceFile): source
+
+$(PackageLicenseFile): $(LicenseSourceFile)
+	$(copy-result)
+
+# We are building this package from version-controlled source, so
+# there is nothing to do for this target goal.
+
+$(PackageSourceDir):
+
+# Prepare the sources.
+
+.PHONY: source
+source: | $(PackageSourceDir)
+
+# Patch the sources, if necessary.
+
+.PHONY: patch
+patch: source
+
+# Generate the package build makefile.
+
+OPTIONS_FLAGS = \
+	--enable-client \
+	--disable-bluetooth \
+	--disable-dundee \
+	--disable-gtk-doc \
+	--disable-hh2serial-gps \
+	--disable-iospm \
+	--disable-openconnect \
+	--disable-openvpn \
+	--disable-pacrunner \
+	--disable-polkit \
+	--disable-threads \
+	--disable-tools \
+	--disable-vpnc \
+	--disable-wispr \
+	--enable-debug \
+	--enable-sleep \
+	--enable-ethernet=builtin \
+	--enable-loopback=builtin \
+	--enable-wifi=builtin
+
+ifdef BUILD_FEATURE_NLCELLULAR
+OPTIONS_FLAGS += \
+	--enable-ofono=builtin
+else
+OPTIONS_FLAGS += \
+	--disable-ofono
+endif
+
+$(PackageBuildMakefile): | $(PackageSourceDir) $(BuildDirectory) $(ResultDirectory)
+	$(Verbose)cd $(BuildDirectory) && \
+	$(CURDIR)/$(PackageSourceDir)/configure \
+	INSTALL="$(INSTALL) $(INSTALLFLAGS)" \
+	CC="$(CC)" CXX="$(CXX)" AR=$(AR) NM=$(NM) RANLIB=$(RANLIB) STRIP=$(STRIP) \
+	CPPFLAGS="$(call ToolGenerateIncludeArgument,$(LinuxIncDir) $(LibEditIncDirs) $(NCursesIncDir))" \
+	LDFLAGS="-L$(LibEditLibDir) -L$(NCursesLibDir) -lcurses" \
+	DBUS_CFLAGS="$(call ToolGenerateIncludeArgument,$(DbusIncDirs))" \
+	DBUS_LIBS="-L$(DbusLibDir) -ldbus-1" \
+	GLIB_CFLAGS="$(call ToolGenerateIncludeArgument,$(GlibIncDirs))" \
+	GLIB_LIBS="-L$(GlibLibDir) -lglib-2.0" \
+	GTHREAD_CFLAGS="$(call ToolGenerateIncludeArgument,$(GlibIncDirs))" \
+	GTHREAD_LIBS="-L$(GlibLibDir) -lgthread-2.0" \
+	XTABLES_CFLAGS="$(call ToolGenerateIncludeArgument,$(IptablesIncDir))" \
+	XTABLES_LIBS="-L$(IptablesLibDir) -lxtables" \
+	WPASUPPLICANT="/sbin/wpa_supplicant" \
+	--build=$(HostTuple) \
+	--host=$(TargetTuple) \
+	--prefix=/usr \
+	--sysconfdir=/etc \
+	--localstatedir=/var \
+	$(OPTIONS_FLAGS)
+
+# Configure the source for building.
+
+.PHONY: configure
+configure: source $(PackageBuildMakefile)
+
+# Build the source.
+#
+# We have to unset MAKEFLAGS since they confuse the package build otherwise.
+
+.PHONY: build
+build: configure
+	$(Verbose)unset MAKEFLAGS && \
+	$(MAKE) $(JOBSFLAG) -C $(BuildDirectory) \
+	all
+
+# Stage the build to a temporary installation area.
+#
+# We have to unset MAKEFLAGS since they confuse the package build otherwise.
+#
+# We explictly remove plug-in '*.la' files because some packages that
+# depend on these libraries use libtool. If libtool finds a '*.la'
+# file for a library, it uses the value of 'libdir=<dir>' it finds. In
+# our case, since '--prefix=/usr' this value is '/usr/lib'. It then
+# resolves '-lfoo' to '/usr/lib/libfoo.so'. In a cross-compilation
+# environment, this is likely to be neither the right architecture nor
+# the right version to link against. In short, we lose.
+#
+# We could also handle this by removing DESTDIR and setting the prefix
+# to $(ResultDirectory); however, that results in libtool hard-coding
+# $(ResultDirectory) as the RPATH in the linked executables which is
+# NOT what we want either. We lose again.
+#
+# By removing the '*.la' file, we win by ensuring neither a misdirected
+# link nor an RPATH.
+
+.PHONY: stage
+stage: build | $(ResultDirectory)
+	$(Verbose)unset MAKEFLAGS && \
+	$(MAKE) $(JOBSFLAG) -C $(BuildDirectory) \
+	DESTDIR=$(ResultDirectory) \
+	install
+	$(Verbose)$(RM) $(RMFLAGS) $(call GenerateResultPaths,,$(addprefix usr/lib/connman/plugins/,ethernet.la loopback.la ntpd.la wifi.la sleepplugin.la))
+DeviceUser:=root
+quick-install: stage
+	tar -czC $(ResultDirectory)/usr/ . | ssh $(DeviceUser)@$(DeviceAddress) tar xvzC /usr
+
+clean:
+	$(Verbose)$(RM) $(RMFLAGS) -r $(BuildDirectory)
+	$(Verbose)$(RM) $(RMFLAGS) -r $(ResultDirectory)
+
+include post.mak
diff --git a/connman.url b/connman.url
new file mode 100644
index 0000000..1d02c06
--- /dev/null
+++ b/connman.url
@@ -0,0 +1 @@
+git://git.kernel.org/pub/scm/network/connman/connman.git
diff --git a/connman.version b/connman.version
new file mode 100644
index 0000000..9de53f1
--- /dev/null
+++ b/connman.version
@@ -0,0 +1 @@
+1.29
diff --git a/connman/.mailmap b/connman/.mailmap
new file mode 100644
index 0000000..aebe06f
--- /dev/null
+++ b/connman/.mailmap
@@ -0,0 +1,5 @@
+Luiz Augusto von Dentz <luiz.dentz-von@nokia.com>	<luiz.dentz-von@nokia.com>
+Leena Gunda <leena.gunda@wipro.com>			<leena.gunda@wipro.com>
+Flávio Ceolin <flavio.ceolin@profusion.mobi>		<flavio.ceolin@profusion.mobi>
+Daniel Wagner <daniel.wagner@bmw-carit.de>		<daniel.wagner@bmw-carit.de>
+Zhang Zhengguang <zhengguang.zhang@intel.com>		<zhengguang.zhang@intel.com>
diff --git a/connman/AUTHORS b/connman/AUTHORS
new file mode 100644
index 0000000..7f95df0
--- /dev/null
+++ b/connman/AUTHORS
@@ -0,0 +1,93 @@
+Marcel Holtmann <marcel@holtmann.org>
+Inaky Perez-Gonzalez <inaky@linux.intel.com>
+Samuel Ortiz <sameo@linux.intel.com>
+Joshua Lock <josh@linux.intel.com>
+Richard Purdie <rpurdie@linux.intel.com>
+Gustavo Sverzut Barbieri <barbieri@profusion.mobi>
+Martin Xu <martin.xu@intel.com>
+Sam Leffler <sleffler@google.com>
+Daniel Wagner <daniel.wagner@bmw-carit.de>
+Forest Bond <forest@alittletooquiet.net>
+Kalle Valo <kalle.valo@canonical.com>
+Fabien Marotte <fabienx.marotte@linux.intel.com>
+Pekka Pessi <pekka.pessi@nokia.com>
+Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
+Cristiano Fernandes <cristiano.fernandes@hp.com>
+Joey Lee <jlee@novell.com>
+Leena Gunda <leena.gunda@wipro.com>
+Patrik Flykt <patrik.flykt@linux.intel.com>
+David Woodhouse <dwmw2@infradead.org>
+Gustavo Padovan <gustavo@padovan.org>
+Julien Massot <jmassot@aldebaran-robotics.com>
+Jukka Rissanen <jukka.rissanen@linux.intel.com>
+Grant Erickson <marathon96@gmail.com>
+Guillaume Lucas <guillaumex.lucas@intel.com>
+Henri Bragge <henri.bragge@ixonos.com>
+Alok Barsode <alok.barsode@intel.com>
+Sébastien Bianti <sebastien.bianti@linux.intel.com>
+Yu A Wang <yu.a.wang@intel.com>
+Thierry Boureille <thierry.boureille@gmail.com>
+Paolo Pellegrino <paolo.pellegrino@zirak.it>
+Bertrand Aygon <bertrand.aygon@intel.com>
+Jeff Zheng <jeff.zheng@intel.com>
+Philippe Nunes <philippe.nunes@linux.intel.com>
+Danny Jeongseok Seo <s.seo@samsung.com>
+Flávio Ceolin <flavio.ceolin@profusion.mobi>
+Arjan van de Ven <arjan@linux.intel.com>
+Daniel Mack <zonque@gmail.com>
+Guillaume Zajac <guillaume.zajac@linux.intel.com>
+Manfred Kober <manfred.kober@gmx.de>
+Mario Domenech Goulart <mario.goulart@gmail.com>
+Otavio Salvador <otavio@ossystems.com.br>
+Tim Sander <tim01@iss.tu-darmstadt.de>
+Adrien Bustany <adrien.bustany@nokia.com>
+Henrique Dante de Almeida <hdante@profusion.mobi>
+Lucas De Marchi <lucas.demarchi@profusion.mobi>
+Elena Tebesoi <elena.tebesoi@gmail.com>
+Mikel Astiz <mikel.astiz@bmw-carit.de>
+Paulo Pizarro <paulo.pizarro@gmail.com>
+Ross Burton <ross.burton@intel.com>
+Tudor Marcu <tudor.a.marcu@intel.com>
+Ceara Chewning <ceara.k.chewning@intel.com>
+Johannes Berg <johannes.berg@intel.com>
+Justin Maggard <jmaggard10@gmail.com>
+Yann E. Morin <yann.morin.1998@free.fr>
+Constantin Musca <constantinx.musca@intel.com>
+Terry Simons <terry.simons@gmail.com>
+Luciano Coelho <luciano.coelho@intel.com>
+Peter Meerwald <pmeerw@pmeerw.net>
+Chengyi Zhao <chengyix.zhao@gmail.com>
+Tysen Moore <tysen.moore@xs-embedded.com>
+Bastien Nocera <hadess@hadess.net>
+Michael Ikey Doherty <michael.i.doherty@intel.com>
+Mateusz Potrola <mateuszx.potrola@intel.com>
+Jaehyun Kim <jeik01.kim@samsung.com>
+Zhang Zhengguang <zhengguang.zhang@intel.com>
+Sjoerd Simons <sjoerd.simons@collabora.co.uk>
+Alban Crequy <alban.crequy@collabora.co.uk>
+Philippe Coval <philippe.coval@open.eurogiciel.org>
+Hannu Mallat <hannu.mallat@jollamobile.com>
+Glenn Schmottlach <Glenn.Schmottlach@xs-embedded.com>
+Jonathan Liu <net147@gmail.com>
+Andrew LeCain <electricalpanel@gmail.com>
+Maneesh Jain <maneesh.jain@samsung.com>
+Eduardo Abinader <eduardo.abinader@openbossa.org>
+Guoqiang Liu <guoqiang.liu@archermind.com>
+Eric Bouxirot <eric.bouxirot@azimut-monitoring.com>
+Alexandru Costache <alexandrux.costache@intel.com>
+Pasi Sjöholm <pasi.sjoholm@jolla.com>
+Mario Schuknecht <mario.schuknecht@dresearch-fe.de>
+Slava Monich <slava.monich@jolla.com>
+Aaron McCarthy <aaron.mccarthy@jolla.com>
+Saurav Babu <saurav.babu@samsung.com>
+David Lechner <david@lechnology.com>
+Jason Abele <jason@aether.com>
+Erik Larsson <erik@ortogonal.com>
+Chris Hiszpanski <chris@kunasystems.com>
+Tomáš Čech <sleep_walker@suse.cz>
+Philip Withnall <philip@tecnocode.co.uk>
+Andreas Oberritter <obi@opendreambox.org>
+Arman Uguray <armansito@chromium.org>
+Vinicius Costa Gomes <vcgomes@gmail.com>
+Marcus Folkesson <marcus.folkesson@gmail.com>
+Michael Olbrich <m.olbrich@pengutronix.de>
diff --git a/connman/COPYING b/connman/COPYING
new file mode 100644
index 0000000..6d45519
--- /dev/null
+++ b/connman/COPYING
@@ -0,0 +1,340 @@
+		    GNU GENERAL PUBLIC LICENSE
+		       Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+                       51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+			    Preamble
+
+  The licenses for most software are designed to take away your
+freedom to share and change it.  By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users.  This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it.  (Some other Free Software Foundation software is covered by
+the GNU Library General Public License instead.)  You can apply it to
+your programs, too.
+
+  When we speak of free software, we are referring to freedom, not
+price.  Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+  To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+  For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have.  You must make sure that they, too, receive or can get the
+source code.  And you must show them these terms so they know their
+rights.
+
+  We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+  Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software.  If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+  Finally, any free program is threatened constantly by software
+patents.  We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary.  To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.
+
+		    GNU GENERAL PUBLIC LICENSE
+   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+  0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License.  The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language.  (Hereinafter, translation is included without limitation in
+the term "modification".)  Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope.  The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+  1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+  2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+    a) You must cause the modified files to carry prominent notices
+    stating that you changed the files and the date of any change.
+
+    b) You must cause any work that you distribute or publish, that in
+    whole or in part contains or is derived from the Program or any
+    part thereof, to be licensed as a whole at no charge to all third
+    parties under the terms of this License.
+
+    c) If the modified program normally reads commands interactively
+    when run, you must cause it, when started running for such
+    interactive use in the most ordinary way, to print or display an
+    announcement including an appropriate copyright notice and a
+    notice that there is no warranty (or else, saying that you provide
+    a warranty) and that users may redistribute the program under
+    these conditions, and telling the user how to view a copy of this
+    License.  (Exception: if the Program itself is interactive but
+    does not normally print such an announcement, your work based on
+    the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole.  If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works.  But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+  3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+    a) Accompany it with the complete corresponding machine-readable
+    source code, which must be distributed under the terms of Sections
+    1 and 2 above on a medium customarily used for software interchange; or,
+
+    b) Accompany it with a written offer, valid for at least three
+    years, to give any third party, for a charge no more than your
+    cost of physically performing source distribution, a complete
+    machine-readable copy of the corresponding source code, to be
+    distributed under the terms of Sections 1 and 2 above on a medium
+    customarily used for software interchange; or,
+
+    c) Accompany it with the information you received as to the offer
+    to distribute corresponding source code.  (This alternative is
+    allowed only for noncommercial distribution and only if you
+    received the program in object code or executable form with such
+    an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it.  For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable.  However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+  4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License.  Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+  5. You are not required to accept this License, since you have not
+signed it.  However, nothing else grants you permission to modify or
+distribute the Program or its derivative works.  These actions are
+prohibited by law if you do not accept this License.  Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+  6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions.  You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+  7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License.  If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all.  For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices.  Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+  8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded.  In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+  9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time.  Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number.  If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation.  If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+  10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission.  For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this.  Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+			    NO WARRANTY
+
+  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+		     END OF TERMS AND CONDITIONS
+
+	    How to Apply These Terms to Your New Programs
+
+  If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+  To do so, attach the following notices to the program.  It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+    <one line to give the program's name and a brief idea of what it does.>
+    Copyright (C) <year>  <name of author>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    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
+
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+    Gnomovision version 69, Copyright (C) year name of author
+    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+    This is free software, and you are welcome to redistribute it
+    under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License.  Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary.  Here is a sample; alter the names:
+
+  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+  `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+  <signature of Ty Coon>, 1 April 1989
+  Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs.  If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library.  If this is what you want to do, use the GNU Library General
+Public License instead of this License.
diff --git a/connman/ChangeLog b/connman/ChangeLog
new file mode 100644
index 0000000..11e08cd
--- /dev/null
+++ b/connman/ChangeLog
@@ -0,0 +1,1015 @@
+ver 1.29:
+	Fix issue with IPv6 autoconfiguration when disabled.
+	Fix issue with IPv6 temporary route handling.
+	Fix issue with IPv6 timers for nameservers.
+	Fix issue with DHPCv6 and route configuration.
+	Fix issue with DHCPv6 source port and buggy servers.
+	Fix issue with DHCPv6 rapid commit option length.
+	Fix issue with DHCPv6 rapid commit error handling.
+	Fix issue with handling invalid WiFi passphrases.
+	Fix issue with connecting Ethernet devices.
+	Add support for Ethernet and VLAN usage.
+
+ver 1.28:
+	Fix issue with DHCPv6 re-transmission timer.
+	Fix issue with DHCP service ID option byte order.
+	Fix issue with IPv6 connections and SLAAC/DHCPv6.
+	Fix issue with telephony and IPv6 autoconfiguration.
+	Fix issue with Bluetooth technology setting changes.
+	Fix issue with WiFi autoscan interval calculation.
+	Fix issue with WiFi and missing BSS signal strength.
+	Add support for IPv4 information for WiFi Display.
+
+ver 1.27:
+	Fix issue with memory leak in IP configuration.
+	Fix issue with providing random numbers for DHCP.
+	Fix issue with handling IN_MOVED_TO inotify events.
+	Fix issue with channel selection for WiFi scanning.
+	Add support for handling Bluetooth GN and PANU roles.
+
+ver 1.26:
+	Fix issue with missing WiFi security provisioning support.
+	Fix issue with immutable setting and provisioned services.
+	Fix issue with scheduling DNS cache cleanup procedure.
+	Fix issue with IPv6 Privacy setting on service removal.
+	Fix issue with DHCPv6 CONFIRM message sending procedure.
+	Fix issue with DHCPv6 lease expiration handling support.
+	Fix issue with DHCPv4 networks and broadcast flag handling.
+	Fix issue with DHCPv4 networks without gateway configuration.
+	Fix issue with P2P Peer authorization handling.
+	Fix issue with P2P Peer service registration.
+	Add support for WiFi Display information elements.
+	Add support for systemd-hostnamed integration.
+
+ver 1.25:
+	Fix issue with handling rebind timer for DHCPv6.
+	Fix issue with handling DHCP renew transaction.
+	Fix issue with user supplied proxy settings and DHCP.
+	Fix issue with extra status codes from captive portals.
+	Fix issue with service idle state reset on failure.
+	Fix issue with DNS label compression handling.
+	Add support for experimental P2P Peer service.
+
+ver 1.24:
+	Fix issue with handling slave interfaces.
+	Fix issue with handling DHCPv4 broadcast flag.
+	Fix issue with handling DHCPv4 lease expiration.
+	Fix issue with handling WiFi auto-scanning timeout.
+	Fix issue with handling domain and DNS server changes.
+	Fix issue with double free and agent messages.
+
+ver 1.23:
+	Fix issue with memory leak in technology handling.
+	Fix issue with not removing host route of OpenVPN.
+	Fix issue with double free in DHCP cleanup handling.
+	Fix issue with handling DHCP method from oFono.
+	Fix issue with IPv6-PD when disabling tethering.
+	Fix issue with DNS proxy when disabling tethering.
+	Fix issue with Bluetooth start and stop interaction.
+	Fix issue with Bluetooth PAN networks on adapter change.
+
+ver 1.22:
+	Fix issue with WPS state synchronization.
+	Fix issue with DNS servers and default service.
+	Fix issue with DHCP client and rebooting state.
+	Add support for NTP exponential backoff handling.
+	Add support for NTP kiss-of-death packet handling.
+	Add support for Ethernet gadget networking.
+
+ver 1.21:
+	Fix issue with WiFi networks and zero SSID length.
+	Fix issue with security details for hidden WiFi networks.
+	Fix issue with handling IPv6 proxy address resolving.
+	Fix issue with enabling Bluetooth controllers.
+
+ver 1.20:
+	Fix issue with invalid cache of DNS proxy support.
+	Fix issue with stopping DHCP for failed connections.
+	Fix issue with not stopping IPv4 Link-Local state machine.
+	Fix issue with service type handling for unknown interfaces.
+	Fix issue with using interface names instead of indexes.
+	Fix issue with resetting network retry counter on failure.
+	Fix issue with using nameservers when its type is not enabled.
+	Fix issue with fallback nameservers not being used.
+	Add support for NTP version 3 protocol.
+
+ver 1.19:
+	Fix issue with not correctly storing IPv4 method.
+	Fix issue with changing the default service too early.
+	Fix issue with service reference count and WISPr checks.
+	Fix issue with service auto-connect handling and ordering.
+	Fix issue with host and domain names when service changes.
+	Fix issue with proxy result and WISPr handling.
+	Fix issue with proxy reset when disconnecting.
+	Fix issue with handling fallback nameservers.
+	Add support for multiple agents.
+
+ver 1.18:
+	Fix issue with alignment calculation for iptables.
+	Fix issue with WEP key index parameter handling.
+	Fix issue with handling of 802.1x credentials.
+	Fix issue with command line parameter parsing.
+	Add support for completion handling in client tool.
+
+ver 1.17:
+	Fix issue with handling consecutive WiFi scanning.
+	Fix issue with WiFi handling and RFKILL soft block.
+	Fix issue with handling external RFKILL events.
+	Fix issue with handling USB gadget devices.
+	Fix issue with network reference handling.
+	Fix issue with byte order and DHCP discover options.
+	Fix issue with DHCP retry handling during IPv4-LL.
+	Fix issue with DHCPv6 rebind handling.
+	Add support for DHCPv6 decline message handling.
+	Add support for DHCPv6 duplicate address detection.
+
+ver 1.16:
+	Fix issue with missing signals during connection changes.
+	Fix issue with missing notification of proxy properties.
+	Fix issue with missing DHCPv6 domain list option.
+	Fix issue with missing DHCPv6 release message.
+	Fix issue with missing DHCPv6 error handling.
+	Fix issue with wrong IPCMv6 checksum calculation.
+	Fix issue with wrong service disconnect state.
+	Fix issue with failure to enable offline mode.
+	Add support for Netfilter Accounting (NFACCT).
+	Add support for IPv6 prefix delegation handling.
+
+ver 1.15:
+	Fix issue with missing cleanup for IPv4-LL handling.
+	Fix issue with missing property update for domain names.
+	Fix issue with scanning for all stored hidden WiFi networks.
+	Fix issue with time server polling for non-default service.
+	Fix issue with persistent storage of time configuration.
+
+ver 1.14:
+	Fix issue with WiFi scanning race condition and power cycle.
+	Add support for configuring allowed tethering technologies.
+	Add support for persistent tethering configurations.
+	Add support for DHCPv6 max retransmission duration option.
+	Add support for DHCPv6 elapsed time option.
+	Add support for DHCPv6 confirm messages.
+
+ver 1.13:
+	Fix issue with auto-scanning of known hidden SSIDs.
+	Fix issue with not correctly terminated auto-scanning.
+	Fix issue with missing enforcing of immutable services.
+	Fix issue with missing handling of multiple connection attempts.
+	Fix issue with missing WISPr restart after nameserver change.
+	Fix issue with missing provisioning for IP address method.
+	Fix issue with missing IP configuration signal on disconnect.
+	Fix issue with DNS proxy and memory leaks on request timeouts.
+	Fix issue with DNS proxy and handling partial TCP messages.
+	Fix issue with DNS proxy and handling of EDNS0 buffers.
+	Fix issue with DNS proxy and handling of IPv6 loopback.
+	Fix issue with DNS proxy listening on all interfaces.
+	Fix issue with CDMA network creation.
+
+ver 1.12:
+	Fix issue with overwriting gateway address.
+	Fix issue with missing IP address validation.
+	Fix issue with parsing of IPv6 configuration settings.
+	Fix issue with DHCP server address stored in host order.
+	Fix issue with resolver query failures and pending results.
+	Fix issue with wrongly reported max scan SSID parameter.
+	Fix issue with handling errors from WiFi fast scanning.
+	Add support for WiFi provisioning via NFC.
+	Add support for VPN daemon provisioning.
+	Add support for Ethernet provisioning.
+
+ver 1.11:
+	Fix issue with agent reference counting imbalance.
+	Fix issue with handling max number of SSID for scanning.
+	Fix issue with missing notification of online state changes.
+	Fix issue with not properly triggering auto-connect behavior.
+	Fix issue with disabling IPv6 in lower up interface states.
+	Fix issue with spurious error messages for interface handling.
+	Fix issue with wrong answer count in DNS responses.
+	Fix issue with crash in DNS lookup function.
+	Add support for BlueZ 5.x network interfaces.
+	Remove deprecated WiMAX support.
+
+ver 1.10:
+	Fix issue with not skipping service if settings loading fails.
+	Fix issue with not clearing address before starting DHCP.
+	Fix issue with not handling removal of GPRS context.
+	Fix issue with not closing UDP socket on error condition.
+	Fix issue with race condition when removing WiFi device.
+	Add support for separate VPN daemon.
+
+ver 1.9:
+	Fix issue with WISPr portal context handling.
+	Fix issue with DNS lookup from wrong queue.
+	Fix issue with DNS data reception after disconnect.
+	Fix issue with missing DNS host part length checking.
+	Fix issue with RFKILL and technology interaction.
+	Fix issue with tethering and disabled technologies.
+	Add support for single connected technology setting.
+
+ver 1.8:
+	Fix issue with NTP transmit time calculation.
+	Fix issue with WiFi Tethering and newer kernels.
+	Fix issue with Netlink messages from Wireless Extensions.
+	Fix issue with IPv6 nameserver refresh beeing applied to IPv4.
+	Fix issue with overwriting DNS proxy address information.
+	Fix issue with missing handling of RFKILL hard blocking.
+	Add support for disabling internal backtrace functionality.
+
+ver 1.7:
+	Fix issue with IPv4 address removal when setting interface down.
+	Fix issue with wrong error when setting tethering support option.
+	Fix issue with errors reported twice via agent to the client.
+	Fix issue with missing serialization of agent callbacks.
+	Add initial version of command line client tool.
+
+ver 1.6:
+	Fix issue with Bluetooth networking support.
+	Fix issue with technology enabling method returns.
+	Fix issue with wrong IP address for fixed configurations.
+	Fix issue with IP address setting when interface is down.
+	Fix issue with handling duplicate hidden WiFi networks.
+	Fix issue with missing scanning for hidden WiFi networks.
+	Fix issue with missing update of service properties.
+	Fix issue with missing clearing of service errors.
+	Add manual pages for daemon and configuration file.
+
+ver 1.5:
+	Fix issue with detecting Bluetooth networks when powered off.
+	Fix issue with connection attempts of non-favorite services.
+	Fix issue with connection attempts of disabled IP configurations.
+	Fix issue with missing auto-connection after changing IP method.
+	Fix issue with setting service state when changing IPv4 method.
+	Fix issue with IPv6 usage and static/manual configuration.
+	Add support for configuration option to disable hostname updates.
+	Add support for storing WiFi Tethering identifier and passphrase.
+	Add support for signaling changes of error property.
+
+ver 1.4:
+	Fix issue with WiFi scanning in Tethering mode.
+	Fix issue with WISPr operation and disconnects.
+	Fix issue with DHCP client and restart behavior.
+	Fix issue with DNS resolving and failing IPv6 records.
+	Fix issue with incorrect NTP leap-not-in-sync flag.
+	Fix issue with incorrect NTP transmit time value.
+	Fix issue with failing NTP server due to routing.
+	Fix issue with missing gateway change notification.
+	Fix issue with stale network interfaces at startup.
+	Fix issue with pending method reply and agent errors.
+	Add support for providing previous WPS PIN to agent.
+	Add support for WPA supplicant based auto-scanning.
+	Add support for per device regulatory domain setting.
+	Add support for provisioning hidden WiFi networks.
+
+ver 1.3:
+	Fix issue with default configuration values.
+	Fix issue with timeserver canonical name entries.
+	Fix issue with crash from cellular dummy context.
+	Fix issue with incorrect index for private networks.
+
+ver 1.2:
+	Fix issue with not handling WiFi security changes.
+	Fix issue with not stopping WiFi scanning on shutdown.
+	Fix issue with auto-scanning and network discovery.
+	Fix issue with D-Bus reply for hidden WiFi networks.
+	Fix issue with overlapping memory areas and DNS requests.
+	Add support for randomized DNS transaction identifiers.
+	Add support for DNS caching over TCP connections.
+	Add support for using default IPv6 privacy setting.
+	Add support for providing previous passphrase to agent.
+	Add support for configuration unprovisioning handling.
+	Add support for NetworkInterfaceBlacklist configuration.
+	Add support for Bluetooth DUN daemon (dundee).
+
+ver 1.1:
+	Fix issue with missing message type and DHCPv4 support.
+	Fix issue with potential NULL pointer in DHCPv6 handling.
+	Fix issue with potential NULL pointer in VPN handling.
+	Fix issue with potential NULL pointer for WiFi SSID.
+	Fix issue with missing conversion of raw WiFi PSK input.
+	Fix issue with missing stop for WiFi auto-scanning handling.
+	Fix issue with uninitialized IPv6 prefix length in oFono plugin.
+	Fix issue with domain search list handling according to RFC 6106.
+	Fix issue with domain name list notifications.
+	Fix issue with nameserver list notifications.
+	Fix issue with incorrect fixed IP configuration.
+	Fix issue with incorrect cleanup of resolver timers.
+	Fix issue with handling of RDNSS lifetime expiration.
+	Fix issue with crash on wrong domain length information.
+	Add support for favorite service database migration.
+	Add support for disabling WISPr functionality.
+	Add support for configurable agent timeouts.
+
+ver 1.0:
+	Fix issue with missing WiFi disconnecting flag.
+	Fix issue with missing GPRS context attached check.
+	Fix issue with potential crash and supplicant handling.
+	Fix issue with potential crash and VPN provider.
+	Fix issue with potential crash and host routes.
+
+ver 0.85:
+	Fix issue with duplicate service timeservers.
+	Fix issue with failure state when aborting agent request.
+	Fix issue with automatic scanning for hidden WiFi networks.
+	Fix issue with missing hostname/domainname validity checks.
+	Fix issue with missing DHCP packet length checks.
+	Add support for browser launching from WISPr login.
+
+ver 0.84:
+	Fix issue with handling changed WiFi security of access points.
+	Fix issue with state notification of NetworkManager compatibility.
+
+ver 0.83:
+	Fix issue with Ethernet not being enabled by default.
+	Fix issue with missing host routes for WISPr request.
+	Fix issue with missing HTTPS handling for WISPr support.
+	Fix issue with agent asking for passphrase for open service.
+	Fix issue with endless online check for preferred technology.
+	Fix issue with IPv6 RDNSS and DNS server creation.
+	Fix issue with WiFi roaming state change handling.
+	Fix issue with broken handling of WPS PBC method.
+
+ver 0.82:
+	Fix issue with global online state handling.
+	Fix issue with timeserver handling in case of VPN.
+	Fix issue with automatic WiFi scanning handling.
+	Fix issue with WPS PIN length of zero and PBC.
+
+ver 0.81:
+	Update default configuration options.
+	Add support for WPS PBC advertising handling.
+	Add support for wpa_supplicant background scanning.
+	Fix issue with showing cellular services without APN.
+	Fix issue with missing timeservers changed signal.
+
+ver 0.80:
+	Update to support additional D-Bus API changes.
+	Add support for preferred technologies switching.
+	Add support for default auto connect technologies option.
+	Add support for service specific timeserver configuration.
+	Add support for extended timeserver fallback functionality.
+	Add support for extended nameserver fallback functionality.
+	Add support for user supplied routes for providers.
+	Add support for checking WiFi passphrase validity.
+	Fix issue with WISPr support and proxy handling.
+	Fix issue with Ethernet and auto connect handling.
+	Fix issue with too early IPv6 auto connection.
+	Fix issue with too early 6to4 connection checks.
+	Fix issue with oFono interaction on disconnect.
+	Fix issue with DNS servers behind point-to-point links.
+	Fix issue with pending DNS proxy requests.
+	Fix multiple issues with VPN handling.
+	Fix multiple issues with default gateway handling.
+
+ver 0.79:
+	Update to support changed D-Bus API.
+	Add support for WiFi background scanning.
+	Add support for showing hidden WiFi networks as services.
+	Add support for generic stateless DHCPv6 handling.
+	Add support for DHCPv4 client identifier handling.
+	Add support for generic IP address pool handling.
+	Add support for global DNS cache handling.
+	Add support for internal NTP time handling.
+	Add support for updated oFono handling.
+
+ver 0.78:
+	Fix multiple issues with service connection states.
+	Fix multiple issues with technology handling.
+	Fix issue with DHCP file descriptor leakage.
+	Fix issue with open access points and WPS.
+	Fix issue with handling of cellular devices.
+	Fix issue with DNS proxy hostname resolving.
+	Add support for PPTP and L2TP VPN tunneling.
+	Add support for organized settings storage.
+	Add support for WiFi fast connect handling.
+	Add support for better WiFi error handling.
+	Add support for integrated WISPr handling.
+
+ver 0.77:
+	Fix issue with iptables API breakage.
+	Fix issue with agent input handling.
+	Fix issue with empty cellular operator name.
+	Fix issue with reference counting for network objects.
+	Fix issue with missing D-Bus signals for proxy changes.
+	Fix issue with group identifier and hidden WiFi networks.
+	Fix issue with setting wrong gateway for PPP connections.
+	Fix issue with mismatch of stored IP configuration settings.
+	Fix issue with not stopping DHCP for IPv4 configuration.
+	Add support for remembering last IP address from DHCP.
+	Add support for EAP-GTC authentication method.
+
+ver 0.76:
+	Fix issue with loopback interface setup.
+	Fix issue with /etc/localtime being a symlink.
+	Fix issue with not handling dummy network devices.
+	Fix issue with not provisioning existing services.
+	Fix issue with running WPAD on IPv6 connections.
+	Fix issue with client certificate for TTLS/PEAP.
+	Remove internal element infrastructure.
+
+ver 0.75:
+	Fix issue with 3G connect timeout handling.
+	Fix issue with WiFi raw key PSK handling.
+	Fix issue with DHCP renewal timeout handling.
+	Fix issue with DHCP and empty nameserver list.
+	Add support for unit testing.
+
+ver 0.74:
+	Fix issue with race condition in ready/online handling.
+	Fix issue with DHCP release callback handling.
+	Fix multiple issues with session API handling.
+	Add support for using DNS proxy for Tethering.
+	Add support for Private Network API.
+	Add support for Clock API.
+
+ver 0.73:
+	Update support for session API handling.
+	Add support for more advanced roaming policies.
+	Add support for EAP identity and passphrase queries.
+	Add support for IPv6 handling with cellular bearer.
+	Add support for main configuration file.
+	Remove deprecated profile interface.
+
+ver 0.72:
+	Fix issue with overwriting DNS servers from DHCP.
+	Fix issue with DHCP renewal with same configuration.
+	Fix issue with multiple memory leaks.
+	Add support for 6to4 tunneling.
+
+ver 0.71:
+	Fix issue with not storing IPv6 privacy settings.
+	Fix issue with storing fixed and manual IP settings.
+	Fix issue with service state when PAN connection fails.
+	Fix issue with tethering and WiFi bridge handling.
+	Fix issue with autonomously activated contexts.
+	Fix issue with nameserver array for PACrunner.
+	Fix issue with network information memory leak.
+	Fix issue with double-free in statistics handling.
+	Fix issue with handling malformed profiles.
+	Fix issue with pending DHCP client requests.
+	Add initial support for TI shared transport handling.
+
+ver 0.70:
+	Add support for reporting invalid WiFi passphrases.
+	Add support for IPv6 privacy extension.
+	Add support for IPv6 advanced features.
+	Add support for IPv6 nameserver settings.
+	Remove deprecated APN service settings.
+
+ver 0.69:
+	Fix issue with not handling DNS proxy failures gracefully.
+	Fix issue with double free in statistics handling.
+	Fix issue with early tethering bridge creation.
+	Add support for tethering property per technology.
+	Add support for initial WiFi tethering feature.
+	Add support for using PACrunner as proxy driver.
+	Add support for WPS as part of the security property.
+
+ver 0.68:
+	Fix issue with wrong name of PolicyKit configuration file.
+	Fix issue with inconsistency of WiFi scan states.
+	Fix issue with missing auto-reconnect and oFono.
+	Add support for vpnc based private networks.
+	Add support for WiFi Protected Setup handling.
+	Remove legacy WiFi plugin.
+
+ver 0.67:
+	Fix issue with oFono plugin and multiple online calls.
+	Fix issue with checking for AutoConnect service property.
+	Remove deprecated MCC and MNC service properties.
+
+ver 0.66:
+	Fix multiple set of memory leaks.
+	Fix issue with WPA supplicant phase2 values.
+	Fix issue with WiFi access points after kill/restart.
+	Fix issue with correct PACrunner configuration loading.
+	Add support for loading provision files at runtime.
+	Add support for setting proxy auto-configuration.
+	Add support for IPv6 auto-configured addresses.
+
+ver 0.65:
+	Use new WiFi plugin by default.
+	Fix issue with handling already powered devices.
+	Fix issue with handling proxy PAC option from DHCP.
+	Add support for handling regulatory domain settings.
+	Add support for handling IPv6 router advertisements.
+	Add support for handling IPv6 nameservers.
+	Add support for handling multiple search domains.
+	Add support for handling oFono modem lockdown.
+	Add support for handling IPv6 DNS connections.
+	Add support for IPv4 Link-Local negotiation.
+	Add support for USB CDC Tethering functionality.
+
+ver 0.64:
+	Update service name to net.connman domain.
+	Fix issue with disabling a technology twice.
+	Fix issue with using wrong string for Proxy.Method.
+	Fix issue with TCP connection lookup and DNS proxy.
+	Fix issue with TCP receive busy waits and DNS proxy.
+	Fix various issues with WPA Supplicant interaction.
+	Add support for chunk encoding to HTTP client.
+	Add support for internal HTTP client for portal detection.
+	Add support for internal DHCP server setup.
+	Add support for internal NAT and IP forwarding setup.
+	Add support for Bluetooth Tethering functionality.
+	Remove deprecated device and network D-Bus interfaces.
+	Remove support for dhclient plugin.
+
+ver 0.63:
+	Change to use nl80211/cfg80211 WiFi management by default.
+	Fix various issues with new WPA Supplicant interface.
+	Fix issue with not connecting failed networks at boot.
+	Fix issue with properly tracking RFKILL blocked state.
+	Fix issue with missing signals for IPv4/IPv6 gateway details.
+	Add support for using RTNL for setting IPv4/IPv6 details.
+	Add support for using PHONET_PIPE GPRS interfaces.
+	Add support for setting manual proxy configurations.
+	Add support for exporting proxy configurations to PACrunner.
+	Add support for combined home and roaming statistics.
+	Add support for OpenVPN connections.
+	Remove dependency on udev.
+
+ver 0.62:
+	Fix crash with non-existent or extra DHCP result options.
+	Fix crash when doing PEAP/TTLS authentication.
+	Fix issue with handling multiple data counters.
+	Fix issue with Bluetooth adapters without address.
+	Fix issue with multiple scanning attempts after disconnects.
+	Fix issue with VPN services when switching into offline mode.
+	Add support for storing statistics information in separate files.
+	Add support for verification of configuration file parameters.
+	Add support for handling time server values from DHCP.
+	Add support for allowing DNS over TCP within the DNS proxy.
+	Add support for loading proxy configurations into PACrunner.
+	Add support for WiFi plugin using new WPA Supplicant D-Bus API.
+	Add support for requesting passphrases via agents.
+	Remove default support for EDNS0 option.
+
+ver 0.61:
+	Add support for using the internal DHCP client by default.
+	Add support for latest PolicyKit framework.
+	Add support for new oFono D-Bus interfaces.
+
+ver 0.60:
+	Fix issue with missing reset of proxy settings.
+	Fix issue with missing Ethernet property changed signal.
+	Fix issue with offline operation on already blocked devices.
+	Fix issue with offline mode and device powered changes.
+	Fix issue with portal detection and DHCP renewals.
+	Fix issue with connection attempts for removed networks.
+	Fix issue with stale pointers of networks.
+
+ver 0.59:
+	Fix issue with D-Bus object paths of VPN providers.
+
+ver 0.58:
+	Fix various issues around offline mode.
+	Fix various issues with VPN nameserver handling.
+	Add support for home/roaming network statistics.
+	Add support for EAP-TTLS WiFi configuration.
+	Add support for creating backtraces.
+
+ver 0.57:
+	Fix missing default profile creation.
+	Fix missing service integration of VPN providers.
+	Fix missing export of PAC information retrieved from DHCP.
+	Fix issue with detection of new Bluetooth devices.
+	Fix issue with offline mode handling.
+	Fix issue with device power handling.
+
+ver 0.56:
+	Fix issues with offline mode handling.
+	Fix service integration with VPN providers.
+	Add internal asynchronous resolver library.
+	Add internal DHCP client library.
+	Add support for using internal DHCP client.
+	Add support for WPAD proxy auto-configuration.
+	Add support for static IPv6 configuration.
+	Add support for DHCP provided domain names.
+	Add initial support for on-demand connections.
+	Remove uDHCP and resolvconf plugins.
+
+ver 0.55:
+	Fix issue with 3G roaming status indication.
+	Fix issue with using -H option with dhclient.
+	Fix issue with loading WiFi SSID details for scanning.
+	Add support for setting host routes for DNS servers.
+	Add support for more detailed statistics counters.
+	Add support for internal DHCP client library.
+
+ver 0.54:
+	Fix issue with root requests and EDNS0 OPT records.
+	Fix issue with default gateway when route deletion fails.
+	Fix issue with group identifiers for cellular networks.
+	Fix issue with fixed IP settings from cellular networks.
+	Fix issue with nameserver settings and manual configuration.
+	Add support for cellular network name changes.
+	Add support for cellular signal strength changes.
+	Add support for actively scanning for hidden networks.
+	Add support for ASCII based WEP keys.
+	Add support for NTP timeserver updates.
+	Add support for PPP default route settings.
+
+ver 0.53:
+	Fix issue with supplicant and device scanning state cleaning.
+	Fix issue with Bluetooth PAN networks stay in connected state.
+	Fix issue with reference counting and connected state.
+	Fix issue with technology disabling on device removal.
+	Fix issue with two default gateways when using VPN.
+	Fix issue with static IPv4 configuration and signals.
+	Add support for splitting DHCP provided nameserver results.
+	Add support multiple nameservers in /etc/resolv.conf.
+	Add support for setting manual DNS server configuration.
+	Add support for exporting IPv4 gateway information.
+	Add support for newer versions of oFono API.
+
+ver 0.52:
+	Fix issue with new "connected" states.
+	Fix issue with hidden networks and PSK.
+	Fix issue with DHCP and Bluetooth PAN.
+	Fix issue when disconnecting PAN networks.
+	Add support for application sessions.
+	Add plugin for hh2serial GPS support.
+
+ver 0.51:
+	Fix issue with missing device power toggling.
+	Fix issue with D-Bus object path on device removal.
+	Add support for WiFi portal detection.
+	Add support for configuring static gateways.
+	Remove unneeded plugin for Option HSO support.
+	Remove unneeded plugin for Ericsson MBM support.
+
+ver 0.50:
+	Fix configuration loading for unknown services.
+	Fix IP method setting of Ethernet plugin.
+
+ver 0.49:
+	Fix issue with WiFi power changes.
+	Fix issue with Bluetooth device startup.
+	Fix issue with host route settings for VPN.
+	Fix issue with processing of RFKILL events.
+	Fix some WPA Enterprise privacy issues.
+	Add support for basic Ethernet information.
+	Add support for static IP settings.
+
+ver 0.48:
+	Fix signal strength calculation when quality is not provided.
+	Fix issues with wpa_supplicant state tracking.
+	Fix faulty removal of IP address from interface.
+	Fix permissions of newly created /etc/resolv.conf file.
+	Fix DNS proxy handling when in offline mode.
+	Add support for EDNS0 resolver option.
+	Add workaround for large EDNS0 queries.
+	Add workaround for DHCP startup failures with WiFi networks.
+	Add support for handling hostnames and domainnames.
+	Add support for IPv4 configuration via service interface.
+	Add support for fixed and manual IPv4 configuration.
+	Add support for default service changed notifier.
+	Add support for clearing failure state via service removal.
+	Add support for OpenConnect VPN connections.
+	Add support for IEEE 802.1x WiFi networks.
+	Add support for roaming between WPA and WPA2 networks.
+	Add various generic D-Bus helpers and use them.
+	Remove special handling of Ethernet devices.
+
+ver 0.47:
+	Fix segmentation fault on resolver shutdown.
+	Fix issue with adding nameserver that doesn't exist.
+	Fix issue when no broadcast address is given.
+	Fix issue with missing property changed signal.
+	Add checks for invalid supplicant state transitions.
+	Add initial version of oFono GPRS support.
+	Add support for dynamic debug framework.
+
+ver 0.46:
+	Fix reconnect issue when power off or disabling the device.
+	Remove problematic retry on failure code path.
+
+ver 0.45:
+	Fix crash with connect timeout and second connect attempt.
+	Fix reconnect issues after suspend or roaming attempt.
+
+ver 0.44:
+	Fix command line options for device filtering.
+	Fix issue with network reference in MBM support.
+	Fix handling when losing network access in MBM plugin.
+	Fix broken libiWmxSDK callback parameter handling.
+	Add work around Intel WiMAX SDK API breakage.
+
+ver 0.43:
+	Fix issue with missing scanning after power up.
+	Fix issue with udev versus /dev/rfkill event processing.
+	Fix issue with powered down device on connection attempt.
+	Add support for multiple connection attempts.
+	Add support for tracking the operation state.
+	Add full support for Ericsson MBM cellular devices.
+
+ver 0.42:
+	Fix issue with switching between hidden WiFi networks.
+	Fix issue with missing scanning after disconnect.
+	Fix issue with not triggering auto-connect in some cases.
+
+ver 0.41:
+	Fix race condition with WiFi devices and RFKILL.
+	Fix issue with WiFi connect/disconnect and some drivers.
+	Fix issue with WEP encryption and staging drivers.
+	Fix issue with wrong setup of loopback interfaces.
+
+ver 0.40:
+	Fix issue with wrong setting of initial AutoConnect value.
+	Fix issue with IP configuration and loopback devices.
+	Fix issue with build system and include directory.
+	Fix wrong variable for dhclient-script location.
+	Fix disconnect race condition with Bluetooth service.
+	Add support for ignoring bonding Ethernet interfaces.
+
+ver 0.39:
+	Fix file permissions for profile storage.
+	Fix service resorting when they are in different states.
+	Fix support for handling Bluetooth PAN devices.
+	Add support for AutoConnect property of services.
+	Add support for creating, modifying and removing profiles.
+	Add support for fully flexible task handling framework.
+	Add support for more generic RTNL handling and notifications.
+	Add support for full non-recursive build.
+
+ver 0.38:
+	Fix broken check for security modes.
+	Fix requirement of inotify when loopback support is disabled.
+
+ver 0.37:
+	Fix missing update of signal strength from scan results.
+	Fix error handling in case when passphrase is required.
+	Add support for PassphraseRequired property.
+	Add missing check for WiFi security modes.
+
+ver 0.36:
+	Fix missing reset of network reference when disconnecting.
+	Fix wrong variable reference when sending technology replies.
+	Fix wrong identifiers of D-Bus error names.
+
+ver 0.35:
+	Fix missing auto-connect trigger on Ethernet device removal.
+	Fix availability listing for devices without attached drivers.
+	Fix signals for connected and default technologies.
+	Fix notification to use service types instead of device types.
+	Fix potential pending scan result reply messages after removal.
+	Add support for blocking enable and disable technology changes.
+
+ver 0.34:
+	Fix setup of udev context before loading any plugins.
+	Fix rearming the scan trigger if a device got disabled.
+	Fix device power state changes tracking with RFKILL notifications.
+	Fix wrong usage of device types instead of service types.
+	Fix connect method to handle non-WiFi services.
+
+ver 0.33:
+	Add support for RFKILL changes of the WiFi subsystem.
+	Fix state value of Network Manager compatibility support.
+
+ver 0.32:
+	Fix broken device unregistration on removal.
+	Fix WiMAX device detection handling.
+
+ver 0.31:
+	Fix missing enforcement of offline mode for new devices.
+	Add support for persistent storage of offline mode.
+	Add support for persistent storage of device power state.
+	Remove deprecated and unused network storage callbacks.
+
+ver 0.30:
+	Fix issue where hidden network could show up in service list.
+	Fix issue with asynchronous notification of scan requests.
+	Fix message reference leak when adding interface fails.
+	Fix problem when removing network during inactive state.
+	Remove broken and unused callback for joining networks.
+	Remove deprecated device and network interface methods.
+	Remove test scripts for deprecated interface methods.
+
+ver 0.29:
+	Fix missing signal emission for offline mode changes.
+	Fix signal emission for changes in technology properties.
+	Rename Technologies property to AvailableTechnologies.
+
+ver 0.28:
+	Fix another reference counting imbalance when adding networks.
+	Revert supplicant change to always reset scanning after results.
+
+ver 0.27:
+	Fix missing disarming of the connection timeout.
+	Fix handling of multiple supplicant disconnect attempts.
+	Fix simultaneous connects from different technologies limitation.
+
+ver 0.26:
+	Fix broken handling of auto-connect logic.
+	Fix handling of out-of-range access points.
+	Fix support for connecting to hidden networks.
+	Fix reference counting for networks with same SSID.
+	Fix issue with WiFi interfaces not getting switched off.
+	Fix problems with delayed service list updates.
+	Fix disconnect/abort of connection attempts.
+
+ver 0.25:
+	Fix showing of WiFi networks with less than 25% signal strength.
+	Fix potential segmentation fault with network passphrases.
+
+ver 0.24:
+	Fix handling of initial device powered state.
+	Fix missing Powered property changed signals.
+	Fix canceling of a network connection attempt.
+	Fix stalled configuration issue with supplicant.
+	Fix detection of association errors from supplicant.
+	Fix issue with wrong scanning state information.
+	Fix hidden SSID detection routines.
+	Fix visible Ethernet services even without carrier.
+	Add global method call to request scanning.
+	Add support for global technologies list.
+	Add support for delaying service list updates.
+	Update the overall D-Bus API documentation.
+
+ver 0.23:
+	Fix dhclient probe/remove race condition.
+	Fix handling of disconnected services during auto-connect.
+	Add support for proper group name of hidden networks.
+	Add support for storing SSID details of hidden networks.
+
+ver 0.22:
+	Fix wrong auto-connect procedure after user connection.
+	Fix invalid update of already connected network.
+	Fix idle state handling after disconnecting device.
+	Fix disconnect race condition in WiFi supplicant.
+	Fix WiFi signal strength reporting.
+
+ver 0.21:
+	Add udev based network device detection.
+	Add support for global auto-connect feature.
+	Add support for basic service drag and drop.
+	Fix missing passphrase cleanup on service removal.
+	Fix potential duplicate network creation.
+	Fix handling of WEP shared keys.
+
+ver 0.20:
+	Add plugin for Intel WiMAX SDK support.
+	Add special handling for default vendor SSIDs.
+	Add support for default gateway in different network.
+	Add support for automatic switching of default gateway.
+	Add support for asynchronous handling of Powered property.
+	Add support for connecting/disconnecting Ethernet services.
+	Add support for more detailed error states of services.
+	Add support for clearing error state via ClearProperty.
+	Fix error code for invalid or unknown properties.
+	Fix various timeout handling issues.
+	Remove Policy and Priority device and network properties.
+
+ver 0.19:
+	Add hidden networks to the service list.
+	Add support for storing the service name.
+	Fix service list sorting for connected services.
+	Fix missing cancel command when operation times out.
+	Fix various issues with service favorite handling.
+	Remove Available and Remember network properties.
+
+ver 0.18:
+	Add support for asynchronous service connect method.
+	Fix broken storage of service favorite details.
+
+ver 0.17:
+	Add AT chat library implementation.
+	Fix service lookup for WiFi and WiMAX devices.
+	Fix service state signal emission and error handling.
+	Fix storing and loading of configured passphrases for services.
+
+ver 0.16:
+	Update Intel OSPM support to latest specification.
+	Add initial support for new service interface.
+	Add support for builtin plugins.
+	Add extra warning if no nameserver is defined.
+	Add error reporting for state and storage directory creation.
+	Add error message for network and device storing failures
+	Fix stale entry in gateway list after connection changes.
+	Fix handling of DHCP results with no nameserver.
+	Fix infinite loop for service lookup.
+	Fix various format string warnings.
+
+ver 0.15:
+	Detect VMware network interface and ignore them.
+	Fix setting of scan_ssid for hidden networks.
+	Fix empty network name property.
+
+ver 0.14:
+	Add support for detecting DHCP failures.
+	Add support for joining hidden WiFi networks.
+	Add support for device and network address property.
+	Add support for default /etc/resolv.conf generation.
+	Fix issue with wrong address setting for loopback.
+	Fix detection of WiFi access point changes.
+	Fix crash with blob properties.
+
+ver 0.13:
+	Add support for notification infrastructure.
+	Add fully dynamic property storage capabilities.
+	Fix broken loading of last network on bootup.
+	Fix crash when unplugging WiFi devices.
+	Rename OSPM plugin to Intel OSPM plugin.
+	Rename WiMAX plugin to Intel WiMAX SDK plugin.
+
+ver 0.12:
+	Fix connection state change handling.
+	Fix network list enumeration.
+	Fix broken driver matching for devices.
+	Fix issue with network identifier lookup.
+
+ver 0.11:
+	Add plugin priority handling.
+	Add network type for WiMAX.
+	Fix network protocol selection for Bluetooth PAN.
+	Fix parameters for Bluetooth PAN disconnect method.
+
+ver 0.10:
+	Fix races with connection signals.
+	Fix automatic switching of default connection.
+
+ver 0.9:
+	Rename FlightMode to OfflineMode.
+	Add static IPv4 setting support for Ethernet devices.
+	Add extra options to exclude devices and plugins.
+	Add support for toggling debug output.
+	Add support for ScanInterval property.
+	Fix handling of disconnect commands from applications.
+	Fix detection of networks that are out of range.
+	Fix setting network remember status.
+	Fix argument type checking of properties.
+
+ver 0.8:
+	Add Device and Network property to connection interface.
+	Add option to disable installation of data files.
+	Add command line option to show version number.
+	Fix signal emission for network changes.
+
+ver 0.7:
+	Add basic support for flight mode.
+	Add support for multiple storage drivers.
+	Add support for RTNL newlink watch API.
+	Add support for different security privileges.
+	Add support for device and network priorities.
+	Add functions for setting network properties.
+	Fix issue with listing devices without a driver.
+	Fix issue with WiFi scanning indication.
+	Fix detection of WiFi security changes.
+	Update WiFi driver to use new network helpers.
+	Install different D-Bus configuration for PolicyKit.
+
+ver 0.6:
+	Add CONNMAN_API_SUBJECT_TO_CHANGE definition.
+	Add detailed configuration options.
+	Add various D-Bus helper functions.
+	Add generic device driver infrastructure.
+	Add generic network driver infrastructure.
+	Add property for WiFi network mode.
+	Add property for network interface name.
+	Add property for global connection policy.
+	Add support for verbose compiler warnings.
+	Add support for device detection via udev.
+	Add support for systems with udhcpc.
+	Add support for Bluetooth PAN networks.
+	Fix WiFi issue with DHCP restart after handshake.
+	Fix exported symbols list creation.
+	Remove deprecated and unused plugins.
+
+ver 0.5:
+	Add support for handling Bluetooth adapters.
+	Add support for activating wpa_supplicant on demand.
+	Add Device property to network objects.
+	Add Scanning property to device objects.
+	Fix Name property of device objects.
+	Fix WiFi SSID to object path conversion.
+	Fix duplicate wireless scan results.
+	Fix built issue with libudev and uClibc.
+	Fix issues with element registration failures.
+
+ver 0.4:
+	Add DNS proxy resolver plugin.
+	Add support for default connections.
+	Add support for gateway change notifications.
+	Add signal strength property for connections.
+	Add property for connection type.
+	Fix issue with carrier detection.
+	Fix broken resolvconf plugin.
+
+ver 0.3:
+	Add support for automatically connecting known networks.
+	Add improved framework for handling resolver details.
+	Add generic signal strength property.
+	Fix bridge and WiMAX device detection.
+	Fix network listing for Ethernet devices.
+
+ver 0.2:
+	Add support for indicating network changes.
+	Add support for signal strength property.
+	Add support for unique device names.
+	Fix broken device enumeration.
+	Fix issue with device removal callback.
+	Fix issue with wpa_supplicant disconnecting.
+	Fix D-Bus access policy configuration.
+
+ver 0.1:
+	Initial public release.
diff --git a/connman/HACKING b/connman/HACKING
new file mode 100644
index 0000000..80382ed
--- /dev/null
+++ b/connman/HACKING
@@ -0,0 +1,109 @@
+Hacking on Connection Manager
+*****************************
+
+
+Build tools requirements
+========================
+
+When building and testing directly from the repository it is important to
+have at least automake version 1.10 or later installed. All modern
+distributions should default to the latest version, but it seems that
+Debian's default is still an earlier version:
+
+  Check version
+    # dpkg -l '*automake*'
+
+  Install new version
+    # apt-get install automake1.10
+    # update-alternatives --config automake
+
+
+Working with the source code repository
+=======================================
+
+The repository contains two extra scripts that accomplish the bootstrap
+process. One is called "bootstrap" which is the basic scripts that uses the
+autotools scripts to create the needed files for building and installing.
+It makes sure to call the right programs depending on the usage of shared or
+static libraries or translations etc.
+
+The second program is called "bootstrap-configure". This program will make
+sure to properly clean the repository, call the "bootstrap" script and then
+call configure with proper settings for development. It will use the best
+options and pass them over to configure. These options normally include
+the enabling the maintainer mode and the debugging features.
+
+So while in a normal source project the call "./configure ..." is used to
+configure the project with its settings like prefix and extra options. In
+case of bare repositories call "./bootstrap-configure" and it will bootstrap
+the repository and calls configure with all the correct options to make
+development easier.
+
+In case of preparing for a release with "make distcheck", don't use
+bootstrap-configure since it could export development specific settings.
+
+So the normal steps to checkout, build and install such a repository is
+like this:
+
+  Checkout repository
+    # git clone git://git.kernel.org/pub/scm/network/connman/connman.git
+    # cd connman
+
+  Configure and build
+    # ./bootstrap-configure
+    # make
+
+  Check installation
+    # make install DESTDIR=$PWD/x
+    # find x
+    # rm -rf x
+
+  Check distribution
+    # make distcheck
+
+  Final installation
+    # sudo make install
+
+  Remove autogenerated files
+    # make maintainer-clean
+
+
+Running from within the source code repository
+==============================================
+
+When using "./configure --enable-maintainer-mode" the automake scripts will
+use the plugins directly from within the repository. This removes the need
+to use "make install" when testing "connmand". The "bootstrap-configure"
+automatically includes this option.
+
+  Run daemon in foreground with debugging
+    # sudo ./src/connmand -n -d 'plugins/*'
+
+The debugging option -d takes an argument. This argument can be a comma
+separated list of file names like 'plugins/wifi.c,plugins/ethernet.c' to
+enable debugs in these files. Simple glob style pattern matching is
+supported in this list.
+
+For production installations or distribution packaging it is important that
+the "--enable-maintainer-mode" option is NOT used.
+
+Some times it is important to restrict the available interfaces. For example
+in cases where testing happens over a network connection. The "-i" command
+line switch allows to specify a glob pattern for the interface names.
+
+  Run daemon for wireless interfaces
+    # sudo ./src/connmand -n -i wlan*
+
+
+Debugging the D-Bus interface during runtime
+============================================
+
+Running the daemon with debugging information in the foreground is quite
+verbose and sometimes not really helpful. The "monitor-connman" script
+allows to monitor "PropertyChanged" D-Bus signals from various interfaces.
+
+Every "PropertyChanged" signal will generate a line of output. Some of them
+can get very complex. The first detail inside "{ ... }" is the interface
+name (without its service name prefix). The second detail inside "[ ... ]"
+is the object path. And after that it is followed by a key and value of
+the property that changed.
diff --git a/connman/INSTALL b/connman/INSTALL
new file mode 100644
index 0000000..56b077d
--- /dev/null
+++ b/connman/INSTALL
@@ -0,0 +1,236 @@
+Installation Instructions
+*************************
+
+Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005 Free
+Software Foundation, Inc.
+
+This file is free documentation; the Free Software Foundation gives
+unlimited permission to copy, distribute and modify it.
+
+Basic Installation
+==================
+
+These are generic installation instructions.
+
+   The `configure' shell script attempts to guess correct values for
+various system-dependent variables used during compilation.  It uses
+those values to create a `Makefile' in each directory of the package.
+It may also create one or more `.h' files containing system-dependent
+definitions.  Finally, it creates a shell script `config.status' that
+you can run in the future to recreate the current configuration, and a
+file `config.log' containing compiler output (useful mainly for
+debugging `configure').
+
+   It can also use an optional file (typically called `config.cache'
+and enabled with `--cache-file=config.cache' or simply `-C') that saves
+the results of its tests to speed up reconfiguring.  (Caching is
+disabled by default to prevent problems with accidental use of stale
+cache files.)
+
+   If you need to do unusual things to compile the package, please try
+to figure out how `configure' could check whether to do them, and mail
+diffs or instructions to the address given in the `README' so they can
+be considered for the next release.  If you are using the cache, and at
+some point `config.cache' contains results you don't want to keep, you
+may remove or edit it.
+
+   The file `configure.ac' (or `configure.in') is used to create
+`configure' by a program called `autoconf'.  You only need
+`configure.ac' if you want to change it or regenerate `configure' using
+a newer version of `autoconf'.
+
+The simplest way to compile this package is:
+
+  1. `cd' to the directory containing the package's source code and type
+     `./configure' to configure the package for your system.  If you're
+     using `csh' on an old version of System V, you might need to type
+     `sh ./configure' instead to prevent `csh' from trying to execute
+     `configure' itself.
+
+     Running `configure' takes awhile.  While running, it prints some
+     messages telling which features it is checking for.
+
+  2. Type `make' to compile the package.
+
+  3. Optionally, type `make check' to run any self-tests that come with
+     the package.
+
+  4. Type `make install' to install the programs and any data files and
+     documentation.
+
+  5. You can remove the program binaries and object files from the
+     source code directory by typing `make clean'.  To also remove the
+     files that `configure' created (so you can compile the package for
+     a different kind of computer), type `make distclean'.  There is
+     also a `make maintainer-clean' target, but that is intended mainly
+     for the package's developers.  If you use it, you may have to get
+     all sorts of other programs in order to regenerate files that came
+     with the distribution.
+
+Compilers and Options
+=====================
+
+Some systems require unusual options for compilation or linking that the
+`configure' script does not know about.  Run `./configure --help' for
+details on some of the pertinent environment variables.
+
+   You can give `configure' initial values for configuration parameters
+by setting variables in the command line or in the environment.  Here
+is an example:
+
+     ./configure CC=c89 CFLAGS=-O2 LIBS=-lposix
+
+   *Note Defining Variables::, for more details.
+
+Compiling For Multiple Architectures
+====================================
+
+You can compile the package for more than one kind of computer at the
+same time, by placing the object files for each architecture in their
+own directory.  To do this, you must use a version of `make' that
+supports the `VPATH' variable, such as GNU `make'.  `cd' to the
+directory where you want the object files and executables to go and run
+the `configure' script.  `configure' automatically checks for the
+source code in the directory that `configure' is in and in `..'.
+
+   If you have to use a `make' that does not support the `VPATH'
+variable, you have to compile the package for one architecture at a
+time in the source code directory.  After you have installed the
+package for one architecture, use `make distclean' before reconfiguring
+for another architecture.
+
+Installation Names
+==================
+
+By default, `make install' will install the package's files in
+`/usr/local/bin', `/usr/local/man', etc.  You can specify an
+installation prefix other than `/usr/local' by giving `configure' the
+option `--prefix=PREFIX'.
+
+   You can specify separate installation prefixes for
+architecture-specific files and architecture-independent files.  If you
+give `configure' the option `--exec-prefix=PREFIX', the package will
+use PREFIX as the prefix for installing programs and libraries.
+Documentation and other data files will still use the regular prefix.
+
+   In addition, if you use an unusual directory layout you can give
+options like `--bindir=DIR' to specify different values for particular
+kinds of files.  Run `configure --help' for a list of the directories
+you can set and what kinds of files go in them.
+
+   If the package supports it, you can cause programs to be installed
+with an extra prefix or suffix on their names by giving `configure' the
+option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'.
+
+Optional Features
+=================
+
+Some packages pay attention to `--enable-FEATURE' options to
+`configure', where FEATURE indicates an optional part of the package.
+They may also pay attention to `--with-PACKAGE' options, where PACKAGE
+is something like `gnu-as' or `x' (for the X Window System).  The
+`README' should mention any `--enable-' and `--with-' options that the
+package recognizes.
+
+   For packages that use the X Window System, `configure' can usually
+find the X include and library files automatically, but if it doesn't,
+you can use the `configure' options `--x-includes=DIR' and
+`--x-libraries=DIR' to specify their locations.
+
+Specifying the System Type
+==========================
+
+There may be some features `configure' cannot figure out automatically,
+but needs to determine by the type of machine the package will run on.
+Usually, assuming the package is built to be run on the _same_
+architectures, `configure' can figure that out, but if it prints a
+message saying it cannot guess the machine type, give it the
+`--build=TYPE' option.  TYPE can either be a short name for the system
+type, such as `sun4', or a canonical name which has the form:
+
+     CPU-COMPANY-SYSTEM
+
+where SYSTEM can have one of these forms:
+
+     OS KERNEL-OS
+
+   See the file `config.sub' for the possible values of each field.  If
+`config.sub' isn't included in this package, then this package doesn't
+need to know the machine type.
+
+   If you are _building_ compiler tools for cross-compiling, you should
+use the `--target=TYPE' option to select the type of system they will
+produce code for.
+
+   If you want to _use_ a cross compiler, that generates code for a
+platform different from the build platform, you should specify the
+"host" platform (i.e., that on which the generated programs will
+eventually be run) with `--host=TYPE'.
+
+Sharing Defaults
+================
+
+If you want to set default values for `configure' scripts to share, you
+can create a site shell script called `config.site' that gives default
+values for variables like `CC', `cache_file', and `prefix'.
+`configure' looks for `PREFIX/share/config.site' if it exists, then
+`PREFIX/etc/config.site' if it exists.  Or, you can set the
+`CONFIG_SITE' environment variable to the location of the site script.
+A warning: not all `configure' scripts look for a site script.
+
+Defining Variables
+==================
+
+Variables not defined in a site shell script can be set in the
+environment passed to `configure'.  However, some packages may run
+configure again during the build, and the customized values of these
+variables may be lost.  In order to avoid this problem, you should set
+them in the `configure' command line, using `VAR=value'.  For example:
+
+     ./configure CC=/usr/local2/bin/gcc
+
+causes the specified `gcc' to be used as the C compiler (unless it is
+overridden in the site shell script).  Here is a another example:
+
+     /bin/bash ./configure CONFIG_SHELL=/bin/bash
+
+Here the `CONFIG_SHELL=/bin/bash' operand causes subsequent
+configuration-related scripts to be executed by `/bin/bash'.
+
+`configure' Invocation
+======================
+
+`configure' recognizes the following options to control how it operates.
+
+`--help'
+`-h'
+     Print a summary of the options to `configure', and exit.
+
+`--version'
+`-V'
+     Print the version of Autoconf used to generate the `configure'
+     script, and exit.
+
+`--cache-file=FILE'
+     Enable the cache: use and save the results of the tests in FILE,
+     traditionally `config.cache'.  FILE defaults to `/dev/null' to
+     disable caching.
+
+`--config-cache'
+`-C'
+     Alias for `--cache-file=config.cache'.
+
+`--quiet'
+`--silent'
+`-q'
+     Do not print messages saying which checks are being made.  To
+     suppress all normal output, redirect it to `/dev/null' (any error
+     messages will still be shown).
+
+`--srcdir=DIR'
+     Look for the package's source code in directory DIR.  Usually
+     `configure' can determine that directory automatically.
+
+`configure' also accepts some other, not widely useful, options.  Run
+`configure --help' for more details.
+
diff --git a/connman/Makefile.am b/connman/Makefile.am
new file mode 100644
index 0000000..aa5ea74
--- /dev/null
+++ b/connman/Makefile.am
@@ -0,0 +1,475 @@
+
+AM_MAKEFLAGS = --no-print-directory
+
+noinst_LTLIBRARIES =
+
+includedir = @includedir@/connman
+
+include_HEADERS = include/log.h include/plugin.h \
+			include/notifier.h include/service.h \
+			include/resolver.h include/ipconfig.h \
+			include/device.h include/network.h include/inet.h \
+			include/storage.h include/provision.h \
+			include/session.h include/ipaddress.h include/agent.h \
+			include/inotify.h include/peer.h include/machine.h \
+			include/technology.h \
+			include/dbus.h \
+			include/gdbus.h
+
+nodist_include_HEADERS = include/version.h
+
+noinst_HEADERS = include/rtnl.h include/task.h \
+			include/option.h \
+			include/provider.h include/vpn-dbus.h \
+			include/utsname.h include/timeserver.h include/proxy.h \
+			include/setting.h
+
+local_headers = $(foreach file,$(include_HEADERS) $(nodist_include_HEADERS) \
+			$(noinst_HEADERS), include/connman/$(notdir $(file)))
+
+
+noinst_LTLIBRARIES += gdbus/libgdbus-internal.la
+
+gdbus_libgdbus_internal_la_SOURCES = gdbus/gdbus.h \
+				gdbus/mainloop.c gdbus/watch.c \
+				gdbus/object.c gdbus/client.c gdbus/polkit.c
+
+gdhcp_sources = gdhcp/gdhcp.h gdhcp/common.h gdhcp/common.c gdhcp/client.c \
+		gdhcp/server.c gdhcp/ipv4ll.h gdhcp/ipv4ll.c gdhcp/unaligned.h \
+		gdhcp/timer.c gdhcp/timer.h
+
+gweb_sources = gweb/gweb.h gweb/gweb.c gweb/gresolv.h gweb/gresolv.c
+
+if WISPR
+gweb_sources += gweb/giognutls.h gweb/giognutls.c
+else
+gweb_sources += gweb/giognutls.h gweb/gionotls.c
+endif
+
+shared_sources = src/shared/util.h src/shared/util.c \
+		src/shared/netlink.h src/shared/netlink.c
+
+if DATAFILES
+
+if NMCOMPAT
+nmcompat_conf = plugins/connman-nmcompat.conf
+endif
+
+dbusconfdir = @DBUS_CONFDIR@
+
+dbusconf_DATA = src/connman.conf $(nmcompat_conf)
+
+if VPN
+dbusconf_DATA += vpn/connman-vpn-dbus.conf
+dbusservicedir = @DBUS_DATADIR@
+dbusservice_DATA = vpn/net.connman.vpn.service
+endif
+
+if SYSTEMD
+systemdunitdir = @SYSTEMD_UNITDIR@
+
+systemdunit_DATA = src/connman.service
+
+if VPN
+systemdunit_DATA += vpn/connman-vpn.service
+endif
+endif
+endif
+
+service_files_sources = src/connman.service.in src/net.connman.service.in \
+				vpn/connman-vpn.service.in \
+				vpn/net.connman.vpn.service.in
+service_files = src/connman.service src/net.connman.service \
+				vpn/connman-vpn.service \
+				vpn/net.connman.vpn.service
+
+plugin_LTLIBRARIES =
+
+plugin_objects =
+
+builtin_modules =
+builtin_sources =
+builtin_libadd =
+builtin_cflags =
+
+noinst_PROGRAMS =
+bin_PROGRAMS =
+
+unit_objects =
+
+MANUAL_PAGES =
+
+sbin_PROGRAMS = src/connmand
+
+src_connmand_SOURCES = $(gdhcp_sources) $(gweb_sources) \
+			$(builtin_sources) $(shared_sources) src/connman.ver \
+			src/main.c src/connman.h src/log.c \
+			src/error.c src/plugin.c src/task.c \
+			src/device.c src/network.c src/connection.c \
+			src/manager.c src/service.c \
+			src/clock.c src/timezone.c src/agent-connman.c \
+			src/agent.c src/notifier.c src/provider.c \
+			src/resolver.c src/ipconfig.c src/detect.c src/inet.c \
+			src/dhcp.c src/dhcpv6.c src/rtnl.c src/proxy.c \
+			src/utsname.c src/timeserver.c src/rfkill.c \
+			src/storage.c src/dbus.c src/config.c \
+			src/technology.c src/counter.c src/ntp.c \
+			src/session.c src/tethering.c src/wpad.c src/wispr.c \
+			src/stats.c src/iptables.c src/dnsproxy.c src/6to4.c \
+			src/ippool.c src/bridge.c src/nat.c src/ipaddress.c \
+			src/inotify.c src/firewall.c src/ipv6pd.c src/peer.c \
+			src/peer_service.c src/machine.c src/util.c \
+			src/rlimits.c
+
+src_connmand_LDADD = gdbus/libgdbus-internal.la $(builtin_libadd) \
+			@GLIB_LIBS@ @DBUS_LIBS@ @XTABLES_LIBS@ @GNUTLS_LIBS@ \
+			-lresolv -ldl -lrt
+
+src_connmand_LDFLAGS = -Wl,--export-dynamic \
+				-Wl,--version-script=$(srcdir)/src/connman.ver
+
+if VPN
+vpn_plugin_LTLIBRARIES =
+
+vpn_plugin_objects =
+
+builtin_vpn_modules =
+builtin_vpn_sources =
+builtin_vpn_libadd =
+builtin_vpn_cflags =
+
+sbin_PROGRAMS += vpn/connman-vpnd
+
+vpn_connman_vpnd_SOURCES = $(builtin_vpn_sources) \
+			$(gweb_sources) vpn/vpn.ver vpn/main.c vpn/vpn.h \
+			src/log.c src/error.c src/plugin.c src/task.c \
+			vpn/vpn-manager.c vpn/vpn-provider.c \
+			vpn/vpn-provider.h vpn/vpn-rtnl.h \
+			vpn/vpn-ipconfig.c src/inet.c vpn/vpn-rtnl.c \
+			src/dbus.c src/storage.c src/ipaddress.c src/agent.c \
+			vpn/vpn-agent.c vpn/vpn-agent.h src/inotify.c \
+			vpn/vpn-config.c
+
+vpn_connman_vpnd_LDADD = gdbus/libgdbus-internal.la $(builtin_vpn_libadd) \
+				@GLIB_LIBS@ @DBUS_LIBS@ @GNUTLS_LIBS@ \
+				-lresolv -ldl
+
+vpn_connman_vpnd_LDFLAGS = -Wl,--export-dynamic \
+				-Wl,--version-script=$(srcdir)/vpn/vpn.ver
+endif
+
+BUILT_SOURCES = $(local_headers) src/builtin.h $(service_files) scripts/connman
+
+if VPN
+BUILT_SOURCES += vpn/builtin.h
+endif
+
+CLEANFILES = src/connman.conf $(BUILT_SOURCES) $(service_files)
+
+statedir = $(localstatedir)/run/connman
+vpn_statedir = $(localstatedir)/run/connman-vpn
+
+if VPN
+vpn_plugindir = $(libdir)/connman/plugins-vpn
+endif
+
+plugindir = $(libdir)/connman/plugins
+
+scriptdir = $(libdir)/connman/scripts
+
+storagedir = $(localstatedir)/lib/connman
+vpn_storagedir = $(localstatedir)/lib/connman-vpn
+
+configdir = ${sysconfdir}/connman
+
+if MAINTAINER_MODE
+if VPN
+build_vpn_plugindir = $(abs_top_srcdir)/vpn/plugins/.libs
+endif
+build_plugindir = $(abs_top_srcdir)/plugins/.libs
+build_scriptdir = $(abs_top_srcdir)/scripts
+else
+build_plugindir = $(plugindir)
+build_scriptdir = $(scriptdir)
+if VPN
+build_vpn_plugindir = $(vpn_plugindir)
+endif
+endif
+
+AM_CFLAGS = @DBUS_CFLAGS@ @GLIB_CFLAGS@ @XTABLES_CFLAGS@ \
+				@GNUTLS_CFLAGS@ $(builtin_cflags) \
+				-DCONNMAN_PLUGIN_BUILTIN \
+				-DSTATEDIR=\""$(statedir)"\" \
+				-DVPN_STATEDIR=\""$(vpn_statedir)"\" \
+				-DPLUGINDIR=\""$(build_plugindir)"\" \
+				-DSCRIPTDIR=\""$(build_scriptdir)"\" \
+				-DSTORAGEDIR=\""$(storagedir)\"" \
+				-DVPN_STORAGEDIR=\""$(vpn_storagedir)\"" \
+				-DCONFIGDIR=\""$(configdir)\""
+
+if VPN
+AM_CPPFLAGS = -I$(builddir)/include -I$(srcdir)/gdbus
+else
+AM_CPPFLAGS = -I$(builddir)/include -I$(builddir)/src -I$(srcdir)/gdbus
+endif
+
+src_connmand_CFLAGS = @DBUS_CFLAGS@ @GLIB_CFLAGS@ @XTABLES_CFLAGS@ \
+				@GNUTLS_CFLAGS@ $(builtin_cflags) \
+				-DCONNMAN_PLUGIN_BUILTIN \
+				-DSTATEDIR=\""$(statedir)"\" \
+				-DPLUGINDIR=\""$(build_plugindir)"\" \
+				-DSCRIPTDIR=\""$(build_scriptdir)"\" \
+				-DSTORAGEDIR=\""$(storagedir)\"" \
+				-DVPN_STORAGEDIR=\""$(vpn_storagedir)\"" \
+				-DCONFIGDIR=\""$(configdir)\"" \
+				-I$(builddir)/src
+
+EXTRA_DIST = src/genbuiltin src/connman-dbus.conf src/connman-polkit.conf \
+				plugins/connman-nmcompat.conf \
+				$(service_files_sources) scripts/connman.in
+
+if VPN
+vpn_connman_vpnd_CFLAGS = @DBUS_CFLAGS@ @GLIB_CFLAGS@ \
+				$(builtin_vpn_cflags) \
+				-DCONNMAN_PLUGIN_BUILTIN \
+				-DVPN_STATEDIR=\""$(vpn_statedir)"\" \
+				-DPLUGINDIR=\""$(build_vpn_plugindir)"\" \
+				-DSCRIPTDIR=\""$(build_scriptdir)"\" \
+				-DSTORAGEDIR=\""$(storagedir)\"" \
+				-DVPN_STORAGEDIR=\""$(vpn_storagedir)\"" \
+				-DCONFIGDIR=\""$(configdir)\"" \
+				-I$(builddir)/vpn
+
+endif
+
+EXTRA_DIST += vpn/vpn-dbus.conf vpn/vpn-polkit.conf
+
+script_DATA =
+script_PROGRAMS =
+script_LTLIBRARIES =
+
+include Makefile.plugins
+
+if CLIENT
+bin_PROGRAMS += client/connmanctl
+
+MANUAL_PAGES += doc/connmanctl.1
+
+client_connmanctl_SOURCES = client/dbus_helpers.h client/dbus_helpers.c \
+			client/services.h client/services.c \
+			client/commands.h client/commands.c \
+			client/input.h client/input.c \
+			client/agent.h client/agent.c \
+			client/peers.h client/peers.c \
+			client/vpnconnections.h client/vpnconnections.c \
+			client/main.c
+
+client_connmanctl_LDADD = gdbus/libgdbus-internal.la @DBUS_LIBS@ @GLIB_LIBS@ \
+				-lreadline -ldl
+endif
+
+noinst_PROGRAMS += unit/test-ippool
+
+unit_test_ippool_SOURCES = src/log.c src/dbus.c src/error.c \
+					src/ippool.c unit/test-ippool.c
+unit_test_ippool_LDADD = gdbus/libgdbus-internal.la \
+				@GLIB_LIBS@ @DBUS_LIBS@ -ldl
+
+TESTS = unit/test-ippool
+
+if WISPR
+noinst_PROGRAMS += tools/wispr
+
+tools_wispr_SOURCES = $(gweb_sources) tools/wispr.c
+tools_wispr_LDADD = @GLIB_LIBS@ @GNUTLS_LIBS@ -lresolv
+endif
+
+if TOOLS
+noinst_PROGRAMS += tools/supplicant-test \
+			tools/dhcp-test tools/dhcp-server-test \
+			tools/addr-test tools/web-test tools/resolv-test \
+			tools/dbus-test tools/polkit-test \
+			tools/iptables-test tools/tap-test tools/wpad-test \
+			tools/stats-tool tools/private-network-test \
+			tools/session-test tools/iptables-unit \
+			tools/dnsproxy-test tools/netlink-test
+
+tools_supplicant_test_SOURCES = tools/supplicant-test.c \
+			tools/supplicant-dbus.h tools/supplicant-dbus.c \
+			tools/supplicant.h tools/supplicant.c
+tools_supplicant_test_LDADD = gdbus/libgdbus-internal.la \
+				@GLIB_LIBS@ @DBUS_LIBS@
+
+tools_web_test_SOURCES = $(gweb_sources) tools/web-test.c
+tools_web_test_LDADD = @GLIB_LIBS@ @GNUTLS_LIBS@ -lresolv
+
+tools_resolv_test_SOURCES = gweb/gresolv.h gweb/gresolv.c tools/resolv-test.c
+tools_resolv_test_LDADD = @GLIB_LIBS@ -lresolv
+
+tools_wpad_test_SOURCES = gweb/gresolv.h gweb/gresolv.c tools/wpad-test.c
+tools_wpad_test_LDADD = @GLIB_LIBS@ -lresolv
+
+tools_stats_tool_LDADD = @GLIB_LIBS@
+
+tools_dhcp_test_SOURCES = $(gdhcp_sources) tools/dhcp-test.c
+tools_dhcp_test_LDADD = @GLIB_LIBS@
+
+tools_dhcp_server_test_SOURCES = $(gdhcp_sources) tools/dhcp-server-test.c
+tools_dhcp_server_test_LDADD = @GLIB_LIBS@
+
+tools_dbus_test_SOURCES = tools/dbus-test.c
+tools_dbus_test_LDADD = gdbus/libgdbus-internal.la @GLIB_LIBS@ @DBUS_LIBS@
+
+tools_polkit_test_LDADD = @DBUS_LIBS@
+
+tools_iptables_test_SOURCES = src/log.c src/iptables.c tools/iptables-test.c
+tools_iptables_test_LDADD = @GLIB_LIBS@ @XTABLES_LIBS@ -ldl
+
+tools_private_network_test_LDADD = @GLIB_LIBS@ @DBUS_LIBS@
+
+tools_session_test_SOURCES = src/log.c src/dbus.c src/error.c \
+		tools/session-test.c tools/session-utils.c tools/manager-api.c \
+		tools/session-api.c tools/session-test.h
+tools_session_test_LDADD = gdbus/libgdbus-internal.la \
+				@GLIB_LIBS@ @DBUS_LIBS@ -ldl
+
+tools_iptables_unit_CFLAGS = @DBUS_CFLAGS@ @GLIB_CFLAGS@ @XTABLES_CFLAGS@ \
+		-DIPTABLES_SAVE=\""${IPTABLES_SAVE}"\"
+tools_iptables_unit_SOURCES = src/log.c \
+		 src/iptables.c src/firewall.c src/nat.c tools/iptables-unit.c
+tools_iptables_unit_LDADD = gdbus/libgdbus-internal.la \
+				@GLIB_LIBS@ @DBUS_LIBS@ @XTABLES_LIBS@ -ldl
+
+tools_dnsproxy_test_SOURCES = tools/dnsproxy-test.c
+tools_dnsproxy_test_LDADD = @GLIB_LIBS@
+
+tools_netlink_test_SOURCES =$(shared_sources) tools/netlink-test.c
+tools_netlink_test_LDADD = @GLIB_LIBS@
+
+endif
+
+test_scripts = test/get-state test/list-services \
+		test/monitor-services test/test-clock \
+		test/simple-agent test/show-introspection test/test-compat \
+		test/test-manager test/test-connman test/monitor-connman \
+		test/connect-provider test/remove-provider \
+		test/test-counter test/set-ipv4-method test/set-ipv6-method \
+		test/get-services test/get-proxy-autoconfig test/set-proxy \
+		test/enable-tethering test/disable-tethering test/backtrace \
+		test/test-session test/p2p-on-supplicant \
+		test/test-new-supplicant test/service-move-before \
+		test/set-global-timeservers test/get-global-timeservers \
+		test/set-nameservers test/set-domains test/set-timeservers \
+		test/set-clock
+
+test_scripts += test/vpn-connect test/vpn-disconnect test/vpn-get \
+		test/monitor-vpn test/vpn-property
+
+if TEST
+testdir = $(pkglibdir)/test
+test_SCRIPTS = $(test_scripts)
+endif
+
+EXTRA_DIST += $(test_scripts)
+
+EXTRA_DIST += doc/overview-api.txt doc/behavior-api.txt \
+				doc/coding-style.txt doc/wifi-p2p-overview.txt \
+				doc/vpn-agent-api.txt doc/peer-api.txt \
+				doc/ipconfig-api.txt doc/plugin-api.txt \
+				doc/manager-api.txt doc/agent-api.txt \
+				doc/service-api.txt doc/technology-api.txt \
+				doc/counter-api.txt doc/config-format.txt \
+				doc/clock-api.txt doc/session-api.txt \
+				doc/session-overview.txt doc/backtrace.txt \
+				doc/advanced-configuration.txt \
+				doc/vpn-config-format.txt \
+				doc/vpn-connection-api.txt \
+				doc/vpn-manager-api.txt doc/vpn-overview.txt \
+				doc/session-policy-format.txt
+
+EXTRA_DIST += src/main.conf \
+		src/eduroam.config
+
+MANUAL_PAGES += doc/connman.8 doc/connman.conf.5
+
+dist_man_MANS = $(MANUAL_PAGES)
+
+pkgconfigdir = $(libdir)/pkgconfig
+
+pkgconfig_DATA = connman.pc
+
+DISTCHECK_CONFIGURE_FLAGS = --disable-datafiles \
+				--enable-hh2serial-gps \
+				--enable-openconnect \
+				--enable-openvpn \
+				--enable-vpnc \
+				--enable-session-policy-local \
+				--enable-nmcompat \
+				--enable-polkit
+
+DISTCLEANFILES = $(pkgconfig_DATA)
+
+MAINTAINERCLEANFILES = Makefile.in \
+	aclocal.m4 configure config.h.in config.sub config.guess \
+	ltmain.sh depcomp compile missing install-sh mkinstalldirs test-driver
+
+
+src/builtin.h: src/genbuiltin $(builtin_sources)
+	$(AM_V_at)$(MKDIR_P) $(dir $@)
+	$(AM_V_GEN)$(srcdir)/src/genbuiltin $(builtin_modules) > $@
+
+vpn/builtin.h: src/genbuiltin $(builtin_vpn_sources)
+	$(AM_V_at)$(MKDIR_P) $(dir $@)
+	$(AM_V_GEN)$(srcdir)/src/genbuiltin $(builtin_vpn_modules) > $@
+
+src/connman.conf: src/connman-dbus.conf src/connman-polkit.conf
+if POLKIT
+	$(AM_V_GEN)cp $(srcdir)/src/connman-polkit.conf $@
+else
+	$(AM_V_GEN)cp $(srcdir)/src/connman-dbus.conf $@
+endif
+
+if VPN
+vpn/connman-vpn-dbus.conf: vpn/vpn-dbus.conf vpn/vpn-polkit.conf
+if POLKIT
+	$(AM_V_GEN)cp $(srcdir)/vpn/vpn-polkit.conf $@
+else
+	$(AM_V_GEN)cp $(srcdir)/vpn/vpn-dbus.conf $@
+endif
+endif
+
+if SELINUX
+if VPN
+EXTRA_DIST += connman-task.pp
+CLEANFILES += connman-task.pp
+endif
+
+connman-task.pp: vpn/connman-task.te
+	make -f /usr/share/selinux/devel/Makefile
+endif
+
+EXTRA_DIST += vpn/connman-task.te
+
+do_subst = $(AM_V_GEN)$(SED) \
+		-e 's,[@]prefix[@],$(prefix),g' \
+		-e 's,[@]sbindir[@],$(sbindir),g' \
+		-e 's,[@]sysconfdir[@],$(sysconfdir),g'
+
+%.service: %.service.in Makefile
+	$(AM_V_at)$(MKDIR_P) $(dir $@)
+	$(do_subst) < $< > $@
+
+scripts/connman: scripts/connman.in Makefile
+	$(AM_V_at)$(MKDIR_P) $(dir $@)
+	$(do_subst) < $< > $@
+
+include/connman/version.h: include/version.h
+	$(AM_V_at)$(MKDIR_P) include/connman
+	$(AM_V_GEN)$(LN_S) $(abs_top_builddir)/$< $@
+
+include/connman/%.h: $(abs_top_srcdir)/include/%.h
+	$(AM_V_at)$(MKDIR_P) include/connman
+	$(AM_V_GEN)$(LN_S) $< $@
+
+clean-local:
+	@$(RM) -rf include/connman
diff --git a/connman/Makefile.in b/connman/Makefile.in
new file mode 100644
index 0000000..6c71a6f
--- /dev/null
+++ b/connman/Makefile.in
@@ -0,0 +1,5397 @@
+# Makefile.in generated by automake 1.14.1 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994-2013 Free Software Foundation, Inc.
+
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+@SET_MAKE@
+
+
+
+
+
+VPATH = @srcdir@
+am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)'
+am__make_running_with_option = \
+  case $${target_option-} in \
+      ?) ;; \
+      *) echo "am__make_running_with_option: internal error: invalid" \
+              "target option '$${target_option-}' specified" >&2; \
+         exit 1;; \
+  esac; \
+  has_opt=no; \
+  sane_makeflags=$$MAKEFLAGS; \
+  if $(am__is_gnu_make); then \
+    sane_makeflags=$$MFLAGS; \
+  else \
+    case $$MAKEFLAGS in \
+      *\\[\ \	]*) \
+        bs=\\; \
+        sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \
+          | sed "s/$$bs$$bs[$$bs $$bs	]*//g"`;; \
+    esac; \
+  fi; \
+  skip_next=no; \
+  strip_trailopt () \
+  { \
+    flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \
+  }; \
+  for flg in $$sane_makeflags; do \
+    test $$skip_next = yes && { skip_next=no; continue; }; \
+    case $$flg in \
+      *=*|--*) continue;; \
+        -*I) strip_trailopt 'I'; skip_next=yes;; \
+      -*I?*) strip_trailopt 'I';; \
+        -*O) strip_trailopt 'O'; skip_next=yes;; \
+      -*O?*) strip_trailopt 'O';; \
+        -*l) strip_trailopt 'l'; skip_next=yes;; \
+      -*l?*) strip_trailopt 'l';; \
+      -[dEDm]) skip_next=yes;; \
+      -[JT]) skip_next=yes;; \
+    esac; \
+    case $$flg in \
+      *$$target_option*) has_opt=yes; break;; \
+    esac; \
+  done; \
+  test $$has_opt = yes
+am__make_dryrun = (target_option=n; $(am__make_running_with_option))
+am__make_keepgoing = (target_option=k; $(am__make_running_with_option))
+pkgdatadir = $(datadir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkglibexecdir = $(libexecdir)/@PACKAGE@
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+build_triplet = @build@
+host_triplet = @host@
+@WISPR_TRUE@am__append_1 = gweb/giognutls.h gweb/giognutls.c
+@WISPR_FALSE@am__append_2 = gweb/giognutls.h gweb/gionotls.c
+@DATAFILES_TRUE@@VPN_TRUE@am__append_3 = vpn/connman-vpn-dbus.conf
+@DATAFILES_TRUE@@SYSTEMD_TRUE@@VPN_TRUE@am__append_4 = vpn/connman-vpn.service
+noinst_PROGRAMS = unit/test-ippool$(EXEEXT) $(am__EXEEXT_2) \
+	$(am__EXEEXT_3)
+bin_PROGRAMS = $(am__EXEEXT_1)
+sbin_PROGRAMS = src/connmand$(EXEEXT) $(am__EXEEXT_4)
+@VPN_TRUE@am__append_5 = vpn/connman-vpnd
+@VPN_TRUE@am__append_6 = vpn/builtin.h
+script_PROGRAMS = $(am__EXEEXT_5) $(am__EXEEXT_6) $(am__EXEEXT_7)
+DIST_COMMON = $(srcdir)/Makefile.plugins $(srcdir)/Makefile.in \
+	$(srcdir)/Makefile.am $(top_srcdir)/configure \
+	$(am__configure_deps) $(srcdir)/config.h.in \
+	$(top_srcdir)/include/version.h.in $(srcdir)/connman.pc.in \
+	depcomp $(dist_man_MANS) $(include_HEADERS) $(noinst_HEADERS) \
+	test-driver AUTHORS COPYING ChangeLog INSTALL NEWS README TODO \
+	compile config.guess config.sub install-sh missing ltmain.sh
+@LOOPBACK_TRUE@am__append_7 = loopback
+@LOOPBACK_TRUE@am__append_8 = plugins/loopback.c
+@ETHERNET_TRUE@am__append_9 = ethernet
+@ETHERNET_TRUE@am__append_10 = plugins/ethernet.c
+@GADGET_TRUE@am__append_11 = gadget
+@GADGET_TRUE@am__append_12 = plugins/gadget.c
+@WIFI_TRUE@am__append_13 = wifi
+@WIFI_TRUE@am__append_14 = plugins/wifi.c $(gsupplicant_sources)
+@BLUETOOTH_TRUE@am__append_15 = bluetooth_legacy bluetooth
+@BLUETOOTH_TRUE@am__append_16 = plugins/bluetooth_legacy.c \
+@BLUETOOTH_TRUE@	plugins/bluetooth.c
+@HH2SERIAL_GPS_BUILTIN_TRUE@@HH2SERIAL_GPS_TRUE@am__append_17 = hh2serial_gps
+@HH2SERIAL_GPS_BUILTIN_TRUE@@HH2SERIAL_GPS_TRUE@am__append_18 = plugins/hh2serial-gps.c
+@HH2SERIAL_GPS_BUILTIN_FALSE@@HH2SERIAL_GPS_TRUE@am__append_19 = plugins/hh2serial-gps.la
+@HH2SERIAL_GPS_BUILTIN_FALSE@@HH2SERIAL_GPS_TRUE@am__append_20 = $(plugins_hh2serial_gps_la_OBJECTS)
+@OFONO_TRUE@am__append_21 = ofono
+@OFONO_TRUE@am__append_22 = plugins/mcc.h plugins/ofono.c
+@DUNDEE_TRUE@am__append_23 = dundee
+@DUNDEE_TRUE@am__append_24 = plugins/dundee.c
+@VPN_TRUE@am__append_25 = vpn
+@VPN_TRUE@am__append_26 = plugins/vpn.c
+@OPENCONNECT_BUILTIN_TRUE@@OPENCONNECT_TRUE@@VPN_TRUE@am__append_27 = openconnect
+@OPENCONNECT_BUILTIN_TRUE@@OPENCONNECT_TRUE@@VPN_TRUE@am__append_28 = vpn/plugins/openconnect.c
+@OPENCONNECT_BUILTIN_TRUE@@OPENCONNECT_TRUE@@VPN_TRUE@am__append_29 = -DOPENCONNECT=\"@OPENCONNECT@\"
+@OPENCONNECT_BUILTIN_FALSE@@OPENCONNECT_TRUE@@VPN_TRUE@am__append_30 = vpn/plugins/openconnect.la
+@OPENCONNECT_BUILTIN_FALSE@@OPENCONNECT_TRUE@@VPN_TRUE@am__append_31 = $(plugins_openconnect_la_OBJECTS)
+@OPENVPN_BUILTIN_TRUE@@OPENVPN_TRUE@@VPN_TRUE@am__append_32 = openvpn
+@OPENVPN_BUILTIN_TRUE@@OPENVPN_TRUE@@VPN_TRUE@am__append_33 = vpn/plugins/openvpn.c
+@OPENVPN_BUILTIN_TRUE@@OPENVPN_TRUE@@VPN_TRUE@am__append_34 = -DOPENVPN=\"@OPENVPN@\"
+@OPENVPN_BUILTIN_FALSE@@OPENVPN_TRUE@@VPN_TRUE@am__append_35 = vpn/plugins/openvpn.la
+@OPENVPN_BUILTIN_FALSE@@OPENVPN_TRUE@@VPN_TRUE@am__append_36 = $(plugins_openvpn_la_OBJECTS)
+@VPNC_BUILTIN_TRUE@@VPNC_TRUE@@VPN_TRUE@am__append_37 = vpnc
+@VPNC_BUILTIN_TRUE@@VPNC_TRUE@@VPN_TRUE@am__append_38 = vpn/plugins/vpnc.c
+@VPNC_BUILTIN_TRUE@@VPNC_TRUE@@VPN_TRUE@am__append_39 = -DVPNC=\"@VPNC@\"
+@VPNC_BUILTIN_FALSE@@VPNC_TRUE@@VPN_TRUE@am__append_40 = vpn/plugins/vpnc.la
+@VPNC_BUILTIN_FALSE@@VPNC_TRUE@@VPN_TRUE@am__append_41 = $(plugins_vpnc_la_OBJECTS)
+@L2TP_BUILTIN_TRUE@@L2TP_TRUE@@VPN_TRUE@am__append_42 = l2tp
+@L2TP_BUILTIN_TRUE@@L2TP_TRUE@@VPN_TRUE@am__append_43 = vpn/plugins/l2tp.c
+@L2TP_BUILTIN_TRUE@@L2TP_TRUE@@VPN_TRUE@am__append_44 = -DL2TP=\"@L2TP@\"
+@L2TP_BUILTIN_FALSE@@L2TP_TRUE@@VPN_TRUE@am__append_45 = vpn/plugins/l2tp.la
+@L2TP_BUILTIN_FALSE@@L2TP_TRUE@@VPN_TRUE@am__append_46 = $(plugins_l2tp_la_OBJECTS)
+@PPTP_BUILTIN_TRUE@@PPTP_TRUE@@VPN_TRUE@am__append_47 = pptp
+@PPTP_BUILTIN_TRUE@@PPTP_TRUE@@VPN_TRUE@am__append_48 = vpn/plugins/pptp.c
+@PPTP_BUILTIN_TRUE@@PPTP_TRUE@@VPN_TRUE@am__append_49 = -DPPPD=\"@PPPD@\" -DPPTP=\"@PPTP@\"
+@PPTP_BUILTIN_FALSE@@PPTP_TRUE@@VPN_TRUE@am__append_50 = vpn/plugins/pptp.la
+@PPTP_BUILTIN_FALSE@@PPTP_TRUE@@VPN_TRUE@am__append_51 = $(plugins_pptp_la_OBJECTS)
+@PPTP_TRUE@@VPN_TRUE@am__append_52 = scripts/libppp-plugin.la
+@L2TP_TRUE@@PPTP_FALSE@@VPN_TRUE@am__append_53 = scripts/libppp-plugin.la
+@PACRUNNER_TRUE@am__append_54 = pacrunner
+@PACRUNNER_TRUE@am__append_55 = plugins/pacrunner.c
+@POLKIT_TRUE@am__append_56 = polkit
+@POLKIT_TRUE@am__append_57 = plugins/polkit.c
+@DATAFILES_TRUE@@POLKIT_TRUE@@VPN_TRUE@am__append_58 = vpn/net.connman.vpn.policy
+@IOSPM_TRUE@am__append_59 = plugins/iospm.la
+@IOSPM_TRUE@am__append_60 = $(plugins_iospm_la_OBJECTS)
+@OPENCONNECT_TRUE@am__append_61 = scripts/openconnect-script
+@OPENCONNECT_FALSE@@VPNC_TRUE@am__append_62 = scripts/openconnect-script
+@OPENVPN_TRUE@am__append_63 = scripts/openvpn-script
+@NMCOMPAT_TRUE@am__append_64 = nmcompat
+@NMCOMPAT_TRUE@am__append_65 = plugins/nmcompat.c
+@TIST_BUILTIN_TRUE@@TIST_TRUE@am__append_66 = tist
+@TIST_BUILTIN_TRUE@@TIST_TRUE@am__append_67 = plugins/tist.c
+@TIST_BUILTIN_FALSE@@TIST_TRUE@am__append_68 = plugins/tist.la
+@TIST_BUILTIN_FALSE@@TIST_TRUE@am__append_69 = $(plugins_tist_la_OBJECTS)
+@SESSION_POLICY_LOCAL_BUILTIN_TRUE@@SESSION_POLICY_LOCAL_TRUE@am__append_70 = session_policy_local
+@SESSION_POLICY_LOCAL_BUILTIN_TRUE@@SESSION_POLICY_LOCAL_TRUE@am__append_71 = plugins/session_policy_local.c
+@SESSION_POLICY_LOCAL_BUILTIN_FALSE@@SESSION_POLICY_LOCAL_TRUE@am__append_72 = plugins/session_policy_local.la
+@SESSION_POLICY_LOCAL_BUILTIN_FALSE@@SESSION_POLICY_LOCAL_TRUE@am__append_73 = $(plugins_session_policy_local_la_OBJECTS)
+@NEARD_TRUE@am__append_74 = neard
+@NEARD_TRUE@am__append_75 = plugins/neard.c
+@CLIENT_TRUE@am__append_76 = client/connmanctl
+@CLIENT_TRUE@am__append_77 = doc/connmanctl.1
+TESTS = unit/test-ippool$(EXEEXT)
+@WISPR_TRUE@am__append_78 = tools/wispr
+@TOOLS_TRUE@am__append_79 = tools/supplicant-test \
+@TOOLS_TRUE@			tools/dhcp-test tools/dhcp-server-test \
+@TOOLS_TRUE@			tools/addr-test tools/web-test tools/resolv-test \
+@TOOLS_TRUE@			tools/dbus-test tools/polkit-test \
+@TOOLS_TRUE@			tools/iptables-test tools/tap-test tools/wpad-test \
+@TOOLS_TRUE@			tools/stats-tool tools/private-network-test \
+@TOOLS_TRUE@			tools/session-test tools/iptables-unit \
+@TOOLS_TRUE@			tools/dnsproxy-test tools/netlink-test
+
+@SELINUX_TRUE@@VPN_TRUE@am__append_80 = connman-task.pp
+@SELINUX_TRUE@@VPN_TRUE@am__append_81 = connman-task.pp
+subdir = .
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/acinclude.m4 \
+	$(top_srcdir)/configure.ac
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+	$(ACLOCAL_M4)
+am__CONFIG_DISTCLEAN_FILES = config.status config.cache config.log \
+ configure.lineno config.status.lineno
+mkinstalldirs = $(install_sh) -d
+CONFIG_HEADER = config.h
+CONFIG_CLEAN_FILES = include/version.h connman.pc
+CONFIG_CLEAN_VPATH_FILES =
+am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
+am__vpath_adj = case $$p in \
+    $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
+    *) f=$$p;; \
+  esac;
+am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`;
+am__install_max = 40
+am__nobase_strip_setup = \
+  srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'`
+am__nobase_strip = \
+  for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||"
+am__nobase_list = $(am__nobase_strip_setup); \
+  for p in $$list; do echo "$$p $$p"; done | \
+  sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \
+  $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \
+    if (++n[$$2] == $(am__install_max)) \
+      { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \
+    END { for (dir in files) print dir, files[dir] }'
+am__base_list = \
+  sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \
+  sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g'
+am__uninstall_files_from_dir = { \
+  test -z "$$files" \
+    || { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \
+    || { echo " ( cd '$$dir' && rm -f" $$files ")"; \
+         $(am__cd) "$$dir" && rm -f $$files; }; \
+  }
+am__installdirs = "$(DESTDIR)$(plugindir)" "$(DESTDIR)$(scriptdir)" \
+	"$(DESTDIR)$(vpn_plugindir)" "$(DESTDIR)$(bindir)" \
+	"$(DESTDIR)$(sbindir)" "$(DESTDIR)$(scriptdir)" \
+	"$(DESTDIR)$(testdir)" "$(DESTDIR)$(man1dir)" \
+	"$(DESTDIR)$(man5dir)" "$(DESTDIR)$(man8dir)" \
+	"$(DESTDIR)$(dbusconfdir)" "$(DESTDIR)$(dbusservicedir)" \
+	"$(DESTDIR)$(pkgconfigdir)" "$(DESTDIR)$(policydir)" \
+	"$(DESTDIR)$(scriptdir)" "$(DESTDIR)$(systemdunitdir)" \
+	"$(DESTDIR)$(includedir)" "$(DESTDIR)$(includedir)"
+LTLIBRARIES = $(noinst_LTLIBRARIES) $(plugin_LTLIBRARIES) \
+	$(script_LTLIBRARIES) $(vpn_plugin_LTLIBRARIES)
+gdbus_libgdbus_internal_la_LIBADD =
+am__dirstamp = $(am__leading_dot)dirstamp
+am_gdbus_libgdbus_internal_la_OBJECTS = gdbus/mainloop.lo \
+	gdbus/watch.lo gdbus/object.lo gdbus/client.lo gdbus/polkit.lo
+gdbus_libgdbus_internal_la_OBJECTS =  \
+	$(am_gdbus_libgdbus_internal_la_OBJECTS)
+AM_V_lt = $(am__v_lt_@AM_V@)
+am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
+am__v_lt_0 = --silent
+am__v_lt_1 = 
+plugins_hh2serial_gps_la_LIBADD =
+plugins_hh2serial_gps_la_SOURCES = plugins/hh2serial-gps.c
+plugins_hh2serial_gps_la_OBJECTS =  \
+	plugins/plugins_hh2serial_gps_la-hh2serial-gps.lo
+plugins_hh2serial_gps_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \
+	$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \
+	$(plugins_hh2serial_gps_la_CFLAGS) $(CFLAGS) \
+	$(plugins_hh2serial_gps_la_LDFLAGS) $(LDFLAGS) -o $@
+@HH2SERIAL_GPS_BUILTIN_FALSE@@HH2SERIAL_GPS_TRUE@am_plugins_hh2serial_gps_la_rpath =  \
+@HH2SERIAL_GPS_BUILTIN_FALSE@@HH2SERIAL_GPS_TRUE@	-rpath \
+@HH2SERIAL_GPS_BUILTIN_FALSE@@HH2SERIAL_GPS_TRUE@	$(plugindir)
+plugins_iospm_la_LIBADD =
+plugins_iospm_la_SOURCES = plugins/iospm.c
+plugins_iospm_la_OBJECTS = plugins/plugins_iospm_la-iospm.lo
+plugins_iospm_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \
+	$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \
+	$(plugins_iospm_la_CFLAGS) $(CFLAGS) \
+	$(plugins_iospm_la_LDFLAGS) $(LDFLAGS) -o $@
+@IOSPM_TRUE@am_plugins_iospm_la_rpath = -rpath $(plugindir)
+plugins_session_policy_local_la_LIBADD =
+plugins_session_policy_local_la_SOURCES =  \
+	plugins/session_policy_local.c
+plugins_session_policy_local_la_OBJECTS = plugins/plugins_session_policy_local_la-session_policy_local.lo
+plugins_session_policy_local_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \
+	$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \
+	$(plugins_session_policy_local_la_CFLAGS) $(CFLAGS) \
+	$(plugins_session_policy_local_la_LDFLAGS) $(LDFLAGS) -o $@
+@SESSION_POLICY_LOCAL_BUILTIN_FALSE@@SESSION_POLICY_LOCAL_TRUE@am_plugins_session_policy_local_la_rpath = -rpath \
+@SESSION_POLICY_LOCAL_BUILTIN_FALSE@@SESSION_POLICY_LOCAL_TRUE@	$(plugindir)
+plugins_tist_la_LIBADD =
+plugins_tist_la_SOURCES = plugins/tist.c
+plugins_tist_la_OBJECTS = plugins/plugins_tist_la-tist.lo
+plugins_tist_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \
+	$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \
+	$(plugins_tist_la_CFLAGS) $(CFLAGS) $(plugins_tist_la_LDFLAGS) \
+	$(LDFLAGS) -o $@
+@TIST_BUILTIN_FALSE@@TIST_TRUE@am_plugins_tist_la_rpath = -rpath \
+@TIST_BUILTIN_FALSE@@TIST_TRUE@	$(plugindir)
+scripts_libppp_plugin_la_DEPENDENCIES =
+scripts_libppp_plugin_la_SOURCES = scripts/libppp-plugin.c
+scripts_libppp_plugin_la_OBJECTS = scripts/libppp-plugin.lo
+scripts_libppp_plugin_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \
+	$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \
+	$(AM_CFLAGS) $(CFLAGS) $(scripts_libppp_plugin_la_LDFLAGS) \
+	$(LDFLAGS) -o $@
+@L2TP_TRUE@@PPTP_FALSE@@VPN_TRUE@am_scripts_libppp_plugin_la_rpath =  \
+@L2TP_TRUE@@PPTP_FALSE@@VPN_TRUE@	-rpath $(scriptdir)
+@PPTP_TRUE@@VPN_TRUE@am_scripts_libppp_plugin_la_rpath = -rpath \
+@PPTP_TRUE@@VPN_TRUE@	$(scriptdir)
+vpn_plugins_l2tp_la_LIBADD =
+am__vpn_plugins_l2tp_la_SOURCES_DIST = vpn/plugins/vpn.h \
+	vpn/plugins/vpn.c vpn/plugins/l2tp.c
+@L2TP_BUILTIN_FALSE@@L2TP_TRUE@@VPN_TRUE@am_vpn_plugins_l2tp_la_OBJECTS = vpn/plugins/vpn_plugins_l2tp_la-vpn.lo \
+@L2TP_BUILTIN_FALSE@@L2TP_TRUE@@VPN_TRUE@	vpn/plugins/vpn_plugins_l2tp_la-l2tp.lo
+vpn_plugins_l2tp_la_OBJECTS = $(am_vpn_plugins_l2tp_la_OBJECTS)
+vpn_plugins_l2tp_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \
+	$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \
+	$(vpn_plugins_l2tp_la_CFLAGS) $(CFLAGS) \
+	$(vpn_plugins_l2tp_la_LDFLAGS) $(LDFLAGS) -o $@
+@L2TP_BUILTIN_FALSE@@L2TP_TRUE@@VPN_TRUE@am_vpn_plugins_l2tp_la_rpath =  \
+@L2TP_BUILTIN_FALSE@@L2TP_TRUE@@VPN_TRUE@	-rpath \
+@L2TP_BUILTIN_FALSE@@L2TP_TRUE@@VPN_TRUE@	$(vpn_plugindir)
+vpn_plugins_openconnect_la_LIBADD =
+am__vpn_plugins_openconnect_la_SOURCES_DIST = vpn/plugins/vpn.h \
+	vpn/plugins/vpn.c vpn/plugins/openconnect.c
+@OPENCONNECT_BUILTIN_FALSE@@OPENCONNECT_TRUE@@VPN_TRUE@am_vpn_plugins_openconnect_la_OBJECTS = vpn/plugins/vpn_plugins_openconnect_la-vpn.lo \
+@OPENCONNECT_BUILTIN_FALSE@@OPENCONNECT_TRUE@@VPN_TRUE@	vpn/plugins/vpn_plugins_openconnect_la-openconnect.lo
+vpn_plugins_openconnect_la_OBJECTS =  \
+	$(am_vpn_plugins_openconnect_la_OBJECTS)
+vpn_plugins_openconnect_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \
+	$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \
+	$(vpn_plugins_openconnect_la_CFLAGS) $(CFLAGS) \
+	$(vpn_plugins_openconnect_la_LDFLAGS) $(LDFLAGS) -o $@
+@OPENCONNECT_BUILTIN_FALSE@@OPENCONNECT_TRUE@@VPN_TRUE@am_vpn_plugins_openconnect_la_rpath =  \
+@OPENCONNECT_BUILTIN_FALSE@@OPENCONNECT_TRUE@@VPN_TRUE@	-rpath \
+@OPENCONNECT_BUILTIN_FALSE@@OPENCONNECT_TRUE@@VPN_TRUE@	$(vpn_plugindir)
+vpn_plugins_openvpn_la_LIBADD =
+am__vpn_plugins_openvpn_la_SOURCES_DIST = vpn/plugins/vpn.h \
+	vpn/plugins/vpn.c vpn/plugins/openvpn.c
+@OPENVPN_BUILTIN_FALSE@@OPENVPN_TRUE@@VPN_TRUE@am_vpn_plugins_openvpn_la_OBJECTS = vpn/plugins/vpn_plugins_openvpn_la-vpn.lo \
+@OPENVPN_BUILTIN_FALSE@@OPENVPN_TRUE@@VPN_TRUE@	vpn/plugins/vpn_plugins_openvpn_la-openvpn.lo
+vpn_plugins_openvpn_la_OBJECTS = $(am_vpn_plugins_openvpn_la_OBJECTS)
+vpn_plugins_openvpn_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \
+	$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \
+	$(vpn_plugins_openvpn_la_CFLAGS) $(CFLAGS) \
+	$(vpn_plugins_openvpn_la_LDFLAGS) $(LDFLAGS) -o $@
+@OPENVPN_BUILTIN_FALSE@@OPENVPN_TRUE@@VPN_TRUE@am_vpn_plugins_openvpn_la_rpath =  \
+@OPENVPN_BUILTIN_FALSE@@OPENVPN_TRUE@@VPN_TRUE@	-rpath \
+@OPENVPN_BUILTIN_FALSE@@OPENVPN_TRUE@@VPN_TRUE@	$(vpn_plugindir)
+vpn_plugins_pptp_la_LIBADD =
+am__vpn_plugins_pptp_la_SOURCES_DIST = vpn/plugins/vpn.h \
+	vpn/plugins/vpn.c vpn/plugins/pptp.c
+@PPTP_BUILTIN_FALSE@@PPTP_TRUE@@VPN_TRUE@am_vpn_plugins_pptp_la_OBJECTS = vpn/plugins/vpn_plugins_pptp_la-vpn.lo \
+@PPTP_BUILTIN_FALSE@@PPTP_TRUE@@VPN_TRUE@	vpn/plugins/vpn_plugins_pptp_la-pptp.lo
+vpn_plugins_pptp_la_OBJECTS = $(am_vpn_plugins_pptp_la_OBJECTS)
+vpn_plugins_pptp_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \
+	$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \
+	$(vpn_plugins_pptp_la_CFLAGS) $(CFLAGS) \
+	$(vpn_plugins_pptp_la_LDFLAGS) $(LDFLAGS) -o $@
+@PPTP_BUILTIN_FALSE@@PPTP_TRUE@@VPN_TRUE@am_vpn_plugins_pptp_la_rpath =  \
+@PPTP_BUILTIN_FALSE@@PPTP_TRUE@@VPN_TRUE@	-rpath \
+@PPTP_BUILTIN_FALSE@@PPTP_TRUE@@VPN_TRUE@	$(vpn_plugindir)
+vpn_plugins_vpnc_la_LIBADD =
+am__vpn_plugins_vpnc_la_SOURCES_DIST = vpn/plugins/vpn.h \
+	vpn/plugins/vpn.c vpn/plugins/vpnc.c
+@VPNC_BUILTIN_FALSE@@VPNC_TRUE@@VPN_TRUE@am_vpn_plugins_vpnc_la_OBJECTS = vpn/plugins/vpn_plugins_vpnc_la-vpn.lo \
+@VPNC_BUILTIN_FALSE@@VPNC_TRUE@@VPN_TRUE@	vpn/plugins/vpn_plugins_vpnc_la-vpnc.lo
+vpn_plugins_vpnc_la_OBJECTS = $(am_vpn_plugins_vpnc_la_OBJECTS)
+vpn_plugins_vpnc_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \
+	$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \
+	$(vpn_plugins_vpnc_la_CFLAGS) $(CFLAGS) \
+	$(vpn_plugins_vpnc_la_LDFLAGS) $(LDFLAGS) -o $@
+@VPNC_BUILTIN_FALSE@@VPNC_TRUE@@VPN_TRUE@am_vpn_plugins_vpnc_la_rpath =  \
+@VPNC_BUILTIN_FALSE@@VPNC_TRUE@@VPN_TRUE@	-rpath \
+@VPNC_BUILTIN_FALSE@@VPNC_TRUE@@VPN_TRUE@	$(vpn_plugindir)
+@CLIENT_TRUE@am__EXEEXT_1 = client/connmanctl$(EXEEXT)
+@WISPR_TRUE@am__EXEEXT_2 = tools/wispr$(EXEEXT)
+@TOOLS_TRUE@am__EXEEXT_3 = tools/supplicant-test$(EXEEXT) \
+@TOOLS_TRUE@	tools/dhcp-test$(EXEEXT) \
+@TOOLS_TRUE@	tools/dhcp-server-test$(EXEEXT) \
+@TOOLS_TRUE@	tools/addr-test$(EXEEXT) tools/web-test$(EXEEXT) \
+@TOOLS_TRUE@	tools/resolv-test$(EXEEXT) \
+@TOOLS_TRUE@	tools/dbus-test$(EXEEXT) \
+@TOOLS_TRUE@	tools/polkit-test$(EXEEXT) \
+@TOOLS_TRUE@	tools/iptables-test$(EXEEXT) \
+@TOOLS_TRUE@	tools/tap-test$(EXEEXT) tools/wpad-test$(EXEEXT) \
+@TOOLS_TRUE@	tools/stats-tool$(EXEEXT) \
+@TOOLS_TRUE@	tools/private-network-test$(EXEEXT) \
+@TOOLS_TRUE@	tools/session-test$(EXEEXT) \
+@TOOLS_TRUE@	tools/iptables-unit$(EXEEXT) \
+@TOOLS_TRUE@	tools/dnsproxy-test$(EXEEXT) \
+@TOOLS_TRUE@	tools/netlink-test$(EXEEXT)
+@VPN_TRUE@am__EXEEXT_4 = vpn/connman-vpnd$(EXEEXT)
+@OPENCONNECT_TRUE@am__EXEEXT_5 = scripts/openconnect-script$(EXEEXT)
+@OPENCONNECT_FALSE@@VPNC_TRUE@am__EXEEXT_6 = scripts/openconnect-script$(EXEEXT)
+@OPENVPN_TRUE@am__EXEEXT_7 = scripts/openvpn-script$(EXEEXT)
+PROGRAMS = $(bin_PROGRAMS) $(noinst_PROGRAMS) $(sbin_PROGRAMS) \
+	$(script_PROGRAMS)
+am__client_connmanctl_SOURCES_DIST = client/dbus_helpers.h \
+	client/dbus_helpers.c client/services.h client/services.c \
+	client/commands.h client/commands.c client/input.h \
+	client/input.c client/agent.h client/agent.c client/peers.h \
+	client/peers.c client/vpnconnections.h client/vpnconnections.c \
+	client/main.c
+@CLIENT_TRUE@am_client_connmanctl_OBJECTS =  \
+@CLIENT_TRUE@	client/dbus_helpers.$(OBJEXT) \
+@CLIENT_TRUE@	client/services.$(OBJEXT) \
+@CLIENT_TRUE@	client/commands.$(OBJEXT) client/input.$(OBJEXT) \
+@CLIENT_TRUE@	client/agent.$(OBJEXT) client/peers.$(OBJEXT) \
+@CLIENT_TRUE@	client/vpnconnections.$(OBJEXT) \
+@CLIENT_TRUE@	client/main.$(OBJEXT)
+client_connmanctl_OBJECTS = $(am_client_connmanctl_OBJECTS)
+@CLIENT_TRUE@client_connmanctl_DEPENDENCIES =  \
+@CLIENT_TRUE@	gdbus/libgdbus-internal.la
+scripts_openconnect_script_SOURCES = scripts/openconnect-script.c
+scripts_openconnect_script_OBJECTS =  \
+	scripts/openconnect-script.$(OBJEXT)
+scripts_openconnect_script_DEPENDENCIES =
+scripts_openvpn_script_SOURCES = scripts/openvpn-script.c
+scripts_openvpn_script_OBJECTS = scripts/openvpn-script.$(OBJEXT)
+scripts_openvpn_script_DEPENDENCIES =
+am__src_connmand_SOURCES_DIST = gdhcp/gdhcp.h gdhcp/common.h \
+	gdhcp/common.c gdhcp/client.c gdhcp/server.c gdhcp/ipv4ll.h \
+	gdhcp/ipv4ll.c gdhcp/unaligned.h gdhcp/timer.c gdhcp/timer.h \
+	gweb/gweb.h gweb/gweb.c gweb/gresolv.h gweb/gresolv.c \
+	gweb/giognutls.h gweb/giognutls.c gweb/gionotls.c \
+	plugins/loopback.c plugins/ethernet.c plugins/gadget.c \
+	plugins/wifi.c gsupplicant/gsupplicant.h gsupplicant/dbus.h \
+	gsupplicant/supplicant.c gsupplicant/dbus.c \
+	plugins/bluetooth_legacy.c plugins/bluetooth.c \
+	plugins/hh2serial-gps.c plugins/mcc.h plugins/ofono.c \
+	plugins/dundee.c plugins/vpn.c plugins/pacrunner.c \
+	plugins/polkit.c plugins/nmcompat.c plugins/tist.c \
+	plugins/session_policy_local.c plugins/neard.c \
+	src/shared/util.h src/shared/util.c src/shared/netlink.h \
+	src/shared/netlink.c src/connman.ver src/main.c src/connman.h \
+	src/log.c src/error.c src/plugin.c src/task.c src/device.c \
+	src/network.c src/connection.c src/manager.c src/service.c \
+	src/clock.c src/timezone.c src/agent-connman.c src/agent.c \
+	src/notifier.c src/provider.c src/resolver.c src/ipconfig.c \
+	src/detect.c src/inet.c src/dhcp.c src/dhcpv6.c src/rtnl.c \
+	src/proxy.c src/utsname.c src/timeserver.c src/rfkill.c \
+	src/storage.c src/dbus.c src/config.c src/technology.c \
+	src/counter.c src/ntp.c src/session.c src/tethering.c \
+	src/wpad.c src/wispr.c src/stats.c src/iptables.c \
+	src/dnsproxy.c src/6to4.c src/ippool.c src/bridge.c src/nat.c \
+	src/ipaddress.c src/inotify.c src/firewall.c src/ipv6pd.c \
+	src/peer.c src/peer_service.c src/machine.c src/util.c \
+	src/rlimits.c
+am__objects_1 = gdhcp/src_connmand-common.$(OBJEXT) \
+	gdhcp/src_connmand-client.$(OBJEXT) \
+	gdhcp/src_connmand-server.$(OBJEXT) \
+	gdhcp/src_connmand-ipv4ll.$(OBJEXT) \
+	gdhcp/src_connmand-timer.$(OBJEXT)
+@WISPR_TRUE@am__objects_2 = gweb/src_connmand-giognutls.$(OBJEXT)
+@WISPR_FALSE@am__objects_3 = gweb/src_connmand-gionotls.$(OBJEXT)
+am__objects_4 = gweb/src_connmand-gweb.$(OBJEXT) \
+	gweb/src_connmand-gresolv.$(OBJEXT) $(am__objects_2) \
+	$(am__objects_3)
+@LOOPBACK_TRUE@am__objects_5 =  \
+@LOOPBACK_TRUE@	plugins/src_connmand-loopback.$(OBJEXT)
+@ETHERNET_TRUE@am__objects_6 =  \
+@ETHERNET_TRUE@	plugins/src_connmand-ethernet.$(OBJEXT)
+@GADGET_TRUE@am__objects_7 = plugins/src_connmand-gadget.$(OBJEXT)
+am__objects_8 = gsupplicant/src_connmand-supplicant.$(OBJEXT) \
+	gsupplicant/src_connmand-dbus.$(OBJEXT)
+@WIFI_TRUE@am__objects_9 = plugins/src_connmand-wifi.$(OBJEXT) \
+@WIFI_TRUE@	$(am__objects_8)
+@BLUETOOTH_TRUE@am__objects_10 = plugins/src_connmand-bluetooth_legacy.$(OBJEXT) \
+@BLUETOOTH_TRUE@	plugins/src_connmand-bluetooth.$(OBJEXT)
+@HH2SERIAL_GPS_BUILTIN_TRUE@@HH2SERIAL_GPS_TRUE@am__objects_11 = plugins/src_connmand-hh2serial-gps.$(OBJEXT)
+@OFONO_TRUE@am__objects_12 = plugins/src_connmand-ofono.$(OBJEXT)
+@DUNDEE_TRUE@am__objects_13 = plugins/src_connmand-dundee.$(OBJEXT)
+@VPN_TRUE@am__objects_14 = plugins/src_connmand-vpn.$(OBJEXT)
+@PACRUNNER_TRUE@am__objects_15 =  \
+@PACRUNNER_TRUE@	plugins/src_connmand-pacrunner.$(OBJEXT)
+@POLKIT_TRUE@am__objects_16 = plugins/src_connmand-polkit.$(OBJEXT)
+@NMCOMPAT_TRUE@am__objects_17 =  \
+@NMCOMPAT_TRUE@	plugins/src_connmand-nmcompat.$(OBJEXT)
+@TIST_BUILTIN_TRUE@@TIST_TRUE@am__objects_18 = plugins/src_connmand-tist.$(OBJEXT)
+@SESSION_POLICY_LOCAL_BUILTIN_TRUE@@SESSION_POLICY_LOCAL_TRUE@am__objects_19 = plugins/src_connmand-session_policy_local.$(OBJEXT)
+@NEARD_TRUE@am__objects_20 = plugins/src_connmand-neard.$(OBJEXT)
+am__objects_21 = $(am__objects_5) $(am__objects_6) $(am__objects_7) \
+	$(am__objects_9) $(am__objects_10) $(am__objects_11) \
+	$(am__objects_12) $(am__objects_13) $(am__objects_14) \
+	$(am__objects_15) $(am__objects_16) $(am__objects_17) \
+	$(am__objects_18) $(am__objects_19) $(am__objects_20)
+am__objects_22 = src/shared/src_connmand-util.$(OBJEXT) \
+	src/shared/src_connmand-netlink.$(OBJEXT)
+am_src_connmand_OBJECTS = $(am__objects_1) $(am__objects_4) \
+	$(am__objects_21) $(am__objects_22) \
+	src/src_connmand-main.$(OBJEXT) src/src_connmand-log.$(OBJEXT) \
+	src/src_connmand-error.$(OBJEXT) \
+	src/src_connmand-plugin.$(OBJEXT) \
+	src/src_connmand-task.$(OBJEXT) \
+	src/src_connmand-device.$(OBJEXT) \
+	src/src_connmand-network.$(OBJEXT) \
+	src/src_connmand-connection.$(OBJEXT) \
+	src/src_connmand-manager.$(OBJEXT) \
+	src/src_connmand-service.$(OBJEXT) \
+	src/src_connmand-clock.$(OBJEXT) \
+	src/src_connmand-timezone.$(OBJEXT) \
+	src/src_connmand-agent-connman.$(OBJEXT) \
+	src/src_connmand-agent.$(OBJEXT) \
+	src/src_connmand-notifier.$(OBJEXT) \
+	src/src_connmand-provider.$(OBJEXT) \
+	src/src_connmand-resolver.$(OBJEXT) \
+	src/src_connmand-ipconfig.$(OBJEXT) \
+	src/src_connmand-detect.$(OBJEXT) \
+	src/src_connmand-inet.$(OBJEXT) \
+	src/src_connmand-dhcp.$(OBJEXT) \
+	src/src_connmand-dhcpv6.$(OBJEXT) \
+	src/src_connmand-rtnl.$(OBJEXT) \
+	src/src_connmand-proxy.$(OBJEXT) \
+	src/src_connmand-utsname.$(OBJEXT) \
+	src/src_connmand-timeserver.$(OBJEXT) \
+	src/src_connmand-rfkill.$(OBJEXT) \
+	src/src_connmand-storage.$(OBJEXT) \
+	src/src_connmand-dbus.$(OBJEXT) \
+	src/src_connmand-config.$(OBJEXT) \
+	src/src_connmand-technology.$(OBJEXT) \
+	src/src_connmand-counter.$(OBJEXT) \
+	src/src_connmand-ntp.$(OBJEXT) \
+	src/src_connmand-session.$(OBJEXT) \
+	src/src_connmand-tethering.$(OBJEXT) \
+	src/src_connmand-wpad.$(OBJEXT) \
+	src/src_connmand-wispr.$(OBJEXT) \
+	src/src_connmand-stats.$(OBJEXT) \
+	src/src_connmand-iptables.$(OBJEXT) \
+	src/src_connmand-dnsproxy.$(OBJEXT) \
+	src/src_connmand-6to4.$(OBJEXT) \
+	src/src_connmand-ippool.$(OBJEXT) \
+	src/src_connmand-bridge.$(OBJEXT) \
+	src/src_connmand-nat.$(OBJEXT) \
+	src/src_connmand-ipaddress.$(OBJEXT) \
+	src/src_connmand-inotify.$(OBJEXT) \
+	src/src_connmand-firewall.$(OBJEXT) \
+	src/src_connmand-ipv6pd.$(OBJEXT) \
+	src/src_connmand-peer.$(OBJEXT) \
+	src/src_connmand-peer_service.$(OBJEXT) \
+	src/src_connmand-machine.$(OBJEXT) \
+	src/src_connmand-util.$(OBJEXT) \
+	src/src_connmand-rlimits.$(OBJEXT)
+src_connmand_OBJECTS = $(am_src_connmand_OBJECTS)
+am__DEPENDENCIES_1 =
+src_connmand_DEPENDENCIES = gdbus/libgdbus-internal.la \
+	$(am__DEPENDENCIES_1)
+src_connmand_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
+	$(LIBTOOLFLAGS) --mode=link $(CCLD) $(src_connmand_CFLAGS) \
+	$(CFLAGS) $(src_connmand_LDFLAGS) $(LDFLAGS) -o $@
+tools_addr_test_SOURCES = tools/addr-test.c
+tools_addr_test_OBJECTS = tools/addr-test.$(OBJEXT)
+tools_addr_test_LDADD = $(LDADD)
+am__tools_dbus_test_SOURCES_DIST = tools/dbus-test.c
+@TOOLS_TRUE@am_tools_dbus_test_OBJECTS = tools/dbus-test.$(OBJEXT)
+tools_dbus_test_OBJECTS = $(am_tools_dbus_test_OBJECTS)
+@TOOLS_TRUE@tools_dbus_test_DEPENDENCIES = gdbus/libgdbus-internal.la
+am__tools_dhcp_server_test_SOURCES_DIST = gdhcp/gdhcp.h gdhcp/common.h \
+	gdhcp/common.c gdhcp/client.c gdhcp/server.c gdhcp/ipv4ll.h \
+	gdhcp/ipv4ll.c gdhcp/unaligned.h gdhcp/timer.c gdhcp/timer.h \
+	tools/dhcp-server-test.c
+am__objects_23 = gdhcp/common.$(OBJEXT) gdhcp/client.$(OBJEXT) \
+	gdhcp/server.$(OBJEXT) gdhcp/ipv4ll.$(OBJEXT) \
+	gdhcp/timer.$(OBJEXT)
+@TOOLS_TRUE@am_tools_dhcp_server_test_OBJECTS = $(am__objects_23) \
+@TOOLS_TRUE@	tools/dhcp-server-test.$(OBJEXT)
+tools_dhcp_server_test_OBJECTS = $(am_tools_dhcp_server_test_OBJECTS)
+tools_dhcp_server_test_DEPENDENCIES =
+am__tools_dhcp_test_SOURCES_DIST = gdhcp/gdhcp.h gdhcp/common.h \
+	gdhcp/common.c gdhcp/client.c gdhcp/server.c gdhcp/ipv4ll.h \
+	gdhcp/ipv4ll.c gdhcp/unaligned.h gdhcp/timer.c gdhcp/timer.h \
+	tools/dhcp-test.c
+@TOOLS_TRUE@am_tools_dhcp_test_OBJECTS = $(am__objects_23) \
+@TOOLS_TRUE@	tools/dhcp-test.$(OBJEXT)
+tools_dhcp_test_OBJECTS = $(am_tools_dhcp_test_OBJECTS)
+tools_dhcp_test_DEPENDENCIES =
+am__tools_dnsproxy_test_SOURCES_DIST = tools/dnsproxy-test.c
+@TOOLS_TRUE@am_tools_dnsproxy_test_OBJECTS =  \
+@TOOLS_TRUE@	tools/dnsproxy-test.$(OBJEXT)
+tools_dnsproxy_test_OBJECTS = $(am_tools_dnsproxy_test_OBJECTS)
+tools_dnsproxy_test_DEPENDENCIES =
+am__tools_iptables_test_SOURCES_DIST = src/log.c src/iptables.c \
+	tools/iptables-test.c
+@TOOLS_TRUE@am_tools_iptables_test_OBJECTS = src/log.$(OBJEXT) \
+@TOOLS_TRUE@	src/iptables.$(OBJEXT) \
+@TOOLS_TRUE@	tools/iptables-test.$(OBJEXT)
+tools_iptables_test_OBJECTS = $(am_tools_iptables_test_OBJECTS)
+tools_iptables_test_DEPENDENCIES =
+am__tools_iptables_unit_SOURCES_DIST = src/log.c src/iptables.c \
+	src/firewall.c src/nat.c tools/iptables-unit.c
+@TOOLS_TRUE@am_tools_iptables_unit_OBJECTS =  \
+@TOOLS_TRUE@	src/tools_iptables_unit-log.$(OBJEXT) \
+@TOOLS_TRUE@	src/tools_iptables_unit-iptables.$(OBJEXT) \
+@TOOLS_TRUE@	src/tools_iptables_unit-firewall.$(OBJEXT) \
+@TOOLS_TRUE@	src/tools_iptables_unit-nat.$(OBJEXT) \
+@TOOLS_TRUE@	tools/tools_iptables_unit-iptables-unit.$(OBJEXT)
+tools_iptables_unit_OBJECTS = $(am_tools_iptables_unit_OBJECTS)
+@TOOLS_TRUE@tools_iptables_unit_DEPENDENCIES =  \
+@TOOLS_TRUE@	gdbus/libgdbus-internal.la
+tools_iptables_unit_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \
+	$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \
+	$(tools_iptables_unit_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
+	$(LDFLAGS) -o $@
+am__tools_netlink_test_SOURCES_DIST = src/shared/util.h \
+	src/shared/util.c src/shared/netlink.h src/shared/netlink.c \
+	tools/netlink-test.c
+am__objects_24 = src/shared/util.$(OBJEXT) \
+	src/shared/netlink.$(OBJEXT)
+@TOOLS_TRUE@am_tools_netlink_test_OBJECTS = $(am__objects_24) \
+@TOOLS_TRUE@	tools/netlink-test.$(OBJEXT)
+tools_netlink_test_OBJECTS = $(am_tools_netlink_test_OBJECTS)
+tools_netlink_test_DEPENDENCIES =
+tools_polkit_test_SOURCES = tools/polkit-test.c
+tools_polkit_test_OBJECTS = tools/polkit-test.$(OBJEXT)
+tools_polkit_test_DEPENDENCIES =
+tools_private_network_test_SOURCES = tools/private-network-test.c
+tools_private_network_test_OBJECTS =  \
+	tools/private-network-test.$(OBJEXT)
+tools_private_network_test_DEPENDENCIES =
+am__tools_resolv_test_SOURCES_DIST = gweb/gresolv.h gweb/gresolv.c \
+	tools/resolv-test.c
+@TOOLS_TRUE@am_tools_resolv_test_OBJECTS = gweb/gresolv.$(OBJEXT) \
+@TOOLS_TRUE@	tools/resolv-test.$(OBJEXT)
+tools_resolv_test_OBJECTS = $(am_tools_resolv_test_OBJECTS)
+tools_resolv_test_DEPENDENCIES =
+am__tools_session_test_SOURCES_DIST = src/log.c src/dbus.c src/error.c \
+	tools/session-test.c tools/session-utils.c tools/manager-api.c \
+	tools/session-api.c tools/session-test.h
+@TOOLS_TRUE@am_tools_session_test_OBJECTS = src/log.$(OBJEXT) \
+@TOOLS_TRUE@	src/dbus.$(OBJEXT) src/error.$(OBJEXT) \
+@TOOLS_TRUE@	tools/session-test.$(OBJEXT) \
+@TOOLS_TRUE@	tools/session-utils.$(OBJEXT) \
+@TOOLS_TRUE@	tools/manager-api.$(OBJEXT) \
+@TOOLS_TRUE@	tools/session-api.$(OBJEXT)
+tools_session_test_OBJECTS = $(am_tools_session_test_OBJECTS)
+@TOOLS_TRUE@tools_session_test_DEPENDENCIES =  \
+@TOOLS_TRUE@	gdbus/libgdbus-internal.la
+tools_stats_tool_SOURCES = tools/stats-tool.c
+tools_stats_tool_OBJECTS = tools/stats-tool.$(OBJEXT)
+tools_stats_tool_DEPENDENCIES =
+am__tools_supplicant_test_SOURCES_DIST = tools/supplicant-test.c \
+	tools/supplicant-dbus.h tools/supplicant-dbus.c \
+	tools/supplicant.h tools/supplicant.c
+@TOOLS_TRUE@am_tools_supplicant_test_OBJECTS =  \
+@TOOLS_TRUE@	tools/supplicant-test.$(OBJEXT) \
+@TOOLS_TRUE@	tools/supplicant-dbus.$(OBJEXT) \
+@TOOLS_TRUE@	tools/supplicant.$(OBJEXT)
+tools_supplicant_test_OBJECTS = $(am_tools_supplicant_test_OBJECTS)
+@TOOLS_TRUE@tools_supplicant_test_DEPENDENCIES =  \
+@TOOLS_TRUE@	gdbus/libgdbus-internal.la
+tools_tap_test_SOURCES = tools/tap-test.c
+tools_tap_test_OBJECTS = tools/tap-test.$(OBJEXT)
+tools_tap_test_LDADD = $(LDADD)
+am__tools_web_test_SOURCES_DIST = gweb/gweb.h gweb/gweb.c \
+	gweb/gresolv.h gweb/gresolv.c gweb/giognutls.h \
+	gweb/giognutls.c gweb/gionotls.c tools/web-test.c
+@WISPR_TRUE@am__objects_25 = gweb/giognutls.$(OBJEXT)
+@WISPR_FALSE@am__objects_26 = gweb/gionotls.$(OBJEXT)
+am__objects_27 = gweb/gweb.$(OBJEXT) gweb/gresolv.$(OBJEXT) \
+	$(am__objects_25) $(am__objects_26)
+@TOOLS_TRUE@am_tools_web_test_OBJECTS = $(am__objects_27) \
+@TOOLS_TRUE@	tools/web-test.$(OBJEXT)
+tools_web_test_OBJECTS = $(am_tools_web_test_OBJECTS)
+tools_web_test_DEPENDENCIES =
+am__tools_wispr_SOURCES_DIST = gweb/gweb.h gweb/gweb.c gweb/gresolv.h \
+	gweb/gresolv.c gweb/giognutls.h gweb/giognutls.c \
+	gweb/gionotls.c tools/wispr.c
+@WISPR_TRUE@am_tools_wispr_OBJECTS = $(am__objects_27) \
+@WISPR_TRUE@	tools/wispr.$(OBJEXT)
+tools_wispr_OBJECTS = $(am_tools_wispr_OBJECTS)
+tools_wispr_DEPENDENCIES =
+am__tools_wpad_test_SOURCES_DIST = gweb/gresolv.h gweb/gresolv.c \
+	tools/wpad-test.c
+@TOOLS_TRUE@am_tools_wpad_test_OBJECTS = gweb/gresolv.$(OBJEXT) \
+@TOOLS_TRUE@	tools/wpad-test.$(OBJEXT)
+tools_wpad_test_OBJECTS = $(am_tools_wpad_test_OBJECTS)
+tools_wpad_test_DEPENDENCIES =
+am_unit_test_ippool_OBJECTS = src/log.$(OBJEXT) src/dbus.$(OBJEXT) \
+	src/error.$(OBJEXT) src/ippool.$(OBJEXT) \
+	unit/test-ippool.$(OBJEXT)
+unit_test_ippool_OBJECTS = $(am_unit_test_ippool_OBJECTS)
+unit_test_ippool_DEPENDENCIES = gdbus/libgdbus-internal.la
+am__vpn_connman_vpnd_SOURCES_DIST = vpn/plugins/openconnect.c \
+	vpn/plugins/openvpn.c vpn/plugins/vpnc.c vpn/plugins/l2tp.c \
+	vpn/plugins/pptp.c vpn/plugins/vpn.c vpn/plugins/vpn.h \
+	gweb/gweb.h gweb/gweb.c gweb/gresolv.h gweb/gresolv.c \
+	gweb/giognutls.h gweb/giognutls.c gweb/gionotls.c vpn/vpn.ver \
+	vpn/main.c vpn/vpn.h src/log.c src/error.c src/plugin.c \
+	src/task.c vpn/vpn-manager.c vpn/vpn-provider.c \
+	vpn/vpn-provider.h vpn/vpn-rtnl.h vpn/vpn-ipconfig.c \
+	src/inet.c vpn/vpn-rtnl.c src/dbus.c src/storage.c \
+	src/ipaddress.c src/agent.c vpn/vpn-agent.c vpn/vpn-agent.h \
+	src/inotify.c vpn/vpn-config.c
+@OPENCONNECT_BUILTIN_TRUE@@OPENCONNECT_TRUE@@VPN_TRUE@am__objects_28 = vpn/plugins/vpn_connman_vpnd-openconnect.$(OBJEXT)
+@OPENVPN_BUILTIN_TRUE@@OPENVPN_TRUE@@VPN_TRUE@am__objects_29 = vpn/plugins/vpn_connman_vpnd-openvpn.$(OBJEXT)
+@VPNC_BUILTIN_TRUE@@VPNC_TRUE@@VPN_TRUE@am__objects_30 = vpn/plugins/vpn_connman_vpnd-vpnc.$(OBJEXT)
+@L2TP_BUILTIN_TRUE@@L2TP_TRUE@@VPN_TRUE@am__objects_31 = vpn/plugins/vpn_connman_vpnd-l2tp.$(OBJEXT)
+@PPTP_BUILTIN_TRUE@@PPTP_TRUE@@VPN_TRUE@am__objects_32 = vpn/plugins/vpn_connman_vpnd-pptp.$(OBJEXT)
+@L2TP_BUILTIN_FALSE@@OPENCONNECT_BUILTIN_FALSE@@OPENVPN_BUILTIN_FALSE@@PPTP_BUILTIN_FALSE@@VPNC_BUILTIN_TRUE@@VPNC_TRUE@@VPN_TRUE@am__objects_33 = vpn/plugins/vpn_connman_vpnd-vpn.$(OBJEXT)
+@L2TP_BUILTIN_FALSE@@OPENCONNECT_BUILTIN_FALSE@@OPENVPN_BUILTIN_FALSE@@PPTP_BUILTIN_TRUE@@PPTP_TRUE@@VPN_TRUE@am__objects_33 = vpn/plugins/vpn_connman_vpnd-vpn.$(OBJEXT)
+@L2TP_BUILTIN_FALSE@@OPENCONNECT_BUILTIN_FALSE@@OPENVPN_BUILTIN_FALSE@@PPTP_FALSE@@VPNC_BUILTIN_TRUE@@VPNC_TRUE@@VPN_TRUE@am__objects_33 = vpn/plugins/vpn_connman_vpnd-vpn.$(OBJEXT)
+@L2TP_BUILTIN_FALSE@@OPENCONNECT_BUILTIN_FALSE@@OPENVPN_BUILTIN_TRUE@@OPENVPN_TRUE@@VPN_TRUE@am__objects_33 = vpn/plugins/vpn_connman_vpnd-vpn.$(OBJEXT)
+@L2TP_BUILTIN_FALSE@@OPENCONNECT_BUILTIN_FALSE@@OPENVPN_FALSE@@PPTP_BUILTIN_FALSE@@VPNC_BUILTIN_TRUE@@VPNC_TRUE@@VPN_TRUE@am__objects_33 = vpn/plugins/vpn_connman_vpnd-vpn.$(OBJEXT)
+@L2TP_BUILTIN_FALSE@@OPENCONNECT_BUILTIN_FALSE@@OPENVPN_FALSE@@PPTP_BUILTIN_TRUE@@PPTP_TRUE@@VPN_TRUE@am__objects_33 = vpn/plugins/vpn_connman_vpnd-vpn.$(OBJEXT)
+@L2TP_BUILTIN_FALSE@@OPENCONNECT_BUILTIN_FALSE@@OPENVPN_FALSE@@PPTP_FALSE@@VPNC_BUILTIN_TRUE@@VPNC_TRUE@@VPN_TRUE@am__objects_33 = vpn/plugins/vpn_connman_vpnd-vpn.$(OBJEXT)
+@L2TP_BUILTIN_FALSE@@OPENCONNECT_BUILTIN_TRUE@@OPENCONNECT_TRUE@@VPN_TRUE@am__objects_33 = vpn/plugins/vpn_connman_vpnd-vpn.$(OBJEXT)
+@L2TP_BUILTIN_FALSE@@OPENCONNECT_FALSE@@OPENVPN_BUILTIN_FALSE@@PPTP_BUILTIN_FALSE@@VPNC_BUILTIN_TRUE@@VPNC_TRUE@@VPN_TRUE@am__objects_33 = vpn/plugins/vpn_connman_vpnd-vpn.$(OBJEXT)
+@L2TP_BUILTIN_FALSE@@OPENCONNECT_FALSE@@OPENVPN_BUILTIN_FALSE@@PPTP_BUILTIN_TRUE@@PPTP_TRUE@@VPN_TRUE@am__objects_33 = vpn/plugins/vpn_connman_vpnd-vpn.$(OBJEXT)
+@L2TP_BUILTIN_FALSE@@OPENCONNECT_FALSE@@OPENVPN_BUILTIN_FALSE@@PPTP_FALSE@@VPNC_BUILTIN_TRUE@@VPNC_TRUE@@VPN_TRUE@am__objects_33 = vpn/plugins/vpn_connman_vpnd-vpn.$(OBJEXT)
+@L2TP_BUILTIN_FALSE@@OPENCONNECT_FALSE@@OPENVPN_BUILTIN_TRUE@@OPENVPN_TRUE@@VPN_TRUE@am__objects_33 = vpn/plugins/vpn_connman_vpnd-vpn.$(OBJEXT)
+@L2TP_BUILTIN_FALSE@@OPENCONNECT_FALSE@@OPENVPN_FALSE@@PPTP_BUILTIN_FALSE@@VPNC_BUILTIN_TRUE@@VPNC_TRUE@@VPN_TRUE@am__objects_33 = vpn/plugins/vpn_connman_vpnd-vpn.$(OBJEXT)
+@L2TP_BUILTIN_FALSE@@OPENCONNECT_FALSE@@OPENVPN_FALSE@@PPTP_BUILTIN_TRUE@@PPTP_TRUE@@VPN_TRUE@am__objects_33 = vpn/plugins/vpn_connman_vpnd-vpn.$(OBJEXT)
+@L2TP_BUILTIN_FALSE@@OPENCONNECT_FALSE@@OPENVPN_FALSE@@PPTP_FALSE@@VPNC_BUILTIN_TRUE@@VPNC_TRUE@@VPN_TRUE@am__objects_33 = vpn/plugins/vpn_connman_vpnd-vpn.$(OBJEXT)
+@L2TP_BUILTIN_TRUE@@L2TP_TRUE@@VPN_TRUE@am__objects_33 = vpn/plugins/vpn_connman_vpnd-vpn.$(OBJEXT)
+@L2TP_FALSE@@OPENCONNECT_BUILTIN_FALSE@@OPENVPN_BUILTIN_FALSE@@PPTP_BUILTIN_FALSE@@VPNC_BUILTIN_TRUE@@VPNC_TRUE@@VPN_TRUE@am__objects_33 = vpn/plugins/vpn_connman_vpnd-vpn.$(OBJEXT)
+@L2TP_FALSE@@OPENCONNECT_BUILTIN_FALSE@@OPENVPN_BUILTIN_FALSE@@PPTP_BUILTIN_TRUE@@PPTP_TRUE@@VPN_TRUE@am__objects_33 = vpn/plugins/vpn_connman_vpnd-vpn.$(OBJEXT)
+@L2TP_FALSE@@OPENCONNECT_BUILTIN_FALSE@@OPENVPN_BUILTIN_FALSE@@PPTP_FALSE@@VPNC_BUILTIN_TRUE@@VPNC_TRUE@@VPN_TRUE@am__objects_33 = vpn/plugins/vpn_connman_vpnd-vpn.$(OBJEXT)
+@L2TP_FALSE@@OPENCONNECT_BUILTIN_FALSE@@OPENVPN_BUILTIN_TRUE@@OPENVPN_TRUE@@VPN_TRUE@am__objects_33 = vpn/plugins/vpn_connman_vpnd-vpn.$(OBJEXT)
+@L2TP_FALSE@@OPENCONNECT_BUILTIN_FALSE@@OPENVPN_FALSE@@PPTP_BUILTIN_FALSE@@VPNC_BUILTIN_TRUE@@VPNC_TRUE@@VPN_TRUE@am__objects_33 = vpn/plugins/vpn_connman_vpnd-vpn.$(OBJEXT)
+@L2TP_FALSE@@OPENCONNECT_BUILTIN_FALSE@@OPENVPN_FALSE@@PPTP_BUILTIN_TRUE@@PPTP_TRUE@@VPN_TRUE@am__objects_33 = vpn/plugins/vpn_connman_vpnd-vpn.$(OBJEXT)
+@L2TP_FALSE@@OPENCONNECT_BUILTIN_FALSE@@OPENVPN_FALSE@@PPTP_FALSE@@VPNC_BUILTIN_TRUE@@VPNC_TRUE@@VPN_TRUE@am__objects_33 = vpn/plugins/vpn_connman_vpnd-vpn.$(OBJEXT)
+@L2TP_FALSE@@OPENCONNECT_BUILTIN_TRUE@@OPENCONNECT_TRUE@@VPN_TRUE@am__objects_33 = vpn/plugins/vpn_connman_vpnd-vpn.$(OBJEXT)
+@L2TP_FALSE@@OPENCONNECT_FALSE@@OPENVPN_BUILTIN_FALSE@@PPTP_BUILTIN_FALSE@@VPNC_BUILTIN_TRUE@@VPNC_TRUE@@VPN_TRUE@am__objects_33 = vpn/plugins/vpn_connman_vpnd-vpn.$(OBJEXT)
+@L2TP_FALSE@@OPENCONNECT_FALSE@@OPENVPN_BUILTIN_FALSE@@PPTP_BUILTIN_TRUE@@PPTP_TRUE@@VPN_TRUE@am__objects_33 = vpn/plugins/vpn_connman_vpnd-vpn.$(OBJEXT)
+@L2TP_FALSE@@OPENCONNECT_FALSE@@OPENVPN_BUILTIN_FALSE@@PPTP_FALSE@@VPNC_BUILTIN_TRUE@@VPNC_TRUE@@VPN_TRUE@am__objects_33 = vpn/plugins/vpn_connman_vpnd-vpn.$(OBJEXT)
+@L2TP_FALSE@@OPENCONNECT_FALSE@@OPENVPN_BUILTIN_TRUE@@OPENVPN_TRUE@@VPN_TRUE@am__objects_33 = vpn/plugins/vpn_connman_vpnd-vpn.$(OBJEXT)
+@L2TP_FALSE@@OPENCONNECT_FALSE@@OPENVPN_FALSE@@PPTP_BUILTIN_FALSE@@VPNC_BUILTIN_TRUE@@VPNC_TRUE@@VPN_TRUE@am__objects_33 = vpn/plugins/vpn_connman_vpnd-vpn.$(OBJEXT)
+@L2TP_FALSE@@OPENCONNECT_FALSE@@OPENVPN_FALSE@@PPTP_BUILTIN_TRUE@@PPTP_TRUE@@VPN_TRUE@am__objects_33 = vpn/plugins/vpn_connman_vpnd-vpn.$(OBJEXT)
+@L2TP_FALSE@@OPENCONNECT_FALSE@@OPENVPN_FALSE@@PPTP_FALSE@@VPNC_BUILTIN_TRUE@@VPNC_TRUE@@VPN_TRUE@am__objects_33 = vpn/plugins/vpn_connman_vpnd-vpn.$(OBJEXT)
+@VPN_TRUE@am__objects_34 = $(am__objects_28) $(am__objects_29) \
+@VPN_TRUE@	$(am__objects_30) $(am__objects_31) \
+@VPN_TRUE@	$(am__objects_32) $(am__objects_33)
+@WISPR_TRUE@am__objects_35 =  \
+@WISPR_TRUE@	gweb/vpn_connman_vpnd-giognutls.$(OBJEXT)
+@WISPR_FALSE@am__objects_36 =  \
+@WISPR_FALSE@	gweb/vpn_connman_vpnd-gionotls.$(OBJEXT)
+am__objects_37 = gweb/vpn_connman_vpnd-gweb.$(OBJEXT) \
+	gweb/vpn_connman_vpnd-gresolv.$(OBJEXT) $(am__objects_35) \
+	$(am__objects_36)
+@VPN_TRUE@am_vpn_connman_vpnd_OBJECTS = $(am__objects_34) \
+@VPN_TRUE@	$(am__objects_37) \
+@VPN_TRUE@	vpn/vpn_connman_vpnd-main.$(OBJEXT) \
+@VPN_TRUE@	src/vpn_connman_vpnd-log.$(OBJEXT) \
+@VPN_TRUE@	src/vpn_connman_vpnd-error.$(OBJEXT) \
+@VPN_TRUE@	src/vpn_connman_vpnd-plugin.$(OBJEXT) \
+@VPN_TRUE@	src/vpn_connman_vpnd-task.$(OBJEXT) \
+@VPN_TRUE@	vpn/vpn_connman_vpnd-vpn-manager.$(OBJEXT) \
+@VPN_TRUE@	vpn/vpn_connman_vpnd-vpn-provider.$(OBJEXT) \
+@VPN_TRUE@	vpn/vpn_connman_vpnd-vpn-ipconfig.$(OBJEXT) \
+@VPN_TRUE@	src/vpn_connman_vpnd-inet.$(OBJEXT) \
+@VPN_TRUE@	vpn/vpn_connman_vpnd-vpn-rtnl.$(OBJEXT) \
+@VPN_TRUE@	src/vpn_connman_vpnd-dbus.$(OBJEXT) \
+@VPN_TRUE@	src/vpn_connman_vpnd-storage.$(OBJEXT) \
+@VPN_TRUE@	src/vpn_connman_vpnd-ipaddress.$(OBJEXT) \
+@VPN_TRUE@	src/vpn_connman_vpnd-agent.$(OBJEXT) \
+@VPN_TRUE@	vpn/vpn_connman_vpnd-vpn-agent.$(OBJEXT) \
+@VPN_TRUE@	src/vpn_connman_vpnd-inotify.$(OBJEXT) \
+@VPN_TRUE@	vpn/vpn_connman_vpnd-vpn-config.$(OBJEXT)
+vpn_connman_vpnd_OBJECTS = $(am_vpn_connman_vpnd_OBJECTS)
+@VPN_TRUE@vpn_connman_vpnd_DEPENDENCIES = gdbus/libgdbus-internal.la \
+@VPN_TRUE@	$(am__DEPENDENCIES_1)
+vpn_connman_vpnd_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \
+	$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \
+	$(vpn_connman_vpnd_CFLAGS) $(CFLAGS) \
+	$(vpn_connman_vpnd_LDFLAGS) $(LDFLAGS) -o $@
+SCRIPTS = $(test_SCRIPTS)
+AM_V_P = $(am__v_P_@AM_V@)
+am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
+am__v_P_0 = false
+am__v_P_1 = :
+AM_V_GEN = $(am__v_GEN_@AM_V@)
+am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
+am__v_GEN_0 = @echo "  GEN     " $@;
+am__v_GEN_1 = 
+AM_V_at = $(am__v_at_@AM_V@)
+am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
+am__v_at_0 = @
+am__v_at_1 = 
+DEFAULT_INCLUDES = -I.@am__isrc@
+depcomp = $(SHELL) $(top_srcdir)/depcomp
+am__depfiles_maybe = depfiles
+am__mv = mv -f
+COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+	$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
+	$(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \
+	$(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
+	$(AM_CFLAGS) $(CFLAGS)
+AM_V_CC = $(am__v_CC_@AM_V@)
+am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@)
+am__v_CC_0 = @echo "  CC      " $@;
+am__v_CC_1 = 
+CCLD = $(CC)
+LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
+	$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+	$(AM_LDFLAGS) $(LDFLAGS) -o $@
+AM_V_CCLD = $(am__v_CCLD_@AM_V@)
+am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
+am__v_CCLD_0 = @echo "  CCLD    " $@;
+am__v_CCLD_1 = 
+SOURCES = $(gdbus_libgdbus_internal_la_SOURCES) \
+	plugins/hh2serial-gps.c plugins/iospm.c \
+	plugins/session_policy_local.c plugins/tist.c \
+	scripts/libppp-plugin.c $(vpn_plugins_l2tp_la_SOURCES) \
+	$(vpn_plugins_openconnect_la_SOURCES) \
+	$(vpn_plugins_openvpn_la_SOURCES) \
+	$(vpn_plugins_pptp_la_SOURCES) $(vpn_plugins_vpnc_la_SOURCES) \
+	$(client_connmanctl_SOURCES) scripts/openconnect-script.c \
+	scripts/openvpn-script.c $(src_connmand_SOURCES) \
+	tools/addr-test.c $(tools_dbus_test_SOURCES) \
+	$(tools_dhcp_server_test_SOURCES) $(tools_dhcp_test_SOURCES) \
+	$(tools_dnsproxy_test_SOURCES) $(tools_iptables_test_SOURCES) \
+	$(tools_iptables_unit_SOURCES) $(tools_netlink_test_SOURCES) \
+	tools/polkit-test.c tools/private-network-test.c \
+	$(tools_resolv_test_SOURCES) $(tools_session_test_SOURCES) \
+	tools/stats-tool.c $(tools_supplicant_test_SOURCES) \
+	tools/tap-test.c $(tools_web_test_SOURCES) \
+	$(tools_wispr_SOURCES) $(tools_wpad_test_SOURCES) \
+	$(unit_test_ippool_SOURCES) $(vpn_connman_vpnd_SOURCES)
+DIST_SOURCES = $(gdbus_libgdbus_internal_la_SOURCES) \
+	plugins/hh2serial-gps.c plugins/iospm.c \
+	plugins/session_policy_local.c plugins/tist.c \
+	scripts/libppp-plugin.c \
+	$(am__vpn_plugins_l2tp_la_SOURCES_DIST) \
+	$(am__vpn_plugins_openconnect_la_SOURCES_DIST) \
+	$(am__vpn_plugins_openvpn_la_SOURCES_DIST) \
+	$(am__vpn_plugins_pptp_la_SOURCES_DIST) \
+	$(am__vpn_plugins_vpnc_la_SOURCES_DIST) \
+	$(am__client_connmanctl_SOURCES_DIST) \
+	scripts/openconnect-script.c scripts/openvpn-script.c \
+	$(am__src_connmand_SOURCES_DIST) tools/addr-test.c \
+	$(am__tools_dbus_test_SOURCES_DIST) \
+	$(am__tools_dhcp_server_test_SOURCES_DIST) \
+	$(am__tools_dhcp_test_SOURCES_DIST) \
+	$(am__tools_dnsproxy_test_SOURCES_DIST) \
+	$(am__tools_iptables_test_SOURCES_DIST) \
+	$(am__tools_iptables_unit_SOURCES_DIST) \
+	$(am__tools_netlink_test_SOURCES_DIST) tools/polkit-test.c \
+	tools/private-network-test.c \
+	$(am__tools_resolv_test_SOURCES_DIST) \
+	$(am__tools_session_test_SOURCES_DIST) tools/stats-tool.c \
+	$(am__tools_supplicant_test_SOURCES_DIST) tools/tap-test.c \
+	$(am__tools_web_test_SOURCES_DIST) \
+	$(am__tools_wispr_SOURCES_DIST) \
+	$(am__tools_wpad_test_SOURCES_DIST) \
+	$(unit_test_ippool_SOURCES) \
+	$(am__vpn_connman_vpnd_SOURCES_DIST)
+am__can_run_installinfo = \
+  case $$AM_UPDATE_INFO_DIR in \
+    n|no|NO) false;; \
+    *) (install-info --version) >/dev/null 2>&1;; \
+  esac
+man1dir = $(mandir)/man1
+man5dir = $(mandir)/man5
+man8dir = $(mandir)/man8
+NROFF = nroff
+MANS = $(dist_man_MANS)
+DATA = $(dbusconf_DATA) $(dbusservice_DATA) $(pkgconfig_DATA) \
+	$(policy_DATA) $(script_DATA) $(systemdunit_DATA)
+HEADERS = $(include_HEADERS) $(nodist_include_HEADERS) \
+	$(noinst_HEADERS)
+am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) \
+	$(LISP)config.h.in
+# Read a list of newline-separated strings from the standard input,
+# and print each of them once, without duplicates.  Input order is
+# *not* preserved.
+am__uniquify_input = $(AWK) '\
+  BEGIN { nonempty = 0; } \
+  { items[$$0] = 1; nonempty = 1; } \
+  END { if (nonempty) { for (i in items) print i; }; } \
+'
+# Make sure the list of sources is unique.  This is necessary because,
+# e.g., the same source file might be shared among _SOURCES variables
+# for different programs/libraries.
+am__define_uniq_tagged_files = \
+  list='$(am__tagged_files)'; \
+  unique=`for i in $$list; do \
+    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+  done | $(am__uniquify_input)`
+ETAGS = etags
+CTAGS = ctags
+CSCOPE = cscope
+AM_RECURSIVE_TARGETS = cscope check recheck
+am__tty_colors_dummy = \
+  mgn= red= grn= lgn= blu= brg= std=; \
+  am__color_tests=no
+am__tty_colors = { \
+  $(am__tty_colors_dummy); \
+  if test "X$(AM_COLOR_TESTS)" = Xno; then \
+    am__color_tests=no; \
+  elif test "X$(AM_COLOR_TESTS)" = Xalways; then \
+    am__color_tests=yes; \
+  elif test "X$$TERM" != Xdumb && { test -t 1; } 2>/dev/null; then \
+    am__color_tests=yes; \
+  fi; \
+  if test $$am__color_tests = yes; then \
+    red=''; \
+    grn=''; \
+    lgn=''; \
+    blu=''; \
+    mgn=''; \
+    brg=''; \
+    std=''; \
+  fi; \
+}
+am__recheck_rx = ^[ 	]*:recheck:[ 	]*
+am__global_test_result_rx = ^[ 	]*:global-test-result:[ 	]*
+am__copy_in_global_log_rx = ^[ 	]*:copy-in-global-log:[ 	]*
+# A command that, given a newline-separated list of test names on the
+# standard input, print the name of the tests that are to be re-run
+# upon "make recheck".
+am__list_recheck_tests = $(AWK) '{ \
+  recheck = 1; \
+  while ((rc = (getline line < ($$0 ".trs"))) != 0) \
+    { \
+      if (rc < 0) \
+        { \
+          if ((getline line2 < ($$0 ".log")) < 0) \
+	    recheck = 0; \
+          break; \
+        } \
+      else if (line ~ /$(am__recheck_rx)[nN][Oo]/) \
+        { \
+          recheck = 0; \
+          break; \
+        } \
+      else if (line ~ /$(am__recheck_rx)[yY][eE][sS]/) \
+        { \
+          break; \
+        } \
+    }; \
+  if (recheck) \
+    print $$0; \
+  close ($$0 ".trs"); \
+  close ($$0 ".log"); \
+}'
+# A command that, given a newline-separated list of test names on the
+# standard input, create the global log from their .trs and .log files.
+am__create_global_log = $(AWK) ' \
+function fatal(msg) \
+{ \
+  print "fatal: making $@: " msg | "cat >&2"; \
+  exit 1; \
+} \
+function rst_section(header) \
+{ \
+  print header; \
+  len = length(header); \
+  for (i = 1; i <= len; i = i + 1) \
+    printf "="; \
+  printf "\n\n"; \
+} \
+{ \
+  copy_in_global_log = 1; \
+  global_test_result = "RUN"; \
+  while ((rc = (getline line < ($$0 ".trs"))) != 0) \
+    { \
+      if (rc < 0) \
+         fatal("failed to read from " $$0 ".trs"); \
+      if (line ~ /$(am__global_test_result_rx)/) \
+        { \
+          sub("$(am__global_test_result_rx)", "", line); \
+          sub("[ 	]*$$", "", line); \
+          global_test_result = line; \
+        } \
+      else if (line ~ /$(am__copy_in_global_log_rx)[nN][oO]/) \
+        copy_in_global_log = 0; \
+    }; \
+  if (copy_in_global_log) \
+    { \
+      rst_section(global_test_result ": " $$0); \
+      while ((rc = (getline line < ($$0 ".log"))) != 0) \
+      { \
+        if (rc < 0) \
+          fatal("failed to read from " $$0 ".log"); \
+        print line; \
+      }; \
+      printf "\n"; \
+    }; \
+  close ($$0 ".trs"); \
+  close ($$0 ".log"); \
+}'
+# Restructured Text title.
+am__rst_title = { sed 's/.*/   &   /;h;s/./=/g;p;x;s/ *$$//;p;g' && echo; }
+# Solaris 10 'make', and several other traditional 'make' implementations,
+# pass "-e" to $(SHELL), and POSIX 2008 even requires this.  Work around it
+# by disabling -e (using the XSI extension "set +e") if it's set.
+am__sh_e_setup = case $$- in *e*) set +e;; esac
+# Default flags passed to test drivers.
+am__common_driver_flags = \
+  --color-tests "$$am__color_tests" \
+  --enable-hard-errors "$$am__enable_hard_errors" \
+  --expect-failure "$$am__expect_failure"
+# To be inserted before the command running the test.  Creates the
+# directory for the log if needed.  Stores in $dir the directory
+# containing $f, in $tst the test, in $log the log.  Executes the
+# developer- defined test setup AM_TESTS_ENVIRONMENT (if any), and
+# passes TESTS_ENVIRONMENT.  Set up options for the wrapper that
+# will run the test scripts (or their associated LOG_COMPILER, if
+# thy have one).
+am__check_pre = \
+$(am__sh_e_setup);					\
+$(am__vpath_adj_setup) $(am__vpath_adj)			\
+$(am__tty_colors);					\
+srcdir=$(srcdir); export srcdir;			\
+case "$@" in						\
+  */*) am__odir=`echo "./$@" | sed 's|/[^/]*$$||'`;;	\
+    *) am__odir=.;; 					\
+esac;							\
+test "x$$am__odir" = x"." || test -d "$$am__odir" 	\
+  || $(MKDIR_P) "$$am__odir" || exit $$?;		\
+if test -f "./$$f"; then dir=./;			\
+elif test -f "$$f"; then dir=;				\
+else dir="$(srcdir)/"; fi;				\
+tst=$$dir$$f; log='$@'; 				\
+if test -n '$(DISABLE_HARD_ERRORS)'; then		\
+  am__enable_hard_errors=no; 				\
+else							\
+  am__enable_hard_errors=yes; 				\
+fi; 							\
+case " $(XFAIL_TESTS) " in				\
+  *[\ \	]$$f[\ \	]* | *[\ \	]$$dir$$f[\ \	]*) \
+    am__expect_failure=yes;;				\
+  *)							\
+    am__expect_failure=no;;				\
+esac; 							\
+$(AM_TESTS_ENVIRONMENT) $(TESTS_ENVIRONMENT)
+# A shell command to get the names of the tests scripts with any registered
+# extension removed (i.e., equivalently, the names of the test logs, with
+# the '.log' extension removed).  The result is saved in the shell variable
+# '$bases'.  This honors runtime overriding of TESTS and TEST_LOGS.  Sadly,
+# we cannot use something simpler, involving e.g., "$(TEST_LOGS:.log=)",
+# since that might cause problem with VPATH rewrites for suffix-less tests.
+# See also 'test-harness-vpath-rewrite.sh' and 'test-trs-basic.sh'.
+am__set_TESTS_bases = \
+  bases='$(TEST_LOGS)'; \
+  bases=`for i in $$bases; do echo $$i; done | sed 's/\.log$$//'`; \
+  bases=`echo $$bases`
+RECHECK_LOGS = $(TEST_LOGS)
+TEST_SUITE_LOG = test-suite.log
+TEST_EXTENSIONS = @EXEEXT@ .test
+LOG_DRIVER = $(SHELL) $(top_srcdir)/test-driver
+LOG_COMPILE = $(LOG_COMPILER) $(AM_LOG_FLAGS) $(LOG_FLAGS)
+am__set_b = \
+  case '$@' in \
+    */*) \
+      case '$*' in \
+        */*) b='$*';; \
+          *) b=`echo '$@' | sed 's/\.log$$//'`; \
+       esac;; \
+    *) \
+      b='$*';; \
+  esac
+am__test_logs1 = $(TESTS:=.log)
+am__test_logs2 = $(am__test_logs1:@EXEEXT@.log=.log)
+TEST_LOGS = $(am__test_logs2:.test.log=.log)
+TEST_LOG_DRIVER = $(SHELL) $(top_srcdir)/test-driver
+TEST_LOG_COMPILE = $(TEST_LOG_COMPILER) $(AM_TEST_LOG_FLAGS) \
+	$(TEST_LOG_FLAGS)
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+distdir = $(PACKAGE)-$(VERSION)
+top_distdir = $(distdir)
+am__remove_distdir = \
+  if test -d "$(distdir)"; then \
+    find "$(distdir)" -type d ! -perm -200 -exec chmod u+w {} ';' \
+      && rm -rf "$(distdir)" \
+      || { sleep 5 && rm -rf "$(distdir)"; }; \
+  else :; fi
+am__post_remove_distdir = $(am__remove_distdir)
+DIST_ARCHIVES = $(distdir).tar.gz
+GZIP_ENV = --best
+DIST_TARGETS = dist-gzip
+distuninstallcheck_listfiles = find . -type f -print
+am__distuninstallcheck_listfiles = $(distuninstallcheck_listfiles) \
+  | sed 's|^\./|$(prefix)/|' | grep -v '$(infodir)/dir$$'
+distcleancheck_listfiles = find . -type f -print
+ACLOCAL = @ACLOCAL@
+AMTAR = @AMTAR@
+AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
+AR = @AR@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+CC = @CC@
+CCDEPMODE = @CCDEPMODE@
+CFLAGS = @CFLAGS@
+CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
+CYGPATH_W = @CYGPATH_W@
+DBUS_CFLAGS = @DBUS_CFLAGS@
+DBUS_CONFDIR = @DBUS_CONFDIR@
+DBUS_DATADIR = @DBUS_DATADIR@
+DBUS_LIBS = @DBUS_LIBS@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+DLLTOOL = @DLLTOOL@
+DSYMUTIL = @DSYMUTIL@
+DUMPBIN = @DUMPBIN@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EGREP = @EGREP@
+EXEEXT = @EXEEXT@
+FGREP = @FGREP@
+GLIB_CFLAGS = @GLIB_CFLAGS@
+GLIB_LIBS = @GLIB_LIBS@
+GNUTLS_CFLAGS = @GNUTLS_CFLAGS@
+GNUTLS_LIBS = @GNUTLS_LIBS@
+GREP = @GREP@
+INSTALL = @INSTALL@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+IPTABLES_SAVE = @IPTABLES_SAVE@
+L2TP = @L2TP@
+LD = @LD@
+LDFLAGS = @LDFLAGS@
+LIBOBJS = @LIBOBJS@
+LIBS = @LIBS@
+LIBTOOL = @LIBTOOL@
+LIPO = @LIPO@
+LN_S = @LN_S@
+LTLIBOBJS = @LTLIBOBJS@
+MAINT = @MAINT@
+MAKEINFO = @MAKEINFO@
+MANIFEST_TOOL = @MANIFEST_TOOL@
+MKDIR_P = @MKDIR_P@
+NM = @NM@
+NMEDIT = @NMEDIT@
+OBJDUMP = @OBJDUMP@
+OBJEXT = @OBJEXT@
+OPENCONNECT = @OPENCONNECT@
+OPENVPN = @OPENVPN@
+OTOOL = @OTOOL@
+OTOOL64 = @OTOOL64@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_URL = @PACKAGE_URL@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+PKG_CONFIG = @PKG_CONFIG@
+PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
+PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
+POLKIT_DATADIR = @POLKIT_DATADIR@
+PPPD = @PPPD@
+PPTP = @PPTP@
+RANLIB = @RANLIB@
+SED = @SED@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+STRIP = @STRIP@
+SYSTEMD_UNITDIR = @SYSTEMD_UNITDIR@
+VERSION = @VERSION@
+VPNC = @VPNC@
+WPASUPPLICANT = @WPASUPPLICANT@
+XTABLES_CFLAGS = @XTABLES_CFLAGS@
+XTABLES_LIBS = @XTABLES_LIBS@
+abs_builddir = @abs_builddir@
+abs_srcdir = @abs_srcdir@
+abs_top_builddir = @abs_top_builddir@
+abs_top_srcdir = @abs_top_srcdir@
+ac_ct_AR = @ac_ct_AR@
+ac_ct_CC = @ac_ct_CC@
+ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
+am__include = @am__include@
+am__leading_dot = @am__leading_dot@
+am__quote = @am__quote@
+am__tar = @am__tar@
+am__untar = @am__untar@
+bindir = @bindir@
+build = @build@
+build_alias = @build_alias@
+build_cpu = @build_cpu@
+build_os = @build_os@
+build_vendor = @build_vendor@
+builddir = @builddir@
+datadir = @datadir@
+datarootdir = @datarootdir@
+docdir = @docdir@
+dvidir = @dvidir@
+exec_prefix = @exec_prefix@
+host = @host@
+host_alias = @host_alias@
+host_cpu = @host_cpu@
+host_os = @host_os@
+host_vendor = @host_vendor@
+htmldir = @htmldir@
+includedir = @includedir@/connman
+infodir = @infodir@
+install_sh = @install_sh@
+libdir = @libdir@
+libexecdir = @libexecdir@
+localedir = @localedir@
+localstatedir = @localstatedir@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+oldincludedir = @oldincludedir@
+pdfdir = @pdfdir@
+prefix = @prefix@
+program_transform_name = @program_transform_name@
+psdir = @psdir@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+srcdir = @srcdir@
+sysconfdir = @sysconfdir@
+target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
+top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
+AM_MAKEFLAGS = --no-print-directory
+noinst_LTLIBRARIES = gdbus/libgdbus-internal.la
+include_HEADERS = include/log.h include/plugin.h \
+			include/notifier.h include/service.h \
+			include/resolver.h include/ipconfig.h \
+			include/device.h include/network.h include/inet.h \
+			include/storage.h include/provision.h \
+			include/session.h include/ipaddress.h include/agent.h \
+			include/inotify.h include/peer.h include/machine.h \
+			include/technology.h \
+			include/dbus.h \
+			include/gdbus.h
+
+nodist_include_HEADERS = include/version.h
+noinst_HEADERS = include/rtnl.h include/task.h \
+			include/option.h \
+			include/provider.h include/vpn-dbus.h \
+			include/utsname.h include/timeserver.h include/proxy.h \
+			include/setting.h
+
+local_headers = $(foreach file,$(include_HEADERS) $(nodist_include_HEADERS) \
+			$(noinst_HEADERS), include/connman/$(notdir $(file)))
+
+gdbus_libgdbus_internal_la_SOURCES = gdbus/gdbus.h \
+				gdbus/mainloop.c gdbus/watch.c \
+				gdbus/object.c gdbus/client.c gdbus/polkit.c
+
+gdhcp_sources = gdhcp/gdhcp.h gdhcp/common.h gdhcp/common.c gdhcp/client.c \
+		gdhcp/server.c gdhcp/ipv4ll.h gdhcp/ipv4ll.c gdhcp/unaligned.h \
+		gdhcp/timer.c gdhcp/timer.h
+
+gweb_sources = gweb/gweb.h gweb/gweb.c gweb/gresolv.h gweb/gresolv.c \
+	$(am__append_1) $(am__append_2)
+shared_sources = src/shared/util.h src/shared/util.c \
+		src/shared/netlink.h src/shared/netlink.c
+
+@DATAFILES_TRUE@@NMCOMPAT_TRUE@nmcompat_conf = plugins/connman-nmcompat.conf
+@DATAFILES_TRUE@dbusconfdir = @DBUS_CONFDIR@
+@DATAFILES_TRUE@dbusconf_DATA = src/connman.conf $(nmcompat_conf) \
+@DATAFILES_TRUE@	$(am__append_3)
+@DATAFILES_TRUE@@VPN_TRUE@dbusservicedir = @DBUS_DATADIR@
+@DATAFILES_TRUE@@VPN_TRUE@dbusservice_DATA = vpn/net.connman.vpn.service
+@DATAFILES_TRUE@@SYSTEMD_TRUE@systemdunitdir = @SYSTEMD_UNITDIR@
+@DATAFILES_TRUE@@SYSTEMD_TRUE@systemdunit_DATA = src/connman.service \
+@DATAFILES_TRUE@@SYSTEMD_TRUE@	$(am__append_4)
+service_files_sources = src/connman.service.in src/net.connman.service.in \
+				vpn/connman-vpn.service.in \
+				vpn/net.connman.vpn.service.in
+
+service_files = src/connman.service src/net.connman.service \
+				vpn/connman-vpn.service \
+				vpn/net.connman.vpn.service
+
+plugin_LTLIBRARIES = $(am__append_19) $(am__append_59) \
+	$(am__append_68) $(am__append_72)
+plugin_objects = $(am__append_20) $(am__append_60) $(am__append_69) \
+	$(am__append_73)
+builtin_modules = $(am__append_7) $(am__append_9) $(am__append_11) \
+	$(am__append_13) $(am__append_15) $(am__append_17) \
+	$(am__append_21) $(am__append_23) $(am__append_25) \
+	$(am__append_54) $(am__append_56) $(am__append_64) \
+	$(am__append_66) $(am__append_70) $(am__append_74)
+builtin_sources = $(am__append_8) $(am__append_10) $(am__append_12) \
+	$(am__append_14) $(am__append_16) $(am__append_18) \
+	$(am__append_22) $(am__append_24) $(am__append_26) \
+	$(am__append_55) $(am__append_57) $(am__append_65) \
+	$(am__append_67) $(am__append_71) $(am__append_75)
+builtin_libadd = 
+builtin_cflags = 
+unit_objects = 
+MANUAL_PAGES = $(am__append_77) doc/connman.8 doc/connman.conf.5
+src_connmand_SOURCES = $(gdhcp_sources) $(gweb_sources) \
+			$(builtin_sources) $(shared_sources) src/connman.ver \
+			src/main.c src/connman.h src/log.c \
+			src/error.c src/plugin.c src/task.c \
+			src/device.c src/network.c src/connection.c \
+			src/manager.c src/service.c \
+			src/clock.c src/timezone.c src/agent-connman.c \
+			src/agent.c src/notifier.c src/provider.c \
+			src/resolver.c src/ipconfig.c src/detect.c src/inet.c \
+			src/dhcp.c src/dhcpv6.c src/rtnl.c src/proxy.c \
+			src/utsname.c src/timeserver.c src/rfkill.c \
+			src/storage.c src/dbus.c src/config.c \
+			src/technology.c src/counter.c src/ntp.c \
+			src/session.c src/tethering.c src/wpad.c src/wispr.c \
+			src/stats.c src/iptables.c src/dnsproxy.c src/6to4.c \
+			src/ippool.c src/bridge.c src/nat.c src/ipaddress.c \
+			src/inotify.c src/firewall.c src/ipv6pd.c src/peer.c \
+			src/peer_service.c src/machine.c src/util.c \
+			src/rlimits.c
+
+src_connmand_LDADD = gdbus/libgdbus-internal.la $(builtin_libadd) \
+			@GLIB_LIBS@ @DBUS_LIBS@ @XTABLES_LIBS@ @GNUTLS_LIBS@ \
+			-lresolv -ldl -lrt
+
+src_connmand_LDFLAGS = -Wl,--export-dynamic \
+				-Wl,--version-script=$(srcdir)/src/connman.ver
+
+@VPN_TRUE@vpn_plugin_LTLIBRARIES = $(am__append_30) $(am__append_35) \
+@VPN_TRUE@	$(am__append_40) $(am__append_45) $(am__append_50)
+@VPN_TRUE@vpn_plugin_objects = $(am__append_31) $(am__append_36) \
+@VPN_TRUE@	$(am__append_41) $(am__append_46) $(am__append_51)
+@VPN_TRUE@builtin_vpn_modules = $(am__append_27) $(am__append_32) \
+@VPN_TRUE@	$(am__append_37) $(am__append_42) $(am__append_47)
+@VPN_TRUE@builtin_vpn_sources = $(am__append_28) $(am__append_33) \
+@VPN_TRUE@	$(am__append_38) $(am__append_43) $(am__append_48) \
+@VPN_TRUE@	$(builtin_vpn_source)
+@VPN_TRUE@builtin_vpn_libadd = 
+@VPN_TRUE@builtin_vpn_cflags = $(am__append_29) $(am__append_34) \
+@VPN_TRUE@	$(am__append_39) $(am__append_44) $(am__append_49)
+@VPN_TRUE@vpn_connman_vpnd_SOURCES = $(builtin_vpn_sources) \
+@VPN_TRUE@			$(gweb_sources) vpn/vpn.ver vpn/main.c vpn/vpn.h \
+@VPN_TRUE@			src/log.c src/error.c src/plugin.c src/task.c \
+@VPN_TRUE@			vpn/vpn-manager.c vpn/vpn-provider.c \
+@VPN_TRUE@			vpn/vpn-provider.h vpn/vpn-rtnl.h \
+@VPN_TRUE@			vpn/vpn-ipconfig.c src/inet.c vpn/vpn-rtnl.c \
+@VPN_TRUE@			src/dbus.c src/storage.c src/ipaddress.c src/agent.c \
+@VPN_TRUE@			vpn/vpn-agent.c vpn/vpn-agent.h src/inotify.c \
+@VPN_TRUE@			vpn/vpn-config.c
+
+@VPN_TRUE@vpn_connman_vpnd_LDADD = gdbus/libgdbus-internal.la $(builtin_vpn_libadd) \
+@VPN_TRUE@				@GLIB_LIBS@ @DBUS_LIBS@ @GNUTLS_LIBS@ \
+@VPN_TRUE@				-lresolv -ldl
+
+@VPN_TRUE@vpn_connman_vpnd_LDFLAGS = -Wl,--export-dynamic \
+@VPN_TRUE@				-Wl,--version-script=$(srcdir)/vpn/vpn.ver
+
+BUILT_SOURCES = $(local_headers) src/builtin.h $(service_files) \
+	scripts/connman $(am__append_6)
+CLEANFILES = src/connman.conf $(BUILT_SOURCES) $(service_files) \
+	$(am__append_81)
+statedir = $(localstatedir)/run/connman
+vpn_statedir = $(localstatedir)/run/connman-vpn
+@VPN_TRUE@vpn_plugindir = $(libdir)/connman/plugins-vpn
+plugindir = $(libdir)/connman/plugins
+scriptdir = $(libdir)/connman/scripts
+storagedir = $(localstatedir)/lib/connman
+vpn_storagedir = $(localstatedir)/lib/connman-vpn
+configdir = ${sysconfdir}/connman
+@MAINTAINER_MODE_FALSE@@VPN_TRUE@build_vpn_plugindir = $(vpn_plugindir)
+@MAINTAINER_MODE_TRUE@@VPN_TRUE@build_vpn_plugindir = $(abs_top_srcdir)/vpn/plugins/.libs
+@MAINTAINER_MODE_FALSE@build_plugindir = $(plugindir)
+@MAINTAINER_MODE_TRUE@build_plugindir = $(abs_top_srcdir)/plugins/.libs
+@MAINTAINER_MODE_FALSE@build_scriptdir = $(scriptdir)
+@MAINTAINER_MODE_TRUE@build_scriptdir = $(abs_top_srcdir)/scripts
+AM_CFLAGS = @DBUS_CFLAGS@ @GLIB_CFLAGS@ @XTABLES_CFLAGS@ \
+				@GNUTLS_CFLAGS@ $(builtin_cflags) \
+				-DCONNMAN_PLUGIN_BUILTIN \
+				-DSTATEDIR=\""$(statedir)"\" \
+				-DVPN_STATEDIR=\""$(vpn_statedir)"\" \
+				-DPLUGINDIR=\""$(build_plugindir)"\" \
+				-DSCRIPTDIR=\""$(build_scriptdir)"\" \
+				-DSTORAGEDIR=\""$(storagedir)\"" \
+				-DVPN_STORAGEDIR=\""$(vpn_storagedir)\"" \
+				-DCONFIGDIR=\""$(configdir)\""
+
+@VPN_FALSE@AM_CPPFLAGS = -I$(builddir)/include -I$(builddir)/src -I$(srcdir)/gdbus
+@VPN_TRUE@AM_CPPFLAGS = -I$(builddir)/include -I$(srcdir)/gdbus
+src_connmand_CFLAGS = @DBUS_CFLAGS@ @GLIB_CFLAGS@ @XTABLES_CFLAGS@ \
+				@GNUTLS_CFLAGS@ $(builtin_cflags) \
+				-DCONNMAN_PLUGIN_BUILTIN \
+				-DSTATEDIR=\""$(statedir)"\" \
+				-DPLUGINDIR=\""$(build_plugindir)"\" \
+				-DSCRIPTDIR=\""$(build_scriptdir)"\" \
+				-DSTORAGEDIR=\""$(storagedir)\"" \
+				-DVPN_STORAGEDIR=\""$(vpn_storagedir)\"" \
+				-DCONFIGDIR=\""$(configdir)\"" \
+				-I$(builddir)/src
+
+EXTRA_DIST = src/genbuiltin src/connman-dbus.conf \
+	src/connman-polkit.conf plugins/connman-nmcompat.conf \
+	$(service_files_sources) scripts/connman.in vpn/vpn-dbus.conf \
+	vpn/vpn-polkit.conf plugins/polkit.policy \
+	vpn/vpn-polkit.policy $(test_scripts) doc/overview-api.txt \
+	doc/behavior-api.txt doc/coding-style.txt \
+	doc/wifi-p2p-overview.txt doc/vpn-agent-api.txt \
+	doc/peer-api.txt doc/ipconfig-api.txt doc/plugin-api.txt \
+	doc/manager-api.txt doc/agent-api.txt doc/service-api.txt \
+	doc/technology-api.txt doc/counter-api.txt \
+	doc/config-format.txt doc/clock-api.txt doc/session-api.txt \
+	doc/session-overview.txt doc/backtrace.txt \
+	doc/advanced-configuration.txt doc/vpn-config-format.txt \
+	doc/vpn-connection-api.txt doc/vpn-manager-api.txt \
+	doc/vpn-overview.txt doc/session-policy-format.txt \
+	src/main.conf src/eduroam.config $(am__append_80) \
+	vpn/connman-task.te
+@VPN_TRUE@vpn_connman_vpnd_CFLAGS = @DBUS_CFLAGS@ @GLIB_CFLAGS@ \
+@VPN_TRUE@				$(builtin_vpn_cflags) \
+@VPN_TRUE@				-DCONNMAN_PLUGIN_BUILTIN \
+@VPN_TRUE@				-DVPN_STATEDIR=\""$(vpn_statedir)"\" \
+@VPN_TRUE@				-DPLUGINDIR=\""$(build_vpn_plugindir)"\" \
+@VPN_TRUE@				-DSCRIPTDIR=\""$(build_scriptdir)"\" \
+@VPN_TRUE@				-DSTORAGEDIR=\""$(storagedir)\"" \
+@VPN_TRUE@				-DVPN_STORAGEDIR=\""$(vpn_storagedir)\"" \
+@VPN_TRUE@				-DCONFIGDIR=\""$(configdir)\"" \
+@VPN_TRUE@				-I$(builddir)/vpn
+
+script_DATA = 
+script_LTLIBRARIES = $(am__append_52) $(am__append_53)
+plugin_cflags = -fvisibility=hidden -I$(srcdir)/gdbus \
+					@DBUS_CFLAGS@ @GLIB_CFLAGS@
+
+plugin_ldflags = -no-undefined -module -avoid-version
+gsupplicant_sources = gsupplicant/gsupplicant.h gsupplicant/dbus.h \
+			gsupplicant/supplicant.c gsupplicant/dbus.c
+
+@HH2SERIAL_GPS_BUILTIN_FALSE@@HH2SERIAL_GPS_TRUE@plugins_hh2serial_gps_la_CFLAGS = $(plugin_cflags)
+@HH2SERIAL_GPS_BUILTIN_FALSE@@HH2SERIAL_GPS_TRUE@plugins_hh2serial_gps_la_LDFLAGS = $(plugin_ldflags)
+@L2TP_BUILTIN_TRUE@@L2TP_TRUE@@VPN_TRUE@builtin_vpn_source = vpn/plugins/vpn.c vpn/plugins/vpn.h
+@OPENCONNECT_BUILTIN_TRUE@@OPENCONNECT_TRUE@@VPN_TRUE@builtin_vpn_source = vpn/plugins/vpn.c vpn/plugins/vpn.h
+@OPENVPN_BUILTIN_TRUE@@OPENVPN_TRUE@@VPN_TRUE@builtin_vpn_source = vpn/plugins/vpn.c vpn/plugins/vpn.h
+@PPTP_BUILTIN_TRUE@@PPTP_TRUE@@VPN_TRUE@builtin_vpn_source = vpn/plugins/vpn.c vpn/plugins/vpn.h
+@VPNC_BUILTIN_TRUE@@VPNC_TRUE@@VPN_TRUE@builtin_vpn_source = vpn/plugins/vpn.c vpn/plugins/vpn.h
+@OPENCONNECT_BUILTIN_FALSE@@OPENCONNECT_TRUE@@VPN_TRUE@vpn_plugins_openconnect_la_SOURCES = vpn/plugins/vpn.h vpn/plugins/vpn.c \
+@OPENCONNECT_BUILTIN_FALSE@@OPENCONNECT_TRUE@@VPN_TRUE@						vpn/plugins/openconnect.c
+
+@OPENCONNECT_BUILTIN_FALSE@@OPENCONNECT_TRUE@@VPN_TRUE@vpn_plugins_openconnect_la_CFLAGS = $(plugin_cflags) \
+@OPENCONNECT_BUILTIN_FALSE@@OPENCONNECT_TRUE@@VPN_TRUE@					-DOPENCONNECT=\"@OPENCONNECT@\" \
+@OPENCONNECT_BUILTIN_FALSE@@OPENCONNECT_TRUE@@VPN_TRUE@					-DVPN_STATEDIR=\""$(vpn_statedir)"\" \
+@OPENCONNECT_BUILTIN_FALSE@@OPENCONNECT_TRUE@@VPN_TRUE@					-DSCRIPTDIR=\""$(build_scriptdir)"\"
+
+@OPENCONNECT_BUILTIN_FALSE@@OPENCONNECT_TRUE@@VPN_TRUE@vpn_plugins_openconnect_la_LDFLAGS = $(plugin_ldflags)
+@OPENVPN_BUILTIN_FALSE@@OPENVPN_TRUE@@VPN_TRUE@vpn_plugins_openvpn_la_SOURCES = vpn/plugins/vpn.h vpn/plugins/vpn.c \
+@OPENVPN_BUILTIN_FALSE@@OPENVPN_TRUE@@VPN_TRUE@						vpn/plugins/openvpn.c
+
+@OPENVPN_BUILTIN_FALSE@@OPENVPN_TRUE@@VPN_TRUE@vpn_plugins_openvpn_la_CFLAGS = $(plugin_cflags) -DOPENVPN=\"@OPENVPN@\" \
+@OPENVPN_BUILTIN_FALSE@@OPENVPN_TRUE@@VPN_TRUE@					-DVPN_STATEDIR=\""$(vpn_statedir)"\" \
+@OPENVPN_BUILTIN_FALSE@@OPENVPN_TRUE@@VPN_TRUE@					-DSCRIPTDIR=\""$(build_scriptdir)"\"
+
+@OPENVPN_BUILTIN_FALSE@@OPENVPN_TRUE@@VPN_TRUE@vpn_plugins_openvpn_la_LDFLAGS = $(plugin_ldflags)
+@VPNC_BUILTIN_FALSE@@VPNC_TRUE@@VPN_TRUE@vpn_plugins_vpnc_la_SOURCES = vpn/plugins/vpn.h vpn/plugins/vpn.c \
+@VPNC_BUILTIN_FALSE@@VPNC_TRUE@@VPN_TRUE@						vpn/plugins/vpnc.c
+
+@VPNC_BUILTIN_FALSE@@VPNC_TRUE@@VPN_TRUE@vpn_plugins_vpnc_la_CFLAGS = $(plugin_cflags) -DVPNC=\"@VPNC@\" \
+@VPNC_BUILTIN_FALSE@@VPNC_TRUE@@VPN_TRUE@					-DVPN_STATEDIR=\""$(vpn_statedir)"\" \
+@VPNC_BUILTIN_FALSE@@VPNC_TRUE@@VPN_TRUE@					-DSCRIPTDIR=\""$(build_scriptdir)"\"
+
+@VPNC_BUILTIN_FALSE@@VPNC_TRUE@@VPN_TRUE@vpn_plugins_vpnc_la_LDFLAGS = $(plugin_ldflags)
+@L2TP_BUILTIN_FALSE@@L2TP_TRUE@@VPN_TRUE@vpn_plugins_l2tp_la_SOURCES = vpn/plugins/vpn.h vpn/plugins/vpn.c \
+@L2TP_BUILTIN_FALSE@@L2TP_TRUE@@VPN_TRUE@						vpn/plugins/l2tp.c
+
+@L2TP_BUILTIN_FALSE@@L2TP_TRUE@@VPN_TRUE@vpn_plugins_l2tp_la_CFLAGS = $(plugin_cflags) -DL2TP=\"@L2TP@\" \
+@L2TP_BUILTIN_FALSE@@L2TP_TRUE@@VPN_TRUE@					-DVPN_STATEDIR=\""$(vpn_statedir)"\" \
+@L2TP_BUILTIN_FALSE@@L2TP_TRUE@@VPN_TRUE@					-DSCRIPTDIR=\""$(build_scriptdir)"\"
+
+@L2TP_BUILTIN_FALSE@@L2TP_TRUE@@VPN_TRUE@vpn_plugins_l2tp_la_LDFLAGS = $(plugin_ldflags)
+@PPTP_BUILTIN_FALSE@@PPTP_TRUE@@VPN_TRUE@vpn_plugins_pptp_la_SOURCES = vpn/plugins/vpn.h vpn/plugins/vpn.c \
+@PPTP_BUILTIN_FALSE@@PPTP_TRUE@@VPN_TRUE@						vpn/plugins/pptp.c
+
+@PPTP_BUILTIN_FALSE@@PPTP_TRUE@@VPN_TRUE@vpn_plugins_pptp_la_CFLAGS = $(plugin_cflags) -DPPPD=\"@PPPD@\" \
+@PPTP_BUILTIN_FALSE@@PPTP_TRUE@@VPN_TRUE@					-DPPTP=\"@PPTP@\" \
+@PPTP_BUILTIN_FALSE@@PPTP_TRUE@@VPN_TRUE@					-DVPN_STATEDIR=\""$(vpn_statedir)"\" \
+@PPTP_BUILTIN_FALSE@@PPTP_TRUE@@VPN_TRUE@					-DSCRIPTDIR=\""$(build_scriptdir)"\"
+
+@PPTP_BUILTIN_FALSE@@PPTP_TRUE@@VPN_TRUE@vpn_plugins_pptp_la_LDFLAGS = $(plugin_ldflags)
+@L2TP_TRUE@@PPTP_FALSE@@VPN_TRUE@scripts_libppp_plugin_la_LDFLAGS = $(plugin_ldflags)
+@PPTP_TRUE@@VPN_TRUE@scripts_libppp_plugin_la_LDFLAGS = $(plugin_ldflags)
+@L2TP_TRUE@@PPTP_FALSE@@VPN_TRUE@scripts_libppp_plugin_la_LIBADD = @DBUS_LIBS@
+@PPTP_TRUE@@VPN_TRUE@scripts_libppp_plugin_la_LIBADD = @DBUS_LIBS@
+@DATAFILES_TRUE@@POLKIT_TRUE@policydir = @POLKIT_DATADIR@
+@DATAFILES_TRUE@@POLKIT_TRUE@policy_DATA = plugins/net.connman.policy \
+@DATAFILES_TRUE@@POLKIT_TRUE@	$(am__append_58)
+@IOSPM_TRUE@plugins_iospm_la_CFLAGS = $(plugin_cflags)
+@IOSPM_TRUE@plugins_iospm_la_LDFLAGS = $(plugin_ldflags)
+@OPENCONNECT_FALSE@@VPNC_TRUE@scripts_openconnect_script_LDADD = @DBUS_LIBS@
+@OPENCONNECT_TRUE@scripts_openconnect_script_LDADD = @DBUS_LIBS@
+@OPENVPN_TRUE@scripts_openvpn_script_LDADD = @DBUS_LIBS@
+@TIST_BUILTIN_FALSE@@TIST_TRUE@plugins_tist_la_CFLAGS = $(plugin_cflags)
+@TIST_BUILTIN_FALSE@@TIST_TRUE@plugins_tist_la_LDFLAGS = $(plugin_ldflags)
+@SESSION_POLICY_LOCAL_BUILTIN_FALSE@@SESSION_POLICY_LOCAL_TRUE@plugins_session_policy_local_la_CFLAGS = $(plugin_cflags) \
+@SESSION_POLICY_LOCAL_BUILTIN_FALSE@@SESSION_POLICY_LOCAL_TRUE@				-DSTORAGEDIR=\""$(storagedir)\""
+
+@SESSION_POLICY_LOCAL_BUILTIN_FALSE@@SESSION_POLICY_LOCAL_TRUE@plugins_session_policy_local_la_LDFLAGS = $(plugin_ldflags)
+@CLIENT_TRUE@client_connmanctl_SOURCES = client/dbus_helpers.h client/dbus_helpers.c \
+@CLIENT_TRUE@			client/services.h client/services.c \
+@CLIENT_TRUE@			client/commands.h client/commands.c \
+@CLIENT_TRUE@			client/input.h client/input.c \
+@CLIENT_TRUE@			client/agent.h client/agent.c \
+@CLIENT_TRUE@			client/peers.h client/peers.c \
+@CLIENT_TRUE@			client/vpnconnections.h client/vpnconnections.c \
+@CLIENT_TRUE@			client/main.c
+
+@CLIENT_TRUE@client_connmanctl_LDADD = gdbus/libgdbus-internal.la @DBUS_LIBS@ @GLIB_LIBS@ \
+@CLIENT_TRUE@				-lreadline -ldl
+
+unit_test_ippool_SOURCES = src/log.c src/dbus.c src/error.c \
+					src/ippool.c unit/test-ippool.c
+
+unit_test_ippool_LDADD = gdbus/libgdbus-internal.la \
+				@GLIB_LIBS@ @DBUS_LIBS@ -ldl
+
+@WISPR_TRUE@tools_wispr_SOURCES = $(gweb_sources) tools/wispr.c
+@WISPR_TRUE@tools_wispr_LDADD = @GLIB_LIBS@ @GNUTLS_LIBS@ -lresolv
+@TOOLS_TRUE@tools_supplicant_test_SOURCES = tools/supplicant-test.c \
+@TOOLS_TRUE@			tools/supplicant-dbus.h tools/supplicant-dbus.c \
+@TOOLS_TRUE@			tools/supplicant.h tools/supplicant.c
+
+@TOOLS_TRUE@tools_supplicant_test_LDADD = gdbus/libgdbus-internal.la \
+@TOOLS_TRUE@				@GLIB_LIBS@ @DBUS_LIBS@
+
+@TOOLS_TRUE@tools_web_test_SOURCES = $(gweb_sources) tools/web-test.c
+@TOOLS_TRUE@tools_web_test_LDADD = @GLIB_LIBS@ @GNUTLS_LIBS@ -lresolv
+@TOOLS_TRUE@tools_resolv_test_SOURCES = gweb/gresolv.h gweb/gresolv.c tools/resolv-test.c
+@TOOLS_TRUE@tools_resolv_test_LDADD = @GLIB_LIBS@ -lresolv
+@TOOLS_TRUE@tools_wpad_test_SOURCES = gweb/gresolv.h gweb/gresolv.c tools/wpad-test.c
+@TOOLS_TRUE@tools_wpad_test_LDADD = @GLIB_LIBS@ -lresolv
+@TOOLS_TRUE@tools_stats_tool_LDADD = @GLIB_LIBS@
+@TOOLS_TRUE@tools_dhcp_test_SOURCES = $(gdhcp_sources) tools/dhcp-test.c
+@TOOLS_TRUE@tools_dhcp_test_LDADD = @GLIB_LIBS@
+@TOOLS_TRUE@tools_dhcp_server_test_SOURCES = $(gdhcp_sources) tools/dhcp-server-test.c
+@TOOLS_TRUE@tools_dhcp_server_test_LDADD = @GLIB_LIBS@
+@TOOLS_TRUE@tools_dbus_test_SOURCES = tools/dbus-test.c
+@TOOLS_TRUE@tools_dbus_test_LDADD = gdbus/libgdbus-internal.la @GLIB_LIBS@ @DBUS_LIBS@
+@TOOLS_TRUE@tools_polkit_test_LDADD = @DBUS_LIBS@
+@TOOLS_TRUE@tools_iptables_test_SOURCES = src/log.c src/iptables.c tools/iptables-test.c
+@TOOLS_TRUE@tools_iptables_test_LDADD = @GLIB_LIBS@ @XTABLES_LIBS@ -ldl
+@TOOLS_TRUE@tools_private_network_test_LDADD = @GLIB_LIBS@ @DBUS_LIBS@
+@TOOLS_TRUE@tools_session_test_SOURCES = src/log.c src/dbus.c src/error.c \
+@TOOLS_TRUE@		tools/session-test.c tools/session-utils.c tools/manager-api.c \
+@TOOLS_TRUE@		tools/session-api.c tools/session-test.h
+
+@TOOLS_TRUE@tools_session_test_LDADD = gdbus/libgdbus-internal.la \
+@TOOLS_TRUE@				@GLIB_LIBS@ @DBUS_LIBS@ -ldl
+
+@TOOLS_TRUE@tools_iptables_unit_CFLAGS = @DBUS_CFLAGS@ @GLIB_CFLAGS@ @XTABLES_CFLAGS@ \
+@TOOLS_TRUE@		-DIPTABLES_SAVE=\""${IPTABLES_SAVE}"\"
+
+@TOOLS_TRUE@tools_iptables_unit_SOURCES = src/log.c \
+@TOOLS_TRUE@		 src/iptables.c src/firewall.c src/nat.c tools/iptables-unit.c
+
+@TOOLS_TRUE@tools_iptables_unit_LDADD = gdbus/libgdbus-internal.la \
+@TOOLS_TRUE@				@GLIB_LIBS@ @DBUS_LIBS@ @XTABLES_LIBS@ -ldl
+
+@TOOLS_TRUE@tools_dnsproxy_test_SOURCES = tools/dnsproxy-test.c
+@TOOLS_TRUE@tools_dnsproxy_test_LDADD = @GLIB_LIBS@
+@TOOLS_TRUE@tools_netlink_test_SOURCES = $(shared_sources) tools/netlink-test.c
+@TOOLS_TRUE@tools_netlink_test_LDADD = @GLIB_LIBS@
+test_scripts = test/get-state test/list-services test/monitor-services \
+	test/test-clock test/simple-agent test/show-introspection \
+	test/test-compat test/test-manager test/test-connman \
+	test/monitor-connman test/connect-provider \
+	test/remove-provider test/test-counter test/set-ipv4-method \
+	test/set-ipv6-method test/get-services \
+	test/get-proxy-autoconfig test/set-proxy test/enable-tethering \
+	test/disable-tethering test/backtrace test/test-session \
+	test/p2p-on-supplicant test/test-new-supplicant \
+	test/service-move-before test/set-global-timeservers \
+	test/get-global-timeservers test/set-nameservers \
+	test/set-domains test/set-timeservers test/set-clock \
+	test/vpn-connect test/vpn-disconnect test/vpn-get \
+	test/monitor-vpn test/vpn-property
+@TEST_TRUE@testdir = $(pkglibdir)/test
+@TEST_TRUE@test_SCRIPTS = $(test_scripts)
+dist_man_MANS = $(MANUAL_PAGES)
+pkgconfigdir = $(libdir)/pkgconfig
+pkgconfig_DATA = connman.pc
+DISTCHECK_CONFIGURE_FLAGS = --disable-datafiles \
+				--enable-hh2serial-gps \
+				--enable-openconnect \
+				--enable-openvpn \
+				--enable-vpnc \
+				--enable-session-policy-local \
+				--enable-nmcompat \
+				--enable-polkit
+
+DISTCLEANFILES = $(pkgconfig_DATA)
+MAINTAINERCLEANFILES = Makefile.in \
+	aclocal.m4 configure config.h.in config.sub config.guess \
+	ltmain.sh depcomp compile missing install-sh mkinstalldirs test-driver
+
+do_subst = $(AM_V_GEN)$(SED) \
+		-e 's,[@]prefix[@],$(prefix),g' \
+		-e 's,[@]sbindir[@],$(sbindir),g' \
+		-e 's,[@]sysconfdir[@],$(sysconfdir),g'
+
+all: $(BUILT_SOURCES) config.h
+	$(MAKE) $(AM_MAKEFLAGS) all-am
+
+.SUFFIXES:
+.SUFFIXES: .c .lo .log .o .obj .test .test$(EXEEXT) .trs
+am--refresh: Makefile
+	@:
+$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(srcdir)/Makefile.plugins $(am__configure_deps)
+	@for dep in $?; do \
+	  case '$(am__configure_deps)' in \
+	    *$$dep*) \
+	      echo ' cd $(srcdir) && $(AUTOMAKE) --foreign'; \
+	      $(am__cd) $(srcdir) && $(AUTOMAKE) --foreign \
+		&& exit 0; \
+	      exit 1;; \
+	  esac; \
+	done; \
+	echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign Makefile'; \
+	$(am__cd) $(top_srcdir) && \
+	  $(AUTOMAKE) --foreign Makefile
+.PRECIOUS: Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+	@case '$?' in \
+	  *config.status*) \
+	    echo ' $(SHELL) ./config.status'; \
+	    $(SHELL) ./config.status;; \
+	  *) \
+	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $@ $(am__depfiles_maybe)'; \
+	    cd $(top_builddir) && $(SHELL) ./config.status $@ $(am__depfiles_maybe);; \
+	esac;
+$(srcdir)/Makefile.plugins:
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+	$(SHELL) ./config.status --recheck
+
+$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps)
+	$(am__cd) $(srcdir) && $(AUTOCONF)
+$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
+	$(am__cd) $(srcdir) && $(ACLOCAL) $(ACLOCAL_AMFLAGS)
+$(am__aclocal_m4_deps):
+
+config.h: stamp-h1
+	@test -f $@ || rm -f stamp-h1
+	@test -f $@ || $(MAKE) $(AM_MAKEFLAGS) stamp-h1
+
+stamp-h1: $(srcdir)/config.h.in $(top_builddir)/config.status
+	@rm -f stamp-h1
+	cd $(top_builddir) && $(SHELL) ./config.status config.h
+$(srcdir)/config.h.in: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) 
+	($(am__cd) $(top_srcdir) && $(AUTOHEADER))
+	rm -f stamp-h1
+	touch $@
+
+distclean-hdr:
+	-rm -f config.h stamp-h1
+include/version.h: $(top_builddir)/config.status $(top_srcdir)/include/version.h.in
+	cd $(top_builddir) && $(SHELL) ./config.status $@
+connman.pc: $(top_builddir)/config.status $(srcdir)/connman.pc.in
+	cd $(top_builddir) && $(SHELL) ./config.status $@
+
+clean-noinstLTLIBRARIES:
+	-test -z "$(noinst_LTLIBRARIES)" || rm -f $(noinst_LTLIBRARIES)
+	@list='$(noinst_LTLIBRARIES)'; \
+	locs=`for p in $$list; do echo $$p; done | \
+	      sed 's|^[^/]*$$|.|; s|/[^/]*$$||; s|$$|/so_locations|' | \
+	      sort -u`; \
+	test -z "$$locs" || { \
+	  echo rm -f $${locs}; \
+	  rm -f $${locs}; \
+	}
+
+install-pluginLTLIBRARIES: $(plugin_LTLIBRARIES)
+	@$(NORMAL_INSTALL)
+	@list='$(plugin_LTLIBRARIES)'; test -n "$(plugindir)" || list=; \
+	list2=; for p in $$list; do \
+	  if test -f $$p; then \
+	    list2="$$list2 $$p"; \
+	  else :; fi; \
+	done; \
+	test -z "$$list2" || { \
+	  echo " $(MKDIR_P) '$(DESTDIR)$(plugindir)'"; \
+	  $(MKDIR_P) "$(DESTDIR)$(plugindir)" || exit 1; \
+	  echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(plugindir)'"; \
+	  $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(plugindir)"; \
+	}
+
+uninstall-pluginLTLIBRARIES:
+	@$(NORMAL_UNINSTALL)
+	@list='$(plugin_LTLIBRARIES)'; test -n "$(plugindir)" || list=; \
+	for p in $$list; do \
+	  $(am__strip_dir) \
+	  echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(plugindir)/$$f'"; \
+	  $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(plugindir)/$$f"; \
+	done
+
+clean-pluginLTLIBRARIES:
+	-test -z "$(plugin_LTLIBRARIES)" || rm -f $(plugin_LTLIBRARIES)
+	@list='$(plugin_LTLIBRARIES)'; \
+	locs=`for p in $$list; do echo $$p; done | \
+	      sed 's|^[^/]*$$|.|; s|/[^/]*$$||; s|$$|/so_locations|' | \
+	      sort -u`; \
+	test -z "$$locs" || { \
+	  echo rm -f $${locs}; \
+	  rm -f $${locs}; \
+	}
+
+install-scriptLTLIBRARIES: $(script_LTLIBRARIES)
+	@$(NORMAL_INSTALL)
+	@list='$(script_LTLIBRARIES)'; test -n "$(scriptdir)" || list=; \
+	list2=; for p in $$list; do \
+	  if test -f $$p; then \
+	    list2="$$list2 $$p"; \
+	  else :; fi; \
+	done; \
+	test -z "$$list2" || { \
+	  echo " $(MKDIR_P) '$(DESTDIR)$(scriptdir)'"; \
+	  $(MKDIR_P) "$(DESTDIR)$(scriptdir)" || exit 1; \
+	  echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(scriptdir)'"; \
+	  $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(scriptdir)"; \
+	}
+
+uninstall-scriptLTLIBRARIES:
+	@$(NORMAL_UNINSTALL)
+	@list='$(script_LTLIBRARIES)'; test -n "$(scriptdir)" || list=; \
+	for p in $$list; do \
+	  $(am__strip_dir) \
+	  echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(scriptdir)/$$f'"; \
+	  $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(scriptdir)/$$f"; \
+	done
+
+clean-scriptLTLIBRARIES:
+	-test -z "$(script_LTLIBRARIES)" || rm -f $(script_LTLIBRARIES)
+	@list='$(script_LTLIBRARIES)'; \
+	locs=`for p in $$list; do echo $$p; done | \
+	      sed 's|^[^/]*$$|.|; s|/[^/]*$$||; s|$$|/so_locations|' | \
+	      sort -u`; \
+	test -z "$$locs" || { \
+	  echo rm -f $${locs}; \
+	  rm -f $${locs}; \
+	}
+
+install-vpn_pluginLTLIBRARIES: $(vpn_plugin_LTLIBRARIES)
+	@$(NORMAL_INSTALL)
+	@list='$(vpn_plugin_LTLIBRARIES)'; test -n "$(vpn_plugindir)" || list=; \
+	list2=; for p in $$list; do \
+	  if test -f $$p; then \
+	    list2="$$list2 $$p"; \
+	  else :; fi; \
+	done; \
+	test -z "$$list2" || { \
+	  echo " $(MKDIR_P) '$(DESTDIR)$(vpn_plugindir)'"; \
+	  $(MKDIR_P) "$(DESTDIR)$(vpn_plugindir)" || exit 1; \
+	  echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(vpn_plugindir)'"; \
+	  $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(vpn_plugindir)"; \
+	}
+
+uninstall-vpn_pluginLTLIBRARIES:
+	@$(NORMAL_UNINSTALL)
+	@list='$(vpn_plugin_LTLIBRARIES)'; test -n "$(vpn_plugindir)" || list=; \
+	for p in $$list; do \
+	  $(am__strip_dir) \
+	  echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(vpn_plugindir)/$$f'"; \
+	  $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(vpn_plugindir)/$$f"; \
+	done
+
+clean-vpn_pluginLTLIBRARIES:
+	-test -z "$(vpn_plugin_LTLIBRARIES)" || rm -f $(vpn_plugin_LTLIBRARIES)
+	@list='$(vpn_plugin_LTLIBRARIES)'; \
+	locs=`for p in $$list; do echo $$p; done | \
+	      sed 's|^[^/]*$$|.|; s|/[^/]*$$||; s|$$|/so_locations|' | \
+	      sort -u`; \
+	test -z "$$locs" || { \
+	  echo rm -f $${locs}; \
+	  rm -f $${locs}; \
+	}
+gdbus/$(am__dirstamp):
+	@$(MKDIR_P) gdbus
+	@: > gdbus/$(am__dirstamp)
+gdbus/$(DEPDIR)/$(am__dirstamp):
+	@$(MKDIR_P) gdbus/$(DEPDIR)
+	@: > gdbus/$(DEPDIR)/$(am__dirstamp)
+gdbus/mainloop.lo: gdbus/$(am__dirstamp) \
+	gdbus/$(DEPDIR)/$(am__dirstamp)
+gdbus/watch.lo: gdbus/$(am__dirstamp) gdbus/$(DEPDIR)/$(am__dirstamp)
+gdbus/object.lo: gdbus/$(am__dirstamp) gdbus/$(DEPDIR)/$(am__dirstamp)
+gdbus/client.lo: gdbus/$(am__dirstamp) gdbus/$(DEPDIR)/$(am__dirstamp)
+gdbus/polkit.lo: gdbus/$(am__dirstamp) gdbus/$(DEPDIR)/$(am__dirstamp)
+
+gdbus/libgdbus-internal.la: $(gdbus_libgdbus_internal_la_OBJECTS) $(gdbus_libgdbus_internal_la_DEPENDENCIES) $(EXTRA_gdbus_libgdbus_internal_la_DEPENDENCIES) gdbus/$(am__dirstamp)
+	$(AM_V_CCLD)$(LINK)  $(gdbus_libgdbus_internal_la_OBJECTS) $(gdbus_libgdbus_internal_la_LIBADD) $(LIBS)
+plugins/$(am__dirstamp):
+	@$(MKDIR_P) plugins
+	@: > plugins/$(am__dirstamp)
+plugins/$(DEPDIR)/$(am__dirstamp):
+	@$(MKDIR_P) plugins/$(DEPDIR)
+	@: > plugins/$(DEPDIR)/$(am__dirstamp)
+plugins/plugins_hh2serial_gps_la-hh2serial-gps.lo:  \
+	plugins/$(am__dirstamp) plugins/$(DEPDIR)/$(am__dirstamp)
+
+plugins/hh2serial-gps.la: $(plugins_hh2serial_gps_la_OBJECTS) $(plugins_hh2serial_gps_la_DEPENDENCIES) $(EXTRA_plugins_hh2serial_gps_la_DEPENDENCIES) plugins/$(am__dirstamp)
+	$(AM_V_CCLD)$(plugins_hh2serial_gps_la_LINK) $(am_plugins_hh2serial_gps_la_rpath) $(plugins_hh2serial_gps_la_OBJECTS) $(plugins_hh2serial_gps_la_LIBADD) $(LIBS)
+plugins/plugins_iospm_la-iospm.lo: plugins/$(am__dirstamp) \
+	plugins/$(DEPDIR)/$(am__dirstamp)
+
+plugins/iospm.la: $(plugins_iospm_la_OBJECTS) $(plugins_iospm_la_DEPENDENCIES) $(EXTRA_plugins_iospm_la_DEPENDENCIES) plugins/$(am__dirstamp)
+	$(AM_V_CCLD)$(plugins_iospm_la_LINK) $(am_plugins_iospm_la_rpath) $(plugins_iospm_la_OBJECTS) $(plugins_iospm_la_LIBADD) $(LIBS)
+plugins/plugins_session_policy_local_la-session_policy_local.lo:  \
+	plugins/$(am__dirstamp) plugins/$(DEPDIR)/$(am__dirstamp)
+
+plugins/session_policy_local.la: $(plugins_session_policy_local_la_OBJECTS) $(plugins_session_policy_local_la_DEPENDENCIES) $(EXTRA_plugins_session_policy_local_la_DEPENDENCIES) plugins/$(am__dirstamp)
+	$(AM_V_CCLD)$(plugins_session_policy_local_la_LINK) $(am_plugins_session_policy_local_la_rpath) $(plugins_session_policy_local_la_OBJECTS) $(plugins_session_policy_local_la_LIBADD) $(LIBS)
+plugins/plugins_tist_la-tist.lo: plugins/$(am__dirstamp) \
+	plugins/$(DEPDIR)/$(am__dirstamp)
+
+plugins/tist.la: $(plugins_tist_la_OBJECTS) $(plugins_tist_la_DEPENDENCIES) $(EXTRA_plugins_tist_la_DEPENDENCIES) plugins/$(am__dirstamp)
+	$(AM_V_CCLD)$(plugins_tist_la_LINK) $(am_plugins_tist_la_rpath) $(plugins_tist_la_OBJECTS) $(plugins_tist_la_LIBADD) $(LIBS)
+scripts/$(am__dirstamp):
+	@$(MKDIR_P) scripts
+	@: > scripts/$(am__dirstamp)
+scripts/$(DEPDIR)/$(am__dirstamp):
+	@$(MKDIR_P) scripts/$(DEPDIR)
+	@: > scripts/$(DEPDIR)/$(am__dirstamp)
+scripts/libppp-plugin.lo: scripts/$(am__dirstamp) \
+	scripts/$(DEPDIR)/$(am__dirstamp)
+
+scripts/libppp-plugin.la: $(scripts_libppp_plugin_la_OBJECTS) $(scripts_libppp_plugin_la_DEPENDENCIES) $(EXTRA_scripts_libppp_plugin_la_DEPENDENCIES) scripts/$(am__dirstamp)
+	$(AM_V_CCLD)$(scripts_libppp_plugin_la_LINK) $(am_scripts_libppp_plugin_la_rpath) $(scripts_libppp_plugin_la_OBJECTS) $(scripts_libppp_plugin_la_LIBADD) $(LIBS)
+vpn/plugins/$(am__dirstamp):
+	@$(MKDIR_P) vpn/plugins
+	@: > vpn/plugins/$(am__dirstamp)
+vpn/plugins/$(DEPDIR)/$(am__dirstamp):
+	@$(MKDIR_P) vpn/plugins/$(DEPDIR)
+	@: > vpn/plugins/$(DEPDIR)/$(am__dirstamp)
+vpn/plugins/vpn_plugins_l2tp_la-vpn.lo: vpn/plugins/$(am__dirstamp) \
+	vpn/plugins/$(DEPDIR)/$(am__dirstamp)
+vpn/plugins/vpn_plugins_l2tp_la-l2tp.lo: vpn/plugins/$(am__dirstamp) \
+	vpn/plugins/$(DEPDIR)/$(am__dirstamp)
+
+vpn/plugins/l2tp.la: $(vpn_plugins_l2tp_la_OBJECTS) $(vpn_plugins_l2tp_la_DEPENDENCIES) $(EXTRA_vpn_plugins_l2tp_la_DEPENDENCIES) vpn/plugins/$(am__dirstamp)
+	$(AM_V_CCLD)$(vpn_plugins_l2tp_la_LINK) $(am_vpn_plugins_l2tp_la_rpath) $(vpn_plugins_l2tp_la_OBJECTS) $(vpn_plugins_l2tp_la_LIBADD) $(LIBS)
+vpn/plugins/vpn_plugins_openconnect_la-vpn.lo:  \
+	vpn/plugins/$(am__dirstamp) \
+	vpn/plugins/$(DEPDIR)/$(am__dirstamp)
+vpn/plugins/vpn_plugins_openconnect_la-openconnect.lo:  \
+	vpn/plugins/$(am__dirstamp) \
+	vpn/plugins/$(DEPDIR)/$(am__dirstamp)
+
+vpn/plugins/openconnect.la: $(vpn_plugins_openconnect_la_OBJECTS) $(vpn_plugins_openconnect_la_DEPENDENCIES) $(EXTRA_vpn_plugins_openconnect_la_DEPENDENCIES) vpn/plugins/$(am__dirstamp)
+	$(AM_V_CCLD)$(vpn_plugins_openconnect_la_LINK) $(am_vpn_plugins_openconnect_la_rpath) $(vpn_plugins_openconnect_la_OBJECTS) $(vpn_plugins_openconnect_la_LIBADD) $(LIBS)
+vpn/plugins/vpn_plugins_openvpn_la-vpn.lo:  \
+	vpn/plugins/$(am__dirstamp) \
+	vpn/plugins/$(DEPDIR)/$(am__dirstamp)
+vpn/plugins/vpn_plugins_openvpn_la-openvpn.lo:  \
+	vpn/plugins/$(am__dirstamp) \
+	vpn/plugins/$(DEPDIR)/$(am__dirstamp)
+
+vpn/plugins/openvpn.la: $(vpn_plugins_openvpn_la_OBJECTS) $(vpn_plugins_openvpn_la_DEPENDENCIES) $(EXTRA_vpn_plugins_openvpn_la_DEPENDENCIES) vpn/plugins/$(am__dirstamp)
+	$(AM_V_CCLD)$(vpn_plugins_openvpn_la_LINK) $(am_vpn_plugins_openvpn_la_rpath) $(vpn_plugins_openvpn_la_OBJECTS) $(vpn_plugins_openvpn_la_LIBADD) $(LIBS)
+vpn/plugins/vpn_plugins_pptp_la-vpn.lo: vpn/plugins/$(am__dirstamp) \
+	vpn/plugins/$(DEPDIR)/$(am__dirstamp)
+vpn/plugins/vpn_plugins_pptp_la-pptp.lo: vpn/plugins/$(am__dirstamp) \
+	vpn/plugins/$(DEPDIR)/$(am__dirstamp)
+
+vpn/plugins/pptp.la: $(vpn_plugins_pptp_la_OBJECTS) $(vpn_plugins_pptp_la_DEPENDENCIES) $(EXTRA_vpn_plugins_pptp_la_DEPENDENCIES) vpn/plugins/$(am__dirstamp)
+	$(AM_V_CCLD)$(vpn_plugins_pptp_la_LINK) $(am_vpn_plugins_pptp_la_rpath) $(vpn_plugins_pptp_la_OBJECTS) $(vpn_plugins_pptp_la_LIBADD) $(LIBS)
+vpn/plugins/vpn_plugins_vpnc_la-vpn.lo: vpn/plugins/$(am__dirstamp) \
+	vpn/plugins/$(DEPDIR)/$(am__dirstamp)
+vpn/plugins/vpn_plugins_vpnc_la-vpnc.lo: vpn/plugins/$(am__dirstamp) \
+	vpn/plugins/$(DEPDIR)/$(am__dirstamp)
+
+vpn/plugins/vpnc.la: $(vpn_plugins_vpnc_la_OBJECTS) $(vpn_plugins_vpnc_la_DEPENDENCIES) $(EXTRA_vpn_plugins_vpnc_la_DEPENDENCIES) vpn/plugins/$(am__dirstamp)
+	$(AM_V_CCLD)$(vpn_plugins_vpnc_la_LINK) $(am_vpn_plugins_vpnc_la_rpath) $(vpn_plugins_vpnc_la_OBJECTS) $(vpn_plugins_vpnc_la_LIBADD) $(LIBS)
+install-binPROGRAMS: $(bin_PROGRAMS)
+	@$(NORMAL_INSTALL)
+	@list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \
+	if test -n "$$list"; then \
+	  echo " $(MKDIR_P) '$(DESTDIR)$(bindir)'"; \
+	  $(MKDIR_P) "$(DESTDIR)$(bindir)" || exit 1; \
+	fi; \
+	for p in $$list; do echo "$$p $$p"; done | \
+	sed 's/$(EXEEXT)$$//' | \
+	while read p p1; do if test -f $$p \
+	 || test -f $$p1 \
+	  ; then echo "$$p"; echo "$$p"; else :; fi; \
+	done | \
+	sed -e 'p;s,.*/,,;n;h' \
+	    -e 's|.*|.|' \
+	    -e 'p;x;s,.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/' | \
+	sed 'N;N;N;s,\n, ,g' | \
+	$(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1 } \
+	  { d=$$3; if (dirs[d] != 1) { print "d", d; dirs[d] = 1 } \
+	    if ($$2 == $$4) files[d] = files[d] " " $$1; \
+	    else { print "f", $$3 "/" $$4, $$1; } } \
+	  END { for (d in files) print "f", d, files[d] }' | \
+	while read type dir files; do \
+	    if test "$$dir" = .; then dir=; else dir=/$$dir; fi; \
+	    test -z "$$files" || { \
+	    echo " $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files '$(DESTDIR)$(bindir)$$dir'"; \
+	    $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files "$(DESTDIR)$(bindir)$$dir" || exit $$?; \
+	    } \
+	; done
+
+uninstall-binPROGRAMS:
+	@$(NORMAL_UNINSTALL)
+	@list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \
+	files=`for p in $$list; do echo "$$p"; done | \
+	  sed -e 'h;s,^.*/,,;s/$(EXEEXT)$$//;$(transform)' \
+	      -e 's/$$/$(EXEEXT)/' \
+	`; \
+	test -n "$$list" || exit 0; \
+	echo " ( cd '$(DESTDIR)$(bindir)' && rm -f" $$files ")"; \
+	cd "$(DESTDIR)$(bindir)" && rm -f $$files
+
+clean-binPROGRAMS:
+	@list='$(bin_PROGRAMS)'; test -n "$$list" || exit 0; \
+	echo " rm -f" $$list; \
+	rm -f $$list || exit $$?; \
+	test -n "$(EXEEXT)" || exit 0; \
+	list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \
+	echo " rm -f" $$list; \
+	rm -f $$list
+
+clean-noinstPROGRAMS:
+	@list='$(noinst_PROGRAMS)'; test -n "$$list" || exit 0; \
+	echo " rm -f" $$list; \
+	rm -f $$list || exit $$?; \
+	test -n "$(EXEEXT)" || exit 0; \
+	list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \
+	echo " rm -f" $$list; \
+	rm -f $$list
+install-sbinPROGRAMS: $(sbin_PROGRAMS)
+	@$(NORMAL_INSTALL)
+	@list='$(sbin_PROGRAMS)'; test -n "$(sbindir)" || list=; \
+	if test -n "$$list"; then \
+	  echo " $(MKDIR_P) '$(DESTDIR)$(sbindir)'"; \
+	  $(MKDIR_P) "$(DESTDIR)$(sbindir)" || exit 1; \
+	fi; \
+	for p in $$list; do echo "$$p $$p"; done | \
+	sed 's/$(EXEEXT)$$//' | \
+	while read p p1; do if test -f $$p \
+	 || test -f $$p1 \
+	  ; then echo "$$p"; echo "$$p"; else :; fi; \
+	done | \
+	sed -e 'p;s,.*/,,;n;h' \
+	    -e 's|.*|.|' \
+	    -e 'p;x;s,.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/' | \
+	sed 'N;N;N;s,\n, ,g' | \
+	$(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1 } \
+	  { d=$$3; if (dirs[d] != 1) { print "d", d; dirs[d] = 1 } \
+	    if ($$2 == $$4) files[d] = files[d] " " $$1; \
+	    else { print "f", $$3 "/" $$4, $$1; } } \
+	  END { for (d in files) print "f", d, files[d] }' | \
+	while read type dir files; do \
+	    if test "$$dir" = .; then dir=; else dir=/$$dir; fi; \
+	    test -z "$$files" || { \
+	    echo " $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files '$(DESTDIR)$(sbindir)$$dir'"; \
+	    $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files "$(DESTDIR)$(sbindir)$$dir" || exit $$?; \
+	    } \
+	; done
+
+uninstall-sbinPROGRAMS:
+	@$(NORMAL_UNINSTALL)
+	@list='$(sbin_PROGRAMS)'; test -n "$(sbindir)" || list=; \
+	files=`for p in $$list; do echo "$$p"; done | \
+	  sed -e 'h;s,^.*/,,;s/$(EXEEXT)$$//;$(transform)' \
+	      -e 's/$$/$(EXEEXT)/' \
+	`; \
+	test -n "$$list" || exit 0; \
+	echo " ( cd '$(DESTDIR)$(sbindir)' && rm -f" $$files ")"; \
+	cd "$(DESTDIR)$(sbindir)" && rm -f $$files
+
+clean-sbinPROGRAMS:
+	@list='$(sbin_PROGRAMS)'; test -n "$$list" || exit 0; \
+	echo " rm -f" $$list; \
+	rm -f $$list || exit $$?; \
+	test -n "$(EXEEXT)" || exit 0; \
+	list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \
+	echo " rm -f" $$list; \
+	rm -f $$list
+install-scriptPROGRAMS: $(script_PROGRAMS)
+	@$(NORMAL_INSTALL)
+	@list='$(script_PROGRAMS)'; test -n "$(scriptdir)" || list=; \
+	if test -n "$$list"; then \
+	  echo " $(MKDIR_P) '$(DESTDIR)$(scriptdir)'"; \
+	  $(MKDIR_P) "$(DESTDIR)$(scriptdir)" || exit 1; \
+	fi; \
+	for p in $$list; do echo "$$p $$p"; done | \
+	sed 's/$(EXEEXT)$$//' | \
+	while read p p1; do if test -f $$p \
+	 || test -f $$p1 \
+	  ; then echo "$$p"; echo "$$p"; else :; fi; \
+	done | \
+	sed -e 'p;s,.*/,,;n;h' \
+	    -e 's|.*|.|' \
+	    -e 'p;x;s,.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/' | \
+	sed 'N;N;N;s,\n, ,g' | \
+	$(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1 } \
+	  { d=$$3; if (dirs[d] != 1) { print "d", d; dirs[d] = 1 } \
+	    if ($$2 == $$4) files[d] = files[d] " " $$1; \
+	    else { print "f", $$3 "/" $$4, $$1; } } \
+	  END { for (d in files) print "f", d, files[d] }' | \
+	while read type dir files; do \
+	    if test "$$dir" = .; then dir=; else dir=/$$dir; fi; \
+	    test -z "$$files" || { \
+	    echo " $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files '$(DESTDIR)$(scriptdir)$$dir'"; \
+	    $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files "$(DESTDIR)$(scriptdir)$$dir" || exit $$?; \
+	    } \
+	; done
+
+uninstall-scriptPROGRAMS:
+	@$(NORMAL_UNINSTALL)
+	@list='$(script_PROGRAMS)'; test -n "$(scriptdir)" || list=; \
+	files=`for p in $$list; do echo "$$p"; done | \
+	  sed -e 'h;s,^.*/,,;s/$(EXEEXT)$$//;$(transform)' \
+	      -e 's/$$/$(EXEEXT)/' \
+	`; \
+	test -n "$$list" || exit 0; \
+	echo " ( cd '$(DESTDIR)$(scriptdir)' && rm -f" $$files ")"; \
+	cd "$(DESTDIR)$(scriptdir)" && rm -f $$files
+
+clean-scriptPROGRAMS:
+	@list='$(script_PROGRAMS)'; test -n "$$list" || exit 0; \
+	echo " rm -f" $$list; \
+	rm -f $$list || exit $$?; \
+	test -n "$(EXEEXT)" || exit 0; \
+	list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \
+	echo " rm -f" $$list; \
+	rm -f $$list
+client/$(am__dirstamp):
+	@$(MKDIR_P) client
+	@: > client/$(am__dirstamp)
+client/$(DEPDIR)/$(am__dirstamp):
+	@$(MKDIR_P) client/$(DEPDIR)
+	@: > client/$(DEPDIR)/$(am__dirstamp)
+client/dbus_helpers.$(OBJEXT): client/$(am__dirstamp) \
+	client/$(DEPDIR)/$(am__dirstamp)
+client/services.$(OBJEXT): client/$(am__dirstamp) \
+	client/$(DEPDIR)/$(am__dirstamp)
+client/commands.$(OBJEXT): client/$(am__dirstamp) \
+	client/$(DEPDIR)/$(am__dirstamp)
+client/input.$(OBJEXT): client/$(am__dirstamp) \
+	client/$(DEPDIR)/$(am__dirstamp)
+client/agent.$(OBJEXT): client/$(am__dirstamp) \
+	client/$(DEPDIR)/$(am__dirstamp)
+client/peers.$(OBJEXT): client/$(am__dirstamp) \
+	client/$(DEPDIR)/$(am__dirstamp)
+client/vpnconnections.$(OBJEXT): client/$(am__dirstamp) \
+	client/$(DEPDIR)/$(am__dirstamp)
+client/main.$(OBJEXT): client/$(am__dirstamp) \
+	client/$(DEPDIR)/$(am__dirstamp)
+
+client/connmanctl$(EXEEXT): $(client_connmanctl_OBJECTS) $(client_connmanctl_DEPENDENCIES) $(EXTRA_client_connmanctl_DEPENDENCIES) client/$(am__dirstamp)
+	@rm -f client/connmanctl$(EXEEXT)
+	$(AM_V_CCLD)$(LINK) $(client_connmanctl_OBJECTS) $(client_connmanctl_LDADD) $(LIBS)
+scripts/openconnect-script.$(OBJEXT): scripts/$(am__dirstamp) \
+	scripts/$(DEPDIR)/$(am__dirstamp)
+
+scripts/openconnect-script$(EXEEXT): $(scripts_openconnect_script_OBJECTS) $(scripts_openconnect_script_DEPENDENCIES) $(EXTRA_scripts_openconnect_script_DEPENDENCIES) scripts/$(am__dirstamp)
+	@rm -f scripts/openconnect-script$(EXEEXT)
+	$(AM_V_CCLD)$(LINK) $(scripts_openconnect_script_OBJECTS) $(scripts_openconnect_script_LDADD) $(LIBS)
+scripts/openvpn-script.$(OBJEXT): scripts/$(am__dirstamp) \
+	scripts/$(DEPDIR)/$(am__dirstamp)
+
+scripts/openvpn-script$(EXEEXT): $(scripts_openvpn_script_OBJECTS) $(scripts_openvpn_script_DEPENDENCIES) $(EXTRA_scripts_openvpn_script_DEPENDENCIES) scripts/$(am__dirstamp)
+	@rm -f scripts/openvpn-script$(EXEEXT)
+	$(AM_V_CCLD)$(LINK) $(scripts_openvpn_script_OBJECTS) $(scripts_openvpn_script_LDADD) $(LIBS)
+gdhcp/$(am__dirstamp):
+	@$(MKDIR_P) gdhcp
+	@: > gdhcp/$(am__dirstamp)
+gdhcp/$(DEPDIR)/$(am__dirstamp):
+	@$(MKDIR_P) gdhcp/$(DEPDIR)
+	@: > gdhcp/$(DEPDIR)/$(am__dirstamp)
+gdhcp/src_connmand-common.$(OBJEXT): gdhcp/$(am__dirstamp) \
+	gdhcp/$(DEPDIR)/$(am__dirstamp)
+gdhcp/src_connmand-client.$(OBJEXT): gdhcp/$(am__dirstamp) \
+	gdhcp/$(DEPDIR)/$(am__dirstamp)
+gdhcp/src_connmand-server.$(OBJEXT): gdhcp/$(am__dirstamp) \
+	gdhcp/$(DEPDIR)/$(am__dirstamp)
+gdhcp/src_connmand-ipv4ll.$(OBJEXT): gdhcp/$(am__dirstamp) \
+	gdhcp/$(DEPDIR)/$(am__dirstamp)
+gdhcp/src_connmand-timer.$(OBJEXT): gdhcp/$(am__dirstamp) \
+	gdhcp/$(DEPDIR)/$(am__dirstamp)
+gweb/$(am__dirstamp):
+	@$(MKDIR_P) gweb
+	@: > gweb/$(am__dirstamp)
+gweb/$(DEPDIR)/$(am__dirstamp):
+	@$(MKDIR_P) gweb/$(DEPDIR)
+	@: > gweb/$(DEPDIR)/$(am__dirstamp)
+gweb/src_connmand-gweb.$(OBJEXT): gweb/$(am__dirstamp) \
+	gweb/$(DEPDIR)/$(am__dirstamp)
+gweb/src_connmand-gresolv.$(OBJEXT): gweb/$(am__dirstamp) \
+	gweb/$(DEPDIR)/$(am__dirstamp)
+gweb/src_connmand-giognutls.$(OBJEXT): gweb/$(am__dirstamp) \
+	gweb/$(DEPDIR)/$(am__dirstamp)
+gweb/src_connmand-gionotls.$(OBJEXT): gweb/$(am__dirstamp) \
+	gweb/$(DEPDIR)/$(am__dirstamp)
+plugins/src_connmand-loopback.$(OBJEXT): plugins/$(am__dirstamp) \
+	plugins/$(DEPDIR)/$(am__dirstamp)
+plugins/src_connmand-ethernet.$(OBJEXT): plugins/$(am__dirstamp) \
+	plugins/$(DEPDIR)/$(am__dirstamp)
+plugins/src_connmand-gadget.$(OBJEXT): plugins/$(am__dirstamp) \
+	plugins/$(DEPDIR)/$(am__dirstamp)
+plugins/src_connmand-wifi.$(OBJEXT): plugins/$(am__dirstamp) \
+	plugins/$(DEPDIR)/$(am__dirstamp)
+gsupplicant/$(am__dirstamp):
+	@$(MKDIR_P) gsupplicant
+	@: > gsupplicant/$(am__dirstamp)
+gsupplicant/$(DEPDIR)/$(am__dirstamp):
+	@$(MKDIR_P) gsupplicant/$(DEPDIR)
+	@: > gsupplicant/$(DEPDIR)/$(am__dirstamp)
+gsupplicant/src_connmand-supplicant.$(OBJEXT):  \
+	gsupplicant/$(am__dirstamp) \
+	gsupplicant/$(DEPDIR)/$(am__dirstamp)
+gsupplicant/src_connmand-dbus.$(OBJEXT): gsupplicant/$(am__dirstamp) \
+	gsupplicant/$(DEPDIR)/$(am__dirstamp)
+plugins/src_connmand-bluetooth_legacy.$(OBJEXT):  \
+	plugins/$(am__dirstamp) plugins/$(DEPDIR)/$(am__dirstamp)
+plugins/src_connmand-bluetooth.$(OBJEXT): plugins/$(am__dirstamp) \
+	plugins/$(DEPDIR)/$(am__dirstamp)
+plugins/src_connmand-hh2serial-gps.$(OBJEXT): plugins/$(am__dirstamp) \
+	plugins/$(DEPDIR)/$(am__dirstamp)
+plugins/src_connmand-ofono.$(OBJEXT): plugins/$(am__dirstamp) \
+	plugins/$(DEPDIR)/$(am__dirstamp)
+plugins/src_connmand-dundee.$(OBJEXT): plugins/$(am__dirstamp) \
+	plugins/$(DEPDIR)/$(am__dirstamp)
+plugins/src_connmand-vpn.$(OBJEXT): plugins/$(am__dirstamp) \
+	plugins/$(DEPDIR)/$(am__dirstamp)
+plugins/src_connmand-pacrunner.$(OBJEXT): plugins/$(am__dirstamp) \
+	plugins/$(DEPDIR)/$(am__dirstamp)
+plugins/src_connmand-polkit.$(OBJEXT): plugins/$(am__dirstamp) \
+	plugins/$(DEPDIR)/$(am__dirstamp)
+plugins/src_connmand-nmcompat.$(OBJEXT): plugins/$(am__dirstamp) \
+	plugins/$(DEPDIR)/$(am__dirstamp)
+plugins/src_connmand-tist.$(OBJEXT): plugins/$(am__dirstamp) \
+	plugins/$(DEPDIR)/$(am__dirstamp)
+plugins/src_connmand-session_policy_local.$(OBJEXT):  \
+	plugins/$(am__dirstamp) plugins/$(DEPDIR)/$(am__dirstamp)
+plugins/src_connmand-neard.$(OBJEXT): plugins/$(am__dirstamp) \
+	plugins/$(DEPDIR)/$(am__dirstamp)
+src/shared/$(am__dirstamp):
+	@$(MKDIR_P) src/shared
+	@: > src/shared/$(am__dirstamp)
+src/shared/$(DEPDIR)/$(am__dirstamp):
+	@$(MKDIR_P) src/shared/$(DEPDIR)
+	@: > src/shared/$(DEPDIR)/$(am__dirstamp)
+src/shared/src_connmand-util.$(OBJEXT): src/shared/$(am__dirstamp) \
+	src/shared/$(DEPDIR)/$(am__dirstamp)
+src/shared/src_connmand-netlink.$(OBJEXT): src/shared/$(am__dirstamp) \
+	src/shared/$(DEPDIR)/$(am__dirstamp)
+src/$(am__dirstamp):
+	@$(MKDIR_P) src
+	@: > src/$(am__dirstamp)
+src/$(DEPDIR)/$(am__dirstamp):
+	@$(MKDIR_P) src/$(DEPDIR)
+	@: > src/$(DEPDIR)/$(am__dirstamp)
+src/src_connmand-main.$(OBJEXT): src/$(am__dirstamp) \
+	src/$(DEPDIR)/$(am__dirstamp)
+src/src_connmand-log.$(OBJEXT): src/$(am__dirstamp) \
+	src/$(DEPDIR)/$(am__dirstamp)
+src/src_connmand-error.$(OBJEXT): src/$(am__dirstamp) \
+	src/$(DEPDIR)/$(am__dirstamp)
+src/src_connmand-plugin.$(OBJEXT): src/$(am__dirstamp) \
+	src/$(DEPDIR)/$(am__dirstamp)
+src/src_connmand-task.$(OBJEXT): src/$(am__dirstamp) \
+	src/$(DEPDIR)/$(am__dirstamp)
+src/src_connmand-device.$(OBJEXT): src/$(am__dirstamp) \
+	src/$(DEPDIR)/$(am__dirstamp)
+src/src_connmand-network.$(OBJEXT): src/$(am__dirstamp) \
+	src/$(DEPDIR)/$(am__dirstamp)
+src/src_connmand-connection.$(OBJEXT): src/$(am__dirstamp) \
+	src/$(DEPDIR)/$(am__dirstamp)
+src/src_connmand-manager.$(OBJEXT): src/$(am__dirstamp) \
+	src/$(DEPDIR)/$(am__dirstamp)
+src/src_connmand-service.$(OBJEXT): src/$(am__dirstamp) \
+	src/$(DEPDIR)/$(am__dirstamp)
+src/src_connmand-clock.$(OBJEXT): src/$(am__dirstamp) \
+	src/$(DEPDIR)/$(am__dirstamp)
+src/src_connmand-timezone.$(OBJEXT): src/$(am__dirstamp) \
+	src/$(DEPDIR)/$(am__dirstamp)
+src/src_connmand-agent-connman.$(OBJEXT): src/$(am__dirstamp) \
+	src/$(DEPDIR)/$(am__dirstamp)
+src/src_connmand-agent.$(OBJEXT): src/$(am__dirstamp) \
+	src/$(DEPDIR)/$(am__dirstamp)
+src/src_connmand-notifier.$(OBJEXT): src/$(am__dirstamp) \
+	src/$(DEPDIR)/$(am__dirstamp)
+src/src_connmand-provider.$(OBJEXT): src/$(am__dirstamp) \
+	src/$(DEPDIR)/$(am__dirstamp)
+src/src_connmand-resolver.$(OBJEXT): src/$(am__dirstamp) \
+	src/$(DEPDIR)/$(am__dirstamp)
+src/src_connmand-ipconfig.$(OBJEXT): src/$(am__dirstamp) \
+	src/$(DEPDIR)/$(am__dirstamp)
+src/src_connmand-detect.$(OBJEXT): src/$(am__dirstamp) \
+	src/$(DEPDIR)/$(am__dirstamp)
+src/src_connmand-inet.$(OBJEXT): src/$(am__dirstamp) \
+	src/$(DEPDIR)/$(am__dirstamp)
+src/src_connmand-dhcp.$(OBJEXT): src/$(am__dirstamp) \
+	src/$(DEPDIR)/$(am__dirstamp)
+src/src_connmand-dhcpv6.$(OBJEXT): src/$(am__dirstamp) \
+	src/$(DEPDIR)/$(am__dirstamp)
+src/src_connmand-rtnl.$(OBJEXT): src/$(am__dirstamp) \
+	src/$(DEPDIR)/$(am__dirstamp)
+src/src_connmand-proxy.$(OBJEXT): src/$(am__dirstamp) \
+	src/$(DEPDIR)/$(am__dirstamp)
+src/src_connmand-utsname.$(OBJEXT): src/$(am__dirstamp) \
+	src/$(DEPDIR)/$(am__dirstamp)
+src/src_connmand-timeserver.$(OBJEXT): src/$(am__dirstamp) \
+	src/$(DEPDIR)/$(am__dirstamp)
+src/src_connmand-rfkill.$(OBJEXT): src/$(am__dirstamp) \
+	src/$(DEPDIR)/$(am__dirstamp)
+src/src_connmand-storage.$(OBJEXT): src/$(am__dirstamp) \
+	src/$(DEPDIR)/$(am__dirstamp)
+src/src_connmand-dbus.$(OBJEXT): src/$(am__dirstamp) \
+	src/$(DEPDIR)/$(am__dirstamp)
+src/src_connmand-config.$(OBJEXT): src/$(am__dirstamp) \
+	src/$(DEPDIR)/$(am__dirstamp)
+src/src_connmand-technology.$(OBJEXT): src/$(am__dirstamp) \
+	src/$(DEPDIR)/$(am__dirstamp)
+src/src_connmand-counter.$(OBJEXT): src/$(am__dirstamp) \
+	src/$(DEPDIR)/$(am__dirstamp)
+src/src_connmand-ntp.$(OBJEXT): src/$(am__dirstamp) \
+	src/$(DEPDIR)/$(am__dirstamp)
+src/src_connmand-session.$(OBJEXT): src/$(am__dirstamp) \
+	src/$(DEPDIR)/$(am__dirstamp)
+src/src_connmand-tethering.$(OBJEXT): src/$(am__dirstamp) \
+	src/$(DEPDIR)/$(am__dirstamp)
+src/src_connmand-wpad.$(OBJEXT): src/$(am__dirstamp) \
+	src/$(DEPDIR)/$(am__dirstamp)
+src/src_connmand-wispr.$(OBJEXT): src/$(am__dirstamp) \
+	src/$(DEPDIR)/$(am__dirstamp)
+src/src_connmand-stats.$(OBJEXT): src/$(am__dirstamp) \
+	src/$(DEPDIR)/$(am__dirstamp)
+src/src_connmand-iptables.$(OBJEXT): src/$(am__dirstamp) \
+	src/$(DEPDIR)/$(am__dirstamp)
+src/src_connmand-dnsproxy.$(OBJEXT): src/$(am__dirstamp) \
+	src/$(DEPDIR)/$(am__dirstamp)
+src/src_connmand-6to4.$(OBJEXT): src/$(am__dirstamp) \
+	src/$(DEPDIR)/$(am__dirstamp)
+src/src_connmand-ippool.$(OBJEXT): src/$(am__dirstamp) \
+	src/$(DEPDIR)/$(am__dirstamp)
+src/src_connmand-bridge.$(OBJEXT): src/$(am__dirstamp) \
+	src/$(DEPDIR)/$(am__dirstamp)
+src/src_connmand-nat.$(OBJEXT): src/$(am__dirstamp) \
+	src/$(DEPDIR)/$(am__dirstamp)
+src/src_connmand-ipaddress.$(OBJEXT): src/$(am__dirstamp) \
+	src/$(DEPDIR)/$(am__dirstamp)
+src/src_connmand-inotify.$(OBJEXT): src/$(am__dirstamp) \
+	src/$(DEPDIR)/$(am__dirstamp)
+src/src_connmand-firewall.$(OBJEXT): src/$(am__dirstamp) \
+	src/$(DEPDIR)/$(am__dirstamp)
+src/src_connmand-ipv6pd.$(OBJEXT): src/$(am__dirstamp) \
+	src/$(DEPDIR)/$(am__dirstamp)
+src/src_connmand-peer.$(OBJEXT): src/$(am__dirstamp) \
+	src/$(DEPDIR)/$(am__dirstamp)
+src/src_connmand-peer_service.$(OBJEXT): src/$(am__dirstamp) \
+	src/$(DEPDIR)/$(am__dirstamp)
+src/src_connmand-machine.$(OBJEXT): src/$(am__dirstamp) \
+	src/$(DEPDIR)/$(am__dirstamp)
+src/src_connmand-util.$(OBJEXT): src/$(am__dirstamp) \
+	src/$(DEPDIR)/$(am__dirstamp)
+src/src_connmand-rlimits.$(OBJEXT): src/$(am__dirstamp) \
+	src/$(DEPDIR)/$(am__dirstamp)
+
+src/connmand$(EXEEXT): $(src_connmand_OBJECTS) $(src_connmand_DEPENDENCIES) $(EXTRA_src_connmand_DEPENDENCIES) src/$(am__dirstamp)
+	@rm -f src/connmand$(EXEEXT)
+	$(AM_V_CCLD)$(src_connmand_LINK) $(src_connmand_OBJECTS) $(src_connmand_LDADD) $(LIBS)
+tools/$(am__dirstamp):
+	@$(MKDIR_P) tools
+	@: > tools/$(am__dirstamp)
+tools/$(DEPDIR)/$(am__dirstamp):
+	@$(MKDIR_P) tools/$(DEPDIR)
+	@: > tools/$(DEPDIR)/$(am__dirstamp)
+tools/addr-test.$(OBJEXT): tools/$(am__dirstamp) \
+	tools/$(DEPDIR)/$(am__dirstamp)
+
+tools/addr-test$(EXEEXT): $(tools_addr_test_OBJECTS) $(tools_addr_test_DEPENDENCIES) $(EXTRA_tools_addr_test_DEPENDENCIES) tools/$(am__dirstamp)
+	@rm -f tools/addr-test$(EXEEXT)
+	$(AM_V_CCLD)$(LINK) $(tools_addr_test_OBJECTS) $(tools_addr_test_LDADD) $(LIBS)
+tools/dbus-test.$(OBJEXT): tools/$(am__dirstamp) \
+	tools/$(DEPDIR)/$(am__dirstamp)
+
+tools/dbus-test$(EXEEXT): $(tools_dbus_test_OBJECTS) $(tools_dbus_test_DEPENDENCIES) $(EXTRA_tools_dbus_test_DEPENDENCIES) tools/$(am__dirstamp)
+	@rm -f tools/dbus-test$(EXEEXT)
+	$(AM_V_CCLD)$(LINK) $(tools_dbus_test_OBJECTS) $(tools_dbus_test_LDADD) $(LIBS)
+gdhcp/common.$(OBJEXT): gdhcp/$(am__dirstamp) \
+	gdhcp/$(DEPDIR)/$(am__dirstamp)
+gdhcp/client.$(OBJEXT): gdhcp/$(am__dirstamp) \
+	gdhcp/$(DEPDIR)/$(am__dirstamp)
+gdhcp/server.$(OBJEXT): gdhcp/$(am__dirstamp) \
+	gdhcp/$(DEPDIR)/$(am__dirstamp)
+gdhcp/ipv4ll.$(OBJEXT): gdhcp/$(am__dirstamp) \
+	gdhcp/$(DEPDIR)/$(am__dirstamp)
+gdhcp/timer.$(OBJEXT): gdhcp/$(am__dirstamp) \
+	gdhcp/$(DEPDIR)/$(am__dirstamp)
+tools/dhcp-server-test.$(OBJEXT): tools/$(am__dirstamp) \
+	tools/$(DEPDIR)/$(am__dirstamp)
+
+tools/dhcp-server-test$(EXEEXT): $(tools_dhcp_server_test_OBJECTS) $(tools_dhcp_server_test_DEPENDENCIES) $(EXTRA_tools_dhcp_server_test_DEPENDENCIES) tools/$(am__dirstamp)
+	@rm -f tools/dhcp-server-test$(EXEEXT)
+	$(AM_V_CCLD)$(LINK) $(tools_dhcp_server_test_OBJECTS) $(tools_dhcp_server_test_LDADD) $(LIBS)
+tools/dhcp-test.$(OBJEXT): tools/$(am__dirstamp) \
+	tools/$(DEPDIR)/$(am__dirstamp)
+
+tools/dhcp-test$(EXEEXT): $(tools_dhcp_test_OBJECTS) $(tools_dhcp_test_DEPENDENCIES) $(EXTRA_tools_dhcp_test_DEPENDENCIES) tools/$(am__dirstamp)
+	@rm -f tools/dhcp-test$(EXEEXT)
+	$(AM_V_CCLD)$(LINK) $(tools_dhcp_test_OBJECTS) $(tools_dhcp_test_LDADD) $(LIBS)
+tools/dnsproxy-test.$(OBJEXT): tools/$(am__dirstamp) \
+	tools/$(DEPDIR)/$(am__dirstamp)
+
+tools/dnsproxy-test$(EXEEXT): $(tools_dnsproxy_test_OBJECTS) $(tools_dnsproxy_test_DEPENDENCIES) $(EXTRA_tools_dnsproxy_test_DEPENDENCIES) tools/$(am__dirstamp)
+	@rm -f tools/dnsproxy-test$(EXEEXT)
+	$(AM_V_CCLD)$(LINK) $(tools_dnsproxy_test_OBJECTS) $(tools_dnsproxy_test_LDADD) $(LIBS)
+src/log.$(OBJEXT): src/$(am__dirstamp) src/$(DEPDIR)/$(am__dirstamp)
+src/iptables.$(OBJEXT): src/$(am__dirstamp) \
+	src/$(DEPDIR)/$(am__dirstamp)
+tools/iptables-test.$(OBJEXT): tools/$(am__dirstamp) \
+	tools/$(DEPDIR)/$(am__dirstamp)
+
+tools/iptables-test$(EXEEXT): $(tools_iptables_test_OBJECTS) $(tools_iptables_test_DEPENDENCIES) $(EXTRA_tools_iptables_test_DEPENDENCIES) tools/$(am__dirstamp)
+	@rm -f tools/iptables-test$(EXEEXT)
+	$(AM_V_CCLD)$(LINK) $(tools_iptables_test_OBJECTS) $(tools_iptables_test_LDADD) $(LIBS)
+src/tools_iptables_unit-log.$(OBJEXT): src/$(am__dirstamp) \
+	src/$(DEPDIR)/$(am__dirstamp)
+src/tools_iptables_unit-iptables.$(OBJEXT): src/$(am__dirstamp) \
+	src/$(DEPDIR)/$(am__dirstamp)
+src/tools_iptables_unit-firewall.$(OBJEXT): src/$(am__dirstamp) \
+	src/$(DEPDIR)/$(am__dirstamp)
+src/tools_iptables_unit-nat.$(OBJEXT): src/$(am__dirstamp) \
+	src/$(DEPDIR)/$(am__dirstamp)
+tools/tools_iptables_unit-iptables-unit.$(OBJEXT):  \
+	tools/$(am__dirstamp) tools/$(DEPDIR)/$(am__dirstamp)
+
+tools/iptables-unit$(EXEEXT): $(tools_iptables_unit_OBJECTS) $(tools_iptables_unit_DEPENDENCIES) $(EXTRA_tools_iptables_unit_DEPENDENCIES) tools/$(am__dirstamp)
+	@rm -f tools/iptables-unit$(EXEEXT)
+	$(AM_V_CCLD)$(tools_iptables_unit_LINK) $(tools_iptables_unit_OBJECTS) $(tools_iptables_unit_LDADD) $(LIBS)
+src/shared/util.$(OBJEXT): src/shared/$(am__dirstamp) \
+	src/shared/$(DEPDIR)/$(am__dirstamp)
+src/shared/netlink.$(OBJEXT): src/shared/$(am__dirstamp) \
+	src/shared/$(DEPDIR)/$(am__dirstamp)
+tools/netlink-test.$(OBJEXT): tools/$(am__dirstamp) \
+	tools/$(DEPDIR)/$(am__dirstamp)
+
+tools/netlink-test$(EXEEXT): $(tools_netlink_test_OBJECTS) $(tools_netlink_test_DEPENDENCIES) $(EXTRA_tools_netlink_test_DEPENDENCIES) tools/$(am__dirstamp)
+	@rm -f tools/netlink-test$(EXEEXT)
+	$(AM_V_CCLD)$(LINK) $(tools_netlink_test_OBJECTS) $(tools_netlink_test_LDADD) $(LIBS)
+tools/polkit-test.$(OBJEXT): tools/$(am__dirstamp) \
+	tools/$(DEPDIR)/$(am__dirstamp)
+
+tools/polkit-test$(EXEEXT): $(tools_polkit_test_OBJECTS) $(tools_polkit_test_DEPENDENCIES) $(EXTRA_tools_polkit_test_DEPENDENCIES) tools/$(am__dirstamp)
+	@rm -f tools/polkit-test$(EXEEXT)
+	$(AM_V_CCLD)$(LINK) $(tools_polkit_test_OBJECTS) $(tools_polkit_test_LDADD) $(LIBS)
+tools/private-network-test.$(OBJEXT): tools/$(am__dirstamp) \
+	tools/$(DEPDIR)/$(am__dirstamp)
+
+tools/private-network-test$(EXEEXT): $(tools_private_network_test_OBJECTS) $(tools_private_network_test_DEPENDENCIES) $(EXTRA_tools_private_network_test_DEPENDENCIES) tools/$(am__dirstamp)
+	@rm -f tools/private-network-test$(EXEEXT)
+	$(AM_V_CCLD)$(LINK) $(tools_private_network_test_OBJECTS) $(tools_private_network_test_LDADD) $(LIBS)
+gweb/gresolv.$(OBJEXT): gweb/$(am__dirstamp) \
+	gweb/$(DEPDIR)/$(am__dirstamp)
+tools/resolv-test.$(OBJEXT): tools/$(am__dirstamp) \
+	tools/$(DEPDIR)/$(am__dirstamp)
+
+tools/resolv-test$(EXEEXT): $(tools_resolv_test_OBJECTS) $(tools_resolv_test_DEPENDENCIES) $(EXTRA_tools_resolv_test_DEPENDENCIES) tools/$(am__dirstamp)
+	@rm -f tools/resolv-test$(EXEEXT)
+	$(AM_V_CCLD)$(LINK) $(tools_resolv_test_OBJECTS) $(tools_resolv_test_LDADD) $(LIBS)
+src/dbus.$(OBJEXT): src/$(am__dirstamp) src/$(DEPDIR)/$(am__dirstamp)
+src/error.$(OBJEXT): src/$(am__dirstamp) src/$(DEPDIR)/$(am__dirstamp)
+tools/session-test.$(OBJEXT): tools/$(am__dirstamp) \
+	tools/$(DEPDIR)/$(am__dirstamp)
+tools/session-utils.$(OBJEXT): tools/$(am__dirstamp) \
+	tools/$(DEPDIR)/$(am__dirstamp)
+tools/manager-api.$(OBJEXT): tools/$(am__dirstamp) \
+	tools/$(DEPDIR)/$(am__dirstamp)
+tools/session-api.$(OBJEXT): tools/$(am__dirstamp) \
+	tools/$(DEPDIR)/$(am__dirstamp)
+
+tools/session-test$(EXEEXT): $(tools_session_test_OBJECTS) $(tools_session_test_DEPENDENCIES) $(EXTRA_tools_session_test_DEPENDENCIES) tools/$(am__dirstamp)
+	@rm -f tools/session-test$(EXEEXT)
+	$(AM_V_CCLD)$(LINK) $(tools_session_test_OBJECTS) $(tools_session_test_LDADD) $(LIBS)
+tools/stats-tool.$(OBJEXT): tools/$(am__dirstamp) \
+	tools/$(DEPDIR)/$(am__dirstamp)
+
+tools/stats-tool$(EXEEXT): $(tools_stats_tool_OBJECTS) $(tools_stats_tool_DEPENDENCIES) $(EXTRA_tools_stats_tool_DEPENDENCIES) tools/$(am__dirstamp)
+	@rm -f tools/stats-tool$(EXEEXT)
+	$(AM_V_CCLD)$(LINK) $(tools_stats_tool_OBJECTS) $(tools_stats_tool_LDADD) $(LIBS)
+tools/supplicant-test.$(OBJEXT): tools/$(am__dirstamp) \
+	tools/$(DEPDIR)/$(am__dirstamp)
+tools/supplicant-dbus.$(OBJEXT): tools/$(am__dirstamp) \
+	tools/$(DEPDIR)/$(am__dirstamp)
+tools/supplicant.$(OBJEXT): tools/$(am__dirstamp) \
+	tools/$(DEPDIR)/$(am__dirstamp)
+
+tools/supplicant-test$(EXEEXT): $(tools_supplicant_test_OBJECTS) $(tools_supplicant_test_DEPENDENCIES) $(EXTRA_tools_supplicant_test_DEPENDENCIES) tools/$(am__dirstamp)
+	@rm -f tools/supplicant-test$(EXEEXT)
+	$(AM_V_CCLD)$(LINK) $(tools_supplicant_test_OBJECTS) $(tools_supplicant_test_LDADD) $(LIBS)
+tools/tap-test.$(OBJEXT): tools/$(am__dirstamp) \
+	tools/$(DEPDIR)/$(am__dirstamp)
+
+tools/tap-test$(EXEEXT): $(tools_tap_test_OBJECTS) $(tools_tap_test_DEPENDENCIES) $(EXTRA_tools_tap_test_DEPENDENCIES) tools/$(am__dirstamp)
+	@rm -f tools/tap-test$(EXEEXT)
+	$(AM_V_CCLD)$(LINK) $(tools_tap_test_OBJECTS) $(tools_tap_test_LDADD) $(LIBS)
+gweb/gweb.$(OBJEXT): gweb/$(am__dirstamp) \
+	gweb/$(DEPDIR)/$(am__dirstamp)
+gweb/giognutls.$(OBJEXT): gweb/$(am__dirstamp) \
+	gweb/$(DEPDIR)/$(am__dirstamp)
+gweb/gionotls.$(OBJEXT): gweb/$(am__dirstamp) \
+	gweb/$(DEPDIR)/$(am__dirstamp)
+tools/web-test.$(OBJEXT): tools/$(am__dirstamp) \
+	tools/$(DEPDIR)/$(am__dirstamp)
+
+tools/web-test$(EXEEXT): $(tools_web_test_OBJECTS) $(tools_web_test_DEPENDENCIES) $(EXTRA_tools_web_test_DEPENDENCIES) tools/$(am__dirstamp)
+	@rm -f tools/web-test$(EXEEXT)
+	$(AM_V_CCLD)$(LINK) $(tools_web_test_OBJECTS) $(tools_web_test_LDADD) $(LIBS)
+tools/wispr.$(OBJEXT): tools/$(am__dirstamp) \
+	tools/$(DEPDIR)/$(am__dirstamp)
+
+tools/wispr$(EXEEXT): $(tools_wispr_OBJECTS) $(tools_wispr_DEPENDENCIES) $(EXTRA_tools_wispr_DEPENDENCIES) tools/$(am__dirstamp)
+	@rm -f tools/wispr$(EXEEXT)
+	$(AM_V_CCLD)$(LINK) $(tools_wispr_OBJECTS) $(tools_wispr_LDADD) $(LIBS)
+tools/wpad-test.$(OBJEXT): tools/$(am__dirstamp) \
+	tools/$(DEPDIR)/$(am__dirstamp)
+
+tools/wpad-test$(EXEEXT): $(tools_wpad_test_OBJECTS) $(tools_wpad_test_DEPENDENCIES) $(EXTRA_tools_wpad_test_DEPENDENCIES) tools/$(am__dirstamp)
+	@rm -f tools/wpad-test$(EXEEXT)
+	$(AM_V_CCLD)$(LINK) $(tools_wpad_test_OBJECTS) $(tools_wpad_test_LDADD) $(LIBS)
+src/ippool.$(OBJEXT): src/$(am__dirstamp) \
+	src/$(DEPDIR)/$(am__dirstamp)
+unit/$(am__dirstamp):
+	@$(MKDIR_P) unit
+	@: > unit/$(am__dirstamp)
+unit/$(DEPDIR)/$(am__dirstamp):
+	@$(MKDIR_P) unit/$(DEPDIR)
+	@: > unit/$(DEPDIR)/$(am__dirstamp)
+unit/test-ippool.$(OBJEXT): unit/$(am__dirstamp) \
+	unit/$(DEPDIR)/$(am__dirstamp)
+
+unit/test-ippool$(EXEEXT): $(unit_test_ippool_OBJECTS) $(unit_test_ippool_DEPENDENCIES) $(EXTRA_unit_test_ippool_DEPENDENCIES) unit/$(am__dirstamp)
+	@rm -f unit/test-ippool$(EXEEXT)
+	$(AM_V_CCLD)$(LINK) $(unit_test_ippool_OBJECTS) $(unit_test_ippool_LDADD) $(LIBS)
+vpn/plugins/vpn_connman_vpnd-openconnect.$(OBJEXT):  \
+	vpn/plugins/$(am__dirstamp) \
+	vpn/plugins/$(DEPDIR)/$(am__dirstamp)
+vpn/plugins/vpn_connman_vpnd-openvpn.$(OBJEXT):  \
+	vpn/plugins/$(am__dirstamp) \
+	vpn/plugins/$(DEPDIR)/$(am__dirstamp)
+vpn/plugins/vpn_connman_vpnd-vpnc.$(OBJEXT):  \
+	vpn/plugins/$(am__dirstamp) \
+	vpn/plugins/$(DEPDIR)/$(am__dirstamp)
+vpn/plugins/vpn_connman_vpnd-l2tp.$(OBJEXT):  \
+	vpn/plugins/$(am__dirstamp) \
+	vpn/plugins/$(DEPDIR)/$(am__dirstamp)
+vpn/plugins/vpn_connman_vpnd-pptp.$(OBJEXT):  \
+	vpn/plugins/$(am__dirstamp) \
+	vpn/plugins/$(DEPDIR)/$(am__dirstamp)
+vpn/plugins/vpn_connman_vpnd-vpn.$(OBJEXT):  \
+	vpn/plugins/$(am__dirstamp) \
+	vpn/plugins/$(DEPDIR)/$(am__dirstamp)
+gweb/vpn_connman_vpnd-gweb.$(OBJEXT): gweb/$(am__dirstamp) \
+	gweb/$(DEPDIR)/$(am__dirstamp)
+gweb/vpn_connman_vpnd-gresolv.$(OBJEXT): gweb/$(am__dirstamp) \
+	gweb/$(DEPDIR)/$(am__dirstamp)
+gweb/vpn_connman_vpnd-giognutls.$(OBJEXT): gweb/$(am__dirstamp) \
+	gweb/$(DEPDIR)/$(am__dirstamp)
+gweb/vpn_connman_vpnd-gionotls.$(OBJEXT): gweb/$(am__dirstamp) \
+	gweb/$(DEPDIR)/$(am__dirstamp)
+vpn/$(am__dirstamp):
+	@$(MKDIR_P) vpn
+	@: > vpn/$(am__dirstamp)
+vpn/$(DEPDIR)/$(am__dirstamp):
+	@$(MKDIR_P) vpn/$(DEPDIR)
+	@: > vpn/$(DEPDIR)/$(am__dirstamp)
+vpn/vpn_connman_vpnd-main.$(OBJEXT): vpn/$(am__dirstamp) \
+	vpn/$(DEPDIR)/$(am__dirstamp)
+src/vpn_connman_vpnd-log.$(OBJEXT): src/$(am__dirstamp) \
+	src/$(DEPDIR)/$(am__dirstamp)
+src/vpn_connman_vpnd-error.$(OBJEXT): src/$(am__dirstamp) \
+	src/$(DEPDIR)/$(am__dirstamp)
+src/vpn_connman_vpnd-plugin.$(OBJEXT): src/$(am__dirstamp) \
+	src/$(DEPDIR)/$(am__dirstamp)
+src/vpn_connman_vpnd-task.$(OBJEXT): src/$(am__dirstamp) \
+	src/$(DEPDIR)/$(am__dirstamp)
+vpn/vpn_connman_vpnd-vpn-manager.$(OBJEXT): vpn/$(am__dirstamp) \
+	vpn/$(DEPDIR)/$(am__dirstamp)
+vpn/vpn_connman_vpnd-vpn-provider.$(OBJEXT): vpn/$(am__dirstamp) \
+	vpn/$(DEPDIR)/$(am__dirstamp)
+vpn/vpn_connman_vpnd-vpn-ipconfig.$(OBJEXT): vpn/$(am__dirstamp) \
+	vpn/$(DEPDIR)/$(am__dirstamp)
+src/vpn_connman_vpnd-inet.$(OBJEXT): src/$(am__dirstamp) \
+	src/$(DEPDIR)/$(am__dirstamp)
+vpn/vpn_connman_vpnd-vpn-rtnl.$(OBJEXT): vpn/$(am__dirstamp) \
+	vpn/$(DEPDIR)/$(am__dirstamp)
+src/vpn_connman_vpnd-dbus.$(OBJEXT): src/$(am__dirstamp) \
+	src/$(DEPDIR)/$(am__dirstamp)
+src/vpn_connman_vpnd-storage.$(OBJEXT): src/$(am__dirstamp) \
+	src/$(DEPDIR)/$(am__dirstamp)
+src/vpn_connman_vpnd-ipaddress.$(OBJEXT): src/$(am__dirstamp) \
+	src/$(DEPDIR)/$(am__dirstamp)
+src/vpn_connman_vpnd-agent.$(OBJEXT): src/$(am__dirstamp) \
+	src/$(DEPDIR)/$(am__dirstamp)
+vpn/vpn_connman_vpnd-vpn-agent.$(OBJEXT): vpn/$(am__dirstamp) \
+	vpn/$(DEPDIR)/$(am__dirstamp)
+src/vpn_connman_vpnd-inotify.$(OBJEXT): src/$(am__dirstamp) \
+	src/$(DEPDIR)/$(am__dirstamp)
+vpn/vpn_connman_vpnd-vpn-config.$(OBJEXT): vpn/$(am__dirstamp) \
+	vpn/$(DEPDIR)/$(am__dirstamp)
+
+vpn/connman-vpnd$(EXEEXT): $(vpn_connman_vpnd_OBJECTS) $(vpn_connman_vpnd_DEPENDENCIES) $(EXTRA_vpn_connman_vpnd_DEPENDENCIES) vpn/$(am__dirstamp)
+	@rm -f vpn/connman-vpnd$(EXEEXT)
+	$(AM_V_CCLD)$(vpn_connman_vpnd_LINK) $(vpn_connman_vpnd_OBJECTS) $(vpn_connman_vpnd_LDADD) $(LIBS)
+install-testSCRIPTS: $(test_SCRIPTS)
+	@$(NORMAL_INSTALL)
+	@list='$(test_SCRIPTS)'; test -n "$(testdir)" || list=; \
+	if test -n "$$list"; then \
+	  echo " $(MKDIR_P) '$(DESTDIR)$(testdir)'"; \
+	  $(MKDIR_P) "$(DESTDIR)$(testdir)" || exit 1; \
+	fi; \
+	for p in $$list; do \
+	  if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
+	  if test -f "$$d$$p"; then echo "$$d$$p"; echo "$$p"; else :; fi; \
+	done | \
+	sed -e 'p;s,.*/,,;n' \
+	    -e 'h;s|.*|.|' \
+	    -e 'p;x;s,.*/,,;$(transform)' | sed 'N;N;N;s,\n, ,g' | \
+	$(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1; } \
+	  { d=$$3; if (dirs[d] != 1) { print "d", d; dirs[d] = 1 } \
+	    if ($$2 == $$4) { files[d] = files[d] " " $$1; \
+	      if (++n[d] == $(am__install_max)) { \
+		print "f", d, files[d]; n[d] = 0; files[d] = "" } } \
+	    else { print "f", d "/" $$4, $$1 } } \
+	  END { for (d in files) print "f", d, files[d] }' | \
+	while read type dir files; do \
+	     if test "$$dir" = .; then dir=; else dir=/$$dir; fi; \
+	     test -z "$$files" || { \
+	       echo " $(INSTALL_SCRIPT) $$files '$(DESTDIR)$(testdir)$$dir'"; \
+	       $(INSTALL_SCRIPT) $$files "$(DESTDIR)$(testdir)$$dir" || exit $$?; \
+	     } \
+	; done
+
+uninstall-testSCRIPTS:
+	@$(NORMAL_UNINSTALL)
+	@list='$(test_SCRIPTS)'; test -n "$(testdir)" || exit 0; \
+	files=`for p in $$list; do echo "$$p"; done | \
+	       sed -e 's,.*/,,;$(transform)'`; \
+	dir='$(DESTDIR)$(testdir)'; $(am__uninstall_files_from_dir)
+
+mostlyclean-compile:
+	-rm -f *.$(OBJEXT)
+	-rm -f client/*.$(OBJEXT)
+	-rm -f gdbus/*.$(OBJEXT)
+	-rm -f gdbus/*.lo
+	-rm -f gdhcp/*.$(OBJEXT)
+	-rm -f gsupplicant/*.$(OBJEXT)
+	-rm -f gweb/*.$(OBJEXT)
+	-rm -f plugins/*.$(OBJEXT)
+	-rm -f plugins/*.lo
+	-rm -f scripts/*.$(OBJEXT)
+	-rm -f scripts/*.lo
+	-rm -f src/*.$(OBJEXT)
+	-rm -f src/shared/*.$(OBJEXT)
+	-rm -f tools/*.$(OBJEXT)
+	-rm -f unit/*.$(OBJEXT)
+	-rm -f vpn/*.$(OBJEXT)
+	-rm -f vpn/plugins/*.$(OBJEXT)
+	-rm -f vpn/plugins/*.lo
+
+distclean-compile:
+	-rm -f *.tab.c
+
+@AMDEP_TRUE@@am__include@ @am__quote@client/$(DEPDIR)/agent.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@client/$(DEPDIR)/commands.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@client/$(DEPDIR)/dbus_helpers.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@client/$(DEPDIR)/input.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@client/$(DEPDIR)/main.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@client/$(DEPDIR)/peers.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@client/$(DEPDIR)/services.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@client/$(DEPDIR)/vpnconnections.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@gdbus/$(DEPDIR)/client.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@gdbus/$(DEPDIR)/mainloop.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@gdbus/$(DEPDIR)/object.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@gdbus/$(DEPDIR)/polkit.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@gdbus/$(DEPDIR)/watch.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@gdhcp/$(DEPDIR)/client.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@gdhcp/$(DEPDIR)/common.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@gdhcp/$(DEPDIR)/ipv4ll.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@gdhcp/$(DEPDIR)/server.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@gdhcp/$(DEPDIR)/src_connmand-client.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@gdhcp/$(DEPDIR)/src_connmand-common.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@gdhcp/$(DEPDIR)/src_connmand-ipv4ll.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@gdhcp/$(DEPDIR)/src_connmand-server.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@gdhcp/$(DEPDIR)/src_connmand-timer.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@gdhcp/$(DEPDIR)/timer.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@gsupplicant/$(DEPDIR)/src_connmand-dbus.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@gsupplicant/$(DEPDIR)/src_connmand-supplicant.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@gweb/$(DEPDIR)/giognutls.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@gweb/$(DEPDIR)/gionotls.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@gweb/$(DEPDIR)/gresolv.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@gweb/$(DEPDIR)/gweb.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@gweb/$(DEPDIR)/src_connmand-giognutls.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@gweb/$(DEPDIR)/src_connmand-gionotls.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@gweb/$(DEPDIR)/src_connmand-gresolv.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@gweb/$(DEPDIR)/src_connmand-gweb.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@gweb/$(DEPDIR)/vpn_connman_vpnd-giognutls.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@gweb/$(DEPDIR)/vpn_connman_vpnd-gionotls.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@gweb/$(DEPDIR)/vpn_connman_vpnd-gresolv.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@gweb/$(DEPDIR)/vpn_connman_vpnd-gweb.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@plugins/$(DEPDIR)/plugins_hh2serial_gps_la-hh2serial-gps.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@plugins/$(DEPDIR)/plugins_iospm_la-iospm.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@plugins/$(DEPDIR)/plugins_session_policy_local_la-session_policy_local.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@plugins/$(DEPDIR)/plugins_tist_la-tist.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@plugins/$(DEPDIR)/src_connmand-bluetooth.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@plugins/$(DEPDIR)/src_connmand-bluetooth_legacy.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@plugins/$(DEPDIR)/src_connmand-dundee.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@plugins/$(DEPDIR)/src_connmand-ethernet.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@plugins/$(DEPDIR)/src_connmand-gadget.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@plugins/$(DEPDIR)/src_connmand-hh2serial-gps.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@plugins/$(DEPDIR)/src_connmand-loopback.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@plugins/$(DEPDIR)/src_connmand-neard.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@plugins/$(DEPDIR)/src_connmand-nmcompat.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@plugins/$(DEPDIR)/src_connmand-ofono.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@plugins/$(DEPDIR)/src_connmand-pacrunner.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@plugins/$(DEPDIR)/src_connmand-polkit.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@plugins/$(DEPDIR)/src_connmand-session_policy_local.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@plugins/$(DEPDIR)/src_connmand-tist.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@plugins/$(DEPDIR)/src_connmand-vpn.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@plugins/$(DEPDIR)/src_connmand-wifi.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@scripts/$(DEPDIR)/libppp-plugin.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@scripts/$(DEPDIR)/openconnect-script.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@scripts/$(DEPDIR)/openvpn-script.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/dbus.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/error.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/ippool.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/iptables.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/log.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/src_connmand-6to4.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/src_connmand-agent-connman.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/src_connmand-agent.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/src_connmand-bridge.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/src_connmand-clock.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/src_connmand-config.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/src_connmand-connection.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/src_connmand-counter.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/src_connmand-dbus.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/src_connmand-detect.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/src_connmand-device.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/src_connmand-dhcp.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/src_connmand-dhcpv6.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/src_connmand-dnsproxy.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/src_connmand-error.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/src_connmand-firewall.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/src_connmand-inet.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/src_connmand-inotify.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/src_connmand-ipaddress.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/src_connmand-ipconfig.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/src_connmand-ippool.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/src_connmand-iptables.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/src_connmand-ipv6pd.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/src_connmand-log.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/src_connmand-machine.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/src_connmand-main.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/src_connmand-manager.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/src_connmand-nat.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/src_connmand-network.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/src_connmand-notifier.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/src_connmand-ntp.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/src_connmand-peer.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/src_connmand-peer_service.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/src_connmand-plugin.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/src_connmand-provider.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/src_connmand-proxy.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/src_connmand-resolver.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/src_connmand-rfkill.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/src_connmand-rlimits.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/src_connmand-rtnl.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/src_connmand-service.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/src_connmand-session.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/src_connmand-stats.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/src_connmand-storage.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/src_connmand-task.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/src_connmand-technology.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/src_connmand-tethering.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/src_connmand-timeserver.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/src_connmand-timezone.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/src_connmand-util.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/src_connmand-utsname.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/src_connmand-wispr.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/src_connmand-wpad.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/tools_iptables_unit-firewall.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/tools_iptables_unit-iptables.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/tools_iptables_unit-log.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/tools_iptables_unit-nat.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/vpn_connman_vpnd-agent.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/vpn_connman_vpnd-dbus.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/vpn_connman_vpnd-error.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/vpn_connman_vpnd-inet.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/vpn_connman_vpnd-inotify.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/vpn_connman_vpnd-ipaddress.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/vpn_connman_vpnd-log.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/vpn_connman_vpnd-plugin.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/vpn_connman_vpnd-storage.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/vpn_connman_vpnd-task.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/shared/$(DEPDIR)/netlink.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/shared/$(DEPDIR)/src_connmand-netlink.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/shared/$(DEPDIR)/src_connmand-util.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/shared/$(DEPDIR)/util.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@tools/$(DEPDIR)/addr-test.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@tools/$(DEPDIR)/dbus-test.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@tools/$(DEPDIR)/dhcp-server-test.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@tools/$(DEPDIR)/dhcp-test.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@tools/$(DEPDIR)/dnsproxy-test.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@tools/$(DEPDIR)/iptables-test.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@tools/$(DEPDIR)/manager-api.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@tools/$(DEPDIR)/netlink-test.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@tools/$(DEPDIR)/polkit-test.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@tools/$(DEPDIR)/private-network-test.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@tools/$(DEPDIR)/resolv-test.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@tools/$(DEPDIR)/session-api.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@tools/$(DEPDIR)/session-test.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@tools/$(DEPDIR)/session-utils.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@tools/$(DEPDIR)/stats-tool.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@tools/$(DEPDIR)/supplicant-dbus.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@tools/$(DEPDIR)/supplicant-test.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@tools/$(DEPDIR)/supplicant.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@tools/$(DEPDIR)/tap-test.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@tools/$(DEPDIR)/tools_iptables_unit-iptables-unit.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@tools/$(DEPDIR)/web-test.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@tools/$(DEPDIR)/wispr.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@tools/$(DEPDIR)/wpad-test.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@unit/$(DEPDIR)/test-ippool.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@vpn/$(DEPDIR)/vpn_connman_vpnd-main.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@vpn/$(DEPDIR)/vpn_connman_vpnd-vpn-agent.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@vpn/$(DEPDIR)/vpn_connman_vpnd-vpn-config.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@vpn/$(DEPDIR)/vpn_connman_vpnd-vpn-ipconfig.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@vpn/$(DEPDIR)/vpn_connman_vpnd-vpn-manager.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@vpn/$(DEPDIR)/vpn_connman_vpnd-vpn-provider.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@vpn/$(DEPDIR)/vpn_connman_vpnd-vpn-rtnl.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@vpn/plugins/$(DEPDIR)/vpn_connman_vpnd-l2tp.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@vpn/plugins/$(DEPDIR)/vpn_connman_vpnd-openconnect.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@vpn/plugins/$(DEPDIR)/vpn_connman_vpnd-openvpn.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@vpn/plugins/$(DEPDIR)/vpn_connman_vpnd-pptp.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@vpn/plugins/$(DEPDIR)/vpn_connman_vpnd-vpn.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@vpn/plugins/$(DEPDIR)/vpn_connman_vpnd-vpnc.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@vpn/plugins/$(DEPDIR)/vpn_plugins_l2tp_la-l2tp.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@vpn/plugins/$(DEPDIR)/vpn_plugins_l2tp_la-vpn.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@vpn/plugins/$(DEPDIR)/vpn_plugins_openconnect_la-openconnect.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@vpn/plugins/$(DEPDIR)/vpn_plugins_openconnect_la-vpn.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@vpn/plugins/$(DEPDIR)/vpn_plugins_openvpn_la-openvpn.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@vpn/plugins/$(DEPDIR)/vpn_plugins_openvpn_la-vpn.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@vpn/plugins/$(DEPDIR)/vpn_plugins_pptp_la-pptp.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@vpn/plugins/$(DEPDIR)/vpn_plugins_pptp_la-vpn.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@vpn/plugins/$(DEPDIR)/vpn_plugins_vpnc_la-vpn.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@vpn/plugins/$(DEPDIR)/vpn_plugins_vpnc_la-vpnc.Plo@am__quote@
+
+.c.o:
+@am__fastdepCC_TRUE@	$(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\
+@am__fastdepCC_TRUE@	$(COMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\
+@am__fastdepCC_TRUE@	$(am__mv) $$depbase.Tpo $$depbase.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ $<
+
+.c.obj:
+@am__fastdepCC_TRUE@	$(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.obj$$||'`;\
+@am__fastdepCC_TRUE@	$(COMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ `$(CYGPATH_W) '$<'` &&\
+@am__fastdepCC_TRUE@	$(am__mv) $$depbase.Tpo $$depbase.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
+
+.c.lo:
+@am__fastdepCC_TRUE@	$(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.lo$$||'`;\
+@am__fastdepCC_TRUE@	$(LTCOMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\
+@am__fastdepCC_TRUE@	$(am__mv) $$depbase.Tpo $$depbase.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $<
+
+plugins/plugins_hh2serial_gps_la-hh2serial-gps.lo: plugins/hh2serial-gps.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(plugins_hh2serial_gps_la_CFLAGS) $(CFLAGS) -MT plugins/plugins_hh2serial_gps_la-hh2serial-gps.lo -MD -MP -MF plugins/$(DEPDIR)/plugins_hh2serial_gps_la-hh2serial-gps.Tpo -c -o plugins/plugins_hh2serial_gps_la-hh2serial-gps.lo `test -f 'plugins/hh2serial-gps.c' || echo '$(srcdir)/'`plugins/hh2serial-gps.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) plugins/$(DEPDIR)/plugins_hh2serial_gps_la-hh2serial-gps.Tpo plugins/$(DEPDIR)/plugins_hh2serial_gps_la-hh2serial-gps.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='plugins/hh2serial-gps.c' object='plugins/plugins_hh2serial_gps_la-hh2serial-gps.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(plugins_hh2serial_gps_la_CFLAGS) $(CFLAGS) -c -o plugins/plugins_hh2serial_gps_la-hh2serial-gps.lo `test -f 'plugins/hh2serial-gps.c' || echo '$(srcdir)/'`plugins/hh2serial-gps.c
+
+plugins/plugins_iospm_la-iospm.lo: plugins/iospm.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(plugins_iospm_la_CFLAGS) $(CFLAGS) -MT plugins/plugins_iospm_la-iospm.lo -MD -MP -MF plugins/$(DEPDIR)/plugins_iospm_la-iospm.Tpo -c -o plugins/plugins_iospm_la-iospm.lo `test -f 'plugins/iospm.c' || echo '$(srcdir)/'`plugins/iospm.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) plugins/$(DEPDIR)/plugins_iospm_la-iospm.Tpo plugins/$(DEPDIR)/plugins_iospm_la-iospm.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='plugins/iospm.c' object='plugins/plugins_iospm_la-iospm.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(plugins_iospm_la_CFLAGS) $(CFLAGS) -c -o plugins/plugins_iospm_la-iospm.lo `test -f 'plugins/iospm.c' || echo '$(srcdir)/'`plugins/iospm.c
+
+plugins/plugins_session_policy_local_la-session_policy_local.lo: plugins/session_policy_local.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(plugins_session_policy_local_la_CFLAGS) $(CFLAGS) -MT plugins/plugins_session_policy_local_la-session_policy_local.lo -MD -MP -MF plugins/$(DEPDIR)/plugins_session_policy_local_la-session_policy_local.Tpo -c -o plugins/plugins_session_policy_local_la-session_policy_local.lo `test -f 'plugins/session_policy_local.c' || echo '$(srcdir)/'`plugins/session_policy_local.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) plugins/$(DEPDIR)/plugins_session_policy_local_la-session_policy_local.Tpo plugins/$(DEPDIR)/plugins_session_policy_local_la-session_policy_local.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='plugins/session_policy_local.c' object='plugins/plugins_session_policy_local_la-session_policy_local.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(plugins_session_policy_local_la_CFLAGS) $(CFLAGS) -c -o plugins/plugins_session_policy_local_la-session_policy_local.lo `test -f 'plugins/session_policy_local.c' || echo '$(srcdir)/'`plugins/session_policy_local.c
+
+plugins/plugins_tist_la-tist.lo: plugins/tist.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(plugins_tist_la_CFLAGS) $(CFLAGS) -MT plugins/plugins_tist_la-tist.lo -MD -MP -MF plugins/$(DEPDIR)/plugins_tist_la-tist.Tpo -c -o plugins/plugins_tist_la-tist.lo `test -f 'plugins/tist.c' || echo '$(srcdir)/'`plugins/tist.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) plugins/$(DEPDIR)/plugins_tist_la-tist.Tpo plugins/$(DEPDIR)/plugins_tist_la-tist.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='plugins/tist.c' object='plugins/plugins_tist_la-tist.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(plugins_tist_la_CFLAGS) $(CFLAGS) -c -o plugins/plugins_tist_la-tist.lo `test -f 'plugins/tist.c' || echo '$(srcdir)/'`plugins/tist.c
+
+vpn/plugins/vpn_plugins_l2tp_la-vpn.lo: vpn/plugins/vpn.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_plugins_l2tp_la_CFLAGS) $(CFLAGS) -MT vpn/plugins/vpn_plugins_l2tp_la-vpn.lo -MD -MP -MF vpn/plugins/$(DEPDIR)/vpn_plugins_l2tp_la-vpn.Tpo -c -o vpn/plugins/vpn_plugins_l2tp_la-vpn.lo `test -f 'vpn/plugins/vpn.c' || echo '$(srcdir)/'`vpn/plugins/vpn.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) vpn/plugins/$(DEPDIR)/vpn_plugins_l2tp_la-vpn.Tpo vpn/plugins/$(DEPDIR)/vpn_plugins_l2tp_la-vpn.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='vpn/plugins/vpn.c' object='vpn/plugins/vpn_plugins_l2tp_la-vpn.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_plugins_l2tp_la_CFLAGS) $(CFLAGS) -c -o vpn/plugins/vpn_plugins_l2tp_la-vpn.lo `test -f 'vpn/plugins/vpn.c' || echo '$(srcdir)/'`vpn/plugins/vpn.c
+
+vpn/plugins/vpn_plugins_l2tp_la-l2tp.lo: vpn/plugins/l2tp.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_plugins_l2tp_la_CFLAGS) $(CFLAGS) -MT vpn/plugins/vpn_plugins_l2tp_la-l2tp.lo -MD -MP -MF vpn/plugins/$(DEPDIR)/vpn_plugins_l2tp_la-l2tp.Tpo -c -o vpn/plugins/vpn_plugins_l2tp_la-l2tp.lo `test -f 'vpn/plugins/l2tp.c' || echo '$(srcdir)/'`vpn/plugins/l2tp.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) vpn/plugins/$(DEPDIR)/vpn_plugins_l2tp_la-l2tp.Tpo vpn/plugins/$(DEPDIR)/vpn_plugins_l2tp_la-l2tp.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='vpn/plugins/l2tp.c' object='vpn/plugins/vpn_plugins_l2tp_la-l2tp.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_plugins_l2tp_la_CFLAGS) $(CFLAGS) -c -o vpn/plugins/vpn_plugins_l2tp_la-l2tp.lo `test -f 'vpn/plugins/l2tp.c' || echo '$(srcdir)/'`vpn/plugins/l2tp.c
+
+vpn/plugins/vpn_plugins_openconnect_la-vpn.lo: vpn/plugins/vpn.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_plugins_openconnect_la_CFLAGS) $(CFLAGS) -MT vpn/plugins/vpn_plugins_openconnect_la-vpn.lo -MD -MP -MF vpn/plugins/$(DEPDIR)/vpn_plugins_openconnect_la-vpn.Tpo -c -o vpn/plugins/vpn_plugins_openconnect_la-vpn.lo `test -f 'vpn/plugins/vpn.c' || echo '$(srcdir)/'`vpn/plugins/vpn.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) vpn/plugins/$(DEPDIR)/vpn_plugins_openconnect_la-vpn.Tpo vpn/plugins/$(DEPDIR)/vpn_plugins_openconnect_la-vpn.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='vpn/plugins/vpn.c' object='vpn/plugins/vpn_plugins_openconnect_la-vpn.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_plugins_openconnect_la_CFLAGS) $(CFLAGS) -c -o vpn/plugins/vpn_plugins_openconnect_la-vpn.lo `test -f 'vpn/plugins/vpn.c' || echo '$(srcdir)/'`vpn/plugins/vpn.c
+
+vpn/plugins/vpn_plugins_openconnect_la-openconnect.lo: vpn/plugins/openconnect.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_plugins_openconnect_la_CFLAGS) $(CFLAGS) -MT vpn/plugins/vpn_plugins_openconnect_la-openconnect.lo -MD -MP -MF vpn/plugins/$(DEPDIR)/vpn_plugins_openconnect_la-openconnect.Tpo -c -o vpn/plugins/vpn_plugins_openconnect_la-openconnect.lo `test -f 'vpn/plugins/openconnect.c' || echo '$(srcdir)/'`vpn/plugins/openconnect.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) vpn/plugins/$(DEPDIR)/vpn_plugins_openconnect_la-openconnect.Tpo vpn/plugins/$(DEPDIR)/vpn_plugins_openconnect_la-openconnect.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='vpn/plugins/openconnect.c' object='vpn/plugins/vpn_plugins_openconnect_la-openconnect.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_plugins_openconnect_la_CFLAGS) $(CFLAGS) -c -o vpn/plugins/vpn_plugins_openconnect_la-openconnect.lo `test -f 'vpn/plugins/openconnect.c' || echo '$(srcdir)/'`vpn/plugins/openconnect.c
+
+vpn/plugins/vpn_plugins_openvpn_la-vpn.lo: vpn/plugins/vpn.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_plugins_openvpn_la_CFLAGS) $(CFLAGS) -MT vpn/plugins/vpn_plugins_openvpn_la-vpn.lo -MD -MP -MF vpn/plugins/$(DEPDIR)/vpn_plugins_openvpn_la-vpn.Tpo -c -o vpn/plugins/vpn_plugins_openvpn_la-vpn.lo `test -f 'vpn/plugins/vpn.c' || echo '$(srcdir)/'`vpn/plugins/vpn.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) vpn/plugins/$(DEPDIR)/vpn_plugins_openvpn_la-vpn.Tpo vpn/plugins/$(DEPDIR)/vpn_plugins_openvpn_la-vpn.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='vpn/plugins/vpn.c' object='vpn/plugins/vpn_plugins_openvpn_la-vpn.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_plugins_openvpn_la_CFLAGS) $(CFLAGS) -c -o vpn/plugins/vpn_plugins_openvpn_la-vpn.lo `test -f 'vpn/plugins/vpn.c' || echo '$(srcdir)/'`vpn/plugins/vpn.c
+
+vpn/plugins/vpn_plugins_openvpn_la-openvpn.lo: vpn/plugins/openvpn.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_plugins_openvpn_la_CFLAGS) $(CFLAGS) -MT vpn/plugins/vpn_plugins_openvpn_la-openvpn.lo -MD -MP -MF vpn/plugins/$(DEPDIR)/vpn_plugins_openvpn_la-openvpn.Tpo -c -o vpn/plugins/vpn_plugins_openvpn_la-openvpn.lo `test -f 'vpn/plugins/openvpn.c' || echo '$(srcdir)/'`vpn/plugins/openvpn.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) vpn/plugins/$(DEPDIR)/vpn_plugins_openvpn_la-openvpn.Tpo vpn/plugins/$(DEPDIR)/vpn_plugins_openvpn_la-openvpn.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='vpn/plugins/openvpn.c' object='vpn/plugins/vpn_plugins_openvpn_la-openvpn.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_plugins_openvpn_la_CFLAGS) $(CFLAGS) -c -o vpn/plugins/vpn_plugins_openvpn_la-openvpn.lo `test -f 'vpn/plugins/openvpn.c' || echo '$(srcdir)/'`vpn/plugins/openvpn.c
+
+vpn/plugins/vpn_plugins_pptp_la-vpn.lo: vpn/plugins/vpn.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_plugins_pptp_la_CFLAGS) $(CFLAGS) -MT vpn/plugins/vpn_plugins_pptp_la-vpn.lo -MD -MP -MF vpn/plugins/$(DEPDIR)/vpn_plugins_pptp_la-vpn.Tpo -c -o vpn/plugins/vpn_plugins_pptp_la-vpn.lo `test -f 'vpn/plugins/vpn.c' || echo '$(srcdir)/'`vpn/plugins/vpn.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) vpn/plugins/$(DEPDIR)/vpn_plugins_pptp_la-vpn.Tpo vpn/plugins/$(DEPDIR)/vpn_plugins_pptp_la-vpn.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='vpn/plugins/vpn.c' object='vpn/plugins/vpn_plugins_pptp_la-vpn.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_plugins_pptp_la_CFLAGS) $(CFLAGS) -c -o vpn/plugins/vpn_plugins_pptp_la-vpn.lo `test -f 'vpn/plugins/vpn.c' || echo '$(srcdir)/'`vpn/plugins/vpn.c
+
+vpn/plugins/vpn_plugins_pptp_la-pptp.lo: vpn/plugins/pptp.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_plugins_pptp_la_CFLAGS) $(CFLAGS) -MT vpn/plugins/vpn_plugins_pptp_la-pptp.lo -MD -MP -MF vpn/plugins/$(DEPDIR)/vpn_plugins_pptp_la-pptp.Tpo -c -o vpn/plugins/vpn_plugins_pptp_la-pptp.lo `test -f 'vpn/plugins/pptp.c' || echo '$(srcdir)/'`vpn/plugins/pptp.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) vpn/plugins/$(DEPDIR)/vpn_plugins_pptp_la-pptp.Tpo vpn/plugins/$(DEPDIR)/vpn_plugins_pptp_la-pptp.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='vpn/plugins/pptp.c' object='vpn/plugins/vpn_plugins_pptp_la-pptp.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_plugins_pptp_la_CFLAGS) $(CFLAGS) -c -o vpn/plugins/vpn_plugins_pptp_la-pptp.lo `test -f 'vpn/plugins/pptp.c' || echo '$(srcdir)/'`vpn/plugins/pptp.c
+
+vpn/plugins/vpn_plugins_vpnc_la-vpn.lo: vpn/plugins/vpn.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_plugins_vpnc_la_CFLAGS) $(CFLAGS) -MT vpn/plugins/vpn_plugins_vpnc_la-vpn.lo -MD -MP -MF vpn/plugins/$(DEPDIR)/vpn_plugins_vpnc_la-vpn.Tpo -c -o vpn/plugins/vpn_plugins_vpnc_la-vpn.lo `test -f 'vpn/plugins/vpn.c' || echo '$(srcdir)/'`vpn/plugins/vpn.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) vpn/plugins/$(DEPDIR)/vpn_plugins_vpnc_la-vpn.Tpo vpn/plugins/$(DEPDIR)/vpn_plugins_vpnc_la-vpn.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='vpn/plugins/vpn.c' object='vpn/plugins/vpn_plugins_vpnc_la-vpn.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_plugins_vpnc_la_CFLAGS) $(CFLAGS) -c -o vpn/plugins/vpn_plugins_vpnc_la-vpn.lo `test -f 'vpn/plugins/vpn.c' || echo '$(srcdir)/'`vpn/plugins/vpn.c
+
+vpn/plugins/vpn_plugins_vpnc_la-vpnc.lo: vpn/plugins/vpnc.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_plugins_vpnc_la_CFLAGS) $(CFLAGS) -MT vpn/plugins/vpn_plugins_vpnc_la-vpnc.lo -MD -MP -MF vpn/plugins/$(DEPDIR)/vpn_plugins_vpnc_la-vpnc.Tpo -c -o vpn/plugins/vpn_plugins_vpnc_la-vpnc.lo `test -f 'vpn/plugins/vpnc.c' || echo '$(srcdir)/'`vpn/plugins/vpnc.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) vpn/plugins/$(DEPDIR)/vpn_plugins_vpnc_la-vpnc.Tpo vpn/plugins/$(DEPDIR)/vpn_plugins_vpnc_la-vpnc.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='vpn/plugins/vpnc.c' object='vpn/plugins/vpn_plugins_vpnc_la-vpnc.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_plugins_vpnc_la_CFLAGS) $(CFLAGS) -c -o vpn/plugins/vpn_plugins_vpnc_la-vpnc.lo `test -f 'vpn/plugins/vpnc.c' || echo '$(srcdir)/'`vpn/plugins/vpnc.c
+
+gdhcp/src_connmand-common.o: gdhcp/common.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT gdhcp/src_connmand-common.o -MD -MP -MF gdhcp/$(DEPDIR)/src_connmand-common.Tpo -c -o gdhcp/src_connmand-common.o `test -f 'gdhcp/common.c' || echo '$(srcdir)/'`gdhcp/common.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) gdhcp/$(DEPDIR)/src_connmand-common.Tpo gdhcp/$(DEPDIR)/src_connmand-common.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='gdhcp/common.c' object='gdhcp/src_connmand-common.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o gdhcp/src_connmand-common.o `test -f 'gdhcp/common.c' || echo '$(srcdir)/'`gdhcp/common.c
+
+gdhcp/src_connmand-common.obj: gdhcp/common.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT gdhcp/src_connmand-common.obj -MD -MP -MF gdhcp/$(DEPDIR)/src_connmand-common.Tpo -c -o gdhcp/src_connmand-common.obj `if test -f 'gdhcp/common.c'; then $(CYGPATH_W) 'gdhcp/common.c'; else $(CYGPATH_W) '$(srcdir)/gdhcp/common.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) gdhcp/$(DEPDIR)/src_connmand-common.Tpo gdhcp/$(DEPDIR)/src_connmand-common.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='gdhcp/common.c' object='gdhcp/src_connmand-common.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o gdhcp/src_connmand-common.obj `if test -f 'gdhcp/common.c'; then $(CYGPATH_W) 'gdhcp/common.c'; else $(CYGPATH_W) '$(srcdir)/gdhcp/common.c'; fi`
+
+gdhcp/src_connmand-client.o: gdhcp/client.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT gdhcp/src_connmand-client.o -MD -MP -MF gdhcp/$(DEPDIR)/src_connmand-client.Tpo -c -o gdhcp/src_connmand-client.o `test -f 'gdhcp/client.c' || echo '$(srcdir)/'`gdhcp/client.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) gdhcp/$(DEPDIR)/src_connmand-client.Tpo gdhcp/$(DEPDIR)/src_connmand-client.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='gdhcp/client.c' object='gdhcp/src_connmand-client.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o gdhcp/src_connmand-client.o `test -f 'gdhcp/client.c' || echo '$(srcdir)/'`gdhcp/client.c
+
+gdhcp/src_connmand-client.obj: gdhcp/client.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT gdhcp/src_connmand-client.obj -MD -MP -MF gdhcp/$(DEPDIR)/src_connmand-client.Tpo -c -o gdhcp/src_connmand-client.obj `if test -f 'gdhcp/client.c'; then $(CYGPATH_W) 'gdhcp/client.c'; else $(CYGPATH_W) '$(srcdir)/gdhcp/client.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) gdhcp/$(DEPDIR)/src_connmand-client.Tpo gdhcp/$(DEPDIR)/src_connmand-client.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='gdhcp/client.c' object='gdhcp/src_connmand-client.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o gdhcp/src_connmand-client.obj `if test -f 'gdhcp/client.c'; then $(CYGPATH_W) 'gdhcp/client.c'; else $(CYGPATH_W) '$(srcdir)/gdhcp/client.c'; fi`
+
+gdhcp/src_connmand-server.o: gdhcp/server.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT gdhcp/src_connmand-server.o -MD -MP -MF gdhcp/$(DEPDIR)/src_connmand-server.Tpo -c -o gdhcp/src_connmand-server.o `test -f 'gdhcp/server.c' || echo '$(srcdir)/'`gdhcp/server.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) gdhcp/$(DEPDIR)/src_connmand-server.Tpo gdhcp/$(DEPDIR)/src_connmand-server.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='gdhcp/server.c' object='gdhcp/src_connmand-server.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o gdhcp/src_connmand-server.o `test -f 'gdhcp/server.c' || echo '$(srcdir)/'`gdhcp/server.c
+
+gdhcp/src_connmand-server.obj: gdhcp/server.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT gdhcp/src_connmand-server.obj -MD -MP -MF gdhcp/$(DEPDIR)/src_connmand-server.Tpo -c -o gdhcp/src_connmand-server.obj `if test -f 'gdhcp/server.c'; then $(CYGPATH_W) 'gdhcp/server.c'; else $(CYGPATH_W) '$(srcdir)/gdhcp/server.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) gdhcp/$(DEPDIR)/src_connmand-server.Tpo gdhcp/$(DEPDIR)/src_connmand-server.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='gdhcp/server.c' object='gdhcp/src_connmand-server.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o gdhcp/src_connmand-server.obj `if test -f 'gdhcp/server.c'; then $(CYGPATH_W) 'gdhcp/server.c'; else $(CYGPATH_W) '$(srcdir)/gdhcp/server.c'; fi`
+
+gdhcp/src_connmand-ipv4ll.o: gdhcp/ipv4ll.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT gdhcp/src_connmand-ipv4ll.o -MD -MP -MF gdhcp/$(DEPDIR)/src_connmand-ipv4ll.Tpo -c -o gdhcp/src_connmand-ipv4ll.o `test -f 'gdhcp/ipv4ll.c' || echo '$(srcdir)/'`gdhcp/ipv4ll.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) gdhcp/$(DEPDIR)/src_connmand-ipv4ll.Tpo gdhcp/$(DEPDIR)/src_connmand-ipv4ll.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='gdhcp/ipv4ll.c' object='gdhcp/src_connmand-ipv4ll.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o gdhcp/src_connmand-ipv4ll.o `test -f 'gdhcp/ipv4ll.c' || echo '$(srcdir)/'`gdhcp/ipv4ll.c
+
+gdhcp/src_connmand-ipv4ll.obj: gdhcp/ipv4ll.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT gdhcp/src_connmand-ipv4ll.obj -MD -MP -MF gdhcp/$(DEPDIR)/src_connmand-ipv4ll.Tpo -c -o gdhcp/src_connmand-ipv4ll.obj `if test -f 'gdhcp/ipv4ll.c'; then $(CYGPATH_W) 'gdhcp/ipv4ll.c'; else $(CYGPATH_W) '$(srcdir)/gdhcp/ipv4ll.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) gdhcp/$(DEPDIR)/src_connmand-ipv4ll.Tpo gdhcp/$(DEPDIR)/src_connmand-ipv4ll.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='gdhcp/ipv4ll.c' object='gdhcp/src_connmand-ipv4ll.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o gdhcp/src_connmand-ipv4ll.obj `if test -f 'gdhcp/ipv4ll.c'; then $(CYGPATH_W) 'gdhcp/ipv4ll.c'; else $(CYGPATH_W) '$(srcdir)/gdhcp/ipv4ll.c'; fi`
+
+gdhcp/src_connmand-timer.o: gdhcp/timer.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT gdhcp/src_connmand-timer.o -MD -MP -MF gdhcp/$(DEPDIR)/src_connmand-timer.Tpo -c -o gdhcp/src_connmand-timer.o `test -f 'gdhcp/timer.c' || echo '$(srcdir)/'`gdhcp/timer.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) gdhcp/$(DEPDIR)/src_connmand-timer.Tpo gdhcp/$(DEPDIR)/src_connmand-timer.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='gdhcp/timer.c' object='gdhcp/src_connmand-timer.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o gdhcp/src_connmand-timer.o `test -f 'gdhcp/timer.c' || echo '$(srcdir)/'`gdhcp/timer.c
+
+gdhcp/src_connmand-timer.obj: gdhcp/timer.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT gdhcp/src_connmand-timer.obj -MD -MP -MF gdhcp/$(DEPDIR)/src_connmand-timer.Tpo -c -o gdhcp/src_connmand-timer.obj `if test -f 'gdhcp/timer.c'; then $(CYGPATH_W) 'gdhcp/timer.c'; else $(CYGPATH_W) '$(srcdir)/gdhcp/timer.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) gdhcp/$(DEPDIR)/src_connmand-timer.Tpo gdhcp/$(DEPDIR)/src_connmand-timer.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='gdhcp/timer.c' object='gdhcp/src_connmand-timer.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o gdhcp/src_connmand-timer.obj `if test -f 'gdhcp/timer.c'; then $(CYGPATH_W) 'gdhcp/timer.c'; else $(CYGPATH_W) '$(srcdir)/gdhcp/timer.c'; fi`
+
+gweb/src_connmand-gweb.o: gweb/gweb.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT gweb/src_connmand-gweb.o -MD -MP -MF gweb/$(DEPDIR)/src_connmand-gweb.Tpo -c -o gweb/src_connmand-gweb.o `test -f 'gweb/gweb.c' || echo '$(srcdir)/'`gweb/gweb.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) gweb/$(DEPDIR)/src_connmand-gweb.Tpo gweb/$(DEPDIR)/src_connmand-gweb.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='gweb/gweb.c' object='gweb/src_connmand-gweb.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o gweb/src_connmand-gweb.o `test -f 'gweb/gweb.c' || echo '$(srcdir)/'`gweb/gweb.c
+
+gweb/src_connmand-gweb.obj: gweb/gweb.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT gweb/src_connmand-gweb.obj -MD -MP -MF gweb/$(DEPDIR)/src_connmand-gweb.Tpo -c -o gweb/src_connmand-gweb.obj `if test -f 'gweb/gweb.c'; then $(CYGPATH_W) 'gweb/gweb.c'; else $(CYGPATH_W) '$(srcdir)/gweb/gweb.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) gweb/$(DEPDIR)/src_connmand-gweb.Tpo gweb/$(DEPDIR)/src_connmand-gweb.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='gweb/gweb.c' object='gweb/src_connmand-gweb.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o gweb/src_connmand-gweb.obj `if test -f 'gweb/gweb.c'; then $(CYGPATH_W) 'gweb/gweb.c'; else $(CYGPATH_W) '$(srcdir)/gweb/gweb.c'; fi`
+
+gweb/src_connmand-gresolv.o: gweb/gresolv.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT gweb/src_connmand-gresolv.o -MD -MP -MF gweb/$(DEPDIR)/src_connmand-gresolv.Tpo -c -o gweb/src_connmand-gresolv.o `test -f 'gweb/gresolv.c' || echo '$(srcdir)/'`gweb/gresolv.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) gweb/$(DEPDIR)/src_connmand-gresolv.Tpo gweb/$(DEPDIR)/src_connmand-gresolv.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='gweb/gresolv.c' object='gweb/src_connmand-gresolv.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o gweb/src_connmand-gresolv.o `test -f 'gweb/gresolv.c' || echo '$(srcdir)/'`gweb/gresolv.c
+
+gweb/src_connmand-gresolv.obj: gweb/gresolv.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT gweb/src_connmand-gresolv.obj -MD -MP -MF gweb/$(DEPDIR)/src_connmand-gresolv.Tpo -c -o gweb/src_connmand-gresolv.obj `if test -f 'gweb/gresolv.c'; then $(CYGPATH_W) 'gweb/gresolv.c'; else $(CYGPATH_W) '$(srcdir)/gweb/gresolv.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) gweb/$(DEPDIR)/src_connmand-gresolv.Tpo gweb/$(DEPDIR)/src_connmand-gresolv.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='gweb/gresolv.c' object='gweb/src_connmand-gresolv.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o gweb/src_connmand-gresolv.obj `if test -f 'gweb/gresolv.c'; then $(CYGPATH_W) 'gweb/gresolv.c'; else $(CYGPATH_W) '$(srcdir)/gweb/gresolv.c'; fi`
+
+gweb/src_connmand-giognutls.o: gweb/giognutls.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT gweb/src_connmand-giognutls.o -MD -MP -MF gweb/$(DEPDIR)/src_connmand-giognutls.Tpo -c -o gweb/src_connmand-giognutls.o `test -f 'gweb/giognutls.c' || echo '$(srcdir)/'`gweb/giognutls.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) gweb/$(DEPDIR)/src_connmand-giognutls.Tpo gweb/$(DEPDIR)/src_connmand-giognutls.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='gweb/giognutls.c' object='gweb/src_connmand-giognutls.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o gweb/src_connmand-giognutls.o `test -f 'gweb/giognutls.c' || echo '$(srcdir)/'`gweb/giognutls.c
+
+gweb/src_connmand-giognutls.obj: gweb/giognutls.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT gweb/src_connmand-giognutls.obj -MD -MP -MF gweb/$(DEPDIR)/src_connmand-giognutls.Tpo -c -o gweb/src_connmand-giognutls.obj `if test -f 'gweb/giognutls.c'; then $(CYGPATH_W) 'gweb/giognutls.c'; else $(CYGPATH_W) '$(srcdir)/gweb/giognutls.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) gweb/$(DEPDIR)/src_connmand-giognutls.Tpo gweb/$(DEPDIR)/src_connmand-giognutls.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='gweb/giognutls.c' object='gweb/src_connmand-giognutls.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o gweb/src_connmand-giognutls.obj `if test -f 'gweb/giognutls.c'; then $(CYGPATH_W) 'gweb/giognutls.c'; else $(CYGPATH_W) '$(srcdir)/gweb/giognutls.c'; fi`
+
+gweb/src_connmand-gionotls.o: gweb/gionotls.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT gweb/src_connmand-gionotls.o -MD -MP -MF gweb/$(DEPDIR)/src_connmand-gionotls.Tpo -c -o gweb/src_connmand-gionotls.o `test -f 'gweb/gionotls.c' || echo '$(srcdir)/'`gweb/gionotls.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) gweb/$(DEPDIR)/src_connmand-gionotls.Tpo gweb/$(DEPDIR)/src_connmand-gionotls.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='gweb/gionotls.c' object='gweb/src_connmand-gionotls.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o gweb/src_connmand-gionotls.o `test -f 'gweb/gionotls.c' || echo '$(srcdir)/'`gweb/gionotls.c
+
+gweb/src_connmand-gionotls.obj: gweb/gionotls.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT gweb/src_connmand-gionotls.obj -MD -MP -MF gweb/$(DEPDIR)/src_connmand-gionotls.Tpo -c -o gweb/src_connmand-gionotls.obj `if test -f 'gweb/gionotls.c'; then $(CYGPATH_W) 'gweb/gionotls.c'; else $(CYGPATH_W) '$(srcdir)/gweb/gionotls.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) gweb/$(DEPDIR)/src_connmand-gionotls.Tpo gweb/$(DEPDIR)/src_connmand-gionotls.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='gweb/gionotls.c' object='gweb/src_connmand-gionotls.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o gweb/src_connmand-gionotls.obj `if test -f 'gweb/gionotls.c'; then $(CYGPATH_W) 'gweb/gionotls.c'; else $(CYGPATH_W) '$(srcdir)/gweb/gionotls.c'; fi`
+
+plugins/src_connmand-loopback.o: plugins/loopback.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT plugins/src_connmand-loopback.o -MD -MP -MF plugins/$(DEPDIR)/src_connmand-loopback.Tpo -c -o plugins/src_connmand-loopback.o `test -f 'plugins/loopback.c' || echo '$(srcdir)/'`plugins/loopback.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) plugins/$(DEPDIR)/src_connmand-loopback.Tpo plugins/$(DEPDIR)/src_connmand-loopback.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='plugins/loopback.c' object='plugins/src_connmand-loopback.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o plugins/src_connmand-loopback.o `test -f 'plugins/loopback.c' || echo '$(srcdir)/'`plugins/loopback.c
+
+plugins/src_connmand-loopback.obj: plugins/loopback.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT plugins/src_connmand-loopback.obj -MD -MP -MF plugins/$(DEPDIR)/src_connmand-loopback.Tpo -c -o plugins/src_connmand-loopback.obj `if test -f 'plugins/loopback.c'; then $(CYGPATH_W) 'plugins/loopback.c'; else $(CYGPATH_W) '$(srcdir)/plugins/loopback.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) plugins/$(DEPDIR)/src_connmand-loopback.Tpo plugins/$(DEPDIR)/src_connmand-loopback.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='plugins/loopback.c' object='plugins/src_connmand-loopback.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o plugins/src_connmand-loopback.obj `if test -f 'plugins/loopback.c'; then $(CYGPATH_W) 'plugins/loopback.c'; else $(CYGPATH_W) '$(srcdir)/plugins/loopback.c'; fi`
+
+plugins/src_connmand-ethernet.o: plugins/ethernet.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT plugins/src_connmand-ethernet.o -MD -MP -MF plugins/$(DEPDIR)/src_connmand-ethernet.Tpo -c -o plugins/src_connmand-ethernet.o `test -f 'plugins/ethernet.c' || echo '$(srcdir)/'`plugins/ethernet.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) plugins/$(DEPDIR)/src_connmand-ethernet.Tpo plugins/$(DEPDIR)/src_connmand-ethernet.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='plugins/ethernet.c' object='plugins/src_connmand-ethernet.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o plugins/src_connmand-ethernet.o `test -f 'plugins/ethernet.c' || echo '$(srcdir)/'`plugins/ethernet.c
+
+plugins/src_connmand-ethernet.obj: plugins/ethernet.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT plugins/src_connmand-ethernet.obj -MD -MP -MF plugins/$(DEPDIR)/src_connmand-ethernet.Tpo -c -o plugins/src_connmand-ethernet.obj `if test -f 'plugins/ethernet.c'; then $(CYGPATH_W) 'plugins/ethernet.c'; else $(CYGPATH_W) '$(srcdir)/plugins/ethernet.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) plugins/$(DEPDIR)/src_connmand-ethernet.Tpo plugins/$(DEPDIR)/src_connmand-ethernet.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='plugins/ethernet.c' object='plugins/src_connmand-ethernet.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o plugins/src_connmand-ethernet.obj `if test -f 'plugins/ethernet.c'; then $(CYGPATH_W) 'plugins/ethernet.c'; else $(CYGPATH_W) '$(srcdir)/plugins/ethernet.c'; fi`
+
+plugins/src_connmand-gadget.o: plugins/gadget.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT plugins/src_connmand-gadget.o -MD -MP -MF plugins/$(DEPDIR)/src_connmand-gadget.Tpo -c -o plugins/src_connmand-gadget.o `test -f 'plugins/gadget.c' || echo '$(srcdir)/'`plugins/gadget.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) plugins/$(DEPDIR)/src_connmand-gadget.Tpo plugins/$(DEPDIR)/src_connmand-gadget.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='plugins/gadget.c' object='plugins/src_connmand-gadget.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o plugins/src_connmand-gadget.o `test -f 'plugins/gadget.c' || echo '$(srcdir)/'`plugins/gadget.c
+
+plugins/src_connmand-gadget.obj: plugins/gadget.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT plugins/src_connmand-gadget.obj -MD -MP -MF plugins/$(DEPDIR)/src_connmand-gadget.Tpo -c -o plugins/src_connmand-gadget.obj `if test -f 'plugins/gadget.c'; then $(CYGPATH_W) 'plugins/gadget.c'; else $(CYGPATH_W) '$(srcdir)/plugins/gadget.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) plugins/$(DEPDIR)/src_connmand-gadget.Tpo plugins/$(DEPDIR)/src_connmand-gadget.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='plugins/gadget.c' object='plugins/src_connmand-gadget.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o plugins/src_connmand-gadget.obj `if test -f 'plugins/gadget.c'; then $(CYGPATH_W) 'plugins/gadget.c'; else $(CYGPATH_W) '$(srcdir)/plugins/gadget.c'; fi`
+
+plugins/src_connmand-wifi.o: plugins/wifi.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT plugins/src_connmand-wifi.o -MD -MP -MF plugins/$(DEPDIR)/src_connmand-wifi.Tpo -c -o plugins/src_connmand-wifi.o `test -f 'plugins/wifi.c' || echo '$(srcdir)/'`plugins/wifi.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) plugins/$(DEPDIR)/src_connmand-wifi.Tpo plugins/$(DEPDIR)/src_connmand-wifi.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='plugins/wifi.c' object='plugins/src_connmand-wifi.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o plugins/src_connmand-wifi.o `test -f 'plugins/wifi.c' || echo '$(srcdir)/'`plugins/wifi.c
+
+plugins/src_connmand-wifi.obj: plugins/wifi.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT plugins/src_connmand-wifi.obj -MD -MP -MF plugins/$(DEPDIR)/src_connmand-wifi.Tpo -c -o plugins/src_connmand-wifi.obj `if test -f 'plugins/wifi.c'; then $(CYGPATH_W) 'plugins/wifi.c'; else $(CYGPATH_W) '$(srcdir)/plugins/wifi.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) plugins/$(DEPDIR)/src_connmand-wifi.Tpo plugins/$(DEPDIR)/src_connmand-wifi.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='plugins/wifi.c' object='plugins/src_connmand-wifi.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o plugins/src_connmand-wifi.obj `if test -f 'plugins/wifi.c'; then $(CYGPATH_W) 'plugins/wifi.c'; else $(CYGPATH_W) '$(srcdir)/plugins/wifi.c'; fi`
+
+gsupplicant/src_connmand-supplicant.o: gsupplicant/supplicant.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT gsupplicant/src_connmand-supplicant.o -MD -MP -MF gsupplicant/$(DEPDIR)/src_connmand-supplicant.Tpo -c -o gsupplicant/src_connmand-supplicant.o `test -f 'gsupplicant/supplicant.c' || echo '$(srcdir)/'`gsupplicant/supplicant.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) gsupplicant/$(DEPDIR)/src_connmand-supplicant.Tpo gsupplicant/$(DEPDIR)/src_connmand-supplicant.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='gsupplicant/supplicant.c' object='gsupplicant/src_connmand-supplicant.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o gsupplicant/src_connmand-supplicant.o `test -f 'gsupplicant/supplicant.c' || echo '$(srcdir)/'`gsupplicant/supplicant.c
+
+gsupplicant/src_connmand-supplicant.obj: gsupplicant/supplicant.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT gsupplicant/src_connmand-supplicant.obj -MD -MP -MF gsupplicant/$(DEPDIR)/src_connmand-supplicant.Tpo -c -o gsupplicant/src_connmand-supplicant.obj `if test -f 'gsupplicant/supplicant.c'; then $(CYGPATH_W) 'gsupplicant/supplicant.c'; else $(CYGPATH_W) '$(srcdir)/gsupplicant/supplicant.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) gsupplicant/$(DEPDIR)/src_connmand-supplicant.Tpo gsupplicant/$(DEPDIR)/src_connmand-supplicant.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='gsupplicant/supplicant.c' object='gsupplicant/src_connmand-supplicant.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o gsupplicant/src_connmand-supplicant.obj `if test -f 'gsupplicant/supplicant.c'; then $(CYGPATH_W) 'gsupplicant/supplicant.c'; else $(CYGPATH_W) '$(srcdir)/gsupplicant/supplicant.c'; fi`
+
+gsupplicant/src_connmand-dbus.o: gsupplicant/dbus.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT gsupplicant/src_connmand-dbus.o -MD -MP -MF gsupplicant/$(DEPDIR)/src_connmand-dbus.Tpo -c -o gsupplicant/src_connmand-dbus.o `test -f 'gsupplicant/dbus.c' || echo '$(srcdir)/'`gsupplicant/dbus.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) gsupplicant/$(DEPDIR)/src_connmand-dbus.Tpo gsupplicant/$(DEPDIR)/src_connmand-dbus.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='gsupplicant/dbus.c' object='gsupplicant/src_connmand-dbus.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o gsupplicant/src_connmand-dbus.o `test -f 'gsupplicant/dbus.c' || echo '$(srcdir)/'`gsupplicant/dbus.c
+
+gsupplicant/src_connmand-dbus.obj: gsupplicant/dbus.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT gsupplicant/src_connmand-dbus.obj -MD -MP -MF gsupplicant/$(DEPDIR)/src_connmand-dbus.Tpo -c -o gsupplicant/src_connmand-dbus.obj `if test -f 'gsupplicant/dbus.c'; then $(CYGPATH_W) 'gsupplicant/dbus.c'; else $(CYGPATH_W) '$(srcdir)/gsupplicant/dbus.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) gsupplicant/$(DEPDIR)/src_connmand-dbus.Tpo gsupplicant/$(DEPDIR)/src_connmand-dbus.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='gsupplicant/dbus.c' object='gsupplicant/src_connmand-dbus.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o gsupplicant/src_connmand-dbus.obj `if test -f 'gsupplicant/dbus.c'; then $(CYGPATH_W) 'gsupplicant/dbus.c'; else $(CYGPATH_W) '$(srcdir)/gsupplicant/dbus.c'; fi`
+
+plugins/src_connmand-bluetooth_legacy.o: plugins/bluetooth_legacy.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT plugins/src_connmand-bluetooth_legacy.o -MD -MP -MF plugins/$(DEPDIR)/src_connmand-bluetooth_legacy.Tpo -c -o plugins/src_connmand-bluetooth_legacy.o `test -f 'plugins/bluetooth_legacy.c' || echo '$(srcdir)/'`plugins/bluetooth_legacy.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) plugins/$(DEPDIR)/src_connmand-bluetooth_legacy.Tpo plugins/$(DEPDIR)/src_connmand-bluetooth_legacy.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='plugins/bluetooth_legacy.c' object='plugins/src_connmand-bluetooth_legacy.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o plugins/src_connmand-bluetooth_legacy.o `test -f 'plugins/bluetooth_legacy.c' || echo '$(srcdir)/'`plugins/bluetooth_legacy.c
+
+plugins/src_connmand-bluetooth_legacy.obj: plugins/bluetooth_legacy.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT plugins/src_connmand-bluetooth_legacy.obj -MD -MP -MF plugins/$(DEPDIR)/src_connmand-bluetooth_legacy.Tpo -c -o plugins/src_connmand-bluetooth_legacy.obj `if test -f 'plugins/bluetooth_legacy.c'; then $(CYGPATH_W) 'plugins/bluetooth_legacy.c'; else $(CYGPATH_W) '$(srcdir)/plugins/bluetooth_legacy.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) plugins/$(DEPDIR)/src_connmand-bluetooth_legacy.Tpo plugins/$(DEPDIR)/src_connmand-bluetooth_legacy.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='plugins/bluetooth_legacy.c' object='plugins/src_connmand-bluetooth_legacy.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o plugins/src_connmand-bluetooth_legacy.obj `if test -f 'plugins/bluetooth_legacy.c'; then $(CYGPATH_W) 'plugins/bluetooth_legacy.c'; else $(CYGPATH_W) '$(srcdir)/plugins/bluetooth_legacy.c'; fi`
+
+plugins/src_connmand-bluetooth.o: plugins/bluetooth.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT plugins/src_connmand-bluetooth.o -MD -MP -MF plugins/$(DEPDIR)/src_connmand-bluetooth.Tpo -c -o plugins/src_connmand-bluetooth.o `test -f 'plugins/bluetooth.c' || echo '$(srcdir)/'`plugins/bluetooth.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) plugins/$(DEPDIR)/src_connmand-bluetooth.Tpo plugins/$(DEPDIR)/src_connmand-bluetooth.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='plugins/bluetooth.c' object='plugins/src_connmand-bluetooth.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o plugins/src_connmand-bluetooth.o `test -f 'plugins/bluetooth.c' || echo '$(srcdir)/'`plugins/bluetooth.c
+
+plugins/src_connmand-bluetooth.obj: plugins/bluetooth.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT plugins/src_connmand-bluetooth.obj -MD -MP -MF plugins/$(DEPDIR)/src_connmand-bluetooth.Tpo -c -o plugins/src_connmand-bluetooth.obj `if test -f 'plugins/bluetooth.c'; then $(CYGPATH_W) 'plugins/bluetooth.c'; else $(CYGPATH_W) '$(srcdir)/plugins/bluetooth.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) plugins/$(DEPDIR)/src_connmand-bluetooth.Tpo plugins/$(DEPDIR)/src_connmand-bluetooth.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='plugins/bluetooth.c' object='plugins/src_connmand-bluetooth.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o plugins/src_connmand-bluetooth.obj `if test -f 'plugins/bluetooth.c'; then $(CYGPATH_W) 'plugins/bluetooth.c'; else $(CYGPATH_W) '$(srcdir)/plugins/bluetooth.c'; fi`
+
+plugins/src_connmand-hh2serial-gps.o: plugins/hh2serial-gps.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT plugins/src_connmand-hh2serial-gps.o -MD -MP -MF plugins/$(DEPDIR)/src_connmand-hh2serial-gps.Tpo -c -o plugins/src_connmand-hh2serial-gps.o `test -f 'plugins/hh2serial-gps.c' || echo '$(srcdir)/'`plugins/hh2serial-gps.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) plugins/$(DEPDIR)/src_connmand-hh2serial-gps.Tpo plugins/$(DEPDIR)/src_connmand-hh2serial-gps.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='plugins/hh2serial-gps.c' object='plugins/src_connmand-hh2serial-gps.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o plugins/src_connmand-hh2serial-gps.o `test -f 'plugins/hh2serial-gps.c' || echo '$(srcdir)/'`plugins/hh2serial-gps.c
+
+plugins/src_connmand-hh2serial-gps.obj: plugins/hh2serial-gps.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT plugins/src_connmand-hh2serial-gps.obj -MD -MP -MF plugins/$(DEPDIR)/src_connmand-hh2serial-gps.Tpo -c -o plugins/src_connmand-hh2serial-gps.obj `if test -f 'plugins/hh2serial-gps.c'; then $(CYGPATH_W) 'plugins/hh2serial-gps.c'; else $(CYGPATH_W) '$(srcdir)/plugins/hh2serial-gps.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) plugins/$(DEPDIR)/src_connmand-hh2serial-gps.Tpo plugins/$(DEPDIR)/src_connmand-hh2serial-gps.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='plugins/hh2serial-gps.c' object='plugins/src_connmand-hh2serial-gps.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o plugins/src_connmand-hh2serial-gps.obj `if test -f 'plugins/hh2serial-gps.c'; then $(CYGPATH_W) 'plugins/hh2serial-gps.c'; else $(CYGPATH_W) '$(srcdir)/plugins/hh2serial-gps.c'; fi`
+
+plugins/src_connmand-ofono.o: plugins/ofono.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT plugins/src_connmand-ofono.o -MD -MP -MF plugins/$(DEPDIR)/src_connmand-ofono.Tpo -c -o plugins/src_connmand-ofono.o `test -f 'plugins/ofono.c' || echo '$(srcdir)/'`plugins/ofono.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) plugins/$(DEPDIR)/src_connmand-ofono.Tpo plugins/$(DEPDIR)/src_connmand-ofono.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='plugins/ofono.c' object='plugins/src_connmand-ofono.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o plugins/src_connmand-ofono.o `test -f 'plugins/ofono.c' || echo '$(srcdir)/'`plugins/ofono.c
+
+plugins/src_connmand-ofono.obj: plugins/ofono.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT plugins/src_connmand-ofono.obj -MD -MP -MF plugins/$(DEPDIR)/src_connmand-ofono.Tpo -c -o plugins/src_connmand-ofono.obj `if test -f 'plugins/ofono.c'; then $(CYGPATH_W) 'plugins/ofono.c'; else $(CYGPATH_W) '$(srcdir)/plugins/ofono.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) plugins/$(DEPDIR)/src_connmand-ofono.Tpo plugins/$(DEPDIR)/src_connmand-ofono.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='plugins/ofono.c' object='plugins/src_connmand-ofono.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o plugins/src_connmand-ofono.obj `if test -f 'plugins/ofono.c'; then $(CYGPATH_W) 'plugins/ofono.c'; else $(CYGPATH_W) '$(srcdir)/plugins/ofono.c'; fi`
+
+plugins/src_connmand-dundee.o: plugins/dundee.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT plugins/src_connmand-dundee.o -MD -MP -MF plugins/$(DEPDIR)/src_connmand-dundee.Tpo -c -o plugins/src_connmand-dundee.o `test -f 'plugins/dundee.c' || echo '$(srcdir)/'`plugins/dundee.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) plugins/$(DEPDIR)/src_connmand-dundee.Tpo plugins/$(DEPDIR)/src_connmand-dundee.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='plugins/dundee.c' object='plugins/src_connmand-dundee.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o plugins/src_connmand-dundee.o `test -f 'plugins/dundee.c' || echo '$(srcdir)/'`plugins/dundee.c
+
+plugins/src_connmand-dundee.obj: plugins/dundee.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT plugins/src_connmand-dundee.obj -MD -MP -MF plugins/$(DEPDIR)/src_connmand-dundee.Tpo -c -o plugins/src_connmand-dundee.obj `if test -f 'plugins/dundee.c'; then $(CYGPATH_W) 'plugins/dundee.c'; else $(CYGPATH_W) '$(srcdir)/plugins/dundee.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) plugins/$(DEPDIR)/src_connmand-dundee.Tpo plugins/$(DEPDIR)/src_connmand-dundee.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='plugins/dundee.c' object='plugins/src_connmand-dundee.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o plugins/src_connmand-dundee.obj `if test -f 'plugins/dundee.c'; then $(CYGPATH_W) 'plugins/dundee.c'; else $(CYGPATH_W) '$(srcdir)/plugins/dundee.c'; fi`
+
+plugins/src_connmand-vpn.o: plugins/vpn.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT plugins/src_connmand-vpn.o -MD -MP -MF plugins/$(DEPDIR)/src_connmand-vpn.Tpo -c -o plugins/src_connmand-vpn.o `test -f 'plugins/vpn.c' || echo '$(srcdir)/'`plugins/vpn.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) plugins/$(DEPDIR)/src_connmand-vpn.Tpo plugins/$(DEPDIR)/src_connmand-vpn.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='plugins/vpn.c' object='plugins/src_connmand-vpn.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o plugins/src_connmand-vpn.o `test -f 'plugins/vpn.c' || echo '$(srcdir)/'`plugins/vpn.c
+
+plugins/src_connmand-vpn.obj: plugins/vpn.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT plugins/src_connmand-vpn.obj -MD -MP -MF plugins/$(DEPDIR)/src_connmand-vpn.Tpo -c -o plugins/src_connmand-vpn.obj `if test -f 'plugins/vpn.c'; then $(CYGPATH_W) 'plugins/vpn.c'; else $(CYGPATH_W) '$(srcdir)/plugins/vpn.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) plugins/$(DEPDIR)/src_connmand-vpn.Tpo plugins/$(DEPDIR)/src_connmand-vpn.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='plugins/vpn.c' object='plugins/src_connmand-vpn.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o plugins/src_connmand-vpn.obj `if test -f 'plugins/vpn.c'; then $(CYGPATH_W) 'plugins/vpn.c'; else $(CYGPATH_W) '$(srcdir)/plugins/vpn.c'; fi`
+
+plugins/src_connmand-pacrunner.o: plugins/pacrunner.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT plugins/src_connmand-pacrunner.o -MD -MP -MF plugins/$(DEPDIR)/src_connmand-pacrunner.Tpo -c -o plugins/src_connmand-pacrunner.o `test -f 'plugins/pacrunner.c' || echo '$(srcdir)/'`plugins/pacrunner.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) plugins/$(DEPDIR)/src_connmand-pacrunner.Tpo plugins/$(DEPDIR)/src_connmand-pacrunner.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='plugins/pacrunner.c' object='plugins/src_connmand-pacrunner.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o plugins/src_connmand-pacrunner.o `test -f 'plugins/pacrunner.c' || echo '$(srcdir)/'`plugins/pacrunner.c
+
+plugins/src_connmand-pacrunner.obj: plugins/pacrunner.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT plugins/src_connmand-pacrunner.obj -MD -MP -MF plugins/$(DEPDIR)/src_connmand-pacrunner.Tpo -c -o plugins/src_connmand-pacrunner.obj `if test -f 'plugins/pacrunner.c'; then $(CYGPATH_W) 'plugins/pacrunner.c'; else $(CYGPATH_W) '$(srcdir)/plugins/pacrunner.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) plugins/$(DEPDIR)/src_connmand-pacrunner.Tpo plugins/$(DEPDIR)/src_connmand-pacrunner.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='plugins/pacrunner.c' object='plugins/src_connmand-pacrunner.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o plugins/src_connmand-pacrunner.obj `if test -f 'plugins/pacrunner.c'; then $(CYGPATH_W) 'plugins/pacrunner.c'; else $(CYGPATH_W) '$(srcdir)/plugins/pacrunner.c'; fi`
+
+plugins/src_connmand-polkit.o: plugins/polkit.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT plugins/src_connmand-polkit.o -MD -MP -MF plugins/$(DEPDIR)/src_connmand-polkit.Tpo -c -o plugins/src_connmand-polkit.o `test -f 'plugins/polkit.c' || echo '$(srcdir)/'`plugins/polkit.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) plugins/$(DEPDIR)/src_connmand-polkit.Tpo plugins/$(DEPDIR)/src_connmand-polkit.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='plugins/polkit.c' object='plugins/src_connmand-polkit.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o plugins/src_connmand-polkit.o `test -f 'plugins/polkit.c' || echo '$(srcdir)/'`plugins/polkit.c
+
+plugins/src_connmand-polkit.obj: plugins/polkit.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT plugins/src_connmand-polkit.obj -MD -MP -MF plugins/$(DEPDIR)/src_connmand-polkit.Tpo -c -o plugins/src_connmand-polkit.obj `if test -f 'plugins/polkit.c'; then $(CYGPATH_W) 'plugins/polkit.c'; else $(CYGPATH_W) '$(srcdir)/plugins/polkit.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) plugins/$(DEPDIR)/src_connmand-polkit.Tpo plugins/$(DEPDIR)/src_connmand-polkit.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='plugins/polkit.c' object='plugins/src_connmand-polkit.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o plugins/src_connmand-polkit.obj `if test -f 'plugins/polkit.c'; then $(CYGPATH_W) 'plugins/polkit.c'; else $(CYGPATH_W) '$(srcdir)/plugins/polkit.c'; fi`
+
+plugins/src_connmand-nmcompat.o: plugins/nmcompat.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT plugins/src_connmand-nmcompat.o -MD -MP -MF plugins/$(DEPDIR)/src_connmand-nmcompat.Tpo -c -o plugins/src_connmand-nmcompat.o `test -f 'plugins/nmcompat.c' || echo '$(srcdir)/'`plugins/nmcompat.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) plugins/$(DEPDIR)/src_connmand-nmcompat.Tpo plugins/$(DEPDIR)/src_connmand-nmcompat.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='plugins/nmcompat.c' object='plugins/src_connmand-nmcompat.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o plugins/src_connmand-nmcompat.o `test -f 'plugins/nmcompat.c' || echo '$(srcdir)/'`plugins/nmcompat.c
+
+plugins/src_connmand-nmcompat.obj: plugins/nmcompat.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT plugins/src_connmand-nmcompat.obj -MD -MP -MF plugins/$(DEPDIR)/src_connmand-nmcompat.Tpo -c -o plugins/src_connmand-nmcompat.obj `if test -f 'plugins/nmcompat.c'; then $(CYGPATH_W) 'plugins/nmcompat.c'; else $(CYGPATH_W) '$(srcdir)/plugins/nmcompat.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) plugins/$(DEPDIR)/src_connmand-nmcompat.Tpo plugins/$(DEPDIR)/src_connmand-nmcompat.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='plugins/nmcompat.c' object='plugins/src_connmand-nmcompat.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o plugins/src_connmand-nmcompat.obj `if test -f 'plugins/nmcompat.c'; then $(CYGPATH_W) 'plugins/nmcompat.c'; else $(CYGPATH_W) '$(srcdir)/plugins/nmcompat.c'; fi`
+
+plugins/src_connmand-tist.o: plugins/tist.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT plugins/src_connmand-tist.o -MD -MP -MF plugins/$(DEPDIR)/src_connmand-tist.Tpo -c -o plugins/src_connmand-tist.o `test -f 'plugins/tist.c' || echo '$(srcdir)/'`plugins/tist.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) plugins/$(DEPDIR)/src_connmand-tist.Tpo plugins/$(DEPDIR)/src_connmand-tist.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='plugins/tist.c' object='plugins/src_connmand-tist.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o plugins/src_connmand-tist.o `test -f 'plugins/tist.c' || echo '$(srcdir)/'`plugins/tist.c
+
+plugins/src_connmand-tist.obj: plugins/tist.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT plugins/src_connmand-tist.obj -MD -MP -MF plugins/$(DEPDIR)/src_connmand-tist.Tpo -c -o plugins/src_connmand-tist.obj `if test -f 'plugins/tist.c'; then $(CYGPATH_W) 'plugins/tist.c'; else $(CYGPATH_W) '$(srcdir)/plugins/tist.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) plugins/$(DEPDIR)/src_connmand-tist.Tpo plugins/$(DEPDIR)/src_connmand-tist.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='plugins/tist.c' object='plugins/src_connmand-tist.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o plugins/src_connmand-tist.obj `if test -f 'plugins/tist.c'; then $(CYGPATH_W) 'plugins/tist.c'; else $(CYGPATH_W) '$(srcdir)/plugins/tist.c'; fi`
+
+plugins/src_connmand-session_policy_local.o: plugins/session_policy_local.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT plugins/src_connmand-session_policy_local.o -MD -MP -MF plugins/$(DEPDIR)/src_connmand-session_policy_local.Tpo -c -o plugins/src_connmand-session_policy_local.o `test -f 'plugins/session_policy_local.c' || echo '$(srcdir)/'`plugins/session_policy_local.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) plugins/$(DEPDIR)/src_connmand-session_policy_local.Tpo plugins/$(DEPDIR)/src_connmand-session_policy_local.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='plugins/session_policy_local.c' object='plugins/src_connmand-session_policy_local.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o plugins/src_connmand-session_policy_local.o `test -f 'plugins/session_policy_local.c' || echo '$(srcdir)/'`plugins/session_policy_local.c
+
+plugins/src_connmand-session_policy_local.obj: plugins/session_policy_local.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT plugins/src_connmand-session_policy_local.obj -MD -MP -MF plugins/$(DEPDIR)/src_connmand-session_policy_local.Tpo -c -o plugins/src_connmand-session_policy_local.obj `if test -f 'plugins/session_policy_local.c'; then $(CYGPATH_W) 'plugins/session_policy_local.c'; else $(CYGPATH_W) '$(srcdir)/plugins/session_policy_local.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) plugins/$(DEPDIR)/src_connmand-session_policy_local.Tpo plugins/$(DEPDIR)/src_connmand-session_policy_local.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='plugins/session_policy_local.c' object='plugins/src_connmand-session_policy_local.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o plugins/src_connmand-session_policy_local.obj `if test -f 'plugins/session_policy_local.c'; then $(CYGPATH_W) 'plugins/session_policy_local.c'; else $(CYGPATH_W) '$(srcdir)/plugins/session_policy_local.c'; fi`
+
+plugins/src_connmand-neard.o: plugins/neard.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT plugins/src_connmand-neard.o -MD -MP -MF plugins/$(DEPDIR)/src_connmand-neard.Tpo -c -o plugins/src_connmand-neard.o `test -f 'plugins/neard.c' || echo '$(srcdir)/'`plugins/neard.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) plugins/$(DEPDIR)/src_connmand-neard.Tpo plugins/$(DEPDIR)/src_connmand-neard.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='plugins/neard.c' object='plugins/src_connmand-neard.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o plugins/src_connmand-neard.o `test -f 'plugins/neard.c' || echo '$(srcdir)/'`plugins/neard.c
+
+plugins/src_connmand-neard.obj: plugins/neard.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT plugins/src_connmand-neard.obj -MD -MP -MF plugins/$(DEPDIR)/src_connmand-neard.Tpo -c -o plugins/src_connmand-neard.obj `if test -f 'plugins/neard.c'; then $(CYGPATH_W) 'plugins/neard.c'; else $(CYGPATH_W) '$(srcdir)/plugins/neard.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) plugins/$(DEPDIR)/src_connmand-neard.Tpo plugins/$(DEPDIR)/src_connmand-neard.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='plugins/neard.c' object='plugins/src_connmand-neard.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o plugins/src_connmand-neard.obj `if test -f 'plugins/neard.c'; then $(CYGPATH_W) 'plugins/neard.c'; else $(CYGPATH_W) '$(srcdir)/plugins/neard.c'; fi`
+
+src/shared/src_connmand-util.o: src/shared/util.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/shared/src_connmand-util.o -MD -MP -MF src/shared/$(DEPDIR)/src_connmand-util.Tpo -c -o src/shared/src_connmand-util.o `test -f 'src/shared/util.c' || echo '$(srcdir)/'`src/shared/util.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/shared/$(DEPDIR)/src_connmand-util.Tpo src/shared/$(DEPDIR)/src_connmand-util.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/shared/util.c' object='src/shared/src_connmand-util.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/shared/src_connmand-util.o `test -f 'src/shared/util.c' || echo '$(srcdir)/'`src/shared/util.c
+
+src/shared/src_connmand-util.obj: src/shared/util.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/shared/src_connmand-util.obj -MD -MP -MF src/shared/$(DEPDIR)/src_connmand-util.Tpo -c -o src/shared/src_connmand-util.obj `if test -f 'src/shared/util.c'; then $(CYGPATH_W) 'src/shared/util.c'; else $(CYGPATH_W) '$(srcdir)/src/shared/util.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/shared/$(DEPDIR)/src_connmand-util.Tpo src/shared/$(DEPDIR)/src_connmand-util.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/shared/util.c' object='src/shared/src_connmand-util.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/shared/src_connmand-util.obj `if test -f 'src/shared/util.c'; then $(CYGPATH_W) 'src/shared/util.c'; else $(CYGPATH_W) '$(srcdir)/src/shared/util.c'; fi`
+
+src/shared/src_connmand-netlink.o: src/shared/netlink.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/shared/src_connmand-netlink.o -MD -MP -MF src/shared/$(DEPDIR)/src_connmand-netlink.Tpo -c -o src/shared/src_connmand-netlink.o `test -f 'src/shared/netlink.c' || echo '$(srcdir)/'`src/shared/netlink.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/shared/$(DEPDIR)/src_connmand-netlink.Tpo src/shared/$(DEPDIR)/src_connmand-netlink.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/shared/netlink.c' object='src/shared/src_connmand-netlink.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/shared/src_connmand-netlink.o `test -f 'src/shared/netlink.c' || echo '$(srcdir)/'`src/shared/netlink.c
+
+src/shared/src_connmand-netlink.obj: src/shared/netlink.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/shared/src_connmand-netlink.obj -MD -MP -MF src/shared/$(DEPDIR)/src_connmand-netlink.Tpo -c -o src/shared/src_connmand-netlink.obj `if test -f 'src/shared/netlink.c'; then $(CYGPATH_W) 'src/shared/netlink.c'; else $(CYGPATH_W) '$(srcdir)/src/shared/netlink.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/shared/$(DEPDIR)/src_connmand-netlink.Tpo src/shared/$(DEPDIR)/src_connmand-netlink.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/shared/netlink.c' object='src/shared/src_connmand-netlink.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/shared/src_connmand-netlink.obj `if test -f 'src/shared/netlink.c'; then $(CYGPATH_W) 'src/shared/netlink.c'; else $(CYGPATH_W) '$(srcdir)/src/shared/netlink.c'; fi`
+
+src/src_connmand-main.o: src/main.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-main.o -MD -MP -MF src/$(DEPDIR)/src_connmand-main.Tpo -c -o src/src_connmand-main.o `test -f 'src/main.c' || echo '$(srcdir)/'`src/main.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-main.Tpo src/$(DEPDIR)/src_connmand-main.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/main.c' object='src/src_connmand-main.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-main.o `test -f 'src/main.c' || echo '$(srcdir)/'`src/main.c
+
+src/src_connmand-main.obj: src/main.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-main.obj -MD -MP -MF src/$(DEPDIR)/src_connmand-main.Tpo -c -o src/src_connmand-main.obj `if test -f 'src/main.c'; then $(CYGPATH_W) 'src/main.c'; else $(CYGPATH_W) '$(srcdir)/src/main.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-main.Tpo src/$(DEPDIR)/src_connmand-main.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/main.c' object='src/src_connmand-main.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-main.obj `if test -f 'src/main.c'; then $(CYGPATH_W) 'src/main.c'; else $(CYGPATH_W) '$(srcdir)/src/main.c'; fi`
+
+src/src_connmand-log.o: src/log.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-log.o -MD -MP -MF src/$(DEPDIR)/src_connmand-log.Tpo -c -o src/src_connmand-log.o `test -f 'src/log.c' || echo '$(srcdir)/'`src/log.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-log.Tpo src/$(DEPDIR)/src_connmand-log.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/log.c' object='src/src_connmand-log.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-log.o `test -f 'src/log.c' || echo '$(srcdir)/'`src/log.c
+
+src/src_connmand-log.obj: src/log.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-log.obj -MD -MP -MF src/$(DEPDIR)/src_connmand-log.Tpo -c -o src/src_connmand-log.obj `if test -f 'src/log.c'; then $(CYGPATH_W) 'src/log.c'; else $(CYGPATH_W) '$(srcdir)/src/log.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-log.Tpo src/$(DEPDIR)/src_connmand-log.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/log.c' object='src/src_connmand-log.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-log.obj `if test -f 'src/log.c'; then $(CYGPATH_W) 'src/log.c'; else $(CYGPATH_W) '$(srcdir)/src/log.c'; fi`
+
+src/src_connmand-error.o: src/error.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-error.o -MD -MP -MF src/$(DEPDIR)/src_connmand-error.Tpo -c -o src/src_connmand-error.o `test -f 'src/error.c' || echo '$(srcdir)/'`src/error.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-error.Tpo src/$(DEPDIR)/src_connmand-error.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/error.c' object='src/src_connmand-error.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-error.o `test -f 'src/error.c' || echo '$(srcdir)/'`src/error.c
+
+src/src_connmand-error.obj: src/error.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-error.obj -MD -MP -MF src/$(DEPDIR)/src_connmand-error.Tpo -c -o src/src_connmand-error.obj `if test -f 'src/error.c'; then $(CYGPATH_W) 'src/error.c'; else $(CYGPATH_W) '$(srcdir)/src/error.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-error.Tpo src/$(DEPDIR)/src_connmand-error.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/error.c' object='src/src_connmand-error.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-error.obj `if test -f 'src/error.c'; then $(CYGPATH_W) 'src/error.c'; else $(CYGPATH_W) '$(srcdir)/src/error.c'; fi`
+
+src/src_connmand-plugin.o: src/plugin.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-plugin.o -MD -MP -MF src/$(DEPDIR)/src_connmand-plugin.Tpo -c -o src/src_connmand-plugin.o `test -f 'src/plugin.c' || echo '$(srcdir)/'`src/plugin.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-plugin.Tpo src/$(DEPDIR)/src_connmand-plugin.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/plugin.c' object='src/src_connmand-plugin.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-plugin.o `test -f 'src/plugin.c' || echo '$(srcdir)/'`src/plugin.c
+
+src/src_connmand-plugin.obj: src/plugin.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-plugin.obj -MD -MP -MF src/$(DEPDIR)/src_connmand-plugin.Tpo -c -o src/src_connmand-plugin.obj `if test -f 'src/plugin.c'; then $(CYGPATH_W) 'src/plugin.c'; else $(CYGPATH_W) '$(srcdir)/src/plugin.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-plugin.Tpo src/$(DEPDIR)/src_connmand-plugin.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/plugin.c' object='src/src_connmand-plugin.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-plugin.obj `if test -f 'src/plugin.c'; then $(CYGPATH_W) 'src/plugin.c'; else $(CYGPATH_W) '$(srcdir)/src/plugin.c'; fi`
+
+src/src_connmand-task.o: src/task.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-task.o -MD -MP -MF src/$(DEPDIR)/src_connmand-task.Tpo -c -o src/src_connmand-task.o `test -f 'src/task.c' || echo '$(srcdir)/'`src/task.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-task.Tpo src/$(DEPDIR)/src_connmand-task.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/task.c' object='src/src_connmand-task.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-task.o `test -f 'src/task.c' || echo '$(srcdir)/'`src/task.c
+
+src/src_connmand-task.obj: src/task.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-task.obj -MD -MP -MF src/$(DEPDIR)/src_connmand-task.Tpo -c -o src/src_connmand-task.obj `if test -f 'src/task.c'; then $(CYGPATH_W) 'src/task.c'; else $(CYGPATH_W) '$(srcdir)/src/task.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-task.Tpo src/$(DEPDIR)/src_connmand-task.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/task.c' object='src/src_connmand-task.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-task.obj `if test -f 'src/task.c'; then $(CYGPATH_W) 'src/task.c'; else $(CYGPATH_W) '$(srcdir)/src/task.c'; fi`
+
+src/src_connmand-device.o: src/device.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-device.o -MD -MP -MF src/$(DEPDIR)/src_connmand-device.Tpo -c -o src/src_connmand-device.o `test -f 'src/device.c' || echo '$(srcdir)/'`src/device.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-device.Tpo src/$(DEPDIR)/src_connmand-device.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/device.c' object='src/src_connmand-device.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-device.o `test -f 'src/device.c' || echo '$(srcdir)/'`src/device.c
+
+src/src_connmand-device.obj: src/device.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-device.obj -MD -MP -MF src/$(DEPDIR)/src_connmand-device.Tpo -c -o src/src_connmand-device.obj `if test -f 'src/device.c'; then $(CYGPATH_W) 'src/device.c'; else $(CYGPATH_W) '$(srcdir)/src/device.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-device.Tpo src/$(DEPDIR)/src_connmand-device.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/device.c' object='src/src_connmand-device.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-device.obj `if test -f 'src/device.c'; then $(CYGPATH_W) 'src/device.c'; else $(CYGPATH_W) '$(srcdir)/src/device.c'; fi`
+
+src/src_connmand-network.o: src/network.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-network.o -MD -MP -MF src/$(DEPDIR)/src_connmand-network.Tpo -c -o src/src_connmand-network.o `test -f 'src/network.c' || echo '$(srcdir)/'`src/network.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-network.Tpo src/$(DEPDIR)/src_connmand-network.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/network.c' object='src/src_connmand-network.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-network.o `test -f 'src/network.c' || echo '$(srcdir)/'`src/network.c
+
+src/src_connmand-network.obj: src/network.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-network.obj -MD -MP -MF src/$(DEPDIR)/src_connmand-network.Tpo -c -o src/src_connmand-network.obj `if test -f 'src/network.c'; then $(CYGPATH_W) 'src/network.c'; else $(CYGPATH_W) '$(srcdir)/src/network.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-network.Tpo src/$(DEPDIR)/src_connmand-network.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/network.c' object='src/src_connmand-network.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-network.obj `if test -f 'src/network.c'; then $(CYGPATH_W) 'src/network.c'; else $(CYGPATH_W) '$(srcdir)/src/network.c'; fi`
+
+src/src_connmand-connection.o: src/connection.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-connection.o -MD -MP -MF src/$(DEPDIR)/src_connmand-connection.Tpo -c -o src/src_connmand-connection.o `test -f 'src/connection.c' || echo '$(srcdir)/'`src/connection.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-connection.Tpo src/$(DEPDIR)/src_connmand-connection.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/connection.c' object='src/src_connmand-connection.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-connection.o `test -f 'src/connection.c' || echo '$(srcdir)/'`src/connection.c
+
+src/src_connmand-connection.obj: src/connection.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-connection.obj -MD -MP -MF src/$(DEPDIR)/src_connmand-connection.Tpo -c -o src/src_connmand-connection.obj `if test -f 'src/connection.c'; then $(CYGPATH_W) 'src/connection.c'; else $(CYGPATH_W) '$(srcdir)/src/connection.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-connection.Tpo src/$(DEPDIR)/src_connmand-connection.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/connection.c' object='src/src_connmand-connection.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-connection.obj `if test -f 'src/connection.c'; then $(CYGPATH_W) 'src/connection.c'; else $(CYGPATH_W) '$(srcdir)/src/connection.c'; fi`
+
+src/src_connmand-manager.o: src/manager.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-manager.o -MD -MP -MF src/$(DEPDIR)/src_connmand-manager.Tpo -c -o src/src_connmand-manager.o `test -f 'src/manager.c' || echo '$(srcdir)/'`src/manager.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-manager.Tpo src/$(DEPDIR)/src_connmand-manager.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/manager.c' object='src/src_connmand-manager.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-manager.o `test -f 'src/manager.c' || echo '$(srcdir)/'`src/manager.c
+
+src/src_connmand-manager.obj: src/manager.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-manager.obj -MD -MP -MF src/$(DEPDIR)/src_connmand-manager.Tpo -c -o src/src_connmand-manager.obj `if test -f 'src/manager.c'; then $(CYGPATH_W) 'src/manager.c'; else $(CYGPATH_W) '$(srcdir)/src/manager.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-manager.Tpo src/$(DEPDIR)/src_connmand-manager.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/manager.c' object='src/src_connmand-manager.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-manager.obj `if test -f 'src/manager.c'; then $(CYGPATH_W) 'src/manager.c'; else $(CYGPATH_W) '$(srcdir)/src/manager.c'; fi`
+
+src/src_connmand-service.o: src/service.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-service.o -MD -MP -MF src/$(DEPDIR)/src_connmand-service.Tpo -c -o src/src_connmand-service.o `test -f 'src/service.c' || echo '$(srcdir)/'`src/service.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-service.Tpo src/$(DEPDIR)/src_connmand-service.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/service.c' object='src/src_connmand-service.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-service.o `test -f 'src/service.c' || echo '$(srcdir)/'`src/service.c
+
+src/src_connmand-service.obj: src/service.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-service.obj -MD -MP -MF src/$(DEPDIR)/src_connmand-service.Tpo -c -o src/src_connmand-service.obj `if test -f 'src/service.c'; then $(CYGPATH_W) 'src/service.c'; else $(CYGPATH_W) '$(srcdir)/src/service.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-service.Tpo src/$(DEPDIR)/src_connmand-service.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/service.c' object='src/src_connmand-service.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-service.obj `if test -f 'src/service.c'; then $(CYGPATH_W) 'src/service.c'; else $(CYGPATH_W) '$(srcdir)/src/service.c'; fi`
+
+src/src_connmand-clock.o: src/clock.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-clock.o -MD -MP -MF src/$(DEPDIR)/src_connmand-clock.Tpo -c -o src/src_connmand-clock.o `test -f 'src/clock.c' || echo '$(srcdir)/'`src/clock.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-clock.Tpo src/$(DEPDIR)/src_connmand-clock.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/clock.c' object='src/src_connmand-clock.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-clock.o `test -f 'src/clock.c' || echo '$(srcdir)/'`src/clock.c
+
+src/src_connmand-clock.obj: src/clock.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-clock.obj -MD -MP -MF src/$(DEPDIR)/src_connmand-clock.Tpo -c -o src/src_connmand-clock.obj `if test -f 'src/clock.c'; then $(CYGPATH_W) 'src/clock.c'; else $(CYGPATH_W) '$(srcdir)/src/clock.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-clock.Tpo src/$(DEPDIR)/src_connmand-clock.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/clock.c' object='src/src_connmand-clock.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-clock.obj `if test -f 'src/clock.c'; then $(CYGPATH_W) 'src/clock.c'; else $(CYGPATH_W) '$(srcdir)/src/clock.c'; fi`
+
+src/src_connmand-timezone.o: src/timezone.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-timezone.o -MD -MP -MF src/$(DEPDIR)/src_connmand-timezone.Tpo -c -o src/src_connmand-timezone.o `test -f 'src/timezone.c' || echo '$(srcdir)/'`src/timezone.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-timezone.Tpo src/$(DEPDIR)/src_connmand-timezone.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/timezone.c' object='src/src_connmand-timezone.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-timezone.o `test -f 'src/timezone.c' || echo '$(srcdir)/'`src/timezone.c
+
+src/src_connmand-timezone.obj: src/timezone.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-timezone.obj -MD -MP -MF src/$(DEPDIR)/src_connmand-timezone.Tpo -c -o src/src_connmand-timezone.obj `if test -f 'src/timezone.c'; then $(CYGPATH_W) 'src/timezone.c'; else $(CYGPATH_W) '$(srcdir)/src/timezone.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-timezone.Tpo src/$(DEPDIR)/src_connmand-timezone.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/timezone.c' object='src/src_connmand-timezone.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-timezone.obj `if test -f 'src/timezone.c'; then $(CYGPATH_W) 'src/timezone.c'; else $(CYGPATH_W) '$(srcdir)/src/timezone.c'; fi`
+
+src/src_connmand-agent-connman.o: src/agent-connman.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-agent-connman.o -MD -MP -MF src/$(DEPDIR)/src_connmand-agent-connman.Tpo -c -o src/src_connmand-agent-connman.o `test -f 'src/agent-connman.c' || echo '$(srcdir)/'`src/agent-connman.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-agent-connman.Tpo src/$(DEPDIR)/src_connmand-agent-connman.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/agent-connman.c' object='src/src_connmand-agent-connman.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-agent-connman.o `test -f 'src/agent-connman.c' || echo '$(srcdir)/'`src/agent-connman.c
+
+src/src_connmand-agent-connman.obj: src/agent-connman.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-agent-connman.obj -MD -MP -MF src/$(DEPDIR)/src_connmand-agent-connman.Tpo -c -o src/src_connmand-agent-connman.obj `if test -f 'src/agent-connman.c'; then $(CYGPATH_W) 'src/agent-connman.c'; else $(CYGPATH_W) '$(srcdir)/src/agent-connman.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-agent-connman.Tpo src/$(DEPDIR)/src_connmand-agent-connman.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/agent-connman.c' object='src/src_connmand-agent-connman.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-agent-connman.obj `if test -f 'src/agent-connman.c'; then $(CYGPATH_W) 'src/agent-connman.c'; else $(CYGPATH_W) '$(srcdir)/src/agent-connman.c'; fi`
+
+src/src_connmand-agent.o: src/agent.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-agent.o -MD -MP -MF src/$(DEPDIR)/src_connmand-agent.Tpo -c -o src/src_connmand-agent.o `test -f 'src/agent.c' || echo '$(srcdir)/'`src/agent.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-agent.Tpo src/$(DEPDIR)/src_connmand-agent.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/agent.c' object='src/src_connmand-agent.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-agent.o `test -f 'src/agent.c' || echo '$(srcdir)/'`src/agent.c
+
+src/src_connmand-agent.obj: src/agent.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-agent.obj -MD -MP -MF src/$(DEPDIR)/src_connmand-agent.Tpo -c -o src/src_connmand-agent.obj `if test -f 'src/agent.c'; then $(CYGPATH_W) 'src/agent.c'; else $(CYGPATH_W) '$(srcdir)/src/agent.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-agent.Tpo src/$(DEPDIR)/src_connmand-agent.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/agent.c' object='src/src_connmand-agent.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-agent.obj `if test -f 'src/agent.c'; then $(CYGPATH_W) 'src/agent.c'; else $(CYGPATH_W) '$(srcdir)/src/agent.c'; fi`
+
+src/src_connmand-notifier.o: src/notifier.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-notifier.o -MD -MP -MF src/$(DEPDIR)/src_connmand-notifier.Tpo -c -o src/src_connmand-notifier.o `test -f 'src/notifier.c' || echo '$(srcdir)/'`src/notifier.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-notifier.Tpo src/$(DEPDIR)/src_connmand-notifier.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/notifier.c' object='src/src_connmand-notifier.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-notifier.o `test -f 'src/notifier.c' || echo '$(srcdir)/'`src/notifier.c
+
+src/src_connmand-notifier.obj: src/notifier.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-notifier.obj -MD -MP -MF src/$(DEPDIR)/src_connmand-notifier.Tpo -c -o src/src_connmand-notifier.obj `if test -f 'src/notifier.c'; then $(CYGPATH_W) 'src/notifier.c'; else $(CYGPATH_W) '$(srcdir)/src/notifier.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-notifier.Tpo src/$(DEPDIR)/src_connmand-notifier.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/notifier.c' object='src/src_connmand-notifier.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-notifier.obj `if test -f 'src/notifier.c'; then $(CYGPATH_W) 'src/notifier.c'; else $(CYGPATH_W) '$(srcdir)/src/notifier.c'; fi`
+
+src/src_connmand-provider.o: src/provider.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-provider.o -MD -MP -MF src/$(DEPDIR)/src_connmand-provider.Tpo -c -o src/src_connmand-provider.o `test -f 'src/provider.c' || echo '$(srcdir)/'`src/provider.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-provider.Tpo src/$(DEPDIR)/src_connmand-provider.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/provider.c' object='src/src_connmand-provider.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-provider.o `test -f 'src/provider.c' || echo '$(srcdir)/'`src/provider.c
+
+src/src_connmand-provider.obj: src/provider.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-provider.obj -MD -MP -MF src/$(DEPDIR)/src_connmand-provider.Tpo -c -o src/src_connmand-provider.obj `if test -f 'src/provider.c'; then $(CYGPATH_W) 'src/provider.c'; else $(CYGPATH_W) '$(srcdir)/src/provider.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-provider.Tpo src/$(DEPDIR)/src_connmand-provider.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/provider.c' object='src/src_connmand-provider.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-provider.obj `if test -f 'src/provider.c'; then $(CYGPATH_W) 'src/provider.c'; else $(CYGPATH_W) '$(srcdir)/src/provider.c'; fi`
+
+src/src_connmand-resolver.o: src/resolver.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-resolver.o -MD -MP -MF src/$(DEPDIR)/src_connmand-resolver.Tpo -c -o src/src_connmand-resolver.o `test -f 'src/resolver.c' || echo '$(srcdir)/'`src/resolver.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-resolver.Tpo src/$(DEPDIR)/src_connmand-resolver.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/resolver.c' object='src/src_connmand-resolver.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-resolver.o `test -f 'src/resolver.c' || echo '$(srcdir)/'`src/resolver.c
+
+src/src_connmand-resolver.obj: src/resolver.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-resolver.obj -MD -MP -MF src/$(DEPDIR)/src_connmand-resolver.Tpo -c -o src/src_connmand-resolver.obj `if test -f 'src/resolver.c'; then $(CYGPATH_W) 'src/resolver.c'; else $(CYGPATH_W) '$(srcdir)/src/resolver.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-resolver.Tpo src/$(DEPDIR)/src_connmand-resolver.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/resolver.c' object='src/src_connmand-resolver.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-resolver.obj `if test -f 'src/resolver.c'; then $(CYGPATH_W) 'src/resolver.c'; else $(CYGPATH_W) '$(srcdir)/src/resolver.c'; fi`
+
+src/src_connmand-ipconfig.o: src/ipconfig.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-ipconfig.o -MD -MP -MF src/$(DEPDIR)/src_connmand-ipconfig.Tpo -c -o src/src_connmand-ipconfig.o `test -f 'src/ipconfig.c' || echo '$(srcdir)/'`src/ipconfig.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-ipconfig.Tpo src/$(DEPDIR)/src_connmand-ipconfig.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/ipconfig.c' object='src/src_connmand-ipconfig.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-ipconfig.o `test -f 'src/ipconfig.c' || echo '$(srcdir)/'`src/ipconfig.c
+
+src/src_connmand-ipconfig.obj: src/ipconfig.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-ipconfig.obj -MD -MP -MF src/$(DEPDIR)/src_connmand-ipconfig.Tpo -c -o src/src_connmand-ipconfig.obj `if test -f 'src/ipconfig.c'; then $(CYGPATH_W) 'src/ipconfig.c'; else $(CYGPATH_W) '$(srcdir)/src/ipconfig.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-ipconfig.Tpo src/$(DEPDIR)/src_connmand-ipconfig.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/ipconfig.c' object='src/src_connmand-ipconfig.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-ipconfig.obj `if test -f 'src/ipconfig.c'; then $(CYGPATH_W) 'src/ipconfig.c'; else $(CYGPATH_W) '$(srcdir)/src/ipconfig.c'; fi`
+
+src/src_connmand-detect.o: src/detect.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-detect.o -MD -MP -MF src/$(DEPDIR)/src_connmand-detect.Tpo -c -o src/src_connmand-detect.o `test -f 'src/detect.c' || echo '$(srcdir)/'`src/detect.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-detect.Tpo src/$(DEPDIR)/src_connmand-detect.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/detect.c' object='src/src_connmand-detect.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-detect.o `test -f 'src/detect.c' || echo '$(srcdir)/'`src/detect.c
+
+src/src_connmand-detect.obj: src/detect.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-detect.obj -MD -MP -MF src/$(DEPDIR)/src_connmand-detect.Tpo -c -o src/src_connmand-detect.obj `if test -f 'src/detect.c'; then $(CYGPATH_W) 'src/detect.c'; else $(CYGPATH_W) '$(srcdir)/src/detect.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-detect.Tpo src/$(DEPDIR)/src_connmand-detect.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/detect.c' object='src/src_connmand-detect.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-detect.obj `if test -f 'src/detect.c'; then $(CYGPATH_W) 'src/detect.c'; else $(CYGPATH_W) '$(srcdir)/src/detect.c'; fi`
+
+src/src_connmand-inet.o: src/inet.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-inet.o -MD -MP -MF src/$(DEPDIR)/src_connmand-inet.Tpo -c -o src/src_connmand-inet.o `test -f 'src/inet.c' || echo '$(srcdir)/'`src/inet.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-inet.Tpo src/$(DEPDIR)/src_connmand-inet.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/inet.c' object='src/src_connmand-inet.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-inet.o `test -f 'src/inet.c' || echo '$(srcdir)/'`src/inet.c
+
+src/src_connmand-inet.obj: src/inet.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-inet.obj -MD -MP -MF src/$(DEPDIR)/src_connmand-inet.Tpo -c -o src/src_connmand-inet.obj `if test -f 'src/inet.c'; then $(CYGPATH_W) 'src/inet.c'; else $(CYGPATH_W) '$(srcdir)/src/inet.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-inet.Tpo src/$(DEPDIR)/src_connmand-inet.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/inet.c' object='src/src_connmand-inet.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-inet.obj `if test -f 'src/inet.c'; then $(CYGPATH_W) 'src/inet.c'; else $(CYGPATH_W) '$(srcdir)/src/inet.c'; fi`
+
+src/src_connmand-dhcp.o: src/dhcp.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-dhcp.o -MD -MP -MF src/$(DEPDIR)/src_connmand-dhcp.Tpo -c -o src/src_connmand-dhcp.o `test -f 'src/dhcp.c' || echo '$(srcdir)/'`src/dhcp.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-dhcp.Tpo src/$(DEPDIR)/src_connmand-dhcp.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/dhcp.c' object='src/src_connmand-dhcp.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-dhcp.o `test -f 'src/dhcp.c' || echo '$(srcdir)/'`src/dhcp.c
+
+src/src_connmand-dhcp.obj: src/dhcp.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-dhcp.obj -MD -MP -MF src/$(DEPDIR)/src_connmand-dhcp.Tpo -c -o src/src_connmand-dhcp.obj `if test -f 'src/dhcp.c'; then $(CYGPATH_W) 'src/dhcp.c'; else $(CYGPATH_W) '$(srcdir)/src/dhcp.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-dhcp.Tpo src/$(DEPDIR)/src_connmand-dhcp.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/dhcp.c' object='src/src_connmand-dhcp.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-dhcp.obj `if test -f 'src/dhcp.c'; then $(CYGPATH_W) 'src/dhcp.c'; else $(CYGPATH_W) '$(srcdir)/src/dhcp.c'; fi`
+
+src/src_connmand-dhcpv6.o: src/dhcpv6.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-dhcpv6.o -MD -MP -MF src/$(DEPDIR)/src_connmand-dhcpv6.Tpo -c -o src/src_connmand-dhcpv6.o `test -f 'src/dhcpv6.c' || echo '$(srcdir)/'`src/dhcpv6.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-dhcpv6.Tpo src/$(DEPDIR)/src_connmand-dhcpv6.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/dhcpv6.c' object='src/src_connmand-dhcpv6.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-dhcpv6.o `test -f 'src/dhcpv6.c' || echo '$(srcdir)/'`src/dhcpv6.c
+
+src/src_connmand-dhcpv6.obj: src/dhcpv6.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-dhcpv6.obj -MD -MP -MF src/$(DEPDIR)/src_connmand-dhcpv6.Tpo -c -o src/src_connmand-dhcpv6.obj `if test -f 'src/dhcpv6.c'; then $(CYGPATH_W) 'src/dhcpv6.c'; else $(CYGPATH_W) '$(srcdir)/src/dhcpv6.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-dhcpv6.Tpo src/$(DEPDIR)/src_connmand-dhcpv6.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/dhcpv6.c' object='src/src_connmand-dhcpv6.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-dhcpv6.obj `if test -f 'src/dhcpv6.c'; then $(CYGPATH_W) 'src/dhcpv6.c'; else $(CYGPATH_W) '$(srcdir)/src/dhcpv6.c'; fi`
+
+src/src_connmand-rtnl.o: src/rtnl.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-rtnl.o -MD -MP -MF src/$(DEPDIR)/src_connmand-rtnl.Tpo -c -o src/src_connmand-rtnl.o `test -f 'src/rtnl.c' || echo '$(srcdir)/'`src/rtnl.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-rtnl.Tpo src/$(DEPDIR)/src_connmand-rtnl.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/rtnl.c' object='src/src_connmand-rtnl.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-rtnl.o `test -f 'src/rtnl.c' || echo '$(srcdir)/'`src/rtnl.c
+
+src/src_connmand-rtnl.obj: src/rtnl.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-rtnl.obj -MD -MP -MF src/$(DEPDIR)/src_connmand-rtnl.Tpo -c -o src/src_connmand-rtnl.obj `if test -f 'src/rtnl.c'; then $(CYGPATH_W) 'src/rtnl.c'; else $(CYGPATH_W) '$(srcdir)/src/rtnl.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-rtnl.Tpo src/$(DEPDIR)/src_connmand-rtnl.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/rtnl.c' object='src/src_connmand-rtnl.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-rtnl.obj `if test -f 'src/rtnl.c'; then $(CYGPATH_W) 'src/rtnl.c'; else $(CYGPATH_W) '$(srcdir)/src/rtnl.c'; fi`
+
+src/src_connmand-proxy.o: src/proxy.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-proxy.o -MD -MP -MF src/$(DEPDIR)/src_connmand-proxy.Tpo -c -o src/src_connmand-proxy.o `test -f 'src/proxy.c' || echo '$(srcdir)/'`src/proxy.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-proxy.Tpo src/$(DEPDIR)/src_connmand-proxy.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/proxy.c' object='src/src_connmand-proxy.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-proxy.o `test -f 'src/proxy.c' || echo '$(srcdir)/'`src/proxy.c
+
+src/src_connmand-proxy.obj: src/proxy.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-proxy.obj -MD -MP -MF src/$(DEPDIR)/src_connmand-proxy.Tpo -c -o src/src_connmand-proxy.obj `if test -f 'src/proxy.c'; then $(CYGPATH_W) 'src/proxy.c'; else $(CYGPATH_W) '$(srcdir)/src/proxy.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-proxy.Tpo src/$(DEPDIR)/src_connmand-proxy.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/proxy.c' object='src/src_connmand-proxy.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-proxy.obj `if test -f 'src/proxy.c'; then $(CYGPATH_W) 'src/proxy.c'; else $(CYGPATH_W) '$(srcdir)/src/proxy.c'; fi`
+
+src/src_connmand-utsname.o: src/utsname.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-utsname.o -MD -MP -MF src/$(DEPDIR)/src_connmand-utsname.Tpo -c -o src/src_connmand-utsname.o `test -f 'src/utsname.c' || echo '$(srcdir)/'`src/utsname.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-utsname.Tpo src/$(DEPDIR)/src_connmand-utsname.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/utsname.c' object='src/src_connmand-utsname.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-utsname.o `test -f 'src/utsname.c' || echo '$(srcdir)/'`src/utsname.c
+
+src/src_connmand-utsname.obj: src/utsname.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-utsname.obj -MD -MP -MF src/$(DEPDIR)/src_connmand-utsname.Tpo -c -o src/src_connmand-utsname.obj `if test -f 'src/utsname.c'; then $(CYGPATH_W) 'src/utsname.c'; else $(CYGPATH_W) '$(srcdir)/src/utsname.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-utsname.Tpo src/$(DEPDIR)/src_connmand-utsname.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/utsname.c' object='src/src_connmand-utsname.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-utsname.obj `if test -f 'src/utsname.c'; then $(CYGPATH_W) 'src/utsname.c'; else $(CYGPATH_W) '$(srcdir)/src/utsname.c'; fi`
+
+src/src_connmand-timeserver.o: src/timeserver.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-timeserver.o -MD -MP -MF src/$(DEPDIR)/src_connmand-timeserver.Tpo -c -o src/src_connmand-timeserver.o `test -f 'src/timeserver.c' || echo '$(srcdir)/'`src/timeserver.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-timeserver.Tpo src/$(DEPDIR)/src_connmand-timeserver.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/timeserver.c' object='src/src_connmand-timeserver.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-timeserver.o `test -f 'src/timeserver.c' || echo '$(srcdir)/'`src/timeserver.c
+
+src/src_connmand-timeserver.obj: src/timeserver.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-timeserver.obj -MD -MP -MF src/$(DEPDIR)/src_connmand-timeserver.Tpo -c -o src/src_connmand-timeserver.obj `if test -f 'src/timeserver.c'; then $(CYGPATH_W) 'src/timeserver.c'; else $(CYGPATH_W) '$(srcdir)/src/timeserver.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-timeserver.Tpo src/$(DEPDIR)/src_connmand-timeserver.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/timeserver.c' object='src/src_connmand-timeserver.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-timeserver.obj `if test -f 'src/timeserver.c'; then $(CYGPATH_W) 'src/timeserver.c'; else $(CYGPATH_W) '$(srcdir)/src/timeserver.c'; fi`
+
+src/src_connmand-rfkill.o: src/rfkill.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-rfkill.o -MD -MP -MF src/$(DEPDIR)/src_connmand-rfkill.Tpo -c -o src/src_connmand-rfkill.o `test -f 'src/rfkill.c' || echo '$(srcdir)/'`src/rfkill.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-rfkill.Tpo src/$(DEPDIR)/src_connmand-rfkill.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/rfkill.c' object='src/src_connmand-rfkill.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-rfkill.o `test -f 'src/rfkill.c' || echo '$(srcdir)/'`src/rfkill.c
+
+src/src_connmand-rfkill.obj: src/rfkill.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-rfkill.obj -MD -MP -MF src/$(DEPDIR)/src_connmand-rfkill.Tpo -c -o src/src_connmand-rfkill.obj `if test -f 'src/rfkill.c'; then $(CYGPATH_W) 'src/rfkill.c'; else $(CYGPATH_W) '$(srcdir)/src/rfkill.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-rfkill.Tpo src/$(DEPDIR)/src_connmand-rfkill.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/rfkill.c' object='src/src_connmand-rfkill.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-rfkill.obj `if test -f 'src/rfkill.c'; then $(CYGPATH_W) 'src/rfkill.c'; else $(CYGPATH_W) '$(srcdir)/src/rfkill.c'; fi`
+
+src/src_connmand-storage.o: src/storage.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-storage.o -MD -MP -MF src/$(DEPDIR)/src_connmand-storage.Tpo -c -o src/src_connmand-storage.o `test -f 'src/storage.c' || echo '$(srcdir)/'`src/storage.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-storage.Tpo src/$(DEPDIR)/src_connmand-storage.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/storage.c' object='src/src_connmand-storage.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-storage.o `test -f 'src/storage.c' || echo '$(srcdir)/'`src/storage.c
+
+src/src_connmand-storage.obj: src/storage.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-storage.obj -MD -MP -MF src/$(DEPDIR)/src_connmand-storage.Tpo -c -o src/src_connmand-storage.obj `if test -f 'src/storage.c'; then $(CYGPATH_W) 'src/storage.c'; else $(CYGPATH_W) '$(srcdir)/src/storage.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-storage.Tpo src/$(DEPDIR)/src_connmand-storage.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/storage.c' object='src/src_connmand-storage.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-storage.obj `if test -f 'src/storage.c'; then $(CYGPATH_W) 'src/storage.c'; else $(CYGPATH_W) '$(srcdir)/src/storage.c'; fi`
+
+src/src_connmand-dbus.o: src/dbus.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-dbus.o -MD -MP -MF src/$(DEPDIR)/src_connmand-dbus.Tpo -c -o src/src_connmand-dbus.o `test -f 'src/dbus.c' || echo '$(srcdir)/'`src/dbus.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-dbus.Tpo src/$(DEPDIR)/src_connmand-dbus.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/dbus.c' object='src/src_connmand-dbus.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-dbus.o `test -f 'src/dbus.c' || echo '$(srcdir)/'`src/dbus.c
+
+src/src_connmand-dbus.obj: src/dbus.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-dbus.obj -MD -MP -MF src/$(DEPDIR)/src_connmand-dbus.Tpo -c -o src/src_connmand-dbus.obj `if test -f 'src/dbus.c'; then $(CYGPATH_W) 'src/dbus.c'; else $(CYGPATH_W) '$(srcdir)/src/dbus.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-dbus.Tpo src/$(DEPDIR)/src_connmand-dbus.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/dbus.c' object='src/src_connmand-dbus.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-dbus.obj `if test -f 'src/dbus.c'; then $(CYGPATH_W) 'src/dbus.c'; else $(CYGPATH_W) '$(srcdir)/src/dbus.c'; fi`
+
+src/src_connmand-config.o: src/config.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-config.o -MD -MP -MF src/$(DEPDIR)/src_connmand-config.Tpo -c -o src/src_connmand-config.o `test -f 'src/config.c' || echo '$(srcdir)/'`src/config.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-config.Tpo src/$(DEPDIR)/src_connmand-config.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/config.c' object='src/src_connmand-config.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-config.o `test -f 'src/config.c' || echo '$(srcdir)/'`src/config.c
+
+src/src_connmand-config.obj: src/config.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-config.obj -MD -MP -MF src/$(DEPDIR)/src_connmand-config.Tpo -c -o src/src_connmand-config.obj `if test -f 'src/config.c'; then $(CYGPATH_W) 'src/config.c'; else $(CYGPATH_W) '$(srcdir)/src/config.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-config.Tpo src/$(DEPDIR)/src_connmand-config.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/config.c' object='src/src_connmand-config.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-config.obj `if test -f 'src/config.c'; then $(CYGPATH_W) 'src/config.c'; else $(CYGPATH_W) '$(srcdir)/src/config.c'; fi`
+
+src/src_connmand-technology.o: src/technology.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-technology.o -MD -MP -MF src/$(DEPDIR)/src_connmand-technology.Tpo -c -o src/src_connmand-technology.o `test -f 'src/technology.c' || echo '$(srcdir)/'`src/technology.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-technology.Tpo src/$(DEPDIR)/src_connmand-technology.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/technology.c' object='src/src_connmand-technology.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-technology.o `test -f 'src/technology.c' || echo '$(srcdir)/'`src/technology.c
+
+src/src_connmand-technology.obj: src/technology.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-technology.obj -MD -MP -MF src/$(DEPDIR)/src_connmand-technology.Tpo -c -o src/src_connmand-technology.obj `if test -f 'src/technology.c'; then $(CYGPATH_W) 'src/technology.c'; else $(CYGPATH_W) '$(srcdir)/src/technology.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-technology.Tpo src/$(DEPDIR)/src_connmand-technology.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/technology.c' object='src/src_connmand-technology.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-technology.obj `if test -f 'src/technology.c'; then $(CYGPATH_W) 'src/technology.c'; else $(CYGPATH_W) '$(srcdir)/src/technology.c'; fi`
+
+src/src_connmand-counter.o: src/counter.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-counter.o -MD -MP -MF src/$(DEPDIR)/src_connmand-counter.Tpo -c -o src/src_connmand-counter.o `test -f 'src/counter.c' || echo '$(srcdir)/'`src/counter.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-counter.Tpo src/$(DEPDIR)/src_connmand-counter.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/counter.c' object='src/src_connmand-counter.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-counter.o `test -f 'src/counter.c' || echo '$(srcdir)/'`src/counter.c
+
+src/src_connmand-counter.obj: src/counter.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-counter.obj -MD -MP -MF src/$(DEPDIR)/src_connmand-counter.Tpo -c -o src/src_connmand-counter.obj `if test -f 'src/counter.c'; then $(CYGPATH_W) 'src/counter.c'; else $(CYGPATH_W) '$(srcdir)/src/counter.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-counter.Tpo src/$(DEPDIR)/src_connmand-counter.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/counter.c' object='src/src_connmand-counter.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-counter.obj `if test -f 'src/counter.c'; then $(CYGPATH_W) 'src/counter.c'; else $(CYGPATH_W) '$(srcdir)/src/counter.c'; fi`
+
+src/src_connmand-ntp.o: src/ntp.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-ntp.o -MD -MP -MF src/$(DEPDIR)/src_connmand-ntp.Tpo -c -o src/src_connmand-ntp.o `test -f 'src/ntp.c' || echo '$(srcdir)/'`src/ntp.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-ntp.Tpo src/$(DEPDIR)/src_connmand-ntp.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/ntp.c' object='src/src_connmand-ntp.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-ntp.o `test -f 'src/ntp.c' || echo '$(srcdir)/'`src/ntp.c
+
+src/src_connmand-ntp.obj: src/ntp.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-ntp.obj -MD -MP -MF src/$(DEPDIR)/src_connmand-ntp.Tpo -c -o src/src_connmand-ntp.obj `if test -f 'src/ntp.c'; then $(CYGPATH_W) 'src/ntp.c'; else $(CYGPATH_W) '$(srcdir)/src/ntp.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-ntp.Tpo src/$(DEPDIR)/src_connmand-ntp.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/ntp.c' object='src/src_connmand-ntp.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-ntp.obj `if test -f 'src/ntp.c'; then $(CYGPATH_W) 'src/ntp.c'; else $(CYGPATH_W) '$(srcdir)/src/ntp.c'; fi`
+
+src/src_connmand-session.o: src/session.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-session.o -MD -MP -MF src/$(DEPDIR)/src_connmand-session.Tpo -c -o src/src_connmand-session.o `test -f 'src/session.c' || echo '$(srcdir)/'`src/session.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-session.Tpo src/$(DEPDIR)/src_connmand-session.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/session.c' object='src/src_connmand-session.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-session.o `test -f 'src/session.c' || echo '$(srcdir)/'`src/session.c
+
+src/src_connmand-session.obj: src/session.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-session.obj -MD -MP -MF src/$(DEPDIR)/src_connmand-session.Tpo -c -o src/src_connmand-session.obj `if test -f 'src/session.c'; then $(CYGPATH_W) 'src/session.c'; else $(CYGPATH_W) '$(srcdir)/src/session.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-session.Tpo src/$(DEPDIR)/src_connmand-session.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/session.c' object='src/src_connmand-session.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-session.obj `if test -f 'src/session.c'; then $(CYGPATH_W) 'src/session.c'; else $(CYGPATH_W) '$(srcdir)/src/session.c'; fi`
+
+src/src_connmand-tethering.o: src/tethering.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-tethering.o -MD -MP -MF src/$(DEPDIR)/src_connmand-tethering.Tpo -c -o src/src_connmand-tethering.o `test -f 'src/tethering.c' || echo '$(srcdir)/'`src/tethering.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-tethering.Tpo src/$(DEPDIR)/src_connmand-tethering.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/tethering.c' object='src/src_connmand-tethering.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-tethering.o `test -f 'src/tethering.c' || echo '$(srcdir)/'`src/tethering.c
+
+src/src_connmand-tethering.obj: src/tethering.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-tethering.obj -MD -MP -MF src/$(DEPDIR)/src_connmand-tethering.Tpo -c -o src/src_connmand-tethering.obj `if test -f 'src/tethering.c'; then $(CYGPATH_W) 'src/tethering.c'; else $(CYGPATH_W) '$(srcdir)/src/tethering.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-tethering.Tpo src/$(DEPDIR)/src_connmand-tethering.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/tethering.c' object='src/src_connmand-tethering.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-tethering.obj `if test -f 'src/tethering.c'; then $(CYGPATH_W) 'src/tethering.c'; else $(CYGPATH_W) '$(srcdir)/src/tethering.c'; fi`
+
+src/src_connmand-wpad.o: src/wpad.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-wpad.o -MD -MP -MF src/$(DEPDIR)/src_connmand-wpad.Tpo -c -o src/src_connmand-wpad.o `test -f 'src/wpad.c' || echo '$(srcdir)/'`src/wpad.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-wpad.Tpo src/$(DEPDIR)/src_connmand-wpad.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/wpad.c' object='src/src_connmand-wpad.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-wpad.o `test -f 'src/wpad.c' || echo '$(srcdir)/'`src/wpad.c
+
+src/src_connmand-wpad.obj: src/wpad.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-wpad.obj -MD -MP -MF src/$(DEPDIR)/src_connmand-wpad.Tpo -c -o src/src_connmand-wpad.obj `if test -f 'src/wpad.c'; then $(CYGPATH_W) 'src/wpad.c'; else $(CYGPATH_W) '$(srcdir)/src/wpad.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-wpad.Tpo src/$(DEPDIR)/src_connmand-wpad.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/wpad.c' object='src/src_connmand-wpad.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-wpad.obj `if test -f 'src/wpad.c'; then $(CYGPATH_W) 'src/wpad.c'; else $(CYGPATH_W) '$(srcdir)/src/wpad.c'; fi`
+
+src/src_connmand-wispr.o: src/wispr.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-wispr.o -MD -MP -MF src/$(DEPDIR)/src_connmand-wispr.Tpo -c -o src/src_connmand-wispr.o `test -f 'src/wispr.c' || echo '$(srcdir)/'`src/wispr.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-wispr.Tpo src/$(DEPDIR)/src_connmand-wispr.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/wispr.c' object='src/src_connmand-wispr.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-wispr.o `test -f 'src/wispr.c' || echo '$(srcdir)/'`src/wispr.c
+
+src/src_connmand-wispr.obj: src/wispr.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-wispr.obj -MD -MP -MF src/$(DEPDIR)/src_connmand-wispr.Tpo -c -o src/src_connmand-wispr.obj `if test -f 'src/wispr.c'; then $(CYGPATH_W) 'src/wispr.c'; else $(CYGPATH_W) '$(srcdir)/src/wispr.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-wispr.Tpo src/$(DEPDIR)/src_connmand-wispr.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/wispr.c' object='src/src_connmand-wispr.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-wispr.obj `if test -f 'src/wispr.c'; then $(CYGPATH_W) 'src/wispr.c'; else $(CYGPATH_W) '$(srcdir)/src/wispr.c'; fi`
+
+src/src_connmand-stats.o: src/stats.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-stats.o -MD -MP -MF src/$(DEPDIR)/src_connmand-stats.Tpo -c -o src/src_connmand-stats.o `test -f 'src/stats.c' || echo '$(srcdir)/'`src/stats.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-stats.Tpo src/$(DEPDIR)/src_connmand-stats.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/stats.c' object='src/src_connmand-stats.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-stats.o `test -f 'src/stats.c' || echo '$(srcdir)/'`src/stats.c
+
+src/src_connmand-stats.obj: src/stats.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-stats.obj -MD -MP -MF src/$(DEPDIR)/src_connmand-stats.Tpo -c -o src/src_connmand-stats.obj `if test -f 'src/stats.c'; then $(CYGPATH_W) 'src/stats.c'; else $(CYGPATH_W) '$(srcdir)/src/stats.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-stats.Tpo src/$(DEPDIR)/src_connmand-stats.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/stats.c' object='src/src_connmand-stats.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-stats.obj `if test -f 'src/stats.c'; then $(CYGPATH_W) 'src/stats.c'; else $(CYGPATH_W) '$(srcdir)/src/stats.c'; fi`
+
+src/src_connmand-iptables.o: src/iptables.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-iptables.o -MD -MP -MF src/$(DEPDIR)/src_connmand-iptables.Tpo -c -o src/src_connmand-iptables.o `test -f 'src/iptables.c' || echo '$(srcdir)/'`src/iptables.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-iptables.Tpo src/$(DEPDIR)/src_connmand-iptables.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/iptables.c' object='src/src_connmand-iptables.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-iptables.o `test -f 'src/iptables.c' || echo '$(srcdir)/'`src/iptables.c
+
+src/src_connmand-iptables.obj: src/iptables.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-iptables.obj -MD -MP -MF src/$(DEPDIR)/src_connmand-iptables.Tpo -c -o src/src_connmand-iptables.obj `if test -f 'src/iptables.c'; then $(CYGPATH_W) 'src/iptables.c'; else $(CYGPATH_W) '$(srcdir)/src/iptables.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-iptables.Tpo src/$(DEPDIR)/src_connmand-iptables.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/iptables.c' object='src/src_connmand-iptables.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-iptables.obj `if test -f 'src/iptables.c'; then $(CYGPATH_W) 'src/iptables.c'; else $(CYGPATH_W) '$(srcdir)/src/iptables.c'; fi`
+
+src/src_connmand-dnsproxy.o: src/dnsproxy.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-dnsproxy.o -MD -MP -MF src/$(DEPDIR)/src_connmand-dnsproxy.Tpo -c -o src/src_connmand-dnsproxy.o `test -f 'src/dnsproxy.c' || echo '$(srcdir)/'`src/dnsproxy.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-dnsproxy.Tpo src/$(DEPDIR)/src_connmand-dnsproxy.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/dnsproxy.c' object='src/src_connmand-dnsproxy.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-dnsproxy.o `test -f 'src/dnsproxy.c' || echo '$(srcdir)/'`src/dnsproxy.c
+
+src/src_connmand-dnsproxy.obj: src/dnsproxy.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-dnsproxy.obj -MD -MP -MF src/$(DEPDIR)/src_connmand-dnsproxy.Tpo -c -o src/src_connmand-dnsproxy.obj `if test -f 'src/dnsproxy.c'; then $(CYGPATH_W) 'src/dnsproxy.c'; else $(CYGPATH_W) '$(srcdir)/src/dnsproxy.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-dnsproxy.Tpo src/$(DEPDIR)/src_connmand-dnsproxy.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/dnsproxy.c' object='src/src_connmand-dnsproxy.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-dnsproxy.obj `if test -f 'src/dnsproxy.c'; then $(CYGPATH_W) 'src/dnsproxy.c'; else $(CYGPATH_W) '$(srcdir)/src/dnsproxy.c'; fi`
+
+src/src_connmand-6to4.o: src/6to4.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-6to4.o -MD -MP -MF src/$(DEPDIR)/src_connmand-6to4.Tpo -c -o src/src_connmand-6to4.o `test -f 'src/6to4.c' || echo '$(srcdir)/'`src/6to4.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-6to4.Tpo src/$(DEPDIR)/src_connmand-6to4.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/6to4.c' object='src/src_connmand-6to4.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-6to4.o `test -f 'src/6to4.c' || echo '$(srcdir)/'`src/6to4.c
+
+src/src_connmand-6to4.obj: src/6to4.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-6to4.obj -MD -MP -MF src/$(DEPDIR)/src_connmand-6to4.Tpo -c -o src/src_connmand-6to4.obj `if test -f 'src/6to4.c'; then $(CYGPATH_W) 'src/6to4.c'; else $(CYGPATH_W) '$(srcdir)/src/6to4.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-6to4.Tpo src/$(DEPDIR)/src_connmand-6to4.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/6to4.c' object='src/src_connmand-6to4.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-6to4.obj `if test -f 'src/6to4.c'; then $(CYGPATH_W) 'src/6to4.c'; else $(CYGPATH_W) '$(srcdir)/src/6to4.c'; fi`
+
+src/src_connmand-ippool.o: src/ippool.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-ippool.o -MD -MP -MF src/$(DEPDIR)/src_connmand-ippool.Tpo -c -o src/src_connmand-ippool.o `test -f 'src/ippool.c' || echo '$(srcdir)/'`src/ippool.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-ippool.Tpo src/$(DEPDIR)/src_connmand-ippool.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/ippool.c' object='src/src_connmand-ippool.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-ippool.o `test -f 'src/ippool.c' || echo '$(srcdir)/'`src/ippool.c
+
+src/src_connmand-ippool.obj: src/ippool.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-ippool.obj -MD -MP -MF src/$(DEPDIR)/src_connmand-ippool.Tpo -c -o src/src_connmand-ippool.obj `if test -f 'src/ippool.c'; then $(CYGPATH_W) 'src/ippool.c'; else $(CYGPATH_W) '$(srcdir)/src/ippool.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-ippool.Tpo src/$(DEPDIR)/src_connmand-ippool.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/ippool.c' object='src/src_connmand-ippool.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-ippool.obj `if test -f 'src/ippool.c'; then $(CYGPATH_W) 'src/ippool.c'; else $(CYGPATH_W) '$(srcdir)/src/ippool.c'; fi`
+
+src/src_connmand-bridge.o: src/bridge.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-bridge.o -MD -MP -MF src/$(DEPDIR)/src_connmand-bridge.Tpo -c -o src/src_connmand-bridge.o `test -f 'src/bridge.c' || echo '$(srcdir)/'`src/bridge.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-bridge.Tpo src/$(DEPDIR)/src_connmand-bridge.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/bridge.c' object='src/src_connmand-bridge.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-bridge.o `test -f 'src/bridge.c' || echo '$(srcdir)/'`src/bridge.c
+
+src/src_connmand-bridge.obj: src/bridge.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-bridge.obj -MD -MP -MF src/$(DEPDIR)/src_connmand-bridge.Tpo -c -o src/src_connmand-bridge.obj `if test -f 'src/bridge.c'; then $(CYGPATH_W) 'src/bridge.c'; else $(CYGPATH_W) '$(srcdir)/src/bridge.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-bridge.Tpo src/$(DEPDIR)/src_connmand-bridge.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/bridge.c' object='src/src_connmand-bridge.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-bridge.obj `if test -f 'src/bridge.c'; then $(CYGPATH_W) 'src/bridge.c'; else $(CYGPATH_W) '$(srcdir)/src/bridge.c'; fi`
+
+src/src_connmand-nat.o: src/nat.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-nat.o -MD -MP -MF src/$(DEPDIR)/src_connmand-nat.Tpo -c -o src/src_connmand-nat.o `test -f 'src/nat.c' || echo '$(srcdir)/'`src/nat.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-nat.Tpo src/$(DEPDIR)/src_connmand-nat.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/nat.c' object='src/src_connmand-nat.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-nat.o `test -f 'src/nat.c' || echo '$(srcdir)/'`src/nat.c
+
+src/src_connmand-nat.obj: src/nat.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-nat.obj -MD -MP -MF src/$(DEPDIR)/src_connmand-nat.Tpo -c -o src/src_connmand-nat.obj `if test -f 'src/nat.c'; then $(CYGPATH_W) 'src/nat.c'; else $(CYGPATH_W) '$(srcdir)/src/nat.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-nat.Tpo src/$(DEPDIR)/src_connmand-nat.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/nat.c' object='src/src_connmand-nat.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-nat.obj `if test -f 'src/nat.c'; then $(CYGPATH_W) 'src/nat.c'; else $(CYGPATH_W) '$(srcdir)/src/nat.c'; fi`
+
+src/src_connmand-ipaddress.o: src/ipaddress.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-ipaddress.o -MD -MP -MF src/$(DEPDIR)/src_connmand-ipaddress.Tpo -c -o src/src_connmand-ipaddress.o `test -f 'src/ipaddress.c' || echo '$(srcdir)/'`src/ipaddress.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-ipaddress.Tpo src/$(DEPDIR)/src_connmand-ipaddress.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/ipaddress.c' object='src/src_connmand-ipaddress.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-ipaddress.o `test -f 'src/ipaddress.c' || echo '$(srcdir)/'`src/ipaddress.c
+
+src/src_connmand-ipaddress.obj: src/ipaddress.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-ipaddress.obj -MD -MP -MF src/$(DEPDIR)/src_connmand-ipaddress.Tpo -c -o src/src_connmand-ipaddress.obj `if test -f 'src/ipaddress.c'; then $(CYGPATH_W) 'src/ipaddress.c'; else $(CYGPATH_W) '$(srcdir)/src/ipaddress.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-ipaddress.Tpo src/$(DEPDIR)/src_connmand-ipaddress.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/ipaddress.c' object='src/src_connmand-ipaddress.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-ipaddress.obj `if test -f 'src/ipaddress.c'; then $(CYGPATH_W) 'src/ipaddress.c'; else $(CYGPATH_W) '$(srcdir)/src/ipaddress.c'; fi`
+
+src/src_connmand-inotify.o: src/inotify.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-inotify.o -MD -MP -MF src/$(DEPDIR)/src_connmand-inotify.Tpo -c -o src/src_connmand-inotify.o `test -f 'src/inotify.c' || echo '$(srcdir)/'`src/inotify.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-inotify.Tpo src/$(DEPDIR)/src_connmand-inotify.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/inotify.c' object='src/src_connmand-inotify.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-inotify.o `test -f 'src/inotify.c' || echo '$(srcdir)/'`src/inotify.c
+
+src/src_connmand-inotify.obj: src/inotify.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-inotify.obj -MD -MP -MF src/$(DEPDIR)/src_connmand-inotify.Tpo -c -o src/src_connmand-inotify.obj `if test -f 'src/inotify.c'; then $(CYGPATH_W) 'src/inotify.c'; else $(CYGPATH_W) '$(srcdir)/src/inotify.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-inotify.Tpo src/$(DEPDIR)/src_connmand-inotify.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/inotify.c' object='src/src_connmand-inotify.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-inotify.obj `if test -f 'src/inotify.c'; then $(CYGPATH_W) 'src/inotify.c'; else $(CYGPATH_W) '$(srcdir)/src/inotify.c'; fi`
+
+src/src_connmand-firewall.o: src/firewall.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-firewall.o -MD -MP -MF src/$(DEPDIR)/src_connmand-firewall.Tpo -c -o src/src_connmand-firewall.o `test -f 'src/firewall.c' || echo '$(srcdir)/'`src/firewall.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-firewall.Tpo src/$(DEPDIR)/src_connmand-firewall.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/firewall.c' object='src/src_connmand-firewall.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-firewall.o `test -f 'src/firewall.c' || echo '$(srcdir)/'`src/firewall.c
+
+src/src_connmand-firewall.obj: src/firewall.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-firewall.obj -MD -MP -MF src/$(DEPDIR)/src_connmand-firewall.Tpo -c -o src/src_connmand-firewall.obj `if test -f 'src/firewall.c'; then $(CYGPATH_W) 'src/firewall.c'; else $(CYGPATH_W) '$(srcdir)/src/firewall.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-firewall.Tpo src/$(DEPDIR)/src_connmand-firewall.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/firewall.c' object='src/src_connmand-firewall.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-firewall.obj `if test -f 'src/firewall.c'; then $(CYGPATH_W) 'src/firewall.c'; else $(CYGPATH_W) '$(srcdir)/src/firewall.c'; fi`
+
+src/src_connmand-ipv6pd.o: src/ipv6pd.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-ipv6pd.o -MD -MP -MF src/$(DEPDIR)/src_connmand-ipv6pd.Tpo -c -o src/src_connmand-ipv6pd.o `test -f 'src/ipv6pd.c' || echo '$(srcdir)/'`src/ipv6pd.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-ipv6pd.Tpo src/$(DEPDIR)/src_connmand-ipv6pd.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/ipv6pd.c' object='src/src_connmand-ipv6pd.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-ipv6pd.o `test -f 'src/ipv6pd.c' || echo '$(srcdir)/'`src/ipv6pd.c
+
+src/src_connmand-ipv6pd.obj: src/ipv6pd.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-ipv6pd.obj -MD -MP -MF src/$(DEPDIR)/src_connmand-ipv6pd.Tpo -c -o src/src_connmand-ipv6pd.obj `if test -f 'src/ipv6pd.c'; then $(CYGPATH_W) 'src/ipv6pd.c'; else $(CYGPATH_W) '$(srcdir)/src/ipv6pd.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-ipv6pd.Tpo src/$(DEPDIR)/src_connmand-ipv6pd.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/ipv6pd.c' object='src/src_connmand-ipv6pd.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-ipv6pd.obj `if test -f 'src/ipv6pd.c'; then $(CYGPATH_W) 'src/ipv6pd.c'; else $(CYGPATH_W) '$(srcdir)/src/ipv6pd.c'; fi`
+
+src/src_connmand-peer.o: src/peer.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-peer.o -MD -MP -MF src/$(DEPDIR)/src_connmand-peer.Tpo -c -o src/src_connmand-peer.o `test -f 'src/peer.c' || echo '$(srcdir)/'`src/peer.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-peer.Tpo src/$(DEPDIR)/src_connmand-peer.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/peer.c' object='src/src_connmand-peer.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-peer.o `test -f 'src/peer.c' || echo '$(srcdir)/'`src/peer.c
+
+src/src_connmand-peer.obj: src/peer.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-peer.obj -MD -MP -MF src/$(DEPDIR)/src_connmand-peer.Tpo -c -o src/src_connmand-peer.obj `if test -f 'src/peer.c'; then $(CYGPATH_W) 'src/peer.c'; else $(CYGPATH_W) '$(srcdir)/src/peer.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-peer.Tpo src/$(DEPDIR)/src_connmand-peer.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/peer.c' object='src/src_connmand-peer.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-peer.obj `if test -f 'src/peer.c'; then $(CYGPATH_W) 'src/peer.c'; else $(CYGPATH_W) '$(srcdir)/src/peer.c'; fi`
+
+src/src_connmand-peer_service.o: src/peer_service.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-peer_service.o -MD -MP -MF src/$(DEPDIR)/src_connmand-peer_service.Tpo -c -o src/src_connmand-peer_service.o `test -f 'src/peer_service.c' || echo '$(srcdir)/'`src/peer_service.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-peer_service.Tpo src/$(DEPDIR)/src_connmand-peer_service.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/peer_service.c' object='src/src_connmand-peer_service.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-peer_service.o `test -f 'src/peer_service.c' || echo '$(srcdir)/'`src/peer_service.c
+
+src/src_connmand-peer_service.obj: src/peer_service.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-peer_service.obj -MD -MP -MF src/$(DEPDIR)/src_connmand-peer_service.Tpo -c -o src/src_connmand-peer_service.obj `if test -f 'src/peer_service.c'; then $(CYGPATH_W) 'src/peer_service.c'; else $(CYGPATH_W) '$(srcdir)/src/peer_service.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-peer_service.Tpo src/$(DEPDIR)/src_connmand-peer_service.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/peer_service.c' object='src/src_connmand-peer_service.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-peer_service.obj `if test -f 'src/peer_service.c'; then $(CYGPATH_W) 'src/peer_service.c'; else $(CYGPATH_W) '$(srcdir)/src/peer_service.c'; fi`
+
+src/src_connmand-machine.o: src/machine.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-machine.o -MD -MP -MF src/$(DEPDIR)/src_connmand-machine.Tpo -c -o src/src_connmand-machine.o `test -f 'src/machine.c' || echo '$(srcdir)/'`src/machine.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-machine.Tpo src/$(DEPDIR)/src_connmand-machine.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/machine.c' object='src/src_connmand-machine.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-machine.o `test -f 'src/machine.c' || echo '$(srcdir)/'`src/machine.c
+
+src/src_connmand-machine.obj: src/machine.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-machine.obj -MD -MP -MF src/$(DEPDIR)/src_connmand-machine.Tpo -c -o src/src_connmand-machine.obj `if test -f 'src/machine.c'; then $(CYGPATH_W) 'src/machine.c'; else $(CYGPATH_W) '$(srcdir)/src/machine.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-machine.Tpo src/$(DEPDIR)/src_connmand-machine.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/machine.c' object='src/src_connmand-machine.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-machine.obj `if test -f 'src/machine.c'; then $(CYGPATH_W) 'src/machine.c'; else $(CYGPATH_W) '$(srcdir)/src/machine.c'; fi`
+
+src/src_connmand-util.o: src/util.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-util.o -MD -MP -MF src/$(DEPDIR)/src_connmand-util.Tpo -c -o src/src_connmand-util.o `test -f 'src/util.c' || echo '$(srcdir)/'`src/util.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-util.Tpo src/$(DEPDIR)/src_connmand-util.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/util.c' object='src/src_connmand-util.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-util.o `test -f 'src/util.c' || echo '$(srcdir)/'`src/util.c
+
+src/src_connmand-util.obj: src/util.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-util.obj -MD -MP -MF src/$(DEPDIR)/src_connmand-util.Tpo -c -o src/src_connmand-util.obj `if test -f 'src/util.c'; then $(CYGPATH_W) 'src/util.c'; else $(CYGPATH_W) '$(srcdir)/src/util.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-util.Tpo src/$(DEPDIR)/src_connmand-util.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/util.c' object='src/src_connmand-util.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-util.obj `if test -f 'src/util.c'; then $(CYGPATH_W) 'src/util.c'; else $(CYGPATH_W) '$(srcdir)/src/util.c'; fi`
+
+src/src_connmand-rlimits.o: src/rlimits.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-rlimits.o -MD -MP -MF src/$(DEPDIR)/src_connmand-rlimits.Tpo -c -o src/src_connmand-rlimits.o `test -f 'src/rlimits.c' || echo '$(srcdir)/'`src/rlimits.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-rlimits.Tpo src/$(DEPDIR)/src_connmand-rlimits.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/rlimits.c' object='src/src_connmand-rlimits.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-rlimits.o `test -f 'src/rlimits.c' || echo '$(srcdir)/'`src/rlimits.c
+
+src/src_connmand-rlimits.obj: src/rlimits.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -MT src/src_connmand-rlimits.obj -MD -MP -MF src/$(DEPDIR)/src_connmand-rlimits.Tpo -c -o src/src_connmand-rlimits.obj `if test -f 'src/rlimits.c'; then $(CYGPATH_W) 'src/rlimits.c'; else $(CYGPATH_W) '$(srcdir)/src/rlimits.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/src_connmand-rlimits.Tpo src/$(DEPDIR)/src_connmand-rlimits.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/rlimits.c' object='src/src_connmand-rlimits.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_connmand_CFLAGS) $(CFLAGS) -c -o src/src_connmand-rlimits.obj `if test -f 'src/rlimits.c'; then $(CYGPATH_W) 'src/rlimits.c'; else $(CYGPATH_W) '$(srcdir)/src/rlimits.c'; fi`
+
+src/tools_iptables_unit-log.o: src/log.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(tools_iptables_unit_CFLAGS) $(CFLAGS) -MT src/tools_iptables_unit-log.o -MD -MP -MF src/$(DEPDIR)/tools_iptables_unit-log.Tpo -c -o src/tools_iptables_unit-log.o `test -f 'src/log.c' || echo '$(srcdir)/'`src/log.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/tools_iptables_unit-log.Tpo src/$(DEPDIR)/tools_iptables_unit-log.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/log.c' object='src/tools_iptables_unit-log.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(tools_iptables_unit_CFLAGS) $(CFLAGS) -c -o src/tools_iptables_unit-log.o `test -f 'src/log.c' || echo '$(srcdir)/'`src/log.c
+
+src/tools_iptables_unit-log.obj: src/log.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(tools_iptables_unit_CFLAGS) $(CFLAGS) -MT src/tools_iptables_unit-log.obj -MD -MP -MF src/$(DEPDIR)/tools_iptables_unit-log.Tpo -c -o src/tools_iptables_unit-log.obj `if test -f 'src/log.c'; then $(CYGPATH_W) 'src/log.c'; else $(CYGPATH_W) '$(srcdir)/src/log.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/tools_iptables_unit-log.Tpo src/$(DEPDIR)/tools_iptables_unit-log.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/log.c' object='src/tools_iptables_unit-log.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(tools_iptables_unit_CFLAGS) $(CFLAGS) -c -o src/tools_iptables_unit-log.obj `if test -f 'src/log.c'; then $(CYGPATH_W) 'src/log.c'; else $(CYGPATH_W) '$(srcdir)/src/log.c'; fi`
+
+src/tools_iptables_unit-iptables.o: src/iptables.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(tools_iptables_unit_CFLAGS) $(CFLAGS) -MT src/tools_iptables_unit-iptables.o -MD -MP -MF src/$(DEPDIR)/tools_iptables_unit-iptables.Tpo -c -o src/tools_iptables_unit-iptables.o `test -f 'src/iptables.c' || echo '$(srcdir)/'`src/iptables.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/tools_iptables_unit-iptables.Tpo src/$(DEPDIR)/tools_iptables_unit-iptables.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/iptables.c' object='src/tools_iptables_unit-iptables.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(tools_iptables_unit_CFLAGS) $(CFLAGS) -c -o src/tools_iptables_unit-iptables.o `test -f 'src/iptables.c' || echo '$(srcdir)/'`src/iptables.c
+
+src/tools_iptables_unit-iptables.obj: src/iptables.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(tools_iptables_unit_CFLAGS) $(CFLAGS) -MT src/tools_iptables_unit-iptables.obj -MD -MP -MF src/$(DEPDIR)/tools_iptables_unit-iptables.Tpo -c -o src/tools_iptables_unit-iptables.obj `if test -f 'src/iptables.c'; then $(CYGPATH_W) 'src/iptables.c'; else $(CYGPATH_W) '$(srcdir)/src/iptables.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/tools_iptables_unit-iptables.Tpo src/$(DEPDIR)/tools_iptables_unit-iptables.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/iptables.c' object='src/tools_iptables_unit-iptables.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(tools_iptables_unit_CFLAGS) $(CFLAGS) -c -o src/tools_iptables_unit-iptables.obj `if test -f 'src/iptables.c'; then $(CYGPATH_W) 'src/iptables.c'; else $(CYGPATH_W) '$(srcdir)/src/iptables.c'; fi`
+
+src/tools_iptables_unit-firewall.o: src/firewall.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(tools_iptables_unit_CFLAGS) $(CFLAGS) -MT src/tools_iptables_unit-firewall.o -MD -MP -MF src/$(DEPDIR)/tools_iptables_unit-firewall.Tpo -c -o src/tools_iptables_unit-firewall.o `test -f 'src/firewall.c' || echo '$(srcdir)/'`src/firewall.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/tools_iptables_unit-firewall.Tpo src/$(DEPDIR)/tools_iptables_unit-firewall.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/firewall.c' object='src/tools_iptables_unit-firewall.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(tools_iptables_unit_CFLAGS) $(CFLAGS) -c -o src/tools_iptables_unit-firewall.o `test -f 'src/firewall.c' || echo '$(srcdir)/'`src/firewall.c
+
+src/tools_iptables_unit-firewall.obj: src/firewall.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(tools_iptables_unit_CFLAGS) $(CFLAGS) -MT src/tools_iptables_unit-firewall.obj -MD -MP -MF src/$(DEPDIR)/tools_iptables_unit-firewall.Tpo -c -o src/tools_iptables_unit-firewall.obj `if test -f 'src/firewall.c'; then $(CYGPATH_W) 'src/firewall.c'; else $(CYGPATH_W) '$(srcdir)/src/firewall.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/tools_iptables_unit-firewall.Tpo src/$(DEPDIR)/tools_iptables_unit-firewall.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/firewall.c' object='src/tools_iptables_unit-firewall.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(tools_iptables_unit_CFLAGS) $(CFLAGS) -c -o src/tools_iptables_unit-firewall.obj `if test -f 'src/firewall.c'; then $(CYGPATH_W) 'src/firewall.c'; else $(CYGPATH_W) '$(srcdir)/src/firewall.c'; fi`
+
+src/tools_iptables_unit-nat.o: src/nat.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(tools_iptables_unit_CFLAGS) $(CFLAGS) -MT src/tools_iptables_unit-nat.o -MD -MP -MF src/$(DEPDIR)/tools_iptables_unit-nat.Tpo -c -o src/tools_iptables_unit-nat.o `test -f 'src/nat.c' || echo '$(srcdir)/'`src/nat.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/tools_iptables_unit-nat.Tpo src/$(DEPDIR)/tools_iptables_unit-nat.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/nat.c' object='src/tools_iptables_unit-nat.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(tools_iptables_unit_CFLAGS) $(CFLAGS) -c -o src/tools_iptables_unit-nat.o `test -f 'src/nat.c' || echo '$(srcdir)/'`src/nat.c
+
+src/tools_iptables_unit-nat.obj: src/nat.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(tools_iptables_unit_CFLAGS) $(CFLAGS) -MT src/tools_iptables_unit-nat.obj -MD -MP -MF src/$(DEPDIR)/tools_iptables_unit-nat.Tpo -c -o src/tools_iptables_unit-nat.obj `if test -f 'src/nat.c'; then $(CYGPATH_W) 'src/nat.c'; else $(CYGPATH_W) '$(srcdir)/src/nat.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/tools_iptables_unit-nat.Tpo src/$(DEPDIR)/tools_iptables_unit-nat.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/nat.c' object='src/tools_iptables_unit-nat.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(tools_iptables_unit_CFLAGS) $(CFLAGS) -c -o src/tools_iptables_unit-nat.obj `if test -f 'src/nat.c'; then $(CYGPATH_W) 'src/nat.c'; else $(CYGPATH_W) '$(srcdir)/src/nat.c'; fi`
+
+tools/tools_iptables_unit-iptables-unit.o: tools/iptables-unit.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(tools_iptables_unit_CFLAGS) $(CFLAGS) -MT tools/tools_iptables_unit-iptables-unit.o -MD -MP -MF tools/$(DEPDIR)/tools_iptables_unit-iptables-unit.Tpo -c -o tools/tools_iptables_unit-iptables-unit.o `test -f 'tools/iptables-unit.c' || echo '$(srcdir)/'`tools/iptables-unit.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) tools/$(DEPDIR)/tools_iptables_unit-iptables-unit.Tpo tools/$(DEPDIR)/tools_iptables_unit-iptables-unit.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='tools/iptables-unit.c' object='tools/tools_iptables_unit-iptables-unit.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(tools_iptables_unit_CFLAGS) $(CFLAGS) -c -o tools/tools_iptables_unit-iptables-unit.o `test -f 'tools/iptables-unit.c' || echo '$(srcdir)/'`tools/iptables-unit.c
+
+tools/tools_iptables_unit-iptables-unit.obj: tools/iptables-unit.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(tools_iptables_unit_CFLAGS) $(CFLAGS) -MT tools/tools_iptables_unit-iptables-unit.obj -MD -MP -MF tools/$(DEPDIR)/tools_iptables_unit-iptables-unit.Tpo -c -o tools/tools_iptables_unit-iptables-unit.obj `if test -f 'tools/iptables-unit.c'; then $(CYGPATH_W) 'tools/iptables-unit.c'; else $(CYGPATH_W) '$(srcdir)/tools/iptables-unit.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) tools/$(DEPDIR)/tools_iptables_unit-iptables-unit.Tpo tools/$(DEPDIR)/tools_iptables_unit-iptables-unit.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='tools/iptables-unit.c' object='tools/tools_iptables_unit-iptables-unit.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(tools_iptables_unit_CFLAGS) $(CFLAGS) -c -o tools/tools_iptables_unit-iptables-unit.obj `if test -f 'tools/iptables-unit.c'; then $(CYGPATH_W) 'tools/iptables-unit.c'; else $(CYGPATH_W) '$(srcdir)/tools/iptables-unit.c'; fi`
+
+vpn/plugins/vpn_connman_vpnd-openconnect.o: vpn/plugins/openconnect.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -MT vpn/plugins/vpn_connman_vpnd-openconnect.o -MD -MP -MF vpn/plugins/$(DEPDIR)/vpn_connman_vpnd-openconnect.Tpo -c -o vpn/plugins/vpn_connman_vpnd-openconnect.o `test -f 'vpn/plugins/openconnect.c' || echo '$(srcdir)/'`vpn/plugins/openconnect.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) vpn/plugins/$(DEPDIR)/vpn_connman_vpnd-openconnect.Tpo vpn/plugins/$(DEPDIR)/vpn_connman_vpnd-openconnect.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='vpn/plugins/openconnect.c' object='vpn/plugins/vpn_connman_vpnd-openconnect.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -c -o vpn/plugins/vpn_connman_vpnd-openconnect.o `test -f 'vpn/plugins/openconnect.c' || echo '$(srcdir)/'`vpn/plugins/openconnect.c
+
+vpn/plugins/vpn_connman_vpnd-openconnect.obj: vpn/plugins/openconnect.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -MT vpn/plugins/vpn_connman_vpnd-openconnect.obj -MD -MP -MF vpn/plugins/$(DEPDIR)/vpn_connman_vpnd-openconnect.Tpo -c -o vpn/plugins/vpn_connman_vpnd-openconnect.obj `if test -f 'vpn/plugins/openconnect.c'; then $(CYGPATH_W) 'vpn/plugins/openconnect.c'; else $(CYGPATH_W) '$(srcdir)/vpn/plugins/openconnect.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) vpn/plugins/$(DEPDIR)/vpn_connman_vpnd-openconnect.Tpo vpn/plugins/$(DEPDIR)/vpn_connman_vpnd-openconnect.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='vpn/plugins/openconnect.c' object='vpn/plugins/vpn_connman_vpnd-openconnect.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -c -o vpn/plugins/vpn_connman_vpnd-openconnect.obj `if test -f 'vpn/plugins/openconnect.c'; then $(CYGPATH_W) 'vpn/plugins/openconnect.c'; else $(CYGPATH_W) '$(srcdir)/vpn/plugins/openconnect.c'; fi`
+
+vpn/plugins/vpn_connman_vpnd-openvpn.o: vpn/plugins/openvpn.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -MT vpn/plugins/vpn_connman_vpnd-openvpn.o -MD -MP -MF vpn/plugins/$(DEPDIR)/vpn_connman_vpnd-openvpn.Tpo -c -o vpn/plugins/vpn_connman_vpnd-openvpn.o `test -f 'vpn/plugins/openvpn.c' || echo '$(srcdir)/'`vpn/plugins/openvpn.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) vpn/plugins/$(DEPDIR)/vpn_connman_vpnd-openvpn.Tpo vpn/plugins/$(DEPDIR)/vpn_connman_vpnd-openvpn.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='vpn/plugins/openvpn.c' object='vpn/plugins/vpn_connman_vpnd-openvpn.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -c -o vpn/plugins/vpn_connman_vpnd-openvpn.o `test -f 'vpn/plugins/openvpn.c' || echo '$(srcdir)/'`vpn/plugins/openvpn.c
+
+vpn/plugins/vpn_connman_vpnd-openvpn.obj: vpn/plugins/openvpn.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -MT vpn/plugins/vpn_connman_vpnd-openvpn.obj -MD -MP -MF vpn/plugins/$(DEPDIR)/vpn_connman_vpnd-openvpn.Tpo -c -o vpn/plugins/vpn_connman_vpnd-openvpn.obj `if test -f 'vpn/plugins/openvpn.c'; then $(CYGPATH_W) 'vpn/plugins/openvpn.c'; else $(CYGPATH_W) '$(srcdir)/vpn/plugins/openvpn.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) vpn/plugins/$(DEPDIR)/vpn_connman_vpnd-openvpn.Tpo vpn/plugins/$(DEPDIR)/vpn_connman_vpnd-openvpn.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='vpn/plugins/openvpn.c' object='vpn/plugins/vpn_connman_vpnd-openvpn.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -c -o vpn/plugins/vpn_connman_vpnd-openvpn.obj `if test -f 'vpn/plugins/openvpn.c'; then $(CYGPATH_W) 'vpn/plugins/openvpn.c'; else $(CYGPATH_W) '$(srcdir)/vpn/plugins/openvpn.c'; fi`
+
+vpn/plugins/vpn_connman_vpnd-vpnc.o: vpn/plugins/vpnc.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -MT vpn/plugins/vpn_connman_vpnd-vpnc.o -MD -MP -MF vpn/plugins/$(DEPDIR)/vpn_connman_vpnd-vpnc.Tpo -c -o vpn/plugins/vpn_connman_vpnd-vpnc.o `test -f 'vpn/plugins/vpnc.c' || echo '$(srcdir)/'`vpn/plugins/vpnc.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) vpn/plugins/$(DEPDIR)/vpn_connman_vpnd-vpnc.Tpo vpn/plugins/$(DEPDIR)/vpn_connman_vpnd-vpnc.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='vpn/plugins/vpnc.c' object='vpn/plugins/vpn_connman_vpnd-vpnc.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -c -o vpn/plugins/vpn_connman_vpnd-vpnc.o `test -f 'vpn/plugins/vpnc.c' || echo '$(srcdir)/'`vpn/plugins/vpnc.c
+
+vpn/plugins/vpn_connman_vpnd-vpnc.obj: vpn/plugins/vpnc.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -MT vpn/plugins/vpn_connman_vpnd-vpnc.obj -MD -MP -MF vpn/plugins/$(DEPDIR)/vpn_connman_vpnd-vpnc.Tpo -c -o vpn/plugins/vpn_connman_vpnd-vpnc.obj `if test -f 'vpn/plugins/vpnc.c'; then $(CYGPATH_W) 'vpn/plugins/vpnc.c'; else $(CYGPATH_W) '$(srcdir)/vpn/plugins/vpnc.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) vpn/plugins/$(DEPDIR)/vpn_connman_vpnd-vpnc.Tpo vpn/plugins/$(DEPDIR)/vpn_connman_vpnd-vpnc.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='vpn/plugins/vpnc.c' object='vpn/plugins/vpn_connman_vpnd-vpnc.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -c -o vpn/plugins/vpn_connman_vpnd-vpnc.obj `if test -f 'vpn/plugins/vpnc.c'; then $(CYGPATH_W) 'vpn/plugins/vpnc.c'; else $(CYGPATH_W) '$(srcdir)/vpn/plugins/vpnc.c'; fi`
+
+vpn/plugins/vpn_connman_vpnd-l2tp.o: vpn/plugins/l2tp.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -MT vpn/plugins/vpn_connman_vpnd-l2tp.o -MD -MP -MF vpn/plugins/$(DEPDIR)/vpn_connman_vpnd-l2tp.Tpo -c -o vpn/plugins/vpn_connman_vpnd-l2tp.o `test -f 'vpn/plugins/l2tp.c' || echo '$(srcdir)/'`vpn/plugins/l2tp.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) vpn/plugins/$(DEPDIR)/vpn_connman_vpnd-l2tp.Tpo vpn/plugins/$(DEPDIR)/vpn_connman_vpnd-l2tp.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='vpn/plugins/l2tp.c' object='vpn/plugins/vpn_connman_vpnd-l2tp.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -c -o vpn/plugins/vpn_connman_vpnd-l2tp.o `test -f 'vpn/plugins/l2tp.c' || echo '$(srcdir)/'`vpn/plugins/l2tp.c
+
+vpn/plugins/vpn_connman_vpnd-l2tp.obj: vpn/plugins/l2tp.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -MT vpn/plugins/vpn_connman_vpnd-l2tp.obj -MD -MP -MF vpn/plugins/$(DEPDIR)/vpn_connman_vpnd-l2tp.Tpo -c -o vpn/plugins/vpn_connman_vpnd-l2tp.obj `if test -f 'vpn/plugins/l2tp.c'; then $(CYGPATH_W) 'vpn/plugins/l2tp.c'; else $(CYGPATH_W) '$(srcdir)/vpn/plugins/l2tp.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) vpn/plugins/$(DEPDIR)/vpn_connman_vpnd-l2tp.Tpo vpn/plugins/$(DEPDIR)/vpn_connman_vpnd-l2tp.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='vpn/plugins/l2tp.c' object='vpn/plugins/vpn_connman_vpnd-l2tp.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -c -o vpn/plugins/vpn_connman_vpnd-l2tp.obj `if test -f 'vpn/plugins/l2tp.c'; then $(CYGPATH_W) 'vpn/plugins/l2tp.c'; else $(CYGPATH_W) '$(srcdir)/vpn/plugins/l2tp.c'; fi`
+
+vpn/plugins/vpn_connman_vpnd-pptp.o: vpn/plugins/pptp.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -MT vpn/plugins/vpn_connman_vpnd-pptp.o -MD -MP -MF vpn/plugins/$(DEPDIR)/vpn_connman_vpnd-pptp.Tpo -c -o vpn/plugins/vpn_connman_vpnd-pptp.o `test -f 'vpn/plugins/pptp.c' || echo '$(srcdir)/'`vpn/plugins/pptp.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) vpn/plugins/$(DEPDIR)/vpn_connman_vpnd-pptp.Tpo vpn/plugins/$(DEPDIR)/vpn_connman_vpnd-pptp.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='vpn/plugins/pptp.c' object='vpn/plugins/vpn_connman_vpnd-pptp.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -c -o vpn/plugins/vpn_connman_vpnd-pptp.o `test -f 'vpn/plugins/pptp.c' || echo '$(srcdir)/'`vpn/plugins/pptp.c
+
+vpn/plugins/vpn_connman_vpnd-pptp.obj: vpn/plugins/pptp.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -MT vpn/plugins/vpn_connman_vpnd-pptp.obj -MD -MP -MF vpn/plugins/$(DEPDIR)/vpn_connman_vpnd-pptp.Tpo -c -o vpn/plugins/vpn_connman_vpnd-pptp.obj `if test -f 'vpn/plugins/pptp.c'; then $(CYGPATH_W) 'vpn/plugins/pptp.c'; else $(CYGPATH_W) '$(srcdir)/vpn/plugins/pptp.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) vpn/plugins/$(DEPDIR)/vpn_connman_vpnd-pptp.Tpo vpn/plugins/$(DEPDIR)/vpn_connman_vpnd-pptp.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='vpn/plugins/pptp.c' object='vpn/plugins/vpn_connman_vpnd-pptp.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -c -o vpn/plugins/vpn_connman_vpnd-pptp.obj `if test -f 'vpn/plugins/pptp.c'; then $(CYGPATH_W) 'vpn/plugins/pptp.c'; else $(CYGPATH_W) '$(srcdir)/vpn/plugins/pptp.c'; fi`
+
+vpn/plugins/vpn_connman_vpnd-vpn.o: vpn/plugins/vpn.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -MT vpn/plugins/vpn_connman_vpnd-vpn.o -MD -MP -MF vpn/plugins/$(DEPDIR)/vpn_connman_vpnd-vpn.Tpo -c -o vpn/plugins/vpn_connman_vpnd-vpn.o `test -f 'vpn/plugins/vpn.c' || echo '$(srcdir)/'`vpn/plugins/vpn.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) vpn/plugins/$(DEPDIR)/vpn_connman_vpnd-vpn.Tpo vpn/plugins/$(DEPDIR)/vpn_connman_vpnd-vpn.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='vpn/plugins/vpn.c' object='vpn/plugins/vpn_connman_vpnd-vpn.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -c -o vpn/plugins/vpn_connman_vpnd-vpn.o `test -f 'vpn/plugins/vpn.c' || echo '$(srcdir)/'`vpn/plugins/vpn.c
+
+vpn/plugins/vpn_connman_vpnd-vpn.obj: vpn/plugins/vpn.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -MT vpn/plugins/vpn_connman_vpnd-vpn.obj -MD -MP -MF vpn/plugins/$(DEPDIR)/vpn_connman_vpnd-vpn.Tpo -c -o vpn/plugins/vpn_connman_vpnd-vpn.obj `if test -f 'vpn/plugins/vpn.c'; then $(CYGPATH_W) 'vpn/plugins/vpn.c'; else $(CYGPATH_W) '$(srcdir)/vpn/plugins/vpn.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) vpn/plugins/$(DEPDIR)/vpn_connman_vpnd-vpn.Tpo vpn/plugins/$(DEPDIR)/vpn_connman_vpnd-vpn.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='vpn/plugins/vpn.c' object='vpn/plugins/vpn_connman_vpnd-vpn.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -c -o vpn/plugins/vpn_connman_vpnd-vpn.obj `if test -f 'vpn/plugins/vpn.c'; then $(CYGPATH_W) 'vpn/plugins/vpn.c'; else $(CYGPATH_W) '$(srcdir)/vpn/plugins/vpn.c'; fi`
+
+gweb/vpn_connman_vpnd-gweb.o: gweb/gweb.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -MT gweb/vpn_connman_vpnd-gweb.o -MD -MP -MF gweb/$(DEPDIR)/vpn_connman_vpnd-gweb.Tpo -c -o gweb/vpn_connman_vpnd-gweb.o `test -f 'gweb/gweb.c' || echo '$(srcdir)/'`gweb/gweb.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) gweb/$(DEPDIR)/vpn_connman_vpnd-gweb.Tpo gweb/$(DEPDIR)/vpn_connman_vpnd-gweb.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='gweb/gweb.c' object='gweb/vpn_connman_vpnd-gweb.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -c -o gweb/vpn_connman_vpnd-gweb.o `test -f 'gweb/gweb.c' || echo '$(srcdir)/'`gweb/gweb.c
+
+gweb/vpn_connman_vpnd-gweb.obj: gweb/gweb.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -MT gweb/vpn_connman_vpnd-gweb.obj -MD -MP -MF gweb/$(DEPDIR)/vpn_connman_vpnd-gweb.Tpo -c -o gweb/vpn_connman_vpnd-gweb.obj `if test -f 'gweb/gweb.c'; then $(CYGPATH_W) 'gweb/gweb.c'; else $(CYGPATH_W) '$(srcdir)/gweb/gweb.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) gweb/$(DEPDIR)/vpn_connman_vpnd-gweb.Tpo gweb/$(DEPDIR)/vpn_connman_vpnd-gweb.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='gweb/gweb.c' object='gweb/vpn_connman_vpnd-gweb.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -c -o gweb/vpn_connman_vpnd-gweb.obj `if test -f 'gweb/gweb.c'; then $(CYGPATH_W) 'gweb/gweb.c'; else $(CYGPATH_W) '$(srcdir)/gweb/gweb.c'; fi`
+
+gweb/vpn_connman_vpnd-gresolv.o: gweb/gresolv.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -MT gweb/vpn_connman_vpnd-gresolv.o -MD -MP -MF gweb/$(DEPDIR)/vpn_connman_vpnd-gresolv.Tpo -c -o gweb/vpn_connman_vpnd-gresolv.o `test -f 'gweb/gresolv.c' || echo '$(srcdir)/'`gweb/gresolv.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) gweb/$(DEPDIR)/vpn_connman_vpnd-gresolv.Tpo gweb/$(DEPDIR)/vpn_connman_vpnd-gresolv.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='gweb/gresolv.c' object='gweb/vpn_connman_vpnd-gresolv.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -c -o gweb/vpn_connman_vpnd-gresolv.o `test -f 'gweb/gresolv.c' || echo '$(srcdir)/'`gweb/gresolv.c
+
+gweb/vpn_connman_vpnd-gresolv.obj: gweb/gresolv.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -MT gweb/vpn_connman_vpnd-gresolv.obj -MD -MP -MF gweb/$(DEPDIR)/vpn_connman_vpnd-gresolv.Tpo -c -o gweb/vpn_connman_vpnd-gresolv.obj `if test -f 'gweb/gresolv.c'; then $(CYGPATH_W) 'gweb/gresolv.c'; else $(CYGPATH_W) '$(srcdir)/gweb/gresolv.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) gweb/$(DEPDIR)/vpn_connman_vpnd-gresolv.Tpo gweb/$(DEPDIR)/vpn_connman_vpnd-gresolv.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='gweb/gresolv.c' object='gweb/vpn_connman_vpnd-gresolv.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -c -o gweb/vpn_connman_vpnd-gresolv.obj `if test -f 'gweb/gresolv.c'; then $(CYGPATH_W) 'gweb/gresolv.c'; else $(CYGPATH_W) '$(srcdir)/gweb/gresolv.c'; fi`
+
+gweb/vpn_connman_vpnd-giognutls.o: gweb/giognutls.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -MT gweb/vpn_connman_vpnd-giognutls.o -MD -MP -MF gweb/$(DEPDIR)/vpn_connman_vpnd-giognutls.Tpo -c -o gweb/vpn_connman_vpnd-giognutls.o `test -f 'gweb/giognutls.c' || echo '$(srcdir)/'`gweb/giognutls.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) gweb/$(DEPDIR)/vpn_connman_vpnd-giognutls.Tpo gweb/$(DEPDIR)/vpn_connman_vpnd-giognutls.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='gweb/giognutls.c' object='gweb/vpn_connman_vpnd-giognutls.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -c -o gweb/vpn_connman_vpnd-giognutls.o `test -f 'gweb/giognutls.c' || echo '$(srcdir)/'`gweb/giognutls.c
+
+gweb/vpn_connman_vpnd-giognutls.obj: gweb/giognutls.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -MT gweb/vpn_connman_vpnd-giognutls.obj -MD -MP -MF gweb/$(DEPDIR)/vpn_connman_vpnd-giognutls.Tpo -c -o gweb/vpn_connman_vpnd-giognutls.obj `if test -f 'gweb/giognutls.c'; then $(CYGPATH_W) 'gweb/giognutls.c'; else $(CYGPATH_W) '$(srcdir)/gweb/giognutls.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) gweb/$(DEPDIR)/vpn_connman_vpnd-giognutls.Tpo gweb/$(DEPDIR)/vpn_connman_vpnd-giognutls.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='gweb/giognutls.c' object='gweb/vpn_connman_vpnd-giognutls.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -c -o gweb/vpn_connman_vpnd-giognutls.obj `if test -f 'gweb/giognutls.c'; then $(CYGPATH_W) 'gweb/giognutls.c'; else $(CYGPATH_W) '$(srcdir)/gweb/giognutls.c'; fi`
+
+gweb/vpn_connman_vpnd-gionotls.o: gweb/gionotls.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -MT gweb/vpn_connman_vpnd-gionotls.o -MD -MP -MF gweb/$(DEPDIR)/vpn_connman_vpnd-gionotls.Tpo -c -o gweb/vpn_connman_vpnd-gionotls.o `test -f 'gweb/gionotls.c' || echo '$(srcdir)/'`gweb/gionotls.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) gweb/$(DEPDIR)/vpn_connman_vpnd-gionotls.Tpo gweb/$(DEPDIR)/vpn_connman_vpnd-gionotls.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='gweb/gionotls.c' object='gweb/vpn_connman_vpnd-gionotls.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -c -o gweb/vpn_connman_vpnd-gionotls.o `test -f 'gweb/gionotls.c' || echo '$(srcdir)/'`gweb/gionotls.c
+
+gweb/vpn_connman_vpnd-gionotls.obj: gweb/gionotls.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -MT gweb/vpn_connman_vpnd-gionotls.obj -MD -MP -MF gweb/$(DEPDIR)/vpn_connman_vpnd-gionotls.Tpo -c -o gweb/vpn_connman_vpnd-gionotls.obj `if test -f 'gweb/gionotls.c'; then $(CYGPATH_W) 'gweb/gionotls.c'; else $(CYGPATH_W) '$(srcdir)/gweb/gionotls.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) gweb/$(DEPDIR)/vpn_connman_vpnd-gionotls.Tpo gweb/$(DEPDIR)/vpn_connman_vpnd-gionotls.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='gweb/gionotls.c' object='gweb/vpn_connman_vpnd-gionotls.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -c -o gweb/vpn_connman_vpnd-gionotls.obj `if test -f 'gweb/gionotls.c'; then $(CYGPATH_W) 'gweb/gionotls.c'; else $(CYGPATH_W) '$(srcdir)/gweb/gionotls.c'; fi`
+
+vpn/vpn_connman_vpnd-main.o: vpn/main.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -MT vpn/vpn_connman_vpnd-main.o -MD -MP -MF vpn/$(DEPDIR)/vpn_connman_vpnd-main.Tpo -c -o vpn/vpn_connman_vpnd-main.o `test -f 'vpn/main.c' || echo '$(srcdir)/'`vpn/main.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) vpn/$(DEPDIR)/vpn_connman_vpnd-main.Tpo vpn/$(DEPDIR)/vpn_connman_vpnd-main.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='vpn/main.c' object='vpn/vpn_connman_vpnd-main.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -c -o vpn/vpn_connman_vpnd-main.o `test -f 'vpn/main.c' || echo '$(srcdir)/'`vpn/main.c
+
+vpn/vpn_connman_vpnd-main.obj: vpn/main.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -MT vpn/vpn_connman_vpnd-main.obj -MD -MP -MF vpn/$(DEPDIR)/vpn_connman_vpnd-main.Tpo -c -o vpn/vpn_connman_vpnd-main.obj `if test -f 'vpn/main.c'; then $(CYGPATH_W) 'vpn/main.c'; else $(CYGPATH_W) '$(srcdir)/vpn/main.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) vpn/$(DEPDIR)/vpn_connman_vpnd-main.Tpo vpn/$(DEPDIR)/vpn_connman_vpnd-main.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='vpn/main.c' object='vpn/vpn_connman_vpnd-main.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -c -o vpn/vpn_connman_vpnd-main.obj `if test -f 'vpn/main.c'; then $(CYGPATH_W) 'vpn/main.c'; else $(CYGPATH_W) '$(srcdir)/vpn/main.c'; fi`
+
+src/vpn_connman_vpnd-log.o: src/log.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -MT src/vpn_connman_vpnd-log.o -MD -MP -MF src/$(DEPDIR)/vpn_connman_vpnd-log.Tpo -c -o src/vpn_connman_vpnd-log.o `test -f 'src/log.c' || echo '$(srcdir)/'`src/log.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/vpn_connman_vpnd-log.Tpo src/$(DEPDIR)/vpn_connman_vpnd-log.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/log.c' object='src/vpn_connman_vpnd-log.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -c -o src/vpn_connman_vpnd-log.o `test -f 'src/log.c' || echo '$(srcdir)/'`src/log.c
+
+src/vpn_connman_vpnd-log.obj: src/log.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -MT src/vpn_connman_vpnd-log.obj -MD -MP -MF src/$(DEPDIR)/vpn_connman_vpnd-log.Tpo -c -o src/vpn_connman_vpnd-log.obj `if test -f 'src/log.c'; then $(CYGPATH_W) 'src/log.c'; else $(CYGPATH_W) '$(srcdir)/src/log.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/vpn_connman_vpnd-log.Tpo src/$(DEPDIR)/vpn_connman_vpnd-log.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/log.c' object='src/vpn_connman_vpnd-log.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -c -o src/vpn_connman_vpnd-log.obj `if test -f 'src/log.c'; then $(CYGPATH_W) 'src/log.c'; else $(CYGPATH_W) '$(srcdir)/src/log.c'; fi`
+
+src/vpn_connman_vpnd-error.o: src/error.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -MT src/vpn_connman_vpnd-error.o -MD -MP -MF src/$(DEPDIR)/vpn_connman_vpnd-error.Tpo -c -o src/vpn_connman_vpnd-error.o `test -f 'src/error.c' || echo '$(srcdir)/'`src/error.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/vpn_connman_vpnd-error.Tpo src/$(DEPDIR)/vpn_connman_vpnd-error.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/error.c' object='src/vpn_connman_vpnd-error.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -c -o src/vpn_connman_vpnd-error.o `test -f 'src/error.c' || echo '$(srcdir)/'`src/error.c
+
+src/vpn_connman_vpnd-error.obj: src/error.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -MT src/vpn_connman_vpnd-error.obj -MD -MP -MF src/$(DEPDIR)/vpn_connman_vpnd-error.Tpo -c -o src/vpn_connman_vpnd-error.obj `if test -f 'src/error.c'; then $(CYGPATH_W) 'src/error.c'; else $(CYGPATH_W) '$(srcdir)/src/error.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/vpn_connman_vpnd-error.Tpo src/$(DEPDIR)/vpn_connman_vpnd-error.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/error.c' object='src/vpn_connman_vpnd-error.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -c -o src/vpn_connman_vpnd-error.obj `if test -f 'src/error.c'; then $(CYGPATH_W) 'src/error.c'; else $(CYGPATH_W) '$(srcdir)/src/error.c'; fi`
+
+src/vpn_connman_vpnd-plugin.o: src/plugin.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -MT src/vpn_connman_vpnd-plugin.o -MD -MP -MF src/$(DEPDIR)/vpn_connman_vpnd-plugin.Tpo -c -o src/vpn_connman_vpnd-plugin.o `test -f 'src/plugin.c' || echo '$(srcdir)/'`src/plugin.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/vpn_connman_vpnd-plugin.Tpo src/$(DEPDIR)/vpn_connman_vpnd-plugin.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/plugin.c' object='src/vpn_connman_vpnd-plugin.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -c -o src/vpn_connman_vpnd-plugin.o `test -f 'src/plugin.c' || echo '$(srcdir)/'`src/plugin.c
+
+src/vpn_connman_vpnd-plugin.obj: src/plugin.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -MT src/vpn_connman_vpnd-plugin.obj -MD -MP -MF src/$(DEPDIR)/vpn_connman_vpnd-plugin.Tpo -c -o src/vpn_connman_vpnd-plugin.obj `if test -f 'src/plugin.c'; then $(CYGPATH_W) 'src/plugin.c'; else $(CYGPATH_W) '$(srcdir)/src/plugin.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/vpn_connman_vpnd-plugin.Tpo src/$(DEPDIR)/vpn_connman_vpnd-plugin.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/plugin.c' object='src/vpn_connman_vpnd-plugin.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -c -o src/vpn_connman_vpnd-plugin.obj `if test -f 'src/plugin.c'; then $(CYGPATH_W) 'src/plugin.c'; else $(CYGPATH_W) '$(srcdir)/src/plugin.c'; fi`
+
+src/vpn_connman_vpnd-task.o: src/task.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -MT src/vpn_connman_vpnd-task.o -MD -MP -MF src/$(DEPDIR)/vpn_connman_vpnd-task.Tpo -c -o src/vpn_connman_vpnd-task.o `test -f 'src/task.c' || echo '$(srcdir)/'`src/task.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/vpn_connman_vpnd-task.Tpo src/$(DEPDIR)/vpn_connman_vpnd-task.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/task.c' object='src/vpn_connman_vpnd-task.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -c -o src/vpn_connman_vpnd-task.o `test -f 'src/task.c' || echo '$(srcdir)/'`src/task.c
+
+src/vpn_connman_vpnd-task.obj: src/task.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -MT src/vpn_connman_vpnd-task.obj -MD -MP -MF src/$(DEPDIR)/vpn_connman_vpnd-task.Tpo -c -o src/vpn_connman_vpnd-task.obj `if test -f 'src/task.c'; then $(CYGPATH_W) 'src/task.c'; else $(CYGPATH_W) '$(srcdir)/src/task.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/vpn_connman_vpnd-task.Tpo src/$(DEPDIR)/vpn_connman_vpnd-task.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/task.c' object='src/vpn_connman_vpnd-task.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -c -o src/vpn_connman_vpnd-task.obj `if test -f 'src/task.c'; then $(CYGPATH_W) 'src/task.c'; else $(CYGPATH_W) '$(srcdir)/src/task.c'; fi`
+
+vpn/vpn_connman_vpnd-vpn-manager.o: vpn/vpn-manager.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -MT vpn/vpn_connman_vpnd-vpn-manager.o -MD -MP -MF vpn/$(DEPDIR)/vpn_connman_vpnd-vpn-manager.Tpo -c -o vpn/vpn_connman_vpnd-vpn-manager.o `test -f 'vpn/vpn-manager.c' || echo '$(srcdir)/'`vpn/vpn-manager.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) vpn/$(DEPDIR)/vpn_connman_vpnd-vpn-manager.Tpo vpn/$(DEPDIR)/vpn_connman_vpnd-vpn-manager.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='vpn/vpn-manager.c' object='vpn/vpn_connman_vpnd-vpn-manager.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -c -o vpn/vpn_connman_vpnd-vpn-manager.o `test -f 'vpn/vpn-manager.c' || echo '$(srcdir)/'`vpn/vpn-manager.c
+
+vpn/vpn_connman_vpnd-vpn-manager.obj: vpn/vpn-manager.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -MT vpn/vpn_connman_vpnd-vpn-manager.obj -MD -MP -MF vpn/$(DEPDIR)/vpn_connman_vpnd-vpn-manager.Tpo -c -o vpn/vpn_connman_vpnd-vpn-manager.obj `if test -f 'vpn/vpn-manager.c'; then $(CYGPATH_W) 'vpn/vpn-manager.c'; else $(CYGPATH_W) '$(srcdir)/vpn/vpn-manager.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) vpn/$(DEPDIR)/vpn_connman_vpnd-vpn-manager.Tpo vpn/$(DEPDIR)/vpn_connman_vpnd-vpn-manager.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='vpn/vpn-manager.c' object='vpn/vpn_connman_vpnd-vpn-manager.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -c -o vpn/vpn_connman_vpnd-vpn-manager.obj `if test -f 'vpn/vpn-manager.c'; then $(CYGPATH_W) 'vpn/vpn-manager.c'; else $(CYGPATH_W) '$(srcdir)/vpn/vpn-manager.c'; fi`
+
+vpn/vpn_connman_vpnd-vpn-provider.o: vpn/vpn-provider.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -MT vpn/vpn_connman_vpnd-vpn-provider.o -MD -MP -MF vpn/$(DEPDIR)/vpn_connman_vpnd-vpn-provider.Tpo -c -o vpn/vpn_connman_vpnd-vpn-provider.o `test -f 'vpn/vpn-provider.c' || echo '$(srcdir)/'`vpn/vpn-provider.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) vpn/$(DEPDIR)/vpn_connman_vpnd-vpn-provider.Tpo vpn/$(DEPDIR)/vpn_connman_vpnd-vpn-provider.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='vpn/vpn-provider.c' object='vpn/vpn_connman_vpnd-vpn-provider.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -c -o vpn/vpn_connman_vpnd-vpn-provider.o `test -f 'vpn/vpn-provider.c' || echo '$(srcdir)/'`vpn/vpn-provider.c
+
+vpn/vpn_connman_vpnd-vpn-provider.obj: vpn/vpn-provider.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -MT vpn/vpn_connman_vpnd-vpn-provider.obj -MD -MP -MF vpn/$(DEPDIR)/vpn_connman_vpnd-vpn-provider.Tpo -c -o vpn/vpn_connman_vpnd-vpn-provider.obj `if test -f 'vpn/vpn-provider.c'; then $(CYGPATH_W) 'vpn/vpn-provider.c'; else $(CYGPATH_W) '$(srcdir)/vpn/vpn-provider.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) vpn/$(DEPDIR)/vpn_connman_vpnd-vpn-provider.Tpo vpn/$(DEPDIR)/vpn_connman_vpnd-vpn-provider.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='vpn/vpn-provider.c' object='vpn/vpn_connman_vpnd-vpn-provider.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -c -o vpn/vpn_connman_vpnd-vpn-provider.obj `if test -f 'vpn/vpn-provider.c'; then $(CYGPATH_W) 'vpn/vpn-provider.c'; else $(CYGPATH_W) '$(srcdir)/vpn/vpn-provider.c'; fi`
+
+vpn/vpn_connman_vpnd-vpn-ipconfig.o: vpn/vpn-ipconfig.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -MT vpn/vpn_connman_vpnd-vpn-ipconfig.o -MD -MP -MF vpn/$(DEPDIR)/vpn_connman_vpnd-vpn-ipconfig.Tpo -c -o vpn/vpn_connman_vpnd-vpn-ipconfig.o `test -f 'vpn/vpn-ipconfig.c' || echo '$(srcdir)/'`vpn/vpn-ipconfig.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) vpn/$(DEPDIR)/vpn_connman_vpnd-vpn-ipconfig.Tpo vpn/$(DEPDIR)/vpn_connman_vpnd-vpn-ipconfig.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='vpn/vpn-ipconfig.c' object='vpn/vpn_connman_vpnd-vpn-ipconfig.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -c -o vpn/vpn_connman_vpnd-vpn-ipconfig.o `test -f 'vpn/vpn-ipconfig.c' || echo '$(srcdir)/'`vpn/vpn-ipconfig.c
+
+vpn/vpn_connman_vpnd-vpn-ipconfig.obj: vpn/vpn-ipconfig.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -MT vpn/vpn_connman_vpnd-vpn-ipconfig.obj -MD -MP -MF vpn/$(DEPDIR)/vpn_connman_vpnd-vpn-ipconfig.Tpo -c -o vpn/vpn_connman_vpnd-vpn-ipconfig.obj `if test -f 'vpn/vpn-ipconfig.c'; then $(CYGPATH_W) 'vpn/vpn-ipconfig.c'; else $(CYGPATH_W) '$(srcdir)/vpn/vpn-ipconfig.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) vpn/$(DEPDIR)/vpn_connman_vpnd-vpn-ipconfig.Tpo vpn/$(DEPDIR)/vpn_connman_vpnd-vpn-ipconfig.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='vpn/vpn-ipconfig.c' object='vpn/vpn_connman_vpnd-vpn-ipconfig.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -c -o vpn/vpn_connman_vpnd-vpn-ipconfig.obj `if test -f 'vpn/vpn-ipconfig.c'; then $(CYGPATH_W) 'vpn/vpn-ipconfig.c'; else $(CYGPATH_W) '$(srcdir)/vpn/vpn-ipconfig.c'; fi`
+
+src/vpn_connman_vpnd-inet.o: src/inet.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -MT src/vpn_connman_vpnd-inet.o -MD -MP -MF src/$(DEPDIR)/vpn_connman_vpnd-inet.Tpo -c -o src/vpn_connman_vpnd-inet.o `test -f 'src/inet.c' || echo '$(srcdir)/'`src/inet.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/vpn_connman_vpnd-inet.Tpo src/$(DEPDIR)/vpn_connman_vpnd-inet.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/inet.c' object='src/vpn_connman_vpnd-inet.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -c -o src/vpn_connman_vpnd-inet.o `test -f 'src/inet.c' || echo '$(srcdir)/'`src/inet.c
+
+src/vpn_connman_vpnd-inet.obj: src/inet.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -MT src/vpn_connman_vpnd-inet.obj -MD -MP -MF src/$(DEPDIR)/vpn_connman_vpnd-inet.Tpo -c -o src/vpn_connman_vpnd-inet.obj `if test -f 'src/inet.c'; then $(CYGPATH_W) 'src/inet.c'; else $(CYGPATH_W) '$(srcdir)/src/inet.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/vpn_connman_vpnd-inet.Tpo src/$(DEPDIR)/vpn_connman_vpnd-inet.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/inet.c' object='src/vpn_connman_vpnd-inet.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -c -o src/vpn_connman_vpnd-inet.obj `if test -f 'src/inet.c'; then $(CYGPATH_W) 'src/inet.c'; else $(CYGPATH_W) '$(srcdir)/src/inet.c'; fi`
+
+vpn/vpn_connman_vpnd-vpn-rtnl.o: vpn/vpn-rtnl.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -MT vpn/vpn_connman_vpnd-vpn-rtnl.o -MD -MP -MF vpn/$(DEPDIR)/vpn_connman_vpnd-vpn-rtnl.Tpo -c -o vpn/vpn_connman_vpnd-vpn-rtnl.o `test -f 'vpn/vpn-rtnl.c' || echo '$(srcdir)/'`vpn/vpn-rtnl.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) vpn/$(DEPDIR)/vpn_connman_vpnd-vpn-rtnl.Tpo vpn/$(DEPDIR)/vpn_connman_vpnd-vpn-rtnl.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='vpn/vpn-rtnl.c' object='vpn/vpn_connman_vpnd-vpn-rtnl.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -c -o vpn/vpn_connman_vpnd-vpn-rtnl.o `test -f 'vpn/vpn-rtnl.c' || echo '$(srcdir)/'`vpn/vpn-rtnl.c
+
+vpn/vpn_connman_vpnd-vpn-rtnl.obj: vpn/vpn-rtnl.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -MT vpn/vpn_connman_vpnd-vpn-rtnl.obj -MD -MP -MF vpn/$(DEPDIR)/vpn_connman_vpnd-vpn-rtnl.Tpo -c -o vpn/vpn_connman_vpnd-vpn-rtnl.obj `if test -f 'vpn/vpn-rtnl.c'; then $(CYGPATH_W) 'vpn/vpn-rtnl.c'; else $(CYGPATH_W) '$(srcdir)/vpn/vpn-rtnl.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) vpn/$(DEPDIR)/vpn_connman_vpnd-vpn-rtnl.Tpo vpn/$(DEPDIR)/vpn_connman_vpnd-vpn-rtnl.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='vpn/vpn-rtnl.c' object='vpn/vpn_connman_vpnd-vpn-rtnl.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -c -o vpn/vpn_connman_vpnd-vpn-rtnl.obj `if test -f 'vpn/vpn-rtnl.c'; then $(CYGPATH_W) 'vpn/vpn-rtnl.c'; else $(CYGPATH_W) '$(srcdir)/vpn/vpn-rtnl.c'; fi`
+
+src/vpn_connman_vpnd-dbus.o: src/dbus.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -MT src/vpn_connman_vpnd-dbus.o -MD -MP -MF src/$(DEPDIR)/vpn_connman_vpnd-dbus.Tpo -c -o src/vpn_connman_vpnd-dbus.o `test -f 'src/dbus.c' || echo '$(srcdir)/'`src/dbus.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/vpn_connman_vpnd-dbus.Tpo src/$(DEPDIR)/vpn_connman_vpnd-dbus.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/dbus.c' object='src/vpn_connman_vpnd-dbus.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -c -o src/vpn_connman_vpnd-dbus.o `test -f 'src/dbus.c' || echo '$(srcdir)/'`src/dbus.c
+
+src/vpn_connman_vpnd-dbus.obj: src/dbus.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -MT src/vpn_connman_vpnd-dbus.obj -MD -MP -MF src/$(DEPDIR)/vpn_connman_vpnd-dbus.Tpo -c -o src/vpn_connman_vpnd-dbus.obj `if test -f 'src/dbus.c'; then $(CYGPATH_W) 'src/dbus.c'; else $(CYGPATH_W) '$(srcdir)/src/dbus.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/vpn_connman_vpnd-dbus.Tpo src/$(DEPDIR)/vpn_connman_vpnd-dbus.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/dbus.c' object='src/vpn_connman_vpnd-dbus.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -c -o src/vpn_connman_vpnd-dbus.obj `if test -f 'src/dbus.c'; then $(CYGPATH_W) 'src/dbus.c'; else $(CYGPATH_W) '$(srcdir)/src/dbus.c'; fi`
+
+src/vpn_connman_vpnd-storage.o: src/storage.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -MT src/vpn_connman_vpnd-storage.o -MD -MP -MF src/$(DEPDIR)/vpn_connman_vpnd-storage.Tpo -c -o src/vpn_connman_vpnd-storage.o `test -f 'src/storage.c' || echo '$(srcdir)/'`src/storage.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/vpn_connman_vpnd-storage.Tpo src/$(DEPDIR)/vpn_connman_vpnd-storage.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/storage.c' object='src/vpn_connman_vpnd-storage.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -c -o src/vpn_connman_vpnd-storage.o `test -f 'src/storage.c' || echo '$(srcdir)/'`src/storage.c
+
+src/vpn_connman_vpnd-storage.obj: src/storage.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -MT src/vpn_connman_vpnd-storage.obj -MD -MP -MF src/$(DEPDIR)/vpn_connman_vpnd-storage.Tpo -c -o src/vpn_connman_vpnd-storage.obj `if test -f 'src/storage.c'; then $(CYGPATH_W) 'src/storage.c'; else $(CYGPATH_W) '$(srcdir)/src/storage.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/vpn_connman_vpnd-storage.Tpo src/$(DEPDIR)/vpn_connman_vpnd-storage.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/storage.c' object='src/vpn_connman_vpnd-storage.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -c -o src/vpn_connman_vpnd-storage.obj `if test -f 'src/storage.c'; then $(CYGPATH_W) 'src/storage.c'; else $(CYGPATH_W) '$(srcdir)/src/storage.c'; fi`
+
+src/vpn_connman_vpnd-ipaddress.o: src/ipaddress.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -MT src/vpn_connman_vpnd-ipaddress.o -MD -MP -MF src/$(DEPDIR)/vpn_connman_vpnd-ipaddress.Tpo -c -o src/vpn_connman_vpnd-ipaddress.o `test -f 'src/ipaddress.c' || echo '$(srcdir)/'`src/ipaddress.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/vpn_connman_vpnd-ipaddress.Tpo src/$(DEPDIR)/vpn_connman_vpnd-ipaddress.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/ipaddress.c' object='src/vpn_connman_vpnd-ipaddress.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -c -o src/vpn_connman_vpnd-ipaddress.o `test -f 'src/ipaddress.c' || echo '$(srcdir)/'`src/ipaddress.c
+
+src/vpn_connman_vpnd-ipaddress.obj: src/ipaddress.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -MT src/vpn_connman_vpnd-ipaddress.obj -MD -MP -MF src/$(DEPDIR)/vpn_connman_vpnd-ipaddress.Tpo -c -o src/vpn_connman_vpnd-ipaddress.obj `if test -f 'src/ipaddress.c'; then $(CYGPATH_W) 'src/ipaddress.c'; else $(CYGPATH_W) '$(srcdir)/src/ipaddress.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/vpn_connman_vpnd-ipaddress.Tpo src/$(DEPDIR)/vpn_connman_vpnd-ipaddress.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/ipaddress.c' object='src/vpn_connman_vpnd-ipaddress.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -c -o src/vpn_connman_vpnd-ipaddress.obj `if test -f 'src/ipaddress.c'; then $(CYGPATH_W) 'src/ipaddress.c'; else $(CYGPATH_W) '$(srcdir)/src/ipaddress.c'; fi`
+
+src/vpn_connman_vpnd-agent.o: src/agent.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -MT src/vpn_connman_vpnd-agent.o -MD -MP -MF src/$(DEPDIR)/vpn_connman_vpnd-agent.Tpo -c -o src/vpn_connman_vpnd-agent.o `test -f 'src/agent.c' || echo '$(srcdir)/'`src/agent.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/vpn_connman_vpnd-agent.Tpo src/$(DEPDIR)/vpn_connman_vpnd-agent.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/agent.c' object='src/vpn_connman_vpnd-agent.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -c -o src/vpn_connman_vpnd-agent.o `test -f 'src/agent.c' || echo '$(srcdir)/'`src/agent.c
+
+src/vpn_connman_vpnd-agent.obj: src/agent.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -MT src/vpn_connman_vpnd-agent.obj -MD -MP -MF src/$(DEPDIR)/vpn_connman_vpnd-agent.Tpo -c -o src/vpn_connman_vpnd-agent.obj `if test -f 'src/agent.c'; then $(CYGPATH_W) 'src/agent.c'; else $(CYGPATH_W) '$(srcdir)/src/agent.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/vpn_connman_vpnd-agent.Tpo src/$(DEPDIR)/vpn_connman_vpnd-agent.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/agent.c' object='src/vpn_connman_vpnd-agent.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -c -o src/vpn_connman_vpnd-agent.obj `if test -f 'src/agent.c'; then $(CYGPATH_W) 'src/agent.c'; else $(CYGPATH_W) '$(srcdir)/src/agent.c'; fi`
+
+vpn/vpn_connman_vpnd-vpn-agent.o: vpn/vpn-agent.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -MT vpn/vpn_connman_vpnd-vpn-agent.o -MD -MP -MF vpn/$(DEPDIR)/vpn_connman_vpnd-vpn-agent.Tpo -c -o vpn/vpn_connman_vpnd-vpn-agent.o `test -f 'vpn/vpn-agent.c' || echo '$(srcdir)/'`vpn/vpn-agent.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) vpn/$(DEPDIR)/vpn_connman_vpnd-vpn-agent.Tpo vpn/$(DEPDIR)/vpn_connman_vpnd-vpn-agent.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='vpn/vpn-agent.c' object='vpn/vpn_connman_vpnd-vpn-agent.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -c -o vpn/vpn_connman_vpnd-vpn-agent.o `test -f 'vpn/vpn-agent.c' || echo '$(srcdir)/'`vpn/vpn-agent.c
+
+vpn/vpn_connman_vpnd-vpn-agent.obj: vpn/vpn-agent.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -MT vpn/vpn_connman_vpnd-vpn-agent.obj -MD -MP -MF vpn/$(DEPDIR)/vpn_connman_vpnd-vpn-agent.Tpo -c -o vpn/vpn_connman_vpnd-vpn-agent.obj `if test -f 'vpn/vpn-agent.c'; then $(CYGPATH_W) 'vpn/vpn-agent.c'; else $(CYGPATH_W) '$(srcdir)/vpn/vpn-agent.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) vpn/$(DEPDIR)/vpn_connman_vpnd-vpn-agent.Tpo vpn/$(DEPDIR)/vpn_connman_vpnd-vpn-agent.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='vpn/vpn-agent.c' object='vpn/vpn_connman_vpnd-vpn-agent.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -c -o vpn/vpn_connman_vpnd-vpn-agent.obj `if test -f 'vpn/vpn-agent.c'; then $(CYGPATH_W) 'vpn/vpn-agent.c'; else $(CYGPATH_W) '$(srcdir)/vpn/vpn-agent.c'; fi`
+
+src/vpn_connman_vpnd-inotify.o: src/inotify.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -MT src/vpn_connman_vpnd-inotify.o -MD -MP -MF src/$(DEPDIR)/vpn_connman_vpnd-inotify.Tpo -c -o src/vpn_connman_vpnd-inotify.o `test -f 'src/inotify.c' || echo '$(srcdir)/'`src/inotify.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/vpn_connman_vpnd-inotify.Tpo src/$(DEPDIR)/vpn_connman_vpnd-inotify.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/inotify.c' object='src/vpn_connman_vpnd-inotify.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -c -o src/vpn_connman_vpnd-inotify.o `test -f 'src/inotify.c' || echo '$(srcdir)/'`src/inotify.c
+
+src/vpn_connman_vpnd-inotify.obj: src/inotify.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -MT src/vpn_connman_vpnd-inotify.obj -MD -MP -MF src/$(DEPDIR)/vpn_connman_vpnd-inotify.Tpo -c -o src/vpn_connman_vpnd-inotify.obj `if test -f 'src/inotify.c'; then $(CYGPATH_W) 'src/inotify.c'; else $(CYGPATH_W) '$(srcdir)/src/inotify.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) src/$(DEPDIR)/vpn_connman_vpnd-inotify.Tpo src/$(DEPDIR)/vpn_connman_vpnd-inotify.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='src/inotify.c' object='src/vpn_connman_vpnd-inotify.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -c -o src/vpn_connman_vpnd-inotify.obj `if test -f 'src/inotify.c'; then $(CYGPATH_W) 'src/inotify.c'; else $(CYGPATH_W) '$(srcdir)/src/inotify.c'; fi`
+
+vpn/vpn_connman_vpnd-vpn-config.o: vpn/vpn-config.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -MT vpn/vpn_connman_vpnd-vpn-config.o -MD -MP -MF vpn/$(DEPDIR)/vpn_connman_vpnd-vpn-config.Tpo -c -o vpn/vpn_connman_vpnd-vpn-config.o `test -f 'vpn/vpn-config.c' || echo '$(srcdir)/'`vpn/vpn-config.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) vpn/$(DEPDIR)/vpn_connman_vpnd-vpn-config.Tpo vpn/$(DEPDIR)/vpn_connman_vpnd-vpn-config.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='vpn/vpn-config.c' object='vpn/vpn_connman_vpnd-vpn-config.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -c -o vpn/vpn_connman_vpnd-vpn-config.o `test -f 'vpn/vpn-config.c' || echo '$(srcdir)/'`vpn/vpn-config.c
+
+vpn/vpn_connman_vpnd-vpn-config.obj: vpn/vpn-config.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -MT vpn/vpn_connman_vpnd-vpn-config.obj -MD -MP -MF vpn/$(DEPDIR)/vpn_connman_vpnd-vpn-config.Tpo -c -o vpn/vpn_connman_vpnd-vpn-config.obj `if test -f 'vpn/vpn-config.c'; then $(CYGPATH_W) 'vpn/vpn-config.c'; else $(CYGPATH_W) '$(srcdir)/vpn/vpn-config.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) vpn/$(DEPDIR)/vpn_connman_vpnd-vpn-config.Tpo vpn/$(DEPDIR)/vpn_connman_vpnd-vpn-config.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='vpn/vpn-config.c' object='vpn/vpn_connman_vpnd-vpn-config.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vpn_connman_vpnd_CFLAGS) $(CFLAGS) -c -o vpn/vpn_connman_vpnd-vpn-config.obj `if test -f 'vpn/vpn-config.c'; then $(CYGPATH_W) 'vpn/vpn-config.c'; else $(CYGPATH_W) '$(srcdir)/vpn/vpn-config.c'; fi`
+
+mostlyclean-libtool:
+	-rm -f *.lo
+
+clean-libtool:
+	-rm -rf .libs _libs
+	-rm -rf client/.libs client/_libs
+	-rm -rf gdbus/.libs gdbus/_libs
+	-rm -rf plugins/.libs plugins/_libs
+	-rm -rf scripts/.libs scripts/_libs
+	-rm -rf src/.libs src/_libs
+	-rm -rf tools/.libs tools/_libs
+	-rm -rf unit/.libs unit/_libs
+	-rm -rf vpn/.libs vpn/_libs
+	-rm -rf vpn/plugins/.libs vpn/plugins/_libs
+
+distclean-libtool:
+	-rm -f libtool config.lt
+install-man1: $(dist_man_MANS)
+	@$(NORMAL_INSTALL)
+	@list1=''; \
+	list2='$(dist_man_MANS)'; \
+	test -n "$(man1dir)" \
+	  && test -n "`echo $$list1$$list2`" \
+	  || exit 0; \
+	echo " $(MKDIR_P) '$(DESTDIR)$(man1dir)'"; \
+	$(MKDIR_P) "$(DESTDIR)$(man1dir)" || exit 1; \
+	{ for i in $$list1; do echo "$$i"; done;  \
+	if test -n "$$list2"; then \
+	  for i in $$list2; do echo "$$i"; done \
+	    | sed -n '/\.1[a-z]*$$/p'; \
+	fi; \
+	} | while read p; do \
+	  if test -f $$p; then d=; else d="$(srcdir)/"; fi; \
+	  echo "$$d$$p"; echo "$$p"; \
+	done | \
+	sed -e 'n;s,.*/,,;p;h;s,.*\.,,;s,^[^1][0-9a-z]*$$,1,;x' \
+	      -e 's,\.[0-9a-z]*$$,,;$(transform);G;s,\n,.,' | \
+	sed 'N;N;s,\n, ,g' | { \
+	list=; while read file base inst; do \
+	  if test "$$base" = "$$inst"; then list="$$list $$file"; else \
+	    echo " $(INSTALL_DATA) '$$file' '$(DESTDIR)$(man1dir)/$$inst'"; \
+	    $(INSTALL_DATA) "$$file" "$(DESTDIR)$(man1dir)/$$inst" || exit $$?; \
+	  fi; \
+	done; \
+	for i in $$list; do echo "$$i"; done | $(am__base_list) | \
+	while read files; do \
+	  test -z "$$files" || { \
+	    echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(man1dir)'"; \
+	    $(INSTALL_DATA) $$files "$(DESTDIR)$(man1dir)" || exit $$?; }; \
+	done; }
+
+uninstall-man1:
+	@$(NORMAL_UNINSTALL)
+	@list=''; test -n "$(man1dir)" || exit 0; \
+	files=`{ for i in $$list; do echo "$$i"; done; \
+	l2='$(dist_man_MANS)'; for i in $$l2; do echo "$$i"; done | \
+	  sed -n '/\.1[a-z]*$$/p'; \
+	} | sed -e 's,.*/,,;h;s,.*\.,,;s,^[^1][0-9a-z]*$$,1,;x' \
+	      -e 's,\.[0-9a-z]*$$,,;$(transform);G;s,\n,.,'`; \
+	dir='$(DESTDIR)$(man1dir)'; $(am__uninstall_files_from_dir)
+install-man5: $(dist_man_MANS)
+	@$(NORMAL_INSTALL)
+	@list1=''; \
+	list2='$(dist_man_MANS)'; \
+	test -n "$(man5dir)" \
+	  && test -n "`echo $$list1$$list2`" \
+	  || exit 0; \
+	echo " $(MKDIR_P) '$(DESTDIR)$(man5dir)'"; \
+	$(MKDIR_P) "$(DESTDIR)$(man5dir)" || exit 1; \
+	{ for i in $$list1; do echo "$$i"; done;  \
+	if test -n "$$list2"; then \
+	  for i in $$list2; do echo "$$i"; done \
+	    | sed -n '/\.5[a-z]*$$/p'; \
+	fi; \
+	} | while read p; do \
+	  if test -f $$p; then d=; else d="$(srcdir)/"; fi; \
+	  echo "$$d$$p"; echo "$$p"; \
+	done | \
+	sed -e 'n;s,.*/,,;p;h;s,.*\.,,;s,^[^5][0-9a-z]*$$,5,;x' \
+	      -e 's,\.[0-9a-z]*$$,,;$(transform);G;s,\n,.,' | \
+	sed 'N;N;s,\n, ,g' | { \
+	list=; while read file base inst; do \
+	  if test "$$base" = "$$inst"; then list="$$list $$file"; else \
+	    echo " $(INSTALL_DATA) '$$file' '$(DESTDIR)$(man5dir)/$$inst'"; \
+	    $(INSTALL_DATA) "$$file" "$(DESTDIR)$(man5dir)/$$inst" || exit $$?; \
+	  fi; \
+	done; \
+	for i in $$list; do echo "$$i"; done | $(am__base_list) | \
+	while read files; do \
+	  test -z "$$files" || { \
+	    echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(man5dir)'"; \
+	    $(INSTALL_DATA) $$files "$(DESTDIR)$(man5dir)" || exit $$?; }; \
+	done; }
+
+uninstall-man5:
+	@$(NORMAL_UNINSTALL)
+	@list=''; test -n "$(man5dir)" || exit 0; \
+	files=`{ for i in $$list; do echo "$$i"; done; \
+	l2='$(dist_man_MANS)'; for i in $$l2; do echo "$$i"; done | \
+	  sed -n '/\.5[a-z]*$$/p'; \
+	} | sed -e 's,.*/,,;h;s,.*\.,,;s,^[^5][0-9a-z]*$$,5,;x' \
+	      -e 's,\.[0-9a-z]*$$,,;$(transform);G;s,\n,.,'`; \
+	dir='$(DESTDIR)$(man5dir)'; $(am__uninstall_files_from_dir)
+install-man8: $(dist_man_MANS)
+	@$(NORMAL_INSTALL)
+	@list1=''; \
+	list2='$(dist_man_MANS)'; \
+	test -n "$(man8dir)" \
+	  && test -n "`echo $$list1$$list2`" \
+	  || exit 0; \
+	echo " $(MKDIR_P) '$(DESTDIR)$(man8dir)'"; \
+	$(MKDIR_P) "$(DESTDIR)$(man8dir)" || exit 1; \
+	{ for i in $$list1; do echo "$$i"; done;  \
+	if test -n "$$list2"; then \
+	  for i in $$list2; do echo "$$i"; done \
+	    | sed -n '/\.8[a-z]*$$/p'; \
+	fi; \
+	} | while read p; do \
+	  if test -f $$p; then d=; else d="$(srcdir)/"; fi; \
+	  echo "$$d$$p"; echo "$$p"; \
+	done | \
+	sed -e 'n;s,.*/,,;p;h;s,.*\.,,;s,^[^8][0-9a-z]*$$,8,;x' \
+	      -e 's,\.[0-9a-z]*$$,,;$(transform);G;s,\n,.,' | \
+	sed 'N;N;s,\n, ,g' | { \
+	list=; while read file base inst; do \
+	  if test "$$base" = "$$inst"; then list="$$list $$file"; else \
+	    echo " $(INSTALL_DATA) '$$file' '$(DESTDIR)$(man8dir)/$$inst'"; \
+	    $(INSTALL_DATA) "$$file" "$(DESTDIR)$(man8dir)/$$inst" || exit $$?; \
+	  fi; \
+	done; \
+	for i in $$list; do echo "$$i"; done | $(am__base_list) | \
+	while read files; do \
+	  test -z "$$files" || { \
+	    echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(man8dir)'"; \
+	    $(INSTALL_DATA) $$files "$(DESTDIR)$(man8dir)" || exit $$?; }; \
+	done; }
+
+uninstall-man8:
+	@$(NORMAL_UNINSTALL)
+	@list=''; test -n "$(man8dir)" || exit 0; \
+	files=`{ for i in $$list; do echo "$$i"; done; \
+	l2='$(dist_man_MANS)'; for i in $$l2; do echo "$$i"; done | \
+	  sed -n '/\.8[a-z]*$$/p'; \
+	} | sed -e 's,.*/,,;h;s,.*\.,,;s,^[^8][0-9a-z]*$$,8,;x' \
+	      -e 's,\.[0-9a-z]*$$,,;$(transform);G;s,\n,.,'`; \
+	dir='$(DESTDIR)$(man8dir)'; $(am__uninstall_files_from_dir)
+install-dbusconfDATA: $(dbusconf_DATA)
+	@$(NORMAL_INSTALL)
+	@list='$(dbusconf_DATA)'; test -n "$(dbusconfdir)" || list=; \
+	if test -n "$$list"; then \
+	  echo " $(MKDIR_P) '$(DESTDIR)$(dbusconfdir)'"; \
+	  $(MKDIR_P) "$(DESTDIR)$(dbusconfdir)" || exit 1; \
+	fi; \
+	for p in $$list; do \
+	  if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
+	  echo "$$d$$p"; \
+	done | $(am__base_list) | \
+	while read files; do \
+	  echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(dbusconfdir)'"; \
+	  $(INSTALL_DATA) $$files "$(DESTDIR)$(dbusconfdir)" || exit $$?; \
+	done
+
+uninstall-dbusconfDATA:
+	@$(NORMAL_UNINSTALL)
+	@list='$(dbusconf_DATA)'; test -n "$(dbusconfdir)" || list=; \
+	files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
+	dir='$(DESTDIR)$(dbusconfdir)'; $(am__uninstall_files_from_dir)
+install-dbusserviceDATA: $(dbusservice_DATA)
+	@$(NORMAL_INSTALL)
+	@list='$(dbusservice_DATA)'; test -n "$(dbusservicedir)" || list=; \
+	if test -n "$$list"; then \
+	  echo " $(MKDIR_P) '$(DESTDIR)$(dbusservicedir)'"; \
+	  $(MKDIR_P) "$(DESTDIR)$(dbusservicedir)" || exit 1; \
+	fi; \
+	for p in $$list; do \
+	  if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
+	  echo "$$d$$p"; \
+	done | $(am__base_list) | \
+	while read files; do \
+	  echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(dbusservicedir)'"; \
+	  $(INSTALL_DATA) $$files "$(DESTDIR)$(dbusservicedir)" || exit $$?; \
+	done
+
+uninstall-dbusserviceDATA:
+	@$(NORMAL_UNINSTALL)
+	@list='$(dbusservice_DATA)'; test -n "$(dbusservicedir)" || list=; \
+	files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
+	dir='$(DESTDIR)$(dbusservicedir)'; $(am__uninstall_files_from_dir)
+install-pkgconfigDATA: $(pkgconfig_DATA)
+	@$(NORMAL_INSTALL)
+	@list='$(pkgconfig_DATA)'; test -n "$(pkgconfigdir)" || list=; \
+	if test -n "$$list"; then \
+	  echo " $(MKDIR_P) '$(DESTDIR)$(pkgconfigdir)'"; \
+	  $(MKDIR_P) "$(DESTDIR)$(pkgconfigdir)" || exit 1; \
+	fi; \
+	for p in $$list; do \
+	  if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
+	  echo "$$d$$p"; \
+	done | $(am__base_list) | \
+	while read files; do \
+	  echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(pkgconfigdir)'"; \
+	  $(INSTALL_DATA) $$files "$(DESTDIR)$(pkgconfigdir)" || exit $$?; \
+	done
+
+uninstall-pkgconfigDATA:
+	@$(NORMAL_UNINSTALL)
+	@list='$(pkgconfig_DATA)'; test -n "$(pkgconfigdir)" || list=; \
+	files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
+	dir='$(DESTDIR)$(pkgconfigdir)'; $(am__uninstall_files_from_dir)
+install-policyDATA: $(policy_DATA)
+	@$(NORMAL_INSTALL)
+	@list='$(policy_DATA)'; test -n "$(policydir)" || list=; \
+	if test -n "$$list"; then \
+	  echo " $(MKDIR_P) '$(DESTDIR)$(policydir)'"; \
+	  $(MKDIR_P) "$(DESTDIR)$(policydir)" || exit 1; \
+	fi; \
+	for p in $$list; do \
+	  if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
+	  echo "$$d$$p"; \
+	done | $(am__base_list) | \
+	while read files; do \
+	  echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(policydir)'"; \
+	  $(INSTALL_DATA) $$files "$(DESTDIR)$(policydir)" || exit $$?; \
+	done
+
+uninstall-policyDATA:
+	@$(NORMAL_UNINSTALL)
+	@list='$(policy_DATA)'; test -n "$(policydir)" || list=; \
+	files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
+	dir='$(DESTDIR)$(policydir)'; $(am__uninstall_files_from_dir)
+install-scriptDATA: $(script_DATA)
+	@$(NORMAL_INSTALL)
+	@list='$(script_DATA)'; test -n "$(scriptdir)" || list=; \
+	if test -n "$$list"; then \
+	  echo " $(MKDIR_P) '$(DESTDIR)$(scriptdir)'"; \
+	  $(MKDIR_P) "$(DESTDIR)$(scriptdir)" || exit 1; \
+	fi; \
+	for p in $$list; do \
+	  if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
+	  echo "$$d$$p"; \
+	done | $(am__base_list) | \
+	while read files; do \
+	  echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(scriptdir)'"; \
+	  $(INSTALL_DATA) $$files "$(DESTDIR)$(scriptdir)" || exit $$?; \
+	done
+
+uninstall-scriptDATA:
+	@$(NORMAL_UNINSTALL)
+	@list='$(script_DATA)'; test -n "$(scriptdir)" || list=; \
+	files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
+	dir='$(DESTDIR)$(scriptdir)'; $(am__uninstall_files_from_dir)
+install-systemdunitDATA: $(systemdunit_DATA)
+	@$(NORMAL_INSTALL)
+	@list='$(systemdunit_DATA)'; test -n "$(systemdunitdir)" || list=; \
+	if test -n "$$list"; then \
+	  echo " $(MKDIR_P) '$(DESTDIR)$(systemdunitdir)'"; \
+	  $(MKDIR_P) "$(DESTDIR)$(systemdunitdir)" || exit 1; \
+	fi; \
+	for p in $$list; do \
+	  if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
+	  echo "$$d$$p"; \
+	done | $(am__base_list) | \
+	while read files; do \
+	  echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(systemdunitdir)'"; \
+	  $(INSTALL_DATA) $$files "$(DESTDIR)$(systemdunitdir)" || exit $$?; \
+	done
+
+uninstall-systemdunitDATA:
+	@$(NORMAL_UNINSTALL)
+	@list='$(systemdunit_DATA)'; test -n "$(systemdunitdir)" || list=; \
+	files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
+	dir='$(DESTDIR)$(systemdunitdir)'; $(am__uninstall_files_from_dir)
+install-includeHEADERS: $(include_HEADERS)
+	@$(NORMAL_INSTALL)
+	@list='$(include_HEADERS)'; test -n "$(includedir)" || list=; \
+	if test -n "$$list"; then \
+	  echo " $(MKDIR_P) '$(DESTDIR)$(includedir)'"; \
+	  $(MKDIR_P) "$(DESTDIR)$(includedir)" || exit 1; \
+	fi; \
+	for p in $$list; do \
+	  if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
+	  echo "$$d$$p"; \
+	done | $(am__base_list) | \
+	while read files; do \
+	  echo " $(INSTALL_HEADER) $$files '$(DESTDIR)$(includedir)'"; \
+	  $(INSTALL_HEADER) $$files "$(DESTDIR)$(includedir)" || exit $$?; \
+	done
+
+uninstall-includeHEADERS:
+	@$(NORMAL_UNINSTALL)
+	@list='$(include_HEADERS)'; test -n "$(includedir)" || list=; \
+	files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
+	dir='$(DESTDIR)$(includedir)'; $(am__uninstall_files_from_dir)
+install-nodist_includeHEADERS: $(nodist_include_HEADERS)
+	@$(NORMAL_INSTALL)
+	@list='$(nodist_include_HEADERS)'; test -n "$(includedir)" || list=; \
+	if test -n "$$list"; then \
+	  echo " $(MKDIR_P) '$(DESTDIR)$(includedir)'"; \
+	  $(MKDIR_P) "$(DESTDIR)$(includedir)" || exit 1; \
+	fi; \
+	for p in $$list; do \
+	  if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
+	  echo "$$d$$p"; \
+	done | $(am__base_list) | \
+	while read files; do \
+	  echo " $(INSTALL_HEADER) $$files '$(DESTDIR)$(includedir)'"; \
+	  $(INSTALL_HEADER) $$files "$(DESTDIR)$(includedir)" || exit $$?; \
+	done
+
+uninstall-nodist_includeHEADERS:
+	@$(NORMAL_UNINSTALL)
+	@list='$(nodist_include_HEADERS)'; test -n "$(includedir)" || list=; \
+	files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
+	dir='$(DESTDIR)$(includedir)'; $(am__uninstall_files_from_dir)
+
+ID: $(am__tagged_files)
+	$(am__define_uniq_tagged_files); mkid -fID $$unique
+tags: tags-am
+TAGS: tags
+
+tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files)
+	set x; \
+	here=`pwd`; \
+	$(am__define_uniq_tagged_files); \
+	shift; \
+	if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
+	  test -n "$$unique" || unique=$$empty_fix; \
+	  if test $$# -gt 0; then \
+	    $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+	      "$$@" $$unique; \
+	  else \
+	    $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+	      $$unique; \
+	  fi; \
+	fi
+ctags: ctags-am
+
+CTAGS: ctags
+ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files)
+	$(am__define_uniq_tagged_files); \
+	test -z "$(CTAGS_ARGS)$$unique" \
+	  || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
+	     $$unique
+
+GTAGS:
+	here=`$(am__cd) $(top_builddir) && pwd` \
+	  && $(am__cd) $(top_srcdir) \
+	  && gtags -i $(GTAGS_ARGS) "$$here"
+cscope: cscope.files
+	test ! -s cscope.files \
+	  || $(CSCOPE) -b -q $(AM_CSCOPEFLAGS) $(CSCOPEFLAGS) -i cscope.files $(CSCOPE_ARGS)
+clean-cscope:
+	-rm -f cscope.files
+cscope.files: clean-cscope cscopelist
+cscopelist: cscopelist-am
+
+cscopelist-am: $(am__tagged_files)
+	list='$(am__tagged_files)'; \
+	case "$(srcdir)" in \
+	  [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \
+	  *) sdir=$(subdir)/$(srcdir) ;; \
+	esac; \
+	for i in $$list; do \
+	  if test -f "$$i"; then \
+	    echo "$(subdir)/$$i"; \
+	  else \
+	    echo "$$sdir/$$i"; \
+	  fi; \
+	done >> $(top_builddir)/cscope.files
+
+distclean-tags:
+	-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
+	-rm -f cscope.out cscope.in.out cscope.po.out cscope.files
+
+# Recover from deleted '.trs' file; this should ensure that
+# "rm -f foo.log; make foo.trs" re-run 'foo.test', and re-create
+# both 'foo.log' and 'foo.trs'.  Break the recipe in two subshells
+# to avoid problems with "make -n".
+.log.trs:
+	rm -f $< $@
+	$(MAKE) $(AM_MAKEFLAGS) $<
+
+# Leading 'am--fnord' is there to ensure the list of targets does not
+# expand to empty, as could happen e.g. with make check TESTS=''.
+am--fnord $(TEST_LOGS) $(TEST_LOGS:.log=.trs): $(am__force_recheck)
+am--force-recheck:
+	@:
+
+$(TEST_SUITE_LOG): $(TEST_LOGS)
+	@$(am__set_TESTS_bases); \
+	am__f_ok () { test -f "$$1" && test -r "$$1"; }; \
+	redo_bases=`for i in $$bases; do \
+	              am__f_ok $$i.trs && am__f_ok $$i.log || echo $$i; \
+	            done`; \
+	if test -n "$$redo_bases"; then \
+	  redo_logs=`for i in $$redo_bases; do echo $$i.log; done`; \
+	  redo_results=`for i in $$redo_bases; do echo $$i.trs; done`; \
+	  if $(am__make_dryrun); then :; else \
+	    rm -f $$redo_logs && rm -f $$redo_results || exit 1; \
+	  fi; \
+	fi; \
+	if test -n "$$am__remaking_logs"; then \
+	  echo "fatal: making $(TEST_SUITE_LOG): possible infinite" \
+	       "recursion detected" >&2; \
+	else \
+	  am__remaking_logs=yes $(MAKE) $(AM_MAKEFLAGS) $$redo_logs; \
+	fi; \
+	if $(am__make_dryrun); then :; else \
+	  st=0;  \
+	  errmsg="fatal: making $(TEST_SUITE_LOG): failed to create"; \
+	  for i in $$redo_bases; do \
+	    test -f $$i.trs && test -r $$i.trs \
+	      || { echo "$$errmsg $$i.trs" >&2; st=1; }; \
+	    test -f $$i.log && test -r $$i.log \
+	      || { echo "$$errmsg $$i.log" >&2; st=1; }; \
+	  done; \
+	  test $$st -eq 0 || exit 1; \
+	fi
+	@$(am__sh_e_setup); $(am__tty_colors); $(am__set_TESTS_bases); \
+	ws='[ 	]'; \
+	results=`for b in $$bases; do echo $$b.trs; done`; \
+	test -n "$$results" || results=/dev/null; \
+	all=`  grep "^$$ws*:test-result:"           $$results | wc -l`; \
+	pass=` grep "^$$ws*:test-result:$$ws*PASS"  $$results | wc -l`; \
+	fail=` grep "^$$ws*:test-result:$$ws*FAIL"  $$results | wc -l`; \
+	skip=` grep "^$$ws*:test-result:$$ws*SKIP"  $$results | wc -l`; \
+	xfail=`grep "^$$ws*:test-result:$$ws*XFAIL" $$results | wc -l`; \
+	xpass=`grep "^$$ws*:test-result:$$ws*XPASS" $$results | wc -l`; \
+	error=`grep "^$$ws*:test-result:$$ws*ERROR" $$results | wc -l`; \
+	if test `expr $$fail + $$xpass + $$error` -eq 0; then \
+	  success=true; \
+	else \
+	  success=false; \
+	fi; \
+	br='==================='; br=$$br$$br$$br$$br; \
+	result_count () \
+	{ \
+	    if test x"$$1" = x"--maybe-color"; then \
+	      maybe_colorize=yes; \
+	    elif test x"$$1" = x"--no-color"; then \
+	      maybe_colorize=no; \
+	    else \
+	      echo "$@: invalid 'result_count' usage" >&2; exit 4; \
+	    fi; \
+	    shift; \
+	    desc=$$1 count=$$2; \
+	    if test $$maybe_colorize = yes && test $$count -gt 0; then \
+	      color_start=$$3 color_end=$$std; \
+	    else \
+	      color_start= color_end=; \
+	    fi; \
+	    echo "$${color_start}# $$desc $$count$${color_end}"; \
+	}; \
+	create_testsuite_report () \
+	{ \
+	  result_count $$1 "TOTAL:" $$all   "$$brg"; \
+	  result_count $$1 "PASS: " $$pass  "$$grn"; \
+	  result_count $$1 "SKIP: " $$skip  "$$blu"; \
+	  result_count $$1 "XFAIL:" $$xfail "$$lgn"; \
+	  result_count $$1 "FAIL: " $$fail  "$$red"; \
+	  result_count $$1 "XPASS:" $$xpass "$$red"; \
+	  result_count $$1 "ERROR:" $$error "$$mgn"; \
+	}; \
+	{								\
+	  echo "$(PACKAGE_STRING): $(subdir)/$(TEST_SUITE_LOG)" |	\
+	    $(am__rst_title);						\
+	  create_testsuite_report --no-color;				\
+	  echo;								\
+	  echo ".. contents:: :depth: 2";				\
+	  echo;								\
+	  for b in $$bases; do echo $$b; done				\
+	    | $(am__create_global_log);					\
+	} >$(TEST_SUITE_LOG).tmp || exit 1;				\
+	mv $(TEST_SUITE_LOG).tmp $(TEST_SUITE_LOG);			\
+	if $$success; then						\
+	  col="$$grn";							\
+	 else								\
+	  col="$$red";							\
+	  test x"$$VERBOSE" = x || cat $(TEST_SUITE_LOG);		\
+	fi;								\
+	echo "$${col}$$br$${std}"; 					\
+	echo "$${col}Testsuite summary for $(PACKAGE_STRING)$${std}";	\
+	echo "$${col}$$br$${std}"; 					\
+	create_testsuite_report --maybe-color;				\
+	echo "$$col$$br$$std";						\
+	if $$success; then :; else					\
+	  echo "$${col}See $(subdir)/$(TEST_SUITE_LOG)$${std}";		\
+	  if test -n "$(PACKAGE_BUGREPORT)"; then			\
+	    echo "$${col}Please report to $(PACKAGE_BUGREPORT)$${std}";	\
+	  fi;								\
+	  echo "$$col$$br$$std";					\
+	fi;								\
+	$$success || exit 1
+
+check-TESTS:
+	@list='$(RECHECK_LOGS)';           test -z "$$list" || rm -f $$list
+	@list='$(RECHECK_LOGS:.log=.trs)'; test -z "$$list" || rm -f $$list
+	@test -z "$(TEST_SUITE_LOG)" || rm -f $(TEST_SUITE_LOG)
+	@set +e; $(am__set_TESTS_bases); \
+	log_list=`for i in $$bases; do echo $$i.log; done`; \
+	trs_list=`for i in $$bases; do echo $$i.trs; done`; \
+	log_list=`echo $$log_list`; trs_list=`echo $$trs_list`; \
+	$(MAKE) $(AM_MAKEFLAGS) $(TEST_SUITE_LOG) TEST_LOGS="$$log_list"; \
+	exit $$?;
+recheck: all 
+	@test -z "$(TEST_SUITE_LOG)" || rm -f $(TEST_SUITE_LOG)
+	@set +e; $(am__set_TESTS_bases); \
+	bases=`for i in $$bases; do echo $$i; done \
+	         | $(am__list_recheck_tests)` || exit 1; \
+	log_list=`for i in $$bases; do echo $$i.log; done`; \
+	log_list=`echo $$log_list`; \
+	$(MAKE) $(AM_MAKEFLAGS) $(TEST_SUITE_LOG) \
+	        am__force_recheck=am--force-recheck \
+	        TEST_LOGS="$$log_list"; \
+	exit $$?
+unit/test-ippool.log: unit/test-ippool$(EXEEXT)
+	@p='unit/test-ippool$(EXEEXT)'; \
+	b='unit/test-ippool'; \
+	$(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
+	--log-file $$b.log --trs-file $$b.trs \
+	$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
+	"$$tst" $(AM_TESTS_FD_REDIRECT)
+.test.log:
+	@p='$<'; \
+	$(am__set_b); \
+	$(am__check_pre) $(TEST_LOG_DRIVER) --test-name "$$f" \
+	--log-file $$b.log --trs-file $$b.trs \
+	$(am__common_driver_flags) $(AM_TEST_LOG_DRIVER_FLAGS) $(TEST_LOG_DRIVER_FLAGS) -- $(TEST_LOG_COMPILE) \
+	"$$tst" $(AM_TESTS_FD_REDIRECT)
+@am__EXEEXT_TRUE@.test$(EXEEXT).log:
+@am__EXEEXT_TRUE@	@p='$<'; \
+@am__EXEEXT_TRUE@	$(am__set_b); \
+@am__EXEEXT_TRUE@	$(am__check_pre) $(TEST_LOG_DRIVER) --test-name "$$f" \
+@am__EXEEXT_TRUE@	--log-file $$b.log --trs-file $$b.trs \
+@am__EXEEXT_TRUE@	$(am__common_driver_flags) $(AM_TEST_LOG_DRIVER_FLAGS) $(TEST_LOG_DRIVER_FLAGS) -- $(TEST_LOG_COMPILE) \
+@am__EXEEXT_TRUE@	"$$tst" $(AM_TESTS_FD_REDIRECT)
+
+distdir: $(DISTFILES)
+	$(am__remove_distdir)
+	test -d "$(distdir)" || mkdir "$(distdir)"
+	@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+	topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+	list='$(DISTFILES)'; \
+	  dist_files=`for file in $$list; do echo $$file; done | \
+	  sed -e "s|^$$srcdirstrip/||;t" \
+	      -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
+	case $$dist_files in \
+	  */*) $(MKDIR_P) `echo "$$dist_files" | \
+			   sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
+			   sort -u` ;; \
+	esac; \
+	for file in $$dist_files; do \
+	  if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+	  if test -d $$d/$$file; then \
+	    dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
+	    if test -d "$(distdir)/$$file"; then \
+	      find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+	    fi; \
+	    if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+	      cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
+	      find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+	    fi; \
+	    cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
+	  else \
+	    test -f "$(distdir)/$$file" \
+	    || cp -p $$d/$$file "$(distdir)/$$file" \
+	    || exit 1; \
+	  fi; \
+	done
+	-test -n "$(am__skip_mode_fix)" \
+	|| find "$(distdir)" -type d ! -perm -755 \
+		-exec chmod u+rwx,go+rx {} \; -o \
+	  ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; -o \
+	  ! -type d ! -perm -400 -exec chmod a+r {} \; -o \
+	  ! -type d ! -perm -444 -exec $(install_sh) -c -m a+r {} {} \; \
+	|| chmod -R a+r "$(distdir)"
+dist-gzip: distdir
+	tardir=$(distdir) && $(am__tar) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz
+	$(am__post_remove_distdir)
+
+dist-bzip2: distdir
+	tardir=$(distdir) && $(am__tar) | BZIP2=$${BZIP2--9} bzip2 -c >$(distdir).tar.bz2
+	$(am__post_remove_distdir)
+
+dist-lzip: distdir
+	tardir=$(distdir) && $(am__tar) | lzip -c $${LZIP_OPT--9} >$(distdir).tar.lz
+	$(am__post_remove_distdir)
+
+dist-xz: distdir
+	tardir=$(distdir) && $(am__tar) | XZ_OPT=$${XZ_OPT--e} xz -c >$(distdir).tar.xz
+	$(am__post_remove_distdir)
+
+dist-tarZ: distdir
+	@echo WARNING: "Support for shar distribution archives is" \
+	               "deprecated." >&2
+	@echo WARNING: "It will be removed altogether in Automake 2.0" >&2
+	tardir=$(distdir) && $(am__tar) | compress -c >$(distdir).tar.Z
+	$(am__post_remove_distdir)
+
+dist-shar: distdir
+	@echo WARNING: "Support for distribution archives compressed with" \
+		       "legacy program 'compress' is deprecated." >&2
+	@echo WARNING: "It will be removed altogether in Automake 2.0" >&2
+	shar $(distdir) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).shar.gz
+	$(am__post_remove_distdir)
+
+dist-zip: distdir
+	-rm -f $(distdir).zip
+	zip -rq $(distdir).zip $(distdir)
+	$(am__post_remove_distdir)
+
+dist dist-all:
+	$(MAKE) $(AM_MAKEFLAGS) $(DIST_TARGETS) am__post_remove_distdir='@:'
+	$(am__post_remove_distdir)
+
+# This target untars the dist file and tries a VPATH configuration.  Then
+# it guarantees that the distribution is self-contained by making another
+# tarfile.
+distcheck: dist
+	case '$(DIST_ARCHIVES)' in \
+	*.tar.gz*) \
+	  GZIP=$(GZIP_ENV) gzip -dc $(distdir).tar.gz | $(am__untar) ;;\
+	*.tar.bz2*) \
+	  bzip2 -dc $(distdir).tar.bz2 | $(am__untar) ;;\
+	*.tar.lz*) \
+	  lzip -dc $(distdir).tar.lz | $(am__untar) ;;\
+	*.tar.xz*) \
+	  xz -dc $(distdir).tar.xz | $(am__untar) ;;\
+	*.tar.Z*) \
+	  uncompress -c $(distdir).tar.Z | $(am__untar) ;;\
+	*.shar.gz*) \
+	  GZIP=$(GZIP_ENV) gzip -dc $(distdir).shar.gz | unshar ;;\
+	*.zip*) \
+	  unzip $(distdir).zip ;;\
+	esac
+	chmod -R a-w $(distdir)
+	chmod u+w $(distdir)
+	mkdir $(distdir)/_build $(distdir)/_inst
+	chmod a-w $(distdir)
+	test -d $(distdir)/_build || exit 0; \
+	dc_install_base=`$(am__cd) $(distdir)/_inst && pwd | sed -e 's,^[^:\\/]:[\\/],/,'` \
+	  && dc_destdir="$${TMPDIR-/tmp}/am-dc-$$$$/" \
+	  && am__cwd=`pwd` \
+	  && $(am__cd) $(distdir)/_build \
+	  && ../configure \
+	    $(AM_DISTCHECK_CONFIGURE_FLAGS) \
+	    $(DISTCHECK_CONFIGURE_FLAGS) \
+	    --srcdir=.. --prefix="$$dc_install_base" \
+	  && $(MAKE) $(AM_MAKEFLAGS) \
+	  && $(MAKE) $(AM_MAKEFLAGS) dvi \
+	  && $(MAKE) $(AM_MAKEFLAGS) check \
+	  && $(MAKE) $(AM_MAKEFLAGS) install \
+	  && $(MAKE) $(AM_MAKEFLAGS) installcheck \
+	  && $(MAKE) $(AM_MAKEFLAGS) uninstall \
+	  && $(MAKE) $(AM_MAKEFLAGS) distuninstallcheck_dir="$$dc_install_base" \
+	        distuninstallcheck \
+	  && chmod -R a-w "$$dc_install_base" \
+	  && ({ \
+	       (cd ../.. && umask 077 && mkdir "$$dc_destdir") \
+	       && $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" install \
+	       && $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" uninstall \
+	       && $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" \
+	            distuninstallcheck_dir="$$dc_destdir" distuninstallcheck; \
+	      } || { rm -rf "$$dc_destdir"; exit 1; }) \
+	  && rm -rf "$$dc_destdir" \
+	  && $(MAKE) $(AM_MAKEFLAGS) dist \
+	  && rm -rf $(DIST_ARCHIVES) \
+	  && $(MAKE) $(AM_MAKEFLAGS) distcleancheck \
+	  && cd "$$am__cwd" \
+	  || exit 1
+	$(am__post_remove_distdir)
+	@(echo "$(distdir) archives ready for distribution: "; \
+	  list='$(DIST_ARCHIVES)'; for i in $$list; do echo $$i; done) | \
+	  sed -e 1h -e 1s/./=/g -e 1p -e 1x -e '$$p' -e '$$x'
+distuninstallcheck:
+	@test -n '$(distuninstallcheck_dir)' || { \
+	  echo 'ERROR: trying to run $@ with an empty' \
+	       '$$(distuninstallcheck_dir)' >&2; \
+	  exit 1; \
+	}; \
+	$(am__cd) '$(distuninstallcheck_dir)' || { \
+	  echo 'ERROR: cannot chdir into $(distuninstallcheck_dir)' >&2; \
+	  exit 1; \
+	}; \
+	test `$(am__distuninstallcheck_listfiles) | wc -l` -eq 0 \
+	   || { echo "ERROR: files left after uninstall:" ; \
+	        if test -n "$(DESTDIR)"; then \
+	          echo "  (check DESTDIR support)"; \
+	        fi ; \
+	        $(distuninstallcheck_listfiles) ; \
+	        exit 1; } >&2
+distcleancheck: distclean
+	@if test '$(srcdir)' = . ; then \
+	  echo "ERROR: distcleancheck can only run from a VPATH build" ; \
+	  exit 1 ; \
+	fi
+	@test `$(distcleancheck_listfiles) | wc -l` -eq 0 \
+	  || { echo "ERROR: files left in build directory after distclean:" ; \
+	       $(distcleancheck_listfiles) ; \
+	       exit 1; } >&2
+check-am: all-am
+	$(MAKE) $(AM_MAKEFLAGS) check-TESTS
+check: $(BUILT_SOURCES)
+	$(MAKE) $(AM_MAKEFLAGS) check-am
+all-am: Makefile $(LTLIBRARIES) $(PROGRAMS) $(SCRIPTS) $(MANS) $(DATA) \
+		$(HEADERS) config.h
+installdirs:
+	for dir in "$(DESTDIR)$(plugindir)" "$(DESTDIR)$(scriptdir)" "$(DESTDIR)$(vpn_plugindir)" "$(DESTDIR)$(bindir)" "$(DESTDIR)$(sbindir)" "$(DESTDIR)$(scriptdir)" "$(DESTDIR)$(testdir)" "$(DESTDIR)$(man1dir)" "$(DESTDIR)$(man5dir)" "$(DESTDIR)$(man8dir)" "$(DESTDIR)$(dbusconfdir)" "$(DESTDIR)$(dbusservicedir)" "$(DESTDIR)$(pkgconfigdir)" "$(DESTDIR)$(policydir)" "$(DESTDIR)$(scriptdir)" "$(DESTDIR)$(systemdunitdir)" "$(DESTDIR)$(includedir)" "$(DESTDIR)$(includedir)"; do \
+	  test -z "$$dir" || $(MKDIR_P) "$$dir"; \
+	done
+install: $(BUILT_SOURCES)
+	$(MAKE) $(AM_MAKEFLAGS) install-am
+install-exec: install-exec-am
+install-data: install-data-am
+uninstall: uninstall-am
+
+install-am: all-am
+	@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-am
+install-strip:
+	if test -z '$(STRIP)'; then \
+	  $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+	    install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+	      install; \
+	else \
+	  $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+	    install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+	    "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
+	fi
+mostlyclean-generic:
+	-test -z "$(TEST_LOGS)" || rm -f $(TEST_LOGS)
+	-test -z "$(TEST_LOGS:.log=.trs)" || rm -f $(TEST_LOGS:.log=.trs)
+	-test -z "$(TEST_SUITE_LOG)" || rm -f $(TEST_SUITE_LOG)
+
+clean-generic:
+	-test -z "$(CLEANFILES)" || rm -f $(CLEANFILES)
+
+distclean-generic:
+	-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+	-test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
+	-rm -f client/$(DEPDIR)/$(am__dirstamp)
+	-rm -f client/$(am__dirstamp)
+	-rm -f gdbus/$(DEPDIR)/$(am__dirstamp)
+	-rm -f gdbus/$(am__dirstamp)
+	-rm -f gdhcp/$(DEPDIR)/$(am__dirstamp)
+	-rm -f gdhcp/$(am__dirstamp)
+	-rm -f gsupplicant/$(DEPDIR)/$(am__dirstamp)
+	-rm -f gsupplicant/$(am__dirstamp)
+	-rm -f gweb/$(DEPDIR)/$(am__dirstamp)
+	-rm -f gweb/$(am__dirstamp)
+	-rm -f plugins/$(DEPDIR)/$(am__dirstamp)
+	-rm -f plugins/$(am__dirstamp)
+	-rm -f scripts/$(DEPDIR)/$(am__dirstamp)
+	-rm -f scripts/$(am__dirstamp)
+	-rm -f src/$(DEPDIR)/$(am__dirstamp)
+	-rm -f src/$(am__dirstamp)
+	-rm -f src/shared/$(DEPDIR)/$(am__dirstamp)
+	-rm -f src/shared/$(am__dirstamp)
+	-rm -f tools/$(DEPDIR)/$(am__dirstamp)
+	-rm -f tools/$(am__dirstamp)
+	-rm -f unit/$(DEPDIR)/$(am__dirstamp)
+	-rm -f unit/$(am__dirstamp)
+	-rm -f vpn/$(DEPDIR)/$(am__dirstamp)
+	-rm -f vpn/$(am__dirstamp)
+	-rm -f vpn/plugins/$(DEPDIR)/$(am__dirstamp)
+	-rm -f vpn/plugins/$(am__dirstamp)
+	-test -z "$(DISTCLEANFILES)" || rm -f $(DISTCLEANFILES)
+
+maintainer-clean-generic:
+	@echo "This command is intended for maintainers to use"
+	@echo "it deletes files that may require special tools to rebuild."
+	-test -z "$(BUILT_SOURCES)" || rm -f $(BUILT_SOURCES)
+	-test -z "$(MAINTAINERCLEANFILES)" || rm -f $(MAINTAINERCLEANFILES)
+clean: clean-am
+
+clean-am: clean-binPROGRAMS clean-generic clean-libtool clean-local \
+	clean-noinstLTLIBRARIES clean-noinstPROGRAMS \
+	clean-pluginLTLIBRARIES clean-sbinPROGRAMS \
+	clean-scriptLTLIBRARIES clean-scriptPROGRAMS \
+	clean-vpn_pluginLTLIBRARIES mostlyclean-am
+
+distclean: distclean-am
+	-rm -f $(am__CONFIG_DISTCLEAN_FILES)
+	-rm -rf client/$(DEPDIR) gdbus/$(DEPDIR) gdhcp/$(DEPDIR) gsupplicant/$(DEPDIR) gweb/$(DEPDIR) plugins/$(DEPDIR) scripts/$(DEPDIR) src/$(DEPDIR) src/shared/$(DEPDIR) tools/$(DEPDIR) unit/$(DEPDIR) vpn/$(DEPDIR) vpn/plugins/$(DEPDIR)
+	-rm -f Makefile
+distclean-am: clean-am distclean-compile distclean-generic \
+	distclean-hdr distclean-libtool distclean-tags
+
+dvi: dvi-am
+
+dvi-am:
+
+html: html-am
+
+html-am:
+
+info: info-am
+
+info-am:
+
+install-data-am: install-dbusconfDATA install-dbusserviceDATA \
+	install-includeHEADERS install-man \
+	install-nodist_includeHEADERS install-pkgconfigDATA \
+	install-pluginLTLIBRARIES install-policyDATA \
+	install-scriptDATA install-scriptLTLIBRARIES \
+	install-scriptPROGRAMS install-systemdunitDATA \
+	install-testSCRIPTS install-vpn_pluginLTLIBRARIES
+
+install-dvi: install-dvi-am
+
+install-dvi-am:
+
+install-exec-am: install-binPROGRAMS install-sbinPROGRAMS
+
+install-html: install-html-am
+
+install-html-am:
+
+install-info: install-info-am
+
+install-info-am:
+
+install-man: install-man1 install-man5 install-man8
+
+install-pdf: install-pdf-am
+
+install-pdf-am:
+
+install-ps: install-ps-am
+
+install-ps-am:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-am
+	-rm -f $(am__CONFIG_DISTCLEAN_FILES)
+	-rm -rf $(top_srcdir)/autom4te.cache
+	-rm -rf client/$(DEPDIR) gdbus/$(DEPDIR) gdhcp/$(DEPDIR) gsupplicant/$(DEPDIR) gweb/$(DEPDIR) plugins/$(DEPDIR) scripts/$(DEPDIR) src/$(DEPDIR) src/shared/$(DEPDIR) tools/$(DEPDIR) unit/$(DEPDIR) vpn/$(DEPDIR) vpn/plugins/$(DEPDIR)
+	-rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-am
+
+mostlyclean-am: mostlyclean-compile mostlyclean-generic \
+	mostlyclean-libtool
+
+pdf: pdf-am
+
+pdf-am:
+
+ps: ps-am
+
+ps-am:
+
+uninstall-am: uninstall-binPROGRAMS uninstall-dbusconfDATA \
+	uninstall-dbusserviceDATA uninstall-includeHEADERS \
+	uninstall-man uninstall-nodist_includeHEADERS \
+	uninstall-pkgconfigDATA uninstall-pluginLTLIBRARIES \
+	uninstall-policyDATA uninstall-sbinPROGRAMS \
+	uninstall-scriptDATA uninstall-scriptLTLIBRARIES \
+	uninstall-scriptPROGRAMS uninstall-systemdunitDATA \
+	uninstall-testSCRIPTS uninstall-vpn_pluginLTLIBRARIES
+
+uninstall-man: uninstall-man1 uninstall-man5 uninstall-man8
+
+.MAKE: all check check-am install install-am install-strip
+
+.PHONY: CTAGS GTAGS TAGS all all-am am--refresh check check-TESTS \
+	check-am clean clean-binPROGRAMS clean-cscope clean-generic \
+	clean-libtool clean-local clean-noinstLTLIBRARIES \
+	clean-noinstPROGRAMS clean-pluginLTLIBRARIES \
+	clean-sbinPROGRAMS clean-scriptLTLIBRARIES \
+	clean-scriptPROGRAMS clean-vpn_pluginLTLIBRARIES cscope \
+	cscopelist-am ctags ctags-am dist dist-all dist-bzip2 \
+	dist-gzip dist-lzip dist-shar dist-tarZ dist-xz dist-zip \
+	distcheck distclean distclean-compile distclean-generic \
+	distclean-hdr distclean-libtool distclean-tags distcleancheck \
+	distdir distuninstallcheck dvi dvi-am html html-am info \
+	info-am install install-am install-binPROGRAMS install-data \
+	install-data-am install-dbusconfDATA install-dbusserviceDATA \
+	install-dvi install-dvi-am install-exec install-exec-am \
+	install-html install-html-am install-includeHEADERS \
+	install-info install-info-am install-man install-man1 \
+	install-man5 install-man8 install-nodist_includeHEADERS \
+	install-pdf install-pdf-am install-pkgconfigDATA \
+	install-pluginLTLIBRARIES install-policyDATA install-ps \
+	install-ps-am install-sbinPROGRAMS install-scriptDATA \
+	install-scriptLTLIBRARIES install-scriptPROGRAMS install-strip \
+	install-systemdunitDATA install-testSCRIPTS \
+	install-vpn_pluginLTLIBRARIES installcheck installcheck-am \
+	installdirs maintainer-clean maintainer-clean-generic \
+	mostlyclean mostlyclean-compile mostlyclean-generic \
+	mostlyclean-libtool pdf pdf-am ps ps-am recheck tags tags-am \
+	uninstall uninstall-am uninstall-binPROGRAMS \
+	uninstall-dbusconfDATA uninstall-dbusserviceDATA \
+	uninstall-includeHEADERS uninstall-man uninstall-man1 \
+	uninstall-man5 uninstall-man8 uninstall-nodist_includeHEADERS \
+	uninstall-pkgconfigDATA uninstall-pluginLTLIBRARIES \
+	uninstall-policyDATA uninstall-sbinPROGRAMS \
+	uninstall-scriptDATA uninstall-scriptLTLIBRARIES \
+	uninstall-scriptPROGRAMS uninstall-systemdunitDATA \
+	uninstall-testSCRIPTS uninstall-vpn_pluginLTLIBRARIES
+
+
+plugins/net.connman.policy: plugins/polkit.policy
+@POLKIT_TRUE@	$(AM_V_GEN)cp $< $@
+
+@VPN_TRUE@vpn/net.connman.vpn.policy: vpn/vpn-polkit.policy
+@POLKIT_TRUE@@VPN_TRUE@	$(AM_V_GEN)cp $< $@
+
+src/builtin.h: src/genbuiltin $(builtin_sources)
+	$(AM_V_at)$(MKDIR_P) $(dir $@)
+	$(AM_V_GEN)$(srcdir)/src/genbuiltin $(builtin_modules) > $@
+
+vpn/builtin.h: src/genbuiltin $(builtin_vpn_sources)
+	$(AM_V_at)$(MKDIR_P) $(dir $@)
+	$(AM_V_GEN)$(srcdir)/src/genbuiltin $(builtin_vpn_modules) > $@
+
+src/connman.conf: src/connman-dbus.conf src/connman-polkit.conf
+@POLKIT_TRUE@	$(AM_V_GEN)cp $(srcdir)/src/connman-polkit.conf $@
+@POLKIT_FALSE@	$(AM_V_GEN)cp $(srcdir)/src/connman-dbus.conf $@
+
+@VPN_TRUE@vpn/connman-vpn-dbus.conf: vpn/vpn-dbus.conf vpn/vpn-polkit.conf
+@POLKIT_TRUE@@VPN_TRUE@	$(AM_V_GEN)cp $(srcdir)/vpn/vpn-polkit.conf $@
+@POLKIT_FALSE@@VPN_TRUE@	$(AM_V_GEN)cp $(srcdir)/vpn/vpn-dbus.conf $@
+
+@SELINUX_TRUE@connman-task.pp: vpn/connman-task.te
+@SELINUX_TRUE@	make -f /usr/share/selinux/devel/Makefile
+
+%.service: %.service.in Makefile
+	$(AM_V_at)$(MKDIR_P) $(dir $@)
+	$(do_subst) < $< > $@
+
+scripts/connman: scripts/connman.in Makefile
+	$(AM_V_at)$(MKDIR_P) $(dir $@)
+	$(do_subst) < $< > $@
+
+include/connman/version.h: include/version.h
+	$(AM_V_at)$(MKDIR_P) include/connman
+	$(AM_V_GEN)$(LN_S) $(abs_top_builddir)/$< $@
+
+include/connman/%.h: $(abs_top_srcdir)/include/%.h
+	$(AM_V_at)$(MKDIR_P) include/connman
+	$(AM_V_GEN)$(LN_S) $< $@
+
+clean-local:
+	@$(RM) -rf include/connman
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/connman/Makefile.plugins b/connman/Makefile.plugins
new file mode 100644
index 0000000..e90ad19
--- /dev/null
+++ b/connman/Makefile.plugins
@@ -0,0 +1,265 @@
+
+plugin_cflags = -fvisibility=hidden -I$(srcdir)/gdbus \
+					@DBUS_CFLAGS@ @GLIB_CFLAGS@
+plugin_ldflags = -no-undefined -module -avoid-version
+
+if LOOPBACK
+builtin_modules += loopback
+builtin_sources += plugins/loopback.c
+endif
+
+if ETHERNET
+builtin_modules += ethernet
+builtin_sources += plugins/ethernet.c
+endif
+
+if GADGET
+builtin_modules += gadget
+builtin_sources += plugins/gadget.c
+endif
+
+gsupplicant_sources = gsupplicant/gsupplicant.h gsupplicant/dbus.h \
+			gsupplicant/supplicant.c gsupplicant/dbus.c
+
+if WIFI
+builtin_modules += wifi
+builtin_sources += plugins/wifi.c $(gsupplicant_sources)
+endif
+
+if BLUETOOTH
+builtin_modules += bluetooth_legacy
+builtin_sources += plugins/bluetooth_legacy.c
+builtin_modules += bluetooth
+builtin_sources += plugins/bluetooth.c
+endif
+
+if HH2SERIAL_GPS
+if HH2SERIAL_GPS_BUILTIN
+builtin_modules += hh2serial_gps
+builtin_sources += plugins/hh2serial-gps.c
+else
+plugin_LTLIBRARIES += plugins/hh2serial-gps.la
+plugin_objects += $(plugins_hh2serial_gps_la_OBJECTS)
+plugins_hh2serial_gps_la_CFLAGS = $(plugin_cflags)
+plugins_hh2serial_gps_la_LDFLAGS = $(plugin_ldflags)
+endif
+endif
+
+if OFONO
+builtin_modules += ofono
+builtin_sources += plugins/mcc.h plugins/ofono.c
+endif
+
+if DUNDEE
+builtin_modules += dundee
+builtin_sources += plugins/dundee.c
+endif
+
+if VPN
+builtin_modules += vpn
+builtin_sources += plugins/vpn.c
+
+if OPENCONNECT
+if OPENCONNECT_BUILTIN
+builtin_vpn_modules += openconnect
+builtin_vpn_sources += vpn/plugins/openconnect.c
+builtin_vpn_source = vpn/plugins/vpn.c vpn/plugins/vpn.h
+builtin_vpn_cflags += -DOPENCONNECT=\"@OPENCONNECT@\"
+else
+vpn_plugin_LTLIBRARIES += vpn/plugins/openconnect.la
+vpn_plugin_objects += $(plugins_openconnect_la_OBJECTS)
+vpn_plugins_openconnect_la_SOURCES = vpn/plugins/vpn.h vpn/plugins/vpn.c \
+						vpn/plugins/openconnect.c
+vpn_plugins_openconnect_la_CFLAGS = $(plugin_cflags) \
+					-DOPENCONNECT=\"@OPENCONNECT@\" \
+					-DVPN_STATEDIR=\""$(vpn_statedir)"\" \
+					-DSCRIPTDIR=\""$(build_scriptdir)"\"
+vpn_plugins_openconnect_la_LDFLAGS = $(plugin_ldflags)
+endif
+endif
+
+if OPENVPN
+if OPENVPN_BUILTIN
+builtin_vpn_modules += openvpn
+builtin_vpn_sources += vpn/plugins/openvpn.c
+builtin_vpn_source = vpn/plugins/vpn.c vpn/plugins/vpn.h
+builtin_vpn_cflags += -DOPENVPN=\"@OPENVPN@\"
+else
+vpn_plugin_LTLIBRARIES += vpn/plugins/openvpn.la
+vpn_plugin_objects += $(plugins_openvpn_la_OBJECTS)
+vpn_plugins_openvpn_la_SOURCES = vpn/plugins/vpn.h vpn/plugins/vpn.c \
+						vpn/plugins/openvpn.c
+vpn_plugins_openvpn_la_CFLAGS = $(plugin_cflags) -DOPENVPN=\"@OPENVPN@\" \
+					-DVPN_STATEDIR=\""$(vpn_statedir)"\" \
+					-DSCRIPTDIR=\""$(build_scriptdir)"\"
+vpn_plugins_openvpn_la_LDFLAGS = $(plugin_ldflags)
+endif
+endif
+
+if VPNC
+if VPNC_BUILTIN
+builtin_vpn_modules += vpnc
+builtin_vpn_sources += vpn/plugins/vpnc.c
+builtin_vpn_source = vpn/plugins/vpn.c vpn/plugins/vpn.h
+builtin_vpn_cflags += -DVPNC=\"@VPNC@\"
+else
+vpn_plugin_LTLIBRARIES += vpn/plugins/vpnc.la
+vpn_plugin_objects += $(plugins_vpnc_la_OBJECTS)
+vpn_plugins_vpnc_la_SOURCES = vpn/plugins/vpn.h vpn/plugins/vpn.c \
+						vpn/plugins/vpnc.c
+vpn_plugins_vpnc_la_CFLAGS = $(plugin_cflags) -DVPNC=\"@VPNC@\" \
+					-DVPN_STATEDIR=\""$(vpn_statedir)"\" \
+					-DSCRIPTDIR=\""$(build_scriptdir)"\"
+vpn_plugins_vpnc_la_LDFLAGS = $(plugin_ldflags)
+endif
+endif
+
+if L2TP
+if L2TP_BUILTIN
+builtin_vpn_modules += l2tp
+builtin_vpn_sources += vpn/plugins/l2tp.c
+builtin_vpn_source = vpn/plugins/vpn.c vpn/plugins/vpn.h
+builtin_vpn_cflags += -DL2TP=\"@L2TP@\"
+else
+vpn_plugin_LTLIBRARIES += vpn/plugins/l2tp.la
+vpn_plugin_objects += $(plugins_l2tp_la_OBJECTS)
+vpn_plugins_l2tp_la_SOURCES = vpn/plugins/vpn.h vpn/plugins/vpn.c \
+						vpn/plugins/l2tp.c
+vpn_plugins_l2tp_la_CFLAGS = $(plugin_cflags) -DL2TP=\"@L2TP@\" \
+					-DVPN_STATEDIR=\""$(vpn_statedir)"\" \
+					-DSCRIPTDIR=\""$(build_scriptdir)"\"
+vpn_plugins_l2tp_la_LDFLAGS = $(plugin_ldflags)
+endif
+endif
+
+if PPTP
+if PPTP_BUILTIN
+builtin_vpn_modules += pptp
+builtin_vpn_sources += vpn/plugins/pptp.c
+builtin_vpn_source = vpn/plugins/vpn.c vpn/plugins/vpn.h
+builtin_vpn_cflags += -DPPPD=\"@PPPD@\" -DPPTP=\"@PPTP@\"
+else
+vpn_plugin_LTLIBRARIES += vpn/plugins/pptp.la
+vpn_plugin_objects += $(plugins_pptp_la_OBJECTS)
+vpn_plugins_pptp_la_SOURCES = vpn/plugins/vpn.h vpn/plugins/vpn.c \
+						vpn/plugins/pptp.c
+vpn_plugins_pptp_la_CFLAGS = $(plugin_cflags) -DPPPD=\"@PPPD@\" \
+					-DPPTP=\"@PPTP@\" \
+					-DVPN_STATEDIR=\""$(vpn_statedir)"\" \
+					-DSCRIPTDIR=\""$(build_scriptdir)"\"
+vpn_plugins_pptp_la_LDFLAGS = $(plugin_ldflags)
+endif
+endif
+
+if PPTP
+script_LTLIBRARIES += scripts/libppp-plugin.la
+scripts_libppp_plugin_la_LDFLAGS = $(plugin_ldflags)
+scripts_libppp_plugin_la_LIBADD = @DBUS_LIBS@
+else
+if L2TP
+script_LTLIBRARIES += scripts/libppp-plugin.la
+scripts_libppp_plugin_la_LDFLAGS = $(plugin_ldflags)
+scripts_libppp_plugin_la_LIBADD = @DBUS_LIBS@
+endif
+endif
+
+if VPN
+builtin_vpn_sources += $(builtin_vpn_source)
+endif
+endif
+
+if PACRUNNER
+builtin_modules += pacrunner
+builtin_sources += plugins/pacrunner.c
+endif
+
+if POLKIT
+builtin_modules += polkit
+builtin_sources += plugins/polkit.c
+
+if DATAFILES
+policydir = @POLKIT_DATADIR@
+
+policy_DATA = plugins/net.connman.policy
+
+if VPN
+policy_DATA += vpn/net.connman.vpn.policy
+endif
+endif
+endif
+
+if IOSPM
+plugin_LTLIBRARIES += plugins/iospm.la
+plugin_objects += $(plugins_iospm_la_OBJECTS)
+plugins_iospm_la_CFLAGS = $(plugin_cflags)
+plugins_iospm_la_LDFLAGS = $(plugin_ldflags)
+endif
+
+if OPENCONNECT
+script_PROGRAMS += scripts/openconnect-script
+
+scripts_openconnect_script_LDADD = @DBUS_LIBS@
+else
+if VPNC
+script_PROGRAMS += scripts/openconnect-script
+
+scripts_openconnect_script_LDADD = @DBUS_LIBS@
+endif
+endif
+
+if OPENVPN
+script_PROGRAMS += scripts/openvpn-script
+
+scripts_openvpn_script_LDADD = @DBUS_LIBS@
+endif
+
+if NMCOMPAT
+builtin_modules += nmcompat
+builtin_sources += plugins/nmcompat.c
+endif
+
+if TIST
+if TIST_BUILTIN
+builtin_modules += tist
+builtin_sources += plugins/tist.c
+else
+plugin_LTLIBRARIES += plugins/tist.la
+plugin_objects += $(plugins_tist_la_OBJECTS)
+plugins_tist_la_CFLAGS = $(plugin_cflags)
+plugins_tist_la_LDFLAGS = $(plugin_ldflags)
+endif
+endif
+
+if SESSION_POLICY_LOCAL
+if SESSION_POLICY_LOCAL_BUILTIN
+builtin_modules += session_policy_local
+builtin_sources += plugins/session_policy_local.c
+else
+plugin_LTLIBRARIES += plugins/session_policy_local.la
+plugin_objects += $(plugins_session_policy_local_la_OBJECTS)
+plugins_session_policy_local_la_CFLAGS = $(plugin_cflags) \
+				-DSTORAGEDIR=\""$(storagedir)\""
+plugins_session_policy_local_la_LDFLAGS = $(plugin_ldflags)
+endif
+endif
+
+if NEARD
+builtin_modules += neard
+builtin_sources += plugins/neard.c
+endif
+
+EXTRA_DIST += plugins/polkit.policy
+
+plugins/net.connman.policy: plugins/polkit.policy
+if POLKIT
+	$(AM_V_GEN)cp $< $@
+endif
+
+EXTRA_DIST += vpn/vpn-polkit.policy
+
+if VPN
+vpn/net.connman.vpn.policy: vpn/vpn-polkit.policy
+if POLKIT
+	$(AM_V_GEN)cp $< $@
+endif
+endif
diff --git a/connman/NEWS b/connman/NEWS
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/connman/NEWS
diff --git a/connman/README b/connman/README
new file mode 100644
index 0000000..531f396
--- /dev/null
+++ b/connman/README
@@ -0,0 +1,399 @@
+Connection Manager
+******************
+
+Copyright (C) 2007-2012  Intel Corporation. All rights reserved.
+
+
+Functionality and features
+==========================
+
+The following features are built-in into Connection Manager:
+	- Generic plugin infrastructure
+	- Device and network abstraction (with basic storage support)
+	- IPv4, IPv4-LL (link-local) and DHCP
+	- IPv6, DHCPv6 and 6to4 tunnels
+	- Advanced routing and DNS configuration
+	- Built-in DNS proxy and intelligent caching
+	- Built-in WISPr hotspot logins and portal detection
+	- Time and timezone configuration (manual and automatic with NTP)
+	- Proxy handling (manual and automatic with WPAD)
+	- Tethering support (USB, Bluetooth and WiFi AP mode)
+	- Detailed statistics handling (home and roaming)
+
+Various plugins can be enabled for networking support:
+	- Ethernet plugin
+	- WiFi plugin with WEP40/WEP128 and WPA/WPA2 (personal and enterprise)
+	- Bluetooth plugin (using BlueZ)
+	- 2G/3G/4G plugin (using oFono)
+
+Also plugins with additional features are available:
+	- Loopback interface setup
+	- PACrunner proxy handling
+	- PolicyKit authorization support
+
+Note that when ConnMan starts, it clears all network interfaces that are
+going to be used. If this is not desired, network interfaces can be ignored
+either by setting NetworkInterfaceBlacklist in the main.conf config file or
+by using the -I command line option.
+
+
+Compilation and installation
+============================
+
+In order to compile Connection Manager you need following software packages:
+	- GCC compiler
+	- GLib library
+	- D-Bus library
+	- IP-Tables library (for tethering support)
+	- GnuTLS library (optional)
+	- PolicyKit (optional)
+	- readline (command line client)
+
+To configure run:
+	./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var
+
+Configure automatically searches for all required components and packages.
+
+To compile and install run:
+	make && make install
+
+
+Configuration and options
+=========================
+
+For a working system, certain configuration options need to be enabled:
+
+	--disable-ethernet
+
+		Disable support for Ethernet network cards
+
+		By default Ethernet technology support is built-in and
+		enabled. This option can be used to build a small daemon
+		for a specific system if Ethernet support is not required.
+
+	--disable-gadget
+
+		Disable support for USB Ethernet Gadget devices
+
+		By default USB Ethernet Gadget technology support is built-in and
+		enabled. This option can be used to build a small daemon
+		for a specific system if USB Ethernet Gadget support is not required.
+
+	--disable-wifi
+
+		Disable support for WiFi devices
+
+		By default WiFi technology support is built-in and
+		enabled. This option can be used to build a small daemon
+		for a specific system if WiFi support is not required.
+
+		It is safe to build a daemon with WiFi support and no
+		running wpa_supplicant. The start of wpa_supplicant is
+		automatically detected and only a runtime dependency. It
+		is not needed to build ConnMan.
+
+	--disable-bluetooth
+
+		Disable support for Bluetooth devices
+
+		By default Bluetooth technology support is built-in and
+		enabled. This option can be used to build a small daemon
+		for a specific system if Bluetooth support is not required.
+
+		It is safe to build a daemon with Bluetooth support and no
+		running bluetoothd. The start of bluetoothd is automatically
+		detected and only a runtime dependency. It is not needed to
+		build ConnMan.
+
+	--disable-ofono
+
+		Disable support for cellular 2G/3G/4G devices
+
+		By default oFono technology support is built-in and
+		enabled. This option can be used to build a small daemon
+		for a specific system where oFono is not used.
+
+		It is safe to build a daemon with oFono support and no
+		running ofonod. That start of ofonod is automatically
+		detected and only a runtime dependency. It is not needed to
+		build ConnMan.
+
+	--disable-dundee
+
+		Disable support for Bluetooth DUN devices
+
+		By default Bluetooth DUN technology (dundee) support is
+		built-in and enabled. This option can be used to build a
+		small daemon for a specific system where dundee is not used.
+
+		It is safe to build a daemon with dundee support and no
+		running dundee. That start of dundee is automatically
+		detected and only a runtime dependency. It is not needed to
+		build ConnMan.
+
+	--disable-pacrunner
+
+		Disable support for PACrunner proxy handling
+
+		By default PACrunner support is built-in and enabled. This
+		option can be used to build a small daemon for a specific
+		system where PACrunner is not used.
+
+		It is safe to build a daemon with PACrunner support and no
+		pacrunner daemon. It will detect and start a PACrunner
+		process if needed at runtime. The presence is not needed
+		to build ConnMan.
+
+	--disable-loopback
+
+		Disable setup of loopback device
+
+		For distributions with a really minimal init system and no
+		networking scripts this can take care of setting up the
+		loopback device and enabling it.
+
+		It is safe to leave this selected even if networking
+		scripts are in place. It detects an already configured
+		loopback device and leaves it as it is.
+
+	--disable-wispr
+
+		Disable support for WISPr hotspot logins
+
+		For systems with really minimal memory requirements, this
+		will disable the support for WISPr hotspot logins. The code
+		for WISPr will be still compiled into the daemon, but its
+		requirement on GnuTLS for secure connections will be lifted.
+
+		The missing GnuTLS support shrinks the memory requirements
+		by about 30% and for systems that are more stationary and do
+		not log into hotspots this might be a better trade off.
+
+		Disabling WISPr support is not disabling the portal detection
+		support. A portal will still be detected, but instead of being
+		asked for login credentials, the request for a browser session
+		will be made through the agent.
+
+	--enable-polkit
+
+		Enable support for PolicyKit authorization
+
+		This allows to check every D-Bus access against a security
+		policy and so restrict access to certain functionality.
+
+	--enable-nmcompat
+
+		Enable support for NetworkManager compatibility interfaces
+
+		This allows to expose a minimal set of NetworkManager
+		interfaces. It is useful for systems with applications
+		written to use NetworkManager to detect online/offline
+		status and have not yet been converted to use ConnMan.
+
+	--disable-client
+
+		Disable support for the command line client
+
+		By default the command line client is enabled and uses the
+		readline library. For specific systems where ConnMan is
+		configured by other means, the command line client can be
+		disabled and the dependency on readline is removed.
+
+	--enable-selinux
+
+		Enable support for compiling SElinux type enforcement rules
+
+		The TE rules are needed if host environment is in enforcing
+		mode. Without this option, the VPN client process cannot
+		send notification to connman-vpnd via net.connman.Task
+		interface. The compiled connman-task.pp module needs to
+		also installed using this command
+			# semodule -i connman-task.pp
+		in order to enable the dbus access.
+
+
+Activating debugging
+====================
+
+One can activate debugging prints in ConnMan using -d command line option.
+If the -d option has no parameters, then debugging is activated for all
+source code files. If the -d option has parameters, they tell which source
+code files have debugging activated. One can use wild cards in file names.
+Example:
+    -d                   Activate all normal debug prints
+    -d src/service.c     This prints debugging info from src/service.c
+                         file only
+    -d src/network.c:src/ipconfig.c
+                         This activates debug prints in src/network.c
+                         and src/ipconfig.c files.
+    -d 'src/n*.c'        This would activate debug print from all the C source
+                         files starting with letter 'n' in src directory.
+                         Note the quotation marks around option, that is to
+                         prevent shell expansion.
+    -d '*/n*.c:*/i*.c'   Activate debug prints for all C source files starting
+                         with letters 'n' or 'i' in any sub-directory.
+
+Some components of ConnMan have environment variable activated debug prints.
+If the environment variable is set, then corresponding component will print
+some extra debugging information.
+Following environment variables can be used:
+    CONNMAN_DHCP_DEBUG        DHCPv4 related debug information
+    CONNMAN_DHCPV6_DEBUG      DHCPv6 related debug information
+    CONNMAN_IPTABLES_DEBUG    Extra information when iptables is used
+    CONNMAN_RESOLV_DEBUG      Name resolver debug prints. These debug prints
+                              are used when ConnMan resolves host names for
+                              its own use.
+                              Note that the DNS proxy debug prints do not
+                              use this environment variable. For that, one
+                              can use "-d src/dnsproxy.c" command line option.
+    CONNMAN_SUPPLICANT_DEBUG  Debugging prints for communication between
+                              connmand and wpa_supplicant processes.
+    CONNMAN_WEB_DEBUG         Debug information when ConnMan does Internet
+                              connectivity check in Wispr and 6to4 components.
+
+Example:
+    CONNMAN_WEB_DEBUG=1 src/connmand -n
+
+If timing conditions are relevant then it is recommended command to
+get log traces as follows:
+    connmand -d 2>&1 | ts '[%H:%M:%.S]' | tee connman.log
+
+The 'ts' program is normaly avialable in the moreutils package.
+
+
+Kernel configuration
+====================
+
+In order to support tethering, the following kernel configuration options
+need to be enabled either as modules (m) or builtin (y):
+
+CONFIG_BRIDGE
+CONFIG_IP_NF_TARGET_MASQUERADE
+
+In order to enable CONFIG_IP_NF_TARGET_MASQUERADE, the following options need
+to be enabled also as modules (m) or builtin (y):
+
+CONFIG_NETFILTER
+CONFIG_NF_CONNTRACK_IPV4
+CONFIG_NF_NAT_IPV4
+
+For routing and statistic support in Sessions, the following options
+need to be enabled as modules (m) or builtin (y):
+
+CONFIG_IP_NF_IPTABLES
+CONFIG_IP_MULTIPLE_TABLES
+CONFIG_NETFILTER_NETLINK_ACCT
+CONFIG_NETFILTER_XT_MATCH_NFACCT
+CONFIG_NETFILTER_XT_CONNMARK
+CONFIG_NETFILTER_XT_TARGET_CONNMARK
+CONFIG_NETFILTER_XT_MATCH_CONNMARK
+
+In order to support USB gadget tethering, the following kernel configuration
+options need to be enabled:
+
+CONFIG_USB_GADGET
+CONFIG_USB_ETH
+
+
+wpa_supplicant configuration
+============================
+
+In order to get wpa_supplicant and Connection Manager working properly
+together you should edit wpa_supplicant .config file and set:
+
+CONFIG_WPS=y
+CONFIG_AP=y
+CONFIG_CTRL_IFACE_DBUS_NEW=y
+
+add:
+
+CONFIG_BGSCAN_SIMPLE=y
+
+This last option will enable the support of background scanning while being
+connected, which is necessary when roaming on wifi.
+
+It is recommended to use wpa_supplicant 2.x or later.
+
+If wpa_supplicant is configured to D-Bus autostart, then ConnMan will
+trigger the autostart of wpa_supplicant. However please keep in mind
+that this trigger only happens once. If wpa_supplicant stops or crashes,
+ConnMan does not periodically try to autostart it. It is up to systemd or
+similar service management tool to autostart it.
+
+
+VPN
+===
+
+In order to compile pptp and l2tp VPN plugins, you need ppp development
+package.
+
+To run l2tp you will need
+	- xl2tpd, http://www.xelerance.com/services/software/xl2tpd
+
+To run pptp you will need
+	- pptp client, http://pptpclient.sourceforge.net
+
+Both l2tp and pptp also need pppd.
+
+
+OpenVPN
+=======
+
+Up to version 2.2 of OpenVPN, pushing additional routes from the
+server will not always work. Some of the symptons are that additional
+routes will not be set by ConnMan if the uplink is a cellular
+network. While the same setup works well for a WiFi or ethernet
+uplink.
+
+
+Online check
+============
+
+ConnMan tries to detect if it has Internet connection or not when
+a service is connected. If the online check succeeds the service
+enters Online state, if not it stays in Ready state. The online
+check is also used to detect whether ConnMan is behind a captive
+portal like when you are in hotel and need to pay for connectivity.
+
+The online check is done by trying to fetch status.html document
+from ipv4.connman.net (for IPv4 connectivity) and ipv6.connman.net
+(for IPv6 connectivity). The used URL looks like this
+http://ipv{4|6}.connman.net/online/status.html
+
+During the online check procedure, ConnMan will temporarily install
+a host route to both the ipv4.connman.net and ipv6.connman.net so that
+the online check query can be directed via the correct network
+interface which the connected service is using. This host route is
+automatically removed when the online check is done.
+
+ConnMan sends this very minimal information in http header when doing
+the online check request (example):
+	Host: ipv4.connman.net
+	User-Agent: ConnMan/1.23 wispr
+	Connection: close
+
+Currently following information is returned from connman.net if
+the connection is successfull (200 OK http response code is returned):
+	Server: nginx
+	Date: Mon, 09 Jun 2014 09:25:42 GMT
+	Content-Type: text/html
+	Connection: close
+	X-ConnMan-Status: online
+
+The X-ConnMan-Status field is used in portal detection, if it is missing
+ConnMan will call RequestBrowser method in net.connman.Agent dbus
+interface to handle the portal login if the portal does not support WISPr.
+See doc/agent-api.txt for more details.
+
+
+Information
+===========
+
+Mailing list:
+	connman@connman.net
+
+For additional information about the project visit ConnMan web site:
+	https://01.org/connman
+	http://www.connman.net
+
+You can report bugs at https://01.org/jira/browse/CM
diff --git a/connman/TODO b/connman/TODO
new file mode 100644
index 0000000..dac2ea2
--- /dev/null
+++ b/connman/TODO
@@ -0,0 +1,222 @@
+Background
+==========
+
+- Priority scale: High, Medium and Low
+
+- Complexity scale: C1, C2, C4 and C8.
+   The complexity scale is exponential, with complexity 1 being the
+   lowest complexity. Complexity is a function of both task 'complexity'
+   and task 'scope'.
+
+
+Core
+====
+
+- Personal firewall
+
+   Priority: Low
+   Complexity: C8
+
+   Discuss and implement a basic and safe firewalling strategy into
+   Connman. Provide a D-Bus API for personal firewalling.
+
+
+- PACRunner extensions
+
+   Priority: Low
+   Complexity: C4
+
+   Support more URI schemes, support multiple connections, tighter
+   security integration.
+
+
+- Check logging produced by connman_info()
+
+   Priority: Medium
+   Complexity: C1
+
+   Check that logging produced by connman_info() contains meaningful messages
+   and get rid of the unnecessary ones.
+
+
+- Remove --nobacktrace option
+
+   Priority: Medium
+   Complexity: C1
+   When: 2.0
+
+   Remove the --nobacktrace option or change it to --backtrace depending on
+   the level of systemd integration or other factors.
+
+
+- Clean up data structure usage
+
+   Priority: Medium
+   Complexity: C4
+
+   Use hash tables, queues and lists in the code. Check on the currently used
+   data structures and see if something can be simplified.
+
+
+- Unit tests for DHCP, DNS and HTTP
+
+   Priority: Low
+   Complexity: C4
+
+   Create unit tests for these components starting with DHCP. Use gtest
+   from GLib for this task similarly to what has been done for OBEX in Bluez
+   and oFono in general.
+
+
+- Support other time sources than NTP
+
+   Priority: Low
+   Complexity: C2
+
+   Support other time sources like cellular, GPS in addition to NTP.
+
+
+- Get interface names from src/device.c
+
+   Priority: Low
+   Complexity: C2
+
+   Instead of using ioctls in connman_inet_ifindex and connman_inet_ifname,
+   utilize the information already provided by netlink in src/device.c.
+
+
+- Simplify gateway selection code
+
+   Priority: Low
+   Complexity: C4
+
+   The service list is always sorted according to preference with the
+   first service always owning the default route. See if update_order and
+   find_default_gateway in src/connection.c can be modified to use the
+   sorted service list instead of walking through the gateway_hash.
+
+
+- Support D-Bus ObjectManager
+
+   Priority: Medium
+   Complexity: C4
+
+   Support D-Bus ObjectManager by using functionality already present in
+   ./gdbus. Method calls and signals are already registered with gdbus, but
+   properties and replies especially in Agent are still handled with plain
+   dbus library function calls.
+
+   With this, Manager API is removed, and a WiFi P2P API based on
+   ObjectManager common to Linux desktops can be implemented.
+
+
+WiFi
+====
+
+- Clean up WiFi data structure usage
+
+   Priority: Medium
+   Complexity: C2
+
+   Struct wifi_data is passed as a pointer in some of the wifi plugin
+   callbacks. For example removing a WiFi USB stick causes RTNL and
+   wpa_supplicant to call the wifi plugin at the same time causing the
+   freeing of the wifi data structure. Fix up the code to have proper
+   reference counting or other handling in place for the shared wifi data
+   and the members in the data structure.
+
+
+- EAP-AKA/SIM
+
+   Priority: Medium
+   Complexity: C2
+
+   This EAP is needed for SIM card based network authentication.
+   ConnMan here plays a minor role: Once wpa_supplicant is set up for
+   starting and EAP-AKA/SIM authentication, it will talk to a SIM card
+   through its pcsc-lite API.
+
+
+- EAP-FAST
+
+   Priority: Low
+   Complexity: C1
+
+
+- Removing wpa_supplicant 0.7.x legacy support
+
+  Priority: Low
+  Complexity: C1
+
+  Removing global country property setter in gsupplicant, and removing
+  wifi's technology set_regdom implementation. Removing autoscan fallback.
+  (Note: should be done around the end 2012)
+
+Bluetooth
+=========
+
+- Remove Bluez 4.x support
+
+  Priority: Low
+  Complexity: C1
+
+  Remove plugins/bluetooth-legacy.c support in about 6 month (July 2013) or
+  when Bluez 4.x usage becomes minimal.
+
+Cellular
+========
+
+
+VPN
+===
+
+- IPsec
+
+   Priority: Medium
+   Complexity: C4
+
+
+- L2TP & PPTP compatibility prefix removal
+
+   Priority: Medium
+   Complexity: C1
+   When: connman 2.0
+
+   The VPN config file provisioning patchset contains code that makes
+   PPP options to be marked by "PPPD." prefix. The code supports also
+   old "L2TP." and "PPTP." prefix for PPP options. Remove the compatibility
+   code and only allow "PPPD." prefix for PPP options.
+
+
+- Update VPNC and OpenVPN with Agent support
+
+   Priority: Medium
+   Complexity: C2
+
+   Update VPNC and OpenVPN with VPN Agent support to request possible user
+   ids and passphrases.
+
+
+Tools
+=====
+
+- Add Clock API and MoveBefore/MoveAfter support to connmanctl
+
+   Priority: Low
+   Complexity: C2
+
+   The connmanctl command line tool should support Clock API and Service API
+   MoveBefore/MoveAfter.
+
+
+User Interface
+==============
+
+- GNOME3 UI
+
+   Priority: Low
+   Complexity: C4
+
+   A GNOME3 shell user interface would make it easier for mainstream distros
+   users to use ConnMan. Continue/restart the work at
+   https://github.com/connectivity/gnome-extension-connman
diff --git a/connman/acinclude.m4 b/connman/acinclude.m4
new file mode 100644
index 0000000..9e8e0dc
--- /dev/null
+++ b/connman/acinclude.m4
@@ -0,0 +1,27 @@
+AC_DEFUN([AC_PROG_CC_PIE], [
+	AC_CACHE_CHECK([whether ${CC-cc} accepts -fPIE], ac_cv_prog_cc_pie, [
+		echo 'void f(){}' > conftest.c
+		if test -z "`${CC-cc} -fPIE -pie -c conftest.c 2>&1`"; then
+			ac_cv_prog_cc_pie=yes
+		else
+			ac_cv_prog_cc_pie=no
+		fi
+		rm -rf conftest*
+	])
+])
+
+AC_DEFUN([COMPILER_FLAGS], [
+	if (test "${CFLAGS}" = ""); then
+		CFLAGS="-Wall -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2"
+	fi
+	if (test "$USE_MAINTAINER_MODE" = "yes"); then
+		CFLAGS+=" -Werror -Wextra"
+		CFLAGS+=" -Wno-unused-parameter"
+		CFLAGS+=" -Wno-missing-field-initializers"
+		CFLAGS+=" -Wdeclaration-after-statement"
+		CFLAGS+=" -Wmissing-declarations"
+		CFLAGS+=" -Wredundant-decls"
+		CFLAGS+=" -Wcast-align"
+		CFLAGS="$CFLAGS -DG_DISABLE_DEPRECATED"
+	fi
+])
diff --git a/connman/aclocal.m4 b/connman/aclocal.m4
new file mode 100644
index 0000000..8bd327b
--- /dev/null
+++ b/connman/aclocal.m4
@@ -0,0 +1,9948 @@
+# generated automatically by aclocal 1.14.1 -*- Autoconf -*-
+
+# Copyright (C) 1996-2013 Free Software Foundation, Inc.
+
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+m4_ifndef([AC_CONFIG_MACRO_DIRS], [m4_defun([_AM_CONFIG_MACRO_DIRS], [])m4_defun([AC_CONFIG_MACRO_DIRS], [_AM_CONFIG_MACRO_DIRS($@)])])
+m4_ifndef([AC_AUTOCONF_VERSION],
+  [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl
+m4_if(m4_defn([AC_AUTOCONF_VERSION]), [2.69],,
+[m4_warning([this file was generated for autoconf 2.69.
+You have another version of autoconf.  It may work, but is not guaranteed to.
+If you have problems, you may need to regenerate the build system entirely.
+To do so, use the procedure documented by the package, typically 'autoreconf'.])])
+
+# libtool.m4 - Configure libtool for the host system. -*-Autoconf-*-
+#
+#   Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005,
+#                 2006, 2007, 2008, 2009, 2010, 2011 Free Software
+#                 Foundation, Inc.
+#   Written by Gordon Matzigkeit, 1996
+#
+# This file is free software; the Free Software Foundation gives
+# unlimited permission to copy and/or distribute it, with or without
+# modifications, as long as this notice is preserved.
+
+m4_define([_LT_COPYING], [dnl
+#   Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005,
+#                 2006, 2007, 2008, 2009, 2010, 2011 Free Software
+#                 Foundation, Inc.
+#   Written by Gordon Matzigkeit, 1996
+#
+#   This file is part of GNU Libtool.
+#
+# GNU Libtool is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2 of
+# the License, or (at your option) any later version.
+#
+# As a special exception to the GNU General Public License,
+# if you distribute this file as part of a program or library that
+# is built using GNU Libtool, you may include this file under the
+# same distribution terms that you use for the rest of that program.
+#
+# GNU Libtool 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 GNU Libtool; see the file COPYING.  If not, a copy
+# can be downloaded from http://www.gnu.org/licenses/gpl.html, or
+# obtained by writing to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+])
+
+# serial 57 LT_INIT
+
+
+# LT_PREREQ(VERSION)
+# ------------------
+# Complain and exit if this libtool version is less that VERSION.
+m4_defun([LT_PREREQ],
+[m4_if(m4_version_compare(m4_defn([LT_PACKAGE_VERSION]), [$1]), -1,
+       [m4_default([$3],
+		   [m4_fatal([Libtool version $1 or higher is required],
+		             63)])],
+       [$2])])
+
+
+# _LT_CHECK_BUILDDIR
+# ------------------
+# Complain if the absolute build directory name contains unusual characters
+m4_defun([_LT_CHECK_BUILDDIR],
+[case `pwd` in
+  *\ * | *\	*)
+    AC_MSG_WARN([Libtool does not cope well with whitespace in `pwd`]) ;;
+esac
+])
+
+
+# LT_INIT([OPTIONS])
+# ------------------
+AC_DEFUN([LT_INIT],
+[AC_PREREQ([2.58])dnl We use AC_INCLUDES_DEFAULT
+AC_REQUIRE([AC_CONFIG_AUX_DIR_DEFAULT])dnl
+AC_BEFORE([$0], [LT_LANG])dnl
+AC_BEFORE([$0], [LT_OUTPUT])dnl
+AC_BEFORE([$0], [LTDL_INIT])dnl
+m4_require([_LT_CHECK_BUILDDIR])dnl
+
+dnl Autoconf doesn't catch unexpanded LT_ macros by default:
+m4_pattern_forbid([^_?LT_[A-Z_]+$])dnl
+m4_pattern_allow([^(_LT_EOF|LT_DLGLOBAL|LT_DLLAZY_OR_NOW|LT_MULTI_MODULE)$])dnl
+dnl aclocal doesn't pull ltoptions.m4, ltsugar.m4, or ltversion.m4
+dnl unless we require an AC_DEFUNed macro:
+AC_REQUIRE([LTOPTIONS_VERSION])dnl
+AC_REQUIRE([LTSUGAR_VERSION])dnl
+AC_REQUIRE([LTVERSION_VERSION])dnl
+AC_REQUIRE([LTOBSOLETE_VERSION])dnl
+m4_require([_LT_PROG_LTMAIN])dnl
+
+_LT_SHELL_INIT([SHELL=${CONFIG_SHELL-/bin/sh}])
+
+dnl Parse OPTIONS
+_LT_SET_OPTIONS([$0], [$1])
+
+# This can be used to rebuild libtool when needed
+LIBTOOL_DEPS="$ltmain"
+
+# Always use our own libtool.
+LIBTOOL='$(SHELL) $(top_builddir)/libtool'
+AC_SUBST(LIBTOOL)dnl
+
+_LT_SETUP
+
+# Only expand once:
+m4_define([LT_INIT])
+])# LT_INIT
+
+# Old names:
+AU_ALIAS([AC_PROG_LIBTOOL], [LT_INIT])
+AU_ALIAS([AM_PROG_LIBTOOL], [LT_INIT])
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AC_PROG_LIBTOOL], [])
+dnl AC_DEFUN([AM_PROG_LIBTOOL], [])
+
+
+# _LT_CC_BASENAME(CC)
+# -------------------
+# Calculate cc_basename.  Skip known compiler wrappers and cross-prefix.
+m4_defun([_LT_CC_BASENAME],
+[for cc_temp in $1""; do
+  case $cc_temp in
+    compile | *[[\\/]]compile | ccache | *[[\\/]]ccache ) ;;
+    distcc | *[[\\/]]distcc | purify | *[[\\/]]purify ) ;;
+    \-*) ;;
+    *) break;;
+  esac
+done
+cc_basename=`$ECHO "$cc_temp" | $SED "s%.*/%%; s%^$host_alias-%%"`
+])
+
+
+# _LT_FILEUTILS_DEFAULTS
+# ----------------------
+# It is okay to use these file commands and assume they have been set
+# sensibly after `m4_require([_LT_FILEUTILS_DEFAULTS])'.
+m4_defun([_LT_FILEUTILS_DEFAULTS],
+[: ${CP="cp -f"}
+: ${MV="mv -f"}
+: ${RM="rm -f"}
+])# _LT_FILEUTILS_DEFAULTS
+
+
+# _LT_SETUP
+# ---------
+m4_defun([_LT_SETUP],
+[AC_REQUIRE([AC_CANONICAL_HOST])dnl
+AC_REQUIRE([AC_CANONICAL_BUILD])dnl
+AC_REQUIRE([_LT_PREPARE_SED_QUOTE_VARS])dnl
+AC_REQUIRE([_LT_PROG_ECHO_BACKSLASH])dnl
+
+_LT_DECL([], [PATH_SEPARATOR], [1], [The PATH separator for the build system])dnl
+dnl
+_LT_DECL([], [host_alias], [0], [The host system])dnl
+_LT_DECL([], [host], [0])dnl
+_LT_DECL([], [host_os], [0])dnl
+dnl
+_LT_DECL([], [build_alias], [0], [The build system])dnl
+_LT_DECL([], [build], [0])dnl
+_LT_DECL([], [build_os], [0])dnl
+dnl
+AC_REQUIRE([AC_PROG_CC])dnl
+AC_REQUIRE([LT_PATH_LD])dnl
+AC_REQUIRE([LT_PATH_NM])dnl
+dnl
+AC_REQUIRE([AC_PROG_LN_S])dnl
+test -z "$LN_S" && LN_S="ln -s"
+_LT_DECL([], [LN_S], [1], [Whether we need soft or hard links])dnl
+dnl
+AC_REQUIRE([LT_CMD_MAX_LEN])dnl
+_LT_DECL([objext], [ac_objext], [0], [Object file suffix (normally "o")])dnl
+_LT_DECL([], [exeext], [0], [Executable file suffix (normally "")])dnl
+dnl
+m4_require([_LT_FILEUTILS_DEFAULTS])dnl
+m4_require([_LT_CHECK_SHELL_FEATURES])dnl
+m4_require([_LT_PATH_CONVERSION_FUNCTIONS])dnl
+m4_require([_LT_CMD_RELOAD])dnl
+m4_require([_LT_CHECK_MAGIC_METHOD])dnl
+m4_require([_LT_CHECK_SHAREDLIB_FROM_LINKLIB])dnl
+m4_require([_LT_CMD_OLD_ARCHIVE])dnl
+m4_require([_LT_CMD_GLOBAL_SYMBOLS])dnl
+m4_require([_LT_WITH_SYSROOT])dnl
+
+_LT_CONFIG_LIBTOOL_INIT([
+# See if we are running on zsh, and set the options which allow our
+# commands through without removal of \ escapes INIT.
+if test -n "\${ZSH_VERSION+set}" ; then
+   setopt NO_GLOB_SUBST
+fi
+])
+if test -n "${ZSH_VERSION+set}" ; then
+   setopt NO_GLOB_SUBST
+fi
+
+_LT_CHECK_OBJDIR
+
+m4_require([_LT_TAG_COMPILER])dnl
+
+case $host_os in
+aix3*)
+  # AIX sometimes has problems with the GCC collect2 program.  For some
+  # reason, if we set the COLLECT_NAMES environment variable, the problems
+  # vanish in a puff of smoke.
+  if test "X${COLLECT_NAMES+set}" != Xset; then
+    COLLECT_NAMES=
+    export COLLECT_NAMES
+  fi
+  ;;
+esac
+
+# Global variables:
+ofile=libtool
+can_build_shared=yes
+
+# All known linkers require a `.a' archive for static linking (except MSVC,
+# which needs '.lib').
+libext=a
+
+with_gnu_ld="$lt_cv_prog_gnu_ld"
+
+old_CC="$CC"
+old_CFLAGS="$CFLAGS"
+
+# Set sane defaults for various variables
+test -z "$CC" && CC=cc
+test -z "$LTCC" && LTCC=$CC
+test -z "$LTCFLAGS" && LTCFLAGS=$CFLAGS
+test -z "$LD" && LD=ld
+test -z "$ac_objext" && ac_objext=o
+
+_LT_CC_BASENAME([$compiler])
+
+# Only perform the check for file, if the check method requires it
+test -z "$MAGIC_CMD" && MAGIC_CMD=file
+case $deplibs_check_method in
+file_magic*)
+  if test "$file_magic_cmd" = '$MAGIC_CMD'; then
+    _LT_PATH_MAGIC
+  fi
+  ;;
+esac
+
+# Use C for the default configuration in the libtool script
+LT_SUPPORTED_TAG([CC])
+_LT_LANG_C_CONFIG
+_LT_LANG_DEFAULT_CONFIG
+_LT_CONFIG_COMMANDS
+])# _LT_SETUP
+
+
+# _LT_PREPARE_SED_QUOTE_VARS
+# --------------------------
+# Define a few sed substitution that help us do robust quoting.
+m4_defun([_LT_PREPARE_SED_QUOTE_VARS],
+[# Backslashify metacharacters that are still active within
+# double-quoted strings.
+sed_quote_subst='s/\([["`$\\]]\)/\\\1/g'
+
+# Same as above, but do not quote variable references.
+double_quote_subst='s/\([["`\\]]\)/\\\1/g'
+
+# Sed substitution to delay expansion of an escaped shell variable in a
+# double_quote_subst'ed string.
+delay_variable_subst='s/\\\\\\\\\\\$/\\\\\\$/g'
+
+# Sed substitution to delay expansion of an escaped single quote.
+delay_single_quote_subst='s/'\''/'\'\\\\\\\'\''/g'
+
+# Sed substitution to avoid accidental globbing in evaled expressions
+no_glob_subst='s/\*/\\\*/g'
+])
+
+# _LT_PROG_LTMAIN
+# ---------------
+# Note that this code is called both from `configure', and `config.status'
+# now that we use AC_CONFIG_COMMANDS to generate libtool.  Notably,
+# `config.status' has no value for ac_aux_dir unless we are using Automake,
+# so we pass a copy along to make sure it has a sensible value anyway.
+m4_defun([_LT_PROG_LTMAIN],
+[m4_ifdef([AC_REQUIRE_AUX_FILE], [AC_REQUIRE_AUX_FILE([ltmain.sh])])dnl
+_LT_CONFIG_LIBTOOL_INIT([ac_aux_dir='$ac_aux_dir'])
+ltmain="$ac_aux_dir/ltmain.sh"
+])# _LT_PROG_LTMAIN
+
+
+
+# So that we can recreate a full libtool script including additional
+# tags, we accumulate the chunks of code to send to AC_CONFIG_COMMANDS
+# in macros and then make a single call at the end using the `libtool'
+# label.
+
+
+# _LT_CONFIG_LIBTOOL_INIT([INIT-COMMANDS])
+# ----------------------------------------
+# Register INIT-COMMANDS to be passed to AC_CONFIG_COMMANDS later.
+m4_define([_LT_CONFIG_LIBTOOL_INIT],
+[m4_ifval([$1],
+          [m4_append([_LT_OUTPUT_LIBTOOL_INIT],
+                     [$1
+])])])
+
+# Initialize.
+m4_define([_LT_OUTPUT_LIBTOOL_INIT])
+
+
+# _LT_CONFIG_LIBTOOL([COMMANDS])
+# ------------------------------
+# Register COMMANDS to be passed to AC_CONFIG_COMMANDS later.
+m4_define([_LT_CONFIG_LIBTOOL],
+[m4_ifval([$1],
+          [m4_append([_LT_OUTPUT_LIBTOOL_COMMANDS],
+                     [$1
+])])])
+
+# Initialize.
+m4_define([_LT_OUTPUT_LIBTOOL_COMMANDS])
+
+
+# _LT_CONFIG_SAVE_COMMANDS([COMMANDS], [INIT_COMMANDS])
+# -----------------------------------------------------
+m4_defun([_LT_CONFIG_SAVE_COMMANDS],
+[_LT_CONFIG_LIBTOOL([$1])
+_LT_CONFIG_LIBTOOL_INIT([$2])
+])
+
+
+# _LT_FORMAT_COMMENT([COMMENT])
+# -----------------------------
+# Add leading comment marks to the start of each line, and a trailing
+# full-stop to the whole comment if one is not present already.
+m4_define([_LT_FORMAT_COMMENT],
+[m4_ifval([$1], [
+m4_bpatsubst([m4_bpatsubst([$1], [^ *], [# ])],
+              [['`$\]], [\\\&])]m4_bmatch([$1], [[!?.]$], [], [.])
+)])
+
+
+
+
+
+# _LT_DECL([CONFIGNAME], VARNAME, VALUE, [DESCRIPTION], [IS-TAGGED?])
+# -------------------------------------------------------------------
+# CONFIGNAME is the name given to the value in the libtool script.
+# VARNAME is the (base) name used in the configure script.
+# VALUE may be 0, 1 or 2 for a computed quote escaped value based on
+# VARNAME.  Any other value will be used directly.
+m4_define([_LT_DECL],
+[lt_if_append_uniq([lt_decl_varnames], [$2], [, ],
+    [lt_dict_add_subkey([lt_decl_dict], [$2], [libtool_name],
+	[m4_ifval([$1], [$1], [$2])])
+    lt_dict_add_subkey([lt_decl_dict], [$2], [value], [$3])
+    m4_ifval([$4],
+	[lt_dict_add_subkey([lt_decl_dict], [$2], [description], [$4])])
+    lt_dict_add_subkey([lt_decl_dict], [$2],
+	[tagged?], [m4_ifval([$5], [yes], [no])])])
+])
+
+
+# _LT_TAGDECL([CONFIGNAME], VARNAME, VALUE, [DESCRIPTION])
+# --------------------------------------------------------
+m4_define([_LT_TAGDECL], [_LT_DECL([$1], [$2], [$3], [$4], [yes])])
+
+
+# lt_decl_tag_varnames([SEPARATOR], [VARNAME1...])
+# ------------------------------------------------
+m4_define([lt_decl_tag_varnames],
+[_lt_decl_filter([tagged?], [yes], $@)])
+
+
+# _lt_decl_filter(SUBKEY, VALUE, [SEPARATOR], [VARNAME1..])
+# ---------------------------------------------------------
+m4_define([_lt_decl_filter],
+[m4_case([$#],
+  [0], [m4_fatal([$0: too few arguments: $#])],
+  [1], [m4_fatal([$0: too few arguments: $#: $1])],
+  [2], [lt_dict_filter([lt_decl_dict], [$1], [$2], [], lt_decl_varnames)],
+  [3], [lt_dict_filter([lt_decl_dict], [$1], [$2], [$3], lt_decl_varnames)],
+  [lt_dict_filter([lt_decl_dict], $@)])[]dnl
+])
+
+
+# lt_decl_quote_varnames([SEPARATOR], [VARNAME1...])
+# --------------------------------------------------
+m4_define([lt_decl_quote_varnames],
+[_lt_decl_filter([value], [1], $@)])
+
+
+# lt_decl_dquote_varnames([SEPARATOR], [VARNAME1...])
+# ---------------------------------------------------
+m4_define([lt_decl_dquote_varnames],
+[_lt_decl_filter([value], [2], $@)])
+
+
+# lt_decl_varnames_tagged([SEPARATOR], [VARNAME1...])
+# ---------------------------------------------------
+m4_define([lt_decl_varnames_tagged],
+[m4_assert([$# <= 2])dnl
+_$0(m4_quote(m4_default([$1], [[, ]])),
+    m4_ifval([$2], [[$2]], [m4_dquote(lt_decl_tag_varnames)]),
+    m4_split(m4_normalize(m4_quote(_LT_TAGS)), [ ]))])
+m4_define([_lt_decl_varnames_tagged],
+[m4_ifval([$3], [lt_combine([$1], [$2], [_], $3)])])
+
+
+# lt_decl_all_varnames([SEPARATOR], [VARNAME1...])
+# ------------------------------------------------
+m4_define([lt_decl_all_varnames],
+[_$0(m4_quote(m4_default([$1], [[, ]])),
+     m4_if([$2], [],
+	   m4_quote(lt_decl_varnames),
+	m4_quote(m4_shift($@))))[]dnl
+])
+m4_define([_lt_decl_all_varnames],
+[lt_join($@, lt_decl_varnames_tagged([$1],
+			lt_decl_tag_varnames([[, ]], m4_shift($@))))dnl
+])
+
+
+# _LT_CONFIG_STATUS_DECLARE([VARNAME])
+# ------------------------------------
+# Quote a variable value, and forward it to `config.status' so that its
+# declaration there will have the same value as in `configure'.  VARNAME
+# must have a single quote delimited value for this to work.
+m4_define([_LT_CONFIG_STATUS_DECLARE],
+[$1='`$ECHO "$][$1" | $SED "$delay_single_quote_subst"`'])
+
+
+# _LT_CONFIG_STATUS_DECLARATIONS
+# ------------------------------
+# We delimit libtool config variables with single quotes, so when
+# we write them to config.status, we have to be sure to quote all
+# embedded single quotes properly.  In configure, this macro expands
+# each variable declared with _LT_DECL (and _LT_TAGDECL) into:
+#
+#    <var>='`$ECHO "$<var>" | $SED "$delay_single_quote_subst"`'
+m4_defun([_LT_CONFIG_STATUS_DECLARATIONS],
+[m4_foreach([_lt_var], m4_quote(lt_decl_all_varnames),
+    [m4_n([_LT_CONFIG_STATUS_DECLARE(_lt_var)])])])
+
+
+# _LT_LIBTOOL_TAGS
+# ----------------
+# Output comment and list of tags supported by the script
+m4_defun([_LT_LIBTOOL_TAGS],
+[_LT_FORMAT_COMMENT([The names of the tagged configurations supported by this script])dnl
+available_tags="_LT_TAGS"dnl
+])
+
+
+# _LT_LIBTOOL_DECLARE(VARNAME, [TAG])
+# -----------------------------------
+# Extract the dictionary values for VARNAME (optionally with TAG) and
+# expand to a commented shell variable setting:
+#
+#    # Some comment about what VAR is for.
+#    visible_name=$lt_internal_name
+m4_define([_LT_LIBTOOL_DECLARE],
+[_LT_FORMAT_COMMENT(m4_quote(lt_dict_fetch([lt_decl_dict], [$1],
+					   [description])))[]dnl
+m4_pushdef([_libtool_name],
+    m4_quote(lt_dict_fetch([lt_decl_dict], [$1], [libtool_name])))[]dnl
+m4_case(m4_quote(lt_dict_fetch([lt_decl_dict], [$1], [value])),
+    [0], [_libtool_name=[$]$1],
+    [1], [_libtool_name=$lt_[]$1],
+    [2], [_libtool_name=$lt_[]$1],
+    [_libtool_name=lt_dict_fetch([lt_decl_dict], [$1], [value])])[]dnl
+m4_ifval([$2], [_$2])[]m4_popdef([_libtool_name])[]dnl
+])
+
+
+# _LT_LIBTOOL_CONFIG_VARS
+# -----------------------
+# Produce commented declarations of non-tagged libtool config variables
+# suitable for insertion in the LIBTOOL CONFIG section of the `libtool'
+# script.  Tagged libtool config variables (even for the LIBTOOL CONFIG
+# section) are produced by _LT_LIBTOOL_TAG_VARS.
+m4_defun([_LT_LIBTOOL_CONFIG_VARS],
+[m4_foreach([_lt_var],
+    m4_quote(_lt_decl_filter([tagged?], [no], [], lt_decl_varnames)),
+    [m4_n([_LT_LIBTOOL_DECLARE(_lt_var)])])])
+
+
+# _LT_LIBTOOL_TAG_VARS(TAG)
+# -------------------------
+m4_define([_LT_LIBTOOL_TAG_VARS],
+[m4_foreach([_lt_var], m4_quote(lt_decl_tag_varnames),
+    [m4_n([_LT_LIBTOOL_DECLARE(_lt_var, [$1])])])])
+
+
+# _LT_TAGVAR(VARNAME, [TAGNAME])
+# ------------------------------
+m4_define([_LT_TAGVAR], [m4_ifval([$2], [$1_$2], [$1])])
+
+
+# _LT_CONFIG_COMMANDS
+# -------------------
+# Send accumulated output to $CONFIG_STATUS.  Thanks to the lists of
+# variables for single and double quote escaping we saved from calls
+# to _LT_DECL, we can put quote escaped variables declarations
+# into `config.status', and then the shell code to quote escape them in
+# for loops in `config.status'.  Finally, any additional code accumulated
+# from calls to _LT_CONFIG_LIBTOOL_INIT is expanded.
+m4_defun([_LT_CONFIG_COMMANDS],
+[AC_PROVIDE_IFELSE([LT_OUTPUT],
+	dnl If the libtool generation code has been placed in $CONFIG_LT,
+	dnl instead of duplicating it all over again into config.status,
+	dnl then we will have config.status run $CONFIG_LT later, so it
+	dnl needs to know what name is stored there:
+        [AC_CONFIG_COMMANDS([libtool],
+            [$SHELL $CONFIG_LT || AS_EXIT(1)], [CONFIG_LT='$CONFIG_LT'])],
+    dnl If the libtool generation code is destined for config.status,
+    dnl expand the accumulated commands and init code now:
+    [AC_CONFIG_COMMANDS([libtool],
+        [_LT_OUTPUT_LIBTOOL_COMMANDS], [_LT_OUTPUT_LIBTOOL_COMMANDS_INIT])])
+])#_LT_CONFIG_COMMANDS
+
+
+# Initialize.
+m4_define([_LT_OUTPUT_LIBTOOL_COMMANDS_INIT],
+[
+
+# The HP-UX ksh and POSIX shell print the target directory to stdout
+# if CDPATH is set.
+(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
+
+sed_quote_subst='$sed_quote_subst'
+double_quote_subst='$double_quote_subst'
+delay_variable_subst='$delay_variable_subst'
+_LT_CONFIG_STATUS_DECLARATIONS
+LTCC='$LTCC'
+LTCFLAGS='$LTCFLAGS'
+compiler='$compiler_DEFAULT'
+
+# A function that is used when there is no print builtin or printf.
+func_fallback_echo ()
+{
+  eval 'cat <<_LTECHO_EOF
+\$[]1
+_LTECHO_EOF'
+}
+
+# Quote evaled strings.
+for var in lt_decl_all_varnames([[ \
+]], lt_decl_quote_varnames); do
+    case \`eval \\\\\$ECHO \\\\""\\\\\$\$var"\\\\"\` in
+    *[[\\\\\\\`\\"\\\$]]*)
+      eval "lt_\$var=\\\\\\"\\\`\\\$ECHO \\"\\\$\$var\\" | \\\$SED \\"\\\$sed_quote_subst\\"\\\`\\\\\\""
+      ;;
+    *)
+      eval "lt_\$var=\\\\\\"\\\$\$var\\\\\\""
+      ;;
+    esac
+done
+
+# Double-quote double-evaled strings.
+for var in lt_decl_all_varnames([[ \
+]], lt_decl_dquote_varnames); do
+    case \`eval \\\\\$ECHO \\\\""\\\\\$\$var"\\\\"\` in
+    *[[\\\\\\\`\\"\\\$]]*)
+      eval "lt_\$var=\\\\\\"\\\`\\\$ECHO \\"\\\$\$var\\" | \\\$SED -e \\"\\\$double_quote_subst\\" -e \\"\\\$sed_quote_subst\\" -e \\"\\\$delay_variable_subst\\"\\\`\\\\\\""
+      ;;
+    *)
+      eval "lt_\$var=\\\\\\"\\\$\$var\\\\\\""
+      ;;
+    esac
+done
+
+_LT_OUTPUT_LIBTOOL_INIT
+])
+
+# _LT_GENERATED_FILE_INIT(FILE, [COMMENT])
+# ------------------------------------
+# Generate a child script FILE with all initialization necessary to
+# reuse the environment learned by the parent script, and make the
+# file executable.  If COMMENT is supplied, it is inserted after the
+# `#!' sequence but before initialization text begins.  After this
+# macro, additional text can be appended to FILE to form the body of
+# the child script.  The macro ends with non-zero status if the
+# file could not be fully written (such as if the disk is full).
+m4_ifdef([AS_INIT_GENERATED],
+[m4_defun([_LT_GENERATED_FILE_INIT],[AS_INIT_GENERATED($@)])],
+[m4_defun([_LT_GENERATED_FILE_INIT],
+[m4_require([AS_PREPARE])]dnl
+[m4_pushdef([AS_MESSAGE_LOG_FD])]dnl
+[lt_write_fail=0
+cat >$1 <<_ASEOF || lt_write_fail=1
+#! $SHELL
+# Generated by $as_me.
+$2
+SHELL=\${CONFIG_SHELL-$SHELL}
+export SHELL
+_ASEOF
+cat >>$1 <<\_ASEOF || lt_write_fail=1
+AS_SHELL_SANITIZE
+_AS_PREPARE
+exec AS_MESSAGE_FD>&1
+_ASEOF
+test $lt_write_fail = 0 && chmod +x $1[]dnl
+m4_popdef([AS_MESSAGE_LOG_FD])])])# _LT_GENERATED_FILE_INIT
+
+# LT_OUTPUT
+# ---------
+# This macro allows early generation of the libtool script (before
+# AC_OUTPUT is called), incase it is used in configure for compilation
+# tests.
+AC_DEFUN([LT_OUTPUT],
+[: ${CONFIG_LT=./config.lt}
+AC_MSG_NOTICE([creating $CONFIG_LT])
+_LT_GENERATED_FILE_INIT(["$CONFIG_LT"],
+[# Run this file to recreate a libtool stub with the current configuration.])
+
+cat >>"$CONFIG_LT" <<\_LTEOF
+lt_cl_silent=false
+exec AS_MESSAGE_LOG_FD>>config.log
+{
+  echo
+  AS_BOX([Running $as_me.])
+} >&AS_MESSAGE_LOG_FD
+
+lt_cl_help="\
+\`$as_me' creates a local libtool stub from the current configuration,
+for use in further configure time tests before the real libtool is
+generated.
+
+Usage: $[0] [[OPTIONS]]
+
+  -h, --help      print this help, then exit
+  -V, --version   print version number, then exit
+  -q, --quiet     do not print progress messages
+  -d, --debug     don't remove temporary files
+
+Report bugs to <bug-libtool@gnu.org>."
+
+lt_cl_version="\
+m4_ifset([AC_PACKAGE_NAME], [AC_PACKAGE_NAME ])config.lt[]dnl
+m4_ifset([AC_PACKAGE_VERSION], [ AC_PACKAGE_VERSION])
+configured by $[0], generated by m4_PACKAGE_STRING.
+
+Copyright (C) 2011 Free Software Foundation, Inc.
+This config.lt script is free software; the Free Software Foundation
+gives unlimited permision to copy, distribute and modify it."
+
+while test $[#] != 0
+do
+  case $[1] in
+    --version | --v* | -V )
+      echo "$lt_cl_version"; exit 0 ;;
+    --help | --h* | -h )
+      echo "$lt_cl_help"; exit 0 ;;
+    --debug | --d* | -d )
+      debug=: ;;
+    --quiet | --q* | --silent | --s* | -q )
+      lt_cl_silent=: ;;
+
+    -*) AC_MSG_ERROR([unrecognized option: $[1]
+Try \`$[0] --help' for more information.]) ;;
+
+    *) AC_MSG_ERROR([unrecognized argument: $[1]
+Try \`$[0] --help' for more information.]) ;;
+  esac
+  shift
+done
+
+if $lt_cl_silent; then
+  exec AS_MESSAGE_FD>/dev/null
+fi
+_LTEOF
+
+cat >>"$CONFIG_LT" <<_LTEOF
+_LT_OUTPUT_LIBTOOL_COMMANDS_INIT
+_LTEOF
+
+cat >>"$CONFIG_LT" <<\_LTEOF
+AC_MSG_NOTICE([creating $ofile])
+_LT_OUTPUT_LIBTOOL_COMMANDS
+AS_EXIT(0)
+_LTEOF
+chmod +x "$CONFIG_LT"
+
+# configure is writing to config.log, but config.lt does its own redirection,
+# appending to config.log, which fails on DOS, as config.log is still kept
+# open by configure.  Here we exec the FD to /dev/null, effectively closing
+# config.log, so it can be properly (re)opened and appended to by config.lt.
+lt_cl_success=:
+test "$silent" = yes &&
+  lt_config_lt_args="$lt_config_lt_args --quiet"
+exec AS_MESSAGE_LOG_FD>/dev/null
+$SHELL "$CONFIG_LT" $lt_config_lt_args || lt_cl_success=false
+exec AS_MESSAGE_LOG_FD>>config.log
+$lt_cl_success || AS_EXIT(1)
+])# LT_OUTPUT
+
+
+# _LT_CONFIG(TAG)
+# ---------------
+# If TAG is the built-in tag, create an initial libtool script with a
+# default configuration from the untagged config vars.  Otherwise add code
+# to config.status for appending the configuration named by TAG from the
+# matching tagged config vars.
+m4_defun([_LT_CONFIG],
+[m4_require([_LT_FILEUTILS_DEFAULTS])dnl
+_LT_CONFIG_SAVE_COMMANDS([
+  m4_define([_LT_TAG], m4_if([$1], [], [C], [$1]))dnl
+  m4_if(_LT_TAG, [C], [
+    # See if we are running on zsh, and set the options which allow our
+    # commands through without removal of \ escapes.
+    if test -n "${ZSH_VERSION+set}" ; then
+      setopt NO_GLOB_SUBST
+    fi
+
+    cfgfile="${ofile}T"
+    trap "$RM \"$cfgfile\"; exit 1" 1 2 15
+    $RM "$cfgfile"
+
+    cat <<_LT_EOF >> "$cfgfile"
+#! $SHELL
+
+# `$ECHO "$ofile" | sed 's%^.*/%%'` - Provide generalized library-building support services.
+# Generated automatically by $as_me ($PACKAGE$TIMESTAMP) $VERSION
+# Libtool was configured on host `(hostname || uname -n) 2>/dev/null | sed 1q`:
+# NOTE: Changes made to this file will be lost: look at ltmain.sh.
+#
+_LT_COPYING
+_LT_LIBTOOL_TAGS
+
+# ### BEGIN LIBTOOL CONFIG
+_LT_LIBTOOL_CONFIG_VARS
+_LT_LIBTOOL_TAG_VARS
+# ### END LIBTOOL CONFIG
+
+_LT_EOF
+
+  case $host_os in
+  aix3*)
+    cat <<\_LT_EOF >> "$cfgfile"
+# AIX sometimes has problems with the GCC collect2 program.  For some
+# reason, if we set the COLLECT_NAMES environment variable, the problems
+# vanish in a puff of smoke.
+if test "X${COLLECT_NAMES+set}" != Xset; then
+  COLLECT_NAMES=
+  export COLLECT_NAMES
+fi
+_LT_EOF
+    ;;
+  esac
+
+  _LT_PROG_LTMAIN
+
+  # We use sed instead of cat because bash on DJGPP gets confused if
+  # if finds mixed CR/LF and LF-only lines.  Since sed operates in
+  # text mode, it properly converts lines to CR/LF.  This bash problem
+  # is reportedly fixed, but why not run on old versions too?
+  sed '$q' "$ltmain" >> "$cfgfile" \
+     || (rm -f "$cfgfile"; exit 1)
+
+  _LT_PROG_REPLACE_SHELLFNS
+
+   mv -f "$cfgfile" "$ofile" ||
+    (rm -f "$ofile" && cp "$cfgfile" "$ofile" && rm -f "$cfgfile")
+  chmod +x "$ofile"
+],
+[cat <<_LT_EOF >> "$ofile"
+
+dnl Unfortunately we have to use $1 here, since _LT_TAG is not expanded
+dnl in a comment (ie after a #).
+# ### BEGIN LIBTOOL TAG CONFIG: $1
+_LT_LIBTOOL_TAG_VARS(_LT_TAG)
+# ### END LIBTOOL TAG CONFIG: $1
+_LT_EOF
+])dnl /m4_if
+],
+[m4_if([$1], [], [
+    PACKAGE='$PACKAGE'
+    VERSION='$VERSION'
+    TIMESTAMP='$TIMESTAMP'
+    RM='$RM'
+    ofile='$ofile'], [])
+])dnl /_LT_CONFIG_SAVE_COMMANDS
+])# _LT_CONFIG
+
+
+# LT_SUPPORTED_TAG(TAG)
+# ---------------------
+# Trace this macro to discover what tags are supported by the libtool
+# --tag option, using:
+#    autoconf --trace 'LT_SUPPORTED_TAG:$1'
+AC_DEFUN([LT_SUPPORTED_TAG], [])
+
+
+# C support is built-in for now
+m4_define([_LT_LANG_C_enabled], [])
+m4_define([_LT_TAGS], [])
+
+
+# LT_LANG(LANG)
+# -------------
+# Enable libtool support for the given language if not already enabled.
+AC_DEFUN([LT_LANG],
+[AC_BEFORE([$0], [LT_OUTPUT])dnl
+m4_case([$1],
+  [C],			[_LT_LANG(C)],
+  [C++],		[_LT_LANG(CXX)],
+  [Go],			[_LT_LANG(GO)],
+  [Java],		[_LT_LANG(GCJ)],
+  [Fortran 77],		[_LT_LANG(F77)],
+  [Fortran],		[_LT_LANG(FC)],
+  [Windows Resource],	[_LT_LANG(RC)],
+  [m4_ifdef([_LT_LANG_]$1[_CONFIG],
+    [_LT_LANG($1)],
+    [m4_fatal([$0: unsupported language: "$1"])])])dnl
+])# LT_LANG
+
+
+# _LT_LANG(LANGNAME)
+# ------------------
+m4_defun([_LT_LANG],
+[m4_ifdef([_LT_LANG_]$1[_enabled], [],
+  [LT_SUPPORTED_TAG([$1])dnl
+  m4_append([_LT_TAGS], [$1 ])dnl
+  m4_define([_LT_LANG_]$1[_enabled], [])dnl
+  _LT_LANG_$1_CONFIG($1)])dnl
+])# _LT_LANG
+
+
+m4_ifndef([AC_PROG_GO], [
+# NOTE: This macro has been submitted for inclusion into   #
+#  GNU Autoconf as AC_PROG_GO.  When it is available in    #
+#  a released version of Autoconf we should remove this    #
+#  macro and use it instead.                               #
+m4_defun([AC_PROG_GO],
+[AC_LANG_PUSH(Go)dnl
+AC_ARG_VAR([GOC],     [Go compiler command])dnl
+AC_ARG_VAR([GOFLAGS], [Go compiler flags])dnl
+_AC_ARG_VAR_LDFLAGS()dnl
+AC_CHECK_TOOL(GOC, gccgo)
+if test -z "$GOC"; then
+  if test -n "$ac_tool_prefix"; then
+    AC_CHECK_PROG(GOC, [${ac_tool_prefix}gccgo], [${ac_tool_prefix}gccgo])
+  fi
+fi
+if test -z "$GOC"; then
+  AC_CHECK_PROG(GOC, gccgo, gccgo, false)
+fi
+])#m4_defun
+])#m4_ifndef
+
+
+# _LT_LANG_DEFAULT_CONFIG
+# -----------------------
+m4_defun([_LT_LANG_DEFAULT_CONFIG],
+[AC_PROVIDE_IFELSE([AC_PROG_CXX],
+  [LT_LANG(CXX)],
+  [m4_define([AC_PROG_CXX], defn([AC_PROG_CXX])[LT_LANG(CXX)])])
+
+AC_PROVIDE_IFELSE([AC_PROG_F77],
+  [LT_LANG(F77)],
+  [m4_define([AC_PROG_F77], defn([AC_PROG_F77])[LT_LANG(F77)])])
+
+AC_PROVIDE_IFELSE([AC_PROG_FC],
+  [LT_LANG(FC)],
+  [m4_define([AC_PROG_FC], defn([AC_PROG_FC])[LT_LANG(FC)])])
+
+dnl The call to [A][M_PROG_GCJ] is quoted like that to stop aclocal
+dnl pulling things in needlessly.
+AC_PROVIDE_IFELSE([AC_PROG_GCJ],
+  [LT_LANG(GCJ)],
+  [AC_PROVIDE_IFELSE([A][M_PROG_GCJ],
+    [LT_LANG(GCJ)],
+    [AC_PROVIDE_IFELSE([LT_PROG_GCJ],
+      [LT_LANG(GCJ)],
+      [m4_ifdef([AC_PROG_GCJ],
+	[m4_define([AC_PROG_GCJ], defn([AC_PROG_GCJ])[LT_LANG(GCJ)])])
+       m4_ifdef([A][M_PROG_GCJ],
+	[m4_define([A][M_PROG_GCJ], defn([A][M_PROG_GCJ])[LT_LANG(GCJ)])])
+       m4_ifdef([LT_PROG_GCJ],
+	[m4_define([LT_PROG_GCJ], defn([LT_PROG_GCJ])[LT_LANG(GCJ)])])])])])
+
+AC_PROVIDE_IFELSE([AC_PROG_GO],
+  [LT_LANG(GO)],
+  [m4_define([AC_PROG_GO], defn([AC_PROG_GO])[LT_LANG(GO)])])
+
+AC_PROVIDE_IFELSE([LT_PROG_RC],
+  [LT_LANG(RC)],
+  [m4_define([LT_PROG_RC], defn([LT_PROG_RC])[LT_LANG(RC)])])
+])# _LT_LANG_DEFAULT_CONFIG
+
+# Obsolete macros:
+AU_DEFUN([AC_LIBTOOL_CXX], [LT_LANG(C++)])
+AU_DEFUN([AC_LIBTOOL_F77], [LT_LANG(Fortran 77)])
+AU_DEFUN([AC_LIBTOOL_FC], [LT_LANG(Fortran)])
+AU_DEFUN([AC_LIBTOOL_GCJ], [LT_LANG(Java)])
+AU_DEFUN([AC_LIBTOOL_RC], [LT_LANG(Windows Resource)])
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AC_LIBTOOL_CXX], [])
+dnl AC_DEFUN([AC_LIBTOOL_F77], [])
+dnl AC_DEFUN([AC_LIBTOOL_FC], [])
+dnl AC_DEFUN([AC_LIBTOOL_GCJ], [])
+dnl AC_DEFUN([AC_LIBTOOL_RC], [])
+
+
+# _LT_TAG_COMPILER
+# ----------------
+m4_defun([_LT_TAG_COMPILER],
+[AC_REQUIRE([AC_PROG_CC])dnl
+
+_LT_DECL([LTCC], [CC], [1], [A C compiler])dnl
+_LT_DECL([LTCFLAGS], [CFLAGS], [1], [LTCC compiler flags])dnl
+_LT_TAGDECL([CC], [compiler], [1], [A language specific compiler])dnl
+_LT_TAGDECL([with_gcc], [GCC], [0], [Is the compiler the GNU compiler?])dnl
+
+# If no C compiler was specified, use CC.
+LTCC=${LTCC-"$CC"}
+
+# If no C compiler flags were specified, use CFLAGS.
+LTCFLAGS=${LTCFLAGS-"$CFLAGS"}
+
+# Allow CC to be a program name with arguments.
+compiler=$CC
+])# _LT_TAG_COMPILER
+
+
+# _LT_COMPILER_BOILERPLATE
+# ------------------------
+# Check for compiler boilerplate output or warnings with
+# the simple compiler test code.
+m4_defun([_LT_COMPILER_BOILERPLATE],
+[m4_require([_LT_DECL_SED])dnl
+ac_outfile=conftest.$ac_objext
+echo "$lt_simple_compile_test_code" >conftest.$ac_ext
+eval "$ac_compile" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err
+_lt_compiler_boilerplate=`cat conftest.err`
+$RM conftest*
+])# _LT_COMPILER_BOILERPLATE
+
+
+# _LT_LINKER_BOILERPLATE
+# ----------------------
+# Check for linker boilerplate output or warnings with
+# the simple link test code.
+m4_defun([_LT_LINKER_BOILERPLATE],
+[m4_require([_LT_DECL_SED])dnl
+ac_outfile=conftest.$ac_objext
+echo "$lt_simple_link_test_code" >conftest.$ac_ext
+eval "$ac_link" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err
+_lt_linker_boilerplate=`cat conftest.err`
+$RM -r conftest*
+])# _LT_LINKER_BOILERPLATE
+
+# _LT_REQUIRED_DARWIN_CHECKS
+# -------------------------
+m4_defun_once([_LT_REQUIRED_DARWIN_CHECKS],[
+  case $host_os in
+    rhapsody* | darwin*)
+    AC_CHECK_TOOL([DSYMUTIL], [dsymutil], [:])
+    AC_CHECK_TOOL([NMEDIT], [nmedit], [:])
+    AC_CHECK_TOOL([LIPO], [lipo], [:])
+    AC_CHECK_TOOL([OTOOL], [otool], [:])
+    AC_CHECK_TOOL([OTOOL64], [otool64], [:])
+    _LT_DECL([], [DSYMUTIL], [1],
+      [Tool to manipulate archived DWARF debug symbol files on Mac OS X])
+    _LT_DECL([], [NMEDIT], [1],
+      [Tool to change global to local symbols on Mac OS X])
+    _LT_DECL([], [LIPO], [1],
+      [Tool to manipulate fat objects and archives on Mac OS X])
+    _LT_DECL([], [OTOOL], [1],
+      [ldd/readelf like tool for Mach-O binaries on Mac OS X])
+    _LT_DECL([], [OTOOL64], [1],
+      [ldd/readelf like tool for 64 bit Mach-O binaries on Mac OS X 10.4])
+
+    AC_CACHE_CHECK([for -single_module linker flag],[lt_cv_apple_cc_single_mod],
+      [lt_cv_apple_cc_single_mod=no
+      if test -z "${LT_MULTI_MODULE}"; then
+	# By default we will add the -single_module flag. You can override
+	# by either setting the environment variable LT_MULTI_MODULE
+	# non-empty at configure time, or by adding -multi_module to the
+	# link flags.
+	rm -rf libconftest.dylib*
+	echo "int foo(void){return 1;}" > conftest.c
+	echo "$LTCC $LTCFLAGS $LDFLAGS -o libconftest.dylib \
+-dynamiclib -Wl,-single_module conftest.c" >&AS_MESSAGE_LOG_FD
+	$LTCC $LTCFLAGS $LDFLAGS -o libconftest.dylib \
+	  -dynamiclib -Wl,-single_module conftest.c 2>conftest.err
+        _lt_result=$?
+	# If there is a non-empty error log, and "single_module"
+	# appears in it, assume the flag caused a linker warning
+        if test -s conftest.err && $GREP single_module conftest.err; then
+	  cat conftest.err >&AS_MESSAGE_LOG_FD
+	# Otherwise, if the output was created with a 0 exit code from
+	# the compiler, it worked.
+	elif test -f libconftest.dylib && test $_lt_result -eq 0; then
+	  lt_cv_apple_cc_single_mod=yes
+	else
+	  cat conftest.err >&AS_MESSAGE_LOG_FD
+	fi
+	rm -rf libconftest.dylib*
+	rm -f conftest.*
+      fi])
+
+    AC_CACHE_CHECK([for -exported_symbols_list linker flag],
+      [lt_cv_ld_exported_symbols_list],
+      [lt_cv_ld_exported_symbols_list=no
+      save_LDFLAGS=$LDFLAGS
+      echo "_main" > conftest.sym
+      LDFLAGS="$LDFLAGS -Wl,-exported_symbols_list,conftest.sym"
+      AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])],
+	[lt_cv_ld_exported_symbols_list=yes],
+	[lt_cv_ld_exported_symbols_list=no])
+	LDFLAGS="$save_LDFLAGS"
+    ])
+
+    AC_CACHE_CHECK([for -force_load linker flag],[lt_cv_ld_force_load],
+      [lt_cv_ld_force_load=no
+      cat > conftest.c << _LT_EOF
+int forced_loaded() { return 2;}
+_LT_EOF
+      echo "$LTCC $LTCFLAGS -c -o conftest.o conftest.c" >&AS_MESSAGE_LOG_FD
+      $LTCC $LTCFLAGS -c -o conftest.o conftest.c 2>&AS_MESSAGE_LOG_FD
+      echo "$AR cru libconftest.a conftest.o" >&AS_MESSAGE_LOG_FD
+      $AR cru libconftest.a conftest.o 2>&AS_MESSAGE_LOG_FD
+      echo "$RANLIB libconftest.a" >&AS_MESSAGE_LOG_FD
+      $RANLIB libconftest.a 2>&AS_MESSAGE_LOG_FD
+      cat > conftest.c << _LT_EOF
+int main() { return 0;}
+_LT_EOF
+      echo "$LTCC $LTCFLAGS $LDFLAGS -o conftest conftest.c -Wl,-force_load,./libconftest.a" >&AS_MESSAGE_LOG_FD
+      $LTCC $LTCFLAGS $LDFLAGS -o conftest conftest.c -Wl,-force_load,./libconftest.a 2>conftest.err
+      _lt_result=$?
+      if test -s conftest.err && $GREP force_load conftest.err; then
+	cat conftest.err >&AS_MESSAGE_LOG_FD
+      elif test -f conftest && test $_lt_result -eq 0 && $GREP forced_load conftest >/dev/null 2>&1 ; then
+	lt_cv_ld_force_load=yes
+      else
+	cat conftest.err >&AS_MESSAGE_LOG_FD
+      fi
+        rm -f conftest.err libconftest.a conftest conftest.c
+        rm -rf conftest.dSYM
+    ])
+    case $host_os in
+    rhapsody* | darwin1.[[012]])
+      _lt_dar_allow_undefined='${wl}-undefined ${wl}suppress' ;;
+    darwin1.*)
+      _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' ;;
+    darwin*) # darwin 5.x on
+      # if running on 10.5 or later, the deployment target defaults
+      # to the OS version, if on x86, and 10.4, the deployment
+      # target defaults to 10.4. Don't you love it?
+      case ${MACOSX_DEPLOYMENT_TARGET-10.0},$host in
+	10.0,*86*-darwin8*|10.0,*-darwin[[91]]*)
+	  _lt_dar_allow_undefined='${wl}-undefined ${wl}dynamic_lookup' ;;
+	10.[[012]]*)
+	  _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' ;;
+	10.*)
+	  _lt_dar_allow_undefined='${wl}-undefined ${wl}dynamic_lookup' ;;
+      esac
+    ;;
+  esac
+    if test "$lt_cv_apple_cc_single_mod" = "yes"; then
+      _lt_dar_single_mod='$single_module'
+    fi
+    if test "$lt_cv_ld_exported_symbols_list" = "yes"; then
+      _lt_dar_export_syms=' ${wl}-exported_symbols_list,$output_objdir/${libname}-symbols.expsym'
+    else
+      _lt_dar_export_syms='~$NMEDIT -s $output_objdir/${libname}-symbols.expsym ${lib}'
+    fi
+    if test "$DSYMUTIL" != ":" && test "$lt_cv_ld_force_load" = "no"; then
+      _lt_dsymutil='~$DSYMUTIL $lib || :'
+    else
+      _lt_dsymutil=
+    fi
+    ;;
+  esac
+])
+
+
+# _LT_DARWIN_LINKER_FEATURES([TAG])
+# ---------------------------------
+# Checks for linker and compiler features on darwin
+m4_defun([_LT_DARWIN_LINKER_FEATURES],
+[
+  m4_require([_LT_REQUIRED_DARWIN_CHECKS])
+  _LT_TAGVAR(archive_cmds_need_lc, $1)=no
+  _LT_TAGVAR(hardcode_direct, $1)=no
+  _LT_TAGVAR(hardcode_automatic, $1)=yes
+  _LT_TAGVAR(hardcode_shlibpath_var, $1)=unsupported
+  if test "$lt_cv_ld_force_load" = "yes"; then
+    _LT_TAGVAR(whole_archive_flag_spec, $1)='`for conv in $convenience\"\"; do test  -n \"$conv\" && new_convenience=\"$new_convenience ${wl}-force_load,$conv\"; done; func_echo_all \"$new_convenience\"`'
+    m4_case([$1], [F77], [_LT_TAGVAR(compiler_needs_object, $1)=yes],
+                  [FC],  [_LT_TAGVAR(compiler_needs_object, $1)=yes])
+  else
+    _LT_TAGVAR(whole_archive_flag_spec, $1)=''
+  fi
+  _LT_TAGVAR(link_all_deplibs, $1)=yes
+  _LT_TAGVAR(allow_undefined_flag, $1)="$_lt_dar_allow_undefined"
+  case $cc_basename in
+     ifort*) _lt_dar_can_shared=yes ;;
+     *) _lt_dar_can_shared=$GCC ;;
+  esac
+  if test "$_lt_dar_can_shared" = "yes"; then
+    output_verbose_link_cmd=func_echo_all
+    _LT_TAGVAR(archive_cmds, $1)="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}"
+    _LT_TAGVAR(module_cmds, $1)="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}"
+    _LT_TAGVAR(archive_expsym_cmds, $1)="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}"
+    _LT_TAGVAR(module_expsym_cmds, $1)="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}"
+    m4_if([$1], [CXX],
+[   if test "$lt_cv_apple_cc_single_mod" != "yes"; then
+      _LT_TAGVAR(archive_cmds, $1)="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dsymutil}"
+      _LT_TAGVAR(archive_expsym_cmds, $1)="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dar_export_syms}${_lt_dsymutil}"
+    fi
+],[])
+  else
+  _LT_TAGVAR(ld_shlibs, $1)=no
+  fi
+])
+
+# _LT_SYS_MODULE_PATH_AIX([TAGNAME])
+# ----------------------------------
+# Links a minimal program and checks the executable
+# for the system default hardcoded library path. In most cases,
+# this is /usr/lib:/lib, but when the MPI compilers are used
+# the location of the communication and MPI libs are included too.
+# If we don't find anything, use the default library path according
+# to the aix ld manual.
+# Store the results from the different compilers for each TAGNAME.
+# Allow to override them for all tags through lt_cv_aix_libpath.
+m4_defun([_LT_SYS_MODULE_PATH_AIX],
+[m4_require([_LT_DECL_SED])dnl
+if test "${lt_cv_aix_libpath+set}" = set; then
+  aix_libpath=$lt_cv_aix_libpath
+else
+  AC_CACHE_VAL([_LT_TAGVAR([lt_cv_aix_libpath_], [$1])],
+  [AC_LINK_IFELSE([AC_LANG_PROGRAM],[
+  lt_aix_libpath_sed='[
+      /Import File Strings/,/^$/ {
+	  /^0/ {
+	      s/^0  *\([^ ]*\) *$/\1/
+	      p
+	  }
+      }]'
+  _LT_TAGVAR([lt_cv_aix_libpath_], [$1])=`dump -H conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"`
+  # Check for a 64-bit object if we didn't find anything.
+  if test -z "$_LT_TAGVAR([lt_cv_aix_libpath_], [$1])"; then
+    _LT_TAGVAR([lt_cv_aix_libpath_], [$1])=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"`
+  fi],[])
+  if test -z "$_LT_TAGVAR([lt_cv_aix_libpath_], [$1])"; then
+    _LT_TAGVAR([lt_cv_aix_libpath_], [$1])="/usr/lib:/lib"
+  fi
+  ])
+  aix_libpath=$_LT_TAGVAR([lt_cv_aix_libpath_], [$1])
+fi
+])# _LT_SYS_MODULE_PATH_AIX
+
+
+# _LT_SHELL_INIT(ARG)
+# -------------------
+m4_define([_LT_SHELL_INIT],
+[m4_divert_text([M4SH-INIT], [$1
+])])# _LT_SHELL_INIT
+
+
+
+# _LT_PROG_ECHO_BACKSLASH
+# -----------------------
+# Find how we can fake an echo command that does not interpret backslash.
+# In particular, with Autoconf 2.60 or later we add some code to the start
+# of the generated configure script which will find a shell with a builtin
+# printf (which we can use as an echo command).
+m4_defun([_LT_PROG_ECHO_BACKSLASH],
+[ECHO='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'
+ECHO=$ECHO$ECHO$ECHO$ECHO$ECHO
+ECHO=$ECHO$ECHO$ECHO$ECHO$ECHO$ECHO
+
+AC_MSG_CHECKING([how to print strings])
+# Test print first, because it will be a builtin if present.
+if test "X`( print -r -- -n ) 2>/dev/null`" = X-n && \
+   test "X`print -r -- $ECHO 2>/dev/null`" = "X$ECHO"; then
+  ECHO='print -r --'
+elif test "X`printf %s $ECHO 2>/dev/null`" = "X$ECHO"; then
+  ECHO='printf %s\n'
+else
+  # Use this function as a fallback that always works.
+  func_fallback_echo ()
+  {
+    eval 'cat <<_LTECHO_EOF
+$[]1
+_LTECHO_EOF'
+  }
+  ECHO='func_fallback_echo'
+fi
+
+# func_echo_all arg...
+# Invoke $ECHO with all args, space-separated.
+func_echo_all ()
+{
+    $ECHO "$*" 
+}
+
+case "$ECHO" in
+  printf*) AC_MSG_RESULT([printf]) ;;
+  print*) AC_MSG_RESULT([print -r]) ;;
+  *) AC_MSG_RESULT([cat]) ;;
+esac
+
+m4_ifdef([_AS_DETECT_SUGGESTED],
+[_AS_DETECT_SUGGESTED([
+  test -n "${ZSH_VERSION+set}${BASH_VERSION+set}" || (
+    ECHO='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'
+    ECHO=$ECHO$ECHO$ECHO$ECHO$ECHO
+    ECHO=$ECHO$ECHO$ECHO$ECHO$ECHO$ECHO
+    PATH=/empty FPATH=/empty; export PATH FPATH
+    test "X`printf %s $ECHO`" = "X$ECHO" \
+      || test "X`print -r -- $ECHO`" = "X$ECHO" )])])
+
+_LT_DECL([], [SHELL], [1], [Shell to use when invoking shell scripts])
+_LT_DECL([], [ECHO], [1], [An echo program that protects backslashes])
+])# _LT_PROG_ECHO_BACKSLASH
+
+
+# _LT_WITH_SYSROOT
+# ----------------
+AC_DEFUN([_LT_WITH_SYSROOT],
+[AC_MSG_CHECKING([for sysroot])
+AC_ARG_WITH([sysroot],
+[  --with-sysroot[=DIR] Search for dependent libraries within DIR
+                        (or the compiler's sysroot if not specified).],
+[], [with_sysroot=no])
+
+dnl lt_sysroot will always be passed unquoted.  We quote it here
+dnl in case the user passed a directory name.
+lt_sysroot=
+case ${with_sysroot} in #(
+ yes)
+   if test "$GCC" = yes; then
+     lt_sysroot=`$CC --print-sysroot 2>/dev/null`
+   fi
+   ;; #(
+ /*)
+   lt_sysroot=`echo "$with_sysroot" | sed -e "$sed_quote_subst"`
+   ;; #(
+ no|'')
+   ;; #(
+ *)
+   AC_MSG_RESULT([${with_sysroot}])
+   AC_MSG_ERROR([The sysroot must be an absolute path.])
+   ;;
+esac
+
+ AC_MSG_RESULT([${lt_sysroot:-no}])
+_LT_DECL([], [lt_sysroot], [0], [The root where to search for ]dnl
+[dependent libraries, and in which our libraries should be installed.])])
+
+# _LT_ENABLE_LOCK
+# ---------------
+m4_defun([_LT_ENABLE_LOCK],
+[AC_ARG_ENABLE([libtool-lock],
+  [AS_HELP_STRING([--disable-libtool-lock],
+    [avoid locking (might break parallel builds)])])
+test "x$enable_libtool_lock" != xno && enable_libtool_lock=yes
+
+# Some flags need to be propagated to the compiler or linker for good
+# libtool support.
+case $host in
+ia64-*-hpux*)
+  # Find out which ABI we are using.
+  echo 'int i;' > conftest.$ac_ext
+  if AC_TRY_EVAL(ac_compile); then
+    case `/usr/bin/file conftest.$ac_objext` in
+      *ELF-32*)
+	HPUX_IA64_MODE="32"
+	;;
+      *ELF-64*)
+	HPUX_IA64_MODE="64"
+	;;
+    esac
+  fi
+  rm -rf conftest*
+  ;;
+*-*-irix6*)
+  # Find out which ABI we are using.
+  echo '[#]line '$LINENO' "configure"' > conftest.$ac_ext
+  if AC_TRY_EVAL(ac_compile); then
+    if test "$lt_cv_prog_gnu_ld" = yes; then
+      case `/usr/bin/file conftest.$ac_objext` in
+	*32-bit*)
+	  LD="${LD-ld} -melf32bsmip"
+	  ;;
+	*N32*)
+	  LD="${LD-ld} -melf32bmipn32"
+	  ;;
+	*64-bit*)
+	  LD="${LD-ld} -melf64bmip"
+	;;
+      esac
+    else
+      case `/usr/bin/file conftest.$ac_objext` in
+	*32-bit*)
+	  LD="${LD-ld} -32"
+	  ;;
+	*N32*)
+	  LD="${LD-ld} -n32"
+	  ;;
+	*64-bit*)
+	  LD="${LD-ld} -64"
+	  ;;
+      esac
+    fi
+  fi
+  rm -rf conftest*
+  ;;
+
+x86_64-*kfreebsd*-gnu|x86_64-*linux*|powerpc*-*linux*| \
+s390*-*linux*|s390*-*tpf*|sparc*-*linux*)
+  # Find out which ABI we are using.
+  echo 'int i;' > conftest.$ac_ext
+  if AC_TRY_EVAL(ac_compile); then
+    case `/usr/bin/file conftest.o` in
+      *32-bit*)
+	case $host in
+	  x86_64-*kfreebsd*-gnu)
+	    LD="${LD-ld} -m elf_i386_fbsd"
+	    ;;
+	  x86_64-*linux*)
+	    case `/usr/bin/file conftest.o` in
+	      *x86-64*)
+		LD="${LD-ld} -m elf32_x86_64"
+		;;
+	      *)
+		LD="${LD-ld} -m elf_i386"
+		;;
+	    esac
+	    ;;
+	  powerpc64le-*)
+	    LD="${LD-ld} -m elf32lppclinux"
+	    ;;
+	  powerpc64-*)
+	    LD="${LD-ld} -m elf32ppclinux"
+	    ;;
+	  s390x-*linux*)
+	    LD="${LD-ld} -m elf_s390"
+	    ;;
+	  sparc64-*linux*)
+	    LD="${LD-ld} -m elf32_sparc"
+	    ;;
+	esac
+	;;
+      *64-bit*)
+	case $host in
+	  x86_64-*kfreebsd*-gnu)
+	    LD="${LD-ld} -m elf_x86_64_fbsd"
+	    ;;
+	  x86_64-*linux*)
+	    LD="${LD-ld} -m elf_x86_64"
+	    ;;
+	  powerpcle-*)
+	    LD="${LD-ld} -m elf64lppc"
+	    ;;
+	  powerpc-*)
+	    LD="${LD-ld} -m elf64ppc"
+	    ;;
+	  s390*-*linux*|s390*-*tpf*)
+	    LD="${LD-ld} -m elf64_s390"
+	    ;;
+	  sparc*-*linux*)
+	    LD="${LD-ld} -m elf64_sparc"
+	    ;;
+	esac
+	;;
+    esac
+  fi
+  rm -rf conftest*
+  ;;
+
+*-*-sco3.2v5*)
+  # On SCO OpenServer 5, we need -belf to get full-featured binaries.
+  SAVE_CFLAGS="$CFLAGS"
+  CFLAGS="$CFLAGS -belf"
+  AC_CACHE_CHECK([whether the C compiler needs -belf], lt_cv_cc_needs_belf,
+    [AC_LANG_PUSH(C)
+     AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],[[]])],[lt_cv_cc_needs_belf=yes],[lt_cv_cc_needs_belf=no])
+     AC_LANG_POP])
+  if test x"$lt_cv_cc_needs_belf" != x"yes"; then
+    # this is probably gcc 2.8.0, egcs 1.0 or newer; no need for -belf
+    CFLAGS="$SAVE_CFLAGS"
+  fi
+  ;;
+*-*solaris*)
+  # Find out which ABI we are using.
+  echo 'int i;' > conftest.$ac_ext
+  if AC_TRY_EVAL(ac_compile); then
+    case `/usr/bin/file conftest.o` in
+    *64-bit*)
+      case $lt_cv_prog_gnu_ld in
+      yes*)
+        case $host in
+        i?86-*-solaris*)
+          LD="${LD-ld} -m elf_x86_64"
+          ;;
+        sparc*-*-solaris*)
+          LD="${LD-ld} -m elf64_sparc"
+          ;;
+        esac
+        # GNU ld 2.21 introduced _sol2 emulations.  Use them if available.
+        if ${LD-ld} -V | grep _sol2 >/dev/null 2>&1; then
+          LD="${LD-ld}_sol2"
+        fi
+        ;;
+      *)
+	if ${LD-ld} -64 -r -o conftest2.o conftest.o >/dev/null 2>&1; then
+	  LD="${LD-ld} -64"
+	fi
+	;;
+      esac
+      ;;
+    esac
+  fi
+  rm -rf conftest*
+  ;;
+esac
+
+need_locks="$enable_libtool_lock"
+])# _LT_ENABLE_LOCK
+
+
+# _LT_PROG_AR
+# -----------
+m4_defun([_LT_PROG_AR],
+[AC_CHECK_TOOLS(AR, [ar], false)
+: ${AR=ar}
+: ${AR_FLAGS=cru}
+_LT_DECL([], [AR], [1], [The archiver])
+_LT_DECL([], [AR_FLAGS], [1], [Flags to create an archive])
+
+AC_CACHE_CHECK([for archiver @FILE support], [lt_cv_ar_at_file],
+  [lt_cv_ar_at_file=no
+   AC_COMPILE_IFELSE([AC_LANG_PROGRAM],
+     [echo conftest.$ac_objext > conftest.lst
+      lt_ar_try='$AR $AR_FLAGS libconftest.a @conftest.lst >&AS_MESSAGE_LOG_FD'
+      AC_TRY_EVAL([lt_ar_try])
+      if test "$ac_status" -eq 0; then
+	# Ensure the archiver fails upon bogus file names.
+	rm -f conftest.$ac_objext libconftest.a
+	AC_TRY_EVAL([lt_ar_try])
+	if test "$ac_status" -ne 0; then
+          lt_cv_ar_at_file=@
+        fi
+      fi
+      rm -f conftest.* libconftest.a
+     ])
+  ])
+
+if test "x$lt_cv_ar_at_file" = xno; then
+  archiver_list_spec=
+else
+  archiver_list_spec=$lt_cv_ar_at_file
+fi
+_LT_DECL([], [archiver_list_spec], [1],
+  [How to feed a file listing to the archiver])
+])# _LT_PROG_AR
+
+
+# _LT_CMD_OLD_ARCHIVE
+# -------------------
+m4_defun([_LT_CMD_OLD_ARCHIVE],
+[_LT_PROG_AR
+
+AC_CHECK_TOOL(STRIP, strip, :)
+test -z "$STRIP" && STRIP=:
+_LT_DECL([], [STRIP], [1], [A symbol stripping program])
+
+AC_CHECK_TOOL(RANLIB, ranlib, :)
+test -z "$RANLIB" && RANLIB=:
+_LT_DECL([], [RANLIB], [1],
+    [Commands used to install an old-style archive])
+
+# Determine commands to create old-style static archives.
+old_archive_cmds='$AR $AR_FLAGS $oldlib$oldobjs'
+old_postinstall_cmds='chmod 644 $oldlib'
+old_postuninstall_cmds=
+
+if test -n "$RANLIB"; then
+  case $host_os in
+  openbsd*)
+    old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB -t \$tool_oldlib"
+    ;;
+  *)
+    old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB \$tool_oldlib"
+    ;;
+  esac
+  old_archive_cmds="$old_archive_cmds~\$RANLIB \$tool_oldlib"
+fi
+
+case $host_os in
+  darwin*)
+    lock_old_archive_extraction=yes ;;
+  *)
+    lock_old_archive_extraction=no ;;
+esac
+_LT_DECL([], [old_postinstall_cmds], [2])
+_LT_DECL([], [old_postuninstall_cmds], [2])
+_LT_TAGDECL([], [old_archive_cmds], [2],
+    [Commands used to build an old-style archive])
+_LT_DECL([], [lock_old_archive_extraction], [0],
+    [Whether to use a lock for old archive extraction])
+])# _LT_CMD_OLD_ARCHIVE
+
+
+# _LT_COMPILER_OPTION(MESSAGE, VARIABLE-NAME, FLAGS,
+#		[OUTPUT-FILE], [ACTION-SUCCESS], [ACTION-FAILURE])
+# ----------------------------------------------------------------
+# Check whether the given compiler option works
+AC_DEFUN([_LT_COMPILER_OPTION],
+[m4_require([_LT_FILEUTILS_DEFAULTS])dnl
+m4_require([_LT_DECL_SED])dnl
+AC_CACHE_CHECK([$1], [$2],
+  [$2=no
+   m4_if([$4], , [ac_outfile=conftest.$ac_objext], [ac_outfile=$4])
+   echo "$lt_simple_compile_test_code" > conftest.$ac_ext
+   lt_compiler_flag="$3"
+   # Insert the option either (1) after the last *FLAGS variable, or
+   # (2) before a word containing "conftest.", or (3) at the end.
+   # Note that $ac_compile itself does not contain backslashes and begins
+   # with a dollar sign (not a hyphen), so the echo should work correctly.
+   # The option is referenced via a variable to avoid confusing sed.
+   lt_compile=`echo "$ac_compile" | $SED \
+   -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
+   -e 's: [[^ ]]*conftest\.: $lt_compiler_flag&:; t' \
+   -e 's:$: $lt_compiler_flag:'`
+   (eval echo "\"\$as_me:$LINENO: $lt_compile\"" >&AS_MESSAGE_LOG_FD)
+   (eval "$lt_compile" 2>conftest.err)
+   ac_status=$?
+   cat conftest.err >&AS_MESSAGE_LOG_FD
+   echo "$as_me:$LINENO: \$? = $ac_status" >&AS_MESSAGE_LOG_FD
+   if (exit $ac_status) && test -s "$ac_outfile"; then
+     # The compiler can only warn and ignore the option if not recognized
+     # So say no if there are warnings other than the usual output.
+     $ECHO "$_lt_compiler_boilerplate" | $SED '/^$/d' >conftest.exp
+     $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2
+     if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; then
+       $2=yes
+     fi
+   fi
+   $RM conftest*
+])
+
+if test x"[$]$2" = xyes; then
+    m4_if([$5], , :, [$5])
+else
+    m4_if([$6], , :, [$6])
+fi
+])# _LT_COMPILER_OPTION
+
+# Old name:
+AU_ALIAS([AC_LIBTOOL_COMPILER_OPTION], [_LT_COMPILER_OPTION])
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AC_LIBTOOL_COMPILER_OPTION], [])
+
+
+# _LT_LINKER_OPTION(MESSAGE, VARIABLE-NAME, FLAGS,
+#                  [ACTION-SUCCESS], [ACTION-FAILURE])
+# ----------------------------------------------------
+# Check whether the given linker option works
+AC_DEFUN([_LT_LINKER_OPTION],
+[m4_require([_LT_FILEUTILS_DEFAULTS])dnl
+m4_require([_LT_DECL_SED])dnl
+AC_CACHE_CHECK([$1], [$2],
+  [$2=no
+   save_LDFLAGS="$LDFLAGS"
+   LDFLAGS="$LDFLAGS $3"
+   echo "$lt_simple_link_test_code" > conftest.$ac_ext
+   if (eval $ac_link 2>conftest.err) && test -s conftest$ac_exeext; then
+     # The linker can only warn and ignore the option if not recognized
+     # So say no if there are warnings
+     if test -s conftest.err; then
+       # Append any errors to the config.log.
+       cat conftest.err 1>&AS_MESSAGE_LOG_FD
+       $ECHO "$_lt_linker_boilerplate" | $SED '/^$/d' > conftest.exp
+       $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2
+       if diff conftest.exp conftest.er2 >/dev/null; then
+         $2=yes
+       fi
+     else
+       $2=yes
+     fi
+   fi
+   $RM -r conftest*
+   LDFLAGS="$save_LDFLAGS"
+])
+
+if test x"[$]$2" = xyes; then
+    m4_if([$4], , :, [$4])
+else
+    m4_if([$5], , :, [$5])
+fi
+])# _LT_LINKER_OPTION
+
+# Old name:
+AU_ALIAS([AC_LIBTOOL_LINKER_OPTION], [_LT_LINKER_OPTION])
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AC_LIBTOOL_LINKER_OPTION], [])
+
+
+# LT_CMD_MAX_LEN
+#---------------
+AC_DEFUN([LT_CMD_MAX_LEN],
+[AC_REQUIRE([AC_CANONICAL_HOST])dnl
+# find the maximum length of command line arguments
+AC_MSG_CHECKING([the maximum length of command line arguments])
+AC_CACHE_VAL([lt_cv_sys_max_cmd_len], [dnl
+  i=0
+  teststring="ABCD"
+
+  case $build_os in
+  msdosdjgpp*)
+    # On DJGPP, this test can blow up pretty badly due to problems in libc
+    # (any single argument exceeding 2000 bytes causes a buffer overrun
+    # during glob expansion).  Even if it were fixed, the result of this
+    # check would be larger than it should be.
+    lt_cv_sys_max_cmd_len=12288;    # 12K is about right
+    ;;
+
+  gnu*)
+    # Under GNU Hurd, this test is not required because there is
+    # no limit to the length of command line arguments.
+    # Libtool will interpret -1 as no limit whatsoever
+    lt_cv_sys_max_cmd_len=-1;
+    ;;
+
+  cygwin* | mingw* | cegcc*)
+    # On Win9x/ME, this test blows up -- it succeeds, but takes
+    # about 5 minutes as the teststring grows exponentially.
+    # Worse, since 9x/ME are not pre-emptively multitasking,
+    # you end up with a "frozen" computer, even though with patience
+    # the test eventually succeeds (with a max line length of 256k).
+    # Instead, let's just punt: use the minimum linelength reported by
+    # all of the supported platforms: 8192 (on NT/2K/XP).
+    lt_cv_sys_max_cmd_len=8192;
+    ;;
+
+  mint*)
+    # On MiNT this can take a long time and run out of memory.
+    lt_cv_sys_max_cmd_len=8192;
+    ;;
+
+  amigaos*)
+    # On AmigaOS with pdksh, this test takes hours, literally.
+    # So we just punt and use a minimum line length of 8192.
+    lt_cv_sys_max_cmd_len=8192;
+    ;;
+
+  netbsd* | freebsd* | openbsd* | darwin* | dragonfly*)
+    # This has been around since 386BSD, at least.  Likely further.
+    if test -x /sbin/sysctl; then
+      lt_cv_sys_max_cmd_len=`/sbin/sysctl -n kern.argmax`
+    elif test -x /usr/sbin/sysctl; then
+      lt_cv_sys_max_cmd_len=`/usr/sbin/sysctl -n kern.argmax`
+    else
+      lt_cv_sys_max_cmd_len=65536	# usable default for all BSDs
+    fi
+    # And add a safety zone
+    lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4`
+    lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3`
+    ;;
+
+  interix*)
+    # We know the value 262144 and hardcode it with a safety zone (like BSD)
+    lt_cv_sys_max_cmd_len=196608
+    ;;
+
+  os2*)
+    # The test takes a long time on OS/2.
+    lt_cv_sys_max_cmd_len=8192
+    ;;
+
+  osf*)
+    # Dr. Hans Ekkehard Plesser reports seeing a kernel panic running configure
+    # due to this test when exec_disable_arg_limit is 1 on Tru64. It is not
+    # nice to cause kernel panics so lets avoid the loop below.
+    # First set a reasonable default.
+    lt_cv_sys_max_cmd_len=16384
+    #
+    if test -x /sbin/sysconfig; then
+      case `/sbin/sysconfig -q proc exec_disable_arg_limit` in
+        *1*) lt_cv_sys_max_cmd_len=-1 ;;
+      esac
+    fi
+    ;;
+  sco3.2v5*)
+    lt_cv_sys_max_cmd_len=102400
+    ;;
+  sysv5* | sco5v6* | sysv4.2uw2*)
+    kargmax=`grep ARG_MAX /etc/conf/cf.d/stune 2>/dev/null`
+    if test -n "$kargmax"; then
+      lt_cv_sys_max_cmd_len=`echo $kargmax | sed 's/.*[[	 ]]//'`
+    else
+      lt_cv_sys_max_cmd_len=32768
+    fi
+    ;;
+  *)
+    lt_cv_sys_max_cmd_len=`(getconf ARG_MAX) 2> /dev/null`
+    if test -n "$lt_cv_sys_max_cmd_len" && \
+	test undefined != "$lt_cv_sys_max_cmd_len"; then
+      lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4`
+      lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3`
+    else
+      # Make teststring a little bigger before we do anything with it.
+      # a 1K string should be a reasonable start.
+      for i in 1 2 3 4 5 6 7 8 ; do
+        teststring=$teststring$teststring
+      done
+      SHELL=${SHELL-${CONFIG_SHELL-/bin/sh}}
+      # If test is not a shell built-in, we'll probably end up computing a
+      # maximum length that is only half of the actual maximum length, but
+      # we can't tell.
+      while { test "X"`env echo "$teststring$teststring" 2>/dev/null` \
+	         = "X$teststring$teststring"; } >/dev/null 2>&1 &&
+	      test $i != 17 # 1/2 MB should be enough
+      do
+        i=`expr $i + 1`
+        teststring=$teststring$teststring
+      done
+      # Only check the string length outside the loop.
+      lt_cv_sys_max_cmd_len=`expr "X$teststring" : ".*" 2>&1`
+      teststring=
+      # Add a significant safety factor because C++ compilers can tack on
+      # massive amounts of additional arguments before passing them to the
+      # linker.  It appears as though 1/2 is a usable value.
+      lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 2`
+    fi
+    ;;
+  esac
+])
+if test -n $lt_cv_sys_max_cmd_len ; then
+  AC_MSG_RESULT($lt_cv_sys_max_cmd_len)
+else
+  AC_MSG_RESULT(none)
+fi
+max_cmd_len=$lt_cv_sys_max_cmd_len
+_LT_DECL([], [max_cmd_len], [0],
+    [What is the maximum length of a command?])
+])# LT_CMD_MAX_LEN
+
+# Old name:
+AU_ALIAS([AC_LIBTOOL_SYS_MAX_CMD_LEN], [LT_CMD_MAX_LEN])
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AC_LIBTOOL_SYS_MAX_CMD_LEN], [])
+
+
+# _LT_HEADER_DLFCN
+# ----------------
+m4_defun([_LT_HEADER_DLFCN],
+[AC_CHECK_HEADERS([dlfcn.h], [], [], [AC_INCLUDES_DEFAULT])dnl
+])# _LT_HEADER_DLFCN
+
+
+# _LT_TRY_DLOPEN_SELF (ACTION-IF-TRUE, ACTION-IF-TRUE-W-USCORE,
+#                      ACTION-IF-FALSE, ACTION-IF-CROSS-COMPILING)
+# ----------------------------------------------------------------
+m4_defun([_LT_TRY_DLOPEN_SELF],
+[m4_require([_LT_HEADER_DLFCN])dnl
+if test "$cross_compiling" = yes; then :
+  [$4]
+else
+  lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
+  lt_status=$lt_dlunknown
+  cat > conftest.$ac_ext <<_LT_EOF
+[#line $LINENO "configure"
+#include "confdefs.h"
+
+#if HAVE_DLFCN_H
+#include <dlfcn.h>
+#endif
+
+#include <stdio.h>
+
+#ifdef RTLD_GLOBAL
+#  define LT_DLGLOBAL		RTLD_GLOBAL
+#else
+#  ifdef DL_GLOBAL
+#    define LT_DLGLOBAL		DL_GLOBAL
+#  else
+#    define LT_DLGLOBAL		0
+#  endif
+#endif
+
+/* We may have to define LT_DLLAZY_OR_NOW in the command line if we
+   find out it does not work in some platform. */
+#ifndef LT_DLLAZY_OR_NOW
+#  ifdef RTLD_LAZY
+#    define LT_DLLAZY_OR_NOW		RTLD_LAZY
+#  else
+#    ifdef DL_LAZY
+#      define LT_DLLAZY_OR_NOW		DL_LAZY
+#    else
+#      ifdef RTLD_NOW
+#        define LT_DLLAZY_OR_NOW	RTLD_NOW
+#      else
+#        ifdef DL_NOW
+#          define LT_DLLAZY_OR_NOW	DL_NOW
+#        else
+#          define LT_DLLAZY_OR_NOW	0
+#        endif
+#      endif
+#    endif
+#  endif
+#endif
+
+/* When -fvisbility=hidden is used, assume the code has been annotated
+   correspondingly for the symbols needed.  */
+#if defined(__GNUC__) && (((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3)) || (__GNUC__ > 3))
+int fnord () __attribute__((visibility("default")));
+#endif
+
+int fnord () { return 42; }
+int main ()
+{
+  void *self = dlopen (0, LT_DLGLOBAL|LT_DLLAZY_OR_NOW);
+  int status = $lt_dlunknown;
+
+  if (self)
+    {
+      if (dlsym (self,"fnord"))       status = $lt_dlno_uscore;
+      else
+        {
+	  if (dlsym( self,"_fnord"))  status = $lt_dlneed_uscore;
+          else puts (dlerror ());
+	}
+      /* dlclose (self); */
+    }
+  else
+    puts (dlerror ());
+
+  return status;
+}]
+_LT_EOF
+  if AC_TRY_EVAL(ac_link) && test -s conftest${ac_exeext} 2>/dev/null; then
+    (./conftest; exit; ) >&AS_MESSAGE_LOG_FD 2>/dev/null
+    lt_status=$?
+    case x$lt_status in
+      x$lt_dlno_uscore) $1 ;;
+      x$lt_dlneed_uscore) $2 ;;
+      x$lt_dlunknown|x*) $3 ;;
+    esac
+  else :
+    # compilation failed
+    $3
+  fi
+fi
+rm -fr conftest*
+])# _LT_TRY_DLOPEN_SELF
+
+
+# LT_SYS_DLOPEN_SELF
+# ------------------
+AC_DEFUN([LT_SYS_DLOPEN_SELF],
+[m4_require([_LT_HEADER_DLFCN])dnl
+if test "x$enable_dlopen" != xyes; then
+  enable_dlopen=unknown
+  enable_dlopen_self=unknown
+  enable_dlopen_self_static=unknown
+else
+  lt_cv_dlopen=no
+  lt_cv_dlopen_libs=
+
+  case $host_os in
+  beos*)
+    lt_cv_dlopen="load_add_on"
+    lt_cv_dlopen_libs=
+    lt_cv_dlopen_self=yes
+    ;;
+
+  mingw* | pw32* | cegcc*)
+    lt_cv_dlopen="LoadLibrary"
+    lt_cv_dlopen_libs=
+    ;;
+
+  cygwin*)
+    lt_cv_dlopen="dlopen"
+    lt_cv_dlopen_libs=
+    ;;
+
+  darwin*)
+  # if libdl is installed we need to link against it
+    AC_CHECK_LIB([dl], [dlopen],
+		[lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-ldl"],[
+    lt_cv_dlopen="dyld"
+    lt_cv_dlopen_libs=
+    lt_cv_dlopen_self=yes
+    ])
+    ;;
+
+  *)
+    AC_CHECK_FUNC([shl_load],
+	  [lt_cv_dlopen="shl_load"],
+      [AC_CHECK_LIB([dld], [shl_load],
+	    [lt_cv_dlopen="shl_load" lt_cv_dlopen_libs="-ldld"],
+	[AC_CHECK_FUNC([dlopen],
+	      [lt_cv_dlopen="dlopen"],
+	  [AC_CHECK_LIB([dl], [dlopen],
+		[lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-ldl"],
+	    [AC_CHECK_LIB([svld], [dlopen],
+		  [lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-lsvld"],
+	      [AC_CHECK_LIB([dld], [dld_link],
+		    [lt_cv_dlopen="dld_link" lt_cv_dlopen_libs="-ldld"])
+	      ])
+	    ])
+	  ])
+	])
+      ])
+    ;;
+  esac
+
+  if test "x$lt_cv_dlopen" != xno; then
+    enable_dlopen=yes
+  else
+    enable_dlopen=no
+  fi
+
+  case $lt_cv_dlopen in
+  dlopen)
+    save_CPPFLAGS="$CPPFLAGS"
+    test "x$ac_cv_header_dlfcn_h" = xyes && CPPFLAGS="$CPPFLAGS -DHAVE_DLFCN_H"
+
+    save_LDFLAGS="$LDFLAGS"
+    wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $export_dynamic_flag_spec\"
+
+    save_LIBS="$LIBS"
+    LIBS="$lt_cv_dlopen_libs $LIBS"
+
+    AC_CACHE_CHECK([whether a program can dlopen itself],
+	  lt_cv_dlopen_self, [dnl
+	  _LT_TRY_DLOPEN_SELF(
+	    lt_cv_dlopen_self=yes, lt_cv_dlopen_self=yes,
+	    lt_cv_dlopen_self=no, lt_cv_dlopen_self=cross)
+    ])
+
+    if test "x$lt_cv_dlopen_self" = xyes; then
+      wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $lt_prog_compiler_static\"
+      AC_CACHE_CHECK([whether a statically linked program can dlopen itself],
+	  lt_cv_dlopen_self_static, [dnl
+	  _LT_TRY_DLOPEN_SELF(
+	    lt_cv_dlopen_self_static=yes, lt_cv_dlopen_self_static=yes,
+	    lt_cv_dlopen_self_static=no,  lt_cv_dlopen_self_static=cross)
+      ])
+    fi
+
+    CPPFLAGS="$save_CPPFLAGS"
+    LDFLAGS="$save_LDFLAGS"
+    LIBS="$save_LIBS"
+    ;;
+  esac
+
+  case $lt_cv_dlopen_self in
+  yes|no) enable_dlopen_self=$lt_cv_dlopen_self ;;
+  *) enable_dlopen_self=unknown ;;
+  esac
+
+  case $lt_cv_dlopen_self_static in
+  yes|no) enable_dlopen_self_static=$lt_cv_dlopen_self_static ;;
+  *) enable_dlopen_self_static=unknown ;;
+  esac
+fi
+_LT_DECL([dlopen_support], [enable_dlopen], [0],
+	 [Whether dlopen is supported])
+_LT_DECL([dlopen_self], [enable_dlopen_self], [0],
+	 [Whether dlopen of programs is supported])
+_LT_DECL([dlopen_self_static], [enable_dlopen_self_static], [0],
+	 [Whether dlopen of statically linked programs is supported])
+])# LT_SYS_DLOPEN_SELF
+
+# Old name:
+AU_ALIAS([AC_LIBTOOL_DLOPEN_SELF], [LT_SYS_DLOPEN_SELF])
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AC_LIBTOOL_DLOPEN_SELF], [])
+
+
+# _LT_COMPILER_C_O([TAGNAME])
+# ---------------------------
+# Check to see if options -c and -o are simultaneously supported by compiler.
+# This macro does not hard code the compiler like AC_PROG_CC_C_O.
+m4_defun([_LT_COMPILER_C_O],
+[m4_require([_LT_DECL_SED])dnl
+m4_require([_LT_FILEUTILS_DEFAULTS])dnl
+m4_require([_LT_TAG_COMPILER])dnl
+AC_CACHE_CHECK([if $compiler supports -c -o file.$ac_objext],
+  [_LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)],
+  [_LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)=no
+   $RM -r conftest 2>/dev/null
+   mkdir conftest
+   cd conftest
+   mkdir out
+   echo "$lt_simple_compile_test_code" > conftest.$ac_ext
+
+   lt_compiler_flag="-o out/conftest2.$ac_objext"
+   # Insert the option either (1) after the last *FLAGS variable, or
+   # (2) before a word containing "conftest.", or (3) at the end.
+   # Note that $ac_compile itself does not contain backslashes and begins
+   # with a dollar sign (not a hyphen), so the echo should work correctly.
+   lt_compile=`echo "$ac_compile" | $SED \
+   -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
+   -e 's: [[^ ]]*conftest\.: $lt_compiler_flag&:; t' \
+   -e 's:$: $lt_compiler_flag:'`
+   (eval echo "\"\$as_me:$LINENO: $lt_compile\"" >&AS_MESSAGE_LOG_FD)
+   (eval "$lt_compile" 2>out/conftest.err)
+   ac_status=$?
+   cat out/conftest.err >&AS_MESSAGE_LOG_FD
+   echo "$as_me:$LINENO: \$? = $ac_status" >&AS_MESSAGE_LOG_FD
+   if (exit $ac_status) && test -s out/conftest2.$ac_objext
+   then
+     # The compiler can only warn and ignore the option if not recognized
+     # So say no if there are warnings
+     $ECHO "$_lt_compiler_boilerplate" | $SED '/^$/d' > out/conftest.exp
+     $SED '/^$/d; /^ *+/d' out/conftest.err >out/conftest.er2
+     if test ! -s out/conftest.er2 || diff out/conftest.exp out/conftest.er2 >/dev/null; then
+       _LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)=yes
+     fi
+   fi
+   chmod u+w . 2>&AS_MESSAGE_LOG_FD
+   $RM conftest*
+   # SGI C++ compiler will create directory out/ii_files/ for
+   # template instantiation
+   test -d out/ii_files && $RM out/ii_files/* && rmdir out/ii_files
+   $RM out/* && rmdir out
+   cd ..
+   $RM -r conftest
+   $RM conftest*
+])
+_LT_TAGDECL([compiler_c_o], [lt_cv_prog_compiler_c_o], [1],
+	[Does compiler simultaneously support -c and -o options?])
+])# _LT_COMPILER_C_O
+
+
+# _LT_COMPILER_FILE_LOCKS([TAGNAME])
+# ----------------------------------
+# Check to see if we can do hard links to lock some files if needed
+m4_defun([_LT_COMPILER_FILE_LOCKS],
+[m4_require([_LT_ENABLE_LOCK])dnl
+m4_require([_LT_FILEUTILS_DEFAULTS])dnl
+_LT_COMPILER_C_O([$1])
+
+hard_links="nottested"
+if test "$_LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)" = no && test "$need_locks" != no; then
+  # do not overwrite the value of need_locks provided by the user
+  AC_MSG_CHECKING([if we can lock with hard links])
+  hard_links=yes
+  $RM conftest*
+  ln conftest.a conftest.b 2>/dev/null && hard_links=no
+  touch conftest.a
+  ln conftest.a conftest.b 2>&5 || hard_links=no
+  ln conftest.a conftest.b 2>/dev/null && hard_links=no
+  AC_MSG_RESULT([$hard_links])
+  if test "$hard_links" = no; then
+    AC_MSG_WARN([`$CC' does not support `-c -o', so `make -j' may be unsafe])
+    need_locks=warn
+  fi
+else
+  need_locks=no
+fi
+_LT_DECL([], [need_locks], [1], [Must we lock files when doing compilation?])
+])# _LT_COMPILER_FILE_LOCKS
+
+
+# _LT_CHECK_OBJDIR
+# ----------------
+m4_defun([_LT_CHECK_OBJDIR],
+[AC_CACHE_CHECK([for objdir], [lt_cv_objdir],
+[rm -f .libs 2>/dev/null
+mkdir .libs 2>/dev/null
+if test -d .libs; then
+  lt_cv_objdir=.libs
+else
+  # MS-DOS does not allow filenames that begin with a dot.
+  lt_cv_objdir=_libs
+fi
+rmdir .libs 2>/dev/null])
+objdir=$lt_cv_objdir
+_LT_DECL([], [objdir], [0],
+         [The name of the directory that contains temporary libtool files])dnl
+m4_pattern_allow([LT_OBJDIR])dnl
+AC_DEFINE_UNQUOTED(LT_OBJDIR, "$lt_cv_objdir/",
+  [Define to the sub-directory in which libtool stores uninstalled libraries.])
+])# _LT_CHECK_OBJDIR
+
+
+# _LT_LINKER_HARDCODE_LIBPATH([TAGNAME])
+# --------------------------------------
+# Check hardcoding attributes.
+m4_defun([_LT_LINKER_HARDCODE_LIBPATH],
+[AC_MSG_CHECKING([how to hardcode library paths into programs])
+_LT_TAGVAR(hardcode_action, $1)=
+if test -n "$_LT_TAGVAR(hardcode_libdir_flag_spec, $1)" ||
+   test -n "$_LT_TAGVAR(runpath_var, $1)" ||
+   test "X$_LT_TAGVAR(hardcode_automatic, $1)" = "Xyes" ; then
+
+  # We can hardcode non-existent directories.
+  if test "$_LT_TAGVAR(hardcode_direct, $1)" != no &&
+     # If the only mechanism to avoid hardcoding is shlibpath_var, we
+     # have to relink, otherwise we might link with an installed library
+     # when we should be linking with a yet-to-be-installed one
+     ## test "$_LT_TAGVAR(hardcode_shlibpath_var, $1)" != no &&
+     test "$_LT_TAGVAR(hardcode_minus_L, $1)" != no; then
+    # Linking always hardcodes the temporary library directory.
+    _LT_TAGVAR(hardcode_action, $1)=relink
+  else
+    # We can link without hardcoding, and we can hardcode nonexisting dirs.
+    _LT_TAGVAR(hardcode_action, $1)=immediate
+  fi
+else
+  # We cannot hardcode anything, or else we can only hardcode existing
+  # directories.
+  _LT_TAGVAR(hardcode_action, $1)=unsupported
+fi
+AC_MSG_RESULT([$_LT_TAGVAR(hardcode_action, $1)])
+
+if test "$_LT_TAGVAR(hardcode_action, $1)" = relink ||
+   test "$_LT_TAGVAR(inherit_rpath, $1)" = yes; then
+  # Fast installation is not supported
+  enable_fast_install=no
+elif test "$shlibpath_overrides_runpath" = yes ||
+     test "$enable_shared" = no; then
+  # Fast installation is not necessary
+  enable_fast_install=needless
+fi
+_LT_TAGDECL([], [hardcode_action], [0],
+    [How to hardcode a shared library path into an executable])
+])# _LT_LINKER_HARDCODE_LIBPATH
+
+
+# _LT_CMD_STRIPLIB
+# ----------------
+m4_defun([_LT_CMD_STRIPLIB],
+[m4_require([_LT_DECL_EGREP])
+striplib=
+old_striplib=
+AC_MSG_CHECKING([whether stripping libraries is possible])
+if test -n "$STRIP" && $STRIP -V 2>&1 | $GREP "GNU strip" >/dev/null; then
+  test -z "$old_striplib" && old_striplib="$STRIP --strip-debug"
+  test -z "$striplib" && striplib="$STRIP --strip-unneeded"
+  AC_MSG_RESULT([yes])
+else
+# FIXME - insert some real tests, host_os isn't really good enough
+  case $host_os in
+  darwin*)
+    if test -n "$STRIP" ; then
+      striplib="$STRIP -x"
+      old_striplib="$STRIP -S"
+      AC_MSG_RESULT([yes])
+    else
+      AC_MSG_RESULT([no])
+    fi
+    ;;
+  *)
+    AC_MSG_RESULT([no])
+    ;;
+  esac
+fi
+_LT_DECL([], [old_striplib], [1], [Commands to strip libraries])
+_LT_DECL([], [striplib], [1])
+])# _LT_CMD_STRIPLIB
+
+
+# _LT_SYS_DYNAMIC_LINKER([TAG])
+# -----------------------------
+# PORTME Fill in your ld.so characteristics
+m4_defun([_LT_SYS_DYNAMIC_LINKER],
+[AC_REQUIRE([AC_CANONICAL_HOST])dnl
+m4_require([_LT_DECL_EGREP])dnl
+m4_require([_LT_FILEUTILS_DEFAULTS])dnl
+m4_require([_LT_DECL_OBJDUMP])dnl
+m4_require([_LT_DECL_SED])dnl
+m4_require([_LT_CHECK_SHELL_FEATURES])dnl
+AC_MSG_CHECKING([dynamic linker characteristics])
+m4_if([$1],
+	[], [
+if test "$GCC" = yes; then
+  case $host_os in
+    darwin*) lt_awk_arg="/^libraries:/,/LR/" ;;
+    *) lt_awk_arg="/^libraries:/" ;;
+  esac
+  case $host_os in
+    mingw* | cegcc*) lt_sed_strip_eq="s,=\([[A-Za-z]]:\),\1,g" ;;
+    *) lt_sed_strip_eq="s,=/,/,g" ;;
+  esac
+  lt_search_path_spec=`$CC -print-search-dirs | awk $lt_awk_arg | $SED -e "s/^libraries://" -e $lt_sed_strip_eq`
+  case $lt_search_path_spec in
+  *\;*)
+    # if the path contains ";" then we assume it to be the separator
+    # otherwise default to the standard path separator (i.e. ":") - it is
+    # assumed that no part of a normal pathname contains ";" but that should
+    # okay in the real world where ";" in dirpaths is itself problematic.
+    lt_search_path_spec=`$ECHO "$lt_search_path_spec" | $SED 's/;/ /g'`
+    ;;
+  *)
+    lt_search_path_spec=`$ECHO "$lt_search_path_spec" | $SED "s/$PATH_SEPARATOR/ /g"`
+    ;;
+  esac
+  # Ok, now we have the path, separated by spaces, we can step through it
+  # and add multilib dir if necessary.
+  lt_tmp_lt_search_path_spec=
+  lt_multi_os_dir=`$CC $CPPFLAGS $CFLAGS $LDFLAGS -print-multi-os-directory 2>/dev/null`
+  for lt_sys_path in $lt_search_path_spec; do
+    if test -d "$lt_sys_path/$lt_multi_os_dir"; then
+      lt_tmp_lt_search_path_spec="$lt_tmp_lt_search_path_spec $lt_sys_path/$lt_multi_os_dir"
+    else
+      test -d "$lt_sys_path" && \
+	lt_tmp_lt_search_path_spec="$lt_tmp_lt_search_path_spec $lt_sys_path"
+    fi
+  done
+  lt_search_path_spec=`$ECHO "$lt_tmp_lt_search_path_spec" | awk '
+BEGIN {RS=" "; FS="/|\n";} {
+  lt_foo="";
+  lt_count=0;
+  for (lt_i = NF; lt_i > 0; lt_i--) {
+    if ($lt_i != "" && $lt_i != ".") {
+      if ($lt_i == "..") {
+        lt_count++;
+      } else {
+        if (lt_count == 0) {
+          lt_foo="/" $lt_i lt_foo;
+        } else {
+          lt_count--;
+        }
+      }
+    }
+  }
+  if (lt_foo != "") { lt_freq[[lt_foo]]++; }
+  if (lt_freq[[lt_foo]] == 1) { print lt_foo; }
+}'`
+  # AWK program above erroneously prepends '/' to C:/dos/paths
+  # for these hosts.
+  case $host_os in
+    mingw* | cegcc*) lt_search_path_spec=`$ECHO "$lt_search_path_spec" |\
+      $SED 's,/\([[A-Za-z]]:\),\1,g'` ;;
+  esac
+  sys_lib_search_path_spec=`$ECHO "$lt_search_path_spec" | $lt_NL2SP`
+else
+  sys_lib_search_path_spec="/lib /usr/lib /usr/local/lib"
+fi])
+library_names_spec=
+libname_spec='lib$name'
+soname_spec=
+shrext_cmds=".so"
+postinstall_cmds=
+postuninstall_cmds=
+finish_cmds=
+finish_eval=
+shlibpath_var=
+shlibpath_overrides_runpath=unknown
+version_type=none
+dynamic_linker="$host_os ld.so"
+sys_lib_dlsearch_path_spec="/lib /usr/lib"
+need_lib_prefix=unknown
+hardcode_into_libs=no
+
+# when you set need_version to no, make sure it does not cause -set_version
+# flags to be left without arguments
+need_version=unknown
+
+case $host_os in
+aix3*)
+  version_type=linux # correct to gnu/linux during the next big refactor
+  library_names_spec='${libname}${release}${shared_ext}$versuffix $libname.a'
+  shlibpath_var=LIBPATH
+
+  # AIX 3 has no versioning support, so we append a major version to the name.
+  soname_spec='${libname}${release}${shared_ext}$major'
+  ;;
+
+aix[[4-9]]*)
+  version_type=linux # correct to gnu/linux during the next big refactor
+  need_lib_prefix=no
+  need_version=no
+  hardcode_into_libs=yes
+  if test "$host_cpu" = ia64; then
+    # AIX 5 supports IA64
+    library_names_spec='${libname}${release}${shared_ext}$major ${libname}${release}${shared_ext}$versuffix $libname${shared_ext}'
+    shlibpath_var=LD_LIBRARY_PATH
+  else
+    # With GCC up to 2.95.x, collect2 would create an import file
+    # for dependence libraries.  The import file would start with
+    # the line `#! .'.  This would cause the generated library to
+    # depend on `.', always an invalid library.  This was fixed in
+    # development snapshots of GCC prior to 3.0.
+    case $host_os in
+      aix4 | aix4.[[01]] | aix4.[[01]].*)
+      if { echo '#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 97)'
+	   echo ' yes '
+	   echo '#endif'; } | ${CC} -E - | $GREP yes > /dev/null; then
+	:
+      else
+	can_build_shared=no
+      fi
+      ;;
+    esac
+    # AIX (on Power*) has no versioning support, so currently we can not hardcode correct
+    # soname into executable. Probably we can add versioning support to
+    # collect2, so additional links can be useful in future.
+    if test "$aix_use_runtimelinking" = yes; then
+      # If using run time linking (on AIX 4.2 or later) use lib<name>.so
+      # instead of lib<name>.a to let people know that these are not
+      # typical AIX shared libraries.
+      library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+    else
+      # We preserve .a as extension for shared libraries through AIX4.2
+      # and later when we are not doing run time linking.
+      library_names_spec='${libname}${release}.a $libname.a'
+      soname_spec='${libname}${release}${shared_ext}$major'
+    fi
+    shlibpath_var=LIBPATH
+  fi
+  ;;
+
+amigaos*)
+  case $host_cpu in
+  powerpc)
+    # Since July 2007 AmigaOS4 officially supports .so libraries.
+    # When compiling the executable, add -use-dynld -Lsobjs: to the compileline.
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+    ;;
+  m68k)
+    library_names_spec='$libname.ixlibrary $libname.a'
+    # Create ${libname}_ixlibrary.a entries in /sys/libs.
+    finish_eval='for lib in `ls $libdir/*.ixlibrary 2>/dev/null`; do libname=`func_echo_all "$lib" | $SED '\''s%^.*/\([[^/]]*\)\.ixlibrary$%\1%'\''`; test $RM /sys/libs/${libname}_ixlibrary.a; $show "cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a"; cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a || exit 1; done'
+    ;;
+  esac
+  ;;
+
+beos*)
+  library_names_spec='${libname}${shared_ext}'
+  dynamic_linker="$host_os ld.so"
+  shlibpath_var=LIBRARY_PATH
+  ;;
+
+bsdi[[45]]*)
+  version_type=linux # correct to gnu/linux during the next big refactor
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  finish_cmds='PATH="\$PATH:/sbin" ldconfig $libdir'
+  shlibpath_var=LD_LIBRARY_PATH
+  sys_lib_search_path_spec="/shlib /usr/lib /usr/X11/lib /usr/contrib/lib /lib /usr/local/lib"
+  sys_lib_dlsearch_path_spec="/shlib /usr/lib /usr/local/lib"
+  # the default ld.so.conf also contains /usr/contrib/lib and
+  # /usr/X11R6/lib (/usr/X11 is a link to /usr/X11R6), but let us allow
+  # libtool to hard-code these into programs
+  ;;
+
+cygwin* | mingw* | pw32* | cegcc*)
+  version_type=windows
+  shrext_cmds=".dll"
+  need_version=no
+  need_lib_prefix=no
+
+  case $GCC,$cc_basename in
+  yes,*)
+    # gcc
+    library_names_spec='$libname.dll.a'
+    # DLL is installed to $(libdir)/../bin by postinstall_cmds
+    postinstall_cmds='base_file=`basename \${file}`~
+      dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
+      dldir=$destdir/`dirname \$dlpath`~
+      test -d \$dldir || mkdir -p \$dldir~
+      $install_prog $dir/$dlname \$dldir/$dlname~
+      chmod a+x \$dldir/$dlname~
+      if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
+        eval '\''$striplib \$dldir/$dlname'\'' || exit \$?;
+      fi'
+    postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~
+      dlpath=$dir/\$dldll~
+       $RM \$dlpath'
+    shlibpath_overrides_runpath=yes
+
+    case $host_os in
+    cygwin*)
+      # Cygwin DLLs use 'cyg' prefix rather than 'lib'
+      soname_spec='`echo ${libname} | sed -e 's/^lib/cyg/'``echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext}'
+m4_if([$1], [],[
+      sys_lib_search_path_spec="$sys_lib_search_path_spec /usr/lib/w32api"])
+      ;;
+    mingw* | cegcc*)
+      # MinGW DLLs use traditional 'lib' prefix
+      soname_spec='${libname}`echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext}'
+      ;;
+    pw32*)
+      # pw32 DLLs use 'pw' prefix rather than 'lib'
+      library_names_spec='`echo ${libname} | sed -e 's/^lib/pw/'``echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext}'
+      ;;
+    esac
+    dynamic_linker='Win32 ld.exe'
+    ;;
+
+  *,cl*)
+    # Native MSVC
+    libname_spec='$name'
+    soname_spec='${libname}`echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext}'
+    library_names_spec='${libname}.dll.lib'
+
+    case $build_os in
+    mingw*)
+      sys_lib_search_path_spec=
+      lt_save_ifs=$IFS
+      IFS=';'
+      for lt_path in $LIB
+      do
+        IFS=$lt_save_ifs
+        # Let DOS variable expansion print the short 8.3 style file name.
+        lt_path=`cd "$lt_path" 2>/dev/null && cmd //C "for %i in (".") do @echo %~si"`
+        sys_lib_search_path_spec="$sys_lib_search_path_spec $lt_path"
+      done
+      IFS=$lt_save_ifs
+      # Convert to MSYS style.
+      sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | sed -e 's|\\\\|/|g' -e 's| \\([[a-zA-Z]]\\):| /\\1|g' -e 's|^ ||'`
+      ;;
+    cygwin*)
+      # Convert to unix form, then to dos form, then back to unix form
+      # but this time dos style (no spaces!) so that the unix form looks
+      # like /cygdrive/c/PROGRA~1:/cygdr...
+      sys_lib_search_path_spec=`cygpath --path --unix "$LIB"`
+      sys_lib_search_path_spec=`cygpath --path --dos "$sys_lib_search_path_spec" 2>/dev/null`
+      sys_lib_search_path_spec=`cygpath --path --unix "$sys_lib_search_path_spec" | $SED -e "s/$PATH_SEPARATOR/ /g"`
+      ;;
+    *)
+      sys_lib_search_path_spec="$LIB"
+      if $ECHO "$sys_lib_search_path_spec" | [$GREP ';[c-zC-Z]:/' >/dev/null]; then
+        # It is most probably a Windows format PATH.
+        sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | $SED -e 's/;/ /g'`
+      else
+        sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | $SED -e "s/$PATH_SEPARATOR/ /g"`
+      fi
+      # FIXME: find the short name or the path components, as spaces are
+      # common. (e.g. "Program Files" -> "PROGRA~1")
+      ;;
+    esac
+
+    # DLL is installed to $(libdir)/../bin by postinstall_cmds
+    postinstall_cmds='base_file=`basename \${file}`~
+      dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
+      dldir=$destdir/`dirname \$dlpath`~
+      test -d \$dldir || mkdir -p \$dldir~
+      $install_prog $dir/$dlname \$dldir/$dlname'
+    postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~
+      dlpath=$dir/\$dldll~
+       $RM \$dlpath'
+    shlibpath_overrides_runpath=yes
+    dynamic_linker='Win32 link.exe'
+    ;;
+
+  *)
+    # Assume MSVC wrapper
+    library_names_spec='${libname}`echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext} $libname.lib'
+    dynamic_linker='Win32 ld.exe'
+    ;;
+  esac
+  # FIXME: first we should search . and the directory the executable is in
+  shlibpath_var=PATH
+  ;;
+
+darwin* | rhapsody*)
+  dynamic_linker="$host_os dyld"
+  version_type=darwin
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${major}$shared_ext ${libname}$shared_ext'
+  soname_spec='${libname}${release}${major}$shared_ext'
+  shlibpath_overrides_runpath=yes
+  shlibpath_var=DYLD_LIBRARY_PATH
+  shrext_cmds='`test .$module = .yes && echo .so || echo .dylib`'
+m4_if([$1], [],[
+  sys_lib_search_path_spec="$sys_lib_search_path_spec /usr/local/lib"])
+  sys_lib_dlsearch_path_spec='/usr/local/lib /lib /usr/lib'
+  ;;
+
+dgux*)
+  version_type=linux # correct to gnu/linux during the next big refactor
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname$shared_ext'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  ;;
+
+freebsd* | dragonfly*)
+  # DragonFly does not have aout.  When/if they implement a new
+  # versioning mechanism, adjust this.
+  if test -x /usr/bin/objformat; then
+    objformat=`/usr/bin/objformat`
+  else
+    case $host_os in
+    freebsd[[23]].*) objformat=aout ;;
+    *) objformat=elf ;;
+    esac
+  fi
+  version_type=freebsd-$objformat
+  case $version_type in
+    freebsd-elf*)
+      library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext} $libname${shared_ext}'
+      need_version=no
+      need_lib_prefix=no
+      ;;
+    freebsd-*)
+      library_names_spec='${libname}${release}${shared_ext}$versuffix $libname${shared_ext}$versuffix'
+      need_version=yes
+      ;;
+  esac
+  shlibpath_var=LD_LIBRARY_PATH
+  case $host_os in
+  freebsd2.*)
+    shlibpath_overrides_runpath=yes
+    ;;
+  freebsd3.[[01]]* | freebsdelf3.[[01]]*)
+    shlibpath_overrides_runpath=yes
+    hardcode_into_libs=yes
+    ;;
+  freebsd3.[[2-9]]* | freebsdelf3.[[2-9]]* | \
+  freebsd4.[[0-5]] | freebsdelf4.[[0-5]] | freebsd4.1.1 | freebsdelf4.1.1)
+    shlibpath_overrides_runpath=no
+    hardcode_into_libs=yes
+    ;;
+  *) # from 4.6 on, and DragonFly
+    shlibpath_overrides_runpath=yes
+    hardcode_into_libs=yes
+    ;;
+  esac
+  ;;
+
+haiku*)
+  version_type=linux # correct to gnu/linux during the next big refactor
+  need_lib_prefix=no
+  need_version=no
+  dynamic_linker="$host_os runtime_loader"
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}${major} ${libname}${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  sys_lib_dlsearch_path_spec='/boot/home/config/lib /boot/common/lib /boot/system/lib'
+  hardcode_into_libs=yes
+  ;;
+
+hpux9* | hpux10* | hpux11*)
+  # Give a soname corresponding to the major version so that dld.sl refuses to
+  # link against other versions.
+  version_type=sunos
+  need_lib_prefix=no
+  need_version=no
+  case $host_cpu in
+  ia64*)
+    shrext_cmds='.so'
+    hardcode_into_libs=yes
+    dynamic_linker="$host_os dld.so"
+    shlibpath_var=LD_LIBRARY_PATH
+    shlibpath_overrides_runpath=yes # Unless +noenvvar is specified.
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+    soname_spec='${libname}${release}${shared_ext}$major'
+    if test "X$HPUX_IA64_MODE" = X32; then
+      sys_lib_search_path_spec="/usr/lib/hpux32 /usr/local/lib/hpux32 /usr/local/lib"
+    else
+      sys_lib_search_path_spec="/usr/lib/hpux64 /usr/local/lib/hpux64"
+    fi
+    sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec
+    ;;
+  hppa*64*)
+    shrext_cmds='.sl'
+    hardcode_into_libs=yes
+    dynamic_linker="$host_os dld.sl"
+    shlibpath_var=LD_LIBRARY_PATH # How should we handle SHLIB_PATH
+    shlibpath_overrides_runpath=yes # Unless +noenvvar is specified.
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+    soname_spec='${libname}${release}${shared_ext}$major'
+    sys_lib_search_path_spec="/usr/lib/pa20_64 /usr/ccs/lib/pa20_64"
+    sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec
+    ;;
+  *)
+    shrext_cmds='.sl'
+    dynamic_linker="$host_os dld.sl"
+    shlibpath_var=SHLIB_PATH
+    shlibpath_overrides_runpath=no # +s is required to enable SHLIB_PATH
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+    soname_spec='${libname}${release}${shared_ext}$major'
+    ;;
+  esac
+  # HP-UX runs *really* slowly unless shared libraries are mode 555, ...
+  postinstall_cmds='chmod 555 $lib'
+  # or fails outright, so override atomically:
+  install_override_mode=555
+  ;;
+
+interix[[3-9]]*)
+  version_type=linux # correct to gnu/linux during the next big refactor
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  dynamic_linker='Interix 3.x ld.so.1 (PE, like ELF)'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=no
+  hardcode_into_libs=yes
+  ;;
+
+irix5* | irix6* | nonstopux*)
+  case $host_os in
+    nonstopux*) version_type=nonstopux ;;
+    *)
+	if test "$lt_cv_prog_gnu_ld" = yes; then
+		version_type=linux # correct to gnu/linux during the next big refactor
+	else
+		version_type=irix
+	fi ;;
+  esac
+  need_lib_prefix=no
+  need_version=no
+  soname_spec='${libname}${release}${shared_ext}$major'
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${release}${shared_ext} $libname${shared_ext}'
+  case $host_os in
+  irix5* | nonstopux*)
+    libsuff= shlibsuff=
+    ;;
+  *)
+    case $LD in # libtool.m4 will add one of these switches to LD
+    *-32|*"-32 "|*-melf32bsmip|*"-melf32bsmip ")
+      libsuff= shlibsuff= libmagic=32-bit;;
+    *-n32|*"-n32 "|*-melf32bmipn32|*"-melf32bmipn32 ")
+      libsuff=32 shlibsuff=N32 libmagic=N32;;
+    *-64|*"-64 "|*-melf64bmip|*"-melf64bmip ")
+      libsuff=64 shlibsuff=64 libmagic=64-bit;;
+    *) libsuff= shlibsuff= libmagic=never-match;;
+    esac
+    ;;
+  esac
+  shlibpath_var=LD_LIBRARY${shlibsuff}_PATH
+  shlibpath_overrides_runpath=no
+  sys_lib_search_path_spec="/usr/lib${libsuff} /lib${libsuff} /usr/local/lib${libsuff}"
+  sys_lib_dlsearch_path_spec="/usr/lib${libsuff} /lib${libsuff}"
+  hardcode_into_libs=yes
+  ;;
+
+# No shared lib support for Linux oldld, aout, or coff.
+linux*oldld* | linux*aout* | linux*coff*)
+  dynamic_linker=no
+  ;;
+
+# This must be glibc/ELF.
+linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*)
+  version_type=linux # correct to gnu/linux during the next big refactor
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  finish_cmds='PATH="\$PATH:/sbin" ldconfig -n $libdir'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=no
+
+  # Some binutils ld are patched to set DT_RUNPATH
+  AC_CACHE_VAL([lt_cv_shlibpath_overrides_runpath],
+    [lt_cv_shlibpath_overrides_runpath=no
+    save_LDFLAGS=$LDFLAGS
+    save_libdir=$libdir
+    eval "libdir=/foo; wl=\"$_LT_TAGVAR(lt_prog_compiler_wl, $1)\"; \
+	 LDFLAGS=\"\$LDFLAGS $_LT_TAGVAR(hardcode_libdir_flag_spec, $1)\""
+    AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])],
+      [AS_IF([ ($OBJDUMP -p conftest$ac_exeext) 2>/dev/null | grep "RUNPATH.*$libdir" >/dev/null],
+	 [lt_cv_shlibpath_overrides_runpath=yes])])
+    LDFLAGS=$save_LDFLAGS
+    libdir=$save_libdir
+    ])
+  shlibpath_overrides_runpath=$lt_cv_shlibpath_overrides_runpath
+
+  # This implies no fast_install, which is unacceptable.
+  # Some rework will be needed to allow for fast_install
+  # before this can be enabled.
+  hardcode_into_libs=yes
+
+  # Append ld.so.conf contents to the search path
+  if test -f /etc/ld.so.conf; then
+    lt_ld_extra=`awk '/^include / { system(sprintf("cd /etc; cat %s 2>/dev/null", \[$]2)); skip = 1; } { if (!skip) print \[$]0; skip = 0; }' < /etc/ld.so.conf | $SED -e 's/#.*//;/^[	 ]*hwcap[	 ]/d;s/[:,	]/ /g;s/=[^=]*$//;s/=[^= ]* / /g;s/"//g;/^$/d' | tr '\n' ' '`
+    sys_lib_dlsearch_path_spec="/lib /usr/lib $lt_ld_extra"
+  fi
+
+  # We used to test for /lib/ld.so.1 and disable shared libraries on
+  # powerpc, because MkLinux only supported shared libraries with the
+  # GNU dynamic linker.  Since this was broken with cross compilers,
+  # most powerpc-linux boxes support dynamic linking these days and
+  # people can always --disable-shared, the test was removed, and we
+  # assume the GNU/Linux dynamic linker is in use.
+  dynamic_linker='GNU/Linux ld.so'
+  ;;
+
+netbsdelf*-gnu)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=no
+  hardcode_into_libs=yes
+  dynamic_linker='NetBSD ld.elf_so'
+  ;;
+
+netbsd*)
+  version_type=sunos
+  need_lib_prefix=no
+  need_version=no
+  if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix'
+    finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir'
+    dynamic_linker='NetBSD (a.out) ld.so'
+  else
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}'
+    soname_spec='${libname}${release}${shared_ext}$major'
+    dynamic_linker='NetBSD ld.elf_so'
+  fi
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  hardcode_into_libs=yes
+  ;;
+
+newsos6)
+  version_type=linux # correct to gnu/linux during the next big refactor
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  ;;
+
+*nto* | *qnx*)
+  version_type=qnx
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=no
+  hardcode_into_libs=yes
+  dynamic_linker='ldqnx.so'
+  ;;
+
+openbsd*)
+  version_type=sunos
+  sys_lib_dlsearch_path_spec="/usr/lib"
+  need_lib_prefix=no
+  # Some older versions of OpenBSD (3.3 at least) *do* need versioned libs.
+  case $host_os in
+    openbsd3.3 | openbsd3.3.*)	need_version=yes ;;
+    *)				need_version=no  ;;
+  esac
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix'
+  finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir'
+  shlibpath_var=LD_LIBRARY_PATH
+  if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then
+    case $host_os in
+      openbsd2.[[89]] | openbsd2.[[89]].*)
+	shlibpath_overrides_runpath=no
+	;;
+      *)
+	shlibpath_overrides_runpath=yes
+	;;
+      esac
+  else
+    shlibpath_overrides_runpath=yes
+  fi
+  ;;
+
+os2*)
+  libname_spec='$name'
+  shrext_cmds=".dll"
+  need_lib_prefix=no
+  library_names_spec='$libname${shared_ext} $libname.a'
+  dynamic_linker='OS/2 ld.exe'
+  shlibpath_var=LIBPATH
+  ;;
+
+osf3* | osf4* | osf5*)
+  version_type=osf
+  need_lib_prefix=no
+  need_version=no
+  soname_spec='${libname}${release}${shared_ext}$major'
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  shlibpath_var=LD_LIBRARY_PATH
+  sys_lib_search_path_spec="/usr/shlib /usr/ccs/lib /usr/lib/cmplrs/cc /usr/lib /usr/local/lib /var/shlib"
+  sys_lib_dlsearch_path_spec="$sys_lib_search_path_spec"
+  ;;
+
+rdos*)
+  dynamic_linker=no
+  ;;
+
+solaris*)
+  version_type=linux # correct to gnu/linux during the next big refactor
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  hardcode_into_libs=yes
+  # ldd complains unless libraries are executable
+  postinstall_cmds='chmod +x $lib'
+  ;;
+
+sunos4*)
+  version_type=sunos
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix'
+  finish_cmds='PATH="\$PATH:/usr/etc" ldconfig $libdir'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  if test "$with_gnu_ld" = yes; then
+    need_lib_prefix=no
+  fi
+  need_version=yes
+  ;;
+
+sysv4 | sysv4.3*)
+  version_type=linux # correct to gnu/linux during the next big refactor
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  case $host_vendor in
+    sni)
+      shlibpath_overrides_runpath=no
+      need_lib_prefix=no
+      runpath_var=LD_RUN_PATH
+      ;;
+    siemens)
+      need_lib_prefix=no
+      ;;
+    motorola)
+      need_lib_prefix=no
+      need_version=no
+      shlibpath_overrides_runpath=no
+      sys_lib_search_path_spec='/lib /usr/lib /usr/ccs/lib'
+      ;;
+  esac
+  ;;
+
+sysv4*MP*)
+  if test -d /usr/nec ;then
+    version_type=linux # correct to gnu/linux during the next big refactor
+    library_names_spec='$libname${shared_ext}.$versuffix $libname${shared_ext}.$major $libname${shared_ext}'
+    soname_spec='$libname${shared_ext}.$major'
+    shlibpath_var=LD_LIBRARY_PATH
+  fi
+  ;;
+
+sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*)
+  version_type=freebsd-elf
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext} $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  hardcode_into_libs=yes
+  if test "$with_gnu_ld" = yes; then
+    sys_lib_search_path_spec='/usr/local/lib /usr/gnu/lib /usr/ccs/lib /usr/lib /lib'
+  else
+    sys_lib_search_path_spec='/usr/ccs/lib /usr/lib'
+    case $host_os in
+      sco3.2v5*)
+        sys_lib_search_path_spec="$sys_lib_search_path_spec /lib"
+	;;
+    esac
+  fi
+  sys_lib_dlsearch_path_spec='/usr/lib'
+  ;;
+
+tpf*)
+  # TPF is a cross-target only.  Preferred cross-host = GNU/Linux.
+  version_type=linux # correct to gnu/linux during the next big refactor
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=no
+  hardcode_into_libs=yes
+  ;;
+
+uts4*)
+  version_type=linux # correct to gnu/linux during the next big refactor
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  ;;
+
+*)
+  dynamic_linker=no
+  ;;
+esac
+AC_MSG_RESULT([$dynamic_linker])
+test "$dynamic_linker" = no && can_build_shared=no
+
+variables_saved_for_relink="PATH $shlibpath_var $runpath_var"
+if test "$GCC" = yes; then
+  variables_saved_for_relink="$variables_saved_for_relink GCC_EXEC_PREFIX COMPILER_PATH LIBRARY_PATH"
+fi
+
+if test "${lt_cv_sys_lib_search_path_spec+set}" = set; then
+  sys_lib_search_path_spec="$lt_cv_sys_lib_search_path_spec"
+fi
+if test "${lt_cv_sys_lib_dlsearch_path_spec+set}" = set; then
+  sys_lib_dlsearch_path_spec="$lt_cv_sys_lib_dlsearch_path_spec"
+fi
+
+_LT_DECL([], [variables_saved_for_relink], [1],
+    [Variables whose values should be saved in libtool wrapper scripts and
+    restored at link time])
+_LT_DECL([], [need_lib_prefix], [0],
+    [Do we need the "lib" prefix for modules?])
+_LT_DECL([], [need_version], [0], [Do we need a version for libraries?])
+_LT_DECL([], [version_type], [0], [Library versioning type])
+_LT_DECL([], [runpath_var], [0],  [Shared library runtime path variable])
+_LT_DECL([], [shlibpath_var], [0],[Shared library path variable])
+_LT_DECL([], [shlibpath_overrides_runpath], [0],
+    [Is shlibpath searched before the hard-coded library search path?])
+_LT_DECL([], [libname_spec], [1], [Format of library name prefix])
+_LT_DECL([], [library_names_spec], [1],
+    [[List of archive names.  First name is the real one, the rest are links.
+    The last name is the one that the linker finds with -lNAME]])
+_LT_DECL([], [soname_spec], [1],
+    [[The coded name of the library, if different from the real name]])
+_LT_DECL([], [install_override_mode], [1],
+    [Permission mode override for installation of shared libraries])
+_LT_DECL([], [postinstall_cmds], [2],
+    [Command to use after installation of a shared archive])
+_LT_DECL([], [postuninstall_cmds], [2],
+    [Command to use after uninstallation of a shared archive])
+_LT_DECL([], [finish_cmds], [2],
+    [Commands used to finish a libtool library installation in a directory])
+_LT_DECL([], [finish_eval], [1],
+    [[As "finish_cmds", except a single script fragment to be evaled but
+    not shown]])
+_LT_DECL([], [hardcode_into_libs], [0],
+    [Whether we should hardcode library paths into libraries])
+_LT_DECL([], [sys_lib_search_path_spec], [2],
+    [Compile-time system search path for libraries])
+_LT_DECL([], [sys_lib_dlsearch_path_spec], [2],
+    [Run-time system search path for libraries])
+])# _LT_SYS_DYNAMIC_LINKER
+
+
+# _LT_PATH_TOOL_PREFIX(TOOL)
+# --------------------------
+# find a file program which can recognize shared library
+AC_DEFUN([_LT_PATH_TOOL_PREFIX],
+[m4_require([_LT_DECL_EGREP])dnl
+AC_MSG_CHECKING([for $1])
+AC_CACHE_VAL(lt_cv_path_MAGIC_CMD,
+[case $MAGIC_CMD in
+[[\\/*] |  ?:[\\/]*])
+  lt_cv_path_MAGIC_CMD="$MAGIC_CMD" # Let the user override the test with a path.
+  ;;
+*)
+  lt_save_MAGIC_CMD="$MAGIC_CMD"
+  lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
+dnl $ac_dummy forces splitting on constant user-supplied paths.
+dnl POSIX.2 word splitting is done only on the output of word expansions,
+dnl not every word.  This closes a longstanding sh security hole.
+  ac_dummy="m4_if([$2], , $PATH, [$2])"
+  for ac_dir in $ac_dummy; do
+    IFS="$lt_save_ifs"
+    test -z "$ac_dir" && ac_dir=.
+    if test -f $ac_dir/$1; then
+      lt_cv_path_MAGIC_CMD="$ac_dir/$1"
+      if test -n "$file_magic_test_file"; then
+	case $deplibs_check_method in
+	"file_magic "*)
+	  file_magic_regex=`expr "$deplibs_check_method" : "file_magic \(.*\)"`
+	  MAGIC_CMD="$lt_cv_path_MAGIC_CMD"
+	  if eval $file_magic_cmd \$file_magic_test_file 2> /dev/null |
+	    $EGREP "$file_magic_regex" > /dev/null; then
+	    :
+	  else
+	    cat <<_LT_EOF 1>&2
+
+*** Warning: the command libtool uses to detect shared libraries,
+*** $file_magic_cmd, produces output that libtool cannot recognize.
+*** The result is that libtool may fail to recognize shared libraries
+*** as such.  This will affect the creation of libtool libraries that
+*** depend on shared libraries, but programs linked with such libtool
+*** libraries will work regardless of this problem.  Nevertheless, you
+*** may want to report the problem to your system manager and/or to
+*** bug-libtool@gnu.org
+
+_LT_EOF
+	  fi ;;
+	esac
+      fi
+      break
+    fi
+  done
+  IFS="$lt_save_ifs"
+  MAGIC_CMD="$lt_save_MAGIC_CMD"
+  ;;
+esac])
+MAGIC_CMD="$lt_cv_path_MAGIC_CMD"
+if test -n "$MAGIC_CMD"; then
+  AC_MSG_RESULT($MAGIC_CMD)
+else
+  AC_MSG_RESULT(no)
+fi
+_LT_DECL([], [MAGIC_CMD], [0],
+	 [Used to examine libraries when file_magic_cmd begins with "file"])dnl
+])# _LT_PATH_TOOL_PREFIX
+
+# Old name:
+AU_ALIAS([AC_PATH_TOOL_PREFIX], [_LT_PATH_TOOL_PREFIX])
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AC_PATH_TOOL_PREFIX], [])
+
+
+# _LT_PATH_MAGIC
+# --------------
+# find a file program which can recognize a shared library
+m4_defun([_LT_PATH_MAGIC],
+[_LT_PATH_TOOL_PREFIX(${ac_tool_prefix}file, /usr/bin$PATH_SEPARATOR$PATH)
+if test -z "$lt_cv_path_MAGIC_CMD"; then
+  if test -n "$ac_tool_prefix"; then
+    _LT_PATH_TOOL_PREFIX(file, /usr/bin$PATH_SEPARATOR$PATH)
+  else
+    MAGIC_CMD=:
+  fi
+fi
+])# _LT_PATH_MAGIC
+
+
+# LT_PATH_LD
+# ----------
+# find the pathname to the GNU or non-GNU linker
+AC_DEFUN([LT_PATH_LD],
+[AC_REQUIRE([AC_PROG_CC])dnl
+AC_REQUIRE([AC_CANONICAL_HOST])dnl
+AC_REQUIRE([AC_CANONICAL_BUILD])dnl
+m4_require([_LT_DECL_SED])dnl
+m4_require([_LT_DECL_EGREP])dnl
+m4_require([_LT_PROG_ECHO_BACKSLASH])dnl
+
+AC_ARG_WITH([gnu-ld],
+    [AS_HELP_STRING([--with-gnu-ld],
+	[assume the C compiler uses GNU ld @<:@default=no@:>@])],
+    [test "$withval" = no || with_gnu_ld=yes],
+    [with_gnu_ld=no])dnl
+
+ac_prog=ld
+if test "$GCC" = yes; then
+  # Check if gcc -print-prog-name=ld gives a path.
+  AC_MSG_CHECKING([for ld used by $CC])
+  case $host in
+  *-*-mingw*)
+    # gcc leaves a trailing carriage return which upsets mingw
+    ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;;
+  *)
+    ac_prog=`($CC -print-prog-name=ld) 2>&5` ;;
+  esac
+  case $ac_prog in
+    # Accept absolute paths.
+    [[\\/]]* | ?:[[\\/]]*)
+      re_direlt='/[[^/]][[^/]]*/\.\./'
+      # Canonicalize the pathname of ld
+      ac_prog=`$ECHO "$ac_prog"| $SED 's%\\\\%/%g'`
+      while $ECHO "$ac_prog" | $GREP "$re_direlt" > /dev/null 2>&1; do
+	ac_prog=`$ECHO $ac_prog| $SED "s%$re_direlt%/%"`
+      done
+      test -z "$LD" && LD="$ac_prog"
+      ;;
+  "")
+    # If it fails, then pretend we aren't using GCC.
+    ac_prog=ld
+    ;;
+  *)
+    # If it is relative, then search for the first ld in PATH.
+    with_gnu_ld=unknown
+    ;;
+  esac
+elif test "$with_gnu_ld" = yes; then
+  AC_MSG_CHECKING([for GNU ld])
+else
+  AC_MSG_CHECKING([for non-GNU ld])
+fi
+AC_CACHE_VAL(lt_cv_path_LD,
+[if test -z "$LD"; then
+  lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
+  for ac_dir in $PATH; do
+    IFS="$lt_save_ifs"
+    test -z "$ac_dir" && ac_dir=.
+    if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then
+      lt_cv_path_LD="$ac_dir/$ac_prog"
+      # Check to see if the program is GNU ld.  I'd rather use --version,
+      # but apparently some variants of GNU ld only accept -v.
+      # Break only if it was the GNU/non-GNU ld that we prefer.
+      case `"$lt_cv_path_LD" -v 2>&1 </dev/null` in
+      *GNU* | *'with BFD'*)
+	test "$with_gnu_ld" != no && break
+	;;
+      *)
+	test "$with_gnu_ld" != yes && break
+	;;
+      esac
+    fi
+  done
+  IFS="$lt_save_ifs"
+else
+  lt_cv_path_LD="$LD" # Let the user override the test with a path.
+fi])
+LD="$lt_cv_path_LD"
+if test -n "$LD"; then
+  AC_MSG_RESULT($LD)
+else
+  AC_MSG_RESULT(no)
+fi
+test -z "$LD" && AC_MSG_ERROR([no acceptable ld found in \$PATH])
+_LT_PATH_LD_GNU
+AC_SUBST([LD])
+
+_LT_TAGDECL([], [LD], [1], [The linker used to build libraries])
+])# LT_PATH_LD
+
+# Old names:
+AU_ALIAS([AM_PROG_LD], [LT_PATH_LD])
+AU_ALIAS([AC_PROG_LD], [LT_PATH_LD])
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AM_PROG_LD], [])
+dnl AC_DEFUN([AC_PROG_LD], [])
+
+
+# _LT_PATH_LD_GNU
+#- --------------
+m4_defun([_LT_PATH_LD_GNU],
+[AC_CACHE_CHECK([if the linker ($LD) is GNU ld], lt_cv_prog_gnu_ld,
+[# I'd rather use --version here, but apparently some GNU lds only accept -v.
+case `$LD -v 2>&1 </dev/null` in
+*GNU* | *'with BFD'*)
+  lt_cv_prog_gnu_ld=yes
+  ;;
+*)
+  lt_cv_prog_gnu_ld=no
+  ;;
+esac])
+with_gnu_ld=$lt_cv_prog_gnu_ld
+])# _LT_PATH_LD_GNU
+
+
+# _LT_CMD_RELOAD
+# --------------
+# find reload flag for linker
+#   -- PORTME Some linkers may need a different reload flag.
+m4_defun([_LT_CMD_RELOAD],
+[AC_CACHE_CHECK([for $LD option to reload object files],
+  lt_cv_ld_reload_flag,
+  [lt_cv_ld_reload_flag='-r'])
+reload_flag=$lt_cv_ld_reload_flag
+case $reload_flag in
+"" | " "*) ;;
+*) reload_flag=" $reload_flag" ;;
+esac
+reload_cmds='$LD$reload_flag -o $output$reload_objs'
+case $host_os in
+  cygwin* | mingw* | pw32* | cegcc*)
+    if test "$GCC" != yes; then
+      reload_cmds=false
+    fi
+    ;;
+  darwin*)
+    if test "$GCC" = yes; then
+      reload_cmds='$LTCC $LTCFLAGS -nostdlib ${wl}-r -o $output$reload_objs'
+    else
+      reload_cmds='$LD$reload_flag -o $output$reload_objs'
+    fi
+    ;;
+esac
+_LT_TAGDECL([], [reload_flag], [1], [How to create reloadable object files])dnl
+_LT_TAGDECL([], [reload_cmds], [2])dnl
+])# _LT_CMD_RELOAD
+
+
+# _LT_CHECK_MAGIC_METHOD
+# ----------------------
+# how to check for library dependencies
+#  -- PORTME fill in with the dynamic library characteristics
+m4_defun([_LT_CHECK_MAGIC_METHOD],
+[m4_require([_LT_DECL_EGREP])
+m4_require([_LT_DECL_OBJDUMP])
+AC_CACHE_CHECK([how to recognize dependent libraries],
+lt_cv_deplibs_check_method,
+[lt_cv_file_magic_cmd='$MAGIC_CMD'
+lt_cv_file_magic_test_file=
+lt_cv_deplibs_check_method='unknown'
+# Need to set the preceding variable on all platforms that support
+# interlibrary dependencies.
+# 'none' -- dependencies not supported.
+# `unknown' -- same as none, but documents that we really don't know.
+# 'pass_all' -- all dependencies passed with no checks.
+# 'test_compile' -- check by making test program.
+# 'file_magic [[regex]]' -- check by looking for files in library path
+# which responds to the $file_magic_cmd with a given extended regex.
+# If you have `file' or equivalent on your system and you're not sure
+# whether `pass_all' will *always* work, you probably want this one.
+
+case $host_os in
+aix[[4-9]]*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+beos*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+bsdi[[45]]*)
+  lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[ML]]SB (shared object|dynamic lib)'
+  lt_cv_file_magic_cmd='/usr/bin/file -L'
+  lt_cv_file_magic_test_file=/shlib/libc.so
+  ;;
+
+cygwin*)
+  # func_win32_libid is a shell function defined in ltmain.sh
+  lt_cv_deplibs_check_method='file_magic ^x86 archive import|^x86 DLL'
+  lt_cv_file_magic_cmd='func_win32_libid'
+  ;;
+
+mingw* | pw32*)
+  # Base MSYS/MinGW do not provide the 'file' command needed by
+  # func_win32_libid shell function, so use a weaker test based on 'objdump',
+  # unless we find 'file', for example because we are cross-compiling.
+  # func_win32_libid assumes BSD nm, so disallow it if using MS dumpbin.
+  if ( test "$lt_cv_nm_interface" = "BSD nm" && file / ) >/dev/null 2>&1; then
+    lt_cv_deplibs_check_method='file_magic ^x86 archive import|^x86 DLL'
+    lt_cv_file_magic_cmd='func_win32_libid'
+  else
+    # Keep this pattern in sync with the one in func_win32_libid.
+    lt_cv_deplibs_check_method='file_magic file format (pei*-i386(.*architecture: i386)?|pe-arm-wince|pe-x86-64)'
+    lt_cv_file_magic_cmd='$OBJDUMP -f'
+  fi
+  ;;
+
+cegcc*)
+  # use the weaker test based on 'objdump'. See mingw*.
+  lt_cv_deplibs_check_method='file_magic file format pe-arm-.*little(.*architecture: arm)?'
+  lt_cv_file_magic_cmd='$OBJDUMP -f'
+  ;;
+
+darwin* | rhapsody*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+freebsd* | dragonfly*)
+  if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then
+    case $host_cpu in
+    i*86 )
+      # Not sure whether the presence of OpenBSD here was a mistake.
+      # Let's accept both of them until this is cleared up.
+      lt_cv_deplibs_check_method='file_magic (FreeBSD|OpenBSD|DragonFly)/i[[3-9]]86 (compact )?demand paged shared library'
+      lt_cv_file_magic_cmd=/usr/bin/file
+      lt_cv_file_magic_test_file=`echo /usr/lib/libc.so.*`
+      ;;
+    esac
+  else
+    lt_cv_deplibs_check_method=pass_all
+  fi
+  ;;
+
+haiku*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+hpux10.20* | hpux11*)
+  lt_cv_file_magic_cmd=/usr/bin/file
+  case $host_cpu in
+  ia64*)
+    lt_cv_deplibs_check_method='file_magic (s[[0-9]][[0-9]][[0-9]]|ELF-[[0-9]][[0-9]]) shared object file - IA64'
+    lt_cv_file_magic_test_file=/usr/lib/hpux32/libc.so
+    ;;
+  hppa*64*)
+    [lt_cv_deplibs_check_method='file_magic (s[0-9][0-9][0-9]|ELF[ -][0-9][0-9])(-bit)?( [LM]SB)? shared object( file)?[, -]* PA-RISC [0-9]\.[0-9]']
+    lt_cv_file_magic_test_file=/usr/lib/pa20_64/libc.sl
+    ;;
+  *)
+    lt_cv_deplibs_check_method='file_magic (s[[0-9]][[0-9]][[0-9]]|PA-RISC[[0-9]]\.[[0-9]]) shared library'
+    lt_cv_file_magic_test_file=/usr/lib/libc.sl
+    ;;
+  esac
+  ;;
+
+interix[[3-9]]*)
+  # PIC code is broken on Interix 3.x, that's why |\.a not |_pic\.a here
+  lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so|\.a)$'
+  ;;
+
+irix5* | irix6* | nonstopux*)
+  case $LD in
+  *-32|*"-32 ") libmagic=32-bit;;
+  *-n32|*"-n32 ") libmagic=N32;;
+  *-64|*"-64 ") libmagic=64-bit;;
+  *) libmagic=never-match;;
+  esac
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+# This must be glibc/ELF.
+linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+netbsd* | netbsdelf*-gnu)
+  if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then
+    lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|_pic\.a)$'
+  else
+    lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so|_pic\.a)$'
+  fi
+  ;;
+
+newos6*)
+  lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[ML]]SB (executable|dynamic lib)'
+  lt_cv_file_magic_cmd=/usr/bin/file
+  lt_cv_file_magic_test_file=/usr/lib/libnls.so
+  ;;
+
+*nto* | *qnx*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+openbsd*)
+  if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then
+    lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|\.so|_pic\.a)$'
+  else
+    lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|_pic\.a)$'
+  fi
+  ;;
+
+osf3* | osf4* | osf5*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+rdos*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+solaris*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+sysv4 | sysv4.3*)
+  case $host_vendor in
+  motorola)
+    lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[ML]]SB (shared object|dynamic lib) M[[0-9]][[0-9]]* Version [[0-9]]'
+    lt_cv_file_magic_test_file=`echo /usr/lib/libc.so*`
+    ;;
+  ncr)
+    lt_cv_deplibs_check_method=pass_all
+    ;;
+  sequent)
+    lt_cv_file_magic_cmd='/bin/file'
+    lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[LM]]SB (shared object|dynamic lib )'
+    ;;
+  sni)
+    lt_cv_file_magic_cmd='/bin/file'
+    lt_cv_deplibs_check_method="file_magic ELF [[0-9]][[0-9]]*-bit [[LM]]SB dynamic lib"
+    lt_cv_file_magic_test_file=/lib/libc.so
+    ;;
+  siemens)
+    lt_cv_deplibs_check_method=pass_all
+    ;;
+  pc)
+    lt_cv_deplibs_check_method=pass_all
+    ;;
+  esac
+  ;;
+
+tpf*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+esac
+])
+
+file_magic_glob=
+want_nocaseglob=no
+if test "$build" = "$host"; then
+  case $host_os in
+  mingw* | pw32*)
+    if ( shopt | grep nocaseglob ) >/dev/null 2>&1; then
+      want_nocaseglob=yes
+    else
+      file_magic_glob=`echo aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ | $SED -e "s/\(..\)/s\/[[\1]]\/[[\1]]\/g;/g"`
+    fi
+    ;;
+  esac
+fi
+
+file_magic_cmd=$lt_cv_file_magic_cmd
+deplibs_check_method=$lt_cv_deplibs_check_method
+test -z "$deplibs_check_method" && deplibs_check_method=unknown
+
+_LT_DECL([], [deplibs_check_method], [1],
+    [Method to check whether dependent libraries are shared objects])
+_LT_DECL([], [file_magic_cmd], [1],
+    [Command to use when deplibs_check_method = "file_magic"])
+_LT_DECL([], [file_magic_glob], [1],
+    [How to find potential files when deplibs_check_method = "file_magic"])
+_LT_DECL([], [want_nocaseglob], [1],
+    [Find potential files using nocaseglob when deplibs_check_method = "file_magic"])
+])# _LT_CHECK_MAGIC_METHOD
+
+
+# LT_PATH_NM
+# ----------
+# find the pathname to a BSD- or MS-compatible name lister
+AC_DEFUN([LT_PATH_NM],
+[AC_REQUIRE([AC_PROG_CC])dnl
+AC_CACHE_CHECK([for BSD- or MS-compatible name lister (nm)], lt_cv_path_NM,
+[if test -n "$NM"; then
+  # Let the user override the test.
+  lt_cv_path_NM="$NM"
+else
+  lt_nm_to_check="${ac_tool_prefix}nm"
+  if test -n "$ac_tool_prefix" && test "$build" = "$host"; then
+    lt_nm_to_check="$lt_nm_to_check nm"
+  fi
+  for lt_tmp_nm in $lt_nm_to_check; do
+    lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
+    for ac_dir in $PATH /usr/ccs/bin/elf /usr/ccs/bin /usr/ucb /bin; do
+      IFS="$lt_save_ifs"
+      test -z "$ac_dir" && ac_dir=.
+      tmp_nm="$ac_dir/$lt_tmp_nm"
+      if test -f "$tmp_nm" || test -f "$tmp_nm$ac_exeext" ; then
+	# Check to see if the nm accepts a BSD-compat flag.
+	# Adding the `sed 1q' prevents false positives on HP-UX, which says:
+	#   nm: unknown option "B" ignored
+	# Tru64's nm complains that /dev/null is an invalid object file
+	case `"$tmp_nm" -B /dev/null 2>&1 | sed '1q'` in
+	*/dev/null* | *'Invalid file or object type'*)
+	  lt_cv_path_NM="$tmp_nm -B"
+	  break
+	  ;;
+	*)
+	  case `"$tmp_nm" -p /dev/null 2>&1 | sed '1q'` in
+	  */dev/null*)
+	    lt_cv_path_NM="$tmp_nm -p"
+	    break
+	    ;;
+	  *)
+	    lt_cv_path_NM=${lt_cv_path_NM="$tmp_nm"} # keep the first match, but
+	    continue # so that we can try to find one that supports BSD flags
+	    ;;
+	  esac
+	  ;;
+	esac
+      fi
+    done
+    IFS="$lt_save_ifs"
+  done
+  : ${lt_cv_path_NM=no}
+fi])
+if test "$lt_cv_path_NM" != "no"; then
+  NM="$lt_cv_path_NM"
+else
+  # Didn't find any BSD compatible name lister, look for dumpbin.
+  if test -n "$DUMPBIN"; then :
+    # Let the user override the test.
+  else
+    AC_CHECK_TOOLS(DUMPBIN, [dumpbin "link -dump"], :)
+    case `$DUMPBIN -symbols /dev/null 2>&1 | sed '1q'` in
+    *COFF*)
+      DUMPBIN="$DUMPBIN -symbols"
+      ;;
+    *)
+      DUMPBIN=:
+      ;;
+    esac
+  fi
+  AC_SUBST([DUMPBIN])
+  if test "$DUMPBIN" != ":"; then
+    NM="$DUMPBIN"
+  fi
+fi
+test -z "$NM" && NM=nm
+AC_SUBST([NM])
+_LT_DECL([], [NM], [1], [A BSD- or MS-compatible name lister])dnl
+
+AC_CACHE_CHECK([the name lister ($NM) interface], [lt_cv_nm_interface],
+  [lt_cv_nm_interface="BSD nm"
+  echo "int some_variable = 0;" > conftest.$ac_ext
+  (eval echo "\"\$as_me:$LINENO: $ac_compile\"" >&AS_MESSAGE_LOG_FD)
+  (eval "$ac_compile" 2>conftest.err)
+  cat conftest.err >&AS_MESSAGE_LOG_FD
+  (eval echo "\"\$as_me:$LINENO: $NM \\\"conftest.$ac_objext\\\"\"" >&AS_MESSAGE_LOG_FD)
+  (eval "$NM \"conftest.$ac_objext\"" 2>conftest.err > conftest.out)
+  cat conftest.err >&AS_MESSAGE_LOG_FD
+  (eval echo "\"\$as_me:$LINENO: output\"" >&AS_MESSAGE_LOG_FD)
+  cat conftest.out >&AS_MESSAGE_LOG_FD
+  if $GREP 'External.*some_variable' conftest.out > /dev/null; then
+    lt_cv_nm_interface="MS dumpbin"
+  fi
+  rm -f conftest*])
+])# LT_PATH_NM
+
+# Old names:
+AU_ALIAS([AM_PROG_NM], [LT_PATH_NM])
+AU_ALIAS([AC_PROG_NM], [LT_PATH_NM])
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AM_PROG_NM], [])
+dnl AC_DEFUN([AC_PROG_NM], [])
+
+# _LT_CHECK_SHAREDLIB_FROM_LINKLIB
+# --------------------------------
+# how to determine the name of the shared library
+# associated with a specific link library.
+#  -- PORTME fill in with the dynamic library characteristics
+m4_defun([_LT_CHECK_SHAREDLIB_FROM_LINKLIB],
+[m4_require([_LT_DECL_EGREP])
+m4_require([_LT_DECL_OBJDUMP])
+m4_require([_LT_DECL_DLLTOOL])
+AC_CACHE_CHECK([how to associate runtime and link libraries],
+lt_cv_sharedlib_from_linklib_cmd,
+[lt_cv_sharedlib_from_linklib_cmd='unknown'
+
+case $host_os in
+cygwin* | mingw* | pw32* | cegcc*)
+  # two different shell functions defined in ltmain.sh
+  # decide which to use based on capabilities of $DLLTOOL
+  case `$DLLTOOL --help 2>&1` in
+  *--identify-strict*)
+    lt_cv_sharedlib_from_linklib_cmd=func_cygming_dll_for_implib
+    ;;
+  *)
+    lt_cv_sharedlib_from_linklib_cmd=func_cygming_dll_for_implib_fallback
+    ;;
+  esac
+  ;;
+*)
+  # fallback: assume linklib IS sharedlib
+  lt_cv_sharedlib_from_linklib_cmd="$ECHO"
+  ;;
+esac
+])
+sharedlib_from_linklib_cmd=$lt_cv_sharedlib_from_linklib_cmd
+test -z "$sharedlib_from_linklib_cmd" && sharedlib_from_linklib_cmd=$ECHO
+
+_LT_DECL([], [sharedlib_from_linklib_cmd], [1],
+    [Command to associate shared and link libraries])
+])# _LT_CHECK_SHAREDLIB_FROM_LINKLIB
+
+
+# _LT_PATH_MANIFEST_TOOL
+# ----------------------
+# locate the manifest tool
+m4_defun([_LT_PATH_MANIFEST_TOOL],
+[AC_CHECK_TOOL(MANIFEST_TOOL, mt, :)
+test -z "$MANIFEST_TOOL" && MANIFEST_TOOL=mt
+AC_CACHE_CHECK([if $MANIFEST_TOOL is a manifest tool], [lt_cv_path_mainfest_tool],
+  [lt_cv_path_mainfest_tool=no
+  echo "$as_me:$LINENO: $MANIFEST_TOOL '-?'" >&AS_MESSAGE_LOG_FD
+  $MANIFEST_TOOL '-?' 2>conftest.err > conftest.out
+  cat conftest.err >&AS_MESSAGE_LOG_FD
+  if $GREP 'Manifest Tool' conftest.out > /dev/null; then
+    lt_cv_path_mainfest_tool=yes
+  fi
+  rm -f conftest*])
+if test "x$lt_cv_path_mainfest_tool" != xyes; then
+  MANIFEST_TOOL=:
+fi
+_LT_DECL([], [MANIFEST_TOOL], [1], [Manifest tool])dnl
+])# _LT_PATH_MANIFEST_TOOL
+
+
+# LT_LIB_M
+# --------
+# check for math library
+AC_DEFUN([LT_LIB_M],
+[AC_REQUIRE([AC_CANONICAL_HOST])dnl
+LIBM=
+case $host in
+*-*-beos* | *-*-cegcc* | *-*-cygwin* | *-*-haiku* | *-*-pw32* | *-*-darwin*)
+  # These system don't have libm, or don't need it
+  ;;
+*-ncr-sysv4.3*)
+  AC_CHECK_LIB(mw, _mwvalidcheckl, LIBM="-lmw")
+  AC_CHECK_LIB(m, cos, LIBM="$LIBM -lm")
+  ;;
+*)
+  AC_CHECK_LIB(m, cos, LIBM="-lm")
+  ;;
+esac
+AC_SUBST([LIBM])
+])# LT_LIB_M
+
+# Old name:
+AU_ALIAS([AC_CHECK_LIBM], [LT_LIB_M])
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AC_CHECK_LIBM], [])
+
+
+# _LT_COMPILER_NO_RTTI([TAGNAME])
+# -------------------------------
+m4_defun([_LT_COMPILER_NO_RTTI],
+[m4_require([_LT_TAG_COMPILER])dnl
+
+_LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)=
+
+if test "$GCC" = yes; then
+  case $cc_basename in
+  nvcc*)
+    _LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)=' -Xcompiler -fno-builtin' ;;
+  *)
+    _LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)=' -fno-builtin' ;;
+  esac
+
+  _LT_COMPILER_OPTION([if $compiler supports -fno-rtti -fno-exceptions],
+    lt_cv_prog_compiler_rtti_exceptions,
+    [-fno-rtti -fno-exceptions], [],
+    [_LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)="$_LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1) -fno-rtti -fno-exceptions"])
+fi
+_LT_TAGDECL([no_builtin_flag], [lt_prog_compiler_no_builtin_flag], [1],
+	[Compiler flag to turn off builtin functions])
+])# _LT_COMPILER_NO_RTTI
+
+
+# _LT_CMD_GLOBAL_SYMBOLS
+# ----------------------
+m4_defun([_LT_CMD_GLOBAL_SYMBOLS],
+[AC_REQUIRE([AC_CANONICAL_HOST])dnl
+AC_REQUIRE([AC_PROG_CC])dnl
+AC_REQUIRE([AC_PROG_AWK])dnl
+AC_REQUIRE([LT_PATH_NM])dnl
+AC_REQUIRE([LT_PATH_LD])dnl
+m4_require([_LT_DECL_SED])dnl
+m4_require([_LT_DECL_EGREP])dnl
+m4_require([_LT_TAG_COMPILER])dnl
+
+# Check for command to grab the raw symbol name followed by C symbol from nm.
+AC_MSG_CHECKING([command to parse $NM output from $compiler object])
+AC_CACHE_VAL([lt_cv_sys_global_symbol_pipe],
+[
+# These are sane defaults that work on at least a few old systems.
+# [They come from Ultrix.  What could be older than Ultrix?!! ;)]
+
+# Character class describing NM global symbol codes.
+symcode='[[BCDEGRST]]'
+
+# Regexp to match symbols that can be accessed directly from C.
+sympat='\([[_A-Za-z]][[_A-Za-z0-9]]*\)'
+
+# Define system-specific variables.
+case $host_os in
+aix*)
+  symcode='[[BCDT]]'
+  ;;
+cygwin* | mingw* | pw32* | cegcc*)
+  symcode='[[ABCDGISTW]]'
+  ;;
+hpux*)
+  if test "$host_cpu" = ia64; then
+    symcode='[[ABCDEGRST]]'
+  fi
+  ;;
+irix* | nonstopux*)
+  symcode='[[BCDEGRST]]'
+  ;;
+osf*)
+  symcode='[[BCDEGQRST]]'
+  ;;
+solaris*)
+  symcode='[[BDRT]]'
+  ;;
+sco3.2v5*)
+  symcode='[[DT]]'
+  ;;
+sysv4.2uw2*)
+  symcode='[[DT]]'
+  ;;
+sysv5* | sco5v6* | unixware* | OpenUNIX*)
+  symcode='[[ABDT]]'
+  ;;
+sysv4)
+  symcode='[[DFNSTU]]'
+  ;;
+esac
+
+# If we're using GNU nm, then use its standard symbol codes.
+case `$NM -V 2>&1` in
+*GNU* | *'with BFD'*)
+  symcode='[[ABCDGIRSTW]]' ;;
+esac
+
+# Transform an extracted symbol line into a proper C declaration.
+# Some systems (esp. on ia64) link data and code symbols differently,
+# so use this general approach.
+lt_cv_sys_global_symbol_to_cdecl="sed -n -e 's/^T .* \(.*\)$/extern int \1();/p' -e 's/^$symcode* .* \(.*\)$/extern char \1;/p'"
+
+# Transform an extracted symbol line into symbol name and symbol address
+lt_cv_sys_global_symbol_to_c_name_address="sed -n -e 's/^: \([[^ ]]*\)[[ ]]*$/  {\\\"\1\\\", (void *) 0},/p' -e 's/^$symcode* \([[^ ]]*\) \([[^ ]]*\)$/  {\"\2\", (void *) \&\2},/p'"
+lt_cv_sys_global_symbol_to_c_name_address_lib_prefix="sed -n -e 's/^: \([[^ ]]*\)[[ ]]*$/  {\\\"\1\\\", (void *) 0},/p' -e 's/^$symcode* \([[^ ]]*\) \(lib[[^ ]]*\)$/  {\"\2\", (void *) \&\2},/p' -e 's/^$symcode* \([[^ ]]*\) \([[^ ]]*\)$/  {\"lib\2\", (void *) \&\2},/p'"
+
+# Handle CRLF in mingw tool chain
+opt_cr=
+case $build_os in
+mingw*)
+  opt_cr=`$ECHO 'x\{0,1\}' | tr x '\015'` # option cr in regexp
+  ;;
+esac
+
+# Try without a prefix underscore, then with it.
+for ac_symprfx in "" "_"; do
+
+  # Transform symcode, sympat, and symprfx into a raw symbol and a C symbol.
+  symxfrm="\\1 $ac_symprfx\\2 \\2"
+
+  # Write the raw and C identifiers.
+  if test "$lt_cv_nm_interface" = "MS dumpbin"; then
+    # Fake it for dumpbin and say T for any non-static function
+    # and D for any global variable.
+    # Also find C++ and __fastcall symbols from MSVC++,
+    # which start with @ or ?.
+    lt_cv_sys_global_symbol_pipe="$AWK ['"\
+"     {last_section=section; section=\$ 3};"\
+"     /^COFF SYMBOL TABLE/{for(i in hide) delete hide[i]};"\
+"     /Section length .*#relocs.*(pick any)/{hide[last_section]=1};"\
+"     \$ 0!~/External *\|/{next};"\
+"     / 0+ UNDEF /{next}; / UNDEF \([^|]\)*()/{next};"\
+"     {if(hide[section]) next};"\
+"     {f=0}; \$ 0~/\(\).*\|/{f=1}; {printf f ? \"T \" : \"D \"};"\
+"     {split(\$ 0, a, /\||\r/); split(a[2], s)};"\
+"     s[1]~/^[@?]/{print s[1], s[1]; next};"\
+"     s[1]~prfx {split(s[1],t,\"@\"); print t[1], substr(t[1],length(prfx))}"\
+"     ' prfx=^$ac_symprfx]"
+  else
+    lt_cv_sys_global_symbol_pipe="sed -n -e 's/^.*[[	 ]]\($symcode$symcode*\)[[	 ]][[	 ]]*$ac_symprfx$sympat$opt_cr$/$symxfrm/p'"
+  fi
+  lt_cv_sys_global_symbol_pipe="$lt_cv_sys_global_symbol_pipe | sed '/ __gnu_lto/d'"
+
+  # Check to see that the pipe works correctly.
+  pipe_works=no
+
+  rm -f conftest*
+  cat > conftest.$ac_ext <<_LT_EOF
+#ifdef __cplusplus
+extern "C" {
+#endif
+char nm_test_var;
+void nm_test_func(void);
+void nm_test_func(void){}
+#ifdef __cplusplus
+}
+#endif
+int main(){nm_test_var='a';nm_test_func();return(0);}
+_LT_EOF
+
+  if AC_TRY_EVAL(ac_compile); then
+    # Now try to grab the symbols.
+    nlist=conftest.nm
+    if AC_TRY_EVAL(NM conftest.$ac_objext \| "$lt_cv_sys_global_symbol_pipe" \> $nlist) && test -s "$nlist"; then
+      # Try sorting and uniquifying the output.
+      if sort "$nlist" | uniq > "$nlist"T; then
+	mv -f "$nlist"T "$nlist"
+      else
+	rm -f "$nlist"T
+      fi
+
+      # Make sure that we snagged all the symbols we need.
+      if $GREP ' nm_test_var$' "$nlist" >/dev/null; then
+	if $GREP ' nm_test_func$' "$nlist" >/dev/null; then
+	  cat <<_LT_EOF > conftest.$ac_ext
+/* Keep this code in sync between libtool.m4, ltmain, lt_system.h, and tests.  */
+#if defined(_WIN32) || defined(__CYGWIN__) || defined(_WIN32_WCE)
+/* DATA imports from DLLs on WIN32 con't be const, because runtime
+   relocations are performed -- see ld's documentation on pseudo-relocs.  */
+# define LT@&t@_DLSYM_CONST
+#elif defined(__osf__)
+/* This system does not cope well with relocations in const data.  */
+# define LT@&t@_DLSYM_CONST
+#else
+# define LT@&t@_DLSYM_CONST const
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+_LT_EOF
+	  # Now generate the symbol file.
+	  eval "$lt_cv_sys_global_symbol_to_cdecl"' < "$nlist" | $GREP -v main >> conftest.$ac_ext'
+
+	  cat <<_LT_EOF >> conftest.$ac_ext
+
+/* The mapping between symbol names and symbols.  */
+LT@&t@_DLSYM_CONST struct {
+  const char *name;
+  void       *address;
+}
+lt__PROGRAM__LTX_preloaded_symbols[[]] =
+{
+  { "@PROGRAM@", (void *) 0 },
+_LT_EOF
+	  $SED "s/^$symcode$symcode* \(.*\) \(.*\)$/  {\"\2\", (void *) \&\2},/" < "$nlist" | $GREP -v main >> conftest.$ac_ext
+	  cat <<\_LT_EOF >> conftest.$ac_ext
+  {0, (void *) 0}
+};
+
+/* This works around a problem in FreeBSD linker */
+#ifdef FREEBSD_WORKAROUND
+static const void *lt_preloaded_setup() {
+  return lt__PROGRAM__LTX_preloaded_symbols;
+}
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+_LT_EOF
+	  # Now try linking the two files.
+	  mv conftest.$ac_objext conftstm.$ac_objext
+	  lt_globsym_save_LIBS=$LIBS
+	  lt_globsym_save_CFLAGS=$CFLAGS
+	  LIBS="conftstm.$ac_objext"
+	  CFLAGS="$CFLAGS$_LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)"
+	  if AC_TRY_EVAL(ac_link) && test -s conftest${ac_exeext}; then
+	    pipe_works=yes
+	  fi
+	  LIBS=$lt_globsym_save_LIBS
+	  CFLAGS=$lt_globsym_save_CFLAGS
+	else
+	  echo "cannot find nm_test_func in $nlist" >&AS_MESSAGE_LOG_FD
+	fi
+      else
+	echo "cannot find nm_test_var in $nlist" >&AS_MESSAGE_LOG_FD
+      fi
+    else
+      echo "cannot run $lt_cv_sys_global_symbol_pipe" >&AS_MESSAGE_LOG_FD
+    fi
+  else
+    echo "$progname: failed program was:" >&AS_MESSAGE_LOG_FD
+    cat conftest.$ac_ext >&5
+  fi
+  rm -rf conftest* conftst*
+
+  # Do not use the global_symbol_pipe unless it works.
+  if test "$pipe_works" = yes; then
+    break
+  else
+    lt_cv_sys_global_symbol_pipe=
+  fi
+done
+])
+if test -z "$lt_cv_sys_global_symbol_pipe"; then
+  lt_cv_sys_global_symbol_to_cdecl=
+fi
+if test -z "$lt_cv_sys_global_symbol_pipe$lt_cv_sys_global_symbol_to_cdecl"; then
+  AC_MSG_RESULT(failed)
+else
+  AC_MSG_RESULT(ok)
+fi
+
+# Response file support.
+if test "$lt_cv_nm_interface" = "MS dumpbin"; then
+  nm_file_list_spec='@'
+elif $NM --help 2>/dev/null | grep '[[@]]FILE' >/dev/null; then
+  nm_file_list_spec='@'
+fi
+
+_LT_DECL([global_symbol_pipe], [lt_cv_sys_global_symbol_pipe], [1],
+    [Take the output of nm and produce a listing of raw symbols and C names])
+_LT_DECL([global_symbol_to_cdecl], [lt_cv_sys_global_symbol_to_cdecl], [1],
+    [Transform the output of nm in a proper C declaration])
+_LT_DECL([global_symbol_to_c_name_address],
+    [lt_cv_sys_global_symbol_to_c_name_address], [1],
+    [Transform the output of nm in a C name address pair])
+_LT_DECL([global_symbol_to_c_name_address_lib_prefix],
+    [lt_cv_sys_global_symbol_to_c_name_address_lib_prefix], [1],
+    [Transform the output of nm in a C name address pair when lib prefix is needed])
+_LT_DECL([], [nm_file_list_spec], [1],
+    [Specify filename containing input files for $NM])
+]) # _LT_CMD_GLOBAL_SYMBOLS
+
+
+# _LT_COMPILER_PIC([TAGNAME])
+# ---------------------------
+m4_defun([_LT_COMPILER_PIC],
+[m4_require([_LT_TAG_COMPILER])dnl
+_LT_TAGVAR(lt_prog_compiler_wl, $1)=
+_LT_TAGVAR(lt_prog_compiler_pic, $1)=
+_LT_TAGVAR(lt_prog_compiler_static, $1)=
+
+m4_if([$1], [CXX], [
+  # C++ specific cases for pic, static, wl, etc.
+  if test "$GXX" = yes; then
+    _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+    _LT_TAGVAR(lt_prog_compiler_static, $1)='-static'
+
+    case $host_os in
+    aix*)
+      # All AIX code is PIC.
+      if test "$host_cpu" = ia64; then
+	# AIX 5 now supports IA64 processor
+	_LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+      fi
+      ;;
+
+    amigaos*)
+      case $host_cpu in
+      powerpc)
+            # see comment about AmigaOS4 .so support
+            _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
+        ;;
+      m68k)
+            # FIXME: we need at least 68020 code to build shared libraries, but
+            # adding the `-m68020' flag to GCC prevents building anything better,
+            # like `-m68040'.
+            _LT_TAGVAR(lt_prog_compiler_pic, $1)='-m68020 -resident32 -malways-restore-a4'
+        ;;
+      esac
+      ;;
+
+    beos* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*)
+      # PIC is the default for these OSes.
+      ;;
+    mingw* | cygwin* | os2* | pw32* | cegcc*)
+      # This hack is so that the source file can tell whether it is being
+      # built for inclusion in a dll (and should export symbols for example).
+      # Although the cygwin gcc ignores -fPIC, still need this for old-style
+      # (--disable-auto-import) libraries
+      m4_if([$1], [GCJ], [],
+	[_LT_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT'])
+      ;;
+    darwin* | rhapsody*)
+      # PIC is the default on this platform
+      # Common symbols not allowed in MH_DYLIB files
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fno-common'
+      ;;
+    *djgpp*)
+      # DJGPP does not support shared libraries at all
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)=
+      ;;
+    haiku*)
+      # PIC is the default for Haiku.
+      # The "-static" flag exists, but is broken.
+      _LT_TAGVAR(lt_prog_compiler_static, $1)=
+      ;;
+    interix[[3-9]]*)
+      # Interix 3.x gcc -fpic/-fPIC options generate broken code.
+      # Instead, we relocate shared libraries at runtime.
+      ;;
+    sysv4*MP*)
+      if test -d /usr/nec; then
+	_LT_TAGVAR(lt_prog_compiler_pic, $1)=-Kconform_pic
+      fi
+      ;;
+    hpux*)
+      # PIC is the default for 64-bit PA HP-UX, but not for 32-bit
+      # PA HP-UX.  On IA64 HP-UX, PIC is the default but the pic flag
+      # sets the default TLS model and affects inlining.
+      case $host_cpu in
+      hppa*64*)
+	;;
+      *)
+	_LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
+	;;
+      esac
+      ;;
+    *qnx* | *nto*)
+      # QNX uses GNU C++, but need to define -shared option too, otherwise
+      # it will coredump.
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC -shared'
+      ;;
+    *)
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
+      ;;
+    esac
+  else
+    case $host_os in
+      aix[[4-9]]*)
+	# All AIX code is PIC.
+	if test "$host_cpu" = ia64; then
+	  # AIX 5 now supports IA64 processor
+	  _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+	else
+	  _LT_TAGVAR(lt_prog_compiler_static, $1)='-bnso -bI:/lib/syscalls.exp'
+	fi
+	;;
+      chorus*)
+	case $cc_basename in
+	cxch68*)
+	  # Green Hills C++ Compiler
+	  # _LT_TAGVAR(lt_prog_compiler_static, $1)="--no_auto_instantiation -u __main -u __premain -u _abort -r $COOL_DIR/lib/libOrb.a $MVME_DIR/lib/CC/libC.a $MVME_DIR/lib/classix/libcx.s.a"
+	  ;;
+	esac
+	;;
+      mingw* | cygwin* | os2* | pw32* | cegcc*)
+	# This hack is so that the source file can tell whether it is being
+	# built for inclusion in a dll (and should export symbols for example).
+	m4_if([$1], [GCJ], [],
+	  [_LT_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT'])
+	;;
+      dgux*)
+	case $cc_basename in
+	  ec++*)
+	    _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+	    ;;
+	  ghcx*)
+	    # Green Hills C++ Compiler
+	    _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic'
+	    ;;
+	  *)
+	    ;;
+	esac
+	;;
+      freebsd* | dragonfly*)
+	# FreeBSD uses GNU C++
+	;;
+      hpux9* | hpux10* | hpux11*)
+	case $cc_basename in
+	  CC*)
+	    _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+	    _LT_TAGVAR(lt_prog_compiler_static, $1)='${wl}-a ${wl}archive'
+	    if test "$host_cpu" != ia64; then
+	      _LT_TAGVAR(lt_prog_compiler_pic, $1)='+Z'
+	    fi
+	    ;;
+	  aCC*)
+	    _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+	    _LT_TAGVAR(lt_prog_compiler_static, $1)='${wl}-a ${wl}archive'
+	    case $host_cpu in
+	    hppa*64*|ia64*)
+	      # +Z the default
+	      ;;
+	    *)
+	      _LT_TAGVAR(lt_prog_compiler_pic, $1)='+Z'
+	      ;;
+	    esac
+	    ;;
+	  *)
+	    ;;
+	esac
+	;;
+      interix*)
+	# This is c89, which is MS Visual C++ (no shared libs)
+	# Anyone wants to do a port?
+	;;
+      irix5* | irix6* | nonstopux*)
+	case $cc_basename in
+	  CC*)
+	    _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+	    _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared'
+	    # CC pic flag -KPIC is the default.
+	    ;;
+	  *)
+	    ;;
+	esac
+	;;
+      linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*)
+	case $cc_basename in
+	  KCC*)
+	    # KAI C++ Compiler
+	    _LT_TAGVAR(lt_prog_compiler_wl, $1)='--backend -Wl,'
+	    _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
+	    ;;
+	  ecpc* )
+	    # old Intel C++ for x86_64 which still supported -KPIC.
+	    _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+	    _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+	    _LT_TAGVAR(lt_prog_compiler_static, $1)='-static'
+	    ;;
+	  icpc* )
+	    # Intel C++, used to be incompatible with GCC.
+	    # ICC 10 doesn't accept -KPIC any more.
+	    _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+	    _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
+	    _LT_TAGVAR(lt_prog_compiler_static, $1)='-static'
+	    ;;
+	  pgCC* | pgcpp*)
+	    # Portland Group C++ compiler
+	    _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+	    _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fpic'
+	    _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+	    ;;
+	  cxx*)
+	    # Compaq C++
+	    # Make sure the PIC flag is empty.  It appears that all Alpha
+	    # Linux and Compaq Tru64 Unix objects are PIC.
+	    _LT_TAGVAR(lt_prog_compiler_pic, $1)=
+	    _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared'
+	    ;;
+	  xlc* | xlC* | bgxl[[cC]]* | mpixl[[cC]]*)
+	    # IBM XL 8.0, 9.0 on PPC and BlueGene
+	    _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+	    _LT_TAGVAR(lt_prog_compiler_pic, $1)='-qpic'
+	    _LT_TAGVAR(lt_prog_compiler_static, $1)='-qstaticlink'
+	    ;;
+	  *)
+	    case `$CC -V 2>&1 | sed 5q` in
+	    *Sun\ C*)
+	      # Sun C++ 5.9
+	      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+	      _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+	      _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld '
+	      ;;
+	    esac
+	    ;;
+	esac
+	;;
+      lynxos*)
+	;;
+      m88k*)
+	;;
+      mvs*)
+	case $cc_basename in
+	  cxx*)
+	    _LT_TAGVAR(lt_prog_compiler_pic, $1)='-W c,exportall'
+	    ;;
+	  *)
+	    ;;
+	esac
+	;;
+      netbsd* | netbsdelf*-gnu)
+	;;
+      *qnx* | *nto*)
+        # QNX uses GNU C++, but need to define -shared option too, otherwise
+        # it will coredump.
+        _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC -shared'
+        ;;
+      osf3* | osf4* | osf5*)
+	case $cc_basename in
+	  KCC*)
+	    _LT_TAGVAR(lt_prog_compiler_wl, $1)='--backend -Wl,'
+	    ;;
+	  RCC*)
+	    # Rational C++ 2.4.1
+	    _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic'
+	    ;;
+	  cxx*)
+	    # Digital/Compaq C++
+	    _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+	    # Make sure the PIC flag is empty.  It appears that all Alpha
+	    # Linux and Compaq Tru64 Unix objects are PIC.
+	    _LT_TAGVAR(lt_prog_compiler_pic, $1)=
+	    _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared'
+	    ;;
+	  *)
+	    ;;
+	esac
+	;;
+      psos*)
+	;;
+      solaris*)
+	case $cc_basename in
+	  CC* | sunCC*)
+	    # Sun C++ 4.2, 5.x and Centerline C++
+	    _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+	    _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+	    _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld '
+	    ;;
+	  gcx*)
+	    # Green Hills C++ Compiler
+	    _LT_TAGVAR(lt_prog_compiler_pic, $1)='-PIC'
+	    ;;
+	  *)
+	    ;;
+	esac
+	;;
+      sunos4*)
+	case $cc_basename in
+	  CC*)
+	    # Sun C++ 4.x
+	    _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic'
+	    _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+	    ;;
+	  lcc*)
+	    # Lucid
+	    _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic'
+	    ;;
+	  *)
+	    ;;
+	esac
+	;;
+      sysv5* | unixware* | sco3.2v5* | sco5v6* | OpenUNIX*)
+	case $cc_basename in
+	  CC*)
+	    _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+	    _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+	    _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+	    ;;
+	esac
+	;;
+      tandem*)
+	case $cc_basename in
+	  NCC*)
+	    # NonStop-UX NCC 3.20
+	    _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+	    ;;
+	  *)
+	    ;;
+	esac
+	;;
+      vxworks*)
+	;;
+      *)
+	_LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no
+	;;
+    esac
+  fi
+],
+[
+  if test "$GCC" = yes; then
+    _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+    _LT_TAGVAR(lt_prog_compiler_static, $1)='-static'
+
+    case $host_os in
+      aix*)
+      # All AIX code is PIC.
+      if test "$host_cpu" = ia64; then
+	# AIX 5 now supports IA64 processor
+	_LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+      fi
+      ;;
+
+    amigaos*)
+      case $host_cpu in
+      powerpc)
+            # see comment about AmigaOS4 .so support
+            _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
+        ;;
+      m68k)
+            # FIXME: we need at least 68020 code to build shared libraries, but
+            # adding the `-m68020' flag to GCC prevents building anything better,
+            # like `-m68040'.
+            _LT_TAGVAR(lt_prog_compiler_pic, $1)='-m68020 -resident32 -malways-restore-a4'
+        ;;
+      esac
+      ;;
+
+    beos* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*)
+      # PIC is the default for these OSes.
+      ;;
+
+    mingw* | cygwin* | pw32* | os2* | cegcc*)
+      # This hack is so that the source file can tell whether it is being
+      # built for inclusion in a dll (and should export symbols for example).
+      # Although the cygwin gcc ignores -fPIC, still need this for old-style
+      # (--disable-auto-import) libraries
+      m4_if([$1], [GCJ], [],
+	[_LT_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT'])
+      ;;
+
+    darwin* | rhapsody*)
+      # PIC is the default on this platform
+      # Common symbols not allowed in MH_DYLIB files
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fno-common'
+      ;;
+
+    haiku*)
+      # PIC is the default for Haiku.
+      # The "-static" flag exists, but is broken.
+      _LT_TAGVAR(lt_prog_compiler_static, $1)=
+      ;;
+
+    hpux*)
+      # PIC is the default for 64-bit PA HP-UX, but not for 32-bit
+      # PA HP-UX.  On IA64 HP-UX, PIC is the default but the pic flag
+      # sets the default TLS model and affects inlining.
+      case $host_cpu in
+      hppa*64*)
+	# +Z the default
+	;;
+      *)
+	_LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
+	;;
+      esac
+      ;;
+
+    interix[[3-9]]*)
+      # Interix 3.x gcc -fpic/-fPIC options generate broken code.
+      # Instead, we relocate shared libraries at runtime.
+      ;;
+
+    msdosdjgpp*)
+      # Just because we use GCC doesn't mean we suddenly get shared libraries
+      # on systems that don't support them.
+      _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no
+      enable_shared=no
+      ;;
+
+    *nto* | *qnx*)
+      # QNX uses GNU C++, but need to define -shared option too, otherwise
+      # it will coredump.
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC -shared'
+      ;;
+
+    sysv4*MP*)
+      if test -d /usr/nec; then
+	_LT_TAGVAR(lt_prog_compiler_pic, $1)=-Kconform_pic
+      fi
+      ;;
+
+    *)
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
+      ;;
+    esac
+
+    case $cc_basename in
+    nvcc*) # Cuda Compiler Driver 2.2
+      _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Xlinker '
+      if test -n "$_LT_TAGVAR(lt_prog_compiler_pic, $1)"; then
+        _LT_TAGVAR(lt_prog_compiler_pic, $1)="-Xcompiler $_LT_TAGVAR(lt_prog_compiler_pic, $1)"
+      fi
+      ;;
+    esac
+  else
+    # PORTME Check for flag to pass linker flags through the system compiler.
+    case $host_os in
+    aix*)
+      _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+      if test "$host_cpu" = ia64; then
+	# AIX 5 now supports IA64 processor
+	_LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+      else
+	_LT_TAGVAR(lt_prog_compiler_static, $1)='-bnso -bI:/lib/syscalls.exp'
+      fi
+      ;;
+
+    mingw* | cygwin* | pw32* | os2* | cegcc*)
+      # This hack is so that the source file can tell whether it is being
+      # built for inclusion in a dll (and should export symbols for example).
+      m4_if([$1], [GCJ], [],
+	[_LT_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT'])
+      ;;
+
+    hpux9* | hpux10* | hpux11*)
+      _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+      # PIC is the default for IA64 HP-UX and 64-bit HP-UX, but
+      # not for PA HP-UX.
+      case $host_cpu in
+      hppa*64*|ia64*)
+	# +Z the default
+	;;
+      *)
+	_LT_TAGVAR(lt_prog_compiler_pic, $1)='+Z'
+	;;
+      esac
+      # Is there a better lt_prog_compiler_static that works with the bundled CC?
+      _LT_TAGVAR(lt_prog_compiler_static, $1)='${wl}-a ${wl}archive'
+      ;;
+
+    irix5* | irix6* | nonstopux*)
+      _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+      # PIC (with -KPIC) is the default.
+      _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared'
+      ;;
+
+    linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*)
+      case $cc_basename in
+      # old Intel for x86_64 which still supported -KPIC.
+      ecc*)
+	_LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+	_LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+	_LT_TAGVAR(lt_prog_compiler_static, $1)='-static'
+        ;;
+      # icc used to be incompatible with GCC.
+      # ICC 10 doesn't accept -KPIC any more.
+      icc* | ifort*)
+	_LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+	_LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
+	_LT_TAGVAR(lt_prog_compiler_static, $1)='-static'
+        ;;
+      # Lahey Fortran 8.1.
+      lf95*)
+	_LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+	_LT_TAGVAR(lt_prog_compiler_pic, $1)='--shared'
+	_LT_TAGVAR(lt_prog_compiler_static, $1)='--static'
+	;;
+      nagfor*)
+	# NAG Fortran compiler
+	_LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,-Wl,,'
+	_LT_TAGVAR(lt_prog_compiler_pic, $1)='-PIC'
+	_LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+	;;
+      pgcc* | pgf77* | pgf90* | pgf95* | pgfortran*)
+        # Portland Group compilers (*not* the Pentium gcc compiler,
+	# which looks to be a dead project)
+	_LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+	_LT_TAGVAR(lt_prog_compiler_pic, $1)='-fpic'
+	_LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+        ;;
+      ccc*)
+        _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+        # All Alpha code is PIC.
+        _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared'
+        ;;
+      xl* | bgxl* | bgf* | mpixl*)
+	# IBM XL C 8.0/Fortran 10.1, 11.1 on PPC and BlueGene
+	_LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+	_LT_TAGVAR(lt_prog_compiler_pic, $1)='-qpic'
+	_LT_TAGVAR(lt_prog_compiler_static, $1)='-qstaticlink'
+	;;
+      *)
+	case `$CC -V 2>&1 | sed 5q` in
+	*Sun\ Ceres\ Fortran* | *Sun*Fortran*\ [[1-7]].* | *Sun*Fortran*\ 8.[[0-3]]*)
+	  # Sun Fortran 8.3 passes all unrecognized flags to the linker
+	  _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+	  _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+	  _LT_TAGVAR(lt_prog_compiler_wl, $1)=''
+	  ;;
+	*Sun\ F* | *Sun*Fortran*)
+	  _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+	  _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+	  _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld '
+	  ;;
+	*Sun\ C*)
+	  # Sun C 5.9
+	  _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+	  _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+	  _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+	  ;;
+        *Intel*\ [[CF]]*Compiler*)
+	  _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+	  _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
+	  _LT_TAGVAR(lt_prog_compiler_static, $1)='-static'
+	  ;;
+	*Portland\ Group*)
+	  _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+	  _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fpic'
+	  _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+	  ;;
+	esac
+	;;
+      esac
+      ;;
+
+    newsos6)
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+      _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+      ;;
+
+    *nto* | *qnx*)
+      # QNX uses GNU C++, but need to define -shared option too, otherwise
+      # it will coredump.
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC -shared'
+      ;;
+
+    osf3* | osf4* | osf5*)
+      _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+      # All OSF/1 code is PIC.
+      _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared'
+      ;;
+
+    rdos*)
+      _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared'
+      ;;
+
+    solaris*)
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+      _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+      case $cc_basename in
+      f77* | f90* | f95* | sunf77* | sunf90* | sunf95*)
+	_LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld ';;
+      *)
+	_LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,';;
+      esac
+      ;;
+
+    sunos4*)
+      _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld '
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-PIC'
+      _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+      ;;
+
+    sysv4 | sysv4.2uw2* | sysv4.3*)
+      _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+      _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+      ;;
+
+    sysv4*MP*)
+      if test -d /usr/nec ;then
+	_LT_TAGVAR(lt_prog_compiler_pic, $1)='-Kconform_pic'
+	_LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+      fi
+      ;;
+
+    sysv5* | unixware* | sco3.2v5* | sco5v6* | OpenUNIX*)
+      _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+      _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+      ;;
+
+    unicos*)
+      _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+      _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no
+      ;;
+
+    uts4*)
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic'
+      _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+      ;;
+
+    *)
+      _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no
+      ;;
+    esac
+  fi
+])
+case $host_os in
+  # For platforms which do not support PIC, -DPIC is meaningless:
+  *djgpp*)
+    _LT_TAGVAR(lt_prog_compiler_pic, $1)=
+    ;;
+  *)
+    _LT_TAGVAR(lt_prog_compiler_pic, $1)="$_LT_TAGVAR(lt_prog_compiler_pic, $1)@&t@m4_if([$1],[],[ -DPIC],[m4_if([$1],[CXX],[ -DPIC],[])])"
+    ;;
+esac
+
+AC_CACHE_CHECK([for $compiler option to produce PIC],
+  [_LT_TAGVAR(lt_cv_prog_compiler_pic, $1)],
+  [_LT_TAGVAR(lt_cv_prog_compiler_pic, $1)=$_LT_TAGVAR(lt_prog_compiler_pic, $1)])
+_LT_TAGVAR(lt_prog_compiler_pic, $1)=$_LT_TAGVAR(lt_cv_prog_compiler_pic, $1)
+
+#
+# Check to make sure the PIC flag actually works.
+#
+if test -n "$_LT_TAGVAR(lt_prog_compiler_pic, $1)"; then
+  _LT_COMPILER_OPTION([if $compiler PIC flag $_LT_TAGVAR(lt_prog_compiler_pic, $1) works],
+    [_LT_TAGVAR(lt_cv_prog_compiler_pic_works, $1)],
+    [$_LT_TAGVAR(lt_prog_compiler_pic, $1)@&t@m4_if([$1],[],[ -DPIC],[m4_if([$1],[CXX],[ -DPIC],[])])], [],
+    [case $_LT_TAGVAR(lt_prog_compiler_pic, $1) in
+     "" | " "*) ;;
+     *) _LT_TAGVAR(lt_prog_compiler_pic, $1)=" $_LT_TAGVAR(lt_prog_compiler_pic, $1)" ;;
+     esac],
+    [_LT_TAGVAR(lt_prog_compiler_pic, $1)=
+     _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no])
+fi
+_LT_TAGDECL([pic_flag], [lt_prog_compiler_pic], [1],
+	[Additional compiler flags for building library objects])
+
+_LT_TAGDECL([wl], [lt_prog_compiler_wl], [1],
+	[How to pass a linker flag through the compiler])
+#
+# Check to make sure the static flag actually works.
+#
+wl=$_LT_TAGVAR(lt_prog_compiler_wl, $1) eval lt_tmp_static_flag=\"$_LT_TAGVAR(lt_prog_compiler_static, $1)\"
+_LT_LINKER_OPTION([if $compiler static flag $lt_tmp_static_flag works],
+  _LT_TAGVAR(lt_cv_prog_compiler_static_works, $1),
+  $lt_tmp_static_flag,
+  [],
+  [_LT_TAGVAR(lt_prog_compiler_static, $1)=])
+_LT_TAGDECL([link_static_flag], [lt_prog_compiler_static], [1],
+	[Compiler flag to prevent dynamic linking])
+])# _LT_COMPILER_PIC
+
+
+# _LT_LINKER_SHLIBS([TAGNAME])
+# ----------------------------
+# See if the linker supports building shared libraries.
+m4_defun([_LT_LINKER_SHLIBS],
+[AC_REQUIRE([LT_PATH_LD])dnl
+AC_REQUIRE([LT_PATH_NM])dnl
+m4_require([_LT_PATH_MANIFEST_TOOL])dnl
+m4_require([_LT_FILEUTILS_DEFAULTS])dnl
+m4_require([_LT_DECL_EGREP])dnl
+m4_require([_LT_DECL_SED])dnl
+m4_require([_LT_CMD_GLOBAL_SYMBOLS])dnl
+m4_require([_LT_TAG_COMPILER])dnl
+AC_MSG_CHECKING([whether the $compiler linker ($LD) supports shared libraries])
+m4_if([$1], [CXX], [
+  _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols'
+  _LT_TAGVAR(exclude_expsyms, $1)=['_GLOBAL_OFFSET_TABLE_|_GLOBAL__F[ID]_.*']
+  case $host_os in
+  aix[[4-9]]*)
+    # If we're using GNU nm, then we don't want the "-C" option.
+    # -C means demangle to AIX nm, but means don't demangle with GNU nm
+    # Also, AIX nm treats weak defined symbols like other global defined
+    # symbols, whereas GNU nm marks them as "W".
+    if $NM -V 2>&1 | $GREP 'GNU' > /dev/null; then
+      _LT_TAGVAR(export_symbols_cmds, $1)='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B") || (\$ 2 == "W")) && ([substr](\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols'
+    else
+      _LT_TAGVAR(export_symbols_cmds, $1)='$NM -BCpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B")) && ([substr](\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols'
+    fi
+    ;;
+  pw32*)
+    _LT_TAGVAR(export_symbols_cmds, $1)="$ltdll_cmds"
+    ;;
+  cygwin* | mingw* | cegcc*)
+    case $cc_basename in
+    cl*)
+      _LT_TAGVAR(exclude_expsyms, $1)='_NULL_IMPORT_DESCRIPTOR|_IMPORT_DESCRIPTOR_.*'
+      ;;
+    *)
+      _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[[BCDGRS]][[ ]]/s/.*[[ ]]\([[^ ]]*\)/\1 DATA/;s/^.*[[ ]]__nm__\([[^ ]]*\)[[ ]][[^ ]]*/\1 DATA/;/^I[[ ]]/d;/^[[AITW]][[ ]]/s/.* //'\'' | sort | uniq > $export_symbols'
+      _LT_TAGVAR(exclude_expsyms, $1)=['[_]+GLOBAL_OFFSET_TABLE_|[_]+GLOBAL__[FID]_.*|[_]+head_[A-Za-z0-9_]+_dll|[A-Za-z0-9_]+_dll_iname']
+      ;;
+    esac
+    ;;
+  linux* | k*bsd*-gnu | gnu*)
+    _LT_TAGVAR(link_all_deplibs, $1)=no
+    ;;
+  *)
+    _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols'
+    ;;
+  esac
+], [
+  runpath_var=
+  _LT_TAGVAR(allow_undefined_flag, $1)=
+  _LT_TAGVAR(always_export_symbols, $1)=no
+  _LT_TAGVAR(archive_cmds, $1)=
+  _LT_TAGVAR(archive_expsym_cmds, $1)=
+  _LT_TAGVAR(compiler_needs_object, $1)=no
+  _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=no
+  _LT_TAGVAR(export_dynamic_flag_spec, $1)=
+  _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols'
+  _LT_TAGVAR(hardcode_automatic, $1)=no
+  _LT_TAGVAR(hardcode_direct, $1)=no
+  _LT_TAGVAR(hardcode_direct_absolute, $1)=no
+  _LT_TAGVAR(hardcode_libdir_flag_spec, $1)=
+  _LT_TAGVAR(hardcode_libdir_separator, $1)=
+  _LT_TAGVAR(hardcode_minus_L, $1)=no
+  _LT_TAGVAR(hardcode_shlibpath_var, $1)=unsupported
+  _LT_TAGVAR(inherit_rpath, $1)=no
+  _LT_TAGVAR(link_all_deplibs, $1)=unknown
+  _LT_TAGVAR(module_cmds, $1)=
+  _LT_TAGVAR(module_expsym_cmds, $1)=
+  _LT_TAGVAR(old_archive_from_new_cmds, $1)=
+  _LT_TAGVAR(old_archive_from_expsyms_cmds, $1)=
+  _LT_TAGVAR(thread_safe_flag_spec, $1)=
+  _LT_TAGVAR(whole_archive_flag_spec, $1)=
+  # include_expsyms should be a list of space-separated symbols to be *always*
+  # included in the symbol list
+  _LT_TAGVAR(include_expsyms, $1)=
+  # exclude_expsyms can be an extended regexp of symbols to exclude
+  # it will be wrapped by ` (' and `)$', so one must not match beginning or
+  # end of line.  Example: `a|bc|.*d.*' will exclude the symbols `a' and `bc',
+  # as well as any symbol that contains `d'.
+  _LT_TAGVAR(exclude_expsyms, $1)=['_GLOBAL_OFFSET_TABLE_|_GLOBAL__F[ID]_.*']
+  # Although _GLOBAL_OFFSET_TABLE_ is a valid symbol C name, most a.out
+  # platforms (ab)use it in PIC code, but their linkers get confused if
+  # the symbol is explicitly referenced.  Since portable code cannot
+  # rely on this symbol name, it's probably fine to never include it in
+  # preloaded symbol tables.
+  # Exclude shared library initialization/finalization symbols.
+dnl Note also adjust exclude_expsyms for C++ above.
+  extract_expsyms_cmds=
+
+  case $host_os in
+  cygwin* | mingw* | pw32* | cegcc*)
+    # FIXME: the MSVC++ port hasn't been tested in a loooong time
+    # When not using gcc, we currently assume that we are using
+    # Microsoft Visual C++.
+    if test "$GCC" != yes; then
+      with_gnu_ld=no
+    fi
+    ;;
+  interix*)
+    # we just hope/assume this is gcc and not c89 (= MSVC++)
+    with_gnu_ld=yes
+    ;;
+  openbsd*)
+    with_gnu_ld=no
+    ;;
+  linux* | k*bsd*-gnu | gnu*)
+    _LT_TAGVAR(link_all_deplibs, $1)=no
+    ;;
+  esac
+
+  _LT_TAGVAR(ld_shlibs, $1)=yes
+
+  # On some targets, GNU ld is compatible enough with the native linker
+  # that we're better off using the native interface for both.
+  lt_use_gnu_ld_interface=no
+  if test "$with_gnu_ld" = yes; then
+    case $host_os in
+      aix*)
+	# The AIX port of GNU ld has always aspired to compatibility
+	# with the native linker.  However, as the warning in the GNU ld
+	# block says, versions before 2.19.5* couldn't really create working
+	# shared libraries, regardless of the interface used.
+	case `$LD -v 2>&1` in
+	  *\ \(GNU\ Binutils\)\ 2.19.5*) ;;
+	  *\ \(GNU\ Binutils\)\ 2.[[2-9]]*) ;;
+	  *\ \(GNU\ Binutils\)\ [[3-9]]*) ;;
+	  *)
+	    lt_use_gnu_ld_interface=yes
+	    ;;
+	esac
+	;;
+      *)
+	lt_use_gnu_ld_interface=yes
+	;;
+    esac
+  fi
+
+  if test "$lt_use_gnu_ld_interface" = yes; then
+    # If archive_cmds runs LD, not CC, wlarc should be empty
+    wlarc='${wl}'
+
+    # Set some defaults for GNU ld with shared library support. These
+    # are reset later if shared libraries are not supported. Putting them
+    # here allows them to be overridden if necessary.
+    runpath_var=LD_RUN_PATH
+    _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
+    _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic'
+    # ancient GNU ld didn't support --whole-archive et. al.
+    if $LD --help 2>&1 | $GREP 'no-whole-archive' > /dev/null; then
+      _LT_TAGVAR(whole_archive_flag_spec, $1)="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive'
+    else
+      _LT_TAGVAR(whole_archive_flag_spec, $1)=
+    fi
+    supports_anon_versioning=no
+    case `$LD -v 2>&1` in
+      *GNU\ gold*) supports_anon_versioning=yes ;;
+      *\ [[01]].* | *\ 2.[[0-9]].* | *\ 2.10.*) ;; # catch versions < 2.11
+      *\ 2.11.93.0.2\ *) supports_anon_versioning=yes ;; # RH7.3 ...
+      *\ 2.11.92.0.12\ *) supports_anon_versioning=yes ;; # Mandrake 8.2 ...
+      *\ 2.11.*) ;; # other 2.11 versions
+      *) supports_anon_versioning=yes ;;
+    esac
+
+    # See if GNU ld supports shared libraries.
+    case $host_os in
+    aix[[3-9]]*)
+      # On AIX/PPC, the GNU linker is very broken
+      if test "$host_cpu" != ia64; then
+	_LT_TAGVAR(ld_shlibs, $1)=no
+	cat <<_LT_EOF 1>&2
+
+*** Warning: the GNU linker, at least up to release 2.19, is reported
+*** to be unable to reliably create shared libraries on AIX.
+*** Therefore, libtool is disabling shared libraries support.  If you
+*** really care for shared libraries, you may want to install binutils
+*** 2.20 or above, or modify your PATH so that a non-GNU linker is found.
+*** You will then need to restart the configuration process.
+
+_LT_EOF
+      fi
+      ;;
+
+    amigaos*)
+      case $host_cpu in
+      powerpc)
+            # see comment about AmigaOS4 .so support
+            _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+            _LT_TAGVAR(archive_expsym_cmds, $1)=''
+        ;;
+      m68k)
+            _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/a2ixlibrary.data~$ECHO "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$ECHO "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$ECHO "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$ECHO "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)'
+            _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
+            _LT_TAGVAR(hardcode_minus_L, $1)=yes
+        ;;
+      esac
+      ;;
+
+    beos*)
+      if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then
+	_LT_TAGVAR(allow_undefined_flag, $1)=unsupported
+	# Joseph Beckenbach <jrb3@best.com> says some releases of gcc
+	# support --undefined.  This deserves some investigation.  FIXME
+	_LT_TAGVAR(archive_cmds, $1)='$CC -nostart $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+      else
+	_LT_TAGVAR(ld_shlibs, $1)=no
+      fi
+      ;;
+
+    cygwin* | mingw* | pw32* | cegcc*)
+      # _LT_TAGVAR(hardcode_libdir_flag_spec, $1) is actually meaningless,
+      # as there is no search path for DLLs.
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
+      _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-all-symbols'
+      _LT_TAGVAR(allow_undefined_flag, $1)=unsupported
+      _LT_TAGVAR(always_export_symbols, $1)=no
+      _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes
+      _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[[BCDGRS]][[ ]]/s/.*[[ ]]\([[^ ]]*\)/\1 DATA/;s/^.*[[ ]]__nm__\([[^ ]]*\)[[ ]][[^ ]]*/\1 DATA/;/^I[[ ]]/d;/^[[AITW]][[ ]]/s/.* //'\'' | sort | uniq > $export_symbols'
+      _LT_TAGVAR(exclude_expsyms, $1)=['[_]+GLOBAL_OFFSET_TABLE_|[_]+GLOBAL__[FID]_.*|[_]+head_[A-Za-z0-9_]+_dll|[A-Za-z0-9_]+_dll_iname']
+
+      if $LD --help 2>&1 | $GREP 'auto-import' > /dev/null; then
+        _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib'
+	# If the export-symbols file already is a .def file (1st line
+	# is EXPORTS), use it as is; otherwise, prepend...
+	_LT_TAGVAR(archive_expsym_cmds, $1)='if test "x`$SED 1q $export_symbols`" = xEXPORTS; then
+	  cp $export_symbols $output_objdir/$soname.def;
+	else
+	  echo EXPORTS > $output_objdir/$soname.def;
+	  cat $export_symbols >> $output_objdir/$soname.def;
+	fi~
+	$CC -shared $output_objdir/$soname.def $libobjs $deplibs $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib'
+      else
+	_LT_TAGVAR(ld_shlibs, $1)=no
+      fi
+      ;;
+
+    haiku*)
+      _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+      _LT_TAGVAR(link_all_deplibs, $1)=yes
+      ;;
+
+    interix[[3-9]]*)
+      _LT_TAGVAR(hardcode_direct, $1)=no
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
+      _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
+      # Hack: On Interix 3.x, we cannot compile PIC because of a broken gcc.
+      # Instead, shared libraries are loaded at an image base (0x10000000 by
+      # default) and relocated if they conflict, which is a slow very memory
+      # consuming and fragmenting process.  To avoid this, we pick a random,
+      # 256 KiB-aligned image base between 0x50000000 and 0x6FFC0000 at link
+      # time.  Moving up from 0x10000000 also allows more sbrk(2) space.
+      _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib'
+      _LT_TAGVAR(archive_expsym_cmds, $1)='sed "s,^,_," $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--retain-symbols-file,$output_objdir/$soname.expsym ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib'
+      ;;
+
+    gnu* | linux* | tpf* | k*bsd*-gnu | kopensolaris*-gnu)
+      tmp_diet=no
+      if test "$host_os" = linux-dietlibc; then
+	case $cc_basename in
+	  diet\ *) tmp_diet=yes;;	# linux-dietlibc with static linking (!diet-dyn)
+	esac
+      fi
+      if $LD --help 2>&1 | $EGREP ': supported targets:.* elf' > /dev/null \
+	 && test "$tmp_diet" = no
+      then
+	tmp_addflag=' $pic_flag'
+	tmp_sharedflag='-shared'
+	case $cc_basename,$host_cpu in
+        pgcc*)				# Portland Group C compiler
+	  _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`for conv in $convenience\"\"; do test  -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` ${wl}--no-whole-archive'
+	  tmp_addflag=' $pic_flag'
+	  ;;
+	pgf77* | pgf90* | pgf95* | pgfortran*)
+					# Portland Group f77 and f90 compilers
+	  _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`for conv in $convenience\"\"; do test  -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` ${wl}--no-whole-archive'
+	  tmp_addflag=' $pic_flag -Mnomain' ;;
+	ecc*,ia64* | icc*,ia64*)	# Intel C compiler on ia64
+	  tmp_addflag=' -i_dynamic' ;;
+	efc*,ia64* | ifort*,ia64*)	# Intel Fortran compiler on ia64
+	  tmp_addflag=' -i_dynamic -nofor_main' ;;
+	ifc* | ifort*)			# Intel Fortran compiler
+	  tmp_addflag=' -nofor_main' ;;
+	lf95*)				# Lahey Fortran 8.1
+	  _LT_TAGVAR(whole_archive_flag_spec, $1)=
+	  tmp_sharedflag='--shared' ;;
+	xl[[cC]]* | bgxl[[cC]]* | mpixl[[cC]]*) # IBM XL C 8.0 on PPC (deal with xlf below)
+	  tmp_sharedflag='-qmkshrobj'
+	  tmp_addflag= ;;
+	nvcc*)	# Cuda Compiler Driver 2.2
+	  _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`for conv in $convenience\"\"; do test  -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` ${wl}--no-whole-archive'
+	  _LT_TAGVAR(compiler_needs_object, $1)=yes
+	  ;;
+	esac
+	case `$CC -V 2>&1 | sed 5q` in
+	*Sun\ C*)			# Sun C 5.9
+	  _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`new_convenience=; for conv in $convenience\"\"; do test -z \"$conv\" || new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` ${wl}--no-whole-archive'
+	  _LT_TAGVAR(compiler_needs_object, $1)=yes
+	  tmp_sharedflag='-G' ;;
+	*Sun\ F*)			# Sun Fortran 8.3
+	  tmp_sharedflag='-G' ;;
+	esac
+	_LT_TAGVAR(archive_cmds, $1)='$CC '"$tmp_sharedflag""$tmp_addflag"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+
+        if test "x$supports_anon_versioning" = xyes; then
+          _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $output_objdir/$libname.ver~
+	    cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~
+	    echo "local: *; };" >> $output_objdir/$libname.ver~
+	    $CC '"$tmp_sharedflag""$tmp_addflag"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-version-script ${wl}$output_objdir/$libname.ver -o $lib'
+        fi
+
+	case $cc_basename in
+	xlf* | bgf* | bgxlf* | mpixlf*)
+	  # IBM XL Fortran 10.1 on PPC cannot create shared libs itself
+	  _LT_TAGVAR(whole_archive_flag_spec, $1)='--whole-archive$convenience --no-whole-archive'
+	  _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
+	  _LT_TAGVAR(archive_cmds, $1)='$LD -shared $libobjs $deplibs $linker_flags -soname $soname -o $lib'
+	  if test "x$supports_anon_versioning" = xyes; then
+	    _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $output_objdir/$libname.ver~
+	      cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~
+	      echo "local: *; };" >> $output_objdir/$libname.ver~
+	      $LD -shared $libobjs $deplibs $linker_flags -soname $soname -version-script $output_objdir/$libname.ver -o $lib'
+	  fi
+	  ;;
+	esac
+      else
+        _LT_TAGVAR(ld_shlibs, $1)=no
+      fi
+      ;;
+
+    netbsd* | netbsdelf*-gnu)
+      if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then
+	_LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable $libobjs $deplibs $linker_flags -o $lib'
+	wlarc=
+      else
+	_LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+	_LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
+      fi
+      ;;
+
+    solaris*)
+      if $LD -v 2>&1 | $GREP 'BFD 2\.8' > /dev/null; then
+	_LT_TAGVAR(ld_shlibs, $1)=no
+	cat <<_LT_EOF 1>&2
+
+*** Warning: The releases 2.8.* of the GNU linker cannot reliably
+*** create shared libraries on Solaris systems.  Therefore, libtool
+*** is disabling shared libraries support.  We urge you to upgrade GNU
+*** binutils to release 2.9.1 or newer.  Another option is to modify
+*** your PATH or compiler configuration so that the native linker is
+*** used, and then restart.
+
+_LT_EOF
+      elif $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then
+	_LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+	_LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
+      else
+	_LT_TAGVAR(ld_shlibs, $1)=no
+      fi
+      ;;
+
+    sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX*)
+      case `$LD -v 2>&1` in
+        *\ [[01]].* | *\ 2.[[0-9]].* | *\ 2.1[[0-5]].*)
+	_LT_TAGVAR(ld_shlibs, $1)=no
+	cat <<_LT_EOF 1>&2
+
+*** Warning: Releases of the GNU linker prior to 2.16.91.0.3 can not
+*** reliably create shared libraries on SCO systems.  Therefore, libtool
+*** is disabling shared libraries support.  We urge you to upgrade GNU
+*** binutils to release 2.16.91.0.3 or newer.  Another option is to modify
+*** your PATH or compiler configuration so that the native linker is
+*** used, and then restart.
+
+_LT_EOF
+	;;
+	*)
+	  # For security reasons, it is highly recommended that you always
+	  # use absolute paths for naming shared libraries, and exclude the
+	  # DT_RUNPATH tag from executables and libraries.  But doing so
+	  # requires that you compile everything twice, which is a pain.
+	  if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then
+	    _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
+	    _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+	    _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
+	  else
+	    _LT_TAGVAR(ld_shlibs, $1)=no
+	  fi
+	;;
+      esac
+      ;;
+
+    sunos4*)
+      _LT_TAGVAR(archive_cmds, $1)='$LD -assert pure-text -Bshareable -o $lib $libobjs $deplibs $linker_flags'
+      wlarc=
+      _LT_TAGVAR(hardcode_direct, $1)=yes
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      ;;
+
+    *)
+      if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then
+	_LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+	_LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
+      else
+	_LT_TAGVAR(ld_shlibs, $1)=no
+      fi
+      ;;
+    esac
+
+    if test "$_LT_TAGVAR(ld_shlibs, $1)" = no; then
+      runpath_var=
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)=
+      _LT_TAGVAR(export_dynamic_flag_spec, $1)=
+      _LT_TAGVAR(whole_archive_flag_spec, $1)=
+    fi
+  else
+    # PORTME fill in a description of your system's linker (not GNU ld)
+    case $host_os in
+    aix3*)
+      _LT_TAGVAR(allow_undefined_flag, $1)=unsupported
+      _LT_TAGVAR(always_export_symbols, $1)=yes
+      _LT_TAGVAR(archive_expsym_cmds, $1)='$LD -o $output_objdir/$soname $libobjs $deplibs $linker_flags -bE:$export_symbols -T512 -H512 -bM:SRE~$AR $AR_FLAGS $lib $output_objdir/$soname'
+      # Note: this linker hardcodes the directories in LIBPATH if there
+      # are no directories specified by -L.
+      _LT_TAGVAR(hardcode_minus_L, $1)=yes
+      if test "$GCC" = yes && test -z "$lt_prog_compiler_static"; then
+	# Neither direct hardcoding nor static linking is supported with a
+	# broken collect2.
+	_LT_TAGVAR(hardcode_direct, $1)=unsupported
+      fi
+      ;;
+
+    aix[[4-9]]*)
+      if test "$host_cpu" = ia64; then
+	# On IA64, the linker does run time linking by default, so we don't
+	# have to do anything special.
+	aix_use_runtimelinking=no
+	exp_sym_flag='-Bexport'
+	no_entry_flag=""
+      else
+	# If we're using GNU nm, then we don't want the "-C" option.
+	# -C means demangle to AIX nm, but means don't demangle with GNU nm
+	# Also, AIX nm treats weak defined symbols like other global
+	# defined symbols, whereas GNU nm marks them as "W".
+	if $NM -V 2>&1 | $GREP 'GNU' > /dev/null; then
+	  _LT_TAGVAR(export_symbols_cmds, $1)='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B") || (\$ 2 == "W")) && ([substr](\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols'
+	else
+	  _LT_TAGVAR(export_symbols_cmds, $1)='$NM -BCpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B")) && ([substr](\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols'
+	fi
+	aix_use_runtimelinking=no
+
+	# Test if we are trying to use run time linking or normal
+	# AIX style linking. If -brtl is somewhere in LDFLAGS, we
+	# need to do runtime linking.
+	case $host_os in aix4.[[23]]|aix4.[[23]].*|aix[[5-9]]*)
+	  for ld_flag in $LDFLAGS; do
+	  if (test $ld_flag = "-brtl" || test $ld_flag = "-Wl,-brtl"); then
+	    aix_use_runtimelinking=yes
+	    break
+	  fi
+	  done
+	  ;;
+	esac
+
+	exp_sym_flag='-bexport'
+	no_entry_flag='-bnoentry'
+      fi
+
+      # When large executables or shared objects are built, AIX ld can
+      # have problems creating the table of contents.  If linking a library
+      # or program results in "error TOC overflow" add -mminimal-toc to
+      # CXXFLAGS/CFLAGS for g++/gcc.  In the cases where that is not
+      # enough to fix the problem, add -Wl,-bbigtoc to LDFLAGS.
+
+      _LT_TAGVAR(archive_cmds, $1)=''
+      _LT_TAGVAR(hardcode_direct, $1)=yes
+      _LT_TAGVAR(hardcode_direct_absolute, $1)=yes
+      _LT_TAGVAR(hardcode_libdir_separator, $1)=':'
+      _LT_TAGVAR(link_all_deplibs, $1)=yes
+      _LT_TAGVAR(file_list_spec, $1)='${wl}-f,'
+
+      if test "$GCC" = yes; then
+	case $host_os in aix4.[[012]]|aix4.[[012]].*)
+	# We only want to do this on AIX 4.2 and lower, the check
+	# below for broken collect2 doesn't work under 4.3+
+	  collect2name=`${CC} -print-prog-name=collect2`
+	  if test -f "$collect2name" &&
+	   strings "$collect2name" | $GREP resolve_lib_name >/dev/null
+	  then
+	  # We have reworked collect2
+	  :
+	  else
+	  # We have old collect2
+	  _LT_TAGVAR(hardcode_direct, $1)=unsupported
+	  # It fails to find uninstalled libraries when the uninstalled
+	  # path is not listed in the libpath.  Setting hardcode_minus_L
+	  # to unsupported forces relinking
+	  _LT_TAGVAR(hardcode_minus_L, $1)=yes
+	  _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
+	  _LT_TAGVAR(hardcode_libdir_separator, $1)=
+	  fi
+	  ;;
+	esac
+	shared_flag='-shared'
+	if test "$aix_use_runtimelinking" = yes; then
+	  shared_flag="$shared_flag "'${wl}-G'
+	fi
+	_LT_TAGVAR(link_all_deplibs, $1)=no
+      else
+	# not using gcc
+	if test "$host_cpu" = ia64; then
+	# VisualAge C++, Version 5.5 for AIX 5L for IA-64, Beta 3 Release
+	# chokes on -Wl,-G. The following line is correct:
+	  shared_flag='-G'
+	else
+	  if test "$aix_use_runtimelinking" = yes; then
+	    shared_flag='${wl}-G'
+	  else
+	    shared_flag='${wl}-bM:SRE'
+	  fi
+	fi
+      fi
+
+      _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-bexpall'
+      # It seems that -bexpall does not export symbols beginning with
+      # underscore (_), so it is better to generate a list of symbols to export.
+      _LT_TAGVAR(always_export_symbols, $1)=yes
+      if test "$aix_use_runtimelinking" = yes; then
+	# Warning - without using the other runtime loading flags (-brtl),
+	# -berok will link without error, but may produce a broken library.
+	_LT_TAGVAR(allow_undefined_flag, $1)='-berok'
+        # Determine the default libpath from the value encoded in an
+        # empty executable.
+        _LT_SYS_MODULE_PATH_AIX([$1])
+        _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-blibpath:$libdir:'"$aix_libpath"
+        _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags `if test "x${allow_undefined_flag}" != "x"; then func_echo_all "${wl}${allow_undefined_flag}"; else :; fi` '"\${wl}$exp_sym_flag:\$export_symbols $shared_flag"
+      else
+	if test "$host_cpu" = ia64; then
+	  _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R $libdir:/usr/lib:/lib'
+	  _LT_TAGVAR(allow_undefined_flag, $1)="-z nodefs"
+	  _LT_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags ${wl}${allow_undefined_flag} '"\${wl}$exp_sym_flag:\$export_symbols"
+	else
+	 # Determine the default libpath from the value encoded in an
+	 # empty executable.
+	 _LT_SYS_MODULE_PATH_AIX([$1])
+	 _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-blibpath:$libdir:'"$aix_libpath"
+	  # Warning - without using the other run time loading flags,
+	  # -berok will link without error, but may produce a broken library.
+	  _LT_TAGVAR(no_undefined_flag, $1)=' ${wl}-bernotok'
+	  _LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-berok'
+	  if test "$with_gnu_ld" = yes; then
+	    # We only use this code for GNU lds that support --whole-archive.
+	    _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive$convenience ${wl}--no-whole-archive'
+	  else
+	    # Exported symbols can be pulled into shared objects from archives
+	    _LT_TAGVAR(whole_archive_flag_spec, $1)='$convenience'
+	  fi
+	  _LT_TAGVAR(archive_cmds_need_lc, $1)=yes
+	  # This is similar to how AIX traditionally builds its shared libraries.
+	  _LT_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs ${wl}-bnoentry $compiler_flags ${wl}-bE:$export_symbols${allow_undefined_flag}~$AR $AR_FLAGS $output_objdir/$libname$release.a $output_objdir/$soname'
+	fi
+      fi
+      ;;
+
+    amigaos*)
+      case $host_cpu in
+      powerpc)
+            # see comment about AmigaOS4 .so support
+            _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+            _LT_TAGVAR(archive_expsym_cmds, $1)=''
+        ;;
+      m68k)
+            _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/a2ixlibrary.data~$ECHO "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$ECHO "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$ECHO "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$ECHO "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)'
+            _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
+            _LT_TAGVAR(hardcode_minus_L, $1)=yes
+        ;;
+      esac
+      ;;
+
+    bsdi[[45]]*)
+      _LT_TAGVAR(export_dynamic_flag_spec, $1)=-rdynamic
+      ;;
+
+    cygwin* | mingw* | pw32* | cegcc*)
+      # When not using gcc, we currently assume that we are using
+      # Microsoft Visual C++.
+      # hardcode_libdir_flag_spec is actually meaningless, as there is
+      # no search path for DLLs.
+      case $cc_basename in
+      cl*)
+	# Native MSVC
+	_LT_TAGVAR(hardcode_libdir_flag_spec, $1)=' '
+	_LT_TAGVAR(allow_undefined_flag, $1)=unsupported
+	_LT_TAGVAR(always_export_symbols, $1)=yes
+	_LT_TAGVAR(file_list_spec, $1)='@'
+	# Tell ltmain to make .lib files, not .a files.
+	libext=lib
+	# Tell ltmain to make .dll files, not .so files.
+	shrext_cmds=".dll"
+	# FIXME: Setting linknames here is a bad hack.
+	_LT_TAGVAR(archive_cmds, $1)='$CC -o $output_objdir/$soname $libobjs $compiler_flags $deplibs -Wl,-dll~linknames='
+	_LT_TAGVAR(archive_expsym_cmds, $1)='if test "x`$SED 1q $export_symbols`" = xEXPORTS; then
+	    sed -n -e 's/\\\\\\\(.*\\\\\\\)/-link\\\ -EXPORT:\\\\\\\1/' -e '1\\\!p' < $export_symbols > $output_objdir/$soname.exp;
+	  else
+	    sed -e 's/\\\\\\\(.*\\\\\\\)/-link\\\ -EXPORT:\\\\\\\1/' < $export_symbols > $output_objdir/$soname.exp;
+	  fi~
+	  $CC -o $tool_output_objdir$soname $libobjs $compiler_flags $deplibs "@$tool_output_objdir$soname.exp" -Wl,-DLL,-IMPLIB:"$tool_output_objdir$libname.dll.lib"~
+	  linknames='
+	# The linker will not automatically build a static lib if we build a DLL.
+	# _LT_TAGVAR(old_archive_from_new_cmds, $1)='true'
+	_LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes
+	_LT_TAGVAR(exclude_expsyms, $1)='_NULL_IMPORT_DESCRIPTOR|_IMPORT_DESCRIPTOR_.*'
+	_LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[[BCDGRS]][[ ]]/s/.*[[ ]]\([[^ ]]*\)/\1,DATA/'\'' | $SED -e '\''/^[[AITW]][[ ]]/s/.*[[ ]]//'\'' | sort | uniq > $export_symbols'
+	# Don't use ranlib
+	_LT_TAGVAR(old_postinstall_cmds, $1)='chmod 644 $oldlib'
+	_LT_TAGVAR(postlink_cmds, $1)='lt_outputfile="@OUTPUT@"~
+	  lt_tool_outputfile="@TOOL_OUTPUT@"~
+	  case $lt_outputfile in
+	    *.exe|*.EXE) ;;
+	    *)
+	      lt_outputfile="$lt_outputfile.exe"
+	      lt_tool_outputfile="$lt_tool_outputfile.exe"
+	      ;;
+	  esac~
+	  if test "$MANIFEST_TOOL" != ":" && test -f "$lt_outputfile.manifest"; then
+	    $MANIFEST_TOOL -manifest "$lt_tool_outputfile.manifest" -outputresource:"$lt_tool_outputfile" || exit 1;
+	    $RM "$lt_outputfile.manifest";
+	  fi'
+	;;
+      *)
+	# Assume MSVC wrapper
+	_LT_TAGVAR(hardcode_libdir_flag_spec, $1)=' '
+	_LT_TAGVAR(allow_undefined_flag, $1)=unsupported
+	# Tell ltmain to make .lib files, not .a files.
+	libext=lib
+	# Tell ltmain to make .dll files, not .so files.
+	shrext_cmds=".dll"
+	# FIXME: Setting linknames here is a bad hack.
+	_LT_TAGVAR(archive_cmds, $1)='$CC -o $lib $libobjs $compiler_flags `func_echo_all "$deplibs" | $SED '\''s/ -lc$//'\''` -link -dll~linknames='
+	# The linker will automatically build a .lib file if we build a DLL.
+	_LT_TAGVAR(old_archive_from_new_cmds, $1)='true'
+	# FIXME: Should let the user specify the lib program.
+	_LT_TAGVAR(old_archive_cmds, $1)='lib -OUT:$oldlib$oldobjs$old_deplibs'
+	_LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes
+	;;
+      esac
+      ;;
+
+    darwin* | rhapsody*)
+      _LT_DARWIN_LINKER_FEATURES($1)
+      ;;
+
+    dgux*)
+      _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      ;;
+
+    # FreeBSD 2.2.[012] allows us to include c++rt0.o to get C++ constructor
+    # support.  Future versions do this automatically, but an explicit c++rt0.o
+    # does not break anything, and helps significantly (at the cost of a little
+    # extra space).
+    freebsd2.2*)
+      _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags /usr/lib/c++rt0.o'
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
+      _LT_TAGVAR(hardcode_direct, $1)=yes
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      ;;
+
+    # Unfortunately, older versions of FreeBSD 2 do not have this feature.
+    freebsd2.*)
+      _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags'
+      _LT_TAGVAR(hardcode_direct, $1)=yes
+      _LT_TAGVAR(hardcode_minus_L, $1)=yes
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      ;;
+
+    # FreeBSD 3 and greater uses gcc -shared to do shared libraries.
+    freebsd* | dragonfly*)
+      _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags'
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
+      _LT_TAGVAR(hardcode_direct, $1)=yes
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      ;;
+
+    hpux9*)
+      if test "$GCC" = yes; then
+	_LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/$soname~$CC -shared $pic_flag ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $libobjs $deplibs $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib'
+      else
+	_LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/$soname~$LD -b +b $install_libdir -o $output_objdir/$soname $libobjs $deplibs $linker_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib'
+      fi
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir'
+      _LT_TAGVAR(hardcode_libdir_separator, $1)=:
+      _LT_TAGVAR(hardcode_direct, $1)=yes
+
+      # hardcode_minus_L: Not really in the search PATH,
+      # but as the default location of the library.
+      _LT_TAGVAR(hardcode_minus_L, $1)=yes
+      _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
+      ;;
+
+    hpux10*)
+      if test "$GCC" = yes && test "$with_gnu_ld" = no; then
+	_LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags'
+      else
+	_LT_TAGVAR(archive_cmds, $1)='$LD -b +h $soname +b $install_libdir -o $lib $libobjs $deplibs $linker_flags'
+      fi
+      if test "$with_gnu_ld" = no; then
+	_LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir'
+	_LT_TAGVAR(hardcode_libdir_separator, $1)=:
+	_LT_TAGVAR(hardcode_direct, $1)=yes
+	_LT_TAGVAR(hardcode_direct_absolute, $1)=yes
+	_LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
+	# hardcode_minus_L: Not really in the search PATH,
+	# but as the default location of the library.
+	_LT_TAGVAR(hardcode_minus_L, $1)=yes
+      fi
+      ;;
+
+    hpux11*)
+      if test "$GCC" = yes && test "$with_gnu_ld" = no; then
+	case $host_cpu in
+	hppa*64*)
+	  _LT_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}+h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags'
+	  ;;
+	ia64*)
+	  _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags'
+	  ;;
+	*)
+	  _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags'
+	  ;;
+	esac
+      else
+	case $host_cpu in
+	hppa*64*)
+	  _LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags'
+	  ;;
+	ia64*)
+	  _LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags'
+	  ;;
+	*)
+	m4_if($1, [], [
+	  # Older versions of the 11.00 compiler do not understand -b yet
+	  # (HP92453-01 A.11.01.20 doesn't, HP92453-01 B.11.X.35175-35176.GP does)
+	  _LT_LINKER_OPTION([if $CC understands -b],
+	    _LT_TAGVAR(lt_cv_prog_compiler__b, $1), [-b],
+	    [_LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags'],
+	    [_LT_TAGVAR(archive_cmds, $1)='$LD -b +h $soname +b $install_libdir -o $lib $libobjs $deplibs $linker_flags'])],
+	  [_LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags'])
+	  ;;
+	esac
+      fi
+      if test "$with_gnu_ld" = no; then
+	_LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir'
+	_LT_TAGVAR(hardcode_libdir_separator, $1)=:
+
+	case $host_cpu in
+	hppa*64*|ia64*)
+	  _LT_TAGVAR(hardcode_direct, $1)=no
+	  _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+	  ;;
+	*)
+	  _LT_TAGVAR(hardcode_direct, $1)=yes
+	  _LT_TAGVAR(hardcode_direct_absolute, $1)=yes
+	  _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
+
+	  # hardcode_minus_L: Not really in the search PATH,
+	  # but as the default location of the library.
+	  _LT_TAGVAR(hardcode_minus_L, $1)=yes
+	  ;;
+	esac
+      fi
+      ;;
+
+    irix5* | irix6* | nonstopux*)
+      if test "$GCC" = yes; then
+	_LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && func_echo_all "${wl}-set_version ${wl}$verstring"` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
+	# Try to use the -exported_symbol ld option, if it does not
+	# work, assume that -exports_file does not work either and
+	# implicitly export all symbols.
+	# This should be the same for all languages, so no per-tag cache variable.
+	AC_CACHE_CHECK([whether the $host_os linker accepts -exported_symbol],
+	  [lt_cv_irix_exported_symbol],
+	  [save_LDFLAGS="$LDFLAGS"
+	   LDFLAGS="$LDFLAGS -shared ${wl}-exported_symbol ${wl}foo ${wl}-update_registry ${wl}/dev/null"
+	   AC_LINK_IFELSE(
+	     [AC_LANG_SOURCE(
+	        [AC_LANG_CASE([C], [[int foo (void) { return 0; }]],
+			      [C++], [[int foo (void) { return 0; }]],
+			      [Fortran 77], [[
+      subroutine foo
+      end]],
+			      [Fortran], [[
+      subroutine foo
+      end]])])],
+	      [lt_cv_irix_exported_symbol=yes],
+	      [lt_cv_irix_exported_symbol=no])
+           LDFLAGS="$save_LDFLAGS"])
+	if test "$lt_cv_irix_exported_symbol" = yes; then
+          _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && func_echo_all "${wl}-set_version ${wl}$verstring"` ${wl}-update_registry ${wl}${output_objdir}/so_locations ${wl}-exports_file ${wl}$export_symbols -o $lib'
+	fi
+      else
+	_LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry ${output_objdir}/so_locations -o $lib'
+	_LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry ${output_objdir}/so_locations -exports_file $export_symbols -o $lib'
+      fi
+      _LT_TAGVAR(archive_cmds_need_lc, $1)='no'
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
+      _LT_TAGVAR(hardcode_libdir_separator, $1)=:
+      _LT_TAGVAR(inherit_rpath, $1)=yes
+      _LT_TAGVAR(link_all_deplibs, $1)=yes
+      ;;
+
+    netbsd* | netbsdelf*-gnu)
+      if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then
+	_LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags'  # a.out
+      else
+	_LT_TAGVAR(archive_cmds, $1)='$LD -shared -o $lib $libobjs $deplibs $linker_flags'      # ELF
+      fi
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
+      _LT_TAGVAR(hardcode_direct, $1)=yes
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      ;;
+
+    newsos6)
+      _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+      _LT_TAGVAR(hardcode_direct, $1)=yes
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
+      _LT_TAGVAR(hardcode_libdir_separator, $1)=:
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      ;;
+
+    *nto* | *qnx*)
+      ;;
+
+    openbsd*)
+      if test -f /usr/libexec/ld.so; then
+	_LT_TAGVAR(hardcode_direct, $1)=yes
+	_LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+	_LT_TAGVAR(hardcode_direct_absolute, $1)=yes
+	if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then
+	  _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags'
+	  _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags ${wl}-retain-symbols-file,$export_symbols'
+	  _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
+	  _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
+	else
+	  case $host_os in
+	   openbsd[[01]].* | openbsd2.[[0-7]] | openbsd2.[[0-7]].*)
+	     _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags'
+	     _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
+	     ;;
+	   *)
+	     _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags'
+	     _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
+	     ;;
+	  esac
+	fi
+      else
+	_LT_TAGVAR(ld_shlibs, $1)=no
+      fi
+      ;;
+
+    os2*)
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
+      _LT_TAGVAR(hardcode_minus_L, $1)=yes
+      _LT_TAGVAR(allow_undefined_flag, $1)=unsupported
+      _LT_TAGVAR(archive_cmds, $1)='$ECHO "LIBRARY $libname INITINSTANCE" > $output_objdir/$libname.def~$ECHO "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~echo DATA >> $output_objdir/$libname.def~echo " SINGLE NONSHARED" >> $output_objdir/$libname.def~echo EXPORTS >> $output_objdir/$libname.def~emxexp $libobjs >> $output_objdir/$libname.def~$CC -Zdll -Zcrtdll -o $lib $libobjs $deplibs $compiler_flags $output_objdir/$libname.def'
+      _LT_TAGVAR(old_archive_from_new_cmds, $1)='emximp -o $output_objdir/$libname.a $output_objdir/$libname.def'
+      ;;
+
+    osf3*)
+      if test "$GCC" = yes; then
+	_LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*'
+	_LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && func_echo_all "${wl}-set_version ${wl}$verstring"` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
+      else
+	_LT_TAGVAR(allow_undefined_flag, $1)=' -expect_unresolved \*'
+	_LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry ${output_objdir}/so_locations -o $lib'
+      fi
+      _LT_TAGVAR(archive_cmds_need_lc, $1)='no'
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
+      _LT_TAGVAR(hardcode_libdir_separator, $1)=:
+      ;;
+
+    osf4* | osf5*)	# as osf3* with the addition of -msym flag
+      if test "$GCC" = yes; then
+	_LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*'
+	_LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $pic_flag $libobjs $deplibs $compiler_flags ${wl}-msym ${wl}-soname ${wl}$soname `test -n "$verstring" && func_echo_all "${wl}-set_version ${wl}$verstring"` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
+	_LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
+      else
+	_LT_TAGVAR(allow_undefined_flag, $1)=' -expect_unresolved \*'
+	_LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags -msym -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry ${output_objdir}/so_locations -o $lib'
+	_LT_TAGVAR(archive_expsym_cmds, $1)='for i in `cat $export_symbols`; do printf "%s %s\\n" -exported_symbol "\$i" >> $lib.exp; done; printf "%s\\n" "-hidden">> $lib.exp~
+	$CC -shared${allow_undefined_flag} ${wl}-input ${wl}$lib.exp $compiler_flags $libobjs $deplibs -soname $soname `test -n "$verstring" && $ECHO "-set_version $verstring"` -update_registry ${output_objdir}/so_locations -o $lib~$RM $lib.exp'
+
+	# Both c and cxx compiler support -rpath directly
+	_LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-rpath $libdir'
+      fi
+      _LT_TAGVAR(archive_cmds_need_lc, $1)='no'
+      _LT_TAGVAR(hardcode_libdir_separator, $1)=:
+      ;;
+
+    solaris*)
+      _LT_TAGVAR(no_undefined_flag, $1)=' -z defs'
+      if test "$GCC" = yes; then
+	wlarc='${wl}'
+	_LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag ${wl}-z ${wl}text ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags'
+	_LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~
+	  $CC -shared $pic_flag ${wl}-z ${wl}text ${wl}-M ${wl}$lib.exp ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags~$RM $lib.exp'
+      else
+	case `$CC -V 2>&1` in
+	*"Compilers 5.0"*)
+	  wlarc=''
+	  _LT_TAGVAR(archive_cmds, $1)='$LD -G${allow_undefined_flag} -h $soname -o $lib $libobjs $deplibs $linker_flags'
+	  _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~
+	  $LD -G${allow_undefined_flag} -M $lib.exp -h $soname -o $lib $libobjs $deplibs $linker_flags~$RM $lib.exp'
+	  ;;
+	*)
+	  wlarc='${wl}'
+	  _LT_TAGVAR(archive_cmds, $1)='$CC -G${allow_undefined_flag} -h $soname -o $lib $libobjs $deplibs $compiler_flags'
+	  _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~
+	  $CC -G${allow_undefined_flag} -M $lib.exp -h $soname -o $lib $libobjs $deplibs $compiler_flags~$RM $lib.exp'
+	  ;;
+	esac
+      fi
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      case $host_os in
+      solaris2.[[0-5]] | solaris2.[[0-5]].*) ;;
+      *)
+	# The compiler driver will combine and reorder linker options,
+	# but understands `-z linker_flag'.  GCC discards it without `$wl',
+	# but is careful enough not to reorder.
+	# Supported since Solaris 2.6 (maybe 2.5.1?)
+	if test "$GCC" = yes; then
+	  _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}-z ${wl}allextract$convenience ${wl}-z ${wl}defaultextract'
+	else
+	  _LT_TAGVAR(whole_archive_flag_spec, $1)='-z allextract$convenience -z defaultextract'
+	fi
+	;;
+      esac
+      _LT_TAGVAR(link_all_deplibs, $1)=yes
+      ;;
+
+    sunos4*)
+      if test "x$host_vendor" = xsequent; then
+	# Use $CC to link under sequent, because it throws in some extra .o
+	# files that make .init and .fini sections work.
+	_LT_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h $soname -o $lib $libobjs $deplibs $compiler_flags'
+      else
+	_LT_TAGVAR(archive_cmds, $1)='$LD -assert pure-text -Bstatic -o $lib $libobjs $deplibs $linker_flags'
+      fi
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
+      _LT_TAGVAR(hardcode_direct, $1)=yes
+      _LT_TAGVAR(hardcode_minus_L, $1)=yes
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      ;;
+
+    sysv4)
+      case $host_vendor in
+	sni)
+	  _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+	  _LT_TAGVAR(hardcode_direct, $1)=yes # is this really true???
+	;;
+	siemens)
+	  ## LD is ld it makes a PLAMLIB
+	  ## CC just makes a GrossModule.
+	  _LT_TAGVAR(archive_cmds, $1)='$LD -G -o $lib $libobjs $deplibs $linker_flags'
+	  _LT_TAGVAR(reload_cmds, $1)='$CC -r -o $output$reload_objs'
+	  _LT_TAGVAR(hardcode_direct, $1)=no
+        ;;
+	motorola)
+	  _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+	  _LT_TAGVAR(hardcode_direct, $1)=no #Motorola manual says yes, but my tests say they lie
+	;;
+      esac
+      runpath_var='LD_RUN_PATH'
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      ;;
+
+    sysv4.3*)
+      _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      _LT_TAGVAR(export_dynamic_flag_spec, $1)='-Bexport'
+      ;;
+
+    sysv4*MP*)
+      if test -d /usr/nec; then
+	_LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+	_LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+	runpath_var=LD_RUN_PATH
+	hardcode_runpath_var=yes
+	_LT_TAGVAR(ld_shlibs, $1)=yes
+      fi
+      ;;
+
+    sysv4*uw2* | sysv5OpenUNIX* | sysv5UnixWare7.[[01]].[[10]]* | unixware7* | sco3.2v5.0.[[024]]*)
+      _LT_TAGVAR(no_undefined_flag, $1)='${wl}-z,text'
+      _LT_TAGVAR(archive_cmds_need_lc, $1)=no
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      runpath_var='LD_RUN_PATH'
+
+      if test "$GCC" = yes; then
+	_LT_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+	_LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+      else
+	_LT_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+	_LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+      fi
+      ;;
+
+    sysv5* | sco3.2v5* | sco5v6*)
+      # Note: We can NOT use -z defs as we might desire, because we do not
+      # link with -lc, and that would cause any symbols used from libc to
+      # always be unresolved, which means just about no library would
+      # ever link correctly.  If we're not using GNU ld we use -z text
+      # though, which does catch some bad symbols but isn't as heavy-handed
+      # as -z defs.
+      _LT_TAGVAR(no_undefined_flag, $1)='${wl}-z,text'
+      _LT_TAGVAR(allow_undefined_flag, $1)='${wl}-z,nodefs'
+      _LT_TAGVAR(archive_cmds_need_lc, $1)=no
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R,$libdir'
+      _LT_TAGVAR(hardcode_libdir_separator, $1)=':'
+      _LT_TAGVAR(link_all_deplibs, $1)=yes
+      _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-Bexport'
+      runpath_var='LD_RUN_PATH'
+
+      if test "$GCC" = yes; then
+	_LT_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+	_LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+      else
+	_LT_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+	_LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+      fi
+      ;;
+
+    uts4*)
+      _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      ;;
+
+    *)
+      _LT_TAGVAR(ld_shlibs, $1)=no
+      ;;
+    esac
+
+    if test x$host_vendor = xsni; then
+      case $host in
+      sysv4 | sysv4.2uw2* | sysv4.3* | sysv5*)
+	_LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-Blargedynsym'
+	;;
+      esac
+    fi
+  fi
+])
+AC_MSG_RESULT([$_LT_TAGVAR(ld_shlibs, $1)])
+test "$_LT_TAGVAR(ld_shlibs, $1)" = no && can_build_shared=no
+
+_LT_TAGVAR(with_gnu_ld, $1)=$with_gnu_ld
+
+_LT_DECL([], [libext], [0], [Old archive suffix (normally "a")])dnl
+_LT_DECL([], [shrext_cmds], [1], [Shared library suffix (normally ".so")])dnl
+_LT_DECL([], [extract_expsyms_cmds], [2],
+    [The commands to extract the exported symbol list from a shared archive])
+
+#
+# Do we need to explicitly link libc?
+#
+case "x$_LT_TAGVAR(archive_cmds_need_lc, $1)" in
+x|xyes)
+  # Assume -lc should be added
+  _LT_TAGVAR(archive_cmds_need_lc, $1)=yes
+
+  if test "$enable_shared" = yes && test "$GCC" = yes; then
+    case $_LT_TAGVAR(archive_cmds, $1) in
+    *'~'*)
+      # FIXME: we may have to deal with multi-command sequences.
+      ;;
+    '$CC '*)
+      # Test whether the compiler implicitly links with -lc since on some
+      # systems, -lgcc has to come before -lc. If gcc already passes -lc
+      # to ld, don't add -lc before -lgcc.
+      AC_CACHE_CHECK([whether -lc should be explicitly linked in],
+	[lt_cv_]_LT_TAGVAR(archive_cmds_need_lc, $1),
+	[$RM conftest*
+	echo "$lt_simple_compile_test_code" > conftest.$ac_ext
+
+	if AC_TRY_EVAL(ac_compile) 2>conftest.err; then
+	  soname=conftest
+	  lib=conftest
+	  libobjs=conftest.$ac_objext
+	  deplibs=
+	  wl=$_LT_TAGVAR(lt_prog_compiler_wl, $1)
+	  pic_flag=$_LT_TAGVAR(lt_prog_compiler_pic, $1)
+	  compiler_flags=-v
+	  linker_flags=-v
+	  verstring=
+	  output_objdir=.
+	  libname=conftest
+	  lt_save_allow_undefined_flag=$_LT_TAGVAR(allow_undefined_flag, $1)
+	  _LT_TAGVAR(allow_undefined_flag, $1)=
+	  if AC_TRY_EVAL(_LT_TAGVAR(archive_cmds, $1) 2\>\&1 \| $GREP \" -lc \" \>/dev/null 2\>\&1)
+	  then
+	    lt_cv_[]_LT_TAGVAR(archive_cmds_need_lc, $1)=no
+	  else
+	    lt_cv_[]_LT_TAGVAR(archive_cmds_need_lc, $1)=yes
+	  fi
+	  _LT_TAGVAR(allow_undefined_flag, $1)=$lt_save_allow_undefined_flag
+	else
+	  cat conftest.err 1>&5
+	fi
+	$RM conftest*
+	])
+      _LT_TAGVAR(archive_cmds_need_lc, $1)=$lt_cv_[]_LT_TAGVAR(archive_cmds_need_lc, $1)
+      ;;
+    esac
+  fi
+  ;;
+esac
+
+_LT_TAGDECL([build_libtool_need_lc], [archive_cmds_need_lc], [0],
+    [Whether or not to add -lc for building shared libraries])
+_LT_TAGDECL([allow_libtool_libs_with_static_runtimes],
+    [enable_shared_with_static_runtimes], [0],
+    [Whether or not to disallow shared libs when runtime libs are static])
+_LT_TAGDECL([], [export_dynamic_flag_spec], [1],
+    [Compiler flag to allow reflexive dlopens])
+_LT_TAGDECL([], [whole_archive_flag_spec], [1],
+    [Compiler flag to generate shared objects directly from archives])
+_LT_TAGDECL([], [compiler_needs_object], [1],
+    [Whether the compiler copes with passing no objects directly])
+_LT_TAGDECL([], [old_archive_from_new_cmds], [2],
+    [Create an old-style archive from a shared archive])
+_LT_TAGDECL([], [old_archive_from_expsyms_cmds], [2],
+    [Create a temporary old-style archive to link instead of a shared archive])
+_LT_TAGDECL([], [archive_cmds], [2], [Commands used to build a shared archive])
+_LT_TAGDECL([], [archive_expsym_cmds], [2])
+_LT_TAGDECL([], [module_cmds], [2],
+    [Commands used to build a loadable module if different from building
+    a shared archive.])
+_LT_TAGDECL([], [module_expsym_cmds], [2])
+_LT_TAGDECL([], [with_gnu_ld], [1],
+    [Whether we are building with GNU ld or not])
+_LT_TAGDECL([], [allow_undefined_flag], [1],
+    [Flag that allows shared libraries with undefined symbols to be built])
+_LT_TAGDECL([], [no_undefined_flag], [1],
+    [Flag that enforces no undefined symbols])
+_LT_TAGDECL([], [hardcode_libdir_flag_spec], [1],
+    [Flag to hardcode $libdir into a binary during linking.
+    This must work even if $libdir does not exist])
+_LT_TAGDECL([], [hardcode_libdir_separator], [1],
+    [Whether we need a single "-rpath" flag with a separated argument])
+_LT_TAGDECL([], [hardcode_direct], [0],
+    [Set to "yes" if using DIR/libNAME${shared_ext} during linking hardcodes
+    DIR into the resulting binary])
+_LT_TAGDECL([], [hardcode_direct_absolute], [0],
+    [Set to "yes" if using DIR/libNAME${shared_ext} during linking hardcodes
+    DIR into the resulting binary and the resulting library dependency is
+    "absolute", i.e impossible to change by setting ${shlibpath_var} if the
+    library is relocated])
+_LT_TAGDECL([], [hardcode_minus_L], [0],
+    [Set to "yes" if using the -LDIR flag during linking hardcodes DIR
+    into the resulting binary])
+_LT_TAGDECL([], [hardcode_shlibpath_var], [0],
+    [Set to "yes" if using SHLIBPATH_VAR=DIR during linking hardcodes DIR
+    into the resulting binary])
+_LT_TAGDECL([], [hardcode_automatic], [0],
+    [Set to "yes" if building a shared library automatically hardcodes DIR
+    into the library and all subsequent libraries and executables linked
+    against it])
+_LT_TAGDECL([], [inherit_rpath], [0],
+    [Set to yes if linker adds runtime paths of dependent libraries
+    to runtime path list])
+_LT_TAGDECL([], [link_all_deplibs], [0],
+    [Whether libtool must link a program against all its dependency libraries])
+_LT_TAGDECL([], [always_export_symbols], [0],
+    [Set to "yes" if exported symbols are required])
+_LT_TAGDECL([], [export_symbols_cmds], [2],
+    [The commands to list exported symbols])
+_LT_TAGDECL([], [exclude_expsyms], [1],
+    [Symbols that should not be listed in the preloaded symbols])
+_LT_TAGDECL([], [include_expsyms], [1],
+    [Symbols that must always be exported])
+_LT_TAGDECL([], [prelink_cmds], [2],
+    [Commands necessary for linking programs (against libraries) with templates])
+_LT_TAGDECL([], [postlink_cmds], [2],
+    [Commands necessary for finishing linking programs])
+_LT_TAGDECL([], [file_list_spec], [1],
+    [Specify filename containing input files])
+dnl FIXME: Not yet implemented
+dnl _LT_TAGDECL([], [thread_safe_flag_spec], [1],
+dnl    [Compiler flag to generate thread safe objects])
+])# _LT_LINKER_SHLIBS
+
+
+# _LT_LANG_C_CONFIG([TAG])
+# ------------------------
+# Ensure that the configuration variables for a C compiler are suitably
+# defined.  These variables are subsequently used by _LT_CONFIG to write
+# the compiler configuration to `libtool'.
+m4_defun([_LT_LANG_C_CONFIG],
+[m4_require([_LT_DECL_EGREP])dnl
+lt_save_CC="$CC"
+AC_LANG_PUSH(C)
+
+# Source file extension for C test sources.
+ac_ext=c
+
+# Object file extension for compiled C test sources.
+objext=o
+_LT_TAGVAR(objext, $1)=$objext
+
+# Code to be used in simple compile tests
+lt_simple_compile_test_code="int some_variable = 0;"
+
+# Code to be used in simple link tests
+lt_simple_link_test_code='int main(){return(0);}'
+
+_LT_TAG_COMPILER
+# Save the default compiler, since it gets overwritten when the other
+# tags are being tested, and _LT_TAGVAR(compiler, []) is a NOP.
+compiler_DEFAULT=$CC
+
+# save warnings/boilerplate of simple test code
+_LT_COMPILER_BOILERPLATE
+_LT_LINKER_BOILERPLATE
+
+if test -n "$compiler"; then
+  _LT_COMPILER_NO_RTTI($1)
+  _LT_COMPILER_PIC($1)
+  _LT_COMPILER_C_O($1)
+  _LT_COMPILER_FILE_LOCKS($1)
+  _LT_LINKER_SHLIBS($1)
+  _LT_SYS_DYNAMIC_LINKER($1)
+  _LT_LINKER_HARDCODE_LIBPATH($1)
+  LT_SYS_DLOPEN_SELF
+  _LT_CMD_STRIPLIB
+
+  # Report which library types will actually be built
+  AC_MSG_CHECKING([if libtool supports shared libraries])
+  AC_MSG_RESULT([$can_build_shared])
+
+  AC_MSG_CHECKING([whether to build shared libraries])
+  test "$can_build_shared" = "no" && enable_shared=no
+
+  # On AIX, shared libraries and static libraries use the same namespace, and
+  # are all built from PIC.
+  case $host_os in
+  aix3*)
+    test "$enable_shared" = yes && enable_static=no
+    if test -n "$RANLIB"; then
+      archive_cmds="$archive_cmds~\$RANLIB \$lib"
+      postinstall_cmds='$RANLIB $lib'
+    fi
+    ;;
+
+  aix[[4-9]]*)
+    if test "$host_cpu" != ia64 && test "$aix_use_runtimelinking" = no ; then
+      test "$enable_shared" = yes && enable_static=no
+    fi
+    ;;
+  esac
+  AC_MSG_RESULT([$enable_shared])
+
+  AC_MSG_CHECKING([whether to build static libraries])
+  # Make sure either enable_shared or enable_static is yes.
+  test "$enable_shared" = yes || enable_static=yes
+  AC_MSG_RESULT([$enable_static])
+
+  _LT_CONFIG($1)
+fi
+AC_LANG_POP
+CC="$lt_save_CC"
+])# _LT_LANG_C_CONFIG
+
+
+# _LT_LANG_CXX_CONFIG([TAG])
+# --------------------------
+# Ensure that the configuration variables for a C++ compiler are suitably
+# defined.  These variables are subsequently used by _LT_CONFIG to write
+# the compiler configuration to `libtool'.
+m4_defun([_LT_LANG_CXX_CONFIG],
+[m4_require([_LT_FILEUTILS_DEFAULTS])dnl
+m4_require([_LT_DECL_EGREP])dnl
+m4_require([_LT_PATH_MANIFEST_TOOL])dnl
+if test -n "$CXX" && ( test "X$CXX" != "Xno" &&
+    ( (test "X$CXX" = "Xg++" && `g++ -v >/dev/null 2>&1` ) ||
+    (test "X$CXX" != "Xg++"))) ; then
+  AC_PROG_CXXCPP
+else
+  _lt_caught_CXX_error=yes
+fi
+
+AC_LANG_PUSH(C++)
+_LT_TAGVAR(archive_cmds_need_lc, $1)=no
+_LT_TAGVAR(allow_undefined_flag, $1)=
+_LT_TAGVAR(always_export_symbols, $1)=no
+_LT_TAGVAR(archive_expsym_cmds, $1)=
+_LT_TAGVAR(compiler_needs_object, $1)=no
+_LT_TAGVAR(export_dynamic_flag_spec, $1)=
+_LT_TAGVAR(hardcode_direct, $1)=no
+_LT_TAGVAR(hardcode_direct_absolute, $1)=no
+_LT_TAGVAR(hardcode_libdir_flag_spec, $1)=
+_LT_TAGVAR(hardcode_libdir_separator, $1)=
+_LT_TAGVAR(hardcode_minus_L, $1)=no
+_LT_TAGVAR(hardcode_shlibpath_var, $1)=unsupported
+_LT_TAGVAR(hardcode_automatic, $1)=no
+_LT_TAGVAR(inherit_rpath, $1)=no
+_LT_TAGVAR(module_cmds, $1)=
+_LT_TAGVAR(module_expsym_cmds, $1)=
+_LT_TAGVAR(link_all_deplibs, $1)=unknown
+_LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds
+_LT_TAGVAR(reload_flag, $1)=$reload_flag
+_LT_TAGVAR(reload_cmds, $1)=$reload_cmds
+_LT_TAGVAR(no_undefined_flag, $1)=
+_LT_TAGVAR(whole_archive_flag_spec, $1)=
+_LT_TAGVAR(enable_shared_with_static_runtimes, $1)=no
+
+# Source file extension for C++ test sources.
+ac_ext=cpp
+
+# Object file extension for compiled C++ test sources.
+objext=o
+_LT_TAGVAR(objext, $1)=$objext
+
+# No sense in running all these tests if we already determined that
+# the CXX compiler isn't working.  Some variables (like enable_shared)
+# are currently assumed to apply to all compilers on this platform,
+# and will be corrupted by setting them based on a non-working compiler.
+if test "$_lt_caught_CXX_error" != yes; then
+  # Code to be used in simple compile tests
+  lt_simple_compile_test_code="int some_variable = 0;"
+
+  # Code to be used in simple link tests
+  lt_simple_link_test_code='int main(int, char *[[]]) { return(0); }'
+
+  # ltmain only uses $CC for tagged configurations so make sure $CC is set.
+  _LT_TAG_COMPILER
+
+  # save warnings/boilerplate of simple test code
+  _LT_COMPILER_BOILERPLATE
+  _LT_LINKER_BOILERPLATE
+
+  # Allow CC to be a program name with arguments.
+  lt_save_CC=$CC
+  lt_save_CFLAGS=$CFLAGS
+  lt_save_LD=$LD
+  lt_save_GCC=$GCC
+  GCC=$GXX
+  lt_save_with_gnu_ld=$with_gnu_ld
+  lt_save_path_LD=$lt_cv_path_LD
+  if test -n "${lt_cv_prog_gnu_ldcxx+set}"; then
+    lt_cv_prog_gnu_ld=$lt_cv_prog_gnu_ldcxx
+  else
+    $as_unset lt_cv_prog_gnu_ld
+  fi
+  if test -n "${lt_cv_path_LDCXX+set}"; then
+    lt_cv_path_LD=$lt_cv_path_LDCXX
+  else
+    $as_unset lt_cv_path_LD
+  fi
+  test -z "${LDCXX+set}" || LD=$LDCXX
+  CC=${CXX-"c++"}
+  CFLAGS=$CXXFLAGS
+  compiler=$CC
+  _LT_TAGVAR(compiler, $1)=$CC
+  _LT_CC_BASENAME([$compiler])
+
+  if test -n "$compiler"; then
+    # We don't want -fno-exception when compiling C++ code, so set the
+    # no_builtin_flag separately
+    if test "$GXX" = yes; then
+      _LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)=' -fno-builtin'
+    else
+      _LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)=
+    fi
+
+    if test "$GXX" = yes; then
+      # Set up default GNU C++ configuration
+
+      LT_PATH_LD
+
+      # Check if GNU C++ uses GNU ld as the underlying linker, since the
+      # archiving commands below assume that GNU ld is being used.
+      if test "$with_gnu_ld" = yes; then
+        _LT_TAGVAR(archive_cmds, $1)='$CC $pic_flag -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname -o $lib'
+        _LT_TAGVAR(archive_expsym_cmds, $1)='$CC $pic_flag -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
+
+        _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
+        _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic'
+
+        # If archive_cmds runs LD, not CC, wlarc should be empty
+        # XXX I think wlarc can be eliminated in ltcf-cxx, but I need to
+        #     investigate it a little bit more. (MM)
+        wlarc='${wl}'
+
+        # ancient GNU ld didn't support --whole-archive et. al.
+        if eval "`$CC -print-prog-name=ld` --help 2>&1" |
+	  $GREP 'no-whole-archive' > /dev/null; then
+          _LT_TAGVAR(whole_archive_flag_spec, $1)="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive'
+        else
+          _LT_TAGVAR(whole_archive_flag_spec, $1)=
+        fi
+      else
+        with_gnu_ld=no
+        wlarc=
+
+        # A generic and very simple default shared library creation
+        # command for GNU C++ for the case where it uses the native
+        # linker, instead of GNU ld.  If possible, this setting should
+        # overridden to take advantage of the native linker features on
+        # the platform it is being used on.
+        _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $lib'
+      fi
+
+      # Commands to make compiler produce verbose output that lists
+      # what "hidden" libraries, object files and flags are used when
+      # linking a shared library.
+      output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"'
+
+    else
+      GXX=no
+      with_gnu_ld=no
+      wlarc=
+    fi
+
+    # PORTME: fill in a description of your system's C++ link characteristics
+    AC_MSG_CHECKING([whether the $compiler linker ($LD) supports shared libraries])
+    _LT_TAGVAR(ld_shlibs, $1)=yes
+    case $host_os in
+      aix3*)
+        # FIXME: insert proper C++ library support
+        _LT_TAGVAR(ld_shlibs, $1)=no
+        ;;
+      aix[[4-9]]*)
+        if test "$host_cpu" = ia64; then
+          # On IA64, the linker does run time linking by default, so we don't
+          # have to do anything special.
+          aix_use_runtimelinking=no
+          exp_sym_flag='-Bexport'
+          no_entry_flag=""
+        else
+          aix_use_runtimelinking=no
+
+          # Test if we are trying to use run time linking or normal
+          # AIX style linking. If -brtl is somewhere in LDFLAGS, we
+          # need to do runtime linking.
+          case $host_os in aix4.[[23]]|aix4.[[23]].*|aix[[5-9]]*)
+	    for ld_flag in $LDFLAGS; do
+	      case $ld_flag in
+	      *-brtl*)
+	        aix_use_runtimelinking=yes
+	        break
+	        ;;
+	      esac
+	    done
+	    ;;
+          esac
+
+          exp_sym_flag='-bexport'
+          no_entry_flag='-bnoentry'
+        fi
+
+        # When large executables or shared objects are built, AIX ld can
+        # have problems creating the table of contents.  If linking a library
+        # or program results in "error TOC overflow" add -mminimal-toc to
+        # CXXFLAGS/CFLAGS for g++/gcc.  In the cases where that is not
+        # enough to fix the problem, add -Wl,-bbigtoc to LDFLAGS.
+
+        _LT_TAGVAR(archive_cmds, $1)=''
+        _LT_TAGVAR(hardcode_direct, $1)=yes
+        _LT_TAGVAR(hardcode_direct_absolute, $1)=yes
+        _LT_TAGVAR(hardcode_libdir_separator, $1)=':'
+        _LT_TAGVAR(link_all_deplibs, $1)=yes
+        _LT_TAGVAR(file_list_spec, $1)='${wl}-f,'
+
+        if test "$GXX" = yes; then
+          case $host_os in aix4.[[012]]|aix4.[[012]].*)
+          # We only want to do this on AIX 4.2 and lower, the check
+          # below for broken collect2 doesn't work under 4.3+
+	  collect2name=`${CC} -print-prog-name=collect2`
+	  if test -f "$collect2name" &&
+	     strings "$collect2name" | $GREP resolve_lib_name >/dev/null
+	  then
+	    # We have reworked collect2
+	    :
+	  else
+	    # We have old collect2
+	    _LT_TAGVAR(hardcode_direct, $1)=unsupported
+	    # It fails to find uninstalled libraries when the uninstalled
+	    # path is not listed in the libpath.  Setting hardcode_minus_L
+	    # to unsupported forces relinking
+	    _LT_TAGVAR(hardcode_minus_L, $1)=yes
+	    _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
+	    _LT_TAGVAR(hardcode_libdir_separator, $1)=
+	  fi
+          esac
+          shared_flag='-shared'
+	  if test "$aix_use_runtimelinking" = yes; then
+	    shared_flag="$shared_flag "'${wl}-G'
+	  fi
+        else
+          # not using gcc
+          if test "$host_cpu" = ia64; then
+	  # VisualAge C++, Version 5.5 for AIX 5L for IA-64, Beta 3 Release
+	  # chokes on -Wl,-G. The following line is correct:
+	  shared_flag='-G'
+          else
+	    if test "$aix_use_runtimelinking" = yes; then
+	      shared_flag='${wl}-G'
+	    else
+	      shared_flag='${wl}-bM:SRE'
+	    fi
+          fi
+        fi
+
+        _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-bexpall'
+        # It seems that -bexpall does not export symbols beginning with
+        # underscore (_), so it is better to generate a list of symbols to
+	# export.
+        _LT_TAGVAR(always_export_symbols, $1)=yes
+        if test "$aix_use_runtimelinking" = yes; then
+          # Warning - without using the other runtime loading flags (-brtl),
+          # -berok will link without error, but may produce a broken library.
+          _LT_TAGVAR(allow_undefined_flag, $1)='-berok'
+          # Determine the default libpath from the value encoded in an empty
+          # executable.
+          _LT_SYS_MODULE_PATH_AIX([$1])
+          _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-blibpath:$libdir:'"$aix_libpath"
+
+          _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags `if test "x${allow_undefined_flag}" != "x"; then func_echo_all "${wl}${allow_undefined_flag}"; else :; fi` '"\${wl}$exp_sym_flag:\$export_symbols $shared_flag"
+        else
+          if test "$host_cpu" = ia64; then
+	    _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R $libdir:/usr/lib:/lib'
+	    _LT_TAGVAR(allow_undefined_flag, $1)="-z nodefs"
+	    _LT_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags ${wl}${allow_undefined_flag} '"\${wl}$exp_sym_flag:\$export_symbols"
+          else
+	    # Determine the default libpath from the value encoded in an
+	    # empty executable.
+	    _LT_SYS_MODULE_PATH_AIX([$1])
+	    _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-blibpath:$libdir:'"$aix_libpath"
+	    # Warning - without using the other run time loading flags,
+	    # -berok will link without error, but may produce a broken library.
+	    _LT_TAGVAR(no_undefined_flag, $1)=' ${wl}-bernotok'
+	    _LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-berok'
+	    if test "$with_gnu_ld" = yes; then
+	      # We only use this code for GNU lds that support --whole-archive.
+	      _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive$convenience ${wl}--no-whole-archive'
+	    else
+	      # Exported symbols can be pulled into shared objects from archives
+	      _LT_TAGVAR(whole_archive_flag_spec, $1)='$convenience'
+	    fi
+	    _LT_TAGVAR(archive_cmds_need_lc, $1)=yes
+	    # This is similar to how AIX traditionally builds its shared
+	    # libraries.
+	    _LT_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs ${wl}-bnoentry $compiler_flags ${wl}-bE:$export_symbols${allow_undefined_flag}~$AR $AR_FLAGS $output_objdir/$libname$release.a $output_objdir/$soname'
+          fi
+        fi
+        ;;
+
+      beos*)
+	if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then
+	  _LT_TAGVAR(allow_undefined_flag, $1)=unsupported
+	  # Joseph Beckenbach <jrb3@best.com> says some releases of gcc
+	  # support --undefined.  This deserves some investigation.  FIXME
+	  _LT_TAGVAR(archive_cmds, $1)='$CC -nostart $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+	else
+	  _LT_TAGVAR(ld_shlibs, $1)=no
+	fi
+	;;
+
+      chorus*)
+        case $cc_basename in
+          *)
+	  # FIXME: insert proper C++ library support
+	  _LT_TAGVAR(ld_shlibs, $1)=no
+	  ;;
+        esac
+        ;;
+
+      cygwin* | mingw* | pw32* | cegcc*)
+	case $GXX,$cc_basename in
+	,cl* | no,cl*)
+	  # Native MSVC
+	  # hardcode_libdir_flag_spec is actually meaningless, as there is
+	  # no search path for DLLs.
+	  _LT_TAGVAR(hardcode_libdir_flag_spec, $1)=' '
+	  _LT_TAGVAR(allow_undefined_flag, $1)=unsupported
+	  _LT_TAGVAR(always_export_symbols, $1)=yes
+	  _LT_TAGVAR(file_list_spec, $1)='@'
+	  # Tell ltmain to make .lib files, not .a files.
+	  libext=lib
+	  # Tell ltmain to make .dll files, not .so files.
+	  shrext_cmds=".dll"
+	  # FIXME: Setting linknames here is a bad hack.
+	  _LT_TAGVAR(archive_cmds, $1)='$CC -o $output_objdir/$soname $libobjs $compiler_flags $deplibs -Wl,-dll~linknames='
+	  _LT_TAGVAR(archive_expsym_cmds, $1)='if test "x`$SED 1q $export_symbols`" = xEXPORTS; then
+	      $SED -n -e 's/\\\\\\\(.*\\\\\\\)/-link\\\ -EXPORT:\\\\\\\1/' -e '1\\\!p' < $export_symbols > $output_objdir/$soname.exp;
+	    else
+	      $SED -e 's/\\\\\\\(.*\\\\\\\)/-link\\\ -EXPORT:\\\\\\\1/' < $export_symbols > $output_objdir/$soname.exp;
+	    fi~
+	    $CC -o $tool_output_objdir$soname $libobjs $compiler_flags $deplibs "@$tool_output_objdir$soname.exp" -Wl,-DLL,-IMPLIB:"$tool_output_objdir$libname.dll.lib"~
+	    linknames='
+	  # The linker will not automatically build a static lib if we build a DLL.
+	  # _LT_TAGVAR(old_archive_from_new_cmds, $1)='true'
+	  _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes
+	  # Don't use ranlib
+	  _LT_TAGVAR(old_postinstall_cmds, $1)='chmod 644 $oldlib'
+	  _LT_TAGVAR(postlink_cmds, $1)='lt_outputfile="@OUTPUT@"~
+	    lt_tool_outputfile="@TOOL_OUTPUT@"~
+	    case $lt_outputfile in
+	      *.exe|*.EXE) ;;
+	      *)
+		lt_outputfile="$lt_outputfile.exe"
+		lt_tool_outputfile="$lt_tool_outputfile.exe"
+		;;
+	    esac~
+	    func_to_tool_file "$lt_outputfile"~
+	    if test "$MANIFEST_TOOL" != ":" && test -f "$lt_outputfile.manifest"; then
+	      $MANIFEST_TOOL -manifest "$lt_tool_outputfile.manifest" -outputresource:"$lt_tool_outputfile" || exit 1;
+	      $RM "$lt_outputfile.manifest";
+	    fi'
+	  ;;
+	*)
+	  # g++
+	  # _LT_TAGVAR(hardcode_libdir_flag_spec, $1) is actually meaningless,
+	  # as there is no search path for DLLs.
+	  _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
+	  _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-all-symbols'
+	  _LT_TAGVAR(allow_undefined_flag, $1)=unsupported
+	  _LT_TAGVAR(always_export_symbols, $1)=no
+	  _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes
+
+	  if $LD --help 2>&1 | $GREP 'auto-import' > /dev/null; then
+	    _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib'
+	    # If the export-symbols file already is a .def file (1st line
+	    # is EXPORTS), use it as is; otherwise, prepend...
+	    _LT_TAGVAR(archive_expsym_cmds, $1)='if test "x`$SED 1q $export_symbols`" = xEXPORTS; then
+	      cp $export_symbols $output_objdir/$soname.def;
+	    else
+	      echo EXPORTS > $output_objdir/$soname.def;
+	      cat $export_symbols >> $output_objdir/$soname.def;
+	    fi~
+	    $CC -shared -nostdlib $output_objdir/$soname.def $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib'
+	  else
+	    _LT_TAGVAR(ld_shlibs, $1)=no
+	  fi
+	  ;;
+	esac
+	;;
+      darwin* | rhapsody*)
+        _LT_DARWIN_LINKER_FEATURES($1)
+	;;
+
+      dgux*)
+        case $cc_basename in
+          ec++*)
+	    # FIXME: insert proper C++ library support
+	    _LT_TAGVAR(ld_shlibs, $1)=no
+	    ;;
+          ghcx*)
+	    # Green Hills C++ Compiler
+	    # FIXME: insert proper C++ library support
+	    _LT_TAGVAR(ld_shlibs, $1)=no
+	    ;;
+          *)
+	    # FIXME: insert proper C++ library support
+	    _LT_TAGVAR(ld_shlibs, $1)=no
+	    ;;
+        esac
+        ;;
+
+      freebsd2.*)
+        # C++ shared libraries reported to be fairly broken before
+	# switch to ELF
+        _LT_TAGVAR(ld_shlibs, $1)=no
+        ;;
+
+      freebsd-elf*)
+        _LT_TAGVAR(archive_cmds_need_lc, $1)=no
+        ;;
+
+      freebsd* | dragonfly*)
+        # FreeBSD 3 and later use GNU C++ and GNU ld with standard ELF
+        # conventions
+        _LT_TAGVAR(ld_shlibs, $1)=yes
+        ;;
+
+      haiku*)
+        _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+        _LT_TAGVAR(link_all_deplibs, $1)=yes
+        ;;
+
+      hpux9*)
+        _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir'
+        _LT_TAGVAR(hardcode_libdir_separator, $1)=:
+        _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
+        _LT_TAGVAR(hardcode_direct, $1)=yes
+        _LT_TAGVAR(hardcode_minus_L, $1)=yes # Not in the search PATH,
+				             # but as the default
+				             # location of the library.
+
+        case $cc_basename in
+          CC*)
+            # FIXME: insert proper C++ library support
+            _LT_TAGVAR(ld_shlibs, $1)=no
+            ;;
+          aCC*)
+            _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/$soname~$CC -b ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib'
+            # Commands to make compiler produce verbose output that lists
+            # what "hidden" libraries, object files and flags are used when
+            # linking a shared library.
+            #
+            # There doesn't appear to be a way to prevent this compiler from
+            # explicitly linking system object files so we need to strip them
+            # from the output so that they don't get included in the library
+            # dependencies.
+            output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $EGREP "\-L"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"'
+            ;;
+          *)
+            if test "$GXX" = yes; then
+              _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/$soname~$CC -shared -nostdlib $pic_flag ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib'
+            else
+              # FIXME: insert proper C++ library support
+              _LT_TAGVAR(ld_shlibs, $1)=no
+            fi
+            ;;
+        esac
+        ;;
+
+      hpux10*|hpux11*)
+        if test $with_gnu_ld = no; then
+	  _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir'
+	  _LT_TAGVAR(hardcode_libdir_separator, $1)=:
+
+          case $host_cpu in
+            hppa*64*|ia64*)
+              ;;
+            *)
+	      _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
+              ;;
+          esac
+        fi
+        case $host_cpu in
+          hppa*64*|ia64*)
+            _LT_TAGVAR(hardcode_direct, $1)=no
+            _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+            ;;
+          *)
+            _LT_TAGVAR(hardcode_direct, $1)=yes
+            _LT_TAGVAR(hardcode_direct_absolute, $1)=yes
+            _LT_TAGVAR(hardcode_minus_L, $1)=yes # Not in the search PATH,
+					         # but as the default
+					         # location of the library.
+            ;;
+        esac
+
+        case $cc_basename in
+          CC*)
+	    # FIXME: insert proper C++ library support
+	    _LT_TAGVAR(ld_shlibs, $1)=no
+	    ;;
+          aCC*)
+	    case $host_cpu in
+	      hppa*64*)
+	        _LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
+	        ;;
+	      ia64*)
+	        _LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
+	        ;;
+	      *)
+	        _LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
+	        ;;
+	    esac
+	    # Commands to make compiler produce verbose output that lists
+	    # what "hidden" libraries, object files and flags are used when
+	    # linking a shared library.
+	    #
+	    # There doesn't appear to be a way to prevent this compiler from
+	    # explicitly linking system object files so we need to strip them
+	    # from the output so that they don't get included in the library
+	    # dependencies.
+	    output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $GREP "\-L"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"'
+	    ;;
+          *)
+	    if test "$GXX" = yes; then
+	      if test $with_gnu_ld = no; then
+	        case $host_cpu in
+	          hppa*64*)
+	            _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib -fPIC ${wl}+h ${wl}$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
+	            ;;
+	          ia64*)
+	            _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $pic_flag ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
+	            ;;
+	          *)
+	            _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $pic_flag ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
+	            ;;
+	        esac
+	      fi
+	    else
+	      # FIXME: insert proper C++ library support
+	      _LT_TAGVAR(ld_shlibs, $1)=no
+	    fi
+	    ;;
+        esac
+        ;;
+
+      interix[[3-9]]*)
+	_LT_TAGVAR(hardcode_direct, $1)=no
+	_LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+	_LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
+	_LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
+	# Hack: On Interix 3.x, we cannot compile PIC because of a broken gcc.
+	# Instead, shared libraries are loaded at an image base (0x10000000 by
+	# default) and relocated if they conflict, which is a slow very memory
+	# consuming and fragmenting process.  To avoid this, we pick a random,
+	# 256 KiB-aligned image base between 0x50000000 and 0x6FFC0000 at link
+	# time.  Moving up from 0x10000000 also allows more sbrk(2) space.
+	_LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib'
+	_LT_TAGVAR(archive_expsym_cmds, $1)='sed "s,^,_," $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--retain-symbols-file,$output_objdir/$soname.expsym ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib'
+	;;
+      irix5* | irix6*)
+        case $cc_basename in
+          CC*)
+	    # SGI C++
+	    _LT_TAGVAR(archive_cmds, $1)='$CC -shared -all -multigot $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry ${output_objdir}/so_locations -o $lib'
+
+	    # Archives containing C++ object files must be created using
+	    # "CC -ar", where "CC" is the IRIX C++ compiler.  This is
+	    # necessary to make sure instantiated templates are included
+	    # in the archive.
+	    _LT_TAGVAR(old_archive_cmds, $1)='$CC -ar -WR,-u -o $oldlib $oldobjs'
+	    ;;
+          *)
+	    if test "$GXX" = yes; then
+	      if test "$with_gnu_ld" = no; then
+	        _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && func_echo_all "${wl}-set_version ${wl}$verstring"` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
+	      else
+	        _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && func_echo_all "${wl}-set_version ${wl}$verstring"` -o $lib'
+	      fi
+	    fi
+	    _LT_TAGVAR(link_all_deplibs, $1)=yes
+	    ;;
+        esac
+        _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
+        _LT_TAGVAR(hardcode_libdir_separator, $1)=:
+        _LT_TAGVAR(inherit_rpath, $1)=yes
+        ;;
+
+      linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*)
+        case $cc_basename in
+          KCC*)
+	    # Kuck and Associates, Inc. (KAI) C++ Compiler
+
+	    # KCC will only create a shared library if the output file
+	    # ends with ".so" (or ".sl" for HP-UX), so rename the library
+	    # to its proper name (with version) after linking.
+	    _LT_TAGVAR(archive_cmds, $1)='tempext=`echo $shared_ext | $SED -e '\''s/\([[^()0-9A-Za-z{}]]\)/\\\\\1/g'\''`; templib=`echo $lib | $SED -e "s/\${tempext}\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib; mv \$templib $lib'
+	    _LT_TAGVAR(archive_expsym_cmds, $1)='tempext=`echo $shared_ext | $SED -e '\''s/\([[^()0-9A-Za-z{}]]\)/\\\\\1/g'\''`; templib=`echo $lib | $SED -e "s/\${tempext}\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib ${wl}-retain-symbols-file,$export_symbols; mv \$templib $lib'
+	    # Commands to make compiler produce verbose output that lists
+	    # what "hidden" libraries, object files and flags are used when
+	    # linking a shared library.
+	    #
+	    # There doesn't appear to be a way to prevent this compiler from
+	    # explicitly linking system object files so we need to strip them
+	    # from the output so that they don't get included in the library
+	    # dependencies.
+	    output_verbose_link_cmd='templist=`$CC $CFLAGS -v conftest.$objext -o libconftest$shared_ext 2>&1 | $GREP "ld"`; rm -f libconftest$shared_ext; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"'
+
+	    _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
+	    _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic'
+
+	    # Archives containing C++ object files must be created using
+	    # "CC -Bstatic", where "CC" is the KAI C++ compiler.
+	    _LT_TAGVAR(old_archive_cmds, $1)='$CC -Bstatic -o $oldlib $oldobjs'
+	    ;;
+	  icpc* | ecpc* )
+	    # Intel C++
+	    with_gnu_ld=yes
+	    # version 8.0 and above of icpc choke on multiply defined symbols
+	    # if we add $predep_objects and $postdep_objects, however 7.1 and
+	    # earlier do not add the objects themselves.
+	    case `$CC -V 2>&1` in
+	      *"Version 7."*)
+	        _LT_TAGVAR(archive_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname -o $lib'
+		_LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
+		;;
+	      *)  # Version 8.0 or newer
+	        tmp_idyn=
+	        case $host_cpu in
+		  ia64*) tmp_idyn=' -i_dynamic';;
+		esac
+	        _LT_TAGVAR(archive_cmds, $1)='$CC -shared'"$tmp_idyn"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+		_LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared'"$tmp_idyn"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
+		;;
+	    esac
+	    _LT_TAGVAR(archive_cmds_need_lc, $1)=no
+	    _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
+	    _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic'
+	    _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive$convenience ${wl}--no-whole-archive'
+	    ;;
+          pgCC* | pgcpp*)
+            # Portland Group C++ compiler
+	    case `$CC -V` in
+	    *pgCC\ [[1-5]].* | *pgcpp\ [[1-5]].*)
+	      _LT_TAGVAR(prelink_cmds, $1)='tpldir=Template.dir~
+		rm -rf $tpldir~
+		$CC --prelink_objects --instantiation_dir $tpldir $objs $libobjs $compile_deplibs~
+		compile_command="$compile_command `find $tpldir -name \*.o | sort | $NL2SP`"'
+	      _LT_TAGVAR(old_archive_cmds, $1)='tpldir=Template.dir~
+		rm -rf $tpldir~
+		$CC --prelink_objects --instantiation_dir $tpldir $oldobjs$old_deplibs~
+		$AR $AR_FLAGS $oldlib$oldobjs$old_deplibs `find $tpldir -name \*.o | sort | $NL2SP`~
+		$RANLIB $oldlib'
+	      _LT_TAGVAR(archive_cmds, $1)='tpldir=Template.dir~
+		rm -rf $tpldir~
+		$CC --prelink_objects --instantiation_dir $tpldir $predep_objects $libobjs $deplibs $convenience $postdep_objects~
+		$CC -shared $pic_flag $predep_objects $libobjs $deplibs `find $tpldir -name \*.o | sort | $NL2SP` $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname -o $lib'
+	      _LT_TAGVAR(archive_expsym_cmds, $1)='tpldir=Template.dir~
+		rm -rf $tpldir~
+		$CC --prelink_objects --instantiation_dir $tpldir $predep_objects $libobjs $deplibs $convenience $postdep_objects~
+		$CC -shared $pic_flag $predep_objects $libobjs $deplibs `find $tpldir -name \*.o | sort | $NL2SP` $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname ${wl}-retain-symbols-file ${wl}$export_symbols -o $lib'
+	      ;;
+	    *) # Version 6 and above use weak symbols
+	      _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname -o $lib'
+	      _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname ${wl}-retain-symbols-file ${wl}$export_symbols -o $lib'
+	      ;;
+	    esac
+
+	    _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}--rpath ${wl}$libdir'
+	    _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic'
+	    _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`for conv in $convenience\"\"; do test  -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` ${wl}--no-whole-archive'
+            ;;
+	  cxx*)
+	    # Compaq C++
+	    _LT_TAGVAR(archive_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname -o $lib'
+	    _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname  -o $lib ${wl}-retain-symbols-file $wl$export_symbols'
+
+	    runpath_var=LD_RUN_PATH
+	    _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-rpath $libdir'
+	    _LT_TAGVAR(hardcode_libdir_separator, $1)=:
+
+	    # Commands to make compiler produce verbose output that lists
+	    # what "hidden" libraries, object files and flags are used when
+	    # linking a shared library.
+	    #
+	    # There doesn't appear to be a way to prevent this compiler from
+	    # explicitly linking system object files so we need to strip them
+	    # from the output so that they don't get included in the library
+	    # dependencies.
+	    output_verbose_link_cmd='templist=`$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP "ld"`; templist=`func_echo_all "$templist" | $SED "s/\(^.*ld.*\)\( .*ld .*$\)/\1/"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "X$list" | $Xsed'
+	    ;;
+	  xl* | mpixl* | bgxl*)
+	    # IBM XL 8.0 on PPC, with GNU ld
+	    _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
+	    _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic'
+	    _LT_TAGVAR(archive_cmds, $1)='$CC -qmkshrobj $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+	    if test "x$supports_anon_versioning" = xyes; then
+	      _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $output_objdir/$libname.ver~
+		cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~
+		echo "local: *; };" >> $output_objdir/$libname.ver~
+		$CC -qmkshrobj $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-version-script ${wl}$output_objdir/$libname.ver -o $lib'
+	    fi
+	    ;;
+	  *)
+	    case `$CC -V 2>&1 | sed 5q` in
+	    *Sun\ C*)
+	      # Sun C++ 5.9
+	      _LT_TAGVAR(no_undefined_flag, $1)=' -zdefs'
+	      _LT_TAGVAR(archive_cmds, $1)='$CC -G${allow_undefined_flag} -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
+	      _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G${allow_undefined_flag} -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-retain-symbols-file ${wl}$export_symbols'
+	      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
+	      _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`new_convenience=; for conv in $convenience\"\"; do test -z \"$conv\" || new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` ${wl}--no-whole-archive'
+	      _LT_TAGVAR(compiler_needs_object, $1)=yes
+
+	      # Not sure whether something based on
+	      # $CC $CFLAGS -v conftest.$objext -o libconftest$shared_ext 2>&1
+	      # would be better.
+	      output_verbose_link_cmd='func_echo_all'
+
+	      # Archives containing C++ object files must be created using
+	      # "CC -xar", where "CC" is the Sun C++ compiler.  This is
+	      # necessary to make sure instantiated templates are included
+	      # in the archive.
+	      _LT_TAGVAR(old_archive_cmds, $1)='$CC -xar -o $oldlib $oldobjs'
+	      ;;
+	    esac
+	    ;;
+	esac
+	;;
+
+      lynxos*)
+        # FIXME: insert proper C++ library support
+	_LT_TAGVAR(ld_shlibs, $1)=no
+	;;
+
+      m88k*)
+        # FIXME: insert proper C++ library support
+        _LT_TAGVAR(ld_shlibs, $1)=no
+	;;
+
+      mvs*)
+        case $cc_basename in
+          cxx*)
+	    # FIXME: insert proper C++ library support
+	    _LT_TAGVAR(ld_shlibs, $1)=no
+	    ;;
+	  *)
+	    # FIXME: insert proper C++ library support
+	    _LT_TAGVAR(ld_shlibs, $1)=no
+	    ;;
+	esac
+	;;
+
+      netbsd*)
+        if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then
+	  _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable  -o $lib $predep_objects $libobjs $deplibs $postdep_objects $linker_flags'
+	  wlarc=
+	  _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
+	  _LT_TAGVAR(hardcode_direct, $1)=yes
+	  _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+	fi
+	# Workaround some broken pre-1.5 toolchains
+	output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP conftest.$objext | $SED -e "s:-lgcc -lc -lgcc::"'
+	;;
+
+      *nto* | *qnx*)
+        _LT_TAGVAR(ld_shlibs, $1)=yes
+	;;
+
+      openbsd2*)
+        # C++ shared libraries are fairly broken
+	_LT_TAGVAR(ld_shlibs, $1)=no
+	;;
+
+      openbsd*)
+	if test -f /usr/libexec/ld.so; then
+	  _LT_TAGVAR(hardcode_direct, $1)=yes
+	  _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+	  _LT_TAGVAR(hardcode_direct_absolute, $1)=yes
+	  _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $lib'
+	  _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
+	  if test -z "`echo __ELF__ | $CC -E - | grep __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then
+	    _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-retain-symbols-file,$export_symbols -o $lib'
+	    _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
+	    _LT_TAGVAR(whole_archive_flag_spec, $1)="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive'
+	  fi
+	  output_verbose_link_cmd=func_echo_all
+	else
+	  _LT_TAGVAR(ld_shlibs, $1)=no
+	fi
+	;;
+
+      osf3* | osf4* | osf5*)
+        case $cc_basename in
+          KCC*)
+	    # Kuck and Associates, Inc. (KAI) C++ Compiler
+
+	    # KCC will only create a shared library if the output file
+	    # ends with ".so" (or ".sl" for HP-UX), so rename the library
+	    # to its proper name (with version) after linking.
+	    _LT_TAGVAR(archive_cmds, $1)='tempext=`echo $shared_ext | $SED -e '\''s/\([[^()0-9A-Za-z{}]]\)/\\\\\1/g'\''`; templib=`echo "$lib" | $SED -e "s/\${tempext}\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib; mv \$templib $lib'
+
+	    _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
+	    _LT_TAGVAR(hardcode_libdir_separator, $1)=:
+
+	    # Archives containing C++ object files must be created using
+	    # the KAI C++ compiler.
+	    case $host in
+	      osf3*) _LT_TAGVAR(old_archive_cmds, $1)='$CC -Bstatic -o $oldlib $oldobjs' ;;
+	      *) _LT_TAGVAR(old_archive_cmds, $1)='$CC -o $oldlib $oldobjs' ;;
+	    esac
+	    ;;
+          RCC*)
+	    # Rational C++ 2.4.1
+	    # FIXME: insert proper C++ library support
+	    _LT_TAGVAR(ld_shlibs, $1)=no
+	    ;;
+          cxx*)
+	    case $host in
+	      osf3*)
+	        _LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*'
+	        _LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $soname `test -n "$verstring" && func_echo_all "${wl}-set_version $verstring"` -update_registry ${output_objdir}/so_locations -o $lib'
+	        _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
+		;;
+	      *)
+	        _LT_TAGVAR(allow_undefined_flag, $1)=' -expect_unresolved \*'
+	        _LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -msym -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry ${output_objdir}/so_locations -o $lib'
+	        _LT_TAGVAR(archive_expsym_cmds, $1)='for i in `cat $export_symbols`; do printf "%s %s\\n" -exported_symbol "\$i" >> $lib.exp; done~
+	          echo "-hidden">> $lib.exp~
+	          $CC -shared$allow_undefined_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -msym -soname $soname ${wl}-input ${wl}$lib.exp  `test -n "$verstring" && $ECHO "-set_version $verstring"` -update_registry ${output_objdir}/so_locations -o $lib~
+	          $RM $lib.exp'
+	        _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-rpath $libdir'
+		;;
+	    esac
+
+	    _LT_TAGVAR(hardcode_libdir_separator, $1)=:
+
+	    # Commands to make compiler produce verbose output that lists
+	    # what "hidden" libraries, object files and flags are used when
+	    # linking a shared library.
+	    #
+	    # There doesn't appear to be a way to prevent this compiler from
+	    # explicitly linking system object files so we need to strip them
+	    # from the output so that they don't get included in the library
+	    # dependencies.
+	    output_verbose_link_cmd='templist=`$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP "ld" | $GREP -v "ld:"`; templist=`func_echo_all "$templist" | $SED "s/\(^.*ld.*\)\( .*ld.*$\)/\1/"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"'
+	    ;;
+	  *)
+	    if test "$GXX" = yes && test "$with_gnu_ld" = no; then
+	      _LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*'
+	      case $host in
+	        osf3*)
+	          _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib ${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && func_echo_all "${wl}-set_version ${wl}$verstring"` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
+		  ;;
+	        *)
+	          _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -nostdlib ${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-msym ${wl}-soname ${wl}$soname `test -n "$verstring" && func_echo_all "${wl}-set_version ${wl}$verstring"` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
+		  ;;
+	      esac
+
+	      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
+	      _LT_TAGVAR(hardcode_libdir_separator, $1)=:
+
+	      # Commands to make compiler produce verbose output that lists
+	      # what "hidden" libraries, object files and flags are used when
+	      # linking a shared library.
+	      output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"'
+
+	    else
+	      # FIXME: insert proper C++ library support
+	      _LT_TAGVAR(ld_shlibs, $1)=no
+	    fi
+	    ;;
+        esac
+        ;;
+
+      psos*)
+        # FIXME: insert proper C++ library support
+        _LT_TAGVAR(ld_shlibs, $1)=no
+        ;;
+
+      sunos4*)
+        case $cc_basename in
+          CC*)
+	    # Sun C++ 4.x
+	    # FIXME: insert proper C++ library support
+	    _LT_TAGVAR(ld_shlibs, $1)=no
+	    ;;
+          lcc*)
+	    # Lucid
+	    # FIXME: insert proper C++ library support
+	    _LT_TAGVAR(ld_shlibs, $1)=no
+	    ;;
+          *)
+	    # FIXME: insert proper C++ library support
+	    _LT_TAGVAR(ld_shlibs, $1)=no
+	    ;;
+        esac
+        ;;
+
+      solaris*)
+        case $cc_basename in
+          CC* | sunCC*)
+	    # Sun C++ 4.2, 5.x and Centerline C++
+            _LT_TAGVAR(archive_cmds_need_lc,$1)=yes
+	    _LT_TAGVAR(no_undefined_flag, $1)=' -zdefs'
+	    _LT_TAGVAR(archive_cmds, $1)='$CC -G${allow_undefined_flag}  -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
+	    _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~
+	      $CC -G${allow_undefined_flag} ${wl}-M ${wl}$lib.exp -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$RM $lib.exp'
+
+	    _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
+	    _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+	    case $host_os in
+	      solaris2.[[0-5]] | solaris2.[[0-5]].*) ;;
+	      *)
+		# The compiler driver will combine and reorder linker options,
+		# but understands `-z linker_flag'.
+	        # Supported since Solaris 2.6 (maybe 2.5.1?)
+		_LT_TAGVAR(whole_archive_flag_spec, $1)='-z allextract$convenience -z defaultextract'
+	        ;;
+	    esac
+	    _LT_TAGVAR(link_all_deplibs, $1)=yes
+
+	    output_verbose_link_cmd='func_echo_all'
+
+	    # Archives containing C++ object files must be created using
+	    # "CC -xar", where "CC" is the Sun C++ compiler.  This is
+	    # necessary to make sure instantiated templates are included
+	    # in the archive.
+	    _LT_TAGVAR(old_archive_cmds, $1)='$CC -xar -o $oldlib $oldobjs'
+	    ;;
+          gcx*)
+	    # Green Hills C++ Compiler
+	    _LT_TAGVAR(archive_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-h $wl$soname -o $lib'
+
+	    # The C++ compiler must be used to create the archive.
+	    _LT_TAGVAR(old_archive_cmds, $1)='$CC $LDFLAGS -archive -o $oldlib $oldobjs'
+	    ;;
+          *)
+	    # GNU C++ compiler with Solaris linker
+	    if test "$GXX" = yes && test "$with_gnu_ld" = no; then
+	      _LT_TAGVAR(no_undefined_flag, $1)=' ${wl}-z ${wl}defs'
+	      if $CC --version | $GREP -v '^2\.7' > /dev/null; then
+	        _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -nostdlib $LDFLAGS $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-h $wl$soname -o $lib'
+	        _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~
+		  $CC -shared $pic_flag -nostdlib ${wl}-M $wl$lib.exp -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$RM $lib.exp'
+
+	        # Commands to make compiler produce verbose output that lists
+	        # what "hidden" libraries, object files and flags are used when
+	        # linking a shared library.
+	        output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"'
+	      else
+	        # g++ 2.7 appears to require `-G' NOT `-shared' on this
+	        # platform.
+	        _LT_TAGVAR(archive_cmds, $1)='$CC -G -nostdlib $LDFLAGS $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-h $wl$soname -o $lib'
+	        _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~
+		  $CC -G -nostdlib ${wl}-M $wl$lib.exp -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$RM $lib.exp'
+
+	        # Commands to make compiler produce verbose output that lists
+	        # what "hidden" libraries, object files and flags are used when
+	        # linking a shared library.
+	        output_verbose_link_cmd='$CC -G $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"'
+	      fi
+
+	      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R $wl$libdir'
+	      case $host_os in
+		solaris2.[[0-5]] | solaris2.[[0-5]].*) ;;
+		*)
+		  _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}-z ${wl}allextract$convenience ${wl}-z ${wl}defaultextract'
+		  ;;
+	      esac
+	    fi
+	    ;;
+        esac
+        ;;
+
+    sysv4*uw2* | sysv5OpenUNIX* | sysv5UnixWare7.[[01]].[[10]]* | unixware7* | sco3.2v5.0.[[024]]*)
+      _LT_TAGVAR(no_undefined_flag, $1)='${wl}-z,text'
+      _LT_TAGVAR(archive_cmds_need_lc, $1)=no
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      runpath_var='LD_RUN_PATH'
+
+      case $cc_basename in
+        CC*)
+	  _LT_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+	  _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+	  ;;
+	*)
+	  _LT_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+	  _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+	  ;;
+      esac
+      ;;
+
+      sysv5* | sco3.2v5* | sco5v6*)
+	# Note: We can NOT use -z defs as we might desire, because we do not
+	# link with -lc, and that would cause any symbols used from libc to
+	# always be unresolved, which means just about no library would
+	# ever link correctly.  If we're not using GNU ld we use -z text
+	# though, which does catch some bad symbols but isn't as heavy-handed
+	# as -z defs.
+	_LT_TAGVAR(no_undefined_flag, $1)='${wl}-z,text'
+	_LT_TAGVAR(allow_undefined_flag, $1)='${wl}-z,nodefs'
+	_LT_TAGVAR(archive_cmds_need_lc, $1)=no
+	_LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+	_LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R,$libdir'
+	_LT_TAGVAR(hardcode_libdir_separator, $1)=':'
+	_LT_TAGVAR(link_all_deplibs, $1)=yes
+	_LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-Bexport'
+	runpath_var='LD_RUN_PATH'
+
+	case $cc_basename in
+          CC*)
+	    _LT_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+	    _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+	    _LT_TAGVAR(old_archive_cmds, $1)='$CC -Tprelink_objects $oldobjs~
+	      '"$_LT_TAGVAR(old_archive_cmds, $1)"
+	    _LT_TAGVAR(reload_cmds, $1)='$CC -Tprelink_objects $reload_objs~
+	      '"$_LT_TAGVAR(reload_cmds, $1)"
+	    ;;
+	  *)
+	    _LT_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+	    _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+	    ;;
+	esac
+      ;;
+
+      tandem*)
+        case $cc_basename in
+          NCC*)
+	    # NonStop-UX NCC 3.20
+	    # FIXME: insert proper C++ library support
+	    _LT_TAGVAR(ld_shlibs, $1)=no
+	    ;;
+          *)
+	    # FIXME: insert proper C++ library support
+	    _LT_TAGVAR(ld_shlibs, $1)=no
+	    ;;
+        esac
+        ;;
+
+      vxworks*)
+        # FIXME: insert proper C++ library support
+        _LT_TAGVAR(ld_shlibs, $1)=no
+        ;;
+
+      *)
+        # FIXME: insert proper C++ library support
+        _LT_TAGVAR(ld_shlibs, $1)=no
+        ;;
+    esac
+
+    AC_MSG_RESULT([$_LT_TAGVAR(ld_shlibs, $1)])
+    test "$_LT_TAGVAR(ld_shlibs, $1)" = no && can_build_shared=no
+
+    _LT_TAGVAR(GCC, $1)="$GXX"
+    _LT_TAGVAR(LD, $1)="$LD"
+
+    ## CAVEAT EMPTOR:
+    ## There is no encapsulation within the following macros, do not change
+    ## the running order or otherwise move them around unless you know exactly
+    ## what you are doing...
+    _LT_SYS_HIDDEN_LIBDEPS($1)
+    _LT_COMPILER_PIC($1)
+    _LT_COMPILER_C_O($1)
+    _LT_COMPILER_FILE_LOCKS($1)
+    _LT_LINKER_SHLIBS($1)
+    _LT_SYS_DYNAMIC_LINKER($1)
+    _LT_LINKER_HARDCODE_LIBPATH($1)
+
+    _LT_CONFIG($1)
+  fi # test -n "$compiler"
+
+  CC=$lt_save_CC
+  CFLAGS=$lt_save_CFLAGS
+  LDCXX=$LD
+  LD=$lt_save_LD
+  GCC=$lt_save_GCC
+  with_gnu_ld=$lt_save_with_gnu_ld
+  lt_cv_path_LDCXX=$lt_cv_path_LD
+  lt_cv_path_LD=$lt_save_path_LD
+  lt_cv_prog_gnu_ldcxx=$lt_cv_prog_gnu_ld
+  lt_cv_prog_gnu_ld=$lt_save_with_gnu_ld
+fi # test "$_lt_caught_CXX_error" != yes
+
+AC_LANG_POP
+])# _LT_LANG_CXX_CONFIG
+
+
+# _LT_FUNC_STRIPNAME_CNF
+# ----------------------
+# func_stripname_cnf prefix suffix name
+# strip PREFIX and SUFFIX off of NAME.
+# PREFIX and SUFFIX must not contain globbing or regex special
+# characters, hashes, percent signs, but SUFFIX may contain a leading
+# dot (in which case that matches only a dot).
+#
+# This function is identical to the (non-XSI) version of func_stripname,
+# except this one can be used by m4 code that may be executed by configure,
+# rather than the libtool script.
+m4_defun([_LT_FUNC_STRIPNAME_CNF],[dnl
+AC_REQUIRE([_LT_DECL_SED])
+AC_REQUIRE([_LT_PROG_ECHO_BACKSLASH])
+func_stripname_cnf ()
+{
+  case ${2} in
+  .*) func_stripname_result=`$ECHO "${3}" | $SED "s%^${1}%%; s%\\\\${2}\$%%"`;;
+  *)  func_stripname_result=`$ECHO "${3}" | $SED "s%^${1}%%; s%${2}\$%%"`;;
+  esac
+} # func_stripname_cnf
+])# _LT_FUNC_STRIPNAME_CNF
+
+# _LT_SYS_HIDDEN_LIBDEPS([TAGNAME])
+# ---------------------------------
+# Figure out "hidden" library dependencies from verbose
+# compiler output when linking a shared library.
+# Parse the compiler output and extract the necessary
+# objects, libraries and library flags.
+m4_defun([_LT_SYS_HIDDEN_LIBDEPS],
+[m4_require([_LT_FILEUTILS_DEFAULTS])dnl
+AC_REQUIRE([_LT_FUNC_STRIPNAME_CNF])dnl
+# Dependencies to place before and after the object being linked:
+_LT_TAGVAR(predep_objects, $1)=
+_LT_TAGVAR(postdep_objects, $1)=
+_LT_TAGVAR(predeps, $1)=
+_LT_TAGVAR(postdeps, $1)=
+_LT_TAGVAR(compiler_lib_search_path, $1)=
+
+dnl we can't use the lt_simple_compile_test_code here,
+dnl because it contains code intended for an executable,
+dnl not a library.  It's possible we should let each
+dnl tag define a new lt_????_link_test_code variable,
+dnl but it's only used here...
+m4_if([$1], [], [cat > conftest.$ac_ext <<_LT_EOF
+int a;
+void foo (void) { a = 0; }
+_LT_EOF
+], [$1], [CXX], [cat > conftest.$ac_ext <<_LT_EOF
+class Foo
+{
+public:
+  Foo (void) { a = 0; }
+private:
+  int a;
+};
+_LT_EOF
+], [$1], [F77], [cat > conftest.$ac_ext <<_LT_EOF
+      subroutine foo
+      implicit none
+      integer*4 a
+      a=0
+      return
+      end
+_LT_EOF
+], [$1], [FC], [cat > conftest.$ac_ext <<_LT_EOF
+      subroutine foo
+      implicit none
+      integer a
+      a=0
+      return
+      end
+_LT_EOF
+], [$1], [GCJ], [cat > conftest.$ac_ext <<_LT_EOF
+public class foo {
+  private int a;
+  public void bar (void) {
+    a = 0;
+  }
+};
+_LT_EOF
+], [$1], [GO], [cat > conftest.$ac_ext <<_LT_EOF
+package foo
+func foo() {
+}
+_LT_EOF
+])
+
+_lt_libdeps_save_CFLAGS=$CFLAGS
+case "$CC $CFLAGS " in #(
+*\ -flto*\ *) CFLAGS="$CFLAGS -fno-lto" ;;
+*\ -fwhopr*\ *) CFLAGS="$CFLAGS -fno-whopr" ;;
+*\ -fuse-linker-plugin*\ *) CFLAGS="$CFLAGS -fno-use-linker-plugin" ;;
+esac
+
+dnl Parse the compiler output and extract the necessary
+dnl objects, libraries and library flags.
+if AC_TRY_EVAL(ac_compile); then
+  # Parse the compiler output and extract the necessary
+  # objects, libraries and library flags.
+
+  # Sentinel used to keep track of whether or not we are before
+  # the conftest object file.
+  pre_test_object_deps_done=no
+
+  for p in `eval "$output_verbose_link_cmd"`; do
+    case ${prev}${p} in
+
+    -L* | -R* | -l*)
+       # Some compilers place space between "-{L,R}" and the path.
+       # Remove the space.
+       if test $p = "-L" ||
+          test $p = "-R"; then
+	 prev=$p
+	 continue
+       fi
+
+       # Expand the sysroot to ease extracting the directories later.
+       if test -z "$prev"; then
+         case $p in
+         -L*) func_stripname_cnf '-L' '' "$p"; prev=-L; p=$func_stripname_result ;;
+         -R*) func_stripname_cnf '-R' '' "$p"; prev=-R; p=$func_stripname_result ;;
+         -l*) func_stripname_cnf '-l' '' "$p"; prev=-l; p=$func_stripname_result ;;
+         esac
+       fi
+       case $p in
+       =*) func_stripname_cnf '=' '' "$p"; p=$lt_sysroot$func_stripname_result ;;
+       esac
+       if test "$pre_test_object_deps_done" = no; then
+	 case ${prev} in
+	 -L | -R)
+	   # Internal compiler library paths should come after those
+	   # provided the user.  The postdeps already come after the
+	   # user supplied libs so there is no need to process them.
+	   if test -z "$_LT_TAGVAR(compiler_lib_search_path, $1)"; then
+	     _LT_TAGVAR(compiler_lib_search_path, $1)="${prev}${p}"
+	   else
+	     _LT_TAGVAR(compiler_lib_search_path, $1)="${_LT_TAGVAR(compiler_lib_search_path, $1)} ${prev}${p}"
+	   fi
+	   ;;
+	 # The "-l" case would never come before the object being
+	 # linked, so don't bother handling this case.
+	 esac
+       else
+	 if test -z "$_LT_TAGVAR(postdeps, $1)"; then
+	   _LT_TAGVAR(postdeps, $1)="${prev}${p}"
+	 else
+	   _LT_TAGVAR(postdeps, $1)="${_LT_TAGVAR(postdeps, $1)} ${prev}${p}"
+	 fi
+       fi
+       prev=
+       ;;
+
+    *.lto.$objext) ;; # Ignore GCC LTO objects
+    *.$objext)
+       # This assumes that the test object file only shows up
+       # once in the compiler output.
+       if test "$p" = "conftest.$objext"; then
+	 pre_test_object_deps_done=yes
+	 continue
+       fi
+
+       if test "$pre_test_object_deps_done" = no; then
+	 if test -z "$_LT_TAGVAR(predep_objects, $1)"; then
+	   _LT_TAGVAR(predep_objects, $1)="$p"
+	 else
+	   _LT_TAGVAR(predep_objects, $1)="$_LT_TAGVAR(predep_objects, $1) $p"
+	 fi
+       else
+	 if test -z "$_LT_TAGVAR(postdep_objects, $1)"; then
+	   _LT_TAGVAR(postdep_objects, $1)="$p"
+	 else
+	   _LT_TAGVAR(postdep_objects, $1)="$_LT_TAGVAR(postdep_objects, $1) $p"
+	 fi
+       fi
+       ;;
+
+    *) ;; # Ignore the rest.
+
+    esac
+  done
+
+  # Clean up.
+  rm -f a.out a.exe
+else
+  echo "libtool.m4: error: problem compiling $1 test program"
+fi
+
+$RM -f confest.$objext
+CFLAGS=$_lt_libdeps_save_CFLAGS
+
+# PORTME: override above test on systems where it is broken
+m4_if([$1], [CXX],
+[case $host_os in
+interix[[3-9]]*)
+  # Interix 3.5 installs completely hosed .la files for C++, so rather than
+  # hack all around it, let's just trust "g++" to DTRT.
+  _LT_TAGVAR(predep_objects,$1)=
+  _LT_TAGVAR(postdep_objects,$1)=
+  _LT_TAGVAR(postdeps,$1)=
+  ;;
+
+linux*)
+  case `$CC -V 2>&1 | sed 5q` in
+  *Sun\ C*)
+    # Sun C++ 5.9
+
+    # The more standards-conforming stlport4 library is
+    # incompatible with the Cstd library. Avoid specifying
+    # it if it's in CXXFLAGS. Ignore libCrun as
+    # -library=stlport4 depends on it.
+    case " $CXX $CXXFLAGS " in
+    *" -library=stlport4 "*)
+      solaris_use_stlport4=yes
+      ;;
+    esac
+
+    if test "$solaris_use_stlport4" != yes; then
+      _LT_TAGVAR(postdeps,$1)='-library=Cstd -library=Crun'
+    fi
+    ;;
+  esac
+  ;;
+
+solaris*)
+  case $cc_basename in
+  CC* | sunCC*)
+    # The more standards-conforming stlport4 library is
+    # incompatible with the Cstd library. Avoid specifying
+    # it if it's in CXXFLAGS. Ignore libCrun as
+    # -library=stlport4 depends on it.
+    case " $CXX $CXXFLAGS " in
+    *" -library=stlport4 "*)
+      solaris_use_stlport4=yes
+      ;;
+    esac
+
+    # Adding this requires a known-good setup of shared libraries for
+    # Sun compiler versions before 5.6, else PIC objects from an old
+    # archive will be linked into the output, leading to subtle bugs.
+    if test "$solaris_use_stlport4" != yes; then
+      _LT_TAGVAR(postdeps,$1)='-library=Cstd -library=Crun'
+    fi
+    ;;
+  esac
+  ;;
+esac
+])
+
+case " $_LT_TAGVAR(postdeps, $1) " in
+*" -lc "*) _LT_TAGVAR(archive_cmds_need_lc, $1)=no ;;
+esac
+ _LT_TAGVAR(compiler_lib_search_dirs, $1)=
+if test -n "${_LT_TAGVAR(compiler_lib_search_path, $1)}"; then
+ _LT_TAGVAR(compiler_lib_search_dirs, $1)=`echo " ${_LT_TAGVAR(compiler_lib_search_path, $1)}" | ${SED} -e 's! -L! !g' -e 's!^ !!'`
+fi
+_LT_TAGDECL([], [compiler_lib_search_dirs], [1],
+    [The directories searched by this compiler when creating a shared library])
+_LT_TAGDECL([], [predep_objects], [1],
+    [Dependencies to place before and after the objects being linked to
+    create a shared library])
+_LT_TAGDECL([], [postdep_objects], [1])
+_LT_TAGDECL([], [predeps], [1])
+_LT_TAGDECL([], [postdeps], [1])
+_LT_TAGDECL([], [compiler_lib_search_path], [1],
+    [The library search path used internally by the compiler when linking
+    a shared library])
+])# _LT_SYS_HIDDEN_LIBDEPS
+
+
+# _LT_LANG_F77_CONFIG([TAG])
+# --------------------------
+# Ensure that the configuration variables for a Fortran 77 compiler are
+# suitably defined.  These variables are subsequently used by _LT_CONFIG
+# to write the compiler configuration to `libtool'.
+m4_defun([_LT_LANG_F77_CONFIG],
+[AC_LANG_PUSH(Fortran 77)
+if test -z "$F77" || test "X$F77" = "Xno"; then
+  _lt_disable_F77=yes
+fi
+
+_LT_TAGVAR(archive_cmds_need_lc, $1)=no
+_LT_TAGVAR(allow_undefined_flag, $1)=
+_LT_TAGVAR(always_export_symbols, $1)=no
+_LT_TAGVAR(archive_expsym_cmds, $1)=
+_LT_TAGVAR(export_dynamic_flag_spec, $1)=
+_LT_TAGVAR(hardcode_direct, $1)=no
+_LT_TAGVAR(hardcode_direct_absolute, $1)=no
+_LT_TAGVAR(hardcode_libdir_flag_spec, $1)=
+_LT_TAGVAR(hardcode_libdir_separator, $1)=
+_LT_TAGVAR(hardcode_minus_L, $1)=no
+_LT_TAGVAR(hardcode_automatic, $1)=no
+_LT_TAGVAR(inherit_rpath, $1)=no
+_LT_TAGVAR(module_cmds, $1)=
+_LT_TAGVAR(module_expsym_cmds, $1)=
+_LT_TAGVAR(link_all_deplibs, $1)=unknown
+_LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds
+_LT_TAGVAR(reload_flag, $1)=$reload_flag
+_LT_TAGVAR(reload_cmds, $1)=$reload_cmds
+_LT_TAGVAR(no_undefined_flag, $1)=
+_LT_TAGVAR(whole_archive_flag_spec, $1)=
+_LT_TAGVAR(enable_shared_with_static_runtimes, $1)=no
+
+# Source file extension for f77 test sources.
+ac_ext=f
+
+# Object file extension for compiled f77 test sources.
+objext=o
+_LT_TAGVAR(objext, $1)=$objext
+
+# No sense in running all these tests if we already determined that
+# the F77 compiler isn't working.  Some variables (like enable_shared)
+# are currently assumed to apply to all compilers on this platform,
+# and will be corrupted by setting them based on a non-working compiler.
+if test "$_lt_disable_F77" != yes; then
+  # Code to be used in simple compile tests
+  lt_simple_compile_test_code="\
+      subroutine t
+      return
+      end
+"
+
+  # Code to be used in simple link tests
+  lt_simple_link_test_code="\
+      program t
+      end
+"
+
+  # ltmain only uses $CC for tagged configurations so make sure $CC is set.
+  _LT_TAG_COMPILER
+
+  # save warnings/boilerplate of simple test code
+  _LT_COMPILER_BOILERPLATE
+  _LT_LINKER_BOILERPLATE
+
+  # Allow CC to be a program name with arguments.
+  lt_save_CC="$CC"
+  lt_save_GCC=$GCC
+  lt_save_CFLAGS=$CFLAGS
+  CC=${F77-"f77"}
+  CFLAGS=$FFLAGS
+  compiler=$CC
+  _LT_TAGVAR(compiler, $1)=$CC
+  _LT_CC_BASENAME([$compiler])
+  GCC=$G77
+  if test -n "$compiler"; then
+    AC_MSG_CHECKING([if libtool supports shared libraries])
+    AC_MSG_RESULT([$can_build_shared])
+
+    AC_MSG_CHECKING([whether to build shared libraries])
+    test "$can_build_shared" = "no" && enable_shared=no
+
+    # On AIX, shared libraries and static libraries use the same namespace, and
+    # are all built from PIC.
+    case $host_os in
+      aix3*)
+        test "$enable_shared" = yes && enable_static=no
+        if test -n "$RANLIB"; then
+          archive_cmds="$archive_cmds~\$RANLIB \$lib"
+          postinstall_cmds='$RANLIB $lib'
+        fi
+        ;;
+      aix[[4-9]]*)
+	if test "$host_cpu" != ia64 && test "$aix_use_runtimelinking" = no ; then
+	  test "$enable_shared" = yes && enable_static=no
+	fi
+        ;;
+    esac
+    AC_MSG_RESULT([$enable_shared])
+
+    AC_MSG_CHECKING([whether to build static libraries])
+    # Make sure either enable_shared or enable_static is yes.
+    test "$enable_shared" = yes || enable_static=yes
+    AC_MSG_RESULT([$enable_static])
+
+    _LT_TAGVAR(GCC, $1)="$G77"
+    _LT_TAGVAR(LD, $1)="$LD"
+
+    ## CAVEAT EMPTOR:
+    ## There is no encapsulation within the following macros, do not change
+    ## the running order or otherwise move them around unless you know exactly
+    ## what you are doing...
+    _LT_COMPILER_PIC($1)
+    _LT_COMPILER_C_O($1)
+    _LT_COMPILER_FILE_LOCKS($1)
+    _LT_LINKER_SHLIBS($1)
+    _LT_SYS_DYNAMIC_LINKER($1)
+    _LT_LINKER_HARDCODE_LIBPATH($1)
+
+    _LT_CONFIG($1)
+  fi # test -n "$compiler"
+
+  GCC=$lt_save_GCC
+  CC="$lt_save_CC"
+  CFLAGS="$lt_save_CFLAGS"
+fi # test "$_lt_disable_F77" != yes
+
+AC_LANG_POP
+])# _LT_LANG_F77_CONFIG
+
+
+# _LT_LANG_FC_CONFIG([TAG])
+# -------------------------
+# Ensure that the configuration variables for a Fortran compiler are
+# suitably defined.  These variables are subsequently used by _LT_CONFIG
+# to write the compiler configuration to `libtool'.
+m4_defun([_LT_LANG_FC_CONFIG],
+[AC_LANG_PUSH(Fortran)
+
+if test -z "$FC" || test "X$FC" = "Xno"; then
+  _lt_disable_FC=yes
+fi
+
+_LT_TAGVAR(archive_cmds_need_lc, $1)=no
+_LT_TAGVAR(allow_undefined_flag, $1)=
+_LT_TAGVAR(always_export_symbols, $1)=no
+_LT_TAGVAR(archive_expsym_cmds, $1)=
+_LT_TAGVAR(export_dynamic_flag_spec, $1)=
+_LT_TAGVAR(hardcode_direct, $1)=no
+_LT_TAGVAR(hardcode_direct_absolute, $1)=no
+_LT_TAGVAR(hardcode_libdir_flag_spec, $1)=
+_LT_TAGVAR(hardcode_libdir_separator, $1)=
+_LT_TAGVAR(hardcode_minus_L, $1)=no
+_LT_TAGVAR(hardcode_automatic, $1)=no
+_LT_TAGVAR(inherit_rpath, $1)=no
+_LT_TAGVAR(module_cmds, $1)=
+_LT_TAGVAR(module_expsym_cmds, $1)=
+_LT_TAGVAR(link_all_deplibs, $1)=unknown
+_LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds
+_LT_TAGVAR(reload_flag, $1)=$reload_flag
+_LT_TAGVAR(reload_cmds, $1)=$reload_cmds
+_LT_TAGVAR(no_undefined_flag, $1)=
+_LT_TAGVAR(whole_archive_flag_spec, $1)=
+_LT_TAGVAR(enable_shared_with_static_runtimes, $1)=no
+
+# Source file extension for fc test sources.
+ac_ext=${ac_fc_srcext-f}
+
+# Object file extension for compiled fc test sources.
+objext=o
+_LT_TAGVAR(objext, $1)=$objext
+
+# No sense in running all these tests if we already determined that
+# the FC compiler isn't working.  Some variables (like enable_shared)
+# are currently assumed to apply to all compilers on this platform,
+# and will be corrupted by setting them based on a non-working compiler.
+if test "$_lt_disable_FC" != yes; then
+  # Code to be used in simple compile tests
+  lt_simple_compile_test_code="\
+      subroutine t
+      return
+      end
+"
+
+  # Code to be used in simple link tests
+  lt_simple_link_test_code="\
+      program t
+      end
+"
+
+  # ltmain only uses $CC for tagged configurations so make sure $CC is set.
+  _LT_TAG_COMPILER
+
+  # save warnings/boilerplate of simple test code
+  _LT_COMPILER_BOILERPLATE
+  _LT_LINKER_BOILERPLATE
+
+  # Allow CC to be a program name with arguments.
+  lt_save_CC="$CC"
+  lt_save_GCC=$GCC
+  lt_save_CFLAGS=$CFLAGS
+  CC=${FC-"f95"}
+  CFLAGS=$FCFLAGS
+  compiler=$CC
+  GCC=$ac_cv_fc_compiler_gnu
+
+  _LT_TAGVAR(compiler, $1)=$CC
+  _LT_CC_BASENAME([$compiler])
+
+  if test -n "$compiler"; then
+    AC_MSG_CHECKING([if libtool supports shared libraries])
+    AC_MSG_RESULT([$can_build_shared])
+
+    AC_MSG_CHECKING([whether to build shared libraries])
+    test "$can_build_shared" = "no" && enable_shared=no
+
+    # On AIX, shared libraries and static libraries use the same namespace, and
+    # are all built from PIC.
+    case $host_os in
+      aix3*)
+        test "$enable_shared" = yes && enable_static=no
+        if test -n "$RANLIB"; then
+          archive_cmds="$archive_cmds~\$RANLIB \$lib"
+          postinstall_cmds='$RANLIB $lib'
+        fi
+        ;;
+      aix[[4-9]]*)
+	if test "$host_cpu" != ia64 && test "$aix_use_runtimelinking" = no ; then
+	  test "$enable_shared" = yes && enable_static=no
+	fi
+        ;;
+    esac
+    AC_MSG_RESULT([$enable_shared])
+
+    AC_MSG_CHECKING([whether to build static libraries])
+    # Make sure either enable_shared or enable_static is yes.
+    test "$enable_shared" = yes || enable_static=yes
+    AC_MSG_RESULT([$enable_static])
+
+    _LT_TAGVAR(GCC, $1)="$ac_cv_fc_compiler_gnu"
+    _LT_TAGVAR(LD, $1)="$LD"
+
+    ## CAVEAT EMPTOR:
+    ## There is no encapsulation within the following macros, do not change
+    ## the running order or otherwise move them around unless you know exactly
+    ## what you are doing...
+    _LT_SYS_HIDDEN_LIBDEPS($1)
+    _LT_COMPILER_PIC($1)
+    _LT_COMPILER_C_O($1)
+    _LT_COMPILER_FILE_LOCKS($1)
+    _LT_LINKER_SHLIBS($1)
+    _LT_SYS_DYNAMIC_LINKER($1)
+    _LT_LINKER_HARDCODE_LIBPATH($1)
+
+    _LT_CONFIG($1)
+  fi # test -n "$compiler"
+
+  GCC=$lt_save_GCC
+  CC=$lt_save_CC
+  CFLAGS=$lt_save_CFLAGS
+fi # test "$_lt_disable_FC" != yes
+
+AC_LANG_POP
+])# _LT_LANG_FC_CONFIG
+
+
+# _LT_LANG_GCJ_CONFIG([TAG])
+# --------------------------
+# Ensure that the configuration variables for the GNU Java Compiler compiler
+# are suitably defined.  These variables are subsequently used by _LT_CONFIG
+# to write the compiler configuration to `libtool'.
+m4_defun([_LT_LANG_GCJ_CONFIG],
+[AC_REQUIRE([LT_PROG_GCJ])dnl
+AC_LANG_SAVE
+
+# Source file extension for Java test sources.
+ac_ext=java
+
+# Object file extension for compiled Java test sources.
+objext=o
+_LT_TAGVAR(objext, $1)=$objext
+
+# Code to be used in simple compile tests
+lt_simple_compile_test_code="class foo {}"
+
+# Code to be used in simple link tests
+lt_simple_link_test_code='public class conftest { public static void main(String[[]] argv) {}; }'
+
+# ltmain only uses $CC for tagged configurations so make sure $CC is set.
+_LT_TAG_COMPILER
+
+# save warnings/boilerplate of simple test code
+_LT_COMPILER_BOILERPLATE
+_LT_LINKER_BOILERPLATE
+
+# Allow CC to be a program name with arguments.
+lt_save_CC=$CC
+lt_save_CFLAGS=$CFLAGS
+lt_save_GCC=$GCC
+GCC=yes
+CC=${GCJ-"gcj"}
+CFLAGS=$GCJFLAGS
+compiler=$CC
+_LT_TAGVAR(compiler, $1)=$CC
+_LT_TAGVAR(LD, $1)="$LD"
+_LT_CC_BASENAME([$compiler])
+
+# GCJ did not exist at the time GCC didn't implicitly link libc in.
+_LT_TAGVAR(archive_cmds_need_lc, $1)=no
+
+_LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds
+_LT_TAGVAR(reload_flag, $1)=$reload_flag
+_LT_TAGVAR(reload_cmds, $1)=$reload_cmds
+
+if test -n "$compiler"; then
+  _LT_COMPILER_NO_RTTI($1)
+  _LT_COMPILER_PIC($1)
+  _LT_COMPILER_C_O($1)
+  _LT_COMPILER_FILE_LOCKS($1)
+  _LT_LINKER_SHLIBS($1)
+  _LT_LINKER_HARDCODE_LIBPATH($1)
+
+  _LT_CONFIG($1)
+fi
+
+AC_LANG_RESTORE
+
+GCC=$lt_save_GCC
+CC=$lt_save_CC
+CFLAGS=$lt_save_CFLAGS
+])# _LT_LANG_GCJ_CONFIG
+
+
+# _LT_LANG_GO_CONFIG([TAG])
+# --------------------------
+# Ensure that the configuration variables for the GNU Go compiler
+# are suitably defined.  These variables are subsequently used by _LT_CONFIG
+# to write the compiler configuration to `libtool'.
+m4_defun([_LT_LANG_GO_CONFIG],
+[AC_REQUIRE([LT_PROG_GO])dnl
+AC_LANG_SAVE
+
+# Source file extension for Go test sources.
+ac_ext=go
+
+# Object file extension for compiled Go test sources.
+objext=o
+_LT_TAGVAR(objext, $1)=$objext
+
+# Code to be used in simple compile tests
+lt_simple_compile_test_code="package main; func main() { }"
+
+# Code to be used in simple link tests
+lt_simple_link_test_code='package main; func main() { }'
+
+# ltmain only uses $CC for tagged configurations so make sure $CC is set.
+_LT_TAG_COMPILER
+
+# save warnings/boilerplate of simple test code
+_LT_COMPILER_BOILERPLATE
+_LT_LINKER_BOILERPLATE
+
+# Allow CC to be a program name with arguments.
+lt_save_CC=$CC
+lt_save_CFLAGS=$CFLAGS
+lt_save_GCC=$GCC
+GCC=yes
+CC=${GOC-"gccgo"}
+CFLAGS=$GOFLAGS
+compiler=$CC
+_LT_TAGVAR(compiler, $1)=$CC
+_LT_TAGVAR(LD, $1)="$LD"
+_LT_CC_BASENAME([$compiler])
+
+# Go did not exist at the time GCC didn't implicitly link libc in.
+_LT_TAGVAR(archive_cmds_need_lc, $1)=no
+
+_LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds
+_LT_TAGVAR(reload_flag, $1)=$reload_flag
+_LT_TAGVAR(reload_cmds, $1)=$reload_cmds
+
+if test -n "$compiler"; then
+  _LT_COMPILER_NO_RTTI($1)
+  _LT_COMPILER_PIC($1)
+  _LT_COMPILER_C_O($1)
+  _LT_COMPILER_FILE_LOCKS($1)
+  _LT_LINKER_SHLIBS($1)
+  _LT_LINKER_HARDCODE_LIBPATH($1)
+
+  _LT_CONFIG($1)
+fi
+
+AC_LANG_RESTORE
+
+GCC=$lt_save_GCC
+CC=$lt_save_CC
+CFLAGS=$lt_save_CFLAGS
+])# _LT_LANG_GO_CONFIG
+
+
+# _LT_LANG_RC_CONFIG([TAG])
+# -------------------------
+# Ensure that the configuration variables for the Windows resource compiler
+# are suitably defined.  These variables are subsequently used by _LT_CONFIG
+# to write the compiler configuration to `libtool'.
+m4_defun([_LT_LANG_RC_CONFIG],
+[AC_REQUIRE([LT_PROG_RC])dnl
+AC_LANG_SAVE
+
+# Source file extension for RC test sources.
+ac_ext=rc
+
+# Object file extension for compiled RC test sources.
+objext=o
+_LT_TAGVAR(objext, $1)=$objext
+
+# Code to be used in simple compile tests
+lt_simple_compile_test_code='sample MENU { MENUITEM "&Soup", 100, CHECKED }'
+
+# Code to be used in simple link tests
+lt_simple_link_test_code="$lt_simple_compile_test_code"
+
+# ltmain only uses $CC for tagged configurations so make sure $CC is set.
+_LT_TAG_COMPILER
+
+# save warnings/boilerplate of simple test code
+_LT_COMPILER_BOILERPLATE
+_LT_LINKER_BOILERPLATE
+
+# Allow CC to be a program name with arguments.
+lt_save_CC="$CC"
+lt_save_CFLAGS=$CFLAGS
+lt_save_GCC=$GCC
+GCC=
+CC=${RC-"windres"}
+CFLAGS=
+compiler=$CC
+_LT_TAGVAR(compiler, $1)=$CC
+_LT_CC_BASENAME([$compiler])
+_LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)=yes
+
+if test -n "$compiler"; then
+  :
+  _LT_CONFIG($1)
+fi
+
+GCC=$lt_save_GCC
+AC_LANG_RESTORE
+CC=$lt_save_CC
+CFLAGS=$lt_save_CFLAGS
+])# _LT_LANG_RC_CONFIG
+
+
+# LT_PROG_GCJ
+# -----------
+AC_DEFUN([LT_PROG_GCJ],
+[m4_ifdef([AC_PROG_GCJ], [AC_PROG_GCJ],
+  [m4_ifdef([A][M_PROG_GCJ], [A][M_PROG_GCJ],
+    [AC_CHECK_TOOL(GCJ, gcj,)
+      test "x${GCJFLAGS+set}" = xset || GCJFLAGS="-g -O2"
+      AC_SUBST(GCJFLAGS)])])[]dnl
+])
+
+# Old name:
+AU_ALIAS([LT_AC_PROG_GCJ], [LT_PROG_GCJ])
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([LT_AC_PROG_GCJ], [])
+
+
+# LT_PROG_GO
+# ----------
+AC_DEFUN([LT_PROG_GO],
+[AC_CHECK_TOOL(GOC, gccgo,)
+])
+
+
+# LT_PROG_RC
+# ----------
+AC_DEFUN([LT_PROG_RC],
+[AC_CHECK_TOOL(RC, windres,)
+])
+
+# Old name:
+AU_ALIAS([LT_AC_PROG_RC], [LT_PROG_RC])
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([LT_AC_PROG_RC], [])
+
+
+# _LT_DECL_EGREP
+# --------------
+# If we don't have a new enough Autoconf to choose the best grep
+# available, choose the one first in the user's PATH.
+m4_defun([_LT_DECL_EGREP],
+[AC_REQUIRE([AC_PROG_EGREP])dnl
+AC_REQUIRE([AC_PROG_FGREP])dnl
+test -z "$GREP" && GREP=grep
+_LT_DECL([], [GREP], [1], [A grep program that handles long lines])
+_LT_DECL([], [EGREP], [1], [An ERE matcher])
+_LT_DECL([], [FGREP], [1], [A literal string matcher])
+dnl Non-bleeding-edge autoconf doesn't subst GREP, so do it here too
+AC_SUBST([GREP])
+])
+
+
+# _LT_DECL_OBJDUMP
+# --------------
+# If we don't have a new enough Autoconf to choose the best objdump
+# available, choose the one first in the user's PATH.
+m4_defun([_LT_DECL_OBJDUMP],
+[AC_CHECK_TOOL(OBJDUMP, objdump, false)
+test -z "$OBJDUMP" && OBJDUMP=objdump
+_LT_DECL([], [OBJDUMP], [1], [An object symbol dumper])
+AC_SUBST([OBJDUMP])
+])
+
+# _LT_DECL_DLLTOOL
+# ----------------
+# Ensure DLLTOOL variable is set.
+m4_defun([_LT_DECL_DLLTOOL],
+[AC_CHECK_TOOL(DLLTOOL, dlltool, false)
+test -z "$DLLTOOL" && DLLTOOL=dlltool
+_LT_DECL([], [DLLTOOL], [1], [DLL creation program])
+AC_SUBST([DLLTOOL])
+])
+
+# _LT_DECL_SED
+# ------------
+# Check for a fully-functional sed program, that truncates
+# as few characters as possible.  Prefer GNU sed if found.
+m4_defun([_LT_DECL_SED],
+[AC_PROG_SED
+test -z "$SED" && SED=sed
+Xsed="$SED -e 1s/^X//"
+_LT_DECL([], [SED], [1], [A sed program that does not truncate output])
+_LT_DECL([], [Xsed], ["\$SED -e 1s/^X//"],
+    [Sed that helps us avoid accidentally triggering echo(1) options like -n])
+])# _LT_DECL_SED
+
+m4_ifndef([AC_PROG_SED], [
+# NOTE: This macro has been submitted for inclusion into   #
+#  GNU Autoconf as AC_PROG_SED.  When it is available in   #
+#  a released version of Autoconf we should remove this    #
+#  macro and use it instead.                               #
+
+m4_defun([AC_PROG_SED],
+[AC_MSG_CHECKING([for a sed that does not truncate output])
+AC_CACHE_VAL(lt_cv_path_SED,
+[# Loop through the user's path and test for sed and gsed.
+# Then use that list of sed's as ones to test for truncation.
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for lt_ac_prog in sed gsed; do
+    for ac_exec_ext in '' $ac_executable_extensions; do
+      if $as_executable_p "$as_dir/$lt_ac_prog$ac_exec_ext"; then
+        lt_ac_sed_list="$lt_ac_sed_list $as_dir/$lt_ac_prog$ac_exec_ext"
+      fi
+    done
+  done
+done
+IFS=$as_save_IFS
+lt_ac_max=0
+lt_ac_count=0
+# Add /usr/xpg4/bin/sed as it is typically found on Solaris
+# along with /bin/sed that truncates output.
+for lt_ac_sed in $lt_ac_sed_list /usr/xpg4/bin/sed; do
+  test ! -f $lt_ac_sed && continue
+  cat /dev/null > conftest.in
+  lt_ac_count=0
+  echo $ECHO_N "0123456789$ECHO_C" >conftest.in
+  # Check for GNU sed and select it if it is found.
+  if "$lt_ac_sed" --version 2>&1 < /dev/null | grep 'GNU' > /dev/null; then
+    lt_cv_path_SED=$lt_ac_sed
+    break
+  fi
+  while true; do
+    cat conftest.in conftest.in >conftest.tmp
+    mv conftest.tmp conftest.in
+    cp conftest.in conftest.nl
+    echo >>conftest.nl
+    $lt_ac_sed -e 's/a$//' < conftest.nl >conftest.out || break
+    cmp -s conftest.out conftest.nl || break
+    # 10000 chars as input seems more than enough
+    test $lt_ac_count -gt 10 && break
+    lt_ac_count=`expr $lt_ac_count + 1`
+    if test $lt_ac_count -gt $lt_ac_max; then
+      lt_ac_max=$lt_ac_count
+      lt_cv_path_SED=$lt_ac_sed
+    fi
+  done
+done
+])
+SED=$lt_cv_path_SED
+AC_SUBST([SED])
+AC_MSG_RESULT([$SED])
+])#AC_PROG_SED
+])#m4_ifndef
+
+# Old name:
+AU_ALIAS([LT_AC_PROG_SED], [AC_PROG_SED])
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([LT_AC_PROG_SED], [])
+
+
+# _LT_CHECK_SHELL_FEATURES
+# ------------------------
+# Find out whether the shell is Bourne or XSI compatible,
+# or has some other useful features.
+m4_defun([_LT_CHECK_SHELL_FEATURES],
+[AC_MSG_CHECKING([whether the shell understands some XSI constructs])
+# Try some XSI features
+xsi_shell=no
+( _lt_dummy="a/b/c"
+  test "${_lt_dummy##*/},${_lt_dummy%/*},${_lt_dummy#??}"${_lt_dummy%"$_lt_dummy"}, \
+      = c,a/b,b/c, \
+    && eval 'test $(( 1 + 1 )) -eq 2 \
+    && test "${#_lt_dummy}" -eq 5' ) >/dev/null 2>&1 \
+  && xsi_shell=yes
+AC_MSG_RESULT([$xsi_shell])
+_LT_CONFIG_LIBTOOL_INIT([xsi_shell='$xsi_shell'])
+
+AC_MSG_CHECKING([whether the shell understands "+="])
+lt_shell_append=no
+( foo=bar; set foo baz; eval "$[1]+=\$[2]" && test "$foo" = barbaz ) \
+    >/dev/null 2>&1 \
+  && lt_shell_append=yes
+AC_MSG_RESULT([$lt_shell_append])
+_LT_CONFIG_LIBTOOL_INIT([lt_shell_append='$lt_shell_append'])
+
+if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then
+  lt_unset=unset
+else
+  lt_unset=false
+fi
+_LT_DECL([], [lt_unset], [0], [whether the shell understands "unset"])dnl
+
+# test EBCDIC or ASCII
+case `echo X|tr X '\101'` in
+ A) # ASCII based system
+    # \n is not interpreted correctly by Solaris 8 /usr/ucb/tr
+  lt_SP2NL='tr \040 \012'
+  lt_NL2SP='tr \015\012 \040\040'
+  ;;
+ *) # EBCDIC based system
+  lt_SP2NL='tr \100 \n'
+  lt_NL2SP='tr \r\n \100\100'
+  ;;
+esac
+_LT_DECL([SP2NL], [lt_SP2NL], [1], [turn spaces into newlines])dnl
+_LT_DECL([NL2SP], [lt_NL2SP], [1], [turn newlines into spaces])dnl
+])# _LT_CHECK_SHELL_FEATURES
+
+
+# _LT_PROG_FUNCTION_REPLACE (FUNCNAME, REPLACEMENT-BODY)
+# ------------------------------------------------------
+# In `$cfgfile', look for function FUNCNAME delimited by `^FUNCNAME ()$' and
+# '^} FUNCNAME ', and replace its body with REPLACEMENT-BODY.
+m4_defun([_LT_PROG_FUNCTION_REPLACE],
+[dnl {
+sed -e '/^$1 ()$/,/^} # $1 /c\
+$1 ()\
+{\
+m4_bpatsubsts([$2], [$], [\\], [^\([	 ]\)], [\\\1])
+} # Extended-shell $1 implementation' "$cfgfile" > $cfgfile.tmp \
+  && mv -f "$cfgfile.tmp" "$cfgfile" \
+    || (rm -f "$cfgfile" && cp "$cfgfile.tmp" "$cfgfile" && rm -f "$cfgfile.tmp")
+test 0 -eq $? || _lt_function_replace_fail=:
+])
+
+
+# _LT_PROG_REPLACE_SHELLFNS
+# -------------------------
+# Replace existing portable implementations of several shell functions with
+# equivalent extended shell implementations where those features are available..
+m4_defun([_LT_PROG_REPLACE_SHELLFNS],
+[if test x"$xsi_shell" = xyes; then
+  _LT_PROG_FUNCTION_REPLACE([func_dirname], [dnl
+    case ${1} in
+      */*) func_dirname_result="${1%/*}${2}" ;;
+      *  ) func_dirname_result="${3}" ;;
+    esac])
+
+  _LT_PROG_FUNCTION_REPLACE([func_basename], [dnl
+    func_basename_result="${1##*/}"])
+
+  _LT_PROG_FUNCTION_REPLACE([func_dirname_and_basename], [dnl
+    case ${1} in
+      */*) func_dirname_result="${1%/*}${2}" ;;
+      *  ) func_dirname_result="${3}" ;;
+    esac
+    func_basename_result="${1##*/}"])
+
+  _LT_PROG_FUNCTION_REPLACE([func_stripname], [dnl
+    # pdksh 5.2.14 does not do ${X%$Y} correctly if both X and Y are
+    # positional parameters, so assign one to ordinary parameter first.
+    func_stripname_result=${3}
+    func_stripname_result=${func_stripname_result#"${1}"}
+    func_stripname_result=${func_stripname_result%"${2}"}])
+
+  _LT_PROG_FUNCTION_REPLACE([func_split_long_opt], [dnl
+    func_split_long_opt_name=${1%%=*}
+    func_split_long_opt_arg=${1#*=}])
+
+  _LT_PROG_FUNCTION_REPLACE([func_split_short_opt], [dnl
+    func_split_short_opt_arg=${1#??}
+    func_split_short_opt_name=${1%"$func_split_short_opt_arg"}])
+
+  _LT_PROG_FUNCTION_REPLACE([func_lo2o], [dnl
+    case ${1} in
+      *.lo) func_lo2o_result=${1%.lo}.${objext} ;;
+      *)    func_lo2o_result=${1} ;;
+    esac])
+
+  _LT_PROG_FUNCTION_REPLACE([func_xform], [    func_xform_result=${1%.*}.lo])
+
+  _LT_PROG_FUNCTION_REPLACE([func_arith], [    func_arith_result=$(( $[*] ))])
+
+  _LT_PROG_FUNCTION_REPLACE([func_len], [    func_len_result=${#1}])
+fi
+
+if test x"$lt_shell_append" = xyes; then
+  _LT_PROG_FUNCTION_REPLACE([func_append], [    eval "${1}+=\\${2}"])
+
+  _LT_PROG_FUNCTION_REPLACE([func_append_quoted], [dnl
+    func_quote_for_eval "${2}"
+dnl m4 expansion turns \\\\ into \\, and then the shell eval turns that into \
+    eval "${1}+=\\\\ \\$func_quote_for_eval_result"])
+
+  # Save a `func_append' function call where possible by direct use of '+='
+  sed -e 's%func_append \([[a-zA-Z_]]\{1,\}\) "%\1+="%g' $cfgfile > $cfgfile.tmp \
+    && mv -f "$cfgfile.tmp" "$cfgfile" \
+      || (rm -f "$cfgfile" && cp "$cfgfile.tmp" "$cfgfile" && rm -f "$cfgfile.tmp")
+  test 0 -eq $? || _lt_function_replace_fail=:
+else
+  # Save a `func_append' function call even when '+=' is not available
+  sed -e 's%func_append \([[a-zA-Z_]]\{1,\}\) "%\1="$\1%g' $cfgfile > $cfgfile.tmp \
+    && mv -f "$cfgfile.tmp" "$cfgfile" \
+      || (rm -f "$cfgfile" && cp "$cfgfile.tmp" "$cfgfile" && rm -f "$cfgfile.tmp")
+  test 0 -eq $? || _lt_function_replace_fail=:
+fi
+
+if test x"$_lt_function_replace_fail" = x":"; then
+  AC_MSG_WARN([Unable to substitute extended shell functions in $ofile])
+fi
+])
+
+# _LT_PATH_CONVERSION_FUNCTIONS
+# -----------------------------
+# Determine which file name conversion functions should be used by
+# func_to_host_file (and, implicitly, by func_to_host_path).  These are needed
+# for certain cross-compile configurations and native mingw.
+m4_defun([_LT_PATH_CONVERSION_FUNCTIONS],
+[AC_REQUIRE([AC_CANONICAL_HOST])dnl
+AC_REQUIRE([AC_CANONICAL_BUILD])dnl
+AC_MSG_CHECKING([how to convert $build file names to $host format])
+AC_CACHE_VAL(lt_cv_to_host_file_cmd,
+[case $host in
+  *-*-mingw* )
+    case $build in
+      *-*-mingw* ) # actually msys
+        lt_cv_to_host_file_cmd=func_convert_file_msys_to_w32
+        ;;
+      *-*-cygwin* )
+        lt_cv_to_host_file_cmd=func_convert_file_cygwin_to_w32
+        ;;
+      * ) # otherwise, assume *nix
+        lt_cv_to_host_file_cmd=func_convert_file_nix_to_w32
+        ;;
+    esac
+    ;;
+  *-*-cygwin* )
+    case $build in
+      *-*-mingw* ) # actually msys
+        lt_cv_to_host_file_cmd=func_convert_file_msys_to_cygwin
+        ;;
+      *-*-cygwin* )
+        lt_cv_to_host_file_cmd=func_convert_file_noop
+        ;;
+      * ) # otherwise, assume *nix
+        lt_cv_to_host_file_cmd=func_convert_file_nix_to_cygwin
+        ;;
+    esac
+    ;;
+  * ) # unhandled hosts (and "normal" native builds)
+    lt_cv_to_host_file_cmd=func_convert_file_noop
+    ;;
+esac
+])
+to_host_file_cmd=$lt_cv_to_host_file_cmd
+AC_MSG_RESULT([$lt_cv_to_host_file_cmd])
+_LT_DECL([to_host_file_cmd], [lt_cv_to_host_file_cmd],
+         [0], [convert $build file names to $host format])dnl
+
+AC_MSG_CHECKING([how to convert $build file names to toolchain format])
+AC_CACHE_VAL(lt_cv_to_tool_file_cmd,
+[#assume ordinary cross tools, or native build.
+lt_cv_to_tool_file_cmd=func_convert_file_noop
+case $host in
+  *-*-mingw* )
+    case $build in
+      *-*-mingw* ) # actually msys
+        lt_cv_to_tool_file_cmd=func_convert_file_msys_to_w32
+        ;;
+    esac
+    ;;
+esac
+])
+to_tool_file_cmd=$lt_cv_to_tool_file_cmd
+AC_MSG_RESULT([$lt_cv_to_tool_file_cmd])
+_LT_DECL([to_tool_file_cmd], [lt_cv_to_tool_file_cmd],
+         [0], [convert $build files to toolchain format])dnl
+])# _LT_PATH_CONVERSION_FUNCTIONS
+
+# Helper functions for option handling.                    -*- Autoconf -*-
+#
+#   Copyright (C) 2004, 2005, 2007, 2008, 2009 Free Software Foundation,
+#   Inc.
+#   Written by Gary V. Vaughan, 2004
+#
+# This file is free software; the Free Software Foundation gives
+# unlimited permission to copy and/or distribute it, with or without
+# modifications, as long as this notice is preserved.
+
+# serial 7 ltoptions.m4
+
+# This is to help aclocal find these macros, as it can't see m4_define.
+AC_DEFUN([LTOPTIONS_VERSION], [m4_if([1])])
+
+
+# _LT_MANGLE_OPTION(MACRO-NAME, OPTION-NAME)
+# ------------------------------------------
+m4_define([_LT_MANGLE_OPTION],
+[[_LT_OPTION_]m4_bpatsubst($1__$2, [[^a-zA-Z0-9_]], [_])])
+
+
+# _LT_SET_OPTION(MACRO-NAME, OPTION-NAME)
+# ---------------------------------------
+# Set option OPTION-NAME for macro MACRO-NAME, and if there is a
+# matching handler defined, dispatch to it.  Other OPTION-NAMEs are
+# saved as a flag.
+m4_define([_LT_SET_OPTION],
+[m4_define(_LT_MANGLE_OPTION([$1], [$2]))dnl
+m4_ifdef(_LT_MANGLE_DEFUN([$1], [$2]),
+        _LT_MANGLE_DEFUN([$1], [$2]),
+    [m4_warning([Unknown $1 option `$2'])])[]dnl
+])
+
+
+# _LT_IF_OPTION(MACRO-NAME, OPTION-NAME, IF-SET, [IF-NOT-SET])
+# ------------------------------------------------------------
+# Execute IF-SET if OPTION is set, IF-NOT-SET otherwise.
+m4_define([_LT_IF_OPTION],
+[m4_ifdef(_LT_MANGLE_OPTION([$1], [$2]), [$3], [$4])])
+
+
+# _LT_UNLESS_OPTIONS(MACRO-NAME, OPTION-LIST, IF-NOT-SET)
+# -------------------------------------------------------
+# Execute IF-NOT-SET unless all options in OPTION-LIST for MACRO-NAME
+# are set.
+m4_define([_LT_UNLESS_OPTIONS],
+[m4_foreach([_LT_Option], m4_split(m4_normalize([$2])),
+	    [m4_ifdef(_LT_MANGLE_OPTION([$1], _LT_Option),
+		      [m4_define([$0_found])])])[]dnl
+m4_ifdef([$0_found], [m4_undefine([$0_found])], [$3
+])[]dnl
+])
+
+
+# _LT_SET_OPTIONS(MACRO-NAME, OPTION-LIST)
+# ----------------------------------------
+# OPTION-LIST is a space-separated list of Libtool options associated
+# with MACRO-NAME.  If any OPTION has a matching handler declared with
+# LT_OPTION_DEFINE, dispatch to that macro; otherwise complain about
+# the unknown option and exit.
+m4_defun([_LT_SET_OPTIONS],
+[# Set options
+m4_foreach([_LT_Option], m4_split(m4_normalize([$2])),
+    [_LT_SET_OPTION([$1], _LT_Option)])
+
+m4_if([$1],[LT_INIT],[
+  dnl
+  dnl Simply set some default values (i.e off) if boolean options were not
+  dnl specified:
+  _LT_UNLESS_OPTIONS([LT_INIT], [dlopen], [enable_dlopen=no
+  ])
+  _LT_UNLESS_OPTIONS([LT_INIT], [win32-dll], [enable_win32_dll=no
+  ])
+  dnl
+  dnl If no reference was made to various pairs of opposing options, then
+  dnl we run the default mode handler for the pair.  For example, if neither
+  dnl `shared' nor `disable-shared' was passed, we enable building of shared
+  dnl archives by default:
+  _LT_UNLESS_OPTIONS([LT_INIT], [shared disable-shared], [_LT_ENABLE_SHARED])
+  _LT_UNLESS_OPTIONS([LT_INIT], [static disable-static], [_LT_ENABLE_STATIC])
+  _LT_UNLESS_OPTIONS([LT_INIT], [pic-only no-pic], [_LT_WITH_PIC])
+  _LT_UNLESS_OPTIONS([LT_INIT], [fast-install disable-fast-install],
+  		   [_LT_ENABLE_FAST_INSTALL])
+  ])
+])# _LT_SET_OPTIONS
+
+
+
+# _LT_MANGLE_DEFUN(MACRO-NAME, OPTION-NAME)
+# -----------------------------------------
+m4_define([_LT_MANGLE_DEFUN],
+[[_LT_OPTION_DEFUN_]m4_bpatsubst(m4_toupper([$1__$2]), [[^A-Z0-9_]], [_])])
+
+
+# LT_OPTION_DEFINE(MACRO-NAME, OPTION-NAME, CODE)
+# -----------------------------------------------
+m4_define([LT_OPTION_DEFINE],
+[m4_define(_LT_MANGLE_DEFUN([$1], [$2]), [$3])[]dnl
+])# LT_OPTION_DEFINE
+
+
+# dlopen
+# ------
+LT_OPTION_DEFINE([LT_INIT], [dlopen], [enable_dlopen=yes
+])
+
+AU_DEFUN([AC_LIBTOOL_DLOPEN],
+[_LT_SET_OPTION([LT_INIT], [dlopen])
+AC_DIAGNOSE([obsolete],
+[$0: Remove this warning and the call to _LT_SET_OPTION when you
+put the `dlopen' option into LT_INIT's first parameter.])
+])
+
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AC_LIBTOOL_DLOPEN], [])
+
+
+# win32-dll
+# ---------
+# Declare package support for building win32 dll's.
+LT_OPTION_DEFINE([LT_INIT], [win32-dll],
+[enable_win32_dll=yes
+
+case $host in
+*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-cegcc*)
+  AC_CHECK_TOOL(AS, as, false)
+  AC_CHECK_TOOL(DLLTOOL, dlltool, false)
+  AC_CHECK_TOOL(OBJDUMP, objdump, false)
+  ;;
+esac
+
+test -z "$AS" && AS=as
+_LT_DECL([], [AS],      [1], [Assembler program])dnl
+
+test -z "$DLLTOOL" && DLLTOOL=dlltool
+_LT_DECL([], [DLLTOOL], [1], [DLL creation program])dnl
+
+test -z "$OBJDUMP" && OBJDUMP=objdump
+_LT_DECL([], [OBJDUMP], [1], [Object dumper program])dnl
+])# win32-dll
+
+AU_DEFUN([AC_LIBTOOL_WIN32_DLL],
+[AC_REQUIRE([AC_CANONICAL_HOST])dnl
+_LT_SET_OPTION([LT_INIT], [win32-dll])
+AC_DIAGNOSE([obsolete],
+[$0: Remove this warning and the call to _LT_SET_OPTION when you
+put the `win32-dll' option into LT_INIT's first parameter.])
+])
+
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AC_LIBTOOL_WIN32_DLL], [])
+
+
+# _LT_ENABLE_SHARED([DEFAULT])
+# ----------------------------
+# implement the --enable-shared flag, and supports the `shared' and
+# `disable-shared' LT_INIT options.
+# DEFAULT is either `yes' or `no'.  If omitted, it defaults to `yes'.
+m4_define([_LT_ENABLE_SHARED],
+[m4_define([_LT_ENABLE_SHARED_DEFAULT], [m4_if($1, no, no, yes)])dnl
+AC_ARG_ENABLE([shared],
+    [AS_HELP_STRING([--enable-shared@<:@=PKGS@:>@],
+	[build shared libraries @<:@default=]_LT_ENABLE_SHARED_DEFAULT[@:>@])],
+    [p=${PACKAGE-default}
+    case $enableval in
+    yes) enable_shared=yes ;;
+    no) enable_shared=no ;;
+    *)
+      enable_shared=no
+      # Look at the argument we got.  We use all the common list separators.
+      lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR,"
+      for pkg in $enableval; do
+	IFS="$lt_save_ifs"
+	if test "X$pkg" = "X$p"; then
+	  enable_shared=yes
+	fi
+      done
+      IFS="$lt_save_ifs"
+      ;;
+    esac],
+    [enable_shared=]_LT_ENABLE_SHARED_DEFAULT)
+
+    _LT_DECL([build_libtool_libs], [enable_shared], [0],
+	[Whether or not to build shared libraries])
+])# _LT_ENABLE_SHARED
+
+LT_OPTION_DEFINE([LT_INIT], [shared], [_LT_ENABLE_SHARED([yes])])
+LT_OPTION_DEFINE([LT_INIT], [disable-shared], [_LT_ENABLE_SHARED([no])])
+
+# Old names:
+AC_DEFUN([AC_ENABLE_SHARED],
+[_LT_SET_OPTION([LT_INIT], m4_if([$1], [no], [disable-])[shared])
+])
+
+AC_DEFUN([AC_DISABLE_SHARED],
+[_LT_SET_OPTION([LT_INIT], [disable-shared])
+])
+
+AU_DEFUN([AM_ENABLE_SHARED], [AC_ENABLE_SHARED($@)])
+AU_DEFUN([AM_DISABLE_SHARED], [AC_DISABLE_SHARED($@)])
+
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AM_ENABLE_SHARED], [])
+dnl AC_DEFUN([AM_DISABLE_SHARED], [])
+
+
+
+# _LT_ENABLE_STATIC([DEFAULT])
+# ----------------------------
+# implement the --enable-static flag, and support the `static' and
+# `disable-static' LT_INIT options.
+# DEFAULT is either `yes' or `no'.  If omitted, it defaults to `yes'.
+m4_define([_LT_ENABLE_STATIC],
+[m4_define([_LT_ENABLE_STATIC_DEFAULT], [m4_if($1, no, no, yes)])dnl
+AC_ARG_ENABLE([static],
+    [AS_HELP_STRING([--enable-static@<:@=PKGS@:>@],
+	[build static libraries @<:@default=]_LT_ENABLE_STATIC_DEFAULT[@:>@])],
+    [p=${PACKAGE-default}
+    case $enableval in
+    yes) enable_static=yes ;;
+    no) enable_static=no ;;
+    *)
+     enable_static=no
+      # Look at the argument we got.  We use all the common list separators.
+      lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR,"
+      for pkg in $enableval; do
+	IFS="$lt_save_ifs"
+	if test "X$pkg" = "X$p"; then
+	  enable_static=yes
+	fi
+      done
+      IFS="$lt_save_ifs"
+      ;;
+    esac],
+    [enable_static=]_LT_ENABLE_STATIC_DEFAULT)
+
+    _LT_DECL([build_old_libs], [enable_static], [0],
+	[Whether or not to build static libraries])
+])# _LT_ENABLE_STATIC
+
+LT_OPTION_DEFINE([LT_INIT], [static], [_LT_ENABLE_STATIC([yes])])
+LT_OPTION_DEFINE([LT_INIT], [disable-static], [_LT_ENABLE_STATIC([no])])
+
+# Old names:
+AC_DEFUN([AC_ENABLE_STATIC],
+[_LT_SET_OPTION([LT_INIT], m4_if([$1], [no], [disable-])[static])
+])
+
+AC_DEFUN([AC_DISABLE_STATIC],
+[_LT_SET_OPTION([LT_INIT], [disable-static])
+])
+
+AU_DEFUN([AM_ENABLE_STATIC], [AC_ENABLE_STATIC($@)])
+AU_DEFUN([AM_DISABLE_STATIC], [AC_DISABLE_STATIC($@)])
+
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AM_ENABLE_STATIC], [])
+dnl AC_DEFUN([AM_DISABLE_STATIC], [])
+
+
+
+# _LT_ENABLE_FAST_INSTALL([DEFAULT])
+# ----------------------------------
+# implement the --enable-fast-install flag, and support the `fast-install'
+# and `disable-fast-install' LT_INIT options.
+# DEFAULT is either `yes' or `no'.  If omitted, it defaults to `yes'.
+m4_define([_LT_ENABLE_FAST_INSTALL],
+[m4_define([_LT_ENABLE_FAST_INSTALL_DEFAULT], [m4_if($1, no, no, yes)])dnl
+AC_ARG_ENABLE([fast-install],
+    [AS_HELP_STRING([--enable-fast-install@<:@=PKGS@:>@],
+    [optimize for fast installation @<:@default=]_LT_ENABLE_FAST_INSTALL_DEFAULT[@:>@])],
+    [p=${PACKAGE-default}
+    case $enableval in
+    yes) enable_fast_install=yes ;;
+    no) enable_fast_install=no ;;
+    *)
+      enable_fast_install=no
+      # Look at the argument we got.  We use all the common list separators.
+      lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR,"
+      for pkg in $enableval; do
+	IFS="$lt_save_ifs"
+	if test "X$pkg" = "X$p"; then
+	  enable_fast_install=yes
+	fi
+      done
+      IFS="$lt_save_ifs"
+      ;;
+    esac],
+    [enable_fast_install=]_LT_ENABLE_FAST_INSTALL_DEFAULT)
+
+_LT_DECL([fast_install], [enable_fast_install], [0],
+	 [Whether or not to optimize for fast installation])dnl
+])# _LT_ENABLE_FAST_INSTALL
+
+LT_OPTION_DEFINE([LT_INIT], [fast-install], [_LT_ENABLE_FAST_INSTALL([yes])])
+LT_OPTION_DEFINE([LT_INIT], [disable-fast-install], [_LT_ENABLE_FAST_INSTALL([no])])
+
+# Old names:
+AU_DEFUN([AC_ENABLE_FAST_INSTALL],
+[_LT_SET_OPTION([LT_INIT], m4_if([$1], [no], [disable-])[fast-install])
+AC_DIAGNOSE([obsolete],
+[$0: Remove this warning and the call to _LT_SET_OPTION when you put
+the `fast-install' option into LT_INIT's first parameter.])
+])
+
+AU_DEFUN([AC_DISABLE_FAST_INSTALL],
+[_LT_SET_OPTION([LT_INIT], [disable-fast-install])
+AC_DIAGNOSE([obsolete],
+[$0: Remove this warning and the call to _LT_SET_OPTION when you put
+the `disable-fast-install' option into LT_INIT's first parameter.])
+])
+
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AC_ENABLE_FAST_INSTALL], [])
+dnl AC_DEFUN([AM_DISABLE_FAST_INSTALL], [])
+
+
+# _LT_WITH_PIC([MODE])
+# --------------------
+# implement the --with-pic flag, and support the `pic-only' and `no-pic'
+# LT_INIT options.
+# MODE is either `yes' or `no'.  If omitted, it defaults to `both'.
+m4_define([_LT_WITH_PIC],
+[AC_ARG_WITH([pic],
+    [AS_HELP_STRING([--with-pic@<:@=PKGS@:>@],
+	[try to use only PIC/non-PIC objects @<:@default=use both@:>@])],
+    [lt_p=${PACKAGE-default}
+    case $withval in
+    yes|no) pic_mode=$withval ;;
+    *)
+      pic_mode=default
+      # Look at the argument we got.  We use all the common list separators.
+      lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR,"
+      for lt_pkg in $withval; do
+	IFS="$lt_save_ifs"
+	if test "X$lt_pkg" = "X$lt_p"; then
+	  pic_mode=yes
+	fi
+      done
+      IFS="$lt_save_ifs"
+      ;;
+    esac],
+    [pic_mode=default])
+
+test -z "$pic_mode" && pic_mode=m4_default([$1], [default])
+
+_LT_DECL([], [pic_mode], [0], [What type of objects to build])dnl
+])# _LT_WITH_PIC
+
+LT_OPTION_DEFINE([LT_INIT], [pic-only], [_LT_WITH_PIC([yes])])
+LT_OPTION_DEFINE([LT_INIT], [no-pic], [_LT_WITH_PIC([no])])
+
+# Old name:
+AU_DEFUN([AC_LIBTOOL_PICMODE],
+[_LT_SET_OPTION([LT_INIT], [pic-only])
+AC_DIAGNOSE([obsolete],
+[$0: Remove this warning and the call to _LT_SET_OPTION when you
+put the `pic-only' option into LT_INIT's first parameter.])
+])
+
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AC_LIBTOOL_PICMODE], [])
+
+
+m4_define([_LTDL_MODE], [])
+LT_OPTION_DEFINE([LTDL_INIT], [nonrecursive],
+		 [m4_define([_LTDL_MODE], [nonrecursive])])
+LT_OPTION_DEFINE([LTDL_INIT], [recursive],
+		 [m4_define([_LTDL_MODE], [recursive])])
+LT_OPTION_DEFINE([LTDL_INIT], [subproject],
+		 [m4_define([_LTDL_MODE], [subproject])])
+
+m4_define([_LTDL_TYPE], [])
+LT_OPTION_DEFINE([LTDL_INIT], [installable],
+		 [m4_define([_LTDL_TYPE], [installable])])
+LT_OPTION_DEFINE([LTDL_INIT], [convenience],
+		 [m4_define([_LTDL_TYPE], [convenience])])
+
+# ltsugar.m4 -- libtool m4 base layer.                         -*-Autoconf-*-
+#
+# Copyright (C) 2004, 2005, 2007, 2008 Free Software Foundation, Inc.
+# Written by Gary V. Vaughan, 2004
+#
+# This file is free software; the Free Software Foundation gives
+# unlimited permission to copy and/or distribute it, with or without
+# modifications, as long as this notice is preserved.
+
+# serial 6 ltsugar.m4
+
+# This is to help aclocal find these macros, as it can't see m4_define.
+AC_DEFUN([LTSUGAR_VERSION], [m4_if([0.1])])
+
+
+# lt_join(SEP, ARG1, [ARG2...])
+# -----------------------------
+# Produce ARG1SEPARG2...SEPARGn, omitting [] arguments and their
+# associated separator.
+# Needed until we can rely on m4_join from Autoconf 2.62, since all earlier
+# versions in m4sugar had bugs.
+m4_define([lt_join],
+[m4_if([$#], [1], [],
+       [$#], [2], [[$2]],
+       [m4_if([$2], [], [], [[$2]_])$0([$1], m4_shift(m4_shift($@)))])])
+m4_define([_lt_join],
+[m4_if([$#$2], [2], [],
+       [m4_if([$2], [], [], [[$1$2]])$0([$1], m4_shift(m4_shift($@)))])])
+
+
+# lt_car(LIST)
+# lt_cdr(LIST)
+# ------------
+# Manipulate m4 lists.
+# These macros are necessary as long as will still need to support
+# Autoconf-2.59 which quotes differently.
+m4_define([lt_car], [[$1]])
+m4_define([lt_cdr],
+[m4_if([$#], 0, [m4_fatal([$0: cannot be called without arguments])],
+       [$#], 1, [],
+       [m4_dquote(m4_shift($@))])])
+m4_define([lt_unquote], $1)
+
+
+# lt_append(MACRO-NAME, STRING, [SEPARATOR])
+# ------------------------------------------
+# Redefine MACRO-NAME to hold its former content plus `SEPARATOR'`STRING'.
+# Note that neither SEPARATOR nor STRING are expanded; they are appended
+# to MACRO-NAME as is (leaving the expansion for when MACRO-NAME is invoked).
+# No SEPARATOR is output if MACRO-NAME was previously undefined (different
+# than defined and empty).
+#
+# This macro is needed until we can rely on Autoconf 2.62, since earlier
+# versions of m4sugar mistakenly expanded SEPARATOR but not STRING.
+m4_define([lt_append],
+[m4_define([$1],
+	   m4_ifdef([$1], [m4_defn([$1])[$3]])[$2])])
+
+
+
+# lt_combine(SEP, PREFIX-LIST, INFIX, SUFFIX1, [SUFFIX2...])
+# ----------------------------------------------------------
+# Produce a SEP delimited list of all paired combinations of elements of
+# PREFIX-LIST with SUFFIX1 through SUFFIXn.  Each element of the list
+# has the form PREFIXmINFIXSUFFIXn.
+# Needed until we can rely on m4_combine added in Autoconf 2.62.
+m4_define([lt_combine],
+[m4_if(m4_eval([$# > 3]), [1],
+       [m4_pushdef([_Lt_sep], [m4_define([_Lt_sep], m4_defn([lt_car]))])]]dnl
+[[m4_foreach([_Lt_prefix], [$2],
+	     [m4_foreach([_Lt_suffix],
+		]m4_dquote(m4_dquote(m4_shift(m4_shift(m4_shift($@)))))[,
+	[_Lt_sep([$1])[]m4_defn([_Lt_prefix])[$3]m4_defn([_Lt_suffix])])])])])
+
+
+# lt_if_append_uniq(MACRO-NAME, VARNAME, [SEPARATOR], [UNIQ], [NOT-UNIQ])
+# -----------------------------------------------------------------------
+# Iff MACRO-NAME does not yet contain VARNAME, then append it (delimited
+# by SEPARATOR if supplied) and expand UNIQ, else NOT-UNIQ.
+m4_define([lt_if_append_uniq],
+[m4_ifdef([$1],
+	  [m4_if(m4_index([$3]m4_defn([$1])[$3], [$3$2$3]), [-1],
+		 [lt_append([$1], [$2], [$3])$4],
+		 [$5])],
+	  [lt_append([$1], [$2], [$3])$4])])
+
+
+# lt_dict_add(DICT, KEY, VALUE)
+# -----------------------------
+m4_define([lt_dict_add],
+[m4_define([$1($2)], [$3])])
+
+
+# lt_dict_add_subkey(DICT, KEY, SUBKEY, VALUE)
+# --------------------------------------------
+m4_define([lt_dict_add_subkey],
+[m4_define([$1($2:$3)], [$4])])
+
+
+# lt_dict_fetch(DICT, KEY, [SUBKEY])
+# ----------------------------------
+m4_define([lt_dict_fetch],
+[m4_ifval([$3],
+	m4_ifdef([$1($2:$3)], [m4_defn([$1($2:$3)])]),
+    m4_ifdef([$1($2)], [m4_defn([$1($2)])]))])
+
+
+# lt_if_dict_fetch(DICT, KEY, [SUBKEY], VALUE, IF-TRUE, [IF-FALSE])
+# -----------------------------------------------------------------
+m4_define([lt_if_dict_fetch],
+[m4_if(lt_dict_fetch([$1], [$2], [$3]), [$4],
+	[$5],
+    [$6])])
+
+
+# lt_dict_filter(DICT, [SUBKEY], VALUE, [SEPARATOR], KEY, [...])
+# --------------------------------------------------------------
+m4_define([lt_dict_filter],
+[m4_if([$5], [], [],
+  [lt_join(m4_quote(m4_default([$4], [[, ]])),
+           lt_unquote(m4_split(m4_normalize(m4_foreach(_Lt_key, lt_car([m4_shiftn(4, $@)]),
+		      [lt_if_dict_fetch([$1], _Lt_key, [$2], [$3], [_Lt_key ])])))))])[]dnl
+])
+
+# ltversion.m4 -- version numbers			-*- Autoconf -*-
+#
+#   Copyright (C) 2004 Free Software Foundation, Inc.
+#   Written by Scott James Remnant, 2004
+#
+# This file is free software; the Free Software Foundation gives
+# unlimited permission to copy and/or distribute it, with or without
+# modifications, as long as this notice is preserved.
+
+# @configure_input@
+
+# serial 3337 ltversion.m4
+# This file is part of GNU Libtool
+
+m4_define([LT_PACKAGE_VERSION], [2.4.2])
+m4_define([LT_PACKAGE_REVISION], [1.3337])
+
+AC_DEFUN([LTVERSION_VERSION],
+[macro_version='2.4.2'
+macro_revision='1.3337'
+_LT_DECL(, macro_version, 0, [Which release of libtool.m4 was used?])
+_LT_DECL(, macro_revision, 0)
+])
+
+# lt~obsolete.m4 -- aclocal satisfying obsolete definitions.    -*-Autoconf-*-
+#
+#   Copyright (C) 2004, 2005, 2007, 2009 Free Software Foundation, Inc.
+#   Written by Scott James Remnant, 2004.
+#
+# This file is free software; the Free Software Foundation gives
+# unlimited permission to copy and/or distribute it, with or without
+# modifications, as long as this notice is preserved.
+
+# serial 5 lt~obsolete.m4
+
+# These exist entirely to fool aclocal when bootstrapping libtool.
+#
+# In the past libtool.m4 has provided macros via AC_DEFUN (or AU_DEFUN)
+# which have later been changed to m4_define as they aren't part of the
+# exported API, or moved to Autoconf or Automake where they belong.
+#
+# The trouble is, aclocal is a bit thick.  It'll see the old AC_DEFUN
+# in /usr/share/aclocal/libtool.m4 and remember it, then when it sees us
+# using a macro with the same name in our local m4/libtool.m4 it'll
+# pull the old libtool.m4 in (it doesn't see our shiny new m4_define
+# and doesn't know about Autoconf macros at all.)
+#
+# So we provide this file, which has a silly filename so it's always
+# included after everything else.  This provides aclocal with the
+# AC_DEFUNs it wants, but when m4 processes it, it doesn't do anything
+# because those macros already exist, or will be overwritten later.
+# We use AC_DEFUN over AU_DEFUN for compatibility with aclocal-1.6. 
+#
+# Anytime we withdraw an AC_DEFUN or AU_DEFUN, remember to add it here.
+# Yes, that means every name once taken will need to remain here until
+# we give up compatibility with versions before 1.7, at which point
+# we need to keep only those names which we still refer to.
+
+# This is to help aclocal find these macros, as it can't see m4_define.
+AC_DEFUN([LTOBSOLETE_VERSION], [m4_if([1])])
+
+m4_ifndef([AC_LIBTOOL_LINKER_OPTION],	[AC_DEFUN([AC_LIBTOOL_LINKER_OPTION])])
+m4_ifndef([AC_PROG_EGREP],		[AC_DEFUN([AC_PROG_EGREP])])
+m4_ifndef([_LT_AC_PROG_ECHO_BACKSLASH],	[AC_DEFUN([_LT_AC_PROG_ECHO_BACKSLASH])])
+m4_ifndef([_LT_AC_SHELL_INIT],		[AC_DEFUN([_LT_AC_SHELL_INIT])])
+m4_ifndef([_LT_AC_SYS_LIBPATH_AIX],	[AC_DEFUN([_LT_AC_SYS_LIBPATH_AIX])])
+m4_ifndef([_LT_PROG_LTMAIN],		[AC_DEFUN([_LT_PROG_LTMAIN])])
+m4_ifndef([_LT_AC_TAGVAR],		[AC_DEFUN([_LT_AC_TAGVAR])])
+m4_ifndef([AC_LTDL_ENABLE_INSTALL],	[AC_DEFUN([AC_LTDL_ENABLE_INSTALL])])
+m4_ifndef([AC_LTDL_PREOPEN],		[AC_DEFUN([AC_LTDL_PREOPEN])])
+m4_ifndef([_LT_AC_SYS_COMPILER],	[AC_DEFUN([_LT_AC_SYS_COMPILER])])
+m4_ifndef([_LT_AC_LOCK],		[AC_DEFUN([_LT_AC_LOCK])])
+m4_ifndef([AC_LIBTOOL_SYS_OLD_ARCHIVE],	[AC_DEFUN([AC_LIBTOOL_SYS_OLD_ARCHIVE])])
+m4_ifndef([_LT_AC_TRY_DLOPEN_SELF],	[AC_DEFUN([_LT_AC_TRY_DLOPEN_SELF])])
+m4_ifndef([AC_LIBTOOL_PROG_CC_C_O],	[AC_DEFUN([AC_LIBTOOL_PROG_CC_C_O])])
+m4_ifndef([AC_LIBTOOL_SYS_HARD_LINK_LOCKS], [AC_DEFUN([AC_LIBTOOL_SYS_HARD_LINK_LOCKS])])
+m4_ifndef([AC_LIBTOOL_OBJDIR],		[AC_DEFUN([AC_LIBTOOL_OBJDIR])])
+m4_ifndef([AC_LTDL_OBJDIR],		[AC_DEFUN([AC_LTDL_OBJDIR])])
+m4_ifndef([AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH], [AC_DEFUN([AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH])])
+m4_ifndef([AC_LIBTOOL_SYS_LIB_STRIP],	[AC_DEFUN([AC_LIBTOOL_SYS_LIB_STRIP])])
+m4_ifndef([AC_PATH_MAGIC],		[AC_DEFUN([AC_PATH_MAGIC])])
+m4_ifndef([AC_PROG_LD_GNU],		[AC_DEFUN([AC_PROG_LD_GNU])])
+m4_ifndef([AC_PROG_LD_RELOAD_FLAG],	[AC_DEFUN([AC_PROG_LD_RELOAD_FLAG])])
+m4_ifndef([AC_DEPLIBS_CHECK_METHOD],	[AC_DEFUN([AC_DEPLIBS_CHECK_METHOD])])
+m4_ifndef([AC_LIBTOOL_PROG_COMPILER_NO_RTTI], [AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_NO_RTTI])])
+m4_ifndef([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE], [AC_DEFUN([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE])])
+m4_ifndef([AC_LIBTOOL_PROG_COMPILER_PIC], [AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_PIC])])
+m4_ifndef([AC_LIBTOOL_PROG_LD_SHLIBS],	[AC_DEFUN([AC_LIBTOOL_PROG_LD_SHLIBS])])
+m4_ifndef([AC_LIBTOOL_POSTDEP_PREDEP],	[AC_DEFUN([AC_LIBTOOL_POSTDEP_PREDEP])])
+m4_ifndef([LT_AC_PROG_EGREP],		[AC_DEFUN([LT_AC_PROG_EGREP])])
+m4_ifndef([LT_AC_PROG_SED],		[AC_DEFUN([LT_AC_PROG_SED])])
+m4_ifndef([_LT_CC_BASENAME],		[AC_DEFUN([_LT_CC_BASENAME])])
+m4_ifndef([_LT_COMPILER_BOILERPLATE],	[AC_DEFUN([_LT_COMPILER_BOILERPLATE])])
+m4_ifndef([_LT_LINKER_BOILERPLATE],	[AC_DEFUN([_LT_LINKER_BOILERPLATE])])
+m4_ifndef([_AC_PROG_LIBTOOL],		[AC_DEFUN([_AC_PROG_LIBTOOL])])
+m4_ifndef([AC_LIBTOOL_SETUP],		[AC_DEFUN([AC_LIBTOOL_SETUP])])
+m4_ifndef([_LT_AC_CHECK_DLFCN],		[AC_DEFUN([_LT_AC_CHECK_DLFCN])])
+m4_ifndef([AC_LIBTOOL_SYS_DYNAMIC_LINKER],	[AC_DEFUN([AC_LIBTOOL_SYS_DYNAMIC_LINKER])])
+m4_ifndef([_LT_AC_TAGCONFIG],		[AC_DEFUN([_LT_AC_TAGCONFIG])])
+m4_ifndef([AC_DISABLE_FAST_INSTALL],	[AC_DEFUN([AC_DISABLE_FAST_INSTALL])])
+m4_ifndef([_LT_AC_LANG_CXX],		[AC_DEFUN([_LT_AC_LANG_CXX])])
+m4_ifndef([_LT_AC_LANG_F77],		[AC_DEFUN([_LT_AC_LANG_F77])])
+m4_ifndef([_LT_AC_LANG_GCJ],		[AC_DEFUN([_LT_AC_LANG_GCJ])])
+m4_ifndef([AC_LIBTOOL_LANG_C_CONFIG],	[AC_DEFUN([AC_LIBTOOL_LANG_C_CONFIG])])
+m4_ifndef([_LT_AC_LANG_C_CONFIG],	[AC_DEFUN([_LT_AC_LANG_C_CONFIG])])
+m4_ifndef([AC_LIBTOOL_LANG_CXX_CONFIG],	[AC_DEFUN([AC_LIBTOOL_LANG_CXX_CONFIG])])
+m4_ifndef([_LT_AC_LANG_CXX_CONFIG],	[AC_DEFUN([_LT_AC_LANG_CXX_CONFIG])])
+m4_ifndef([AC_LIBTOOL_LANG_F77_CONFIG],	[AC_DEFUN([AC_LIBTOOL_LANG_F77_CONFIG])])
+m4_ifndef([_LT_AC_LANG_F77_CONFIG],	[AC_DEFUN([_LT_AC_LANG_F77_CONFIG])])
+m4_ifndef([AC_LIBTOOL_LANG_GCJ_CONFIG],	[AC_DEFUN([AC_LIBTOOL_LANG_GCJ_CONFIG])])
+m4_ifndef([_LT_AC_LANG_GCJ_CONFIG],	[AC_DEFUN([_LT_AC_LANG_GCJ_CONFIG])])
+m4_ifndef([AC_LIBTOOL_LANG_RC_CONFIG],	[AC_DEFUN([AC_LIBTOOL_LANG_RC_CONFIG])])
+m4_ifndef([_LT_AC_LANG_RC_CONFIG],	[AC_DEFUN([_LT_AC_LANG_RC_CONFIG])])
+m4_ifndef([AC_LIBTOOL_CONFIG],		[AC_DEFUN([AC_LIBTOOL_CONFIG])])
+m4_ifndef([_LT_AC_FILE_LTDLL_C],	[AC_DEFUN([_LT_AC_FILE_LTDLL_C])])
+m4_ifndef([_LT_REQUIRED_DARWIN_CHECKS],	[AC_DEFUN([_LT_REQUIRED_DARWIN_CHECKS])])
+m4_ifndef([_LT_AC_PROG_CXXCPP],		[AC_DEFUN([_LT_AC_PROG_CXXCPP])])
+m4_ifndef([_LT_PREPARE_SED_QUOTE_VARS],	[AC_DEFUN([_LT_PREPARE_SED_QUOTE_VARS])])
+m4_ifndef([_LT_PROG_ECHO_BACKSLASH],	[AC_DEFUN([_LT_PROG_ECHO_BACKSLASH])])
+m4_ifndef([_LT_PROG_F77],		[AC_DEFUN([_LT_PROG_F77])])
+m4_ifndef([_LT_PROG_FC],		[AC_DEFUN([_LT_PROG_FC])])
+m4_ifndef([_LT_PROG_CXX],		[AC_DEFUN([_LT_PROG_CXX])])
+
+# pkg.m4 - Macros to locate and utilise pkg-config.            -*- Autoconf -*-
+# serial 1 (pkg-config-0.24)
+# 
+# Copyright © 2004 Scott James Remnant <scott@netsplit.com>.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+# As a special exception to the GNU General Public License, if you
+# distribute this file as part of a program that contains a
+# configuration script generated by Autoconf, you may include it under
+# the same distribution terms that you use for the rest of that program.
+
+# PKG_PROG_PKG_CONFIG([MIN-VERSION])
+# ----------------------------------
+AC_DEFUN([PKG_PROG_PKG_CONFIG],
+[m4_pattern_forbid([^_?PKG_[A-Z_]+$])
+m4_pattern_allow([^PKG_CONFIG(_(PATH|LIBDIR|SYSROOT_DIR|ALLOW_SYSTEM_(CFLAGS|LIBS)))?$])
+m4_pattern_allow([^PKG_CONFIG_(DISABLE_UNINSTALLED|TOP_BUILD_DIR|DEBUG_SPEW)$])
+AC_ARG_VAR([PKG_CONFIG], [path to pkg-config utility])
+AC_ARG_VAR([PKG_CONFIG_PATH], [directories to add to pkg-config's search path])
+AC_ARG_VAR([PKG_CONFIG_LIBDIR], [path overriding pkg-config's built-in search path])
+
+if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then
+	AC_PATH_TOOL([PKG_CONFIG], [pkg-config])
+fi
+if test -n "$PKG_CONFIG"; then
+	_pkg_min_version=m4_default([$1], [0.9.0])
+	AC_MSG_CHECKING([pkg-config is at least version $_pkg_min_version])
+	if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then
+		AC_MSG_RESULT([yes])
+	else
+		AC_MSG_RESULT([no])
+		PKG_CONFIG=""
+	fi
+fi[]dnl
+])# PKG_PROG_PKG_CONFIG
+
+# PKG_CHECK_EXISTS(MODULES, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
+#
+# Check to see whether a particular set of modules exists.  Similar
+# to PKG_CHECK_MODULES(), but does not set variables or print errors.
+#
+# Please remember that m4 expands AC_REQUIRE([PKG_PROG_PKG_CONFIG])
+# only at the first occurence in configure.ac, so if the first place
+# it's called might be skipped (such as if it is within an "if", you
+# have to call PKG_CHECK_EXISTS manually
+# --------------------------------------------------------------
+AC_DEFUN([PKG_CHECK_EXISTS],
+[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
+if test -n "$PKG_CONFIG" && \
+    AC_RUN_LOG([$PKG_CONFIG --exists --print-errors "$1"]); then
+  m4_default([$2], [:])
+m4_ifvaln([$3], [else
+  $3])dnl
+fi])
+
+# _PKG_CONFIG([VARIABLE], [COMMAND], [MODULES])
+# ---------------------------------------------
+m4_define([_PKG_CONFIG],
+[if test -n "$$1"; then
+    pkg_cv_[]$1="$$1"
+ elif test -n "$PKG_CONFIG"; then
+    PKG_CHECK_EXISTS([$3],
+                     [pkg_cv_[]$1=`$PKG_CONFIG --[]$2 "$3" 2>/dev/null`
+		      test "x$?" != "x0" && pkg_failed=yes ],
+		     [pkg_failed=yes])
+ else
+    pkg_failed=untried
+fi[]dnl
+])# _PKG_CONFIG
+
+# _PKG_SHORT_ERRORS_SUPPORTED
+# -----------------------------
+AC_DEFUN([_PKG_SHORT_ERRORS_SUPPORTED],
+[AC_REQUIRE([PKG_PROG_PKG_CONFIG])
+if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
+        _pkg_short_errors_supported=yes
+else
+        _pkg_short_errors_supported=no
+fi[]dnl
+])# _PKG_SHORT_ERRORS_SUPPORTED
+
+
+# PKG_CHECK_MODULES(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND],
+# [ACTION-IF-NOT-FOUND])
+#
+#
+# Note that if there is a possibility the first call to
+# PKG_CHECK_MODULES might not happen, you should be sure to include an
+# explicit call to PKG_PROG_PKG_CONFIG in your configure.ac
+#
+#
+# --------------------------------------------------------------
+AC_DEFUN([PKG_CHECK_MODULES],
+[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
+AC_ARG_VAR([$1][_CFLAGS], [C compiler flags for $1, overriding pkg-config])dnl
+AC_ARG_VAR([$1][_LIBS], [linker flags for $1, overriding pkg-config])dnl
+
+pkg_failed=no
+AC_MSG_CHECKING([for $1])
+
+_PKG_CONFIG([$1][_CFLAGS], [cflags], [$2])
+_PKG_CONFIG([$1][_LIBS], [libs], [$2])
+
+m4_define([_PKG_TEXT], [Alternatively, you may set the environment variables $1[]_CFLAGS
+and $1[]_LIBS to avoid the need to call pkg-config.
+See the pkg-config man page for more details.])
+
+if test $pkg_failed = yes; then
+   	AC_MSG_RESULT([no])
+        _PKG_SHORT_ERRORS_SUPPORTED
+        if test $_pkg_short_errors_supported = yes; then
+	        $1[]_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "$2" 2>&1`
+        else 
+	        $1[]_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "$2" 2>&1`
+        fi
+	# Put the nasty error message in config.log where it belongs
+	echo "$$1[]_PKG_ERRORS" >&AS_MESSAGE_LOG_FD
+
+	m4_default([$4], [AC_MSG_ERROR(
+[Package requirements ($2) were not met:
+
+$$1_PKG_ERRORS
+
+Consider adjusting the PKG_CONFIG_PATH environment variable if you
+installed software in a non-standard prefix.
+
+_PKG_TEXT])[]dnl
+        ])
+elif test $pkg_failed = untried; then
+     	AC_MSG_RESULT([no])
+	m4_default([$4], [AC_MSG_FAILURE(
+[The pkg-config script could not be found or is too old.  Make sure it
+is in your PATH or set the PKG_CONFIG environment variable to the full
+path to pkg-config.
+
+_PKG_TEXT
+
+To get pkg-config, see <http://pkg-config.freedesktop.org/>.])[]dnl
+        ])
+else
+	$1[]_CFLAGS=$pkg_cv_[]$1[]_CFLAGS
+	$1[]_LIBS=$pkg_cv_[]$1[]_LIBS
+        AC_MSG_RESULT([yes])
+	$3
+fi[]dnl
+])# PKG_CHECK_MODULES
+
+# Copyright (C) 2002-2013 Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# AM_AUTOMAKE_VERSION(VERSION)
+# ----------------------------
+# Automake X.Y traces this macro to ensure aclocal.m4 has been
+# generated from the m4 files accompanying Automake X.Y.
+# (This private macro should not be called outside this file.)
+AC_DEFUN([AM_AUTOMAKE_VERSION],
+[am__api_version='1.14'
+dnl Some users find AM_AUTOMAKE_VERSION and mistake it for a way to
+dnl require some minimum version.  Point them to the right macro.
+m4_if([$1], [1.14.1], [],
+      [AC_FATAL([Do not call $0, use AM_INIT_AUTOMAKE([$1]).])])dnl
+])
+
+# _AM_AUTOCONF_VERSION(VERSION)
+# -----------------------------
+# aclocal traces this macro to find the Autoconf version.
+# This is a private macro too.  Using m4_define simplifies
+# the logic in aclocal, which can simply ignore this definition.
+m4_define([_AM_AUTOCONF_VERSION], [])
+
+# AM_SET_CURRENT_AUTOMAKE_VERSION
+# -------------------------------
+# Call AM_AUTOMAKE_VERSION and AM_AUTOMAKE_VERSION so they can be traced.
+# This function is AC_REQUIREd by AM_INIT_AUTOMAKE.
+AC_DEFUN([AM_SET_CURRENT_AUTOMAKE_VERSION],
+[AM_AUTOMAKE_VERSION([1.14.1])dnl
+m4_ifndef([AC_AUTOCONF_VERSION],
+  [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl
+_AM_AUTOCONF_VERSION(m4_defn([AC_AUTOCONF_VERSION]))])
+
+# AM_AUX_DIR_EXPAND                                         -*- Autoconf -*-
+
+# Copyright (C) 2001-2013 Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# For projects using AC_CONFIG_AUX_DIR([foo]), Autoconf sets
+# $ac_aux_dir to '$srcdir/foo'.  In other projects, it is set to
+# '$srcdir', '$srcdir/..', or '$srcdir/../..'.
+#
+# Of course, Automake must honor this variable whenever it calls a
+# tool from the auxiliary directory.  The problem is that $srcdir (and
+# therefore $ac_aux_dir as well) can be either absolute or relative,
+# depending on how configure is run.  This is pretty annoying, since
+# it makes $ac_aux_dir quite unusable in subdirectories: in the top
+# source directory, any form will work fine, but in subdirectories a
+# relative path needs to be adjusted first.
+#
+# $ac_aux_dir/missing
+#    fails when called from a subdirectory if $ac_aux_dir is relative
+# $top_srcdir/$ac_aux_dir/missing
+#    fails if $ac_aux_dir is absolute,
+#    fails when called from a subdirectory in a VPATH build with
+#          a relative $ac_aux_dir
+#
+# The reason of the latter failure is that $top_srcdir and $ac_aux_dir
+# are both prefixed by $srcdir.  In an in-source build this is usually
+# harmless because $srcdir is '.', but things will broke when you
+# start a VPATH build or use an absolute $srcdir.
+#
+# So we could use something similar to $top_srcdir/$ac_aux_dir/missing,
+# iff we strip the leading $srcdir from $ac_aux_dir.  That would be:
+#   am_aux_dir='\$(top_srcdir)/'`expr "$ac_aux_dir" : "$srcdir//*\(.*\)"`
+# and then we would define $MISSING as
+#   MISSING="\${SHELL} $am_aux_dir/missing"
+# This will work as long as MISSING is not called from configure, because
+# unfortunately $(top_srcdir) has no meaning in configure.
+# However there are other variables, like CC, which are often used in
+# configure, and could therefore not use this "fixed" $ac_aux_dir.
+#
+# Another solution, used here, is to always expand $ac_aux_dir to an
+# absolute PATH.  The drawback is that using absolute paths prevent a
+# configured tree to be moved without reconfiguration.
+
+AC_DEFUN([AM_AUX_DIR_EXPAND],
+[dnl Rely on autoconf to set up CDPATH properly.
+AC_PREREQ([2.50])dnl
+# expand $ac_aux_dir to an absolute path
+am_aux_dir=`cd $ac_aux_dir && pwd`
+])
+
+# AM_CONDITIONAL                                            -*- Autoconf -*-
+
+# Copyright (C) 1997-2013 Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# AM_CONDITIONAL(NAME, SHELL-CONDITION)
+# -------------------------------------
+# Define a conditional.
+AC_DEFUN([AM_CONDITIONAL],
+[AC_PREREQ([2.52])dnl
+ m4_if([$1], [TRUE],  [AC_FATAL([$0: invalid condition: $1])],
+       [$1], [FALSE], [AC_FATAL([$0: invalid condition: $1])])dnl
+AC_SUBST([$1_TRUE])dnl
+AC_SUBST([$1_FALSE])dnl
+_AM_SUBST_NOTMAKE([$1_TRUE])dnl
+_AM_SUBST_NOTMAKE([$1_FALSE])dnl
+m4_define([_AM_COND_VALUE_$1], [$2])dnl
+if $2; then
+  $1_TRUE=
+  $1_FALSE='#'
+else
+  $1_TRUE='#'
+  $1_FALSE=
+fi
+AC_CONFIG_COMMANDS_PRE(
+[if test -z "${$1_TRUE}" && test -z "${$1_FALSE}"; then
+  AC_MSG_ERROR([[conditional "$1" was never defined.
+Usually this means the macro was only invoked conditionally.]])
+fi])])
+
+# Copyright (C) 1999-2013 Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+
+# There are a few dirty hacks below to avoid letting 'AC_PROG_CC' be
+# written in clear, in which case automake, when reading aclocal.m4,
+# will think it sees a *use*, and therefore will trigger all it's
+# C support machinery.  Also note that it means that autoscan, seeing
+# CC etc. in the Makefile, will ask for an AC_PROG_CC use...
+
+
+# _AM_DEPENDENCIES(NAME)
+# ----------------------
+# See how the compiler implements dependency checking.
+# NAME is "CC", "CXX", "OBJC", "OBJCXX", "UPC", or "GJC".
+# We try a few techniques and use that to set a single cache variable.
+#
+# We don't AC_REQUIRE the corresponding AC_PROG_CC since the latter was
+# modified to invoke _AM_DEPENDENCIES(CC); we would have a circular
+# dependency, and given that the user is not expected to run this macro,
+# just rely on AC_PROG_CC.
+AC_DEFUN([_AM_DEPENDENCIES],
+[AC_REQUIRE([AM_SET_DEPDIR])dnl
+AC_REQUIRE([AM_OUTPUT_DEPENDENCY_COMMANDS])dnl
+AC_REQUIRE([AM_MAKE_INCLUDE])dnl
+AC_REQUIRE([AM_DEP_TRACK])dnl
+
+m4_if([$1], [CC],   [depcc="$CC"   am_compiler_list=],
+      [$1], [CXX],  [depcc="$CXX"  am_compiler_list=],
+      [$1], [OBJC], [depcc="$OBJC" am_compiler_list='gcc3 gcc'],
+      [$1], [OBJCXX], [depcc="$OBJCXX" am_compiler_list='gcc3 gcc'],
+      [$1], [UPC],  [depcc="$UPC"  am_compiler_list=],
+      [$1], [GCJ],  [depcc="$GCJ"  am_compiler_list='gcc3 gcc'],
+                    [depcc="$$1"   am_compiler_list=])
+
+AC_CACHE_CHECK([dependency style of $depcc],
+               [am_cv_$1_dependencies_compiler_type],
+[if test -z "$AMDEP_TRUE" && test -f "$am_depcomp"; then
+  # We make a subdir and do the tests there.  Otherwise we can end up
+  # making bogus files that we don't know about and never remove.  For
+  # instance it was reported that on HP-UX the gcc test will end up
+  # making a dummy file named 'D' -- because '-MD' means "put the output
+  # in D".
+  rm -rf conftest.dir
+  mkdir conftest.dir
+  # Copy depcomp to subdir because otherwise we won't find it if we're
+  # using a relative directory.
+  cp "$am_depcomp" conftest.dir
+  cd conftest.dir
+  # We will build objects and dependencies in a subdirectory because
+  # it helps to detect inapplicable dependency modes.  For instance
+  # both Tru64's cc and ICC support -MD to output dependencies as a
+  # side effect of compilation, but ICC will put the dependencies in
+  # the current directory while Tru64 will put them in the object
+  # directory.
+  mkdir sub
+
+  am_cv_$1_dependencies_compiler_type=none
+  if test "$am_compiler_list" = ""; then
+     am_compiler_list=`sed -n ['s/^#*\([a-zA-Z0-9]*\))$/\1/p'] < ./depcomp`
+  fi
+  am__universal=false
+  m4_case([$1], [CC],
+    [case " $depcc " in #(
+     *\ -arch\ *\ -arch\ *) am__universal=true ;;
+     esac],
+    [CXX],
+    [case " $depcc " in #(
+     *\ -arch\ *\ -arch\ *) am__universal=true ;;
+     esac])
+
+  for depmode in $am_compiler_list; do
+    # Setup a source with many dependencies, because some compilers
+    # like to wrap large dependency lists on column 80 (with \), and
+    # we should not choose a depcomp mode which is confused by this.
+    #
+    # We need to recreate these files for each test, as the compiler may
+    # overwrite some of them when testing with obscure command lines.
+    # This happens at least with the AIX C compiler.
+    : > sub/conftest.c
+    for i in 1 2 3 4 5 6; do
+      echo '#include "conftst'$i'.h"' >> sub/conftest.c
+      # Using ": > sub/conftst$i.h" creates only sub/conftst1.h with
+      # Solaris 10 /bin/sh.
+      echo '/* dummy */' > sub/conftst$i.h
+    done
+    echo "${am__include} ${am__quote}sub/conftest.Po${am__quote}" > confmf
+
+    # We check with '-c' and '-o' for the sake of the "dashmstdout"
+    # mode.  It turns out that the SunPro C++ compiler does not properly
+    # handle '-M -o', and we need to detect this.  Also, some Intel
+    # versions had trouble with output in subdirs.
+    am__obj=sub/conftest.${OBJEXT-o}
+    am__minus_obj="-o $am__obj"
+    case $depmode in
+    gcc)
+      # This depmode causes a compiler race in universal mode.
+      test "$am__universal" = false || continue
+      ;;
+    nosideeffect)
+      # After this tag, mechanisms are not by side-effect, so they'll
+      # only be used when explicitly requested.
+      if test "x$enable_dependency_tracking" = xyes; then
+	continue
+      else
+	break
+      fi
+      ;;
+    msvc7 | msvc7msys | msvisualcpp | msvcmsys)
+      # This compiler won't grok '-c -o', but also, the minuso test has
+      # not run yet.  These depmodes are late enough in the game, and
+      # so weak that their functioning should not be impacted.
+      am__obj=conftest.${OBJEXT-o}
+      am__minus_obj=
+      ;;
+    none) break ;;
+    esac
+    if depmode=$depmode \
+       source=sub/conftest.c object=$am__obj \
+       depfile=sub/conftest.Po tmpdepfile=sub/conftest.TPo \
+       $SHELL ./depcomp $depcc -c $am__minus_obj sub/conftest.c \
+         >/dev/null 2>conftest.err &&
+       grep sub/conftst1.h sub/conftest.Po > /dev/null 2>&1 &&
+       grep sub/conftst6.h sub/conftest.Po > /dev/null 2>&1 &&
+       grep $am__obj sub/conftest.Po > /dev/null 2>&1 &&
+       ${MAKE-make} -s -f confmf > /dev/null 2>&1; then
+      # icc doesn't choke on unknown options, it will just issue warnings
+      # or remarks (even with -Werror).  So we grep stderr for any message
+      # that says an option was ignored or not supported.
+      # When given -MP, icc 7.0 and 7.1 complain thusly:
+      #   icc: Command line warning: ignoring option '-M'; no argument required
+      # The diagnosis changed in icc 8.0:
+      #   icc: Command line remark: option '-MP' not supported
+      if (grep 'ignoring option' conftest.err ||
+          grep 'not supported' conftest.err) >/dev/null 2>&1; then :; else
+        am_cv_$1_dependencies_compiler_type=$depmode
+        break
+      fi
+    fi
+  done
+
+  cd ..
+  rm -rf conftest.dir
+else
+  am_cv_$1_dependencies_compiler_type=none
+fi
+])
+AC_SUBST([$1DEPMODE], [depmode=$am_cv_$1_dependencies_compiler_type])
+AM_CONDITIONAL([am__fastdep$1], [
+  test "x$enable_dependency_tracking" != xno \
+  && test "$am_cv_$1_dependencies_compiler_type" = gcc3])
+])
+
+
+# AM_SET_DEPDIR
+# -------------
+# Choose a directory name for dependency files.
+# This macro is AC_REQUIREd in _AM_DEPENDENCIES.
+AC_DEFUN([AM_SET_DEPDIR],
+[AC_REQUIRE([AM_SET_LEADING_DOT])dnl
+AC_SUBST([DEPDIR], ["${am__leading_dot}deps"])dnl
+])
+
+
+# AM_DEP_TRACK
+# ------------
+AC_DEFUN([AM_DEP_TRACK],
+[AC_ARG_ENABLE([dependency-tracking], [dnl
+AS_HELP_STRING(
+  [--enable-dependency-tracking],
+  [do not reject slow dependency extractors])
+AS_HELP_STRING(
+  [--disable-dependency-tracking],
+  [speeds up one-time build])])
+if test "x$enable_dependency_tracking" != xno; then
+  am_depcomp="$ac_aux_dir/depcomp"
+  AMDEPBACKSLASH='\'
+  am__nodep='_no'
+fi
+AM_CONDITIONAL([AMDEP], [test "x$enable_dependency_tracking" != xno])
+AC_SUBST([AMDEPBACKSLASH])dnl
+_AM_SUBST_NOTMAKE([AMDEPBACKSLASH])dnl
+AC_SUBST([am__nodep])dnl
+_AM_SUBST_NOTMAKE([am__nodep])dnl
+])
+
+# Generate code to set up dependency tracking.              -*- Autoconf -*-
+
+# Copyright (C) 1999-2013 Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+
+# _AM_OUTPUT_DEPENDENCY_COMMANDS
+# ------------------------------
+AC_DEFUN([_AM_OUTPUT_DEPENDENCY_COMMANDS],
+[{
+  # Older Autoconf quotes --file arguments for eval, but not when files
+  # are listed without --file.  Let's play safe and only enable the eval
+  # if we detect the quoting.
+  case $CONFIG_FILES in
+  *\'*) eval set x "$CONFIG_FILES" ;;
+  *)   set x $CONFIG_FILES ;;
+  esac
+  shift
+  for mf
+  do
+    # Strip MF so we end up with the name of the file.
+    mf=`echo "$mf" | sed -e 's/:.*$//'`
+    # Check whether this is an Automake generated Makefile or not.
+    # We used to match only the files named 'Makefile.in', but
+    # some people rename them; so instead we look at the file content.
+    # Grep'ing the first line is not enough: some people post-process
+    # each Makefile.in and add a new line on top of each file to say so.
+    # Grep'ing the whole file is not good either: AIX grep has a line
+    # limit of 2048, but all sed's we know have understand at least 4000.
+    if sed -n 's,^#.*generated by automake.*,X,p' "$mf" | grep X >/dev/null 2>&1; then
+      dirpart=`AS_DIRNAME("$mf")`
+    else
+      continue
+    fi
+    # Extract the definition of DEPDIR, am__include, and am__quote
+    # from the Makefile without running 'make'.
+    DEPDIR=`sed -n 's/^DEPDIR = //p' < "$mf"`
+    test -z "$DEPDIR" && continue
+    am__include=`sed -n 's/^am__include = //p' < "$mf"`
+    test -z "$am__include" && continue
+    am__quote=`sed -n 's/^am__quote = //p' < "$mf"`
+    # Find all dependency output files, they are included files with
+    # $(DEPDIR) in their names.  We invoke sed twice because it is the
+    # simplest approach to changing $(DEPDIR) to its actual value in the
+    # expansion.
+    for file in `sed -n "
+      s/^$am__include $am__quote\(.*(DEPDIR).*\)$am__quote"'$/\1/p' <"$mf" | \
+	 sed -e 's/\$(DEPDIR)/'"$DEPDIR"'/g'`; do
+      # Make sure the directory exists.
+      test -f "$dirpart/$file" && continue
+      fdir=`AS_DIRNAME(["$file"])`
+      AS_MKDIR_P([$dirpart/$fdir])
+      # echo "creating $dirpart/$file"
+      echo '# dummy' > "$dirpart/$file"
+    done
+  done
+}
+])# _AM_OUTPUT_DEPENDENCY_COMMANDS
+
+
+# AM_OUTPUT_DEPENDENCY_COMMANDS
+# -----------------------------
+# This macro should only be invoked once -- use via AC_REQUIRE.
+#
+# This code is only required when automatic dependency tracking
+# is enabled.  FIXME.  This creates each '.P' file that we will
+# need in order to bootstrap the dependency handling code.
+AC_DEFUN([AM_OUTPUT_DEPENDENCY_COMMANDS],
+[AC_CONFIG_COMMANDS([depfiles],
+     [test x"$AMDEP_TRUE" != x"" || _AM_OUTPUT_DEPENDENCY_COMMANDS],
+     [AMDEP_TRUE="$AMDEP_TRUE" ac_aux_dir="$ac_aux_dir"])
+])
+
+# Do all the work for Automake.                             -*- Autoconf -*-
+
+# Copyright (C) 1996-2013 Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This macro actually does too much.  Some checks are only needed if
+# your package does certain things.  But this isn't really a big deal.
+
+dnl Redefine AC_PROG_CC to automatically invoke _AM_PROG_CC_C_O.
+m4_define([AC_PROG_CC],
+m4_defn([AC_PROG_CC])
+[_AM_PROG_CC_C_O
+])
+
+# AM_INIT_AUTOMAKE(PACKAGE, VERSION, [NO-DEFINE])
+# AM_INIT_AUTOMAKE([OPTIONS])
+# -----------------------------------------------
+# The call with PACKAGE and VERSION arguments is the old style
+# call (pre autoconf-2.50), which is being phased out.  PACKAGE
+# and VERSION should now be passed to AC_INIT and removed from
+# the call to AM_INIT_AUTOMAKE.
+# We support both call styles for the transition.  After
+# the next Automake release, Autoconf can make the AC_INIT
+# arguments mandatory, and then we can depend on a new Autoconf
+# release and drop the old call support.
+AC_DEFUN([AM_INIT_AUTOMAKE],
+[AC_PREREQ([2.65])dnl
+dnl Autoconf wants to disallow AM_ names.  We explicitly allow
+dnl the ones we care about.
+m4_pattern_allow([^AM_[A-Z]+FLAGS$])dnl
+AC_REQUIRE([AM_SET_CURRENT_AUTOMAKE_VERSION])dnl
+AC_REQUIRE([AC_PROG_INSTALL])dnl
+if test "`cd $srcdir && pwd`" != "`pwd`"; then
+  # Use -I$(srcdir) only when $(srcdir) != ., so that make's output
+  # is not polluted with repeated "-I."
+  AC_SUBST([am__isrc], [' -I$(srcdir)'])_AM_SUBST_NOTMAKE([am__isrc])dnl
+  # test to see if srcdir already configured
+  if test -f $srcdir/config.status; then
+    AC_MSG_ERROR([source directory already configured; run "make distclean" there first])
+  fi
+fi
+
+# test whether we have cygpath
+if test -z "$CYGPATH_W"; then
+  if (cygpath --version) >/dev/null 2>/dev/null; then
+    CYGPATH_W='cygpath -w'
+  else
+    CYGPATH_W=echo
+  fi
+fi
+AC_SUBST([CYGPATH_W])
+
+# Define the identity of the package.
+dnl Distinguish between old-style and new-style calls.
+m4_ifval([$2],
+[AC_DIAGNOSE([obsolete],
+             [$0: two- and three-arguments forms are deprecated.])
+m4_ifval([$3], [_AM_SET_OPTION([no-define])])dnl
+ AC_SUBST([PACKAGE], [$1])dnl
+ AC_SUBST([VERSION], [$2])],
+[_AM_SET_OPTIONS([$1])dnl
+dnl Diagnose old-style AC_INIT with new-style AM_AUTOMAKE_INIT.
+m4_if(
+  m4_ifdef([AC_PACKAGE_NAME], [ok]):m4_ifdef([AC_PACKAGE_VERSION], [ok]),
+  [ok:ok],,
+  [m4_fatal([AC_INIT should be called with package and version arguments])])dnl
+ AC_SUBST([PACKAGE], ['AC_PACKAGE_TARNAME'])dnl
+ AC_SUBST([VERSION], ['AC_PACKAGE_VERSION'])])dnl
+
+_AM_IF_OPTION([no-define],,
+[AC_DEFINE_UNQUOTED([PACKAGE], ["$PACKAGE"], [Name of package])
+ AC_DEFINE_UNQUOTED([VERSION], ["$VERSION"], [Version number of package])])dnl
+
+# Some tools Automake needs.
+AC_REQUIRE([AM_SANITY_CHECK])dnl
+AC_REQUIRE([AC_ARG_PROGRAM])dnl
+AM_MISSING_PROG([ACLOCAL], [aclocal-${am__api_version}])
+AM_MISSING_PROG([AUTOCONF], [autoconf])
+AM_MISSING_PROG([AUTOMAKE], [automake-${am__api_version}])
+AM_MISSING_PROG([AUTOHEADER], [autoheader])
+AM_MISSING_PROG([MAKEINFO], [makeinfo])
+AC_REQUIRE([AM_PROG_INSTALL_SH])dnl
+AC_REQUIRE([AM_PROG_INSTALL_STRIP])dnl
+AC_REQUIRE([AC_PROG_MKDIR_P])dnl
+# For better backward compatibility.  To be removed once Automake 1.9.x
+# dies out for good.  For more background, see:
+# <http://lists.gnu.org/archive/html/automake/2012-07/msg00001.html>
+# <http://lists.gnu.org/archive/html/automake/2012-07/msg00014.html>
+AC_SUBST([mkdir_p], ['$(MKDIR_P)'])
+# We need awk for the "check" target.  The system "awk" is bad on
+# some platforms.
+AC_REQUIRE([AC_PROG_AWK])dnl
+AC_REQUIRE([AC_PROG_MAKE_SET])dnl
+AC_REQUIRE([AM_SET_LEADING_DOT])dnl
+_AM_IF_OPTION([tar-ustar], [_AM_PROG_TAR([ustar])],
+	      [_AM_IF_OPTION([tar-pax], [_AM_PROG_TAR([pax])],
+			     [_AM_PROG_TAR([v7])])])
+_AM_IF_OPTION([no-dependencies],,
+[AC_PROVIDE_IFELSE([AC_PROG_CC],
+		  [_AM_DEPENDENCIES([CC])],
+		  [m4_define([AC_PROG_CC],
+			     m4_defn([AC_PROG_CC])[_AM_DEPENDENCIES([CC])])])dnl
+AC_PROVIDE_IFELSE([AC_PROG_CXX],
+		  [_AM_DEPENDENCIES([CXX])],
+		  [m4_define([AC_PROG_CXX],
+			     m4_defn([AC_PROG_CXX])[_AM_DEPENDENCIES([CXX])])])dnl
+AC_PROVIDE_IFELSE([AC_PROG_OBJC],
+		  [_AM_DEPENDENCIES([OBJC])],
+		  [m4_define([AC_PROG_OBJC],
+			     m4_defn([AC_PROG_OBJC])[_AM_DEPENDENCIES([OBJC])])])dnl
+AC_PROVIDE_IFELSE([AC_PROG_OBJCXX],
+		  [_AM_DEPENDENCIES([OBJCXX])],
+		  [m4_define([AC_PROG_OBJCXX],
+			     m4_defn([AC_PROG_OBJCXX])[_AM_DEPENDENCIES([OBJCXX])])])dnl
+])
+AC_REQUIRE([AM_SILENT_RULES])dnl
+dnl The testsuite driver may need to know about EXEEXT, so add the
+dnl 'am__EXEEXT' conditional if _AM_COMPILER_EXEEXT was seen.  This
+dnl macro is hooked onto _AC_COMPILER_EXEEXT early, see below.
+AC_CONFIG_COMMANDS_PRE(dnl
+[m4_provide_if([_AM_COMPILER_EXEEXT],
+  [AM_CONDITIONAL([am__EXEEXT], [test -n "$EXEEXT"])])])dnl
+
+# POSIX will say in a future version that running "rm -f" with no argument
+# is OK; and we want to be able to make that assumption in our Makefile
+# recipes.  So use an aggressive probe to check that the usage we want is
+# actually supported "in the wild" to an acceptable degree.
+# See automake bug#10828.
+# To make any issue more visible, cause the running configure to be aborted
+# by default if the 'rm' program in use doesn't match our expectations; the
+# user can still override this though.
+if rm -f && rm -fr && rm -rf; then : OK; else
+  cat >&2 <<'END'
+Oops!
+
+Your 'rm' program seems unable to run without file operands specified
+on the command line, even when the '-f' option is present.  This is contrary
+to the behaviour of most rm programs out there, and not conforming with
+the upcoming POSIX standard: <http://austingroupbugs.net/view.php?id=542>
+
+Please tell bug-automake@gnu.org about your system, including the value
+of your $PATH and any error possibly output before this message.  This
+can help us improve future automake versions.
+
+END
+  if test x"$ACCEPT_INFERIOR_RM_PROGRAM" = x"yes"; then
+    echo 'Configuration will proceed anyway, since you have set the' >&2
+    echo 'ACCEPT_INFERIOR_RM_PROGRAM variable to "yes"' >&2
+    echo >&2
+  else
+    cat >&2 <<'END'
+Aborting the configuration process, to ensure you take notice of the issue.
+
+You can download and install GNU coreutils to get an 'rm' implementation
+that behaves properly: <http://www.gnu.org/software/coreutils/>.
+
+If you want to complete the configuration process using your problematic
+'rm' anyway, export the environment variable ACCEPT_INFERIOR_RM_PROGRAM
+to "yes", and re-run configure.
+
+END
+    AC_MSG_ERROR([Your 'rm' program is bad, sorry.])
+  fi
+fi])
+
+dnl Hook into '_AC_COMPILER_EXEEXT' early to learn its expansion.  Do not
+dnl add the conditional right here, as _AC_COMPILER_EXEEXT may be further
+dnl mangled by Autoconf and run in a shell conditional statement.
+m4_define([_AC_COMPILER_EXEEXT],
+m4_defn([_AC_COMPILER_EXEEXT])[m4_provide([_AM_COMPILER_EXEEXT])])
+
+# When config.status generates a header, we must update the stamp-h file.
+# This file resides in the same directory as the config header
+# that is generated.  The stamp files are numbered to have different names.
+
+# Autoconf calls _AC_AM_CONFIG_HEADER_HOOK (when defined) in the
+# loop where config.status creates the headers, so we can generate
+# our stamp files there.
+AC_DEFUN([_AC_AM_CONFIG_HEADER_HOOK],
+[# Compute $1's index in $config_headers.
+_am_arg=$1
+_am_stamp_count=1
+for _am_header in $config_headers :; do
+  case $_am_header in
+    $_am_arg | $_am_arg:* )
+      break ;;
+    * )
+      _am_stamp_count=`expr $_am_stamp_count + 1` ;;
+  esac
+done
+echo "timestamp for $_am_arg" >`AS_DIRNAME(["$_am_arg"])`/stamp-h[]$_am_stamp_count])
+
+# Copyright (C) 2001-2013 Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# AM_PROG_INSTALL_SH
+# ------------------
+# Define $install_sh.
+AC_DEFUN([AM_PROG_INSTALL_SH],
+[AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl
+if test x"${install_sh}" != xset; then
+  case $am_aux_dir in
+  *\ * | *\	*)
+    install_sh="\${SHELL} '$am_aux_dir/install-sh'" ;;
+  *)
+    install_sh="\${SHELL} $am_aux_dir/install-sh"
+  esac
+fi
+AC_SUBST([install_sh])])
+
+# Copyright (C) 2003-2013 Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# Check whether the underlying file-system supports filenames
+# with a leading dot.  For instance MS-DOS doesn't.
+AC_DEFUN([AM_SET_LEADING_DOT],
+[rm -rf .tst 2>/dev/null
+mkdir .tst 2>/dev/null
+if test -d .tst; then
+  am__leading_dot=.
+else
+  am__leading_dot=_
+fi
+rmdir .tst 2>/dev/null
+AC_SUBST([am__leading_dot])])
+
+# Add --enable-maintainer-mode option to configure.         -*- Autoconf -*-
+# From Jim Meyering
+
+# Copyright (C) 1996-2013 Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# AM_MAINTAINER_MODE([DEFAULT-MODE])
+# ----------------------------------
+# Control maintainer-specific portions of Makefiles.
+# Default is to disable them, unless 'enable' is passed literally.
+# For symmetry, 'disable' may be passed as well.  Anyway, the user
+# can override the default with the --enable/--disable switch.
+AC_DEFUN([AM_MAINTAINER_MODE],
+[m4_case(m4_default([$1], [disable]),
+       [enable], [m4_define([am_maintainer_other], [disable])],
+       [disable], [m4_define([am_maintainer_other], [enable])],
+       [m4_define([am_maintainer_other], [enable])
+        m4_warn([syntax], [unexpected argument to AM@&t@_MAINTAINER_MODE: $1])])
+AC_MSG_CHECKING([whether to enable maintainer-specific portions of Makefiles])
+  dnl maintainer-mode's default is 'disable' unless 'enable' is passed
+  AC_ARG_ENABLE([maintainer-mode],
+    [AS_HELP_STRING([--]am_maintainer_other[-maintainer-mode],
+      am_maintainer_other[ make rules and dependencies not useful
+      (and sometimes confusing) to the casual installer])],
+    [USE_MAINTAINER_MODE=$enableval],
+    [USE_MAINTAINER_MODE=]m4_if(am_maintainer_other, [enable], [no], [yes]))
+  AC_MSG_RESULT([$USE_MAINTAINER_MODE])
+  AM_CONDITIONAL([MAINTAINER_MODE], [test $USE_MAINTAINER_MODE = yes])
+  MAINT=$MAINTAINER_MODE_TRUE
+  AC_SUBST([MAINT])dnl
+]
+)
+
+# Check to see how 'make' treats includes.	            -*- Autoconf -*-
+
+# Copyright (C) 2001-2013 Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# AM_MAKE_INCLUDE()
+# -----------------
+# Check to see how make treats includes.
+AC_DEFUN([AM_MAKE_INCLUDE],
+[am_make=${MAKE-make}
+cat > confinc << 'END'
+am__doit:
+	@echo this is the am__doit target
+.PHONY: am__doit
+END
+# If we don't find an include directive, just comment out the code.
+AC_MSG_CHECKING([for style of include used by $am_make])
+am__include="#"
+am__quote=
+_am_result=none
+# First try GNU make style include.
+echo "include confinc" > confmf
+# Ignore all kinds of additional output from 'make'.
+case `$am_make -s -f confmf 2> /dev/null` in #(
+*the\ am__doit\ target*)
+  am__include=include
+  am__quote=
+  _am_result=GNU
+  ;;
+esac
+# Now try BSD make style include.
+if test "$am__include" = "#"; then
+   echo '.include "confinc"' > confmf
+   case `$am_make -s -f confmf 2> /dev/null` in #(
+   *the\ am__doit\ target*)
+     am__include=.include
+     am__quote="\""
+     _am_result=BSD
+     ;;
+   esac
+fi
+AC_SUBST([am__include])
+AC_SUBST([am__quote])
+AC_MSG_RESULT([$_am_result])
+rm -f confinc confmf
+])
+
+# Fake the existence of programs that GNU maintainers use.  -*- Autoconf -*-
+
+# Copyright (C) 1997-2013 Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# AM_MISSING_PROG(NAME, PROGRAM)
+# ------------------------------
+AC_DEFUN([AM_MISSING_PROG],
+[AC_REQUIRE([AM_MISSING_HAS_RUN])
+$1=${$1-"${am_missing_run}$2"}
+AC_SUBST($1)])
+
+# AM_MISSING_HAS_RUN
+# ------------------
+# Define MISSING if not defined so far and test if it is modern enough.
+# If it is, set am_missing_run to use it, otherwise, to nothing.
+AC_DEFUN([AM_MISSING_HAS_RUN],
+[AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl
+AC_REQUIRE_AUX_FILE([missing])dnl
+if test x"${MISSING+set}" != xset; then
+  case $am_aux_dir in
+  *\ * | *\	*)
+    MISSING="\${SHELL} \"$am_aux_dir/missing\"" ;;
+  *)
+    MISSING="\${SHELL} $am_aux_dir/missing" ;;
+  esac
+fi
+# Use eval to expand $SHELL
+if eval "$MISSING --is-lightweight"; then
+  am_missing_run="$MISSING "
+else
+  am_missing_run=
+  AC_MSG_WARN(['missing' script is too old or missing])
+fi
+])
+
+# Helper functions for option handling.                     -*- Autoconf -*-
+
+# Copyright (C) 2001-2013 Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# _AM_MANGLE_OPTION(NAME)
+# -----------------------
+AC_DEFUN([_AM_MANGLE_OPTION],
+[[_AM_OPTION_]m4_bpatsubst($1, [[^a-zA-Z0-9_]], [_])])
+
+# _AM_SET_OPTION(NAME)
+# --------------------
+# Set option NAME.  Presently that only means defining a flag for this option.
+AC_DEFUN([_AM_SET_OPTION],
+[m4_define(_AM_MANGLE_OPTION([$1]), [1])])
+
+# _AM_SET_OPTIONS(OPTIONS)
+# ------------------------
+# OPTIONS is a space-separated list of Automake options.
+AC_DEFUN([_AM_SET_OPTIONS],
+[m4_foreach_w([_AM_Option], [$1], [_AM_SET_OPTION(_AM_Option)])])
+
+# _AM_IF_OPTION(OPTION, IF-SET, [IF-NOT-SET])
+# -------------------------------------------
+# Execute IF-SET if OPTION is set, IF-NOT-SET otherwise.
+AC_DEFUN([_AM_IF_OPTION],
+[m4_ifset(_AM_MANGLE_OPTION([$1]), [$2], [$3])])
+
+# Copyright (C) 1999-2013 Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# _AM_PROG_CC_C_O
+# ---------------
+# Like AC_PROG_CC_C_O, but changed for automake.  We rewrite AC_PROG_CC
+# to automatically call this.
+AC_DEFUN([_AM_PROG_CC_C_O],
+[AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl
+AC_REQUIRE_AUX_FILE([compile])dnl
+AC_LANG_PUSH([C])dnl
+AC_CACHE_CHECK(
+  [whether $CC understands -c and -o together],
+  [am_cv_prog_cc_c_o],
+  [AC_LANG_CONFTEST([AC_LANG_PROGRAM([])])
+  # Make sure it works both with $CC and with simple cc.
+  # Following AC_PROG_CC_C_O, we do the test twice because some
+  # compilers refuse to overwrite an existing .o file with -o,
+  # though they will create one.
+  am_cv_prog_cc_c_o=yes
+  for am_i in 1 2; do
+    if AM_RUN_LOG([$CC -c conftest.$ac_ext -o conftest2.$ac_objext]) \
+         && test -f conftest2.$ac_objext; then
+      : OK
+    else
+      am_cv_prog_cc_c_o=no
+      break
+    fi
+  done
+  rm -f core conftest*
+  unset am_i])
+if test "$am_cv_prog_cc_c_o" != yes; then
+   # Losing compiler, so override with the script.
+   # FIXME: It is wrong to rewrite CC.
+   # But if we don't then we get into trouble of one sort or another.
+   # A longer-term fix would be to have automake use am__CC in this case,
+   # and then we could set am__CC="\$(top_srcdir)/compile \$(CC)"
+   CC="$am_aux_dir/compile $CC"
+fi
+AC_LANG_POP([C])])
+
+# For backward compatibility.
+AC_DEFUN_ONCE([AM_PROG_CC_C_O], [AC_REQUIRE([AC_PROG_CC])])
+
+# Copyright (C) 2001-2013 Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# AM_RUN_LOG(COMMAND)
+# -------------------
+# Run COMMAND, save the exit status in ac_status, and log it.
+# (This has been adapted from Autoconf's _AC_RUN_LOG macro.)
+AC_DEFUN([AM_RUN_LOG],
+[{ echo "$as_me:$LINENO: $1" >&AS_MESSAGE_LOG_FD
+   ($1) >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD
+   ac_status=$?
+   echo "$as_me:$LINENO: \$? = $ac_status" >&AS_MESSAGE_LOG_FD
+   (exit $ac_status); }])
+
+# Check to make sure that the build environment is sane.    -*- Autoconf -*-
+
+# Copyright (C) 1996-2013 Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# AM_SANITY_CHECK
+# ---------------
+AC_DEFUN([AM_SANITY_CHECK],
+[AC_MSG_CHECKING([whether build environment is sane])
+# Reject unsafe characters in $srcdir or the absolute working directory
+# name.  Accept space and tab only in the latter.
+am_lf='
+'
+case `pwd` in
+  *[[\\\"\#\$\&\'\`$am_lf]]*)
+    AC_MSG_ERROR([unsafe absolute working directory name]);;
+esac
+case $srcdir in
+  *[[\\\"\#\$\&\'\`$am_lf\ \	]]*)
+    AC_MSG_ERROR([unsafe srcdir value: '$srcdir']);;
+esac
+
+# Do 'set' in a subshell so we don't clobber the current shell's
+# arguments.  Must try -L first in case configure is actually a
+# symlink; some systems play weird games with the mod time of symlinks
+# (eg FreeBSD returns the mod time of the symlink's containing
+# directory).
+if (
+   am_has_slept=no
+   for am_try in 1 2; do
+     echo "timestamp, slept: $am_has_slept" > conftest.file
+     set X `ls -Lt "$srcdir/configure" conftest.file 2> /dev/null`
+     if test "$[*]" = "X"; then
+	# -L didn't work.
+	set X `ls -t "$srcdir/configure" conftest.file`
+     fi
+     if test "$[*]" != "X $srcdir/configure conftest.file" \
+	&& test "$[*]" != "X conftest.file $srcdir/configure"; then
+
+	# If neither matched, then we have a broken ls.  This can happen
+	# if, for instance, CONFIG_SHELL is bash and it inherits a
+	# broken ls alias from the environment.  This has actually
+	# happened.  Such a system could not be considered "sane".
+	AC_MSG_ERROR([ls -t appears to fail.  Make sure there is not a broken
+  alias in your environment])
+     fi
+     if test "$[2]" = conftest.file || test $am_try -eq 2; then
+       break
+     fi
+     # Just in case.
+     sleep 1
+     am_has_slept=yes
+   done
+   test "$[2]" = conftest.file
+   )
+then
+   # Ok.
+   :
+else
+   AC_MSG_ERROR([newly created file is older than distributed files!
+Check your system clock])
+fi
+AC_MSG_RESULT([yes])
+# If we didn't sleep, we still need to ensure time stamps of config.status and
+# generated files are strictly newer.
+am_sleep_pid=
+if grep 'slept: no' conftest.file >/dev/null 2>&1; then
+  ( sleep 1 ) &
+  am_sleep_pid=$!
+fi
+AC_CONFIG_COMMANDS_PRE(
+  [AC_MSG_CHECKING([that generated files are newer than configure])
+   if test -n "$am_sleep_pid"; then
+     # Hide warnings about reused PIDs.
+     wait $am_sleep_pid 2>/dev/null
+   fi
+   AC_MSG_RESULT([done])])
+rm -f conftest.file
+])
+
+# Copyright (C) 2009-2013 Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# AM_SILENT_RULES([DEFAULT])
+# --------------------------
+# Enable less verbose build rules; with the default set to DEFAULT
+# ("yes" being less verbose, "no" or empty being verbose).
+AC_DEFUN([AM_SILENT_RULES],
+[AC_ARG_ENABLE([silent-rules], [dnl
+AS_HELP_STRING(
+  [--enable-silent-rules],
+  [less verbose build output (undo: "make V=1")])
+AS_HELP_STRING(
+  [--disable-silent-rules],
+  [verbose build output (undo: "make V=0")])dnl
+])
+case $enable_silent_rules in @%:@ (((
+  yes) AM_DEFAULT_VERBOSITY=0;;
+   no) AM_DEFAULT_VERBOSITY=1;;
+    *) AM_DEFAULT_VERBOSITY=m4_if([$1], [yes], [0], [1]);;
+esac
+dnl
+dnl A few 'make' implementations (e.g., NonStop OS and NextStep)
+dnl do not support nested variable expansions.
+dnl See automake bug#9928 and bug#10237.
+am_make=${MAKE-make}
+AC_CACHE_CHECK([whether $am_make supports nested variables],
+   [am_cv_make_support_nested_variables],
+   [if AS_ECHO([['TRUE=$(BAR$(V))
+BAR0=false
+BAR1=true
+V=1
+am__doit:
+	@$(TRUE)
+.PHONY: am__doit']]) | $am_make -f - >/dev/null 2>&1; then
+  am_cv_make_support_nested_variables=yes
+else
+  am_cv_make_support_nested_variables=no
+fi])
+if test $am_cv_make_support_nested_variables = yes; then
+  dnl Using '$V' instead of '$(V)' breaks IRIX make.
+  AM_V='$(V)'
+  AM_DEFAULT_V='$(AM_DEFAULT_VERBOSITY)'
+else
+  AM_V=$AM_DEFAULT_VERBOSITY
+  AM_DEFAULT_V=$AM_DEFAULT_VERBOSITY
+fi
+AC_SUBST([AM_V])dnl
+AM_SUBST_NOTMAKE([AM_V])dnl
+AC_SUBST([AM_DEFAULT_V])dnl
+AM_SUBST_NOTMAKE([AM_DEFAULT_V])dnl
+AC_SUBST([AM_DEFAULT_VERBOSITY])dnl
+AM_BACKSLASH='\'
+AC_SUBST([AM_BACKSLASH])dnl
+_AM_SUBST_NOTMAKE([AM_BACKSLASH])dnl
+])
+
+# Copyright (C) 2001-2013 Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# AM_PROG_INSTALL_STRIP
+# ---------------------
+# One issue with vendor 'install' (even GNU) is that you can't
+# specify the program used to strip binaries.  This is especially
+# annoying in cross-compiling environments, where the build's strip
+# is unlikely to handle the host's binaries.
+# Fortunately install-sh will honor a STRIPPROG variable, so we
+# always use install-sh in "make install-strip", and initialize
+# STRIPPROG with the value of the STRIP variable (set by the user).
+AC_DEFUN([AM_PROG_INSTALL_STRIP],
+[AC_REQUIRE([AM_PROG_INSTALL_SH])dnl
+# Installed binaries are usually stripped using 'strip' when the user
+# run "make install-strip".  However 'strip' might not be the right
+# tool to use in cross-compilation environments, therefore Automake
+# will honor the 'STRIP' environment variable to overrule this program.
+dnl Don't test for $cross_compiling = yes, because it might be 'maybe'.
+if test "$cross_compiling" != no; then
+  AC_CHECK_TOOL([STRIP], [strip], :)
+fi
+INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s"
+AC_SUBST([INSTALL_STRIP_PROGRAM])])
+
+# Copyright (C) 2006-2013 Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# _AM_SUBST_NOTMAKE(VARIABLE)
+# ---------------------------
+# Prevent Automake from outputting VARIABLE = @VARIABLE@ in Makefile.in.
+# This macro is traced by Automake.
+AC_DEFUN([_AM_SUBST_NOTMAKE])
+
+# AM_SUBST_NOTMAKE(VARIABLE)
+# --------------------------
+# Public sister of _AM_SUBST_NOTMAKE.
+AC_DEFUN([AM_SUBST_NOTMAKE], [_AM_SUBST_NOTMAKE($@)])
+
+# Check how to create a tarball.                            -*- Autoconf -*-
+
+# Copyright (C) 2004-2013 Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# _AM_PROG_TAR(FORMAT)
+# --------------------
+# Check how to create a tarball in format FORMAT.
+# FORMAT should be one of 'v7', 'ustar', or 'pax'.
+#
+# Substitute a variable $(am__tar) that is a command
+# writing to stdout a FORMAT-tarball containing the directory
+# $tardir.
+#     tardir=directory && $(am__tar) > result.tar
+#
+# Substitute a variable $(am__untar) that extract such
+# a tarball read from stdin.
+#     $(am__untar) < result.tar
+#
+AC_DEFUN([_AM_PROG_TAR],
+[# Always define AMTAR for backward compatibility.  Yes, it's still used
+# in the wild :-(  We should find a proper way to deprecate it ...
+AC_SUBST([AMTAR], ['$${TAR-tar}'])
+
+# We'll loop over all known methods to create a tar archive until one works.
+_am_tools='gnutar m4_if([$1], [ustar], [plaintar]) pax cpio none'
+
+m4_if([$1], [v7],
+  [am__tar='$${TAR-tar} chof - "$$tardir"' am__untar='$${TAR-tar} xf -'],
+
+  [m4_case([$1],
+    [ustar],
+     [# The POSIX 1988 'ustar' format is defined with fixed-size fields.
+      # There is notably a 21 bits limit for the UID and the GID.  In fact,
+      # the 'pax' utility can hang on bigger UID/GID (see automake bug#8343
+      # and bug#13588).
+      am_max_uid=2097151 # 2^21 - 1
+      am_max_gid=$am_max_uid
+      # The $UID and $GID variables are not portable, so we need to resort
+      # to the POSIX-mandated id(1) utility.  Errors in the 'id' calls
+      # below are definitely unexpected, so allow the users to see them
+      # (that is, avoid stderr redirection).
+      am_uid=`id -u || echo unknown`
+      am_gid=`id -g || echo unknown`
+      AC_MSG_CHECKING([whether UID '$am_uid' is supported by ustar format])
+      if test $am_uid -le $am_max_uid; then
+         AC_MSG_RESULT([yes])
+      else
+         AC_MSG_RESULT([no])
+         _am_tools=none
+      fi
+      AC_MSG_CHECKING([whether GID '$am_gid' is supported by ustar format])
+      if test $am_gid -le $am_max_gid; then
+         AC_MSG_RESULT([yes])
+      else
+        AC_MSG_RESULT([no])
+        _am_tools=none
+      fi],
+
+  [pax],
+    [],
+
+  [m4_fatal([Unknown tar format])])
+
+  AC_MSG_CHECKING([how to create a $1 tar archive])
+
+  # Go ahead even if we have the value already cached.  We do so because we
+  # need to set the values for the 'am__tar' and 'am__untar' variables.
+  _am_tools=${am_cv_prog_tar_$1-$_am_tools}
+
+  for _am_tool in $_am_tools; do
+    case $_am_tool in
+    gnutar)
+      for _am_tar in tar gnutar gtar; do
+        AM_RUN_LOG([$_am_tar --version]) && break
+      done
+      am__tar="$_am_tar --format=m4_if([$1], [pax], [posix], [$1]) -chf - "'"$$tardir"'
+      am__tar_="$_am_tar --format=m4_if([$1], [pax], [posix], [$1]) -chf - "'"$tardir"'
+      am__untar="$_am_tar -xf -"
+      ;;
+    plaintar)
+      # Must skip GNU tar: if it does not support --format= it doesn't create
+      # ustar tarball either.
+      (tar --version) >/dev/null 2>&1 && continue
+      am__tar='tar chf - "$$tardir"'
+      am__tar_='tar chf - "$tardir"'
+      am__untar='tar xf -'
+      ;;
+    pax)
+      am__tar='pax -L -x $1 -w "$$tardir"'
+      am__tar_='pax -L -x $1 -w "$tardir"'
+      am__untar='pax -r'
+      ;;
+    cpio)
+      am__tar='find "$$tardir" -print | cpio -o -H $1 -L'
+      am__tar_='find "$tardir" -print | cpio -o -H $1 -L'
+      am__untar='cpio -i -H $1 -d'
+      ;;
+    none)
+      am__tar=false
+      am__tar_=false
+      am__untar=false
+      ;;
+    esac
+
+    # If the value was cached, stop now.  We just wanted to have am__tar
+    # and am__untar set.
+    test -n "${am_cv_prog_tar_$1}" && break
+
+    # tar/untar a dummy directory, and stop if the command works.
+    rm -rf conftest.dir
+    mkdir conftest.dir
+    echo GrepMe > conftest.dir/file
+    AM_RUN_LOG([tardir=conftest.dir && eval $am__tar_ >conftest.tar])
+    rm -rf conftest.dir
+    if test -s conftest.tar; then
+      AM_RUN_LOG([$am__untar <conftest.tar])
+      AM_RUN_LOG([cat conftest.dir/file])
+      grep GrepMe conftest.dir/file >/dev/null 2>&1 && break
+    fi
+  done
+  rm -rf conftest.dir
+
+  AC_CACHE_VAL([am_cv_prog_tar_$1], [am_cv_prog_tar_$1=$_am_tool])
+  AC_MSG_RESULT([$am_cv_prog_tar_$1])])
+
+AC_SUBST([am__tar])
+AC_SUBST([am__untar])
+]) # _AM_PROG_TAR
+
+m4_include([acinclude.m4])
diff --git a/connman/bootstrap b/connman/bootstrap
new file mode 100755
index 0000000..fb2c692
--- /dev/null
+++ b/connman/bootstrap
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+cd "`dirname $0`"
+
+aclocal && \
+    autoheader && \
+        libtoolize --automake --copy --force && \
+	    automake --add-missing --copy && \
+		autoconf
diff --git a/connman/bootstrap-configure b/connman/bootstrap-configure
new file mode 100755
index 0000000..070c676
--- /dev/null
+++ b/connman/bootstrap-configure
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+if [ -f config.status ]; then
+	make maintainer-clean
+fi
+
+./bootstrap && \
+    ./configure --enable-maintainer-mode \
+		--enable-debug \
+		--prefix=/usr \
+		--mandir=/usr/share/man \
+		--localstatedir=/var \
+		--sysconfdir=/etc \
+		--disable-datafiles \
+		--enable-openconnect=builtin \
+		--enable-openvpn=builtin \
+		--enable-vpnc=builtin \
+		--enable-session-policy-local=builtin \
+		--enable-nmcompat \
+		--enable-polkit $*
diff --git a/connman/client/agent.c b/connman/client/agent.c
new file mode 100644
index 0000000..d020889
--- /dev/null
+++ b/connman/client/agent.c
@@ -0,0 +1,910 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2013  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 as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  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 <stdio.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <errno.h>
+#include <stdbool.h>
+#include <string.h>
+#include <ctype.h>
+
+#include <gdbus.h>
+
+#include "input.h"
+#include "dbus_helpers.h"
+#include "agent.h"
+
+#define AGENT_INTERFACE      "net.connman.Agent"
+#define VPN_AGENT_INTERFACE  "net.connman.vpn.Agent"
+
+static DBusConnection *agent_connection;
+
+struct agent_input_data {
+	const char *attribute;
+	bool requested;
+	char *prompt;
+	connmanctl_input_func_t func;
+};
+
+struct agent_data {
+	struct agent_input_data *input;
+	char *interface;
+	bool registered;
+	DBusMessage *message;
+	DBusMessage *reply;
+	DBusMessageIter iter;
+	DBusMessageIter dict;
+	GDBusMethodFunction pending_function;
+};
+
+static void request_input_ssid_return(char *input, void *user_data);
+static void request_input_passphrase_return(char *input, void *user_data);
+static void request_input_string_return(char *input, void *user_data);
+
+enum requestinput {
+	SSID                    = 0,
+	IDENTITY                = 1,
+	PASSPHRASE              = 2,
+	WPS                     = 3,
+	WISPR_USERNAME          = 4,
+	WISPR_PASSPHRASE        = 5,
+	REQUEST_INPUT_MAX       = 6,
+};
+
+static struct agent_input_data agent_input_handler[] = {
+	{ "Name", false, "Hidden SSID name? ", request_input_ssid_return },
+	{ "Identity", false, "EAP username? ", request_input_string_return },
+	{ "Passphrase", false, "Passphrase? ",
+	  request_input_passphrase_return },
+	{ "WPS", false, "WPS PIN (empty line for pushbutton)? " ,
+	  request_input_string_return },
+	{ "Username", false, "WISPr username? ", request_input_string_return },
+	{ "Password", false, "WISPr password? ", request_input_string_return },
+	{ },
+};
+
+static struct agent_data agent_request = {
+	agent_input_handler,
+	AGENT_INTERFACE,
+};
+
+static struct agent_input_data vpnagent_input_handler[] = {
+	{ "OpenConnect.Cookie", false, "OpenConnect Cookie? ",
+	  request_input_string_return },
+	{ "OpenConnect.ServerCert", false,
+	  "OpenConnect server certificate hash? ",
+	  request_input_string_return },
+	{ "OpenConnect.VPNHost", false, "OpenConnect VPN server? ",
+	  request_input_string_return },
+	{ "Username", false, "VPN username? ", request_input_string_return },
+	{ "Password", false, "VPN password? ", request_input_string_return },
+	{ },
+};
+
+static struct agent_data vpn_agent_request = {
+	vpnagent_input_handler,
+	VPN_AGENT_INTERFACE,
+};
+
+static int confirm_input(char *input)
+{
+	int i;
+
+	if (!input)
+		return -1;
+
+	for (i = 0; input[i] != '\0'; i++)
+		if (isspace(input[i]) == 0)
+			break;
+
+	if (strcasecmp(&input[i], "yes") == 0 ||
+			strcasecmp(&input[i], "y") == 0)
+		return 1;
+
+	if (strcasecmp(&input[i], "no") == 0 ||
+			strcasecmp(&input[i], "n") == 0)
+		return 0;
+
+	return -1;
+}
+
+static char *strip_path(char *path)
+{
+	char *name = strrchr(path, '/');
+	if (name)
+		name++;
+	else
+		name = path;
+
+	return name;
+}
+
+static char *agent_path(void)
+{
+	static char *path = NULL;
+
+	if (!path)
+		path = g_strdup_printf("/net/connman/connmanctl%d", getpid());
+
+	return path;
+}
+
+static void pending_message_remove(struct agent_data *request)
+{
+	if (request->message) {
+		dbus_message_unref(request->message);
+		request->message = NULL;
+	}
+
+	if (request->reply) {
+		dbus_message_unref(request->reply);
+		request->reply = NULL;
+	}
+}
+
+static void pending_command_complete(char *message)
+{
+	struct agent_data *next_request = NULL;
+	DBusMessage *pending_message;
+	GDBusMethodFunction pending_function;
+
+	__connmanctl_save_rl();
+
+	fprintf(stdout, "%s", message);
+
+	__connmanctl_redraw_rl();
+
+	if (__connmanctl_is_interactive() == true)
+		__connmanctl_command_mode();
+	else
+		__connmanctl_agent_mode("", NULL, NULL);
+
+	if (agent_request.message)
+		next_request = &agent_request;
+	else if (vpn_agent_request.message)
+		next_request = &vpn_agent_request;
+
+	if (!next_request)
+		return;
+
+	pending_message = next_request->message;
+	pending_function = next_request->pending_function;
+	next_request->pending_function = NULL;
+
+	pending_function(agent_connection, next_request->message,
+			next_request);
+
+	dbus_message_unref(pending_message);
+}
+
+static bool handle_message(DBusMessage *message, struct agent_data *request,
+		GDBusMethodFunction function)
+{
+	if (!agent_request.pending_function &&
+			!vpn_agent_request.pending_function)
+		return true;
+
+	request->message = dbus_message_ref(message);
+	request->pending_function = function;
+
+	return false;
+}
+
+static DBusMessage *agent_release(DBusConnection *connection,
+		DBusMessage *message, void *user_data)
+{
+	struct agent_data *request = user_data;
+
+	if (handle_message(message, request, agent_release) == false)
+		return NULL;
+
+	g_dbus_unregister_interface(connection, agent_path(),
+			request->interface);
+	request->registered = false;
+
+	pending_message_remove(request);
+
+	if (strcmp(request->interface, AGENT_INTERFACE) == 0)
+		pending_command_complete("Agent unregistered by ConnMan\n");
+	else
+		pending_command_complete("VPN Agent unregistered by ConnMan "
+				"VPNd\n");
+
+	if (__connmanctl_is_interactive() == false)
+		__connmanctl_quit();
+
+	return dbus_message_new_method_return(message);
+}
+
+static DBusMessage *agent_cancel(DBusConnection *connection,
+		DBusMessage *message, void *user_data)
+{
+	struct agent_data *request = user_data;
+
+	if (handle_message(message, request, agent_cancel) == false)
+		return NULL;
+
+	pending_message_remove(request);
+
+	if (strcmp(request->interface, AGENT_INTERFACE) == 0)
+		pending_command_complete("Agent request cancelled by "
+				"ConnMan\n");
+	else
+		pending_command_complete("VPN Agent request cancelled by "
+				"ConnMan VPNd\n");
+
+	return dbus_message_new_method_return(message);
+}
+
+static void request_browser_return(char *input, void *user_data)
+{
+	struct agent_data *request = user_data;
+
+	switch (confirm_input(input)) {
+	case 1:
+		g_dbus_send_reply(agent_connection, request->message,
+				DBUS_TYPE_INVALID);
+		break;
+	case 0:
+		g_dbus_send_error(agent_connection, request->message,
+				"net.connman.Agent.Error.Canceled", NULL);
+		break;
+	default:
+		return;
+	}
+
+	pending_message_remove(request);
+	pending_command_complete("");
+}
+
+static DBusMessage *agent_request_browser(DBusConnection *connection,
+		DBusMessage *message, void *user_data)
+{
+	struct agent_data *request = user_data;
+	DBusMessageIter iter;
+	char *service, *url;
+
+	if (handle_message(message, request, agent_request_browser) == false)
+		return NULL;
+
+	dbus_message_iter_init(message, &iter);
+
+	dbus_message_iter_get_basic(&iter, &service);
+	dbus_message_iter_next(&iter);
+	dbus_message_iter_get_basic(&iter, &url);
+
+	__connmanctl_save_rl();
+	fprintf(stdout, "Agent RequestBrowser %s\n", strip_path(service));
+	fprintf(stdout, "  %s\n", url);
+	__connmanctl_redraw_rl();
+
+	request->message = dbus_message_ref(message);
+	__connmanctl_agent_mode("Connected (yes/no)? ",
+			request_browser_return, request);
+
+	return NULL;
+}
+
+static void report_error_return(char *input, void *user_data)
+{
+	struct agent_data *request = user_data;
+
+	switch (confirm_input(input)) {
+	case 1:
+		if (strcmp(request->interface, AGENT_INTERFACE) == 0)
+			g_dbus_send_error(agent_connection, request->message,
+					"net.connman.Agent.Error.Retry", NULL);
+		else
+			g_dbus_send_error(agent_connection, request->message,
+					"net.connman.vpn.Agent.Error.Retry",
+					NULL);
+		break;
+	case 0:
+		g_dbus_send_reply(agent_connection, request->message,
+				DBUS_TYPE_INVALID);
+		break;
+	default:
+		return;
+	}
+
+	pending_message_remove(request);
+	pending_command_complete("");
+}
+
+static DBusMessage *agent_report_error(DBusConnection *connection,
+		DBusMessage *message, void *user_data)
+{
+	struct agent_data *request = user_data;
+	DBusMessageIter iter;
+	char *path, *service, *error;
+
+	if (handle_message(message, request, agent_report_error) == false)
+		return NULL;
+
+	dbus_message_iter_init(message, &iter);
+
+	dbus_message_iter_get_basic(&iter, &path);
+	service = strip_path(path);
+
+	dbus_message_iter_next(&iter);
+	dbus_message_iter_get_basic(&iter, &error);
+
+	__connmanctl_save_rl();
+	if (strcmp(request->interface, AGENT_INTERFACE) == 0)
+		fprintf(stdout, "Agent ReportError %s\n", service);
+	else
+		fprintf(stdout, "VPN Agent ReportError %s\n", service);
+	fprintf(stdout, "  %s\n", error);
+	__connmanctl_redraw_rl();
+
+	request->message = dbus_message_ref(message);
+	__connmanctl_agent_mode("Retry (yes/no)? ", report_error_return,
+			request);
+
+	return NULL;
+}
+
+static DBusMessage *agent_report_peer_error(DBusConnection *connection,
+					DBusMessage *message, void *user_data)
+{
+	struct agent_data *request = user_data;
+	char *path, *peer, *error;
+	DBusMessageIter iter;
+
+	if (handle_message(message, request,
+				agent_report_peer_error) == false)
+		return NULL;
+
+	dbus_message_iter_init(message, &iter);
+
+	dbus_message_iter_get_basic(&iter, &path);
+	peer = strip_path(path);
+
+	dbus_message_iter_next(&iter);
+	dbus_message_iter_get_basic(&iter, &error);
+
+	__connmanctl_save_rl();
+	fprintf(stdout, "Agent ReportPeerError %s\n", peer);
+	fprintf(stdout, "  %s\n", error);
+	__connmanctl_redraw_rl();
+
+	request->message = dbus_message_ref(message);
+	__connmanctl_agent_mode("Retry (yes/no)? ",
+				report_error_return, request);
+	return NULL;
+}
+
+static void request_input_next(struct agent_data *request)
+{
+	int i;
+
+	for (i = 0; request->input[i].attribute; i++) {
+		if (request->input[i].requested == true) {
+			if (request->input[i].func)
+				__connmanctl_agent_mode(request->input[i].prompt,
+						request->input[i].func,
+						request);
+			else
+				request->input[i].requested = false;
+			return;
+		}
+	}
+
+	dbus_message_iter_close_container(&request->iter, &request->dict);
+
+	g_dbus_send_message(agent_connection, request->reply);
+	request->reply = NULL;
+
+	pending_message_remove(request);
+	pending_command_complete("");
+
+	__connmanctl_redraw_rl();
+}
+
+static void request_input_append(struct agent_data *request,
+		const char *attribute, char *value)
+{
+	__connmanctl_dbus_append_dict_entry(&request->dict, attribute,
+			DBUS_TYPE_STRING, &value);
+}
+
+static void request_input_ssid_return(char *input,
+		void *user_data)
+{
+	struct agent_data *request = user_data;
+	int len = 0;
+
+	if (input)
+		len = strlen(input);
+
+	if (len > 0 && len <= 32) {
+		request->input[SSID].requested = false;
+		request_input_append(request, request->input[SSID].attribute,
+				input);
+
+		request_input_next(request);
+	}
+}
+
+static void request_input_passphrase_return(char *input, void *user_data)
+{
+	struct agent_data *request = user_data;
+	int len = 0;
+
+	/* TBD passphrase length checking */
+
+	if (input)
+		len = strlen(input);
+
+	if (len == 0 && request->input[WPS].requested == false)
+		return;
+
+	request->input[PASSPHRASE].requested = false;
+
+	if (len > 0) {
+		request_input_append(request,
+				request->input[PASSPHRASE].attribute, input);
+
+		request->input[WPS].requested = false;
+	}
+
+	request_input_next(request);
+}
+
+static void request_input_string_return(char *input, void *user_data)
+{
+	struct agent_data *request = user_data;
+	int i;
+
+	for (i = 0; request->input[i].attribute; i++) {
+		if (request->input[i].requested == true) {
+			request_input_append(request,
+					request->input[i].attribute, input);
+			request->input[i].requested = false;
+			break;
+		}
+	}
+
+	request_input_next(request);
+}
+
+static void parse_agent_request(struct agent_data *request,
+						DBusMessageIter *iter)
+{
+	DBusMessageIter dict, entry, variant, dict_entry;
+	DBusMessageIter field_entry, field_value;
+	char *field, *argument, *value;
+	char *attr_type = NULL;
+	int i;
+
+	dbus_message_iter_recurse(iter, &dict);
+
+	while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
+
+		dbus_message_iter_recurse(&dict, &entry);
+
+		dbus_message_iter_get_basic(&entry, &field);
+
+		dbus_message_iter_next(&entry);
+
+		dbus_message_iter_recurse(&entry, &variant);
+		dbus_message_iter_recurse(&variant, &dict_entry);
+
+		while (dbus_message_iter_get_arg_type(&dict_entry)
+				== DBUS_TYPE_DICT_ENTRY) {
+			dbus_message_iter_recurse(&dict_entry, &field_entry);
+
+			dbus_message_iter_get_basic(&field_entry, &argument);
+
+			dbus_message_iter_next(&field_entry);
+
+			dbus_message_iter_recurse(&field_entry, &field_value);
+
+			if (strcmp(argument, "Type") == 0) {
+				dbus_message_iter_get_basic(&field_value,
+						&value);
+				attr_type = g_strdup(value);
+			}
+
+			dbus_message_iter_next(&dict_entry);
+		}
+
+		for (i = 0; request->input[i].attribute; i++) {
+			if (strcmp(field, request->input[i].attribute) == 0) {
+				request->input[i].requested = true;
+				break;
+			}
+		}
+
+		g_free(attr_type);
+		attr_type = NULL;
+
+		dbus_message_iter_next(&dict);
+	}
+}
+
+static DBusMessage *agent_request_input(DBusConnection *connection,
+		DBusMessage *message, void *user_data)
+{
+	struct agent_data *request = user_data;
+	DBusMessageIter iter, dict;
+	char *service, *str;
+
+	if (handle_message(message, request, agent_request_input) == false)
+		return NULL;
+
+	dbus_message_iter_init(message, &iter);
+
+	dbus_message_iter_get_basic(&iter, &str);
+	service = strip_path(str);
+
+	dbus_message_iter_next(&iter);
+	dbus_message_iter_recurse(&iter, &dict);
+
+	__connmanctl_save_rl();
+	if (strcmp(request->interface, AGENT_INTERFACE) == 0)
+		fprintf(stdout, "Agent RequestInput %s\n", service);
+	else
+		fprintf(stdout, "VPN Agent RequestInput %s\n", service);
+	__connmanctl_dbus_print(&dict, "  ", " = ", "\n");
+	fprintf(stdout, "\n");
+
+	parse_agent_request(request, &iter);
+
+	request->reply = dbus_message_new_method_return(message);
+	dbus_message_iter_init_append(request->reply, &request->iter);
+
+	dbus_message_iter_open_container(&request->iter, DBUS_TYPE_ARRAY,
+                        DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+                        DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
+                        DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
+			&request->dict);
+
+	request_input_next(request);
+
+	return NULL;
+}
+
+static void request_authorization_return(char *input, void *user_data)
+{
+	struct agent_data *request = user_data;
+
+	switch (confirm_input(input)) {
+	case 1:
+		request->reply = dbus_message_new_method_return(
+							request->message);
+		dbus_message_iter_init_append(request->reply, &request->iter);
+
+		dbus_message_iter_open_container(&request->iter,
+				DBUS_TYPE_ARRAY,
+				DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+				DBUS_TYPE_STRING_AS_STRING
+				DBUS_TYPE_VARIANT_AS_STRING
+				DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
+				&request->dict);
+		dbus_message_iter_close_container(&request->iter,
+							&request->dict);
+		g_dbus_send_message(agent_connection, request->reply);
+		request->reply = NULL;
+		break;
+	case 0:
+		 g_dbus_send_error(agent_connection, request->message,
+				 "net.connman.Agent.Error.Rejected", NULL);
+		 break;
+	default:
+		 g_dbus_send_error(agent_connection, request->message,
+				 "net.connman.Agent.Error.Canceled", NULL);
+		 break;
+	}
+
+	pending_message_remove(request);
+	pending_command_complete("");
+}
+
+static DBusMessage *
+agent_request_peer_authorization(DBusConnection *connection,
+					DBusMessage *message, void *user_data)
+{
+	struct agent_data *request = user_data;
+	DBusMessageIter iter, dict;
+	char *peer, *str;
+	bool input;
+	int i;
+
+	if (handle_message(message, request, agent_request_peer_authorization)
+								== false)
+		return NULL;
+
+	dbus_message_iter_init(message, &iter);
+
+	dbus_message_iter_get_basic(&iter, &str);
+	peer = strip_path(str);
+
+	dbus_message_iter_next(&iter);
+	dbus_message_iter_recurse(&iter, &dict);
+
+	__connmanctl_save_rl();
+	fprintf(stdout, "Agent RequestPeerAuthorization %s\n", peer);
+	__connmanctl_dbus_print(&dict, "  ", " = ", "\n");
+	fprintf(stdout, "\n");
+
+	parse_agent_request(request, &iter);
+
+	for (input = false, i = 0; request->input[i].attribute; i++) {
+		if (request->input[i].requested == true) {
+			input = true;
+			break;
+		}
+	}
+
+	if (!input) {
+		request->message = dbus_message_ref(message);
+		__connmanctl_agent_mode("Accept connection (yes/no)? ",
+					request_authorization_return, request);
+		return NULL;
+	}
+
+	request->reply = dbus_message_new_method_return(message);
+	dbus_message_iter_init_append(request->reply, &request->iter);
+
+	dbus_message_iter_open_container(&request->iter, DBUS_TYPE_ARRAY,
+                        DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+                        DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
+                        DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
+			&request->dict);
+
+	request_input_next(request);
+
+	return NULL;
+}
+
+static const GDBusMethodTable agent_methods[] = {
+	{ GDBUS_ASYNC_METHOD("Release", NULL, NULL, agent_release) },
+	{ GDBUS_ASYNC_METHOD("Cancel", NULL, NULL, agent_cancel) },
+	{ GDBUS_ASYNC_METHOD("RequestBrowser",
+				GDBUS_ARGS({ "service", "o" },
+					{ "url", "s" }),
+				NULL, agent_request_browser) },
+	{ GDBUS_ASYNC_METHOD("ReportError",
+				GDBUS_ARGS({ "service", "o" },
+					{ "error", "s" }),
+				NULL, agent_report_error) },
+	{ GDBUS_ASYNC_METHOD("ReportPeerError",
+				GDBUS_ARGS({ "peer", "o" },
+					{ "error", "s" }),
+				NULL, agent_report_peer_error) },
+	{ GDBUS_ASYNC_METHOD("RequestInput",
+				GDBUS_ARGS({ "service", "o" },
+					{ "fields", "a{sv}" }),
+				GDBUS_ARGS({ "fields", "a{sv}" }),
+				agent_request_input) },
+	{ GDBUS_ASYNC_METHOD("RequestPeerAuthorization",
+				GDBUS_ARGS({ "peer", "o" },
+					{ "fields", "a{sv}" }),
+				GDBUS_ARGS({ "fields", "a{sv}" }),
+				agent_request_peer_authorization) },
+	{ },
+};
+
+static int agent_register_return(DBusMessageIter *iter, const char *error,
+		void *user_data)
+{
+	DBusConnection *connection = user_data;
+
+	if (error) {
+		g_dbus_unregister_interface(connection, agent_path(),
+				AGENT_INTERFACE);
+		fprintf(stderr, "Error registering Agent: %s\n", error);
+		return 0;
+	}
+
+	agent_request.registered = true;
+	fprintf(stdout, "Agent registered\n");
+
+	return -EINPROGRESS;
+}
+
+static void append_path(DBusMessageIter *iter, void *user_data)
+{
+	const char *path = user_data;
+
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH, &path);
+}
+
+int __connmanctl_agent_register(DBusConnection *connection)
+{
+	char *path = agent_path();
+	int result;
+
+	if (agent_request.registered == true) {
+		fprintf(stderr, "Agent already registered\n");
+		return -EALREADY;
+	}
+
+	agent_connection = connection;
+
+	if (!g_dbus_register_interface(connection, path,
+					AGENT_INTERFACE, agent_methods,
+					NULL, NULL, &agent_request, NULL)) {
+		fprintf(stderr, "Error: Failed to register Agent callbacks\n");
+		return 0;
+	}
+
+	result = __connmanctl_dbus_method_call(connection, CONNMAN_SERVICE,
+			CONNMAN_PATH, "net.connman.Manager", "RegisterAgent",
+			agent_register_return, connection, append_path, path);
+
+	if (result != -EINPROGRESS) {
+		g_dbus_unregister_interface(connection, agent_path(),
+				AGENT_INTERFACE);
+
+		fprintf(stderr, "Error: Failed to register Agent\n");
+	}
+
+	return result;
+}
+
+static int agent_unregister_return(DBusMessageIter *iter, const char *error,
+		void *user_data)
+{
+	if (error) {
+		fprintf(stderr, "Error unregistering Agent: %s\n", error);
+		return 0;
+	}
+
+	agent_request.registered = false;
+	fprintf(stdout, "Agent unregistered\n");
+
+	return 0;
+}
+
+int __connmanctl_agent_unregister(DBusConnection *connection)
+{
+	char *path = agent_path();
+	int result;
+
+	if (agent_request.registered == false) {
+		fprintf(stderr, "Agent not registered\n");
+		return -EALREADY;
+	}
+
+	g_dbus_unregister_interface(connection, agent_path(), AGENT_INTERFACE);
+
+	result = __connmanctl_dbus_method_call(connection, CONNMAN_SERVICE,
+			CONNMAN_PATH, "net.connman.Manager", "UnregisterAgent",
+			agent_unregister_return, NULL, append_path, path);
+
+	if (result != -EINPROGRESS)
+		fprintf(stderr, "Error: Failed to unregister Agent\n");
+
+	return result;
+}
+
+static const GDBusMethodTable vpn_agent_methods[] = {
+	{ GDBUS_ASYNC_METHOD("Release", NULL, NULL, agent_release) },
+	{ GDBUS_ASYNC_METHOD("Cancel", NULL, NULL, agent_cancel) },
+	{ GDBUS_ASYNC_METHOD("ReportError",
+				GDBUS_ARGS({ "service", "o" },
+					{ "error", "s" }),
+				NULL, agent_report_error) },
+	{ GDBUS_ASYNC_METHOD("RequestInput",
+				GDBUS_ARGS({ "service", "o" },
+					{ "fields", "a{sv}" }),
+				GDBUS_ARGS({ "fields", "a{sv}" }),
+				agent_request_input) },
+	{ },
+};
+
+static int vpn_agent_register_return(DBusMessageIter *iter, const char *error,
+		void *user_data)
+{
+	DBusConnection *connection = user_data;
+
+	if (error) {
+		g_dbus_unregister_interface(connection, agent_path(),
+				VPN_AGENT_INTERFACE);
+		fprintf(stderr, "Error registering VPN Agent: %s\n", error);
+		return 0;
+	}
+
+	vpn_agent_request.registered = true;
+	fprintf(stdout, "VPN Agent registered\n");
+
+	return -EINPROGRESS;
+}
+
+int __connmanctl_vpn_agent_register(DBusConnection *connection)
+{
+	char *path = agent_path();
+	int result;
+
+	if (vpn_agent_request.registered == true) {
+		fprintf(stderr, "VPN Agent already registered\n");
+		return -EALREADY;
+	}
+
+	agent_connection = connection;
+
+	if (!g_dbus_register_interface(connection, path,
+			VPN_AGENT_INTERFACE, vpn_agent_methods,
+			NULL, NULL, &vpn_agent_request, NULL)) {
+		fprintf(stderr, "Error: Failed to register VPN Agent "
+				"callbacks\n");
+		return 0;
+	}
+
+	result = __connmanctl_dbus_method_call(connection, VPN_SERVICE,
+			VPN_PATH, "net.connman.vpn.Manager", "RegisterAgent",
+			vpn_agent_register_return, connection, append_path,
+			path);
+
+	if (result != -EINPROGRESS) {
+		g_dbus_unregister_interface(connection, agent_path(),
+				VPN_AGENT_INTERFACE);
+
+		fprintf(stderr, "Error: Failed to register VPN Agent\n");
+	}
+
+	return result;
+}
+
+static int vpn_agent_unregister_return(DBusMessageIter *iter,
+		const char *error, void *user_data)
+{
+	if (error) {
+		fprintf(stderr, "Error unregistering VPN Agent: %s\n", error);
+		return 0;
+	}
+
+	vpn_agent_request.registered = false;
+	fprintf(stdout, "VPN Agent unregistered\n");
+
+	return 0;
+}
+
+int __connmanctl_vpn_agent_unregister(DBusConnection *connection)
+{
+	char *path = agent_path();
+	int result;
+
+	if (vpn_agent_request.registered == false) {
+		fprintf(stderr, "VPN Agent not registered\n");
+		return -EALREADY;
+	}
+
+	g_dbus_unregister_interface(connection, agent_path(),
+			VPN_AGENT_INTERFACE);
+
+	result = __connmanctl_dbus_method_call(connection, VPN_SERVICE,
+			VPN_PATH, "net.connman.vpn.Manager", "UnregisterAgent",
+			vpn_agent_unregister_return, NULL, append_path, path);
+
+	if (result != -EINPROGRESS)
+		fprintf(stderr, "Error: Failed to unregister VPN Agent\n");
+
+	return result;
+}
diff --git a/connman/client/agent.h b/connman/client/agent.h
new file mode 100644
index 0000000..669a593
--- /dev/null
+++ b/connman/client/agent.h
@@ -0,0 +1,42 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2013  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 as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  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 __CONNMANCTL_AGENT_H
+#define __CONNMANCTL_AGENT_H
+
+#include <dbus/dbus.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int __connmanctl_agent_register(DBusConnection *connection);
+int __connmanctl_agent_unregister(DBusConnection *connection);
+
+int __connmanctl_vpn_agent_register(DBusConnection *connection);
+int __connmanctl_vpn_agent_unregister(DBusConnection *connection);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CONNMANCTL_AGENT_H */
diff --git a/connman/client/commands.c b/connman/client/commands.c
new file mode 100644
index 0000000..9208016
--- /dev/null
+++ b/connman/client/commands.c
@@ -0,0 +1,2853 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2012-2014  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 as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <stdbool.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <ctype.h>
+
+#include <glib.h>
+#include <gdbus.h>
+
+#include "dbus_helpers.h"
+#include "input.h"
+#include "services.h"
+#include "peers.h"
+#include "commands.h"
+#include "agent.h"
+#include "vpnconnections.h"
+
+static DBusConnection *connection;
+static GHashTable *service_hash;
+static GHashTable *peer_hash;
+static GHashTable *technology_hash;
+static char *session_notify_path;
+static char *session_path;
+static bool session_connected;
+
+struct connman_option {
+	const char *name;
+	const char val;
+	const char *desc;
+};
+
+static char *ipv4[] = {
+	"Method",
+	"Address",
+	"Netmask",
+	"Gateway",
+	NULL
+};
+
+static char *ipv6[] = {
+	"Method",
+	"Address",
+	"PrefixLength",
+	"Gateway",
+	NULL
+};
+
+static int cmd_help(char *args[], int num, struct connman_option *options);
+
+static bool check_dbus_name(const char *name)
+{
+	/*
+	 * Valid dbus chars should be [A-Z][a-z][0-9]_
+	 * and should not start with number.
+	 */
+	unsigned int i;
+
+	if (!name || name[0] == '\0')
+		return false;
+
+	for (i = 0; name[i] != '\0'; i++)
+		if (!((name[i] >= 'A' && name[i] <= 'Z') ||
+				(name[i] >= 'a' && name[i] <= 'z') ||
+				(name[i] >= '0' && name[i] <= '9') ||
+				name[i] == '_'))
+			return false;
+
+	return true;
+}
+
+static int parse_boolean(char *arg)
+{
+	if (!arg)
+		return -1;
+
+	if (strcasecmp(arg, "no") == 0 ||
+			strcasecmp(arg, "false") == 0 ||
+			strcasecmp(arg, "off" ) == 0 ||
+			strcasecmp(arg, "disable" ) == 0 ||
+			strcasecmp(arg, "n") == 0 ||
+			strcasecmp(arg, "f") == 0 ||
+			strcasecmp(arg, "0") == 0)
+		return 0;
+
+	if (strcasecmp(arg, "yes") == 0 ||
+			strcasecmp(arg, "true") == 0 ||
+			strcasecmp(arg, "on") == 0 ||
+			strcasecmp(arg, "enable" ) == 0 ||
+			strcasecmp(arg, "y") == 0 ||
+			strcasecmp(arg, "t") == 0 ||
+			strcasecmp(arg, "1") == 0)
+		return 1;
+
+	return -1;
+}
+
+static int parse_args(char *arg, struct connman_option *options)
+{
+	int i;
+
+	if (!arg)
+		return -1;
+
+	for (i = 0; options[i].name; i++) {
+		if (strcmp(options[i].name, arg) == 0 ||
+				(strncmp(arg, "--", 2) == 0 &&
+					strcmp(&arg[2], options[i].name) == 0))
+			return options[i].val;
+	}
+
+	return '?';
+}
+
+static int enable_return(DBusMessageIter *iter, const char *error,
+		void *user_data)
+{
+	char *tech = user_data;
+	char *str;
+
+	str = strrchr(tech, '/');
+	if (str)
+		str++;
+	else
+		str = tech;
+
+	if (!error)
+		fprintf(stdout, "Enabled %s\n", str);
+	else
+		fprintf(stderr, "Error %s: %s\n", str, error);
+
+	g_free(user_data);
+
+	return 0;
+}
+
+static int cmd_enable(char *args[], int num, struct connman_option *options)
+{
+	char *tech;
+	dbus_bool_t b = TRUE;
+
+	if (num > 2)
+		return -E2BIG;
+
+	if (num < 2)
+		return -EINVAL;
+
+	if (check_dbus_name(args[1]) == false)
+		return -EINVAL;
+
+	if (strcmp(args[1], "offline") == 0) {
+		tech = g_strdup(args[1]);
+		return __connmanctl_dbus_set_property(connection, "/",
+				"net.connman.Manager", enable_return, tech,
+				"OfflineMode", DBUS_TYPE_BOOLEAN, &b);
+	}
+
+	tech = g_strdup_printf("/net/connman/technology/%s", args[1]);
+	return __connmanctl_dbus_set_property(connection, tech,
+				"net.connman.Technology", enable_return, tech,
+				"Powered", DBUS_TYPE_BOOLEAN, &b);
+}
+
+static int disable_return(DBusMessageIter *iter, const char *error,
+		void *user_data)
+{
+	char *tech = user_data;
+	char *str;
+
+	str = strrchr(tech, '/');
+	if (str)
+		str++;
+	else
+		str = tech;
+
+	if (!error)
+		fprintf(stdout, "Disabled %s\n", str);
+	else
+		fprintf(stderr, "Error %s: %s\n", str, error);
+
+	g_free(user_data);
+
+	return 0;
+}
+
+static int cmd_disable(char *args[], int num, struct connman_option *options)
+{
+	char *tech;
+	dbus_bool_t b = FALSE;
+
+	if (num > 2)
+		return -E2BIG;
+
+	if (num < 2)
+		return -EINVAL;
+
+	if (check_dbus_name(args[1]) == false)
+		return -EINVAL;
+
+	if (strcmp(args[1], "offline") == 0) {
+		tech = g_strdup(args[1]);
+		return __connmanctl_dbus_set_property(connection, "/",
+				"net.connman.Manager", disable_return, tech,
+				"OfflineMode", DBUS_TYPE_BOOLEAN, &b);
+	}
+
+	tech = g_strdup_printf("/net/connman/technology/%s", args[1]);
+	return __connmanctl_dbus_set_property(connection, tech,
+				"net.connman.Technology", disable_return, tech,
+				"Powered", DBUS_TYPE_BOOLEAN, &b);
+}
+
+static int state_print(DBusMessageIter *iter, const char *error,
+		void *user_data)
+{
+	DBusMessageIter entry;
+
+	if (error) {
+		fprintf(stderr, "Error: %s", error);
+		return 0;
+	}
+
+	dbus_message_iter_recurse(iter, &entry);
+	__connmanctl_dbus_print(&entry, "  ", " = ", "\n");
+	fprintf(stdout, "\n");
+
+	return 0;
+}
+
+static int cmd_state(char *args[], int num, struct connman_option *options)
+{
+	if (num > 1)
+		return -E2BIG;
+
+	return __connmanctl_dbus_method_call(connection, CONNMAN_SERVICE,
+			CONNMAN_PATH, "net.connman.Manager", "GetProperties",
+			state_print, NULL, NULL, NULL);
+}
+
+static int services_list(DBusMessageIter *iter, const char *error,
+		void *user_data)
+{
+	if (!error) {
+		__connmanctl_services_list(iter);
+		fprintf(stdout, "\n");
+	} else {
+		fprintf(stderr, "Error: %s\n", error);
+	}
+
+	return 0;
+}
+
+static int peers_list(DBusMessageIter *iter,
+					const char *error, void *user_data)
+{
+	if (!error) {
+		__connmanctl_peers_list(iter);
+		fprintf(stdout, "\n");
+	} else
+		fprintf(stderr, "Error: %s\n", error);
+
+	return 0;
+}
+
+static int object_properties(DBusMessageIter *iter,
+					const char *error, void *user_data)
+{
+	char *path = user_data;
+	char *str;
+	DBusMessageIter dict;
+
+	if (!error) {
+		fprintf(stdout, "%s\n", path);
+
+		dbus_message_iter_recurse(iter, &dict);
+		__connmanctl_dbus_print(&dict, "  ", " = ", "\n");
+
+		fprintf(stdout, "\n");
+
+	} else {
+		str = strrchr(path, '/');
+		if (str)
+			str++;
+		else
+			str = path;
+
+		fprintf(stderr, "Error %s: %s\n", str, error);
+	}
+
+	g_free(user_data);
+
+	return 0;
+}
+
+static int cmd_services(char *args[], int num, struct connman_option *options)
+{
+	char *service_name = NULL;
+	char *path;
+	int c;
+
+	if (num > 3)
+		return -E2BIG;
+
+	c = parse_args(args[1], options);
+	switch (c) {
+	case -1:
+		break;
+	case 'p':
+		if (num < 3)
+			return -EINVAL;
+		service_name = args[2];
+		break;
+	default:
+		if (num > 2)
+			return -E2BIG;
+		service_name = args[1];
+		break;
+	}
+
+	if (!service_name) {
+		return __connmanctl_dbus_method_call(connection,
+				CONNMAN_SERVICE, CONNMAN_PATH,
+				"net.connman.Manager", "GetServices",
+				services_list, NULL, NULL, NULL);
+	}
+
+	if (check_dbus_name(service_name) == false)
+		return -EINVAL;
+
+	path = g_strdup_printf("/net/connman/service/%s", service_name);
+	return __connmanctl_dbus_method_call(connection, CONNMAN_SERVICE, path,
+			"net.connman.Service", "GetProperties",
+			object_properties, path, NULL, NULL);
+}
+
+static int cmd_peers(char *args[], int num, struct connman_option *options)
+{
+	char *peer_name = NULL;
+	char *path;
+
+	if (num > 2)
+		return -E2BIG;
+
+	if (num == 2)
+		peer_name = args[1];
+
+	if (!peer_name) {
+		return __connmanctl_dbus_method_call(connection,
+					CONNMAN_SERVICE, CONNMAN_PATH,
+					"net.connman.Manager", "GetPeers",
+					peers_list, NULL, NULL, NULL);
+	}
+
+	if (check_dbus_name(peer_name) == false)
+		return -EINVAL;
+
+	path = g_strdup_printf("/net/connman/peer/%s", peer_name);
+	return __connmanctl_dbus_method_call(connection, CONNMAN_SERVICE,
+				path, "net.connman.Peer", "GetProperties",
+				object_properties, path, NULL, NULL);
+}
+
+static int technology_print(DBusMessageIter *iter, const char *error,
+		void *user_data)
+{
+	DBusMessageIter array;
+
+	if (error) {
+		fprintf(stderr, "Error: %s\n", error);
+		return 0;
+	}
+
+	dbus_message_iter_recurse(iter, &array);
+	while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_STRUCT) {
+		DBusMessageIter entry, dict;
+		const char *path;
+
+		dbus_message_iter_recurse(&array, &entry);
+		dbus_message_iter_get_basic(&entry, &path);
+		fprintf(stdout, "%s\n", path);
+
+		dbus_message_iter_next(&entry);
+
+		dbus_message_iter_recurse(&entry, &dict);
+		__connmanctl_dbus_print(&dict, "  ", " = ", "\n");
+		fprintf(stdout, "\n");
+
+		dbus_message_iter_next(&array);
+	}
+
+	return 0;
+}
+
+static int cmd_technologies(char *args[], int num,
+		struct connman_option *options)
+{
+	if (num > 1)
+		return -E2BIG;
+
+	return __connmanctl_dbus_method_call(connection, CONNMAN_SERVICE,
+			CONNMAN_PATH, "net.connman.Manager", "GetTechnologies",
+			technology_print, NULL,	NULL, NULL);
+}
+
+struct tether_enable {
+	char *path;
+	dbus_bool_t enable;
+};
+
+static int tether_set_return(DBusMessageIter *iter, const char *error,
+		void *user_data)
+{
+	struct tether_enable *tether = user_data;
+	char *str;
+
+	str = strrchr(tether->path, '/');
+	if (str)
+		str++;
+	else
+		str = tether->path;
+
+	if (!error) {
+		fprintf(stdout, "%s tethering for %s\n",
+				tether->enable ? "Enabled" : "Disabled",
+				str);
+	} else
+		fprintf(stderr, "Error %s %s tethering: %s\n",
+				tether->enable ?
+				"enabling" : "disabling", str, error);
+
+	g_free(tether->path);
+	g_free(user_data);
+
+	return 0;
+}
+
+static int tether_set(char *technology, int set_tethering)
+{
+	struct tether_enable *tether = g_new(struct tether_enable, 1);
+
+	switch(set_tethering) {
+	case 1:
+		tether->enable = TRUE;
+		break;
+	case 0:
+		tether->enable = FALSE;
+		break;
+	default:
+		g_free(tether);
+		return 0;
+	}
+
+	tether->path = g_strdup_printf("/net/connman/technology/%s",
+			technology);
+
+	return __connmanctl_dbus_set_property(connection, tether->path,
+			"net.connman.Technology", tether_set_return,
+			tether, "Tethering", DBUS_TYPE_BOOLEAN,
+			&tether->enable);
+}
+
+struct tether_properties {
+	int ssid_result;
+	int passphrase_result;
+	int set_tethering;
+};
+
+static int tether_update(struct tether_properties *tether)
+{
+	if (tether->ssid_result == 0 && tether->passphrase_result == 0)
+		return tether_set("wifi", tether->set_tethering);
+
+	if (tether->ssid_result != -EINPROGRESS &&
+			tether->passphrase_result != -EINPROGRESS) {
+		g_free(tether);
+		return 0;
+	}
+
+	return -EINPROGRESS;
+}
+
+static int tether_set_ssid_return(DBusMessageIter *iter, const char *error,
+		void *user_data)
+{
+	struct tether_properties *tether = user_data;
+
+	if (!error) {
+		fprintf(stdout, "Wifi SSID set\n");
+		tether->ssid_result = 0;
+	} else {
+		fprintf(stderr, "Error setting wifi SSID: %s\n", error);
+		tether->ssid_result = -EINVAL;
+	}
+
+	return tether_update(tether);
+}
+
+static int tether_set_passphrase_return(DBusMessageIter *iter,
+		const char *error, void *user_data)
+{
+	struct tether_properties *tether = user_data;
+
+	if (!error) {
+		fprintf(stdout, "Wifi passphrase set\n");
+		tether->passphrase_result = 0;
+	} else {
+		fprintf(stderr, "Error setting wifi passphrase: %s\n", error);
+		tether->passphrase_result = -EINVAL;
+	}
+
+	return tether_update(tether);
+}
+
+static int tether_set_ssid(char *ssid, char *passphrase, int set_tethering)
+{
+	struct tether_properties *tether = g_new(struct tether_properties, 1);
+
+	tether->set_tethering = set_tethering;
+
+	tether->ssid_result = __connmanctl_dbus_set_property(connection,
+			"/net/connman/technology/wifi",
+			"net.connman.Technology",
+			tether_set_ssid_return, tether,
+			"TetheringIdentifier", DBUS_TYPE_STRING, &ssid);
+
+	tether->passphrase_result =__connmanctl_dbus_set_property(connection,
+			"/net/connman/technology/wifi",
+			"net.connman.Technology",
+			tether_set_passphrase_return, tether,
+			"TetheringPassphrase", DBUS_TYPE_STRING, &passphrase);
+
+	if (tether->ssid_result != -EINPROGRESS &&
+			tether->passphrase_result != -EINPROGRESS) {
+		g_free(tether);
+		return -ENXIO;
+	}
+
+	return -EINPROGRESS;
+}
+
+static int cmd_tether(char *args[], int num, struct connman_option *options)
+{
+	char *ssid, *passphrase;
+	int set_tethering;
+
+	if (num < 3)
+		return -EINVAL;
+
+	passphrase = args[num - 1];
+	ssid = args[num - 2];
+
+	set_tethering = parse_boolean(args[2]);
+
+	if (strcmp(args[1], "wifi") == 0) {
+
+		if (num > 5)
+			return -E2BIG;
+
+		if (num == 5 && set_tethering == -1)
+			return -EINVAL;
+
+		if (num == 4)
+			set_tethering = -1;
+
+		if (num > 3)
+			return tether_set_ssid(ssid, passphrase, set_tethering);
+	}
+
+	if (num > 3)
+		return -E2BIG;
+
+	if (set_tethering == -1)
+		return -EINVAL;
+
+	if (check_dbus_name(args[1]) == false)
+		return -EINVAL;
+
+	return tether_set(args[1], set_tethering);
+}
+
+static int scan_return(DBusMessageIter *iter, const char *error,
+		void *user_data)
+{
+	char *path = user_data;
+
+	if (!error) {
+		char *str = strrchr(path, '/');
+		str++;
+		fprintf(stdout, "Scan completed for %s\n", str);
+	} else
+		fprintf(stderr, "Error %s: %s\n", path, error);
+
+	g_free(user_data);
+
+	return 0;
+}
+
+static int cmd_scan(char *args[], int num, struct connman_option *options)
+{
+	char *path;
+
+	if (num > 2)
+		return -E2BIG;
+
+	if (num < 2)
+		return -EINVAL;
+
+	if (check_dbus_name(args[1]) == false)
+		return -EINVAL;
+
+	path = g_strdup_printf("/net/connman/technology/%s", args[1]);
+	return __connmanctl_dbus_method_call(connection, CONNMAN_SERVICE, path,
+			"net.connman.Technology", "Scan",
+			scan_return, path, NULL, NULL);
+}
+
+static int connect_return(DBusMessageIter *iter, const char *error,
+		void *user_data)
+{
+	char *path = user_data;
+
+	if (!error) {
+		char *str = strrchr(path, '/');
+		str++;
+		fprintf(stdout, "Connected %s\n", str);
+	} else
+		fprintf(stderr, "Error %s: %s\n", path, error);
+
+	g_free(user_data);
+
+	return 0;
+}
+
+static int cmd_connect(char *args[], int num, struct connman_option *options)
+{
+	const char *iface = "net.connman.Service";
+	char *path;
+
+	if (num > 2)
+		return -E2BIG;
+
+	if (num < 2)
+		return -EINVAL;
+
+	if (check_dbus_name(args[1]) == false)
+		return -EINVAL;
+
+	if (g_strstr_len(args[1], 5, "peer_") == args[1]) {
+		iface = "net.connman.Peer";
+		path = g_strdup_printf("/net/connman/peer/%s", args[1]);
+	} else
+		path = g_strdup_printf("/net/connman/service/%s", args[1]);
+
+	return __connmanctl_dbus_method_call(connection, CONNMAN_SERVICE, path,
+			iface, "Connect", connect_return, path, NULL, NULL);
+}
+
+static int disconnect_return(DBusMessageIter *iter, const char *error,
+		void *user_data)
+{
+	char *path = user_data;
+
+	if (!error) {
+		char *str = strrchr(path, '/');
+		str++;
+		fprintf(stdout, "Disconnected %s\n", str);
+	} else
+		fprintf(stderr, "Error %s: %s\n", path, error);
+
+	g_free(user_data);
+
+	return 0;
+}
+
+static int cmd_disconnect(char *args[], int num, struct connman_option *options)
+{
+	const char *iface = "net.connman.Service";
+	char *path;
+
+	if (num > 2)
+		return -E2BIG;
+
+	if (num < 2)
+		return -EINVAL;
+
+	if (check_dbus_name(args[1]) == false)
+		return -EINVAL;
+
+	if (g_strstr_len(args[1], 5, "peer_") == args[1]) {
+		iface = "net.connman.Peer";
+		path = g_strdup_printf("/net/connman/peer/%s", args[1]);
+	} else
+		path = g_strdup_printf("/net/connman/service/%s", args[1]);
+
+	return __connmanctl_dbus_method_call(connection, CONNMAN_SERVICE,
+					path, iface, "Disconnect",
+					disconnect_return, path, NULL, NULL);
+}
+
+static int config_return(DBusMessageIter *iter, const char *error,
+		void *user_data)
+{
+	char *service_name = user_data;
+
+	if (error)
+		fprintf(stderr, "Error %s: %s\n", service_name, error);
+
+	g_free(user_data);
+
+	return 0;
+}
+
+struct config_append {
+	char **opts;
+	int values;
+};
+
+static void config_append_ipv4(DBusMessageIter *iter,
+		void *user_data)
+{
+	struct config_append *append = user_data;
+	char **opts = append->opts;
+	int i = 0;
+
+	if (!opts)
+		return;
+
+	while (opts[i] && ipv4[i]) {
+		__connmanctl_dbus_append_dict_entry(iter, ipv4[i],
+				DBUS_TYPE_STRING, &opts[i]);
+		i++;
+	}
+
+	append->values = i;
+}
+
+static void config_append_ipv6(DBusMessageIter *iter, void *user_data)
+{
+	struct config_append *append = user_data;
+	char **opts = append->opts;
+
+	if (!opts)
+		return;
+
+	append->values = 1;
+
+	if (g_strcmp0(opts[0], "auto") == 0) {
+		char *str;
+
+		switch (parse_boolean(opts[1])) {
+		case 0:
+			append->values = 2;
+
+			str = "disabled";
+			__connmanctl_dbus_append_dict_entry(iter, "Privacy",
+					DBUS_TYPE_STRING, &str);
+			break;
+
+		case 1:
+			append->values = 2;
+
+			str = "enabled";
+			__connmanctl_dbus_append_dict_entry(iter, "Privacy",
+					DBUS_TYPE_STRING, &str);
+			break;
+
+		default:
+			if (opts[1]) {
+				append->values = 2;
+
+				if (g_strcmp0(opts[1], "prefered") != 0 &&
+						g_strcmp0(opts[1],
+							"preferred") != 0) {
+					fprintf(stderr, "Error %s: %s\n",
+							opts[1],
+							strerror(EINVAL));
+					return;
+				}
+
+				str = "prefered";
+				__connmanctl_dbus_append_dict_entry(iter,
+						"Privacy", DBUS_TYPE_STRING,
+						&str);
+			}
+			break;
+		}
+	} else if (g_strcmp0(opts[0], "manual") == 0) {
+		int i = 1;
+
+		while (opts[i] && ipv6[i]) {
+			if (i == 2) {
+				int value = atoi(opts[i]);
+				__connmanctl_dbus_append_dict_entry(iter,
+						ipv6[i], DBUS_TYPE_BYTE,
+						&value);
+			} else {
+				__connmanctl_dbus_append_dict_entry(iter,
+						ipv6[i], DBUS_TYPE_STRING,
+						&opts[i]);
+			}
+			i++;
+		}
+
+		append->values = i;
+
+	} else if (g_strcmp0(opts[0], "off") != 0) {
+		fprintf(stderr, "Error %s: %s\n", opts[0], strerror(EINVAL));
+
+		return;
+	}
+
+	__connmanctl_dbus_append_dict_entry(iter, "Method", DBUS_TYPE_STRING,
+				&opts[0]);
+}
+
+static void config_append_str(DBusMessageIter *iter, void *user_data)
+{
+	struct config_append *append = user_data;
+	char **opts = append->opts;
+	int i = 0;
+
+	if (!opts)
+		return;
+
+	while (opts[i]) {
+		dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING,
+				&opts[i]);
+		i++;
+	}
+
+	append->values = i;
+}
+
+static void append_servers(DBusMessageIter *iter, void *user_data)
+{
+	struct config_append *append = user_data;
+	char **opts = append->opts;
+	int i = 1;
+
+	if (!opts)
+		return;
+
+	while (opts[i] && g_strcmp0(opts[i], "--excludes") != 0) {
+		dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING,
+				&opts[i]);
+		i++;
+	}
+
+	append->values = i;
+}
+
+static void append_excludes(DBusMessageIter *iter, void *user_data)
+{
+	struct config_append *append = user_data;
+	char **opts = append->opts;
+	int i = append->values;
+
+	if (!opts || !opts[i] ||
+			g_strcmp0(opts[i], "--excludes") != 0)
+		return;
+
+	i++;
+	while (opts[i]) {
+		dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING,
+				&opts[i]);
+		i++;
+	}
+
+	append->values = i;
+}
+
+static void config_append_proxy(DBusMessageIter *iter, void *user_data)
+{
+	struct config_append *append = user_data;
+	char **opts = append->opts;
+
+	if (!opts)
+		return;
+
+	if (g_strcmp0(opts[0], "manual") == 0) {
+		__connmanctl_dbus_append_dict_string_array(iter, "Servers",
+				append_servers, append);
+
+		__connmanctl_dbus_append_dict_string_array(iter, "Excludes",
+				append_excludes, append);
+
+	} else if (g_strcmp0(opts[0], "auto") == 0) {
+		if (opts[1]) {
+			__connmanctl_dbus_append_dict_entry(iter, "URL",
+					DBUS_TYPE_STRING, &opts[1]);
+			append->values++;
+		}
+
+	} else if (g_strcmp0(opts[0], "direct") != 0)
+		return;
+
+	__connmanctl_dbus_append_dict_entry(iter, "Method",DBUS_TYPE_STRING,
+			&opts[0]);
+
+	append->values++;
+}
+
+static int cmd_config(char *args[], int num, struct connman_option *options)
+{
+	int result = 0, res = 0, index = 2, oldindex = 0;
+	int c;
+	char *service_name, *path;
+	char **opt_start;
+	dbus_bool_t val;
+	struct config_append append;
+
+	service_name = args[1];
+	if (!service_name)
+		return -EINVAL;
+
+	if (check_dbus_name(service_name) == false)
+		return -EINVAL;
+
+	while (index < num && args[index]) {
+		c = parse_args(args[index], options);
+		opt_start = &args[index + 1];
+		append.opts = opt_start;
+		append.values = 0;
+
+		res = 0;
+
+		oldindex = index;
+		path = g_strdup_printf("/net/connman/service/%s", service_name);
+
+		switch (c) {
+		case 'a':
+			switch (parse_boolean(*opt_start)) {
+			case 1:
+				val = TRUE;
+				break;
+			case 0:
+				val = FALSE;
+				break;
+			default:
+				res = -EINVAL;
+				break;
+			}
+
+			index++;
+
+			if (res == 0) {
+				res = __connmanctl_dbus_set_property(connection,
+						path, "net.connman.Service",
+						config_return,
+						g_strdup(service_name),
+						"AutoConnect",
+						DBUS_TYPE_BOOLEAN, &val);
+			}
+			break;
+		case 'i':
+			res = __connmanctl_dbus_set_property_dict(connection,
+					path, "net.connman.Service",
+					config_return, g_strdup(service_name),
+					"IPv4.Configuration", DBUS_TYPE_STRING,
+					config_append_ipv4, &append);
+			index += append.values;
+			break;
+
+		case 'v':
+			res = __connmanctl_dbus_set_property_dict(connection,
+					path, "net.connman.Service",
+					config_return, g_strdup(service_name),
+					"IPv6.Configuration", DBUS_TYPE_STRING,
+					config_append_ipv6, &append);
+			index += append.values;
+			break;
+
+		case 'n':
+			res = __connmanctl_dbus_set_property_array(connection,
+					path, "net.connman.Service",
+					config_return, g_strdup(service_name),
+					"Nameservers.Configuration",
+					DBUS_TYPE_STRING, config_append_str,
+					&append);
+			index += append.values;
+			break;
+
+		case 't':
+			res = __connmanctl_dbus_set_property_array(connection,
+					path, "net.connman.Service",
+					config_return, g_strdup(service_name),
+					"Timeservers.Configuration",
+					DBUS_TYPE_STRING, config_append_str,
+					&append);
+			index += append.values;
+			break;
+
+		case 'd':
+			res = __connmanctl_dbus_set_property_array(connection,
+					path, "net.connman.Service",
+					config_return, g_strdup(service_name),
+					"Domains.Configuration",
+					DBUS_TYPE_STRING, config_append_str,
+					&append);
+			index += append.values;
+			break;
+
+		case 'x':
+			res = __connmanctl_dbus_set_property_dict(connection,
+					path, "net.connman.Service",
+					config_return, g_strdup(service_name),
+					"Proxy.Configuration",
+					DBUS_TYPE_STRING, config_append_proxy,
+					&append);
+			index += append.values;
+			break;
+		case 'r':
+			res = __connmanctl_dbus_method_call(connection,
+					CONNMAN_SERVICE, path,
+					"net.connman.Service", "Remove",
+					config_return, g_strdup(service_name),
+					NULL, NULL);
+			break;
+		default:
+			res = -EINVAL;
+			break;
+		}
+
+		g_free(path);
+
+		if (res < 0) {
+			if (res == -EINPROGRESS)
+				result = -EINPROGRESS;
+			else
+				printf("Error '%s': %s\n", args[oldindex],
+						strerror(-res));
+		} else
+			index += res;
+
+		index++;
+	}
+
+	return result;
+}
+
+static DBusHandlerResult monitor_changed(DBusConnection *connection,
+		DBusMessage *message, void *user_data)
+{
+	DBusMessageIter iter;
+	const char *interface, *path;
+
+	interface = dbus_message_get_interface(message);
+	if (!interface)
+		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+	if (strncmp(interface, "net.connman.", 12) != 0)
+		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+	if (!strcmp(interface, "net.connman.Agent") ||
+			!strcmp(interface, "net.connman.vpn.Agent") ||
+			!strcmp(interface, "net.connman.Session") ||
+			!strcmp(interface, "net.connman.Notification"))
+		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+	interface = strrchr(interface, '.');
+	if (interface && *interface != '\0')
+		interface++;
+
+	path = strrchr(dbus_message_get_path(message), '/');
+	if (path && *path != '\0')
+		path++;
+
+	__connmanctl_save_rl();
+
+	if (dbus_message_is_signal(message, "net.connman.Manager",
+					"ServicesChanged")) {
+
+		fprintf(stdout, "%-12s %-20s = {\n", interface,
+				"ServicesChanged");
+		dbus_message_iter_init(message, &iter);
+		__connmanctl_services_list(&iter);
+		fprintf(stdout, "\n}\n");
+
+		__connmanctl_redraw_rl();
+
+		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+	} else if (dbus_message_is_signal(message, "net.connman.Manager",
+							"PeersChanged")) {
+		fprintf(stdout, "%-12s %-20s = {\n", interface,
+							"PeersChanged");
+		dbus_message_iter_init(message, &iter);
+		__connmanctl_peers_list(&iter);
+		fprintf(stdout, "\n}\n");
+
+		__connmanctl_redraw_rl();
+
+		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+	} else if (dbus_message_is_signal(message, "net.connman.vpn.Manager",
+					"ConnectionAdded") ||
+			dbus_message_is_signal(message,
+					"net.connman.vpn.Manager",
+					"ConnectionRemoved")) {
+		interface = "vpn.Manager";
+		path = dbus_message_get_member(message);
+
+	} else if (dbus_message_is_signal(message, "net.connman.Manager",
+					"TechnologyAdded") ||
+			dbus_message_is_signal(message, "net.connman.Manager",
+					"TechnologyRemoved"))
+		path = dbus_message_get_member(message);
+
+	fprintf(stdout, "%-12s %-20s ", interface, path);
+	dbus_message_iter_init(message, &iter);
+
+	__connmanctl_dbus_print(&iter, "", " = ", " = ");
+	fprintf(stdout, "\n");
+
+	__connmanctl_redraw_rl();
+
+	return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+
+static struct {
+	char *interface;
+	bool enabled;
+} monitor[] = {
+	{ "Service", false },
+	{ "Technology", false },
+	{ "Manager", false },
+	{ "vpn.Manager", false },
+	{ "vpn.Connection", false },
+	{ NULL, },
+};
+
+static void monitor_add(char *interface)
+{
+	bool add_filter = true, found = false;
+	int i;
+	char *rule;
+	DBusError err;
+
+	for (i = 0; monitor[i].interface; i++) {
+		if (monitor[i].enabled == true)
+			add_filter = false;
+
+		if (g_strcmp0(interface, monitor[i].interface) == 0) {
+			if (monitor[i].enabled == true)
+				return;
+
+			monitor[i].enabled = true;
+			found = true;
+		}
+	}
+
+	if (found == false)
+		return;
+
+	if (add_filter == true)
+		dbus_connection_add_filter(connection, monitor_changed,
+				NULL, NULL);
+
+	dbus_error_init(&err);
+	rule  = g_strdup_printf("type='signal',interface='net.connman.%s'",
+			interface);
+	dbus_bus_add_match(connection, rule, &err);
+	g_free(rule);
+
+	if (dbus_error_is_set(&err))
+		fprintf(stderr, "Error: %s\n", err.message);
+}
+
+static void monitor_del(char *interface)
+{
+	bool del_filter = true, found = false;
+	int i;
+	char *rule;
+
+
+	for (i = 0; monitor[i].interface; i++) {
+		if (g_strcmp0(interface, monitor[i].interface) == 0) {
+			if (monitor[i].enabled == false)
+				return;
+
+			monitor[i].enabled = false;
+			found = true;
+		}
+
+		if (monitor[i].enabled == true)
+			del_filter = false;
+	}
+
+	if (found == false)
+		return;
+
+	rule  = g_strdup_printf("type='signal',interface='net.connman.%s'",
+			interface);
+	dbus_bus_remove_match(connection, rule, NULL);
+	g_free(rule);
+
+	if (del_filter == true)
+		dbus_connection_remove_filter(connection, monitor_changed,
+				NULL);
+}
+
+static int cmd_monitor(char *args[], int num, struct connman_option *options)
+{
+	bool add = true;
+	int c;
+
+	if (num > 3)
+		return -E2BIG;
+
+	if (num == 3) {
+		switch (parse_boolean(args[2])) {
+		case 0:
+			add = false;
+			break;
+
+		default:
+			break;
+		}
+	}
+
+	c = parse_args(args[1], options);
+	switch (c) {
+	case -1:
+		monitor_add("Service");
+		monitor_add("Technology");
+		monitor_add("Manager");
+		monitor_add("vpn.Manager");
+		monitor_add("vpn.Connection");
+		break;
+
+	case 's':
+		if (add == true)
+			monitor_add("Service");
+		else
+			monitor_del("Service");
+		break;
+
+	case 'c':
+		if (add == true)
+			monitor_add("Technology");
+		else
+			monitor_del("Technology");
+		break;
+
+	case 'm':
+		if (add == true)
+			monitor_add("Manager");
+		else
+			monitor_del("Manager");
+		break;
+
+	case 'M':
+		if (add == true)
+			monitor_add("vpn.Manager");
+		else
+			monitor_del("vpn.Manager");
+		break;
+
+	case 'C':
+		if (add == true)
+			monitor_add("vpn.Connection");
+		else
+			monitor_del("vpn.Connection");
+		break;
+
+	default:
+		switch(parse_boolean(args[1])) {
+		case 0:
+			monitor_del("Service");
+			monitor_del("Technology");
+			monitor_del("Manager");
+			monitor_del("vpn.Manager");
+			monitor_del("vpn.Connection");
+			break;
+
+		case 1:
+			monitor_add("Service");
+			monitor_add("Technology");
+			monitor_add("Manager");
+			monitor_add("vpn.Manager");
+			monitor_add("vpn.Connection");
+			break;
+
+		default:
+			return -EINVAL;
+		}
+	}
+
+	if (add == true)
+		return -EINPROGRESS;
+
+	return 0;
+}
+
+static int cmd_agent(char *args[], int num, struct connman_option *options)
+{
+	if (!__connmanctl_is_interactive()) {
+		fprintf(stderr, "Error: Not supported in non-interactive "
+				"mode\n");
+		return 0;
+	}
+
+	if (num > 2)
+		return -E2BIG;
+
+	if (num < 2)
+		return -EINVAL;
+
+	switch(parse_boolean(args[1])) {
+	case 0:
+		__connmanctl_agent_unregister(connection);
+		break;
+
+	case 1:
+		if (__connmanctl_agent_register(connection) == -EINPROGRESS)
+			return -EINPROGRESS;
+
+		break;
+
+	default:
+		return -EINVAL;
+		break;
+	}
+
+	return 0;
+}
+
+static int vpnconnections_properties(DBusMessageIter *iter, const char *error,
+		void *user_data)
+{
+	char *path = user_data;
+	char *str;
+	DBusMessageIter dict;
+
+	if (!error) {
+		fprintf(stdout, "%s\n", path);
+
+		dbus_message_iter_recurse(iter, &dict);
+		__connmanctl_dbus_print(&dict, "  ", " = ", "\n");
+
+		fprintf(stdout, "\n");
+
+	} else {
+		str = strrchr(path, '/');
+		if (str)
+			str++;
+		else
+			str = path;
+
+		fprintf(stderr, "Error %s: %s\n", str, error);
+	}
+
+	g_free(user_data);
+
+	return 0;
+}
+
+static int vpnconnections_list(DBusMessageIter *iter, const char *error,
+		void *user_data)
+{
+	if (!error)
+		__connmanctl_vpnconnections_list(iter);
+        else
+		fprintf(stderr, "Error: %s\n", error);
+
+	return 0;
+}
+
+static int cmd_vpnconnections(char *args[], int num,
+		struct connman_option *options)
+{
+	char *vpnconnection_name, *path;
+
+	if (num > 2)
+		return -E2BIG;
+
+	vpnconnection_name = args[1];
+
+	if (!vpnconnection_name)
+		return __connmanctl_dbus_method_call(connection,
+				VPN_SERVICE, VPN_PATH,
+				"net.connman.vpn.Manager", "GetConnections",
+				vpnconnections_list, NULL,
+				NULL, NULL);
+
+	if (check_dbus_name(vpnconnection_name) == false)
+		return -EINVAL;
+
+	path = g_strdup_printf("/net/connman/vpn/connection/%s",
+			vpnconnection_name);
+	return __connmanctl_dbus_method_call(connection, VPN_SERVICE, path,
+			"net.connman.vpn.Connection", "GetProperties",
+			vpnconnections_properties, path, NULL, NULL);
+
+}
+
+static int cmd_vpnagent(char *args[], int num, struct connman_option *options)
+{
+	if (!__connmanctl_is_interactive()) {
+		fprintf(stderr, "Error: Not supported in non-interactive "
+				"mode\n");
+		return 0;
+	}
+
+	if (num > 2)
+		return -E2BIG;
+
+	if (num < 2)
+		return -EINVAL;
+
+	switch(parse_boolean(args[1])) {
+	case 0:
+		__connmanctl_vpn_agent_unregister(connection);
+		break;
+
+	case 1:
+		if (__connmanctl_vpn_agent_register(connection) ==
+				-EINPROGRESS)
+			return -EINPROGRESS;
+
+		break;
+
+	default:
+		return -EINVAL;
+		break;
+	}
+
+	return 0;
+}
+
+static DBusMessage *session_release(DBusConnection *connection,
+		DBusMessage *message, void *user_data)
+{
+	__connmanctl_save_rl();
+
+	fprintf(stdout, "Session %s released\n", session_path);
+
+	__connmanctl_redraw_rl();
+
+	g_free(session_path);
+	session_path = NULL;
+	session_connected = false;
+
+	return g_dbus_create_reply(message, DBUS_TYPE_INVALID);
+}
+
+static DBusMessage *session_update(DBusConnection *connection,
+		DBusMessage *message, void *user_data)
+{
+	DBusMessageIter iter, dict;
+
+	__connmanctl_save_rl();
+
+	fprintf(stdout, "Session      Update               = {\n");
+
+	dbus_message_iter_init(message, &iter);
+	dbus_message_iter_recurse(&iter, &dict);
+
+	__connmanctl_dbus_print(&dict, "", " = ", "\n");
+	fprintf(stdout, "\n}\n");
+
+	dbus_message_iter_recurse(&iter, &dict);
+
+	while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
+		DBusMessageIter entry, variant;
+		char *field, *state;
+
+		dbus_message_iter_recurse(&dict, &entry);
+
+		dbus_message_iter_get_basic(&entry, &field);
+
+		if (dbus_message_iter_get_arg_type(&entry)
+				== DBUS_TYPE_STRING
+				&& !strcmp(field, "State")) {
+
+			dbus_message_iter_next(&entry);
+			dbus_message_iter_recurse(&entry, &variant);
+			if (dbus_message_iter_get_arg_type(&variant)
+					!= DBUS_TYPE_STRING)
+				break;
+
+			dbus_message_iter_get_basic(&variant, &state);
+
+			if (!session_connected && (!strcmp(state, "connected")
+					|| !strcmp(state, "online"))) {
+
+				fprintf(stdout, "Session %s connected\n",
+					session_path);
+				session_connected = true;
+
+				break;
+			}
+
+			if (!strcmp(state, "disconnected") &&
+					session_connected) {
+
+				fprintf(stdout, "Session %s disconnected\n",
+					session_path);
+				session_connected = false;
+			}
+			break;
+		}
+
+		dbus_message_iter_next(&dict);
+	}
+
+	__connmanctl_redraw_rl();
+
+	return g_dbus_create_reply(message, DBUS_TYPE_INVALID);
+}
+
+static const GDBusMethodTable notification_methods[] = {
+	{ GDBUS_METHOD("Release", NULL, NULL, session_release) },
+	{ GDBUS_METHOD("Update", GDBUS_ARGS({"settings", "a{sv}"}),
+				NULL, session_update) },
+	{ },
+};
+
+static int session_notify_add(const char *path)
+{
+	if (session_notify_path)
+		return 0;
+
+	if (!g_dbus_register_interface(connection, path,
+					"net.connman.Notification",
+					notification_methods, NULL, NULL,
+					NULL, NULL)) {
+		fprintf(stderr, "Error: Failed to register VPN Agent "
+				"callbacks\n");
+		return -EIO;
+	}
+
+	session_notify_path = g_strdup(path);
+
+	return 0;
+}
+
+static void session_notify_remove(void)
+{
+	if (!session_notify_path)
+		return;
+
+	g_dbus_unregister_interface(connection, session_notify_path,
+			"net.connman.Notification");
+
+	g_free(session_notify_path);
+	session_notify_path = NULL;
+}
+
+static int session_connect_cb(DBusMessageIter *iter, const char *error,
+		void *user_data)
+{
+	if (error) {
+		fprintf(stderr, "Error: %s", error);
+		return 0;
+	}
+
+	return -EINPROGRESS;
+}
+
+
+static int session_connect(void)
+{
+	return __connmanctl_dbus_method_call(connection, "net.connman",
+			session_path, "net.connman.Session", "Connect",
+			session_connect_cb, NULL, NULL, NULL);
+}
+
+static int session_disconnect_cb(DBusMessageIter *iter, const char *error,
+		void *user_data)
+{
+	if (error)
+		fprintf(stderr, "Error: %s", error);
+
+	return 0;
+}
+
+static int session_disconnect(void)
+{
+	return __connmanctl_dbus_method_call(connection, "net.connman",
+			session_path, "net.connman.Session", "Disconnect",
+			session_disconnect_cb, NULL, NULL, NULL);
+}
+
+static int session_create_cb(DBusMessageIter *iter, const char *error,
+		void *user_data)
+{
+	gboolean connect = GPOINTER_TO_INT(user_data);
+	char *str;
+
+	if (error) {
+		fprintf(stderr, "Error creating session: %s", error);
+		session_notify_remove();
+		return 0;
+	}
+
+	if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_OBJECT_PATH) {
+		fprintf(stderr, "Error creating session: No session path\n");
+		return -EINVAL;
+	}
+
+	g_free(session_path);
+
+	dbus_message_iter_get_basic(iter, &str);
+	session_path = g_strdup(str);
+
+	fprintf(stdout, "Session %s created\n", session_path);
+
+	if (connect)
+		return session_connect();
+
+	return -EINPROGRESS;
+}
+
+static void session_create_append(DBusMessageIter *iter, void *user_data)
+{
+	const char *notify_path = user_data;
+
+	__connmanctl_dbus_append_dict(iter, NULL, NULL);
+
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH,
+			&notify_path);
+}
+
+static int session_create(gboolean connect)
+{
+	int res;
+	char *notify_path;
+
+	notify_path = g_strdup_printf("/net/connman/connmanctl%d", getpid());
+	session_notify_add(notify_path);
+
+	res = __connmanctl_dbus_method_call(connection, "net.connman", "/",
+			"net.connman.Manager", "CreateSession",
+			session_create_cb, GINT_TO_POINTER(connect),
+			session_create_append, notify_path);
+
+	g_free(notify_path);
+
+	if (res < 0 && res != -EINPROGRESS)
+		session_notify_remove();
+
+	return res;
+}
+
+static int session_destroy_cb(DBusMessageIter *iter, const char *error,
+		void *user_data)
+{
+	if (error) {
+		fprintf(stderr, "Error destroying session: %s", error);
+		return 0;
+	}
+
+	fprintf(stdout, "Session %s ended\n", session_path);
+
+	g_free(session_path);
+	session_path = NULL;
+	session_connected = false;
+
+	return 0;
+}
+
+static void session_destroy_append(DBusMessageIter *iter, void *user_data)
+{
+	const char *path = user_data;
+
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH, &path);
+}
+
+static int session_destroy(void)
+{
+	return __connmanctl_dbus_method_call(connection, "net.connman", "/",
+			"net.connman.Manager", "DestroySession",
+			session_destroy_cb, NULL,
+			session_destroy_append, session_path);
+}
+
+static int session_config_return(DBusMessageIter *iter, const char *error,
+		void *user_data)
+{
+	char *property_name = user_data;
+
+	if (error)
+		fprintf(stderr, "Error setting session %s: %s\n",
+				property_name, error);
+
+	return 0;
+}
+
+static void session_config_append_array(DBusMessageIter *iter,
+		void *user_data)
+{
+	struct config_append *append = user_data;
+	char **opts = append->opts;
+	int i = 1;
+
+	if (!opts)
+		return;
+
+	while (opts[i] && strncmp(opts[i], "--", 2) != 0) {
+		dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING,
+				&opts[i]);
+		i++;
+	}
+
+	append->values = i;
+}
+
+static int session_config(char *args[], int num,
+		struct connman_option *options)
+{
+	int index = 0, res = 0;
+	struct config_append append;
+	char c;
+
+	while (index < num && args[index]) {
+		append.opts = &args[index];
+		append.values = 0;
+
+		c = parse_args(args[index], options);
+
+		switch (c) {
+		case 'b':
+			res = __connmanctl_dbus_session_change_array(connection,
+					session_path, session_config_return,
+					"AllowedBearers", "AllowedBearers",
+					session_config_append_array, &append);
+			break;
+		case 't':
+			if (!args[index + 1]) {
+				res = -EINVAL;
+				break;
+			}
+
+			res = __connmanctl_dbus_session_change(connection,
+					session_path, session_config_return,
+					"ConnectionType", "ConnectionType",
+					DBUS_TYPE_STRING, &args[index + 1]);
+			append.values = 2;
+			break;
+
+		default:
+			res = -EINVAL;
+		}
+
+		if (res < 0 && res != -EINPROGRESS) {
+			printf("Error '%s': %s\n", args[index],
+					strerror(-res));
+			return 0;
+		}
+
+		index += append.values;
+	}
+
+	return 0;
+}
+
+static int cmd_session(char *args[], int num, struct connman_option *options)
+{
+	char *command;
+
+	if (num < 2)
+		return -EINVAL;
+
+	command = args[1];
+
+	switch(parse_boolean(command)) {
+	case 0:
+		if (!session_path)
+			return -EALREADY;
+		return session_destroy();
+
+	case 1:
+		if (session_path)
+			return -EALREADY;
+		return session_create(FALSE);
+
+	default:
+		if (!strcmp(command, "connect")) {
+			if (!session_path)
+				return session_create(TRUE);
+
+			return session_connect();
+
+		} else if (!strcmp(command, "disconnect")) {
+
+			if (!session_path) {
+				fprintf(stdout, "Session does not exist\n");
+				return 0;
+			}
+
+			return session_disconnect();
+		} else if (!strcmp(command, "config")) {
+			if (!session_path) {
+				fprintf(stdout, "Session does not exist\n");
+				return 0;
+			}
+
+			if (num == 2)
+				return -EINVAL;
+
+			return session_config(&args[2], num - 2, options);
+		}
+
+	}
+
+	return -EINVAL;
+}
+
+static int cmd_exit(char *args[], int num, struct connman_option *options)
+{
+	return 1;
+}
+
+static char *lookup_service(const char *text, int state)
+{
+	static int len = 0;
+	static GHashTableIter iter;
+	gpointer key, value;
+
+	if (state == 0) {
+		g_hash_table_iter_init(&iter, service_hash);
+		len = strlen(text);
+	}
+
+	while (g_hash_table_iter_next(&iter, &key, &value)) {
+		const char *service = key;
+		if (strncmp(text, service, len) == 0)
+			return strdup(service);
+	}
+
+	return NULL;
+}
+
+static char *lookup_service_arg(const char *text, int state)
+{
+	if (__connmanctl_input_calc_level() > 1) {
+		__connmanctl_input_lookup_end();
+		return NULL;
+	}
+
+	return lookup_service(text, state);
+}
+
+static char *lookup_peer(const char *text, int state)
+{
+	static GHashTableIter iter;
+	gpointer key, value;
+	static int len = 0;
+
+	if (state == 0) {
+		g_hash_table_iter_init(&iter, peer_hash);
+		len = strlen(text);
+	}
+
+	while (g_hash_table_iter_next(&iter, &key, &value)) {
+		const char *peer = key;
+		if (strncmp(text, peer, len) == 0)
+			return strdup(peer);
+	}
+
+	return NULL;
+}
+
+static char *lookup_peer_arg(const char *text, int state)
+{
+	if (__connmanctl_input_calc_level() > 1) {
+		__connmanctl_input_lookup_end();
+		return NULL;
+	}
+
+	return lookup_peer(text, state);
+}
+
+static char *lookup_technology(const char *text, int state)
+{
+	static int len = 0;
+	static GHashTableIter iter;
+	gpointer key, value;
+
+	if (state == 0) {
+		g_hash_table_iter_init(&iter, technology_hash);
+		len = strlen(text);
+	}
+
+	while (g_hash_table_iter_next(&iter, &key, &value)) {
+		const char *technology = key;
+		if (strncmp(text, technology, len) == 0)
+			return strdup(technology);
+	}
+
+	return NULL;
+}
+
+static char *lookup_technology_arg(const char *text, int state)
+{
+	if (__connmanctl_input_calc_level() > 1) {
+		__connmanctl_input_lookup_end();
+		return NULL;
+	}
+
+	return lookup_technology(text, state);
+}
+
+static char *lookup_technology_offline(const char *text, int state)
+{
+	static int len = 0;
+	static bool end = false;
+	char *str;
+
+	if (__connmanctl_input_calc_level() > 1) {
+		__connmanctl_input_lookup_end();
+		return NULL;
+	}
+
+	if (state == 0) {
+		len = strlen(text);
+		end = false;
+	}
+
+	if (end)
+		return NULL;
+
+	str = lookup_technology(text, state);
+	if (str)
+		return str;
+
+	end = true;
+
+	if (strncmp(text, "offline", len) == 0)
+		return strdup("offline");
+
+	return NULL;
+}
+
+static char *lookup_on_off(const char *text, int state)
+{
+	char *onoff[] = { "on", "off", NULL };
+	static int idx = 0;
+	static int len = 0;
+
+	char *str;
+
+	if (!state) {
+		idx = 0;
+		len = strlen(text);
+	}
+
+	while (onoff[idx]) {
+		str = onoff[idx];
+		idx++;
+
+		if (!strncmp(text, str, len))
+			return strdup(str);
+	}
+
+	return NULL;
+}
+
+static char *lookup_tether(const char *text, int state)
+{
+	int level;
+
+	level = __connmanctl_input_calc_level();
+	if (level < 2)
+		return lookup_technology(text, state);
+
+	if (level == 2)
+		return lookup_on_off(text, state);
+
+	__connmanctl_input_lookup_end();
+
+	return NULL;
+}
+
+static char *lookup_agent(const char *text, int state)
+{
+	if (__connmanctl_input_calc_level() > 1) {
+		__connmanctl_input_lookup_end();
+		return NULL;
+	}
+
+	return lookup_on_off(text, state);
+}
+
+static struct connman_option service_options[] = {
+	{"properties", 'p', "[<service>]      (obsolete)"},
+	{ NULL, }
+};
+
+static struct connman_option config_options[] = {
+	{"nameservers", 'n', "<dns1> [<dns2>] [<dns3>]"},
+	{"timeservers", 't', "<ntp1> [<ntp2>] [...]"},
+	{"domains", 'd', "<domain1> [<domain2>] [...]"},
+	{"ipv6", 'v', "off|auto [enable|disable|preferred]|\n"
+	              "\t\t\tmanual <address> <prefixlength> <gateway>"},
+	{"proxy", 'x', "direct|auto <URL>|manual <URL1> [<URL2>] [...]\n"
+	               "\t\t\t[exclude <exclude1> [<exclude2>] [...]]"},
+	{"autoconnect", 'a', "yes|no"},
+	{"ipv4", 'i', "off|dhcp|manual <address> <netmask> <gateway>"},
+	{"remove", 'r', "                 Remove service"},
+	{ NULL, }
+};
+
+static struct connman_option monitor_options[] = {
+	{"services", 's', "[off]            Monitor only services"},
+	{"tech", 'c', "[off]            Monitor only technologies"},
+	{"manager", 'm', "[off]            Monitor only manager interface"},
+	{"vpnmanager", 'M', "[off]            Monitor only VPN manager "
+	 "interface"},
+	{"vpnconnection", 'C', "[off]            Monitor only VPN "
+	 "connections" },
+	{ NULL, }
+};
+
+static struct connman_option session_options[] = {
+	{"bearers", 'b', "<technology1> [<technology2> [...]]"},
+	{"type", 't', "local|internet|any"},
+	{ NULL, }
+};
+
+static char *lookup_options(struct connman_option *options, const char *text,
+		int state)
+{
+	static int idx = 0;
+	static int len = 0;
+	const char *str;
+
+	if (state == 0) {
+		idx = 0;
+		len = strlen(text);
+	}
+
+	while (options[idx].name) {
+		str = options[idx].name;
+		idx++;
+
+		if (str && strncmp(text, str, len) == 0)
+			return strdup(str);
+	}
+
+	return NULL;
+}
+
+static char *lookup_monitor(const char *text, int state)
+{
+	int level;
+
+	level = __connmanctl_input_calc_level();
+
+	if (level < 2)
+		return lookup_options(monitor_options, text, state);
+
+	if (level == 2)
+		return lookup_on_off(text, state);
+
+	__connmanctl_input_lookup_end();
+	return NULL;
+}
+
+static char *lookup_config(const char *text, int state)
+{
+	if (__connmanctl_input_calc_level() < 2)
+		return lookup_service(text, state);
+
+	return lookup_options(config_options, text, state);
+}
+
+static char *lookup_session(const char *text, int state)
+{
+	return lookup_options(session_options, text, state);
+}
+
+static int peer_service_cb(DBusMessageIter *iter, const char *error,
+							void *user_data)
+{
+	bool registration = GPOINTER_TO_INT(user_data);
+
+	if (error)
+		fprintf(stderr, "Error %s peer service: %s\n",
+			registration ? "registering" : "unregistering", error);
+	else
+		fprintf(stdout, "Peer service %s\n",
+			registration ? "registered" : "unregistered");
+
+	return 0;
+}
+
+struct _peer_service {
+	unsigned char *bjr_query;
+	int bjr_query_len;
+	unsigned char *bjr_response;
+	int bjr_response_len;
+	unsigned char *wfd_ies;
+	int wfd_ies_len;
+	char *upnp_service;
+	int version;
+	int master;
+};
+
+static void append_dict_entry_fixed_array(DBusMessageIter *iter,
+			const char *property, void *value, int length)
+{
+	DBusMessageIter dict_entry, variant, array;
+
+	dbus_message_iter_open_container(iter, DBUS_TYPE_DICT_ENTRY,
+							NULL, &dict_entry);
+	dbus_message_iter_append_basic(&dict_entry, DBUS_TYPE_STRING,
+								&property);
+	dbus_message_iter_open_container(&dict_entry, DBUS_TYPE_VARIANT,
+			DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_BYTE_AS_STRING,
+			&variant);
+	dbus_message_iter_open_container(&variant, DBUS_TYPE_ARRAY,
+					DBUS_TYPE_BYTE_AS_STRING, &array);
+	dbus_message_iter_append_fixed_array(&array, DBUS_TYPE_BYTE,
+							value, length);
+	dbus_message_iter_close_container(&variant, &array);
+	dbus_message_iter_close_container(&dict_entry, &variant);
+	dbus_message_iter_close_container(iter, &dict_entry);
+}
+
+static void append_peer_service_dict(DBusMessageIter *iter, void *user_data)
+{
+	struct _peer_service *service = user_data;
+
+	if (service->bjr_query && service->bjr_response) {
+		append_dict_entry_fixed_array(iter, "BonjourQuery",
+			&service->bjr_query, service->bjr_query_len);
+		append_dict_entry_fixed_array(iter, "BonjourResponse",
+			&service->bjr_response, service->bjr_response_len);
+	} else if (service->upnp_service && service->version) {
+		__connmanctl_dbus_append_dict_entry(iter, "UpnpVersion",
+					DBUS_TYPE_INT32, &service->version);
+		__connmanctl_dbus_append_dict_entry(iter, "UpnpService",
+				DBUS_TYPE_STRING, &service->upnp_service);
+	} else if (service->wfd_ies) {
+		append_dict_entry_fixed_array(iter, "WiFiDisplayIEs",
+				&service->wfd_ies, service->wfd_ies_len);
+	}
+}
+
+static void peer_service_append(DBusMessageIter *iter, void *user_data)
+{
+	struct _peer_service *service = user_data;
+	dbus_bool_t master;
+
+	__connmanctl_dbus_append_dict(iter, append_peer_service_dict, service);
+
+	if (service->master < 0)
+		return;
+
+	master = service->master == 1 ? TRUE : FALSE;
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_BOOLEAN, &master);
+}
+
+static struct _peer_service *fill_in_peer_service(unsigned char *bjr_query,
+				int bjr_query_len, unsigned char *bjr_response,
+				int bjr_response_len, char *upnp_service,
+				int version, unsigned char *wfd_ies,
+				int wfd_ies_len)
+{
+	struct _peer_service *service;
+
+	service = dbus_malloc0(sizeof(*service));
+
+	if (bjr_query_len && bjr_response_len) {
+		service->bjr_query = dbus_malloc0(bjr_query_len);
+		memcpy(service->bjr_query, bjr_query, bjr_query_len);
+		service->bjr_query_len = bjr_query_len;
+
+		service->bjr_response = dbus_malloc0(bjr_response_len);
+		memcpy(service->bjr_response, bjr_response, bjr_response_len);
+		service->bjr_response_len = bjr_response_len;
+	} else if (upnp_service && version) {
+		service->upnp_service = strdup(upnp_service);
+		service->version = version;
+	} else if (wfd_ies && wfd_ies_len) {
+		service->wfd_ies = dbus_malloc0(wfd_ies_len);
+		memcpy(service->wfd_ies, wfd_ies, wfd_ies_len);
+		service->wfd_ies_len = wfd_ies_len;
+	} else {
+		dbus_free(service);
+		service = NULL;
+	}
+
+	return service;
+}
+
+static void free_peer_service(struct _peer_service *service)
+{
+	dbus_free(service->bjr_query);
+	dbus_free(service->bjr_response);
+	dbus_free(service->wfd_ies);
+	free(service->upnp_service);
+	dbus_free(service);
+}
+
+static int peer_service_register(unsigned char *bjr_query, int bjr_query_len,
+			unsigned char *bjr_response, int bjr_response_len,
+			char *upnp_service, int version,
+			unsigned char *wfd_ies, int wfd_ies_len, int master)
+{
+	struct _peer_service *service;
+	bool registration = true;
+	int ret;
+
+	service = fill_in_peer_service(bjr_query, bjr_query_len, bjr_response,
+				bjr_response_len, upnp_service, version,
+				wfd_ies, wfd_ies_len);
+	if (!service)
+		return -EINVAL;
+
+	service->master = master;
+
+	ret = __connmanctl_dbus_method_call(connection, "net.connman", "/",
+			"net.connman.Manager", "RegisterPeerService",
+			peer_service_cb, GINT_TO_POINTER(registration),
+			peer_service_append, service);
+
+	free_peer_service(service);
+
+	return ret;
+}
+
+static int peer_service_unregister(unsigned char *bjr_query, int bjr_query_len,
+			unsigned char *bjr_response, int bjr_response_len,
+			char *upnp_service, int version,
+			unsigned char *wfd_ies, int wfd_ies_len)
+{
+	struct _peer_service *service;
+	bool registration = false;
+	int ret;
+
+	service = fill_in_peer_service(bjr_query, bjr_query_len, bjr_response,
+				bjr_response_len, upnp_service, version,
+				wfd_ies, wfd_ies_len);
+	if (!service)
+		return -EINVAL;
+
+	service->master = -1;
+
+	ret = __connmanctl_dbus_method_call(connection, "net.connman", "/",
+			"net.connman.Manager", "UnregisterPeerService",
+			peer_service_cb, GINT_TO_POINTER(registration),
+			peer_service_append, service);
+
+	free_peer_service(service);
+
+	return ret;
+}
+
+static int parse_spec_array(char *command, unsigned char spec[1024])
+{
+	int length, pos, end;
+	char b[3] = {};
+	char *e;
+
+	end = strlen(command);
+	for (e = NULL, length = pos = 0; command[pos] != '\0'; length++) {
+		if (pos+2 > end)
+			return -EINVAL;
+
+		b[0] = command[pos];
+		b[1] = command[pos+1];
+
+		spec[length] = strtol(b, &e, 16);
+		if (e && *e != '\0')
+			return -EINVAL;
+
+		pos += 2;
+	}
+
+	return length;
+}
+
+static int cmd_peer_service(char *args[], int num,
+				struct connman_option *options)
+{
+	unsigned char bjr_query[1024] = {};
+	unsigned char bjr_response[1024] = {};
+	unsigned char wfd_ies[1024] = {};
+	char *upnp_service = NULL;
+	int bjr_query_len = 0, bjr_response_len = 0;
+	int version = 0, master = 0, wfd_ies_len = 0;
+	int limit;
+
+	if (num < 4)
+		return -EINVAL;
+
+	if (!strcmp(args[2], "wfd_ies")) {
+		wfd_ies_len = parse_spec_array(args[3], wfd_ies);
+		if (wfd_ies_len == -EINVAL)
+			return -EINVAL;
+		limit = 5;
+		goto master;
+	}
+
+	if (num < 6)
+		return -EINVAL;
+
+	limit = 7;
+	if (!strcmp(args[2], "bjr_query")) {
+		if (strcmp(args[4], "bjr_response"))
+			return -EINVAL;
+		bjr_query_len = parse_spec_array(args[3], bjr_query);
+		bjr_response_len = parse_spec_array(args[5], bjr_response);
+
+		if (bjr_query_len == -EINVAL || bjr_response_len == -EINVAL)
+			return -EINVAL;
+	} else if (!strcmp(args[2], "upnp_service")) {
+		char *e = NULL;
+
+		if (strcmp(args[4], "upnp_version"))
+			return -EINVAL;
+		upnp_service = args[3];
+		version = strtol(args[5], &e, 10);
+		if (*e != '\0')
+			return -EINVAL;
+	}
+
+master:
+	if (num == limit) {
+		master = parse_boolean(args[6]);
+		if (master < 0)
+			return -EINVAL;
+	}
+
+	if (!strcmp(args[1], "register")) {
+		return peer_service_register(bjr_query, bjr_query_len,
+				bjr_response, bjr_response_len, upnp_service,
+				version, wfd_ies, wfd_ies_len, master);
+	} else if (!strcmp(args[1], "unregister")) {
+		return peer_service_unregister(bjr_query, bjr_query_len,
+				bjr_response, bjr_response_len, upnp_service,
+				version, wfd_ies, wfd_ies_len);
+	}
+
+	return -EINVAL;
+}
+
+static const struct {
+        const char *cmd;
+	const char *argument;
+        struct connman_option *options;
+        int (*func) (char *args[], int num, struct connman_option *options);
+        const char *desc;
+	__connmanctl_lookup_cb cb;
+} cmd_table[] = {
+	{ "state",        NULL,           NULL,            cmd_state,
+	  "Shows if the system is online or offline", NULL },
+	{ "technologies", NULL,           NULL,            cmd_technologies,
+	  "Display technologies", NULL },
+	{ "enable",       "<technology>|offline", NULL,    cmd_enable,
+	  "Enables given technology or offline mode",
+	  lookup_technology_offline },
+	{ "disable",      "<technology>|offline", NULL,    cmd_disable,
+	  "Disables given technology or offline mode",
+	  lookup_technology_offline },
+	{ "tether", "<technology> on|off\n"
+	            "            wifi [on|off] <ssid> <passphrase> ",
+	                                  NULL,            cmd_tether,
+	  "Enable, disable tethering, set SSID and passphrase for wifi",
+	  lookup_tether },
+	{ "services",     "[<service>]",  service_options, cmd_services,
+	  "Display services", lookup_service_arg },
+	{ "peers",        "[peer]",       NULL,            cmd_peers,
+	  "Display peers", lookup_peer_arg },
+	{ "scan",         "<technology>", NULL,            cmd_scan,
+	  "Scans for new services for given technology",
+	  lookup_technology_arg },
+	{ "connect",      "<service/peer>", NULL,          cmd_connect,
+	  "Connect a given service or peer", lookup_service_arg },
+	{ "disconnect",   "<service/peer>", NULL,          cmd_disconnect,
+	  "Disconnect a given service or peer", lookup_service_arg },
+	{ "config",       "<service>",    config_options,  cmd_config,
+	  "Set service configuration options", lookup_config },
+	{ "monitor",      "[off]",        monitor_options, cmd_monitor,
+	  "Monitor signals from interfaces", lookup_monitor },
+	{ "agent", "on|off",              NULL,            cmd_agent,
+	  "Agent mode", lookup_agent },
+	{"vpnconnections", "[<connection>]", NULL,         cmd_vpnconnections,
+	 "Display VPN connections", NULL },
+	{ "vpnagent",     "on|off",     NULL,            cmd_vpnagent,
+	  "VPN Agent mode", lookup_agent },
+	{ "session",      "on|off|connect|disconnect|config", session_options,
+	  cmd_session, "Enable or disable a session", lookup_session },
+	{ "peer_service", "register|unregister <specs> <master>\n"
+			  "Where specs are:\n"
+			  "\tbjr_query <query> bjr_response <response>\n"
+			  "\tupnp_service <service> upnp_version <version>\n"
+			  "\twfd_ies <ies>\n", NULL,
+	  cmd_peer_service, "(Un)Register a Peer Service", NULL },
+	{ "help",         NULL,           NULL,            cmd_help,
+	  "Show help", NULL },
+	{ "exit",         NULL,           NULL,            cmd_exit,
+	  "Exit", NULL },
+	{ "quit",         NULL,           NULL,            cmd_exit,
+	  "Quit", NULL },
+	{  NULL, },
+};
+
+static int cmd_help(char *args[], int num, struct connman_option *options)
+{
+	bool interactive = __connmanctl_is_interactive();
+	int i, j;
+
+	if (interactive == false)
+		fprintf(stdout, "Usage: connmanctl [[command] [args]]\n");
+
+	for (i = 0; cmd_table[i].cmd; i++) {
+		const char *cmd = cmd_table[i].cmd;
+		const char *argument = cmd_table[i].argument;
+		const char *desc = cmd_table[i].desc;
+
+		printf("%-16s%-22s%s\n", cmd? cmd: "",
+				argument? argument: "",
+				desc? desc: "");
+
+		if (cmd_table[i].options) {
+			for (j = 0; cmd_table[i].options[j].name;
+			     j++) {
+				const char *options_desc =
+					cmd_table[i].options[j].desc ?
+					cmd_table[i].options[j].desc: "";
+
+				printf("   --%-16s%s\n",
+						cmd_table[i].options[j].name,
+						options_desc);
+			}
+		}
+	}
+
+	if (interactive == false)
+		fprintf(stdout, "\nNote: arguments and output are considered "
+				"EXPERIMENTAL for now.\n");
+
+	return 0;
+}
+
+__connmanctl_lookup_cb __connmanctl_get_lookup_func(const char *text)
+{
+	int i, cmdlen, textlen;
+
+	if (!text)
+		return NULL;
+
+	textlen = strlen(text);
+
+	for (i = 0; cmd_table[i].cmd; i++) {
+		cmdlen = strlen(cmd_table[i].cmd);
+
+		if (textlen > cmdlen && text[cmdlen] != ' ')
+			continue;
+
+		if (strncmp(cmd_table[i].cmd, text, cmdlen) == 0)
+			return cmd_table[i].cb;
+	}
+
+	return NULL;
+}
+
+int __connmanctl_commands(DBusConnection *dbus_conn, char *argv[], int argc)
+{
+	int i, result;
+
+	connection = dbus_conn;
+
+	for (i = 0; cmd_table[i].cmd; i++) {
+		if (g_strcmp0(cmd_table[i].cmd, argv[0]) == 0 &&
+				cmd_table[i].func) {
+			result = cmd_table[i].func(argv, argc,
+					cmd_table[i].options);
+			if (result < 0 && result != -EINPROGRESS)
+				fprintf(stderr, "Error '%s': %s\n", argv[0],
+						strerror(-result));
+			return result;
+		}
+	}
+
+	fprintf(stderr, "Error '%s': Unknown command\n", argv[0]);
+	return -EINVAL;
+}
+
+char *__connmanctl_lookup_command(const char *text, int state)
+{
+	static int i = 0;
+	static int len = 0;
+
+	if (state == 0) {
+		i = 0;
+		len = strlen(text);
+	}
+
+	while (cmd_table[i].cmd) {
+		const char *command = cmd_table[i].cmd;
+
+		i++;
+
+		if (strncmp(text, command, len) == 0)
+			return strdup(command);
+	}
+
+	return NULL;
+}
+
+static char *get_path(char *full_path)
+{
+	char *path;
+
+	path = strrchr(full_path, '/');
+	if (path && *path != '\0')
+		path++;
+	else
+		path = full_path;
+
+	return path;
+}
+
+static void add_service_id(const char *path)
+{
+	g_hash_table_replace(service_hash, g_strdup(path),
+			GINT_TO_POINTER(TRUE));
+}
+
+static void remove_service_id(const char *path)
+{
+	g_hash_table_remove(service_hash, path);
+}
+
+static void services_added(DBusMessageIter *iter)
+{
+	DBusMessageIter array;
+	char *path = NULL;
+
+	while (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_STRUCT) {
+
+		dbus_message_iter_recurse(iter, &array);
+		if (dbus_message_iter_get_arg_type(&array) !=
+						DBUS_TYPE_OBJECT_PATH)
+			return;
+
+		dbus_message_iter_get_basic(&array, &path);
+		add_service_id(get_path(path));
+
+		dbus_message_iter_next(iter);
+	}
+}
+
+static void update_services(DBusMessageIter *iter)
+{
+	DBusMessageIter array;
+	char *path;
+
+	if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_ARRAY)
+		return;
+
+	dbus_message_iter_recurse(iter, &array);
+	services_added(&array);
+
+	dbus_message_iter_next(iter);
+	if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_ARRAY)
+		return;
+
+	dbus_message_iter_recurse(iter, &array);
+	while (dbus_message_iter_get_arg_type(&array) ==
+						DBUS_TYPE_OBJECT_PATH) {
+		dbus_message_iter_get_basic(&array, &path);
+		remove_service_id(get_path(path));
+
+		dbus_message_iter_next(&array);
+	}
+}
+
+static int populate_service_hash(DBusMessageIter *iter, const char *error,
+				void *user_data)
+{
+	if (error) {
+		fprintf(stderr, "Error getting services: %s", error);
+		return 0;
+	}
+
+	update_services(iter);
+	return 0;
+}
+
+static void add_peer_id(const char *path)
+{
+	g_hash_table_replace(peer_hash, g_strdup(path),	GINT_TO_POINTER(TRUE));
+}
+
+static void remove_peer_id(const char *path)
+{
+	g_hash_table_remove(peer_hash, path);
+}
+
+static void peers_added(DBusMessageIter *iter)
+{
+	DBusMessageIter array;
+	char *path = NULL;
+
+	while (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_STRUCT) {
+
+		dbus_message_iter_recurse(iter, &array);
+		if (dbus_message_iter_get_arg_type(&array) !=
+						DBUS_TYPE_OBJECT_PATH)
+			return;
+
+		dbus_message_iter_get_basic(&array, &path);
+		add_peer_id(get_path(path));
+
+		dbus_message_iter_next(iter);
+	}
+}
+
+static void update_peers(DBusMessageIter *iter)
+{
+	DBusMessageIter array;
+	char *path;
+
+	if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_ARRAY)
+		return;
+
+	dbus_message_iter_recurse(iter, &array);
+	peers_added(&array);
+
+	dbus_message_iter_next(iter);
+	if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_ARRAY)
+		return;
+
+	dbus_message_iter_recurse(iter, &array);
+	while (dbus_message_iter_get_arg_type(&array) ==
+						DBUS_TYPE_OBJECT_PATH) {
+		dbus_message_iter_get_basic(&array, &path);
+		remove_peer_id(get_path(path));
+
+		dbus_message_iter_next(&array);
+	}
+}
+
+static int populate_peer_hash(DBusMessageIter *iter,
+					const char *error, void *user_data)
+{
+	if (error) {
+		fprintf(stderr, "Error getting peers: %s", error);
+		return 0;
+	}
+
+	update_peers(iter);
+	return 0;
+}
+
+static void add_technology_id(const char *path)
+{
+	g_hash_table_replace(technology_hash, g_strdup(path),
+			GINT_TO_POINTER(TRUE));
+}
+
+static void remove_technology_id(const char *path)
+{
+	g_hash_table_remove(technology_hash, path);
+}
+
+static void remove_technology(DBusMessageIter *iter)
+{
+	char *path = NULL;
+
+	if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_OBJECT_PATH)
+		return;
+
+	dbus_message_iter_get_basic(iter, &path);
+	remove_technology_id(get_path(path));
+}
+
+static void add_technology(DBusMessageIter *iter)
+{
+	char *path = NULL;
+
+	if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_OBJECT_PATH)
+		return;
+
+	dbus_message_iter_get_basic(iter, &path);
+	add_technology_id(get_path(path));
+}
+
+static void update_technologies(DBusMessageIter *iter)
+{
+	DBusMessageIter array;
+
+	if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_ARRAY)
+		return;
+
+	dbus_message_iter_recurse(iter, &array);
+
+	while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_STRUCT) {
+		DBusMessageIter object_path;
+
+		dbus_message_iter_recurse(&array, &object_path);
+
+		add_technology(&object_path);
+
+		dbus_message_iter_next(&array);
+	}
+}
+
+static int populate_technology_hash(DBusMessageIter *iter, const char *error,
+				void *user_data)
+{
+	if (error) {
+		fprintf(stderr, "Error getting technologies: %s", error);
+		return 0;
+	}
+
+	update_technologies(iter);
+
+	return 0;
+}
+
+static DBusHandlerResult monitor_completions_changed(
+		DBusConnection *connection,
+		DBusMessage *message, void *user_data)
+{
+	bool *enabled = user_data;
+	DBusMessageIter iter;
+	DBusHandlerResult handled;
+
+	if (*enabled)
+		handled = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+	else
+		handled = DBUS_HANDLER_RESULT_HANDLED;
+
+	if (dbus_message_is_signal(message, "net.connman.Manager",
+					"ServicesChanged")) {
+		dbus_message_iter_init(message, &iter);
+		update_services(&iter);
+		return handled;
+	}
+
+	if (dbus_message_is_signal(message, "net.connman.Manager",
+						"PeersChanged")) {
+		dbus_message_iter_init(message, &iter);
+		update_peers(&iter);
+		return handled;
+	}
+
+	if (dbus_message_is_signal(message, "net.connman.Manager",
+					"TechnologyAdded")) {
+		dbus_message_iter_init(message, &iter);
+		add_technology(&iter);
+		return handled;
+	}
+
+	if (dbus_message_is_signal(message, "net.connman.Manager",
+					"TechnologyRemoved")) {
+		dbus_message_iter_init(message, &iter);
+		remove_technology(&iter);
+		return handled;
+	}
+
+	if (!g_strcmp0(dbus_message_get_interface(message),
+					"net.connman.Manager"))
+		return handled;
+
+	return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+
+void __connmanctl_monitor_completions(DBusConnection *dbus_conn)
+{
+	bool *manager_enabled = NULL;
+	DBusError err;
+	int i;
+
+	for (i = 0; monitor[i].interface; i++) {
+		if (!strcmp(monitor[i].interface, "Manager")) {
+			manager_enabled = &monitor[i].enabled;
+			break;
+		}
+	}
+
+	if (!dbus_conn) {
+		g_hash_table_destroy(service_hash);
+		g_hash_table_destroy(technology_hash);
+
+		dbus_bus_remove_match(connection,
+			"type='signal',interface='net.connman.Manager'", NULL);
+		dbus_connection_remove_filter(connection,
+					monitor_completions_changed,
+					manager_enabled);
+		return;
+	}
+
+	connection = dbus_conn;
+
+	service_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
+								g_free, NULL);
+
+	peer_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
+								g_free, NULL);
+
+	technology_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
+								g_free, NULL);
+
+	__connmanctl_dbus_method_call(connection,
+				CONNMAN_SERVICE, CONNMAN_PATH,
+				"net.connman.Manager", "GetServices",
+				populate_service_hash, NULL, NULL, NULL);
+
+	__connmanctl_dbus_method_call(connection,
+				CONNMAN_SERVICE, CONNMAN_PATH,
+				"net.connman.Manager", "GetPeers",
+				populate_peer_hash, NULL, NULL, NULL);
+
+	__connmanctl_dbus_method_call(connection,
+				CONNMAN_SERVICE, CONNMAN_PATH,
+				"net.connman.Manager", "GetTechnologies",
+				populate_technology_hash, NULL, NULL, NULL);
+
+	dbus_connection_add_filter(connection,
+				monitor_completions_changed, manager_enabled,
+			NULL);
+
+	dbus_error_init(&err);
+	dbus_bus_add_match(connection,
+			"type='signal',interface='net.connman.Manager'", &err);
+
+	if (dbus_error_is_set(&err))
+		fprintf(stderr, "Error: %s\n", err.message);
+}
diff --git a/connman/client/commands.h b/connman/client/commands.h
new file mode 100644
index 0000000..d5d1bec
--- /dev/null
+++ b/connman/client/commands.h
@@ -0,0 +1,43 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2013  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 as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  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 __CONNMANCTL_COMMANDS_H
+#define __CONNMANCTL_COMMANDS_H
+
+#include <dbus/dbus.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef char *(*__connmanctl_lookup_cb)(const char *text, int state);
+
+int __connmanctl_commands(DBusConnection *connection, char *argv[], int argc);
+char *__connmanctl_lookup_command(const char *text, int state);
+void __connmanctl_monitor_completions(DBusConnection *dbus_conn);
+__connmanctl_lookup_cb __connmanctl_get_lookup_func(const char *text);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CONNMANCTL_COMMANDS_H */
diff --git a/connman/client/dbus_helpers.c b/connman/client/dbus_helpers.c
new file mode 100644
index 0000000..d905746
--- /dev/null
+++ b/connman/client/dbus_helpers.c
@@ -0,0 +1,456 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2013  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 as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  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
+ *
+ */
+
+#include <stdio.h>
+#include <errno.h>
+#include <glib.h>
+
+#include "input.h"
+#include "dbus_helpers.h"
+
+#define TIMEOUT         120000
+
+void __connmanctl_dbus_print(DBusMessageIter *iter, const char *pre,
+		const char *dict, const char *sep)
+{
+	int arg_type;
+	dbus_bool_t b;
+	unsigned char c;
+	dbus_uint16_t u16;
+	dbus_uint32_t u;
+	dbus_int32_t i;
+	double d;
+
+	char *str;
+	DBusMessageIter entry;
+
+	if (!pre)
+		pre = "";
+
+	while ((arg_type = dbus_message_iter_get_arg_type(iter))
+			!= DBUS_TYPE_INVALID) {
+
+		fprintf(stdout, "%s", pre);
+
+		switch (arg_type) {
+		case DBUS_TYPE_STRUCT:
+			fprintf(stdout, "{ ");
+			dbus_message_iter_recurse(iter, &entry);
+			__connmanctl_dbus_print(&entry, "", "=", " ");
+			fprintf(stdout, " }");
+			break;
+
+		case DBUS_TYPE_ARRAY:
+			fprintf(stdout, "[ ");
+
+			dbus_message_iter_recurse(iter, &entry);
+			__connmanctl_dbus_print(&entry, "", "=", ", ");
+
+			fprintf(stdout, " ]");
+			break;
+
+		case DBUS_TYPE_DICT_ENTRY:
+
+			dbus_message_iter_recurse(iter, &entry);
+			__connmanctl_dbus_print(&entry, "", dict, dict);
+			break;
+
+		case DBUS_TYPE_STRING:
+		case DBUS_TYPE_OBJECT_PATH:
+			dbus_message_iter_get_basic(iter, &str);
+			fprintf(stdout, "%s", str);
+			break;
+
+		case DBUS_TYPE_VARIANT:
+			dbus_message_iter_recurse(iter, &entry);
+			__connmanctl_dbus_print(&entry, pre, dict, sep);
+			break;
+
+		case DBUS_TYPE_BOOLEAN:
+			dbus_message_iter_get_basic(iter, &b);
+			if (!b)
+				fprintf(stdout, "False");
+			else
+				fprintf(stdout, "True");
+			break;
+
+		case DBUS_TYPE_BYTE:
+			dbus_message_iter_get_basic(iter, &c);
+			fprintf(stdout, "%d", c);
+			break;
+
+		case DBUS_TYPE_UINT16:
+			dbus_message_iter_get_basic(iter, &u16);
+			fprintf(stdout, "%u", u16);
+			break;
+
+		case DBUS_TYPE_UINT32:
+			dbus_message_iter_get_basic(iter, &u);
+			fprintf(stdout, "%d", u);
+			break;
+
+		case DBUS_TYPE_INT32:
+			dbus_message_iter_get_basic(iter, &i);
+			fprintf(stdout, "%d", i);
+			break;
+
+		case DBUS_TYPE_DOUBLE:
+			dbus_message_iter_get_basic(iter, &d);
+			fprintf(stdout, "%f", d);
+			break;
+
+		default:
+			fprintf(stdout, "<type %c>", arg_type);
+			break;
+		}
+
+		if (dbus_message_iter_has_next(iter))
+			fprintf(stdout, "%s", sep);
+
+		dbus_message_iter_next(iter);
+	}
+}
+
+struct dbus_callback {
+	connmanctl_dbus_method_return_func_t cb;
+	void *user_data;
+};
+
+static void dbus_method_reply(DBusPendingCall *call, void *user_data)
+{
+	struct dbus_callback *callback = user_data;
+	int res = 0;
+	DBusMessage *reply;
+	DBusMessageIter iter;
+
+	__connmanctl_save_rl();
+
+	reply = dbus_pending_call_steal_reply(call);
+	if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) {
+		DBusError err;
+
+		dbus_error_init(&err);
+		dbus_set_error_from_message(&err, reply);
+
+		callback->cb(NULL, err.message, callback->user_data);
+
+		dbus_error_free(&err);
+		goto end;
+	}
+
+	dbus_message_iter_init(reply, &iter);
+	res = callback->cb(&iter, NULL, callback->user_data);
+
+end:
+	__connmanctl_redraw_rl();
+	if (__connmanctl_is_interactive() == false && res != -EINPROGRESS)
+		__connmanctl_quit();
+
+	g_free(callback);
+	dbus_message_unref(reply);
+}
+
+static int send_method_call(DBusConnection *connection,
+		DBusMessage *message, connmanctl_dbus_method_return_func_t cb,
+		void *user_data)
+{
+	int res = -ENXIO;
+	DBusPendingCall *call;
+	struct dbus_callback *callback;
+
+	if (!dbus_connection_send_with_reply(connection, message, &call, TIMEOUT))
+		goto end;
+
+	if (!call)
+		goto end;
+
+	if (cb) {
+		callback = g_new0(struct dbus_callback, 1);
+		callback->cb = cb;
+		callback->user_data = user_data;
+		dbus_pending_call_set_notify(call, dbus_method_reply,
+				callback, NULL);
+		res = -EINPROGRESS;
+	}
+
+end:
+        dbus_message_unref(message);
+	return res;
+}
+
+static int append_variant(DBusMessageIter *iter, const char *property,
+		int type, void *value)
+{
+	DBusMessageIter variant;
+	char *type_str;
+
+	switch(type) {
+	case DBUS_TYPE_BOOLEAN:
+                type_str = DBUS_TYPE_BOOLEAN_AS_STRING;
+                break;
+        case DBUS_TYPE_BYTE:
+                type_str = DBUS_TYPE_BYTE_AS_STRING;
+                break;
+        case DBUS_TYPE_STRING:
+                type_str = DBUS_TYPE_STRING_AS_STRING;
+                break;
+	case DBUS_TYPE_INT32:
+		type_str = DBUS_TYPE_INT32_AS_STRING;
+		break;
+	default:
+		return -EOPNOTSUPP;
+	}
+
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &property);
+	dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT, type_str,
+			&variant);
+	dbus_message_iter_append_basic(&variant, type, value);
+	dbus_message_iter_close_container(iter, &variant);
+
+	return 0;
+}
+
+int __connmanctl_dbus_method_call(DBusConnection *connection,
+		const char *service, const char *path, const char *interface,
+		const char *method, connmanctl_dbus_method_return_func_t cb,
+		void *user_data, connmanctl_dbus_append_func_t append_func,
+		void *append_data)
+{
+	DBusMessage *message;
+	DBusMessageIter iter;
+
+	message = dbus_message_new_method_call(service, path, interface,
+			method);
+
+	if (!message)
+		return -ENOMEM;
+
+	if (append_func) {
+		dbus_message_iter_init_append(message, &iter);
+		append_func(&iter, append_data);
+	}
+
+	return send_method_call(connection, message, cb, user_data);
+}
+
+int __connmanctl_dbus_set_property(DBusConnection *connection,
+		const char *path, const char *interface,
+		connmanctl_dbus_method_return_func_t cb, void * user_data,
+		const char *property, int type, void *value)
+{
+	DBusMessage *message;
+	DBusMessageIter iter;
+
+	message = dbus_message_new_method_call("net.connman", path,
+			interface, "SetProperty");
+
+	if (!message)
+		return -ENOMEM;
+
+	dbus_message_iter_init_append(message, &iter);
+
+	if (append_variant(&iter, property, type, value) < 0) {
+		dbus_message_unref(message);
+		return -EINVAL;
+	}
+
+	return send_method_call(connection, message, cb, user_data);
+}
+
+void __connmanctl_dbus_append_dict(DBusMessageIter *iter,
+		connmanctl_dbus_append_func_t append_fn, void *append_data)
+{
+	DBusMessageIter dict;
+
+	dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY,
+                        DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+                        DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
+                        DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict);
+
+	if (append_fn)
+		append_fn(&dict, append_data);
+
+	dbus_message_iter_close_container(iter, &dict);
+}
+
+void __connmanctl_dbus_append_dict_entry(DBusMessageIter *iter,
+		const char *property, int type, void *value)
+{
+	DBusMessageIter dict_entry;
+
+	dbus_message_iter_open_container(iter, DBUS_TYPE_DICT_ENTRY, NULL,
+			&dict_entry);
+
+	append_variant(&dict_entry, property, type, value);
+
+	dbus_message_iter_close_container(iter, &dict_entry);
+}
+
+int __connmanctl_dbus_set_property_dict(DBusConnection *connection,
+		const char *path, const char *interface,
+		connmanctl_dbus_method_return_func_t cb, void *user_data,
+		const char *property, int type,
+		connmanctl_dbus_append_func_t append_fn,
+		void *append_user_data)
+{
+	DBusMessage *message;
+	DBusMessageIter iter, variant, dict;
+
+	message = dbus_message_new_method_call("net.connman", path,
+			interface, "SetProperty");
+
+	if (!message)
+		return -ENOMEM;
+
+	dbus_message_iter_init_append(message, &iter);
+	dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &property);
+	dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT,
+			DBUS_TYPE_ARRAY_AS_STRING
+				DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+					DBUS_TYPE_STRING_AS_STRING
+					DBUS_TYPE_VARIANT_AS_STRING
+				DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
+			&variant);
+
+	dbus_message_iter_open_container(&variant, DBUS_TYPE_ARRAY,
+			DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+				DBUS_TYPE_STRING_AS_STRING
+				DBUS_TYPE_VARIANT_AS_STRING
+			DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
+			&dict);
+
+	append_fn(&dict, append_user_data);
+
+	dbus_message_iter_close_container(&variant, &dict);
+	dbus_message_iter_close_container(&iter, &variant);
+
+	return send_method_call(connection, message, cb, user_data);
+}
+
+static void append_variant_array(DBusMessageIter *iter, const char *property,
+		connmanctl_dbus_append_func_t append_fn,
+		void *append_user_data)
+{
+	DBusMessageIter variant, array;
+
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &property);
+	dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
+			DBUS_TYPE_ARRAY_AS_STRING
+				DBUS_TYPE_STRING_AS_STRING,
+			&variant);
+
+	dbus_message_iter_open_container(&variant, DBUS_TYPE_ARRAY,
+			DBUS_TYPE_STRING_AS_STRING, &array);
+
+	append_fn(&array, append_user_data);
+
+	dbus_message_iter_close_container(&variant, &array);
+	dbus_message_iter_close_container(iter, &variant);
+}
+
+void __connmanctl_dbus_append_dict_string_array(DBusMessageIter *iter,
+		const char *property, connmanctl_dbus_append_func_t append_fn,
+		void *append_user_data)
+{
+	DBusMessageIter dict_entry;
+
+	dbus_message_iter_open_container(iter, DBUS_TYPE_DICT_ENTRY, NULL,
+			&dict_entry);
+
+	append_variant_array(&dict_entry, property, append_fn,
+			append_user_data);
+
+	dbus_message_iter_close_container(iter, &dict_entry);
+}
+
+int __connmanctl_dbus_set_property_array(DBusConnection *connection,
+		const char *path, const char *interface,
+		connmanctl_dbus_method_return_func_t cb, void *user_data,
+		const char *property, int type,
+		connmanctl_dbus_append_func_t append_fn,
+		void *append_user_data)
+{
+	DBusMessage *message;
+	DBusMessageIter iter;
+
+	if (type != DBUS_TYPE_STRING)
+		return -EOPNOTSUPP;
+
+	message = dbus_message_new_method_call("net.connman", path,
+			interface, "SetProperty");
+
+	if (!message)
+		return -ENOMEM;
+
+	dbus_message_iter_init_append(message, &iter);
+
+	append_variant_array(&iter, property, append_fn, append_user_data);
+
+	return send_method_call(connection, message, cb, user_data);
+}
+
+int __connmanctl_dbus_session_change(DBusConnection *connection,
+		const char *session_path,
+		connmanctl_dbus_method_return_func_t cb, void * user_data,
+		const char *property, int type, void *value)
+{
+	DBusMessage *message;
+	DBusMessageIter iter;
+
+	message = dbus_message_new_method_call("net.connman", session_path,
+			"net.connman.Session", "Change");
+
+	if (!message)
+		return -ENOMEM;
+
+	dbus_message_iter_init_append(message, &iter);
+
+	if (append_variant(&iter, property, type, value) < 0) {
+		dbus_message_unref(message);
+		return -EINVAL;
+	}
+
+	return send_method_call(connection, message, cb, user_data);
+}
+
+int __connmanctl_dbus_session_change_array(DBusConnection *connection,
+		const char *session_path,
+		connmanctl_dbus_method_return_func_t cb, void *user_data,
+		const char *property,
+		connmanctl_dbus_append_func_t append_fn,
+		void *append_user_data)
+{
+	DBusMessage *message;
+	DBusMessageIter iter;
+
+	message = dbus_message_new_method_call("net.connman", session_path,
+			"net.connman.Session", "Change");
+
+	if (!message)
+		return -ENOMEM;
+
+	dbus_message_iter_init_append(message, &iter);
+
+	append_variant_array(&iter, property, append_fn, append_user_data);
+
+	return send_method_call(connection, message, cb, user_data);
+}
diff --git a/connman/client/dbus_helpers.h b/connman/client/dbus_helpers.h
new file mode 100644
index 0000000..395808a
--- /dev/null
+++ b/connman/client/dbus_helpers.h
@@ -0,0 +1,96 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2013  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 as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  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 __CONNMANCTL_DBUS_HELPERS_H
+#define __CONNMANCTL_DBUS_HELPERS_H
+
+#include <dbus/dbus.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define CONNMAN_SERVICE   "net.connman"
+#define CONNMAN_PATH      "/"
+#define VPN_SERVICE       CONNMAN_SERVICE ".vpn"
+#define VPN_PATH          "/"
+
+void __connmanctl_dbus_print(DBusMessageIter *iter, const char *pre,
+		const char *dict, const char *sep);
+
+typedef int (*connmanctl_dbus_method_return_func_t)(DBusMessageIter *iter,
+		const char *error, void *user_data);
+
+typedef void (*connmanctl_dbus_append_func_t)(DBusMessageIter *iter,
+		void *user_data);
+
+int __connmanctl_dbus_method_call(DBusConnection *connection,
+		const char *service, const char *path, const char *interface,
+		const char *method, connmanctl_dbus_method_return_func_t cb,
+		void * user_data, connmanctl_dbus_append_func_t append_fn,
+		void *append_data);
+
+int __connmanctl_dbus_set_property(DBusConnection *connection,
+		const char *path, const char *interface,
+		connmanctl_dbus_method_return_func_t cb, void * user_data,
+		const char *property, int type, void *value);
+
+void __connmanctl_dbus_append_dict(DBusMessageIter *iter,
+		connmanctl_dbus_append_func_t append_fn, void *append_data);
+
+void __connmanctl_dbus_append_dict_entry(DBusMessageIter *iter,
+		const char *property, int type, void *value);
+
+int __connmanctl_dbus_set_property_dict(DBusConnection *connection,
+		const char *path, const char *interface,
+		connmanctl_dbus_method_return_func_t cb, void * user_data,
+		const char *property, int type,
+		connmanctl_dbus_append_func_t append_fn,
+		void *append_user_data);
+
+void __connmanctl_dbus_append_dict_string_array(DBusMessageIter *iter,
+		const char *property, connmanctl_dbus_append_func_t append_fn,
+		void *append_user_data);
+int __connmanctl_dbus_set_property_array(DBusConnection *connection,
+		const char *path, const char *interface,
+		connmanctl_dbus_method_return_func_t cb, void *user_data,
+		const char *property, int type,
+		connmanctl_dbus_append_func_t append_fn,
+		void *append_user_data);
+
+int __connmanctl_dbus_session_change(DBusConnection *connection,
+		const char *session_path,
+		connmanctl_dbus_method_return_func_t cb, void * user_data,
+		const char *property, int type, void *value);
+
+int __connmanctl_dbus_session_change_array(DBusConnection *connection,
+		const char *session_path,
+		connmanctl_dbus_method_return_func_t cb, void *user_data,
+		const char *property,
+		connmanctl_dbus_append_func_t append_fn,
+		void *append_user_data);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/connman/client/input.c b/connman/client/input.c
new file mode 100644
index 0000000..f0c4ab2
--- /dev/null
+++ b/connman/client/input.c
@@ -0,0 +1,295 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2012-2014  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 as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  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 <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <glib.h>
+#include <readline/readline.h>
+#include <readline/history.h>
+
+#include <gdbus.h>
+#include "input.h"
+#include "commands.h"
+
+static DBusConnection *connection;
+static GMainLoop *main_loop;
+static bool interactive = false;
+
+static bool save_input;
+static char *saved_line;
+static int saved_point;
+
+void __connmanctl_quit(void)
+{
+	if (main_loop)
+		g_main_loop_quit(main_loop);
+}
+
+bool __connmanctl_is_interactive(void)
+{
+	return interactive;
+}
+
+void __connmanctl_save_rl(void)
+{
+#if 0
+	save_input = !RL_ISSTATE(RL_STATE_DONE);
+
+	if (save_input) {
+		saved_point = rl_point;
+		saved_line = rl_copy_text(0, rl_end);
+		rl_save_prompt();
+		rl_replace_line("", 0);
+		rl_redisplay();
+	}
+#endif
+}
+
+void __connmanctl_redraw_rl(void)
+{
+#if 0
+	if (save_input) {
+		rl_restore_prompt();
+		rl_replace_line(saved_line, 0);
+		rl_point = saved_point;
+		rl_redisplay();
+		free(saved_line);
+	}
+
+	save_input = 0;
+#endif
+}
+
+static void rl_handler(char *input)
+{
+	char **args, **trim_args;
+	int num, len, err, i;
+
+	if (!input) {
+		rl_newline(1, '\n');
+		g_main_loop_quit(main_loop);
+		return;
+	}
+
+	args = g_strsplit(input, " ", 0);
+	num = g_strv_length(args);
+
+	trim_args = g_new0(char *, num + 1);
+	for (i = 0, len = 0; i < num; i++) {
+		if (*args[i] != '\0') {
+			trim_args[len] = args[i];
+			len++;
+		}
+	}
+
+	if (len > 0) {
+
+		add_history(input);
+
+		err = __connmanctl_commands(connection, trim_args, len);
+
+		if (err > 0)
+			g_main_loop_quit(main_loop);
+	}
+
+	rl_callback_handler_install("connmanctl> ", rl_handler);   
+
+	g_strfreev(args);
+	g_free(trim_args);
+}
+
+static gboolean input_handler(GIOChannel *channel, GIOCondition condition,
+		gpointer user_data)
+{
+	if (condition & (G_IO_HUP | G_IO_ERR | G_IO_NVAL)) {
+		g_main_loop_quit(main_loop);
+		return FALSE;
+	}
+
+	rl_callback_read_char();
+	return TRUE;
+}
+
+static char **complete_agent(const char *text, int start, int end)
+{
+	rl_attempted_completion_over = 1;
+
+	return NULL;
+}
+
+/* Return how many parameters we have typed */
+int __connmanctl_input_calc_level(void)
+{
+	int count = 0;
+	char *ptr;
+
+	ptr = rl_line_buffer;
+
+	while (*ptr) {
+		if (*ptr == ' ') {
+			if (*(ptr + 1) == ' ') {
+				ptr++;
+				continue;
+			} else
+				count++;
+		}
+		ptr++;
+	}
+
+	return count;
+}
+
+void __connmanctl_input_lookup_end(void)
+{
+	rl_attempted_completion_over = 1;
+}
+
+static char **complete_command(const char *text, int start, int end)
+{
+	if (start == 0) {
+		return rl_completion_matches(text,
+				__connmanctl_lookup_command);
+
+	} else {
+		__connmanctl_lookup_cb cb;
+		char **str = NULL;
+
+		cb = __connmanctl_get_lookup_func(rl_line_buffer);
+		if (cb)
+			str = rl_completion_matches(text, cb);
+		else
+			rl_attempted_completion_over = 1;
+
+		return str;
+	}
+}
+
+static struct {
+	connmanctl_input_func_t cb;
+	void *user_data;
+} agent_handler;
+
+static void rl_agent_handler(char *input)
+{
+	agent_handler.cb(input, agent_handler.user_data);
+}
+
+void __connmanctl_agent_mode(const char *prompt,
+		connmanctl_input_func_t input_handler, void *user_data)
+{
+	agent_handler.cb = input_handler;
+	agent_handler.user_data = user_data;
+
+	if (input_handler)
+		rl_callback_handler_install(prompt, rl_agent_handler);
+	else {
+		rl_set_prompt(prompt);
+		rl_callback_handler_remove();
+		rl_redisplay();
+	}
+	rl_attempted_completion_function = complete_agent;
+}
+
+void __connmanctl_command_mode(void)
+{
+	rl_callback_handler_install("connmanctl> ", rl_handler);
+	rl_attempted_completion_function = complete_command;
+}
+
+int __connmanctl_input_init(int argc, char *argv[])
+{
+	char *help[] = {
+		"help",
+		NULL
+	};
+	guint source = 0;
+	int err;
+	DBusError dbus_err;
+	GIOChannel *channel;
+
+	dbus_error_init(&dbus_err);
+	connection = g_dbus_setup_bus(DBUS_BUS_SYSTEM, NULL, &dbus_err);
+
+	if (dbus_error_is_set(&dbus_err)) {
+		fprintf(stderr, "Error: %s\n", dbus_err.message);
+		dbus_error_free(&dbus_err);
+		return 1;
+	}
+
+	if (argc < 2) {
+		interactive = true;
+
+		channel = g_io_channel_unix_new(fileno(stdin));
+		source = g_io_add_watch(channel,
+				G_IO_IN|G_IO_ERR|G_IO_HUP|G_IO_NVAL,
+				input_handler, NULL);
+		g_io_channel_unref(channel);
+
+		__connmanctl_monitor_completions(connection);
+
+		__connmanctl_command_mode();
+
+		err = -EINPROGRESS;
+	} else {
+		interactive = false;
+
+		if (strcmp(argv[1], "--help") == 0 ||
+				strcmp(argv[1], "-h") == 0)
+			err = __connmanctl_commands(connection, help, 1);
+		else
+			err = __connmanctl_commands(connection, argv + 1,
+					argc - 1);
+	}
+
+	if (err == -EINPROGRESS) {
+		main_loop = g_main_loop_new(NULL, FALSE);
+		g_main_loop_run(main_loop);
+
+		err = 0;
+	}
+
+	if (interactive) {
+		g_source_remove(source);
+		__connmanctl_monitor_completions(NULL);
+
+		rl_callback_handler_remove();
+#if 0
+		rl_message("");
+#endif
+	}
+
+	dbus_connection_unref(connection);
+	if (main_loop)
+		g_main_loop_unref(main_loop);
+
+	if (err < 0)
+		err = -err;
+	else
+		err = 0;
+
+	return err;
+}
diff --git a/connman/client/input.h b/connman/client/input.h
new file mode 100644
index 0000000..c7256a4
--- /dev/null
+++ b/connman/client/input.h
@@ -0,0 +1,48 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2012-2014  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 as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  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 __CONNMANCTL_INPUT_H
+#define __CONNMANCTL_INPUT_H
+
+#include <stdbool.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void __connmanctl_quit(void);
+bool __connmanctl_is_interactive(void);
+void __connmanctl_save_rl(void);
+void __connmanctl_redraw_rl(void);
+int __connmanctl_input_calc_level(void);
+void __connmanctl_input_lookup_end(void);
+typedef void (* connmanctl_input_func_t) (char *input, void *user_data);
+void __connmanctl_agent_mode(const char *prompt,
+		connmanctl_input_func_t input_handler, void *user_data);
+void __connmanctl_command_mode(void);
+int __connmanctl_input_init(int argc, char *argv[]);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CONNMANCTL_INPUT_H */
diff --git a/connman/client/main.c b/connman/client/main.c
new file mode 100644
index 0000000..6d3c57f
--- /dev/null
+++ b/connman/client/main.c
@@ -0,0 +1,28 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2012-2013  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 as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  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
+ *
+ */
+
+#include "input.h"
+
+int main(int argc, char *argv[])
+{
+	return __connmanctl_input_init(argc, argv);
+}
diff --git a/connman/client/peers.c b/connman/client/peers.c
new file mode 100644
index 0000000..bf1aa0e
--- /dev/null
+++ b/connman/client/peers.c
@@ -0,0 +1,122 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2014  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 as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  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 <stdio.h>
+#include <string.h>
+
+#include "peers.h"
+
+static void print_peer(char *path, DBusMessageIter *iter)
+{
+	char *name = "", *state = "";
+	char *str, *property;
+	DBusMessageIter entry, val;
+	int count = 0;
+
+	while (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) {
+		dbus_message_iter_recurse(iter, &entry);
+		dbus_message_iter_get_basic(&entry, &property);
+
+		if (strcmp(property, "Name") == 0) {
+			dbus_message_iter_next(&entry);
+			dbus_message_iter_recurse(&entry, &val);
+			dbus_message_iter_get_basic(&val, &name);
+		} else if (strcmp(property, "State") == 0) {
+			dbus_message_iter_next(&entry);
+			dbus_message_iter_recurse(&entry, &val);
+			dbus_message_iter_get_basic(&val, &state);
+		}
+
+		dbus_message_iter_next(iter);
+		count++;
+	}
+
+	str = strrchr(path, '/');
+	if (str)
+		str++;
+	else
+		str = path;
+
+	if (count > 0)
+		fprintf(stdout, "%s %s %s", name, state, str);
+	else
+		fprintf(stdout, "%s %s", "unchanged", str);
+}
+
+static void list_peer_array(DBusMessageIter *iter)
+{
+	DBusMessageIter array, dict;
+	char *path = NULL;
+
+	while (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_STRUCT) {
+		dbus_message_iter_recurse(iter, &array);
+		if (dbus_message_iter_get_arg_type(&array)
+				!= DBUS_TYPE_OBJECT_PATH)
+			return;
+
+		dbus_message_iter_get_basic(&array, &path);
+
+		dbus_message_iter_next(&array);
+		if (dbus_message_iter_get_arg_type(&array)
+						== DBUS_TYPE_ARRAY) {
+			dbus_message_iter_recurse(&array, &dict);
+			print_peer(path, &dict);
+		}
+
+		if (dbus_message_iter_has_next(iter))
+			fprintf(stdout, "\n");
+
+		dbus_message_iter_next(iter);
+	}
+}
+
+void __connmanctl_peers_list(DBusMessageIter *iter)
+{
+	DBusMessageIter array;
+	char *path;
+
+	if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_ARRAY)
+		return;
+
+	dbus_message_iter_recurse(iter, &array);
+	list_peer_array(&array);
+
+	dbus_message_iter_next(iter);
+	if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_ARRAY)
+		return;
+
+	fprintf(stdout, "\n}, {");
+
+	dbus_message_iter_recurse(iter, &array);
+	while (dbus_message_iter_get_arg_type(&array)
+					== DBUS_TYPE_OBJECT_PATH) {
+		dbus_message_iter_get_basic(&array, &path);
+		fprintf(stdout, "\n%s %s", "removed", path);
+
+		dbus_message_iter_next(&array);
+	}
+
+}
diff --git a/connman/client/peers.h b/connman/client/peers.h
new file mode 100644
index 0000000..fdf7ce7
--- /dev/null
+++ b/connman/client/peers.h
@@ -0,0 +1,38 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2014  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 as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  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 __CONNMANCTL_PEERS_H
+#define __CONNMANCTL_PEERS_H
+
+#include <dbus/dbus.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void __connmanctl_peers_list(DBusMessageIter *iter);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CONNMANCTL_PEERS_H */
diff --git a/connman/client/services.c b/connman/client/services.c
new file mode 100644
index 0000000..0c18669
--- /dev/null
+++ b/connman/client/services.c
@@ -0,0 +1,156 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2012-2013  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 as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  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 <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+
+#include <glib.h>
+
+#include "services.h"
+
+static void print_service(char *path, DBusMessageIter *iter)
+{
+	char *name = "", *str = NULL;
+	int autoconn = 0, favorite = 0, count = 0;
+	char *property;
+	char state = ' ';
+	DBusMessageIter entry, val;
+
+	while (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) {
+
+		dbus_message_iter_recurse(iter, &entry);
+		dbus_message_iter_get_basic(&entry, &property);
+		if (strcmp(property, "Name") == 0) {
+			dbus_message_iter_next(&entry);
+			dbus_message_iter_recurse(&entry, &val);
+			dbus_message_iter_get_basic(&val, &name);
+
+		} else if (strcmp(property, "State") == 0) {
+			dbus_message_iter_next(&entry);
+			dbus_message_iter_recurse(&entry, &val);
+			dbus_message_iter_get_basic(&val, &str);
+
+			if (str) {
+				if (strcmp(str, "online") == 0)
+					state = 'O';
+				else if (strcmp(str, "ready") == 0)
+					state = 'R';
+				else if (!strcmp(str, "association"))
+					state = 'a';
+				else if (!strcmp(str, "configuration"))
+					state = 'c';
+				else if (!strcmp(str, "disconnect"))
+					state = 'd';
+			}
+
+		} else if (strcmp(property, "AutoConnect") == 0) {
+			dbus_message_iter_next(&entry);
+			dbus_message_iter_recurse(&entry, &val);
+			dbus_message_iter_get_basic(&val, &autoconn);
+
+		} else if (strcmp(property, "Favorite") == 0) {
+			dbus_message_iter_next(&entry);
+			dbus_message_iter_recurse(&entry, &val);
+			dbus_message_iter_get_basic(&val, &favorite);
+		}
+
+		count++;
+		dbus_message_iter_next(iter);
+	}
+
+	str = strrchr(path, '/');
+	if (str)
+		str++;
+	else
+		str = path;
+
+	if (count > 0)
+		fprintf(stdout, "%c%c%c %-20s %s", favorite != 0 ? '*' : ' ',
+				autoconn != 0 ? 'A' : ' ', state, name, str);
+	else
+		fprintf(stdout, "%-24s %s", "unchanged", str);
+
+}
+
+static void list_service_array(DBusMessageIter *iter)
+{
+	DBusMessageIter array, dict;
+	char *path = NULL;
+
+	while (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_STRUCT) {
+
+		dbus_message_iter_recurse(iter, &array);
+		if (dbus_message_iter_get_arg_type(&array)
+				!= DBUS_TYPE_OBJECT_PATH)
+			return;
+
+		dbus_message_iter_get_basic(&array, &path);
+
+		dbus_message_iter_next(&array);
+		if (dbus_message_iter_get_arg_type(&array)
+				== DBUS_TYPE_ARRAY) {
+			dbus_message_iter_recurse(&array, &dict);
+			print_service(path, &dict);
+		}
+
+		if (dbus_message_iter_has_next(iter))
+			fprintf(stdout, "\n");
+
+		dbus_message_iter_next(iter);
+	}
+}
+
+void __connmanctl_services_list(DBusMessageIter *iter)
+{
+	DBusMessageIter array;
+	char *path;
+
+	if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_ARRAY)
+		return;
+
+	dbus_message_iter_recurse(iter, &array);
+	list_service_array(&array);
+
+	dbus_message_iter_next(iter);
+	if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_ARRAY)
+		return;
+
+	fprintf(stdout, "\n}, {");
+
+	dbus_message_iter_recurse(iter, &array);
+	while (dbus_message_iter_get_arg_type(&array)
+			== DBUS_TYPE_OBJECT_PATH) {
+		dbus_message_iter_get_basic(&array, &path);
+		fprintf(stdout, "\n%-24s %s", "removed", path);
+
+		dbus_message_iter_next(&array);
+	}
+
+}
diff --git a/connman/client/services.h b/connman/client/services.h
new file mode 100644
index 0000000..9b555fe
--- /dev/null
+++ b/connman/client/services.h
@@ -0,0 +1,38 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2012-2013  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 as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  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 __CONNMANCTL_SERVICES_H
+#define __CONNMANCTL_SERVICES_H
+
+#include <dbus/dbus.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void __connmanctl_services_list(DBusMessageIter *iter);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CONNMANCTL_SERVICES_H */
diff --git a/connman/client/vpnconnections.c b/connman/client/vpnconnections.c
new file mode 100644
index 0000000..d7bcbfe
--- /dev/null
+++ b/connman/client/vpnconnections.c
@@ -0,0 +1,111 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2013  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 as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  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 <stdio.h>
+#include <string.h>
+
+#include <glib.h>
+
+#include "vpnconnections.h"
+
+static void print_connection(char *path, DBusMessageIter *iter)
+{
+	char *name = "";
+	char state = ' ';
+	char *str;
+	char *property;
+	DBusMessageIter entry, val;
+
+	while (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) {
+
+		dbus_message_iter_recurse(iter, &entry);
+		dbus_message_iter_get_basic(&entry, &property);
+		if (strcmp(property, "Name") == 0) {
+			dbus_message_iter_next(&entry);
+			dbus_message_iter_recurse(&entry, &val);
+			dbus_message_iter_get_basic(&val, &name);
+
+		} else if (strcmp(property, "State") == 0) {
+			dbus_message_iter_next(&entry);
+			dbus_message_iter_recurse(&entry, &val);
+			dbus_message_iter_get_basic(&val, &str);
+
+			if (str) {
+				if (strcmp(str, "ready") == 0)
+					state = 'R';
+				else if (strcmp(str, "configuration") == 0)
+					state = 'C';
+				else if (strcmp(str, "failure") == 0)
+					state = 'F';
+			}
+		}
+
+		dbus_message_iter_next(iter);
+	}
+
+	str = strrchr(path, '/');
+	if (str)
+		str++;
+	else
+		str = path;
+
+	fprintf(stdout, "  %c %-20s %s", state, name, str);
+}
+
+void __connmanctl_vpnconnections_list(DBusMessageIter *iter)
+{
+	DBusMessageIter array, entry, dict;
+	char *path = NULL;
+
+	if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_ARRAY)
+		return;
+
+	dbus_message_iter_recurse(iter, &array);
+
+	while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_STRUCT) {
+
+		dbus_message_iter_recurse(&array, &entry);
+		if (dbus_message_iter_get_arg_type(&entry)
+				!= DBUS_TYPE_OBJECT_PATH)
+			return;
+
+		dbus_message_iter_get_basic(&entry, &path);
+
+		dbus_message_iter_next(&entry);
+		if (dbus_message_iter_get_arg_type(&entry)
+				== DBUS_TYPE_ARRAY) {
+			dbus_message_iter_recurse(&entry, &dict);
+			print_connection(path, &dict);
+		}
+
+		if (dbus_message_iter_has_next(&array))
+			fprintf(stdout, "\n");
+
+		dbus_message_iter_next(&array);
+	}
+
+	fprintf(stdout, "\n");
+}
diff --git a/connman/client/vpnconnections.h b/connman/client/vpnconnections.h
new file mode 100644
index 0000000..a915c84
--- /dev/null
+++ b/connman/client/vpnconnections.h
@@ -0,0 +1,38 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2013  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 as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  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 __CONNMANCTL_VPNCONNECTIONS_H
+#define __CONNMANCTL_VPNCONNECTIONS_H
+
+#include <dbus/dbus.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void __connmanctl_vpnconnections_list(DBusMessageIter *iter);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CONNMANCTL_VPNCONNECTIONS_H */
diff --git a/connman/compile b/connman/compile
new file mode 100755
index 0000000..531136b
--- /dev/null
+++ b/connman/compile
@@ -0,0 +1,347 @@
+#! /bin/sh
+# Wrapper for compilers which do not understand '-c -o'.
+
+scriptversion=2012-10-14.11; # UTC
+
+# Copyright (C) 1999-2013 Free Software Foundation, Inc.
+# Written by Tom Tromey <tromey@cygnus.com>.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# 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, see <http://www.gnu.org/licenses/>.
+
+# As a special exception to the GNU General Public License, if you
+# distribute this file as part of a program that contains a
+# configuration script generated by Autoconf, you may include it under
+# the same distribution terms that you use for the rest of that program.
+
+# This file is maintained in Automake, please report
+# bugs to <bug-automake@gnu.org> or send patches to
+# <automake-patches@gnu.org>.
+
+nl='
+'
+
+# We need space, tab and new line, in precisely that order.  Quoting is
+# there to prevent tools from complaining about whitespace usage.
+IFS=" ""	$nl"
+
+file_conv=
+
+# func_file_conv build_file lazy
+# Convert a $build file to $host form and store it in $file
+# Currently only supports Windows hosts. If the determined conversion
+# type is listed in (the comma separated) LAZY, no conversion will
+# take place.
+func_file_conv ()
+{
+  file=$1
+  case $file in
+    / | /[!/]*) # absolute file, and not a UNC file
+      if test -z "$file_conv"; then
+	# lazily determine how to convert abs files
+	case `uname -s` in
+	  MINGW*)
+	    file_conv=mingw
+	    ;;
+	  CYGWIN*)
+	    file_conv=cygwin
+	    ;;
+	  *)
+	    file_conv=wine
+	    ;;
+	esac
+      fi
+      case $file_conv/,$2, in
+	*,$file_conv,*)
+	  ;;
+	mingw/*)
+	  file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'`
+	  ;;
+	cygwin/*)
+	  file=`cygpath -m "$file" || echo "$file"`
+	  ;;
+	wine/*)
+	  file=`winepath -w "$file" || echo "$file"`
+	  ;;
+      esac
+      ;;
+  esac
+}
+
+# func_cl_dashL linkdir
+# Make cl look for libraries in LINKDIR
+func_cl_dashL ()
+{
+  func_file_conv "$1"
+  if test -z "$lib_path"; then
+    lib_path=$file
+  else
+    lib_path="$lib_path;$file"
+  fi
+  linker_opts="$linker_opts -LIBPATH:$file"
+}
+
+# func_cl_dashl library
+# Do a library search-path lookup for cl
+func_cl_dashl ()
+{
+  lib=$1
+  found=no
+  save_IFS=$IFS
+  IFS=';'
+  for dir in $lib_path $LIB
+  do
+    IFS=$save_IFS
+    if $shared && test -f "$dir/$lib.dll.lib"; then
+      found=yes
+      lib=$dir/$lib.dll.lib
+      break
+    fi
+    if test -f "$dir/$lib.lib"; then
+      found=yes
+      lib=$dir/$lib.lib
+      break
+    fi
+    if test -f "$dir/lib$lib.a"; then
+      found=yes
+      lib=$dir/lib$lib.a
+      break
+    fi
+  done
+  IFS=$save_IFS
+
+  if test "$found" != yes; then
+    lib=$lib.lib
+  fi
+}
+
+# func_cl_wrapper cl arg...
+# Adjust compile command to suit cl
+func_cl_wrapper ()
+{
+  # Assume a capable shell
+  lib_path=
+  shared=:
+  linker_opts=
+  for arg
+  do
+    if test -n "$eat"; then
+      eat=
+    else
+      case $1 in
+	-o)
+	  # configure might choose to run compile as 'compile cc -o foo foo.c'.
+	  eat=1
+	  case $2 in
+	    *.o | *.[oO][bB][jJ])
+	      func_file_conv "$2"
+	      set x "$@" -Fo"$file"
+	      shift
+	      ;;
+	    *)
+	      func_file_conv "$2"
+	      set x "$@" -Fe"$file"
+	      shift
+	      ;;
+	  esac
+	  ;;
+	-I)
+	  eat=1
+	  func_file_conv "$2" mingw
+	  set x "$@" -I"$file"
+	  shift
+	  ;;
+	-I*)
+	  func_file_conv "${1#-I}" mingw
+	  set x "$@" -I"$file"
+	  shift
+	  ;;
+	-l)
+	  eat=1
+	  func_cl_dashl "$2"
+	  set x "$@" "$lib"
+	  shift
+	  ;;
+	-l*)
+	  func_cl_dashl "${1#-l}"
+	  set x "$@" "$lib"
+	  shift
+	  ;;
+	-L)
+	  eat=1
+	  func_cl_dashL "$2"
+	  ;;
+	-L*)
+	  func_cl_dashL "${1#-L}"
+	  ;;
+	-static)
+	  shared=false
+	  ;;
+	-Wl,*)
+	  arg=${1#-Wl,}
+	  save_ifs="$IFS"; IFS=','
+	  for flag in $arg; do
+	    IFS="$save_ifs"
+	    linker_opts="$linker_opts $flag"
+	  done
+	  IFS="$save_ifs"
+	  ;;
+	-Xlinker)
+	  eat=1
+	  linker_opts="$linker_opts $2"
+	  ;;
+	-*)
+	  set x "$@" "$1"
+	  shift
+	  ;;
+	*.cc | *.CC | *.cxx | *.CXX | *.[cC]++)
+	  func_file_conv "$1"
+	  set x "$@" -Tp"$file"
+	  shift
+	  ;;
+	*.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO])
+	  func_file_conv "$1" mingw
+	  set x "$@" "$file"
+	  shift
+	  ;;
+	*)
+	  set x "$@" "$1"
+	  shift
+	  ;;
+      esac
+    fi
+    shift
+  done
+  if test -n "$linker_opts"; then
+    linker_opts="-link$linker_opts"
+  fi
+  exec "$@" $linker_opts
+  exit 1
+}
+
+eat=
+
+case $1 in
+  '')
+     echo "$0: No command.  Try '$0 --help' for more information." 1>&2
+     exit 1;
+     ;;
+  -h | --h*)
+    cat <<\EOF
+Usage: compile [--help] [--version] PROGRAM [ARGS]
+
+Wrapper for compilers which do not understand '-c -o'.
+Remove '-o dest.o' from ARGS, run PROGRAM with the remaining
+arguments, and rename the output as expected.
+
+If you are trying to build a whole package this is not the
+right script to run: please start by reading the file 'INSTALL'.
+
+Report bugs to <bug-automake@gnu.org>.
+EOF
+    exit $?
+    ;;
+  -v | --v*)
+    echo "compile $scriptversion"
+    exit $?
+    ;;
+  cl | *[/\\]cl | cl.exe | *[/\\]cl.exe )
+    func_cl_wrapper "$@"      # Doesn't return...
+    ;;
+esac
+
+ofile=
+cfile=
+
+for arg
+do
+  if test -n "$eat"; then
+    eat=
+  else
+    case $1 in
+      -o)
+	# configure might choose to run compile as 'compile cc -o foo foo.c'.
+	# So we strip '-o arg' only if arg is an object.
+	eat=1
+	case $2 in
+	  *.o | *.obj)
+	    ofile=$2
+	    ;;
+	  *)
+	    set x "$@" -o "$2"
+	    shift
+	    ;;
+	esac
+	;;
+      *.c)
+	cfile=$1
+	set x "$@" "$1"
+	shift
+	;;
+      *)
+	set x "$@" "$1"
+	shift
+	;;
+    esac
+  fi
+  shift
+done
+
+if test -z "$ofile" || test -z "$cfile"; then
+  # If no '-o' option was seen then we might have been invoked from a
+  # pattern rule where we don't need one.  That is ok -- this is a
+  # normal compilation that the losing compiler can handle.  If no
+  # '.c' file was seen then we are probably linking.  That is also
+  # ok.
+  exec "$@"
+fi
+
+# Name of file we expect compiler to create.
+cofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'`
+
+# Create the lock directory.
+# Note: use '[/\\:.-]' here to ensure that we don't use the same name
+# that we are using for the .o file.  Also, base the name on the expected
+# object file name, since that is what matters with a parallel build.
+lockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d
+while true; do
+  if mkdir "$lockdir" >/dev/null 2>&1; then
+    break
+  fi
+  sleep 1
+done
+# FIXME: race condition here if user kills between mkdir and trap.
+trap "rmdir '$lockdir'; exit 1" 1 2 15
+
+# Run the compile.
+"$@"
+ret=$?
+
+if test -f "$cofile"; then
+  test "$cofile" = "$ofile" || mv "$cofile" "$ofile"
+elif test -f "${cofile}bj"; then
+  test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile"
+fi
+
+rmdir "$lockdir"
+exit $ret
+
+# Local Variables:
+# mode: shell-script
+# sh-indentation: 2
+# eval: (add-hook 'write-file-hooks 'time-stamp)
+# time-stamp-start: "scriptversion="
+# time-stamp-format: "%:y-%02m-%02d.%02H"
+# time-stamp-time-zone: "UTC"
+# time-stamp-end: "; # UTC"
+# End:
diff --git a/connman/config.guess b/connman/config.guess
new file mode 100755
index 0000000..b79252d
--- /dev/null
+++ b/connman/config.guess
@@ -0,0 +1,1558 @@
+#! /bin/sh
+# Attempt to guess a canonical system name.
+#   Copyright 1992-2013 Free Software Foundation, Inc.
+
+timestamp='2013-06-10'
+
+# This file is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# 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, see <http://www.gnu.org/licenses/>.
+#
+# As a special exception to the GNU General Public License, if you
+# distribute this file as part of a program that contains a
+# configuration script generated by Autoconf, you may include it under
+# the same distribution terms that you use for the rest of that
+# program.  This Exception is an additional permission under section 7
+# of the GNU General Public License, version 3 ("GPLv3").
+#
+# Originally written by Per Bothner.
+#
+# You can get the latest version of this script from:
+# http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD
+#
+# Please send patches with a ChangeLog entry to config-patches@gnu.org.
+
+
+me=`echo "$0" | sed -e 's,.*/,,'`
+
+usage="\
+Usage: $0 [OPTION]
+
+Output the configuration name of the system \`$me' is run on.
+
+Operation modes:
+  -h, --help         print this help, then exit
+  -t, --time-stamp   print date of last modification, then exit
+  -v, --version      print version number, then exit
+
+Report bugs and patches to <config-patches@gnu.org>."
+
+version="\
+GNU config.guess ($timestamp)
+
+Originally written by Per Bothner.
+Copyright 1992-2013 Free Software Foundation, Inc.
+
+This is free software; see the source for copying conditions.  There is NO
+warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
+
+help="
+Try \`$me --help' for more information."
+
+# Parse command line
+while test $# -gt 0 ; do
+  case $1 in
+    --time-stamp | --time* | -t )
+       echo "$timestamp" ; exit ;;
+    --version | -v )
+       echo "$version" ; exit ;;
+    --help | --h* | -h )
+       echo "$usage"; exit ;;
+    -- )     # Stop option processing
+       shift; break ;;
+    - )	# Use stdin as input.
+       break ;;
+    -* )
+       echo "$me: invalid option $1$help" >&2
+       exit 1 ;;
+    * )
+       break ;;
+  esac
+done
+
+if test $# != 0; then
+  echo "$me: too many arguments$help" >&2
+  exit 1
+fi
+
+trap 'exit 1' 1 2 15
+
+# CC_FOR_BUILD -- compiler used by this script. Note that the use of a
+# compiler to aid in system detection is discouraged as it requires
+# temporary files to be created and, as you can see below, it is a
+# headache to deal with in a portable fashion.
+
+# Historically, `CC_FOR_BUILD' used to be named `HOST_CC'. We still
+# use `HOST_CC' if defined, but it is deprecated.
+
+# Portable tmp directory creation inspired by the Autoconf team.
+
+set_cc_for_build='
+trap "exitcode=\$?; (rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null) && exit \$exitcode" 0 ;
+trap "rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null; exit 1" 1 2 13 15 ;
+: ${TMPDIR=/tmp} ;
+ { tmp=`(umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } ||
+ { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir $tmp) ; } ||
+ { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir $tmp) && echo "Warning: creating insecure temp directory" >&2 ; } ||
+ { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } ;
+dummy=$tmp/dummy ;
+tmpfiles="$dummy.c $dummy.o $dummy.rel $dummy" ;
+case $CC_FOR_BUILD,$HOST_CC,$CC in
+ ,,)    echo "int x;" > $dummy.c ;
+	for c in cc gcc c89 c99 ; do
+	  if ($c -c -o $dummy.o $dummy.c) >/dev/null 2>&1 ; then
+	     CC_FOR_BUILD="$c"; break ;
+	  fi ;
+	done ;
+	if test x"$CC_FOR_BUILD" = x ; then
+	  CC_FOR_BUILD=no_compiler_found ;
+	fi
+	;;
+ ,,*)   CC_FOR_BUILD=$CC ;;
+ ,*,*)  CC_FOR_BUILD=$HOST_CC ;;
+esac ; set_cc_for_build= ;'
+
+# This is needed to find uname on a Pyramid OSx when run in the BSD universe.
+# (ghazi@noc.rutgers.edu 1994-08-24)
+if (test -f /.attbin/uname) >/dev/null 2>&1 ; then
+	PATH=$PATH:/.attbin ; export PATH
+fi
+
+UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown
+UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown
+UNAME_SYSTEM=`(uname -s) 2>/dev/null`  || UNAME_SYSTEM=unknown
+UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown
+
+case "${UNAME_SYSTEM}" in
+Linux|GNU|GNU/*)
+	# If the system lacks a compiler, then just pick glibc.
+	# We could probably try harder.
+	LIBC=gnu
+
+	eval $set_cc_for_build
+	cat <<-EOF > $dummy.c
+	#include <features.h>
+	#if defined(__UCLIBC__)
+	LIBC=uclibc
+	#elif defined(__dietlibc__)
+	LIBC=dietlibc
+	#else
+	LIBC=gnu
+	#endif
+	EOF
+	eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^LIBC'`
+	;;
+esac
+
+# Note: order is significant - the case branches are not exclusive.
+
+case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
+    *:NetBSD:*:*)
+	# NetBSD (nbsd) targets should (where applicable) match one or
+	# more of the tuples: *-*-netbsdelf*, *-*-netbsdaout*,
+	# *-*-netbsdecoff* and *-*-netbsd*.  For targets that recently
+	# switched to ELF, *-*-netbsd* would select the old
+	# object file format.  This provides both forward
+	# compatibility and a consistent mechanism for selecting the
+	# object file format.
+	#
+	# Note: NetBSD doesn't particularly care about the vendor
+	# portion of the name.  We always set it to "unknown".
+	sysctl="sysctl -n hw.machine_arch"
+	UNAME_MACHINE_ARCH=`(/sbin/$sysctl 2>/dev/null || \
+	    /usr/sbin/$sysctl 2>/dev/null || echo unknown)`
+	case "${UNAME_MACHINE_ARCH}" in
+	    armeb) machine=armeb-unknown ;;
+	    arm*) machine=arm-unknown ;;
+	    sh3el) machine=shl-unknown ;;
+	    sh3eb) machine=sh-unknown ;;
+	    sh5el) machine=sh5le-unknown ;;
+	    *) machine=${UNAME_MACHINE_ARCH}-unknown ;;
+	esac
+	# The Operating System including object format, if it has switched
+	# to ELF recently, or will in the future.
+	case "${UNAME_MACHINE_ARCH}" in
+	    arm*|i386|m68k|ns32k|sh3*|sparc|vax)
+		eval $set_cc_for_build
+		if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \
+			| grep -q __ELF__
+		then
+		    # Once all utilities can be ECOFF (netbsdecoff) or a.out (netbsdaout).
+		    # Return netbsd for either.  FIX?
+		    os=netbsd
+		else
+		    os=netbsdelf
+		fi
+		;;
+	    *)
+		os=netbsd
+		;;
+	esac
+	# The OS release
+	# Debian GNU/NetBSD machines have a different userland, and
+	# thus, need a distinct triplet. However, they do not need
+	# kernel version information, so it can be replaced with a
+	# suitable tag, in the style of linux-gnu.
+	case "${UNAME_VERSION}" in
+	    Debian*)
+		release='-gnu'
+		;;
+	    *)
+		release=`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'`
+		;;
+	esac
+	# Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM:
+	# contains redundant information, the shorter form:
+	# CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used.
+	echo "${machine}-${os}${release}"
+	exit ;;
+    *:Bitrig:*:*)
+	UNAME_MACHINE_ARCH=`arch | sed 's/Bitrig.//'`
+	echo ${UNAME_MACHINE_ARCH}-unknown-bitrig${UNAME_RELEASE}
+	exit ;;
+    *:OpenBSD:*:*)
+	UNAME_MACHINE_ARCH=`arch | sed 's/OpenBSD.//'`
+	echo ${UNAME_MACHINE_ARCH}-unknown-openbsd${UNAME_RELEASE}
+	exit ;;
+    *:ekkoBSD:*:*)
+	echo ${UNAME_MACHINE}-unknown-ekkobsd${UNAME_RELEASE}
+	exit ;;
+    *:SolidBSD:*:*)
+	echo ${UNAME_MACHINE}-unknown-solidbsd${UNAME_RELEASE}
+	exit ;;
+    macppc:MirBSD:*:*)
+	echo powerpc-unknown-mirbsd${UNAME_RELEASE}
+	exit ;;
+    *:MirBSD:*:*)
+	echo ${UNAME_MACHINE}-unknown-mirbsd${UNAME_RELEASE}
+	exit ;;
+    alpha:OSF1:*:*)
+	case $UNAME_RELEASE in
+	*4.0)
+		UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'`
+		;;
+	*5.*)
+		UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'`
+		;;
+	esac
+	# According to Compaq, /usr/sbin/psrinfo has been available on
+	# OSF/1 and Tru64 systems produced since 1995.  I hope that
+	# covers most systems running today.  This code pipes the CPU
+	# types through head -n 1, so we only detect the type of CPU 0.
+	ALPHA_CPU_TYPE=`/usr/sbin/psrinfo -v | sed -n -e 's/^  The alpha \(.*\) processor.*$/\1/p' | head -n 1`
+	case "$ALPHA_CPU_TYPE" in
+	    "EV4 (21064)")
+		UNAME_MACHINE="alpha" ;;
+	    "EV4.5 (21064)")
+		UNAME_MACHINE="alpha" ;;
+	    "LCA4 (21066/21068)")
+		UNAME_MACHINE="alpha" ;;
+	    "EV5 (21164)")
+		UNAME_MACHINE="alphaev5" ;;
+	    "EV5.6 (21164A)")
+		UNAME_MACHINE="alphaev56" ;;
+	    "EV5.6 (21164PC)")
+		UNAME_MACHINE="alphapca56" ;;
+	    "EV5.7 (21164PC)")
+		UNAME_MACHINE="alphapca57" ;;
+	    "EV6 (21264)")
+		UNAME_MACHINE="alphaev6" ;;
+	    "EV6.7 (21264A)")
+		UNAME_MACHINE="alphaev67" ;;
+	    "EV6.8CB (21264C)")
+		UNAME_MACHINE="alphaev68" ;;
+	    "EV6.8AL (21264B)")
+		UNAME_MACHINE="alphaev68" ;;
+	    "EV6.8CX (21264D)")
+		UNAME_MACHINE="alphaev68" ;;
+	    "EV6.9A (21264/EV69A)")
+		UNAME_MACHINE="alphaev69" ;;
+	    "EV7 (21364)")
+		UNAME_MACHINE="alphaev7" ;;
+	    "EV7.9 (21364A)")
+		UNAME_MACHINE="alphaev79" ;;
+	esac
+	# A Pn.n version is a patched version.
+	# A Vn.n version is a released version.
+	# A Tn.n version is a released field test version.
+	# A Xn.n version is an unreleased experimental baselevel.
+	# 1.2 uses "1.2" for uname -r.
+	echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[PVTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
+	# Reset EXIT trap before exiting to avoid spurious non-zero exit code.
+	exitcode=$?
+	trap '' 0
+	exit $exitcode ;;
+    Alpha\ *:Windows_NT*:*)
+	# How do we know it's Interix rather than the generic POSIX subsystem?
+	# Should we change UNAME_MACHINE based on the output of uname instead
+	# of the specific Alpha model?
+	echo alpha-pc-interix
+	exit ;;
+    21064:Windows_NT:50:3)
+	echo alpha-dec-winnt3.5
+	exit ;;
+    Amiga*:UNIX_System_V:4.0:*)
+	echo m68k-unknown-sysv4
+	exit ;;
+    *:[Aa]miga[Oo][Ss]:*:*)
+	echo ${UNAME_MACHINE}-unknown-amigaos
+	exit ;;
+    *:[Mm]orph[Oo][Ss]:*:*)
+	echo ${UNAME_MACHINE}-unknown-morphos
+	exit ;;
+    *:OS/390:*:*)
+	echo i370-ibm-openedition
+	exit ;;
+    *:z/VM:*:*)
+	echo s390-ibm-zvmoe
+	exit ;;
+    *:OS400:*:*)
+	echo powerpc-ibm-os400
+	exit ;;
+    arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*)
+	echo arm-acorn-riscix${UNAME_RELEASE}
+	exit ;;
+    arm*:riscos:*:*|arm*:RISCOS:*:*)
+	echo arm-unknown-riscos
+	exit ;;
+    SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*)
+	echo hppa1.1-hitachi-hiuxmpp
+	exit ;;
+    Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*)
+	# akee@wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE.
+	if test "`(/bin/universe) 2>/dev/null`" = att ; then
+		echo pyramid-pyramid-sysv3
+	else
+		echo pyramid-pyramid-bsd
+	fi
+	exit ;;
+    NILE*:*:*:dcosx)
+	echo pyramid-pyramid-svr4
+	exit ;;
+    DRS?6000:unix:4.0:6*)
+	echo sparc-icl-nx6
+	exit ;;
+    DRS?6000:UNIX_SV:4.2*:7* | DRS?6000:isis:4.2*:7*)
+	case `/usr/bin/uname -p` in
+	    sparc) echo sparc-icl-nx7; exit ;;
+	esac ;;
+    s390x:SunOS:*:*)
+	echo ${UNAME_MACHINE}-ibm-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
+	exit ;;
+    sun4H:SunOS:5.*:*)
+	echo sparc-hal-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
+	exit ;;
+    sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*)
+	echo sparc-sun-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
+	exit ;;
+    i86pc:AuroraUX:5.*:* | i86xen:AuroraUX:5.*:*)
+	echo i386-pc-auroraux${UNAME_RELEASE}
+	exit ;;
+    i86pc:SunOS:5.*:* | i86xen:SunOS:5.*:*)
+	eval $set_cc_for_build
+	SUN_ARCH="i386"
+	# If there is a compiler, see if it is configured for 64-bit objects.
+	# Note that the Sun cc does not turn __LP64__ into 1 like gcc does.
+	# This test works for both compilers.
+	if [ "$CC_FOR_BUILD" != 'no_compiler_found' ]; then
+	    if (echo '#ifdef __amd64'; echo IS_64BIT_ARCH; echo '#endif') | \
+		(CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \
+		grep IS_64BIT_ARCH >/dev/null
+	    then
+		SUN_ARCH="x86_64"
+	    fi
+	fi
+	echo ${SUN_ARCH}-pc-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
+	exit ;;
+    sun4*:SunOS:6*:*)
+	# According to config.sub, this is the proper way to canonicalize
+	# SunOS6.  Hard to guess exactly what SunOS6 will be like, but
+	# it's likely to be more like Solaris than SunOS4.
+	echo sparc-sun-solaris3`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
+	exit ;;
+    sun4*:SunOS:*:*)
+	case "`/usr/bin/arch -k`" in
+	    Series*|S4*)
+		UNAME_RELEASE=`uname -v`
+		;;
+	esac
+	# Japanese Language versions have a version number like `4.1.3-JL'.
+	echo sparc-sun-sunos`echo ${UNAME_RELEASE}|sed -e 's/-/_/'`
+	exit ;;
+    sun3*:SunOS:*:*)
+	echo m68k-sun-sunos${UNAME_RELEASE}
+	exit ;;
+    sun*:*:4.2BSD:*)
+	UNAME_RELEASE=`(sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null`
+	test "x${UNAME_RELEASE}" = "x" && UNAME_RELEASE=3
+	case "`/bin/arch`" in
+	    sun3)
+		echo m68k-sun-sunos${UNAME_RELEASE}
+		;;
+	    sun4)
+		echo sparc-sun-sunos${UNAME_RELEASE}
+		;;
+	esac
+	exit ;;
+    aushp:SunOS:*:*)
+	echo sparc-auspex-sunos${UNAME_RELEASE}
+	exit ;;
+    # The situation for MiNT is a little confusing.  The machine name
+    # can be virtually everything (everything which is not
+    # "atarist" or "atariste" at least should have a processor
+    # > m68000).  The system name ranges from "MiNT" over "FreeMiNT"
+    # to the lowercase version "mint" (or "freemint").  Finally
+    # the system name "TOS" denotes a system which is actually not
+    # MiNT.  But MiNT is downward compatible to TOS, so this should
+    # be no problem.
+    atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*)
+	echo m68k-atari-mint${UNAME_RELEASE}
+	exit ;;
+    atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*)
+	echo m68k-atari-mint${UNAME_RELEASE}
+	exit ;;
+    *falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*)
+	echo m68k-atari-mint${UNAME_RELEASE}
+	exit ;;
+    milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*)
+	echo m68k-milan-mint${UNAME_RELEASE}
+	exit ;;
+    hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*)
+	echo m68k-hades-mint${UNAME_RELEASE}
+	exit ;;
+    *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*)
+	echo m68k-unknown-mint${UNAME_RELEASE}
+	exit ;;
+    m68k:machten:*:*)
+	echo m68k-apple-machten${UNAME_RELEASE}
+	exit ;;
+    powerpc:machten:*:*)
+	echo powerpc-apple-machten${UNAME_RELEASE}
+	exit ;;
+    RISC*:Mach:*:*)
+	echo mips-dec-mach_bsd4.3
+	exit ;;
+    RISC*:ULTRIX:*:*)
+	echo mips-dec-ultrix${UNAME_RELEASE}
+	exit ;;
+    VAX*:ULTRIX*:*:*)
+	echo vax-dec-ultrix${UNAME_RELEASE}
+	exit ;;
+    2020:CLIX:*:* | 2430:CLIX:*:*)
+	echo clipper-intergraph-clix${UNAME_RELEASE}
+	exit ;;
+    mips:*:*:UMIPS | mips:*:*:RISCos)
+	eval $set_cc_for_build
+	sed 's/^	//' << EOF >$dummy.c
+#ifdef __cplusplus
+#include <stdio.h>  /* for printf() prototype */
+	int main (int argc, char *argv[]) {
+#else
+	int main (argc, argv) int argc; char *argv[]; {
+#endif
+	#if defined (host_mips) && defined (MIPSEB)
+	#if defined (SYSTYPE_SYSV)
+	  printf ("mips-mips-riscos%ssysv\n", argv[1]); exit (0);
+	#endif
+	#if defined (SYSTYPE_SVR4)
+	  printf ("mips-mips-riscos%ssvr4\n", argv[1]); exit (0);
+	#endif
+	#if defined (SYSTYPE_BSD43) || defined(SYSTYPE_BSD)
+	  printf ("mips-mips-riscos%sbsd\n", argv[1]); exit (0);
+	#endif
+	#endif
+	  exit (-1);
+	}
+EOF
+	$CC_FOR_BUILD -o $dummy $dummy.c &&
+	  dummyarg=`echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` &&
+	  SYSTEM_NAME=`$dummy $dummyarg` &&
+	    { echo "$SYSTEM_NAME"; exit; }
+	echo mips-mips-riscos${UNAME_RELEASE}
+	exit ;;
+    Motorola:PowerMAX_OS:*:*)
+	echo powerpc-motorola-powermax
+	exit ;;
+    Motorola:*:4.3:PL8-*)
+	echo powerpc-harris-powermax
+	exit ;;
+    Night_Hawk:*:*:PowerMAX_OS | Synergy:PowerMAX_OS:*:*)
+	echo powerpc-harris-powermax
+	exit ;;
+    Night_Hawk:Power_UNIX:*:*)
+	echo powerpc-harris-powerunix
+	exit ;;
+    m88k:CX/UX:7*:*)
+	echo m88k-harris-cxux7
+	exit ;;
+    m88k:*:4*:R4*)
+	echo m88k-motorola-sysv4
+	exit ;;
+    m88k:*:3*:R3*)
+	echo m88k-motorola-sysv3
+	exit ;;
+    AViiON:dgux:*:*)
+	# DG/UX returns AViiON for all architectures
+	UNAME_PROCESSOR=`/usr/bin/uname -p`
+	if [ $UNAME_PROCESSOR = mc88100 ] || [ $UNAME_PROCESSOR = mc88110 ]
+	then
+	    if [ ${TARGET_BINARY_INTERFACE}x = m88kdguxelfx ] || \
+	       [ ${TARGET_BINARY_INTERFACE}x = x ]
+	    then
+		echo m88k-dg-dgux${UNAME_RELEASE}
+	    else
+		echo m88k-dg-dguxbcs${UNAME_RELEASE}
+	    fi
+	else
+	    echo i586-dg-dgux${UNAME_RELEASE}
+	fi
+	exit ;;
+    M88*:DolphinOS:*:*)	# DolphinOS (SVR3)
+	echo m88k-dolphin-sysv3
+	exit ;;
+    M88*:*:R3*:*)
+	# Delta 88k system running SVR3
+	echo m88k-motorola-sysv3
+	exit ;;
+    XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3)
+	echo m88k-tektronix-sysv3
+	exit ;;
+    Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD)
+	echo m68k-tektronix-bsd
+	exit ;;
+    *:IRIX*:*:*)
+	echo mips-sgi-irix`echo ${UNAME_RELEASE}|sed -e 's/-/_/g'`
+	exit ;;
+    ????????:AIX?:[12].1:2)   # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX.
+	echo romp-ibm-aix     # uname -m gives an 8 hex-code CPU id
+	exit ;;               # Note that: echo "'`uname -s`'" gives 'AIX '
+    i*86:AIX:*:*)
+	echo i386-ibm-aix
+	exit ;;
+    ia64:AIX:*:*)
+	if [ -x /usr/bin/oslevel ] ; then
+		IBM_REV=`/usr/bin/oslevel`
+	else
+		IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE}
+	fi
+	echo ${UNAME_MACHINE}-ibm-aix${IBM_REV}
+	exit ;;
+    *:AIX:2:3)
+	if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then
+		eval $set_cc_for_build
+		sed 's/^		//' << EOF >$dummy.c
+		#include <sys/systemcfg.h>
+
+		main()
+			{
+			if (!__power_pc())
+				exit(1);
+			puts("powerpc-ibm-aix3.2.5");
+			exit(0);
+			}
+EOF
+		if $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy`
+		then
+			echo "$SYSTEM_NAME"
+		else
+			echo rs6000-ibm-aix3.2.5
+		fi
+	elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then
+		echo rs6000-ibm-aix3.2.4
+	else
+		echo rs6000-ibm-aix3.2
+	fi
+	exit ;;
+    *:AIX:*:[4567])
+	IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'`
+	if /usr/sbin/lsattr -El ${IBM_CPU_ID} | grep ' POWER' >/dev/null 2>&1; then
+		IBM_ARCH=rs6000
+	else
+		IBM_ARCH=powerpc
+	fi
+	if [ -x /usr/bin/oslevel ] ; then
+		IBM_REV=`/usr/bin/oslevel`
+	else
+		IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE}
+	fi
+	echo ${IBM_ARCH}-ibm-aix${IBM_REV}
+	exit ;;
+    *:AIX:*:*)
+	echo rs6000-ibm-aix
+	exit ;;
+    ibmrt:4.4BSD:*|romp-ibm:BSD:*)
+	echo romp-ibm-bsd4.4
+	exit ;;
+    ibmrt:*BSD:*|romp-ibm:BSD:*)            # covers RT/PC BSD and
+	echo romp-ibm-bsd${UNAME_RELEASE}   # 4.3 with uname added to
+	exit ;;                             # report: romp-ibm BSD 4.3
+    *:BOSX:*:*)
+	echo rs6000-bull-bosx
+	exit ;;
+    DPX/2?00:B.O.S.:*:*)
+	echo m68k-bull-sysv3
+	exit ;;
+    9000/[34]??:4.3bsd:1.*:*)
+	echo m68k-hp-bsd
+	exit ;;
+    hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*)
+	echo m68k-hp-bsd4.4
+	exit ;;
+    9000/[34678]??:HP-UX:*:*)
+	HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'`
+	case "${UNAME_MACHINE}" in
+	    9000/31? )            HP_ARCH=m68000 ;;
+	    9000/[34]?? )         HP_ARCH=m68k ;;
+	    9000/[678][0-9][0-9])
+		if [ -x /usr/bin/getconf ]; then
+		    sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null`
+		    sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null`
+		    case "${sc_cpu_version}" in
+		      523) HP_ARCH="hppa1.0" ;; # CPU_PA_RISC1_0
+		      528) HP_ARCH="hppa1.1" ;; # CPU_PA_RISC1_1
+		      532)                      # CPU_PA_RISC2_0
+			case "${sc_kernel_bits}" in
+			  32) HP_ARCH="hppa2.0n" ;;
+			  64) HP_ARCH="hppa2.0w" ;;
+			  '') HP_ARCH="hppa2.0" ;;   # HP-UX 10.20
+			esac ;;
+		    esac
+		fi
+		if [ "${HP_ARCH}" = "" ]; then
+		    eval $set_cc_for_build
+		    sed 's/^		//' << EOF >$dummy.c
+
+		#define _HPUX_SOURCE
+		#include <stdlib.h>
+		#include <unistd.h>
+
+		int main ()
+		{
+		#if defined(_SC_KERNEL_BITS)
+		    long bits = sysconf(_SC_KERNEL_BITS);
+		#endif
+		    long cpu  = sysconf (_SC_CPU_VERSION);
+
+		    switch (cpu)
+			{
+			case CPU_PA_RISC1_0: puts ("hppa1.0"); break;
+			case CPU_PA_RISC1_1: puts ("hppa1.1"); break;
+			case CPU_PA_RISC2_0:
+		#if defined(_SC_KERNEL_BITS)
+			    switch (bits)
+				{
+				case 64: puts ("hppa2.0w"); break;
+				case 32: puts ("hppa2.0n"); break;
+				default: puts ("hppa2.0"); break;
+				} break;
+		#else  /* !defined(_SC_KERNEL_BITS) */
+			    puts ("hppa2.0"); break;
+		#endif
+			default: puts ("hppa1.0"); break;
+			}
+		    exit (0);
+		}
+EOF
+		    (CCOPTS= $CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null) && HP_ARCH=`$dummy`
+		    test -z "$HP_ARCH" && HP_ARCH=hppa
+		fi ;;
+	esac
+	if [ ${HP_ARCH} = "hppa2.0w" ]
+	then
+	    eval $set_cc_for_build
+
+	    # hppa2.0w-hp-hpux* has a 64-bit kernel and a compiler generating
+	    # 32-bit code.  hppa64-hp-hpux* has the same kernel and a compiler
+	    # generating 64-bit code.  GNU and HP use different nomenclature:
+	    #
+	    # $ CC_FOR_BUILD=cc ./config.guess
+	    # => hppa2.0w-hp-hpux11.23
+	    # $ CC_FOR_BUILD="cc +DA2.0w" ./config.guess
+	    # => hppa64-hp-hpux11.23
+
+	    if echo __LP64__ | (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) |
+		grep -q __LP64__
+	    then
+		HP_ARCH="hppa2.0w"
+	    else
+		HP_ARCH="hppa64"
+	    fi
+	fi
+	echo ${HP_ARCH}-hp-hpux${HPUX_REV}
+	exit ;;
+    ia64:HP-UX:*:*)
+	HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'`
+	echo ia64-hp-hpux${HPUX_REV}
+	exit ;;
+    3050*:HI-UX:*:*)
+	eval $set_cc_for_build
+	sed 's/^	//' << EOF >$dummy.c
+	#include <unistd.h>
+	int
+	main ()
+	{
+	  long cpu = sysconf (_SC_CPU_VERSION);
+	  /* The order matters, because CPU_IS_HP_MC68K erroneously returns
+	     true for CPU_PA_RISC1_0.  CPU_IS_PA_RISC returns correct
+	     results, however.  */
+	  if (CPU_IS_PA_RISC (cpu))
+	    {
+	      switch (cpu)
+		{
+		  case CPU_PA_RISC1_0: puts ("hppa1.0-hitachi-hiuxwe2"); break;
+		  case CPU_PA_RISC1_1: puts ("hppa1.1-hitachi-hiuxwe2"); break;
+		  case CPU_PA_RISC2_0: puts ("hppa2.0-hitachi-hiuxwe2"); break;
+		  default: puts ("hppa-hitachi-hiuxwe2"); break;
+		}
+	    }
+	  else if (CPU_IS_HP_MC68K (cpu))
+	    puts ("m68k-hitachi-hiuxwe2");
+	  else puts ("unknown-hitachi-hiuxwe2");
+	  exit (0);
+	}
+EOF
+	$CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` &&
+		{ echo "$SYSTEM_NAME"; exit; }
+	echo unknown-hitachi-hiuxwe2
+	exit ;;
+    9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:* )
+	echo hppa1.1-hp-bsd
+	exit ;;
+    9000/8??:4.3bsd:*:*)
+	echo hppa1.0-hp-bsd
+	exit ;;
+    *9??*:MPE/iX:*:* | *3000*:MPE/iX:*:*)
+	echo hppa1.0-hp-mpeix
+	exit ;;
+    hp7??:OSF1:*:* | hp8?[79]:OSF1:*:* )
+	echo hppa1.1-hp-osf
+	exit ;;
+    hp8??:OSF1:*:*)
+	echo hppa1.0-hp-osf
+	exit ;;
+    i*86:OSF1:*:*)
+	if [ -x /usr/sbin/sysversion ] ; then
+	    echo ${UNAME_MACHINE}-unknown-osf1mk
+	else
+	    echo ${UNAME_MACHINE}-unknown-osf1
+	fi
+	exit ;;
+    parisc*:Lites*:*:*)
+	echo hppa1.1-hp-lites
+	exit ;;
+    C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*)
+	echo c1-convex-bsd
+	exit ;;
+    C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*)
+	if getsysinfo -f scalar_acc
+	then echo c32-convex-bsd
+	else echo c2-convex-bsd
+	fi
+	exit ;;
+    C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*)
+	echo c34-convex-bsd
+	exit ;;
+    C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*)
+	echo c38-convex-bsd
+	exit ;;
+    C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*)
+	echo c4-convex-bsd
+	exit ;;
+    CRAY*Y-MP:*:*:*)
+	echo ymp-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
+	exit ;;
+    CRAY*[A-Z]90:*:*:*)
+	echo ${UNAME_MACHINE}-cray-unicos${UNAME_RELEASE} \
+	| sed -e 's/CRAY.*\([A-Z]90\)/\1/' \
+	      -e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ \
+	      -e 's/\.[^.]*$/.X/'
+	exit ;;
+    CRAY*TS:*:*:*)
+	echo t90-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
+	exit ;;
+    CRAY*T3E:*:*:*)
+	echo alphaev5-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
+	exit ;;
+    CRAY*SV1:*:*:*)
+	echo sv1-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
+	exit ;;
+    *:UNICOS/mp:*:*)
+	echo craynv-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
+	exit ;;
+    F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*)
+	FUJITSU_PROC=`uname -m | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
+	FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'`
+	FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'`
+	echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
+	exit ;;
+    5000:UNIX_System_V:4.*:*)
+	FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'`
+	FUJITSU_REL=`echo ${UNAME_RELEASE} | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/ /_/'`
+	echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
+	exit ;;
+    i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*)
+	echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE}
+	exit ;;
+    sparc*:BSD/OS:*:*)
+	echo sparc-unknown-bsdi${UNAME_RELEASE}
+	exit ;;
+    *:BSD/OS:*:*)
+	echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE}
+	exit ;;
+    *:FreeBSD:*:*)
+	UNAME_PROCESSOR=`/usr/bin/uname -p`
+	case ${UNAME_PROCESSOR} in
+	    amd64)
+		echo x86_64-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
+	    *)
+		echo ${UNAME_PROCESSOR}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
+	esac
+	exit ;;
+    i*:CYGWIN*:*)
+	echo ${UNAME_MACHINE}-pc-cygwin
+	exit ;;
+    *:MINGW64*:*)
+	echo ${UNAME_MACHINE}-pc-mingw64
+	exit ;;
+    *:MINGW*:*)
+	echo ${UNAME_MACHINE}-pc-mingw32
+	exit ;;
+    i*:MSYS*:*)
+	echo ${UNAME_MACHINE}-pc-msys
+	exit ;;
+    i*:windows32*:*)
+	# uname -m includes "-pc" on this system.
+	echo ${UNAME_MACHINE}-mingw32
+	exit ;;
+    i*:PW*:*)
+	echo ${UNAME_MACHINE}-pc-pw32
+	exit ;;
+    *:Interix*:*)
+	case ${UNAME_MACHINE} in
+	    x86)
+		echo i586-pc-interix${UNAME_RELEASE}
+		exit ;;
+	    authenticamd | genuineintel | EM64T)
+		echo x86_64-unknown-interix${UNAME_RELEASE}
+		exit ;;
+	    IA64)
+		echo ia64-unknown-interix${UNAME_RELEASE}
+		exit ;;
+	esac ;;
+    [345]86:Windows_95:* | [345]86:Windows_98:* | [345]86:Windows_NT:*)
+	echo i${UNAME_MACHINE}-pc-mks
+	exit ;;
+    8664:Windows_NT:*)
+	echo x86_64-pc-mks
+	exit ;;
+    i*:Windows_NT*:* | Pentium*:Windows_NT*:*)
+	# How do we know it's Interix rather than the generic POSIX subsystem?
+	# It also conflicts with pre-2.0 versions of AT&T UWIN. Should we
+	# UNAME_MACHINE based on the output of uname instead of i386?
+	echo i586-pc-interix
+	exit ;;
+    i*:UWIN*:*)
+	echo ${UNAME_MACHINE}-pc-uwin
+	exit ;;
+    amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*)
+	echo x86_64-unknown-cygwin
+	exit ;;
+    p*:CYGWIN*:*)
+	echo powerpcle-unknown-cygwin
+	exit ;;
+    prep*:SunOS:5.*:*)
+	echo powerpcle-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
+	exit ;;
+    *:GNU:*:*)
+	# the GNU system
+	echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-${LIBC}`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'`
+	exit ;;
+    *:GNU/*:*:*)
+	# other systems with GNU libc and userland
+	echo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr '[A-Z]' '[a-z]'``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-${LIBC}
+	exit ;;
+    i*86:Minix:*:*)
+	echo ${UNAME_MACHINE}-pc-minix
+	exit ;;
+    aarch64:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+	exit ;;
+    aarch64_be:Linux:*:*)
+	UNAME_MACHINE=aarch64_be
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+	exit ;;
+    alpha:Linux:*:*)
+	case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in
+	  EV5)   UNAME_MACHINE=alphaev5 ;;
+	  EV56)  UNAME_MACHINE=alphaev56 ;;
+	  PCA56) UNAME_MACHINE=alphapca56 ;;
+	  PCA57) UNAME_MACHINE=alphapca56 ;;
+	  EV6)   UNAME_MACHINE=alphaev6 ;;
+	  EV67)  UNAME_MACHINE=alphaev67 ;;
+	  EV68*) UNAME_MACHINE=alphaev68 ;;
+	esac
+	objdump --private-headers /bin/sh | grep -q ld.so.1
+	if test "$?" = 0 ; then LIBC="gnulibc1" ; fi
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+	exit ;;
+    arc:Linux:*:* | arceb:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+	exit ;;
+    arm*:Linux:*:*)
+	eval $set_cc_for_build
+	if echo __ARM_EABI__ | $CC_FOR_BUILD -E - 2>/dev/null \
+	    | grep -q __ARM_EABI__
+	then
+	    echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+	else
+	    if echo __ARM_PCS_VFP | $CC_FOR_BUILD -E - 2>/dev/null \
+		| grep -q __ARM_PCS_VFP
+	    then
+		echo ${UNAME_MACHINE}-unknown-linux-${LIBC}eabi
+	    else
+		echo ${UNAME_MACHINE}-unknown-linux-${LIBC}eabihf
+	    fi
+	fi
+	exit ;;
+    avr32*:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+	exit ;;
+    cris:Linux:*:*)
+	echo ${UNAME_MACHINE}-axis-linux-${LIBC}
+	exit ;;
+    crisv32:Linux:*:*)
+	echo ${UNAME_MACHINE}-axis-linux-${LIBC}
+	exit ;;
+    frv:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+	exit ;;
+    hexagon:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+	exit ;;
+    i*86:Linux:*:*)
+	echo ${UNAME_MACHINE}-pc-linux-${LIBC}
+	exit ;;
+    ia64:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+	exit ;;
+    m32r*:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+	exit ;;
+    m68*:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+	exit ;;
+    mips:Linux:*:* | mips64:Linux:*:*)
+	eval $set_cc_for_build
+	sed 's/^	//' << EOF >$dummy.c
+	#undef CPU
+	#undef ${UNAME_MACHINE}
+	#undef ${UNAME_MACHINE}el
+	#if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL)
+	CPU=${UNAME_MACHINE}el
+	#else
+	#if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB)
+	CPU=${UNAME_MACHINE}
+	#else
+	CPU=
+	#endif
+	#endif
+EOF
+	eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^CPU'`
+	test x"${CPU}" != x && { echo "${CPU}-unknown-linux-${LIBC}"; exit; }
+	;;
+    or1k:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+	exit ;;
+    or32:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+	exit ;;
+    padre:Linux:*:*)
+	echo sparc-unknown-linux-${LIBC}
+	exit ;;
+    parisc64:Linux:*:* | hppa64:Linux:*:*)
+	echo hppa64-unknown-linux-${LIBC}
+	exit ;;
+    parisc:Linux:*:* | hppa:Linux:*:*)
+	# Look for CPU level
+	case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in
+	  PA7*) echo hppa1.1-unknown-linux-${LIBC} ;;
+	  PA8*) echo hppa2.0-unknown-linux-${LIBC} ;;
+	  *)    echo hppa-unknown-linux-${LIBC} ;;
+	esac
+	exit ;;
+    ppc64:Linux:*:*)
+	echo powerpc64-unknown-linux-${LIBC}
+	exit ;;
+    ppc:Linux:*:*)
+	echo powerpc-unknown-linux-${LIBC}
+	exit ;;
+    ppc64le:Linux:*:*)
+	echo powerpc64le-unknown-linux-${LIBC}
+	exit ;;
+    ppcle:Linux:*:*)
+	echo powerpcle-unknown-linux-${LIBC}
+	exit ;;
+    s390:Linux:*:* | s390x:Linux:*:*)
+	echo ${UNAME_MACHINE}-ibm-linux-${LIBC}
+	exit ;;
+    sh64*:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+	exit ;;
+    sh*:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+	exit ;;
+    sparc:Linux:*:* | sparc64:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+	exit ;;
+    tile*:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+	exit ;;
+    vax:Linux:*:*)
+	echo ${UNAME_MACHINE}-dec-linux-${LIBC}
+	exit ;;
+    x86_64:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+	exit ;;
+    xtensa*:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+	exit ;;
+    i*86:DYNIX/ptx:4*:*)
+	# ptx 4.0 does uname -s correctly, with DYNIX/ptx in there.
+	# earlier versions are messed up and put the nodename in both
+	# sysname and nodename.
+	echo i386-sequent-sysv4
+	exit ;;
+    i*86:UNIX_SV:4.2MP:2.*)
+	# Unixware is an offshoot of SVR4, but it has its own version
+	# number series starting with 2...
+	# I am not positive that other SVR4 systems won't match this,
+	# I just have to hope.  -- rms.
+	# Use sysv4.2uw... so that sysv4* matches it.
+	echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION}
+	exit ;;
+    i*86:OS/2:*:*)
+	# If we were able to find `uname', then EMX Unix compatibility
+	# is probably installed.
+	echo ${UNAME_MACHINE}-pc-os2-emx
+	exit ;;
+    i*86:XTS-300:*:STOP)
+	echo ${UNAME_MACHINE}-unknown-stop
+	exit ;;
+    i*86:atheos:*:*)
+	echo ${UNAME_MACHINE}-unknown-atheos
+	exit ;;
+    i*86:syllable:*:*)
+	echo ${UNAME_MACHINE}-pc-syllable
+	exit ;;
+    i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.[02]*:*)
+	echo i386-unknown-lynxos${UNAME_RELEASE}
+	exit ;;
+    i*86:*DOS:*:*)
+	echo ${UNAME_MACHINE}-pc-msdosdjgpp
+	exit ;;
+    i*86:*:4.*:* | i*86:SYSTEM_V:4.*:*)
+	UNAME_REL=`echo ${UNAME_RELEASE} | sed 's/\/MP$//'`
+	if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then
+		echo ${UNAME_MACHINE}-univel-sysv${UNAME_REL}
+	else
+		echo ${UNAME_MACHINE}-pc-sysv${UNAME_REL}
+	fi
+	exit ;;
+    i*86:*:5:[678]*)
+	# UnixWare 7.x, OpenUNIX and OpenServer 6.
+	case `/bin/uname -X | grep "^Machine"` in
+	    *486*)	     UNAME_MACHINE=i486 ;;
+	    *Pentium)	     UNAME_MACHINE=i586 ;;
+	    *Pent*|*Celeron) UNAME_MACHINE=i686 ;;
+	esac
+	echo ${UNAME_MACHINE}-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION}
+	exit ;;
+    i*86:*:3.2:*)
+	if test -f /usr/options/cb.name; then
+		UNAME_REL=`sed -n 's/.*Version //p' </usr/options/cb.name`
+		echo ${UNAME_MACHINE}-pc-isc$UNAME_REL
+	elif /bin/uname -X 2>/dev/null >/dev/null ; then
+		UNAME_REL=`(/bin/uname -X|grep Release|sed -e 's/.*= //')`
+		(/bin/uname -X|grep i80486 >/dev/null) && UNAME_MACHINE=i486
+		(/bin/uname -X|grep '^Machine.*Pentium' >/dev/null) \
+			&& UNAME_MACHINE=i586
+		(/bin/uname -X|grep '^Machine.*Pent *II' >/dev/null) \
+			&& UNAME_MACHINE=i686
+		(/bin/uname -X|grep '^Machine.*Pentium Pro' >/dev/null) \
+			&& UNAME_MACHINE=i686
+		echo ${UNAME_MACHINE}-pc-sco$UNAME_REL
+	else
+		echo ${UNAME_MACHINE}-pc-sysv32
+	fi
+	exit ;;
+    pc:*:*:*)
+	# Left here for compatibility:
+	# uname -m prints for DJGPP always 'pc', but it prints nothing about
+	# the processor, so we play safe by assuming i586.
+	# Note: whatever this is, it MUST be the same as what config.sub
+	# prints for the "djgpp" host, or else GDB configury will decide that
+	# this is a cross-build.
+	echo i586-pc-msdosdjgpp
+	exit ;;
+    Intel:Mach:3*:*)
+	echo i386-pc-mach3
+	exit ;;
+    paragon:*:*:*)
+	echo i860-intel-osf1
+	exit ;;
+    i860:*:4.*:*) # i860-SVR4
+	if grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then
+	  echo i860-stardent-sysv${UNAME_RELEASE} # Stardent Vistra i860-SVR4
+	else # Add other i860-SVR4 vendors below as they are discovered.
+	  echo i860-unknown-sysv${UNAME_RELEASE}  # Unknown i860-SVR4
+	fi
+	exit ;;
+    mini*:CTIX:SYS*5:*)
+	# "miniframe"
+	echo m68010-convergent-sysv
+	exit ;;
+    mc68k:UNIX:SYSTEM5:3.51m)
+	echo m68k-convergent-sysv
+	exit ;;
+    M680?0:D-NIX:5.3:*)
+	echo m68k-diab-dnix
+	exit ;;
+    M68*:*:R3V[5678]*:*)
+	test -r /sysV68 && { echo 'm68k-motorola-sysv'; exit; } ;;
+    3[345]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0 | S7501*:*:4.0:3.0)
+	OS_REL=''
+	test -r /etc/.relid \
+	&& OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid`
+	/bin/uname -p 2>/dev/null | grep 86 >/dev/null \
+	  && { echo i486-ncr-sysv4.3${OS_REL}; exit; }
+	/bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \
+	  && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;;
+    3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*)
+	/bin/uname -p 2>/dev/null | grep 86 >/dev/null \
+	  && { echo i486-ncr-sysv4; exit; } ;;
+    NCR*:*:4.2:* | MPRAS*:*:4.2:*)
+	OS_REL='.3'
+	test -r /etc/.relid \
+	    && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid`
+	/bin/uname -p 2>/dev/null | grep 86 >/dev/null \
+	    && { echo i486-ncr-sysv4.3${OS_REL}; exit; }
+	/bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \
+	    && { echo i586-ncr-sysv4.3${OS_REL}; exit; }
+	/bin/uname -p 2>/dev/null | /bin/grep pteron >/dev/null \
+	    && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;;
+    m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*)
+	echo m68k-unknown-lynxos${UNAME_RELEASE}
+	exit ;;
+    mc68030:UNIX_System_V:4.*:*)
+	echo m68k-atari-sysv4
+	exit ;;
+    TSUNAMI:LynxOS:2.*:*)
+	echo sparc-unknown-lynxos${UNAME_RELEASE}
+	exit ;;
+    rs6000:LynxOS:2.*:*)
+	echo rs6000-unknown-lynxos${UNAME_RELEASE}
+	exit ;;
+    PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.[02]*:*)
+	echo powerpc-unknown-lynxos${UNAME_RELEASE}
+	exit ;;
+    SM[BE]S:UNIX_SV:*:*)
+	echo mips-dde-sysv${UNAME_RELEASE}
+	exit ;;
+    RM*:ReliantUNIX-*:*:*)
+	echo mips-sni-sysv4
+	exit ;;
+    RM*:SINIX-*:*:*)
+	echo mips-sni-sysv4
+	exit ;;
+    *:SINIX-*:*:*)
+	if uname -p 2>/dev/null >/dev/null ; then
+		UNAME_MACHINE=`(uname -p) 2>/dev/null`
+		echo ${UNAME_MACHINE}-sni-sysv4
+	else
+		echo ns32k-sni-sysv
+	fi
+	exit ;;
+    PENTIUM:*:4.0*:*)	# Unisys `ClearPath HMP IX 4000' SVR4/MP effort
+			# says <Richard.M.Bartel@ccMail.Census.GOV>
+	echo i586-unisys-sysv4
+	exit ;;
+    *:UNIX_System_V:4*:FTX*)
+	# From Gerald Hewes <hewes@openmarket.com>.
+	# How about differentiating between stratus architectures? -djm
+	echo hppa1.1-stratus-sysv4
+	exit ;;
+    *:*:*:FTX*)
+	# From seanf@swdc.stratus.com.
+	echo i860-stratus-sysv4
+	exit ;;
+    i*86:VOS:*:*)
+	# From Paul.Green@stratus.com.
+	echo ${UNAME_MACHINE}-stratus-vos
+	exit ;;
+    *:VOS:*:*)
+	# From Paul.Green@stratus.com.
+	echo hppa1.1-stratus-vos
+	exit ;;
+    mc68*:A/UX:*:*)
+	echo m68k-apple-aux${UNAME_RELEASE}
+	exit ;;
+    news*:NEWS-OS:6*:*)
+	echo mips-sony-newsos6
+	exit ;;
+    R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*)
+	if [ -d /usr/nec ]; then
+		echo mips-nec-sysv${UNAME_RELEASE}
+	else
+		echo mips-unknown-sysv${UNAME_RELEASE}
+	fi
+	exit ;;
+    BeBox:BeOS:*:*)	# BeOS running on hardware made by Be, PPC only.
+	echo powerpc-be-beos
+	exit ;;
+    BeMac:BeOS:*:*)	# BeOS running on Mac or Mac clone, PPC only.
+	echo powerpc-apple-beos
+	exit ;;
+    BePC:BeOS:*:*)	# BeOS running on Intel PC compatible.
+	echo i586-pc-beos
+	exit ;;
+    BePC:Haiku:*:*)	# Haiku running on Intel PC compatible.
+	echo i586-pc-haiku
+	exit ;;
+    x86_64:Haiku:*:*)
+	echo x86_64-unknown-haiku
+	exit ;;
+    SX-4:SUPER-UX:*:*)
+	echo sx4-nec-superux${UNAME_RELEASE}
+	exit ;;
+    SX-5:SUPER-UX:*:*)
+	echo sx5-nec-superux${UNAME_RELEASE}
+	exit ;;
+    SX-6:SUPER-UX:*:*)
+	echo sx6-nec-superux${UNAME_RELEASE}
+	exit ;;
+    SX-7:SUPER-UX:*:*)
+	echo sx7-nec-superux${UNAME_RELEASE}
+	exit ;;
+    SX-8:SUPER-UX:*:*)
+	echo sx8-nec-superux${UNAME_RELEASE}
+	exit ;;
+    SX-8R:SUPER-UX:*:*)
+	echo sx8r-nec-superux${UNAME_RELEASE}
+	exit ;;
+    Power*:Rhapsody:*:*)
+	echo powerpc-apple-rhapsody${UNAME_RELEASE}
+	exit ;;
+    *:Rhapsody:*:*)
+	echo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE}
+	exit ;;
+    *:Darwin:*:*)
+	UNAME_PROCESSOR=`uname -p` || UNAME_PROCESSOR=unknown
+	eval $set_cc_for_build
+	if test "$UNAME_PROCESSOR" = unknown ; then
+	    UNAME_PROCESSOR=powerpc
+	fi
+	if [ "$CC_FOR_BUILD" != 'no_compiler_found' ]; then
+	    if (echo '#ifdef __LP64__'; echo IS_64BIT_ARCH; echo '#endif') | \
+		(CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \
+		grep IS_64BIT_ARCH >/dev/null
+	    then
+		case $UNAME_PROCESSOR in
+		    i386) UNAME_PROCESSOR=x86_64 ;;
+		    powerpc) UNAME_PROCESSOR=powerpc64 ;;
+		esac
+	    fi
+	fi
+	echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE}
+	exit ;;
+    *:procnto*:*:* | *:QNX:[0123456789]*:*)
+	UNAME_PROCESSOR=`uname -p`
+	if test "$UNAME_PROCESSOR" = "x86"; then
+		UNAME_PROCESSOR=i386
+		UNAME_MACHINE=pc
+	fi
+	echo ${UNAME_PROCESSOR}-${UNAME_MACHINE}-nto-qnx${UNAME_RELEASE}
+	exit ;;
+    *:QNX:*:4*)
+	echo i386-pc-qnx
+	exit ;;
+    NEO-?:NONSTOP_KERNEL:*:*)
+	echo neo-tandem-nsk${UNAME_RELEASE}
+	exit ;;
+    NSE-*:NONSTOP_KERNEL:*:*)
+	echo nse-tandem-nsk${UNAME_RELEASE}
+	exit ;;
+    NSR-?:NONSTOP_KERNEL:*:*)
+	echo nsr-tandem-nsk${UNAME_RELEASE}
+	exit ;;
+    *:NonStop-UX:*:*)
+	echo mips-compaq-nonstopux
+	exit ;;
+    BS2000:POSIX*:*:*)
+	echo bs2000-siemens-sysv
+	exit ;;
+    DS/*:UNIX_System_V:*:*)
+	echo ${UNAME_MACHINE}-${UNAME_SYSTEM}-${UNAME_RELEASE}
+	exit ;;
+    *:Plan9:*:*)
+	# "uname -m" is not consistent, so use $cputype instead. 386
+	# is converted to i386 for consistency with other x86
+	# operating systems.
+	if test "$cputype" = "386"; then
+	    UNAME_MACHINE=i386
+	else
+	    UNAME_MACHINE="$cputype"
+	fi
+	echo ${UNAME_MACHINE}-unknown-plan9
+	exit ;;
+    *:TOPS-10:*:*)
+	echo pdp10-unknown-tops10
+	exit ;;
+    *:TENEX:*:*)
+	echo pdp10-unknown-tenex
+	exit ;;
+    KS10:TOPS-20:*:* | KL10:TOPS-20:*:* | TYPE4:TOPS-20:*:*)
+	echo pdp10-dec-tops20
+	exit ;;
+    XKL-1:TOPS-20:*:* | TYPE5:TOPS-20:*:*)
+	echo pdp10-xkl-tops20
+	exit ;;
+    *:TOPS-20:*:*)
+	echo pdp10-unknown-tops20
+	exit ;;
+    *:ITS:*:*)
+	echo pdp10-unknown-its
+	exit ;;
+    SEI:*:*:SEIUX)
+	echo mips-sei-seiux${UNAME_RELEASE}
+	exit ;;
+    *:DragonFly:*:*)
+	echo ${UNAME_MACHINE}-unknown-dragonfly`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`
+	exit ;;
+    *:*VMS:*:*)
+	UNAME_MACHINE=`(uname -p) 2>/dev/null`
+	case "${UNAME_MACHINE}" in
+	    A*) echo alpha-dec-vms ; exit ;;
+	    I*) echo ia64-dec-vms ; exit ;;
+	    V*) echo vax-dec-vms ; exit ;;
+	esac ;;
+    *:XENIX:*:SysV)
+	echo i386-pc-xenix
+	exit ;;
+    i*86:skyos:*:*)
+	echo ${UNAME_MACHINE}-pc-skyos`echo ${UNAME_RELEASE}` | sed -e 's/ .*$//'
+	exit ;;
+    i*86:rdos:*:*)
+	echo ${UNAME_MACHINE}-pc-rdos
+	exit ;;
+    i*86:AROS:*:*)
+	echo ${UNAME_MACHINE}-pc-aros
+	exit ;;
+    x86_64:VMkernel:*:*)
+	echo ${UNAME_MACHINE}-unknown-esx
+	exit ;;
+esac
+
+eval $set_cc_for_build
+cat >$dummy.c <<EOF
+#ifdef _SEQUENT_
+# include <sys/types.h>
+# include <sys/utsname.h>
+#endif
+main ()
+{
+#if defined (sony)
+#if defined (MIPSEB)
+  /* BFD wants "bsd" instead of "newsos".  Perhaps BFD should be changed,
+     I don't know....  */
+  printf ("mips-sony-bsd\n"); exit (0);
+#else
+#include <sys/param.h>
+  printf ("m68k-sony-newsos%s\n",
+#ifdef NEWSOS4
+	"4"
+#else
+	""
+#endif
+	); exit (0);
+#endif
+#endif
+
+#if defined (__arm) && defined (__acorn) && defined (__unix)
+  printf ("arm-acorn-riscix\n"); exit (0);
+#endif
+
+#if defined (hp300) && !defined (hpux)
+  printf ("m68k-hp-bsd\n"); exit (0);
+#endif
+
+#if defined (NeXT)
+#if !defined (__ARCHITECTURE__)
+#define __ARCHITECTURE__ "m68k"
+#endif
+  int version;
+  version=`(hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null`;
+  if (version < 4)
+    printf ("%s-next-nextstep%d\n", __ARCHITECTURE__, version);
+  else
+    printf ("%s-next-openstep%d\n", __ARCHITECTURE__, version);
+  exit (0);
+#endif
+
+#if defined (MULTIMAX) || defined (n16)
+#if defined (UMAXV)
+  printf ("ns32k-encore-sysv\n"); exit (0);
+#else
+#if defined (CMU)
+  printf ("ns32k-encore-mach\n"); exit (0);
+#else
+  printf ("ns32k-encore-bsd\n"); exit (0);
+#endif
+#endif
+#endif
+
+#if defined (__386BSD__)
+  printf ("i386-pc-bsd\n"); exit (0);
+#endif
+
+#if defined (sequent)
+#if defined (i386)
+  printf ("i386-sequent-dynix\n"); exit (0);
+#endif
+#if defined (ns32000)
+  printf ("ns32k-sequent-dynix\n"); exit (0);
+#endif
+#endif
+
+#if defined (_SEQUENT_)
+    struct utsname un;
+
+    uname(&un);
+
+    if (strncmp(un.version, "V2", 2) == 0) {
+	printf ("i386-sequent-ptx2\n"); exit (0);
+    }
+    if (strncmp(un.version, "V1", 2) == 0) { /* XXX is V1 correct? */
+	printf ("i386-sequent-ptx1\n"); exit (0);
+    }
+    printf ("i386-sequent-ptx\n"); exit (0);
+
+#endif
+
+#if defined (vax)
+# if !defined (ultrix)
+#  include <sys/param.h>
+#  if defined (BSD)
+#   if BSD == 43
+      printf ("vax-dec-bsd4.3\n"); exit (0);
+#   else
+#    if BSD == 199006
+      printf ("vax-dec-bsd4.3reno\n"); exit (0);
+#    else
+      printf ("vax-dec-bsd\n"); exit (0);
+#    endif
+#   endif
+#  else
+    printf ("vax-dec-bsd\n"); exit (0);
+#  endif
+# else
+    printf ("vax-dec-ultrix\n"); exit (0);
+# endif
+#endif
+
+#if defined (alliant) && defined (i860)
+  printf ("i860-alliant-bsd\n"); exit (0);
+#endif
+
+  exit (1);
+}
+EOF
+
+$CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null && SYSTEM_NAME=`$dummy` &&
+	{ echo "$SYSTEM_NAME"; exit; }
+
+# Apollos put the system type in the environment.
+
+test -d /usr/apollo && { echo ${ISP}-apollo-${SYSTYPE}; exit; }
+
+# Convex versions that predate uname can use getsysinfo(1)
+
+if [ -x /usr/convex/getsysinfo ]
+then
+    case `getsysinfo -f cpu_type` in
+    c1*)
+	echo c1-convex-bsd
+	exit ;;
+    c2*)
+	if getsysinfo -f scalar_acc
+	then echo c32-convex-bsd
+	else echo c2-convex-bsd
+	fi
+	exit ;;
+    c34*)
+	echo c34-convex-bsd
+	exit ;;
+    c38*)
+	echo c38-convex-bsd
+	exit ;;
+    c4*)
+	echo c4-convex-bsd
+	exit ;;
+    esac
+fi
+
+cat >&2 <<EOF
+$0: unable to guess system type
+
+This script, last modified $timestamp, has failed to recognize
+the operating system you are using. It is advised that you
+download the most up to date version of the config scripts from
+
+  http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD
+and
+  http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD
+
+If the version you run ($0) is already up to date, please
+send the following data and any information you think might be
+pertinent to <config-patches@gnu.org> in order to provide the needed
+information to handle your system.
+
+config.guess timestamp = $timestamp
+
+uname -m = `(uname -m) 2>/dev/null || echo unknown`
+uname -r = `(uname -r) 2>/dev/null || echo unknown`
+uname -s = `(uname -s) 2>/dev/null || echo unknown`
+uname -v = `(uname -v) 2>/dev/null || echo unknown`
+
+/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null`
+/bin/uname -X     = `(/bin/uname -X) 2>/dev/null`
+
+hostinfo               = `(hostinfo) 2>/dev/null`
+/bin/universe          = `(/bin/universe) 2>/dev/null`
+/usr/bin/arch -k       = `(/usr/bin/arch -k) 2>/dev/null`
+/bin/arch              = `(/bin/arch) 2>/dev/null`
+/usr/bin/oslevel       = `(/usr/bin/oslevel) 2>/dev/null`
+/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null`
+
+UNAME_MACHINE = ${UNAME_MACHINE}
+UNAME_RELEASE = ${UNAME_RELEASE}
+UNAME_SYSTEM  = ${UNAME_SYSTEM}
+UNAME_VERSION = ${UNAME_VERSION}
+EOF
+
+exit 1
+
+# Local variables:
+# eval: (add-hook 'write-file-hooks 'time-stamp)
+# time-stamp-start: "timestamp='"
+# time-stamp-format: "%:y-%02m-%02d"
+# time-stamp-end: "'"
+# End:
diff --git a/connman/config.h.in b/connman/config.h.in
new file mode 100644
index 0000000..03ab443
--- /dev/null
+++ b/connman/config.h.in
@@ -0,0 +1,80 @@
+/* config.h.in.  Generated from configure.ac by autoheader.  */
+
+/* Enable connman debugging code? */
+#undef CONNMAN_DEBUG
+
+/* Define to 1 if you have the <dlfcn.h> header file. */
+#undef HAVE_DLFCN_H
+
+/* Define to 1 if you have the <inttypes.h> header file. */
+#undef HAVE_INTTYPES_H
+
+/* Define to 1 if you have the <memory.h> header file. */
+#undef HAVE_MEMORY_H
+
+/* Define to 1 if you have the <pppd/pppd.h> header file. */
+#undef HAVE_PPPD_PPPD_H
+
+/* Define to 1 if you have the <readline/readline.h> header file. */
+#undef HAVE_READLINE_READLINE_H
+
+/* Define to 1 if you have the <resolv.h> header file. */
+#undef HAVE_RESOLV_H
+
+/* Define to 1 if you have the <stdint.h> header file. */
+#undef HAVE_STDINT_H
+
+/* Define to 1 if you have the <stdlib.h> header file. */
+#undef HAVE_STDLIB_H
+
+/* Define to 1 if you have the <strings.h> header file. */
+#undef HAVE_STRINGS_H
+
+/* Define to 1 if you have the <string.h> header file. */
+#undef HAVE_STRING_H
+
+/* Define to 1 if you have the <sys/inotify.h> header file. */
+#undef HAVE_SYS_INOTIFY_H
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#undef HAVE_SYS_STAT_H
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#undef HAVE_SYS_TYPES_H
+
+/* Define to 1 if you have the <unistd.h> header file. */
+#undef HAVE_UNISTD_H
+
+/* Define to the sub-directory in which libtool stores uninstalled libraries.
+   */
+#undef LT_OBJDIR
+
+/* Name of package */
+#undef PACKAGE
+
+/* Define to the address where bug reports for this package should be sent. */
+#undef PACKAGE_BUGREPORT
+
+/* Define to the full name of this package. */
+#undef PACKAGE_NAME
+
+/* Define to the full name and version of this package. */
+#undef PACKAGE_STRING
+
+/* Define to the one symbol short name of this package. */
+#undef PACKAGE_TARNAME
+
+/* Define to the home page for this package. */
+#undef PACKAGE_URL
+
+/* Define to the version of this package. */
+#undef PACKAGE_VERSION
+
+/* Maximal size of a statistics round robin file */
+#undef STATS_MAX_FILE_SIZE
+
+/* Define to 1 if you have the ANSI C header files. */
+#undef STDC_HEADERS
+
+/* Version number of package */
+#undef VERSION
diff --git a/connman/config.sub b/connman/config.sub
new file mode 100755
index 0000000..9633db7
--- /dev/null
+++ b/connman/config.sub
@@ -0,0 +1,1791 @@
+#! /bin/sh
+# Configuration validation subroutine script.
+#   Copyright 1992-2013 Free Software Foundation, Inc.
+
+timestamp='2013-08-10'
+
+# This file is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# 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, see <http://www.gnu.org/licenses/>.
+#
+# As a special exception to the GNU General Public License, if you
+# distribute this file as part of a program that contains a
+# configuration script generated by Autoconf, you may include it under
+# the same distribution terms that you use for the rest of that
+# program.  This Exception is an additional permission under section 7
+# of the GNU General Public License, version 3 ("GPLv3").
+
+
+# Please send patches with a ChangeLog entry to config-patches@gnu.org.
+#
+# Configuration subroutine to validate and canonicalize a configuration type.
+# Supply the specified configuration type as an argument.
+# If it is invalid, we print an error message on stderr and exit with code 1.
+# Otherwise, we print the canonical config type on stdout and succeed.
+
+# You can get the latest version of this script from:
+# http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD
+
+# This file is supposed to be the same for all GNU packages
+# and recognize all the CPU types, system types and aliases
+# that are meaningful with *any* GNU software.
+# Each package is responsible for reporting which valid configurations
+# it does not support.  The user should be able to distinguish
+# a failure to support a valid configuration from a meaningless
+# configuration.
+
+# The goal of this file is to map all the various variations of a given
+# machine specification into a single specification in the form:
+#	CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM
+# or in some cases, the newer four-part form:
+#	CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM
+# It is wrong to echo any other type of specification.
+
+me=`echo "$0" | sed -e 's,.*/,,'`
+
+usage="\
+Usage: $0 [OPTION] CPU-MFR-OPSYS
+       $0 [OPTION] ALIAS
+
+Canonicalize a configuration name.
+
+Operation modes:
+  -h, --help         print this help, then exit
+  -t, --time-stamp   print date of last modification, then exit
+  -v, --version      print version number, then exit
+
+Report bugs and patches to <config-patches@gnu.org>."
+
+version="\
+GNU config.sub ($timestamp)
+
+Copyright 1992-2013 Free Software Foundation, Inc.
+
+This is free software; see the source for copying conditions.  There is NO
+warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
+
+help="
+Try \`$me --help' for more information."
+
+# Parse command line
+while test $# -gt 0 ; do
+  case $1 in
+    --time-stamp | --time* | -t )
+       echo "$timestamp" ; exit ;;
+    --version | -v )
+       echo "$version" ; exit ;;
+    --help | --h* | -h )
+       echo "$usage"; exit ;;
+    -- )     # Stop option processing
+       shift; break ;;
+    - )	# Use stdin as input.
+       break ;;
+    -* )
+       echo "$me: invalid option $1$help"
+       exit 1 ;;
+
+    *local*)
+       # First pass through any local machine types.
+       echo $1
+       exit ;;
+
+    * )
+       break ;;
+  esac
+done
+
+case $# in
+ 0) echo "$me: missing argument$help" >&2
+    exit 1;;
+ 1) ;;
+ *) echo "$me: too many arguments$help" >&2
+    exit 1;;
+esac
+
+# Separate what the user gave into CPU-COMPANY and OS or KERNEL-OS (if any).
+# Here we must recognize all the valid KERNEL-OS combinations.
+maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'`
+case $maybe_os in
+  nto-qnx* | linux-gnu* | linux-android* | linux-dietlibc | linux-newlib* | \
+  linux-musl* | linux-uclibc* | uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | \
+  knetbsd*-gnu* | netbsd*-gnu* | \
+  kopensolaris*-gnu* | \
+  storm-chaos* | os2-emx* | rtmk-nova*)
+    os=-$maybe_os
+    basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`
+    ;;
+  android-linux)
+    os=-linux-android
+    basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`-unknown
+    ;;
+  *)
+    basic_machine=`echo $1 | sed 's/-[^-]*$//'`
+    if [ $basic_machine != $1 ]
+    then os=`echo $1 | sed 's/.*-/-/'`
+    else os=; fi
+    ;;
+esac
+
+### Let's recognize common machines as not being operating systems so
+### that things like config.sub decstation-3100 work.  We also
+### recognize some manufacturers as not being operating systems, so we
+### can provide default operating systems below.
+case $os in
+	-sun*os*)
+		# Prevent following clause from handling this invalid input.
+		;;
+	-dec* | -mips* | -sequent* | -encore* | -pc532* | -sgi* | -sony* | \
+	-att* | -7300* | -3300* | -delta* | -motorola* | -sun[234]* | \
+	-unicom* | -ibm* | -next | -hp | -isi* | -apollo | -altos* | \
+	-convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\
+	-c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \
+	-harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp | \
+	-apple | -axis | -knuth | -cray | -microblaze*)
+		os=
+		basic_machine=$1
+		;;
+	-bluegene*)
+		os=-cnk
+		;;
+	-sim | -cisco | -oki | -wec | -winbond)
+		os=
+		basic_machine=$1
+		;;
+	-scout)
+		;;
+	-wrs)
+		os=-vxworks
+		basic_machine=$1
+		;;
+	-chorusos*)
+		os=-chorusos
+		basic_machine=$1
+		;;
+	-chorusrdb)
+		os=-chorusrdb
+		basic_machine=$1
+		;;
+	-hiux*)
+		os=-hiuxwe2
+		;;
+	-sco6)
+		os=-sco5v6
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
+	-sco5)
+		os=-sco3.2v5
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
+	-sco4)
+		os=-sco3.2v4
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
+	-sco3.2.[4-9]*)
+		os=`echo $os | sed -e 's/sco3.2./sco3.2v/'`
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
+	-sco3.2v[4-9]*)
+		# Don't forget version if it is 3.2v4 or newer.
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
+	-sco5v6*)
+		# Don't forget version if it is 3.2v4 or newer.
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
+	-sco*)
+		os=-sco3.2v2
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
+	-udk*)
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
+	-isc)
+		os=-isc2.2
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
+	-clix*)
+		basic_machine=clipper-intergraph
+		;;
+	-isc*)
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
+	-lynx*178)
+		os=-lynxos178
+		;;
+	-lynx*5)
+		os=-lynxos5
+		;;
+	-lynx*)
+		os=-lynxos
+		;;
+	-ptx*)
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-sequent/'`
+		;;
+	-windowsnt*)
+		os=`echo $os | sed -e 's/windowsnt/winnt/'`
+		;;
+	-psos*)
+		os=-psos
+		;;
+	-mint | -mint[0-9]*)
+		basic_machine=m68k-atari
+		os=-mint
+		;;
+esac
+
+# Decode aliases for certain CPU-COMPANY combinations.
+case $basic_machine in
+	# Recognize the basic CPU types without company name.
+	# Some are omitted here because they have special meanings below.
+	1750a | 580 \
+	| a29k \
+	| aarch64 | aarch64_be \
+	| alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \
+	| alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \
+	| am33_2.0 \
+	| arc | arceb \
+	| arm | arm[bl]e | arme[lb] | armv[2-8] | armv[3-8][lb] | armv7[arm] \
+	| avr | avr32 \
+	| be32 | be64 \
+	| bfin \
+	| c4x | c8051 | clipper \
+	| d10v | d30v | dlx | dsp16xx \
+	| epiphany \
+	| fido | fr30 | frv \
+	| h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \
+	| hexagon \
+	| i370 | i860 | i960 | ia64 \
+	| ip2k | iq2000 \
+	| le32 | le64 \
+	| lm32 \
+	| m32c | m32r | m32rle | m68000 | m68k | m88k \
+	| maxq | mb | microblaze | microblazeel | mcore | mep | metag \
+	| mips | mipsbe | mipseb | mipsel | mipsle \
+	| mips16 \
+	| mips64 | mips64el \
+	| mips64octeon | mips64octeonel \
+	| mips64orion | mips64orionel \
+	| mips64r5900 | mips64r5900el \
+	| mips64vr | mips64vrel \
+	| mips64vr4100 | mips64vr4100el \
+	| mips64vr4300 | mips64vr4300el \
+	| mips64vr5000 | mips64vr5000el \
+	| mips64vr5900 | mips64vr5900el \
+	| mipsisa32 | mipsisa32el \
+	| mipsisa32r2 | mipsisa32r2el \
+	| mipsisa64 | mipsisa64el \
+	| mipsisa64r2 | mipsisa64r2el \
+	| mipsisa64sb1 | mipsisa64sb1el \
+	| mipsisa64sr71k | mipsisa64sr71kel \
+	| mipsr5900 | mipsr5900el \
+	| mipstx39 | mipstx39el \
+	| mn10200 | mn10300 \
+	| moxie \
+	| mt \
+	| msp430 \
+	| nds32 | nds32le | nds32be \
+	| nios | nios2 | nios2eb | nios2el \
+	| ns16k | ns32k \
+	| open8 \
+	| or1k | or32 \
+	| pdp10 | pdp11 | pj | pjl \
+	| powerpc | powerpc64 | powerpc64le | powerpcle \
+	| pyramid \
+	| rl78 | rx \
+	| score \
+	| sh | sh[1234] | sh[24]a | sh[24]aeb | sh[23]e | sh[34]eb | sheb | shbe | shle | sh[1234]le | sh3ele \
+	| sh64 | sh64le \
+	| sparc | sparc64 | sparc64b | sparc64v | sparc86x | sparclet | sparclite \
+	| sparcv8 | sparcv9 | sparcv9b | sparcv9v \
+	| spu \
+	| tahoe | tic4x | tic54x | tic55x | tic6x | tic80 | tron \
+	| ubicom32 \
+	| v850 | v850e | v850e1 | v850e2 | v850es | v850e2v3 \
+	| we32k \
+	| x86 | xc16x | xstormy16 | xtensa \
+	| z8k | z80)
+		basic_machine=$basic_machine-unknown
+		;;
+	c54x)
+		basic_machine=tic54x-unknown
+		;;
+	c55x)
+		basic_machine=tic55x-unknown
+		;;
+	c6x)
+		basic_machine=tic6x-unknown
+		;;
+	m6811 | m68hc11 | m6812 | m68hc12 | m68hcs12x | picochip)
+		basic_machine=$basic_machine-unknown
+		os=-none
+		;;
+	m88110 | m680[12346]0 | m683?2 | m68360 | m5200 | v70 | w65 | z8k)
+		;;
+	ms1)
+		basic_machine=mt-unknown
+		;;
+
+	strongarm | thumb | xscale)
+		basic_machine=arm-unknown
+		;;
+	xgate)
+		basic_machine=$basic_machine-unknown
+		os=-none
+		;;
+	xscaleeb)
+		basic_machine=armeb-unknown
+		;;
+
+	xscaleel)
+		basic_machine=armel-unknown
+		;;
+
+	# We use `pc' rather than `unknown'
+	# because (1) that's what they normally are, and
+	# (2) the word "unknown" tends to confuse beginning users.
+	i*86 | x86_64)
+	  basic_machine=$basic_machine-pc
+	  ;;
+	# Object if more than one company name word.
+	*-*-*)
+		echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2
+		exit 1
+		;;
+	# Recognize the basic CPU types with company name.
+	580-* \
+	| a29k-* \
+	| aarch64-* | aarch64_be-* \
+	| alpha-* | alphaev[4-8]-* | alphaev56-* | alphaev6[78]-* \
+	| alpha64-* | alpha64ev[4-8]-* | alpha64ev56-* | alpha64ev6[78]-* \
+	| alphapca5[67]-* | alpha64pca5[67]-* | arc-* | arceb-* \
+	| arm-*  | armbe-* | armle-* | armeb-* | armv*-* \
+	| avr-* | avr32-* \
+	| be32-* | be64-* \
+	| bfin-* | bs2000-* \
+	| c[123]* | c30-* | [cjt]90-* | c4x-* \
+	| c8051-* | clipper-* | craynv-* | cydra-* \
+	| d10v-* | d30v-* | dlx-* \
+	| elxsi-* \
+	| f30[01]-* | f700-* | fido-* | fr30-* | frv-* | fx80-* \
+	| h8300-* | h8500-* \
+	| hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \
+	| hexagon-* \
+	| i*86-* | i860-* | i960-* | ia64-* \
+	| ip2k-* | iq2000-* \
+	| le32-* | le64-* \
+	| lm32-* \
+	| m32c-* | m32r-* | m32rle-* \
+	| m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \
+	| m88110-* | m88k-* | maxq-* | mcore-* | metag-* \
+	| microblaze-* | microblazeel-* \
+	| mips-* | mipsbe-* | mipseb-* | mipsel-* | mipsle-* \
+	| mips16-* \
+	| mips64-* | mips64el-* \
+	| mips64octeon-* | mips64octeonel-* \
+	| mips64orion-* | mips64orionel-* \
+	| mips64r5900-* | mips64r5900el-* \
+	| mips64vr-* | mips64vrel-* \
+	| mips64vr4100-* | mips64vr4100el-* \
+	| mips64vr4300-* | mips64vr4300el-* \
+	| mips64vr5000-* | mips64vr5000el-* \
+	| mips64vr5900-* | mips64vr5900el-* \
+	| mipsisa32-* | mipsisa32el-* \
+	| mipsisa32r2-* | mipsisa32r2el-* \
+	| mipsisa64-* | mipsisa64el-* \
+	| mipsisa64r2-* | mipsisa64r2el-* \
+	| mipsisa64sb1-* | mipsisa64sb1el-* \
+	| mipsisa64sr71k-* | mipsisa64sr71kel-* \
+	| mipsr5900-* | mipsr5900el-* \
+	| mipstx39-* | mipstx39el-* \
+	| mmix-* \
+	| mt-* \
+	| msp430-* \
+	| nds32-* | nds32le-* | nds32be-* \
+	| nios-* | nios2-* | nios2eb-* | nios2el-* \
+	| none-* | np1-* | ns16k-* | ns32k-* \
+	| open8-* \
+	| orion-* \
+	| pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \
+	| powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* \
+	| pyramid-* \
+	| rl78-* | romp-* | rs6000-* | rx-* \
+	| sh-* | sh[1234]-* | sh[24]a-* | sh[24]aeb-* | sh[23]e-* | sh[34]eb-* | sheb-* | shbe-* \
+	| shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \
+	| sparc-* | sparc64-* | sparc64b-* | sparc64v-* | sparc86x-* | sparclet-* \
+	| sparclite-* \
+	| sparcv8-* | sparcv9-* | sparcv9b-* | sparcv9v-* | sv1-* | sx?-* \
+	| tahoe-* \
+	| tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* \
+	| tile*-* \
+	| tron-* \
+	| ubicom32-* \
+	| v850-* | v850e-* | v850e1-* | v850es-* | v850e2-* | v850e2v3-* \
+	| vax-* \
+	| we32k-* \
+	| x86-* | x86_64-* | xc16x-* | xps100-* \
+	| xstormy16-* | xtensa*-* \
+	| ymp-* \
+	| z8k-* | z80-*)
+		;;
+	# Recognize the basic CPU types without company name, with glob match.
+	xtensa*)
+		basic_machine=$basic_machine-unknown
+		;;
+	# Recognize the various machine names and aliases which stand
+	# for a CPU type and a company and sometimes even an OS.
+	386bsd)
+		basic_machine=i386-unknown
+		os=-bsd
+		;;
+	3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc)
+		basic_machine=m68000-att
+		;;
+	3b*)
+		basic_machine=we32k-att
+		;;
+	a29khif)
+		basic_machine=a29k-amd
+		os=-udi
+		;;
+	abacus)
+		basic_machine=abacus-unknown
+		;;
+	adobe68k)
+		basic_machine=m68010-adobe
+		os=-scout
+		;;
+	alliant | fx80)
+		basic_machine=fx80-alliant
+		;;
+	altos | altos3068)
+		basic_machine=m68k-altos
+		;;
+	am29k)
+		basic_machine=a29k-none
+		os=-bsd
+		;;
+	amd64)
+		basic_machine=x86_64-pc
+		;;
+	amd64-*)
+		basic_machine=x86_64-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	amdahl)
+		basic_machine=580-amdahl
+		os=-sysv
+		;;
+	amiga | amiga-*)
+		basic_machine=m68k-unknown
+		;;
+	amigaos | amigados)
+		basic_machine=m68k-unknown
+		os=-amigaos
+		;;
+	amigaunix | amix)
+		basic_machine=m68k-unknown
+		os=-sysv4
+		;;
+	apollo68)
+		basic_machine=m68k-apollo
+		os=-sysv
+		;;
+	apollo68bsd)
+		basic_machine=m68k-apollo
+		os=-bsd
+		;;
+	aros)
+		basic_machine=i386-pc
+		os=-aros
+		;;
+	aux)
+		basic_machine=m68k-apple
+		os=-aux
+		;;
+	balance)
+		basic_machine=ns32k-sequent
+		os=-dynix
+		;;
+	blackfin)
+		basic_machine=bfin-unknown
+		os=-linux
+		;;
+	blackfin-*)
+		basic_machine=bfin-`echo $basic_machine | sed 's/^[^-]*-//'`
+		os=-linux
+		;;
+	bluegene*)
+		basic_machine=powerpc-ibm
+		os=-cnk
+		;;
+	c54x-*)
+		basic_machine=tic54x-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	c55x-*)
+		basic_machine=tic55x-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	c6x-*)
+		basic_machine=tic6x-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	c90)
+		basic_machine=c90-cray
+		os=-unicos
+		;;
+	cegcc)
+		basic_machine=arm-unknown
+		os=-cegcc
+		;;
+	convex-c1)
+		basic_machine=c1-convex
+		os=-bsd
+		;;
+	convex-c2)
+		basic_machine=c2-convex
+		os=-bsd
+		;;
+	convex-c32)
+		basic_machine=c32-convex
+		os=-bsd
+		;;
+	convex-c34)
+		basic_machine=c34-convex
+		os=-bsd
+		;;
+	convex-c38)
+		basic_machine=c38-convex
+		os=-bsd
+		;;
+	cray | j90)
+		basic_machine=j90-cray
+		os=-unicos
+		;;
+	craynv)
+		basic_machine=craynv-cray
+		os=-unicosmp
+		;;
+	cr16 | cr16-*)
+		basic_machine=cr16-unknown
+		os=-elf
+		;;
+	crds | unos)
+		basic_machine=m68k-crds
+		;;
+	crisv32 | crisv32-* | etraxfs*)
+		basic_machine=crisv32-axis
+		;;
+	cris | cris-* | etrax*)
+		basic_machine=cris-axis
+		;;
+	crx)
+		basic_machine=crx-unknown
+		os=-elf
+		;;
+	da30 | da30-*)
+		basic_machine=m68k-da30
+		;;
+	decstation | decstation-3100 | pmax | pmax-* | pmin | dec3100 | decstatn)
+		basic_machine=mips-dec
+		;;
+	decsystem10* | dec10*)
+		basic_machine=pdp10-dec
+		os=-tops10
+		;;
+	decsystem20* | dec20*)
+		basic_machine=pdp10-dec
+		os=-tops20
+		;;
+	delta | 3300 | motorola-3300 | motorola-delta \
+	      | 3300-motorola | delta-motorola)
+		basic_machine=m68k-motorola
+		;;
+	delta88)
+		basic_machine=m88k-motorola
+		os=-sysv3
+		;;
+	dicos)
+		basic_machine=i686-pc
+		os=-dicos
+		;;
+	djgpp)
+		basic_machine=i586-pc
+		os=-msdosdjgpp
+		;;
+	dpx20 | dpx20-*)
+		basic_machine=rs6000-bull
+		os=-bosx
+		;;
+	dpx2* | dpx2*-bull)
+		basic_machine=m68k-bull
+		os=-sysv3
+		;;
+	ebmon29k)
+		basic_machine=a29k-amd
+		os=-ebmon
+		;;
+	elxsi)
+		basic_machine=elxsi-elxsi
+		os=-bsd
+		;;
+	encore | umax | mmax)
+		basic_machine=ns32k-encore
+		;;
+	es1800 | OSE68k | ose68k | ose | OSE)
+		basic_machine=m68k-ericsson
+		os=-ose
+		;;
+	fx2800)
+		basic_machine=i860-alliant
+		;;
+	genix)
+		basic_machine=ns32k-ns
+		;;
+	gmicro)
+		basic_machine=tron-gmicro
+		os=-sysv
+		;;
+	go32)
+		basic_machine=i386-pc
+		os=-go32
+		;;
+	h3050r* | hiux*)
+		basic_machine=hppa1.1-hitachi
+		os=-hiuxwe2
+		;;
+	h8300hms)
+		basic_machine=h8300-hitachi
+		os=-hms
+		;;
+	h8300xray)
+		basic_machine=h8300-hitachi
+		os=-xray
+		;;
+	h8500hms)
+		basic_machine=h8500-hitachi
+		os=-hms
+		;;
+	harris)
+		basic_machine=m88k-harris
+		os=-sysv3
+		;;
+	hp300-*)
+		basic_machine=m68k-hp
+		;;
+	hp300bsd)
+		basic_machine=m68k-hp
+		os=-bsd
+		;;
+	hp300hpux)
+		basic_machine=m68k-hp
+		os=-hpux
+		;;
+	hp3k9[0-9][0-9] | hp9[0-9][0-9])
+		basic_machine=hppa1.0-hp
+		;;
+	hp9k2[0-9][0-9] | hp9k31[0-9])
+		basic_machine=m68000-hp
+		;;
+	hp9k3[2-9][0-9])
+		basic_machine=m68k-hp
+		;;
+	hp9k6[0-9][0-9] | hp6[0-9][0-9])
+		basic_machine=hppa1.0-hp
+		;;
+	hp9k7[0-79][0-9] | hp7[0-79][0-9])
+		basic_machine=hppa1.1-hp
+		;;
+	hp9k78[0-9] | hp78[0-9])
+		# FIXME: really hppa2.0-hp
+		basic_machine=hppa1.1-hp
+		;;
+	hp9k8[67]1 | hp8[67]1 | hp9k80[24] | hp80[24] | hp9k8[78]9 | hp8[78]9 | hp9k893 | hp893)
+		# FIXME: really hppa2.0-hp
+		basic_machine=hppa1.1-hp
+		;;
+	hp9k8[0-9][13679] | hp8[0-9][13679])
+		basic_machine=hppa1.1-hp
+		;;
+	hp9k8[0-9][0-9] | hp8[0-9][0-9])
+		basic_machine=hppa1.0-hp
+		;;
+	hppa-next)
+		os=-nextstep3
+		;;
+	hppaosf)
+		basic_machine=hppa1.1-hp
+		os=-osf
+		;;
+	hppro)
+		basic_machine=hppa1.1-hp
+		os=-proelf
+		;;
+	i370-ibm* | ibm*)
+		basic_machine=i370-ibm
+		;;
+	i*86v32)
+		basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
+		os=-sysv32
+		;;
+	i*86v4*)
+		basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
+		os=-sysv4
+		;;
+	i*86v)
+		basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
+		os=-sysv
+		;;
+	i*86sol2)
+		basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
+		os=-solaris2
+		;;
+	i386mach)
+		basic_machine=i386-mach
+		os=-mach
+		;;
+	i386-vsta | vsta)
+		basic_machine=i386-unknown
+		os=-vsta
+		;;
+	iris | iris4d)
+		basic_machine=mips-sgi
+		case $os in
+		    -irix*)
+			;;
+		    *)
+			os=-irix4
+			;;
+		esac
+		;;
+	isi68 | isi)
+		basic_machine=m68k-isi
+		os=-sysv
+		;;
+	m68knommu)
+		basic_machine=m68k-unknown
+		os=-linux
+		;;
+	m68knommu-*)
+		basic_machine=m68k-`echo $basic_machine | sed 's/^[^-]*-//'`
+		os=-linux
+		;;
+	m88k-omron*)
+		basic_machine=m88k-omron
+		;;
+	magnum | m3230)
+		basic_machine=mips-mips
+		os=-sysv
+		;;
+	merlin)
+		basic_machine=ns32k-utek
+		os=-sysv
+		;;
+	microblaze*)
+		basic_machine=microblaze-xilinx
+		;;
+	mingw64)
+		basic_machine=x86_64-pc
+		os=-mingw64
+		;;
+	mingw32)
+		basic_machine=i686-pc
+		os=-mingw32
+		;;
+	mingw32ce)
+		basic_machine=arm-unknown
+		os=-mingw32ce
+		;;
+	miniframe)
+		basic_machine=m68000-convergent
+		;;
+	*mint | -mint[0-9]* | *MiNT | *MiNT[0-9]*)
+		basic_machine=m68k-atari
+		os=-mint
+		;;
+	mips3*-*)
+		basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`
+		;;
+	mips3*)
+		basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`-unknown
+		;;
+	monitor)
+		basic_machine=m68k-rom68k
+		os=-coff
+		;;
+	morphos)
+		basic_machine=powerpc-unknown
+		os=-morphos
+		;;
+	msdos)
+		basic_machine=i386-pc
+		os=-msdos
+		;;
+	ms1-*)
+		basic_machine=`echo $basic_machine | sed -e 's/ms1-/mt-/'`
+		;;
+	msys)
+		basic_machine=i686-pc
+		os=-msys
+		;;
+	mvs)
+		basic_machine=i370-ibm
+		os=-mvs
+		;;
+	nacl)
+		basic_machine=le32-unknown
+		os=-nacl
+		;;
+	ncr3000)
+		basic_machine=i486-ncr
+		os=-sysv4
+		;;
+	netbsd386)
+		basic_machine=i386-unknown
+		os=-netbsd
+		;;
+	netwinder)
+		basic_machine=armv4l-rebel
+		os=-linux
+		;;
+	news | news700 | news800 | news900)
+		basic_machine=m68k-sony
+		os=-newsos
+		;;
+	news1000)
+		basic_machine=m68030-sony
+		os=-newsos
+		;;
+	news-3600 | risc-news)
+		basic_machine=mips-sony
+		os=-newsos
+		;;
+	necv70)
+		basic_machine=v70-nec
+		os=-sysv
+		;;
+	next | m*-next )
+		basic_machine=m68k-next
+		case $os in
+		    -nextstep* )
+			;;
+		    -ns2*)
+		      os=-nextstep2
+			;;
+		    *)
+		      os=-nextstep3
+			;;
+		esac
+		;;
+	nh3000)
+		basic_machine=m68k-harris
+		os=-cxux
+		;;
+	nh[45]000)
+		basic_machine=m88k-harris
+		os=-cxux
+		;;
+	nindy960)
+		basic_machine=i960-intel
+		os=-nindy
+		;;
+	mon960)
+		basic_machine=i960-intel
+		os=-mon960
+		;;
+	nonstopux)
+		basic_machine=mips-compaq
+		os=-nonstopux
+		;;
+	np1)
+		basic_machine=np1-gould
+		;;
+	neo-tandem)
+		basic_machine=neo-tandem
+		;;
+	nse-tandem)
+		basic_machine=nse-tandem
+		;;
+	nsr-tandem)
+		basic_machine=nsr-tandem
+		;;
+	op50n-* | op60c-*)
+		basic_machine=hppa1.1-oki
+		os=-proelf
+		;;
+	openrisc | openrisc-*)
+		basic_machine=or32-unknown
+		;;
+	os400)
+		basic_machine=powerpc-ibm
+		os=-os400
+		;;
+	OSE68000 | ose68000)
+		basic_machine=m68000-ericsson
+		os=-ose
+		;;
+	os68k)
+		basic_machine=m68k-none
+		os=-os68k
+		;;
+	pa-hitachi)
+		basic_machine=hppa1.1-hitachi
+		os=-hiuxwe2
+		;;
+	paragon)
+		basic_machine=i860-intel
+		os=-osf
+		;;
+	parisc)
+		basic_machine=hppa-unknown
+		os=-linux
+		;;
+	parisc-*)
+		basic_machine=hppa-`echo $basic_machine | sed 's/^[^-]*-//'`
+		os=-linux
+		;;
+	pbd)
+		basic_machine=sparc-tti
+		;;
+	pbb)
+		basic_machine=m68k-tti
+		;;
+	pc532 | pc532-*)
+		basic_machine=ns32k-pc532
+		;;
+	pc98)
+		basic_machine=i386-pc
+		;;
+	pc98-*)
+		basic_machine=i386-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	pentium | p5 | k5 | k6 | nexgen | viac3)
+		basic_machine=i586-pc
+		;;
+	pentiumpro | p6 | 6x86 | athlon | athlon_*)
+		basic_machine=i686-pc
+		;;
+	pentiumii | pentium2 | pentiumiii | pentium3)
+		basic_machine=i686-pc
+		;;
+	pentium4)
+		basic_machine=i786-pc
+		;;
+	pentium-* | p5-* | k5-* | k6-* | nexgen-* | viac3-*)
+		basic_machine=i586-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	pentiumpro-* | p6-* | 6x86-* | athlon-*)
+		basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	pentiumii-* | pentium2-* | pentiumiii-* | pentium3-*)
+		basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	pentium4-*)
+		basic_machine=i786-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	pn)
+		basic_machine=pn-gould
+		;;
+	power)	basic_machine=power-ibm
+		;;
+	ppc | ppcbe)	basic_machine=powerpc-unknown
+		;;
+	ppc-* | ppcbe-*)
+		basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	ppcle | powerpclittle | ppc-le | powerpc-little)
+		basic_machine=powerpcle-unknown
+		;;
+	ppcle-* | powerpclittle-*)
+		basic_machine=powerpcle-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	ppc64)	basic_machine=powerpc64-unknown
+		;;
+	ppc64-*) basic_machine=powerpc64-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	ppc64le | powerpc64little | ppc64-le | powerpc64-little)
+		basic_machine=powerpc64le-unknown
+		;;
+	ppc64le-* | powerpc64little-*)
+		basic_machine=powerpc64le-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	ps2)
+		basic_machine=i386-ibm
+		;;
+	pw32)
+		basic_machine=i586-unknown
+		os=-pw32
+		;;
+	rdos | rdos64)
+		basic_machine=x86_64-pc
+		os=-rdos
+		;;
+	rdos32)
+		basic_machine=i386-pc
+		os=-rdos
+		;;
+	rom68k)
+		basic_machine=m68k-rom68k
+		os=-coff
+		;;
+	rm[46]00)
+		basic_machine=mips-siemens
+		;;
+	rtpc | rtpc-*)
+		basic_machine=romp-ibm
+		;;
+	s390 | s390-*)
+		basic_machine=s390-ibm
+		;;
+	s390x | s390x-*)
+		basic_machine=s390x-ibm
+		;;
+	sa29200)
+		basic_machine=a29k-amd
+		os=-udi
+		;;
+	sb1)
+		basic_machine=mipsisa64sb1-unknown
+		;;
+	sb1el)
+		basic_machine=mipsisa64sb1el-unknown
+		;;
+	sde)
+		basic_machine=mipsisa32-sde
+		os=-elf
+		;;
+	sei)
+		basic_machine=mips-sei
+		os=-seiux
+		;;
+	sequent)
+		basic_machine=i386-sequent
+		;;
+	sh)
+		basic_machine=sh-hitachi
+		os=-hms
+		;;
+	sh5el)
+		basic_machine=sh5le-unknown
+		;;
+	sh64)
+		basic_machine=sh64-unknown
+		;;
+	sparclite-wrs | simso-wrs)
+		basic_machine=sparclite-wrs
+		os=-vxworks
+		;;
+	sps7)
+		basic_machine=m68k-bull
+		os=-sysv2
+		;;
+	spur)
+		basic_machine=spur-unknown
+		;;
+	st2000)
+		basic_machine=m68k-tandem
+		;;
+	stratus)
+		basic_machine=i860-stratus
+		os=-sysv4
+		;;
+	strongarm-* | thumb-*)
+		basic_machine=arm-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	sun2)
+		basic_machine=m68000-sun
+		;;
+	sun2os3)
+		basic_machine=m68000-sun
+		os=-sunos3
+		;;
+	sun2os4)
+		basic_machine=m68000-sun
+		os=-sunos4
+		;;
+	sun3os3)
+		basic_machine=m68k-sun
+		os=-sunos3
+		;;
+	sun3os4)
+		basic_machine=m68k-sun
+		os=-sunos4
+		;;
+	sun4os3)
+		basic_machine=sparc-sun
+		os=-sunos3
+		;;
+	sun4os4)
+		basic_machine=sparc-sun
+		os=-sunos4
+		;;
+	sun4sol2)
+		basic_machine=sparc-sun
+		os=-solaris2
+		;;
+	sun3 | sun3-*)
+		basic_machine=m68k-sun
+		;;
+	sun4)
+		basic_machine=sparc-sun
+		;;
+	sun386 | sun386i | roadrunner)
+		basic_machine=i386-sun
+		;;
+	sv1)
+		basic_machine=sv1-cray
+		os=-unicos
+		;;
+	symmetry)
+		basic_machine=i386-sequent
+		os=-dynix
+		;;
+	t3e)
+		basic_machine=alphaev5-cray
+		os=-unicos
+		;;
+	t90)
+		basic_machine=t90-cray
+		os=-unicos
+		;;
+	tile*)
+		basic_machine=$basic_machine-unknown
+		os=-linux-gnu
+		;;
+	tx39)
+		basic_machine=mipstx39-unknown
+		;;
+	tx39el)
+		basic_machine=mipstx39el-unknown
+		;;
+	toad1)
+		basic_machine=pdp10-xkl
+		os=-tops20
+		;;
+	tower | tower-32)
+		basic_machine=m68k-ncr
+		;;
+	tpf)
+		basic_machine=s390x-ibm
+		os=-tpf
+		;;
+	udi29k)
+		basic_machine=a29k-amd
+		os=-udi
+		;;
+	ultra3)
+		basic_machine=a29k-nyu
+		os=-sym1
+		;;
+	v810 | necv810)
+		basic_machine=v810-nec
+		os=-none
+		;;
+	vaxv)
+		basic_machine=vax-dec
+		os=-sysv
+		;;
+	vms)
+		basic_machine=vax-dec
+		os=-vms
+		;;
+	vpp*|vx|vx-*)
+		basic_machine=f301-fujitsu
+		;;
+	vxworks960)
+		basic_machine=i960-wrs
+		os=-vxworks
+		;;
+	vxworks68)
+		basic_machine=m68k-wrs
+		os=-vxworks
+		;;
+	vxworks29k)
+		basic_machine=a29k-wrs
+		os=-vxworks
+		;;
+	w65*)
+		basic_machine=w65-wdc
+		os=-none
+		;;
+	w89k-*)
+		basic_machine=hppa1.1-winbond
+		os=-proelf
+		;;
+	xbox)
+		basic_machine=i686-pc
+		os=-mingw32
+		;;
+	xps | xps100)
+		basic_machine=xps100-honeywell
+		;;
+	xscale-* | xscalee[bl]-*)
+		basic_machine=`echo $basic_machine | sed 's/^xscale/arm/'`
+		;;
+	ymp)
+		basic_machine=ymp-cray
+		os=-unicos
+		;;
+	z8k-*-coff)
+		basic_machine=z8k-unknown
+		os=-sim
+		;;
+	z80-*-coff)
+		basic_machine=z80-unknown
+		os=-sim
+		;;
+	none)
+		basic_machine=none-none
+		os=-none
+		;;
+
+# Here we handle the default manufacturer of certain CPU types.  It is in
+# some cases the only manufacturer, in others, it is the most popular.
+	w89k)
+		basic_machine=hppa1.1-winbond
+		;;
+	op50n)
+		basic_machine=hppa1.1-oki
+		;;
+	op60c)
+		basic_machine=hppa1.1-oki
+		;;
+	romp)
+		basic_machine=romp-ibm
+		;;
+	mmix)
+		basic_machine=mmix-knuth
+		;;
+	rs6000)
+		basic_machine=rs6000-ibm
+		;;
+	vax)
+		basic_machine=vax-dec
+		;;
+	pdp10)
+		# there are many clones, so DEC is not a safe bet
+		basic_machine=pdp10-unknown
+		;;
+	pdp11)
+		basic_machine=pdp11-dec
+		;;
+	we32k)
+		basic_machine=we32k-att
+		;;
+	sh[1234] | sh[24]a | sh[24]aeb | sh[34]eb | sh[1234]le | sh[23]ele)
+		basic_machine=sh-unknown
+		;;
+	sparc | sparcv8 | sparcv9 | sparcv9b | sparcv9v)
+		basic_machine=sparc-sun
+		;;
+	cydra)
+		basic_machine=cydra-cydrome
+		;;
+	orion)
+		basic_machine=orion-highlevel
+		;;
+	orion105)
+		basic_machine=clipper-highlevel
+		;;
+	mac | mpw | mac-mpw)
+		basic_machine=m68k-apple
+		;;
+	pmac | pmac-mpw)
+		basic_machine=powerpc-apple
+		;;
+	*-unknown)
+		# Make sure to match an already-canonicalized machine name.
+		;;
+	*)
+		echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2
+		exit 1
+		;;
+esac
+
+# Here we canonicalize certain aliases for manufacturers.
+case $basic_machine in
+	*-digital*)
+		basic_machine=`echo $basic_machine | sed 's/digital.*/dec/'`
+		;;
+	*-commodore*)
+		basic_machine=`echo $basic_machine | sed 's/commodore.*/cbm/'`
+		;;
+	*)
+		;;
+esac
+
+# Decode manufacturer-specific aliases for certain operating systems.
+
+if [ x"$os" != x"" ]
+then
+case $os in
+	# First match some system type aliases
+	# that might get confused with valid system types.
+	# -solaris* is a basic system type, with this one exception.
+	-auroraux)
+		os=-auroraux
+		;;
+	-solaris1 | -solaris1.*)
+		os=`echo $os | sed -e 's|solaris1|sunos4|'`
+		;;
+	-solaris)
+		os=-solaris2
+		;;
+	-svr4*)
+		os=-sysv4
+		;;
+	-unixware*)
+		os=-sysv4.2uw
+		;;
+	-gnu/linux*)
+		os=`echo $os | sed -e 's|gnu/linux|linux-gnu|'`
+		;;
+	# First accept the basic system types.
+	# The portable systems comes first.
+	# Each alternative MUST END IN A *, to match a version number.
+	# -sysv* is not here because it comes later, after sysvr4.
+	-gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \
+	      | -*vms* | -sco* | -esix* | -isc* | -aix* | -cnk* | -sunos | -sunos[34]*\
+	      | -hpux* | -unos* | -osf* | -luna* | -dgux* | -auroraux* | -solaris* \
+	      | -sym* | -kopensolaris* | -plan9* \
+	      | -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \
+	      | -aos* | -aros* \
+	      | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \
+	      | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \
+	      | -hiux* | -386bsd* | -knetbsd* | -mirbsd* | -netbsd* \
+	      | -bitrig* | -openbsd* | -solidbsd* \
+	      | -ekkobsd* | -kfreebsd* | -freebsd* | -riscix* | -lynxos* \
+	      | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \
+	      | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \
+	      | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \
+	      | -chorusos* | -chorusrdb* | -cegcc* \
+	      | -cygwin* | -msys* | -pe* | -psos* | -moss* | -proelf* | -rtems* \
+	      | -mingw32* | -mingw64* | -linux-gnu* | -linux-android* \
+	      | -linux-newlib* | -linux-musl* | -linux-uclibc* \
+	      | -uxpv* | -beos* | -mpeix* | -udk* \
+	      | -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \
+	      | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \
+	      | -storm-chaos* | -tops10* | -tenex* | -tops20* | -its* \
+	      | -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \
+	      | -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \
+	      | -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly* \
+	      | -skyos* | -haiku* | -rdos* | -toppers* | -drops* | -es*)
+	# Remember, each alternative MUST END IN *, to match a version number.
+		;;
+	-qnx*)
+		case $basic_machine in
+		    x86-* | i*86-*)
+			;;
+		    *)
+			os=-nto$os
+			;;
+		esac
+		;;
+	-nto-qnx*)
+		;;
+	-nto*)
+		os=`echo $os | sed -e 's|nto|nto-qnx|'`
+		;;
+	-sim | -es1800* | -hms* | -xray | -os68k* | -none* | -v88r* \
+	      | -windows* | -osx | -abug | -netware* | -os9* | -beos* | -haiku* \
+	      | -macos* | -mpw* | -magic* | -mmixware* | -mon960* | -lnews*)
+		;;
+	-mac*)
+		os=`echo $os | sed -e 's|mac|macos|'`
+		;;
+	-linux-dietlibc)
+		os=-linux-dietlibc
+		;;
+	-linux*)
+		os=`echo $os | sed -e 's|linux|linux-gnu|'`
+		;;
+	-sunos5*)
+		os=`echo $os | sed -e 's|sunos5|solaris2|'`
+		;;
+	-sunos6*)
+		os=`echo $os | sed -e 's|sunos6|solaris3|'`
+		;;
+	-opened*)
+		os=-openedition
+		;;
+	-os400*)
+		os=-os400
+		;;
+	-wince*)
+		os=-wince
+		;;
+	-osfrose*)
+		os=-osfrose
+		;;
+	-osf*)
+		os=-osf
+		;;
+	-utek*)
+		os=-bsd
+		;;
+	-dynix*)
+		os=-bsd
+		;;
+	-acis*)
+		os=-aos
+		;;
+	-atheos*)
+		os=-atheos
+		;;
+	-syllable*)
+		os=-syllable
+		;;
+	-386bsd)
+		os=-bsd
+		;;
+	-ctix* | -uts*)
+		os=-sysv
+		;;
+	-nova*)
+		os=-rtmk-nova
+		;;
+	-ns2 )
+		os=-nextstep2
+		;;
+	-nsk*)
+		os=-nsk
+		;;
+	# Preserve the version number of sinix5.
+	-sinix5.*)
+		os=`echo $os | sed -e 's|sinix|sysv|'`
+		;;
+	-sinix*)
+		os=-sysv4
+		;;
+	-tpf*)
+		os=-tpf
+		;;
+	-triton*)
+		os=-sysv3
+		;;
+	-oss*)
+		os=-sysv3
+		;;
+	-svr4)
+		os=-sysv4
+		;;
+	-svr3)
+		os=-sysv3
+		;;
+	-sysvr4)
+		os=-sysv4
+		;;
+	# This must come after -sysvr4.
+	-sysv*)
+		;;
+	-ose*)
+		os=-ose
+		;;
+	-es1800*)
+		os=-ose
+		;;
+	-xenix)
+		os=-xenix
+		;;
+	-*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*)
+		os=-mint
+		;;
+	-aros*)
+		os=-aros
+		;;
+	-zvmoe)
+		os=-zvmoe
+		;;
+	-dicos*)
+		os=-dicos
+		;;
+	-nacl*)
+		;;
+	-none)
+		;;
+	*)
+		# Get rid of the `-' at the beginning of $os.
+		os=`echo $os | sed 's/[^-]*-//'`
+		echo Invalid configuration \`$1\': system \`$os\' not recognized 1>&2
+		exit 1
+		;;
+esac
+else
+
+# Here we handle the default operating systems that come with various machines.
+# The value should be what the vendor currently ships out the door with their
+# machine or put another way, the most popular os provided with the machine.
+
+# Note that if you're going to try to match "-MANUFACTURER" here (say,
+# "-sun"), then you have to tell the case statement up towards the top
+# that MANUFACTURER isn't an operating system.  Otherwise, code above
+# will signal an error saying that MANUFACTURER isn't an operating
+# system, and we'll never get to this point.
+
+case $basic_machine in
+	score-*)
+		os=-elf
+		;;
+	spu-*)
+		os=-elf
+		;;
+	*-acorn)
+		os=-riscix1.2
+		;;
+	arm*-rebel)
+		os=-linux
+		;;
+	arm*-semi)
+		os=-aout
+		;;
+	c4x-* | tic4x-*)
+		os=-coff
+		;;
+	c8051-*)
+		os=-elf
+		;;
+	hexagon-*)
+		os=-elf
+		;;
+	tic54x-*)
+		os=-coff
+		;;
+	tic55x-*)
+		os=-coff
+		;;
+	tic6x-*)
+		os=-coff
+		;;
+	# This must come before the *-dec entry.
+	pdp10-*)
+		os=-tops20
+		;;
+	pdp11-*)
+		os=-none
+		;;
+	*-dec | vax-*)
+		os=-ultrix4.2
+		;;
+	m68*-apollo)
+		os=-domain
+		;;
+	i386-sun)
+		os=-sunos4.0.2
+		;;
+	m68000-sun)
+		os=-sunos3
+		;;
+	m68*-cisco)
+		os=-aout
+		;;
+	mep-*)
+		os=-elf
+		;;
+	mips*-cisco)
+		os=-elf
+		;;
+	mips*-*)
+		os=-elf
+		;;
+	or1k-*)
+		os=-elf
+		;;
+	or32-*)
+		os=-coff
+		;;
+	*-tti)	# must be before sparc entry or we get the wrong os.
+		os=-sysv3
+		;;
+	sparc-* | *-sun)
+		os=-sunos4.1.1
+		;;
+	*-be)
+		os=-beos
+		;;
+	*-haiku)
+		os=-haiku
+		;;
+	*-ibm)
+		os=-aix
+		;;
+	*-knuth)
+		os=-mmixware
+		;;
+	*-wec)
+		os=-proelf
+		;;
+	*-winbond)
+		os=-proelf
+		;;
+	*-oki)
+		os=-proelf
+		;;
+	*-hp)
+		os=-hpux
+		;;
+	*-hitachi)
+		os=-hiux
+		;;
+	i860-* | *-att | *-ncr | *-altos | *-motorola | *-convergent)
+		os=-sysv
+		;;
+	*-cbm)
+		os=-amigaos
+		;;
+	*-dg)
+		os=-dgux
+		;;
+	*-dolphin)
+		os=-sysv3
+		;;
+	m68k-ccur)
+		os=-rtu
+		;;
+	m88k-omron*)
+		os=-luna
+		;;
+	*-next )
+		os=-nextstep
+		;;
+	*-sequent)
+		os=-ptx
+		;;
+	*-crds)
+		os=-unos
+		;;
+	*-ns)
+		os=-genix
+		;;
+	i370-*)
+		os=-mvs
+		;;
+	*-next)
+		os=-nextstep3
+		;;
+	*-gould)
+		os=-sysv
+		;;
+	*-highlevel)
+		os=-bsd
+		;;
+	*-encore)
+		os=-bsd
+		;;
+	*-sgi)
+		os=-irix
+		;;
+	*-siemens)
+		os=-sysv4
+		;;
+	*-masscomp)
+		os=-rtu
+		;;
+	f30[01]-fujitsu | f700-fujitsu)
+		os=-uxpv
+		;;
+	*-rom68k)
+		os=-coff
+		;;
+	*-*bug)
+		os=-coff
+		;;
+	*-apple)
+		os=-macos
+		;;
+	*-atari*)
+		os=-mint
+		;;
+	*)
+		os=-none
+		;;
+esac
+fi
+
+# Here we handle the case where we know the os, and the CPU type, but not the
+# manufacturer.  We pick the logical manufacturer.
+vendor=unknown
+case $basic_machine in
+	*-unknown)
+		case $os in
+			-riscix*)
+				vendor=acorn
+				;;
+			-sunos*)
+				vendor=sun
+				;;
+			-cnk*|-aix*)
+				vendor=ibm
+				;;
+			-beos*)
+				vendor=be
+				;;
+			-hpux*)
+				vendor=hp
+				;;
+			-mpeix*)
+				vendor=hp
+				;;
+			-hiux*)
+				vendor=hitachi
+				;;
+			-unos*)
+				vendor=crds
+				;;
+			-dgux*)
+				vendor=dg
+				;;
+			-luna*)
+				vendor=omron
+				;;
+			-genix*)
+				vendor=ns
+				;;
+			-mvs* | -opened*)
+				vendor=ibm
+				;;
+			-os400*)
+				vendor=ibm
+				;;
+			-ptx*)
+				vendor=sequent
+				;;
+			-tpf*)
+				vendor=ibm
+				;;
+			-vxsim* | -vxworks* | -windiss*)
+				vendor=wrs
+				;;
+			-aux*)
+				vendor=apple
+				;;
+			-hms*)
+				vendor=hitachi
+				;;
+			-mpw* | -macos*)
+				vendor=apple
+				;;
+			-*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*)
+				vendor=atari
+				;;
+			-vos*)
+				vendor=stratus
+				;;
+		esac
+		basic_machine=`echo $basic_machine | sed "s/unknown/$vendor/"`
+		;;
+esac
+
+echo $basic_machine$os
+exit
+
+# Local variables:
+# eval: (add-hook 'write-file-hooks 'time-stamp)
+# time-stamp-start: "timestamp='"
+# time-stamp-format: "%:y-%02m-%02d"
+# time-stamp-end: "'"
+# End:
diff --git a/connman/configure b/connman/configure
new file mode 100755
index 0000000..78aad26
--- /dev/null
+++ b/connman/configure
@@ -0,0 +1,16017 @@
+#! /bin/sh
+# Guess values for system-dependent variables and create Makefiles.
+# Generated by GNU Autoconf 2.69 for connman 1.29.
+#
+#
+# Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc.
+#
+#
+# This configure script is free software; the Free Software Foundation
+# gives unlimited permission to copy, distribute and modify it.
+## -------------------- ##
+## M4sh Initialization. ##
+## -------------------- ##
+
+# Be more Bourne compatible
+DUALCASE=1; export DUALCASE # for MKS sh
+if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then :
+  emulate sh
+  NULLCMD=:
+  # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
+  # is contrary to our usage.  Disable this feature.
+  alias -g '${1+"$@"}'='"$@"'
+  setopt NO_GLOB_SUBST
+else
+  case `(set -o) 2>/dev/null` in #(
+  *posix*) :
+    set -o posix ;; #(
+  *) :
+     ;;
+esac
+fi
+
+
+as_nl='
+'
+export as_nl
+# Printing a long string crashes Solaris 7 /usr/bin/printf.
+as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'
+as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo
+as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo
+# Prefer a ksh shell builtin over an external printf program on Solaris,
+# but without wasting forks for bash or zsh.
+if test -z "$BASH_VERSION$ZSH_VERSION" \
+    && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then
+  as_echo='print -r --'
+  as_echo_n='print -rn --'
+elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then
+  as_echo='printf %s\n'
+  as_echo_n='printf %s'
+else
+  if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then
+    as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"'
+    as_echo_n='/usr/ucb/echo -n'
+  else
+    as_echo_body='eval expr "X$1" : "X\\(.*\\)"'
+    as_echo_n_body='eval
+      arg=$1;
+      case $arg in #(
+      *"$as_nl"*)
+	expr "X$arg" : "X\\(.*\\)$as_nl";
+	arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;;
+      esac;
+      expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl"
+    '
+    export as_echo_n_body
+    as_echo_n='sh -c $as_echo_n_body as_echo'
+  fi
+  export as_echo_body
+  as_echo='sh -c $as_echo_body as_echo'
+fi
+
+# The user is always right.
+if test "${PATH_SEPARATOR+set}" != set; then
+  PATH_SEPARATOR=:
+  (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && {
+    (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 ||
+      PATH_SEPARATOR=';'
+  }
+fi
+
+
+# IFS
+# We need space, tab and new line, in precisely that order.  Quoting is
+# there to prevent editors from complaining about space-tab.
+# (If _AS_PATH_WALK were called with IFS unset, it would disable word
+# splitting by setting IFS to empty value.)
+IFS=" ""	$as_nl"
+
+# Find who we are.  Look in the path if we contain no directory separator.
+as_myself=
+case $0 in #((
+  *[\\/]* ) as_myself=$0 ;;
+  *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break
+  done
+IFS=$as_save_IFS
+
+     ;;
+esac
+# We did not find ourselves, most probably we were run as `sh COMMAND'
+# in which case we are not to be found in the path.
+if test "x$as_myself" = x; then
+  as_myself=$0
+fi
+if test ! -f "$as_myself"; then
+  $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2
+  exit 1
+fi
+
+# Unset variables that we do not need and which cause bugs (e.g. in
+# pre-3.0 UWIN ksh).  But do not cause bugs in bash 2.01; the "|| exit 1"
+# suppresses any "Segmentation fault" message there.  '((' could
+# trigger a bug in pdksh 5.2.14.
+for as_var in BASH_ENV ENV MAIL MAILPATH
+do eval test x\${$as_var+set} = xset \
+  && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || :
+done
+PS1='$ '
+PS2='> '
+PS4='+ '
+
+# NLS nuisances.
+LC_ALL=C
+export LC_ALL
+LANGUAGE=C
+export LANGUAGE
+
+# CDPATH.
+(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
+
+# Use a proper internal environment variable to ensure we don't fall
+  # into an infinite loop, continuously re-executing ourselves.
+  if test x"${_as_can_reexec}" != xno && test "x$CONFIG_SHELL" != x; then
+    _as_can_reexec=no; export _as_can_reexec;
+    # We cannot yet assume a decent shell, so we have to provide a
+# neutralization value for shells without unset; and this also
+# works around shells that cannot unset nonexistent variables.
+# Preserve -v and -x to the replacement shell.
+BASH_ENV=/dev/null
+ENV=/dev/null
+(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV
+case $- in # ((((
+  *v*x* | *x*v* ) as_opts=-vx ;;
+  *v* ) as_opts=-v ;;
+  *x* ) as_opts=-x ;;
+  * ) as_opts= ;;
+esac
+exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"}
+# Admittedly, this is quite paranoid, since all the known shells bail
+# out after a failed `exec'.
+$as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2
+as_fn_exit 255
+  fi
+  # We don't want this to propagate to other subprocesses.
+          { _as_can_reexec=; unset _as_can_reexec;}
+if test "x$CONFIG_SHELL" = x; then
+  as_bourne_compatible="if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then :
+  emulate sh
+  NULLCMD=:
+  # Pre-4.2 versions of Zsh do word splitting on \${1+\"\$@\"}, which
+  # is contrary to our usage.  Disable this feature.
+  alias -g '\${1+\"\$@\"}'='\"\$@\"'
+  setopt NO_GLOB_SUBST
+else
+  case \`(set -o) 2>/dev/null\` in #(
+  *posix*) :
+    set -o posix ;; #(
+  *) :
+     ;;
+esac
+fi
+"
+  as_required="as_fn_return () { (exit \$1); }
+as_fn_success () { as_fn_return 0; }
+as_fn_failure () { as_fn_return 1; }
+as_fn_ret_success () { return 0; }
+as_fn_ret_failure () { return 1; }
+
+exitcode=0
+as_fn_success || { exitcode=1; echo as_fn_success failed.; }
+as_fn_failure && { exitcode=1; echo as_fn_failure succeeded.; }
+as_fn_ret_success || { exitcode=1; echo as_fn_ret_success failed.; }
+as_fn_ret_failure && { exitcode=1; echo as_fn_ret_failure succeeded.; }
+if ( set x; as_fn_ret_success y && test x = \"\$1\" ); then :
+
+else
+  exitcode=1; echo positional parameters were not saved.
+fi
+test x\$exitcode = x0 || exit 1
+test -x / || exit 1"
+  as_suggested="  as_lineno_1=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_1a=\$LINENO
+  as_lineno_2=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_2a=\$LINENO
+  eval 'test \"x\$as_lineno_1'\$as_run'\" != \"x\$as_lineno_2'\$as_run'\" &&
+  test \"x\`expr \$as_lineno_1'\$as_run' + 1\`\" = \"x\$as_lineno_2'\$as_run'\"' || exit 1
+
+  test -n \"\${ZSH_VERSION+set}\${BASH_VERSION+set}\" || (
+    ECHO='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'
+    ECHO=\$ECHO\$ECHO\$ECHO\$ECHO\$ECHO
+    ECHO=\$ECHO\$ECHO\$ECHO\$ECHO\$ECHO\$ECHO
+    PATH=/empty FPATH=/empty; export PATH FPATH
+    test \"X\`printf %s \$ECHO\`\" = \"X\$ECHO\" \\
+      || test \"X\`print -r -- \$ECHO\`\" = \"X\$ECHO\" ) || exit 1
+test \$(( 1 + 1 )) = 2 || exit 1"
+  if (eval "$as_required") 2>/dev/null; then :
+  as_have_required=yes
+else
+  as_have_required=no
+fi
+  if test x$as_have_required = xyes && (eval "$as_suggested") 2>/dev/null; then :
+
+else
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+as_found=false
+for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  as_found=:
+  case $as_dir in #(
+	 /*)
+	   for as_base in sh bash ksh sh5; do
+	     # Try only shells that exist, to save several forks.
+	     as_shell=$as_dir/$as_base
+	     if { test -f "$as_shell" || test -f "$as_shell.exe"; } &&
+		    { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$as_shell"; } 2>/dev/null; then :
+  CONFIG_SHELL=$as_shell as_have_required=yes
+		   if { $as_echo "$as_bourne_compatible""$as_suggested" | as_run=a "$as_shell"; } 2>/dev/null; then :
+  break 2
+fi
+fi
+	   done;;
+       esac
+  as_found=false
+done
+$as_found || { if { test -f "$SHELL" || test -f "$SHELL.exe"; } &&
+	      { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$SHELL"; } 2>/dev/null; then :
+  CONFIG_SHELL=$SHELL as_have_required=yes
+fi; }
+IFS=$as_save_IFS
+
+
+      if test "x$CONFIG_SHELL" != x; then :
+  export CONFIG_SHELL
+             # We cannot yet assume a decent shell, so we have to provide a
+# neutralization value for shells without unset; and this also
+# works around shells that cannot unset nonexistent variables.
+# Preserve -v and -x to the replacement shell.
+BASH_ENV=/dev/null
+ENV=/dev/null
+(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV
+case $- in # ((((
+  *v*x* | *x*v* ) as_opts=-vx ;;
+  *v* ) as_opts=-v ;;
+  *x* ) as_opts=-x ;;
+  * ) as_opts= ;;
+esac
+exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"}
+# Admittedly, this is quite paranoid, since all the known shells bail
+# out after a failed `exec'.
+$as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2
+exit 255
+fi
+
+    if test x$as_have_required = xno; then :
+  $as_echo "$0: This script requires a shell more modern than all"
+  $as_echo "$0: the shells that I found on your system."
+  if test x${ZSH_VERSION+set} = xset ; then
+    $as_echo "$0: In particular, zsh $ZSH_VERSION has bugs and should"
+    $as_echo "$0: be upgraded to zsh 4.3.4 or later."
+  else
+    $as_echo "$0: Please tell bug-autoconf@gnu.org about your system,
+$0: including any error possibly output before this
+$0: message. Then install a modern shell, or manually run
+$0: the script under such a shell if you do have one."
+  fi
+  exit 1
+fi
+fi
+fi
+SHELL=${CONFIG_SHELL-/bin/sh}
+export SHELL
+# Unset more variables known to interfere with behavior of common tools.
+CLICOLOR_FORCE= GREP_OPTIONS=
+unset CLICOLOR_FORCE GREP_OPTIONS
+
+## --------------------- ##
+## M4sh Shell Functions. ##
+## --------------------- ##
+# as_fn_unset VAR
+# ---------------
+# Portably unset VAR.
+as_fn_unset ()
+{
+  { eval $1=; unset $1;}
+}
+as_unset=as_fn_unset
+
+# as_fn_set_status STATUS
+# -----------------------
+# Set $? to STATUS, without forking.
+as_fn_set_status ()
+{
+  return $1
+} # as_fn_set_status
+
+# as_fn_exit STATUS
+# -----------------
+# Exit the shell with STATUS, even in a "trap 0" or "set -e" context.
+as_fn_exit ()
+{
+  set +e
+  as_fn_set_status $1
+  exit $1
+} # as_fn_exit
+
+# as_fn_mkdir_p
+# -------------
+# Create "$as_dir" as a directory, including parents if necessary.
+as_fn_mkdir_p ()
+{
+
+  case $as_dir in #(
+  -*) as_dir=./$as_dir;;
+  esac
+  test -d "$as_dir" || eval $as_mkdir_p || {
+    as_dirs=
+    while :; do
+      case $as_dir in #(
+      *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'(
+      *) as_qdir=$as_dir;;
+      esac
+      as_dirs="'$as_qdir' $as_dirs"
+      as_dir=`$as_dirname -- "$as_dir" ||
+$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+	 X"$as_dir" : 'X\(//\)[^/]' \| \
+	 X"$as_dir" : 'X\(//\)$' \| \
+	 X"$as_dir" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X"$as_dir" |
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)[^/].*/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\).*/{
+	    s//\1/
+	    q
+	  }
+	  s/.*/./; q'`
+      test -d "$as_dir" && break
+    done
+    test -z "$as_dirs" || eval "mkdir $as_dirs"
+  } || test -d "$as_dir" || as_fn_error $? "cannot create directory $as_dir"
+
+
+} # as_fn_mkdir_p
+
+# as_fn_executable_p FILE
+# -----------------------
+# Test if FILE is an executable regular file.
+as_fn_executable_p ()
+{
+  test -f "$1" && test -x "$1"
+} # as_fn_executable_p
+# as_fn_append VAR VALUE
+# ----------------------
+# Append the text in VALUE to the end of the definition contained in VAR. Take
+# advantage of any shell optimizations that allow amortized linear growth over
+# repeated appends, instead of the typical quadratic growth present in naive
+# implementations.
+if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then :
+  eval 'as_fn_append ()
+  {
+    eval $1+=\$2
+  }'
+else
+  as_fn_append ()
+  {
+    eval $1=\$$1\$2
+  }
+fi # as_fn_append
+
+# as_fn_arith ARG...
+# ------------------
+# Perform arithmetic evaluation on the ARGs, and store the result in the
+# global $as_val. Take advantage of shells that can avoid forks. The arguments
+# must be portable across $(()) and expr.
+if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then :
+  eval 'as_fn_arith ()
+  {
+    as_val=$(( $* ))
+  }'
+else
+  as_fn_arith ()
+  {
+    as_val=`expr "$@" || test $? -eq 1`
+  }
+fi # as_fn_arith
+
+
+# as_fn_error STATUS ERROR [LINENO LOG_FD]
+# ----------------------------------------
+# Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are
+# provided, also output the error to LOG_FD, referencing LINENO. Then exit the
+# script with STATUS, using 1 if that was 0.
+as_fn_error ()
+{
+  as_status=$1; test $as_status -eq 0 && as_status=1
+  if test "$4"; then
+    as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+    $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4
+  fi
+  $as_echo "$as_me: error: $2" >&2
+  as_fn_exit $as_status
+} # as_fn_error
+
+if expr a : '\(a\)' >/dev/null 2>&1 &&
+   test "X`expr 00001 : '.*\(...\)'`" = X001; then
+  as_expr=expr
+else
+  as_expr=false
+fi
+
+if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then
+  as_basename=basename
+else
+  as_basename=false
+fi
+
+if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then
+  as_dirname=dirname
+else
+  as_dirname=false
+fi
+
+as_me=`$as_basename -- "$0" ||
+$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \
+	 X"$0" : 'X\(//\)$' \| \
+	 X"$0" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X/"$0" |
+    sed '/^.*\/\([^/][^/]*\)\/*$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\/\(\/\/\)$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\/\(\/\).*/{
+	    s//\1/
+	    q
+	  }
+	  s/.*/./; q'`
+
+# Avoid depending upon Character Ranges.
+as_cr_letters='abcdefghijklmnopqrstuvwxyz'
+as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
+as_cr_Letters=$as_cr_letters$as_cr_LETTERS
+as_cr_digits='0123456789'
+as_cr_alnum=$as_cr_Letters$as_cr_digits
+
+
+  as_lineno_1=$LINENO as_lineno_1a=$LINENO
+  as_lineno_2=$LINENO as_lineno_2a=$LINENO
+  eval 'test "x$as_lineno_1'$as_run'" != "x$as_lineno_2'$as_run'" &&
+  test "x`expr $as_lineno_1'$as_run' + 1`" = "x$as_lineno_2'$as_run'"' || {
+  # Blame Lee E. McMahon (1931-1989) for sed's syntax.  :-)
+  sed -n '
+    p
+    /[$]LINENO/=
+  ' <$as_myself |
+    sed '
+      s/[$]LINENO.*/&-/
+      t lineno
+      b
+      :lineno
+      N
+      :loop
+      s/[$]LINENO\([^'$as_cr_alnum'_].*\n\)\(.*\)/\2\1\2/
+      t loop
+      s/-\n.*//
+    ' >$as_me.lineno &&
+  chmod +x "$as_me.lineno" ||
+    { $as_echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2; as_fn_exit 1; }
+
+  # If we had to re-execute with $CONFIG_SHELL, we're ensured to have
+  # already done that, so ensure we don't try to do so again and fall
+  # in an infinite loop.  This has already happened in practice.
+  _as_can_reexec=no; export _as_can_reexec
+  # Don't try to exec as it changes $[0], causing all sort of problems
+  # (the dirname of $[0] is not the place where we might find the
+  # original and so on.  Autoconf is especially sensitive to this).
+  . "./$as_me.lineno"
+  # Exit status is that of the last command.
+  exit
+}
+
+ECHO_C= ECHO_N= ECHO_T=
+case `echo -n x` in #(((((
+-n*)
+  case `echo 'xy\c'` in
+  *c*) ECHO_T='	';;	# ECHO_T is single tab character.
+  xy)  ECHO_C='\c';;
+  *)   echo `echo ksh88 bug on AIX 6.1` > /dev/null
+       ECHO_T='	';;
+  esac;;
+*)
+  ECHO_N='-n';;
+esac
+
+rm -f conf$$ conf$$.exe conf$$.file
+if test -d conf$$.dir; then
+  rm -f conf$$.dir/conf$$.file
+else
+  rm -f conf$$.dir
+  mkdir conf$$.dir 2>/dev/null
+fi
+if (echo >conf$$.file) 2>/dev/null; then
+  if ln -s conf$$.file conf$$ 2>/dev/null; then
+    as_ln_s='ln -s'
+    # ... but there are two gotchas:
+    # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail.
+    # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable.
+    # In both cases, we have to default to `cp -pR'.
+    ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe ||
+      as_ln_s='cp -pR'
+  elif ln conf$$.file conf$$ 2>/dev/null; then
+    as_ln_s=ln
+  else
+    as_ln_s='cp -pR'
+  fi
+else
+  as_ln_s='cp -pR'
+fi
+rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file
+rmdir conf$$.dir 2>/dev/null
+
+if mkdir -p . 2>/dev/null; then
+  as_mkdir_p='mkdir -p "$as_dir"'
+else
+  test -d ./-p && rmdir ./-p
+  as_mkdir_p=false
+fi
+
+as_test_x='test -x'
+as_executable_p=as_fn_executable_p
+
+# Sed expression to map a string onto a valid CPP name.
+as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'"
+
+# Sed expression to map a string onto a valid variable name.
+as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'"
+
+SHELL=${CONFIG_SHELL-/bin/sh}
+
+
+test -n "$DJDIR" || exec 7<&0 </dev/null
+exec 6>&1
+
+# Name of the host.
+# hostname on some systems (SVR3.2, old GNU/Linux) returns a bogus exit status,
+# so uname gets run too.
+ac_hostname=`(hostname || uname -n) 2>/dev/null | sed 1q`
+
+#
+# Initializations.
+#
+ac_default_prefix=/usr/local
+ac_clean_files=
+ac_config_libobj_dir=.
+LIBOBJS=
+cross_compiling=no
+subdirs=
+MFLAGS=
+MAKEFLAGS=
+
+# Identity of this package.
+PACKAGE_NAME='connman'
+PACKAGE_TARNAME='connman'
+PACKAGE_VERSION='1.29'
+PACKAGE_STRING='connman 1.29'
+PACKAGE_BUGREPORT=''
+PACKAGE_URL=''
+
+ac_default_prefix=/usr/local
+# Factoring default headers for most tests.
+ac_includes_default="\
+#include <stdio.h>
+#ifdef HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
+#ifdef HAVE_SYS_STAT_H
+# include <sys/stat.h>
+#endif
+#ifdef STDC_HEADERS
+# include <stdlib.h>
+# include <stddef.h>
+#else
+# ifdef HAVE_STDLIB_H
+#  include <stdlib.h>
+# endif
+#endif
+#ifdef HAVE_STRING_H
+# if !defined STDC_HEADERS && defined HAVE_MEMORY_H
+#  include <memory.h>
+# endif
+# include <string.h>
+#endif
+#ifdef HAVE_STRINGS_H
+# include <strings.h>
+#endif
+#ifdef HAVE_INTTYPES_H
+# include <inttypes.h>
+#endif
+#ifdef HAVE_STDINT_H
+# include <stdint.h>
+#endif
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif"
+
+ac_subst_vars='am__EXEEXT_FALSE
+am__EXEEXT_TRUE
+LTLIBOBJS
+LIBOBJS
+VPN_FALSE
+VPN_TRUE
+DATAFILES_FALSE
+DATAFILES_TRUE
+WPASUPPLICANT
+GNUTLS_LIBS
+GNUTLS_CFLAGS
+CLIENT_FALSE
+CLIENT_TRUE
+IPTABLES_SAVE
+TOOLS_FALSE
+TOOLS_TRUE
+WISPR_FALSE
+WISPR_TRUE
+NEARD_FALSE
+NEARD_TRUE
+PACRUNNER_FALSE
+PACRUNNER_TRUE
+DUNDEE_FALSE
+DUNDEE_TRUE
+OFONO_FALSE
+OFONO_TRUE
+BLUETOOTH_FALSE
+BLUETOOTH_TRUE
+WIFI_FALSE
+WIFI_TRUE
+GADGET_FALSE
+GADGET_TRUE
+ETHERNET_FALSE
+ETHERNET_TRUE
+LOOPBACK_FALSE
+LOOPBACK_TRUE
+SELINUX_FALSE
+SELINUX_TRUE
+POLKIT_FALSE
+POLKIT_TRUE
+POLKIT_DATADIR
+NMCOMPAT_FALSE
+NMCOMPAT_TRUE
+TEST_FALSE
+TEST_TRUE
+XTABLES_LIBS
+XTABLES_CFLAGS
+SYSTEMD_FALSE
+SYSTEMD_TRUE
+SYSTEMD_UNITDIR
+DBUS_DATADIR
+DBUS_CONFDIR
+DBUS_LIBS
+DBUS_CFLAGS
+GLIB_LIBS
+GLIB_CFLAGS
+SESSION_POLICY_LOCAL_BUILTIN_FALSE
+SESSION_POLICY_LOCAL_BUILTIN_TRUE
+SESSION_POLICY_LOCAL_FALSE
+SESSION_POLICY_LOCAL_TRUE
+TIST_BUILTIN_FALSE
+TIST_BUILTIN_TRUE
+TIST_FALSE
+TIST_TRUE
+IOSPM_FALSE
+IOSPM_TRUE
+PPTP_BUILTIN_FALSE
+PPTP_BUILTIN_TRUE
+PPTP_FALSE
+PPTP_TRUE
+PPTP
+L2TP_BUILTIN_FALSE
+L2TP_BUILTIN_TRUE
+L2TP_FALSE
+L2TP_TRUE
+L2TP
+PPPD
+VPNC_BUILTIN_FALSE
+VPNC_BUILTIN_TRUE
+VPNC_FALSE
+VPNC_TRUE
+VPNC
+OPENVPN_BUILTIN_FALSE
+OPENVPN_BUILTIN_TRUE
+OPENVPN_FALSE
+OPENVPN_TRUE
+OPENVPN
+OPENCONNECT_BUILTIN_FALSE
+OPENCONNECT_BUILTIN_TRUE
+OPENCONNECT_FALSE
+OPENCONNECT_TRUE
+OPENCONNECT
+HH2SERIAL_GPS_BUILTIN_FALSE
+HH2SERIAL_GPS_BUILTIN_TRUE
+HH2SERIAL_GPS_FALSE
+HH2SERIAL_GPS_TRUE
+CPP
+OTOOL64
+OTOOL
+LIPO
+NMEDIT
+DSYMUTIL
+MANIFEST_TOOL
+RANLIB
+ac_ct_AR
+AR
+DLLTOOL
+OBJDUMP
+LN_S
+NM
+ac_ct_DUMPBIN
+DUMPBIN
+LD
+FGREP
+EGREP
+GREP
+SED
+host_os
+host_vendor
+host_cpu
+host
+build_os
+build_vendor
+build_cpu
+build
+LIBTOOL
+am__fastdepCC_FALSE
+am__fastdepCC_TRUE
+CCDEPMODE
+am__nodep
+AMDEPBACKSLASH
+AMDEP_FALSE
+AMDEP_TRUE
+am__quote
+am__include
+DEPDIR
+OBJEXT
+EXEEXT
+ac_ct_CC
+CPPFLAGS
+LDFLAGS
+CFLAGS
+CC
+abs_top_builddir
+abs_top_srcdir
+PKG_CONFIG_LIBDIR
+PKG_CONFIG_PATH
+PKG_CONFIG
+MAINT
+MAINTAINER_MODE_FALSE
+MAINTAINER_MODE_TRUE
+AM_BACKSLASH
+AM_DEFAULT_VERBOSITY
+AM_DEFAULT_V
+AM_V
+am__untar
+am__tar
+AMTAR
+am__leading_dot
+SET_MAKE
+AWK
+mkdir_p
+MKDIR_P
+INSTALL_STRIP_PROGRAM
+STRIP
+install_sh
+MAKEINFO
+AUTOHEADER
+AUTOMAKE
+AUTOCONF
+ACLOCAL
+VERSION
+PACKAGE
+CYGPATH_W
+am__isrc
+INSTALL_DATA
+INSTALL_SCRIPT
+INSTALL_PROGRAM
+target_alias
+host_alias
+build_alias
+LIBS
+ECHO_T
+ECHO_N
+ECHO_C
+DEFS
+mandir
+localedir
+libdir
+psdir
+pdfdir
+dvidir
+htmldir
+infodir
+docdir
+oldincludedir
+includedir
+localstatedir
+sharedstatedir
+sysconfdir
+datadir
+datarootdir
+libexecdir
+sbindir
+bindir
+program_transform_name
+prefix
+exec_prefix
+PACKAGE_URL
+PACKAGE_BUGREPORT
+PACKAGE_STRING
+PACKAGE_VERSION
+PACKAGE_TARNAME
+PACKAGE_NAME
+PATH_SEPARATOR
+SHELL'
+ac_subst_files=''
+ac_user_opts='
+enable_option_checking
+enable_silent_rules
+enable_maintainer_mode
+enable_dependency_tracking
+enable_static
+enable_shared
+with_pic
+enable_fast_install
+with_gnu_ld
+with_sysroot
+enable_libtool_lock
+enable_optimization
+enable_debug
+enable_pie
+enable_hh2serial_gps
+with_openconnect
+enable_openconnect
+with_openvpn
+enable_openvpn
+with_vpnc
+enable_vpnc
+with_l2tp
+enable_l2tp
+with_pptp
+enable_pptp
+enable_iospm
+enable_tist
+enable_session_policy_local
+with_stats_max_file_size
+with_dbusconfdir
+with_dbusdatadir
+with_systemdunitdir
+enable_test
+enable_nmcompat
+enable_polkit
+enable_selinux
+enable_loopback
+enable_ethernet
+enable_gadget
+enable_wifi
+enable_bluetooth
+enable_ofono
+enable_dundee
+enable_pacrunner
+enable_neard
+enable_wispr
+enable_tools
+enable_client
+enable_datafiles
+'
+      ac_precious_vars='build_alias
+host_alias
+target_alias
+PKG_CONFIG
+PKG_CONFIG_PATH
+PKG_CONFIG_LIBDIR
+CC
+CFLAGS
+LDFLAGS
+LIBS
+CPPFLAGS
+CPP
+GLIB_CFLAGS
+GLIB_LIBS
+DBUS_CFLAGS
+DBUS_LIBS
+XTABLES_CFLAGS
+XTABLES_LIBS
+GNUTLS_CFLAGS
+GNUTLS_LIBS'
+
+
+# Initialize some variables set by options.
+ac_init_help=
+ac_init_version=false
+ac_unrecognized_opts=
+ac_unrecognized_sep=
+# The variables have the same names as the options, with
+# dashes changed to underlines.
+cache_file=/dev/null
+exec_prefix=NONE
+no_create=
+no_recursion=
+prefix=NONE
+program_prefix=NONE
+program_suffix=NONE
+program_transform_name=s,x,x,
+silent=
+site=
+srcdir=
+verbose=
+x_includes=NONE
+x_libraries=NONE
+
+# Installation directory options.
+# These are left unexpanded so users can "make install exec_prefix=/foo"
+# and all the variables that are supposed to be based on exec_prefix
+# by default will actually change.
+# Use braces instead of parens because sh, perl, etc. also accept them.
+# (The list follows the same order as the GNU Coding Standards.)
+bindir='${exec_prefix}/bin'
+sbindir='${exec_prefix}/sbin'
+libexecdir='${exec_prefix}/libexec'
+datarootdir='${prefix}/share'
+datadir='${datarootdir}'
+sysconfdir='${prefix}/etc'
+sharedstatedir='${prefix}/com'
+localstatedir='${prefix}/var'
+includedir='${prefix}/include'
+oldincludedir='/usr/include'
+docdir='${datarootdir}/doc/${PACKAGE_TARNAME}'
+infodir='${datarootdir}/info'
+htmldir='${docdir}'
+dvidir='${docdir}'
+pdfdir='${docdir}'
+psdir='${docdir}'
+libdir='${exec_prefix}/lib'
+localedir='${datarootdir}/locale'
+mandir='${datarootdir}/man'
+
+ac_prev=
+ac_dashdash=
+for ac_option
+do
+  # If the previous option needs an argument, assign it.
+  if test -n "$ac_prev"; then
+    eval $ac_prev=\$ac_option
+    ac_prev=
+    continue
+  fi
+
+  case $ac_option in
+  *=?*) ac_optarg=`expr "X$ac_option" : '[^=]*=\(.*\)'` ;;
+  *=)   ac_optarg= ;;
+  *)    ac_optarg=yes ;;
+  esac
+
+  # Accept the important Cygnus configure options, so we can diagnose typos.
+
+  case $ac_dashdash$ac_option in
+  --)
+    ac_dashdash=yes ;;
+
+  -bindir | --bindir | --bindi | --bind | --bin | --bi)
+    ac_prev=bindir ;;
+  -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*)
+    bindir=$ac_optarg ;;
+
+  -build | --build | --buil | --bui | --bu)
+    ac_prev=build_alias ;;
+  -build=* | --build=* | --buil=* | --bui=* | --bu=*)
+    build_alias=$ac_optarg ;;
+
+  -cache-file | --cache-file | --cache-fil | --cache-fi \
+  | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c)
+    ac_prev=cache_file ;;
+  -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \
+  | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*)
+    cache_file=$ac_optarg ;;
+
+  --config-cache | -C)
+    cache_file=config.cache ;;
+
+  -datadir | --datadir | --datadi | --datad)
+    ac_prev=datadir ;;
+  -datadir=* | --datadir=* | --datadi=* | --datad=*)
+    datadir=$ac_optarg ;;
+
+  -datarootdir | --datarootdir | --datarootdi | --datarootd | --dataroot \
+  | --dataroo | --dataro | --datar)
+    ac_prev=datarootdir ;;
+  -datarootdir=* | --datarootdir=* | --datarootdi=* | --datarootd=* \
+  | --dataroot=* | --dataroo=* | --dataro=* | --datar=*)
+    datarootdir=$ac_optarg ;;
+
+  -disable-* | --disable-*)
+    ac_useropt=`expr "x$ac_option" : 'x-*disable-\(.*\)'`
+    # Reject names that are not valid shell variable names.
+    expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null &&
+      as_fn_error $? "invalid feature name: $ac_useropt"
+    ac_useropt_orig=$ac_useropt
+    ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
+    case $ac_user_opts in
+      *"
+"enable_$ac_useropt"
+"*) ;;
+      *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--disable-$ac_useropt_orig"
+	 ac_unrecognized_sep=', ';;
+    esac
+    eval enable_$ac_useropt=no ;;
+
+  -docdir | --docdir | --docdi | --doc | --do)
+    ac_prev=docdir ;;
+  -docdir=* | --docdir=* | --docdi=* | --doc=* | --do=*)
+    docdir=$ac_optarg ;;
+
+  -dvidir | --dvidir | --dvidi | --dvid | --dvi | --dv)
+    ac_prev=dvidir ;;
+  -dvidir=* | --dvidir=* | --dvidi=* | --dvid=* | --dvi=* | --dv=*)
+    dvidir=$ac_optarg ;;
+
+  -enable-* | --enable-*)
+    ac_useropt=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'`
+    # Reject names that are not valid shell variable names.
+    expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null &&
+      as_fn_error $? "invalid feature name: $ac_useropt"
+    ac_useropt_orig=$ac_useropt
+    ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
+    case $ac_user_opts in
+      *"
+"enable_$ac_useropt"
+"*) ;;
+      *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--enable-$ac_useropt_orig"
+	 ac_unrecognized_sep=', ';;
+    esac
+    eval enable_$ac_useropt=\$ac_optarg ;;
+
+  -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \
+  | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \
+  | --exec | --exe | --ex)
+    ac_prev=exec_prefix ;;
+  -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \
+  | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \
+  | --exec=* | --exe=* | --ex=*)
+    exec_prefix=$ac_optarg ;;
+
+  -gas | --gas | --ga | --g)
+    # Obsolete; use --with-gas.
+    with_gas=yes ;;
+
+  -help | --help | --hel | --he | -h)
+    ac_init_help=long ;;
+  -help=r* | --help=r* | --hel=r* | --he=r* | -hr*)
+    ac_init_help=recursive ;;
+  -help=s* | --help=s* | --hel=s* | --he=s* | -hs*)
+    ac_init_help=short ;;
+
+  -host | --host | --hos | --ho)
+    ac_prev=host_alias ;;
+  -host=* | --host=* | --hos=* | --ho=*)
+    host_alias=$ac_optarg ;;
+
+  -htmldir | --htmldir | --htmldi | --htmld | --html | --htm | --ht)
+    ac_prev=htmldir ;;
+  -htmldir=* | --htmldir=* | --htmldi=* | --htmld=* | --html=* | --htm=* \
+  | --ht=*)
+    htmldir=$ac_optarg ;;
+
+  -includedir | --includedir | --includedi | --included | --include \
+  | --includ | --inclu | --incl | --inc)
+    ac_prev=includedir ;;
+  -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \
+  | --includ=* | --inclu=* | --incl=* | --inc=*)
+    includedir=$ac_optarg ;;
+
+  -infodir | --infodir | --infodi | --infod | --info | --inf)
+    ac_prev=infodir ;;
+  -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*)
+    infodir=$ac_optarg ;;
+
+  -libdir | --libdir | --libdi | --libd)
+    ac_prev=libdir ;;
+  -libdir=* | --libdir=* | --libdi=* | --libd=*)
+    libdir=$ac_optarg ;;
+
+  -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \
+  | --libexe | --libex | --libe)
+    ac_prev=libexecdir ;;
+  -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \
+  | --libexe=* | --libex=* | --libe=*)
+    libexecdir=$ac_optarg ;;
+
+  -localedir | --localedir | --localedi | --localed | --locale)
+    ac_prev=localedir ;;
+  -localedir=* | --localedir=* | --localedi=* | --localed=* | --locale=*)
+    localedir=$ac_optarg ;;
+
+  -localstatedir | --localstatedir | --localstatedi | --localstated \
+  | --localstate | --localstat | --localsta | --localst | --locals)
+    ac_prev=localstatedir ;;
+  -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \
+  | --localstate=* | --localstat=* | --localsta=* | --localst=* | --locals=*)
+    localstatedir=$ac_optarg ;;
+
+  -mandir | --mandir | --mandi | --mand | --man | --ma | --m)
+    ac_prev=mandir ;;
+  -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*)
+    mandir=$ac_optarg ;;
+
+  -nfp | --nfp | --nf)
+    # Obsolete; use --without-fp.
+    with_fp=no ;;
+
+  -no-create | --no-create | --no-creat | --no-crea | --no-cre \
+  | --no-cr | --no-c | -n)
+    no_create=yes ;;
+
+  -no-recursion | --no-recursion | --no-recursio | --no-recursi \
+  | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r)
+    no_recursion=yes ;;
+
+  -oldincludedir | --oldincludedir | --oldincludedi | --oldincluded \
+  | --oldinclude | --oldinclud | --oldinclu | --oldincl | --oldinc \
+  | --oldin | --oldi | --old | --ol | --o)
+    ac_prev=oldincludedir ;;
+  -oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \
+  | --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \
+  | --oldin=* | --oldi=* | --old=* | --ol=* | --o=*)
+    oldincludedir=$ac_optarg ;;
+
+  -prefix | --prefix | --prefi | --pref | --pre | --pr | --p)
+    ac_prev=prefix ;;
+  -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*)
+    prefix=$ac_optarg ;;
+
+  -program-prefix | --program-prefix | --program-prefi | --program-pref \
+  | --program-pre | --program-pr | --program-p)
+    ac_prev=program_prefix ;;
+  -program-prefix=* | --program-prefix=* | --program-prefi=* \
+  | --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*)
+    program_prefix=$ac_optarg ;;
+
+  -program-suffix | --program-suffix | --program-suffi | --program-suff \
+  | --program-suf | --program-su | --program-s)
+    ac_prev=program_suffix ;;
+  -program-suffix=* | --program-suffix=* | --program-suffi=* \
+  | --program-suff=* | --program-suf=* | --program-su=* | --program-s=*)
+    program_suffix=$ac_optarg ;;
+
+  -program-transform-name | --program-transform-name \
+  | --program-transform-nam | --program-transform-na \
+  | --program-transform-n | --program-transform- \
+  | --program-transform | --program-transfor \
+  | --program-transfo | --program-transf \
+  | --program-trans | --program-tran \
+  | --progr-tra | --program-tr | --program-t)
+    ac_prev=program_transform_name ;;
+  -program-transform-name=* | --program-transform-name=* \
+  | --program-transform-nam=* | --program-transform-na=* \
+  | --program-transform-n=* | --program-transform-=* \
+  | --program-transform=* | --program-transfor=* \
+  | --program-transfo=* | --program-transf=* \
+  | --program-trans=* | --program-tran=* \
+  | --progr-tra=* | --program-tr=* | --program-t=*)
+    program_transform_name=$ac_optarg ;;
+
+  -pdfdir | --pdfdir | --pdfdi | --pdfd | --pdf | --pd)
+    ac_prev=pdfdir ;;
+  -pdfdir=* | --pdfdir=* | --pdfdi=* | --pdfd=* | --pdf=* | --pd=*)
+    pdfdir=$ac_optarg ;;
+
+  -psdir | --psdir | --psdi | --psd | --ps)
+    ac_prev=psdir ;;
+  -psdir=* | --psdir=* | --psdi=* | --psd=* | --ps=*)
+    psdir=$ac_optarg ;;
+
+  -q | -quiet | --quiet | --quie | --qui | --qu | --q \
+  | -silent | --silent | --silen | --sile | --sil)
+    silent=yes ;;
+
+  -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
+    ac_prev=sbindir ;;
+  -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
+  | --sbi=* | --sb=*)
+    sbindir=$ac_optarg ;;
+
+  -sharedstatedir | --sharedstatedir | --sharedstatedi \
+  | --sharedstated | --sharedstate | --sharedstat | --sharedsta \
+  | --sharedst | --shareds | --shared | --share | --shar \
+  | --sha | --sh)
+    ac_prev=sharedstatedir ;;
+  -sharedstatedir=* | --sharedstatedir=* | --sharedstatedi=* \
+  | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \
+  | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \
+  | --sha=* | --sh=*)
+    sharedstatedir=$ac_optarg ;;
+
+  -site | --site | --sit)
+    ac_prev=site ;;
+  -site=* | --site=* | --sit=*)
+    site=$ac_optarg ;;
+
+  -srcdir | --srcdir | --srcdi | --srcd | --src | --sr)
+    ac_prev=srcdir ;;
+  -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*)
+    srcdir=$ac_optarg ;;
+
+  -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \
+  | --syscon | --sysco | --sysc | --sys | --sy)
+    ac_prev=sysconfdir ;;
+  -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \
+  | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*)
+    sysconfdir=$ac_optarg ;;
+
+  -target | --target | --targe | --targ | --tar | --ta | --t)
+    ac_prev=target_alias ;;
+  -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*)
+    target_alias=$ac_optarg ;;
+
+  -v | -verbose | --verbose | --verbos | --verbo | --verb)
+    verbose=yes ;;
+
+  -version | --version | --versio | --versi | --vers | -V)
+    ac_init_version=: ;;
+
+  -with-* | --with-*)
+    ac_useropt=`expr "x$ac_option" : 'x-*with-\([^=]*\)'`
+    # Reject names that are not valid shell variable names.
+    expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null &&
+      as_fn_error $? "invalid package name: $ac_useropt"
+    ac_useropt_orig=$ac_useropt
+    ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
+    case $ac_user_opts in
+      *"
+"with_$ac_useropt"
+"*) ;;
+      *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--with-$ac_useropt_orig"
+	 ac_unrecognized_sep=', ';;
+    esac
+    eval with_$ac_useropt=\$ac_optarg ;;
+
+  -without-* | --without-*)
+    ac_useropt=`expr "x$ac_option" : 'x-*without-\(.*\)'`
+    # Reject names that are not valid shell variable names.
+    expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null &&
+      as_fn_error $? "invalid package name: $ac_useropt"
+    ac_useropt_orig=$ac_useropt
+    ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
+    case $ac_user_opts in
+      *"
+"with_$ac_useropt"
+"*) ;;
+      *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--without-$ac_useropt_orig"
+	 ac_unrecognized_sep=', ';;
+    esac
+    eval with_$ac_useropt=no ;;
+
+  --x)
+    # Obsolete; use --with-x.
+    with_x=yes ;;
+
+  -x-includes | --x-includes | --x-include | --x-includ | --x-inclu \
+  | --x-incl | --x-inc | --x-in | --x-i)
+    ac_prev=x_includes ;;
+  -x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \
+  | --x-incl=* | --x-inc=* | --x-in=* | --x-i=*)
+    x_includes=$ac_optarg ;;
+
+  -x-libraries | --x-libraries | --x-librarie | --x-librari \
+  | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l)
+    ac_prev=x_libraries ;;
+  -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \
+  | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*)
+    x_libraries=$ac_optarg ;;
+
+  -*) as_fn_error $? "unrecognized option: \`$ac_option'
+Try \`$0 --help' for more information"
+    ;;
+
+  *=*)
+    ac_envvar=`expr "x$ac_option" : 'x\([^=]*\)='`
+    # Reject names that are not valid shell variable names.
+    case $ac_envvar in #(
+      '' | [0-9]* | *[!_$as_cr_alnum]* )
+      as_fn_error $? "invalid variable name: \`$ac_envvar'" ;;
+    esac
+    eval $ac_envvar=\$ac_optarg
+    export $ac_envvar ;;
+
+  *)
+    # FIXME: should be removed in autoconf 3.0.
+    $as_echo "$as_me: WARNING: you should use --build, --host, --target" >&2
+    expr "x$ac_option" : ".*[^-._$as_cr_alnum]" >/dev/null &&
+      $as_echo "$as_me: WARNING: invalid host type: $ac_option" >&2
+    : "${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option}"
+    ;;
+
+  esac
+done
+
+if test -n "$ac_prev"; then
+  ac_option=--`echo $ac_prev | sed 's/_/-/g'`
+  as_fn_error $? "missing argument to $ac_option"
+fi
+
+if test -n "$ac_unrecognized_opts"; then
+  case $enable_option_checking in
+    no) ;;
+    fatal) as_fn_error $? "unrecognized options: $ac_unrecognized_opts" ;;
+    *)     $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2 ;;
+  esac
+fi
+
+# Check all directory arguments for consistency.
+for ac_var in	exec_prefix prefix bindir sbindir libexecdir datarootdir \
+		datadir sysconfdir sharedstatedir localstatedir includedir \
+		oldincludedir docdir infodir htmldir dvidir pdfdir psdir \
+		libdir localedir mandir
+do
+  eval ac_val=\$$ac_var
+  # Remove trailing slashes.
+  case $ac_val in
+    */ )
+      ac_val=`expr "X$ac_val" : 'X\(.*[^/]\)' \| "X$ac_val" : 'X\(.*\)'`
+      eval $ac_var=\$ac_val;;
+  esac
+  # Be sure to have absolute directory names.
+  case $ac_val in
+    [\\/$]* | ?:[\\/]* )  continue;;
+    NONE | '' ) case $ac_var in *prefix ) continue;; esac;;
+  esac
+  as_fn_error $? "expected an absolute directory name for --$ac_var: $ac_val"
+done
+
+# There might be people who depend on the old broken behavior: `$host'
+# used to hold the argument of --host etc.
+# FIXME: To remove some day.
+build=$build_alias
+host=$host_alias
+target=$target_alias
+
+# FIXME: To remove some day.
+if test "x$host_alias" != x; then
+  if test "x$build_alias" = x; then
+    cross_compiling=maybe
+  elif test "x$build_alias" != "x$host_alias"; then
+    cross_compiling=yes
+  fi
+fi
+
+ac_tool_prefix=
+test -n "$host_alias" && ac_tool_prefix=$host_alias-
+
+test "$silent" = yes && exec 6>/dev/null
+
+
+ac_pwd=`pwd` && test -n "$ac_pwd" &&
+ac_ls_di=`ls -di .` &&
+ac_pwd_ls_di=`cd "$ac_pwd" && ls -di .` ||
+  as_fn_error $? "working directory cannot be determined"
+test "X$ac_ls_di" = "X$ac_pwd_ls_di" ||
+  as_fn_error $? "pwd does not report name of working directory"
+
+
+# Find the source files, if location was not specified.
+if test -z "$srcdir"; then
+  ac_srcdir_defaulted=yes
+  # Try the directory containing this script, then the parent directory.
+  ac_confdir=`$as_dirname -- "$as_myself" ||
+$as_expr X"$as_myself" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+	 X"$as_myself" : 'X\(//\)[^/]' \| \
+	 X"$as_myself" : 'X\(//\)$' \| \
+	 X"$as_myself" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X"$as_myself" |
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)[^/].*/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\).*/{
+	    s//\1/
+	    q
+	  }
+	  s/.*/./; q'`
+  srcdir=$ac_confdir
+  if test ! -r "$srcdir/$ac_unique_file"; then
+    srcdir=..
+  fi
+else
+  ac_srcdir_defaulted=no
+fi
+if test ! -r "$srcdir/$ac_unique_file"; then
+  test "$ac_srcdir_defaulted" = yes && srcdir="$ac_confdir or .."
+  as_fn_error $? "cannot find sources ($ac_unique_file) in $srcdir"
+fi
+ac_msg="sources are in $srcdir, but \`cd $srcdir' does not work"
+ac_abs_confdir=`(
+	cd "$srcdir" && test -r "./$ac_unique_file" || as_fn_error $? "$ac_msg"
+	pwd)`
+# When building in place, set srcdir=.
+if test "$ac_abs_confdir" = "$ac_pwd"; then
+  srcdir=.
+fi
+# Remove unnecessary trailing slashes from srcdir.
+# Double slashes in file names in object file debugging info
+# mess up M-x gdb in Emacs.
+case $srcdir in
+*/) srcdir=`expr "X$srcdir" : 'X\(.*[^/]\)' \| "X$srcdir" : 'X\(.*\)'`;;
+esac
+for ac_var in $ac_precious_vars; do
+  eval ac_env_${ac_var}_set=\${${ac_var}+set}
+  eval ac_env_${ac_var}_value=\$${ac_var}
+  eval ac_cv_env_${ac_var}_set=\${${ac_var}+set}
+  eval ac_cv_env_${ac_var}_value=\$${ac_var}
+done
+
+#
+# Report the --help message.
+#
+if test "$ac_init_help" = "long"; then
+  # Omit some internal or obsolete options to make the list less imposing.
+  # This message is too long to be a string in the A/UX 3.1 sh.
+  cat <<_ACEOF
+\`configure' configures connman 1.29 to adapt to many kinds of systems.
+
+Usage: $0 [OPTION]... [VAR=VALUE]...
+
+To assign environment variables (e.g., CC, CFLAGS...), specify them as
+VAR=VALUE.  See below for descriptions of some of the useful variables.
+
+Defaults for the options are specified in brackets.
+
+Configuration:
+  -h, --help              display this help and exit
+      --help=short        display options specific to this package
+      --help=recursive    display the short help of all the included packages
+  -V, --version           display version information and exit
+  -q, --quiet, --silent   do not print \`checking ...' messages
+      --cache-file=FILE   cache test results in FILE [disabled]
+  -C, --config-cache      alias for \`--cache-file=config.cache'
+  -n, --no-create         do not create output files
+      --srcdir=DIR        find the sources in DIR [configure dir or \`..']
+
+Installation directories:
+  --prefix=PREFIX         install architecture-independent files in PREFIX
+                          [$ac_default_prefix]
+  --exec-prefix=EPREFIX   install architecture-dependent files in EPREFIX
+                          [PREFIX]
+
+By default, \`make install' will install all the files in
+\`$ac_default_prefix/bin', \`$ac_default_prefix/lib' etc.  You can specify
+an installation prefix other than \`$ac_default_prefix' using \`--prefix',
+for instance \`--prefix=\$HOME'.
+
+For better control, use the options below.
+
+Fine tuning of the installation directories:
+  --bindir=DIR            user executables [EPREFIX/bin]
+  --sbindir=DIR           system admin executables [EPREFIX/sbin]
+  --libexecdir=DIR        program executables [EPREFIX/libexec]
+  --sysconfdir=DIR        read-only single-machine data [PREFIX/etc]
+  --sharedstatedir=DIR    modifiable architecture-independent data [PREFIX/com]
+  --localstatedir=DIR     modifiable single-machine data [PREFIX/var]
+  --libdir=DIR            object code libraries [EPREFIX/lib]
+  --includedir=DIR        C header files [PREFIX/include]
+  --oldincludedir=DIR     C header files for non-gcc [/usr/include]
+  --datarootdir=DIR       read-only arch.-independent data root [PREFIX/share]
+  --datadir=DIR           read-only architecture-independent data [DATAROOTDIR]
+  --infodir=DIR           info documentation [DATAROOTDIR/info]
+  --localedir=DIR         locale-dependent data [DATAROOTDIR/locale]
+  --mandir=DIR            man documentation [DATAROOTDIR/man]
+  --docdir=DIR            documentation root [DATAROOTDIR/doc/connman]
+  --htmldir=DIR           html documentation [DOCDIR]
+  --dvidir=DIR            dvi documentation [DOCDIR]
+  --pdfdir=DIR            pdf documentation [DOCDIR]
+  --psdir=DIR             ps documentation [DOCDIR]
+_ACEOF
+
+  cat <<\_ACEOF
+
+Program names:
+  --program-prefix=PREFIX            prepend PREFIX to installed program names
+  --program-suffix=SUFFIX            append SUFFIX to installed program names
+  --program-transform-name=PROGRAM   run sed PROGRAM on installed program names
+
+System types:
+  --build=BUILD     configure for building on BUILD [guessed]
+  --host=HOST       cross-compile to build programs to run on HOST [BUILD]
+_ACEOF
+fi
+
+if test -n "$ac_init_help"; then
+  case $ac_init_help in
+     short | recursive ) echo "Configuration of connman 1.29:";;
+   esac
+  cat <<\_ACEOF
+
+Optional Features:
+  --disable-option-checking  ignore unrecognized --enable/--with options
+  --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
+  --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
+  --enable-silent-rules   less verbose build output (undo: "make V=1")
+  --disable-silent-rules  verbose build output (undo: "make V=0")
+  --enable-maintainer-mode
+                          enable make rules and dependencies not useful (and
+                          sometimes confusing) to the casual installer
+  --enable-dependency-tracking
+                          do not reject slow dependency extractors
+  --disable-dependency-tracking
+                          speeds up one-time build
+  --enable-static[=PKGS]  build static libraries [default=no]
+  --enable-shared[=PKGS]  build shared libraries [default=yes]
+  --enable-fast-install[=PKGS]
+                          optimize for fast installation [default=yes]
+  --disable-libtool-lock  avoid locking (might break parallel builds)
+  --disable-optimization  disable code optimization through compiler
+  --enable-debug          enable compiling with debugging information
+  --enable-pie            enable position independent executables flag
+  --enable-hh2serial-gps  enable hh2serial GPS support
+  --enable-openconnect    enable openconnect support
+  --enable-openvpn        enable openvpn support
+  --enable-vpnc           enable vpnc support
+  --enable-l2tp           enable l2tp support
+  --enable-pptp           enable pptp support
+  --enable-iospm          enable Intel OSPM support
+  --enable-tist           enable TI Shared Transport support
+  --enable-session-policy-local
+                          enable local file Session policy configuration
+                          support
+  --enable-test           enable test/example scripts
+  --enable-nmcompat       enable Network Manager support
+  --enable-polkit         enable PolicyKit support
+  --enable-selinux        enable selinux support
+  --disable-loopback      disable loopback support
+  --disable-ethernet      disable Ethernet support
+  --disable-gadget        disable USB Gadget support
+  --disable-wifi          disable WiFi support
+  --disable-bluetooth     disable Bluetooth support
+  --disable-ofono         disable oFono support
+  --disable-dundee        disable dundee support (Bluetooth DUN)
+  --disable-pacrunner     disable PACrunner support
+  --disable-neard         disable Neard support
+  --disable-wispr         disable WISPr support
+  --disable-tools         disable testing tools
+  --disable-client        disable command line client
+  --disable-datafiles     don't install configuration and data files
+
+Optional Packages:
+  --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
+  --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)
+  --with-pic[=PKGS]       try to use only PIC/non-PIC objects [default=use
+                          both]
+  --with-gnu-ld           assume the C compiler uses GNU ld [default=no]
+  --with-sysroot=DIR Search for dependent libraries within DIR
+                        (or the compiler's sysroot if not specified).
+  --with-openconnect=PROGRAM
+                          specify location of openconnect binary
+  --with-openvpn=PROGRAM  specify location of openvpn binary
+  --with-vpnc=PROGRAM     specify location of vpnc binary
+  --with-l2tp=PROGRAM     specify location of l2tp binary
+  --with-pptp=PROGRAM     specify location of pptp binary
+  --with-stats-max-file-size=SIZE
+                          Maximal size of a statistics round robin file
+  --with-dbusconfdir=PATH path to D-Bus config directory
+  --with-dbusdatadir=PATH path to D-Bus data directory
+  --with-systemdunitdir=DIR
+                          path to systemd service directory
+
+Some influential environment variables:
+  PKG_CONFIG  path to pkg-config utility
+  PKG_CONFIG_PATH
+              directories to add to pkg-config's search path
+  PKG_CONFIG_LIBDIR
+              path overriding pkg-config's built-in search path
+  CC          C compiler command
+  CFLAGS      C compiler flags
+  LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries in a
+              nonstandard directory <lib dir>
+  LIBS        libraries to pass to the linker, e.g. -l<library>
+  CPPFLAGS    (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if
+              you have headers in a nonstandard directory <include dir>
+  CPP         C preprocessor
+  GLIB_CFLAGS C compiler flags for GLIB, overriding pkg-config
+  GLIB_LIBS   linker flags for GLIB, overriding pkg-config
+  DBUS_CFLAGS C compiler flags for DBUS, overriding pkg-config
+  DBUS_LIBS   linker flags for DBUS, overriding pkg-config
+  XTABLES_CFLAGS
+              C compiler flags for XTABLES, overriding pkg-config
+  XTABLES_LIBS
+              linker flags for XTABLES, overriding pkg-config
+  GNUTLS_CFLAGS
+              C compiler flags for GNUTLS, overriding pkg-config
+  GNUTLS_LIBS linker flags for GNUTLS, overriding pkg-config
+
+Use these variables to override the choices made by `configure' or to help
+it to find libraries and programs with nonstandard names/locations.
+
+Report bugs to the package provider.
+_ACEOF
+ac_status=$?
+fi
+
+if test "$ac_init_help" = "recursive"; then
+  # If there are subdirs, report their specific --help.
+  for ac_dir in : $ac_subdirs_all; do test "x$ac_dir" = x: && continue
+    test -d "$ac_dir" ||
+      { cd "$srcdir" && ac_pwd=`pwd` && srcdir=. && test -d "$ac_dir"; } ||
+      continue
+    ac_builddir=.
+
+case "$ac_dir" in
+.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;;
+*)
+  ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'`
+  # A ".." for each directory in $ac_dir_suffix.
+  ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'`
+  case $ac_top_builddir_sub in
+  "") ac_top_builddir_sub=. ac_top_build_prefix= ;;
+  *)  ac_top_build_prefix=$ac_top_builddir_sub/ ;;
+  esac ;;
+esac
+ac_abs_top_builddir=$ac_pwd
+ac_abs_builddir=$ac_pwd$ac_dir_suffix
+# for backward compatibility:
+ac_top_builddir=$ac_top_build_prefix
+
+case $srcdir in
+  .)  # We are building in place.
+    ac_srcdir=.
+    ac_top_srcdir=$ac_top_builddir_sub
+    ac_abs_top_srcdir=$ac_pwd ;;
+  [\\/]* | ?:[\\/]* )  # Absolute name.
+    ac_srcdir=$srcdir$ac_dir_suffix;
+    ac_top_srcdir=$srcdir
+    ac_abs_top_srcdir=$srcdir ;;
+  *) # Relative name.
+    ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix
+    ac_top_srcdir=$ac_top_build_prefix$srcdir
+    ac_abs_top_srcdir=$ac_pwd/$srcdir ;;
+esac
+ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix
+
+    cd "$ac_dir" || { ac_status=$?; continue; }
+    # Check for guested configure.
+    if test -f "$ac_srcdir/configure.gnu"; then
+      echo &&
+      $SHELL "$ac_srcdir/configure.gnu" --help=recursive
+    elif test -f "$ac_srcdir/configure"; then
+      echo &&
+      $SHELL "$ac_srcdir/configure" --help=recursive
+    else
+      $as_echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2
+    fi || ac_status=$?
+    cd "$ac_pwd" || { ac_status=$?; break; }
+  done
+fi
+
+test -n "$ac_init_help" && exit $ac_status
+if $ac_init_version; then
+  cat <<\_ACEOF
+connman configure 1.29
+generated by GNU Autoconf 2.69
+
+Copyright (C) 2012 Free Software Foundation, Inc.
+This configure script is free software; the Free Software Foundation
+gives unlimited permission to copy, distribute and modify it.
+_ACEOF
+  exit
+fi
+
+## ------------------------ ##
+## Autoconf initialization. ##
+## ------------------------ ##
+
+# ac_fn_c_try_compile LINENO
+# --------------------------
+# Try to compile conftest.$ac_ext, and return whether this succeeded.
+ac_fn_c_try_compile ()
+{
+  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+  rm -f conftest.$ac_objext
+  if { { ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_compile") 2>conftest.err
+  ac_status=$?
+  if test -s conftest.err; then
+    grep -v '^ *+' conftest.err >conftest.er1
+    cat conftest.er1 >&5
+    mv -f conftest.er1 conftest.err
+  fi
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then :
+  ac_retval=0
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_retval=1
+fi
+  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
+  as_fn_set_status $ac_retval
+
+} # ac_fn_c_try_compile
+
+# ac_fn_c_try_link LINENO
+# -----------------------
+# Try to link conftest.$ac_ext, and return whether this succeeded.
+ac_fn_c_try_link ()
+{
+  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+  rm -f conftest.$ac_objext conftest$ac_exeext
+  if { { ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_link") 2>conftest.err
+  ac_status=$?
+  if test -s conftest.err; then
+    grep -v '^ *+' conftest.err >conftest.er1
+    cat conftest.er1 >&5
+    mv -f conftest.er1 conftest.err
+  fi
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext && {
+	 test "$cross_compiling" = yes ||
+	 test -x conftest$ac_exeext
+       }; then :
+  ac_retval=0
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_retval=1
+fi
+  # Delete the IPA/IPO (Inter Procedural Analysis/Optimization) information
+  # created by the PGI compiler (conftest_ipa8_conftest.oo), as it would
+  # interfere with the next link command; also delete a directory that is
+  # left behind by Apple's compiler.  We do this before executing the actions.
+  rm -rf conftest.dSYM conftest_ipa8_conftest.oo
+  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
+  as_fn_set_status $ac_retval
+
+} # ac_fn_c_try_link
+
+# ac_fn_c_check_header_compile LINENO HEADER VAR INCLUDES
+# -------------------------------------------------------
+# Tests whether HEADER exists and can be compiled using the include files in
+# INCLUDES, setting the cache variable VAR accordingly.
+ac_fn_c_check_header_compile ()
+{
+  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
+$as_echo_n "checking for $2... " >&6; }
+if eval \${$3+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+$4
+#include <$2>
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  eval "$3=yes"
+else
+  eval "$3=no"
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+eval ac_res=\$$3
+	       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
+
+} # ac_fn_c_check_header_compile
+
+# ac_fn_c_try_cpp LINENO
+# ----------------------
+# Try to preprocess conftest.$ac_ext, and return whether this succeeded.
+ac_fn_c_try_cpp ()
+{
+  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+  if { { ac_try="$ac_cpp conftest.$ac_ext"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.err
+  ac_status=$?
+  if test -s conftest.err; then
+    grep -v '^ *+' conftest.err >conftest.er1
+    cat conftest.er1 >&5
+    mv -f conftest.er1 conftest.err
+  fi
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; } > conftest.i && {
+	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       }; then :
+  ac_retval=0
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+    ac_retval=1
+fi
+  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
+  as_fn_set_status $ac_retval
+
+} # ac_fn_c_try_cpp
+
+# ac_fn_c_try_run LINENO
+# ----------------------
+# Try to link conftest.$ac_ext, and return whether this succeeded. Assumes
+# that executables *can* be run.
+ac_fn_c_try_run ()
+{
+  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+  if { { ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_link") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; } && { ac_try='./conftest$ac_exeext'
+  { { case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_try") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; }; then :
+  ac_retval=0
+else
+  $as_echo "$as_me: program exited with status $ac_status" >&5
+       $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+       ac_retval=$ac_status
+fi
+  rm -rf conftest.dSYM conftest_ipa8_conftest.oo
+  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
+  as_fn_set_status $ac_retval
+
+} # ac_fn_c_try_run
+
+# ac_fn_c_check_func LINENO FUNC VAR
+# ----------------------------------
+# Tests whether FUNC exists, setting the cache variable VAR accordingly
+ac_fn_c_check_func ()
+{
+  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
+$as_echo_n "checking for $2... " >&6; }
+if eval \${$3+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+/* Define $2 to an innocuous variant, in case <limits.h> declares $2.
+   For example, HP-UX 11i <limits.h> declares gettimeofday.  */
+#define $2 innocuous_$2
+
+/* System header to define __stub macros and hopefully few prototypes,
+    which can conflict with char $2 (); below.
+    Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+    <limits.h> exists even on freestanding compilers.  */
+
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+
+#undef $2
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char $2 ();
+/* The GNU C library defines this for functions which it implements
+    to always fail with ENOSYS.  Some functions are actually named
+    something starting with __ and the normal name is an alias.  */
+#if defined __stub_$2 || defined __stub___$2
+choke me
+#endif
+
+int
+main ()
+{
+return $2 ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  eval "$3=yes"
+else
+  eval "$3=no"
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+fi
+eval ac_res=\$$3
+	       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
+
+} # ac_fn_c_check_func
+
+# ac_fn_c_check_header_mongrel LINENO HEADER VAR INCLUDES
+# -------------------------------------------------------
+# Tests whether HEADER exists, giving a warning if it cannot be compiled using
+# the include files in INCLUDES and setting the cache variable VAR
+# accordingly.
+ac_fn_c_check_header_mongrel ()
+{
+  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+  if eval \${$3+:} false; then :
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
+$as_echo_n "checking for $2... " >&6; }
+if eval \${$3+:} false; then :
+  $as_echo_n "(cached) " >&6
+fi
+eval ac_res=\$$3
+	       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+else
+  # Is the header compilable?
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking $2 usability" >&5
+$as_echo_n "checking $2 usability... " >&6; }
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+$4
+#include <$2>
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_header_compiler=yes
+else
+  ac_header_compiler=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_compiler" >&5
+$as_echo "$ac_header_compiler" >&6; }
+
+# Is the header present?
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking $2 presence" >&5
+$as_echo_n "checking $2 presence... " >&6; }
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <$2>
+_ACEOF
+if ac_fn_c_try_cpp "$LINENO"; then :
+  ac_header_preproc=yes
+else
+  ac_header_preproc=no
+fi
+rm -f conftest.err conftest.i conftest.$ac_ext
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_preproc" >&5
+$as_echo "$ac_header_preproc" >&6; }
+
+# So?  What about this header?
+case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in #((
+  yes:no: )
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: accepted by the compiler, rejected by the preprocessor!" >&5
+$as_echo "$as_me: WARNING: $2: accepted by the compiler, rejected by the preprocessor!" >&2;}
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5
+$as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;}
+    ;;
+  no:yes:* )
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: present but cannot be compiled" >&5
+$as_echo "$as_me: WARNING: $2: present but cannot be compiled" >&2;}
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2:     check for missing prerequisite headers?" >&5
+$as_echo "$as_me: WARNING: $2:     check for missing prerequisite headers?" >&2;}
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: see the Autoconf documentation" >&5
+$as_echo "$as_me: WARNING: $2: see the Autoconf documentation" >&2;}
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2:     section \"Present But Cannot Be Compiled\"" >&5
+$as_echo "$as_me: WARNING: $2:     section \"Present But Cannot Be Compiled\"" >&2;}
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5
+$as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;}
+    ;;
+esac
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
+$as_echo_n "checking for $2... " >&6; }
+if eval \${$3+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  eval "$3=\$ac_header_compiler"
+fi
+eval ac_res=\$$3
+	       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+fi
+  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
+
+} # ac_fn_c_check_header_mongrel
+cat >config.log <<_ACEOF
+This file contains any messages produced by compilers while
+running configure, to aid debugging if configure makes a mistake.
+
+It was created by connman $as_me 1.29, which was
+generated by GNU Autoconf 2.69.  Invocation command line was
+
+  $ $0 $@
+
+_ACEOF
+exec 5>>config.log
+{
+cat <<_ASUNAME
+## --------- ##
+## Platform. ##
+## --------- ##
+
+hostname = `(hostname || uname -n) 2>/dev/null | sed 1q`
+uname -m = `(uname -m) 2>/dev/null || echo unknown`
+uname -r = `(uname -r) 2>/dev/null || echo unknown`
+uname -s = `(uname -s) 2>/dev/null || echo unknown`
+uname -v = `(uname -v) 2>/dev/null || echo unknown`
+
+/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null || echo unknown`
+/bin/uname -X     = `(/bin/uname -X) 2>/dev/null     || echo unknown`
+
+/bin/arch              = `(/bin/arch) 2>/dev/null              || echo unknown`
+/usr/bin/arch -k       = `(/usr/bin/arch -k) 2>/dev/null       || echo unknown`
+/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null || echo unknown`
+/usr/bin/hostinfo      = `(/usr/bin/hostinfo) 2>/dev/null      || echo unknown`
+/bin/machine           = `(/bin/machine) 2>/dev/null           || echo unknown`
+/usr/bin/oslevel       = `(/usr/bin/oslevel) 2>/dev/null       || echo unknown`
+/bin/universe          = `(/bin/universe) 2>/dev/null          || echo unknown`
+
+_ASUNAME
+
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    $as_echo "PATH: $as_dir"
+  done
+IFS=$as_save_IFS
+
+} >&5
+
+cat >&5 <<_ACEOF
+
+
+## ----------- ##
+## Core tests. ##
+## ----------- ##
+
+_ACEOF
+
+
+# Keep a trace of the command line.
+# Strip out --no-create and --no-recursion so they do not pile up.
+# Strip out --silent because we don't want to record it for future runs.
+# Also quote any args containing shell meta-characters.
+# Make two passes to allow for proper duplicate-argument suppression.
+ac_configure_args=
+ac_configure_args0=
+ac_configure_args1=
+ac_must_keep_next=false
+for ac_pass in 1 2
+do
+  for ac_arg
+  do
+    case $ac_arg in
+    -no-create | --no-c* | -n | -no-recursion | --no-r*) continue ;;
+    -q | -quiet | --quiet | --quie | --qui | --qu | --q \
+    | -silent | --silent | --silen | --sile | --sil)
+      continue ;;
+    *\'*)
+      ac_arg=`$as_echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;;
+    esac
+    case $ac_pass in
+    1) as_fn_append ac_configure_args0 " '$ac_arg'" ;;
+    2)
+      as_fn_append ac_configure_args1 " '$ac_arg'"
+      if test $ac_must_keep_next = true; then
+	ac_must_keep_next=false # Got value, back to normal.
+      else
+	case $ac_arg in
+	  *=* | --config-cache | -C | -disable-* | --disable-* \
+	  | -enable-* | --enable-* | -gas | --g* | -nfp | --nf* \
+	  | -q | -quiet | --q* | -silent | --sil* | -v | -verb* \
+	  | -with-* | --with-* | -without-* | --without-* | --x)
+	    case "$ac_configure_args0 " in
+	      "$ac_configure_args1"*" '$ac_arg' "* ) continue ;;
+	    esac
+	    ;;
+	  -* ) ac_must_keep_next=true ;;
+	esac
+      fi
+      as_fn_append ac_configure_args " '$ac_arg'"
+      ;;
+    esac
+  done
+done
+{ ac_configure_args0=; unset ac_configure_args0;}
+{ ac_configure_args1=; unset ac_configure_args1;}
+
+# When interrupted or exit'd, cleanup temporary files, and complete
+# config.log.  We remove comments because anyway the quotes in there
+# would cause problems or look ugly.
+# WARNING: Use '\'' to represent an apostrophe within the trap.
+# WARNING: Do not start the trap code with a newline, due to a FreeBSD 4.0 bug.
+trap 'exit_status=$?
+  # Save into config.log some information that might help in debugging.
+  {
+    echo
+
+    $as_echo "## ---------------- ##
+## Cache variables. ##
+## ---------------- ##"
+    echo
+    # The following way of writing the cache mishandles newlines in values,
+(
+  for ac_var in `(set) 2>&1 | sed -n '\''s/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'\''`; do
+    eval ac_val=\$$ac_var
+    case $ac_val in #(
+    *${as_nl}*)
+      case $ac_var in #(
+      *_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5
+$as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;;
+      esac
+      case $ac_var in #(
+      _ | IFS | as_nl) ;; #(
+      BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #(
+      *) { eval $ac_var=; unset $ac_var;} ;;
+      esac ;;
+    esac
+  done
+  (set) 2>&1 |
+    case $as_nl`(ac_space='\'' '\''; set) 2>&1` in #(
+    *${as_nl}ac_space=\ *)
+      sed -n \
+	"s/'\''/'\''\\\\'\'''\''/g;
+	  s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\''\\2'\''/p"
+      ;; #(
+    *)
+      sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p"
+      ;;
+    esac |
+    sort
+)
+    echo
+
+    $as_echo "## ----------------- ##
+## Output variables. ##
+## ----------------- ##"
+    echo
+    for ac_var in $ac_subst_vars
+    do
+      eval ac_val=\$$ac_var
+      case $ac_val in
+      *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;;
+      esac
+      $as_echo "$ac_var='\''$ac_val'\''"
+    done | sort
+    echo
+
+    if test -n "$ac_subst_files"; then
+      $as_echo "## ------------------- ##
+## File substitutions. ##
+## ------------------- ##"
+      echo
+      for ac_var in $ac_subst_files
+      do
+	eval ac_val=\$$ac_var
+	case $ac_val in
+	*\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;;
+	esac
+	$as_echo "$ac_var='\''$ac_val'\''"
+      done | sort
+      echo
+    fi
+
+    if test -s confdefs.h; then
+      $as_echo "## ----------- ##
+## confdefs.h. ##
+## ----------- ##"
+      echo
+      cat confdefs.h
+      echo
+    fi
+    test "$ac_signal" != 0 &&
+      $as_echo "$as_me: caught signal $ac_signal"
+    $as_echo "$as_me: exit $exit_status"
+  } >&5
+  rm -f core *.core core.conftest.* &&
+    rm -f -r conftest* confdefs* conf$$* $ac_clean_files &&
+    exit $exit_status
+' 0
+for ac_signal in 1 2 13 15; do
+  trap 'ac_signal='$ac_signal'; as_fn_exit 1' $ac_signal
+done
+ac_signal=0
+
+# confdefs.h avoids OS command line length limits that DEFS can exceed.
+rm -f -r conftest* confdefs.h
+
+$as_echo "/* confdefs.h */" > confdefs.h
+
+# Predefined preprocessor variables.
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_NAME "$PACKAGE_NAME"
+_ACEOF
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_TARNAME "$PACKAGE_TARNAME"
+_ACEOF
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_VERSION "$PACKAGE_VERSION"
+_ACEOF
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_STRING "$PACKAGE_STRING"
+_ACEOF
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_BUGREPORT "$PACKAGE_BUGREPORT"
+_ACEOF
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_URL "$PACKAGE_URL"
+_ACEOF
+
+
+# Let the site file select an alternate cache file if it wants to.
+# Prefer an explicitly selected file to automatically selected ones.
+ac_site_file1=NONE
+ac_site_file2=NONE
+if test -n "$CONFIG_SITE"; then
+  # We do not want a PATH search for config.site.
+  case $CONFIG_SITE in #((
+    -*)  ac_site_file1=./$CONFIG_SITE;;
+    */*) ac_site_file1=$CONFIG_SITE;;
+    *)   ac_site_file1=./$CONFIG_SITE;;
+  esac
+elif test "x$prefix" != xNONE; then
+  ac_site_file1=$prefix/share/config.site
+  ac_site_file2=$prefix/etc/config.site
+else
+  ac_site_file1=$ac_default_prefix/share/config.site
+  ac_site_file2=$ac_default_prefix/etc/config.site
+fi
+for ac_site_file in "$ac_site_file1" "$ac_site_file2"
+do
+  test "x$ac_site_file" = xNONE && continue
+  if test /dev/null != "$ac_site_file" && test -r "$ac_site_file"; then
+    { $as_echo "$as_me:${as_lineno-$LINENO}: loading site script $ac_site_file" >&5
+$as_echo "$as_me: loading site script $ac_site_file" >&6;}
+    sed 's/^/| /' "$ac_site_file" >&5
+    . "$ac_site_file" \
+      || { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "failed to load site script $ac_site_file
+See \`config.log' for more details" "$LINENO" 5; }
+  fi
+done
+
+if test -r "$cache_file"; then
+  # Some versions of bash will fail to source /dev/null (special files
+  # actually), so we avoid doing that.  DJGPP emulates it as a regular file.
+  if test /dev/null != "$cache_file" && test -f "$cache_file"; then
+    { $as_echo "$as_me:${as_lineno-$LINENO}: loading cache $cache_file" >&5
+$as_echo "$as_me: loading cache $cache_file" >&6;}
+    case $cache_file in
+      [\\/]* | ?:[\\/]* ) . "$cache_file";;
+      *)                      . "./$cache_file";;
+    esac
+  fi
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: creating cache $cache_file" >&5
+$as_echo "$as_me: creating cache $cache_file" >&6;}
+  >$cache_file
+fi
+
+# Check that the precious variables saved in the cache have kept the same
+# value.
+ac_cache_corrupted=false
+for ac_var in $ac_precious_vars; do
+  eval ac_old_set=\$ac_cv_env_${ac_var}_set
+  eval ac_new_set=\$ac_env_${ac_var}_set
+  eval ac_old_val=\$ac_cv_env_${ac_var}_value
+  eval ac_new_val=\$ac_env_${ac_var}_value
+  case $ac_old_set,$ac_new_set in
+    set,)
+      { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5
+$as_echo "$as_me: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&2;}
+      ac_cache_corrupted=: ;;
+    ,set)
+      { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was not set in the previous run" >&5
+$as_echo "$as_me: error: \`$ac_var' was not set in the previous run" >&2;}
+      ac_cache_corrupted=: ;;
+    ,);;
+    *)
+      if test "x$ac_old_val" != "x$ac_new_val"; then
+	# differences in whitespace do not lead to failure.
+	ac_old_val_w=`echo x $ac_old_val`
+	ac_new_val_w=`echo x $ac_new_val`
+	if test "$ac_old_val_w" != "$ac_new_val_w"; then
+	  { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' has changed since the previous run:" >&5
+$as_echo "$as_me: error: \`$ac_var' has changed since the previous run:" >&2;}
+	  ac_cache_corrupted=:
+	else
+	  { $as_echo "$as_me:${as_lineno-$LINENO}: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&5
+$as_echo "$as_me: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&2;}
+	  eval $ac_var=\$ac_old_val
+	fi
+	{ $as_echo "$as_me:${as_lineno-$LINENO}:   former value:  \`$ac_old_val'" >&5
+$as_echo "$as_me:   former value:  \`$ac_old_val'" >&2;}
+	{ $as_echo "$as_me:${as_lineno-$LINENO}:   current value: \`$ac_new_val'" >&5
+$as_echo "$as_me:   current value: \`$ac_new_val'" >&2;}
+      fi;;
+  esac
+  # Pass precious variables to config.status.
+  if test "$ac_new_set" = set; then
+    case $ac_new_val in
+    *\'*) ac_arg=$ac_var=`$as_echo "$ac_new_val" | sed "s/'/'\\\\\\\\''/g"` ;;
+    *) ac_arg=$ac_var=$ac_new_val ;;
+    esac
+    case " $ac_configure_args " in
+      *" '$ac_arg' "*) ;; # Avoid dups.  Use of quotes ensures accuracy.
+      *) as_fn_append ac_configure_args " '$ac_arg'" ;;
+    esac
+  fi
+done
+if $ac_cache_corrupted; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+  { $as_echo "$as_me:${as_lineno-$LINENO}: error: changes in the environment can compromise the build" >&5
+$as_echo "$as_me: error: changes in the environment can compromise the build" >&2;}
+  as_fn_error $? "run \`make distclean' and/or \`rm $cache_file' and start over" "$LINENO" 5
+fi
+## -------------------- ##
+## Main body of script. ##
+## -------------------- ##
+
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+
+am__api_version='1.14'
+
+ac_aux_dir=
+for ac_dir in "$srcdir" "$srcdir/.." "$srcdir/../.."; do
+  if test -f "$ac_dir/install-sh"; then
+    ac_aux_dir=$ac_dir
+    ac_install_sh="$ac_aux_dir/install-sh -c"
+    break
+  elif test -f "$ac_dir/install.sh"; then
+    ac_aux_dir=$ac_dir
+    ac_install_sh="$ac_aux_dir/install.sh -c"
+    break
+  elif test -f "$ac_dir/shtool"; then
+    ac_aux_dir=$ac_dir
+    ac_install_sh="$ac_aux_dir/shtool install -c"
+    break
+  fi
+done
+if test -z "$ac_aux_dir"; then
+  as_fn_error $? "cannot find install-sh, install.sh, or shtool in \"$srcdir\" \"$srcdir/..\" \"$srcdir/../..\"" "$LINENO" 5
+fi
+
+# These three variables are undocumented and unsupported,
+# and are intended to be withdrawn in a future Autoconf release.
+# They can cause serious problems if a builder's source tree is in a directory
+# whose full name contains unusual characters.
+ac_config_guess="$SHELL $ac_aux_dir/config.guess"  # Please don't use this var.
+ac_config_sub="$SHELL $ac_aux_dir/config.sub"  # Please don't use this var.
+ac_configure="$SHELL $ac_aux_dir/configure"  # Please don't use this var.
+
+
+# Find a good install program.  We prefer a C program (faster),
+# so one script is as good as another.  But avoid the broken or
+# incompatible versions:
+# SysV /etc/install, /usr/sbin/install
+# SunOS /usr/etc/install
+# IRIX /sbin/install
+# AIX /bin/install
+# AmigaOS /C/install, which installs bootblocks on floppy discs
+# AIX 4 /usr/bin/installbsd, which doesn't work without a -g flag
+# AFS /usr/afsws/bin/install, which mishandles nonexistent args
+# SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff"
+# OS/2's system install, which has a completely different semantic
+# ./install, which can be erroneously created by make from ./install.sh.
+# Reject install programs that cannot install multiple files.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for a BSD-compatible install" >&5
+$as_echo_n "checking for a BSD-compatible install... " >&6; }
+if test -z "$INSTALL"; then
+if ${ac_cv_path_install+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    # Account for people who put trailing slashes in PATH elements.
+case $as_dir/ in #((
+  ./ | .// | /[cC]/* | \
+  /etc/* | /usr/sbin/* | /usr/etc/* | /sbin/* | /usr/afsws/bin/* | \
+  ?:[\\/]os2[\\/]install[\\/]* | ?:[\\/]OS2[\\/]INSTALL[\\/]* | \
+  /usr/ucb/* ) ;;
+  *)
+    # OSF1 and SCO ODT 3.0 have their own names for install.
+    # Don't use installbsd from OSF since it installs stuff as root
+    # by default.
+    for ac_prog in ginstall scoinst install; do
+      for ac_exec_ext in '' $ac_executable_extensions; do
+	if as_fn_executable_p "$as_dir/$ac_prog$ac_exec_ext"; then
+	  if test $ac_prog = install &&
+	    grep dspmsg "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then
+	    # AIX install.  It has an incompatible calling convention.
+	    :
+	  elif test $ac_prog = install &&
+	    grep pwplus "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then
+	    # program-specific install script used by HP pwplus--don't use.
+	    :
+	  else
+	    rm -rf conftest.one conftest.two conftest.dir
+	    echo one > conftest.one
+	    echo two > conftest.two
+	    mkdir conftest.dir
+	    if "$as_dir/$ac_prog$ac_exec_ext" -c conftest.one conftest.two "`pwd`/conftest.dir" &&
+	      test -s conftest.one && test -s conftest.two &&
+	      test -s conftest.dir/conftest.one &&
+	      test -s conftest.dir/conftest.two
+	    then
+	      ac_cv_path_install="$as_dir/$ac_prog$ac_exec_ext -c"
+	      break 3
+	    fi
+	  fi
+	fi
+      done
+    done
+    ;;
+esac
+
+  done
+IFS=$as_save_IFS
+
+rm -rf conftest.one conftest.two conftest.dir
+
+fi
+  if test "${ac_cv_path_install+set}" = set; then
+    INSTALL=$ac_cv_path_install
+  else
+    # As a last resort, use the slow shell script.  Don't cache a
+    # value for INSTALL within a source directory, because that will
+    # break other packages using the cache if that directory is
+    # removed, or if the value is a relative name.
+    INSTALL=$ac_install_sh
+  fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $INSTALL" >&5
+$as_echo "$INSTALL" >&6; }
+
+# Use test -z because SunOS4 sh mishandles braces in ${var-val}.
+# It thinks the first close brace ends the variable substitution.
+test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}'
+
+test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL}'
+
+test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644'
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether build environment is sane" >&5
+$as_echo_n "checking whether build environment is sane... " >&6; }
+# Reject unsafe characters in $srcdir or the absolute working directory
+# name.  Accept space and tab only in the latter.
+am_lf='
+'
+case `pwd` in
+  *[\\\"\#\$\&\'\`$am_lf]*)
+    as_fn_error $? "unsafe absolute working directory name" "$LINENO" 5;;
+esac
+case $srcdir in
+  *[\\\"\#\$\&\'\`$am_lf\ \	]*)
+    as_fn_error $? "unsafe srcdir value: '$srcdir'" "$LINENO" 5;;
+esac
+
+# Do 'set' in a subshell so we don't clobber the current shell's
+# arguments.  Must try -L first in case configure is actually a
+# symlink; some systems play weird games with the mod time of symlinks
+# (eg FreeBSD returns the mod time of the symlink's containing
+# directory).
+if (
+   am_has_slept=no
+   for am_try in 1 2; do
+     echo "timestamp, slept: $am_has_slept" > conftest.file
+     set X `ls -Lt "$srcdir/configure" conftest.file 2> /dev/null`
+     if test "$*" = "X"; then
+	# -L didn't work.
+	set X `ls -t "$srcdir/configure" conftest.file`
+     fi
+     if test "$*" != "X $srcdir/configure conftest.file" \
+	&& test "$*" != "X conftest.file $srcdir/configure"; then
+
+	# If neither matched, then we have a broken ls.  This can happen
+	# if, for instance, CONFIG_SHELL is bash and it inherits a
+	# broken ls alias from the environment.  This has actually
+	# happened.  Such a system could not be considered "sane".
+	as_fn_error $? "ls -t appears to fail.  Make sure there is not a broken
+  alias in your environment" "$LINENO" 5
+     fi
+     if test "$2" = conftest.file || test $am_try -eq 2; then
+       break
+     fi
+     # Just in case.
+     sleep 1
+     am_has_slept=yes
+   done
+   test "$2" = conftest.file
+   )
+then
+   # Ok.
+   :
+else
+   as_fn_error $? "newly created file is older than distributed files!
+Check your system clock" "$LINENO" 5
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+# If we didn't sleep, we still need to ensure time stamps of config.status and
+# generated files are strictly newer.
+am_sleep_pid=
+if grep 'slept: no' conftest.file >/dev/null 2>&1; then
+  ( sleep 1 ) &
+  am_sleep_pid=$!
+fi
+
+rm -f conftest.file
+
+test "$program_prefix" != NONE &&
+  program_transform_name="s&^&$program_prefix&;$program_transform_name"
+# Use a double $ so make ignores it.
+test "$program_suffix" != NONE &&
+  program_transform_name="s&\$&$program_suffix&;$program_transform_name"
+# Double any \ or $.
+# By default was `s,x,x', remove it if useless.
+ac_script='s/[\\$]/&&/g;s/;s,x,x,$//'
+program_transform_name=`$as_echo "$program_transform_name" | sed "$ac_script"`
+
+# expand $ac_aux_dir to an absolute path
+am_aux_dir=`cd $ac_aux_dir && pwd`
+
+if test x"${MISSING+set}" != xset; then
+  case $am_aux_dir in
+  *\ * | *\	*)
+    MISSING="\${SHELL} \"$am_aux_dir/missing\"" ;;
+  *)
+    MISSING="\${SHELL} $am_aux_dir/missing" ;;
+  esac
+fi
+# Use eval to expand $SHELL
+if eval "$MISSING --is-lightweight"; then
+  am_missing_run="$MISSING "
+else
+  am_missing_run=
+  { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: 'missing' script is too old or missing" >&5
+$as_echo "$as_me: WARNING: 'missing' script is too old or missing" >&2;}
+fi
+
+if test x"${install_sh}" != xset; then
+  case $am_aux_dir in
+  *\ * | *\	*)
+    install_sh="\${SHELL} '$am_aux_dir/install-sh'" ;;
+  *)
+    install_sh="\${SHELL} $am_aux_dir/install-sh"
+  esac
+fi
+
+# Installed binaries are usually stripped using 'strip' when the user
+# run "make install-strip".  However 'strip' might not be the right
+# tool to use in cross-compilation environments, therefore Automake
+# will honor the 'STRIP' environment variable to overrule this program.
+if test "$cross_compiling" != no; then
+  if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}strip", so it can be a program name with args.
+set dummy ${ac_tool_prefix}strip; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_STRIP+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$STRIP"; then
+  ac_cv_prog_STRIP="$STRIP" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_STRIP="${ac_tool_prefix}strip"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+STRIP=$ac_cv_prog_STRIP
+if test -n "$STRIP"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $STRIP" >&5
+$as_echo "$STRIP" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_prog_STRIP"; then
+  ac_ct_STRIP=$STRIP
+  # Extract the first word of "strip", so it can be a program name with args.
+set dummy strip; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_ac_ct_STRIP+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_STRIP"; then
+  ac_cv_prog_ac_ct_STRIP="$ac_ct_STRIP" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_ac_ct_STRIP="strip"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_STRIP=$ac_cv_prog_ac_ct_STRIP
+if test -n "$ac_ct_STRIP"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_STRIP" >&5
+$as_echo "$ac_ct_STRIP" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_ct_STRIP" = x; then
+    STRIP=":"
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    STRIP=$ac_ct_STRIP
+  fi
+else
+  STRIP="$ac_cv_prog_STRIP"
+fi
+
+fi
+INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s"
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for a thread-safe mkdir -p" >&5
+$as_echo_n "checking for a thread-safe mkdir -p... " >&6; }
+if test -z "$MKDIR_P"; then
+  if ${ac_cv_path_mkdir+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH$PATH_SEPARATOR/opt/sfw/bin
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_prog in mkdir gmkdir; do
+	 for ac_exec_ext in '' $ac_executable_extensions; do
+	   as_fn_executable_p "$as_dir/$ac_prog$ac_exec_ext" || continue
+	   case `"$as_dir/$ac_prog$ac_exec_ext" --version 2>&1` in #(
+	     'mkdir (GNU coreutils) '* | \
+	     'mkdir (coreutils) '* | \
+	     'mkdir (fileutils) '4.1*)
+	       ac_cv_path_mkdir=$as_dir/$ac_prog$ac_exec_ext
+	       break 3;;
+	   esac
+	 done
+       done
+  done
+IFS=$as_save_IFS
+
+fi
+
+  test -d ./--version && rmdir ./--version
+  if test "${ac_cv_path_mkdir+set}" = set; then
+    MKDIR_P="$ac_cv_path_mkdir -p"
+  else
+    # As a last resort, use the slow shell script.  Don't cache a
+    # value for MKDIR_P within a source directory, because that will
+    # break other packages using the cache if that directory is
+    # removed, or if the value is a relative name.
+    MKDIR_P="$ac_install_sh -d"
+  fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $MKDIR_P" >&5
+$as_echo "$MKDIR_P" >&6; }
+
+for ac_prog in gawk mawk nawk awk
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_AWK+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$AWK"; then
+  ac_cv_prog_AWK="$AWK" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_AWK="$ac_prog"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+AWK=$ac_cv_prog_AWK
+if test -n "$AWK"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $AWK" >&5
+$as_echo "$AWK" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+  test -n "$AWK" && break
+done
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${MAKE-make} sets \$(MAKE)" >&5
+$as_echo_n "checking whether ${MAKE-make} sets \$(MAKE)... " >&6; }
+set x ${MAKE-make}
+ac_make=`$as_echo "$2" | sed 's/+/p/g; s/[^a-zA-Z0-9_]/_/g'`
+if eval \${ac_cv_prog_make_${ac_make}_set+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat >conftest.make <<\_ACEOF
+SHELL = /bin/sh
+all:
+	@echo '@@@%%%=$(MAKE)=@@@%%%'
+_ACEOF
+# GNU make sometimes prints "make[1]: Entering ...", which would confuse us.
+case `${MAKE-make} -f conftest.make 2>/dev/null` in
+  *@@@%%%=?*=@@@%%%*)
+    eval ac_cv_prog_make_${ac_make}_set=yes;;
+  *)
+    eval ac_cv_prog_make_${ac_make}_set=no;;
+esac
+rm -f conftest.make
+fi
+if eval test \$ac_cv_prog_make_${ac_make}_set = yes; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+  SET_MAKE=
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+  SET_MAKE="MAKE=${MAKE-make}"
+fi
+
+rm -rf .tst 2>/dev/null
+mkdir .tst 2>/dev/null
+if test -d .tst; then
+  am__leading_dot=.
+else
+  am__leading_dot=_
+fi
+rmdir .tst 2>/dev/null
+
+# Check whether --enable-silent-rules was given.
+if test "${enable_silent_rules+set}" = set; then :
+  enableval=$enable_silent_rules;
+fi
+
+case $enable_silent_rules in # (((
+  yes) AM_DEFAULT_VERBOSITY=0;;
+   no) AM_DEFAULT_VERBOSITY=1;;
+    *) AM_DEFAULT_VERBOSITY=1;;
+esac
+am_make=${MAKE-make}
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $am_make supports nested variables" >&5
+$as_echo_n "checking whether $am_make supports nested variables... " >&6; }
+if ${am_cv_make_support_nested_variables+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if $as_echo 'TRUE=$(BAR$(V))
+BAR0=false
+BAR1=true
+V=1
+am__doit:
+	@$(TRUE)
+.PHONY: am__doit' | $am_make -f - >/dev/null 2>&1; then
+  am_cv_make_support_nested_variables=yes
+else
+  am_cv_make_support_nested_variables=no
+fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_make_support_nested_variables" >&5
+$as_echo "$am_cv_make_support_nested_variables" >&6; }
+if test $am_cv_make_support_nested_variables = yes; then
+    AM_V='$(V)'
+  AM_DEFAULT_V='$(AM_DEFAULT_VERBOSITY)'
+else
+  AM_V=$AM_DEFAULT_VERBOSITY
+  AM_DEFAULT_V=$AM_DEFAULT_VERBOSITY
+fi
+AM_BACKSLASH='\'
+
+if test "`cd $srcdir && pwd`" != "`pwd`"; then
+  # Use -I$(srcdir) only when $(srcdir) != ., so that make's output
+  # is not polluted with repeated "-I."
+  am__isrc=' -I$(srcdir)'
+  # test to see if srcdir already configured
+  if test -f $srcdir/config.status; then
+    as_fn_error $? "source directory already configured; run \"make distclean\" there first" "$LINENO" 5
+  fi
+fi
+
+# test whether we have cygpath
+if test -z "$CYGPATH_W"; then
+  if (cygpath --version) >/dev/null 2>/dev/null; then
+    CYGPATH_W='cygpath -w'
+  else
+    CYGPATH_W=echo
+  fi
+fi
+
+
+# Define the identity of the package.
+ PACKAGE='connman'
+ VERSION='1.29'
+
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE "$PACKAGE"
+_ACEOF
+
+
+cat >>confdefs.h <<_ACEOF
+#define VERSION "$VERSION"
+_ACEOF
+
+# Some tools Automake needs.
+
+ACLOCAL=${ACLOCAL-"${am_missing_run}aclocal-${am__api_version}"}
+
+
+AUTOCONF=${AUTOCONF-"${am_missing_run}autoconf"}
+
+
+AUTOMAKE=${AUTOMAKE-"${am_missing_run}automake-${am__api_version}"}
+
+
+AUTOHEADER=${AUTOHEADER-"${am_missing_run}autoheader"}
+
+
+MAKEINFO=${MAKEINFO-"${am_missing_run}makeinfo"}
+
+# For better backward compatibility.  To be removed once Automake 1.9.x
+# dies out for good.  For more background, see:
+# <http://lists.gnu.org/archive/html/automake/2012-07/msg00001.html>
+# <http://lists.gnu.org/archive/html/automake/2012-07/msg00014.html>
+mkdir_p='$(MKDIR_P)'
+
+# We need awk for the "check" target.  The system "awk" is bad on
+# some platforms.
+# Always define AMTAR for backward compatibility.  Yes, it's still used
+# in the wild :-(  We should find a proper way to deprecate it ...
+AMTAR='$${TAR-tar}'
+
+
+# We'll loop over all known methods to create a tar archive until one works.
+_am_tools='gnutar  pax cpio none'
+
+am__tar='$${TAR-tar} chof - "$$tardir"' am__untar='$${TAR-tar} xf -'
+
+
+
+
+
+
+# POSIX will say in a future version that running "rm -f" with no argument
+# is OK; and we want to be able to make that assumption in our Makefile
+# recipes.  So use an aggressive probe to check that the usage we want is
+# actually supported "in the wild" to an acceptable degree.
+# See automake bug#10828.
+# To make any issue more visible, cause the running configure to be aborted
+# by default if the 'rm' program in use doesn't match our expectations; the
+# user can still override this though.
+if rm -f && rm -fr && rm -rf; then : OK; else
+  cat >&2 <<'END'
+Oops!
+
+Your 'rm' program seems unable to run without file operands specified
+on the command line, even when the '-f' option is present.  This is contrary
+to the behaviour of most rm programs out there, and not conforming with
+the upcoming POSIX standard: <http://austingroupbugs.net/view.php?id=542>
+
+Please tell bug-automake@gnu.org about your system, including the value
+of your $PATH and any error possibly output before this message.  This
+can help us improve future automake versions.
+
+END
+  if test x"$ACCEPT_INFERIOR_RM_PROGRAM" = x"yes"; then
+    echo 'Configuration will proceed anyway, since you have set the' >&2
+    echo 'ACCEPT_INFERIOR_RM_PROGRAM variable to "yes"' >&2
+    echo >&2
+  else
+    cat >&2 <<'END'
+Aborting the configuration process, to ensure you take notice of the issue.
+
+You can download and install GNU coreutils to get an 'rm' implementation
+that behaves properly: <http://www.gnu.org/software/coreutils/>.
+
+If you want to complete the configuration process using your problematic
+'rm' anyway, export the environment variable ACCEPT_INFERIOR_RM_PROGRAM
+to "yes", and re-run configure.
+
+END
+    as_fn_error $? "Your 'rm' program is bad, sorry." "$LINENO" 5
+  fi
+fi
+ac_config_headers="$ac_config_headers config.h"
+
+
+# Check whether --enable-silent-rules was given.
+if test "${enable_silent_rules+set}" = set; then :
+  enableval=$enable_silent_rules;
+fi
+
+case $enable_silent_rules in # (((
+  yes) AM_DEFAULT_VERBOSITY=0;;
+   no) AM_DEFAULT_VERBOSITY=1;;
+    *) AM_DEFAULT_VERBOSITY=0;;
+esac
+am_make=${MAKE-make}
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $am_make supports nested variables" >&5
+$as_echo_n "checking whether $am_make supports nested variables... " >&6; }
+if ${am_cv_make_support_nested_variables+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if $as_echo 'TRUE=$(BAR$(V))
+BAR0=false
+BAR1=true
+V=1
+am__doit:
+	@$(TRUE)
+.PHONY: am__doit' | $am_make -f - >/dev/null 2>&1; then
+  am_cv_make_support_nested_variables=yes
+else
+  am_cv_make_support_nested_variables=no
+fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_make_support_nested_variables" >&5
+$as_echo "$am_cv_make_support_nested_variables" >&6; }
+if test $am_cv_make_support_nested_variables = yes; then
+    AM_V='$(V)'
+  AM_DEFAULT_V='$(AM_DEFAULT_VERBOSITY)'
+else
+  AM_V=$AM_DEFAULT_VERBOSITY
+  AM_DEFAULT_V=$AM_DEFAULT_VERBOSITY
+fi
+AM_BACKSLASH='\'
+
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to enable maintainer-specific portions of Makefiles" >&5
+$as_echo_n "checking whether to enable maintainer-specific portions of Makefiles... " >&6; }
+    # Check whether --enable-maintainer-mode was given.
+if test "${enable_maintainer_mode+set}" = set; then :
+  enableval=$enable_maintainer_mode; USE_MAINTAINER_MODE=$enableval
+else
+  USE_MAINTAINER_MODE=no
+fi
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $USE_MAINTAINER_MODE" >&5
+$as_echo "$USE_MAINTAINER_MODE" >&6; }
+   if test $USE_MAINTAINER_MODE = yes; then
+  MAINTAINER_MODE_TRUE=
+  MAINTAINER_MODE_FALSE='#'
+else
+  MAINTAINER_MODE_TRUE='#'
+  MAINTAINER_MODE_FALSE=
+fi
+
+  MAINT=$MAINTAINER_MODE_TRUE
+
+
+
+
+
+
+
+
+
+
+
+
+if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then
+	if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}pkg-config", so it can be a program name with args.
+set dummy ${ac_tool_prefix}pkg-config; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_PKG_CONFIG+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $PKG_CONFIG in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_PKG_CONFIG="$PKG_CONFIG" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_PKG_CONFIG="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  ;;
+esac
+fi
+PKG_CONFIG=$ac_cv_path_PKG_CONFIG
+if test -n "$PKG_CONFIG"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $PKG_CONFIG" >&5
+$as_echo "$PKG_CONFIG" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_path_PKG_CONFIG"; then
+  ac_pt_PKG_CONFIG=$PKG_CONFIG
+  # Extract the first word of "pkg-config", so it can be a program name with args.
+set dummy pkg-config; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_ac_pt_PKG_CONFIG+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $ac_pt_PKG_CONFIG in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_ac_pt_PKG_CONFIG="$ac_pt_PKG_CONFIG" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_ac_pt_PKG_CONFIG="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  ;;
+esac
+fi
+ac_pt_PKG_CONFIG=$ac_cv_path_ac_pt_PKG_CONFIG
+if test -n "$ac_pt_PKG_CONFIG"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_pt_PKG_CONFIG" >&5
+$as_echo "$ac_pt_PKG_CONFIG" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_pt_PKG_CONFIG" = x; then
+    PKG_CONFIG=""
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    PKG_CONFIG=$ac_pt_PKG_CONFIG
+  fi
+else
+  PKG_CONFIG="$ac_cv_path_PKG_CONFIG"
+fi
+
+fi
+if test -n "$PKG_CONFIG"; then
+	_pkg_min_version=0.9.0
+	{ $as_echo "$as_me:${as_lineno-$LINENO}: checking pkg-config is at least version $_pkg_min_version" >&5
+$as_echo_n "checking pkg-config is at least version $_pkg_min_version... " >&6; }
+	if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then
+		{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+	else
+		{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+		PKG_CONFIG=""
+	fi
+fi
+
+
+	if (test "${CFLAGS}" = ""); then
+		CFLAGS="-Wall -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2"
+	fi
+	if (test "$USE_MAINTAINER_MODE" = "yes"); then
+		CFLAGS+=" -Werror -Wextra"
+		CFLAGS+=" -Wno-unused-parameter"
+		CFLAGS+=" -Wno-missing-field-initializers"
+		CFLAGS+=" -Wdeclaration-after-statement"
+		CFLAGS+=" -Wmissing-declarations"
+		CFLAGS+=" -Wredundant-decls"
+		CFLAGS+=" -Wcast-align"
+		CFLAGS="$CFLAGS -DG_DISABLE_DEPRECATED"
+	fi
+
+
+
+
+
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args.
+set dummy ${ac_tool_prefix}gcc; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_CC+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$CC"; then
+  ac_cv_prog_CC="$CC" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_CC="${ac_tool_prefix}gcc"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+CC=$ac_cv_prog_CC
+if test -n "$CC"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
+$as_echo "$CC" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_prog_CC"; then
+  ac_ct_CC=$CC
+  # Extract the first word of "gcc", so it can be a program name with args.
+set dummy gcc; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_ac_ct_CC+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_CC"; then
+  ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_ac_ct_CC="gcc"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_CC=$ac_cv_prog_ac_ct_CC
+if test -n "$ac_ct_CC"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5
+$as_echo "$ac_ct_CC" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_ct_CC" = x; then
+    CC=""
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    CC=$ac_ct_CC
+  fi
+else
+  CC="$ac_cv_prog_CC"
+fi
+
+if test -z "$CC"; then
+          if test -n "$ac_tool_prefix"; then
+    # Extract the first word of "${ac_tool_prefix}cc", so it can be a program name with args.
+set dummy ${ac_tool_prefix}cc; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_CC+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$CC"; then
+  ac_cv_prog_CC="$CC" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_CC="${ac_tool_prefix}cc"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+CC=$ac_cv_prog_CC
+if test -n "$CC"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
+$as_echo "$CC" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+  fi
+fi
+if test -z "$CC"; then
+  # Extract the first word of "cc", so it can be a program name with args.
+set dummy cc; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_CC+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$CC"; then
+  ac_cv_prog_CC="$CC" # Let the user override the test.
+else
+  ac_prog_rejected=no
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then
+       ac_prog_rejected=yes
+       continue
+     fi
+    ac_cv_prog_CC="cc"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+if test $ac_prog_rejected = yes; then
+  # We found a bogon in the path, so make sure we never use it.
+  set dummy $ac_cv_prog_CC
+  shift
+  if test $# != 0; then
+    # We chose a different compiler from the bogus one.
+    # However, it has the same basename, so the bogon will be chosen
+    # first if we set CC to just the basename; use the full file name.
+    shift
+    ac_cv_prog_CC="$as_dir/$ac_word${1+' '}$@"
+  fi
+fi
+fi
+fi
+CC=$ac_cv_prog_CC
+if test -n "$CC"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
+$as_echo "$CC" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$CC"; then
+  if test -n "$ac_tool_prefix"; then
+  for ac_prog in cl.exe
+  do
+    # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args.
+set dummy $ac_tool_prefix$ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_CC+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$CC"; then
+  ac_cv_prog_CC="$CC" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_CC="$ac_tool_prefix$ac_prog"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+CC=$ac_cv_prog_CC
+if test -n "$CC"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
+$as_echo "$CC" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+    test -n "$CC" && break
+  done
+fi
+if test -z "$CC"; then
+  ac_ct_CC=$CC
+  for ac_prog in cl.exe
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_ac_ct_CC+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_CC"; then
+  ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_ac_ct_CC="$ac_prog"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_CC=$ac_cv_prog_ac_ct_CC
+if test -n "$ac_ct_CC"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5
+$as_echo "$ac_ct_CC" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+  test -n "$ac_ct_CC" && break
+done
+
+  if test "x$ac_ct_CC" = x; then
+    CC=""
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    CC=$ac_ct_CC
+  fi
+fi
+
+fi
+
+
+test -z "$CC" && { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "no acceptable C compiler found in \$PATH
+See \`config.log' for more details" "$LINENO" 5; }
+
+# Provide some information about the compiler.
+$as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler version" >&5
+set X $ac_compile
+ac_compiler=$2
+for ac_option in --version -v -V -qversion; do
+  { { ac_try="$ac_compiler $ac_option >&5"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_compiler $ac_option >&5") 2>conftest.err
+  ac_status=$?
+  if test -s conftest.err; then
+    sed '10a\
+... rest of stderr output deleted ...
+         10q' conftest.err >conftest.er1
+    cat conftest.er1 >&5
+  fi
+  rm -f conftest.er1 conftest.err
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }
+done
+
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+ac_clean_files_save=$ac_clean_files
+ac_clean_files="$ac_clean_files a.out a.out.dSYM a.exe b.out"
+# Try to create an executable without -o first, disregard a.out.
+# It will help us diagnose broken compilers, and finding out an intuition
+# of exeext.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the C compiler works" >&5
+$as_echo_n "checking whether the C compiler works... " >&6; }
+ac_link_default=`$as_echo "$ac_link" | sed 's/ -o *conftest[^ ]*//'`
+
+# The possible output files:
+ac_files="a.out conftest.exe conftest a.exe a_out.exe b.out conftest.*"
+
+ac_rmfiles=
+for ac_file in $ac_files
+do
+  case $ac_file in
+    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;;
+    * ) ac_rmfiles="$ac_rmfiles $ac_file";;
+  esac
+done
+rm -f $ac_rmfiles
+
+if { { ac_try="$ac_link_default"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_link_default") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then :
+  # Autoconf-2.13 could set the ac_cv_exeext variable to `no'.
+# So ignore a value of `no', otherwise this would lead to `EXEEXT = no'
+# in a Makefile.  We should not override ac_cv_exeext if it was cached,
+# so that the user can short-circuit this test for compilers unknown to
+# Autoconf.
+for ac_file in $ac_files ''
+do
+  test -f "$ac_file" || continue
+  case $ac_file in
+    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj )
+	;;
+    [ab].out )
+	# We found the default executable, but exeext='' is most
+	# certainly right.
+	break;;
+    *.* )
+	if test "${ac_cv_exeext+set}" = set && test "$ac_cv_exeext" != no;
+	then :; else
+	   ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'`
+	fi
+	# We set ac_cv_exeext here because the later test for it is not
+	# safe: cross compilers may not add the suffix if given an `-o'
+	# argument, so we may need to know it at that point already.
+	# Even if this section looks crufty: it has the advantage of
+	# actually working.
+	break;;
+    * )
+	break;;
+  esac
+done
+test "$ac_cv_exeext" = no && ac_cv_exeext=
+
+else
+  ac_file=''
+fi
+if test -z "$ac_file"; then :
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+$as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error 77 "C compiler cannot create executables
+See \`config.log' for more details" "$LINENO" 5; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler default output file name" >&5
+$as_echo_n "checking for C compiler default output file name... " >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_file" >&5
+$as_echo "$ac_file" >&6; }
+ac_exeext=$ac_cv_exeext
+
+rm -f -r a.out a.out.dSYM a.exe conftest$ac_cv_exeext b.out
+ac_clean_files=$ac_clean_files_save
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of executables" >&5
+$as_echo_n "checking for suffix of executables... " >&6; }
+if { { ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_link") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then :
+  # If both `conftest.exe' and `conftest' are `present' (well, observable)
+# catch `conftest.exe'.  For instance with Cygwin, `ls conftest' will
+# work properly (i.e., refer to `conftest.exe'), while it won't with
+# `rm'.
+for ac_file in conftest.exe conftest conftest.*; do
+  test -f "$ac_file" || continue
+  case $ac_file in
+    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;;
+    *.* ) ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'`
+	  break;;
+    * ) break;;
+  esac
+done
+else
+  { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "cannot compute suffix of executables: cannot compile and link
+See \`config.log' for more details" "$LINENO" 5; }
+fi
+rm -f conftest conftest$ac_cv_exeext
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_exeext" >&5
+$as_echo "$ac_cv_exeext" >&6; }
+
+rm -f conftest.$ac_ext
+EXEEXT=$ac_cv_exeext
+ac_exeext=$EXEEXT
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <stdio.h>
+int
+main ()
+{
+FILE *f = fopen ("conftest.out", "w");
+ return ferror (f) || fclose (f) != 0;
+
+  ;
+  return 0;
+}
+_ACEOF
+ac_clean_files="$ac_clean_files conftest.out"
+# Check that the compiler produces executables we can run.  If not, either
+# the compiler is broken, or we cross compile.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are cross compiling" >&5
+$as_echo_n "checking whether we are cross compiling... " >&6; }
+if test "$cross_compiling" != yes; then
+  { { ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_link") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }
+  if { ac_try='./conftest$ac_cv_exeext'
+  { { case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_try") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; }; then
+    cross_compiling=no
+  else
+    if test "$cross_compiling" = maybe; then
+	cross_compiling=yes
+    else
+	{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "cannot run C compiled programs.
+If you meant to cross compile, use \`--host'.
+See \`config.log' for more details" "$LINENO" 5; }
+    fi
+  fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $cross_compiling" >&5
+$as_echo "$cross_compiling" >&6; }
+
+rm -f conftest.$ac_ext conftest$ac_cv_exeext conftest.out
+ac_clean_files=$ac_clean_files_save
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of object files" >&5
+$as_echo_n "checking for suffix of object files... " >&6; }
+if ${ac_cv_objext+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.o conftest.obj
+if { { ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_compile") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then :
+  for ac_file in conftest.o conftest.obj conftest.*; do
+  test -f "$ac_file" || continue;
+  case $ac_file in
+    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM ) ;;
+    *) ac_cv_objext=`expr "$ac_file" : '.*\.\(.*\)'`
+       break;;
+  esac
+done
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "cannot compute suffix of object files: cannot compile
+See \`config.log' for more details" "$LINENO" 5; }
+fi
+rm -f conftest.$ac_cv_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_objext" >&5
+$as_echo "$ac_cv_objext" >&6; }
+OBJEXT=$ac_cv_objext
+ac_objext=$OBJEXT
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are using the GNU C compiler" >&5
+$as_echo_n "checking whether we are using the GNU C compiler... " >&6; }
+if ${ac_cv_c_compiler_gnu+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+#ifndef __GNUC__
+       choke me
+#endif
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_compiler_gnu=yes
+else
+  ac_compiler_gnu=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+ac_cv_c_compiler_gnu=$ac_compiler_gnu
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_compiler_gnu" >&5
+$as_echo "$ac_cv_c_compiler_gnu" >&6; }
+if test $ac_compiler_gnu = yes; then
+  GCC=yes
+else
+  GCC=
+fi
+ac_test_CFLAGS=${CFLAGS+set}
+ac_save_CFLAGS=$CFLAGS
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC accepts -g" >&5
+$as_echo_n "checking whether $CC accepts -g... " >&6; }
+if ${ac_cv_prog_cc_g+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_save_c_werror_flag=$ac_c_werror_flag
+   ac_c_werror_flag=yes
+   ac_cv_prog_cc_g=no
+   CFLAGS="-g"
+   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_cv_prog_cc_g=yes
+else
+  CFLAGS=""
+      cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+
+else
+  ac_c_werror_flag=$ac_save_c_werror_flag
+	 CFLAGS="-g"
+	 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_cv_prog_cc_g=yes
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+   ac_c_werror_flag=$ac_save_c_werror_flag
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_g" >&5
+$as_echo "$ac_cv_prog_cc_g" >&6; }
+if test "$ac_test_CFLAGS" = set; then
+  CFLAGS=$ac_save_CFLAGS
+elif test $ac_cv_prog_cc_g = yes; then
+  if test "$GCC" = yes; then
+    CFLAGS="-g -O2"
+  else
+    CFLAGS="-g"
+  fi
+else
+  if test "$GCC" = yes; then
+    CFLAGS="-O2"
+  else
+    CFLAGS=
+  fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $CC option to accept ISO C89" >&5
+$as_echo_n "checking for $CC option to accept ISO C89... " >&6; }
+if ${ac_cv_prog_cc_c89+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_cv_prog_cc_c89=no
+ac_save_CC=$CC
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <stdarg.h>
+#include <stdio.h>
+struct stat;
+/* Most of the following tests are stolen from RCS 5.7's src/conf.sh.  */
+struct buf { int x; };
+FILE * (*rcsopen) (struct buf *, struct stat *, int);
+static char *e (p, i)
+     char **p;
+     int i;
+{
+  return p[i];
+}
+static char *f (char * (*g) (char **, int), char **p, ...)
+{
+  char *s;
+  va_list v;
+  va_start (v,p);
+  s = g (p, va_arg (v,int));
+  va_end (v);
+  return s;
+}
+
+/* OSF 4.0 Compaq cc is some sort of almost-ANSI by default.  It has
+   function prototypes and stuff, but not '\xHH' hex character constants.
+   These don't provoke an error unfortunately, instead are silently treated
+   as 'x'.  The following induces an error, until -std is added to get
+   proper ANSI mode.  Curiously '\x00'!='x' always comes out true, for an
+   array size at least.  It's necessary to write '\x00'==0 to get something
+   that's true only with -std.  */
+int osf4_cc_array ['\x00' == 0 ? 1 : -1];
+
+/* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters
+   inside strings and character constants.  */
+#define FOO(x) 'x'
+int xlc6_cc_array[FOO(a) == 'x' ? 1 : -1];
+
+int test (int i, double x);
+struct s1 {int (*f) (int a);};
+struct s2 {int (*f) (double a);};
+int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int);
+int argc;
+char **argv;
+int
+main ()
+{
+return f (e, argv, 0) != argv[0]  ||  f (e, argv, 1) != argv[1];
+  ;
+  return 0;
+}
+_ACEOF
+for ac_arg in '' -qlanglvl=extc89 -qlanglvl=ansi -std \
+	-Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__"
+do
+  CC="$ac_save_CC $ac_arg"
+  if ac_fn_c_try_compile "$LINENO"; then :
+  ac_cv_prog_cc_c89=$ac_arg
+fi
+rm -f core conftest.err conftest.$ac_objext
+  test "x$ac_cv_prog_cc_c89" != "xno" && break
+done
+rm -f conftest.$ac_ext
+CC=$ac_save_CC
+
+fi
+# AC_CACHE_VAL
+case "x$ac_cv_prog_cc_c89" in
+  x)
+    { $as_echo "$as_me:${as_lineno-$LINENO}: result: none needed" >&5
+$as_echo "none needed" >&6; } ;;
+  xno)
+    { $as_echo "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5
+$as_echo "unsupported" >&6; } ;;
+  *)
+    CC="$CC $ac_cv_prog_cc_c89"
+    { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c89" >&5
+$as_echo "$ac_cv_prog_cc_c89" >&6; } ;;
+esac
+if test "x$ac_cv_prog_cc_c89" != xno; then :
+
+fi
+
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC understands -c and -o together" >&5
+$as_echo_n "checking whether $CC understands -c and -o together... " >&6; }
+if ${am_cv_prog_cc_c_o+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+  # Make sure it works both with $CC and with simple cc.
+  # Following AC_PROG_CC_C_O, we do the test twice because some
+  # compilers refuse to overwrite an existing .o file with -o,
+  # though they will create one.
+  am_cv_prog_cc_c_o=yes
+  for am_i in 1 2; do
+    if { echo "$as_me:$LINENO: $CC -c conftest.$ac_ext -o conftest2.$ac_objext" >&5
+   ($CC -c conftest.$ac_ext -o conftest2.$ac_objext) >&5 2>&5
+   ac_status=$?
+   echo "$as_me:$LINENO: \$? = $ac_status" >&5
+   (exit $ac_status); } \
+         && test -f conftest2.$ac_objext; then
+      : OK
+    else
+      am_cv_prog_cc_c_o=no
+      break
+    fi
+  done
+  rm -f core conftest*
+  unset am_i
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_prog_cc_c_o" >&5
+$as_echo "$am_cv_prog_cc_c_o" >&6; }
+if test "$am_cv_prog_cc_c_o" != yes; then
+   # Losing compiler, so override with the script.
+   # FIXME: It is wrong to rewrite CC.
+   # But if we don't then we get into trouble of one sort or another.
+   # A longer-term fix would be to have automake use am__CC in this case,
+   # and then we could set am__CC="\$(top_srcdir)/compile \$(CC)"
+   CC="$am_aux_dir/compile $CC"
+fi
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+DEPDIR="${am__leading_dot}deps"
+
+ac_config_commands="$ac_config_commands depfiles"
+
+
+am_make=${MAKE-make}
+cat > confinc << 'END'
+am__doit:
+	@echo this is the am__doit target
+.PHONY: am__doit
+END
+# If we don't find an include directive, just comment out the code.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for style of include used by $am_make" >&5
+$as_echo_n "checking for style of include used by $am_make... " >&6; }
+am__include="#"
+am__quote=
+_am_result=none
+# First try GNU make style include.
+echo "include confinc" > confmf
+# Ignore all kinds of additional output from 'make'.
+case `$am_make -s -f confmf 2> /dev/null` in #(
+*the\ am__doit\ target*)
+  am__include=include
+  am__quote=
+  _am_result=GNU
+  ;;
+esac
+# Now try BSD make style include.
+if test "$am__include" = "#"; then
+   echo '.include "confinc"' > confmf
+   case `$am_make -s -f confmf 2> /dev/null` in #(
+   *the\ am__doit\ target*)
+     am__include=.include
+     am__quote="\""
+     _am_result=BSD
+     ;;
+   esac
+fi
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $_am_result" >&5
+$as_echo "$_am_result" >&6; }
+rm -f confinc confmf
+
+# Check whether --enable-dependency-tracking was given.
+if test "${enable_dependency_tracking+set}" = set; then :
+  enableval=$enable_dependency_tracking;
+fi
+
+if test "x$enable_dependency_tracking" != xno; then
+  am_depcomp="$ac_aux_dir/depcomp"
+  AMDEPBACKSLASH='\'
+  am__nodep='_no'
+fi
+ if test "x$enable_dependency_tracking" != xno; then
+  AMDEP_TRUE=
+  AMDEP_FALSE='#'
+else
+  AMDEP_TRUE='#'
+  AMDEP_FALSE=
+fi
+
+
+
+depcc="$CC"   am_compiler_list=
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking dependency style of $depcc" >&5
+$as_echo_n "checking dependency style of $depcc... " >&6; }
+if ${am_cv_CC_dependencies_compiler_type+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -z "$AMDEP_TRUE" && test -f "$am_depcomp"; then
+  # We make a subdir and do the tests there.  Otherwise we can end up
+  # making bogus files that we don't know about and never remove.  For
+  # instance it was reported that on HP-UX the gcc test will end up
+  # making a dummy file named 'D' -- because '-MD' means "put the output
+  # in D".
+  rm -rf conftest.dir
+  mkdir conftest.dir
+  # Copy depcomp to subdir because otherwise we won't find it if we're
+  # using a relative directory.
+  cp "$am_depcomp" conftest.dir
+  cd conftest.dir
+  # We will build objects and dependencies in a subdirectory because
+  # it helps to detect inapplicable dependency modes.  For instance
+  # both Tru64's cc and ICC support -MD to output dependencies as a
+  # side effect of compilation, but ICC will put the dependencies in
+  # the current directory while Tru64 will put them in the object
+  # directory.
+  mkdir sub
+
+  am_cv_CC_dependencies_compiler_type=none
+  if test "$am_compiler_list" = ""; then
+     am_compiler_list=`sed -n 's/^#*\([a-zA-Z0-9]*\))$/\1/p' < ./depcomp`
+  fi
+  am__universal=false
+  case " $depcc " in #(
+     *\ -arch\ *\ -arch\ *) am__universal=true ;;
+     esac
+
+  for depmode in $am_compiler_list; do
+    # Setup a source with many dependencies, because some compilers
+    # like to wrap large dependency lists on column 80 (with \), and
+    # we should not choose a depcomp mode which is confused by this.
+    #
+    # We need to recreate these files for each test, as the compiler may
+    # overwrite some of them when testing with obscure command lines.
+    # This happens at least with the AIX C compiler.
+    : > sub/conftest.c
+    for i in 1 2 3 4 5 6; do
+      echo '#include "conftst'$i'.h"' >> sub/conftest.c
+      # Using ": > sub/conftst$i.h" creates only sub/conftst1.h with
+      # Solaris 10 /bin/sh.
+      echo '/* dummy */' > sub/conftst$i.h
+    done
+    echo "${am__include} ${am__quote}sub/conftest.Po${am__quote}" > confmf
+
+    # We check with '-c' and '-o' for the sake of the "dashmstdout"
+    # mode.  It turns out that the SunPro C++ compiler does not properly
+    # handle '-M -o', and we need to detect this.  Also, some Intel
+    # versions had trouble with output in subdirs.
+    am__obj=sub/conftest.${OBJEXT-o}
+    am__minus_obj="-o $am__obj"
+    case $depmode in
+    gcc)
+      # This depmode causes a compiler race in universal mode.
+      test "$am__universal" = false || continue
+      ;;
+    nosideeffect)
+      # After this tag, mechanisms are not by side-effect, so they'll
+      # only be used when explicitly requested.
+      if test "x$enable_dependency_tracking" = xyes; then
+	continue
+      else
+	break
+      fi
+      ;;
+    msvc7 | msvc7msys | msvisualcpp | msvcmsys)
+      # This compiler won't grok '-c -o', but also, the minuso test has
+      # not run yet.  These depmodes are late enough in the game, and
+      # so weak that their functioning should not be impacted.
+      am__obj=conftest.${OBJEXT-o}
+      am__minus_obj=
+      ;;
+    none) break ;;
+    esac
+    if depmode=$depmode \
+       source=sub/conftest.c object=$am__obj \
+       depfile=sub/conftest.Po tmpdepfile=sub/conftest.TPo \
+       $SHELL ./depcomp $depcc -c $am__minus_obj sub/conftest.c \
+         >/dev/null 2>conftest.err &&
+       grep sub/conftst1.h sub/conftest.Po > /dev/null 2>&1 &&
+       grep sub/conftst6.h sub/conftest.Po > /dev/null 2>&1 &&
+       grep $am__obj sub/conftest.Po > /dev/null 2>&1 &&
+       ${MAKE-make} -s -f confmf > /dev/null 2>&1; then
+      # icc doesn't choke on unknown options, it will just issue warnings
+      # or remarks (even with -Werror).  So we grep stderr for any message
+      # that says an option was ignored or not supported.
+      # When given -MP, icc 7.0 and 7.1 complain thusly:
+      #   icc: Command line warning: ignoring option '-M'; no argument required
+      # The diagnosis changed in icc 8.0:
+      #   icc: Command line remark: option '-MP' not supported
+      if (grep 'ignoring option' conftest.err ||
+          grep 'not supported' conftest.err) >/dev/null 2>&1; then :; else
+        am_cv_CC_dependencies_compiler_type=$depmode
+        break
+      fi
+    fi
+  done
+
+  cd ..
+  rm -rf conftest.dir
+else
+  am_cv_CC_dependencies_compiler_type=none
+fi
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_CC_dependencies_compiler_type" >&5
+$as_echo "$am_cv_CC_dependencies_compiler_type" >&6; }
+CCDEPMODE=depmode=$am_cv_CC_dependencies_compiler_type
+
+ if
+  test "x$enable_dependency_tracking" != xno \
+  && test "$am_cv_CC_dependencies_compiler_type" = gcc3; then
+  am__fastdepCC_TRUE=
+  am__fastdepCC_FALSE='#'
+else
+  am__fastdepCC_TRUE='#'
+  am__fastdepCC_FALSE=
+fi
+
+
+
+
+	{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CC-cc} accepts -fPIE" >&5
+$as_echo_n "checking whether ${CC-cc} accepts -fPIE... " >&6; }
+if ${ac_cv_prog_cc_pie+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+
+		echo 'void f(){}' > conftest.c
+		if test -z "`${CC-cc} -fPIE -pie -c conftest.c 2>&1`"; then
+			ac_cv_prog_cc_pie=yes
+		else
+			ac_cv_prog_cc_pie=no
+		fi
+		rm -rf conftest*
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_pie" >&5
+$as_echo "$ac_cv_prog_cc_pie" >&6; }
+
+
+
+
+
+
+
+# Check whether --enable-static was given.
+if test "${enable_static+set}" = set; then :
+  enableval=$enable_static; p=${PACKAGE-default}
+    case $enableval in
+    yes) enable_static=yes ;;
+    no) enable_static=no ;;
+    *)
+     enable_static=no
+      # Look at the argument we got.  We use all the common list separators.
+      lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR,"
+      for pkg in $enableval; do
+	IFS="$lt_save_ifs"
+	if test "X$pkg" = "X$p"; then
+	  enable_static=yes
+	fi
+      done
+      IFS="$lt_save_ifs"
+      ;;
+    esac
+else
+  enable_static=no
+fi
+
+
+
+
+
+
+
+
+
+case `pwd` in
+  *\ * | *\	*)
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Libtool does not cope well with whitespace in \`pwd\`" >&5
+$as_echo "$as_me: WARNING: Libtool does not cope well with whitespace in \`pwd\`" >&2;} ;;
+esac
+
+
+
+macro_version='2.4.2'
+macro_revision='1.3337'
+
+
+
+
+
+
+
+
+
+
+
+
+
+ltmain="$ac_aux_dir/ltmain.sh"
+
+# Make sure we can run config.sub.
+$SHELL "$ac_aux_dir/config.sub" sun4 >/dev/null 2>&1 ||
+  as_fn_error $? "cannot run $SHELL $ac_aux_dir/config.sub" "$LINENO" 5
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking build system type" >&5
+$as_echo_n "checking build system type... " >&6; }
+if ${ac_cv_build+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_build_alias=$build_alias
+test "x$ac_build_alias" = x &&
+  ac_build_alias=`$SHELL "$ac_aux_dir/config.guess"`
+test "x$ac_build_alias" = x &&
+  as_fn_error $? "cannot guess build type; you must specify one" "$LINENO" 5
+ac_cv_build=`$SHELL "$ac_aux_dir/config.sub" $ac_build_alias` ||
+  as_fn_error $? "$SHELL $ac_aux_dir/config.sub $ac_build_alias failed" "$LINENO" 5
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_build" >&5
+$as_echo "$ac_cv_build" >&6; }
+case $ac_cv_build in
+*-*-*) ;;
+*) as_fn_error $? "invalid value of canonical build" "$LINENO" 5;;
+esac
+build=$ac_cv_build
+ac_save_IFS=$IFS; IFS='-'
+set x $ac_cv_build
+shift
+build_cpu=$1
+build_vendor=$2
+shift; shift
+# Remember, the first character of IFS is used to create $*,
+# except with old shells:
+build_os=$*
+IFS=$ac_save_IFS
+case $build_os in *\ *) build_os=`echo "$build_os" | sed 's/ /-/g'`;; esac
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking host system type" >&5
+$as_echo_n "checking host system type... " >&6; }
+if ${ac_cv_host+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test "x$host_alias" = x; then
+  ac_cv_host=$ac_cv_build
+else
+  ac_cv_host=`$SHELL "$ac_aux_dir/config.sub" $host_alias` ||
+    as_fn_error $? "$SHELL $ac_aux_dir/config.sub $host_alias failed" "$LINENO" 5
+fi
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_host" >&5
+$as_echo "$ac_cv_host" >&6; }
+case $ac_cv_host in
+*-*-*) ;;
+*) as_fn_error $? "invalid value of canonical host" "$LINENO" 5;;
+esac
+host=$ac_cv_host
+ac_save_IFS=$IFS; IFS='-'
+set x $ac_cv_host
+shift
+host_cpu=$1
+host_vendor=$2
+shift; shift
+# Remember, the first character of IFS is used to create $*,
+# except with old shells:
+host_os=$*
+IFS=$ac_save_IFS
+case $host_os in *\ *) host_os=`echo "$host_os" | sed 's/ /-/g'`;; esac
+
+
+# Backslashify metacharacters that are still active within
+# double-quoted strings.
+sed_quote_subst='s/\(["`$\\]\)/\\\1/g'
+
+# Same as above, but do not quote variable references.
+double_quote_subst='s/\(["`\\]\)/\\\1/g'
+
+# Sed substitution to delay expansion of an escaped shell variable in a
+# double_quote_subst'ed string.
+delay_variable_subst='s/\\\\\\\\\\\$/\\\\\\$/g'
+
+# Sed substitution to delay expansion of an escaped single quote.
+delay_single_quote_subst='s/'\''/'\'\\\\\\\'\''/g'
+
+# Sed substitution to avoid accidental globbing in evaled expressions
+no_glob_subst='s/\*/\\\*/g'
+
+ECHO='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'
+ECHO=$ECHO$ECHO$ECHO$ECHO$ECHO
+ECHO=$ECHO$ECHO$ECHO$ECHO$ECHO$ECHO
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to print strings" >&5
+$as_echo_n "checking how to print strings... " >&6; }
+# Test print first, because it will be a builtin if present.
+if test "X`( print -r -- -n ) 2>/dev/null`" = X-n && \
+   test "X`print -r -- $ECHO 2>/dev/null`" = "X$ECHO"; then
+  ECHO='print -r --'
+elif test "X`printf %s $ECHO 2>/dev/null`" = "X$ECHO"; then
+  ECHO='printf %s\n'
+else
+  # Use this function as a fallback that always works.
+  func_fallback_echo ()
+  {
+    eval 'cat <<_LTECHO_EOF
+$1
+_LTECHO_EOF'
+  }
+  ECHO='func_fallback_echo'
+fi
+
+# func_echo_all arg...
+# Invoke $ECHO with all args, space-separated.
+func_echo_all ()
+{
+    $ECHO ""
+}
+
+case "$ECHO" in
+  printf*) { $as_echo "$as_me:${as_lineno-$LINENO}: result: printf" >&5
+$as_echo "printf" >&6; } ;;
+  print*) { $as_echo "$as_me:${as_lineno-$LINENO}: result: print -r" >&5
+$as_echo "print -r" >&6; } ;;
+  *) { $as_echo "$as_me:${as_lineno-$LINENO}: result: cat" >&5
+$as_echo "cat" >&6; } ;;
+esac
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for a sed that does not truncate output" >&5
+$as_echo_n "checking for a sed that does not truncate output... " >&6; }
+if ${ac_cv_path_SED+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+            ac_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/
+     for ac_i in 1 2 3 4 5 6 7; do
+       ac_script="$ac_script$as_nl$ac_script"
+     done
+     echo "$ac_script" 2>/dev/null | sed 99q >conftest.sed
+     { ac_script=; unset ac_script;}
+     if test -z "$SED"; then
+  ac_path_SED_found=false
+  # Loop through the user's path and test for each of PROGNAME-LIST
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_prog in sed gsed; do
+    for ac_exec_ext in '' $ac_executable_extensions; do
+      ac_path_SED="$as_dir/$ac_prog$ac_exec_ext"
+      as_fn_executable_p "$ac_path_SED" || continue
+# Check for GNU ac_path_SED and select it if it is found.
+  # Check for GNU $ac_path_SED
+case `"$ac_path_SED" --version 2>&1` in
+*GNU*)
+  ac_cv_path_SED="$ac_path_SED" ac_path_SED_found=:;;
+*)
+  ac_count=0
+  $as_echo_n 0123456789 >"conftest.in"
+  while :
+  do
+    cat "conftest.in" "conftest.in" >"conftest.tmp"
+    mv "conftest.tmp" "conftest.in"
+    cp "conftest.in" "conftest.nl"
+    $as_echo '' >> "conftest.nl"
+    "$ac_path_SED" -f conftest.sed < "conftest.nl" >"conftest.out" 2>/dev/null || break
+    diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break
+    as_fn_arith $ac_count + 1 && ac_count=$as_val
+    if test $ac_count -gt ${ac_path_SED_max-0}; then
+      # Best one so far, save it but keep looking for a better one
+      ac_cv_path_SED="$ac_path_SED"
+      ac_path_SED_max=$ac_count
+    fi
+    # 10*(2^10) chars as input seems more than enough
+    test $ac_count -gt 10 && break
+  done
+  rm -f conftest.in conftest.tmp conftest.nl conftest.out;;
+esac
+
+      $ac_path_SED_found && break 3
+    done
+  done
+  done
+IFS=$as_save_IFS
+  if test -z "$ac_cv_path_SED"; then
+    as_fn_error $? "no acceptable sed could be found in \$PATH" "$LINENO" 5
+  fi
+else
+  ac_cv_path_SED=$SED
+fi
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_SED" >&5
+$as_echo "$ac_cv_path_SED" >&6; }
+ SED="$ac_cv_path_SED"
+  rm -f conftest.sed
+
+test -z "$SED" && SED=sed
+Xsed="$SED -e 1s/^X//"
+
+
+
+
+
+
+
+
+
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for grep that handles long lines and -e" >&5
+$as_echo_n "checking for grep that handles long lines and -e... " >&6; }
+if ${ac_cv_path_GREP+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -z "$GREP"; then
+  ac_path_GREP_found=false
+  # Loop through the user's path and test for each of PROGNAME-LIST
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_prog in grep ggrep; do
+    for ac_exec_ext in '' $ac_executable_extensions; do
+      ac_path_GREP="$as_dir/$ac_prog$ac_exec_ext"
+      as_fn_executable_p "$ac_path_GREP" || continue
+# Check for GNU ac_path_GREP and select it if it is found.
+  # Check for GNU $ac_path_GREP
+case `"$ac_path_GREP" --version 2>&1` in
+*GNU*)
+  ac_cv_path_GREP="$ac_path_GREP" ac_path_GREP_found=:;;
+*)
+  ac_count=0
+  $as_echo_n 0123456789 >"conftest.in"
+  while :
+  do
+    cat "conftest.in" "conftest.in" >"conftest.tmp"
+    mv "conftest.tmp" "conftest.in"
+    cp "conftest.in" "conftest.nl"
+    $as_echo 'GREP' >> "conftest.nl"
+    "$ac_path_GREP" -e 'GREP$' -e '-(cannot match)-' < "conftest.nl" >"conftest.out" 2>/dev/null || break
+    diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break
+    as_fn_arith $ac_count + 1 && ac_count=$as_val
+    if test $ac_count -gt ${ac_path_GREP_max-0}; then
+      # Best one so far, save it but keep looking for a better one
+      ac_cv_path_GREP="$ac_path_GREP"
+      ac_path_GREP_max=$ac_count
+    fi
+    # 10*(2^10) chars as input seems more than enough
+    test $ac_count -gt 10 && break
+  done
+  rm -f conftest.in conftest.tmp conftest.nl conftest.out;;
+esac
+
+      $ac_path_GREP_found && break 3
+    done
+  done
+  done
+IFS=$as_save_IFS
+  if test -z "$ac_cv_path_GREP"; then
+    as_fn_error $? "no acceptable grep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5
+  fi
+else
+  ac_cv_path_GREP=$GREP
+fi
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_GREP" >&5
+$as_echo "$ac_cv_path_GREP" >&6; }
+ GREP="$ac_cv_path_GREP"
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for egrep" >&5
+$as_echo_n "checking for egrep... " >&6; }
+if ${ac_cv_path_EGREP+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if echo a | $GREP -E '(a|b)' >/dev/null 2>&1
+   then ac_cv_path_EGREP="$GREP -E"
+   else
+     if test -z "$EGREP"; then
+  ac_path_EGREP_found=false
+  # Loop through the user's path and test for each of PROGNAME-LIST
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_prog in egrep; do
+    for ac_exec_ext in '' $ac_executable_extensions; do
+      ac_path_EGREP="$as_dir/$ac_prog$ac_exec_ext"
+      as_fn_executable_p "$ac_path_EGREP" || continue
+# Check for GNU ac_path_EGREP and select it if it is found.
+  # Check for GNU $ac_path_EGREP
+case `"$ac_path_EGREP" --version 2>&1` in
+*GNU*)
+  ac_cv_path_EGREP="$ac_path_EGREP" ac_path_EGREP_found=:;;
+*)
+  ac_count=0
+  $as_echo_n 0123456789 >"conftest.in"
+  while :
+  do
+    cat "conftest.in" "conftest.in" >"conftest.tmp"
+    mv "conftest.tmp" "conftest.in"
+    cp "conftest.in" "conftest.nl"
+    $as_echo 'EGREP' >> "conftest.nl"
+    "$ac_path_EGREP" 'EGREP$' < "conftest.nl" >"conftest.out" 2>/dev/null || break
+    diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break
+    as_fn_arith $ac_count + 1 && ac_count=$as_val
+    if test $ac_count -gt ${ac_path_EGREP_max-0}; then
+      # Best one so far, save it but keep looking for a better one
+      ac_cv_path_EGREP="$ac_path_EGREP"
+      ac_path_EGREP_max=$ac_count
+    fi
+    # 10*(2^10) chars as input seems more than enough
+    test $ac_count -gt 10 && break
+  done
+  rm -f conftest.in conftest.tmp conftest.nl conftest.out;;
+esac
+
+      $ac_path_EGREP_found && break 3
+    done
+  done
+  done
+IFS=$as_save_IFS
+  if test -z "$ac_cv_path_EGREP"; then
+    as_fn_error $? "no acceptable egrep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5
+  fi
+else
+  ac_cv_path_EGREP=$EGREP
+fi
+
+   fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_EGREP" >&5
+$as_echo "$ac_cv_path_EGREP" >&6; }
+ EGREP="$ac_cv_path_EGREP"
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for fgrep" >&5
+$as_echo_n "checking for fgrep... " >&6; }
+if ${ac_cv_path_FGREP+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if echo 'ab*c' | $GREP -F 'ab*c' >/dev/null 2>&1
+   then ac_cv_path_FGREP="$GREP -F"
+   else
+     if test -z "$FGREP"; then
+  ac_path_FGREP_found=false
+  # Loop through the user's path and test for each of PROGNAME-LIST
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_prog in fgrep; do
+    for ac_exec_ext in '' $ac_executable_extensions; do
+      ac_path_FGREP="$as_dir/$ac_prog$ac_exec_ext"
+      as_fn_executable_p "$ac_path_FGREP" || continue
+# Check for GNU ac_path_FGREP and select it if it is found.
+  # Check for GNU $ac_path_FGREP
+case `"$ac_path_FGREP" --version 2>&1` in
+*GNU*)
+  ac_cv_path_FGREP="$ac_path_FGREP" ac_path_FGREP_found=:;;
+*)
+  ac_count=0
+  $as_echo_n 0123456789 >"conftest.in"
+  while :
+  do
+    cat "conftest.in" "conftest.in" >"conftest.tmp"
+    mv "conftest.tmp" "conftest.in"
+    cp "conftest.in" "conftest.nl"
+    $as_echo 'FGREP' >> "conftest.nl"
+    "$ac_path_FGREP" FGREP < "conftest.nl" >"conftest.out" 2>/dev/null || break
+    diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break
+    as_fn_arith $ac_count + 1 && ac_count=$as_val
+    if test $ac_count -gt ${ac_path_FGREP_max-0}; then
+      # Best one so far, save it but keep looking for a better one
+      ac_cv_path_FGREP="$ac_path_FGREP"
+      ac_path_FGREP_max=$ac_count
+    fi
+    # 10*(2^10) chars as input seems more than enough
+    test $ac_count -gt 10 && break
+  done
+  rm -f conftest.in conftest.tmp conftest.nl conftest.out;;
+esac
+
+      $ac_path_FGREP_found && break 3
+    done
+  done
+  done
+IFS=$as_save_IFS
+  if test -z "$ac_cv_path_FGREP"; then
+    as_fn_error $? "no acceptable fgrep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5
+  fi
+else
+  ac_cv_path_FGREP=$FGREP
+fi
+
+   fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_FGREP" >&5
+$as_echo "$ac_cv_path_FGREP" >&6; }
+ FGREP="$ac_cv_path_FGREP"
+
+
+test -z "$GREP" && GREP=grep
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+# Check whether --with-gnu-ld was given.
+if test "${with_gnu_ld+set}" = set; then :
+  withval=$with_gnu_ld; test "$withval" = no || with_gnu_ld=yes
+else
+  with_gnu_ld=no
+fi
+
+ac_prog=ld
+if test "$GCC" = yes; then
+  # Check if gcc -print-prog-name=ld gives a path.
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ld used by $CC" >&5
+$as_echo_n "checking for ld used by $CC... " >&6; }
+  case $host in
+  *-*-mingw*)
+    # gcc leaves a trailing carriage return which upsets mingw
+    ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;;
+  *)
+    ac_prog=`($CC -print-prog-name=ld) 2>&5` ;;
+  esac
+  case $ac_prog in
+    # Accept absolute paths.
+    [\\/]* | ?:[\\/]*)
+      re_direlt='/[^/][^/]*/\.\./'
+      # Canonicalize the pathname of ld
+      ac_prog=`$ECHO "$ac_prog"| $SED 's%\\\\%/%g'`
+      while $ECHO "$ac_prog" | $GREP "$re_direlt" > /dev/null 2>&1; do
+	ac_prog=`$ECHO $ac_prog| $SED "s%$re_direlt%/%"`
+      done
+      test -z "$LD" && LD="$ac_prog"
+      ;;
+  "")
+    # If it fails, then pretend we aren't using GCC.
+    ac_prog=ld
+    ;;
+  *)
+    # If it is relative, then search for the first ld in PATH.
+    with_gnu_ld=unknown
+    ;;
+  esac
+elif test "$with_gnu_ld" = yes; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for GNU ld" >&5
+$as_echo_n "checking for GNU ld... " >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for non-GNU ld" >&5
+$as_echo_n "checking for non-GNU ld... " >&6; }
+fi
+if ${lt_cv_path_LD+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -z "$LD"; then
+  lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
+  for ac_dir in $PATH; do
+    IFS="$lt_save_ifs"
+    test -z "$ac_dir" && ac_dir=.
+    if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then
+      lt_cv_path_LD="$ac_dir/$ac_prog"
+      # Check to see if the program is GNU ld.  I'd rather use --version,
+      # but apparently some variants of GNU ld only accept -v.
+      # Break only if it was the GNU/non-GNU ld that we prefer.
+      case `"$lt_cv_path_LD" -v 2>&1 </dev/null` in
+      *GNU* | *'with BFD'*)
+	test "$with_gnu_ld" != no && break
+	;;
+      *)
+	test "$with_gnu_ld" != yes && break
+	;;
+      esac
+    fi
+  done
+  IFS="$lt_save_ifs"
+else
+  lt_cv_path_LD="$LD" # Let the user override the test with a path.
+fi
+fi
+
+LD="$lt_cv_path_LD"
+if test -n "$LD"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LD" >&5
+$as_echo "$LD" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+test -z "$LD" && as_fn_error $? "no acceptable ld found in \$PATH" "$LINENO" 5
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if the linker ($LD) is GNU ld" >&5
+$as_echo_n "checking if the linker ($LD) is GNU ld... " >&6; }
+if ${lt_cv_prog_gnu_ld+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  # I'd rather use --version here, but apparently some GNU lds only accept -v.
+case `$LD -v 2>&1 </dev/null` in
+*GNU* | *'with BFD'*)
+  lt_cv_prog_gnu_ld=yes
+  ;;
+*)
+  lt_cv_prog_gnu_ld=no
+  ;;
+esac
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_gnu_ld" >&5
+$as_echo "$lt_cv_prog_gnu_ld" >&6; }
+with_gnu_ld=$lt_cv_prog_gnu_ld
+
+
+
+
+
+
+
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for BSD- or MS-compatible name lister (nm)" >&5
+$as_echo_n "checking for BSD- or MS-compatible name lister (nm)... " >&6; }
+if ${lt_cv_path_NM+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$NM"; then
+  # Let the user override the test.
+  lt_cv_path_NM="$NM"
+else
+  lt_nm_to_check="${ac_tool_prefix}nm"
+  if test -n "$ac_tool_prefix" && test "$build" = "$host"; then
+    lt_nm_to_check="$lt_nm_to_check nm"
+  fi
+  for lt_tmp_nm in $lt_nm_to_check; do
+    lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
+    for ac_dir in $PATH /usr/ccs/bin/elf /usr/ccs/bin /usr/ucb /bin; do
+      IFS="$lt_save_ifs"
+      test -z "$ac_dir" && ac_dir=.
+      tmp_nm="$ac_dir/$lt_tmp_nm"
+      if test -f "$tmp_nm" || test -f "$tmp_nm$ac_exeext" ; then
+	# Check to see if the nm accepts a BSD-compat flag.
+	# Adding the `sed 1q' prevents false positives on HP-UX, which says:
+	#   nm: unknown option "B" ignored
+	# Tru64's nm complains that /dev/null is an invalid object file
+	case `"$tmp_nm" -B /dev/null 2>&1 | sed '1q'` in
+	*/dev/null* | *'Invalid file or object type'*)
+	  lt_cv_path_NM="$tmp_nm -B"
+	  break
+	  ;;
+	*)
+	  case `"$tmp_nm" -p /dev/null 2>&1 | sed '1q'` in
+	  */dev/null*)
+	    lt_cv_path_NM="$tmp_nm -p"
+	    break
+	    ;;
+	  *)
+	    lt_cv_path_NM=${lt_cv_path_NM="$tmp_nm"} # keep the first match, but
+	    continue # so that we can try to find one that supports BSD flags
+	    ;;
+	  esac
+	  ;;
+	esac
+      fi
+    done
+    IFS="$lt_save_ifs"
+  done
+  : ${lt_cv_path_NM=no}
+fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_path_NM" >&5
+$as_echo "$lt_cv_path_NM" >&6; }
+if test "$lt_cv_path_NM" != "no"; then
+  NM="$lt_cv_path_NM"
+else
+  # Didn't find any BSD compatible name lister, look for dumpbin.
+  if test -n "$DUMPBIN"; then :
+    # Let the user override the test.
+  else
+    if test -n "$ac_tool_prefix"; then
+  for ac_prog in dumpbin "link -dump"
+  do
+    # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args.
+set dummy $ac_tool_prefix$ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_DUMPBIN+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$DUMPBIN"; then
+  ac_cv_prog_DUMPBIN="$DUMPBIN" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_DUMPBIN="$ac_tool_prefix$ac_prog"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+DUMPBIN=$ac_cv_prog_DUMPBIN
+if test -n "$DUMPBIN"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DUMPBIN" >&5
+$as_echo "$DUMPBIN" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+    test -n "$DUMPBIN" && break
+  done
+fi
+if test -z "$DUMPBIN"; then
+  ac_ct_DUMPBIN=$DUMPBIN
+  for ac_prog in dumpbin "link -dump"
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_ac_ct_DUMPBIN+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_DUMPBIN"; then
+  ac_cv_prog_ac_ct_DUMPBIN="$ac_ct_DUMPBIN" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_ac_ct_DUMPBIN="$ac_prog"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_DUMPBIN=$ac_cv_prog_ac_ct_DUMPBIN
+if test -n "$ac_ct_DUMPBIN"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_DUMPBIN" >&5
+$as_echo "$ac_ct_DUMPBIN" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+  test -n "$ac_ct_DUMPBIN" && break
+done
+
+  if test "x$ac_ct_DUMPBIN" = x; then
+    DUMPBIN=":"
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    DUMPBIN=$ac_ct_DUMPBIN
+  fi
+fi
+
+    case `$DUMPBIN -symbols /dev/null 2>&1 | sed '1q'` in
+    *COFF*)
+      DUMPBIN="$DUMPBIN -symbols"
+      ;;
+    *)
+      DUMPBIN=:
+      ;;
+    esac
+  fi
+
+  if test "$DUMPBIN" != ":"; then
+    NM="$DUMPBIN"
+  fi
+fi
+test -z "$NM" && NM=nm
+
+
+
+
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking the name lister ($NM) interface" >&5
+$as_echo_n "checking the name lister ($NM) interface... " >&6; }
+if ${lt_cv_nm_interface+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  lt_cv_nm_interface="BSD nm"
+  echo "int some_variable = 0;" > conftest.$ac_ext
+  (eval echo "\"\$as_me:$LINENO: $ac_compile\"" >&5)
+  (eval "$ac_compile" 2>conftest.err)
+  cat conftest.err >&5
+  (eval echo "\"\$as_me:$LINENO: $NM \\\"conftest.$ac_objext\\\"\"" >&5)
+  (eval "$NM \"conftest.$ac_objext\"" 2>conftest.err > conftest.out)
+  cat conftest.err >&5
+  (eval echo "\"\$as_me:$LINENO: output\"" >&5)
+  cat conftest.out >&5
+  if $GREP 'External.*some_variable' conftest.out > /dev/null; then
+    lt_cv_nm_interface="MS dumpbin"
+  fi
+  rm -f conftest*
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_nm_interface" >&5
+$as_echo "$lt_cv_nm_interface" >&6; }
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ln -s works" >&5
+$as_echo_n "checking whether ln -s works... " >&6; }
+LN_S=$as_ln_s
+if test "$LN_S" = "ln -s"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no, using $LN_S" >&5
+$as_echo "no, using $LN_S" >&6; }
+fi
+
+# find the maximum length of command line arguments
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking the maximum length of command line arguments" >&5
+$as_echo_n "checking the maximum length of command line arguments... " >&6; }
+if ${lt_cv_sys_max_cmd_len+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+    i=0
+  teststring="ABCD"
+
+  case $build_os in
+  msdosdjgpp*)
+    # On DJGPP, this test can blow up pretty badly due to problems in libc
+    # (any single argument exceeding 2000 bytes causes a buffer overrun
+    # during glob expansion).  Even if it were fixed, the result of this
+    # check would be larger than it should be.
+    lt_cv_sys_max_cmd_len=12288;    # 12K is about right
+    ;;
+
+  gnu*)
+    # Under GNU Hurd, this test is not required because there is
+    # no limit to the length of command line arguments.
+    # Libtool will interpret -1 as no limit whatsoever
+    lt_cv_sys_max_cmd_len=-1;
+    ;;
+
+  cygwin* | mingw* | cegcc*)
+    # On Win9x/ME, this test blows up -- it succeeds, but takes
+    # about 5 minutes as the teststring grows exponentially.
+    # Worse, since 9x/ME are not pre-emptively multitasking,
+    # you end up with a "frozen" computer, even though with patience
+    # the test eventually succeeds (with a max line length of 256k).
+    # Instead, let's just punt: use the minimum linelength reported by
+    # all of the supported platforms: 8192 (on NT/2K/XP).
+    lt_cv_sys_max_cmd_len=8192;
+    ;;
+
+  mint*)
+    # On MiNT this can take a long time and run out of memory.
+    lt_cv_sys_max_cmd_len=8192;
+    ;;
+
+  amigaos*)
+    # On AmigaOS with pdksh, this test takes hours, literally.
+    # So we just punt and use a minimum line length of 8192.
+    lt_cv_sys_max_cmd_len=8192;
+    ;;
+
+  netbsd* | freebsd* | openbsd* | darwin* | dragonfly*)
+    # This has been around since 386BSD, at least.  Likely further.
+    if test -x /sbin/sysctl; then
+      lt_cv_sys_max_cmd_len=`/sbin/sysctl -n kern.argmax`
+    elif test -x /usr/sbin/sysctl; then
+      lt_cv_sys_max_cmd_len=`/usr/sbin/sysctl -n kern.argmax`
+    else
+      lt_cv_sys_max_cmd_len=65536	# usable default for all BSDs
+    fi
+    # And add a safety zone
+    lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4`
+    lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3`
+    ;;
+
+  interix*)
+    # We know the value 262144 and hardcode it with a safety zone (like BSD)
+    lt_cv_sys_max_cmd_len=196608
+    ;;
+
+  os2*)
+    # The test takes a long time on OS/2.
+    lt_cv_sys_max_cmd_len=8192
+    ;;
+
+  osf*)
+    # Dr. Hans Ekkehard Plesser reports seeing a kernel panic running configure
+    # due to this test when exec_disable_arg_limit is 1 on Tru64. It is not
+    # nice to cause kernel panics so lets avoid the loop below.
+    # First set a reasonable default.
+    lt_cv_sys_max_cmd_len=16384
+    #
+    if test -x /sbin/sysconfig; then
+      case `/sbin/sysconfig -q proc exec_disable_arg_limit` in
+        *1*) lt_cv_sys_max_cmd_len=-1 ;;
+      esac
+    fi
+    ;;
+  sco3.2v5*)
+    lt_cv_sys_max_cmd_len=102400
+    ;;
+  sysv5* | sco5v6* | sysv4.2uw2*)
+    kargmax=`grep ARG_MAX /etc/conf/cf.d/stune 2>/dev/null`
+    if test -n "$kargmax"; then
+      lt_cv_sys_max_cmd_len=`echo $kargmax | sed 's/.*[	 ]//'`
+    else
+      lt_cv_sys_max_cmd_len=32768
+    fi
+    ;;
+  *)
+    lt_cv_sys_max_cmd_len=`(getconf ARG_MAX) 2> /dev/null`
+    if test -n "$lt_cv_sys_max_cmd_len" && \
+	test undefined != "$lt_cv_sys_max_cmd_len"; then
+      lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4`
+      lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3`
+    else
+      # Make teststring a little bigger before we do anything with it.
+      # a 1K string should be a reasonable start.
+      for i in 1 2 3 4 5 6 7 8 ; do
+        teststring=$teststring$teststring
+      done
+      SHELL=${SHELL-${CONFIG_SHELL-/bin/sh}}
+      # If test is not a shell built-in, we'll probably end up computing a
+      # maximum length that is only half of the actual maximum length, but
+      # we can't tell.
+      while { test "X"`env echo "$teststring$teststring" 2>/dev/null` \
+	         = "X$teststring$teststring"; } >/dev/null 2>&1 &&
+	      test $i != 17 # 1/2 MB should be enough
+      do
+        i=`expr $i + 1`
+        teststring=$teststring$teststring
+      done
+      # Only check the string length outside the loop.
+      lt_cv_sys_max_cmd_len=`expr "X$teststring" : ".*" 2>&1`
+      teststring=
+      # Add a significant safety factor because C++ compilers can tack on
+      # massive amounts of additional arguments before passing them to the
+      # linker.  It appears as though 1/2 is a usable value.
+      lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 2`
+    fi
+    ;;
+  esac
+
+fi
+
+if test -n $lt_cv_sys_max_cmd_len ; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_sys_max_cmd_len" >&5
+$as_echo "$lt_cv_sys_max_cmd_len" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: none" >&5
+$as_echo "none" >&6; }
+fi
+max_cmd_len=$lt_cv_sys_max_cmd_len
+
+
+
+
+
+
+: ${CP="cp -f"}
+: ${MV="mv -f"}
+: ${RM="rm -f"}
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the shell understands some XSI constructs" >&5
+$as_echo_n "checking whether the shell understands some XSI constructs... " >&6; }
+# Try some XSI features
+xsi_shell=no
+( _lt_dummy="a/b/c"
+  test "${_lt_dummy##*/},${_lt_dummy%/*},${_lt_dummy#??}"${_lt_dummy%"$_lt_dummy"}, \
+      = c,a/b,b/c, \
+    && eval 'test $(( 1 + 1 )) -eq 2 \
+    && test "${#_lt_dummy}" -eq 5' ) >/dev/null 2>&1 \
+  && xsi_shell=yes
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xsi_shell" >&5
+$as_echo "$xsi_shell" >&6; }
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the shell understands \"+=\"" >&5
+$as_echo_n "checking whether the shell understands \"+=\"... " >&6; }
+lt_shell_append=no
+( foo=bar; set foo baz; eval "$1+=\$2" && test "$foo" = barbaz ) \
+    >/dev/null 2>&1 \
+  && lt_shell_append=yes
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_shell_append" >&5
+$as_echo "$lt_shell_append" >&6; }
+
+
+if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then
+  lt_unset=unset
+else
+  lt_unset=false
+fi
+
+
+
+
+
+# test EBCDIC or ASCII
+case `echo X|tr X '\101'` in
+ A) # ASCII based system
+    # \n is not interpreted correctly by Solaris 8 /usr/ucb/tr
+  lt_SP2NL='tr \040 \012'
+  lt_NL2SP='tr \015\012 \040\040'
+  ;;
+ *) # EBCDIC based system
+  lt_SP2NL='tr \100 \n'
+  lt_NL2SP='tr \r\n \100\100'
+  ;;
+esac
+
+
+
+
+
+
+
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to convert $build file names to $host format" >&5
+$as_echo_n "checking how to convert $build file names to $host format... " >&6; }
+if ${lt_cv_to_host_file_cmd+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $host in
+  *-*-mingw* )
+    case $build in
+      *-*-mingw* ) # actually msys
+        lt_cv_to_host_file_cmd=func_convert_file_msys_to_w32
+        ;;
+      *-*-cygwin* )
+        lt_cv_to_host_file_cmd=func_convert_file_cygwin_to_w32
+        ;;
+      * ) # otherwise, assume *nix
+        lt_cv_to_host_file_cmd=func_convert_file_nix_to_w32
+        ;;
+    esac
+    ;;
+  *-*-cygwin* )
+    case $build in
+      *-*-mingw* ) # actually msys
+        lt_cv_to_host_file_cmd=func_convert_file_msys_to_cygwin
+        ;;
+      *-*-cygwin* )
+        lt_cv_to_host_file_cmd=func_convert_file_noop
+        ;;
+      * ) # otherwise, assume *nix
+        lt_cv_to_host_file_cmd=func_convert_file_nix_to_cygwin
+        ;;
+    esac
+    ;;
+  * ) # unhandled hosts (and "normal" native builds)
+    lt_cv_to_host_file_cmd=func_convert_file_noop
+    ;;
+esac
+
+fi
+
+to_host_file_cmd=$lt_cv_to_host_file_cmd
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_to_host_file_cmd" >&5
+$as_echo "$lt_cv_to_host_file_cmd" >&6; }
+
+
+
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to convert $build file names to toolchain format" >&5
+$as_echo_n "checking how to convert $build file names to toolchain format... " >&6; }
+if ${lt_cv_to_tool_file_cmd+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  #assume ordinary cross tools, or native build.
+lt_cv_to_tool_file_cmd=func_convert_file_noop
+case $host in
+  *-*-mingw* )
+    case $build in
+      *-*-mingw* ) # actually msys
+        lt_cv_to_tool_file_cmd=func_convert_file_msys_to_w32
+        ;;
+    esac
+    ;;
+esac
+
+fi
+
+to_tool_file_cmd=$lt_cv_to_tool_file_cmd
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_to_tool_file_cmd" >&5
+$as_echo "$lt_cv_to_tool_file_cmd" >&6; }
+
+
+
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $LD option to reload object files" >&5
+$as_echo_n "checking for $LD option to reload object files... " >&6; }
+if ${lt_cv_ld_reload_flag+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  lt_cv_ld_reload_flag='-r'
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_ld_reload_flag" >&5
+$as_echo "$lt_cv_ld_reload_flag" >&6; }
+reload_flag=$lt_cv_ld_reload_flag
+case $reload_flag in
+"" | " "*) ;;
+*) reload_flag=" $reload_flag" ;;
+esac
+reload_cmds='$LD$reload_flag -o $output$reload_objs'
+case $host_os in
+  cygwin* | mingw* | pw32* | cegcc*)
+    if test "$GCC" != yes; then
+      reload_cmds=false
+    fi
+    ;;
+  darwin*)
+    if test "$GCC" = yes; then
+      reload_cmds='$LTCC $LTCFLAGS -nostdlib ${wl}-r -o $output$reload_objs'
+    else
+      reload_cmds='$LD$reload_flag -o $output$reload_objs'
+    fi
+    ;;
+esac
+
+
+
+
+
+
+
+
+
+if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}objdump", so it can be a program name with args.
+set dummy ${ac_tool_prefix}objdump; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_OBJDUMP+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$OBJDUMP"; then
+  ac_cv_prog_OBJDUMP="$OBJDUMP" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_OBJDUMP="${ac_tool_prefix}objdump"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+OBJDUMP=$ac_cv_prog_OBJDUMP
+if test -n "$OBJDUMP"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $OBJDUMP" >&5
+$as_echo "$OBJDUMP" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_prog_OBJDUMP"; then
+  ac_ct_OBJDUMP=$OBJDUMP
+  # Extract the first word of "objdump", so it can be a program name with args.
+set dummy objdump; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_ac_ct_OBJDUMP+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_OBJDUMP"; then
+  ac_cv_prog_ac_ct_OBJDUMP="$ac_ct_OBJDUMP" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_ac_ct_OBJDUMP="objdump"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_OBJDUMP=$ac_cv_prog_ac_ct_OBJDUMP
+if test -n "$ac_ct_OBJDUMP"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OBJDUMP" >&5
+$as_echo "$ac_ct_OBJDUMP" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_ct_OBJDUMP" = x; then
+    OBJDUMP="false"
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    OBJDUMP=$ac_ct_OBJDUMP
+  fi
+else
+  OBJDUMP="$ac_cv_prog_OBJDUMP"
+fi
+
+test -z "$OBJDUMP" && OBJDUMP=objdump
+
+
+
+
+
+
+
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to recognize dependent libraries" >&5
+$as_echo_n "checking how to recognize dependent libraries... " >&6; }
+if ${lt_cv_deplibs_check_method+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  lt_cv_file_magic_cmd='$MAGIC_CMD'
+lt_cv_file_magic_test_file=
+lt_cv_deplibs_check_method='unknown'
+# Need to set the preceding variable on all platforms that support
+# interlibrary dependencies.
+# 'none' -- dependencies not supported.
+# `unknown' -- same as none, but documents that we really don't know.
+# 'pass_all' -- all dependencies passed with no checks.
+# 'test_compile' -- check by making test program.
+# 'file_magic [[regex]]' -- check by looking for files in library path
+# which responds to the $file_magic_cmd with a given extended regex.
+# If you have `file' or equivalent on your system and you're not sure
+# whether `pass_all' will *always* work, you probably want this one.
+
+case $host_os in
+aix[4-9]*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+beos*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+bsdi[45]*)
+  lt_cv_deplibs_check_method='file_magic ELF [0-9][0-9]*-bit [ML]SB (shared object|dynamic lib)'
+  lt_cv_file_magic_cmd='/usr/bin/file -L'
+  lt_cv_file_magic_test_file=/shlib/libc.so
+  ;;
+
+cygwin*)
+  # func_win32_libid is a shell function defined in ltmain.sh
+  lt_cv_deplibs_check_method='file_magic ^x86 archive import|^x86 DLL'
+  lt_cv_file_magic_cmd='func_win32_libid'
+  ;;
+
+mingw* | pw32*)
+  # Base MSYS/MinGW do not provide the 'file' command needed by
+  # func_win32_libid shell function, so use a weaker test based on 'objdump',
+  # unless we find 'file', for example because we are cross-compiling.
+  # func_win32_libid assumes BSD nm, so disallow it if using MS dumpbin.
+  if ( test "$lt_cv_nm_interface" = "BSD nm" && file / ) >/dev/null 2>&1; then
+    lt_cv_deplibs_check_method='file_magic ^x86 archive import|^x86 DLL'
+    lt_cv_file_magic_cmd='func_win32_libid'
+  else
+    # Keep this pattern in sync with the one in func_win32_libid.
+    lt_cv_deplibs_check_method='file_magic file format (pei*-i386(.*architecture: i386)?|pe-arm-wince|pe-x86-64)'
+    lt_cv_file_magic_cmd='$OBJDUMP -f'
+  fi
+  ;;
+
+cegcc*)
+  # use the weaker test based on 'objdump'. See mingw*.
+  lt_cv_deplibs_check_method='file_magic file format pe-arm-.*little(.*architecture: arm)?'
+  lt_cv_file_magic_cmd='$OBJDUMP -f'
+  ;;
+
+darwin* | rhapsody*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+freebsd* | dragonfly*)
+  if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then
+    case $host_cpu in
+    i*86 )
+      # Not sure whether the presence of OpenBSD here was a mistake.
+      # Let's accept both of them until this is cleared up.
+      lt_cv_deplibs_check_method='file_magic (FreeBSD|OpenBSD|DragonFly)/i[3-9]86 (compact )?demand paged shared library'
+      lt_cv_file_magic_cmd=/usr/bin/file
+      lt_cv_file_magic_test_file=`echo /usr/lib/libc.so.*`
+      ;;
+    esac
+  else
+    lt_cv_deplibs_check_method=pass_all
+  fi
+  ;;
+
+haiku*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+hpux10.20* | hpux11*)
+  lt_cv_file_magic_cmd=/usr/bin/file
+  case $host_cpu in
+  ia64*)
+    lt_cv_deplibs_check_method='file_magic (s[0-9][0-9][0-9]|ELF-[0-9][0-9]) shared object file - IA64'
+    lt_cv_file_magic_test_file=/usr/lib/hpux32/libc.so
+    ;;
+  hppa*64*)
+    lt_cv_deplibs_check_method='file_magic (s[0-9][0-9][0-9]|ELF[ -][0-9][0-9])(-bit)?( [LM]SB)? shared object( file)?[, -]* PA-RISC [0-9]\.[0-9]'
+    lt_cv_file_magic_test_file=/usr/lib/pa20_64/libc.sl
+    ;;
+  *)
+    lt_cv_deplibs_check_method='file_magic (s[0-9][0-9][0-9]|PA-RISC[0-9]\.[0-9]) shared library'
+    lt_cv_file_magic_test_file=/usr/lib/libc.sl
+    ;;
+  esac
+  ;;
+
+interix[3-9]*)
+  # PIC code is broken on Interix 3.x, that's why |\.a not |_pic\.a here
+  lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so|\.a)$'
+  ;;
+
+irix5* | irix6* | nonstopux*)
+  case $LD in
+  *-32|*"-32 ") libmagic=32-bit;;
+  *-n32|*"-n32 ") libmagic=N32;;
+  *-64|*"-64 ") libmagic=64-bit;;
+  *) libmagic=never-match;;
+  esac
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+# This must be glibc/ELF.
+linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+netbsd* | netbsdelf*-gnu)
+  if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then
+    lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so\.[0-9]+\.[0-9]+|_pic\.a)$'
+  else
+    lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so|_pic\.a)$'
+  fi
+  ;;
+
+newos6*)
+  lt_cv_deplibs_check_method='file_magic ELF [0-9][0-9]*-bit [ML]SB (executable|dynamic lib)'
+  lt_cv_file_magic_cmd=/usr/bin/file
+  lt_cv_file_magic_test_file=/usr/lib/libnls.so
+  ;;
+
+*nto* | *qnx*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+openbsd*)
+  if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then
+    lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so\.[0-9]+\.[0-9]+|\.so|_pic\.a)$'
+  else
+    lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so\.[0-9]+\.[0-9]+|_pic\.a)$'
+  fi
+  ;;
+
+osf3* | osf4* | osf5*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+rdos*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+solaris*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+sysv4 | sysv4.3*)
+  case $host_vendor in
+  motorola)
+    lt_cv_deplibs_check_method='file_magic ELF [0-9][0-9]*-bit [ML]SB (shared object|dynamic lib) M[0-9][0-9]* Version [0-9]'
+    lt_cv_file_magic_test_file=`echo /usr/lib/libc.so*`
+    ;;
+  ncr)
+    lt_cv_deplibs_check_method=pass_all
+    ;;
+  sequent)
+    lt_cv_file_magic_cmd='/bin/file'
+    lt_cv_deplibs_check_method='file_magic ELF [0-9][0-9]*-bit [LM]SB (shared object|dynamic lib )'
+    ;;
+  sni)
+    lt_cv_file_magic_cmd='/bin/file'
+    lt_cv_deplibs_check_method="file_magic ELF [0-9][0-9]*-bit [LM]SB dynamic lib"
+    lt_cv_file_magic_test_file=/lib/libc.so
+    ;;
+  siemens)
+    lt_cv_deplibs_check_method=pass_all
+    ;;
+  pc)
+    lt_cv_deplibs_check_method=pass_all
+    ;;
+  esac
+  ;;
+
+tpf*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+esac
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_deplibs_check_method" >&5
+$as_echo "$lt_cv_deplibs_check_method" >&6; }
+
+file_magic_glob=
+want_nocaseglob=no
+if test "$build" = "$host"; then
+  case $host_os in
+  mingw* | pw32*)
+    if ( shopt | grep nocaseglob ) >/dev/null 2>&1; then
+      want_nocaseglob=yes
+    else
+      file_magic_glob=`echo aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ | $SED -e "s/\(..\)/s\/[\1]\/[\1]\/g;/g"`
+    fi
+    ;;
+  esac
+fi
+
+file_magic_cmd=$lt_cv_file_magic_cmd
+deplibs_check_method=$lt_cv_deplibs_check_method
+test -z "$deplibs_check_method" && deplibs_check_method=unknown
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}dlltool", so it can be a program name with args.
+set dummy ${ac_tool_prefix}dlltool; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_DLLTOOL+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$DLLTOOL"; then
+  ac_cv_prog_DLLTOOL="$DLLTOOL" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_DLLTOOL="${ac_tool_prefix}dlltool"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+DLLTOOL=$ac_cv_prog_DLLTOOL
+if test -n "$DLLTOOL"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DLLTOOL" >&5
+$as_echo "$DLLTOOL" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_prog_DLLTOOL"; then
+  ac_ct_DLLTOOL=$DLLTOOL
+  # Extract the first word of "dlltool", so it can be a program name with args.
+set dummy dlltool; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_ac_ct_DLLTOOL+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_DLLTOOL"; then
+  ac_cv_prog_ac_ct_DLLTOOL="$ac_ct_DLLTOOL" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_ac_ct_DLLTOOL="dlltool"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_DLLTOOL=$ac_cv_prog_ac_ct_DLLTOOL
+if test -n "$ac_ct_DLLTOOL"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_DLLTOOL" >&5
+$as_echo "$ac_ct_DLLTOOL" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_ct_DLLTOOL" = x; then
+    DLLTOOL="false"
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    DLLTOOL=$ac_ct_DLLTOOL
+  fi
+else
+  DLLTOOL="$ac_cv_prog_DLLTOOL"
+fi
+
+test -z "$DLLTOOL" && DLLTOOL=dlltool
+
+
+
+
+
+
+
+
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to associate runtime and link libraries" >&5
+$as_echo_n "checking how to associate runtime and link libraries... " >&6; }
+if ${lt_cv_sharedlib_from_linklib_cmd+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  lt_cv_sharedlib_from_linklib_cmd='unknown'
+
+case $host_os in
+cygwin* | mingw* | pw32* | cegcc*)
+  # two different shell functions defined in ltmain.sh
+  # decide which to use based on capabilities of $DLLTOOL
+  case `$DLLTOOL --help 2>&1` in
+  *--identify-strict*)
+    lt_cv_sharedlib_from_linklib_cmd=func_cygming_dll_for_implib
+    ;;
+  *)
+    lt_cv_sharedlib_from_linklib_cmd=func_cygming_dll_for_implib_fallback
+    ;;
+  esac
+  ;;
+*)
+  # fallback: assume linklib IS sharedlib
+  lt_cv_sharedlib_from_linklib_cmd="$ECHO"
+  ;;
+esac
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_sharedlib_from_linklib_cmd" >&5
+$as_echo "$lt_cv_sharedlib_from_linklib_cmd" >&6; }
+sharedlib_from_linklib_cmd=$lt_cv_sharedlib_from_linklib_cmd
+test -z "$sharedlib_from_linklib_cmd" && sharedlib_from_linklib_cmd=$ECHO
+
+
+
+
+
+
+
+
+if test -n "$ac_tool_prefix"; then
+  for ac_prog in ar
+  do
+    # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args.
+set dummy $ac_tool_prefix$ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_AR+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$AR"; then
+  ac_cv_prog_AR="$AR" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_AR="$ac_tool_prefix$ac_prog"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+AR=$ac_cv_prog_AR
+if test -n "$AR"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $AR" >&5
+$as_echo "$AR" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+    test -n "$AR" && break
+  done
+fi
+if test -z "$AR"; then
+  ac_ct_AR=$AR
+  for ac_prog in ar
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_ac_ct_AR+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_AR"; then
+  ac_cv_prog_ac_ct_AR="$ac_ct_AR" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_ac_ct_AR="$ac_prog"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_AR=$ac_cv_prog_ac_ct_AR
+if test -n "$ac_ct_AR"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_AR" >&5
+$as_echo "$ac_ct_AR" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+  test -n "$ac_ct_AR" && break
+done
+
+  if test "x$ac_ct_AR" = x; then
+    AR="false"
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    AR=$ac_ct_AR
+  fi
+fi
+
+: ${AR=ar}
+: ${AR_FLAGS=cru}
+
+
+
+
+
+
+
+
+
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for archiver @FILE support" >&5
+$as_echo_n "checking for archiver @FILE support... " >&6; }
+if ${lt_cv_ar_at_file+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  lt_cv_ar_at_file=no
+   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  echo conftest.$ac_objext > conftest.lst
+      lt_ar_try='$AR $AR_FLAGS libconftest.a @conftest.lst >&5'
+      { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$lt_ar_try\""; } >&5
+  (eval $lt_ar_try) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }
+      if test "$ac_status" -eq 0; then
+	# Ensure the archiver fails upon bogus file names.
+	rm -f conftest.$ac_objext libconftest.a
+	{ { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$lt_ar_try\""; } >&5
+  (eval $lt_ar_try) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }
+	if test "$ac_status" -ne 0; then
+          lt_cv_ar_at_file=@
+        fi
+      fi
+      rm -f conftest.* libconftest.a
+
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_ar_at_file" >&5
+$as_echo "$lt_cv_ar_at_file" >&6; }
+
+if test "x$lt_cv_ar_at_file" = xno; then
+  archiver_list_spec=
+else
+  archiver_list_spec=$lt_cv_ar_at_file
+fi
+
+
+
+
+
+
+
+if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}strip", so it can be a program name with args.
+set dummy ${ac_tool_prefix}strip; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_STRIP+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$STRIP"; then
+  ac_cv_prog_STRIP="$STRIP" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_STRIP="${ac_tool_prefix}strip"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+STRIP=$ac_cv_prog_STRIP
+if test -n "$STRIP"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $STRIP" >&5
+$as_echo "$STRIP" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_prog_STRIP"; then
+  ac_ct_STRIP=$STRIP
+  # Extract the first word of "strip", so it can be a program name with args.
+set dummy strip; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_ac_ct_STRIP+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_STRIP"; then
+  ac_cv_prog_ac_ct_STRIP="$ac_ct_STRIP" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_ac_ct_STRIP="strip"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_STRIP=$ac_cv_prog_ac_ct_STRIP
+if test -n "$ac_ct_STRIP"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_STRIP" >&5
+$as_echo "$ac_ct_STRIP" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_ct_STRIP" = x; then
+    STRIP=":"
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    STRIP=$ac_ct_STRIP
+  fi
+else
+  STRIP="$ac_cv_prog_STRIP"
+fi
+
+test -z "$STRIP" && STRIP=:
+
+
+
+
+
+
+if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}ranlib", so it can be a program name with args.
+set dummy ${ac_tool_prefix}ranlib; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_RANLIB+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$RANLIB"; then
+  ac_cv_prog_RANLIB="$RANLIB" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_RANLIB="${ac_tool_prefix}ranlib"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+RANLIB=$ac_cv_prog_RANLIB
+if test -n "$RANLIB"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $RANLIB" >&5
+$as_echo "$RANLIB" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_prog_RANLIB"; then
+  ac_ct_RANLIB=$RANLIB
+  # Extract the first word of "ranlib", so it can be a program name with args.
+set dummy ranlib; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_ac_ct_RANLIB+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_RANLIB"; then
+  ac_cv_prog_ac_ct_RANLIB="$ac_ct_RANLIB" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_ac_ct_RANLIB="ranlib"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_RANLIB=$ac_cv_prog_ac_ct_RANLIB
+if test -n "$ac_ct_RANLIB"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_RANLIB" >&5
+$as_echo "$ac_ct_RANLIB" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_ct_RANLIB" = x; then
+    RANLIB=":"
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    RANLIB=$ac_ct_RANLIB
+  fi
+else
+  RANLIB="$ac_cv_prog_RANLIB"
+fi
+
+test -z "$RANLIB" && RANLIB=:
+
+
+
+
+
+
+# Determine commands to create old-style static archives.
+old_archive_cmds='$AR $AR_FLAGS $oldlib$oldobjs'
+old_postinstall_cmds='chmod 644 $oldlib'
+old_postuninstall_cmds=
+
+if test -n "$RANLIB"; then
+  case $host_os in
+  openbsd*)
+    old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB -t \$tool_oldlib"
+    ;;
+  *)
+    old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB \$tool_oldlib"
+    ;;
+  esac
+  old_archive_cmds="$old_archive_cmds~\$RANLIB \$tool_oldlib"
+fi
+
+case $host_os in
+  darwin*)
+    lock_old_archive_extraction=yes ;;
+  *)
+    lock_old_archive_extraction=no ;;
+esac
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+# If no C compiler was specified, use CC.
+LTCC=${LTCC-"$CC"}
+
+# If no C compiler flags were specified, use CFLAGS.
+LTCFLAGS=${LTCFLAGS-"$CFLAGS"}
+
+# Allow CC to be a program name with arguments.
+compiler=$CC
+
+
+# Check for command to grab the raw symbol name followed by C symbol from nm.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking command to parse $NM output from $compiler object" >&5
+$as_echo_n "checking command to parse $NM output from $compiler object... " >&6; }
+if ${lt_cv_sys_global_symbol_pipe+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+
+# These are sane defaults that work on at least a few old systems.
+# [They come from Ultrix.  What could be older than Ultrix?!! ;)]
+
+# Character class describing NM global symbol codes.
+symcode='[BCDEGRST]'
+
+# Regexp to match symbols that can be accessed directly from C.
+sympat='\([_A-Za-z][_A-Za-z0-9]*\)'
+
+# Define system-specific variables.
+case $host_os in
+aix*)
+  symcode='[BCDT]'
+  ;;
+cygwin* | mingw* | pw32* | cegcc*)
+  symcode='[ABCDGISTW]'
+  ;;
+hpux*)
+  if test "$host_cpu" = ia64; then
+    symcode='[ABCDEGRST]'
+  fi
+  ;;
+irix* | nonstopux*)
+  symcode='[BCDEGRST]'
+  ;;
+osf*)
+  symcode='[BCDEGQRST]'
+  ;;
+solaris*)
+  symcode='[BDRT]'
+  ;;
+sco3.2v5*)
+  symcode='[DT]'
+  ;;
+sysv4.2uw2*)
+  symcode='[DT]'
+  ;;
+sysv5* | sco5v6* | unixware* | OpenUNIX*)
+  symcode='[ABDT]'
+  ;;
+sysv4)
+  symcode='[DFNSTU]'
+  ;;
+esac
+
+# If we're using GNU nm, then use its standard symbol codes.
+case `$NM -V 2>&1` in
+*GNU* | *'with BFD'*)
+  symcode='[ABCDGIRSTW]' ;;
+esac
+
+# Transform an extracted symbol line into a proper C declaration.
+# Some systems (esp. on ia64) link data and code symbols differently,
+# so use this general approach.
+lt_cv_sys_global_symbol_to_cdecl="sed -n -e 's/^T .* \(.*\)$/extern int \1();/p' -e 's/^$symcode* .* \(.*\)$/extern char \1;/p'"
+
+# Transform an extracted symbol line into symbol name and symbol address
+lt_cv_sys_global_symbol_to_c_name_address="sed -n -e 's/^: \([^ ]*\)[ ]*$/  {\\\"\1\\\", (void *) 0},/p' -e 's/^$symcode* \([^ ]*\) \([^ ]*\)$/  {\"\2\", (void *) \&\2},/p'"
+lt_cv_sys_global_symbol_to_c_name_address_lib_prefix="sed -n -e 's/^: \([^ ]*\)[ ]*$/  {\\\"\1\\\", (void *) 0},/p' -e 's/^$symcode* \([^ ]*\) \(lib[^ ]*\)$/  {\"\2\", (void *) \&\2},/p' -e 's/^$symcode* \([^ ]*\) \([^ ]*\)$/  {\"lib\2\", (void *) \&\2},/p'"
+
+# Handle CRLF in mingw tool chain
+opt_cr=
+case $build_os in
+mingw*)
+  opt_cr=`$ECHO 'x\{0,1\}' | tr x '\015'` # option cr in regexp
+  ;;
+esac
+
+# Try without a prefix underscore, then with it.
+for ac_symprfx in "" "_"; do
+
+  # Transform symcode, sympat, and symprfx into a raw symbol and a C symbol.
+  symxfrm="\\1 $ac_symprfx\\2 \\2"
+
+  # Write the raw and C identifiers.
+  if test "$lt_cv_nm_interface" = "MS dumpbin"; then
+    # Fake it for dumpbin and say T for any non-static function
+    # and D for any global variable.
+    # Also find C++ and __fastcall symbols from MSVC++,
+    # which start with @ or ?.
+    lt_cv_sys_global_symbol_pipe="$AWK '"\
+"     {last_section=section; section=\$ 3};"\
+"     /^COFF SYMBOL TABLE/{for(i in hide) delete hide[i]};"\
+"     /Section length .*#relocs.*(pick any)/{hide[last_section]=1};"\
+"     \$ 0!~/External *\|/{next};"\
+"     / 0+ UNDEF /{next}; / UNDEF \([^|]\)*()/{next};"\
+"     {if(hide[section]) next};"\
+"     {f=0}; \$ 0~/\(\).*\|/{f=1}; {printf f ? \"T \" : \"D \"};"\
+"     {split(\$ 0, a, /\||\r/); split(a[2], s)};"\
+"     s[1]~/^[@?]/{print s[1], s[1]; next};"\
+"     s[1]~prfx {split(s[1],t,\"@\"); print t[1], substr(t[1],length(prfx))}"\
+"     ' prfx=^$ac_symprfx"
+  else
+    lt_cv_sys_global_symbol_pipe="sed -n -e 's/^.*[	 ]\($symcode$symcode*\)[	 ][	 ]*$ac_symprfx$sympat$opt_cr$/$symxfrm/p'"
+  fi
+  lt_cv_sys_global_symbol_pipe="$lt_cv_sys_global_symbol_pipe | sed '/ __gnu_lto/d'"
+
+  # Check to see that the pipe works correctly.
+  pipe_works=no
+
+  rm -f conftest*
+  cat > conftest.$ac_ext <<_LT_EOF
+#ifdef __cplusplus
+extern "C" {
+#endif
+char nm_test_var;
+void nm_test_func(void);
+void nm_test_func(void){}
+#ifdef __cplusplus
+}
+#endif
+int main(){nm_test_var='a';nm_test_func();return(0);}
+_LT_EOF
+
+  if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5
+  (eval $ac_compile) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+    # Now try to grab the symbols.
+    nlist=conftest.nm
+    if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$NM conftest.$ac_objext \| "$lt_cv_sys_global_symbol_pipe" \> $nlist\""; } >&5
+  (eval $NM conftest.$ac_objext \| "$lt_cv_sys_global_symbol_pipe" \> $nlist) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; } && test -s "$nlist"; then
+      # Try sorting and uniquifying the output.
+      if sort "$nlist" | uniq > "$nlist"T; then
+	mv -f "$nlist"T "$nlist"
+      else
+	rm -f "$nlist"T
+      fi
+
+      # Make sure that we snagged all the symbols we need.
+      if $GREP ' nm_test_var$' "$nlist" >/dev/null; then
+	if $GREP ' nm_test_func$' "$nlist" >/dev/null; then
+	  cat <<_LT_EOF > conftest.$ac_ext
+/* Keep this code in sync between libtool.m4, ltmain, lt_system.h, and tests.  */
+#if defined(_WIN32) || defined(__CYGWIN__) || defined(_WIN32_WCE)
+/* DATA imports from DLLs on WIN32 con't be const, because runtime
+   relocations are performed -- see ld's documentation on pseudo-relocs.  */
+# define LT_DLSYM_CONST
+#elif defined(__osf__)
+/* This system does not cope well with relocations in const data.  */
+# define LT_DLSYM_CONST
+#else
+# define LT_DLSYM_CONST const
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+_LT_EOF
+	  # Now generate the symbol file.
+	  eval "$lt_cv_sys_global_symbol_to_cdecl"' < "$nlist" | $GREP -v main >> conftest.$ac_ext'
+
+	  cat <<_LT_EOF >> conftest.$ac_ext
+
+/* The mapping between symbol names and symbols.  */
+LT_DLSYM_CONST struct {
+  const char *name;
+  void       *address;
+}
+lt__PROGRAM__LTX_preloaded_symbols[] =
+{
+  { "@PROGRAM@", (void *) 0 },
+_LT_EOF
+	  $SED "s/^$symcode$symcode* \(.*\) \(.*\)$/  {\"\2\", (void *) \&\2},/" < "$nlist" | $GREP -v main >> conftest.$ac_ext
+	  cat <<\_LT_EOF >> conftest.$ac_ext
+  {0, (void *) 0}
+};
+
+/* This works around a problem in FreeBSD linker */
+#ifdef FREEBSD_WORKAROUND
+static const void *lt_preloaded_setup() {
+  return lt__PROGRAM__LTX_preloaded_symbols;
+}
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+_LT_EOF
+	  # Now try linking the two files.
+	  mv conftest.$ac_objext conftstm.$ac_objext
+	  lt_globsym_save_LIBS=$LIBS
+	  lt_globsym_save_CFLAGS=$CFLAGS
+	  LIBS="conftstm.$ac_objext"
+	  CFLAGS="$CFLAGS$lt_prog_compiler_no_builtin_flag"
+	  if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_link\""; } >&5
+  (eval $ac_link) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; } && test -s conftest${ac_exeext}; then
+	    pipe_works=yes
+	  fi
+	  LIBS=$lt_globsym_save_LIBS
+	  CFLAGS=$lt_globsym_save_CFLAGS
+	else
+	  echo "cannot find nm_test_func in $nlist" >&5
+	fi
+      else
+	echo "cannot find nm_test_var in $nlist" >&5
+      fi
+    else
+      echo "cannot run $lt_cv_sys_global_symbol_pipe" >&5
+    fi
+  else
+    echo "$progname: failed program was:" >&5
+    cat conftest.$ac_ext >&5
+  fi
+  rm -rf conftest* conftst*
+
+  # Do not use the global_symbol_pipe unless it works.
+  if test "$pipe_works" = yes; then
+    break
+  else
+    lt_cv_sys_global_symbol_pipe=
+  fi
+done
+
+fi
+
+if test -z "$lt_cv_sys_global_symbol_pipe"; then
+  lt_cv_sys_global_symbol_to_cdecl=
+fi
+if test -z "$lt_cv_sys_global_symbol_pipe$lt_cv_sys_global_symbol_to_cdecl"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: failed" >&5
+$as_echo "failed" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: ok" >&5
+$as_echo "ok" >&6; }
+fi
+
+# Response file support.
+if test "$lt_cv_nm_interface" = "MS dumpbin"; then
+  nm_file_list_spec='@'
+elif $NM --help 2>/dev/null | grep '[@]FILE' >/dev/null; then
+  nm_file_list_spec='@'
+fi
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for sysroot" >&5
+$as_echo_n "checking for sysroot... " >&6; }
+
+# Check whether --with-sysroot was given.
+if test "${with_sysroot+set}" = set; then :
+  withval=$with_sysroot;
+else
+  with_sysroot=no
+fi
+
+
+lt_sysroot=
+case ${with_sysroot} in #(
+ yes)
+   if test "$GCC" = yes; then
+     lt_sysroot=`$CC --print-sysroot 2>/dev/null`
+   fi
+   ;; #(
+ /*)
+   lt_sysroot=`echo "$with_sysroot" | sed -e "$sed_quote_subst"`
+   ;; #(
+ no|'')
+   ;; #(
+ *)
+   { $as_echo "$as_me:${as_lineno-$LINENO}: result: ${with_sysroot}" >&5
+$as_echo "${with_sysroot}" >&6; }
+   as_fn_error $? "The sysroot must be an absolute path." "$LINENO" 5
+   ;;
+esac
+
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: ${lt_sysroot:-no}" >&5
+$as_echo "${lt_sysroot:-no}" >&6; }
+
+
+
+
+
+# Check whether --enable-libtool-lock was given.
+if test "${enable_libtool_lock+set}" = set; then :
+  enableval=$enable_libtool_lock;
+fi
+
+test "x$enable_libtool_lock" != xno && enable_libtool_lock=yes
+
+# Some flags need to be propagated to the compiler or linker for good
+# libtool support.
+case $host in
+ia64-*-hpux*)
+  # Find out which ABI we are using.
+  echo 'int i;' > conftest.$ac_ext
+  if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5
+  (eval $ac_compile) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+    case `/usr/bin/file conftest.$ac_objext` in
+      *ELF-32*)
+	HPUX_IA64_MODE="32"
+	;;
+      *ELF-64*)
+	HPUX_IA64_MODE="64"
+	;;
+    esac
+  fi
+  rm -rf conftest*
+  ;;
+*-*-irix6*)
+  # Find out which ABI we are using.
+  echo '#line '$LINENO' "configure"' > conftest.$ac_ext
+  if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5
+  (eval $ac_compile) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+    if test "$lt_cv_prog_gnu_ld" = yes; then
+      case `/usr/bin/file conftest.$ac_objext` in
+	*32-bit*)
+	  LD="${LD-ld} -melf32bsmip"
+	  ;;
+	*N32*)
+	  LD="${LD-ld} -melf32bmipn32"
+	  ;;
+	*64-bit*)
+	  LD="${LD-ld} -melf64bmip"
+	;;
+      esac
+    else
+      case `/usr/bin/file conftest.$ac_objext` in
+	*32-bit*)
+	  LD="${LD-ld} -32"
+	  ;;
+	*N32*)
+	  LD="${LD-ld} -n32"
+	  ;;
+	*64-bit*)
+	  LD="${LD-ld} -64"
+	  ;;
+      esac
+    fi
+  fi
+  rm -rf conftest*
+  ;;
+
+x86_64-*kfreebsd*-gnu|x86_64-*linux*|powerpc*-*linux*| \
+s390*-*linux*|s390*-*tpf*|sparc*-*linux*)
+  # Find out which ABI we are using.
+  echo 'int i;' > conftest.$ac_ext
+  if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5
+  (eval $ac_compile) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+    case `/usr/bin/file conftest.o` in
+      *32-bit*)
+	case $host in
+	  x86_64-*kfreebsd*-gnu)
+	    LD="${LD-ld} -m elf_i386_fbsd"
+	    ;;
+	  x86_64-*linux*)
+	    case `/usr/bin/file conftest.o` in
+	      *x86-64*)
+		LD="${LD-ld} -m elf32_x86_64"
+		;;
+	      *)
+		LD="${LD-ld} -m elf_i386"
+		;;
+	    esac
+	    ;;
+	  powerpc64le-*)
+	    LD="${LD-ld} -m elf32lppclinux"
+	    ;;
+	  powerpc64-*)
+	    LD="${LD-ld} -m elf32ppclinux"
+	    ;;
+	  s390x-*linux*)
+	    LD="${LD-ld} -m elf_s390"
+	    ;;
+	  sparc64-*linux*)
+	    LD="${LD-ld} -m elf32_sparc"
+	    ;;
+	esac
+	;;
+      *64-bit*)
+	case $host in
+	  x86_64-*kfreebsd*-gnu)
+	    LD="${LD-ld} -m elf_x86_64_fbsd"
+	    ;;
+	  x86_64-*linux*)
+	    LD="${LD-ld} -m elf_x86_64"
+	    ;;
+	  powerpcle-*)
+	    LD="${LD-ld} -m elf64lppc"
+	    ;;
+	  powerpc-*)
+	    LD="${LD-ld} -m elf64ppc"
+	    ;;
+	  s390*-*linux*|s390*-*tpf*)
+	    LD="${LD-ld} -m elf64_s390"
+	    ;;
+	  sparc*-*linux*)
+	    LD="${LD-ld} -m elf64_sparc"
+	    ;;
+	esac
+	;;
+    esac
+  fi
+  rm -rf conftest*
+  ;;
+
+*-*-sco3.2v5*)
+  # On SCO OpenServer 5, we need -belf to get full-featured binaries.
+  SAVE_CFLAGS="$CFLAGS"
+  CFLAGS="$CFLAGS -belf"
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the C compiler needs -belf" >&5
+$as_echo_n "checking whether the C compiler needs -belf... " >&6; }
+if ${lt_cv_cc_needs_belf+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+     cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  lt_cv_cc_needs_belf=yes
+else
+  lt_cv_cc_needs_belf=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+     ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_cc_needs_belf" >&5
+$as_echo "$lt_cv_cc_needs_belf" >&6; }
+  if test x"$lt_cv_cc_needs_belf" != x"yes"; then
+    # this is probably gcc 2.8.0, egcs 1.0 or newer; no need for -belf
+    CFLAGS="$SAVE_CFLAGS"
+  fi
+  ;;
+*-*solaris*)
+  # Find out which ABI we are using.
+  echo 'int i;' > conftest.$ac_ext
+  if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5
+  (eval $ac_compile) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+    case `/usr/bin/file conftest.o` in
+    *64-bit*)
+      case $lt_cv_prog_gnu_ld in
+      yes*)
+        case $host in
+        i?86-*-solaris*)
+          LD="${LD-ld} -m elf_x86_64"
+          ;;
+        sparc*-*-solaris*)
+          LD="${LD-ld} -m elf64_sparc"
+          ;;
+        esac
+        # GNU ld 2.21 introduced _sol2 emulations.  Use them if available.
+        if ${LD-ld} -V | grep _sol2 >/dev/null 2>&1; then
+          LD="${LD-ld}_sol2"
+        fi
+        ;;
+      *)
+	if ${LD-ld} -64 -r -o conftest2.o conftest.o >/dev/null 2>&1; then
+	  LD="${LD-ld} -64"
+	fi
+	;;
+      esac
+      ;;
+    esac
+  fi
+  rm -rf conftest*
+  ;;
+esac
+
+need_locks="$enable_libtool_lock"
+
+if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}mt", so it can be a program name with args.
+set dummy ${ac_tool_prefix}mt; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_MANIFEST_TOOL+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$MANIFEST_TOOL"; then
+  ac_cv_prog_MANIFEST_TOOL="$MANIFEST_TOOL" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_MANIFEST_TOOL="${ac_tool_prefix}mt"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+MANIFEST_TOOL=$ac_cv_prog_MANIFEST_TOOL
+if test -n "$MANIFEST_TOOL"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $MANIFEST_TOOL" >&5
+$as_echo "$MANIFEST_TOOL" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_prog_MANIFEST_TOOL"; then
+  ac_ct_MANIFEST_TOOL=$MANIFEST_TOOL
+  # Extract the first word of "mt", so it can be a program name with args.
+set dummy mt; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_ac_ct_MANIFEST_TOOL+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_MANIFEST_TOOL"; then
+  ac_cv_prog_ac_ct_MANIFEST_TOOL="$ac_ct_MANIFEST_TOOL" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_ac_ct_MANIFEST_TOOL="mt"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_MANIFEST_TOOL=$ac_cv_prog_ac_ct_MANIFEST_TOOL
+if test -n "$ac_ct_MANIFEST_TOOL"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_MANIFEST_TOOL" >&5
+$as_echo "$ac_ct_MANIFEST_TOOL" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_ct_MANIFEST_TOOL" = x; then
+    MANIFEST_TOOL=":"
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    MANIFEST_TOOL=$ac_ct_MANIFEST_TOOL
+  fi
+else
+  MANIFEST_TOOL="$ac_cv_prog_MANIFEST_TOOL"
+fi
+
+test -z "$MANIFEST_TOOL" && MANIFEST_TOOL=mt
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if $MANIFEST_TOOL is a manifest tool" >&5
+$as_echo_n "checking if $MANIFEST_TOOL is a manifest tool... " >&6; }
+if ${lt_cv_path_mainfest_tool+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  lt_cv_path_mainfest_tool=no
+  echo "$as_me:$LINENO: $MANIFEST_TOOL '-?'" >&5
+  $MANIFEST_TOOL '-?' 2>conftest.err > conftest.out
+  cat conftest.err >&5
+  if $GREP 'Manifest Tool' conftest.out > /dev/null; then
+    lt_cv_path_mainfest_tool=yes
+  fi
+  rm -f conftest*
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_path_mainfest_tool" >&5
+$as_echo "$lt_cv_path_mainfest_tool" >&6; }
+if test "x$lt_cv_path_mainfest_tool" != xyes; then
+  MANIFEST_TOOL=:
+fi
+
+
+
+
+
+
+  case $host_os in
+    rhapsody* | darwin*)
+    if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}dsymutil", so it can be a program name with args.
+set dummy ${ac_tool_prefix}dsymutil; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_DSYMUTIL+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$DSYMUTIL"; then
+  ac_cv_prog_DSYMUTIL="$DSYMUTIL" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_DSYMUTIL="${ac_tool_prefix}dsymutil"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+DSYMUTIL=$ac_cv_prog_DSYMUTIL
+if test -n "$DSYMUTIL"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DSYMUTIL" >&5
+$as_echo "$DSYMUTIL" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_prog_DSYMUTIL"; then
+  ac_ct_DSYMUTIL=$DSYMUTIL
+  # Extract the first word of "dsymutil", so it can be a program name with args.
+set dummy dsymutil; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_ac_ct_DSYMUTIL+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_DSYMUTIL"; then
+  ac_cv_prog_ac_ct_DSYMUTIL="$ac_ct_DSYMUTIL" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_ac_ct_DSYMUTIL="dsymutil"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_DSYMUTIL=$ac_cv_prog_ac_ct_DSYMUTIL
+if test -n "$ac_ct_DSYMUTIL"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_DSYMUTIL" >&5
+$as_echo "$ac_ct_DSYMUTIL" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_ct_DSYMUTIL" = x; then
+    DSYMUTIL=":"
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    DSYMUTIL=$ac_ct_DSYMUTIL
+  fi
+else
+  DSYMUTIL="$ac_cv_prog_DSYMUTIL"
+fi
+
+    if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}nmedit", so it can be a program name with args.
+set dummy ${ac_tool_prefix}nmedit; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_NMEDIT+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$NMEDIT"; then
+  ac_cv_prog_NMEDIT="$NMEDIT" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_NMEDIT="${ac_tool_prefix}nmedit"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+NMEDIT=$ac_cv_prog_NMEDIT
+if test -n "$NMEDIT"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $NMEDIT" >&5
+$as_echo "$NMEDIT" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_prog_NMEDIT"; then
+  ac_ct_NMEDIT=$NMEDIT
+  # Extract the first word of "nmedit", so it can be a program name with args.
+set dummy nmedit; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_ac_ct_NMEDIT+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_NMEDIT"; then
+  ac_cv_prog_ac_ct_NMEDIT="$ac_ct_NMEDIT" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_ac_ct_NMEDIT="nmedit"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_NMEDIT=$ac_cv_prog_ac_ct_NMEDIT
+if test -n "$ac_ct_NMEDIT"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_NMEDIT" >&5
+$as_echo "$ac_ct_NMEDIT" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_ct_NMEDIT" = x; then
+    NMEDIT=":"
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    NMEDIT=$ac_ct_NMEDIT
+  fi
+else
+  NMEDIT="$ac_cv_prog_NMEDIT"
+fi
+
+    if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}lipo", so it can be a program name with args.
+set dummy ${ac_tool_prefix}lipo; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_LIPO+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$LIPO"; then
+  ac_cv_prog_LIPO="$LIPO" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_LIPO="${ac_tool_prefix}lipo"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+LIPO=$ac_cv_prog_LIPO
+if test -n "$LIPO"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LIPO" >&5
+$as_echo "$LIPO" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_prog_LIPO"; then
+  ac_ct_LIPO=$LIPO
+  # Extract the first word of "lipo", so it can be a program name with args.
+set dummy lipo; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_ac_ct_LIPO+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_LIPO"; then
+  ac_cv_prog_ac_ct_LIPO="$ac_ct_LIPO" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_ac_ct_LIPO="lipo"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_LIPO=$ac_cv_prog_ac_ct_LIPO
+if test -n "$ac_ct_LIPO"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_LIPO" >&5
+$as_echo "$ac_ct_LIPO" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_ct_LIPO" = x; then
+    LIPO=":"
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    LIPO=$ac_ct_LIPO
+  fi
+else
+  LIPO="$ac_cv_prog_LIPO"
+fi
+
+    if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}otool", so it can be a program name with args.
+set dummy ${ac_tool_prefix}otool; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_OTOOL+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$OTOOL"; then
+  ac_cv_prog_OTOOL="$OTOOL" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_OTOOL="${ac_tool_prefix}otool"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+OTOOL=$ac_cv_prog_OTOOL
+if test -n "$OTOOL"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $OTOOL" >&5
+$as_echo "$OTOOL" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_prog_OTOOL"; then
+  ac_ct_OTOOL=$OTOOL
+  # Extract the first word of "otool", so it can be a program name with args.
+set dummy otool; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_ac_ct_OTOOL+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_OTOOL"; then
+  ac_cv_prog_ac_ct_OTOOL="$ac_ct_OTOOL" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_ac_ct_OTOOL="otool"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_OTOOL=$ac_cv_prog_ac_ct_OTOOL
+if test -n "$ac_ct_OTOOL"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OTOOL" >&5
+$as_echo "$ac_ct_OTOOL" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_ct_OTOOL" = x; then
+    OTOOL=":"
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    OTOOL=$ac_ct_OTOOL
+  fi
+else
+  OTOOL="$ac_cv_prog_OTOOL"
+fi
+
+    if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}otool64", so it can be a program name with args.
+set dummy ${ac_tool_prefix}otool64; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_OTOOL64+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$OTOOL64"; then
+  ac_cv_prog_OTOOL64="$OTOOL64" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_OTOOL64="${ac_tool_prefix}otool64"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+OTOOL64=$ac_cv_prog_OTOOL64
+if test -n "$OTOOL64"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $OTOOL64" >&5
+$as_echo "$OTOOL64" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_prog_OTOOL64"; then
+  ac_ct_OTOOL64=$OTOOL64
+  # Extract the first word of "otool64", so it can be a program name with args.
+set dummy otool64; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_ac_ct_OTOOL64+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_OTOOL64"; then
+  ac_cv_prog_ac_ct_OTOOL64="$ac_ct_OTOOL64" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_ac_ct_OTOOL64="otool64"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_OTOOL64=$ac_cv_prog_ac_ct_OTOOL64
+if test -n "$ac_ct_OTOOL64"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OTOOL64" >&5
+$as_echo "$ac_ct_OTOOL64" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_ct_OTOOL64" = x; then
+    OTOOL64=":"
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    OTOOL64=$ac_ct_OTOOL64
+  fi
+else
+  OTOOL64="$ac_cv_prog_OTOOL64"
+fi
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for -single_module linker flag" >&5
+$as_echo_n "checking for -single_module linker flag... " >&6; }
+if ${lt_cv_apple_cc_single_mod+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  lt_cv_apple_cc_single_mod=no
+      if test -z "${LT_MULTI_MODULE}"; then
+	# By default we will add the -single_module flag. You can override
+	# by either setting the environment variable LT_MULTI_MODULE
+	# non-empty at configure time, or by adding -multi_module to the
+	# link flags.
+	rm -rf libconftest.dylib*
+	echo "int foo(void){return 1;}" > conftest.c
+	echo "$LTCC $LTCFLAGS $LDFLAGS -o libconftest.dylib \
+-dynamiclib -Wl,-single_module conftest.c" >&5
+	$LTCC $LTCFLAGS $LDFLAGS -o libconftest.dylib \
+	  -dynamiclib -Wl,-single_module conftest.c 2>conftest.err
+        _lt_result=$?
+	# If there is a non-empty error log, and "single_module"
+	# appears in it, assume the flag caused a linker warning
+        if test -s conftest.err && $GREP single_module conftest.err; then
+	  cat conftest.err >&5
+	# Otherwise, if the output was created with a 0 exit code from
+	# the compiler, it worked.
+	elif test -f libconftest.dylib && test $_lt_result -eq 0; then
+	  lt_cv_apple_cc_single_mod=yes
+	else
+	  cat conftest.err >&5
+	fi
+	rm -rf libconftest.dylib*
+	rm -f conftest.*
+      fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_apple_cc_single_mod" >&5
+$as_echo "$lt_cv_apple_cc_single_mod" >&6; }
+
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for -exported_symbols_list linker flag" >&5
+$as_echo_n "checking for -exported_symbols_list linker flag... " >&6; }
+if ${lt_cv_ld_exported_symbols_list+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  lt_cv_ld_exported_symbols_list=no
+      save_LDFLAGS=$LDFLAGS
+      echo "_main" > conftest.sym
+      LDFLAGS="$LDFLAGS -Wl,-exported_symbols_list,conftest.sym"
+      cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  lt_cv_ld_exported_symbols_list=yes
+else
+  lt_cv_ld_exported_symbols_list=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+	LDFLAGS="$save_LDFLAGS"
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_ld_exported_symbols_list" >&5
+$as_echo "$lt_cv_ld_exported_symbols_list" >&6; }
+
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for -force_load linker flag" >&5
+$as_echo_n "checking for -force_load linker flag... " >&6; }
+if ${lt_cv_ld_force_load+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  lt_cv_ld_force_load=no
+      cat > conftest.c << _LT_EOF
+int forced_loaded() { return 2;}
+_LT_EOF
+      echo "$LTCC $LTCFLAGS -c -o conftest.o conftest.c" >&5
+      $LTCC $LTCFLAGS -c -o conftest.o conftest.c 2>&5
+      echo "$AR cru libconftest.a conftest.o" >&5
+      $AR cru libconftest.a conftest.o 2>&5
+      echo "$RANLIB libconftest.a" >&5
+      $RANLIB libconftest.a 2>&5
+      cat > conftest.c << _LT_EOF
+int main() { return 0;}
+_LT_EOF
+      echo "$LTCC $LTCFLAGS $LDFLAGS -o conftest conftest.c -Wl,-force_load,./libconftest.a" >&5
+      $LTCC $LTCFLAGS $LDFLAGS -o conftest conftest.c -Wl,-force_load,./libconftest.a 2>conftest.err
+      _lt_result=$?
+      if test -s conftest.err && $GREP force_load conftest.err; then
+	cat conftest.err >&5
+      elif test -f conftest && test $_lt_result -eq 0 && $GREP forced_load conftest >/dev/null 2>&1 ; then
+	lt_cv_ld_force_load=yes
+      else
+	cat conftest.err >&5
+      fi
+        rm -f conftest.err libconftest.a conftest conftest.c
+        rm -rf conftest.dSYM
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_ld_force_load" >&5
+$as_echo "$lt_cv_ld_force_load" >&6; }
+    case $host_os in
+    rhapsody* | darwin1.[012])
+      _lt_dar_allow_undefined='${wl}-undefined ${wl}suppress' ;;
+    darwin1.*)
+      _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' ;;
+    darwin*) # darwin 5.x on
+      # if running on 10.5 or later, the deployment target defaults
+      # to the OS version, if on x86, and 10.4, the deployment
+      # target defaults to 10.4. Don't you love it?
+      case ${MACOSX_DEPLOYMENT_TARGET-10.0},$host in
+	10.0,*86*-darwin8*|10.0,*-darwin[91]*)
+	  _lt_dar_allow_undefined='${wl}-undefined ${wl}dynamic_lookup' ;;
+	10.[012]*)
+	  _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' ;;
+	10.*)
+	  _lt_dar_allow_undefined='${wl}-undefined ${wl}dynamic_lookup' ;;
+      esac
+    ;;
+  esac
+    if test "$lt_cv_apple_cc_single_mod" = "yes"; then
+      _lt_dar_single_mod='$single_module'
+    fi
+    if test "$lt_cv_ld_exported_symbols_list" = "yes"; then
+      _lt_dar_export_syms=' ${wl}-exported_symbols_list,$output_objdir/${libname}-symbols.expsym'
+    else
+      _lt_dar_export_syms='~$NMEDIT -s $output_objdir/${libname}-symbols.expsym ${lib}'
+    fi
+    if test "$DSYMUTIL" != ":" && test "$lt_cv_ld_force_load" = "no"; then
+      _lt_dsymutil='~$DSYMUTIL $lib || :'
+    else
+      _lt_dsymutil=
+    fi
+    ;;
+  esac
+
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to run the C preprocessor" >&5
+$as_echo_n "checking how to run the C preprocessor... " >&6; }
+# On Suns, sometimes $CPP names a directory.
+if test -n "$CPP" && test -d "$CPP"; then
+  CPP=
+fi
+if test -z "$CPP"; then
+  if ${ac_cv_prog_CPP+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+      # Double quotes because CPP needs to be expanded
+    for CPP in "$CC -E" "$CC -E -traditional-cpp" "/lib/cpp"
+    do
+      ac_preproc_ok=false
+for ac_c_preproc_warn_flag in '' yes
+do
+  # Use a header file that comes with gcc, so configuring glibc
+  # with a fresh cross-compiler works.
+  # Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+  # <limits.h> exists even on freestanding compilers.
+  # On the NeXT, cc -E runs the code through the compiler's parser,
+  # not just through cpp. "Syntax error" is here to catch this case.
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+		     Syntax error
+_ACEOF
+if ac_fn_c_try_cpp "$LINENO"; then :
+
+else
+  # Broken: fails on valid input.
+continue
+fi
+rm -f conftest.err conftest.i conftest.$ac_ext
+
+  # OK, works on sane cases.  Now check whether nonexistent headers
+  # can be detected and how.
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <ac_nonexistent.h>
+_ACEOF
+if ac_fn_c_try_cpp "$LINENO"; then :
+  # Broken: success on invalid input.
+continue
+else
+  # Passes both tests.
+ac_preproc_ok=:
+break
+fi
+rm -f conftest.err conftest.i conftest.$ac_ext
+
+done
+# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped.
+rm -f conftest.i conftest.err conftest.$ac_ext
+if $ac_preproc_ok; then :
+  break
+fi
+
+    done
+    ac_cv_prog_CPP=$CPP
+
+fi
+  CPP=$ac_cv_prog_CPP
+else
+  ac_cv_prog_CPP=$CPP
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $CPP" >&5
+$as_echo "$CPP" >&6; }
+ac_preproc_ok=false
+for ac_c_preproc_warn_flag in '' yes
+do
+  # Use a header file that comes with gcc, so configuring glibc
+  # with a fresh cross-compiler works.
+  # Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+  # <limits.h> exists even on freestanding compilers.
+  # On the NeXT, cc -E runs the code through the compiler's parser,
+  # not just through cpp. "Syntax error" is here to catch this case.
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+		     Syntax error
+_ACEOF
+if ac_fn_c_try_cpp "$LINENO"; then :
+
+else
+  # Broken: fails on valid input.
+continue
+fi
+rm -f conftest.err conftest.i conftest.$ac_ext
+
+  # OK, works on sane cases.  Now check whether nonexistent headers
+  # can be detected and how.
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <ac_nonexistent.h>
+_ACEOF
+if ac_fn_c_try_cpp "$LINENO"; then :
+  # Broken: success on invalid input.
+continue
+else
+  # Passes both tests.
+ac_preproc_ok=:
+break
+fi
+rm -f conftest.err conftest.i conftest.$ac_ext
+
+done
+# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped.
+rm -f conftest.i conftest.err conftest.$ac_ext
+if $ac_preproc_ok; then :
+
+else
+  { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "C preprocessor \"$CPP\" fails sanity check
+See \`config.log' for more details" "$LINENO" 5; }
+fi
+
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ANSI C header files" >&5
+$as_echo_n "checking for ANSI C header files... " >&6; }
+if ${ac_cv_header_stdc+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+#include <float.h>
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_cv_header_stdc=yes
+else
+  ac_cv_header_stdc=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+
+if test $ac_cv_header_stdc = yes; then
+  # SunOS 4.x string.h does not declare mem*, contrary to ANSI.
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <string.h>
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  $EGREP "memchr" >/dev/null 2>&1; then :
+
+else
+  ac_cv_header_stdc=no
+fi
+rm -f conftest*
+
+fi
+
+if test $ac_cv_header_stdc = yes; then
+  # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI.
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <stdlib.h>
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  $EGREP "free" >/dev/null 2>&1; then :
+
+else
+  ac_cv_header_stdc=no
+fi
+rm -f conftest*
+
+fi
+
+if test $ac_cv_header_stdc = yes; then
+  # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi.
+  if test "$cross_compiling" = yes; then :
+  :
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <ctype.h>
+#include <stdlib.h>
+#if ((' ' & 0x0FF) == 0x020)
+# define ISLOWER(c) ('a' <= (c) && (c) <= 'z')
+# define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c))
+#else
+# define ISLOWER(c) \
+		   (('a' <= (c) && (c) <= 'i') \
+		     || ('j' <= (c) && (c) <= 'r') \
+		     || ('s' <= (c) && (c) <= 'z'))
+# define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c))
+#endif
+
+#define XOR(e, f) (((e) && !(f)) || (!(e) && (f)))
+int
+main ()
+{
+  int i;
+  for (i = 0; i < 256; i++)
+    if (XOR (islower (i), ISLOWER (i))
+	|| toupper (i) != TOUPPER (i))
+      return 2;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_run "$LINENO"; then :
+
+else
+  ac_cv_header_stdc=no
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
+  conftest.$ac_objext conftest.beam conftest.$ac_ext
+fi
+
+fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_stdc" >&5
+$as_echo "$ac_cv_header_stdc" >&6; }
+if test $ac_cv_header_stdc = yes; then
+
+$as_echo "#define STDC_HEADERS 1" >>confdefs.h
+
+fi
+
+# On IRIX 5.3, sys/types and inttypes.h are conflicting.
+for ac_header in sys/types.h sys/stat.h stdlib.h string.h memory.h strings.h \
+		  inttypes.h stdint.h unistd.h
+do :
+  as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
+ac_fn_c_check_header_compile "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default
+"
+if eval test \"x\$"$as_ac_Header"\" = x"yes"; then :
+  cat >>confdefs.h <<_ACEOF
+#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1
+_ACEOF
+
+fi
+
+done
+
+
+for ac_header in dlfcn.h
+do :
+  ac_fn_c_check_header_compile "$LINENO" "dlfcn.h" "ac_cv_header_dlfcn_h" "$ac_includes_default
+"
+if test "x$ac_cv_header_dlfcn_h" = xyes; then :
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_DLFCN_H 1
+_ACEOF
+
+fi
+
+done
+
+
+
+
+
+# Set options
+
+
+
+        enable_dlopen=no
+
+
+  enable_win32_dll=no
+
+
+            # Check whether --enable-shared was given.
+if test "${enable_shared+set}" = set; then :
+  enableval=$enable_shared; p=${PACKAGE-default}
+    case $enableval in
+    yes) enable_shared=yes ;;
+    no) enable_shared=no ;;
+    *)
+      enable_shared=no
+      # Look at the argument we got.  We use all the common list separators.
+      lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR,"
+      for pkg in $enableval; do
+	IFS="$lt_save_ifs"
+	if test "X$pkg" = "X$p"; then
+	  enable_shared=yes
+	fi
+      done
+      IFS="$lt_save_ifs"
+      ;;
+    esac
+else
+  enable_shared=yes
+fi
+
+
+
+
+
+
+
+
+
+
+
+# Check whether --with-pic was given.
+if test "${with_pic+set}" = set; then :
+  withval=$with_pic; lt_p=${PACKAGE-default}
+    case $withval in
+    yes|no) pic_mode=$withval ;;
+    *)
+      pic_mode=default
+      # Look at the argument we got.  We use all the common list separators.
+      lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR,"
+      for lt_pkg in $withval; do
+	IFS="$lt_save_ifs"
+	if test "X$lt_pkg" = "X$lt_p"; then
+	  pic_mode=yes
+	fi
+      done
+      IFS="$lt_save_ifs"
+      ;;
+    esac
+else
+  pic_mode=default
+fi
+
+
+test -z "$pic_mode" && pic_mode=default
+
+
+
+
+
+
+
+  # Check whether --enable-fast-install was given.
+if test "${enable_fast_install+set}" = set; then :
+  enableval=$enable_fast_install; p=${PACKAGE-default}
+    case $enableval in
+    yes) enable_fast_install=yes ;;
+    no) enable_fast_install=no ;;
+    *)
+      enable_fast_install=no
+      # Look at the argument we got.  We use all the common list separators.
+      lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR,"
+      for pkg in $enableval; do
+	IFS="$lt_save_ifs"
+	if test "X$pkg" = "X$p"; then
+	  enable_fast_install=yes
+	fi
+      done
+      IFS="$lt_save_ifs"
+      ;;
+    esac
+else
+  enable_fast_install=yes
+fi
+
+
+
+
+
+
+
+
+
+
+
+# This can be used to rebuild libtool when needed
+LIBTOOL_DEPS="$ltmain"
+
+# Always use our own libtool.
+LIBTOOL='$(SHELL) $(top_builddir)/libtool'
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+test -z "$LN_S" && LN_S="ln -s"
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+if test -n "${ZSH_VERSION+set}" ; then
+   setopt NO_GLOB_SUBST
+fi
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for objdir" >&5
+$as_echo_n "checking for objdir... " >&6; }
+if ${lt_cv_objdir+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  rm -f .libs 2>/dev/null
+mkdir .libs 2>/dev/null
+if test -d .libs; then
+  lt_cv_objdir=.libs
+else
+  # MS-DOS does not allow filenames that begin with a dot.
+  lt_cv_objdir=_libs
+fi
+rmdir .libs 2>/dev/null
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_objdir" >&5
+$as_echo "$lt_cv_objdir" >&6; }
+objdir=$lt_cv_objdir
+
+
+
+
+
+cat >>confdefs.h <<_ACEOF
+#define LT_OBJDIR "$lt_cv_objdir/"
+_ACEOF
+
+
+
+
+case $host_os in
+aix3*)
+  # AIX sometimes has problems with the GCC collect2 program.  For some
+  # reason, if we set the COLLECT_NAMES environment variable, the problems
+  # vanish in a puff of smoke.
+  if test "X${COLLECT_NAMES+set}" != Xset; then
+    COLLECT_NAMES=
+    export COLLECT_NAMES
+  fi
+  ;;
+esac
+
+# Global variables:
+ofile=libtool
+can_build_shared=yes
+
+# All known linkers require a `.a' archive for static linking (except MSVC,
+# which needs '.lib').
+libext=a
+
+with_gnu_ld="$lt_cv_prog_gnu_ld"
+
+old_CC="$CC"
+old_CFLAGS="$CFLAGS"
+
+# Set sane defaults for various variables
+test -z "$CC" && CC=cc
+test -z "$LTCC" && LTCC=$CC
+test -z "$LTCFLAGS" && LTCFLAGS=$CFLAGS
+test -z "$LD" && LD=ld
+test -z "$ac_objext" && ac_objext=o
+
+for cc_temp in $compiler""; do
+  case $cc_temp in
+    compile | *[\\/]compile | ccache | *[\\/]ccache ) ;;
+    distcc | *[\\/]distcc | purify | *[\\/]purify ) ;;
+    \-*) ;;
+    *) break;;
+  esac
+done
+cc_basename=`$ECHO "$cc_temp" | $SED "s%.*/%%; s%^$host_alias-%%"`
+
+
+# Only perform the check for file, if the check method requires it
+test -z "$MAGIC_CMD" && MAGIC_CMD=file
+case $deplibs_check_method in
+file_magic*)
+  if test "$file_magic_cmd" = '$MAGIC_CMD'; then
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ${ac_tool_prefix}file" >&5
+$as_echo_n "checking for ${ac_tool_prefix}file... " >&6; }
+if ${lt_cv_path_MAGIC_CMD+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $MAGIC_CMD in
+[\\/*] |  ?:[\\/]*)
+  lt_cv_path_MAGIC_CMD="$MAGIC_CMD" # Let the user override the test with a path.
+  ;;
+*)
+  lt_save_MAGIC_CMD="$MAGIC_CMD"
+  lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
+  ac_dummy="/usr/bin$PATH_SEPARATOR$PATH"
+  for ac_dir in $ac_dummy; do
+    IFS="$lt_save_ifs"
+    test -z "$ac_dir" && ac_dir=.
+    if test -f $ac_dir/${ac_tool_prefix}file; then
+      lt_cv_path_MAGIC_CMD="$ac_dir/${ac_tool_prefix}file"
+      if test -n "$file_magic_test_file"; then
+	case $deplibs_check_method in
+	"file_magic "*)
+	  file_magic_regex=`expr "$deplibs_check_method" : "file_magic \(.*\)"`
+	  MAGIC_CMD="$lt_cv_path_MAGIC_CMD"
+	  if eval $file_magic_cmd \$file_magic_test_file 2> /dev/null |
+	    $EGREP "$file_magic_regex" > /dev/null; then
+	    :
+	  else
+	    cat <<_LT_EOF 1>&2
+
+*** Warning: the command libtool uses to detect shared libraries,
+*** $file_magic_cmd, produces output that libtool cannot recognize.
+*** The result is that libtool may fail to recognize shared libraries
+*** as such.  This will affect the creation of libtool libraries that
+*** depend on shared libraries, but programs linked with such libtool
+*** libraries will work regardless of this problem.  Nevertheless, you
+*** may want to report the problem to your system manager and/or to
+*** bug-libtool@gnu.org
+
+_LT_EOF
+	  fi ;;
+	esac
+      fi
+      break
+    fi
+  done
+  IFS="$lt_save_ifs"
+  MAGIC_CMD="$lt_save_MAGIC_CMD"
+  ;;
+esac
+fi
+
+MAGIC_CMD="$lt_cv_path_MAGIC_CMD"
+if test -n "$MAGIC_CMD"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $MAGIC_CMD" >&5
+$as_echo "$MAGIC_CMD" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+
+
+
+if test -z "$lt_cv_path_MAGIC_CMD"; then
+  if test -n "$ac_tool_prefix"; then
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for file" >&5
+$as_echo_n "checking for file... " >&6; }
+if ${lt_cv_path_MAGIC_CMD+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $MAGIC_CMD in
+[\\/*] |  ?:[\\/]*)
+  lt_cv_path_MAGIC_CMD="$MAGIC_CMD" # Let the user override the test with a path.
+  ;;
+*)
+  lt_save_MAGIC_CMD="$MAGIC_CMD"
+  lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
+  ac_dummy="/usr/bin$PATH_SEPARATOR$PATH"
+  for ac_dir in $ac_dummy; do
+    IFS="$lt_save_ifs"
+    test -z "$ac_dir" && ac_dir=.
+    if test -f $ac_dir/file; then
+      lt_cv_path_MAGIC_CMD="$ac_dir/file"
+      if test -n "$file_magic_test_file"; then
+	case $deplibs_check_method in
+	"file_magic "*)
+	  file_magic_regex=`expr "$deplibs_check_method" : "file_magic \(.*\)"`
+	  MAGIC_CMD="$lt_cv_path_MAGIC_CMD"
+	  if eval $file_magic_cmd \$file_magic_test_file 2> /dev/null |
+	    $EGREP "$file_magic_regex" > /dev/null; then
+	    :
+	  else
+	    cat <<_LT_EOF 1>&2
+
+*** Warning: the command libtool uses to detect shared libraries,
+*** $file_magic_cmd, produces output that libtool cannot recognize.
+*** The result is that libtool may fail to recognize shared libraries
+*** as such.  This will affect the creation of libtool libraries that
+*** depend on shared libraries, but programs linked with such libtool
+*** libraries will work regardless of this problem.  Nevertheless, you
+*** may want to report the problem to your system manager and/or to
+*** bug-libtool@gnu.org
+
+_LT_EOF
+	  fi ;;
+	esac
+      fi
+      break
+    fi
+  done
+  IFS="$lt_save_ifs"
+  MAGIC_CMD="$lt_save_MAGIC_CMD"
+  ;;
+esac
+fi
+
+MAGIC_CMD="$lt_cv_path_MAGIC_CMD"
+if test -n "$MAGIC_CMD"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $MAGIC_CMD" >&5
+$as_echo "$MAGIC_CMD" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+  else
+    MAGIC_CMD=:
+  fi
+fi
+
+  fi
+  ;;
+esac
+
+# Use C for the default configuration in the libtool script
+
+lt_save_CC="$CC"
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+# Source file extension for C test sources.
+ac_ext=c
+
+# Object file extension for compiled C test sources.
+objext=o
+objext=$objext
+
+# Code to be used in simple compile tests
+lt_simple_compile_test_code="int some_variable = 0;"
+
+# Code to be used in simple link tests
+lt_simple_link_test_code='int main(){return(0);}'
+
+
+
+
+
+
+
+# If no C compiler was specified, use CC.
+LTCC=${LTCC-"$CC"}
+
+# If no C compiler flags were specified, use CFLAGS.
+LTCFLAGS=${LTCFLAGS-"$CFLAGS"}
+
+# Allow CC to be a program name with arguments.
+compiler=$CC
+
+# Save the default compiler, since it gets overwritten when the other
+# tags are being tested, and _LT_TAGVAR(compiler, []) is a NOP.
+compiler_DEFAULT=$CC
+
+# save warnings/boilerplate of simple test code
+ac_outfile=conftest.$ac_objext
+echo "$lt_simple_compile_test_code" >conftest.$ac_ext
+eval "$ac_compile" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err
+_lt_compiler_boilerplate=`cat conftest.err`
+$RM conftest*
+
+ac_outfile=conftest.$ac_objext
+echo "$lt_simple_link_test_code" >conftest.$ac_ext
+eval "$ac_link" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err
+_lt_linker_boilerplate=`cat conftest.err`
+$RM -r conftest*
+
+
+if test -n "$compiler"; then
+
+lt_prog_compiler_no_builtin_flag=
+
+if test "$GCC" = yes; then
+  case $cc_basename in
+  nvcc*)
+    lt_prog_compiler_no_builtin_flag=' -Xcompiler -fno-builtin' ;;
+  *)
+    lt_prog_compiler_no_builtin_flag=' -fno-builtin' ;;
+  esac
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -fno-rtti -fno-exceptions" >&5
+$as_echo_n "checking if $compiler supports -fno-rtti -fno-exceptions... " >&6; }
+if ${lt_cv_prog_compiler_rtti_exceptions+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  lt_cv_prog_compiler_rtti_exceptions=no
+   ac_outfile=conftest.$ac_objext
+   echo "$lt_simple_compile_test_code" > conftest.$ac_ext
+   lt_compiler_flag="-fno-rtti -fno-exceptions"
+   # Insert the option either (1) after the last *FLAGS variable, or
+   # (2) before a word containing "conftest.", or (3) at the end.
+   # Note that $ac_compile itself does not contain backslashes and begins
+   # with a dollar sign (not a hyphen), so the echo should work correctly.
+   # The option is referenced via a variable to avoid confusing sed.
+   lt_compile=`echo "$ac_compile" | $SED \
+   -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
+   -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
+   -e 's:$: $lt_compiler_flag:'`
+   (eval echo "\"\$as_me:$LINENO: $lt_compile\"" >&5)
+   (eval "$lt_compile" 2>conftest.err)
+   ac_status=$?
+   cat conftest.err >&5
+   echo "$as_me:$LINENO: \$? = $ac_status" >&5
+   if (exit $ac_status) && test -s "$ac_outfile"; then
+     # The compiler can only warn and ignore the option if not recognized
+     # So say no if there are warnings other than the usual output.
+     $ECHO "$_lt_compiler_boilerplate" | $SED '/^$/d' >conftest.exp
+     $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2
+     if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; then
+       lt_cv_prog_compiler_rtti_exceptions=yes
+     fi
+   fi
+   $RM conftest*
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_rtti_exceptions" >&5
+$as_echo "$lt_cv_prog_compiler_rtti_exceptions" >&6; }
+
+if test x"$lt_cv_prog_compiler_rtti_exceptions" = xyes; then
+    lt_prog_compiler_no_builtin_flag="$lt_prog_compiler_no_builtin_flag -fno-rtti -fno-exceptions"
+else
+    :
+fi
+
+fi
+
+
+
+
+
+
+  lt_prog_compiler_wl=
+lt_prog_compiler_pic=
+lt_prog_compiler_static=
+
+
+  if test "$GCC" = yes; then
+    lt_prog_compiler_wl='-Wl,'
+    lt_prog_compiler_static='-static'
+
+    case $host_os in
+      aix*)
+      # All AIX code is PIC.
+      if test "$host_cpu" = ia64; then
+	# AIX 5 now supports IA64 processor
+	lt_prog_compiler_static='-Bstatic'
+      fi
+      ;;
+
+    amigaos*)
+      case $host_cpu in
+      powerpc)
+            # see comment about AmigaOS4 .so support
+            lt_prog_compiler_pic='-fPIC'
+        ;;
+      m68k)
+            # FIXME: we need at least 68020 code to build shared libraries, but
+            # adding the `-m68020' flag to GCC prevents building anything better,
+            # like `-m68040'.
+            lt_prog_compiler_pic='-m68020 -resident32 -malways-restore-a4'
+        ;;
+      esac
+      ;;
+
+    beos* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*)
+      # PIC is the default for these OSes.
+      ;;
+
+    mingw* | cygwin* | pw32* | os2* | cegcc*)
+      # This hack is so that the source file can tell whether it is being
+      # built for inclusion in a dll (and should export symbols for example).
+      # Although the cygwin gcc ignores -fPIC, still need this for old-style
+      # (--disable-auto-import) libraries
+      lt_prog_compiler_pic='-DDLL_EXPORT'
+      ;;
+
+    darwin* | rhapsody*)
+      # PIC is the default on this platform
+      # Common symbols not allowed in MH_DYLIB files
+      lt_prog_compiler_pic='-fno-common'
+      ;;
+
+    haiku*)
+      # PIC is the default for Haiku.
+      # The "-static" flag exists, but is broken.
+      lt_prog_compiler_static=
+      ;;
+
+    hpux*)
+      # PIC is the default for 64-bit PA HP-UX, but not for 32-bit
+      # PA HP-UX.  On IA64 HP-UX, PIC is the default but the pic flag
+      # sets the default TLS model and affects inlining.
+      case $host_cpu in
+      hppa*64*)
+	# +Z the default
+	;;
+      *)
+	lt_prog_compiler_pic='-fPIC'
+	;;
+      esac
+      ;;
+
+    interix[3-9]*)
+      # Interix 3.x gcc -fpic/-fPIC options generate broken code.
+      # Instead, we relocate shared libraries at runtime.
+      ;;
+
+    msdosdjgpp*)
+      # Just because we use GCC doesn't mean we suddenly get shared libraries
+      # on systems that don't support them.
+      lt_prog_compiler_can_build_shared=no
+      enable_shared=no
+      ;;
+
+    *nto* | *qnx*)
+      # QNX uses GNU C++, but need to define -shared option too, otherwise
+      # it will coredump.
+      lt_prog_compiler_pic='-fPIC -shared'
+      ;;
+
+    sysv4*MP*)
+      if test -d /usr/nec; then
+	lt_prog_compiler_pic=-Kconform_pic
+      fi
+      ;;
+
+    *)
+      lt_prog_compiler_pic='-fPIC'
+      ;;
+    esac
+
+    case $cc_basename in
+    nvcc*) # Cuda Compiler Driver 2.2
+      lt_prog_compiler_wl='-Xlinker '
+      if test -n "$lt_prog_compiler_pic"; then
+        lt_prog_compiler_pic="-Xcompiler $lt_prog_compiler_pic"
+      fi
+      ;;
+    esac
+  else
+    # PORTME Check for flag to pass linker flags through the system compiler.
+    case $host_os in
+    aix*)
+      lt_prog_compiler_wl='-Wl,'
+      if test "$host_cpu" = ia64; then
+	# AIX 5 now supports IA64 processor
+	lt_prog_compiler_static='-Bstatic'
+      else
+	lt_prog_compiler_static='-bnso -bI:/lib/syscalls.exp'
+      fi
+      ;;
+
+    mingw* | cygwin* | pw32* | os2* | cegcc*)
+      # This hack is so that the source file can tell whether it is being
+      # built for inclusion in a dll (and should export symbols for example).
+      lt_prog_compiler_pic='-DDLL_EXPORT'
+      ;;
+
+    hpux9* | hpux10* | hpux11*)
+      lt_prog_compiler_wl='-Wl,'
+      # PIC is the default for IA64 HP-UX and 64-bit HP-UX, but
+      # not for PA HP-UX.
+      case $host_cpu in
+      hppa*64*|ia64*)
+	# +Z the default
+	;;
+      *)
+	lt_prog_compiler_pic='+Z'
+	;;
+      esac
+      # Is there a better lt_prog_compiler_static that works with the bundled CC?
+      lt_prog_compiler_static='${wl}-a ${wl}archive'
+      ;;
+
+    irix5* | irix6* | nonstopux*)
+      lt_prog_compiler_wl='-Wl,'
+      # PIC (with -KPIC) is the default.
+      lt_prog_compiler_static='-non_shared'
+      ;;
+
+    linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*)
+      case $cc_basename in
+      # old Intel for x86_64 which still supported -KPIC.
+      ecc*)
+	lt_prog_compiler_wl='-Wl,'
+	lt_prog_compiler_pic='-KPIC'
+	lt_prog_compiler_static='-static'
+        ;;
+      # icc used to be incompatible with GCC.
+      # ICC 10 doesn't accept -KPIC any more.
+      icc* | ifort*)
+	lt_prog_compiler_wl='-Wl,'
+	lt_prog_compiler_pic='-fPIC'
+	lt_prog_compiler_static='-static'
+        ;;
+      # Lahey Fortran 8.1.
+      lf95*)
+	lt_prog_compiler_wl='-Wl,'
+	lt_prog_compiler_pic='--shared'
+	lt_prog_compiler_static='--static'
+	;;
+      nagfor*)
+	# NAG Fortran compiler
+	lt_prog_compiler_wl='-Wl,-Wl,,'
+	lt_prog_compiler_pic='-PIC'
+	lt_prog_compiler_static='-Bstatic'
+	;;
+      pgcc* | pgf77* | pgf90* | pgf95* | pgfortran*)
+        # Portland Group compilers (*not* the Pentium gcc compiler,
+	# which looks to be a dead project)
+	lt_prog_compiler_wl='-Wl,'
+	lt_prog_compiler_pic='-fpic'
+	lt_prog_compiler_static='-Bstatic'
+        ;;
+      ccc*)
+        lt_prog_compiler_wl='-Wl,'
+        # All Alpha code is PIC.
+        lt_prog_compiler_static='-non_shared'
+        ;;
+      xl* | bgxl* | bgf* | mpixl*)
+	# IBM XL C 8.0/Fortran 10.1, 11.1 on PPC and BlueGene
+	lt_prog_compiler_wl='-Wl,'
+	lt_prog_compiler_pic='-qpic'
+	lt_prog_compiler_static='-qstaticlink'
+	;;
+      *)
+	case `$CC -V 2>&1 | sed 5q` in
+	*Sun\ Ceres\ Fortran* | *Sun*Fortran*\ [1-7].* | *Sun*Fortran*\ 8.[0-3]*)
+	  # Sun Fortran 8.3 passes all unrecognized flags to the linker
+	  lt_prog_compiler_pic='-KPIC'
+	  lt_prog_compiler_static='-Bstatic'
+	  lt_prog_compiler_wl=''
+	  ;;
+	*Sun\ F* | *Sun*Fortran*)
+	  lt_prog_compiler_pic='-KPIC'
+	  lt_prog_compiler_static='-Bstatic'
+	  lt_prog_compiler_wl='-Qoption ld '
+	  ;;
+	*Sun\ C*)
+	  # Sun C 5.9
+	  lt_prog_compiler_pic='-KPIC'
+	  lt_prog_compiler_static='-Bstatic'
+	  lt_prog_compiler_wl='-Wl,'
+	  ;;
+        *Intel*\ [CF]*Compiler*)
+	  lt_prog_compiler_wl='-Wl,'
+	  lt_prog_compiler_pic='-fPIC'
+	  lt_prog_compiler_static='-static'
+	  ;;
+	*Portland\ Group*)
+	  lt_prog_compiler_wl='-Wl,'
+	  lt_prog_compiler_pic='-fpic'
+	  lt_prog_compiler_static='-Bstatic'
+	  ;;
+	esac
+	;;
+      esac
+      ;;
+
+    newsos6)
+      lt_prog_compiler_pic='-KPIC'
+      lt_prog_compiler_static='-Bstatic'
+      ;;
+
+    *nto* | *qnx*)
+      # QNX uses GNU C++, but need to define -shared option too, otherwise
+      # it will coredump.
+      lt_prog_compiler_pic='-fPIC -shared'
+      ;;
+
+    osf3* | osf4* | osf5*)
+      lt_prog_compiler_wl='-Wl,'
+      # All OSF/1 code is PIC.
+      lt_prog_compiler_static='-non_shared'
+      ;;
+
+    rdos*)
+      lt_prog_compiler_static='-non_shared'
+      ;;
+
+    solaris*)
+      lt_prog_compiler_pic='-KPIC'
+      lt_prog_compiler_static='-Bstatic'
+      case $cc_basename in
+      f77* | f90* | f95* | sunf77* | sunf90* | sunf95*)
+	lt_prog_compiler_wl='-Qoption ld ';;
+      *)
+	lt_prog_compiler_wl='-Wl,';;
+      esac
+      ;;
+
+    sunos4*)
+      lt_prog_compiler_wl='-Qoption ld '
+      lt_prog_compiler_pic='-PIC'
+      lt_prog_compiler_static='-Bstatic'
+      ;;
+
+    sysv4 | sysv4.2uw2* | sysv4.3*)
+      lt_prog_compiler_wl='-Wl,'
+      lt_prog_compiler_pic='-KPIC'
+      lt_prog_compiler_static='-Bstatic'
+      ;;
+
+    sysv4*MP*)
+      if test -d /usr/nec ;then
+	lt_prog_compiler_pic='-Kconform_pic'
+	lt_prog_compiler_static='-Bstatic'
+      fi
+      ;;
+
+    sysv5* | unixware* | sco3.2v5* | sco5v6* | OpenUNIX*)
+      lt_prog_compiler_wl='-Wl,'
+      lt_prog_compiler_pic='-KPIC'
+      lt_prog_compiler_static='-Bstatic'
+      ;;
+
+    unicos*)
+      lt_prog_compiler_wl='-Wl,'
+      lt_prog_compiler_can_build_shared=no
+      ;;
+
+    uts4*)
+      lt_prog_compiler_pic='-pic'
+      lt_prog_compiler_static='-Bstatic'
+      ;;
+
+    *)
+      lt_prog_compiler_can_build_shared=no
+      ;;
+    esac
+  fi
+
+case $host_os in
+  # For platforms which do not support PIC, -DPIC is meaningless:
+  *djgpp*)
+    lt_prog_compiler_pic=
+    ;;
+  *)
+    lt_prog_compiler_pic="$lt_prog_compiler_pic -DPIC"
+    ;;
+esac
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $compiler option to produce PIC" >&5
+$as_echo_n "checking for $compiler option to produce PIC... " >&6; }
+if ${lt_cv_prog_compiler_pic+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  lt_cv_prog_compiler_pic=$lt_prog_compiler_pic
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_pic" >&5
+$as_echo "$lt_cv_prog_compiler_pic" >&6; }
+lt_prog_compiler_pic=$lt_cv_prog_compiler_pic
+
+#
+# Check to make sure the PIC flag actually works.
+#
+if test -n "$lt_prog_compiler_pic"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler PIC flag $lt_prog_compiler_pic works" >&5
+$as_echo_n "checking if $compiler PIC flag $lt_prog_compiler_pic works... " >&6; }
+if ${lt_cv_prog_compiler_pic_works+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  lt_cv_prog_compiler_pic_works=no
+   ac_outfile=conftest.$ac_objext
+   echo "$lt_simple_compile_test_code" > conftest.$ac_ext
+   lt_compiler_flag="$lt_prog_compiler_pic -DPIC"
+   # Insert the option either (1) after the last *FLAGS variable, or
+   # (2) before a word containing "conftest.", or (3) at the end.
+   # Note that $ac_compile itself does not contain backslashes and begins
+   # with a dollar sign (not a hyphen), so the echo should work correctly.
+   # The option is referenced via a variable to avoid confusing sed.
+   lt_compile=`echo "$ac_compile" | $SED \
+   -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
+   -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
+   -e 's:$: $lt_compiler_flag:'`
+   (eval echo "\"\$as_me:$LINENO: $lt_compile\"" >&5)
+   (eval "$lt_compile" 2>conftest.err)
+   ac_status=$?
+   cat conftest.err >&5
+   echo "$as_me:$LINENO: \$? = $ac_status" >&5
+   if (exit $ac_status) && test -s "$ac_outfile"; then
+     # The compiler can only warn and ignore the option if not recognized
+     # So say no if there are warnings other than the usual output.
+     $ECHO "$_lt_compiler_boilerplate" | $SED '/^$/d' >conftest.exp
+     $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2
+     if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; then
+       lt_cv_prog_compiler_pic_works=yes
+     fi
+   fi
+   $RM conftest*
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_pic_works" >&5
+$as_echo "$lt_cv_prog_compiler_pic_works" >&6; }
+
+if test x"$lt_cv_prog_compiler_pic_works" = xyes; then
+    case $lt_prog_compiler_pic in
+     "" | " "*) ;;
+     *) lt_prog_compiler_pic=" $lt_prog_compiler_pic" ;;
+     esac
+else
+    lt_prog_compiler_pic=
+     lt_prog_compiler_can_build_shared=no
+fi
+
+fi
+
+
+
+
+
+
+
+
+
+
+
+#
+# Check to make sure the static flag actually works.
+#
+wl=$lt_prog_compiler_wl eval lt_tmp_static_flag=\"$lt_prog_compiler_static\"
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler static flag $lt_tmp_static_flag works" >&5
+$as_echo_n "checking if $compiler static flag $lt_tmp_static_flag works... " >&6; }
+if ${lt_cv_prog_compiler_static_works+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  lt_cv_prog_compiler_static_works=no
+   save_LDFLAGS="$LDFLAGS"
+   LDFLAGS="$LDFLAGS $lt_tmp_static_flag"
+   echo "$lt_simple_link_test_code" > conftest.$ac_ext
+   if (eval $ac_link 2>conftest.err) && test -s conftest$ac_exeext; then
+     # The linker can only warn and ignore the option if not recognized
+     # So say no if there are warnings
+     if test -s conftest.err; then
+       # Append any errors to the config.log.
+       cat conftest.err 1>&5
+       $ECHO "$_lt_linker_boilerplate" | $SED '/^$/d' > conftest.exp
+       $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2
+       if diff conftest.exp conftest.er2 >/dev/null; then
+         lt_cv_prog_compiler_static_works=yes
+       fi
+     else
+       lt_cv_prog_compiler_static_works=yes
+     fi
+   fi
+   $RM -r conftest*
+   LDFLAGS="$save_LDFLAGS"
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_static_works" >&5
+$as_echo "$lt_cv_prog_compiler_static_works" >&6; }
+
+if test x"$lt_cv_prog_compiler_static_works" = xyes; then
+    :
+else
+    lt_prog_compiler_static=
+fi
+
+
+
+
+
+
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -c -o file.$ac_objext" >&5
+$as_echo_n "checking if $compiler supports -c -o file.$ac_objext... " >&6; }
+if ${lt_cv_prog_compiler_c_o+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  lt_cv_prog_compiler_c_o=no
+   $RM -r conftest 2>/dev/null
+   mkdir conftest
+   cd conftest
+   mkdir out
+   echo "$lt_simple_compile_test_code" > conftest.$ac_ext
+
+   lt_compiler_flag="-o out/conftest2.$ac_objext"
+   # Insert the option either (1) after the last *FLAGS variable, or
+   # (2) before a word containing "conftest.", or (3) at the end.
+   # Note that $ac_compile itself does not contain backslashes and begins
+   # with a dollar sign (not a hyphen), so the echo should work correctly.
+   lt_compile=`echo "$ac_compile" | $SED \
+   -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
+   -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
+   -e 's:$: $lt_compiler_flag:'`
+   (eval echo "\"\$as_me:$LINENO: $lt_compile\"" >&5)
+   (eval "$lt_compile" 2>out/conftest.err)
+   ac_status=$?
+   cat out/conftest.err >&5
+   echo "$as_me:$LINENO: \$? = $ac_status" >&5
+   if (exit $ac_status) && test -s out/conftest2.$ac_objext
+   then
+     # The compiler can only warn and ignore the option if not recognized
+     # So say no if there are warnings
+     $ECHO "$_lt_compiler_boilerplate" | $SED '/^$/d' > out/conftest.exp
+     $SED '/^$/d; /^ *+/d' out/conftest.err >out/conftest.er2
+     if test ! -s out/conftest.er2 || diff out/conftest.exp out/conftest.er2 >/dev/null; then
+       lt_cv_prog_compiler_c_o=yes
+     fi
+   fi
+   chmod u+w . 2>&5
+   $RM conftest*
+   # SGI C++ compiler will create directory out/ii_files/ for
+   # template instantiation
+   test -d out/ii_files && $RM out/ii_files/* && rmdir out/ii_files
+   $RM out/* && rmdir out
+   cd ..
+   $RM -r conftest
+   $RM conftest*
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_c_o" >&5
+$as_echo "$lt_cv_prog_compiler_c_o" >&6; }
+
+
+
+
+
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -c -o file.$ac_objext" >&5
+$as_echo_n "checking if $compiler supports -c -o file.$ac_objext... " >&6; }
+if ${lt_cv_prog_compiler_c_o+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  lt_cv_prog_compiler_c_o=no
+   $RM -r conftest 2>/dev/null
+   mkdir conftest
+   cd conftest
+   mkdir out
+   echo "$lt_simple_compile_test_code" > conftest.$ac_ext
+
+   lt_compiler_flag="-o out/conftest2.$ac_objext"
+   # Insert the option either (1) after the last *FLAGS variable, or
+   # (2) before a word containing "conftest.", or (3) at the end.
+   # Note that $ac_compile itself does not contain backslashes and begins
+   # with a dollar sign (not a hyphen), so the echo should work correctly.
+   lt_compile=`echo "$ac_compile" | $SED \
+   -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
+   -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
+   -e 's:$: $lt_compiler_flag:'`
+   (eval echo "\"\$as_me:$LINENO: $lt_compile\"" >&5)
+   (eval "$lt_compile" 2>out/conftest.err)
+   ac_status=$?
+   cat out/conftest.err >&5
+   echo "$as_me:$LINENO: \$? = $ac_status" >&5
+   if (exit $ac_status) && test -s out/conftest2.$ac_objext
+   then
+     # The compiler can only warn and ignore the option if not recognized
+     # So say no if there are warnings
+     $ECHO "$_lt_compiler_boilerplate" | $SED '/^$/d' > out/conftest.exp
+     $SED '/^$/d; /^ *+/d' out/conftest.err >out/conftest.er2
+     if test ! -s out/conftest.er2 || diff out/conftest.exp out/conftest.er2 >/dev/null; then
+       lt_cv_prog_compiler_c_o=yes
+     fi
+   fi
+   chmod u+w . 2>&5
+   $RM conftest*
+   # SGI C++ compiler will create directory out/ii_files/ for
+   # template instantiation
+   test -d out/ii_files && $RM out/ii_files/* && rmdir out/ii_files
+   $RM out/* && rmdir out
+   cd ..
+   $RM -r conftest
+   $RM conftest*
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_c_o" >&5
+$as_echo "$lt_cv_prog_compiler_c_o" >&6; }
+
+
+
+
+hard_links="nottested"
+if test "$lt_cv_prog_compiler_c_o" = no && test "$need_locks" != no; then
+  # do not overwrite the value of need_locks provided by the user
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking if we can lock with hard links" >&5
+$as_echo_n "checking if we can lock with hard links... " >&6; }
+  hard_links=yes
+  $RM conftest*
+  ln conftest.a conftest.b 2>/dev/null && hard_links=no
+  touch conftest.a
+  ln conftest.a conftest.b 2>&5 || hard_links=no
+  ln conftest.a conftest.b 2>/dev/null && hard_links=no
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $hard_links" >&5
+$as_echo "$hard_links" >&6; }
+  if test "$hard_links" = no; then
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: \`$CC' does not support \`-c -o', so \`make -j' may be unsafe" >&5
+$as_echo "$as_me: WARNING: \`$CC' does not support \`-c -o', so \`make -j' may be unsafe" >&2;}
+    need_locks=warn
+  fi
+else
+  need_locks=no
+fi
+
+
+
+
+
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the $compiler linker ($LD) supports shared libraries" >&5
+$as_echo_n "checking whether the $compiler linker ($LD) supports shared libraries... " >&6; }
+
+  runpath_var=
+  allow_undefined_flag=
+  always_export_symbols=no
+  archive_cmds=
+  archive_expsym_cmds=
+  compiler_needs_object=no
+  enable_shared_with_static_runtimes=no
+  export_dynamic_flag_spec=
+  export_symbols_cmds='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols'
+  hardcode_automatic=no
+  hardcode_direct=no
+  hardcode_direct_absolute=no
+  hardcode_libdir_flag_spec=
+  hardcode_libdir_separator=
+  hardcode_minus_L=no
+  hardcode_shlibpath_var=unsupported
+  inherit_rpath=no
+  link_all_deplibs=unknown
+  module_cmds=
+  module_expsym_cmds=
+  old_archive_from_new_cmds=
+  old_archive_from_expsyms_cmds=
+  thread_safe_flag_spec=
+  whole_archive_flag_spec=
+  # include_expsyms should be a list of space-separated symbols to be *always*
+  # included in the symbol list
+  include_expsyms=
+  # exclude_expsyms can be an extended regexp of symbols to exclude
+  # it will be wrapped by ` (' and `)$', so one must not match beginning or
+  # end of line.  Example: `a|bc|.*d.*' will exclude the symbols `a' and `bc',
+  # as well as any symbol that contains `d'.
+  exclude_expsyms='_GLOBAL_OFFSET_TABLE_|_GLOBAL__F[ID]_.*'
+  # Although _GLOBAL_OFFSET_TABLE_ is a valid symbol C name, most a.out
+  # platforms (ab)use it in PIC code, but their linkers get confused if
+  # the symbol is explicitly referenced.  Since portable code cannot
+  # rely on this symbol name, it's probably fine to never include it in
+  # preloaded symbol tables.
+  # Exclude shared library initialization/finalization symbols.
+  extract_expsyms_cmds=
+
+  case $host_os in
+  cygwin* | mingw* | pw32* | cegcc*)
+    # FIXME: the MSVC++ port hasn't been tested in a loooong time
+    # When not using gcc, we currently assume that we are using
+    # Microsoft Visual C++.
+    if test "$GCC" != yes; then
+      with_gnu_ld=no
+    fi
+    ;;
+  interix*)
+    # we just hope/assume this is gcc and not c89 (= MSVC++)
+    with_gnu_ld=yes
+    ;;
+  openbsd*)
+    with_gnu_ld=no
+    ;;
+  linux* | k*bsd*-gnu | gnu*)
+    link_all_deplibs=no
+    ;;
+  esac
+
+  ld_shlibs=yes
+
+  # On some targets, GNU ld is compatible enough with the native linker
+  # that we're better off using the native interface for both.
+  lt_use_gnu_ld_interface=no
+  if test "$with_gnu_ld" = yes; then
+    case $host_os in
+      aix*)
+	# The AIX port of GNU ld has always aspired to compatibility
+	# with the native linker.  However, as the warning in the GNU ld
+	# block says, versions before 2.19.5* couldn't really create working
+	# shared libraries, regardless of the interface used.
+	case `$LD -v 2>&1` in
+	  *\ \(GNU\ Binutils\)\ 2.19.5*) ;;
+	  *\ \(GNU\ Binutils\)\ 2.[2-9]*) ;;
+	  *\ \(GNU\ Binutils\)\ [3-9]*) ;;
+	  *)
+	    lt_use_gnu_ld_interface=yes
+	    ;;
+	esac
+	;;
+      *)
+	lt_use_gnu_ld_interface=yes
+	;;
+    esac
+  fi
+
+  if test "$lt_use_gnu_ld_interface" = yes; then
+    # If archive_cmds runs LD, not CC, wlarc should be empty
+    wlarc='${wl}'
+
+    # Set some defaults for GNU ld with shared library support. These
+    # are reset later if shared libraries are not supported. Putting them
+    # here allows them to be overridden if necessary.
+    runpath_var=LD_RUN_PATH
+    hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
+    export_dynamic_flag_spec='${wl}--export-dynamic'
+    # ancient GNU ld didn't support --whole-archive et. al.
+    if $LD --help 2>&1 | $GREP 'no-whole-archive' > /dev/null; then
+      whole_archive_flag_spec="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive'
+    else
+      whole_archive_flag_spec=
+    fi
+    supports_anon_versioning=no
+    case `$LD -v 2>&1` in
+      *GNU\ gold*) supports_anon_versioning=yes ;;
+      *\ [01].* | *\ 2.[0-9].* | *\ 2.10.*) ;; # catch versions < 2.11
+      *\ 2.11.93.0.2\ *) supports_anon_versioning=yes ;; # RH7.3 ...
+      *\ 2.11.92.0.12\ *) supports_anon_versioning=yes ;; # Mandrake 8.2 ...
+      *\ 2.11.*) ;; # other 2.11 versions
+      *) supports_anon_versioning=yes ;;
+    esac
+
+    # See if GNU ld supports shared libraries.
+    case $host_os in
+    aix[3-9]*)
+      # On AIX/PPC, the GNU linker is very broken
+      if test "$host_cpu" != ia64; then
+	ld_shlibs=no
+	cat <<_LT_EOF 1>&2
+
+*** Warning: the GNU linker, at least up to release 2.19, is reported
+*** to be unable to reliably create shared libraries on AIX.
+*** Therefore, libtool is disabling shared libraries support.  If you
+*** really care for shared libraries, you may want to install binutils
+*** 2.20 or above, or modify your PATH so that a non-GNU linker is found.
+*** You will then need to restart the configuration process.
+
+_LT_EOF
+      fi
+      ;;
+
+    amigaos*)
+      case $host_cpu in
+      powerpc)
+            # see comment about AmigaOS4 .so support
+            archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+            archive_expsym_cmds=''
+        ;;
+      m68k)
+            archive_cmds='$RM $output_objdir/a2ixlibrary.data~$ECHO "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$ECHO "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$ECHO "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$ECHO "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)'
+            hardcode_libdir_flag_spec='-L$libdir'
+            hardcode_minus_L=yes
+        ;;
+      esac
+      ;;
+
+    beos*)
+      if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then
+	allow_undefined_flag=unsupported
+	# Joseph Beckenbach <jrb3@best.com> says some releases of gcc
+	# support --undefined.  This deserves some investigation.  FIXME
+	archive_cmds='$CC -nostart $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+      else
+	ld_shlibs=no
+      fi
+      ;;
+
+    cygwin* | mingw* | pw32* | cegcc*)
+      # _LT_TAGVAR(hardcode_libdir_flag_spec, ) is actually meaningless,
+      # as there is no search path for DLLs.
+      hardcode_libdir_flag_spec='-L$libdir'
+      export_dynamic_flag_spec='${wl}--export-all-symbols'
+      allow_undefined_flag=unsupported
+      always_export_symbols=no
+      enable_shared_with_static_runtimes=yes
+      export_symbols_cmds='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[BCDGRS][ ]/s/.*[ ]\([^ ]*\)/\1 DATA/;s/^.*[ ]__nm__\([^ ]*\)[ ][^ ]*/\1 DATA/;/^I[ ]/d;/^[AITW][ ]/s/.* //'\'' | sort | uniq > $export_symbols'
+      exclude_expsyms='[_]+GLOBAL_OFFSET_TABLE_|[_]+GLOBAL__[FID]_.*|[_]+head_[A-Za-z0-9_]+_dll|[A-Za-z0-9_]+_dll_iname'
+
+      if $LD --help 2>&1 | $GREP 'auto-import' > /dev/null; then
+        archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib'
+	# If the export-symbols file already is a .def file (1st line
+	# is EXPORTS), use it as is; otherwise, prepend...
+	archive_expsym_cmds='if test "x`$SED 1q $export_symbols`" = xEXPORTS; then
+	  cp $export_symbols $output_objdir/$soname.def;
+	else
+	  echo EXPORTS > $output_objdir/$soname.def;
+	  cat $export_symbols >> $output_objdir/$soname.def;
+	fi~
+	$CC -shared $output_objdir/$soname.def $libobjs $deplibs $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib'
+      else
+	ld_shlibs=no
+      fi
+      ;;
+
+    haiku*)
+      archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+      link_all_deplibs=yes
+      ;;
+
+    interix[3-9]*)
+      hardcode_direct=no
+      hardcode_shlibpath_var=no
+      hardcode_libdir_flag_spec='${wl}-rpath,$libdir'
+      export_dynamic_flag_spec='${wl}-E'
+      # Hack: On Interix 3.x, we cannot compile PIC because of a broken gcc.
+      # Instead, shared libraries are loaded at an image base (0x10000000 by
+      # default) and relocated if they conflict, which is a slow very memory
+      # consuming and fragmenting process.  To avoid this, we pick a random,
+      # 256 KiB-aligned image base between 0x50000000 and 0x6FFC0000 at link
+      # time.  Moving up from 0x10000000 also allows more sbrk(2) space.
+      archive_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib'
+      archive_expsym_cmds='sed "s,^,_," $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--retain-symbols-file,$output_objdir/$soname.expsym ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib'
+      ;;
+
+    gnu* | linux* | tpf* | k*bsd*-gnu | kopensolaris*-gnu)
+      tmp_diet=no
+      if test "$host_os" = linux-dietlibc; then
+	case $cc_basename in
+	  diet\ *) tmp_diet=yes;;	# linux-dietlibc with static linking (!diet-dyn)
+	esac
+      fi
+      if $LD --help 2>&1 | $EGREP ': supported targets:.* elf' > /dev/null \
+	 && test "$tmp_diet" = no
+      then
+	tmp_addflag=' $pic_flag'
+	tmp_sharedflag='-shared'
+	case $cc_basename,$host_cpu in
+        pgcc*)				# Portland Group C compiler
+	  whole_archive_flag_spec='${wl}--whole-archive`for conv in $convenience\"\"; do test  -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` ${wl}--no-whole-archive'
+	  tmp_addflag=' $pic_flag'
+	  ;;
+	pgf77* | pgf90* | pgf95* | pgfortran*)
+					# Portland Group f77 and f90 compilers
+	  whole_archive_flag_spec='${wl}--whole-archive`for conv in $convenience\"\"; do test  -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` ${wl}--no-whole-archive'
+	  tmp_addflag=' $pic_flag -Mnomain' ;;
+	ecc*,ia64* | icc*,ia64*)	# Intel C compiler on ia64
+	  tmp_addflag=' -i_dynamic' ;;
+	efc*,ia64* | ifort*,ia64*)	# Intel Fortran compiler on ia64
+	  tmp_addflag=' -i_dynamic -nofor_main' ;;
+	ifc* | ifort*)			# Intel Fortran compiler
+	  tmp_addflag=' -nofor_main' ;;
+	lf95*)				# Lahey Fortran 8.1
+	  whole_archive_flag_spec=
+	  tmp_sharedflag='--shared' ;;
+	xl[cC]* | bgxl[cC]* | mpixl[cC]*) # IBM XL C 8.0 on PPC (deal with xlf below)
+	  tmp_sharedflag='-qmkshrobj'
+	  tmp_addflag= ;;
+	nvcc*)	# Cuda Compiler Driver 2.2
+	  whole_archive_flag_spec='${wl}--whole-archive`for conv in $convenience\"\"; do test  -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` ${wl}--no-whole-archive'
+	  compiler_needs_object=yes
+	  ;;
+	esac
+	case `$CC -V 2>&1 | sed 5q` in
+	*Sun\ C*)			# Sun C 5.9
+	  whole_archive_flag_spec='${wl}--whole-archive`new_convenience=; for conv in $convenience\"\"; do test -z \"$conv\" || new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` ${wl}--no-whole-archive'
+	  compiler_needs_object=yes
+	  tmp_sharedflag='-G' ;;
+	*Sun\ F*)			# Sun Fortran 8.3
+	  tmp_sharedflag='-G' ;;
+	esac
+	archive_cmds='$CC '"$tmp_sharedflag""$tmp_addflag"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+
+        if test "x$supports_anon_versioning" = xyes; then
+          archive_expsym_cmds='echo "{ global:" > $output_objdir/$libname.ver~
+	    cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~
+	    echo "local: *; };" >> $output_objdir/$libname.ver~
+	    $CC '"$tmp_sharedflag""$tmp_addflag"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-version-script ${wl}$output_objdir/$libname.ver -o $lib'
+        fi
+
+	case $cc_basename in
+	xlf* | bgf* | bgxlf* | mpixlf*)
+	  # IBM XL Fortran 10.1 on PPC cannot create shared libs itself
+	  whole_archive_flag_spec='--whole-archive$convenience --no-whole-archive'
+	  hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
+	  archive_cmds='$LD -shared $libobjs $deplibs $linker_flags -soname $soname -o $lib'
+	  if test "x$supports_anon_versioning" = xyes; then
+	    archive_expsym_cmds='echo "{ global:" > $output_objdir/$libname.ver~
+	      cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~
+	      echo "local: *; };" >> $output_objdir/$libname.ver~
+	      $LD -shared $libobjs $deplibs $linker_flags -soname $soname -version-script $output_objdir/$libname.ver -o $lib'
+	  fi
+	  ;;
+	esac
+      else
+        ld_shlibs=no
+      fi
+      ;;
+
+    netbsd* | netbsdelf*-gnu)
+      if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then
+	archive_cmds='$LD -Bshareable $libobjs $deplibs $linker_flags -o $lib'
+	wlarc=
+      else
+	archive_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+	archive_expsym_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
+      fi
+      ;;
+
+    solaris*)
+      if $LD -v 2>&1 | $GREP 'BFD 2\.8' > /dev/null; then
+	ld_shlibs=no
+	cat <<_LT_EOF 1>&2
+
+*** Warning: The releases 2.8.* of the GNU linker cannot reliably
+*** create shared libraries on Solaris systems.  Therefore, libtool
+*** is disabling shared libraries support.  We urge you to upgrade GNU
+*** binutils to release 2.9.1 or newer.  Another option is to modify
+*** your PATH or compiler configuration so that the native linker is
+*** used, and then restart.
+
+_LT_EOF
+      elif $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then
+	archive_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+	archive_expsym_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
+      else
+	ld_shlibs=no
+      fi
+      ;;
+
+    sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX*)
+      case `$LD -v 2>&1` in
+        *\ [01].* | *\ 2.[0-9].* | *\ 2.1[0-5].*)
+	ld_shlibs=no
+	cat <<_LT_EOF 1>&2
+
+*** Warning: Releases of the GNU linker prior to 2.16.91.0.3 can not
+*** reliably create shared libraries on SCO systems.  Therefore, libtool
+*** is disabling shared libraries support.  We urge you to upgrade GNU
+*** binutils to release 2.16.91.0.3 or newer.  Another option is to modify
+*** your PATH or compiler configuration so that the native linker is
+*** used, and then restart.
+
+_LT_EOF
+	;;
+	*)
+	  # For security reasons, it is highly recommended that you always
+	  # use absolute paths for naming shared libraries, and exclude the
+	  # DT_RUNPATH tag from executables and libraries.  But doing so
+	  # requires that you compile everything twice, which is a pain.
+	  if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then
+	    hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
+	    archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+	    archive_expsym_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
+	  else
+	    ld_shlibs=no
+	  fi
+	;;
+      esac
+      ;;
+
+    sunos4*)
+      archive_cmds='$LD -assert pure-text -Bshareable -o $lib $libobjs $deplibs $linker_flags'
+      wlarc=
+      hardcode_direct=yes
+      hardcode_shlibpath_var=no
+      ;;
+
+    *)
+      if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then
+	archive_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+	archive_expsym_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
+      else
+	ld_shlibs=no
+      fi
+      ;;
+    esac
+
+    if test "$ld_shlibs" = no; then
+      runpath_var=
+      hardcode_libdir_flag_spec=
+      export_dynamic_flag_spec=
+      whole_archive_flag_spec=
+    fi
+  else
+    # PORTME fill in a description of your system's linker (not GNU ld)
+    case $host_os in
+    aix3*)
+      allow_undefined_flag=unsupported
+      always_export_symbols=yes
+      archive_expsym_cmds='$LD -o $output_objdir/$soname $libobjs $deplibs $linker_flags -bE:$export_symbols -T512 -H512 -bM:SRE~$AR $AR_FLAGS $lib $output_objdir/$soname'
+      # Note: this linker hardcodes the directories in LIBPATH if there
+      # are no directories specified by -L.
+      hardcode_minus_L=yes
+      if test "$GCC" = yes && test -z "$lt_prog_compiler_static"; then
+	# Neither direct hardcoding nor static linking is supported with a
+	# broken collect2.
+	hardcode_direct=unsupported
+      fi
+      ;;
+
+    aix[4-9]*)
+      if test "$host_cpu" = ia64; then
+	# On IA64, the linker does run time linking by default, so we don't
+	# have to do anything special.
+	aix_use_runtimelinking=no
+	exp_sym_flag='-Bexport'
+	no_entry_flag=""
+      else
+	# If we're using GNU nm, then we don't want the "-C" option.
+	# -C means demangle to AIX nm, but means don't demangle with GNU nm
+	# Also, AIX nm treats weak defined symbols like other global
+	# defined symbols, whereas GNU nm marks them as "W".
+	if $NM -V 2>&1 | $GREP 'GNU' > /dev/null; then
+	  export_symbols_cmds='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B") || (\$ 2 == "W")) && (substr(\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols'
+	else
+	  export_symbols_cmds='$NM -BCpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B")) && (substr(\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols'
+	fi
+	aix_use_runtimelinking=no
+
+	# Test if we are trying to use run time linking or normal
+	# AIX style linking. If -brtl is somewhere in LDFLAGS, we
+	# need to do runtime linking.
+	case $host_os in aix4.[23]|aix4.[23].*|aix[5-9]*)
+	  for ld_flag in $LDFLAGS; do
+	  if (test $ld_flag = "-brtl" || test $ld_flag = "-Wl,-brtl"); then
+	    aix_use_runtimelinking=yes
+	    break
+	  fi
+	  done
+	  ;;
+	esac
+
+	exp_sym_flag='-bexport'
+	no_entry_flag='-bnoentry'
+      fi
+
+      # When large executables or shared objects are built, AIX ld can
+      # have problems creating the table of contents.  If linking a library
+      # or program results in "error TOC overflow" add -mminimal-toc to
+      # CXXFLAGS/CFLAGS for g++/gcc.  In the cases where that is not
+      # enough to fix the problem, add -Wl,-bbigtoc to LDFLAGS.
+
+      archive_cmds=''
+      hardcode_direct=yes
+      hardcode_direct_absolute=yes
+      hardcode_libdir_separator=':'
+      link_all_deplibs=yes
+      file_list_spec='${wl}-f,'
+
+      if test "$GCC" = yes; then
+	case $host_os in aix4.[012]|aix4.[012].*)
+	# We only want to do this on AIX 4.2 and lower, the check
+	# below for broken collect2 doesn't work under 4.3+
+	  collect2name=`${CC} -print-prog-name=collect2`
+	  if test -f "$collect2name" &&
+	   strings "$collect2name" | $GREP resolve_lib_name >/dev/null
+	  then
+	  # We have reworked collect2
+	  :
+	  else
+	  # We have old collect2
+	  hardcode_direct=unsupported
+	  # It fails to find uninstalled libraries when the uninstalled
+	  # path is not listed in the libpath.  Setting hardcode_minus_L
+	  # to unsupported forces relinking
+	  hardcode_minus_L=yes
+	  hardcode_libdir_flag_spec='-L$libdir'
+	  hardcode_libdir_separator=
+	  fi
+	  ;;
+	esac
+	shared_flag='-shared'
+	if test "$aix_use_runtimelinking" = yes; then
+	  shared_flag="$shared_flag "'${wl}-G'
+	fi
+	link_all_deplibs=no
+      else
+	# not using gcc
+	if test "$host_cpu" = ia64; then
+	# VisualAge C++, Version 5.5 for AIX 5L for IA-64, Beta 3 Release
+	# chokes on -Wl,-G. The following line is correct:
+	  shared_flag='-G'
+	else
+	  if test "$aix_use_runtimelinking" = yes; then
+	    shared_flag='${wl}-G'
+	  else
+	    shared_flag='${wl}-bM:SRE'
+	  fi
+	fi
+      fi
+
+      export_dynamic_flag_spec='${wl}-bexpall'
+      # It seems that -bexpall does not export symbols beginning with
+      # underscore (_), so it is better to generate a list of symbols to export.
+      always_export_symbols=yes
+      if test "$aix_use_runtimelinking" = yes; then
+	# Warning - without using the other runtime loading flags (-brtl),
+	# -berok will link without error, but may produce a broken library.
+	allow_undefined_flag='-berok'
+        # Determine the default libpath from the value encoded in an
+        # empty executable.
+        if test "${lt_cv_aix_libpath+set}" = set; then
+  aix_libpath=$lt_cv_aix_libpath
+else
+  if ${lt_cv_aix_libpath_+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+
+  lt_aix_libpath_sed='
+      /Import File Strings/,/^$/ {
+	  /^0/ {
+	      s/^0  *\([^ ]*\) *$/\1/
+	      p
+	  }
+      }'
+  lt_cv_aix_libpath_=`dump -H conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"`
+  # Check for a 64-bit object if we didn't find anything.
+  if test -z "$lt_cv_aix_libpath_"; then
+    lt_cv_aix_libpath_=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"`
+  fi
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+  if test -z "$lt_cv_aix_libpath_"; then
+    lt_cv_aix_libpath_="/usr/lib:/lib"
+  fi
+
+fi
+
+  aix_libpath=$lt_cv_aix_libpath_
+fi
+
+        hardcode_libdir_flag_spec='${wl}-blibpath:$libdir:'"$aix_libpath"
+        archive_expsym_cmds='$CC -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags `if test "x${allow_undefined_flag}" != "x"; then func_echo_all "${wl}${allow_undefined_flag}"; else :; fi` '"\${wl}$exp_sym_flag:\$export_symbols $shared_flag"
+      else
+	if test "$host_cpu" = ia64; then
+	  hardcode_libdir_flag_spec='${wl}-R $libdir:/usr/lib:/lib'
+	  allow_undefined_flag="-z nodefs"
+	  archive_expsym_cmds="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags ${wl}${allow_undefined_flag} '"\${wl}$exp_sym_flag:\$export_symbols"
+	else
+	 # Determine the default libpath from the value encoded in an
+	 # empty executable.
+	 if test "${lt_cv_aix_libpath+set}" = set; then
+  aix_libpath=$lt_cv_aix_libpath
+else
+  if ${lt_cv_aix_libpath_+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+
+  lt_aix_libpath_sed='
+      /Import File Strings/,/^$/ {
+	  /^0/ {
+	      s/^0  *\([^ ]*\) *$/\1/
+	      p
+	  }
+      }'
+  lt_cv_aix_libpath_=`dump -H conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"`
+  # Check for a 64-bit object if we didn't find anything.
+  if test -z "$lt_cv_aix_libpath_"; then
+    lt_cv_aix_libpath_=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"`
+  fi
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+  if test -z "$lt_cv_aix_libpath_"; then
+    lt_cv_aix_libpath_="/usr/lib:/lib"
+  fi
+
+fi
+
+  aix_libpath=$lt_cv_aix_libpath_
+fi
+
+	 hardcode_libdir_flag_spec='${wl}-blibpath:$libdir:'"$aix_libpath"
+	  # Warning - without using the other run time loading flags,
+	  # -berok will link without error, but may produce a broken library.
+	  no_undefined_flag=' ${wl}-bernotok'
+	  allow_undefined_flag=' ${wl}-berok'
+	  if test "$with_gnu_ld" = yes; then
+	    # We only use this code for GNU lds that support --whole-archive.
+	    whole_archive_flag_spec='${wl}--whole-archive$convenience ${wl}--no-whole-archive'
+	  else
+	    # Exported symbols can be pulled into shared objects from archives
+	    whole_archive_flag_spec='$convenience'
+	  fi
+	  archive_cmds_need_lc=yes
+	  # This is similar to how AIX traditionally builds its shared libraries.
+	  archive_expsym_cmds="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs ${wl}-bnoentry $compiler_flags ${wl}-bE:$export_symbols${allow_undefined_flag}~$AR $AR_FLAGS $output_objdir/$libname$release.a $output_objdir/$soname'
+	fi
+      fi
+      ;;
+
+    amigaos*)
+      case $host_cpu in
+      powerpc)
+            # see comment about AmigaOS4 .so support
+            archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+            archive_expsym_cmds=''
+        ;;
+      m68k)
+            archive_cmds='$RM $output_objdir/a2ixlibrary.data~$ECHO "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$ECHO "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$ECHO "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$ECHO "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)'
+            hardcode_libdir_flag_spec='-L$libdir'
+            hardcode_minus_L=yes
+        ;;
+      esac
+      ;;
+
+    bsdi[45]*)
+      export_dynamic_flag_spec=-rdynamic
+      ;;
+
+    cygwin* | mingw* | pw32* | cegcc*)
+      # When not using gcc, we currently assume that we are using
+      # Microsoft Visual C++.
+      # hardcode_libdir_flag_spec is actually meaningless, as there is
+      # no search path for DLLs.
+      case $cc_basename in
+      cl*)
+	# Native MSVC
+	hardcode_libdir_flag_spec=' '
+	allow_undefined_flag=unsupported
+	always_export_symbols=yes
+	file_list_spec='@'
+	# Tell ltmain to make .lib files, not .a files.
+	libext=lib
+	# Tell ltmain to make .dll files, not .so files.
+	shrext_cmds=".dll"
+	# FIXME: Setting linknames here is a bad hack.
+	archive_cmds='$CC -o $output_objdir/$soname $libobjs $compiler_flags $deplibs -Wl,-dll~linknames='
+	archive_expsym_cmds='if test "x`$SED 1q $export_symbols`" = xEXPORTS; then
+	    sed -n -e 's/\\\\\\\(.*\\\\\\\)/-link\\\ -EXPORT:\\\\\\\1/' -e '1\\\!p' < $export_symbols > $output_objdir/$soname.exp;
+	  else
+	    sed -e 's/\\\\\\\(.*\\\\\\\)/-link\\\ -EXPORT:\\\\\\\1/' < $export_symbols > $output_objdir/$soname.exp;
+	  fi~
+	  $CC -o $tool_output_objdir$soname $libobjs $compiler_flags $deplibs "@$tool_output_objdir$soname.exp" -Wl,-DLL,-IMPLIB:"$tool_output_objdir$libname.dll.lib"~
+	  linknames='
+	# The linker will not automatically build a static lib if we build a DLL.
+	# _LT_TAGVAR(old_archive_from_new_cmds, )='true'
+	enable_shared_with_static_runtimes=yes
+	exclude_expsyms='_NULL_IMPORT_DESCRIPTOR|_IMPORT_DESCRIPTOR_.*'
+	export_symbols_cmds='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[BCDGRS][ ]/s/.*[ ]\([^ ]*\)/\1,DATA/'\'' | $SED -e '\''/^[AITW][ ]/s/.*[ ]//'\'' | sort | uniq > $export_symbols'
+	# Don't use ranlib
+	old_postinstall_cmds='chmod 644 $oldlib'
+	postlink_cmds='lt_outputfile="@OUTPUT@"~
+	  lt_tool_outputfile="@TOOL_OUTPUT@"~
+	  case $lt_outputfile in
+	    *.exe|*.EXE) ;;
+	    *)
+	      lt_outputfile="$lt_outputfile.exe"
+	      lt_tool_outputfile="$lt_tool_outputfile.exe"
+	      ;;
+	  esac~
+	  if test "$MANIFEST_TOOL" != ":" && test -f "$lt_outputfile.manifest"; then
+	    $MANIFEST_TOOL -manifest "$lt_tool_outputfile.manifest" -outputresource:"$lt_tool_outputfile" || exit 1;
+	    $RM "$lt_outputfile.manifest";
+	  fi'
+	;;
+      *)
+	# Assume MSVC wrapper
+	hardcode_libdir_flag_spec=' '
+	allow_undefined_flag=unsupported
+	# Tell ltmain to make .lib files, not .a files.
+	libext=lib
+	# Tell ltmain to make .dll files, not .so files.
+	shrext_cmds=".dll"
+	# FIXME: Setting linknames here is a bad hack.
+	archive_cmds='$CC -o $lib $libobjs $compiler_flags `func_echo_all "$deplibs" | $SED '\''s/ -lc$//'\''` -link -dll~linknames='
+	# The linker will automatically build a .lib file if we build a DLL.
+	old_archive_from_new_cmds='true'
+	# FIXME: Should let the user specify the lib program.
+	old_archive_cmds='lib -OUT:$oldlib$oldobjs$old_deplibs'
+	enable_shared_with_static_runtimes=yes
+	;;
+      esac
+      ;;
+
+    darwin* | rhapsody*)
+
+
+  archive_cmds_need_lc=no
+  hardcode_direct=no
+  hardcode_automatic=yes
+  hardcode_shlibpath_var=unsupported
+  if test "$lt_cv_ld_force_load" = "yes"; then
+    whole_archive_flag_spec='`for conv in $convenience\"\"; do test  -n \"$conv\" && new_convenience=\"$new_convenience ${wl}-force_load,$conv\"; done; func_echo_all \"$new_convenience\"`'
+
+  else
+    whole_archive_flag_spec=''
+  fi
+  link_all_deplibs=yes
+  allow_undefined_flag="$_lt_dar_allow_undefined"
+  case $cc_basename in
+     ifort*) _lt_dar_can_shared=yes ;;
+     *) _lt_dar_can_shared=$GCC ;;
+  esac
+  if test "$_lt_dar_can_shared" = "yes"; then
+    output_verbose_link_cmd=func_echo_all
+    archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}"
+    module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}"
+    archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}"
+    module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}"
+
+  else
+  ld_shlibs=no
+  fi
+
+      ;;
+
+    dgux*)
+      archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+      hardcode_libdir_flag_spec='-L$libdir'
+      hardcode_shlibpath_var=no
+      ;;
+
+    # FreeBSD 2.2.[012] allows us to include c++rt0.o to get C++ constructor
+    # support.  Future versions do this automatically, but an explicit c++rt0.o
+    # does not break anything, and helps significantly (at the cost of a little
+    # extra space).
+    freebsd2.2*)
+      archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags /usr/lib/c++rt0.o'
+      hardcode_libdir_flag_spec='-R$libdir'
+      hardcode_direct=yes
+      hardcode_shlibpath_var=no
+      ;;
+
+    # Unfortunately, older versions of FreeBSD 2 do not have this feature.
+    freebsd2.*)
+      archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags'
+      hardcode_direct=yes
+      hardcode_minus_L=yes
+      hardcode_shlibpath_var=no
+      ;;
+
+    # FreeBSD 3 and greater uses gcc -shared to do shared libraries.
+    freebsd* | dragonfly*)
+      archive_cmds='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags'
+      hardcode_libdir_flag_spec='-R$libdir'
+      hardcode_direct=yes
+      hardcode_shlibpath_var=no
+      ;;
+
+    hpux9*)
+      if test "$GCC" = yes; then
+	archive_cmds='$RM $output_objdir/$soname~$CC -shared $pic_flag ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $libobjs $deplibs $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib'
+      else
+	archive_cmds='$RM $output_objdir/$soname~$LD -b +b $install_libdir -o $output_objdir/$soname $libobjs $deplibs $linker_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib'
+      fi
+      hardcode_libdir_flag_spec='${wl}+b ${wl}$libdir'
+      hardcode_libdir_separator=:
+      hardcode_direct=yes
+
+      # hardcode_minus_L: Not really in the search PATH,
+      # but as the default location of the library.
+      hardcode_minus_L=yes
+      export_dynamic_flag_spec='${wl}-E'
+      ;;
+
+    hpux10*)
+      if test "$GCC" = yes && test "$with_gnu_ld" = no; then
+	archive_cmds='$CC -shared $pic_flag ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags'
+      else
+	archive_cmds='$LD -b +h $soname +b $install_libdir -o $lib $libobjs $deplibs $linker_flags'
+      fi
+      if test "$with_gnu_ld" = no; then
+	hardcode_libdir_flag_spec='${wl}+b ${wl}$libdir'
+	hardcode_libdir_separator=:
+	hardcode_direct=yes
+	hardcode_direct_absolute=yes
+	export_dynamic_flag_spec='${wl}-E'
+	# hardcode_minus_L: Not really in the search PATH,
+	# but as the default location of the library.
+	hardcode_minus_L=yes
+      fi
+      ;;
+
+    hpux11*)
+      if test "$GCC" = yes && test "$with_gnu_ld" = no; then
+	case $host_cpu in
+	hppa*64*)
+	  archive_cmds='$CC -shared ${wl}+h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags'
+	  ;;
+	ia64*)
+	  archive_cmds='$CC -shared $pic_flag ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags'
+	  ;;
+	*)
+	  archive_cmds='$CC -shared $pic_flag ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags'
+	  ;;
+	esac
+      else
+	case $host_cpu in
+	hppa*64*)
+	  archive_cmds='$CC -b ${wl}+h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags'
+	  ;;
+	ia64*)
+	  archive_cmds='$CC -b ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags'
+	  ;;
+	*)
+
+	  # Older versions of the 11.00 compiler do not understand -b yet
+	  # (HP92453-01 A.11.01.20 doesn't, HP92453-01 B.11.X.35175-35176.GP does)
+	  { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC understands -b" >&5
+$as_echo_n "checking if $CC understands -b... " >&6; }
+if ${lt_cv_prog_compiler__b+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  lt_cv_prog_compiler__b=no
+   save_LDFLAGS="$LDFLAGS"
+   LDFLAGS="$LDFLAGS -b"
+   echo "$lt_simple_link_test_code" > conftest.$ac_ext
+   if (eval $ac_link 2>conftest.err) && test -s conftest$ac_exeext; then
+     # The linker can only warn and ignore the option if not recognized
+     # So say no if there are warnings
+     if test -s conftest.err; then
+       # Append any errors to the config.log.
+       cat conftest.err 1>&5
+       $ECHO "$_lt_linker_boilerplate" | $SED '/^$/d' > conftest.exp
+       $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2
+       if diff conftest.exp conftest.er2 >/dev/null; then
+         lt_cv_prog_compiler__b=yes
+       fi
+     else
+       lt_cv_prog_compiler__b=yes
+     fi
+   fi
+   $RM -r conftest*
+   LDFLAGS="$save_LDFLAGS"
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler__b" >&5
+$as_echo "$lt_cv_prog_compiler__b" >&6; }
+
+if test x"$lt_cv_prog_compiler__b" = xyes; then
+    archive_cmds='$CC -b ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags'
+else
+    archive_cmds='$LD -b +h $soname +b $install_libdir -o $lib $libobjs $deplibs $linker_flags'
+fi
+
+	  ;;
+	esac
+      fi
+      if test "$with_gnu_ld" = no; then
+	hardcode_libdir_flag_spec='${wl}+b ${wl}$libdir'
+	hardcode_libdir_separator=:
+
+	case $host_cpu in
+	hppa*64*|ia64*)
+	  hardcode_direct=no
+	  hardcode_shlibpath_var=no
+	  ;;
+	*)
+	  hardcode_direct=yes
+	  hardcode_direct_absolute=yes
+	  export_dynamic_flag_spec='${wl}-E'
+
+	  # hardcode_minus_L: Not really in the search PATH,
+	  # but as the default location of the library.
+	  hardcode_minus_L=yes
+	  ;;
+	esac
+      fi
+      ;;
+
+    irix5* | irix6* | nonstopux*)
+      if test "$GCC" = yes; then
+	archive_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && func_echo_all "${wl}-set_version ${wl}$verstring"` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
+	# Try to use the -exported_symbol ld option, if it does not
+	# work, assume that -exports_file does not work either and
+	# implicitly export all symbols.
+	# This should be the same for all languages, so no per-tag cache variable.
+	{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the $host_os linker accepts -exported_symbol" >&5
+$as_echo_n "checking whether the $host_os linker accepts -exported_symbol... " >&6; }
+if ${lt_cv_irix_exported_symbol+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  save_LDFLAGS="$LDFLAGS"
+	   LDFLAGS="$LDFLAGS -shared ${wl}-exported_symbol ${wl}foo ${wl}-update_registry ${wl}/dev/null"
+	   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int foo (void) { return 0; }
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  lt_cv_irix_exported_symbol=yes
+else
+  lt_cv_irix_exported_symbol=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+           LDFLAGS="$save_LDFLAGS"
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_irix_exported_symbol" >&5
+$as_echo "$lt_cv_irix_exported_symbol" >&6; }
+	if test "$lt_cv_irix_exported_symbol" = yes; then
+          archive_expsym_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && func_echo_all "${wl}-set_version ${wl}$verstring"` ${wl}-update_registry ${wl}${output_objdir}/so_locations ${wl}-exports_file ${wl}$export_symbols -o $lib'
+	fi
+      else
+	archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry ${output_objdir}/so_locations -o $lib'
+	archive_expsym_cmds='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry ${output_objdir}/so_locations -exports_file $export_symbols -o $lib'
+      fi
+      archive_cmds_need_lc='no'
+      hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
+      hardcode_libdir_separator=:
+      inherit_rpath=yes
+      link_all_deplibs=yes
+      ;;
+
+    netbsd* | netbsdelf*-gnu)
+      if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then
+	archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags'  # a.out
+      else
+	archive_cmds='$LD -shared -o $lib $libobjs $deplibs $linker_flags'      # ELF
+      fi
+      hardcode_libdir_flag_spec='-R$libdir'
+      hardcode_direct=yes
+      hardcode_shlibpath_var=no
+      ;;
+
+    newsos6)
+      archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+      hardcode_direct=yes
+      hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
+      hardcode_libdir_separator=:
+      hardcode_shlibpath_var=no
+      ;;
+
+    *nto* | *qnx*)
+      ;;
+
+    openbsd*)
+      if test -f /usr/libexec/ld.so; then
+	hardcode_direct=yes
+	hardcode_shlibpath_var=no
+	hardcode_direct_absolute=yes
+	if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then
+	  archive_cmds='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags'
+	  archive_expsym_cmds='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags ${wl}-retain-symbols-file,$export_symbols'
+	  hardcode_libdir_flag_spec='${wl}-rpath,$libdir'
+	  export_dynamic_flag_spec='${wl}-E'
+	else
+	  case $host_os in
+	   openbsd[01].* | openbsd2.[0-7] | openbsd2.[0-7].*)
+	     archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags'
+	     hardcode_libdir_flag_spec='-R$libdir'
+	     ;;
+	   *)
+	     archive_cmds='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags'
+	     hardcode_libdir_flag_spec='${wl}-rpath,$libdir'
+	     ;;
+	  esac
+	fi
+      else
+	ld_shlibs=no
+      fi
+      ;;
+
+    os2*)
+      hardcode_libdir_flag_spec='-L$libdir'
+      hardcode_minus_L=yes
+      allow_undefined_flag=unsupported
+      archive_cmds='$ECHO "LIBRARY $libname INITINSTANCE" > $output_objdir/$libname.def~$ECHO "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~echo DATA >> $output_objdir/$libname.def~echo " SINGLE NONSHARED" >> $output_objdir/$libname.def~echo EXPORTS >> $output_objdir/$libname.def~emxexp $libobjs >> $output_objdir/$libname.def~$CC -Zdll -Zcrtdll -o $lib $libobjs $deplibs $compiler_flags $output_objdir/$libname.def'
+      old_archive_from_new_cmds='emximp -o $output_objdir/$libname.a $output_objdir/$libname.def'
+      ;;
+
+    osf3*)
+      if test "$GCC" = yes; then
+	allow_undefined_flag=' ${wl}-expect_unresolved ${wl}\*'
+	archive_cmds='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && func_echo_all "${wl}-set_version ${wl}$verstring"` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
+      else
+	allow_undefined_flag=' -expect_unresolved \*'
+	archive_cmds='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry ${output_objdir}/so_locations -o $lib'
+      fi
+      archive_cmds_need_lc='no'
+      hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
+      hardcode_libdir_separator=:
+      ;;
+
+    osf4* | osf5*)	# as osf3* with the addition of -msym flag
+      if test "$GCC" = yes; then
+	allow_undefined_flag=' ${wl}-expect_unresolved ${wl}\*'
+	archive_cmds='$CC -shared${allow_undefined_flag} $pic_flag $libobjs $deplibs $compiler_flags ${wl}-msym ${wl}-soname ${wl}$soname `test -n "$verstring" && func_echo_all "${wl}-set_version ${wl}$verstring"` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
+	hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
+      else
+	allow_undefined_flag=' -expect_unresolved \*'
+	archive_cmds='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags -msym -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry ${output_objdir}/so_locations -o $lib'
+	archive_expsym_cmds='for i in `cat $export_symbols`; do printf "%s %s\\n" -exported_symbol "\$i" >> $lib.exp; done; printf "%s\\n" "-hidden">> $lib.exp~
+	$CC -shared${allow_undefined_flag} ${wl}-input ${wl}$lib.exp $compiler_flags $libobjs $deplibs -soname $soname `test -n "$verstring" && $ECHO "-set_version $verstring"` -update_registry ${output_objdir}/so_locations -o $lib~$RM $lib.exp'
+
+	# Both c and cxx compiler support -rpath directly
+	hardcode_libdir_flag_spec='-rpath $libdir'
+      fi
+      archive_cmds_need_lc='no'
+      hardcode_libdir_separator=:
+      ;;
+
+    solaris*)
+      no_undefined_flag=' -z defs'
+      if test "$GCC" = yes; then
+	wlarc='${wl}'
+	archive_cmds='$CC -shared $pic_flag ${wl}-z ${wl}text ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags'
+	archive_expsym_cmds='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~
+	  $CC -shared $pic_flag ${wl}-z ${wl}text ${wl}-M ${wl}$lib.exp ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags~$RM $lib.exp'
+      else
+	case `$CC -V 2>&1` in
+	*"Compilers 5.0"*)
+	  wlarc=''
+	  archive_cmds='$LD -G${allow_undefined_flag} -h $soname -o $lib $libobjs $deplibs $linker_flags'
+	  archive_expsym_cmds='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~
+	  $LD -G${allow_undefined_flag} -M $lib.exp -h $soname -o $lib $libobjs $deplibs $linker_flags~$RM $lib.exp'
+	  ;;
+	*)
+	  wlarc='${wl}'
+	  archive_cmds='$CC -G${allow_undefined_flag} -h $soname -o $lib $libobjs $deplibs $compiler_flags'
+	  archive_expsym_cmds='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~
+	  $CC -G${allow_undefined_flag} -M $lib.exp -h $soname -o $lib $libobjs $deplibs $compiler_flags~$RM $lib.exp'
+	  ;;
+	esac
+      fi
+      hardcode_libdir_flag_spec='-R$libdir'
+      hardcode_shlibpath_var=no
+      case $host_os in
+      solaris2.[0-5] | solaris2.[0-5].*) ;;
+      *)
+	# The compiler driver will combine and reorder linker options,
+	# but understands `-z linker_flag'.  GCC discards it without `$wl',
+	# but is careful enough not to reorder.
+	# Supported since Solaris 2.6 (maybe 2.5.1?)
+	if test "$GCC" = yes; then
+	  whole_archive_flag_spec='${wl}-z ${wl}allextract$convenience ${wl}-z ${wl}defaultextract'
+	else
+	  whole_archive_flag_spec='-z allextract$convenience -z defaultextract'
+	fi
+	;;
+      esac
+      link_all_deplibs=yes
+      ;;
+
+    sunos4*)
+      if test "x$host_vendor" = xsequent; then
+	# Use $CC to link under sequent, because it throws in some extra .o
+	# files that make .init and .fini sections work.
+	archive_cmds='$CC -G ${wl}-h $soname -o $lib $libobjs $deplibs $compiler_flags'
+      else
+	archive_cmds='$LD -assert pure-text -Bstatic -o $lib $libobjs $deplibs $linker_flags'
+      fi
+      hardcode_libdir_flag_spec='-L$libdir'
+      hardcode_direct=yes
+      hardcode_minus_L=yes
+      hardcode_shlibpath_var=no
+      ;;
+
+    sysv4)
+      case $host_vendor in
+	sni)
+	  archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+	  hardcode_direct=yes # is this really true???
+	;;
+	siemens)
+	  ## LD is ld it makes a PLAMLIB
+	  ## CC just makes a GrossModule.
+	  archive_cmds='$LD -G -o $lib $libobjs $deplibs $linker_flags'
+	  reload_cmds='$CC -r -o $output$reload_objs'
+	  hardcode_direct=no
+        ;;
+	motorola)
+	  archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+	  hardcode_direct=no #Motorola manual says yes, but my tests say they lie
+	;;
+      esac
+      runpath_var='LD_RUN_PATH'
+      hardcode_shlibpath_var=no
+      ;;
+
+    sysv4.3*)
+      archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+      hardcode_shlibpath_var=no
+      export_dynamic_flag_spec='-Bexport'
+      ;;
+
+    sysv4*MP*)
+      if test -d /usr/nec; then
+	archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+	hardcode_shlibpath_var=no
+	runpath_var=LD_RUN_PATH
+	hardcode_runpath_var=yes
+	ld_shlibs=yes
+      fi
+      ;;
+
+    sysv4*uw2* | sysv5OpenUNIX* | sysv5UnixWare7.[01].[10]* | unixware7* | sco3.2v5.0.[024]*)
+      no_undefined_flag='${wl}-z,text'
+      archive_cmds_need_lc=no
+      hardcode_shlibpath_var=no
+      runpath_var='LD_RUN_PATH'
+
+      if test "$GCC" = yes; then
+	archive_cmds='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+	archive_expsym_cmds='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+      else
+	archive_cmds='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+	archive_expsym_cmds='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+      fi
+      ;;
+
+    sysv5* | sco3.2v5* | sco5v6*)
+      # Note: We can NOT use -z defs as we might desire, because we do not
+      # link with -lc, and that would cause any symbols used from libc to
+      # always be unresolved, which means just about no library would
+      # ever link correctly.  If we're not using GNU ld we use -z text
+      # though, which does catch some bad symbols but isn't as heavy-handed
+      # as -z defs.
+      no_undefined_flag='${wl}-z,text'
+      allow_undefined_flag='${wl}-z,nodefs'
+      archive_cmds_need_lc=no
+      hardcode_shlibpath_var=no
+      hardcode_libdir_flag_spec='${wl}-R,$libdir'
+      hardcode_libdir_separator=':'
+      link_all_deplibs=yes
+      export_dynamic_flag_spec='${wl}-Bexport'
+      runpath_var='LD_RUN_PATH'
+
+      if test "$GCC" = yes; then
+	archive_cmds='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+	archive_expsym_cmds='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+      else
+	archive_cmds='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+	archive_expsym_cmds='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+      fi
+      ;;
+
+    uts4*)
+      archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+      hardcode_libdir_flag_spec='-L$libdir'
+      hardcode_shlibpath_var=no
+      ;;
+
+    *)
+      ld_shlibs=no
+      ;;
+    esac
+
+    if test x$host_vendor = xsni; then
+      case $host in
+      sysv4 | sysv4.2uw2* | sysv4.3* | sysv5*)
+	export_dynamic_flag_spec='${wl}-Blargedynsym'
+	;;
+      esac
+    fi
+  fi
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ld_shlibs" >&5
+$as_echo "$ld_shlibs" >&6; }
+test "$ld_shlibs" = no && can_build_shared=no
+
+with_gnu_ld=$with_gnu_ld
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#
+# Do we need to explicitly link libc?
+#
+case "x$archive_cmds_need_lc" in
+x|xyes)
+  # Assume -lc should be added
+  archive_cmds_need_lc=yes
+
+  if test "$enable_shared" = yes && test "$GCC" = yes; then
+    case $archive_cmds in
+    *'~'*)
+      # FIXME: we may have to deal with multi-command sequences.
+      ;;
+    '$CC '*)
+      # Test whether the compiler implicitly links with -lc since on some
+      # systems, -lgcc has to come before -lc. If gcc already passes -lc
+      # to ld, don't add -lc before -lgcc.
+      { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether -lc should be explicitly linked in" >&5
+$as_echo_n "checking whether -lc should be explicitly linked in... " >&6; }
+if ${lt_cv_archive_cmds_need_lc+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  $RM conftest*
+	echo "$lt_simple_compile_test_code" > conftest.$ac_ext
+
+	if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5
+  (eval $ac_compile) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; } 2>conftest.err; then
+	  soname=conftest
+	  lib=conftest
+	  libobjs=conftest.$ac_objext
+	  deplibs=
+	  wl=$lt_prog_compiler_wl
+	  pic_flag=$lt_prog_compiler_pic
+	  compiler_flags=-v
+	  linker_flags=-v
+	  verstring=
+	  output_objdir=.
+	  libname=conftest
+	  lt_save_allow_undefined_flag=$allow_undefined_flag
+	  allow_undefined_flag=
+	  if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$archive_cmds 2\>\&1 \| $GREP \" -lc \" \>/dev/null 2\>\&1\""; } >&5
+  (eval $archive_cmds 2\>\&1 \| $GREP \" -lc \" \>/dev/null 2\>\&1) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }
+	  then
+	    lt_cv_archive_cmds_need_lc=no
+	  else
+	    lt_cv_archive_cmds_need_lc=yes
+	  fi
+	  allow_undefined_flag=$lt_save_allow_undefined_flag
+	else
+	  cat conftest.err 1>&5
+	fi
+	$RM conftest*
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_archive_cmds_need_lc" >&5
+$as_echo "$lt_cv_archive_cmds_need_lc" >&6; }
+      archive_cmds_need_lc=$lt_cv_archive_cmds_need_lc
+      ;;
+    esac
+  fi
+  ;;
+esac
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking dynamic linker characteristics" >&5
+$as_echo_n "checking dynamic linker characteristics... " >&6; }
+
+if test "$GCC" = yes; then
+  case $host_os in
+    darwin*) lt_awk_arg="/^libraries:/,/LR/" ;;
+    *) lt_awk_arg="/^libraries:/" ;;
+  esac
+  case $host_os in
+    mingw* | cegcc*) lt_sed_strip_eq="s,=\([A-Za-z]:\),\1,g" ;;
+    *) lt_sed_strip_eq="s,=/,/,g" ;;
+  esac
+  lt_search_path_spec=`$CC -print-search-dirs | awk $lt_awk_arg | $SED -e "s/^libraries://" -e $lt_sed_strip_eq`
+  case $lt_search_path_spec in
+  *\;*)
+    # if the path contains ";" then we assume it to be the separator
+    # otherwise default to the standard path separator (i.e. ":") - it is
+    # assumed that no part of a normal pathname contains ";" but that should
+    # okay in the real world where ";" in dirpaths is itself problematic.
+    lt_search_path_spec=`$ECHO "$lt_search_path_spec" | $SED 's/;/ /g'`
+    ;;
+  *)
+    lt_search_path_spec=`$ECHO "$lt_search_path_spec" | $SED "s/$PATH_SEPARATOR/ /g"`
+    ;;
+  esac
+  # Ok, now we have the path, separated by spaces, we can step through it
+  # and add multilib dir if necessary.
+  lt_tmp_lt_search_path_spec=
+  lt_multi_os_dir=`$CC $CPPFLAGS $CFLAGS $LDFLAGS -print-multi-os-directory 2>/dev/null`
+  for lt_sys_path in $lt_search_path_spec; do
+    if test -d "$lt_sys_path/$lt_multi_os_dir"; then
+      lt_tmp_lt_search_path_spec="$lt_tmp_lt_search_path_spec $lt_sys_path/$lt_multi_os_dir"
+    else
+      test -d "$lt_sys_path" && \
+	lt_tmp_lt_search_path_spec="$lt_tmp_lt_search_path_spec $lt_sys_path"
+    fi
+  done
+  lt_search_path_spec=`$ECHO "$lt_tmp_lt_search_path_spec" | awk '
+BEGIN {RS=" "; FS="/|\n";} {
+  lt_foo="";
+  lt_count=0;
+  for (lt_i = NF; lt_i > 0; lt_i--) {
+    if ($lt_i != "" && $lt_i != ".") {
+      if ($lt_i == "..") {
+        lt_count++;
+      } else {
+        if (lt_count == 0) {
+          lt_foo="/" $lt_i lt_foo;
+        } else {
+          lt_count--;
+        }
+      }
+    }
+  }
+  if (lt_foo != "") { lt_freq[lt_foo]++; }
+  if (lt_freq[lt_foo] == 1) { print lt_foo; }
+}'`
+  # AWK program above erroneously prepends '/' to C:/dos/paths
+  # for these hosts.
+  case $host_os in
+    mingw* | cegcc*) lt_search_path_spec=`$ECHO "$lt_search_path_spec" |\
+      $SED 's,/\([A-Za-z]:\),\1,g'` ;;
+  esac
+  sys_lib_search_path_spec=`$ECHO "$lt_search_path_spec" | $lt_NL2SP`
+else
+  sys_lib_search_path_spec="/lib /usr/lib /usr/local/lib"
+fi
+library_names_spec=
+libname_spec='lib$name'
+soname_spec=
+shrext_cmds=".so"
+postinstall_cmds=
+postuninstall_cmds=
+finish_cmds=
+finish_eval=
+shlibpath_var=
+shlibpath_overrides_runpath=unknown
+version_type=none
+dynamic_linker="$host_os ld.so"
+sys_lib_dlsearch_path_spec="/lib /usr/lib"
+need_lib_prefix=unknown
+hardcode_into_libs=no
+
+# when you set need_version to no, make sure it does not cause -set_version
+# flags to be left without arguments
+need_version=unknown
+
+case $host_os in
+aix3*)
+  version_type=linux # correct to gnu/linux during the next big refactor
+  library_names_spec='${libname}${release}${shared_ext}$versuffix $libname.a'
+  shlibpath_var=LIBPATH
+
+  # AIX 3 has no versioning support, so we append a major version to the name.
+  soname_spec='${libname}${release}${shared_ext}$major'
+  ;;
+
+aix[4-9]*)
+  version_type=linux # correct to gnu/linux during the next big refactor
+  need_lib_prefix=no
+  need_version=no
+  hardcode_into_libs=yes
+  if test "$host_cpu" = ia64; then
+    # AIX 5 supports IA64
+    library_names_spec='${libname}${release}${shared_ext}$major ${libname}${release}${shared_ext}$versuffix $libname${shared_ext}'
+    shlibpath_var=LD_LIBRARY_PATH
+  else
+    # With GCC up to 2.95.x, collect2 would create an import file
+    # for dependence libraries.  The import file would start with
+    # the line `#! .'.  This would cause the generated library to
+    # depend on `.', always an invalid library.  This was fixed in
+    # development snapshots of GCC prior to 3.0.
+    case $host_os in
+      aix4 | aix4.[01] | aix4.[01].*)
+      if { echo '#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 97)'
+	   echo ' yes '
+	   echo '#endif'; } | ${CC} -E - | $GREP yes > /dev/null; then
+	:
+      else
+	can_build_shared=no
+      fi
+      ;;
+    esac
+    # AIX (on Power*) has no versioning support, so currently we can not hardcode correct
+    # soname into executable. Probably we can add versioning support to
+    # collect2, so additional links can be useful in future.
+    if test "$aix_use_runtimelinking" = yes; then
+      # If using run time linking (on AIX 4.2 or later) use lib<name>.so
+      # instead of lib<name>.a to let people know that these are not
+      # typical AIX shared libraries.
+      library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+    else
+      # We preserve .a as extension for shared libraries through AIX4.2
+      # and later when we are not doing run time linking.
+      library_names_spec='${libname}${release}.a $libname.a'
+      soname_spec='${libname}${release}${shared_ext}$major'
+    fi
+    shlibpath_var=LIBPATH
+  fi
+  ;;
+
+amigaos*)
+  case $host_cpu in
+  powerpc)
+    # Since July 2007 AmigaOS4 officially supports .so libraries.
+    # When compiling the executable, add -use-dynld -Lsobjs: to the compileline.
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+    ;;
+  m68k)
+    library_names_spec='$libname.ixlibrary $libname.a'
+    # Create ${libname}_ixlibrary.a entries in /sys/libs.
+    finish_eval='for lib in `ls $libdir/*.ixlibrary 2>/dev/null`; do libname=`func_echo_all "$lib" | $SED '\''s%^.*/\([^/]*\)\.ixlibrary$%\1%'\''`; test $RM /sys/libs/${libname}_ixlibrary.a; $show "cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a"; cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a || exit 1; done'
+    ;;
+  esac
+  ;;
+
+beos*)
+  library_names_spec='${libname}${shared_ext}'
+  dynamic_linker="$host_os ld.so"
+  shlibpath_var=LIBRARY_PATH
+  ;;
+
+bsdi[45]*)
+  version_type=linux # correct to gnu/linux during the next big refactor
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  finish_cmds='PATH="\$PATH:/sbin" ldconfig $libdir'
+  shlibpath_var=LD_LIBRARY_PATH
+  sys_lib_search_path_spec="/shlib /usr/lib /usr/X11/lib /usr/contrib/lib /lib /usr/local/lib"
+  sys_lib_dlsearch_path_spec="/shlib /usr/lib /usr/local/lib"
+  # the default ld.so.conf also contains /usr/contrib/lib and
+  # /usr/X11R6/lib (/usr/X11 is a link to /usr/X11R6), but let us allow
+  # libtool to hard-code these into programs
+  ;;
+
+cygwin* | mingw* | pw32* | cegcc*)
+  version_type=windows
+  shrext_cmds=".dll"
+  need_version=no
+  need_lib_prefix=no
+
+  case $GCC,$cc_basename in
+  yes,*)
+    # gcc
+    library_names_spec='$libname.dll.a'
+    # DLL is installed to $(libdir)/../bin by postinstall_cmds
+    postinstall_cmds='base_file=`basename \${file}`~
+      dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
+      dldir=$destdir/`dirname \$dlpath`~
+      test -d \$dldir || mkdir -p \$dldir~
+      $install_prog $dir/$dlname \$dldir/$dlname~
+      chmod a+x \$dldir/$dlname~
+      if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
+        eval '\''$striplib \$dldir/$dlname'\'' || exit \$?;
+      fi'
+    postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~
+      dlpath=$dir/\$dldll~
+       $RM \$dlpath'
+    shlibpath_overrides_runpath=yes
+
+    case $host_os in
+    cygwin*)
+      # Cygwin DLLs use 'cyg' prefix rather than 'lib'
+      soname_spec='`echo ${libname} | sed -e 's/^lib/cyg/'``echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}'
+
+      sys_lib_search_path_spec="$sys_lib_search_path_spec /usr/lib/w32api"
+      ;;
+    mingw* | cegcc*)
+      # MinGW DLLs use traditional 'lib' prefix
+      soname_spec='${libname}`echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}'
+      ;;
+    pw32*)
+      # pw32 DLLs use 'pw' prefix rather than 'lib'
+      library_names_spec='`echo ${libname} | sed -e 's/^lib/pw/'``echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}'
+      ;;
+    esac
+    dynamic_linker='Win32 ld.exe'
+    ;;
+
+  *,cl*)
+    # Native MSVC
+    libname_spec='$name'
+    soname_spec='${libname}`echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}'
+    library_names_spec='${libname}.dll.lib'
+
+    case $build_os in
+    mingw*)
+      sys_lib_search_path_spec=
+      lt_save_ifs=$IFS
+      IFS=';'
+      for lt_path in $LIB
+      do
+        IFS=$lt_save_ifs
+        # Let DOS variable expansion print the short 8.3 style file name.
+        lt_path=`cd "$lt_path" 2>/dev/null && cmd //C "for %i in (".") do @echo %~si"`
+        sys_lib_search_path_spec="$sys_lib_search_path_spec $lt_path"
+      done
+      IFS=$lt_save_ifs
+      # Convert to MSYS style.
+      sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | sed -e 's|\\\\|/|g' -e 's| \\([a-zA-Z]\\):| /\\1|g' -e 's|^ ||'`
+      ;;
+    cygwin*)
+      # Convert to unix form, then to dos form, then back to unix form
+      # but this time dos style (no spaces!) so that the unix form looks
+      # like /cygdrive/c/PROGRA~1:/cygdr...
+      sys_lib_search_path_spec=`cygpath --path --unix "$LIB"`
+      sys_lib_search_path_spec=`cygpath --path --dos "$sys_lib_search_path_spec" 2>/dev/null`
+      sys_lib_search_path_spec=`cygpath --path --unix "$sys_lib_search_path_spec" | $SED -e "s/$PATH_SEPARATOR/ /g"`
+      ;;
+    *)
+      sys_lib_search_path_spec="$LIB"
+      if $ECHO "$sys_lib_search_path_spec" | $GREP ';[c-zC-Z]:/' >/dev/null; then
+        # It is most probably a Windows format PATH.
+        sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | $SED -e 's/;/ /g'`
+      else
+        sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | $SED -e "s/$PATH_SEPARATOR/ /g"`
+      fi
+      # FIXME: find the short name or the path components, as spaces are
+      # common. (e.g. "Program Files" -> "PROGRA~1")
+      ;;
+    esac
+
+    # DLL is installed to $(libdir)/../bin by postinstall_cmds
+    postinstall_cmds='base_file=`basename \${file}`~
+      dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
+      dldir=$destdir/`dirname \$dlpath`~
+      test -d \$dldir || mkdir -p \$dldir~
+      $install_prog $dir/$dlname \$dldir/$dlname'
+    postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~
+      dlpath=$dir/\$dldll~
+       $RM \$dlpath'
+    shlibpath_overrides_runpath=yes
+    dynamic_linker='Win32 link.exe'
+    ;;
+
+  *)
+    # Assume MSVC wrapper
+    library_names_spec='${libname}`echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext} $libname.lib'
+    dynamic_linker='Win32 ld.exe'
+    ;;
+  esac
+  # FIXME: first we should search . and the directory the executable is in
+  shlibpath_var=PATH
+  ;;
+
+darwin* | rhapsody*)
+  dynamic_linker="$host_os dyld"
+  version_type=darwin
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${major}$shared_ext ${libname}$shared_ext'
+  soname_spec='${libname}${release}${major}$shared_ext'
+  shlibpath_overrides_runpath=yes
+  shlibpath_var=DYLD_LIBRARY_PATH
+  shrext_cmds='`test .$module = .yes && echo .so || echo .dylib`'
+
+  sys_lib_search_path_spec="$sys_lib_search_path_spec /usr/local/lib"
+  sys_lib_dlsearch_path_spec='/usr/local/lib /lib /usr/lib'
+  ;;
+
+dgux*)
+  version_type=linux # correct to gnu/linux during the next big refactor
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname$shared_ext'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  ;;
+
+freebsd* | dragonfly*)
+  # DragonFly does not have aout.  When/if they implement a new
+  # versioning mechanism, adjust this.
+  if test -x /usr/bin/objformat; then
+    objformat=`/usr/bin/objformat`
+  else
+    case $host_os in
+    freebsd[23].*) objformat=aout ;;
+    *) objformat=elf ;;
+    esac
+  fi
+  version_type=freebsd-$objformat
+  case $version_type in
+    freebsd-elf*)
+      library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext} $libname${shared_ext}'
+      need_version=no
+      need_lib_prefix=no
+      ;;
+    freebsd-*)
+      library_names_spec='${libname}${release}${shared_ext}$versuffix $libname${shared_ext}$versuffix'
+      need_version=yes
+      ;;
+  esac
+  shlibpath_var=LD_LIBRARY_PATH
+  case $host_os in
+  freebsd2.*)
+    shlibpath_overrides_runpath=yes
+    ;;
+  freebsd3.[01]* | freebsdelf3.[01]*)
+    shlibpath_overrides_runpath=yes
+    hardcode_into_libs=yes
+    ;;
+  freebsd3.[2-9]* | freebsdelf3.[2-9]* | \
+  freebsd4.[0-5] | freebsdelf4.[0-5] | freebsd4.1.1 | freebsdelf4.1.1)
+    shlibpath_overrides_runpath=no
+    hardcode_into_libs=yes
+    ;;
+  *) # from 4.6 on, and DragonFly
+    shlibpath_overrides_runpath=yes
+    hardcode_into_libs=yes
+    ;;
+  esac
+  ;;
+
+haiku*)
+  version_type=linux # correct to gnu/linux during the next big refactor
+  need_lib_prefix=no
+  need_version=no
+  dynamic_linker="$host_os runtime_loader"
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}${major} ${libname}${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  sys_lib_dlsearch_path_spec='/boot/home/config/lib /boot/common/lib /boot/system/lib'
+  hardcode_into_libs=yes
+  ;;
+
+hpux9* | hpux10* | hpux11*)
+  # Give a soname corresponding to the major version so that dld.sl refuses to
+  # link against other versions.
+  version_type=sunos
+  need_lib_prefix=no
+  need_version=no
+  case $host_cpu in
+  ia64*)
+    shrext_cmds='.so'
+    hardcode_into_libs=yes
+    dynamic_linker="$host_os dld.so"
+    shlibpath_var=LD_LIBRARY_PATH
+    shlibpath_overrides_runpath=yes # Unless +noenvvar is specified.
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+    soname_spec='${libname}${release}${shared_ext}$major'
+    if test "X$HPUX_IA64_MODE" = X32; then
+      sys_lib_search_path_spec="/usr/lib/hpux32 /usr/local/lib/hpux32 /usr/local/lib"
+    else
+      sys_lib_search_path_spec="/usr/lib/hpux64 /usr/local/lib/hpux64"
+    fi
+    sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec
+    ;;
+  hppa*64*)
+    shrext_cmds='.sl'
+    hardcode_into_libs=yes
+    dynamic_linker="$host_os dld.sl"
+    shlibpath_var=LD_LIBRARY_PATH # How should we handle SHLIB_PATH
+    shlibpath_overrides_runpath=yes # Unless +noenvvar is specified.
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+    soname_spec='${libname}${release}${shared_ext}$major'
+    sys_lib_search_path_spec="/usr/lib/pa20_64 /usr/ccs/lib/pa20_64"
+    sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec
+    ;;
+  *)
+    shrext_cmds='.sl'
+    dynamic_linker="$host_os dld.sl"
+    shlibpath_var=SHLIB_PATH
+    shlibpath_overrides_runpath=no # +s is required to enable SHLIB_PATH
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+    soname_spec='${libname}${release}${shared_ext}$major'
+    ;;
+  esac
+  # HP-UX runs *really* slowly unless shared libraries are mode 555, ...
+  postinstall_cmds='chmod 555 $lib'
+  # or fails outright, so override atomically:
+  install_override_mode=555
+  ;;
+
+interix[3-9]*)
+  version_type=linux # correct to gnu/linux during the next big refactor
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  dynamic_linker='Interix 3.x ld.so.1 (PE, like ELF)'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=no
+  hardcode_into_libs=yes
+  ;;
+
+irix5* | irix6* | nonstopux*)
+  case $host_os in
+    nonstopux*) version_type=nonstopux ;;
+    *)
+	if test "$lt_cv_prog_gnu_ld" = yes; then
+		version_type=linux # correct to gnu/linux during the next big refactor
+	else
+		version_type=irix
+	fi ;;
+  esac
+  need_lib_prefix=no
+  need_version=no
+  soname_spec='${libname}${release}${shared_ext}$major'
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${release}${shared_ext} $libname${shared_ext}'
+  case $host_os in
+  irix5* | nonstopux*)
+    libsuff= shlibsuff=
+    ;;
+  *)
+    case $LD in # libtool.m4 will add one of these switches to LD
+    *-32|*"-32 "|*-melf32bsmip|*"-melf32bsmip ")
+      libsuff= shlibsuff= libmagic=32-bit;;
+    *-n32|*"-n32 "|*-melf32bmipn32|*"-melf32bmipn32 ")
+      libsuff=32 shlibsuff=N32 libmagic=N32;;
+    *-64|*"-64 "|*-melf64bmip|*"-melf64bmip ")
+      libsuff=64 shlibsuff=64 libmagic=64-bit;;
+    *) libsuff= shlibsuff= libmagic=never-match;;
+    esac
+    ;;
+  esac
+  shlibpath_var=LD_LIBRARY${shlibsuff}_PATH
+  shlibpath_overrides_runpath=no
+  sys_lib_search_path_spec="/usr/lib${libsuff} /lib${libsuff} /usr/local/lib${libsuff}"
+  sys_lib_dlsearch_path_spec="/usr/lib${libsuff} /lib${libsuff}"
+  hardcode_into_libs=yes
+  ;;
+
+# No shared lib support for Linux oldld, aout, or coff.
+linux*oldld* | linux*aout* | linux*coff*)
+  dynamic_linker=no
+  ;;
+
+# This must be glibc/ELF.
+linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*)
+  version_type=linux # correct to gnu/linux during the next big refactor
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  finish_cmds='PATH="\$PATH:/sbin" ldconfig -n $libdir'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=no
+
+  # Some binutils ld are patched to set DT_RUNPATH
+  if ${lt_cv_shlibpath_overrides_runpath+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  lt_cv_shlibpath_overrides_runpath=no
+    save_LDFLAGS=$LDFLAGS
+    save_libdir=$libdir
+    eval "libdir=/foo; wl=\"$lt_prog_compiler_wl\"; \
+	 LDFLAGS=\"\$LDFLAGS $hardcode_libdir_flag_spec\""
+    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  if  ($OBJDUMP -p conftest$ac_exeext) 2>/dev/null | grep "RUNPATH.*$libdir" >/dev/null; then :
+  lt_cv_shlibpath_overrides_runpath=yes
+fi
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+    LDFLAGS=$save_LDFLAGS
+    libdir=$save_libdir
+
+fi
+
+  shlibpath_overrides_runpath=$lt_cv_shlibpath_overrides_runpath
+
+  # This implies no fast_install, which is unacceptable.
+  # Some rework will be needed to allow for fast_install
+  # before this can be enabled.
+  hardcode_into_libs=yes
+
+  # Append ld.so.conf contents to the search path
+  if test -f /etc/ld.so.conf; then
+    lt_ld_extra=`awk '/^include / { system(sprintf("cd /etc; cat %s 2>/dev/null", \$2)); skip = 1; } { if (!skip) print \$0; skip = 0; }' < /etc/ld.so.conf | $SED -e 's/#.*//;/^[	 ]*hwcap[	 ]/d;s/[:,	]/ /g;s/=[^=]*$//;s/=[^= ]* / /g;s/"//g;/^$/d' | tr '\n' ' '`
+    sys_lib_dlsearch_path_spec="/lib /usr/lib $lt_ld_extra"
+  fi
+
+  # We used to test for /lib/ld.so.1 and disable shared libraries on
+  # powerpc, because MkLinux only supported shared libraries with the
+  # GNU dynamic linker.  Since this was broken with cross compilers,
+  # most powerpc-linux boxes support dynamic linking these days and
+  # people can always --disable-shared, the test was removed, and we
+  # assume the GNU/Linux dynamic linker is in use.
+  dynamic_linker='GNU/Linux ld.so'
+  ;;
+
+netbsdelf*-gnu)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=no
+  hardcode_into_libs=yes
+  dynamic_linker='NetBSD ld.elf_so'
+  ;;
+
+netbsd*)
+  version_type=sunos
+  need_lib_prefix=no
+  need_version=no
+  if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix'
+    finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir'
+    dynamic_linker='NetBSD (a.out) ld.so'
+  else
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}'
+    soname_spec='${libname}${release}${shared_ext}$major'
+    dynamic_linker='NetBSD ld.elf_so'
+  fi
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  hardcode_into_libs=yes
+  ;;
+
+newsos6)
+  version_type=linux # correct to gnu/linux during the next big refactor
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  ;;
+
+*nto* | *qnx*)
+  version_type=qnx
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=no
+  hardcode_into_libs=yes
+  dynamic_linker='ldqnx.so'
+  ;;
+
+openbsd*)
+  version_type=sunos
+  sys_lib_dlsearch_path_spec="/usr/lib"
+  need_lib_prefix=no
+  # Some older versions of OpenBSD (3.3 at least) *do* need versioned libs.
+  case $host_os in
+    openbsd3.3 | openbsd3.3.*)	need_version=yes ;;
+    *)				need_version=no  ;;
+  esac
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix'
+  finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir'
+  shlibpath_var=LD_LIBRARY_PATH
+  if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then
+    case $host_os in
+      openbsd2.[89] | openbsd2.[89].*)
+	shlibpath_overrides_runpath=no
+	;;
+      *)
+	shlibpath_overrides_runpath=yes
+	;;
+      esac
+  else
+    shlibpath_overrides_runpath=yes
+  fi
+  ;;
+
+os2*)
+  libname_spec='$name'
+  shrext_cmds=".dll"
+  need_lib_prefix=no
+  library_names_spec='$libname${shared_ext} $libname.a'
+  dynamic_linker='OS/2 ld.exe'
+  shlibpath_var=LIBPATH
+  ;;
+
+osf3* | osf4* | osf5*)
+  version_type=osf
+  need_lib_prefix=no
+  need_version=no
+  soname_spec='${libname}${release}${shared_ext}$major'
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  shlibpath_var=LD_LIBRARY_PATH
+  sys_lib_search_path_spec="/usr/shlib /usr/ccs/lib /usr/lib/cmplrs/cc /usr/lib /usr/local/lib /var/shlib"
+  sys_lib_dlsearch_path_spec="$sys_lib_search_path_spec"
+  ;;
+
+rdos*)
+  dynamic_linker=no
+  ;;
+
+solaris*)
+  version_type=linux # correct to gnu/linux during the next big refactor
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  hardcode_into_libs=yes
+  # ldd complains unless libraries are executable
+  postinstall_cmds='chmod +x $lib'
+  ;;
+
+sunos4*)
+  version_type=sunos
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix'
+  finish_cmds='PATH="\$PATH:/usr/etc" ldconfig $libdir'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  if test "$with_gnu_ld" = yes; then
+    need_lib_prefix=no
+  fi
+  need_version=yes
+  ;;
+
+sysv4 | sysv4.3*)
+  version_type=linux # correct to gnu/linux during the next big refactor
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  case $host_vendor in
+    sni)
+      shlibpath_overrides_runpath=no
+      need_lib_prefix=no
+      runpath_var=LD_RUN_PATH
+      ;;
+    siemens)
+      need_lib_prefix=no
+      ;;
+    motorola)
+      need_lib_prefix=no
+      need_version=no
+      shlibpath_overrides_runpath=no
+      sys_lib_search_path_spec='/lib /usr/lib /usr/ccs/lib'
+      ;;
+  esac
+  ;;
+
+sysv4*MP*)
+  if test -d /usr/nec ;then
+    version_type=linux # correct to gnu/linux during the next big refactor
+    library_names_spec='$libname${shared_ext}.$versuffix $libname${shared_ext}.$major $libname${shared_ext}'
+    soname_spec='$libname${shared_ext}.$major'
+    shlibpath_var=LD_LIBRARY_PATH
+  fi
+  ;;
+
+sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*)
+  version_type=freebsd-elf
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext} $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  hardcode_into_libs=yes
+  if test "$with_gnu_ld" = yes; then
+    sys_lib_search_path_spec='/usr/local/lib /usr/gnu/lib /usr/ccs/lib /usr/lib /lib'
+  else
+    sys_lib_search_path_spec='/usr/ccs/lib /usr/lib'
+    case $host_os in
+      sco3.2v5*)
+        sys_lib_search_path_spec="$sys_lib_search_path_spec /lib"
+	;;
+    esac
+  fi
+  sys_lib_dlsearch_path_spec='/usr/lib'
+  ;;
+
+tpf*)
+  # TPF is a cross-target only.  Preferred cross-host = GNU/Linux.
+  version_type=linux # correct to gnu/linux during the next big refactor
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=no
+  hardcode_into_libs=yes
+  ;;
+
+uts4*)
+  version_type=linux # correct to gnu/linux during the next big refactor
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  ;;
+
+*)
+  dynamic_linker=no
+  ;;
+esac
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $dynamic_linker" >&5
+$as_echo "$dynamic_linker" >&6; }
+test "$dynamic_linker" = no && can_build_shared=no
+
+variables_saved_for_relink="PATH $shlibpath_var $runpath_var"
+if test "$GCC" = yes; then
+  variables_saved_for_relink="$variables_saved_for_relink GCC_EXEC_PREFIX COMPILER_PATH LIBRARY_PATH"
+fi
+
+if test "${lt_cv_sys_lib_search_path_spec+set}" = set; then
+  sys_lib_search_path_spec="$lt_cv_sys_lib_search_path_spec"
+fi
+if test "${lt_cv_sys_lib_dlsearch_path_spec+set}" = set; then
+  sys_lib_dlsearch_path_spec="$lt_cv_sys_lib_dlsearch_path_spec"
+fi
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking how to hardcode library paths into programs" >&5
+$as_echo_n "checking how to hardcode library paths into programs... " >&6; }
+hardcode_action=
+if test -n "$hardcode_libdir_flag_spec" ||
+   test -n "$runpath_var" ||
+   test "X$hardcode_automatic" = "Xyes" ; then
+
+  # We can hardcode non-existent directories.
+  if test "$hardcode_direct" != no &&
+     # If the only mechanism to avoid hardcoding is shlibpath_var, we
+     # have to relink, otherwise we might link with an installed library
+     # when we should be linking with a yet-to-be-installed one
+     ## test "$_LT_TAGVAR(hardcode_shlibpath_var, )" != no &&
+     test "$hardcode_minus_L" != no; then
+    # Linking always hardcodes the temporary library directory.
+    hardcode_action=relink
+  else
+    # We can link without hardcoding, and we can hardcode nonexisting dirs.
+    hardcode_action=immediate
+  fi
+else
+  # We cannot hardcode anything, or else we can only hardcode existing
+  # directories.
+  hardcode_action=unsupported
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $hardcode_action" >&5
+$as_echo "$hardcode_action" >&6; }
+
+if test "$hardcode_action" = relink ||
+   test "$inherit_rpath" = yes; then
+  # Fast installation is not supported
+  enable_fast_install=no
+elif test "$shlibpath_overrides_runpath" = yes ||
+     test "$enable_shared" = no; then
+  # Fast installation is not necessary
+  enable_fast_install=needless
+fi
+
+
+
+
+
+
+  if test "x$enable_dlopen" != xyes; then
+  enable_dlopen=unknown
+  enable_dlopen_self=unknown
+  enable_dlopen_self_static=unknown
+else
+  lt_cv_dlopen=no
+  lt_cv_dlopen_libs=
+
+  case $host_os in
+  beos*)
+    lt_cv_dlopen="load_add_on"
+    lt_cv_dlopen_libs=
+    lt_cv_dlopen_self=yes
+    ;;
+
+  mingw* | pw32* | cegcc*)
+    lt_cv_dlopen="LoadLibrary"
+    lt_cv_dlopen_libs=
+    ;;
+
+  cygwin*)
+    lt_cv_dlopen="dlopen"
+    lt_cv_dlopen_libs=
+    ;;
+
+  darwin*)
+  # if libdl is installed we need to link against it
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dlopen in -ldl" >&5
+$as_echo_n "checking for dlopen in -ldl... " >&6; }
+if ${ac_cv_lib_dl_dlopen+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-ldl  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char dlopen ();
+int
+main ()
+{
+return dlopen ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_dl_dlopen=yes
+else
+  ac_cv_lib_dl_dlopen=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dl_dlopen" >&5
+$as_echo "$ac_cv_lib_dl_dlopen" >&6; }
+if test "x$ac_cv_lib_dl_dlopen" = xyes; then :
+  lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-ldl"
+else
+
+    lt_cv_dlopen="dyld"
+    lt_cv_dlopen_libs=
+    lt_cv_dlopen_self=yes
+
+fi
+
+    ;;
+
+  *)
+    ac_fn_c_check_func "$LINENO" "shl_load" "ac_cv_func_shl_load"
+if test "x$ac_cv_func_shl_load" = xyes; then :
+  lt_cv_dlopen="shl_load"
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for shl_load in -ldld" >&5
+$as_echo_n "checking for shl_load in -ldld... " >&6; }
+if ${ac_cv_lib_dld_shl_load+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-ldld  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char shl_load ();
+int
+main ()
+{
+return shl_load ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_dld_shl_load=yes
+else
+  ac_cv_lib_dld_shl_load=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dld_shl_load" >&5
+$as_echo "$ac_cv_lib_dld_shl_load" >&6; }
+if test "x$ac_cv_lib_dld_shl_load" = xyes; then :
+  lt_cv_dlopen="shl_load" lt_cv_dlopen_libs="-ldld"
+else
+  ac_fn_c_check_func "$LINENO" "dlopen" "ac_cv_func_dlopen"
+if test "x$ac_cv_func_dlopen" = xyes; then :
+  lt_cv_dlopen="dlopen"
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dlopen in -ldl" >&5
+$as_echo_n "checking for dlopen in -ldl... " >&6; }
+if ${ac_cv_lib_dl_dlopen+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-ldl  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char dlopen ();
+int
+main ()
+{
+return dlopen ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_dl_dlopen=yes
+else
+  ac_cv_lib_dl_dlopen=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dl_dlopen" >&5
+$as_echo "$ac_cv_lib_dl_dlopen" >&6; }
+if test "x$ac_cv_lib_dl_dlopen" = xyes; then :
+  lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-ldl"
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dlopen in -lsvld" >&5
+$as_echo_n "checking for dlopen in -lsvld... " >&6; }
+if ${ac_cv_lib_svld_dlopen+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lsvld  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char dlopen ();
+int
+main ()
+{
+return dlopen ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_svld_dlopen=yes
+else
+  ac_cv_lib_svld_dlopen=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_svld_dlopen" >&5
+$as_echo "$ac_cv_lib_svld_dlopen" >&6; }
+if test "x$ac_cv_lib_svld_dlopen" = xyes; then :
+  lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-lsvld"
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dld_link in -ldld" >&5
+$as_echo_n "checking for dld_link in -ldld... " >&6; }
+if ${ac_cv_lib_dld_dld_link+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-ldld  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char dld_link ();
+int
+main ()
+{
+return dld_link ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_dld_dld_link=yes
+else
+  ac_cv_lib_dld_dld_link=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dld_dld_link" >&5
+$as_echo "$ac_cv_lib_dld_dld_link" >&6; }
+if test "x$ac_cv_lib_dld_dld_link" = xyes; then :
+  lt_cv_dlopen="dld_link" lt_cv_dlopen_libs="-ldld"
+fi
+
+
+fi
+
+
+fi
+
+
+fi
+
+
+fi
+
+
+fi
+
+    ;;
+  esac
+
+  if test "x$lt_cv_dlopen" != xno; then
+    enable_dlopen=yes
+  else
+    enable_dlopen=no
+  fi
+
+  case $lt_cv_dlopen in
+  dlopen)
+    save_CPPFLAGS="$CPPFLAGS"
+    test "x$ac_cv_header_dlfcn_h" = xyes && CPPFLAGS="$CPPFLAGS -DHAVE_DLFCN_H"
+
+    save_LDFLAGS="$LDFLAGS"
+    wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $export_dynamic_flag_spec\"
+
+    save_LIBS="$LIBS"
+    LIBS="$lt_cv_dlopen_libs $LIBS"
+
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether a program can dlopen itself" >&5
+$as_echo_n "checking whether a program can dlopen itself... " >&6; }
+if ${lt_cv_dlopen_self+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  	  if test "$cross_compiling" = yes; then :
+  lt_cv_dlopen_self=cross
+else
+  lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
+  lt_status=$lt_dlunknown
+  cat > conftest.$ac_ext <<_LT_EOF
+#line $LINENO "configure"
+#include "confdefs.h"
+
+#if HAVE_DLFCN_H
+#include <dlfcn.h>
+#endif
+
+#include <stdio.h>
+
+#ifdef RTLD_GLOBAL
+#  define LT_DLGLOBAL		RTLD_GLOBAL
+#else
+#  ifdef DL_GLOBAL
+#    define LT_DLGLOBAL		DL_GLOBAL
+#  else
+#    define LT_DLGLOBAL		0
+#  endif
+#endif
+
+/* We may have to define LT_DLLAZY_OR_NOW in the command line if we
+   find out it does not work in some platform. */
+#ifndef LT_DLLAZY_OR_NOW
+#  ifdef RTLD_LAZY
+#    define LT_DLLAZY_OR_NOW		RTLD_LAZY
+#  else
+#    ifdef DL_LAZY
+#      define LT_DLLAZY_OR_NOW		DL_LAZY
+#    else
+#      ifdef RTLD_NOW
+#        define LT_DLLAZY_OR_NOW	RTLD_NOW
+#      else
+#        ifdef DL_NOW
+#          define LT_DLLAZY_OR_NOW	DL_NOW
+#        else
+#          define LT_DLLAZY_OR_NOW	0
+#        endif
+#      endif
+#    endif
+#  endif
+#endif
+
+/* When -fvisbility=hidden is used, assume the code has been annotated
+   correspondingly for the symbols needed.  */
+#if defined(__GNUC__) && (((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3)) || (__GNUC__ > 3))
+int fnord () __attribute__((visibility("default")));
+#endif
+
+int fnord () { return 42; }
+int main ()
+{
+  void *self = dlopen (0, LT_DLGLOBAL|LT_DLLAZY_OR_NOW);
+  int status = $lt_dlunknown;
+
+  if (self)
+    {
+      if (dlsym (self,"fnord"))       status = $lt_dlno_uscore;
+      else
+        {
+	  if (dlsym( self,"_fnord"))  status = $lt_dlneed_uscore;
+          else puts (dlerror ());
+	}
+      /* dlclose (self); */
+    }
+  else
+    puts (dlerror ());
+
+  return status;
+}
+_LT_EOF
+  if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_link\""; } >&5
+  (eval $ac_link) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; } && test -s conftest${ac_exeext} 2>/dev/null; then
+    (./conftest; exit; ) >&5 2>/dev/null
+    lt_status=$?
+    case x$lt_status in
+      x$lt_dlno_uscore) lt_cv_dlopen_self=yes ;;
+      x$lt_dlneed_uscore) lt_cv_dlopen_self=yes ;;
+      x$lt_dlunknown|x*) lt_cv_dlopen_self=no ;;
+    esac
+  else :
+    # compilation failed
+    lt_cv_dlopen_self=no
+  fi
+fi
+rm -fr conftest*
+
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_dlopen_self" >&5
+$as_echo "$lt_cv_dlopen_self" >&6; }
+
+    if test "x$lt_cv_dlopen_self" = xyes; then
+      wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $lt_prog_compiler_static\"
+      { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether a statically linked program can dlopen itself" >&5
+$as_echo_n "checking whether a statically linked program can dlopen itself... " >&6; }
+if ${lt_cv_dlopen_self_static+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  	  if test "$cross_compiling" = yes; then :
+  lt_cv_dlopen_self_static=cross
+else
+  lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
+  lt_status=$lt_dlunknown
+  cat > conftest.$ac_ext <<_LT_EOF
+#line $LINENO "configure"
+#include "confdefs.h"
+
+#if HAVE_DLFCN_H
+#include <dlfcn.h>
+#endif
+
+#include <stdio.h>
+
+#ifdef RTLD_GLOBAL
+#  define LT_DLGLOBAL		RTLD_GLOBAL
+#else
+#  ifdef DL_GLOBAL
+#    define LT_DLGLOBAL		DL_GLOBAL
+#  else
+#    define LT_DLGLOBAL		0
+#  endif
+#endif
+
+/* We may have to define LT_DLLAZY_OR_NOW in the command line if we
+   find out it does not work in some platform. */
+#ifndef LT_DLLAZY_OR_NOW
+#  ifdef RTLD_LAZY
+#    define LT_DLLAZY_OR_NOW		RTLD_LAZY
+#  else
+#    ifdef DL_LAZY
+#      define LT_DLLAZY_OR_NOW		DL_LAZY
+#    else
+#      ifdef RTLD_NOW
+#        define LT_DLLAZY_OR_NOW	RTLD_NOW
+#      else
+#        ifdef DL_NOW
+#          define LT_DLLAZY_OR_NOW	DL_NOW
+#        else
+#          define LT_DLLAZY_OR_NOW	0
+#        endif
+#      endif
+#    endif
+#  endif
+#endif
+
+/* When -fvisbility=hidden is used, assume the code has been annotated
+   correspondingly for the symbols needed.  */
+#if defined(__GNUC__) && (((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3)) || (__GNUC__ > 3))
+int fnord () __attribute__((visibility("default")));
+#endif
+
+int fnord () { return 42; }
+int main ()
+{
+  void *self = dlopen (0, LT_DLGLOBAL|LT_DLLAZY_OR_NOW);
+  int status = $lt_dlunknown;
+
+  if (self)
+    {
+      if (dlsym (self,"fnord"))       status = $lt_dlno_uscore;
+      else
+        {
+	  if (dlsym( self,"_fnord"))  status = $lt_dlneed_uscore;
+          else puts (dlerror ());
+	}
+      /* dlclose (self); */
+    }
+  else
+    puts (dlerror ());
+
+  return status;
+}
+_LT_EOF
+  if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_link\""; } >&5
+  (eval $ac_link) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; } && test -s conftest${ac_exeext} 2>/dev/null; then
+    (./conftest; exit; ) >&5 2>/dev/null
+    lt_status=$?
+    case x$lt_status in
+      x$lt_dlno_uscore) lt_cv_dlopen_self_static=yes ;;
+      x$lt_dlneed_uscore) lt_cv_dlopen_self_static=yes ;;
+      x$lt_dlunknown|x*) lt_cv_dlopen_self_static=no ;;
+    esac
+  else :
+    # compilation failed
+    lt_cv_dlopen_self_static=no
+  fi
+fi
+rm -fr conftest*
+
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_dlopen_self_static" >&5
+$as_echo "$lt_cv_dlopen_self_static" >&6; }
+    fi
+
+    CPPFLAGS="$save_CPPFLAGS"
+    LDFLAGS="$save_LDFLAGS"
+    LIBS="$save_LIBS"
+    ;;
+  esac
+
+  case $lt_cv_dlopen_self in
+  yes|no) enable_dlopen_self=$lt_cv_dlopen_self ;;
+  *) enable_dlopen_self=unknown ;;
+  esac
+
+  case $lt_cv_dlopen_self_static in
+  yes|no) enable_dlopen_self_static=$lt_cv_dlopen_self_static ;;
+  *) enable_dlopen_self_static=unknown ;;
+  esac
+fi
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+striplib=
+old_striplib=
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether stripping libraries is possible" >&5
+$as_echo_n "checking whether stripping libraries is possible... " >&6; }
+if test -n "$STRIP" && $STRIP -V 2>&1 | $GREP "GNU strip" >/dev/null; then
+  test -z "$old_striplib" && old_striplib="$STRIP --strip-debug"
+  test -z "$striplib" && striplib="$STRIP --strip-unneeded"
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+else
+# FIXME - insert some real tests, host_os isn't really good enough
+  case $host_os in
+  darwin*)
+    if test -n "$STRIP" ; then
+      striplib="$STRIP -x"
+      old_striplib="$STRIP -S"
+      { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+    else
+      { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+    fi
+    ;;
+  *)
+    { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+    ;;
+  esac
+fi
+
+
+
+
+
+
+
+
+
+
+
+
+  # Report which library types will actually be built
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking if libtool supports shared libraries" >&5
+$as_echo_n "checking if libtool supports shared libraries... " >&6; }
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $can_build_shared" >&5
+$as_echo "$can_build_shared" >&6; }
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to build shared libraries" >&5
+$as_echo_n "checking whether to build shared libraries... " >&6; }
+  test "$can_build_shared" = "no" && enable_shared=no
+
+  # On AIX, shared libraries and static libraries use the same namespace, and
+  # are all built from PIC.
+  case $host_os in
+  aix3*)
+    test "$enable_shared" = yes && enable_static=no
+    if test -n "$RANLIB"; then
+      archive_cmds="$archive_cmds~\$RANLIB \$lib"
+      postinstall_cmds='$RANLIB $lib'
+    fi
+    ;;
+
+  aix[4-9]*)
+    if test "$host_cpu" != ia64 && test "$aix_use_runtimelinking" = no ; then
+      test "$enable_shared" = yes && enable_static=no
+    fi
+    ;;
+  esac
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $enable_shared" >&5
+$as_echo "$enable_shared" >&6; }
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to build static libraries" >&5
+$as_echo_n "checking whether to build static libraries... " >&6; }
+  # Make sure either enable_shared or enable_static is yes.
+  test "$enable_shared" = yes || enable_static=yes
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $enable_static" >&5
+$as_echo "$enable_static" >&6; }
+
+
+
+
+fi
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+CC="$lt_save_CC"
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+        ac_config_commands="$ac_config_commands libtool"
+
+
+
+
+# Only expand once:
+
+
+
+# Check whether --enable-optimization was given.
+if test "${enable_optimization+set}" = set; then :
+  enableval=$enable_optimization;
+	if (test "${enableval}" = "no"); then
+		CFLAGS="$CFLAGS -O0 -U_FORTIFY_SOURCE"
+	fi
+
+fi
+
+
+# Check whether --enable-debug was given.
+if test "${enable_debug+set}" = set; then :
+  enableval=$enable_debug;
+	if (test "${enableval}" = "yes" &&
+				test "${ac_cv_prog_cc_g}" = "yes"); then
+		CFLAGS="$CFLAGS -g"
+
+$as_echo "#define CONNMAN_DEBUG 1" >>confdefs.h
+
+	fi
+
+fi
+
+
+# Check whether --enable-pie was given.
+if test "${enable_pie+set}" = set; then :
+  enableval=$enable_pie;
+	if (test "${enableval}" = "yes" &&
+				test "${ac_cv_prog_cc_pie}" = "yes"); then
+		CFLAGS="$CFLAGS -fPIE"
+		LDFLAGS="$LDFLAGS -pie"
+	fi
+
+fi
+
+
+# Check whether --enable-hh2serial-gps was given.
+if test "${enable_hh2serial_gps+set}" = set; then :
+  enableval=$enable_hh2serial_gps; enable_hh2serial_gps=${enableval}
+else
+  enable_hh2serial_gps="no"
+fi
+
+ if test "${enable_hh2serial_gps}" != "no"; then
+  HH2SERIAL_GPS_TRUE=
+  HH2SERIAL_GPS_FALSE='#'
+else
+  HH2SERIAL_GPS_TRUE='#'
+  HH2SERIAL_GPS_FALSE=
+fi
+
+ if test "${enable_hh2serial_gps}" = "builtin"; then
+  HH2SERIAL_GPS_BUILTIN_TRUE=
+  HH2SERIAL_GPS_BUILTIN_FALSE='#'
+else
+  HH2SERIAL_GPS_BUILTIN_TRUE='#'
+  HH2SERIAL_GPS_BUILTIN_FALSE=
+fi
+
+
+
+# Check whether --with-openconnect was given.
+if test "${with_openconnect+set}" = set; then :
+  withval=$with_openconnect; path_openconnect=${withval}
+fi
+
+
+# Check whether --enable-openconnect was given.
+if test "${enable_openconnect+set}" = set; then :
+  enableval=$enable_openconnect; enable_openconnect=${enableval}
+else
+  enable_openconnect="no"
+fi
+
+if (test "${enable_openconnect}" != "no"); then
+	if (test -z "${path_openconnect}"); then
+		# Extract the first word of "openconnect", so it can be a program name with args.
+set dummy openconnect; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_OPENCONNECT+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $OPENCONNECT in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_OPENCONNECT="$OPENCONNECT" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+as_dummy="$PATH:/sbin:/usr/sbin"
+for as_dir in $as_dummy
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_OPENCONNECT="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  ;;
+esac
+fi
+OPENCONNECT=$ac_cv_path_OPENCONNECT
+if test -n "$OPENCONNECT"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $OPENCONNECT" >&5
+$as_echo "$OPENCONNECT" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+		if (test -z "${OPENCONNECT}"); then
+			as_fn_error $? "openconnect binary not found" "$LINENO" 5
+		fi
+	else
+		OPENCONNECT="${path_openconnect}"
+
+	fi
+fi
+ if test "${enable_openconnect}" != "no"; then
+  OPENCONNECT_TRUE=
+  OPENCONNECT_FALSE='#'
+else
+  OPENCONNECT_TRUE='#'
+  OPENCONNECT_FALSE=
+fi
+
+ if test "${enable_openconnect}" = "builtin"; then
+  OPENCONNECT_BUILTIN_TRUE=
+  OPENCONNECT_BUILTIN_FALSE='#'
+else
+  OPENCONNECT_BUILTIN_TRUE='#'
+  OPENCONNECT_BUILTIN_FALSE=
+fi
+
+
+
+# Check whether --with-openvpn was given.
+if test "${with_openvpn+set}" = set; then :
+  withval=$with_openvpn; path_openvpn=${withval}
+fi
+
+
+# Check whether --enable-openvpn was given.
+if test "${enable_openvpn+set}" = set; then :
+  enableval=$enable_openvpn; enable_openvpn=${enableval}
+else
+  enable_openvpn="no"
+fi
+
+if (test "${enable_openvpn}" != "no"); then
+	if (test -z "${path_openvpn}"); then
+		# Extract the first word of "openvpn", so it can be a program name with args.
+set dummy openvpn; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_OPENVPN+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $OPENVPN in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_OPENVPN="$OPENVPN" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+as_dummy="$PATH:/sbin:/usr/sbin"
+for as_dir in $as_dummy
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_OPENVPN="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  ;;
+esac
+fi
+OPENVPN=$ac_cv_path_OPENVPN
+if test -n "$OPENVPN"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $OPENVPN" >&5
+$as_echo "$OPENVPN" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+		if (test -z "${OPENVPN}"); then
+			as_fn_error $? "openvpn binary not found" "$LINENO" 5
+		fi
+	else
+		OPENVPN="${path_openvpn}"
+
+	fi
+fi
+ if test "${enable_openvpn}" != "no"; then
+  OPENVPN_TRUE=
+  OPENVPN_FALSE='#'
+else
+  OPENVPN_TRUE='#'
+  OPENVPN_FALSE=
+fi
+
+ if test "${enable_openvpn}" = "builtin"; then
+  OPENVPN_BUILTIN_TRUE=
+  OPENVPN_BUILTIN_FALSE='#'
+else
+  OPENVPN_BUILTIN_TRUE='#'
+  OPENVPN_BUILTIN_FALSE=
+fi
+
+
+
+# Check whether --with-vpnc was given.
+if test "${with_vpnc+set}" = set; then :
+  withval=$with_vpnc; path_vpnc=${withval}
+fi
+
+
+# Check whether --enable-vpnc was given.
+if test "${enable_vpnc+set}" = set; then :
+  enableval=$enable_vpnc; enable_vpnc=${enableval}
+else
+  enable_vpnc="no"
+fi
+
+if (test "${enable_vpnc}" != "no"); then
+	if (test -z "${path_vpnc}"); then
+		# Extract the first word of "vpnc", so it can be a program name with args.
+set dummy vpnc; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_VPNC+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $VPNC in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_VPNC="$VPNC" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+as_dummy="$PATH:/sbin:/usr/sbin"
+for as_dir in $as_dummy
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_VPNC="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  ;;
+esac
+fi
+VPNC=$ac_cv_path_VPNC
+if test -n "$VPNC"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $VPNC" >&5
+$as_echo "$VPNC" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+		if (test -z "${VPNC}"); then
+			as_fn_error $? "vpnc binary not found" "$LINENO" 5
+		fi
+	else
+		VPNC="${path_vpnc}"
+
+	fi
+fi
+ if test "${enable_vpnc}" != "no"; then
+  VPNC_TRUE=
+  VPNC_FALSE='#'
+else
+  VPNC_TRUE='#'
+  VPNC_FALSE=
+fi
+
+ if test "${enable_vpnc}" = "builtin"; then
+  VPNC_BUILTIN_TRUE=
+  VPNC_BUILTIN_FALSE='#'
+else
+  VPNC_BUILTIN_TRUE='#'
+  VPNC_BUILTIN_FALSE=
+fi
+
+
+
+# Check whether --with-l2tp was given.
+if test "${with_l2tp+set}" = set; then :
+  withval=$with_l2tp; path_l2tp=${withval}
+fi
+
+
+# Check whether --enable-l2tp was given.
+if test "${enable_l2tp+set}" = set; then :
+  enableval=$enable_l2tp; enable_l2tp=${enableval}
+else
+  enable_l2tp="no"
+fi
+
+if (test "${enable_l2tp}" != "no"); then
+	if (test -z "${path_pppd}"); then
+		# Extract the first word of "pppd", so it can be a program name with args.
+set dummy pppd; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_PPPD+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $PPPD in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_PPPD="$PPPD" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+as_dummy="$PATH:/sbin:/usr/sbin"
+for as_dir in $as_dummy
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_PPPD="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  test -z "$ac_cv_path_PPPD" && ac_cv_path_PPPD="/usr/sbin/pppd"
+  ;;
+esac
+fi
+PPPD=$ac_cv_path_PPPD
+if test -n "$PPPD"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $PPPD" >&5
+$as_echo "$PPPD" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+	else
+		PPPD="${path_pppd}"
+
+	fi
+	for ac_header in pppd/pppd.h
+do :
+  ac_fn_c_check_header_mongrel "$LINENO" "pppd/pppd.h" "ac_cv_header_pppd_pppd_h" "$ac_includes_default"
+if test "x$ac_cv_header_pppd_pppd_h" = xyes; then :
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_PPPD_PPPD_H 1
+_ACEOF
+ dummy=yes
+else
+  as_fn_error $? "ppp header files are required" "$LINENO" 5
+fi
+
+done
+
+	if (test -z "${path_l2tp}"); then
+		# Extract the first word of "xl2tpd", so it can be a program name with args.
+set dummy xl2tpd; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_L2TP+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $L2TP in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_L2TP="$L2TP" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+as_dummy="$PATH:/sbin:/usr/sbin"
+for as_dir in $as_dummy
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_L2TP="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  test -z "$ac_cv_path_L2TP" && ac_cv_path_L2TP="/usr/sbin/xl2tpd"
+  ;;
+esac
+fi
+L2TP=$ac_cv_path_L2TP
+if test -n "$L2TP"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $L2TP" >&5
+$as_echo "$L2TP" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+	else
+		L2TP="${path_l2tp}"
+
+	fi
+fi
+ if test "${enable_l2tp}" != "no"; then
+  L2TP_TRUE=
+  L2TP_FALSE='#'
+else
+  L2TP_TRUE='#'
+  L2TP_FALSE=
+fi
+
+ if test "${enable_l2tp}" = "builtin"; then
+  L2TP_BUILTIN_TRUE=
+  L2TP_BUILTIN_FALSE='#'
+else
+  L2TP_BUILTIN_TRUE='#'
+  L2TP_BUILTIN_FALSE=
+fi
+
+
+
+# Check whether --with-pptp was given.
+if test "${with_pptp+set}" = set; then :
+  withval=$with_pptp; path_pptp=${withval}
+fi
+
+
+# Check whether --enable-pptp was given.
+if test "${enable_pptp+set}" = set; then :
+  enableval=$enable_pptp; enable_pptp=${enableval}
+else
+  enable_pptp="no"
+fi
+
+if (test "${enable_pptp}" != "no"); then
+	if (test -z "${path_pppd}"); then
+		# Extract the first word of "pppd", so it can be a program name with args.
+set dummy pppd; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_PPPD+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $PPPD in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_PPPD="$PPPD" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+as_dummy="$PATH:/sbin:/usr/sbin"
+for as_dir in $as_dummy
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_PPPD="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  test -z "$ac_cv_path_PPPD" && ac_cv_path_PPPD="/usr/sbin/pppd"
+  ;;
+esac
+fi
+PPPD=$ac_cv_path_PPPD
+if test -n "$PPPD"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $PPPD" >&5
+$as_echo "$PPPD" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+	else
+		PPPD="${path_pppd}"
+
+	fi
+	for ac_header in pppd/pppd.h
+do :
+  ac_fn_c_check_header_mongrel "$LINENO" "pppd/pppd.h" "ac_cv_header_pppd_pppd_h" "$ac_includes_default"
+if test "x$ac_cv_header_pppd_pppd_h" = xyes; then :
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_PPPD_PPPD_H 1
+_ACEOF
+ dummy=yes
+else
+  as_fn_error $? "ppp header files are required" "$LINENO" 5
+fi
+
+done
+
+	if (test -z "${path_pptp}"); then
+		# Extract the first word of "pptp", so it can be a program name with args.
+set dummy pptp; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_PPTP+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $PPTP in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_PPTP="$PPTP" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+as_dummy="$PATH:/sbin:/usr/sbin"
+for as_dir in $as_dummy
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_PPTP="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  test -z "$ac_cv_path_PPTP" && ac_cv_path_PPTP="/usr/sbin/pptp"
+  ;;
+esac
+fi
+PPTP=$ac_cv_path_PPTP
+if test -n "$PPTP"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $PPTP" >&5
+$as_echo "$PPTP" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+	else
+		PPTP="${path_pptp}"
+
+	fi
+fi
+ if test "${enable_pptp}" != "no"; then
+  PPTP_TRUE=
+  PPTP_FALSE='#'
+else
+  PPTP_TRUE='#'
+  PPTP_FALSE=
+fi
+
+ if test "${enable_pptp}" = "builtin"; then
+  PPTP_BUILTIN_TRUE=
+  PPTP_BUILTIN_FALSE='#'
+else
+  PPTP_BUILTIN_TRUE='#'
+  PPTP_BUILTIN_FALSE=
+fi
+
+
+for ac_header in resolv.h
+do :
+  ac_fn_c_check_header_mongrel "$LINENO" "resolv.h" "ac_cv_header_resolv_h" "$ac_includes_default"
+if test "x$ac_cv_header_resolv_h" = xyes; then :
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_RESOLV_H 1
+_ACEOF
+ dummy=yes
+else
+  as_fn_error $? "resolver header files are required" "$LINENO" 5
+fi
+
+done
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ns_initparse in -lresolv" >&5
+$as_echo_n "checking for ns_initparse in -lresolv... " >&6; }
+if ${ac_cv_lib_resolv_ns_initparse+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lresolv  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char ns_initparse ();
+int
+main ()
+{
+return ns_initparse ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_resolv_ns_initparse=yes
+else
+  ac_cv_lib_resolv_ns_initparse=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_resolv_ns_initparse" >&5
+$as_echo "$ac_cv_lib_resolv_ns_initparse" >&6; }
+if test "x$ac_cv_lib_resolv_ns_initparse" = xyes; then :
+  dummy=yes
+else
+
+	{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for __ns_initparse in -lresolv" >&5
+$as_echo_n "checking for __ns_initparse in -lresolv... " >&6; }
+if ${ac_cv_lib_resolv___ns_initparse+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lresolv  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char __ns_initparse ();
+int
+main ()
+{
+return __ns_initparse ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_resolv___ns_initparse=yes
+else
+  ac_cv_lib_resolv___ns_initparse=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_resolv___ns_initparse" >&5
+$as_echo "$ac_cv_lib_resolv___ns_initparse" >&6; }
+if test "x$ac_cv_lib_resolv___ns_initparse" = xyes; then :
+  dummy=yes
+else
+  as_fn_error $? "resolver library support is required" "$LINENO" 5
+fi
+
+
+fi
+
+
+ac_fn_c_check_func "$LINENO" "signalfd" "ac_cv_func_signalfd"
+if test "x$ac_cv_func_signalfd" = xyes; then :
+  dummy=yes
+else
+  as_fn_error $? "signalfd support is required" "$LINENO" 5
+fi
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for dlopen in -ldl" >&5
+$as_echo_n "checking for dlopen in -ldl... " >&6; }
+if ${ac_cv_lib_dl_dlopen+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-ldl  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char dlopen ();
+int
+main ()
+{
+return dlopen ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_dl_dlopen=yes
+else
+  ac_cv_lib_dl_dlopen=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dl_dlopen" >&5
+$as_echo "$ac_cv_lib_dl_dlopen" >&6; }
+if test "x$ac_cv_lib_dl_dlopen" = xyes; then :
+  dummy=yes
+else
+  as_fn_error $? "dynamic linking loader is required" "$LINENO" 5
+fi
+
+
+# Check whether --enable-iospm was given.
+if test "${enable_iospm+set}" = set; then :
+  enableval=$enable_iospm; enable_iospm=${enableval}
+fi
+
+ if test "${enable_iospm}" = "yes"; then
+  IOSPM_TRUE=
+  IOSPM_FALSE='#'
+else
+  IOSPM_TRUE='#'
+  IOSPM_FALSE=
+fi
+
+
+# Check whether --enable-tist was given.
+if test "${enable_tist+set}" = set; then :
+  enableval=$enable_tist; enable_tist=${enableval}
+else
+  enable_tist="no"
+fi
+
+ if test "${enable_tist}" != "no"; then
+  TIST_TRUE=
+  TIST_FALSE='#'
+else
+  TIST_TRUE='#'
+  TIST_FALSE=
+fi
+
+ if test "${enable_tist}" = "builtin"; then
+  TIST_BUILTIN_TRUE=
+  TIST_BUILTIN_FALSE='#'
+else
+  TIST_BUILTIN_TRUE='#'
+  TIST_BUILTIN_FALSE=
+fi
+
+
+# Check whether --enable-session-policy-local was given.
+if test "${enable_session_policy_local+set}" = set; then :
+  enableval=$enable_session_policy_local; enable_session_policy_local=${enableval}
+else
+  enable_session_policy_local="no"
+fi
+
+ if test "${enable_session_policy_local}" != "no"; then
+  SESSION_POLICY_LOCAL_TRUE=
+  SESSION_POLICY_LOCAL_FALSE='#'
+else
+  SESSION_POLICY_LOCAL_TRUE='#'
+  SESSION_POLICY_LOCAL_FALSE=
+fi
+
+ if test "${enable_session_policy_local}" = "builtin"; then
+  SESSION_POLICY_LOCAL_BUILTIN_TRUE=
+  SESSION_POLICY_LOCAL_BUILTIN_FALSE='#'
+else
+  SESSION_POLICY_LOCAL_BUILTIN_TRUE='#'
+  SESSION_POLICY_LOCAL_BUILTIN_FALSE=
+fi
+
+
+
+# Check whether --with-stats-max-file-size was given.
+if test "${with_stats_max_file_size+set}" = set; then :
+  withval=$with_stats_max_file_size; stats_max_file_size=${withval}
+fi
+
+
+if (test -z "${stats_max_file_size}"); then
+   # default size is 16 kByte
+   stats_max_file_size="16 * 8 * 128"
+fi
+
+
+cat >>confdefs.h <<_ACEOF
+#define STATS_MAX_FILE_SIZE (${stats_max_file_size})
+_ACEOF
+
+
+
+pkg_failed=no
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for GLIB" >&5
+$as_echo_n "checking for GLIB... " >&6; }
+
+if test -n "$GLIB_CFLAGS"; then
+    pkg_cv_GLIB_CFLAGS="$GLIB_CFLAGS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"glib-2.0 >= 2.28\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "glib-2.0 >= 2.28") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_GLIB_CFLAGS=`$PKG_CONFIG --cflags "glib-2.0 >= 2.28" 2>/dev/null`
+		      test "x$?" != "x0" && pkg_failed=yes
+else
+  pkg_failed=yes
+fi
+ else
+    pkg_failed=untried
+fi
+if test -n "$GLIB_LIBS"; then
+    pkg_cv_GLIB_LIBS="$GLIB_LIBS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"glib-2.0 >= 2.28\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "glib-2.0 >= 2.28") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_GLIB_LIBS=`$PKG_CONFIG --libs "glib-2.0 >= 2.28" 2>/dev/null`
+		      test "x$?" != "x0" && pkg_failed=yes
+else
+  pkg_failed=yes
+fi
+ else
+    pkg_failed=untried
+fi
+
+
+
+if test $pkg_failed = yes; then
+   	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+
+if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
+        _pkg_short_errors_supported=yes
+else
+        _pkg_short_errors_supported=no
+fi
+        if test $_pkg_short_errors_supported = yes; then
+	        GLIB_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "glib-2.0 >= 2.28" 2>&1`
+        else
+	        GLIB_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "glib-2.0 >= 2.28" 2>&1`
+        fi
+	# Put the nasty error message in config.log where it belongs
+	echo "$GLIB_PKG_ERRORS" >&5
+
+	as_fn_error $? "GLib >= 2.28 is required" "$LINENO" 5
+elif test $pkg_failed = untried; then
+     	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+	as_fn_error $? "GLib >= 2.28 is required" "$LINENO" 5
+else
+	GLIB_CFLAGS=$pkg_cv_GLIB_CFLAGS
+	GLIB_LIBS=$pkg_cv_GLIB_LIBS
+        { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+	dummy=yes
+fi
+
+
+
+
+pkg_failed=no
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for DBUS" >&5
+$as_echo_n "checking for DBUS... " >&6; }
+
+if test -n "$DBUS_CFLAGS"; then
+    pkg_cv_DBUS_CFLAGS="$DBUS_CFLAGS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"dbus-1 >= 1.4\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "dbus-1 >= 1.4") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_DBUS_CFLAGS=`$PKG_CONFIG --cflags "dbus-1 >= 1.4" 2>/dev/null`
+		      test "x$?" != "x0" && pkg_failed=yes
+else
+  pkg_failed=yes
+fi
+ else
+    pkg_failed=untried
+fi
+if test -n "$DBUS_LIBS"; then
+    pkg_cv_DBUS_LIBS="$DBUS_LIBS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"dbus-1 >= 1.4\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "dbus-1 >= 1.4") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_DBUS_LIBS=`$PKG_CONFIG --libs "dbus-1 >= 1.4" 2>/dev/null`
+		      test "x$?" != "x0" && pkg_failed=yes
+else
+  pkg_failed=yes
+fi
+ else
+    pkg_failed=untried
+fi
+
+
+
+if test $pkg_failed = yes; then
+   	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+
+if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
+        _pkg_short_errors_supported=yes
+else
+        _pkg_short_errors_supported=no
+fi
+        if test $_pkg_short_errors_supported = yes; then
+	        DBUS_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "dbus-1 >= 1.4" 2>&1`
+        else
+	        DBUS_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "dbus-1 >= 1.4" 2>&1`
+        fi
+	# Put the nasty error message in config.log where it belongs
+	echo "$DBUS_PKG_ERRORS" >&5
+
+	as_fn_error $? "D-Bus >= 1.4 is required" "$LINENO" 5
+elif test $pkg_failed = untried; then
+     	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+	as_fn_error $? "D-Bus >= 1.4 is required" "$LINENO" 5
+else
+	DBUS_CFLAGS=$pkg_cv_DBUS_CFLAGS
+	DBUS_LIBS=$pkg_cv_DBUS_LIBS
+        { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+	dummy=yes
+fi
+
+
+
+
+# Check whether --with-dbusconfdir was given.
+if test "${with_dbusconfdir+set}" = set; then :
+  withval=$with_dbusconfdir; path_dbusconf=${withval}
+else
+  path_dbusconf="`$PKG_CONFIG --variable=sysconfdir dbus-1`"
+fi
+
+if (test -z "${path_dbusconf}"); then
+	DBUS_CONFDIR="${sysconfdir}/dbus-1/system.d"
+else
+	DBUS_CONFDIR="${path_dbusconf}/dbus-1/system.d"
+fi
+
+
+
+# Check whether --with-dbusdatadir was given.
+if test "${with_dbusdatadir+set}" = set; then :
+  withval=$with_dbusdatadir; path_dbusdata=${withval}
+else
+  path_dbusdata="`$PKG_CONFIG --variable=datadir dbus-1`"
+fi
+
+if (test -z "${path_dbusdata}"); then
+	DBUS_DATADIR="${datadir}/dbus-1/system-services"
+else
+	DBUS_DATADIR="${path_dbusdata}/dbus-1/system-services"
+fi
+
+
+
+# Check whether --with-systemdunitdir was given.
+if test "${with_systemdunitdir+set}" = set; then :
+  withval=$with_systemdunitdir; path_systemdunit=${withval}
+else
+  path_systemdunit="`$PKG_CONFIG --variable=systemdsystemunitdir systemd`"
+fi
+
+if (test -n "${path_systemdunit}"); then
+	SYSTEMD_UNITDIR="${path_systemdunit}"
+
+fi
+ if test -n "${path_systemdunit}"; then
+  SYSTEMD_TRUE=
+  SYSTEMD_FALSE='#'
+else
+  SYSTEMD_TRUE='#'
+  SYSTEMD_FALSE=
+fi
+
+
+
+pkg_failed=no
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for XTABLES" >&5
+$as_echo_n "checking for XTABLES... " >&6; }
+
+if test -n "$XTABLES_CFLAGS"; then
+    pkg_cv_XTABLES_CFLAGS="$XTABLES_CFLAGS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"xtables >= 1.4.11\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "xtables >= 1.4.11") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_XTABLES_CFLAGS=`$PKG_CONFIG --cflags "xtables >= 1.4.11" 2>/dev/null`
+		      test "x$?" != "x0" && pkg_failed=yes
+else
+  pkg_failed=yes
+fi
+ else
+    pkg_failed=untried
+fi
+if test -n "$XTABLES_LIBS"; then
+    pkg_cv_XTABLES_LIBS="$XTABLES_LIBS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"xtables >= 1.4.11\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "xtables >= 1.4.11") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_XTABLES_LIBS=`$PKG_CONFIG --libs "xtables >= 1.4.11" 2>/dev/null`
+		      test "x$?" != "x0" && pkg_failed=yes
+else
+  pkg_failed=yes
+fi
+ else
+    pkg_failed=untried
+fi
+
+
+
+if test $pkg_failed = yes; then
+   	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+
+if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
+        _pkg_short_errors_supported=yes
+else
+        _pkg_short_errors_supported=no
+fi
+        if test $_pkg_short_errors_supported = yes; then
+	        XTABLES_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "xtables >= 1.4.11" 2>&1`
+        else
+	        XTABLES_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "xtables >= 1.4.11" 2>&1`
+        fi
+	# Put the nasty error message in config.log where it belongs
+	echo "$XTABLES_PKG_ERRORS" >&5
+
+	as_fn_error $? "Xtables library is required" "$LINENO" 5
+elif test $pkg_failed = untried; then
+     	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+	as_fn_error $? "Xtables library is required" "$LINENO" 5
+else
+	XTABLES_CFLAGS=$pkg_cv_XTABLES_CFLAGS
+	XTABLES_LIBS=$pkg_cv_XTABLES_LIBS
+        { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+	dummy=yes
+fi
+
+
+
+# Check whether --enable-test was given.
+if test "${enable_test+set}" = set; then :
+  enableval=$enable_test; enable_test=${enableval}
+fi
+
+ if test "${enable_test}" = "yes"; then
+  TEST_TRUE=
+  TEST_FALSE='#'
+else
+  TEST_TRUE='#'
+  TEST_FALSE=
+fi
+
+
+# Check whether --enable-nmcompat was given.
+if test "${enable_nmcompat+set}" = set; then :
+  enableval=$enable_nmcompat; enable_nmcompat=${enableval}
+else
+  enable_nmcompat="no"
+fi
+
+ if test "${enable_nmcompat}" != "no"; then
+  NMCOMPAT_TRUE=
+  NMCOMPAT_FALSE='#'
+else
+  NMCOMPAT_TRUE='#'
+  NMCOMPAT_FALSE=
+fi
+
+
+# Check whether --enable-polkit was given.
+if test "${enable_polkit+set}" = set; then :
+  enableval=$enable_polkit; enable_polkit=${enableval}
+else
+  enable_polkit="no"
+fi
+
+if (test "${enable_polkit}" != "no"); then
+	POLKIT_DATADIR="`$PKG_CONFIG --variable=actiondir polkit`"
+	POLKIT_DATADIR=""
+	if (test -z "${POLKIT_DATADIR}"); then
+		POLKIT_DATADIR="${datadir}/polkit-1/actions"
+	fi
+
+fi
+ if test "${enable_polkit}" != "no"; then
+  POLKIT_TRUE=
+  POLKIT_FALSE='#'
+else
+  POLKIT_TRUE='#'
+  POLKIT_FALSE=
+fi
+
+
+# Check whether --enable-selinux was given.
+if test "${enable_selinux+set}" = set; then :
+  enableval=$enable_selinux; enable_selinux=${enableval}
+else
+  enable_selinux="no"
+fi
+
+ if test "${enable_selinux}" != "no"; then
+  SELINUX_TRUE=
+  SELINUX_FALSE='#'
+else
+  SELINUX_TRUE='#'
+  SELINUX_FALSE=
+fi
+
+
+# Check whether --enable-loopback was given.
+if test "${enable_loopback+set}" = set; then :
+  enableval=$enable_loopback; enable_loopback=${enableval}
+fi
+
+ if test "${enable_loopback}" != "no"; then
+  LOOPBACK_TRUE=
+  LOOPBACK_FALSE='#'
+else
+  LOOPBACK_TRUE='#'
+  LOOPBACK_FALSE=
+fi
+
+
+# Check whether --enable-ethernet was given.
+if test "${enable_ethernet+set}" = set; then :
+  enableval=$enable_ethernet; enable_ethernet=${enableval}
+fi
+
+ if test "${enable_ethernet}" != "no"; then
+  ETHERNET_TRUE=
+  ETHERNET_FALSE='#'
+else
+  ETHERNET_TRUE='#'
+  ETHERNET_FALSE=
+fi
+
+
+# Check whether --enable-gadget was given.
+if test "${enable_gadget+set}" = set; then :
+  enableval=$enable_gadget; enable_gadget=${enableval}
+fi
+
+ if test "${enable_gadget}" != "no"; then
+  GADGET_TRUE=
+  GADGET_FALSE='#'
+else
+  GADGET_TRUE='#'
+  GADGET_FALSE=
+fi
+
+
+# Check whether --enable-wifi was given.
+if test "${enable_wifi+set}" = set; then :
+  enableval=$enable_wifi; enable_wifi=${enableval}
+fi
+
+ if test "${enable_wifi}" != "no"; then
+  WIFI_TRUE=
+  WIFI_FALSE='#'
+else
+  WIFI_TRUE='#'
+  WIFI_FALSE=
+fi
+
+
+# Check whether --enable-bluetooth was given.
+if test "${enable_bluetooth+set}" = set; then :
+  enableval=$enable_bluetooth; enable_bluetooth=${enableval}
+fi
+
+ if test "${enable_bluetooth}" != "no"; then
+  BLUETOOTH_TRUE=
+  BLUETOOTH_FALSE='#'
+else
+  BLUETOOTH_TRUE='#'
+  BLUETOOTH_FALSE=
+fi
+
+
+# Check whether --enable-ofono was given.
+if test "${enable_ofono+set}" = set; then :
+  enableval=$enable_ofono; enable_ofono=${enableval}
+fi
+
+ if test "${enable_ofono}" != "no"; then
+  OFONO_TRUE=
+  OFONO_FALSE='#'
+else
+  OFONO_TRUE='#'
+  OFONO_FALSE=
+fi
+
+
+# Check whether --enable-dundee was given.
+if test "${enable_dundee+set}" = set; then :
+  enableval=$enable_dundee; enable_dundee=${enableval}
+fi
+
+ if test "${enable_dundee}" != "no"; then
+  DUNDEE_TRUE=
+  DUNDEE_FALSE='#'
+else
+  DUNDEE_TRUE='#'
+  DUNDEE_FALSE=
+fi
+
+
+# Check whether --enable-pacrunner was given.
+if test "${enable_pacrunner+set}" = set; then :
+  enableval=$enable_pacrunner; enable_pacrunner=${enableval}
+fi
+
+ if test "${enable_pacrunner}" != "no"; then
+  PACRUNNER_TRUE=
+  PACRUNNER_FALSE='#'
+else
+  PACRUNNER_TRUE='#'
+  PACRUNNER_FALSE=
+fi
+
+
+# Check whether --enable-neard was given.
+if test "${enable_neard+set}" = set; then :
+  enableval=$enable_neard; enable_neard=${enableval}
+fi
+
+ if test "${enable_neard}" != "no"; then
+  NEARD_TRUE=
+  NEARD_FALSE='#'
+else
+  NEARD_TRUE='#'
+  NEARD_FALSE=
+fi
+
+
+# Check whether --enable-wispr was given.
+if test "${enable_wispr+set}" = set; then :
+  enableval=$enable_wispr; enable_wispr=${enableval}
+fi
+
+ if test "${enable_wispr}" != "no"; then
+  WISPR_TRUE=
+  WISPR_FALSE='#'
+else
+  WISPR_TRUE='#'
+  WISPR_FALSE=
+fi
+
+
+# Check whether --enable-tools was given.
+if test "${enable_tools+set}" = set; then :
+  enableval=$enable_tools; enable_tools=${enableval}
+fi
+
+ if test "${enable_tools}" != "no"; then
+  TOOLS_TRUE=
+  TOOLS_FALSE='#'
+else
+  TOOLS_TRUE='#'
+  TOOLS_FALSE=
+fi
+
+
+if (test "${enable_tools}" != "no"); then
+	for ac_prog in iptables-save
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_IPTABLES_SAVE+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $IPTABLES_SAVE in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_IPTABLES_SAVE="$IPTABLES_SAVE" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+as_dummy="$PATH:/sbin:/usr/sbin"
+for as_dir in $as_dummy
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_IPTABLES_SAVE="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  ;;
+esac
+fi
+IPTABLES_SAVE=$ac_cv_path_IPTABLES_SAVE
+if test -n "$IPTABLES_SAVE"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $IPTABLES_SAVE" >&5
+$as_echo "$IPTABLES_SAVE" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+  test -n "$IPTABLES_SAVE" && break
+done
+
+	IPTABLES_SAVE=$ac_cv_path_IPTABLES_SAVE
+else
+	IPTABLES_SAVE=""
+fi
+
+
+# Check whether --enable-client was given.
+if test "${enable_client+set}" = set; then :
+  enableval=$enable_client; enable_client=${enableval}
+fi
+
+ if test "${enable_client}" != "no"; then
+  CLIENT_TRUE=
+  CLIENT_FALSE='#'
+else
+  CLIENT_TRUE='#'
+  CLIENT_FALSE=
+fi
+
+
+if (test "${enable_wispr}" != "no"); then
+
+pkg_failed=no
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for GNUTLS" >&5
+$as_echo_n "checking for GNUTLS... " >&6; }
+
+if test -n "$GNUTLS_CFLAGS"; then
+    pkg_cv_GNUTLS_CFLAGS="$GNUTLS_CFLAGS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"gnutls\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "gnutls") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_GNUTLS_CFLAGS=`$PKG_CONFIG --cflags "gnutls" 2>/dev/null`
+		      test "x$?" != "x0" && pkg_failed=yes
+else
+  pkg_failed=yes
+fi
+ else
+    pkg_failed=untried
+fi
+if test -n "$GNUTLS_LIBS"; then
+    pkg_cv_GNUTLS_LIBS="$GNUTLS_LIBS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"gnutls\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "gnutls") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_GNUTLS_LIBS=`$PKG_CONFIG --libs "gnutls" 2>/dev/null`
+		      test "x$?" != "x0" && pkg_failed=yes
+else
+  pkg_failed=yes
+fi
+ else
+    pkg_failed=untried
+fi
+
+
+
+if test $pkg_failed = yes; then
+   	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+
+if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
+        _pkg_short_errors_supported=yes
+else
+        _pkg_short_errors_supported=no
+fi
+        if test $_pkg_short_errors_supported = yes; then
+	        GNUTLS_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "gnutls" 2>&1`
+        else
+	        GNUTLS_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "gnutls" 2>&1`
+        fi
+	# Put the nasty error message in config.log where it belongs
+	echo "$GNUTLS_PKG_ERRORS" >&5
+
+	as_fn_error $? "GnuTLS library is required" "$LINENO" 5
+elif test $pkg_failed = untried; then
+     	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+	as_fn_error $? "GnuTLS library is required" "$LINENO" 5
+else
+	GNUTLS_CFLAGS=$pkg_cv_GNUTLS_CFLAGS
+	GNUTLS_LIBS=$pkg_cv_GNUTLS_LIBS
+        { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+	dummy=yes
+fi
+else
+	GNUTLS_CFLAGS=""
+	GNUTLS_LIBS=""
+fi
+
+
+
+if (test "${enable_loopback}" != "no"); then
+	for ac_header in sys/inotify.h
+do :
+  ac_fn_c_check_header_mongrel "$LINENO" "sys/inotify.h" "ac_cv_header_sys_inotify_h" "$ac_includes_default"
+if test "x$ac_cv_header_sys_inotify_h" = xyes; then :
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_SYS_INOTIFY_H 1
+_ACEOF
+ dummy=yes
+else
+  as_fn_error $? "inotify header files are required" "$LINENO" 5
+fi
+
+done
+
+
+	{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for inotify_init in -lc" >&5
+$as_echo_n "checking for inotify_init in -lc... " >&6; }
+if ${ac_cv_lib_c_inotify_init+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lc  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char inotify_init ();
+int
+main ()
+{
+return inotify_init ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_c_inotify_init=yes
+else
+  ac_cv_lib_c_inotify_init=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_c_inotify_init" >&5
+$as_echo "$ac_cv_lib_c_inotify_init" >&6; }
+if test "x$ac_cv_lib_c_inotify_init" = xyes; then :
+  dummy=yes
+else
+  as_fn_error $? "inotify library support is required" "$LINENO" 5
+fi
+
+fi
+
+if (test "${enable_wifi}" != "no"); then
+	# Extract the first word of "wpa_supplicant", so it can be a program name with args.
+set dummy wpa_supplicant; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_WPASUPPLICANT+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $WPASUPPLICANT in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_WPASUPPLICANT="$WPASUPPLICANT" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+as_dummy="$PATH:/sbin:/usr/sbin"
+for as_dir in $as_dummy
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_WPASUPPLICANT="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  ;;
+esac
+fi
+WPASUPPLICANT=$ac_cv_path_WPASUPPLICANT
+if test -n "$WPASUPPLICANT"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $WPASUPPLICANT" >&5
+$as_echo "$WPASUPPLICANT" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+
+# Check whether --enable-datafiles was given.
+if test "${enable_datafiles+set}" = set; then :
+  enableval=$enable_datafiles; enable_datafiles=${enableval}
+fi
+
+ if test "${enable_datafiles}" != "no"; then
+  DATAFILES_TRUE=
+  DATAFILES_FALSE='#'
+else
+  DATAFILES_TRUE='#'
+  DATAFILES_FALSE=
+fi
+
+
+if (test "${enable_client}" != "no"); then
+	for ac_header in readline/readline.h
+do :
+  ac_fn_c_check_header_mongrel "$LINENO" "readline/readline.h" "ac_cv_header_readline_readline_h" "$ac_includes_default"
+if test "x$ac_cv_header_readline_readline_h" = xyes; then :
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_READLINE_READLINE_H 1
+_ACEOF
+ dummy=yes
+else
+  as_fn_error $? "readline header files are required" "$LINENO" 5
+fi
+
+done
+
+fi
+
+ if test "${enable_openconnect}" != "no" -o \
+			"${enable_openvpn}" != "no" -o \
+			"${enable_vpnc}" != "no" -o \
+			"${enable_l2tp}" != "no" -o \
+			"${enable_pptp}" != "no"; then
+  VPN_TRUE=
+  VPN_FALSE='#'
+else
+  VPN_TRUE='#'
+  VPN_FALSE=
+fi
+
+
+ac_config_files="$ac_config_files Makefile include/version.h connman.pc"
+
+cat >confcache <<\_ACEOF
+# This file is a shell script that caches the results of configure
+# tests run on this system so they can be shared between configure
+# scripts and configure runs, see configure's option --config-cache.
+# It is not useful on other systems.  If it contains results you don't
+# want to keep, you may remove or edit it.
+#
+# config.status only pays attention to the cache file if you give it
+# the --recheck option to rerun configure.
+#
+# `ac_cv_env_foo' variables (set or unset) will be overridden when
+# loading this file, other *unset* `ac_cv_foo' will be assigned the
+# following values.
+
+_ACEOF
+
+# The following way of writing the cache mishandles newlines in values,
+# but we know of no workaround that is simple, portable, and efficient.
+# So, we kill variables containing newlines.
+# Ultrix sh set writes to stderr and can't be redirected directly,
+# and sets the high bit in the cache file unless we assign to the vars.
+(
+  for ac_var in `(set) 2>&1 | sed -n 's/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'`; do
+    eval ac_val=\$$ac_var
+    case $ac_val in #(
+    *${as_nl}*)
+      case $ac_var in #(
+      *_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5
+$as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;;
+      esac
+      case $ac_var in #(
+      _ | IFS | as_nl) ;; #(
+      BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #(
+      *) { eval $ac_var=; unset $ac_var;} ;;
+      esac ;;
+    esac
+  done
+
+  (set) 2>&1 |
+    case $as_nl`(ac_space=' '; set) 2>&1` in #(
+    *${as_nl}ac_space=\ *)
+      # `set' does not quote correctly, so add quotes: double-quote
+      # substitution turns \\\\ into \\, and sed turns \\ into \.
+      sed -n \
+	"s/'/'\\\\''/g;
+	  s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\\2'/p"
+      ;; #(
+    *)
+      # `set' quotes correctly as required by POSIX, so do not add quotes.
+      sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p"
+      ;;
+    esac |
+    sort
+) |
+  sed '
+     /^ac_cv_env_/b end
+     t clear
+     :clear
+     s/^\([^=]*\)=\(.*[{}].*\)$/test "${\1+set}" = set || &/
+     t end
+     s/^\([^=]*\)=\(.*\)$/\1=${\1=\2}/
+     :end' >>confcache
+if diff "$cache_file" confcache >/dev/null 2>&1; then :; else
+  if test -w "$cache_file"; then
+    if test "x$cache_file" != "x/dev/null"; then
+      { $as_echo "$as_me:${as_lineno-$LINENO}: updating cache $cache_file" >&5
+$as_echo "$as_me: updating cache $cache_file" >&6;}
+      if test ! -f "$cache_file" || test -h "$cache_file"; then
+	cat confcache >"$cache_file"
+      else
+        case $cache_file in #(
+        */* | ?:*)
+	  mv -f confcache "$cache_file"$$ &&
+	  mv -f "$cache_file"$$ "$cache_file" ;; #(
+        *)
+	  mv -f confcache "$cache_file" ;;
+	esac
+      fi
+    fi
+  else
+    { $as_echo "$as_me:${as_lineno-$LINENO}: not updating unwritable cache $cache_file" >&5
+$as_echo "$as_me: not updating unwritable cache $cache_file" >&6;}
+  fi
+fi
+rm -f confcache
+
+test "x$prefix" = xNONE && prefix=$ac_default_prefix
+# Let make expand exec_prefix.
+test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'
+
+DEFS=-DHAVE_CONFIG_H
+
+ac_libobjs=
+ac_ltlibobjs=
+U=
+for ac_i in : $LIBOBJS; do test "x$ac_i" = x: && continue
+  # 1. Remove the extension, and $U if already installed.
+  ac_script='s/\$U\././;s/\.o$//;s/\.obj$//'
+  ac_i=`$as_echo "$ac_i" | sed "$ac_script"`
+  # 2. Prepend LIBOBJDIR.  When used with automake>=1.10 LIBOBJDIR
+  #    will be set to the directory where LIBOBJS objects are built.
+  as_fn_append ac_libobjs " \${LIBOBJDIR}$ac_i\$U.$ac_objext"
+  as_fn_append ac_ltlibobjs " \${LIBOBJDIR}$ac_i"'$U.lo'
+done
+LIBOBJS=$ac_libobjs
+
+LTLIBOBJS=$ac_ltlibobjs
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking that generated files are newer than configure" >&5
+$as_echo_n "checking that generated files are newer than configure... " >&6; }
+   if test -n "$am_sleep_pid"; then
+     # Hide warnings about reused PIDs.
+     wait $am_sleep_pid 2>/dev/null
+   fi
+   { $as_echo "$as_me:${as_lineno-$LINENO}: result: done" >&5
+$as_echo "done" >&6; }
+ if test -n "$EXEEXT"; then
+  am__EXEEXT_TRUE=
+  am__EXEEXT_FALSE='#'
+else
+  am__EXEEXT_TRUE='#'
+  am__EXEEXT_FALSE=
+fi
+
+if test -z "${MAINTAINER_MODE_TRUE}" && test -z "${MAINTAINER_MODE_FALSE}"; then
+  as_fn_error $? "conditional \"MAINTAINER_MODE\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+if test -z "${AMDEP_TRUE}" && test -z "${AMDEP_FALSE}"; then
+  as_fn_error $? "conditional \"AMDEP\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+if test -z "${am__fastdepCC_TRUE}" && test -z "${am__fastdepCC_FALSE}"; then
+  as_fn_error $? "conditional \"am__fastdepCC\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+if test -z "${HH2SERIAL_GPS_TRUE}" && test -z "${HH2SERIAL_GPS_FALSE}"; then
+  as_fn_error $? "conditional \"HH2SERIAL_GPS\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+if test -z "${HH2SERIAL_GPS_BUILTIN_TRUE}" && test -z "${HH2SERIAL_GPS_BUILTIN_FALSE}"; then
+  as_fn_error $? "conditional \"HH2SERIAL_GPS_BUILTIN\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+if test -z "${OPENCONNECT_TRUE}" && test -z "${OPENCONNECT_FALSE}"; then
+  as_fn_error $? "conditional \"OPENCONNECT\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+if test -z "${OPENCONNECT_BUILTIN_TRUE}" && test -z "${OPENCONNECT_BUILTIN_FALSE}"; then
+  as_fn_error $? "conditional \"OPENCONNECT_BUILTIN\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+if test -z "${OPENVPN_TRUE}" && test -z "${OPENVPN_FALSE}"; then
+  as_fn_error $? "conditional \"OPENVPN\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+if test -z "${OPENVPN_BUILTIN_TRUE}" && test -z "${OPENVPN_BUILTIN_FALSE}"; then
+  as_fn_error $? "conditional \"OPENVPN_BUILTIN\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+if test -z "${VPNC_TRUE}" && test -z "${VPNC_FALSE}"; then
+  as_fn_error $? "conditional \"VPNC\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+if test -z "${VPNC_BUILTIN_TRUE}" && test -z "${VPNC_BUILTIN_FALSE}"; then
+  as_fn_error $? "conditional \"VPNC_BUILTIN\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+if test -z "${L2TP_TRUE}" && test -z "${L2TP_FALSE}"; then
+  as_fn_error $? "conditional \"L2TP\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+if test -z "${L2TP_BUILTIN_TRUE}" && test -z "${L2TP_BUILTIN_FALSE}"; then
+  as_fn_error $? "conditional \"L2TP_BUILTIN\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+if test -z "${PPTP_TRUE}" && test -z "${PPTP_FALSE}"; then
+  as_fn_error $? "conditional \"PPTP\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+if test -z "${PPTP_BUILTIN_TRUE}" && test -z "${PPTP_BUILTIN_FALSE}"; then
+  as_fn_error $? "conditional \"PPTP_BUILTIN\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+if test -z "${IOSPM_TRUE}" && test -z "${IOSPM_FALSE}"; then
+  as_fn_error $? "conditional \"IOSPM\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+if test -z "${TIST_TRUE}" && test -z "${TIST_FALSE}"; then
+  as_fn_error $? "conditional \"TIST\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+if test -z "${TIST_BUILTIN_TRUE}" && test -z "${TIST_BUILTIN_FALSE}"; then
+  as_fn_error $? "conditional \"TIST_BUILTIN\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+if test -z "${SESSION_POLICY_LOCAL_TRUE}" && test -z "${SESSION_POLICY_LOCAL_FALSE}"; then
+  as_fn_error $? "conditional \"SESSION_POLICY_LOCAL\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+if test -z "${SESSION_POLICY_LOCAL_BUILTIN_TRUE}" && test -z "${SESSION_POLICY_LOCAL_BUILTIN_FALSE}"; then
+  as_fn_error $? "conditional \"SESSION_POLICY_LOCAL_BUILTIN\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+if test -z "${SYSTEMD_TRUE}" && test -z "${SYSTEMD_FALSE}"; then
+  as_fn_error $? "conditional \"SYSTEMD\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+if test -z "${TEST_TRUE}" && test -z "${TEST_FALSE}"; then
+  as_fn_error $? "conditional \"TEST\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+if test -z "${NMCOMPAT_TRUE}" && test -z "${NMCOMPAT_FALSE}"; then
+  as_fn_error $? "conditional \"NMCOMPAT\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+if test -z "${POLKIT_TRUE}" && test -z "${POLKIT_FALSE}"; then
+  as_fn_error $? "conditional \"POLKIT\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+if test -z "${SELINUX_TRUE}" && test -z "${SELINUX_FALSE}"; then
+  as_fn_error $? "conditional \"SELINUX\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+if test -z "${LOOPBACK_TRUE}" && test -z "${LOOPBACK_FALSE}"; then
+  as_fn_error $? "conditional \"LOOPBACK\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+if test -z "${ETHERNET_TRUE}" && test -z "${ETHERNET_FALSE}"; then
+  as_fn_error $? "conditional \"ETHERNET\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+if test -z "${GADGET_TRUE}" && test -z "${GADGET_FALSE}"; then
+  as_fn_error $? "conditional \"GADGET\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+if test -z "${WIFI_TRUE}" && test -z "${WIFI_FALSE}"; then
+  as_fn_error $? "conditional \"WIFI\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+if test -z "${BLUETOOTH_TRUE}" && test -z "${BLUETOOTH_FALSE}"; then
+  as_fn_error $? "conditional \"BLUETOOTH\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+if test -z "${OFONO_TRUE}" && test -z "${OFONO_FALSE}"; then
+  as_fn_error $? "conditional \"OFONO\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+if test -z "${DUNDEE_TRUE}" && test -z "${DUNDEE_FALSE}"; then
+  as_fn_error $? "conditional \"DUNDEE\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+if test -z "${PACRUNNER_TRUE}" && test -z "${PACRUNNER_FALSE}"; then
+  as_fn_error $? "conditional \"PACRUNNER\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+if test -z "${NEARD_TRUE}" && test -z "${NEARD_FALSE}"; then
+  as_fn_error $? "conditional \"NEARD\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+if test -z "${WISPR_TRUE}" && test -z "${WISPR_FALSE}"; then
+  as_fn_error $? "conditional \"WISPR\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+if test -z "${TOOLS_TRUE}" && test -z "${TOOLS_FALSE}"; then
+  as_fn_error $? "conditional \"TOOLS\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+if test -z "${CLIENT_TRUE}" && test -z "${CLIENT_FALSE}"; then
+  as_fn_error $? "conditional \"CLIENT\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+if test -z "${DATAFILES_TRUE}" && test -z "${DATAFILES_FALSE}"; then
+  as_fn_error $? "conditional \"DATAFILES\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+if test -z "${VPN_TRUE}" && test -z "${VPN_FALSE}"; then
+  as_fn_error $? "conditional \"VPN\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+
+: "${CONFIG_STATUS=./config.status}"
+ac_write_fail=0
+ac_clean_files_save=$ac_clean_files
+ac_clean_files="$ac_clean_files $CONFIG_STATUS"
+{ $as_echo "$as_me:${as_lineno-$LINENO}: creating $CONFIG_STATUS" >&5
+$as_echo "$as_me: creating $CONFIG_STATUS" >&6;}
+as_write_fail=0
+cat >$CONFIG_STATUS <<_ASEOF || as_write_fail=1
+#! $SHELL
+# Generated by $as_me.
+# Run this file to recreate the current configuration.
+# Compiler output produced by configure, useful for debugging
+# configure, is in config.log if it exists.
+
+debug=false
+ac_cs_recheck=false
+ac_cs_silent=false
+
+SHELL=\${CONFIG_SHELL-$SHELL}
+export SHELL
+_ASEOF
+cat >>$CONFIG_STATUS <<\_ASEOF || as_write_fail=1
+## -------------------- ##
+## M4sh Initialization. ##
+## -------------------- ##
+
+# Be more Bourne compatible
+DUALCASE=1; export DUALCASE # for MKS sh
+if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then :
+  emulate sh
+  NULLCMD=:
+  # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
+  # is contrary to our usage.  Disable this feature.
+  alias -g '${1+"$@"}'='"$@"'
+  setopt NO_GLOB_SUBST
+else
+  case `(set -o) 2>/dev/null` in #(
+  *posix*) :
+    set -o posix ;; #(
+  *) :
+     ;;
+esac
+fi
+
+
+as_nl='
+'
+export as_nl
+# Printing a long string crashes Solaris 7 /usr/bin/printf.
+as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'
+as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo
+as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo
+# Prefer a ksh shell builtin over an external printf program on Solaris,
+# but without wasting forks for bash or zsh.
+if test -z "$BASH_VERSION$ZSH_VERSION" \
+    && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then
+  as_echo='print -r --'
+  as_echo_n='print -rn --'
+elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then
+  as_echo='printf %s\n'
+  as_echo_n='printf %s'
+else
+  if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then
+    as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"'
+    as_echo_n='/usr/ucb/echo -n'
+  else
+    as_echo_body='eval expr "X$1" : "X\\(.*\\)"'
+    as_echo_n_body='eval
+      arg=$1;
+      case $arg in #(
+      *"$as_nl"*)
+	expr "X$arg" : "X\\(.*\\)$as_nl";
+	arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;;
+      esac;
+      expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl"
+    '
+    export as_echo_n_body
+    as_echo_n='sh -c $as_echo_n_body as_echo'
+  fi
+  export as_echo_body
+  as_echo='sh -c $as_echo_body as_echo'
+fi
+
+# The user is always right.
+if test "${PATH_SEPARATOR+set}" != set; then
+  PATH_SEPARATOR=:
+  (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && {
+    (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 ||
+      PATH_SEPARATOR=';'
+  }
+fi
+
+
+# IFS
+# We need space, tab and new line, in precisely that order.  Quoting is
+# there to prevent editors from complaining about space-tab.
+# (If _AS_PATH_WALK were called with IFS unset, it would disable word
+# splitting by setting IFS to empty value.)
+IFS=" ""	$as_nl"
+
+# Find who we are.  Look in the path if we contain no directory separator.
+as_myself=
+case $0 in #((
+  *[\\/]* ) as_myself=$0 ;;
+  *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break
+  done
+IFS=$as_save_IFS
+
+     ;;
+esac
+# We did not find ourselves, most probably we were run as `sh COMMAND'
+# in which case we are not to be found in the path.
+if test "x$as_myself" = x; then
+  as_myself=$0
+fi
+if test ! -f "$as_myself"; then
+  $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2
+  exit 1
+fi
+
+# Unset variables that we do not need and which cause bugs (e.g. in
+# pre-3.0 UWIN ksh).  But do not cause bugs in bash 2.01; the "|| exit 1"
+# suppresses any "Segmentation fault" message there.  '((' could
+# trigger a bug in pdksh 5.2.14.
+for as_var in BASH_ENV ENV MAIL MAILPATH
+do eval test x\${$as_var+set} = xset \
+  && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || :
+done
+PS1='$ '
+PS2='> '
+PS4='+ '
+
+# NLS nuisances.
+LC_ALL=C
+export LC_ALL
+LANGUAGE=C
+export LANGUAGE
+
+# CDPATH.
+(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
+
+
+# as_fn_error STATUS ERROR [LINENO LOG_FD]
+# ----------------------------------------
+# Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are
+# provided, also output the error to LOG_FD, referencing LINENO. Then exit the
+# script with STATUS, using 1 if that was 0.
+as_fn_error ()
+{
+  as_status=$1; test $as_status -eq 0 && as_status=1
+  if test "$4"; then
+    as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+    $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4
+  fi
+  $as_echo "$as_me: error: $2" >&2
+  as_fn_exit $as_status
+} # as_fn_error
+
+
+# as_fn_set_status STATUS
+# -----------------------
+# Set $? to STATUS, without forking.
+as_fn_set_status ()
+{
+  return $1
+} # as_fn_set_status
+
+# as_fn_exit STATUS
+# -----------------
+# Exit the shell with STATUS, even in a "trap 0" or "set -e" context.
+as_fn_exit ()
+{
+  set +e
+  as_fn_set_status $1
+  exit $1
+} # as_fn_exit
+
+# as_fn_unset VAR
+# ---------------
+# Portably unset VAR.
+as_fn_unset ()
+{
+  { eval $1=; unset $1;}
+}
+as_unset=as_fn_unset
+# as_fn_append VAR VALUE
+# ----------------------
+# Append the text in VALUE to the end of the definition contained in VAR. Take
+# advantage of any shell optimizations that allow amortized linear growth over
+# repeated appends, instead of the typical quadratic growth present in naive
+# implementations.
+if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then :
+  eval 'as_fn_append ()
+  {
+    eval $1+=\$2
+  }'
+else
+  as_fn_append ()
+  {
+    eval $1=\$$1\$2
+  }
+fi # as_fn_append
+
+# as_fn_arith ARG...
+# ------------------
+# Perform arithmetic evaluation on the ARGs, and store the result in the
+# global $as_val. Take advantage of shells that can avoid forks. The arguments
+# must be portable across $(()) and expr.
+if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then :
+  eval 'as_fn_arith ()
+  {
+    as_val=$(( $* ))
+  }'
+else
+  as_fn_arith ()
+  {
+    as_val=`expr "$@" || test $? -eq 1`
+  }
+fi # as_fn_arith
+
+
+if expr a : '\(a\)' >/dev/null 2>&1 &&
+   test "X`expr 00001 : '.*\(...\)'`" = X001; then
+  as_expr=expr
+else
+  as_expr=false
+fi
+
+if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then
+  as_basename=basename
+else
+  as_basename=false
+fi
+
+if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then
+  as_dirname=dirname
+else
+  as_dirname=false
+fi
+
+as_me=`$as_basename -- "$0" ||
+$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \
+	 X"$0" : 'X\(//\)$' \| \
+	 X"$0" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X/"$0" |
+    sed '/^.*\/\([^/][^/]*\)\/*$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\/\(\/\/\)$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\/\(\/\).*/{
+	    s//\1/
+	    q
+	  }
+	  s/.*/./; q'`
+
+# Avoid depending upon Character Ranges.
+as_cr_letters='abcdefghijklmnopqrstuvwxyz'
+as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
+as_cr_Letters=$as_cr_letters$as_cr_LETTERS
+as_cr_digits='0123456789'
+as_cr_alnum=$as_cr_Letters$as_cr_digits
+
+ECHO_C= ECHO_N= ECHO_T=
+case `echo -n x` in #(((((
+-n*)
+  case `echo 'xy\c'` in
+  *c*) ECHO_T='	';;	# ECHO_T is single tab character.
+  xy)  ECHO_C='\c';;
+  *)   echo `echo ksh88 bug on AIX 6.1` > /dev/null
+       ECHO_T='	';;
+  esac;;
+*)
+  ECHO_N='-n';;
+esac
+
+rm -f conf$$ conf$$.exe conf$$.file
+if test -d conf$$.dir; then
+  rm -f conf$$.dir/conf$$.file
+else
+  rm -f conf$$.dir
+  mkdir conf$$.dir 2>/dev/null
+fi
+if (echo >conf$$.file) 2>/dev/null; then
+  if ln -s conf$$.file conf$$ 2>/dev/null; then
+    as_ln_s='ln -s'
+    # ... but there are two gotchas:
+    # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail.
+    # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable.
+    # In both cases, we have to default to `cp -pR'.
+    ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe ||
+      as_ln_s='cp -pR'
+  elif ln conf$$.file conf$$ 2>/dev/null; then
+    as_ln_s=ln
+  else
+    as_ln_s='cp -pR'
+  fi
+else
+  as_ln_s='cp -pR'
+fi
+rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file
+rmdir conf$$.dir 2>/dev/null
+
+
+# as_fn_mkdir_p
+# -------------
+# Create "$as_dir" as a directory, including parents if necessary.
+as_fn_mkdir_p ()
+{
+
+  case $as_dir in #(
+  -*) as_dir=./$as_dir;;
+  esac
+  test -d "$as_dir" || eval $as_mkdir_p || {
+    as_dirs=
+    while :; do
+      case $as_dir in #(
+      *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'(
+      *) as_qdir=$as_dir;;
+      esac
+      as_dirs="'$as_qdir' $as_dirs"
+      as_dir=`$as_dirname -- "$as_dir" ||
+$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+	 X"$as_dir" : 'X\(//\)[^/]' \| \
+	 X"$as_dir" : 'X\(//\)$' \| \
+	 X"$as_dir" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X"$as_dir" |
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)[^/].*/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\).*/{
+	    s//\1/
+	    q
+	  }
+	  s/.*/./; q'`
+      test -d "$as_dir" && break
+    done
+    test -z "$as_dirs" || eval "mkdir $as_dirs"
+  } || test -d "$as_dir" || as_fn_error $? "cannot create directory $as_dir"
+
+
+} # as_fn_mkdir_p
+if mkdir -p . 2>/dev/null; then
+  as_mkdir_p='mkdir -p "$as_dir"'
+else
+  test -d ./-p && rmdir ./-p
+  as_mkdir_p=false
+fi
+
+
+# as_fn_executable_p FILE
+# -----------------------
+# Test if FILE is an executable regular file.
+as_fn_executable_p ()
+{
+  test -f "$1" && test -x "$1"
+} # as_fn_executable_p
+as_test_x='test -x'
+as_executable_p=as_fn_executable_p
+
+# Sed expression to map a string onto a valid CPP name.
+as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'"
+
+# Sed expression to map a string onto a valid variable name.
+as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'"
+
+
+exec 6>&1
+## ----------------------------------- ##
+## Main body of $CONFIG_STATUS script. ##
+## ----------------------------------- ##
+_ASEOF
+test $as_write_fail = 0 && chmod +x $CONFIG_STATUS || ac_write_fail=1
+
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+# Save the log message, to keep $0 and so on meaningful, and to
+# report actual input values of CONFIG_FILES etc. instead of their
+# values after options handling.
+ac_log="
+This file was extended by connman $as_me 1.29, which was
+generated by GNU Autoconf 2.69.  Invocation command line was
+
+  CONFIG_FILES    = $CONFIG_FILES
+  CONFIG_HEADERS  = $CONFIG_HEADERS
+  CONFIG_LINKS    = $CONFIG_LINKS
+  CONFIG_COMMANDS = $CONFIG_COMMANDS
+  $ $0 $@
+
+on `(hostname || uname -n) 2>/dev/null | sed 1q`
+"
+
+_ACEOF
+
+case $ac_config_files in *"
+"*) set x $ac_config_files; shift; ac_config_files=$*;;
+esac
+
+case $ac_config_headers in *"
+"*) set x $ac_config_headers; shift; ac_config_headers=$*;;
+esac
+
+
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+# Files that config.status was made for.
+config_files="$ac_config_files"
+config_headers="$ac_config_headers"
+config_commands="$ac_config_commands"
+
+_ACEOF
+
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+ac_cs_usage="\
+\`$as_me' instantiates files and other configuration actions
+from templates according to the current configuration.  Unless the files
+and actions are specified as TAGs, all are instantiated by default.
+
+Usage: $0 [OPTION]... [TAG]...
+
+  -h, --help       print this help, then exit
+  -V, --version    print version number and configuration settings, then exit
+      --config     print configuration, then exit
+  -q, --quiet, --silent
+                   do not print progress messages
+  -d, --debug      don't remove temporary files
+      --recheck    update $as_me by reconfiguring in the same conditions
+      --file=FILE[:TEMPLATE]
+                   instantiate the configuration file FILE
+      --header=FILE[:TEMPLATE]
+                   instantiate the configuration header FILE
+
+Configuration files:
+$config_files
+
+Configuration headers:
+$config_headers
+
+Configuration commands:
+$config_commands
+
+Report bugs to the package provider."
+
+_ACEOF
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
+ac_cs_version="\\
+connman config.status 1.29
+configured by $0, generated by GNU Autoconf 2.69,
+  with options \\"\$ac_cs_config\\"
+
+Copyright (C) 2012 Free Software Foundation, Inc.
+This config.status script is free software; the Free Software Foundation
+gives unlimited permission to copy, distribute and modify it."
+
+ac_pwd='$ac_pwd'
+srcdir='$srcdir'
+INSTALL='$INSTALL'
+MKDIR_P='$MKDIR_P'
+AWK='$AWK'
+test -n "\$AWK" || AWK=awk
+_ACEOF
+
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+# The default lists apply if the user does not specify any file.
+ac_need_defaults=:
+while test $# != 0
+do
+  case $1 in
+  --*=?*)
+    ac_option=`expr "X$1" : 'X\([^=]*\)='`
+    ac_optarg=`expr "X$1" : 'X[^=]*=\(.*\)'`
+    ac_shift=:
+    ;;
+  --*=)
+    ac_option=`expr "X$1" : 'X\([^=]*\)='`
+    ac_optarg=
+    ac_shift=:
+    ;;
+  *)
+    ac_option=$1
+    ac_optarg=$2
+    ac_shift=shift
+    ;;
+  esac
+
+  case $ac_option in
+  # Handling of the options.
+  -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r)
+    ac_cs_recheck=: ;;
+  --version | --versio | --versi | --vers | --ver | --ve | --v | -V )
+    $as_echo "$ac_cs_version"; exit ;;
+  --config | --confi | --conf | --con | --co | --c )
+    $as_echo "$ac_cs_config"; exit ;;
+  --debug | --debu | --deb | --de | --d | -d )
+    debug=: ;;
+  --file | --fil | --fi | --f )
+    $ac_shift
+    case $ac_optarg in
+    *\'*) ac_optarg=`$as_echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;;
+    '') as_fn_error $? "missing file argument" ;;
+    esac
+    as_fn_append CONFIG_FILES " '$ac_optarg'"
+    ac_need_defaults=false;;
+  --header | --heade | --head | --hea )
+    $ac_shift
+    case $ac_optarg in
+    *\'*) ac_optarg=`$as_echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;;
+    esac
+    as_fn_append CONFIG_HEADERS " '$ac_optarg'"
+    ac_need_defaults=false;;
+  --he | --h)
+    # Conflict between --help and --header
+    as_fn_error $? "ambiguous option: \`$1'
+Try \`$0 --help' for more information.";;
+  --help | --hel | -h )
+    $as_echo "$ac_cs_usage"; exit ;;
+  -q | -quiet | --quiet | --quie | --qui | --qu | --q \
+  | -silent | --silent | --silen | --sile | --sil | --si | --s)
+    ac_cs_silent=: ;;
+
+  # This is an error.
+  -*) as_fn_error $? "unrecognized option: \`$1'
+Try \`$0 --help' for more information." ;;
+
+  *) as_fn_append ac_config_targets " $1"
+     ac_need_defaults=false ;;
+
+  esac
+  shift
+done
+
+ac_configure_extra_args=
+
+if $ac_cs_silent; then
+  exec 6>/dev/null
+  ac_configure_extra_args="$ac_configure_extra_args --silent"
+fi
+
+_ACEOF
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+if \$ac_cs_recheck; then
+  set X $SHELL '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion
+  shift
+  \$as_echo "running CONFIG_SHELL=$SHELL \$*" >&6
+  CONFIG_SHELL='$SHELL'
+  export CONFIG_SHELL
+  exec "\$@"
+fi
+
+_ACEOF
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+exec 5>>config.log
+{
+  echo
+  sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX
+## Running $as_me. ##
+_ASBOX
+  $as_echo "$ac_log"
+} >&5
+
+_ACEOF
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+#
+# INIT-COMMANDS
+#
+AMDEP_TRUE="$AMDEP_TRUE" ac_aux_dir="$ac_aux_dir"
+
+
+# The HP-UX ksh and POSIX shell print the target directory to stdout
+# if CDPATH is set.
+(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
+
+sed_quote_subst='$sed_quote_subst'
+double_quote_subst='$double_quote_subst'
+delay_variable_subst='$delay_variable_subst'
+enable_static='`$ECHO "$enable_static" | $SED "$delay_single_quote_subst"`'
+macro_version='`$ECHO "$macro_version" | $SED "$delay_single_quote_subst"`'
+macro_revision='`$ECHO "$macro_revision" | $SED "$delay_single_quote_subst"`'
+enable_shared='`$ECHO "$enable_shared" | $SED "$delay_single_quote_subst"`'
+pic_mode='`$ECHO "$pic_mode" | $SED "$delay_single_quote_subst"`'
+enable_fast_install='`$ECHO "$enable_fast_install" | $SED "$delay_single_quote_subst"`'
+SHELL='`$ECHO "$SHELL" | $SED "$delay_single_quote_subst"`'
+ECHO='`$ECHO "$ECHO" | $SED "$delay_single_quote_subst"`'
+PATH_SEPARATOR='`$ECHO "$PATH_SEPARATOR" | $SED "$delay_single_quote_subst"`'
+host_alias='`$ECHO "$host_alias" | $SED "$delay_single_quote_subst"`'
+host='`$ECHO "$host" | $SED "$delay_single_quote_subst"`'
+host_os='`$ECHO "$host_os" | $SED "$delay_single_quote_subst"`'
+build_alias='`$ECHO "$build_alias" | $SED "$delay_single_quote_subst"`'
+build='`$ECHO "$build" | $SED "$delay_single_quote_subst"`'
+build_os='`$ECHO "$build_os" | $SED "$delay_single_quote_subst"`'
+SED='`$ECHO "$SED" | $SED "$delay_single_quote_subst"`'
+Xsed='`$ECHO "$Xsed" | $SED "$delay_single_quote_subst"`'
+GREP='`$ECHO "$GREP" | $SED "$delay_single_quote_subst"`'
+EGREP='`$ECHO "$EGREP" | $SED "$delay_single_quote_subst"`'
+FGREP='`$ECHO "$FGREP" | $SED "$delay_single_quote_subst"`'
+LD='`$ECHO "$LD" | $SED "$delay_single_quote_subst"`'
+NM='`$ECHO "$NM" | $SED "$delay_single_quote_subst"`'
+LN_S='`$ECHO "$LN_S" | $SED "$delay_single_quote_subst"`'
+max_cmd_len='`$ECHO "$max_cmd_len" | $SED "$delay_single_quote_subst"`'
+ac_objext='`$ECHO "$ac_objext" | $SED "$delay_single_quote_subst"`'
+exeext='`$ECHO "$exeext" | $SED "$delay_single_quote_subst"`'
+lt_unset='`$ECHO "$lt_unset" | $SED "$delay_single_quote_subst"`'
+lt_SP2NL='`$ECHO "$lt_SP2NL" | $SED "$delay_single_quote_subst"`'
+lt_NL2SP='`$ECHO "$lt_NL2SP" | $SED "$delay_single_quote_subst"`'
+lt_cv_to_host_file_cmd='`$ECHO "$lt_cv_to_host_file_cmd" | $SED "$delay_single_quote_subst"`'
+lt_cv_to_tool_file_cmd='`$ECHO "$lt_cv_to_tool_file_cmd" | $SED "$delay_single_quote_subst"`'
+reload_flag='`$ECHO "$reload_flag" | $SED "$delay_single_quote_subst"`'
+reload_cmds='`$ECHO "$reload_cmds" | $SED "$delay_single_quote_subst"`'
+OBJDUMP='`$ECHO "$OBJDUMP" | $SED "$delay_single_quote_subst"`'
+deplibs_check_method='`$ECHO "$deplibs_check_method" | $SED "$delay_single_quote_subst"`'
+file_magic_cmd='`$ECHO "$file_magic_cmd" | $SED "$delay_single_quote_subst"`'
+file_magic_glob='`$ECHO "$file_magic_glob" | $SED "$delay_single_quote_subst"`'
+want_nocaseglob='`$ECHO "$want_nocaseglob" | $SED "$delay_single_quote_subst"`'
+DLLTOOL='`$ECHO "$DLLTOOL" | $SED "$delay_single_quote_subst"`'
+sharedlib_from_linklib_cmd='`$ECHO "$sharedlib_from_linklib_cmd" | $SED "$delay_single_quote_subst"`'
+AR='`$ECHO "$AR" | $SED "$delay_single_quote_subst"`'
+AR_FLAGS='`$ECHO "$AR_FLAGS" | $SED "$delay_single_quote_subst"`'
+archiver_list_spec='`$ECHO "$archiver_list_spec" | $SED "$delay_single_quote_subst"`'
+STRIP='`$ECHO "$STRIP" | $SED "$delay_single_quote_subst"`'
+RANLIB='`$ECHO "$RANLIB" | $SED "$delay_single_quote_subst"`'
+old_postinstall_cmds='`$ECHO "$old_postinstall_cmds" | $SED "$delay_single_quote_subst"`'
+old_postuninstall_cmds='`$ECHO "$old_postuninstall_cmds" | $SED "$delay_single_quote_subst"`'
+old_archive_cmds='`$ECHO "$old_archive_cmds" | $SED "$delay_single_quote_subst"`'
+lock_old_archive_extraction='`$ECHO "$lock_old_archive_extraction" | $SED "$delay_single_quote_subst"`'
+CC='`$ECHO "$CC" | $SED "$delay_single_quote_subst"`'
+CFLAGS='`$ECHO "$CFLAGS" | $SED "$delay_single_quote_subst"`'
+compiler='`$ECHO "$compiler" | $SED "$delay_single_quote_subst"`'
+GCC='`$ECHO "$GCC" | $SED "$delay_single_quote_subst"`'
+lt_cv_sys_global_symbol_pipe='`$ECHO "$lt_cv_sys_global_symbol_pipe" | $SED "$delay_single_quote_subst"`'
+lt_cv_sys_global_symbol_to_cdecl='`$ECHO "$lt_cv_sys_global_symbol_to_cdecl" | $SED "$delay_single_quote_subst"`'
+lt_cv_sys_global_symbol_to_c_name_address='`$ECHO "$lt_cv_sys_global_symbol_to_c_name_address" | $SED "$delay_single_quote_subst"`'
+lt_cv_sys_global_symbol_to_c_name_address_lib_prefix='`$ECHO "$lt_cv_sys_global_symbol_to_c_name_address_lib_prefix" | $SED "$delay_single_quote_subst"`'
+nm_file_list_spec='`$ECHO "$nm_file_list_spec" | $SED "$delay_single_quote_subst"`'
+lt_sysroot='`$ECHO "$lt_sysroot" | $SED "$delay_single_quote_subst"`'
+objdir='`$ECHO "$objdir" | $SED "$delay_single_quote_subst"`'
+MAGIC_CMD='`$ECHO "$MAGIC_CMD" | $SED "$delay_single_quote_subst"`'
+lt_prog_compiler_no_builtin_flag='`$ECHO "$lt_prog_compiler_no_builtin_flag" | $SED "$delay_single_quote_subst"`'
+lt_prog_compiler_pic='`$ECHO "$lt_prog_compiler_pic" | $SED "$delay_single_quote_subst"`'
+lt_prog_compiler_wl='`$ECHO "$lt_prog_compiler_wl" | $SED "$delay_single_quote_subst"`'
+lt_prog_compiler_static='`$ECHO "$lt_prog_compiler_static" | $SED "$delay_single_quote_subst"`'
+lt_cv_prog_compiler_c_o='`$ECHO "$lt_cv_prog_compiler_c_o" | $SED "$delay_single_quote_subst"`'
+need_locks='`$ECHO "$need_locks" | $SED "$delay_single_quote_subst"`'
+MANIFEST_TOOL='`$ECHO "$MANIFEST_TOOL" | $SED "$delay_single_quote_subst"`'
+DSYMUTIL='`$ECHO "$DSYMUTIL" | $SED "$delay_single_quote_subst"`'
+NMEDIT='`$ECHO "$NMEDIT" | $SED "$delay_single_quote_subst"`'
+LIPO='`$ECHO "$LIPO" | $SED "$delay_single_quote_subst"`'
+OTOOL='`$ECHO "$OTOOL" | $SED "$delay_single_quote_subst"`'
+OTOOL64='`$ECHO "$OTOOL64" | $SED "$delay_single_quote_subst"`'
+libext='`$ECHO "$libext" | $SED "$delay_single_quote_subst"`'
+shrext_cmds='`$ECHO "$shrext_cmds" | $SED "$delay_single_quote_subst"`'
+extract_expsyms_cmds='`$ECHO "$extract_expsyms_cmds" | $SED "$delay_single_quote_subst"`'
+archive_cmds_need_lc='`$ECHO "$archive_cmds_need_lc" | $SED "$delay_single_quote_subst"`'
+enable_shared_with_static_runtimes='`$ECHO "$enable_shared_with_static_runtimes" | $SED "$delay_single_quote_subst"`'
+export_dynamic_flag_spec='`$ECHO "$export_dynamic_flag_spec" | $SED "$delay_single_quote_subst"`'
+whole_archive_flag_spec='`$ECHO "$whole_archive_flag_spec" | $SED "$delay_single_quote_subst"`'
+compiler_needs_object='`$ECHO "$compiler_needs_object" | $SED "$delay_single_quote_subst"`'
+old_archive_from_new_cmds='`$ECHO "$old_archive_from_new_cmds" | $SED "$delay_single_quote_subst"`'
+old_archive_from_expsyms_cmds='`$ECHO "$old_archive_from_expsyms_cmds" | $SED "$delay_single_quote_subst"`'
+archive_cmds='`$ECHO "$archive_cmds" | $SED "$delay_single_quote_subst"`'
+archive_expsym_cmds='`$ECHO "$archive_expsym_cmds" | $SED "$delay_single_quote_subst"`'
+module_cmds='`$ECHO "$module_cmds" | $SED "$delay_single_quote_subst"`'
+module_expsym_cmds='`$ECHO "$module_expsym_cmds" | $SED "$delay_single_quote_subst"`'
+with_gnu_ld='`$ECHO "$with_gnu_ld" | $SED "$delay_single_quote_subst"`'
+allow_undefined_flag='`$ECHO "$allow_undefined_flag" | $SED "$delay_single_quote_subst"`'
+no_undefined_flag='`$ECHO "$no_undefined_flag" | $SED "$delay_single_quote_subst"`'
+hardcode_libdir_flag_spec='`$ECHO "$hardcode_libdir_flag_spec" | $SED "$delay_single_quote_subst"`'
+hardcode_libdir_separator='`$ECHO "$hardcode_libdir_separator" | $SED "$delay_single_quote_subst"`'
+hardcode_direct='`$ECHO "$hardcode_direct" | $SED "$delay_single_quote_subst"`'
+hardcode_direct_absolute='`$ECHO "$hardcode_direct_absolute" | $SED "$delay_single_quote_subst"`'
+hardcode_minus_L='`$ECHO "$hardcode_minus_L" | $SED "$delay_single_quote_subst"`'
+hardcode_shlibpath_var='`$ECHO "$hardcode_shlibpath_var" | $SED "$delay_single_quote_subst"`'
+hardcode_automatic='`$ECHO "$hardcode_automatic" | $SED "$delay_single_quote_subst"`'
+inherit_rpath='`$ECHO "$inherit_rpath" | $SED "$delay_single_quote_subst"`'
+link_all_deplibs='`$ECHO "$link_all_deplibs" | $SED "$delay_single_quote_subst"`'
+always_export_symbols='`$ECHO "$always_export_symbols" | $SED "$delay_single_quote_subst"`'
+export_symbols_cmds='`$ECHO "$export_symbols_cmds" | $SED "$delay_single_quote_subst"`'
+exclude_expsyms='`$ECHO "$exclude_expsyms" | $SED "$delay_single_quote_subst"`'
+include_expsyms='`$ECHO "$include_expsyms" | $SED "$delay_single_quote_subst"`'
+prelink_cmds='`$ECHO "$prelink_cmds" | $SED "$delay_single_quote_subst"`'
+postlink_cmds='`$ECHO "$postlink_cmds" | $SED "$delay_single_quote_subst"`'
+file_list_spec='`$ECHO "$file_list_spec" | $SED "$delay_single_quote_subst"`'
+variables_saved_for_relink='`$ECHO "$variables_saved_for_relink" | $SED "$delay_single_quote_subst"`'
+need_lib_prefix='`$ECHO "$need_lib_prefix" | $SED "$delay_single_quote_subst"`'
+need_version='`$ECHO "$need_version" | $SED "$delay_single_quote_subst"`'
+version_type='`$ECHO "$version_type" | $SED "$delay_single_quote_subst"`'
+runpath_var='`$ECHO "$runpath_var" | $SED "$delay_single_quote_subst"`'
+shlibpath_var='`$ECHO "$shlibpath_var" | $SED "$delay_single_quote_subst"`'
+shlibpath_overrides_runpath='`$ECHO "$shlibpath_overrides_runpath" | $SED "$delay_single_quote_subst"`'
+libname_spec='`$ECHO "$libname_spec" | $SED "$delay_single_quote_subst"`'
+library_names_spec='`$ECHO "$library_names_spec" | $SED "$delay_single_quote_subst"`'
+soname_spec='`$ECHO "$soname_spec" | $SED "$delay_single_quote_subst"`'
+install_override_mode='`$ECHO "$install_override_mode" | $SED "$delay_single_quote_subst"`'
+postinstall_cmds='`$ECHO "$postinstall_cmds" | $SED "$delay_single_quote_subst"`'
+postuninstall_cmds='`$ECHO "$postuninstall_cmds" | $SED "$delay_single_quote_subst"`'
+finish_cmds='`$ECHO "$finish_cmds" | $SED "$delay_single_quote_subst"`'
+finish_eval='`$ECHO "$finish_eval" | $SED "$delay_single_quote_subst"`'
+hardcode_into_libs='`$ECHO "$hardcode_into_libs" | $SED "$delay_single_quote_subst"`'
+sys_lib_search_path_spec='`$ECHO "$sys_lib_search_path_spec" | $SED "$delay_single_quote_subst"`'
+sys_lib_dlsearch_path_spec='`$ECHO "$sys_lib_dlsearch_path_spec" | $SED "$delay_single_quote_subst"`'
+hardcode_action='`$ECHO "$hardcode_action" | $SED "$delay_single_quote_subst"`'
+enable_dlopen='`$ECHO "$enable_dlopen" | $SED "$delay_single_quote_subst"`'
+enable_dlopen_self='`$ECHO "$enable_dlopen_self" | $SED "$delay_single_quote_subst"`'
+enable_dlopen_self_static='`$ECHO "$enable_dlopen_self_static" | $SED "$delay_single_quote_subst"`'
+old_striplib='`$ECHO "$old_striplib" | $SED "$delay_single_quote_subst"`'
+striplib='`$ECHO "$striplib" | $SED "$delay_single_quote_subst"`'
+
+LTCC='$LTCC'
+LTCFLAGS='$LTCFLAGS'
+compiler='$compiler_DEFAULT'
+
+# A function that is used when there is no print builtin or printf.
+func_fallback_echo ()
+{
+  eval 'cat <<_LTECHO_EOF
+\$1
+_LTECHO_EOF'
+}
+
+# Quote evaled strings.
+for var in SHELL \
+ECHO \
+PATH_SEPARATOR \
+SED \
+GREP \
+EGREP \
+FGREP \
+LD \
+NM \
+LN_S \
+lt_SP2NL \
+lt_NL2SP \
+reload_flag \
+OBJDUMP \
+deplibs_check_method \
+file_magic_cmd \
+file_magic_glob \
+want_nocaseglob \
+DLLTOOL \
+sharedlib_from_linklib_cmd \
+AR \
+AR_FLAGS \
+archiver_list_spec \
+STRIP \
+RANLIB \
+CC \
+CFLAGS \
+compiler \
+lt_cv_sys_global_symbol_pipe \
+lt_cv_sys_global_symbol_to_cdecl \
+lt_cv_sys_global_symbol_to_c_name_address \
+lt_cv_sys_global_symbol_to_c_name_address_lib_prefix \
+nm_file_list_spec \
+lt_prog_compiler_no_builtin_flag \
+lt_prog_compiler_pic \
+lt_prog_compiler_wl \
+lt_prog_compiler_static \
+lt_cv_prog_compiler_c_o \
+need_locks \
+MANIFEST_TOOL \
+DSYMUTIL \
+NMEDIT \
+LIPO \
+OTOOL \
+OTOOL64 \
+shrext_cmds \
+export_dynamic_flag_spec \
+whole_archive_flag_spec \
+compiler_needs_object \
+with_gnu_ld \
+allow_undefined_flag \
+no_undefined_flag \
+hardcode_libdir_flag_spec \
+hardcode_libdir_separator \
+exclude_expsyms \
+include_expsyms \
+file_list_spec \
+variables_saved_for_relink \
+libname_spec \
+library_names_spec \
+soname_spec \
+install_override_mode \
+finish_eval \
+old_striplib \
+striplib; do
+    case \`eval \\\\\$ECHO \\\\""\\\\\$\$var"\\\\"\` in
+    *[\\\\\\\`\\"\\\$]*)
+      eval "lt_\$var=\\\\\\"\\\`\\\$ECHO \\"\\\$\$var\\" | \\\$SED \\"\\\$sed_quote_subst\\"\\\`\\\\\\""
+      ;;
+    *)
+      eval "lt_\$var=\\\\\\"\\\$\$var\\\\\\""
+      ;;
+    esac
+done
+
+# Double-quote double-evaled strings.
+for var in reload_cmds \
+old_postinstall_cmds \
+old_postuninstall_cmds \
+old_archive_cmds \
+extract_expsyms_cmds \
+old_archive_from_new_cmds \
+old_archive_from_expsyms_cmds \
+archive_cmds \
+archive_expsym_cmds \
+module_cmds \
+module_expsym_cmds \
+export_symbols_cmds \
+prelink_cmds \
+postlink_cmds \
+postinstall_cmds \
+postuninstall_cmds \
+finish_cmds \
+sys_lib_search_path_spec \
+sys_lib_dlsearch_path_spec; do
+    case \`eval \\\\\$ECHO \\\\""\\\\\$\$var"\\\\"\` in
+    *[\\\\\\\`\\"\\\$]*)
+      eval "lt_\$var=\\\\\\"\\\`\\\$ECHO \\"\\\$\$var\\" | \\\$SED -e \\"\\\$double_quote_subst\\" -e \\"\\\$sed_quote_subst\\" -e \\"\\\$delay_variable_subst\\"\\\`\\\\\\""
+      ;;
+    *)
+      eval "lt_\$var=\\\\\\"\\\$\$var\\\\\\""
+      ;;
+    esac
+done
+
+ac_aux_dir='$ac_aux_dir'
+xsi_shell='$xsi_shell'
+lt_shell_append='$lt_shell_append'
+
+# See if we are running on zsh, and set the options which allow our
+# commands through without removal of \ escapes INIT.
+if test -n "\${ZSH_VERSION+set}" ; then
+   setopt NO_GLOB_SUBST
+fi
+
+
+    PACKAGE='$PACKAGE'
+    VERSION='$VERSION'
+    TIMESTAMP='$TIMESTAMP'
+    RM='$RM'
+    ofile='$ofile'
+
+
+
+
+_ACEOF
+
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+
+# Handling of arguments.
+for ac_config_target in $ac_config_targets
+do
+  case $ac_config_target in
+    "config.h") CONFIG_HEADERS="$CONFIG_HEADERS config.h" ;;
+    "depfiles") CONFIG_COMMANDS="$CONFIG_COMMANDS depfiles" ;;
+    "libtool") CONFIG_COMMANDS="$CONFIG_COMMANDS libtool" ;;
+    "Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;;
+    "include/version.h") CONFIG_FILES="$CONFIG_FILES include/version.h" ;;
+    "connman.pc") CONFIG_FILES="$CONFIG_FILES connman.pc" ;;
+
+  *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;;
+  esac
+done
+
+
+# If the user did not use the arguments to specify the items to instantiate,
+# then the envvar interface is used.  Set only those that are not.
+# We use the long form for the default assignment because of an extremely
+# bizarre bug on SunOS 4.1.3.
+if $ac_need_defaults; then
+  test "${CONFIG_FILES+set}" = set || CONFIG_FILES=$config_files
+  test "${CONFIG_HEADERS+set}" = set || CONFIG_HEADERS=$config_headers
+  test "${CONFIG_COMMANDS+set}" = set || CONFIG_COMMANDS=$config_commands
+fi
+
+# Have a temporary directory for convenience.  Make it in the build tree
+# simply because there is no reason against having it here, and in addition,
+# creating and moving files from /tmp can sometimes cause problems.
+# Hook for its removal unless debugging.
+# Note that there is a small window in which the directory will not be cleaned:
+# after its creation but before its name has been assigned to `$tmp'.
+$debug ||
+{
+  tmp= ac_tmp=
+  trap 'exit_status=$?
+  : "${ac_tmp:=$tmp}"
+  { test ! -d "$ac_tmp" || rm -fr "$ac_tmp"; } && exit $exit_status
+' 0
+  trap 'as_fn_exit 1' 1 2 13 15
+}
+# Create a (secure) tmp directory for tmp files.
+
+{
+  tmp=`(umask 077 && mktemp -d "./confXXXXXX") 2>/dev/null` &&
+  test -d "$tmp"
+}  ||
+{
+  tmp=./conf$$-$RANDOM
+  (umask 077 && mkdir "$tmp")
+} || as_fn_error $? "cannot create a temporary directory in ." "$LINENO" 5
+ac_tmp=$tmp
+
+# Set up the scripts for CONFIG_FILES section.
+# No need to generate them if there are no CONFIG_FILES.
+# This happens for instance with `./config.status config.h'.
+if test -n "$CONFIG_FILES"; then
+
+
+ac_cr=`echo X | tr X '\015'`
+# On cygwin, bash can eat \r inside `` if the user requested igncr.
+# But we know of no other shell where ac_cr would be empty at this
+# point, so we can use a bashism as a fallback.
+if test "x$ac_cr" = x; then
+  eval ac_cr=\$\'\\r\'
+fi
+ac_cs_awk_cr=`$AWK 'BEGIN { print "a\rb" }' </dev/null 2>/dev/null`
+if test "$ac_cs_awk_cr" = "a${ac_cr}b"; then
+  ac_cs_awk_cr='\\r'
+else
+  ac_cs_awk_cr=$ac_cr
+fi
+
+echo 'BEGIN {' >"$ac_tmp/subs1.awk" &&
+_ACEOF
+
+
+{
+  echo "cat >conf$$subs.awk <<_ACEOF" &&
+  echo "$ac_subst_vars" | sed 's/.*/&!$&$ac_delim/' &&
+  echo "_ACEOF"
+} >conf$$subs.sh ||
+  as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5
+ac_delim_num=`echo "$ac_subst_vars" | grep -c '^'`
+ac_delim='%!_!# '
+for ac_last_try in false false false false false :; do
+  . ./conf$$subs.sh ||
+    as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5
+
+  ac_delim_n=`sed -n "s/.*$ac_delim\$/X/p" conf$$subs.awk | grep -c X`
+  if test $ac_delim_n = $ac_delim_num; then
+    break
+  elif $ac_last_try; then
+    as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5
+  else
+    ac_delim="$ac_delim!$ac_delim _$ac_delim!! "
+  fi
+done
+rm -f conf$$subs.sh
+
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+cat >>"\$ac_tmp/subs1.awk" <<\\_ACAWK &&
+_ACEOF
+sed -n '
+h
+s/^/S["/; s/!.*/"]=/
+p
+g
+s/^[^!]*!//
+:repl
+t repl
+s/'"$ac_delim"'$//
+t delim
+:nl
+h
+s/\(.\{148\}\)..*/\1/
+t more1
+s/["\\]/\\&/g; s/^/"/; s/$/\\n"\\/
+p
+n
+b repl
+:more1
+s/["\\]/\\&/g; s/^/"/; s/$/"\\/
+p
+g
+s/.\{148\}//
+t nl
+:delim
+h
+s/\(.\{148\}\)..*/\1/
+t more2
+s/["\\]/\\&/g; s/^/"/; s/$/"/
+p
+b
+:more2
+s/["\\]/\\&/g; s/^/"/; s/$/"\\/
+p
+g
+s/.\{148\}//
+t delim
+' <conf$$subs.awk | sed '
+/^[^""]/{
+  N
+  s/\n//
+}
+' >>$CONFIG_STATUS || ac_write_fail=1
+rm -f conf$$subs.awk
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+_ACAWK
+cat >>"\$ac_tmp/subs1.awk" <<_ACAWK &&
+  for (key in S) S_is_set[key] = 1
+  FS = ""
+
+}
+{
+  line = $ 0
+  nfields = split(line, field, "@")
+  substed = 0
+  len = length(field[1])
+  for (i = 2; i < nfields; i++) {
+    key = field[i]
+    keylen = length(key)
+    if (S_is_set[key]) {
+      value = S[key]
+      line = substr(line, 1, len) "" value "" substr(line, len + keylen + 3)
+      len += length(value) + length(field[++i])
+      substed = 1
+    } else
+      len += 1 + keylen
+  }
+
+  print line
+}
+
+_ACAWK
+_ACEOF
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+if sed "s/$ac_cr//" < /dev/null > /dev/null 2>&1; then
+  sed "s/$ac_cr\$//; s/$ac_cr/$ac_cs_awk_cr/g"
+else
+  cat
+fi < "$ac_tmp/subs1.awk" > "$ac_tmp/subs.awk" \
+  || as_fn_error $? "could not setup config files machinery" "$LINENO" 5
+_ACEOF
+
+# VPATH may cause trouble with some makes, so we remove sole $(srcdir),
+# ${srcdir} and @srcdir@ entries from VPATH if srcdir is ".", strip leading and
+# trailing colons and then remove the whole line if VPATH becomes empty
+# (actually we leave an empty line to preserve line numbers).
+if test "x$srcdir" = x.; then
+  ac_vpsub='/^[	 ]*VPATH[	 ]*=[	 ]*/{
+h
+s///
+s/^/:/
+s/[	 ]*$/:/
+s/:\$(srcdir):/:/g
+s/:\${srcdir}:/:/g
+s/:@srcdir@:/:/g
+s/^:*//
+s/:*$//
+x
+s/\(=[	 ]*\).*/\1/
+G
+s/\n//
+s/^[^=]*=[	 ]*$//
+}'
+fi
+
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+fi # test -n "$CONFIG_FILES"
+
+# Set up the scripts for CONFIG_HEADERS section.
+# No need to generate them if there are no CONFIG_HEADERS.
+# This happens for instance with `./config.status Makefile'.
+if test -n "$CONFIG_HEADERS"; then
+cat >"$ac_tmp/defines.awk" <<\_ACAWK ||
+BEGIN {
+_ACEOF
+
+# Transform confdefs.h into an awk script `defines.awk', embedded as
+# here-document in config.status, that substitutes the proper values into
+# config.h.in to produce config.h.
+
+# Create a delimiter string that does not exist in confdefs.h, to ease
+# handling of long lines.
+ac_delim='%!_!# '
+for ac_last_try in false false :; do
+  ac_tt=`sed -n "/$ac_delim/p" confdefs.h`
+  if test -z "$ac_tt"; then
+    break
+  elif $ac_last_try; then
+    as_fn_error $? "could not make $CONFIG_HEADERS" "$LINENO" 5
+  else
+    ac_delim="$ac_delim!$ac_delim _$ac_delim!! "
+  fi
+done
+
+# For the awk script, D is an array of macro values keyed by name,
+# likewise P contains macro parameters if any.  Preserve backslash
+# newline sequences.
+
+ac_word_re=[_$as_cr_Letters][_$as_cr_alnum]*
+sed -n '
+s/.\{148\}/&'"$ac_delim"'/g
+t rset
+:rset
+s/^[	 ]*#[	 ]*define[	 ][	 ]*/ /
+t def
+d
+:def
+s/\\$//
+t bsnl
+s/["\\]/\\&/g
+s/^ \('"$ac_word_re"'\)\(([^()]*)\)[	 ]*\(.*\)/P["\1"]="\2"\
+D["\1"]=" \3"/p
+s/^ \('"$ac_word_re"'\)[	 ]*\(.*\)/D["\1"]=" \2"/p
+d
+:bsnl
+s/["\\]/\\&/g
+s/^ \('"$ac_word_re"'\)\(([^()]*)\)[	 ]*\(.*\)/P["\1"]="\2"\
+D["\1"]=" \3\\\\\\n"\\/p
+t cont
+s/^ \('"$ac_word_re"'\)[	 ]*\(.*\)/D["\1"]=" \2\\\\\\n"\\/p
+t cont
+d
+:cont
+n
+s/.\{148\}/&'"$ac_delim"'/g
+t clear
+:clear
+s/\\$//
+t bsnlc
+s/["\\]/\\&/g; s/^/"/; s/$/"/p
+d
+:bsnlc
+s/["\\]/\\&/g; s/^/"/; s/$/\\\\\\n"\\/p
+b cont
+' <confdefs.h | sed '
+s/'"$ac_delim"'/"\\\
+"/g' >>$CONFIG_STATUS || ac_write_fail=1
+
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+  for (key in D) D_is_set[key] = 1
+  FS = ""
+}
+/^[\t ]*#[\t ]*(define|undef)[\t ]+$ac_word_re([\t (]|\$)/ {
+  line = \$ 0
+  split(line, arg, " ")
+  if (arg[1] == "#") {
+    defundef = arg[2]
+    mac1 = arg[3]
+  } else {
+    defundef = substr(arg[1], 2)
+    mac1 = arg[2]
+  }
+  split(mac1, mac2, "(") #)
+  macro = mac2[1]
+  prefix = substr(line, 1, index(line, defundef) - 1)
+  if (D_is_set[macro]) {
+    # Preserve the white space surrounding the "#".
+    print prefix "define", macro P[macro] D[macro]
+    next
+  } else {
+    # Replace #undef with comments.  This is necessary, for example,
+    # in the case of _POSIX_SOURCE, which is predefined and required
+    # on some systems where configure will not decide to define it.
+    if (defundef == "undef") {
+      print "/*", prefix defundef, macro, "*/"
+      next
+    }
+  }
+}
+{ print }
+_ACAWK
+_ACEOF
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+  as_fn_error $? "could not setup config headers machinery" "$LINENO" 5
+fi # test -n "$CONFIG_HEADERS"
+
+
+eval set X "  :F $CONFIG_FILES  :H $CONFIG_HEADERS    :C $CONFIG_COMMANDS"
+shift
+for ac_tag
+do
+  case $ac_tag in
+  :[FHLC]) ac_mode=$ac_tag; continue;;
+  esac
+  case $ac_mode$ac_tag in
+  :[FHL]*:*);;
+  :L* | :C*:*) as_fn_error $? "invalid tag \`$ac_tag'" "$LINENO" 5;;
+  :[FH]-) ac_tag=-:-;;
+  :[FH]*) ac_tag=$ac_tag:$ac_tag.in;;
+  esac
+  ac_save_IFS=$IFS
+  IFS=:
+  set x $ac_tag
+  IFS=$ac_save_IFS
+  shift
+  ac_file=$1
+  shift
+
+  case $ac_mode in
+  :L) ac_source=$1;;
+  :[FH])
+    ac_file_inputs=
+    for ac_f
+    do
+      case $ac_f in
+      -) ac_f="$ac_tmp/stdin";;
+      *) # Look for the file first in the build tree, then in the source tree
+	 # (if the path is not absolute).  The absolute path cannot be DOS-style,
+	 # because $ac_f cannot contain `:'.
+	 test -f "$ac_f" ||
+	   case $ac_f in
+	   [\\/$]*) false;;
+	   *) test -f "$srcdir/$ac_f" && ac_f="$srcdir/$ac_f";;
+	   esac ||
+	   as_fn_error 1 "cannot find input file: \`$ac_f'" "$LINENO" 5;;
+      esac
+      case $ac_f in *\'*) ac_f=`$as_echo "$ac_f" | sed "s/'/'\\\\\\\\''/g"`;; esac
+      as_fn_append ac_file_inputs " '$ac_f'"
+    done
+
+    # Let's still pretend it is `configure' which instantiates (i.e., don't
+    # use $as_me), people would be surprised to read:
+    #    /* config.h.  Generated by config.status.  */
+    configure_input='Generated from '`
+	  $as_echo "$*" | sed 's|^[^:]*/||;s|:[^:]*/|, |g'
+	`' by configure.'
+    if test x"$ac_file" != x-; then
+      configure_input="$ac_file.  $configure_input"
+      { $as_echo "$as_me:${as_lineno-$LINENO}: creating $ac_file" >&5
+$as_echo "$as_me: creating $ac_file" >&6;}
+    fi
+    # Neutralize special characters interpreted by sed in replacement strings.
+    case $configure_input in #(
+    *\&* | *\|* | *\\* )
+       ac_sed_conf_input=`$as_echo "$configure_input" |
+       sed 's/[\\\\&|]/\\\\&/g'`;; #(
+    *) ac_sed_conf_input=$configure_input;;
+    esac
+
+    case $ac_tag in
+    *:-:* | *:-) cat >"$ac_tmp/stdin" \
+      || as_fn_error $? "could not create $ac_file" "$LINENO" 5 ;;
+    esac
+    ;;
+  esac
+
+  ac_dir=`$as_dirname -- "$ac_file" ||
+$as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+	 X"$ac_file" : 'X\(//\)[^/]' \| \
+	 X"$ac_file" : 'X\(//\)$' \| \
+	 X"$ac_file" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X"$ac_file" |
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)[^/].*/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\).*/{
+	    s//\1/
+	    q
+	  }
+	  s/.*/./; q'`
+  as_dir="$ac_dir"; as_fn_mkdir_p
+  ac_builddir=.
+
+case "$ac_dir" in
+.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;;
+*)
+  ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'`
+  # A ".." for each directory in $ac_dir_suffix.
+  ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'`
+  case $ac_top_builddir_sub in
+  "") ac_top_builddir_sub=. ac_top_build_prefix= ;;
+  *)  ac_top_build_prefix=$ac_top_builddir_sub/ ;;
+  esac ;;
+esac
+ac_abs_top_builddir=$ac_pwd
+ac_abs_builddir=$ac_pwd$ac_dir_suffix
+# for backward compatibility:
+ac_top_builddir=$ac_top_build_prefix
+
+case $srcdir in
+  .)  # We are building in place.
+    ac_srcdir=.
+    ac_top_srcdir=$ac_top_builddir_sub
+    ac_abs_top_srcdir=$ac_pwd ;;
+  [\\/]* | ?:[\\/]* )  # Absolute name.
+    ac_srcdir=$srcdir$ac_dir_suffix;
+    ac_top_srcdir=$srcdir
+    ac_abs_top_srcdir=$srcdir ;;
+  *) # Relative name.
+    ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix
+    ac_top_srcdir=$ac_top_build_prefix$srcdir
+    ac_abs_top_srcdir=$ac_pwd/$srcdir ;;
+esac
+ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix
+
+
+  case $ac_mode in
+  :F)
+  #
+  # CONFIG_FILE
+  #
+
+  case $INSTALL in
+  [\\/$]* | ?:[\\/]* ) ac_INSTALL=$INSTALL ;;
+  *) ac_INSTALL=$ac_top_build_prefix$INSTALL ;;
+  esac
+  ac_MKDIR_P=$MKDIR_P
+  case $MKDIR_P in
+  [\\/$]* | ?:[\\/]* ) ;;
+  */*) ac_MKDIR_P=$ac_top_build_prefix$MKDIR_P ;;
+  esac
+_ACEOF
+
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+# If the template does not know about datarootdir, expand it.
+# FIXME: This hack should be removed a few years after 2.60.
+ac_datarootdir_hack=; ac_datarootdir_seen=
+ac_sed_dataroot='
+/datarootdir/ {
+  p
+  q
+}
+/@datadir@/p
+/@docdir@/p
+/@infodir@/p
+/@localedir@/p
+/@mandir@/p'
+case `eval "sed -n \"\$ac_sed_dataroot\" $ac_file_inputs"` in
+*datarootdir*) ac_datarootdir_seen=yes;;
+*@datadir@*|*@docdir@*|*@infodir@*|*@localedir@*|*@mandir@*)
+  { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&5
+$as_echo "$as_me: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&2;}
+_ACEOF
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+  ac_datarootdir_hack='
+  s&@datadir@&$datadir&g
+  s&@docdir@&$docdir&g
+  s&@infodir@&$infodir&g
+  s&@localedir@&$localedir&g
+  s&@mandir@&$mandir&g
+  s&\\\${datarootdir}&$datarootdir&g' ;;
+esac
+_ACEOF
+
+# Neutralize VPATH when `$srcdir' = `.'.
+# Shell code in configure.ac might set extrasub.
+# FIXME: do we really want to maintain this feature?
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+ac_sed_extra="$ac_vpsub
+$extrasub
+_ACEOF
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+:t
+/@[a-zA-Z_][a-zA-Z_0-9]*@/!b
+s|@configure_input@|$ac_sed_conf_input|;t t
+s&@top_builddir@&$ac_top_builddir_sub&;t t
+s&@top_build_prefix@&$ac_top_build_prefix&;t t
+s&@srcdir@&$ac_srcdir&;t t
+s&@abs_srcdir@&$ac_abs_srcdir&;t t
+s&@top_srcdir@&$ac_top_srcdir&;t t
+s&@abs_top_srcdir@&$ac_abs_top_srcdir&;t t
+s&@builddir@&$ac_builddir&;t t
+s&@abs_builddir@&$ac_abs_builddir&;t t
+s&@abs_top_builddir@&$ac_abs_top_builddir&;t t
+s&@INSTALL@&$ac_INSTALL&;t t
+s&@MKDIR_P@&$ac_MKDIR_P&;t t
+$ac_datarootdir_hack
+"
+eval sed \"\$ac_sed_extra\" "$ac_file_inputs" | $AWK -f "$ac_tmp/subs.awk" \
+  >$ac_tmp/out || as_fn_error $? "could not create $ac_file" "$LINENO" 5
+
+test -z "$ac_datarootdir_hack$ac_datarootdir_seen" &&
+  { ac_out=`sed -n '/\${datarootdir}/p' "$ac_tmp/out"`; test -n "$ac_out"; } &&
+  { ac_out=`sed -n '/^[	 ]*datarootdir[	 ]*:*=/p' \
+      "$ac_tmp/out"`; test -z "$ac_out"; } &&
+  { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file contains a reference to the variable \`datarootdir'
+which seems to be undefined.  Please make sure it is defined" >&5
+$as_echo "$as_me: WARNING: $ac_file contains a reference to the variable \`datarootdir'
+which seems to be undefined.  Please make sure it is defined" >&2;}
+
+  rm -f "$ac_tmp/stdin"
+  case $ac_file in
+  -) cat "$ac_tmp/out" && rm -f "$ac_tmp/out";;
+  *) rm -f "$ac_file" && mv "$ac_tmp/out" "$ac_file";;
+  esac \
+  || as_fn_error $? "could not create $ac_file" "$LINENO" 5
+ ;;
+  :H)
+  #
+  # CONFIG_HEADER
+  #
+  if test x"$ac_file" != x-; then
+    {
+      $as_echo "/* $configure_input  */" \
+      && eval '$AWK -f "$ac_tmp/defines.awk"' "$ac_file_inputs"
+    } >"$ac_tmp/config.h" \
+      || as_fn_error $? "could not create $ac_file" "$LINENO" 5
+    if diff "$ac_file" "$ac_tmp/config.h" >/dev/null 2>&1; then
+      { $as_echo "$as_me:${as_lineno-$LINENO}: $ac_file is unchanged" >&5
+$as_echo "$as_me: $ac_file is unchanged" >&6;}
+    else
+      rm -f "$ac_file"
+      mv "$ac_tmp/config.h" "$ac_file" \
+	|| as_fn_error $? "could not create $ac_file" "$LINENO" 5
+    fi
+  else
+    $as_echo "/* $configure_input  */" \
+      && eval '$AWK -f "$ac_tmp/defines.awk"' "$ac_file_inputs" \
+      || as_fn_error $? "could not create -" "$LINENO" 5
+  fi
+# Compute "$ac_file"'s index in $config_headers.
+_am_arg="$ac_file"
+_am_stamp_count=1
+for _am_header in $config_headers :; do
+  case $_am_header in
+    $_am_arg | $_am_arg:* )
+      break ;;
+    * )
+      _am_stamp_count=`expr $_am_stamp_count + 1` ;;
+  esac
+done
+echo "timestamp for $_am_arg" >`$as_dirname -- "$_am_arg" ||
+$as_expr X"$_am_arg" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+	 X"$_am_arg" : 'X\(//\)[^/]' \| \
+	 X"$_am_arg" : 'X\(//\)$' \| \
+	 X"$_am_arg" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X"$_am_arg" |
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)[^/].*/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\).*/{
+	    s//\1/
+	    q
+	  }
+	  s/.*/./; q'`/stamp-h$_am_stamp_count
+ ;;
+
+  :C)  { $as_echo "$as_me:${as_lineno-$LINENO}: executing $ac_file commands" >&5
+$as_echo "$as_me: executing $ac_file commands" >&6;}
+ ;;
+  esac
+
+
+  case $ac_file$ac_mode in
+    "depfiles":C) test x"$AMDEP_TRUE" != x"" || {
+  # Older Autoconf quotes --file arguments for eval, but not when files
+  # are listed without --file.  Let's play safe and only enable the eval
+  # if we detect the quoting.
+  case $CONFIG_FILES in
+  *\'*) eval set x "$CONFIG_FILES" ;;
+  *)   set x $CONFIG_FILES ;;
+  esac
+  shift
+  for mf
+  do
+    # Strip MF so we end up with the name of the file.
+    mf=`echo "$mf" | sed -e 's/:.*$//'`
+    # Check whether this is an Automake generated Makefile or not.
+    # We used to match only the files named 'Makefile.in', but
+    # some people rename them; so instead we look at the file content.
+    # Grep'ing the first line is not enough: some people post-process
+    # each Makefile.in and add a new line on top of each file to say so.
+    # Grep'ing the whole file is not good either: AIX grep has a line
+    # limit of 2048, but all sed's we know have understand at least 4000.
+    if sed -n 's,^#.*generated by automake.*,X,p' "$mf" | grep X >/dev/null 2>&1; then
+      dirpart=`$as_dirname -- "$mf" ||
+$as_expr X"$mf" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+	 X"$mf" : 'X\(//\)[^/]' \| \
+	 X"$mf" : 'X\(//\)$' \| \
+	 X"$mf" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X"$mf" |
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)[^/].*/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\).*/{
+	    s//\1/
+	    q
+	  }
+	  s/.*/./; q'`
+    else
+      continue
+    fi
+    # Extract the definition of DEPDIR, am__include, and am__quote
+    # from the Makefile without running 'make'.
+    DEPDIR=`sed -n 's/^DEPDIR = //p' < "$mf"`
+    test -z "$DEPDIR" && continue
+    am__include=`sed -n 's/^am__include = //p' < "$mf"`
+    test -z "$am__include" && continue
+    am__quote=`sed -n 's/^am__quote = //p' < "$mf"`
+    # Find all dependency output files, they are included files with
+    # $(DEPDIR) in their names.  We invoke sed twice because it is the
+    # simplest approach to changing $(DEPDIR) to its actual value in the
+    # expansion.
+    for file in `sed -n "
+      s/^$am__include $am__quote\(.*(DEPDIR).*\)$am__quote"'$/\1/p' <"$mf" | \
+	 sed -e 's/\$(DEPDIR)/'"$DEPDIR"'/g'`; do
+      # Make sure the directory exists.
+      test -f "$dirpart/$file" && continue
+      fdir=`$as_dirname -- "$file" ||
+$as_expr X"$file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+	 X"$file" : 'X\(//\)[^/]' \| \
+	 X"$file" : 'X\(//\)$' \| \
+	 X"$file" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X"$file" |
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)[^/].*/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\).*/{
+	    s//\1/
+	    q
+	  }
+	  s/.*/./; q'`
+      as_dir=$dirpart/$fdir; as_fn_mkdir_p
+      # echo "creating $dirpart/$file"
+      echo '# dummy' > "$dirpart/$file"
+    done
+  done
+}
+ ;;
+    "libtool":C)
+
+    # See if we are running on zsh, and set the options which allow our
+    # commands through without removal of \ escapes.
+    if test -n "${ZSH_VERSION+set}" ; then
+      setopt NO_GLOB_SUBST
+    fi
+
+    cfgfile="${ofile}T"
+    trap "$RM \"$cfgfile\"; exit 1" 1 2 15
+    $RM "$cfgfile"
+
+    cat <<_LT_EOF >> "$cfgfile"
+#! $SHELL
+
+# `$ECHO "$ofile" | sed 's%^.*/%%'` - Provide generalized library-building support services.
+# Generated automatically by $as_me ($PACKAGE$TIMESTAMP) $VERSION
+# Libtool was configured on host `(hostname || uname -n) 2>/dev/null | sed 1q`:
+# NOTE: Changes made to this file will be lost: look at ltmain.sh.
+#
+#   Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005,
+#                 2006, 2007, 2008, 2009, 2010, 2011 Free Software
+#                 Foundation, Inc.
+#   Written by Gordon Matzigkeit, 1996
+#
+#   This file is part of GNU Libtool.
+#
+# GNU Libtool is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2 of
+# the License, or (at your option) any later version.
+#
+# As a special exception to the GNU General Public License,
+# if you distribute this file as part of a program or library that
+# is built using GNU Libtool, you may include this file under the
+# same distribution terms that you use for the rest of that program.
+#
+# GNU Libtool 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 GNU Libtool; see the file COPYING.  If not, a copy
+# can be downloaded from http://www.gnu.org/licenses/gpl.html, or
+# obtained by writing to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+
+# The names of the tagged configurations supported by this script.
+available_tags=""
+
+# ### BEGIN LIBTOOL CONFIG
+
+# Whether or not to build static libraries.
+build_old_libs=$enable_static
+
+# Which release of libtool.m4 was used?
+macro_version=$macro_version
+macro_revision=$macro_revision
+
+# Whether or not to build shared libraries.
+build_libtool_libs=$enable_shared
+
+# What type of objects to build.
+pic_mode=$pic_mode
+
+# Whether or not to optimize for fast installation.
+fast_install=$enable_fast_install
+
+# Shell to use when invoking shell scripts.
+SHELL=$lt_SHELL
+
+# An echo program that protects backslashes.
+ECHO=$lt_ECHO
+
+# The PATH separator for the build system.
+PATH_SEPARATOR=$lt_PATH_SEPARATOR
+
+# The host system.
+host_alias=$host_alias
+host=$host
+host_os=$host_os
+
+# The build system.
+build_alias=$build_alias
+build=$build
+build_os=$build_os
+
+# A sed program that does not truncate output.
+SED=$lt_SED
+
+# Sed that helps us avoid accidentally triggering echo(1) options like -n.
+Xsed="\$SED -e 1s/^X//"
+
+# A grep program that handles long lines.
+GREP=$lt_GREP
+
+# An ERE matcher.
+EGREP=$lt_EGREP
+
+# A literal string matcher.
+FGREP=$lt_FGREP
+
+# A BSD- or MS-compatible name lister.
+NM=$lt_NM
+
+# Whether we need soft or hard links.
+LN_S=$lt_LN_S
+
+# What is the maximum length of a command?
+max_cmd_len=$max_cmd_len
+
+# Object file suffix (normally "o").
+objext=$ac_objext
+
+# Executable file suffix (normally "").
+exeext=$exeext
+
+# whether the shell understands "unset".
+lt_unset=$lt_unset
+
+# turn spaces into newlines.
+SP2NL=$lt_lt_SP2NL
+
+# turn newlines into spaces.
+NL2SP=$lt_lt_NL2SP
+
+# convert \$build file names to \$host format.
+to_host_file_cmd=$lt_cv_to_host_file_cmd
+
+# convert \$build files to toolchain format.
+to_tool_file_cmd=$lt_cv_to_tool_file_cmd
+
+# An object symbol dumper.
+OBJDUMP=$lt_OBJDUMP
+
+# Method to check whether dependent libraries are shared objects.
+deplibs_check_method=$lt_deplibs_check_method
+
+# Command to use when deplibs_check_method = "file_magic".
+file_magic_cmd=$lt_file_magic_cmd
+
+# How to find potential files when deplibs_check_method = "file_magic".
+file_magic_glob=$lt_file_magic_glob
+
+# Find potential files using nocaseglob when deplibs_check_method = "file_magic".
+want_nocaseglob=$lt_want_nocaseglob
+
+# DLL creation program.
+DLLTOOL=$lt_DLLTOOL
+
+# Command to associate shared and link libraries.
+sharedlib_from_linklib_cmd=$lt_sharedlib_from_linklib_cmd
+
+# The archiver.
+AR=$lt_AR
+
+# Flags to create an archive.
+AR_FLAGS=$lt_AR_FLAGS
+
+# How to feed a file listing to the archiver.
+archiver_list_spec=$lt_archiver_list_spec
+
+# A symbol stripping program.
+STRIP=$lt_STRIP
+
+# Commands used to install an old-style archive.
+RANLIB=$lt_RANLIB
+old_postinstall_cmds=$lt_old_postinstall_cmds
+old_postuninstall_cmds=$lt_old_postuninstall_cmds
+
+# Whether to use a lock for old archive extraction.
+lock_old_archive_extraction=$lock_old_archive_extraction
+
+# A C compiler.
+LTCC=$lt_CC
+
+# LTCC compiler flags.
+LTCFLAGS=$lt_CFLAGS
+
+# Take the output of nm and produce a listing of raw symbols and C names.
+global_symbol_pipe=$lt_lt_cv_sys_global_symbol_pipe
+
+# Transform the output of nm in a proper C declaration.
+global_symbol_to_cdecl=$lt_lt_cv_sys_global_symbol_to_cdecl
+
+# Transform the output of nm in a C name address pair.
+global_symbol_to_c_name_address=$lt_lt_cv_sys_global_symbol_to_c_name_address
+
+# Transform the output of nm in a C name address pair when lib prefix is needed.
+global_symbol_to_c_name_address_lib_prefix=$lt_lt_cv_sys_global_symbol_to_c_name_address_lib_prefix
+
+# Specify filename containing input files for \$NM.
+nm_file_list_spec=$lt_nm_file_list_spec
+
+# The root where to search for dependent libraries,and in which our libraries should be installed.
+lt_sysroot=$lt_sysroot
+
+# The name of the directory that contains temporary libtool files.
+objdir=$objdir
+
+# Used to examine libraries when file_magic_cmd begins with "file".
+MAGIC_CMD=$MAGIC_CMD
+
+# Must we lock files when doing compilation?
+need_locks=$lt_need_locks
+
+# Manifest tool.
+MANIFEST_TOOL=$lt_MANIFEST_TOOL
+
+# Tool to manipulate archived DWARF debug symbol files on Mac OS X.
+DSYMUTIL=$lt_DSYMUTIL
+
+# Tool to change global to local symbols on Mac OS X.
+NMEDIT=$lt_NMEDIT
+
+# Tool to manipulate fat objects and archives on Mac OS X.
+LIPO=$lt_LIPO
+
+# ldd/readelf like tool for Mach-O binaries on Mac OS X.
+OTOOL=$lt_OTOOL
+
+# ldd/readelf like tool for 64 bit Mach-O binaries on Mac OS X 10.4.
+OTOOL64=$lt_OTOOL64
+
+# Old archive suffix (normally "a").
+libext=$libext
+
+# Shared library suffix (normally ".so").
+shrext_cmds=$lt_shrext_cmds
+
+# The commands to extract the exported symbol list from a shared archive.
+extract_expsyms_cmds=$lt_extract_expsyms_cmds
+
+# Variables whose values should be saved in libtool wrapper scripts and
+# restored at link time.
+variables_saved_for_relink=$lt_variables_saved_for_relink
+
+# Do we need the "lib" prefix for modules?
+need_lib_prefix=$need_lib_prefix
+
+# Do we need a version for libraries?
+need_version=$need_version
+
+# Library versioning type.
+version_type=$version_type
+
+# Shared library runtime path variable.
+runpath_var=$runpath_var
+
+# Shared library path variable.
+shlibpath_var=$shlibpath_var
+
+# Is shlibpath searched before the hard-coded library search path?
+shlibpath_overrides_runpath=$shlibpath_overrides_runpath
+
+# Format of library name prefix.
+libname_spec=$lt_libname_spec
+
+# List of archive names.  First name is the real one, the rest are links.
+# The last name is the one that the linker finds with -lNAME
+library_names_spec=$lt_library_names_spec
+
+# The coded name of the library, if different from the real name.
+soname_spec=$lt_soname_spec
+
+# Permission mode override for installation of shared libraries.
+install_override_mode=$lt_install_override_mode
+
+# Command to use after installation of a shared archive.
+postinstall_cmds=$lt_postinstall_cmds
+
+# Command to use after uninstallation of a shared archive.
+postuninstall_cmds=$lt_postuninstall_cmds
+
+# Commands used to finish a libtool library installation in a directory.
+finish_cmds=$lt_finish_cmds
+
+# As "finish_cmds", except a single script fragment to be evaled but
+# not shown.
+finish_eval=$lt_finish_eval
+
+# Whether we should hardcode library paths into libraries.
+hardcode_into_libs=$hardcode_into_libs
+
+# Compile-time system search path for libraries.
+sys_lib_search_path_spec=$lt_sys_lib_search_path_spec
+
+# Run-time system search path for libraries.
+sys_lib_dlsearch_path_spec=$lt_sys_lib_dlsearch_path_spec
+
+# Whether dlopen is supported.
+dlopen_support=$enable_dlopen
+
+# Whether dlopen of programs is supported.
+dlopen_self=$enable_dlopen_self
+
+# Whether dlopen of statically linked programs is supported.
+dlopen_self_static=$enable_dlopen_self_static
+
+# Commands to strip libraries.
+old_striplib=$lt_old_striplib
+striplib=$lt_striplib
+
+
+# The linker used to build libraries.
+LD=$lt_LD
+
+# How to create reloadable object files.
+reload_flag=$lt_reload_flag
+reload_cmds=$lt_reload_cmds
+
+# Commands used to build an old-style archive.
+old_archive_cmds=$lt_old_archive_cmds
+
+# A language specific compiler.
+CC=$lt_compiler
+
+# Is the compiler the GNU compiler?
+with_gcc=$GCC
+
+# Compiler flag to turn off builtin functions.
+no_builtin_flag=$lt_lt_prog_compiler_no_builtin_flag
+
+# Additional compiler flags for building library objects.
+pic_flag=$lt_lt_prog_compiler_pic
+
+# How to pass a linker flag through the compiler.
+wl=$lt_lt_prog_compiler_wl
+
+# Compiler flag to prevent dynamic linking.
+link_static_flag=$lt_lt_prog_compiler_static
+
+# Does compiler simultaneously support -c and -o options?
+compiler_c_o=$lt_lt_cv_prog_compiler_c_o
+
+# Whether or not to add -lc for building shared libraries.
+build_libtool_need_lc=$archive_cmds_need_lc
+
+# Whether or not to disallow shared libs when runtime libs are static.
+allow_libtool_libs_with_static_runtimes=$enable_shared_with_static_runtimes
+
+# Compiler flag to allow reflexive dlopens.
+export_dynamic_flag_spec=$lt_export_dynamic_flag_spec
+
+# Compiler flag to generate shared objects directly from archives.
+whole_archive_flag_spec=$lt_whole_archive_flag_spec
+
+# Whether the compiler copes with passing no objects directly.
+compiler_needs_object=$lt_compiler_needs_object
+
+# Create an old-style archive from a shared archive.
+old_archive_from_new_cmds=$lt_old_archive_from_new_cmds
+
+# Create a temporary old-style archive to link instead of a shared archive.
+old_archive_from_expsyms_cmds=$lt_old_archive_from_expsyms_cmds
+
+# Commands used to build a shared archive.
+archive_cmds=$lt_archive_cmds
+archive_expsym_cmds=$lt_archive_expsym_cmds
+
+# Commands used to build a loadable module if different from building
+# a shared archive.
+module_cmds=$lt_module_cmds
+module_expsym_cmds=$lt_module_expsym_cmds
+
+# Whether we are building with GNU ld or not.
+with_gnu_ld=$lt_with_gnu_ld
+
+# Flag that allows shared libraries with undefined symbols to be built.
+allow_undefined_flag=$lt_allow_undefined_flag
+
+# Flag that enforces no undefined symbols.
+no_undefined_flag=$lt_no_undefined_flag
+
+# Flag to hardcode \$libdir into a binary during linking.
+# This must work even if \$libdir does not exist
+hardcode_libdir_flag_spec=$lt_hardcode_libdir_flag_spec
+
+# Whether we need a single "-rpath" flag with a separated argument.
+hardcode_libdir_separator=$lt_hardcode_libdir_separator
+
+# Set to "yes" if using DIR/libNAME\${shared_ext} during linking hardcodes
+# DIR into the resulting binary.
+hardcode_direct=$hardcode_direct
+
+# Set to "yes" if using DIR/libNAME\${shared_ext} during linking hardcodes
+# DIR into the resulting binary and the resulting library dependency is
+# "absolute",i.e impossible to change by setting \${shlibpath_var} if the
+# library is relocated.
+hardcode_direct_absolute=$hardcode_direct_absolute
+
+# Set to "yes" if using the -LDIR flag during linking hardcodes DIR
+# into the resulting binary.
+hardcode_minus_L=$hardcode_minus_L
+
+# Set to "yes" if using SHLIBPATH_VAR=DIR during linking hardcodes DIR
+# into the resulting binary.
+hardcode_shlibpath_var=$hardcode_shlibpath_var
+
+# Set to "yes" if building a shared library automatically hardcodes DIR
+# into the library and all subsequent libraries and executables linked
+# against it.
+hardcode_automatic=$hardcode_automatic
+
+# Set to yes if linker adds runtime paths of dependent libraries
+# to runtime path list.
+inherit_rpath=$inherit_rpath
+
+# Whether libtool must link a program against all its dependency libraries.
+link_all_deplibs=$link_all_deplibs
+
+# Set to "yes" if exported symbols are required.
+always_export_symbols=$always_export_symbols
+
+# The commands to list exported symbols.
+export_symbols_cmds=$lt_export_symbols_cmds
+
+# Symbols that should not be listed in the preloaded symbols.
+exclude_expsyms=$lt_exclude_expsyms
+
+# Symbols that must always be exported.
+include_expsyms=$lt_include_expsyms
+
+# Commands necessary for linking programs (against libraries) with templates.
+prelink_cmds=$lt_prelink_cmds
+
+# Commands necessary for finishing linking programs.
+postlink_cmds=$lt_postlink_cmds
+
+# Specify filename containing input files.
+file_list_spec=$lt_file_list_spec
+
+# How to hardcode a shared library path into an executable.
+hardcode_action=$hardcode_action
+
+# ### END LIBTOOL CONFIG
+
+_LT_EOF
+
+  case $host_os in
+  aix3*)
+    cat <<\_LT_EOF >> "$cfgfile"
+# AIX sometimes has problems with the GCC collect2 program.  For some
+# reason, if we set the COLLECT_NAMES environment variable, the problems
+# vanish in a puff of smoke.
+if test "X${COLLECT_NAMES+set}" != Xset; then
+  COLLECT_NAMES=
+  export COLLECT_NAMES
+fi
+_LT_EOF
+    ;;
+  esac
+
+
+ltmain="$ac_aux_dir/ltmain.sh"
+
+
+  # We use sed instead of cat because bash on DJGPP gets confused if
+  # if finds mixed CR/LF and LF-only lines.  Since sed operates in
+  # text mode, it properly converts lines to CR/LF.  This bash problem
+  # is reportedly fixed, but why not run on old versions too?
+  sed '$q' "$ltmain" >> "$cfgfile" \
+     || (rm -f "$cfgfile"; exit 1)
+
+  if test x"$xsi_shell" = xyes; then
+  sed -e '/^func_dirname ()$/,/^} # func_dirname /c\
+func_dirname ()\
+{\
+\    case ${1} in\
+\      */*) func_dirname_result="${1%/*}${2}" ;;\
+\      *  ) func_dirname_result="${3}" ;;\
+\    esac\
+} # Extended-shell func_dirname implementation' "$cfgfile" > $cfgfile.tmp \
+  && mv -f "$cfgfile.tmp" "$cfgfile" \
+    || (rm -f "$cfgfile" && cp "$cfgfile.tmp" "$cfgfile" && rm -f "$cfgfile.tmp")
+test 0 -eq $? || _lt_function_replace_fail=:
+
+
+  sed -e '/^func_basename ()$/,/^} # func_basename /c\
+func_basename ()\
+{\
+\    func_basename_result="${1##*/}"\
+} # Extended-shell func_basename implementation' "$cfgfile" > $cfgfile.tmp \
+  && mv -f "$cfgfile.tmp" "$cfgfile" \
+    || (rm -f "$cfgfile" && cp "$cfgfile.tmp" "$cfgfile" && rm -f "$cfgfile.tmp")
+test 0 -eq $? || _lt_function_replace_fail=:
+
+
+  sed -e '/^func_dirname_and_basename ()$/,/^} # func_dirname_and_basename /c\
+func_dirname_and_basename ()\
+{\
+\    case ${1} in\
+\      */*) func_dirname_result="${1%/*}${2}" ;;\
+\      *  ) func_dirname_result="${3}" ;;\
+\    esac\
+\    func_basename_result="${1##*/}"\
+} # Extended-shell func_dirname_and_basename implementation' "$cfgfile" > $cfgfile.tmp \
+  && mv -f "$cfgfile.tmp" "$cfgfile" \
+    || (rm -f "$cfgfile" && cp "$cfgfile.tmp" "$cfgfile" && rm -f "$cfgfile.tmp")
+test 0 -eq $? || _lt_function_replace_fail=:
+
+
+  sed -e '/^func_stripname ()$/,/^} # func_stripname /c\
+func_stripname ()\
+{\
+\    # pdksh 5.2.14 does not do ${X%$Y} correctly if both X and Y are\
+\    # positional parameters, so assign one to ordinary parameter first.\
+\    func_stripname_result=${3}\
+\    func_stripname_result=${func_stripname_result#"${1}"}\
+\    func_stripname_result=${func_stripname_result%"${2}"}\
+} # Extended-shell func_stripname implementation' "$cfgfile" > $cfgfile.tmp \
+  && mv -f "$cfgfile.tmp" "$cfgfile" \
+    || (rm -f "$cfgfile" && cp "$cfgfile.tmp" "$cfgfile" && rm -f "$cfgfile.tmp")
+test 0 -eq $? || _lt_function_replace_fail=:
+
+
+  sed -e '/^func_split_long_opt ()$/,/^} # func_split_long_opt /c\
+func_split_long_opt ()\
+{\
+\    func_split_long_opt_name=${1%%=*}\
+\    func_split_long_opt_arg=${1#*=}\
+} # Extended-shell func_split_long_opt implementation' "$cfgfile" > $cfgfile.tmp \
+  && mv -f "$cfgfile.tmp" "$cfgfile" \
+    || (rm -f "$cfgfile" && cp "$cfgfile.tmp" "$cfgfile" && rm -f "$cfgfile.tmp")
+test 0 -eq $? || _lt_function_replace_fail=:
+
+
+  sed -e '/^func_split_short_opt ()$/,/^} # func_split_short_opt /c\
+func_split_short_opt ()\
+{\
+\    func_split_short_opt_arg=${1#??}\
+\    func_split_short_opt_name=${1%"$func_split_short_opt_arg"}\
+} # Extended-shell func_split_short_opt implementation' "$cfgfile" > $cfgfile.tmp \
+  && mv -f "$cfgfile.tmp" "$cfgfile" \
+    || (rm -f "$cfgfile" && cp "$cfgfile.tmp" "$cfgfile" && rm -f "$cfgfile.tmp")
+test 0 -eq $? || _lt_function_replace_fail=:
+
+
+  sed -e '/^func_lo2o ()$/,/^} # func_lo2o /c\
+func_lo2o ()\
+{\
+\    case ${1} in\
+\      *.lo) func_lo2o_result=${1%.lo}.${objext} ;;\
+\      *)    func_lo2o_result=${1} ;;\
+\    esac\
+} # Extended-shell func_lo2o implementation' "$cfgfile" > $cfgfile.tmp \
+  && mv -f "$cfgfile.tmp" "$cfgfile" \
+    || (rm -f "$cfgfile" && cp "$cfgfile.tmp" "$cfgfile" && rm -f "$cfgfile.tmp")
+test 0 -eq $? || _lt_function_replace_fail=:
+
+
+  sed -e '/^func_xform ()$/,/^} # func_xform /c\
+func_xform ()\
+{\
+    func_xform_result=${1%.*}.lo\
+} # Extended-shell func_xform implementation' "$cfgfile" > $cfgfile.tmp \
+  && mv -f "$cfgfile.tmp" "$cfgfile" \
+    || (rm -f "$cfgfile" && cp "$cfgfile.tmp" "$cfgfile" && rm -f "$cfgfile.tmp")
+test 0 -eq $? || _lt_function_replace_fail=:
+
+
+  sed -e '/^func_arith ()$/,/^} # func_arith /c\
+func_arith ()\
+{\
+    func_arith_result=$(( $* ))\
+} # Extended-shell func_arith implementation' "$cfgfile" > $cfgfile.tmp \
+  && mv -f "$cfgfile.tmp" "$cfgfile" \
+    || (rm -f "$cfgfile" && cp "$cfgfile.tmp" "$cfgfile" && rm -f "$cfgfile.tmp")
+test 0 -eq $? || _lt_function_replace_fail=:
+
+
+  sed -e '/^func_len ()$/,/^} # func_len /c\
+func_len ()\
+{\
+    func_len_result=${#1}\
+} # Extended-shell func_len implementation' "$cfgfile" > $cfgfile.tmp \
+  && mv -f "$cfgfile.tmp" "$cfgfile" \
+    || (rm -f "$cfgfile" && cp "$cfgfile.tmp" "$cfgfile" && rm -f "$cfgfile.tmp")
+test 0 -eq $? || _lt_function_replace_fail=:
+
+fi
+
+if test x"$lt_shell_append" = xyes; then
+  sed -e '/^func_append ()$/,/^} # func_append /c\
+func_append ()\
+{\
+    eval "${1}+=\\${2}"\
+} # Extended-shell func_append implementation' "$cfgfile" > $cfgfile.tmp \
+  && mv -f "$cfgfile.tmp" "$cfgfile" \
+    || (rm -f "$cfgfile" && cp "$cfgfile.tmp" "$cfgfile" && rm -f "$cfgfile.tmp")
+test 0 -eq $? || _lt_function_replace_fail=:
+
+
+  sed -e '/^func_append_quoted ()$/,/^} # func_append_quoted /c\
+func_append_quoted ()\
+{\
+\    func_quote_for_eval "${2}"\
+\    eval "${1}+=\\\\ \\$func_quote_for_eval_result"\
+} # Extended-shell func_append_quoted implementation' "$cfgfile" > $cfgfile.tmp \
+  && mv -f "$cfgfile.tmp" "$cfgfile" \
+    || (rm -f "$cfgfile" && cp "$cfgfile.tmp" "$cfgfile" && rm -f "$cfgfile.tmp")
+test 0 -eq $? || _lt_function_replace_fail=:
+
+
+  # Save a `func_append' function call where possible by direct use of '+='
+  sed -e 's%func_append \([a-zA-Z_]\{1,\}\) "%\1+="%g' $cfgfile > $cfgfile.tmp \
+    && mv -f "$cfgfile.tmp" "$cfgfile" \
+      || (rm -f "$cfgfile" && cp "$cfgfile.tmp" "$cfgfile" && rm -f "$cfgfile.tmp")
+  test 0 -eq $? || _lt_function_replace_fail=:
+else
+  # Save a `func_append' function call even when '+=' is not available
+  sed -e 's%func_append \([a-zA-Z_]\{1,\}\) "%\1="$\1%g' $cfgfile > $cfgfile.tmp \
+    && mv -f "$cfgfile.tmp" "$cfgfile" \
+      || (rm -f "$cfgfile" && cp "$cfgfile.tmp" "$cfgfile" && rm -f "$cfgfile.tmp")
+  test 0 -eq $? || _lt_function_replace_fail=:
+fi
+
+if test x"$_lt_function_replace_fail" = x":"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Unable to substitute extended shell functions in $ofile" >&5
+$as_echo "$as_me: WARNING: Unable to substitute extended shell functions in $ofile" >&2;}
+fi
+
+
+   mv -f "$cfgfile" "$ofile" ||
+    (rm -f "$ofile" && cp "$cfgfile" "$ofile" && rm -f "$cfgfile")
+  chmod +x "$ofile"
+
+ ;;
+
+  esac
+done # for ac_tag
+
+
+as_fn_exit 0
+_ACEOF
+ac_clean_files=$ac_clean_files_save
+
+test $ac_write_fail = 0 ||
+  as_fn_error $? "write failure creating $CONFIG_STATUS" "$LINENO" 5
+
+
+# configure is writing to config.log, and then calls config.status.
+# config.status does its own redirection, appending to config.log.
+# Unfortunately, on DOS this fails, as config.log is still kept open
+# by configure, so config.status won't be able to write to it; its
+# output is simply discarded.  So we exec the FD to /dev/null,
+# effectively closing config.log, so it can be properly (re)opened and
+# appended to by config.status.  When coming back to configure, we
+# need to make the FD available again.
+if test "$no_create" != yes; then
+  ac_cs_success=:
+  ac_config_status_args=
+  test "$silent" = yes &&
+    ac_config_status_args="$ac_config_status_args --quiet"
+  exec 5>/dev/null
+  $SHELL $CONFIG_STATUS $ac_config_status_args || ac_cs_success=false
+  exec 5>>config.log
+  # Use ||, not &&, to avoid exiting from the if with $? = 1, which
+  # would make configure fail if this is the last instruction.
+  $ac_cs_success || as_fn_exit 1
+fi
+if test -n "$ac_unrecognized_opts" && test "$enable_option_checking" != no; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: unrecognized options: $ac_unrecognized_opts" >&5
+$as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2;}
+fi
+
diff --git a/connman/configure.ac b/connman/configure.ac
new file mode 100644
index 0000000..1825527
--- /dev/null
+++ b/connman/configure.ac
@@ -0,0 +1,394 @@
+AC_PREREQ(2.60)
+AC_INIT(connman, 1.29)
+
+AM_INIT_AUTOMAKE([foreign subdir-objects color-tests])
+AC_CONFIG_HEADERS([config.h])
+
+m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
+
+AM_MAINTAINER_MODE
+
+AC_PREFIX_DEFAULT(/usr/local)
+
+PKG_PROG_PKG_CONFIG
+
+COMPILER_FLAGS
+
+AC_SUBST(abs_top_srcdir)
+AC_SUBST(abs_top_builddir)
+
+AC_LANG_C
+
+AC_PROG_CC
+AM_PROG_CC_C_O
+AC_PROG_CC_PIE
+AC_PROG_INSTALL
+AC_PROG_MKDIR_P
+
+m4_define([_LT_AC_TAGCONFIG], [])
+m4_ifdef([AC_LIBTOOL_TAGS], [AC_LIBTOOL_TAGS([])])
+
+AC_DISABLE_STATIC
+AC_PROG_LIBTOOL
+
+AC_ARG_ENABLE(optimization, AC_HELP_STRING([--disable-optimization],
+			[disable code optimization through compiler]), [
+	if (test "${enableval}" = "no"); then
+		CFLAGS="$CFLAGS -O0 -U_FORTIFY_SOURCE"
+	fi
+])
+
+AC_ARG_ENABLE(debug, AC_HELP_STRING([--enable-debug],
+			[enable compiling with debugging information]), [
+	if (test "${enableval}" = "yes" &&
+				test "${ac_cv_prog_cc_g}" = "yes"); then
+		CFLAGS="$CFLAGS -g"
+		AC_DEFINE(CONNMAN_DEBUG, 1, [Enable connman debugging code?])
+	fi
+])
+
+AC_ARG_ENABLE(pie, AC_HELP_STRING([--enable-pie],
+			[enable position independent executables flag]), [
+	if (test "${enableval}" = "yes" &&
+				test "${ac_cv_prog_cc_pie}" = "yes"); then
+		CFLAGS="$CFLAGS -fPIE"
+		LDFLAGS="$LDFLAGS -pie"
+	fi
+])
+
+AC_ARG_ENABLE(hh2serial-gps,
+	AC_HELP_STRING([--enable-hh2serial-gps], [enable hh2serial GPS support]),
+			[enable_hh2serial_gps=${enableval}], [enable_hh2serial_gps="no"])
+AM_CONDITIONAL(HH2SERIAL_GPS, test "${enable_hh2serial_gps}" != "no")
+AM_CONDITIONAL(HH2SERIAL_GPS_BUILTIN, test "${enable_hh2serial_gps}" = "builtin")
+
+AC_ARG_WITH(openconnect, AC_HELP_STRING([--with-openconnect=PROGRAM],
+        [specify location of openconnect binary]), [path_openconnect=${withval}])
+
+AC_ARG_ENABLE(openconnect,
+	AC_HELP_STRING([--enable-openconnect], [enable openconnect support]),
+			[enable_openconnect=${enableval}], [enable_openconnect="no"])
+if (test "${enable_openconnect}" != "no"); then
+	if (test -z "${path_openconnect}"); then
+		AC_PATH_PROG(OPENCONNECT, [openconnect], [], $PATH:/sbin:/usr/sbin)
+		if (test -z "${OPENCONNECT}"); then
+			AC_MSG_ERROR(openconnect binary not found)
+		fi
+	else
+		OPENCONNECT="${path_openconnect}"
+		AC_SUBST(OPENCONNECT)
+	fi
+fi
+AM_CONDITIONAL(OPENCONNECT, test "${enable_openconnect}" != "no")
+AM_CONDITIONAL(OPENCONNECT_BUILTIN, test "${enable_openconnect}" = "builtin")
+
+AC_ARG_WITH(openvpn, AC_HELP_STRING([--with-openvpn=PROGRAM],
+        [specify location of openvpn binary]), [path_openvpn=${withval}])
+
+AC_ARG_ENABLE(openvpn,
+	AC_HELP_STRING([--enable-openvpn], [enable openvpn support]),
+			[enable_openvpn=${enableval}], [enable_openvpn="no"])
+if (test "${enable_openvpn}" != "no"); then
+	if (test -z "${path_openvpn}"); then
+		AC_PATH_PROG(OPENVPN, [openvpn], [], $PATH:/sbin:/usr/sbin)
+		if (test -z "${OPENVPN}"); then
+			AC_MSG_ERROR(openvpn binary not found)
+		fi
+	else
+		OPENVPN="${path_openvpn}"
+		AC_SUBST(OPENVPN)
+	fi
+fi
+AM_CONDITIONAL(OPENVPN, test "${enable_openvpn}" != "no")
+AM_CONDITIONAL(OPENVPN_BUILTIN, test "${enable_openvpn}" = "builtin")
+
+AC_ARG_WITH(vpnc, AC_HELP_STRING([--with-vpnc=PROGRAM],
+	[specify location of vpnc binary]), [path_vpnc=${withval}])
+
+AC_ARG_ENABLE(vpnc,
+	AC_HELP_STRING([--enable-vpnc], [enable vpnc support]),
+		[enable_vpnc=${enableval}], [enable_vpnc="no"])
+if (test "${enable_vpnc}" != "no"); then
+	if (test -z "${path_vpnc}"); then
+		AC_PATH_PROG(VPNC, [vpnc], [], $PATH:/sbin:/usr/sbin)
+		if (test -z "${VPNC}"); then
+			AC_MSG_ERROR(vpnc binary not found)
+		fi
+	else
+		VPNC="${path_vpnc}"
+		AC_SUBST(VPNC)
+	fi
+fi
+AM_CONDITIONAL(VPNC, test "${enable_vpnc}" != "no")
+AM_CONDITIONAL(VPNC_BUILTIN, test "${enable_vpnc}" = "builtin")
+
+AC_ARG_WITH(l2tp, AC_HELP_STRING([--with-l2tp=PROGRAM],
+        [specify location of l2tp binary]), [path_l2tp=${withval}])
+
+AC_ARG_ENABLE(l2tp,
+	AC_HELP_STRING([--enable-l2tp], [enable l2tp support]),
+			[enable_l2tp=${enableval}], [enable_l2tp="no"])
+if (test "${enable_l2tp}" != "no"); then
+	if (test -z "${path_pppd}"); then
+		AC_PATH_PROG(PPPD, [pppd], [/usr/sbin/pppd], $PATH:/sbin:/usr/sbin)
+	else
+		PPPD="${path_pppd}"
+		AC_SUBST(PPPD)
+	fi
+	AC_CHECK_HEADERS(pppd/pppd.h, dummy=yes,
+			AC_MSG_ERROR(ppp header files are required))
+	if (test -z "${path_l2tp}"); then
+		AC_PATH_PROG(L2TP, [xl2tpd], [/usr/sbin/xl2tpd], $PATH:/sbin:/usr/sbin)
+	else
+		L2TP="${path_l2tp}"
+		AC_SUBST(L2TP)
+	fi
+fi
+AM_CONDITIONAL(L2TP, test "${enable_l2tp}" != "no")
+AM_CONDITIONAL(L2TP_BUILTIN, test "${enable_l2tp}" = "builtin")
+
+AC_ARG_WITH(pptp, AC_HELP_STRING([--with-pptp=PROGRAM],
+        [specify location of pptp binary]), [path_pptp=${withval}])
+
+AC_ARG_ENABLE(pptp,
+	AC_HELP_STRING([--enable-pptp], [enable pptp support]),
+			[enable_pptp=${enableval}], [enable_pptp="no"])
+if (test "${enable_pptp}" != "no"); then
+	if (test -z "${path_pppd}"); then
+		AC_PATH_PROG(PPPD, [pppd], [/usr/sbin/pppd], $PATH:/sbin:/usr/sbin)
+	else
+		PPPD="${path_pppd}"
+		AC_SUBST(PPPD)
+	fi
+	AC_CHECK_HEADERS(pppd/pppd.h, dummy=yes,
+			AC_MSG_ERROR(ppp header files are required))
+	if (test -z "${path_pptp}"); then
+		AC_PATH_PROG(PPTP, [pptp], [/usr/sbin/pptp], $PATH:/sbin:/usr/sbin)
+	else
+		PPTP="${path_pptp}"
+		AC_SUBST(PPTP)
+	fi
+fi
+AM_CONDITIONAL(PPTP, test "${enable_pptp}" != "no")
+AM_CONDITIONAL(PPTP_BUILTIN, test "${enable_pptp}" = "builtin")
+
+AC_CHECK_HEADERS(resolv.h, dummy=yes,
+	AC_MSG_ERROR(resolver header files are required))
+AC_CHECK_LIB(resolv, ns_initparse, dummy=yes, [
+	AC_CHECK_LIB(resolv, __ns_initparse, dummy=yes,
+		AC_MSG_ERROR(resolver library support is required))
+])
+
+AC_CHECK_FUNC(signalfd, dummy=yes,
+			AC_MSG_ERROR(signalfd support is required))
+
+AC_CHECK_LIB(dl, dlopen, dummy=yes,
+			AC_MSG_ERROR(dynamic linking loader is required))
+
+AC_ARG_ENABLE(iospm, AC_HELP_STRING([--enable-iospm],
+		[enable Intel OSPM support]), [enable_iospm=${enableval}])
+AM_CONDITIONAL(IOSPM, test "${enable_iospm}" = "yes")
+
+AC_ARG_ENABLE(tist,
+	AC_HELP_STRING([--enable-tist], [enable TI Shared Transport support]),
+			[enable_tist=${enableval}], [enable_tist="no"])
+AM_CONDITIONAL(TIST, test "${enable_tist}" != "no")
+AM_CONDITIONAL(TIST_BUILTIN, test "${enable_tist}" = "builtin")
+
+AC_ARG_ENABLE(session-policy-local,
+	AC_HELP_STRING([--enable-session-policy-local], [enable local file Session policy configuration support]),
+			[enable_session_policy_local=${enableval}], [enable_session_policy_local="no"])
+AM_CONDITIONAL(SESSION_POLICY_LOCAL, test "${enable_session_policy_local}" != "no")
+AM_CONDITIONAL(SESSION_POLICY_LOCAL_BUILTIN, test "${enable_session_policy_local}" = "builtin")
+
+AC_ARG_WITH(stats-max-file-size, AC_HELP_STRING([--with-stats-max-file-size=SIZE],
+			[Maximal size of a statistics round robin file]),
+			[stats_max_file_size=${withval}])
+
+if (test -z "${stats_max_file_size}"); then
+   # default size is 16 kByte
+   stats_max_file_size="16 * 8 * 128"
+fi
+
+AC_DEFINE_UNQUOTED([STATS_MAX_FILE_SIZE], (${stats_max_file_size}), [Maximal size of a statistics round robin file])
+
+PKG_CHECK_MODULES(GLIB, glib-2.0 >= 2.28, dummy=yes,
+				AC_MSG_ERROR(GLib >= 2.28 is required))
+AC_SUBST(GLIB_CFLAGS)
+AC_SUBST(GLIB_LIBS)
+
+PKG_CHECK_MODULES(DBUS, dbus-1 >= 1.4, dummy=yes,
+				AC_MSG_ERROR(D-Bus >= 1.4 is required))
+AC_SUBST(DBUS_CFLAGS)
+AC_SUBST(DBUS_LIBS)
+
+AC_ARG_WITH(dbusconfdir, AC_HELP_STRING([--with-dbusconfdir=PATH],
+	[path to D-Bus config directory]), [path_dbusconf=${withval}],
+		[path_dbusconf="`$PKG_CONFIG --variable=sysconfdir dbus-1`"])
+if (test -z "${path_dbusconf}"); then
+	DBUS_CONFDIR="${sysconfdir}/dbus-1/system.d"
+else
+	DBUS_CONFDIR="${path_dbusconf}/dbus-1/system.d"
+fi
+AC_SUBST(DBUS_CONFDIR)
+
+AC_ARG_WITH(dbusdatadir, AC_HELP_STRING([--with-dbusdatadir=PATH],
+	[path to D-Bus data directory]), [path_dbusdata=${withval}],
+		[path_dbusdata="`$PKG_CONFIG --variable=datadir dbus-1`"])
+if (test -z "${path_dbusdata}"); then
+	DBUS_DATADIR="${datadir}/dbus-1/system-services"
+else
+	DBUS_DATADIR="${path_dbusdata}/dbus-1/system-services"
+fi
+AC_SUBST(DBUS_DATADIR)
+
+AC_ARG_WITH([systemdunitdir], AC_HELP_STRING([--with-systemdunitdir=DIR],
+	[path to systemd service directory]), [path_systemdunit=${withval}],
+		[path_systemdunit="`$PKG_CONFIG --variable=systemdsystemunitdir systemd`"])
+if (test -n "${path_systemdunit}"); then
+	SYSTEMD_UNITDIR="${path_systemdunit}"
+	AC_SUBST(SYSTEMD_UNITDIR)
+fi
+AM_CONDITIONAL(SYSTEMD, test -n "${path_systemdunit}")
+
+PKG_CHECK_MODULES(XTABLES, xtables >= 1.4.11, dummy=yes,
+				AC_MSG_ERROR(Xtables library is required))
+AC_SUBST(XTABLES_CFLAGS)
+AC_SUBST(XTABLES_LIBS)
+
+AC_ARG_ENABLE(test, AC_HELP_STRING([--enable-test],
+		[enable test/example scripts]), [enable_test=${enableval}])
+AM_CONDITIONAL(TEST, test "${enable_test}" = "yes")
+
+AC_ARG_ENABLE(nmcompat, AC_HELP_STRING([--enable-nmcompat],
+				[enable Network Manager support]),
+			[enable_nmcompat=${enableval}], [enable_nmcompat="no"])
+AM_CONDITIONAL(NMCOMPAT, test "${enable_nmcompat}" != "no")
+
+AC_ARG_ENABLE(polkit, AC_HELP_STRING([--enable-polkit],
+				[enable PolicyKit support]),
+			[enable_polkit=${enableval}], [enable_polkit="no"])
+if (test "${enable_polkit}" != "no"); then
+	POLKIT_DATADIR="`$PKG_CONFIG --variable=actiondir polkit`"
+	POLKIT_DATADIR=""
+	if (test -z "${POLKIT_DATADIR}"); then
+		POLKIT_DATADIR="${datadir}/polkit-1/actions"
+	fi
+	AC_SUBST(POLKIT_DATADIR)
+fi
+AM_CONDITIONAL(POLKIT, test "${enable_polkit}" != "no")
+
+AC_ARG_ENABLE(selinux, AC_HELP_STRING([--enable-selinux],
+				[enable selinux support]),
+			[enable_selinux=${enableval}], [enable_selinux="no"])
+AM_CONDITIONAL(SELINUX, test "${enable_selinux}" != "no")
+
+AC_ARG_ENABLE(loopback, AC_HELP_STRING([--disable-loopback],
+				[disable loopback support]),
+					[enable_loopback=${enableval}])
+AM_CONDITIONAL(LOOPBACK, test "${enable_loopback}" != "no")
+
+AC_ARG_ENABLE(ethernet, AC_HELP_STRING([--disable-ethernet],
+				[disable Ethernet support]),
+					[enable_ethernet=${enableval}])
+AM_CONDITIONAL(ETHERNET, test "${enable_ethernet}" != "no")
+
+AC_ARG_ENABLE(gadget, AC_HELP_STRING([--disable-gadget],
+				[disable USB Gadget support]),
+					[enable_gadget=${enableval}])
+AM_CONDITIONAL(GADGET, test "${enable_gadget}" != "no")
+
+AC_ARG_ENABLE(wifi, AC_HELP_STRING([--disable-wifi],
+				[disable WiFi support]),
+					[enable_wifi=${enableval}])
+AM_CONDITIONAL(WIFI, test "${enable_wifi}" != "no")
+
+AC_ARG_ENABLE(bluetooth, AC_HELP_STRING([--disable-bluetooth],
+				[disable Bluetooth support]),
+					[enable_bluetooth=${enableval}])
+AM_CONDITIONAL(BLUETOOTH, test "${enable_bluetooth}" != "no")
+
+AC_ARG_ENABLE(ofono, AC_HELP_STRING([--disable-ofono],
+				[disable oFono support]),
+					[enable_ofono=${enableval}])
+AM_CONDITIONAL(OFONO, test "${enable_ofono}" != "no")
+
+AC_ARG_ENABLE(dundee, AC_HELP_STRING([--disable-dundee],
+				[disable dundee support (Bluetooth DUN)]),
+					[enable_dundee=${enableval}])
+AM_CONDITIONAL(DUNDEE, test "${enable_dundee}" != "no")
+
+AC_ARG_ENABLE(pacrunner, AC_HELP_STRING([--disable-pacrunner],
+				[disable PACrunner support]),
+					[enable_pacrunner=${enableval}])
+AM_CONDITIONAL(PACRUNNER, test "${enable_pacrunner}" != "no")
+
+AC_ARG_ENABLE(neard, AC_HELP_STRING([--disable-neard],
+				[disable Neard support]),
+					[enable_neard=${enableval}])
+AM_CONDITIONAL(NEARD, test "${enable_neard}" != "no")
+
+AC_ARG_ENABLE(wispr, AC_HELP_STRING([--disable-wispr],
+				[disable WISPr support]),
+					[enable_wispr=${enableval}])
+AM_CONDITIONAL(WISPR, test "${enable_wispr}" != "no")
+
+AC_ARG_ENABLE(tools, AC_HELP_STRING([--disable-tools],
+				[disable testing tools]),
+					[enable_tools=${enableval}])
+AM_CONDITIONAL(TOOLS, test "${enable_tools}" != "no")
+
+if (test "${enable_tools}" != "no"); then
+	AC_PATH_PROGS(IPTABLES_SAVE, [iptables-save], [],
+						$PATH:/sbin:/usr/sbin)
+	IPTABLES_SAVE=$ac_cv_path_IPTABLES_SAVE
+else
+	IPTABLES_SAVE=""
+fi
+AC_SUBST(IPTABLES_SAVE)
+
+AC_ARG_ENABLE(client, AC_HELP_STRING([--disable-client],
+				[disable command line client]),
+					[enable_client=${enableval}])
+AM_CONDITIONAL(CLIENT, test "${enable_client}" != "no")
+
+if (test "${enable_wispr}" != "no"); then
+	PKG_CHECK_MODULES(GNUTLS, gnutls, dummy=yes,
+				AC_MSG_ERROR(GnuTLS library is required))
+else
+	GNUTLS_CFLAGS=""
+	GNUTLS_LIBS=""
+fi
+AC_SUBST(GNUTLS_CFLAGS)
+AC_SUBST(GNUTLS_LIBS)
+
+if (test "${enable_loopback}" != "no"); then
+	AC_CHECK_HEADERS(sys/inotify.h, dummy=yes,
+			AC_MSG_ERROR(inotify header files are required))
+
+	AC_CHECK_LIB(c, inotify_init, dummy=yes,
+			AC_MSG_ERROR(inotify library support is required))
+fi
+
+if (test "${enable_wifi}" != "no"); then
+	AC_PATH_PROG(WPASUPPLICANT, [wpa_supplicant], [],
+						$PATH:/sbin:/usr/sbin)
+fi
+
+AC_ARG_ENABLE(datafiles, AC_HELP_STRING([--disable-datafiles],
+			[don't install configuration and data files]),
+					[enable_datafiles=${enableval}])
+AM_CONDITIONAL(DATAFILES, test "${enable_datafiles}" != "no")
+
+if (test "${enable_client}" != "no"); then
+	AC_CHECK_HEADERS(readline/readline.h, dummy=yes,
+		AC_MSG_ERROR(readline header files are required))
+fi
+
+AM_CONDITIONAL(VPN, test "${enable_openconnect}" != "no" -o \
+			"${enable_openvpn}" != "no" -o \
+			"${enable_vpnc}" != "no" -o \
+			"${enable_l2tp}" != "no" -o \
+			"${enable_pptp}" != "no")
+
+AC_OUTPUT(Makefile include/version.h connman.pc)
diff --git a/connman/connman.pc.in b/connman/connman.pc.in
new file mode 100644
index 0000000..2af3c2b
--- /dev/null
+++ b/connman/connman.pc.in
@@ -0,0 +1,14 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+ 
+plugindir=${libdir}/connman/plugins
+scriptdir=${libdir}/connman/scripts
+
+Name: connman
+Description: Connection Manager
+Requires: glib-2.0 dbus-1
+Version: @VERSION@
+Libs: -module -avoid-version -export-symbols-regex connman_plugin_desc
+Cflags: -I${includedir}
diff --git a/connman/depcomp b/connman/depcomp
new file mode 100755
index 0000000..4ebd5b3
--- /dev/null
+++ b/connman/depcomp
@@ -0,0 +1,791 @@
+#! /bin/sh
+# depcomp - compile a program generating dependencies as side-effects
+
+scriptversion=2013-05-30.07; # UTC
+
+# Copyright (C) 1999-2013 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+
+# 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, see <http://www.gnu.org/licenses/>.
+
+# As a special exception to the GNU General Public License, if you
+# distribute this file as part of a program that contains a
+# configuration script generated by Autoconf, you may include it under
+# the same distribution terms that you use for the rest of that program.
+
+# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
+
+case $1 in
+  '')
+    echo "$0: No command.  Try '$0 --help' for more information." 1>&2
+    exit 1;
+    ;;
+  -h | --h*)
+    cat <<\EOF
+Usage: depcomp [--help] [--version] PROGRAM [ARGS]
+
+Run PROGRAMS ARGS to compile a file, generating dependencies
+as side-effects.
+
+Environment variables:
+  depmode     Dependency tracking mode.
+  source      Source file read by 'PROGRAMS ARGS'.
+  object      Object file output by 'PROGRAMS ARGS'.
+  DEPDIR      directory where to store dependencies.
+  depfile     Dependency file to output.
+  tmpdepfile  Temporary file to use when outputting dependencies.
+  libtool     Whether libtool is used (yes/no).
+
+Report bugs to <bug-automake@gnu.org>.
+EOF
+    exit $?
+    ;;
+  -v | --v*)
+    echo "depcomp $scriptversion"
+    exit $?
+    ;;
+esac
+
+# Get the directory component of the given path, and save it in the
+# global variables '$dir'.  Note that this directory component will
+# be either empty or ending with a '/' character.  This is deliberate.
+set_dir_from ()
+{
+  case $1 in
+    */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
+      *) dir=;;
+  esac
+}
+
+# Get the suffix-stripped basename of the given path, and save it the
+# global variable '$base'.
+set_base_from ()
+{
+  base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
+}
+
+# If no dependency file was actually created by the compiler invocation,
+# we still have to create a dummy depfile, to avoid errors with the
+# Makefile "include basename.Plo" scheme.
+make_dummy_depfile ()
+{
+  echo "#dummy" > "$depfile"
+}
+
+# Factor out some common post-processing of the generated depfile.
+# Requires the auxiliary global variable '$tmpdepfile' to be set.
+aix_post_process_depfile ()
+{
+  # If the compiler actually managed to produce a dependency file,
+  # post-process it.
+  if test -f "$tmpdepfile"; then
+    # Each line is of the form 'foo.o: dependency.h'.
+    # Do two passes, one to just change these to
+    #   $object: dependency.h
+    # and one to simply output
+    #   dependency.h:
+    # which is needed to avoid the deleted-header problem.
+    { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
+      sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
+    } > "$depfile"
+    rm -f "$tmpdepfile"
+  else
+    make_dummy_depfile
+  fi
+}
+
+# A tabulation character.
+tab='	'
+# A newline character.
+nl='
+'
+# Character ranges might be problematic outside the C locale.
+# These definitions help.
+upper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
+lower=abcdefghijklmnopqrstuvwxyz
+digits=0123456789
+alpha=${upper}${lower}
+
+if test -z "$depmode" || test -z "$source" || test -z "$object"; then
+  echo "depcomp: Variables source, object and depmode must be set" 1>&2
+  exit 1
+fi
+
+# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
+depfile=${depfile-`echo "$object" |
+  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
+tmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
+
+rm -f "$tmpdepfile"
+
+# Avoid interferences from the environment.
+gccflag= dashmflag=
+
+# Some modes work just like other modes, but use different flags.  We
+# parameterize here, but still list the modes in the big case below,
+# to make depend.m4 easier to write.  Note that we *cannot* use a case
+# here, because this file can only contain one case statement.
+if test "$depmode" = hp; then
+  # HP compiler uses -M and no extra arg.
+  gccflag=-M
+  depmode=gcc
+fi
+
+if test "$depmode" = dashXmstdout; then
+  # This is just like dashmstdout with a different argument.
+  dashmflag=-xM
+  depmode=dashmstdout
+fi
+
+cygpath_u="cygpath -u -f -"
+if test "$depmode" = msvcmsys; then
+  # This is just like msvisualcpp but w/o cygpath translation.
+  # Just convert the backslash-escaped backslashes to single forward
+  # slashes to satisfy depend.m4
+  cygpath_u='sed s,\\\\,/,g'
+  depmode=msvisualcpp
+fi
+
+if test "$depmode" = msvc7msys; then
+  # This is just like msvc7 but w/o cygpath translation.
+  # Just convert the backslash-escaped backslashes to single forward
+  # slashes to satisfy depend.m4
+  cygpath_u='sed s,\\\\,/,g'
+  depmode=msvc7
+fi
+
+if test "$depmode" = xlc; then
+  # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
+  gccflag=-qmakedep=gcc,-MF
+  depmode=gcc
+fi
+
+case "$depmode" in
+gcc3)
+## gcc 3 implements dependency tracking that does exactly what
+## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
+## it if -MD -MP comes after the -MF stuff.  Hmm.
+## Unfortunately, FreeBSD c89 acceptance of flags depends upon
+## the command line argument order; so add the flags where they
+## appear in depend2.am.  Note that the slowdown incurred here
+## affects only configure: in makefiles, %FASTDEP% shortcuts this.
+  for arg
+  do
+    case $arg in
+    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
+    *)  set fnord "$@" "$arg" ;;
+    esac
+    shift # fnord
+    shift # $arg
+  done
+  "$@"
+  stat=$?
+  if test $stat -ne 0; then
+    rm -f "$tmpdepfile"
+    exit $stat
+  fi
+  mv "$tmpdepfile" "$depfile"
+  ;;
+
+gcc)
+## Note that this doesn't just cater to obsosete pre-3.x GCC compilers.
+## but also to in-use compilers like IMB xlc/xlC and the HP C compiler.
+## (see the conditional assignment to $gccflag above).
+## There are various ways to get dependency output from gcc.  Here's
+## why we pick this rather obscure method:
+## - Don't want to use -MD because we'd like the dependencies to end
+##   up in a subdir.  Having to rename by hand is ugly.
+##   (We might end up doing this anyway to support other compilers.)
+## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
+##   -MM, not -M (despite what the docs say).  Also, it might not be
+##   supported by the other compilers which use the 'gcc' depmode.
+## - Using -M directly means running the compiler twice (even worse
+##   than renaming).
+  if test -z "$gccflag"; then
+    gccflag=-MD,
+  fi
+  "$@" -Wp,"$gccflag$tmpdepfile"
+  stat=$?
+  if test $stat -ne 0; then
+    rm -f "$tmpdepfile"
+    exit $stat
+  fi
+  rm -f "$depfile"
+  echo "$object : \\" > "$depfile"
+  # The second -e expression handles DOS-style file names with drive
+  # letters.
+  sed -e 's/^[^:]*: / /' \
+      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
+## This next piece of magic avoids the "deleted header file" problem.
+## The problem is that when a header file which appears in a .P file
+## is deleted, the dependency causes make to die (because there is
+## typically no way to rebuild the header).  We avoid this by adding
+## dummy dependencies for each header file.  Too bad gcc doesn't do
+## this for us directly.
+## Some versions of gcc put a space before the ':'.  On the theory
+## that the space means something, we add a space to the output as
+## well.  hp depmode also adds that space, but also prefixes the VPATH
+## to the object.  Take care to not repeat it in the output.
+## Some versions of the HPUX 10.20 sed can't process this invocation
+## correctly.  Breaking it into two sed invocations is a workaround.
+  tr ' ' "$nl" < "$tmpdepfile" \
+    | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
+    | sed -e 's/$/ :/' >> "$depfile"
+  rm -f "$tmpdepfile"
+  ;;
+
+hp)
+  # This case exists only to let depend.m4 do its work.  It works by
+  # looking at the text of this script.  This case will never be run,
+  # since it is checked for above.
+  exit 1
+  ;;
+
+sgi)
+  if test "$libtool" = yes; then
+    "$@" "-Wp,-MDupdate,$tmpdepfile"
+  else
+    "$@" -MDupdate "$tmpdepfile"
+  fi
+  stat=$?
+  if test $stat -ne 0; then
+    rm -f "$tmpdepfile"
+    exit $stat
+  fi
+  rm -f "$depfile"
+
+  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
+    echo "$object : \\" > "$depfile"
+    # Clip off the initial element (the dependent).  Don't try to be
+    # clever and replace this with sed code, as IRIX sed won't handle
+    # lines with more than a fixed number of characters (4096 in
+    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
+    # the IRIX cc adds comments like '#:fec' to the end of the
+    # dependency line.
+    tr ' ' "$nl" < "$tmpdepfile" \
+      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
+      | tr "$nl" ' ' >> "$depfile"
+    echo >> "$depfile"
+    # The second pass generates a dummy entry for each header file.
+    tr ' ' "$nl" < "$tmpdepfile" \
+      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
+      >> "$depfile"
+  else
+    make_dummy_depfile
+  fi
+  rm -f "$tmpdepfile"
+  ;;
+
+xlc)
+  # This case exists only to let depend.m4 do its work.  It works by
+  # looking at the text of this script.  This case will never be run,
+  # since it is checked for above.
+  exit 1
+  ;;
+
+aix)
+  # The C for AIX Compiler uses -M and outputs the dependencies
+  # in a .u file.  In older versions, this file always lives in the
+  # current directory.  Also, the AIX compiler puts '$object:' at the
+  # start of each line; $object doesn't have directory information.
+  # Version 6 uses the directory in both cases.
+  set_dir_from "$object"
+  set_base_from "$object"
+  if test "$libtool" = yes; then
+    tmpdepfile1=$dir$base.u
+    tmpdepfile2=$base.u
+    tmpdepfile3=$dir.libs/$base.u
+    "$@" -Wc,-M
+  else
+    tmpdepfile1=$dir$base.u
+    tmpdepfile2=$dir$base.u
+    tmpdepfile3=$dir$base.u
+    "$@" -M
+  fi
+  stat=$?
+  if test $stat -ne 0; then
+    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
+    exit $stat
+  fi
+
+  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
+  do
+    test -f "$tmpdepfile" && break
+  done
+  aix_post_process_depfile
+  ;;
+
+tcc)
+  # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
+  # FIXME: That version still under development at the moment of writing.
+  #        Make that this statement remains true also for stable, released
+  #        versions.
+  # It will wrap lines (doesn't matter whether long or short) with a
+  # trailing '\', as in:
+  #
+  #   foo.o : \
+  #    foo.c \
+  #    foo.h \
+  #
+  # It will put a trailing '\' even on the last line, and will use leading
+  # spaces rather than leading tabs (at least since its commit 0394caf7
+  # "Emit spaces for -MD").
+  "$@" -MD -MF "$tmpdepfile"
+  stat=$?
+  if test $stat -ne 0; then
+    rm -f "$tmpdepfile"
+    exit $stat
+  fi
+  rm -f "$depfile"
+  # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
+  # We have to change lines of the first kind to '$object: \'.
+  sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
+  # And for each line of the second kind, we have to emit a 'dep.h:'
+  # dummy dependency, to avoid the deleted-header problem.
+  sed -n -e 's|^  *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
+  rm -f "$tmpdepfile"
+  ;;
+
+## The order of this option in the case statement is important, since the
+## shell code in configure will try each of these formats in the order
+## listed in this file.  A plain '-MD' option would be understood by many
+## compilers, so we must ensure this comes after the gcc and icc options.
+pgcc)
+  # Portland's C compiler understands '-MD'.
+  # Will always output deps to 'file.d' where file is the root name of the
+  # source file under compilation, even if file resides in a subdirectory.
+  # The object file name does not affect the name of the '.d' file.
+  # pgcc 10.2 will output
+  #    foo.o: sub/foo.c sub/foo.h
+  # and will wrap long lines using '\' :
+  #    foo.o: sub/foo.c ... \
+  #     sub/foo.h ... \
+  #     ...
+  set_dir_from "$object"
+  # Use the source, not the object, to determine the base name, since
+  # that's sadly what pgcc will do too.
+  set_base_from "$source"
+  tmpdepfile=$base.d
+
+  # For projects that build the same source file twice into different object
+  # files, the pgcc approach of using the *source* file root name can cause
+  # problems in parallel builds.  Use a locking strategy to avoid stomping on
+  # the same $tmpdepfile.
+  lockdir=$base.d-lock
+  trap "
+    echo '$0: caught signal, cleaning up...' >&2
+    rmdir '$lockdir'
+    exit 1
+  " 1 2 13 15
+  numtries=100
+  i=$numtries
+  while test $i -gt 0; do
+    # mkdir is a portable test-and-set.
+    if mkdir "$lockdir" 2>/dev/null; then
+      # This process acquired the lock.
+      "$@" -MD
+      stat=$?
+      # Release the lock.
+      rmdir "$lockdir"
+      break
+    else
+      # If the lock is being held by a different process, wait
+      # until the winning process is done or we timeout.
+      while test -d "$lockdir" && test $i -gt 0; do
+        sleep 1
+        i=`expr $i - 1`
+      done
+    fi
+    i=`expr $i - 1`
+  done
+  trap - 1 2 13 15
+  if test $i -le 0; then
+    echo "$0: failed to acquire lock after $numtries attempts" >&2
+    echo "$0: check lockdir '$lockdir'" >&2
+    exit 1
+  fi
+
+  if test $stat -ne 0; then
+    rm -f "$tmpdepfile"
+    exit $stat
+  fi
+  rm -f "$depfile"
+  # Each line is of the form `foo.o: dependent.h',
+  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
+  # Do two passes, one to just change these to
+  # `$object: dependent.h' and one to simply `dependent.h:'.
+  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
+  # Some versions of the HPUX 10.20 sed can't process this invocation
+  # correctly.  Breaking it into two sed invocations is a workaround.
+  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
+    | sed -e 's/$/ :/' >> "$depfile"
+  rm -f "$tmpdepfile"
+  ;;
+
+hp2)
+  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
+  # compilers, which have integrated preprocessors.  The correct option
+  # to use with these is +Maked; it writes dependencies to a file named
+  # 'foo.d', which lands next to the object file, wherever that
+  # happens to be.
+  # Much of this is similar to the tru64 case; see comments there.
+  set_dir_from  "$object"
+  set_base_from "$object"
+  if test "$libtool" = yes; then
+    tmpdepfile1=$dir$base.d
+    tmpdepfile2=$dir.libs/$base.d
+    "$@" -Wc,+Maked
+  else
+    tmpdepfile1=$dir$base.d
+    tmpdepfile2=$dir$base.d
+    "$@" +Maked
+  fi
+  stat=$?
+  if test $stat -ne 0; then
+     rm -f "$tmpdepfile1" "$tmpdepfile2"
+     exit $stat
+  fi
+
+  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
+  do
+    test -f "$tmpdepfile" && break
+  done
+  if test -f "$tmpdepfile"; then
+    sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
+    # Add 'dependent.h:' lines.
+    sed -ne '2,${
+               s/^ *//
+               s/ \\*$//
+               s/$/:/
+               p
+             }' "$tmpdepfile" >> "$depfile"
+  else
+    make_dummy_depfile
+  fi
+  rm -f "$tmpdepfile" "$tmpdepfile2"
+  ;;
+
+tru64)
+  # The Tru64 compiler uses -MD to generate dependencies as a side
+  # effect.  'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
+  # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
+  # dependencies in 'foo.d' instead, so we check for that too.
+  # Subdirectories are respected.
+  set_dir_from  "$object"
+  set_base_from "$object"
+
+  if test "$libtool" = yes; then
+    # Libtool generates 2 separate objects for the 2 libraries.  These
+    # two compilations output dependencies in $dir.libs/$base.o.d and
+    # in $dir$base.o.d.  We have to check for both files, because
+    # one of the two compilations can be disabled.  We should prefer
+    # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
+    # automatically cleaned when .libs/ is deleted, while ignoring
+    # the former would cause a distcleancheck panic.
+    tmpdepfile1=$dir$base.o.d          # libtool 1.5
+    tmpdepfile2=$dir.libs/$base.o.d    # Likewise.
+    tmpdepfile3=$dir.libs/$base.d      # Compaq CCC V6.2-504
+    "$@" -Wc,-MD
+  else
+    tmpdepfile1=$dir$base.d
+    tmpdepfile2=$dir$base.d
+    tmpdepfile3=$dir$base.d
+    "$@" -MD
+  fi
+
+  stat=$?
+  if test $stat -ne 0; then
+    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
+    exit $stat
+  fi
+
+  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
+  do
+    test -f "$tmpdepfile" && break
+  done
+  # Same post-processing that is required for AIX mode.
+  aix_post_process_depfile
+  ;;
+
+msvc7)
+  if test "$libtool" = yes; then
+    showIncludes=-Wc,-showIncludes
+  else
+    showIncludes=-showIncludes
+  fi
+  "$@" $showIncludes > "$tmpdepfile"
+  stat=$?
+  grep -v '^Note: including file: ' "$tmpdepfile"
+  if test $stat -ne 0; then
+    rm -f "$tmpdepfile"
+    exit $stat
+  fi
+  rm -f "$depfile"
+  echo "$object : \\" > "$depfile"
+  # The first sed program below extracts the file names and escapes
+  # backslashes for cygpath.  The second sed program outputs the file
+  # name when reading, but also accumulates all include files in the
+  # hold buffer in order to output them again at the end.  This only
+  # works with sed implementations that can handle large buffers.
+  sed < "$tmpdepfile" -n '
+/^Note: including file:  *\(.*\)/ {
+  s//\1/
+  s/\\/\\\\/g
+  p
+}' | $cygpath_u | sort -u | sed -n '
+s/ /\\ /g
+s/\(.*\)/'"$tab"'\1 \\/p
+s/.\(.*\) \\/\1:/
+H
+$ {
+  s/.*/'"$tab"'/
+  G
+  p
+}' >> "$depfile"
+  echo >> "$depfile" # make sure the fragment doesn't end with a backslash
+  rm -f "$tmpdepfile"
+  ;;
+
+msvc7msys)
+  # This case exists only to let depend.m4 do its work.  It works by
+  # looking at the text of this script.  This case will never be run,
+  # since it is checked for above.
+  exit 1
+  ;;
+
+#nosideeffect)
+  # This comment above is used by automake to tell side-effect
+  # dependency tracking mechanisms from slower ones.
+
+dashmstdout)
+  # Important note: in order to support this mode, a compiler *must*
+  # always write the preprocessed file to stdout, regardless of -o.
+  "$@" || exit $?
+
+  # Remove the call to Libtool.
+  if test "$libtool" = yes; then
+    while test "X$1" != 'X--mode=compile'; do
+      shift
+    done
+    shift
+  fi
+
+  # Remove '-o $object'.
+  IFS=" "
+  for arg
+  do
+    case $arg in
+    -o)
+      shift
+      ;;
+    $object)
+      shift
+      ;;
+    *)
+      set fnord "$@" "$arg"
+      shift # fnord
+      shift # $arg
+      ;;
+    esac
+  done
+
+  test -z "$dashmflag" && dashmflag=-M
+  # Require at least two characters before searching for ':'
+  # in the target name.  This is to cope with DOS-style filenames:
+  # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
+  "$@" $dashmflag |
+    sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
+  rm -f "$depfile"
+  cat < "$tmpdepfile" > "$depfile"
+  # Some versions of the HPUX 10.20 sed can't process this sed invocation
+  # correctly.  Breaking it into two sed invocations is a workaround.
+  tr ' ' "$nl" < "$tmpdepfile" \
+    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
+    | sed -e 's/$/ :/' >> "$depfile"
+  rm -f "$tmpdepfile"
+  ;;
+
+dashXmstdout)
+  # This case only exists to satisfy depend.m4.  It is never actually
+  # run, as this mode is specially recognized in the preamble.
+  exit 1
+  ;;
+
+makedepend)
+  "$@" || exit $?
+  # Remove any Libtool call
+  if test "$libtool" = yes; then
+    while test "X$1" != 'X--mode=compile'; do
+      shift
+    done
+    shift
+  fi
+  # X makedepend
+  shift
+  cleared=no eat=no
+  for arg
+  do
+    case $cleared in
+    no)
+      set ""; shift
+      cleared=yes ;;
+    esac
+    if test $eat = yes; then
+      eat=no
+      continue
+    fi
+    case "$arg" in
+    -D*|-I*)
+      set fnord "$@" "$arg"; shift ;;
+    # Strip any option that makedepend may not understand.  Remove
+    # the object too, otherwise makedepend will parse it as a source file.
+    -arch)
+      eat=yes ;;
+    -*|$object)
+      ;;
+    *)
+      set fnord "$@" "$arg"; shift ;;
+    esac
+  done
+  obj_suffix=`echo "$object" | sed 's/^.*\././'`
+  touch "$tmpdepfile"
+  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
+  rm -f "$depfile"
+  # makedepend may prepend the VPATH from the source file name to the object.
+  # No need to regex-escape $object, excess matching of '.' is harmless.
+  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
+  # Some versions of the HPUX 10.20 sed can't process the last invocation
+  # correctly.  Breaking it into two sed invocations is a workaround.
+  sed '1,2d' "$tmpdepfile" \
+    | tr ' ' "$nl" \
+    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
+    | sed -e 's/$/ :/' >> "$depfile"
+  rm -f "$tmpdepfile" "$tmpdepfile".bak
+  ;;
+
+cpp)
+  # Important note: in order to support this mode, a compiler *must*
+  # always write the preprocessed file to stdout.
+  "$@" || exit $?
+
+  # Remove the call to Libtool.
+  if test "$libtool" = yes; then
+    while test "X$1" != 'X--mode=compile'; do
+      shift
+    done
+    shift
+  fi
+
+  # Remove '-o $object'.
+  IFS=" "
+  for arg
+  do
+    case $arg in
+    -o)
+      shift
+      ;;
+    $object)
+      shift
+      ;;
+    *)
+      set fnord "$@" "$arg"
+      shift # fnord
+      shift # $arg
+      ;;
+    esac
+  done
+
+  "$@" -E \
+    | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
+             -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
+    | sed '$ s: \\$::' > "$tmpdepfile"
+  rm -f "$depfile"
+  echo "$object : \\" > "$depfile"
+  cat < "$tmpdepfile" >> "$depfile"
+  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
+  rm -f "$tmpdepfile"
+  ;;
+
+msvisualcpp)
+  # Important note: in order to support this mode, a compiler *must*
+  # always write the preprocessed file to stdout.
+  "$@" || exit $?
+
+  # Remove the call to Libtool.
+  if test "$libtool" = yes; then
+    while test "X$1" != 'X--mode=compile'; do
+      shift
+    done
+    shift
+  fi
+
+  IFS=" "
+  for arg
+  do
+    case "$arg" in
+    -o)
+      shift
+      ;;
+    $object)
+      shift
+      ;;
+    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
+        set fnord "$@"
+        shift
+        shift
+        ;;
+    *)
+        set fnord "$@" "$arg"
+        shift
+        shift
+        ;;
+    esac
+  done
+  "$@" -E 2>/dev/null |
+  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
+  rm -f "$depfile"
+  echo "$object : \\" > "$depfile"
+  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
+  echo "$tab" >> "$depfile"
+  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
+  rm -f "$tmpdepfile"
+  ;;
+
+msvcmsys)
+  # This case exists only to let depend.m4 do its work.  It works by
+  # looking at the text of this script.  This case will never be run,
+  # since it is checked for above.
+  exit 1
+  ;;
+
+none)
+  exec "$@"
+  ;;
+
+*)
+  echo "Unknown depmode $depmode" 1>&2
+  exit 1
+  ;;
+esac
+
+exit 0
+
+# Local Variables:
+# mode: shell-script
+# sh-indentation: 2
+# eval: (add-hook 'write-file-hooks 'time-stamp)
+# time-stamp-start: "scriptversion="
+# time-stamp-format: "%:y-%02m-%02d.%02H"
+# time-stamp-time-zone: "UTC"
+# time-stamp-end: "; # UTC"
+# End:
diff --git a/connman/doc/advanced-configuration.txt b/connman/doc/advanced-configuration.txt
new file mode 100644
index 0000000..12c2250
--- /dev/null
+++ b/connman/doc/advanced-configuration.txt
@@ -0,0 +1,61 @@
+Advanced configuration interface
+********************************
+
+
+Configuration basics
+====================
+
+The default configuration method for all services is automatic or something
+like DHCP. In almost every case that should be just good enough, but if it
+is not, Connection Manager supports manual configuration for Ethernet and
+IP settings.
+
+
+Configuration interface
+=======================
+
+Every service contains two properties. One represents the current active
+configuration and the other one allows manual configuration via the user.
+
+For IPv4 they are named "IPv4" and IPv4.Configuration".
+
+[ /profile/default/wifi_001122334455_42696720696e204a6170616e_managed_psk ]
+    Type = wifi
+    Name = Big in Japan
+    Mode = managed
+    Strength = 82
+    Security = rsn
+    Favorite = true
+    State = ready
+    IPv4.Configuration = { Method=dhcp }
+    IPv4 = { Netmask=255.255.255.0 Method=dhcp Address=192.168.1.198 }
+
+The above WiFi network shows how the default configuration would look like
+with a connected service. The configuration method is DHCP and the current
+IP address is 192.168.1.198.
+
+The "IPv4" property is read-only and will emit PropertyChanged signals in
+case the IP address of this interface changes. The "IPv4.Configuration"
+property is read-write and allows changes. For example to use a static IP
+configuration this call could be used:
+
+    service.SetProperty("IPv4.Configuration", { "Method": "manual",
+    						"Address": "192.168.1.100",
+    						"Netmask": "255.255.255.0" })
+
+The configuration itself is a dictionary with various fields. Not all of
+them need to be present. A lot of combinations are valid.
+
+For example the "Method" field has valid settings of "off", "fixed", "manual"
+and "dhcp". The "fixed" value however can not be set by any user program. It
+is an internal value that some 3G cards require. Switching to "off" will
+remove any IP configuration from the interface. The "manual" method allows
+for static address configuration. And "dhcp" will use DHCP to retrieve all
+required information automatically.
+
+With a manual configuration, the fields "Address" and "Netmask" should be
+given. In case "Netmask" is left out, the best netmask will be calculated.
+
+The "Gateway" field can be used to indicate the default route/gateway for
+this interface.
+
diff --git a/connman/doc/agent-api.txt b/connman/doc/agent-api.txt
new file mode 100644
index 0000000..2ddd19a
--- /dev/null
+++ b/connman/doc/agent-api.txt
@@ -0,0 +1,305 @@
+Agent hierarchy
+===============
+
+Service		unique name
+Interface	net.connman.Agent
+Object path	freely definable
+
+Methods		void Release()
+
+			This method gets called when the service daemon
+			unregisters the agent. An agent can use it to do
+			cleanup tasks. There is no need to unregister the
+			agent, because when this method gets called it has
+			already been unregistered.
+
+		void ReportError(object service, string error)
+
+			This method gets called when an error has to be
+			reported to the user.
+
+			A special return value can be used to trigger a
+			retry of the failed transaction.
+
+			Possible Errors: net.connman.Agent.Error.Retry
+
+		void ReportPeerError(object peer, string error)
+
+			This method gets called when an error has to be
+			reported to the user about a peer connection.
+
+			A special return value can be used to trigger a
+			retry of the failed transaction.
+
+			Possible Errors: net.connman.Agent.Error.Retry
+
+		void RequestBrowser(object service, string url)
+
+			This method gets called when it is required
+			to ask the user to open a website to procceed
+			with login handling.
+
+			This can happen if connected to a hotspot portal
+			page without WISPr support.
+
+			Possible Errors: net.connman.Agent.Error.Canceled
+
+		dict RequestInput(object service, dict fields)
+
+			This method gets called when trying to connect to
+			a service and some extra input is required. For
+			example a passphrase or the name of a hidden network.
+
+			The return value should be a dictionary where the
+			keys are the field names and the values are the
+			actual fields. Alternatively an error indicating that
+			the request got canceled can be returned.
+
+			Most common return field names are "Name" and of
+			course "Passphrase".
+
+			The dictionary arguments contains field names with
+			their input parameters.
+
+			In case of WISPr credentials requests and if the user
+			prefers to login through the browser by himself, agent
+			will have to return a LaunchBrowser error (see below).
+
+			Possible Errors: net.connman.Agent.Error.Canceled
+					 net.connman.Agent.Error.LaunchBrowser
+
+		dict RequestPeerAuthorization(object peer, dict fields) [experimental]
+
+			This method gets called when trying to connect to a
+			peer or when an incoming peer connection is requested,
+			for which some extra input is required. In this case,
+			it will only deal with WPS input as well as accepting
+			or rejecting an incoming connection.
+
+			The return value should be a dictionary where the
+			keys are the field names and the values are the
+			actual fields. Alternatively an error indicating that
+			the request got canceled or rejected can be returned.
+
+			The dictionary arguments contains field names with
+			their input parameters.
+
+			Possible Errors: net.connman.Agent.Error.Canceled
+			                 net.connman.Agent.Error.Rejected
+
+		void Cancel()
+
+			This method gets called to indicate that the agent
+			request failed before a reply was returned.
+
+Fields		string Name
+
+			The name of a network. This field will be requested
+			when trying to connect to a hidden network.
+
+		array{byte} SSID
+
+			This field is an alternative to "Name" for WiFi
+			networks and can be used to return the exact binary
+			representation of a network name.
+
+			Normally returning the "Name" field is the better
+			option here.
+
+		string Identity
+
+			Identity (username) for EAP authentication methods.
+
+		string Passphrase
+
+			The passphrase for authentication. For example a WEP
+			key, a PSK passphrase or a passphrase for EAP
+			authentication methods.
+
+		string PreviousPassphrase
+
+			The previous passphrase successfully saved, i.e.
+			which lead to a successfull connection. This field is
+			provided as an informational argument when connecting
+			with it does not work anymore, for instance when it
+			has been changed on the AP. Such argument appears when
+			a RequestInput is raised after a retry. In case of WPS
+			association through PIN method: when retrying, the
+			previous wpspin will be provided.
+
+		string WPS
+
+			This field requests the use of WPS to get associated.
+			This is an alternate choice against Passphrase when
+			requested service supports WPS. The reply can contain
+			either empty pin, if user wants to use push-button
+			method, or a pin code if user wants to use the pin
+			method.
+
+			In case of a RequestPeerAuthorization, this field will
+			be set as mandatory.
+
+		string Username
+
+			Username for WISPr authentication. This field will be
+			requested when connecting to a WISPr-enabled hotspot.
+
+		string Password
+
+			Password for WISPr authentication. This field will be
+			requested when connecting to a WISPr-enabled hotspot.
+
+Arguments	string Type
+
+			Contains the type of a field. For example "psk", "wep"
+			"passphrase", "response", "ssid", "wpspin" or plain
+			"string".
+
+		string Requirement
+
+			Contains the requirement option. Valid values are
+			"mandatory", "optional", "alternate" or
+			"informational".
+
+			The "alternate" value specifies that this field can be
+			returned as an alternative to another one. An example
+			would be the network name or SSID.
+
+			All "mandatory" fields must be returned, while the
+			"optional" can be returned if available.
+
+			Nothing needs to be returned for "informational", as it
+			is here only to provide an information so a value is
+			attached to it.
+
+		array{string} Alternates
+
+			Contains the list of alternate field names this
+			field can be represented by.
+
+		string Value
+
+			Contains data as a string, relatively to an
+			"informational" argument.
+
+Examples	Requesting a passphrase for WPA2 network
+
+			RequestInput("/service1",
+				{ "Passphrase" : { "Type"        : "psk",
+						   "Requirement" : "mandatory"
+						 }
+				}
+			==> { "Passphrase" : "secret123" }
+
+		Requesting a passphrase after an error on the previous one:
+
+			RequestInput("/service1",
+				{ "Passphrase" : { "Type"        : "psk",
+						   "Requirement" : "mandatory"
+						 },
+				  "PreviousPassphrase" :
+					{ "Type"       : "psk",
+					  "Requirement : "informational",
+					  "Value"      : "secret123"
+					}
+				}
+
+		Requesting name for hidden network
+
+			RequestInput("/service2",
+				{ "Name" : { "Type"        : "string",
+					     "Requirement" : "mandatory",
+					     "Alternates"  : [ "SSID" ]
+					   },
+				  "SSID" : { "Type"        : "ssid",
+					     "Requirement" : "alternate"
+					   }
+				}
+			==> { "Name" : "My hidden network" }
+
+		Requesting a passphrase for a WPA2 network with WPS alternative:
+
+			RequestInput("/service3",
+				{ "Passphrase" : { "Type"        : "psk",
+						   "Requirement" : "mandatory",
+						   "Alternates"  : [ "WPS" ]
+						 },
+				  "WPS"        : { "Type"        : "wpspin",
+						   "Requirement" : "alternate"
+						 }
+				}
+
+			==> { "WPS" : "123456" }
+
+		Requesting a passphrase for a WPA2 network with WPS alternative
+		after an error on the previous one:
+
+			RequestInput("/service3",
+				{ "Passphrase" : { "Type"        : "psk",
+						   "Requirement" : "mandatory",
+						   "Alternates"  : [ "WPS" ]
+					         },
+				"WPS"          : { "Type"        : "wpspin",
+						   "Requirement" : "alternate"
+						 }
+				"PreviousPassphrase" :
+						{ "Type"       : "wpspin",
+					  	"Requirement : "informational",
+					  	"Value"      : "123456"
+						}
+
+		Requesting passphrase for a WPA-Enterprise network:
+
+			RequestInput("/service4",
+				{ "Identity"   : { "Type"        : "string",
+						   "Requirement" : "mandatory"
+						 },
+				  "Passphrase" : { "Type"        : "passphrase",
+						   "Requirement" : "mandatory"
+						 }
+				}
+
+			==> { "Identity" : "alice", "Passphrase": "secret123" }
+
+		Requesting challenge response for a WPA-Enterprise network:
+
+			RequestInput("/service4",
+				{ "Identity"   : { "Type"        : "string",
+						   "Requirement" : "mandatory"
+						 },
+				  "Passphrase" : { "Type"        : "response",
+						   "Requirement" : "mandatory"
+						 }
+				}
+
+			==> { "Identity" : "bob", "Passphrase": "secret123" }
+
+		Requesting username and password for a WISPr-enabled hotspot:
+
+			RequestInput("/service5",
+				{ "Username"   : { "Type"        : "string",
+						   "Requirement" : "mandatory"
+						 },
+				  "Password"   : { "Type"        : "passphrase",
+						   "Requirement" : "mandatory"
+						 }
+				}
+
+			==> { "Username" : "foo", "Password": "secret" }
+
+		Requesting a answer about an inconming peer connection:
+
+			RequestPeerAuthorization("/peer3", {})
+
+			==> { }
+
+		Requesting the WPS details when connecting to a peer:
+
+			RequestPeerAuthorization("/peer4",
+				{ "WPS":
+					{ "Type"        : "wpspin",
+					  "Requirement" : "mandatory"
+					}
+				}
+
+			==> { "WPS" : "" }
diff --git a/connman/doc/backtrace.txt b/connman/doc/backtrace.txt
new file mode 100644
index 0000000..ac8472c
--- /dev/null
+++ b/connman/doc/backtrace.txt
@@ -0,0 +1,28 @@
+ConnMan backtraces
+******************
+
+ConnMan dumps backtraces upon segmentation faults, bus errors and other
+crashing signals. Regardless of the debug level you started connmand with, the
+backtrace will be dumped to syslog.
+
+The ConnMan backtraces start with the following line:
+	-------- backtrace --------
+and will try to display function names if those can be resolved from the stack
+addresses. All static functions name will not appear for example.
+
+For a more complete and useful stack frame output you can use the
+test/backtrace script. It takes the actual binary that crashed and the
+connmand logs. The logs can contain any connman debug strings on top of the
+backtrace.
+
+Here is an example of the backtrace script usage:
+
+me@localhost:[~]$ backtrace /sbin/connmand connman.log
+-------- backtrace --------
+[0]: __connman_debug_list_available() [log.c:117]
+[1]: connman_driver_register() [element.c:515]
+[2]: __connman_driver_rescan() [element.c:490]
+[3]: disable_technology() [manager.c:391]
+[4]: generic_message() [object.c:262]
+-----------------------------------
+
diff --git a/connman/doc/behavior-api.txt b/connman/doc/behavior-api.txt
new file mode 100644
index 0000000..5feea76
--- /dev/null
+++ b/connman/doc/behavior-api.txt
@@ -0,0 +1,11 @@
+Interface behavior description
+******************************
+
+
+Ethernet service
+================
+
+The Ethernet based service is a special case since it has no children, but
+still can be manually connected and disconnected while also has an implicit
+behavior when physically plugging in or removing an Ethernet cable.
+
diff --git a/connman/doc/clock-api.txt b/connman/doc/clock-api.txt
new file mode 100644
index 0000000..6818f5a
--- /dev/null
+++ b/connman/doc/clock-api.txt
@@ -0,0 +1,87 @@
+Clock hierarchy
+===============
+
+Service		net.connman
+Interface	net.connman.Clock
+Object path	/
+
+Methods		dict GetProperties()  [experimental]
+
+			Returns all system clock properties. See the
+			properties section for available properties.
+
+			Possible Errors: [service].Error.InvalidArguments
+
+		void SetProperty(string name, variant value)  [experimental]
+
+			Changes the value of the specified property. Only
+			properties that are listed as read-write are
+			changeable. On success a PropertyChanged signal
+			will be emitted.
+
+			Possible Errors: [service].Error.InvalidArguments
+					 [service].Error.InvalidProperty
+
+Signals		PropertyChanged(string name, variant value)  [experimental]
+
+			This signal indicates a changed value of the given
+			property.
+
+
+Properties	uint64 Time [readonly or readwrite]  [experimental]
+
+			Current system time in seconds since epoch.
+
+			This value is present for changing the system time
+			if TimeUpdates is set to manual.
+
+			It is not present for driving an updated display
+			of the system time. PropertyChanged signal for this
+			value are only send out if it gets changed or jumps
+			unexpectedly.
+
+			In general application interested in the current
+			time should be using gettimeofday() and related
+			system calls.
+
+		string TimeUpdates [readwrite]  [experimental]
+
+			Possible values are "manual" and "auto" to indicate
+			time update policy.
+
+			With the "auto" setting the system tries to use as
+			many sources as possible to determine the correct
+			and updated time.
+
+		string Timezone [readonly or readwrite]  [experimental]
+
+			Current system timezone string. Allowed values
+			are from the standard timezone data (tzdata)
+			package under /usr/share/zoneinfo. For example
+			strings like "America/Vancouver" or "Europe/Berlin".
+
+			This value is present for changing the timezone
+			if TimezoneUpdates is set to manual.
+
+			When the timezone gets changed a PropertyChanged
+			signal will be send out.
+
+		string TimezoneUpdates [readwrite]  [experimental]
+
+			Possible values are "manual" and "auto" to indicate
+			timezone update policy.
+
+			With the "auto" setting the system tries to use as
+			many sources as possible to determine the correct
+			timezone.
+
+		array{string} Timeservers [readwrite]  [experimental]
+
+			List of global default NTP servers. The list should
+			be sorted in order of preference.
+
+			If a service configuration provides NTP servers,
+			then they are preferred over the global ones.
+
+			This list of servers is used when TimeUpdates is set
+			to auto.
diff --git a/connman/doc/coding-style.txt b/connman/doc/coding-style.txt
new file mode 100644
index 0000000..97410ce
--- /dev/null
+++ b/connman/doc/coding-style.txt
@@ -0,0 +1,344 @@
+Every project has its coding style, and ConnMan is not an exception. This
+document describes the preferred coding style for ConnMan code, in order to keep
+some level of consistency among developers so that code can be easily
+understood and maintained, and also to help your code survive under
+maintainer's fastidious eyes so that you can get a passport for your patch
+ASAP.
+
+First of all, ConnMan coding style must follow every rule for Linux kernel
+(http://www.kernel.org/doc/Documentation/CodingStyle). There also exists a tool
+named checkpatch.pl to help you check the compliance with it. Just type
+"checkpatch.pl --no-tree patch_name" to check your patch. In theory, you need
+to clean up all the warnings and errors except this one: "ERROR: Missing
+Signed-off-by: line(s)". ConnMan does not used Signed-Off lines, so including
+them is actually an error.  In certain circumstances one can ignore the 80
+character per line limit.  This is generally only allowed if the alternative
+would make the code even less readable.
+
+Besides the kernel coding style above, ConnMan has special flavors for its own.
+Some of them are mandatory (marked as 'M'), while some others are optional
+(marked as 'O'), but generally preferred.
+
+M1: Blank line before and after an if/while/do/for statement
+============================================================
+There should be a blank line before if statement unless the if is nested and
+not preceded by an expression or variable declaration.
+
+Example:
+1)
+a = 1;
+if (b) {  // wrong
+
+2)
+a = 1
+
+if (b) {
+}
+a = 2;	// wrong
+
+3)
+if (a) {
+	if (b)  // correct
+
+4)
+b = 2;
+
+if (a) {	// correct
+
+}
+
+b = 3;
+
+The only exception to this rule applies when a variable is being allocated:
+array = g_try_new0(int, 20);
+if (!array)	// Correct
+	return;
+
+
+M2: Multiple line comment
+=========================
+If your comments have more then one line, please start it from the second line.
+
+Example:
+/*
+ * first line comment	// correct
+ * ...
+ * last line comment
+ */
+
+
+M3: Space before and after operator
+===================================
+There should be a space before and after each operator.
+
+Example:
+a + b;  // correct
+
+
+M4: Wrap long lines
+===================
+If your condition in if, while, for statement or a function declaration is too
+long to fit in one line, the new line needs to be indented not aligned with the
+body.
+
+Example:
+1)
+if (call->status == CALL_STATUS_ACTIVE ||
+	call->status == CALL_STATUS_HELD) {  // wrong
+	connman_dbus_dict_append();
+
+2)
+if (call->status == CALL_STATUS_ACTIVE ||
+		call->status == CALL_STATUS_HELD) {  // correct
+	connman_dbus_dict_append();
+
+3)
+gboolean sim_ust_is_available(unsigned char *service_ust, unsigned char len,
+	enum sim_ust_service index) // wrong
+{
+	int a;
+	...
+}
+
+4)
+gboolean sim_ust_is_available(unsigned char *service_ust, unsigned char len,
+					enum sim_ust_service index) // correct
+{
+	int a;
+	...
+}
+
+If the line being wrapped is a function call or function declaration, the
+preferred style is to indent at least past the opening parenthesis. Indenting
+further is acceptable as well (as long as you don't hit the 80 character
+limit).
+
+If this is not possible due to hitting the 80 character limit, then indenting
+as far as possible to the right without hitting the limit is preferred.
+
+Example:
+
+1)
+gboolean sim_ust_is_available(unsigned char *service_ust, unsigned char len,
+		enum sim_ust_service index); // worse
+
+2)
+gboolean sim_ust_is_available(unsigned char *service_ust, unsigned char len,
+						enum sim_ust_service index);
+						// better
+
+M5: Git commit message 50/72 formatting
+=======================================
+The commit message header should be within 50 characters. And if you have
+detailed explanatory text, wrap it to 72 character.
+
+
+M6: Space when doing type casting
+=================================
+There should be a space between new type and variable.
+
+Example:
+1)
+a = (int *)b;  // wrong
+2)
+a = (int *) b;  // correct
+
+
+M7: Don't initialize variable unnecessarily
+===========================================
+When declaring a variable, try not to initialize it unless necessary.
+
+Example:
+int i = 1;  // wrong
+
+for (i = 0; i < 3; i++) {
+}
+
+
+M8: Use g_try_malloc instead of g_malloc
+========================================
+When g_malloc fails, the whole program would exit. Most of time, this is not
+the expected behavior, and you may want to use g_try_malloc instead.
+
+Example:
+additional = g_try_malloc(len - 1);  // correct
+if (!additional)
+	return FALSE;
+
+
+M9: Follow the order of include header elements
+===============================================
+When writing an include header the various elements should be in the following
+order:
+	- #includes
+	- forward declarations
+	- #defines
+	- enums
+	- typedefs
+	- function declarations and inline function definitions
+
+
+M10: Internal headers must not use include guards
+=================================================
+Any time when creating a new header file with non-public API, that header
+must not contain include guards.
+
+
+M11: Naming of enums
+====================
+
+Enums must have a descriptive name.  The enum type should be small caps and
+it should not be typedef-ed.  Enum contents should be in CAPITAL letters and
+prefixed by the enum type name.
+
+Example:
+
+enum animal_type {
+	ANIMAL_TYPE_FOUR_LEGS,
+	ANIMAL_TYPE_EIGHT_LEGS,
+	ANIMAL_TYPE_TWO_LEGS,
+};
+
+If the enum contents have values (e.g. from specification) the formatting
+should be as follows:
+
+enum animal_type {
+	ANIMAL_TYPE_FOUR_LEGS =		4,
+	ANIMAL_TYPE_EIGHT_LEGS =	8,
+	ANIMAL_TYPE_TWO_LEGS =		2,
+};
+
+M12: Enum as switch variable
+====================
+
+If the variable of a switch is an enum, you must not include a default in
+switch body. The reason for this is: If later on you modify the enum by adding
+a new type, and forget to change the switch accordingly, the compiler will
+complain the new added type hasn't been handled.
+
+Example:
+
+enum animal_type {
+	ANIMAL_TYPE_FOUR_LEGS =		4,
+	ANIMAL_TYPE_EIGHT_LEGS =	8,
+	ANIMAL_TYPE_TWO_LEGS =		2,
+};
+
+enum animal_type t;
+
+switch (t) {
+case ANIMAL_TYPE_FOUR_LEGS:
+	...
+	break;
+case ANIMAL_TYPE_EIGHT_LEGS:
+	...
+	break;
+case ANIMAL_TYPE_TWO_LEGS:
+	...
+	break;
+default:  // wrong
+	break;
+}
+
+However if the enum comes from an external header file outside ConnMan
+we cannot make any assumption of how the enum is defined and this
+rule might not apply.
+
+M13: Check for pointer being NULL
+=================================
+
+When checking if a pointer or a return value is NULL, use the
+check with "!" operator.
+
+Example:
+1)
+array = g_try_new0(int, 20);
+if (!array)	// Correct
+	return;
+
+2)
+if (!g_at_chat_get_slave(chat))	// Correct
+	return -EINVAL;
+
+3)
+array = g_try_new0(int, 20);
+if (array == NULL)	// Wrong
+	return;
+
+
+M14: Always use parenthesis with sizeof
+=======================================
+The expression argument to the sizeof operator should always be in
+parenthesis, too.
+
+Example:
+1)
+memset(stuff, 0, sizeof(*stuff));
+
+2)
+memset(stuff, 0, sizeof *stuff); // Wrong
+
+
+M15: Use void if function has no parameters
+===========================================================
+A function with no parameters must use void in the parameter list.
+
+Example:
+1)
+void foo(void)
+{
+}
+
+2)
+void foo()	// Wrong
+{
+}
+
+M16: Don't use hex value with shift operators
+==============================================
+The expression argument to the shift operators should not be in hex.
+
+Example:
+
+1)
+1 << y
+
+2)
+0x1 << y	// Wrong
+
+O1: Shorten the name
+====================
+Better to use abbreviation, rather than full name, to name a variable,
+function, struct, etc.
+
+Example:
+supplementary_service  // too long
+ss  // better
+
+O2: Try to avoid complex if body
+================================
+It's better not to have a complicated statement for if. You may judge its
+contrary condition and return | break | continue | goto ASAP.
+
+Example:
+1)
+if (a) {  // worse
+	struct voicecall *v;
+	call = synthesize_outgoing_call(vc, vc->pending);
+	v = voicecall_create(vc, call);
+	v->detect_time = time(NULL);
+	DBG("Registering new call: %d", call->id);
+	voicecall_dbus_register(v);
+} else
+	return;
+
+2)
+if (!a)
+	return;
+
+struct voicecall *v;
+call = synthesize_outgoing_call(vc, vc->pending);
+v = voicecall_create(vc, call);
+v->detect_time = time(NULL);
+DBG("Registering new call: %d", call->id);
+voicecall_dbus_register(v);
diff --git a/connman/doc/config-format.txt b/connman/doc/config-format.txt
new file mode 100644
index 0000000..b16f4e4
--- /dev/null
+++ b/connman/doc/config-format.txt
@@ -0,0 +1,155 @@
+Connman configuration file format
+*********************************
+
+Connman uses configuration files to provision existing services. Connman will
+be looking for its configuration files at STORAGEDIR which by default points
+to /var/lib/connman/. Configuration file names must not include other
+characters than letters or numbers and must have a .config suffix.
+Those configuration files are text files with a simple key-value pair format,
+organized into sections. Values do not comprise leading or trailing whitespace.
+We typically have one file per provisioned network.
+
+If the config file is removed, then Connman tries to remove the
+provisioned services. If an individual service inside a config is removed,
+then the corresponding provisioned service is removed. If a service section
+is changed, then the corresponding service is removed and immediately
+re-provisioned.
+
+
+Global section [global]
+=======================
+
+These files can have an optional global section describing the actual file.
+The two allowed fields for this section are:
+- Name: Name of the network.
+- Description: Description of the network.
+
+
+Service sections [service_*]
+============================
+
+Each provisioned service must start with the [service_*] tag. Replace * with
+an identifier unique to the config file.
+
+Allowed fields:
+- Type: Service type. We currently only support wifi and ethernet.
+- IPv4: The IPv4 address, netmask and gateway. Format of the entry
+  is network/netmask/gateway. The mask length can be used instead
+  of netmask. The gateway can be omitted if necessary.
+  The IPv4 field can also contain the string "off" or "dhcp".
+  If the setting is "off", then no IPv4 address is set to the interface.
+  If the setting is "dhcp", then DHCPv4 address resolution is activated.
+  Example: 192.168.1.2/24/192.168.1.1
+           192.168.200.100/255.255.255.0/192.168.200.1
+           10.0.0.2/24
+- IPv6: The IPv6 address, prefix length and gateway. Format of the entry
+  is network/prefixlen/gateway. For IPv6 addresses only prefix length is
+  accepted. The gateway can be omitted if necessary.
+  The IPv6 field can also contain the string "off" or "auto".
+  If the setting is "off", then no IPv6 address is set to the interface.
+  If the setting is "auto", then SLAAC or DHCPv6 is used.
+  Example: 2001:db8::2/64/2001:db8::1
+           2001:db8::1:2:3:4/64
+- IPv6.Privacy: IPv6 privacy option. Value can be either "disabled",
+  "enabled" or "preferred" (or the misspelled "prefered"). See use_tempaddr
+  variable description in Linux kernel Documentation/networking/ip-sysctl.txt
+  file.
+- MAC: MAC address of the interface where this setting should be applied.
+  The MAC address is optional and if it is missing, then the first found
+  interface is used. The byte values must have prefix 0 added,
+  the bytes must be separated by ":" char and its length must be
+  exactly 2 + 1 + 2 + 1 + 2 + 1 + 2 + 1 + 2 + 1 + 2 = 17 characters.
+- Nameservers: Comma separated list of nameservers
+- SearchDomains: Comma separated list of DNS search domains
+- Timeservers: Comma separated list of timeservers
+- Domain: Domain name to be used
+
+If IPv4 address is missing then DHCP is used. If IPv6 address is missing,
+then SLAAC or DHCPv6 is used.
+
+The following options are valid if Type is "wifi"
+- Name: A string representation of an 802.11 SSID. If the SSID field is
+  present, the Name field is ignored.
+- SSID: A hexadecimal representation of an 802.11 SSID. Use this format to
+  encode special characters including starting or ending spaces. If the SSID
+  field is omitted, the Name field is used instead.
+- EAP: EAP type. We currently only support tls, ttls or peap.
+- CACertFile: File path to CA certificate file (PEM/DER).
+- ClientCertFile: File path to client certificate file (PEM/DER).
+- PrivateKeyFile: File path to client private key file (PEM/DER/PFX).
+- PrivateKeyPassphrase: Password/passphrase for private key file.
+- PrivateKeyPassphraseType: We only support the fsid passphrase type for now.
+  This is for private keys generated by using their own filesystem UUID as the
+  passphrase. The PrivateKeyPassphrase field is ignored when this field is set
+  to fsid.
+- Identity: Identity string for EAP.
+- Phase2: Phase2 (inner authentication with TLS tunnel) authentication method.
+  Prefix the value with "EAP-" to indicate the usage of an EAP-based inner
+  authentication method (should only be used with EAP = TTLS).
+- Passphrase: RSN/WPA/WPA2 Passphrase
+- Security: The security type of the network. Possible values are 'psk'
+  (WPA/WPA2 PSK), 'ieee8021x' (WPA EAP), 'none' and 'wep'. When not set, the
+  default value is 'ieee8021x' if an EAP type is configured, 'psk' if a
+  passphrase is present and 'none' otherwise.
+- Hidden: If set to true, then this AP is hidden. If missing or set to false,
+  then AP is not hidden.
+
+
+Examples
+========
+
+This is a configuration file for a network providing EAP-TLS, EAP-TTLS and
+EAP-PEAP services. The respective SSIDs are tls_ssid, ttls_ssid and peap_ssid
+and the file name is example.config.
+
+Please note that the SSID entry is for hexadecimal encoded SSID (e.g. "SSID =
+746c735f73736964"). If your SSID does not contain any exotic character then
+you should use the Name entry instead (e.g. "Name = tls_ssid").
+
+example@example:[~]$ cat /var/lib/connman/example.config
+[global]
+Name = Example
+Description = Example network configuration
+
+[service_tls]
+Type = wifi
+SSID = 746c735f73736964
+EAP = tls
+CACertFile = /home/user/.certs/ca.pem
+ClientCertFile = /home/user/devlp/.certs/client.pem
+PrivateKeyFile = /home/user/.certs/client.fsid.pem
+PrivateKeyPassphraseType = fsid
+Identity = user
+
+[service_ttls]
+Type = wifi
+Name = ttls_ssid
+EAP = ttls
+CACertFile = /home/user/.cert/ca.pem
+Phase2 = MSCHAPV2
+Identity = user
+
+[service_peap]
+Type = wifi
+Name = peap_ssid
+EAP = peap
+CACertFile = /home/user/.cert/ca.pem
+Phase2 = MSCHAPV2
+Identity = user
+
+[service_home_ethernet]
+Type = ethernet
+IPv4 = 192.168.1.42/255.255.255.0/192.168.1.1
+IPv6 = 2001:db8::42/64/2001:db8::1
+MAC = 01:02:03:04:05:06
+Nameservers = 10.2.3.4,192.168.1.99
+SearchDomains = my.home,isp.net
+Timeservers = 10.172.2.1,ntp.my.isp.net
+Domain = my.home
+
+[service_home_wifi]
+Type = wifi
+Name = my_home_wifi
+Passphrase = secret
+IPv4 = 192.168.2.2/255.255.255.0/192.168.2.1
+MAC = 06:05:04:03:02:01
diff --git a/connman/doc/connman.8 b/connman/doc/connman.8
new file mode 100644
index 0000000..7297cf8
--- /dev/null
+++ b/connman/doc/connman.8
@@ -0,0 +1,79 @@
+.\" connman(8) manual page
+.\"
+.\" Copyright (C) 2012 Intel Corporation
+.\"
+.TH CONNMAN "8" "21 August 2012"
+.SH NAME
+ConnMan \- network management daemon
+.SH SYNOPSIS
+.B connmand [\-\-version] | [\-\-help]
+.PP
+.B connmand [\-\-config=<filename>] [\-\-debug=<file1>:<file2>:...] [\-\-device=<interface1>,<interface2>,...] [\-\-nodevice=<interface1>,<interface2>,..] [\-\-wifi=<driver1>,<driver2>,...] [\-\-plugin=<plugin1>,<plugin2>,...] [\-\-noplugin=<plugin1>,<plugin2>,...] [\-\-nodaemon] [\-\-nodnsproxy]
+.SH DESCRIPTION
+The \fIConnMan\fP provides a daemon for managing internet connections
+within devices running the Linux operating system. The Connection Manager is
+designed to be slim and to use as few resources as possible.
+It is a fully modular system that can be extended, through plug-ins,
+to support all kinds of wired or wireless technologies.
+Also, configuration methods, like DHCP and domain name resolving,
+are implemented using plug-ins.
+The plug-in approach allows for easy adaption and modification for various
+use cases.
+.P
+.SH OPTIONS
+The following options are supported:
+.TP
+.I "\-\-version"
+Print the ConnMan software version and exit.
+.TP
+.I "\-\-help"
+Print ConnMan's available options and exit.
+.TP
+.I "\-\-config=<filename>"
+Specify configuration file to set up various settings for ConnMan.  If not
+specified, the default value of '<SYSCONFDIR>/connman/main.conf'
+is used; where <SYSCONFDIR> is dependent on your distribution (usually
+it's /etc).  See \fBconnman.conf\fP(5) for more information on configuration
+file. The use of config file is optional and sane default values
+are used if config file is missing.
+.TP
+.I "\-\-debug=<file1>:<file2>:..."
+Sets how much information ConnMan sends to the log destination (usually
+syslog's "daemon" facility).  If the file options are omitted, then debugging
+information from all the source files are printed. If file options are
+present, then only debug prints from that source file are printed.
+Example: --debug=src/service.c:plugins/wifi.c
+.TP
+.I "\-\-device=<interface1>,<interface2>,..."
+Only manage these network interfaces. By default all network interfaces
+are managed.
+.TP
+.I "\-\-nodevice=<interface1>,<interface2>,..."
+Never manage these network interfaces.
+.TP
+.I "\-\-plugin=<plugin1>,<plugin2>,..."
+Load these plugins only. The option can be a pattern containing
+"*" and "?" characters.
+.TP
+.I "\-\-noplugin=<plugin1>,<plugin2>,..."
+Never load these plugins. The option can be a pattern containing
+"*" and "?" characters.
+.TP
+.I "\-\-wifi=<driver1>,<driver2>,..."
+Wifi driver that WiFi/Supplicant should use. If omitted, then the value
+of "nl80211,wext" is used by default.
+.TP
+.I "\-\-nodaemon"
+Do not daemonize. This is useful for debugging, and directs log output to
+the controlling terminal in addition to syslog.
+.TP
+.I "\-\-nodnsproxy"
+Do not act as a DNS proxy. By default ConnMan will direct all DNS traffic
+to itself by setting nameserver to 127.0.0.1 in \fBresolv.conf\fP(5) file.
+If this is not desired and you want that all programs call directly some
+DNS server, then you can use the --nodnsproxy option.
+If this option is used, then ConnMan is not able to cache the DNS queries
+because the DNS traffic is not going through ConnMan and that can cause
+some extra network traffic.
+.SH SEE ALSO
+.BR connman.conf (5).
diff --git a/connman/doc/connman.conf.5 b/connman/doc/connman.conf.5
new file mode 100644
index 0000000..c1ca75c
--- /dev/null
+++ b/connman/doc/connman.conf.5
@@ -0,0 +1,135 @@
+.\" connman.conf(5) manual page
+.\"
+.\" Copyright (C) 2012 Intel Corporation
+.\"
+.TH "connman.conf" "5" "21 August 2012" ""
+.SH NAME
+main.conf \- ConnMan configuration file
+.SH SYNOPSIS
+/etc/connman/main.conf
+.br
+or
+.br
+\fI<SYSCONFDIR>\fP/connman/main.conf
+.br
+where <SYSCONFDIR> depends on your distribution or build.
+.SH DESCRIPTION
+.P
+.I main.conf
+is a configuration file for ConnMan. The configuration file is
+optional but it can be used to set up various aspects of ConnMan's
+behavior. The location of the file may be changed through use of
+the "\-\-config=" argument for \fBconnman\fP (8).
+.SH "FILE FORMAT"
+.P
+The configuration file format is key file format.
+It consists of sections (groups) of key-value pairs.
+Lines beginning with a '#' and blank lines are considered comments.
+Sections are started by a header line containing the section enclosed
+in '[' and ']', and ended implicitly by the start of the next section
+or the end of the file. Each key-value pair must be contained in a section.
+.P
+Description of sections and available keys follows:
+.SS [General]
+This section is the only mandatory section of the configuration file.
+.TP
+.B InputRequestTimeout=\fPsecs\fP
+Set input request timeout. Default is 120 seconds
+The request for inputs like passphrase will timeout
+after certain amount of time. Use this setting to
+increase the value in case of different user
+interface designs.
+.TP
+.B BrowserLaunchTimeout=\fPsecs\fP
+Set browser launch timeout. Default is 300 seconds
+The request for launching a browser for portal pages
+will timeout after certain amount of time. Use this
+setting to increase the value in case of different
+user interface designs.
+.TP
+.B BackgroundScanning=\fPtrue|false\fP
+Enable background scanning. Default is true.
+Background scanning will start every 5 minutes unless
+the scan list is empty. In that case, a simple backoff
+mechanism starting from 10s up to 5 minutes will run.
+.TP
+.B FallbackTimeservers=\fPserver1,server2,...\fP
+List of Fallback timeservers separated by ",".
+These timeservers are used for NTP sync when there are
+no timeserver set by the user or by the service.
+These can contain mixed combination of fully qualified
+domain names, IPv4 and IPv6 addresses.
+.TP
+.B FallbackNameservers=\fPserver1,server2,...\fP
+List of fallback nameservers separated by "," appended
+to the list of nameservers given by the service. The
+nameserver entries must be in numeric format, host
+names are ignored.
+.TP
+.B DefaultAutoConnectTechnologies=\fPtechnology1,technology2,...\fP
+List of technologies that are marked autoconnectable
+by default, separated by commas ",". The default value
+for this entry when empty is ethernet,wifi,cellular.
+Services that are automatically connected must have been
+set up and saved to storage beforehand.
+.TP
+.B PreferredTechnologies=\fPtechnology1,technology2,...\fP
+List of preferred technologies from the most preferred
+one to the least preferred one separated by commas ",".
+Services of the listed technology type will be tried one
+by one in the order given, until one of them gets connected
+or they are all tried. A service of a preferred technology
+type in state 'ready' will get the default route when
+compared to another preferred type further down the list
+with state 'ready' or with a non-preferred type; a service
+of a preferred technology type in state 'online' will get
+the default route when compared to either a non-preferred
+type or a preferred type further down in the list.
+.TP
+.B NetworkInterfaceBlacklist=\fPinterface1,interface2,...\fP
+List of blacklisted network interfaces separated by ",".
+Found interfaces will be compared to the list and will
+not be handled by connman, if their first characters
+match any of the list entries. Default value is
+vmnet,vboxnet,virbr,ifb.
+.TP
+.B AllowHostnameUpdates=\fPtrue|false\fP
+Allow connman to change the system hostname. This can
+happen for example if we receive DHCP hostname option.
+Default value is true.
+.TP
+.B SingleConnectedTechnology=\fPtrue|false\fP
+Keep only a single connected technology at any time. When a new
+service is connected by the user or a better one is found according
+to PreferredTechnologies, the new service is kept connected and all
+the other previously connected services are disconnected. With this
+setting it does not matter whether the previously connected services
+are in 'online' or 'ready' states, the newly connected service is
+the only one that will be kept connected. A service connected by the
+user will be used until going out of network coverage. With this
+setting enabled applications will notice more network breaks than
+normal. Default value is false.
+.TP
+.B TetheringTechnologies=\fPtechnology1,technology2,...\fP
+List of technologies that are allowed to enable tethering separated by ",".
+The default value is wifi,bluetooth,gadget. Only those technologies listed
+here are used for tethering. If one wants to tether ethernet,
+then add "ethernet" in the list.
+NOTE that if ethernet tethering is enabled, then a DHCP server is
+started on all ethernet interfaces. Tethered ethernet should
+never be connected to corporate or home network as it will disrupt
+normal operation of these networks. Due to this ethernet is not
+tethered by default. Do not activate ethernet tethering unless you
+really know what you are doing.
+.TP
+.B PersistentTetheringMode=\fPtrue|false\fP
+Restore earlier tethering status when returning from offline mode,
+re-enabling a technology, and after restarts and reboots.
+Default value is false.
+.TP
+.B Enable6to4=\fPtrue|false\fP
+Automatically enable Anycast 6to4 if possible. This is not recommended, as the
+use of 6to4 will generally lead to a severe degradation of connection quality.
+See RFC6343.  Default value is false (as recommended by RFC6343 section 4.1).
+.SH "SEE ALSO"
+.BR Connman (8)
diff --git a/connman/doc/connmanctl.1 b/connman/doc/connmanctl.1
new file mode 100644
index 0000000..b71c6e6
--- /dev/null
+++ b/connman/doc/connmanctl.1
@@ -0,0 +1,190 @@
+.TH connmanctl 1 07/31/2012 "" "User Commands for Connman CLI"
+.SH
+NAME
+connmanctl \- Connman CLI
+.SH
+SYNOPSIS
+.BR connmanctl " ["
+.BR enable " <technology> | "
+.BR offlinemode "] ["
+.BR disable " <technology> | "
+.BR offlinemode "] ["
+.BR technologies "] ["
+.BR state "] ["
+.BR services " [\-\-properties <service>]] ["
+.BR scan " <technology>] ["
+.BR connect " <service>] ["
+.BR config " <service> \-\-<option> ARGS...] ["
+.BR help " | \-\-help]"
+.PP
+.SH
+DESCRIPTION
+Connmanctl is a Connman command line interface which can be run in two modes:
+a plain synchronous command input, and an asynchronous interactive shell.
+To run a specific command the user may enter connmanctl <command> [options]
+[args], or enter connmanctl; in this case, the program will drop into the
+interactive shell.
+.PP
+Connmantl can handle most simple network connections. It is able to enable/
+disable any technology that exists on the system, display a list of
+services available, connect to/disconnect from any unsecured networks,
+show properties of the system, the technologies, and any individual
+service, and configure all of the properties. It is also able to monitor
+changes in the properties of the services, technologies, and the system.
+.PP
+In the interactive shell, all of the same commands can be used. It
+provides quicker usage when needing to use connmanctl more extensively.
+.SH
+COMMANDS AND OPTIONS
+.TP
+.BR "help | \-\-help | " "(no arguments)"
+Shows the abbreviated help menu in the terminal.
+.PP
+.TP
+.BR enable " <technology>"
+Enables the given technology type (e.g. ethernet, wifi, 3g, etc.)
+Turns power on to the technology, but doesn't connect unless
+there is a service with autoconnect set to True.
+.PP
+.TP
+.BR disable " <technology>"
+Disables the given technology type. Turns power off to the
+technology and disconnects if it is already connected.
+.PP
+.TP
+.B enable offlinemode
+Enables offline mode. Disconnects and powers down all
+technologies system-wide, however each technology can be powered
+back on individually.
+.PP
+.TP
+.B disable offlinemode
+Disables offline mode. Technologies are powered back on according
+to their individual policies.
+.PP
+.TP
+.B technologies
+Shows a list of all technology types existing on the system and
+their properties. See the properties section of the Technology
+API for explanations of each property.
+.PP
+.TP
+.B state
+Shows the system properties. Includes ths online state of the
+system, offline mode, and session mode.
+.PP
+.TP
+.BR scan " <technology>"
+Scans for new services on the given technology.
+.PP
+.TP
+.B services
+Shows a list of all available service names. This includes the
+names of wifi networks, the wired ethernet connection, names of
+bluetooth devices, etc. These are the names used when a
+<service> command is called for. The service name
+(e.g. Joes-wifi), the service path (e.g.
+wifi_6834534139723_managed_none), or the full service path (e.g.
+/net/connman/Service/wifi_5467631...) are all accepted as valid
+input. An asterisk in front of the service indicates that the
+service is favorited, and a "C" indicates a service that is
+already connected.
+.PP
+.TP
+.BR "services \-\-properties" " <service>"
+Shows a list of all properties for that service. See the
+properties section of the Service API for explanations of each
+property.
+.PP
+.TP
+.BR connect " <service>"
+Connects to the given service if it is unsecured.
+.PP
+.TP
+.BR disconnect " <service>"
+Disconnects from the given service.
+.PP
+.TP
+.BR config " <service> " \-\-<option>
+Configures a writable property of the given service to the
+value(s) entered after --<option>.
+.PP
+.TP
+.BR monitor " [\-\-<option>]"
+Listens for and displays DBus signals sent by Connman. The option indicates
+which signals you want to subscribe to. If no option is entered, it displays
+all signals from all interfaces.
+.PP
+.SS
+Config Options:
+.PP
+.TP
+.B \-\-autoconnect=y/n
+Sets the autoconnect property of the service.
+.PP
+.TP
+.B \-\-ipv4
+Configures the IPv4 settings for the service. Enter the settings
+in the order "Method", "Address", "Netmask", then "Gateway"
+after the argument. See the properties section of the Service
+API for more information on these settings and the values
+accepted for them. It also displays a list of changes to both the
+IPv4 settings, and incidental changes to other values related to
+it.
+.PP
+.TP
+.B \-\-ipv6
+Configures the IPv6 settings for the service. Enter the settings
+in the order "Method", "Address", "PrefixLength", "Gateway", then
+"Privacy". See the properties section of the Service API for more
+information on these settings and the values accepted for them.
+It also displays a list of entered changes to the IPv6 settings,
+and incidental changes to other values related to it.
+.PP
+.TP
+.B \-\-nameservers
+Adds to the list of manually configured domain name servers.
+Enter the name servers after the argument separated by spaces.
+.PP
+.TP
+.B \-\-timeservers
+Adds to the list of manually configured time servers. Enter the
+time servers after the argument separated by spaces.
+.PP
+.TP
+.B \-\-domains
+Adds to the list of manually configured search domains. Enter
+the domains after the argument, separated by spaces.
+.PP
+.TP
+.B \-\-proxy
+Configures the IPv6 settings for the service. Enter the settings in the
+order "Method", "URL". If the Method is set to "direct", no other arguments
+are taken. If the Method is set to "auto", the URL is optional. To set the
+Servers and Excludes manually, enter "manual" followed by "servers" with a
+list of servers separated by spaces. Then, optionally, the word "excludes"
+followed by a list of excludes separated by spaces. e.g. "./connmanctl config
+joes-wifi \-\-proxy manual servers serv1 serv2 serv3 excludes excl1 excl2"
+.PP
+.SS
+Monitor Options:
+.PP
+.TP
+.B \-\-services
+Listens for and displays the PropertyChanged signal from the Service interface.
+Also displays the service name (e.g. Joes-wifi) that the property is part of.
+More information, including a list of possible properties can be found in the
+Service API.
+.PP
+.TP
+.B \-\-tech
+Listens for and displays the PropertyChanged signal from the Technology
+interface. More information, including a list of possible properties can be
+found in the Technology API.
+.PP
+.TP
+.B \-\-manager
+Listens for and displays the PropertyChanged, ServicesChanged, TechnologyAdded,
+and TechnologyRemoved signals from the Manager interface. More information on
+these signals and a list of possible properties can be found in the Manager API.
+.PP
diff --git a/connman/doc/counter-api.txt b/connman/doc/counter-api.txt
new file mode 100644
index 0000000..32411d5
--- /dev/null
+++ b/connman/doc/counter-api.txt
@@ -0,0 +1,70 @@
+Counter hierarchy
+=================
+
+Service		unique name
+Interface	net.connman.Counter
+Object path	freely definable
+
+Methods		void Release()
+
+			This method gets called when the service daemon
+			unregisters the counter. A counter can use it to do
+			cleanup tasks. There is no need to unregister the
+			counter, because when this method gets called it has
+			already been unregistered.
+
+		void Usage(object service, dict home, dict roaming)
+
+			This signal indicates a change in the counter values
+			for the service object. The counter is reset by calling
+			the service ResetCounters method.
+
+			When registering a new counter this method will be
+			called once with all details for "home" and "roaming"
+			counters filled in. Every further method call will
+			only include the changed values.
+
+			When "home" counter is active, then "roaming" counter
+			will contain an empty dictionary and vise-versa.
+
+			The dictionary argument contains the following entries:
+
+				RX.Packets
+
+					Total number of packets received.
+
+				TX.Bytes
+
+					Total number of packets sent.
+
+				RX.Bytes
+
+					Total number of bytes received.
+
+				TX.Bytes
+
+					Total number of bytes sent.
+
+				RX.Errors
+
+					Total number of erronous packets
+					received.
+
+				TX.Errors
+
+					Total number of erronous packets
+					sent.
+
+				RX.Dropped
+
+					Total number of dropped packets
+					while receiving.
+
+				TX.Dropped
+
+					Total number of dropped packets
+					while sending.
+
+				Time
+
+					Total number of seconds online.
diff --git a/connman/doc/ipconfig-api.txt b/connman/doc/ipconfig-api.txt
new file mode 100644
index 0000000..080fdac
--- /dev/null
+++ b/connman/doc/ipconfig-api.txt
@@ -0,0 +1,41 @@
+IP configuration handling
+*************************
+
+
+IP basics
+=========
+
+The core IP handling is designed around network interfaces or more precisely
+what the Linux kernel handles as struct net_device. Via RTNL every interface
+is tracked and an IP device created for it.
+
+	+--------+           +---- eth0 -----+
+	|        |           |               |
+	|  RTNL  +-----+---->|   IP device   |
+	|        |     |     |               |
+	+--------+     |     +---------------+
+                       |
+                       |     +---- wlan0 ----+
+	               |     |               |
+	               +---->|   IP device   |
+	                     |               |
+	                     +---------------+
+
+The IP device tracks link configuration, IP address setting and routing
+information for that interface. Every IP device also contains a configuration
+element. That element contains an operation table for callbacks based on
+different events.
+
+	struct connman_ipconfig_ops {
+		void (*up)         (struct connman_ipconfig *);
+		void (*down)       (struct connman_ipconfig *);
+		void (*lower_up)   (struct connman_ipconfig *);
+		void (*lower_down) (struct connman_ipconfig *);
+		void (*ip_bound)   (struct connman_ipconfig *);
+		void (*ip_release) (struct connman_ipconfig *);
+	};
+
+All configuration objects created directly by RTNL are tightly bound to the
+IP device. They will trigger DHCP or other configuration helpers.
+
+
diff --git a/connman/doc/manager-api.txt b/connman/doc/manager-api.txt
new file mode 100644
index 0000000..31e137c
--- /dev/null
+++ b/connman/doc/manager-api.txt
@@ -0,0 +1,307 @@
+Manager hierarchy
+=================
+
+Service		net.connman
+Interface	net.connman.Manager
+Object path	/
+
+Methods		dict GetProperties()
+
+			Returns all global system properties. See the
+			properties section for available properties.
+
+			Possible Errors: [service].Error.InvalidArguments
+
+		void SetProperty(string name, variant value)
+
+			Changes the value of the specified property. Only
+			properties that are listed as read-write are
+			changeable. On success a PropertyChanged signal
+			will be emitted.
+
+			Possible Errors: [service].Error.InvalidArguments
+					 [service].Error.InvalidProperty
+
+		array{object,dict} GetTechnologies()
+
+			Returns a list of tuples with technology object
+			path and dictionary of technology properties.
+
+			Possible Errors: [service].Error.InvalidArguments
+
+		array{object,dict} GetServices()
+
+			Returns a sorted list of tuples with service
+			object path and dictionary of service properties.
+
+			This list will not contain sensitive information
+			like passphrases etc.
+
+			Possible Errors: [service].Error.InvalidArguments
+
+		array{object,dict} GetPeers() [experimental]
+
+			Returns a sorted list of tuples with peer object path
+			and dictionary of peer properties
+
+			Possible Errors: [service].Error.InvalidArguments
+
+		object ConnectProvider(dict provider)	[deprecated]
+
+			Connect to a VPN specified by the given provider
+			properties.
+
+			When successful this method will return the object
+			path of the VPN service object.
+
+			This method can also be used to connect to an
+			already existing VPN.
+
+			This method call will only return in case of an
+			error or when the service is fully connected. So
+			setting a longer D-Bus timeout might be a really
+			good idea.
+
+			When 'SessionMode' property is enabled, this method
+			call is disallowed.
+
+			This API is deprecated and should not be used.
+			The VPN configuration API is provided by ConnMan
+			VPN daemon and user should use that one instead.
+
+			Possible Errors: [service].Error.InvalidArguments
+
+		void RemoveProvider(object path)	[deprecated]
+
+			Remove a VPN specified by the object path.
+
+		void RegisterAgent(object path)
+
+			Register new agent for handling user requests.
+
+			Possible Errors: [service].Error.InvalidArguments
+
+		void UnregisterAgent(object path)
+
+			Unregister an existing agent.
+
+			Possible Errors: [service].Error.InvalidArguments
+
+		void RegisterCounter(object path, uint32 accuracy, uint32 period)  [experimental]
+
+			Register a new counter for user notifications.
+
+			The accuracy is specified in kilo-bytes and defines
+			a threshold for counter updates. Together with the
+			period value it defines how often user space needs
+			to be updated. The period value is in seconds.
+
+			This interface is not meant for time tracking. If
+			the time needs to be tracked down to the second, it
+			is better to have a real timer running inside the
+			application than using this interface.
+
+			Also getting notified for every kilo-byte is a bad
+			choice (even if the interface supports it). Something
+			like 10 kilo-byte units or better 1 mega-byte seems
+			to be a lot more reasonable and better for the user.
+
+			Possible Errors: [service].Error.InvalidArguments
+
+		void UnregisterCounter(object path)  [experimental]
+
+			Unregister an existing counter.
+
+			Possible Errors: [service].Error.InvalidArguments
+
+		object CreateSession(dict settings, object notifier)  [experimental]
+
+			Create a new session for the application. Every
+			application can create multiple session with
+			different settings. The settings are described
+			as part of the session interface.
+
+			The notifier allows asynchronous notification about
+			session specific changes. These changes can be
+			for online/offline state or IP address changes or
+			similar things the application is required to
+			handle.
+
+			Every application should at least create one session
+			to inform about its requirements and it purpose.
+
+		void DestroySession(object session)  [experimental]
+
+			Remove the previously created session.
+
+			If an application exits unexpectatly the session
+			will be automatically destroyed.
+
+		object path, dict, fd RequestPrivateNetwork(dict options)
+								[experimental]
+
+			Request a new Private Network, which includes the
+			creation of a tun/tap interface, and IP
+			configuration, NAT and IP forwarding on that
+			interface.
+			An object path, a dictionnary and a file descriptor
+			with IP settings are returned.
+
+			Possible Errors: [service].Error.InvalidArguments
+					 [service].Error.NotSupported
+
+		void ReleasePrivateNetwork(object path) [experimental]
+
+			Releases a private network.
+
+			Possible Errors: [service].Error.InvalidArguments
+
+		void RegisterPeerService(dict specification, boolean master)
+			   [experimental]
+
+			Registers a local P2P Peer service
+
+			Even if p2p techonology is not available, it will be
+			possible to register peer services, since a p2p
+			enabled WiFi device might appear at anytime. The
+			registered peer services will automatically be enabled
+			for the p2p WiFi device; the application does not need
+			to do any re-registration.
+
+			A Peer service belongs to the process that registers
+			it, thus if that process dies, its Peer services will
+			be destroyed as well.
+
+			The specification dict follows the format described
+			in the Peer API document.
+
+			ConnMan will be able to determine in most cases
+			whether to be the P2P Group Owner or not. If the
+			service for some reason must belong to a group that
+			this device manages, the "master" property can be
+			set. Do not enable the "master" property unless it
+			is absolutely sure that this is needed for the
+			provided peer service.
+
+			Possible Errors: [service].Error.InvalidArguments
+					 [service].Error.AlreadyExists
+					 [service].Error.NotSupported
+
+		void UnregisterPeerService(dict specification) [experimental]
+
+			Unregisters an existing local P2P Peer service
+
+			Possible Errors: [service].Error.InvalidArguments
+					 [service].Error.NotRegistered
+
+Signals		TechnologyAdded(object path, dict properties)
+
+			Signal that is sent when a new technology is added.
+
+			It contains the object path of the technology and
+			also its properties.
+
+		TechnologyRemoved(object path)
+
+			Signal that is sent when a technology has been removed.
+
+			The object path is no longer accessible after this
+			signal and only emitted for reference.
+
+		ServicesChanged(array{object, dict}, array{object})
+
+			Signals a list of services that have been changed
+			via the first array. And a list of service that
+			have been removed via the second array.
+
+			The list of added services is sorted. The dictionary
+			with the properties might be empty in case none of
+			the properties have changed. Or only contains the
+			properties that have changed.
+
+			For newly added services the whole set of properties
+			will be present.
+
+			The list of removed services can be empty.
+
+			This signal will only be triggered when the sort
+			order of the service list or the number of services
+			changes. It will not be emitted if only a property
+			of the service object changes. For that it is
+			required to watch the PropertyChanged signal of
+			the service object.
+
+		PeersChanged(array{object, dict}, array{object}) [experimental]
+
+			Signals a list of peers that have been changed via the
+			first array. And a list of peer that have been removed
+			via the second array.
+
+			The list of changed peers is sorted. The dictionary
+			with the properties might be empty in case none of the
+			properties have changed. Or only contains the
+			properties that have changed.
+
+			For newly added peers the whole set of properties will
+			be present.
+
+			The list of removed peers can be empty.
+
+			This signal will only be triggered when the sort order
+			of the peer list or the number of peers changes. It
+			will not be emitted if only a property of the peer
+			object changes. For that it is required to watch the
+			PropertyChanged signal of the peer object.
+
+		PropertyChanged(string name, variant value)
+
+			This signal indicates a changed value of the given
+			property.
+
+Properties	string State [readonly]
+
+			The global connection state of a system. Possible
+			values are "offline", "idle", "ready" and "online".
+
+			If the device is in offline mode, the value "offline"
+			indicates this special global state. It can also be
+			retrieved via the OfflineMode property, but is kept
+			here for consistency and to differentiate from "idle".
+
+			However when OfflineMode property is true, the State
+			property can still be "idle", "ready" or "online"
+			since it is possible by the end user to re-enable
+			individual technologies like WiFi and Bluetooth while
+			in offline mode.
+
+			The states "idle", "ready" and "online" match to
+			states from the services. If no service is in
+			either "ready" or "online" state it will indicate
+			the "idle" state.
+
+			If at least one service is in "ready" state and no
+			service is in "online" state, then it will indicate
+			the "ready" state.
+
+			When at least one service is in "online" state,
+			this property will indicate "online" as well.
+
+		boolean OfflineMode [readwrite]
+
+			The offline mode indicates the global setting for
+			switching all radios on or off. Changing offline mode
+			to true results in powering down all devices. When
+			leaving offline mode the individual policy of each
+			device decides to switch the radio back on or not.
+
+			During offline mode, it is still possible to switch
+			certain technologies manually back on. For example
+			the limited usage of WiFi or Bluetooth devices might
+			be allowed in some situations.
+
+		boolean SessionMode [readwrite]  [experminental][deprecated]
+
+			This property exists only for compatibility reasons
+			and does not affect ConnMan in any way.
+
+			The default value is false.
diff --git a/connman/doc/overview-api.txt b/connman/doc/overview-api.txt
new file mode 100644
index 0000000..f126887
--- /dev/null
+++ b/connman/doc/overview-api.txt
@@ -0,0 +1,435 @@
+Application programming interface
+*********************************
+
+
+Service basics
+==============
+
+Inside Connection Manager there exists one advanced interface to allow the
+user interface an easy access to networking details and user chosen
+preferences. This is the service list and interface.
+
+The basic idea is that Connection Manager maintains a single flat and sorted
+list of all available, preferred or previously used services. A service here
+can be either a Ethernet device, a WiFi network or a remote Bluetooth device
+(for example a mobile phone).
+
+This list of service is sorted by Connection Manager and there is no need
+for the user interface to implement its own sorting. User decisions will
+need to be done via Connection Manager and it is then responsible to update
+the order of services in this list.
+
+	+---------------------------------------+
+	| Ethernet                              |
+	+---------------------------------------+
+	| Bluetooth phone                       |
+	+---------------------------------------+
+	| Guest            (strength 90, none)  |
+	+---------------------------------------+
+	| My WiFi AP       (strength 80, rsn)   |
+	+---------------------------------------+
+	| Other AP         (strength 70, rsn)   |
+	+---------------------------------------+
+	| Friends AP       (strength 70, wep)   |
+	+---------------------------------------+
+
+If none of the services has been used before the sorting order will be done
+with these priorities:
+
+	1. Ethernet	(lower index numbers first)
+	2. Bluetooth	(last used devices first)
+	3. GSM/UTMS/3G	(if SIM card is present, activated and not roaming)
+	3. WiFi		(signal strength first, then more secure network
+			first)
+
+The Ethernet devices are always sorted first since they are physically built
+into the system and will be always present. In cases they are switched off
+manually they will not be showing in this list.
+
+Since every Bluetooth device has to be configured/paired first, the user
+already made a choice here that these are important. Connection Manager will
+only show devices with PAN or DUN profile support. While Bluetooth devices
+do have a signal strength, it is mostly unknown since background scanning
+in Bluetooth is too expensive. The choice here is to sort the last used
+Bluetooth device before the others.
+
+WiFi networks closer in the proximity should be shown first since it is more
+likely they are selected. The signal strength value is normalized to 0-100
+(effectively a percentage) and allows an easy sorting.
+
+WiFi networks with the same signal strength are then sorted by their security
+setting. WPA2 encrypted networks should be preferred over WPA/WEP and also
+unencrypted ones. After that they will be sorted by the SSID in alphabetical
+order.
+
+In the case the WiFi network uses WPS for setup and it is clearly detectable
+that a network waits for Connection Manager to connect to it (for example via
+a push-to-connect button press on the AP), then this network should be shown
+first before any other WiFi networks. The reason here is that the user already
+made a choice via the access point. However this depends on technical details
+if it is possible to detect these situations.
+
+
+Service order
+=============
+
+All unused services will have the internal order number of 0 and then will
+be sorted according to the rules above. For Bluetooth the user already made
+the decision to setup their device and by that means select it. However
+until the first connection attempt it might have been setup for total
+different reason (like audio usage) and thus it still counts as unused from
+a networking point of view.
+
+Selecting the "My WiFi AP" and successfully connecting to it makes it a
+favorite device and it will become an order number bigger than 0. All
+order numbers are internally. They are given only to service that are marked
+as favorite. For WiFi and Bluetooth a successful connection attempt makes
+these services automatically a favorite. For Ethernet the plugging of a cable
+makes it a favorite. Disconnecting from a network doesn't remove the favorite
+setting. It is a manual operation and is equal to users pressing
+delete/remove button.
+
+	+---------------------------------------+
+	| My WiFi AP       (strength 80, rsn)   |  order=1 - favorite=yes
+	+---------------------------------------+
+	| Ethernet                              |  order=0
+	+---------------------------------------+
+	| Guest            (strength 90, none)  |  order=0
+	+---------------------------------------+
+	|                                       |
+
+Ethernet is special here since the unplugging of the network cable will
+remove the service from the list
+
+	+---------------------------------------+
+	| Ethernet with cable                   |  order=1 - favorite=yes
+	+---------------------------------------+
+	| Guest            (strength 90, none)  |  order=0
+	+---------------------------------------+
+	|                                       |
+
+This means that all services with an order > 0 have favorite=yes and all
+others have favorite=no setting. The favorite setting is exposed via a
+property over the service interface. As mentioned above, the order number
+is only used internally.
+
+Within Connection Manager many services can be connected at the same time and
+also have an IP assignment. However only one can have the default route. The
+service with the default route will always be sorted at the top of the
+list.
+
+	+---------------------------------------+
+	| Ethernet                              |  order=2 - connected=yes
+	+---------------------------------------+
+	| My WiFi AP       (strength 80, rsn)   |  order=1 - connected=yes
+	+---------------------------------------+
+	| Guest            (strength 90, none)  |  order=0
+	+---------------------------------------+
+	|                                       |
+
+To change the default connection to your access point, the user needs to
+manually drag the access point service to the top of the list. Connection
+Manager will not take down default routes if there is no reason to do so.
+A working connection is considered top priority.
+
+	+---------------------------------------+
+	| My WiFi AP       (strength 80, rsn)   |  order=2 - connected=yes
+	+---------------------------------------+
+	| Ethernet                              |  order=1 - connected=yes
+	+---------------------------------------+
+	| Guest            (strength 90, none)  |  order=0
+	+---------------------------------------+
+	|                                       |
+
+Another possible user interaction would be to disconnect the Ethernet service
+and in this case the service falls back down in the list.
+
+	+---------------------------------------+
+	| My WiFi AP       (strength 80, rsn)   |  order=1 - connected=yes
+	+---------------------------------------+
+	| Ethernet                              |  order=1 - connected=no
+	+---------------------------------------+
+	| Guest            (strength 90, none)  |  order=0
+	+---------------------------------------+
+	|                                       |
+
+If the service on the top of the list changes the default route will be
+automatically adjusted as needed. The user can trigger this by disconnecting
+from a network, if the network becomes unavailable (out of range) or if the
+cable gets unplugged.
+
+As described above, the pure case of disconnecting from a network will not
+remove the favorite setting. So previously selected networks are still present
+and are sorted above all others.
+
+	+---------------------------------------+
+	| Ethernet                              |  order=2 - connected=yes
+	+---------------------------------------+
+	| My WiFi AP       (strength 80, rsn)   |  order=1 - connected=no
+	+---------------------------------------+
+	| Guest            (strength 90, none)  |  order=0
+	+---------------------------------------+
+	|                                       |
+
+Unplugging the Ethernet cable will remove the Ethernet service.
+
+	+---------------------------------------+
+	| My WiFi AP       (strength 80, rsn)   |  order=1 - connected=no
+	+---------------------------------------+
+	| Guest            (strength 90, none)  |  order=0
+	+---------------------------------------+
+	|                                       |
+
+
+Service tweaks
+==============
+
+The interfaces of Connection Manager will always export all services that are
+currently known. The Ethernet devices with no cable plugged are actually not
+included in this list. They will only show up once a carrier is detected.
+
+The service interface is not meant for basic device configuration task. So
+switching a device on and off (via RFKILL for example) should be done via
+the technology interface. See "Technology interfaces" chapter in this document.
+
+Due to limited screen size of small devices and the big amount of WiFi
+access points that are deployed right now it might be sensible to not show
+certain WiFi networks in the user interface.
+
+The choice to hide a WiFi network from the user interface should be purely
+done by the signal strength. The optimal cut-off value here still has to be
+determined, but in the end that is a user interface policy.
+
+
+Service naming
+==============
+
+Every service will have a name property that allows the user interface to
+display them directly. All names will be already converted into UTF-8. It
+derives from the netork details.
+
+In case of WiFi this will be the SSID value. The SSID is a binary array and
+will be converted into printable form. Unprintable characters are replaced
+with spaces.
+
+In addition to WiFi naming, WiFi networks are subject to a grouping policy
+performed around SSID and security type. This means that one service will be
+seen for N WiFi networks providing the same SSID and the same security metod.
+For instance, if 5 APs are servicing an SSID called "TEST" with WPA2
+authentication and 3 APs are servicing the same SSID with open authentication
+method, the user will see only two services listed with the name "TEST"
+differentiated by their security type, which are "psk" and "none". Such
+policy is also applied to hidden networks, where hidden services will have an
+empty name and will be differentiated by the security type. The user has then
+to select the one with the right security and the Agent API will request any
+required information such as the SSID for the network (See "Application
+basics" below).
+
+For Bluetooth the device alias is used. The alias is different since it
+can be overwritten by the user via the Bluetooth service. The identification
+is still done based on its address, but the display name might change. In
+most cases the alias is equal to the Bluetooth remote friendly name.
+
+For Ethernet device no name will be provided. The type property will indicate
+that this service is Ethernet and then it is up to the user interface to
+provide a proper localized name for it.
+
+
+Service states
+==============
+
+Every service can have multiple states that indicate what is currently
+going on with it. The choice to have multiple states instead of a simple
+connected yes/no value comes from the fact that it is important to let the
+user interface name if a service is in process of connecting/disconnecting.
+
+The basic state of every service is "idle". This means that this service
+is not in use at all at the moment. It also is not attempting to connect
+or do anything else.
+
+The "association" state indicates that this service tries to establish a
+low-level connection to the network. For example associating/connecting
+with a WiFi access point.
+
+With the "configuration" state the service indicates that it is trying
+to retrieve/configure IP settings.
+
+The "ready" state signals a successful connected device. This doesn't mean
+it has the default route, but basic IP operations will succeed.
+
+With the "disconnect" state a service indicates that it is going to terminate
+the current connection and will return to the "idle" state.
+
+In addition a "failure" state indicates a wrong behavior. It is similar to
+the "idle" state since the service is not connected.
+
+		+---------------+
+		| idle          |<-------------------------------+
+		+---------------+                                |
+		      |                                          |
+		      |                      +-------------+     |
+		      +----------------------| failure     |     |
+		      | service.Connect()    +-------------+     |
+		      V                           A              |
+		+---------------+                 |              |
+		| association   |-----------------+              |
+		+---------------+      error      |              |
+		      |                           |              |
+		      | success                   |              |
+		      V                           |              |
+		+---------------+                 |              |
+		| configuration |-----------------+              |
+		+---------------+      error                     |
+		      |                                          |
+		      | success                                  |
+		      V                                          |
+		+---------------+                                |
+		| ready         |                                |
+		+---------------+                                |
+		      |                                          |
+		      | success                                  |
+		      |                                          |
+		      V                                          |
+		+---------------+                                |
+		| online        |<----------------+              |
+		+---------------+                 |              |
+		      |                           |              |
+		      | service.Disconnect()      |              |
+		      V                           |              |
+		+---------------+                 |              |
+		| disconnect    |-----------------+              |
+		+---------------+      error                     |
+		      |                                          |
+		      +------------------------------------------+
+
+The different states should no be used by the user interface to trigger
+advanced actions. The state transitions are provided for the sole purpose
+to give the user feedback on what is currently going on. Especially in
+cases where networks are flaky or DHCP servers take a long time these
+information are helpful for the user.
+
+Some services might require special authentication procedure like a web
+based confirmation. The LoginRequired property should be used to check
+for this.
+
+
+Application basics
+==================
+
+All applications should use D-Bus to communicate with Connection Manager. The
+main entry point is the manager object. Currently the manager object is
+located at "/", but this might change to allow full namespacing of the API
+in the future. The manager interface is documented in manager-api.txt and
+contains a set of global properties and methods.
+
+A simple way to retrieve all global properties looks like this:
+
+	bus = dbus.SystemBus()
+
+	manager = dbus.Interface(bus.get_object("net.connman", "/"),
+						"net.connman.Manager")
+
+	properties = manager.GetProperties()
+
+Changing a global property is also pretty simple. For example enabling the
+so called offline mode (aka flight mode) it is enough to just set that
+property:
+
+	manager.SetProperty("OfflineMode", dbus.Boolean(1))
+
+The manager object contains references to profiles, devices, services and
+connections. All these references represent other interfaces that allow
+detailed control of Connection Manager. The profiles and devices interfaces
+are more for advanced features and most applications don't need them at all.
+
+The services are represented as a list of object paths. Every of these object
+paths contains a service interface. A service is a global collection for
+Ethernet devices, WiFi networks, Bluetooth services etc. and all these
+different types are treated equally.
+
+Every local Ethernet card will show up as exactly one service. WiFi networks
+will be grouped by SSID, mode and security setting. Bluetooth PAN and DUN
+service will show up per remote device. This creates a simple list that can
+be directly displayed to the users since these are the exact details users
+should care about.
+
+	properties = manager.GetProperties()
+
+	for path in properties["Services"]:
+		service = dbus.Interface(bus.get_object("net.connman", path),
+							"net.connman.Service")
+
+		service_properties = service.GetProperties()
+
+The service interface is documented in service-api.txt and contains common
+properties valid for all services. It also contains method to connect or
+disconnect a specific service. This allows users to select a specific service.
+Connection Manager can also auto-connect services based on his policies or
+via external events (like plugging in an Ethernet cable).
+
+Connecting (or disconnecting) a specific service manually is as simple as
+just telling it to actually connect:
+
+	service.Connect()  or  service.Disconnect()
+
+It is possible to connect multiple services if the underlying technology
+allows it. For example it would be possible to connect to a WiFi network
+and a Bluetooth service at the same time. Trying to connect to a second WiFi
+network with the same WiFi hardware would result in an automatic disconnect
+of the currently connected network. Connection Manager handles all of this
+for the applications in the background. Trying to connect an Ethernet service
+will result in an error if no cable is plugged in. All connection attempts
+can fail for one reason or another. Application should be able to handle
+such errors and will also be notified of changes via signals.
+
+Connection Manager will interact with an agent via the Agent API to confirm
+certain transactions with the user. If Connection Manager needs extra
+information, it will ask the user for exactly the information it requires,
+i.e. passphrase, network's name (for hidden WiFi networks) and more depending
+on the use case (e.g. WPS, EAP). Therefore an application environment using
+Connection Manager should implement one dedicated Connection Manager agent
+according to the Agent API in order to interact with the user. Please see
+agent-api.txt for implementation details.
+
+To monitor the current status of a service the state property can be used. It
+gives detailed information about the current progress.
+
+	properties = service.GetProperties()
+
+	print properties["State"]
+
+All state changes are also sent via the PropertyChanged signal on the
+service interface. This allows asynchronous monitoring without having to poll
+Connection Manager for changes.
+
+
+Technology interfaces
+=====================
+
+When ConnMan is started first time, all technologies except ethernet are
+powered off by default. The reason is that the user needs to decide which
+technologies are relevant to him and what bearers the user wants to use.
+User can use the Technology Powered property to turn on or off a given
+technology. See doc/technology-api.txt document for details.
+
+User can activate offline (flight) mode via Manager OfflineMode property.
+While in offline mode, all the technologies including ethernet are
+powered off. During the offline mode, the user can temporarily activate
+individual technologies by using the Technology Powered property or by
+using the rfkill command or Fn-Fx key combination found in some laptops.
+
+If the host supports rfkill switch, then all the radios can be turned off
+by the kernel when the switch is activated. ConnMan will notice this and
+remove corresponding technologies from D-Bus. Technologies cannot be
+activated while rfkill switch is turned on. When rfkill switch is turned
+off (radios are activated), then ConnMan restores the original Powered
+status for each activated technology.
+
+User can use the rfkill command from command line or indirectly via
+some UI component to activate/deactivate individual radios found in
+the host. ConnMan will listen these rfkill events and set the Powered
+property accordingly. ConnMan will not save the rfkill status it has
+received. This means that after restarting ConnMan, the original and
+saved technology status is used when deciding which technologies should
+be powered. If the user uses the Technology D-Bus API to set the Powered
+property, then that information is saved and used when ConnMan is restarted.
diff --git a/connman/doc/peer-api.txt b/connman/doc/peer-api.txt
new file mode 100644
index 0000000..cc094ff
--- /dev/null
+++ b/connman/doc/peer-api.txt
@@ -0,0 +1,102 @@
+Peer hierarchy [EXPERIMENTAL]
+=============================
+
+Service		net.connman
+Interface	net.connman.Peer
+Object path	[variable prefix]/{peer0,peer1,...}
+
+Methods		dict GetProperties() [deprecated]
+
+			Returns properties for the peer object. See the
+			properties sections for available properties.
+
+			Usage of this method is highly discouraged. Use
+			the Manager.GetPeers() method instead.
+
+			Possible Errors: [service].Error.InvalidArguments
+
+		void Connect() [experimental]
+
+			Connect this peer.
+
+			This method call will only return in case of an error
+			or when the peer is fully connected. So setting a
+			longer D-Bus timeout might be a really good idea.
+
+			Possible Errors: [service].Error.InvalidArguments
+
+		void Disconnect() [experimental]
+
+			Disconnect this peer. If the peer is not connected, an
+			error message will be generated.
+
+			Possible Errors: [service].Error.InvalidArguments
+
+Signals		PropertyChanged(string name, variant value) [experimental]
+
+			This signal indicates a changed value of the given
+			property.
+
+Properties	string State [readonly] [experimental]
+
+			The peer state information.
+
+			Valid state are "idle", "failure", "association",
+			"configuration", "ready" and "disconnect".
+
+		string Name [readonly] [experimental]
+
+			Name of the peer.
+
+		dict IPv4 [readonly] [experimental]
+
+			string Local [readonly]
+
+				The current peer's local configured IPv4
+				address.
+
+			string Remote [readonly]
+
+				The current peer's remote configured IPv4
+				address.
+
+		array{dict} Services [readonly] [experimental]
+
+			Array of P2P service specifications consisting of
+			either UpnpService and UpnpVersion or BonjourQuery
+			and BonjourResponse, but not a mix of these. The
+			dict members have the following format:
+
+			String UpnpService [readonly]
+
+				The UPNP service URI.
+
+			int32 UpnpVersion [readonly]
+
+				The UPNP version in use.
+
+			array{byte} BonjourQuery [readonly]
+
+				The bonjour service query data, provided
+				through a byte array.
+
+				Note: a Peer object will never show this
+				information. When scanning, a device gets
+				only the bonjour response data. However,
+				this information is mandatory when a bonjour
+				service is given through Manager API
+				RegisterPeerService and
+				UnregisterPeerService.
+
+			array{byte} BonjourResponse [readonly]
+
+				The bonjour service response data, provided
+				through a byte array.
+
+				Note: this will be the only bonjour related
+				information a Peer object will show.
+
+			array{byte} WiFiDisplayIEs [readonly]
+
+				The TLV formated byte array representing the
+				WiFi Display Informations Elements.
diff --git a/connman/doc/plugin-api.txt b/connman/doc/plugin-api.txt
new file mode 100644
index 0000000..616938b
--- /dev/null
+++ b/connman/doc/plugin-api.txt
@@ -0,0 +1,164 @@
+Plugin programming interface
+****************************
+
+
+Plugin basics
+=============
+
+The Connection Manager supports plugins for various actions. The basic plugin
+contains of plugin description via CONNMAN_PLUGIN_DEFINE and also init/exit
+callbacks defined through that description.
+
+#include <connman/plugin.h>
+
+static int example_init(void)
+{
+	return 0;
+}
+
+static void example_exit(void)
+{
+}
+
+CONNMAN_PLUGIN_DEFINE(example, "Example plugin", CONNMAN_VERSION,
+						example_init, example_exit)
+
+
+Infrastructure for plugins
+==========================
+
+The Connection Manager provides a very good infrastructure for plugins to
+interface with the core functionalities of ConnMan. The infrastructure is
+well divided into the concepts of Technology, Device and Network, among
+others.
+
+Technology infrastructure
+=========================
+
+A Technology in ConnMan is an abstract representation of the different
+kinds of technologies it supports such as WiFi, Ethernet, Bluetooth and
+Celullar. The technologies support are added to ConnMan through plugins, such
+as plugins/bluetooth.c for the Bluetooth Technology or plugins/wifi.c for the
+WiFi Technology. Each new technology plugin needs to register itself as a
+Technology with ConnMan. As an example we will take a look at the Bluetooth
+plugin registration. As a first step 'struct connman_technology_driver' needs
+to be defined:
+
+	static struct connman_technology_driver tech_driver = {
+		.name           = "bluetooth",
+		.type           = CONNMAN_SERVICE_TYPE_BLUETOOTH,
+		.probe          = bluetooth_tech_probe,
+		.remove         = bluetooth_tech_remove,
+		.set_tethering  = bluetooth_tech_set_tethering,
+	};
+
+More functions can be defined depending on the purpose of the plugin. All
+vtable's supported functions can be seen in include/technology.h. If a
+completely new technology type is added 'enum connman_service_type' in
+include/service.h needs to be extended accordingly. This inclusion comes in
+the form of Service because ultimately a new technology introduces a new
+Service. New technologies can also reuse existing Services types.
+
+To make the Connection Manager aware of the new Technology plugin we need to
+register its driver by calling 'connman_technology_driver_register()' in the
+plugin initialization function, bluetooth_init() in this example:
+
+	connman_technology_driver_register(&tech_driver);
+
+In this document the error check is supressed for the sake of simplicity.
+All plugins should check return values in driver registration functions.
+
+After this call ConnMan becomes aware of the new Technology plugin and will
+call the probe() method when the new technology is recognized by the system. For
+the Bluetooth plugin for example probe() would be called when a Bluetooth
+adapter is recognized. A Technology is only probed if there exists at least
+one device of such technology plugged into the system.
+
+Complementary, the technology must be unregistered on the plugin exit function
+through 'connman_technology_driver_unregister()'.
+
+Device infrastructure
+=====================
+
+A Device represents a real device of a given Technology, there could be many
+devices per technology. To enable ConnMan to handle Devices a device driver
+needs to be registered. Using the Bluetooth plugin as example it would have to
+define a 'struct connman_device_driver':
+
+	static struct connman_device_driver device_driver = {
+		.name           = "bluetooth",
+		.type           = CONNMAN_DEVICE_TYPE_BLUETOOTH,
+		.probe          = bluetooth_device_probe,
+		.remove         = bluetooth_device_remove,
+		.enable         = bluetooth_device_enable,
+		.disable        = bluetooth_device_disable,
+	};
+
+And to register the driver:
+
+	connman_device_driver_register(&device_driver);
+
+'connman_device_driver_register()' is called during the plugin initialization
+process, not necessarily at the plugin init function.
+
+In this document the error check is supressed for the sake of simplicity.
+All plugins should check return values in driver registration functions.
+
+Additionally code to handle the detection of new devices needs to be written
+for each plugin, the bluetooth plugin does so by registering watchers for the
+BlueZ D-Bus interface. Once a new Bluetooth Device appears the plugin needs to
+notify ConnMan core by calling connman_device_create(), for the bluetooth
+plugin the call would be:
+
+	struct connman_device *device;
+
+        device = connman_device_create("bluetooth",
+				        CONNMAN_DEVICE_TYPE_BLUETOOTH)
+
+ConnMan core will then register the bluetooth device as a Device entity and
+call the probe() function from the bluetooth plugin device driver. If a
+Technology entity for the Device type doesn't exist it will be created and
+Technology probe() function in the bluetooth technology driver is called.
+
+For the Bluetooth plugin a Device represents the local Bluetooth Adapter
+plugged in the system.
+
+To learn how to use the connman_device_*() functions such as
+connman_device_set_powered() and connman_device_ref() see src/device.c for
+its API documentation.
+
+Network infrastructure
+======================
+
+The Connection Manager provides a mean to plugins handle the specifics of
+establishing/handling a connection for each type of Technology. For the
+bluetooth plugin a connman_network_driver needs to be registered:
+
+	static struct connman_network_driver network_driver = {
+		.name           = "bluetooth",
+		.type           = CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN,
+		.probe          = bluetooth_pan_probe,
+		.remove         = bluetooth_pan_remove,
+		.connect        = bluetooth_pan_connect,
+		.disconnect     = bluetooth_pan_disconnect,
+	};
+
+And then call the register function:
+
+	connman_network_driver_register(&network_driver);
+
+In this document the error check is supressed for the sake of simplicity.
+All plugins should check return values in driver registration functions.
+
+The next step would be the probe of a Network entity, for the bluetooth
+plugin this would happen when a new device that supports the PAN NAP role is
+paired with the system. ConnMan then call connman_device_add_network() to
+associate the new Network with the existing Device entity (the local Bluetooth
+Adapter).
+
+Then in the vtable's connect method all the needed pieces to perform a
+connection shall be perfomed.
+
+To learn how to use the connman_network_*() functions such as
+connman_network_set_index() and connman_network_set_connected() see
+src/network.c for its API documentation.
diff --git a/connman/doc/service-api.txt b/connman/doc/service-api.txt
new file mode 100644
index 0000000..b4f1dca
--- /dev/null
+++ b/connman/doc/service-api.txt
@@ -0,0 +1,496 @@
+Service hierarchy
+=================
+
+Service		net.connman
+Interface	net.connman.Service
+Object path	[variable prefix]/{service0,service1,...}
+
+Methods		dict GetProperties()  [deprecated]
+
+			Returns properties for the service object. See
+			the properties section for available properties.
+
+			Usage of this method is highly discouraged. Use
+			the Manager.GetServices() method instead.
+
+			Possible Errors: [service].Error.InvalidArguments
+
+		void SetProperty(string name, variant value)
+
+			Changes the value of the specified property. Only
+			properties that are listed as read-write are
+			changeable. On success a PropertyChanged signal
+			will be emitted.
+
+			Properties cannot be set for hidden WiFi service
+			entries or provisioned services.
+
+			Possible Errors: [service].Error.InvalidArguments
+					 [service].Error.InvalidProperty
+
+		void ClearProperty(string name)
+
+			Clears the value of the specified property.
+
+			Properties cannot be cleared for hidden WiFi service
+			entries or provisioned services.
+
+			Possible Errors: [service].Error.InvalidArguments
+					 [service].Error.InvalidProperty
+
+		void Connect()
+
+			Connect this service. It will attempt to connect
+			WiFi or Bluetooth services.
+
+			For Ethernet devices this method can only be used
+			if it has previously been disconnected. Otherwise
+			the plugging of a cable will trigger connecting
+			automatically. If no cable is plugged in this method
+			will fail.
+
+			This method call will only return in case of an
+			error or when the service is fully connected. So
+			setting a longer D-Bus timeout might be a really
+			good idea.
+
+			Calling Connect() on a hidden WiFi service entry will
+			query the missing SSID via the Agent API causing a
+			WiFi service with the given SSID to be scanned,
+			created and connected.
+
+			Possible Errors: [service].Error.InvalidArguments
+
+		void Disconnect()
+
+			Disconnect this service. If the service is not
+			connected an error message will be generated.
+
+			On Ethernet devices this will disconnect the IP
+			details from the service. It will not magically
+			unplug the cable. When no cable is plugged in this
+			method will fail.
+
+			This method can also be used to abort a previous
+			connection attempt via the Connect method.
+
+			Hidden WiFi service entries cannot be disconnected
+			as they always stay in idle state.
+
+			Possible Errors: [service].Error.InvalidArguments
+
+		void Remove()
+
+			A successfully connected service with Favorite=true
+			can be removed this way. If it is connected, it will
+			be automatically disconnected first.
+
+			If the service requires a passphrase it will be
+			cleared and forgotten when removing.
+
+			This is similar to setting the Favorite property
+			to false, but that is currently not supported.
+
+			In the case a connection attempt failed and the
+			service is in the State=failure, this method can
+			also be used to reset the service.
+
+			Calling this method on Ethernet devices, hidden WiFi
+			services or provisioned services will cause an error
+			message. It is not possible to remove these kind of
+			services.
+
+			Possible Errors: [service].Error.InvalidArguments
+
+		void MoveBefore(object service)
+
+			If a service has been used before, this allows a
+			reorder of the favorite services.
+
+			Possible Errors: [service].Error.InvalidArguments
+
+		void MoveAfter(object service)
+
+			If a service has been used before, this allows a
+			reorder of the favorite services.
+
+			Possible Errors: [service].Error.InvalidArguments
+
+		void ResetCounters()  [experimental]
+
+			Reset the counter statistics.
+
+			Possible Errors: None
+
+Signals		PropertyChanged(string name, variant value)
+
+			This signal indicates a changed value of the given
+			property.
+
+Properties	string State [readonly]
+
+			The service state information.
+
+			Valid states are "idle", "failure", "association",
+			"configuration", "ready", "disconnect" and "online".
+
+			The "ready" state signals a successfully
+			connected device. "online" signals that an
+			Internet connection is available and has been
+			verified.
+
+			See doc/overview-api.txt for more information about
+			state transitions.
+
+		string Error [readonly]
+
+			The service error status details.
+
+			When error occur during connection or disconnection
+			the detailed information is represented in this
+			property to help the user interface to present the
+			user with alternate options.
+
+			This property is only valid when the service is in
+			the "failure" state. Otherwise it might be empty or
+			not present at all.
+
+			Currently defined error codes are: "out-of-range",
+			"pin-missing", "dhcp-failed", "connect-failed",
+			"login-failed", "auth-failed" and "invalid-key".
+
+		string Name [readonly]
+
+			The service name (for example "Wireless" etc.)
+
+			This name can be used for directly displaying it in
+			the application. It has pure informational purpose
+			and no attempt should be made to translate it.
+
+			For Ethernet devices and hidden WiFi networks this
+			property is not present.
+
+		string Type [readonly]
+
+			The service type (for example "ethernet", "wifi" etc.)
+
+			This information should only be used to determine
+			advanced properties or showing the correct icon
+			to the user.
+
+			Together with a missing Name property, this can
+			be used to identify hidden WiFi networks.
+
+		array{string} Security [readonly]
+
+			If the service type is WiFi, then this property is
+			present and contains the list of security methods
+			or key management settings.
+
+			Possible values are "none", "wep", "psk", "ieee8021x"
+			and also "wps".
+
+			This property might be only present for WiFi
+			services.
+
+		uint8 Strength [readonly]
+
+			Indicates the signal strength of the service. This
+			is a normalized value between 0 and 100.
+
+			This property will not be present for Ethernet
+			devices.
+
+		boolean Favorite [readonly]
+
+			Will be true if a cable is plugged in or the user
+			selected and successfully connected to this service.
+
+			This value is automatically changed and to revert
+			it back to false the Remove() method needs to be
+			used.
+
+		boolean Immutable [readonly]
+
+			This value will be set to true if the service is
+			configured externally via a configuration file.
+
+			The only valid operation are Connect() and of
+			course Disconnect(). The Remove() method will
+			result in an error.
+
+		boolean AutoConnect [readwrite]
+
+			If set to true, this service will auto-connect
+			when no other connection is available.
+
+			The service won't auto-connect while roaming.
+
+			For favorite services it is possible to change
+			this value to prevent or permit automatic
+			connection attempts.
+
+		boolean Roaming [readonly]
+
+			This property indicates if this service is roaming.
+
+			In the case of Cellular services this normally
+			indicates connections to a foreign provider when
+			traveling abroad.
+
+		array{string} Nameservers [readonly]
+
+			The list of currently active nameservers for this
+			service. If the server is not in READY or ONLINE
+			state than this list will be empty.
+
+			Global nameservers are automatically added to this
+			list. The array represents a sorted list of the
+			current nameservers. The first one has the highest
+			priority and is used by default.
+
+			When using DHCP this array represents the nameservers
+			provided by the network. In case of manual settings,
+			the ones from Nameservers.Configuration are used.
+
+		array{string} Nameservers.Configuration [readwrite]
+
+			The list of manually configured domain name
+			servers. Some cellular networks don't provide
+			correct name servers and this allows for an
+			override.
+
+			This array is sorted by priority and the first
+			entry in the list represents the nameserver with
+			the highest priority.
+
+			When using manual configuration and no global
+			nameservers are configured, then it is useful
+			to configure this setting.
+
+			Changes to the domain name servers can be done
+			at any time. It will not cause a disconnect of
+			the service. However there might be small window
+			where name resolution might fail.
+
+		array{string} Timeservers [readonly]
+
+			The list of currently active timeservers for this
+			service. If the server is not in READY or ONLINE
+			state than this list will be empty.
+
+		array{string} Timeservers.Configuration [readwrite]
+
+			The list of manually configured time servers.
+
+			The first entry in the list represents the
+			timeserver with the highest priority.
+
+			When using manual configuration this setting
+			is useful to override all the other timeserver
+			settings. This is service specific, hence only
+			the values for the default service are used.
+
+			Changes to this property will result in restart
+			of NTP query.
+
+		array{string} Domains [readonly]
+
+			The list of currently used search domains taken
+			from Domains.Configurations if set, otherwise a
+			domain name if provided by DHCP or VPNs.
+
+		array{string} Domains.Configuration [readwrite]
+
+			The list of manually configured search domains.
+
+		dict IPv4 [readonly]
+
+			string Method [readonly]
+
+				Possible values are "dhcp", "manual"
+				and "off".
+
+				The value "fixed" indicates an IP address
+				that can not be modified. For example
+				cellular networks return fixed information.
+
+			string Address [readonly]
+
+				The current configured IPv4 address.
+
+			string Netmask [readonly]
+
+				The current configured IPv4 netmask.
+
+			string Gateway [readonly]
+
+				The current configured IPv4 gateway.
+
+		dict IPv4.Configuration [readwrite]
+
+			Same values as IPv4 property. The IPv4 represents
+			the actual system configuration while this allows
+			user configuration.
+
+			Changing these settings will cause a state change
+			of the service. The service will become unavailable
+			until the new configuration has been successfully
+			installed.
+
+		dict IPv6 [readonly]
+
+			string Method [readonly]
+
+				Possible values are "auto", "manual", "6to4"
+				and "off".
+
+				The value "fixed" indicates an IP address
+				that can not be modified. For example
+				cellular networks return fixed information.
+				The value "6to4" is returned if 6to4 tunnel
+				is created by connman. The tunnel can only be
+				created if method was set to "auto" by the
+				user. User cannot set the method to "6to4".
+
+			string Address [readonly]
+
+				The current configured IPv6 address.
+
+			uint8 PrefixLength [readonly]
+
+				The prefix length of the IPv6 address.
+
+			string Gateway [readonly]
+
+				The current configured IPv6 gateway.
+
+			string Privacy [readonly]
+
+				Enable or disable IPv6 privacy extension
+				that is described in RFC 4941. The value
+				has only meaning if Method is set to "auto".
+
+				Value "disabled" means that privacy extension
+				is disabled and normal autoconf addresses are
+				used.
+
+				Value "enabled" means that privacy extension is
+				enabled and system prefers to use public
+				addresses over temporary addresses.
+
+				Value "prefered" means that privacy extension is
+				enabled and system prefers temporary addresses
+				over public addresses.
+
+				Default value is "disabled".
+
+		dict IPv6.Configuration [readwrite]
+
+			Same values as IPv6 property. The IPv6 represents
+			the actual system configuration while this allows
+			user configuration.
+
+			Changing these settings will cause a state change
+			of the service. The service will become unavailable
+			until the new configuration has been successfully
+			installed.
+
+		dict Proxy [readonly]
+
+			string Method [readonly]
+
+				Possible values are "direct", "auto" and
+				"manual".
+
+				In case of "auto" method, the URL file can be
+				provided unless you want to let DHCP/WPAD
+				auto-discover to be tried. In such case if DHCP
+				and WPAD auto-discover methods fails then
+				method will be "direct".
+
+				In case of "direct" no additional information
+				are provided. For the "manual" method the
+				Servers have to be set, Excludes is optional.
+
+			string URL [readonly]
+
+				Automatic proxy configuration URL. Used by
+				"auto" method.
+
+			array{string} Servers [readonly]
+
+				Used when "manual" method is set.
+
+				List of proxy URIs. The URI without a protocol
+				will be interpreted as the generic proxy URI.
+				All others will target a specific protocol and
+				only once.
+
+				Example for generic proxy server entry would
+				be like this: "server.example.com:911".
+
+			array{string} Excludes [readonly]
+
+				Used when "manual" method is set.
+
+				List of hosts which can be accessed directly.
+
+		dict Proxy.Configuration [readwrite]
+
+			Same values as Proxy property. The Proxy represents
+			the actual system configuration while this allows
+			user configuration.
+
+			If "auto" method is set with an empty URL, then
+			DHCP/WPAD auto-discover will be tried. Otherwise the
+			specified URL will be used.
+
+		dict Provider [readonly]
+
+			string Host [readonly]
+
+				VPN host IP.
+
+			string Domain [readonly]
+
+				VPN Domain.
+
+			string Name [readonly]
+
+				VPN provider Name.
+
+			string Type [readonly]
+
+				VPN provider type.
+
+		dict Ethernet [readonly]
+
+			string Method [readonly]
+
+				Possible values are "auto" and "manual".
+
+			string Interface [readonly]
+
+				Interface name (for example eth0).
+
+			string Address [readonly]
+
+				Ethernet device address (MAC address).
+
+			uint16 MTU [readonly]
+
+				The Ethernet MTU (default is 1500).
+
+			uint16 Speed [readonly] [deprecated]
+
+				Selected speed of the line.
+
+				This information is not available.
+
+			string Duplex [readonly] [deprecated]
+
+				Selected duplex settings of the line.
+				Possible values are "half" and "full".
+
+				This information is not available.
diff --git a/connman/doc/session-api.txt b/connman/doc/session-api.txt
new file mode 100644
index 0000000..3aac535
--- /dev/null
+++ b/connman/doc/session-api.txt
@@ -0,0 +1,184 @@
+Service		unique name
+Interface	net.connman.Notification
+Object path	freely definable
+
+Methods		void Release()
+
+			This method gets called when the service daemon
+			unregisters the session. A counter can use it to do
+			cleanup tasks. There is no need to unregister the
+			session, because when this method gets called it has
+			already been unregistered.
+
+		void Update(dict settings)
+
+			Sends an update of changed settings. Only settings
+			that are changed will be included.
+
+			Initially on every session creation this method is
+			called once to inform about the current settings.
+
+
+Service		net.connman
+Interface	net.connman.Session
+Object path	variable
+
+Methods		void Destroy()
+
+			Close the current session. This is similar to
+			DestroySession method on the manager interface. It
+			is just provided for convenience depending on how
+			the application wants to track the session.
+
+		void Connect()
+
+			If not connected, then attempt to connect this
+			session.
+
+			The usage of this method depends a little bit on
+			the model of the application. Some application
+			should not try to call Connect on any session at
+			all. They should just monitor if it becomes online
+			or gets back offline.
+
+			Others might require an active connection right now.
+			So for example email notification should only check
+			for new emails when a connection is available. However
+			if the user presses the button for get email or wants
+			to send an email it should request to get online with
+			this method.
+
+			Depending on the bearer settings the current service
+			is used or a new service will be connected.
+
+			This method returns immediately after it has been
+			called. The application is informed through the update
+			notification about the state of the session.
+
+			It is also not guaranteed that a session stays online
+			after this method call. It can be taken offline at any
+			time. This might happen because of idle timeouts or
+			other reasons.
+
+			It is safe to call this method multiple times. The
+			actual usage will be sorted out for the application.
+
+		void Disconnect()
+
+			This method indicates that the current session does
+			not need a connection anymore.
+
+			This method returns immediately. The application is
+			informed through the update notification about the
+			state of the session.
+
+		void Change(string name, variant value)
+
+			Change the value of certain settings. Not all
+			settings can be changed. Normally this should not
+			be needed or an extra session should be created.
+			However in some cases it makes sense to change
+			a value and trigger different behavior.
+
+			A change of a setting will cause an update notification
+			to be sent. Some changes might cause the session to
+			be moved to offline state.
+
+Settings	string State [readonly]
+
+			This indicates if the connection is disconnected,
+			connected or online. It is updated according to the
+			selected ConnectionType. The session will not be
+			in a useful shape (i.e.: providing a network connection
+			to the owner) until its State gets updated to connected
+			and/or online.
+
+			This maps to the useful port of the  service state.
+			And it is only valid for the selected bearer
+			configuration. Otherwise it will be reported as
+			disconnected even if connected services are present.
+
+			In addition the State settings notification might
+			not happen right away. Notifications of this state
+			can be delayed based on the speed of the bearer. It
+			is done to avoid congestion on bearers like cellular
+			etc.
+
+		string Name [readonly]
+
+			The Service name to which the system is connected.
+			It should only be used for displaying it in the UI
+			and not for getting hold on session object.
+
+		string  Bearer [readonly]
+
+			This indicates the current bearer that is used
+			for this session. Or an empty string if no bearer
+			if available.
+
+		string  Interface [readonly]
+
+			Interface name used by the service object to connect.
+			This name can be used for SO_BINDTODEVICE in the
+			application.
+
+		dict IPv4 [readonly]
+
+			Current IPv4 configuration.
+
+		dict IPv6 [readonly]
+
+			Current IPv6 configuration.
+
+		array{string} AllowedBearers [readwrite]
+
+			A list of bearers that can be used for this session.
+			In general this list should be empty to indicate that
+			any bearer is acceptable.
+
+			The order of the entries in AllowedBearers matters.
+			The services are sorted in the order of the bearer
+			entries in this list.
+
+			Also "*" matches any bearer. This is usefull to prefer
+			certain bearers such as 'wifi' with a fallback to any
+			other available bearer.
+
+			Invalid bearer names will be ignored and removed
+			from the list. And empty AllowedBearers will
+			not match to any bearer, therefore the session
+			will never go online.
+
+			When a session is created and the provided settings
+			dictionary does not contain AllowedBearers, a default
+			session with "*" will be created.
+
+		string ConnectionType [readwrite]
+
+			This is used to indicate which connection is requested
+			from the session. The state of the session will be
+			updated accordingly. Values can be 'local',
+			'internet' or 'any'.
+
+			'local' means the session requests to be connected,
+			but does not require specifically to be online.
+			Therefore State property will be set to 'connected' if
+			underlying service gets ready and/or online.
+
+			'online' means the session requests to be connected,
+			and online. State property will never get 'connected'
+			but instead will switch to 'online' if underlying
+			service gets online.
+
+			'any' means either 'local' or 'internet'.
+
+			Invalid values will be ignored and removed. An
+			empty ConnectionType is an invalid configuration.
+
+			When a session is created and the provided settings
+			dictionary does not contain ConnectionType, a default
+			session with 'any' will be created.
+
+			(This setting will be removed when the unique process
+			identification problem is solved.)
+
diff --git a/connman/doc/session-overview.txt b/connman/doc/session-overview.txt
new file mode 100644
index 0000000..2393167
--- /dev/null
+++ b/connman/doc/session-overview.txt
@@ -0,0 +1,94 @@
+Session API
+***********
+
+
+Connection management algorithm basics
+======================================
+
+The Session core uses the normal auto-connect algorithm for selecting
+which services will be connected or disconnected. That means only
+Services with AutoConnect set to true will be used. The Session
+core will assign a connected Service to a Session if the Service
+is matching the AllowedBearer filter.
+
+By using the normal auto-connect algorithm, it is possible to
+use the Session API and the Service API at the same time.
+
+
+Session States and Transitions
+==============================
+
+There is only one state which is called Free Ride.
+
+The Free Ride state means that a session will go online if a matching
+service goes online without calling Service.Connect() itself. The idea
+behind this is that a session doesn't request a connection for itself
+instead waits until another session actively requires to go online.
+This is comparable to piggy-backing.
+
+Connnect()
+ +------+
+ |      v
++------------+
+|  Free Ride |
++------------+
+  |     ^
+  +-----+
+ Disconnect()
+
+
+If an application wants to stay offline it can set an empty
+AllowedBearers list.
+
+
+Session application identification
+==================================
+
+Application using session can be identified through different means.
+
+  - SELinux
+  - UID
+  - GID
+
+ConnMan will try to identify the application in the given order above.
+If SELinux is not supported by the system or not configured, ConnMan
+will ignore it and fallback asking the D-Bus daemon about the UID of
+the application.
+
+The identification is only useful in combination with the policy plugin.
+
+
+Policy Plugin
+=============
+
+The policy plugin allows the administrator to provision/configure
+sessions. Each policy needs an application identification in order to
+match the policy to a session.
+
+See session-policy-format.txt for more details.
+
+
+Per application routing
+=======================
+
+For each session a policy routing table is maintained. Each policy
+routing table contains a default route to the selected service.
+
+Per session iptables rules:
+
+iptables -t mangle -A OUTPUT -m owner [--uid-owner|--gid-owner] $OWNER \
+	  -j MARK --set-mark $MARK
+
+Global rules for all sessions:
+
+iptables -t mangle -A INPUT -j CONNMARK --restore-mark
+iptables -t mangle -A POSTROUTING -j CONNMARK --save-mark
+
+Per application routing is only available when policy files are
+used. Without the policy plugin or a valid configuration, the default
+session configuration is applied.
+
+The default session configuration does not enable the per application
+routing. Sessions are still useful in this setup, because the
+notification of sessions is still available, e.g. the online/offline
+notification.
diff --git a/connman/doc/session-policy-format.txt b/connman/doc/session-policy-format.txt
new file mode 100644
index 0000000..babc2c1
--- /dev/null
+++ b/connman/doc/session-policy-format.txt
@@ -0,0 +1,83 @@
+ConnMan policy file format
+**************************
+
+The session policy plugin allows to configure/provision a session.
+ConnMan will be looking for policy files in STORAGEDIR/session_policy_local
+which by default points to /var/lib/connman. Policy file names must
+not include other characters than letters or numbers and must have
+a .policy suffix. Policy files are text files.
+
+It is possible to add, remove or update a policy file during run-time.
+The corresponding sessions will be updated accordingly.
+
+Policy group [policy_*]
+=======================
+
+Each policy group must start with as [policy_*] tag. '*' has no
+semantic meaning but should consist just out of characters.
+
+Required fields:
+
+Exactly one and only one of the required fields need to be present
+per policy group.
+
+- uid: This policy group will be applied to any session
+  with given user ID.
+
+- gid: This policy group will be applied to any session
+  with given group ID.
+
+- selinux: This policy group will be applied to any session
+  with given SELinux context.
+
+Allowed fields:
+
+- AllowedBearers: see session-api.txt
+  The policy AllowedBearers overrules the settings done via
+  D-Bus. For example the policy AllowedBearers is 'ethernet' then
+  the D-Bus API will only accept an empty string or 'ethernet'.
+
+- ConnectionType: see session-api.txt
+  The policy ConnectionType overrules the settings done via
+  D-Bus.
+
+- Priority: A boolean which tells ConnMan to prefer the session
+  over other Sessions. This priority value is more for applications
+  that want to push themselves up in the asychronization notification
+  queue once a bearer becomes online.
+
+  This actual priority order also depends on the allowed bearers and
+  other factors. This setting is just a little indicator for one
+  application being notified before another one.
+
+- RoamingPolicy: The allowed roaming behavior.
+
+  Valid policies are "national", "international", "default", "always"
+  and "forbidden".
+
+  "national" allows roaming within a country.  "international" allows
+  roaming in a country and between countries.
+
+  "default" is used to tell the session to use the global roaming
+  setting.
+
+  "always" will overwrite the default "forbidden" value which is
+  useful for emergency application.
+
+  Default value is "forbidden".
+
+- EmergencyCall: A boolean which tells ConnMan whenever the
+  Connect() method is called for this session, all other
+  session are disconnected.
+
+  Note only services matching the AllowedBearers rule will be
+  considered.
+
+Example
+=======
+
+example@example:[~]$ cat /var/lib/connman/session_policy_local/auser.policy
+[policy_auser]
+uid = auser
+AllowedBearers = wifi cellular
+RoamingPolicy = forbidden
diff --git a/connman/doc/technology-api.txt b/connman/doc/technology-api.txt
new file mode 100644
index 0000000..f97eac0
--- /dev/null
+++ b/connman/doc/technology-api.txt
@@ -0,0 +1,99 @@
+Technology hierarchy
+====================
+
+Service		net.connman
+Interface	net.connman.Technology
+Object path	[variable prefix]/{technology0,technology1,...}
+
+Methods		dict GetProperties()  [deprecated]
+
+			Returns properties for the technology object. See
+			the properties section for available properties.
+
+			Usage of this method is highly discouraged. Use
+			the Manager.GetTechnologies() method instead.
+
+			Possible Errors: [service].Error.InvalidArguments
+
+		void SetProperty(string name, variant value)
+
+			Changes the value of the specified property. Only
+			properties that are listed as read-write are
+			changeable. On success a PropertyChanged signal
+			will be emitted.
+
+			Possible Errors: [service].Error.InvalidArguments
+					 [service].Error.InvalidProperty
+
+		void Scan()
+
+			Trigger a scan for this specific technology. The
+			method call will return when a scan has been
+			finished and results are available. So setting
+			a longer D-Bus timeout might be a really good
+			idea.
+
+			Results will be signaled via the ServicesChanged
+			signal from the manager interface.
+
+			In case of P2P technology, results will be signaled
+			via the PeersChanged signal from the manager
+			interface.
+
+Signals		PropertyChanged(string name, variant value)
+
+			This signal indicates a changed value of the given
+			property.
+
+Properties	boolean Powered [readwrite]
+
+			Boolean representing the power state of the
+			technology. False means that the technology is
+			off (and is available RF-Killed) while True means
+			that the technology is enabled.
+
+		boolean Connected [readonly]
+
+			Boolean representing if a technology is connected.
+
+			This is just a convience property for allowing the
+			UI to easily show if this technology has an active
+			connection or not.
+
+			If this property is True it means that at least one
+			service of this technology is in ready state.
+
+		string Name [readonly]
+
+			Name of this technology.
+
+		string Type [readonly]
+
+			The technology type (for example "ethernet" etc.)
+
+			This information should only be used to determine
+			advanced properties or showing the correct icon
+			to the user.
+
+		boolean Tethering [readwrite]
+
+			This option allows to enable or disable the support
+			for tethering. When tethering is enabled then the
+			default service is bridged to all clients connected
+			through the technology.
+
+		string TetheringIdentifier [readwrite]
+
+			The tethering broadcasted identifier.
+
+			This property is only valid for the WiFi technology,
+			and is then mapped to the WiFi AP SSID clients will
+			have to join in order to gain internet connectivity.
+
+		string TetheringPassphrase [readwrite]
+
+			The tethering connection passphrase.
+
+			This property is only valid for the WiFi technology,
+			and is then mapped to the WPA pre-shared key clients
+			will have to use in order to establish a connection.
diff --git a/connman/doc/valgrind.suppressions b/connman/doc/valgrind.suppressions
new file mode 100644
index 0000000..c1c7bca
--- /dev/null
+++ b/connman/doc/valgrind.suppressions
@@ -0,0 +1,235 @@
+{
+   <syslog error>
+   Memcheck:Cond
+   obj:/lib/libc-*.so
+   ...
+   fun:localtime_r
+   fun:__vsyslog_chk
+   fun:__syslog_chk
+   fun:__connman_log_init
+   ...
+}
+{
+   <iconv open>
+   Memcheck:Addr4
+   obj:/lib/libc-*.so
+   obj:/lib/libglib-2.0.so*
+   fun:g_iconv_open
+   ...
+   fun:g_convert
+   fun:g_locale_to_utf8
+   fun:g_strerror
+   fun:g_key_file_load_from_file
+   ...
+}
+{
+   <ioctl ADDRT/DELRT>
+   Memcheck:Param
+   ioctl(SIOCADDRT/DELRT)
+   obj:/lib/ld-*.so
+   ...
+}
+{
+   <g_main_loop>
+   Memcheck:Leak
+   fun:memalign
+   ...
+   fun:g_slice_alloc
+   ...
+   fun:g_main_loop_new
+   ...
+}
+{
+   <g_option_context_parse>
+   Memcheck:Leak
+   ...
+   fun:g_slice_alloc
+   ...
+   fun:g_option_context_parse
+   ...
+}
+{
+   <g_key_file_load_from_data>
+   Memcheck:Leak
+   ...
+   fun:g_slice_alloc
+   ...
+   fun:g_key_file_load_from_data
+   ...
+}
+{
+   <g_key_file_new 1>
+   Memcheck:Leak
+   ...
+   fun:g_slice_alloc
+   ...
+   fun:g_key_file_new
+   ...
+}
+{
+   <g_key_file_new 2>
+   Memcheck:Leak
+   fun:*alloc
+   ...
+   fun:g_key_file_new
+   fun:main
+}
+{
+   <connman plugin cleanup>
+   Memcheck:Leak
+   ...
+   fun:__connman_plugin_cleanup
+   ...
+}
+{
+   <cmd line option parsing>
+   Memcheck:Leak
+   fun:malloc
+   fun:g_malloc
+   fun:g_strdup
+   fun:g_set_prgname
+   fun:g_option_context_parse
+   fun:main
+}
+{
+   <dbus system bus setup 1>
+   Memcheck:Leak
+   ...
+   fun:dbus_malloc*
+   ...
+   fun:g_dbus_setup_bus
+   fun:main
+}
+{
+   <dbus system bus setup 2>
+   Memcheck:Leak
+   ...
+   fun:g_malloc*
+   ...
+   fun:dbus_connection_set_watch_functions
+   fun:setup_bus
+   ...
+}
+{
+   <key file get charset>
+   Memcheck:Leak
+   ...
+   fun:g_*alloc*
+   ...
+   fun:g_strerror
+   fun:g_key_file_load_from_file
+   fun:main
+}
+{
+   <dbus disconnect func set>
+   Memcheck:Leak
+   ...
+   fun:filter_data_get
+   fun:g_dbus_add_signal_watch
+   fun:g_dbus_set_disconnect_function
+   fun:main
+}
+{
+   <plugin dlopen>
+   Memcheck:Leak
+   ...
+   fun:dlopen
+   fun:__connman_plugin_init
+   fun:main
+}
+{
+   <dbus system bus setup 3>
+   Memcheck:Leak
+   ...
+   fun:dbus_malloc0
+   ...
+   fun:dbus_parse_address
+   ...
+   fun:g_dbus_setup_bus
+   fun:main
+}
+{
+   <libdbus internals 1>
+   Memcheck:Leak
+   fun:*malloc
+   ...
+   obj:/lib/libdbus-1.so.3.5.3
+}
+{
+   <dbus system bus setup 4>
+   Memcheck:Leak
+   fun:*alloc
+   ...
+   fun:dbus_*alloc*
+   ...
+   fun:g_dbus_setup_bus
+   fun:main
+}
+{
+   <dbus system bus setup 5>
+   Memcheck:Leak
+   fun:calloc
+   fun:g_malloc0
+   ...
+   fun:g_dbus_set_disconnect_function
+   fun:main
+}
+{
+   <dbus bus remove match>
+   Memcheck:Leak
+   fun:malloc
+   fun:g_malloc
+   fun:g_source_set_callback
+   fun:g_timeout_add_full
+   fun:g_timeout_add
+   ...
+   fun:dbus_pending_call_block
+   fun:dbus_connection_send_with_reply_and_block
+   ...
+   fun:dbus_bus_remove_match
+}
+{
+   <g_main_loop_run/new>
+   Memcheck:Leak
+   fun:*alloc
+   ...
+   fun:g_main_loop_*
+   fun:main
+}
+{
+   <g_main_context_dispatch>
+   Memcheck:Leak
+   fun:*alloc
+   ...
+   fun:g_main_context_dispatch
+}
+{
+   <libdbus internals 2>
+   Memcheck:Leak
+   fun:realloc
+   fun:dbus_realloc
+   ...
+   fun:dbus_message_set_reply_serial
+   fun:dbus_message_new_error
+   ...
+}
+{
+   <libdbus internals 3>
+   Memcheck:Leak
+   fun:realloc
+   fun:dbus_realloc
+   ...
+   fun:dbus_message_new_signal
+   ...
+}
+{
+   <dbus_bus_register>
+   Memcheck:Leak
+   fun:malloc
+   fun:realloc
+   fun:dbus_realloc
+   ...
+   fun:dbus_pending_call_block
+   fun:dbus_connection_send_with_reply_and_block
+   fun:dbus_bus_register
+}
diff --git a/connman/doc/vpn-agent-api.txt b/connman/doc/vpn-agent-api.txt
new file mode 100644
index 0000000..72bee9d
--- /dev/null
+++ b/connman/doc/vpn-agent-api.txt
@@ -0,0 +1,158 @@
+Agent hierarchy
+===============
+
+Service		unique name
+Interface	net.connman.vpn.Agent
+Object path	freely definable
+
+Methods		void Release()
+
+			This method gets called when the service daemon
+			unregisters the agent. An agent can use it to do
+			cleanup tasks. There is no need to unregister the
+			agent, because when this method gets called it has
+			already been unregistered.
+
+		void ReportError(object service, string error)
+
+			This method gets called when an error has to be
+			reported to the user.
+
+			A special return value can be used to trigger a
+			retry of the failed transaction.
+
+			Possible Errors: net.connman.vpn.Agent.Error.Retry
+
+		dict RequestInput(object service, dict fields)
+
+			This method gets called when trying to connect to
+			a service and some extra input is required. For
+			example a password or username.
+
+			The return value should be a dictionary where the
+			keys are the field names and the values are the
+			actual fields. Alternatively an error indicating that
+			the request got canceled can be returned.
+
+			Most common return field names are "Username" and of
+			course "Password".
+
+			The dictionary arguments contains field names with
+			their input parameters.
+
+			Possible Errors: net.connman.vpn.Agent.Error.Canceled
+
+		void Cancel()
+
+			This method gets called to indicate that the agent
+			request failed before a reply was returned.
+
+Fields		string Username
+
+			Username for authentication. This field will be
+			requested when connecting to L2TP and PPTP.
+
+		string Password
+
+			Password for authentication.
+
+		boolean SaveCredentials
+
+			Tells if the user wants the user credentials
+			be saved by connman-vpnd.
+
+		string Host
+
+			End point of this VPN link i.e., the VPN gateway
+			we are trying to connect to.
+
+		string Name
+
+			Name of the VPN connection we are trying to connect to.
+
+		string OpenConnect.CACert
+
+			Informational field containing a path name for an
+			additional Certificate Authority file.
+
+		string OpenConnect.ClientCert
+
+			Informational field containing a pkcs11 URL or a path
+                        name for the client certificate.
+
+		string OpenConnect.Cookie
+
+			Return the OpenConnect cookie value that is used for
+			authenticating the VPN session.
+
+		string OpenConnect.ServerCert
+
+			Return the OpenConnect server hash used to identify
+			the final server after possible web authentication
+			logins, selections and redirections.
+
+		string OpenConnect.VPNHost
+
+			Return the final VPN server to use after possible
+			web authentication logins, selections and redirections.
+
+Arguments	string Type
+
+			Contains the type of a field. For example "password",
+			"response", "boolean" or plain "string".
+
+		string Requirement
+
+			Contains the requirement option. Valid values are
+			"mandatory", "optional", "alternate" or
+			"informational".
+
+			The "alternate" value specifies that this field can be
+			returned as an alternative to another one.
+
+			All "mandatory" fields must be returned, while the
+			"optional" can be returned if available.
+
+			Nothing needs to be returned for "informational", as it
+			is here only to provide an information so a value is
+			attached to it.
+
+		array{string} Alternates
+
+			Contains the list of alternate field names this
+			field can be represented by.
+
+		string Value
+
+			Contains data as a string, relatively to an
+			"informational" argument.
+
+Examples	Requesting a username and password for L2TP network
+
+			RequestInput("/vpn1",
+				{ "Username" : { "Type"        : "string",
+						 "Requirement" : "mandatory"
+						} }
+				{ "Password" : { "Type"        : "password",
+						 "Requirement" : "mandatory"
+						} }
+				{ "SaveCredentials" : { "Type" : "boolean",
+						"Requirement" : "optional"
+						}
+				}
+			==> { "Username" : "foo", "Password" : "secret123",
+				"SaveCredentials" : true }
+
+		Requesting a OpenConnect cookie
+
+			RequestInput("/vpn2",
+				{ "OpenConnect.Cookie" : { "Type" : "string",
+						 "Requirement" : "mandatory"
+							} }
+				{ "Host" : { "Type" : "string",
+					 "Requirement" : "informational"
+							} }
+				{ "Name" : { "Type" : "string",
+					 "Requirement" : "informational"
+							} }
+			==> { "OpenConnect.Cookie" : "0123456@adfsf@asasdf" }
diff --git a/connman/doc/vpn-config-format.txt b/connman/doc/vpn-config-format.txt
new file mode 100644
index 0000000..23c9c14
--- /dev/null
+++ b/connman/doc/vpn-config-format.txt
@@ -0,0 +1,235 @@
+Connman configuration file format for VPN
+*****************************************
+
+Connman VPN uses configuration files to provision existing providers.
+vpnd will be looking for its configuration files at VPN_STORAGEDIR
+which by default points to /var/lib/connman-vpn. Configuration file names
+must not include other characters than letters or numbers and must have
+a .config suffix. Those configuration files are text files with a simple
+key-value pair format organized into sections. Values do not comprise leading
+trailing whitespace. We typically have one file per provisioned network.
+
+If the config file is removed, then vpnd tries to remove the
+provisioned service. If an individual service entry inside a config is removed,
+then the corresponding provisioned service is removed. If a service
+section is changed, then the corresponding service is removed and immediately
+re-provisioned.
+
+
+Global section [global]
+=======================
+
+These files can have an optional global section describing the actual file.
+The two allowed fields for this section are:
+- Name: Name of the network.
+- Description: Description of the network.
+
+
+Provider section [provider_*]
+=============================
+
+Each provisioned provider must start with the [provider_*] tag.
+Replace * with an identifier unique to the config file.
+
+Allowed fields:
+- Type: Provider type. Value of OpenConnect, OpenVPN, VPNC, L2TP or PPTP
+
+VPN related parameters (M = mandatory, O = optional):
+- Name: A user defined name for the VPN (M)
+- Host: VPN server IP address (M)
+- Domain: Domain name for the VPN service (M)
+- Networks: The networks behind the VPN link can be defined here. This can
+  be missing if all traffic should go via VPN tunnel. If there are more
+  than one network, then separate them by comma. Format of the entry
+  is network/netmask/gateway. The gateway can be left out. (O)
+  Example: 192.168.100.0/24/10.1.0.1,192.168.200.0/255.255.255.0/10.1.0.2
+  For IPv6 addresses only prefix length is accepted like this 2001:db8::1/64
+
+OpenConnect VPN supports following options (see openconnect(8) for details):
+ Option name            OpenConnect option Description
+ OpenConnect.ServerCert --servercert       SHA1 certificate fingerprint of the
+                                           final VPN server after possible web
+                                           authentication login, selection and
+                                           redirection (O)
+ OpenConnect.CACert     --cafile           File containing other Certificate
+                                           Authorities in addition to the ones
+                                           in the system trust database (O)
+ OpenConnect.ClientCert --certificate      Client certificate file, if needed
+                                           by web authentication (O)
+ VPN.MTU                --mtu              Request MTU from server as the MTU
+                                           of the tunnel (O)
+ OpenConnect.Cookie     --cookie-on-stdin  Cookie received as a result of the
+                                           web authentication. As the cookie
+                                           lifetime can be very limited, it
+                                           does not usually make sense to add
+                                           it into the configuration file (O)
+ OpenConnect.VPNHost                       The final VPN server to use after
+                                           completing the web authentication.
+                                           Only usable for extremely simple VPN
+                                           configurations and should normally
+                                           be set only via the VPN Agent API.
+If OpenConnect.Cookie or OpenConnect.ServerCert are missing, the VPN Agent will
+be contacted to supply the information.
+
+OpenVPN VPN supports following options (see openvpn(8) for details):
+ Option name            OpenVPN option   Description
+ OpenVPN.CACert         --ca             Certificate authority file (M)
+ OpenVPN.Cert           --cert           Local peer's signed certificate (M)
+ OpenVPN.Key            --key            Local peer's private key (M)
+ OpenVPN.MTU            --mtu            MTU of the tunnel (O)
+ OpenVPN.NSCertType     --ns-cert-type   Peer certificate type, value of
+                                         either server or client (O)
+ OpenVPN.Proto          --proto          Use protocol (O)
+ OpenVPN.Port           --port           TCP/UDP port number (O)
+ OpenVPN.AuthUserPass   --auth-user-pass Authenticate with server using
+                                         username/password (O)
+ OpenVPN.AskPass        --askpass        Get certificate password from file (O)
+ OpenVPN.AuthNoCache    --auth-nocache   Don't cache --askpass or
+                                         --auth-user-pass value (O)
+ OpenVPN.TLSRemote      --tls-remote     Accept connections only from a host
+                                         with X509 name or common name equal
+                                         to name parameter (O)
+ OpenVPN.TLSAuth        sub-option of --tls-remote (O)
+ OpenVPN.TLSAuthDir     sub-option of --tls-remote (O)
+ OpenVPN.Cipher         --cipher         Encrypt packets with cipher algorithm
+                                         given as parameter (O)
+ OpenVPN.Auth           --auth           Authenticate  packets with HMAC using
+                                         message digest algorithm alg (O)
+ OpenVPN.CompLZO        --comp-lzo       Use  fast  LZO compression. Value can
+                                         be "yes", "no", or "adaptive". Default
+                                         is adaptive (O)
+ OpenVPN.RemoteCertTls  --remote-cert-tls Require that peer certificate was
+                                          signed based on RFC3280 TLS rules.
+                                          Value is "client" or "server" (O)
+ OpenVPN.ConfigFile     --config         OpenVPN config file that can contain
+                                         extra options not supported by OpenVPN
+                                         plugin (O)
+
+VPNC VPN supports following options (see vpnc(8) for details):
+ Option name         VPNC config value     Description
+ VPNC.IPSec.ID       IPSec ID              your group username (M)
+ VPNC.IPSec.Secret   IPSec secret          your group password (cleartext) (O)
+ VPNC.Xauth.Username Xauth username        your username (O)
+ VPNC.Xauth.Password Xauth password        your password (cleartext) (O)
+ VPNC.IKE.Authmode   IKE Authmode          IKE Authentication mode (O)
+ VPNC.IKE.DHGroup    IKE DH Group          name of the IKE DH Group (O)
+ VPNC.PFS Perfect    Forward Secrecy       Diffie-Hellman group to use for PFS (O)
+ VPNC.Domain         Domain                Domain name for authentication (O)
+ VPNC.Vendor         Vendor                vendor of your IPSec gateway (O)
+ VPNC.LocalPort      Local Port            local ISAKMP port number to use
+ VPNC.CiscoPort      Cisco UDP Encapsulation Port  Local UDP port number to use (O)
+ VPNC.AppVersion     Application Version   Application Version to report (O)
+ VPNC.NATTMode       NAT Traversal Mode    Which NAT-Traversal Method to use (O)
+ VPNC.DPDTimeout     DPD idle timeout (our side)  Send DPD packet after timeout (O)
+ VPNC.SingleDES      Enable Single DES     enables single DES encryption (O)
+ VPNC.NoEncryption   Enable no encryption  enables using no encryption for data traffic (O)
+
+L2TP VPN supports following options (see xl2tpd.conf(5) and pppd(8) for details)
+ Option name         xl2tpd config value    Description
+ L2TP.User           -                      L2TP user name, asked from the user
+                                            if not set here (O)
+ L2TP.Password       -                      L2TP password, asked from the user
+                                            if not set here (O)
+ L2TP.BPS            bps                    Max bandwith to use (O)
+ L2TP.TXBPS          tx bps                 Max transmit bandwith to use (O)
+ L2TP.RXBPS          rx bps                 Max receive bandwith to use (O)
+ L2TP.LengthBit      length bit             Use length bit (O)
+ L2TP.Challenge      challenge              Use challenge authentication (O)
+ L2TP.DefaultRoute   defaultroute           Default route (O)
+ L2TP.FlowBit        flow bit               Use seq numbers (O)
+ L2TP.TunnelRWS      tunnel rws             Window size (O)
+ L2TP.Exclusive      exclusive              Use only one control channel (O)
+ L2TP.Redial         redial                 Redial if disconnected (O)
+ L2TP.RedialTimeout  redial timeout         Redial timeout (O)
+ L2TP.MaxRedials     max redials            How many times to try redial (O)
+ L2TP.RequirePAP     require pap            Need pap (O)
+ L2TP.RequireCHAP    require chap           Need chap (O)
+ L2TP.ReqAuth        require authentication Need auth (O)
+ L2TP.AccessControl  access control         Accept only these peers (O)
+ L2TP.AuthFile       auth file              Authentication file location (O)
+ L2TP.ListenAddr     listen-addr            Listen address (O)
+ L2TP.IPsecSaref     ipsec saref            Use IPSec SA (O)
+ L2TP.Port           port                   What UDP port is used (O)
+
+ Option name         pppd config value      Description
+ PPPD.EchoFailure    lcp-echo-failure       Dead peer check count (O)
+ PPPD.EchoInterval   lcp-echo-interval      Dead peer check interval (O)
+ PPPD.Debug          debug                  Debug level (O)
+ PPPD.RefuseEAP      refuse-eap             Deny eap auth (O)
+ PPPD.RefusePAP      refuse-pap             Deny pap auth (O)
+ PPPD.RefuseCHAP     refuse-chap            Deny chap auth (O)
+ PPPD.RefuseMSCHAP   refuse-mschap          Deny mschap auth (O)
+ PPPD.RefuseMSCHAP2  refuse-mschapv2        Deny mschapv2 auth (O)
+ PPPD.NoBSDComp      nobsdcomp              Disables BSD compression (O)
+ PPPD.NoPcomp        nopcomp                Disable protocol compression (O)
+ PPPD.UseAccomp      accomp                 Disable address/control compression (O)
+ PPPD.NoDeflate      nodeflate              Disable deflate compression (O)
+ PPPD.ReqMPPE        require-mppe           Require the use of MPPE (O)
+ PPPD.ReqMPPE40      require-mppe-40        Require the use of MPPE 40 bit (O)
+ PPPD.ReqMPPE128     require-mppe-128       Require the use of MPPE 128 bit (O)
+ PPPD.ReqMPPEStateful mppe-stateful         Allow MPPE to use stateful mode (O)
+ PPPD.NoVJ           no-vj-comp             No Van Jacobson compression (O)
+
+
+PPTP VPN supports following options (see pptp(8) and pppd(8) for details)
+ Option name         pptp config value    Description
+ PPTP.User           -                    PPTP user name, asked from the user
+                                          if not set here (O)
+ PPTP.Password       -                    PPTP password, asked from the user
+                                          if not set here (O)
+
+ Option name         pppd config value    Description
+ PPPD.EchoFailure    lcp-echo-failure     Dead peer check count (O)
+ PPPD.EchoInterval   lcp-echo-interval    Dead peer check interval (O)
+ PPPD.Debug          debug                Debug level (O)
+ PPPD.RefuseEAP      refuse-eap           Deny eap auth (O)
+ PPPD.RefusePAP      refuse-pap           Deny pap auth (O)
+ PPPD.RefuseCHAP     refuse-chap          Deny chap auth (O)
+ PPPD.RefuseMSCHAP   refuse-mschap        Deny mschap auth (O)
+ PPPD.RefuseMSCHAP2  refuse-mschapv2      Deny mschapv2 auth (O)
+ PPPD.NoBSDComp      nobsdcomp            Disables BSD compression (O)
+ PPPD.NoDeflate      nodeflate            Disable deflate compression (O)
+ PPPD.RequirMPPE     require-mppe         Require the use of MPPE (O)
+ PPPD.RequirMPPE40   require-mppe-40      Require the use of MPPE 40 bit (O)
+ PPPD.RequirMPPE128  require-mppe-128     Require the use of MPPE 128 bit (O)
+ PPPD.RequirMPPEStateful mppe-stateful    Allow MPPE to use stateful mode (O)
+ PPPD.NoVJ           no-vj-comp           No Van Jacobson compression (O)
+
+
+Example
+=======
+
+This is a configuration file for a VPN providing L2TP, OpenVPN and
+OpenConnect services.
+
+
+example@example:[~]$ cat /var/lib/connman/vpn/example.config
+[global]
+Name = Example
+Description = Example VPN configuration
+
+[provider_l2tp]
+Type = L2TP
+Name = Connection to corporate network
+Host = 1.2.3.4
+Domain = corporate.com
+Networks = 10.10.30.0/24
+L2TP.User = username
+
+[provider_openconnect]
+Type = OpenConnect
+Name = Connection to corporate network using Cisco VPN
+Host = 7.6.5.4
+Domain = corporate.com
+Networks = 10.10.20.0/255.255.255.0/10.20.1.5,192.168.99.1/24,2001:db8::1/64
+OpenConnect.ServerCert = 263AFAB4CB2E6621D12E90182008AEF44AEFA031
+OpenConnect.CACert = /etc/certs/certificate.p12
+
+[provider_openvpn]
+Type = OpenVPN
+Name = Connection to corporate network using OpenVPN
+Host = 3.2.5.6
+Domain = my.home.network
+OpenVPN.CACert = /etc/certs/cacert.pem
+OpenVPN.Cert = /etc/certs/cert.pem
+OpenVPN.Key = /etc/certs/cert.key
diff --git a/connman/doc/vpn-connection-api.txt b/connman/doc/vpn-connection-api.txt
new file mode 100644
index 0000000..4367699
--- /dev/null
+++ b/connman/doc/vpn-connection-api.txt
@@ -0,0 +1,181 @@
+vpn connection
+==============
+
+Service		net.connman.vpn
+Interface	net.connman.vpn.Connection
+Object path	[variable prefix]/{connection0,connection1,...}
+
+Methods		dict GetProperties()  [experimental]
+
+			Returns properties for the connection object. See
+			the properties section for available properties.
+
+			Possible Errors: [connection].Error.InvalidArguments
+
+		void SetProperty(string name, variant value) [experimental]
+
+			Changes the value of the specified property. Only
+			properties that are listed as read-write are
+			changeable. On success a PropertyChanged signal
+			will be emitted.
+
+			Possible Errors: [connection].Error.InvalidArguments
+					 [connection].Error.InvalidProperty
+
+		void ClearProperty(string name) [experimental]
+
+			Clears the value of the specified property.
+
+			Possible Errors: [connection].Error.InvalidArguments
+					 [connection].Error.InvalidProperty
+
+		void Connect() [experimental]
+
+			Connect this VPN connection. It will attempt to connect
+			to the VPN connection. The Connect() will wait until
+			the connection is created or there is an error. The
+			error description is returned in dbus error.
+
+			Possible Errors: [connection].Error.InvalidArguments
+					[connection].Error.InProgress
+
+		void Disconnect() [experimental]
+
+			Disconnect this VPN connection. If the connection is
+			not connected an error message will be generated.
+
+			Possible Errors: [connection].Error.InvalidArguments
+
+Signals		PropertyChanged(string name, variant value) [experimental]
+
+			This signal indicates a changed value of the given
+			property.
+
+Properties	string State [readonly]
+
+			The connection state information.
+
+			Valid states are "idle", "failure", "configuration",
+			"ready", "disconnect".
+
+		string Type [readonly]
+
+			The VPN type (for example "openvpn", "vpnc" etc.)
+
+		string Name [readonly]
+
+			The VPN name.
+
+		string Domain [readonly]
+
+			The domain name used behind the VPN connection.
+			This is optional for most VPN technologies.
+
+		string Host [readonly]
+
+		       The VPN host (server) address.
+
+		boolean Immutable [readonly]
+
+			This value will be set to true if the connection is
+			configured externally via a configuration file.
+
+			The only valid operation are Connect(), Disconnect()
+                        and GetProperties()
+
+		int Index [readonly]
+
+			The index of the VPN network tunneling interface.
+			If there is no tunneling device, then this value
+			is not returned.
+
+		dict IPv4 [readonly]
+
+			string Address
+
+			        The current configured IPv4 address.
+
+			string Netmask
+
+			       The current configured IPv4 netmask.
+
+			string Gateway
+
+			       The current configured IPv4 gateway.
+
+			string Peer
+
+			       The current configured VPN tunnel endpoint
+			       IPv4 address.
+
+		dict IPv6 [readonly]
+
+			string Address
+
+			        The current configured IPv6 address.
+
+			string PrefixLength
+
+			       The prefix length of the IPv6 address.
+
+			string Gateway
+
+			       The current configured IPv6 gateway.
+
+			string Peer
+
+			       The current configured VPN tunnel endpoint
+			       IPv6 address.
+
+		array{string} Nameservers [readonly]
+
+			The list of nameservers set by VPN.
+
+		array{dict} UserRoutes [readwrite]
+
+			int ProtocolFamily
+
+				Protocol family of the route. Set to 4
+				if IPv4 and 6 if IPv6 route.
+
+			string Network
+
+				The network part of the route.
+
+			string Netmask
+
+				The netmask of the route.
+
+			string Gateway
+
+				Gateway address of the route.
+
+			The list of currently active user activated
+			routes.
+
+		array{dict} ServerRoutes [readonly]
+
+			int ProtocolFamily
+
+				Protocol family of the route. Set to 4
+				if IPv4 and 6 if IPv6 route.
+
+			string Network
+
+				The network part of the route.
+
+			string Netmask
+
+				The netmask of the route.
+
+			string Gateway
+
+				Gateway address of the route.
+
+			The VPN server activated route. These routes
+			are pushed to connman by VPN server.
+
+		There can be other properties also but as the VPN
+		technologies are so different, they have different
+		kind of options that they need, so not all options
+		are mentioned in this document.
diff --git a/connman/doc/vpn-manager-api.txt b/connman/doc/vpn-manager-api.txt
new file mode 100644
index 0000000..66c5bee
--- /dev/null
+++ b/connman/doc/vpn-manager-api.txt
@@ -0,0 +1,50 @@
+vpn manager
+===========
+
+Service		net.connman.vpn
+Interface	net.connman.vpn.Manager
+Object path	/
+
+Method		object Create(dict settings) [experimental]
+
+			Create a new VPN connection and configuration using
+			the supplied settings.
+
+		void Remove(object vpn)  [experimental]
+
+			Remove the previously created VPN configuration.
+
+		array{object,dict} GetConnections()  [experimental]
+
+			Returns a list of tuples with VPN connection object
+			path and dictionary of their properties.
+
+			Possible Errors: [manager].Error.InvalidArguments
+
+		void RegisterAgent(object path)  [experimental]
+
+			Register new agent for handling user requests.
+
+			Possible Errors: [manager].Error.InvalidArguments
+
+		void UnregisterAgent(object path)  [experimental]
+
+			Unregister an existing agent.
+
+			Possible Errors: [manager].Error.InvalidArguments
+
+Signals		ConnectionAdded(object path, dict properties)  [experimental]
+
+			Signal that is sent when a new VPN connection
+			is added.
+
+			It contains the object path of the VPN connection
+			and also its properties.
+
+		ConnectionRemoved(object path)  [experimental]
+
+			Signal that is sent when a VPN connection
+			has been removed.
+
+			The object path is no longer accessible after this
+			signal and only emitted for reference.
diff --git a/connman/doc/vpn-overview.txt b/connman/doc/vpn-overview.txt
new file mode 100644
index 0000000..42b6e94
--- /dev/null
+++ b/connman/doc/vpn-overview.txt
@@ -0,0 +1,60 @@
+VPN daemon overview
+*******************
+
+
+Manager interface
+=================
+
+Manager interface described in vpn-manager-api.txt is to be used
+by both the connectivity UI and by ConnMan. The Create(),
+Remove(), RegisterAgent() and UnregisterAgent() functions are for
+UI usage. The GetConnections() method and ConnectionAdded() and
+ConnectionRemoved() signals are for ConnMan VPN plugin to use.
+
+The UI should use the methods like this:
+- Ask VPN properties (like certs, usernames etc) from the user.
+- Call Manager.Create() to create a VPN connection (note that
+  the system does not yet try to connect to VPN at this point)
+- Register an agent to vpnd so that vpnd can ask any extra
+  parameters etc from the user if needed.
+- If the user wants to connect to VPN gateway, then the
+  connection attempt should be done in ConnMan side as
+  there will be a service created there.
+- If the user wishes to remove the VPN configuration, the UI
+  can call the Manager.Remove() which removes the VPN connection.
+  If the VPN was in use, the VPN connection is also disconnected.
+- When UI is terminated, the UI should call the UnregisterAgent()
+
+The ConnMan calls VPN daemon like this:
+- There is a VPN plugin which at startup starts to listen the
+  ConnectionAdded() and ConnectionRemoved() signals.
+- The VPN plugin will call GetConnections() in order to get
+  available VPN connections. It will then create a provider service
+  for each VPN connection that is returned.
+- User can then connect to the VPN by calling the service Connect()
+  method
+- The existing ConnMan Manager.ConnectProvider() interface can still
+  work by calling vpn.Manager.Create() and then call vpn.Connection.Connect()
+  but this ConnectProvider() interface will be deprecated at some
+  point.
+
+
+
+Connection interface
+====================
+
+The Manager.Create() will return the object path of the created
+vpn.Connection object and place it in idle state. Note that
+vpn.Connection.PropertyChanged signal is not called when Connection
+object is created because the same parameters are returned via
+vpn.Manager.ConnectionAdded() signal.
+The vpn.Connection object can be connected using the Connect() method
+and disconnected by calling Disconnect() method. When the connection
+is established (meaning VPN client has managed to create a connection
+to VPN server), then State property is set to "ready" and PropertyChanged
+signal is sent. If the connection cannot be established, then
+State property is set to "failure".
+After successfull connection, the relevant connection properties are sent
+by PropertyChanged signal; like IPv[4|6] information, the index of the
+VPN tunneling interface (if there is any), nameserver information,
+server specified routes etc.
diff --git a/connman/doc/wifi-p2p-overview.txt b/connman/doc/wifi-p2p-overview.txt
new file mode 100644
index 0000000..73b677c
--- /dev/null
+++ b/connman/doc/wifi-p2p-overview.txt
@@ -0,0 +1,54 @@
+WiFi P2P Functionality [experimental]
+*************************************
+
+Note: Nothing about WiFi P2P Services is exposed, this is yet to be specified.
+
+Summary
+=======
+
+WiFi P2P is supported as follows:
+- if hardware and wpa_supplicant supports it, a "p2p" technology will appear
+  in the technology list
+- "p2p" technology, as for "wifi" technology, supports a Scan() method. Such
+  method will trigger a P2P find process. The results will be available
+  through the Manager interface, comparable to services being available
+  through this same interface after a Scan() on "wifi" technology.
+- the result of a "p2p" Scan() consists into a list of "peer" objects
+- it is then possible to access peer information, connecting and disconnecting
+  it via the Peer API.
+
+
+API Usage
+=========
+
+The UI willing to access to WiFi P2P technology should proceed this way:
+- Request Manager.GetTechnologies() and figure out from the result if "p2p"
+  technology is provided. What comes next implies this successful case.
+- Add a listener to signal Manager.PeersChanged(): this signal will provide
+  the results of a "p2p" technology Scan().
+- From the "p2p" technology object, request a Technology.Scan() method. This
+  will run for a while a P2P find process.
+- If P2P peers are found, it will be signaled through Manager.PeersChanged().
+  Objects are "Peer" objects. UI might use Manager.GetPeers() instead, if
+  listening to a signal is not the preferred way.
+- Once selected the proper Peer object, request a Peer.Connect() method on it
+  so it will connect to it. Peer.Disconnect() will disconnect.
+
+Internals
+=========
+
+Through such API, everything is made to hide irrelevant informations for the
+applications, which are:
+
+- Everything related to the P2P group and the Group Owner (GO)
+- All low level peer settings
+- All Service Request Discovery mechanism
+
+Hiding this mean ConnMan will handle it properly behind.
+
+For instance, if you connect to a Peer which happens to be a persistent GO
+ConnMan will notice it and store the Group information for a later connection
+to speed up such connection.
+
+For Service Discovery (SD), this will be handled the same way: silently
+behind, by ConnMan.
diff --git a/connman/gdbus/client.c b/connman/gdbus/client.c
new file mode 100644
index 0000000..48711ae
--- /dev/null
+++ b/connman/gdbus/client.c
@@ -0,0 +1,1398 @@
+/*
+ *
+ *  D-Bus helper library
+ *
+ *  Copyright (C) 2004-2011  Marcel Holtmann <marcel@holtmann.org>
+ *
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  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 <stdio.h>
+#include <glib.h>
+#include <dbus/dbus.h>
+
+#include "gdbus.h"
+
+#define METHOD_CALL_TIMEOUT (300 * 1000)
+
+#ifndef DBUS_INTERFACE_OBJECT_MANAGER
+#define DBUS_INTERFACE_OBJECT_MANAGER DBUS_INTERFACE_DBUS ".ObjectManager"
+#endif
+
+struct GDBusClient {
+	int ref_count;
+	DBusConnection *dbus_conn;
+	char *service_name;
+	char *base_path;
+	char *root_path;
+	guint watch;
+	guint added_watch;
+	guint removed_watch;
+	GPtrArray *match_rules;
+	DBusPendingCall *pending_call;
+	DBusPendingCall *get_objects_call;
+	GDBusWatchFunction connect_func;
+	void *connect_data;
+	GDBusWatchFunction disconn_func;
+	gboolean connected;
+	void *disconn_data;
+	GDBusMessageFunction signal_func;
+	void *signal_data;
+	GDBusProxyFunction proxy_added;
+	GDBusProxyFunction proxy_removed;
+	GDBusClientFunction ready;
+	void *ready_data;
+	GDBusPropertyFunction property_changed;
+	void *user_data;
+	GList *proxy_list;
+};
+
+struct GDBusProxy {
+	int ref_count;
+	GDBusClient *client;
+	char *obj_path;
+	char *interface;
+	GHashTable *prop_list;
+	guint watch;
+	GDBusPropertyFunction prop_func;
+	void *prop_data;
+	GDBusProxyFunction removed_func;
+	void *removed_data;
+};
+
+struct prop_entry {
+	char *name;
+	int type;
+	DBusMessage *msg;
+};
+
+static void modify_match_reply(DBusPendingCall *call, void *user_data)
+{
+	DBusMessage *reply = dbus_pending_call_steal_reply(call);
+	DBusError error;
+
+	dbus_error_init(&error);
+
+	if (dbus_set_error_from_message(&error, reply) == TRUE)
+		dbus_error_free(&error);
+
+	dbus_message_unref(reply);
+}
+
+static gboolean modify_match(DBusConnection *conn, const char *member,
+							const char *rule)
+{
+	DBusMessage *msg;
+	DBusPendingCall *call;
+
+	msg = dbus_message_new_method_call(DBUS_SERVICE_DBUS, DBUS_PATH_DBUS,
+					DBUS_INTERFACE_DBUS, member);
+	if (msg == NULL)
+		return FALSE;
+
+	dbus_message_append_args(msg, DBUS_TYPE_STRING, &rule,
+						DBUS_TYPE_INVALID);
+
+	if (g_dbus_send_message_with_reply(conn, msg, &call, -1) == FALSE) {
+		dbus_message_unref(msg);
+		return FALSE;
+	}
+
+	dbus_pending_call_set_notify(call, modify_match_reply, NULL, NULL);
+	dbus_pending_call_unref(call);
+
+	dbus_message_unref(msg);
+
+	return TRUE;
+}
+
+static void iter_append_iter(DBusMessageIter *base, DBusMessageIter *iter)
+{
+	int type;
+
+	type = dbus_message_iter_get_arg_type(iter);
+
+	if (dbus_type_is_basic(type)) {
+		const void *value;
+
+		dbus_message_iter_get_basic(iter, &value);
+		dbus_message_iter_append_basic(base, type, &value);
+	} else if (dbus_type_is_container(type)) {
+		DBusMessageIter iter_sub, base_sub;
+		char *sig;
+
+		dbus_message_iter_recurse(iter, &iter_sub);
+
+		switch (type) {
+		case DBUS_TYPE_ARRAY:
+		case DBUS_TYPE_VARIANT:
+			sig = dbus_message_iter_get_signature(&iter_sub);
+			break;
+		default:
+			sig = NULL;
+			break;
+		}
+
+		dbus_message_iter_open_container(base, type, sig, &base_sub);
+
+		if (sig != NULL)
+			dbus_free(sig);
+
+		while (dbus_message_iter_get_arg_type(&iter_sub) !=
+							DBUS_TYPE_INVALID) {
+			iter_append_iter(&base_sub, &iter_sub);
+			dbus_message_iter_next(&iter_sub);
+		}
+
+		dbus_message_iter_close_container(base, &base_sub);
+	}
+}
+
+static void prop_entry_update(struct prop_entry *prop, DBusMessageIter *iter)
+{
+	DBusMessage *msg;
+	DBusMessageIter base;
+
+	msg = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_RETURN);
+	if (msg == NULL)
+		return;
+
+	dbus_message_iter_init_append(msg, &base);
+	iter_append_iter(&base, iter);
+
+	if (prop->msg != NULL)
+		dbus_message_unref(prop->msg);
+
+	prop->msg = dbus_message_copy(msg);
+	dbus_message_unref(msg);
+}
+
+static struct prop_entry *prop_entry_new(const char *name,
+						DBusMessageIter *iter)
+{
+	struct prop_entry *prop;
+
+	prop = g_try_new0(struct prop_entry, 1);
+	if (prop == NULL)
+		return NULL;
+
+	prop->name = g_strdup(name);
+	prop->type = dbus_message_iter_get_arg_type(iter);
+
+	prop_entry_update(prop, iter);
+
+	return prop;
+}
+
+static void prop_entry_free(gpointer data)
+{
+	struct prop_entry *prop = data;
+
+	if (prop->msg != NULL)
+		dbus_message_unref(prop->msg);
+
+	g_free(prop->name);
+
+	g_free(prop);
+}
+
+static void add_property(GDBusProxy *proxy, const char *name,
+				DBusMessageIter *iter, gboolean send_changed)
+{
+	GDBusClient *client = proxy->client;
+	DBusMessageIter value;
+	struct prop_entry *prop;
+
+	if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_VARIANT)
+		return;
+
+	dbus_message_iter_recurse(iter, &value);
+
+	prop = g_hash_table_lookup(proxy->prop_list, name);
+	if (prop != NULL) {
+		prop_entry_update(prop, &value);
+		goto done;
+	}
+
+	prop = prop_entry_new(name, &value);
+	if (prop == NULL)
+		return;
+
+	g_hash_table_replace(proxy->prop_list, prop->name, prop);
+
+done:
+	if (proxy->prop_func)
+		proxy->prop_func(proxy, name, &value, proxy->prop_data);
+
+	if (client == NULL || send_changed == FALSE)
+		return;
+
+	if (client->property_changed)
+		client->property_changed(proxy, name, &value,
+							client->user_data);
+}
+
+static void update_properties(GDBusProxy *proxy, DBusMessageIter *iter,
+							gboolean send_changed)
+{
+	DBusMessageIter dict;
+
+	if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_ARRAY)
+		return;
+
+	dbus_message_iter_recurse(iter, &dict);
+
+	while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
+		DBusMessageIter entry;
+		const char *name;
+
+		dbus_message_iter_recurse(&dict, &entry);
+
+		if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING)
+			break;
+
+		dbus_message_iter_get_basic(&entry, &name);
+		dbus_message_iter_next(&entry);
+
+		add_property(proxy, name, &entry, send_changed);
+
+		dbus_message_iter_next(&dict);
+	}
+}
+
+static void get_all_properties_reply(DBusPendingCall *call, void *user_data)
+{
+	GDBusProxy *proxy = user_data;
+	GDBusClient *client = proxy->client;
+	DBusMessage *reply = dbus_pending_call_steal_reply(call);
+	DBusMessageIter iter;
+	DBusError error;
+
+	dbus_error_init(&error);
+
+	if (dbus_set_error_from_message(&error, reply) == TRUE) {
+		dbus_error_free(&error);
+		goto done;
+	}
+
+	dbus_message_iter_init(reply, &iter);
+
+	update_properties(proxy, &iter, FALSE);
+
+done:
+	if (g_list_find(client->proxy_list, proxy) == NULL) {
+		if (client->proxy_added)
+			client->proxy_added(proxy, client->user_data);
+
+		client->proxy_list = g_list_append(client->proxy_list, proxy);
+	}
+
+	dbus_message_unref(reply);
+
+	g_dbus_client_unref(client);
+}
+
+static void get_all_properties(GDBusProxy *proxy)
+{
+	GDBusClient *client = proxy->client;
+	const char *service_name = client->service_name;
+	DBusMessage *msg;
+	DBusPendingCall *call;
+
+	msg = dbus_message_new_method_call(service_name, proxy->obj_path,
+					DBUS_INTERFACE_PROPERTIES, "GetAll");
+	if (msg == NULL)
+		return;
+
+	dbus_message_append_args(msg, DBUS_TYPE_STRING, &proxy->interface,
+							DBUS_TYPE_INVALID);
+
+	if (g_dbus_send_message_with_reply(client->dbus_conn, msg,
+							&call, -1) == FALSE) {
+		dbus_message_unref(msg);
+		return;
+	}
+
+	g_dbus_client_ref(client);
+
+	dbus_pending_call_set_notify(call, get_all_properties_reply,
+							proxy, NULL);
+	dbus_pending_call_unref(call);
+
+	dbus_message_unref(msg);
+}
+
+static GDBusProxy *proxy_lookup(GDBusClient *client, const char *path,
+						const char *interface)
+{
+	GList *list;
+
+	for (list = g_list_first(client->proxy_list); list;
+						list = g_list_next(list)) {
+		GDBusProxy *proxy = list->data;
+
+		if (g_str_equal(proxy->interface, interface) == TRUE &&
+				g_str_equal(proxy->obj_path, path) == TRUE)
+			return proxy;
+        }
+
+	return NULL;
+}
+
+static gboolean properties_changed(DBusConnection *conn, DBusMessage *msg,
+							void *user_data)
+{
+	GDBusProxy *proxy = user_data;
+	GDBusClient *client = proxy->client;
+	DBusMessageIter iter, entry;
+	const char *interface;
+
+	if (dbus_message_iter_init(msg, &iter) == FALSE)
+		return TRUE;
+
+	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
+		return TRUE;
+
+	dbus_message_iter_get_basic(&iter, &interface);
+	dbus_message_iter_next(&iter);
+
+	update_properties(proxy, &iter, TRUE);
+
+	dbus_message_iter_next(&iter);
+
+	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY)
+		return TRUE;
+
+	dbus_message_iter_recurse(&iter, &entry);
+
+	while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
+		const char *name;
+
+		dbus_message_iter_get_basic(&entry, &name);
+
+		g_hash_table_remove(proxy->prop_list, name);
+
+		if (proxy->prop_func)
+			proxy->prop_func(proxy, name, NULL, proxy->prop_data);
+
+		if (client->property_changed)
+			client->property_changed(proxy, name, NULL,
+							client->user_data);
+
+		dbus_message_iter_next(&entry);
+	}
+
+	return TRUE;
+}
+
+static GDBusProxy *proxy_new(GDBusClient *client, const char *path,
+						const char *interface)
+{
+	GDBusProxy *proxy;
+
+	proxy = g_try_new0(GDBusProxy, 1);
+	if (proxy == NULL)
+		return NULL;
+
+	proxy->client = client;
+	proxy->obj_path = g_strdup(path);
+	proxy->interface = g_strdup(interface);
+
+	proxy->prop_list = g_hash_table_new_full(g_str_hash, g_str_equal,
+							NULL, prop_entry_free);
+	proxy->watch = g_dbus_add_properties_watch(client->dbus_conn,
+							client->service_name,
+							proxy->obj_path,
+							proxy->interface,
+							properties_changed,
+							proxy, NULL);
+
+	return g_dbus_proxy_ref(proxy);
+}
+
+static void proxy_free(gpointer data)
+{
+	GDBusProxy *proxy = data;
+
+	if (proxy->client) {
+		GDBusClient *client = proxy->client;
+
+		if (client->proxy_removed)
+			client->proxy_removed(proxy, client->user_data);
+
+		g_dbus_remove_watch(client->dbus_conn, proxy->watch);
+
+		g_hash_table_remove_all(proxy->prop_list);
+
+		proxy->client = NULL;
+	}
+
+	if (proxy->removed_func)
+		proxy->removed_func(proxy, proxy->removed_data);
+
+	g_dbus_proxy_unref(proxy);
+}
+
+static void proxy_remove(GDBusClient *client, const char *path,
+						const char *interface)
+{
+	GList *list;
+
+	for (list = g_list_first(client->proxy_list); list;
+						list = g_list_next(list)) {
+		GDBusProxy *proxy = list->data;
+
+		if (g_str_equal(proxy->interface, interface) == TRUE &&
+				g_str_equal(proxy->obj_path, path) == TRUE) {
+			client->proxy_list =
+				g_list_delete_link(client->proxy_list, list);
+			proxy_free(proxy);
+			break;
+		}
+	}
+}
+
+GDBusProxy *g_dbus_proxy_new(GDBusClient *client, const char *path,
+							const char *interface)
+{
+	GDBusProxy *proxy;
+
+	if (client == NULL)
+		return NULL;
+
+	proxy = proxy_lookup(client, path, interface);
+	if (proxy)
+		return g_dbus_proxy_ref(proxy);
+
+	proxy = proxy_new(client, path, interface);
+	if (proxy == NULL)
+		return NULL;
+
+	get_all_properties(proxy);
+
+	return g_dbus_proxy_ref(proxy);
+}
+
+GDBusProxy *g_dbus_proxy_ref(GDBusProxy *proxy)
+{
+	if (proxy == NULL)
+		return NULL;
+
+	__sync_fetch_and_add(&proxy->ref_count, 1);
+
+	return proxy;
+}
+
+void g_dbus_proxy_unref(GDBusProxy *proxy)
+{
+	if (proxy == NULL)
+		return;
+
+	if (__sync_sub_and_fetch(&proxy->ref_count, 1) > 0)
+		return;
+
+	g_hash_table_destroy(proxy->prop_list);
+
+	g_free(proxy->obj_path);
+	g_free(proxy->interface);
+
+	g_free(proxy);
+}
+
+const char *g_dbus_proxy_get_path(GDBusProxy *proxy)
+{
+	if (proxy == NULL)
+		return NULL;
+
+	return proxy->obj_path;
+}
+
+const char *g_dbus_proxy_get_interface(GDBusProxy *proxy)
+{
+	if (proxy == NULL)
+		return NULL;
+
+	return proxy->interface;
+}
+
+gboolean g_dbus_proxy_get_property(GDBusProxy *proxy, const char *name,
+                                                        DBusMessageIter *iter)
+{
+	struct prop_entry *prop;
+
+	if (proxy == NULL || name == NULL)
+		return FALSE;
+
+	prop = g_hash_table_lookup(proxy->prop_list, name);
+	if (prop == NULL)
+		return FALSE;
+
+	if (prop->msg == NULL)
+		return FALSE;
+
+	if (dbus_message_iter_init(prop->msg, iter) == FALSE)
+		return FALSE;
+
+	return TRUE;
+}
+
+struct refresh_property_data {
+	GDBusProxy *proxy;
+	char *name;
+};
+
+static void refresh_property_free(gpointer user_data)
+{
+	struct refresh_property_data *data = user_data;
+
+	g_free(data->name);
+	g_free(data);
+}
+
+static void refresh_property_reply(DBusPendingCall *call, void *user_data)
+{
+	struct refresh_property_data *data = user_data;
+	DBusMessage *reply = dbus_pending_call_steal_reply(call);
+	DBusError error;
+
+	dbus_error_init(&error);
+
+	if (dbus_set_error_from_message(&error, reply) == FALSE) {
+		DBusMessageIter iter;
+
+		dbus_message_iter_init(reply, &iter);
+
+		add_property(data->proxy, data->name, &iter, TRUE);
+	} else
+		dbus_error_free(&error);
+
+	dbus_message_unref(reply);
+}
+
+gboolean g_dbus_proxy_refresh_property(GDBusProxy *proxy, const char *name)
+{
+	struct refresh_property_data *data;
+	GDBusClient *client;
+	DBusMessage *msg;
+	DBusMessageIter iter;
+	DBusPendingCall *call;
+
+	if (proxy == NULL || name == NULL)
+		return FALSE;
+
+	client = proxy->client;
+	if (client == NULL)
+		return FALSE;
+
+	data = g_try_new0(struct refresh_property_data, 1);
+	if (data == NULL)
+		return FALSE;
+
+	data->proxy = proxy;
+	data->name = g_strdup(name);
+
+	msg = dbus_message_new_method_call(client->service_name,
+			proxy->obj_path, DBUS_INTERFACE_PROPERTIES, "Get");
+	if (msg == NULL) {
+		refresh_property_free(data);
+		return FALSE;
+	}
+
+	dbus_message_iter_init_append(msg, &iter);
+	dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING,
+							&proxy->interface);
+	dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &name);
+
+	if (g_dbus_send_message_with_reply(client->dbus_conn, msg,
+							&call, -1) == FALSE) {
+		dbus_message_unref(msg);
+		refresh_property_free(data);
+		return FALSE;
+	}
+
+	dbus_pending_call_set_notify(call, refresh_property_reply,
+						data, refresh_property_free);
+	dbus_pending_call_unref(call);
+
+	dbus_message_unref(msg);
+
+	return TRUE;
+}
+
+struct set_property_data {
+	GDBusResultFunction function;
+	void *user_data;
+	GDBusDestroyFunction destroy;
+};
+
+static void set_property_reply(DBusPendingCall *call, void *user_data)
+{
+	struct set_property_data *data = user_data;
+	DBusMessage *reply = dbus_pending_call_steal_reply(call);
+	DBusError error;
+
+	dbus_error_init(&error);
+
+	dbus_set_error_from_message(&error, reply);
+
+	if (data->function)
+		data->function(&error, data->user_data);
+
+	if (data->destroy)
+		data->destroy(data->user_data);
+
+	dbus_error_free(&error);
+
+	dbus_message_unref(reply);
+}
+
+gboolean g_dbus_proxy_set_property_basic(GDBusProxy *proxy,
+				const char *name, int type, const void *value,
+				GDBusResultFunction function, void *user_data,
+				GDBusDestroyFunction destroy)
+{
+	struct set_property_data *data;
+	GDBusClient *client;
+	DBusMessage *msg;
+	DBusMessageIter iter, variant;
+	DBusPendingCall *call;
+	char type_as_str[2];
+
+	if (proxy == NULL || name == NULL || value == NULL)
+		return FALSE;
+
+	if (dbus_type_is_basic(type) == FALSE)
+		return FALSE;
+
+	client = proxy->client;
+	if (client == NULL)
+		return FALSE;
+
+	data = g_try_new0(struct set_property_data, 1);
+	if (data == NULL)
+		return FALSE;
+
+	data->function = function;
+	data->user_data = user_data;
+	data->destroy = destroy;
+
+	msg = dbus_message_new_method_call(client->service_name,
+			proxy->obj_path, DBUS_INTERFACE_PROPERTIES, "Set");
+	if (msg == NULL) {
+		g_free(data);
+		return FALSE;
+	}
+
+	type_as_str[0] = (char) type;
+	type_as_str[1] = '\0';
+
+	dbus_message_iter_init_append(msg, &iter);
+	dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING,
+							&proxy->interface);
+	dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &name);
+
+	dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT,
+						type_as_str, &variant);
+	dbus_message_iter_append_basic(&variant, type, value);
+	dbus_message_iter_close_container(&iter, &variant);
+
+	if (g_dbus_send_message_with_reply(client->dbus_conn, msg,
+							&call, -1) == FALSE) {
+		dbus_message_unref(msg);
+		g_free(data);
+		return FALSE;
+	}
+
+	dbus_pending_call_set_notify(call, set_property_reply, data, g_free);
+	dbus_pending_call_unref(call);
+
+	dbus_message_unref(msg);
+
+	return TRUE;
+}
+
+gboolean g_dbus_proxy_set_property_array(GDBusProxy *proxy,
+				const char *name, int type, const void *value,
+				size_t size, GDBusResultFunction function,
+				void *user_data, GDBusDestroyFunction destroy)
+{
+	struct set_property_data *data;
+	GDBusClient *client;
+	DBusMessage *msg;
+	DBusMessageIter iter, variant, array;
+	DBusPendingCall *call;
+	char array_sig[3];
+	char type_sig[2];
+
+	if (!proxy || !name || !value)
+		return FALSE;
+
+	if (!dbus_type_is_basic(type))
+		return FALSE;
+
+	client = proxy->client;
+	if (!client)
+		return FALSE;
+
+	data = g_try_new0(struct set_property_data, 1);
+	if (!data)
+		return FALSE;
+
+	data->function = function;
+	data->user_data = user_data;
+	data->destroy = destroy;
+
+	msg = dbus_message_new_method_call(client->service_name,
+						proxy->obj_path,
+						DBUS_INTERFACE_PROPERTIES,
+						"Set");
+	if (!msg) {
+		g_free(data);
+		return FALSE;
+	}
+
+	array_sig[0] = DBUS_TYPE_ARRAY;
+	array_sig[1] = (char) type;
+	array_sig[2] = '\0';
+
+	type_sig[0] = (char) type;
+	type_sig[1] = '\0';
+
+	dbus_message_iter_init_append(msg, &iter);
+	dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING,
+							&proxy->interface);
+	dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &name);
+
+	dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT,
+							array_sig, &variant);
+
+	dbus_message_iter_open_container(&variant, DBUS_TYPE_ARRAY,
+							type_sig, &array);
+
+	if (dbus_type_is_fixed(type))
+		dbus_message_iter_append_fixed_array(&array, type, &value,
+									size);
+	else if (type == DBUS_TYPE_STRING || type == DBUS_TYPE_OBJECT_PATH) {
+		const char **str = (const char **) value;
+		size_t i;
+
+		for (i = 0; i < size; i++)
+			dbus_message_iter_append_basic(&array, type, &str[i]);
+	}
+
+	dbus_message_iter_close_container(&variant, &array);
+	dbus_message_iter_close_container(&iter, &variant);
+
+	if (g_dbus_send_message_with_reply(client->dbus_conn, msg,
+							&call, -1) == FALSE) {
+		dbus_message_unref(msg);
+		g_free(data);
+		return FALSE;
+	}
+
+	dbus_pending_call_set_notify(call, set_property_reply, data, g_free);
+	dbus_pending_call_unref(call);
+
+	dbus_message_unref(msg);
+
+	return TRUE;
+}
+
+struct method_call_data {
+	GDBusReturnFunction function;
+	void *user_data;
+	GDBusDestroyFunction destroy;
+};
+
+static void method_call_reply(DBusPendingCall *call, void *user_data)
+{
+	struct method_call_data *data = user_data;
+	DBusMessage *reply = dbus_pending_call_steal_reply(call);
+
+	if (data->function)
+		data->function(reply, data->user_data);
+
+	if (data->destroy)
+		data->destroy(data->user_data);
+
+	dbus_message_unref(reply);
+}
+
+gboolean g_dbus_proxy_method_call(GDBusProxy *proxy, const char *method,
+				GDBusSetupFunction setup,
+				GDBusReturnFunction function, void *user_data,
+				GDBusDestroyFunction destroy)
+{
+	struct method_call_data *data;
+	GDBusClient *client;
+	DBusMessage *msg;
+	DBusPendingCall *call;
+
+	if (proxy == NULL || method == NULL)
+		return FALSE;
+
+	client = proxy->client;
+	if (client == NULL)
+		return FALSE;
+
+	data = g_try_new0(struct method_call_data, 1);
+	if (data == NULL)
+		return FALSE;
+
+	data->function = function;
+	data->user_data = user_data;
+	data->destroy = destroy;
+
+	msg = dbus_message_new_method_call(client->service_name,
+				proxy->obj_path, proxy->interface, method);
+	if (msg == NULL) {
+		g_free(data);
+		return FALSE;
+	}
+
+	if (setup) {
+		DBusMessageIter iter;
+
+		dbus_message_iter_init_append(msg, &iter);
+		setup(&iter, data->user_data);
+	}
+
+	if (g_dbus_send_message_with_reply(client->dbus_conn, msg,
+					&call, METHOD_CALL_TIMEOUT) == FALSE) {
+		dbus_message_unref(msg);
+		g_free(data);
+		return FALSE;
+	}
+
+	dbus_pending_call_set_notify(call, method_call_reply, data, g_free);
+	dbus_pending_call_unref(call);
+
+	dbus_message_unref(msg);
+
+	return TRUE;
+}
+
+gboolean g_dbus_proxy_set_property_watch(GDBusProxy *proxy,
+			GDBusPropertyFunction function, void *user_data)
+{
+	if (proxy == NULL)
+		return FALSE;
+
+	proxy->prop_func = function;
+	proxy->prop_data = user_data;
+
+	return TRUE;
+}
+
+gboolean g_dbus_proxy_set_removed_watch(GDBusProxy *proxy,
+				GDBusProxyFunction function, void *user_data)
+{
+	if (proxy == NULL)
+		return FALSE;
+
+	proxy->removed_func = function;
+	proxy->removed_data = user_data;
+
+	return TRUE;
+}
+
+static void refresh_properties(GDBusClient *client)
+{
+	GList *list;
+
+	for (list = g_list_first(client->proxy_list); list;
+						list = g_list_next(list)) {
+		GDBusProxy *proxy = list->data;
+
+		get_all_properties(proxy);
+        }
+}
+
+static void parse_properties(GDBusClient *client, const char *path,
+				const char *interface, DBusMessageIter *iter)
+{
+	GDBusProxy *proxy;
+
+	if (g_str_equal(interface, DBUS_INTERFACE_INTROSPECTABLE) == TRUE)
+		return;
+
+	if (g_str_equal(interface, DBUS_INTERFACE_PROPERTIES) == TRUE)
+		return;
+
+	proxy = proxy_lookup(client, path, interface);
+	if (proxy) {
+		update_properties(proxy, iter, FALSE);
+		return;
+	}
+
+	proxy = proxy_new(client, path, interface);
+	if (proxy == NULL)
+		return;
+
+	update_properties(proxy, iter, FALSE);
+
+	if (client->proxy_added)
+		client->proxy_added(proxy, client->user_data);
+
+	client->proxy_list = g_list_append(client->proxy_list, proxy);
+}
+
+static void parse_interfaces(GDBusClient *client, const char *path,
+						DBusMessageIter *iter)
+{
+	DBusMessageIter dict;
+
+	if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_ARRAY)
+		return;
+
+	dbus_message_iter_recurse(iter, &dict);
+
+	while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
+		DBusMessageIter entry;
+		const char *interface;
+
+		dbus_message_iter_recurse(&dict, &entry);
+
+		if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING)
+			break;
+
+		dbus_message_iter_get_basic(&entry, &interface);
+		dbus_message_iter_next(&entry);
+
+		parse_properties(client, path, interface, &entry);
+
+		dbus_message_iter_next(&dict);
+	}
+}
+
+static gboolean interfaces_added(DBusConnection *conn, DBusMessage *msg,
+							void *user_data)
+{
+	GDBusClient *client = user_data;
+	DBusMessageIter iter;
+	const char *path;
+
+	if (dbus_message_iter_init(msg, &iter) == FALSE)
+		return TRUE;
+
+	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_OBJECT_PATH)
+		return TRUE;
+
+	dbus_message_iter_get_basic(&iter, &path);
+	dbus_message_iter_next(&iter);
+
+	g_dbus_client_ref(client);
+
+	parse_interfaces(client, path, &iter);
+
+	g_dbus_client_unref(client);
+
+	return TRUE;
+}
+
+static gboolean interfaces_removed(DBusConnection *conn, DBusMessage *msg,
+							void *user_data)
+{
+	GDBusClient *client = user_data;
+	DBusMessageIter iter, entry;
+	const char *path;
+
+	if (dbus_message_iter_init(msg, &iter) == FALSE)
+		return TRUE;
+
+	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_OBJECT_PATH)
+		return TRUE;
+
+	dbus_message_iter_get_basic(&iter, &path);
+	dbus_message_iter_next(&iter);
+
+	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY)
+		return TRUE;
+
+	dbus_message_iter_recurse(&iter, &entry);
+
+	g_dbus_client_ref(client);
+
+	while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
+		const char *interface;
+
+		dbus_message_iter_get_basic(&entry, &interface);
+		proxy_remove(client, path, interface);
+		dbus_message_iter_next(&entry);
+	}
+
+	g_dbus_client_unref(client);
+
+	return TRUE;
+}
+
+static void parse_managed_objects(GDBusClient *client, DBusMessage *msg)
+{
+	DBusMessageIter iter, dict;
+
+	if (dbus_message_iter_init(msg, &iter) == FALSE)
+		return;
+
+	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY)
+		return;
+
+	dbus_message_iter_recurse(&iter, &dict);
+
+	while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
+		DBusMessageIter entry;
+		const char *path;
+
+		dbus_message_iter_recurse(&dict, &entry);
+
+		if (dbus_message_iter_get_arg_type(&entry) !=
+							DBUS_TYPE_OBJECT_PATH)
+			break;
+
+		dbus_message_iter_get_basic(&entry, &path);
+		dbus_message_iter_next(&entry);
+
+		parse_interfaces(client, path, &entry);
+
+		dbus_message_iter_next(&dict);
+	}
+
+	if (client->ready)
+		client->ready(client, client->ready_data);
+}
+
+static void get_managed_objects_reply(DBusPendingCall *call, void *user_data)
+{
+	GDBusClient *client = user_data;
+	DBusMessage *reply = dbus_pending_call_steal_reply(call);
+	DBusError error;
+
+	g_dbus_client_ref(client);
+
+	dbus_error_init(&error);
+
+	if (dbus_set_error_from_message(&error, reply) == TRUE) {
+		dbus_error_free(&error);
+		goto done;
+	}
+
+	parse_managed_objects(client, reply);
+
+done:
+	dbus_message_unref(reply);
+
+	dbus_pending_call_unref(client->get_objects_call);
+	client->get_objects_call = NULL;
+
+	g_dbus_client_unref(client);
+}
+
+static void get_managed_objects(GDBusClient *client)
+{
+	DBusMessage *msg;
+
+	if (!client->connected)
+		return;
+
+	if ((!client->proxy_added && !client->proxy_removed) ||
+							!client->root_path) {
+		refresh_properties(client);
+		return;
+	}
+
+	if (client->get_objects_call != NULL)
+		return;
+
+	msg = dbus_message_new_method_call(client->service_name,
+						client->root_path,
+						DBUS_INTERFACE_OBJECT_MANAGER,
+						"GetManagedObjects");
+	if (msg == NULL)
+		return;
+
+	dbus_message_append_args(msg, DBUS_TYPE_INVALID);
+
+	if (g_dbus_send_message_with_reply(client->dbus_conn, msg,
+				&client->get_objects_call, -1) == FALSE) {
+		dbus_message_unref(msg);
+		return;
+	}
+
+	dbus_pending_call_set_notify(client->get_objects_call,
+						get_managed_objects_reply,
+						client, NULL);
+
+	dbus_message_unref(msg);
+}
+
+static void service_connect(DBusConnection *conn, void *user_data)
+{
+	GDBusClient *client = user_data;
+
+	g_dbus_client_ref(client);
+
+	client->connected = TRUE;
+
+	if (client->connect_func)
+		client->connect_func(conn, client->connect_data);
+
+	get_managed_objects(client);
+
+	g_dbus_client_unref(client);
+}
+
+static void service_disconnect(DBusConnection *conn, void *user_data)
+{
+	GDBusClient *client = user_data;
+
+	client->connected = FALSE;
+
+	g_list_free_full(client->proxy_list, proxy_free);
+	client->proxy_list = NULL;
+
+	if (client->disconn_func)
+		client->disconn_func(conn, client->disconn_data);
+}
+
+static DBusHandlerResult message_filter(DBusConnection *connection,
+					DBusMessage *message, void *user_data)
+{
+	GDBusClient *client = user_data;
+	const char *sender, *path, *interface;
+
+	if (dbus_message_get_type(message) != DBUS_MESSAGE_TYPE_SIGNAL)
+		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+	sender = dbus_message_get_sender(message);
+	if (sender == NULL)
+		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+	path = dbus_message_get_path(message);
+	interface = dbus_message_get_interface(message);
+
+	if (g_str_has_prefix(path, client->base_path) == FALSE)
+		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+	if (g_str_equal(interface, DBUS_INTERFACE_PROPERTIES) == TRUE)
+		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+	if (client->signal_func)
+		client->signal_func(connection, message, client->signal_data);
+
+	return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+
+GDBusClient *g_dbus_client_new(DBusConnection *connection,
+					const char *service, const char *path)
+{
+	return g_dbus_client_new_full(connection, service, path, "/");
+}
+
+GDBusClient *g_dbus_client_new_full(DBusConnection *connection,
+							const char *service,
+							const char *path,
+							const char *root_path)
+{
+	GDBusClient *client;
+	unsigned int i;
+
+	if (!connection || !service)
+		return NULL;
+
+	client = g_try_new0(GDBusClient, 1);
+	if (client == NULL)
+		return NULL;
+
+	if (dbus_connection_add_filter(connection, message_filter,
+						client, NULL) == FALSE) {
+		g_free(client);
+		return NULL;
+	}
+
+	client->dbus_conn = dbus_connection_ref(connection);
+	client->service_name = g_strdup(service);
+	client->base_path = g_strdup(path);
+	client->root_path = g_strdup(root_path);
+	client->connected = FALSE;
+
+	client->match_rules = g_ptr_array_sized_new(1);
+	g_ptr_array_set_free_func(client->match_rules, g_free);
+
+	client->watch = g_dbus_add_service_watch(connection, service,
+						service_connect,
+						service_disconnect,
+						client, NULL);
+
+	if (!root_path)
+		return g_dbus_client_ref(client);
+
+	client->added_watch = g_dbus_add_signal_watch(connection, service,
+						client->root_path,
+						DBUS_INTERFACE_OBJECT_MANAGER,
+						"InterfacesAdded",
+						interfaces_added,
+						client, NULL);
+	client->removed_watch = g_dbus_add_signal_watch(connection, service,
+						client->root_path,
+						DBUS_INTERFACE_OBJECT_MANAGER,
+						"InterfacesRemoved",
+						interfaces_removed,
+						client, NULL);
+	g_ptr_array_add(client->match_rules, g_strdup_printf("type='signal',"
+				"sender='%s',path_namespace='%s'",
+				client->service_name, client->base_path));
+
+	for (i = 0; i < client->match_rules->len; i++) {
+		modify_match(client->dbus_conn, "AddMatch",
+				g_ptr_array_index(client->match_rules, i));
+	}
+
+	return g_dbus_client_ref(client);
+}
+
+GDBusClient *g_dbus_client_ref(GDBusClient *client)
+{
+	if (client == NULL)
+		return NULL;
+
+	__sync_fetch_and_add(&client->ref_count, 1);
+
+	return client;
+}
+
+void g_dbus_client_unref(GDBusClient *client)
+{
+	unsigned int i;
+
+	if (client == NULL)
+		return;
+
+	if (__sync_sub_and_fetch(&client->ref_count, 1) > 0)
+		return;
+
+	if (client->pending_call != NULL) {
+		dbus_pending_call_cancel(client->pending_call);
+		dbus_pending_call_unref(client->pending_call);
+	}
+
+	if (client->get_objects_call != NULL) {
+		dbus_pending_call_cancel(client->get_objects_call);
+		dbus_pending_call_unref(client->get_objects_call);
+	}
+
+	for (i = 0; i < client->match_rules->len; i++) {
+		modify_match(client->dbus_conn, "RemoveMatch",
+				g_ptr_array_index(client->match_rules, i));
+	}
+
+	g_ptr_array_free(client->match_rules, TRUE);
+
+	dbus_connection_remove_filter(client->dbus_conn,
+						message_filter, client);
+
+	g_list_free_full(client->proxy_list, proxy_free);
+
+	/*
+	 * Don't call disconn_func twice if disconnection
+	 * was previously reported.
+	 */
+	if (client->disconn_func && client->connected)
+		client->disconn_func(client->dbus_conn, client->disconn_data);
+
+	g_dbus_remove_watch(client->dbus_conn, client->watch);
+	g_dbus_remove_watch(client->dbus_conn, client->added_watch);
+	g_dbus_remove_watch(client->dbus_conn, client->removed_watch);
+
+	dbus_connection_unref(client->dbus_conn);
+
+	g_free(client->service_name);
+	g_free(client->base_path);
+	g_free(client->root_path);
+
+	g_free(client);
+}
+
+gboolean g_dbus_client_set_connect_watch(GDBusClient *client,
+				GDBusWatchFunction function, void *user_data)
+{
+	if (client == NULL)
+		return FALSE;
+
+	client->connect_func = function;
+	client->connect_data = user_data;
+
+	return TRUE;
+}
+
+gboolean g_dbus_client_set_disconnect_watch(GDBusClient *client,
+				GDBusWatchFunction function, void *user_data)
+{
+	if (client == NULL)
+		return FALSE;
+
+	client->disconn_func = function;
+	client->disconn_data = user_data;
+
+	return TRUE;
+}
+
+gboolean g_dbus_client_set_signal_watch(GDBusClient *client,
+				GDBusMessageFunction function, void *user_data)
+{
+	if (client == NULL)
+		return FALSE;
+
+	client->signal_func = function;
+	client->signal_data = user_data;
+
+	return TRUE;
+}
+
+gboolean g_dbus_client_set_ready_watch(GDBusClient *client,
+				GDBusClientFunction ready, void *user_data)
+{
+	if (client == NULL)
+		return FALSE;
+
+	client->ready = ready;
+	client->ready_data = user_data;
+
+	return TRUE;
+}
+
+gboolean g_dbus_client_set_proxy_handlers(GDBusClient *client,
+					GDBusProxyFunction proxy_added,
+					GDBusProxyFunction proxy_removed,
+					GDBusPropertyFunction property_changed,
+					void *user_data)
+{
+	if (client == NULL)
+		return FALSE;
+
+	client->proxy_added = proxy_added;
+	client->proxy_removed = proxy_removed;
+	client->property_changed = property_changed;
+	client->user_data = user_data;
+
+	if (proxy_added || proxy_removed || property_changed)
+		get_managed_objects(client);
+
+	return TRUE;
+}
diff --git a/connman/gdbus/gdbus.h b/connman/gdbus/gdbus.h
new file mode 100644
index 0000000..87f0000
--- /dev/null
+++ b/connman/gdbus/gdbus.h
@@ -0,0 +1,386 @@
+/*
+ *
+ *  D-Bus helper library
+ *
+ *  Copyright (C) 2004-2011  Marcel Holtmann <marcel@holtmann.org>
+ *
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  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 __GDBUS_H
+#define __GDBUS_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <dbus/dbus.h>
+#include <glib.h>
+
+typedef enum GDBusMethodFlags GDBusMethodFlags;
+typedef enum GDBusSignalFlags GDBusSignalFlags;
+typedef enum GDBusPropertyFlags GDBusPropertyFlags;
+typedef enum GDBusSecurityFlags GDBusSecurityFlags;
+
+typedef struct GDBusArgInfo GDBusArgInfo;
+typedef struct GDBusMethodTable GDBusMethodTable;
+typedef struct GDBusSignalTable GDBusSignalTable;
+typedef struct GDBusPropertyTable GDBusPropertyTable;
+typedef struct GDBusSecurityTable GDBusSecurityTable;
+
+typedef void (* GDBusWatchFunction) (DBusConnection *connection,
+							void *user_data);
+
+typedef void (* GDBusMessageFunction) (DBusConnection *connection,
+					 DBusMessage *message, void *user_data);
+
+typedef gboolean (* GDBusSignalFunction) (DBusConnection *connection,
+					DBusMessage *message, void *user_data);
+
+DBusConnection *g_dbus_setup_bus(DBusBusType type, const char *name,
+							DBusError *error);
+
+DBusConnection *g_dbus_setup_private(DBusBusType type, const char *name,
+							DBusError *error);
+
+gboolean g_dbus_request_name(DBusConnection *connection, const char *name,
+							DBusError *error);
+
+gboolean g_dbus_set_disconnect_function(DBusConnection *connection,
+				GDBusWatchFunction function,
+				void *user_data, DBusFreeFunction destroy);
+
+typedef void (* GDBusDestroyFunction) (void *user_data);
+
+typedef DBusMessage * (* GDBusMethodFunction) (DBusConnection *connection,
+					DBusMessage *message, void *user_data);
+
+typedef gboolean (*GDBusPropertyGetter)(const GDBusPropertyTable *property,
+					DBusMessageIter *iter, void *data);
+
+typedef guint32 GDBusPendingPropertySet;
+
+typedef void (*GDBusPropertySetter)(const GDBusPropertyTable *property,
+			DBusMessageIter *value, GDBusPendingPropertySet id,
+			void *data);
+
+typedef gboolean (*GDBusPropertyExists)(const GDBusPropertyTable *property,
+								void *data);
+
+typedef guint32 GDBusPendingReply;
+
+typedef void (* GDBusSecurityFunction) (DBusConnection *connection,
+						const char *action,
+						gboolean interaction,
+						GDBusPendingReply pending);
+
+enum GDBusFlags {
+	G_DBUS_FLAG_ENABLE_EXPERIMENTAL = (1 << 0),
+};
+
+enum GDBusMethodFlags {
+	G_DBUS_METHOD_FLAG_NONE         = 0,
+	G_DBUS_METHOD_FLAG_DEPRECATED   = (1 << 0),
+	G_DBUS_METHOD_FLAG_NOREPLY      = (1 << 1),
+	G_DBUS_METHOD_FLAG_ASYNC        = (1 << 2),
+	G_DBUS_METHOD_FLAG_EXPERIMENTAL = (1 << 3),
+};
+
+enum GDBusSignalFlags {
+	G_DBUS_SIGNAL_FLAG_DEPRECATED   = (1 << 0),
+	G_DBUS_SIGNAL_FLAG_EXPERIMENTAL = (1 << 1),
+};
+
+enum GDBusPropertyFlags {
+	G_DBUS_PROPERTY_FLAG_DEPRECATED   = (1 << 0),
+	G_DBUS_PROPERTY_FLAG_EXPERIMENTAL = (1 << 1),
+};
+
+enum GDBusSecurityFlags {
+	G_DBUS_SECURITY_FLAG_DEPRECATED        = (1 << 0),
+	G_DBUS_SECURITY_FLAG_BUILTIN           = (1 << 1),
+	G_DBUS_SECURITY_FLAG_ALLOW_INTERACTION = (1 << 2),
+};
+
+struct GDBusArgInfo {
+	const char *name;
+	const char *signature;
+};
+
+struct GDBusMethodTable {
+	const char *name;
+	GDBusMethodFunction function;
+	GDBusMethodFlags flags;
+	unsigned int privilege;
+	const GDBusArgInfo *in_args;
+	const GDBusArgInfo *out_args;
+};
+
+struct GDBusSignalTable {
+	const char *name;
+	GDBusSignalFlags flags;
+	const GDBusArgInfo *args;
+};
+
+struct GDBusPropertyTable {
+	const char *name;
+	const char *type;
+	GDBusPropertyGetter get;
+	GDBusPropertySetter set;
+	GDBusPropertyExists exists;
+	GDBusPropertyFlags flags;
+};
+
+struct GDBusSecurityTable {
+	unsigned int privilege;
+	const char *action;
+	GDBusSecurityFlags flags;
+	GDBusSecurityFunction function;
+};
+
+#define GDBUS_ARGS(args...) (const GDBusArgInfo[]) { args, { } }
+
+#define GDBUS_METHOD(_name, _in_args, _out_args, _function) \
+	.name = _name, \
+	.in_args = _in_args, \
+	.out_args = _out_args, \
+	.function = _function
+
+#define GDBUS_ASYNC_METHOD(_name, _in_args, _out_args, _function) \
+	.name = _name, \
+	.in_args = _in_args, \
+	.out_args = _out_args, \
+	.function = _function, \
+	.flags = G_DBUS_METHOD_FLAG_ASYNC
+
+#define GDBUS_DEPRECATED_METHOD(_name, _in_args, _out_args, _function) \
+	.name = _name, \
+	.in_args = _in_args, \
+	.out_args = _out_args, \
+	.function = _function, \
+	.flags = G_DBUS_METHOD_FLAG_DEPRECATED
+
+#define GDBUS_DEPRECATED_ASYNC_METHOD(_name, _in_args, _out_args, _function) \
+	.name = _name, \
+	.in_args = _in_args, \
+	.out_args = _out_args, \
+	.function = _function, \
+	.flags = G_DBUS_METHOD_FLAG_ASYNC | G_DBUS_METHOD_FLAG_DEPRECATED
+
+#define GDBUS_EXPERIMENTAL_METHOD(_name, _in_args, _out_args, _function) \
+	.name = _name, \
+	.in_args = _in_args, \
+	.out_args = _out_args, \
+	.function = _function, \
+	.flags = G_DBUS_METHOD_FLAG_EXPERIMENTAL
+
+#define GDBUS_EXPERIMENTAL_ASYNC_METHOD(_name, _in_args, _out_args, _function) \
+	.name = _name, \
+	.in_args = _in_args, \
+	.out_args = _out_args, \
+	.function = _function, \
+	.flags = G_DBUS_METHOD_FLAG_ASYNC | G_DBUS_METHOD_FLAG_EXPERIMENTAL
+
+#define GDBUS_NOREPLY_METHOD(_name, _in_args, _out_args, _function) \
+	.name = _name, \
+	.in_args = _in_args, \
+	.out_args = _out_args, \
+	.function = _function, \
+	.flags = G_DBUS_METHOD_FLAG_NOREPLY
+
+#define GDBUS_SIGNAL(_name, _args) \
+	.name = _name, \
+	.args = _args
+
+#define GDBUS_DEPRECATED_SIGNAL(_name, _args) \
+	.name = _name, \
+	.args = _args, \
+	.flags = G_DBUS_SIGNAL_FLAG_DEPRECATED
+
+#define GDBUS_EXPERIMENTAL_SIGNAL(_name, _args) \
+	.name = _name, \
+	.args = _args, \
+	.flags = G_DBUS_SIGNAL_FLAG_EXPERIMENTAL
+
+void g_dbus_set_flags(int flags);
+int g_dbus_get_flags(void);
+
+gboolean g_dbus_register_interface(DBusConnection *connection,
+					const char *path, const char *name,
+					const GDBusMethodTable *methods,
+					const GDBusSignalTable *signals,
+					const GDBusPropertyTable *properties,
+					void *user_data,
+					GDBusDestroyFunction destroy);
+gboolean g_dbus_unregister_interface(DBusConnection *connection,
+					const char *path, const char *name);
+
+gboolean g_dbus_register_security(const GDBusSecurityTable *security);
+gboolean g_dbus_unregister_security(const GDBusSecurityTable *security);
+
+void g_dbus_pending_success(DBusConnection *connection,
+					GDBusPendingReply pending);
+void g_dbus_pending_error(DBusConnection *connection,
+				GDBusPendingReply pending,
+				const char *name, const char *format, ...)
+					__attribute__((format(printf, 4, 5)));
+void g_dbus_pending_error_valist(DBusConnection *connection,
+				GDBusPendingReply pending, const char *name,
+					const char *format, va_list args);
+
+DBusMessage *g_dbus_create_error(DBusMessage *message, const char *name,
+						const char *format, ...)
+					__attribute__((format(printf, 3, 4)));
+DBusMessage *g_dbus_create_error_valist(DBusMessage *message, const char *name,
+					const char *format, va_list args);
+DBusMessage *g_dbus_create_reply(DBusMessage *message, int type, ...);
+DBusMessage *g_dbus_create_reply_valist(DBusMessage *message,
+						int type, va_list args);
+
+gboolean g_dbus_send_message(DBusConnection *connection, DBusMessage *message);
+gboolean g_dbus_send_message_with_reply(DBusConnection *connection,
+					DBusMessage *message,
+					DBusPendingCall **call, int timeout);
+gboolean g_dbus_send_error(DBusConnection *connection, DBusMessage *message,
+				const char *name, const char *format, ...)
+					 __attribute__((format(printf, 4, 5)));
+gboolean g_dbus_send_error_valist(DBusConnection *connection,
+					DBusMessage *message, const char *name,
+					const char *format, va_list args);
+gboolean g_dbus_send_reply(DBusConnection *connection,
+				DBusMessage *message, int type, ...);
+gboolean g_dbus_send_reply_valist(DBusConnection *connection,
+				DBusMessage *message, int type, va_list args);
+
+gboolean g_dbus_emit_signal(DBusConnection *connection,
+				const char *path, const char *interface,
+				const char *name, int type, ...);
+gboolean g_dbus_emit_signal_valist(DBusConnection *connection,
+				const char *path, const char *interface,
+				const char *name, int type, va_list args);
+
+guint g_dbus_add_service_watch(DBusConnection *connection, const char *name,
+				GDBusWatchFunction connect,
+				GDBusWatchFunction disconnect,
+				void *user_data, GDBusDestroyFunction destroy);
+guint g_dbus_add_disconnect_watch(DBusConnection *connection, const char *name,
+				GDBusWatchFunction function,
+				void *user_data, GDBusDestroyFunction destroy);
+guint g_dbus_add_signal_watch(DBusConnection *connection,
+				const char *sender, const char *path,
+				const char *interface, const char *member,
+				GDBusSignalFunction function, void *user_data,
+				GDBusDestroyFunction destroy);
+guint g_dbus_add_properties_watch(DBusConnection *connection,
+				const char *sender, const char *path,
+				const char *interface,
+				GDBusSignalFunction function, void *user_data,
+				GDBusDestroyFunction destroy);
+gboolean g_dbus_remove_watch(DBusConnection *connection, guint tag);
+void g_dbus_remove_all_watches(DBusConnection *connection);
+
+void g_dbus_pending_property_success(GDBusPendingPropertySet id);
+void g_dbus_pending_property_error_valist(GDBusPendingReply id,
+			const char *name, const char *format, va_list args);
+void g_dbus_pending_property_error(GDBusPendingReply id, const char *name,
+						const char *format, ...);
+void g_dbus_emit_property_changed(DBusConnection *connection,
+				const char *path, const char *interface,
+				const char *name);
+gboolean g_dbus_get_properties(DBusConnection *connection, const char *path,
+				const char *interface, DBusMessageIter *iter);
+
+gboolean g_dbus_attach_object_manager(DBusConnection *connection);
+gboolean g_dbus_detach_object_manager(DBusConnection *connection);
+
+typedef struct GDBusClient GDBusClient;
+typedef struct GDBusProxy GDBusProxy;
+
+GDBusProxy *g_dbus_proxy_new(GDBusClient *client, const char *path,
+							const char *interface);
+
+GDBusProxy *g_dbus_proxy_ref(GDBusProxy *proxy);
+void g_dbus_proxy_unref(GDBusProxy *proxy);
+
+const char *g_dbus_proxy_get_path(GDBusProxy *proxy);
+const char *g_dbus_proxy_get_interface(GDBusProxy *proxy);
+
+gboolean g_dbus_proxy_get_property(GDBusProxy *proxy, const char *name,
+							DBusMessageIter *iter);
+
+gboolean g_dbus_proxy_refresh_property(GDBusProxy *proxy, const char *name);
+
+typedef void (* GDBusResultFunction) (const DBusError *error, void *user_data);
+
+gboolean g_dbus_proxy_set_property_basic(GDBusProxy *proxy,
+				const char *name, int type, const void *value,
+				GDBusResultFunction function, void *user_data,
+				GDBusDestroyFunction destroy);
+
+gboolean g_dbus_proxy_set_property_array(GDBusProxy *proxy,
+				const char *name, int type, const void *value,
+				size_t size, GDBusResultFunction function,
+				void *user_data, GDBusDestroyFunction destroy);
+
+typedef void (* GDBusSetupFunction) (DBusMessageIter *iter, void *user_data);
+typedef void (* GDBusReturnFunction) (DBusMessage *message, void *user_data);
+
+gboolean g_dbus_proxy_method_call(GDBusProxy *proxy, const char *method,
+				GDBusSetupFunction setup,
+				GDBusReturnFunction function, void *user_data,
+				GDBusDestroyFunction destroy);
+
+typedef void (* GDBusClientFunction) (GDBusClient *client, void *user_data);
+typedef void (* GDBusProxyFunction) (GDBusProxy *proxy, void *user_data);
+typedef void (* GDBusPropertyFunction) (GDBusProxy *proxy, const char *name,
+					DBusMessageIter *iter, void *user_data);
+
+gboolean g_dbus_proxy_set_property_watch(GDBusProxy *proxy,
+			GDBusPropertyFunction function, void *user_data);
+
+gboolean g_dbus_proxy_set_removed_watch(GDBusProxy *proxy,
+			GDBusProxyFunction destroy, void *user_data);
+
+GDBusClient *g_dbus_client_new(DBusConnection *connection,
+					const char *service, const char *path);
+GDBusClient *g_dbus_client_new_full(DBusConnection *connection,
+							const char *service,
+							const char *path,
+							const char *root_path);
+
+GDBusClient *g_dbus_client_ref(GDBusClient *client);
+void g_dbus_client_unref(GDBusClient *client);
+
+gboolean g_dbus_client_set_connect_watch(GDBusClient *client,
+				GDBusWatchFunction function, void *user_data);
+gboolean g_dbus_client_set_disconnect_watch(GDBusClient *client,
+				GDBusWatchFunction function, void *user_data);
+gboolean g_dbus_client_set_signal_watch(GDBusClient *client,
+				GDBusMessageFunction function, void *user_data);
+gboolean g_dbus_client_set_ready_watch(GDBusClient *client,
+				GDBusClientFunction ready, void *user_data);
+gboolean g_dbus_client_set_proxy_handlers(GDBusClient *client,
+					GDBusProxyFunction proxy_added,
+					GDBusProxyFunction proxy_removed,
+					GDBusPropertyFunction property_changed,
+					void *user_data);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __GDBUS_H */
diff --git a/connman/gdbus/mainloop.c b/connman/gdbus/mainloop.c
new file mode 100644
index 0000000..b90a844
--- /dev/null
+++ b/connman/gdbus/mainloop.c
@@ -0,0 +1,378 @@
+/*
+ *
+ *  D-Bus helper library
+ *
+ *  Copyright (C) 2004-2011  Marcel Holtmann <marcel@holtmann.org>
+ *
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  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 <glib.h>
+#include <dbus/dbus.h>
+
+#include "gdbus.h"
+
+#define info(fmt...)
+#define error(fmt...)
+#define debug(fmt...)
+
+struct timeout_handler {
+	guint id;
+	DBusTimeout *timeout;
+};
+
+struct watch_info {
+	guint id;
+	DBusWatch *watch;
+	DBusConnection *conn;
+};
+
+struct disconnect_data {
+	GDBusWatchFunction function;
+	void *user_data;
+};
+
+static gboolean disconnected_signal(DBusConnection *conn,
+						DBusMessage *msg, void *data)
+{
+	struct disconnect_data *dc_data = data;
+
+	error("Got disconnected from the system message bus");
+
+	dc_data->function(conn, dc_data->user_data);
+
+	dbus_connection_unref(conn);
+
+	return TRUE;
+}
+
+static gboolean message_dispatch(void *data)
+{
+	DBusConnection *conn = data;
+
+	/* Dispatch messages */
+	while (dbus_connection_dispatch(conn) == DBUS_DISPATCH_DATA_REMAINS);
+
+	dbus_connection_unref(conn);
+
+	return FALSE;
+}
+
+static inline void queue_dispatch(DBusConnection *conn,
+						DBusDispatchStatus status)
+{
+	if (status == DBUS_DISPATCH_DATA_REMAINS)
+		g_idle_add(message_dispatch, dbus_connection_ref(conn));
+}
+
+static gboolean watch_func(GIOChannel *chan, GIOCondition cond, gpointer data)
+{
+	struct watch_info *info = data;
+	unsigned int flags = 0;
+	DBusDispatchStatus status;
+	DBusConnection *conn;
+
+	if (cond & G_IO_IN)  flags |= DBUS_WATCH_READABLE;
+	if (cond & G_IO_OUT) flags |= DBUS_WATCH_WRITABLE;
+	if (cond & G_IO_HUP) flags |= DBUS_WATCH_HANGUP;
+	if (cond & G_IO_ERR) flags |= DBUS_WATCH_ERROR;
+
+	/* Protect connection from being destroyed by dbus_watch_handle */
+	conn = dbus_connection_ref(info->conn);
+
+	dbus_watch_handle(info->watch, flags);
+
+	status = dbus_connection_get_dispatch_status(conn);
+	queue_dispatch(conn, status);
+
+	dbus_connection_unref(conn);
+
+	return TRUE;
+}
+
+static void watch_info_free(void *data)
+{
+	struct watch_info *info = data;
+
+	if (info->id > 0) {
+		g_source_remove(info->id);
+		info->id = 0;
+	}
+
+	dbus_connection_unref(info->conn);
+
+	g_free(info);
+}
+
+static dbus_bool_t add_watch(DBusWatch *watch, void *data)
+{
+	DBusConnection *conn = data;
+	GIOCondition cond = G_IO_HUP | G_IO_ERR;
+	GIOChannel *chan;
+	struct watch_info *info;
+	unsigned int flags;
+	int fd;
+
+	if (!dbus_watch_get_enabled(watch))
+		return TRUE;
+
+	info = g_new0(struct watch_info, 1);
+
+	fd = dbus_watch_get_unix_fd(watch);
+	chan = g_io_channel_unix_new(fd);
+
+	info->watch = watch;
+	info->conn = dbus_connection_ref(conn);
+
+	dbus_watch_set_data(watch, info, watch_info_free);
+
+	flags = dbus_watch_get_flags(watch);
+
+	if (flags & DBUS_WATCH_READABLE) cond |= G_IO_IN;
+	if (flags & DBUS_WATCH_WRITABLE) cond |= G_IO_OUT;
+
+	info->id = g_io_add_watch(chan, cond, watch_func, info);
+
+	g_io_channel_unref(chan);
+
+	return TRUE;
+}
+
+static void remove_watch(DBusWatch *watch, void *data)
+{
+	if (dbus_watch_get_enabled(watch))
+		return;
+
+	/* will trigger watch_info_free() */
+	dbus_watch_set_data(watch, NULL, NULL);
+}
+
+static void watch_toggled(DBusWatch *watch, void *data)
+{
+	/* Because we just exit on OOM, enable/disable is
+	 * no different from add/remove */
+	if (dbus_watch_get_enabled(watch))
+		add_watch(watch, data);
+	else
+		remove_watch(watch, data);
+}
+
+static gboolean timeout_handler_dispatch(gpointer data)
+{
+	struct timeout_handler *handler = data;
+
+	handler->id = 0;
+
+	/* if not enabled should not be polled by the main loop */
+	if (!dbus_timeout_get_enabled(handler->timeout))
+		return FALSE;
+
+	dbus_timeout_handle(handler->timeout);
+
+	return FALSE;
+}
+
+static void timeout_handler_free(void *data)
+{
+	struct timeout_handler *handler = data;
+
+	if (handler->id > 0) {
+		g_source_remove(handler->id);
+		handler->id = 0;
+	}
+
+	g_free(handler);
+}
+
+static dbus_bool_t add_timeout(DBusTimeout *timeout, void *data)
+{
+	int interval = dbus_timeout_get_interval(timeout);
+	struct timeout_handler *handler;
+
+	if (!dbus_timeout_get_enabled(timeout))
+		return TRUE;
+
+	handler = g_new0(struct timeout_handler, 1);
+
+	handler->timeout = timeout;
+
+	dbus_timeout_set_data(timeout, handler, timeout_handler_free);
+
+	handler->id = g_timeout_add(interval, timeout_handler_dispatch,
+								handler);
+
+	return TRUE;
+}
+
+static void remove_timeout(DBusTimeout *timeout, void *data)
+{
+	/* will trigger timeout_handler_free() */
+	dbus_timeout_set_data(timeout, NULL, NULL);
+}
+
+static void timeout_toggled(DBusTimeout *timeout, void *data)
+{
+	if (dbus_timeout_get_enabled(timeout))
+		add_timeout(timeout, data);
+	else
+		remove_timeout(timeout, data);
+}
+
+static void dispatch_status(DBusConnection *conn,
+					DBusDispatchStatus status, void *data)
+{
+	if (!dbus_connection_get_is_connected(conn))
+		return;
+
+	queue_dispatch(conn, status);
+}
+
+static inline void setup_dbus_with_main_loop(DBusConnection *conn)
+{
+	dbus_connection_set_watch_functions(conn, add_watch, remove_watch,
+						watch_toggled, conn, NULL);
+
+	dbus_connection_set_timeout_functions(conn, add_timeout, remove_timeout,
+						timeout_toggled, NULL, NULL);
+
+	dbus_connection_set_dispatch_status_function(conn, dispatch_status,
+								NULL, NULL);
+}
+
+static gboolean setup_bus(DBusConnection *conn, const char *name,
+						DBusError *error)
+{
+	gboolean result;
+	DBusDispatchStatus status;
+
+	if (name != NULL) {
+		result = g_dbus_request_name(conn, name, error);
+
+		if (error != NULL) {
+			if (dbus_error_is_set(error) == TRUE)
+				return FALSE;
+		}
+
+		if (result == FALSE)
+			return FALSE;
+	}
+
+	setup_dbus_with_main_loop(conn);
+
+	status = dbus_connection_get_dispatch_status(conn);
+	queue_dispatch(conn, status);
+
+	return TRUE;
+}
+
+DBusConnection *g_dbus_setup_bus(DBusBusType type, const char *name,
+							DBusError *error)
+{
+	DBusConnection *conn;
+
+	conn = dbus_bus_get(type, error);
+
+	if (error != NULL) {
+		if (dbus_error_is_set(error) == TRUE)
+			return NULL;
+	}
+
+	if (conn == NULL)
+		return NULL;
+
+	if (setup_bus(conn, name, error) == FALSE) {
+		dbus_connection_unref(conn);
+		return NULL;
+	}
+
+	return conn;
+}
+
+DBusConnection *g_dbus_setup_private(DBusBusType type, const char *name,
+							DBusError *error)
+{
+	DBusConnection *conn;
+
+	conn = dbus_bus_get_private(type, error);
+
+	if (error != NULL) {
+		if (dbus_error_is_set(error) == TRUE)
+			return NULL;
+	}
+
+	if (conn == NULL)
+		return NULL;
+
+	if (setup_bus(conn, name, error) == FALSE) {
+		dbus_connection_close(conn);
+		dbus_connection_unref(conn);
+		return NULL;
+	}
+
+	return conn;
+}
+
+gboolean g_dbus_request_name(DBusConnection *connection, const char *name,
+							DBusError *error)
+{
+	int result;
+
+	result = dbus_bus_request_name(connection, name,
+					DBUS_NAME_FLAG_DO_NOT_QUEUE, error);
+
+	if (error != NULL) {
+		if (dbus_error_is_set(error) == TRUE)
+			return FALSE;
+	}
+
+	if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
+		if (error != NULL)
+			dbus_set_error(error, name, "Name already in use");
+
+		return FALSE;
+	}
+
+	return TRUE;
+}
+
+gboolean g_dbus_set_disconnect_function(DBusConnection *connection,
+				GDBusWatchFunction function,
+				void *user_data, DBusFreeFunction destroy)
+{
+	struct disconnect_data *dc_data;
+
+	dc_data = g_new0(struct disconnect_data, 1);
+
+	dc_data->function = function;
+	dc_data->user_data = user_data;
+
+	dbus_connection_set_exit_on_disconnect(connection, FALSE);
+
+	if (g_dbus_add_signal_watch(connection, NULL, NULL,
+				DBUS_INTERFACE_LOCAL, "Disconnected",
+				disconnected_signal, dc_data, g_free) == 0) {
+		error("Failed to add watch for D-Bus Disconnected signal");
+		g_free(dc_data);
+		return FALSE;
+	}
+
+	return TRUE;
+}
diff --git a/connman/gdbus/object.c b/connman/gdbus/object.c
new file mode 100644
index 0000000..96db516
--- /dev/null
+++ b/connman/gdbus/object.c
@@ -0,0 +1,1823 @@
+/*
+ *
+ *  D-Bus helper library
+ *
+ *  Copyright (C) 2004-2011  Marcel Holtmann <marcel@holtmann.org>
+ *
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  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 <stdio.h>
+#include <string.h>
+
+#include <glib.h>
+#include <dbus/dbus.h>
+
+#include "gdbus.h"
+
+#define info(fmt...)
+#define error(fmt...)
+#define debug(fmt...)
+
+#define DBUS_INTERFACE_OBJECT_MANAGER "org.freedesktop.DBus.ObjectManager"
+
+#ifndef DBUS_ERROR_UNKNOWN_PROPERTY
+#define DBUS_ERROR_UNKNOWN_PROPERTY "org.freedesktop.DBus.Error.UnknownProperty"
+#endif
+
+#ifndef DBUS_ERROR_PROPERTY_READ_ONLY
+#define DBUS_ERROR_PROPERTY_READ_ONLY "org.freedesktop.DBus.Error.PropertyReadOnly"
+#endif
+
+struct generic_data {
+	unsigned int refcount;
+	DBusConnection *conn;
+	char *path;
+	GSList *interfaces;
+	GSList *objects;
+	GSList *added;
+	GSList *removed;
+	guint process_id;
+	gboolean pending_prop;
+	char *introspect;
+	struct generic_data *parent;
+};
+
+struct interface_data {
+	char *name;
+	const GDBusMethodTable *methods;
+	const GDBusSignalTable *signals;
+	const GDBusPropertyTable *properties;
+	GSList *pending_prop;
+	void *user_data;
+	GDBusDestroyFunction destroy;
+};
+
+struct security_data {
+	GDBusPendingReply pending;
+	DBusMessage *message;
+	const GDBusMethodTable *method;
+	void *iface_user_data;
+};
+
+struct property_data {
+	DBusConnection *conn;
+	GDBusPendingPropertySet id;
+	DBusMessage *message;
+};
+
+static int global_flags = 0;
+static struct generic_data *root;
+static GSList *pending = NULL;
+
+static gboolean process_changes(gpointer user_data);
+static void process_properties_from_interface(struct generic_data *data,
+						struct interface_data *iface);
+static void process_property_changes(struct generic_data *data);
+
+static void print_arguments(GString *gstr, const GDBusArgInfo *args,
+						const char *direction)
+{
+	for (; args && args->name; args++) {
+		g_string_append_printf(gstr,
+					"<arg name=\"%s\" type=\"%s\"",
+					args->name, args->signature);
+
+		if (direction)
+			g_string_append_printf(gstr,
+					" direction=\"%s\"/>\n", direction);
+		else
+			g_string_append_printf(gstr, "/>\n");
+
+	}
+}
+
+#define G_DBUS_ANNOTATE(name_, value_)				\
+	"<annotation name=\"org.freedesktop.DBus." name_ "\" "	\
+	"value=\"" value_ "\"/>"
+
+#define G_DBUS_ANNOTATE_DEPRECATED \
+	G_DBUS_ANNOTATE("Deprecated", "true")
+
+#define G_DBUS_ANNOTATE_NOREPLY \
+	G_DBUS_ANNOTATE("Method.NoReply", "true")
+
+static gboolean check_experimental(int flags, int flag)
+{
+	if (!(flags & flag))
+		return FALSE;
+
+	return !(global_flags & G_DBUS_FLAG_ENABLE_EXPERIMENTAL);
+}
+
+static void generate_interface_xml(GString *gstr, struct interface_data *iface)
+{
+	const GDBusMethodTable *method;
+	const GDBusSignalTable *signal;
+	const GDBusPropertyTable *property;
+
+	for (method = iface->methods; method && method->name; method++) {
+		if (check_experimental(method->flags,
+					G_DBUS_METHOD_FLAG_EXPERIMENTAL))
+			continue;
+
+		g_string_append_printf(gstr, "<method name=\"%s\">",
+								method->name);
+		print_arguments(gstr, method->in_args, "in");
+		print_arguments(gstr, method->out_args, "out");
+
+		if (method->flags & G_DBUS_METHOD_FLAG_DEPRECATED)
+			g_string_append_printf(gstr,
+						G_DBUS_ANNOTATE_DEPRECATED);
+
+		if (method->flags & G_DBUS_METHOD_FLAG_NOREPLY)
+			g_string_append_printf(gstr, G_DBUS_ANNOTATE_NOREPLY);
+
+		g_string_append_printf(gstr, "</method>");
+	}
+
+	for (signal = iface->signals; signal && signal->name; signal++) {
+		if (check_experimental(signal->flags,
+					G_DBUS_SIGNAL_FLAG_EXPERIMENTAL))
+			continue;
+
+		g_string_append_printf(gstr, "<signal name=\"%s\">",
+								signal->name);
+		print_arguments(gstr, signal->args, NULL);
+
+		if (signal->flags & G_DBUS_SIGNAL_FLAG_DEPRECATED)
+			g_string_append_printf(gstr,
+						G_DBUS_ANNOTATE_DEPRECATED);
+
+		g_string_append_printf(gstr, "</signal>\n");
+	}
+
+	for (property = iface->properties; property && property->name;
+								property++) {
+		if (check_experimental(property->flags,
+					G_DBUS_PROPERTY_FLAG_EXPERIMENTAL))
+			continue;
+
+		g_string_append_printf(gstr, "<property name=\"%s\""
+					" type=\"%s\" access=\"%s%s\">",
+					property->name,	property->type,
+					property->get ? "read" : "",
+					property->set ? "write" : "");
+
+		if (property->flags & G_DBUS_PROPERTY_FLAG_DEPRECATED)
+			g_string_append_printf(gstr,
+						G_DBUS_ANNOTATE_DEPRECATED);
+
+		g_string_append_printf(gstr, "</property>");
+	}
+}
+
+static void generate_introspection_xml(DBusConnection *conn,
+				struct generic_data *data, const char *path)
+{
+	GSList *list;
+	GString *gstr;
+	char **children;
+	int i;
+
+	g_free(data->introspect);
+
+	gstr = g_string_new(DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE);
+
+	g_string_append_printf(gstr, "<node>");
+
+	for (list = data->interfaces; list; list = list->next) {
+		struct interface_data *iface = list->data;
+
+		g_string_append_printf(gstr, "<interface name=\"%s\">",
+								iface->name);
+
+		generate_interface_xml(gstr, iface);
+
+		g_string_append_printf(gstr, "</interface>");
+	}
+
+	if (!dbus_connection_list_registered(conn, path, &children))
+		goto done;
+
+	for (i = 0; children[i]; i++)
+		g_string_append_printf(gstr, "<node name=\"%s\"/>",
+								children[i]);
+
+	dbus_free_string_array(children);
+
+done:
+	g_string_append_printf(gstr, "</node>");
+
+	data->introspect = g_string_free(gstr, FALSE);
+}
+
+static DBusMessage *introspect(DBusConnection *connection,
+				DBusMessage *message, void *user_data)
+{
+	struct generic_data *data = user_data;
+	DBusMessage *reply;
+
+	if (data->introspect == NULL)
+		generate_introspection_xml(connection, data,
+						dbus_message_get_path(message));
+
+	reply = dbus_message_new_method_return(message);
+	if (reply == NULL)
+		return NULL;
+
+	dbus_message_append_args(reply, DBUS_TYPE_STRING, &data->introspect,
+					DBUS_TYPE_INVALID);
+
+	return reply;
+}
+
+static DBusHandlerResult process_message(DBusConnection *connection,
+			DBusMessage *message, const GDBusMethodTable *method,
+							void *iface_user_data)
+{
+	DBusMessage *reply;
+
+	reply = method->function(connection, message, iface_user_data);
+
+	if (method->flags & G_DBUS_METHOD_FLAG_NOREPLY) {
+		if (reply != NULL)
+			dbus_message_unref(reply);
+		return DBUS_HANDLER_RESULT_HANDLED;
+	}
+
+	if (method->flags & G_DBUS_METHOD_FLAG_ASYNC) {
+		if (reply == NULL)
+			return DBUS_HANDLER_RESULT_HANDLED;
+	}
+
+	if (reply == NULL)
+		return DBUS_HANDLER_RESULT_NEED_MEMORY;
+
+	g_dbus_send_message(connection, reply);
+
+	return DBUS_HANDLER_RESULT_HANDLED;
+}
+
+static GDBusPendingReply next_pending = 1;
+static GSList *pending_security = NULL;
+
+static const GDBusSecurityTable *security_table = NULL;
+
+void g_dbus_pending_success(DBusConnection *connection,
+					GDBusPendingReply pending)
+{
+	GSList *list;
+
+	for (list = pending_security; list; list = list->next) {
+		struct security_data *secdata = list->data;
+
+		if (secdata->pending != pending)
+			continue;
+
+		pending_security = g_slist_remove(pending_security, secdata);
+
+		process_message(connection, secdata->message,
+				secdata->method, secdata->iface_user_data);
+
+		dbus_message_unref(secdata->message);
+		g_free(secdata);
+		return;
+	}
+}
+
+void g_dbus_pending_error_valist(DBusConnection *connection,
+				GDBusPendingReply pending, const char *name,
+					const char *format, va_list args)
+{
+	GSList *list;
+
+	for (list = pending_security; list; list = list->next) {
+		struct security_data *secdata = list->data;
+
+		if (secdata->pending != pending)
+			continue;
+
+		pending_security = g_slist_remove(pending_security, secdata);
+
+		g_dbus_send_error_valist(connection, secdata->message,
+							name, format, args);
+
+		dbus_message_unref(secdata->message);
+		g_free(secdata);
+		return;
+	}
+}
+
+void g_dbus_pending_error(DBusConnection *connection,
+				GDBusPendingReply pending,
+				const char *name, const char *format, ...)
+{
+	va_list args;
+
+	va_start(args, format);
+
+	g_dbus_pending_error_valist(connection, pending, name, format, args);
+
+	va_end(args);
+}
+
+int polkit_check_authorization(DBusConnection *conn,
+				const char *action, gboolean interaction,
+				void (*function) (dbus_bool_t authorized,
+							void *user_data),
+						void *user_data, int timeout);
+
+struct builtin_security_data {
+	DBusConnection *conn;
+	GDBusPendingReply pending;
+};
+
+static void builtin_security_result(dbus_bool_t authorized, void *user_data)
+{
+	struct builtin_security_data *data = user_data;
+
+	if (authorized == TRUE)
+		g_dbus_pending_success(data->conn, data->pending);
+	else
+		g_dbus_pending_error(data->conn, data->pending,
+						DBUS_ERROR_AUTH_FAILED, NULL);
+
+	g_free(data);
+}
+
+static void builtin_security_function(DBusConnection *conn,
+						const char *action,
+						gboolean interaction,
+						GDBusPendingReply pending)
+{
+	struct builtin_security_data *data;
+
+	data = g_new0(struct builtin_security_data, 1);
+	data->conn = conn;
+	data->pending = pending;
+
+	if (polkit_check_authorization(conn, action, interaction,
+				builtin_security_result, data, 30000) < 0)
+		g_dbus_pending_error(conn, pending, NULL, NULL);
+}
+
+static gboolean check_privilege(DBusConnection *conn, DBusMessage *msg,
+			const GDBusMethodTable *method, void *iface_user_data)
+{
+	const GDBusSecurityTable *security;
+
+	for (security = security_table; security && security->privilege;
+								security++) {
+		struct security_data *secdata;
+		gboolean interaction;
+
+		if (security->privilege != method->privilege)
+			continue;
+
+		secdata = g_new(struct security_data, 1);
+		secdata->pending = next_pending++;
+		secdata->message = dbus_message_ref(msg);
+		secdata->method = method;
+		secdata->iface_user_data = iface_user_data;
+
+		pending_security = g_slist_prepend(pending_security, secdata);
+
+		if (security->flags & G_DBUS_SECURITY_FLAG_ALLOW_INTERACTION)
+			interaction = TRUE;
+		else
+			interaction = FALSE;
+
+		if (!(security->flags & G_DBUS_SECURITY_FLAG_BUILTIN) &&
+							security->function)
+			security->function(conn, security->action,
+						interaction, secdata->pending);
+		else
+			builtin_security_function(conn, security->action,
+						interaction, secdata->pending);
+
+		return TRUE;
+	}
+
+	return FALSE;
+}
+
+static GDBusPendingPropertySet next_pending_property = 1;
+static GSList *pending_property_set;
+
+static struct property_data *remove_pending_property_data(
+						GDBusPendingPropertySet id)
+{
+	struct property_data *propdata;
+	GSList *l;
+
+	for (l = pending_property_set; l != NULL; l = l->next) {
+		propdata = l->data;
+		if (propdata->id != id)
+			continue;
+
+		break;
+	}
+
+	if (l == NULL)
+		return NULL;
+
+	pending_property_set = g_slist_delete_link(pending_property_set, l);
+
+	return propdata;
+}
+
+void g_dbus_pending_property_success(GDBusPendingPropertySet id)
+{
+	struct property_data *propdata;
+
+	propdata = remove_pending_property_data(id);
+	if (propdata == NULL)
+		return;
+
+	g_dbus_send_reply(propdata->conn, propdata->message,
+							DBUS_TYPE_INVALID);
+	dbus_message_unref(propdata->message);
+	g_free(propdata);
+}
+
+void g_dbus_pending_property_error_valist(GDBusPendingReply id,
+					const char *name, const char *format,
+					va_list args)
+{
+	struct property_data *propdata;
+
+	propdata = remove_pending_property_data(id);
+	if (propdata == NULL)
+		return;
+
+	g_dbus_send_error_valist(propdata->conn, propdata->message, name,
+								format, args);
+
+	dbus_message_unref(propdata->message);
+	g_free(propdata);
+}
+
+void g_dbus_pending_property_error(GDBusPendingReply id, const char *name,
+						const char *format, ...)
+{
+	va_list args;
+
+	va_start(args, format);
+
+	g_dbus_pending_property_error_valist(id, name, format, args);
+
+	va_end(args);
+}
+
+static void reset_parent(gpointer data, gpointer user_data)
+{
+	struct generic_data *child = data;
+	struct generic_data *parent = user_data;
+
+	child->parent = parent;
+}
+
+static void append_property(struct interface_data *iface,
+			const GDBusPropertyTable *p, DBusMessageIter *dict)
+{
+	DBusMessageIter entry, value;
+
+	dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY, NULL,
+								&entry);
+	dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &p->name);
+	dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT, p->type,
+								&value);
+
+	p->get(p, &value, iface->user_data);
+
+	dbus_message_iter_close_container(&entry, &value);
+	dbus_message_iter_close_container(dict, &entry);
+}
+
+static void append_properties(struct interface_data *data,
+							DBusMessageIter *iter)
+{
+	DBusMessageIter dict;
+	const GDBusPropertyTable *p;
+
+	dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY,
+				DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+				DBUS_TYPE_STRING_AS_STRING
+				DBUS_TYPE_VARIANT_AS_STRING
+				DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict);
+
+	for (p = data->properties; p && p->name; p++) {
+		if (check_experimental(p->flags,
+					G_DBUS_PROPERTY_FLAG_EXPERIMENTAL))
+			continue;
+
+		if (p->get == NULL)
+			continue;
+
+		if (p->exists != NULL && !p->exists(p, data->user_data))
+			continue;
+
+		append_property(data, p, &dict);
+	}
+
+	dbus_message_iter_close_container(iter, &dict);
+}
+
+static void append_interface(gpointer data, gpointer user_data)
+{
+	struct interface_data *iface = data;
+	DBusMessageIter *array = user_data;
+	DBusMessageIter entry;
+
+	dbus_message_iter_open_container(array, DBUS_TYPE_DICT_ENTRY, NULL,
+								&entry);
+	dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &iface->name);
+	append_properties(data, &entry);
+	dbus_message_iter_close_container(array, &entry);
+}
+
+static void emit_interfaces_added(struct generic_data *data)
+{
+	DBusMessage *signal;
+	DBusMessageIter iter, array;
+
+	if (root == NULL || data == root)
+		return;
+
+	signal = dbus_message_new_signal(root->path,
+					DBUS_INTERFACE_OBJECT_MANAGER,
+					"InterfacesAdded");
+	if (signal == NULL)
+		return;
+
+	dbus_message_iter_init_append(signal, &iter);
+	dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
+								&data->path);
+
+	dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
+				DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+				DBUS_TYPE_STRING_AS_STRING
+				DBUS_TYPE_ARRAY_AS_STRING
+				DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+				DBUS_TYPE_STRING_AS_STRING
+				DBUS_TYPE_VARIANT_AS_STRING
+				DBUS_DICT_ENTRY_END_CHAR_AS_STRING
+				DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &array);
+
+	g_slist_foreach(data->added, append_interface, &array);
+	g_slist_free(data->added);
+	data->added = NULL;
+
+	dbus_message_iter_close_container(&iter, &array);
+
+	/* Use dbus_connection_send to avoid recursive calls to g_dbus_flush */
+	dbus_connection_send(data->conn, signal, NULL);
+	dbus_message_unref(signal);
+}
+
+static struct interface_data *find_interface(GSList *interfaces,
+						const char *name)
+{
+	GSList *list;
+
+	if (name == NULL)
+		return NULL;
+
+	for (list = interfaces; list; list = list->next) {
+		struct interface_data *iface = list->data;
+		if (!strcmp(name, iface->name))
+			return iface;
+	}
+
+	return NULL;
+}
+
+static gboolean g_dbus_args_have_signature(const GDBusArgInfo *args,
+							DBusMessage *message)
+{
+	const char *sig = dbus_message_get_signature(message);
+	const char *p = NULL;
+
+	for (; args && args->signature && *sig; args++) {
+		p = args->signature;
+
+		for (; *sig && *p; sig++, p++) {
+			if (*p != *sig)
+				return FALSE;
+		}
+	}
+
+	if (*sig || (p && *p) || (args && args->signature))
+		return FALSE;
+
+	return TRUE;
+}
+
+static void add_pending(struct generic_data *data)
+{
+	if (data->process_id > 0)
+		return;
+
+	data->process_id = g_idle_add(process_changes, data);
+
+	pending = g_slist_append(pending, data);
+}
+
+static gboolean remove_interface(struct generic_data *data, const char *name)
+{
+	struct interface_data *iface;
+
+	iface = find_interface(data->interfaces, name);
+	if (iface == NULL)
+		return FALSE;
+
+	process_properties_from_interface(data, iface);
+
+	data->interfaces = g_slist_remove(data->interfaces, iface);
+
+	if (iface->destroy) {
+		iface->destroy(iface->user_data);
+		iface->user_data = NULL;
+	}
+
+	/*
+	 * Interface being removed was just added, on the same mainloop
+	 * iteration? Don't send any signal
+	 */
+	if (g_slist_find(data->added, iface)) {
+		data->added = g_slist_remove(data->added, iface);
+		g_free(iface->name);
+		g_free(iface);
+		return TRUE;
+	}
+
+	if (data->parent == NULL) {
+		g_free(iface->name);
+		g_free(iface);
+		return TRUE;
+	}
+
+	data->removed = g_slist_prepend(data->removed, iface->name);
+	g_free(iface);
+
+	add_pending(data);
+
+	return TRUE;
+}
+
+static struct generic_data *invalidate_parent_data(DBusConnection *conn,
+						const char *child_path)
+{
+	struct generic_data *data = NULL, *child = NULL, *parent = NULL;
+	char *parent_path, *slash;
+
+	parent_path = g_strdup(child_path);
+	slash = strrchr(parent_path, '/');
+	if (slash == NULL)
+		goto done;
+
+	if (slash == parent_path && parent_path[1] != '\0')
+		parent_path[1] = '\0';
+	else
+		*slash = '\0';
+
+	if (!strlen(parent_path))
+		goto done;
+
+	if (dbus_connection_get_object_path_data(conn, parent_path,
+							(void *) &data) == FALSE) {
+		goto done;
+	}
+
+	parent = invalidate_parent_data(conn, parent_path);
+
+	if (data == NULL) {
+		data = parent;
+		if (data == NULL)
+			goto done;
+	}
+
+	g_free(data->introspect);
+	data->introspect = NULL;
+
+	if (!dbus_connection_get_object_path_data(conn, child_path,
+							(void *) &child))
+		goto done;
+
+	if (child == NULL || g_slist_find(data->objects, child) != NULL)
+		goto done;
+
+	data->objects = g_slist_prepend(data->objects, child);
+	child->parent = data;
+
+done:
+	g_free(parent_path);
+	return data;
+}
+
+static inline const GDBusPropertyTable *find_property(const GDBusPropertyTable *properties,
+							const char *name)
+{
+	const GDBusPropertyTable *p;
+
+	for (p = properties; p && p->name; p++) {
+		if (strcmp(name, p->name) != 0)
+			continue;
+
+		if (check_experimental(p->flags,
+					G_DBUS_PROPERTY_FLAG_EXPERIMENTAL))
+			break;
+
+		return p;
+	}
+
+	return NULL;
+}
+
+static DBusMessage *properties_get(DBusConnection *connection,
+					DBusMessage *message, void *user_data)
+{
+	struct generic_data *data = user_data;
+	struct interface_data *iface;
+	const GDBusPropertyTable *property;
+	const char *interface, *name;
+	DBusMessageIter iter, value;
+	DBusMessage *reply;
+
+	if (!dbus_message_get_args(message, NULL,
+					DBUS_TYPE_STRING, &interface,
+					DBUS_TYPE_STRING, &name,
+					DBUS_TYPE_INVALID))
+		return NULL;
+
+	iface = find_interface(data->interfaces, interface);
+	if (iface == NULL)
+		return g_dbus_create_error(message, DBUS_ERROR_INVALID_ARGS,
+				"No such interface '%s'", interface);
+
+	property = find_property(iface->properties, name);
+	if (property == NULL)
+		return g_dbus_create_error(message, DBUS_ERROR_INVALID_ARGS,
+				"No such property '%s'", name);
+
+	if (property->exists != NULL &&
+			!property->exists(property, iface->user_data))
+		return g_dbus_create_error(message, DBUS_ERROR_INVALID_ARGS,
+					"No such property '%s'", name);
+
+	if (property->get == NULL)
+		return g_dbus_create_error(message, DBUS_ERROR_INVALID_ARGS,
+				"Property '%s' is not readable", name);
+
+	reply = dbus_message_new_method_return(message);
+	if (reply == NULL)
+		return NULL;
+
+	dbus_message_iter_init_append(reply, &iter);
+	dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT,
+						property->type, &value);
+
+	if (!property->get(property, &value, iface->user_data)) {
+		dbus_message_unref(reply);
+		return NULL;
+	}
+
+	dbus_message_iter_close_container(&iter, &value);
+
+	return reply;
+}
+
+static DBusMessage *properties_get_all(DBusConnection *connection,
+					DBusMessage *message, void *user_data)
+{
+	struct generic_data *data = user_data;
+	struct interface_data *iface;
+	const char *interface;
+	DBusMessageIter iter;
+	DBusMessage *reply;
+
+	if (!dbus_message_get_args(message, NULL,
+					DBUS_TYPE_STRING, &interface,
+					DBUS_TYPE_INVALID))
+		return NULL;
+
+	iface = find_interface(data->interfaces, interface);
+	if (iface == NULL)
+		return g_dbus_create_error(message, DBUS_ERROR_INVALID_ARGS,
+					"No such interface '%s'", interface);
+
+	reply = dbus_message_new_method_return(message);
+	if (reply == NULL)
+		return NULL;
+
+	dbus_message_iter_init_append(reply, &iter);
+
+	append_properties(iface, &iter);
+
+	return reply;
+}
+
+static DBusMessage *properties_set(DBusConnection *connection,
+					DBusMessage *message, void *user_data)
+{
+	struct generic_data *data = user_data;
+	DBusMessageIter iter, sub;
+	struct interface_data *iface;
+	const GDBusPropertyTable *property;
+	const char *name, *interface;
+	struct property_data *propdata;
+	gboolean valid_signature;
+	char *signature;
+
+	if (!dbus_message_iter_init(message, &iter))
+		return g_dbus_create_error(message, DBUS_ERROR_INVALID_ARGS,
+							"No arguments given");
+
+	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
+		return g_dbus_create_error(message, DBUS_ERROR_INVALID_ARGS,
+					"Invalid argument type: '%c'",
+					dbus_message_iter_get_arg_type(&iter));
+
+	dbus_message_iter_get_basic(&iter, &interface);
+	dbus_message_iter_next(&iter);
+
+	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
+		return g_dbus_create_error(message, DBUS_ERROR_INVALID_ARGS,
+					"Invalid argument type: '%c'",
+					dbus_message_iter_get_arg_type(&iter));
+
+	dbus_message_iter_get_basic(&iter, &name);
+	dbus_message_iter_next(&iter);
+
+	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT)
+		return g_dbus_create_error(message, DBUS_ERROR_INVALID_ARGS,
+					"Invalid argument type: '%c'",
+					dbus_message_iter_get_arg_type(&iter));
+
+	dbus_message_iter_recurse(&iter, &sub);
+
+	iface = find_interface(data->interfaces, interface);
+	if (iface == NULL)
+		return g_dbus_create_error(message, DBUS_ERROR_INVALID_ARGS,
+					"No such interface '%s'", interface);
+
+	property = find_property(iface->properties, name);
+	if (property == NULL)
+		return g_dbus_create_error(message,
+						DBUS_ERROR_UNKNOWN_PROPERTY,
+						"No such property '%s'", name);
+
+	if (property->set == NULL)
+		return g_dbus_create_error(message,
+					DBUS_ERROR_PROPERTY_READ_ONLY,
+					"Property '%s' is not writable", name);
+
+	if (property->exists != NULL &&
+			!property->exists(property, iface->user_data))
+		return g_dbus_create_error(message,
+						DBUS_ERROR_UNKNOWN_PROPERTY,
+						"No such property '%s'", name);
+
+	signature = dbus_message_iter_get_signature(&sub);
+	valid_signature = strcmp(signature, property->type) ? FALSE : TRUE;
+	dbus_free(signature);
+	if (!valid_signature)
+		return g_dbus_create_error(message,
+					DBUS_ERROR_INVALID_SIGNATURE,
+					"Invalid signature for '%s'", name);
+
+	propdata = g_new(struct property_data, 1);
+	propdata->id = next_pending_property++;
+	propdata->message = dbus_message_ref(message);
+	propdata->conn = connection;
+	pending_property_set = g_slist_prepend(pending_property_set, propdata);
+
+	property->set(property, &sub, propdata->id, iface->user_data);
+
+	return NULL;
+}
+
+static const GDBusMethodTable properties_methods[] = {
+	{ GDBUS_METHOD("Get",
+			GDBUS_ARGS({ "interface", "s" }, { "name", "s" }),
+			GDBUS_ARGS({ "value", "v" }),
+			properties_get) },
+	{ GDBUS_ASYNC_METHOD("Set",
+			GDBUS_ARGS({ "interface", "s" }, { "name", "s" },
+							{ "value", "v" }),
+			NULL,
+			properties_set) },
+	{ GDBUS_METHOD("GetAll",
+			GDBUS_ARGS({ "interface", "s" }),
+			GDBUS_ARGS({ "properties", "a{sv}" }),
+			properties_get_all) },
+	{ }
+};
+
+static const GDBusSignalTable properties_signals[] = {
+	{ GDBUS_SIGNAL("PropertiesChanged",
+			GDBUS_ARGS({ "interface", "s" },
+					{ "changed_properties", "a{sv}" },
+					{ "invalidated_properties", "as"})) },
+	{ }
+};
+
+static void append_name(gpointer data, gpointer user_data)
+{
+	char *name = data;
+	DBusMessageIter *iter = user_data;
+
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &name);
+}
+
+static void emit_interfaces_removed(struct generic_data *data)
+{
+	DBusMessage *signal;
+	DBusMessageIter iter, array;
+
+	if (root == NULL || data == root)
+		return;
+
+	signal = dbus_message_new_signal(root->path,
+					DBUS_INTERFACE_OBJECT_MANAGER,
+					"InterfacesRemoved");
+	if (signal == NULL)
+		return;
+
+	dbus_message_iter_init_append(signal, &iter);
+	dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
+								&data->path);
+	dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
+					DBUS_TYPE_STRING_AS_STRING, &array);
+
+	g_slist_foreach(data->removed, append_name, &array);
+	g_slist_free_full(data->removed, g_free);
+	data->removed = NULL;
+
+	dbus_message_iter_close_container(&iter, &array);
+
+	/* Use dbus_connection_send to avoid recursive calls to g_dbus_flush */
+	dbus_connection_send(data->conn, signal, NULL);
+	dbus_message_unref(signal);
+}
+
+static void remove_pending(struct generic_data *data)
+{
+	if (data->process_id > 0) {
+		g_source_remove(data->process_id);
+		data->process_id = 0;
+	}
+
+	pending = g_slist_remove(pending, data);
+}
+
+static gboolean process_changes(gpointer user_data)
+{
+	struct generic_data *data = user_data;
+
+	remove_pending(data);
+
+	if (data->added != NULL)
+		emit_interfaces_added(data);
+
+	/* Flush pending properties */
+	if (data->pending_prop == TRUE)
+		process_property_changes(data);
+
+	if (data->removed != NULL)
+		emit_interfaces_removed(data);
+
+	data->process_id = 0;
+
+	return FALSE;
+}
+
+static void generic_unregister(DBusConnection *connection, void *user_data)
+{
+	struct generic_data *data = user_data;
+	struct generic_data *parent = data->parent;
+
+	if (parent != NULL)
+		parent->objects = g_slist_remove(parent->objects, data);
+
+	if (data->process_id > 0) {
+		g_source_remove(data->process_id);
+		data->process_id = 0;
+		process_changes(data);
+	}
+
+	g_slist_foreach(data->objects, reset_parent, data->parent);
+	g_slist_free(data->objects);
+
+	dbus_connection_unref(data->conn);
+	g_free(data->introspect);
+	g_free(data->path);
+	g_free(data);
+}
+
+static DBusHandlerResult generic_message(DBusConnection *connection,
+					DBusMessage *message, void *user_data)
+{
+	struct generic_data *data = user_data;
+	struct interface_data *iface;
+	const GDBusMethodTable *method;
+	const char *interface;
+
+	interface = dbus_message_get_interface(message);
+
+	iface = find_interface(data->interfaces, interface);
+	if (iface == NULL)
+		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+	for (method = iface->methods; method &&
+			method->name && method->function; method++) {
+
+		if (dbus_message_is_method_call(message, iface->name,
+							method->name) == FALSE)
+			continue;
+
+		if (check_experimental(method->flags,
+					G_DBUS_METHOD_FLAG_EXPERIMENTAL))
+			return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+		if (g_dbus_args_have_signature(method->in_args,
+							message) == FALSE)
+			continue;
+
+		if (check_privilege(connection, message, method,
+						iface->user_data) == TRUE)
+			return DBUS_HANDLER_RESULT_HANDLED;
+
+		return process_message(connection, message, method,
+							iface->user_data);
+	}
+
+	return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+
+static DBusObjectPathVTable generic_table = {
+	.unregister_function	= generic_unregister,
+	.message_function	= generic_message,
+};
+
+static const GDBusMethodTable introspect_methods[] = {
+	{ GDBUS_METHOD("Introspect", NULL,
+			GDBUS_ARGS({ "xml", "s" }), introspect) },
+	{ }
+};
+
+static void append_interfaces(struct generic_data *data, DBusMessageIter *iter)
+{
+	DBusMessageIter array;
+
+	dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY,
+				DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+				DBUS_TYPE_STRING_AS_STRING
+				DBUS_TYPE_ARRAY_AS_STRING
+				DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+				DBUS_TYPE_STRING_AS_STRING
+				DBUS_TYPE_VARIANT_AS_STRING
+				DBUS_DICT_ENTRY_END_CHAR_AS_STRING
+				DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &array);
+
+	g_slist_foreach(data->interfaces, append_interface, &array);
+
+	dbus_message_iter_close_container(iter, &array);
+}
+
+static void append_object(gpointer data, gpointer user_data)
+{
+	struct generic_data *child = data;
+	DBusMessageIter *array = user_data;
+	DBusMessageIter entry;
+
+	dbus_message_iter_open_container(array, DBUS_TYPE_DICT_ENTRY, NULL,
+								&entry);
+	dbus_message_iter_append_basic(&entry, DBUS_TYPE_OBJECT_PATH,
+								&child->path);
+	append_interfaces(child, &entry);
+	dbus_message_iter_close_container(array, &entry);
+
+	g_slist_foreach(child->objects, append_object, user_data);
+}
+
+static DBusMessage *get_objects(DBusConnection *connection,
+				DBusMessage *message, void *user_data)
+{
+	struct generic_data *data = user_data;
+	DBusMessage *reply;
+	DBusMessageIter iter;
+	DBusMessageIter array;
+
+	reply = dbus_message_new_method_return(message);
+	if (reply == NULL)
+		return NULL;
+
+	dbus_message_iter_init_append(reply, &iter);
+
+	dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
+					DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+					DBUS_TYPE_OBJECT_PATH_AS_STRING
+					DBUS_TYPE_ARRAY_AS_STRING
+					DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+					DBUS_TYPE_STRING_AS_STRING
+					DBUS_TYPE_ARRAY_AS_STRING
+					DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+					DBUS_TYPE_STRING_AS_STRING
+					DBUS_TYPE_VARIANT_AS_STRING
+					DBUS_DICT_ENTRY_END_CHAR_AS_STRING
+					DBUS_DICT_ENTRY_END_CHAR_AS_STRING
+					DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
+					&array);
+
+	g_slist_foreach(data->objects, append_object, &array);
+
+	dbus_message_iter_close_container(&iter, &array);
+
+	return reply;
+}
+
+static const GDBusMethodTable manager_methods[] = {
+	{ GDBUS_METHOD("GetManagedObjects", NULL,
+		GDBUS_ARGS({ "objects", "a{oa{sa{sv}}}" }), get_objects) },
+	{ }
+};
+
+static const GDBusSignalTable manager_signals[] = {
+	{ GDBUS_SIGNAL("InterfacesAdded",
+		GDBUS_ARGS({ "object", "o" },
+				{ "interfaces", "a{sa{sv}}" })) },
+	{ GDBUS_SIGNAL("InterfacesRemoved",
+		GDBUS_ARGS({ "object", "o" }, { "interfaces", "as" })) },
+	{ }
+};
+
+static gboolean add_interface(struct generic_data *data,
+				const char *name,
+				const GDBusMethodTable *methods,
+				const GDBusSignalTable *signals,
+				const GDBusPropertyTable *properties,
+				void *user_data,
+				GDBusDestroyFunction destroy)
+{
+	struct interface_data *iface;
+	const GDBusMethodTable *method;
+	const GDBusSignalTable *signal;
+	const GDBusPropertyTable *property;
+
+	for (method = methods; method && method->name; method++) {
+		if (!check_experimental(method->flags,
+					G_DBUS_METHOD_FLAG_EXPERIMENTAL))
+			goto done;
+	}
+
+	for (signal = signals; signal && signal->name; signal++) {
+		if (!check_experimental(signal->flags,
+					G_DBUS_SIGNAL_FLAG_EXPERIMENTAL))
+			goto done;
+	}
+
+	for (property = properties; property && property->name; property++) {
+		if (!check_experimental(property->flags,
+					G_DBUS_PROPERTY_FLAG_EXPERIMENTAL))
+			goto done;
+	}
+
+	/* Nothing to register */
+	return FALSE;
+
+done:
+	iface = g_new0(struct interface_data, 1);
+	iface->name = g_strdup(name);
+	iface->methods = methods;
+	iface->signals = signals;
+	iface->properties = properties;
+	iface->user_data = user_data;
+	iface->destroy = destroy;
+
+	data->interfaces = g_slist_append(data->interfaces, iface);
+	if (data->parent == NULL)
+		return TRUE;
+
+	data->added = g_slist_append(data->added, iface);
+
+	add_pending(data);
+
+	return TRUE;
+}
+
+static struct generic_data *object_path_ref(DBusConnection *connection,
+							const char *path)
+{
+	struct generic_data *data;
+
+	if (dbus_connection_get_object_path_data(connection, path,
+						(void *) &data) == TRUE) {
+		if (data != NULL) {
+			data->refcount++;
+			return data;
+		}
+	}
+
+	data = g_new0(struct generic_data, 1);
+	data->conn = dbus_connection_ref(connection);
+	data->path = g_strdup(path);
+	data->refcount = 1;
+
+	data->introspect = g_strdup(DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE "<node></node>");
+
+	if (!dbus_connection_register_object_path(connection, path,
+						&generic_table, data)) {
+		dbus_connection_unref(data->conn);
+		g_free(data->path);
+		g_free(data->introspect);
+		g_free(data);
+		return NULL;
+	}
+
+	invalidate_parent_data(connection, path);
+
+	add_interface(data, DBUS_INTERFACE_INTROSPECTABLE, introspect_methods,
+						NULL, NULL, data, NULL);
+
+	return data;
+}
+
+static void object_path_unref(DBusConnection *connection, const char *path)
+{
+	struct generic_data *data = NULL;
+
+	if (dbus_connection_get_object_path_data(connection, path,
+						(void *) &data) == FALSE)
+		return;
+
+	if (data == NULL)
+		return;
+
+	data->refcount--;
+
+	if (data->refcount > 0)
+		return;
+
+	remove_interface(data, DBUS_INTERFACE_INTROSPECTABLE);
+	remove_interface(data, DBUS_INTERFACE_PROPERTIES);
+
+	invalidate_parent_data(data->conn, data->path);
+
+	dbus_connection_unregister_object_path(data->conn, data->path);
+}
+
+static gboolean check_signal(DBusConnection *conn, const char *path,
+				const char *interface, const char *name,
+				const GDBusArgInfo **args)
+{
+	struct generic_data *data = NULL;
+	struct interface_data *iface;
+	const GDBusSignalTable *signal;
+
+	*args = NULL;
+	if (!dbus_connection_get_object_path_data(conn, path,
+					(void *) &data) || data == NULL) {
+		error("dbus_connection_emit_signal: path %s isn't registered",
+				path);
+		return FALSE;
+	}
+
+	iface = find_interface(data->interfaces, interface);
+	if (iface == NULL) {
+		error("dbus_connection_emit_signal: %s does not implement %s",
+				path, interface);
+		return FALSE;
+	}
+
+	for (signal = iface->signals; signal && signal->name; signal++) {
+		if (strcmp(signal->name, name) != 0)
+			continue;
+
+		if (signal->flags & G_DBUS_SIGNAL_FLAG_EXPERIMENTAL) {
+			const char *env = g_getenv("GDBUS_EXPERIMENTAL");
+			if (g_strcmp0(env, "1") != 0)
+				break;
+		}
+
+		*args = signal->args;
+		return TRUE;
+	}
+
+	error("No signal named %s on interface %s", name, interface);
+	return FALSE;
+}
+
+gboolean g_dbus_register_interface(DBusConnection *connection,
+					const char *path, const char *name,
+					const GDBusMethodTable *methods,
+					const GDBusSignalTable *signals,
+					const GDBusPropertyTable *properties,
+					void *user_data,
+					GDBusDestroyFunction destroy)
+{
+	struct generic_data *data;
+
+	data = object_path_ref(connection, path);
+	if (data == NULL)
+		return FALSE;
+
+	if (find_interface(data->interfaces, name)) {
+		object_path_unref(connection, path);
+		return FALSE;
+	}
+
+	if (!add_interface(data, name, methods, signals, properties, user_data,
+								destroy)) {
+		object_path_unref(connection, path);
+		return FALSE;
+	}
+
+	if (properties != NULL && !find_interface(data->interfaces,
+						DBUS_INTERFACE_PROPERTIES))
+		add_interface(data, DBUS_INTERFACE_PROPERTIES,
+				properties_methods, properties_signals, NULL,
+				data, NULL);
+
+	g_free(data->introspect);
+	data->introspect = NULL;
+
+	return TRUE;
+}
+
+gboolean g_dbus_unregister_interface(DBusConnection *connection,
+					const char *path, const char *name)
+{
+	struct generic_data *data = NULL;
+
+	if (path == NULL)
+		return FALSE;
+
+	if (dbus_connection_get_object_path_data(connection, path,
+						(void *) &data) == FALSE)
+		return FALSE;
+
+	if (data == NULL)
+		return FALSE;
+
+	if (remove_interface(data, name) == FALSE)
+		return FALSE;
+
+	g_free(data->introspect);
+	data->introspect = NULL;
+
+	object_path_unref(connection, data->path);
+
+	return TRUE;
+}
+
+gboolean g_dbus_register_security(const GDBusSecurityTable *security)
+{
+	if (security_table != NULL)
+		return FALSE;
+
+	security_table = security;
+
+	return TRUE;
+}
+
+gboolean g_dbus_unregister_security(const GDBusSecurityTable *security)
+{
+	security_table = NULL;
+
+	return TRUE;
+}
+
+DBusMessage *g_dbus_create_error_valist(DBusMessage *message, const char *name,
+					const char *format, va_list args)
+{
+	char str[1024];
+
+	if (format)
+		vsnprintf(str, sizeof(str), format, args);
+	else
+		str[0] = '\0';
+
+	return dbus_message_new_error(message, name, str);
+}
+
+DBusMessage *g_dbus_create_error(DBusMessage *message, const char *name,
+						const char *format, ...)
+{
+	va_list args;
+	DBusMessage *reply;
+
+	va_start(args, format);
+
+	reply = g_dbus_create_error_valist(message, name, format, args);
+
+	va_end(args);
+
+	return reply;
+}
+
+DBusMessage *g_dbus_create_reply_valist(DBusMessage *message,
+						int type, va_list args)
+{
+	DBusMessage *reply;
+
+	reply = dbus_message_new_method_return(message);
+	if (reply == NULL)
+		return NULL;
+
+	if (dbus_message_append_args_valist(reply, type, args) == FALSE) {
+		dbus_message_unref(reply);
+		return NULL;
+	}
+
+	return reply;
+}
+
+DBusMessage *g_dbus_create_reply(DBusMessage *message, int type, ...)
+{
+	va_list args;
+	DBusMessage *reply;
+
+	va_start(args, type);
+
+	reply = g_dbus_create_reply_valist(message, type, args);
+
+	va_end(args);
+
+	return reply;
+}
+
+static void g_dbus_flush(DBusConnection *connection)
+{
+	GSList *l;
+
+	for (l = pending; l;) {
+		struct generic_data *data = l->data;
+
+		l = l->next;
+		if (data->conn != connection)
+			continue;
+
+		process_changes(data);
+	}
+}
+
+gboolean g_dbus_send_message(DBusConnection *connection, DBusMessage *message)
+{
+	dbus_bool_t result = FALSE;
+
+	if (dbus_message_get_type(message) == DBUS_MESSAGE_TYPE_METHOD_CALL)
+		dbus_message_set_no_reply(message, TRUE);
+	else if (dbus_message_get_type(message) == DBUS_MESSAGE_TYPE_SIGNAL) {
+		const char *path = dbus_message_get_path(message);
+		const char *interface = dbus_message_get_interface(message);
+		const char *name = dbus_message_get_member(message);
+		const GDBusArgInfo *args;
+
+		if (!check_signal(connection, path, interface, name, &args))
+			goto out;
+	}
+
+	/* Flush pending signal to guarantee message order */
+	g_dbus_flush(connection);
+
+	result = dbus_connection_send(connection, message, NULL);
+
+out:
+	dbus_message_unref(message);
+
+	return result;
+}
+
+gboolean g_dbus_send_message_with_reply(DBusConnection *connection,
+					DBusMessage *message,
+					DBusPendingCall **call, int timeout)
+{
+	dbus_bool_t ret;
+
+	/* Flush pending signal to guarantee message order */
+	g_dbus_flush(connection);
+
+	ret = dbus_connection_send_with_reply(connection, message, call,
+								timeout);
+
+	if (ret == TRUE && call != NULL && *call == NULL) {
+		error("Unable to send message (passing fd blocked?)");
+		return FALSE;
+	}
+
+	return ret;
+}
+
+gboolean g_dbus_send_error_valist(DBusConnection *connection,
+					DBusMessage *message, const char *name,
+					const char *format, va_list args)
+{
+	DBusMessage *error;
+
+	error = g_dbus_create_error_valist(message, name, format, args);
+	if (error == NULL)
+		return FALSE;
+
+	return g_dbus_send_message(connection, error);
+}
+
+gboolean g_dbus_send_error(DBusConnection *connection, DBusMessage *message,
+				const char *name, const char *format, ...)
+{
+	va_list args;
+	gboolean result;
+
+	va_start(args, format);
+
+	result = g_dbus_send_error_valist(connection, message, name,
+							format, args);
+
+	va_end(args);
+
+	return result;
+}
+
+gboolean g_dbus_send_reply_valist(DBusConnection *connection,
+				DBusMessage *message, int type, va_list args)
+{
+	DBusMessage *reply;
+
+	reply = dbus_message_new_method_return(message);
+	if (reply == NULL)
+		return FALSE;
+
+	if (dbus_message_append_args_valist(reply, type, args) == FALSE) {
+		dbus_message_unref(reply);
+		return FALSE;
+	}
+
+	return g_dbus_send_message(connection, reply);
+}
+
+gboolean g_dbus_send_reply(DBusConnection *connection,
+				DBusMessage *message, int type, ...)
+{
+	va_list args;
+	gboolean result;
+
+	va_start(args, type);
+
+	result = g_dbus_send_reply_valist(connection, message, type, args);
+
+	va_end(args);
+
+	return result;
+}
+
+gboolean g_dbus_emit_signal(DBusConnection *connection,
+				const char *path, const char *interface,
+				const char *name, int type, ...)
+{
+	va_list args;
+	gboolean result;
+
+	va_start(args, type);
+
+	result = g_dbus_emit_signal_valist(connection, path, interface,
+							name, type, args);
+
+	va_end(args);
+
+	return result;
+}
+
+gboolean g_dbus_emit_signal_valist(DBusConnection *connection,
+				const char *path, const char *interface,
+				const char *name, int type, va_list args)
+{
+	DBusMessage *signal;
+	dbus_bool_t ret;
+	const GDBusArgInfo *args_info;
+
+	if (!check_signal(connection, path, interface, name, &args_info))
+		return FALSE;
+
+	signal = dbus_message_new_signal(path, interface, name);
+	if (signal == NULL) {
+		error("Unable to allocate new %s.%s signal", interface,  name);
+		return FALSE;
+	}
+
+	ret = dbus_message_append_args_valist(signal, type, args);
+	if (!ret)
+		goto fail;
+
+	if (g_dbus_args_have_signature(args_info, signal) == FALSE) {
+		error("%s.%s: got unexpected signature '%s'", interface, name,
+					dbus_message_get_signature(signal));
+		ret = FALSE;
+		goto fail;
+	}
+
+	return g_dbus_send_message(connection, signal);
+
+fail:
+	dbus_message_unref(signal);
+
+	return ret;
+}
+
+static void process_properties_from_interface(struct generic_data *data,
+						struct interface_data *iface)
+{
+	GSList *l;
+	DBusMessage *signal;
+	DBusMessageIter iter, dict, array;
+	GSList *invalidated;
+
+	data->pending_prop = FALSE;
+
+	if (iface->pending_prop == NULL)
+		return;
+
+	signal = dbus_message_new_signal(data->path,
+			DBUS_INTERFACE_PROPERTIES, "PropertiesChanged");
+	if (signal == NULL) {
+		error("Unable to allocate new " DBUS_INTERFACE_PROPERTIES
+						".PropertiesChanged signal");
+		return;
+	}
+
+	iface->pending_prop = g_slist_reverse(iface->pending_prop);
+
+	dbus_message_iter_init_append(signal, &iter);
+	dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING,	&iface->name);
+	dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
+			DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+			DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
+			DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict);
+
+	invalidated = NULL;
+
+	for (l = iface->pending_prop; l != NULL; l = l->next) {
+		GDBusPropertyTable *p = l->data;
+
+		if (p->get == NULL)
+			continue;
+
+		if (p->exists != NULL && !p->exists(p, iface->user_data)) {
+			invalidated = g_slist_prepend(invalidated, p);
+			continue;
+		}
+
+		append_property(iface, p, &dict);
+	}
+
+	dbus_message_iter_close_container(&iter, &dict);
+
+	dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
+				DBUS_TYPE_STRING_AS_STRING, &array);
+	for (l = invalidated; l != NULL; l = g_slist_next(l)) {
+		GDBusPropertyTable *p = l->data;
+
+		dbus_message_iter_append_basic(&array, DBUS_TYPE_STRING,
+								&p->name);
+	}
+	g_slist_free(invalidated);
+	dbus_message_iter_close_container(&iter, &array);
+
+	g_slist_free(iface->pending_prop);
+	iface->pending_prop = NULL;
+
+	/* Use dbus_connection_send to avoid recursive calls to g_dbus_flush */
+	dbus_connection_send(data->conn, signal, NULL);
+	dbus_message_unref(signal);
+}
+
+static void process_property_changes(struct generic_data *data)
+{
+	GSList *l;
+
+	for (l = data->interfaces; l != NULL; l = l->next) {
+		struct interface_data *iface = l->data;
+
+		process_properties_from_interface(data, iface);
+	}
+}
+
+void g_dbus_emit_property_changed(DBusConnection *connection,
+				const char *path, const char *interface,
+				const char *name)
+{
+	const GDBusPropertyTable *property;
+	struct generic_data *data;
+	struct interface_data *iface;
+
+	if (path == NULL)
+		return;
+
+	if (!dbus_connection_get_object_path_data(connection, path,
+					(void **) &data) || data == NULL)
+		return;
+
+	iface = find_interface(data->interfaces, interface);
+	if (iface == NULL)
+		return;
+
+	/*
+	 * If ObjectManager is attached, don't emit property changed if
+	 * interface is not yet published
+	 */
+	if (root && g_slist_find(data->added, iface))
+		return;
+
+	property = find_property(iface->properties, name);
+	if (property == NULL) {
+		error("Could not find property %s in %p", name,
+							iface->properties);
+		return;
+	}
+
+	if (g_slist_find(iface->pending_prop, (void *) property) != NULL)
+		return;
+
+	data->pending_prop = TRUE;
+	iface->pending_prop = g_slist_prepend(iface->pending_prop,
+						(void *) property);
+
+	add_pending(data);
+}
+
+gboolean g_dbus_get_properties(DBusConnection *connection, const char *path,
+				const char *interface, DBusMessageIter *iter)
+{
+	struct generic_data *data;
+	struct interface_data *iface;
+
+	if (path == NULL)
+		return FALSE;
+
+	if (!dbus_connection_get_object_path_data(connection, path,
+					(void **) &data) || data == NULL)
+		return FALSE;
+
+	iface = find_interface(data->interfaces, interface);
+	if (iface == NULL)
+		return FALSE;
+
+	append_properties(iface, iter);
+
+	return TRUE;
+}
+
+gboolean g_dbus_attach_object_manager(DBusConnection *connection)
+{
+	struct generic_data *data;
+
+	data = object_path_ref(connection, "/");
+	if (data == NULL)
+		return FALSE;
+
+	add_interface(data, DBUS_INTERFACE_OBJECT_MANAGER,
+					manager_methods, manager_signals,
+					NULL, data, NULL);
+	root = data;
+
+	return TRUE;
+}
+
+gboolean g_dbus_detach_object_manager(DBusConnection *connection)
+{
+	if (!g_dbus_unregister_interface(connection, "/",
+					DBUS_INTERFACE_OBJECT_MANAGER))
+		return FALSE;
+
+	root = NULL;
+
+	return TRUE;
+}
+
+void g_dbus_set_flags(int flags)
+{
+	global_flags = flags;
+}
+
+int g_dbus_get_flags(void)
+{
+	return global_flags;
+}
diff --git a/connman/gdbus/polkit.c b/connman/gdbus/polkit.c
new file mode 100644
index 0000000..9e95fa3
--- /dev/null
+++ b/connman/gdbus/polkit.c
@@ -0,0 +1,202 @@
+/*
+ *
+ *  D-Bus helper library
+ *
+ *  Copyright (C) 2004-2011  Marcel Holtmann <marcel@holtmann.org>
+ *
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  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 <dbus/dbus.h>
+
+#include <glib.h>
+
+int polkit_check_authorization(DBusConnection *conn,
+				const char *action, gboolean interaction,
+				void (*function) (dbus_bool_t authorized,
+							void *user_data),
+						void *user_data, int timeout);
+
+static void add_dict_with_string_value(DBusMessageIter *iter,
+					const char *key, const char *str)
+{
+	DBusMessageIter dict, entry, value;
+
+	dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY,
+			DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+			DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
+			DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict);
+	dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY,
+								NULL, &entry);
+
+	dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
+
+	dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT,
+					DBUS_TYPE_STRING_AS_STRING, &value);
+	dbus_message_iter_append_basic(&value, DBUS_TYPE_STRING, &str);
+	dbus_message_iter_close_container(&entry, &value);
+
+	dbus_message_iter_close_container(&dict, &entry);
+	dbus_message_iter_close_container(iter, &dict);
+}
+
+static void add_empty_string_dict(DBusMessageIter *iter)
+{
+	DBusMessageIter dict;
+
+	dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY,
+			DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+			DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_STRING_AS_STRING
+			DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict);
+
+	dbus_message_iter_close_container(iter, &dict);
+}
+
+static void add_arguments(DBusConnection *conn, DBusMessageIter *iter,
+				const char *action, dbus_uint32_t flags)
+{
+	const char *busname = dbus_bus_get_unique_name(conn);
+	const char *kind = "system-bus-name";
+	const char *cancel = "";
+	DBusMessageIter subject;
+
+	dbus_message_iter_open_container(iter, DBUS_TYPE_STRUCT,
+							NULL, &subject);
+	dbus_message_iter_append_basic(&subject, DBUS_TYPE_STRING, &kind);
+	add_dict_with_string_value(&subject, "name", busname);
+	dbus_message_iter_close_container(iter, &subject);
+
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &action);
+	add_empty_string_dict(iter);
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT32, &flags);
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &cancel);
+}
+
+static dbus_bool_t parse_result(DBusMessageIter *iter)
+{
+	DBusMessageIter result;
+	dbus_bool_t authorized, challenge;
+
+	dbus_message_iter_recurse(iter, &result);
+
+	dbus_message_iter_get_basic(&result, &authorized);
+	dbus_message_iter_get_basic(&result, &challenge);
+
+	return authorized;
+}
+
+struct authorization_data {
+	void (*function) (dbus_bool_t authorized, void *user_data);
+	void *user_data;
+};
+
+static void authorization_reply(DBusPendingCall *call, void *user_data)
+{
+	struct authorization_data *data = user_data;
+	DBusMessage *reply;
+	DBusMessageIter iter;
+	dbus_bool_t authorized = FALSE;
+
+	reply = dbus_pending_call_steal_reply(call);
+
+	if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR)
+		goto done;
+
+	if (dbus_message_has_signature(reply, "(bba{ss})") == FALSE)
+		goto done;
+
+	dbus_message_iter_init(reply, &iter);
+
+	authorized = parse_result(&iter);
+
+done:
+	if (data->function != NULL)
+		data->function(authorized, data->user_data);
+
+	dbus_message_unref(reply);
+
+	dbus_pending_call_unref(call);
+}
+
+#define AUTHORITY_DBUS	"org.freedesktop.PolicyKit1"
+#define AUTHORITY_INTF	"org.freedesktop.PolicyKit1.Authority"
+#define AUTHORITY_PATH	"/org/freedesktop/PolicyKit1/Authority"
+
+int polkit_check_authorization(DBusConnection *conn,
+				const char *action, gboolean interaction,
+				void (*function) (dbus_bool_t authorized,
+							void *user_data),
+						void *user_data, int timeout)
+{
+	struct authorization_data *data;
+	DBusMessage *msg;
+	DBusMessageIter iter;
+	DBusPendingCall *call;
+	dbus_uint32_t flags = 0x00000000;
+
+	if (conn == NULL)
+		return -EINVAL;
+
+	data = dbus_malloc0(sizeof(*data));
+	if (data == NULL)
+		return -ENOMEM;
+
+	msg = dbus_message_new_method_call(AUTHORITY_DBUS, AUTHORITY_PATH,
+				AUTHORITY_INTF, "CheckAuthorization");
+	if (msg == NULL) {
+		dbus_free(data);
+		return -ENOMEM;
+	}
+
+	if (interaction == TRUE)
+		flags |= 0x00000001;
+
+	if (action == NULL)
+		action = "org.freedesktop.policykit.exec";
+
+	dbus_message_iter_init_append(msg, &iter);
+	add_arguments(conn, &iter, action, flags);
+
+	if (dbus_connection_send_with_reply(conn, msg,
+						&call, timeout) == FALSE) {
+		dbus_message_unref(msg);
+		dbus_free(data);
+		return -EIO;
+	}
+
+	if (call == NULL) {
+		dbus_message_unref(msg);
+		dbus_free(data);
+		return -EIO;
+	}
+
+	data->function = function;
+	data->user_data = user_data;
+
+	dbus_pending_call_set_notify(call, authorization_reply,
+							data, dbus_free);
+
+	dbus_message_unref(msg);
+
+	return 0;
+}
diff --git a/connman/gdbus/watch.c b/connman/gdbus/watch.c
new file mode 100644
index 0000000..b60f650
--- /dev/null
+++ b/connman/gdbus/watch.c
@@ -0,0 +1,818 @@
+/*
+ *
+ *  D-Bus helper library
+ *
+ *  Copyright (C) 2004-2011  Marcel Holtmann <marcel@holtmann.org>
+ *
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  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 <stdio.h>
+#include <string.h>
+
+#include <glib.h>
+#include <dbus/dbus.h>
+
+#include "gdbus.h"
+
+#define info(fmt...)
+#define error(fmt...)
+#define debug(fmt...)
+
+static DBusHandlerResult message_filter(DBusConnection *connection,
+					DBusMessage *message, void *user_data);
+
+static guint listener_id = 0;
+static GSList *listeners = NULL;
+
+struct service_data {
+	DBusConnection *conn;
+	DBusPendingCall *call;
+	char *name;
+	const char *owner;
+	guint id;
+	struct filter_callback *callback;
+};
+
+struct filter_callback {
+	GDBusWatchFunction conn_func;
+	GDBusWatchFunction disc_func;
+	GDBusSignalFunction signal_func;
+	GDBusDestroyFunction destroy_func;
+	struct service_data *data;
+	void *user_data;
+	guint id;
+};
+
+struct filter_data {
+	DBusConnection *connection;
+	DBusHandleMessageFunction handle_func;
+	char *name;
+	char *owner;
+	char *path;
+	char *interface;
+	char *member;
+	char *argument;
+	GSList *callbacks;
+	GSList *processed;
+	guint name_watch;
+	gboolean lock;
+	gboolean registered;
+};
+
+static struct filter_data *filter_data_find_match(DBusConnection *connection,
+							const char *name,
+							const char *owner,
+							const char *path,
+							const char *interface,
+							const char *member,
+							const char *argument)
+{
+	GSList *current;
+
+	for (current = listeners;
+			current != NULL; current = current->next) {
+		struct filter_data *data = current->data;
+
+		if (connection != data->connection)
+			continue;
+
+		if (g_strcmp0(name, data->name) != 0)
+			continue;
+
+		if (g_strcmp0(owner, data->owner) != 0)
+			continue;
+
+		if (g_strcmp0(path, data->path) != 0)
+			continue;
+
+		if (g_strcmp0(interface, data->interface) != 0)
+			continue;
+
+		if (g_strcmp0(member, data->member) != 0)
+			continue;
+
+		if (g_strcmp0(argument, data->argument) != 0)
+			continue;
+
+		return data;
+	}
+
+	return NULL;
+}
+
+static struct filter_data *filter_data_find(DBusConnection *connection)
+{
+	GSList *current;
+
+	for (current = listeners;
+			current != NULL; current = current->next) {
+		struct filter_data *data = current->data;
+
+		if (connection != data->connection)
+			continue;
+
+		return data;
+	}
+
+	return NULL;
+}
+
+static void format_rule(struct filter_data *data, char *rule, size_t size)
+{
+	const char *sender;
+	int offset;
+
+	offset = snprintf(rule, size, "type='signal'");
+	sender = data->name ? : data->owner;
+
+	if (sender)
+		offset += snprintf(rule + offset, size - offset,
+				",sender='%s'", sender);
+	if (data->path)
+		offset += snprintf(rule + offset, size - offset,
+				",path='%s'", data->path);
+	if (data->interface)
+		offset += snprintf(rule + offset, size - offset,
+				",interface='%s'", data->interface);
+	if (data->member)
+		offset += snprintf(rule + offset, size - offset,
+				",member='%s'", data->member);
+	if (data->argument)
+		snprintf(rule + offset, size - offset,
+				",arg0='%s'", data->argument);
+}
+
+static gboolean add_match(struct filter_data *data,
+				DBusHandleMessageFunction filter)
+{
+	DBusError err;
+	char rule[DBUS_MAXIMUM_MATCH_RULE_LENGTH];
+
+	format_rule(data, rule, sizeof(rule));
+	dbus_error_init(&err);
+
+	dbus_bus_add_match(data->connection, rule, &err);
+	if (dbus_error_is_set(&err)) {
+		error("Adding match rule \"%s\" failed: %s", rule,
+				err.message);
+		dbus_error_free(&err);
+		return FALSE;
+	}
+
+	data->handle_func = filter;
+	data->registered = TRUE;
+
+	return TRUE;
+}
+
+static gboolean remove_match(struct filter_data *data)
+{
+	DBusError err;
+	char rule[DBUS_MAXIMUM_MATCH_RULE_LENGTH];
+
+	format_rule(data, rule, sizeof(rule));
+
+	dbus_error_init(&err);
+
+	dbus_bus_remove_match(data->connection, rule, &err);
+	if (dbus_error_is_set(&err)) {
+		error("Removing owner match rule for %s failed: %s",
+				rule, err.message);
+		dbus_error_free(&err);
+		return FALSE;
+	}
+
+	return TRUE;
+}
+
+static struct filter_data *filter_data_get(DBusConnection *connection,
+					DBusHandleMessageFunction filter,
+					const char *sender,
+					const char *path,
+					const char *interface,
+					const char *member,
+					const char *argument)
+{
+	struct filter_data *data;
+	const char *name = NULL, *owner = NULL;
+
+	if (filter_data_find(connection) == NULL) {
+		if (!dbus_connection_add_filter(connection,
+					message_filter, NULL, NULL)) {
+			error("dbus_connection_add_filter() failed");
+			return NULL;
+		}
+	}
+
+	if (sender == NULL)
+		goto proceed;
+
+	if (sender[0] == ':')
+		owner = sender;
+	else
+		name = sender;
+
+proceed:
+	data = filter_data_find_match(connection, name, owner, path,
+						interface, member, argument);
+	if (data)
+		return data;
+
+	data = g_new0(struct filter_data, 1);
+
+	data->connection = dbus_connection_ref(connection);
+	data->name = g_strdup(name);
+	data->owner = g_strdup(owner);
+	data->path = g_strdup(path);
+	data->interface = g_strdup(interface);
+	data->member = g_strdup(member);
+	data->argument = g_strdup(argument);
+
+	if (!add_match(data, filter)) {
+		g_free(data);
+		return NULL;
+	}
+
+	listeners = g_slist_append(listeners, data);
+
+	return data;
+}
+
+static struct filter_callback *filter_data_find_callback(
+						struct filter_data *data,
+						guint id)
+{
+	GSList *l;
+
+	for (l = data->callbacks; l; l = l->next) {
+		struct filter_callback *cb = l->data;
+		if (cb->id == id)
+			return cb;
+	}
+	for (l = data->processed; l; l = l->next) {
+		struct filter_callback *cb = l->data;
+		if (cb->id == id)
+			return cb;
+	}
+
+	return NULL;
+}
+
+static void filter_data_free(struct filter_data *data)
+{
+	GSList *l;
+
+	/* Remove filter if there are no listeners left for the connection */
+	if (filter_data_find(data->connection) == NULL)
+		dbus_connection_remove_filter(data->connection, message_filter,
+									NULL);
+
+	for (l = data->callbacks; l != NULL; l = l->next)
+		g_free(l->data);
+
+	g_slist_free(data->callbacks);
+	g_dbus_remove_watch(data->connection, data->name_watch);
+	g_free(data->name);
+	g_free(data->owner);
+	g_free(data->path);
+	g_free(data->interface);
+	g_free(data->member);
+	g_free(data->argument);
+	dbus_connection_unref(data->connection);
+	g_free(data);
+}
+
+static void filter_data_call_and_free(struct filter_data *data)
+{
+	GSList *l;
+
+	for (l = data->callbacks; l != NULL; l = l->next) {
+		struct filter_callback *cb = l->data;
+		if (cb->disc_func)
+			cb->disc_func(data->connection, cb->user_data);
+		if (cb->destroy_func)
+			cb->destroy_func(cb->user_data);
+		g_free(cb);
+	}
+
+	filter_data_free(data);
+}
+
+static struct filter_callback *filter_data_add_callback(
+						struct filter_data *data,
+						GDBusWatchFunction connect,
+						GDBusWatchFunction disconnect,
+						GDBusSignalFunction signal,
+						GDBusDestroyFunction destroy,
+						void *user_data)
+{
+	struct filter_callback *cb = NULL;
+
+	cb = g_new0(struct filter_callback, 1);
+
+	cb->conn_func = connect;
+	cb->disc_func = disconnect;
+	cb->signal_func = signal;
+	cb->destroy_func = destroy;
+	cb->user_data = user_data;
+	cb->id = ++listener_id;
+
+	if (data->lock)
+		data->processed = g_slist_append(data->processed, cb);
+	else
+		data->callbacks = g_slist_append(data->callbacks, cb);
+
+	return cb;
+}
+
+static void service_data_free(struct service_data *data)
+{
+	struct filter_callback *callback = data->callback;
+
+	dbus_connection_unref(data->conn);
+
+	if (data->call)
+		dbus_pending_call_unref(data->call);
+
+	if (data->id)
+		g_source_remove(data->id);
+
+	g_free(data->name);
+	g_free(data);
+
+	callback->data = NULL;
+}
+
+/* Returns TRUE if data is freed */
+static gboolean filter_data_remove_callback(struct filter_data *data,
+						struct filter_callback *cb)
+{
+	data->callbacks = g_slist_remove(data->callbacks, cb);
+	data->processed = g_slist_remove(data->processed, cb);
+
+	/* Cancel pending operations */
+	if (cb->data) {
+		if (cb->data->call)
+			dbus_pending_call_cancel(cb->data->call);
+		service_data_free(cb->data);
+	}
+
+	if (cb->destroy_func)
+		cb->destroy_func(cb->user_data);
+
+	g_free(cb);
+
+	/* Don't remove the filter if other callbacks exist or data is lock
+	 * processing callbacks */
+	if (data->callbacks || data->lock)
+		return FALSE;
+
+	if (data->registered && !remove_match(data))
+		return FALSE;
+
+	listeners = g_slist_remove(listeners, data);
+	filter_data_free(data);
+
+	return TRUE;
+}
+
+static DBusHandlerResult signal_filter(DBusConnection *connection,
+					DBusMessage *message, void *user_data)
+{
+	struct filter_data *data = user_data;
+	struct filter_callback *cb;
+
+	while (data->callbacks) {
+		cb = data->callbacks->data;
+
+		if (cb->signal_func && !cb->signal_func(connection, message,
+							cb->user_data)) {
+			if (filter_data_remove_callback(data, cb))
+				break;
+
+			continue;
+		}
+
+		/* Check if the watch was removed/freed by the callback
+		 * function */
+		if (!g_slist_find(data->callbacks, cb))
+			continue;
+
+		data->callbacks = g_slist_remove(data->callbacks, cb);
+		data->processed = g_slist_append(data->processed, cb);
+	}
+
+	return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+
+static void update_name_cache(const char *name, const char *owner)
+{
+	GSList *l;
+
+	for (l = listeners; l != NULL; l = l->next) {
+		struct filter_data *data = l->data;
+
+		if (g_strcmp0(data->name, name) != 0)
+			continue;
+
+		g_free(data->owner);
+		data->owner = g_strdup(owner);
+	}
+}
+
+static const char *check_name_cache(const char *name)
+{
+	GSList *l;
+
+	for (l = listeners; l != NULL; l = l->next) {
+		struct filter_data *data = l->data;
+
+		if (g_strcmp0(data->name, name) != 0)
+			continue;
+
+		return data->owner;
+	}
+
+	return NULL;
+}
+
+static DBusHandlerResult service_filter(DBusConnection *connection,
+					DBusMessage *message, void *user_data)
+{
+	struct filter_data *data = user_data;
+	struct filter_callback *cb;
+	char *name, *old, *new;
+
+	if (!dbus_message_get_args(message, NULL,
+				DBUS_TYPE_STRING, &name,
+				DBUS_TYPE_STRING, &old,
+				DBUS_TYPE_STRING, &new,
+				DBUS_TYPE_INVALID)) {
+		error("Invalid arguments for NameOwnerChanged signal");
+		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+	}
+
+	update_name_cache(name, new);
+
+	while (data->callbacks) {
+		cb = data->callbacks->data;
+
+		if (*new == '\0') {
+			if (cb->disc_func)
+				cb->disc_func(connection, cb->user_data);
+		} else {
+			if (cb->conn_func)
+				cb->conn_func(connection, cb->user_data);
+		}
+
+		/* Check if the watch was removed/freed by the callback
+		 * function */
+		if (!g_slist_find(data->callbacks, cb))
+			continue;
+
+		/* Only auto remove if it is a bus name watch */
+		if (data->argument[0] == ':' &&
+				(cb->conn_func == NULL || cb->disc_func == NULL)) {
+			if (filter_data_remove_callback(data, cb))
+				break;
+
+			continue;
+		}
+
+		data->callbacks = g_slist_remove(data->callbacks, cb);
+		data->processed = g_slist_append(data->processed, cb);
+	}
+
+	return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+
+
+static DBusHandlerResult message_filter(DBusConnection *connection,
+					DBusMessage *message, void *user_data)
+{
+	struct filter_data *data;
+	const char *sender, *path, *iface, *member, *arg = NULL;
+	GSList *current, *delete_listener = NULL;
+
+	/* Only filter signals */
+	if (dbus_message_get_type(message) != DBUS_MESSAGE_TYPE_SIGNAL)
+		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+	sender = dbus_message_get_sender(message);
+	path = dbus_message_get_path(message);
+	iface = dbus_message_get_interface(message);
+	member = dbus_message_get_member(message);
+	dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &arg, DBUS_TYPE_INVALID);
+
+	/* If sender != NULL it is always the owner */
+
+	for (current = listeners; current != NULL; current = current->next) {
+		data = current->data;
+
+		if (connection != data->connection)
+			continue;
+
+		if (!sender && data->owner)
+			continue;
+
+		if (data->owner && g_str_equal(sender, data->owner) == FALSE)
+			continue;
+
+		if (data->path && g_str_equal(path, data->path) == FALSE)
+			continue;
+
+		if (data->interface && g_str_equal(iface,
+						data->interface) == FALSE)
+			continue;
+
+		if (data->member && g_str_equal(member, data->member) == FALSE)
+			continue;
+
+		if (data->argument && g_str_equal(arg,
+						data->argument) == FALSE)
+			continue;
+
+		if (data->handle_func) {
+			data->lock = TRUE;
+
+			data->handle_func(connection, message, data);
+
+			data->callbacks = data->processed;
+			data->processed = NULL;
+			data->lock = FALSE;
+		}
+
+		if (!data->callbacks)
+			delete_listener = g_slist_prepend(delete_listener,
+								current);
+	}
+
+	if (delete_listener == NULL)
+		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+	for (current = delete_listener; current != NULL;
+					current = delete_listener->next) {
+		GSList *l = current->data;
+
+		data = l->data;
+
+		/* Has any other callback added callbacks back to this data? */
+		if (data->callbacks != NULL)
+			continue;
+
+		remove_match(data);
+		listeners = g_slist_delete_link(listeners, l);
+
+		filter_data_free(data);
+	}
+
+	g_slist_free(delete_listener);
+
+	return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+
+static gboolean update_service(void *user_data)
+{
+	struct service_data *data = user_data;
+	struct filter_callback *cb = data->callback;
+	DBusConnection *conn;
+
+	conn = dbus_connection_ref(data->conn);
+	service_data_free(data);
+
+	if (cb->conn_func)
+		cb->conn_func(conn, cb->user_data);
+
+	dbus_connection_unref(conn);
+
+	return FALSE;
+}
+
+static void service_reply(DBusPendingCall *call, void *user_data)
+{
+	struct service_data *data = user_data;
+	DBusMessage *reply;
+	DBusError err;
+
+	reply = dbus_pending_call_steal_reply(call);
+	if (reply == NULL)
+		return;
+
+	dbus_error_init(&err);
+
+	if (dbus_set_error_from_message(&err, reply))
+		goto fail;
+
+	if (dbus_message_get_args(reply, &err,
+					DBUS_TYPE_STRING, &data->owner,
+						DBUS_TYPE_INVALID) == FALSE)
+		goto fail;
+
+	update_service(data);
+
+	goto done;
+
+fail:
+	error("%s", err.message);
+	dbus_error_free(&err);
+	service_data_free(data);
+done:
+	dbus_message_unref(reply);
+}
+
+static void check_service(DBusConnection *connection,
+					const char *name,
+					struct filter_callback *callback)
+{
+	DBusMessage *message;
+	struct service_data *data;
+
+	data = g_try_malloc0(sizeof(*data));
+	if (data == NULL) {
+		error("Can't allocate data structure");
+		return;
+	}
+
+	data->conn = dbus_connection_ref(connection);
+	data->name = g_strdup(name);
+	data->callback = callback;
+	callback->data = data;
+
+	data->owner = check_name_cache(name);
+	if (data->owner != NULL) {
+		data->id = g_idle_add(update_service, data);
+		return;
+	}
+
+	message = dbus_message_new_method_call(DBUS_SERVICE_DBUS,
+			DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, "GetNameOwner");
+	if (message == NULL) {
+		error("Can't allocate new message");
+		g_free(data);
+		return;
+	}
+
+	dbus_message_append_args(message, DBUS_TYPE_STRING, &name,
+							DBUS_TYPE_INVALID);
+
+	if (dbus_connection_send_with_reply(connection, message,
+							&data->call, -1) == FALSE) {
+		error("Failed to execute method call");
+		g_free(data);
+		goto done;
+	}
+
+	if (data->call == NULL) {
+		error("D-Bus connection not available");
+		g_free(data);
+		goto done;
+	}
+
+	dbus_pending_call_set_notify(data->call, service_reply, data, NULL);
+
+done:
+	dbus_message_unref(message);
+}
+
+guint g_dbus_add_service_watch(DBusConnection *connection, const char *name,
+				GDBusWatchFunction connect,
+				GDBusWatchFunction disconnect,
+				void *user_data, GDBusDestroyFunction destroy)
+{
+	struct filter_data *data;
+	struct filter_callback *cb;
+
+	if (name == NULL)
+		return 0;
+
+	data = filter_data_get(connection, service_filter,
+				DBUS_SERVICE_DBUS, DBUS_PATH_DBUS,
+				DBUS_INTERFACE_DBUS, "NameOwnerChanged",
+				name);
+	if (data == NULL)
+		return 0;
+
+	cb = filter_data_add_callback(data, connect, disconnect, NULL, destroy,
+					user_data);
+	if (cb == NULL)
+		return 0;
+
+	if (connect)
+		check_service(connection, name, cb);
+
+	return cb->id;
+}
+
+guint g_dbus_add_disconnect_watch(DBusConnection *connection, const char *name,
+				GDBusWatchFunction func,
+				void *user_data, GDBusDestroyFunction destroy)
+{
+	return g_dbus_add_service_watch(connection, name, NULL, func,
+							user_data, destroy);
+}
+
+guint g_dbus_add_signal_watch(DBusConnection *connection,
+				const char *sender, const char *path,
+				const char *interface, const char *member,
+				GDBusSignalFunction function, void *user_data,
+				GDBusDestroyFunction destroy)
+{
+	struct filter_data *data;
+	struct filter_callback *cb;
+
+	data = filter_data_get(connection, signal_filter, sender, path,
+				interface, member, NULL);
+	if (data == NULL)
+		return 0;
+
+	cb = filter_data_add_callback(data, NULL, NULL, function, destroy,
+					user_data);
+	if (cb == NULL)
+		return 0;
+
+	if (data->name != NULL && data->name_watch == 0)
+		data->name_watch = g_dbus_add_service_watch(connection,
+							data->name, NULL,
+							NULL, NULL, NULL);
+
+	return cb->id;
+}
+
+guint g_dbus_add_properties_watch(DBusConnection *connection,
+				const char *sender, const char *path,
+				const char *interface,
+				GDBusSignalFunction function, void *user_data,
+				GDBusDestroyFunction destroy)
+{
+	struct filter_data *data;
+	struct filter_callback *cb;
+
+	data = filter_data_get(connection, signal_filter, sender, path,
+				DBUS_INTERFACE_PROPERTIES, "PropertiesChanged",
+				interface);
+	if (data == NULL)
+		return 0;
+
+	cb = filter_data_add_callback(data, NULL, NULL, function, destroy,
+					user_data);
+	if (cb == NULL)
+		return 0;
+
+	if (data->name != NULL && data->name_watch == 0)
+		data->name_watch = g_dbus_add_service_watch(connection,
+							data->name, NULL,
+							NULL, NULL, NULL);
+
+	return cb->id;
+}
+
+gboolean g_dbus_remove_watch(DBusConnection *connection, guint id)
+{
+	struct filter_data *data;
+	struct filter_callback *cb;
+	GSList *ldata;
+
+	if (id == 0)
+		return FALSE;
+
+	for (ldata = listeners; ldata; ldata = ldata->next) {
+		data = ldata->data;
+
+		cb = filter_data_find_callback(data, id);
+		if (cb) {
+			filter_data_remove_callback(data, cb);
+			return TRUE;
+		}
+	}
+
+	return FALSE;
+}
+
+void g_dbus_remove_all_watches(DBusConnection *connection)
+{
+	struct filter_data *data;
+
+	while ((data = filter_data_find(connection))) {
+		listeners = g_slist_remove(listeners, data);
+		filter_data_call_and_free(data);
+	}
+}
diff --git a/connman/gdhcp/client.c b/connman/gdhcp/client.c
new file mode 100644
index 0000000..3f5ea4c
--- /dev/null
+++ b/connman/gdhcp/client.c
@@ -0,0 +1,3420 @@
+/*
+ *
+ *  DHCP client library with GLib integration
+ *
+ *  Copyright (C) 2009-2014  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
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <errno.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/ioctl.h>
+#include <arpa/inet.h>
+#include <sys/time.h>
+#include <resolv.h>
+
+#include <netpacket/packet.h>
+#include <netinet/if_ether.h>
+#include <net/ethernet.h>
+
+#include <linux/if.h>
+#include <linux/filter.h>
+
+#include <glib.h>
+
+#include "gdhcp.h"
+#include "common.h"
+#include "ipv4ll.h"
+#include "timer.h"
+#define CLOCK_BOOTTIME_ALARM 9
+#define DISCOVER_TIMEOUT 10
+#define DISCOVER_RETRIES 6
+
+#define REQUEST_TIMEOUT 5
+#define REQUEST_RETRIES 3
+
+typedef enum _listen_mode {
+	L_NONE,
+	L2,
+	L3,
+	L_ARP,
+} ListenMode;
+
+typedef enum _dhcp_client_state {
+	INIT_SELECTING,
+	REBOOTING,
+	REQUESTING,
+	BOUND,
+	RENEWING,
+	REBINDING,
+	RELEASED,
+	IPV4LL_PROBE,
+	IPV4LL_ANNOUNCE,
+	IPV4LL_MONITOR,
+	IPV4LL_DEFEND,
+	INFORMATION_REQ,
+	SOLICITATION,
+	REQUEST,
+	CONFIRM,
+	RENEW,
+	REBIND,
+	RELEASE,
+	DECLINE,
+} ClientState;
+
+struct _GDHCPClient {
+	int ref_count;
+	GDHCPType type;
+	ClientState state;
+	int ifindex;
+	char *interface;
+	uint8_t mac_address[6];
+	uint32_t xid;
+	uint32_t server_ip;
+	uint32_t requested_ip;
+	char *assigned_ip;
+	time_t start;
+	uint32_t lease_seconds;
+	ListenMode listen_mode;
+	int listener_sockfd;
+	uint8_t retry_times;
+	uint8_t ack_retry_times;
+	uint8_t conflicts;
+	guint timeout;
+	guint t1_timeout;
+	guint t2_timeout;
+	guint lease_timeout;
+	guint listener_watch;
+	GList *require_list;
+	GList *request_list;
+	GHashTable *code_value_hash;
+	GHashTable *send_value_hash;
+	GDHCPClientEventFunc lease_available_cb;
+	gpointer lease_available_data;
+	GDHCPClientEventFunc ipv4ll_available_cb;
+	gpointer ipv4ll_available_data;
+	GDHCPClientEventFunc no_lease_cb;
+	gpointer no_lease_data;
+	GDHCPClientEventFunc lease_lost_cb;
+	gpointer lease_lost_data;
+	GDHCPClientEventFunc ipv4ll_lost_cb;
+	gpointer ipv4ll_lost_data;
+	GDHCPClientEventFunc address_conflict_cb;
+	gpointer address_conflict_data;
+	GDHCPDebugFunc debug_func;
+	gpointer debug_data;
+	GDHCPClientEventFunc information_req_cb;
+	gpointer information_req_data;
+	GDHCPClientEventFunc solicitation_cb;
+	gpointer solicitation_data;
+	GDHCPClientEventFunc advertise_cb;
+	gpointer advertise_data;
+	GDHCPClientEventFunc request_cb;
+	gpointer request_data;
+	GDHCPClientEventFunc renew_cb;
+	gpointer renew_data;
+	GDHCPClientEventFunc wake_event_cb;
+	gpointer wake_event_data;
+	GDHCPClientEventFunc rebind_cb;
+	gpointer rebind_data;
+	GDHCPClientEventFunc release_cb;
+	gpointer release_data;
+	GDHCPClientEventFunc confirm_cb;
+	gpointer confirm_data;
+	GDHCPClientEventFunc decline_cb;
+	gpointer decline_data;
+	char *last_address;
+	unsigned char *duid;
+	int duid_len;
+	unsigned char *server_duid;
+	int server_duid_len;
+	uint16_t status_code;
+	uint32_t iaid;
+	uint32_t T1, T2;
+	uint32_t next_event;
+	int can_sleep;
+	struct in6_addr ia_na;
+	struct in6_addr ia_ta;
+	time_t last_request;
+	uint32_t expire;
+	bool retransmit;
+	struct timeval start_time;
+	bool request_bcast;
+};
+
+static inline void debug(GDHCPClient *client, const char *format, ...)
+{
+	char str[256];
+	va_list ap;
+
+	if (!client->debug_func)
+		return;
+
+	va_start(ap, format);
+
+	if (vsnprintf(str, sizeof(str), format, ap) > 0)
+		client->debug_func(str, client->debug_data);
+
+	va_end(ap);
+}
+
+static void set_wake(GDHCPClient *dhcp_client, uint32_t timeout)
+{
+	debug(dhcp_client, "Stay awake for %d", timeout);
+
+	dhcp_client->next_event = timeout + time(NULL);
+	dhcp_client->can_sleep = FALSE;
+	if (dhcp_client->wake_event_cb)
+		dhcp_client->wake_event_cb(dhcp_client,
+				dhcp_client->wake_event_data);
+}
+
+static void release_wake(GDHCPClient *dhcp_client, uint32_t timeout)
+{
+	debug(dhcp_client, "may sleep for %d", timeout);
+	dhcp_client->next_event = timeout + time(NULL);
+	dhcp_client->can_sleep = TRUE;
+	if (dhcp_client->wake_event_cb)
+		dhcp_client->wake_event_cb(dhcp_client,
+				dhcp_client->wake_event_data);
+}
+
+int g_dhcp_get_next_event(GDHCPClient *dhcp_client, time_t *next_event)
+{
+	*next_event = dhcp_client->next_event;
+	return dhcp_client->can_sleep;
+}
+
+/* Initialize the packet with the proper defaults */
+static void init_packet(GDHCPClient *dhcp_client, gpointer pkt, char type)
+{
+	if (dhcp_client->type == G_DHCP_IPV6)
+		dhcpv6_init_header(pkt, type);
+	else {
+		struct dhcp_packet *packet = pkt;
+
+		dhcp_init_header(packet, type);
+		memcpy(packet->chaddr, dhcp_client->mac_address, 6);
+	}
+}
+
+static void add_request_options(GDHCPClient *dhcp_client,
+				struct dhcp_packet *packet)
+{
+	int len = 0;
+	GList *list;
+	uint8_t code;
+	int end = dhcp_end_option(packet->options);
+
+	for (list = dhcp_client->request_list; list; list = list->next) {
+		code = (uint8_t) GPOINTER_TO_INT(list->data);
+
+		packet->options[end + OPT_DATA + len] = code;
+		len++;
+	}
+
+	if (len) {
+		packet->options[end + OPT_CODE] = DHCP_PARAM_REQ;
+		packet->options[end + OPT_LEN] = len;
+		packet->options[end + OPT_DATA + len] = DHCP_END;
+	}
+}
+
+struct hash_params {
+	unsigned char *buf;
+	int max_buf;
+	unsigned char **ptr_buf;
+};
+
+static void add_dhcpv6_binary_option(gpointer key, gpointer value,
+					gpointer user_data)
+{
+	uint8_t *option = value;
+	uint16_t len;
+	struct hash_params *params = user_data;
+
+	/* option[0][1] contains option code */
+	len = option[2] << 8 | option[3];
+
+	if ((*params->ptr_buf + len + 2 + 2) > (params->buf + params->max_buf))
+		return;
+
+	memcpy(*params->ptr_buf, option, len + 2 + 2);
+	(*params->ptr_buf) += len + 2 + 2;
+}
+
+static void add_dhcpv6_send_options(GDHCPClient *dhcp_client,
+				unsigned char *buf, int max_buf,
+				unsigned char **ptr_buf)
+{
+	struct hash_params params = {
+		.buf = buf,
+		.max_buf = max_buf,
+		.ptr_buf = ptr_buf
+	};
+
+	if (dhcp_client->type != G_DHCP_IPV6)
+		return;
+
+	g_hash_table_foreach(dhcp_client->send_value_hash,
+				add_dhcpv6_binary_option, &params);
+
+	*ptr_buf = *params.ptr_buf;
+}
+
+static void copy_option(uint8_t *buf, uint16_t code, uint16_t len,
+			uint8_t *msg)
+{
+	buf[0] = code >> 8;
+	buf[1] = code & 0xff;
+	buf[2] = len >> 8;
+	buf[3] = len & 0xff;
+	if (len > 0 && msg)
+		memcpy(&buf[4], msg, len);
+}
+
+static int32_t get_time_diff(struct timeval *tv)
+{
+	struct timeval now;
+	int32_t hsec;
+
+	gettimeofday(&now, NULL);
+
+	hsec = (now.tv_sec - tv->tv_sec) * 100;
+	hsec += (now.tv_usec - tv->tv_usec) / 10000;
+
+	return hsec;
+}
+
+static void remove_timeouts(GDHCPClient *dhcp_client)
+{
+
+	if (dhcp_client->timeout > 0)
+		g_rttimeout_source_remove(dhcp_client->timeout);
+	if (dhcp_client->t1_timeout > 0)
+		g_rttimeout_source_remove(dhcp_client->t1_timeout);
+	if (dhcp_client->t2_timeout > 0)
+		g_rttimeout_source_remove(dhcp_client->t2_timeout);
+	if (dhcp_client->lease_timeout > 0)
+		g_rttimeout_source_remove(dhcp_client->lease_timeout);
+
+	dhcp_client->timeout = 0;
+	dhcp_client->t1_timeout = 0;
+	dhcp_client->t2_timeout = 0;
+	dhcp_client->lease_timeout = 0;
+
+}
+
+static void add_dhcpv6_request_options(GDHCPClient *dhcp_client,
+				struct dhcpv6_packet *packet,
+				unsigned char *buf, int max_buf,
+				unsigned char **ptr_buf)
+{
+	GList *list;
+	uint16_t code, value;
+	bool added;
+	int32_t diff;
+	int len;
+
+	if (dhcp_client->type != G_DHCP_IPV6)
+		return;
+
+	for (list = dhcp_client->request_list; list; list = list->next) {
+		code = (uint16_t) GPOINTER_TO_INT(list->data);
+		added = false;
+
+		switch (code) {
+		case G_DHCPV6_CLIENTID:
+			if (!dhcp_client->duid)
+				return;
+
+			len = 2 + 2 + dhcp_client->duid_len;
+			if ((*ptr_buf + len) > (buf + max_buf)) {
+				debug(dhcp_client, "Too long dhcpv6 message "
+					"when writing client id option");
+				return;
+			}
+
+			copy_option(*ptr_buf, G_DHCPV6_CLIENTID,
+				dhcp_client->duid_len, dhcp_client->duid);
+			(*ptr_buf) += len;
+			added = true;
+			break;
+
+		case G_DHCPV6_SERVERID:
+			if (!dhcp_client->server_duid)
+				break;
+
+			len = 2 + 2 + dhcp_client->server_duid_len;
+			if ((*ptr_buf + len) > (buf + max_buf)) {
+				debug(dhcp_client, "Too long dhcpv6 message "
+					"when writing server id option");
+				return;
+			}
+
+			copy_option(*ptr_buf, G_DHCPV6_SERVERID,
+				dhcp_client->server_duid_len,
+				dhcp_client->server_duid);
+			(*ptr_buf) += len;
+			added = true;
+			break;
+
+		case G_DHCPV6_RAPID_COMMIT:
+			len = 2 + 2;
+			if ((*ptr_buf + len) > (buf + max_buf)) {
+				debug(dhcp_client, "Too long dhcpv6 message "
+					"when writing rapid commit option");
+				return;
+			}
+
+			copy_option(*ptr_buf, G_DHCPV6_RAPID_COMMIT, 0, 0);
+			(*ptr_buf) += len;
+			added = true;
+			break;
+
+		case G_DHCPV6_ORO:
+			break;
+
+		case G_DHCPV6_ELAPSED_TIME:
+			if (!dhcp_client->retransmit) {
+				/*
+				 * Initial message, elapsed time is 0.
+				 */
+				diff = 0;
+			} else {
+				diff = get_time_diff(&dhcp_client->start_time);
+				if (diff < 0 || diff > 0xffff)
+					diff = 0xffff;
+			}
+
+			len = 2 + 2 + 2;
+			if ((*ptr_buf + len) > (buf + max_buf)) {
+				debug(dhcp_client, "Too long dhcpv6 message "
+					"when writing elapsed time option");
+				return;
+			}
+
+			value = htons((uint16_t)diff);
+			copy_option(*ptr_buf, G_DHCPV6_ELAPSED_TIME,
+				2, (uint8_t *)&value);
+			(*ptr_buf) += len;
+			added = true;
+			break;
+
+		case G_DHCPV6_DNS_SERVERS:
+			break;
+
+		case G_DHCPV6_DOMAIN_LIST:
+			break;
+
+		case G_DHCPV6_SNTP_SERVERS:
+			break;
+
+		default:
+			break;
+		}
+
+		if (added)
+			debug(dhcp_client, "option %d len %d added", code, len);
+	}
+}
+
+static void add_binary_option(gpointer key, gpointer value, gpointer user_data)
+{
+	uint8_t *option = value;
+	struct dhcp_packet *packet = user_data;
+
+	dhcp_add_binary_option(packet, option);
+}
+
+static void add_send_options(GDHCPClient *dhcp_client,
+				struct dhcp_packet *packet)
+{
+	g_hash_table_foreach(dhcp_client->send_value_hash,
+				add_binary_option, packet);
+}
+
+static const char *get_message_type(uint8_t type)
+{
+	switch (type) {
+	case DHCPDISCOVER:
+		return "DISCOVER";
+	case DHCPOFFER:
+		return "OFFER";
+	case DHCPREQUEST:
+		return "REQUEST";
+	case DHCPDECLINE:
+		return "DECLINE";
+	case DHCPACK:
+		return "ACK";
+	case DHCPNAK:
+		return "NAK";
+	case DHCPRELEASE:
+		return "RELEASE";
+	case DHCPINFORM:
+		return "INFORM";
+	default:
+		return "";
+	}
+}
+/*
+ * Return an RFC 951- and 2131-complaint BOOTP 'secs' value that
+ * represents the number of seconds elapsed from the start of
+ * attempting DHCP to satisfy some DHCP servers that allow for an
+ * "authoritative" reply before responding.
+ */
+static uint16_t dhcp_attempt_secs(GDHCPClient *dhcp_client)
+{
+	return htons(MIN(time(NULL) - dhcp_client->start, UINT16_MAX));
+}
+
+static int send_discover(GDHCPClient *dhcp_client, uint32_t requested)
+{
+	const uint8_t type = DHCPDISCOVER;
+	struct dhcp_packet packet;
+	struct in_addr dest;
+	char destbuf[INET_ADDRSTRLEN];
+
+	init_packet(dhcp_client, &packet, type);
+
+	packet.xid = dhcp_client->xid;
+	packet.secs = dhcp_attempt_secs(dhcp_client);
+
+	if (requested)
+		dhcp_add_option_uint32(&packet, DHCP_REQUESTED_IP, requested);
+
+	/* Explicitly saying that we want RFC-compliant packets helps
+	 * some buggy DHCP servers to NOT send bigger packets */
+	dhcp_add_option_uint16(&packet, DHCP_MAX_SIZE, 576);
+
+	add_request_options(dhcp_client, &packet);
+
+	add_send_options(dhcp_client, &packet);
+
+	dest.s_addr = INADDR_BROADCAST;
+
+	debug(dhcp_client, "%s on %s to %s port %d interval %d",
+		get_message_type(type),
+		dhcp_client->interface,
+		inet_ntop(AF_INET, &dest, destbuf, sizeof(destbuf)),
+		SERVER_PORT,
+		DISCOVER_TIMEOUT);
+
+	set_wake(dhcp_client, DISCOVER_TIMEOUT);
+
+	return dhcp_send_raw_packet(&packet, INADDR_ANY, CLIENT_PORT,
+					dest.s_addr, SERVER_PORT,
+					MAC_BCAST_ADDR, dhcp_client->ifindex,
+                    dhcp_client->retry_times % 2);
+}
+
+static int send_request(GDHCPClient *dhcp_client)
+{
+	const uint8_t type = DHCPREQUEST;
+	struct dhcp_packet packet;
+	struct in_addr request, dest;
+	char requestbuf[INET_ADDRSTRLEN], destbuf[INET_ADDRSTRLEN];
+    
+    debug(dhcp_client, "sending DHCP request (state %d)",
+                     dhcp_client->state);
+
+	init_packet(dhcp_client, &packet, type);
+
+	packet.xid = dhcp_client->xid;
+	packet.secs = dhcp_attempt_secs(dhcp_client);
+
+	if (dhcp_client->state == REQUESTING || dhcp_client->state == REBOOTING)
+		dhcp_add_option_uint32(&packet, DHCP_REQUESTED_IP,
+				dhcp_client->requested_ip);
+
+	if (dhcp_client->state == REQUESTING)
+		dhcp_add_option_uint32(&packet, DHCP_SERVER_ID,
+				dhcp_client->server_ip);
+
+	dhcp_add_option_uint16(&packet, DHCP_MAX_SIZE, 576);
+
+	add_request_options(dhcp_client, &packet);
+
+	add_send_options(dhcp_client, &packet);
+    
+    request.s_addr = dhcp_client->requested_ip;
+    dest.s_addr = INADDR_BROADCAST;
+          
+    debug(dhcp_client, "%s of %s on %s to %s port %d interval %d",
+          get_message_type(type),
+          inet_ntop(AF_INET, &request, requestbuf, sizeof(requestbuf)),
+          dhcp_client->interface,
+          inet_ntop(AF_INET, &dest, destbuf, sizeof(destbuf)),
+          SERVER_PORT,
+          REQUEST_TIMEOUT);
+
+	if (dhcp_client->state == RENEWING || dhcp_client->state == REBINDING)
+		packet.ciaddr = htonl(dhcp_client->requested_ip);
+
+	set_wake(dhcp_client, REQUEST_TIMEOUT);
+
+	if (dhcp_client->state == RENEWING )
+		return dhcp_send_kernel_packet(&packet,
+				dhcp_client->requested_ip, CLIENT_PORT,
+				dhcp_client->server_ip, SERVER_PORT);
+
+	return dhcp_send_raw_packet(&packet, INADDR_ANY, CLIENT_PORT,
+				INADDR_BROADCAST, SERVER_PORT,
+				MAC_BCAST_ADDR, dhcp_client->ifindex,
+				dhcp_client->request_bcast);
+}
+
+static int send_release(GDHCPClient *dhcp_client,
+			uint32_t server, uint32_t ciaddr)
+{
+	const uint8_t type = DHCPRELEASE;
+	struct dhcp_packet packet;
+	uint64_t rand;
+    struct in_addr release, dest;
+	char releasebuf[INET_ADDRSTRLEN], destbuf[INET_ADDRSTRLEN];
+	
+    debug(dhcp_client, "sending DHCP release request");
+
+	init_packet(dhcp_client, &packet, DHCPRELEASE);
+	dhcp_get_random(&rand);
+	packet.xid = rand;
+	packet.ciaddr = htonl(ciaddr);
+
+	dhcp_add_option_uint32(&packet, DHCP_SERVER_ID, server);
+
+	release.s_addr = ciaddr;
+	dest.s_addr = server;
+
+	debug(dhcp_client, "%s of %s on %s to %s port %d",
+		get_message_type(type),
+		inet_ntop(AF_INET, &release, releasebuf, sizeof(releasebuf)),
+		dhcp_client->interface,
+		inet_ntop(AF_INET, &dest, destbuf, sizeof(destbuf)),
+		SERVER_PORT);
+
+	return dhcp_send_kernel_packet(&packet, release.s_addr, CLIENT_PORT,
+						dest.s_addr, SERVER_PORT);
+}
+
+static gboolean ipv4ll_probe_timeout(gpointer dhcp_data);
+static int switch_listening_mode(GDHCPClient *dhcp_client,
+					ListenMode listen_mode);
+
+static gboolean send_probe_packet(gpointer dhcp_data)
+{
+	GDHCPClient *dhcp_client;
+	guint timeout;
+
+	dhcp_client = dhcp_data;
+	/* if requested_ip is not valid, pick a new address*/
+	if (dhcp_client->requested_ip == 0) {
+		debug(dhcp_client, "pick a new random address");
+		dhcp_client->requested_ip = ipv4ll_random_ip();
+	}
+
+	debug(dhcp_client, "sending IPV4LL probe request");
+
+	if (dhcp_client->retry_times == 1) {
+		dhcp_client->state = IPV4LL_PROBE;
+		switch_listening_mode(dhcp_client, L_ARP);
+	}
+	ipv4ll_send_arp_packet(dhcp_client->mac_address, 0,
+			dhcp_client->requested_ip, dhcp_client->ifindex);
+
+	if (dhcp_client->retry_times < PROBE_NUM) {
+		/*add a random timeout in range of PROBE_MIN to PROBE_MAX*/
+		timeout = ipv4ll_random_delay_ms(PROBE_MAX-PROBE_MIN);
+		timeout += PROBE_MIN*1000;
+	} else
+		timeout = (ANNOUNCE_WAIT * 1000);
+
+	dhcp_client->timeout = g_rttimeout_add_full(CLOCK_BOOTTIME_ALARM, G_PRIORITY_HIGH,
+						 timeout,
+						 ipv4ll_probe_timeout,
+						 dhcp_client,
+						 NULL);
+	return FALSE;
+}
+
+static gboolean ipv4ll_announce_timeout(gpointer dhcp_data);
+static gboolean ipv4ll_defend_timeout(gpointer dhcp_data);
+
+static gboolean send_announce_packet(gpointer dhcp_data)
+{
+	GDHCPClient *dhcp_client;
+
+	dhcp_client = dhcp_data;
+
+	debug(dhcp_client, "sending IPV4LL announce request");
+
+	ipv4ll_send_arp_packet(dhcp_client->mac_address,
+				dhcp_client->requested_ip,
+				dhcp_client->requested_ip,
+				dhcp_client->ifindex);
+
+	remove_timeouts(dhcp_client);
+
+	if (dhcp_client->state == IPV4LL_DEFEND) {
+		dhcp_client->timeout =
+			g_rttimeout_add_seconds_full(CLOCK_BOOTTIME_ALARM, G_PRIORITY_HIGH,
+						DEFEND_INTERVAL,
+						ipv4ll_defend_timeout,
+						dhcp_client,
+						NULL);
+		return TRUE;
+	} else
+		dhcp_client->timeout =
+			g_rttimeout_add_seconds_full(CLOCK_BOOTTIME_ALARM, G_PRIORITY_HIGH,
+						ANNOUNCE_INTERVAL,
+						ipv4ll_announce_timeout,
+						dhcp_client,
+						NULL);
+	return TRUE;
+}
+
+static void get_interface_mac_address(int index, uint8_t *mac_address)
+{
+	struct ifreq ifr;
+	int sk, err;
+
+	sk = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
+	if (sk < 0) {
+		perror("Open socket error");
+		return;
+	}
+
+	memset(&ifr, 0, sizeof(ifr));
+	ifr.ifr_ifindex = index;
+
+	err = ioctl(sk, SIOCGIFNAME, &ifr);
+	if (err < 0) {
+		perror("Get interface name error");
+		goto done;
+	}
+
+	err = ioctl(sk, SIOCGIFHWADDR, &ifr);
+	if (err < 0) {
+		perror("Get mac address error");
+		goto done;
+	}
+
+	memcpy(mac_address, ifr.ifr_hwaddr.sa_data, 6);
+
+done:
+	close(sk);
+}
+
+void g_dhcpv6_client_set_retransmit(GDHCPClient *dhcp_client)
+{
+	if (!dhcp_client)
+		return;
+
+	dhcp_client->retransmit = true;
+}
+
+void g_dhcpv6_client_clear_retransmit(GDHCPClient *dhcp_client)
+{
+	if (!dhcp_client)
+		return;
+
+	dhcp_client->retransmit = false;
+}
+
+int g_dhcpv6_create_duid(GDHCPDuidType duid_type, int index, int type,
+			unsigned char **duid, int *duid_len)
+{
+	time_t duid_time;
+
+	switch (duid_type) {
+	case G_DHCPV6_DUID_LLT:
+		*duid_len = 2 + 2 + 4 + ETH_ALEN;
+		*duid = g_try_malloc(*duid_len);
+		if (!*duid)
+			return -ENOMEM;
+
+		(*duid)[0] = 0;
+		(*duid)[1] = 1;
+		get_interface_mac_address(index, &(*duid)[2 + 2 + 4]);
+		(*duid)[2] = 0;
+		(*duid)[3] = type;
+		duid_time = time(NULL) - DUID_TIME_EPOCH;
+		(*duid)[4] = duid_time >> 24;
+		(*duid)[5] = duid_time >> 16;
+		(*duid)[6] = duid_time >> 8;
+		(*duid)[7] = duid_time & 0xff;
+		break;
+	case G_DHCPV6_DUID_EN:
+		return -EINVAL;
+	case G_DHCPV6_DUID_LL:
+		*duid_len = 2 + 2 + ETH_ALEN;
+		*duid = g_try_malloc(*duid_len);
+		if (!*duid)
+			return -ENOMEM;
+
+		(*duid)[0] = 0;
+		(*duid)[1] = 3;
+		get_interface_mac_address(index, &(*duid)[2 + 2]);
+		(*duid)[2] = 0;
+		(*duid)[3] = type;
+		break;
+	}
+
+	return 0;
+}
+
+static gchar *convert_to_hex(unsigned char *buf, int len)
+{
+	gchar *ret = g_try_malloc(len * 2 + 1);
+	int i;
+
+	for (i = 0; ret && i < len; i++)
+		g_snprintf(ret + i * 2, 3, "%02x", buf[i]);
+
+	return ret;
+}
+
+int g_dhcpv6_client_set_duid(GDHCPClient *dhcp_client, unsigned char *duid,
+			int duid_len)
+{
+	if (!dhcp_client || dhcp_client->type != G_DHCP_IPV6)
+		return -EINVAL;
+
+	g_free(dhcp_client->duid);
+
+	dhcp_client->duid = duid;
+	dhcp_client->duid_len = duid_len;
+
+	if (dhcp_client->debug_func) {
+		gchar *hex = convert_to_hex(duid, duid_len);
+		debug(dhcp_client, "DUID(%d) %s", duid_len, hex);
+		g_free(hex);
+	}
+
+	return 0;
+}
+
+int g_dhcpv6_client_set_pd(GDHCPClient *dhcp_client, uint32_t *T1,
+			uint32_t *T2, GSList *prefixes)
+{
+	uint8_t options[1452];
+	unsigned int max_buf = sizeof(options);
+	int len, count = g_slist_length(prefixes);
+
+	if (!dhcp_client || dhcp_client->type != G_DHCP_IPV6)
+		return -EINVAL;
+
+	g_dhcp_client_set_request(dhcp_client, G_DHCPV6_IA_PD);
+
+	memset(options, 0, sizeof(options));
+
+	options[0] = dhcp_client->iaid >> 24;
+	options[1] = dhcp_client->iaid >> 16;
+	options[2] = dhcp_client->iaid >> 8;
+	options[3] = dhcp_client->iaid;
+
+	if (T1) {
+		uint32_t t = htonl(*T1);
+		memcpy(&options[4], &t, 4);
+	}
+
+	if (T2) {
+		uint32_t t = htonl(*T2);
+		memcpy(&options[8], &t, 4);
+	}
+
+	len = 12;
+
+	if (count > 0) {
+		GSList *list;
+
+		for (list = prefixes; list; list = list->next) {
+			GDHCPIAPrefix *prefix = list->data;
+			uint8_t sub_option[4+4+1+16];
+
+			if ((len + 2 + 2 + sizeof(sub_option)) >= max_buf) {
+				debug(dhcp_client,
+					"Too long dhcpv6 message "
+					"when writing IA prefix option");
+				return -EINVAL;
+			}
+
+			memset(&sub_option, 0, sizeof(sub_option));
+
+			/* preferred and validity time are left zero */
+
+			sub_option[8] = prefix->prefixlen;
+			memcpy(&sub_option[9], &prefix->prefix, 16);
+
+			copy_option(&options[len], G_DHCPV6_IA_PREFIX,
+				sizeof(sub_option), sub_option);
+			len += 2 + 2 + sizeof(sub_option);
+		}
+	}
+
+	g_dhcpv6_client_set_send(dhcp_client, G_DHCPV6_IA_PD,
+				options, len);
+
+	return 0;
+}
+
+uint32_t g_dhcpv6_client_get_iaid(GDHCPClient *dhcp_client)
+{
+	if (!dhcp_client || dhcp_client->type != G_DHCP_IPV6)
+		return 0;
+
+	return dhcp_client->iaid;
+}
+
+void g_dhcpv6_client_set_iaid(GDHCPClient *dhcp_client, uint32_t iaid)
+{
+	if (!dhcp_client || dhcp_client->type != G_DHCP_IPV6)
+		return;
+
+	dhcp_client->iaid = iaid;
+}
+
+void g_dhcpv6_client_create_iaid(GDHCPClient *dhcp_client, int index,
+				unsigned char *iaid)
+{
+	uint8_t buf[6];
+
+	get_interface_mac_address(index, buf);
+
+	memcpy(iaid, &buf[2], 4);
+	dhcp_client->iaid = iaid[0] << 24 |
+			iaid[1] << 16 | iaid[2] << 8 | iaid[3];
+}
+
+int g_dhcpv6_client_get_timeouts(GDHCPClient *dhcp_client,
+				uint32_t *T1, uint32_t *T2,
+				time_t *started,
+				time_t *expire)
+{
+	if (!dhcp_client || dhcp_client->type != G_DHCP_IPV6)
+		return -EINVAL;
+
+	if (T1)
+		*T1 = dhcp_client->T1;
+
+	if (T2)
+		*T2 = dhcp_client->T2;
+
+	if (started)
+		*started = dhcp_client->last_request;
+
+	if (expire)
+		*expire = dhcp_client->last_request + dhcp_client->expire;
+
+	return 0;
+}
+
+static uint8_t *create_iaaddr(GDHCPClient *dhcp_client, uint8_t *buf,
+				uint16_t len)
+{
+	buf[0] = 0;
+	buf[1] = G_DHCPV6_IAADDR;
+	buf[2] = 0;
+	buf[3] = len;
+	memcpy(&buf[4], &dhcp_client->ia_na, 16);
+	memset(&buf[20], 0, 4); /* preferred */
+	memset(&buf[24], 0, 4); /* valid */
+	return buf;
+}
+
+static uint8_t *append_iaaddr(GDHCPClient *dhcp_client, uint8_t *buf,
+			const char *address)
+{
+	struct in6_addr addr;
+
+	if (inet_pton(AF_INET6, address, &addr) != 1)
+		return NULL;
+
+	buf[0] = 0;
+	buf[1] = G_DHCPV6_IAADDR;
+	buf[2] = 0;
+	buf[3] = 24;
+	memcpy(&buf[4], &addr, 16);
+	memset(&buf[20], 0, 4); /* preferred */
+	memset(&buf[24], 0, 4); /* valid */
+	return &buf[28];
+}
+
+static void put_iaid(GDHCPClient *dhcp_client, int index, uint8_t *buf)
+{
+	uint32_t iaid;
+
+	iaid = g_dhcpv6_client_get_iaid(dhcp_client);
+	if (iaid == 0) {
+		g_dhcpv6_client_create_iaid(dhcp_client, index, buf);
+		return;
+	}
+
+	buf[0] = iaid >> 24;
+	buf[1] = iaid >> 16;
+	buf[2] = iaid >> 8;
+	buf[3] = iaid;
+}
+
+int g_dhcpv6_client_set_ia(GDHCPClient *dhcp_client, int index,
+			int code, uint32_t *T1, uint32_t *T2,
+			bool add_iaaddr, const char *ia_na)
+{
+	if (code == G_DHCPV6_IA_TA) {
+		uint8_t ia_options[4];
+
+		put_iaid(dhcp_client, index, ia_options);
+
+		g_dhcp_client_set_request(dhcp_client, G_DHCPV6_IA_TA);
+		g_dhcpv6_client_set_send(dhcp_client, G_DHCPV6_IA_TA,
+					ia_options, sizeof(ia_options));
+
+	} else if (code == G_DHCPV6_IA_NA) {
+		struct in6_addr addr;
+
+		g_dhcp_client_set_request(dhcp_client, G_DHCPV6_IA_NA);
+
+		/*
+		 * If caller has specified the IPv6 address it wishes to
+		 * to use (ia_na != NULL and address is valid), then send
+		 * the address to server.
+		 * If caller did not specify the address (ia_na == NULL) and
+		 * if the current address is not set, then we should not send
+		 * the address sub-option.
+		 */
+		if (add_iaaddr && ((!ia_na &&
+			!IN6_IS_ADDR_UNSPECIFIED(&dhcp_client->ia_na))
+			|| (ia_na &&
+				inet_pton(AF_INET6, ia_na, &addr) == 1))) {
+#define IAADDR_LEN (16+4+4)
+			uint8_t ia_options[4+4+4+2+2+IAADDR_LEN];
+
+			if (ia_na)
+				memcpy(&dhcp_client->ia_na, &addr,
+						sizeof(struct in6_addr));
+
+			put_iaid(dhcp_client, index, ia_options);
+
+			if (T1) {
+				ia_options[4] = *T1 >> 24;
+				ia_options[5] = *T1 >> 16;
+				ia_options[6] = *T1 >> 8;
+				ia_options[7] = *T1;
+			} else
+				memset(&ia_options[4], 0x00, 4);
+
+			if (T2) {
+				ia_options[8] = *T2 >> 24;
+				ia_options[9] = *T2 >> 16;
+				ia_options[10] = *T2 >> 8;
+				ia_options[11] = *T2;
+			} else
+				memset(&ia_options[8], 0x00, 4);
+
+			create_iaaddr(dhcp_client, &ia_options[12],
+					IAADDR_LEN);
+
+			g_dhcpv6_client_set_send(dhcp_client, G_DHCPV6_IA_NA,
+					ia_options, sizeof(ia_options));
+		} else {
+			uint8_t ia_options[4+4+4];
+
+			put_iaid(dhcp_client, index, ia_options);
+
+			memset(&ia_options[4], 0x00, 4); /* T1 (4 bytes) */
+			memset(&ia_options[8], 0x00, 4); /* T2 (4 bytes) */
+
+			g_dhcpv6_client_set_send(dhcp_client, G_DHCPV6_IA_NA,
+					ia_options, sizeof(ia_options));
+		}
+
+	} else
+		return -EINVAL;
+
+	return 0;
+}
+
+int g_dhcpv6_client_set_ias(GDHCPClient *dhcp_client, int index,
+			int code, uint32_t *T1, uint32_t *T2,
+			GSList *addresses)
+{
+	GSList *list;
+	uint8_t *ia_options, *pos;
+	int len, count, total_len;
+
+	count = g_slist_length(addresses);
+	if (count == 0)
+		return -EINVAL;
+
+	g_dhcp_client_set_request(dhcp_client, code);
+
+	if (code == G_DHCPV6_IA_TA)
+		len = 4;         /* IAID */
+	else if (code == G_DHCPV6_IA_NA)
+		len = 4 + 4 + 4; /* IAID + T1 + T2 */
+	else
+		return -EINVAL;
+
+	total_len = len + count * (2 + 2 + 16 + 4 + 4);
+	ia_options = g_try_malloc0(total_len);
+	if (!ia_options)
+		return -ENOMEM;
+
+	put_iaid(dhcp_client, index, ia_options);
+
+	pos = &ia_options[len]; /* skip the IA_NA or IA_TA */
+
+	for (list = addresses; list; list = list->next) {
+		pos = append_iaaddr(dhcp_client, pos, list->data);
+		if (!pos)
+			break;
+	}
+
+	if (code == G_DHCPV6_IA_NA) {
+		if (T1) {
+			ia_options[4] = *T1 >> 24;
+			ia_options[5] = *T1 >> 16;
+			ia_options[6] = *T1 >> 8;
+			ia_options[7] = *T1;
+		} else
+			memset(&ia_options[4], 0x00, 4);
+
+		if (T2) {
+			ia_options[8] = *T2 >> 24;
+			ia_options[9] = *T2 >> 16;
+			ia_options[10] = *T2 >> 8;
+			ia_options[11] = *T2;
+		} else
+			memset(&ia_options[8], 0x00, 4);
+	}
+
+	g_dhcpv6_client_set_send(dhcp_client, code, ia_options, total_len);
+
+	g_free(ia_options);
+
+	return 0;
+}
+
+int g_dhcpv6_client_set_oro(GDHCPClient *dhcp_client, int args, ...)
+{
+	va_list va;
+	int i, j, len = sizeof(uint16_t) * args;
+	uint8_t *values;
+
+	values = g_try_malloc(len);
+	if (!values)
+		return -ENOMEM;
+
+	va_start(va, args);
+	for (i = 0, j = 0; i < args; i++) {
+		uint16_t value = va_arg(va, int);
+		values[j++] = value >> 8;
+		values[j++] = value & 0xff;
+	}
+	va_end(va);
+
+	g_dhcpv6_client_set_send(dhcp_client, G_DHCPV6_ORO, values, len);
+
+	g_free(values);
+
+	return 0;
+}
+
+static int send_dhcpv6_msg(GDHCPClient *dhcp_client, int type, char *msg)
+{
+	struct dhcpv6_packet *packet;
+	uint8_t buf[MAX_DHCPV6_PKT_SIZE];
+	unsigned char *ptr;
+	int ret, max_buf;
+
+	memset(buf, 0, sizeof(buf));
+	packet = (struct dhcpv6_packet *)&buf[0];
+	ptr = buf + sizeof(struct dhcpv6_packet);
+
+	debug(dhcp_client, "sending DHCPv6 %s message", msg);
+
+	init_packet(dhcp_client, packet, type);
+
+	if (!dhcp_client->retransmit) {
+		dhcp_client->xid = packet->transaction_id[0] << 16 |
+				packet->transaction_id[1] << 8 |
+				packet->transaction_id[2];
+		gettimeofday(&dhcp_client->start_time, NULL);
+	} else {
+		packet->transaction_id[0] = dhcp_client->xid >> 16;
+		packet->transaction_id[1] = dhcp_client->xid >> 8 ;
+		packet->transaction_id[2] = dhcp_client->xid;
+	}
+
+	g_dhcp_client_set_request(dhcp_client, G_DHCPV6_ELAPSED_TIME);
+
+	debug(dhcp_client, "sending DHCPv6 %s message xid 0x%04x", msg,
+							dhcp_client->xid);
+
+	max_buf = MAX_DHCPV6_PKT_SIZE - sizeof(struct dhcpv6_packet);
+
+	add_dhcpv6_request_options(dhcp_client, packet, buf, max_buf, &ptr);
+
+	add_dhcpv6_send_options(dhcp_client, buf, max_buf, &ptr);
+
+	ret = dhcpv6_send_packet(dhcp_client->ifindex, packet, ptr - buf);
+
+	debug(dhcp_client, "sent %d pkt %p len %d", ret, packet, ptr - buf);
+	return ret;
+}
+
+static int send_solicitation(GDHCPClient *dhcp_client)
+{
+	return send_dhcpv6_msg(dhcp_client, DHCPV6_SOLICIT, "solicit");
+}
+
+static int send_dhcpv6_request(GDHCPClient *dhcp_client)
+{
+	return send_dhcpv6_msg(dhcp_client, DHCPV6_REQUEST, "request");
+}
+
+static int send_dhcpv6_confirm(GDHCPClient *dhcp_client)
+{
+	return send_dhcpv6_msg(dhcp_client, DHCPV6_CONFIRM, "confirm");
+}
+
+static int send_dhcpv6_renew(GDHCPClient *dhcp_client)
+{
+	return send_dhcpv6_msg(dhcp_client, DHCPV6_RENEW, "renew");
+}
+
+static int send_dhcpv6_rebind(GDHCPClient *dhcp_client)
+{
+	return send_dhcpv6_msg(dhcp_client, DHCPV6_REBIND, "rebind");
+}
+
+static int send_dhcpv6_decline(GDHCPClient *dhcp_client)
+{
+	return send_dhcpv6_msg(dhcp_client, DHCPV6_DECLINE, "decline");
+}
+
+static int send_dhcpv6_release(GDHCPClient *dhcp_client)
+{
+	return send_dhcpv6_msg(dhcp_client, DHCPV6_RELEASE, "release");
+}
+
+static int send_information_req(GDHCPClient *dhcp_client)
+{
+	return send_dhcpv6_msg(dhcp_client, DHCPV6_INFORMATION_REQ,
+				"information-req");
+}
+
+static void remove_value(gpointer data, gpointer user_data)
+{
+	char *value = data;
+	g_free(value);
+}
+
+static void remove_option_value(gpointer data)
+{
+	GList *option_value = data;
+
+	g_list_foreach(option_value, remove_value, NULL);
+	g_list_free(option_value);
+}
+
+GDHCPClient *g_dhcp_client_new(GDHCPType type,
+			int ifindex, GDHCPClientError *error)
+{
+	GDHCPClient *dhcp_client;
+
+	if (ifindex < 0) {
+		*error = G_DHCP_CLIENT_ERROR_INVALID_INDEX;
+		return NULL;
+	}
+
+	dhcp_client = g_try_new0(GDHCPClient, 1);
+	if (!dhcp_client) {
+		*error = G_DHCP_CLIENT_ERROR_NOMEM;
+		return NULL;
+	}
+
+	dhcp_client->interface = get_interface_name(ifindex);
+	if (!dhcp_client->interface) {
+		*error = G_DHCP_CLIENT_ERROR_INTERFACE_UNAVAILABLE;
+		goto error;
+	}
+
+	if (!interface_is_up(ifindex)) {
+		*error = G_DHCP_CLIENT_ERROR_INTERFACE_DOWN;
+		goto error;
+	}
+
+	get_interface_mac_address(ifindex, dhcp_client->mac_address);
+
+	dhcp_client->listener_sockfd = -1;
+	dhcp_client->listen_mode = L_NONE;
+	dhcp_client->ref_count = 1;
+	dhcp_client->type = type;
+	dhcp_client->ifindex = ifindex;
+	dhcp_client->lease_available_cb = NULL;
+	dhcp_client->ipv4ll_available_cb = NULL;
+	dhcp_client->no_lease_cb = NULL;
+	dhcp_client->lease_lost_cb = NULL;
+	dhcp_client->ipv4ll_lost_cb = NULL;
+	dhcp_client->address_conflict_cb = NULL;
+	dhcp_client->listener_watch = 0;
+	dhcp_client->retry_times = 0;
+	dhcp_client->ack_retry_times = 0;
+	dhcp_client->code_value_hash = g_hash_table_new_full(g_direct_hash,
+				g_direct_equal, NULL, remove_option_value);
+	dhcp_client->send_value_hash = g_hash_table_new_full(g_direct_hash,
+				g_direct_equal, NULL, g_free);
+	dhcp_client->request_list = NULL;
+	dhcp_client->require_list = NULL;
+	dhcp_client->duid = NULL;
+	dhcp_client->duid_len = 0;
+	dhcp_client->last_request = time(NULL);
+	dhcp_client->expire = 0;
+	dhcp_client->request_bcast = false;
+
+	*error = G_DHCP_CLIENT_ERROR_NONE;
+
+	return dhcp_client;
+
+error:
+	g_free(dhcp_client->interface);
+	g_free(dhcp_client);
+	return NULL;
+}
+
+#define SERVER_AND_CLIENT_PORTS  ((67 << 16) + 68)
+
+static int dhcp_l2_socket(int ifindex)
+{
+	int fd;
+	struct sockaddr_ll sock;
+
+	/*
+	 * Comment:
+	 *
+	 *	I've selected not to see LL header, so BPF doesn't see it, too.
+	 *	The filter may also pass non-IP and non-ARP packets, but we do
+	 *	a more complete check when receiving the message in userspace.
+	 *
+	 * and filter shamelessly stolen from:
+	 *
+	 *	http://www.flamewarmaster.de/software/dhcpclient/
+	 *
+	 * There are a few other interesting ideas on that page (look under
+	 * "Motivation").  Use of netlink events is most interesting.  Think
+	 * of various network servers listening for events and reconfiguring.
+	 * That would obsolete sending HUP signals and/or make use of restarts.
+	 *
+	 * Copyright: 2006, 2007 Stefan Rompf <sux@loplof.de>.
+	 * License: GPL v2.
+	 *
+	 * TODO: make conditional?
+	 */
+	static const struct sock_filter filter_instr[] = {
+		/* check for udp */
+		BPF_STMT(BPF_LD|BPF_B|BPF_ABS, 9),
+		/* L5, L1, is UDP? */
+		BPF_JUMP(BPF_JMP|BPF_JEQ|BPF_K, IPPROTO_UDP, 2, 0),
+		/* ugly check for arp on ethernet-like and IPv4 */
+		BPF_STMT(BPF_LD|BPF_W|BPF_ABS, 2), /* L1: */
+		BPF_JUMP(BPF_JMP|BPF_JEQ|BPF_K, 0x08000604, 3, 4),/* L3, L4 */
+		/* skip IP header */
+		BPF_STMT(BPF_LDX|BPF_B|BPF_MSH, 0), /* L5: */
+		/* check udp source and destination ports */
+		BPF_STMT(BPF_LD|BPF_W|BPF_IND, 0),
+		/* L3, L4 */
+		BPF_JUMP(BPF_JMP|BPF_JEQ|BPF_K, SERVER_AND_CLIENT_PORTS, 0, 1),
+		/* returns */
+		BPF_STMT(BPF_RET|BPF_K, 0x0fffffff), /* L3: pass */
+		BPF_STMT(BPF_RET|BPF_K, 0), /* L4: reject */
+	};
+
+	static const struct sock_fprog filter_prog = {
+		.len = sizeof(filter_instr) / sizeof(filter_instr[0]),
+		/* casting const away: */
+		.filter = (struct sock_filter *) filter_instr,
+	};
+
+	fd = socket(PF_PACKET, SOCK_DGRAM | SOCK_CLOEXEC, htons(ETH_P_IP));
+	if (fd < 0)
+		return -errno;
+
+	if (SERVER_PORT == 67 && CLIENT_PORT == 68)
+		/* Use only if standard ports are in use */
+		setsockopt(fd, SOL_SOCKET, SO_ATTACH_FILTER, &filter_prog,
+							sizeof(filter_prog));
+
+	memset(&sock, 0, sizeof(sock));
+	sock.sll_family = AF_PACKET;
+	sock.sll_protocol = htons(ETH_P_IP);
+	sock.sll_ifindex = ifindex;
+
+	if (bind(fd, (struct sockaddr *) &sock, sizeof(sock)) != 0) {
+		int err = -errno;
+		close(fd);
+		return err;
+	}
+
+	return fd;
+}
+
+static bool sanity_check(struct ip_udp_dhcp_packet *packet, int bytes)
+{
+	if (packet->ip.protocol != IPPROTO_UDP)
+		return false;
+
+	if (packet->ip.version != IPVERSION)
+		return false;
+
+	if (packet->ip.ihl != sizeof(packet->ip) >> 2)
+		return false;
+
+	if (packet->udp.dest != htons(CLIENT_PORT))
+		return false;
+
+	if (ntohs(packet->udp.len) != (uint16_t)(bytes - sizeof(packet->ip)))
+		return false;
+
+	return true;
+}
+
+static int dhcp_recv_l2_packet(struct dhcp_packet *dhcp_pkt, int fd,
+				struct sockaddr_in *dst_addr)
+{
+	int bytes;
+	struct ip_udp_dhcp_packet packet;
+	uint16_t check;
+
+	memset(&packet, 0, sizeof(packet));
+
+	bytes = read(fd, &packet, sizeof(packet));
+	if (bytes < 0)
+		return -1;
+
+	if (bytes < (int) (sizeof(packet.ip) + sizeof(packet.udp)))
+		return -1;
+
+	if (bytes < ntohs(packet.ip.tot_len))
+		/* packet is bigger than sizeof(packet), we did partial read */
+		return -1;
+
+	/* ignore any extra garbage bytes */
+	bytes = ntohs(packet.ip.tot_len);
+
+	if (!sanity_check(&packet, bytes))
+		return -1;
+
+	check = packet.ip.check;
+	packet.ip.check = 0;
+	if (check != dhcp_checksum(&packet.ip, sizeof(packet.ip)))
+		return -1;
+
+	/* verify UDP checksum. IP header has to be modified for this */
+	memset(&packet.ip, 0, offsetof(struct iphdr, protocol));
+	/* ip.xx fields which are not memset: protocol, check, saddr, daddr */
+	packet.ip.tot_len = packet.udp.len; /* yes, this is needed */
+	check = packet.udp.check;
+	packet.udp.check = 0;
+	if (check && check != dhcp_checksum(&packet, bytes))
+		return -1;
+
+	memcpy(dhcp_pkt, &packet.data, bytes - (sizeof(packet.ip) +
+							sizeof(packet.udp)));
+
+	if (dhcp_pkt->cookie != htonl(DHCP_MAGIC))
+		return -1;
+
+	dst_addr->sin_addr.s_addr = packet.ip.daddr;
+
+	return bytes - (sizeof(packet.ip) + sizeof(packet.udp));
+}
+
+static void ipv4ll_start(GDHCPClient *dhcp_client)
+{
+	guint timeout;
+
+	remove_timeouts(dhcp_client);
+
+	switch_listening_mode(dhcp_client, L_NONE);
+	dhcp_client->retry_times = 0;
+	dhcp_client->requested_ip = 0;
+
+	dhcp_client->requested_ip = ipv4ll_random_ip();
+
+	/*first wait a random delay to avoid storm of arp request on boot*/
+	timeout = ipv4ll_random_delay_ms(PROBE_WAIT);
+
+	dhcp_client->retry_times++;
+	dhcp_client->timeout = g_rttimeout_add_full(CLOCK_BOOTTIME_ALARM, G_PRIORITY_HIGH,
+						timeout,
+						send_probe_packet,
+						dhcp_client,
+						NULL);
+}
+
+static void ipv4ll_stop(GDHCPClient *dhcp_client)
+{
+
+	switch_listening_mode(dhcp_client, L_NONE);
+
+	remove_timeouts(dhcp_client);
+
+	if (dhcp_client->listener_watch > 0) {
+		g_source_remove(dhcp_client->listener_watch);
+		dhcp_client->listener_watch = 0;
+	}
+
+	dhcp_client->state = IPV4LL_PROBE;
+	dhcp_client->retry_times = 0;
+	dhcp_client->requested_ip = 0;
+
+	g_free(dhcp_client->assigned_ip);
+	dhcp_client->assigned_ip = NULL;
+}
+
+static int ipv4ll_recv_arp_packet(GDHCPClient *dhcp_client)
+{
+	int bytes;
+	struct ether_arp arp;
+	uint32_t ip_requested;
+	int source_conflict;
+	int target_conflict;
+
+	memset(&arp, 0, sizeof(arp));
+	bytes = read(dhcp_client->listener_sockfd, &arp, sizeof(arp));
+	if (bytes < 0)
+		return bytes;
+
+	if (arp.arp_op != htons(ARPOP_REPLY) &&
+			arp.arp_op != htons(ARPOP_REQUEST))
+		return -EINVAL;
+
+	ip_requested = htonl(dhcp_client->requested_ip);
+	source_conflict = !memcmp(arp.arp_spa, &ip_requested,
+						sizeof(ip_requested));
+
+	target_conflict = !memcmp(arp.arp_tpa, &ip_requested,
+				sizeof(ip_requested));
+
+	if (!source_conflict && !target_conflict)
+		return 0;
+
+	dhcp_client->conflicts++;
+
+	debug(dhcp_client, "IPV4LL conflict detected");
+
+	if (dhcp_client->state == IPV4LL_MONITOR) {
+		if (!source_conflict)
+			return 0;
+		dhcp_client->state = IPV4LL_DEFEND;
+		debug(dhcp_client, "DEFEND mode conflicts : %d",
+			dhcp_client->conflicts);
+		/*Try to defend with a single announce*/
+		send_announce_packet(dhcp_client);
+		return 0;
+	}
+
+	if (dhcp_client->state == IPV4LL_DEFEND) {
+		if (!source_conflict)
+			return 0;
+		else if (dhcp_client->ipv4ll_lost_cb)
+			dhcp_client->ipv4ll_lost_cb(dhcp_client,
+						dhcp_client->ipv4ll_lost_data);
+	}
+
+	ipv4ll_stop(dhcp_client);
+
+	if (dhcp_client->conflicts < MAX_CONFLICTS) {
+		/*restart whole state machine*/
+		dhcp_client->retry_times++;
+		dhcp_client->timeout =
+			g_rttimeout_add_full(CLOCK_BOOTTIME_ALARM, G_PRIORITY_HIGH,
+					ipv4ll_random_delay_ms(PROBE_WAIT),
+					send_probe_packet,
+					dhcp_client,
+					NULL);
+	}
+	/* Here we got a lot of conflicts, RFC3927 states that we have
+	 * to wait RATE_LIMIT_INTERVAL before retrying,
+	 * but we just report failure.
+	 */
+	else if (dhcp_client->no_lease_cb)
+			dhcp_client->no_lease_cb(dhcp_client,
+						dhcp_client->no_lease_data);
+
+	return 0;
+}
+
+static bool check_package_owner(GDHCPClient *dhcp_client, gpointer pkt)
+{
+	if (dhcp_client->type == G_DHCP_IPV6) {
+		struct dhcpv6_packet *packet6 = pkt;
+		uint32_t xid;
+
+		if (!packet6)
+			return false;
+
+		xid = packet6->transaction_id[0] << 16 |
+			packet6->transaction_id[1] << 8 |
+			packet6->transaction_id[2];
+
+		if (xid != dhcp_client->xid)
+			return false;
+	} else {
+		struct dhcp_packet *packet = pkt;
+
+		if (packet->xid != dhcp_client->xid)
+			return false;
+
+		if (packet->hlen != 6)
+			return false;
+
+		if (memcmp(packet->chaddr, dhcp_client->mac_address, 6))
+			return false;
+	}
+
+	return true;
+}
+
+static void start_request(GDHCPClient *dhcp_client);
+
+static gboolean request_timeout(gpointer user_data)
+{
+	GDHCPClient *dhcp_client = user_data;
+
+	debug(dhcp_client, "request timeout (retries %d)",
+					dhcp_client->retry_times);
+
+	dhcp_client->retry_times++;
+
+	start_request(dhcp_client);
+
+	return FALSE;
+}
+
+static gboolean listener_event(GIOChannel *channel, GIOCondition condition,
+							gpointer user_data);
+
+static int switch_listening_mode(GDHCPClient *dhcp_client,
+					ListenMode listen_mode)
+{
+	GIOChannel *listener_channel;
+	int listener_sockfd;
+
+	if (dhcp_client->listen_mode == listen_mode)
+		return 0;
+
+	debug(dhcp_client, "switch listening mode (%d ==> %d)",
+				dhcp_client->listen_mode, listen_mode);
+
+	if (dhcp_client->listen_mode != L_NONE) {
+		if (dhcp_client->listener_watch > 0)
+			g_source_remove(dhcp_client->listener_watch);
+		dhcp_client->listen_mode = L_NONE;
+		dhcp_client->listener_sockfd = -1;
+		dhcp_client->listener_watch = 0;
+	}
+
+	if (listen_mode == L_NONE)
+		return 0;
+
+	if (listen_mode == L2)
+		listener_sockfd = dhcp_l2_socket(dhcp_client->ifindex);
+	else if (listen_mode == L3) {
+		if (dhcp_client->type == G_DHCP_IPV6)
+			listener_sockfd = dhcp_l3_socket(DHCPV6_CLIENT_PORT,
+							dhcp_client->interface,
+							AF_INET6);
+		else
+			listener_sockfd = dhcp_l3_socket(CLIENT_PORT,
+							dhcp_client->interface,
+							AF_INET);
+	} else if (listen_mode == L_ARP)
+		listener_sockfd = ipv4ll_arp_socket(dhcp_client->ifindex);
+	else
+		return -EIO;
+
+	if (listener_sockfd < 0)
+		return -EIO;
+
+	listener_channel = g_io_channel_unix_new(listener_sockfd);
+	if (!listener_channel) {
+		/* Failed to create listener channel */
+		close(listener_sockfd);
+		return -EIO;
+	}
+
+	dhcp_client->listen_mode = listen_mode;
+	dhcp_client->listener_sockfd = listener_sockfd;
+
+	g_io_channel_set_close_on_unref(listener_channel, TRUE);
+	dhcp_client->listener_watch =
+			g_io_add_watch_full(listener_channel, G_PRIORITY_HIGH,
+				G_IO_IN | G_IO_NVAL | G_IO_ERR | G_IO_HUP,
+						listener_event, dhcp_client,
+								NULL);
+	g_io_channel_unref(listener_channel);
+
+	return 0;
+}
+
+static void start_request(GDHCPClient *dhcp_client)
+{
+	debug(dhcp_client, "start request (retries %d)",
+					dhcp_client->retry_times);
+
+	if (dhcp_client->retry_times == REQUEST_RETRIES) {
+		if (dhcp_client->no_lease_cb)
+			dhcp_client->no_lease_cb(dhcp_client,
+						dhcp_client->no_lease_data);
+		return;
+	}
+
+	if (dhcp_client->retry_times == 0) {
+		dhcp_client->state = REQUESTING;
+		switch_listening_mode(dhcp_client, L2);
+	}
+
+	send_request(dhcp_client);
+
+	dhcp_client->timeout = g_rttimeout_add_seconds_full(CLOCK_BOOTTIME_ALARM, G_PRIORITY_HIGH,
+							REQUEST_TIMEOUT,
+							request_timeout,
+							dhcp_client,
+							NULL);
+}
+#define MINIMUM_LEASE_DURATION 3600
+#define MAXIMUM_LEASE_DURATION 30*24*60*60
+static uint32_t get_lease(GDHCPClient *dhcp_client, struct dhcp_packet *packet)
+{
+	uint8_t *option;
+	uint32_t lease_seconds;
+
+	option = dhcp_get_option(packet, DHCP_LEASE_TIME);
+	if (!option)
+		return 3600;
+
+	lease_seconds = get_be32(option);
+	if (lease_seconds < MINIMUM_LEASE_DURATION)
+	{
+		debug(dhcp_client, "actual lease %d, new lease %d", lease_seconds, MINIMUM_LEASE_DURATION);
+		lease_seconds = MINIMUM_LEASE_DURATION;
+	}
+
+	if (lease_seconds > MAXIMUM_LEASE_DURATION)
+	{
+		debug(dhcp_client, "actual lease %d, new lease %d", lease_seconds, MAXIMUM_LEASE_DURATION);
+		lease_seconds = MAXIMUM_LEASE_DURATION;
+	}
+
+	return lease_seconds;
+}
+
+static void restart_dhcp(GDHCPClient *dhcp_client, int retry_times)
+{
+	debug(dhcp_client, "restart DHCP (retries %d)", retry_times);
+
+	remove_timeouts(dhcp_client);
+
+	dhcp_client->retry_times = retry_times;
+	dhcp_client->requested_ip = 0;
+	dhcp_client->state = INIT_SELECTING;
+	switch_listening_mode(dhcp_client, L2);
+
+	g_dhcp_client_start(dhcp_client, dhcp_client->last_address);
+}
+
+static gboolean start_expire(gpointer user_data)
+{
+	GDHCPClient *dhcp_client = user_data;
+
+	debug(dhcp_client, "lease expired");
+
+	/*remove all timeouts if they are set*/
+	remove_timeouts(dhcp_client);
+
+	restart_dhcp(dhcp_client, 0);
+
+	/* ip need to be cleared */
+	if (dhcp_client->lease_lost_cb)
+		dhcp_client->lease_lost_cb(dhcp_client,
+				dhcp_client->lease_lost_data);
+
+	return false;
+}
+
+static gboolean continue_rebound(gpointer user_data)
+{
+	GDHCPClient *dhcp_client = user_data;
+	uint64_t rand;
+
+	switch_listening_mode(dhcp_client, L2);
+	send_request(dhcp_client);
+
+	if (dhcp_client->t2_timeout> 0)
+		g_source_remove(dhcp_client->t2_timeout);
+
+	/*recalculate remaining rebind time*/
+	dhcp_client->T2 >>= 1;
+	if (dhcp_client->T2 > 60) {
+		dhcp_get_random(&rand);
+		dhcp_client->t2_timeout =
+			g_rttimeout_add_full(CLOCK_BOOTTIME_ALARM, G_PRIORITY_HIGH,
+					dhcp_client->T2 * 1000 + (rand % 2000) - 1000,
+					continue_rebound,
+					dhcp_client,
+					NULL);
+	}
+	set_wake(dhcp_client, REQUEST_TIMEOUT);
+
+	return FALSE;
+}
+
+static gboolean start_rebound(gpointer user_data)
+{
+	GDHCPClient *dhcp_client = user_data;
+
+	/*remove renew timer*/
+	if (dhcp_client->t1_timeout > 0)
+		g_source_remove(dhcp_client->t1_timeout);
+
+	debug(dhcp_client, "start rebound");
+	dhcp_client->state = REBINDING;
+
+	/*calculate total rebind time*/
+	dhcp_client->T2 = dhcp_client->expire - dhcp_client->T2;
+
+	/*send the first rebound and reschedule*/
+	continue_rebound(user_data);
+
+	return FALSE;
+}
+
+static gboolean continue_renew (gpointer user_data)
+{
+	GDHCPClient *dhcp_client = user_data;
+	uint64_t rand;
+
+	switch_listening_mode(dhcp_client, L3);
+	send_request(dhcp_client);
+
+	if (dhcp_client->t1_timeout > 0)
+		g_source_remove(dhcp_client->t1_timeout);
+
+	dhcp_client->t1_timeout = 0;
+
+	dhcp_client->T1 >>= 1;
+
+	if (dhcp_client->T1 > 60) {
+		dhcp_get_random(&rand);
+		dhcp_client->t1_timeout = g_rttimeout_add_full(CLOCK_BOOTTIME_ALARM, G_PRIORITY_HIGH,
+				dhcp_client->T1 * 1000 + (rand % 2000) - 1000,
+				continue_renew,
+				dhcp_client,
+				NULL);
+	}
+	set_wake(dhcp_client, REQUEST_TIMEOUT);
+
+	return FALSE;
+}
+static gboolean start_renew(gpointer user_data)
+{
+	GDHCPClient *dhcp_client = user_data;
+
+	debug(dhcp_client, "start renew");
+	dhcp_client->state = RENEWING;
+
+	/*calculate total renew period*/
+	dhcp_client->T1 = dhcp_client->T2 - dhcp_client->T1;
+
+	/*send first renew and reschedule for half the remaining time.*/
+	continue_renew(user_data);
+
+	return FALSE;
+}
+
+static void start_bound(GDHCPClient *dhcp_client)
+{
+	debug(dhcp_client, "bound to %s -- renewal in %ld seconds.",
+	      dhcp_client->assigned_ip,
+	      dhcp_client->lease_seconds);
+
+	dhcp_client->state = BOUND;
+
+	remove_timeouts(dhcp_client);
+
+	/*
+	 *TODO: T1 and T2 should be set through options instead of
+	 * defaults as they are here.
+	 */
+
+	dhcp_client->T1 = dhcp_client->lease_seconds >> 1;
+	dhcp_client->T2 = dhcp_client->lease_seconds * 0.875;
+	dhcp_client->expire = dhcp_client->lease_seconds;
+
+        dhcp_client->t1_timeout = g_rttimeout_add_seconds_full(CLOCK_BOOTTIME_ALARM,
+                                                               G_PRIORITY_HIGH,
+                                                               dhcp_client->T1,
+                                                               start_renew, dhcp_client,
+                                                               NULL);
+
+        dhcp_client->t2_timeout = g_rttimeout_add_seconds_full(CLOCK_BOOTTIME_ALARM, G_PRIORITY_HIGH,
+                                        dhcp_client->T2,
+                                        start_rebound, dhcp_client,
+                                                        NULL);
+
+        dhcp_client->lease_timeout= g_rttimeout_add_seconds_full(CLOCK_BOOTTIME_ALARM, G_PRIORITY_HIGH,
+                                        dhcp_client->expire,
+                                        start_expire, dhcp_client,
+                                                        NULL);
+	release_wake(dhcp_client, dhcp_client->T1);
+}
+
+static gboolean restart_dhcp_timeout(gpointer user_data)
+{
+	GDHCPClient *dhcp_client = user_data;
+
+	debug(dhcp_client, "restart DHCP timeout");
+
+	if (dhcp_client->state == REBOOTING) {
+		g_free(dhcp_client->last_address);
+		dhcp_client->last_address = NULL;
+		restart_dhcp(dhcp_client, 0);
+	} else {
+		dhcp_client->ack_retry_times++;
+		restart_dhcp(dhcp_client, dhcp_client->ack_retry_times);
+	}
+	return FALSE;
+}
+
+static char *get_ip(uint32_t ip)
+{
+	struct in_addr addr;
+
+	addr.s_addr = ip;
+
+	return g_strdup(inet_ntoa(addr));
+}
+
+/* get a rough idea of how long an option will be */
+static const uint8_t len_of_option_as_string[] = {
+	[OPTION_IP] = sizeof("255.255.255.255 "),
+	[OPTION_STRING] = 1,
+	[OPTION_U8] = sizeof("255 "),
+	[OPTION_U16] = sizeof("65535 "),
+	[OPTION_U32] = sizeof("4294967295 "),
+};
+
+static int sprint_nip(char *dest, const char *pre, const uint8_t *ip)
+{
+	return sprintf(dest, "%s%u.%u.%u.%u", pre, ip[0], ip[1], ip[2], ip[3]);
+}
+
+/* Create "opt_value1 option_value2 ..." string */
+static char *malloc_option_value_string(uint8_t *option, GDHCPOptionType type)
+{
+	unsigned upper_length;
+	int len, optlen;
+	char *dest, *ret;
+
+	len = option[OPT_LEN - OPT_DATA];
+	type &= OPTION_TYPE_MASK;
+	optlen = dhcp_option_lengths[type];
+	if (optlen == 0)
+		return NULL;
+	upper_length = len_of_option_as_string[type] *
+			((unsigned)len / (unsigned)optlen);
+	dest = ret = g_malloc(upper_length + 1);
+	if (!ret)
+		return NULL;
+
+	while (len >= optlen) {
+		switch (type) {
+		case OPTION_IP:
+			dest += sprint_nip(dest, "", option);
+			break;
+		case OPTION_U16: {
+			uint16_t val_u16 = get_be16(option);
+			dest += sprintf(dest, "%u", val_u16);
+			break;
+		}
+		case OPTION_U32: {
+			uint32_t val_u32 = get_be32(option);
+			dest += sprintf(dest, "%u", val_u32);
+			break;
+		}
+		case OPTION_STRING:
+			memcpy(dest, option, len);
+			dest[len] = '\0';
+			return ret;
+		default:
+			break;
+		}
+		option += optlen;
+		len -= optlen;
+		if (len <= 0)
+			break;
+		*dest++ = ' ';
+		*dest = '\0';
+	}
+
+	return ret;
+}
+
+static GList *get_option_value_list(char *value, GDHCPOptionType type)
+{
+	char *pos = value;
+	GList *list = NULL;
+
+	if (!pos)
+		return NULL;
+
+	if (type == OPTION_STRING)
+		return g_list_append(list, g_strdup(value));
+
+	while ((pos = strchr(pos, ' '))) {
+		*pos = '\0';
+
+		list = g_list_append(list, g_strdup(value));
+
+		value = ++pos;
+	}
+
+	list = g_list_append(list, g_strdup(value));
+
+	return list;
+}
+
+static inline uint32_t get_uint32(unsigned char *value)
+{
+	return value[0] << 24 | value[1] << 16 |
+		value[2] << 8 | value[3];
+}
+
+static inline uint16_t get_uint16(unsigned char *value)
+{
+	return value[0] << 8 | value[1];
+}
+
+static GList *add_prefix(GDHCPClient *dhcp_client, GList *list,
+			struct in6_addr *addr,
+			unsigned char prefixlen, uint32_t preferred,
+			uint32_t valid)
+{
+	GDHCPIAPrefix *ia_prefix;
+
+	ia_prefix = g_try_new(GDHCPIAPrefix, 1);
+	if (!ia_prefix)
+		return list;
+
+	if (dhcp_client->debug_func) {
+		char addr_str[INET6_ADDRSTRLEN + 1];
+		inet_ntop(AF_INET6, addr, addr_str, INET6_ADDRSTRLEN);
+		debug(dhcp_client, "prefix %s/%d preferred %u valid %u",
+			addr_str, prefixlen, preferred, valid);
+	}
+
+	memcpy(&ia_prefix->prefix, addr, sizeof(struct in6_addr));
+	ia_prefix->prefixlen = prefixlen;
+	ia_prefix->preferred = preferred;
+	ia_prefix->valid = valid;
+	ia_prefix->expire = time(NULL) + valid;
+
+	return g_list_prepend(list, ia_prefix);
+}
+
+static GList *get_addresses(GDHCPClient *dhcp_client,
+				int code, int len,
+				unsigned char *value,
+				uint16_t *status)
+{
+	GList *list = NULL;
+	struct in6_addr addr;
+	uint32_t iaid, T1 = 0, T2 = 0, preferred = 0, valid = 0;
+	uint16_t option_len, option_code, st = 0, max_len;
+	int addr_count = 0, prefix_count = 0, i, pos;
+	unsigned char prefixlen;
+	unsigned int shortest_valid = 0;
+	uint8_t *option;
+	char *str;
+
+	if (!value || len < 4)
+		return NULL;
+
+	iaid = get_uint32(&value[0]);
+	if (dhcp_client->iaid != iaid)
+		return NULL;
+
+	if (code == G_DHCPV6_IA_NA || code == G_DHCPV6_IA_PD) {
+		T1 = get_uint32(&value[4]);
+		T2 = get_uint32(&value[8]);
+
+		if (T1 > T2)
+			/* IA_NA: RFC 3315, 22.4 */
+			/* IA_PD: RFC 3633, ch 9 */
+			return NULL;
+
+		pos = 12;
+	} else
+		pos = 4;
+
+	if (len <= pos)
+		return NULL;
+
+	max_len = len - pos;
+
+	debug(dhcp_client, "header %d sub-option max len %d", pos, max_len);
+
+	/* We have more sub-options in this packet. */
+	do {
+		option = dhcpv6_get_sub_option(&value[pos], max_len,
+					&option_code, &option_len);
+
+		debug(dhcp_client, "pos %d option %p code %d len %d",
+			pos, option, option_code, option_len);
+
+		if (!option)
+			break;
+
+		if (pos >= len)
+			break;
+
+		switch (option_code) {
+		case G_DHCPV6_IAADDR:
+			i = 0;
+			memcpy(&addr, &option[0], sizeof(addr));
+			i += sizeof(addr);
+			preferred = get_uint32(&option[i]);
+			i += 4;
+			valid = get_uint32(&option[i]);
+
+			addr_count++;
+			break;
+
+		case G_DHCPV6_STATUS_CODE:
+			st = get_uint16(&option[0]);
+			debug(dhcp_client, "error code %d", st);
+			if (option_len > 2) {
+				str = g_strndup((gchar *)&option[2],
+						option_len - 2);
+				debug(dhcp_client, "error text: %s", str);
+				g_free(str);
+			}
+
+			*status = st;
+			break;
+
+		case G_DHCPV6_IA_PREFIX:
+			i = 0;
+			preferred = get_uint32(&option[i]);
+			i += 4;
+			valid = get_uint32(&option[i]);
+			i += 4;
+			prefixlen = option[i];
+			i += 1;
+			memcpy(&addr, &option[i], sizeof(addr));
+			i += sizeof(addr);
+			if (preferred < valid) {
+				/* RFC 3633, ch 10 */
+				list = add_prefix(dhcp_client, list, &addr,
+						prefixlen, preferred, valid);
+				if (shortest_valid > valid)
+					shortest_valid = valid;
+				prefix_count++;
+			}
+			break;
+		}
+
+		pos += 2 + 2 + option_len;
+
+	} while (pos < len);
+
+	if (addr_count > 0 && st == 0) {
+		/* We only support one address atm */
+		char addr_str[INET6_ADDRSTRLEN + 1];
+
+		if (preferred > valid)
+			/* RFC 3315, 22.6 */
+			return NULL;
+
+		dhcp_client->T1 = T1;
+		dhcp_client->T2 = T2;
+
+		inet_ntop(AF_INET6, &addr, addr_str, INET6_ADDRSTRLEN);
+		debug(dhcp_client, "address count %d addr %s T1 %u T2 %u",
+			addr_count, addr_str, T1, T2);
+
+		list = g_list_append(list, g_strdup(addr_str));
+
+		if (code == G_DHCPV6_IA_NA)
+			memcpy(&dhcp_client->ia_na, &addr,
+						sizeof(struct in6_addr));
+		else
+			memcpy(&dhcp_client->ia_ta, &addr,
+						sizeof(struct in6_addr));
+
+		if (valid != dhcp_client->expire)
+			dhcp_client->expire = valid;
+	}
+
+	if (prefix_count > 0 && list) {
+		/*
+		 * This means we have a list of prefixes to delegate.
+		 */
+		list = g_list_reverse(list);
+
+		debug(dhcp_client, "prefix count %d T1 %u T2 %u",
+			prefix_count, T1, T2);
+
+		dhcp_client->T1 = T1;
+		dhcp_client->T2 = T2;
+
+		dhcp_client->expire = shortest_valid;
+	}
+
+	if (status && *status != 0)
+		debug(dhcp_client, "status %d", *status);
+
+	return list;
+}
+
+static GList *get_domains(int maxlen, unsigned char *value)
+
+{
+	GList *list = NULL;
+	int pos = 0;
+	unsigned char *c;
+	char dns_name[NS_MAXDNAME + 1];
+
+	if (!value || maxlen < 3)
+		return NULL;
+
+	while (pos < maxlen) {
+		strncpy(dns_name, (char *)&value[pos], NS_MAXDNAME);
+
+		c = (unsigned char *)dns_name;
+		while (c && *c) {
+			int jump;
+			jump = *c;
+			*c = '.';
+			c += jump + 1;
+		}
+		list = g_list_prepend(list, g_strdup(&dns_name[1]));
+		pos += (char *)c - dns_name + 1;
+	}
+
+	return g_list_reverse(list);
+}
+
+static GList *get_dhcpv6_option_value_list(GDHCPClient *dhcp_client,
+					int code, int len,
+					unsigned char *value,
+					uint16_t *status)
+{
+	GList *list = NULL;
+	char *str;
+	int i;
+
+	if (!value)
+		return NULL;
+
+	switch (code) {
+	case G_DHCPV6_DNS_SERVERS:	/* RFC 3646, chapter 3 */
+	case G_DHCPV6_SNTP_SERVERS:	/* RFC 4075, chapter 4 */
+		if (len % 16) {
+			debug(dhcp_client,
+				"%s server list length (%d) is invalid",
+				code == G_DHCPV6_DNS_SERVERS ? "DNS" : "SNTP",
+				len);
+			return NULL;
+		}
+		for (i = 0; i < len; i += 16) {
+
+			str = g_try_malloc0(INET6_ADDRSTRLEN+1);
+			if (!str)
+				return list;
+
+			if (!inet_ntop(AF_INET6, &value[i], str,
+					INET6_ADDRSTRLEN))
+				g_free(str);
+			else
+				list = g_list_append(list, str);
+		}
+		break;
+
+	case G_DHCPV6_IA_NA:		/* RFC 3315, chapter 22.4 */
+	case G_DHCPV6_IA_TA:		/* RFC 3315, chapter 22.5 */
+	case G_DHCPV6_IA_PD:		/* RFC 3633, chapter 9 */
+		list = get_addresses(dhcp_client, code, len, value, status);
+		break;
+
+	case G_DHCPV6_DOMAIN_LIST:
+		list = get_domains(len, value);
+		break;
+
+	default:
+		break;
+	}
+
+	return list;
+}
+
+static void get_dhcpv6_request(GDHCPClient *dhcp_client,
+				struct dhcpv6_packet *packet,
+				uint16_t pkt_len, uint16_t *status)
+{
+	GList *list, *value_list;
+	uint8_t *option;
+	uint16_t code;
+	uint16_t option_len;
+
+	for (list = dhcp_client->request_list; list; list = list->next) {
+		code = (uint16_t) GPOINTER_TO_INT(list->data);
+
+		option = dhcpv6_get_option(packet, pkt_len, code, &option_len,
+						NULL);
+		if (!option) {
+			g_hash_table_remove(dhcp_client->code_value_hash,
+						GINT_TO_POINTER((int) code));
+			continue;
+		}
+
+		value_list = get_dhcpv6_option_value_list(dhcp_client, code,
+						option_len, option, status);
+
+		debug(dhcp_client, "code %d %p len %d list %p", code, option,
+			option_len, value_list);
+
+		if (!value_list)
+			g_hash_table_remove(dhcp_client->code_value_hash,
+						GINT_TO_POINTER((int) code));
+		else
+			g_hash_table_insert(dhcp_client->code_value_hash,
+				GINT_TO_POINTER((int) code), value_list);
+	}
+}
+
+static void get_request(GDHCPClient *dhcp_client, struct dhcp_packet *packet)
+{
+	GDHCPOptionType type;
+	GList *list, *value_list;
+	char *option_value;
+	uint8_t *option;
+	uint8_t code;
+
+	for (list = dhcp_client->request_list; list; list = list->next) {
+		code = (uint8_t) GPOINTER_TO_INT(list->data);
+
+		option = dhcp_get_option(packet, code);
+		if (!option) {
+			g_hash_table_remove(dhcp_client->code_value_hash,
+						GINT_TO_POINTER((int) code));
+			continue;
+		}
+
+		type =  dhcp_get_code_type(code);
+
+		option_value = malloc_option_value_string(option, type);
+		if (!option_value)
+			g_hash_table_remove(dhcp_client->code_value_hash,
+						GINT_TO_POINTER((int) code));
+
+		value_list = get_option_value_list(option_value, type);
+
+		g_free(option_value);
+
+		if (!value_list)
+			g_hash_table_remove(dhcp_client->code_value_hash,
+						GINT_TO_POINTER((int) code));
+		else
+			g_hash_table_insert(dhcp_client->code_value_hash,
+				GINT_TO_POINTER((int) code), value_list);
+	}
+}
+
+static gboolean listener_event(GIOChannel *channel, GIOCondition condition,
+							gpointer user_data)
+{
+	GDHCPClient *dhcp_client = user_data;
+	struct sockaddr_in dst_addr = { 0 };
+	struct dhcp_packet packet;
+	struct dhcpv6_packet *packet6 = NULL;
+	uint8_t *message_type = NULL, *client_id = NULL, *option,
+		*server_id = NULL;
+	uint16_t option_len = 0, status = 0;
+    uint32_t xid = 0;
+    gpointer pkt;
+	unsigned char buf[MAX_DHCPV6_PKT_SIZE];
+	uint16_t pkt_len = 0;
+	int count;
+	int re;
+	const char *p = NULL;
+	struct in_addr server, request;
+	char serverbuf[INET_ADDRSTRLEN], requestbuf[INET_ADDRSTRLEN];
+
+	if (condition & (G_IO_NVAL | G_IO_ERR | G_IO_HUP)) {
+		dhcp_client->listener_watch = 0;
+		return FALSE;
+	}
+
+	if (dhcp_client->listen_mode == L_NONE)
+		return FALSE;
+
+	pkt = &packet;
+
+	dhcp_client->status_code = 0;
+
+	if (dhcp_client->listen_mode == L2) {
+		re = dhcp_recv_l2_packet(&packet,
+					dhcp_client->listener_sockfd,
+					&dst_addr);
+		xid = packet.xid;
+	} else if (dhcp_client->listen_mode == L3) {
+		if (dhcp_client->type == G_DHCP_IPV6) {
+			re = dhcpv6_recv_l3_packet(&packet6, buf, sizeof(buf),
+						dhcp_client->listener_sockfd);
+			pkt_len = re;
+			pkt = packet6;
+			xid = packet6->transaction_id[0] << 16 |
+			packet6->transaction_id[1] << 8 |
+			packet6->transaction_id[2];
+
+		} else {
+			re = dhcp_recv_l3_packet(&packet,
+						dhcp_client->listener_sockfd);
+			xid = packet.xid;
+		}
+	} else if (dhcp_client->listen_mode == L_ARP) {
+		ipv4ll_recv_arp_packet(dhcp_client);
+		return TRUE;
+	} else
+		re = -EIO;
+
+	if (re < 0)
+		return TRUE;
+
+	if (!check_package_owner(dhcp_client, pkt))
+		return TRUE;
+
+	if (dhcp_client->type == G_DHCP_IPV6) {
+		if (!packet6)
+			return TRUE;
+
+		count = 0;
+		client_id = dhcpv6_get_option(packet6, pkt_len,
+				G_DHCPV6_CLIENTID, &option_len,	&count);
+
+		if (!client_id || count == 0 || option_len == 0 ||
+				memcmp(dhcp_client->duid, client_id,
+					dhcp_client->duid_len) != 0) {
+			debug(dhcp_client,
+				"client duid error, discarding msg %p/%d/%d",
+				client_id, option_len, count);
+			return TRUE;
+		}
+
+		option = dhcpv6_get_option(packet6, pkt_len,
+				G_DHCPV6_STATUS_CODE, &option_len, NULL);
+		if (option != 0 && option_len > 0) {
+			status = option[0]<<8 | option[1];
+			if (status != 0) {
+				debug(dhcp_client, "error code %d", status);
+				if (option_len > 2) {
+					gchar *txt = g_strndup(
+						(gchar *)&option[2],
+						option_len - 2);
+					debug(dhcp_client, "error text: %s",
+						txt);
+					g_free(txt);
+				}
+			}
+			dhcp_client->status_code = status;
+		}
+	} else {
+		message_type = dhcp_get_option(&packet, DHCP_MESSAGE_TYPE);
+		if (!message_type)
+			return TRUE;
+	}
+
+	if (!message_type && !client_id)
+		/* No message type / client id option, ignore package */
+		return TRUE;
+
+	debug(dhcp_client, "received DHCP packet xid 0x%04x "
+		"(current state %d)", ntohl(xid), dhcp_client->state);
+
+	if (message_type) {
+		p = get_message_type(*message_type);
+
+		debug(dhcp_client, "received DHCP%s (%#02x) packet "
+			"(current state %d)",
+			p,
+			*message_type,
+			dhcp_client->state);
+	} else {
+		debug(dhcp_client, "received DHCPv6 packet "
+			"(current state %d)",
+			dhcp_client->state);
+	}
+
+	switch (dhcp_client->state) {
+	case INIT_SELECTING:
+		if (message_type == NULL ) {
+			debug(dhcp_client, "INIT_SELECTING but message_type is NULL" );
+			return TRUE;
+		}
+		if (*message_type != DHCPOFFER)
+			return TRUE;
+
+		remove_timeouts(dhcp_client);
+		dhcp_client->timeout = 0;
+		dhcp_client->retry_times = 0;
+
+		option = dhcp_get_option(&packet, DHCP_SERVER_ID);
+		dhcp_client->server_ip = get_be32(option);
+		dhcp_client->requested_ip = ntohl(packet.yiaddr);
+
+		dhcp_client->state = REQUESTING;
+
+		server.s_addr = dhcp_client->server_ip;
+		request.s_addr = dhcp_client->requested_ip;
+
+		debug(dhcp_client, "init ip %s -> %sadding broadcast flag",
+			inet_ntoa(dst_addr.sin_addr),
+			dhcp_client->request_bcast ? "" : "not ");
+		
+        server.s_addr = dhcp_client->server_ip;
+		request.s_addr = dhcp_client->requested_ip;
+
+		debug(dhcp_client, "%s of %s from %s",
+			p,
+			inet_ntop(AF_INET, &request,
+				  requestbuf, sizeof(requestbuf)),
+			inet_ntop(AF_INET, &server,
+				  serverbuf, sizeof(serverbuf)));
+
+		start_request(dhcp_client);
+
+		return TRUE;
+	case REBOOTING:
+		if (dst_addr.sin_addr.s_addr == INADDR_BROADCAST)
+			dhcp_client->request_bcast = true;
+		else
+			dhcp_client->request_bcast = false;
+
+		debug(dhcp_client, "ip %s -> %sadding broadcast flag",
+			inet_ntoa(dst_addr.sin_addr),
+			dhcp_client->request_bcast ? "" : "not ");
+		/* fall through */
+	case REQUESTING:
+	case RENEWING:
+	case REBINDING:
+		if (message_type == NULL ) {
+			debug(dhcp_client, "REQUESTING/RENEWING/REBINDING/REBOOTING but message_type is NULL" );
+			return TRUE;
+		}
+		if (*message_type == DHCPACK) {
+			dhcp_client->retry_times = 0;
+
+			remove_timeouts(dhcp_client);
+
+			dhcp_client->lease_seconds = get_lease(dhcp_client, &packet);
+
+			get_request(dhcp_client, &packet);
+
+			switch_listening_mode(dhcp_client, L_NONE);
+
+			g_free(dhcp_client->assigned_ip);
+			dhcp_client->assigned_ip = get_ip(packet.yiaddr);
+
+			if (dhcp_client->state == REBOOTING) {
+				option = dhcp_get_option(&packet,
+							DHCP_SERVER_ID);
+				dhcp_client->server_ip = get_be32(option);
+			}
+			request.s_addr = packet.yiaddr;
+			server.s_addr = dhcp_client->server_ip;
+
+			debug(dhcp_client, "%s of %s from %s",
+				p,
+				inet_ntop(AF_INET, &request,
+					  requestbuf, sizeof(requestbuf)),
+				inet_ntop(AF_INET, &server,
+					  serverbuf, sizeof(serverbuf)));
+
+			/* Address should be set up here */
+			if (dhcp_client->lease_available_cb)
+				dhcp_client->lease_available_cb(dhcp_client,
+					dhcp_client->lease_available_data);
+
+			start_bound(dhcp_client);
+		} else if (*message_type == DHCPNAK) {
+			dhcp_client->retry_times = 0;
+
+			remove_timeouts(dhcp_client);
+
+			dhcp_client->timeout = g_rttimeout_add_seconds_full(CLOCK_BOOTTIME_ALARM,
+							G_PRIORITY_HIGH, 3,
+							restart_dhcp_timeout,
+							dhcp_client,
+							NULL);
+		}
+
+		break;
+	case SOLICITATION:
+		if (dhcp_client->type != G_DHCP_IPV6)
+			return TRUE;
+
+		if (packet6->message != DHCPV6_REPLY &&
+				packet6->message != DHCPV6_ADVERTISE)
+			return TRUE;
+
+		count = 0;
+		server_id = dhcpv6_get_option(packet6, pkt_len,
+				G_DHCPV6_SERVERID, &option_len,	&count);
+		if (!server_id || count != 1 || option_len == 0) {
+			/* RFC 3315, 15.10 */
+			debug(dhcp_client,
+				"server duid error, discarding msg %p/%d/%d",
+				server_id, option_len, count);
+			return TRUE;
+		}
+		dhcp_client->server_duid = g_try_malloc(option_len);
+		if (!dhcp_client->server_duid)
+			return TRUE;
+		memcpy(dhcp_client->server_duid, server_id, option_len);
+		dhcp_client->server_duid_len = option_len;
+
+		if (packet6->message == DHCPV6_REPLY) {
+			uint8_t *rapid_commit;
+			count = 0;
+			option_len = 0;
+			rapid_commit = dhcpv6_get_option(packet6, pkt_len,
+							G_DHCPV6_RAPID_COMMIT,
+							&option_len, &count);
+			if (!rapid_commit || option_len != 0 ||
+								count != 1)
+				/* RFC 3315, 17.1.4 */
+				return TRUE;
+		}
+
+		switch_listening_mode(dhcp_client, L_NONE);
+
+		if (dhcp_client->status_code == 0)
+			get_dhcpv6_request(dhcp_client, packet6, pkt_len,
+					&dhcp_client->status_code);
+
+		if (packet6->message == DHCPV6_ADVERTISE) {
+			if (dhcp_client->advertise_cb)
+				dhcp_client->advertise_cb(dhcp_client,
+						dhcp_client->advertise_data);
+			return TRUE;
+		}
+
+		if (dhcp_client->solicitation_cb) {
+			/*
+			 * The dhcp_client might not be valid after the
+			 * callback call so just return immediately.
+			 */
+			dhcp_client->solicitation_cb(dhcp_client,
+					dhcp_client->solicitation_data);
+			return TRUE;
+		}
+		break;
+	case REBIND:
+		if (dhcp_client->type != G_DHCP_IPV6)
+			return TRUE;
+
+		server_id = dhcpv6_get_option(packet6, pkt_len,
+				G_DHCPV6_SERVERID, &option_len,	&count);
+		if (!dhcp_client->server_duid && server_id &&
+								count == 1) {
+			/*
+			 * If we do not have server duid yet, then get it now.
+			 * Prefix delegation renew support needs it.
+			 */
+			dhcp_client->server_duid = g_try_malloc(option_len);
+			if (!dhcp_client->server_duid)
+				return TRUE;
+			memcpy(dhcp_client->server_duid, server_id, option_len);
+			dhcp_client->server_duid_len = option_len;
+		}
+		/* fall through */
+	case INFORMATION_REQ:
+	case REQUEST:
+	case RENEW:
+	case RELEASE:
+	case CONFIRM:
+	case DECLINE:
+		if (dhcp_client->type != G_DHCP_IPV6)
+			return TRUE;
+
+		if (packet6->message != DHCPV6_REPLY)
+			return TRUE;
+
+		count = 0;
+		option_len = 0;
+		server_id = dhcpv6_get_option(packet6, pkt_len,
+				G_DHCPV6_SERVERID, &option_len, &count);
+		if (!server_id || count != 1 || option_len == 0 ||
+				(dhcp_client->server_duid_len > 0 &&
+				memcmp(dhcp_client->server_duid, server_id,
+					dhcp_client->server_duid_len) != 0)) {
+			/* RFC 3315, 15.10 */
+			debug(dhcp_client,
+				"server duid error, discarding msg %p/%d/%d",
+				server_id, option_len, count);
+			return TRUE;
+		}
+
+		switch_listening_mode(dhcp_client, L_NONE);
+
+		get_dhcpv6_request(dhcp_client, packet6, pkt_len,
+						&dhcp_client->status_code);
+
+		if (dhcp_client->information_req_cb) {
+			/*
+			 * The dhcp_client might not be valid after the
+			 * callback call so just return immediately.
+			 */
+			dhcp_client->information_req_cb(dhcp_client,
+					dhcp_client->information_req_data);
+			return TRUE;
+		}
+		if (dhcp_client->request_cb) {
+			dhcp_client->request_cb(dhcp_client,
+					dhcp_client->request_data);
+			return TRUE;
+		}
+		if (dhcp_client->renew_cb) {
+			dhcp_client->renew_cb(dhcp_client,
+					dhcp_client->renew_data);
+			return TRUE;
+		}
+		if (dhcp_client->rebind_cb) {
+			dhcp_client->rebind_cb(dhcp_client,
+					dhcp_client->rebind_data);
+			return TRUE;
+		}
+		if (dhcp_client->release_cb) {
+			dhcp_client->release_cb(dhcp_client,
+					dhcp_client->release_data);
+			return TRUE;
+		}
+		if (dhcp_client->decline_cb) {
+			dhcp_client->decline_cb(dhcp_client,
+					dhcp_client->decline_data);
+			return TRUE;
+		}
+		if (dhcp_client->confirm_cb) {
+			count = 0;
+			server_id = dhcpv6_get_option(packet6, pkt_len,
+						G_DHCPV6_SERVERID, &option_len,
+						&count);
+			if (!server_id || count != 1 ||
+							option_len == 0) {
+				/* RFC 3315, 15.10 */
+				debug(dhcp_client,
+					"confirm server duid error, "
+					"discarding msg %p/%d/%d",
+					server_id, option_len, count);
+				return TRUE;
+			}
+			dhcp_client->server_duid = g_try_malloc(option_len);
+			if (!dhcp_client->server_duid)
+				return TRUE;
+			memcpy(dhcp_client->server_duid, server_id, option_len);
+			dhcp_client->server_duid_len = option_len;
+
+			dhcp_client->confirm_cb(dhcp_client,
+						dhcp_client->confirm_data);
+			return TRUE;
+		}
+		break;
+	default:
+		break;
+	}
+
+	if (message_type) {
+		debug(dhcp_client, "processed DHCP%s (%#02x) packet (new state %d)",
+			p,
+			*message_type,
+			dhcp_client->state);
+	} else {
+		debug(dhcp_client, "processed DHCPv6 packet (new state %d)",
+			dhcp_client->state);
+	}
+	return TRUE;
+}
+
+static gboolean discover_timeout(gpointer user_data)
+{
+	GDHCPClient *dhcp_client = user_data;
+
+	dhcp_client->retry_times++;
+
+	/*
+	 * We do not send the REQUESTED IP option if we are retrying because
+	 * if the server is non-authoritative it will ignore the request if the
+	 * option is present.
+	 */
+	g_dhcp_client_start(dhcp_client, NULL);
+
+	return FALSE;
+}
+
+static gboolean reboot_timeout(gpointer user_data)
+{
+	GDHCPClient *dhcp_client = user_data;
+	dhcp_client->retry_times = 0;
+	dhcp_client->requested_ip = 0;
+	dhcp_client->state = INIT_SELECTING;
+	/*
+	 * We do not send the REQUESTED IP option because the server didn't
+	 * respond when we send DHCPREQUEST with the REQUESTED IP option in
+	 * init-reboot state
+	 */
+	g_dhcp_client_start(dhcp_client, NULL);
+
+	return FALSE;
+}
+
+static gboolean ipv4ll_defend_timeout(gpointer dhcp_data)
+{
+	GDHCPClient *dhcp_client = dhcp_data;
+
+	debug(dhcp_client, "back to MONITOR mode");
+
+	dhcp_client->conflicts = 0;
+	dhcp_client->state = IPV4LL_MONITOR;
+
+	return FALSE;
+}
+
+static gboolean ipv4ll_announce_timeout(gpointer dhcp_data)
+{
+	GDHCPClient *dhcp_client = dhcp_data;
+	uint32_t ip;
+
+	debug(dhcp_client, "request timeout (retries %d)",
+	       dhcp_client->retry_times);
+
+	if (dhcp_client->retry_times != ANNOUNCE_NUM) {
+		dhcp_client->retry_times++;
+		send_announce_packet(dhcp_client);
+		return FALSE;
+	}
+
+	ip = htonl(dhcp_client->requested_ip);
+	debug(dhcp_client, "switching to monitor mode");
+	dhcp_client->state = IPV4LL_MONITOR;
+	dhcp_client->assigned_ip = get_ip(ip);
+
+	if (dhcp_client->ipv4ll_available_cb)
+		dhcp_client->ipv4ll_available_cb(dhcp_client,
+					dhcp_client->ipv4ll_available_data);
+	dhcp_client->conflicts = 0;
+
+	return FALSE;
+}
+
+static gboolean ipv4ll_probe_timeout(gpointer dhcp_data)
+{
+
+	GDHCPClient *dhcp_client = dhcp_data;
+
+	debug(dhcp_client, "IPV4LL probe timeout (retries %d)",
+	       dhcp_client->retry_times);
+
+	if (dhcp_client->retry_times == PROBE_NUM) {
+		dhcp_client->state = IPV4LL_ANNOUNCE;
+		dhcp_client->retry_times = 0;
+
+		dhcp_client->retry_times++;
+		send_announce_packet(dhcp_client);
+		return FALSE;
+	}
+	dhcp_client->retry_times++;
+	send_probe_packet(dhcp_client);
+
+	return FALSE;
+}
+
+int g_dhcp_client_start(GDHCPClient *dhcp_client, const char *last_address)
+{
+	int re;
+	uint32_t addr;
+	uint64_t rand;
+
+	if (dhcp_client->type == G_DHCP_IPV6) {
+		if (dhcp_client->information_req_cb) {
+			dhcp_client->state = INFORMATION_REQ;
+			re = switch_listening_mode(dhcp_client, L3);
+			if (re != 0) {
+				switch_listening_mode(dhcp_client, L_NONE);
+				dhcp_client->state = 0;
+				return re;
+			}
+			send_information_req(dhcp_client);
+
+		} else if (dhcp_client->solicitation_cb) {
+			dhcp_client->state = SOLICITATION;
+			re = switch_listening_mode(dhcp_client, L3);
+			if (re != 0) {
+				switch_listening_mode(dhcp_client, L_NONE);
+				dhcp_client->state = 0;
+				return re;
+			}
+			send_solicitation(dhcp_client);
+
+		} else if (dhcp_client->request_cb) {
+			dhcp_client->state = REQUEST;
+			re = switch_listening_mode(dhcp_client, L3);
+			if (re != 0) {
+				switch_listening_mode(dhcp_client, L_NONE);
+				dhcp_client->state = 0;
+				return re;
+			}
+			send_dhcpv6_request(dhcp_client);
+
+		} else if (dhcp_client->confirm_cb) {
+			dhcp_client->state = CONFIRM;
+			re = switch_listening_mode(dhcp_client, L3);
+			if (re != 0) {
+				switch_listening_mode(dhcp_client, L_NONE);
+				dhcp_client->state = 0;
+				return re;
+			}
+			send_dhcpv6_confirm(dhcp_client);
+
+		} else if (dhcp_client->renew_cb) {
+			dhcp_client->state = RENEW;
+			re = switch_listening_mode(dhcp_client, L3);
+			if (re != 0) {
+				switch_listening_mode(dhcp_client, L_NONE);
+				dhcp_client->state = 0;
+				return re;
+			}
+			send_dhcpv6_renew(dhcp_client);
+
+		} else if (dhcp_client->rebind_cb) {
+			dhcp_client->state = REBIND;
+			re = switch_listening_mode(dhcp_client, L3);
+			if (re != 0) {
+				switch_listening_mode(dhcp_client, L_NONE);
+				dhcp_client->state = 0;
+				return re;
+			}
+			send_dhcpv6_rebind(dhcp_client);
+
+		} else if (dhcp_client->release_cb) {
+			dhcp_client->state = RENEW;
+			re = switch_listening_mode(dhcp_client, L3);
+			if (re != 0) {
+				switch_listening_mode(dhcp_client, L_NONE);
+				dhcp_client->state = 0;
+				return re;
+			}
+			send_dhcpv6_release(dhcp_client);
+		} else if (dhcp_client->decline_cb) {
+			dhcp_client->state = DECLINE;
+			re = switch_listening_mode(dhcp_client, L3);
+			if (re != 0) {
+				switch_listening_mode(dhcp_client, L_NONE);
+				dhcp_client->state = 0;
+				return re;
+			}
+			send_dhcpv6_decline(dhcp_client);
+		}
+
+		return 0;
+	}
+
+	if (dhcp_client->type == G_DHCP_IPV4LL) {
+		dhcp_client->state = INIT_SELECTING;
+		ipv4ll_start(dhcp_client);
+		return 0;
+	}
+
+	if (dhcp_client->retry_times == DISCOVER_RETRIES) {
+		if (dhcp_client->no_lease_cb)
+			dhcp_client->no_lease_cb(dhcp_client,
+						dhcp_client->no_lease_data);
+		dhcp_client->retry_times = 0;
+		return 0;
+	}
+
+	if (dhcp_client->retry_times == 0) {
+		g_free(dhcp_client->assigned_ip);
+		dhcp_client->assigned_ip = NULL;
+
+		dhcp_client->state = INIT_SELECTING;
+		re = switch_listening_mode(dhcp_client, L2);
+		if (re != 0)
+			return re;
+
+		dhcp_get_random(&rand);
+		dhcp_client->xid = rand;
+		dhcp_client->start = time(NULL);
+	}
+
+	if (!last_address) {
+		addr = 0;
+	} else {
+		addr = ntohl(inet_addr(last_address));
+		if (addr == 0xFFFFFFFF) {
+			addr = 0;
+		} else {
+			g_free(dhcp_client->last_address);
+			dhcp_client->last_address = g_strdup(last_address);
+		}
+	}
+
+	if ((addr != 0) && (dhcp_client->type != G_DHCP_IPV4LL)) {
+		debug(dhcp_client, "DHCP client start with state init_reboot");
+		dhcp_client->requested_ip = addr;
+		dhcp_client->state = REBOOTING;
+		send_request(dhcp_client);
+
+		dhcp_client->timeout = g_rttimeout_add_seconds_full(CLOCK_BOOTTIME_ALARM,
+								G_PRIORITY_HIGH,
+								REQUEST_TIMEOUT,
+								reboot_timeout,
+								dhcp_client,
+								NULL);
+		return 0;
+	}
+	send_discover(dhcp_client, addr);
+
+	dhcp_client->timeout = g_rttimeout_add_seconds_full(CLOCK_BOOTTIME_ALARM, G_PRIORITY_HIGH,
+							DISCOVER_TIMEOUT,
+							discover_timeout,
+							dhcp_client,
+							NULL);
+	return 0;
+}
+
+void g_dhcp_client_stop(GDHCPClient *dhcp_client)
+{
+	switch_listening_mode(dhcp_client, L_NONE);
+
+	if (dhcp_client->state == BOUND ||
+			dhcp_client->state == RENEWING ||
+				dhcp_client->state == REBINDING)
+		send_release(dhcp_client, dhcp_client->server_ip,
+					dhcp_client->requested_ip);
+
+	remove_timeouts(dhcp_client);
+
+	if (dhcp_client->listener_watch > 0) {
+		g_source_remove(dhcp_client->listener_watch);
+		dhcp_client->listener_watch = 0;
+	}
+
+	dhcp_client->retry_times = 0;
+	dhcp_client->ack_retry_times = 0;
+
+	dhcp_client->requested_ip = 0;
+	dhcp_client->state = RELEASED;
+	dhcp_client->lease_seconds = 0;
+	dhcp_client->request_bcast = false;
+}
+
+GList *g_dhcp_client_get_option(GDHCPClient *dhcp_client,
+					unsigned char option_code)
+{
+	return g_hash_table_lookup(dhcp_client->code_value_hash,
+					GINT_TO_POINTER((int) option_code));
+}
+
+void g_dhcp_client_register_event(GDHCPClient *dhcp_client,
+					GDHCPClientEvent event,
+					GDHCPClientEventFunc func,
+							gpointer data)
+{
+	switch (event) {
+	case G_DHCP_CLIENT_EVENT_LEASE_AVAILABLE:
+		dhcp_client->lease_available_cb = func;
+		dhcp_client->lease_available_data = data;
+		return;
+	case G_DHCP_CLIENT_EVENT_IPV4LL_AVAILABLE:
+		if (dhcp_client->type == G_DHCP_IPV6)
+			return;
+		dhcp_client->ipv4ll_available_cb = func;
+		dhcp_client->ipv4ll_available_data = data;
+		return;
+	case G_DHCP_CLIENT_EVENT_NO_LEASE:
+		dhcp_client->no_lease_cb = func;
+		dhcp_client->no_lease_data = data;
+		return;
+	case G_DHCP_CLIENT_EVENT_LEASE_LOST:
+		dhcp_client->lease_lost_cb = func;
+		dhcp_client->lease_lost_data = data;
+		return;
+	case G_DHCP_CLIENT_EVENT_IPV4LL_LOST:
+		if (dhcp_client->type == G_DHCP_IPV6)
+			return;
+		dhcp_client->ipv4ll_lost_cb = func;
+		dhcp_client->ipv4ll_lost_data = data;
+		return;
+	case G_DHCP_CLIENT_EVENT_ADDRESS_CONFLICT:
+		dhcp_client->address_conflict_cb = func;
+		dhcp_client->address_conflict_data = data;
+		return;
+	case G_DHCP_CLIENT_EVENT_INFORMATION_REQ:
+		if (dhcp_client->type != G_DHCP_IPV6)
+			return;
+		dhcp_client->information_req_cb = func;
+		dhcp_client->information_req_data = data;
+		return;
+	case G_DHCP_CLIENT_EVENT_SOLICITATION:
+		if (dhcp_client->type != G_DHCP_IPV6)
+			return;
+		dhcp_client->solicitation_cb = func;
+		dhcp_client->solicitation_data = data;
+		return;
+	case G_DHCP_CLIENT_EVENT_ADVERTISE:
+		if (dhcp_client->type != G_DHCP_IPV6)
+			return;
+		dhcp_client->advertise_cb = func;
+		dhcp_client->advertise_data = data;
+		return;
+	case G_DHCP_CLIENT_EVENT_REQUEST:
+		if (dhcp_client->type != G_DHCP_IPV6)
+			return;
+		dhcp_client->request_cb = func;
+		dhcp_client->request_data = data;
+		return;
+	case G_DHCP_CLIENT_EVENT_RENEW:
+		if (dhcp_client->type != G_DHCP_IPV6)
+			return;
+		dhcp_client->renew_cb = func;
+		dhcp_client->renew_data = data;
+		return;
+	case G_DHCP_CLIENT_EVENT_REBIND:
+		if (dhcp_client->type != G_DHCP_IPV6)
+			return;
+		dhcp_client->rebind_cb = func;
+		dhcp_client->rebind_data = data;
+		return;
+	case G_DHCP_CLIENT_EVENT_RELEASE:
+		if (dhcp_client->type != G_DHCP_IPV6)
+			return;
+		dhcp_client->release_cb = func;
+		dhcp_client->release_data = data;
+		return;
+	case G_DHCP_CLIENT_EVENT_CONFIRM:
+		if (dhcp_client->type != G_DHCP_IPV6)
+			return;
+		dhcp_client->confirm_cb = func;
+		dhcp_client->confirm_data = data;
+		return;
+	case G_DHCP_CLIENT_EVENT_DECLINE:
+		if (dhcp_client->type != G_DHCP_IPV6)
+			return;
+		dhcp_client->decline_cb = func;
+		dhcp_client->decline_data = data;
+		return;
+	case G_DHCP_CLIENT_EVENT_WAKE_EVENT:
+		dhcp_client->wake_event_cb = func;
+		dhcp_client->wake_event_data= data;
+		return;
+	}
+}
+
+int g_dhcp_client_get_index(GDHCPClient *dhcp_client)
+{
+	return dhcp_client->ifindex;
+}
+
+char *g_dhcp_client_get_server_address(GDHCPClient *dhcp_client)
+{
+	if (!dhcp_client)
+		return NULL;
+
+	return get_ip(dhcp_client->server_ip);
+}
+
+char *g_dhcp_client_get_address(GDHCPClient *dhcp_client)
+{
+	if (!dhcp_client)
+		return NULL;
+
+	return g_strdup(dhcp_client->assigned_ip);
+}
+
+char *g_dhcp_client_get_netmask(GDHCPClient *dhcp_client)
+{
+	GList *option = NULL;
+
+	if (dhcp_client->type == G_DHCP_IPV6)
+		return NULL;
+
+	switch (dhcp_client->state) {
+	case IPV4LL_DEFEND:
+	case IPV4LL_MONITOR:
+		return g_strdup("255.255.0.0");
+	case BOUND:
+	case RENEWING:
+	case REBINDING:
+		option = g_dhcp_client_get_option(dhcp_client, G_DHCP_SUBNET);
+		if (option)
+			return g_strdup(option->data);
+	case INIT_SELECTING:
+	case REBOOTING:
+	case REQUESTING:
+	case RELEASED:
+	case IPV4LL_PROBE:
+	case IPV4LL_ANNOUNCE:
+	case INFORMATION_REQ:
+	case SOLICITATION:
+	case REQUEST:
+	case CONFIRM:
+	case RENEW:
+	case REBIND:
+	case RELEASE:
+	case DECLINE:
+		break;
+	}
+	return NULL;
+}
+
+GDHCPClientError g_dhcp_client_set_request(GDHCPClient *dhcp_client,
+						unsigned int option_code)
+{
+	if (!g_list_find(dhcp_client->request_list,
+				GINT_TO_POINTER((int)option_code)))
+		dhcp_client->request_list = g_list_prepend(
+					dhcp_client->request_list,
+					(GINT_TO_POINTER((int) option_code)));
+
+	return G_DHCP_CLIENT_ERROR_NONE;
+}
+
+void g_dhcp_client_clear_requests(GDHCPClient *dhcp_client)
+{
+	g_list_free(dhcp_client->request_list);
+	dhcp_client->request_list = NULL;
+}
+
+void g_dhcp_client_clear_values(GDHCPClient *dhcp_client)
+{
+	g_hash_table_remove_all(dhcp_client->send_value_hash);
+}
+
+static uint8_t *alloc_dhcp_option(int code, const uint8_t *data, unsigned size)
+{
+	uint8_t *storage;
+
+	storage = g_try_malloc(size + OPT_DATA);
+	if (!storage)
+		return NULL;
+
+	storage[OPT_CODE] = code;
+	storage[OPT_LEN] = size;
+	memcpy(&storage[OPT_DATA], data, size);
+
+	return storage;
+}
+
+static uint8_t *alloc_dhcp_data_option(int code, const uint8_t *data,
+					unsigned size)
+{
+	return alloc_dhcp_option(code, data, MIN(size, 255));
+}
+
+static uint8_t *alloc_dhcp_string_option(int code, const char *str)
+{
+	return alloc_dhcp_data_option(code, (const uint8_t *)str, strlen(str));
+}
+
+GDHCPClientError g_dhcp_client_set_id(GDHCPClient *dhcp_client)
+{
+	const unsigned maclen = 6;
+	const unsigned idlen = maclen + 1;
+	const uint8_t option_code = G_DHCP_CLIENT_ID;
+	uint8_t idbuf[idlen];
+	uint8_t *data_option;
+
+	idbuf[0] = ARPHRD_ETHER;
+
+	memcpy(&idbuf[1], dhcp_client->mac_address, maclen);
+
+	data_option = alloc_dhcp_data_option(option_code, idbuf, idlen);
+	if (!data_option)
+		return G_DHCP_CLIENT_ERROR_NOMEM;
+
+	g_hash_table_insert(dhcp_client->send_value_hash,
+		GINT_TO_POINTER((int) option_code), data_option);
+
+	return G_DHCP_CLIENT_ERROR_NONE;
+}
+
+/* Now only support send hostname */
+GDHCPClientError g_dhcp_client_set_send(GDHCPClient *dhcp_client,
+		unsigned char option_code, const char *option_value)
+{
+	uint8_t *binary_option;
+
+	if (option_code == G_DHCP_HOST_NAME && option_value) {
+		binary_option = alloc_dhcp_string_option(option_code,
+							option_value);
+		if (!binary_option)
+			return G_DHCP_CLIENT_ERROR_NOMEM;
+
+		g_hash_table_insert(dhcp_client->send_value_hash,
+			GINT_TO_POINTER((int) option_code), binary_option);
+	}
+
+	return G_DHCP_CLIENT_ERROR_NONE;
+}
+
+static uint8_t *alloc_dhcpv6_option(uint16_t code, uint8_t *option,
+				uint16_t len)
+{
+	uint8_t *storage;
+
+	storage = g_malloc(2 + 2 + len);
+	if (!storage)
+		return NULL;
+
+	storage[0] = code >> 8;
+	storage[1] = code & 0xff;
+	storage[2] = len >> 8;
+	storage[3] = len & 0xff;
+	memcpy(storage + 2 + 2, option, len);
+
+	return storage;
+}
+
+gboolean g_dhcpv6_client_clear_send(GDHCPClient *dhcp_client, uint16_t code)
+{
+	return g_hash_table_remove(dhcp_client->send_value_hash,
+				GINT_TO_POINTER((int)code));
+}
+
+void g_dhcpv6_client_set_send(GDHCPClient *dhcp_client,
+					uint16_t option_code,
+					uint8_t *option_value,
+					uint16_t option_len)
+{
+	if (option_value) {
+		uint8_t *binary_option;
+
+		debug(dhcp_client, "setting option %d to %p len %d",
+			option_code, option_value, option_len);
+
+		binary_option = alloc_dhcpv6_option(option_code, option_value,
+						option_len);
+		if (binary_option)
+			g_hash_table_insert(dhcp_client->send_value_hash,
+					GINT_TO_POINTER((int) option_code),
+					binary_option);
+	}
+}
+
+void g_dhcpv6_client_reset_request(GDHCPClient *dhcp_client)
+{
+	if (!dhcp_client || dhcp_client->type != G_DHCP_IPV6)
+		return;
+
+	dhcp_client->last_request = time(NULL);
+}
+
+uint16_t g_dhcpv6_client_get_status(GDHCPClient *dhcp_client)
+{
+	if (!dhcp_client || dhcp_client->type != G_DHCP_IPV6)
+		return 0;
+
+	return dhcp_client->status_code;
+}
+
+GDHCPClient *g_dhcp_client_ref(GDHCPClient *dhcp_client)
+{
+	if (!dhcp_client)
+		return NULL;
+
+	__sync_fetch_and_add(&dhcp_client->ref_count, 1);
+
+	return dhcp_client;
+}
+
+void g_dhcp_client_unref(GDHCPClient *dhcp_client)
+{
+	if (!dhcp_client)
+		return;
+
+	if (__sync_fetch_and_sub(&dhcp_client->ref_count, 1) != 1)
+		return;
+
+	g_dhcp_client_stop(dhcp_client);
+
+	g_free(dhcp_client->interface);
+	g_free(dhcp_client->assigned_ip);
+	g_free(dhcp_client->last_address);
+	g_free(dhcp_client->duid);
+	g_free(dhcp_client->server_duid);
+
+	g_list_free(dhcp_client->request_list);
+	g_list_free(dhcp_client->require_list);
+
+	g_hash_table_destroy(dhcp_client->code_value_hash);
+	g_hash_table_destroy(dhcp_client->send_value_hash);
+
+	g_free(dhcp_client);
+}
+
+void g_dhcp_client_set_debug(GDHCPClient *dhcp_client,
+				GDHCPDebugFunc func, gpointer user_data)
+{
+	if (!dhcp_client)
+		return;
+
+	dhcp_client->debug_func = func;
+	dhcp_client->debug_data = user_data;
+}
+
+static GDHCPIAPrefix *copy_prefix(gpointer data)
+{
+	GDHCPIAPrefix *copy, *prefix = data;
+
+	copy = g_try_new(GDHCPIAPrefix, 1);
+	if (!copy)
+		return NULL;
+
+	memcpy(copy, prefix, sizeof(GDHCPIAPrefix));
+
+	return copy;
+}
+
+GSList *g_dhcpv6_copy_prefixes(GSList *prefixes)
+{
+	GSList *copy = NULL;
+	GSList *list;
+
+	for (list = prefixes; list; list = list->next)
+		copy = g_slist_prepend(copy, copy_prefix(list->data));
+
+	return copy;
+}
diff --git a/connman/gdhcp/common.c b/connman/gdhcp/common.c
new file mode 100644
index 0000000..f3d4677
--- /dev/null
+++ b/connman/gdhcp/common.c
@@ -0,0 +1,780 @@
+/*
+ *  DHCP library with GLib integration
+ *
+ *  Copyright (C) 2007-2013  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 <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
+#include <stdint.h>
+#include <string.h>
+#include <endian.h>
+#include <net/if_arp.h>
+#include <linux/if.h>
+#include <netpacket/packet.h>
+#include <net/ethernet.h>
+#include <arpa/inet.h>
+#include <fcntl.h>
+
+#include "gdhcp.h"
+#include "common.h"
+
+static const DHCPOption client_options[] = {
+	{ OPTION_IP,			0x01 }, /* subnet-mask */
+	{ OPTION_IP | OPTION_LIST,	0x03 }, /* routers */
+	{ OPTION_IP | OPTION_LIST,	0x06 }, /* domain-name-servers */
+	{ OPTION_STRING,		0x0c }, /* hostname */
+	{ OPTION_STRING,		0x0f }, /* domain-name */
+	{ OPTION_IP | OPTION_LIST,	0x2a }, /* ntp-servers */
+	{ OPTION_U32,			0x33 }, /* dhcp-lease-time */
+	/* Options below will not be exposed to user */
+	{ OPTION_IP,			0x32 }, /* requested-ip */
+	{ OPTION_U8,			0x35 }, /* message-type */
+	{ OPTION_U32,			0x36 }, /* server-id */
+	{ OPTION_U16,			0x39 }, /* max-size */
+	{ OPTION_STRING,		0x3c }, /* vendor */
+	{ OPTION_STRING,		0x3d }, /* client-id */
+	{ OPTION_STRING,		0xfc }, /* UNOFFICIAL proxy-pac */
+	{ OPTION_UNKNOWN,		0x00 },
+};
+
+#define URANDOM "/dev/urandom"
+static int random_fd = -1;
+
+int dhcp_get_random(uint64_t *val)
+{
+	int r;
+
+	if (random_fd < 0) {
+		random_fd = open(URANDOM, O_RDONLY);
+		if (random_fd < 0) {
+			r = -errno;
+			*val = random();
+
+			return r;
+		}
+	}
+
+	if (read(random_fd, val, sizeof(uint64_t)) < 0) {
+		r = -errno;
+		*val = random();
+
+		return r;
+	}
+
+	return 0;
+}
+
+void dhcp_cleanup_random(void)
+{
+	if (random_fd < 0)
+		return;
+
+	close(random_fd);
+	random_fd = -1;
+}
+
+GDHCPOptionType dhcp_get_code_type(uint8_t code)
+{
+	int i;
+
+	for (i = 0; client_options[i].code; i++) {
+		if (client_options[i].code == code)
+			return client_options[i].type;
+	}
+
+	return OPTION_UNKNOWN;
+}
+
+uint8_t *dhcp_get_option(struct dhcp_packet *packet, int code)
+{
+	int len, rem;
+	uint8_t *optionptr;
+	uint8_t overload = 0;
+
+	/* option bytes: [code][len][data1][data2]..[dataLEN] */
+	optionptr = packet->options;
+	rem = sizeof(packet->options);
+
+	while (1) {
+		if (rem <= 0)
+			/* Bad packet, malformed option field */
+			return NULL;
+
+		if (optionptr[OPT_CODE] == DHCP_PADDING) {
+			rem--;
+			optionptr++;
+
+			continue;
+		}
+
+		if (optionptr[OPT_CODE] == DHCP_END) {
+			if (overload & FILE_FIELD) {
+				overload &= ~FILE_FIELD;
+
+				optionptr = packet->file;
+				rem = sizeof(packet->file);
+
+				continue;
+			} else if (overload & SNAME_FIELD) {
+				overload &= ~SNAME_FIELD;
+
+				optionptr = packet->sname;
+				rem = sizeof(packet->sname);
+
+				continue;
+			}
+
+			break;
+		}
+
+		len = 2 + optionptr[OPT_LEN];
+
+		rem -= len;
+		if (rem < 0)
+			continue; /* complain and return NULL */
+
+		if (optionptr[OPT_CODE] == code)
+			return optionptr + OPT_DATA;
+
+		if (optionptr[OPT_CODE] == DHCP_OPTION_OVERLOAD)
+			overload |= optionptr[OPT_DATA];
+
+		optionptr += len;
+	}
+
+	return NULL;
+}
+
+int dhcp_end_option(uint8_t *optionptr)
+{
+	int i = 0;
+
+	while (optionptr[i] != DHCP_END) {
+		if (optionptr[i] != DHCP_PADDING)
+			i += optionptr[i + OPT_LEN] + OPT_DATA - 1;
+
+		i++;
+	}
+
+	return i;
+}
+
+uint8_t *dhcpv6_get_option(struct dhcpv6_packet *packet, uint16_t pkt_len,
+			int code, uint16_t *option_len, int *option_count)
+{
+	int rem, count = 0;
+	uint8_t *optionptr, *found = NULL;
+	uint16_t opt_code, opt_len, len;
+
+	optionptr = packet->options;
+	rem = pkt_len - 1 - 3;
+
+	if (rem <= 0)
+		goto bad_packet;
+
+	while (1) {
+		opt_code = optionptr[0] << 8 | optionptr[1];
+		opt_len = len = optionptr[2] << 8 | optionptr[3];
+		len += 2 + 2; /* skip code and len */
+
+		if (len < 4)
+			goto bad_packet;
+
+		rem -= len;
+		if (rem < 0)
+			break;
+
+		if (opt_code == code) {
+			if (option_len)
+				*option_len = opt_len;
+			found = optionptr + 2 + 2;
+			count++;
+		}
+
+		if (rem == 0)
+			break;
+
+		optionptr += len;
+	}
+
+	if (option_count)
+		*option_count = count;
+
+	return found;
+
+bad_packet:
+	if (option_len)
+		*option_len = 0;
+	if (option_count)
+		*option_count = 0;
+	return NULL;
+}
+
+uint8_t *dhcpv6_get_sub_option(unsigned char *option, uint16_t max_len,
+			uint16_t *option_code, uint16_t *option_len)
+{
+	int rem;
+	uint16_t code, len;
+
+	rem = max_len - 2 - 2;
+
+	if (rem <= 0)
+		/* Bad option */
+		return NULL;
+
+	code = option[0] << 8 | option[1];
+	len = option[2] << 8 | option[3];
+
+	rem -= len;
+	if (rem < 0)
+		return NULL;
+
+	*option_code = code;
+	*option_len = len;
+
+	return &option[4];
+}
+
+/*
+ * Add an option (supplied in binary form) to the options.
+ * Option format: [code][len][data1][data2]..[dataLEN]
+ */
+void dhcp_add_binary_option(struct dhcp_packet *packet, uint8_t *addopt)
+{
+	unsigned len;
+	uint8_t *optionptr = packet->options;
+	unsigned end = dhcp_end_option(optionptr);
+
+	len = OPT_DATA + addopt[OPT_LEN];
+
+	/* end position + (option code/length + addopt length) + end option */
+	if (end + len + 1 >= DHCP_OPTIONS_BUFSIZE)
+		/* option did not fit into the packet */
+		return;
+
+	memcpy(optionptr + end, addopt, len);
+
+	optionptr[end + len] = DHCP_END;
+}
+
+/*
+ * Add an option (supplied in binary form) to the options.
+ * Option format: [code][len][data1][data2]..[dataLEN]
+ */
+void dhcpv6_add_binary_option(struct dhcpv6_packet *packet, uint16_t max_len,
+				uint16_t *pkt_len, uint8_t *addopt)
+{
+	unsigned len;
+	uint8_t *optionptr = packet->options;
+
+	len = 2 + 2 + (addopt[2] << 8 | addopt[3]);
+
+	/* end position + (option code/length + addopt length) */
+	if (*pkt_len + len >= max_len)
+		/* option did not fit into the packet */
+		return;
+
+	memcpy(optionptr + *pkt_len, addopt, len);
+	*pkt_len += len;
+}
+
+static GDHCPOptionType check_option(uint8_t code, uint8_t data_len)
+{
+	GDHCPOptionType type = dhcp_get_code_type(code);
+	uint8_t len;
+
+	if (type == OPTION_UNKNOWN)
+		return type;
+
+	len = dhcp_option_lengths[type & OPTION_TYPE_MASK];
+	if (len != data_len) {
+		printf("Invalid option len %d (expecting %d) for code 0x%x\n",
+			data_len, len, code);
+		return OPTION_UNKNOWN;
+	}
+
+	return type;
+}
+
+void dhcp_add_option_uint32(struct dhcp_packet *packet, uint8_t code,
+							uint32_t data)
+{
+	uint8_t option[6];
+
+	if (check_option(code, sizeof(data)) == OPTION_UNKNOWN)
+		return;
+
+	option[OPT_CODE] = code;
+	option[OPT_LEN] = sizeof(data);
+	put_be32(data, option + OPT_DATA);
+
+	dhcp_add_binary_option(packet, option);
+
+	return;
+}
+
+void dhcp_add_option_uint16(struct dhcp_packet *packet, uint8_t code,
+							uint16_t data)
+{
+	uint8_t option[6];
+
+	if (check_option(code, sizeof(data)) == OPTION_UNKNOWN)
+		return;
+
+	option[OPT_CODE] = code;
+	option[OPT_LEN] = sizeof(data);
+	put_be16(data, option + OPT_DATA);
+
+	dhcp_add_binary_option(packet, option);
+
+	return;
+}
+
+void dhcp_add_option_uint8(struct dhcp_packet *packet, uint8_t code,
+							uint8_t data)
+{
+	uint8_t option[6];
+
+	if (check_option(code, sizeof(data)) == OPTION_UNKNOWN)
+		return;
+
+	option[OPT_CODE] = code;
+	option[OPT_LEN] = sizeof(data);
+	option[OPT_DATA] = data;
+
+	dhcp_add_binary_option(packet, option);
+
+	return;
+}
+
+void dhcp_init_header(struct dhcp_packet *packet, char type)
+{
+	memset(packet, 0, sizeof(*packet));
+
+	packet->op = BOOTREQUEST;
+
+	switch (type) {
+	case DHCPOFFER:
+	case DHCPACK:
+	case DHCPNAK:
+		packet->op = BOOTREPLY;
+	}
+
+	packet->htype = 1;
+	packet->hlen = 6;
+	packet->cookie = htonl(DHCP_MAGIC);
+	packet->options[0] = DHCP_END;
+
+	dhcp_add_option_uint8(packet, DHCP_MESSAGE_TYPE, type);
+}
+
+void dhcpv6_init_header(struct dhcpv6_packet *packet, uint8_t type)
+{
+	int id;
+	uint64_t rand;
+
+	memset(packet, 0, sizeof(*packet));
+
+	packet->message = type;
+
+	dhcp_get_random(&rand);
+	id = rand;
+
+	packet->transaction_id[0] = (id >> 16) & 0xff;
+	packet->transaction_id[1] = (id >> 8) & 0xff;
+	packet->transaction_id[2] = id & 0xff;
+}
+
+int dhcp_recv_l3_packet(struct dhcp_packet *packet, int fd)
+{
+	int n;
+
+	memset(packet, 0, sizeof(*packet));
+
+	n = read(fd, packet, sizeof(*packet));
+	if (n < 0)
+		return -errno;
+
+	if (packet->cookie != htonl(DHCP_MAGIC))
+		return -EPROTO;
+
+	return n;
+}
+
+int dhcpv6_recv_l3_packet(struct dhcpv6_packet **packet, unsigned char *buf,
+			int buf_len, int fd)
+{
+	int n;
+
+	n = read(fd, buf, buf_len);
+	if (n < 0)
+		return -errno;
+
+	*packet = (struct dhcpv6_packet *)buf;
+
+	return n;
+}
+
+/* TODO: Use glib checksum */
+uint16_t dhcp_checksum(void *addr, int count)
+{
+	/*
+	 * Compute Internet Checksum for "count" bytes
+	 * beginning at location "addr".
+	 */
+	int32_t sum = 0;
+	uint16_t *source = (uint16_t *) addr;
+
+	while (count > 1)  {
+		/*  This is the inner loop */
+		sum += *source++;
+		count -= 2;
+	}
+
+	/*  Add left-over byte, if any */
+	if (count > 0) {
+		/* Make sure that the left-over byte is added correctly both
+		 * with little and big endian hosts */
+		uint16_t tmp = 0;
+		*(uint8_t *) &tmp = *(uint8_t *) source;
+		sum += tmp;
+	}
+	/*  Fold 32-bit sum to 16 bits */
+	while (sum >> 16)
+		sum = (sum & 0xffff) + (sum >> 16);
+
+	return ~sum;
+}
+
+#define IN6ADDR_ALL_DHCP_RELAY_AGENTS_AND_SERVERS_MC_INIT \
+	{ { { 0xff,0x02,0,0,0,0,0,0,0,0,0,0,0,0x1,0,0x2 } } } /* ff02::1:2 */
+static const struct in6_addr in6addr_all_dhcp_relay_agents_and_servers_mc =
+	IN6ADDR_ALL_DHCP_RELAY_AGENTS_AND_SERVERS_MC_INIT;
+
+int dhcpv6_send_packet(int index, struct dhcpv6_packet *dhcp_pkt, int len)
+{
+	struct msghdr m;
+	struct iovec v;
+	struct in6_pktinfo *pktinfo;
+	struct cmsghdr *cmsg;
+	int fd, ret, opt = 1;
+	struct sockaddr_in6 src;
+	struct sockaddr_in6 dst;
+	void *control_buf;
+	size_t control_buf_len;
+
+	fd = socket(PF_INET6, SOCK_DGRAM | SOCK_CLOEXEC, IPPROTO_UDP);
+	if (fd < 0)
+		return -errno;
+
+	setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
+
+	memset(&src, 0, sizeof(src));
+	src.sin6_family = AF_INET6;
+	src.sin6_port = htons(DHCPV6_CLIENT_PORT);
+
+	if (bind(fd, (struct sockaddr *) &src, sizeof(src)) <0) {
+		close(fd);
+		return -errno;
+	}
+
+	memset(&dst, 0, sizeof(dst));
+	dst.sin6_family = AF_INET6;
+	dst.sin6_port = htons(DHCPV6_SERVER_PORT);
+
+	dst.sin6_addr = in6addr_all_dhcp_relay_agents_and_servers_mc;
+
+	control_buf_len = CMSG_SPACE(sizeof(struct in6_pktinfo));
+	control_buf = g_try_malloc0(control_buf_len);
+	if (!control_buf) {
+		close(fd);
+		return -ENOMEM;
+	}
+
+	memset(&m, 0, sizeof(m));
+	memset(&v, 0, sizeof(v));
+
+	m.msg_name = &dst;
+	m.msg_namelen = sizeof(dst);
+
+	v.iov_base = (char *)dhcp_pkt;
+	v.iov_len = len;
+	m.msg_iov = &v;
+	m.msg_iovlen = 1;
+
+	m.msg_control = control_buf;
+	m.msg_controllen = control_buf_len;
+	cmsg = CMSG_FIRSTHDR(&m);
+	cmsg->cmsg_level = IPPROTO_IPV6;
+	cmsg->cmsg_type = IPV6_PKTINFO;
+	cmsg->cmsg_len = CMSG_LEN(sizeof(*pktinfo));
+
+	pktinfo = (struct in6_pktinfo *)CMSG_DATA(cmsg);
+	memset(pktinfo, 0, sizeof(*pktinfo));
+	pktinfo->ipi6_ifindex = index;
+	m.msg_controllen = cmsg->cmsg_len;
+
+	ret = sendmsg(fd, &m, 0);
+	if (ret < 0) {
+		char *msg = "DHCPv6 msg send failed";
+
+		if (errno == EADDRNOTAVAIL) {
+			char *str = g_strdup_printf("%s (index %d)",
+					msg, index);
+			perror(str);
+			g_free(str);
+		} else
+			perror(msg);
+	}
+
+	g_free(control_buf);
+	close(fd);
+
+	return ret;
+}
+
+int dhcp_send_raw_packet(struct dhcp_packet *dhcp_pkt,
+			uint32_t source_ip, int source_port,
+			uint32_t dest_ip, int dest_port,
+			const uint8_t *dest_arp, int ifindex, bool bcast)
+{
+	struct sockaddr_ll dest;
+	struct ip_udp_dhcp_packet packet;
+	int fd, n;
+
+	enum {
+		IP_UPD_DHCP_SIZE = sizeof(struct ip_udp_dhcp_packet) -
+						EXTEND_FOR_BUGGY_SERVERS,
+		UPD_DHCP_SIZE = IP_UPD_DHCP_SIZE -
+				offsetof(struct ip_udp_dhcp_packet, udp),
+	};
+
+	fd = socket(PF_PACKET, SOCK_DGRAM | SOCK_CLOEXEC, htons(ETH_P_IP));
+	if (fd < 0)
+		return -errno;
+
+	if (bcast)
+		dhcp_pkt->flags |= htons(BROADCAST_FLAG);
+
+	memset(&dest, 0, sizeof(dest));
+	memset(&packet, 0, sizeof(packet));
+	packet.data = *dhcp_pkt;
+
+	dest.sll_family = AF_PACKET;
+	dest.sll_protocol = htons(ETH_P_IP);
+	dest.sll_ifindex = ifindex;
+	dest.sll_halen = 6;
+	memcpy(dest.sll_addr, dest_arp, 6);
+	if (bind(fd, (struct sockaddr *)&dest, sizeof(dest)) < 0) {
+		close(fd);
+		return -errno;
+	}
+
+	packet.ip.protocol = IPPROTO_UDP;
+	packet.ip.saddr = source_ip;
+	packet.ip.daddr = dest_ip;
+	packet.udp.source = htons(source_port);
+	packet.udp.dest = htons(dest_port);
+	/* size, excluding IP header: */
+	packet.udp.len = htons(UPD_DHCP_SIZE);
+	/* for UDP checksumming, ip.len is set to UDP packet len */
+	packet.ip.tot_len = packet.udp.len;
+	packet.udp.check = dhcp_checksum(&packet, IP_UPD_DHCP_SIZE);
+	/* but for sending, it is set to IP packet len */
+	packet.ip.tot_len = htons(IP_UPD_DHCP_SIZE);
+	packet.ip.ihl = sizeof(packet.ip) >> 2;
+	packet.ip.version = IPVERSION;
+	packet.ip.ttl = IPDEFTTL;
+	packet.ip.check = dhcp_checksum(&packet.ip, sizeof(packet.ip));
+
+	/*
+	 * Currently we send full-sized DHCP packets (zero padded).
+	 * If you need to change this: last byte of the packet is
+	 * packet.data.options[dhcp_end_option(packet.data.options)]
+	 */
+	n = sendto(fd, &packet, IP_UPD_DHCP_SIZE, 0,
+			(struct sockaddr *) &dest, sizeof(dest));
+	close(fd);
+
+	if (n < 0)
+		return -errno;
+
+	return n;
+}
+
+int dhcp_send_kernel_packet(struct dhcp_packet *dhcp_pkt,
+				uint32_t source_ip, int source_port,
+				uint32_t dest_ip, int dest_port)
+{
+	struct sockaddr_in client;
+	int fd, n, opt = 1;
+
+	enum {
+		DHCP_SIZE = sizeof(struct dhcp_packet) -
+					EXTEND_FOR_BUGGY_SERVERS,
+	};
+
+	fd = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, IPPROTO_UDP);
+	if (fd < 0)
+		return -errno;
+
+	setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
+
+	memset(&client, 0, sizeof(client));
+	client.sin_family = AF_INET;
+	client.sin_port = htons(source_port);
+	client.sin_addr.s_addr = htonl(source_ip);
+	if (bind(fd, (struct sockaddr *) &client, sizeof(client)) < 0) {
+		close(fd);
+		return -errno;
+	}
+
+	memset(&client, 0, sizeof(client));
+	client.sin_family = AF_INET;
+	client.sin_port = htons(dest_port);
+	client.sin_addr.s_addr = htonl(dest_ip);
+	if (connect(fd, (struct sockaddr *) &client, sizeof(client)) < 0) {
+		close(fd);
+		return -errno;
+	}
+
+	n = write(fd, dhcp_pkt, DHCP_SIZE);
+
+	close(fd);
+
+	if (n < 0)
+		return -errno;
+
+	return n;
+}
+
+int dhcp_l3_socket(int port, const char *interface, int family)
+{
+	int fd, opt = 1, len;
+	struct sockaddr_in addr4;
+	struct sockaddr_in6 addr6;
+	struct sockaddr *addr;
+
+	fd = socket(family, SOCK_DGRAM | SOCK_CLOEXEC, IPPROTO_UDP);
+	if (fd < 0)
+		return -errno;
+
+	setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
+
+	if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE,
+				interface, strlen(interface) + 1) < 0) {
+		close(fd);
+		return -1;
+	}
+
+	if (family == AF_INET) {
+		memset(&addr4, 0, sizeof(addr4));
+		addr4.sin_family = family;
+		addr4.sin_port = htons(port);
+		addr = (struct sockaddr *)&addr4;
+		len = sizeof(addr4);
+	} else if (family == AF_INET6) {
+		memset(&addr6, 0, sizeof(addr6));
+		addr6.sin6_family = family;
+		addr6.sin6_port = htons(port);
+		addr = (struct sockaddr *)&addr6;
+		len = sizeof(addr6);
+	} else {
+		close(fd);
+		return -EINVAL;
+	}
+
+	if (bind(fd, addr, len) != 0) {
+		close(fd);
+		return -1;
+	}
+
+	return fd;
+}
+
+char *get_interface_name(int index)
+{
+	struct ifreq ifr;
+	int sk, err;
+
+	if (index < 0)
+		return NULL;
+
+	sk = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
+	if (sk < 0) {
+		perror("Open socket error");
+		return NULL;
+	}
+
+	memset(&ifr, 0, sizeof(ifr));
+	ifr.ifr_ifindex = index;
+
+	err = ioctl(sk, SIOCGIFNAME, &ifr);
+	if (err < 0) {
+		perror("Get interface name error");
+		close(sk);
+		return NULL;
+	}
+
+	close(sk);
+
+	return g_strdup(ifr.ifr_name);
+}
+
+bool interface_is_up(int index)
+{
+	int sk, err;
+	struct ifreq ifr;
+	bool ret = false;
+
+	sk = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
+	if (sk < 0) {
+		perror("Open socket error");
+		return false;
+	}
+
+	memset(&ifr, 0, sizeof(ifr));
+	ifr.ifr_ifindex = index;
+
+	err = ioctl(sk, SIOCGIFNAME, &ifr);
+	if (err < 0) {
+		perror("Get interface name error");
+		goto done;
+	}
+
+	err = ioctl(sk, SIOCGIFFLAGS, &ifr);
+	if (err < 0) {
+		perror("Get interface flags error");
+		goto done;
+	}
+
+	if (ifr.ifr_flags & IFF_UP)
+		ret = true;
+
+done:
+	close(sk);
+
+	return ret;
+}
diff --git a/connman/gdhcp/common.h b/connman/gdhcp/common.h
new file mode 100644
index 0000000..75abc18
--- /dev/null
+++ b/connman/gdhcp/common.h
@@ -0,0 +1,220 @@
+/*
+ *
+ *  DHCP client library with GLib integration
+ *
+ *  Copyright (C) 2009-2012  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
+ *
+ */
+
+#include <netinet/udp.h>
+#include <netinet/ip.h>
+
+#include <glib.h>
+
+#include "unaligned.h"
+#include "gdhcp.h"
+
+#define CLIENT_PORT 68
+#define SERVER_PORT 67
+
+#define DHCPV6_CLIENT_PORT 546
+#define DHCPV6_SERVER_PORT 547
+#define MAX_DHCPV6_PKT_SIZE 1500
+
+#define EXTEND_FOR_BUGGY_SERVERS 80
+
+static const uint8_t MAC_BCAST_ADDR[ETH_ALEN] __attribute__((aligned(2))) = {
+	0xff, 0xff, 0xff, 0xff, 0xff, 0xff
+};
+
+static const uint8_t MAC_ANY_ADDR[ETH_ALEN] __attribute__((aligned(2))) = {
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+};
+
+/* DHCP packet */
+#define DHCP_MAGIC              0x63825363
+#define DHCP_OPTIONS_BUFSIZE    308
+#define BOOTREQUEST             1
+#define BOOTREPLY               2
+
+#define BROADCAST_FLAG		0x8000
+
+/* See RFC 2131 */
+struct dhcp_packet {
+	uint8_t op;
+	uint8_t htype;
+	uint8_t hlen;
+	uint8_t hops;
+	uint32_t xid;
+	uint16_t secs;
+	uint16_t flags;
+	uint32_t ciaddr;
+	uint32_t yiaddr;
+	uint32_t siaddr_nip;
+	uint32_t gateway_nip;
+	uint8_t chaddr[16];
+	uint8_t sname[64];
+	uint8_t file[128];
+	uint32_t cookie;
+	uint8_t options[DHCP_OPTIONS_BUFSIZE + EXTEND_FOR_BUGGY_SERVERS];
+} __attribute__((packed));
+
+struct ip_udp_dhcp_packet {
+	struct iphdr ip;
+	struct udphdr udp;
+	struct dhcp_packet data;
+} __attribute__((packed));
+
+/* See RFC 3315 */
+struct dhcpv6_packet {
+	uint8_t message;
+	uint8_t transaction_id[3];
+	uint8_t options[];
+} __attribute__((packed));
+
+
+/* See RFC 2132 */
+#define DHCP_PADDING		0x00
+#define DHCP_SUBNET		0x01
+#define DHCP_ROUTER		0x03
+#define DHCP_TIME_SERVER	0x04
+#define DHCP_NAME_SERVER	0x05
+#define DHCP_DNS_SERVER		0x06
+#define DHCP_HOST_NAME		0x0c
+#define DHCP_DOMAIN_NAME	0x0f
+#define DHCP_NTP_SERVER		0x2a
+#define DHCP_REQUESTED_IP	0x32
+#define DHCP_LEASE_TIME		0x33
+#define DHCP_OPTION_OVERLOAD	0x34
+#define DHCP_MESSAGE_TYPE	0x35
+#define DHCP_SERVER_ID		0x36
+#define DHCP_PARAM_REQ		0x37
+#define DHCP_ERR_MESSAGE	0x38
+#define DHCP_MAX_SIZE		0x39
+#define DHCP_VENDOR		0x3c
+#define DHCP_CLIENT_ID		0x3d
+#define DHCP_END		0xff
+
+#define OPT_CODE		0
+#define OPT_LEN			1
+#define OPT_DATA		2
+#define OPTION_FIELD		0
+#define FILE_FIELD		1
+#define SNAME_FIELD		2
+
+/* DHCP_MESSAGE_TYPE values */
+#define DHCPDISCOVER		1
+#define DHCPOFFER		2
+#define DHCPREQUEST		3
+#define DHCPDECLINE		4
+#define DHCPACK			5
+#define DHCPNAK			6
+#define DHCPRELEASE		7
+#define DHCPINFORM		8
+#define DHCP_MINTYPE DHCPDISCOVER
+#define DHCP_MAXTYPE DHCPINFORM
+
+/* Message types for DHCPv6, RFC 3315 sec 5.3 */
+#define DHCPV6_SOLICIT		1
+#define DHCPV6_ADVERTISE	2
+#define DHCPV6_REQUEST		3
+#define DHCPV6_CONFIRM		4
+#define DHCPV6_RENEW		5
+#define DHCPV6_REBIND		6
+#define DHCPV6_REPLY		7
+#define DHCPV6_RELEASE		8
+#define DHCPV6_DECLINE		9
+#define DHCPV6_RECONFIGURE	10
+#define DHCPV6_INFORMATION_REQ	11
+
+/*
+ * DUID time starts 2000-01-01.
+ */
+#define DUID_TIME_EPOCH 946684800
+
+typedef enum {
+	OPTION_UNKNOWN,
+	OPTION_IP,
+	OPTION_STRING,
+	OPTION_U8,
+	OPTION_U16,
+	OPTION_U32,
+	OPTION_TYPE_MASK = 0x0f,
+	OPTION_LIST = 0x10,
+} GDHCPOptionType;
+
+typedef struct dhcp_option {
+	GDHCPOptionType type;
+	uint8_t code;
+} DHCPOption;
+
+/* Length of the option types in binary form */
+static const uint8_t dhcp_option_lengths[] = {
+	[OPTION_IP]	= 4,
+	[OPTION_STRING]	= 1,
+	[OPTION_U8]	= 1,
+	[OPTION_U16]	= 2,
+	[OPTION_U32]	= 4,
+};
+
+/* already defined within netinet/in.h if using GNU compiler */
+#ifndef __USE_GNU
+struct in6_pktinfo {
+	struct in6_addr ipi6_addr;  /* src/dst IPv6 address */
+	unsigned int ipi6_ifindex;  /* send/recv interface index */
+};
+#endif
+
+uint8_t *dhcp_get_option(struct dhcp_packet *packet, int code);
+uint8_t *dhcpv6_get_option(struct dhcpv6_packet *packet, uint16_t pkt_len,
+			int code, uint16_t *option_len, int *option_count);
+uint8_t *dhcpv6_get_sub_option(unsigned char *option, uint16_t max_len,
+			uint16_t *code, uint16_t *option_len);
+int dhcp_end_option(uint8_t *optionptr);
+void dhcp_add_binary_option(struct dhcp_packet *packet, uint8_t *addopt);
+void dhcpv6_add_binary_option(struct dhcpv6_packet *packet, uint16_t max_len,
+				uint16_t *pkt_len, uint8_t *addopt);
+void dhcp_add_option_uint8(struct dhcp_packet *packet,
+				uint8_t code, uint8_t data);
+void dhcp_add_option_uint16(struct dhcp_packet *packet,
+				uint8_t code, uint16_t data);
+void dhcp_add_option_uint32(struct dhcp_packet *packet,
+				uint8_t code, uint32_t data);
+GDHCPOptionType dhcp_get_code_type(uint8_t code);
+GDHCPOptionType dhcpv6_get_code_type(uint16_t code);
+
+uint16_t dhcp_checksum(void *addr, int count);
+
+void dhcp_init_header(struct dhcp_packet *packet, char type);
+void dhcpv6_init_header(struct dhcpv6_packet *packet, uint8_t type);
+
+int dhcp_send_raw_packet(struct dhcp_packet *dhcp_pkt,
+			uint32_t source_ip, int source_port,
+			uint32_t dest_ip, int dest_port,
+			const uint8_t *dest_arp, int ifindex,
+			bool bcast);
+int dhcpv6_send_packet(int index, struct dhcpv6_packet *dhcp_pkt, int len);
+int dhcp_send_kernel_packet(struct dhcp_packet *dhcp_pkt,
+			uint32_t source_ip, int source_port,
+			uint32_t dest_ip, int dest_port);
+int dhcp_l3_socket(int port, const char *interface, int family);
+int dhcp_recv_l3_packet(struct dhcp_packet *packet, int fd);
+int dhcpv6_recv_l3_packet(struct dhcpv6_packet **packet, unsigned char *buf,
+			int buf_len, int fd);
+int dhcp_l3_socket_send(int index, int port, int family);
+
+char *get_interface_name(int index);
+bool interface_is_up(int index);
diff --git a/connman/gdhcp/gdhcp.h b/connman/gdhcp/gdhcp.h
new file mode 100644
index 0000000..5ee079e
--- /dev/null
+++ b/connman/gdhcp/gdhcp.h
@@ -0,0 +1,241 @@
+/*
+ *
+ *  DHCP library with GLib integration
+ *
+ *  Copyright (C) 2009-2013  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 __G_DHCP_H
+#define __G_DHCP_H
+
+#include <stdbool.h>
+#include <stdint.h>
+#include <arpa/inet.h>
+
+#include <glib.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* DHCP Client part*/
+struct _GDHCPClient;
+
+typedef struct _GDHCPClient GDHCPClient;
+
+typedef enum {
+	G_DHCP_CLIENT_ERROR_NONE,
+	G_DHCP_CLIENT_ERROR_INTERFACE_UNAVAILABLE,
+	G_DHCP_CLIENT_ERROR_INTERFACE_IN_USE,
+	G_DHCP_CLIENT_ERROR_INTERFACE_DOWN,
+	G_DHCP_CLIENT_ERROR_NOMEM,
+	G_DHCP_CLIENT_ERROR_INVALID_INDEX,
+	G_DHCP_CLIENT_ERROR_INVALID_OPTION
+} GDHCPClientError;
+
+typedef enum {
+	G_DHCP_CLIENT_EVENT_LEASE_AVAILABLE,
+	G_DHCP_CLIENT_EVENT_IPV4LL_AVAILABLE,
+	G_DHCP_CLIENT_EVENT_NO_LEASE,
+	G_DHCP_CLIENT_EVENT_LEASE_LOST,
+	G_DHCP_CLIENT_EVENT_IPV4LL_LOST,
+	G_DHCP_CLIENT_EVENT_ADDRESS_CONFLICT,
+	G_DHCP_CLIENT_EVENT_INFORMATION_REQ,
+	G_DHCP_CLIENT_EVENT_SOLICITATION,
+	G_DHCP_CLIENT_EVENT_ADVERTISE,
+	G_DHCP_CLIENT_EVENT_REQUEST,
+	G_DHCP_CLIENT_EVENT_RENEW,
+	G_DHCP_CLIENT_EVENT_REBIND,
+	G_DHCP_CLIENT_EVENT_RELEASE,
+	G_DHCP_CLIENT_EVENT_CONFIRM,
+	G_DHCP_CLIENT_EVENT_DECLINE,
+	G_DHCP_CLIENT_EVENT_WAKE_EVENT,
+} GDHCPClientEvent;
+
+typedef enum {
+	G_DHCP_IPV4,
+	G_DHCP_IPV6,
+	G_DHCP_IPV4LL,
+} GDHCPType;
+
+#define G_DHCP_SUBNET		0x01
+#define G_DHCP_ROUTER		0x03
+#define G_DHCP_TIME_SERVER	0x04
+#define G_DHCP_DNS_SERVER	0x06
+#define G_DHCP_DOMAIN_NAME	0x0f
+#define G_DHCP_HOST_NAME	0x0c
+#define G_DHCP_NTP_SERVER	0x2a
+#define G_DHCP_CLIENT_ID	0x3d
+
+#define G_DHCPV6_CLIENTID	1
+#define G_DHCPV6_SERVERID	2
+#define G_DHCPV6_IA_NA		3
+#define G_DHCPV6_IA_TA		4
+#define G_DHCPV6_IAADDR		5
+#define G_DHCPV6_ORO		6
+#define G_DHCPV6_PREFERENCE     7
+#define G_DHCPV6_ELAPSED_TIME   8
+#define G_DHCPV6_STATUS_CODE	13
+#define G_DHCPV6_RAPID_COMMIT	14
+#define G_DHCPV6_DNS_SERVERS	23
+#define G_DHCPV6_DOMAIN_LIST	24
+#define G_DHCPV6_IA_PD		25
+#define G_DHCPV6_IA_PREFIX	26
+#define G_DHCPV6_SNTP_SERVERS	31
+
+#define G_DHCPV6_ERROR_SUCCESS	0
+#define G_DHCPV6_ERROR_FAILURE	1
+#define G_DHCPV6_ERROR_NO_ADDR	2
+#define G_DHCPV6_ERROR_BINDING	3
+#define G_DHCPV6_ERROR_LINK	4
+#define G_DHCPV6_ERROR_MCAST	5
+#define G_DHCPV6_ERROR_NO_PREFIX 6
+
+typedef enum {
+	G_DHCPV6_DUID_LLT = 1,
+	G_DHCPV6_DUID_EN  = 2,
+	G_DHCPV6_DUID_LL  = 3,
+} GDHCPDuidType;
+
+typedef struct {
+	/*
+	 * Note that no field in this struct can be allocated
+	 * from heap or there will be a memory leak when the
+	 * struct is freed by client.c:remove_option_value()
+	 */
+	struct in6_addr prefix;
+	unsigned char prefixlen;
+	uint32_t preferred;
+	uint32_t valid;
+	time_t expire;
+} GDHCPIAPrefix;
+
+typedef void (*GDHCPClientEventFunc) (GDHCPClient *client, gpointer user_data);
+
+typedef void (*GDHCPDebugFunc)(const char *str, gpointer user_data);
+
+GDHCPClient *g_dhcp_client_new(GDHCPType type, int index,
+						GDHCPClientError *error);
+
+int g_dhcp_client_start(GDHCPClient *client, const char *last_address);
+void g_dhcp_client_stop(GDHCPClient *client);
+
+GDHCPClient *g_dhcp_client_ref(GDHCPClient *client);
+void g_dhcp_client_unref(GDHCPClient *client);
+
+void g_dhcp_client_register_event(GDHCPClient *client,
+					GDHCPClientEvent event,
+					GDHCPClientEventFunc func,
+					gpointer user_data);
+
+GDHCPClientError g_dhcp_client_set_request(GDHCPClient *client,
+						unsigned int option_code);
+void g_dhcp_client_clear_requests(GDHCPClient *dhcp_client);
+void g_dhcp_client_clear_values(GDHCPClient *dhcp_client);
+GDHCPClientError g_dhcp_client_set_id(GDHCPClient *client);
+GDHCPClientError g_dhcp_client_set_send(GDHCPClient *client,
+						unsigned char option_code,
+						const char *option_value);
+
+char *g_dhcp_client_get_server_address(GDHCPClient *client);
+char *g_dhcp_client_get_address(GDHCPClient *client);
+char *g_dhcp_client_get_netmask(GDHCPClient *client);
+GList *g_dhcp_client_get_option(GDHCPClient *client,
+						unsigned char option_code);
+int g_dhcp_client_get_index(GDHCPClient *client);
+
+void g_dhcp_client_set_debug(GDHCPClient *client,
+				GDHCPDebugFunc func, gpointer user_data);
+int g_dhcpv6_create_duid(GDHCPDuidType duid_type, int index, int type,
+			unsigned char **duid, int *duid_len);
+int g_dhcpv6_client_set_duid(GDHCPClient *dhcp_client, unsigned char *duid,
+			int duid_len);
+int g_dhcpv6_client_set_pd(GDHCPClient *dhcp_client, uint32_t *T1, uint32_t *T2,
+			GSList *prefixes);
+GSList *g_dhcpv6_copy_prefixes(GSList *prefixes);
+gboolean g_dhcpv6_client_clear_send(GDHCPClient *dhcp_client, uint16_t code);
+void g_dhcpv6_client_set_send(GDHCPClient *dhcp_client, uint16_t option_code,
+			uint8_t *option_value, uint16_t option_len);
+uint16_t g_dhcpv6_client_get_status(GDHCPClient *dhcp_client);
+int g_dhcpv6_client_set_oro(GDHCPClient *dhcp_client, int args, ...);
+void g_dhcpv6_client_create_iaid(GDHCPClient *dhcp_client, int index,
+				unsigned char *iaid);
+int g_dhcpv6_client_get_timeouts(GDHCPClient *dhcp_client,
+				uint32_t *T1, uint32_t *T2,
+				time_t *started, time_t *expire);
+uint32_t g_dhcpv6_client_get_iaid(GDHCPClient *dhcp_client);
+void g_dhcpv6_client_set_iaid(GDHCPClient *dhcp_client, uint32_t iaid);
+int g_dhcpv6_client_set_ia(GDHCPClient *dhcp_client, int index,
+			int code, uint32_t *T1, uint32_t *T2,
+			bool add_addresses, const char *address);
+int g_dhcpv6_client_set_ias(GDHCPClient *dhcp_client, int index,
+			int code, uint32_t *T1, uint32_t *T2,
+			GSList *addresses);
+void g_dhcpv6_client_reset_request(GDHCPClient *dhcp_client);
+void g_dhcpv6_client_set_retransmit(GDHCPClient *dhcp_client);
+void g_dhcpv6_client_clear_retransmit(GDHCPClient *dhcp_client);
+
+/* DHCP Server */
+typedef enum {
+	G_DHCP_SERVER_ERROR_NONE,
+	G_DHCP_SERVER_ERROR_INTERFACE_UNAVAILABLE,
+	G_DHCP_SERVER_ERROR_INTERFACE_IN_USE,
+	G_DHCP_SERVER_ERROR_INTERFACE_DOWN,
+	G_DHCP_SERVER_ERROR_NOMEM,
+	G_DHCP_SERVER_ERROR_INVALID_INDEX,
+	G_DHCP_SERVER_ERROR_INVALID_OPTION,
+	G_DHCP_SERVER_ERROR_IP_ADDRESS_INVALID
+} GDHCPServerError;
+
+typedef void (*GDHCPSaveLeaseFunc) (unsigned char *mac,
+			unsigned int nip, unsigned int expire);
+
+typedef void (*GDHCPLeaseAddedCb) (unsigned char *mac, uint32_t ip);
+
+struct _GDHCPServer;
+
+typedef struct _GDHCPServer GDHCPServer;
+
+GDHCPServer *g_dhcp_server_new(GDHCPType type,
+		int ifindex, GDHCPServerError *error);
+int g_dhcp_server_start(GDHCPServer *server);
+void g_dhcp_server_stop(GDHCPServer *server);
+
+GDHCPServer *g_dhcp_server_ref(GDHCPServer *server);
+void g_dhcp_server_unref(GDHCPServer *server);
+
+int g_dhcp_server_set_option(GDHCPServer *server,
+		unsigned char option_code, const char *option_value);
+int g_dhcp_server_set_ip_range(GDHCPServer *server,
+		const char *start_ip, const char *end_ip);
+void g_dhcp_server_set_debug(GDHCPServer *server,
+				GDHCPDebugFunc func, gpointer user_data);
+void g_dhcp_server_set_lease_time(GDHCPServer *dhcp_server,
+						unsigned int lease_time);
+void g_dhcp_server_set_save_lease(GDHCPServer *dhcp_server,
+				GDHCPSaveLeaseFunc func, gpointer user_data);
+void g_dhcp_server_set_lease_added_cb(GDHCPServer *dhcp_server,
+							GDHCPLeaseAddedCb cb);
+
+int dhcp_get_random(uint64_t *val);
+void dhcp_cleanup_random(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __G_DHCP_H */
diff --git a/connman/gdhcp/ipv4ll.c b/connman/gdhcp/ipv4ll.c
new file mode 100644
index 0000000..c43971f
--- /dev/null
+++ b/connman/gdhcp/ipv4ll.c
@@ -0,0 +1,135 @@
+/*
+ *
+ *  IPV4 Local Link library with GLib integration
+ *
+ *  Copyright (C) 2009-2010  Aldebaran Robotics. 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
+ *
+ */
+#include <string.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <unistd.h>
+
+#include <sys/time.h>
+#include <sys/socket.h>
+#include <sys/types.h>
+#include <netpacket/packet.h>
+#include <net/ethernet.h>
+#include <netinet/if_ether.h>
+
+#include <arpa/inet.h>
+
+#include <glib.h>
+#include "ipv4ll.h"
+#include "common.h"
+
+/**
+ * Return a random link local IP (in host byte order)
+ */
+uint32_t ipv4ll_random_ip(void)
+{
+	unsigned tmp;
+	uint64_t rand;
+
+	do {
+		dhcp_get_random(&rand);
+		tmp = rand;
+		tmp = tmp & IN_CLASSB_HOST;
+	} while (tmp > (IN_CLASSB_HOST - 0x0200));
+	return ((LINKLOCAL_ADDR + 0x0100) + tmp);
+}
+
+/**
+ * Return a random delay in range of zero to secs*1000
+ */
+guint ipv4ll_random_delay_ms(guint secs)
+{
+	uint64_t rand;
+
+	dhcp_get_random(&rand);
+	return rand % (secs * 1000);
+}
+
+int ipv4ll_send_arp_packet(uint8_t* source_eth, uint32_t source_ip,
+		    uint32_t target_ip, int ifindex)
+{
+	struct sockaddr_ll dest;
+	struct ether_arp p;
+	uint32_t ip_source;
+	uint32_t ip_target;
+	int fd, n;
+
+	fd = socket(PF_PACKET, SOCK_DGRAM | SOCK_CLOEXEC, htons(ETH_P_ARP));
+	if (fd < 0)
+		return -errno;
+
+	memset(&dest, 0, sizeof(dest));
+	memset(&p, 0, sizeof(p));
+
+	dest.sll_family = AF_PACKET;
+	dest.sll_protocol = htons(ETH_P_ARP);
+	dest.sll_ifindex = ifindex;
+	dest.sll_halen = ETH_ALEN;
+	memset(dest.sll_addr, 0xFF, ETH_ALEN);
+	if (bind(fd, (struct sockaddr *)&dest, sizeof(dest)) < 0) {
+		close(fd);
+		return -errno;
+	}
+
+	ip_source = htonl(source_ip);
+	ip_target = htonl(target_ip);
+	p.arp_hrd = htons(ARPHRD_ETHER);
+	p.arp_pro = htons(ETHERTYPE_IP);
+	p.arp_hln = ETH_ALEN;
+	p.arp_pln = 4;
+	p.arp_op = htons(ARPOP_REQUEST);
+
+	memcpy(&p.arp_sha, source_eth, ETH_ALEN);
+	memcpy(&p.arp_spa, &ip_source, sizeof(p.arp_spa));
+	memcpy(&p.arp_tpa, &ip_target, sizeof(p.arp_tpa));
+
+	n = sendto(fd, &p, sizeof(p), 0,
+	       (struct sockaddr*) &dest, sizeof(dest));
+	if (n < 0)
+		n = -errno;
+
+	close(fd);
+
+	return n;
+}
+
+int ipv4ll_arp_socket(int ifindex)
+{
+	int fd;
+	struct sockaddr_ll sock;
+
+	fd = socket(PF_PACKET, SOCK_DGRAM | SOCK_CLOEXEC, htons(ETH_P_ARP));
+	if (fd < 0)
+		return fd;
+
+	memset(&sock, 0, sizeof(sock));
+
+	sock.sll_family = AF_PACKET;
+	sock.sll_protocol = htons(ETH_P_ARP);
+	sock.sll_ifindex = ifindex;
+
+	if (bind(fd, (struct sockaddr *) &sock, sizeof(sock)) != 0) {
+		close(fd);
+		return -errno;
+	}
+
+	return fd;
+}
diff --git a/connman/gdhcp/ipv4ll.h b/connman/gdhcp/ipv4ll.h
new file mode 100644
index 0000000..bee8138
--- /dev/null
+++ b/connman/gdhcp/ipv4ll.h
@@ -0,0 +1,55 @@
+/*
+ *
+ *  IPV4 Local Link library with GLib integration
+ *
+ *  Copyright (C) 2009-2010  Aldebaran Robotics. 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 __G_IPV4LL_H
+#define __G_IPV4LL_H
+
+#include <glib.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* 169.254.0.0 */
+#define LINKLOCAL_ADDR 0xa9fe0000
+
+/* See RFC 3927 */
+#define PROBE_WAIT	     1
+#define PROBE_NUM	     3
+#define PROBE_MIN	     1
+#define PROBE_MAX	     2
+#define ANNOUNCE_WAIT	     2
+#define ANNOUNCE_NUM	     2
+#define ANNOUNCE_INTERVAL    2
+#define MAX_CONFLICTS	    10
+#define RATE_LIMIT_INTERVAL 60
+#define DEFEND_INTERVAL	    10
+
+uint32_t ipv4ll_random_ip(void);
+guint ipv4ll_random_delay_ms(guint secs);
+int ipv4ll_send_arp_packet(uint8_t* source_eth, uint32_t source_ip,
+		    uint32_t target_ip, int ifindex);
+int ipv4ll_arp_socket(int ifindex);
+
+#ifdef __cplusplus
+}
+#endif
+#endif	    /* !IPV4LL_H_ */
diff --git a/connman/gdhcp/server.c b/connman/gdhcp/server.c
new file mode 100644
index 0000000..8574c24
--- /dev/null
+++ b/connman/gdhcp/server.c
@@ -0,0 +1,910 @@
+/*
+ *
+ *  DHCP Server library with GLib integration
+ *
+ *  Copyright (C) 2009-2012  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 <stdio.h>
+#include <errno.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/ioctl.h>
+#include <arpa/inet.h>
+
+#include <netpacket/packet.h>
+#include <net/ethernet.h>
+#include <net/if_arp.h>
+
+#include <linux/if.h>
+#include <linux/filter.h>
+
+#include <glib.h>
+
+#include "common.h"
+
+/* 8 hours */
+#define DEFAULT_DHCP_LEASE_SEC (8*60*60)
+
+/* 5 minutes  */
+#define OFFER_TIME (5*60)
+
+struct _GDHCPServer {
+	int ref_count;
+	GDHCPType type;
+	bool started;
+	int ifindex;
+	char *interface;
+	uint32_t start_ip;
+	uint32_t end_ip;
+	uint32_t server_nip;	/* our address in network byte order */
+	uint32_t lease_seconds;
+	int listener_sockfd;
+	guint listener_watch;
+	GIOChannel *listener_channel;
+	GList *lease_list;
+	GHashTable *nip_lease_hash;
+	GHashTable *option_hash; /* Options send to client */
+	GDHCPSaveLeaseFunc save_lease_func;
+	GDHCPLeaseAddedCb lease_added_cb;
+	GDHCPDebugFunc debug_func;
+	gpointer debug_data;
+};
+
+struct dhcp_lease {
+	time_t expire;
+	uint32_t lease_nip;
+	uint8_t lease_mac[ETH_ALEN];
+};
+
+static inline void debug(GDHCPServer *server, const char *format, ...)
+{
+	char str[256];
+	va_list ap;
+
+	if (!server->debug_func)
+		return;
+
+	va_start(ap, format);
+
+	if (vsnprintf(str, sizeof(str), format, ap) > 0)
+		server->debug_func(str, server->debug_data);
+
+	va_end(ap);
+}
+
+static struct dhcp_lease *find_lease_by_mac(GDHCPServer *dhcp_server,
+						const uint8_t *mac)
+{
+	GList *list;
+
+	for (list = dhcp_server->lease_list; list; list = list->next) {
+		struct dhcp_lease *lease = list->data;
+
+		if (memcmp(lease->lease_mac, mac, ETH_ALEN) == 0)
+			return lease;
+	}
+
+	return NULL;
+}
+
+static void remove_lease(GDHCPServer *dhcp_server, struct dhcp_lease *lease)
+{
+	dhcp_server->lease_list =
+			g_list_remove(dhcp_server->lease_list, lease);
+
+	g_hash_table_remove(dhcp_server->nip_lease_hash,
+				GINT_TO_POINTER((int) lease->lease_nip));
+	g_free(lease);
+}
+
+/* Clear the old lease and create the new one */
+static int get_lease(GDHCPServer *dhcp_server, uint32_t yiaddr,
+				const uint8_t *mac, struct dhcp_lease **lease)
+{
+	struct dhcp_lease *lease_nip, *lease_mac;
+
+	if (yiaddr == 0)
+		return -ENXIO;
+
+	if (ntohl(yiaddr) < dhcp_server->start_ip)
+		return -ENXIO;
+
+	if (ntohl(yiaddr) > dhcp_server->end_ip)
+		return -ENXIO;
+
+	if (memcmp(mac, MAC_BCAST_ADDR, ETH_ALEN) == 0)
+		return -ENXIO;
+
+	if (memcmp(mac, MAC_ANY_ADDR, ETH_ALEN) == 0)
+		return -ENXIO;
+
+	lease_mac = find_lease_by_mac(dhcp_server, mac);
+
+	lease_nip = g_hash_table_lookup(dhcp_server->nip_lease_hash,
+					GINT_TO_POINTER((int) ntohl(yiaddr)));
+	debug(dhcp_server, "lease_mac %p lease_nip %p", lease_mac, lease_nip);
+
+	if (lease_nip) {
+		dhcp_server->lease_list =
+				g_list_remove(dhcp_server->lease_list,
+								lease_nip);
+		g_hash_table_remove(dhcp_server->nip_lease_hash,
+				GINT_TO_POINTER((int) ntohl(yiaddr)));
+
+		if (!lease_mac)
+			*lease = lease_nip;
+		else if (lease_nip != lease_mac) {
+			remove_lease(dhcp_server, lease_mac);
+			*lease = lease_nip;
+		} else
+			*lease = lease_nip;
+
+		return 0;
+	}
+
+	if (lease_mac) {
+		dhcp_server->lease_list =
+				g_list_remove(dhcp_server->lease_list,
+								lease_mac);
+		g_hash_table_remove(dhcp_server->nip_lease_hash,
+				GINT_TO_POINTER((int) lease_mac->lease_nip));
+		*lease = lease_mac;
+
+		return 0;
+	}
+
+	*lease = g_try_new0(struct dhcp_lease, 1);
+	if (!*lease)
+		return -ENOMEM;
+
+	return 0;
+}
+
+static gint compare_expire(gconstpointer a, gconstpointer b)
+{
+	const struct dhcp_lease *lease1 = a;
+	const struct dhcp_lease *lease2 = b;
+
+	return lease2->expire - lease1->expire;
+}
+
+static struct dhcp_lease *add_lease(GDHCPServer *dhcp_server, uint32_t expire,
+					const uint8_t *chaddr, uint32_t yiaddr)
+{
+	struct dhcp_lease *lease = NULL;
+	int ret;
+
+	ret = get_lease(dhcp_server, yiaddr, chaddr, &lease);
+	if (ret != 0)
+		return NULL;
+
+	memset(lease, 0, sizeof(*lease));
+
+	memcpy(lease->lease_mac, chaddr, ETH_ALEN);
+	lease->lease_nip = ntohl(yiaddr);
+
+	if (expire == 0)
+		lease->expire = time(NULL) + dhcp_server->lease_seconds;
+	else
+		lease->expire = expire;
+
+	dhcp_server->lease_list = g_list_insert_sorted(dhcp_server->lease_list,
+							lease, compare_expire);
+
+	g_hash_table_insert(dhcp_server->nip_lease_hash,
+				GINT_TO_POINTER((int) lease->lease_nip), lease);
+
+	if (dhcp_server->lease_added_cb)
+		dhcp_server->lease_added_cb(lease->lease_mac, yiaddr);
+
+	return lease;
+}
+
+static struct dhcp_lease *find_lease_by_nip(GDHCPServer *dhcp_server,
+								uint32_t nip)
+{
+	return g_hash_table_lookup(dhcp_server->nip_lease_hash,
+						GINT_TO_POINTER((int) nip));
+}
+
+/* Check if the IP is taken; if it is, add it to the lease table */
+static bool arp_check(uint32_t nip, const uint8_t *safe_mac)
+{
+	/* TODO: Add ARP checking */
+	return true;
+}
+
+static bool is_expired_lease(struct dhcp_lease *lease)
+{
+	if (lease->expire < time(NULL))
+		return true;
+
+	return false;
+}
+
+static uint32_t find_free_or_expired_nip(GDHCPServer *dhcp_server,
+					const uint8_t *safe_mac)
+{
+	uint32_t ip_addr;
+	struct dhcp_lease *lease;
+	GList *list;
+	ip_addr = dhcp_server->start_ip;
+	for (; ip_addr <= dhcp_server->end_ip; ip_addr++) {
+		/* e.g. 192.168.55.0 */
+		if ((ip_addr & 0xff) == 0)
+			continue;
+
+		/* e.g. 192.168.55.255 */
+		if ((ip_addr & 0xff) == 0xff)
+			continue;
+
+		lease = find_lease_by_nip(dhcp_server, ip_addr);
+		if (lease)
+			continue;
+
+		if (arp_check(htonl(ip_addr), safe_mac))
+			return ip_addr;
+	}
+
+	/* The last lease is the oldest one */
+	list = g_list_last(dhcp_server->lease_list);
+	if (!list)
+		return 0;
+
+	lease = list->data;
+	if (!lease)
+		return 0;
+
+	 if (!is_expired_lease(lease))
+		return 0;
+
+	 if (!arp_check(lease->lease_nip, safe_mac))
+		return 0;
+
+	return lease->lease_nip;
+}
+
+static void lease_set_expire(GDHCPServer *dhcp_server,
+			struct dhcp_lease *lease, uint32_t expire)
+{
+	dhcp_server->lease_list = g_list_remove(dhcp_server->lease_list, lease);
+
+	lease->expire = expire;
+
+	dhcp_server->lease_list = g_list_insert_sorted(dhcp_server->lease_list,
+							lease, compare_expire);
+}
+
+static void destroy_lease_table(GDHCPServer *dhcp_server)
+{
+	GList *list;
+
+	g_hash_table_destroy(dhcp_server->nip_lease_hash);
+
+	dhcp_server->nip_lease_hash = NULL;
+
+	for (list = dhcp_server->lease_list; list; list = list->next) {
+		struct dhcp_lease *lease = list->data;
+
+		g_free(lease);
+	}
+
+	g_list_free(dhcp_server->lease_list);
+
+	dhcp_server->lease_list = NULL;
+}
+static uint32_t get_interface_address(int index)
+{
+	struct ifreq ifr;
+	int sk, err;
+	struct sockaddr_in *server_ip;
+	uint32_t ret = 0;
+
+	sk = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
+	if (sk < 0) {
+		perror("Open socket error");
+		return 0;
+	}
+
+	memset(&ifr, 0, sizeof(ifr));
+	ifr.ifr_ifindex = index;
+
+	err = ioctl(sk, SIOCGIFNAME, &ifr);
+	if (err < 0) {
+		perror("Get interface name error");
+		goto done;
+	}
+
+	err = ioctl(sk, SIOCGIFADDR, &ifr);
+	if (err < 0) {
+		perror("Get ip address error");
+		goto done;
+	}
+
+	server_ip = (struct sockaddr_in *) &ifr.ifr_addr;
+	ret = server_ip->sin_addr.s_addr;
+
+done:
+	close(sk);
+
+	return ret;
+}
+
+GDHCPServer *g_dhcp_server_new(GDHCPType type,
+		int ifindex, GDHCPServerError *error)
+{
+	GDHCPServer *dhcp_server = NULL;
+
+	if (ifindex < 0) {
+		*error = G_DHCP_SERVER_ERROR_INVALID_INDEX;
+		return NULL;
+	}
+
+	dhcp_server = g_try_new0(GDHCPServer, 1);
+	if (!dhcp_server) {
+		*error = G_DHCP_SERVER_ERROR_NOMEM;
+		return NULL;
+	}
+
+	dhcp_server->interface = get_interface_name(ifindex);
+	if (!dhcp_server->interface) {
+		*error = G_DHCP_SERVER_ERROR_INTERFACE_UNAVAILABLE;
+		goto error;
+	}
+
+	if (!interface_is_up(ifindex)) {
+		*error = G_DHCP_SERVER_ERROR_INTERFACE_DOWN;
+		goto error;
+	}
+
+	dhcp_server->server_nip = get_interface_address(ifindex);
+	if (dhcp_server->server_nip == 0) {
+		*error = G_DHCP_SERVER_ERROR_IP_ADDRESS_INVALID;
+		goto error;
+	}
+
+	dhcp_server->nip_lease_hash = g_hash_table_new_full(g_direct_hash,
+						g_direct_equal, NULL, NULL);
+	dhcp_server->option_hash = g_hash_table_new_full(g_direct_hash,
+						g_direct_equal, NULL, NULL);
+
+	dhcp_server->started = FALSE;
+
+	/* All the leases have the same fixed lease time,
+	 * do not support DHCP_LEASE_TIME option from client.
+	 */
+	dhcp_server->lease_seconds = DEFAULT_DHCP_LEASE_SEC;
+
+	dhcp_server->type = type;
+	dhcp_server->ref_count = 1;
+	dhcp_server->ifindex = ifindex;
+	dhcp_server->listener_sockfd = -1;
+	dhcp_server->listener_watch = -1;
+	dhcp_server->listener_channel = NULL;
+	dhcp_server->save_lease_func = NULL;
+	dhcp_server->debug_func = NULL;
+	dhcp_server->debug_data = NULL;
+
+	*error = G_DHCP_SERVER_ERROR_NONE;
+
+	return dhcp_server;
+
+error:
+	g_free(dhcp_server->interface);
+	g_free(dhcp_server);
+	return NULL;
+}
+
+
+static uint8_t check_packet_type(struct dhcp_packet *packet)
+{
+	uint8_t *type;
+
+	if (packet->hlen != ETH_ALEN)
+		return 0;
+
+	if (packet->op != BOOTREQUEST)
+		return 0;
+
+	type = dhcp_get_option(packet, DHCP_MESSAGE_TYPE);
+
+	if (!type)
+		return 0;
+
+	if (*type < DHCP_MINTYPE)
+		return 0;
+
+	if (*type > DHCP_MAXTYPE)
+		return 0;
+
+	return *type;
+}
+
+static void init_packet(GDHCPServer *dhcp_server, struct dhcp_packet *packet,
+				struct dhcp_packet *client_packet, char type)
+{
+	/* Sets op, htype, hlen, cookie fields
+	 * and adds DHCP_MESSAGE_TYPE option */
+	dhcp_init_header(packet, type);
+
+	packet->xid = client_packet->xid;
+	memcpy(packet->chaddr, client_packet->chaddr,
+				sizeof(client_packet->chaddr));
+	packet->flags = client_packet->flags;
+	packet->gateway_nip = client_packet->gateway_nip;
+	packet->ciaddr = client_packet->ciaddr;
+	dhcp_add_option_uint32(packet, DHCP_SERVER_ID,
+					ntohl(dhcp_server->server_nip));
+}
+
+static void add_option(gpointer key, gpointer value, gpointer user_data)
+{
+	const char *option_value = value;
+	uint8_t option_code = GPOINTER_TO_INT(key);
+	struct in_addr nip;
+	struct dhcp_packet *packet = user_data;
+
+	if (!option_value)
+		return;
+
+	switch (option_code) {
+	case G_DHCP_SUBNET:
+	case G_DHCP_ROUTER:
+	case G_DHCP_DNS_SERVER:
+		if (inet_aton(option_value, &nip) == 0)
+			return;
+
+		dhcp_add_option_uint32(packet, (uint8_t) option_code,
+							ntohl(nip.s_addr));
+		break;
+	default:
+		return;
+	}
+}
+
+static void add_server_options(GDHCPServer *dhcp_server,
+				struct dhcp_packet *packet)
+{
+	g_hash_table_foreach(dhcp_server->option_hash,
+				add_option, packet);
+}
+
+static bool check_requested_nip(GDHCPServer *dhcp_server,
+					uint32_t requested_nip)
+{
+	struct dhcp_lease *lease;
+
+	if (requested_nip == 0)
+		return false;
+
+	if (requested_nip < dhcp_server->start_ip)
+		return false;
+
+	if (requested_nip > dhcp_server->end_ip)
+		return false;
+
+	lease = find_lease_by_nip(dhcp_server, requested_nip);
+	if (!lease)
+		return true;
+
+	if (!is_expired_lease(lease))
+		return false;
+
+	return true;
+}
+
+static void send_packet_to_client(GDHCPServer *dhcp_server,
+				struct dhcp_packet *dhcp_pkt)
+{
+	const uint8_t *chaddr;
+	uint32_t ciaddr;
+
+	if ((dhcp_pkt->flags & htons(BROADCAST_FLAG))
+				|| dhcp_pkt->ciaddr == 0) {
+		debug(dhcp_server, "Broadcasting packet to client");
+		ciaddr = INADDR_BROADCAST;
+		chaddr = MAC_BCAST_ADDR;
+	} else {
+		debug(dhcp_server, "Unicasting packet to client ciaddr");
+		ciaddr = dhcp_pkt->ciaddr;
+		chaddr = dhcp_pkt->chaddr;
+	}
+
+	dhcp_send_raw_packet(dhcp_pkt,
+		dhcp_server->server_nip, SERVER_PORT,
+		ciaddr, CLIENT_PORT, chaddr,
+		dhcp_server->ifindex, false);
+}
+
+static void send_offer(GDHCPServer *dhcp_server,
+			struct dhcp_packet *client_packet,
+				struct dhcp_lease *lease,
+					uint32_t requested_nip)
+{
+	struct dhcp_packet packet;
+	struct in_addr addr;
+
+	init_packet(dhcp_server, &packet, client_packet, DHCPOFFER);
+
+	if (lease)
+		packet.yiaddr = htonl(lease->lease_nip);
+	else if (check_requested_nip(dhcp_server, requested_nip))
+		packet.yiaddr = htonl(requested_nip);
+	else
+		packet.yiaddr = htonl(find_free_or_expired_nip(
+					dhcp_server, client_packet->chaddr));
+
+	debug(dhcp_server, "find yiaddr %u", packet.yiaddr);
+
+	if (!packet.yiaddr) {
+		debug(dhcp_server, "Err: Can not found lease and send offer");
+		return;
+	}
+
+	lease = add_lease(dhcp_server, OFFER_TIME,
+				packet.chaddr, packet.yiaddr);
+	if (!lease) {
+		debug(dhcp_server,
+				"Err: No free IP addresses. OFFER abandoned");
+		return;
+	}
+
+	dhcp_add_option_uint32(&packet, DHCP_LEASE_TIME,
+						dhcp_server->lease_seconds);
+	add_server_options(dhcp_server, &packet);
+
+	addr.s_addr = packet.yiaddr;
+
+	debug(dhcp_server, "Sending OFFER of %s", inet_ntoa(addr));
+	send_packet_to_client(dhcp_server, &packet);
+}
+
+static void save_lease(GDHCPServer *dhcp_server)
+{
+	GList *list;
+
+	if (!dhcp_server->save_lease_func)
+		return;
+
+	for (list = dhcp_server->lease_list; list; list = list->next) {
+		struct dhcp_lease *lease = list->data;
+		dhcp_server->save_lease_func(lease->lease_mac,
+					lease->lease_nip, lease->expire);
+	}
+}
+
+static void send_ACK(GDHCPServer *dhcp_server,
+		struct dhcp_packet *client_packet, uint32_t dest)
+{
+	struct dhcp_packet packet;
+	uint32_t lease_time_sec;
+	struct in_addr addr;
+
+	init_packet(dhcp_server, &packet, client_packet, DHCPACK);
+	packet.yiaddr = htonl(dest);
+
+	lease_time_sec = dhcp_server->lease_seconds;
+
+	dhcp_add_option_uint32(&packet, DHCP_LEASE_TIME, lease_time_sec);
+
+	add_server_options(dhcp_server, &packet);
+
+	addr.s_addr = htonl(dest);
+
+	debug(dhcp_server, "Sending ACK to %s", inet_ntoa(addr));
+
+	send_packet_to_client(dhcp_server, &packet);
+
+	add_lease(dhcp_server, 0, packet.chaddr, packet.yiaddr);
+}
+
+static void send_NAK(GDHCPServer *dhcp_server,
+			struct dhcp_packet *client_packet)
+{
+	struct dhcp_packet packet;
+
+	init_packet(dhcp_server, &packet, client_packet, DHCPNAK);
+
+	debug(dhcp_server, "Sending NAK");
+
+	dhcp_send_raw_packet(&packet,
+			dhcp_server->server_nip, SERVER_PORT,
+			INADDR_BROADCAST, CLIENT_PORT, MAC_BCAST_ADDR,
+			dhcp_server->ifindex, false);
+}
+
+static void send_inform(GDHCPServer *dhcp_server,
+				struct dhcp_packet *client_packet)
+{
+	struct dhcp_packet packet;
+
+	init_packet(dhcp_server, &packet, client_packet, DHCPACK);
+	add_server_options(dhcp_server, &packet);
+	send_packet_to_client(dhcp_server, &packet);
+}
+
+static gboolean listener_event(GIOChannel *channel, GIOCondition condition,
+							gpointer user_data)
+{
+	GDHCPServer *dhcp_server = user_data;
+	struct dhcp_packet packet;
+	struct dhcp_lease *lease;
+	uint32_t requested_nip = 0;
+	uint8_t type, *server_id_option, *request_ip_option;
+	int re;
+
+	if (condition & (G_IO_NVAL | G_IO_ERR | G_IO_HUP)) {
+		dhcp_server->listener_watch = 0;
+		return FALSE;
+	}
+
+	re = dhcp_recv_l3_packet(&packet, dhcp_server->listener_sockfd);
+	if (re < 0)
+		return TRUE;
+
+	type = check_packet_type(&packet);
+	if (type == 0)
+		return TRUE;
+
+	server_id_option = dhcp_get_option(&packet, DHCP_SERVER_ID);
+	if (server_id_option) {
+		uint32_t server_nid =
+			get_unaligned((const uint32_t *) server_id_option);
+
+		if (server_nid != dhcp_server->server_nip)
+			return TRUE;
+	}
+
+	request_ip_option = dhcp_get_option(&packet, DHCP_REQUESTED_IP);
+	if (request_ip_option)
+		requested_nip = get_be32(request_ip_option);
+
+	lease = find_lease_by_mac(dhcp_server, packet.chaddr);
+
+	switch (type) {
+	case DHCPDISCOVER:
+		debug(dhcp_server, "Received DISCOVER");
+
+		send_offer(dhcp_server, &packet, lease, requested_nip);
+		break;
+	case DHCPREQUEST:
+		debug(dhcp_server, "Received REQUEST NIP %d",
+							requested_nip);
+		if (requested_nip == 0) {
+			requested_nip = packet.ciaddr;
+			if (requested_nip == 0)
+				break;
+		}
+
+		if (lease && requested_nip == lease->lease_nip) {
+			debug(dhcp_server, "Sending ACK");
+			send_ACK(dhcp_server, &packet,
+				lease->lease_nip);
+			break;
+		}
+
+		if (server_id_option || !lease) {
+			debug(dhcp_server, "Sending NAK");
+			send_NAK(dhcp_server, &packet);
+		}
+
+		break;
+	case DHCPDECLINE:
+		debug(dhcp_server, "Received DECLINE");
+
+		if (!server_id_option)
+			break;
+
+		if (!request_ip_option)
+			break;
+
+		if (!lease)
+			break;
+
+		if (requested_nip == lease->lease_nip)
+			remove_lease(dhcp_server, lease);
+
+		break;
+	case DHCPRELEASE:
+		debug(dhcp_server, "Received RELEASE");
+
+		if (!server_id_option)
+			break;
+
+		if (!lease)
+			break;
+
+		if (packet.ciaddr == lease->lease_nip)
+			lease_set_expire(dhcp_server, lease,
+					time(NULL));
+		break;
+	case DHCPINFORM:
+		debug(dhcp_server, "Received INFORM");
+		send_inform(dhcp_server, &packet);
+		break;
+	}
+
+	return TRUE;
+}
+
+/* Caller need to load leases before call it */
+int g_dhcp_server_start(GDHCPServer *dhcp_server)
+{
+	GIOChannel *listener_channel;
+	int listener_sockfd;
+
+	if (dhcp_server->started)
+		return 0;
+
+	listener_sockfd = dhcp_l3_socket(SERVER_PORT,
+					dhcp_server->interface, AF_INET);
+	if (listener_sockfd < 0)
+		return -EIO;
+
+	listener_channel = g_io_channel_unix_new(listener_sockfd);
+	if (!listener_channel) {
+		close(listener_sockfd);
+		return -EIO;
+	}
+
+	dhcp_server->listener_sockfd = listener_sockfd;
+	dhcp_server->listener_channel = listener_channel;
+
+	g_io_channel_set_close_on_unref(listener_channel, TRUE);
+	dhcp_server->listener_watch =
+			g_io_add_watch_full(listener_channel, G_PRIORITY_HIGH,
+				G_IO_IN | G_IO_NVAL | G_IO_ERR | G_IO_HUP,
+						listener_event, dhcp_server,
+								NULL);
+	g_io_channel_unref(dhcp_server->listener_channel);
+
+	dhcp_server->started = TRUE;
+
+	return 0;
+}
+
+int g_dhcp_server_set_option(GDHCPServer *dhcp_server,
+		unsigned char option_code, const char *option_value)
+{
+	struct in_addr nip;
+
+	if (!option_value)
+		return -EINVAL;
+
+	debug(dhcp_server, "option_code %d option_value %s",
+					option_code, option_value);
+	switch (option_code) {
+	case G_DHCP_SUBNET:
+	case G_DHCP_ROUTER:
+	case G_DHCP_DNS_SERVER:
+		if (inet_aton(option_value, &nip) == 0)
+			return -ENXIO;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	g_hash_table_replace(dhcp_server->option_hash,
+			GINT_TO_POINTER((int) option_code),
+					(gpointer) option_value);
+	return 0;
+}
+
+void g_dhcp_server_set_save_lease(GDHCPServer *dhcp_server,
+				GDHCPSaveLeaseFunc func, gpointer user_data)
+{
+	if (!dhcp_server)
+		return;
+
+	dhcp_server->save_lease_func = func;
+}
+
+void g_dhcp_server_set_lease_added_cb(GDHCPServer *dhcp_server,
+							GDHCPLeaseAddedCb cb)
+{
+	if (!dhcp_server)
+		return;
+
+	dhcp_server->lease_added_cb = cb;
+}
+
+GDHCPServer *g_dhcp_server_ref(GDHCPServer *dhcp_server)
+{
+	if (!dhcp_server)
+		return NULL;
+
+	__sync_fetch_and_add(&dhcp_server->ref_count, 1);
+
+	return dhcp_server;
+}
+
+void g_dhcp_server_stop(GDHCPServer *dhcp_server)
+{
+	/* Save leases, before stop; load them before start */
+	save_lease(dhcp_server);
+
+	if (dhcp_server->listener_watch > 0) {
+		g_source_remove(dhcp_server->listener_watch);
+		dhcp_server->listener_watch = 0;
+	}
+
+	dhcp_server->listener_channel = NULL;
+
+	dhcp_server->started = FALSE;
+}
+
+void g_dhcp_server_unref(GDHCPServer *dhcp_server)
+{
+	if (!dhcp_server)
+		return;
+
+	if (__sync_fetch_and_sub(&dhcp_server->ref_count, 1) != 1)
+		return;
+
+	g_dhcp_server_stop(dhcp_server);
+
+	g_hash_table_destroy(dhcp_server->option_hash);
+
+	destroy_lease_table(dhcp_server);
+
+	g_free(dhcp_server->interface);
+
+	g_free(dhcp_server);
+}
+
+int g_dhcp_server_set_ip_range(GDHCPServer *dhcp_server,
+		const char *start_ip, const char *end_ip)
+{
+	struct in_addr _host_addr;
+
+	if (inet_aton(start_ip, &_host_addr) == 0)
+		return -ENXIO;
+
+	dhcp_server->start_ip = ntohl(_host_addr.s_addr);
+
+	if (inet_aton(end_ip, &_host_addr) == 0)
+		return -ENXIO;
+
+	dhcp_server->end_ip = ntohl(_host_addr.s_addr);
+
+	return 0;
+}
+
+void g_dhcp_server_set_lease_time(GDHCPServer *dhcp_server,
+					unsigned int lease_time)
+{
+	if (!dhcp_server)
+		return;
+
+	dhcp_server->lease_seconds = lease_time;
+}
+
+void g_dhcp_server_set_debug(GDHCPServer *dhcp_server,
+				GDHCPDebugFunc func, gpointer user_data)
+{
+	if (!dhcp_server)
+		return;
+
+	dhcp_server->debug_func = func;
+	dhcp_server->debug_data = user_data;
+}
diff --git a/connman/gdhcp/timer.c b/connman/gdhcp/timer.c
new file mode 100644
index 0000000..db47817
--- /dev/null
+++ b/connman/gdhcp/timer.c
@@ -0,0 +1,222 @@
+/*
+ *  Realtime timer with GLib integration
+ *
+ *  Copyright (C) 2014  Nest Labs. 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
+ *
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <syslog.h>
+#include <errno.h>
+
+#include "timer.h"
+
+/*
+ * A GLib custom event source using a POSIX fd timer that becomes
+ * 'ready' on timer expiration. Timer 'advances' across a suspend but
+ * has no ability to bring system out of suspend. Timer will fire upon
+ * resume if expired.
+ */
+
+typedef struct _GRTimeoutSource GRTimeoutSource;
+
+struct _GRTimeoutSource
+{
+	GSource	source;
+	GPollFD	pfd;
+	guint interval;
+        gpointer tag;
+};
+
+static gboolean g_rttimeout_prepare (GSource *source, gint *timeout);
+static gboolean g_rttimeout_check (GSource *source);
+static gboolean g_rttimeout_dispatch (GSource *source, GSourceFunc callback,
+				     gpointer user_data);
+
+GSourceFuncs g_rttimeout_funcs =
+{
+	g_rttimeout_prepare,
+	g_rttimeout_check,
+	g_rttimeout_dispatch,
+	NULL
+};
+
+void g_rttimeout_info(const char *format, ...)
+{
+	va_list ap;
+
+	va_start(ap, format);
+	vsyslog(LOG_INFO, format, ap);
+	va_end(ap);
+}
+
+static gboolean g_rttimeout_prepare (GSource *source, gint *timeout)
+{
+	*timeout = -1;
+
+	return FALSE;
+}
+
+static gboolean g_rttimeout_check (GSource *source)
+{
+	GRTimeoutSource *timeout_source = (GRTimeoutSource *)source;
+
+	return timeout_source->pfd.revents & G_IO_IN;
+}
+
+static gboolean
+g_rttimeout_dispatch (GSource *source, GSourceFunc callback, gpointer user_data)
+{
+	GRTimeoutSource *timeout_source = (GRTimeoutSource *)source;
+	gboolean again;
+
+	g_rttimeout_info("DHCP: %s: fd=%d, source=%p, user_data=%p",
+			__func__, timeout_source->pfd.fd, source, user_data);
+	if (!callback) {
+		g_warning ("GR timeout source dispatched without callback\n"
+			   "You must call g_source_set_callback().");
+		if (!g_source_is_destroyed (source)) {
+			g_source_remove_poll (source, &timeout_source->pfd);
+			close(timeout_source->pfd.fd);
+		}
+		return FALSE;
+	}
+
+	again = callback (user_data);
+
+	if (again) {
+		struct itimerspec timer_value;
+		int result;
+
+		/* arm the timer as a single-shot */
+		timer_value.it_value.tv_sec = timeout_source->interval;
+		timer_value.it_value.tv_nsec = 0;
+		timer_value.it_interval.tv_sec = 0;
+		timer_value.it_interval.tv_nsec = 0;
+
+		result = timerfd_settime (timeout_source->pfd.fd, 0,
+					  &timer_value, NULL);
+		if (result == -1)
+			g_error ("%s: error calling timer_settime", G_STRLOC);
+	} else {
+		if (!g_source_is_destroyed (source)) {
+			g_source_remove_poll (source, &timeout_source->pfd);
+			close(timeout_source->pfd.fd);
+		}
+	}
+
+	return again;
+}
+
+/**
+ * g_rttimeout_add_seconds_full:
+ */
+guint g_rttimeout_add_seconds_full (gint type, gint priority, guint32 interval,
+				   GSourceFunc function, gpointer data,
+				   GDestroyNotify notify)
+{
+  return g_rttimeout_add_full(type, priority, interval * 1000,
+				   function, data, notify);
+}
+
+/**
+ * g_rttimeout_add_full:
+ */
+guint g_rttimeout_add_full (gint type, gint priority, guint32 interval,
+			   GSourceFunc function, gpointer data,
+			   GDestroyNotify notify)
+{
+	GSource *source;
+	int fd;
+	guint id;
+        gpointer tag;
+
+	g_return_val_if_fail (function != NULL, 0);
+
+	source = g_source_new (&g_rttimeout_funcs, sizeof (GRTimeoutSource));
+	if (priority != G_PRIORITY_DEFAULT)
+		g_source_set_priority (source, priority);
+	g_source_set_callback (source, function, data, notify);
+	id = g_source_attach (source, NULL);
+	g_source_unref (source);
+
+	fd = timerfd_create(type, 0);
+	if (fd != -1) {
+		GRTimeoutSource *timeout_source = (GRTimeoutSource *)source;
+		struct itimerspec timer_value;
+		int result;
+
+		g_rttimeout_info("DHCP: %s: id=%d fd=%d, source=%p, seconds=%d",
+				__func__, id, fd, source, interval/1000);
+		memset(&timer_value, 0, sizeof(struct itimerspec));
+
+		timer_value.it_value.tv_sec = interval / 1000;
+		timer_value.it_value.tv_nsec = 0;
+
+		/* arm the timer as a single-shot */
+		result = timerfd_settime (fd, 0, &timer_value,
+					  NULL);
+		if (result != -1) {
+			timeout_source->interval = interval;
+			timeout_source->pfd.fd = fd;
+			timeout_source->pfd.events = G_IO_IN;
+
+                        tag = g_source_add_unix_fd(source, fd, G_IO_IN);
+
+                        if (tag != NULL) {
+                            timeout_source->tag = tag;
+                        } else {
+                            g_rttimeout_info("DHCP: %s: cannot attach fd to source\n", __func__);
+                            g_error ("%s: error calling g_source_add_unix_fd", G_STRLOC);
+                        }
+		} else {
+			g_rttimeout_info("DHCP: %s: error timerfd_settime, err=%d\n",
+				__func__, errno);
+			g_error ("%s: error calling timerfd_settime", G_STRLOC);
+		}
+	} else {
+		g_error ("%s: error calling timerfd_create", G_STRLOC);
+	}
+
+	return id;
+}
+
+gboolean g_rttimeout_source_remove(guint id)
+{
+	GSource *source;
+
+	g_return_val_if_fail (id > 0, FALSE);
+	source = g_main_context_find_source_by_id (NULL, id);
+	if (source) {
+		GRTimeoutSource *timeout_source = (GRTimeoutSource *)source;
+
+		if (!g_source_is_destroyed (source)) {
+			g_rttimeout_info("DHCP: %s: id=%d fd=%d source=%p",
+					__func__, id, timeout_source->pfd.fd,
+					source);
+                        g_source_remove_unix_fd(source, timeout_source->tag);
+			close(timeout_source->pfd.fd);
+			g_source_destroy (source);
+		}
+	} else {
+		g_rttimeout_info("DHCP: %s: id=%d not found", __func__, id);
+	}
+
+	return source != NULL;
+}
diff --git a/connman/gdhcp/timer.h b/connman/gdhcp/timer.h
new file mode 100644
index 0000000..2c7085b
--- /dev/null
+++ b/connman/gdhcp/timer.h
@@ -0,0 +1,36 @@
+/*
+ *
+ *  Realtime timer with GLib integration
+ *
+ *  Copyright (C) 2014  Nest Labs. 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
+ *
+ */
+#include <sys/timerfd.h>
+#include <glib.h>
+
+#define G_CLOCK_REALTIME CLOCK_REALTIME
+/* if your kernel supports */
+/* #define G_CLOCK_BOOTTIME CLOCK_BOOTTIME */
+
+guint g_rttimeout_add_seconds_full (gint type, gint priority, guint32 interval,
+				   GSourceFunc function, gpointer data,
+				   GDestroyNotify notify);
+
+guint g_rttimeout_add_full (gint type, gint priority, guint32 interval,
+			   GSourceFunc function, gpointer data,
+			   GDestroyNotify notify);
+
+gboolean g_rttimeout_source_remove(guint id);
diff --git a/connman/gdhcp/unaligned.h b/connman/gdhcp/unaligned.h
new file mode 100644
index 0000000..ffdaae2
--- /dev/null
+++ b/connman/gdhcp/unaligned.h
@@ -0,0 +1,163 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2012  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
+ *
+ */
+
+#include <endian.h>
+#include <byteswap.h>
+
+#define get_unaligned(ptr)			\
+({						\
+	struct __attribute__((packed)) {	\
+		typeof(*(ptr)) __v;		\
+	} *__p = (typeof(__p)) (ptr);		\
+	__p->__v;				\
+})
+
+#define put_unaligned(val, ptr)			\
+do {						\
+	struct __attribute__((packed)) {	\
+		typeof(*(ptr)) __v;		\
+	} *__p = (typeof(__p)) (ptr);		\
+	__p->__v = (val);			\
+} while(0)
+
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+static inline uint64_t get_le64(const void *ptr)
+{
+	return get_unaligned((const uint64_t *) ptr);
+}
+
+static inline uint64_t get_be64(const void *ptr)
+{
+	return bswap_64(get_unaligned((const uint64_t *) ptr));
+}
+
+static inline uint32_t get_le32(const void *ptr)
+{
+	return get_unaligned((const uint32_t *) ptr);
+}
+
+static inline uint32_t get_be32(const void *ptr)
+{
+	return bswap_32(get_unaligned((const uint32_t *) ptr));
+}
+
+static inline uint16_t get_le16(const void *ptr)
+{
+	return get_unaligned((const uint16_t *) ptr);
+}
+
+static inline uint16_t get_be16(const void *ptr)
+{
+	return bswap_16(get_unaligned((const uint16_t *) ptr));
+}
+
+static inline void put_be16(uint16_t val, void *ptr)
+{
+	put_unaligned(bswap_16(val), (uint16_t *) ptr);
+}
+
+static inline void put_be32(uint32_t val, void *ptr)
+{
+	put_unaligned(bswap_32(val), (uint32_t *) ptr);
+}
+
+static inline void put_le16(uint16_t val, void *ptr)
+{
+	put_unaligned(val, (uint16_t *) ptr);
+}
+
+static inline void put_le32(uint32_t val, void *ptr)
+{
+	put_unaligned(val, (uint32_t *) ptr);
+}
+
+static inline void put_be64(uint64_t val, void *ptr)
+{
+	put_unaligned(bswap_64(val), (uint64_t *) ptr);
+}
+
+static inline void put_le64(uint64_t val, void *ptr)
+{
+	put_unaligned(val, (uint64_t *) ptr);
+}
+#elif __BYTE_ORDER == __BIG_ENDIAN
+static inline uint64_t get_le64(const void *ptr)
+{
+	return bswap_64(get_unaligned((const uint64_t *) ptr));
+}
+
+static inline uint64_t get_be64(const void *ptr)
+{
+	return get_unaligned((const uint64_t *) ptr);
+}
+
+static inline uint32_t get_le32(const void *ptr)
+{
+	return bswap_32(get_unaligned((const uint32_t *) ptr));
+}
+
+static inline uint32_t get_be32(const void *ptr)
+{
+	return get_unaligned((const uint32_t *) ptr);
+}
+
+static inline uint16_t get_le16(const void *ptr)
+{
+	return bswap_16(get_unaligned((const uint16_t *) ptr));
+}
+
+static inline uint16_t get_be16(const void *ptr)
+{
+	return get_unaligned((const uint16_t *) ptr);
+}
+
+static inline void put_be16(uint16_t val, void *ptr)
+{
+	put_unaligned(val, (uint16_t *) ptr);
+}
+
+static inline void put_be32(uint32_t val, void *ptr)
+{
+	put_unaligned(val, (uint32_t *) ptr);
+}
+
+static inline void put_le16(uint16_t val, void *ptr)
+{
+	put_unaligned(bswap_16(val), (uint16_t *) ptr);
+}
+
+static inline void put_le32(uint32_t val, void *ptr)
+{
+	put_unaligned(bswap_32(val), (uint32_t *) ptr);
+}
+
+static inline void put_be64(uint64_t val, void *ptr)
+{
+	put_unaligned(val, (uint64_t *) ptr);
+}
+
+static inline void put_le64(uint64_t val, void *ptr)
+{
+	put_unaligned(bswap_64(val), (uint64_t *) ptr);
+}
+#else
+#error "Unknown byte order"
+#endif
diff --git a/connman/gsupplicant/dbus.c b/connman/gsupplicant/dbus.c
new file mode 100644
index 0000000..cb2aace
--- /dev/null
+++ b/connman/gsupplicant/dbus.c
@@ -0,0 +1,651 @@
+/*
+ *
+ *  WPA supplicant library with GLib integration
+ *
+ *  Copyright (C) 2012-2013  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 <string.h>
+#include <dbus/dbus.h>
+#include <glib.h>
+
+#include "dbus.h"
+
+#define TIMEOUT 30000
+
+static DBusConnection *connection;
+
+static GSList *method_calls;
+
+struct method_call_data {
+	gpointer caller;
+	DBusPendingCall *pending_call;
+	supplicant_dbus_result_function function;
+	void *user_data;
+};
+
+static void method_call_free(void *pointer)
+{
+	struct method_call_data *method_call = pointer;
+	method_calls = g_slist_remove(method_calls, method_call);
+	g_free(method_call);
+}
+
+static int find_method_call_by_caller(gconstpointer a, gconstpointer b)
+{
+	const struct method_call_data *method_call = a;
+	gconstpointer caller = b;
+
+	return method_call->caller != caller;
+}
+
+static GSList *property_calls;
+
+struct property_call_data {
+	gpointer caller;
+	DBusPendingCall *pending_call;
+	supplicant_dbus_property_function function;
+	void *user_data;
+};
+
+static void property_call_free(void *pointer)
+{
+	struct property_call_data *property_call = pointer;
+	property_calls = g_slist_remove(property_calls, property_call);
+	g_free(property_call);
+}
+
+static int find_property_call_by_caller(gconstpointer a, gconstpointer b)
+{
+	const struct property_call_data *property_call = a;
+	gconstpointer caller = b;
+
+	return property_call->caller != caller;
+}
+
+void supplicant_dbus_setup(DBusConnection *conn)
+{
+	connection = conn;
+	method_calls = NULL;
+	property_calls = NULL;
+}
+
+void supplicant_dbus_array_foreach(DBusMessageIter *iter,
+				supplicant_dbus_array_function function,
+							void *user_data)
+{
+	DBusMessageIter entry;
+
+	if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_ARRAY)
+		return;
+
+	dbus_message_iter_recurse(iter, &entry);
+
+	while (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_INVALID) {
+		if (function)
+			function(&entry, user_data);
+
+		dbus_message_iter_next(&entry);
+	}
+}
+
+void supplicant_dbus_property_foreach(DBusMessageIter *iter,
+				supplicant_dbus_property_function function,
+							void *user_data)
+{
+	DBusMessageIter dict;
+
+	if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_ARRAY)
+		return;
+
+	dbus_message_iter_recurse(iter, &dict);
+
+	while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
+		DBusMessageIter entry, value;
+		const char *key;
+
+		dbus_message_iter_recurse(&dict, &entry);
+
+		if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING)
+			return;
+
+		dbus_message_iter_get_basic(&entry, &key);
+		dbus_message_iter_next(&entry);
+
+		if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_VARIANT)
+			return;
+
+		dbus_message_iter_recurse(&entry, &value);
+
+		if (key) {
+			if (strcmp(key, "Properties") == 0)
+				supplicant_dbus_property_foreach(&value,
+							function, user_data);
+			else if (function)
+				function(key, &value, user_data);
+		}
+
+		dbus_message_iter_next(&dict);
+	}
+}
+
+void supplicant_dbus_property_call_cancel_all(gpointer caller)
+{
+	while (property_calls) {
+		struct property_call_data *property_call;
+		GSList *elem = g_slist_find_custom(property_calls, caller,
+						find_property_call_by_caller);
+		if (!elem)
+			break;
+
+		property_call = elem->data;
+		property_calls = g_slist_delete_link(property_calls, elem);
+
+		dbus_pending_call_cancel(property_call->pending_call);
+
+		dbus_pending_call_unref(property_call->pending_call);
+	}
+}
+
+static void property_get_all_reply(DBusPendingCall *call, void *user_data)
+{
+	struct property_call_data *property_call = user_data;
+	DBusMessage *reply;
+	DBusMessageIter iter;
+
+	reply = dbus_pending_call_steal_reply(call);
+
+	if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR)
+		goto done;
+
+	if (!dbus_message_iter_init(reply, &iter))
+		goto done;
+
+	supplicant_dbus_property_foreach(&iter, property_call->function,
+						property_call->user_data);
+
+	if (property_call->function)
+		property_call->function(NULL, NULL, property_call->user_data);
+
+done:
+	dbus_message_unref(reply);
+
+	dbus_pending_call_unref(call);
+}
+
+int supplicant_dbus_property_get_all(const char *path, const char *interface,
+				supplicant_dbus_property_function function,
+				void *user_data, gpointer caller)
+{
+	struct property_call_data *property_call = NULL;
+	DBusMessage *message;
+	DBusPendingCall *call;
+
+	if (!connection)
+		return -EINVAL;
+
+	if (!path || !interface)
+		return -EINVAL;
+
+	property_call = g_try_new0(struct property_call_data, 1);
+	if (!property_call)
+		return -ENOMEM;
+
+	message = dbus_message_new_method_call(SUPPLICANT_SERVICE, path,
+					DBUS_INTERFACE_PROPERTIES, "GetAll");
+	if (!message) {
+		g_free(property_call);
+		return -ENOMEM;
+	}
+
+	dbus_message_set_auto_start(message, FALSE);
+
+	dbus_message_append_args(message, DBUS_TYPE_STRING, &interface, NULL);
+
+	if (!dbus_connection_send_with_reply(connection, message,
+						&call, TIMEOUT)) {
+		dbus_message_unref(message);
+		g_free(property_call);
+		return -EIO;
+	}
+
+	if (!call) {
+		dbus_message_unref(message);
+		g_free(property_call);
+		return -EIO;
+	}
+
+	property_call->caller = caller;
+	property_call->pending_call = call;
+	property_call->function = function;
+	property_call->user_data = user_data;
+
+	property_calls = g_slist_prepend(property_calls, property_call);
+
+	dbus_pending_call_set_notify(call, property_get_all_reply,
+				property_call, property_call_free);
+
+	dbus_message_unref(message);
+
+	return 0;
+}
+
+static void property_get_reply(DBusPendingCall *call, void *user_data)
+{
+	struct property_call_data *property_call = user_data;
+	DBusMessage *reply;
+	DBusMessageIter iter;
+
+	reply = dbus_pending_call_steal_reply(call);
+
+	if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR)
+		goto done;
+
+	if (!dbus_message_iter_init(reply, &iter))
+		goto done;
+
+	if (dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_VARIANT) {
+		DBusMessageIter variant;
+
+		dbus_message_iter_recurse(&iter, &variant);
+
+		if (property_call->function)
+			property_call->function(NULL, &variant,
+						property_call->user_data);
+	}
+done:
+	dbus_message_unref(reply);
+
+	dbus_pending_call_unref(call);
+}
+
+int supplicant_dbus_property_get(const char *path, const char *interface,
+				const char *method,
+				supplicant_dbus_property_function function,
+				void *user_data, gpointer caller)
+{
+	struct property_call_data *property_call = NULL;
+	DBusMessage *message;
+	DBusPendingCall *call;
+
+	if (!connection)
+		return -EINVAL;
+
+	if (!path || !interface || !method)
+		return -EINVAL;
+
+	property_call = g_try_new0(struct property_call_data, 1);
+	if (!property_call)
+		return -ENOMEM;
+
+	message = dbus_message_new_method_call(SUPPLICANT_SERVICE, path,
+					DBUS_INTERFACE_PROPERTIES, "Get");
+
+	if (!message) {
+		g_free(property_call);
+		return -ENOMEM;
+	}
+
+	dbus_message_set_auto_start(message, FALSE);
+
+	dbus_message_append_args(message, DBUS_TYPE_STRING, &interface,
+					DBUS_TYPE_STRING, &method, NULL);
+
+	if (!dbus_connection_send_with_reply(connection, message,
+						&call, TIMEOUT)) {
+		dbus_message_unref(message);
+		g_free(property_call);
+		return -EIO;
+	}
+
+	if (!call) {
+		dbus_message_unref(message);
+		g_free(property_call);
+		return -EIO;
+	}
+
+	property_call->caller = caller;
+	property_call->pending_call = call;
+	property_call->function = function;
+	property_call->user_data = user_data;
+
+	property_calls = g_slist_prepend(property_calls, property_call);
+
+	dbus_pending_call_set_notify(call, property_get_reply,
+					property_call, property_call_free);
+
+	dbus_message_unref(message);
+
+	return 0;
+}
+
+static void property_set_reply(DBusPendingCall *call, void *user_data)
+{
+	struct property_call_data *property_call = user_data;
+	DBusMessage *reply;
+	DBusMessageIter iter;
+	const char *error;
+
+	reply = dbus_pending_call_steal_reply(call);
+
+	if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR)
+		error = dbus_message_get_error_name(reply);
+	else
+		error = NULL;
+
+	dbus_message_iter_init(reply, &iter);
+
+	if (property_call->function)
+		property_call->function(error, &iter, property_call->user_data);
+
+	dbus_message_unref(reply);
+
+	dbus_pending_call_unref(call);
+}
+
+int supplicant_dbus_property_set(const char *path, const char *interface,
+				const char *key, const char *signature,
+				supplicant_dbus_setup_function setup,
+				supplicant_dbus_result_function function,
+				void *user_data, gpointer caller)
+{
+	struct property_call_data *property_call = NULL;
+	DBusMessage *message;
+	DBusMessageIter iter, value;
+	DBusPendingCall *call;
+
+	if (!connection)
+		return -EINVAL;
+
+	if (!path || !interface)
+		return -EINVAL;
+
+	if (!key || !signature || !setup)
+		return -EINVAL;
+
+	property_call = g_try_new0(struct property_call_data, 1);
+	if (!property_call)
+		return -ENOMEM;
+
+	message = dbus_message_new_method_call(SUPPLICANT_SERVICE, path,
+					DBUS_INTERFACE_PROPERTIES, "Set");
+	if (!message) {
+		g_free(property_call);
+		return -ENOMEM;
+	}
+
+	dbus_message_set_auto_start(message, FALSE);
+
+	dbus_message_iter_init_append(message, &iter);
+	dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &interface);
+	dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key);
+
+	dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT,
+							signature, &value);
+	setup(&value, user_data);
+	dbus_message_iter_close_container(&iter, &value);
+
+	if (!dbus_connection_send_with_reply(connection, message,
+						&call, TIMEOUT)) {
+		dbus_message_unref(message);
+		g_free(property_call);
+		return -EIO;
+	}
+
+	if (!call) {
+		dbus_message_unref(message);
+		g_free(property_call);
+		return -EIO;
+	}
+
+	property_call->caller = caller;
+	property_call->pending_call = call;
+	property_call->function = function;
+	property_call->user_data = user_data;
+
+	property_calls = g_slist_prepend(property_calls, property_call);
+
+	dbus_pending_call_set_notify(call, property_set_reply,
+					property_call, property_call_free);
+
+	dbus_message_unref(message);
+
+	return 0;
+}
+
+void supplicant_dbus_method_call_cancel_all(gpointer caller)
+{
+	while (method_calls) {
+		struct method_call_data *method_call;
+		GSList *elem = g_slist_find_custom(method_calls, caller,
+						find_method_call_by_caller);
+		if (!elem)
+			break;
+
+		method_call = elem->data;
+		method_calls = g_slist_delete_link(method_calls, elem);
+
+		dbus_pending_call_cancel(method_call->pending_call);
+
+		if (method_call->function)
+			method_call->function("net.connman.Error.OperationAborted",
+					NULL, method_call->user_data);
+
+		dbus_pending_call_unref(method_call->pending_call);
+	}
+}
+
+static void method_call_reply(DBusPendingCall *call, void *user_data)
+{
+	struct method_call_data *method_call = user_data;
+	DBusMessage *reply;
+	DBusMessageIter iter;
+	const char *error;
+
+	reply = dbus_pending_call_steal_reply(call);
+
+	if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR)
+		error = dbus_message_get_error_name(reply);
+	else
+		error = NULL;
+
+	dbus_message_iter_init(reply, &iter);
+
+	if (method_call && method_call->function)
+		method_call->function(error, &iter, method_call->user_data);
+
+	dbus_message_unref(reply);
+
+	dbus_pending_call_unref(call);
+}
+
+int supplicant_dbus_method_call(const char *path,
+				const char *interface, const char *method,
+				supplicant_dbus_setup_function setup,
+				supplicant_dbus_result_function function,
+				void *user_data,
+				gpointer caller)
+{
+	struct method_call_data *method_call = NULL;
+	DBusMessage *message;
+	DBusMessageIter iter;
+	DBusPendingCall *call;
+
+	if (!connection)
+		return -EINVAL;
+
+	if (!path || !interface || !method)
+		return -EINVAL;
+
+	method_call = g_try_new0(struct method_call_data, 1);
+	if (!method_call)
+		return -ENOMEM;
+
+	message = dbus_message_new_method_call(SUPPLICANT_SERVICE, path,
+							interface, method);
+	if (!message) {
+		g_free(method_call);
+		return -ENOMEM;
+	}
+
+	dbus_message_set_auto_start(message, FALSE);
+
+	dbus_message_iter_init_append(message, &iter);
+	if (setup)
+		setup(&iter, user_data);
+
+	if (!dbus_connection_send_with_reply(connection, message,
+						&call, TIMEOUT)) {
+		dbus_message_unref(message);
+		g_free(method_call);
+		return -EIO;
+	}
+
+	if (!call) {
+		dbus_message_unref(message);
+		g_free(method_call);
+		return -EIO;
+	}
+
+	method_call->caller = caller;
+	method_call->pending_call = call;
+	method_call->function = function;
+	method_call->user_data = user_data;
+	method_calls = g_slist_prepend(method_calls, method_call);
+
+	dbus_pending_call_set_notify(call, method_call_reply, method_call,
+				method_call_free);
+
+	dbus_message_unref(message);
+
+	return 0;
+
+}
+
+void supplicant_dbus_property_append_basic(DBusMessageIter *iter,
+					const char *key, int type, void *val)
+{
+	DBusMessageIter value;
+	const char *signature;
+
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &key);
+
+	switch (type) {
+	case DBUS_TYPE_BOOLEAN:
+		signature = DBUS_TYPE_BOOLEAN_AS_STRING;
+		break;
+	case DBUS_TYPE_STRING:
+		signature = DBUS_TYPE_STRING_AS_STRING;
+		break;
+	case DBUS_TYPE_BYTE:
+		signature = DBUS_TYPE_BYTE_AS_STRING;
+		break;
+	case DBUS_TYPE_UINT16:
+		signature = DBUS_TYPE_UINT16_AS_STRING;
+		break;
+	case DBUS_TYPE_INT16:
+		signature = DBUS_TYPE_INT16_AS_STRING;
+		break;
+	case DBUS_TYPE_UINT32:
+		signature = DBUS_TYPE_UINT32_AS_STRING;
+		break;
+	case DBUS_TYPE_INT32:
+		signature = DBUS_TYPE_INT32_AS_STRING;
+		break;
+	case DBUS_TYPE_OBJECT_PATH:
+		signature = DBUS_TYPE_OBJECT_PATH_AS_STRING;
+		break;
+	default:
+		signature = DBUS_TYPE_VARIANT_AS_STRING;
+		break;
+	}
+
+	dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
+							signature, &value);
+	dbus_message_iter_append_basic(&value, type, val);
+	dbus_message_iter_close_container(iter, &value);
+}
+
+void supplicant_dbus_property_append_fixed_array(DBusMessageIter *iter,
+				const char *key, int type, void *val, int len)
+{
+	DBusMessageIter value, array;
+	const char *variant_sig, *array_sig;
+
+	switch (type) {
+	case DBUS_TYPE_BYTE:
+		variant_sig = DBUS_TYPE_ARRAY_AS_STRING
+					DBUS_TYPE_BYTE_AS_STRING;
+		array_sig = DBUS_TYPE_BYTE_AS_STRING;
+		break;
+	default:
+		return;
+	}
+
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &key);
+
+	dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
+							variant_sig, &value);
+
+	dbus_message_iter_open_container(&value, DBUS_TYPE_ARRAY,
+							array_sig, &array);
+	dbus_message_iter_append_fixed_array(&array, type, val, len);
+	dbus_message_iter_close_container(&value, &array);
+
+	dbus_message_iter_close_container(iter, &value);
+}
+
+void supplicant_dbus_property_append_array(DBusMessageIter *iter,
+				const char *key, int type,
+				supplicant_dbus_array_function function,
+				void *user_data)
+{
+	DBusMessageIter value, array;
+	const char *variant_sig, *array_sig;
+
+	switch (type) {
+	case DBUS_TYPE_STRING:
+	case DBUS_TYPE_BYTE:
+		variant_sig = DBUS_TYPE_ARRAY_AS_STRING
+				DBUS_TYPE_ARRAY_AS_STRING
+				DBUS_TYPE_BYTE_AS_STRING;
+		array_sig = DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_BYTE_AS_STRING;
+		break;
+	default:
+		return;
+	}
+
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &key);
+
+	dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
+							variant_sig, &value);
+
+	dbus_message_iter_open_container(&value, DBUS_TYPE_ARRAY,
+							array_sig, &array);
+	if (function)
+		function(&array, user_data);
+
+	dbus_message_iter_close_container(&value, &array);
+
+	dbus_message_iter_close_container(iter, &value);
+}
diff --git a/connman/gsupplicant/dbus.h b/connman/gsupplicant/dbus.h
new file mode 100644
index 0000000..3a90406
--- /dev/null
+++ b/connman/gsupplicant/dbus.h
@@ -0,0 +1,138 @@
+/*
+ *
+ *  WPA supplicant library with GLib integration
+ *
+ *  Copyright (C) 2012-2013  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
+ *
+ */
+
+#include <dbus/dbus.h>
+
+#define SUPPLICANT_SERVICE	"fi.w1.wpa_supplicant1"
+#define SUPPLICANT_INTERFACE	"fi.w1.wpa_supplicant1"
+#define SUPPLICANT_PATH		"/fi/w1/wpa_supplicant1"
+
+typedef void (*supplicant_dbus_array_function) (DBusMessageIter *iter,
+							void *user_data);
+
+typedef void (*supplicant_dbus_property_function) (const char *key,
+				DBusMessageIter *iter, void *user_data);
+
+typedef void (*supplicant_dbus_setup_function) (DBusMessageIter *iter,
+							void *user_data);
+
+typedef void (*supplicant_dbus_result_function) (const char *error,
+				DBusMessageIter *iter, void *user_data);
+
+void supplicant_dbus_property_append_array(DBusMessageIter *iter,
+				const char *key, int type,
+				supplicant_dbus_array_function function,
+				void *user_data);
+
+void supplicant_dbus_setup(DBusConnection *conn);
+
+void supplicant_dbus_array_foreach(DBusMessageIter *iter,
+				supplicant_dbus_array_function function,
+							void *user_data);
+
+void supplicant_dbus_property_foreach(DBusMessageIter *iter,
+				supplicant_dbus_property_function function,
+							void *user_data);
+
+int supplicant_dbus_property_get_all(const char *path, const char *interface,
+				supplicant_dbus_property_function function,
+				void *user_data, gpointer caller);
+
+int supplicant_dbus_property_get(const char *path, const char *interface,
+				const char *method,
+				supplicant_dbus_property_function function,
+				void *user_data, gpointer caller);
+
+int supplicant_dbus_property_set(const char *path, const char *interface,
+				const char *key, const char *signature,
+				supplicant_dbus_setup_function setup,
+				supplicant_dbus_result_function function,
+				void *user_data, gpointer caller);
+
+void supplicant_dbus_property_call_cancel_all(gpointer caller);
+
+int supplicant_dbus_method_call(const char *path,
+				const char *interface, const char *method,
+				supplicant_dbus_setup_function setup,
+				supplicant_dbus_result_function function,
+				void *user_data,
+				gpointer caller);
+
+void supplicant_dbus_method_call_cancel_all(gpointer caller);
+
+void supplicant_dbus_property_append_basic(DBusMessageIter *iter,
+					const char *key, int type, void *val);
+
+void supplicant_dbus_property_append_fixed_array(DBusMessageIter *iter,
+				const char *key, int type, void *val, int len);
+
+static inline void supplicant_dbus_dict_open(DBusMessageIter *iter,
+							DBusMessageIter *dict)
+{
+	dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY,
+			DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+			DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
+			DBUS_DICT_ENTRY_END_CHAR_AS_STRING, dict);
+}
+
+static inline void supplicant_dbus_dict_close(DBusMessageIter *iter,
+							DBusMessageIter *dict)
+{
+	dbus_message_iter_close_container(iter, dict);
+}
+
+static inline void supplicant_dbus_dict_append_basic(DBusMessageIter *dict,
+					const char *key, int type, void *val)
+{
+	DBusMessageIter entry;
+
+	dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
+								NULL, &entry);
+	supplicant_dbus_property_append_basic(&entry, key, type, val);
+	dbus_message_iter_close_container(dict, &entry);
+}
+
+static inline void
+supplicant_dbus_dict_append_fixed_array(DBusMessageIter *dict,
+				const char *key, int type, void *val, int len)
+{
+	DBusMessageIter entry;
+
+	dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
+							NULL, &entry);
+	supplicant_dbus_property_append_fixed_array(&entry, key, type, val, len);
+	dbus_message_iter_close_container(dict, &entry);
+}
+
+static inline void
+supplicant_dbus_dict_append_array(DBusMessageIter *dict,
+				const char *key, int type,
+				supplicant_dbus_array_function function,
+				void *user_data)
+{
+	DBusMessageIter entry;
+
+	dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
+								NULL, &entry);
+	supplicant_dbus_property_append_array(&entry, key, type,
+						function, user_data);
+	dbus_message_iter_close_container(dict, &entry);
+}
diff --git a/connman/gsupplicant/gsupplicant.h b/connman/gsupplicant/gsupplicant.h
new file mode 100644
index 0000000..2a87f2f
--- /dev/null
+++ b/connman/gsupplicant/gsupplicant.h
@@ -0,0 +1,374 @@
+/*
+ *
+ *  WPA supplicant library with GLib integration
+ *
+ *  Copyright (C) 2012-2013  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 __G_SUPPLICANT_H
+#define __G_SUPPLICANT_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define G_SUPPLICANT_EAP_METHOD_MD5	(1 << 0)
+#define G_SUPPLICANT_EAP_METHOD_TLS	(1 << 1)
+#define G_SUPPLICANT_EAP_METHOD_MSCHAPV2	(1 << 2)
+#define G_SUPPLICANT_EAP_METHOD_PEAP	(1 << 3)
+#define G_SUPPLICANT_EAP_METHOD_TTLS	(1 << 4)
+#define G_SUPPLICANT_EAP_METHOD_GTC	(1 << 5)
+#define G_SUPPLICANT_EAP_METHOD_OTP	(1 << 6)
+#define G_SUPPLICANT_EAP_METHOD_LEAP	(1 << 7)
+#define G_SUPPLICANT_EAP_METHOD_WSC	(1 << 8)
+
+#define G_SUPPLICANT_CAPABILITY_AUTHALG_OPEN	(1 << 0)
+#define G_SUPPLICANT_CAPABILITY_AUTHALG_SHARED	(1 << 1)
+#define G_SUPPLICANT_CAPABILITY_AUTHALG_LEAP	(1 << 2)
+
+#define G_SUPPLICANT_CAPABILITY_PROTO_WPA		(1 << 0)
+#define G_SUPPLICANT_CAPABILITY_PROTO_RSN		(1 << 1)
+
+#define G_SUPPLICANT_CAPABILITY_SCAN_ACTIVE	(1 << 0)
+#define G_SUPPLICANT_CAPABILITY_SCAN_PASSIVE	(1 << 1)
+#define G_SUPPLICANT_CAPABILITY_SCAN_SSID		(1 << 2)
+
+#define G_SUPPLICANT_CAPABILITY_MODE_INFRA	(1 << 0)
+#define G_SUPPLICANT_CAPABILITY_MODE_IBSS		(1 << 1)
+#define G_SUPPLICANT_CAPABILITY_MODE_AP		(1 << 2)
+#define G_SUPPLICANT_CAPABILITY_MODE_P2P	(1 << 3)
+
+#define G_SUPPLICANT_KEYMGMT_NONE		(1 << 0)
+#define G_SUPPLICANT_KEYMGMT_IEEE8021X	(1 << 1)
+#define G_SUPPLICANT_KEYMGMT_WPA_NONE	(1 << 2)
+#define G_SUPPLICANT_KEYMGMT_WPA_PSK	(1 << 3)
+#define G_SUPPLICANT_KEYMGMT_WPA_PSK_256	(1 << 4)
+#define G_SUPPLICANT_KEYMGMT_WPA_FT_PSK	(1 << 5)
+#define G_SUPPLICANT_KEYMGMT_WPA_FT_EAP	(1 << 6)
+#define G_SUPPLICANT_KEYMGMT_WPA_EAP	(1 << 7)
+#define G_SUPPLICANT_KEYMGMT_WPA_EAP_256	(1 << 8)
+#define G_SUPPLICANT_KEYMGMT_WPS		(1 << 9)
+
+#define G_SUPPLICANT_PROTO_WPA		(1 << 0)
+#define G_SUPPLICANT_PROTO_RSN		(1 << 1)
+
+#define G_SUPPLICANT_GROUP_WEP40		(1 << 0)
+#define G_SUPPLICANT_GROUP_WEP104		(1 << 1)
+#define G_SUPPLICANT_GROUP_TKIP		(1 << 2)
+#define G_SUPPLICANT_GROUP_CCMP		(1 << 3)
+
+#define G_SUPPLICANT_PAIRWISE_NONE	(1 << 0)
+#define G_SUPPLICANT_PAIRWISE_TKIP	(1 << 1)
+#define G_SUPPLICANT_PAIRWISE_CCMP	(1 << 2)
+
+#define G_SUPPLICANT_WPS_CONFIGURED     (1 << 0)
+#define G_SUPPLICANT_WPS_PBC            (1 << 1)
+#define G_SUPPLICANT_WPS_PIN            (1 << 2)
+#define G_SUPPLICANT_WPS_REGISTRAR      (1 << 3)
+
+#define G_SUPPLICANT_WPS_CONFIG_PBC	0x0080
+
+#define G_SUPPLICANT_GROUP_ROLE_CLIENT	(1 << 0)
+#define G_SUPPLICANT_GROUP_ROLE_GO      (1 << 1)
+
+typedef enum {
+	G_SUPPLICANT_MODE_UNKNOWN,
+	G_SUPPLICANT_MODE_INFRA,
+	G_SUPPLICANT_MODE_IBSS,
+	G_SUPPLICANT_MODE_MASTER,
+} GSupplicantMode;
+
+typedef enum {
+	G_SUPPLICANT_SECURITY_UNKNOWN,
+	G_SUPPLICANT_SECURITY_NONE,
+	G_SUPPLICANT_SECURITY_WEP,
+	G_SUPPLICANT_SECURITY_PSK,
+	G_SUPPLICANT_SECURITY_IEEE8021X,
+} GSupplicantSecurity;
+
+typedef enum {
+	G_SUPPLICANT_STATE_UNKNOWN,
+	G_SUPPLICANT_STATE_DISABLED,
+	G_SUPPLICANT_STATE_DISCONNECTED,
+	G_SUPPLICANT_STATE_INACTIVE,
+	G_SUPPLICANT_STATE_SCANNING,
+	G_SUPPLICANT_STATE_AUTHENTICATING,
+	G_SUPPLICANT_STATE_ASSOCIATING,
+	G_SUPPLICANT_STATE_ASSOCIATED,
+	G_SUPPLICANT_STATE_4WAY_HANDSHAKE,
+	G_SUPPLICANT_STATE_GROUP_HANDSHAKE,
+	G_SUPPLICANT_STATE_COMPLETED,
+} GSupplicantState;
+
+typedef enum {
+	G_SUPPLICANT_WPS_STATE_UNKNOWN,
+	G_SUPPLICANT_WPS_STATE_SUCCESS,
+	G_SUPPLICANT_WPS_STATE_FAIL,
+} GSupplicantWpsState;
+
+typedef enum {
+	G_SUPPLICANT_PEER_SERVICES_CHANGED,
+	G_SUPPLICANT_PEER_GROUP_CHANGED,
+	G_SUPPLICANT_PEER_GROUP_STARTED,
+	G_SUPPLICANT_PEER_GROUP_FINISHED,
+	G_SUPPLICANT_PEER_GROUP_JOINED,
+	G_SUPPLICANT_PEER_GROUP_DISCONNECTED,
+	G_SUPPLICANT_PEER_GROUP_FAILED,
+} GSupplicantPeerState;
+
+struct _GSupplicantSSID {
+	const void *ssid;
+	unsigned int ssid_len;
+	unsigned int scan_ssid;
+	GSupplicantMode mode;
+	GSupplicantSecurity security;
+	unsigned int protocol;
+	unsigned int pairwise_cipher;
+	unsigned int group_cipher;
+	unsigned int freq;
+	const char *eap;
+	const char *passphrase;
+	const char *identity;
+	const char *ca_cert_path;
+	const char *client_cert_path;
+	const char *private_key_path;
+	const char *private_key_passphrase;
+	const char *phase2_auth;
+	dbus_bool_t use_wps;
+	const char *pin_wps;
+	const char *bgscan;
+};
+
+typedef struct _GSupplicantSSID GSupplicantSSID;
+
+struct scan_ssid {
+	unsigned char ssid[32];
+	uint8_t ssid_len;
+};
+
+struct _GSupplicantScanParams {
+	GSList *ssids;
+
+	uint8_t num_ssids;
+
+	uint8_t num_freqs;
+	uint16_t *freqs;
+};
+
+typedef struct _GSupplicantScanParams GSupplicantScanParams;
+
+struct _GSupplicantPeerParams {
+	bool master;
+	char *wps_pin;
+	char *path;
+};
+
+typedef struct _GSupplicantPeerParams GSupplicantPeerParams;
+
+struct _GSupplicantP2PServiceParams {
+	int version;
+	char *service;
+	unsigned char *query;
+	int query_length;
+	unsigned char *response;
+	int response_length;
+	unsigned char *wfd_ies;
+	int wfd_ies_length;
+};
+
+typedef struct _GSupplicantP2PServiceParams GSupplicantP2PServiceParams;
+
+/* global API */
+typedef void (*GSupplicantCountryCallback) (int result,
+						const char *alpha2,
+							void *user_data);
+
+int g_supplicant_set_country(const char *alpha2,
+				GSupplicantCountryCallback callback,
+						const void *user_data);
+
+/* Interface API */
+struct _GSupplicantInterface;
+struct _GSupplicantPeer;
+
+typedef struct _GSupplicantInterface GSupplicantInterface;
+typedef struct _GSupplicantPeer GSupplicantPeer;
+
+typedef void (*GSupplicantInterfaceCallback) (int result,
+					GSupplicantInterface *interface,
+							void *user_data);
+
+void g_supplicant_interface_cancel(GSupplicantInterface *interface);
+
+int g_supplicant_interface_create(const char *ifname, const char *driver,
+					const char *bridge,
+					GSupplicantInterfaceCallback callback,
+							void *user_data);
+int g_supplicant_interface_remove(GSupplicantInterface *interface,
+					GSupplicantInterfaceCallback callback,
+							void *user_data);
+int g_supplicant_interface_scan(GSupplicantInterface *interface,
+					GSupplicantScanParams *scan_data,
+					GSupplicantInterfaceCallback callback,
+							void *user_data);
+
+int g_supplicant_interface_p2p_find(GSupplicantInterface *interface,
+					GSupplicantInterfaceCallback callback,
+							void *user_data);
+
+int g_supplicant_interface_p2p_stop_find(GSupplicantInterface *interface);
+
+int g_supplicant_interface_p2p_connect(GSupplicantInterface *interface,
+					GSupplicantPeerParams *peer_params,
+					GSupplicantInterfaceCallback callback,
+					void *user_data);
+
+int g_supplicant_interface_p2p_disconnect(GSupplicantInterface *interface,
+					GSupplicantPeerParams *peer_params);
+
+int g_supplicant_interface_p2p_listen(GSupplicantInterface *interface,
+						int period, int interval);
+
+int g_supplicant_interface_p2p_add_service(GSupplicantInterface *interface,
+				GSupplicantInterfaceCallback callback,
+				GSupplicantP2PServiceParams *p2p_service_params,
+				void *user_data);
+
+int g_supplicant_interface_p2p_del_service(GSupplicantInterface *interface,
+				GSupplicantP2PServiceParams *p2p_service_params);
+
+int g_supplicant_set_widi_ies(GSupplicantP2PServiceParams *p2p_service_params,
+					GSupplicantInterfaceCallback callback,
+					void *user_data);
+
+int g_supplicant_interface_connect(GSupplicantInterface *interface,
+					GSupplicantSSID *ssid,
+					GSupplicantInterfaceCallback callback,
+							void *user_data);
+
+int g_supplicant_interface_disconnect(GSupplicantInterface *interface,
+					GSupplicantInterfaceCallback callback,
+							void *user_data);
+
+int g_supplicant_interface_set_apscan(GSupplicantInterface *interface,
+							unsigned int ap_scan);
+
+void g_supplicant_interface_set_data(GSupplicantInterface *interface,
+								void *data);
+void *g_supplicant_interface_get_data(GSupplicantInterface *interface);
+const char *g_supplicant_interface_get_ifname(GSupplicantInterface *interface);
+const char *g_supplicant_interface_get_driver(GSupplicantInterface *interface);
+GSupplicantState g_supplicant_interface_get_state(GSupplicantInterface *interface);
+const char *g_supplicant_interface_get_wps_key(GSupplicantInterface *interface);
+const void *g_supplicant_interface_get_wps_ssid(GSupplicantInterface *interface,
+							unsigned int *ssid_len);
+GSupplicantWpsState g_supplicant_interface_get_wps_state(GSupplicantInterface *interface);
+unsigned int g_supplicant_interface_get_mode(GSupplicantInterface *interface);
+dbus_bool_t g_supplicant_interface_get_ready(GSupplicantInterface *interface);
+unsigned int g_supplicant_interface_get_max_scan_ssids(
+					GSupplicantInterface *interface);
+
+int g_supplicant_interface_enable_selected_network(GSupplicantInterface *interface,
+							dbus_bool_t enable);
+int g_supplicant_interface_set_country(GSupplicantInterface *interface,
+					GSupplicantCountryCallback callback,
+							const char *alpha2,
+							void *user_data);
+bool g_supplicant_interface_has_p2p(GSupplicantInterface *interface);
+int g_supplicant_interface_set_p2p_device_config(GSupplicantInterface *interface,
+						const char *device_name,
+						const char *primary_dev_type);
+GSupplicantPeer *g_supplicant_interface_peer_lookup(GSupplicantInterface *interface,
+						const char *identifier);
+bool g_supplicant_interface_is_p2p_finding(GSupplicantInterface *interface);
+
+/* Network and Peer API */
+struct _GSupplicantNetwork;
+struct _GSupplicantGroup;
+
+typedef struct _GSupplicantNetwork GSupplicantNetwork;
+typedef struct _GSupplicantGroup GSupplicantGroup;
+
+GSupplicantInterface *g_supplicant_network_get_interface(GSupplicantNetwork *network);
+const char *g_supplicant_network_get_name(GSupplicantNetwork *network);
+const char *g_supplicant_network_get_identifier(GSupplicantNetwork *network);
+const char *g_supplicant_network_get_path(GSupplicantNetwork *network);
+const void *g_supplicant_network_get_ssid(GSupplicantNetwork *network,
+							unsigned int *ssid_len);
+const char *g_supplicant_network_get_mode(GSupplicantNetwork *network);
+const char *g_supplicant_network_get_security(GSupplicantNetwork *network);
+dbus_int16_t g_supplicant_network_get_signal(GSupplicantNetwork *network);
+dbus_uint16_t g_supplicant_network_get_frequency(GSupplicantNetwork *network);
+dbus_bool_t g_supplicant_network_get_wps(GSupplicantNetwork *network);
+dbus_bool_t g_supplicant_network_is_wps_active(GSupplicantNetwork *network);
+dbus_bool_t g_supplicant_network_is_wps_pbc(GSupplicantNetwork *network);
+dbus_bool_t g_supplicant_network_is_wps_advertizing(GSupplicantNetwork *network);
+
+GSupplicantInterface *g_supplicant_peer_get_interface(GSupplicantPeer *peer);
+const char *g_supplicant_peer_get_path(GSupplicantPeer *peer);
+const char *g_supplicant_peer_get_identifier(GSupplicantPeer *peer);
+const void *g_supplicant_peer_get_device_address(GSupplicantPeer *peer);
+const void *g_supplicant_peer_get_iface_address(GSupplicantPeer *peer);
+const char *g_supplicant_peer_get_name(GSupplicantPeer *peer);
+const unsigned char *g_supplicant_peer_get_widi_ies(GSupplicantPeer *peer,
+								int *length);
+bool g_supplicant_peer_is_wps_pbc(GSupplicantPeer *peer);
+bool g_supplicant_peer_is_wps_pin(GSupplicantPeer *peer);
+bool g_supplicant_peer_is_in_a_group(GSupplicantPeer *peer);
+GSupplicantInterface *g_supplicant_peer_get_group_interface(GSupplicantPeer *peer);
+bool g_supplicant_peer_is_client(GSupplicantPeer *peer);
+bool g_supplicant_peer_has_requested_connection(GSupplicantPeer *peer);
+
+struct _GSupplicantCallbacks {
+	void (*system_ready) (void);
+	void (*system_killed) (void);
+	void (*interface_added) (GSupplicantInterface *interface);
+	void (*interface_state) (GSupplicantInterface *interface);
+	void (*interface_removed) (GSupplicantInterface *interface);
+	void (*p2p_support) (GSupplicantInterface *interface);
+	void (*scan_started) (GSupplicantInterface *interface);
+	void (*scan_finished) (GSupplicantInterface *interface);
+	void (*ap_create_fail) (GSupplicantInterface *interface);
+	void (*network_added) (GSupplicantNetwork *network);
+	void (*network_removed) (GSupplicantNetwork *network);
+	void (*network_changed) (GSupplicantNetwork *network,
+					const char *property);
+	void (*peer_found) (GSupplicantPeer *peer);
+	void (*peer_lost) (GSupplicantPeer *peer);
+	void (*peer_changed) (GSupplicantPeer *peer,
+					GSupplicantPeerState state);
+	void (*peer_request) (GSupplicantPeer *peer);
+	void (*debug) (const char *str);
+};
+
+typedef struct _GSupplicantCallbacks GSupplicantCallbacks;
+
+int g_supplicant_register(const GSupplicantCallbacks *callbacks);
+void g_supplicant_unregister(const GSupplicantCallbacks *callbacks);
+
+static inline
+void g_supplicant_free_scan_params(GSupplicantScanParams *scan_params)
+{
+	g_slist_free_full(scan_params->ssids, g_free);
+	g_free(scan_params->freqs);
+	g_free(scan_params);
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __G_SUPPLICANT_H */
diff --git a/connman/gsupplicant/supplicant.c b/connman/gsupplicant/supplicant.c
new file mode 100644
index 0000000..70d85f3
--- /dev/null
+++ b/connman/gsupplicant/supplicant.c
@@ -0,0 +1,5463 @@
+/*
+ *
+ *  WPA supplicant library with GLib integration
+ *
+ *  Copyright (C) 2012-2013  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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdint.h>
+#include <syslog.h>
+#include <ctype.h>
+#include <stdbool.h>
+#include <netinet/if_ether.h>
+#include <netinet/in.h>
+
+#include <glib.h>
+#include <gdbus.h>
+
+#include "dbus.h"
+#include "gsupplicant.h"
+
+#define IEEE80211_CAP_ESS	0x0001
+#define IEEE80211_CAP_IBSS	0x0002
+#define IEEE80211_CAP_PRIVACY	0x0010
+
+#define BSS_UNKNOWN_STRENGTH    -90
+
+static DBusConnection *connection;
+
+static const GSupplicantCallbacks *callbacks_pointer;
+
+static dbus_bool_t system_available = FALSE;
+static dbus_bool_t system_ready = FALSE;
+
+static dbus_int32_t debug_level;
+static dbus_bool_t debug_timestamp = FALSE;
+static dbus_bool_t debug_showkeys = FALSE;
+
+static const char *debug_strings[] = {
+	"msgdump", "debug", "info", "warning", "error", NULL
+};
+
+static unsigned int eap_methods;
+
+struct strvalmap {
+	const char *str;
+	unsigned int val;
+};
+
+static struct strvalmap eap_method_map[] = {
+	{ "MD5",	G_SUPPLICANT_EAP_METHOD_MD5	},
+	{ "TLS",	G_SUPPLICANT_EAP_METHOD_TLS	},
+	{ "MSCHAPV2",	G_SUPPLICANT_EAP_METHOD_MSCHAPV2	},
+	{ "PEAP",	G_SUPPLICANT_EAP_METHOD_PEAP	},
+	{ "TTLS",	G_SUPPLICANT_EAP_METHOD_TTLS	},
+	{ "GTC",	G_SUPPLICANT_EAP_METHOD_GTC	},
+	{ "OTP",	G_SUPPLICANT_EAP_METHOD_OTP	},
+	{ "LEAP",	G_SUPPLICANT_EAP_METHOD_LEAP	},
+	{ "WSC",	G_SUPPLICANT_EAP_METHOD_WSC	},
+	{ }
+};
+
+static struct strvalmap keymgmt_map[] = {
+	{ "none",		G_SUPPLICANT_KEYMGMT_NONE		},
+	{ "ieee8021x",		G_SUPPLICANT_KEYMGMT_IEEE8021X	},
+	{ "wpa-none",		G_SUPPLICANT_KEYMGMT_WPA_NONE	},
+	{ "wpa-psk",		G_SUPPLICANT_KEYMGMT_WPA_PSK	},
+	{ "wpa-psk-sha256",	G_SUPPLICANT_KEYMGMT_WPA_PSK_256	},
+	{ "wpa-ft-psk",		G_SUPPLICANT_KEYMGMT_WPA_FT_PSK	},
+	{ "wpa-ft-eap",		G_SUPPLICANT_KEYMGMT_WPA_FT_EAP	},
+	{ "wpa-eap",		G_SUPPLICANT_KEYMGMT_WPA_EAP	},
+	{ "wpa-eap-sha256",	G_SUPPLICANT_KEYMGMT_WPA_EAP_256	},
+	{ "wps",		G_SUPPLICANT_KEYMGMT_WPS		},
+	{ }
+};
+
+static struct strvalmap authalg_capa_map[] = {
+	{ "open",	G_SUPPLICANT_CAPABILITY_AUTHALG_OPEN	},
+	{ "shared",	G_SUPPLICANT_CAPABILITY_AUTHALG_SHARED	},
+	{ "leap",	G_SUPPLICANT_CAPABILITY_AUTHALG_LEAP	},
+	{ }
+};
+
+static struct strvalmap proto_capa_map[] = {
+	{ "wpa",	G_SUPPLICANT_CAPABILITY_PROTO_WPA		},
+	{ "rsn",	G_SUPPLICANT_CAPABILITY_PROTO_RSN		},
+	{ }
+};
+
+static struct strvalmap group_map[] = {
+	{ "wep40",	G_SUPPLICANT_GROUP_WEP40	},
+	{ "wep104",	G_SUPPLICANT_GROUP_WEP104	},
+	{ "tkip",	G_SUPPLICANT_GROUP_TKIP	},
+	{ "ccmp",	G_SUPPLICANT_GROUP_CCMP	},
+	{ }
+};
+
+static struct strvalmap pairwise_map[] = {
+	{ "none",	G_SUPPLICANT_PAIRWISE_NONE	},
+	{ "tkip",	G_SUPPLICANT_PAIRWISE_TKIP	},
+	{ "ccmp",	G_SUPPLICANT_PAIRWISE_CCMP	},
+	{ }
+};
+
+static struct strvalmap scan_capa_map[] = {
+	{ "active",	G_SUPPLICANT_CAPABILITY_SCAN_ACTIVE	},
+	{ "passive",	G_SUPPLICANT_CAPABILITY_SCAN_PASSIVE	},
+	{ "ssid",	G_SUPPLICANT_CAPABILITY_SCAN_SSID		},
+	{ }
+};
+
+static struct strvalmap mode_capa_map[] = {
+	{ "infrastructure",	G_SUPPLICANT_CAPABILITY_MODE_INFRA	},
+	{ "ad-hoc",		G_SUPPLICANT_CAPABILITY_MODE_IBSS	},
+	{ "ap",			G_SUPPLICANT_CAPABILITY_MODE_AP		},
+	{ }
+};
+
+static GHashTable *interface_table;
+static GHashTable *bss_mapping;
+static GHashTable *peer_mapping;
+static GHashTable *group_mapping;
+static GHashTable *pending_peer_connection;
+
+struct _GSupplicantWpsCredentials {
+	unsigned char ssid[32];
+	unsigned int ssid_len;
+	char *key;
+};
+
+struct _GSupplicantInterface {
+	char *path;
+	char *network_path;
+	unsigned int keymgmt_capa;
+	unsigned int authalg_capa;
+	unsigned int proto_capa;
+	unsigned int group_capa;
+	unsigned int pairwise_capa;
+	unsigned int scan_capa;
+	unsigned int mode_capa;
+	unsigned int max_scan_ssids;
+	bool p2p_support;
+	bool p2p_finding;
+	bool ap_create_in_progress;
+	dbus_bool_t ready;
+	GSupplicantState state;
+	dbus_bool_t scanning;
+	GSupplicantInterfaceCallback scan_callback;
+	void *scan_data;
+	int apscan;
+	char *ifname;
+	char *driver;
+	char *bridge;
+	struct _GSupplicantWpsCredentials wps_cred;
+	GSupplicantWpsState wps_state;
+	GHashTable *network_table;
+	GHashTable *peer_table;
+	GHashTable *group_table;
+	GHashTable *net_mapping;
+	GHashTable *bss_mapping;
+	void *data;
+	const char *pending_peer_path;
+};
+
+struct g_supplicant_bss {
+	GSupplicantInterface *interface;
+	char *path;
+	unsigned char bssid[6];
+	unsigned char ssid[32];
+	unsigned int ssid_len;
+	dbus_uint16_t frequency;
+	dbus_uint32_t maxrate;
+	dbus_int16_t signal;
+	GSupplicantMode mode;
+	GSupplicantSecurity security;
+	dbus_bool_t rsn_selected;
+	unsigned int wpa_keymgmt;
+	unsigned int wpa_pairwise;
+	unsigned int wpa_group;
+	unsigned int rsn_keymgmt;
+	unsigned int rsn_pairwise;
+	unsigned int rsn_group;
+	unsigned int keymgmt;
+	dbus_bool_t privacy;
+	dbus_bool_t psk;
+	dbus_bool_t ieee8021x;
+	unsigned int wps_capabilities;
+};
+
+struct _GSupplicantNetwork {
+	GSupplicantInterface *interface;
+	char *path;
+	char *group;
+	char *name;
+	unsigned char ssid[32];
+	unsigned int ssid_len;
+	dbus_int16_t signal;
+	dbus_uint16_t frequency;
+	struct g_supplicant_bss *best_bss;
+	GSupplicantMode mode;
+	GSupplicantSecurity security;
+	dbus_bool_t wps;
+	unsigned int wps_capabilities;
+	GHashTable *bss_table;
+	GHashTable *config_table;
+};
+
+struct _GSupplicantPeer {
+	GSupplicantInterface *interface;
+	char *path;
+	unsigned char device_address[ETH_ALEN];
+	unsigned char iface_address[ETH_ALEN];
+	char *name;
+	unsigned char *widi_ies;
+	int widi_ies_length;
+	char *identifier;
+	unsigned int wps_capabilities;
+	GSList *groups;
+	const GSupplicantInterface *current_group_iface;
+	bool connection_requested;
+};
+
+struct _GSupplicantGroup {
+	GSupplicantInterface *interface;
+	GSupplicantInterface *orig_interface;
+	char *path;
+	int role;
+	GSList *members;
+};
+
+struct interface_data {
+	GSupplicantInterface *interface;
+	char *path; /* Interface path cannot be taken from interface (above) as
+		     * it might have been freed already.
+		     */
+	GSupplicantInterfaceCallback callback;
+	void *user_data;
+        bool network_remove_in_progress;
+};
+
+struct interface_create_data {
+	char *ifname;
+	char *driver;
+	char *bridge;
+	GSupplicantInterface *interface;
+	GSupplicantInterfaceCallback callback;
+	void *user_data;
+};
+
+struct interface_connect_data {
+	GSupplicantInterface *interface;
+	char *path;
+	GSupplicantInterfaceCallback callback;
+	void *user_data;
+        bool network_remove_in_progress;
+	union {
+		GSupplicantSSID *ssid;
+		GSupplicantPeerParams *peer;
+	};
+};
+
+struct interface_scan_data {
+	GSupplicantInterface *interface;
+	char *path;
+	GSupplicantInterfaceCallback callback;
+	GSupplicantScanParams *scan_params;
+	void *user_data;
+};
+
+
+static int network_remove(struct interface_data *data);
+static void network_remove_params(DBusMessageIter *iter, void *user_data);
+static void network_remove_result(const char *error,
+				DBusMessageIter *iter, void *user_data);
+
+static inline void debug(const char *format, ...)
+{
+	char str[256];
+	va_list ap;
+
+	if (!callbacks_pointer->debug)
+		return;
+
+	va_start(ap, format);
+
+	if (vsnprintf(str, sizeof(str), format, ap) > 0)
+		callbacks_pointer->debug(str);
+
+	va_end(ap);
+}
+
+#define SUPPLICANT_DBG(fmt, arg...) \
+	debug("%s:%s() " fmt, __FILE__, __FUNCTION__ , ## arg);
+
+static GSupplicantMode string2mode(const char *mode)
+{
+	if (!mode)
+		return G_SUPPLICANT_MODE_UNKNOWN;
+
+	if (g_str_equal(mode, "infrastructure"))
+		return G_SUPPLICANT_MODE_INFRA;
+	else if (g_str_equal(mode, "ad-hoc"))
+		return G_SUPPLICANT_MODE_IBSS;
+
+	return G_SUPPLICANT_MODE_UNKNOWN;
+}
+
+static const char *mode2string(GSupplicantMode mode)
+{
+	switch (mode) {
+	case G_SUPPLICANT_MODE_UNKNOWN:
+		break;
+	case G_SUPPLICANT_MODE_INFRA:
+		return "managed";
+	case G_SUPPLICANT_MODE_IBSS:
+		return "adhoc";
+	case G_SUPPLICANT_MODE_MASTER:
+		return "ap";
+	}
+
+	return NULL;
+}
+
+static const char *security2string(GSupplicantSecurity security)
+{
+	switch (security) {
+	case G_SUPPLICANT_SECURITY_UNKNOWN:
+		break;
+	case G_SUPPLICANT_SECURITY_NONE:
+		return "none";
+	case G_SUPPLICANT_SECURITY_WEP:
+		return "wep";
+	case G_SUPPLICANT_SECURITY_PSK:
+		return "psk";
+	case G_SUPPLICANT_SECURITY_IEEE8021X:
+		return "ieee8021x";
+	}
+
+	return NULL;
+}
+
+static GSupplicantState string2state(const char *state)
+{
+	if (!state)
+		return G_SUPPLICANT_STATE_UNKNOWN;
+
+	if (g_str_equal(state, "unknown"))
+		return G_SUPPLICANT_STATE_UNKNOWN;
+	else if (g_str_equal(state, "interface_disabled"))
+		return G_SUPPLICANT_STATE_DISABLED;
+	else if (g_str_equal(state, "disconnected"))
+		return G_SUPPLICANT_STATE_DISCONNECTED;
+	else if (g_str_equal(state, "inactive"))
+		return G_SUPPLICANT_STATE_INACTIVE;
+	else if (g_str_equal(state, "scanning"))
+		return G_SUPPLICANT_STATE_SCANNING;
+	else if (g_str_equal(state, "authenticating"))
+		return G_SUPPLICANT_STATE_AUTHENTICATING;
+	else if (g_str_equal(state, "associating"))
+		return G_SUPPLICANT_STATE_ASSOCIATING;
+	else if (g_str_equal(state, "associated"))
+		return G_SUPPLICANT_STATE_ASSOCIATED;
+	else if (g_str_equal(state, "group_handshake"))
+		return G_SUPPLICANT_STATE_GROUP_HANDSHAKE;
+	else if (g_str_equal(state, "4way_handshake"))
+		return G_SUPPLICANT_STATE_4WAY_HANDSHAKE;
+	else if (g_str_equal(state, "completed"))
+		return G_SUPPLICANT_STATE_COMPLETED;
+
+	return G_SUPPLICANT_STATE_UNKNOWN;
+}
+
+static void callback_system_ready(void)
+{
+	if (system_ready)
+		return;
+
+	system_ready = TRUE;
+
+	if (!callbacks_pointer)
+		return;
+
+	if (!callbacks_pointer->system_ready)
+		return;
+
+	callbacks_pointer->system_ready();
+}
+
+static void callback_system_killed(void)
+{
+	system_ready = FALSE;
+
+	if (!callbacks_pointer)
+		return;
+
+	if (!callbacks_pointer->system_killed)
+		return;
+
+	callbacks_pointer->system_killed();
+}
+
+static void callback_interface_added(GSupplicantInterface *interface)
+{
+	SUPPLICANT_DBG("");
+
+	if (!callbacks_pointer)
+		return;
+
+	if (!callbacks_pointer->interface_added)
+		return;
+
+	callbacks_pointer->interface_added(interface);
+}
+
+static void callback_interface_state(GSupplicantInterface *interface)
+{
+	if (!callbacks_pointer)
+		return;
+
+	if (!callbacks_pointer->interface_state)
+		return;
+
+	callbacks_pointer->interface_state(interface);
+}
+
+static void callback_interface_removed(GSupplicantInterface *interface)
+{
+	if (!callbacks_pointer)
+		return;
+
+	if (!callbacks_pointer->interface_removed)
+		return;
+
+	callbacks_pointer->interface_removed(interface);
+}
+
+static void callback_p2p_support(GSupplicantInterface *interface)
+{
+	SUPPLICANT_DBG("");
+
+    return;
+
+	if (!interface->p2p_support)
+		return;
+
+	if (callbacks_pointer && callbacks_pointer->p2p_support)
+		callbacks_pointer->p2p_support(interface);
+}
+
+static void callback_scan_started(GSupplicantInterface *interface)
+{
+	if (!callbacks_pointer)
+		return;
+
+	if (!callbacks_pointer->scan_started)
+		return;
+
+	callbacks_pointer->scan_started(interface);
+}
+
+static void callback_ap_create_fail(GSupplicantInterface *interface)
+{
+	if (!callbacks_pointer)
+		return;
+
+	if (!callbacks_pointer->scan_started)
+		return;
+
+	callbacks_pointer->ap_create_fail(interface);
+}
+
+static void callback_scan_finished(GSupplicantInterface *interface)
+{
+	if (!callbacks_pointer)
+		return;
+
+	if (!callbacks_pointer->scan_finished)
+		return;
+
+	callbacks_pointer->scan_finished(interface);
+}
+
+static void callback_network_added(GSupplicantNetwork *network)
+{
+	if (!callbacks_pointer)
+		return;
+
+	if (!callbacks_pointer->network_added)
+		return;
+
+	callbacks_pointer->network_added(network);
+}
+
+static void callback_network_removed(GSupplicantNetwork *network)
+{
+	if (!callbacks_pointer)
+		return;
+
+	if (!callbacks_pointer->network_removed)
+		return;
+
+	callbacks_pointer->network_removed(network);
+}
+
+static void callback_network_changed(GSupplicantNetwork *network,
+					const char *property)
+{
+	if (!callbacks_pointer)
+		return;
+
+	if (!callbacks_pointer->network_changed)
+		return;
+
+	callbacks_pointer->network_changed(network, property);
+}
+
+static void callback_peer_found(GSupplicantPeer *peer)
+{
+	if (!callbacks_pointer)
+		return;
+
+	if (!callbacks_pointer->peer_found)
+		return;
+
+	callbacks_pointer->peer_found(peer);
+}
+
+static void callback_peer_lost(GSupplicantPeer *peer)
+{
+	if (!callbacks_pointer)
+		return;
+
+	if (!callbacks_pointer->peer_lost)
+		return;
+
+	callbacks_pointer->peer_lost(peer);
+}
+
+static void callback_peer_changed(GSupplicantPeer *peer,
+						GSupplicantPeerState state)
+{
+	if (!callbacks_pointer)
+		return;
+
+	if (!callbacks_pointer->peer_changed)
+		return;
+
+	callbacks_pointer->peer_changed(peer, state);
+}
+
+static void callback_peer_request(GSupplicantPeer *peer)
+{
+	if (!callbacks_pointer)
+		return;
+
+	if (!callbacks_pointer->peer_request)
+		return;
+
+	peer->connection_requested = true;
+
+	callbacks_pointer->peer_request(peer);
+}
+
+static void remove_group(gpointer data)
+{
+	GSupplicantGroup *group = data;
+
+	if (group->members)
+		g_slist_free_full(group->members, g_free);
+
+	g_free(group->path);
+	g_free(group);
+}
+
+static void remove_interface(gpointer data)
+{
+	GSupplicantInterface *interface = data;
+
+	g_hash_table_destroy(interface->bss_mapping);
+	g_hash_table_destroy(interface->net_mapping);
+	g_hash_table_destroy(interface->network_table);
+	g_hash_table_destroy(interface->peer_table);
+	g_hash_table_destroy(interface->group_table);
+
+	if (interface->scan_callback) {
+		SUPPLICANT_DBG("call interface %p callback %p scanning %d",
+				interface, interface->scan_callback,
+				interface->scanning);
+
+		interface->scan_callback(-EIO, interface, interface->scan_data);
+                interface->scan_callback = NULL;
+                interface->scan_data = NULL;
+
+		if (interface->scanning) {
+			interface->scanning = FALSE;
+			callback_scan_finished(interface);
+		}
+	}
+
+	callback_interface_removed(interface);
+
+	g_free(interface->wps_cred.key);
+	g_free(interface->path);
+	g_free(interface->network_path);
+	g_free(interface->ifname);
+	g_free(interface->driver);
+	g_free(interface->bridge);
+	g_free(interface);
+}
+
+static void remove_network(gpointer data)
+{
+	GSupplicantNetwork *network = data;
+
+	g_hash_table_destroy(network->bss_table);
+
+	callback_network_removed(network);
+
+	g_hash_table_destroy(network->config_table);
+
+	g_free(network->path);
+	g_free(network->group);
+	g_free(network->name);
+	g_free(network);
+}
+
+static void remove_bss(gpointer data)
+{
+	struct g_supplicant_bss *bss = data;
+
+	g_free(bss->path);
+	g_free(bss);
+}
+
+static void remove_peer(gpointer data)
+{
+	GSupplicantPeer *peer = data;
+
+	callback_peer_lost(peer);
+
+	if (peer->groups)
+		g_slist_free_full(peer->groups, g_free);
+
+	if (peer_mapping)
+		g_hash_table_remove(peer_mapping, peer->path);
+
+	if (pending_peer_connection)
+		g_hash_table_remove(pending_peer_connection, peer->path);
+
+	g_free(peer->path);
+	g_free(peer->name);
+	g_free(peer->identifier);
+
+	g_free(peer);
+}
+
+static void debug_strvalmap(const char *label, struct strvalmap *map,
+							unsigned int val)
+{
+	int i;
+
+	for (i = 0; map[i].str; i++) {
+		if (val & map[i].val)
+			SUPPLICANT_DBG("%s: %s", label, map[i].str);
+	}
+}
+
+static void interface_capability_keymgmt(DBusMessageIter *iter, void *user_data)
+{
+	GSupplicantInterface *interface = user_data;
+	const char *str = NULL;
+	int i;
+
+	dbus_message_iter_get_basic(iter, &str);
+	if (!str)
+		return;
+
+	for (i = 0; keymgmt_map[i].str; i++)
+		if (strcmp(str, keymgmt_map[i].str) == 0) {
+			interface->keymgmt_capa |= keymgmt_map[i].val;
+			break;
+		}
+}
+
+static void interface_capability_authalg(DBusMessageIter *iter, void *user_data)
+{
+	GSupplicantInterface *interface = user_data;
+	const char *str = NULL;
+	int i;
+
+	dbus_message_iter_get_basic(iter, &str);
+	if (!str)
+		return;
+
+	for (i = 0; authalg_capa_map[i].str; i++)
+		if (strcmp(str, authalg_capa_map[i].str) == 0) {
+			interface->authalg_capa |= authalg_capa_map[i].val;
+			break;
+		}
+}
+
+static void interface_capability_proto(DBusMessageIter *iter, void *user_data)
+{
+	GSupplicantInterface *interface = user_data;
+	const char *str = NULL;
+	int i;
+
+	dbus_message_iter_get_basic(iter, &str);
+	if (!str)
+		return;
+
+	for (i = 0; proto_capa_map[i].str; i++)
+		if (strcmp(str, proto_capa_map[i].str) == 0) {
+			interface->proto_capa |= proto_capa_map[i].val;
+			break;
+		}
+}
+
+static void interface_capability_pairwise(DBusMessageIter *iter,
+							void *user_data)
+{
+	GSupplicantInterface *interface = user_data;
+	const char *str = NULL;
+	int i;
+
+	dbus_message_iter_get_basic(iter, &str);
+	if (!str)
+		return;
+
+	for (i = 0; pairwise_map[i].str; i++)
+		if (strcmp(str, pairwise_map[i].str) == 0) {
+			interface->pairwise_capa |= pairwise_map[i].val;
+			break;
+		}
+}
+
+static void interface_capability_group(DBusMessageIter *iter, void *user_data)
+{
+	GSupplicantInterface *interface = user_data;
+	const char *str = NULL;
+	int i;
+
+	dbus_message_iter_get_basic(iter, &str);
+	if (!str)
+		return;
+
+	for (i = 0; group_map[i].str; i++)
+		if (strcmp(str, group_map[i].str) == 0) {
+			interface->group_capa |= group_map[i].val;
+			break;
+		}
+}
+
+static void interface_capability_scan(DBusMessageIter *iter, void *user_data)
+{
+	GSupplicantInterface *interface = user_data;
+	const char *str = NULL;
+	int i;
+
+	dbus_message_iter_get_basic(iter, &str);
+	if (!str)
+		return;
+
+	for (i = 0; scan_capa_map[i].str; i++)
+		if (strcmp(str, scan_capa_map[i].str) == 0) {
+			interface->scan_capa |= scan_capa_map[i].val;
+			break;
+		}
+}
+
+static void interface_capability_mode(DBusMessageIter *iter, void *user_data)
+{
+	GSupplicantInterface *interface = user_data;
+	const char *str = NULL;
+	int i;
+
+	dbus_message_iter_get_basic(iter, &str);
+	if (!str)
+		return;
+
+	for (i = 0; mode_capa_map[i].str; i++)
+		if (strcmp(str, mode_capa_map[i].str) == 0) {
+			interface->mode_capa |= mode_capa_map[i].val;
+			break;
+		}
+}
+
+static void interface_capability(const char *key, DBusMessageIter *iter,
+							void *user_data)
+{
+	GSupplicantInterface *interface = user_data;
+
+	if (!key)
+		return;
+
+	if (g_strcmp0(key, "KeyMgmt") == 0)
+		supplicant_dbus_array_foreach(iter,
+				interface_capability_keymgmt, interface);
+	else if (g_strcmp0(key, "AuthAlg") == 0)
+		supplicant_dbus_array_foreach(iter,
+				interface_capability_authalg, interface);
+	else if (g_strcmp0(key, "Protocol") == 0)
+		supplicant_dbus_array_foreach(iter,
+				interface_capability_proto, interface);
+	else if (g_strcmp0(key, "Pairwise") == 0)
+		supplicant_dbus_array_foreach(iter,
+				interface_capability_pairwise, interface);
+	else if (g_strcmp0(key, "Group") == 0)
+		supplicant_dbus_array_foreach(iter,
+				interface_capability_group, interface);
+	else if (g_strcmp0(key, "Scan") == 0)
+		supplicant_dbus_array_foreach(iter,
+				interface_capability_scan, interface);
+	else if (g_strcmp0(key, "Modes") == 0)
+		supplicant_dbus_array_foreach(iter,
+				interface_capability_mode, interface);
+	else if (g_strcmp0(key, "MaxScanSSID") == 0) {
+		dbus_int32_t max_scan_ssid;
+
+		dbus_message_iter_get_basic(iter, &max_scan_ssid);
+		if (max_scan_ssid < 2)
+			max_scan_ssid = 0;
+		interface->max_scan_ssids = max_scan_ssid;
+
+	} else
+		SUPPLICANT_DBG("key %s type %c",
+				key, dbus_message_iter_get_arg_type(iter));
+}
+
+struct set_apscan_data
+{
+	unsigned int ap_scan;
+	GSupplicantInterface *interface;
+};
+
+static void set_apscan(DBusMessageIter *iter, void *user_data)
+{
+	struct set_apscan_data *data = user_data;
+	unsigned int ap_scan = data->ap_scan;
+
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT32, &ap_scan);
+}
+
+static void set_apscan_complete(const char *error,
+		DBusMessageIter *iter, void *user_data)
+{
+	struct set_apscan_data *data = user_data;
+	GSupplicantInterface *interface = data->interface;
+
+	if (error) {
+		interface->ap_create_in_progress = false;
+		SUPPLICANT_DBG("Set AP scan error %s", error);
+		goto error;
+	}
+
+	interface->ap_create_in_progress = true;
+error:
+	dbus_free(data);
+}
+
+int g_supplicant_interface_set_apscan(GSupplicantInterface *interface,
+							unsigned int ap_scan)
+{
+	struct set_apscan_data *data;
+	int ret;
+
+	data = dbus_malloc0(sizeof(*data));
+
+	if (!data)
+		return -ENOMEM;
+
+	data->ap_scan = ap_scan;
+	data->interface = interface;
+
+	ret = supplicant_dbus_property_set(interface->path,
+			SUPPLICANT_INTERFACE ".Interface",
+			"ApScan", DBUS_TYPE_UINT32_AS_STRING,
+			set_apscan, set_apscan_complete, data, NULL);
+	if (ret < 0)
+		dbus_free(data);
+
+	return ret;
+}
+
+void g_supplicant_interface_set_data(GSupplicantInterface *interface,
+								void *data)
+{
+	if (!interface)
+		return;
+
+	interface->data = data;
+
+	if (!data)
+		interface->scan_callback = NULL;
+}
+
+void *g_supplicant_interface_get_data(GSupplicantInterface *interface)
+{
+	if (!interface)
+		return NULL;
+
+	return interface->data;
+}
+
+const char *g_supplicant_interface_get_ifname(GSupplicantInterface *interface)
+{
+	if (!interface)
+		return NULL;
+
+	return interface->ifname;
+}
+
+const char *g_supplicant_interface_get_driver(GSupplicantInterface *interface)
+{
+	if (!interface)
+		return NULL;
+
+	return interface->driver;
+}
+
+GSupplicantState g_supplicant_interface_get_state(
+					GSupplicantInterface *interface)
+{
+	if (!interface)
+		return G_SUPPLICANT_STATE_UNKNOWN;
+
+	return interface->state;
+}
+
+const char *g_supplicant_interface_get_wps_key(GSupplicantInterface *interface)
+{
+	if (!interface)
+		return NULL;
+
+	return (const char *)interface->wps_cred.key;
+}
+
+const void *g_supplicant_interface_get_wps_ssid(GSupplicantInterface *interface,
+							unsigned int *ssid_len)
+{
+	if (!ssid_len)
+		return NULL;
+
+	if (!interface || interface->wps_cred.ssid_len == 0) {
+		*ssid_len = 0;
+		return NULL;
+	}
+
+	*ssid_len = interface->wps_cred.ssid_len;
+	return interface->wps_cred.ssid;
+}
+
+GSupplicantWpsState g_supplicant_interface_get_wps_state(
+					GSupplicantInterface *interface)
+{
+	if (!interface)
+		return G_SUPPLICANT_WPS_STATE_UNKNOWN;
+
+	return interface->wps_state;
+}
+
+unsigned int g_supplicant_interface_get_mode(GSupplicantInterface *interface)
+{
+	if (!interface)
+		return 0;
+
+	return interface->mode_capa;
+}
+
+unsigned int g_supplicant_interface_get_max_scan_ssids(
+				GSupplicantInterface *interface)
+{
+	if (!interface)
+		return 0;
+
+	return interface->max_scan_ssids;
+}
+
+static void set_network_enabled(DBusMessageIter *iter, void *user_data)
+{
+	dbus_bool_t enable = *(dbus_bool_t *)user_data;
+
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_BOOLEAN, &enable);
+}
+
+int g_supplicant_interface_enable_selected_network(GSupplicantInterface *interface,
+							dbus_bool_t enable)
+{
+	if (!interface)
+		return -1;
+
+	if (!interface->network_path)
+		return -1;
+
+	SUPPLICANT_DBG(" ");
+	return supplicant_dbus_property_set(interface->network_path,
+				SUPPLICANT_INTERFACE ".Network",
+				"Enabled", DBUS_TYPE_BOOLEAN_AS_STRING,
+				set_network_enabled, NULL, &enable, NULL);
+}
+
+dbus_bool_t g_supplicant_interface_get_ready(GSupplicantInterface *interface)
+{
+	if (!interface)
+		return FALSE;
+
+	return interface->ready;
+}
+
+GSupplicantInterface *g_supplicant_network_get_interface(
+					GSupplicantNetwork *network)
+{
+	if (!network)
+		return NULL;
+
+	return network->interface;
+}
+
+const char *g_supplicant_network_get_name(GSupplicantNetwork *network)
+{
+	if (!network || !network->name)
+		return "";
+
+	return network->name;
+}
+
+const char *g_supplicant_network_get_identifier(GSupplicantNetwork *network)
+{
+	if (!network || !network->group)
+		return "";
+
+	return network->group;
+}
+
+const char *g_supplicant_network_get_path(GSupplicantNetwork *network)
+{
+	if (!network || !network->path)
+		return NULL;
+
+	return network->path;
+}
+
+const char *g_supplicant_network_get_mode(GSupplicantNetwork *network)
+{
+	if (!network)
+		return G_SUPPLICANT_MODE_UNKNOWN;
+
+	return mode2string(network->mode);
+}
+
+const char *g_supplicant_network_get_security(GSupplicantNetwork *network)
+{
+	if (!network)
+		return G_SUPPLICANT_SECURITY_UNKNOWN;
+
+	return security2string(network->security);
+}
+
+const void *g_supplicant_network_get_ssid(GSupplicantNetwork *network,
+						unsigned int *ssid_len)
+{
+	if (!network) {
+		*ssid_len = 0;
+		return NULL;
+	}
+
+	*ssid_len = network->ssid_len;
+	return network->ssid;
+}
+
+dbus_int16_t g_supplicant_network_get_signal(GSupplicantNetwork *network)
+{
+	if (!network)
+		return 0;
+
+	return network->signal;
+}
+
+dbus_uint16_t g_supplicant_network_get_frequency(GSupplicantNetwork *network)
+{
+	if (!network)
+		return 0;
+
+	return network->frequency;
+}
+
+dbus_bool_t g_supplicant_network_get_wps(GSupplicantNetwork *network)
+{
+	if (!network)
+		return FALSE;
+
+	return network->wps;
+}
+
+dbus_bool_t g_supplicant_network_is_wps_active(GSupplicantNetwork *network)
+{
+	if (!network)
+		return FALSE;
+
+	if (network->wps_capabilities & G_SUPPLICANT_WPS_CONFIGURED)
+		return TRUE;
+
+	return FALSE;
+}
+
+dbus_bool_t g_supplicant_network_is_wps_pbc(GSupplicantNetwork *network)
+{
+	if (!network)
+		return FALSE;
+
+	if (network->wps_capabilities & G_SUPPLICANT_WPS_PBC)
+		return TRUE;
+
+	return FALSE;
+}
+
+dbus_bool_t g_supplicant_network_is_wps_advertizing(GSupplicantNetwork *network)
+{
+	if (!network)
+		return FALSE;
+
+	if (network->wps_capabilities & G_SUPPLICANT_WPS_REGISTRAR)
+		return TRUE;
+
+	return FALSE;
+}
+
+GSupplicantInterface *g_supplicant_peer_get_interface(GSupplicantPeer *peer)
+{
+	if (!peer)
+		return NULL;
+
+	return peer->interface;
+}
+
+const char *g_supplicant_peer_get_path(GSupplicantPeer *peer)
+{
+	if (!peer)
+		return NULL;
+
+	return peer->path;
+}
+
+const char *g_supplicant_peer_get_identifier(GSupplicantPeer *peer)
+{
+	if (!peer)
+		return NULL;
+
+	return peer->identifier;
+}
+
+const void *g_supplicant_peer_get_device_address(GSupplicantPeer *peer)
+{
+	if (!peer)
+		return NULL;
+
+	return peer->device_address;
+}
+
+const void *g_supplicant_peer_get_iface_address(GSupplicantPeer *peer)
+{
+	if (!peer)
+		return NULL;
+
+	return peer->iface_address;
+}
+
+const char *g_supplicant_peer_get_name(GSupplicantPeer *peer)
+{
+	if (!peer)
+		return NULL;
+
+	return peer->name;
+}
+
+const unsigned char *g_supplicant_peer_get_widi_ies(GSupplicantPeer *peer,
+								int *length)
+{
+	if (!peer || !length)
+		return NULL;
+
+	*length = peer->widi_ies_length;
+	return peer->widi_ies;
+}
+
+bool g_supplicant_peer_is_wps_pbc(GSupplicantPeer *peer)
+{
+	if (!peer)
+		return false;
+
+	if (peer->wps_capabilities & G_SUPPLICANT_WPS_PBC)
+		return true;
+
+	return false;
+}
+
+bool g_supplicant_peer_is_wps_pin(GSupplicantPeer *peer)
+{
+	if (!peer)
+		return false;
+
+	if (peer->wps_capabilities & G_SUPPLICANT_WPS_PIN)
+		return true;
+
+	return false;
+}
+
+bool g_supplicant_peer_is_in_a_group(GSupplicantPeer *peer)
+{
+	if (!peer || !peer->groups)
+		return false;
+
+	return true;
+}
+
+GSupplicantInterface *g_supplicant_peer_get_group_interface(GSupplicantPeer *peer)
+{
+	if (!peer)
+		return NULL;
+
+	return (GSupplicantInterface *) peer->current_group_iface;
+}
+
+bool g_supplicant_peer_is_client(GSupplicantPeer *peer)
+{
+	GSupplicantGroup *group;
+	GSList *list;
+
+	if (!peer)
+		return false;
+
+	for (list = peer->groups; list; list = list->next) {
+		const char *path = list->data;
+
+		group = g_hash_table_lookup(group_mapping, path);
+		if (!group)
+			continue;
+
+		if (group->role != G_SUPPLICANT_GROUP_ROLE_CLIENT ||
+				group->orig_interface != peer->interface)
+			continue;
+
+		if (group->interface == peer->current_group_iface)
+			return true;
+	}
+
+	return false;
+}
+
+bool g_supplicant_peer_has_requested_connection(GSupplicantPeer *peer)
+{
+	if (!peer)
+		return false;
+
+	return peer->connection_requested;
+}
+
+static void merge_network(GSupplicantNetwork *network)
+{
+	GString *str;
+	const char *ssid, *mode, *key_mgmt;
+	unsigned int i, ssid_len;
+	char *group;
+
+	ssid = g_hash_table_lookup(network->config_table, "ssid");
+	mode = g_hash_table_lookup(network->config_table, "mode");
+	key_mgmt = g_hash_table_lookup(network->config_table, "key_mgmt");
+
+	SUPPLICANT_DBG("ssid %s mode %s", ssid, mode);
+
+	if (ssid)
+		ssid_len = strlen(ssid);
+	else
+		ssid_len = 0;
+
+	str = g_string_sized_new((ssid_len * 2) + 24);
+	if (!str)
+		return;
+
+	for (i = 0; i < ssid_len; i++)
+		g_string_append_printf(str, "%02x", ssid[i]);
+
+	if (g_strcmp0(mode, "0") == 0)
+		g_string_append_printf(str, "_managed");
+	else if (g_strcmp0(mode, "1") == 0)
+		g_string_append_printf(str, "_adhoc");
+
+	if (g_strcmp0(key_mgmt, "WPA-PSK") == 0)
+		g_string_append_printf(str, "_psk");
+
+	group = g_string_free(str, FALSE);
+
+	SUPPLICANT_DBG("%s", group);
+
+	g_free(group);
+
+	g_hash_table_destroy(network->config_table);
+
+	g_free(network->path);
+	g_free(network);
+}
+
+static void network_property(const char *key, DBusMessageIter *iter,
+							void *user_data)
+{
+	GSupplicantNetwork *network = user_data;
+
+	if (!network->interface)
+		return;
+
+	if (!key) {
+		merge_network(network);
+		return;
+	}
+
+	if (g_strcmp0(key, "Enabled") == 0) {
+		dbus_bool_t enabled = FALSE;
+
+		dbus_message_iter_get_basic(iter, &enabled);
+	} else if (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_STRING) {
+		const char *str = NULL;
+
+		dbus_message_iter_get_basic(iter, &str);
+		if (str) {
+			g_hash_table_replace(network->config_table,
+						g_strdup(key), g_strdup(str));
+		}
+	} else
+		SUPPLICANT_DBG("key %s type %c",
+				key, dbus_message_iter_get_arg_type(iter));
+}
+
+static void interface_network_added(DBusMessageIter *iter, void *user_data)
+{
+	GSupplicantInterface *interface = user_data;
+	GSupplicantNetwork *network;
+	const char *path = NULL;
+
+	SUPPLICANT_DBG("");
+
+	dbus_message_iter_get_basic(iter, &path);
+	if (!path)
+		return;
+
+	if (g_strcmp0(path, "/") == 0)
+		return;
+
+	network = g_hash_table_lookup(interface->net_mapping, path);
+	if (network)
+		return;
+
+	network = g_try_new0(GSupplicantNetwork, 1);
+	if (!network)
+		return;
+
+	network->interface = interface;
+	network->path = g_strdup(path);
+
+	network->config_table = g_hash_table_new_full(g_str_hash, g_str_equal,
+							g_free, g_free);
+
+	dbus_message_iter_next(iter);
+	if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) {
+		supplicant_dbus_property_foreach(iter, network_property,
+								network);
+		network_property(NULL, NULL, network);
+		return;
+	}
+
+	supplicant_dbus_property_get_all(path,
+				SUPPLICANT_INTERFACE ".Network",
+					network_property, network, NULL);
+}
+
+static void interface_network_removed(DBusMessageIter *iter, void *user_data)
+{
+	GSupplicantInterface *interface = user_data;
+	GSupplicantNetwork *network;
+	const char *path = NULL;
+
+	dbus_message_iter_get_basic(iter, &path);
+	if (!path)
+		return;
+
+	network = g_hash_table_lookup(interface->net_mapping, path);
+	if (!network)
+		return;
+
+	g_hash_table_remove(interface->net_mapping, path);
+}
+
+static char *create_name(unsigned char *ssid, int ssid_len)
+{
+	GString *string;
+	const gchar *remainder, *invalid;
+	int valid_bytes, remaining_bytes;
+
+	if (ssid_len < 1 || ssid[0] == '\0')
+		return g_strdup("");
+
+	string = NULL;
+	remainder = (const gchar *)ssid;
+	remaining_bytes = ssid_len;
+
+	while (remaining_bytes != 0) {
+		if (g_utf8_validate(remainder, remaining_bytes,
+					&invalid)) {
+			break;
+		}
+
+		valid_bytes = invalid - remainder;
+
+		if (!string)
+			string = g_string_sized_new(remaining_bytes);
+
+		g_string_append_len(string, remainder, valid_bytes);
+
+		/* append U+FFFD REPLACEMENT CHARACTER */
+		g_string_append(string, "\357\277\275");
+
+		remaining_bytes -= valid_bytes + 1;
+		remainder = invalid + 1;
+	}
+
+	if (!string)
+		return g_strndup((const gchar *)ssid, ssid_len + 1);
+
+	g_string_append(string, remainder);
+
+	return g_string_free(string, FALSE);
+}
+
+static char *create_group(struct g_supplicant_bss *bss)
+{
+	GString *str;
+	unsigned int i;
+	const char *mode, *security;
+
+	str = g_string_sized_new((bss->ssid_len * 2) + 24);
+	if (!str)
+		return NULL;
+
+	if (bss->ssid_len > 0 && bss->ssid[0] != '\0') {
+		for (i = 0; i < bss->ssid_len; i++)
+			g_string_append_printf(str, "%02x", bss->ssid[i]);
+	} else
+		g_string_append_printf(str, "hidden");
+
+	mode = mode2string(bss->mode);
+	if (mode)
+		g_string_append_printf(str, "_%s", mode);
+
+	security = security2string(bss->security);
+	if (security)
+		g_string_append_printf(str, "_%s", security);
+
+	return g_string_free(str, FALSE);
+}
+
+static void add_or_replace_bss_to_network(struct g_supplicant_bss *bss)
+{
+	GSupplicantInterface *interface = bss->interface;
+	GSupplicantNetwork *network;
+	char *group;
+
+	group = create_group(bss);
+	SUPPLICANT_DBG("New group created: %s", group);
+
+	if (!group)
+		return;
+
+	network = g_hash_table_lookup(interface->network_table, group);
+	if (network) {
+		g_free(group);
+		SUPPLICANT_DBG("Network %s already exist", network->name);
+
+		goto done;
+	}
+
+	network = g_try_new0(GSupplicantNetwork, 1);
+	if (!network) {
+		g_free(group);
+		return;
+	}
+
+	network->interface = interface;
+	if (!network->path)
+		network->path = g_strdup(bss->path);
+	network->group = group;
+	network->name = create_name(bss->ssid, bss->ssid_len);
+	network->mode = bss->mode;
+	network->security = bss->security;
+	network->ssid_len = bss->ssid_len;
+	memcpy(network->ssid, bss->ssid, bss->ssid_len);
+	network->signal = bss->signal;
+	network->frequency = bss->frequency;
+	network->best_bss = bss;
+
+	SUPPLICANT_DBG("New network %s created", network->name);
+
+	network->bss_table = g_hash_table_new_full(g_str_hash, g_str_equal,
+							NULL, remove_bss);
+
+	network->config_table = g_hash_table_new_full(g_str_hash, g_str_equal,
+							g_free, g_free);
+
+	g_hash_table_replace(interface->network_table,
+						network->group, network);
+
+	callback_network_added(network);
+
+done:
+	/* We update network's WPS properties if only bss provides WPS. */
+	if ((bss->keymgmt & G_SUPPLICANT_KEYMGMT_WPS) != 0) {
+		network->wps = TRUE;
+		network->wps_capabilities |= bss->wps_capabilities;
+	}
+
+	if (bss->signal > network->signal) {
+		network->signal = bss->signal;
+		network->best_bss = bss;
+		callback_network_changed(network, "Signal");
+	}
+
+	g_hash_table_replace(interface->bss_mapping, bss->path, network);
+	g_hash_table_replace(network->bss_table, bss->path, bss);
+
+	g_hash_table_replace(bss_mapping, bss->path, interface);
+}
+
+static void bss_rates(DBusMessageIter *iter, void *user_data)
+{
+	struct g_supplicant_bss *bss = user_data;
+	dbus_uint32_t rate = 0;
+
+	dbus_message_iter_get_basic(iter, &rate);
+	if (rate == 0)
+		return;
+
+	if (rate > bss->maxrate)
+		bss->maxrate = rate;
+}
+
+static void bss_keymgmt(DBusMessageIter *iter, void *user_data)
+{
+	unsigned int *keymgmt = user_data;
+	const char *str = NULL;
+	int i;
+
+	dbus_message_iter_get_basic(iter, &str);
+	if (!str)
+		return;
+
+	for (i = 0; keymgmt_map[i].str; i++)
+		if (strcmp(str, keymgmt_map[i].str) == 0) {
+			SUPPLICANT_DBG("Keymgmt: %s", str);
+			*keymgmt |= keymgmt_map[i].val;
+			break;
+		}
+}
+
+static void bss_group(DBusMessageIter *iter, void *user_data)
+{
+	unsigned int *group = user_data;
+	const char *str = NULL;
+	int i;
+
+	dbus_message_iter_get_basic(iter, &str);
+	if (!str)
+		return;
+
+	for (i = 0; group_map[i].str; i++)
+		if (strcmp(str, group_map[i].str) == 0) {
+			SUPPLICANT_DBG("Group: %s", str);
+			*group |= group_map[i].val;
+			break;
+		}
+}
+
+static void bss_pairwise(DBusMessageIter *iter, void *user_data)
+{
+	unsigned int *pairwise = user_data;
+	const char *str = NULL;
+	int i;
+
+	dbus_message_iter_get_basic(iter, &str);
+	if (!str)
+		return;
+
+	for (i = 0; pairwise_map[i].str; i++)
+		if (strcmp(str, pairwise_map[i].str) == 0) {
+			SUPPLICANT_DBG("Pairwise: %s", str);
+			*pairwise |= pairwise_map[i].val;
+			break;
+		}
+}
+
+static void bss_wpa(const char *key, DBusMessageIter *iter,
+			void *user_data)
+{
+	struct g_supplicant_bss *bss = user_data;
+	unsigned int value = 0;
+
+	SUPPLICANT_DBG("Key: %s", key);
+
+	if (g_strcmp0(key, "KeyMgmt") == 0) {
+		supplicant_dbus_array_foreach(iter, bss_keymgmt, &value);
+
+		if (bss->rsn_selected)
+			bss->rsn_keymgmt = value;
+		else
+			bss->wpa_keymgmt = value;
+	} else if (g_strcmp0(key, "Group") == 0) {
+		supplicant_dbus_array_foreach(iter, bss_group, &value);
+
+		if (bss->rsn_selected)
+			bss->rsn_group = value;
+		else
+			bss->wpa_group = value;
+	} else if (g_strcmp0(key, "Pairwise") == 0) {
+		supplicant_dbus_array_foreach(iter, bss_pairwise, &value);
+
+		if (bss->rsn_selected)
+			bss->rsn_pairwise = value;
+		else
+			bss->wpa_pairwise = value;
+	}
+}
+
+static unsigned int get_tlv(unsigned char *ie, unsigned int ie_size,
+							unsigned int type)
+{
+	unsigned int len = 0;
+
+	while (len + 4 < ie_size) {
+		unsigned int hi = ie[len];
+		unsigned int lo = ie[len + 1];
+		unsigned int tmp_type = (hi << 8) + lo;
+		unsigned int v_len = 0;
+
+		/* hi and lo are used to recreate an unsigned int
+		 * based on 2 8bits length unsigned int. */
+
+		hi = ie[len + 2];
+		lo = ie[len + 3];
+		v_len = (hi << 8) + lo;
+
+		if (tmp_type == type) {
+			unsigned int ret_value = 0;
+			unsigned char *value = (unsigned char *)&ret_value;
+
+			SUPPLICANT_DBG("IE: match type 0x%x", type);
+
+			/* Verifying length relevance */
+			if (v_len > sizeof(unsigned int) ||
+				len + 4 + v_len > ie_size)
+				break;
+
+			memcpy(value, ie + len + 4, v_len);
+
+			SUPPLICANT_DBG("returning 0x%x", ret_value);
+			return ret_value;
+		}
+
+		len += v_len + 4;
+	}
+
+	SUPPLICANT_DBG("returning 0");
+	return 0;
+}
+
+static void bss_process_ies(DBusMessageIter *iter, void *user_data)
+{
+	struct g_supplicant_bss *bss = user_data;
+	const unsigned char WPS_OUI[] = { 0x00, 0x50, 0xf2, 0x04 };
+	unsigned char *ie, *ie_end;
+	DBusMessageIter array;
+	unsigned int value;
+	int ie_len;
+
+#define WMM_WPA1_WPS_INFO 221
+#define WPS_INFO_MIN_LEN  6
+#define WPS_VERSION_TLV   0x104A
+#define WPS_STATE_TLV     0x1044
+#define WPS_METHODS_TLV   0x1012
+#define WPS_REGISTRAR_TLV 0x1041
+#define WPS_VERSION       0x10
+#define WPS_PBC           0x04
+#define WPS_PIN           0x00
+#define WPS_CONFIGURED    0x02
+
+	dbus_message_iter_recurse(iter, &array);
+	dbus_message_iter_get_fixed_array(&array, &ie, &ie_len);
+
+	if (!ie || ie_len < 2)
+		return;
+
+	bss->wps_capabilities = 0;
+	bss->keymgmt = 0;
+
+	for (ie_end = ie + ie_len; ie < ie_end && ie + ie[1] + 1 <= ie_end;
+							ie += ie[1] + 2) {
+
+		if (ie[0] != WMM_WPA1_WPS_INFO || ie[1] < WPS_INFO_MIN_LEN ||
+			memcmp(ie+2, WPS_OUI, sizeof(WPS_OUI)) != 0)
+			continue;
+
+		SUPPLICANT_DBG("IE: match WPS_OUI");
+
+		value = get_tlv(&ie[6], ie[1], WPS_STATE_TLV);
+		if (get_tlv(&ie[6], ie[1], WPS_VERSION_TLV) == WPS_VERSION &&
+								value != 0) {
+			bss->keymgmt |= G_SUPPLICANT_KEYMGMT_WPS;
+
+			if (value == WPS_CONFIGURED)
+				bss->wps_capabilities |=
+					G_SUPPLICANT_WPS_CONFIGURED;
+		}
+
+		value = get_tlv(&ie[6], ie[1], WPS_METHODS_TLV);
+		if (value != 0) {
+			if (GUINT16_FROM_BE(value) == WPS_PBC)
+				bss->wps_capabilities |= G_SUPPLICANT_WPS_PBC;
+			if (GUINT16_FROM_BE(value) == WPS_PIN)
+				bss->wps_capabilities |= G_SUPPLICANT_WPS_PIN;
+		} else
+			bss->wps_capabilities |=
+				G_SUPPLICANT_WPS_PBC | G_SUPPLICANT_WPS_PIN;
+
+		/* If the AP sends this it means it's advertizing
+		 * as a registrar and the WPS process is launched
+		 * on its side */
+		if (get_tlv(&ie[6], ie[1], WPS_REGISTRAR_TLV) != 0)
+			bss->wps_capabilities |= G_SUPPLICANT_WPS_REGISTRAR;
+
+		SUPPLICANT_DBG("WPS Methods 0x%x", bss->wps_capabilities);
+	}
+}
+
+static void bss_compute_security(struct g_supplicant_bss *bss)
+{
+	/*
+	 * Combining RSN and WPA keymgmt
+	 * We combine it since parsing IEs might have set something for WPS. */
+	bss->keymgmt |= bss->rsn_keymgmt | bss->wpa_keymgmt;
+
+	bss->ieee8021x = FALSE;
+	bss->psk = FALSE;
+
+	if (bss->keymgmt &
+			(G_SUPPLICANT_KEYMGMT_WPA_EAP |
+				G_SUPPLICANT_KEYMGMT_WPA_FT_EAP |
+				G_SUPPLICANT_KEYMGMT_WPA_EAP_256))
+		bss->ieee8021x = TRUE;
+
+	if (bss->keymgmt &
+			(G_SUPPLICANT_KEYMGMT_WPA_PSK |
+				G_SUPPLICANT_KEYMGMT_WPA_FT_PSK |
+				G_SUPPLICANT_KEYMGMT_WPA_PSK_256))
+		bss->psk = TRUE;
+
+	if (bss->ieee8021x)
+		bss->security = G_SUPPLICANT_SECURITY_IEEE8021X;
+	else if (bss->psk)
+		bss->security = G_SUPPLICANT_SECURITY_PSK;
+	else if (bss->privacy)
+		bss->security = G_SUPPLICANT_SECURITY_WEP;
+	else
+		bss->security = G_SUPPLICANT_SECURITY_NONE;
+}
+
+
+static void bss_property(const char *key, DBusMessageIter *iter,
+							void *user_data)
+{
+	struct g_supplicant_bss *bss = user_data;
+
+	if (!bss->interface)
+		return;
+
+	SUPPLICANT_DBG("key %s", key);
+
+	if (!key)
+		return;
+
+	if (g_strcmp0(key, "BSSID") == 0) {
+		DBusMessageIter array;
+		unsigned char *addr;
+		int addr_len;
+
+		dbus_message_iter_recurse(iter, &array);
+		dbus_message_iter_get_fixed_array(&array, &addr, &addr_len);
+
+		if (addr_len == 6)
+			memcpy(bss->bssid, addr, addr_len);
+	} else if (g_strcmp0(key, "SSID") == 0) {
+		DBusMessageIter array;
+		unsigned char *ssid;
+		int ssid_len;
+
+		dbus_message_iter_recurse(iter, &array);
+		dbus_message_iter_get_fixed_array(&array, &ssid, &ssid_len);
+
+		if (ssid_len > 0 && ssid_len < 33) {
+			memcpy(bss->ssid, ssid, ssid_len);
+			bss->ssid_len = ssid_len;
+		} else {
+			memset(bss->ssid, 0, sizeof(bss->ssid));
+			bss->ssid_len = 0;
+		}
+	} else if (g_strcmp0(key, "Capabilities") == 0) {
+		dbus_uint16_t capabilities = 0x0000;
+
+		dbus_message_iter_get_basic(iter, &capabilities);
+
+		if (capabilities & IEEE80211_CAP_ESS)
+			bss->mode = G_SUPPLICANT_MODE_INFRA;
+		else if (capabilities & IEEE80211_CAP_IBSS)
+			bss->mode = G_SUPPLICANT_MODE_IBSS;
+
+		if (capabilities & IEEE80211_CAP_PRIVACY)
+			bss->privacy = TRUE;
+	} else if (g_strcmp0(key, "Mode") == 0) {
+		const char *mode = NULL;
+
+		dbus_message_iter_get_basic(iter, &mode);
+		bss->mode = string2mode(mode);
+	} else if (g_strcmp0(key, "Frequency") == 0) {
+		dbus_uint16_t frequency = 0;
+
+		dbus_message_iter_get_basic(iter, &frequency);
+		bss->frequency = frequency;
+	} else if (g_strcmp0(key, "Signal") == 0) {
+		dbus_int16_t signal = 0;
+
+		dbus_message_iter_get_basic(iter, &signal);
+
+		bss->signal = signal;
+		if (!bss->signal)
+			bss->signal = BSS_UNKNOWN_STRENGTH;
+
+	} else if (g_strcmp0(key, "Level") == 0) {
+		dbus_int32_t level = 0;
+
+		dbus_message_iter_get_basic(iter, &level);
+	} else if (g_strcmp0(key, "Rates") == 0) {
+		supplicant_dbus_array_foreach(iter, bss_rates, bss);
+	} else if (g_strcmp0(key, "MaxRate") == 0) {
+		dbus_uint32_t maxrate = 0;
+
+		dbus_message_iter_get_basic(iter, &maxrate);
+		if (maxrate != 0)
+			bss->maxrate = maxrate;
+	} else if (g_strcmp0(key, "Privacy") == 0) {
+		dbus_bool_t privacy = FALSE;
+
+		dbus_message_iter_get_basic(iter, &privacy);
+		bss->privacy = privacy;
+	} else if (g_strcmp0(key, "RSN") == 0) {
+		bss->rsn_selected = TRUE;
+
+		supplicant_dbus_property_foreach(iter, bss_wpa, bss);
+	} else if (g_strcmp0(key, "WPA") == 0) {
+		bss->rsn_selected = FALSE;
+
+		supplicant_dbus_property_foreach(iter, bss_wpa, bss);
+	} else if (g_strcmp0(key, "IEs") == 0)
+		bss_process_ies(iter, bss);
+	else
+		SUPPLICANT_DBG("key %s type %c",
+				key, dbus_message_iter_get_arg_type(iter));
+}
+
+static struct g_supplicant_bss *interface_bss_added(DBusMessageIter *iter,
+							void *user_data)
+{
+	GSupplicantInterface *interface = user_data;
+	GSupplicantNetwork *network;
+	struct g_supplicant_bss *bss;
+	const char *path = NULL;
+
+	SUPPLICANT_DBG("");
+
+	dbus_message_iter_get_basic(iter, &path);
+	if (!path)
+		return NULL;
+
+	if (g_strcmp0(path, "/") == 0)
+		return NULL;
+
+	SUPPLICANT_DBG("%s", path);
+
+	network = g_hash_table_lookup(interface->bss_mapping, path);
+	if (network) {
+		bss = g_hash_table_lookup(network->bss_table, path);
+		if (bss)
+			return NULL;
+	}
+
+	bss = g_try_new0(struct g_supplicant_bss, 1);
+	if (!bss)
+		return NULL;
+
+	bss->interface = interface;
+	bss->path = g_strdup(path);
+	bss->signal = BSS_UNKNOWN_STRENGTH;
+
+	return bss;
+}
+
+static void interface_bss_added_with_keys(DBusMessageIter *iter,
+						void *user_data)
+{
+	struct g_supplicant_bss *bss;
+
+	SUPPLICANT_DBG("");
+
+	bss = interface_bss_added(iter, user_data);
+	if (!bss)
+		return;
+
+	dbus_message_iter_next(iter);
+
+	if (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_INVALID)
+		return;
+
+	supplicant_dbus_property_foreach(iter, bss_property, bss);
+
+	bss_compute_security(bss);
+	add_or_replace_bss_to_network(bss);
+}
+
+static void interface_bss_added_without_keys(DBusMessageIter *iter,
+						void *user_data)
+{
+	struct g_supplicant_bss *bss;
+
+	SUPPLICANT_DBG("");
+
+	bss = interface_bss_added(iter, user_data);
+	if (!bss)
+		return;
+
+	supplicant_dbus_property_get_all(bss->path,
+					SUPPLICANT_INTERFACE ".BSS",
+					bss_property, bss, NULL);
+
+	bss_compute_security(bss);
+	add_or_replace_bss_to_network(bss);
+}
+
+static void update_signal(gpointer key, gpointer value,
+						gpointer user_data)
+{
+	struct g_supplicant_bss *bss = value;
+	GSupplicantNetwork *network = user_data;
+
+	if (bss->signal > network->signal) {
+		network->signal = bss->signal;
+		network->best_bss = bss;
+	}
+}
+
+static void update_network_signal(GSupplicantNetwork *network)
+{
+	if (g_hash_table_size(network->bss_table) <= 1 && network->best_bss)
+		return;
+
+	g_hash_table_foreach(network->bss_table,
+				update_signal, network);
+
+	SUPPLICANT_DBG("New network signal %d", network->signal);
+}
+
+static void interface_bss_removed(DBusMessageIter *iter, void *user_data)
+{
+	GSupplicantInterface *interface = user_data;
+	GSupplicantNetwork *network;
+	struct g_supplicant_bss *bss = NULL;
+	const char *path = NULL;
+
+	dbus_message_iter_get_basic(iter, &path);
+	if (!path)
+		return;
+
+	network = g_hash_table_lookup(interface->bss_mapping, path);
+	if (!network)
+		return;
+
+	bss = g_hash_table_lookup(network->bss_table, path);
+	if (network->best_bss == bss) {
+		network->best_bss = NULL;
+		network->signal = BSS_UNKNOWN_STRENGTH;
+	}
+
+	g_hash_table_remove(bss_mapping, path);
+
+	g_hash_table_remove(interface->bss_mapping, path);
+	g_hash_table_remove(network->bss_table, path);
+
+	update_network_signal(network);
+
+	if (g_hash_table_size(network->bss_table) == 0)
+		g_hash_table_remove(interface->network_table, network->group);
+}
+
+static void set_config_methods(DBusMessageIter *iter, void *user_data)
+{
+	const char *config_methods = "push_button";
+
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING,
+							&config_methods);
+}
+
+static void interface_property(const char *key, DBusMessageIter *iter,
+							void *user_data)
+{
+	GSupplicantInterface *interface = user_data;
+
+	if (!interface)
+		return;
+
+	SUPPLICANT_DBG("%s", key);
+
+	if (!key) {
+		debug_strvalmap("KeyMgmt capability", keymgmt_map,
+						interface->keymgmt_capa);
+		debug_strvalmap("AuthAlg capability", authalg_capa_map,
+						interface->authalg_capa);
+		debug_strvalmap("Protocol capability", proto_capa_map,
+						interface->proto_capa);
+		debug_strvalmap("Pairwise capability", pairwise_map,
+						interface->pairwise_capa);
+		debug_strvalmap("Group capability", group_map,
+						interface->group_capa);
+		debug_strvalmap("Scan capability", scan_capa_map,
+						interface->scan_capa);
+		debug_strvalmap("Mode capability", mode_capa_map,
+						interface->mode_capa);
+
+
+		supplicant_dbus_property_set(interface->path,
+				SUPPLICANT_INTERFACE ".Interface.WPS",
+				"ConfigMethods", DBUS_TYPE_STRING_AS_STRING,
+				set_config_methods, NULL, NULL, NULL);
+
+		if (interface->ready)
+			callback_interface_added(interface);
+
+		return;
+	}
+
+	if (g_strcmp0(key, "Capabilities") == 0) {
+		supplicant_dbus_property_foreach(iter, interface_capability,
+								interface);
+		if (interface->mode_capa & G_SUPPLICANT_CAPABILITY_MODE_P2P)
+			interface->p2p_support = true;
+	} else if (g_strcmp0(key, "State") == 0) {
+		const char *str = NULL;
+
+		dbus_message_iter_get_basic(iter, &str);
+		if (str)
+			if (string2state(str) != interface->state) {
+				interface->state = string2state(str);
+				callback_interface_state(interface);
+			}
+
+		if (interface->ap_create_in_progress) {
+			if (interface->state == G_SUPPLICANT_STATE_DISCONNECTED)
+				callback_ap_create_fail(interface);
+
+			interface->ap_create_in_progress = false;
+		}
+
+		if (interface->state == G_SUPPLICANT_STATE_DISABLED)
+			interface->ready = FALSE;
+		else
+			interface->ready = TRUE;
+
+		SUPPLICANT_DBG("state %s (%d)", str, interface->state);
+	} else if (g_strcmp0(key, "Scanning") == 0) {
+		dbus_bool_t scanning = FALSE;
+
+		dbus_message_iter_get_basic(iter, &scanning);
+		interface->scanning = scanning;
+
+		if (interface->ready) {
+			if (interface->scanning)
+				callback_scan_started(interface);
+			else
+				callback_scan_finished(interface);
+		}
+	} else if (g_strcmp0(key, "ApScan") == 0) {
+		int apscan = 1;
+
+		dbus_message_iter_get_basic(iter, &apscan);
+		interface->apscan = apscan;
+	} else if (g_strcmp0(key, "Ifname") == 0) {
+		const char *str = NULL;
+
+		dbus_message_iter_get_basic(iter, &str);
+		if (str) {
+			g_free(interface->ifname);
+			interface->ifname = g_strdup(str);
+		}
+	} else if (g_strcmp0(key, "Driver") == 0) {
+		const char *str = NULL;
+
+		dbus_message_iter_get_basic(iter, &str);
+		if (str) {
+			g_free(interface->driver);
+			interface->driver = g_strdup(str);
+		}
+	} else if (g_strcmp0(key, "BridgeIfname") == 0) {
+		const char *str = NULL;
+
+		dbus_message_iter_get_basic(iter, &str);
+		if (str) {
+			g_free(interface->bridge);
+			interface->bridge = g_strdup(str);
+		}
+	} else if (g_strcmp0(key, "CurrentBSS") == 0) {
+		interface_bss_added_without_keys(iter, interface);
+	} else if (g_strcmp0(key, "CurrentNetwork") == 0) {
+		interface_network_added(iter, interface);
+	} else if (g_strcmp0(key, "BSSs") == 0) {
+		supplicant_dbus_array_foreach(iter,
+					interface_bss_added_without_keys,
+					interface);
+	} else if (g_strcmp0(key, "Blobs") == 0) {
+		/* Nothing */
+	} else if (g_strcmp0(key, "Networks") == 0) {
+		supplicant_dbus_array_foreach(iter, interface_network_added,
+								interface);
+	} else
+		SUPPLICANT_DBG("key %s type %c",
+				key, dbus_message_iter_get_arg_type(iter));
+}
+
+static void scan_network_update(DBusMessageIter *iter, void *user_data)
+{
+	GSupplicantInterface *interface = user_data;
+	GSupplicantNetwork *network;
+	char *path;
+
+	if (!iter)
+		return;
+
+	dbus_message_iter_get_basic(iter, &path);
+
+	if (!path)
+		return;
+
+	if (g_strcmp0(path, "/") == 0)
+		return;
+
+	/* Update the network details based on scan BSS data */
+	network = g_hash_table_lookup(interface->bss_mapping, path);
+	if (network)
+		callback_network_added(network);
+}
+
+static void scan_bss_data(const char *key, DBusMessageIter *iter,
+				void *user_data)
+{
+	GSupplicantInterface *interface = user_data;
+
+	if (iter)
+		supplicant_dbus_array_foreach(iter, scan_network_update,
+						interface);
+
+	if (interface->scan_callback)
+		interface->scan_callback(0, interface, interface->scan_data);
+
+	interface->scan_callback = NULL;
+	interface->scan_data = NULL;
+}
+
+static GSupplicantInterface *interface_alloc(const char *path)
+{
+	GSupplicantInterface *interface;
+
+	interface = g_try_new0(GSupplicantInterface, 1);
+	if (!interface)
+		return NULL;
+
+	interface->path = g_strdup(path);
+
+	interface->network_table = g_hash_table_new_full(g_str_hash,
+					g_str_equal, NULL, remove_network);
+	interface->peer_table = g_hash_table_new_full(g_str_hash,
+					g_str_equal, NULL, remove_peer);
+	interface->group_table = g_hash_table_new_full(g_str_hash,
+					g_str_equal, NULL, remove_group);
+	interface->net_mapping = g_hash_table_new_full(g_str_hash, g_str_equal,
+								NULL, NULL);
+	interface->bss_mapping = g_hash_table_new_full(g_str_hash, g_str_equal,
+								NULL, NULL);
+
+	g_hash_table_replace(interface_table, interface->path, interface);
+
+	return interface;
+}
+
+static void interface_added(DBusMessageIter *iter, void *user_data)
+{
+	GSupplicantInterface *interface;
+	const char *path = NULL;
+
+	SUPPLICANT_DBG("");
+
+	dbus_message_iter_get_basic(iter, &path);
+	if (!path)
+		return;
+
+	if (g_strcmp0(path, "/") == 0)
+		return;
+
+	interface = g_hash_table_lookup(interface_table, path);
+	if (interface)
+		return;
+
+	interface = interface_alloc(path);
+	if (!interface)
+		return;
+
+	dbus_message_iter_next(iter);
+	if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) {
+		supplicant_dbus_property_foreach(iter, interface_property,
+								interface);
+		interface_property(NULL, NULL, interface);
+		return;
+	}
+
+	supplicant_dbus_property_get_all(path,
+					SUPPLICANT_INTERFACE ".Interface",
+					interface_property, interface,
+					interface);
+}
+
+static void interface_removed(DBusMessageIter *iter, void *user_data)
+{
+	const char *path = NULL;
+	GSupplicantInterface *interface = user_data;
+
+	dbus_message_iter_get_basic(iter, &path);
+	if (!path)
+		return;
+
+	interface = g_hash_table_lookup(interface_table, path);
+	g_supplicant_interface_cancel(interface);
+
+	g_hash_table_remove(interface_table, path);
+}
+
+static void eap_method(DBusMessageIter *iter, void *user_data)
+{
+	const char *str = NULL;
+	int i;
+
+	dbus_message_iter_get_basic(iter, &str);
+	if (!str)
+		return;
+
+	for (i = 0; eap_method_map[i].str; i++)
+		if (strcmp(str, eap_method_map[i].str) == 0) {
+			eap_methods |= eap_method_map[i].val;
+			break;
+		}
+}
+
+static void service_property(const char *key, DBusMessageIter *iter,
+							void *user_data)
+{
+	if (!key) {
+		callback_system_ready();
+		return;
+	}
+
+	if (g_strcmp0(key, "DebugLevel") == 0) {
+		const char *str = NULL;
+		int i;
+
+		dbus_message_iter_get_basic(iter, &str);
+		for (i = 0; debug_strings[i]; i++)
+			if (g_strcmp0(debug_strings[i], str) == 0) {
+				debug_level = i;
+				break;
+			}
+		SUPPLICANT_DBG("Debug level %d", debug_level);
+	} else if (g_strcmp0(key, "DebugTimestamp") == 0) {
+		dbus_message_iter_get_basic(iter, &debug_timestamp);
+		SUPPLICANT_DBG("Debug timestamp %u", debug_timestamp);
+	} else if (g_strcmp0(key, "DebugShowKeys") == 0) {
+		dbus_message_iter_get_basic(iter, &debug_showkeys);
+		SUPPLICANT_DBG("Debug show keys %u", debug_showkeys);
+	} else if (g_strcmp0(key, "Interfaces") == 0) {
+		supplicant_dbus_array_foreach(iter, interface_added, NULL);
+	} else if (g_strcmp0(key, "EapMethods") == 0) {
+		supplicant_dbus_array_foreach(iter, eap_method, NULL);
+		debug_strvalmap("EAP method", eap_method_map, eap_methods);
+	} else if (g_strcmp0(key, "Country") == 0) {
+		const char *country = NULL;
+
+		dbus_message_iter_get_basic(iter, &country);
+		SUPPLICANT_DBG("Country %s", country);
+	} else
+		SUPPLICANT_DBG("key %s type %c",
+				key, dbus_message_iter_get_arg_type(iter));
+}
+
+static void signal_name_owner_changed(const char *path, DBusMessageIter *iter)
+{
+	const char *name = NULL, *old = NULL, *new = NULL;
+
+	SUPPLICANT_DBG("");
+
+	if (g_strcmp0(path, DBUS_PATH_DBUS) != 0)
+		return;
+
+	dbus_message_iter_get_basic(iter, &name);
+	if (!name)
+		return;
+
+	if (g_strcmp0(name, SUPPLICANT_SERVICE) != 0)
+		return;
+
+	dbus_message_iter_next(iter);
+	dbus_message_iter_get_basic(iter, &old);
+	dbus_message_iter_next(iter);
+	dbus_message_iter_get_basic(iter, &new);
+
+	if (!old || !new)
+		return;
+
+	if (strlen(old) > 0 && strlen(new) == 0) {
+		system_available = FALSE;
+		g_hash_table_remove_all(bss_mapping);
+		g_hash_table_remove_all(peer_mapping);
+		g_hash_table_remove_all(group_mapping);
+		g_hash_table_remove_all(interface_table);
+		callback_system_killed();
+	}
+
+	if (strlen(new) > 0 && strlen(old) == 0) {
+		system_available = TRUE;
+		supplicant_dbus_property_get_all(SUPPLICANT_PATH,
+						SUPPLICANT_INTERFACE,
+						service_property, NULL, NULL);
+	}
+}
+
+static void signal_properties_changed(const char *path, DBusMessageIter *iter)
+{
+	SUPPLICANT_DBG("");
+
+	if (g_strcmp0(path, SUPPLICANT_PATH) != 0)
+		return;
+
+	supplicant_dbus_property_foreach(iter, service_property, NULL);
+}
+
+static void signal_interface_added(const char *path, DBusMessageIter *iter)
+{
+	SUPPLICANT_DBG("path %s %s", path, SUPPLICANT_PATH);
+
+	if (g_strcmp0(path, SUPPLICANT_PATH) == 0)
+		interface_added(iter, NULL);
+}
+
+static void signal_interface_removed(const char *path, DBusMessageIter *iter)
+{
+	SUPPLICANT_DBG("");
+
+	if (g_strcmp0(path, SUPPLICANT_PATH) == 0)
+		interface_removed(iter, NULL);
+}
+
+static void signal_interface_changed(const char *path, DBusMessageIter *iter)
+{
+	GSupplicantInterface *interface;
+
+	SUPPLICANT_DBG("");
+
+	interface = g_hash_table_lookup(interface_table, path);
+	if (!interface)
+		return;
+
+	supplicant_dbus_property_foreach(iter, interface_property, interface);
+}
+
+static void signal_scan_done(const char *path, DBusMessageIter *iter)
+{
+	GSupplicantInterface *interface;
+	dbus_bool_t success = FALSE;
+
+	SUPPLICANT_DBG("");
+
+	interface = g_hash_table_lookup(interface_table, path);
+	if (!interface)
+		return;
+
+	dbus_message_iter_get_basic(iter, &success);
+
+	if (interface->scanning) {
+		callback_scan_finished(interface);
+		interface->scanning = FALSE;
+	}
+
+	/*
+	 * If scan is unsuccessful return -EIO else get the scanned BSSs
+	 * and update the network details accordingly
+	 */
+	if (!success) {
+		if (interface->scan_callback)
+			interface->scan_callback(-EIO, interface,
+						interface->scan_data);
+
+		interface->scan_callback = NULL;
+		interface->scan_data = NULL;
+
+		return;
+	}
+
+	supplicant_dbus_property_get(path, SUPPLICANT_INTERFACE ".Interface",
+				"BSSs", scan_bss_data, interface, interface);
+}
+
+static void signal_bss_added(const char *path, DBusMessageIter *iter)
+{
+	GSupplicantInterface *interface;
+
+	SUPPLICANT_DBG("");
+
+	interface = g_hash_table_lookup(interface_table, path);
+	if (!interface)
+		return;
+
+	interface_bss_added_with_keys(iter, interface);
+}
+
+static void signal_bss_removed(const char *path, DBusMessageIter *iter)
+{
+	GSupplicantInterface *interface;
+
+	SUPPLICANT_DBG("");
+
+	interface = g_hash_table_lookup(interface_table, path);
+	if (!interface)
+		return;
+
+	interface_bss_removed(iter, interface);
+}
+
+static void signal_network_added(const char *path, DBusMessageIter *iter)
+{
+	GSupplicantInterface *interface;
+
+	SUPPLICANT_DBG("");
+
+	interface = g_hash_table_lookup(interface_table, path);
+	if (!interface)
+		return;
+
+	interface_network_added(iter, interface);
+}
+
+static void signal_network_removed(const char *path, DBusMessageIter *iter)
+{
+	GSupplicantInterface *interface;
+
+	SUPPLICANT_DBG("");
+
+	interface = g_hash_table_lookup(interface_table, path);
+	if (!interface)
+		return;
+
+	interface_network_removed(iter, interface);
+}
+
+static void signal_bss_changed(const char *path, DBusMessageIter *iter)
+{
+	GSupplicantInterface *interface;
+	GSupplicantNetwork *network;
+	GSupplicantSecurity old_security;
+	struct g_supplicant_bss *bss;
+
+	SUPPLICANT_DBG("");
+
+	interface = g_hash_table_lookup(bss_mapping, path);
+	if (!interface)
+		return;
+
+	network = g_hash_table_lookup(interface->bss_mapping, path);
+	if (!network)
+		return;
+
+	bss = g_hash_table_lookup(network->bss_table, path);
+	if (!bss)
+		return;
+
+	supplicant_dbus_property_foreach(iter, bss_property, bss);
+
+	old_security = network->security;
+	bss_compute_security(bss);
+
+	if (old_security != bss->security) {
+		struct g_supplicant_bss *new_bss;
+
+		SUPPLICANT_DBG("New network security for %s", bss->ssid);
+
+		/* Security change policy:
+		 * - we first copy the current bss into a new one with
+		 * its own pointer (path)
+		 * - we remove the current bss related network which will
+		 * tell the plugin about such removal. This is done due
+		 * to the fact that a security change means a group change
+		 * so a complete network change.
+		 * (current bss becomes invalid as well)
+		 * - we add the new bss: it adds new network and tell the
+		 * plugin about it. */
+
+		new_bss = g_try_new0(struct g_supplicant_bss, 1);
+		if (!new_bss)
+			return;
+
+		memcpy(new_bss, bss, sizeof(struct g_supplicant_bss));
+		new_bss->path = g_strdup(bss->path);
+
+		g_hash_table_remove(interface->network_table, network->group);
+
+		add_or_replace_bss_to_network(new_bss);
+
+		return;
+	}
+
+	if (bss->signal == network->signal)
+		return;
+
+	/*
+	 * If the new signal is lower than the SSID signal, we need
+	 * to check for the new maximum.
+	 */
+	if (bss->signal < network->signal) {
+		if (bss != network->best_bss)
+			return;
+		network->signal = bss->signal;
+		update_network_signal(network);
+	} else {
+		network->signal = bss->signal;
+		network->best_bss = bss;
+	}
+
+	SUPPLICANT_DBG("New network signal for %s %d dBm", network->ssid,
+			network->signal);
+
+	callback_network_changed(network, "Signal");
+}
+
+static void wps_credentials(const char *key, DBusMessageIter *iter,
+			void *user_data)
+{
+	GSupplicantInterface *interface = user_data;
+
+	if (!key)
+		return;
+
+	SUPPLICANT_DBG("key %s", key);
+
+	if (g_strcmp0(key, "Key") == 0) {
+		DBusMessageIter array;
+		unsigned char *key_val;
+		int key_len;
+
+		dbus_message_iter_recurse(iter, &array);
+		dbus_message_iter_get_fixed_array(&array, &key_val, &key_len);
+
+		g_free(interface->wps_cred.key);
+		interface->wps_cred.key = g_try_malloc0(
+						sizeof(char) * key_len + 1);
+
+		if (!interface->wps_cred.key)
+			return;
+
+		memcpy(interface->wps_cred.key, key_val,
+						sizeof(char) * key_len);
+
+		SUPPLICANT_DBG("WPS key present");
+	} else if (g_strcmp0(key, "SSID") == 0) {
+		DBusMessageIter array;
+		unsigned char *ssid;
+		int ssid_len;
+
+		dbus_message_iter_recurse(iter, &array);
+		dbus_message_iter_get_fixed_array(&array, &ssid, &ssid_len);
+
+		if (ssid_len > 0 && ssid_len < 33) {
+			memcpy(interface->wps_cred.ssid, ssid, ssid_len);
+			interface->wps_cred.ssid_len = ssid_len;
+		} else {
+			memset(interface->wps_cred.ssid, 0, 32);
+			interface->wps_cred.ssid_len = 0;
+		}
+	}
+}
+
+static void signal_wps_credentials(const char *path, DBusMessageIter *iter)
+{
+	GSupplicantInterface *interface;
+
+	SUPPLICANT_DBG("");
+
+	interface = g_hash_table_lookup(interface_table, path);
+	if (!interface)
+		return;
+
+	supplicant_dbus_property_foreach(iter, wps_credentials, interface);
+}
+
+static void wps_event_args(const char *key, DBusMessageIter *iter,
+			void *user_data)
+{
+	GSupplicantInterface *interface = user_data;
+
+	if (!key || !interface)
+		return;
+
+	SUPPLICANT_DBG("Arg Key %s", key);
+}
+
+static void signal_wps_event(const char *path, DBusMessageIter *iter)
+{
+	GSupplicantInterface *interface;
+	const char *name = NULL;
+
+	SUPPLICANT_DBG("");
+
+	interface = g_hash_table_lookup(interface_table, path);
+	if (!interface)
+		return;
+
+	dbus_message_iter_get_basic(iter, &name);
+
+	SUPPLICANT_DBG("Name: %s", name);
+
+	if (g_strcmp0(name, "success") == 0)
+		interface->wps_state = G_SUPPLICANT_WPS_STATE_SUCCESS;
+	else if (g_strcmp0(name, "fail") == 0)
+		interface->wps_state = G_SUPPLICANT_WPS_STATE_FAIL;
+	else
+		interface->wps_state = G_SUPPLICANT_WPS_STATE_UNKNOWN;
+
+	if (!dbus_message_iter_has_next(iter))
+		return;
+
+	dbus_message_iter_next(iter);
+
+	supplicant_dbus_property_foreach(iter, wps_event_args, interface);
+}
+
+static void create_peer_identifier(GSupplicantPeer *peer)
+{
+	const unsigned char test[ETH_ALEN] = {};
+
+	if (!peer)
+		return;
+
+	if (!memcmp(peer->device_address, test, ETH_ALEN)) {
+		peer->identifier = g_strdup(peer->name);
+		return;
+	}
+
+	peer->identifier = g_malloc0(19);
+	snprintf(peer->identifier, 19, "%02x%02x%02x%02x%02x%02x",
+						peer->device_address[0],
+						peer->device_address[1],
+						peer->device_address[2],
+						peer->device_address[3],
+						peer->device_address[4],
+						peer->device_address[5]);
+}
+
+struct peer_property_data {
+	GSupplicantPeer *peer;
+	GSList *old_groups;
+	bool groups_changed;
+	bool services_changed;
+};
+
+static void peer_groups_relation(DBusMessageIter *iter, void *user_data)
+{
+	struct peer_property_data *data = user_data;
+	GSupplicantPeer *peer = data->peer;
+	GSupplicantGroup *group;
+	const char *str = NULL;
+	GSList *elem;
+
+	dbus_message_iter_get_basic(iter, &str);
+	if (!str)
+		return;
+
+	group = g_hash_table_lookup(group_mapping, str);
+	if (!group)
+		return;
+
+	elem = g_slist_find_custom(data->old_groups, str, (GCompareFunc)g_strcmp0);
+	if (elem) {
+		data->old_groups = g_slist_remove_link(data->old_groups, elem);
+		peer->groups = g_slist_concat(elem, peer->groups);
+	} else {
+		peer->groups = g_slist_prepend(peer->groups, g_strdup(str));
+		data->groups_changed = true;
+	}
+}
+
+static void peer_property(const char *key, DBusMessageIter *iter,
+							void *user_data)
+{
+	GSupplicantPeer *pending_peer;
+	struct peer_property_data *data = user_data;
+	GSupplicantPeer *peer = data->peer;
+
+	SUPPLICANT_DBG("key: %s", key);
+
+	if (!peer->interface)
+		return;
+
+	if (!key) {
+		if (peer->name) {
+			create_peer_identifier(peer);
+			callback_peer_found(peer);
+			pending_peer = g_hash_table_lookup(
+					pending_peer_connection, peer->path);
+
+			if (pending_peer && pending_peer == peer) {
+				callback_peer_request(peer);
+				g_hash_table_remove(pending_peer_connection,
+						peer->path);
+			}
+
+			dbus_free(data);
+		}
+
+		return;
+	}
+
+	if (g_strcmp0(key, "DeviceAddress") == 0) {
+		unsigned char *dev_addr;
+		DBusMessageIter array;
+		int len;
+
+		dbus_message_iter_recurse(iter, &array);
+		dbus_message_iter_get_fixed_array(&array, &dev_addr, &len);
+
+		if (len == ETH_ALEN)
+			memcpy(peer->device_address, dev_addr, len);
+	} else if (g_strcmp0(key, "DeviceName") == 0) {
+		const char *str = NULL;
+
+		dbus_message_iter_get_basic(iter, &str);
+		if (str)
+			peer->name = g_strdup(str);
+	} else if (g_strcmp0(key, "config_method") == 0) {
+		uint16_t wps_config;
+
+		dbus_message_iter_get_basic(iter, &wps_config);
+
+		if (wps_config & G_SUPPLICANT_WPS_CONFIG_PBC)
+			peer->wps_capabilities |= G_SUPPLICANT_WPS_PBC;
+		if (wps_config & ~G_SUPPLICANT_WPS_CONFIG_PBC)
+			peer->wps_capabilities |= G_SUPPLICANT_WPS_PIN;
+	} else if (g_strcmp0(key, "Groups") == 0) {
+		data->old_groups = peer->groups;
+		peer->groups = NULL;
+
+		supplicant_dbus_array_foreach(iter,
+						peer_groups_relation, data);
+		if (g_slist_length(data->old_groups) > 0) {
+			g_slist_free_full(data->old_groups, g_free);
+			data->groups_changed = true;
+		}
+	} else if (g_strcmp0(key, "IEs") == 0) {
+		DBusMessageIter array;
+		unsigned char *ie;
+		int ie_len;
+
+		dbus_message_iter_recurse(iter, &array);
+		dbus_message_iter_get_fixed_array(&array, &ie, &ie_len);
+
+		if (!ie || ie_len < 2)
+			return;
+
+		if (peer->widi_ies) {
+			if (memcmp(peer->widi_ies, ie, ie_len) == 0)
+				return;
+
+			g_free(peer->widi_ies);
+			peer->widi_ies_length = 0;
+		}
+
+		peer->widi_ies = g_malloc0(ie_len * sizeof(unsigned char));
+
+		memcpy(peer->widi_ies, ie, ie_len);
+		peer->widi_ies_length = ie_len;
+		data->services_changed = true;
+	}
+}
+
+static void signal_peer_found(const char *path, DBusMessageIter *iter)
+{
+	struct peer_property_data *property_data;
+	GSupplicantInterface *interface;
+	const char *obj_path = NULL;
+	GSupplicantPeer *peer;
+
+	SUPPLICANT_DBG("");
+
+	interface = g_hash_table_lookup(interface_table, path);
+	if (!interface)
+		return;
+
+	dbus_message_iter_get_basic(iter, &obj_path);
+	if (!obj_path || g_strcmp0(obj_path, "/") == 0)
+		return;
+
+	peer = g_hash_table_lookup(interface->peer_table, obj_path);
+	if (peer)
+		return;
+
+	peer = g_try_new0(GSupplicantPeer, 1);
+	if (!peer)
+		return;
+
+	peer->interface = interface;
+	peer->path = g_strdup(obj_path);
+	g_hash_table_insert(interface->peer_table, peer->path, peer);
+	g_hash_table_replace(peer_mapping, peer->path, interface);
+
+	property_data = dbus_malloc0(sizeof(struct peer_property_data));
+	property_data->peer = peer;
+
+	dbus_message_iter_next(iter);
+	if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) {
+		supplicant_dbus_property_foreach(iter, peer_property,
+							property_data);
+		peer_property(NULL, NULL, property_data);
+		return;
+	}
+
+	supplicant_dbus_property_get_all(obj_path,
+					SUPPLICANT_INTERFACE ".Peer",
+					peer_property, property_data, NULL);
+}
+
+static void signal_peer_lost(const char *path, DBusMessageIter *iter)
+{
+	GSupplicantInterface *interface;
+	const char *obj_path = NULL;
+	GSupplicantPeer *peer;
+
+	SUPPLICANT_DBG("");
+
+	interface = g_hash_table_lookup(interface_table, path);
+	if (!interface)
+		return;
+
+	dbus_message_iter_get_basic(iter, &obj_path);
+	if (!obj_path || g_strcmp0(obj_path, "/") == 0)
+		return;
+
+	peer = g_hash_table_lookup(interface->peer_table, obj_path);
+	if (!peer)
+		return;
+
+	g_hash_table_remove(interface->peer_table, obj_path);
+}
+
+static void signal_peer_changed(const char *path, DBusMessageIter *iter)
+{
+	struct peer_property_data *property_data;
+	GSupplicantInterface *interface;
+	GSupplicantPeer *peer;
+
+	SUPPLICANT_DBG("");
+
+	interface = g_hash_table_lookup(peer_mapping, path);
+	if (!interface)
+		return;
+
+	peer = g_hash_table_lookup(interface->peer_table, path);
+	if (!peer) {
+		g_hash_table_remove(peer_mapping, path);
+		return;
+	}
+
+	property_data = dbus_malloc0(sizeof(struct peer_property_data));
+	property_data->peer = peer;
+
+	supplicant_dbus_property_foreach(iter, peer_property, property_data);
+	if (property_data->services_changed)
+		callback_peer_changed(peer,
+					G_SUPPLICANT_PEER_SERVICES_CHANGED);
+
+	if (property_data->groups_changed)
+		callback_peer_changed(peer, G_SUPPLICANT_PEER_GROUP_CHANGED);
+
+	dbus_free(property_data);
+
+	if (!g_supplicant_peer_is_in_a_group(peer))
+		peer->connection_requested = false;
+}
+
+struct group_sig_data {
+	const char *peer_obj_path;
+	unsigned char iface_address[ETH_ALEN];
+	const char *interface_obj_path;
+	const char *group_obj_path;
+	int role;
+};
+
+static void group_sig_property(const char *key, DBusMessageIter *iter,
+							void *user_data)
+{
+	struct group_sig_data *data = user_data;
+
+	if (!key)
+		return;
+
+	if (g_strcmp0(key, "peer_interface_addr") == 0) {
+		unsigned char *dev_addr;
+		DBusMessageIter array;
+		int len;
+
+		dbus_message_iter_recurse(iter, &array);
+		dbus_message_iter_get_fixed_array(&array, &dev_addr, &len);
+
+		if (len == ETH_ALEN)
+			memcpy(data->iface_address, dev_addr, len);
+	} else if (g_strcmp0(key, "role") == 0) {
+		const char *str = NULL;
+
+		dbus_message_iter_get_basic(iter, &str);
+		if (g_strcmp0(str, "GO") == 0)
+			data->role = G_SUPPLICANT_GROUP_ROLE_GO;
+		else
+			data->role = G_SUPPLICANT_GROUP_ROLE_CLIENT;
+	} else if (g_strcmp0(key, "peer_object") == 0)
+		dbus_message_iter_get_basic(iter, &data->peer_obj_path);
+	else if (g_strcmp0(key, "interface_object") == 0)
+		dbus_message_iter_get_basic(iter, &data->interface_obj_path);
+	else if (g_strcmp0(key, "group_object") == 0)
+		dbus_message_iter_get_basic(iter, &data->group_obj_path);
+
+}
+
+static void signal_group_success(const char *path, DBusMessageIter *iter)
+{
+	GSupplicantInterface *interface;
+	struct group_sig_data data = {};
+	GSupplicantPeer *peer;
+
+	SUPPLICANT_DBG("");
+
+	interface = g_hash_table_lookup(interface_table, path);
+	if (!interface)
+		return;
+
+	supplicant_dbus_property_foreach(iter, group_sig_property, &data);
+	if (!data.peer_obj_path)
+		return;
+
+	peer = g_hash_table_lookup(interface->peer_table, data.peer_obj_path);
+	if (!peer)
+		return;
+
+	memcpy(peer->iface_address, data.iface_address, ETH_ALEN);
+	interface->pending_peer_path = peer->path;
+}
+
+static void signal_group_failure(const char *path, DBusMessageIter *iter)
+{
+	GSupplicantInterface *interface;
+	struct group_sig_data data = {};
+	GSupplicantPeer *peer;
+
+	SUPPLICANT_DBG("");
+
+	interface = g_hash_table_lookup(interface_table, path);
+	if (!interface)
+		return;
+
+	supplicant_dbus_property_foreach(iter, group_sig_property, &data);
+	if (!data.peer_obj_path)
+		return;
+
+	peer = g_hash_table_lookup(interface->peer_table, data.peer_obj_path);
+	if (!peer)
+		return;
+
+	callback_peer_changed(peer, G_SUPPLICANT_PEER_GROUP_FAILED);
+	peer->connection_requested = false;
+}
+
+static void signal_group_started(const char *path, DBusMessageIter *iter)
+{
+	GSupplicantInterface *interface, *g_interface;
+	struct group_sig_data data = {};
+	GSupplicantGroup *group;
+	GSupplicantPeer *peer;
+
+	SUPPLICANT_DBG("");
+
+	interface = g_hash_table_lookup(interface_table, path);
+	if (!interface)
+		return;
+
+	supplicant_dbus_property_foreach(iter, group_sig_property, &data);
+	if (!data.interface_obj_path || !data.group_obj_path)
+		return;
+
+	peer = g_hash_table_lookup(interface->peer_table,
+						interface->pending_peer_path);
+	interface->pending_peer_path = NULL;
+	if (!peer)
+		return;
+
+	g_interface = g_hash_table_lookup(interface_table,
+						data.interface_obj_path);
+	if (!g_interface)
+		return;
+
+	group = g_hash_table_lookup(interface->group_table,
+						data.group_obj_path);
+	if (group)
+		return;
+
+	group = g_try_new0(GSupplicantGroup, 1);
+	if (!group)
+		return;
+
+	group->interface = g_interface;
+	group->orig_interface = interface;
+	group->path = g_strdup(data.group_obj_path);
+	group->role = data.role;
+
+	g_hash_table_insert(interface->group_table, group->path, group);
+	g_hash_table_replace(group_mapping, group->path, group);
+
+	peer->current_group_iface = g_interface;
+	callback_peer_changed(peer, G_SUPPLICANT_PEER_GROUP_STARTED);
+}
+
+static void remove_peer_group_interface(GHashTable *group_table,
+				const char* path)
+{
+	GSupplicantGroup *group;
+	GHashTableIter iter;
+	gpointer value, key;
+
+	if (!group_table)
+		return;
+
+	group = g_hash_table_lookup(group_table, path);
+
+	if (!group || !group->orig_interface)
+		return;
+
+	g_hash_table_iter_init(&iter, group->orig_interface->peer_table);
+
+	while (g_hash_table_iter_next(&iter, &key, &value)) {
+		GSupplicantPeer *peer = value;
+
+		if (peer->current_group_iface == group->interface)
+			peer->current_group_iface = NULL;
+	}
+}
+
+static void signal_group_finished(const char *path, DBusMessageIter *iter)
+{
+	GSupplicantInterface *interface;
+	struct group_sig_data data = {};
+
+	SUPPLICANT_DBG("");
+
+	interface = g_hash_table_lookup(interface_table, path);
+	if (!interface)
+		return;
+
+	supplicant_dbus_property_foreach(iter, group_sig_property, &data);
+	if (!data.interface_obj_path || !data.group_obj_path)
+		return;
+
+	remove_peer_group_interface(interface->group_table, data.group_obj_path);
+
+	g_hash_table_remove(group_mapping, data.group_obj_path);
+
+	g_hash_table_remove(interface->group_table, data.group_obj_path);
+}
+
+static void signal_group_request(const char *path, DBusMessageIter *iter)
+{
+	GSupplicantInterface *interface;
+	GSupplicantPeer *peer;
+	const char *obj_path;
+
+	SUPPLICANT_DBG("");
+
+	interface = g_hash_table_lookup(interface_table, path);
+	if (!interface)
+		return;
+
+	dbus_message_iter_get_basic(iter, &obj_path);
+	if (!obj_path || !g_strcmp0(obj_path, "/"))
+		return;
+
+	peer = g_hash_table_lookup(interface->peer_table, obj_path);
+	if (!peer)
+		return;
+
+	/*
+	 * Peer has been previously found and property set,
+	 * otherwise, defer connection to when peer property
+	 * is set.
+	 */
+	if (peer->identifier)
+		callback_peer_request(peer);
+	else
+		g_hash_table_replace(pending_peer_connection, peer->path, peer);
+}
+
+static void signal_group_peer_joined(const char *path, DBusMessageIter *iter)
+{
+	const char *peer_path = NULL;
+	GSupplicantInterface *interface;
+	GSupplicantGroup *group;
+	GSupplicantPeer *peer;
+
+	SUPPLICANT_DBG("");
+
+	group = g_hash_table_lookup(group_mapping, path);
+	if (!group)
+		return;
+
+	dbus_message_iter_get_basic(iter, &peer_path);
+	if (!peer_path)
+		return;
+
+	interface = g_hash_table_lookup(peer_mapping, peer_path);
+	if (!interface)
+		return;
+
+	peer = g_hash_table_lookup(interface->peer_table, peer_path);
+	if (!peer)
+		return;
+
+	group->members = g_slist_prepend(group->members, g_strdup(peer_path));
+
+	callback_peer_changed(peer, G_SUPPLICANT_PEER_GROUP_JOINED);
+}
+
+static void signal_group_peer_disconnected(const char *path, DBusMessageIter *iter)
+{
+	const char *peer_path = NULL;
+	GSupplicantInterface *interface;
+	GSupplicantGroup *group;
+	GSupplicantPeer *peer;
+	GSList *elem;
+
+	SUPPLICANT_DBG("");
+
+	group = g_hash_table_lookup(group_mapping, path);
+	if (!group)
+		return;
+
+	dbus_message_iter_get_basic(iter, &peer_path);
+	if (!peer_path)
+		return;
+
+	for (elem = group->members; elem; elem = elem->next) {
+		if (!g_strcmp0(elem->data, peer_path))
+			break;
+	}
+
+	if (!elem)
+		return;
+
+	g_free(elem->data);
+	group->members = g_slist_delete_link(group->members, elem);
+
+	interface = g_hash_table_lookup(peer_mapping, peer_path);
+	if (!interface)
+		return;
+
+	peer = g_hash_table_lookup(interface->peer_table, peer_path);
+	if (!peer)
+		return;
+
+	callback_peer_changed(peer, G_SUPPLICANT_PEER_GROUP_DISCONNECTED);
+	peer->connection_requested = false;
+}
+
+static struct {
+	const char *interface;
+	const char *member;
+	void (*function) (const char *path, DBusMessageIter *iter);
+} signal_map[] = {
+	{ DBUS_INTERFACE_DBUS,  "NameOwnerChanged",  signal_name_owner_changed },
+
+	{ SUPPLICANT_INTERFACE, "PropertiesChanged", signal_properties_changed },
+	{ SUPPLICANT_INTERFACE, "InterfaceAdded",    signal_interface_added    },
+	{ SUPPLICANT_INTERFACE, "InterfaceCreated",  signal_interface_added    },
+	{ SUPPLICANT_INTERFACE, "InterfaceRemoved",  signal_interface_removed  },
+
+	{ SUPPLICANT_INTERFACE ".Interface", "PropertiesChanged", signal_interface_changed },
+	{ SUPPLICANT_INTERFACE ".Interface", "ScanDone",          signal_scan_done         },
+	{ SUPPLICANT_INTERFACE ".Interface", "BSSAdded",          signal_bss_added         },
+	{ SUPPLICANT_INTERFACE ".Interface", "BSSRemoved",        signal_bss_removed       },
+	{ SUPPLICANT_INTERFACE ".Interface", "NetworkAdded",      signal_network_added     },
+	{ SUPPLICANT_INTERFACE ".Interface", "NetworkRemoved",    signal_network_removed   },
+
+	{ SUPPLICANT_INTERFACE ".BSS", "PropertiesChanged", signal_bss_changed   },
+
+	{ SUPPLICANT_INTERFACE ".Interface.WPS", "Credentials", signal_wps_credentials },
+	{ SUPPLICANT_INTERFACE ".Interface.WPS", "Event",       signal_wps_event       },
+
+	{ SUPPLICANT_INTERFACE ".Interface.P2PDevice", "DeviceFound", signal_peer_found },
+	{ SUPPLICANT_INTERFACE ".Interface.P2PDevice", "DeviceLost",  signal_peer_lost  },
+
+	{ SUPPLICANT_INTERFACE ".Peer", "PropertiesChanged", signal_peer_changed },
+
+	{ SUPPLICANT_INTERFACE ".Interface.P2PDevice", "GONegotiationSuccess", signal_group_success },
+	{ SUPPLICANT_INTERFACE ".Interface.P2PDevice", "GONegotiationFailure", signal_group_failure },
+	{ SUPPLICANT_INTERFACE ".Interface.P2PDevice", "GroupStarted", signal_group_started },
+	{ SUPPLICANT_INTERFACE ".Interface.P2PDevice", "GroupFinished", signal_group_finished },
+	{ SUPPLICANT_INTERFACE ".Interface.P2PDevice", "GONegotiationRequest", signal_group_request },
+
+	{ SUPPLICANT_INTERFACE ".Group", "PeerJoined", signal_group_peer_joined },
+	{ SUPPLICANT_INTERFACE ".Group", "PeerDisconnected", signal_group_peer_disconnected },
+
+	{ }
+};
+
+static DBusHandlerResult g_supplicant_filter(DBusConnection *conn,
+					DBusMessage *message, void *data)
+{
+	DBusMessageIter iter;
+	const char *path;
+	int i;
+
+	path = dbus_message_get_path(message);
+	if (!path)
+		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+	if (!dbus_message_iter_init(message, &iter))
+		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+	for (i = 0; signal_map[i].interface; i++) {
+		if (!dbus_message_has_interface(message, signal_map[i].interface))
+			continue;
+
+		if (!dbus_message_has_member(message, signal_map[i].member))
+			continue;
+
+		signal_map[i].function(path, &iter);
+		break;
+	}
+
+	return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+
+void g_supplicant_interface_cancel(GSupplicantInterface *interface)
+{
+	SUPPLICANT_DBG("Cancelling any pending DBus calls");
+	supplicant_dbus_method_call_cancel_all(interface);
+	supplicant_dbus_property_call_cancel_all(interface);
+}
+
+struct supplicant_regdom {
+	GSupplicantCountryCallback callback;
+	const char *alpha2;
+	const void *user_data;
+};
+
+static void country_result(const char *error,
+				DBusMessageIter *iter, void *user_data)
+{
+	struct supplicant_regdom *regdom = user_data;
+	int result = 0;
+
+	SUPPLICANT_DBG("Country setting result");
+
+	if (!user_data)
+		return;
+
+	if (error) {
+		SUPPLICANT_DBG("Country setting failure %s", error);
+		result = -EINVAL;
+	}
+
+	if (regdom->callback)
+		regdom->callback(result, regdom->alpha2,
+					(void *) regdom->user_data);
+
+	g_free(regdom);
+}
+
+static void country_params(DBusMessageIter *iter, void *user_data)
+{
+	struct supplicant_regdom *regdom = user_data;
+
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING,
+							&regdom->alpha2);
+}
+
+int g_supplicant_set_country(const char *alpha2,
+				GSupplicantCountryCallback callback,
+					const void *user_data)
+{
+	struct supplicant_regdom *regdom;
+
+	SUPPLICANT_DBG("Country setting %s", alpha2);
+
+	if (!system_available)
+		return -EFAULT;
+
+	regdom = dbus_malloc0(sizeof(*regdom));
+	if (!regdom)
+		return -ENOMEM;
+
+	regdom->callback = callback;
+	regdom->alpha2 = alpha2;
+	regdom->user_data = user_data;
+
+	return supplicant_dbus_property_set(SUPPLICANT_PATH, SUPPLICANT_INTERFACE,
+					"Country", DBUS_TYPE_STRING_AS_STRING,
+					country_params, country_result,
+					regdom, NULL);
+}
+
+int g_supplicant_interface_set_country(GSupplicantInterface *interface,
+					GSupplicantCountryCallback callback,
+							const char *alpha2,
+							void *user_data)
+{
+	struct supplicant_regdom *regdom;
+
+	regdom = dbus_malloc0(sizeof(*regdom));
+	if (!regdom)
+		return -ENOMEM;
+
+	regdom->callback = callback;
+	regdom->alpha2 = alpha2;
+	regdom->user_data = user_data;
+
+	return supplicant_dbus_property_set(interface->path,
+				SUPPLICANT_INTERFACE ".Interface",
+				"Country", DBUS_TYPE_STRING_AS_STRING,
+				country_params, country_result,
+					regdom, NULL);
+}
+
+bool g_supplicant_interface_has_p2p(GSupplicantInterface *interface)
+{
+	if (!interface)
+		return false;
+
+	return interface->p2p_support;
+}
+
+struct supplicant_p2p_dev_config {
+	char *device_name;
+	char *dev_type;
+};
+
+static void p2p_device_config_result(const char *error,
+					DBusMessageIter *iter, void *user_data)
+{
+	struct supplicant_p2p_dev_config *config = user_data;
+
+	if (error)
+		SUPPLICANT_DBG("Unable to set P2P Device configuration: %s",
+									error);
+
+	g_free(config->device_name);
+	g_free(config->dev_type);
+	dbus_free(config);
+}
+
+static int dev_type_str2bin(const char *type, unsigned char dev_type[8])
+{
+	int length, pos, end;
+	char b[3] = {};
+	char *e = NULL;
+
+	end = strlen(type);
+	for (length = pos = 0; type[pos] != '\0' && length < 8; length++) {
+		if (pos+2 > end)
+			return 0;
+
+		b[0] = type[pos];
+		b[1] = type[pos+1];
+
+		dev_type[length] = strtol(b, &e, 16);
+		if (e && *e != '\0')
+			return 0;
+
+		pos += 2;
+	}
+
+	return 8;
+}
+
+static void p2p_device_config_params(DBusMessageIter *iter, void *user_data)
+{
+	struct supplicant_p2p_dev_config *config = user_data;
+	DBusMessageIter dict;
+
+	supplicant_dbus_dict_open(iter, &dict);
+
+	supplicant_dbus_dict_append_basic(&dict, "DeviceName",
+				DBUS_TYPE_STRING, &config->device_name);
+
+	if (config->dev_type) {
+		unsigned char dev_type[8] = {}, *type;
+		int len;
+
+		len = dev_type_str2bin(config->dev_type, dev_type);
+		if (len) {
+			type = dev_type;
+			supplicant_dbus_dict_append_fixed_array(&dict,
+					"PrimaryDeviceType",
+					DBUS_TYPE_BYTE, &type, len);
+		}
+	}
+
+	supplicant_dbus_dict_close(iter, &dict);
+}
+
+int g_supplicant_interface_set_p2p_device_config(GSupplicantInterface *interface,
+					const char *device_name,
+					const char *primary_dev_type)
+{
+	struct supplicant_p2p_dev_config *config;
+	int ret;
+
+	SUPPLICANT_DBG("P2P Device settings %s/%s",
+					device_name, primary_dev_type);
+
+	config = dbus_malloc0(sizeof(*config));
+	if (!config)
+		return -ENOMEM;
+
+	config->device_name = g_strdup(device_name);
+	config->dev_type = g_strdup(primary_dev_type);
+
+	ret = supplicant_dbus_property_set(interface->path,
+				SUPPLICANT_INTERFACE ".Interface.P2PDevice",
+				"P2PDeviceConfig",
+				DBUS_TYPE_ARRAY_AS_STRING
+				DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+				DBUS_TYPE_STRING_AS_STRING
+				DBUS_TYPE_VARIANT_AS_STRING
+				DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
+				p2p_device_config_params,
+				p2p_device_config_result, config, NULL);
+	if (ret < 0) {
+		g_free(config->device_name);
+		g_free(config->dev_type);
+		dbus_free(config);
+		SUPPLICANT_DBG("Unable to set P2P Device configuration");
+	}
+
+	return ret;
+}
+
+static gboolean peer_lookup_by_identifier(gpointer key, gpointer value,
+							gpointer user_data)
+{
+	const GSupplicantPeer *peer = value;
+	const char *identifier = user_data;
+
+	if (!g_strcmp0(identifier, peer->identifier))
+		return TRUE;
+
+	return FALSE;
+}
+
+GSupplicantPeer *g_supplicant_interface_peer_lookup(GSupplicantInterface *interface,
+							const char *identifier)
+{
+	GSupplicantPeer *peer;
+
+	peer = g_hash_table_find(interface->peer_table,
+					peer_lookup_by_identifier,
+					(void *) identifier);
+	return peer;
+}
+
+static void interface_create_data_free(struct interface_create_data *data)
+{
+	g_free(data->ifname);
+	g_free(data->driver);
+	g_free(data->bridge);
+	dbus_free(data);
+}
+
+static bool interface_exists(GSupplicantInterface *interface,
+				const char *path)
+{
+	GSupplicantInterface *tmp;
+
+	tmp = g_hash_table_lookup(interface_table, path);
+	if (tmp && tmp == interface)
+		return true;
+
+	return false;
+}
+
+static void interface_create_property(const char *key, DBusMessageIter *iter,
+							void *user_data)
+{
+	struct interface_create_data *data = user_data;
+	GSupplicantInterface *interface = data->interface;
+
+	if (!key) {
+		if (data->callback) {
+			data->callback(0, data->interface, data->user_data);
+			callback_p2p_support(interface);
+		}
+
+		interface_create_data_free(data);
+	}
+
+	interface_property(key, iter, interface);
+}
+
+static void interface_create_result(const char *error,
+				DBusMessageIter *iter, void *user_data)
+{
+	struct interface_create_data *data = user_data;
+	const char *path = NULL;
+	int err;
+
+	SUPPLICANT_DBG("");
+
+	if (error) {
+		g_warning("error %s", error);
+		err = -EIO;
+		goto done;
+	}
+
+	dbus_message_iter_get_basic(iter, &path);
+	if (!path) {
+		err = -EINVAL;
+		goto done;
+	}
+
+	if (!system_available) {
+		err = -EFAULT;
+		goto done;
+	}
+
+	data->interface = g_hash_table_lookup(interface_table, path);
+	if (!data->interface) {
+		data->interface = interface_alloc(path);
+		if (!data->interface) {
+			err = -ENOMEM;
+			goto done;
+		}
+	}
+
+	err = supplicant_dbus_property_get_all(path,
+					SUPPLICANT_INTERFACE ".Interface",
+					interface_create_property, data,
+					NULL);
+	if (err == 0)
+		return;
+
+done:
+	if (data->callback)
+		data->callback(err, NULL, data->user_data);
+
+	interface_create_data_free(data);
+}
+
+static void interface_create_params(DBusMessageIter *iter, void *user_data)
+{
+	struct interface_create_data *data = user_data;
+	DBusMessageIter dict;
+
+	SUPPLICANT_DBG("");
+
+	supplicant_dbus_dict_open(iter, &dict);
+
+	supplicant_dbus_dict_append_basic(&dict, "Ifname",
+					DBUS_TYPE_STRING, &data->ifname);
+
+	if (data->driver)
+		supplicant_dbus_dict_append_basic(&dict, "Driver",
+					DBUS_TYPE_STRING, &data->driver);
+
+	if (data->bridge)
+		supplicant_dbus_dict_append_basic(&dict, "BridgeIfname",
+					DBUS_TYPE_STRING, &data->bridge);
+
+	supplicant_dbus_dict_close(iter, &dict);
+}
+
+static void interface_get_result(const char *error,
+				DBusMessageIter *iter, void *user_data)
+{
+	struct interface_create_data *data = user_data;
+	GSupplicantInterface *interface;
+	const char *path = NULL;
+	int err;
+
+	SUPPLICANT_DBG("");
+
+	if (error) {
+		SUPPLICANT_DBG("Interface not created yet");
+		goto create;
+	}
+
+	dbus_message_iter_get_basic(iter, &path);
+	if (!path) {
+		err = -EINVAL;
+		goto done;
+	}
+
+	interface = g_hash_table_lookup(interface_table, path);
+	if (!interface) {
+		err = -ENOENT;
+		goto done;
+	}
+
+	if (data->callback) {
+		data->callback(0, interface, data->user_data);
+		callback_p2p_support(interface);
+	}
+
+	interface_create_data_free(data);
+
+	return;
+
+create:
+	if (!system_available) {
+		err = -EFAULT;
+		goto done;
+	}
+
+	SUPPLICANT_DBG("Creating interface");
+
+	err = supplicant_dbus_method_call(SUPPLICANT_PATH,
+						SUPPLICANT_INTERFACE,
+						"CreateInterface",
+						interface_create_params,
+						interface_create_result, data,
+						NULL);
+	if (err == 0)
+		return;
+
+done:
+	if (data->callback)
+		data->callback(err, NULL, data->user_data);
+
+	interface_create_data_free(data);
+}
+
+static void interface_get_params(DBusMessageIter *iter, void *user_data)
+{
+	struct interface_create_data *data = user_data;
+
+	SUPPLICANT_DBG("");
+
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &data->ifname);
+}
+
+int g_supplicant_interface_create(const char *ifname, const char *driver,
+					const char *bridge,
+					GSupplicantInterfaceCallback callback,
+							void *user_data)
+{
+	struct interface_create_data *data;
+	int ret;
+
+	SUPPLICANT_DBG("ifname %s", ifname);
+
+	if (!ifname)
+		return -EINVAL;
+
+	if (!system_available)
+		return -EFAULT;
+
+	data = dbus_malloc0(sizeof(*data));
+	if (!data)
+		return -ENOMEM;
+
+	data->ifname = g_strdup(ifname);
+	data->driver = g_strdup(driver);
+	data->bridge = g_strdup(bridge);
+	data->callback = callback;
+	data->user_data = user_data;
+
+	ret = supplicant_dbus_method_call(SUPPLICANT_PATH,
+						SUPPLICANT_INTERFACE,
+						"GetInterface",
+						interface_get_params,
+						interface_get_result, data,
+						NULL);
+	if (ret < 0)
+		interface_create_data_free(data);
+
+	return ret;
+}
+
+static void interface_remove_result(const char *error,
+				DBusMessageIter *iter, void *user_data)
+{
+	struct interface_data *data = user_data;
+	int err;
+
+	if (error) {
+		err = -EIO;
+		goto done;
+	}
+
+	if (!system_available) {
+		err = -EFAULT;
+		goto done;
+	}
+
+	/*
+	 * The gsupplicant interface is already freed by the InterfaceRemoved
+	 * signal callback. Simply invoke the interface_data callback.
+	 */
+	err = 0;
+
+done:
+	g_free(data->path);
+
+	if (data->callback)
+		data->callback(err, NULL, data->user_data);
+
+	dbus_free(data);
+}
+
+
+static void interface_remove_params(DBusMessageIter *iter, void *user_data)
+{
+	struct interface_data *data = user_data;
+
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH,
+							&data->interface->path);
+}
+
+
+int g_supplicant_interface_remove(GSupplicantInterface *interface,
+			GSupplicantInterfaceCallback callback,
+							void *user_data)
+{
+	struct interface_data *data;
+	int ret;
+
+	if (!interface)
+		return -EINVAL;
+
+	if (!system_available)
+		return -EFAULT;
+
+	g_supplicant_interface_cancel(interface);
+
+	data = dbus_malloc0(sizeof(*data));
+	if (!data)
+		return -ENOMEM;
+
+	data->interface = interface;
+	data->path = g_strdup(interface->path);
+	data->callback = callback;
+	data->user_data = user_data;
+
+	ret = supplicant_dbus_method_call(SUPPLICANT_PATH,
+						SUPPLICANT_INTERFACE,
+						"RemoveInterface",
+						interface_remove_params,
+						interface_remove_result, data,
+						NULL);
+	if (ret < 0) {
+		g_free(data->path);
+		dbus_free(data);
+	}
+	return ret;
+}
+
+static void interface_scan_result(const char *error,
+				DBusMessageIter *iter, void *user_data)
+{
+	struct interface_scan_data *data = user_data;
+	int err = 0;
+
+	if (error) {
+		SUPPLICANT_DBG("error %s", error);
+		err = -EIO;
+	}
+
+	/* A non ready interface cannot send/receive anything */
+	if (interface_exists(data->interface, data->path)) {
+		if (!data->interface->ready)
+			err = -ENOLINK;
+	}
+
+	g_free(data->path);
+
+	if (err != 0) {
+		if (data->callback)
+			data->callback(err, data->interface, data->user_data);
+	} else {
+		data->interface->scan_callback = data->callback;
+		data->interface->scan_data = data->user_data;
+	}
+
+	if (data->scan_params)
+		g_supplicant_free_scan_params(data->scan_params);
+
+	dbus_free(data);
+}
+
+static void add_scan_frequency(DBusMessageIter *iter, unsigned int freq)
+{
+	DBusMessageIter data;
+	unsigned int width = 0; /* Not used by wpa_supplicant atm */
+
+	dbus_message_iter_open_container(iter, DBUS_TYPE_STRUCT, NULL, &data);
+
+	dbus_message_iter_append_basic(&data, DBUS_TYPE_UINT32, &freq);
+	dbus_message_iter_append_basic(&data, DBUS_TYPE_UINT32, &width);
+
+	dbus_message_iter_close_container(iter, &data);
+}
+
+static void add_scan_frequencies(DBusMessageIter *iter,
+						void *user_data)
+{
+	GSupplicantScanParams *scan_data = user_data;
+	unsigned int freq;
+	int i;
+
+	for (i = 0; i < scan_data->num_freqs; i++) {
+		freq = scan_data->freqs[i];
+		if (!freq)
+			break;
+
+		add_scan_frequency(iter, freq);
+	}
+}
+
+static void append_ssid(DBusMessageIter *iter,
+			const void *ssid, unsigned int len)
+{
+	DBusMessageIter array;
+
+	dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY,
+	DBUS_TYPE_BYTE_AS_STRING, &array);
+
+	dbus_message_iter_append_fixed_array(&array, DBUS_TYPE_BYTE,
+								&ssid, len);
+	dbus_message_iter_close_container(iter, &array);
+}
+
+static void append_ssids(DBusMessageIter *iter, void *user_data)
+{
+	GSupplicantScanParams *scan_data = user_data;
+	GSList *list;
+
+	for (list = scan_data->ssids; list; list = list->next) {
+		struct scan_ssid *scan_ssid = list->data;
+
+		append_ssid(iter, scan_ssid->ssid, scan_ssid->ssid_len);
+	}
+}
+
+static void supplicant_add_scan_frequency(DBusMessageIter *dict,
+		supplicant_dbus_array_function function,
+					void *user_data)
+{
+	GSupplicantScanParams *scan_params = user_data;
+	DBusMessageIter entry, value, array;
+	const char *key = "Channels";
+
+	if (scan_params->freqs && scan_params->freqs[0] != 0) {
+		dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
+						NULL, &entry);
+
+		dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
+
+		dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT,
+					DBUS_TYPE_ARRAY_AS_STRING
+					DBUS_STRUCT_BEGIN_CHAR_AS_STRING
+					DBUS_TYPE_UINT32_AS_STRING
+					DBUS_TYPE_UINT32_AS_STRING
+					DBUS_STRUCT_END_CHAR_AS_STRING,
+					&value);
+
+		dbus_message_iter_open_container(&value, DBUS_TYPE_ARRAY,
+					DBUS_STRUCT_BEGIN_CHAR_AS_STRING
+					DBUS_TYPE_UINT32_AS_STRING
+					DBUS_TYPE_UINT32_AS_STRING
+					DBUS_STRUCT_END_CHAR_AS_STRING,
+					&array);
+
+		if (function)
+			function(&array, user_data);
+
+		dbus_message_iter_close_container(&value, &array);
+		dbus_message_iter_close_container(&entry, &value);
+		dbus_message_iter_close_container(dict, &entry);
+	}
+}
+
+static void interface_scan_params(DBusMessageIter *iter, void *user_data)
+{
+	DBusMessageIter dict;
+	const char *type = "passive";
+	struct interface_scan_data *data = user_data;
+
+	supplicant_dbus_dict_open(iter, &dict);
+
+	if (data && data->scan_params) {
+		type = "active";
+
+		supplicant_dbus_dict_append_basic(&dict, "Type",
+					DBUS_TYPE_STRING, &type);
+
+		supplicant_dbus_dict_append_array(&dict, "SSIDs",
+						DBUS_TYPE_STRING,
+						append_ssids,
+						data->scan_params);
+
+		supplicant_add_scan_frequency(&dict, add_scan_frequencies,
+						data->scan_params);
+	} else
+		supplicant_dbus_dict_append_basic(&dict, "Type",
+					DBUS_TYPE_STRING, &type);
+
+	supplicant_dbus_dict_close(iter, &dict);
+}
+
+static int interface_ready_to_scan(GSupplicantInterface *interface)
+{
+	if (!interface)
+		return -EINVAL;
+
+	if (!system_available)
+		return -EFAULT;
+
+	if (interface->scanning)
+		return -EALREADY;
+
+	switch (interface->state) {
+	case G_SUPPLICANT_STATE_AUTHENTICATING:
+	case G_SUPPLICANT_STATE_ASSOCIATING:
+	case G_SUPPLICANT_STATE_ASSOCIATED:
+	case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
+	case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
+		return -EBUSY;
+	case G_SUPPLICANT_STATE_UNKNOWN:
+	case G_SUPPLICANT_STATE_DISABLED:
+	case G_SUPPLICANT_STATE_DISCONNECTED:
+	case G_SUPPLICANT_STATE_INACTIVE:
+	case G_SUPPLICANT_STATE_SCANNING:
+	case G_SUPPLICANT_STATE_COMPLETED:
+		break;
+	}
+
+	return 0;
+}
+
+int g_supplicant_interface_scan(GSupplicantInterface *interface,
+				GSupplicantScanParams *scan_data,
+				GSupplicantInterfaceCallback callback,
+							void *user_data)
+{
+	struct interface_scan_data *data;
+	int ret;
+
+	ret = interface_ready_to_scan(interface);
+	if (ret)
+		return ret;
+
+	data = dbus_malloc0(sizeof(*data));
+	if (!data)
+		return -ENOMEM;
+
+	data->interface = interface;
+	data->path = g_strdup(interface->path);
+	data->callback = callback;
+	data->user_data = user_data;
+	data->scan_params = scan_data;
+
+	interface->scan_callback = callback;
+	interface->scan_data = user_data;
+
+	ret = supplicant_dbus_method_call(interface->path,
+			SUPPLICANT_INTERFACE ".Interface", "Scan",
+			interface_scan_params, interface_scan_result, data,
+			interface);
+
+	if (ret < 0) {
+		g_free(data->path);
+		dbus_free(data);
+	}
+
+	return ret;
+}
+
+static int parse_supplicant_error(DBusMessageIter *iter)
+{
+	int err = -ECANCELED;
+	char *key;
+
+	if (!iter)
+		return err;
+
+	/* If the given passphrase is malformed wpa_s returns
+	 * "invalid message format" but this error should be interpreted as
+	 * invalid-key.
+	 */
+	while (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_STRING) {
+		dbus_message_iter_get_basic(iter, &key);
+		if (strncmp(key, "psk", 3) == 0 ||
+				strncmp(key, "wep_key", 7) == 0 ||
+				strcmp(key, "invalid message format") == 0) {
+			err = -ENOKEY;
+			break;
+		}
+		dbus_message_iter_next(iter);
+	}
+
+	return err;
+}
+
+static void interface_select_network_result(const char *error,
+				DBusMessageIter *iter, void *user_data)
+{
+	struct interface_connect_data *data = user_data;
+	int err;
+
+	SUPPLICANT_DBG("");
+
+	err = 0;
+	if (error) {
+		SUPPLICANT_DBG("SelectNetwork error %s", error);
+		err = parse_supplicant_error(iter);
+	}
+
+	g_free(data->path);
+
+	if (data->callback)
+		data->callback(err, data->interface, data->user_data);
+
+	g_free(data->ssid);
+	dbus_free(data);
+}
+
+static void interface_select_network_params(DBusMessageIter *iter,
+							void *user_data)
+{
+	struct interface_connect_data *data = user_data;
+	GSupplicantInterface *interface = data->interface;
+
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH,
+					&interface->network_path);
+}
+
+static void interface_add_network_result(const char *error,
+				DBusMessageIter *iter, void *user_data)
+{
+	struct interface_connect_data *data = user_data;
+	GSupplicantInterface *interface = data->interface;
+	const char *path;
+	int err;
+
+	if (error)
+		goto error;
+
+	dbus_message_iter_get_basic(iter, &path);
+	if (!path)
+		goto error;
+
+	SUPPLICANT_DBG("PATH: %s", path);
+
+	interface->network_path = g_strdup(path);
+
+	supplicant_dbus_method_call(data->interface->path,
+			SUPPLICANT_INTERFACE ".Interface", "SelectNetwork",
+			interface_select_network_params,
+			interface_select_network_result, data,
+			interface);
+
+	return;
+
+error:
+	SUPPLICANT_DBG("AddNetwork error %s", error);
+
+	if (interface_exists(data->interface, data->interface->path)) {
+		err = parse_supplicant_error(iter);
+		if (data->callback)
+			data->callback(err, data->interface, data->user_data);
+
+		g_free(interface->network_path);
+		interface->network_path = NULL;
+	}
+
+	g_free(data->path);
+	g_free(data->ssid);
+	g_free(data);
+}
+
+static void add_network_security_none(DBusMessageIter *dict)
+{
+	const char *auth_alg = "OPEN";
+
+	supplicant_dbus_dict_append_basic(dict, "auth_alg",
+					DBUS_TYPE_STRING, &auth_alg);
+}
+
+static void add_network_security_wep(DBusMessageIter *dict,
+					GSupplicantSSID *ssid)
+{
+	const char *auth_alg = "OPEN SHARED";
+	dbus_uint32_t key_index = 0;
+
+	supplicant_dbus_dict_append_basic(dict, "auth_alg",
+					DBUS_TYPE_STRING, &auth_alg);
+
+	if (ssid->passphrase) {
+		int size = strlen(ssid->passphrase);
+		if (size == 10 || size == 26) {
+			unsigned char *key = g_try_malloc(13);
+			char tmp[3];
+			int i;
+
+			memset(tmp, 0, sizeof(tmp));
+			if (!key)
+				size = 0;
+
+			for (i = 0; i < size / 2; i++) {
+				memcpy(tmp, ssid->passphrase + (i * 2), 2);
+				key[i] = (unsigned char) strtol(tmp, NULL, 16);
+			}
+
+			supplicant_dbus_dict_append_fixed_array(dict,
+							"wep_key0",
+							DBUS_TYPE_BYTE,
+							&key, size / 2);
+			g_free(key);
+		} else if (size == 5 || size == 13) {
+			unsigned char *key = g_try_malloc(13);
+			int i;
+
+			if (!key)
+				size = 0;
+
+			for (i = 0; i < size; i++)
+				key[i] = (unsigned char) ssid->passphrase[i];
+
+			supplicant_dbus_dict_append_fixed_array(dict,
+								"wep_key0",
+								DBUS_TYPE_BYTE,
+								&key, size);
+			g_free(key);
+		} else
+			supplicant_dbus_dict_append_basic(dict,
+							"wep_key0",
+							DBUS_TYPE_STRING,
+							&ssid->passphrase);
+
+		supplicant_dbus_dict_append_basic(dict, "wep_tx_keyidx",
+					DBUS_TYPE_UINT32, &key_index);
+	}
+}
+
+static dbus_bool_t is_psk_raw_key(const char *psk)
+{
+	int i;
+
+	/* A raw key is always 64 bytes length... */
+	if (strlen(psk) != 64)
+		return FALSE;
+
+	/* ... and its content is in hex representation */
+	for (i = 0; i < 64; i++)
+		if (!isxdigit((unsigned char) psk[i]))
+			return FALSE;
+
+	return TRUE;
+}
+
+static unsigned char hexchar2bin(char c)
+{
+	if ((c >= '0') && (c <= '9'))
+		return c - '0';
+	else if ((c >= 'A') && (c <= 'F'))
+		return c - 'A' + 10;
+	else if ((c >= 'a') && (c <= 'f'))
+		return c - 'a' + 10;
+	else
+		return c;
+}
+
+static void hexstring2bin(const char *string, unsigned char *data,
+				size_t data_len)
+{
+	size_t i;
+
+	for (i = 0; i < data_len; i++)
+		data[i] = (hexchar2bin(string[i * 2 + 0]) << 4 |
+			   hexchar2bin(string[i * 2 + 1]) << 0);
+}
+
+static void add_network_security_psk(DBusMessageIter *dict,
+					GSupplicantSSID *ssid)
+{
+	if (ssid->passphrase && strlen(ssid->passphrase) > 0) {
+		const char *key = "psk";
+
+		if (is_psk_raw_key(ssid->passphrase)) {
+			unsigned char data[32];
+			unsigned char *datap = data;
+
+			/* The above pointer alias is required by D-Bus because
+			 * with D-Bus and GCC, non-heap-allocated arrays cannot
+			 * be passed directly by their base pointer. */
+
+			hexstring2bin(ssid->passphrase, datap, sizeof(data));
+
+			supplicant_dbus_dict_append_fixed_array(dict,
+							key, DBUS_TYPE_BYTE,
+							&datap, sizeof(data));
+		} else
+			supplicant_dbus_dict_append_basic(dict,
+							key, DBUS_TYPE_STRING,
+							&ssid->passphrase);
+	}
+}
+
+static void add_network_security_tls(DBusMessageIter *dict,
+					GSupplicantSSID *ssid)
+{
+	/*
+	 * For TLS, we at least need:
+	 *              The client certificate
+	 *              The client private key file
+	 *              The client private key file password
+	 *
+	 * The Authority certificate is optional.
+	 */
+	if (!ssid->client_cert_path)
+		return;
+
+	if (!ssid->private_key_path)
+		return;
+
+	if (!ssid->private_key_passphrase)
+		return;
+
+	if (ssid->ca_cert_path)
+		supplicant_dbus_dict_append_basic(dict, "ca_cert",
+					DBUS_TYPE_STRING, &ssid->ca_cert_path);
+
+	supplicant_dbus_dict_append_basic(dict, "private_key",
+						DBUS_TYPE_STRING,
+						&ssid->private_key_path);
+	supplicant_dbus_dict_append_basic(dict, "private_key_passwd",
+						DBUS_TYPE_STRING,
+						&ssid->private_key_passphrase);
+	supplicant_dbus_dict_append_basic(dict, "client_cert",
+						DBUS_TYPE_STRING,
+						&ssid->client_cert_path);
+}
+
+static void add_network_security_peap(DBusMessageIter *dict,
+					GSupplicantSSID *ssid)
+{
+	char *phase2_auth;
+
+	/*
+	 * For PEAP/TTLS, we at least need
+	 *              The authority certificate
+	 *              The 2nd phase authentication method
+	 *              The 2nd phase passphrase
+	 *
+	 * The Client certificate is optional although strongly recommended
+	 * When setting it, we need in addition
+	 *              The Client private key file
+	 *              The Client private key file password
+	 */
+	if (!ssid->passphrase)
+		return;
+
+	if (!ssid->phase2_auth)
+		return;
+
+	if (ssid->client_cert_path) {
+		if (!ssid->private_key_path)
+			return;
+
+		if (!ssid->private_key_passphrase)
+			return;
+
+		supplicant_dbus_dict_append_basic(dict, "client_cert",
+						DBUS_TYPE_STRING,
+						&ssid->client_cert_path);
+
+		supplicant_dbus_dict_append_basic(dict, "private_key",
+						DBUS_TYPE_STRING,
+						&ssid->private_key_path);
+
+		supplicant_dbus_dict_append_basic(dict, "private_key_passwd",
+						DBUS_TYPE_STRING,
+						&ssid->private_key_passphrase);
+
+	}
+
+	if (g_str_has_prefix(ssid->phase2_auth, "EAP-")) {
+		phase2_auth = g_strdup_printf("autheap=%s",
+					ssid->phase2_auth + strlen("EAP-"));
+	} else
+		phase2_auth = g_strdup_printf("auth=%s", ssid->phase2_auth);
+
+	supplicant_dbus_dict_append_basic(dict, "password",
+						DBUS_TYPE_STRING,
+						&ssid->passphrase);
+
+	if (ssid->ca_cert_path)
+		supplicant_dbus_dict_append_basic(dict, "ca_cert",
+						DBUS_TYPE_STRING,
+						&ssid->ca_cert_path);
+
+	supplicant_dbus_dict_append_basic(dict, "phase2",
+						DBUS_TYPE_STRING,
+						&phase2_auth);
+
+	g_free(phase2_auth);
+}
+
+static void add_network_security_eap(DBusMessageIter *dict,
+					GSupplicantSSID *ssid)
+{
+	char *eap_value;
+
+	if (!ssid->eap || !ssid->identity)
+		return;
+
+	if (g_strcmp0(ssid->eap, "tls") == 0) {
+		add_network_security_tls(dict, ssid);
+	} else if (g_strcmp0(ssid->eap, "peap") == 0 ||
+				g_strcmp0(ssid->eap, "ttls") == 0) {
+		add_network_security_peap(dict, ssid);
+	} else
+		return;
+
+	eap_value = g_ascii_strup(ssid->eap, -1);
+
+	supplicant_dbus_dict_append_basic(dict, "eap",
+						DBUS_TYPE_STRING,
+						&eap_value);
+	supplicant_dbus_dict_append_basic(dict, "identity",
+						DBUS_TYPE_STRING,
+						&ssid->identity);
+
+	g_free(eap_value);
+}
+
+static void add_network_security_ciphers(DBusMessageIter *dict,
+						GSupplicantSSID *ssid)
+{
+	unsigned int p_cipher, g_cipher, i;
+	char *pairwise, *group;
+	char *pair_ciphers[4];
+	char *group_ciphers[5];
+
+	p_cipher = ssid->pairwise_cipher;
+	g_cipher = ssid->group_cipher;
+
+	if (p_cipher == 0 && g_cipher == 0)
+		return;
+
+	i = 0;
+
+	if (p_cipher & G_SUPPLICANT_PAIRWISE_CCMP)
+		pair_ciphers[i++] = "CCMP";
+
+	if (p_cipher & G_SUPPLICANT_PAIRWISE_TKIP)
+		pair_ciphers[i++] = "TKIP";
+
+	if (p_cipher & G_SUPPLICANT_PAIRWISE_NONE)
+		pair_ciphers[i++] = "NONE";
+
+	pair_ciphers[i] = NULL;
+
+	i = 0;
+
+	if (g_cipher & G_SUPPLICANT_GROUP_CCMP)
+		group_ciphers[i++] = "CCMP";
+
+	if (g_cipher & G_SUPPLICANT_GROUP_TKIP)
+		group_ciphers[i++] = "TKIP";
+
+	if (g_cipher & G_SUPPLICANT_GROUP_WEP104)
+		group_ciphers[i++] = "WEP104";
+
+	if (g_cipher & G_SUPPLICANT_GROUP_WEP40)
+		group_ciphers[i++] = "WEP40";
+
+	group_ciphers[i] = NULL;
+
+	pairwise = g_strjoinv(" ", pair_ciphers);
+	group = g_strjoinv(" ", group_ciphers);
+
+	SUPPLICANT_DBG("cipher %s %s", pairwise, group);
+
+	supplicant_dbus_dict_append_basic(dict, "pairwise",
+						DBUS_TYPE_STRING,
+						&pairwise);
+	supplicant_dbus_dict_append_basic(dict, "group",
+						DBUS_TYPE_STRING,
+						&group);
+
+	g_free(pairwise);
+	g_free(group);
+}
+
+static void add_network_security_proto(DBusMessageIter *dict,
+						GSupplicantSSID *ssid)
+{
+	unsigned int protocol, i;
+	char *proto;
+	char *protos[3];
+
+	protocol = ssid->protocol;
+
+	if (protocol == 0)
+		return;
+
+	i = 0;
+
+	if (protocol & G_SUPPLICANT_PROTO_RSN)
+		protos[i++] = "RSN";
+
+	if (protocol & G_SUPPLICANT_PROTO_WPA)
+		protos[i++] = "WPA";
+
+	protos[i] = NULL;
+
+	proto = g_strjoinv(" ", protos);
+
+	SUPPLICANT_DBG("proto %s", proto);
+
+	supplicant_dbus_dict_append_basic(dict, "proto",
+						DBUS_TYPE_STRING,
+						&proto);
+
+	g_free(proto);
+}
+
+static void add_network_security(DBusMessageIter *dict, GSupplicantSSID *ssid)
+{
+	char *key_mgmt;
+
+	switch (ssid->security) {
+	case G_SUPPLICANT_SECURITY_NONE:
+		key_mgmt = "NONE";
+		add_network_security_none(dict);
+		add_network_security_ciphers(dict, ssid);
+		break;
+	case G_SUPPLICANT_SECURITY_UNKNOWN:
+	case G_SUPPLICANT_SECURITY_WEP:
+		key_mgmt = "NONE";
+		add_network_security_wep(dict, ssid);
+		add_network_security_ciphers(dict, ssid);
+		break;
+	case G_SUPPLICANT_SECURITY_PSK:
+		key_mgmt = "WPA-PSK";
+		add_network_security_psk(dict, ssid);
+		add_network_security_ciphers(dict, ssid);
+		add_network_security_proto(dict, ssid);
+		break;
+	case G_SUPPLICANT_SECURITY_IEEE8021X:
+		key_mgmt = "WPA-EAP";
+		add_network_security_eap(dict, ssid);
+		add_network_security_ciphers(dict, ssid);
+		add_network_security_proto(dict, ssid);
+		break;
+	}
+
+	supplicant_dbus_dict_append_basic(dict, "key_mgmt",
+				DBUS_TYPE_STRING, &key_mgmt);
+}
+
+static void add_network_mode(DBusMessageIter *dict, GSupplicantSSID *ssid)
+{
+	dbus_uint32_t mode;
+
+	switch (ssid->mode) {
+	case G_SUPPLICANT_MODE_UNKNOWN:
+	case G_SUPPLICANT_MODE_INFRA:
+		mode = 0;
+		break;
+	case G_SUPPLICANT_MODE_IBSS:
+		mode = 1;
+		break;
+	case G_SUPPLICANT_MODE_MASTER:
+		mode = 2;
+		break;
+	}
+
+	supplicant_dbus_dict_append_basic(dict, "mode",
+				DBUS_TYPE_UINT32, &mode);
+}
+
+static void interface_add_network_params(DBusMessageIter *iter, void *user_data)
+{
+	DBusMessageIter dict;
+	struct interface_connect_data *data = user_data;
+	GSupplicantSSID *ssid = data->ssid;
+
+	supplicant_dbus_dict_open(iter, &dict);
+
+	if (ssid->scan_ssid)
+		supplicant_dbus_dict_append_basic(&dict, "scan_ssid",
+					 DBUS_TYPE_UINT32, &ssid->scan_ssid);
+
+	if (ssid->freq)
+		supplicant_dbus_dict_append_basic(&dict, "frequency",
+					 DBUS_TYPE_UINT32, &ssid->freq);
+
+	if (ssid->bgscan)
+		supplicant_dbus_dict_append_basic(&dict, "bgscan",
+					DBUS_TYPE_STRING, &ssid->bgscan);
+
+	add_network_mode(&dict, ssid);
+
+	add_network_security(&dict, ssid);
+
+	supplicant_dbus_dict_append_fixed_array(&dict, "ssid",
+					DBUS_TYPE_BYTE, &ssid->ssid,
+						ssid->ssid_len);
+
+	supplicant_dbus_dict_close(iter, &dict);
+}
+
+static void interface_wps_start_result(const char *error,
+				DBusMessageIter *iter, void *user_data)
+{
+	struct interface_connect_data *data = user_data;
+	int err;
+
+	SUPPLICANT_DBG("");
+
+	err = 0;
+	if (error) {
+		SUPPLICANT_DBG("error: %s", error);
+		err = parse_supplicant_error(iter);
+	}
+
+	if(data->callback)
+		data->callback(err, data->interface, data->user_data);
+
+	g_free(data->path);
+	g_free(data->ssid);
+	dbus_free(data);
+}
+
+static void interface_add_wps_params(DBusMessageIter *iter, void *user_data)
+{
+	struct interface_connect_data *data = user_data;
+	GSupplicantSSID *ssid = data->ssid;
+	const char *role = "enrollee", *type;
+	DBusMessageIter dict;
+
+	SUPPLICANT_DBG("");
+
+	supplicant_dbus_dict_open(iter, &dict);
+
+	supplicant_dbus_dict_append_basic(&dict, "Role",
+						DBUS_TYPE_STRING, &role);
+
+	type = "pbc";
+	if (ssid->pin_wps) {
+		type = "pin";
+		supplicant_dbus_dict_append_basic(&dict, "Pin",
+					DBUS_TYPE_STRING, &ssid->pin_wps);
+	}
+
+	supplicant_dbus_dict_append_basic(&dict, "Type",
+					DBUS_TYPE_STRING, &type);
+
+	supplicant_dbus_dict_close(iter, &dict);
+}
+
+static void wps_start(const char *error, DBusMessageIter *iter, void *user_data)
+{
+	struct interface_connect_data *data = user_data;
+
+	SUPPLICANT_DBG("");
+
+	if (error) {
+		SUPPLICANT_DBG("error: %s", error);
+		g_free(data->path);
+		g_free(data->ssid);
+		dbus_free(data);
+		return;
+	}
+
+	supplicant_dbus_method_call(data->interface->path,
+			SUPPLICANT_INTERFACE ".Interface.WPS", "Start",
+			interface_add_wps_params,
+			interface_wps_start_result, data, NULL);
+}
+
+static void wps_process_credentials(DBusMessageIter *iter, void *user_data)
+{
+	dbus_bool_t credentials = TRUE;
+
+	SUPPLICANT_DBG("");
+
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_BOOLEAN, &credentials);
+}
+
+
+int g_supplicant_interface_connect(GSupplicantInterface *interface,
+				GSupplicantSSID *ssid,
+				GSupplicantInterfaceCallback callback,
+							void *user_data)
+{
+	struct interface_connect_data *data;
+	int ret = 0;
+
+	if (!interface)
+		return -EINVAL;
+
+	if (!system_available)
+		return -EFAULT;
+
+	/* TODO: Check if we're already connected and switch */
+
+	data = dbus_malloc0(sizeof(*data));
+	if (!data)
+		return -ENOMEM;
+
+	data->interface = interface;
+	data->path = g_strdup(interface->path);
+	data->callback = callback;
+	data->ssid = ssid;
+	data->user_data = user_data;
+
+	if (ssid->use_wps) {
+		g_free(interface->wps_cred.key);
+		memset(&interface->wps_cred, 0,
+				sizeof(struct _GSupplicantWpsCredentials));
+
+		ret = supplicant_dbus_property_set(interface->path,
+			SUPPLICANT_INTERFACE ".Interface.WPS",
+			"ProcessCredentials", DBUS_TYPE_BOOLEAN_AS_STRING,
+			wps_process_credentials, wps_start, data, interface);
+	} else {
+		/* By the time there is a request for connect and the network
+		 * path is not NULL it means that connman has not removed the
+		 * previous network pointer. This can happen in the case AP
+		 * deauthenticated client and connman does not remove the
+		 * previously connected network pointer. This causes supplicant
+		 * to reallocate the memory for struct wpa_ssid again even if it
+		 * is the same SSID. This causes memory usage of wpa_supplicnat
+		 * to go high. The idea here is that if the previously connected
+		 * network is not removed at the time of next connection attempt
+		 * check if the network path is not NULL. In case it is non-NULL
+		 * first remove the network and then once removal is successful, add
+		 * the network.
+		 */
+
+		if (interface->network_path != NULL) {
+			data->network_remove_in_progress = TRUE;
+			network_remove((struct interface_data *)data);
+		}
+		else {
+			ret = supplicant_dbus_method_call(interface->path,
+					SUPPLICANT_INTERFACE ".Interface", "AddNetwork",
+					interface_add_network_params,
+					interface_add_network_result, data,
+					interface);
+		}
+        }
+
+	if (ret < 0) {
+		g_free(data->path);
+		dbus_free(data);
+		return ret;
+	}
+
+	return -EINPROGRESS;
+}
+
+static void network_remove_result(const char *error,
+				DBusMessageIter *iter, void *user_data)
+{
+	struct interface_data *data = user_data;
+	int result = 0;
+
+	SUPPLICANT_DBG("");
+
+	if (error) {
+		result = -EIO;
+		if (g_strcmp0("org.freedesktop.DBus.Error.UnknownMethod",
+						error) == 0)
+			result = -ECONNABORTED;
+	}
+
+        g_free(data->interface->network_path);
+        data->interface->network_path = NULL;
+
+	if (data->network_remove_in_progress == TRUE) {
+		data->network_remove_in_progress = FALSE;
+		supplicant_dbus_method_call(data->interface->path,
+			SUPPLICANT_INTERFACE ".Interface", "AddNetwork",
+			interface_add_network_params,
+			interface_add_network_result, data,
+			data->interface);
+	}
+	else {
+		g_free(data->path);
+		if (data->callback)
+			data->callback(result, data->interface, data->user_data);
+		dbus_free(data);
+	}
+}
+
+static void network_remove_params(DBusMessageIter *iter, void *user_data)
+{
+	struct interface_data *data = user_data;
+	const char *path = data->interface->network_path;
+
+	SUPPLICANT_DBG("path %s", path);
+
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH, &path);
+}
+
+static int network_remove(struct interface_data *data)
+{
+	GSupplicantInterface *interface = data->interface;
+
+	SUPPLICANT_DBG("");
+
+	return supplicant_dbus_method_call(interface->path,
+			SUPPLICANT_INTERFACE ".Interface", "RemoveNetwork",
+			network_remove_params, network_remove_result, data,
+			interface);
+}
+
+static void interface_disconnect_result(const char *error,
+				DBusMessageIter *iter, void *user_data)
+{
+	struct interface_data *data = user_data;
+	int result = 0;
+
+	SUPPLICANT_DBG("");
+
+	if (error) {
+		result = -EIO;
+		if (g_strcmp0("org.freedesktop.DBus.Error.UnknownMethod",
+						error) == 0)
+			result = -ECONNABORTED;
+	}
+
+	if (result < 0 && data->callback) {
+		data->callback(result, data->interface, data->user_data);
+		data->callback = NULL;
+	}
+
+	/* If we are disconnecting from previous WPS successful
+	 * association. i.e.: it did not went through AddNetwork,
+	 * and interface->network_path was never set. */
+	if (!data->interface->network_path) {
+		g_free(data->path);
+		dbus_free(data);
+		return;
+	}
+
+	if (result != -ECONNABORTED) {
+		if (network_remove(data) < 0) {
+			g_free(data->path);
+			dbus_free(data);
+		}
+	} else {
+		g_free(data->path);
+		dbus_free(data);
+	}
+}
+
+int g_supplicant_interface_disconnect(GSupplicantInterface *interface,
+					GSupplicantInterfaceCallback callback,
+							void *user_data)
+{
+	struct interface_data *data;
+	int ret;
+
+	SUPPLICANT_DBG("");
+
+	if (!interface)
+		return -EINVAL;
+
+	if (!system_available)
+		return -EFAULT;
+
+	data = dbus_malloc0(sizeof(*data));
+	if (!data)
+		return -ENOMEM;
+
+	data->interface = interface;
+	data->path = g_strdup(interface->path);
+	data->callback = callback;
+	data->user_data = user_data;
+
+	ret = supplicant_dbus_method_call(interface->path,
+			SUPPLICANT_INTERFACE ".Interface", "Disconnect",
+			NULL, interface_disconnect_result, data,
+			interface);
+
+	if (ret < 0) {
+		g_free(data->path);
+		dbus_free(data);
+	}
+
+	return ret;
+}
+
+static void interface_p2p_find_result(const char *error,
+					DBusMessageIter *iter, void *user_data)
+{
+	struct interface_scan_data *data = user_data;
+	int err = 0;
+
+	SUPPLICANT_DBG("error %s", error);
+
+	if (error)
+		err = -EIO;
+
+	if (interface_exists(data->interface, data->path)) {
+		if (!data->interface->ready)
+			err = -ENOLINK;
+		if (!err)
+			data->interface->p2p_finding = true;
+	}
+
+	if (data->callback)
+		data->callback(err, data->interface, data->user_data);
+
+	g_free(data->path);
+	dbus_free(data);
+}
+
+static void interface_p2p_find_params(DBusMessageIter *iter, void *user_data)
+{
+	DBusMessageIter dict;
+
+	supplicant_dbus_dict_open(iter, &dict);
+	supplicant_dbus_dict_close(iter, &dict);
+}
+
+int g_supplicant_interface_p2p_find(GSupplicantInterface *interface,
+					GSupplicantInterfaceCallback callback,
+							void *user_data)
+{
+	struct interface_scan_data *data;
+	int ret;
+
+	if (!interface->p2p_support)
+		return -ENOTSUP;
+
+	ret = interface_ready_to_scan(interface);
+	if (ret && ret != -EALREADY)
+		return ret;
+
+	data = dbus_malloc0(sizeof(*data));
+	if (!data)
+		return -ENOMEM;
+
+	data->interface = interface;
+	data->path = g_strdup(interface->path);
+	data->callback = callback;
+	data->user_data = user_data;
+
+	ret = supplicant_dbus_method_call(interface->path,
+			SUPPLICANT_INTERFACE ".Interface.P2PDevice", "Find",
+			interface_p2p_find_params, interface_p2p_find_result,
+			data, interface);
+	if (ret < 0) {
+		g_free(data->path);
+		dbus_free(data);
+	}
+
+	return ret;
+}
+
+bool g_supplicant_interface_is_p2p_finding(GSupplicantInterface *interface)
+{
+	if (!interface)
+		return false;
+
+	return interface->p2p_finding;
+}
+
+int g_supplicant_interface_p2p_stop_find(GSupplicantInterface *interface)
+{
+	if (!interface->p2p_finding)
+		return 0;
+
+	SUPPLICANT_DBG("");
+
+	interface->p2p_finding = false;
+
+	return supplicant_dbus_method_call(interface->path,
+		SUPPLICANT_INTERFACE ".Interface.P2PDevice", "StopFind",
+		NULL, NULL, NULL, NULL);
+}
+
+static void interface_p2p_connect_result(const char *error,
+					DBusMessageIter *iter, void *user_data)
+{
+	struct interface_connect_data *data = user_data;
+	int err = 0;
+
+	SUPPLICANT_DBG("");
+
+	if (error)
+		err = parse_supplicant_error(iter);
+
+	if (data->callback)
+		data->callback(err, data->interface, data->user_data);
+
+	g_free(data->path);
+	g_free(data->peer->wps_pin);
+	g_free(data->peer->path);
+	g_free(data->peer);
+	g_free(data);
+}
+
+static void interface_p2p_connect_params(DBusMessageIter *iter, void *user_data)
+{
+	struct interface_connect_data *data = user_data;
+	const char *wps = "pbc";
+	DBusMessageIter dict;
+	int go_intent = 7;
+
+	SUPPLICANT_DBG("");
+
+	supplicant_dbus_dict_open(iter, &dict);
+
+	if (data->peer->master)
+		go_intent = 15;
+
+	if (data->peer->wps_pin)
+		wps = "pin";
+
+	supplicant_dbus_dict_append_basic(&dict, "peer",
+				DBUS_TYPE_OBJECT_PATH, &data->peer->path);
+	supplicant_dbus_dict_append_basic(&dict, "wps_method",
+				DBUS_TYPE_STRING, &wps);
+	if (data->peer->wps_pin) {
+		supplicant_dbus_dict_append_basic(&dict, "pin",
+				DBUS_TYPE_STRING, &data->peer->wps_pin);
+	}
+
+	supplicant_dbus_dict_append_basic(&dict, "go_intent",
+					DBUS_TYPE_INT32, &go_intent);
+
+	supplicant_dbus_dict_close(iter, &dict);
+}
+
+int g_supplicant_interface_p2p_connect(GSupplicantInterface *interface,
+					GSupplicantPeerParams *peer_params,
+					GSupplicantInterfaceCallback callback,
+					void *user_data)
+{
+	struct interface_connect_data *data;
+	int ret;
+
+	SUPPLICANT_DBG("");
+
+	if (!interface->p2p_support)
+		return -ENOTSUP;
+
+	data = dbus_malloc0(sizeof(*data));
+	data->interface = interface;
+	data->path = g_strdup(interface->path);
+	data->peer = peer_params;
+	data->callback = callback;
+	data->user_data = user_data;
+
+	ret = supplicant_dbus_method_call(interface->path,
+		SUPPLICANT_INTERFACE ".Interface.P2PDevice", "Connect",
+		interface_p2p_connect_params, interface_p2p_connect_result,
+		data, interface);
+	if (ret < 0) {
+		g_free(data->path);
+		dbus_free(data);
+		return ret;
+	}
+
+	return -EINPROGRESS;
+}
+
+int g_supplicant_interface_p2p_disconnect(GSupplicantInterface *interface,
+					GSupplicantPeerParams *peer_params)
+{
+	GSupplicantPeer *peer;
+	int count = 0;
+	GSList *list;
+
+	SUPPLICANT_DBG("");
+
+	if (!interface->p2p_support)
+		return -ENOTSUP;
+
+	peer = g_hash_table_lookup(interface->peer_table, peer_params->path);
+	if (!peer)
+		return -ENODEV;
+
+	for (list = peer->groups; list; list = list->next, count++) {
+		const char *group_obj_path = list->data;
+		GSupplicantInterface *g_interface;
+		GSupplicantGroup *group;
+
+		group = g_hash_table_lookup(group_mapping, group_obj_path);
+		if (!group || !group->interface)
+			continue;
+
+		g_interface = group->interface;
+		supplicant_dbus_method_call(g_interface->path,
+				SUPPLICANT_INTERFACE ".Interface.P2PDevice",
+				"Disconnect", NULL, NULL, NULL, g_interface);
+	}
+
+	if (count == 0 && peer->current_group_iface) {
+		supplicant_dbus_method_call(peer->current_group_iface->path,
+				SUPPLICANT_INTERFACE ".Interface.P2PDevice",
+				"Disconnect", NULL, NULL, NULL,
+				peer->current_group_iface->path);
+	}
+
+	peer->current_group_iface = NULL;
+
+	return -EINPROGRESS;
+}
+
+struct p2p_service_data {
+	bool registration;
+	GSupplicantInterface *interface;
+	GSupplicantP2PServiceParams *service;
+	GSupplicantInterfaceCallback callback;
+	void *user_data;
+};
+
+static void interface_p2p_service_result(const char *error,
+					DBusMessageIter *iter, void *user_data)
+{
+	struct p2p_service_data *data = user_data;
+	int result = 0;
+
+	SUPPLICANT_DBG("%s result - %s", data->registration ?
+				"Registration" : "Deletion",
+				error ? error : "Success");
+	if (error)
+		result = -EINVAL;
+
+	if (data->callback)
+		data->callback(result, data->interface, data->user_data);
+
+	g_free(data->service->query);
+	g_free(data->service->response);
+	g_free(data->service->service);
+	g_free(data->service->wfd_ies);
+	g_free(data->service);
+	dbus_free(data);
+}
+
+static void interface_p2p_service_params(DBusMessageIter *iter,
+							void *user_data)
+{
+	struct p2p_service_data *data = user_data;
+	GSupplicantP2PServiceParams *service;
+	DBusMessageIter dict;
+	const char *type;
+
+	SUPPLICANT_DBG("");
+
+	service = data->service;
+
+	supplicant_dbus_dict_open(iter, &dict);
+
+	if (service->query && service->response) {
+		type = "bonjour";
+		supplicant_dbus_dict_append_basic(&dict, "service_type",
+						DBUS_TYPE_STRING, &type);
+		supplicant_dbus_dict_append_fixed_array(&dict, "query",
+					DBUS_TYPE_BYTE, &service->query,
+					service->query_length);
+		supplicant_dbus_dict_append_fixed_array(&dict, "response",
+					DBUS_TYPE_BYTE, &service->response,
+					service->response_length);
+	} else if (service->version && service->service) {
+		type = "upnp";
+		supplicant_dbus_dict_append_basic(&dict, "service_type",
+						DBUS_TYPE_STRING, &type);
+		supplicant_dbus_dict_append_basic(&dict, "version",
+					DBUS_TYPE_INT32, &service->version);
+		supplicant_dbus_dict_append_basic(&dict, "service",
+					DBUS_TYPE_STRING, &service->service);
+	}
+
+	supplicant_dbus_dict_close(iter, &dict);
+}
+
+int g_supplicant_interface_p2p_add_service(GSupplicantInterface *interface,
+				GSupplicantInterfaceCallback callback,
+				GSupplicantP2PServiceParams *p2p_service_params,
+				void *user_data)
+{
+	struct p2p_service_data *data;
+	int ret;
+
+	SUPPLICANT_DBG("");
+
+	if (!interface->p2p_support)
+		return -ENOTSUP;
+
+	data = dbus_malloc0(sizeof(*data));
+	data->registration = true;
+	data->interface = interface;
+	data->service = p2p_service_params;
+	data->callback = callback;
+	data->user_data = user_data;
+
+	ret = supplicant_dbus_method_call(interface->path,
+		SUPPLICANT_INTERFACE ".Interface.P2PDevice", "AddService",
+		interface_p2p_service_params, interface_p2p_service_result,
+		data, interface);
+	if (ret < 0) {
+		dbus_free(data);
+		return ret;
+	}
+
+	return -EINPROGRESS;
+}
+
+int g_supplicant_interface_p2p_del_service(GSupplicantInterface *interface,
+				GSupplicantP2PServiceParams *p2p_service_params)
+{
+	struct p2p_service_data *data;
+	int ret;
+
+	SUPPLICANT_DBG("");
+
+	if (!interface->p2p_support)
+		return -ENOTSUP;
+
+	data = dbus_malloc0(sizeof(*data));
+	data->interface = interface;
+	data->service = p2p_service_params;
+
+	ret = supplicant_dbus_method_call(interface->path,
+		SUPPLICANT_INTERFACE ".Interface.P2PDevice", "DeleteService",
+		interface_p2p_service_params, interface_p2p_service_result,
+		data, interface);
+	if (ret < 0) {
+		dbus_free(data);
+		return ret;
+	}
+
+	return -EINPROGRESS;
+}
+
+struct p2p_listen_data {
+	int period;
+	int interval;
+};
+
+static void interface_p2p_listen_params(DBusMessageIter *iter, void *user_data)
+{
+	struct p2p_listen_data *params = user_data;
+	DBusMessageIter dict;
+
+	supplicant_dbus_dict_open(iter, &dict);
+
+	supplicant_dbus_dict_append_basic(&dict, "period",
+					DBUS_TYPE_INT32, &params->period);
+	supplicant_dbus_dict_append_basic(&dict, "interval",
+					DBUS_TYPE_INT32, &params->interval);
+	supplicant_dbus_dict_close(iter, &dict);
+}
+
+int g_supplicant_interface_p2p_listen(GSupplicantInterface *interface,
+						int period, int interval)
+{
+	struct p2p_listen_data params;
+
+	SUPPLICANT_DBG("");
+
+	if (!interface->p2p_support)
+		return -ENOTSUP;
+
+	params.period = period;
+	params.interval = interval;
+
+	return supplicant_dbus_method_call(interface->path,
+			SUPPLICANT_INTERFACE ".Interface.P2PDevice",
+			"ExtendedListen", interface_p2p_listen_params,
+			NULL, &params, NULL);
+}
+
+static void widi_ies_params(DBusMessageIter *iter, void *user_data)
+{
+	struct p2p_service_data *data = user_data;
+	GSupplicantP2PServiceParams *service = data->service;
+	DBusMessageIter array;
+
+	SUPPLICANT_DBG("%p - %d", service->wfd_ies, service->wfd_ies_length);
+
+	dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY,
+					DBUS_TYPE_BYTE_AS_STRING, &array);
+
+	if (service->wfd_ies && service->wfd_ies_length > 0) {
+		dbus_message_iter_append_fixed_array(&array, DBUS_TYPE_BYTE,
+				&service->wfd_ies, service->wfd_ies_length);
+	}
+
+	dbus_message_iter_close_container(iter, &array);
+}
+
+int g_supplicant_set_widi_ies(GSupplicantP2PServiceParams *p2p_service_params,
+					GSupplicantInterfaceCallback callback,
+					void *user_data)
+{
+	struct p2p_service_data *data;
+	int ret;
+
+	SUPPLICANT_DBG("");
+
+	if (!system_available)
+		return -EFAULT;
+
+	data = dbus_malloc0(sizeof(*data));
+	data->service = p2p_service_params;
+	data->callback = callback;
+	data->user_data = user_data;
+
+	if (p2p_service_params->wfd_ies)
+		data->registration = true;
+
+	ret = supplicant_dbus_property_set(SUPPLICANT_PATH,
+					SUPPLICANT_INTERFACE, "WFDIEs",
+					DBUS_TYPE_ARRAY_AS_STRING
+					DBUS_TYPE_BYTE_AS_STRING,
+					widi_ies_params,
+					interface_p2p_service_result,
+					data, NULL);
+	if (ret < 0 && ret != -EINPROGRESS) {
+		dbus_free(data);
+		return ret;
+	}
+
+	return -EINPROGRESS;
+}
+
+
+static const char *g_supplicant_rule0 = "type=signal,"
+					"path=" DBUS_PATH_DBUS ","
+					"sender=" DBUS_SERVICE_DBUS ","
+					"interface=" DBUS_INTERFACE_DBUS ","
+					"member=NameOwnerChanged,"
+					"arg0=" SUPPLICANT_SERVICE;
+static const char *g_supplicant_rule1 = "type=signal,"
+			"interface=" SUPPLICANT_INTERFACE;
+static const char *g_supplicant_rule2 = "type=signal,"
+			"interface=" SUPPLICANT_INTERFACE ".Interface";
+static const char *g_supplicant_rule3 = "type=signal,"
+			"interface=" SUPPLICANT_INTERFACE ".Interface.WPS";
+static const char *g_supplicant_rule4 = "type=signal,"
+			"interface=" SUPPLICANT_INTERFACE ".BSS";
+static const char *g_supplicant_rule5 = "type=signal,"
+			"interface=" SUPPLICANT_INTERFACE ".Network";
+static const char *g_supplicant_rule6 = "type=signal,"
+		"interface=" SUPPLICANT_INTERFACE ".Interface.P2PDevice";
+static const char *g_supplicant_rule7 = "type=signal,"
+		"interface=" SUPPLICANT_INTERFACE ".Peer";
+static const char *g_supplicant_rule8 = "type=signal,"
+		"interface=" SUPPLICANT_INTERFACE ".Group";
+
+static void invoke_introspect_method(void)
+{
+	DBusMessage *message;
+
+	message = dbus_message_new_method_call(SUPPLICANT_SERVICE,
+					SUPPLICANT_PATH,
+					DBUS_INTERFACE_INTROSPECTABLE,
+					"Introspect");
+
+	if (!message)
+		return;
+
+	dbus_message_set_no_reply(message, TRUE);
+	dbus_connection_send(connection, message, NULL);
+	dbus_message_unref(message);
+}
+
+int g_supplicant_register(const GSupplicantCallbacks *callbacks)
+{
+	connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
+	if (!connection)
+		return -EIO;
+
+	if (!dbus_connection_add_filter(connection, g_supplicant_filter,
+						NULL, NULL)) {
+		dbus_connection_unref(connection);
+		connection = NULL;
+		return -EIO;
+	}
+
+	callbacks_pointer = callbacks;
+	eap_methods = 0;
+
+	interface_table = g_hash_table_new_full(g_str_hash, g_str_equal,
+						NULL, remove_interface);
+
+	bss_mapping = g_hash_table_new_full(g_str_hash, g_str_equal,
+								NULL, NULL);
+	peer_mapping = g_hash_table_new_full(g_str_hash, g_str_equal,
+								NULL, NULL);
+	group_mapping = g_hash_table_new_full(g_str_hash, g_str_equal,
+								NULL, NULL);
+	pending_peer_connection = g_hash_table_new_full(g_str_hash, g_str_equal,
+								NULL, NULL);
+
+	supplicant_dbus_setup(connection);
+
+	dbus_bus_add_match(connection, g_supplicant_rule0, NULL);
+	dbus_bus_add_match(connection, g_supplicant_rule1, NULL);
+	dbus_bus_add_match(connection, g_supplicant_rule2, NULL);
+	dbus_bus_add_match(connection, g_supplicant_rule3, NULL);
+	dbus_bus_add_match(connection, g_supplicant_rule4, NULL);
+	dbus_bus_add_match(connection, g_supplicant_rule5, NULL);
+	dbus_bus_add_match(connection, g_supplicant_rule6, NULL);
+	dbus_bus_add_match(connection, g_supplicant_rule7, NULL);
+	dbus_bus_add_match(connection, g_supplicant_rule8, NULL);
+	dbus_connection_flush(connection);
+
+	if (dbus_bus_name_has_owner(connection,
+					SUPPLICANT_SERVICE, NULL)) {
+		system_available = TRUE;
+		supplicant_dbus_property_get_all(SUPPLICANT_PATH,
+						SUPPLICANT_INTERFACE,
+						service_property, NULL, NULL);
+	} else
+		invoke_introspect_method();
+
+	return 0;
+}
+
+static void unregister_interface_remove_params(DBusMessageIter *iter,
+						void *user_data)
+{
+	const char *path = user_data;
+
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH,
+							&path);
+}
+
+
+static void unregister_remove_interface(gpointer key, gpointer value,
+						gpointer user_data)
+{
+	GSupplicantInterface *interface = value;
+
+	supplicant_dbus_method_call(SUPPLICANT_PATH,
+					SUPPLICANT_INTERFACE,
+					"RemoveInterface",
+					unregister_interface_remove_params,
+					NULL, interface->path, NULL);
+}
+
+void g_supplicant_unregister(const GSupplicantCallbacks *callbacks)
+{
+	SUPPLICANT_DBG("");
+
+	if (connection) {
+		dbus_bus_remove_match(connection, g_supplicant_rule8, NULL);
+		dbus_bus_remove_match(connection, g_supplicant_rule7, NULL);
+		dbus_bus_remove_match(connection, g_supplicant_rule6, NULL);
+		dbus_bus_remove_match(connection, g_supplicant_rule5, NULL);
+		dbus_bus_remove_match(connection, g_supplicant_rule4, NULL);
+		dbus_bus_remove_match(connection, g_supplicant_rule3, NULL);
+		dbus_bus_remove_match(connection, g_supplicant_rule2, NULL);
+		dbus_bus_remove_match(connection, g_supplicant_rule1, NULL);
+		dbus_bus_remove_match(connection, g_supplicant_rule0, NULL);
+		dbus_connection_flush(connection);
+
+		dbus_connection_remove_filter(connection,
+						g_supplicant_filter, NULL);
+	}
+
+	if (bss_mapping) {
+		g_hash_table_destroy(bss_mapping);
+		bss_mapping = NULL;
+	}
+
+	if (peer_mapping) {
+		g_hash_table_destroy(peer_mapping);
+		peer_mapping = NULL;
+	}
+
+	if (group_mapping) {
+		g_hash_table_destroy(group_mapping);
+		group_mapping = NULL;
+	}
+
+	if (interface_table) {
+		g_hash_table_foreach(interface_table,
+					unregister_remove_interface, NULL);
+		g_hash_table_destroy(interface_table);
+		interface_table = NULL;
+	}
+
+	if (system_available)
+		callback_system_killed();
+
+	if (connection) {
+		dbus_connection_unref(connection);
+		connection = NULL;
+	}
+
+	callbacks_pointer = NULL;
+	eap_methods = 0;
+}
diff --git a/connman/gweb/giognutls.c b/connman/gweb/giognutls.c
new file mode 100644
index 0000000..09dc9e7
--- /dev/null
+++ b/connman/gweb/giognutls.c
@@ -0,0 +1,469 @@
+/*
+ *
+ *  Web service library with GLib integration
+ *
+ *  Copyright (C) 2009-2012  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 <stdio.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#include <gnutls/gnutls.h>
+
+#include "giognutls.h"
+
+//#define DBG(fmt, arg...)  printf("%s: " fmt "\n" , __func__ , ## arg)
+#define DBG(fmt, arg...)
+
+typedef struct _GIOGnuTLSChannel GIOGnuTLSChannel;
+typedef struct _GIOGnuTLSWatch GIOGnuTLSWatch;
+
+struct _GIOGnuTLSChannel {
+	GIOChannel channel;
+	gint fd;
+	gnutls_certificate_credentials_t cred;
+	gnutls_session_t session;
+	bool established;
+	bool again;
+};
+
+struct _GIOGnuTLSWatch {
+	GSource source;
+	GPollFD pollfd;
+	GIOChannel *channel;
+	GIOCondition condition;
+};
+
+static volatile int global_init_done = 0;
+
+static inline void g_io_gnutls_global_init(void)
+{
+	if (__sync_bool_compare_and_swap(&global_init_done, 0, 1))
+		gnutls_global_init();
+}
+
+static GIOStatus check_handshake(GIOChannel *channel, GError **err)
+{
+	GIOGnuTLSChannel *gnutls_channel = (GIOGnuTLSChannel *) channel;
+	int result;
+
+	DBG("channel %p", channel);
+
+	if (gnutls_channel->established)
+		return G_IO_STATUS_NORMAL;
+
+again:
+	result = gnutls_handshake(gnutls_channel->session);
+
+	if (result == GNUTLS_E_INTERRUPTED || result == GNUTLS_E_AGAIN) {
+		GIOFlags flags = g_io_channel_get_flags(channel);
+
+		if (gnutls_channel->again)
+			return G_IO_STATUS_AGAIN;
+
+		if (flags & G_IO_FLAG_NONBLOCK)
+			return G_IO_STATUS_AGAIN;
+
+		goto again;
+	}
+
+	if (result < 0) {
+		g_set_error(err, G_IO_CHANNEL_ERROR,
+				G_IO_CHANNEL_ERROR_FAILED, "Handshake failed");
+		return G_IO_STATUS_ERROR;
+	}
+
+	gnutls_channel->established = true;
+
+	DBG("handshake done");
+
+	return G_IO_STATUS_NORMAL;
+}
+
+static GIOStatus g_io_gnutls_read(GIOChannel *channel, gchar *buf,
+				gsize count, gsize *bytes_read, GError **err)
+{
+	GIOGnuTLSChannel *gnutls_channel = (GIOGnuTLSChannel *) channel;
+	GIOStatus status;
+	ssize_t result;
+
+	DBG("channel %p count %zu", channel, count);
+
+	*bytes_read = 0;
+
+again:
+	status = check_handshake(channel, err);
+	if (status != G_IO_STATUS_NORMAL)
+		return status;
+
+	result = gnutls_record_recv(gnutls_channel->session, buf, count);
+
+	DBG("result %zd", result);
+
+	if (result == GNUTLS_E_REHANDSHAKE) {
+		gnutls_channel->established = false;
+		goto again;
+	}
+
+	if (result == GNUTLS_E_INTERRUPTED || result == GNUTLS_E_AGAIN) {
+		GIOFlags flags = g_io_channel_get_flags(channel);
+
+		if (gnutls_channel->again)
+			return G_IO_STATUS_AGAIN;
+
+		if (flags & G_IO_FLAG_NONBLOCK)
+			return G_IO_STATUS_AGAIN;
+
+		goto again;
+	}
+
+	if (result == GNUTLS_E_UNEXPECTED_PACKET_LENGTH)
+		return G_IO_STATUS_EOF;
+
+	if (result < 0) {
+		g_set_error(err, G_IO_CHANNEL_ERROR,
+				G_IO_CHANNEL_ERROR_FAILED, "Stream corrupted");
+		return G_IO_STATUS_ERROR;
+	}
+
+	*bytes_read = result;
+
+	return (result > 0) ? G_IO_STATUS_NORMAL : G_IO_STATUS_EOF;
+}
+
+static GIOStatus g_io_gnutls_write(GIOChannel *channel, const gchar *buf,
+				gsize count, gsize *bytes_written, GError **err)
+{
+	GIOGnuTLSChannel *gnutls_channel = (GIOGnuTLSChannel *) channel;
+	GIOStatus status;
+	ssize_t result;
+
+	DBG("channel %p count %zu", channel, count);
+
+	*bytes_written = 0;
+
+again:
+	status = check_handshake(channel, err);
+	if (status != G_IO_STATUS_NORMAL)
+		return status;
+
+	result = gnutls_record_send(gnutls_channel->session, buf, count);
+
+	DBG("result %zd", result);
+
+	if (result == GNUTLS_E_REHANDSHAKE) {
+		gnutls_channel->established = false;
+		goto again;
+	}
+
+	if (result == GNUTLS_E_INTERRUPTED || result == GNUTLS_E_AGAIN) {
+		GIOFlags flags = g_io_channel_get_flags(channel);
+
+		if (gnutls_channel->again)
+			return G_IO_STATUS_AGAIN;
+
+		if (flags & G_IO_FLAG_NONBLOCK)
+			return G_IO_STATUS_AGAIN;
+
+		goto again;
+	}
+
+	if (result < 0) {
+		g_set_error(err, G_IO_CHANNEL_ERROR,
+				G_IO_CHANNEL_ERROR_FAILED, "Stream corrupted");
+		return G_IO_STATUS_ERROR;
+        }
+
+	*bytes_written = result;
+
+	return (result > 0) ? G_IO_STATUS_NORMAL : G_IO_STATUS_EOF;
+}
+
+static GIOStatus g_io_gnutls_seek(GIOChannel *channel, gint64 offset,
+						GSeekType type, GError **err)
+{
+	DBG("channel %p", channel);
+
+	g_set_error_literal(err, G_IO_CHANNEL_ERROR,
+				G_IO_CHANNEL_ERROR_FAILED, "Not supported");
+	return G_IO_STATUS_ERROR;
+}
+
+static GIOStatus g_io_gnutls_close(GIOChannel *channel, GError **err)
+{
+	GIOGnuTLSChannel *gnutls_channel = (GIOGnuTLSChannel *) channel;
+
+	DBG("channel %p", channel);
+
+	if (gnutls_channel->established)
+		gnutls_bye(gnutls_channel->session, GNUTLS_SHUT_RDWR);
+
+	if (close(gnutls_channel->fd) < 0) {
+		g_set_error_literal(err, G_IO_CHANNEL_ERROR,
+				G_IO_CHANNEL_ERROR_FAILED, "Closing failed");
+		return G_IO_STATUS_ERROR;
+	}
+
+	return G_IO_STATUS_NORMAL;
+}
+
+static void g_io_gnutls_free(GIOChannel *channel)
+{
+	GIOGnuTLSChannel *gnutls_channel = (GIOGnuTLSChannel *) channel;
+
+	DBG("channel %p", channel);
+
+	gnutls_deinit(gnutls_channel->session);
+
+	gnutls_certificate_free_credentials(gnutls_channel->cred);
+
+	g_free(gnutls_channel);
+}
+
+static GIOStatus g_io_gnutls_set_flags(GIOChannel *channel,
+						GIOFlags flags, GError **err)
+{
+	GIOGnuTLSChannel *gnutls_channel = (GIOGnuTLSChannel *) channel;
+	glong fcntl_flags = 0;
+
+	DBG("channel %p flags %u", channel, flags);
+
+	if (flags & G_IO_FLAG_NONBLOCK)
+		fcntl_flags |= O_NONBLOCK;
+
+	if (fcntl(gnutls_channel->fd, F_SETFL, fcntl_flags) < 0) {
+		g_set_error_literal(err, G_IO_CHANNEL_ERROR,
+			G_IO_CHANNEL_ERROR_FAILED, "Setting flags failed");
+		return G_IO_STATUS_ERROR;
+	}
+
+	return G_IO_STATUS_NORMAL;
+}
+
+static GIOFlags g_io_gnutls_get_flags(GIOChannel *channel)
+{
+	GIOGnuTLSChannel *gnutls_channel = (GIOGnuTLSChannel *) channel;
+	GIOFlags flags = 0;
+	glong fcntl_flags;
+
+	DBG("channel %p", channel);
+
+	fcntl_flags = fcntl(gnutls_channel->fd, F_GETFL);
+	if (fcntl_flags < 0)
+		return 0;
+
+	if (fcntl_flags & O_NONBLOCK)
+		flags |= G_IO_FLAG_NONBLOCK;
+
+	return flags;
+}
+
+static gboolean g_io_gnutls_prepare(GSource *source, gint *timeout)
+{
+	DBG("source %p", source);
+
+	*timeout = -1;
+
+	return FALSE;
+}
+
+static gboolean g_io_gnutls_check(GSource *source)
+{
+	GIOGnuTLSWatch *watch = (GIOGnuTLSWatch *) source;
+	GIOCondition condition = watch->pollfd.revents;
+
+	DBG("source %p condition %u", source, condition);
+
+	if (condition & watch->condition)
+		return TRUE;
+
+	return FALSE;
+}
+
+static gboolean g_io_gnutls_dispatch(GSource *source, GSourceFunc callback,
+							gpointer user_data)
+{
+	GIOGnuTLSWatch *watch = (GIOGnuTLSWatch *) source;
+	GIOFunc func = (GIOFunc) callback;
+	GIOCondition condition = watch->pollfd.revents;
+
+	DBG("source %p condition %u", source, condition);
+
+	if (!func)
+		return FALSE;
+
+	return func(watch->channel, condition & watch->condition, user_data);
+}
+
+static void g_io_gnutls_finalize(GSource *source)
+{
+	GIOGnuTLSWatch *watch = (GIOGnuTLSWatch *) source;
+
+	DBG("source %p", source);
+
+	g_io_channel_unref(watch->channel);
+}
+
+static GSourceFuncs gnutls_watch_funcs = {
+	g_io_gnutls_prepare,
+	g_io_gnutls_check,
+	g_io_gnutls_dispatch,
+	g_io_gnutls_finalize,
+};
+
+static GSource *g_io_gnutls_create_watch(GIOChannel *channel,
+						GIOCondition condition)
+{
+	GIOGnuTLSChannel *gnutls_channel = (GIOGnuTLSChannel *) channel;
+	GIOGnuTLSWatch *watch;
+	GSource *source;
+
+	DBG("channel %p condition %u", channel, condition);
+
+	source = g_source_new(&gnutls_watch_funcs, sizeof(GIOGnuTLSWatch));
+
+	watch = (GIOGnuTLSWatch *) source;
+
+	watch->channel = channel;
+	g_io_channel_ref(channel);
+
+	watch->condition = condition;
+
+	watch->pollfd.fd = gnutls_channel->fd;
+	watch->pollfd.events = condition;
+
+	g_source_add_poll(source, &watch->pollfd);
+
+	return source;
+}
+
+static GIOFuncs gnutls_channel_funcs = {
+	g_io_gnutls_read,
+	g_io_gnutls_write,
+	g_io_gnutls_seek,
+	g_io_gnutls_close,
+	g_io_gnutls_create_watch,
+	g_io_gnutls_free,
+	g_io_gnutls_set_flags,
+	g_io_gnutls_get_flags,
+};
+
+static ssize_t g_io_gnutls_push_func(gnutls_transport_ptr_t transport_data,
+						const void *buf, size_t count)
+{
+	GIOGnuTLSChannel *gnutls_channel = transport_data;
+	ssize_t result;
+
+	DBG("count %zu", count);
+
+	result = write(gnutls_channel->fd, buf, count);
+
+	if (result < 0 && errno == EAGAIN)
+		gnutls_channel->again = true;
+	else
+		gnutls_channel->again = false;
+
+	DBG("result %zd", result);
+
+	return result;
+}
+
+static ssize_t g_io_gnutls_pull_func(gnutls_transport_ptr_t transport_data,
+						void *buf, size_t count)
+{
+	GIOGnuTLSChannel *gnutls_channel = transport_data;
+	ssize_t result;
+
+	DBG("count %zu", count);
+
+	result = read(gnutls_channel->fd, buf, count);
+
+	if (result < 0 && errno == EAGAIN)
+		gnutls_channel->again = true;
+	else
+		gnutls_channel->again = false;
+
+	DBG("result %zd", result);
+
+	return result;
+}
+
+bool g_io_channel_supports_tls(void)
+{
+	return true;
+}
+
+GIOChannel *g_io_channel_gnutls_new(int fd)
+{
+	GIOGnuTLSChannel *gnutls_channel;
+	GIOChannel *channel;
+	int err;
+
+	DBG("");
+
+	gnutls_channel = g_new(GIOGnuTLSChannel, 1);
+
+	channel = (GIOChannel *) gnutls_channel;
+
+	g_io_channel_init(channel);
+	channel->funcs = &gnutls_channel_funcs;
+
+	gnutls_channel->fd = fd;
+
+	channel->is_seekable = FALSE;
+	channel->is_readable = TRUE;
+	channel->is_writeable = TRUE;
+
+	channel->do_encode = FALSE;
+
+	g_io_gnutls_global_init();
+
+        err = gnutls_init(&gnutls_channel->session, GNUTLS_CLIENT);
+	if (err < 0) {
+		g_free(gnutls_channel);
+		return NULL;
+	}
+
+	gnutls_transport_set_ptr(gnutls_channel->session, gnutls_channel);
+        gnutls_transport_set_push_function(gnutls_channel->session,
+						g_io_gnutls_push_func);
+        gnutls_transport_set_pull_function(gnutls_channel->session,
+						g_io_gnutls_pull_func);
+#if GNUTLS_VERSION_NUMBER < 0x020c00
+	gnutls_transport_set_lowat(gnutls_channel->session, 0);
+
+	gnutls_priority_set_direct(gnutls_channel->session,
+						"NORMAL:%COMPAT", NULL);
+#else
+	gnutls_priority_set_direct(gnutls_channel->session,
+		"NORMAL:-VERS-TLS-ALL:+VERS-TLS1.0:+VERS-SSL3.0:%COMPAT", NULL);
+#endif
+
+	gnutls_certificate_allocate_credentials(&gnutls_channel->cred);
+	gnutls_credentials_set(gnutls_channel->session,
+				GNUTLS_CRD_CERTIFICATE, gnutls_channel->cred);
+
+	DBG("channel %p", channel);
+
+	return channel;
+}
diff --git a/connman/gweb/giognutls.h b/connman/gweb/giognutls.h
new file mode 100644
index 0000000..ea0df8f
--- /dev/null
+++ b/connman/gweb/giognutls.h
@@ -0,0 +1,28 @@
+/*
+ *
+ *  Web service library with GLib integration
+ *
+ *  Copyright (C) 2009-2012  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
+ *
+ */
+
+#include <stdbool.h>
+
+#include <glib.h>
+
+bool g_io_channel_supports_tls(void);
+
+GIOChannel *g_io_channel_gnutls_new(int fd);
diff --git a/connman/gweb/gionotls.c b/connman/gweb/gionotls.c
new file mode 100644
index 0000000..2998895
--- /dev/null
+++ b/connman/gweb/gionotls.c
@@ -0,0 +1,36 @@
+/*
+ *
+ *  Web service library with GLib integration
+ *
+ *  Copyright (C) 2009-2012  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 "giognutls.h"
+
+bool g_io_channel_supports_tls(void)
+{
+	return false;
+}
+
+GIOChannel *g_io_channel_gnutls_new(int fd)
+{
+	return NULL;
+}
diff --git a/connman/gweb/gresolv.c b/connman/gweb/gresolv.c
new file mode 100644
index 0000000..5cf7a9a
--- /dev/null
+++ b/connman/gweb/gresolv.c
@@ -0,0 +1,1117 @@
+/*
+ *
+ *  Resolver library with GLib integration
+ *
+ *  Copyright (C) 2009-2013  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 <unistd.h>
+#include <stdarg.h>
+#include <string.h>
+#include <stdlib.h>
+#include <resolv.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netdb.h>
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+#include <net/if.h>
+
+#include "gresolv.h"
+
+struct sort_result {
+	int precedence;
+	int src_scope;
+	int dst_scope;
+	int src_label;
+	int dst_label;
+	bool reachable;
+	union {
+		struct sockaddr sa;
+		struct sockaddr_in sin;
+		struct sockaddr_in6 sin6;
+	} src;
+	union {
+		struct sockaddr sa;
+		struct sockaddr_in sin;
+		struct sockaddr_in6 sin6;
+	} dst;
+};
+
+struct resolv_query;
+
+struct resolv_lookup {
+	GResolv *resolv;
+	guint id;
+
+	int nr_results;
+	struct sort_result *results;
+
+	struct resolv_query *ipv4_query;
+	struct resolv_query *ipv6_query;
+
+	guint ipv4_status;
+	guint ipv6_status;
+
+	GResolvResultFunc result_func;
+	gpointer result_data;
+};
+
+struct resolv_query {
+	GResolv *resolv;
+
+	int nr_ns;
+	guint timeout;
+
+	uint16_t msgid;
+
+	struct resolv_lookup *lookup;
+};
+
+struct resolv_nameserver {
+	GResolv *resolv;
+
+	char *address;
+	uint16_t port;
+	unsigned long flags;
+
+	GIOChannel *udp_channel;
+	guint udp_watch;
+};
+
+struct _GResolv {
+	int ref_count;
+
+	int result_family;
+
+	guint next_lookup_id;
+	GQueue *lookup_queue;
+	GQueue *query_queue;
+
+	int index;
+	GList *nameserver_list;
+
+	struct __res_state res;
+
+	GResolvDebugFunc debug_func;
+	gpointer debug_data;
+};
+
+#define debug(resolv, format, arg...)				\
+	_debug(resolv, __FILE__, __func__, format, ## arg)
+
+static void _debug(GResolv *resolv, const char *file, const char *caller,
+						const char *format, ...)
+{
+	char str[256];
+	va_list ap;
+	int len;
+
+	if (!resolv->debug_func)
+		return;
+
+	va_start(ap, format);
+
+	if ((len = snprintf(str, sizeof(str), "%s:%s() resolv %p ",
+						file, caller, resolv)) > 0) {
+		if (vsnprintf(str + len, sizeof(str) - len, format, ap) > 0)
+			resolv->debug_func(str, resolv->debug_data);
+	}
+
+	va_end(ap);
+}
+
+static void destroy_query(struct resolv_query *query)
+{
+	debug(query->resolv, "query %p timeout %d", query, query->timeout);
+
+	if (query->timeout > 0)
+		g_source_remove(query->timeout);
+
+	g_free(query);
+}
+
+static void destroy_lookup(struct resolv_lookup *lookup)
+{
+	debug(lookup->resolv, "lookup %p id %d ipv4 %p ipv6 %p",
+		lookup, lookup->id, lookup->ipv4_query, lookup->ipv6_query);
+
+	if (lookup->ipv4_query) {
+		g_queue_remove(lookup->resolv->query_queue,
+						lookup->ipv4_query);
+		destroy_query(lookup->ipv4_query);
+	}
+
+	if (lookup->ipv6_query) {
+		g_queue_remove(lookup->resolv->query_queue,
+						lookup->ipv6_query);
+		destroy_query(lookup->ipv6_query);
+	}
+
+	g_free(lookup->results);
+	g_free(lookup);
+}
+
+static void find_srcaddr(struct sort_result *res)
+{
+	socklen_t sl = sizeof(res->src);
+	int fd;
+
+	fd = socket(res->dst.sa.sa_family, SOCK_DGRAM | SOCK_CLOEXEC,
+			IPPROTO_IP);
+	if (fd < 0)
+		return;
+
+	if (connect(fd, &res->dst.sa, sizeof(res->dst)) < 0) {
+		close(fd);
+		return;
+	}
+
+	if (getsockname(fd, &res->src.sa, &sl) < 0) {
+		close(fd);
+		return;
+	}
+
+	res->reachable = true;
+	close(fd);
+}
+
+struct gai_table
+{
+	unsigned char addr[NS_IN6ADDRSZ];
+	int mask;
+	int value;
+};
+
+static const struct gai_table gai_labels[] = {
+	{
+		.addr = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+			  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 },
+		.mask = 128,
+		.value = 0,
+	}, {
+		.addr = { 0x20, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+			  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+		.mask = 16,
+		.value = 2,
+	}, {
+		.addr = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+			  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+		.mask = 96,
+		.value = 3,
+	}, {
+		.addr = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+			  0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 },
+		.mask = 96,
+		.value = 4,
+	}, {
+		/* Variations from RFC 3484, matching glibc behaviour */
+		.addr = { 0xfe, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+			  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+		.mask = 10,
+		.value = 5,
+	}, {
+		.addr = { 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+			  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+		.mask = 7,
+		.value = 6,
+	}, {
+		.addr = { 0x20, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+			  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+		.mask = 32,
+		.value = 7,
+	}, {
+		/* catch-all */
+		.addr = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+			  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+		.mask = 0,
+		.value = 1,
+	}
+};
+
+static const struct gai_table gai_precedences[] = {
+	{
+		.addr = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+			  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 },
+		.mask = 128,
+		.value = 50,
+	}, {
+		.addr = { 0x20, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+			  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+		.mask = 16,
+		.value = 30,
+	}, {
+		.addr = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+			  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+		.mask = 96,
+		.value = 20,
+	}, {
+		.addr = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+			  0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 },
+		.mask = 96,
+		.value = 10,
+	}, {
+		.addr = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+			  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+		.mask = 0,
+		.value = 40,
+	}
+};
+
+static unsigned char v4mapped[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+				    0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 };
+
+static bool mask_compare(const unsigned char *one,
+					const unsigned char *two, int mask)
+{
+	if (mask > 8) {
+		if (memcmp(one, two, mask / 8))
+			return false;
+		one += mask / 8;
+		two += mask / 8;
+		mask %= 8;
+	}
+
+	if (mask && ((*one ^ *two) >> (8 - mask)))
+		return false;
+
+	return true;
+}
+
+static int match_gai_table(struct sockaddr *sa, const struct gai_table *tbl)
+{
+	struct sockaddr_in *sin = (void *)sa;
+	struct sockaddr_in6 *sin6 = (void *)sa;
+	void *addr;
+
+	if (sa->sa_family == AF_INET) {
+		addr = v4mapped;
+		memcpy(v4mapped+12, &sin->sin_addr, NS_INADDRSZ);
+	} else
+		addr = &sin6->sin6_addr;
+
+	while (1) {
+		if (mask_compare(addr, tbl->addr, tbl->mask))
+			return tbl->value;
+		tbl++;
+	}
+}
+
+#define DQUAD(_a,_b,_c,_d) ( ((_a)<<24) | ((_b)<<16) | ((_c)<<8) | (_d) )
+#define V4MATCH(addr, a,b,c,d, m) ( ((addr) ^ DQUAD(a,b,c,d)) >> (32 - (m)) )
+
+#define RFC3484_SCOPE_LINK	2
+#define RFC3484_SCOPE_SITE	5
+#define RFC3484_SCOPE_GLOBAL	14
+
+static int addr_scope(struct sockaddr *sa)
+{
+	if (sa->sa_family == AF_INET) {
+		struct sockaddr_in *sin = (void *)sa;
+		guint32 addr = ntohl(sin->sin_addr.s_addr);
+
+		if (V4MATCH(addr, 169,254,0,0, 16) ||
+					V4MATCH(addr, 127,0,0,0, 8))
+			return RFC3484_SCOPE_LINK;
+
+		/* Site-local */
+		if (V4MATCH(addr, 10,0,0,0, 8) ||
+				V4MATCH(addr, 172,16,0,0, 12) ||
+				V4MATCH(addr, 192,168,0,0, 16))
+			return RFC3484_SCOPE_SITE;
+
+		/* Global */
+		return RFC3484_SCOPE_GLOBAL;
+	} else {
+		struct sockaddr_in6 *sin6 = (void *)sa;
+
+		/* Multicast addresses have a 4-bit scope field */
+		if (IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr))
+			return sin6->sin6_addr.s6_addr[1] & 0xf;
+
+		if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr) ||
+				IN6_IS_ADDR_LOOPBACK(&sin6->sin6_addr))
+			return RFC3484_SCOPE_LINK;
+
+		if (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))
+			return RFC3484_SCOPE_SITE;
+
+		return RFC3484_SCOPE_GLOBAL;
+	}
+}
+
+static int rfc3484_compare(const void *__one, const void *__two)
+{
+	const struct sort_result *one = __one;
+	const struct sort_result *two = __two;
+
+	/* Rule 1: Avoid unusable destinations */
+	if (one->reachable && !two->reachable)
+		return -1;
+	else if (two->reachable && !one->reachable)
+		return 1;
+
+	/* Rule 2: Prefer matching scope */
+	if (one->dst_scope == one->src_scope &&
+				two->dst_scope != two->src_scope)
+		return -1;
+	else if (two->dst_scope == two->src_scope &&
+				one->dst_scope != one->src_scope)
+		return 1;
+
+	/* Rule 3: Avoid deprecated addresses */
+
+	/* Rule 4: Prefer home addresses */
+
+	/* Rule 5: Prefer matching label */
+	if (one->dst_label == one->src_label &&
+				two->dst_label != two->src_label)
+		return -1;
+	else if (two->dst_label == two->src_label &&
+				one->dst_label != one->src_label)
+		return 1;
+
+	/* Rule 6: Prefer higher precedence */
+	if (one->precedence > two->precedence)
+		return -1;
+	else if (two->precedence > one->precedence)
+		return 1;
+
+	/* Rule 7: Prefer native transport */
+
+	/* Rule 8: Prefer smaller scope */
+	if (one->dst_scope != two->dst_scope)
+		return one->dst_scope - two->dst_scope;
+
+	/* Rule 9: Use longest matching prefix */
+	if (one->dst.sa.sa_family == AF_INET) {
+		/*
+		 * Rule 9 is meaningless and counterproductive for Legacy IP
+		 * unless perhaps we can tell that it's actually on the local
+		 * subnet. But we don't (yet) have local interface config
+		 * information, so do nothing here for Legacy IP for now.
+		 */
+	} else {
+		int i;
+
+		for (i = 0; i < 4; i++) {
+			guint32 cmp_one, cmp_two;
+
+			cmp_one = one->src.sin6.sin6_addr.s6_addr32[i] ^
+					one->dst.sin6.sin6_addr.s6_addr32[i];
+			cmp_two = two->src.sin6.sin6_addr.s6_addr32[i] ^
+					two->dst.sin6.sin6_addr.s6_addr32[i];
+
+			if (!cmp_two && !cmp_one)
+				continue;
+
+			if (cmp_one && !cmp_two)
+				return 1;
+			if (cmp_two && !cmp_one)
+				return -1;
+
+			/* g_bit_storage() is effectively fls() */
+			cmp_one = g_bit_storage(ntohl(cmp_one));
+			cmp_two = g_bit_storage(ntohl(cmp_two));
+
+			if (cmp_one == cmp_two)
+				break;
+
+			return cmp_one - cmp_two;
+		}
+	}
+
+
+	/* Rule 10: Otherwise, leave the order unchanged */
+	if (one < two)
+		return -1;
+	else
+		return 1;
+}
+
+static void rfc3484_sort_results(struct resolv_lookup *lookup)
+{
+	int i;
+
+	for (i = 0; i < lookup->nr_results; i++) {
+		struct sort_result *res = &lookup->results[i];
+		find_srcaddr(res);
+		res->precedence = match_gai_table(&res->dst.sa,
+							gai_precedences);
+		res->dst_label = match_gai_table(&res->dst.sa, gai_labels);
+		res->src_label = match_gai_table(&res->src.sa, gai_labels);
+		res->dst_scope = addr_scope(&res->dst.sa);
+		res->src_scope = addr_scope(&res->src.sa);
+	}
+
+	qsort(lookup->results, lookup->nr_results,
+			sizeof(struct sort_result), rfc3484_compare);
+}
+
+static void sort_and_return_results(struct resolv_lookup *lookup)
+{
+	char buf[INET6_ADDRSTRLEN + 1];
+	GResolvResultStatus status;
+	char **results = g_try_new0(char *, lookup->nr_results + 1);
+	GResolvResultFunc result_func = lookup->result_func;
+	void *result_data = lookup->result_data;
+	int i, n = 0;
+
+	if (!results)
+		return;
+
+	memset(buf, 0, INET6_ADDRSTRLEN + 1);
+
+	rfc3484_sort_results(lookup);
+
+	for (i = 0; i < lookup->nr_results; i++) {
+		if (lookup->results[i].dst.sa.sa_family == AF_INET) {
+			if (!inet_ntop(AF_INET,
+					&lookup->results[i].dst.sin.sin_addr,
+					buf, sizeof(buf) - 1))
+				continue;
+		} else if (lookup->results[i].dst.sa.sa_family == AF_INET6) {
+			if (!inet_ntop(AF_INET6,
+					&lookup->results[i].dst.sin6.sin6_addr,
+					buf, sizeof(buf) - 1))
+				continue;
+		} else
+			continue;
+
+		results[n++] = g_strdup(buf);
+	}
+
+	results[n++] = NULL;
+
+	if (lookup->resolv->result_family == AF_INET)
+		status = lookup->ipv4_status;
+	else if (lookup->resolv->result_family == AF_INET6)
+		status = lookup->ipv6_status;
+	else {
+		if (lookup->ipv6_status == G_RESOLV_RESULT_STATUS_SUCCESS)
+			status = lookup->ipv6_status;
+		else
+			status = lookup->ipv4_status;
+	}
+
+	debug(lookup->resolv, "lookup %p received %d results", lookup, n);
+
+	g_queue_remove(lookup->resolv->lookup_queue, lookup);
+	destroy_lookup(lookup);
+
+	result_func(status, results, result_data);
+
+	g_strfreev(results);
+}
+
+static gboolean query_timeout(gpointer user_data)
+{
+	struct resolv_query *query = user_data;
+	struct resolv_lookup *lookup = query->lookup;
+	GResolv *resolv = query->resolv;
+
+	query->timeout = 0;
+
+	if (query == lookup->ipv4_query) {
+		lookup->ipv4_status = G_RESOLV_RESULT_STATUS_NO_RESPONSE;
+		lookup->ipv4_query = NULL;
+	} else if (query == lookup->ipv6_query) {
+		lookup->ipv6_status = G_RESOLV_RESULT_STATUS_NO_RESPONSE;
+		lookup->ipv6_query = NULL;
+	}
+
+	g_queue_remove(resolv->query_queue, query);
+	destroy_query(query);
+
+	if (!lookup->ipv4_query && !lookup->ipv6_query)
+		sort_and_return_results(lookup);
+
+	return FALSE;
+}
+
+static void free_nameserver(struct resolv_nameserver *nameserver)
+{
+	if (!nameserver)
+		return;
+
+	if (nameserver->udp_watch > 0)
+		g_source_remove(nameserver->udp_watch);
+
+	if (nameserver->udp_channel) {
+		g_io_channel_shutdown(nameserver->udp_channel, TRUE, NULL);
+		g_io_channel_unref(nameserver->udp_channel);
+	}
+
+	g_free(nameserver->address);
+	g_free(nameserver);
+}
+
+static void flush_nameservers(GResolv *resolv)
+{
+	GList *list;
+
+	for (list = g_list_first(resolv->nameserver_list);
+					list; list = g_list_next(list))
+		free_nameserver(list->data);
+
+	g_list_free(resolv->nameserver_list);
+	resolv->nameserver_list = NULL;
+}
+
+static int send_query(GResolv *resolv, const unsigned char *buf, int len)
+{
+	GList *list;
+	int nr_ns;
+
+	if (!resolv->nameserver_list)
+		return -ENOENT;
+
+	for (list = g_list_first(resolv->nameserver_list), nr_ns = 0;
+				list; list = g_list_next(list), nr_ns++) {
+		struct resolv_nameserver *nameserver = list->data;
+		int sk, sent;
+
+		if (!nameserver->udp_channel)
+			continue;
+
+		sk = g_io_channel_unix_get_fd(nameserver->udp_channel);
+
+		sent = send(sk, buf, len, 0);
+		if (sent < 0)
+			continue;
+	}
+
+	return nr_ns;
+}
+
+static gint compare_lookup_id(gconstpointer a, gconstpointer b)
+{
+	const struct resolv_lookup *lookup = a;
+	guint id = GPOINTER_TO_UINT(b);
+
+	if (lookup->id < id)
+		return -1;
+
+	if (lookup->id > id)
+		return 1;
+
+	return 0;
+}
+
+static gint compare_query_msgid(gconstpointer a, gconstpointer b)
+{
+	const struct resolv_query *query = a;
+	uint16_t msgid = GPOINTER_TO_UINT(b);
+
+	if (query->msgid < msgid)
+		return -1;
+
+	if (query->msgid > msgid)
+		return 1;
+
+	return 0;
+}
+
+static void add_result(struct resolv_lookup *lookup, int family,
+							const void *data)
+{
+	int n = lookup->nr_results++;
+	lookup->results = g_try_realloc(lookup->results,
+					sizeof(struct sort_result) * (n + 1));
+	if (!lookup->results)
+		return;
+
+	memset(&lookup->results[n], 0, sizeof(struct sort_result));
+
+	lookup->results[n].dst.sa.sa_family = family;
+	if (family == AF_INET)
+		memcpy(&lookup->results[n].dst.sin.sin_addr,
+						data, NS_INADDRSZ);
+	else
+		memcpy(&lookup->results[n].dst.sin6.sin6_addr,
+						data, NS_IN6ADDRSZ);
+}
+
+static void parse_response(struct resolv_nameserver *nameserver,
+					const unsigned char *buf, int len)
+{
+	GResolv *resolv = nameserver->resolv;
+	GResolvResultStatus status;
+	struct resolv_query *query;
+	struct resolv_lookup *lookup;
+	GList *list;
+	ns_msg msg;
+	ns_rr rr;
+	int i, rcode, count;
+
+	debug(resolv, "response from %s", nameserver->address);
+
+	if (ns_initparse(buf, len, &msg) < 0)
+		return;
+
+	list = g_queue_find_custom(resolv->query_queue,
+			GUINT_TO_POINTER(ns_msg_id(msg)), compare_query_msgid);
+	if (!list)
+		return;
+
+	rcode = ns_msg_getflag(msg, ns_f_rcode);
+	count = ns_msg_count(msg, ns_s_an);
+
+	debug(resolv, "msg id: 0x%04x rcode: %d count: %d",
+					ns_msg_id(msg), rcode, count);
+
+	switch (rcode) {
+	case ns_r_noerror:
+		status = G_RESOLV_RESULT_STATUS_SUCCESS;
+		break;
+	case ns_r_formerr:
+		status = G_RESOLV_RESULT_STATUS_FORMAT_ERROR;
+		break;
+	case ns_r_servfail:
+		status = G_RESOLV_RESULT_STATUS_SERVER_FAILURE;
+		break;
+	case ns_r_nxdomain:
+		status = G_RESOLV_RESULT_STATUS_NAME_ERROR;
+		break;
+	case ns_r_notimpl:
+		status = G_RESOLV_RESULT_STATUS_NOT_IMPLEMENTED;
+		break;
+	case ns_r_refused:
+		status = G_RESOLV_RESULT_STATUS_REFUSED;
+		break;
+	default:
+		status = G_RESOLV_RESULT_STATUS_ERROR;
+		break;
+	}
+
+	query = list->data;
+	query->nr_ns--;
+
+	lookup = query->lookup;
+
+	if (query == lookup->ipv6_query)
+		lookup->ipv6_status = status;
+	else if (query == lookup->ipv4_query)
+		lookup->ipv4_status = status;
+
+	for (i = 0; i < count; i++) {
+		if (ns_parserr(&msg, ns_s_an, i, &rr) < 0)
+			continue;
+
+		if (ns_rr_class(rr) != ns_c_in)
+			continue;
+
+		g_assert(offsetof(struct sockaddr_in, sin_addr) ==
+				offsetof(struct sockaddr_in6, sin6_flowinfo));
+
+		if (ns_rr_type(rr) == ns_t_a &&
+					ns_rr_rdlen(rr) == NS_INADDRSZ) {
+			add_result(lookup, AF_INET, ns_rr_rdata(rr));
+		} else if (ns_rr_type(rr) == ns_t_aaaa &&
+					ns_rr_rdlen(rr) == NS_IN6ADDRSZ) {
+			add_result(lookup, AF_INET6, ns_rr_rdata(rr));
+		}
+	}
+
+	if (status != G_RESOLV_RESULT_STATUS_SUCCESS && query->nr_ns > 0)
+		return;
+
+	if (query == lookup->ipv6_query)
+		lookup->ipv6_query = NULL;
+	else
+		lookup->ipv4_query = NULL;
+
+	g_queue_remove(resolv->query_queue, query);
+	destroy_query(query);
+
+	if (!lookup->ipv4_query && !lookup->ipv6_query)
+		sort_and_return_results(lookup);
+}
+
+static gboolean received_udp_data(GIOChannel *channel, GIOCondition cond,
+							gpointer user_data)
+{
+	struct resolv_nameserver *nameserver = user_data;
+	unsigned char buf[4096];
+	int sk, len;
+
+	if (cond & (G_IO_NVAL | G_IO_ERR | G_IO_HUP)) {
+		nameserver->udp_watch = 0;
+		return FALSE;
+	}
+
+	sk = g_io_channel_unix_get_fd(nameserver->udp_channel);
+
+	len = recv(sk, buf, sizeof(buf), 0);
+	if (len < 12)
+		return TRUE;
+
+	parse_response(nameserver, buf, len);
+
+	return TRUE;
+}
+
+static int connect_udp_channel(struct resolv_nameserver *nameserver)
+{
+	struct addrinfo hints, *rp;
+	char portnr[6];
+	int err, sk;
+
+	memset(&hints, 0, sizeof(hints));
+	hints.ai_family = AF_UNSPEC;
+	hints.ai_socktype = SOCK_DGRAM;
+	hints.ai_flags = AI_PASSIVE | AI_NUMERICSERV | AI_NUMERICHOST;
+
+	sprintf(portnr, "%d", nameserver->port);
+	err = getaddrinfo(nameserver->address, portnr, &hints, &rp);
+	if (err)
+		return -EINVAL;
+
+	/*
+	 * Do not blindly copy this code elsewhere; it doesn't loop over the
+	 * results using ->ai_next as it should. That's OK in *this* case
+	 * because it was a numeric lookup; we *know* there's only one.
+	 */
+	if (!rp)
+		return -EINVAL;
+
+	sk = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
+	if (sk < 0) {
+		freeaddrinfo(rp);
+		return -EIO;
+	}
+
+	/*
+	 * If nameserver points to localhost ip, their is no need to
+	 * bind the socket on any interface.
+	 */
+	if (nameserver->resolv->index > 0 &&
+			strncmp(nameserver->address, "127.0.0.1", 9) != 0) {
+		char interface[IF_NAMESIZE];
+
+		memset(interface, 0, IF_NAMESIZE);
+		if (if_indextoname(nameserver->resolv->index, interface)) {
+			if (setsockopt(sk, SOL_SOCKET, SO_BINDTODEVICE,
+						interface, IF_NAMESIZE) < 0) {
+				close(sk);
+				freeaddrinfo(rp);
+				return -EIO;
+			}
+		}
+	}
+
+	if (connect(sk, rp->ai_addr, rp->ai_addrlen) < 0) {
+		close(sk);
+		freeaddrinfo(rp);
+		return -EIO;
+	}
+
+	freeaddrinfo(rp);
+
+	nameserver->udp_channel = g_io_channel_unix_new(sk);
+	if (!nameserver->udp_channel) {
+		close(sk);
+		return -ENOMEM;
+	}
+
+	g_io_channel_set_close_on_unref(nameserver->udp_channel, TRUE);
+
+	nameserver->udp_watch = g_io_add_watch(nameserver->udp_channel,
+				G_IO_IN | G_IO_NVAL | G_IO_ERR | G_IO_HUP,
+				received_udp_data, nameserver);
+
+	return 0;
+}
+
+GResolv *g_resolv_new(int index)
+{
+	GResolv *resolv;
+
+	if (index < 0)
+		return NULL;
+
+	resolv = g_try_new0(GResolv, 1);
+	if (!resolv)
+		return NULL;
+
+	resolv->ref_count = 1;
+
+	resolv->result_family = AF_UNSPEC;
+
+	resolv->next_lookup_id = 1;
+
+	resolv->query_queue = g_queue_new();
+	if (!resolv->query_queue) {
+		g_free(resolv);
+		return NULL;
+	}
+
+	resolv->lookup_queue = g_queue_new();
+	if (!resolv->lookup_queue) {
+		g_queue_free(resolv->query_queue);
+		g_free(resolv);
+		return NULL;
+	}
+
+	resolv->index = index;
+	resolv->nameserver_list = NULL;
+
+	res_ninit(&resolv->res);
+
+	return resolv;
+}
+
+GResolv *g_resolv_ref(GResolv *resolv)
+{
+	if (!resolv)
+		return NULL;
+
+	__sync_fetch_and_add(&resolv->ref_count, 1);
+
+	return resolv;
+}
+
+void g_resolv_unref(GResolv *resolv)
+{
+	struct resolv_query *query;
+	struct resolv_lookup *lookup;
+
+	if (!resolv)
+		return;
+
+	if (__sync_fetch_and_sub(&resolv->ref_count, 1) != 1)
+		return;
+
+	while ((lookup = g_queue_pop_head(resolv->lookup_queue))) {
+		debug(resolv, "lookup %p id %d", lookup, lookup->id);
+		destroy_lookup(lookup);
+	}
+
+	while ((query = g_queue_pop_head(resolv->query_queue))) {
+		debug(resolv, "query %p", query);
+		destroy_query(query);
+	}
+
+	g_queue_free(resolv->query_queue);
+	g_queue_free(resolv->lookup_queue);
+
+	flush_nameservers(resolv);
+
+	res_nclose(&resolv->res);
+
+	g_free(resolv);
+}
+
+void g_resolv_set_debug(GResolv *resolv, GResolvDebugFunc func,
+						gpointer user_data)
+{
+	if (!resolv)
+		return;
+
+	resolv->debug_func = func;
+	resolv->debug_data = user_data;
+}
+
+bool g_resolv_add_nameserver(GResolv *resolv, const char *address,
+					uint16_t port, unsigned long flags)
+{
+	struct resolv_nameserver *nameserver;
+
+	if (!resolv)
+		return false;
+
+	nameserver = g_try_new0(struct resolv_nameserver, 1);
+	if (!nameserver)
+		return false;
+
+	nameserver->address = g_strdup(address);
+	nameserver->port = port;
+	nameserver->flags = flags;
+	nameserver->resolv = resolv;
+
+	if (connect_udp_channel(nameserver) < 0) {
+		free_nameserver(nameserver);
+		return false;
+	}
+
+	resolv->nameserver_list = g_list_append(resolv->nameserver_list,
+								nameserver);
+
+	debug(resolv, "setting nameserver %s", address);
+
+	return true;
+}
+
+void g_resolv_flush_nameservers(GResolv *resolv)
+{
+	if (!resolv)
+		return;
+
+	flush_nameservers(resolv);
+}
+
+static gint add_query(struct resolv_lookup *lookup, const char *hostname, int type)
+{
+	struct resolv_query *query = g_try_new0(struct resolv_query, 1);
+	unsigned char buf[4096];
+	int len;
+
+	if (!query)
+		return -ENOMEM;
+
+	len = res_mkquery(ns_o_query, hostname, ns_c_in, type,
+					NULL, 0, NULL, buf, sizeof(buf));
+
+	query->msgid = buf[0] << 8 | buf[1];
+
+	debug(lookup->resolv, "sending %d bytes", len);
+
+	query->nr_ns = send_query(lookup->resolv, buf, len);
+	if (query->nr_ns <= 0) {
+		g_free(query);
+		return -EIO;
+	}
+
+	query->resolv = lookup->resolv;
+	query->lookup = lookup;
+
+	g_queue_push_tail(lookup->resolv->query_queue, query);
+
+	debug(lookup->resolv, "lookup %p id %d query %p", lookup, lookup->id,
+									query);
+
+	query->timeout = g_timeout_add_seconds(5, query_timeout, query);
+
+	if (type == ns_t_aaaa)
+		lookup->ipv6_query = query;
+	else
+		lookup->ipv4_query = query;
+
+	return 0;
+}
+
+guint g_resolv_lookup_hostname(GResolv *resolv, const char *hostname,
+				GResolvResultFunc func, gpointer user_data)
+{
+	struct resolv_lookup *lookup;
+
+	if (!resolv)
+		return 0;
+
+	debug(resolv, "hostname %s", hostname);
+
+	if (!resolv->nameserver_list) {
+		int i;
+
+		for (i = 0; i < resolv->res.nscount; i++) {
+			char buf[100];
+			int family = resolv->res.nsaddr_list[i].sin_family;
+			void *sa_addr = &resolv->res.nsaddr_list[i].sin_addr;
+
+			if (family != AF_INET &&
+					resolv->res._u._ext.nsaddrs[i]) {
+				family = AF_INET6;
+				sa_addr = &resolv->res._u._ext.nsaddrs[i]->sin6_addr;
+			}
+
+			if (family != AF_INET && family != AF_INET6)
+				continue;
+
+			if (inet_ntop(family, sa_addr, buf, sizeof(buf)))
+				g_resolv_add_nameserver(resolv, buf, 53, 0);
+		}
+
+		if (!resolv->nameserver_list)
+			g_resolv_add_nameserver(resolv, "127.0.0.1", 53, 0);
+	}
+
+	lookup = g_try_new0(struct resolv_lookup, 1);
+	if (!lookup)
+		return 0;
+
+	lookup->resolv = resolv;
+	lookup->result_func = func;
+	lookup->result_data = user_data;
+	lookup->id = resolv->next_lookup_id++;
+
+	if (resolv->result_family != AF_INET6) {
+		if (add_query(lookup, hostname, ns_t_a)) {
+			g_free(lookup);
+			return -EIO;
+		}
+	}
+
+	if (resolv->result_family != AF_INET) {
+		if (add_query(lookup, hostname, ns_t_aaaa)) {
+			if (resolv->result_family != AF_INET6) {
+				g_queue_remove(resolv->query_queue,
+						lookup->ipv4_query);
+				destroy_query(lookup->ipv4_query);
+			}
+
+			g_free(lookup);
+			return -EIO;
+		}
+	}
+
+	g_queue_push_tail(resolv->lookup_queue, lookup);
+
+	debug(resolv, "lookup %p id %d", lookup, lookup->id);
+
+	return lookup->id;
+}
+
+bool g_resolv_cancel_lookup(GResolv *resolv, guint id)
+{
+	struct resolv_lookup *lookup;
+	GList *list;
+
+	debug(resolv, "lookup id %d", id);
+
+	list = g_queue_find_custom(resolv->lookup_queue,
+				GUINT_TO_POINTER(id), compare_lookup_id);
+
+	if (!list)
+		return false;
+
+	lookup = list->data;
+
+	debug(resolv, "lookup %p", lookup);
+
+	g_queue_remove(resolv->lookup_queue, lookup);
+	destroy_lookup(lookup);
+
+	return true;
+}
+
+bool g_resolv_set_address_family(GResolv *resolv, int family)
+{
+	if (!resolv)
+		return false;
+
+	if (family != AF_UNSPEC && family != AF_INET && family != AF_INET6)
+		return false;
+
+	resolv->result_family = family;
+
+	return true;
+}
diff --git a/connman/gweb/gresolv.h b/connman/gweb/gresolv.h
new file mode 100644
index 0000000..fac14f5
--- /dev/null
+++ b/connman/gweb/gresolv.h
@@ -0,0 +1,77 @@
+/*
+ *
+ *  Resolver library with GLib integration
+ *
+ *  Copyright (C) 2009-2012  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 __G_RESOLV_H
+#define __G_RESOLV_H
+
+#include <stdbool.h>
+#include <stdint.h>
+
+#include <glib.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct _GResolv;
+
+typedef struct _GResolv GResolv;
+
+typedef enum {
+	G_RESOLV_RESULT_STATUS_SUCCESS,
+	G_RESOLV_RESULT_STATUS_ERROR,
+	G_RESOLV_RESULT_STATUS_NO_RESPONSE,
+	G_RESOLV_RESULT_STATUS_FORMAT_ERROR,
+	G_RESOLV_RESULT_STATUS_SERVER_FAILURE,
+	G_RESOLV_RESULT_STATUS_NAME_ERROR,
+	G_RESOLV_RESULT_STATUS_NOT_IMPLEMENTED,
+	G_RESOLV_RESULT_STATUS_REFUSED,
+} GResolvResultStatus;
+
+typedef void (*GResolvResultFunc)(GResolvResultStatus status,
+					char **results, gpointer user_data);
+
+typedef void (*GResolvDebugFunc)(const char *str, gpointer user_data);
+
+GResolv *g_resolv_new(int index);
+
+GResolv *g_resolv_ref(GResolv *resolv);
+void g_resolv_unref(GResolv *resolv);
+
+void g_resolv_set_debug(GResolv *resolv,
+				GResolvDebugFunc func, gpointer user_data);
+
+bool g_resolv_add_nameserver(GResolv *resolv, const char *address,
+					uint16_t port, unsigned long flags);
+void g_resolv_flush_nameservers(GResolv *resolv);
+
+guint g_resolv_lookup_hostname(GResolv *resolv, const char *hostname,
+				GResolvResultFunc func, gpointer user_data);
+
+bool g_resolv_cancel_lookup(GResolv *resolv, guint id);
+
+bool g_resolv_set_address_family(GResolv *resolv, int family);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __G_RESOLV_H */
diff --git a/connman/gweb/gweb.c b/connman/gweb/gweb.c
new file mode 100644
index 0000000..f6828cf
--- /dev/null
+++ b/connman/gweb/gweb.c
@@ -0,0 +1,1600 @@
+/*
+ *
+ *  Web service library with GLib integration
+ *
+ *  Copyright (C) 2009-2013  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 <stdio.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+#include <sys/socket.h>
+#include <sys/sendfile.h>
+#include <sys/stat.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+#include <net/if.h>
+#include <netinet/tcp.h>
+#include <ifaddrs.h>
+
+#include "giognutls.h"
+#include "gresolv.h"
+#include "gweb.h"
+
+#define DEFAULT_BUFFER_SIZE  2048
+
+#define SESSION_FLAG_USE_TLS	(1 << 0)
+
+enum chunk_state {
+	CHUNK_SIZE,
+	CHUNK_R_BODY,
+	CHUNK_N_BODY,
+	CHUNK_DATA,
+};
+
+struct _GWebResult {
+	guint16 status;
+	const guint8 *buffer;
+	gsize length;
+	bool use_chunk;
+	gchar *last_key;
+	GHashTable *headers;
+};
+
+struct web_session {
+	GWeb *web;
+
+	char *address;
+	char *host;
+	uint16_t port;
+	unsigned long flags;
+	struct addrinfo *addr;
+
+	char *content_type;
+
+	GIOChannel *transport_channel;
+	guint transport_watch;
+	guint send_watch;
+
+	guint resolv_action;
+	guint address_action;
+	char *request;
+
+	guint8 *receive_buffer;
+	gsize receive_space;
+	GString *send_buffer;
+	GString *current_header;
+	bool header_done;
+	bool body_done;
+	bool more_data;
+	bool request_started;
+
+	enum chunk_state chunck_state;
+	gsize chunk_size;
+	gsize chunk_left;
+	gsize total_len;
+
+	GWebResult result;
+
+	GWebResultFunc result_func;
+	GWebRouteFunc route_func;
+	GWebInputFunc input_func;
+	int fd;
+	gsize length;
+	gsize offset;
+	gpointer user_data;
+};
+
+struct _GWeb {
+	int ref_count;
+
+	guint next_query_id;
+
+	int family;
+
+	int index;
+	GList *session_list;
+
+	GResolv *resolv;
+	char *proxy;
+	char *accept_option;
+	char *user_agent;
+	char *user_agent_profile;
+	char *http_version;
+	bool close_connection;
+
+	GWebDebugFunc debug_func;
+	gpointer debug_data;
+};
+
+#define debug(web, format, arg...)				\
+	_debug(web, __FILE__, __func__, format, ## arg)
+
+static void _debug(GWeb *web, const char *file, const char *caller,
+						const char *format, ...)
+{
+	char str[256];
+	va_list ap;
+	int len;
+
+	if (!web->debug_func)
+		return;
+
+	va_start(ap, format);
+
+	if ((len = snprintf(str, sizeof(str), "%s:%s() web %p ",
+						file, caller, web)) > 0) {
+		if (vsnprintf(str + len, sizeof(str) - len, format, ap) > 0)
+			web->debug_func(str, web->debug_data);
+	}
+
+	va_end(ap);
+}
+
+static void free_session(struct web_session *session)
+{
+	GWeb *web;
+
+	if (!session)
+		return;
+
+	g_free(session->request);
+
+	web = session->web;
+
+	if (session->address_action > 0)
+		g_source_remove(session->address_action);
+
+	if (session->resolv_action > 0)
+		g_resolv_cancel_lookup(web->resolv, session->resolv_action);
+
+	if (session->transport_watch > 0)
+		g_source_remove(session->transport_watch);
+
+	if (session->send_watch > 0)
+		g_source_remove(session->send_watch);
+
+	if (session->transport_channel)
+		g_io_channel_unref(session->transport_channel);
+
+	g_free(session->result.last_key);
+
+	if (session->result.headers)
+		g_hash_table_destroy(session->result.headers);
+
+	if (session->send_buffer)
+		g_string_free(session->send_buffer, TRUE);
+
+	if (session->current_header)
+		g_string_free(session->current_header, TRUE);
+
+	g_free(session->receive_buffer);
+
+	g_free(session->content_type);
+
+	g_free(session->host);
+	g_free(session->address);
+	if (session->addr)
+		freeaddrinfo(session->addr);
+
+	g_free(session);
+}
+
+static void flush_sessions(GWeb *web)
+{
+	GList *list;
+
+	for (list = g_list_first(web->session_list);
+					list; list = g_list_next(list))
+		free_session(list->data);
+
+	g_list_free(web->session_list);
+	web->session_list = NULL;
+}
+
+GWeb *g_web_new(int index)
+{
+	GWeb *web;
+
+	if (index < 0)
+		return NULL;
+
+	web = g_try_new0(GWeb, 1);
+	if (!web)
+		return NULL;
+
+	web->ref_count = 1;
+
+	web->next_query_id = 1;
+
+	web->family = AF_UNSPEC;
+
+	web->index = index;
+	web->session_list = NULL;
+
+	web->resolv = g_resolv_new(index);
+	if (!web->resolv) {
+		g_free(web);
+		return NULL;
+	}
+
+	web->accept_option = g_strdup("*/*");
+	web->user_agent = g_strdup_printf("GWeb/%s", VERSION);
+	web->close_connection = false;
+
+	return web;
+}
+
+GWeb *g_web_ref(GWeb *web)
+{
+	if (!web)
+		return NULL;
+
+	__sync_fetch_and_add(&web->ref_count, 1);
+
+	return web;
+}
+
+void g_web_unref(GWeb *web)
+{
+	if (!web)
+		return;
+
+	if (__sync_fetch_and_sub(&web->ref_count, 1) != 1)
+		return;
+
+	flush_sessions(web);
+
+	g_resolv_unref(web->resolv);
+
+	g_free(web->proxy);
+
+	g_free(web->accept_option);
+	g_free(web->user_agent);
+	g_free(web->user_agent_profile);
+	g_free(web->http_version);
+
+	g_free(web);
+}
+
+bool g_web_supports_tls(void)
+{
+	return g_io_channel_supports_tls();
+}
+
+void g_web_set_debug(GWeb *web, GWebDebugFunc func, gpointer user_data)
+{
+	if (!web)
+		return;
+
+	web->debug_func = func;
+	web->debug_data = user_data;
+
+	g_resolv_set_debug(web->resolv, func, user_data);
+}
+
+bool g_web_set_proxy(GWeb *web, const char *proxy)
+{
+	if (!web)
+		return false;
+
+	g_free(web->proxy);
+
+	if (!proxy) {
+		web->proxy = NULL;
+		debug(web, "clearing proxy");
+	} else {
+		web->proxy = g_strdup(proxy);
+		debug(web, "setting proxy %s", web->proxy);
+	}
+
+	return true;
+}
+
+bool g_web_set_address_family(GWeb *web, int family)
+{
+	if (!web)
+		return false;
+
+	if (family != AF_UNSPEC && family != AF_INET && family != AF_INET6)
+		return false;
+
+	web->family = family;
+
+	g_resolv_set_address_family(web->resolv, family);
+
+	return true;
+}
+
+bool g_web_add_nameserver(GWeb *web, const char *address)
+{
+	if (!web)
+		return false;
+
+	g_resolv_add_nameserver(web->resolv, address, 53, 0);
+
+	return true;
+}
+
+static bool set_accept_option(GWeb *web, const char *format, va_list args)
+{
+	g_free(web->accept_option);
+
+	if (!format) {
+		web->accept_option = NULL;
+		debug(web, "clearing accept option");
+	} else {
+		web->accept_option = g_strdup_vprintf(format, args);
+		debug(web, "setting accept %s", web->accept_option);
+	}
+
+	return true;
+}
+
+bool g_web_set_accept(GWeb *web, const char *format, ...)
+{
+	va_list args;
+	bool result;
+
+	if (!web)
+		return false;
+
+	va_start(args, format);
+	result = set_accept_option(web, format, args);
+	va_end(args);
+
+	return result;
+}
+
+static bool set_user_agent(GWeb *web, const char *format, va_list args)
+{
+	g_free(web->user_agent);
+
+	if (!format) {
+		web->user_agent = NULL;
+		debug(web, "clearing user agent");
+	} else {
+		web->user_agent = g_strdup_vprintf(format, args);
+		debug(web, "setting user agent %s", web->user_agent);
+	}
+
+	return true;
+}
+
+bool g_web_set_user_agent(GWeb *web, const char *format, ...)
+{
+	va_list args;
+	bool result;
+
+	if (!web)
+		return false;
+
+	va_start(args, format);
+	result = set_user_agent(web, format, args);
+	va_end(args);
+
+	return result;
+}
+
+bool g_web_set_ua_profile(GWeb *web, const char *profile)
+{
+	if (!web)
+		return false;
+
+	g_free(web->user_agent_profile);
+
+	web->user_agent_profile = g_strdup(profile);
+	debug(web, "setting user agent profile %s", web->user_agent);
+
+	return true;
+}
+
+bool g_web_set_http_version(GWeb *web, const char *version)
+{
+	if (!web)
+		return false;
+
+	g_free(web->http_version);
+
+	if (!version) {
+		web->http_version = NULL;
+		debug(web, "clearing HTTP version");
+	} else {
+		web->http_version = g_strdup(version);
+		debug(web, "setting HTTP version %s", web->http_version);
+	}
+
+	return true;
+}
+
+void g_web_set_close_connection(GWeb *web, bool enabled)
+{
+	if (!web)
+		return;
+
+	web->close_connection = enabled;
+}
+
+bool g_web_get_close_connection(GWeb *web)
+{
+	if (!web)
+		return false;
+
+	return web->close_connection;
+}
+
+static inline void call_result_func(struct web_session *session, guint16 status)
+{
+
+	if (!session->result_func)
+		return;
+
+	if (status != 0)
+		session->result.status = status;
+
+	session->result_func(&session->result, session->user_data);
+
+}
+
+static inline void call_route_func(struct web_session *session)
+{
+	if (session->route_func)
+		session->route_func(session->address, session->addr->ai_family,
+				session->web->index, session->user_data);
+}
+
+static bool process_send_buffer(struct web_session *session)
+{
+	GString *buf;
+	gsize count, bytes_written;
+	GIOStatus status;
+
+	if (!session)
+		return false;
+
+	buf = session->send_buffer;
+	count = buf->len;
+
+	if (count == 0) {
+		if (session->request_started &&
+					!session->more_data &&
+					session->fd == -1)
+			session->body_done = true;
+
+		return false;
+	}
+
+	status = g_io_channel_write_chars(session->transport_channel,
+					buf->str, count, &bytes_written, NULL);
+
+	debug(session->web, "status %u bytes to write %zu bytes written %zu",
+					status, count, bytes_written);
+
+	if (status != G_IO_STATUS_NORMAL && status != G_IO_STATUS_AGAIN)
+		return false;
+
+	g_string_erase(buf, 0, bytes_written);
+
+	return true;
+}
+
+static bool process_send_file(struct web_session *session)
+{
+	int sk;
+	off_t offset;
+	ssize_t bytes_sent;
+
+	if (session->fd == -1)
+		return false;
+
+	if (!session->request_started || session->more_data)
+		return false;
+
+	sk = g_io_channel_unix_get_fd(session->transport_channel);
+	if (sk < 0)
+		return false;
+
+	offset = session->offset;
+
+	bytes_sent = sendfile(sk, session->fd, &offset, session->length);
+
+	debug(session->web, "errno: %d, bytes to send %zu / bytes sent %zu",
+			errno, session->length, bytes_sent);
+
+	if (bytes_sent < 0 && errno != EAGAIN)
+		return false;
+
+	session->offset = offset;
+	session->length -= bytes_sent;
+
+	if (session->length == 0) {
+		session->body_done = true;
+		return false;
+	}
+
+	return true;
+}
+
+static void process_next_chunk(struct web_session *session)
+{
+	GString *buf = session->send_buffer;
+	const guint8 *body;
+	gsize length;
+
+	if (!session->input_func) {
+		session->more_data = false;
+		return;
+	}
+
+	session->more_data = session->input_func(&body, &length,
+						session->user_data);
+
+	if (length > 0) {
+		g_string_append_printf(buf, "%zx\r\n", length);
+		g_string_append_len(buf, (char *) body, length);
+		g_string_append(buf, "\r\n");
+	}
+
+	if (!session->more_data)
+		g_string_append(buf, "0\r\n\r\n");
+}
+
+static void start_request(struct web_session *session)
+{
+	GString *buf = session->send_buffer;
+	const char *version;
+	const guint8 *body;
+	gsize length;
+
+	debug(session->web, "request %s from %s",
+					session->request, session->host);
+
+	g_string_truncate(buf, 0);
+
+	if (!session->web->http_version)
+		version = "1.1";
+	else
+		version = session->web->http_version;
+
+	if (!session->content_type)
+		g_string_append_printf(buf, "GET %s HTTP/%s\r\n",
+						session->request, version);
+	else
+		g_string_append_printf(buf, "POST %s HTTP/%s\r\n",
+						session->request, version);
+
+	g_string_append_printf(buf, "Host: %s\r\n", session->host);
+
+	if (session->web->user_agent)
+		g_string_append_printf(buf, "User-Agent: %s\r\n",
+						session->web->user_agent);
+
+	if (session->web->user_agent_profile) {
+		g_string_append_printf(buf, "x-wap-profile: %s\r\n",
+				       session->web->user_agent_profile);
+	}
+
+	if (session->web->accept_option)
+		g_string_append_printf(buf, "Accept: %s\r\n",
+						session->web->accept_option);
+
+	if (session->content_type) {
+		g_string_append_printf(buf, "Content-Type: %s\r\n",
+							session->content_type);
+		if (!session->input_func) {
+			session->more_data = false;
+			length = session->length;
+		} else
+			session->more_data = session->input_func(&body, &length,
+							session->user_data);
+		if (!session->more_data)
+			g_string_append_printf(buf, "Content-Length: %zu\r\n",
+									length);
+		else
+			g_string_append(buf, "Transfer-Encoding: chunked\r\n");
+	}
+
+	if (session->web->close_connection)
+		g_string_append(buf, "Connection: close\r\n");
+
+	g_string_append(buf, "\r\n");
+
+	if (session->content_type && length > 0) {
+		if (session->more_data) {
+			g_string_append_printf(buf, "%zx\r\n", length);
+			g_string_append_len(buf, (char *) body, length);
+			g_string_append(buf, "\r\n");
+		} else if (session->fd == -1)
+			g_string_append_len(buf, (char *) body, length);
+	}
+}
+
+static gboolean send_data(GIOChannel *channel, GIOCondition cond,
+						gpointer user_data)
+{
+	struct web_session *session = user_data;
+
+	if (cond & (G_IO_NVAL | G_IO_ERR | G_IO_HUP)) {
+		session->send_watch = 0;
+		return FALSE;
+	}
+
+	if (process_send_buffer(session))
+		return TRUE;
+
+	if (process_send_file(session))
+		return TRUE;
+
+	if (!session->request_started) {
+		session->request_started = true;
+		start_request(session);
+	} else if (session->more_data)
+		process_next_chunk(session);
+
+	process_send_buffer(session);
+
+	if (session->body_done) {
+		session->send_watch = 0;
+		return FALSE;
+	}
+
+	return TRUE;
+}
+
+static int decode_chunked(struct web_session *session,
+					const guint8 *buf, gsize len)
+{
+	const guint8 *ptr = buf;
+	gsize counter;
+
+	while (len > 0) {
+		guint8 *pos;
+		gsize count;
+		char *str;
+
+		switch (session->chunck_state) {
+		case CHUNK_SIZE:
+			pos = memchr(ptr, '\n', len);
+			if (!pos) {
+				g_string_append_len(session->current_header,
+						(gchar *) ptr, len);
+				return 0;
+			}
+
+			count = pos - ptr;
+			if (count < 1 || ptr[count - 1] != '\r')
+				return -EILSEQ;
+
+			g_string_append_len(session->current_header,
+						(gchar *) ptr, count);
+
+			len -= count + 1;
+			ptr = pos + 1;
+
+			str = session->current_header->str;
+
+			counter = strtoul(str, NULL, 16);
+			if ((counter == 0 && errno == EINVAL) ||
+						counter == ULONG_MAX)
+				return -EILSEQ;
+
+			session->chunk_size = counter;
+			session->chunk_left = counter;
+
+			session->chunck_state = CHUNK_DATA;
+			break;
+		case CHUNK_R_BODY:
+			if (*ptr != '\r')
+				return -EILSEQ;
+			ptr++;
+			len--;
+			session->chunck_state = CHUNK_N_BODY;
+			break;
+		case CHUNK_N_BODY:
+			if (*ptr != '\n')
+				return -EILSEQ;
+			ptr++;
+			len--;
+			session->chunck_state = CHUNK_SIZE;
+			break;
+		case CHUNK_DATA:
+			if (session->chunk_size == 0) {
+				debug(session->web, "Download Done in chunk");
+				g_string_truncate(session->current_header, 0);
+				return 0;
+			}
+
+			if (session->chunk_left <= len) {
+				session->result.buffer = ptr;
+				session->result.length = session->chunk_left;
+				call_result_func(session, 0);
+
+				len -= session->chunk_left;
+				ptr += session->chunk_left;
+
+				session->total_len += session->chunk_left;
+				session->chunk_left = 0;
+
+				g_string_truncate(session->current_header, 0);
+				session->chunck_state = CHUNK_R_BODY;
+				break;
+			}
+			/* more data */
+			session->result.buffer = ptr;
+			session->result.length = len;
+			call_result_func(session, 0);
+
+			session->chunk_left -= len;
+			session->total_len += len;
+
+			len -= len;
+			ptr += len;
+			break;
+		}
+	}
+
+	return 0;
+}
+
+static int handle_body(struct web_session *session,
+				const guint8 *buf, gsize len)
+{
+	int err;
+
+	debug(session->web, "[body] length %zu", len);
+
+	if (!session->result.use_chunk) {
+		if (len > 0) {
+			session->result.buffer = buf;
+			session->result.length = len;
+			call_result_func(session, 0);
+		}
+		return 0;
+	}
+
+	err = decode_chunked(session, buf, len);
+	if (err < 0) {
+		debug(session->web, "Error in chunk decode %d", err);
+
+		session->result.buffer = NULL;
+		session->result.length = 0;
+		call_result_func(session, 400);
+	}
+
+	return err;
+}
+
+static void handle_multi_line(struct web_session *session)
+{
+	gsize count;
+	char *str;
+	gchar *value;
+
+	str = session->current_header->str;
+
+	if (str[0] != ' ' && str[0] != '\t')
+		return;
+
+	while (str[0] == ' ' || str[0] == '\t')
+		str++;
+
+	count = str - session->current_header->str;
+	if (count > 0) {
+		g_string_erase(session->current_header, 0, count);
+		g_string_insert_c(session->current_header, 0, ' ');
+	}
+
+	value = g_hash_table_lookup(session->result.headers,
+					session->result.last_key);
+	if (value) {
+		g_string_insert(session->current_header, 0, value);
+
+		str = session->current_header->str;
+
+		g_hash_table_replace(session->result.headers,
+					g_strdup(session->result.last_key),
+					g_strdup(str));
+	}
+}
+
+static void add_header_field(struct web_session *session)
+{
+	gsize count;
+	guint8 *pos;
+	char *str;
+	gchar *value;
+	gchar *key;
+
+	str = session->current_header->str;
+
+	pos = memchr(str, ':', session->current_header->len);
+	if (pos) {
+		*pos = '\0';
+		pos++;
+
+		key = g_strdup(str);
+
+		/* remove preceding white spaces */
+		while (*pos == ' ')
+			pos++;
+
+		count = (char *) pos - str;
+
+		g_string_erase(session->current_header, 0, count);
+
+		value = g_hash_table_lookup(session->result.headers, key);
+		if (value) {
+			g_string_insert_c(session->current_header, 0, ' ');
+			g_string_insert_c(session->current_header, 0, ';');
+
+			g_string_insert(session->current_header, 0, value);
+		}
+
+		str = session->current_header->str;
+		g_hash_table_replace(session->result.headers, key,
+							g_strdup(str));
+
+		g_free(session->result.last_key);
+		session->result.last_key = g_strdup(key);
+	}
+}
+
+static gboolean received_data(GIOChannel *channel, GIOCondition cond,
+							gpointer user_data)
+{
+	struct web_session *session = user_data;
+	guint8 *ptr = session->receive_buffer;
+	gsize bytes_read;
+	GIOStatus status;
+
+	if (cond & (G_IO_NVAL | G_IO_ERR | G_IO_HUP)) {
+		session->transport_watch = 0;
+		session->result.buffer = NULL;
+		session->result.length = 0;
+		call_result_func(session, 400);
+		return FALSE;
+	}
+
+	status = g_io_channel_read_chars(channel,
+				(gchar *) session->receive_buffer,
+				session->receive_space - 1, &bytes_read, NULL);
+
+	debug(session->web, "bytes read %zu", bytes_read);
+
+	if (status != G_IO_STATUS_NORMAL && status != G_IO_STATUS_AGAIN) {
+		session->transport_watch = 0;
+		session->result.buffer = NULL;
+		session->result.length = 0;
+		call_result_func(session, 0);
+		return FALSE;
+	}
+
+	session->receive_buffer[bytes_read] = '\0';
+
+	if (session->header_done) {
+		if (handle_body(session, session->receive_buffer,
+							bytes_read) < 0) {
+			session->transport_watch = 0;
+			return FALSE;
+		}
+		return TRUE;
+	}
+
+	while (bytes_read > 0) {
+		guint8 *pos;
+		gsize count;
+		char *str;
+
+		pos = memchr(ptr, '\n', bytes_read);
+		if (!pos) {
+			g_string_append_len(session->current_header,
+						(gchar *) ptr, bytes_read);
+			return TRUE;
+		}
+
+		*pos = '\0';
+		count = strlen((char *) ptr);
+		if (count > 0 && ptr[count - 1] == '\r') {
+			ptr[--count] = '\0';
+			bytes_read--;
+		}
+
+		g_string_append_len(session->current_header,
+						(gchar *) ptr, count);
+
+		bytes_read -= count + 1;
+		if (bytes_read > 0)
+			ptr = pos + 1;
+		else
+			ptr = NULL;
+
+		if (session->current_header->len == 0) {
+			char *val;
+
+			session->header_done = true;
+
+			val = g_hash_table_lookup(session->result.headers,
+							"Transfer-Encoding");
+			if (val) {
+				val = g_strrstr(val, "chunked");
+				if (val) {
+					session->result.use_chunk = true;
+
+					session->chunck_state = CHUNK_SIZE;
+					session->chunk_left = 0;
+					session->total_len = 0;
+				}
+			}
+
+			if (handle_body(session, ptr, bytes_read) < 0) {
+				session->transport_watch = 0;
+				return FALSE;
+			}
+			break;
+		}
+
+		str = session->current_header->str;
+
+		if (session->result.status == 0) {
+			unsigned int code;
+
+			if (sscanf(str, "HTTP/%*s %u %*s", &code) == 1)
+				session->result.status = code;
+		}
+
+		debug(session->web, "[header] %s", str);
+
+		/* handle multi-line header */
+		if (str[0] == ' ' || str[0] == '\t')
+			handle_multi_line(session);
+		else
+			add_header_field(session);
+
+		g_string_truncate(session->current_header, 0);
+	}
+
+	return TRUE;
+}
+
+static int bind_to_address(int sk, const char *interface, int family)
+{
+	struct ifaddrs *ifaddr_list, *ifaddr;
+	int size, err = -1;
+
+	if (getifaddrs(&ifaddr_list) < 0)
+		return err;
+
+	for (ifaddr = ifaddr_list; ifaddr; ifaddr = ifaddr->ifa_next) {
+		if (g_strcmp0(ifaddr->ifa_name, interface) != 0)
+			continue;
+
+		if (!ifaddr->ifa_addr ||
+				ifaddr->ifa_addr->sa_family != family)
+			continue;
+
+		switch (family) {
+		case AF_INET:
+			size = sizeof(struct sockaddr_in);
+			break;
+		case AF_INET6:
+			size = sizeof(struct sockaddr_in6);
+			break;
+		default:
+			continue;
+		}
+
+		err = bind(sk, (struct sockaddr *) ifaddr->ifa_addr, size);
+		break;
+	}
+
+	freeifaddrs(ifaddr_list);
+	return err;
+}
+
+static inline int bind_socket(int sk, int index, int family)
+{
+	char interface[IF_NAMESIZE];
+	int err;
+
+	if (!if_indextoname(index, interface))
+		return -1;
+
+	err = setsockopt(sk, SOL_SOCKET, SO_BINDTODEVICE,
+					interface, IF_NAMESIZE);
+	if (err < 0)
+		err = bind_to_address(sk, interface, family);
+
+	return err;
+}
+
+static int connect_session_transport(struct web_session *session)
+{
+	GIOFlags flags;
+	int sk;
+
+	sk = socket(session->addr->ai_family, SOCK_STREAM | SOCK_CLOEXEC,
+			IPPROTO_TCP);
+	if (sk < 0)
+		return -EIO;
+
+	if (session->web->index > 0) {
+		if (bind_socket(sk, session->web->index,
+					session->addr->ai_family) < 0) {
+			debug(session->web, "bind() %s", strerror(errno));
+			close(sk);
+			return -EIO;
+		}
+	}
+
+	if (session->flags & SESSION_FLAG_USE_TLS) {
+		debug(session->web, "using TLS encryption");
+		session->transport_channel = g_io_channel_gnutls_new(sk);
+	} else {
+		debug(session->web, "no encryption");
+		session->transport_channel = g_io_channel_unix_new(sk);
+	}
+
+	if (!session->transport_channel) {
+		debug(session->web, "channel missing");
+		close(sk);
+		return -ENOMEM;
+	}
+
+	flags = g_io_channel_get_flags(session->transport_channel);
+	g_io_channel_set_flags(session->transport_channel,
+					flags | G_IO_FLAG_NONBLOCK, NULL);
+
+	g_io_channel_set_encoding(session->transport_channel, NULL, NULL);
+	g_io_channel_set_buffered(session->transport_channel, FALSE);
+
+	g_io_channel_set_close_on_unref(session->transport_channel, TRUE);
+
+	if (connect(sk, session->addr->ai_addr,
+			session->addr->ai_addrlen) < 0) {
+		if (errno != EINPROGRESS) {
+			debug(session->web, "connect() %s", strerror(errno));
+			close(sk);
+			return -EIO;
+		}
+	}
+
+	session->transport_watch = g_io_add_watch(session->transport_channel,
+				G_IO_IN | G_IO_HUP | G_IO_NVAL | G_IO_ERR,
+						received_data, session);
+
+	session->send_watch = g_io_add_watch(session->transport_channel,
+				G_IO_OUT | G_IO_HUP | G_IO_NVAL | G_IO_ERR,
+						send_data, session);
+
+	return 0;
+}
+
+static int create_transport(struct web_session *session)
+{
+	int err;
+
+	err = connect_session_transport(session);
+	if (err < 0)
+		return err;
+
+	debug(session->web, "creating session %s:%u",
+					session->address, session->port);
+
+	return 0;
+}
+
+static int parse_url(struct web_session *session,
+				const char *url, const char *proxy)
+{
+	char *scheme, *host, *port, *path;
+
+	scheme = g_strdup(url);
+	if (!scheme)
+		return -EINVAL;
+
+	host = strstr(scheme, "://");
+	if (host) {
+		*host = '\0';
+		host += 3;
+
+		if (strcasecmp(scheme, "https") == 0) {
+			session->port = 443;
+			session->flags |= SESSION_FLAG_USE_TLS;
+		} else if (strcasecmp(scheme, "http") == 0) {
+			session->port = 80;
+		} else {
+			g_free(scheme);
+			return -EINVAL;
+		}
+	} else {
+		host = scheme;
+		session->port = 80;
+	}
+
+	path = strchr(host, '/');
+	if (path)
+		*(path++) = '\0';
+
+	if (!proxy)
+		session->request = g_strdup_printf("/%s", path ? path : "");
+	else
+		session->request = g_strdup(url);
+
+	port = strrchr(host, ':');
+	if (port) {
+		char *end;
+		int tmp = strtol(port + 1, &end, 10);
+
+		if (*end == '\0') {
+			*port = '\0';
+			session->port = tmp;
+		}
+
+		if (!proxy)
+			session->host = g_strdup(host);
+		else
+			session->host = g_strdup_printf("%s:%u", host, tmp);
+	} else
+		session->host = g_strdup(host);
+
+	g_free(scheme);
+
+	if (!proxy)
+		return 0;
+
+	scheme = g_strdup(proxy);
+	if (!scheme)
+		return -EINVAL;
+
+	host = strstr(proxy, "://");
+	if (host) {
+		*host = '\0';
+		host += 3;
+
+		if (strcasecmp(scheme, "http") != 0) {
+			g_free(scheme);
+			return -EINVAL;
+		}
+	} else
+		host = scheme;
+
+	path = strchr(host, '/');
+	if (path)
+		*(path++) = '\0';
+
+	port = strrchr(host, ':');
+	if (port) {
+		char *end;
+		int tmp = strtol(port + 1, &end, 10);
+
+		if (*end == '\0') {
+			*port = '\0';
+			session->port = tmp;
+		}
+	}
+
+	session->address = g_strdup(host);
+
+	g_free(scheme);
+
+	return 0;
+}
+
+static void handle_resolved_address(struct web_session *session)
+{
+	struct addrinfo hints;
+	char *port;
+	int ret;
+
+	debug(session->web, "address %s", session->address);
+
+	memset(&hints, 0, sizeof(struct addrinfo));
+	hints.ai_flags = AI_NUMERICHOST;
+	hints.ai_family = session->web->family;
+
+	if (session->addr) {
+		freeaddrinfo(session->addr);
+		session->addr = NULL;
+	}
+
+	port = g_strdup_printf("%u", session->port);
+	ret = getaddrinfo(session->address, port, &hints, &session->addr);
+	g_free(port);
+	if (ret != 0 || !session->addr) {
+		call_result_func(session, 400);
+		return;
+	}
+
+	call_route_func(session);
+
+	if (create_transport(session) < 0) {
+		call_result_func(session, 409);
+		return;
+	}
+}
+
+static gboolean already_resolved(gpointer data)
+{
+	struct web_session *session = data;
+
+	session->address_action = 0;
+	handle_resolved_address(session);
+
+	return FALSE;
+}
+
+static void resolv_result(GResolvResultStatus status,
+					char **results, gpointer user_data)
+{
+	struct web_session *session = user_data;
+
+	if (!results || !results[0]) {
+		call_result_func(session, 404);
+		return;
+	}
+
+	g_free(session->address);
+	session->address = g_strdup(results[0]);
+
+	handle_resolved_address(session);
+}
+
+static bool is_ip_address(const char *host)
+{
+	struct addrinfo hints;
+	struct addrinfo *addr;
+	int result;
+
+	memset(&hints, 0, sizeof(struct addrinfo));
+	hints.ai_flags = AI_NUMERICHOST;
+	addr = NULL;
+
+	result = getaddrinfo(host, NULL, &hints, &addr);
+	freeaddrinfo(addr);
+
+	return result == 0;
+}
+
+static guint do_request(GWeb *web, const char *url,
+				const char *type, GWebInputFunc input,
+				int fd, gsize length, GWebResultFunc func,
+				GWebRouteFunc route, gpointer user_data)
+{
+	struct web_session *session;
+	const gchar *host;
+
+	if (!web || !url)
+		return 0;
+
+	debug(web, "request %s", url);
+
+	session = g_try_new0(struct web_session, 1);
+	if (!session)
+		return 0;
+
+	if (parse_url(session, url, web->proxy) < 0) {
+		free_session(session);
+		return 0;
+	}
+
+	debug(web, "proxy host %s", session->address);
+	debug(web, "port %u", session->port);
+	debug(web, "host %s", session->host);
+	debug(web, "flags %lu", session->flags);
+	debug(web, "request %s", session->request);
+
+	if (type) {
+		session->content_type = g_strdup(type);
+
+		debug(web, "content-type %s", session->content_type);
+	}
+
+	session->web = web;
+
+	session->result_func = func;
+	session->route_func = route;
+	session->input_func = input;
+	session->fd = fd;
+	session->length = length;
+	session->offset = 0;
+	session->user_data = user_data;
+
+	session->receive_buffer = g_try_malloc(DEFAULT_BUFFER_SIZE);
+	if (!session->receive_buffer) {
+		free_session(session);
+		return 0;
+	}
+
+	session->result.headers = g_hash_table_new_full(g_str_hash, g_str_equal,
+							g_free, g_free);
+	if (!session->result.headers) {
+		free_session(session);
+		return 0;
+	}
+
+	session->receive_space = DEFAULT_BUFFER_SIZE;
+	session->send_buffer = g_string_sized_new(0);
+	session->current_header = g_string_sized_new(0);
+	session->header_done = false;
+	session->body_done = false;
+
+	host = session->address ? session->address : session->host;
+	if (is_ip_address(host)) {
+		if (session->address != host) {
+			g_free(session->address);
+			session->address = g_strdup(host);
+		}
+		session->address_action = g_timeout_add(0, already_resolved,
+							session);
+	} else {
+		session->resolv_action = g_resolv_lookup_hostname(web->resolv,
+					host, resolv_result, session);
+		if (session->resolv_action == 0) {
+			free_session(session);
+			return 0;
+		}
+	}
+
+	web->session_list = g_list_append(web->session_list, session);
+
+	return web->next_query_id++;
+}
+
+guint g_web_request_get(GWeb *web, const char *url, GWebResultFunc func,
+		GWebRouteFunc route, gpointer user_data)
+{
+	return do_request(web, url, NULL, NULL, -1, 0, func, route, user_data);
+}
+
+guint g_web_request_post(GWeb *web, const char *url,
+				const char *type, GWebInputFunc input,
+				GWebResultFunc func, gpointer user_data)
+{
+	return do_request(web, url, type, input, -1, 0, func, NULL, user_data);
+}
+
+guint g_web_request_post_file(GWeb *web, const char *url,
+				const char *type, const char *file,
+				GWebResultFunc func, gpointer user_data)
+{
+	struct stat st;
+	int fd;
+	guint ret;
+
+	if (stat(file, &st) < 0)
+		return 0;
+
+	fd = open(file, O_RDONLY);
+	if (fd < 0)
+		return 0;
+
+	ret = do_request(web, url, type, NULL, fd, st.st_size, func, NULL,
+			user_data);
+	if (ret == 0)
+		close(fd);
+
+	return ret;
+}
+
+bool g_web_cancel_request(GWeb *web, guint id)
+{
+	if (!web)
+		return false;
+
+	return true;
+}
+
+guint16 g_web_result_get_status(GWebResult *result)
+{
+	if (!result)
+		return 0;
+
+	return result->status;
+}
+
+bool g_web_result_get_chunk(GWebResult *result,
+				const guint8 **chunk, gsize *length)
+{
+	if (!result)
+		return false;
+
+	if (!chunk)
+		return false;
+
+	*chunk = result->buffer;
+
+	if (length)
+		*length = result->length;
+
+	return true;
+}
+
+bool g_web_result_get_header(GWebResult *result,
+				const char *header, const char **value)
+{
+	if (!result)
+		return false;
+
+	if (!value)
+		return false;
+
+	*value = g_hash_table_lookup(result->headers, header);
+
+	if (!*value)
+		return false;
+
+	return true;
+}
+
+struct _GWebParser {
+	gint ref_count;
+	char *begin_token;
+	char *end_token;
+	const char *token_str;
+	size_t token_len;
+	size_t token_pos;
+	bool intoken;
+	GString *content;
+	GWebParserFunc func;
+	gpointer user_data;
+};
+
+GWebParser *g_web_parser_new(const char *begin, const char *end,
+				GWebParserFunc func, gpointer user_data)
+{
+	GWebParser *parser;
+
+	parser = g_try_new0(GWebParser, 1);
+	if (!parser)
+		return NULL;
+
+	parser->ref_count = 1;
+
+	parser->begin_token = g_strdup(begin);
+	parser->end_token = g_strdup(end);
+
+	if (!parser->begin_token) {
+		g_free(parser);
+		return NULL;
+	}
+
+	parser->func = func;
+	parser->user_data = user_data;
+
+	parser->token_str = parser->begin_token;
+	parser->token_len = strlen(parser->token_str);
+	parser->token_pos = 0;
+
+	parser->intoken = false;
+	parser->content = g_string_sized_new(0);
+
+	return parser;
+}
+
+GWebParser *g_web_parser_ref(GWebParser *parser)
+{
+	if (!parser)
+		return NULL;
+
+	__sync_fetch_and_add(&parser->ref_count, 1);
+
+	return parser;
+}
+
+void g_web_parser_unref(GWebParser *parser)
+{
+	if (!parser)
+		return;
+
+	if (__sync_fetch_and_sub(&parser->ref_count, 1) != 1)
+		return;
+
+	g_string_free(parser->content, TRUE);
+
+	g_free(parser->begin_token);
+	g_free(parser->end_token);
+	g_free(parser);
+}
+
+void g_web_parser_feed_data(GWebParser *parser,
+				const guint8 *data, gsize length)
+{
+	const guint8 *ptr = data;
+
+	if (!parser)
+		return;
+
+	while (length > 0) {
+		guint8 chr = parser->token_str[parser->token_pos];
+
+		if (parser->token_pos == 0) {
+			guint8 *pos;
+
+			pos = memchr(ptr, chr, length);
+			if (!pos) {
+				if (parser->intoken)
+					g_string_append_len(parser->content,
+							(gchar *) ptr, length);
+				break;
+			}
+
+			if (parser->intoken)
+				g_string_append_len(parser->content,
+						(gchar *) ptr, (pos - ptr) + 1);
+
+			length -= (pos - ptr) + 1;
+			ptr = pos + 1;
+
+			parser->token_pos++;
+			continue;
+		}
+
+		if (parser->intoken)
+			g_string_append_c(parser->content, ptr[0]);
+
+		if (ptr[0] != chr) {
+			length--;
+			ptr++;
+
+			parser->token_pos = 0;
+			continue;
+		}
+
+		length--;
+		ptr++;
+
+		parser->token_pos++;
+
+		if (parser->token_pos == parser->token_len) {
+			if (!parser->intoken) {
+				g_string_append(parser->content,
+							parser->token_str);
+
+				parser->intoken = true;
+				parser->token_str = parser->end_token;
+				parser->token_len = strlen(parser->end_token);
+				parser->token_pos = 0;
+			} else {
+				char *str;
+				str = g_string_free(parser->content, FALSE);
+				parser->content = g_string_sized_new(0);
+				if (parser->func)
+					parser->func(str, parser->user_data);
+				g_free(str);
+
+				parser->intoken = false;
+				parser->token_str = parser->begin_token;
+				parser->token_len = strlen(parser->begin_token);
+				parser->token_pos = 0;
+			}
+		}
+	}
+}
+
+void g_web_parser_end_data(GWebParser *parser)
+{
+	if (!parser)
+		return;
+}
diff --git a/connman/gweb/gweb.h b/connman/gweb/gweb.h
new file mode 100644
index 0000000..6c28542
--- /dev/null
+++ b/connman/gweb/gweb.h
@@ -0,0 +1,113 @@
+/*
+ *
+ *  Web service library with GLib integration
+ *
+ *  Copyright (C) 2009-2012  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 __G_WEB_H
+#define __G_WEB_H
+
+#include <stdbool.h>
+#include <stdint.h>
+
+#include <glib.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct _GWeb;
+struct _GWebResult;
+struct _GWebParser;
+
+typedef struct _GWeb GWeb;
+typedef struct _GWebResult GWebResult;
+typedef struct _GWebParser GWebParser;
+
+typedef bool (*GWebResultFunc)(GWebResult *result, gpointer user_data);
+
+typedef bool (*GWebRouteFunc)(const char *addr, int ai_family,
+		int if_index, gpointer user_data);
+
+typedef bool (*GWebInputFunc)(const guint8 **data, gsize *length,
+							gpointer user_data);
+
+typedef void (*GWebDebugFunc)(const char *str, gpointer user_data);
+
+GWeb *g_web_new(int index);
+
+GWeb *g_web_ref(GWeb *web);
+void g_web_unref(GWeb *web);
+
+void g_web_set_debug(GWeb *web, GWebDebugFunc func, gpointer user_data);
+
+bool g_web_supports_tls(void);
+
+bool g_web_set_proxy(GWeb *web, const char *proxy);
+
+bool g_web_set_address_family(GWeb *web, int family);
+
+bool g_web_add_nameserver(GWeb *web, const char *address);
+
+bool g_web_set_accept(GWeb *web, const char *format, ...)
+				__attribute__((format(printf, 2, 3)));
+bool g_web_set_user_agent(GWeb *web, const char *format, ...)
+				__attribute__((format(printf, 2, 3)));
+bool g_web_set_ua_profile(GWeb *web, const char *profile);
+
+bool g_web_set_http_version(GWeb *web, const char *version);
+
+void g_web_set_close_connection(GWeb *web, bool enabled);
+bool g_web_get_close_connection(GWeb *web);
+
+guint g_web_request_get(GWeb *web, const char *url,
+				GWebResultFunc func, GWebRouteFunc route,
+				gpointer user_data);
+guint g_web_request_post(GWeb *web, const char *url,
+				const char *type, GWebInputFunc input,
+				GWebResultFunc func, gpointer user_data);
+guint g_web_request_post_file(GWeb *web, const char *url,
+				const char *type, const char *file,
+				GWebResultFunc func, gpointer user_data);
+
+bool g_web_cancel_request(GWeb *web, guint id);
+
+guint16 g_web_result_get_status(GWebResult *result);
+
+bool g_web_result_get_header(GWebResult *result,
+				const char *header, const char **value);
+bool g_web_result_get_chunk(GWebResult *result,
+				const guint8 **chunk, gsize *length);
+
+typedef void (*GWebParserFunc)(const char *str, gpointer user_data);
+
+GWebParser *g_web_parser_new(const char *begin, const char *end,
+				GWebParserFunc func, gpointer user_data);
+
+GWebParser *g_web_parser_ref(GWebParser *parser);
+void g_web_parser_unref(GWebParser *parser);
+
+void g_web_parser_feed_data(GWebParser *parser,
+				const guint8 *data, gsize length);
+void g_web_parser_end_data(GWebParser *parser);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __G_WEB_H */
diff --git a/connman/include/agent.h b/connman/include/agent.h
new file mode 100644
index 0000000..6961f7a
--- /dev/null
+++ b/connman/include/agent.h
@@ -0,0 +1,82 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2012-2013  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 __CONNMAN_AGENT_H
+#define __CONNMAN_AGENT_H
+
+#include <stdbool.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * SECTION:agent
+ * @title: agent primitives
+ * @short_description: Functions for handling generic agent details
+ */
+
+struct connman_agent;
+
+struct connman_agent_driver {
+	const char *name;
+	const char *interface;
+	int priority;
+	int (*probe) (struct connman_agent *agent);
+	void (*remove) (struct connman_agent *agent);
+	void * (*context_ref) (void *user_context);
+	void (*context_unref) (void *user_context);
+};
+
+int connman_agent_driver_register(struct connman_agent_driver *driver);
+void connman_agent_driver_unregister(struct connman_agent_driver *driver);
+
+typedef void (* report_error_cb_t) (void *user_context,
+				bool retry, void *user_data);
+
+int connman_agent_report_error_full(void *user_context, const char *path,
+				const char *method, const char *error,
+				report_error_cb_t callback,
+				const char *dbus_sender, void *user_data);
+int connman_agent_report_error(void *user_context, const char *path,
+				const char *error,
+				report_error_cb_t callback,
+				const char *dbus_sender, void *user_data);
+
+int connman_agent_register(const char *sender, const char *path);
+int connman_agent_unregister(const char *sender, const char *path);
+void connman_agent_cancel(void *user_context);
+
+typedef void (*agent_queue_cb)(DBusMessage *reply, void *user_data);
+
+int connman_agent_queue_message(void *user_context,
+				DBusMessage *msg, int timeout,
+				agent_queue_cb callback, void *user_data,
+				void *agent_data);
+
+void *connman_agent_get_info(const char *dbus_sender, const char **sender,
+							const char **path);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CONNMAN_TECHNOLOGY_H */
diff --git a/connman/include/dbus.h b/connman/include/dbus.h
new file mode 100644
index 0000000..26f94d6
--- /dev/null
+++ b/connman/include/dbus.h
@@ -0,0 +1,198 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2012  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 __CONNMAN_DBUS_H
+#define __CONNMAN_DBUS_H
+
+#include <dbus/dbus.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#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_CLOCK_INTERFACE		CONNMAN_SERVICE ".Clock"
+#define CONNMAN_TASK_INTERFACE		CONNMAN_SERVICE ".Task"
+#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"
+#define CONNMAN_PEER_INTERFACE		CONNMAN_SERVICE ".Peer"
+
+#define CONNMAN_PRIVILEGE_MODIFY	1
+#define CONNMAN_PRIVILEGE_SECRET	2
+
+typedef void (* connman_dbus_append_cb_t) (DBusMessageIter *iter,
+							void *user_data);
+
+DBusConnection *connman_dbus_get_connection(void);
+
+void connman_dbus_property_append_basic(DBusMessageIter *iter,
+					const char *key, int type, void *val);
+void connman_dbus_property_append_dict(DBusMessageIter *iter, const char *key,
+			connman_dbus_append_cb_t function, void *user_data);
+void connman_dbus_property_append_array(DBusMessageIter *iter,
+						const char *key, int type,
+			connman_dbus_append_cb_t function, void *user_data);
+void connman_dbus_property_append_fixed_array(DBusMessageIter *iter,
+				const char *key, int type, void *val, int len);
+
+dbus_bool_t connman_dbus_property_changed_basic(const char *path,
+				const char *interface, const char *key,
+							int type, void *val);
+dbus_bool_t connman_dbus_property_changed_dict(const char *path,
+				const char *interface, const char *key,
+			connman_dbus_append_cb_t function, void *user_data);
+dbus_bool_t connman_dbus_property_changed_array(const char *path,
+			const char *interface, const char *key, int type,
+			connman_dbus_append_cb_t function, void *user_data);
+
+dbus_bool_t connman_dbus_setting_changed_basic(const char *owner,
+				const char *path, const char *key,
+				int type, void *val);
+dbus_bool_t connman_dbus_setting_changed_dict(const char *owner,
+				const char *path, const char *key,
+				connman_dbus_append_cb_t function,
+				void *user_data);
+dbus_bool_t connman_dbus_setting_changed_array(const char *owner,
+				const char *path, const char *key, int type,
+				connman_dbus_append_cb_t function,
+				void *user_data);
+
+static inline void connman_dbus_dict_open(DBusMessageIter *iter,
+							DBusMessageIter *dict)
+{
+	dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY,
+			DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+			DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
+			DBUS_DICT_ENTRY_END_CHAR_AS_STRING, dict);
+}
+
+static inline void connman_dbus_dict_open_variant(DBusMessageIter *iter,
+							DBusMessageIter *dict)
+{
+	dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
+			DBUS_TYPE_ARRAY_AS_STRING
+			DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+			DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
+			DBUS_DICT_ENTRY_END_CHAR_AS_STRING, dict);
+}
+
+static inline void connman_dbus_array_open(DBusMessageIter *iter,
+							DBusMessageIter *dict)
+{
+	dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
+			DBUS_TYPE_ARRAY_AS_STRING
+			DBUS_TYPE_STRING_AS_STRING,
+			dict);
+}
+
+static inline void connman_dbus_dict_close(DBusMessageIter *iter,
+							DBusMessageIter *dict)
+{
+	dbus_message_iter_close_container(iter, dict);
+}
+
+static inline void connman_dbus_dict_append_basic(DBusMessageIter *dict,
+					const char *key, int type, void *val)
+{
+	DBusMessageIter entry;
+
+	dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
+								NULL, &entry);
+	connman_dbus_property_append_basic(&entry, key, type, val);
+	dbus_message_iter_close_container(dict, &entry);
+}
+
+static inline void connman_dbus_dict_append_dict(DBusMessageIter *dict,
+			const char *key, connman_dbus_append_cb_t function,
+							void *user_data)
+{
+	DBusMessageIter entry;
+
+	dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
+								NULL, &entry);
+	connman_dbus_property_append_dict(&entry, key, function, user_data);
+	dbus_message_iter_close_container(dict, &entry);
+}
+
+static inline void connman_dbus_dict_append_array(DBusMessageIter *dict,
+		const char *key, int type, connman_dbus_append_cb_t function,
+							void *user_data)
+{
+	DBusMessageIter entry;
+
+	dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
+								NULL, &entry);
+	connman_dbus_property_append_array(&entry, key,
+						type, function, user_data);
+	dbus_message_iter_close_container(dict, &entry);
+}
+
+static inline void connman_dbus_dict_append_fixed_array(DBusMessageIter *dict,
+				const char *key, int type, void *val, int len)
+{
+	DBusMessageIter entry;
+
+	dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
+								NULL, &entry);
+	connman_dbus_property_append_fixed_array(&entry, key, type, val, len);
+	dbus_message_iter_close_container(dict, &entry);
+}
+
+dbus_bool_t connman_dbus_validate_ident(const char *ident);
+char *connman_dbus_encode_string(const char *value);
+
+typedef void (* connman_dbus_get_connection_unix_user_cb_t) (unsigned int uid,
+						void *user_data, int err);
+
+int connman_dbus_get_connection_unix_user(DBusConnection *connection,
+                               const char *bus_name,
+                               connman_dbus_get_connection_unix_user_cb_t func,
+                               void *user_data);
+
+typedef void (* connman_dbus_get_context_cb_t) (const unsigned char *context,
+						void *user_data, int err);
+
+int connman_dbus_get_selinux_context(DBusConnection *connection,
+                               const char *service,
+                               connman_dbus_get_context_cb_t func,
+                               void *user_data);
+
+void connman_dbus_reply_pending(DBusMessage *pending,
+					int error, const char *path);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CONNMAN_DBUS_H */
diff --git a/connman/include/device.h b/connman/include/device.h
new file mode 100644
index 0000000..c6bc47c
--- /dev/null
+++ b/connman/include/device.h
@@ -0,0 +1,143 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2014  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 __CONNMAN_DEVICE_H
+#define __CONNMAN_DEVICE_H
+
+#include <connman/network.h>
+#include <connman/service.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * SECTION:device
+ * @title: Device premitives
+ * @short_description: Functions for handling devices
+ */
+
+enum connman_device_type {
+	CONNMAN_DEVICE_TYPE_UNKNOWN   = 0,
+	CONNMAN_DEVICE_TYPE_ETHERNET  = 1,
+	CONNMAN_DEVICE_TYPE_WIFI      = 2,
+	CONNMAN_DEVICE_TYPE_BLUETOOTH = 3,
+	CONNMAN_DEVICE_TYPE_CELLULAR  = 4,
+	CONNMAN_DEVICE_TYPE_GPS       = 5,
+	CONNMAN_DEVICE_TYPE_GADGET    = 6,
+	CONNMAN_DEVICE_TYPE_LOWPAN    = 7,
+	CONNMAN_DEVICE_TYPE_VENDOR    = 10000,
+};
+
+#define CONNMAN_DEVICE_PRIORITY_LOW      -100
+#define CONNMAN_DEVICE_PRIORITY_DEFAULT     0
+#define CONNMAN_DEVICE_PRIORITY_HIGH      100
+
+struct connman_device;
+
+struct connman_device *connman_device_create(const char *node,
+						enum connman_device_type type);
+
+#define connman_device_ref(device) \
+	connman_device_ref_debug(device, __FILE__, __LINE__, __func__)
+
+#define connman_device_unref(device) \
+	connman_device_unref_debug(device, __FILE__, __LINE__, __func__)
+
+struct connman_device *
+connman_device_ref_debug(struct connman_device *device,
+			const char *file, int line, const char *caller);
+void connman_device_unref_debug(struct connman_device *device,
+			const char *file, int line, const char *caller);
+
+enum connman_device_type connman_device_get_type(struct connman_device *device);
+void connman_device_set_index(struct connman_device *device, int index);
+int connman_device_get_index(struct connman_device *device);
+void connman_device_set_interface(struct connman_device *device,
+						const char *interface);
+
+void connman_device_set_ident(struct connman_device *device,
+						const char *ident);
+const char *connman_device_get_ident(struct connman_device *device);
+
+int connman_device_set_powered(struct connman_device *device,
+						bool powered);
+bool connman_device_get_powered(struct connman_device *device);
+int connman_device_set_scanning(struct connman_device *device,
+				enum connman_service_type type, bool scanning);
+bool connman_device_get_scanning(struct connman_device *device);
+void connman_device_reset_scanning(struct connman_device *device);
+
+int connman_device_set_disconnected(struct connman_device *device,
+						bool disconnected);
+bool connman_device_get_disconnected(struct connman_device *device);
+
+int connman_device_set_string(struct connman_device *device,
+					const char *key, const char *value);
+const char *connman_device_get_string(struct connman_device *device,
+							const char *key);
+
+int connman_device_add_network(struct connman_device *device,
+					struct connman_network *network);
+struct connman_network *connman_device_get_network(struct connman_device *device,
+							const char *identifier);
+int connman_device_remove_network(struct connman_device *device,
+					struct connman_network *network);
+
+int connman_device_register(struct connman_device *device);
+void connman_device_unregister(struct connman_device *device);
+
+void *connman_device_get_data(struct connman_device *device);
+void connman_device_set_data(struct connman_device *device, void *data);
+
+int connman_device_set_regdom(struct connman_device *device,
+						const char *alpha2);
+void connman_device_regdom_notify(struct connman_device *device,
+					int result, const char *alpha2);
+struct connman_device *connman_device_create_from_index(int index);
+struct connman_device *connman_device_find_by_index(int index);
+int connman_device_reconnect_service(struct connman_device *device);
+
+struct connman_device_driver {
+	const char *name;
+	enum connman_device_type type;
+	int priority;
+	int (*probe) (struct connman_device *device);
+	void (*remove) (struct connman_device *device);
+	int (*enable) (struct connman_device *device);
+	int (*disable) (struct connman_device *device);
+	int (*scan)(enum connman_service_type type,
+			struct connman_device *device,
+			const char *ssid, unsigned int ssid_len,
+			const char *identity, const char* passphrase,
+			const char *security, void *user_data);
+	int (*set_regdom) (struct connman_device *device,
+						const char *alpha2);
+};
+
+int connman_device_driver_register(struct connman_device_driver *driver);
+void connman_device_driver_unregister(struct connman_device_driver *driver);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CONNMAN_DEVICE_H */
diff --git a/connman/include/gdbus.h b/connman/include/gdbus.h
new file mode 100644
index 0000000..87f0000
--- /dev/null
+++ b/connman/include/gdbus.h
@@ -0,0 +1,386 @@
+/*
+ *
+ *  D-Bus helper library
+ *
+ *  Copyright (C) 2004-2011  Marcel Holtmann <marcel@holtmann.org>
+ *
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  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 __GDBUS_H
+#define __GDBUS_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <dbus/dbus.h>
+#include <glib.h>
+
+typedef enum GDBusMethodFlags GDBusMethodFlags;
+typedef enum GDBusSignalFlags GDBusSignalFlags;
+typedef enum GDBusPropertyFlags GDBusPropertyFlags;
+typedef enum GDBusSecurityFlags GDBusSecurityFlags;
+
+typedef struct GDBusArgInfo GDBusArgInfo;
+typedef struct GDBusMethodTable GDBusMethodTable;
+typedef struct GDBusSignalTable GDBusSignalTable;
+typedef struct GDBusPropertyTable GDBusPropertyTable;
+typedef struct GDBusSecurityTable GDBusSecurityTable;
+
+typedef void (* GDBusWatchFunction) (DBusConnection *connection,
+							void *user_data);
+
+typedef void (* GDBusMessageFunction) (DBusConnection *connection,
+					 DBusMessage *message, void *user_data);
+
+typedef gboolean (* GDBusSignalFunction) (DBusConnection *connection,
+					DBusMessage *message, void *user_data);
+
+DBusConnection *g_dbus_setup_bus(DBusBusType type, const char *name,
+							DBusError *error);
+
+DBusConnection *g_dbus_setup_private(DBusBusType type, const char *name,
+							DBusError *error);
+
+gboolean g_dbus_request_name(DBusConnection *connection, const char *name,
+							DBusError *error);
+
+gboolean g_dbus_set_disconnect_function(DBusConnection *connection,
+				GDBusWatchFunction function,
+				void *user_data, DBusFreeFunction destroy);
+
+typedef void (* GDBusDestroyFunction) (void *user_data);
+
+typedef DBusMessage * (* GDBusMethodFunction) (DBusConnection *connection,
+					DBusMessage *message, void *user_data);
+
+typedef gboolean (*GDBusPropertyGetter)(const GDBusPropertyTable *property,
+					DBusMessageIter *iter, void *data);
+
+typedef guint32 GDBusPendingPropertySet;
+
+typedef void (*GDBusPropertySetter)(const GDBusPropertyTable *property,
+			DBusMessageIter *value, GDBusPendingPropertySet id,
+			void *data);
+
+typedef gboolean (*GDBusPropertyExists)(const GDBusPropertyTable *property,
+								void *data);
+
+typedef guint32 GDBusPendingReply;
+
+typedef void (* GDBusSecurityFunction) (DBusConnection *connection,
+						const char *action,
+						gboolean interaction,
+						GDBusPendingReply pending);
+
+enum GDBusFlags {
+	G_DBUS_FLAG_ENABLE_EXPERIMENTAL = (1 << 0),
+};
+
+enum GDBusMethodFlags {
+	G_DBUS_METHOD_FLAG_NONE         = 0,
+	G_DBUS_METHOD_FLAG_DEPRECATED   = (1 << 0),
+	G_DBUS_METHOD_FLAG_NOREPLY      = (1 << 1),
+	G_DBUS_METHOD_FLAG_ASYNC        = (1 << 2),
+	G_DBUS_METHOD_FLAG_EXPERIMENTAL = (1 << 3),
+};
+
+enum GDBusSignalFlags {
+	G_DBUS_SIGNAL_FLAG_DEPRECATED   = (1 << 0),
+	G_DBUS_SIGNAL_FLAG_EXPERIMENTAL = (1 << 1),
+};
+
+enum GDBusPropertyFlags {
+	G_DBUS_PROPERTY_FLAG_DEPRECATED   = (1 << 0),
+	G_DBUS_PROPERTY_FLAG_EXPERIMENTAL = (1 << 1),
+};
+
+enum GDBusSecurityFlags {
+	G_DBUS_SECURITY_FLAG_DEPRECATED        = (1 << 0),
+	G_DBUS_SECURITY_FLAG_BUILTIN           = (1 << 1),
+	G_DBUS_SECURITY_FLAG_ALLOW_INTERACTION = (1 << 2),
+};
+
+struct GDBusArgInfo {
+	const char *name;
+	const char *signature;
+};
+
+struct GDBusMethodTable {
+	const char *name;
+	GDBusMethodFunction function;
+	GDBusMethodFlags flags;
+	unsigned int privilege;
+	const GDBusArgInfo *in_args;
+	const GDBusArgInfo *out_args;
+};
+
+struct GDBusSignalTable {
+	const char *name;
+	GDBusSignalFlags flags;
+	const GDBusArgInfo *args;
+};
+
+struct GDBusPropertyTable {
+	const char *name;
+	const char *type;
+	GDBusPropertyGetter get;
+	GDBusPropertySetter set;
+	GDBusPropertyExists exists;
+	GDBusPropertyFlags flags;
+};
+
+struct GDBusSecurityTable {
+	unsigned int privilege;
+	const char *action;
+	GDBusSecurityFlags flags;
+	GDBusSecurityFunction function;
+};
+
+#define GDBUS_ARGS(args...) (const GDBusArgInfo[]) { args, { } }
+
+#define GDBUS_METHOD(_name, _in_args, _out_args, _function) \
+	.name = _name, \
+	.in_args = _in_args, \
+	.out_args = _out_args, \
+	.function = _function
+
+#define GDBUS_ASYNC_METHOD(_name, _in_args, _out_args, _function) \
+	.name = _name, \
+	.in_args = _in_args, \
+	.out_args = _out_args, \
+	.function = _function, \
+	.flags = G_DBUS_METHOD_FLAG_ASYNC
+
+#define GDBUS_DEPRECATED_METHOD(_name, _in_args, _out_args, _function) \
+	.name = _name, \
+	.in_args = _in_args, \
+	.out_args = _out_args, \
+	.function = _function, \
+	.flags = G_DBUS_METHOD_FLAG_DEPRECATED
+
+#define GDBUS_DEPRECATED_ASYNC_METHOD(_name, _in_args, _out_args, _function) \
+	.name = _name, \
+	.in_args = _in_args, \
+	.out_args = _out_args, \
+	.function = _function, \
+	.flags = G_DBUS_METHOD_FLAG_ASYNC | G_DBUS_METHOD_FLAG_DEPRECATED
+
+#define GDBUS_EXPERIMENTAL_METHOD(_name, _in_args, _out_args, _function) \
+	.name = _name, \
+	.in_args = _in_args, \
+	.out_args = _out_args, \
+	.function = _function, \
+	.flags = G_DBUS_METHOD_FLAG_EXPERIMENTAL
+
+#define GDBUS_EXPERIMENTAL_ASYNC_METHOD(_name, _in_args, _out_args, _function) \
+	.name = _name, \
+	.in_args = _in_args, \
+	.out_args = _out_args, \
+	.function = _function, \
+	.flags = G_DBUS_METHOD_FLAG_ASYNC | G_DBUS_METHOD_FLAG_EXPERIMENTAL
+
+#define GDBUS_NOREPLY_METHOD(_name, _in_args, _out_args, _function) \
+	.name = _name, \
+	.in_args = _in_args, \
+	.out_args = _out_args, \
+	.function = _function, \
+	.flags = G_DBUS_METHOD_FLAG_NOREPLY
+
+#define GDBUS_SIGNAL(_name, _args) \
+	.name = _name, \
+	.args = _args
+
+#define GDBUS_DEPRECATED_SIGNAL(_name, _args) \
+	.name = _name, \
+	.args = _args, \
+	.flags = G_DBUS_SIGNAL_FLAG_DEPRECATED
+
+#define GDBUS_EXPERIMENTAL_SIGNAL(_name, _args) \
+	.name = _name, \
+	.args = _args, \
+	.flags = G_DBUS_SIGNAL_FLAG_EXPERIMENTAL
+
+void g_dbus_set_flags(int flags);
+int g_dbus_get_flags(void);
+
+gboolean g_dbus_register_interface(DBusConnection *connection,
+					const char *path, const char *name,
+					const GDBusMethodTable *methods,
+					const GDBusSignalTable *signals,
+					const GDBusPropertyTable *properties,
+					void *user_data,
+					GDBusDestroyFunction destroy);
+gboolean g_dbus_unregister_interface(DBusConnection *connection,
+					const char *path, const char *name);
+
+gboolean g_dbus_register_security(const GDBusSecurityTable *security);
+gboolean g_dbus_unregister_security(const GDBusSecurityTable *security);
+
+void g_dbus_pending_success(DBusConnection *connection,
+					GDBusPendingReply pending);
+void g_dbus_pending_error(DBusConnection *connection,
+				GDBusPendingReply pending,
+				const char *name, const char *format, ...)
+					__attribute__((format(printf, 4, 5)));
+void g_dbus_pending_error_valist(DBusConnection *connection,
+				GDBusPendingReply pending, const char *name,
+					const char *format, va_list args);
+
+DBusMessage *g_dbus_create_error(DBusMessage *message, const char *name,
+						const char *format, ...)
+					__attribute__((format(printf, 3, 4)));
+DBusMessage *g_dbus_create_error_valist(DBusMessage *message, const char *name,
+					const char *format, va_list args);
+DBusMessage *g_dbus_create_reply(DBusMessage *message, int type, ...);
+DBusMessage *g_dbus_create_reply_valist(DBusMessage *message,
+						int type, va_list args);
+
+gboolean g_dbus_send_message(DBusConnection *connection, DBusMessage *message);
+gboolean g_dbus_send_message_with_reply(DBusConnection *connection,
+					DBusMessage *message,
+					DBusPendingCall **call, int timeout);
+gboolean g_dbus_send_error(DBusConnection *connection, DBusMessage *message,
+				const char *name, const char *format, ...)
+					 __attribute__((format(printf, 4, 5)));
+gboolean g_dbus_send_error_valist(DBusConnection *connection,
+					DBusMessage *message, const char *name,
+					const char *format, va_list args);
+gboolean g_dbus_send_reply(DBusConnection *connection,
+				DBusMessage *message, int type, ...);
+gboolean g_dbus_send_reply_valist(DBusConnection *connection,
+				DBusMessage *message, int type, va_list args);
+
+gboolean g_dbus_emit_signal(DBusConnection *connection,
+				const char *path, const char *interface,
+				const char *name, int type, ...);
+gboolean g_dbus_emit_signal_valist(DBusConnection *connection,
+				const char *path, const char *interface,
+				const char *name, int type, va_list args);
+
+guint g_dbus_add_service_watch(DBusConnection *connection, const char *name,
+				GDBusWatchFunction connect,
+				GDBusWatchFunction disconnect,
+				void *user_data, GDBusDestroyFunction destroy);
+guint g_dbus_add_disconnect_watch(DBusConnection *connection, const char *name,
+				GDBusWatchFunction function,
+				void *user_data, GDBusDestroyFunction destroy);
+guint g_dbus_add_signal_watch(DBusConnection *connection,
+				const char *sender, const char *path,
+				const char *interface, const char *member,
+				GDBusSignalFunction function, void *user_data,
+				GDBusDestroyFunction destroy);
+guint g_dbus_add_properties_watch(DBusConnection *connection,
+				const char *sender, const char *path,
+				const char *interface,
+				GDBusSignalFunction function, void *user_data,
+				GDBusDestroyFunction destroy);
+gboolean g_dbus_remove_watch(DBusConnection *connection, guint tag);
+void g_dbus_remove_all_watches(DBusConnection *connection);
+
+void g_dbus_pending_property_success(GDBusPendingPropertySet id);
+void g_dbus_pending_property_error_valist(GDBusPendingReply id,
+			const char *name, const char *format, va_list args);
+void g_dbus_pending_property_error(GDBusPendingReply id, const char *name,
+						const char *format, ...);
+void g_dbus_emit_property_changed(DBusConnection *connection,
+				const char *path, const char *interface,
+				const char *name);
+gboolean g_dbus_get_properties(DBusConnection *connection, const char *path,
+				const char *interface, DBusMessageIter *iter);
+
+gboolean g_dbus_attach_object_manager(DBusConnection *connection);
+gboolean g_dbus_detach_object_manager(DBusConnection *connection);
+
+typedef struct GDBusClient GDBusClient;
+typedef struct GDBusProxy GDBusProxy;
+
+GDBusProxy *g_dbus_proxy_new(GDBusClient *client, const char *path,
+							const char *interface);
+
+GDBusProxy *g_dbus_proxy_ref(GDBusProxy *proxy);
+void g_dbus_proxy_unref(GDBusProxy *proxy);
+
+const char *g_dbus_proxy_get_path(GDBusProxy *proxy);
+const char *g_dbus_proxy_get_interface(GDBusProxy *proxy);
+
+gboolean g_dbus_proxy_get_property(GDBusProxy *proxy, const char *name,
+							DBusMessageIter *iter);
+
+gboolean g_dbus_proxy_refresh_property(GDBusProxy *proxy, const char *name);
+
+typedef void (* GDBusResultFunction) (const DBusError *error, void *user_data);
+
+gboolean g_dbus_proxy_set_property_basic(GDBusProxy *proxy,
+				const char *name, int type, const void *value,
+				GDBusResultFunction function, void *user_data,
+				GDBusDestroyFunction destroy);
+
+gboolean g_dbus_proxy_set_property_array(GDBusProxy *proxy,
+				const char *name, int type, const void *value,
+				size_t size, GDBusResultFunction function,
+				void *user_data, GDBusDestroyFunction destroy);
+
+typedef void (* GDBusSetupFunction) (DBusMessageIter *iter, void *user_data);
+typedef void (* GDBusReturnFunction) (DBusMessage *message, void *user_data);
+
+gboolean g_dbus_proxy_method_call(GDBusProxy *proxy, const char *method,
+				GDBusSetupFunction setup,
+				GDBusReturnFunction function, void *user_data,
+				GDBusDestroyFunction destroy);
+
+typedef void (* GDBusClientFunction) (GDBusClient *client, void *user_data);
+typedef void (* GDBusProxyFunction) (GDBusProxy *proxy, void *user_data);
+typedef void (* GDBusPropertyFunction) (GDBusProxy *proxy, const char *name,
+					DBusMessageIter *iter, void *user_data);
+
+gboolean g_dbus_proxy_set_property_watch(GDBusProxy *proxy,
+			GDBusPropertyFunction function, void *user_data);
+
+gboolean g_dbus_proxy_set_removed_watch(GDBusProxy *proxy,
+			GDBusProxyFunction destroy, void *user_data);
+
+GDBusClient *g_dbus_client_new(DBusConnection *connection,
+					const char *service, const char *path);
+GDBusClient *g_dbus_client_new_full(DBusConnection *connection,
+							const char *service,
+							const char *path,
+							const char *root_path);
+
+GDBusClient *g_dbus_client_ref(GDBusClient *client);
+void g_dbus_client_unref(GDBusClient *client);
+
+gboolean g_dbus_client_set_connect_watch(GDBusClient *client,
+				GDBusWatchFunction function, void *user_data);
+gboolean g_dbus_client_set_disconnect_watch(GDBusClient *client,
+				GDBusWatchFunction function, void *user_data);
+gboolean g_dbus_client_set_signal_watch(GDBusClient *client,
+				GDBusMessageFunction function, void *user_data);
+gboolean g_dbus_client_set_ready_watch(GDBusClient *client,
+				GDBusClientFunction ready, void *user_data);
+gboolean g_dbus_client_set_proxy_handlers(GDBusClient *client,
+					GDBusProxyFunction proxy_added,
+					GDBusProxyFunction proxy_removed,
+					GDBusPropertyFunction property_changed,
+					void *user_data);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __GDBUS_H */
diff --git a/connman/include/inet.h b/connman/include/inet.h
new file mode 100644
index 0000000..bb0f1dc
--- /dev/null
+++ b/connman/include/inet.h
@@ -0,0 +1,84 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2013  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 __CONNMAN_INET_H
+#define __CONNMAN_INET_H
+
+#include <arpa/inet.h>
+#include <linux/netlink.h>
+#include <linux/rtnetlink.h>
+
+#include <connman/device.h>
+#include <connman/ipconfig.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int connman_inet_ifindex(const char *name);
+char *connman_inet_ifname(int index);
+
+int connman_inet_ifup(int index);
+int connman_inet_ifdown(int index);
+
+int connman_inet_set_address(int index, struct connman_ipaddress *ipaddress);
+int connman_inet_clear_address(int index, struct connman_ipaddress *ipaddress);
+int connman_inet_add_host_route(int index, const char *host, const char *gateway);
+int connman_inet_del_host_route(int index, const char *host);
+int connman_inet_add_network_route(int index, const char *host, const char *gateway,
+					const char *netmask);
+int connman_inet_del_network_route(int index, const char *host);
+int connman_inet_clear_gateway_address(int index, const char *gateway);
+int connman_inet_set_gateway_interface(int index);
+int connman_inet_clear_gateway_interface(int index);
+bool connman_inet_compare_subnet(int index, const char *host);
+int connman_inet_set_ipv6_address(int index,
+		struct connman_ipaddress *ipaddress);
+int connman_inet_clear_ipv6_address(int index,
+		const char *address, int prefix_len);
+int connman_inet_add_ipv6_network_route(int index, const char *host,
+					const char *gateway, unsigned char prefix_len);
+int connman_inet_add_ipv6_host_route(int index, const char *host,
+						const char *gateway);
+int connman_inet_del_ipv6_network_route(int index, const char *host,
+					unsigned char prefix_len);
+int connman_inet_del_ipv6_host_route(int index, const char *host);
+int connman_inet_clear_ipv6_gateway_address(int index, const char *gateway);
+int connman_inet_set_ipv6_gateway_interface(int index);
+int connman_inet_clear_ipv6_gateway_interface(int index);
+
+int connman_inet_add_to_bridge(int index, const char *bridge);
+int connman_inet_remove_from_bridge(int index, const char *bridge);
+
+int connman_inet_set_mtu(int index, int mtu);
+int connman_inet_setup_tunnel(char *tunnel, int mtu);
+int connman_inet_create_tunnel(char **iface);
+int connman_inet_get_dest_addr(int index, char **dest);
+int connman_inet_ipv6_get_dest_addr(int index, char **dest);
+int connman_inet_check_ipaddress(const char *host);
+bool connman_inet_check_hostname(const char *ptr, size_t len);
+bool connman_inet_is_ipv6_supported(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CONNMAN_INET_H */
diff --git a/connman/include/inotify.h b/connman/include/inotify.h
new file mode 100644
index 0000000..4bc6330
--- /dev/null
+++ b/connman/include/inotify.h
@@ -0,0 +1,37 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2012,2014  BMW Car IT GmbH.
+ *
+ *  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 __CONNMAN_INOTIFY_H
+#define __CONNMAN_INOTIFY_H
+
+struct inotify_event;
+
+typedef void (* inotify_event_cb) (struct inotify_event *event,
+					const char *ident);
+
+int connman_inotify_register(const char *path, inotify_event_cb callback);
+void connman_inotify_unregister(const char *path, inotify_event_cb callback);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CONNMAN_INOTIFY_H */
diff --git a/connman/include/ipaddress.h b/connman/include/ipaddress.h
new file mode 100644
index 0000000..3655ca8
--- /dev/null
+++ b/connman/include/ipaddress.h
@@ -0,0 +1,60 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2013  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 __CONNMAN_IPADDRESS_H
+#define __CONNMAN_IPADDRESS_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * SECTION:ipaddress
+ * @title: IP address premitives
+ * @short_description: Functions for IP address handling
+ */
+
+struct connman_ipaddress;
+
+unsigned char connman_ipaddress_calc_netmask_len(const char *netmask);
+struct connman_ipaddress *connman_ipaddress_alloc(int family);
+void connman_ipaddress_free(struct connman_ipaddress *ipaddress);
+int connman_ipaddress_set_ipv4(struct connman_ipaddress *ipaddress,
+				const char *address, const char *netmask,
+				const char *gateway);
+int connman_ipaddress_set_ipv6(struct connman_ipaddress *ipaddress,
+				const char *address,
+				unsigned char prefix_length,
+				const char *gateway);
+int connman_ipaddress_get_ip(struct connman_ipaddress *ipaddress,
+			const char **address, unsigned char *prefix_length);
+void connman_ipaddress_set_peer(struct connman_ipaddress *ipaddress,
+				const char *peer);
+void connman_ipaddress_clear(struct connman_ipaddress *ipaddress);
+void connman_ipaddress_copy_address(struct connman_ipaddress *ipaddress,
+					struct connman_ipaddress *source);
+struct connman_ipaddress *connman_ipaddress_copy(struct connman_ipaddress *ipaddress);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CONNMAN_IPADDRESS_H */
diff --git a/connman/include/ipconfig.h b/connman/include/ipconfig.h
new file mode 100644
index 0000000..e26dd1a
--- /dev/null
+++ b/connman/include/ipconfig.h
@@ -0,0 +1,63 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2012  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 __CONNMAN_IPCONFIG_H
+#define __CONNMAN_IPCONFIG_H
+
+#include <connman/ipaddress.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * SECTION:ipconfig
+ * @title: IP configuration premitives
+ * @short_description: Functions for IP configuration handling
+ */
+
+enum connman_ipconfig_type {
+	CONNMAN_IPCONFIG_TYPE_UNKNOWN = 0,
+	CONNMAN_IPCONFIG_TYPE_IPV4    = 1,
+	CONNMAN_IPCONFIG_TYPE_IPV6    = 2,
+	CONNMAN_IPCONFIG_TYPE_ALL     = 3,
+};
+
+enum connman_ipconfig_method {
+	CONNMAN_IPCONFIG_METHOD_UNKNOWN = 0,
+	CONNMAN_IPCONFIG_METHOD_OFF     = 1,
+	CONNMAN_IPCONFIG_METHOD_FIXED   = 2,
+	CONNMAN_IPCONFIG_METHOD_MANUAL  = 3,
+	CONNMAN_IPCONFIG_METHOD_DHCP    = 4,
+	CONNMAN_IPCONFIG_METHOD_AUTO    = 5,
+};
+
+struct connman_ipconfig;
+struct connman_ipdevice;
+
+struct connman_ipdevice *connman_ipdevice_lookup_from_index(int index);
+void connman_ipdevice_set_address(struct connman_ipdevice *ipdevice, const char* address);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CONNMAN_IPCONFIG_H */
diff --git a/connman/include/log.h b/connman/include/log.h
new file mode 100644
index 0000000..d41d037
--- /dev/null
+++ b/connman/include/log.h
@@ -0,0 +1,371 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2013  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 __CONNMAN_LOG_H
+#define __CONNMAN_LOG_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * SECTION:log
+ * @title: Logging premitives
+ * @short_description: Functions for logging error and debug information
+ */
+
+void connman_info(const char *format, ...)
+				__attribute__((format(printf, 1, 2)));
+void connman_warn(const char *format, ...)
+				__attribute__((format(printf, 1, 2)));
+void connman_error(const char *format, ...)
+				__attribute__((format(printf, 1, 2)));
+void connman_debug(const char *format, ...)
+				__attribute__((format(printf, 1, 2)));
+
+#define connman_warn_once(fmt, arg...) do {		\
+	static bool printed;				\
+	if (!printed) {					\
+		connman_warn(fmt, ## arg);		\
+		printed = true;				\
+	}						\
+} while (0)
+
+struct connman_debug_desc {
+	const char *name;
+	const char *file;
+#define CONNMAN_DEBUG_FLAG_DEFAULT (0)
+#define CONNMAN_DEBUG_FLAG_PRINT   (1 << 0)
+#define CONNMAN_DEBUG_FLAG_ALIAS   (1 << 1)
+	unsigned int flags;
+} __attribute__((aligned(8)));
+
+#define CONNMAN_DEBUG_DEFINE(name) \
+	static struct connman_debug_desc __debug_alias_ ## name \
+	__attribute__((used, section("__debug"), aligned(8))) = { \
+		#name, __FILE__, CONNMAN_DEBUG_FLAG_ALIAS \
+	};
+
+/**
+ * DBG:
+ * @fmt: format string
+ * @arg...: list of arguments
+ *
+ * Simple macro around connman_debug() which also include the function
+ * name it is called in.
+ */
+#define DBG(fmt, arg...) do { \
+	static struct connman_debug_desc __connman_debug_desc \
+	__attribute__((used, section("__debug"), aligned(8))) = { \
+		.file = __FILE__, .flags = CONNMAN_DEBUG_FLAG_DEFAULT, \
+	}; \
+	if (__connman_debug_desc.flags & CONNMAN_DEBUG_FLAG_PRINT) \
+		connman_debug("%s:%s() " fmt, \
+					__FILE__, __FUNCTION__ , ## arg); \
+} while (0)
+
+#if !defined(CONNMAN_DEBUG)
+#define CONNMAN_DEBUG DEBUG && !NDEBUG
+#endif
+
+#if CONNMAN_DEBUG
+extern unsigned int trace_depth;
+extern char trace_tabbuf[];
+
+extern void connman_create_indent(unsigned int depth, char *buffer);
+
+#define connman_trace(dir, fmt, arg...)					\
+	do {								\
+		connman_create_indent(trace_depth, trace_tabbuf);	\
+		connman_debug("%s" dir " (%d) %s: " fmt,		\
+			      trace_tabbuf,				\
+			      trace_depth,				\
+			      __FUNCTION__,				\
+			      ## arg);					\
+	} while (0)
+
+#define connman_trace_in(fmt, arg...)					\
+	do {								\
+		connman_trace("-->", fmt, ## arg);			\
+		trace_depth++;						\
+	} while (0)
+
+#define connman_trace_out(fmt, arg...)					\
+	do {								\
+		--trace_depth;						\
+		connman_trace("<--", fmt, ## arg);			\
+	} while (0)
+#else
+#define connman_trace_in(fmt, arg...)
+#define connman_trace_out(fmt, arg...)
+#endif
+
+extern void connman_assert_handler(const char *name, const char *predicate, const char *message, const char *file, unsigned int line, void *value, int terminate);
+
+#if !defined(CONNMAN_ASSERT)
+#define CONNMAN_ASSERT(name, predicate, message, file, line, value) connman_assert_handler(name, predicate, message, file, line, value, 0)
+#endif
+
+#if !defined(CONNMAN_ASSERT_MODULE)
+#define CONNMAN_ASSERT_MODULE NULL
+#endif
+
+#if CONNMAN_DEBUG
+#define connman_assert(predicate)					\
+	do {								\
+		if (!(predicate)) {					\
+			connman_assert_handler(CONNMAN_ASSERT_MODULE,	\
+					       #predicate,		\
+					       NULL,			\
+					       __FILE__,		\
+					       __LINE__,		\
+					       0,			\
+					       1);			\
+		}							\
+	} while (0)
+#else
+#define connman_assert(predicate)
+#endif
+
+#if CONNMAN_DEBUG
+#define connman_check_message(predicate, message)			\
+	do {								\
+		if (!(predicate)) {					\
+			CONNMAN_ASSERT(CONNMAN_ASSERT_MODULE,		\
+				       #predicate,			\
+				       message,				\
+				       __FILE__,			\
+				       __LINE__,			\
+				       0);				\
+		}							\
+	} while (0)
+#else
+#define connman_check_message(predicate, message)
+#endif
+
+#if CONNMAN_DEBUG
+#define connman_check(predicate)					\
+	connman_check_message(predicate, NULL)
+#else
+#define connman_check(predicate)
+#endif
+
+#if CONNMAN_DEBUG
+#define connman_check_ok_message(error, message)			\
+	do {								\
+		if ((error) != 0) {					\
+			CONNMAN_ASSERT(CONNMAN_ASSERT_MODULE,		\
+				       #error " == 0",			\
+				       message,				\
+				       __FILE__,			\
+				       __LINE__,			\
+				       (void *)error);			\
+		}							\
+	} while (0)
+#else
+#define connman_check_ok_message(error, message)
+#endif
+
+#if CONNMAN_DEBUG
+#define connman_check_ok(error)						\
+	connman_check_ok_message(error, NULL) 
+#else
+#define connman_check_ok(error)
+#endif
+
+#if CONNMAN_DEBUG
+#define connman_verify_message(predicate, message)			\
+	connman_check_message(predicate, message)
+#else
+#define connman_verify_message(predicate, message)			\
+	do {								\
+		if (!predicate) { }					\
+	} while (0)
+#endif
+
+#define connman_verify(predicate)					\
+	connman_verify_message(predicate, NULL)
+
+#if CONNMAN_DEBUG
+#define connman_verify_execute_message(predicate, action, message)	\
+	do {								\
+		if (!(predicate)) {					\
+			CONNMAN_ASSERT(CONNMAN_ASSERT_MODULE,		\
+				       #predicate,			\
+				       message,				\
+				       __FILE__,			\
+				       __LINE__,			\
+				       0);				\
+			{						\
+				action;					\
+			}						\
+		}							\
+	} while (0)
+#else
+#define connman_verify_execute_message(predicate, action, message)	\
+	do {								\
+		if (!(predicate)) {					\
+			{						\
+				action;					\
+			}						\
+		}							\
+	} while (0)
+#endif
+
+#define connman_verify_execute(predicate, action)			\
+    connman_verify_execute_message(predicate, action, NULL)
+
+#if CONNMAN_DEBUG
+#define connman_verify_ok_message(error, message)			\
+	connman_check_ok_message(error, message)
+#else
+#define connman_verify_ok_message(error, message)			\
+	connman_verify_message(error == 0, message)
+#endif
+
+#define connman_verify_ok(error)					\
+	connman_verify_ok_message(error, NULL)
+
+#define connman_require_quiet(predicate, label)				\
+	do {								\
+		if (!(predicate))	{				\
+			goto label;					\
+		}							\
+	} while (0)
+
+#if CONNMAN_DEBUG
+#define connman_require_message(predicate, label, message)		\
+	do {								\
+		if (!(predicate)) {					\
+			CONNMAN_ASSERT(CONNMAN_ASSERT_MODULE,		\
+				       #predicate,			\
+				       message,				\
+				       __FILE__,			\
+				       __LINE__,			\
+				       0);				\
+			goto label;					\
+		}							\
+	} while (0)
+#else
+#define connman_require_message(predicate, label, message)		\
+	connman_require(predicate, label)
+#endif
+
+#define connman_require(predicate, label)				\
+	connman_require_message(predicate, label, NULL)
+
+#define connman_require_execute_quiet(predicate, label, action)		\
+	do {								\
+		if (!(predicate)) {					\
+			{						\
+				action;					\
+			}						\
+			goto label;					\
+		}							\
+	} while (0)
+
+#if CONNMAN_DEBUG
+#define connman_require_execute_message(predicate, label, action, message)  \
+	do {								\
+		if (!(predicate)) {					\
+			CONNMAN_ASSERT(					\
+				       CONNMAN_ASSERT_MODULE,		\
+				       #predicate,			\
+				       message,				\
+				       __FILE__,			\
+				       __LINE__,			\
+				       0);				\
+			{						\
+				action;					\
+			}						\
+			goto label;					\
+		}							\
+	} while (0)
+#else
+#define connman_require_execute_message(predicate, label, action, message)  \
+	connman_require_execute_message_quiet(predicate, label, action, message)
+#endif
+
+#define connman_require_execute(predicate, label, action)		\
+	connman_require_execute_message(predicate, label, action, NULL)
+
+#define connman_require_ok_quiet(error, label)				\
+	connnman_require_quiet(error == 0, label)
+
+#if CONNMAN_DEBUG
+#define connman_require_ok_message(error, label, message)		\
+	do {								\
+		if ((error) != 0) {					\
+			CONNMAN_ASSERT(CONNMAN_ASSERT_MODULE,		\
+				       #error " == 0 ",			\
+				       message,				\
+				       __FILE__,			\
+				       __LINE__,			\
+				       error);				\
+			goto label;					\
+		}							\
+	} while (0)
+#else
+#define connman_require_ok_message(error, label, message)		\
+	  connman_require_ok_quiet(error, label)
+#endif
+
+#define connman_require_ok(error, label)				\
+	connman_require_ok_message(error, label, NULL)
+
+#define connman_require_ok_execute_quiet(error, label, action)		\
+	do {								\
+		if ((error) != 0) {					\
+			{						\
+				action;					\
+			}						\
+			goto label;					\
+		}							\
+	} while (0)
+#if CONNMAN_DEBUG
+#define connman_require_ok_execute_message(error, label, action, message) \
+	do {								\
+		if ((error) != 0) {					\
+			CONNMAN_ASSERT(CONNMAN_ASSERT_MODULE,		\
+				       #error " == 0 ",			\
+				       message,				\
+				       __FILE__,			\
+				       __LINE__,			\
+				       error);				\
+			{						\
+				action;					\
+			}						\
+			goto label;					\
+		}							\
+	} while (0)
+#else
+#define connman_require_ok_execute_message(error, label, action, message) \
+		connman_require_ok_execute_quiet(error, label, action)
+#endif
+
+#define connman_require_ok_execute(error, label, action)	\
+		connman_require_ok_execute_message(error, label, action, NULL)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CONNMAN_LOG_H */
diff --git a/connman/include/machine.h b/connman/include/machine.h
new file mode 100644
index 0000000..c8d8735
--- /dev/null
+++ b/connman/include/machine.h
@@ -0,0 +1,35 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2014  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 __CONNMAN_MACHINE_H
+#define __CONNMAN_MACHINE_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+const char *connman_machine_get_type(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CONNMAN_MACHINE_H */
diff --git a/connman/include/network.h b/connman/include/network.h
new file mode 100644
index 0000000..22c3560
--- /dev/null
+++ b/connman/include/network.h
@@ -0,0 +1,171 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2013  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 __CONNMAN_NETWORK_H
+#define __CONNMAN_NETWORK_H
+
+#include <stdbool.h>
+#include <stdint.h>
+
+#include <connman/device.h>
+#include <connman/ipconfig.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * SECTION:network
+ * @title: Network premitives
+ * @short_description: Functions for handling networks
+ */
+
+enum connman_network_type {
+	CONNMAN_NETWORK_TYPE_UNKNOWN       = 0,
+	CONNMAN_NETWORK_TYPE_ETHERNET      = 1,
+	CONNMAN_NETWORK_TYPE_WIFI          = 2,
+	CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN = 8,
+	CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN = 9,
+	CONNMAN_NETWORK_TYPE_CELLULAR      = 10,
+	CONNMAN_NETWORK_TYPE_GADGET        = 11,
+	CONNMAN_NETWORK_TYPE_LOWPAN        = 12,
+	CONNMAN_NETWORK_TYPE_VENDOR        = 10000,
+};
+
+enum connman_network_error {
+	CONNMAN_NETWORK_ERROR_UNKNOWN         = 0,
+	CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL  = 1,
+	CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL  = 2,
+	CONNMAN_NETWORK_ERROR_INVALID_KEY     = 3,
+	CONNMAN_NETWORK_ERROR_CONNECT_FAIL    = 4,
+};
+
+#define CONNMAN_NETWORK_PRIORITY_LOW      -100
+#define CONNMAN_NETWORK_PRIORITY_DEFAULT     0
+#define CONNMAN_NETWORK_PRIORITY_HIGH      100
+
+struct connman_network;
+
+struct connman_network *connman_network_create(const char *identifier,
+					enum connman_network_type type);
+
+#define connman_network_ref(network) \
+	connman_network_ref_debug(network, __func__, __LINE__, __func__)
+
+#define connman_network_unref(network) \
+	connman_network_unref_debug(network, __func__, __LINE__, __func__)
+
+struct connman_network *
+connman_network_ref_debug(struct connman_network *network,
+			const char *file, int line, const char *caller);
+void connman_network_unref_debug(struct connman_network *network,
+			const char *file, int line, const char *caller);
+
+enum connman_network_type connman_network_get_type(struct connman_network *network);
+const char *connman_network_get_identifier(struct connman_network *network);
+
+void connman_network_set_index(struct connman_network *network, int index);
+int connman_network_get_index(struct connman_network *network);
+
+void connman_network_set_group(struct connman_network *network,
+						const char *group);
+const char *connman_network_get_group(struct connman_network *network);
+
+bool connman_network_get_connecting(struct connman_network *network);
+int connman_network_set_available(struct connman_network *network,
+						bool available);
+bool connman_network_get_available(struct connman_network *network);
+int connman_network_set_associating(struct connman_network *network,
+						bool associating);
+void connman_network_set_error(struct connman_network *network,
+					enum connman_network_error error);
+int connman_network_set_connected(struct connman_network *network,
+						bool connected);
+bool connman_network_get_connected(struct connman_network *network);
+
+bool connman_network_get_associating(struct connman_network *network);
+
+int connman_network_needs_input(struct connman_network *network);
+
+void connman_network_clear_hidden(void *user_data);
+int connman_network_connect_hidden(struct connman_network *network,
+			char *identity, char* passphrase, void *user_data);
+
+void connman_network_set_ipv4_method(struct connman_network *network,
+					enum connman_ipconfig_method method);
+void connman_network_set_ipv6_method(struct connman_network *network,
+					enum connman_ipconfig_method method);
+int connman_network_set_ipaddress(struct connman_network *network,
+				struct connman_ipaddress *ipaddress);
+int connman_network_set_nameservers(struct connman_network *network,
+				const char *nameservers);
+int connman_network_set_domain(struct connman_network *network,
+			             const char *domain);
+int connman_network_set_name(struct connman_network *network,
+							const char *name);
+int connman_network_set_strength(struct connman_network *network,
+						uint8_t strength);
+uint8_t connman_network_get_strength(struct connman_network *network);
+int connman_network_set_frequency(struct connman_network *network,
+					uint16_t frequency);
+uint16_t connman_network_get_frequency(struct connman_network *network);
+int connman_network_set_wifi_channel(struct connman_network *network,
+					uint16_t channel);
+uint16_t connman_network_get_wifi_channel(struct connman_network *network);
+
+int connman_network_set_string(struct connman_network *network,
+					const char *key, const char *value);
+const char *connman_network_get_string(struct connman_network *network,
+							const char *key);
+int connman_network_set_bool(struct connman_network *network,
+					const char *key, bool value);
+bool connman_network_get_bool(struct connman_network *network,
+							const char *key);
+int connman_network_set_blob(struct connman_network *network,
+			const char *key, const void *data, unsigned int size);
+const void *connman_network_get_blob(struct connman_network *network,
+					const char *key, unsigned int *size);
+
+struct connman_device *connman_network_get_device(struct connman_network *network);
+
+void *connman_network_get_data(struct connman_network *network);
+void connman_network_set_data(struct connman_network *network, void *data);
+
+void connman_network_update(struct connman_network *network);
+
+struct connman_network_driver {
+	const char *name;
+	enum connman_network_type type;
+	int priority;
+	int (*probe) (struct connman_network *network);
+	void (*remove) (struct connman_network *network);
+	int (*connect) (struct connman_network *network);
+	int (*disconnect) (struct connman_network *network, bool user_initiated);
+};
+
+int connman_network_driver_register(struct connman_network_driver *driver);
+void connman_network_driver_unregister(struct connman_network_driver *driver);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CONNMAN_NETWORK_H */
diff --git a/connman/include/notifier.h b/connman/include/notifier.h
new file mode 100644
index 0000000..c4b0383
--- /dev/null
+++ b/connman/include/notifier.h
@@ -0,0 +1,68 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2012  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 __CONNMAN_NOTIFIER_H
+#define __CONNMAN_NOTIFIER_H
+
+#include <connman/service.h>
+#include <connman/ipconfig.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * SECTION:notifier
+ * @title: Notifier premitives
+ * @short_description: Functions for registering notifier modules
+ */
+
+#define CONNMAN_NOTIFIER_PRIORITY_LOW      -100
+#define CONNMAN_NOTIFIER_PRIORITY_DEFAULT     0
+#define CONNMAN_NOTIFIER_PRIORITY_HIGH      100
+
+struct connman_notifier {
+	const char *name;
+	int priority;
+	void (*default_changed) (struct connman_service *service);
+	void (*service_add) (struct connman_service *service,
+				const char *name);
+	void (*service_remove) (struct connman_service *service);
+	void (*service_enabled) (enum connman_service_type type,
+						bool enabled);
+	void (*offline_mode) (bool enabled);
+	void (*proxy_changed) (struct connman_service *service);
+	void (*service_state_changed) (struct connman_service *service,
+					enum connman_service_state state);
+	void (*ipconfig_changed) (struct connman_service *service,
+					struct connman_ipconfig *ipconfig);
+	void (*sleep_event) (void * identifier, int cansleep, time_t valid_until);
+	void (*idle_state) (bool idle);
+};
+
+int connman_notifier_register(struct connman_notifier *notifier);
+void connman_notifier_unregister(struct connman_notifier *notifier);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CONNMAN_NOTIFIER_H */
diff --git a/connman/include/option.h b/connman/include/option.h
new file mode 100644
index 0000000..5e97ed4
--- /dev/null
+++ b/connman/include/option.h
@@ -0,0 +1,35 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2012  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 __CONNMAN_OPTION_H
+#define __CONNMAN_OPTION_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+const char *connman_option_get_string(const char *key);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CONNMAN_OPTION_H */
diff --git a/connman/include/peer.h b/connman/include/peer.h
new file mode 100644
index 0000000..8066393
--- /dev/null
+++ b/connman/include/peer.h
@@ -0,0 +1,118 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2014  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 __CONNMAN_PEER_H
+#define __CONNMAN_PEER_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+enum connman_peer_state {
+	CONNMAN_PEER_STATE_UNKNOWN       = 0,
+	CONNMAN_PEER_STATE_IDLE          = 1,
+	CONNMAN_PEER_STATE_ASSOCIATION   = 2,
+	CONNMAN_PEER_STATE_CONFIGURATION = 3,
+	CONNMAN_PEER_STATE_READY         = 4,
+	CONNMAN_PEER_STATE_DISCONNECT    = 5,
+	CONNMAN_PEER_STATE_FAILURE       = 6,
+};
+
+enum connman_peer_wps_method {
+	CONNMAN_PEER_WPS_UNKNOWN         = 0,
+	CONNMAN_PEER_WPS_PBC             = 1,
+	CONNMAN_PEER_WPS_PIN             = 2,
+};
+
+enum connman_peer_service_type {
+	CONNMAN_PEER_SERVICE_UNKNOWN      = 0,
+	CONNMAN_PEER_SERVICE_WIFI_DISPLAY = 1,
+};
+
+struct connman_peer;
+
+struct connman_peer *connman_peer_create(const char *identifier);
+
+#define connman_peer_ref(peer) \
+	connman_peer_ref_debug(peer, __FILE__, __LINE__, __func__)
+
+#define connman_peer_unref(peer) \
+	connman_peer_unref_debug(peer, __FILE__, __LINE__, __func__)
+
+struct connman_peer *connman_peer_ref_debug(struct connman_peer *peer,
+			const char *file, int line, const char *caller);
+void connman_peer_unref_debug(struct connman_peer *peer,
+			const char *file, int line, const char *caller);
+
+const char *connman_peer_get_identifier(struct connman_peer *peer);
+void connman_peer_set_name(struct connman_peer *peer, const char *name);
+void connman_peer_set_iface_address(struct connman_peer *peer,
+					const unsigned char *iface_address);
+void connman_peer_set_device(struct connman_peer *peer,
+				struct connman_device *device);
+struct connman_device *connman_peer_get_device(struct connman_peer *peer);
+void connman_peer_set_sub_device(struct connman_peer *peer,
+					struct connman_device *device);
+void connman_peer_set_as_master(struct connman_peer *peer, bool master);
+int connman_peer_set_state(struct connman_peer *peer,
+					enum connman_peer_state new_state);
+int connman_peer_request_connection(struct connman_peer *peer);
+void connman_peer_reset_services(struct connman_peer *peer);
+void connman_peer_add_service(struct connman_peer *peer,
+				enum connman_peer_service_type type,
+				const unsigned char *data, int data_length);
+void connman_peer_services_changed(struct connman_peer *peer);
+
+int connman_peer_register(struct connman_peer *peer);
+void connman_peer_unregister(struct connman_peer *peer);
+
+struct connman_peer *connman_peer_get(struct connman_device *device,
+						const char *identifier);
+
+typedef void (* peer_service_registration_cb_t) (int result, void *user_data);
+
+struct connman_peer_driver {
+	int (*connect) (struct connman_peer *peer,
+			enum connman_peer_wps_method wps_method,
+			const char *wps_pin);
+	int (*disconnect) (struct connman_peer *peer);
+	int (*register_service) (const unsigned char *specification,
+				int specification_length,
+				const unsigned char *query,
+				int query_length, int version,
+				peer_service_registration_cb_t callback,
+				void *user_data);
+	int (*unregister_service) (const unsigned char *specification,
+					int specification_length,
+					const unsigned char *query,
+					int query_length, int version);
+};
+
+int connman_peer_driver_register(struct connman_peer_driver *driver);
+void connman_peer_driver_unregister(struct connman_peer_driver *driver);
+
+bool connman_peer_service_is_master(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CONNMAN_PEER_H */
diff --git a/connman/include/plugin.h b/connman/include/plugin.h
new file mode 100644
index 0000000..8d2bb08
--- /dev/null
+++ b/connman/include/plugin.h
@@ -0,0 +1,107 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2012  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 __CONNMAN_PLUGIN_H
+#define __CONNMAN_PLUGIN_H
+
+#include <connman/version.h>
+#include <connman/log.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef CONNMAN_API_SUBJECT_TO_CHANGE
+#error "Please define CONNMAN_API_SUBJECT_TO_CHANGE to acknowledge your \
+understanding that ConnMan hasn't reached a stable API."
+#endif
+
+#define CONNMAN_PLUGIN_PRIORITY_LOW      -100
+#define CONNMAN_PLUGIN_PRIORITY_DEFAULT     0
+#define CONNMAN_PLUGIN_PRIORITY_HIGH      100
+
+/**
+ * SECTION:plugin
+ * @title: Plugin premitives
+ * @short_description: Functions for declaring plugins
+ */
+
+struct connman_plugin_desc {
+	const char *name;
+	const char *description;
+	const char *version;
+	int priority;
+	int (*init) (void);
+	void (*exit) (void);
+	void *debug_start;
+	void *debug_stop;
+};
+
+/**
+ * CONNMAN_PLUGIN_DEFINE:
+ * @name: plugin name
+ * @description: plugin description
+ * @version: plugin version string
+ * @init: init function called on plugin loading
+ * @exit: exit function called on plugin removal
+ *
+ * Macro for defining a plugin descriptor
+ *
+ * |[
+ * #include <connman/plugin.h>
+ *
+ * static int example_init(void)
+ * {
+ * 	return 0;
+ * }
+ *
+ * static void example_exit(void)
+ * {
+ * }
+ *
+ * CONNMAN_PLUGIN_DEFINE(example, "Example plugin", CONNMAN_VERSION,
+ * 					example_init, example_exit)
+ * ]|
+ */
+#ifdef CONNMAN_PLUGIN_BUILTIN
+#define CONNMAN_PLUGIN_DEFINE(name, description, version, priority, init, exit) \
+		struct connman_plugin_desc __connman_builtin_ ## name = { \
+			#name, description, version, priority, init, exit \
+		};
+#else
+#define CONNMAN_PLUGIN_DEFINE(name, description, version, priority, init, exit) \
+		extern struct connman_debug_desc __start___debug[] \
+				__attribute__ ((weak, visibility("hidden"))); \
+		extern struct connman_debug_desc __stop___debug[] \
+				__attribute__ ((weak, visibility("hidden"))); \
+		extern struct connman_plugin_desc connman_plugin_desc \
+				__attribute__ ((visibility("default"))); \
+		struct connman_plugin_desc connman_plugin_desc = { \
+			#name, description, version, priority, init, exit, \
+			__start___debug, __stop___debug \
+		};
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CONNMAN_PLUGIN_H */
diff --git a/connman/include/provider.h b/connman/include/provider.h
new file mode 100644
index 0000000..d1a8983
--- /dev/null
+++ b/connman/include/provider.h
@@ -0,0 +1,149 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2013  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 __CONNMAN_PROVIDER_H
+#define __CONNMAN_PROVIDER_H
+
+#include <stdbool.h>
+
+#include <glib.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * SECTION:provider
+ * @title: Provider premitives
+ * @short_description: Functions for handling providers
+ */
+
+enum connman_provider_type {
+	CONNMAN_PROVIDER_TYPE_UNKNOWN = 0,
+	CONNMAN_PROVIDER_TYPE_VPN     = 1,
+};
+
+enum connman_provider_state {
+	CONNMAN_PROVIDER_STATE_UNKNOWN       = 0,
+	CONNMAN_PROVIDER_STATE_IDLE          = 1,
+	CONNMAN_PROVIDER_STATE_CONNECT       = 2,
+	CONNMAN_PROVIDER_STATE_READY         = 3,
+	CONNMAN_PROVIDER_STATE_DISCONNECT    = 4,
+	CONNMAN_PROVIDER_STATE_FAILURE       = 5,
+};
+
+enum connman_provider_error {
+	CONNMAN_PROVIDER_ERROR_UNKNOWN		= 0,
+	CONNMAN_PROVIDER_ERROR_CONNECT_FAILED	= 1,
+	CONNMAN_PROVIDER_ERROR_LOGIN_FAILED	= 2,
+	CONNMAN_PROVIDER_ERROR_AUTH_FAILED	= 3,
+};
+
+enum connman_provider_route_type {
+	CONNMAN_PROVIDER_ROUTE_UNKNOWN = 0,
+	CONNMAN_PROVIDER_ROUTE_ALL = 0,
+	CONNMAN_PROVIDER_ROUTE_USER = 1,
+	CONNMAN_PROVIDER_ROUTE_SERVER = 2,
+};
+
+struct connman_provider;
+struct connman_ipaddress;
+
+#define connman_provider_ref(provider) \
+	connman_provider_ref_debug(provider, __FILE__, __LINE__, __func__)
+
+#define connman_provider_unref(provider) \
+	connman_provider_unref_debug(provider, __FILE__, __LINE__, __func__)
+
+struct connman_provider *
+connman_provider_ref_debug(struct connman_provider *provider,
+			const char *file, int line, const char *caller);
+void connman_provider_unref_debug(struct connman_provider *provider,
+			const char *file, int line, const char *caller);
+
+int connman_provider_disconnect(struct connman_provider *provider);
+int connman_provider_remove(struct connman_provider *provider);
+
+int connman_provider_set_string(struct connman_provider *provider,
+					const char *key, const char *value);
+const char *connman_provider_get_string(struct connman_provider *provider,
+							const char *key);
+
+int connman_provider_set_state(struct connman_provider *provider,
+					enum connman_provider_state state);
+
+int connman_provider_indicate_error(struct connman_provider *provider,
+					enum connman_provider_error error);
+
+void connman_provider_set_index(struct connman_provider *provider, int index);
+int connman_provider_get_index(struct connman_provider *provider);
+
+void connman_provider_set_data(struct connman_provider *provider, void *data);
+void *connman_provider_get_data(struct connman_provider *provider);
+int connman_provider_set_ipaddress(struct connman_provider *provider,
+					struct connman_ipaddress *ipaddress);
+int connman_provider_set_pac(struct connman_provider *provider,
+				const char *pac);
+int connman_provider_create_service(struct connman_provider *provider);
+int connman_provider_set_immutable(struct connman_provider *provider,
+						bool immutable);
+struct connman_provider *connman_provider_get(const char *identifier);
+void connman_provider_put(struct connman_provider *provider);
+int connman_provider_set_domain(struct connman_provider *provider,
+				const char *domain);
+int connman_provider_set_nameservers(struct connman_provider *provider,
+					char * const *nameservers);
+int connman_provider_append_route(struct connman_provider *provider,
+					const char *key, const char *value);
+
+const char *connman_provider_get_driver_name(struct connman_provider *provider);
+const char *connman_provider_get_save_group(struct connman_provider *provider);
+typedef void (* connection_ready_cb) (DBusMessage *msg, int error_code,
+					void *user_data);
+
+struct connman_provider_driver {
+	const char *name;
+	enum connman_provider_type type;
+	int (*probe) (struct connman_provider *provider);
+	int (*remove) (struct connman_provider *provider);
+	int (*connect) (struct connman_provider *provider);
+	int (*disconnect) (struct connman_provider *provider);
+	int (*save) (struct connman_provider *provider, GKeyFile *keyfile);
+	int (*set_property) (struct connman_provider *provider,
+				const char *key, const char *value);
+	const char * (*get_property) (struct connman_provider *provider,
+				const char *key);
+	int (*create) (DBusMessage *msg, connection_ready_cb callback);
+	int (*set_routes) (struct connman_provider *provider,
+				enum connman_provider_route_type type);
+	bool (*check_routes) (struct connman_provider *provider);
+};
+
+int connman_provider_driver_register(struct connman_provider_driver *driver);
+void connman_provider_driver_unregister(struct connman_provider_driver *driver);
+void connman_provider_set_driver(struct connman_provider *provider,
+				struct connman_provider_driver *driver);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CONNMAN_PROVIDER_H */
diff --git a/connman/include/provision.h b/connman/include/provision.h
new file mode 100644
index 0000000..3eb80a8
--- /dev/null
+++ b/connman/include/provision.h
@@ -0,0 +1,53 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2012-2013  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 __CONNMAN_PROVISION_H
+#define __CONNMAN_PROVISION_H
+
+#include <stdbool.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * SECTION:provision
+ * @title: Provisioned configuration premitives
+ * @short_description: Functions for provision configuration handling
+ */
+
+struct connman_config_entry {
+	char *ident;
+	char *name;
+	void *ssid;
+	unsigned int ssid_len;
+	bool hidden;
+};
+
+int connman_config_provision_mutable_service(GKeyFile *keyfile);
+struct connman_config_entry **connman_config_get_entries(const char *type);
+void connman_config_free_entries(struct connman_config_entry **entries);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CONNMAN_PROVISION_H */
diff --git a/connman/include/proxy.h b/connman/include/proxy.h
new file mode 100644
index 0000000..7842f65
--- /dev/null
+++ b/connman/include/proxy.h
@@ -0,0 +1,67 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2012  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 __CONNMAN_PROXY_H
+#define __CONNMAN_PROXY_H
+
+#include <connman/service.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * SECTION:proxy
+ * @title: Proxy premitives
+ * @short_description: Functions for handling proxy configuration
+ */
+
+typedef void (*connman_proxy_lookup_cb) (const char *proxy, void *user_data);
+
+unsigned int connman_proxy_lookup(const char *interface, const char *url,
+				struct connman_service *service,
+				connman_proxy_lookup_cb cb, void *user_data);
+void connman_proxy_lookup_cancel(unsigned int token);
+
+void connman_proxy_driver_lookup_notify(struct connman_service *service,
+					const char *url, const char *result);
+
+#define CONNMAN_PROXY_PRIORITY_LOW      -100
+#define CONNMAN_PROXY_PRIORITY_DEFAULT     0
+#define CONNMAN_PROXY_PRIORITY_HIGH      100
+
+struct connman_proxy_driver {
+	const char *name;
+	int priority;
+	int (*request_lookup) (struct connman_service *service,
+							const char *url);
+	void (*cancel_lookup) (struct connman_service *service,
+							const char *url);
+};
+
+int connman_proxy_driver_register(struct connman_proxy_driver *driver);
+void connman_proxy_driver_unregister(struct connman_proxy_driver *driver);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CONNMAN_PROXY_H */
diff --git a/connman/include/resolver.h b/connman/include/resolver.h
new file mode 100644
index 0000000..70a02ad
--- /dev/null
+++ b/connman/include/resolver.h
@@ -0,0 +1,47 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2012  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 __CONNMAN_RESOLVER_H
+#define __CONNMAN_RESOLVER_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * SECTION:resolver
+ * @title: Resolver premitives
+ * @short_description: Functions for registering resolver modules
+ */
+
+int connman_resolver_append(int index, const char *domain,
+							const char *server);
+int connman_resolver_append_lifetime(int index, const char *domain,
+				     const char *server, unsigned int lifetime);
+int connman_resolver_remove(int index, const char *domain,
+							const char *server);
+int connman_resolver_remove_all(int index);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CONNMAN_RESOLVER_H */
diff --git a/connman/include/rtnl.h b/connman/include/rtnl.h
new file mode 100644
index 0000000..aa70f4d
--- /dev/null
+++ b/connman/include/rtnl.h
@@ -0,0 +1,65 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2012  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 __CONNMAN_RTNL_H
+#define __CONNMAN_RTNL_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * SECTION:rtnl
+ * @title: RTNL premitives
+ * @short_description: Functions for registering RTNL modules
+ */
+
+typedef void (* connman_rtnl_link_cb_t) (unsigned flags, unsigned change,
+							void *user_data);
+
+unsigned int connman_rtnl_add_newlink_watch(int index,
+			connman_rtnl_link_cb_t callback, void *user_data);
+
+void connman_rtnl_remove_watch(unsigned int id);
+
+#define CONNMAN_RTNL_PRIORITY_LOW      -100
+#define CONNMAN_RTNL_PRIORITY_DEFAULT     0
+#define CONNMAN_RTNL_PRIORITY_HIGH      100
+
+struct connman_rtnl {
+	const char *name;
+	int priority;
+	void (*newlink) (unsigned short type, int index,
+					unsigned flags, unsigned change);
+	void (*dellink) (unsigned short type, int index,
+					unsigned flags, unsigned change);
+	void (*newgateway) (int index, const char *gateway);
+	void (*delgateway) (int index, const char *gateway);
+};
+
+int connman_rtnl_register(struct connman_rtnl *rtnl);
+void connman_rtnl_unregister(struct connman_rtnl *rtnl);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CONNMAN_RTNL_H */
diff --git a/connman/include/service.h b/connman/include/service.h
new file mode 100644
index 0000000..45bc876
--- /dev/null
+++ b/connman/include/service.h
@@ -0,0 +1,151 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2014  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 __CONNMAN_SERVICE_H
+#define __CONNMAN_SERVICE_H
+
+#include <stdbool.h>
+#include <connman/ipconfig.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * SECTION:service
+ * @title: Service premitives
+ * @short_description: Functions for handling services
+ */
+
+enum connman_service_type {
+	CONNMAN_SERVICE_TYPE_UNKNOWN   = 0,
+	CONNMAN_SERVICE_TYPE_SYSTEM    = 1,
+	CONNMAN_SERVICE_TYPE_ETHERNET  = 2,
+	CONNMAN_SERVICE_TYPE_WIFI      = 3,
+	CONNMAN_SERVICE_TYPE_BLUETOOTH = 4,
+	CONNMAN_SERVICE_TYPE_CELLULAR  = 5,
+	CONNMAN_SERVICE_TYPE_GPS       = 6,
+	CONNMAN_SERVICE_TYPE_VPN       = 7,
+	CONNMAN_SERVICE_TYPE_GADGET    = 8,
+	CONNMAN_SERVICE_TYPE_P2P       = 9,
+	CONNMAN_SERVICE_TYPE_LOWPAN    = 10
+};
+#define	MAX_CONNMAN_SERVICE_TYPES        11
+
+
+enum connman_service_security {
+	CONNMAN_SERVICE_SECURITY_UNKNOWN = 0,
+	CONNMAN_SERVICE_SECURITY_NONE    = 1,
+	CONNMAN_SERVICE_SECURITY_WEP     = 2,
+	CONNMAN_SERVICE_SECURITY_PSK     = 3,
+	CONNMAN_SERVICE_SECURITY_8021X   = 4,
+	CONNMAN_SERVICE_SECURITY_WPA     = 8,
+	CONNMAN_SERVICE_SECURITY_RSN     = 9,
+};
+
+enum connman_service_state {
+	CONNMAN_SERVICE_STATE_UNKNOWN       = 0,
+	CONNMAN_SERVICE_STATE_IDLE          = 1,
+	CONNMAN_SERVICE_STATE_ASSOCIATION   = 2,
+	CONNMAN_SERVICE_STATE_CONFIGURATION = 3,
+	CONNMAN_SERVICE_STATE_READY         = 4,
+	CONNMAN_SERVICE_STATE_ONLINE        = 5,
+	CONNMAN_SERVICE_STATE_DISCONNECT    = 6,
+	CONNMAN_SERVICE_STATE_FAILURE       = 7,
+};
+
+enum connman_service_error {
+	CONNMAN_SERVICE_ERROR_UNKNOWN        = 0,
+	CONNMAN_SERVICE_ERROR_OUT_OF_RANGE   = 1,
+	CONNMAN_SERVICE_ERROR_PIN_MISSING    = 2,
+	CONNMAN_SERVICE_ERROR_DHCP_FAILED    = 3,
+	CONNMAN_SERVICE_ERROR_CONNECT_FAILED = 4,
+	CONNMAN_SERVICE_ERROR_LOGIN_FAILED  = 5,
+	CONNMAN_SERVICE_ERROR_AUTH_FAILED    = 6,
+	CONNMAN_SERVICE_ERROR_INVALID_KEY    = 7,
+};
+
+enum connman_service_proxy_method {
+	CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN     = 0,
+	CONNMAN_SERVICE_PROXY_METHOD_DIRECT      = 1,
+	CONNMAN_SERVICE_PROXY_METHOD_MANUAL      = 2,
+	CONNMAN_SERVICE_PROXY_METHOD_AUTO        = 3,
+};
+
+enum connman_service_connect_reason {
+	CONNMAN_SERVICE_CONNECT_REASON_NONE	= 0,
+	CONNMAN_SERVICE_CONNECT_REASON_AUTO	= 1,
+	CONNMAN_SERVICE_CONNECT_REASON_USER	= 2,
+	CONNMAN_SERVICE_CONNECT_REASON_SESSION	= 3,
+};
+
+struct connman_service;
+struct connman_network;
+
+struct connman_service *connman_service_create(void);
+
+#define connman_service_ref(service) \
+	connman_service_ref_debug(service, __FILE__, __LINE__, __func__)
+
+#define connman_service_unref(service) \
+	connman_service_unref_debug(service, __FILE__, __LINE__, __func__)
+
+struct connman_service *
+connman_service_ref_debug(struct connman_service *service,
+			const char *file, int line, const char *caller);
+void connman_service_unref_debug(struct connman_service *service,
+			const char *file, int line, const char *caller);
+
+enum connman_service_type connman_service_get_type(struct connman_service *service);
+char *connman_service_get_interface(struct connman_service *service);
+
+const char *connman_service_get_domainname(struct connman_service *service);
+char **connman_service_get_nameservers(struct connman_service *service);
+char **connman_service_get_timeservers_config(struct connman_service *service);
+char **connman_service_get_timeservers(struct connman_service *service);
+void connman_service_set_proxy_method(struct connman_service *service, enum connman_service_proxy_method method);
+enum connman_service_proxy_method connman_service_get_proxy_method(struct connman_service *service);
+char **connman_service_get_proxy_servers(struct connman_service *service);
+char **connman_service_get_proxy_excludes(struct connman_service *service);
+const char *connman_service_get_proxy_url(struct connman_service *service);
+const char *connman_service_get_proxy_autoconfig(struct connman_service *service);
+bool connman_service_get_favorite(struct connman_service *service);
+bool connman_service_get_autoconnect(struct connman_service *service);
+
+struct connman_service *connman_service_lookup_from_network(struct connman_network *network);
+
+void connman_service_create_ip4config(struct connman_service *service,
+								int index);
+void connman_service_create_ip6config(struct connman_service *service,
+								int index);
+
+int connman_service_connect(struct connman_service *service, enum connman_service_connect_reason reason);
+int connman_service_disconnect(struct connman_service *service);
+
+int connman_service_ipconfig_indicate_state(struct connman_service *service,
+					enum connman_service_state new_state,
+					enum connman_ipconfig_type type);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CONNMAN_SERVICE_H */
diff --git a/connman/include/session.h b/connman/include/session.h
new file mode 100644
index 0000000..37dfc4e
--- /dev/null
+++ b/connman/include/session.h
@@ -0,0 +1,110 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2012-2014  BMW Car IT GmbH.
+ *
+ *  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 __CONNMAN_SESSION_H
+#define __CONNMAN_SESSION_H
+
+#include <connman/service.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define CONNMAN_SESSION_POLICY_PRIORITY_LOW      -100
+#define CONNMAN_SESSION_POLICY_PRIORITY_DEFAULT     0
+#define CONNMAN_SESSION_POLICY_PRIORITY_HIGH      100
+
+enum connman_session_roaming_policy {
+	CONNMAN_SESSION_ROAMING_POLICY_UNKNOWN		= 0,
+	CONNMAN_SESSION_ROAMING_POLICY_DEFAULT		= 1,
+	CONNMAN_SESSION_ROAMING_POLICY_ALWAYS		= 2,
+	CONNMAN_SESSION_ROAMING_POLICY_FORBIDDEN	= 3,
+	CONNMAN_SESSION_ROAMING_POLICY_NATIONAL		= 4,
+	CONNMAN_SESSION_ROAMING_POLICY_INTERNATIONAL	= 5,
+};
+
+enum connman_session_type {
+	CONNMAN_SESSION_TYPE_UNKNOWN  = 0,
+	CONNMAN_SESSION_TYPE_ANY      = 1,
+	CONNMAN_SESSION_TYPE_LOCAL    = 2,
+	CONNMAN_SESSION_TYPE_INTERNET = 3,
+};
+
+enum connman_session_id_type {
+	CONNMAN_SESSION_ID_TYPE_UNKNOWN = 0,
+	CONNMAN_SESSION_ID_TYPE_UID	= 1,
+	CONNMAN_SESSION_ID_TYPE_GID	= 2,
+	CONNMAN_SESSION_ID_TYPE_LSM	= 3,
+};
+
+struct connman_session;
+
+struct connman_session_config {
+	enum connman_session_id_type id_type;
+	char *id;
+	bool priority;
+	enum connman_session_roaming_policy roaming_policy;
+	enum connman_session_type type;
+	bool ecall;
+	GSList *allowed_bearers;
+};
+
+typedef int (* connman_session_config_func_t) (struct connman_session *session,
+					struct connman_session_config *config,
+					void *user_data, int err);
+
+struct connman_session_policy {
+	const char *name;
+	int priority;
+	bool (*autoconnect)(enum connman_service_connect_reason reason);
+	int (*create)(struct connman_session *session,
+			connman_session_config_func_t cb,
+			void *user_data);
+	void (*destroy)(struct connman_session *session);
+	void (*session_changed)(struct connman_session *session, bool active,
+				GSList *bearers);
+	bool (*allowed)(struct connman_session *session,
+			struct connman_service *service);
+};
+
+int connman_session_policy_register(struct connman_session_policy *config);
+void connman_session_policy_unregister(struct connman_session_policy *config);
+
+int connman_session_config_update(struct connman_session *session);
+void connman_session_destroy(struct connman_session *session);
+
+void connman_session_set_default_config(struct connman_session_config *config);
+struct connman_session_config *connman_session_create_default_config(void);
+
+enum connman_session_roaming_policy connman_session_parse_roaming_policy(const char *policy);
+enum connman_session_type connman_session_parse_connection_type(const char *type);
+int connman_session_parse_bearers(const char *token, GSList **list);
+
+const char *connman_session_get_owner(struct connman_session *session);
+
+int connman_session_connect(struct connman_service *service);
+int connman_session_disconnect(struct connman_service *service);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CONNMAN_SESSION_H */
diff --git a/connman/include/setting.h b/connman/include/setting.h
new file mode 100644
index 0000000..a882021
--- /dev/null
+++ b/connman/include/setting.h
@@ -0,0 +1,42 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2012  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 __CONNMAN_SETTING_H
+#define __CONNMAN_SETTING_H
+
+#include <stdbool.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+bool connman_setting_get_bool(const char *key);
+char **connman_setting_get_string_list(const char *key);
+unsigned int *connman_setting_get_uint_list(const char *key);
+
+unsigned int connman_timeout_input_request(void);
+unsigned int connman_timeout_browser_launch(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CONNMAN_SETTING_H */
diff --git a/connman/include/storage.h b/connman/include/storage.h
new file mode 100644
index 0000000..4c23a14
--- /dev/null
+++ b/connman/include/storage.h
@@ -0,0 +1,38 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2012  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 __CONNMAN_STORAGE_H
+#define __CONNMAN_STORAGE_H
+
+#include <glib.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+gchar **connman_storage_get_services();
+GKeyFile *connman_storage_load_service(const char *service_id);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CONNMAN_STORAGE_H */
diff --git a/connman/include/task.h b/connman/include/task.h
new file mode 100644
index 0000000..9977d63
--- /dev/null
+++ b/connman/include/task.h
@@ -0,0 +1,67 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2012  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 __CONNMAN_TASK_H
+#define __CONNMAN_TASK_H
+
+#include <dbus/dbus.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * SECTION:task
+ * @title: Task premitives
+ * @short_description: Functions for handling tasks
+ */
+
+struct connman_task;
+
+typedef void (* connman_task_exit_t) (struct connman_task *task,
+						int exit_code, void *user_data);
+
+typedef DBusMessage * (* connman_task_notify_t) (struct connman_task *task,
+				DBusMessage *message, void *user_data);
+
+struct connman_task *connman_task_create(const char *program);
+void connman_task_destroy(struct connman_task *task);
+
+const char *connman_task_get_path(struct connman_task *task);
+
+int connman_task_add_argument(struct connman_task *task,
+				const char *name, const char *format, ...);
+int connman_task_add_variable(struct connman_task *task,
+				const char *key, const char *format, ...);
+
+int connman_task_set_notify(struct connman_task *task, const char *member,
+			connman_task_notify_t function, void *user_data);
+
+int connman_task_run(struct connman_task *task,
+			connman_task_exit_t function, void *user_data,
+			int *stdin_fd, int *stdout_fd, int *stderr_fd);
+int connman_task_stop(struct connman_task *task);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CONNMAN_TASK_H */
diff --git a/connman/include/technology.h b/connman/include/technology.h
new file mode 100644
index 0000000..d7fcdde
--- /dev/null
+++ b/connman/include/technology.h
@@ -0,0 +1,74 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2013  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 __CONNMAN_TECHNOLOGY_H
+#define __CONNMAN_TECHNOLOGY_H
+
+#include <connman/service.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * SECTION:technology
+ * @title: technology premitives
+ * @short_description: Functions for handling technology details
+ */
+
+struct connman_technology;
+
+void connman_technology_tethering_notify(struct connman_technology *technology,
+							bool enabled);
+int connman_technology_set_regdom(const char *alpha2);
+void connman_technology_regdom_notify(struct connman_technology *technology,
+							const char *alpha2);
+
+bool connman_technology_get_wifi_tethering(const char **ssid,
+							const char **psk);
+bool connman_technology_is_tethering_allowed(enum connman_service_type type);
+
+struct connman_technology_driver {
+	const char *name;
+	enum connman_service_type type;
+	int priority;
+	int (*probe) (struct connman_technology *technology);
+	void (*remove) (struct connman_technology *technology);
+	void (*add_interface) (struct connman_technology *technology,
+						int index, const char *name,
+							const char *ident);
+	void (*remove_interface) (struct connman_technology *technology,
+								int index);
+	int (*set_tethering) (struct connman_technology *technology,
+				const char *identifier, const char *passphrase,
+				const char *bridge, bool enabled);
+	int (*set_regdom) (struct connman_technology *technology,
+						const char *alpha2);
+};
+
+int connman_technology_driver_register(struct connman_technology_driver *driver);
+void connman_technology_driver_unregister(struct connman_technology_driver *driver);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CONNMAN_TECHNOLOGY_H */
diff --git a/connman/include/timeserver.h b/connman/include/timeserver.h
new file mode 100644
index 0000000..48ea194
--- /dev/null
+++ b/connman/include/timeserver.h
@@ -0,0 +1,35 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2012  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 __CONNMAN_TIMESERVER_H
+#define __CONNMAN_TIMESERVER_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int __connman_timeserver_system_set(char **server);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CONNMAN_TIMESERVER_H */
diff --git a/connman/include/utsname.h b/connman/include/utsname.h
new file mode 100644
index 0000000..b8165f6
--- /dev/null
+++ b/connman/include/utsname.h
@@ -0,0 +1,52 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2012  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 __CONNMAN_UTSNAME_H
+#define __CONNMAN_UTSNAME_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * SECTION:utsname
+ * @title: utsname premitives
+ * @short_description: Functions for handling utsname
+ */
+
+const char *connman_utsname_get_hostname(void);
+
+struct connman_utsname_driver {
+	const char *name;
+	int priority;
+	const char * (*get_hostname) (void);
+	int (*set_hostname) (const char *hostname);
+	int (*set_domainname) (const char *domainname);
+};
+
+int connman_utsname_driver_register(struct connman_utsname_driver *driver);
+void connman_utsname_driver_unregister(struct connman_utsname_driver *driver);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CONNMAN_UTSNAME_H */
diff --git a/connman/include/version.h.in b/connman/include/version.h.in
new file mode 100644
index 0000000..d3d6dd3
--- /dev/null
+++ b/connman/include/version.h.in
@@ -0,0 +1,35 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2012  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 __CONNMAN_VERSION_H
+#define __CONNMAN_VERSION_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define CONNMAN_VERSION	"@VERSION@"
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CONNMAN_VERSION_H */
diff --git a/connman/include/vpn-dbus.h b/connman/include/vpn-dbus.h
new file mode 100644
index 0000000..01780cb
--- /dev/null
+++ b/connman/include/vpn-dbus.h
@@ -0,0 +1,58 @@
+/*
+ *
+ *  ConnMan VPN daemon
+ *
+ *  Copyright (C) 2007-2012  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 __VPN_DBUS_H
+#define __VPN_DBUS_H
+
+#include <dbus/dbus.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define VPN_SERVICE			"net.connman.vpn"
+#define VPN_PATH			"/net/connman/vpn"
+
+#define VPN_ERROR_INTERFACE		VPN_SERVICE ".Error"
+
+#define VPN_MANAGER_INTERFACE		VPN_SERVICE ".Manager"
+#define VPN_MANAGER_PATH		"/"
+
+#define VPN_CONNECTION_INTERFACE	VPN_SERVICE ".Connection"
+#define VPN_AGENT_INTERFACE		VPN_SERVICE ".Agent"
+#define VPN_TASK_INTERFACE		VPN_SERVICE ".Task"
+
+#define VPN_PRIVILEGE_MODIFY		1
+#define VPN_PRIVILEGE_SECRET		2
+
+#define CONNECTION_ADDED		"ConnectionAdded"
+#define CONNECTION_REMOVED		"ConnectionRemoved"
+#define PROPERTY_CHANGED		"PropertyChanged"
+#define GET_CONNECTIONS			"GetConnections"
+#define VPN_CONNECT			"Connect"
+#define VPN_DISCONNECT			"Disconnect"
+#define VPN_REMOVE			"Remove"
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __VPN_DBUS_H */
diff --git a/connman/install-sh b/connman/install-sh
new file mode 100755
index 0000000..377bb86
--- /dev/null
+++ b/connman/install-sh
@@ -0,0 +1,527 @@
+#!/bin/sh
+# install - install a program, script, or datafile
+
+scriptversion=2011-11-20.07; # UTC
+
+# This originates from X11R5 (mit/util/scripts/install.sh), which was
+# later released in X11R6 (xc/config/util/install.sh) with the
+# following copyright and license.
+#
+# Copyright (C) 1994 X Consortium
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to
+# deal in the Software without restriction, including without limitation the
+# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+# sell copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
+# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+# Except as contained in this notice, the name of the X Consortium shall not
+# be used in advertising or otherwise to promote the sale, use or other deal-
+# ings in this Software without prior written authorization from the X Consor-
+# tium.
+#
+#
+# FSF changes to this file are in the public domain.
+#
+# Calling this script install-sh is preferred over install.sh, to prevent
+# 'make' implicit rules from creating a file called install from it
+# when there is no Makefile.
+#
+# This script is compatible with the BSD install script, but was written
+# from scratch.
+
+nl='
+'
+IFS=" ""	$nl"
+
+# set DOITPROG to echo to test this script
+
+# Don't use :- since 4.3BSD and earlier shells don't like it.
+doit=${DOITPROG-}
+if test -z "$doit"; then
+  doit_exec=exec
+else
+  doit_exec=$doit
+fi
+
+# Put in absolute file names if you don't have them in your path;
+# or use environment vars.
+
+chgrpprog=${CHGRPPROG-chgrp}
+chmodprog=${CHMODPROG-chmod}
+chownprog=${CHOWNPROG-chown}
+cmpprog=${CMPPROG-cmp}
+cpprog=${CPPROG-cp}
+mkdirprog=${MKDIRPROG-mkdir}
+mvprog=${MVPROG-mv}
+rmprog=${RMPROG-rm}
+stripprog=${STRIPPROG-strip}
+
+posix_glob='?'
+initialize_posix_glob='
+  test "$posix_glob" != "?" || {
+    if (set -f) 2>/dev/null; then
+      posix_glob=
+    else
+      posix_glob=:
+    fi
+  }
+'
+
+posix_mkdir=
+
+# Desired mode of installed file.
+mode=0755
+
+chgrpcmd=
+chmodcmd=$chmodprog
+chowncmd=
+mvcmd=$mvprog
+rmcmd="$rmprog -f"
+stripcmd=
+
+src=
+dst=
+dir_arg=
+dst_arg=
+
+copy_on_change=false
+no_target_directory=
+
+usage="\
+Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE
+   or: $0 [OPTION]... SRCFILES... DIRECTORY
+   or: $0 [OPTION]... -t DIRECTORY SRCFILES...
+   or: $0 [OPTION]... -d DIRECTORIES...
+
+In the 1st form, copy SRCFILE to DSTFILE.
+In the 2nd and 3rd, copy all SRCFILES to DIRECTORY.
+In the 4th, create DIRECTORIES.
+
+Options:
+     --help     display this help and exit.
+     --version  display version info and exit.
+
+  -c            (ignored)
+  -C            install only if different (preserve the last data modification time)
+  -d            create directories instead of installing files.
+  -g GROUP      $chgrpprog installed files to GROUP.
+  -m MODE       $chmodprog installed files to MODE.
+  -o USER       $chownprog installed files to USER.
+  -s            $stripprog installed files.
+  -t DIRECTORY  install into DIRECTORY.
+  -T            report an error if DSTFILE is a directory.
+
+Environment variables override the default commands:
+  CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG
+  RMPROG STRIPPROG
+"
+
+while test $# -ne 0; do
+  case $1 in
+    -c) ;;
+
+    -C) copy_on_change=true;;
+
+    -d) dir_arg=true;;
+
+    -g) chgrpcmd="$chgrpprog $2"
+	shift;;
+
+    --help) echo "$usage"; exit $?;;
+
+    -m) mode=$2
+	case $mode in
+	  *' '* | *'	'* | *'
+'*	  | *'*'* | *'?'* | *'['*)
+	    echo "$0: invalid mode: $mode" >&2
+	    exit 1;;
+	esac
+	shift;;
+
+    -o) chowncmd="$chownprog $2"
+	shift;;
+
+    -s) stripcmd=$stripprog;;
+
+    -t) dst_arg=$2
+	# Protect names problematic for 'test' and other utilities.
+	case $dst_arg in
+	  -* | [=\(\)!]) dst_arg=./$dst_arg;;
+	esac
+	shift;;
+
+    -T) no_target_directory=true;;
+
+    --version) echo "$0 $scriptversion"; exit $?;;
+
+    --)	shift
+	break;;
+
+    -*)	echo "$0: invalid option: $1" >&2
+	exit 1;;
+
+    *)  break;;
+  esac
+  shift
+done
+
+if test $# -ne 0 && test -z "$dir_arg$dst_arg"; then
+  # When -d is used, all remaining arguments are directories to create.
+  # When -t is used, the destination is already specified.
+  # Otherwise, the last argument is the destination.  Remove it from $@.
+  for arg
+  do
+    if test -n "$dst_arg"; then
+      # $@ is not empty: it contains at least $arg.
+      set fnord "$@" "$dst_arg"
+      shift # fnord
+    fi
+    shift # arg
+    dst_arg=$arg
+    # Protect names problematic for 'test' and other utilities.
+    case $dst_arg in
+      -* | [=\(\)!]) dst_arg=./$dst_arg;;
+    esac
+  done
+fi
+
+if test $# -eq 0; then
+  if test -z "$dir_arg"; then
+    echo "$0: no input file specified." >&2
+    exit 1
+  fi
+  # It's OK to call 'install-sh -d' without argument.
+  # This can happen when creating conditional directories.
+  exit 0
+fi
+
+if test -z "$dir_arg"; then
+  do_exit='(exit $ret); exit $ret'
+  trap "ret=129; $do_exit" 1
+  trap "ret=130; $do_exit" 2
+  trap "ret=141; $do_exit" 13
+  trap "ret=143; $do_exit" 15
+
+  # Set umask so as not to create temps with too-generous modes.
+  # However, 'strip' requires both read and write access to temps.
+  case $mode in
+    # Optimize common cases.
+    *644) cp_umask=133;;
+    *755) cp_umask=22;;
+
+    *[0-7])
+      if test -z "$stripcmd"; then
+	u_plus_rw=
+      else
+	u_plus_rw='% 200'
+      fi
+      cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;;
+    *)
+      if test -z "$stripcmd"; then
+	u_plus_rw=
+      else
+	u_plus_rw=,u+rw
+      fi
+      cp_umask=$mode$u_plus_rw;;
+  esac
+fi
+
+for src
+do
+  # Protect names problematic for 'test' and other utilities.
+  case $src in
+    -* | [=\(\)!]) src=./$src;;
+  esac
+
+  if test -n "$dir_arg"; then
+    dst=$src
+    dstdir=$dst
+    test -d "$dstdir"
+    dstdir_status=$?
+  else
+
+    # Waiting for this to be detected by the "$cpprog $src $dsttmp" command
+    # might cause directories to be created, which would be especially bad
+    # if $src (and thus $dsttmp) contains '*'.
+    if test ! -f "$src" && test ! -d "$src"; then
+      echo "$0: $src does not exist." >&2
+      exit 1
+    fi
+
+    if test -z "$dst_arg"; then
+      echo "$0: no destination specified." >&2
+      exit 1
+    fi
+    dst=$dst_arg
+
+    # If destination is a directory, append the input filename; won't work
+    # if double slashes aren't ignored.
+    if test -d "$dst"; then
+      if test -n "$no_target_directory"; then
+	echo "$0: $dst_arg: Is a directory" >&2
+	exit 1
+      fi
+      dstdir=$dst
+      dst=$dstdir/`basename "$src"`
+      dstdir_status=0
+    else
+      # Prefer dirname, but fall back on a substitute if dirname fails.
+      dstdir=`
+	(dirname "$dst") 2>/dev/null ||
+	expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+	     X"$dst" : 'X\(//\)[^/]' \| \
+	     X"$dst" : 'X\(//\)$' \| \
+	     X"$dst" : 'X\(/\)' \| . 2>/dev/null ||
+	echo X"$dst" |
+	    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+		   s//\1/
+		   q
+		 }
+		 /^X\(\/\/\)[^/].*/{
+		   s//\1/
+		   q
+		 }
+		 /^X\(\/\/\)$/{
+		   s//\1/
+		   q
+		 }
+		 /^X\(\/\).*/{
+		   s//\1/
+		   q
+		 }
+		 s/.*/./; q'
+      `
+
+      test -d "$dstdir"
+      dstdir_status=$?
+    fi
+  fi
+
+  obsolete_mkdir_used=false
+
+  if test $dstdir_status != 0; then
+    case $posix_mkdir in
+      '')
+	# Create intermediate dirs using mode 755 as modified by the umask.
+	# This is like FreeBSD 'install' as of 1997-10-28.
+	umask=`umask`
+	case $stripcmd.$umask in
+	  # Optimize common cases.
+	  *[2367][2367]) mkdir_umask=$umask;;
+	  .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;;
+
+	  *[0-7])
+	    mkdir_umask=`expr $umask + 22 \
+	      - $umask % 100 % 40 + $umask % 20 \
+	      - $umask % 10 % 4 + $umask % 2
+	    `;;
+	  *) mkdir_umask=$umask,go-w;;
+	esac
+
+	# With -d, create the new directory with the user-specified mode.
+	# Otherwise, rely on $mkdir_umask.
+	if test -n "$dir_arg"; then
+	  mkdir_mode=-m$mode
+	else
+	  mkdir_mode=
+	fi
+
+	posix_mkdir=false
+	case $umask in
+	  *[123567][0-7][0-7])
+	    # POSIX mkdir -p sets u+wx bits regardless of umask, which
+	    # is incompatible with FreeBSD 'install' when (umask & 300) != 0.
+	    ;;
+	  *)
+	    tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$
+	    trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0
+
+	    if (umask $mkdir_umask &&
+		exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1
+	    then
+	      if test -z "$dir_arg" || {
+		   # Check for POSIX incompatibilities with -m.
+		   # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or
+		   # other-writable bit of parent directory when it shouldn't.
+		   # FreeBSD 6.1 mkdir -m -p sets mode of existing directory.
+		   ls_ld_tmpdir=`ls -ld "$tmpdir"`
+		   case $ls_ld_tmpdir in
+		     d????-?r-*) different_mode=700;;
+		     d????-?--*) different_mode=755;;
+		     *) false;;
+		   esac &&
+		   $mkdirprog -m$different_mode -p -- "$tmpdir" && {
+		     ls_ld_tmpdir_1=`ls -ld "$tmpdir"`
+		     test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1"
+		   }
+		 }
+	      then posix_mkdir=:
+	      fi
+	      rmdir "$tmpdir/d" "$tmpdir"
+	    else
+	      # Remove any dirs left behind by ancient mkdir implementations.
+	      rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null
+	    fi
+	    trap '' 0;;
+	esac;;
+    esac
+
+    if
+      $posix_mkdir && (
+	umask $mkdir_umask &&
+	$doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir"
+      )
+    then :
+    else
+
+      # The umask is ridiculous, or mkdir does not conform to POSIX,
+      # or it failed possibly due to a race condition.  Create the
+      # directory the slow way, step by step, checking for races as we go.
+
+      case $dstdir in
+	/*) prefix='/';;
+	[-=\(\)!]*) prefix='./';;
+	*)  prefix='';;
+      esac
+
+      eval "$initialize_posix_glob"
+
+      oIFS=$IFS
+      IFS=/
+      $posix_glob set -f
+      set fnord $dstdir
+      shift
+      $posix_glob set +f
+      IFS=$oIFS
+
+      prefixes=
+
+      for d
+      do
+	test X"$d" = X && continue
+
+	prefix=$prefix$d
+	if test -d "$prefix"; then
+	  prefixes=
+	else
+	  if $posix_mkdir; then
+	    (umask=$mkdir_umask &&
+	     $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break
+	    # Don't fail if two instances are running concurrently.
+	    test -d "$prefix" || exit 1
+	  else
+	    case $prefix in
+	      *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;;
+	      *) qprefix=$prefix;;
+	    esac
+	    prefixes="$prefixes '$qprefix'"
+	  fi
+	fi
+	prefix=$prefix/
+      done
+
+      if test -n "$prefixes"; then
+	# Don't fail if two instances are running concurrently.
+	(umask $mkdir_umask &&
+	 eval "\$doit_exec \$mkdirprog $prefixes") ||
+	  test -d "$dstdir" || exit 1
+	obsolete_mkdir_used=true
+      fi
+    fi
+  fi
+
+  if test -n "$dir_arg"; then
+    { test -z "$chowncmd" || $doit $chowncmd "$dst"; } &&
+    { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } &&
+    { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false ||
+      test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1
+  else
+
+    # Make a couple of temp file names in the proper directory.
+    dsttmp=$dstdir/_inst.$$_
+    rmtmp=$dstdir/_rm.$$_
+
+    # Trap to clean up those temp files at exit.
+    trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0
+
+    # Copy the file name to the temp name.
+    (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") &&
+
+    # and set any options; do chmod last to preserve setuid bits.
+    #
+    # If any of these fail, we abort the whole thing.  If we want to
+    # ignore errors from any of these, just make sure not to ignore
+    # errors from the above "$doit $cpprog $src $dsttmp" command.
+    #
+    { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } &&
+    { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } &&
+    { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } &&
+    { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } &&
+
+    # If -C, don't bother to copy if it wouldn't change the file.
+    if $copy_on_change &&
+       old=`LC_ALL=C ls -dlL "$dst"	2>/dev/null` &&
+       new=`LC_ALL=C ls -dlL "$dsttmp"	2>/dev/null` &&
+
+       eval "$initialize_posix_glob" &&
+       $posix_glob set -f &&
+       set X $old && old=:$2:$4:$5:$6 &&
+       set X $new && new=:$2:$4:$5:$6 &&
+       $posix_glob set +f &&
+
+       test "$old" = "$new" &&
+       $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1
+    then
+      rm -f "$dsttmp"
+    else
+      # Rename the file to the real destination.
+      $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null ||
+
+      # The rename failed, perhaps because mv can't rename something else
+      # to itself, or perhaps because mv is so ancient that it does not
+      # support -f.
+      {
+	# Now remove or move aside any old file at destination location.
+	# We try this two ways since rm can't unlink itself on some
+	# systems and the destination file might be busy for other
+	# reasons.  In this case, the final cleanup might fail but the new
+	# file should still install successfully.
+	{
+	  test ! -f "$dst" ||
+	  $doit $rmcmd -f "$dst" 2>/dev/null ||
+	  { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null &&
+	    { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; }
+	  } ||
+	  { echo "$0: cannot unlink or rename $dst" >&2
+	    (exit 1); exit 1
+	  }
+	} &&
+
+	# Now rename the file to the real destination.
+	$doit $mvcmd "$dsttmp" "$dst"
+      }
+    fi || exit 1
+
+    trap '' 0
+  fi
+done
+
+# Local variables:
+# eval: (add-hook 'write-file-hooks 'time-stamp)
+# time-stamp-start: "scriptversion="
+# time-stamp-format: "%:y-%02m-%02d.%02H"
+# time-stamp-time-zone: "UTC"
+# time-stamp-end: "; # UTC"
+# End:
diff --git a/connman/ltmain.sh b/connman/ltmain.sh
new file mode 100644
index 0000000..a356aca
--- /dev/null
+++ b/connman/ltmain.sh
@@ -0,0 +1,9661 @@
+
+# libtool (GNU libtool) 2.4.2
+# Written by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996
+
+# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006,
+# 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
+# This is free software; see the source for copying conditions.  There is NO
+# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+# GNU Libtool is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# As a special exception to the GNU General Public License,
+# if you distribute this file as part of a program or library that
+# is built using GNU Libtool, you may include this file under the
+# same distribution terms that you use for the rest of that program.
+#
+# GNU Libtool 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 GNU Libtool; see the file COPYING.  If not, a copy
+# can be downloaded from http://www.gnu.org/licenses/gpl.html,
+# or obtained by writing to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+# Usage: $progname [OPTION]... [MODE-ARG]...
+#
+# Provide generalized library-building support services.
+#
+#       --config             show all configuration variables
+#       --debug              enable verbose shell tracing
+#   -n, --dry-run            display commands without modifying any files
+#       --features           display basic configuration information and exit
+#       --mode=MODE          use operation mode MODE
+#       --preserve-dup-deps  don't remove duplicate dependency libraries
+#       --quiet, --silent    don't print informational messages
+#       --no-quiet, --no-silent
+#                            print informational messages (default)
+#       --no-warn            don't display warning messages
+#       --tag=TAG            use configuration variables from tag TAG
+#   -v, --verbose            print more informational messages than default
+#       --no-verbose         don't print the extra informational messages
+#       --version            print version information
+#   -h, --help, --help-all   print short, long, or detailed help message
+#
+# MODE must be one of the following:
+#
+#         clean              remove files from the build directory
+#         compile            compile a source file into a libtool object
+#         execute            automatically set library path, then run a program
+#         finish             complete the installation of libtool libraries
+#         install            install libraries or executables
+#         link               create a library or an executable
+#         uninstall          remove libraries from an installed directory
+#
+# MODE-ARGS vary depending on the MODE.  When passed as first option,
+# `--mode=MODE' may be abbreviated as `MODE' or a unique abbreviation of that.
+# Try `$progname --help --mode=MODE' for a more detailed description of MODE.
+#
+# When reporting a bug, please describe a test case to reproduce it and
+# include the following information:
+#
+#         host-triplet:	$host
+#         shell:		$SHELL
+#         compiler:		$LTCC
+#         compiler flags:		$LTCFLAGS
+#         linker:		$LD (gnu? $with_gnu_ld)
+#         $progname:	(GNU libtool) 2.4.2 Debian-2.4.2-1.7ubuntu1
+#         automake:	$automake_version
+#         autoconf:	$autoconf_version
+#
+# Report bugs to <bug-libtool@gnu.org>.
+# GNU libtool home page: <http://www.gnu.org/software/libtool/>.
+# General help using GNU software: <http://www.gnu.org/gethelp/>.
+
+PROGRAM=libtool
+PACKAGE=libtool
+VERSION="2.4.2 Debian-2.4.2-1.7ubuntu1"
+TIMESTAMP=""
+package_revision=1.3337
+
+# Be Bourne compatible
+if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
+  emulate sh
+  NULLCMD=:
+  # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which
+  # is contrary to our usage.  Disable this feature.
+  alias -g '${1+"$@"}'='"$@"'
+  setopt NO_GLOB_SUBST
+else
+  case `(set -o) 2>/dev/null` in *posix*) set -o posix;; esac
+fi
+BIN_SH=xpg4; export BIN_SH # for Tru64
+DUALCASE=1; export DUALCASE # for MKS sh
+
+# A function that is used when there is no print builtin or printf.
+func_fallback_echo ()
+{
+  eval 'cat <<_LTECHO_EOF
+$1
+_LTECHO_EOF'
+}
+
+# NLS nuisances: We save the old values to restore during execute mode.
+lt_user_locale=
+lt_safe_locale=
+for lt_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
+do
+  eval "if test \"\${$lt_var+set}\" = set; then
+          save_$lt_var=\$$lt_var
+          $lt_var=C
+	  export $lt_var
+	  lt_user_locale=\"$lt_var=\\\$save_\$lt_var; \$lt_user_locale\"
+	  lt_safe_locale=\"$lt_var=C; \$lt_safe_locale\"
+	fi"
+done
+LC_ALL=C
+LANGUAGE=C
+export LANGUAGE LC_ALL
+
+$lt_unset CDPATH
+
+
+# Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh
+# is ksh but when the shell is invoked as "sh" and the current value of
+# the _XPG environment variable is not equal to 1 (one), the special
+# positional parameter $0, within a function call, is the name of the
+# function.
+progpath="$0"
+
+
+
+: ${CP="cp -f"}
+test "${ECHO+set}" = set || ECHO=${as_echo-'printf %s\n'}
+: ${MAKE="make"}
+: ${MKDIR="mkdir"}
+: ${MV="mv -f"}
+: ${RM="rm -f"}
+: ${SHELL="${CONFIG_SHELL-/bin/sh}"}
+: ${Xsed="$SED -e 1s/^X//"}
+
+# Global variables:
+EXIT_SUCCESS=0
+EXIT_FAILURE=1
+EXIT_MISMATCH=63  # $? = 63 is used to indicate version mismatch to missing.
+EXIT_SKIP=77	  # $? = 77 is used to indicate a skipped test to automake.
+
+exit_status=$EXIT_SUCCESS
+
+# Make sure IFS has a sensible default
+lt_nl='
+'
+IFS=" 	$lt_nl"
+
+dirname="s,/[^/]*$,,"
+basename="s,^.*/,,"
+
+# func_dirname file append nondir_replacement
+# Compute the dirname of FILE.  If nonempty, add APPEND to the result,
+# otherwise set result to NONDIR_REPLACEMENT.
+func_dirname ()
+{
+    func_dirname_result=`$ECHO "${1}" | $SED "$dirname"`
+    if test "X$func_dirname_result" = "X${1}"; then
+      func_dirname_result="${3}"
+    else
+      func_dirname_result="$func_dirname_result${2}"
+    fi
+} # func_dirname may be replaced by extended shell implementation
+
+
+# func_basename file
+func_basename ()
+{
+    func_basename_result=`$ECHO "${1}" | $SED "$basename"`
+} # func_basename may be replaced by extended shell implementation
+
+
+# func_dirname_and_basename file append nondir_replacement
+# perform func_basename and func_dirname in a single function
+# call:
+#   dirname:  Compute the dirname of FILE.  If nonempty,
+#             add APPEND to the result, otherwise set result
+#             to NONDIR_REPLACEMENT.
+#             value returned in "$func_dirname_result"
+#   basename: Compute filename of FILE.
+#             value retuned in "$func_basename_result"
+# Implementation must be kept synchronized with func_dirname
+# and func_basename. For efficiency, we do not delegate to
+# those functions but instead duplicate the functionality here.
+func_dirname_and_basename ()
+{
+    # Extract subdirectory from the argument.
+    func_dirname_result=`$ECHO "${1}" | $SED -e "$dirname"`
+    if test "X$func_dirname_result" = "X${1}"; then
+      func_dirname_result="${3}"
+    else
+      func_dirname_result="$func_dirname_result${2}"
+    fi
+    func_basename_result=`$ECHO "${1}" | $SED -e "$basename"`
+} # func_dirname_and_basename may be replaced by extended shell implementation
+
+
+# func_stripname prefix suffix name
+# strip PREFIX and SUFFIX off of NAME.
+# PREFIX and SUFFIX must not contain globbing or regex special
+# characters, hashes, percent signs, but SUFFIX may contain a leading
+# dot (in which case that matches only a dot).
+# func_strip_suffix prefix name
+func_stripname ()
+{
+    case ${2} in
+      .*) func_stripname_result=`$ECHO "${3}" | $SED "s%^${1}%%; s%\\\\${2}\$%%"`;;
+      *)  func_stripname_result=`$ECHO "${3}" | $SED "s%^${1}%%; s%${2}\$%%"`;;
+    esac
+} # func_stripname may be replaced by extended shell implementation
+
+
+# These SED scripts presuppose an absolute path with a trailing slash.
+pathcar='s,^/\([^/]*\).*$,\1,'
+pathcdr='s,^/[^/]*,,'
+removedotparts=':dotsl
+		s@/\./@/@g
+		t dotsl
+		s,/\.$,/,'
+collapseslashes='s@/\{1,\}@/@g'
+finalslash='s,/*$,/,'
+
+# func_normal_abspath PATH
+# Remove doubled-up and trailing slashes, "." path components,
+# and cancel out any ".." path components in PATH after making
+# it an absolute path.
+#             value returned in "$func_normal_abspath_result"
+func_normal_abspath ()
+{
+  # Start from root dir and reassemble the path.
+  func_normal_abspath_result=
+  func_normal_abspath_tpath=$1
+  func_normal_abspath_altnamespace=
+  case $func_normal_abspath_tpath in
+    "")
+      # Empty path, that just means $cwd.
+      func_stripname '' '/' "`pwd`"
+      func_normal_abspath_result=$func_stripname_result
+      return
+    ;;
+    # The next three entries are used to spot a run of precisely
+    # two leading slashes without using negated character classes;
+    # we take advantage of case's first-match behaviour.
+    ///*)
+      # Unusual form of absolute path, do nothing.
+    ;;
+    //*)
+      # Not necessarily an ordinary path; POSIX reserves leading '//'
+      # and for example Cygwin uses it to access remote file shares
+      # over CIFS/SMB, so we conserve a leading double slash if found.
+      func_normal_abspath_altnamespace=/
+    ;;
+    /*)
+      # Absolute path, do nothing.
+    ;;
+    *)
+      # Relative path, prepend $cwd.
+      func_normal_abspath_tpath=`pwd`/$func_normal_abspath_tpath
+    ;;
+  esac
+  # Cancel out all the simple stuff to save iterations.  We also want
+  # the path to end with a slash for ease of parsing, so make sure
+  # there is one (and only one) here.
+  func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
+        -e "$removedotparts" -e "$collapseslashes" -e "$finalslash"`
+  while :; do
+    # Processed it all yet?
+    if test "$func_normal_abspath_tpath" = / ; then
+      # If we ascended to the root using ".." the result may be empty now.
+      if test -z "$func_normal_abspath_result" ; then
+        func_normal_abspath_result=/
+      fi
+      break
+    fi
+    func_normal_abspath_tcomponent=`$ECHO "$func_normal_abspath_tpath" | $SED \
+        -e "$pathcar"`
+    func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
+        -e "$pathcdr"`
+    # Figure out what to do with it
+    case $func_normal_abspath_tcomponent in
+      "")
+        # Trailing empty path component, ignore it.
+      ;;
+      ..)
+        # Parent dir; strip last assembled component from result.
+        func_dirname "$func_normal_abspath_result"
+        func_normal_abspath_result=$func_dirname_result
+      ;;
+      *)
+        # Actual path component, append it.
+        func_normal_abspath_result=$func_normal_abspath_result/$func_normal_abspath_tcomponent
+      ;;
+    esac
+  done
+  # Restore leading double-slash if one was found on entry.
+  func_normal_abspath_result=$func_normal_abspath_altnamespace$func_normal_abspath_result
+}
+
+# func_relative_path SRCDIR DSTDIR
+# generates a relative path from SRCDIR to DSTDIR, with a trailing
+# slash if non-empty, suitable for immediately appending a filename
+# without needing to append a separator.
+#             value returned in "$func_relative_path_result"
+func_relative_path ()
+{
+  func_relative_path_result=
+  func_normal_abspath "$1"
+  func_relative_path_tlibdir=$func_normal_abspath_result
+  func_normal_abspath "$2"
+  func_relative_path_tbindir=$func_normal_abspath_result
+
+  # Ascend the tree starting from libdir
+  while :; do
+    # check if we have found a prefix of bindir
+    case $func_relative_path_tbindir in
+      $func_relative_path_tlibdir)
+        # found an exact match
+        func_relative_path_tcancelled=
+        break
+        ;;
+      $func_relative_path_tlibdir*)
+        # found a matching prefix
+        func_stripname "$func_relative_path_tlibdir" '' "$func_relative_path_tbindir"
+        func_relative_path_tcancelled=$func_stripname_result
+        if test -z "$func_relative_path_result"; then
+          func_relative_path_result=.
+        fi
+        break
+        ;;
+      *)
+        func_dirname $func_relative_path_tlibdir
+        func_relative_path_tlibdir=${func_dirname_result}
+        if test "x$func_relative_path_tlibdir" = x ; then
+          # Have to descend all the way to the root!
+          func_relative_path_result=../$func_relative_path_result
+          func_relative_path_tcancelled=$func_relative_path_tbindir
+          break
+        fi
+        func_relative_path_result=../$func_relative_path_result
+        ;;
+    esac
+  done
+
+  # Now calculate path; take care to avoid doubling-up slashes.
+  func_stripname '' '/' "$func_relative_path_result"
+  func_relative_path_result=$func_stripname_result
+  func_stripname '/' '/' "$func_relative_path_tcancelled"
+  if test "x$func_stripname_result" != x ; then
+    func_relative_path_result=${func_relative_path_result}/${func_stripname_result}
+  fi
+
+  # Normalisation. If bindir is libdir, return empty string,
+  # else relative path ending with a slash; either way, target
+  # file name can be directly appended.
+  if test ! -z "$func_relative_path_result"; then
+    func_stripname './' '' "$func_relative_path_result/"
+    func_relative_path_result=$func_stripname_result
+  fi
+}
+
+# The name of this program:
+func_dirname_and_basename "$progpath"
+progname=$func_basename_result
+
+# Make sure we have an absolute path for reexecution:
+case $progpath in
+  [\\/]*|[A-Za-z]:\\*) ;;
+  *[\\/]*)
+     progdir=$func_dirname_result
+     progdir=`cd "$progdir" && pwd`
+     progpath="$progdir/$progname"
+     ;;
+  *)
+     save_IFS="$IFS"
+     IFS=${PATH_SEPARATOR-:}
+     for progdir in $PATH; do
+       IFS="$save_IFS"
+       test -x "$progdir/$progname" && break
+     done
+     IFS="$save_IFS"
+     test -n "$progdir" || progdir=`pwd`
+     progpath="$progdir/$progname"
+     ;;
+esac
+
+# Sed substitution that helps us do robust quoting.  It backslashifies
+# metacharacters that are still active within double-quoted strings.
+Xsed="${SED}"' -e 1s/^X//'
+sed_quote_subst='s/\([`"$\\]\)/\\\1/g'
+
+# Same as above, but do not quote variable references.
+double_quote_subst='s/\(["`\\]\)/\\\1/g'
+
+# Sed substitution that turns a string into a regex matching for the
+# string literally.
+sed_make_literal_regex='s,[].[^$\\*\/],\\&,g'
+
+# Sed substitution that converts a w32 file name or path
+# which contains forward slashes, into one that contains
+# (escaped) backslashes.  A very naive implementation.
+lt_sed_naive_backslashify='s|\\\\*|\\|g;s|/|\\|g;s|\\|\\\\|g'
+
+# Re-`\' parameter expansions in output of double_quote_subst that were
+# `\'-ed in input to the same.  If an odd number of `\' preceded a '$'
+# in input to double_quote_subst, that '$' was protected from expansion.
+# Since each input `\' is now two `\'s, look for any number of runs of
+# four `\'s followed by two `\'s and then a '$'.  `\' that '$'.
+bs='\\'
+bs2='\\\\'
+bs4='\\\\\\\\'
+dollar='\$'
+sed_double_backslash="\
+  s/$bs4/&\\
+/g
+  s/^$bs2$dollar/$bs&/
+  s/\\([^$bs]\\)$bs2$dollar/\\1$bs2$bs$dollar/g
+  s/\n//g"
+
+# Standard options:
+opt_dry_run=false
+opt_help=false
+opt_quiet=false
+opt_verbose=false
+opt_warning=:
+
+# func_echo arg...
+# Echo program name prefixed message, along with the current mode
+# name if it has been set yet.
+func_echo ()
+{
+    $ECHO "$progname: ${opt_mode+$opt_mode: }$*"
+}
+
+# func_verbose arg...
+# Echo program name prefixed message in verbose mode only.
+func_verbose ()
+{
+    $opt_verbose && func_echo ${1+"$@"}
+
+    # A bug in bash halts the script if the last line of a function
+    # fails when set -e is in force, so we need another command to
+    # work around that:
+    :
+}
+
+# func_echo_all arg...
+# Invoke $ECHO with all args, space-separated.
+func_echo_all ()
+{
+    $ECHO "$*"
+}
+
+# func_error arg...
+# Echo program name prefixed message to standard error.
+func_error ()
+{
+    $ECHO "$progname: ${opt_mode+$opt_mode: }"${1+"$@"} 1>&2
+}
+
+# func_warning arg...
+# Echo program name prefixed warning message to standard error.
+func_warning ()
+{
+    $opt_warning && $ECHO "$progname: ${opt_mode+$opt_mode: }warning: "${1+"$@"} 1>&2
+
+    # bash bug again:
+    :
+}
+
+# func_fatal_error arg...
+# Echo program name prefixed message to standard error, and exit.
+func_fatal_error ()
+{
+    func_error ${1+"$@"}
+    exit $EXIT_FAILURE
+}
+
+# func_fatal_help arg...
+# Echo program name prefixed message to standard error, followed by
+# a help hint, and exit.
+func_fatal_help ()
+{
+    func_error ${1+"$@"}
+    func_fatal_error "$help"
+}
+help="Try \`$progname --help' for more information."  ## default
+
+
+# func_grep expression filename
+# Check whether EXPRESSION matches any line of FILENAME, without output.
+func_grep ()
+{
+    $GREP "$1" "$2" >/dev/null 2>&1
+}
+
+
+# func_mkdir_p directory-path
+# Make sure the entire path to DIRECTORY-PATH is available.
+func_mkdir_p ()
+{
+    my_directory_path="$1"
+    my_dir_list=
+
+    if test -n "$my_directory_path" && test "$opt_dry_run" != ":"; then
+
+      # Protect directory names starting with `-'
+      case $my_directory_path in
+        -*) my_directory_path="./$my_directory_path" ;;
+      esac
+
+      # While some portion of DIR does not yet exist...
+      while test ! -d "$my_directory_path"; do
+        # ...make a list in topmost first order.  Use a colon delimited
+	# list incase some portion of path contains whitespace.
+        my_dir_list="$my_directory_path:$my_dir_list"
+
+        # If the last portion added has no slash in it, the list is done
+        case $my_directory_path in */*) ;; *) break ;; esac
+
+        # ...otherwise throw away the child directory and loop
+        my_directory_path=`$ECHO "$my_directory_path" | $SED -e "$dirname"`
+      done
+      my_dir_list=`$ECHO "$my_dir_list" | $SED 's,:*$,,'`
+
+      save_mkdir_p_IFS="$IFS"; IFS=':'
+      for my_dir in $my_dir_list; do
+	IFS="$save_mkdir_p_IFS"
+        # mkdir can fail with a `File exist' error if two processes
+        # try to create one of the directories concurrently.  Don't
+        # stop in that case!
+        $MKDIR "$my_dir" 2>/dev/null || :
+      done
+      IFS="$save_mkdir_p_IFS"
+
+      # Bail out if we (or some other process) failed to create a directory.
+      test -d "$my_directory_path" || \
+        func_fatal_error "Failed to create \`$1'"
+    fi
+}
+
+
+# func_mktempdir [string]
+# Make a temporary directory that won't clash with other running
+# libtool processes, and avoids race conditions if possible.  If
+# given, STRING is the basename for that directory.
+func_mktempdir ()
+{
+    my_template="${TMPDIR-/tmp}/${1-$progname}"
+
+    if test "$opt_dry_run" = ":"; then
+      # Return a directory name, but don't create it in dry-run mode
+      my_tmpdir="${my_template}-$$"
+    else
+
+      # If mktemp works, use that first and foremost
+      my_tmpdir=`mktemp -d "${my_template}-XXXXXXXX" 2>/dev/null`
+
+      if test ! -d "$my_tmpdir"; then
+        # Failing that, at least try and use $RANDOM to avoid a race
+        my_tmpdir="${my_template}-${RANDOM-0}$$"
+
+        save_mktempdir_umask=`umask`
+        umask 0077
+        $MKDIR "$my_tmpdir"
+        umask $save_mktempdir_umask
+      fi
+
+      # If we're not in dry-run mode, bomb out on failure
+      test -d "$my_tmpdir" || \
+        func_fatal_error "cannot create temporary directory \`$my_tmpdir'"
+    fi
+
+    $ECHO "$my_tmpdir"
+}
+
+
+# func_quote_for_eval arg
+# Aesthetically quote ARG to be evaled later.
+# This function returns two values: FUNC_QUOTE_FOR_EVAL_RESULT
+# is double-quoted, suitable for a subsequent eval, whereas
+# FUNC_QUOTE_FOR_EVAL_UNQUOTED_RESULT has merely all characters
+# which are still active within double quotes backslashified.
+func_quote_for_eval ()
+{
+    case $1 in
+      *[\\\`\"\$]*)
+	func_quote_for_eval_unquoted_result=`$ECHO "$1" | $SED "$sed_quote_subst"` ;;
+      *)
+        func_quote_for_eval_unquoted_result="$1" ;;
+    esac
+
+    case $func_quote_for_eval_unquoted_result in
+      # Double-quote args containing shell metacharacters to delay
+      # word splitting, command substitution and and variable
+      # expansion for a subsequent eval.
+      # Many Bourne shells cannot handle close brackets correctly
+      # in scan sets, so we specify it separately.
+      *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*|"")
+        func_quote_for_eval_result="\"$func_quote_for_eval_unquoted_result\""
+        ;;
+      *)
+        func_quote_for_eval_result="$func_quote_for_eval_unquoted_result"
+    esac
+}
+
+
+# func_quote_for_expand arg
+# Aesthetically quote ARG to be evaled later; same as above,
+# but do not quote variable references.
+func_quote_for_expand ()
+{
+    case $1 in
+      *[\\\`\"]*)
+	my_arg=`$ECHO "$1" | $SED \
+	    -e "$double_quote_subst" -e "$sed_double_backslash"` ;;
+      *)
+        my_arg="$1" ;;
+    esac
+
+    case $my_arg in
+      # Double-quote args containing shell metacharacters to delay
+      # word splitting and command substitution for a subsequent eval.
+      # Many Bourne shells cannot handle close brackets correctly
+      # in scan sets, so we specify it separately.
+      *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*|"")
+        my_arg="\"$my_arg\""
+        ;;
+    esac
+
+    func_quote_for_expand_result="$my_arg"
+}
+
+
+# func_show_eval cmd [fail_exp]
+# Unless opt_silent is true, then output CMD.  Then, if opt_dryrun is
+# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
+# is given, then evaluate it.
+func_show_eval ()
+{
+    my_cmd="$1"
+    my_fail_exp="${2-:}"
+
+    ${opt_silent-false} || {
+      func_quote_for_expand "$my_cmd"
+      eval "func_echo $func_quote_for_expand_result"
+    }
+
+    if ${opt_dry_run-false}; then :; else
+      eval "$my_cmd"
+      my_status=$?
+      if test "$my_status" -eq 0; then :; else
+	eval "(exit $my_status); $my_fail_exp"
+      fi
+    fi
+}
+
+
+# func_show_eval_locale cmd [fail_exp]
+# Unless opt_silent is true, then output CMD.  Then, if opt_dryrun is
+# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
+# is given, then evaluate it.  Use the saved locale for evaluation.
+func_show_eval_locale ()
+{
+    my_cmd="$1"
+    my_fail_exp="${2-:}"
+
+    ${opt_silent-false} || {
+      func_quote_for_expand "$my_cmd"
+      eval "func_echo $func_quote_for_expand_result"
+    }
+
+    if ${opt_dry_run-false}; then :; else
+      eval "$lt_user_locale
+	    $my_cmd"
+      my_status=$?
+      eval "$lt_safe_locale"
+      if test "$my_status" -eq 0; then :; else
+	eval "(exit $my_status); $my_fail_exp"
+      fi
+    fi
+}
+
+# func_tr_sh
+# Turn $1 into a string suitable for a shell variable name.
+# Result is stored in $func_tr_sh_result.  All characters
+# not in the set a-zA-Z0-9_ are replaced with '_'. Further,
+# if $1 begins with a digit, a '_' is prepended as well.
+func_tr_sh ()
+{
+  case $1 in
+  [0-9]* | *[!a-zA-Z0-9_]*)
+    func_tr_sh_result=`$ECHO "$1" | $SED 's/^\([0-9]\)/_\1/; s/[^a-zA-Z0-9_]/_/g'`
+    ;;
+  * )
+    func_tr_sh_result=$1
+    ;;
+  esac
+}
+
+
+# func_version
+# Echo version message to standard output and exit.
+func_version ()
+{
+    $opt_debug
+
+    $SED -n '/(C)/!b go
+	:more
+	/\./!{
+	  N
+	  s/\n# / /
+	  b more
+	}
+	:go
+	/^# '$PROGRAM' (GNU /,/# warranty; / {
+        s/^# //
+	s/^# *$//
+        s/\((C)\)[ 0-9,-]*\( [1-9][0-9]*\)/\1\2/
+        p
+     }' < "$progpath"
+     exit $?
+}
+
+# func_usage
+# Echo short help message to standard output and exit.
+func_usage ()
+{
+    $opt_debug
+
+    $SED -n '/^# Usage:/,/^#  *.*--help/ {
+        s/^# //
+	s/^# *$//
+	s/\$progname/'$progname'/
+	p
+    }' < "$progpath"
+    echo
+    $ECHO "run \`$progname --help | more' for full usage"
+    exit $?
+}
+
+# func_help [NOEXIT]
+# Echo long help message to standard output and exit,
+# unless 'noexit' is passed as argument.
+func_help ()
+{
+    $opt_debug
+
+    $SED -n '/^# Usage:/,/# Report bugs to/ {
+	:print
+        s/^# //
+	s/^# *$//
+	s*\$progname*'$progname'*
+	s*\$host*'"$host"'*
+	s*\$SHELL*'"$SHELL"'*
+	s*\$LTCC*'"$LTCC"'*
+	s*\$LTCFLAGS*'"$LTCFLAGS"'*
+	s*\$LD*'"$LD"'*
+	s/\$with_gnu_ld/'"$with_gnu_ld"'/
+	s/\$automake_version/'"`(${AUTOMAKE-automake} --version) 2>/dev/null |$SED 1q`"'/
+	s/\$autoconf_version/'"`(${AUTOCONF-autoconf} --version) 2>/dev/null |$SED 1q`"'/
+	p
+	d
+     }
+     /^# .* home page:/b print
+     /^# General help using/b print
+     ' < "$progpath"
+    ret=$?
+    if test -z "$1"; then
+      exit $ret
+    fi
+}
+
+# func_missing_arg argname
+# Echo program name prefixed message to standard error and set global
+# exit_cmd.
+func_missing_arg ()
+{
+    $opt_debug
+
+    func_error "missing argument for $1."
+    exit_cmd=exit
+}
+
+
+# func_split_short_opt shortopt
+# Set func_split_short_opt_name and func_split_short_opt_arg shell
+# variables after splitting SHORTOPT after the 2nd character.
+func_split_short_opt ()
+{
+    my_sed_short_opt='1s/^\(..\).*$/\1/;q'
+    my_sed_short_rest='1s/^..\(.*\)$/\1/;q'
+
+    func_split_short_opt_name=`$ECHO "$1" | $SED "$my_sed_short_opt"`
+    func_split_short_opt_arg=`$ECHO "$1" | $SED "$my_sed_short_rest"`
+} # func_split_short_opt may be replaced by extended shell implementation
+
+
+# func_split_long_opt longopt
+# Set func_split_long_opt_name and func_split_long_opt_arg shell
+# variables after splitting LONGOPT at the `=' sign.
+func_split_long_opt ()
+{
+    my_sed_long_opt='1s/^\(--[^=]*\)=.*/\1/;q'
+    my_sed_long_arg='1s/^--[^=]*=//'
+
+    func_split_long_opt_name=`$ECHO "$1" | $SED "$my_sed_long_opt"`
+    func_split_long_opt_arg=`$ECHO "$1" | $SED "$my_sed_long_arg"`
+} # func_split_long_opt may be replaced by extended shell implementation
+
+exit_cmd=:
+
+
+
+
+
+magic="%%%MAGIC variable%%%"
+magic_exe="%%%MAGIC EXE variable%%%"
+
+# Global variables.
+nonopt=
+preserve_args=
+lo2o="s/\\.lo\$/.${objext}/"
+o2lo="s/\\.${objext}\$/.lo/"
+extracted_archives=
+extracted_serial=0
+
+# If this variable is set in any of the actions, the command in it
+# will be execed at the end.  This prevents here-documents from being
+# left over by shells.
+exec_cmd=
+
+# func_append var value
+# Append VALUE to the end of shell variable VAR.
+func_append ()
+{
+    eval "${1}=\$${1}\${2}"
+} # func_append may be replaced by extended shell implementation
+
+# func_append_quoted var value
+# Quote VALUE and append to the end of shell variable VAR, separated
+# by a space.
+func_append_quoted ()
+{
+    func_quote_for_eval "${2}"
+    eval "${1}=\$${1}\\ \$func_quote_for_eval_result"
+} # func_append_quoted may be replaced by extended shell implementation
+
+
+# func_arith arithmetic-term...
+func_arith ()
+{
+    func_arith_result=`expr "${@}"`
+} # func_arith may be replaced by extended shell implementation
+
+
+# func_len string
+# STRING may not start with a hyphen.
+func_len ()
+{
+    func_len_result=`expr "${1}" : ".*" 2>/dev/null || echo $max_cmd_len`
+} # func_len may be replaced by extended shell implementation
+
+
+# func_lo2o object
+func_lo2o ()
+{
+    func_lo2o_result=`$ECHO "${1}" | $SED "$lo2o"`
+} # func_lo2o may be replaced by extended shell implementation
+
+
+# func_xform libobj-or-source
+func_xform ()
+{
+    func_xform_result=`$ECHO "${1}" | $SED 's/\.[^.]*$/.lo/'`
+} # func_xform may be replaced by extended shell implementation
+
+
+# func_fatal_configuration arg...
+# Echo program name prefixed message to standard error, followed by
+# a configuration failure hint, and exit.
+func_fatal_configuration ()
+{
+    func_error ${1+"$@"}
+    func_error "See the $PACKAGE documentation for more information."
+    func_fatal_error "Fatal configuration error."
+}
+
+
+# func_config
+# Display the configuration for all the tags in this script.
+func_config ()
+{
+    re_begincf='^# ### BEGIN LIBTOOL'
+    re_endcf='^# ### END LIBTOOL'
+
+    # Default configuration.
+    $SED "1,/$re_begincf CONFIG/d;/$re_endcf CONFIG/,\$d" < "$progpath"
+
+    # Now print the configurations for the tags.
+    for tagname in $taglist; do
+      $SED -n "/$re_begincf TAG CONFIG: $tagname\$/,/$re_endcf TAG CONFIG: $tagname\$/p" < "$progpath"
+    done
+
+    exit $?
+}
+
+# func_features
+# Display the features supported by this script.
+func_features ()
+{
+    echo "host: $host"
+    if test "$build_libtool_libs" = yes; then
+      echo "enable shared libraries"
+    else
+      echo "disable shared libraries"
+    fi
+    if test "$build_old_libs" = yes; then
+      echo "enable static libraries"
+    else
+      echo "disable static libraries"
+    fi
+
+    exit $?
+}
+
+# func_enable_tag tagname
+# Verify that TAGNAME is valid, and either flag an error and exit, or
+# enable the TAGNAME tag.  We also add TAGNAME to the global $taglist
+# variable here.
+func_enable_tag ()
+{
+  # Global variable:
+  tagname="$1"
+
+  re_begincf="^# ### BEGIN LIBTOOL TAG CONFIG: $tagname\$"
+  re_endcf="^# ### END LIBTOOL TAG CONFIG: $tagname\$"
+  sed_extractcf="/$re_begincf/,/$re_endcf/p"
+
+  # Validate tagname.
+  case $tagname in
+    *[!-_A-Za-z0-9,/]*)
+      func_fatal_error "invalid tag name: $tagname"
+      ;;
+  esac
+
+  # Don't test for the "default" C tag, as we know it's
+  # there but not specially marked.
+  case $tagname in
+    CC) ;;
+    *)
+      if $GREP "$re_begincf" "$progpath" >/dev/null 2>&1; then
+	taglist="$taglist $tagname"
+
+	# Evaluate the configuration.  Be careful to quote the path
+	# and the sed script, to avoid splitting on whitespace, but
+	# also don't use non-portable quotes within backquotes within
+	# quotes we have to do it in 2 steps:
+	extractedcf=`$SED -n -e "$sed_extractcf" < "$progpath"`
+	eval "$extractedcf"
+      else
+	func_error "ignoring unknown tag $tagname"
+      fi
+      ;;
+  esac
+}
+
+# func_check_version_match
+# Ensure that we are using m4 macros, and libtool script from the same
+# release of libtool.
+func_check_version_match ()
+{
+  if test "$package_revision" != "$macro_revision"; then
+    if test "$VERSION" != "$macro_version"; then
+      if test -z "$macro_version"; then
+        cat >&2 <<_LT_EOF
+$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
+$progname: definition of this LT_INIT comes from an older release.
+$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
+$progname: and run autoconf again.
+_LT_EOF
+      else
+        cat >&2 <<_LT_EOF
+$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
+$progname: definition of this LT_INIT comes from $PACKAGE $macro_version.
+$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
+$progname: and run autoconf again.
+_LT_EOF
+      fi
+    else
+      cat >&2 <<_LT_EOF
+$progname: Version mismatch error.  This is $PACKAGE $VERSION, revision $package_revision,
+$progname: but the definition of this LT_INIT comes from revision $macro_revision.
+$progname: You should recreate aclocal.m4 with macros from revision $package_revision
+$progname: of $PACKAGE $VERSION and run autoconf again.
+_LT_EOF
+    fi
+
+    exit $EXIT_MISMATCH
+  fi
+}
+
+
+# Shorthand for --mode=foo, only valid as the first argument
+case $1 in
+clean|clea|cle|cl)
+  shift; set dummy --mode clean ${1+"$@"}; shift
+  ;;
+compile|compil|compi|comp|com|co|c)
+  shift; set dummy --mode compile ${1+"$@"}; shift
+  ;;
+execute|execut|execu|exec|exe|ex|e)
+  shift; set dummy --mode execute ${1+"$@"}; shift
+  ;;
+finish|finis|fini|fin|fi|f)
+  shift; set dummy --mode finish ${1+"$@"}; shift
+  ;;
+install|instal|insta|inst|ins|in|i)
+  shift; set dummy --mode install ${1+"$@"}; shift
+  ;;
+link|lin|li|l)
+  shift; set dummy --mode link ${1+"$@"}; shift
+  ;;
+uninstall|uninstal|uninsta|uninst|unins|unin|uni|un|u)
+  shift; set dummy --mode uninstall ${1+"$@"}; shift
+  ;;
+esac
+
+
+
+# Option defaults:
+opt_debug=:
+opt_dry_run=false
+opt_config=false
+opt_preserve_dup_deps=false
+opt_features=false
+opt_finish=false
+opt_help=false
+opt_help_all=false
+opt_silent=:
+opt_warning=:
+opt_verbose=:
+opt_silent=false
+opt_verbose=false
+
+
+# Parse options once, thoroughly.  This comes as soon as possible in the
+# script to make things like `--version' happen as quickly as we can.
+{
+  # this just eases exit handling
+  while test $# -gt 0; do
+    opt="$1"
+    shift
+    case $opt in
+      --debug|-x)	opt_debug='set -x'
+			func_echo "enabling shell trace mode"
+			$opt_debug
+			;;
+      --dry-run|--dryrun|-n)
+			opt_dry_run=:
+			;;
+      --config)
+			opt_config=:
+func_config
+			;;
+      --dlopen|-dlopen)
+			optarg="$1"
+			opt_dlopen="${opt_dlopen+$opt_dlopen
+}$optarg"
+			shift
+			;;
+      --preserve-dup-deps)
+			opt_preserve_dup_deps=:
+			;;
+      --features)
+			opt_features=:
+func_features
+			;;
+      --finish)
+			opt_finish=:
+set dummy --mode finish ${1+"$@"}; shift
+			;;
+      --help)
+			opt_help=:
+			;;
+      --help-all)
+			opt_help_all=:
+opt_help=': help-all'
+			;;
+      --mode)
+			test $# = 0 && func_missing_arg $opt && break
+			optarg="$1"
+			opt_mode="$optarg"
+case $optarg in
+  # Valid mode arguments:
+  clean|compile|execute|finish|install|link|relink|uninstall) ;;
+
+  # Catch anything else as an error
+  *) func_error "invalid argument for $opt"
+     exit_cmd=exit
+     break
+     ;;
+esac
+			shift
+			;;
+      --no-silent|--no-quiet)
+			opt_silent=false
+func_append preserve_args " $opt"
+			;;
+      --no-warning|--no-warn)
+			opt_warning=false
+func_append preserve_args " $opt"
+			;;
+      --no-verbose)
+			opt_verbose=false
+func_append preserve_args " $opt"
+			;;
+      --silent|--quiet)
+			opt_silent=:
+func_append preserve_args " $opt"
+        opt_verbose=false
+			;;
+      --verbose|-v)
+			opt_verbose=:
+func_append preserve_args " $opt"
+opt_silent=false
+			;;
+      --tag)
+			test $# = 0 && func_missing_arg $opt && break
+			optarg="$1"
+			opt_tag="$optarg"
+func_append preserve_args " $opt $optarg"
+func_enable_tag "$optarg"
+			shift
+			;;
+
+      -\?|-h)		func_usage				;;
+      --help)		func_help				;;
+      --version)	func_version				;;
+
+      # Separate optargs to long options:
+      --*=*)
+			func_split_long_opt "$opt"
+			set dummy "$func_split_long_opt_name" "$func_split_long_opt_arg" ${1+"$@"}
+			shift
+			;;
+
+      # Separate non-argument short options:
+      -\?*|-h*|-n*|-v*)
+			func_split_short_opt "$opt"
+			set dummy "$func_split_short_opt_name" "-$func_split_short_opt_arg" ${1+"$@"}
+			shift
+			;;
+
+      --)		break					;;
+      -*)		func_fatal_help "unrecognized option \`$opt'" ;;
+      *)		set dummy "$opt" ${1+"$@"};	shift; break  ;;
+    esac
+  done
+
+  # Validate options:
+
+  # save first non-option argument
+  if test "$#" -gt 0; then
+    nonopt="$opt"
+    shift
+  fi
+
+  # preserve --debug
+  test "$opt_debug" = : || func_append preserve_args " --debug"
+
+  case $host in
+    *cygwin* | *mingw* | *pw32* | *cegcc*)
+      # don't eliminate duplications in $postdeps and $predeps
+      opt_duplicate_compiler_generated_deps=:
+      ;;
+    *)
+      opt_duplicate_compiler_generated_deps=$opt_preserve_dup_deps
+      ;;
+  esac
+
+  $opt_help || {
+    # Sanity checks first:
+    func_check_version_match
+
+    if test "$build_libtool_libs" != yes && test "$build_old_libs" != yes; then
+      func_fatal_configuration "not configured to build any kind of library"
+    fi
+
+    # Darwin sucks
+    eval std_shrext=\"$shrext_cmds\"
+
+    # Only execute mode is allowed to have -dlopen flags.
+    if test -n "$opt_dlopen" && test "$opt_mode" != execute; then
+      func_error "unrecognized option \`-dlopen'"
+      $ECHO "$help" 1>&2
+      exit $EXIT_FAILURE
+    fi
+
+    # Change the help message to a mode-specific one.
+    generic_help="$help"
+    help="Try \`$progname --help --mode=$opt_mode' for more information."
+  }
+
+
+  # Bail if the options were screwed
+  $exit_cmd $EXIT_FAILURE
+}
+
+
+
+
+## ----------- ##
+##    Main.    ##
+## ----------- ##
+
+# func_lalib_p file
+# True iff FILE is a libtool `.la' library or `.lo' object file.
+# This function is only a basic sanity check; it will hardly flush out
+# determined imposters.
+func_lalib_p ()
+{
+    test -f "$1" &&
+      $SED -e 4q "$1" 2>/dev/null \
+        | $GREP "^# Generated by .*$PACKAGE" > /dev/null 2>&1
+}
+
+# func_lalib_unsafe_p file
+# True iff FILE is a libtool `.la' library or `.lo' object file.
+# This function implements the same check as func_lalib_p without
+# resorting to external programs.  To this end, it redirects stdin and
+# closes it afterwards, without saving the original file descriptor.
+# As a safety measure, use it only where a negative result would be
+# fatal anyway.  Works if `file' does not exist.
+func_lalib_unsafe_p ()
+{
+    lalib_p=no
+    if test -f "$1" && test -r "$1" && exec 5<&0 <"$1"; then
+	for lalib_p_l in 1 2 3 4
+	do
+	    read lalib_p_line
+	    case "$lalib_p_line" in
+		\#\ Generated\ by\ *$PACKAGE* ) lalib_p=yes; break;;
+	    esac
+	done
+	exec 0<&5 5<&-
+    fi
+    test "$lalib_p" = yes
+}
+
+# func_ltwrapper_script_p file
+# True iff FILE is a libtool wrapper script
+# This function is only a basic sanity check; it will hardly flush out
+# determined imposters.
+func_ltwrapper_script_p ()
+{
+    func_lalib_p "$1"
+}
+
+# func_ltwrapper_executable_p file
+# True iff FILE is a libtool wrapper executable
+# This function is only a basic sanity check; it will hardly flush out
+# determined imposters.
+func_ltwrapper_executable_p ()
+{
+    func_ltwrapper_exec_suffix=
+    case $1 in
+    *.exe) ;;
+    *) func_ltwrapper_exec_suffix=.exe ;;
+    esac
+    $GREP "$magic_exe" "$1$func_ltwrapper_exec_suffix" >/dev/null 2>&1
+}
+
+# func_ltwrapper_scriptname file
+# Assumes file is an ltwrapper_executable
+# uses $file to determine the appropriate filename for a
+# temporary ltwrapper_script.
+func_ltwrapper_scriptname ()
+{
+    func_dirname_and_basename "$1" "" "."
+    func_stripname '' '.exe' "$func_basename_result"
+    func_ltwrapper_scriptname_result="$func_dirname_result/$objdir/${func_stripname_result}_ltshwrapper"
+}
+
+# func_ltwrapper_p file
+# True iff FILE is a libtool wrapper script or wrapper executable
+# This function is only a basic sanity check; it will hardly flush out
+# determined imposters.
+func_ltwrapper_p ()
+{
+    func_ltwrapper_script_p "$1" || func_ltwrapper_executable_p "$1"
+}
+
+
+# func_execute_cmds commands fail_cmd
+# Execute tilde-delimited COMMANDS.
+# If FAIL_CMD is given, eval that upon failure.
+# FAIL_CMD may read-access the current command in variable CMD!
+func_execute_cmds ()
+{
+    $opt_debug
+    save_ifs=$IFS; IFS='~'
+    for cmd in $1; do
+      IFS=$save_ifs
+      eval cmd=\"$cmd\"
+      func_show_eval "$cmd" "${2-:}"
+    done
+    IFS=$save_ifs
+}
+
+
+# func_source file
+# Source FILE, adding directory component if necessary.
+# Note that it is not necessary on cygwin/mingw to append a dot to
+# FILE even if both FILE and FILE.exe exist: automatic-append-.exe
+# behavior happens only for exec(3), not for open(2)!  Also, sourcing
+# `FILE.' does not work on cygwin managed mounts.
+func_source ()
+{
+    $opt_debug
+    case $1 in
+    */* | *\\*)	. "$1" ;;
+    *)		. "./$1" ;;
+    esac
+}
+
+
+# func_resolve_sysroot PATH
+# Replace a leading = in PATH with a sysroot.  Store the result into
+# func_resolve_sysroot_result
+func_resolve_sysroot ()
+{
+  func_resolve_sysroot_result=$1
+  case $func_resolve_sysroot_result in
+  =*)
+    func_stripname '=' '' "$func_resolve_sysroot_result"
+    func_resolve_sysroot_result=$lt_sysroot$func_stripname_result
+    ;;
+  esac
+}
+
+# func_replace_sysroot PATH
+# If PATH begins with the sysroot, replace it with = and
+# store the result into func_replace_sysroot_result.
+func_replace_sysroot ()
+{
+  case "$lt_sysroot:$1" in
+  ?*:"$lt_sysroot"*)
+    func_stripname "$lt_sysroot" '' "$1"
+    func_replace_sysroot_result="=$func_stripname_result"
+    ;;
+  *)
+    # Including no sysroot.
+    func_replace_sysroot_result=$1
+    ;;
+  esac
+}
+
+# func_infer_tag arg
+# Infer tagged configuration to use if any are available and
+# if one wasn't chosen via the "--tag" command line option.
+# Only attempt this if the compiler in the base compile
+# command doesn't match the default compiler.
+# arg is usually of the form 'gcc ...'
+func_infer_tag ()
+{
+    $opt_debug
+    if test -n "$available_tags" && test -z "$tagname"; then
+      CC_quoted=
+      for arg in $CC; do
+	func_append_quoted CC_quoted "$arg"
+      done
+      CC_expanded=`func_echo_all $CC`
+      CC_quoted_expanded=`func_echo_all $CC_quoted`
+      case $@ in
+      # Blanks in the command may have been stripped by the calling shell,
+      # but not from the CC environment variable when configure was run.
+      " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \
+      " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*) ;;
+      # Blanks at the start of $base_compile will cause this to fail
+      # if we don't check for them as well.
+      *)
+	for z in $available_tags; do
+	  if $GREP "^# ### BEGIN LIBTOOL TAG CONFIG: $z$" < "$progpath" > /dev/null; then
+	    # Evaluate the configuration.
+	    eval "`${SED} -n -e '/^# ### BEGIN LIBTOOL TAG CONFIG: '$z'$/,/^# ### END LIBTOOL TAG CONFIG: '$z'$/p' < $progpath`"
+	    CC_quoted=
+	    for arg in $CC; do
+	      # Double-quote args containing other shell metacharacters.
+	      func_append_quoted CC_quoted "$arg"
+	    done
+	    CC_expanded=`func_echo_all $CC`
+	    CC_quoted_expanded=`func_echo_all $CC_quoted`
+	    case "$@ " in
+	    " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \
+	    " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*)
+	      # The compiler in the base compile command matches
+	      # the one in the tagged configuration.
+	      # Assume this is the tagged configuration we want.
+	      tagname=$z
+	      break
+	      ;;
+	    esac
+	  fi
+	done
+	# If $tagname still isn't set, then no tagged configuration
+	# was found and let the user know that the "--tag" command
+	# line option must be used.
+	if test -z "$tagname"; then
+	  func_echo "unable to infer tagged configuration"
+	  func_fatal_error "specify a tag with \`--tag'"
+#	else
+#	  func_verbose "using $tagname tagged configuration"
+	fi
+	;;
+      esac
+    fi
+}
+
+
+
+# func_write_libtool_object output_name pic_name nonpic_name
+# Create a libtool object file (analogous to a ".la" file),
+# but don't create it if we're doing a dry run.
+func_write_libtool_object ()
+{
+    write_libobj=${1}
+    if test "$build_libtool_libs" = yes; then
+      write_lobj=\'${2}\'
+    else
+      write_lobj=none
+    fi
+
+    if test "$build_old_libs" = yes; then
+      write_oldobj=\'${3}\'
+    else
+      write_oldobj=none
+    fi
+
+    $opt_dry_run || {
+      cat >${write_libobj}T <<EOF
+# $write_libobj - a libtool object file
+# Generated by $PROGRAM (GNU $PACKAGE$TIMESTAMP) $VERSION
+#
+# Please DO NOT delete this file!
+# It is necessary for linking the library.
+
+# Name of the PIC object.
+pic_object=$write_lobj
+
+# Name of the non-PIC object
+non_pic_object=$write_oldobj
+
+EOF
+      $MV "${write_libobj}T" "${write_libobj}"
+    }
+}
+
+
+##################################################
+# FILE NAME AND PATH CONVERSION HELPER FUNCTIONS #
+##################################################
+
+# func_convert_core_file_wine_to_w32 ARG
+# Helper function used by file name conversion functions when $build is *nix,
+# and $host is mingw, cygwin, or some other w32 environment. Relies on a
+# correctly configured wine environment available, with the winepath program
+# in $build's $PATH.
+#
+# ARG is the $build file name to be converted to w32 format.
+# Result is available in $func_convert_core_file_wine_to_w32_result, and will
+# be empty on error (or when ARG is empty)
+func_convert_core_file_wine_to_w32 ()
+{
+  $opt_debug
+  func_convert_core_file_wine_to_w32_result="$1"
+  if test -n "$1"; then
+    # Unfortunately, winepath does not exit with a non-zero error code, so we
+    # are forced to check the contents of stdout. On the other hand, if the
+    # command is not found, the shell will set an exit code of 127 and print
+    # *an error message* to stdout. So we must check for both error code of
+    # zero AND non-empty stdout, which explains the odd construction:
+    func_convert_core_file_wine_to_w32_tmp=`winepath -w "$1" 2>/dev/null`
+    if test "$?" -eq 0 && test -n "${func_convert_core_file_wine_to_w32_tmp}"; then
+      func_convert_core_file_wine_to_w32_result=`$ECHO "$func_convert_core_file_wine_to_w32_tmp" |
+        $SED -e "$lt_sed_naive_backslashify"`
+    else
+      func_convert_core_file_wine_to_w32_result=
+    fi
+  fi
+}
+# end: func_convert_core_file_wine_to_w32
+
+
+# func_convert_core_path_wine_to_w32 ARG
+# Helper function used by path conversion functions when $build is *nix, and
+# $host is mingw, cygwin, or some other w32 environment. Relies on a correctly
+# configured wine environment available, with the winepath program in $build's
+# $PATH. Assumes ARG has no leading or trailing path separator characters.
+#
+# ARG is path to be converted from $build format to win32.
+# Result is available in $func_convert_core_path_wine_to_w32_result.
+# Unconvertible file (directory) names in ARG are skipped; if no directory names
+# are convertible, then the result may be empty.
+func_convert_core_path_wine_to_w32 ()
+{
+  $opt_debug
+  # unfortunately, winepath doesn't convert paths, only file names
+  func_convert_core_path_wine_to_w32_result=""
+  if test -n "$1"; then
+    oldIFS=$IFS
+    IFS=:
+    for func_convert_core_path_wine_to_w32_f in $1; do
+      IFS=$oldIFS
+      func_convert_core_file_wine_to_w32 "$func_convert_core_path_wine_to_w32_f"
+      if test -n "$func_convert_core_file_wine_to_w32_result" ; then
+        if test -z "$func_convert_core_path_wine_to_w32_result"; then
+          func_convert_core_path_wine_to_w32_result="$func_convert_core_file_wine_to_w32_result"
+        else
+          func_append func_convert_core_path_wine_to_w32_result ";$func_convert_core_file_wine_to_w32_result"
+        fi
+      fi
+    done
+    IFS=$oldIFS
+  fi
+}
+# end: func_convert_core_path_wine_to_w32
+
+
+# func_cygpath ARGS...
+# Wrapper around calling the cygpath program via LT_CYGPATH. This is used when
+# when (1) $build is *nix and Cygwin is hosted via a wine environment; or (2)
+# $build is MSYS and $host is Cygwin, or (3) $build is Cygwin. In case (1) or
+# (2), returns the Cygwin file name or path in func_cygpath_result (input
+# file name or path is assumed to be in w32 format, as previously converted
+# from $build's *nix or MSYS format). In case (3), returns the w32 file name
+# or path in func_cygpath_result (input file name or path is assumed to be in
+# Cygwin format). Returns an empty string on error.
+#
+# ARGS are passed to cygpath, with the last one being the file name or path to
+# be converted.
+#
+# Specify the absolute *nix (or w32) name to cygpath in the LT_CYGPATH
+# environment variable; do not put it in $PATH.
+func_cygpath ()
+{
+  $opt_debug
+  if test -n "$LT_CYGPATH" && test -f "$LT_CYGPATH"; then
+    func_cygpath_result=`$LT_CYGPATH "$@" 2>/dev/null`
+    if test "$?" -ne 0; then
+      # on failure, ensure result is empty
+      func_cygpath_result=
+    fi
+  else
+    func_cygpath_result=
+    func_error "LT_CYGPATH is empty or specifies non-existent file: \`$LT_CYGPATH'"
+  fi
+}
+#end: func_cygpath
+
+
+# func_convert_core_msys_to_w32 ARG
+# Convert file name or path ARG from MSYS format to w32 format.  Return
+# result in func_convert_core_msys_to_w32_result.
+func_convert_core_msys_to_w32 ()
+{
+  $opt_debug
+  # awkward: cmd appends spaces to result
+  func_convert_core_msys_to_w32_result=`( cmd //c echo "$1" ) 2>/dev/null |
+    $SED -e 's/[ ]*$//' -e "$lt_sed_naive_backslashify"`
+}
+#end: func_convert_core_msys_to_w32
+
+
+# func_convert_file_check ARG1 ARG2
+# Verify that ARG1 (a file name in $build format) was converted to $host
+# format in ARG2. Otherwise, emit an error message, but continue (resetting
+# func_to_host_file_result to ARG1).
+func_convert_file_check ()
+{
+  $opt_debug
+  if test -z "$2" && test -n "$1" ; then
+    func_error "Could not determine host file name corresponding to"
+    func_error "  \`$1'"
+    func_error "Continuing, but uninstalled executables may not work."
+    # Fallback:
+    func_to_host_file_result="$1"
+  fi
+}
+# end func_convert_file_check
+
+
+# func_convert_path_check FROM_PATHSEP TO_PATHSEP FROM_PATH TO_PATH
+# Verify that FROM_PATH (a path in $build format) was converted to $host
+# format in TO_PATH. Otherwise, emit an error message, but continue, resetting
+# func_to_host_file_result to a simplistic fallback value (see below).
+func_convert_path_check ()
+{
+  $opt_debug
+  if test -z "$4" && test -n "$3"; then
+    func_error "Could not determine the host path corresponding to"
+    func_error "  \`$3'"
+    func_error "Continuing, but uninstalled executables may not work."
+    # Fallback.  This is a deliberately simplistic "conversion" and
+    # should not be "improved".  See libtool.info.
+    if test "x$1" != "x$2"; then
+      lt_replace_pathsep_chars="s|$1|$2|g"
+      func_to_host_path_result=`echo "$3" |
+        $SED -e "$lt_replace_pathsep_chars"`
+    else
+      func_to_host_path_result="$3"
+    fi
+  fi
+}
+# end func_convert_path_check
+
+
+# func_convert_path_front_back_pathsep FRONTPAT BACKPAT REPL ORIG
+# Modifies func_to_host_path_result by prepending REPL if ORIG matches FRONTPAT
+# and appending REPL if ORIG matches BACKPAT.
+func_convert_path_front_back_pathsep ()
+{
+  $opt_debug
+  case $4 in
+  $1 ) func_to_host_path_result="$3$func_to_host_path_result"
+    ;;
+  esac
+  case $4 in
+  $2 ) func_append func_to_host_path_result "$3"
+    ;;
+  esac
+}
+# end func_convert_path_front_back_pathsep
+
+
+##################################################
+# $build to $host FILE NAME CONVERSION FUNCTIONS #
+##################################################
+# invoked via `$to_host_file_cmd ARG'
+#
+# In each case, ARG is the path to be converted from $build to $host format.
+# Result will be available in $func_to_host_file_result.
+
+
+# func_to_host_file ARG
+# Converts the file name ARG from $build format to $host format. Return result
+# in func_to_host_file_result.
+func_to_host_file ()
+{
+  $opt_debug
+  $to_host_file_cmd "$1"
+}
+# end func_to_host_file
+
+
+# func_to_tool_file ARG LAZY
+# converts the file name ARG from $build format to toolchain format. Return
+# result in func_to_tool_file_result.  If the conversion in use is listed
+# in (the comma separated) LAZY, no conversion takes place.
+func_to_tool_file ()
+{
+  $opt_debug
+  case ,$2, in
+    *,"$to_tool_file_cmd",*)
+      func_to_tool_file_result=$1
+      ;;
+    *)
+      $to_tool_file_cmd "$1"
+      func_to_tool_file_result=$func_to_host_file_result
+      ;;
+  esac
+}
+# end func_to_tool_file
+
+
+# func_convert_file_noop ARG
+# Copy ARG to func_to_host_file_result.
+func_convert_file_noop ()
+{
+  func_to_host_file_result="$1"
+}
+# end func_convert_file_noop
+
+
+# func_convert_file_msys_to_w32 ARG
+# Convert file name ARG from (mingw) MSYS to (mingw) w32 format; automatic
+# conversion to w32 is not available inside the cwrapper.  Returns result in
+# func_to_host_file_result.
+func_convert_file_msys_to_w32 ()
+{
+  $opt_debug
+  func_to_host_file_result="$1"
+  if test -n "$1"; then
+    func_convert_core_msys_to_w32 "$1"
+    func_to_host_file_result="$func_convert_core_msys_to_w32_result"
+  fi
+  func_convert_file_check "$1" "$func_to_host_file_result"
+}
+# end func_convert_file_msys_to_w32
+
+
+# func_convert_file_cygwin_to_w32 ARG
+# Convert file name ARG from Cygwin to w32 format.  Returns result in
+# func_to_host_file_result.
+func_convert_file_cygwin_to_w32 ()
+{
+  $opt_debug
+  func_to_host_file_result="$1"
+  if test -n "$1"; then
+    # because $build is cygwin, we call "the" cygpath in $PATH; no need to use
+    # LT_CYGPATH in this case.
+    func_to_host_file_result=`cygpath -m "$1"`
+  fi
+  func_convert_file_check "$1" "$func_to_host_file_result"
+}
+# end func_convert_file_cygwin_to_w32
+
+
+# func_convert_file_nix_to_w32 ARG
+# Convert file name ARG from *nix to w32 format.  Requires a wine environment
+# and a working winepath. Returns result in func_to_host_file_result.
+func_convert_file_nix_to_w32 ()
+{
+  $opt_debug
+  func_to_host_file_result="$1"
+  if test -n "$1"; then
+    func_convert_core_file_wine_to_w32 "$1"
+    func_to_host_file_result="$func_convert_core_file_wine_to_w32_result"
+  fi
+  func_convert_file_check "$1" "$func_to_host_file_result"
+}
+# end func_convert_file_nix_to_w32
+
+
+# func_convert_file_msys_to_cygwin ARG
+# Convert file name ARG from MSYS to Cygwin format.  Requires LT_CYGPATH set.
+# Returns result in func_to_host_file_result.
+func_convert_file_msys_to_cygwin ()
+{
+  $opt_debug
+  func_to_host_file_result="$1"
+  if test -n "$1"; then
+    func_convert_core_msys_to_w32 "$1"
+    func_cygpath -u "$func_convert_core_msys_to_w32_result"
+    func_to_host_file_result="$func_cygpath_result"
+  fi
+  func_convert_file_check "$1" "$func_to_host_file_result"
+}
+# end func_convert_file_msys_to_cygwin
+
+
+# func_convert_file_nix_to_cygwin ARG
+# Convert file name ARG from *nix to Cygwin format.  Requires Cygwin installed
+# in a wine environment, working winepath, and LT_CYGPATH set.  Returns result
+# in func_to_host_file_result.
+func_convert_file_nix_to_cygwin ()
+{
+  $opt_debug
+  func_to_host_file_result="$1"
+  if test -n "$1"; then
+    # convert from *nix to w32, then use cygpath to convert from w32 to cygwin.
+    func_convert_core_file_wine_to_w32 "$1"
+    func_cygpath -u "$func_convert_core_file_wine_to_w32_result"
+    func_to_host_file_result="$func_cygpath_result"
+  fi
+  func_convert_file_check "$1" "$func_to_host_file_result"
+}
+# end func_convert_file_nix_to_cygwin
+
+
+#############################################
+# $build to $host PATH CONVERSION FUNCTIONS #
+#############################################
+# invoked via `$to_host_path_cmd ARG'
+#
+# In each case, ARG is the path to be converted from $build to $host format.
+# The result will be available in $func_to_host_path_result.
+#
+# Path separators are also converted from $build format to $host format.  If
+# ARG begins or ends with a path separator character, it is preserved (but
+# converted to $host format) on output.
+#
+# All path conversion functions are named using the following convention:
+#   file name conversion function    : func_convert_file_X_to_Y ()
+#   path conversion function         : func_convert_path_X_to_Y ()
+# where, for any given $build/$host combination the 'X_to_Y' value is the
+# same.  If conversion functions are added for new $build/$host combinations,
+# the two new functions must follow this pattern, or func_init_to_host_path_cmd
+# will break.
+
+
+# func_init_to_host_path_cmd
+# Ensures that function "pointer" variable $to_host_path_cmd is set to the
+# appropriate value, based on the value of $to_host_file_cmd.
+to_host_path_cmd=
+func_init_to_host_path_cmd ()
+{
+  $opt_debug
+  if test -z "$to_host_path_cmd"; then
+    func_stripname 'func_convert_file_' '' "$to_host_file_cmd"
+    to_host_path_cmd="func_convert_path_${func_stripname_result}"
+  fi
+}
+
+
+# func_to_host_path ARG
+# Converts the path ARG from $build format to $host format. Return result
+# in func_to_host_path_result.
+func_to_host_path ()
+{
+  $opt_debug
+  func_init_to_host_path_cmd
+  $to_host_path_cmd "$1"
+}
+# end func_to_host_path
+
+
+# func_convert_path_noop ARG
+# Copy ARG to func_to_host_path_result.
+func_convert_path_noop ()
+{
+  func_to_host_path_result="$1"
+}
+# end func_convert_path_noop
+
+
+# func_convert_path_msys_to_w32 ARG
+# Convert path ARG from (mingw) MSYS to (mingw) w32 format; automatic
+# conversion to w32 is not available inside the cwrapper.  Returns result in
+# func_to_host_path_result.
+func_convert_path_msys_to_w32 ()
+{
+  $opt_debug
+  func_to_host_path_result="$1"
+  if test -n "$1"; then
+    # Remove leading and trailing path separator characters from ARG.  MSYS
+    # behavior is inconsistent here; cygpath turns them into '.;' and ';.';
+    # and winepath ignores them completely.
+    func_stripname : : "$1"
+    func_to_host_path_tmp1=$func_stripname_result
+    func_convert_core_msys_to_w32 "$func_to_host_path_tmp1"
+    func_to_host_path_result="$func_convert_core_msys_to_w32_result"
+    func_convert_path_check : ";" \
+      "$func_to_host_path_tmp1" "$func_to_host_path_result"
+    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
+  fi
+}
+# end func_convert_path_msys_to_w32
+
+
+# func_convert_path_cygwin_to_w32 ARG
+# Convert path ARG from Cygwin to w32 format.  Returns result in
+# func_to_host_file_result.
+func_convert_path_cygwin_to_w32 ()
+{
+  $opt_debug
+  func_to_host_path_result="$1"
+  if test -n "$1"; then
+    # See func_convert_path_msys_to_w32:
+    func_stripname : : "$1"
+    func_to_host_path_tmp1=$func_stripname_result
+    func_to_host_path_result=`cygpath -m -p "$func_to_host_path_tmp1"`
+    func_convert_path_check : ";" \
+      "$func_to_host_path_tmp1" "$func_to_host_path_result"
+    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
+  fi
+}
+# end func_convert_path_cygwin_to_w32
+
+
+# func_convert_path_nix_to_w32 ARG
+# Convert path ARG from *nix to w32 format.  Requires a wine environment and
+# a working winepath.  Returns result in func_to_host_file_result.
+func_convert_path_nix_to_w32 ()
+{
+  $opt_debug
+  func_to_host_path_result="$1"
+  if test -n "$1"; then
+    # See func_convert_path_msys_to_w32:
+    func_stripname : : "$1"
+    func_to_host_path_tmp1=$func_stripname_result
+    func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1"
+    func_to_host_path_result="$func_convert_core_path_wine_to_w32_result"
+    func_convert_path_check : ";" \
+      "$func_to_host_path_tmp1" "$func_to_host_path_result"
+    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
+  fi
+}
+# end func_convert_path_nix_to_w32
+
+
+# func_convert_path_msys_to_cygwin ARG
+# Convert path ARG from MSYS to Cygwin format.  Requires LT_CYGPATH set.
+# Returns result in func_to_host_file_result.
+func_convert_path_msys_to_cygwin ()
+{
+  $opt_debug
+  func_to_host_path_result="$1"
+  if test -n "$1"; then
+    # See func_convert_path_msys_to_w32:
+    func_stripname : : "$1"
+    func_to_host_path_tmp1=$func_stripname_result
+    func_convert_core_msys_to_w32 "$func_to_host_path_tmp1"
+    func_cygpath -u -p "$func_convert_core_msys_to_w32_result"
+    func_to_host_path_result="$func_cygpath_result"
+    func_convert_path_check : : \
+      "$func_to_host_path_tmp1" "$func_to_host_path_result"
+    func_convert_path_front_back_pathsep ":*" "*:" : "$1"
+  fi
+}
+# end func_convert_path_msys_to_cygwin
+
+
+# func_convert_path_nix_to_cygwin ARG
+# Convert path ARG from *nix to Cygwin format.  Requires Cygwin installed in a
+# a wine environment, working winepath, and LT_CYGPATH set.  Returns result in
+# func_to_host_file_result.
+func_convert_path_nix_to_cygwin ()
+{
+  $opt_debug
+  func_to_host_path_result="$1"
+  if test -n "$1"; then
+    # Remove leading and trailing path separator characters from
+    # ARG. msys behavior is inconsistent here, cygpath turns them
+    # into '.;' and ';.', and winepath ignores them completely.
+    func_stripname : : "$1"
+    func_to_host_path_tmp1=$func_stripname_result
+    func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1"
+    func_cygpath -u -p "$func_convert_core_path_wine_to_w32_result"
+    func_to_host_path_result="$func_cygpath_result"
+    func_convert_path_check : : \
+      "$func_to_host_path_tmp1" "$func_to_host_path_result"
+    func_convert_path_front_back_pathsep ":*" "*:" : "$1"
+  fi
+}
+# end func_convert_path_nix_to_cygwin
+
+
+# func_mode_compile arg...
+func_mode_compile ()
+{
+    $opt_debug
+    # Get the compilation command and the source file.
+    base_compile=
+    srcfile="$nonopt"  #  always keep a non-empty value in "srcfile"
+    suppress_opt=yes
+    suppress_output=
+    arg_mode=normal
+    libobj=
+    later=
+    pie_flag=
+
+    for arg
+    do
+      case $arg_mode in
+      arg  )
+	# do not "continue".  Instead, add this to base_compile
+	lastarg="$arg"
+	arg_mode=normal
+	;;
+
+      target )
+	libobj="$arg"
+	arg_mode=normal
+	continue
+	;;
+
+      normal )
+	# Accept any command-line options.
+	case $arg in
+	-o)
+	  test -n "$libobj" && \
+	    func_fatal_error "you cannot specify \`-o' more than once"
+	  arg_mode=target
+	  continue
+	  ;;
+
+	-pie | -fpie | -fPIE)
+          func_append pie_flag " $arg"
+	  continue
+	  ;;
+
+	-shared | -static | -prefer-pic | -prefer-non-pic)
+	  func_append later " $arg"
+	  continue
+	  ;;
+
+	-no-suppress)
+	  suppress_opt=no
+	  continue
+	  ;;
+
+	-Xcompiler)
+	  arg_mode=arg  #  the next one goes into the "base_compile" arg list
+	  continue      #  The current "srcfile" will either be retained or
+	  ;;            #  replaced later.  I would guess that would be a bug.
+
+	-Wc,*)
+	  func_stripname '-Wc,' '' "$arg"
+	  args=$func_stripname_result
+	  lastarg=
+	  save_ifs="$IFS"; IFS=','
+	  for arg in $args; do
+	    IFS="$save_ifs"
+	    func_append_quoted lastarg "$arg"
+	  done
+	  IFS="$save_ifs"
+	  func_stripname ' ' '' "$lastarg"
+	  lastarg=$func_stripname_result
+
+	  # Add the arguments to base_compile.
+	  func_append base_compile " $lastarg"
+	  continue
+	  ;;
+
+	*)
+	  # Accept the current argument as the source file.
+	  # The previous "srcfile" becomes the current argument.
+	  #
+	  lastarg="$srcfile"
+	  srcfile="$arg"
+	  ;;
+	esac  #  case $arg
+	;;
+      esac    #  case $arg_mode
+
+      # Aesthetically quote the previous argument.
+      func_append_quoted base_compile "$lastarg"
+    done # for arg
+
+    case $arg_mode in
+    arg)
+      func_fatal_error "you must specify an argument for -Xcompile"
+      ;;
+    target)
+      func_fatal_error "you must specify a target with \`-o'"
+      ;;
+    *)
+      # Get the name of the library object.
+      test -z "$libobj" && {
+	func_basename "$srcfile"
+	libobj="$func_basename_result"
+      }
+      ;;
+    esac
+
+    # Recognize several different file suffixes.
+    # If the user specifies -o file.o, it is replaced with file.lo
+    case $libobj in
+    *.[cCFSifmso] | \
+    *.ada | *.adb | *.ads | *.asm | \
+    *.c++ | *.cc | *.ii | *.class | *.cpp | *.cxx | \
+    *.[fF][09]? | *.for | *.java | *.go | *.obj | *.sx | *.cu | *.cup)
+      func_xform "$libobj"
+      libobj=$func_xform_result
+      ;;
+    esac
+
+    case $libobj in
+    *.lo) func_lo2o "$libobj"; obj=$func_lo2o_result ;;
+    *)
+      func_fatal_error "cannot determine name of library object from \`$libobj'"
+      ;;
+    esac
+
+    func_infer_tag $base_compile
+
+    for arg in $later; do
+      case $arg in
+      -shared)
+	test "$build_libtool_libs" != yes && \
+	  func_fatal_configuration "can not build a shared library"
+	build_old_libs=no
+	continue
+	;;
+
+      -static)
+	build_libtool_libs=no
+	build_old_libs=yes
+	continue
+	;;
+
+      -prefer-pic)
+	pic_mode=yes
+	continue
+	;;
+
+      -prefer-non-pic)
+	pic_mode=no
+	continue
+	;;
+      esac
+    done
+
+    func_quote_for_eval "$libobj"
+    test "X$libobj" != "X$func_quote_for_eval_result" \
+      && $ECHO "X$libobj" | $GREP '[]~#^*{};<>?"'"'"'	 &()|`$[]' \
+      && func_warning "libobj name \`$libobj' may not contain shell special characters."
+    func_dirname_and_basename "$obj" "/" ""
+    objname="$func_basename_result"
+    xdir="$func_dirname_result"
+    lobj=${xdir}$objdir/$objname
+
+    test -z "$base_compile" && \
+      func_fatal_help "you must specify a compilation command"
+
+    # Delete any leftover library objects.
+    if test "$build_old_libs" = yes; then
+      removelist="$obj $lobj $libobj ${libobj}T"
+    else
+      removelist="$lobj $libobj ${libobj}T"
+    fi
+
+    # On Cygwin there's no "real" PIC flag so we must build both object types
+    case $host_os in
+    cygwin* | mingw* | pw32* | os2* | cegcc*)
+      pic_mode=default
+      ;;
+    esac
+    if test "$pic_mode" = no && test "$deplibs_check_method" != pass_all; then
+      # non-PIC code in shared libraries is not supported
+      pic_mode=default
+    fi
+
+    # Calculate the filename of the output object if compiler does
+    # not support -o with -c
+    if test "$compiler_c_o" = no; then
+      output_obj=`$ECHO "$srcfile" | $SED 's%^.*/%%; s%\.[^.]*$%%'`.${objext}
+      lockfile="$output_obj.lock"
+    else
+      output_obj=
+      need_locks=no
+      lockfile=
+    fi
+
+    # Lock this critical section if it is needed
+    # We use this script file to make the link, it avoids creating a new file
+    if test "$need_locks" = yes; then
+      until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do
+	func_echo "Waiting for $lockfile to be removed"
+	sleep 2
+      done
+    elif test "$need_locks" = warn; then
+      if test -f "$lockfile"; then
+	$ECHO "\
+*** ERROR, $lockfile exists and contains:
+`cat $lockfile 2>/dev/null`
+
+This indicates that another process is trying to use the same
+temporary object file, and libtool could not work around it because
+your compiler does not support \`-c' and \`-o' together.  If you
+repeat this compilation, it may succeed, by chance, but you had better
+avoid parallel builds (make -j) in this platform, or get a better
+compiler."
+
+	$opt_dry_run || $RM $removelist
+	exit $EXIT_FAILURE
+      fi
+      func_append removelist " $output_obj"
+      $ECHO "$srcfile" > "$lockfile"
+    fi
+
+    $opt_dry_run || $RM $removelist
+    func_append removelist " $lockfile"
+    trap '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE' 1 2 15
+
+    func_to_tool_file "$srcfile" func_convert_file_msys_to_w32
+    srcfile=$func_to_tool_file_result
+    func_quote_for_eval "$srcfile"
+    qsrcfile=$func_quote_for_eval_result
+
+    # Only build a PIC object if we are building libtool libraries.
+    if test "$build_libtool_libs" = yes; then
+      # Without this assignment, base_compile gets emptied.
+      fbsd_hideous_sh_bug=$base_compile
+
+      if test "$pic_mode" != no; then
+	command="$base_compile $qsrcfile $pic_flag"
+      else
+	# Don't build PIC code
+	command="$base_compile $qsrcfile"
+      fi
+
+      func_mkdir_p "$xdir$objdir"
+
+      if test -z "$output_obj"; then
+	# Place PIC objects in $objdir
+	func_append command " -o $lobj"
+      fi
+
+      func_show_eval_locale "$command"	\
+          'test -n "$output_obj" && $RM $removelist; exit $EXIT_FAILURE'
+
+      if test "$need_locks" = warn &&
+	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
+	$ECHO "\
+*** ERROR, $lockfile contains:
+`cat $lockfile 2>/dev/null`
+
+but it should contain:
+$srcfile
+
+This indicates that another process is trying to use the same
+temporary object file, and libtool could not work around it because
+your compiler does not support \`-c' and \`-o' together.  If you
+repeat this compilation, it may succeed, by chance, but you had better
+avoid parallel builds (make -j) in this platform, or get a better
+compiler."
+
+	$opt_dry_run || $RM $removelist
+	exit $EXIT_FAILURE
+      fi
+
+      # Just move the object if needed, then go on to compile the next one
+      if test -n "$output_obj" && test "X$output_obj" != "X$lobj"; then
+	func_show_eval '$MV "$output_obj" "$lobj"' \
+	  'error=$?; $opt_dry_run || $RM $removelist; exit $error'
+      fi
+
+      # Allow error messages only from the first compilation.
+      if test "$suppress_opt" = yes; then
+	suppress_output=' >/dev/null 2>&1'
+      fi
+    fi
+
+    # Only build a position-dependent object if we build old libraries.
+    if test "$build_old_libs" = yes; then
+      if test "$pic_mode" != yes; then
+	# Don't build PIC code
+	command="$base_compile $qsrcfile$pie_flag"
+      else
+	command="$base_compile $qsrcfile $pic_flag"
+      fi
+      if test "$compiler_c_o" = yes; then
+	func_append command " -o $obj"
+      fi
+
+      # Suppress compiler output if we already did a PIC compilation.
+      func_append command "$suppress_output"
+      func_show_eval_locale "$command" \
+        '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE'
+
+      if test "$need_locks" = warn &&
+	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
+	$ECHO "\
+*** ERROR, $lockfile contains:
+`cat $lockfile 2>/dev/null`
+
+but it should contain:
+$srcfile
+
+This indicates that another process is trying to use the same
+temporary object file, and libtool could not work around it because
+your compiler does not support \`-c' and \`-o' together.  If you
+repeat this compilation, it may succeed, by chance, but you had better
+avoid parallel builds (make -j) in this platform, or get a better
+compiler."
+
+	$opt_dry_run || $RM $removelist
+	exit $EXIT_FAILURE
+      fi
+
+      # Just move the object if needed
+      if test -n "$output_obj" && test "X$output_obj" != "X$obj"; then
+	func_show_eval '$MV "$output_obj" "$obj"' \
+	  'error=$?; $opt_dry_run || $RM $removelist; exit $error'
+      fi
+    fi
+
+    $opt_dry_run || {
+      func_write_libtool_object "$libobj" "$objdir/$objname" "$objname"
+
+      # Unlock the critical section if it was locked
+      if test "$need_locks" != no; then
+	removelist=$lockfile
+        $RM "$lockfile"
+      fi
+    }
+
+    exit $EXIT_SUCCESS
+}
+
+$opt_help || {
+  test "$opt_mode" = compile && func_mode_compile ${1+"$@"}
+}
+
+func_mode_help ()
+{
+    # We need to display help for each of the modes.
+    case $opt_mode in
+      "")
+        # Generic help is extracted from the usage comments
+        # at the start of this file.
+        func_help
+        ;;
+
+      clean)
+        $ECHO \
+"Usage: $progname [OPTION]... --mode=clean RM [RM-OPTION]... FILE...
+
+Remove files from the build directory.
+
+RM is the name of the program to use to delete files associated with each FILE
+(typically \`/bin/rm').  RM-OPTIONS are options (such as \`-f') to be passed
+to RM.
+
+If FILE is a libtool library, object or program, all the files associated
+with it are deleted. Otherwise, only FILE itself is deleted using RM."
+        ;;
+
+      compile)
+      $ECHO \
+"Usage: $progname [OPTION]... --mode=compile COMPILE-COMMAND... SOURCEFILE
+
+Compile a source file into a libtool library object.
+
+This mode accepts the following additional options:
+
+  -o OUTPUT-FILE    set the output file name to OUTPUT-FILE
+  -no-suppress      do not suppress compiler output for multiple passes
+  -prefer-pic       try to build PIC objects only
+  -prefer-non-pic   try to build non-PIC objects only
+  -shared           do not build a \`.o' file suitable for static linking
+  -static           only build a \`.o' file suitable for static linking
+  -Wc,FLAG          pass FLAG directly to the compiler
+
+COMPILE-COMMAND is a command to be used in creating a \`standard' object file
+from the given SOURCEFILE.
+
+The output file name is determined by removing the directory component from
+SOURCEFILE, then substituting the C source code suffix \`.c' with the
+library object suffix, \`.lo'."
+        ;;
+
+      execute)
+        $ECHO \
+"Usage: $progname [OPTION]... --mode=execute COMMAND [ARGS]...
+
+Automatically set library path, then run a program.
+
+This mode accepts the following additional options:
+
+  -dlopen FILE      add the directory containing FILE to the library path
+
+This mode sets the library path environment variable according to \`-dlopen'
+flags.
+
+If any of the ARGS are libtool executable wrappers, then they are translated
+into their corresponding uninstalled binary, and any of their required library
+directories are added to the library path.
+
+Then, COMMAND is executed, with ARGS as arguments."
+        ;;
+
+      finish)
+        $ECHO \
+"Usage: $progname [OPTION]... --mode=finish [LIBDIR]...
+
+Complete the installation of libtool libraries.
+
+Each LIBDIR is a directory that contains libtool libraries.
+
+The commands that this mode executes may require superuser privileges.  Use
+the \`--dry-run' option if you just want to see what would be executed."
+        ;;
+
+      install)
+        $ECHO \
+"Usage: $progname [OPTION]... --mode=install INSTALL-COMMAND...
+
+Install executables or libraries.
+
+INSTALL-COMMAND is the installation command.  The first component should be
+either the \`install' or \`cp' program.
+
+The following components of INSTALL-COMMAND are treated specially:
+
+  -inst-prefix-dir PREFIX-DIR  Use PREFIX-DIR as a staging area for installation
+
+The rest of the components are interpreted as arguments to that command (only
+BSD-compatible install options are recognized)."
+        ;;
+
+      link)
+        $ECHO \
+"Usage: $progname [OPTION]... --mode=link LINK-COMMAND...
+
+Link object files or libraries together to form another library, or to
+create an executable program.
+
+LINK-COMMAND is a command using the C compiler that you would use to create
+a program from several object files.
+
+The following components of LINK-COMMAND are treated specially:
+
+  -all-static       do not do any dynamic linking at all
+  -avoid-version    do not add a version suffix if possible
+  -bindir BINDIR    specify path to binaries directory (for systems where
+                    libraries must be found in the PATH setting at runtime)
+  -dlopen FILE      \`-dlpreopen' FILE if it cannot be dlopened at runtime
+  -dlpreopen FILE   link in FILE and add its symbols to lt_preloaded_symbols
+  -export-dynamic   allow symbols from OUTPUT-FILE to be resolved with dlsym(3)
+  -export-symbols SYMFILE
+                    try to export only the symbols listed in SYMFILE
+  -export-symbols-regex REGEX
+                    try to export only the symbols matching REGEX
+  -LLIBDIR          search LIBDIR for required installed libraries
+  -lNAME            OUTPUT-FILE requires the installed library libNAME
+  -module           build a library that can dlopened
+  -no-fast-install  disable the fast-install mode
+  -no-install       link a not-installable executable
+  -no-undefined     declare that a library does not refer to external symbols
+  -o OUTPUT-FILE    create OUTPUT-FILE from the specified objects
+  -objectlist FILE  Use a list of object files found in FILE to specify objects
+  -precious-files-regex REGEX
+                    don't remove output files matching REGEX
+  -release RELEASE  specify package release information
+  -rpath LIBDIR     the created library will eventually be installed in LIBDIR
+  -R[ ]LIBDIR       add LIBDIR to the runtime path of programs and libraries
+  -shared           only do dynamic linking of libtool libraries
+  -shrext SUFFIX    override the standard shared library file extension
+  -static           do not do any dynamic linking of uninstalled libtool libraries
+  -static-libtool-libs
+                    do not do any dynamic linking of libtool libraries
+  -version-info CURRENT[:REVISION[:AGE]]
+                    specify library version info [each variable defaults to 0]
+  -weak LIBNAME     declare that the target provides the LIBNAME interface
+  -Wc,FLAG
+  -Xcompiler FLAG   pass linker-specific FLAG directly to the compiler
+  -Wl,FLAG
+  -Xlinker FLAG     pass linker-specific FLAG directly to the linker
+  -XCClinker FLAG   pass link-specific FLAG to the compiler driver (CC)
+
+All other options (arguments beginning with \`-') are ignored.
+
+Every other argument is treated as a filename.  Files ending in \`.la' are
+treated as uninstalled libtool libraries, other files are standard or library
+object files.
+
+If the OUTPUT-FILE ends in \`.la', then a libtool library is created,
+only library objects (\`.lo' files) may be specified, and \`-rpath' is
+required, except when creating a convenience library.
+
+If OUTPUT-FILE ends in \`.a' or \`.lib', then a standard library is created
+using \`ar' and \`ranlib', or on Windows using \`lib'.
+
+If OUTPUT-FILE ends in \`.lo' or \`.${objext}', then a reloadable object file
+is created, otherwise an executable program is created."
+        ;;
+
+      uninstall)
+        $ECHO \
+"Usage: $progname [OPTION]... --mode=uninstall RM [RM-OPTION]... FILE...
+
+Remove libraries from an installation directory.
+
+RM is the name of the program to use to delete files associated with each FILE
+(typically \`/bin/rm').  RM-OPTIONS are options (such as \`-f') to be passed
+to RM.
+
+If FILE is a libtool library, all the files associated with it are deleted.
+Otherwise, only FILE itself is deleted using RM."
+        ;;
+
+      *)
+        func_fatal_help "invalid operation mode \`$opt_mode'"
+        ;;
+    esac
+
+    echo
+    $ECHO "Try \`$progname --help' for more information about other modes."
+}
+
+# Now that we've collected a possible --mode arg, show help if necessary
+if $opt_help; then
+  if test "$opt_help" = :; then
+    func_mode_help
+  else
+    {
+      func_help noexit
+      for opt_mode in compile link execute install finish uninstall clean; do
+	func_mode_help
+      done
+    } | sed -n '1p; 2,$s/^Usage:/  or: /p'
+    {
+      func_help noexit
+      for opt_mode in compile link execute install finish uninstall clean; do
+	echo
+	func_mode_help
+      done
+    } |
+    sed '1d
+      /^When reporting/,/^Report/{
+	H
+	d
+      }
+      $x
+      /information about other modes/d
+      /more detailed .*MODE/d
+      s/^Usage:.*--mode=\([^ ]*\) .*/Description of \1 mode:/'
+  fi
+  exit $?
+fi
+
+
+# func_mode_execute arg...
+func_mode_execute ()
+{
+    $opt_debug
+    # The first argument is the command name.
+    cmd="$nonopt"
+    test -z "$cmd" && \
+      func_fatal_help "you must specify a COMMAND"
+
+    # Handle -dlopen flags immediately.
+    for file in $opt_dlopen; do
+      test -f "$file" \
+	|| func_fatal_help "\`$file' is not a file"
+
+      dir=
+      case $file in
+      *.la)
+	func_resolve_sysroot "$file"
+	file=$func_resolve_sysroot_result
+
+	# Check to see that this really is a libtool archive.
+	func_lalib_unsafe_p "$file" \
+	  || func_fatal_help "\`$lib' is not a valid libtool archive"
+
+	# Read the libtool library.
+	dlname=
+	library_names=
+	func_source "$file"
+
+	# Skip this library if it cannot be dlopened.
+	if test -z "$dlname"; then
+	  # Warn if it was a shared library.
+	  test -n "$library_names" && \
+	    func_warning "\`$file' was not linked with \`-export-dynamic'"
+	  continue
+	fi
+
+	func_dirname "$file" "" "."
+	dir="$func_dirname_result"
+
+	if test -f "$dir/$objdir/$dlname"; then
+	  func_append dir "/$objdir"
+	else
+	  if test ! -f "$dir/$dlname"; then
+	    func_fatal_error "cannot find \`$dlname' in \`$dir' or \`$dir/$objdir'"
+	  fi
+	fi
+	;;
+
+      *.lo)
+	# Just add the directory containing the .lo file.
+	func_dirname "$file" "" "."
+	dir="$func_dirname_result"
+	;;
+
+      *)
+	func_warning "\`-dlopen' is ignored for non-libtool libraries and objects"
+	continue
+	;;
+      esac
+
+      # Get the absolute pathname.
+      absdir=`cd "$dir" && pwd`
+      test -n "$absdir" && dir="$absdir"
+
+      # Now add the directory to shlibpath_var.
+      if eval "test -z \"\$$shlibpath_var\""; then
+	eval "$shlibpath_var=\"\$dir\""
+      else
+	eval "$shlibpath_var=\"\$dir:\$$shlibpath_var\""
+      fi
+    done
+
+    # This variable tells wrapper scripts just to set shlibpath_var
+    # rather than running their programs.
+    libtool_execute_magic="$magic"
+
+    # Check if any of the arguments is a wrapper script.
+    args=
+    for file
+    do
+      case $file in
+      -* | *.la | *.lo ) ;;
+      *)
+	# Do a test to see if this is really a libtool program.
+	if func_ltwrapper_script_p "$file"; then
+	  func_source "$file"
+	  # Transform arg to wrapped name.
+	  file="$progdir/$program"
+	elif func_ltwrapper_executable_p "$file"; then
+	  func_ltwrapper_scriptname "$file"
+	  func_source "$func_ltwrapper_scriptname_result"
+	  # Transform arg to wrapped name.
+	  file="$progdir/$program"
+	fi
+	;;
+      esac
+      # Quote arguments (to preserve shell metacharacters).
+      func_append_quoted args "$file"
+    done
+
+    if test "X$opt_dry_run" = Xfalse; then
+      if test -n "$shlibpath_var"; then
+	# Export the shlibpath_var.
+	eval "export $shlibpath_var"
+      fi
+
+      # Restore saved environment variables
+      for lt_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
+      do
+	eval "if test \"\${save_$lt_var+set}\" = set; then
+                $lt_var=\$save_$lt_var; export $lt_var
+	      else
+		$lt_unset $lt_var
+	      fi"
+      done
+
+      # Now prepare to actually exec the command.
+      exec_cmd="\$cmd$args"
+    else
+      # Display what would be done.
+      if test -n "$shlibpath_var"; then
+	eval "\$ECHO \"\$shlibpath_var=\$$shlibpath_var\""
+	echo "export $shlibpath_var"
+      fi
+      $ECHO "$cmd$args"
+      exit $EXIT_SUCCESS
+    fi
+}
+
+test "$opt_mode" = execute && func_mode_execute ${1+"$@"}
+
+
+# func_mode_finish arg...
+func_mode_finish ()
+{
+    $opt_debug
+    libs=
+    libdirs=
+    admincmds=
+
+    for opt in "$nonopt" ${1+"$@"}
+    do
+      if test -d "$opt"; then
+	func_append libdirs " $opt"
+
+      elif test -f "$opt"; then
+	if func_lalib_unsafe_p "$opt"; then
+	  func_append libs " $opt"
+	else
+	  func_warning "\`$opt' is not a valid libtool archive"
+	fi
+
+      else
+	func_fatal_error "invalid argument \`$opt'"
+      fi
+    done
+
+    if test -n "$libs"; then
+      if test -n "$lt_sysroot"; then
+        sysroot_regex=`$ECHO "$lt_sysroot" | $SED "$sed_make_literal_regex"`
+        sysroot_cmd="s/\([ ']\)$sysroot_regex/\1/g;"
+      else
+        sysroot_cmd=
+      fi
+
+      # Remove sysroot references
+      if $opt_dry_run; then
+        for lib in $libs; do
+          echo "removing references to $lt_sysroot and \`=' prefixes from $lib"
+        done
+      else
+        tmpdir=`func_mktempdir`
+        for lib in $libs; do
+	  sed -e "${sysroot_cmd} s/\([ ']-[LR]\)=/\1/g; s/\([ ']\)=/\1/g" $lib \
+	    > $tmpdir/tmp-la
+	  mv -f $tmpdir/tmp-la $lib
+	done
+        ${RM}r "$tmpdir"
+      fi
+    fi
+
+    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then
+      for libdir in $libdirs; do
+	if test -n "$finish_cmds"; then
+	  # Do each command in the finish commands.
+	  func_execute_cmds "$finish_cmds" 'admincmds="$admincmds
+'"$cmd"'"'
+	fi
+	if test -n "$finish_eval"; then
+	  # Do the single finish_eval.
+	  eval cmds=\"$finish_eval\"
+	  $opt_dry_run || eval "$cmds" || func_append admincmds "
+       $cmds"
+	fi
+      done
+    fi
+
+    # Exit here if they wanted silent mode.
+    $opt_silent && exit $EXIT_SUCCESS
+
+    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then
+      echo "----------------------------------------------------------------------"
+      echo "Libraries have been installed in:"
+      for libdir in $libdirs; do
+	$ECHO "   $libdir"
+      done
+      echo
+      echo "If you ever happen to want to link against installed libraries"
+      echo "in a given directory, LIBDIR, you must either use libtool, and"
+      echo "specify the full pathname of the library, or use the \`-LLIBDIR'"
+      echo "flag during linking and do at least one of the following:"
+      if test -n "$shlibpath_var"; then
+	echo "   - add LIBDIR to the \`$shlibpath_var' environment variable"
+	echo "     during execution"
+      fi
+      if test -n "$runpath_var"; then
+	echo "   - add LIBDIR to the \`$runpath_var' environment variable"
+	echo "     during linking"
+      fi
+      if test -n "$hardcode_libdir_flag_spec"; then
+	libdir=LIBDIR
+	eval flag=\"$hardcode_libdir_flag_spec\"
+
+	$ECHO "   - use the \`$flag' linker flag"
+      fi
+      if test -n "$admincmds"; then
+	$ECHO "   - have your system administrator run these commands:$admincmds"
+      fi
+      if test -f /etc/ld.so.conf; then
+	echo "   - have your system administrator add LIBDIR to \`/etc/ld.so.conf'"
+      fi
+      echo
+
+      echo "See any operating system documentation about shared libraries for"
+      case $host in
+	solaris2.[6789]|solaris2.1[0-9])
+	  echo "more information, such as the ld(1), crle(1) and ld.so(8) manual"
+	  echo "pages."
+	  ;;
+	*)
+	  echo "more information, such as the ld(1) and ld.so(8) manual pages."
+	  ;;
+      esac
+      echo "----------------------------------------------------------------------"
+    fi
+    exit $EXIT_SUCCESS
+}
+
+test "$opt_mode" = finish && func_mode_finish ${1+"$@"}
+
+
+# func_mode_install arg...
+func_mode_install ()
+{
+    $opt_debug
+    # There may be an optional sh(1) argument at the beginning of
+    # install_prog (especially on Windows NT).
+    if test "$nonopt" = "$SHELL" || test "$nonopt" = /bin/sh ||
+       # Allow the use of GNU shtool's install command.
+       case $nonopt in *shtool*) :;; *) false;; esac; then
+      # Aesthetically quote it.
+      func_quote_for_eval "$nonopt"
+      install_prog="$func_quote_for_eval_result "
+      arg=$1
+      shift
+    else
+      install_prog=
+      arg=$nonopt
+    fi
+
+    # The real first argument should be the name of the installation program.
+    # Aesthetically quote it.
+    func_quote_for_eval "$arg"
+    func_append install_prog "$func_quote_for_eval_result"
+    install_shared_prog=$install_prog
+    case " $install_prog " in
+      *[\\\ /]cp\ *) install_cp=: ;;
+      *) install_cp=false ;;
+    esac
+
+    # We need to accept at least all the BSD install flags.
+    dest=
+    files=
+    opts=
+    prev=
+    install_type=
+    isdir=no
+    stripme=
+    no_mode=:
+    for arg
+    do
+      arg2=
+      if test -n "$dest"; then
+	func_append files " $dest"
+	dest=$arg
+	continue
+      fi
+
+      case $arg in
+      -d) isdir=yes ;;
+      -f)
+	if $install_cp; then :; else
+	  prev=$arg
+	fi
+	;;
+      -g | -m | -o)
+	prev=$arg
+	;;
+      -s)
+	stripme=" -s"
+	continue
+	;;
+      -*)
+	;;
+      *)
+	# If the previous option needed an argument, then skip it.
+	if test -n "$prev"; then
+	  if test "x$prev" = x-m && test -n "$install_override_mode"; then
+	    arg2=$install_override_mode
+	    no_mode=false
+	  fi
+	  prev=
+	else
+	  dest=$arg
+	  continue
+	fi
+	;;
+      esac
+
+      # Aesthetically quote the argument.
+      func_quote_for_eval "$arg"
+      func_append install_prog " $func_quote_for_eval_result"
+      if test -n "$arg2"; then
+	func_quote_for_eval "$arg2"
+      fi
+      func_append install_shared_prog " $func_quote_for_eval_result"
+    done
+
+    test -z "$install_prog" && \
+      func_fatal_help "you must specify an install program"
+
+    test -n "$prev" && \
+      func_fatal_help "the \`$prev' option requires an argument"
+
+    if test -n "$install_override_mode" && $no_mode; then
+      if $install_cp; then :; else
+	func_quote_for_eval "$install_override_mode"
+	func_append install_shared_prog " -m $func_quote_for_eval_result"
+      fi
+    fi
+
+    if test -z "$files"; then
+      if test -z "$dest"; then
+	func_fatal_help "no file or destination specified"
+      else
+	func_fatal_help "you must specify a destination"
+      fi
+    fi
+
+    # Strip any trailing slash from the destination.
+    func_stripname '' '/' "$dest"
+    dest=$func_stripname_result
+
+    # Check to see that the destination is a directory.
+    test -d "$dest" && isdir=yes
+    if test "$isdir" = yes; then
+      destdir="$dest"
+      destname=
+    else
+      func_dirname_and_basename "$dest" "" "."
+      destdir="$func_dirname_result"
+      destname="$func_basename_result"
+
+      # Not a directory, so check to see that there is only one file specified.
+      set dummy $files; shift
+      test "$#" -gt 1 && \
+	func_fatal_help "\`$dest' is not a directory"
+    fi
+    case $destdir in
+    [\\/]* | [A-Za-z]:[\\/]*) ;;
+    *)
+      for file in $files; do
+	case $file in
+	*.lo) ;;
+	*)
+	  func_fatal_help "\`$destdir' must be an absolute directory name"
+	  ;;
+	esac
+      done
+      ;;
+    esac
+
+    # This variable tells wrapper scripts just to set variables rather
+    # than running their programs.
+    libtool_install_magic="$magic"
+
+    staticlibs=
+    future_libdirs=
+    current_libdirs=
+    for file in $files; do
+
+      # Do each installation.
+      case $file in
+      *.$libext)
+	# Do the static libraries later.
+	func_append staticlibs " $file"
+	;;
+
+      *.la)
+	func_resolve_sysroot "$file"
+	file=$func_resolve_sysroot_result
+
+	# Check to see that this really is a libtool archive.
+	func_lalib_unsafe_p "$file" \
+	  || func_fatal_help "\`$file' is not a valid libtool archive"
+
+	library_names=
+	old_library=
+	relink_command=
+	func_source "$file"
+
+	# Add the libdir to current_libdirs if it is the destination.
+	if test "X$destdir" = "X$libdir"; then
+	  case "$current_libdirs " in
+	  *" $libdir "*) ;;
+	  *) func_append current_libdirs " $libdir" ;;
+	  esac
+	else
+	  # Note the libdir as a future libdir.
+	  case "$future_libdirs " in
+	  *" $libdir "*) ;;
+	  *) func_append future_libdirs " $libdir" ;;
+	  esac
+	fi
+
+	func_dirname "$file" "/" ""
+	dir="$func_dirname_result"
+	func_append dir "$objdir"
+
+	if test -n "$relink_command"; then
+	  # Determine the prefix the user has applied to our future dir.
+	  inst_prefix_dir=`$ECHO "$destdir" | $SED -e "s%$libdir\$%%"`
+
+	  # Don't allow the user to place us outside of our expected
+	  # location b/c this prevents finding dependent libraries that
+	  # are installed to the same prefix.
+	  # At present, this check doesn't affect windows .dll's that
+	  # are installed into $libdir/../bin (currently, that works fine)
+	  # but it's something to keep an eye on.
+	  test "$inst_prefix_dir" = "$destdir" && \
+	    func_fatal_error "error: cannot install \`$file' to a directory not ending in $libdir"
+
+	  if test -n "$inst_prefix_dir"; then
+	    # Stick the inst_prefix_dir data into the link command.
+	    relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%-inst-prefix-dir $inst_prefix_dir%"`
+	  else
+	    relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%%"`
+	  fi
+
+	  func_warning "relinking \`$file'"
+	  func_show_eval "$relink_command" \
+	    'func_fatal_error "error: relink \`$file'\'' with the above command before installing it"'
+	fi
+
+	# See the names of the shared library.
+	set dummy $library_names; shift
+	if test -n "$1"; then
+	  realname="$1"
+	  shift
+
+	  srcname="$realname"
+	  test -n "$relink_command" && srcname="$realname"T
+
+	  # Install the shared library and build the symlinks.
+	  func_show_eval "$install_shared_prog $dir/$srcname $destdir/$realname" \
+	      'exit $?'
+	  tstripme="$stripme"
+	  case $host_os in
+	  cygwin* | mingw* | pw32* | cegcc*)
+	    case $realname in
+	    *.dll.a)
+	      tstripme=""
+	      ;;
+	    esac
+	    ;;
+	  esac
+	  if test -n "$tstripme" && test -n "$striplib"; then
+	    func_show_eval "$striplib $destdir/$realname" 'exit $?'
+	  fi
+
+	  if test "$#" -gt 0; then
+	    # Delete the old symlinks, and create new ones.
+	    # Try `ln -sf' first, because the `ln' binary might depend on
+	    # the symlink we replace!  Solaris /bin/ln does not understand -f,
+	    # so we also need to try rm && ln -s.
+	    for linkname
+	    do
+	      test "$linkname" != "$realname" \
+		&& func_show_eval "(cd $destdir && { $LN_S -f $realname $linkname || { $RM $linkname && $LN_S $realname $linkname; }; })"
+	    done
+	  fi
+
+	  # Do each command in the postinstall commands.
+	  lib="$destdir/$realname"
+	  func_execute_cmds "$postinstall_cmds" 'exit $?'
+	fi
+
+	# Install the pseudo-library for information purposes.
+	func_basename "$file"
+	name="$func_basename_result"
+	instname="$dir/$name"i
+	func_show_eval "$install_prog $instname $destdir/$name" 'exit $?'
+
+	# Maybe install the static library, too.
+	test -n "$old_library" && func_append staticlibs " $dir/$old_library"
+	;;
+
+      *.lo)
+	# Install (i.e. copy) a libtool object.
+
+	# Figure out destination file name, if it wasn't already specified.
+	if test -n "$destname"; then
+	  destfile="$destdir/$destname"
+	else
+	  func_basename "$file"
+	  destfile="$func_basename_result"
+	  destfile="$destdir/$destfile"
+	fi
+
+	# Deduce the name of the destination old-style object file.
+	case $destfile in
+	*.lo)
+	  func_lo2o "$destfile"
+	  staticdest=$func_lo2o_result
+	  ;;
+	*.$objext)
+	  staticdest="$destfile"
+	  destfile=
+	  ;;
+	*)
+	  func_fatal_help "cannot copy a libtool object to \`$destfile'"
+	  ;;
+	esac
+
+	# Install the libtool object if requested.
+	test -n "$destfile" && \
+	  func_show_eval "$install_prog $file $destfile" 'exit $?'
+
+	# Install the old object if enabled.
+	if test "$build_old_libs" = yes; then
+	  # Deduce the name of the old-style object file.
+	  func_lo2o "$file"
+	  staticobj=$func_lo2o_result
+	  func_show_eval "$install_prog \$staticobj \$staticdest" 'exit $?'
+	fi
+	exit $EXIT_SUCCESS
+	;;
+
+      *)
+	# Figure out destination file name, if it wasn't already specified.
+	if test -n "$destname"; then
+	  destfile="$destdir/$destname"
+	else
+	  func_basename "$file"
+	  destfile="$func_basename_result"
+	  destfile="$destdir/$destfile"
+	fi
+
+	# If the file is missing, and there is a .exe on the end, strip it
+	# because it is most likely a libtool script we actually want to
+	# install
+	stripped_ext=""
+	case $file in
+	  *.exe)
+	    if test ! -f "$file"; then
+	      func_stripname '' '.exe' "$file"
+	      file=$func_stripname_result
+	      stripped_ext=".exe"
+	    fi
+	    ;;
+	esac
+
+	# Do a test to see if this is really a libtool program.
+	case $host in
+	*cygwin* | *mingw*)
+	    if func_ltwrapper_executable_p "$file"; then
+	      func_ltwrapper_scriptname "$file"
+	      wrapper=$func_ltwrapper_scriptname_result
+	    else
+	      func_stripname '' '.exe' "$file"
+	      wrapper=$func_stripname_result
+	    fi
+	    ;;
+	*)
+	    wrapper=$file
+	    ;;
+	esac
+	if func_ltwrapper_script_p "$wrapper"; then
+	  notinst_deplibs=
+	  relink_command=
+
+	  func_source "$wrapper"
+
+	  # Check the variables that should have been set.
+	  test -z "$generated_by_libtool_version" && \
+	    func_fatal_error "invalid libtool wrapper script \`$wrapper'"
+
+	  finalize=yes
+	  for lib in $notinst_deplibs; do
+	    # Check to see that each library is installed.
+	    libdir=
+	    if test -f "$lib"; then
+	      func_source "$lib"
+	    fi
+	    libfile="$libdir/"`$ECHO "$lib" | $SED 's%^.*/%%g'` ### testsuite: skip nested quoting test
+	    if test -n "$libdir" && test ! -f "$libfile"; then
+	      func_warning "\`$lib' has not been installed in \`$libdir'"
+	      finalize=no
+	    fi
+	  done
+
+	  relink_command=
+	  func_source "$wrapper"
+
+	  outputname=
+	  if test "$fast_install" = no && test -n "$relink_command"; then
+	    $opt_dry_run || {
+	      if test "$finalize" = yes; then
+	        tmpdir=`func_mktempdir`
+		func_basename "$file$stripped_ext"
+		file="$func_basename_result"
+	        outputname="$tmpdir/$file"
+	        # Replace the output file specification.
+	        relink_command=`$ECHO "$relink_command" | $SED 's%@OUTPUT@%'"$outputname"'%g'`
+
+	        $opt_silent || {
+	          func_quote_for_expand "$relink_command"
+		  eval "func_echo $func_quote_for_expand_result"
+	        }
+	        if eval "$relink_command"; then :
+	          else
+		  func_error "error: relink \`$file' with the above command before installing it"
+		  $opt_dry_run || ${RM}r "$tmpdir"
+		  continue
+	        fi
+	        file="$outputname"
+	      else
+	        func_warning "cannot relink \`$file'"
+	      fi
+	    }
+	  else
+	    # Install the binary that we compiled earlier.
+	    file=`$ECHO "$file$stripped_ext" | $SED "s%\([^/]*\)$%$objdir/\1%"`
+	  fi
+	fi
+
+	# remove .exe since cygwin /usr/bin/install will append another
+	# one anyway
+	case $install_prog,$host in
+	*/usr/bin/install*,*cygwin*)
+	  case $file:$destfile in
+	  *.exe:*.exe)
+	    # this is ok
+	    ;;
+	  *.exe:*)
+	    destfile=$destfile.exe
+	    ;;
+	  *:*.exe)
+	    func_stripname '' '.exe' "$destfile"
+	    destfile=$func_stripname_result
+	    ;;
+	  esac
+	  ;;
+	esac
+	func_show_eval "$install_prog\$stripme \$file \$destfile" 'exit $?'
+	$opt_dry_run || if test -n "$outputname"; then
+	  ${RM}r "$tmpdir"
+	fi
+	;;
+      esac
+    done
+
+    for file in $staticlibs; do
+      func_basename "$file"
+      name="$func_basename_result"
+
+      # Set up the ranlib parameters.
+      oldlib="$destdir/$name"
+      func_to_tool_file "$oldlib" func_convert_file_msys_to_w32
+      tool_oldlib=$func_to_tool_file_result
+
+      func_show_eval "$install_prog \$file \$oldlib" 'exit $?'
+
+      if test -n "$stripme" && test -n "$old_striplib"; then
+	func_show_eval "$old_striplib $tool_oldlib" 'exit $?'
+      fi
+
+      # Do each command in the postinstall commands.
+      func_execute_cmds "$old_postinstall_cmds" 'exit $?'
+    done
+
+    test -n "$future_libdirs" && \
+      func_warning "remember to run \`$progname --finish$future_libdirs'"
+
+    if test -n "$current_libdirs"; then
+      # Maybe just do a dry run.
+      $opt_dry_run && current_libdirs=" -n$current_libdirs"
+      exec_cmd='$SHELL $progpath $preserve_args --finish$current_libdirs'
+    else
+      exit $EXIT_SUCCESS
+    fi
+}
+
+test "$opt_mode" = install && func_mode_install ${1+"$@"}
+
+
+# func_generate_dlsyms outputname originator pic_p
+# Extract symbols from dlprefiles and create ${outputname}S.o with
+# a dlpreopen symbol table.
+func_generate_dlsyms ()
+{
+    $opt_debug
+    my_outputname="$1"
+    my_originator="$2"
+    my_pic_p="${3-no}"
+    my_prefix=`$ECHO "$my_originator" | sed 's%[^a-zA-Z0-9]%_%g'`
+    my_dlsyms=
+
+    if test -n "$dlfiles$dlprefiles" || test "$dlself" != no; then
+      if test -n "$NM" && test -n "$global_symbol_pipe"; then
+	my_dlsyms="${my_outputname}S.c"
+      else
+	func_error "not configured to extract global symbols from dlpreopened files"
+      fi
+    fi
+
+    if test -n "$my_dlsyms"; then
+      case $my_dlsyms in
+      "") ;;
+      *.c)
+	# Discover the nlist of each of the dlfiles.
+	nlist="$output_objdir/${my_outputname}.nm"
+
+	func_show_eval "$RM $nlist ${nlist}S ${nlist}T"
+
+	# Parse the name list into a source file.
+	func_verbose "creating $output_objdir/$my_dlsyms"
+
+	$opt_dry_run || $ECHO > "$output_objdir/$my_dlsyms" "\
+/* $my_dlsyms - symbol resolution table for \`$my_outputname' dlsym emulation. */
+/* Generated by $PROGRAM (GNU $PACKAGE$TIMESTAMP) $VERSION */
+
+#ifdef __cplusplus
+extern \"C\" {
+#endif
+
+#if defined(__GNUC__) && (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 4)) || (__GNUC__ > 4))
+#pragma GCC diagnostic ignored \"-Wstrict-prototypes\"
+#endif
+
+/* Keep this code in sync between libtool.m4, ltmain, lt_system.h, and tests.  */
+#if defined(_WIN32) || defined(__CYGWIN__) || defined(_WIN32_WCE)
+/* DATA imports from DLLs on WIN32 con't be const, because runtime
+   relocations are performed -- see ld's documentation on pseudo-relocs.  */
+# define LT_DLSYM_CONST
+#elif defined(__osf__)
+/* This system does not cope well with relocations in const data.  */
+# define LT_DLSYM_CONST
+#else
+# define LT_DLSYM_CONST const
+#endif
+
+/* External symbol declarations for the compiler. */\
+"
+
+	if test "$dlself" = yes; then
+	  func_verbose "generating symbol list for \`$output'"
+
+	  $opt_dry_run || echo ': @PROGRAM@ ' > "$nlist"
+
+	  # Add our own program objects to the symbol list.
+	  progfiles=`$ECHO "$objs$old_deplibs" | $SP2NL | $SED "$lo2o" | $NL2SP`
+	  for progfile in $progfiles; do
+	    func_to_tool_file "$progfile" func_convert_file_msys_to_w32
+	    func_verbose "extracting global C symbols from \`$func_to_tool_file_result'"
+	    $opt_dry_run || eval "$NM $func_to_tool_file_result | $global_symbol_pipe >> '$nlist'"
+	  done
+
+	  if test -n "$exclude_expsyms"; then
+	    $opt_dry_run || {
+	      eval '$EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T'
+	      eval '$MV "$nlist"T "$nlist"'
+	    }
+	  fi
+
+	  if test -n "$export_symbols_regex"; then
+	    $opt_dry_run || {
+	      eval '$EGREP -e "$export_symbols_regex" "$nlist" > "$nlist"T'
+	      eval '$MV "$nlist"T "$nlist"'
+	    }
+	  fi
+
+	  # Prepare the list of exported symbols
+	  if test -z "$export_symbols"; then
+	    export_symbols="$output_objdir/$outputname.exp"
+	    $opt_dry_run || {
+	      $RM $export_symbols
+	      eval "${SED} -n -e '/^: @PROGRAM@ $/d' -e 's/^.* \(.*\)$/\1/p' "'< "$nlist" > "$export_symbols"'
+	      case $host in
+	      *cygwin* | *mingw* | *cegcc* )
+                eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
+                eval 'cat "$export_symbols" >> "$output_objdir/$outputname.def"'
+	        ;;
+	      esac
+	    }
+	  else
+	    $opt_dry_run || {
+	      eval "${SED} -e 's/\([].[*^$]\)/\\\\\1/g' -e 's/^/ /' -e 's/$/$/'"' < "$export_symbols" > "$output_objdir/$outputname.exp"'
+	      eval '$GREP -f "$output_objdir/$outputname.exp" < "$nlist" > "$nlist"T'
+	      eval '$MV "$nlist"T "$nlist"'
+	      case $host in
+	        *cygwin* | *mingw* | *cegcc* )
+	          eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
+	          eval 'cat "$nlist" >> "$output_objdir/$outputname.def"'
+	          ;;
+	      esac
+	    }
+	  fi
+	fi
+
+	for dlprefile in $dlprefiles; do
+	  func_verbose "extracting global C symbols from \`$dlprefile'"
+	  func_basename "$dlprefile"
+	  name="$func_basename_result"
+          case $host in
+	    *cygwin* | *mingw* | *cegcc* )
+	      # if an import library, we need to obtain dlname
+	      if func_win32_import_lib_p "$dlprefile"; then
+	        func_tr_sh "$dlprefile"
+	        eval "curr_lafile=\$libfile_$func_tr_sh_result"
+	        dlprefile_dlbasename=""
+	        if test -n "$curr_lafile" && func_lalib_p "$curr_lafile"; then
+	          # Use subshell, to avoid clobbering current variable values
+	          dlprefile_dlname=`source "$curr_lafile" && echo "$dlname"`
+	          if test -n "$dlprefile_dlname" ; then
+	            func_basename "$dlprefile_dlname"
+	            dlprefile_dlbasename="$func_basename_result"
+	          else
+	            # no lafile. user explicitly requested -dlpreopen <import library>.
+	            $sharedlib_from_linklib_cmd "$dlprefile"
+	            dlprefile_dlbasename=$sharedlib_from_linklib_result
+	          fi
+	        fi
+	        $opt_dry_run || {
+	          if test -n "$dlprefile_dlbasename" ; then
+	            eval '$ECHO ": $dlprefile_dlbasename" >> "$nlist"'
+	          else
+	            func_warning "Could not compute DLL name from $name"
+	            eval '$ECHO ": $name " >> "$nlist"'
+	          fi
+	          func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
+	          eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe |
+	            $SED -e '/I __imp/d' -e 's/I __nm_/D /;s/_nm__//' >> '$nlist'"
+	        }
+	      else # not an import lib
+	        $opt_dry_run || {
+	          eval '$ECHO ": $name " >> "$nlist"'
+	          func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
+	          eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'"
+	        }
+	      fi
+	    ;;
+	    *)
+	      $opt_dry_run || {
+	        eval '$ECHO ": $name " >> "$nlist"'
+	        func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
+	        eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'"
+	      }
+	    ;;
+          esac
+	done
+
+	$opt_dry_run || {
+	  # Make sure we have at least an empty file.
+	  test -f "$nlist" || : > "$nlist"
+
+	  if test -n "$exclude_expsyms"; then
+	    $EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T
+	    $MV "$nlist"T "$nlist"
+	  fi
+
+	  # Try sorting and uniquifying the output.
+	  if $GREP -v "^: " < "$nlist" |
+	      if sort -k 3 </dev/null >/dev/null 2>&1; then
+		sort -k 3
+	      else
+		sort +2
+	      fi |
+	      uniq > "$nlist"S; then
+	    :
+	  else
+	    $GREP -v "^: " < "$nlist" > "$nlist"S
+	  fi
+
+	  if test -f "$nlist"S; then
+	    eval "$global_symbol_to_cdecl"' < "$nlist"S >> "$output_objdir/$my_dlsyms"'
+	  else
+	    echo '/* NONE */' >> "$output_objdir/$my_dlsyms"
+	  fi
+
+	  echo >> "$output_objdir/$my_dlsyms" "\
+
+/* The mapping between symbol names and symbols.  */
+typedef struct {
+  const char *name;
+  void *address;
+} lt_dlsymlist;
+extern LT_DLSYM_CONST lt_dlsymlist
+lt_${my_prefix}_LTX_preloaded_symbols[];
+LT_DLSYM_CONST lt_dlsymlist
+lt_${my_prefix}_LTX_preloaded_symbols[] =
+{\
+  { \"$my_originator\", (void *) 0 },"
+
+	  case $need_lib_prefix in
+	  no)
+	    eval "$global_symbol_to_c_name_address" < "$nlist" >> "$output_objdir/$my_dlsyms"
+	    ;;
+	  *)
+	    eval "$global_symbol_to_c_name_address_lib_prefix" < "$nlist" >> "$output_objdir/$my_dlsyms"
+	    ;;
+	  esac
+	  echo >> "$output_objdir/$my_dlsyms" "\
+  {0, (void *) 0}
+};
+
+/* This works around a problem in FreeBSD linker */
+#ifdef FREEBSD_WORKAROUND
+static const void *lt_preloaded_setup() {
+  return lt_${my_prefix}_LTX_preloaded_symbols;
+}
+#endif
+
+#ifdef __cplusplus
+}
+#endif\
+"
+	} # !$opt_dry_run
+
+	pic_flag_for_symtable=
+	case "$compile_command " in
+	*" -static "*) ;;
+	*)
+	  case $host in
+	  # compiling the symbol table file with pic_flag works around
+	  # a FreeBSD bug that causes programs to crash when -lm is
+	  # linked before any other PIC object.  But we must not use
+	  # pic_flag when linking with -static.  The problem exists in
+	  # FreeBSD 2.2.6 and is fixed in FreeBSD 3.1.
+	  *-*-freebsd2.*|*-*-freebsd3.0*|*-*-freebsdelf3.0*)
+	    pic_flag_for_symtable=" $pic_flag -DFREEBSD_WORKAROUND" ;;
+	  *-*-hpux*)
+	    pic_flag_for_symtable=" $pic_flag"  ;;
+	  *)
+	    if test "X$my_pic_p" != Xno; then
+	      pic_flag_for_symtable=" $pic_flag"
+	    fi
+	    ;;
+	  esac
+	  ;;
+	esac
+	symtab_cflags=
+	for arg in $LTCFLAGS; do
+	  case $arg in
+	  -pie | -fpie | -fPIE) ;;
+	  *) func_append symtab_cflags " $arg" ;;
+	  esac
+	done
+
+	# Now compile the dynamic symbol file.
+	func_show_eval '(cd $output_objdir && $LTCC$symtab_cflags -c$no_builtin_flag$pic_flag_for_symtable "$my_dlsyms")' 'exit $?'
+
+	# Clean up the generated files.
+	func_show_eval '$RM "$output_objdir/$my_dlsyms" "$nlist" "${nlist}S" "${nlist}T"'
+
+	# Transform the symbol file into the correct name.
+	symfileobj="$output_objdir/${my_outputname}S.$objext"
+	case $host in
+	*cygwin* | *mingw* | *cegcc* )
+	  if test -f "$output_objdir/$my_outputname.def"; then
+	    compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
+	    finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
+	  else
+	    compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"`
+	    finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"`
+	  fi
+	  ;;
+	*)
+	  compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"`
+	  finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"`
+	  ;;
+	esac
+	;;
+      *)
+	func_fatal_error "unknown suffix for \`$my_dlsyms'"
+	;;
+      esac
+    else
+      # We keep going just in case the user didn't refer to
+      # lt_preloaded_symbols.  The linker will fail if global_symbol_pipe
+      # really was required.
+
+      # Nullify the symbol file.
+      compile_command=`$ECHO "$compile_command" | $SED "s% @SYMFILE@%%"`
+      finalize_command=`$ECHO "$finalize_command" | $SED "s% @SYMFILE@%%"`
+    fi
+}
+
+# func_win32_libid arg
+# return the library type of file 'arg'
+#
+# Need a lot of goo to handle *both* DLLs and import libs
+# Has to be a shell function in order to 'eat' the argument
+# that is supplied when $file_magic_command is called.
+# Despite the name, also deal with 64 bit binaries.
+func_win32_libid ()
+{
+  $opt_debug
+  win32_libid_type="unknown"
+  win32_fileres=`file -L $1 2>/dev/null`
+  case $win32_fileres in
+  *ar\ archive\ import\ library*) # definitely import
+    win32_libid_type="x86 archive import"
+    ;;
+  *ar\ archive*) # could be an import, or static
+    # Keep the egrep pattern in sync with the one in _LT_CHECK_MAGIC_METHOD.
+    if eval $OBJDUMP -f $1 | $SED -e '10q' 2>/dev/null |
+       $EGREP 'file format (pei*-i386(.*architecture: i386)?|pe-arm-wince|pe-x86-64)' >/dev/null; then
+      func_to_tool_file "$1" func_convert_file_msys_to_w32
+      win32_nmres=`eval $NM -f posix -A \"$func_to_tool_file_result\" |
+	$SED -n -e '
+	    1,100{
+		/ I /{
+		    s,.*,import,
+		    p
+		    q
+		}
+	    }'`
+      case $win32_nmres in
+      import*)  win32_libid_type="x86 archive import";;
+      *)        win32_libid_type="x86 archive static";;
+      esac
+    fi
+    ;;
+  *DLL*)
+    win32_libid_type="x86 DLL"
+    ;;
+  *executable*) # but shell scripts are "executable" too...
+    case $win32_fileres in
+    *MS\ Windows\ PE\ Intel*)
+      win32_libid_type="x86 DLL"
+      ;;
+    esac
+    ;;
+  esac
+  $ECHO "$win32_libid_type"
+}
+
+# func_cygming_dll_for_implib ARG
+#
+# Platform-specific function to extract the
+# name of the DLL associated with the specified
+# import library ARG.
+# Invoked by eval'ing the libtool variable
+#    $sharedlib_from_linklib_cmd
+# Result is available in the variable
+#    $sharedlib_from_linklib_result
+func_cygming_dll_for_implib ()
+{
+  $opt_debug
+  sharedlib_from_linklib_result=`$DLLTOOL --identify-strict --identify "$1"`
+}
+
+# func_cygming_dll_for_implib_fallback_core SECTION_NAME LIBNAMEs
+#
+# The is the core of a fallback implementation of a
+# platform-specific function to extract the name of the
+# DLL associated with the specified import library LIBNAME.
+#
+# SECTION_NAME is either .idata$6 or .idata$7, depending
+# on the platform and compiler that created the implib.
+#
+# Echos the name of the DLL associated with the
+# specified import library.
+func_cygming_dll_for_implib_fallback_core ()
+{
+  $opt_debug
+  match_literal=`$ECHO "$1" | $SED "$sed_make_literal_regex"`
+  $OBJDUMP -s --section "$1" "$2" 2>/dev/null |
+    $SED '/^Contents of section '"$match_literal"':/{
+      # Place marker at beginning of archive member dllname section
+      s/.*/====MARK====/
+      p
+      d
+    }
+    # These lines can sometimes be longer than 43 characters, but
+    # are always uninteresting
+    /:[	 ]*file format pe[i]\{,1\}-/d
+    /^In archive [^:]*:/d
+    # Ensure marker is printed
+    /^====MARK====/p
+    # Remove all lines with less than 43 characters
+    /^.\{43\}/!d
+    # From remaining lines, remove first 43 characters
+    s/^.\{43\}//' |
+    $SED -n '
+      # Join marker and all lines until next marker into a single line
+      /^====MARK====/ b para
+      H
+      $ b para
+      b
+      :para
+      x
+      s/\n//g
+      # Remove the marker
+      s/^====MARK====//
+      # Remove trailing dots and whitespace
+      s/[\. \t]*$//
+      # Print
+      /./p' |
+    # we now have a list, one entry per line, of the stringified
+    # contents of the appropriate section of all members of the
+    # archive which possess that section. Heuristic: eliminate
+    # all those which have a first or second character that is
+    # a '.' (that is, objdump's representation of an unprintable
+    # character.) This should work for all archives with less than
+    # 0x302f exports -- but will fail for DLLs whose name actually
+    # begins with a literal '.' or a single character followed by
+    # a '.'.
+    #
+    # Of those that remain, print the first one.
+    $SED -e '/^\./d;/^.\./d;q'
+}
+
+# func_cygming_gnu_implib_p ARG
+# This predicate returns with zero status (TRUE) if
+# ARG is a GNU/binutils-style import library. Returns
+# with nonzero status (FALSE) otherwise.
+func_cygming_gnu_implib_p ()
+{
+  $opt_debug
+  func_to_tool_file "$1" func_convert_file_msys_to_w32
+  func_cygming_gnu_implib_tmp=`$NM "$func_to_tool_file_result" | eval "$global_symbol_pipe" | $EGREP ' (_head_[A-Za-z0-9_]+_[ad]l*|[A-Za-z0-9_]+_[ad]l*_iname)$'`
+  test -n "$func_cygming_gnu_implib_tmp"
+}
+
+# func_cygming_ms_implib_p ARG
+# This predicate returns with zero status (TRUE) if
+# ARG is an MS-style import library. Returns
+# with nonzero status (FALSE) otherwise.
+func_cygming_ms_implib_p ()
+{
+  $opt_debug
+  func_to_tool_file "$1" func_convert_file_msys_to_w32
+  func_cygming_ms_implib_tmp=`$NM "$func_to_tool_file_result" | eval "$global_symbol_pipe" | $GREP '_NULL_IMPORT_DESCRIPTOR'`
+  test -n "$func_cygming_ms_implib_tmp"
+}
+
+# func_cygming_dll_for_implib_fallback ARG
+# Platform-specific function to extract the
+# name of the DLL associated with the specified
+# import library ARG.
+#
+# This fallback implementation is for use when $DLLTOOL
+# does not support the --identify-strict option.
+# Invoked by eval'ing the libtool variable
+#    $sharedlib_from_linklib_cmd
+# Result is available in the variable
+#    $sharedlib_from_linklib_result
+func_cygming_dll_for_implib_fallback ()
+{
+  $opt_debug
+  if func_cygming_gnu_implib_p "$1" ; then
+    # binutils import library
+    sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$7' "$1"`
+  elif func_cygming_ms_implib_p "$1" ; then
+    # ms-generated import library
+    sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$6' "$1"`
+  else
+    # unknown
+    sharedlib_from_linklib_result=""
+  fi
+}
+
+
+# func_extract_an_archive dir oldlib
+func_extract_an_archive ()
+{
+    $opt_debug
+    f_ex_an_ar_dir="$1"; shift
+    f_ex_an_ar_oldlib="$1"
+    if test "$lock_old_archive_extraction" = yes; then
+      lockfile=$f_ex_an_ar_oldlib.lock
+      until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do
+	func_echo "Waiting for $lockfile to be removed"
+	sleep 2
+      done
+    fi
+    func_show_eval "(cd \$f_ex_an_ar_dir && $AR x \"\$f_ex_an_ar_oldlib\")" \
+		   'stat=$?; rm -f "$lockfile"; exit $stat'
+    if test "$lock_old_archive_extraction" = yes; then
+      $opt_dry_run || rm -f "$lockfile"
+    fi
+    if ($AR t "$f_ex_an_ar_oldlib" | sort | sort -uc >/dev/null 2>&1); then
+     :
+    else
+      func_fatal_error "object name conflicts in archive: $f_ex_an_ar_dir/$f_ex_an_ar_oldlib"
+    fi
+}
+
+
+# func_extract_archives gentop oldlib ...
+func_extract_archives ()
+{
+    $opt_debug
+    my_gentop="$1"; shift
+    my_oldlibs=${1+"$@"}
+    my_oldobjs=""
+    my_xlib=""
+    my_xabs=""
+    my_xdir=""
+
+    for my_xlib in $my_oldlibs; do
+      # Extract the objects.
+      case $my_xlib in
+	[\\/]* | [A-Za-z]:[\\/]*) my_xabs="$my_xlib" ;;
+	*) my_xabs=`pwd`"/$my_xlib" ;;
+      esac
+      func_basename "$my_xlib"
+      my_xlib="$func_basename_result"
+      my_xlib_u=$my_xlib
+      while :; do
+        case " $extracted_archives " in
+	*" $my_xlib_u "*)
+	  func_arith $extracted_serial + 1
+	  extracted_serial=$func_arith_result
+	  my_xlib_u=lt$extracted_serial-$my_xlib ;;
+	*) break ;;
+	esac
+      done
+      extracted_archives="$extracted_archives $my_xlib_u"
+      my_xdir="$my_gentop/$my_xlib_u"
+
+      func_mkdir_p "$my_xdir"
+
+      case $host in
+      *-darwin*)
+	func_verbose "Extracting $my_xabs"
+	# Do not bother doing anything if just a dry run
+	$opt_dry_run || {
+	  darwin_orig_dir=`pwd`
+	  cd $my_xdir || exit $?
+	  darwin_archive=$my_xabs
+	  darwin_curdir=`pwd`
+	  darwin_base_archive=`basename "$darwin_archive"`
+	  darwin_arches=`$LIPO -info "$darwin_archive" 2>/dev/null | $GREP Architectures 2>/dev/null || true`
+	  if test -n "$darwin_arches"; then
+	    darwin_arches=`$ECHO "$darwin_arches" | $SED -e 's/.*are://'`
+	    darwin_arch=
+	    func_verbose "$darwin_base_archive has multiple architectures $darwin_arches"
+	    for darwin_arch in  $darwin_arches ; do
+	      func_mkdir_p "unfat-$$/${darwin_base_archive}-${darwin_arch}"
+	      $LIPO -thin $darwin_arch -output "unfat-$$/${darwin_base_archive}-${darwin_arch}/${darwin_base_archive}" "${darwin_archive}"
+	      cd "unfat-$$/${darwin_base_archive}-${darwin_arch}"
+	      func_extract_an_archive "`pwd`" "${darwin_base_archive}"
+	      cd "$darwin_curdir"
+	      $RM "unfat-$$/${darwin_base_archive}-${darwin_arch}/${darwin_base_archive}"
+	    done # $darwin_arches
+            ## Okay now we've a bunch of thin objects, gotta fatten them up :)
+	    darwin_filelist=`find unfat-$$ -type f -name \*.o -print -o -name \*.lo -print | $SED -e "$basename" | sort -u`
+	    darwin_file=
+	    darwin_files=
+	    for darwin_file in $darwin_filelist; do
+	      darwin_files=`find unfat-$$ -name $darwin_file -print | sort | $NL2SP`
+	      $LIPO -create -output "$darwin_file" $darwin_files
+	    done # $darwin_filelist
+	    $RM -rf unfat-$$
+	    cd "$darwin_orig_dir"
+	  else
+	    cd $darwin_orig_dir
+	    func_extract_an_archive "$my_xdir" "$my_xabs"
+	  fi # $darwin_arches
+	} # !$opt_dry_run
+	;;
+      *)
+        func_extract_an_archive "$my_xdir" "$my_xabs"
+	;;
+      esac
+      my_oldobjs="$my_oldobjs "`find $my_xdir -name \*.$objext -print -o -name \*.lo -print | sort | $NL2SP`
+    done
+
+    func_extract_archives_result="$my_oldobjs"
+}
+
+
+# func_emit_wrapper [arg=no]
+#
+# Emit a libtool wrapper script on stdout.
+# Don't directly open a file because we may want to
+# incorporate the script contents within a cygwin/mingw
+# wrapper executable.  Must ONLY be called from within
+# func_mode_link because it depends on a number of variables
+# set therein.
+#
+# ARG is the value that the WRAPPER_SCRIPT_BELONGS_IN_OBJDIR
+# variable will take.  If 'yes', then the emitted script
+# will assume that the directory in which it is stored is
+# the $objdir directory.  This is a cygwin/mingw-specific
+# behavior.
+func_emit_wrapper ()
+{
+	func_emit_wrapper_arg1=${1-no}
+
+	$ECHO "\
+#! $SHELL
+
+# $output - temporary wrapper script for $objdir/$outputname
+# Generated by $PROGRAM (GNU $PACKAGE$TIMESTAMP) $VERSION
+#
+# The $output program cannot be directly executed until all the libtool
+# libraries that it depends on are installed.
+#
+# This wrapper script should never be moved out of the build directory.
+# If it is, it will not operate correctly.
+
+# Sed substitution that helps us do robust quoting.  It backslashifies
+# metacharacters that are still active within double-quoted strings.
+sed_quote_subst='$sed_quote_subst'
+
+# Be Bourne compatible
+if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then
+  emulate sh
+  NULLCMD=:
+  # Zsh 3.x and 4.x performs word splitting on \${1+\"\$@\"}, which
+  # is contrary to our usage.  Disable this feature.
+  alias -g '\${1+\"\$@\"}'='\"\$@\"'
+  setopt NO_GLOB_SUBST
+else
+  case \`(set -o) 2>/dev/null\` in *posix*) set -o posix;; esac
+fi
+BIN_SH=xpg4; export BIN_SH # for Tru64
+DUALCASE=1; export DUALCASE # for MKS sh
+
+# The HP-UX ksh and POSIX shell print the target directory to stdout
+# if CDPATH is set.
+(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
+
+relink_command=\"$relink_command\"
+
+# This environment variable determines our operation mode.
+if test \"\$libtool_install_magic\" = \"$magic\"; then
+  # install mode needs the following variables:
+  generated_by_libtool_version='$macro_version'
+  notinst_deplibs='$notinst_deplibs'
+else
+  # When we are sourced in execute mode, \$file and \$ECHO are already set.
+  if test \"\$libtool_execute_magic\" != \"$magic\"; then
+    file=\"\$0\""
+
+    qECHO=`$ECHO "$ECHO" | $SED "$sed_quote_subst"`
+    $ECHO "\
+
+# A function that is used when there is no print builtin or printf.
+func_fallback_echo ()
+{
+  eval 'cat <<_LTECHO_EOF
+\$1
+_LTECHO_EOF'
+}
+    ECHO=\"$qECHO\"
+  fi
+
+# Very basic option parsing. These options are (a) specific to
+# the libtool wrapper, (b) are identical between the wrapper
+# /script/ and the wrapper /executable/ which is used only on
+# windows platforms, and (c) all begin with the string "--lt-"
+# (application programs are unlikely to have options which match
+# this pattern).
+#
+# There are only two supported options: --lt-debug and
+# --lt-dump-script. There is, deliberately, no --lt-help.
+#
+# The first argument to this parsing function should be the
+# script's $0 value, followed by "$@".
+lt_option_debug=
+func_parse_lt_options ()
+{
+  lt_script_arg0=\$0
+  shift
+  for lt_opt
+  do
+    case \"\$lt_opt\" in
+    --lt-debug) lt_option_debug=1 ;;
+    --lt-dump-script)
+        lt_dump_D=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%/[^/]*$%%'\`
+        test \"X\$lt_dump_D\" = \"X\$lt_script_arg0\" && lt_dump_D=.
+        lt_dump_F=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%^.*/%%'\`
+        cat \"\$lt_dump_D/\$lt_dump_F\"
+        exit 0
+      ;;
+    --lt-*)
+        \$ECHO \"Unrecognized --lt- option: '\$lt_opt'\" 1>&2
+        exit 1
+      ;;
+    esac
+  done
+
+  # Print the debug banner immediately:
+  if test -n \"\$lt_option_debug\"; then
+    echo \"${outputname}:${output}:\${LINENO}: libtool wrapper (GNU $PACKAGE$TIMESTAMP) $VERSION\" 1>&2
+  fi
+}
+
+# Used when --lt-debug. Prints its arguments to stdout
+# (redirection is the responsibility of the caller)
+func_lt_dump_args ()
+{
+  lt_dump_args_N=1;
+  for lt_arg
+  do
+    \$ECHO \"${outputname}:${output}:\${LINENO}: newargv[\$lt_dump_args_N]: \$lt_arg\"
+    lt_dump_args_N=\`expr \$lt_dump_args_N + 1\`
+  done
+}
+
+# Core function for launching the target application
+func_exec_program_core ()
+{
+"
+  case $host in
+  # Backslashes separate directories on plain windows
+  *-*-mingw | *-*-os2* | *-cegcc*)
+    $ECHO "\
+      if test -n \"\$lt_option_debug\"; then
+        \$ECHO \"${outputname}:${output}:\${LINENO}: newargv[0]: \$progdir\\\\\$program\" 1>&2
+        func_lt_dump_args \${1+\"\$@\"} 1>&2
+      fi
+      exec \"\$progdir\\\\\$program\" \${1+\"\$@\"}
+"
+    ;;
+
+  *)
+    $ECHO "\
+      if test -n \"\$lt_option_debug\"; then
+        \$ECHO \"${outputname}:${output}:\${LINENO}: newargv[0]: \$progdir/\$program\" 1>&2
+        func_lt_dump_args \${1+\"\$@\"} 1>&2
+      fi
+      exec \"\$progdir/\$program\" \${1+\"\$@\"}
+"
+    ;;
+  esac
+  $ECHO "\
+      \$ECHO \"\$0: cannot exec \$program \$*\" 1>&2
+      exit 1
+}
+
+# A function to encapsulate launching the target application
+# Strips options in the --lt-* namespace from \$@ and
+# launches target application with the remaining arguments.
+func_exec_program ()
+{
+  case \" \$* \" in
+  *\\ --lt-*)
+    for lt_wr_arg
+    do
+      case \$lt_wr_arg in
+      --lt-*) ;;
+      *) set x \"\$@\" \"\$lt_wr_arg\"; shift;;
+      esac
+      shift
+    done ;;
+  esac
+  func_exec_program_core \${1+\"\$@\"}
+}
+
+  # Parse options
+  func_parse_lt_options \"\$0\" \${1+\"\$@\"}
+
+  # Find the directory that this script lives in.
+  thisdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*$%%'\`
+  test \"x\$thisdir\" = \"x\$file\" && thisdir=.
+
+  # Follow symbolic links until we get to the real thisdir.
+  file=\`ls -ld \"\$file\" | $SED -n 's/.*-> //p'\`
+  while test -n \"\$file\"; do
+    destdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*\$%%'\`
+
+    # If there was a directory component, then change thisdir.
+    if test \"x\$destdir\" != \"x\$file\"; then
+      case \"\$destdir\" in
+      [\\\\/]* | [A-Za-z]:[\\\\/]*) thisdir=\"\$destdir\" ;;
+      *) thisdir=\"\$thisdir/\$destdir\" ;;
+      esac
+    fi
+
+    file=\`\$ECHO \"\$file\" | $SED 's%^.*/%%'\`
+    file=\`ls -ld \"\$thisdir/\$file\" | $SED -n 's/.*-> //p'\`
+  done
+
+  # Usually 'no', except on cygwin/mingw when embedded into
+  # the cwrapper.
+  WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=$func_emit_wrapper_arg1
+  if test \"\$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR\" = \"yes\"; then
+    # special case for '.'
+    if test \"\$thisdir\" = \".\"; then
+      thisdir=\`pwd\`
+    fi
+    # remove .libs from thisdir
+    case \"\$thisdir\" in
+    *[\\\\/]$objdir ) thisdir=\`\$ECHO \"\$thisdir\" | $SED 's%[\\\\/][^\\\\/]*$%%'\` ;;
+    $objdir )   thisdir=. ;;
+    esac
+  fi
+
+  # Try to get the absolute directory name.
+  absdir=\`cd \"\$thisdir\" && pwd\`
+  test -n \"\$absdir\" && thisdir=\"\$absdir\"
+"
+
+	if test "$fast_install" = yes; then
+	  $ECHO "\
+  program=lt-'$outputname'$exeext
+  progdir=\"\$thisdir/$objdir\"
+
+  if test ! -f \"\$progdir/\$program\" ||
+     { file=\`ls -1dt \"\$progdir/\$program\" \"\$progdir/../\$program\" 2>/dev/null | ${SED} 1q\`; \\
+       test \"X\$file\" != \"X\$progdir/\$program\"; }; then
+
+    file=\"\$\$-\$program\"
+
+    if test ! -d \"\$progdir\"; then
+      $MKDIR \"\$progdir\"
+    else
+      $RM \"\$progdir/\$file\"
+    fi"
+
+	  $ECHO "\
+
+    # relink executable if necessary
+    if test -n \"\$relink_command\"; then
+      if relink_command_output=\`eval \$relink_command 2>&1\`; then :
+      else
+	$ECHO \"\$relink_command_output\" >&2
+	$RM \"\$progdir/\$file\"
+	exit 1
+      fi
+    fi
+
+    $MV \"\$progdir/\$file\" \"\$progdir/\$program\" 2>/dev/null ||
+    { $RM \"\$progdir/\$program\";
+      $MV \"\$progdir/\$file\" \"\$progdir/\$program\"; }
+    $RM \"\$progdir/\$file\"
+  fi"
+	else
+	  $ECHO "\
+  program='$outputname'
+  progdir=\"\$thisdir/$objdir\"
+"
+	fi
+
+	$ECHO "\
+
+  if test -f \"\$progdir/\$program\"; then"
+
+	# fixup the dll searchpath if we need to.
+	#
+	# Fix the DLL searchpath if we need to.  Do this before prepending
+	# to shlibpath, because on Windows, both are PATH and uninstalled
+	# libraries must come first.
+	if test -n "$dllsearchpath"; then
+	  $ECHO "\
+    # Add the dll search path components to the executable PATH
+    PATH=$dllsearchpath:\$PATH
+"
+	fi
+
+	# Export our shlibpath_var if we have one.
+	if test "$shlibpath_overrides_runpath" = yes && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
+	  $ECHO "\
+    # Add our own library path to $shlibpath_var
+    $shlibpath_var=\"$temp_rpath\$$shlibpath_var\"
+
+    # Some systems cannot cope with colon-terminated $shlibpath_var
+    # The second colon is a workaround for a bug in BeOS R4 sed
+    $shlibpath_var=\`\$ECHO \"\$$shlibpath_var\" | $SED 's/::*\$//'\`
+
+    export $shlibpath_var
+"
+	fi
+
+	$ECHO "\
+    if test \"\$libtool_execute_magic\" != \"$magic\"; then
+      # Run the actual program with our arguments.
+      func_exec_program \${1+\"\$@\"}
+    fi
+  else
+    # The program doesn't exist.
+    \$ECHO \"\$0: error: \\\`\$progdir/\$program' does not exist\" 1>&2
+    \$ECHO \"This script is just a wrapper for \$program.\" 1>&2
+    \$ECHO \"See the $PACKAGE documentation for more information.\" 1>&2
+    exit 1
+  fi
+fi\
+"
+}
+
+
+# func_emit_cwrapperexe_src
+# emit the source code for a wrapper executable on stdout
+# Must ONLY be called from within func_mode_link because
+# it depends on a number of variable set therein.
+func_emit_cwrapperexe_src ()
+{
+	cat <<EOF
+
+/* $cwrappersource - temporary wrapper executable for $objdir/$outputname
+   Generated by $PROGRAM (GNU $PACKAGE$TIMESTAMP) $VERSION
+
+   The $output program cannot be directly executed until all the libtool
+   libraries that it depends on are installed.
+
+   This wrapper executable should never be moved out of the build directory.
+   If it is, it will not operate correctly.
+*/
+EOF
+	    cat <<"EOF"
+#ifdef _MSC_VER
+# define _CRT_SECURE_NO_DEPRECATE 1
+#endif
+#include <stdio.h>
+#include <stdlib.h>
+#ifdef _MSC_VER
+# include <direct.h>
+# include <process.h>
+# include <io.h>
+#else
+# include <unistd.h>
+# include <stdint.h>
+# ifdef __CYGWIN__
+#  include <io.h>
+# endif
+#endif
+#include <malloc.h>
+#include <stdarg.h>
+#include <assert.h>
+#include <string.h>
+#include <ctype.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+
+/* declarations of non-ANSI functions */
+#if defined(__MINGW32__)
+# ifdef __STRICT_ANSI__
+int _putenv (const char *);
+# endif
+#elif defined(__CYGWIN__)
+# ifdef __STRICT_ANSI__
+char *realpath (const char *, char *);
+int putenv (char *);
+int setenv (const char *, const char *, int);
+# endif
+/* #elif defined (other platforms) ... */
+#endif
+
+/* portability defines, excluding path handling macros */
+#if defined(_MSC_VER)
+# define setmode _setmode
+# define stat    _stat
+# define chmod   _chmod
+# define getcwd  _getcwd
+# define putenv  _putenv
+# define S_IXUSR _S_IEXEC
+# ifndef _INTPTR_T_DEFINED
+#  define _INTPTR_T_DEFINED
+#  define intptr_t int
+# endif
+#elif defined(__MINGW32__)
+# define setmode _setmode
+# define stat    _stat
+# define chmod   _chmod
+# define getcwd  _getcwd
+# define putenv  _putenv
+#elif defined(__CYGWIN__)
+# define HAVE_SETENV
+# define FOPEN_WB "wb"
+/* #elif defined (other platforms) ... */
+#endif
+
+#if defined(PATH_MAX)
+# define LT_PATHMAX PATH_MAX
+#elif defined(MAXPATHLEN)
+# define LT_PATHMAX MAXPATHLEN
+#else
+# define LT_PATHMAX 1024
+#endif
+
+#ifndef S_IXOTH
+# define S_IXOTH 0
+#endif
+#ifndef S_IXGRP
+# define S_IXGRP 0
+#endif
+
+/* path handling portability macros */
+#ifndef DIR_SEPARATOR
+# define DIR_SEPARATOR '/'
+# define PATH_SEPARATOR ':'
+#endif
+
+#if defined (_WIN32) || defined (__MSDOS__) || defined (__DJGPP__) || \
+  defined (__OS2__)
+# define HAVE_DOS_BASED_FILE_SYSTEM
+# define FOPEN_WB "wb"
+# ifndef DIR_SEPARATOR_2
+#  define DIR_SEPARATOR_2 '\\'
+# endif
+# ifndef PATH_SEPARATOR_2
+#  define PATH_SEPARATOR_2 ';'
+# endif
+#endif
+
+#ifndef DIR_SEPARATOR_2
+# define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)
+#else /* DIR_SEPARATOR_2 */
+# define IS_DIR_SEPARATOR(ch) \
+	(((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))
+#endif /* DIR_SEPARATOR_2 */
+
+#ifndef PATH_SEPARATOR_2
+# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR)
+#else /* PATH_SEPARATOR_2 */
+# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR_2)
+#endif /* PATH_SEPARATOR_2 */
+
+#ifndef FOPEN_WB
+# define FOPEN_WB "w"
+#endif
+#ifndef _O_BINARY
+# define _O_BINARY 0
+#endif
+
+#define XMALLOC(type, num)      ((type *) xmalloc ((num) * sizeof(type)))
+#define XFREE(stale) do { \
+  if (stale) { free ((void *) stale); stale = 0; } \
+} while (0)
+
+#if defined(LT_DEBUGWRAPPER)
+static int lt_debug = 1;
+#else
+static int lt_debug = 0;
+#endif
+
+const char *program_name = "libtool-wrapper"; /* in case xstrdup fails */
+
+void *xmalloc (size_t num);
+char *xstrdup (const char *string);
+const char *base_name (const char *name);
+char *find_executable (const char *wrapper);
+char *chase_symlinks (const char *pathspec);
+int make_executable (const char *path);
+int check_executable (const char *path);
+char *strendzap (char *str, const char *pat);
+void lt_debugprintf (const char *file, int line, const char *fmt, ...);
+void lt_fatal (const char *file, int line, const char *message, ...);
+static const char *nonnull (const char *s);
+static const char *nonempty (const char *s);
+void lt_setenv (const char *name, const char *value);
+char *lt_extend_str (const char *orig_value, const char *add, int to_end);
+void lt_update_exe_path (const char *name, const char *value);
+void lt_update_lib_path (const char *name, const char *value);
+char **prepare_spawn (char **argv);
+void lt_dump_script (FILE *f);
+EOF
+
+	    cat <<EOF
+volatile const char * MAGIC_EXE = "$magic_exe";
+const char * LIB_PATH_VARNAME = "$shlibpath_var";
+EOF
+
+	    if test "$shlibpath_overrides_runpath" = yes && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
+              func_to_host_path "$temp_rpath"
+	      cat <<EOF
+const char * LIB_PATH_VALUE   = "$func_to_host_path_result";
+EOF
+	    else
+	      cat <<"EOF"
+const char * LIB_PATH_VALUE   = "";
+EOF
+	    fi
+
+	    if test -n "$dllsearchpath"; then
+              func_to_host_path "$dllsearchpath:"
+	      cat <<EOF
+const char * EXE_PATH_VARNAME = "PATH";
+const char * EXE_PATH_VALUE   = "$func_to_host_path_result";
+EOF
+	    else
+	      cat <<"EOF"
+const char * EXE_PATH_VARNAME = "";
+const char * EXE_PATH_VALUE   = "";
+EOF
+	    fi
+
+	    if test "$fast_install" = yes; then
+	      cat <<EOF
+const char * TARGET_PROGRAM_NAME = "lt-$outputname"; /* hopefully, no .exe */
+EOF
+	    else
+	      cat <<EOF
+const char * TARGET_PROGRAM_NAME = "$outputname"; /* hopefully, no .exe */
+EOF
+	    fi
+
+
+	    cat <<"EOF"
+
+#define LTWRAPPER_OPTION_PREFIX         "--lt-"
+
+static const char *ltwrapper_option_prefix = LTWRAPPER_OPTION_PREFIX;
+static const char *dumpscript_opt       = LTWRAPPER_OPTION_PREFIX "dump-script";
+static const char *debug_opt            = LTWRAPPER_OPTION_PREFIX "debug";
+
+int
+main (int argc, char *argv[])
+{
+  char **newargz;
+  int  newargc;
+  char *tmp_pathspec;
+  char *actual_cwrapper_path;
+  char *actual_cwrapper_name;
+  char *target_name;
+  char *lt_argv_zero;
+  intptr_t rval = 127;
+
+  int i;
+
+  program_name = (char *) xstrdup (base_name (argv[0]));
+  newargz = XMALLOC (char *, argc + 1);
+
+  /* very simple arg parsing; don't want to rely on getopt
+   * also, copy all non cwrapper options to newargz, except
+   * argz[0], which is handled differently
+   */
+  newargc=0;
+  for (i = 1; i < argc; i++)
+    {
+      if (strcmp (argv[i], dumpscript_opt) == 0)
+	{
+EOF
+	    case "$host" in
+	      *mingw* | *cygwin* )
+		# make stdout use "unix" line endings
+		echo "          setmode(1,_O_BINARY);"
+		;;
+	      esac
+
+	    cat <<"EOF"
+	  lt_dump_script (stdout);
+	  return 0;
+	}
+      if (strcmp (argv[i], debug_opt) == 0)
+	{
+          lt_debug = 1;
+          continue;
+	}
+      if (strcmp (argv[i], ltwrapper_option_prefix) == 0)
+        {
+          /* however, if there is an option in the LTWRAPPER_OPTION_PREFIX
+             namespace, but it is not one of the ones we know about and
+             have already dealt with, above (inluding dump-script), then
+             report an error. Otherwise, targets might begin to believe
+             they are allowed to use options in the LTWRAPPER_OPTION_PREFIX
+             namespace. The first time any user complains about this, we'll
+             need to make LTWRAPPER_OPTION_PREFIX a configure-time option
+             or a configure.ac-settable value.
+           */
+          lt_fatal (__FILE__, __LINE__,
+		    "unrecognized %s option: '%s'",
+                    ltwrapper_option_prefix, argv[i]);
+        }
+      /* otherwise ... */
+      newargz[++newargc] = xstrdup (argv[i]);
+    }
+  newargz[++newargc] = NULL;
+
+EOF
+	    cat <<EOF
+  /* The GNU banner must be the first non-error debug message */
+  lt_debugprintf (__FILE__, __LINE__, "libtool wrapper (GNU $PACKAGE$TIMESTAMP) $VERSION\n");
+EOF
+	    cat <<"EOF"
+  lt_debugprintf (__FILE__, __LINE__, "(main) argv[0]: %s\n", argv[0]);
+  lt_debugprintf (__FILE__, __LINE__, "(main) program_name: %s\n", program_name);
+
+  tmp_pathspec = find_executable (argv[0]);
+  if (tmp_pathspec == NULL)
+    lt_fatal (__FILE__, __LINE__, "couldn't find %s", argv[0]);
+  lt_debugprintf (__FILE__, __LINE__,
+                  "(main) found exe (before symlink chase) at: %s\n",
+		  tmp_pathspec);
+
+  actual_cwrapper_path = chase_symlinks (tmp_pathspec);
+  lt_debugprintf (__FILE__, __LINE__,
+                  "(main) found exe (after symlink chase) at: %s\n",
+		  actual_cwrapper_path);
+  XFREE (tmp_pathspec);
+
+  actual_cwrapper_name = xstrdup (base_name (actual_cwrapper_path));
+  strendzap (actual_cwrapper_path, actual_cwrapper_name);
+
+  /* wrapper name transforms */
+  strendzap (actual_cwrapper_name, ".exe");
+  tmp_pathspec = lt_extend_str (actual_cwrapper_name, ".exe", 1);
+  XFREE (actual_cwrapper_name);
+  actual_cwrapper_name = tmp_pathspec;
+  tmp_pathspec = 0;
+
+  /* target_name transforms -- use actual target program name; might have lt- prefix */
+  target_name = xstrdup (base_name (TARGET_PROGRAM_NAME));
+  strendzap (target_name, ".exe");
+  tmp_pathspec = lt_extend_str (target_name, ".exe", 1);
+  XFREE (target_name);
+  target_name = tmp_pathspec;
+  tmp_pathspec = 0;
+
+  lt_debugprintf (__FILE__, __LINE__,
+		  "(main) libtool target name: %s\n",
+		  target_name);
+EOF
+
+	    cat <<EOF
+  newargz[0] =
+    XMALLOC (char, (strlen (actual_cwrapper_path) +
+		    strlen ("$objdir") + 1 + strlen (actual_cwrapper_name) + 1));
+  strcpy (newargz[0], actual_cwrapper_path);
+  strcat (newargz[0], "$objdir");
+  strcat (newargz[0], "/");
+EOF
+
+	    cat <<"EOF"
+  /* stop here, and copy so we don't have to do this twice */
+  tmp_pathspec = xstrdup (newargz[0]);
+
+  /* do NOT want the lt- prefix here, so use actual_cwrapper_name */
+  strcat (newargz[0], actual_cwrapper_name);
+
+  /* DO want the lt- prefix here if it exists, so use target_name */
+  lt_argv_zero = lt_extend_str (tmp_pathspec, target_name, 1);
+  XFREE (tmp_pathspec);
+  tmp_pathspec = NULL;
+EOF
+
+	    case $host_os in
+	      mingw*)
+	    cat <<"EOF"
+  {
+    char* p;
+    while ((p = strchr (newargz[0], '\\')) != NULL)
+      {
+	*p = '/';
+      }
+    while ((p = strchr (lt_argv_zero, '\\')) != NULL)
+      {
+	*p = '/';
+      }
+  }
+EOF
+	    ;;
+	    esac
+
+	    cat <<"EOF"
+  XFREE (target_name);
+  XFREE (actual_cwrapper_path);
+  XFREE (actual_cwrapper_name);
+
+  lt_setenv ("BIN_SH", "xpg4"); /* for Tru64 */
+  lt_setenv ("DUALCASE", "1");  /* for MSK sh */
+  /* Update the DLL searchpath.  EXE_PATH_VALUE ($dllsearchpath) must
+     be prepended before (that is, appear after) LIB_PATH_VALUE ($temp_rpath)
+     because on Windows, both *_VARNAMEs are PATH but uninstalled
+     libraries must come first. */
+  lt_update_exe_path (EXE_PATH_VARNAME, EXE_PATH_VALUE);
+  lt_update_lib_path (LIB_PATH_VARNAME, LIB_PATH_VALUE);
+
+  lt_debugprintf (__FILE__, __LINE__, "(main) lt_argv_zero: %s\n",
+		  nonnull (lt_argv_zero));
+  for (i = 0; i < newargc; i++)
+    {
+      lt_debugprintf (__FILE__, __LINE__, "(main) newargz[%d]: %s\n",
+		      i, nonnull (newargz[i]));
+    }
+
+EOF
+
+	    case $host_os in
+	      mingw*)
+		cat <<"EOF"
+  /* execv doesn't actually work on mingw as expected on unix */
+  newargz = prepare_spawn (newargz);
+  rval = _spawnv (_P_WAIT, lt_argv_zero, (const char * const *) newargz);
+  if (rval == -1)
+    {
+      /* failed to start process */
+      lt_debugprintf (__FILE__, __LINE__,
+		      "(main) failed to launch target \"%s\": %s\n",
+		      lt_argv_zero, nonnull (strerror (errno)));
+      return 127;
+    }
+  return rval;
+EOF
+		;;
+	      *)
+		cat <<"EOF"
+  execv (lt_argv_zero, newargz);
+  return rval; /* =127, but avoids unused variable warning */
+EOF
+		;;
+	    esac
+
+	    cat <<"EOF"
+}
+
+void *
+xmalloc (size_t num)
+{
+  void *p = (void *) malloc (num);
+  if (!p)
+    lt_fatal (__FILE__, __LINE__, "memory exhausted");
+
+  return p;
+}
+
+char *
+xstrdup (const char *string)
+{
+  return string ? strcpy ((char *) xmalloc (strlen (string) + 1),
+			  string) : NULL;
+}
+
+const char *
+base_name (const char *name)
+{
+  const char *base;
+
+#if defined (HAVE_DOS_BASED_FILE_SYSTEM)
+  /* Skip over the disk name in MSDOS pathnames. */
+  if (isalpha ((unsigned char) name[0]) && name[1] == ':')
+    name += 2;
+#endif
+
+  for (base = name; *name; name++)
+    if (IS_DIR_SEPARATOR (*name))
+      base = name + 1;
+  return base;
+}
+
+int
+check_executable (const char *path)
+{
+  struct stat st;
+
+  lt_debugprintf (__FILE__, __LINE__, "(check_executable): %s\n",
+                  nonempty (path));
+  if ((!path) || (!*path))
+    return 0;
+
+  if ((stat (path, &st) >= 0)
+      && (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)))
+    return 1;
+  else
+    return 0;
+}
+
+int
+make_executable (const char *path)
+{
+  int rval = 0;
+  struct stat st;
+
+  lt_debugprintf (__FILE__, __LINE__, "(make_executable): %s\n",
+                  nonempty (path));
+  if ((!path) || (!*path))
+    return 0;
+
+  if (stat (path, &st) >= 0)
+    {
+      rval = chmod (path, st.st_mode | S_IXOTH | S_IXGRP | S_IXUSR);
+    }
+  return rval;
+}
+
+/* Searches for the full path of the wrapper.  Returns
+   newly allocated full path name if found, NULL otherwise
+   Does not chase symlinks, even on platforms that support them.
+*/
+char *
+find_executable (const char *wrapper)
+{
+  int has_slash = 0;
+  const char *p;
+  const char *p_next;
+  /* static buffer for getcwd */
+  char tmp[LT_PATHMAX + 1];
+  int tmp_len;
+  char *concat_name;
+
+  lt_debugprintf (__FILE__, __LINE__, "(find_executable): %s\n",
+                  nonempty (wrapper));
+
+  if ((wrapper == NULL) || (*wrapper == '\0'))
+    return NULL;
+
+  /* Absolute path? */
+#if defined (HAVE_DOS_BASED_FILE_SYSTEM)
+  if (isalpha ((unsigned char) wrapper[0]) && wrapper[1] == ':')
+    {
+      concat_name = xstrdup (wrapper);
+      if (check_executable (concat_name))
+	return concat_name;
+      XFREE (concat_name);
+    }
+  else
+    {
+#endif
+      if (IS_DIR_SEPARATOR (wrapper[0]))
+	{
+	  concat_name = xstrdup (wrapper);
+	  if (check_executable (concat_name))
+	    return concat_name;
+	  XFREE (concat_name);
+	}
+#if defined (HAVE_DOS_BASED_FILE_SYSTEM)
+    }
+#endif
+
+  for (p = wrapper; *p; p++)
+    if (*p == '/')
+      {
+	has_slash = 1;
+	break;
+      }
+  if (!has_slash)
+    {
+      /* no slashes; search PATH */
+      const char *path = getenv ("PATH");
+      if (path != NULL)
+	{
+	  for (p = path; *p; p = p_next)
+	    {
+	      const char *q;
+	      size_t p_len;
+	      for (q = p; *q; q++)
+		if (IS_PATH_SEPARATOR (*q))
+		  break;
+	      p_len = q - p;
+	      p_next = (*q == '\0' ? q : q + 1);
+	      if (p_len == 0)
+		{
+		  /* empty path: current directory */
+		  if (getcwd (tmp, LT_PATHMAX) == NULL)
+		    lt_fatal (__FILE__, __LINE__, "getcwd failed: %s",
+                              nonnull (strerror (errno)));
+		  tmp_len = strlen (tmp);
+		  concat_name =
+		    XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
+		  memcpy (concat_name, tmp, tmp_len);
+		  concat_name[tmp_len] = '/';
+		  strcpy (concat_name + tmp_len + 1, wrapper);
+		}
+	      else
+		{
+		  concat_name =
+		    XMALLOC (char, p_len + 1 + strlen (wrapper) + 1);
+		  memcpy (concat_name, p, p_len);
+		  concat_name[p_len] = '/';
+		  strcpy (concat_name + p_len + 1, wrapper);
+		}
+	      if (check_executable (concat_name))
+		return concat_name;
+	      XFREE (concat_name);
+	    }
+	}
+      /* not found in PATH; assume curdir */
+    }
+  /* Relative path | not found in path: prepend cwd */
+  if (getcwd (tmp, LT_PATHMAX) == NULL)
+    lt_fatal (__FILE__, __LINE__, "getcwd failed: %s",
+              nonnull (strerror (errno)));
+  tmp_len = strlen (tmp);
+  concat_name = XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
+  memcpy (concat_name, tmp, tmp_len);
+  concat_name[tmp_len] = '/';
+  strcpy (concat_name + tmp_len + 1, wrapper);
+
+  if (check_executable (concat_name))
+    return concat_name;
+  XFREE (concat_name);
+  return NULL;
+}
+
+char *
+chase_symlinks (const char *pathspec)
+{
+#ifndef S_ISLNK
+  return xstrdup (pathspec);
+#else
+  char buf[LT_PATHMAX];
+  struct stat s;
+  char *tmp_pathspec = xstrdup (pathspec);
+  char *p;
+  int has_symlinks = 0;
+  while (strlen (tmp_pathspec) && !has_symlinks)
+    {
+      lt_debugprintf (__FILE__, __LINE__,
+		      "checking path component for symlinks: %s\n",
+		      tmp_pathspec);
+      if (lstat (tmp_pathspec, &s) == 0)
+	{
+	  if (S_ISLNK (s.st_mode) != 0)
+	    {
+	      has_symlinks = 1;
+	      break;
+	    }
+
+	  /* search backwards for last DIR_SEPARATOR */
+	  p = tmp_pathspec + strlen (tmp_pathspec) - 1;
+	  while ((p > tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
+	    p--;
+	  if ((p == tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
+	    {
+	      /* no more DIR_SEPARATORS left */
+	      break;
+	    }
+	  *p = '\0';
+	}
+      else
+	{
+	  lt_fatal (__FILE__, __LINE__,
+		    "error accessing file \"%s\": %s",
+		    tmp_pathspec, nonnull (strerror (errno)));
+	}
+    }
+  XFREE (tmp_pathspec);
+
+  if (!has_symlinks)
+    {
+      return xstrdup (pathspec);
+    }
+
+  tmp_pathspec = realpath (pathspec, buf);
+  if (tmp_pathspec == 0)
+    {
+      lt_fatal (__FILE__, __LINE__,
+		"could not follow symlinks for %s", pathspec);
+    }
+  return xstrdup (tmp_pathspec);
+#endif
+}
+
+char *
+strendzap (char *str, const char *pat)
+{
+  size_t len, patlen;
+
+  assert (str != NULL);
+  assert (pat != NULL);
+
+  len = strlen (str);
+  patlen = strlen (pat);
+
+  if (patlen <= len)
+    {
+      str += len - patlen;
+      if (strcmp (str, pat) == 0)
+	*str = '\0';
+    }
+  return str;
+}
+
+void
+lt_debugprintf (const char *file, int line, const char *fmt, ...)
+{
+  va_list args;
+  if (lt_debug)
+    {
+      (void) fprintf (stderr, "%s:%s:%d: ", program_name, file, line);
+      va_start (args, fmt);
+      (void) vfprintf (stderr, fmt, args);
+      va_end (args);
+    }
+}
+
+static void
+lt_error_core (int exit_status, const char *file,
+	       int line, const char *mode,
+	       const char *message, va_list ap)
+{
+  fprintf (stderr, "%s:%s:%d: %s: ", program_name, file, line, mode);
+  vfprintf (stderr, message, ap);
+  fprintf (stderr, ".\n");
+
+  if (exit_status >= 0)
+    exit (exit_status);
+}
+
+void
+lt_fatal (const char *file, int line, const char *message, ...)
+{
+  va_list ap;
+  va_start (ap, message);
+  lt_error_core (EXIT_FAILURE, file, line, "FATAL", message, ap);
+  va_end (ap);
+}
+
+static const char *
+nonnull (const char *s)
+{
+  return s ? s : "(null)";
+}
+
+static const char *
+nonempty (const char *s)
+{
+  return (s && !*s) ? "(empty)" : nonnull (s);
+}
+
+void
+lt_setenv (const char *name, const char *value)
+{
+  lt_debugprintf (__FILE__, __LINE__,
+		  "(lt_setenv) setting '%s' to '%s'\n",
+                  nonnull (name), nonnull (value));
+  {
+#ifdef HAVE_SETENV
+    /* always make a copy, for consistency with !HAVE_SETENV */
+    char *str = xstrdup (value);
+    setenv (name, str, 1);
+#else
+    int len = strlen (name) + 1 + strlen (value) + 1;
+    char *str = XMALLOC (char, len);
+    sprintf (str, "%s=%s", name, value);
+    if (putenv (str) != EXIT_SUCCESS)
+      {
+        XFREE (str);
+      }
+#endif
+  }
+}
+
+char *
+lt_extend_str (const char *orig_value, const char *add, int to_end)
+{
+  char *new_value;
+  if (orig_value && *orig_value)
+    {
+      int orig_value_len = strlen (orig_value);
+      int add_len = strlen (add);
+      new_value = XMALLOC (char, add_len + orig_value_len + 1);
+      if (to_end)
+        {
+          strcpy (new_value, orig_value);
+          strcpy (new_value + orig_value_len, add);
+        }
+      else
+        {
+          strcpy (new_value, add);
+          strcpy (new_value + add_len, orig_value);
+        }
+    }
+  else
+    {
+      new_value = xstrdup (add);
+    }
+  return new_value;
+}
+
+void
+lt_update_exe_path (const char *name, const char *value)
+{
+  lt_debugprintf (__FILE__, __LINE__,
+		  "(lt_update_exe_path) modifying '%s' by prepending '%s'\n",
+                  nonnull (name), nonnull (value));
+
+  if (name && *name && value && *value)
+    {
+      char *new_value = lt_extend_str (getenv (name), value, 0);
+      /* some systems can't cope with a ':'-terminated path #' */
+      int len = strlen (new_value);
+      while (((len = strlen (new_value)) > 0) && IS_PATH_SEPARATOR (new_value[len-1]))
+        {
+          new_value[len-1] = '\0';
+        }
+      lt_setenv (name, new_value);
+      XFREE (new_value);
+    }
+}
+
+void
+lt_update_lib_path (const char *name, const char *value)
+{
+  lt_debugprintf (__FILE__, __LINE__,
+		  "(lt_update_lib_path) modifying '%s' by prepending '%s'\n",
+                  nonnull (name), nonnull (value));
+
+  if (name && *name && value && *value)
+    {
+      char *new_value = lt_extend_str (getenv (name), value, 0);
+      lt_setenv (name, new_value);
+      XFREE (new_value);
+    }
+}
+
+EOF
+	    case $host_os in
+	      mingw*)
+		cat <<"EOF"
+
+/* Prepares an argument vector before calling spawn().
+   Note that spawn() does not by itself call the command interpreter
+     (getenv ("COMSPEC") != NULL ? getenv ("COMSPEC") :
+      ({ OSVERSIONINFO v; v.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+         GetVersionEx(&v);
+         v.dwPlatformId == VER_PLATFORM_WIN32_NT;
+      }) ? "cmd.exe" : "command.com").
+   Instead it simply concatenates the arguments, separated by ' ', and calls
+   CreateProcess().  We must quote the arguments since Win32 CreateProcess()
+   interprets characters like ' ', '\t', '\\', '"' (but not '<' and '>') in a
+   special way:
+   - Space and tab are interpreted as delimiters. They are not treated as
+     delimiters if they are surrounded by double quotes: "...".
+   - Unescaped double quotes are removed from the input. Their only effect is
+     that within double quotes, space and tab are treated like normal
+     characters.
+   - Backslashes not followed by double quotes are not special.
+   - But 2*n+1 backslashes followed by a double quote become
+     n backslashes followed by a double quote (n >= 0):
+       \" -> "
+       \\\" -> \"
+       \\\\\" -> \\"
+ */
+#define SHELL_SPECIAL_CHARS "\"\\ \001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037"
+#define SHELL_SPACE_CHARS " \001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037"
+char **
+prepare_spawn (char **argv)
+{
+  size_t argc;
+  char **new_argv;
+  size_t i;
+
+  /* Count number of arguments.  */
+  for (argc = 0; argv[argc] != NULL; argc++)
+    ;
+
+  /* Allocate new argument vector.  */
+  new_argv = XMALLOC (char *, argc + 1);
+
+  /* Put quoted arguments into the new argument vector.  */
+  for (i = 0; i < argc; i++)
+    {
+      const char *string = argv[i];
+
+      if (string[0] == '\0')
+	new_argv[i] = xstrdup ("\"\"");
+      else if (strpbrk (string, SHELL_SPECIAL_CHARS) != NULL)
+	{
+	  int quote_around = (strpbrk (string, SHELL_SPACE_CHARS) != NULL);
+	  size_t length;
+	  unsigned int backslashes;
+	  const char *s;
+	  char *quoted_string;
+	  char *p;
+
+	  length = 0;
+	  backslashes = 0;
+	  if (quote_around)
+	    length++;
+	  for (s = string; *s != '\0'; s++)
+	    {
+	      char c = *s;
+	      if (c == '"')
+		length += backslashes + 1;
+	      length++;
+	      if (c == '\\')
+		backslashes++;
+	      else
+		backslashes = 0;
+	    }
+	  if (quote_around)
+	    length += backslashes + 1;
+
+	  quoted_string = XMALLOC (char, length + 1);
+
+	  p = quoted_string;
+	  backslashes = 0;
+	  if (quote_around)
+	    *p++ = '"';
+	  for (s = string; *s != '\0'; s++)
+	    {
+	      char c = *s;
+	      if (c == '"')
+		{
+		  unsigned int j;
+		  for (j = backslashes + 1; j > 0; j--)
+		    *p++ = '\\';
+		}
+	      *p++ = c;
+	      if (c == '\\')
+		backslashes++;
+	      else
+		backslashes = 0;
+	    }
+	  if (quote_around)
+	    {
+	      unsigned int j;
+	      for (j = backslashes; j > 0; j--)
+		*p++ = '\\';
+	      *p++ = '"';
+	    }
+	  *p = '\0';
+
+	  new_argv[i] = quoted_string;
+	}
+      else
+	new_argv[i] = (char *) string;
+    }
+  new_argv[argc] = NULL;
+
+  return new_argv;
+}
+EOF
+		;;
+	    esac
+
+            cat <<"EOF"
+void lt_dump_script (FILE* f)
+{
+EOF
+	    func_emit_wrapper yes |
+	      $SED -n -e '
+s/^\(.\{79\}\)\(..*\)/\1\
+\2/
+h
+s/\([\\"]\)/\\\1/g
+s/$/\\n/
+s/\([^\n]*\).*/  fputs ("\1", f);/p
+g
+D'
+            cat <<"EOF"
+}
+EOF
+}
+# end: func_emit_cwrapperexe_src
+
+# func_win32_import_lib_p ARG
+# True if ARG is an import lib, as indicated by $file_magic_cmd
+func_win32_import_lib_p ()
+{
+    $opt_debug
+    case `eval $file_magic_cmd \"\$1\" 2>/dev/null | $SED -e 10q` in
+    *import*) : ;;
+    *) false ;;
+    esac
+}
+
+# func_mode_link arg...
+func_mode_link ()
+{
+    $opt_debug
+    case $host in
+    *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
+      # It is impossible to link a dll without this setting, and
+      # we shouldn't force the makefile maintainer to figure out
+      # which system we are compiling for in order to pass an extra
+      # flag for every libtool invocation.
+      # allow_undefined=no
+
+      # FIXME: Unfortunately, there are problems with the above when trying
+      # to make a dll which has undefined symbols, in which case not
+      # even a static library is built.  For now, we need to specify
+      # -no-undefined on the libtool link line when we can be certain
+      # that all symbols are satisfied, otherwise we get a static library.
+      allow_undefined=yes
+      ;;
+    *)
+      allow_undefined=yes
+      ;;
+    esac
+    libtool_args=$nonopt
+    base_compile="$nonopt $@"
+    compile_command=$nonopt
+    finalize_command=$nonopt
+
+    compile_rpath=
+    finalize_rpath=
+    compile_shlibpath=
+    finalize_shlibpath=
+    convenience=
+    old_convenience=
+    deplibs=
+    old_deplibs=
+    compiler_flags=
+    linker_flags=
+    dllsearchpath=
+    lib_search_path=`pwd`
+    inst_prefix_dir=
+    new_inherited_linker_flags=
+
+    avoid_version=no
+    bindir=
+    dlfiles=
+    dlprefiles=
+    dlself=no
+    export_dynamic=no
+    export_symbols=
+    export_symbols_regex=
+    generated=
+    libobjs=
+    ltlibs=
+    module=no
+    no_install=no
+    objs=
+    non_pic_objects=
+    precious_files_regex=
+    prefer_static_libs=no
+    preload=no
+    prev=
+    prevarg=
+    release=
+    rpath=
+    xrpath=
+    perm_rpath=
+    temp_rpath=
+    thread_safe=no
+    vinfo=
+    vinfo_number=no
+    weak_libs=
+    single_module="${wl}-single_module"
+    func_infer_tag $base_compile
+
+    # We need to know -static, to get the right output filenames.
+    for arg
+    do
+      case $arg in
+      -shared)
+	test "$build_libtool_libs" != yes && \
+	  func_fatal_configuration "can not build a shared library"
+	build_old_libs=no
+	break
+	;;
+      -all-static | -static | -static-libtool-libs)
+	case $arg in
+	-all-static)
+	  if test "$build_libtool_libs" = yes && test -z "$link_static_flag"; then
+	    func_warning "complete static linking is impossible in this configuration"
+	  fi
+	  if test -n "$link_static_flag"; then
+	    dlopen_self=$dlopen_self_static
+	  fi
+	  prefer_static_libs=yes
+	  ;;
+	-static)
+	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
+	    dlopen_self=$dlopen_self_static
+	  fi
+	  prefer_static_libs=built
+	  ;;
+	-static-libtool-libs)
+	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
+	    dlopen_self=$dlopen_self_static
+	  fi
+	  prefer_static_libs=yes
+	  ;;
+	esac
+	build_libtool_libs=no
+	build_old_libs=yes
+	break
+	;;
+      esac
+    done
+
+    # See if our shared archives depend on static archives.
+    test -n "$old_archive_from_new_cmds" && build_old_libs=yes
+
+    # Go through the arguments, transforming them on the way.
+    while test "$#" -gt 0; do
+      arg="$1"
+      shift
+      func_quote_for_eval "$arg"
+      qarg=$func_quote_for_eval_unquoted_result
+      func_append libtool_args " $func_quote_for_eval_result"
+
+      # If the previous option needs an argument, assign it.
+      if test -n "$prev"; then
+	case $prev in
+	output)
+	  func_append compile_command " @OUTPUT@"
+	  func_append finalize_command " @OUTPUT@"
+	  ;;
+	esac
+
+	case $prev in
+	bindir)
+	  bindir="$arg"
+	  prev=
+	  continue
+	  ;;
+	dlfiles|dlprefiles)
+	  if test "$preload" = no; then
+	    # Add the symbol object into the linking commands.
+	    func_append compile_command " @SYMFILE@"
+	    func_append finalize_command " @SYMFILE@"
+	    preload=yes
+	  fi
+	  case $arg in
+	  *.la | *.lo) ;;  # We handle these cases below.
+	  force)
+	    if test "$dlself" = no; then
+	      dlself=needless
+	      export_dynamic=yes
+	    fi
+	    prev=
+	    continue
+	    ;;
+	  self)
+	    if test "$prev" = dlprefiles; then
+	      dlself=yes
+	    elif test "$prev" = dlfiles && test "$dlopen_self" != yes; then
+	      dlself=yes
+	    else
+	      dlself=needless
+	      export_dynamic=yes
+	    fi
+	    prev=
+	    continue
+	    ;;
+	  *)
+	    if test "$prev" = dlfiles; then
+	      func_append dlfiles " $arg"
+	    else
+	      func_append dlprefiles " $arg"
+	    fi
+	    prev=
+	    continue
+	    ;;
+	  esac
+	  ;;
+	expsyms)
+	  export_symbols="$arg"
+	  test -f "$arg" \
+	    || func_fatal_error "symbol file \`$arg' does not exist"
+	  prev=
+	  continue
+	  ;;
+	expsyms_regex)
+	  export_symbols_regex="$arg"
+	  prev=
+	  continue
+	  ;;
+	framework)
+	  case $host in
+	    *-*-darwin*)
+	      case "$deplibs " in
+		*" $qarg.ltframework "*) ;;
+		*) func_append deplibs " $qarg.ltframework" # this is fixed later
+		   ;;
+	      esac
+	      ;;
+	  esac
+	  prev=
+	  continue
+	  ;;
+	inst_prefix)
+	  inst_prefix_dir="$arg"
+	  prev=
+	  continue
+	  ;;
+	objectlist)
+	  if test -f "$arg"; then
+	    save_arg=$arg
+	    moreargs=
+	    for fil in `cat "$save_arg"`
+	    do
+#	      func_append moreargs " $fil"
+	      arg=$fil
+	      # A libtool-controlled object.
+
+	      # Check to see that this really is a libtool object.
+	      if func_lalib_unsafe_p "$arg"; then
+		pic_object=
+		non_pic_object=
+
+		# Read the .lo file
+		func_source "$arg"
+
+		if test -z "$pic_object" ||
+		   test -z "$non_pic_object" ||
+		   test "$pic_object" = none &&
+		   test "$non_pic_object" = none; then
+		  func_fatal_error "cannot find name of object for \`$arg'"
+		fi
+
+		# Extract subdirectory from the argument.
+		func_dirname "$arg" "/" ""
+		xdir="$func_dirname_result"
+
+		if test "$pic_object" != none; then
+		  # Prepend the subdirectory the object is found in.
+		  pic_object="$xdir$pic_object"
+
+		  if test "$prev" = dlfiles; then
+		    if test "$build_libtool_libs" = yes && test "$dlopen_support" = yes; then
+		      func_append dlfiles " $pic_object"
+		      prev=
+		      continue
+		    else
+		      # If libtool objects are unsupported, then we need to preload.
+		      prev=dlprefiles
+		    fi
+		  fi
+
+		  # CHECK ME:  I think I busted this.  -Ossama
+		  if test "$prev" = dlprefiles; then
+		    # Preload the old-style object.
+		    func_append dlprefiles " $pic_object"
+		    prev=
+		  fi
+
+		  # A PIC object.
+		  func_append libobjs " $pic_object"
+		  arg="$pic_object"
+		fi
+
+		# Non-PIC object.
+		if test "$non_pic_object" != none; then
+		  # Prepend the subdirectory the object is found in.
+		  non_pic_object="$xdir$non_pic_object"
+
+		  # A standard non-PIC object
+		  func_append non_pic_objects " $non_pic_object"
+		  if test -z "$pic_object" || test "$pic_object" = none ; then
+		    arg="$non_pic_object"
+		  fi
+		else
+		  # If the PIC object exists, use it instead.
+		  # $xdir was prepended to $pic_object above.
+		  non_pic_object="$pic_object"
+		  func_append non_pic_objects " $non_pic_object"
+		fi
+	      else
+		# Only an error if not doing a dry-run.
+		if $opt_dry_run; then
+		  # Extract subdirectory from the argument.
+		  func_dirname "$arg" "/" ""
+		  xdir="$func_dirname_result"
+
+		  func_lo2o "$arg"
+		  pic_object=$xdir$objdir/$func_lo2o_result
+		  non_pic_object=$xdir$func_lo2o_result
+		  func_append libobjs " $pic_object"
+		  func_append non_pic_objects " $non_pic_object"
+	        else
+		  func_fatal_error "\`$arg' is not a valid libtool object"
+		fi
+	      fi
+	    done
+	  else
+	    func_fatal_error "link input file \`$arg' does not exist"
+	  fi
+	  arg=$save_arg
+	  prev=
+	  continue
+	  ;;
+	precious_regex)
+	  precious_files_regex="$arg"
+	  prev=
+	  continue
+	  ;;
+	release)
+	  release="-$arg"
+	  prev=
+	  continue
+	  ;;
+	rpath | xrpath)
+	  # We need an absolute path.
+	  case $arg in
+	  [\\/]* | [A-Za-z]:[\\/]*) ;;
+	  *)
+	    func_fatal_error "only absolute run-paths are allowed"
+	    ;;
+	  esac
+	  if test "$prev" = rpath; then
+	    case "$rpath " in
+	    *" $arg "*) ;;
+	    *) func_append rpath " $arg" ;;
+	    esac
+	  else
+	    case "$xrpath " in
+	    *" $arg "*) ;;
+	    *) func_append xrpath " $arg" ;;
+	    esac
+	  fi
+	  prev=
+	  continue
+	  ;;
+	shrext)
+	  shrext_cmds="$arg"
+	  prev=
+	  continue
+	  ;;
+	weak)
+	  func_append weak_libs " $arg"
+	  prev=
+	  continue
+	  ;;
+	xcclinker)
+	  func_append linker_flags " $qarg"
+	  func_append compiler_flags " $qarg"
+	  prev=
+	  func_append compile_command " $qarg"
+	  func_append finalize_command " $qarg"
+	  continue
+	  ;;
+	xcompiler)
+	  func_append compiler_flags " $qarg"
+	  prev=
+	  func_append compile_command " $qarg"
+	  func_append finalize_command " $qarg"
+	  continue
+	  ;;
+	xlinker)
+	  func_append linker_flags " $qarg"
+	  func_append compiler_flags " $wl$qarg"
+	  prev=
+	  func_append compile_command " $wl$qarg"
+	  func_append finalize_command " $wl$qarg"
+	  continue
+	  ;;
+	*)
+	  eval "$prev=\"\$arg\""
+	  prev=
+	  continue
+	  ;;
+	esac
+      fi # test -n "$prev"
+
+      prevarg="$arg"
+
+      case $arg in
+      -all-static)
+	if test -n "$link_static_flag"; then
+	  # See comment for -static flag below, for more details.
+	  func_append compile_command " $link_static_flag"
+	  func_append finalize_command " $link_static_flag"
+	fi
+	continue
+	;;
+
+      -allow-undefined)
+	# FIXME: remove this flag sometime in the future.
+	func_fatal_error "\`-allow-undefined' must not be used because it is the default"
+	;;
+
+      -avoid-version)
+	avoid_version=yes
+	continue
+	;;
+
+      -bindir)
+	prev=bindir
+	continue
+	;;
+
+      -dlopen)
+	prev=dlfiles
+	continue
+	;;
+
+      -dlpreopen)
+	prev=dlprefiles
+	continue
+	;;
+
+      -export-dynamic)
+	export_dynamic=yes
+	continue
+	;;
+
+      -export-symbols | -export-symbols-regex)
+	if test -n "$export_symbols" || test -n "$export_symbols_regex"; then
+	  func_fatal_error "more than one -exported-symbols argument is not allowed"
+	fi
+	if test "X$arg" = "X-export-symbols"; then
+	  prev=expsyms
+	else
+	  prev=expsyms_regex
+	fi
+	continue
+	;;
+
+      -framework)
+	prev=framework
+	continue
+	;;
+
+      -inst-prefix-dir)
+	prev=inst_prefix
+	continue
+	;;
+
+      # The native IRIX linker understands -LANG:*, -LIST:* and -LNO:*
+      # so, if we see these flags be careful not to treat them like -L
+      -L[A-Z][A-Z]*:*)
+	case $with_gcc/$host in
+	no/*-*-irix* | /*-*-irix*)
+	  func_append compile_command " $arg"
+	  func_append finalize_command " $arg"
+	  ;;
+	esac
+	continue
+	;;
+
+      -L*)
+	func_stripname "-L" '' "$arg"
+	if test -z "$func_stripname_result"; then
+	  if test "$#" -gt 0; then
+	    func_fatal_error "require no space between \`-L' and \`$1'"
+	  else
+	    func_fatal_error "need path for \`-L' option"
+	  fi
+	fi
+	func_resolve_sysroot "$func_stripname_result"
+	dir=$func_resolve_sysroot_result
+	# We need an absolute path.
+	case $dir in
+	[\\/]* | [A-Za-z]:[\\/]*) ;;
+	*)
+	  absdir=`cd "$dir" && pwd`
+	  test -z "$absdir" && \
+	    func_fatal_error "cannot determine absolute directory name of \`$dir'"
+	  dir="$absdir"
+	  ;;
+	esac
+	case "$deplibs " in
+	*" -L$dir "* | *" $arg "*)
+	  # Will only happen for absolute or sysroot arguments
+	  ;;
+	*)
+	  # Preserve sysroot, but never include relative directories
+	  case $dir in
+	    [\\/]* | [A-Za-z]:[\\/]* | =*) func_append deplibs " $arg" ;;
+	    *) func_append deplibs " -L$dir" ;;
+	  esac
+	  func_append lib_search_path " $dir"
+	  ;;
+	esac
+	case $host in
+	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
+	  testbindir=`$ECHO "$dir" | $SED 's*/lib$*/bin*'`
+	  case :$dllsearchpath: in
+	  *":$dir:"*) ;;
+	  ::) dllsearchpath=$dir;;
+	  *) func_append dllsearchpath ":$dir";;
+	  esac
+	  case :$dllsearchpath: in
+	  *":$testbindir:"*) ;;
+	  ::) dllsearchpath=$testbindir;;
+	  *) func_append dllsearchpath ":$testbindir";;
+	  esac
+	  ;;
+	esac
+	continue
+	;;
+
+      -l*)
+	if test "X$arg" = "X-lc" || test "X$arg" = "X-lm"; then
+	  case $host in
+	  *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-beos* | *-cegcc* | *-*-haiku*)
+	    # These systems don't actually have a C or math library (as such)
+	    continue
+	    ;;
+	  *-*-os2*)
+	    # These systems don't actually have a C library (as such)
+	    test "X$arg" = "X-lc" && continue
+	    ;;
+	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly*)
+	    # Do not include libc due to us having libc/libc_r.
+	    test "X$arg" = "X-lc" && continue
+	    ;;
+	  *-*-rhapsody* | *-*-darwin1.[012])
+	    # Rhapsody C and math libraries are in the System framework
+	    func_append deplibs " System.ltframework"
+	    continue
+	    ;;
+	  *-*-sco3.2v5* | *-*-sco5v6*)
+	    # Causes problems with __ctype
+	    test "X$arg" = "X-lc" && continue
+	    ;;
+	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
+	    # Compiler inserts libc in the correct place for threads to work
+	    test "X$arg" = "X-lc" && continue
+	    ;;
+	  esac
+	elif test "X$arg" = "X-lc_r"; then
+	 case $host in
+	 *-*-openbsd* | *-*-freebsd* | *-*-dragonfly*)
+	   # Do not include libc_r directly, use -pthread flag.
+	   continue
+	   ;;
+	 esac
+	fi
+	func_append deplibs " $arg"
+	continue
+	;;
+
+      -module)
+	module=yes
+	continue
+	;;
+
+      # Tru64 UNIX uses -model [arg] to determine the layout of C++
+      # classes, name mangling, and exception handling.
+      # Darwin uses the -arch flag to determine output architecture.
+      -model|-arch|-isysroot|--sysroot)
+	func_append compiler_flags " $arg"
+	func_append compile_command " $arg"
+	func_append finalize_command " $arg"
+	prev=xcompiler
+	continue
+	;;
+
+      -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe \
+      |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
+	func_append compiler_flags " $arg"
+	func_append compile_command " $arg"
+	func_append finalize_command " $arg"
+	case "$new_inherited_linker_flags " in
+	    *" $arg "*) ;;
+	    * ) func_append new_inherited_linker_flags " $arg" ;;
+	esac
+	continue
+	;;
+
+      -multi_module)
+	single_module="${wl}-multi_module"
+	continue
+	;;
+
+      -no-fast-install)
+	fast_install=no
+	continue
+	;;
+
+      -no-install)
+	case $host in
+	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-darwin* | *-cegcc*)
+	  # The PATH hackery in wrapper scripts is required on Windows
+	  # and Darwin in order for the loader to find any dlls it needs.
+	  func_warning "\`-no-install' is ignored for $host"
+	  func_warning "assuming \`-no-fast-install' instead"
+	  fast_install=no
+	  ;;
+	*) no_install=yes ;;
+	esac
+	continue
+	;;
+
+      -no-undefined)
+	allow_undefined=no
+	continue
+	;;
+
+      -objectlist)
+	prev=objectlist
+	continue
+	;;
+
+      -o) prev=output ;;
+
+      -precious-files-regex)
+	prev=precious_regex
+	continue
+	;;
+
+      -release)
+	prev=release
+	continue
+	;;
+
+      -rpath)
+	prev=rpath
+	continue
+	;;
+
+      -R)
+	prev=xrpath
+	continue
+	;;
+
+      -R*)
+	func_stripname '-R' '' "$arg"
+	dir=$func_stripname_result
+	# We need an absolute path.
+	case $dir in
+	[\\/]* | [A-Za-z]:[\\/]*) ;;
+	=*)
+	  func_stripname '=' '' "$dir"
+	  dir=$lt_sysroot$func_stripname_result
+	  ;;
+	*)
+	  func_fatal_error "only absolute run-paths are allowed"
+	  ;;
+	esac
+	case "$xrpath " in
+	*" $dir "*) ;;
+	*) func_append xrpath " $dir" ;;
+	esac
+	continue
+	;;
+
+      -shared)
+	# The effects of -shared are defined in a previous loop.
+	continue
+	;;
+
+      -shrext)
+	prev=shrext
+	continue
+	;;
+
+      -static | -static-libtool-libs)
+	# The effects of -static are defined in a previous loop.
+	# We used to do the same as -all-static on platforms that
+	# didn't have a PIC flag, but the assumption that the effects
+	# would be equivalent was wrong.  It would break on at least
+	# Digital Unix and AIX.
+	continue
+	;;
+
+      -thread-safe)
+	thread_safe=yes
+	continue
+	;;
+
+      -version-info)
+	prev=vinfo
+	continue
+	;;
+
+      -version-number)
+	prev=vinfo
+	vinfo_number=yes
+	continue
+	;;
+
+      -weak)
+        prev=weak
+	continue
+	;;
+
+      -Wc,*)
+	func_stripname '-Wc,' '' "$arg"
+	args=$func_stripname_result
+	arg=
+	save_ifs="$IFS"; IFS=','
+	for flag in $args; do
+	  IFS="$save_ifs"
+          func_quote_for_eval "$flag"
+	  func_append arg " $func_quote_for_eval_result"
+	  func_append compiler_flags " $func_quote_for_eval_result"
+	done
+	IFS="$save_ifs"
+	func_stripname ' ' '' "$arg"
+	arg=$func_stripname_result
+	;;
+
+      -Wl,*)
+	func_stripname '-Wl,' '' "$arg"
+	args=$func_stripname_result
+	arg=
+	save_ifs="$IFS"; IFS=','
+	for flag in $args; do
+	  IFS="$save_ifs"
+          func_quote_for_eval "$flag"
+	  func_append arg " $wl$func_quote_for_eval_result"
+	  func_append compiler_flags " $wl$func_quote_for_eval_result"
+	  func_append linker_flags " $func_quote_for_eval_result"
+	done
+	IFS="$save_ifs"
+	func_stripname ' ' '' "$arg"
+	arg=$func_stripname_result
+	;;
+
+      -Xcompiler)
+	prev=xcompiler
+	continue
+	;;
+
+      -Xlinker)
+	prev=xlinker
+	continue
+	;;
+
+      -XCClinker)
+	prev=xcclinker
+	continue
+	;;
+
+      # -msg_* for osf cc
+      -msg_*)
+	func_quote_for_eval "$arg"
+	arg="$func_quote_for_eval_result"
+	;;
+
+      # Flags to be passed through unchanged, with rationale:
+      # -64, -mips[0-9]      enable 64-bit mode for the SGI compiler
+      # -r[0-9][0-9]*        specify processor for the SGI compiler
+      # -xarch=*, -xtarget=* enable 64-bit mode for the Sun compiler
+      # +DA*, +DD*           enable 64-bit mode for the HP compiler
+      # -q*                  compiler args for the IBM compiler
+      # -m*, -t[45]*, -txscale* architecture-specific flags for GCC
+      # -F/path              path to uninstalled frameworks, gcc on darwin
+      # -p, -pg, --coverage, -fprofile-*  profiling flags for GCC
+      # @file                GCC response files
+      # -tp=*                Portland pgcc target processor selection
+      # --sysroot=*          for sysroot support
+      # -O*, -flto*, -fwhopr*, -fuse-linker-plugin GCC link-time optimization
+      -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \
+      -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*|-tp=*|--sysroot=*| \
+      -O*|-flto*|-fwhopr*|-fuse-linker-plugin)
+        func_quote_for_eval "$arg"
+	arg="$func_quote_for_eval_result"
+        func_append compile_command " $arg"
+        func_append finalize_command " $arg"
+        func_append compiler_flags " $arg"
+        continue
+        ;;
+
+      # Some other compiler flag.
+      -* | +*)
+        func_quote_for_eval "$arg"
+	arg="$func_quote_for_eval_result"
+	;;
+
+      *.$objext)
+	# A standard object.
+	func_append objs " $arg"
+	;;
+
+      *.lo)
+	# A libtool-controlled object.
+
+	# Check to see that this really is a libtool object.
+	if func_lalib_unsafe_p "$arg"; then
+	  pic_object=
+	  non_pic_object=
+
+	  # Read the .lo file
+	  func_source "$arg"
+
+	  if test -z "$pic_object" ||
+	     test -z "$non_pic_object" ||
+	     test "$pic_object" = none &&
+	     test "$non_pic_object" = none; then
+	    func_fatal_error "cannot find name of object for \`$arg'"
+	  fi
+
+	  # Extract subdirectory from the argument.
+	  func_dirname "$arg" "/" ""
+	  xdir="$func_dirname_result"
+
+	  if test "$pic_object" != none; then
+	    # Prepend the subdirectory the object is found in.
+	    pic_object="$xdir$pic_object"
+
+	    if test "$prev" = dlfiles; then
+	      if test "$build_libtool_libs" = yes && test "$dlopen_support" = yes; then
+		func_append dlfiles " $pic_object"
+		prev=
+		continue
+	      else
+		# If libtool objects are unsupported, then we need to preload.
+		prev=dlprefiles
+	      fi
+	    fi
+
+	    # CHECK ME:  I think I busted this.  -Ossama
+	    if test "$prev" = dlprefiles; then
+	      # Preload the old-style object.
+	      func_append dlprefiles " $pic_object"
+	      prev=
+	    fi
+
+	    # A PIC object.
+	    func_append libobjs " $pic_object"
+	    arg="$pic_object"
+	  fi
+
+	  # Non-PIC object.
+	  if test "$non_pic_object" != none; then
+	    # Prepend the subdirectory the object is found in.
+	    non_pic_object="$xdir$non_pic_object"
+
+	    # A standard non-PIC object
+	    func_append non_pic_objects " $non_pic_object"
+	    if test -z "$pic_object" || test "$pic_object" = none ; then
+	      arg="$non_pic_object"
+	    fi
+	  else
+	    # If the PIC object exists, use it instead.
+	    # $xdir was prepended to $pic_object above.
+	    non_pic_object="$pic_object"
+	    func_append non_pic_objects " $non_pic_object"
+	  fi
+	else
+	  # Only an error if not doing a dry-run.
+	  if $opt_dry_run; then
+	    # Extract subdirectory from the argument.
+	    func_dirname "$arg" "/" ""
+	    xdir="$func_dirname_result"
+
+	    func_lo2o "$arg"
+	    pic_object=$xdir$objdir/$func_lo2o_result
+	    non_pic_object=$xdir$func_lo2o_result
+	    func_append libobjs " $pic_object"
+	    func_append non_pic_objects " $non_pic_object"
+	  else
+	    func_fatal_error "\`$arg' is not a valid libtool object"
+	  fi
+	fi
+	;;
+
+      *.$libext)
+	# An archive.
+	func_append deplibs " $arg"
+	func_append old_deplibs " $arg"
+	continue
+	;;
+
+      *.la)
+	# A libtool-controlled library.
+
+	func_resolve_sysroot "$arg"
+	if test "$prev" = dlfiles; then
+	  # This library was specified with -dlopen.
+	  func_append dlfiles " $func_resolve_sysroot_result"
+	  prev=
+	elif test "$prev" = dlprefiles; then
+	  # The library was specified with -dlpreopen.
+	  func_append dlprefiles " $func_resolve_sysroot_result"
+	  prev=
+	else
+	  func_append deplibs " $func_resolve_sysroot_result"
+	fi
+	continue
+	;;
+
+      # Some other compiler argument.
+      *)
+	# Unknown arguments in both finalize_command and compile_command need
+	# to be aesthetically quoted because they are evaled later.
+	func_quote_for_eval "$arg"
+	arg="$func_quote_for_eval_result"
+	;;
+      esac # arg
+
+      # Now actually substitute the argument into the commands.
+      if test -n "$arg"; then
+	func_append compile_command " $arg"
+	func_append finalize_command " $arg"
+      fi
+    done # argument parsing loop
+
+    test -n "$prev" && \
+      func_fatal_help "the \`$prevarg' option requires an argument"
+
+    if test "$export_dynamic" = yes && test -n "$export_dynamic_flag_spec"; then
+      eval arg=\"$export_dynamic_flag_spec\"
+      func_append compile_command " $arg"
+      func_append finalize_command " $arg"
+    fi
+
+    oldlibs=
+    # calculate the name of the file, without its directory
+    func_basename "$output"
+    outputname="$func_basename_result"
+    libobjs_save="$libobjs"
+
+    if test -n "$shlibpath_var"; then
+      # get the directories listed in $shlibpath_var
+      eval shlib_search_path=\`\$ECHO \"\${$shlibpath_var}\" \| \$SED \'s/:/ /g\'\`
+    else
+      shlib_search_path=
+    fi
+    eval sys_lib_search_path=\"$sys_lib_search_path_spec\"
+    eval sys_lib_dlsearch_path=\"$sys_lib_dlsearch_path_spec\"
+
+    func_dirname "$output" "/" ""
+    output_objdir="$func_dirname_result$objdir"
+    func_to_tool_file "$output_objdir/"
+    tool_output_objdir=$func_to_tool_file_result
+    # Create the object directory.
+    func_mkdir_p "$output_objdir"
+
+    # Determine the type of output
+    case $output in
+    "")
+      func_fatal_help "you must specify an output file"
+      ;;
+    *.$libext) linkmode=oldlib ;;
+    *.lo | *.$objext) linkmode=obj ;;
+    *.la) linkmode=lib ;;
+    *) linkmode=prog ;; # Anything else should be a program.
+    esac
+
+    specialdeplibs=
+
+    libs=
+    # Find all interdependent deplibs by searching for libraries
+    # that are linked more than once (e.g. -la -lb -la)
+    for deplib in $deplibs; do
+      if $opt_preserve_dup_deps ; then
+	case "$libs " in
+	*" $deplib "*) func_append specialdeplibs " $deplib" ;;
+	esac
+      fi
+      func_append libs " $deplib"
+    done
+
+    if test "$linkmode" = lib; then
+      libs="$predeps $libs $compiler_lib_search_path $postdeps"
+
+      # Compute libraries that are listed more than once in $predeps
+      # $postdeps and mark them as special (i.e., whose duplicates are
+      # not to be eliminated).
+      pre_post_deps=
+      if $opt_duplicate_compiler_generated_deps; then
+	for pre_post_dep in $predeps $postdeps; do
+	  case "$pre_post_deps " in
+	  *" $pre_post_dep "*) func_append specialdeplibs " $pre_post_deps" ;;
+	  esac
+	  func_append pre_post_deps " $pre_post_dep"
+	done
+      fi
+      pre_post_deps=
+    fi
+
+    deplibs=
+    newdependency_libs=
+    newlib_search_path=
+    need_relink=no # whether we're linking any uninstalled libtool libraries
+    notinst_deplibs= # not-installed libtool libraries
+    notinst_path= # paths that contain not-installed libtool libraries
+
+    case $linkmode in
+    lib)
+	passes="conv dlpreopen link"
+	for file in $dlfiles $dlprefiles; do
+	  case $file in
+	  *.la) ;;
+	  *)
+	    func_fatal_help "libraries can \`-dlopen' only libtool libraries: $file"
+	    ;;
+	  esac
+	done
+	;;
+    prog)
+	compile_deplibs=
+	finalize_deplibs=
+	alldeplibs=no
+	newdlfiles=
+	newdlprefiles=
+	passes="conv scan dlopen dlpreopen link"
+	;;
+    *)  passes="conv"
+	;;
+    esac
+
+    for pass in $passes; do
+      # The preopen pass in lib mode reverses $deplibs; put it back here
+      # so that -L comes before libs that need it for instance...
+      if test "$linkmode,$pass" = "lib,link"; then
+	## FIXME: Find the place where the list is rebuilt in the wrong
+	##        order, and fix it there properly
+        tmp_deplibs=
+	for deplib in $deplibs; do
+	  tmp_deplibs="$deplib $tmp_deplibs"
+	done
+	deplibs="$tmp_deplibs"
+      fi
+
+      if test "$linkmode,$pass" = "lib,link" ||
+	 test "$linkmode,$pass" = "prog,scan"; then
+	libs="$deplibs"
+	deplibs=
+      fi
+      if test "$linkmode" = prog; then
+	case $pass in
+	dlopen) libs="$dlfiles" ;;
+	dlpreopen) libs="$dlprefiles" ;;
+	link)
+	  libs="$deplibs %DEPLIBS%"
+	  test "X$link_all_deplibs" != Xno && libs="$libs $dependency_libs"
+	  ;;
+	esac
+      fi
+      if test "$linkmode,$pass" = "lib,dlpreopen"; then
+	# Collect and forward deplibs of preopened libtool libs
+	for lib in $dlprefiles; do
+	  # Ignore non-libtool-libs
+	  dependency_libs=
+	  func_resolve_sysroot "$lib"
+	  case $lib in
+	  *.la)	func_source "$func_resolve_sysroot_result" ;;
+	  esac
+
+	  # Collect preopened libtool deplibs, except any this library
+	  # has declared as weak libs
+	  for deplib in $dependency_libs; do
+	    func_basename "$deplib"
+            deplib_base=$func_basename_result
+	    case " $weak_libs " in
+	    *" $deplib_base "*) ;;
+	    *) func_append deplibs " $deplib" ;;
+	    esac
+	  done
+	done
+	libs="$dlprefiles"
+      fi
+      if test "$pass" = dlopen; then
+	# Collect dlpreopened libraries
+	save_deplibs="$deplibs"
+	deplibs=
+      fi
+
+      for deplib in $libs; do
+	lib=
+	found=no
+	case $deplib in
+	-mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe \
+        |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
+	  if test "$linkmode,$pass" = "prog,link"; then
+	    compile_deplibs="$deplib $compile_deplibs"
+	    finalize_deplibs="$deplib $finalize_deplibs"
+	  else
+	    func_append compiler_flags " $deplib"
+	    if test "$linkmode" = lib ; then
+		case "$new_inherited_linker_flags " in
+		    *" $deplib "*) ;;
+		    * ) func_append new_inherited_linker_flags " $deplib" ;;
+		esac
+	    fi
+	  fi
+	  continue
+	  ;;
+	-l*)
+	  if test "$linkmode" != lib && test "$linkmode" != prog; then
+	    func_warning "\`-l' is ignored for archives/objects"
+	    continue
+	  fi
+	  func_stripname '-l' '' "$deplib"
+	  name=$func_stripname_result
+	  if test "$linkmode" = lib; then
+	    searchdirs="$newlib_search_path $lib_search_path $compiler_lib_search_dirs $sys_lib_search_path $shlib_search_path"
+	  else
+	    searchdirs="$newlib_search_path $lib_search_path $sys_lib_search_path $shlib_search_path"
+	  fi
+	  for searchdir in $searchdirs; do
+	    for search_ext in .la $std_shrext .so .a; do
+	      # Search the libtool library
+	      lib="$searchdir/lib${name}${search_ext}"
+	      if test -f "$lib"; then
+		if test "$search_ext" = ".la"; then
+		  found=yes
+		else
+		  found=no
+		fi
+		break 2
+	      fi
+	    done
+	  done
+	  if test "$found" != yes; then
+	    # deplib doesn't seem to be a libtool library
+	    if test "$linkmode,$pass" = "prog,link"; then
+	      compile_deplibs="$deplib $compile_deplibs"
+	      finalize_deplibs="$deplib $finalize_deplibs"
+	    else
+	      deplibs="$deplib $deplibs"
+	      test "$linkmode" = lib && newdependency_libs="$deplib $newdependency_libs"
+	    fi
+	    continue
+	  else # deplib is a libtool library
+	    # If $allow_libtool_libs_with_static_runtimes && $deplib is a stdlib,
+	    # We need to do some special things here, and not later.
+	    if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then
+	      case " $predeps $postdeps " in
+	      *" $deplib "*)
+		if func_lalib_p "$lib"; then
+		  library_names=
+		  old_library=
+		  func_source "$lib"
+		  for l in $old_library $library_names; do
+		    ll="$l"
+		  done
+		  if test "X$ll" = "X$old_library" ; then # only static version available
+		    found=no
+		    func_dirname "$lib" "" "."
+		    ladir="$func_dirname_result"
+		    lib=$ladir/$old_library
+		    if test "$linkmode,$pass" = "prog,link"; then
+		      compile_deplibs="$deplib $compile_deplibs"
+		      finalize_deplibs="$deplib $finalize_deplibs"
+		    else
+		      deplibs="$deplib $deplibs"
+		      test "$linkmode" = lib && newdependency_libs="$deplib $newdependency_libs"
+		    fi
+		    continue
+		  fi
+		fi
+		;;
+	      *) ;;
+	      esac
+	    fi
+	  fi
+	  ;; # -l
+	*.ltframework)
+	  if test "$linkmode,$pass" = "prog,link"; then
+	    compile_deplibs="$deplib $compile_deplibs"
+	    finalize_deplibs="$deplib $finalize_deplibs"
+	  else
+	    deplibs="$deplib $deplibs"
+	    if test "$linkmode" = lib ; then
+		case "$new_inherited_linker_flags " in
+		    *" $deplib "*) ;;
+		    * ) func_append new_inherited_linker_flags " $deplib" ;;
+		esac
+	    fi
+	  fi
+	  continue
+	  ;;
+	-L*)
+	  case $linkmode in
+	  lib)
+	    deplibs="$deplib $deplibs"
+	    test "$pass" = conv && continue
+	    newdependency_libs="$deplib $newdependency_libs"
+	    func_stripname '-L' '' "$deplib"
+	    func_resolve_sysroot "$func_stripname_result"
+	    func_append newlib_search_path " $func_resolve_sysroot_result"
+	    ;;
+	  prog)
+	    if test "$pass" = conv; then
+	      deplibs="$deplib $deplibs"
+	      continue
+	    fi
+	    if test "$pass" = scan; then
+	      deplibs="$deplib $deplibs"
+	    else
+	      compile_deplibs="$deplib $compile_deplibs"
+	      finalize_deplibs="$deplib $finalize_deplibs"
+	    fi
+	    func_stripname '-L' '' "$deplib"
+	    func_resolve_sysroot "$func_stripname_result"
+	    func_append newlib_search_path " $func_resolve_sysroot_result"
+	    ;;
+	  *)
+	    func_warning "\`-L' is ignored for archives/objects"
+	    ;;
+	  esac # linkmode
+	  continue
+	  ;; # -L
+	-R*)
+	  if test "$pass" = link; then
+	    func_stripname '-R' '' "$deplib"
+	    func_resolve_sysroot "$func_stripname_result"
+	    dir=$func_resolve_sysroot_result
+	    # Make sure the xrpath contains only unique directories.
+	    case "$xrpath " in
+	    *" $dir "*) ;;
+	    *) func_append xrpath " $dir" ;;
+	    esac
+	  fi
+	  deplibs="$deplib $deplibs"
+	  continue
+	  ;;
+	*.la)
+	  func_resolve_sysroot "$deplib"
+	  lib=$func_resolve_sysroot_result
+	  ;;
+	*.$libext)
+	  if test "$pass" = conv; then
+	    deplibs="$deplib $deplibs"
+	    continue
+	  fi
+	  case $linkmode in
+	  lib)
+	    # Linking convenience modules into shared libraries is allowed,
+	    # but linking other static libraries is non-portable.
+	    case " $dlpreconveniencelibs " in
+	    *" $deplib "*) ;;
+	    *)
+	      valid_a_lib=no
+	      case $deplibs_check_method in
+		match_pattern*)
+		  set dummy $deplibs_check_method; shift
+		  match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
+		  if eval "\$ECHO \"$deplib\"" 2>/dev/null | $SED 10q \
+		    | $EGREP "$match_pattern_regex" > /dev/null; then
+		    valid_a_lib=yes
+		  fi
+		;;
+		pass_all)
+		  valid_a_lib=yes
+		;;
+	      esac
+	      if test "$valid_a_lib" != yes; then
+		echo
+		$ECHO "*** Warning: Trying to link with static lib archive $deplib."
+		echo "*** I have the capability to make that library automatically link in when"
+		echo "*** you link to this library.  But I can only do this if you have a"
+		echo "*** shared version of the library, which you do not appear to have"
+		echo "*** because the file extensions .$libext of this argument makes me believe"
+		echo "*** that it is just a static archive that I should not use here."
+	      else
+		echo
+		$ECHO "*** Warning: Linking the shared library $output against the"
+		$ECHO "*** static library $deplib is not portable!"
+		deplibs="$deplib $deplibs"
+	      fi
+	      ;;
+	    esac
+	    continue
+	    ;;
+	  prog)
+	    if test "$pass" != link; then
+	      deplibs="$deplib $deplibs"
+	    else
+	      compile_deplibs="$deplib $compile_deplibs"
+	      finalize_deplibs="$deplib $finalize_deplibs"
+	    fi
+	    continue
+	    ;;
+	  esac # linkmode
+	  ;; # *.$libext
+	*.lo | *.$objext)
+	  if test "$pass" = conv; then
+	    deplibs="$deplib $deplibs"
+	  elif test "$linkmode" = prog; then
+	    if test "$pass" = dlpreopen || test "$dlopen_support" != yes || test "$build_libtool_libs" = no; then
+	      # If there is no dlopen support or we're linking statically,
+	      # we need to preload.
+	      func_append newdlprefiles " $deplib"
+	      compile_deplibs="$deplib $compile_deplibs"
+	      finalize_deplibs="$deplib $finalize_deplibs"
+	    else
+	      func_append newdlfiles " $deplib"
+	    fi
+	  fi
+	  continue
+	  ;;
+	%DEPLIBS%)
+	  alldeplibs=yes
+	  continue
+	  ;;
+	esac # case $deplib
+
+	if test "$found" = yes || test -f "$lib"; then :
+	else
+	  func_fatal_error "cannot find the library \`$lib' or unhandled argument \`$deplib'"
+	fi
+
+	# Check to see that this really is a libtool archive.
+	func_lalib_unsafe_p "$lib" \
+	  || func_fatal_error "\`$lib' is not a valid libtool archive"
+
+	func_dirname "$lib" "" "."
+	ladir="$func_dirname_result"
+
+	dlname=
+	dlopen=
+	dlpreopen=
+	libdir=
+	library_names=
+	old_library=
+	inherited_linker_flags=
+	# If the library was installed with an old release of libtool,
+	# it will not redefine variables installed, or shouldnotlink
+	installed=yes
+	shouldnotlink=no
+	avoidtemprpath=
+
+
+	# Read the .la file
+	func_source "$lib"
+
+	# Convert "-framework foo" to "foo.ltframework"
+	if test -n "$inherited_linker_flags"; then
+	  tmp_inherited_linker_flags=`$ECHO "$inherited_linker_flags" | $SED 's/-framework \([^ $]*\)/\1.ltframework/g'`
+	  for tmp_inherited_linker_flag in $tmp_inherited_linker_flags; do
+	    case " $new_inherited_linker_flags " in
+	      *" $tmp_inherited_linker_flag "*) ;;
+	      *) func_append new_inherited_linker_flags " $tmp_inherited_linker_flag";;
+	    esac
+	  done
+	fi
+	dependency_libs=`$ECHO " $dependency_libs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
+	if test "$linkmode,$pass" = "lib,link" ||
+	   test "$linkmode,$pass" = "prog,scan" ||
+	   { test "$linkmode" != prog && test "$linkmode" != lib; }; then
+	  test -n "$dlopen" && func_append dlfiles " $dlopen"
+	  test -n "$dlpreopen" && func_append dlprefiles " $dlpreopen"
+	fi
+
+	if test "$pass" = conv; then
+	  # Only check for convenience libraries
+	  deplibs="$lib $deplibs"
+	  if test -z "$libdir"; then
+	    if test -z "$old_library"; then
+	      func_fatal_error "cannot find name of link library for \`$lib'"
+	    fi
+	    # It is a libtool convenience library, so add in its objects.
+	    func_append convenience " $ladir/$objdir/$old_library"
+	    func_append old_convenience " $ladir/$objdir/$old_library"
+	    tmp_libs=
+	    for deplib in $dependency_libs; do
+	      deplibs="$deplib $deplibs"
+	      if $opt_preserve_dup_deps ; then
+		case "$tmp_libs " in
+		*" $deplib "*) func_append specialdeplibs " $deplib" ;;
+		esac
+	      fi
+	      func_append tmp_libs " $deplib"
+	    done
+	  elif test "$linkmode" != prog && test "$linkmode" != lib; then
+	    func_fatal_error "\`$lib' is not a convenience library"
+	  fi
+	  continue
+	fi # $pass = conv
+
+
+	# Get the name of the library we link against.
+	linklib=
+	if test -n "$old_library" &&
+	   { test "$prefer_static_libs" = yes ||
+	     test "$prefer_static_libs,$installed" = "built,no"; }; then
+	  linklib=$old_library
+	else
+	  for l in $old_library $library_names; do
+	    linklib="$l"
+	  done
+	fi
+	if test -z "$linklib"; then
+	  func_fatal_error "cannot find name of link library for \`$lib'"
+	fi
+
+	# This library was specified with -dlopen.
+	if test "$pass" = dlopen; then
+	  if test -z "$libdir"; then
+	    func_fatal_error "cannot -dlopen a convenience library: \`$lib'"
+	  fi
+	  if test -z "$dlname" ||
+	     test "$dlopen_support" != yes ||
+	     test "$build_libtool_libs" = no; then
+	    # If there is no dlname, no dlopen support or we're linking
+	    # statically, we need to preload.  We also need to preload any
+	    # dependent libraries so libltdl's deplib preloader doesn't
+	    # bomb out in the load deplibs phase.
+	    func_append dlprefiles " $lib $dependency_libs"
+	  else
+	    func_append newdlfiles " $lib"
+	  fi
+	  continue
+	fi # $pass = dlopen
+
+	# We need an absolute path.
+	case $ladir in
+	[\\/]* | [A-Za-z]:[\\/]*) abs_ladir="$ladir" ;;
+	*)
+	  abs_ladir=`cd "$ladir" && pwd`
+	  if test -z "$abs_ladir"; then
+	    func_warning "cannot determine absolute directory name of \`$ladir'"
+	    func_warning "passing it literally to the linker, although it might fail"
+	    abs_ladir="$ladir"
+	  fi
+	  ;;
+	esac
+	func_basename "$lib"
+	laname="$func_basename_result"
+
+	# Find the relevant object directory and library name.
+	if test "X$installed" = Xyes; then
+	  if test ! -f "$lt_sysroot$libdir/$linklib" && test -f "$abs_ladir/$linklib"; then
+	    func_warning "library \`$lib' was moved."
+	    dir="$ladir"
+	    absdir="$abs_ladir"
+	    libdir="$abs_ladir"
+	  else
+	    dir="$lt_sysroot$libdir"
+	    absdir="$lt_sysroot$libdir"
+	  fi
+	  test "X$hardcode_automatic" = Xyes && avoidtemprpath=yes
+	else
+	  if test ! -f "$ladir/$objdir/$linklib" && test -f "$abs_ladir/$linklib"; then
+	    dir="$ladir"
+	    absdir="$abs_ladir"
+	    # Remove this search path later
+	    func_append notinst_path " $abs_ladir"
+	  else
+	    dir="$ladir/$objdir"
+	    absdir="$abs_ladir/$objdir"
+	    # Remove this search path later
+	    func_append notinst_path " $abs_ladir"
+	  fi
+	fi # $installed = yes
+	func_stripname 'lib' '.la' "$laname"
+	name=$func_stripname_result
+
+	# This library was specified with -dlpreopen.
+	if test "$pass" = dlpreopen; then
+	  if test -z "$libdir" && test "$linkmode" = prog; then
+	    func_fatal_error "only libraries may -dlpreopen a convenience library: \`$lib'"
+	  fi
+	  case "$host" in
+	    # special handling for platforms with PE-DLLs.
+	    *cygwin* | *mingw* | *cegcc* )
+	      # Linker will automatically link against shared library if both
+	      # static and shared are present.  Therefore, ensure we extract
+	      # symbols from the import library if a shared library is present
+	      # (otherwise, the dlopen module name will be incorrect).  We do
+	      # this by putting the import library name into $newdlprefiles.
+	      # We recover the dlopen module name by 'saving' the la file
+	      # name in a special purpose variable, and (later) extracting the
+	      # dlname from the la file.
+	      if test -n "$dlname"; then
+	        func_tr_sh "$dir/$linklib"
+	        eval "libfile_$func_tr_sh_result=\$abs_ladir/\$laname"
+	        func_append newdlprefiles " $dir/$linklib"
+	      else
+	        func_append newdlprefiles " $dir/$old_library"
+	        # Keep a list of preopened convenience libraries to check
+	        # that they are being used correctly in the link pass.
+	        test -z "$libdir" && \
+	          func_append dlpreconveniencelibs " $dir/$old_library"
+	      fi
+	    ;;
+	    * )
+	      # Prefer using a static library (so that no silly _DYNAMIC symbols
+	      # are required to link).
+	      if test -n "$old_library"; then
+	        func_append newdlprefiles " $dir/$old_library"
+	        # Keep a list of preopened convenience libraries to check
+	        # that they are being used correctly in the link pass.
+	        test -z "$libdir" && \
+	          func_append dlpreconveniencelibs " $dir/$old_library"
+	      # Otherwise, use the dlname, so that lt_dlopen finds it.
+	      elif test -n "$dlname"; then
+	        func_append newdlprefiles " $dir/$dlname"
+	      else
+	        func_append newdlprefiles " $dir/$linklib"
+	      fi
+	    ;;
+	  esac
+	fi # $pass = dlpreopen
+
+	if test -z "$libdir"; then
+	  # Link the convenience library
+	  if test "$linkmode" = lib; then
+	    deplibs="$dir/$old_library $deplibs"
+	  elif test "$linkmode,$pass" = "prog,link"; then
+	    compile_deplibs="$dir/$old_library $compile_deplibs"
+	    finalize_deplibs="$dir/$old_library $finalize_deplibs"
+	  else
+	    deplibs="$lib $deplibs" # used for prog,scan pass
+	  fi
+	  continue
+	fi
+
+
+	if test "$linkmode" = prog && test "$pass" != link; then
+	  func_append newlib_search_path " $ladir"
+	  deplibs="$lib $deplibs"
+
+	  linkalldeplibs=no
+	  if test "$link_all_deplibs" != no || test -z "$library_names" ||
+	     test "$build_libtool_libs" = no; then
+	    linkalldeplibs=yes
+	  fi
+
+	  tmp_libs=
+	  for deplib in $dependency_libs; do
+	    case $deplib in
+	    -L*) func_stripname '-L' '' "$deplib"
+	         func_resolve_sysroot "$func_stripname_result"
+	         func_append newlib_search_path " $func_resolve_sysroot_result"
+		 ;;
+	    esac
+	    # Need to link against all dependency_libs?
+	    if test "$linkalldeplibs" = yes; then
+	      deplibs="$deplib $deplibs"
+	    else
+	      # Need to hardcode shared library paths
+	      # or/and link against static libraries
+	      newdependency_libs="$deplib $newdependency_libs"
+	    fi
+	    if $opt_preserve_dup_deps ; then
+	      case "$tmp_libs " in
+	      *" $deplib "*) func_append specialdeplibs " $deplib" ;;
+	      esac
+	    fi
+	    func_append tmp_libs " $deplib"
+	  done # for deplib
+	  continue
+	fi # $linkmode = prog...
+
+	if test "$linkmode,$pass" = "prog,link"; then
+	  if test -n "$library_names" &&
+	     { { test "$prefer_static_libs" = no ||
+	         test "$prefer_static_libs,$installed" = "built,yes"; } ||
+	       test -z "$old_library"; }; then
+	    # We need to hardcode the library path
+	    if test -n "$shlibpath_var" && test -z "$avoidtemprpath" ; then
+	      # Make sure the rpath contains only unique directories.
+	      case "$temp_rpath:" in
+	      *"$absdir:"*) ;;
+	      *) func_append temp_rpath "$absdir:" ;;
+	      esac
+	    fi
+
+	    # Hardcode the library path.
+	    # Skip directories that are in the system default run-time
+	    # search path.
+	    case " $sys_lib_dlsearch_path " in
+	    *" $absdir "*) ;;
+	    *)
+	      case "$compile_rpath " in
+	      *" $absdir "*) ;;
+	      *) func_append compile_rpath " $absdir" ;;
+	      esac
+	      ;;
+	    esac
+	    case " $sys_lib_dlsearch_path " in
+	    *" $libdir "*) ;;
+	    *)
+	      case "$finalize_rpath " in
+	      *" $libdir "*) ;;
+	      *) func_append finalize_rpath " $libdir" ;;
+	      esac
+	      ;;
+	    esac
+	  fi # $linkmode,$pass = prog,link...
+
+	  if test "$alldeplibs" = yes &&
+	     { test "$deplibs_check_method" = pass_all ||
+	       { test "$build_libtool_libs" = yes &&
+		 test -n "$library_names"; }; }; then
+	    # We only need to search for static libraries
+	    continue
+	  fi
+	fi
+
+	link_static=no # Whether the deplib will be linked statically
+	use_static_libs=$prefer_static_libs
+	if test "$use_static_libs" = built && test "$installed" = yes; then
+	  use_static_libs=no
+	fi
+	if test -n "$library_names" &&
+	   { test "$use_static_libs" = no || test -z "$old_library"; }; then
+	  case $host in
+	  *cygwin* | *mingw* | *cegcc*)
+	      # No point in relinking DLLs because paths are not encoded
+	      func_append notinst_deplibs " $lib"
+	      need_relink=no
+	    ;;
+	  *)
+	    if test "$installed" = no; then
+	      func_append notinst_deplibs " $lib"
+	      need_relink=yes
+	    fi
+	    ;;
+	  esac
+	  # This is a shared library
+
+	  # Warn about portability, can't link against -module's on some
+	  # systems (darwin).  Don't bleat about dlopened modules though!
+	  dlopenmodule=""
+	  for dlpremoduletest in $dlprefiles; do
+	    if test "X$dlpremoduletest" = "X$lib"; then
+	      dlopenmodule="$dlpremoduletest"
+	      break
+	    fi
+	  done
+	  if test -z "$dlopenmodule" && test "$shouldnotlink" = yes && test "$pass" = link; then
+	    echo
+	    if test "$linkmode" = prog; then
+	      $ECHO "*** Warning: Linking the executable $output against the loadable module"
+	    else
+	      $ECHO "*** Warning: Linking the shared library $output against the loadable module"
+	    fi
+	    $ECHO "*** $linklib is not portable!"
+	  fi
+	  if test "$linkmode" = lib &&
+	     test "$hardcode_into_libs" = yes; then
+	    # Hardcode the library path.
+	    # Skip directories that are in the system default run-time
+	    # search path.
+	    case " $sys_lib_dlsearch_path " in
+	    *" $absdir "*) ;;
+	    *)
+	      case "$compile_rpath " in
+	      *" $absdir "*) ;;
+	      *) func_append compile_rpath " $absdir" ;;
+	      esac
+	      ;;
+	    esac
+	    case " $sys_lib_dlsearch_path " in
+	    *" $libdir "*) ;;
+	    *)
+	      case "$finalize_rpath " in
+	      *" $libdir "*) ;;
+	      *) func_append finalize_rpath " $libdir" ;;
+	      esac
+	      ;;
+	    esac
+	  fi
+
+	  if test -n "$old_archive_from_expsyms_cmds"; then
+	    # figure out the soname
+	    set dummy $library_names
+	    shift
+	    realname="$1"
+	    shift
+	    libname=`eval "\\$ECHO \"$libname_spec\""`
+	    # use dlname if we got it. it's perfectly good, no?
+	    if test -n "$dlname"; then
+	      soname="$dlname"
+	    elif test -n "$soname_spec"; then
+	      # bleh windows
+	      case $host in
+	      *cygwin* | mingw* | *cegcc*)
+	        func_arith $current - $age
+		major=$func_arith_result
+		versuffix="-$major"
+		;;
+	      esac
+	      eval soname=\"$soname_spec\"
+	    else
+	      soname="$realname"
+	    fi
+
+	    # Make a new name for the extract_expsyms_cmds to use
+	    soroot="$soname"
+	    func_basename "$soroot"
+	    soname="$func_basename_result"
+	    func_stripname 'lib' '.dll' "$soname"
+	    newlib=libimp-$func_stripname_result.a
+
+	    # If the library has no export list, then create one now
+	    if test -f "$output_objdir/$soname-def"; then :
+	    else
+	      func_verbose "extracting exported symbol list from \`$soname'"
+	      func_execute_cmds "$extract_expsyms_cmds" 'exit $?'
+	    fi
+
+	    # Create $newlib
+	    if test -f "$output_objdir/$newlib"; then :; else
+	      func_verbose "generating import library for \`$soname'"
+	      func_execute_cmds "$old_archive_from_expsyms_cmds" 'exit $?'
+	    fi
+	    # make sure the library variables are pointing to the new library
+	    dir=$output_objdir
+	    linklib=$newlib
+	  fi # test -n "$old_archive_from_expsyms_cmds"
+
+	  if test "$linkmode" = prog || test "$opt_mode" != relink; then
+	    add_shlibpath=
+	    add_dir=
+	    add=
+	    lib_linked=yes
+	    case $hardcode_action in
+	    immediate | unsupported)
+	      if test "$hardcode_direct" = no; then
+		add="$dir/$linklib"
+		case $host in
+		  *-*-sco3.2v5.0.[024]*) add_dir="-L$dir" ;;
+		  *-*-sysv4*uw2*) add_dir="-L$dir" ;;
+		  *-*-sysv5OpenUNIX* | *-*-sysv5UnixWare7.[01].[10]* | \
+		    *-*-unixware7*) add_dir="-L$dir" ;;
+		  *-*-darwin* )
+		    # if the lib is a (non-dlopened) module then we can not
+		    # link against it, someone is ignoring the earlier warnings
+		    if /usr/bin/file -L $add 2> /dev/null |
+			 $GREP ": [^:]* bundle" >/dev/null ; then
+		      if test "X$dlopenmodule" != "X$lib"; then
+			$ECHO "*** Warning: lib $linklib is a module, not a shared library"
+			if test -z "$old_library" ; then
+			  echo
+			  echo "*** And there doesn't seem to be a static archive available"
+			  echo "*** The link will probably fail, sorry"
+			else
+			  add="$dir/$old_library"
+			fi
+		      elif test -n "$old_library"; then
+			add="$dir/$old_library"
+		      fi
+		    fi
+		esac
+	      elif test "$hardcode_minus_L" = no; then
+		case $host in
+		*-*-sunos*) add_shlibpath="$dir" ;;
+		esac
+		add_dir="-L$dir"
+		add="-l$name"
+	      elif test "$hardcode_shlibpath_var" = no; then
+		add_shlibpath="$dir"
+		add="-l$name"
+	      else
+		lib_linked=no
+	      fi
+	      ;;
+	    relink)
+	      if test "$hardcode_direct" = yes &&
+	         test "$hardcode_direct_absolute" = no; then
+		add="$dir/$linklib"
+	      elif test "$hardcode_minus_L" = yes; then
+		add_dir="-L$absdir"
+		# Try looking first in the location we're being installed to.
+		if test -n "$inst_prefix_dir"; then
+		  case $libdir in
+		    [\\/]*)
+		      func_append add_dir " -L$inst_prefix_dir$libdir"
+		      ;;
+		  esac
+		fi
+		add="-l$name"
+	      elif test "$hardcode_shlibpath_var" = yes; then
+		add_shlibpath="$dir"
+		add="-l$name"
+	      else
+		lib_linked=no
+	      fi
+	      ;;
+	    *) lib_linked=no ;;
+	    esac
+
+	    if test "$lib_linked" != yes; then
+	      func_fatal_configuration "unsupported hardcode properties"
+	    fi
+
+	    if test -n "$add_shlibpath"; then
+	      case :$compile_shlibpath: in
+	      *":$add_shlibpath:"*) ;;
+	      *) func_append compile_shlibpath "$add_shlibpath:" ;;
+	      esac
+	    fi
+	    if test "$linkmode" = prog; then
+	      test -n "$add_dir" && compile_deplibs="$add_dir $compile_deplibs"
+	      test -n "$add" && compile_deplibs="$add $compile_deplibs"
+	    else
+	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
+	      test -n "$add" && deplibs="$add $deplibs"
+	      if test "$hardcode_direct" != yes &&
+		 test "$hardcode_minus_L" != yes &&
+		 test "$hardcode_shlibpath_var" = yes; then
+		case :$finalize_shlibpath: in
+		*":$libdir:"*) ;;
+		*) func_append finalize_shlibpath "$libdir:" ;;
+		esac
+	      fi
+	    fi
+	  fi
+
+	  if test "$linkmode" = prog || test "$opt_mode" = relink; then
+	    add_shlibpath=
+	    add_dir=
+	    add=
+	    # Finalize command for both is simple: just hardcode it.
+	    if test "$hardcode_direct" = yes &&
+	       test "$hardcode_direct_absolute" = no; then
+	      add="$libdir/$linklib"
+	    elif test "$hardcode_minus_L" = yes; then
+	      add_dir="-L$libdir"
+	      add="-l$name"
+	    elif test "$hardcode_shlibpath_var" = yes; then
+	      case :$finalize_shlibpath: in
+	      *":$libdir:"*) ;;
+	      *) func_append finalize_shlibpath "$libdir:" ;;
+	      esac
+	      add="-l$name"
+	    elif test "$hardcode_automatic" = yes; then
+	      if test -n "$inst_prefix_dir" &&
+		 test -f "$inst_prefix_dir$libdir/$linklib" ; then
+		add="$inst_prefix_dir$libdir/$linklib"
+	      else
+		add="$libdir/$linklib"
+	      fi
+	    else
+	      # We cannot seem to hardcode it, guess we'll fake it.
+	      add_dir="-L$libdir"
+	      # Try looking first in the location we're being installed to.
+	      if test -n "$inst_prefix_dir"; then
+		case $libdir in
+		  [\\/]*)
+		    func_append add_dir " -L$inst_prefix_dir$libdir"
+		    ;;
+		esac
+	      fi
+	      add="-l$name"
+	    fi
+
+	    if test "$linkmode" = prog; then
+	      test -n "$add_dir" && finalize_deplibs="$add_dir $finalize_deplibs"
+	      test -n "$add" && finalize_deplibs="$add $finalize_deplibs"
+	    else
+	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
+	      test -n "$add" && deplibs="$add $deplibs"
+	    fi
+	  fi
+	elif test "$linkmode" = prog; then
+	  # Here we assume that one of hardcode_direct or hardcode_minus_L
+	  # is not unsupported.  This is valid on all known static and
+	  # shared platforms.
+	  if test "$hardcode_direct" != unsupported; then
+	    test -n "$old_library" && linklib="$old_library"
+	    compile_deplibs="$dir/$linklib $compile_deplibs"
+	    finalize_deplibs="$dir/$linklib $finalize_deplibs"
+	  else
+	    compile_deplibs="-l$name -L$dir $compile_deplibs"
+	    finalize_deplibs="-l$name -L$dir $finalize_deplibs"
+	  fi
+	elif test "$build_libtool_libs" = yes; then
+	  # Not a shared library
+	  if test "$deplibs_check_method" != pass_all; then
+	    # We're trying link a shared library against a static one
+	    # but the system doesn't support it.
+
+	    # Just print a warning and add the library to dependency_libs so
+	    # that the program can be linked against the static library.
+	    echo
+	    $ECHO "*** Warning: This system can not link to static lib archive $lib."
+	    echo "*** I have the capability to make that library automatically link in when"
+	    echo "*** you link to this library.  But I can only do this if you have a"
+	    echo "*** shared version of the library, which you do not appear to have."
+	    if test "$module" = yes; then
+	      echo "*** But as you try to build a module library, libtool will still create "
+	      echo "*** a static module, that should work as long as the dlopening application"
+	      echo "*** is linked with the -dlopen flag to resolve symbols at runtime."
+	      if test -z "$global_symbol_pipe"; then
+		echo
+		echo "*** However, this would only work if libtool was able to extract symbol"
+		echo "*** lists from a program, using \`nm' or equivalent, but libtool could"
+		echo "*** not find such a program.  So, this module is probably useless."
+		echo "*** \`nm' from GNU binutils and a full rebuild may help."
+	      fi
+	      if test "$build_old_libs" = no; then
+		build_libtool_libs=module
+		build_old_libs=yes
+	      else
+		build_libtool_libs=no
+	      fi
+	    fi
+	  else
+	    deplibs="$dir/$old_library $deplibs"
+	    link_static=yes
+	  fi
+	fi # link shared/static library?
+
+	if test "$linkmode" = lib; then
+	  if test -n "$dependency_libs" &&
+	     { test "$hardcode_into_libs" != yes ||
+	       test "$build_old_libs" = yes ||
+	       test "$link_static" = yes; }; then
+	    # Extract -R from dependency_libs
+	    temp_deplibs=
+	    for libdir in $dependency_libs; do
+	      case $libdir in
+	      -R*) func_stripname '-R' '' "$libdir"
+	           temp_xrpath=$func_stripname_result
+		   case " $xrpath " in
+		   *" $temp_xrpath "*) ;;
+		   *) func_append xrpath " $temp_xrpath";;
+		   esac;;
+	      *) func_append temp_deplibs " $libdir";;
+	      esac
+	    done
+	    dependency_libs="$temp_deplibs"
+	  fi
+
+	  func_append newlib_search_path " $absdir"
+	  # Link against this library
+	  test "$link_static" = no && newdependency_libs="$abs_ladir/$laname $newdependency_libs"
+	  # ... and its dependency_libs
+	  tmp_libs=
+	  for deplib in $dependency_libs; do
+	    newdependency_libs="$deplib $newdependency_libs"
+	    case $deplib in
+              -L*) func_stripname '-L' '' "$deplib"
+                   func_resolve_sysroot "$func_stripname_result";;
+              *) func_resolve_sysroot "$deplib" ;;
+            esac
+	    if $opt_preserve_dup_deps ; then
+	      case "$tmp_libs " in
+	      *" $func_resolve_sysroot_result "*)
+                func_append specialdeplibs " $func_resolve_sysroot_result" ;;
+	      esac
+	    fi
+	    func_append tmp_libs " $func_resolve_sysroot_result"
+	  done
+
+	  if test "$link_all_deplibs" != no; then
+	    # Add the search paths of all dependency libraries
+	    for deplib in $dependency_libs; do
+	      path=
+	      case $deplib in
+	      -L*) path="$deplib" ;;
+	      *.la)
+	        func_resolve_sysroot "$deplib"
+	        deplib=$func_resolve_sysroot_result
+	        func_dirname "$deplib" "" "."
+		dir=$func_dirname_result
+		# We need an absolute path.
+		case $dir in
+		[\\/]* | [A-Za-z]:[\\/]*) absdir="$dir" ;;
+		*)
+		  absdir=`cd "$dir" && pwd`
+		  if test -z "$absdir"; then
+		    func_warning "cannot determine absolute directory name of \`$dir'"
+		    absdir="$dir"
+		  fi
+		  ;;
+		esac
+		if $GREP "^installed=no" $deplib > /dev/null; then
+		case $host in
+		*-*-darwin*)
+		  depdepl=
+		  eval deplibrary_names=`${SED} -n -e 's/^library_names=\(.*\)$/\1/p' $deplib`
+		  if test -n "$deplibrary_names" ; then
+		    for tmp in $deplibrary_names ; do
+		      depdepl=$tmp
+		    done
+		    if test -f "$absdir/$objdir/$depdepl" ; then
+		      depdepl="$absdir/$objdir/$depdepl"
+		      darwin_install_name=`${OTOOL} -L $depdepl | awk '{if (NR == 2) {print $1;exit}}'`
+                      if test -z "$darwin_install_name"; then
+                          darwin_install_name=`${OTOOL64} -L $depdepl  | awk '{if (NR == 2) {print $1;exit}}'`
+                      fi
+		      func_append compiler_flags " ${wl}-dylib_file ${wl}${darwin_install_name}:${depdepl}"
+		      func_append linker_flags " -dylib_file ${darwin_install_name}:${depdepl}"
+		      path=
+		    fi
+		  fi
+		  ;;
+		*)
+		  path="-L$absdir/$objdir"
+		  ;;
+		esac
+		else
+		  eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $deplib`
+		  test -z "$libdir" && \
+		    func_fatal_error "\`$deplib' is not a valid libtool archive"
+		  test "$absdir" != "$libdir" && \
+		    func_warning "\`$deplib' seems to be moved"
+
+		  path="-L$absdir"
+		fi
+		;;
+	      esac
+	      case " $deplibs " in
+	      *" $path "*) ;;
+	      *) deplibs="$path $deplibs" ;;
+	      esac
+	    done
+	  fi # link_all_deplibs != no
+	fi # linkmode = lib
+      done # for deplib in $libs
+      if test "$pass" = link; then
+	if test "$linkmode" = "prog"; then
+	  compile_deplibs="$new_inherited_linker_flags $compile_deplibs"
+	  finalize_deplibs="$new_inherited_linker_flags $finalize_deplibs"
+	else
+	  compiler_flags="$compiler_flags "`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
+	fi
+      fi
+      dependency_libs="$newdependency_libs"
+      if test "$pass" = dlpreopen; then
+	# Link the dlpreopened libraries before other libraries
+	for deplib in $save_deplibs; do
+	  deplibs="$deplib $deplibs"
+	done
+      fi
+      if test "$pass" != dlopen; then
+	if test "$pass" != conv; then
+	  # Make sure lib_search_path contains only unique directories.
+	  lib_search_path=
+	  for dir in $newlib_search_path; do
+	    case "$lib_search_path " in
+	    *" $dir "*) ;;
+	    *) func_append lib_search_path " $dir" ;;
+	    esac
+	  done
+	  newlib_search_path=
+	fi
+
+	if test "$linkmode,$pass" != "prog,link"; then
+	  vars="deplibs"
+	else
+	  vars="compile_deplibs finalize_deplibs"
+	fi
+	for var in $vars dependency_libs; do
+	  # Add libraries to $var in reverse order
+	  eval tmp_libs=\"\$$var\"
+	  new_libs=
+	  for deplib in $tmp_libs; do
+	    # FIXME: Pedantically, this is the right thing to do, so
+	    #        that some nasty dependency loop isn't accidentally
+	    #        broken:
+	    #new_libs="$deplib $new_libs"
+	    # Pragmatically, this seems to cause very few problems in
+	    # practice:
+	    case $deplib in
+	    -L*) new_libs="$deplib $new_libs" ;;
+	    -R*) ;;
+	    *)
+	      # And here is the reason: when a library appears more
+	      # than once as an explicit dependence of a library, or
+	      # is implicitly linked in more than once by the
+	      # compiler, it is considered special, and multiple
+	      # occurrences thereof are not removed.  Compare this
+	      # with having the same library being listed as a
+	      # dependency of multiple other libraries: in this case,
+	      # we know (pedantically, we assume) the library does not
+	      # need to be listed more than once, so we keep only the
+	      # last copy.  This is not always right, but it is rare
+	      # enough that we require users that really mean to play
+	      # such unportable linking tricks to link the library
+	      # using -Wl,-lname, so that libtool does not consider it
+	      # for duplicate removal.
+	      case " $specialdeplibs " in
+	      *" $deplib "*) new_libs="$deplib $new_libs" ;;
+	      *)
+		case " $new_libs " in
+		*" $deplib "*) ;;
+		*) new_libs="$deplib $new_libs" ;;
+		esac
+		;;
+	      esac
+	      ;;
+	    esac
+	  done
+	  tmp_libs=
+	  for deplib in $new_libs; do
+	    case $deplib in
+	    -L*)
+	      case " $tmp_libs " in
+	      *" $deplib "*) ;;
+	      *) func_append tmp_libs " $deplib" ;;
+	      esac
+	      ;;
+	    *) func_append tmp_libs " $deplib" ;;
+	    esac
+	  done
+	  eval $var=\"$tmp_libs\"
+	done # for var
+      fi
+      # Last step: remove runtime libs from dependency_libs
+      # (they stay in deplibs)
+      tmp_libs=
+      for i in $dependency_libs ; do
+	case " $predeps $postdeps $compiler_lib_search_path " in
+	*" $i "*)
+	  i=""
+	  ;;
+	esac
+	if test -n "$i" ; then
+	  func_append tmp_libs " $i"
+	fi
+      done
+      dependency_libs=$tmp_libs
+    done # for pass
+    if test "$linkmode" = prog; then
+      dlfiles="$newdlfiles"
+    fi
+    if test "$linkmode" = prog || test "$linkmode" = lib; then
+      dlprefiles="$newdlprefiles"
+    fi
+
+    case $linkmode in
+    oldlib)
+      if test -n "$dlfiles$dlprefiles" || test "$dlself" != no; then
+	func_warning "\`-dlopen' is ignored for archives"
+      fi
+
+      case " $deplibs" in
+      *\ -l* | *\ -L*)
+	func_warning "\`-l' and \`-L' are ignored for archives" ;;
+      esac
+
+      test -n "$rpath" && \
+	func_warning "\`-rpath' is ignored for archives"
+
+      test -n "$xrpath" && \
+	func_warning "\`-R' is ignored for archives"
+
+      test -n "$vinfo" && \
+	func_warning "\`-version-info/-version-number' is ignored for archives"
+
+      test -n "$release" && \
+	func_warning "\`-release' is ignored for archives"
+
+      test -n "$export_symbols$export_symbols_regex" && \
+	func_warning "\`-export-symbols' is ignored for archives"
+
+      # Now set the variables for building old libraries.
+      build_libtool_libs=no
+      oldlibs="$output"
+      func_append objs "$old_deplibs"
+      ;;
+
+    lib)
+      # Make sure we only generate libraries of the form `libNAME.la'.
+      case $outputname in
+      lib*)
+	func_stripname 'lib' '.la' "$outputname"
+	name=$func_stripname_result
+	eval shared_ext=\"$shrext_cmds\"
+	eval libname=\"$libname_spec\"
+	;;
+      *)
+	test "$module" = no && \
+	  func_fatal_help "libtool library \`$output' must begin with \`lib'"
+
+	if test "$need_lib_prefix" != no; then
+	  # Add the "lib" prefix for modules if required
+	  func_stripname '' '.la' "$outputname"
+	  name=$func_stripname_result
+	  eval shared_ext=\"$shrext_cmds\"
+	  eval libname=\"$libname_spec\"
+	else
+	  func_stripname '' '.la' "$outputname"
+	  libname=$func_stripname_result
+	fi
+	;;
+      esac
+
+      if test -n "$objs"; then
+	if test "$deplibs_check_method" != pass_all; then
+	  func_fatal_error "cannot build libtool library \`$output' from non-libtool objects on this host:$objs"
+	else
+	  echo
+	  $ECHO "*** Warning: Linking the shared library $output against the non-libtool"
+	  $ECHO "*** objects $objs is not portable!"
+	  func_append libobjs " $objs"
+	fi
+      fi
+
+      test "$dlself" != no && \
+	func_warning "\`-dlopen self' is ignored for libtool libraries"
+
+      set dummy $rpath
+      shift
+      test "$#" -gt 1 && \
+	func_warning "ignoring multiple \`-rpath's for a libtool library"
+
+      install_libdir="$1"
+
+      oldlibs=
+      if test -z "$rpath"; then
+	if test "$build_libtool_libs" = yes; then
+	  # Building a libtool convenience library.
+	  # Some compilers have problems with a `.al' extension so
+	  # convenience libraries should have the same extension an
+	  # archive normally would.
+	  oldlibs="$output_objdir/$libname.$libext $oldlibs"
+	  build_libtool_libs=convenience
+	  build_old_libs=yes
+	fi
+
+	test -n "$vinfo" && \
+	  func_warning "\`-version-info/-version-number' is ignored for convenience libraries"
+
+	test -n "$release" && \
+	  func_warning "\`-release' is ignored for convenience libraries"
+      else
+
+	# Parse the version information argument.
+	save_ifs="$IFS"; IFS=':'
+	set dummy $vinfo 0 0 0
+	shift
+	IFS="$save_ifs"
+
+	test -n "$7" && \
+	  func_fatal_help "too many parameters to \`-version-info'"
+
+	# convert absolute version numbers to libtool ages
+	# this retains compatibility with .la files and attempts
+	# to make the code below a bit more comprehensible
+
+	case $vinfo_number in
+	yes)
+	  number_major="$1"
+	  number_minor="$2"
+	  number_revision="$3"
+	  #
+	  # There are really only two kinds -- those that
+	  # use the current revision as the major version
+	  # and those that subtract age and use age as
+	  # a minor version.  But, then there is irix
+	  # which has an extra 1 added just for fun
+	  #
+	  case $version_type in
+	  # correct linux to gnu/linux during the next big refactor
+	  darwin|linux|osf|windows|none)
+	    func_arith $number_major + $number_minor
+	    current=$func_arith_result
+	    age="$number_minor"
+	    revision="$number_revision"
+	    ;;
+	  freebsd-aout|freebsd-elf|qnx|sunos)
+	    current="$number_major"
+	    revision="$number_minor"
+	    age="0"
+	    ;;
+	  irix|nonstopux)
+	    func_arith $number_major + $number_minor
+	    current=$func_arith_result
+	    age="$number_minor"
+	    revision="$number_minor"
+	    lt_irix_increment=no
+	    ;;
+	  *)
+	    func_fatal_configuration "$modename: unknown library version type \`$version_type'"
+	    ;;
+	  esac
+	  ;;
+	no)
+	  current="$1"
+	  revision="$2"
+	  age="$3"
+	  ;;
+	esac
+
+	# Check that each of the things are valid numbers.
+	case $current in
+	0|[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]) ;;
+	*)
+	  func_error "CURRENT \`$current' must be a nonnegative integer"
+	  func_fatal_error "\`$vinfo' is not valid version information"
+	  ;;
+	esac
+
+	case $revision in
+	0|[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]) ;;
+	*)
+	  func_error "REVISION \`$revision' must be a nonnegative integer"
+	  func_fatal_error "\`$vinfo' is not valid version information"
+	  ;;
+	esac
+
+	case $age in
+	0|[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]) ;;
+	*)
+	  func_error "AGE \`$age' must be a nonnegative integer"
+	  func_fatal_error "\`$vinfo' is not valid version information"
+	  ;;
+	esac
+
+	if test "$age" -gt "$current"; then
+	  func_error "AGE \`$age' is greater than the current interface number \`$current'"
+	  func_fatal_error "\`$vinfo' is not valid version information"
+	fi
+
+	# Calculate the version variables.
+	major=
+	versuffix=
+	verstring=
+	case $version_type in
+	none) ;;
+
+	darwin)
+	  # Like Linux, but with the current version available in
+	  # verstring for coding it into the library header
+	  func_arith $current - $age
+	  major=.$func_arith_result
+	  versuffix="$major.$age.$revision"
+	  # Darwin ld doesn't like 0 for these options...
+	  func_arith $current + 1
+	  minor_current=$func_arith_result
+	  xlcverstring="${wl}-compatibility_version ${wl}$minor_current ${wl}-current_version ${wl}$minor_current.$revision"
+	  verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
+	  ;;
+
+	freebsd-aout)
+	  major=".$current"
+	  versuffix=".$current.$revision";
+	  ;;
+
+	freebsd-elf)
+	  major=".$current"
+	  versuffix=".$current"
+	  ;;
+
+	irix | nonstopux)
+	  if test "X$lt_irix_increment" = "Xno"; then
+	    func_arith $current - $age
+	  else
+	    func_arith $current - $age + 1
+	  fi
+	  major=$func_arith_result
+
+	  case $version_type in
+	    nonstopux) verstring_prefix=nonstopux ;;
+	    *)         verstring_prefix=sgi ;;
+	  esac
+	  verstring="$verstring_prefix$major.$revision"
+
+	  # Add in all the interfaces that we are compatible with.
+	  loop=$revision
+	  while test "$loop" -ne 0; do
+	    func_arith $revision - $loop
+	    iface=$func_arith_result
+	    func_arith $loop - 1
+	    loop=$func_arith_result
+	    verstring="$verstring_prefix$major.$iface:$verstring"
+	  done
+
+	  # Before this point, $major must not contain `.'.
+	  major=.$major
+	  versuffix="$major.$revision"
+	  ;;
+
+	linux) # correct to gnu/linux during the next big refactor
+	  func_arith $current - $age
+	  major=.$func_arith_result
+	  versuffix="$major.$age.$revision"
+	  ;;
+
+	osf)
+	  func_arith $current - $age
+	  major=.$func_arith_result
+	  versuffix=".$current.$age.$revision"
+	  verstring="$current.$age.$revision"
+
+	  # Add in all the interfaces that we are compatible with.
+	  loop=$age
+	  while test "$loop" -ne 0; do
+	    func_arith $current - $loop
+	    iface=$func_arith_result
+	    func_arith $loop - 1
+	    loop=$func_arith_result
+	    verstring="$verstring:${iface}.0"
+	  done
+
+	  # Make executables depend on our current version.
+	  func_append verstring ":${current}.0"
+	  ;;
+
+	qnx)
+	  major=".$current"
+	  versuffix=".$current"
+	  ;;
+
+	sunos)
+	  major=".$current"
+	  versuffix=".$current.$revision"
+	  ;;
+
+	windows)
+	  # Use '-' rather than '.', since we only want one
+	  # extension on DOS 8.3 filesystems.
+	  func_arith $current - $age
+	  major=$func_arith_result
+	  versuffix="-$major"
+	  ;;
+
+	*)
+	  func_fatal_configuration "unknown library version type \`$version_type'"
+	  ;;
+	esac
+
+	# Clear the version info if we defaulted, and they specified a release.
+	if test -z "$vinfo" && test -n "$release"; then
+	  major=
+	  case $version_type in
+	  darwin)
+	    # we can't check for "0.0" in archive_cmds due to quoting
+	    # problems, so we reset it completely
+	    verstring=
+	    ;;
+	  *)
+	    verstring="0.0"
+	    ;;
+	  esac
+	  if test "$need_version" = no; then
+	    versuffix=
+	  else
+	    versuffix=".0.0"
+	  fi
+	fi
+
+	# Remove version info from name if versioning should be avoided
+	if test "$avoid_version" = yes && test "$need_version" = no; then
+	  major=
+	  versuffix=
+	  verstring=""
+	fi
+
+	# Check to see if the archive will have undefined symbols.
+	if test "$allow_undefined" = yes; then
+	  if test "$allow_undefined_flag" = unsupported; then
+	    func_warning "undefined symbols not allowed in $host shared libraries"
+	    build_libtool_libs=no
+	    build_old_libs=yes
+	  fi
+	else
+	  # Don't allow undefined symbols.
+	  allow_undefined_flag="$no_undefined_flag"
+	fi
+
+      fi
+
+      func_generate_dlsyms "$libname" "$libname" "yes"
+      func_append libobjs " $symfileobj"
+      test "X$libobjs" = "X " && libobjs=
+
+      if test "$opt_mode" != relink; then
+	# Remove our outputs, but don't remove object files since they
+	# may have been created when compiling PIC objects.
+	removelist=
+	tempremovelist=`$ECHO "$output_objdir/*"`
+	for p in $tempremovelist; do
+	  case $p in
+	    *.$objext | *.gcno)
+	       ;;
+	    $output_objdir/$outputname | $output_objdir/$libname.* | $output_objdir/${libname}${release}.*)
+	       if test "X$precious_files_regex" != "X"; then
+		 if $ECHO "$p" | $EGREP -e "$precious_files_regex" >/dev/null 2>&1
+		 then
+		   continue
+		 fi
+	       fi
+	       func_append removelist " $p"
+	       ;;
+	    *) ;;
+	  esac
+	done
+	test -n "$removelist" && \
+	  func_show_eval "${RM}r \$removelist"
+      fi
+
+      # Now set the variables for building old libraries.
+      if test "$build_old_libs" = yes && test "$build_libtool_libs" != convenience ; then
+	func_append oldlibs " $output_objdir/$libname.$libext"
+
+	# Transform .lo files to .o files.
+	oldobjs="$objs "`$ECHO "$libobjs" | $SP2NL | $SED "/\.${libext}$/d; $lo2o" | $NL2SP`
+      fi
+
+      # Eliminate all temporary directories.
+      #for path in $notinst_path; do
+      #	lib_search_path=`$ECHO "$lib_search_path " | $SED "s% $path % %g"`
+      #	deplibs=`$ECHO "$deplibs " | $SED "s% -L$path % %g"`
+      #	dependency_libs=`$ECHO "$dependency_libs " | $SED "s% -L$path % %g"`
+      #done
+
+      if test -n "$xrpath"; then
+	# If the user specified any rpath flags, then add them.
+	temp_xrpath=
+	for libdir in $xrpath; do
+	  func_replace_sysroot "$libdir"
+	  func_append temp_xrpath " -R$func_replace_sysroot_result"
+	  case "$finalize_rpath " in
+	  *" $libdir "*) ;;
+	  *) func_append finalize_rpath " $libdir" ;;
+	  esac
+	done
+	if test "$hardcode_into_libs" != yes || test "$build_old_libs" = yes; then
+	  dependency_libs="$temp_xrpath $dependency_libs"
+	fi
+      fi
+
+      # Make sure dlfiles contains only unique files that won't be dlpreopened
+      old_dlfiles="$dlfiles"
+      dlfiles=
+      for lib in $old_dlfiles; do
+	case " $dlprefiles $dlfiles " in
+	*" $lib "*) ;;
+	*) func_append dlfiles " $lib" ;;
+	esac
+      done
+
+      # Make sure dlprefiles contains only unique files
+      old_dlprefiles="$dlprefiles"
+      dlprefiles=
+      for lib in $old_dlprefiles; do
+	case "$dlprefiles " in
+	*" $lib "*) ;;
+	*) func_append dlprefiles " $lib" ;;
+	esac
+      done
+
+      if test "$build_libtool_libs" = yes; then
+	if test -n "$rpath"; then
+	  case $host in
+	  *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-beos* | *-cegcc* | *-*-haiku*)
+	    # these systems don't actually have a c library (as such)!
+	    ;;
+	  *-*-rhapsody* | *-*-darwin1.[012])
+	    # Rhapsody C library is in the System framework
+	    func_append deplibs " System.ltframework"
+	    ;;
+	  *-*-netbsd*)
+	    # Don't link with libc until the a.out ld.so is fixed.
+	    ;;
+	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly*)
+	    # Do not include libc due to us having libc/libc_r.
+	    ;;
+	  *-*-sco3.2v5* | *-*-sco5v6*)
+	    # Causes problems with __ctype
+	    ;;
+	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
+	    # Compiler inserts libc in the correct place for threads to work
+	    ;;
+	  *)
+	    # Add libc to deplibs on all other systems if necessary.
+	    if test "$build_libtool_need_lc" = "yes"; then
+	      func_append deplibs " -lc"
+	    fi
+	    ;;
+	  esac
+	fi
+
+	# Transform deplibs into only deplibs that can be linked in shared.
+	name_save=$name
+	libname_save=$libname
+	release_save=$release
+	versuffix_save=$versuffix
+	major_save=$major
+	# I'm not sure if I'm treating the release correctly.  I think
+	# release should show up in the -l (ie -lgmp5) so we don't want to
+	# add it in twice.  Is that correct?
+	release=""
+	versuffix=""
+	major=""
+	newdeplibs=
+	droppeddeps=no
+	case $deplibs_check_method in
+	pass_all)
+	  # Don't check for shared/static.  Everything works.
+	  # This might be a little naive.  We might want to check
+	  # whether the library exists or not.  But this is on
+	  # osf3 & osf4 and I'm not really sure... Just
+	  # implementing what was already the behavior.
+	  newdeplibs=$deplibs
+	  ;;
+	test_compile)
+	  # This code stresses the "libraries are programs" paradigm to its
+	  # limits. Maybe even breaks it.  We compile a program, linking it
+	  # against the deplibs as a proxy for the library.  Then we can check
+	  # whether they linked in statically or dynamically with ldd.
+	  $opt_dry_run || $RM conftest.c
+	  cat > conftest.c <<EOF
+	  int main() { return 0; }
+EOF
+	  $opt_dry_run || $RM conftest
+	  if $LTCC $LTCFLAGS -o conftest conftest.c $deplibs; then
+	    ldd_output=`ldd conftest`
+	    for i in $deplibs; do
+	      case $i in
+	      -l*)
+		func_stripname -l '' "$i"
+		name=$func_stripname_result
+		if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then
+		  case " $predeps $postdeps " in
+		  *" $i "*)
+		    func_append newdeplibs " $i"
+		    i=""
+		    ;;
+		  esac
+		fi
+		if test -n "$i" ; then
+		  libname=`eval "\\$ECHO \"$libname_spec\""`
+		  deplib_matches=`eval "\\$ECHO \"$library_names_spec\""`
+		  set dummy $deplib_matches; shift
+		  deplib_match=$1
+		  if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0 ; then
+		    func_append newdeplibs " $i"
+		  else
+		    droppeddeps=yes
+		    echo
+		    $ECHO "*** Warning: dynamic linker does not accept needed library $i."
+		    echo "*** I have the capability to make that library automatically link in when"
+		    echo "*** you link to this library.  But I can only do this if you have a"
+		    echo "*** shared version of the library, which I believe you do not have"
+		    echo "*** because a test_compile did reveal that the linker did not use it for"
+		    echo "*** its dynamic dependency list that programs get resolved with at runtime."
+		  fi
+		fi
+		;;
+	      *)
+		func_append newdeplibs " $i"
+		;;
+	      esac
+	    done
+	  else
+	    # Error occurred in the first compile.  Let's try to salvage
+	    # the situation: Compile a separate program for each library.
+	    for i in $deplibs; do
+	      case $i in
+	      -l*)
+		func_stripname -l '' "$i"
+		name=$func_stripname_result
+		$opt_dry_run || $RM conftest
+		if $LTCC $LTCFLAGS -o conftest conftest.c $i; then
+		  ldd_output=`ldd conftest`
+		  if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then
+		    case " $predeps $postdeps " in
+		    *" $i "*)
+		      func_append newdeplibs " $i"
+		      i=""
+		      ;;
+		    esac
+		  fi
+		  if test -n "$i" ; then
+		    libname=`eval "\\$ECHO \"$libname_spec\""`
+		    deplib_matches=`eval "\\$ECHO \"$library_names_spec\""`
+		    set dummy $deplib_matches; shift
+		    deplib_match=$1
+		    if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0 ; then
+		      func_append newdeplibs " $i"
+		    else
+		      droppeddeps=yes
+		      echo
+		      $ECHO "*** Warning: dynamic linker does not accept needed library $i."
+		      echo "*** I have the capability to make that library automatically link in when"
+		      echo "*** you link to this library.  But I can only do this if you have a"
+		      echo "*** shared version of the library, which you do not appear to have"
+		      echo "*** because a test_compile did reveal that the linker did not use this one"
+		      echo "*** as a dynamic dependency that programs can get resolved with at runtime."
+		    fi
+		  fi
+		else
+		  droppeddeps=yes
+		  echo
+		  $ECHO "*** Warning!  Library $i is needed by this library but I was not able to"
+		  echo "*** make it link in!  You will probably need to install it or some"
+		  echo "*** library that it depends on before this library will be fully"
+		  echo "*** functional.  Installing it before continuing would be even better."
+		fi
+		;;
+	      *)
+		func_append newdeplibs " $i"
+		;;
+	      esac
+	    done
+	  fi
+	  ;;
+	file_magic*)
+	  set dummy $deplibs_check_method; shift
+	  file_magic_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
+	  for a_deplib in $deplibs; do
+	    case $a_deplib in
+	    -l*)
+	      func_stripname -l '' "$a_deplib"
+	      name=$func_stripname_result
+	      if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then
+		case " $predeps $postdeps " in
+		*" $a_deplib "*)
+		  func_append newdeplibs " $a_deplib"
+		  a_deplib=""
+		  ;;
+		esac
+	      fi
+	      if test -n "$a_deplib" ; then
+		libname=`eval "\\$ECHO \"$libname_spec\""`
+		if test -n "$file_magic_glob"; then
+		  libnameglob=`func_echo_all "$libname" | $SED -e $file_magic_glob`
+		else
+		  libnameglob=$libname
+		fi
+		test "$want_nocaseglob" = yes && nocaseglob=`shopt -p nocaseglob`
+		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
+		  if test "$want_nocaseglob" = yes; then
+		    shopt -s nocaseglob
+		    potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null`
+		    $nocaseglob
+		  else
+		    potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null`
+		  fi
+		  for potent_lib in $potential_libs; do
+		      # Follow soft links.
+		      if ls -lLd "$potent_lib" 2>/dev/null |
+			 $GREP " -> " >/dev/null; then
+			continue
+		      fi
+		      # The statement above tries to avoid entering an
+		      # endless loop below, in case of cyclic links.
+		      # We might still enter an endless loop, since a link
+		      # loop can be closed while we follow links,
+		      # but so what?
+		      potlib="$potent_lib"
+		      while test -h "$potlib" 2>/dev/null; do
+			potliblink=`ls -ld $potlib | ${SED} 's/.* -> //'`
+			case $potliblink in
+			[\\/]* | [A-Za-z]:[\\/]*) potlib="$potliblink";;
+			*) potlib=`$ECHO "$potlib" | $SED 's,[^/]*$,,'`"$potliblink";;
+			esac
+		      done
+		      if eval $file_magic_cmd \"\$potlib\" 2>/dev/null |
+			 $SED -e 10q |
+			 $EGREP "$file_magic_regex" > /dev/null; then
+			func_append newdeplibs " $a_deplib"
+			a_deplib=""
+			break 2
+		      fi
+		  done
+		done
+	      fi
+	      if test -n "$a_deplib" ; then
+		droppeddeps=yes
+		echo
+		$ECHO "*** Warning: linker path does not have real file for library $a_deplib."
+		echo "*** I have the capability to make that library automatically link in when"
+		echo "*** you link to this library.  But I can only do this if you have a"
+		echo "*** shared version of the library, which you do not appear to have"
+		echo "*** because I did check the linker path looking for a file starting"
+		if test -z "$potlib" ; then
+		  $ECHO "*** with $libname but no candidates were found. (...for file magic test)"
+		else
+		  $ECHO "*** with $libname and none of the candidates passed a file format test"
+		  $ECHO "*** using a file magic. Last file checked: $potlib"
+		fi
+	      fi
+	      ;;
+	    *)
+	      # Add a -L argument.
+	      func_append newdeplibs " $a_deplib"
+	      ;;
+	    esac
+	  done # Gone through all deplibs.
+	  ;;
+	match_pattern*)
+	  set dummy $deplibs_check_method; shift
+	  match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
+	  for a_deplib in $deplibs; do
+	    case $a_deplib in
+	    -l*)
+	      func_stripname -l '' "$a_deplib"
+	      name=$func_stripname_result
+	      if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then
+		case " $predeps $postdeps " in
+		*" $a_deplib "*)
+		  func_append newdeplibs " $a_deplib"
+		  a_deplib=""
+		  ;;
+		esac
+	      fi
+	      if test -n "$a_deplib" ; then
+		libname=`eval "\\$ECHO \"$libname_spec\""`
+		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
+		  potential_libs=`ls $i/$libname[.-]* 2>/dev/null`
+		  for potent_lib in $potential_libs; do
+		    potlib="$potent_lib" # see symlink-check above in file_magic test
+		    if eval "\$ECHO \"$potent_lib\"" 2>/dev/null | $SED 10q | \
+		       $EGREP "$match_pattern_regex" > /dev/null; then
+		      func_append newdeplibs " $a_deplib"
+		      a_deplib=""
+		      break 2
+		    fi
+		  done
+		done
+	      fi
+	      if test -n "$a_deplib" ; then
+		droppeddeps=yes
+		echo
+		$ECHO "*** Warning: linker path does not have real file for library $a_deplib."
+		echo "*** I have the capability to make that library automatically link in when"
+		echo "*** you link to this library.  But I can only do this if you have a"
+		echo "*** shared version of the library, which you do not appear to have"
+		echo "*** because I did check the linker path looking for a file starting"
+		if test -z "$potlib" ; then
+		  $ECHO "*** with $libname but no candidates were found. (...for regex pattern test)"
+		else
+		  $ECHO "*** with $libname and none of the candidates passed a file format test"
+		  $ECHO "*** using a regex pattern. Last file checked: $potlib"
+		fi
+	      fi
+	      ;;
+	    *)
+	      # Add a -L argument.
+	      func_append newdeplibs " $a_deplib"
+	      ;;
+	    esac
+	  done # Gone through all deplibs.
+	  ;;
+	none | unknown | *)
+	  newdeplibs=""
+	  tmp_deplibs=`$ECHO " $deplibs" | $SED 's/ -lc$//; s/ -[LR][^ ]*//g'`
+	  if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then
+	    for i in $predeps $postdeps ; do
+	      # can't use Xsed below, because $i might contain '/'
+	      tmp_deplibs=`$ECHO " $tmp_deplibs" | $SED "s,$i,,"`
+	    done
+	  fi
+	  case $tmp_deplibs in
+	  *[!\	\ ]*)
+	    echo
+	    if test "X$deplibs_check_method" = "Xnone"; then
+	      echo "*** Warning: inter-library dependencies are not supported in this platform."
+	    else
+	      echo "*** Warning: inter-library dependencies are not known to be supported."
+	    fi
+	    echo "*** All declared inter-library dependencies are being dropped."
+	    droppeddeps=yes
+	    ;;
+	  esac
+	  ;;
+	esac
+	versuffix=$versuffix_save
+	major=$major_save
+	release=$release_save
+	libname=$libname_save
+	name=$name_save
+
+	case $host in
+	*-*-rhapsody* | *-*-darwin1.[012])
+	  # On Rhapsody replace the C library with the System framework
+	  newdeplibs=`$ECHO " $newdeplibs" | $SED 's/ -lc / System.ltframework /'`
+	  ;;
+	esac
+
+	if test "$droppeddeps" = yes; then
+	  if test "$module" = yes; then
+	    echo
+	    echo "*** Warning: libtool could not satisfy all declared inter-library"
+	    $ECHO "*** dependencies of module $libname.  Therefore, libtool will create"
+	    echo "*** a static module, that should work as long as the dlopening"
+	    echo "*** application is linked with the -dlopen flag."
+	    if test -z "$global_symbol_pipe"; then
+	      echo
+	      echo "*** However, this would only work if libtool was able to extract symbol"
+	      echo "*** lists from a program, using \`nm' or equivalent, but libtool could"
+	      echo "*** not find such a program.  So, this module is probably useless."
+	      echo "*** \`nm' from GNU binutils and a full rebuild may help."
+	    fi
+	    if test "$build_old_libs" = no; then
+	      oldlibs="$output_objdir/$libname.$libext"
+	      build_libtool_libs=module
+	      build_old_libs=yes
+	    else
+	      build_libtool_libs=no
+	    fi
+	  else
+	    echo "*** The inter-library dependencies that have been dropped here will be"
+	    echo "*** automatically added whenever a program is linked with this library"
+	    echo "*** or is declared to -dlopen it."
+
+	    if test "$allow_undefined" = no; then
+	      echo
+	      echo "*** Since this library must not contain undefined symbols,"
+	      echo "*** because either the platform does not support them or"
+	      echo "*** it was explicitly requested with -no-undefined,"
+	      echo "*** libtool will only create a static version of it."
+	      if test "$build_old_libs" = no; then
+		oldlibs="$output_objdir/$libname.$libext"
+		build_libtool_libs=module
+		build_old_libs=yes
+	      else
+		build_libtool_libs=no
+	      fi
+	    fi
+	  fi
+	fi
+	# Done checking deplibs!
+	deplibs=$newdeplibs
+      fi
+      # Time to change all our "foo.ltframework" stuff back to "-framework foo"
+      case $host in
+	*-*-darwin*)
+	  newdeplibs=`$ECHO " $newdeplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
+	  new_inherited_linker_flags=`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
+	  deplibs=`$ECHO " $deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
+	  ;;
+      esac
+
+      # move library search paths that coincide with paths to not yet
+      # installed libraries to the beginning of the library search list
+      new_libs=
+      for path in $notinst_path; do
+	case " $new_libs " in
+	*" -L$path/$objdir "*) ;;
+	*)
+	  case " $deplibs " in
+	  *" -L$path/$objdir "*)
+	    func_append new_libs " -L$path/$objdir" ;;
+	  esac
+	  ;;
+	esac
+      done
+      for deplib in $deplibs; do
+	case $deplib in
+	-L*)
+	  case " $new_libs " in
+	  *" $deplib "*) ;;
+	  *) func_append new_libs " $deplib" ;;
+	  esac
+	  ;;
+	*) func_append new_libs " $deplib" ;;
+	esac
+      done
+      deplibs="$new_libs"
+
+      # All the library-specific variables (install_libdir is set above).
+      library_names=
+      old_library=
+      dlname=
+
+      # Test again, we may have decided not to build it any more
+      if test "$build_libtool_libs" = yes; then
+	# Remove ${wl} instances when linking with ld.
+	# FIXME: should test the right _cmds variable.
+	case $archive_cmds in
+	  *\$LD\ *) wl= ;;
+        esac
+	if test "$hardcode_into_libs" = yes; then
+	  # Hardcode the library paths
+	  hardcode_libdirs=
+	  dep_rpath=
+	  rpath="$finalize_rpath"
+	  test "$opt_mode" != relink && rpath="$compile_rpath$rpath"
+	  for libdir in $rpath; do
+	    if test -n "$hardcode_libdir_flag_spec"; then
+	      if test -n "$hardcode_libdir_separator"; then
+		func_replace_sysroot "$libdir"
+		libdir=$func_replace_sysroot_result
+		if test -z "$hardcode_libdirs"; then
+		  hardcode_libdirs="$libdir"
+		else
+		  # Just accumulate the unique libdirs.
+		  case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
+		  *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
+		    ;;
+		  *)
+		    func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
+		    ;;
+		  esac
+		fi
+	      else
+		eval flag=\"$hardcode_libdir_flag_spec\"
+		func_append dep_rpath " $flag"
+	      fi
+	    elif test -n "$runpath_var"; then
+	      case "$perm_rpath " in
+	      *" $libdir "*) ;;
+	      *) func_append perm_rpath " $libdir" ;;
+	      esac
+	    fi
+	  done
+	  # Substitute the hardcoded libdirs into the rpath.
+	  if test -n "$hardcode_libdir_separator" &&
+	     test -n "$hardcode_libdirs"; then
+	    libdir="$hardcode_libdirs"
+	    eval "dep_rpath=\"$hardcode_libdir_flag_spec\""
+	  fi
+	  if test -n "$runpath_var" && test -n "$perm_rpath"; then
+	    # We should set the runpath_var.
+	    rpath=
+	    for dir in $perm_rpath; do
+	      func_append rpath "$dir:"
+	    done
+	    eval "$runpath_var='$rpath\$$runpath_var'; export $runpath_var"
+	  fi
+	  test -n "$dep_rpath" && deplibs="$dep_rpath $deplibs"
+	fi
+
+	shlibpath="$finalize_shlibpath"
+	test "$opt_mode" != relink && shlibpath="$compile_shlibpath$shlibpath"
+	if test -n "$shlibpath"; then
+	  eval "$shlibpath_var='$shlibpath\$$shlibpath_var'; export $shlibpath_var"
+	fi
+
+	# Get the real and link names of the library.
+	eval shared_ext=\"$shrext_cmds\"
+	eval library_names=\"$library_names_spec\"
+	set dummy $library_names
+	shift
+	realname="$1"
+	shift
+
+	if test -n "$soname_spec"; then
+	  eval soname=\"$soname_spec\"
+	else
+	  soname="$realname"
+	fi
+	if test -z "$dlname"; then
+	  dlname=$soname
+	fi
+
+	lib="$output_objdir/$realname"
+	linknames=
+	for link
+	do
+	  func_append linknames " $link"
+	done
+
+	# Use standard objects if they are pic
+	test -z "$pic_flag" && libobjs=`$ECHO "$libobjs" | $SP2NL | $SED "$lo2o" | $NL2SP`
+	test "X$libobjs" = "X " && libobjs=
+
+	delfiles=
+	if test -n "$export_symbols" && test -n "$include_expsyms"; then
+	  $opt_dry_run || cp "$export_symbols" "$output_objdir/$libname.uexp"
+	  export_symbols="$output_objdir/$libname.uexp"
+	  func_append delfiles " $export_symbols"
+	fi
+
+	orig_export_symbols=
+	case $host_os in
+	cygwin* | mingw* | cegcc*)
+	  if test -n "$export_symbols" && test -z "$export_symbols_regex"; then
+	    # exporting using user supplied symfile
+	    if test "x`$SED 1q $export_symbols`" != xEXPORTS; then
+	      # and it's NOT already a .def file. Must figure out
+	      # which of the given symbols are data symbols and tag
+	      # them as such. So, trigger use of export_symbols_cmds.
+	      # export_symbols gets reassigned inside the "prepare
+	      # the list of exported symbols" if statement, so the
+	      # include_expsyms logic still works.
+	      orig_export_symbols="$export_symbols"
+	      export_symbols=
+	      always_export_symbols=yes
+	    fi
+	  fi
+	  ;;
+	esac
+
+	# Prepare the list of exported symbols
+	if test -z "$export_symbols"; then
+	  if test "$always_export_symbols" = yes || test -n "$export_symbols_regex"; then
+	    func_verbose "generating symbol list for \`$libname.la'"
+	    export_symbols="$output_objdir/$libname.exp"
+	    $opt_dry_run || $RM $export_symbols
+	    cmds=$export_symbols_cmds
+	    save_ifs="$IFS"; IFS='~'
+	    for cmd1 in $cmds; do
+	      IFS="$save_ifs"
+	      # Take the normal branch if the nm_file_list_spec branch
+	      # doesn't work or if tool conversion is not needed.
+	      case $nm_file_list_spec~$to_tool_file_cmd in
+		*~func_convert_file_noop | *~func_convert_file_msys_to_w32 | ~*)
+		  try_normal_branch=yes
+		  eval cmd=\"$cmd1\"
+		  func_len " $cmd"
+		  len=$func_len_result
+		  ;;
+		*)
+		  try_normal_branch=no
+		  ;;
+	      esac
+	      if test "$try_normal_branch" = yes \
+		 && { test "$len" -lt "$max_cmd_len" \
+		      || test "$max_cmd_len" -le -1; }
+	      then
+		func_show_eval "$cmd" 'exit $?'
+		skipped_export=false
+	      elif test -n "$nm_file_list_spec"; then
+		func_basename "$output"
+		output_la=$func_basename_result
+		save_libobjs=$libobjs
+		save_output=$output
+		output=${output_objdir}/${output_la}.nm
+		func_to_tool_file "$output"
+		libobjs=$nm_file_list_spec$func_to_tool_file_result
+		func_append delfiles " $output"
+		func_verbose "creating $NM input file list: $output"
+		for obj in $save_libobjs; do
+		  func_to_tool_file "$obj"
+		  $ECHO "$func_to_tool_file_result"
+		done > "$output"
+		eval cmd=\"$cmd1\"
+		func_show_eval "$cmd" 'exit $?'
+		output=$save_output
+		libobjs=$save_libobjs
+		skipped_export=false
+	      else
+		# The command line is too long to execute in one step.
+		func_verbose "using reloadable object file for export list..."
+		skipped_export=:
+		# Break out early, otherwise skipped_export may be
+		# set to false by a later but shorter cmd.
+		break
+	      fi
+	    done
+	    IFS="$save_ifs"
+	    if test -n "$export_symbols_regex" && test "X$skipped_export" != "X:"; then
+	      func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
+	      func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
+	    fi
+	  fi
+	fi
+
+	if test -n "$export_symbols" && test -n "$include_expsyms"; then
+	  tmp_export_symbols="$export_symbols"
+	  test -n "$orig_export_symbols" && tmp_export_symbols="$orig_export_symbols"
+	  $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"'
+	fi
+
+	if test "X$skipped_export" != "X:" && test -n "$orig_export_symbols"; then
+	  # The given exports_symbols file has to be filtered, so filter it.
+	  func_verbose "filter symbol list for \`$libname.la' to tag DATA exports"
+	  # FIXME: $output_objdir/$libname.filter potentially contains lots of
+	  # 's' commands which not all seds can handle. GNU sed should be fine
+	  # though. Also, the filter scales superlinearly with the number of
+	  # global variables. join(1) would be nice here, but unfortunately
+	  # isn't a blessed tool.
+	  $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
+	  func_append delfiles " $export_symbols $output_objdir/$libname.filter"
+	  export_symbols=$output_objdir/$libname.def
+	  $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
+	fi
+
+	tmp_deplibs=
+	for test_deplib in $deplibs; do
+	  case " $convenience " in
+	  *" $test_deplib "*) ;;
+	  *)
+	    func_append tmp_deplibs " $test_deplib"
+	    ;;
+	  esac
+	done
+	deplibs="$tmp_deplibs"
+
+	if test -n "$convenience"; then
+	  if test -n "$whole_archive_flag_spec" &&
+	    test "$compiler_needs_object" = yes &&
+	    test -z "$libobjs"; then
+	    # extract the archives, so we have objects to list.
+	    # TODO: could optimize this to just extract one archive.
+	    whole_archive_flag_spec=
+	  fi
+	  if test -n "$whole_archive_flag_spec"; then
+	    save_libobjs=$libobjs
+	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
+	    test "X$libobjs" = "X " && libobjs=
+	  else
+	    gentop="$output_objdir/${outputname}x"
+	    func_append generated " $gentop"
+
+	    func_extract_archives $gentop $convenience
+	    func_append libobjs " $func_extract_archives_result"
+	    test "X$libobjs" = "X " && libobjs=
+	  fi
+	fi
+
+	if test "$thread_safe" = yes && test -n "$thread_safe_flag_spec"; then
+	  eval flag=\"$thread_safe_flag_spec\"
+	  func_append linker_flags " $flag"
+	fi
+
+	# Make a backup of the uninstalled library when relinking
+	if test "$opt_mode" = relink; then
+	  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}U && $MV $realname ${realname}U)' || exit $?
+	fi
+
+	# Do each of the archive commands.
+	if test "$module" = yes && test -n "$module_cmds" ; then
+	  if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
+	    eval test_cmds=\"$module_expsym_cmds\"
+	    cmds=$module_expsym_cmds
+	  else
+	    eval test_cmds=\"$module_cmds\"
+	    cmds=$module_cmds
+	  fi
+	else
+	  if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
+	    eval test_cmds=\"$archive_expsym_cmds\"
+	    cmds=$archive_expsym_cmds
+	  else
+	    eval test_cmds=\"$archive_cmds\"
+	    cmds=$archive_cmds
+	  fi
+	fi
+
+	if test "X$skipped_export" != "X:" &&
+	   func_len " $test_cmds" &&
+	   len=$func_len_result &&
+	   test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
+	  :
+	else
+	  # The command line is too long to link in one step, link piecewise
+	  # or, if using GNU ld and skipped_export is not :, use a linker
+	  # script.
+
+	  # Save the value of $output and $libobjs because we want to
+	  # use them later.  If we have whole_archive_flag_spec, we
+	  # want to use save_libobjs as it was before
+	  # whole_archive_flag_spec was expanded, because we can't
+	  # assume the linker understands whole_archive_flag_spec.
+	  # This may have to be revisited, in case too many
+	  # convenience libraries get linked in and end up exceeding
+	  # the spec.
+	  if test -z "$convenience" || test -z "$whole_archive_flag_spec"; then
+	    save_libobjs=$libobjs
+	  fi
+	  save_output=$output
+	  func_basename "$output"
+	  output_la=$func_basename_result
+
+	  # Clear the reloadable object creation command queue and
+	  # initialize k to one.
+	  test_cmds=
+	  concat_cmds=
+	  objlist=
+	  last_robj=
+	  k=1
+
+	  if test -n "$save_libobjs" && test "X$skipped_export" != "X:" && test "$with_gnu_ld" = yes; then
+	    output=${output_objdir}/${output_la}.lnkscript
+	    func_verbose "creating GNU ld script: $output"
+	    echo 'INPUT (' > $output
+	    for obj in $save_libobjs
+	    do
+	      func_to_tool_file "$obj"
+	      $ECHO "$func_to_tool_file_result" >> $output
+	    done
+	    echo ')' >> $output
+	    func_append delfiles " $output"
+	    func_to_tool_file "$output"
+	    output=$func_to_tool_file_result
+	  elif test -n "$save_libobjs" && test "X$skipped_export" != "X:" && test "X$file_list_spec" != X; then
+	    output=${output_objdir}/${output_la}.lnk
+	    func_verbose "creating linker input file list: $output"
+	    : > $output
+	    set x $save_libobjs
+	    shift
+	    firstobj=
+	    if test "$compiler_needs_object" = yes; then
+	      firstobj="$1 "
+	      shift
+	    fi
+	    for obj
+	    do
+	      func_to_tool_file "$obj"
+	      $ECHO "$func_to_tool_file_result" >> $output
+	    done
+	    func_append delfiles " $output"
+	    func_to_tool_file "$output"
+	    output=$firstobj\"$file_list_spec$func_to_tool_file_result\"
+	  else
+	    if test -n "$save_libobjs"; then
+	      func_verbose "creating reloadable object files..."
+	      output=$output_objdir/$output_la-${k}.$objext
+	      eval test_cmds=\"$reload_cmds\"
+	      func_len " $test_cmds"
+	      len0=$func_len_result
+	      len=$len0
+
+	      # Loop over the list of objects to be linked.
+	      for obj in $save_libobjs
+	      do
+		func_len " $obj"
+		func_arith $len + $func_len_result
+		len=$func_arith_result
+		if test "X$objlist" = X ||
+		   test "$len" -lt "$max_cmd_len"; then
+		  func_append objlist " $obj"
+		else
+		  # The command $test_cmds is almost too long, add a
+		  # command to the queue.
+		  if test "$k" -eq 1 ; then
+		    # The first file doesn't have a previous command to add.
+		    reload_objs=$objlist
+		    eval concat_cmds=\"$reload_cmds\"
+		  else
+		    # All subsequent reloadable object files will link in
+		    # the last one created.
+		    reload_objs="$objlist $last_robj"
+		    eval concat_cmds=\"\$concat_cmds~$reload_cmds~\$RM $last_robj\"
+		  fi
+		  last_robj=$output_objdir/$output_la-${k}.$objext
+		  func_arith $k + 1
+		  k=$func_arith_result
+		  output=$output_objdir/$output_la-${k}.$objext
+		  objlist=" $obj"
+		  func_len " $last_robj"
+		  func_arith $len0 + $func_len_result
+		  len=$func_arith_result
+		fi
+	      done
+	      # Handle the remaining objects by creating one last
+	      # reloadable object file.  All subsequent reloadable object
+	      # files will link in the last one created.
+	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
+	      reload_objs="$objlist $last_robj"
+	      eval concat_cmds=\"\${concat_cmds}$reload_cmds\"
+	      if test -n "$last_robj"; then
+	        eval concat_cmds=\"\${concat_cmds}~\$RM $last_robj\"
+	      fi
+	      func_append delfiles " $output"
+
+	    else
+	      output=
+	    fi
+
+	    if ${skipped_export-false}; then
+	      func_verbose "generating symbol list for \`$libname.la'"
+	      export_symbols="$output_objdir/$libname.exp"
+	      $opt_dry_run || $RM $export_symbols
+	      libobjs=$output
+	      # Append the command to create the export file.
+	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
+	      eval concat_cmds=\"\$concat_cmds$export_symbols_cmds\"
+	      if test -n "$last_robj"; then
+		eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\"
+	      fi
+	    fi
+
+	    test -n "$save_libobjs" &&
+	      func_verbose "creating a temporary reloadable object file: $output"
+
+	    # Loop through the commands generated above and execute them.
+	    save_ifs="$IFS"; IFS='~'
+	    for cmd in $concat_cmds; do
+	      IFS="$save_ifs"
+	      $opt_silent || {
+		  func_quote_for_expand "$cmd"
+		  eval "func_echo $func_quote_for_expand_result"
+	      }
+	      $opt_dry_run || eval "$cmd" || {
+		lt_exit=$?
+
+		# Restore the uninstalled library and exit
+		if test "$opt_mode" = relink; then
+		  ( cd "$output_objdir" && \
+		    $RM "${realname}T" && \
+		    $MV "${realname}U" "$realname" )
+		fi
+
+		exit $lt_exit
+	      }
+	    done
+	    IFS="$save_ifs"
+
+	    if test -n "$export_symbols_regex" && ${skipped_export-false}; then
+	      func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
+	      func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
+	    fi
+	  fi
+
+          if ${skipped_export-false}; then
+	    if test -n "$export_symbols" && test -n "$include_expsyms"; then
+	      tmp_export_symbols="$export_symbols"
+	      test -n "$orig_export_symbols" && tmp_export_symbols="$orig_export_symbols"
+	      $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"'
+	    fi
+
+	    if test -n "$orig_export_symbols"; then
+	      # The given exports_symbols file has to be filtered, so filter it.
+	      func_verbose "filter symbol list for \`$libname.la' to tag DATA exports"
+	      # FIXME: $output_objdir/$libname.filter potentially contains lots of
+	      # 's' commands which not all seds can handle. GNU sed should be fine
+	      # though. Also, the filter scales superlinearly with the number of
+	      # global variables. join(1) would be nice here, but unfortunately
+	      # isn't a blessed tool.
+	      $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
+	      func_append delfiles " $export_symbols $output_objdir/$libname.filter"
+	      export_symbols=$output_objdir/$libname.def
+	      $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
+	    fi
+	  fi
+
+	  libobjs=$output
+	  # Restore the value of output.
+	  output=$save_output
+
+	  if test -n "$convenience" && test -n "$whole_archive_flag_spec"; then
+	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
+	    test "X$libobjs" = "X " && libobjs=
+	  fi
+	  # Expand the library linking commands again to reset the
+	  # value of $libobjs for piecewise linking.
+
+	  # Do each of the archive commands.
+	  if test "$module" = yes && test -n "$module_cmds" ; then
+	    if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
+	      cmds=$module_expsym_cmds
+	    else
+	      cmds=$module_cmds
+	    fi
+	  else
+	    if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
+	      cmds=$archive_expsym_cmds
+	    else
+	      cmds=$archive_cmds
+	    fi
+	  fi
+	fi
+
+	if test -n "$delfiles"; then
+	  # Append the command to remove temporary files to $cmds.
+	  eval cmds=\"\$cmds~\$RM $delfiles\"
+	fi
+
+	# Add any objects from preloaded convenience libraries
+	if test -n "$dlprefiles"; then
+	  gentop="$output_objdir/${outputname}x"
+	  func_append generated " $gentop"
+
+	  func_extract_archives $gentop $dlprefiles
+	  func_append libobjs " $func_extract_archives_result"
+	  test "X$libobjs" = "X " && libobjs=
+	fi
+
+	save_ifs="$IFS"; IFS='~'
+	for cmd in $cmds; do
+	  IFS="$save_ifs"
+	  eval cmd=\"$cmd\"
+	  $opt_silent || {
+	    func_quote_for_expand "$cmd"
+	    eval "func_echo $func_quote_for_expand_result"
+	  }
+	  $opt_dry_run || eval "$cmd" || {
+	    lt_exit=$?
+
+	    # Restore the uninstalled library and exit
+	    if test "$opt_mode" = relink; then
+	      ( cd "$output_objdir" && \
+	        $RM "${realname}T" && \
+		$MV "${realname}U" "$realname" )
+	    fi
+
+	    exit $lt_exit
+	  }
+	done
+	IFS="$save_ifs"
+
+	# Restore the uninstalled library and exit
+	if test "$opt_mode" = relink; then
+	  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}T && $MV $realname ${realname}T && $MV ${realname}U $realname)' || exit $?
+
+	  if test -n "$convenience"; then
+	    if test -z "$whole_archive_flag_spec"; then
+	      func_show_eval '${RM}r "$gentop"'
+	    fi
+	  fi
+
+	  exit $EXIT_SUCCESS
+	fi
+
+	# Create links to the real library.
+	for linkname in $linknames; do
+	  if test "$realname" != "$linkname"; then
+	    func_show_eval '(cd "$output_objdir" && $RM "$linkname" && $LN_S "$realname" "$linkname")' 'exit $?'
+	  fi
+	done
+
+	# If -module or -export-dynamic was specified, set the dlname.
+	if test "$module" = yes || test "$export_dynamic" = yes; then
+	  # On all known operating systems, these are identical.
+	  dlname="$soname"
+	fi
+      fi
+      ;;
+
+    obj)
+      if test -n "$dlfiles$dlprefiles" || test "$dlself" != no; then
+	func_warning "\`-dlopen' is ignored for objects"
+      fi
+
+      case " $deplibs" in
+      *\ -l* | *\ -L*)
+	func_warning "\`-l' and \`-L' are ignored for objects" ;;
+      esac
+
+      test -n "$rpath" && \
+	func_warning "\`-rpath' is ignored for objects"
+
+      test -n "$xrpath" && \
+	func_warning "\`-R' is ignored for objects"
+
+      test -n "$vinfo" && \
+	func_warning "\`-version-info' is ignored for objects"
+
+      test -n "$release" && \
+	func_warning "\`-release' is ignored for objects"
+
+      case $output in
+      *.lo)
+	test -n "$objs$old_deplibs" && \
+	  func_fatal_error "cannot build library object \`$output' from non-libtool objects"
+
+	libobj=$output
+	func_lo2o "$libobj"
+	obj=$func_lo2o_result
+	;;
+      *)
+	libobj=
+	obj="$output"
+	;;
+      esac
+
+      # Delete the old objects.
+      $opt_dry_run || $RM $obj $libobj
+
+      # Objects from convenience libraries.  This assumes
+      # single-version convenience libraries.  Whenever we create
+      # different ones for PIC/non-PIC, this we'll have to duplicate
+      # the extraction.
+      reload_conv_objs=
+      gentop=
+      # reload_cmds runs $LD directly, so let us get rid of
+      # -Wl from whole_archive_flag_spec and hope we can get by with
+      # turning comma into space..
+      wl=
+
+      if test -n "$convenience"; then
+	if test -n "$whole_archive_flag_spec"; then
+	  eval tmp_whole_archive_flags=\"$whole_archive_flag_spec\"
+	  reload_conv_objs=$reload_objs\ `$ECHO "$tmp_whole_archive_flags" | $SED 's|,| |g'`
+	else
+	  gentop="$output_objdir/${obj}x"
+	  func_append generated " $gentop"
+
+	  func_extract_archives $gentop $convenience
+	  reload_conv_objs="$reload_objs $func_extract_archives_result"
+	fi
+      fi
+
+      # If we're not building shared, we need to use non_pic_objs
+      test "$build_libtool_libs" != yes && libobjs="$non_pic_objects"
+
+      # Create the old-style object.
+      reload_objs="$objs$old_deplibs "`$ECHO "$libobjs" | $SP2NL | $SED "/\.${libext}$/d; /\.lib$/d; $lo2o" | $NL2SP`" $reload_conv_objs" ### testsuite: skip nested quoting test
+
+      output="$obj"
+      func_execute_cmds "$reload_cmds" 'exit $?'
+
+      # Exit if we aren't doing a library object file.
+      if test -z "$libobj"; then
+	if test -n "$gentop"; then
+	  func_show_eval '${RM}r "$gentop"'
+	fi
+
+	exit $EXIT_SUCCESS
+      fi
+
+      if test "$build_libtool_libs" != yes; then
+	if test -n "$gentop"; then
+	  func_show_eval '${RM}r "$gentop"'
+	fi
+
+	# Create an invalid libtool object if no PIC, so that we don't
+	# accidentally link it into a program.
+	# $show "echo timestamp > $libobj"
+	# $opt_dry_run || eval "echo timestamp > $libobj" || exit $?
+	exit $EXIT_SUCCESS
+      fi
+
+      if test -n "$pic_flag" || test "$pic_mode" != default; then
+	# Only do commands if we really have different PIC objects.
+	reload_objs="$libobjs $reload_conv_objs"
+	output="$libobj"
+	func_execute_cmds "$reload_cmds" 'exit $?'
+      fi
+
+      if test -n "$gentop"; then
+	func_show_eval '${RM}r "$gentop"'
+      fi
+
+      exit $EXIT_SUCCESS
+      ;;
+
+    prog)
+      case $host in
+	*cygwin*) func_stripname '' '.exe' "$output"
+	          output=$func_stripname_result.exe;;
+      esac
+      test -n "$vinfo" && \
+	func_warning "\`-version-info' is ignored for programs"
+
+      test -n "$release" && \
+	func_warning "\`-release' is ignored for programs"
+
+      test "$preload" = yes \
+        && test "$dlopen_support" = unknown \
+	&& test "$dlopen_self" = unknown \
+	&& test "$dlopen_self_static" = unknown && \
+	  func_warning "\`LT_INIT([dlopen])' not used. Assuming no dlopen support."
+
+      case $host in
+      *-*-rhapsody* | *-*-darwin1.[012])
+	# On Rhapsody replace the C library is the System framework
+	compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's/ -lc / System.ltframework /'`
+	finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's/ -lc / System.ltframework /'`
+	;;
+      esac
+
+      case $host in
+      *-*-darwin*)
+	# Don't allow lazy linking, it breaks C++ global constructors
+	# But is supposedly fixed on 10.4 or later (yay!).
+	if test "$tagname" = CXX ; then
+	  case ${MACOSX_DEPLOYMENT_TARGET-10.0} in
+	    10.[0123])
+	      func_append compile_command " ${wl}-bind_at_load"
+	      func_append finalize_command " ${wl}-bind_at_load"
+	    ;;
+	  esac
+	fi
+	# Time to change all our "foo.ltframework" stuff back to "-framework foo"
+	compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
+	finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
+	;;
+      esac
+
+
+      # move library search paths that coincide with paths to not yet
+      # installed libraries to the beginning of the library search list
+      new_libs=
+      for path in $notinst_path; do
+	case " $new_libs " in
+	*" -L$path/$objdir "*) ;;
+	*)
+	  case " $compile_deplibs " in
+	  *" -L$path/$objdir "*)
+	    func_append new_libs " -L$path/$objdir" ;;
+	  esac
+	  ;;
+	esac
+      done
+      for deplib in $compile_deplibs; do
+	case $deplib in
+	-L*)
+	  case " $new_libs " in
+	  *" $deplib "*) ;;
+	  *) func_append new_libs " $deplib" ;;
+	  esac
+	  ;;
+	*) func_append new_libs " $deplib" ;;
+	esac
+      done
+      compile_deplibs="$new_libs"
+
+
+      func_append compile_command " $compile_deplibs"
+      func_append finalize_command " $finalize_deplibs"
+
+      if test -n "$rpath$xrpath"; then
+	# If the user specified any rpath flags, then add them.
+	for libdir in $rpath $xrpath; do
+	  # This is the magic to use -rpath.
+	  case "$finalize_rpath " in
+	  *" $libdir "*) ;;
+	  *) func_append finalize_rpath " $libdir" ;;
+	  esac
+	done
+      fi
+
+      # Now hardcode the library paths
+      rpath=
+      hardcode_libdirs=
+      for libdir in $compile_rpath $finalize_rpath; do
+	if test -n "$hardcode_libdir_flag_spec"; then
+	  if test -n "$hardcode_libdir_separator"; then
+	    if test -z "$hardcode_libdirs"; then
+	      hardcode_libdirs="$libdir"
+	    else
+	      # Just accumulate the unique libdirs.
+	      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
+	      *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
+		;;
+	      *)
+		func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
+		;;
+	      esac
+	    fi
+	  else
+	    eval flag=\"$hardcode_libdir_flag_spec\"
+	    func_append rpath " $flag"
+	  fi
+	elif test -n "$runpath_var"; then
+	  case "$perm_rpath " in
+	  *" $libdir "*) ;;
+	  *) func_append perm_rpath " $libdir" ;;
+	  esac
+	fi
+	case $host in
+	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
+	  testbindir=`${ECHO} "$libdir" | ${SED} -e 's*/lib$*/bin*'`
+	  case :$dllsearchpath: in
+	  *":$libdir:"*) ;;
+	  ::) dllsearchpath=$libdir;;
+	  *) func_append dllsearchpath ":$libdir";;
+	  esac
+	  case :$dllsearchpath: in
+	  *":$testbindir:"*) ;;
+	  ::) dllsearchpath=$testbindir;;
+	  *) func_append dllsearchpath ":$testbindir";;
+	  esac
+	  ;;
+	esac
+      done
+      # Substitute the hardcoded libdirs into the rpath.
+      if test -n "$hardcode_libdir_separator" &&
+	 test -n "$hardcode_libdirs"; then
+	libdir="$hardcode_libdirs"
+	eval rpath=\" $hardcode_libdir_flag_spec\"
+      fi
+      compile_rpath="$rpath"
+
+      rpath=
+      hardcode_libdirs=
+      for libdir in $finalize_rpath; do
+	if test -n "$hardcode_libdir_flag_spec"; then
+	  if test -n "$hardcode_libdir_separator"; then
+	    if test -z "$hardcode_libdirs"; then
+	      hardcode_libdirs="$libdir"
+	    else
+	      # Just accumulate the unique libdirs.
+	      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
+	      *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
+		;;
+	      *)
+		func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
+		;;
+	      esac
+	    fi
+	  else
+	    eval flag=\"$hardcode_libdir_flag_spec\"
+	    func_append rpath " $flag"
+	  fi
+	elif test -n "$runpath_var"; then
+	  case "$finalize_perm_rpath " in
+	  *" $libdir "*) ;;
+	  *) func_append finalize_perm_rpath " $libdir" ;;
+	  esac
+	fi
+      done
+      # Substitute the hardcoded libdirs into the rpath.
+      if test -n "$hardcode_libdir_separator" &&
+	 test -n "$hardcode_libdirs"; then
+	libdir="$hardcode_libdirs"
+	eval rpath=\" $hardcode_libdir_flag_spec\"
+      fi
+      finalize_rpath="$rpath"
+
+      if test -n "$libobjs" && test "$build_old_libs" = yes; then
+	# Transform all the library objects into standard objects.
+	compile_command=`$ECHO "$compile_command" | $SP2NL | $SED "$lo2o" | $NL2SP`
+	finalize_command=`$ECHO "$finalize_command" | $SP2NL | $SED "$lo2o" | $NL2SP`
+      fi
+
+      func_generate_dlsyms "$outputname" "@PROGRAM@" "no"
+
+      # template prelinking step
+      if test -n "$prelink_cmds"; then
+	func_execute_cmds "$prelink_cmds" 'exit $?'
+      fi
+
+      wrappers_required=yes
+      case $host in
+      *cegcc* | *mingw32ce*)
+        # Disable wrappers for cegcc and mingw32ce hosts, we are cross compiling anyway.
+        wrappers_required=no
+        ;;
+      *cygwin* | *mingw* )
+        if test "$build_libtool_libs" != yes; then
+          wrappers_required=no
+        fi
+        ;;
+      *)
+        if test "$need_relink" = no || test "$build_libtool_libs" != yes; then
+          wrappers_required=no
+        fi
+        ;;
+      esac
+      if test "$wrappers_required" = no; then
+	# Replace the output file specification.
+	compile_command=`$ECHO "$compile_command" | $SED 's%@OUTPUT@%'"$output"'%g'`
+	link_command="$compile_command$compile_rpath"
+
+	# We have no uninstalled library dependencies, so finalize right now.
+	exit_status=0
+	func_show_eval "$link_command" 'exit_status=$?'
+
+	if test -n "$postlink_cmds"; then
+	  func_to_tool_file "$output"
+	  postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
+	  func_execute_cmds "$postlink_cmds" 'exit $?'
+	fi
+
+	# Delete the generated files.
+	if test -f "$output_objdir/${outputname}S.${objext}"; then
+	  func_show_eval '$RM "$output_objdir/${outputname}S.${objext}"'
+	fi
+
+	exit $exit_status
+      fi
+
+      if test -n "$compile_shlibpath$finalize_shlibpath"; then
+	compile_command="$shlibpath_var=\"$compile_shlibpath$finalize_shlibpath\$$shlibpath_var\" $compile_command"
+      fi
+      if test -n "$finalize_shlibpath"; then
+	finalize_command="$shlibpath_var=\"$finalize_shlibpath\$$shlibpath_var\" $finalize_command"
+      fi
+
+      compile_var=
+      finalize_var=
+      if test -n "$runpath_var"; then
+	if test -n "$perm_rpath"; then
+	  # We should set the runpath_var.
+	  rpath=
+	  for dir in $perm_rpath; do
+	    func_append rpath "$dir:"
+	  done
+	  compile_var="$runpath_var=\"$rpath\$$runpath_var\" "
+	fi
+	if test -n "$finalize_perm_rpath"; then
+	  # We should set the runpath_var.
+	  rpath=
+	  for dir in $finalize_perm_rpath; do
+	    func_append rpath "$dir:"
+	  done
+	  finalize_var="$runpath_var=\"$rpath\$$runpath_var\" "
+	fi
+      fi
+
+      if test "$no_install" = yes; then
+	# We don't need to create a wrapper script.
+	link_command="$compile_var$compile_command$compile_rpath"
+	# Replace the output file specification.
+	link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output"'%g'`
+	# Delete the old output file.
+	$opt_dry_run || $RM $output
+	# Link the executable and exit
+	func_show_eval "$link_command" 'exit $?'
+
+	if test -n "$postlink_cmds"; then
+	  func_to_tool_file "$output"
+	  postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
+	  func_execute_cmds "$postlink_cmds" 'exit $?'
+	fi
+
+	exit $EXIT_SUCCESS
+      fi
+
+      if test "$hardcode_action" = relink; then
+	# Fast installation is not supported
+	link_command="$compile_var$compile_command$compile_rpath"
+	relink_command="$finalize_var$finalize_command$finalize_rpath"
+
+	func_warning "this platform does not like uninstalled shared libraries"
+	func_warning "\`$output' will be relinked during installation"
+      else
+	if test "$fast_install" != no; then
+	  link_command="$finalize_var$compile_command$finalize_rpath"
+	  if test "$fast_install" = yes; then
+	    relink_command=`$ECHO "$compile_var$compile_command$compile_rpath" | $SED 's%@OUTPUT@%\$progdir/\$file%g'`
+	  else
+	    # fast_install is set to needless
+	    relink_command=
+	  fi
+	else
+	  link_command="$compile_var$compile_command$compile_rpath"
+	  relink_command="$finalize_var$finalize_command$finalize_rpath"
+	fi
+      fi
+
+      # Replace the output file specification.
+      link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output_objdir/$outputname"'%g'`
+
+      # Delete the old output files.
+      $opt_dry_run || $RM $output $output_objdir/$outputname $output_objdir/lt-$outputname
+
+      func_show_eval "$link_command" 'exit $?'
+
+      if test -n "$postlink_cmds"; then
+	func_to_tool_file "$output_objdir/$outputname"
+	postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output_objdir/$outputname"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
+	func_execute_cmds "$postlink_cmds" 'exit $?'
+      fi
+
+      # Now create the wrapper script.
+      func_verbose "creating $output"
+
+      # Quote the relink command for shipping.
+      if test -n "$relink_command"; then
+	# Preserve any variables that may affect compiler behavior
+	for var in $variables_saved_for_relink; do
+	  if eval test -z \"\${$var+set}\"; then
+	    relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
+	  elif eval var_value=\$$var; test -z "$var_value"; then
+	    relink_command="$var=; export $var; $relink_command"
+	  else
+	    func_quote_for_eval "$var_value"
+	    relink_command="$var=$func_quote_for_eval_result; export $var; $relink_command"
+	  fi
+	done
+	relink_command="(cd `pwd`; $relink_command)"
+	relink_command=`$ECHO "$relink_command" | $SED "$sed_quote_subst"`
+      fi
+
+      # Only actually do things if not in dry run mode.
+      $opt_dry_run || {
+	# win32 will think the script is a binary if it has
+	# a .exe suffix, so we strip it off here.
+	case $output in
+	  *.exe) func_stripname '' '.exe' "$output"
+	         output=$func_stripname_result ;;
+	esac
+	# test for cygwin because mv fails w/o .exe extensions
+	case $host in
+	  *cygwin*)
+	    exeext=.exe
+	    func_stripname '' '.exe' "$outputname"
+	    outputname=$func_stripname_result ;;
+	  *) exeext= ;;
+	esac
+	case $host in
+	  *cygwin* | *mingw* )
+	    func_dirname_and_basename "$output" "" "."
+	    output_name=$func_basename_result
+	    output_path=$func_dirname_result
+	    cwrappersource="$output_path/$objdir/lt-$output_name.c"
+	    cwrapper="$output_path/$output_name.exe"
+	    $RM $cwrappersource $cwrapper
+	    trap "$RM $cwrappersource $cwrapper; exit $EXIT_FAILURE" 1 2 15
+
+	    func_emit_cwrapperexe_src > $cwrappersource
+
+	    # The wrapper executable is built using the $host compiler,
+	    # because it contains $host paths and files. If cross-
+	    # compiling, it, like the target executable, must be
+	    # executed on the $host or under an emulation environment.
+	    $opt_dry_run || {
+	      $LTCC $LTCFLAGS -o $cwrapper $cwrappersource
+	      $STRIP $cwrapper
+	    }
+
+	    # Now, create the wrapper script for func_source use:
+	    func_ltwrapper_scriptname $cwrapper
+	    $RM $func_ltwrapper_scriptname_result
+	    trap "$RM $func_ltwrapper_scriptname_result; exit $EXIT_FAILURE" 1 2 15
+	    $opt_dry_run || {
+	      # note: this script will not be executed, so do not chmod.
+	      if test "x$build" = "x$host" ; then
+		$cwrapper --lt-dump-script > $func_ltwrapper_scriptname_result
+	      else
+		func_emit_wrapper no > $func_ltwrapper_scriptname_result
+	      fi
+	    }
+	  ;;
+	  * )
+	    $RM $output
+	    trap "$RM $output; exit $EXIT_FAILURE" 1 2 15
+
+	    func_emit_wrapper no > $output
+	    chmod +x $output
+	  ;;
+	esac
+      }
+      exit $EXIT_SUCCESS
+      ;;
+    esac
+
+    # See if we need to build an old-fashioned archive.
+    for oldlib in $oldlibs; do
+
+      if test "$build_libtool_libs" = convenience; then
+	oldobjs="$libobjs_save $symfileobj"
+	addlibs="$convenience"
+	build_libtool_libs=no
+      else
+	if test "$build_libtool_libs" = module; then
+	  oldobjs="$libobjs_save"
+	  build_libtool_libs=no
+	else
+	  oldobjs="$old_deplibs $non_pic_objects"
+	  if test "$preload" = yes && test -f "$symfileobj"; then
+	    func_append oldobjs " $symfileobj"
+	  fi
+	fi
+	addlibs="$old_convenience"
+      fi
+
+      if test -n "$addlibs"; then
+	gentop="$output_objdir/${outputname}x"
+	func_append generated " $gentop"
+
+	func_extract_archives $gentop $addlibs
+	func_append oldobjs " $func_extract_archives_result"
+      fi
+
+      # Do each command in the archive commands.
+      if test -n "$old_archive_from_new_cmds" && test "$build_libtool_libs" = yes; then
+	cmds=$old_archive_from_new_cmds
+      else
+
+	# Add any objects from preloaded convenience libraries
+	if test -n "$dlprefiles"; then
+	  gentop="$output_objdir/${outputname}x"
+	  func_append generated " $gentop"
+
+	  func_extract_archives $gentop $dlprefiles
+	  func_append oldobjs " $func_extract_archives_result"
+	fi
+
+	# POSIX demands no paths to be encoded in archives.  We have
+	# to avoid creating archives with duplicate basenames if we
+	# might have to extract them afterwards, e.g., when creating a
+	# static archive out of a convenience library, or when linking
+	# the entirety of a libtool archive into another (currently
+	# not supported by libtool).
+	if (for obj in $oldobjs
+	    do
+	      func_basename "$obj"
+	      $ECHO "$func_basename_result"
+	    done | sort | sort -uc >/dev/null 2>&1); then
+	  :
+	else
+	  echo "copying selected object files to avoid basename conflicts..."
+	  gentop="$output_objdir/${outputname}x"
+	  func_append generated " $gentop"
+	  func_mkdir_p "$gentop"
+	  save_oldobjs=$oldobjs
+	  oldobjs=
+	  counter=1
+	  for obj in $save_oldobjs
+	  do
+	    func_basename "$obj"
+	    objbase="$func_basename_result"
+	    case " $oldobjs " in
+	    " ") oldobjs=$obj ;;
+	    *[\ /]"$objbase "*)
+	      while :; do
+		# Make sure we don't pick an alternate name that also
+		# overlaps.
+		newobj=lt$counter-$objbase
+		func_arith $counter + 1
+		counter=$func_arith_result
+		case " $oldobjs " in
+		*[\ /]"$newobj "*) ;;
+		*) if test ! -f "$gentop/$newobj"; then break; fi ;;
+		esac
+	      done
+	      func_show_eval "ln $obj $gentop/$newobj || cp $obj $gentop/$newobj"
+	      func_append oldobjs " $gentop/$newobj"
+	      ;;
+	    *) func_append oldobjs " $obj" ;;
+	    esac
+	  done
+	fi
+	func_to_tool_file "$oldlib" func_convert_file_msys_to_w32
+	tool_oldlib=$func_to_tool_file_result
+	eval cmds=\"$old_archive_cmds\"
+
+	func_len " $cmds"
+	len=$func_len_result
+	if test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
+	  cmds=$old_archive_cmds
+	elif test -n "$archiver_list_spec"; then
+	  func_verbose "using command file archive linking..."
+	  for obj in $oldobjs
+	  do
+	    func_to_tool_file "$obj"
+	    $ECHO "$func_to_tool_file_result"
+	  done > $output_objdir/$libname.libcmd
+	  func_to_tool_file "$output_objdir/$libname.libcmd"
+	  oldobjs=" $archiver_list_spec$func_to_tool_file_result"
+	  cmds=$old_archive_cmds
+	else
+	  # the command line is too long to link in one step, link in parts
+	  func_verbose "using piecewise archive linking..."
+	  save_RANLIB=$RANLIB
+	  RANLIB=:
+	  objlist=
+	  concat_cmds=
+	  save_oldobjs=$oldobjs
+	  oldobjs=
+	  # Is there a better way of finding the last object in the list?
+	  for obj in $save_oldobjs
+	  do
+	    last_oldobj=$obj
+	  done
+	  eval test_cmds=\"$old_archive_cmds\"
+	  func_len " $test_cmds"
+	  len0=$func_len_result
+	  len=$len0
+	  for obj in $save_oldobjs
+	  do
+	    func_len " $obj"
+	    func_arith $len + $func_len_result
+	    len=$func_arith_result
+	    func_append objlist " $obj"
+	    if test "$len" -lt "$max_cmd_len"; then
+	      :
+	    else
+	      # the above command should be used before it gets too long
+	      oldobjs=$objlist
+	      if test "$obj" = "$last_oldobj" ; then
+		RANLIB=$save_RANLIB
+	      fi
+	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
+	      eval concat_cmds=\"\${concat_cmds}$old_archive_cmds\"
+	      objlist=
+	      len=$len0
+	    fi
+	  done
+	  RANLIB=$save_RANLIB
+	  oldobjs=$objlist
+	  if test "X$oldobjs" = "X" ; then
+	    eval cmds=\"\$concat_cmds\"
+	  else
+	    eval cmds=\"\$concat_cmds~\$old_archive_cmds\"
+	  fi
+	fi
+      fi
+      func_execute_cmds "$cmds" 'exit $?'
+    done
+
+    test -n "$generated" && \
+      func_show_eval "${RM}r$generated"
+
+    # Now create the libtool archive.
+    case $output in
+    *.la)
+      old_library=
+      test "$build_old_libs" = yes && old_library="$libname.$libext"
+      func_verbose "creating $output"
+
+      # Preserve any variables that may affect compiler behavior
+      for var in $variables_saved_for_relink; do
+	if eval test -z \"\${$var+set}\"; then
+	  relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
+	elif eval var_value=\$$var; test -z "$var_value"; then
+	  relink_command="$var=; export $var; $relink_command"
+	else
+	  func_quote_for_eval "$var_value"
+	  relink_command="$var=$func_quote_for_eval_result; export $var; $relink_command"
+	fi
+      done
+      # Quote the link command for shipping.
+      relink_command="(cd `pwd`; $SHELL $progpath $preserve_args --mode=relink $libtool_args @inst_prefix_dir@)"
+      relink_command=`$ECHO "$relink_command" | $SED "$sed_quote_subst"`
+      if test "$hardcode_automatic" = yes ; then
+	relink_command=
+      fi
+
+      # Only create the output if not a dry run.
+      $opt_dry_run || {
+	for installed in no yes; do
+	  if test "$installed" = yes; then
+	    if test -z "$install_libdir"; then
+	      break
+	    fi
+	    output="$output_objdir/$outputname"i
+	    # Replace all uninstalled libtool libraries with the installed ones
+	    newdependency_libs=
+	    for deplib in $dependency_libs; do
+	      case $deplib in
+	      *.la)
+		func_basename "$deplib"
+		name="$func_basename_result"
+		func_resolve_sysroot "$deplib"
+		eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $func_resolve_sysroot_result`
+		test -z "$libdir" && \
+		  func_fatal_error "\`$deplib' is not a valid libtool archive"
+		func_append newdependency_libs " ${lt_sysroot:+=}$libdir/$name"
+		;;
+	      -L*)
+		func_stripname -L '' "$deplib"
+		func_replace_sysroot "$func_stripname_result"
+		func_append newdependency_libs " -L$func_replace_sysroot_result"
+		;;
+	      -R*)
+		func_stripname -R '' "$deplib"
+		func_replace_sysroot "$func_stripname_result"
+		func_append newdependency_libs " -R$func_replace_sysroot_result"
+		;;
+	      *) func_append newdependency_libs " $deplib" ;;
+	      esac
+	    done
+	    dependency_libs="$newdependency_libs"
+	    newdlfiles=
+
+	    for lib in $dlfiles; do
+	      case $lib in
+	      *.la)
+	        func_basename "$lib"
+		name="$func_basename_result"
+		eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
+		test -z "$libdir" && \
+		  func_fatal_error "\`$lib' is not a valid libtool archive"
+		func_append newdlfiles " ${lt_sysroot:+=}$libdir/$name"
+		;;
+	      *) func_append newdlfiles " $lib" ;;
+	      esac
+	    done
+	    dlfiles="$newdlfiles"
+	    newdlprefiles=
+	    for lib in $dlprefiles; do
+	      case $lib in
+	      *.la)
+		# Only pass preopened files to the pseudo-archive (for
+		# eventual linking with the app. that links it) if we
+		# didn't already link the preopened objects directly into
+		# the library:
+		func_basename "$lib"
+		name="$func_basename_result"
+		eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
+		test -z "$libdir" && \
+		  func_fatal_error "\`$lib' is not a valid libtool archive"
+		func_append newdlprefiles " ${lt_sysroot:+=}$libdir/$name"
+		;;
+	      esac
+	    done
+	    dlprefiles="$newdlprefiles"
+	  else
+	    newdlfiles=
+	    for lib in $dlfiles; do
+	      case $lib in
+		[\\/]* | [A-Za-z]:[\\/]*) abs="$lib" ;;
+		*) abs=`pwd`"/$lib" ;;
+	      esac
+	      func_append newdlfiles " $abs"
+	    done
+	    dlfiles="$newdlfiles"
+	    newdlprefiles=
+	    for lib in $dlprefiles; do
+	      case $lib in
+		[\\/]* | [A-Za-z]:[\\/]*) abs="$lib" ;;
+		*) abs=`pwd`"/$lib" ;;
+	      esac
+	      func_append newdlprefiles " $abs"
+	    done
+	    dlprefiles="$newdlprefiles"
+	  fi
+	  $RM $output
+	  # place dlname in correct position for cygwin
+	  # In fact, it would be nice if we could use this code for all target
+	  # systems that can't hard-code library paths into their executables
+	  # and that have no shared library path variable independent of PATH,
+	  # but it turns out we can't easily determine that from inspecting
+	  # libtool variables, so we have to hard-code the OSs to which it
+	  # applies here; at the moment, that means platforms that use the PE
+	  # object format with DLL files.  See the long comment at the top of
+	  # tests/bindir.at for full details.
+	  tdlname=$dlname
+	  case $host,$output,$installed,$module,$dlname in
+	    *cygwin*,*lai,yes,no,*.dll | *mingw*,*lai,yes,no,*.dll | *cegcc*,*lai,yes,no,*.dll)
+	      # If a -bindir argument was supplied, place the dll there.
+	      if test "x$bindir" != x ;
+	      then
+		func_relative_path "$install_libdir" "$bindir"
+		tdlname=$func_relative_path_result$dlname
+	      else
+		# Otherwise fall back on heuristic.
+		tdlname=../bin/$dlname
+	      fi
+	      ;;
+	  esac
+	  $ECHO > $output "\
+# $outputname - a libtool library file
+# Generated by $PROGRAM (GNU $PACKAGE$TIMESTAMP) $VERSION
+#
+# Please DO NOT delete this file!
+# It is necessary for linking the library.
+
+# The name that we can dlopen(3).
+dlname='$tdlname'
+
+# Names of this library.
+library_names='$library_names'
+
+# The name of the static archive.
+old_library='$old_library'
+
+# Linker flags that can not go in dependency_libs.
+inherited_linker_flags='$new_inherited_linker_flags'
+
+# Libraries that this one depends upon.
+dependency_libs='$dependency_libs'
+
+# Names of additional weak libraries provided by this library
+weak_library_names='$weak_libs'
+
+# Version information for $libname.
+current=$current
+age=$age
+revision=$revision
+
+# Is this an already installed library?
+installed=$installed
+
+# Should we warn about portability when linking against -modules?
+shouldnotlink=$module
+
+# Files to dlopen/dlpreopen
+dlopen='$dlfiles'
+dlpreopen='$dlprefiles'
+
+# Directory that this library needs to be installed in:
+libdir='$install_libdir'"
+	  if test "$installed" = no && test "$need_relink" = yes; then
+	    $ECHO >> $output "\
+relink_command=\"$relink_command\""
+	  fi
+	done
+      }
+
+      # Do a symbolic link so that the libtool archive can be found in
+      # LD_LIBRARY_PATH before the program is installed.
+      func_show_eval '( cd "$output_objdir" && $RM "$outputname" && $LN_S "../$outputname" "$outputname" )' 'exit $?'
+      ;;
+    esac
+    exit $EXIT_SUCCESS
+}
+
+{ test "$opt_mode" = link || test "$opt_mode" = relink; } &&
+    func_mode_link ${1+"$@"}
+
+
+# func_mode_uninstall arg...
+func_mode_uninstall ()
+{
+    $opt_debug
+    RM="$nonopt"
+    files=
+    rmforce=
+    exit_status=0
+
+    # This variable tells wrapper scripts just to set variables rather
+    # than running their programs.
+    libtool_install_magic="$magic"
+
+    for arg
+    do
+      case $arg in
+      -f) func_append RM " $arg"; rmforce=yes ;;
+      -*) func_append RM " $arg" ;;
+      *) func_append files " $arg" ;;
+      esac
+    done
+
+    test -z "$RM" && \
+      func_fatal_help "you must specify an RM program"
+
+    rmdirs=
+
+    for file in $files; do
+      func_dirname "$file" "" "."
+      dir="$func_dirname_result"
+      if test "X$dir" = X.; then
+	odir="$objdir"
+      else
+	odir="$dir/$objdir"
+      fi
+      func_basename "$file"
+      name="$func_basename_result"
+      test "$opt_mode" = uninstall && odir="$dir"
+
+      # Remember odir for removal later, being careful to avoid duplicates
+      if test "$opt_mode" = clean; then
+	case " $rmdirs " in
+	  *" $odir "*) ;;
+	  *) func_append rmdirs " $odir" ;;
+	esac
+      fi
+
+      # Don't error if the file doesn't exist and rm -f was used.
+      if { test -L "$file"; } >/dev/null 2>&1 ||
+	 { test -h "$file"; } >/dev/null 2>&1 ||
+	 test -f "$file"; then
+	:
+      elif test -d "$file"; then
+	exit_status=1
+	continue
+      elif test "$rmforce" = yes; then
+	continue
+      fi
+
+      rmfiles="$file"
+
+      case $name in
+      *.la)
+	# Possibly a libtool archive, so verify it.
+	if func_lalib_p "$file"; then
+	  func_source $dir/$name
+
+	  # Delete the libtool libraries and symlinks.
+	  for n in $library_names; do
+	    func_append rmfiles " $odir/$n"
+	  done
+	  test -n "$old_library" && func_append rmfiles " $odir/$old_library"
+
+	  case "$opt_mode" in
+	  clean)
+	    case " $library_names " in
+	    *" $dlname "*) ;;
+	    *) test -n "$dlname" && func_append rmfiles " $odir/$dlname" ;;
+	    esac
+	    test -n "$libdir" && func_append rmfiles " $odir/$name $odir/${name}i"
+	    ;;
+	  uninstall)
+	    if test -n "$library_names"; then
+	      # Do each command in the postuninstall commands.
+	      func_execute_cmds "$postuninstall_cmds" 'test "$rmforce" = yes || exit_status=1'
+	    fi
+
+	    if test -n "$old_library"; then
+	      # Do each command in the old_postuninstall commands.
+	      func_execute_cmds "$old_postuninstall_cmds" 'test "$rmforce" = yes || exit_status=1'
+	    fi
+	    # FIXME: should reinstall the best remaining shared library.
+	    ;;
+	  esac
+	fi
+	;;
+
+      *.lo)
+	# Possibly a libtool object, so verify it.
+	if func_lalib_p "$file"; then
+
+	  # Read the .lo file
+	  func_source $dir/$name
+
+	  # Add PIC object to the list of files to remove.
+	  if test -n "$pic_object" &&
+	     test "$pic_object" != none; then
+	    func_append rmfiles " $dir/$pic_object"
+	  fi
+
+	  # Add non-PIC object to the list of files to remove.
+	  if test -n "$non_pic_object" &&
+	     test "$non_pic_object" != none; then
+	    func_append rmfiles " $dir/$non_pic_object"
+	  fi
+	fi
+	;;
+
+      *)
+	if test "$opt_mode" = clean ; then
+	  noexename=$name
+	  case $file in
+	  *.exe)
+	    func_stripname '' '.exe' "$file"
+	    file=$func_stripname_result
+	    func_stripname '' '.exe' "$name"
+	    noexename=$func_stripname_result
+	    # $file with .exe has already been added to rmfiles,
+	    # add $file without .exe
+	    func_append rmfiles " $file"
+	    ;;
+	  esac
+	  # Do a test to see if this is a libtool program.
+	  if func_ltwrapper_p "$file"; then
+	    if func_ltwrapper_executable_p "$file"; then
+	      func_ltwrapper_scriptname "$file"
+	      relink_command=
+	      func_source $func_ltwrapper_scriptname_result
+	      func_append rmfiles " $func_ltwrapper_scriptname_result"
+	    else
+	      relink_command=
+	      func_source $dir/$noexename
+	    fi
+
+	    # note $name still contains .exe if it was in $file originally
+	    # as does the version of $file that was added into $rmfiles
+	    func_append rmfiles " $odir/$name $odir/${name}S.${objext}"
+	    if test "$fast_install" = yes && test -n "$relink_command"; then
+	      func_append rmfiles " $odir/lt-$name"
+	    fi
+	    if test "X$noexename" != "X$name" ; then
+	      func_append rmfiles " $odir/lt-${noexename}.c"
+	    fi
+	  fi
+	fi
+	;;
+      esac
+      func_show_eval "$RM $rmfiles" 'exit_status=1'
+    done
+
+    # Try to remove the ${objdir}s in the directories where we deleted files
+    for dir in $rmdirs; do
+      if test -d "$dir"; then
+	func_show_eval "rmdir $dir >/dev/null 2>&1"
+      fi
+    done
+
+    exit $exit_status
+}
+
+{ test "$opt_mode" = uninstall || test "$opt_mode" = clean; } &&
+    func_mode_uninstall ${1+"$@"}
+
+test -z "$opt_mode" && {
+  help="$generic_help"
+  func_fatal_help "you must specify a MODE"
+}
+
+test -z "$exec_cmd" && \
+  func_fatal_help "invalid operation mode \`$opt_mode'"
+
+if test -n "$exec_cmd"; then
+  eval exec "$exec_cmd"
+  exit $EXIT_FAILURE
+fi
+
+exit $exit_status
+
+
+# The TAGs below are defined such that we never get into a situation
+# in which we disable both kinds of libraries.  Given conflicting
+# choices, we go for a static library, that is the most portable,
+# since we can't tell whether shared libraries were disabled because
+# the user asked for that or because the platform doesn't support
+# them.  This is particularly important on AIX, because we don't
+# support having both static and shared libraries enabled at the same
+# time on that platform, so we default to a shared-only configuration.
+# If a disable-shared tag is given, we'll fallback to a static-only
+# configuration.  But we'll never go from static-only to shared-only.
+
+# ### BEGIN LIBTOOL TAG CONFIG: disable-shared
+build_libtool_libs=no
+build_old_libs=yes
+# ### END LIBTOOL TAG CONFIG: disable-shared
+
+# ### BEGIN LIBTOOL TAG CONFIG: disable-static
+build_old_libs=`case $build_libtool_libs in yes) echo no;; *) echo yes;; esac`
+# ### END LIBTOOL TAG CONFIG: disable-static
+
+# Local Variables:
+# mode:shell-script
+# sh-indentation:2
+# End:
+# vi:sw=2
+
diff --git a/connman/missing b/connman/missing
new file mode 100755
index 0000000..db98974
--- /dev/null
+++ b/connman/missing
@@ -0,0 +1,215 @@
+#! /bin/sh
+# Common wrapper for a few potentially missing GNU programs.
+
+scriptversion=2013-10-28.13; # UTC
+
+# Copyright (C) 1996-2013 Free Software Foundation, Inc.
+# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+
+# 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, see <http://www.gnu.org/licenses/>.
+
+# As a special exception to the GNU General Public License, if you
+# distribute this file as part of a program that contains a
+# configuration script generated by Autoconf, you may include it under
+# the same distribution terms that you use for the rest of that program.
+
+if test $# -eq 0; then
+  echo 1>&2 "Try '$0 --help' for more information"
+  exit 1
+fi
+
+case $1 in
+
+  --is-lightweight)
+    # Used by our autoconf macros to check whether the available missing
+    # script is modern enough.
+    exit 0
+    ;;
+
+  --run)
+    # Back-compat with the calling convention used by older automake.
+    shift
+    ;;
+
+  -h|--h|--he|--hel|--help)
+    echo "\
+$0 [OPTION]... PROGRAM [ARGUMENT]...
+
+Run 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
+to PROGRAM being missing or too old.
+
+Options:
+  -h, --help      display this help and exit
+  -v, --version   output version information and exit
+
+Supported PROGRAM values:
+  aclocal   autoconf  autoheader   autom4te  automake  makeinfo
+  bison     yacc      flex         lex       help2man
+
+Version suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
+'g' are ignored when checking the name.
+
+Send bug reports to <bug-automake@gnu.org>."
+    exit $?
+    ;;
+
+  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
+    echo "missing $scriptversion (GNU Automake)"
+    exit $?
+    ;;
+
+  -*)
+    echo 1>&2 "$0: unknown '$1' option"
+    echo 1>&2 "Try '$0 --help' for more information"
+    exit 1
+    ;;
+
+esac
+
+# Run the given program, remember its exit status.
+"$@"; st=$?
+
+# If it succeeded, we are done.
+test $st -eq 0 && exit 0
+
+# Also exit now if we it failed (or wasn't found), and '--version' was
+# passed; such an option is passed most likely to detect whether the
+# program is present and works.
+case $2 in --version|--help) exit $st;; esac
+
+# Exit code 63 means version mismatch.  This often happens when the user
+# tries to use an ancient version of a tool on a file that requires a
+# minimum version.
+if test $st -eq 63; then
+  msg="probably too old"
+elif test $st -eq 127; then
+  # Program was missing.
+  msg="missing on your system"
+else
+  # Program was found and executed, but failed.  Give up.
+  exit $st
+fi
+
+perl_URL=http://www.perl.org/
+flex_URL=http://flex.sourceforge.net/
+gnu_software_URL=http://www.gnu.org/software
+
+program_details ()
+{
+  case $1 in
+    aclocal|automake)
+      echo "The '$1' program is part of the GNU Automake package:"
+      echo "<$gnu_software_URL/automake>"
+      echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
+      echo "<$gnu_software_URL/autoconf>"
+      echo "<$gnu_software_URL/m4/>"
+      echo "<$perl_URL>"
+      ;;
+    autoconf|autom4te|autoheader)
+      echo "The '$1' program is part of the GNU Autoconf package:"
+      echo "<$gnu_software_URL/autoconf/>"
+      echo "It also requires GNU m4 and Perl in order to run:"
+      echo "<$gnu_software_URL/m4/>"
+      echo "<$perl_URL>"
+      ;;
+  esac
+}
+
+give_advice ()
+{
+  # Normalize program name to check for.
+  normalized_program=`echo "$1" | sed '
+    s/^gnu-//; t
+    s/^gnu//; t
+    s/^g//; t'`
+
+  printf '%s\n' "'$1' is $msg."
+
+  configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
+  case $normalized_program in
+    autoconf*)
+      echo "You should only need it if you modified 'configure.ac',"
+      echo "or m4 files included by it."
+      program_details 'autoconf'
+      ;;
+    autoheader*)
+      echo "You should only need it if you modified 'acconfig.h' or"
+      echo "$configure_deps."
+      program_details 'autoheader'
+      ;;
+    automake*)
+      echo "You should only need it if you modified 'Makefile.am' or"
+      echo "$configure_deps."
+      program_details 'automake'
+      ;;
+    aclocal*)
+      echo "You should only need it if you modified 'acinclude.m4' or"
+      echo "$configure_deps."
+      program_details 'aclocal'
+      ;;
+   autom4te*)
+      echo "You might have modified some maintainer files that require"
+      echo "the 'autom4te' program to be rebuilt."
+      program_details 'autom4te'
+      ;;
+    bison*|yacc*)
+      echo "You should only need it if you modified a '.y' file."
+      echo "You may want to install the GNU Bison package:"
+      echo "<$gnu_software_URL/bison/>"
+      ;;
+    lex*|flex*)
+      echo "You should only need it if you modified a '.l' file."
+      echo "You may want to install the Fast Lexical Analyzer package:"
+      echo "<$flex_URL>"
+      ;;
+    help2man*)
+      echo "You should only need it if you modified a dependency" \
+           "of a man page."
+      echo "You may want to install the GNU Help2man package:"
+      echo "<$gnu_software_URL/help2man/>"
+    ;;
+    makeinfo*)
+      echo "You should only need it if you modified a '.texi' file, or"
+      echo "any other file indirectly affecting the aspect of the manual."
+      echo "You might want to install the Texinfo package:"
+      echo "<$gnu_software_URL/texinfo/>"
+      echo "The spurious makeinfo call might also be the consequence of"
+      echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
+      echo "want to install GNU make:"
+      echo "<$gnu_software_URL/make/>"
+      ;;
+    *)
+      echo "You might have modified some files without having the proper"
+      echo "tools for further handling them.  Check the 'README' file, it"
+      echo "often tells you about the needed prerequisites for installing"
+      echo "this package.  You may also peek at any GNU archive site, in"
+      echo "case some other package contains this missing '$1' program."
+      ;;
+  esac
+}
+
+give_advice "$1" | sed -e '1s/^/WARNING: /' \
+                       -e '2,$s/^/         /' >&2
+
+# Propagate the correct exit status (expected to be 127 for a program
+# not found, 63 for a program that failed due to version mismatch).
+exit $st
+
+# Local variables:
+# eval: (add-hook 'write-file-hooks 'time-stamp)
+# time-stamp-start: "scriptversion="
+# time-stamp-format: "%:y-%02m-%02d.%02H"
+# time-stamp-time-zone: "UTC"
+# time-stamp-end: "; # UTC"
+# End:
diff --git a/connman/plugins/bluetooth.c b/connman/plugins/bluetooth.c
new file mode 100644
index 0000000..f192c18
--- /dev/null
+++ b/connman/plugins/bluetooth.c
@@ -0,0 +1,992 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2013  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 <string.h>
+
+#define CONNMAN_API_SUBJECT_TO_CHANGE
+#include <connman/plugin.h>
+#include <connman/dbus.h>
+#include <connman/technology.h>
+#include <connman/device.h>
+#include <connman/inet.h>
+#include <gdbus.h>
+
+#define BLUEZ_SERVICE                   "org.bluez"
+#define BLUEZ_PATH                      "/org/bluez"
+#define BLUETOOTH_PAN_PANU              "00001115-0000-1000-8000-00805f9b34fb"
+#define BLUETOOTH_PAN_NAP               "00001116-0000-1000-8000-00805f9b34fb"
+#define BLUETOOTH_PAN_GN                "00001117-0000-1000-8000-00805f9b34fb"
+
+#define BLUETOOTH_ADDR_LEN              6
+
+static DBusConnection *connection;
+static GDBusClient *client;
+static GHashTable *devices;
+static GHashTable *networks;
+static bool bluetooth_tethering;
+
+struct bluetooth_pan {
+	struct connman_network *network;
+	GDBusProxy *btdevice_proxy;
+	GDBusProxy *btnetwork_proxy;
+	const char *pan_role;
+};
+
+static void address2ident(const char *address, char *ident)
+{
+	int i;
+
+	for (i = 0; i < BLUETOOTH_ADDR_LEN; i++) {
+		ident[i * 2] = address[i * 3];
+		ident[i * 2 + 1] = address[i * 3 + 1];
+	}
+	ident[BLUETOOTH_ADDR_LEN * 2] = '\0';
+}
+
+static const char *proxy_get_string(GDBusProxy *proxy, const char *property)
+{
+	DBusMessageIter iter;
+	const char *str;
+
+	if (!g_dbus_proxy_get_property(proxy, property, &iter))
+		return NULL;
+	dbus_message_iter_get_basic(&iter, &str);
+	return str;
+}
+
+static bool proxy_get_bool(GDBusProxy *proxy, const char *property)
+{
+	DBusMessageIter iter;
+	dbus_bool_t value;
+
+	if (!g_dbus_proxy_get_property(proxy, property, &iter))
+		return false;
+	dbus_message_iter_get_basic(&iter, &value);
+	return value;
+}
+
+static const char *proxy_get_role(GDBusProxy *proxy)
+{
+	DBusMessageIter iter, value;
+	const char *pref = NULL;
+
+	if (!proxy)
+		return NULL;
+
+        if (!g_dbus_proxy_get_property(proxy, "UUIDs", &iter))
+		return NULL;
+
+        dbus_message_iter_recurse(&iter, &value);
+        while (dbus_message_iter_get_arg_type(&value) == DBUS_TYPE_STRING) {
+                const char *uuid;
+
+		dbus_message_iter_get_basic(&value, &uuid);
+		/*
+		 * If a device offers more than one role, we prefer NAP,
+		 * then GN, then PANU.
+		 */
+		if (!strcmp(uuid, BLUETOOTH_PAN_NAP))
+			return "nap";
+		if (!strcmp(uuid, BLUETOOTH_PAN_GN))
+			pref = "gn";
+		if (!strcmp(uuid, BLUETOOTH_PAN_PANU) && !pref)
+			pref = "panu";
+
+                dbus_message_iter_next(&value);
+        }
+
+	return pref;
+}
+
+static int bluetooth_pan_probe(struct connman_network *network)
+{
+	GHashTableIter iter;
+	gpointer key, value;
+
+	DBG("network %p", network);
+
+	g_hash_table_iter_init(&iter, networks);
+
+	while (g_hash_table_iter_next(&iter, &key, &value)) {
+		struct bluetooth_pan *pan = value;
+
+		if (network == pan->network)
+			return 0;
+	}
+
+	return -EOPNOTSUPP;
+}
+
+static void pan_remove_nap(struct bluetooth_pan *pan)
+{
+	struct connman_device *device;
+	struct connman_network *network = pan->network;
+
+	DBG("network %p pan %p", pan->network, pan);
+
+	if (!network)
+		return;
+
+	pan->network = NULL;
+	connman_network_set_data(network, NULL);
+
+	device = connman_network_get_device(network);
+	if (device)
+		connman_device_remove_network(device, network);
+
+	connman_network_unref(network);
+}
+
+static void bluetooth_pan_remove(struct connman_network *network)
+{
+	struct bluetooth_pan *pan = connman_network_get_data(network);
+
+	DBG("network %p pan %p", network, pan);
+
+	connman_network_set_data(network, NULL);
+
+	if (pan)
+		pan_remove_nap(pan);
+}
+
+static bool pan_connect(struct bluetooth_pan *pan,
+		const char *iface)
+{
+	int index;
+
+	if (!iface) {
+		if (!proxy_get_bool(pan->btnetwork_proxy, "Connected"))
+			return false;
+		iface = proxy_get_string(pan->btnetwork_proxy, "Interface");
+	}
+
+	if (!iface)
+		return false;
+
+	index = connman_inet_ifindex(iface);
+	if (index < 0) {
+		DBG("network %p invalid index %d", pan->network, index);
+		return false;
+	}
+
+	connman_network_set_index(pan->network, index);
+	connman_network_set_connected(pan->network, true);
+
+	return true;
+}
+
+static void pan_connect_cb(DBusMessage *message, void *user_data)
+{
+	const char *path = user_data;
+	const char *iface = NULL;
+	struct bluetooth_pan *pan;
+	DBusMessageIter iter;
+
+	pan = g_hash_table_lookup(networks, path);
+	if (!pan) {
+		DBG("network already removed");
+		return;
+	}
+
+	if (dbus_message_get_type(message) == DBUS_MESSAGE_TYPE_ERROR) {
+		const char *dbus_error = dbus_message_get_error_name(message);
+
+		DBG("network %p %s", pan->network, dbus_error);
+
+		if (strcmp(dbus_error,
+				"org.bluez.Error.AlreadyConnected") != 0) {
+			connman_network_set_error(pan->network,
+				CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL);
+			return;
+		}
+	} else {
+		if (dbus_message_iter_init(message, &iter) &&
+				dbus_message_iter_get_arg_type(&iter) ==
+				DBUS_TYPE_STRING)
+			dbus_message_iter_get_basic(&iter, &iface);
+	}
+
+	DBG("network %p interface %s", pan->network, iface);
+
+	pan_connect(pan, iface);
+}
+
+static void pan_connect_append(DBusMessageIter *iter,
+		void *user_data)
+{
+	const char *path = user_data;
+	struct bluetooth_pan *pan;
+
+	pan = g_hash_table_lookup(networks, path);
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &pan->pan_role);
+}
+
+static int bluetooth_pan_connect(struct connman_network *network)
+{
+	struct bluetooth_pan *pan = connman_network_get_data(network);
+	const char *path;
+
+	DBG("network %p", network);
+
+	if (!pan)
+		return -EINVAL;
+
+	path = g_dbus_proxy_get_path(pan->btnetwork_proxy);
+
+	if (!g_dbus_proxy_method_call(pan->btnetwork_proxy, "Connect",
+			pan_connect_append, pan_connect_cb,
+			g_strdup(path), g_free))
+		return -EIO;
+
+	connman_network_set_associating(pan->network, true);
+
+	return -EINPROGRESS;
+}
+
+static void pan_disconnect_cb(DBusMessage *message, void *user_data)
+{
+	const char *path = user_data;
+	struct bluetooth_pan *pan;
+
+	pan = g_hash_table_lookup(networks, path);
+	if (!pan) {
+		DBG("network already removed");
+		return;
+	}
+
+	if (dbus_message_get_type(message) == DBUS_MESSAGE_TYPE_ERROR) {
+		const char *dbus_error = dbus_message_get_error_name(message);
+
+		DBG("network %p %s", pan->network, dbus_error);
+	}
+
+	DBG("network %p", pan->network);
+
+	connman_network_set_connected(pan->network, false);
+}
+
+static int bluetooth_pan_disconnect(struct connman_network *network, bool user_initiated)
+{
+	struct bluetooth_pan *pan = connman_network_get_data(network);
+	const char *path;
+
+	DBG("network %p", network);
+
+	if (!pan)
+		return -EINVAL;
+
+	path = g_dbus_proxy_get_path(pan->btnetwork_proxy);
+
+	if (!g_dbus_proxy_method_call(pan->btnetwork_proxy, "Disconnect",
+			NULL, pan_disconnect_cb, g_strdup(path), g_free))
+		return -EIO;
+
+       return -EINPROGRESS;
+}
+
+static void btnetwork_property_change(GDBusProxy *proxy, const char *name,
+		DBusMessageIter *iter, void *user_data)
+{
+	struct bluetooth_pan *pan;
+	dbus_bool_t connected;
+	bool proxy_connected, network_connected;
+
+	if (strcmp(name, "Connected") != 0)
+		return;
+
+	pan = g_hash_table_lookup(networks, g_dbus_proxy_get_path(proxy));
+	if (!pan || !pan->network)
+		return;
+
+	dbus_message_iter_get_basic(iter, &connected);
+	proxy_connected = connected;
+
+	network_connected = connman_network_get_connected(pan->network);
+
+	DBG("network %p network connected %d proxy connected %d",
+			pan->network, network_connected, proxy_connected);
+
+       if (network_connected != proxy_connected)
+               connman_network_set_connected(pan->network, proxy_connected);
+}
+
+static void pan_create_nap(struct bluetooth_pan *pan)
+{
+	struct connman_device *device;
+	const char* role;
+
+	role = proxy_get_role(pan->btdevice_proxy);
+	if (!role) {
+		pan_remove_nap(pan);
+		return;
+	}
+
+	device = g_hash_table_lookup(devices,
+			proxy_get_string(pan->btdevice_proxy, "Adapter"));
+
+	if (!device || !connman_device_get_powered(device))
+		return;
+
+	if (!pan->network) {
+		const char *address;
+		char ident[BLUETOOTH_ADDR_LEN * 2 + 1];
+		const char *name, *path;
+
+		address = proxy_get_string(pan->btdevice_proxy, "Address");
+		if (!address) {
+			connman_warn("Bluetooth device address missing");
+			return;
+		}
+
+		address2ident(address, ident);
+
+		pan->network = connman_network_create(ident,
+				CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN);
+
+		name = proxy_get_string(pan->btdevice_proxy, "Alias");
+		path = g_dbus_proxy_get_path(pan->btnetwork_proxy);
+
+		DBG("network %p %s %s", pan->network, path, name);
+
+		if (!pan->network) {
+			connman_warn("Bluetooth network %s creation failed",
+					path);
+			return;
+		}
+
+		connman_network_set_data(pan->network, pan);
+		connman_network_set_name(pan->network, name);
+		connman_network_set_group(pan->network, ident);
+	}
+
+	pan->pan_role = role;
+	connman_device_add_network(device, pan->network);
+
+	if (pan_connect(pan, NULL))
+		DBG("network %p already connected", pan->network);
+}
+
+static void btdevice_property_change(GDBusProxy *proxy, const char *name,
+		DBusMessageIter *iter, void *user_data)
+{
+	struct bluetooth_pan *pan;
+	const char *old_role = NULL;
+	const char *new_role;
+
+	if (strcmp(name, "UUIDs"))
+		return;
+
+	pan = g_hash_table_lookup(networks, g_dbus_proxy_get_path(proxy));
+	if (!pan)
+		return;
+
+	if (pan->network &&
+			connman_network_get_device(pan->network))
+		old_role = pan->pan_role;
+	new_role = proxy_get_role(pan->btdevice_proxy);
+
+	DBG("network %p network role %s proxy role %s", pan->network, old_role,
+			new_role);
+
+	if (old_role && new_role && !strcmp(old_role, new_role))
+		return;
+
+	pan_create_nap(pan);
+}
+
+static void pan_free(gpointer data)
+{
+	struct bluetooth_pan *pan = data;
+
+	if (pan->btnetwork_proxy) {
+		g_dbus_proxy_unref(pan->btnetwork_proxy);
+		pan->btnetwork_proxy = NULL;
+	}
+
+	if (pan->btdevice_proxy) {
+		g_dbus_proxy_unref(pan->btdevice_proxy);
+		pan->btdevice_proxy = NULL;
+	}
+
+	pan_remove_nap(pan);
+
+	g_free(pan);
+}
+
+static void pan_create(GDBusProxy *network_proxy)
+{
+	const char *path = g_dbus_proxy_get_path(network_proxy);
+	struct bluetooth_pan *pan;
+
+	pan = g_try_new0(struct bluetooth_pan, 1);
+
+	if (!pan) {
+		connman_error("Out of memory creating PAN NAP");
+		return;
+	}
+
+	g_hash_table_replace(networks, g_strdup(path), pan);
+
+	pan->btnetwork_proxy = g_dbus_proxy_ref(network_proxy);
+	pan->btdevice_proxy = g_dbus_proxy_new(client, path,
+			"org.bluez.Device1");
+
+	if (!pan->btdevice_proxy) {
+		connman_error("Cannot create BT PAN watcher %s", path);
+		g_hash_table_remove(networks, path);
+		return;
+	}
+
+	g_dbus_proxy_set_property_watch(pan->btnetwork_proxy,
+			btnetwork_property_change, NULL);
+
+	g_dbus_proxy_set_property_watch(pan->btdevice_proxy,
+			btdevice_property_change, NULL);
+
+	DBG("pan %p %s role %s", pan, path, proxy_get_role(pan->btdevice_proxy));
+
+	pan_create_nap(pan);
+}
+
+static struct connman_network_driver network_driver = {
+	.name		= "bluetooth",
+	.type           = CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN,
+	.probe          = bluetooth_pan_probe,
+	.remove         = bluetooth_pan_remove,
+	.connect        = bluetooth_pan_connect,
+	.disconnect     = bluetooth_pan_disconnect,
+};
+
+static void enable_device(struct connman_device *device, const char *path)
+{
+	GHashTableIter iter;
+	gpointer key, value;
+
+	DBG("device %p %s", device, path);
+	connman_device_set_powered(device, true);
+
+	g_hash_table_iter_init(&iter, networks);
+	while (g_hash_table_iter_next(&iter, &key, &value)) {
+		struct bluetooth_pan *pan = value;
+
+		if (g_strcmp0(proxy_get_string(pan->btdevice_proxy, "Adapter"),
+						path) == 0) {
+
+			DBG("enable network %p", pan->network);
+			pan_create_nap(pan);
+		}
+	}
+}
+
+static void device_enable_cb(const DBusError *error, void *user_data)
+{
+	char *path = user_data;
+	struct connman_device *device;
+
+	device = g_hash_table_lookup(devices, path);
+	if (!device) {
+		DBG("device already removed");
+		goto out;
+	}
+
+	if (dbus_error_is_set(error)) {
+		connman_warn("Bluetooth device %s not enabled %s",
+				path, error->message);
+		goto out;
+	}
+
+	enable_device(device, path);
+out:
+	g_free(path);
+}
+
+static int bluetooth_device_enable(struct connman_device *device)
+{
+	GDBusProxy *proxy = connman_device_get_data(device);
+	dbus_bool_t device_powered = TRUE;
+	const char *path;
+
+	if (!proxy)
+		return 0;
+
+	path = g_dbus_proxy_get_path(proxy);
+
+	if (proxy_get_bool(proxy, "Powered")) {
+		DBG("already enabled %p %s", device, path);
+		return -EALREADY;
+	}
+
+	DBG("device %p %s", device, path);
+
+	g_dbus_proxy_set_property_basic(proxy, "Powered",
+			DBUS_TYPE_BOOLEAN, &device_powered,
+			device_enable_cb, g_strdup(path), NULL);
+
+	return -EINPROGRESS;
+}
+
+static void disable_device(struct connman_device *device, const char *path)
+{
+	GHashTableIter iter;
+	gpointer key, value;
+
+	DBG("device %p %s", device, path);
+	connman_device_set_powered(device, false);
+
+	g_hash_table_iter_init(&iter, networks);
+	while (g_hash_table_iter_next(&iter, &key, &value)) {
+		struct bluetooth_pan *pan = value;
+
+		if (pan->network && connman_network_get_device(pan->network)
+				== device) {
+			DBG("disable network %p", pan->network);
+			connman_device_remove_network(device, pan->network);
+		}
+	}
+}
+
+static void device_disable_cb(const DBusError *error, void *user_data)
+{
+	char *path = user_data;
+	struct connman_device *device;
+
+	device = g_hash_table_lookup(devices, path);
+	if (!device) {
+		DBG("device already removed");
+		goto out;
+	}
+
+	if (dbus_error_is_set(error)) {
+		connman_warn("Bluetooth device %s not disabled: %s",
+				path, error->message);
+		goto out;
+	}
+
+	disable_device(device, path);
+
+out:
+	g_free(path);
+}
+
+static int bluetooth_device_disable(struct connman_device *device)
+{
+	GDBusProxy *proxy = connman_device_get_data(device);
+	dbus_bool_t device_powered = FALSE;
+	const char *path;
+
+	if (!proxy)
+		return 0;
+
+	path = g_dbus_proxy_get_path(proxy);
+
+	if (!proxy_get_bool(proxy, "Powered")) {
+		DBG("already disabled %p %s", device, path);
+		return -EALREADY;
+	}
+
+	DBG("device %p %s", device, path);
+
+	g_dbus_proxy_set_property_basic(proxy, "Powered",
+			DBUS_TYPE_BOOLEAN, &device_powered,
+			device_disable_cb, g_strdup(path), NULL);
+
+	return -EINPROGRESS;
+}
+
+static void adapter_property_change(GDBusProxy *proxy, const char *name,
+		DBusMessageIter *iter, void *user_data)
+{
+	struct connman_device *device;
+	const char *path;
+	bool adapter_powered, device_powered;
+
+	if (strcmp(name, "Powered") != 0)
+		return;
+
+	path = g_dbus_proxy_get_path(proxy);
+	device = g_hash_table_lookup(devices, path);
+
+	adapter_powered = proxy_get_bool(proxy, "Powered");
+	device_powered = connman_device_get_powered(device);
+
+	DBG("device %p %s device powered %d adapter powered %d", device, path,
+			device_powered, adapter_powered);
+
+	if (device_powered != adapter_powered) {
+		if (adapter_powered)
+			enable_device(device, path);
+		else
+			disable_device(device, path);
+	}
+}
+
+static void device_free(gpointer data)
+{
+	struct connman_device *device = data;
+	GDBusProxy *proxy = connman_device_get_data(device);
+
+	connman_device_set_data(device, NULL);
+	if (proxy)
+		g_dbus_proxy_unref(proxy);
+
+	connman_device_unregister(device);
+	connman_device_unref(device);
+}
+
+struct tethering_info {
+	struct connman_technology *technology;
+	char *bridge;
+	bool enable;
+};
+
+static void tethering_free(void *user_data)
+{
+	struct tethering_info *tethering = user_data;
+
+	g_free(tethering->bridge);
+	g_free(tethering);
+}
+
+static void tethering_create_cb(DBusMessage *message, void *user_data)
+{
+	struct tethering_info *tethering = user_data;
+
+	if (dbus_message_get_type(message) == DBUS_MESSAGE_TYPE_ERROR) {
+		const char *dbus_error = dbus_message_get_error_name(message);
+
+		DBG("%s tethering failed: %s",
+				tethering->enable ? "enable" : "disable",
+				dbus_error);
+		return;
+	}
+
+	DBG("bridge %s %s", tethering->bridge, tethering->enable ?
+			"enabled": "disabled");
+
+	if (tethering->technology)
+		connman_technology_tethering_notify(tethering->technology,
+				tethering->enable);
+}
+
+static void tethering_append(DBusMessageIter *iter, void *user_data)
+{
+	struct tethering_info *tethering = user_data;
+	const char *nap = "nap";
+
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &nap);
+	if (tethering->enable)
+		dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING,
+				&tethering->bridge);
+}
+
+static bool tethering_create(const char *path,
+		struct connman_technology *technology, const char *bridge,
+		bool enabled)
+{
+	struct tethering_info *tethering = g_new0(struct tethering_info, 1);
+	GDBusProxy *proxy;
+	const char *method;
+	bool result;
+
+	DBG("path %s bridge %s", path, bridge);
+
+	if (!bridge)
+		return -EINVAL;
+
+	proxy = g_dbus_proxy_new(client, path, "org.bluez.NetworkServer1");
+	if (!proxy)
+		return false;
+
+	tethering->technology = technology;
+	tethering->bridge = g_strdup(bridge);
+	tethering->enable = enabled;
+
+	if (tethering->enable)
+		method = "Register";
+	else
+		method = "Unregister";
+
+	result = g_dbus_proxy_method_call(proxy, method, tethering_append,
+			tethering_create_cb, tethering, tethering_free);
+
+	g_dbus_proxy_unref(proxy);
+
+	return result;
+}
+
+static void device_create(GDBusProxy *proxy)
+{
+	struct connman_device *device = NULL;
+	const char *path = g_dbus_proxy_get_path(proxy);
+	const char *address;
+	char ident[BLUETOOTH_ADDR_LEN * 2 + 1];
+	bool powered;
+
+	address = proxy_get_string(proxy, "Address");
+	if (!address)
+		return;
+
+	address2ident(address, ident);
+
+	device = connman_device_create("bluetooth",
+			CONNMAN_DEVICE_TYPE_BLUETOOTH);
+	if (!device)
+		return;
+
+	connman_device_set_data(device, g_dbus_proxy_ref(proxy));
+	connman_device_set_ident(device, ident);
+
+	g_hash_table_replace(devices, g_strdup(path), device);
+
+	DBG("device %p %s device powered %d adapter powered %d", device,
+			path, connman_device_get_powered(device),
+			proxy_get_bool(proxy, "Powered"));
+
+	if (connman_device_register(device) < 0) {
+		g_hash_table_remove(devices, device);
+		return;
+	}
+
+	g_dbus_proxy_set_property_watch(proxy, adapter_property_change, NULL);
+
+	powered = proxy_get_bool(proxy, "Powered");
+	connman_device_set_powered(device, powered);
+
+	if (proxy_get_role(proxy) && !bluetooth_tethering)
+		tethering_create(path, NULL, NULL, false);
+}
+
+static void object_added(GDBusProxy *proxy, void *user_data)
+{
+	const char *interface;
+
+	interface = g_dbus_proxy_get_interface(proxy);
+	if (!interface) {
+		connman_warn("Interface or proxy missing when adding "
+							"bluetooth object");
+		return;
+	}
+
+	if (strcmp(interface, "org.bluez.Adapter1") == 0) {
+		DBG("%s %s", interface, g_dbus_proxy_get_path(proxy));
+		device_create(proxy);
+		return;
+	}
+
+	if (strcmp(interface, "org.bluez.Network1") == 0) {
+		DBG("%s %s", interface, g_dbus_proxy_get_path(proxy));
+		pan_create(proxy);
+		return;
+	}
+}
+
+static void object_removed(GDBusProxy *proxy, void *user_data)
+{
+	const char *interface, *path;
+
+	interface = g_dbus_proxy_get_interface(proxy);
+	if (!interface) {
+		connman_warn("Interface or proxy missing when removing "
+							"bluetooth object");
+		return;
+	}
+
+	if (strcmp(interface, "org.bluez.Adapter1") == 0) {
+		path = g_dbus_proxy_get_path(proxy);
+		DBG("%s %s", interface, path);
+
+		g_hash_table_remove(devices, path);
+	}
+
+	if (strcmp(interface, "org.bluez.Network1") == 0) {
+		path = g_dbus_proxy_get_path(proxy);
+		DBG("%s %s", interface, path);
+
+		g_hash_table_remove(networks, path);
+	}
+
+}
+
+static int bluetooth_device_probe(struct connman_device *device)
+{
+	GHashTableIter iter;
+	gpointer key, value;
+
+	g_hash_table_iter_init(&iter, devices);
+
+	while (g_hash_table_iter_next(&iter, &key, &value)) {
+		struct connman_device *known = value;
+
+		if (device == known)
+			return 0;
+	}
+
+	return -EOPNOTSUPP;
+}
+
+static void bluetooth_device_remove(struct connman_device *device)
+{
+	DBG("%p", device);
+}
+
+static struct connman_device_driver device_driver = {
+	.name		= "bluetooth",
+	.type		= CONNMAN_DEVICE_TYPE_BLUETOOTH,
+	.probe          = bluetooth_device_probe,
+	.remove         = bluetooth_device_remove,
+	.enable         = bluetooth_device_enable,
+	.disable        = bluetooth_device_disable,
+};
+
+static int bluetooth_tech_probe(struct connman_technology *technology)
+{
+	return 0;
+}
+
+static void bluetooth_tech_remove(struct connman_technology *technology)
+{
+
+}
+
+static int bluetooth_tech_set_tethering(struct connman_technology *technology,
+		const char *identifier, const char *passphrase,
+		const char *bridge, bool enabled)
+{
+	GHashTableIter hash_iter;
+	gpointer key, value;
+	int i = 0;
+
+	bluetooth_tethering = enabled;
+
+	g_hash_table_iter_init(&hash_iter, devices);
+
+	while (g_hash_table_iter_next(&hash_iter, &key, &value)) {
+		const char *path = key;
+		struct connman_device *device = value;
+
+		DBG("device %p", device);
+
+		if (tethering_create(path, technology, bridge, enabled)
+				)
+			i++;
+	}
+
+	DBG("%s %d device(s)", enabled ? "enabled" : "disabled", i);
+
+	if (i == 0)
+		return -ENODEV;
+
+	return 0;
+}
+
+static struct connman_technology_driver tech_driver = {
+	.name		= "bluetooth",
+	.type		= CONNMAN_SERVICE_TYPE_BLUETOOTH,
+	.probe          = bluetooth_tech_probe,
+	.remove         = bluetooth_tech_remove,
+	.set_tethering  = bluetooth_tech_set_tethering,
+};
+
+static int bluetooth_init(void)
+{
+	connection = connman_dbus_get_connection();
+	if (!connection)
+		goto out;
+
+	if (connman_technology_driver_register(&tech_driver) < 0) {
+		connman_warn("Failed to initialize technology for Bluez 5");
+		goto out;
+	}
+
+	devices = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
+			device_free);
+
+	if (connman_device_driver_register(&device_driver) < 0) {
+		connman_warn("Failed to initialize device driver for "
+				BLUEZ_SERVICE);
+		connman_technology_driver_unregister(&tech_driver);
+		goto out;
+	}
+
+	if (connman_network_driver_register(&network_driver) < 0) {
+		connman_technology_driver_unregister(&tech_driver);
+		connman_device_driver_unregister(&device_driver);
+		goto out;
+	}
+
+	networks = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
+			pan_free);
+
+	client = g_dbus_client_new(connection, BLUEZ_SERVICE, BLUEZ_PATH);
+	if (!client) {
+		connman_warn("Failed to initialize D-Bus client for "
+				BLUEZ_SERVICE);
+		goto out;
+	}
+
+	g_dbus_client_set_proxy_handlers(client, object_added, object_removed,
+			NULL, NULL);
+
+	return 0;
+
+out:
+	if (networks)
+		g_hash_table_destroy(networks);
+
+	if (devices)
+		g_hash_table_destroy(devices);
+
+	if (client)
+		g_dbus_client_unref(client);
+
+	if (connection)
+		dbus_connection_unref(connection);
+
+	return -EIO;
+}
+
+static void bluetooth_exit(void)
+{
+	/*
+	 * We unset the disabling of the Bluetooth device when shutting down
+	 * so that non-PAN BT connections are not affected.
+	 */
+	device_driver.disable = NULL;
+
+	g_dbus_client_unref(client);
+
+	connman_network_driver_unregister(&network_driver);
+	g_hash_table_destroy(networks);
+
+	connman_device_driver_unregister(&device_driver);
+	g_hash_table_destroy(devices);
+
+	connman_technology_driver_unregister(&tech_driver);
+	dbus_connection_unref(connection);
+}
+
+CONNMAN_PLUGIN_DEFINE(bluetooth, "Bluetooth technology plugin", VERSION,
+                CONNMAN_PLUGIN_PRIORITY_DEFAULT, bluetooth_init, bluetooth_exit)
diff --git a/connman/plugins/bluetooth_legacy.c b/connman/plugins/bluetooth_legacy.c
new file mode 100644
index 0000000..62c89e1
--- /dev/null
+++ b/connman/plugins/bluetooth_legacy.c
@@ -0,0 +1,1385 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2013  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 <stdio.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <netinet/ether.h>
+
+#include <gdbus.h>
+
+#define CONNMAN_API_SUBJECT_TO_CHANGE
+#include <connman/plugin.h>
+#include <connman/technology.h>
+#include <connman/device.h>
+#include <connman/inet.h>
+#include <connman/dbus.h>
+#include <connman/log.h>
+
+#define BLUEZ_SERVICE			"org.bluez"
+#define BLUEZ_MANAGER_INTERFACE		BLUEZ_SERVICE ".Manager"
+#define BLUEZ_ADAPTER_INTERFACE		BLUEZ_SERVICE ".Adapter"
+#define BLUEZ_DEVICE_INTERFACE		BLUEZ_SERVICE ".Device"
+#define BLUEZ_NETWORK_INTERFACE		BLUEZ_SERVICE ".Network"
+#define BLUEZ_NETWORK_SERVER		BLUEZ_SERVICE ".NetworkServer"
+
+#define LIST_ADAPTERS			"ListAdapters"
+#define ADAPTER_ADDED			"AdapterAdded"
+#define ADAPTER_REMOVED			"AdapterRemoved"
+#define DEVICE_REMOVED			"DeviceRemoved"
+
+#define PROPERTY_CHANGED		"PropertyChanged"
+#define GET_PROPERTIES			"GetProperties"
+#define SET_PROPERTY			"SetProperty"
+
+#define CONNECT				"Connect"
+#define DISCONNECT			"Disconnect"
+
+#define REGISTER			"Register"
+#define UNREGISTER			"Unregister"
+
+#define UUID_NAP	"00001116-0000-1000-8000-00805f9b34fb"
+
+#define TIMEOUT 60000
+
+static DBusConnection *connection;
+
+static GHashTable *bluetooth_devices = NULL;
+static GHashTable *bluetooth_networks = NULL;
+static GHashTable *pending_networks = NULL;
+
+static int pan_probe(struct connman_network *network)
+{
+	GHashTableIter iter;
+	gpointer key, val;
+
+	g_hash_table_iter_init(&iter, bluetooth_networks);
+	while (g_hash_table_iter_next(&iter, &key, &val)) {
+		struct connman_network *known = val;
+
+		if (network != known)
+			continue;
+
+		DBG("network %p", network);
+
+		return 0;
+	}
+
+	return -EOPNOTSUPP;
+}
+
+static void pan_remove(struct connman_network *network)
+{
+	DBG("network %p", network);
+}
+
+static void connect_reply(DBusPendingCall *call, void *user_data)
+{
+	char *path = user_data;
+	struct connman_network *network;
+	DBusMessage *reply;
+	DBusError error;
+	const char *interface = NULL;
+	int index;
+
+	network = g_hash_table_lookup(bluetooth_networks, path);
+	if (!network)
+		return;
+
+	DBG("network %p", network);
+
+	reply = dbus_pending_call_steal_reply(call);
+
+	dbus_error_init(&error);
+
+	if (dbus_set_error_from_message(&error, reply)) {
+		connman_error("%s", error.message);
+		dbus_error_free(&error);
+
+		goto err;
+	}
+
+	if (!dbus_message_get_args(reply, &error, DBUS_TYPE_STRING,
+					&interface, DBUS_TYPE_INVALID)) {
+		if (dbus_error_is_set(&error)) {
+			connman_error("%s", error.message);
+			dbus_error_free(&error);
+		} else
+			connman_error("Wrong arguments for connect");
+		goto err;
+	}
+
+	if (!interface)
+		goto err;
+
+	DBG("interface %s", interface);
+
+	index = connman_inet_ifindex(interface);
+
+	connman_network_set_index(network, index);
+
+	connman_network_set_connected(network, true);
+
+	dbus_message_unref(reply);
+
+	dbus_pending_call_unref(call);
+
+	return;
+err:
+
+	connman_network_set_connected(network, false);
+
+	dbus_message_unref(reply);
+
+	dbus_pending_call_unref(call);
+}
+
+static int pan_connect(struct connman_network *network)
+{
+	const char *path = connman_network_get_string(network, "Path");
+	const char *uuid = "nap";
+	DBusMessage *message;
+	DBusPendingCall *call;
+
+	DBG("network %p", network);
+
+	if (!path)
+		return -EINVAL;
+
+	message = dbus_message_new_method_call(BLUEZ_SERVICE, path,
+					BLUEZ_NETWORK_INTERFACE, CONNECT);
+	if (!message)
+		return -ENOMEM;
+
+	dbus_message_set_auto_start(message, FALSE);
+
+	dbus_message_append_args(message, DBUS_TYPE_STRING, &uuid,
+							DBUS_TYPE_INVALID);
+
+	if (!dbus_connection_send_with_reply(connection, message,
+						&call, TIMEOUT * 10)) {
+		connman_error("Failed to connect service");
+		dbus_message_unref(message);
+		return -EINVAL;
+	}
+
+	if (!call) {
+		connman_error("D-Bus connection not available");
+		dbus_message_unref(message);
+		return -EINVAL;
+	}
+
+	dbus_pending_call_set_notify(call, connect_reply, g_strdup(path),
+			g_free);
+
+	dbus_message_unref(message);
+
+	return -EINPROGRESS;
+}
+
+static void disconnect_reply(DBusPendingCall *call, void *user_data)
+{
+	char *path = user_data;
+	struct connman_network *network;
+	DBusMessage *reply;
+	DBusError error;
+
+	network = g_hash_table_lookup(bluetooth_networks, path);
+	if (!network)
+		return;
+
+	DBG("network %p", network);
+
+	reply = dbus_pending_call_steal_reply(call);
+
+	dbus_error_init(&error);
+
+	if (dbus_set_error_from_message(&error, reply)) {
+		connman_error("%s", error.message);
+		dbus_error_free(&error);
+		goto done;
+	}
+
+	if (!dbus_message_get_args(reply, &error, DBUS_TYPE_INVALID)) {
+		if (dbus_error_is_set(&error)) {
+			connman_error("%s", error.message);
+			dbus_error_free(&error);
+		} else
+			connman_error("Wrong arguments for disconnect");
+		goto done;
+	}
+
+	connman_network_set_connected(network, false);
+
+done:
+	dbus_message_unref(reply);
+
+	dbus_pending_call_unref(call);
+
+	connman_network_unref(network);
+}
+
+static int pan_disconnect(struct connman_network *network, bool user_initiated)
+{
+	const char *path = connman_network_get_string(network, "Path");
+	DBusMessage *message;
+	DBusPendingCall *call;
+
+	DBG("network %p", network);
+
+	if (!path)
+		return -EINVAL;
+
+	message = dbus_message_new_method_call(BLUEZ_SERVICE, path,
+					BLUEZ_NETWORK_INTERFACE, DISCONNECT);
+	if (!message)
+		return -ENOMEM;
+
+	dbus_message_set_auto_start(message, FALSE);
+
+	dbus_message_append_args(message, DBUS_TYPE_INVALID);
+
+	if (!dbus_connection_send_with_reply(connection, message,
+						&call, TIMEOUT)) {
+		connman_error("Failed to disconnect service");
+		dbus_message_unref(message);
+		return -EINVAL;
+	}
+
+	if (!call) {
+		connman_error("D-Bus connection not available");
+		dbus_message_unref(message);
+		return -EINVAL;
+	}
+
+	connman_network_ref(network);
+
+	connman_network_set_associating(network, false);
+
+	dbus_pending_call_set_notify(call, disconnect_reply, g_strdup(path),
+			g_free);
+
+	dbus_message_unref(message);
+
+	return 0;
+}
+
+static struct connman_network_driver pan_driver = {
+	.name		= "bluetooth_legacy-pan",
+	.type		= CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN,
+	.priority       = CONNMAN_NETWORK_PRIORITY_LOW,
+	.probe		= pan_probe,
+	.remove		= pan_remove,
+	.connect	= pan_connect,
+	.disconnect	= pan_disconnect,
+};
+
+static gboolean network_changed(DBusConnection *conn,
+				DBusMessage *message, void *user_data)
+{
+	const char *path = dbus_message_get_path(message);
+	struct connman_network *network;
+	DBusMessageIter iter, value;
+	const char *key;
+
+	DBG("path %s", path);
+
+	network = g_hash_table_lookup(bluetooth_networks, path);
+	if (!network)
+		return TRUE;
+
+	if (!dbus_message_iter_init(message, &iter))
+		return TRUE;
+
+	dbus_message_iter_get_basic(&iter, &key);
+
+	dbus_message_iter_next(&iter);
+	dbus_message_iter_recurse(&iter, &value);
+
+	if (g_str_equal(key, "Connected")) {
+		dbus_bool_t connected;
+
+		dbus_message_iter_get_basic(&value, &connected);
+
+		if (connected)
+			return TRUE;
+
+		connman_network_set_associating(network, false);
+		connman_network_set_connected(network, false);
+	}
+
+	return TRUE;
+}
+
+static void extract_properties(DBusMessage *reply, const char **parent,
+						const char **address,
+						const char **name,
+						const char **alias,
+						dbus_bool_t *powered,
+						dbus_bool_t *scanning,
+						DBusMessageIter *uuids,
+						DBusMessageIter *networks)
+{
+	DBusMessageIter array, dict;
+
+	if (!dbus_message_iter_init(reply, &array))
+		return;
+
+	if (dbus_message_iter_get_arg_type(&array) != DBUS_TYPE_ARRAY)
+		return;
+
+	dbus_message_iter_recurse(&array, &dict);
+
+	while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
+		DBusMessageIter entry, value;
+		const char *key;
+
+		dbus_message_iter_recurse(&dict, &entry);
+		dbus_message_iter_get_basic(&entry, &key);
+
+		dbus_message_iter_next(&entry);
+		dbus_message_iter_recurse(&entry, &value);
+
+		if (g_str_equal(key, "Adapter")) {
+			if (parent)
+				dbus_message_iter_get_basic(&value, parent);
+		} else if (g_str_equal(key, "Address")) {
+			if (address)
+				dbus_message_iter_get_basic(&value, address);
+		} else if (g_str_equal(key, "Name")) {
+			if (name)
+				dbus_message_iter_get_basic(&value, name);
+		} else if (g_str_equal(key, "Alias")) {
+			if (alias)
+				dbus_message_iter_get_basic(&value, alias);
+		} else if (g_str_equal(key, "Powered")) {
+			if (powered)
+				dbus_message_iter_get_basic(&value, powered);
+		} else if (g_str_equal(key, "Discovering")) {
+			if (scanning)
+				dbus_message_iter_get_basic(&value, scanning);
+		} else if (g_str_equal(key, "Devices")) {
+			if (networks)
+				memcpy(networks, &value, sizeof(value));
+		} else if (g_str_equal(key, "UUIDs")) {
+			if (uuids)
+				memcpy(uuids, &value, sizeof(value));
+		}
+
+		dbus_message_iter_next(&dict);
+	}
+}
+
+static dbus_bool_t has_pan(DBusMessageIter *array)
+{
+	DBusMessageIter value;
+
+	if (dbus_message_iter_get_arg_type(array) != DBUS_TYPE_ARRAY)
+		return FALSE;
+
+	dbus_message_iter_recurse(array, &value);
+
+	while (dbus_message_iter_get_arg_type(&value) == DBUS_TYPE_STRING) {
+		const char *uuid;
+
+		dbus_message_iter_get_basic(&value, &uuid);
+
+		if (g_strcmp0(uuid, UUID_NAP) == 0)
+			return TRUE;
+
+		dbus_message_iter_next(&value);
+	}
+
+	return FALSE;
+}
+
+static void network_properties_reply(DBusPendingCall *call, void *user_data)
+{
+	char *path = user_data;
+	struct connman_device *device;
+	struct connman_network *network;
+	DBusMessage *reply;
+	DBusMessageIter uuids;
+	const char *parent = NULL, *address = NULL, *name = NULL;
+	struct ether_addr addr;
+	char ident[13];
+
+	reply = dbus_pending_call_steal_reply(call);
+
+	extract_properties(reply, &parent, &address, NULL, &name,
+						NULL, NULL, &uuids, NULL);
+
+	if (!parent)
+		goto done;
+
+	device = g_hash_table_lookup(bluetooth_devices, parent);
+	if (!device)
+		goto done;
+
+	if (!address)
+		goto done;
+
+	ether_aton_r(address, &addr);
+
+	snprintf(ident, 13, "%02x%02x%02x%02x%02x%02x",
+						addr.ether_addr_octet[0],
+						addr.ether_addr_octet[1],
+						addr.ether_addr_octet[2],
+						addr.ether_addr_octet[3],
+						addr.ether_addr_octet[4],
+						addr.ether_addr_octet[5]);
+
+	if (!has_pan(&uuids))
+		goto done;
+
+	network = connman_device_get_network(device, ident);
+	if (network)
+		goto done;
+
+	network = connman_network_create(ident,
+					CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN);
+	if (!network)
+		goto done;
+
+	connman_network_set_string(network, "Path", path);
+
+	connman_network_set_name(network, name);
+
+	g_hash_table_replace(bluetooth_networks, g_strdup(path), network);
+
+	connman_device_add_network(device, network);
+
+	connman_network_set_group(network, ident);
+
+done:
+	dbus_message_unref(reply);
+
+	dbus_pending_call_unref(call);
+}
+
+static void add_network(const char *path)
+{
+	DBusMessage *message;
+	DBusPendingCall *call;
+
+	DBG("path %s", path);
+
+	message = dbus_message_new_method_call(BLUEZ_SERVICE, path,
+				BLUEZ_DEVICE_INTERFACE, GET_PROPERTIES);
+	if (!message)
+		return;
+
+	dbus_message_set_auto_start(message, FALSE);
+
+	if (!dbus_connection_send_with_reply(connection, message,
+						&call, TIMEOUT)) {
+		connman_error("Failed to get network properties for %s", path);
+		goto done;
+	}
+
+	if (!call) {
+		connman_error("D-Bus connection not available");
+		goto done;
+	}
+
+	dbus_pending_call_set_notify(call, network_properties_reply,
+						g_strdup(path), g_free);
+
+done:
+	dbus_message_unref(message);
+}
+
+static void check_networks(DBusMessageIter *array)
+{
+	DBusMessageIter value;
+
+	if (dbus_message_iter_get_arg_type(array) != DBUS_TYPE_ARRAY)
+		return;
+
+	dbus_message_iter_recurse(array, &value);
+
+	while (dbus_message_iter_get_arg_type(&value) == DBUS_TYPE_OBJECT_PATH) {
+		const char *path;
+
+		dbus_message_iter_get_basic(&value, &path);
+
+		add_network(path);
+
+		dbus_message_iter_next(&value);
+	}
+}
+
+static void check_pending_networks(const char *adapter)
+{
+	GSList *networks, *list;
+
+	networks = g_hash_table_lookup(pending_networks, adapter);
+	if (!networks)
+		return;
+
+	for (list = networks; list; list = list->next) {
+		char *path = list->data;
+
+		add_network(path);
+	}
+
+	g_hash_table_remove(pending_networks, adapter);
+}
+
+static gboolean adapter_changed(DBusConnection *conn,
+				DBusMessage *message, void *user_data)
+{
+	const char *path = dbus_message_get_path(message);
+	struct connman_device *device;
+	DBusMessageIter iter, value;
+	const char *key;
+
+	DBG("path %s", path);
+
+	device = g_hash_table_lookup(bluetooth_devices, path);
+	if (!device)
+		return TRUE;
+
+	if (!dbus_message_iter_init(message, &iter))
+		return TRUE;
+
+	dbus_message_iter_get_basic(&iter, &key);
+
+	dbus_message_iter_next(&iter);
+	dbus_message_iter_recurse(&iter, &value);
+
+	if (g_str_equal(key, "Powered")) {
+		dbus_bool_t val;
+
+		dbus_message_iter_get_basic(&value, &val);
+		connman_device_set_powered(device, val);
+		if (val)
+			check_pending_networks(path);
+	} else if (g_str_equal(key, "Discovering")) {
+		dbus_bool_t val;
+
+		dbus_message_iter_get_basic(&value, &val);
+		connman_device_set_scanning(device,
+				CONNMAN_SERVICE_TYPE_BLUETOOTH, val);
+	} else if (g_str_equal(key, "Devices")) {
+		check_networks(&value);
+	}
+
+	return TRUE;
+}
+
+static gboolean device_removed(DBusConnection *conn,
+				DBusMessage *message, void *user_data)
+{
+	const char *network_path;
+	struct connman_network *network;
+	struct connman_device *device;
+	DBusMessageIter iter;
+
+	DBG("");
+
+	if (!dbus_message_iter_init(message, &iter))
+		return TRUE;
+
+	dbus_message_iter_get_basic(&iter, &network_path);
+
+	network = g_hash_table_lookup(bluetooth_networks, network_path);
+	if (!network)
+		return TRUE;
+
+	device = connman_network_get_device(network);
+	if (!device)
+		return TRUE;
+
+	g_hash_table_remove(bluetooth_networks, network_path);
+
+	return TRUE;
+}
+
+static gboolean device_changed(DBusConnection *conn,
+				DBusMessage *message, void *user_data)
+{
+	const char *path = dbus_message_get_path(message);
+	DBusMessageIter iter, value;
+	const char *key;
+
+	DBG("path %s", path);
+
+	if (!dbus_message_iter_init(message, &iter))
+		return TRUE;
+
+	dbus_message_iter_get_basic(&iter, &key);
+
+	dbus_message_iter_next(&iter);
+	dbus_message_iter_recurse(&iter, &value);
+
+	DBG("key %s", key);
+
+	if (g_str_equal(key, "UUIDs"))
+		add_network(path);
+
+	return TRUE;
+}
+
+static void remove_device_networks(struct connman_device *device)
+{
+	GHashTableIter iter;
+	gpointer key, value;
+	GSList *key_list = NULL;
+	GSList *list;
+
+	if (!bluetooth_networks)
+		return;
+
+	g_hash_table_iter_init(&iter, bluetooth_networks);
+
+	while (g_hash_table_iter_next(&iter, &key, &value)) {
+		struct connman_network *network = value;
+
+		if (connman_network_get_device(network) != device)
+			continue;
+
+		key_list = g_slist_prepend(key_list, key);
+	}
+
+	for (list = key_list; list; list = list->next) {
+		const char *network_path = list->data;
+
+		g_hash_table_remove(bluetooth_networks, network_path);
+	}
+
+	g_slist_free(key_list);
+}
+
+static void add_pending_networks(const char *adapter, DBusMessageIter *array)
+{
+	DBusMessageIter value;
+	GSList *list = NULL;
+
+	if (dbus_message_iter_get_arg_type(array) != DBUS_TYPE_ARRAY)
+		return;
+
+	dbus_message_iter_recurse(array, &value);
+
+	while (dbus_message_iter_get_arg_type(&value) == DBUS_TYPE_OBJECT_PATH) {
+		const char *path;
+
+		dbus_message_iter_get_basic(&value, &path);
+
+		list = g_slist_prepend(list, g_strdup(path));
+
+		dbus_message_iter_next(&value);
+	}
+
+	if (!list)
+		return;
+
+	g_hash_table_replace(pending_networks, g_strdup(adapter), list);
+}
+
+static void adapter_properties_reply(DBusPendingCall *call, void *user_data)
+{
+	char *path = user_data;
+	struct connman_device *device;
+	DBusMessage *reply;
+	DBusMessageIter networks;
+	const char *address = NULL, *name = NULL;
+	dbus_bool_t powered = FALSE, scanning = FALSE;
+	struct ether_addr addr;
+	char ident[13];
+
+	DBG("path %s", path);
+
+	reply = dbus_pending_call_steal_reply(call);
+
+	if (!path)
+		goto done;
+
+	extract_properties(reply, NULL, &address, &name, NULL,
+					&powered, &scanning, NULL, &networks);
+
+	if (!address)
+		goto done;
+
+	if (g_strcmp0(address, "00:00:00:00:00:00") == 0)
+		goto done;
+
+	device = g_hash_table_lookup(bluetooth_devices, path);
+	if (device)
+		goto update;
+
+	ether_aton_r(address, &addr);
+
+	snprintf(ident, 13, "%02x%02x%02x%02x%02x%02x",
+						addr.ether_addr_octet[0],
+						addr.ether_addr_octet[1],
+						addr.ether_addr_octet[2],
+						addr.ether_addr_octet[3],
+						addr.ether_addr_octet[4],
+						addr.ether_addr_octet[5]);
+
+	device = connman_device_create("bluetooth_legacy",
+			CONNMAN_DEVICE_TYPE_BLUETOOTH);
+	if (!device)
+		goto done;
+
+	g_hash_table_insert(bluetooth_devices, g_strdup(path), device);
+
+	connman_device_set_ident(device, ident);
+
+	connman_device_set_string(device, "Path", path);
+
+	if (connman_device_register(device) < 0) {
+		connman_device_unref(device);
+		g_hash_table_remove(bluetooth_devices, path);
+		goto done;
+	}
+
+update:
+	connman_device_set_string(device, "Address", address);
+	connman_device_set_string(device, "Name", name);
+	connman_device_set_string(device, "Path", path);
+
+	connman_device_set_powered(device, powered);
+	connman_device_set_scanning(device,
+			CONNMAN_SERVICE_TYPE_BLUETOOTH, scanning);
+
+	if (!powered) {
+		remove_device_networks(device);
+		add_pending_networks(path, &networks);
+	} else
+		check_networks(&networks);
+
+done:
+	dbus_message_unref(reply);
+
+	dbus_pending_call_unref(call);
+}
+
+static void add_adapter(DBusConnection *conn, const char *path)
+{
+	DBusMessage *message;
+	DBusPendingCall *call;
+
+	DBG("path %s", path);
+
+	message = dbus_message_new_method_call(BLUEZ_SERVICE, path,
+				BLUEZ_ADAPTER_INTERFACE, GET_PROPERTIES);
+	if (!message)
+		return;
+
+	dbus_message_set_auto_start(message, FALSE);
+
+	if (!dbus_connection_send_with_reply(conn, message, &call, TIMEOUT)) {
+		connman_error("Failed to get adapter properties for %s", path);
+		goto done;
+	}
+
+	if (!call) {
+		connman_error("D-Bus connection not available");
+		goto done;
+	}
+
+	dbus_pending_call_set_notify(call, adapter_properties_reply,
+						g_strdup(path), g_free);
+
+done:
+	dbus_message_unref(message);
+}
+
+static gboolean adapter_added(DBusConnection *conn, DBusMessage *message,
+				void *user_data)
+{
+	const char *path;
+
+	dbus_message_get_args(message, NULL, DBUS_TYPE_OBJECT_PATH, &path,
+				DBUS_TYPE_INVALID);
+	add_adapter(conn, path);
+	return TRUE;
+}
+
+static void remove_adapter(DBusConnection *conn, const char *path)
+{
+	DBG("path %s", path);
+
+	g_hash_table_remove(bluetooth_devices, path);
+	g_hash_table_remove(pending_networks, path);
+}
+
+static gboolean adapter_removed(DBusConnection *conn, DBusMessage *message,
+				void *user_data)
+{
+	const char *path;
+
+	dbus_message_get_args(message, NULL, DBUS_TYPE_OBJECT_PATH, &path,
+				DBUS_TYPE_INVALID);
+	remove_adapter(conn, path);
+	return TRUE;
+}
+
+static void list_adapters_reply(DBusPendingCall *call, void *user_data)
+{
+	DBusMessage *reply;
+	DBusError error;
+	char **adapters;
+	int i, num_adapters;
+
+	DBG("");
+
+	reply = dbus_pending_call_steal_reply(call);
+
+	dbus_error_init(&error);
+
+	if (dbus_set_error_from_message(&error, reply)) {
+		connman_error("%s", error.message);
+		dbus_error_free(&error);
+		goto done;
+	}
+
+	if (!dbus_message_get_args(reply, &error, DBUS_TYPE_ARRAY,
+			DBUS_TYPE_OBJECT_PATH, &adapters,
+			&num_adapters, DBUS_TYPE_INVALID)) {
+		if (dbus_error_is_set(&error)) {
+			connman_error("%s", error.message);
+			dbus_error_free(&error);
+		} else
+			connman_error("Wrong arguments for adapter list");
+		goto done;
+	}
+
+	for (i = 0; i < num_adapters; i++)
+		add_adapter(connection, adapters[i]);
+
+	g_strfreev(adapters);
+
+done:
+	dbus_message_unref(reply);
+
+	dbus_pending_call_unref(call);
+}
+
+static void unregister_device(gpointer data)
+{
+	struct connman_device *device = data;
+
+	DBG("");
+
+	remove_device_networks(device);
+
+	connman_device_unregister(device);
+	connman_device_unref(device);
+}
+
+static void remove_network(gpointer data)
+{
+	struct connman_network *network = data;
+	struct connman_device *device;
+
+	DBG("network %p", network);
+
+	device = connman_network_get_device(network);
+	if (device)
+		connman_device_remove_network(device, network);
+
+	connman_network_unref(network);
+}
+
+static void remove_pending_networks(gpointer data)
+{
+	GSList *list = data;
+
+	g_slist_free_full(list, g_free);
+}
+
+static void bluetooth_connect(DBusConnection *conn, void *user_data)
+{
+	DBusMessage *message;
+	DBusPendingCall *call;
+
+	DBG("connection %p", conn);
+
+	bluetooth_devices = g_hash_table_new_full(g_str_hash, g_str_equal,
+						g_free, unregister_device);
+
+	bluetooth_networks = g_hash_table_new_full(g_str_hash, g_str_equal,
+						g_free, remove_network);
+
+	pending_networks = g_hash_table_new_full(g_str_hash, g_str_equal,
+					g_free, remove_pending_networks);
+
+	message = dbus_message_new_method_call(BLUEZ_SERVICE, "/",
+				BLUEZ_MANAGER_INTERFACE, LIST_ADAPTERS);
+	if (!message)
+		return;
+
+	dbus_message_set_auto_start(message, FALSE);
+
+	if (!dbus_connection_send_with_reply(conn, message, &call, TIMEOUT)) {
+		connman_error("Failed to get Bluetooth adapters");
+		goto done;
+	}
+
+	if (!call) {
+		connman_error("D-Bus connection not available");
+		goto done;
+	}
+
+	dbus_pending_call_set_notify(call, list_adapters_reply, NULL, NULL);
+
+done:
+	dbus_message_unref(message);
+}
+
+static void bluetooth_disconnect(DBusConnection *conn, void *user_data)
+{
+	DBG("connection %p", conn);
+
+	if (!bluetooth_devices)
+		return;
+
+	g_hash_table_destroy(bluetooth_networks);
+	bluetooth_networks = NULL;
+	g_hash_table_destroy(bluetooth_devices);
+	bluetooth_devices = NULL;
+	g_hash_table_destroy(pending_networks);
+	pending_networks = NULL;
+}
+
+static int bluetooth_probe(struct connman_device *device)
+{
+	GHashTableIter iter;
+	gpointer key, value;
+
+	DBG("device %p", device);
+
+	if (!bluetooth_devices)
+		return -ENOTSUP;
+
+	g_hash_table_iter_init(&iter, bluetooth_devices);
+
+	while (g_hash_table_iter_next(&iter, &key, &value)) {
+		struct connman_device *device_pan = value;
+
+		if (device == device_pan)
+			return 0;
+	}
+
+	return -ENOTSUP;
+}
+
+static void bluetooth_remove(struct connman_device *device)
+{
+	DBG("device %p", device);
+}
+
+static void powered_reply(DBusPendingCall *call, void *user_data)
+{
+	DBusError error;
+	DBusMessage *reply;
+
+	DBG("");
+
+	reply = dbus_pending_call_steal_reply(call);
+
+	dbus_error_init(&error);
+
+	if (dbus_set_error_from_message(&error, reply)) {
+		connman_error("%s", error.message);
+		dbus_error_free(&error);
+		dbus_message_unref(reply);
+		dbus_pending_call_unref(call);
+		return;
+	}
+
+	dbus_message_unref(reply);
+	dbus_pending_call_unref(call);
+
+	add_adapter(connection, user_data);
+}
+
+static int change_powered(DBusConnection *conn, const char *path,
+							dbus_bool_t powered)
+{
+	DBusMessage *message;
+	DBusMessageIter iter;
+	DBusPendingCall *call;
+
+	DBG("");
+
+	if (!path)
+		return -EINVAL;
+
+	message = dbus_message_new_method_call(BLUEZ_SERVICE, path,
+					BLUEZ_ADAPTER_INTERFACE, SET_PROPERTY);
+	if (!message)
+		return -ENOMEM;
+
+	dbus_message_set_auto_start(message, FALSE);
+
+	dbus_message_iter_init_append(message, &iter);
+	connman_dbus_property_append_basic(&iter, "Powered",
+						DBUS_TYPE_BOOLEAN, &powered);
+
+	if (!dbus_connection_send_with_reply(conn, message, &call, TIMEOUT)) {
+		connman_error("Failed to change Powered property");
+		dbus_message_unref(message);
+		return -EINVAL;
+	}
+
+	if (!call) {
+		connman_error("D-Bus connection not available");
+		dbus_message_unref(message);
+		return -EINVAL;
+	}
+
+	dbus_pending_call_set_notify(call, powered_reply,
+					g_strdup(path), g_free);
+
+	dbus_message_unref(message);
+
+	return -EINPROGRESS;
+}
+
+static int bluetooth_enable(struct connman_device *device)
+{
+	const char *path = connman_device_get_string(device, "Path");
+
+	DBG("device %p", device);
+
+	return change_powered(connection, path, TRUE);
+}
+
+static int bluetooth_disable(struct connman_device *device)
+{
+	const char *path = connman_device_get_string(device, "Path");
+
+	DBG("device %p", device);
+
+	return change_powered(connection, path, FALSE);
+}
+
+static struct connman_device_driver bluetooth_driver = {
+	.name		= "bluetooth_legacy",
+	.type		= CONNMAN_DEVICE_TYPE_BLUETOOTH,
+	.probe		= bluetooth_probe,
+	.remove		= bluetooth_remove,
+	.enable		= bluetooth_enable,
+	.disable	= bluetooth_disable,
+};
+
+static int tech_probe(struct connman_technology *technology)
+{
+	return 0;
+}
+
+static void tech_remove(struct connman_technology *technology)
+{
+}
+
+static void server_register_reply(DBusPendingCall *call, void *user_data)
+{
+	struct connman_technology *technology = user_data;
+	DBusError error;
+	DBusMessage *reply;
+
+	DBG("");
+
+	reply = dbus_pending_call_steal_reply(call);
+
+	dbus_error_init(&error);
+
+	if (dbus_set_error_from_message(&error, reply)) {
+		connman_error("%s", error.message);
+		dbus_error_free(&error);
+		dbus_message_unref(reply);
+		dbus_pending_call_unref(call);
+		return;
+	}
+
+	dbus_message_unref(reply);
+	dbus_pending_call_unref(call);
+
+	connman_technology_tethering_notify(technology, true);
+}
+
+static void server_unregister_reply(DBusPendingCall *call, void *user_data)
+{
+	struct connman_technology *technology = user_data;
+	DBusError error;
+	DBusMessage *reply;
+
+	DBG("");
+
+	reply = dbus_pending_call_steal_reply(call);
+
+	dbus_error_init(&error);
+
+	if (dbus_set_error_from_message(&error, reply)) {
+		connman_error("%s", error.message);
+		dbus_error_free(&error);
+		dbus_message_unref(reply);
+		dbus_pending_call_unref(call);
+		return;
+	}
+
+	dbus_message_unref(reply);
+	dbus_pending_call_unref(call);
+
+	connman_technology_tethering_notify(technology, false);
+}
+
+
+static void server_register(const char *path, const char *uuid,
+				struct connman_technology *technology,
+				const char *bridge, bool enabled)
+{
+	DBusMessage *message;
+	DBusPendingCall *call;
+	char *command;
+
+	DBG("path %s enabled %d", path, enabled);
+
+	command = enabled ? REGISTER : UNREGISTER;
+
+	message = dbus_message_new_method_call(BLUEZ_SERVICE, path,
+					BLUEZ_NETWORK_SERVER, command);
+	if (!message)
+		return;
+
+	dbus_message_set_auto_start(message, FALSE);
+
+	dbus_message_append_args(message, DBUS_TYPE_STRING, &uuid,
+							DBUS_TYPE_INVALID);
+
+	if (enabled)
+		dbus_message_append_args(message, DBUS_TYPE_STRING, &bridge,
+							DBUS_TYPE_INVALID);
+
+	if (!dbus_connection_send_with_reply(connection, message,
+						&call, TIMEOUT)) {
+		connman_error("Failed to enable PAN server");
+		dbus_message_unref(message);
+		return;
+	}
+
+	if (!call) {
+		connman_error("D-Bus connection not available");
+		dbus_message_unref(message);
+		return;
+	}
+
+	if (enabled)
+		dbus_pending_call_set_notify(call, server_register_reply,
+						technology, NULL);
+	else
+		dbus_pending_call_set_notify(call, server_unregister_reply,
+						technology, NULL);
+
+	dbus_message_unref(message);
+}
+
+struct tethering_info {
+	struct connman_technology *technology;
+	const char *bridge;
+};
+
+static void enable_nap(gpointer key, gpointer value, gpointer user_data)
+{
+	struct tethering_info *info = user_data;
+	struct connman_device *device = value;
+	const char *path;
+
+	DBG("");
+
+	path = connman_device_get_string(device, "Path");
+
+	server_register(path, "nap", info->technology, info->bridge, true);
+}
+
+static void disable_nap(gpointer key, gpointer value, gpointer user_data)
+{
+	struct tethering_info *info = user_data;
+	struct connman_device *device = value;
+	const char *path;
+
+	DBG("");
+
+	path = connman_device_get_string(device, "Path");
+
+	server_register(path, "nap", info->technology, info->bridge, false);
+}
+
+static int tech_set_tethering(struct connman_technology *technology,
+				const char *identifier, const char *passphrase,
+				const char *bridge, bool enabled)
+{
+	struct tethering_info info = {
+		.technology	= technology,
+		.bridge		= bridge,
+	};
+
+	DBG("bridge %s", bridge);
+
+	if (!bluetooth_devices)
+		return -ENOTCONN;
+
+	if (enabled)
+		g_hash_table_foreach(bluetooth_devices, enable_nap, &info);
+	else
+		g_hash_table_foreach(bluetooth_devices, disable_nap, &info);
+
+	return 0;
+}
+
+static struct connman_technology_driver tech_driver = {
+	.name		= "bluetooth_legacy",
+	.type		= CONNMAN_SERVICE_TYPE_BLUETOOTH,
+	.priority       = -10,
+	.probe		= tech_probe,
+	.remove		= tech_remove,
+	.set_tethering	= tech_set_tethering,
+};
+
+static guint watch;
+static guint added_watch;
+static guint removed_watch;
+static guint adapter_watch;
+static guint device_watch;
+static guint device_removed_watch;
+static guint network_watch;
+
+static int bluetooth_init(void)
+{
+	int err;
+
+	connection = connman_dbus_get_connection();
+	if (!connection)
+		return -EIO;
+
+	watch = g_dbus_add_service_watch(connection, BLUEZ_SERVICE,
+			bluetooth_connect, bluetooth_disconnect, NULL, NULL);
+
+	added_watch = g_dbus_add_signal_watch(connection, BLUEZ_SERVICE, NULL,
+						BLUEZ_MANAGER_INTERFACE,
+						ADAPTER_ADDED, adapter_added,
+						NULL, NULL);
+
+	removed_watch = g_dbus_add_signal_watch(connection, BLUEZ_SERVICE, NULL,
+						BLUEZ_MANAGER_INTERFACE,
+						ADAPTER_REMOVED, adapter_removed,
+						NULL, NULL);
+
+	adapter_watch = g_dbus_add_signal_watch(connection, BLUEZ_SERVICE,
+						NULL, BLUEZ_ADAPTER_INTERFACE,
+						PROPERTY_CHANGED, adapter_changed,
+						NULL, NULL);
+
+	device_removed_watch = g_dbus_add_signal_watch(connection,
+						BLUEZ_SERVICE, NULL,
+						BLUEZ_ADAPTER_INTERFACE,
+						DEVICE_REMOVED, device_removed,
+						NULL, NULL);
+
+	device_watch = g_dbus_add_signal_watch(connection, BLUEZ_SERVICE, NULL,
+						BLUEZ_DEVICE_INTERFACE,
+						PROPERTY_CHANGED, device_changed,
+						NULL, NULL);
+
+	network_watch = g_dbus_add_signal_watch(connection, BLUEZ_SERVICE,
+						NULL, BLUEZ_NETWORK_INTERFACE,
+						PROPERTY_CHANGED, network_changed,
+						NULL, NULL);
+
+	if (watch == 0 || added_watch == 0 || removed_watch == 0
+			|| adapter_watch == 0 || network_watch == 0
+				|| device_watch == 0
+					|| device_removed_watch == 0) {
+		err = -EIO;
+		goto remove;
+	}
+
+	err = connman_network_driver_register(&pan_driver);
+	if (err < 0)
+		goto remove;
+
+	err = connman_device_driver_register(&bluetooth_driver);
+	if (err < 0) {
+		connman_network_driver_unregister(&pan_driver);
+		goto remove;
+	}
+
+	err = connman_technology_driver_register(&tech_driver);
+	if (err < 0) {
+		connman_device_driver_unregister(&bluetooth_driver);
+		connman_network_driver_unregister(&pan_driver);
+		goto remove;
+	}
+
+	return 0;
+
+remove:
+	g_dbus_remove_watch(connection, watch);
+	g_dbus_remove_watch(connection, added_watch);
+	g_dbus_remove_watch(connection, removed_watch);
+	g_dbus_remove_watch(connection, adapter_watch);
+	g_dbus_remove_watch(connection, device_removed_watch);
+	g_dbus_remove_watch(connection, device_watch);
+	g_dbus_remove_watch(connection, network_watch);
+
+	dbus_connection_unref(connection);
+
+	return err;
+}
+
+static void bluetooth_exit(void)
+{
+	g_dbus_remove_watch(connection, watch);
+	g_dbus_remove_watch(connection, added_watch);
+	g_dbus_remove_watch(connection, removed_watch);
+	g_dbus_remove_watch(connection, adapter_watch);
+	g_dbus_remove_watch(connection, device_removed_watch);
+	g_dbus_remove_watch(connection, device_watch);
+	g_dbus_remove_watch(connection, network_watch);
+
+	/*
+	 * We unset the disabling of the Bluetooth device when shutting down
+	 * so that non-PAN BT connections are not affected.
+	 */
+	bluetooth_driver.disable = NULL;
+
+	bluetooth_disconnect(connection, NULL);
+
+	connman_technology_driver_unregister(&tech_driver);
+
+	connman_device_driver_unregister(&bluetooth_driver);
+	connman_network_driver_unregister(&pan_driver);
+
+	dbus_connection_unref(connection);
+}
+
+CONNMAN_PLUGIN_DEFINE(bluetooth_legacy, "Bluetooth technology plugin (legacy)",
+		VERSION, CONNMAN_PLUGIN_PRIORITY_LOW,
+		bluetooth_init, bluetooth_exit)
diff --git a/connman/plugins/connman-nmcompat.conf b/connman/plugins/connman-nmcompat.conf
new file mode 100644
index 0000000..5887a34
--- /dev/null
+++ b/connman/plugins/connman-nmcompat.conf
@@ -0,0 +1,14 @@
+<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
+ "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
+<busconfig>
+    <policy user="root">
+        <allow own="org.freedesktop.NetworkManager"/>
+        <allow send_destination="org.freedesktop.NetworkManager"/>
+    </policy>
+    <policy at_console="true">
+        <allow send_destination="org.freedesktop.NetworkManager"/>
+    </policy>
+    <policy context="default">
+        <deny send_destination="org.freedesktop.NetworkManager"/>
+    </policy>
+</busconfig>
diff --git a/connman/plugins/dundee.c b/connman/plugins/dundee.c
new file mode 100644
index 0000000..fd4e1eb
--- /dev/null
+++ b/connman/plugins/dundee.c
@@ -0,0 +1,886 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2012-2014  BMW Car IT GmbH.
+ *
+ *  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 <errno.h>
+
+#include <gdbus.h>
+
+#define CONNMAN_API_SUBJECT_TO_CHANGE
+#include <connman/plugin.h>
+#include <connman/device.h>
+#include <connman/network.h>
+#include <connman/service.h>
+#include <connman/inet.h>
+#include <connman/dbus.h>
+
+#define DUNDEE_SERVICE			"org.ofono.dundee"
+#define DUNDEE_MANAGER_INTERFACE	DUNDEE_SERVICE ".Manager"
+#define DUNDEE_DEVICE_INTERFACE		DUNDEE_SERVICE ".Device"
+
+#define DEVICE_ADDED			"DeviceAdded"
+#define DEVICE_REMOVED			"DeviceRemoved"
+#define PROPERTY_CHANGED		"PropertyChanged"
+
+#define GET_PROPERTIES			"GetProperties"
+#define SET_PROPERTY			"SetProperty"
+#define GET_DEVICES			"GetDevices"
+
+#define TIMEOUT 60000
+
+static DBusConnection *connection;
+
+static GHashTable *dundee_devices = NULL;
+
+struct dundee_data {
+	char *path;
+	char *name;
+
+	struct connman_device *device;
+	struct connman_network *network;
+
+	bool active;
+
+	int index;
+
+	/* IPv4 Settings */
+	enum connman_ipconfig_method method;
+	struct connman_ipaddress *address;
+	char *nameservers;
+
+	DBusPendingCall *call;
+};
+
+static char *get_ident(const char *path)
+{
+	char *pos;
+
+	if (*path != '/')
+		return NULL;
+
+	pos = strrchr(path, '/');
+	if (!pos)
+		return NULL;
+
+	return pos + 1;
+}
+
+static int create_device(struct dundee_data *info)
+{
+	struct connman_device *device;
+	char *ident;
+	int err;
+
+	DBG("%s", info->path);
+
+	ident = g_strdup(get_ident(info->path));
+	device = connman_device_create("dundee", CONNMAN_DEVICE_TYPE_BLUETOOTH);
+	if (!device) {
+		err = -ENOMEM;
+		goto out;
+	}
+
+	DBG("device %p", device);
+
+	connman_device_set_ident(device, ident);
+
+	connman_device_set_string(device, "Path", info->path);
+
+	connman_device_set_data(device, info);
+
+	err = connman_device_register(device);
+	if (err < 0) {
+		connman_error("Failed to register DUN device");
+		connman_device_unref(device);
+		goto out;
+	}
+
+	info->device = device;
+
+out:
+	g_free(ident);
+	return err;
+}
+
+static void destroy_device(struct dundee_data *info)
+{
+	connman_device_set_powered(info->device, false);
+
+	if (info->call)
+		dbus_pending_call_cancel(info->call);
+
+	if (info->network) {
+		connman_device_remove_network(info->device, info->network);
+		connman_network_unref(info->network);
+		info->network = NULL;
+	}
+
+	connman_device_unregister(info->device);
+	connman_device_unref(info->device);
+
+	info->device = NULL;
+}
+
+static void device_destroy(gpointer data)
+{
+	struct dundee_data *info = data;
+
+	if (info->device)
+		destroy_device(info);
+
+	g_free(info->path);
+	g_free(info->name);
+
+	g_free(info);
+}
+
+static int create_network(struct dundee_data *info)
+{
+	struct connman_network *network;
+	const char *group;
+	int err;
+
+	DBG("%s", info->path);
+
+	network = connman_network_create(info->path,
+				CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN);
+	if (!network)
+		return -ENOMEM;
+
+	DBG("network %p", network);
+
+	connman_network_set_data(network, info);
+
+	connman_network_set_string(network, "Path",
+				info->path);
+
+	connman_network_set_name(network, info->name);
+
+	group = get_ident(info->path);
+	connman_network_set_group(network, group);
+
+	err = connman_device_add_network(info->device, network);
+	if (err < 0) {
+		connman_network_unref(network);
+		return err;
+	}
+
+	info->network = network;
+
+	return 0;
+}
+
+static void set_connected(struct dundee_data *info)
+{
+	struct connman_service *service;
+
+	DBG("%s", info->path);
+
+	connman_inet_ifup(info->index);
+
+	service = connman_service_lookup_from_network(info->network);
+	if (!service)
+		return;
+
+	connman_service_create_ip4config(service, info->index);
+	connman_network_set_index(info->network, info->index);
+	connman_network_set_ipv4_method(info->network,
+					CONNMAN_IPCONFIG_METHOD_FIXED);
+	connman_network_set_ipaddress(info->network, info->address);
+	connman_network_set_nameservers(info->network, info->nameservers);
+
+	connman_network_set_connected(info->network, true);
+}
+
+static void set_disconnected(struct dundee_data *info)
+{
+	DBG("%s", info->path);
+
+	connman_network_set_connected(info->network, false);
+	connman_inet_ifdown(info->index);
+}
+
+static void set_property_reply(DBusPendingCall *call, void *user_data)
+{
+	struct dundee_data *info = user_data;
+	DBusMessage *reply;
+	DBusError error;
+
+	DBG("%s", info->path);
+
+	info->call = NULL;
+
+	dbus_error_init(&error);
+
+	reply = dbus_pending_call_steal_reply(call);
+
+	if (dbus_set_error_from_message(&error, reply)) {
+		connman_error("Failed to change property: %s %s %s",
+				info->path, error.name, error.message);
+		dbus_error_free(&error);
+
+		connman_network_set_error(info->network,
+					CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL);
+	}
+
+	dbus_message_unref(reply);
+
+	dbus_pending_call_unref(call);
+}
+
+static int set_property(struct dundee_data *info,
+			const char *property, int type, void *value)
+{
+	DBusMessage *message;
+	DBusMessageIter iter;
+
+	DBG("%s %s", info->path, property);
+
+	message = dbus_message_new_method_call(DUNDEE_SERVICE, info->path,
+					DUNDEE_DEVICE_INTERFACE, SET_PROPERTY);
+	if (!message)
+		return -ENOMEM;
+
+	dbus_message_iter_init_append(message, &iter);
+	connman_dbus_property_append_basic(&iter, property, type, value);
+
+	if (!dbus_connection_send_with_reply(connection, message,
+						&info->call, TIMEOUT)) {
+		connman_error("Failed to change property: %s %s",
+				info->path, property);
+		dbus_message_unref(message);
+		return -EINVAL;
+	}
+
+	if (!info->call) {
+		connman_error("D-Bus connection not available");
+		dbus_message_unref(message);
+		return -EINVAL;
+	}
+
+	dbus_pending_call_set_notify(info->call, set_property_reply,
+					info, NULL);
+
+	dbus_message_unref(message);
+
+	return -EINPROGRESS;
+}
+
+static int device_set_active(struct dundee_data *info)
+{
+	dbus_bool_t active = TRUE;
+
+	DBG("%s", info->path);
+
+	return set_property(info, "Active", DBUS_TYPE_BOOLEAN,
+				&active);
+}
+
+static int device_set_inactive(struct dundee_data *info)
+{
+	dbus_bool_t active = FALSE;
+	int err;
+
+	DBG("%s", info->path);
+
+	err = set_property(info, "Active", DBUS_TYPE_BOOLEAN,
+				&active);
+	if (err == -EINPROGRESS)
+		return 0;
+
+	return err;
+}
+
+static int network_probe(struct connman_network *network)
+{
+	DBG("network %p", network);
+
+	return 0;
+}
+
+static void network_remove(struct connman_network *network)
+{
+	DBG("network %p", network);
+}
+
+static int network_connect(struct connman_network *network)
+{
+	struct dundee_data *info = connman_network_get_data(network);
+
+	DBG("network %p", network);
+
+	return device_set_active(info);
+}
+
+static int network_disconnect(struct connman_network *network, bool user_initiated)
+{
+	struct dundee_data *info = connman_network_get_data(network);
+
+	DBG("network %p", network);
+
+	return device_set_inactive(info);
+}
+
+static struct connman_network_driver network_driver = {
+	.name		= "network",
+	.type		= CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN,
+	.probe		= network_probe,
+	.remove		= network_remove,
+	.connect	= network_connect,
+	.disconnect	= network_disconnect,
+};
+
+static int dundee_probe(struct connman_device *device)
+{
+	GHashTableIter iter;
+	gpointer key, value;
+
+	DBG("device %p", device);
+
+	if (!dundee_devices)
+		return -ENOTSUP;
+
+	g_hash_table_iter_init(&iter, dundee_devices);
+
+	while (g_hash_table_iter_next(&iter, &key, &value)) {
+		struct dundee_data *info = value;
+
+		if (device == info->device)
+			return 0;
+	}
+
+	return -ENOTSUP;
+}
+
+static void dundee_remove(struct connman_device *device)
+{
+	DBG("device %p", device);
+}
+
+static int dundee_enable(struct connman_device *device)
+{
+	DBG("device %p", device);
+
+	return 0;
+}
+
+static int dundee_disable(struct connman_device *device)
+{
+	DBG("device %p", device);
+
+	return 0;
+}
+
+static struct connman_device_driver dundee_driver = {
+	.name		= "dundee",
+	.type		= CONNMAN_DEVICE_TYPE_BLUETOOTH,
+	.probe		= dundee_probe,
+	.remove		= dundee_remove,
+	.enable		= dundee_enable,
+	.disable	= dundee_disable,
+};
+
+static char *extract_nameservers(DBusMessageIter *array)
+{
+	DBusMessageIter entry;
+	char *nameservers = NULL;
+	char *tmp;
+
+	dbus_message_iter_recurse(array, &entry);
+
+	while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
+		const char *nameserver;
+
+		dbus_message_iter_get_basic(&entry, &nameserver);
+
+		if (!nameservers) {
+			nameservers = g_strdup(nameserver);
+		} else {
+			tmp = nameservers;
+			nameservers = g_strdup_printf("%s %s", tmp, nameserver);
+			g_free(tmp);
+		}
+
+		dbus_message_iter_next(&entry);
+	}
+
+	return nameservers;
+}
+
+static void extract_settings(DBusMessageIter *array,
+				struct dundee_data *info)
+{
+	DBusMessageIter dict;
+	char *address = NULL, *gateway = NULL;
+	char *nameservers = NULL;
+	const char *interface = NULL;
+	int index = -1;
+
+	if (dbus_message_iter_get_arg_type(array) != DBUS_TYPE_ARRAY)
+		return;
+
+	dbus_message_iter_recurse(array, &dict);
+
+	while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
+		DBusMessageIter entry, value;
+		const char *key, *val;
+
+		dbus_message_iter_recurse(&dict, &entry);
+		dbus_message_iter_get_basic(&entry, &key);
+
+		dbus_message_iter_next(&entry);
+		dbus_message_iter_recurse(&entry, &value);
+
+		if (g_str_equal(key, "Interface")) {
+			dbus_message_iter_get_basic(&value, &interface);
+
+			DBG("Interface %s", interface);
+
+			index = connman_inet_ifindex(interface);
+
+			DBG("index %d", index);
+
+			if (index < 0)
+				break;
+		} else if (g_str_equal(key, "Address")) {
+			dbus_message_iter_get_basic(&value, &val);
+
+			address = g_strdup(val);
+
+			DBG("Address %s", address);
+		} else if (g_str_equal(key, "DomainNameServers")) {
+			nameservers = extract_nameservers(&value);
+
+			DBG("Nameservers %s", nameservers);
+		} else if (g_str_equal(key, "Gateway")) {
+			dbus_message_iter_get_basic(&value, &val);
+
+			gateway = g_strdup(val);
+
+			DBG("Gateway %s", gateway);
+		}
+
+		dbus_message_iter_next(&dict);
+	}
+
+	if (index < 0)
+		goto out;
+
+	info->address = connman_ipaddress_alloc(CONNMAN_IPCONFIG_TYPE_IPV4);
+	if (!info->address)
+		goto out;
+
+	info->index = index;
+	connman_ipaddress_set_ipv4(info->address, address, NULL, gateway);
+
+	info->nameservers = nameservers;
+
+out:
+	if (info->nameservers != nameservers)
+		g_free(nameservers);
+
+	g_free(address);
+	g_free(gateway);
+}
+
+static gboolean device_changed(DBusConnection *conn,
+				DBusMessage *message,
+				void *user_data)
+{
+	const char *path = dbus_message_get_path(message);
+	struct dundee_data *info = NULL;
+	DBusMessageIter iter, value;
+	const char *key;
+	const char *signature =	DBUS_TYPE_STRING_AS_STRING
+		DBUS_TYPE_VARIANT_AS_STRING;
+
+	if (!dbus_message_has_signature(message, signature)) {
+		connman_error("dundee signature does not match");
+		return TRUE;
+	}
+
+	info = g_hash_table_lookup(dundee_devices, path);
+	if (!info)
+		return TRUE;
+
+	if (!dbus_message_iter_init(message, &iter))
+		return TRUE;
+
+	dbus_message_iter_get_basic(&iter, &key);
+
+	dbus_message_iter_next(&iter);
+	dbus_message_iter_recurse(&iter, &value);
+
+	/*
+	 * Dundee guarantees the ordering of Settings and
+	 * Active. Settings will always be send before Active = True.
+	 * That means we don't have to order here.
+	 */
+	if (g_str_equal(key, "Active")) {
+		dbus_bool_t active;
+
+		dbus_message_iter_get_basic(&value, &active);
+		info->active = active;
+
+		DBG("%s Active %d", info->path, info->active);
+
+		if (info->active)
+			set_connected(info);
+		else
+			set_disconnected(info);
+	} else if (g_str_equal(key, "Settings")) {
+		DBG("%s Settings", info->path);
+
+		extract_settings(&value, info);
+	} else if (g_str_equal(key, "Name")) {
+		char *name;
+
+		dbus_message_iter_get_basic(&value, &name);
+
+		g_free(info->name);
+		info->name = g_strdup(name);
+
+		DBG("%s Name %s", info->path, info->name);
+
+		connman_network_set_name(info->network, info->name);
+		connman_network_update(info->network);
+	}
+
+	return TRUE;
+}
+
+static void add_device(const char *path, DBusMessageIter *properties)
+{
+	struct dundee_data *info;
+	int err;
+
+	info = g_hash_table_lookup(dundee_devices, path);
+	if (info)
+		return;
+
+	info = g_try_new0(struct dundee_data, 1);
+	if (!info)
+		return;
+
+	info->path = g_strdup(path);
+
+	while (dbus_message_iter_get_arg_type(properties) ==
+			DBUS_TYPE_DICT_ENTRY) {
+		DBusMessageIter entry, value;
+		const char *key;
+
+		dbus_message_iter_recurse(properties, &entry);
+		dbus_message_iter_get_basic(&entry, &key);
+
+		dbus_message_iter_next(&entry);
+		dbus_message_iter_recurse(&entry, &value);
+
+		if (g_str_equal(key, "Active")) {
+			dbus_bool_t active;
+
+			dbus_message_iter_get_basic(&value, &active);
+			info->active = active;
+
+			DBG("%s Active %d", info->path, info->active);
+		} else if (g_str_equal(key, "Settings")) {
+			DBG("%s Settings", info->path);
+
+			extract_settings(&value, info);
+		} else if (g_str_equal(key, "Name")) {
+			char *name;
+
+			dbus_message_iter_get_basic(&value, &name);
+
+			info->name = g_strdup(name);
+
+			DBG("%s Name %s", info->path, info->name);
+		}
+
+		dbus_message_iter_next(properties);
+	}
+
+	g_hash_table_insert(dundee_devices, g_strdup(path), info);
+
+	err = create_device(info);
+	if (err < 0)
+		goto out;
+
+	err = create_network(info);
+	if (err < 0) {
+		destroy_device(info);
+		goto out;
+	}
+
+	if (info->active)
+		set_connected(info);
+
+	return;
+
+out:
+	g_hash_table_remove(dundee_devices, path);
+}
+
+static gboolean device_added(DBusConnection *conn, DBusMessage *message,
+				void *user_data)
+{
+	DBusMessageIter iter, properties;
+	const char *path;
+	const char *signature = DBUS_TYPE_OBJECT_PATH_AS_STRING
+		DBUS_TYPE_ARRAY_AS_STRING
+		DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+		DBUS_TYPE_STRING_AS_STRING
+		DBUS_TYPE_VARIANT_AS_STRING
+		DBUS_DICT_ENTRY_END_CHAR_AS_STRING;
+
+	if (!dbus_message_has_signature(message, signature)) {
+		connman_error("dundee signature does not match");
+		return TRUE;
+	}
+
+	DBG("");
+
+	if (!dbus_message_iter_init(message, &iter))
+		return TRUE;
+
+	dbus_message_iter_get_basic(&iter, &path);
+
+	dbus_message_iter_next(&iter);
+	dbus_message_iter_recurse(&iter, &properties);
+
+	add_device(path, &properties);
+
+	return TRUE;
+}
+
+static void remove_device(DBusConnection *conn, const char *path)
+{
+	DBG("path %s", path);
+
+	g_hash_table_remove(dundee_devices, path);
+}
+
+static gboolean device_removed(DBusConnection *conn, DBusMessage *message,
+				void *user_data)
+{
+	const char *path;
+	const char *signature = DBUS_TYPE_OBJECT_PATH_AS_STRING;
+
+	if (!dbus_message_has_signature(message, signature)) {
+		connman_error("dundee signature does not match");
+		return TRUE;
+	}
+
+	dbus_message_get_args(message, NULL, DBUS_TYPE_OBJECT_PATH, &path,
+				DBUS_TYPE_INVALID);
+	remove_device(conn, path);
+	return TRUE;
+}
+
+static void manager_get_devices_reply(DBusPendingCall *call, void *user_data)
+{
+	DBusMessage *reply;
+	DBusError error;
+	DBusMessageIter array, dict;
+	const char *signature = DBUS_TYPE_ARRAY_AS_STRING
+		DBUS_STRUCT_BEGIN_CHAR_AS_STRING
+		DBUS_TYPE_OBJECT_PATH_AS_STRING
+		DBUS_TYPE_ARRAY_AS_STRING
+		DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+		DBUS_TYPE_STRING_AS_STRING
+		DBUS_TYPE_VARIANT_AS_STRING
+		DBUS_DICT_ENTRY_END_CHAR_AS_STRING
+		DBUS_STRUCT_END_CHAR_AS_STRING;
+
+	DBG("");
+
+	reply = dbus_pending_call_steal_reply(call);
+
+	if (!dbus_message_has_signature(reply, signature)) {
+		connman_error("dundee signature does not match");
+		goto done;
+	}
+
+	dbus_error_init(&error);
+
+	if (dbus_set_error_from_message(&error, reply)) {
+		connman_error("%s", error.message);
+		dbus_error_free(&error);
+		goto done;
+	}
+
+	if (!dbus_message_iter_init(reply, &array))
+		goto done;
+
+	dbus_message_iter_recurse(&array, &dict);
+
+	while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_STRUCT) {
+		DBusMessageIter value, properties;
+		const char *path;
+
+		dbus_message_iter_recurse(&dict, &value);
+		dbus_message_iter_get_basic(&value, &path);
+
+		dbus_message_iter_next(&value);
+		dbus_message_iter_recurse(&value, &properties);
+
+		add_device(path, &properties);
+
+		dbus_message_iter_next(&dict);
+	}
+
+done:
+	dbus_message_unref(reply);
+
+	dbus_pending_call_unref(call);
+}
+
+static int manager_get_devices(void)
+{
+	DBusMessage *message;
+	DBusPendingCall *call;
+
+	DBG("");
+
+	message = dbus_message_new_method_call(DUNDEE_SERVICE, "/",
+					DUNDEE_MANAGER_INTERFACE, GET_DEVICES);
+	if (!message)
+		return -ENOMEM;
+
+	if (!dbus_connection_send_with_reply(connection, message,
+						&call, TIMEOUT)) {
+		connman_error("Failed to call GetDevices()");
+		dbus_message_unref(message);
+		return -EINVAL;
+	}
+
+	if (!call) {
+		connman_error("D-Bus connection not available");
+		dbus_message_unref(message);
+		return -EINVAL;
+	}
+
+	dbus_pending_call_set_notify(call, manager_get_devices_reply,
+					NULL, NULL);
+
+	dbus_message_unref(message);
+
+	return -EINPROGRESS;
+}
+
+static void dundee_connect(DBusConnection *conn, void *user_data)
+{
+	DBG("connection %p", conn);
+
+	dundee_devices = g_hash_table_new_full(g_str_hash, g_str_equal,
+					g_free, device_destroy);
+
+	manager_get_devices();
+}
+
+static void dundee_disconnect(DBusConnection *conn, void *user_data)
+{
+	DBG("connection %p", conn);
+
+	g_hash_table_destroy(dundee_devices);
+	dundee_devices = NULL;
+}
+
+static guint watch;
+static guint added_watch;
+static guint removed_watch;
+static guint device_watch;
+
+static int dundee_init(void)
+{
+	int err;
+
+	connection = connman_dbus_get_connection();
+	if (!connection)
+		return -EIO;
+
+	watch = g_dbus_add_service_watch(connection, DUNDEE_SERVICE,
+			dundee_connect, dundee_disconnect, NULL, NULL);
+
+	added_watch = g_dbus_add_signal_watch(connection, DUNDEE_SERVICE, NULL,
+						DUNDEE_MANAGER_INTERFACE,
+						DEVICE_ADDED, device_added,
+						NULL, NULL);
+
+	removed_watch = g_dbus_add_signal_watch(connection, DUNDEE_SERVICE,
+						NULL, DUNDEE_MANAGER_INTERFACE,
+						DEVICE_REMOVED, device_removed,
+						NULL, NULL);
+
+	device_watch = g_dbus_add_signal_watch(connection, DUNDEE_SERVICE,
+						NULL, DUNDEE_DEVICE_INTERFACE,
+						PROPERTY_CHANGED,
+						device_changed,
+						NULL, NULL);
+
+
+	if (watch == 0 || added_watch == 0 || removed_watch == 0 ||
+			device_watch == 0) {
+		err = -EIO;
+		goto remove;
+	}
+
+	err = connman_network_driver_register(&network_driver);
+	if (err < 0)
+		goto remove;
+
+	err = connman_device_driver_register(&dundee_driver);
+	if (err < 0) {
+		connman_network_driver_unregister(&network_driver);
+		goto remove;
+	}
+
+	return 0;
+
+remove:
+	g_dbus_remove_watch(connection, watch);
+	g_dbus_remove_watch(connection, added_watch);
+	g_dbus_remove_watch(connection, removed_watch);
+	g_dbus_remove_watch(connection, device_watch);
+
+	dbus_connection_unref(connection);
+
+	return err;
+}
+
+static void dundee_exit(void)
+{
+	g_dbus_remove_watch(connection, watch);
+	g_dbus_remove_watch(connection, added_watch);
+	g_dbus_remove_watch(connection, removed_watch);
+	g_dbus_remove_watch(connection, device_watch);
+
+	connman_device_driver_unregister(&dundee_driver);
+	connman_network_driver_unregister(&network_driver);
+
+	dbus_connection_unref(connection);
+}
+
+CONNMAN_PLUGIN_DEFINE(dundee, "Dundee plugin", VERSION,
+		CONNMAN_PLUGIN_PRIORITY_DEFAULT, dundee_init, dundee_exit)
diff --git a/connman/plugins/ethernet.c b/connman/plugins/ethernet.c
new file mode 100644
index 0000000..64ef677
--- /dev/null
+++ b/connman/plugins/ethernet.c
@@ -0,0 +1,413 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2013  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 <net/if.h>
+#include <string.h>
+#include <sys/ioctl.h>
+#include <unistd.h>
+#include <stdio.h>
+
+#include <linux/if_vlan.h>
+#include <linux/sockios.h>
+
+#ifndef IFF_LOWER_UP
+#define IFF_LOWER_UP	0x10000
+#endif
+
+#include <glib.h>
+
+#define CONNMAN_API_SUBJECT_TO_CHANGE
+#include <connman/technology.h>
+#include <connman/plugin.h>
+#include <connman/device.h>
+#include <connman/inet.h>
+#include <connman/rtnl.h>
+#include <connman/log.h>
+#include <connman/setting.h>
+
+static bool eth_tethering = false;
+
+struct ethernet_data {
+	int index;
+	unsigned flags;
+	unsigned int watch;
+	struct connman_network *network;
+};
+
+
+static int get_vlan_vid(const char *ifname)
+{
+	struct vlan_ioctl_args vifr;
+	int vid;
+	int sk;
+
+	memset(&vifr, 0, sizeof(vifr));
+
+	sk = socket(AF_INET, SOCK_STREAM, 0);
+	if (sk < 0)
+		return -errno;
+
+	vifr.cmd = GET_VLAN_VID_CMD;
+	strncpy(vifr.device1, ifname, sizeof(vifr.device1));
+
+	if(ioctl(sk, SIOCSIFVLAN, &vifr) >= 0)
+		vid = vifr.u.VID;
+	else
+		vid = -errno;
+
+	close(sk);
+
+	return vid;
+}
+
+static int eth_network_probe(struct connman_network *network)
+{
+	DBG("network %p", network);
+
+	return 0;
+}
+
+static void eth_network_remove(struct connman_network *network)
+{
+	DBG("network %p", network);
+}
+
+static int eth_network_connect(struct connman_network *network)
+{
+	DBG("network %p", network);
+
+	connman_network_set_connected(network, true);
+
+	return 0;
+}
+
+static int eth_network_disconnect(struct connman_network *network, bool user_initiated)
+{
+	DBG("network %p", network);
+
+	connman_network_set_connected(network, false);
+
+	return 0;
+}
+
+static struct connman_network_driver eth_network_driver = {
+	.name		= "cable",
+	.type		= CONNMAN_NETWORK_TYPE_ETHERNET,
+	.probe		= eth_network_probe,
+	.remove		= eth_network_remove,
+	.connect	= eth_network_connect,
+	.disconnect	= eth_network_disconnect,
+};
+
+static void add_network(struct connman_device *device,
+			struct ethernet_data *ethernet)
+{
+	struct connman_network *network;
+	int index, vid;
+	char *ifname;
+
+	network = connman_network_create("carrier",
+					CONNMAN_NETWORK_TYPE_ETHERNET);
+	if (!network)
+		return;
+
+	index = connman_device_get_index(device);
+	connman_network_set_index(network, index);
+	ifname = connman_inet_ifname(index);
+	if (!ifname)
+		return;
+	vid = get_vlan_vid(ifname);
+
+	connman_network_set_name(network, "Wired");
+
+	if (connman_device_add_network(device, network) < 0) {
+		connman_network_unref(network);
+		return;
+	}
+
+	if (!eth_tethering) {
+		char group[10] = "cable";
+		/*
+		 * Prevent service from starting the reconnect
+		 * procedure as we do not want the DHCP client
+		 * to run when tethering.
+		 */
+		if (vid >= 0)
+			snprintf(group, sizeof(group), "%03x_cable", vid);
+
+		connman_network_set_group(network, group);
+	}
+
+	ethernet->network = network;
+	g_free(ifname);
+}
+
+static void remove_network(struct connman_device *device,
+				struct ethernet_data *ethernet)
+{
+	if (!ethernet->network)
+		return;
+
+	connman_device_remove_network(device, ethernet->network);
+	connman_network_unref(ethernet->network);
+
+	ethernet->network = NULL;
+}
+
+static void ethernet_newlink(unsigned flags, unsigned change, void *user_data)
+{
+	struct connman_device *device = user_data;
+	struct ethernet_data *ethernet = connman_device_get_data(device);
+
+	DBG("index %d flags %d change %d", ethernet->index, flags, change);
+
+	if ((ethernet->flags & IFF_UP) != (flags & IFF_UP)) {
+		if (flags & IFF_UP) {
+			DBG("power on");
+			connman_device_set_powered(device, true);
+		} else {
+			DBG("power off");
+			connman_device_set_powered(device, false);
+		}
+	}
+
+	if ((ethernet->flags & IFF_LOWER_UP) != (flags & IFF_LOWER_UP)) {
+		if (flags & IFF_LOWER_UP) {
+			DBG("carrier on");
+			add_network(device, ethernet);
+		} else {
+			DBG("carrier off");
+			remove_network(device, ethernet);
+		}
+	}
+
+	ethernet->flags = flags;
+}
+
+static int eth_dev_probe(struct connman_device *device)
+{
+	struct ethernet_data *ethernet;
+
+	DBG("device %p", device);
+
+	ethernet = g_try_new0(struct ethernet_data, 1);
+	if (!ethernet)
+		return -ENOMEM;
+
+	connman_device_set_data(device, ethernet);
+
+	ethernet->index = connman_device_get_index(device);
+	ethernet->flags = 0;
+
+	ethernet->watch = connman_rtnl_add_newlink_watch(ethernet->index,
+						ethernet_newlink, device);
+
+	return 0;
+}
+
+static void eth_dev_remove(struct connman_device *device)
+{
+	struct ethernet_data *ethernet = connman_device_get_data(device);
+
+	DBG("device %p", device);
+
+	connman_device_set_data(device, NULL);
+
+	connman_rtnl_remove_watch(ethernet->watch);
+
+	remove_network(device, ethernet);
+
+	g_free(ethernet);
+}
+
+static int eth_dev_enable(struct connman_device *device)
+{
+	struct ethernet_data *ethernet = connman_device_get_data(device);
+
+	DBG("device %p", device);
+
+	return connman_inet_ifup(ethernet->index);
+}
+
+static int eth_dev_disable(struct connman_device *device)
+{
+	struct ethernet_data *ethernet = connman_device_get_data(device);
+
+	DBG("device %p", device);
+
+	return connman_inet_ifdown(ethernet->index);
+}
+
+static struct connman_device_driver eth_dev_driver = {
+	.name		= "ethernet",
+	.type		= CONNMAN_DEVICE_TYPE_ETHERNET,
+	.probe		= eth_dev_probe,
+	.remove		= eth_dev_remove,
+	.enable		= eth_dev_enable,
+	.disable	= eth_dev_disable,
+};
+
+static int eth_tech_probe(struct connman_technology *technology)
+{
+	return 0;
+}
+
+static void eth_tech_remove(struct connman_technology *technology)
+{
+	DBG("");
+}
+
+static GList *eth_interface_list = NULL;
+
+static void eth_tech_add_interface(struct connman_technology *technology,
+			int index, const char *name, const char *ident)
+{
+	DBG("index %d name %s ident %s", index, name, ident);
+
+	if (g_list_find(eth_interface_list, GINT_TO_POINTER((int)index)))
+		return;
+
+	eth_interface_list = g_list_prepend(eth_interface_list,
+					(GINT_TO_POINTER((int) index)));
+}
+
+static void eth_tech_remove_interface(struct connman_technology *technology,
+								int index)
+{
+	DBG("index %d", index);
+
+	eth_interface_list = g_list_remove(eth_interface_list,
+					GINT_TO_POINTER((int) index));
+}
+
+static void eth_tech_enable_tethering(struct connman_technology *technology,
+						const char *bridge)
+{
+	GList *list;
+	struct ethernet_data *ethernet;
+
+	for (list = eth_interface_list; list; list = list->next) {
+		int index = GPOINTER_TO_INT(list->data);
+		struct connman_device *device =
+			connman_device_find_by_index(index);
+
+		if (device) {
+			ethernet = connman_device_get_data(device);
+			if (ethernet)
+				remove_network(device, ethernet);
+		}
+
+		connman_technology_tethering_notify(technology, true);
+
+		connman_inet_ifup(index);
+
+		connman_inet_add_to_bridge(index, bridge);
+
+		eth_tethering = true;
+	}
+}
+
+static void eth_tech_disable_tethering(struct connman_technology *technology,
+						const char *bridge)
+{
+	GList *list;
+
+	for (list = eth_interface_list; list; list = list->next) {
+		int index = GPOINTER_TO_INT(list->data);
+		struct connman_device *device =
+			connman_device_find_by_index(index);
+
+		connman_inet_remove_from_bridge(index, bridge);
+
+		connman_technology_tethering_notify(technology, false);
+
+		if (device)
+			connman_device_reconnect_service(device);
+
+		eth_tethering = false;
+	}
+}
+
+static int eth_tech_set_tethering(struct connman_technology *technology,
+				const char *identifier, const char *passphrase,
+				const char *bridge, bool enabled)
+{
+	if (!connman_technology_is_tethering_allowed(
+			CONNMAN_SERVICE_TYPE_ETHERNET))
+		return 0;
+
+	DBG("bridge %s enabled %d", bridge, enabled);
+
+	if (enabled)
+		eth_tech_enable_tethering(technology, bridge);
+	else
+		eth_tech_disable_tethering(technology, bridge);
+
+	return 0;
+}
+
+static struct connman_technology_driver eth_tech_driver = {
+	.name			= "ethernet",
+	.type			= CONNMAN_SERVICE_TYPE_ETHERNET,
+	.probe			= eth_tech_probe,
+	.remove			= eth_tech_remove,
+	.add_interface		= eth_tech_add_interface,
+	.remove_interface	= eth_tech_remove_interface,
+	.set_tethering		= eth_tech_set_tethering,
+};
+
+static int ethernet_init(void)
+{
+	int err;
+
+	err = connman_technology_driver_register(&eth_tech_driver);
+	if (err < 0)
+		return err;
+
+	err = connman_network_driver_register(&eth_network_driver);
+	if (err < 0)
+		return err;
+
+	err = connman_device_driver_register(&eth_dev_driver);
+	if (err < 0) {
+		connman_network_driver_unregister(&eth_network_driver);
+		return err;
+	}
+
+	return 0;
+}
+
+static void ethernet_exit(void)
+{
+	connman_technology_driver_unregister(&eth_tech_driver);
+
+	connman_network_driver_unregister(&eth_network_driver);
+
+	connman_device_driver_unregister(&eth_dev_driver);
+}
+
+CONNMAN_PLUGIN_DEFINE(ethernet, "Ethernet interface plugin", VERSION,
+		CONNMAN_PLUGIN_PRIORITY_DEFAULT, ethernet_init, ethernet_exit)
diff --git a/connman/plugins/gadget.c b/connman/plugins/gadget.c
new file mode 100644
index 0000000..40660e8
--- /dev/null
+++ b/connman/plugins/gadget.c
@@ -0,0 +1,358 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2012  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 <net/if.h>
+
+#ifndef IFF_LOWER_UP
+#define IFF_LOWER_UP	0x10000
+#endif
+
+#include <glib.h>
+
+#define CONNMAN_API_SUBJECT_TO_CHANGE
+#include <connman/technology.h>
+#include <connman/plugin.h>
+#include <connman/device.h>
+#include <connman/rtnl.h>
+#include <connman/inet.h>
+#include <connman/log.h>
+
+static bool gadget_tethering = false;
+
+struct gadget_data {
+	int index;
+	unsigned flags;
+	unsigned int watch;
+	struct connman_network *network;
+};
+
+static int gadget_network_probe(struct connman_network *network)
+{
+	DBG("network %p", network);
+
+	return 0;
+}
+
+static void gadget_network_remove(struct connman_network *network)
+{
+	DBG("network %p", network);
+}
+
+static int gadget_network_connect(struct connman_network *network)
+{
+	DBG("network %p", network);
+
+	connman_network_set_connected(network, true);
+
+	return 0;
+}
+
+static int gadget_network_disconnect(struct connman_network *network, bool user_initiated)
+{
+	DBG("network %p", network);
+
+	connman_network_set_connected(network, false);
+
+	return 0;
+}
+
+static struct connman_network_driver gadget_network_driver = {
+	.name		= "usb",
+	.type		= CONNMAN_NETWORK_TYPE_GADGET,
+	.probe		= gadget_network_probe,
+	.remove		= gadget_network_remove,
+	.connect	= gadget_network_connect,
+	.disconnect	= gadget_network_disconnect,
+};
+
+static void add_network(struct connman_device *device,
+			struct gadget_data *gadget)
+{
+	struct connman_network *network;
+	int index;
+
+	network = connman_network_create("gadget",
+					CONNMAN_NETWORK_TYPE_GADGET);
+	if (!network)
+		return;
+
+	index = connman_device_get_index(device);
+	connman_network_set_index(network, index);
+
+	connman_network_set_name(network, "Wired");
+
+	if (connman_device_add_network(device, network) < 0) {
+		connman_network_unref(network);
+		return;
+	}
+
+	if (!gadget_tethering)
+		/*
+		 * Prevent service from starting the reconnect
+		 * procedure as we do not want the DHCP client
+		 * to run when tethering.
+		 */
+		connman_network_set_group(network, "usb");
+
+	gadget->network = network;
+}
+
+static void remove_network(struct connman_device *device,
+				struct gadget_data *gadget)
+{
+	if (!gadget->network)
+		return;
+
+	connman_device_remove_network(device, gadget->network);
+	connman_network_unref(gadget->network);
+
+	gadget->network = NULL;
+}
+
+static void gadget_newlink(unsigned flags, unsigned change, void *user_data)
+{
+	struct connman_device *device = user_data;
+	struct gadget_data *gadget = connman_device_get_data(device);
+
+	DBG("index %d flags %d change %d", gadget->index, flags, change);
+
+	if ((gadget->flags & IFF_UP) != (flags & IFF_UP)) {
+		if (flags & IFF_UP) {
+			DBG("power on");
+			connman_device_set_powered(device, true);
+		} else {
+			DBG("power off");
+			connman_device_set_powered(device, false);
+		}
+	}
+
+	if ((gadget->flags & IFF_LOWER_UP) != (flags & IFF_LOWER_UP)) {
+		if (flags & IFF_LOWER_UP) {
+			DBG("carrier on");
+			add_network(device, gadget);
+		} else {
+			DBG("carrier off");
+			remove_network(device, gadget);
+		}
+	}
+
+	gadget->flags = flags;
+}
+
+static int gadget_dev_probe(struct connman_device *device)
+{
+	struct gadget_data *gadget;
+
+	DBG("device %p", device);
+
+	gadget = g_try_new0(struct gadget_data, 1);
+	if (!gadget)
+		return -ENOMEM;
+
+	connman_device_set_data(device, gadget);
+
+	gadget->index = connman_device_get_index(device);
+	gadget->flags = 0;
+
+	gadget->watch = connman_rtnl_add_newlink_watch(gadget->index,
+						gadget_newlink, device);
+
+	return 0;
+}
+
+static void gadget_dev_remove(struct connman_device *device)
+{
+	struct gadget_data *gadget = connman_device_get_data(device);
+
+	DBG("device %p", device);
+
+	connman_device_set_data(device, NULL);
+
+	connman_rtnl_remove_watch(gadget->watch);
+
+	remove_network(device, gadget);
+
+	g_free(gadget);
+}
+
+static int gadget_dev_enable(struct connman_device *device)
+{
+	struct gadget_data *gadget = connman_device_get_data(device);
+
+	DBG("device %p", device);
+
+	return connman_inet_ifup(gadget->index);
+}
+
+static int gadget_dev_disable(struct connman_device *device)
+{
+	struct gadget_data *gadget = connman_device_get_data(device);
+
+	DBG("device %p", device);
+
+	return connman_inet_ifdown(gadget->index);
+}
+
+static struct connman_device_driver gadget_dev_driver = {
+	.name		= "gadget",
+	.type		= CONNMAN_DEVICE_TYPE_GADGET,
+	.probe		= gadget_dev_probe,
+	.remove		= gadget_dev_remove,
+	.enable		= gadget_dev_enable,
+	.disable	= gadget_dev_disable,
+};
+
+static GList *cdc_interface_list = NULL;
+
+static void gadget_tech_add_interface(struct connman_technology *technology,
+			int index, const char *name, const char *ident)
+{
+	DBG("index %d name %s ident %s", index, name, ident);
+
+	if (g_list_find(cdc_interface_list, GINT_TO_POINTER((int)index)))
+		return;
+
+	cdc_interface_list = g_list_prepend(cdc_interface_list,
+					(GINT_TO_POINTER((int) index)));
+}
+
+static void gadget_tech_remove_interface(struct connman_technology *technology,
+								int index)
+{
+	DBG("index %d", index);
+
+	cdc_interface_list = g_list_remove(cdc_interface_list,
+					GINT_TO_POINTER((int) index));
+}
+
+static void gadget_tech_enable_tethering(struct connman_technology *technology,
+						const char *bridge)
+{
+	GList *list;
+
+	for (list = cdc_interface_list; list; list = list->next) {
+		int index = GPOINTER_TO_INT(list->data);
+		struct connman_device *device =
+			connman_device_find_by_index(index);
+		struct gadget_data *gadget;
+
+		if (device) {
+			gadget = connman_device_get_data(device);
+			if (gadget)
+				remove_network(device, gadget);
+		}
+
+		connman_technology_tethering_notify(technology, true);
+
+		connman_inet_ifup(index);
+
+		connman_inet_add_to_bridge(index, bridge);
+	}
+}
+
+static void gadget_tech_disable_tethering(struct connman_technology *technology,
+						const char *bridge)
+{
+	GList *list;
+
+	for (list = cdc_interface_list; list; list = list->next) {
+		int index = GPOINTER_TO_INT(list->data);
+
+		connman_inet_remove_from_bridge(index, bridge);
+
+		connman_inet_ifdown(index);
+
+		connman_technology_tethering_notify(technology, false);
+	}
+}
+
+static int gadget_tech_set_tethering(struct connman_technology *technology,
+				const char *identifier, const char *passphrase,
+				const char *bridge, bool enabled)
+{
+	DBG("bridge %s enabled %d", bridge, enabled);
+
+	if (enabled)
+		gadget_tech_enable_tethering(technology, bridge);
+	else
+		gadget_tech_disable_tethering(technology, bridge);
+
+	return 0;
+}
+
+static int gadget_tech_probe(struct connman_technology *technology)
+{
+	return 0;
+}
+
+static void gadget_tech_remove(struct connman_technology *technology)
+{
+	g_list_free(cdc_interface_list);
+
+	cdc_interface_list = NULL;
+}
+
+static struct connman_technology_driver gadget_tech_driver = {
+	.name			= "cdc_ethernet",
+	.type			= CONNMAN_SERVICE_TYPE_GADGET,
+	.probe			= gadget_tech_probe,
+	.remove			= gadget_tech_remove,
+	.add_interface		= gadget_tech_add_interface,
+	.remove_interface	= gadget_tech_remove_interface,
+	.set_tethering		= gadget_tech_set_tethering,
+};
+
+static int gadget_init(void)
+{
+	int err;
+
+	err = connman_technology_driver_register(&gadget_tech_driver);
+	if (err < 0) {
+		return err;
+	}
+
+	err = connman_network_driver_register(&gadget_network_driver);
+	if (err < 0)
+		return err;
+
+	err = connman_device_driver_register(&gadget_dev_driver);
+	if (err < 0) {
+		connman_technology_driver_unregister(&gadget_tech_driver);
+		return err;
+	}
+
+	return 0;
+}
+
+static void gadget_exit(void)
+{
+	connman_technology_driver_unregister(&gadget_tech_driver);
+	connman_network_driver_unregister(&gadget_network_driver);
+	connman_device_driver_unregister(&gadget_dev_driver);
+}
+
+CONNMAN_PLUGIN_DEFINE(gadget, "Gadget interface plugin", VERSION,
+		CONNMAN_PLUGIN_PRIORITY_DEFAULT, gadget_init, gadget_exit)
diff --git a/connman/plugins/hh2serial-gps.c b/connman/plugins/hh2serial-gps.c
new file mode 100644
index 0000000..99394e1
--- /dev/null
+++ b/connman/plugins/hh2serial-gps.c
@@ -0,0 +1,124 @@
+/*
+ *
+ *  hh2serial GPS
+ *
+ *  Copyright (C) 2007-2012  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 <stdio.h>
+#include <errno.h>
+
+#define CONNMAN_API_SUBJECT_TO_CHANGE
+#include <connman/plugin.h>
+#include <connman/device.h>
+#include <connman/log.h>
+
+static struct connman_device *hh2serial_device;
+
+static int set_reg(char *key, char *value)
+{
+	FILE *reg_file;
+
+	reg_file = fopen(key, "w");
+	if (!reg_file)
+		return -errno;
+
+	fprintf(reg_file, "%s", value);
+	fclose(reg_file);
+	return 0;
+}
+
+static int hh2serial_probe(struct connman_device *device)
+{
+	return 0;
+}
+
+static void hh2serial_remove(struct connman_device *device)
+{
+}
+
+static int hh2serial_enable(struct connman_device *device)
+{
+	DBG("");
+
+	set_reg("/sys/class/gpio/expo_rt", "85");
+	set_reg("/sys/class/gpio/gpio85/direction", "out");
+	set_reg("/sys/class/gpio/gpio85/value", "1");
+
+	return 0;
+}
+
+static int hh2serial_disable(struct connman_device *device)
+{
+	DBG("");
+
+	set_reg("/sys/class/gpio/expo_rt", "85");
+	set_reg("/sys/class/gpio/gpio85/direction", "out");
+	set_reg("/sys/class/gpio/gpio85/value", "0");
+
+	return 0;
+}
+
+static struct connman_device_driver hh2serial_device_driver = {
+	.name           = "hh2serial GPS",
+	.type           = CONNMAN_DEVICE_TYPE_GPS,
+	.enable         = hh2serial_enable,
+	.disable        = hh2serial_disable,
+	.probe		= hh2serial_probe,
+	.remove		= hh2serial_remove,
+};
+
+static int hh2serial_init(void)
+{
+	int err;
+
+	err = connman_device_driver_register(&hh2serial_device_driver);
+	if (err < 0)
+		return err;
+
+	hh2serial_device = connman_device_create("hh2serial_gps",
+						CONNMAN_DEVICE_TYPE_GPS);
+	if (!hh2serial_device) {
+		connman_device_driver_unregister(&hh2serial_device_driver);
+		return -ENODEV;
+	}
+
+	err = connman_device_register(hh2serial_device);
+	if (err < 0) {
+		connman_device_unref(hh2serial_device);
+		return err;
+	}
+
+	return 0;
+}
+
+static void hh2serial_exit(void)
+{
+	if (hh2serial_device) {
+		connman_device_unregister(hh2serial_device);
+		connman_device_unref(hh2serial_device);
+	}
+
+	connman_device_driver_unregister(&hh2serial_device_driver);
+}
+
+CONNMAN_PLUGIN_DEFINE(hh2serial_gps, "hh2serial GPS", VERSION,
+		CONNMAN_PLUGIN_PRIORITY_LOW, hh2serial_init, hh2serial_exit)
diff --git a/connman/plugins/iospm.c b/connman/plugins/iospm.c
new file mode 100644
index 0000000..fcb4cea
--- /dev/null
+++ b/connman/plugins/iospm.c
@@ -0,0 +1,111 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2012  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
+
+#define CONNMAN_API_SUBJECT_TO_CHANGE
+#include <connman/plugin.h>
+#include <connman/notifier.h>
+#include <connman/dbus.h>
+#include <connman/log.h>
+
+#define IOSPM_SERVICE		"com.intel.mid.ospm"
+#define IOSPM_INTERFACE		IOSPM_SERVICE ".Comms"
+
+#define IOSPM_BLUETOOTH		"/com/intel/mid/ospm/bluetooth"
+#define IOSPM_FLIGHT_MODE	"/com/intel/mid/ospm/flight_mode"
+
+static DBusConnection *connection;
+
+static void send_indication(const char *path, bool enabled)
+{
+	DBusMessage *message;
+	const char *method;
+
+	DBG("path %s enabled %d", path, enabled);
+
+	if (enabled)
+		method = "IndicateStart";
+	else
+		method = "IndicateStop";
+
+	message = dbus_message_new_method_call(IOSPM_SERVICE, path,
+						IOSPM_INTERFACE, method);
+	if (!message)
+		return;
+
+	dbus_message_set_no_reply(message, TRUE);
+
+	dbus_connection_send(connection, message, NULL);
+
+	dbus_message_unref(message);
+}
+
+static void iospm_service_enabled(enum connman_service_type type,
+						bool enabled)
+{
+	switch (type) {
+	case CONNMAN_SERVICE_TYPE_UNKNOWN:
+	case CONNMAN_SERVICE_TYPE_SYSTEM:
+	case CONNMAN_SERVICE_TYPE_ETHERNET:
+	case CONNMAN_SERVICE_TYPE_WIFI:
+	case CONNMAN_SERVICE_TYPE_CELLULAR:
+	case CONNMAN_SERVICE_TYPE_GPS:
+	case CONNMAN_SERVICE_TYPE_VPN:
+	case CONNMAN_SERVICE_TYPE_GADGET:
+	case CONNMAN_SERVICE_TYPE_P2P:
+		break;
+	case CONNMAN_SERVICE_TYPE_BLUETOOTH:
+		send_indication(IOSPM_BLUETOOTH, enabled);
+		break;
+	}
+}
+
+static void iospm_offline_mode(bool enabled)
+{
+	send_indication(IOSPM_FLIGHT_MODE, enabled);
+}
+
+static struct connman_notifier iospm_notifier = {
+	.name		= "iospm",
+	.priority	= CONNMAN_NOTIFIER_PRIORITY_DEFAULT,
+	.service_enabled= iospm_service_enabled,
+	.offline_mode	= iospm_offline_mode,
+};
+
+static int iospm_init(void)
+{
+	connection = connman_dbus_get_connection();
+
+	return connman_notifier_register(&iospm_notifier);
+}
+
+static void iospm_exit(void)
+{
+	connman_notifier_unregister(&iospm_notifier);
+
+	dbus_connection_unref(connection);
+}
+
+CONNMAN_PLUGIN_DEFINE(ospm, "Intel OSPM notification plugin", VERSION,
+		CONNMAN_PLUGIN_PRIORITY_DEFAULT, iospm_init, iospm_exit)
diff --git a/connman/plugins/loopback.c b/connman/plugins/loopback.c
new file mode 100644
index 0000000..e113887
--- /dev/null
+++ b/connman/plugins/loopback.c
@@ -0,0 +1,282 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2012  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 <unistd.h>
+#include <limits.h>
+#include <string.h>
+#include <sys/ioctl.h>
+#include <sys/inotify.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>
+#include <net/if.h>
+
+#include <glib.h>
+
+#define CONNMAN_API_SUBJECT_TO_CHANGE
+#include <connman/plugin.h>
+#include <connman/utsname.h>
+#include <connman/log.h>
+#include <connman/inet.h>
+
+static in_addr_t loopback_address;
+static in_addr_t loopback_netmask;
+
+static char system_hostname[HOST_NAME_MAX + 1];
+
+static void create_hostname(void)
+{
+	const char *name = "localhost";
+
+	if (sethostname(name, strlen(name)) < 0)
+		connman_error("Failed to set hostname to %s", name);
+
+	strncpy(system_hostname, name, HOST_NAME_MAX);
+}
+
+static int setup_hostname(void)
+{
+	char name[HOST_NAME_MAX + 1];
+
+	memset(system_hostname, 0, sizeof(system_hostname));
+
+	if (gethostname(system_hostname, HOST_NAME_MAX) < 0) {
+		connman_error("Failed to get current hostname");
+		return -EIO;
+	}
+
+	if (strlen(system_hostname) > 0 &&
+				strcmp(system_hostname, "(none)") != 0)
+		connman_info("System hostname is %s", system_hostname);
+	else
+		create_hostname();
+
+	memset(name, 0, sizeof(name));
+
+	if (getdomainname(name, HOST_NAME_MAX) < 0) {
+		connman_error("Failed to get current domainname");
+		return -EIO;
+	}
+
+	if (strlen(name) > 0 && strcmp(name, "(none)") != 0)
+		connman_info("System domainname is %s", name);
+
+	return 0;
+}
+
+static bool valid_loopback(int sk, struct ifreq *ifr)
+{
+	struct sockaddr_in *addr;
+	int err;
+	char buf[INET_ADDRSTRLEN];
+
+	/* It is possible to end up in situations in which the
+	 * loopback interface is up but has no valid address. In that
+	 * case, we expect EADDRNOTAVAIL and should return FALSE.
+	 */
+
+	err = ioctl(sk, SIOCGIFADDR, ifr);
+	if (err < 0) {
+		err = -errno;
+		connman_error("Getting address failed (%s)", strerror(-err));
+		return err != -EADDRNOTAVAIL ? TRUE : FALSE;
+	}
+
+	addr = (struct sockaddr_in *) &ifr->ifr_addr;
+	if (addr->sin_addr.s_addr != loopback_address) {
+		connman_warn("Invalid loopback address %s",
+			inet_ntop(AF_INET, &addr->sin_addr, buf, sizeof(buf)));
+		return false;
+	}
+
+	err = ioctl(sk, SIOCGIFNETMASK, ifr);
+	if (err < 0) {
+		err = -errno;
+		connman_error("Getting netmask failed (%s)", strerror(-err));
+		return true;
+	}
+
+	addr = (struct sockaddr_in *) &ifr->ifr_netmask;
+	if (addr->sin_addr.s_addr != loopback_netmask) {
+		connman_warn("Invalid loopback netmask %s",
+			inet_ntop(AF_INET, &addr->sin_addr, buf, sizeof(buf)));
+		return false;
+	}
+
+	return true;
+}
+
+static int setup_loopback(void)
+{
+	struct ifreq ifr;
+	struct sockaddr_in addr;
+	int sk, err;
+
+	sk = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
+	if (sk < 0)
+		return -errno;
+
+	memset(&ifr, 0, sizeof(ifr));
+	strcpy(ifr.ifr_name, "lo");
+
+	if (ioctl(sk, SIOCGIFFLAGS, &ifr) < 0) {
+		err = -errno;
+		goto done;
+	}
+
+	if (ifr.ifr_flags & IFF_UP) {
+		connman_info("Checking loopback interface settings");
+		if (valid_loopback(sk, &ifr)) {
+			err = -EALREADY;
+			goto done;
+		}
+
+		connman_warn("Correcting wrong loopback settings");
+	}
+
+	memset(&addr, 0, sizeof(addr));
+	addr.sin_family = AF_INET;
+	addr.sin_addr.s_addr = loopback_address;
+	memcpy(&ifr.ifr_addr, &addr, sizeof(ifr.ifr_addr));
+
+	err = ioctl(sk, SIOCSIFADDR, &ifr);
+	if (err < 0) {
+		err = -errno;
+		connman_error("Setting address failed (%s)", strerror(-err));
+		goto done;
+	}
+
+	memset(&addr, 0, sizeof(addr));
+	addr.sin_family = AF_INET;
+	addr.sin_addr.s_addr = loopback_netmask;
+	memcpy(&ifr.ifr_netmask, &addr, sizeof(ifr.ifr_netmask));
+
+	err = ioctl(sk, SIOCSIFNETMASK, &ifr);
+	if (err < 0) {
+		err = -errno;
+		connman_error("Setting netmask failed (%s)", strerror(-err));
+		goto done;
+	}
+
+	if (ioctl(sk, SIOCGIFFLAGS, &ifr) < 0) {
+		err = -errno;
+		goto done;
+	}
+
+	ifr.ifr_flags |= IFF_UP;
+
+	if (ioctl(sk, SIOCSIFFLAGS, &ifr) < 0) {
+		err = -errno;
+		connman_error("Activating loopback interface failed (%s)",
+							strerror(-err));
+		goto done;
+	}
+
+done:
+	close(sk);
+
+	return err;
+}
+
+static const char *loopback_get_hostname(void)
+{
+	return system_hostname;
+}
+
+static int loopback_set_hostname(const char *hostname)
+{
+	const char *ptr;
+	int err, len;
+
+	if (g_strcmp0(hostname, "<hostname>") == 0)
+		return 0;
+
+	len = strlen(hostname);
+
+	if (!connman_inet_check_hostname(hostname, len))
+		return -EINVAL;
+
+	if ((ptr = strstr(hostname, ".")))
+		len = ptr - hostname;
+
+	if (sethostname(hostname, len) < 0) {
+		err = -errno;
+		connman_error("Failed to set hostname to %s", hostname);
+		return err;
+	}
+
+	connman_info("Setting hostname to %s", hostname);
+
+	return 0;
+}
+
+static int loopback_set_domainname(const char *domainname)
+{
+	int err, len;
+
+	len = strlen(domainname);
+
+	if (!connman_inet_check_hostname(domainname, len))
+		return -EINVAL;
+
+	if (setdomainname(domainname, len) < 0) {
+		err = -errno;
+		connman_error("Failed to set domainname to %s", domainname);
+		return err;
+	}
+
+	connman_info("Setting domainname to %s", domainname);
+
+	return 0;
+}
+
+static struct connman_utsname_driver loopback_driver = {
+	.name		= "loopback",
+	.get_hostname	= loopback_get_hostname,
+	.set_hostname	= loopback_set_hostname,
+	.set_domainname	= loopback_set_domainname,
+};
+
+static int loopback_init(void)
+{
+	loopback_address = inet_addr("127.0.0.1");
+	loopback_netmask = inet_addr("255.0.0.0");
+
+	setup_loopback();
+
+	setup_hostname();
+
+	connman_utsname_driver_register(&loopback_driver);
+
+	return 0;
+}
+
+static void loopback_exit(void)
+{
+	connman_utsname_driver_unregister(&loopback_driver);
+}
+
+CONNMAN_PLUGIN_DEFINE(loopback, "Loopback device plugin", VERSION,
+		CONNMAN_PLUGIN_PRIORITY_HIGH, loopback_init, loopback_exit)
diff --git a/connman/plugins/mcc.h b/connman/plugins/mcc.h
new file mode 100644
index 0000000..0e0407c
--- /dev/null
+++ b/connman/plugins/mcc.h
@@ -0,0 +1,475 @@
+/*
+ * Mobile country code list from
+ * "LIST OF MOBILE COUNTRY OR GEOGRAPHICAL AREA CODES"
+ * (http://www.itu.int/publ/T-SP-E.212A-2007)
+ * combined with ISO 3166-1 alpha-2 list for two letter country codes
+ */
+
+char *mcc_country_codes[] = {
+	NULL, /* 200 */
+	NULL,
+	NULL,
+	NULL,
+	"NL",
+	NULL,
+	"BE",
+	NULL,
+	"FR",
+	NULL,
+	NULL,
+	NULL,
+	"MC",
+	"AD",
+	"ES",
+	NULL,
+	"HU",
+	NULL,
+	"BA",
+	"HR",
+	"RS",
+	NULL,
+	"IT",
+	NULL,
+	NULL,
+	"VA",
+	"RO",
+	NULL,
+	"CH",
+	NULL,
+	"CZ",
+	"SK",
+	"AT",
+	NULL,
+	"GB",
+	"GB",
+	NULL,
+	NULL,
+	"DK",
+	NULL,
+	"SE",
+	NULL,
+	"NO",
+	NULL,
+	"FI",
+	NULL,
+	"LT",
+	"LV",
+	"EE",
+	NULL,
+	"RU",
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	"UA",
+	NULL,
+	"BY",
+	NULL,
+	"MD",
+	"PL",
+	NULL,
+	"DE",
+	NULL,
+	NULL,
+	NULL,
+	"GI",
+	NULL,
+	"PT",
+	NULL,
+	"LU",
+	NULL,
+	"IE",
+	NULL,
+	"IS",
+	NULL,
+	"AL",
+	NULL,
+	"MT",
+	NULL,
+	"CY",
+	NULL,
+	"GE",
+	"AM",
+	"BG",
+	NULL,
+	"TR",
+	NULL,
+	"FO",
+	NULL,
+	"GL",
+	NULL,
+	"SM",
+	"SI",
+	"MK",
+	"LI",
+	NULL,
+	"ME",
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	"CA",
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	"PM",
+	NULL,
+	"US",
+	"US",
+	"US",
+	"US",
+	"US",
+	"US",
+	"US",
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	"PR",
+	NULL,
+	"VI",
+	NULL,
+	"MX",
+	NULL,
+	NULL,
+	NULL,
+	"JM",
+	NULL,
+	"MQ",
+	NULL,
+	"BB",
+	NULL,
+	"AG",
+	NULL,
+	"KY",
+	NULL,
+	"VG",
+	NULL,
+	"BM",
+	NULL,
+	"GD",
+	NULL,
+	"MS",
+	NULL,
+	"KN",
+	NULL,
+	"LC",
+	NULL,
+	"VC",
+	NULL,
+	"AN",
+	"AW",
+	"BS",
+	"AI",
+	"DM",
+	NULL,
+	"CU",
+	NULL,
+	"DO",
+	NULL,
+	"HT",
+	NULL,
+	"TT",
+	NULL,
+	"TC",
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	"AZ",
+	"KZ",
+	"BT",
+	NULL,
+	"IN",
+	"IN",
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	"PK",
+	NULL,
+	"AF",
+	"LK",
+	"MM",
+	"LB",
+	"JO",
+	"SY",
+	"IQ",
+	"KW",
+	"SA",
+	"YE",
+	"OM",
+	NULL,
+	"AE",
+	"IL",
+	"BH",
+	"QA",
+	"MN",
+	"NP",
+	"AE",
+	"AE",
+	"IR",
+	NULL,
+	"UZ",
+	NULL,
+	"TJ",
+	"KG",
+	"TM",
+	NULL,
+	"JP",
+	"JP",
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	"KR",
+	NULL,
+	"VN",
+	NULL,
+	"HK",
+	"MO",
+	"KH",
+	"LA",
+	NULL,
+	NULL,
+	"CN",
+	"CN",
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	"TW",
+	"KP",
+	NULL,
+	NULL,
+	"BD",
+	NULL,
+	"MV",
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 500 */
+	NULL,
+	"MY",
+	NULL,
+	NULL,
+	"AU",
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	"ID",
+	NULL,
+	NULL,
+	NULL,
+	"TL",
+	"PH",
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	"TH",
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	"SG",
+	NULL,
+	NULL,
+	"BN",
+	NULL,
+	"NZ",
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	"NR",
+	"PG",
+	NULL,
+	"TO",
+	"SB",
+	"VU",
+	"FJ",
+	"WF",
+	"AS",
+	"KI",
+	"NC",
+	"PF",
+	"CK",
+	"WS",
+	"FM",
+	"MH",
+	"PW",
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 600 */
+	NULL,
+	"EG",
+	"DZ",
+	"MA",
+	"TN",
+	"LY",
+	"GM",
+	"SN",
+	"MR",
+	"ML",
+	"GN",
+	"CI",
+	"BF",
+	"NE",
+	"TG",
+	"BJ",
+	"MU",
+	"LR",
+	"SL",
+	"GH",
+	"NG",
+	"TD",
+	"CF",
+	"CM",
+	"CV",
+	"ST",
+	"GQ",
+	"GA",
+	"CG",
+	"CD",
+	"AO",
+	"GW",
+	"SC",
+	"SD",
+	"RW",
+	"ET",
+	"SO",
+	"DJ",
+	"KE",
+	"TZ",
+	"UG",
+	"BI",
+	"MZ",
+	NULL,
+	"ZM",
+	"MG",
+	"TF",
+	"ZW",
+	"NA",
+	"MW",
+	"LS",
+	"BW",
+	"SZ",
+	"KM",
+	"ZA",
+	NULL,
+	"ER",
+	NULL,
+	NULL,
+	NULL,
+	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 700 */
+	NULL,
+	"BZ",
+	NULL,
+	"GT",
+	NULL,
+	"SV",
+	NULL,
+	"HN",
+	NULL,
+	"NI",
+	NULL,
+	"CR",
+	NULL,
+	"PA",
+	NULL,
+	"PE",
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	"AR",
+	NULL,
+	"BR",
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	"CL",
+	NULL,
+	"CO",
+	NULL,
+	"VE",
+	NULL,
+	"BO",
+	NULL,
+	"GY",
+	NULL,
+	"EC",
+	NULL,
+	"GF",
+	NULL,
+	"PY",
+	NULL,
+	"SR",
+	NULL,
+	"UY",
+	NULL,
+	"FK",
+	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 799 */
+};
diff --git a/connman/plugins/neard.c b/connman/plugins/neard.c
new file mode 100644
index 0000000..1a0fc1c
--- /dev/null
+++ b/connman/plugins/neard.c
@@ -0,0 +1,628 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2013  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 <stdio.h>
+#include <stdint.h>
+#include <string.h>
+#include <arpa/inet.h>
+
+#include <glib.h>
+
+#define CONNMAN_API_SUBJECT_TO_CHANGE
+#include <connman/plugin.h>
+#include <connman/dbus.h>
+#include <connman/technology.h>
+#include <connman/provision.h>
+
+#include <gdbus.h>
+
+#define TIMEOUT 30000
+
+#define NEARD_SERVICE "org.neard"
+#define NEARD_PATH "/"
+#define NEARD_MANAGER_INTERFACE "org.neard.Manager"
+#define NEARD_AGENT_INTERFACE "org.neard.HandoverAgent"
+#define NEARD_ERROR_INTERFACE "org.neard.HandoverAgent.Error"
+
+#define AGENT_PATH "/net/connman/neard_handover_agent"
+#define AGENT_TYPE "wifi"
+
+#define NEARD_SERVICE_GROUP "service_neard_provision"
+
+/* Configuration keys */
+#define SERVICE_KEY_TYPE               "Type"
+#define SERVICE_KEY_SSID               "SSID"
+#define SERVICE_KEY_PASSPHRASE         "Passphrase"
+#define SERVICE_KEY_HIDDEN             "Hidden"
+
+struct data_elements {
+	unsigned int value;
+	unsigned int length;
+	bool fixed_length;
+};
+
+typedef enum {
+	DE_AUTHENTICATION_TYPE = 0,
+	DE_NETWORK_KEY         = 1,
+	DE_SSID                = 2,
+	DE_MAX                 = 3,
+} DEid;
+
+static const struct data_elements  DEs[DE_MAX] = {
+	{ 0x1003, 2,  TRUE  },
+	{ 0x1027, 64, FALSE },
+	{ 0x1045, 32, FALSE },
+};
+
+#define DE_VAL_OPEN                 0x0001
+#define DE_VAL_PSK                  0x0022
+
+struct wifi_sc {
+	gchar *ssid;
+	gchar *passphrase;
+};
+
+static DBusConnection *connection = NULL;
+DBusPendingCall *register_call = NULL;
+bool agent_registered = false;
+static guint watch_id = 0;
+
+static int set_2b_into_tlv(uint8_t *tlv_msg, uint16_t val)
+{
+	uint16_t ne_val;
+	uint8_t *ins;
+
+	ins = (uint8_t *) &ne_val;
+
+	ne_val = htons(val);
+	tlv_msg[0] = ins[0];
+	tlv_msg[1] = ins[1];
+
+	return 2;
+}
+
+static int set_byte_array_into_tlv(uint8_t *tlv_msg,
+					uint8_t *array, int length)
+{
+	memcpy((void *)tlv_msg, (void *)array, length);
+	return length;
+}
+
+static uint8_t *encode_to_tlv(const char *ssid, const char *psk, int *length)
+{
+	uint16_t ssid_len, psk_len;
+	uint8_t *tlv_msg;
+	int pos = 0;
+
+	if (!ssid || !length)
+		return NULL;
+
+	ssid_len = strlen(ssid);
+
+	*length = 6 + 4 + ssid_len;
+	if (psk) {
+		psk_len = strlen(psk);
+		*length += 4 + psk_len;
+	} else
+		psk_len = 0;
+
+	tlv_msg = g_try_malloc0(sizeof(uint8_t) * (*length));
+	if (!tlv_msg)
+		return NULL;
+
+	pos += set_2b_into_tlv(tlv_msg+pos, DEs[DE_SSID].value);
+	pos += set_2b_into_tlv(tlv_msg+pos, ssid_len);
+	pos += set_byte_array_into_tlv(tlv_msg+pos, (uint8_t *)ssid, ssid_len);
+
+	pos += set_2b_into_tlv(tlv_msg+pos, DEs[DE_AUTHENTICATION_TYPE].value);
+	pos += set_2b_into_tlv(tlv_msg+pos,
+					DEs[DE_AUTHENTICATION_TYPE].length);
+	if (psk) {
+		pos += set_2b_into_tlv(tlv_msg+pos, DE_VAL_PSK);
+		pos += set_2b_into_tlv(tlv_msg+pos, DEs[DE_NETWORK_KEY].value);
+		pos += set_2b_into_tlv(tlv_msg+pos, psk_len);
+		pos += set_byte_array_into_tlv(tlv_msg+pos,
+						(uint8_t *)psk, psk_len);
+	} else
+		pos += set_2b_into_tlv(tlv_msg+pos, DE_VAL_OPEN);
+
+	return tlv_msg;
+}
+
+static DBusMessage *get_reply_on_error(DBusMessage *message, int error)
+{
+	if (error == ENOTSUP)
+		return g_dbus_create_error(message,
+					NEARD_ERROR_INTERFACE ".NotSupported",
+					"Operation is not supported");
+
+	return g_dbus_create_error(message,
+		NEARD_ERROR_INTERFACE ".Failed", "Invalid parameters");
+}
+
+static int parse_request_oob_params(DBusMessage *message,
+				const uint8_t **tlv_msg, int *length)
+{
+	DBusMessageIter iter;
+	DBusMessageIter array;
+	DBusMessageIter dict_entry;
+	const char *key;
+	int arg_type;
+
+	if (!tlv_msg || !length)
+		return -EINVAL;
+
+	dbus_message_iter_init(message, &iter);
+
+	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY)
+		return -EINVAL;
+
+	dbus_message_iter_recurse(&iter, &array);
+	arg_type = dbus_message_iter_get_arg_type(&array);
+	if (arg_type != DBUS_TYPE_DICT_ENTRY)
+		return -EINVAL;
+
+	while (arg_type != DBUS_TYPE_INVALID) {
+		dbus_message_iter_recurse(&array, &dict_entry);
+		if (dbus_message_iter_get_arg_type(&dict_entry) !=
+							DBUS_TYPE_STRING)
+			return -EINVAL;
+
+		dbus_message_iter_get_basic(&dict_entry, &key);
+		if (g_strcmp0(key, "WSC") == 0) {
+			DBusMessageIter value;
+			DBusMessageIter fixed_array;
+
+			dbus_message_iter_next(&dict_entry);
+			dbus_message_iter_recurse(&dict_entry, &value);
+
+			if (dbus_message_iter_get_arg_type(&value) !=
+							DBUS_TYPE_ARRAY)
+				return -EINVAL;
+
+			dbus_message_iter_recurse(&value, &fixed_array);
+			dbus_message_iter_get_fixed_array(&fixed_array,
+							tlv_msg, length);
+			return 0;
+		}
+
+		dbus_message_iter_next(&array);
+		arg_type = dbus_message_iter_get_arg_type(&array);
+	}
+
+	return -EINVAL;
+}
+
+static DBusMessage *create_request_oob_reply(DBusMessage *message)
+{
+	DBusMessage *reply;
+	DBusMessageIter iter;
+	DBusMessageIter dict;
+	const char *ssid, *psk;
+	uint8_t *tlv_msg;
+	int length;
+
+	if (!connman_technology_get_wifi_tethering(&ssid, &psk))
+		return get_reply_on_error(message, ENOTSUP);
+
+	tlv_msg = encode_to_tlv(ssid, psk, &length);
+	if (!tlv_msg)
+		return get_reply_on_error(message, ENOTSUP);
+
+	reply = dbus_message_new_method_return(message);
+	if (!reply)
+		goto out;
+
+	dbus_message_iter_init_append(reply, &iter);
+
+	connman_dbus_dict_open(&iter, &dict);
+
+	connman_dbus_dict_append_fixed_array(&dict, "WSC",
+					DBUS_TYPE_BYTE, &tlv_msg, length);
+
+	dbus_message_iter_close_container(&iter, &dict);
+
+out:
+	g_free(tlv_msg);
+
+	return reply;
+}
+
+static DBusMessage *request_oob_method(DBusConnection *dbus_conn,
+					DBusMessage *message, void *user_data)
+{
+	DBusMessageIter iter;
+
+	DBG("");
+
+	dbus_message_iter_init(message, &iter);
+
+	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY)
+		return get_reply_on_error(message, EINVAL);
+
+	return create_request_oob_reply(message);
+}
+
+static void free_wifi_sc(struct wifi_sc *wsc)
+{
+	if (!wsc)
+		return;
+
+	g_free(wsc->ssid);
+	g_free(wsc->passphrase);
+
+	g_free(wsc);
+}
+
+static inline int get_2b_from_tlv(const uint8_t *tlv_msg, uint16_t *val)
+{
+	*val = ntohs(tlv_msg[0] | (tlv_msg[1] << 8));
+
+	return 2;
+}
+
+static uint8_t *get_byte_array_from_tlv(const uint8_t *tlv_msg, int length)
+{
+	uint8_t *array;
+
+	array = g_try_malloc0(sizeof(uint8_t) * length);
+	if (!array)
+		return NULL;
+
+	memcpy((void *)array, (void *)tlv_msg, length*sizeof(uint8_t));
+
+	return array;
+}
+
+static char *get_string_from_tlv(const uint8_t *tlv_msg, int length)
+{
+	char *str;
+
+	str = g_try_malloc0((sizeof(char) * length) + 1);
+	if (!str)
+		return NULL;
+
+	memcpy((void *)str, (void *)tlv_msg, length*sizeof(char));
+
+	return str;
+}
+
+static inline DEid get_de_id(uint16_t attr)
+{
+	int i;
+
+	for (i = 0; i < DE_MAX && DEs[i].value != 0; i++) {
+		if (attr == DEs[i].value)
+			return i;
+	}
+
+	return DE_MAX;
+}
+
+static inline bool is_de_length_fine(DEid id, uint16_t length)
+{
+	if (DEs[id].fixed_length)
+		return (length == DEs[id].length);
+
+	return (length <= DEs[id].length);
+}
+
+static char *get_hexstr_from_byte_array(const uint8_t *bt, int length)
+{
+	char *hex_str;
+	int i, j;
+
+	hex_str = g_try_malloc0(((length*2)+1) * sizeof(char));
+	if (!hex_str)
+		return NULL;
+
+	for (i = 0, j = 0; i < length; i++, j += 2)
+		snprintf(hex_str+j, 3, "%02x", bt[i]);
+
+	return hex_str;
+}
+
+static struct wifi_sc *decode_from_tlv(const uint8_t *tlv_msg, int length)
+{
+	struct wifi_sc *wsc;
+	uint16_t attr, len;
+	uint8_t *bt;
+	int pos;
+	DEid id;
+
+	if (!tlv_msg || length == 0)
+		return NULL;
+
+	wsc = g_try_malloc0(sizeof(struct wifi_sc));
+	if (!wsc)
+		return NULL;
+
+	pos = 0;
+	while (pos < length) {
+		pos += get_2b_from_tlv(tlv_msg+pos, &attr);
+		pos += get_2b_from_tlv(tlv_msg+pos, &len);
+
+		if (len > length - pos)
+			goto error;
+
+		id = get_de_id(attr);
+		if (id == DE_MAX) {
+			pos += len;
+			continue;
+		}
+
+		if (!is_de_length_fine(id, len))
+			goto error;
+
+		switch (id) {
+		case DE_AUTHENTICATION_TYPE:
+			break;
+		case DE_NETWORK_KEY:
+			wsc->passphrase = get_string_from_tlv(tlv_msg+pos,
+									len);
+			break;
+		case DE_SSID:
+			bt = get_byte_array_from_tlv(tlv_msg+pos, len);
+			wsc->ssid = get_hexstr_from_byte_array(bt, len);
+			g_free(bt);
+
+			break;
+		case DE_MAX:
+			/* Falling back. Should never happen though. */
+		default:
+			break;
+		}
+
+		pos += len;
+	}
+
+	return wsc;
+
+error:
+	free_wifi_sc(wsc);
+	return NULL;
+}
+
+static int handle_wcs_data(const uint8_t *tlv_msg, int length)
+{
+	struct wifi_sc *wsc = NULL;
+	GKeyFile *keyfile = NULL;
+	int ret = -EINVAL;
+
+	wsc = decode_from_tlv(tlv_msg, length);
+	if (!wsc)
+		return -EINVAL;
+
+	if (!wsc->ssid)
+		goto out;
+
+	keyfile = g_key_file_new();
+	if (!keyfile) {
+		ret = -ENOMEM;
+		goto out;
+	}
+
+	g_key_file_set_string(keyfile, NEARD_SERVICE_GROUP,
+					SERVICE_KEY_TYPE, "wifi");
+	g_key_file_set_string(keyfile, NEARD_SERVICE_GROUP,
+					SERVICE_KEY_SSID, wsc->ssid);
+	g_key_file_set_boolean(keyfile, NEARD_SERVICE_GROUP,
+					SERVICE_KEY_HIDDEN, TRUE);
+
+	if (wsc->passphrase)
+		g_key_file_set_string(keyfile, NEARD_SERVICE_GROUP,
+				SERVICE_KEY_PASSPHRASE, wsc->passphrase);
+
+	ret = connman_config_provision_mutable_service(keyfile);
+
+out:
+	g_key_file_free(keyfile);
+	free_wifi_sc(wsc);
+	return ret;
+}
+
+static DBusMessage *push_oob_method(DBusConnection *dbus_conn,
+					DBusMessage *message, void *user_data)
+{
+	const uint8_t *tlv_msg;
+	int err = EINVAL;
+	int length;
+
+	DBG("");
+
+	if (parse_request_oob_params(message, &tlv_msg, &length) != 0)
+		return get_reply_on_error(message, err);
+
+	err = handle_wcs_data(tlv_msg, length);
+	if (err != 0)
+		return get_reply_on_error(message, err);
+
+	return g_dbus_create_reply(message, DBUS_TYPE_INVALID);
+}
+
+static DBusMessage *release_method(DBusConnection *dbus_conn,
+					DBusMessage *message, void *user_data)
+{
+	DBG("");
+
+	agent_registered = false;
+	g_dbus_unregister_interface(connection,
+					AGENT_PATH, NEARD_AGENT_INTERFACE);
+
+	return g_dbus_create_reply(message, DBUS_TYPE_INVALID);
+}
+
+static const GDBusMethodTable neard_methods[] = {
+	{ GDBUS_ASYNC_METHOD("RequestOOB",
+		GDBUS_ARGS({ "data", "a{sv}" }),
+		GDBUS_ARGS({ "data", "a{sv}" }), request_oob_method) },
+	{ GDBUS_ASYNC_METHOD("PushOOB",
+		GDBUS_ARGS({ "data", "a{sv}"}), NULL, push_oob_method) },
+	{ GDBUS_METHOD("Release", NULL, NULL, release_method) },
+	{ },
+};
+
+static void cleanup_register_call(void)
+{
+	if (register_call) {
+		dbus_pending_call_cancel(register_call);
+		dbus_pending_call_unref(register_call);
+		register_call = NULL;
+	}
+}
+
+static void register_agent_cb(DBusPendingCall *pending, void *user_data)
+{
+	DBusMessage *reply;
+
+	if (!dbus_pending_call_get_completed(pending))
+		return;
+
+	register_call = NULL;
+
+	reply = dbus_pending_call_steal_reply(pending);
+	if (!reply)
+		goto out;
+
+	if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) {
+		g_dbus_unregister_interface(connection,
+					AGENT_PATH, NEARD_AGENT_INTERFACE);
+	} else
+		agent_registered = true;
+
+	dbus_message_unref(reply);
+out:
+	dbus_pending_call_unref(pending);
+}
+
+static void register_agent(void)
+{
+	const char *path = AGENT_PATH;
+	const char *type = AGENT_TYPE;
+	DBusMessage *message;
+
+	message = dbus_message_new_method_call(NEARD_SERVICE, NEARD_PATH,
+						NEARD_MANAGER_INTERFACE,
+						"RegisterHandoverAgent");
+	if (!message)
+		return;
+
+	dbus_message_append_args(message, DBUS_TYPE_OBJECT_PATH,
+			&path, DBUS_TYPE_STRING, &type, DBUS_TYPE_INVALID);
+
+	if (!dbus_connection_send_with_reply(connection, message,
+						&register_call, TIMEOUT)) {
+		dbus_message_unref(message);
+		goto out;
+	}
+
+	if (!dbus_pending_call_set_notify(register_call,
+						register_agent_cb, NULL, NULL))
+		cleanup_register_call();
+
+out:
+	dbus_message_unref(message);
+}
+
+static void unregister_agent(void)
+{
+	const char *path = AGENT_PATH;
+	const char *type = AGENT_TYPE;
+	DBusMessage *message;
+
+	if (!agent_registered)
+		return cleanup_register_call();
+
+	agent_registered = false;
+
+	message = dbus_message_new_method_call(NEARD_SERVICE, NEARD_PATH,
+						NEARD_MANAGER_INTERFACE,
+						"UnregisterHandoverAgent");
+	if (message) {
+		dbus_message_append_args(message, DBUS_TYPE_OBJECT_PATH,
+			&path, DBUS_TYPE_STRING, &type, DBUS_TYPE_INVALID);
+		g_dbus_send_message(connection, message);
+	}
+
+	g_dbus_unregister_interface(connection,
+					AGENT_PATH, NEARD_AGENT_INTERFACE);
+}
+
+static void neard_is_present(DBusConnection *conn, void *user_data)
+{
+	DBG("");
+
+	if (agent_registered)
+		return;
+
+	if (g_dbus_register_interface(connection, AGENT_PATH,
+					NEARD_AGENT_INTERFACE, neard_methods,
+					NULL, NULL, NULL, NULL))
+		register_agent();
+}
+
+static void neard_is_out(DBusConnection *conn, void *user_data)
+{
+	DBG("");
+
+	if (agent_registered) {
+		g_dbus_unregister_interface(connection,
+					AGENT_PATH, NEARD_AGENT_INTERFACE);
+		agent_registered = false;
+	}
+
+	cleanup_register_call();
+}
+
+static int neard_init(void)
+{
+	connection = connman_dbus_get_connection();
+	if (!connection)
+		return -EIO;
+
+	watch_id = g_dbus_add_service_watch(connection, NEARD_SERVICE,
+						neard_is_present, neard_is_out,
+						NULL, NULL);
+	if (watch_id == 0) {
+		dbus_connection_unref(connection);
+		return -ENOMEM;
+	}
+
+	return 0;
+}
+
+static void neard_exit(void)
+{
+	unregister_agent();
+
+	if (watch_id != 0)
+		g_dbus_remove_watch(connection, watch_id);
+	if (connection)
+		dbus_connection_unref(connection);
+}
+
+CONNMAN_PLUGIN_DEFINE(neard, "Neard handover plugin", VERSION,
+		CONNMAN_PLUGIN_PRIORITY_DEFAULT, neard_init, neard_exit)
diff --git a/connman/plugins/nmcompat.c b/connman/plugins/nmcompat.c
new file mode 100644
index 0000000..883ce9b
--- /dev/null
+++ b/connman/plugins/nmcompat.c
@@ -0,0 +1,284 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2012  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 <gdbus.h>
+
+#define CONNMAN_API_SUBJECT_TO_CHANGE
+#include <connman/plugin.h>
+#include <connman/log.h>
+#include <connman/notifier.h>
+#include <connman/dbus.h>
+
+enum {
+	NM_STATE_UNKNOWN          = 0,
+	NM_STATE_ASLEEP           = 10,
+	NM_STATE_DISCONNECTED     = 20,
+	NM_STATE_DISCONNECTING    = 30,
+	NM_STATE_CONNECTING       = 40,
+	NM_STATE_CONNECTED_LOCAL  = 50,
+	NM_STATE_CONNECTED_SITE   = 60,
+	NM_STATE_CONNECTED_GLOBAL = 70
+};
+
+#define NM_SERVICE    "org.freedesktop.NetworkManager"
+#define NM_PATH       "/org/freedesktop/NetworkManager"
+#define NM_INTERFACE  NM_SERVICE
+
+#define DBUS_PROPERTIES_INTERFACE	"org.freedesktop.DBus.Properties"
+
+static DBusConnection *connection = NULL;
+static struct connman_service *current_service = NULL;
+static dbus_uint32_t nm_state = NM_STATE_UNKNOWN;
+
+static void state_changed(dbus_uint32_t state)
+{
+	DBusMessage *signal;
+
+	DBG("state %d", state);
+
+	signal = dbus_message_new_signal(NM_PATH, NM_INTERFACE,
+						"StateChanged");
+	if (!signal)
+		return;
+
+	dbus_message_append_args(signal, DBUS_TYPE_UINT32, &state,
+						DBUS_TYPE_INVALID);
+
+	g_dbus_send_message(connection, signal);
+}
+
+static void properties_changed(dbus_uint32_t state)
+{
+	const char *key = "State";
+	DBusMessageIter iter, dict, dict_entry, dict_val;
+	DBusMessage *signal;
+
+	DBG("state %d", state);
+
+	signal = dbus_message_new_signal(NM_PATH, NM_INTERFACE,
+						"PropertiesChanged");
+	if (!signal)
+		return;
+
+	dbus_message_iter_init_append(signal, &iter);
+
+	dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
+					DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+					DBUS_TYPE_STRING_AS_STRING
+					DBUS_TYPE_VARIANT_AS_STRING
+					DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
+					&dict);
+
+	dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY,
+							NULL, &dict_entry);
+
+	dbus_message_iter_append_basic(&dict_entry, DBUS_TYPE_STRING, &key);
+
+	dbus_message_iter_open_container(&dict_entry, DBUS_TYPE_VARIANT,
+					DBUS_TYPE_UINT32_AS_STRING, &dict_val);
+
+	dbus_message_iter_append_basic(&dict_val, DBUS_TYPE_UINT32, &state);
+
+	dbus_message_iter_close_container(&dict_entry, &dict_val);
+	dbus_message_iter_close_container(&dict, &dict_entry);
+	dbus_message_iter_close_container(&iter, &dict);
+
+	g_dbus_send_message(connection, signal);
+}
+
+static void default_changed(struct connman_service *service)
+{
+	DBG("service %p", service);
+
+	if (!service)
+		nm_state = NM_STATE_DISCONNECTED;
+	else
+		nm_state = NM_STATE_CONNECTED_LOCAL;
+
+	state_changed(nm_state);
+	properties_changed(nm_state);
+
+	current_service = service;
+}
+
+static void service_state_changed(struct connman_service *service,
+					enum connman_service_state state)
+{
+	DBG("service %p state %d", service, state);
+
+	if (!current_service || current_service != service)
+		return;
+
+	switch (state) {
+	case CONNMAN_SERVICE_STATE_UNKNOWN:
+		nm_state = NM_STATE_UNKNOWN;
+		break;
+	case CONNMAN_SERVICE_STATE_FAILURE:
+	case CONNMAN_SERVICE_STATE_IDLE:
+		nm_state = NM_STATE_DISCONNECTED;
+		break;
+	case CONNMAN_SERVICE_STATE_ASSOCIATION:
+	case CONNMAN_SERVICE_STATE_CONFIGURATION:
+		nm_state = NM_STATE_CONNECTING;
+		break;
+	case CONNMAN_SERVICE_STATE_READY:
+		nm_state = NM_STATE_CONNECTED_LOCAL;
+		break;
+	case CONNMAN_SERVICE_STATE_ONLINE:
+		nm_state = NM_STATE_CONNECTED_GLOBAL;
+		break;
+	case CONNMAN_SERVICE_STATE_DISCONNECT:
+		nm_state = NM_STATE_DISCONNECTING;
+		break;
+	}
+
+	state_changed(nm_state);
+	properties_changed(nm_state);
+}
+
+static void offline_mode(bool enabled)
+{
+	DBG("enabled %d", enabled);
+
+	if (enabled)
+		nm_state = NM_STATE_ASLEEP;
+	else
+		nm_state = NM_STATE_DISCONNECTED;
+
+	state_changed(nm_state);
+	properties_changed(nm_state);
+
+	current_service = NULL;
+}
+
+static struct connman_notifier notifier = {
+	.name			= "nmcompat",
+	.priority		= CONNMAN_NOTIFIER_PRIORITY_DEFAULT,
+	.default_changed	= default_changed,
+	.service_state_changed	= service_state_changed,
+	.offline_mode		= offline_mode,
+};
+
+static DBusMessage *property_get(DBusConnection *conn,
+					DBusMessage *msg, void *data)
+{
+	const char *interface, *key;
+
+	dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &interface,
+				DBUS_TYPE_STRING, &key, DBUS_TYPE_INVALID);
+
+	DBG("interface %s property %s", interface, key);
+
+	if (!g_str_equal(interface, NM_INTERFACE))
+		return dbus_message_new_error(msg, DBUS_ERROR_FAILED,
+						"Unsupported interface");
+
+	if (g_str_equal(key, "State")) {
+		DBusMessage *reply;
+		DBusMessageIter iter, value;
+
+		DBG("state %d", nm_state);
+
+		reply = dbus_message_new_method_return(msg);
+		if (!reply)
+			return NULL;
+
+		dbus_message_iter_init_append(reply, &iter);
+
+		dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT,
+					DBUS_TYPE_UINT32_AS_STRING, &value);
+		dbus_message_iter_append_basic(&value,
+						DBUS_TYPE_UINT32, &nm_state);
+		dbus_message_iter_close_container(&iter, &value);
+
+		return reply;
+	}
+
+	return dbus_message_new_error(msg, DBUS_ERROR_FAILED,
+						"Unsupported property");
+}
+
+static const GDBusMethodTable methods[] = {
+	{ GDBUS_METHOD("Get",
+			GDBUS_ARGS({ "interface", "s" }, { "key", "s" }),
+			GDBUS_ARGS({ "property", "v" }), property_get) },
+	{ },
+};
+
+static const GDBusSignalTable signals[] = {
+	{ GDBUS_SIGNAL("PropertiesChanged",
+			GDBUS_ARGS({ "properties", "a{sv}" })) },
+	{ GDBUS_SIGNAL("StateChanged",
+			GDBUS_ARGS({ "state", "u" })) },
+	{ },
+};
+
+static int nmcompat_init(void)
+{
+	DBG("");
+
+	connection = connman_dbus_get_connection();
+	if (!connection)
+		return -1;
+
+	if (!g_dbus_request_name(connection, NM_SERVICE, NULL)) {
+		connman_error("nmcompat: failed to register service");
+		return -1;
+	}
+
+	if (connman_notifier_register(&notifier) < 0) {
+		connman_error("nmcompat: failed to register notifier");
+		return -1;
+	}
+
+	if (!g_dbus_register_interface(connection, NM_PATH,
+					DBUS_PROPERTIES_INTERFACE, methods,
+					signals, NULL, NULL, NULL)) {
+		connman_error("nmcompat: failed to register "
+						DBUS_PROPERTIES_INTERFACE);
+		return -1;
+	}
+
+	return 0;
+}
+
+static void nmcompat_exit(void)
+{
+	DBG("");
+
+	connman_notifier_unregister(&notifier);
+
+	if (!connection)
+		return;
+
+	g_dbus_unregister_interface(connection, NM_PATH,
+					DBUS_PROPERTIES_INTERFACE);
+
+	dbus_connection_unref(connection);
+}
+
+CONNMAN_PLUGIN_DEFINE(nmcompat, "NetworkManager compatibility interfaces",
+			VERSION, CONNMAN_PLUGIN_PRIORITY_DEFAULT,
+			nmcompat_init, nmcompat_exit)
diff --git a/connman/plugins/ofono.c b/connman/plugins/ofono.c
new file mode 100644
index 0000000..036993c
--- /dev/null
+++ b/connman/plugins/ofono.c
@@ -0,0 +1,2841 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2013  Intel Corporation. All rights reserved.
+ *  Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+ *  Copyright (C) 2011-2014  BMW Car IT GmbH.
+ *
+ *  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 <gdbus.h>
+#include <string.h>
+#include <stdint.h>
+
+#define CONNMAN_API_SUBJECT_TO_CHANGE
+#include <connman/plugin.h>
+#include <connman/device.h>
+#include <connman/network.h>
+#include <connman/inet.h>
+#include <connman/dbus.h>
+#include <connman/log.h>
+#include <connman/technology.h>
+
+#include "mcc.h"
+
+#define OFONO_SERVICE			"org.ofono"
+
+#define OFONO_MANAGER_INTERFACE		OFONO_SERVICE ".Manager"
+#define OFONO_MODEM_INTERFACE		OFONO_SERVICE ".Modem"
+#define OFONO_SIM_INTERFACE		OFONO_SERVICE ".SimManager"
+#define OFONO_NETREG_INTERFACE		OFONO_SERVICE ".NetworkRegistration"
+#define OFONO_CM_INTERFACE		OFONO_SERVICE ".ConnectionManager"
+#define OFONO_CONTEXT_INTERFACE		OFONO_SERVICE ".ConnectionContext"
+#define OFONO_CDMA_CM_INTERFACE		OFONO_SERVICE ".cdma.ConnectionManager"
+#define OFONO_CDMA_NETREG_INTERFACE	OFONO_SERVICE ".cdma.NetworkRegistration"
+
+#define MODEM_ADDED			"ModemAdded"
+#define MODEM_REMOVED			"ModemRemoved"
+#define PROPERTY_CHANGED		"PropertyChanged"
+#define CONTEXT_ADDED			"ContextAdded"
+#define CONTEXT_REMOVED			"ContextRemoved"
+
+#define GET_PROPERTIES			"GetProperties"
+#define SET_PROPERTY			"SetProperty"
+#define GET_MODEMS			"GetModems"
+#define GET_CONTEXTS			"GetContexts"
+
+#define TIMEOUT 40000
+
+enum ofono_api {
+	OFONO_API_SIM =		0x1,
+	OFONO_API_NETREG =	0x2,
+	OFONO_API_CM =		0x4,
+	OFONO_API_CDMA_NETREG =	0x8,
+	OFONO_API_CDMA_CM =	0x10,
+};
+
+/*
+ * The way this plugin works is following:
+ *
+ *   powered -> SubscriberIdentity or Online = True -> gprs, context ->
+ *     attached -> netreg -> ready
+ *
+ * Depending on the modem type, this plugin will behave differently.
+ *
+ * GSM working flow:
+ *
+ * When a new modem appears, the plugin always powers it up. This
+ * allows the plugin to create a connman_device. The core will call
+ * modem_enable() if the technology is enabled. modem_enable() will
+ * then set the modem online. If the technology is disabled then
+ * modem_disable() will just set the modem offline. The modem is
+ * always kept powered all the time.
+ *
+ * After setting the modem online the plugin waits for the
+ * ConnectionManager and ConnectionContext to appear. When the context
+ * signals that it is attached and the NetworkRegistration interface
+ * appears, a new Service will be created and registered at the core.
+ *
+ * When asked to connect to the network (network_connect()) the plugin
+ * will set the Active property on the context. If this operation is
+ * successful the modem is connected to the network. oFono will inform
+ * the plugin about IP configuration through the updating the context's
+ * properties.
+ *
+ * CDMA working flow:
+ *
+ * When a new modem appears, the plugin always powers it up. This
+ * allows the plugin to create connman_device either using IMSI either
+ * using modem Serial if the modem got a SIM interface or not.
+ *
+ * As for GSM, the core will call modem_enable() if the technology
+ * is enabled. modem_enable() will then set the modem online.
+ * If the technology is disabled then modem_disable() will just set the
+ * modem offline. The modem is always kept powered all the time.
+ *
+ * After setting the modem online the plugin waits for CdmaConnectionManager
+ * interface to appear. Then, once CdmaNetworkRegistration appears, a new
+ * Service will be created and registered at the core.
+ *
+ * When asked to connect to the network (network_connect()) the plugin
+ * will power up the CdmaConnectionManager interface.
+ * If the operation is successful the modem is connected to the network.
+ * oFono will inform the plugin about IP configuration through the
+ * updating CdmaConnectionManager settings properties.
+ */
+
+static DBusConnection *connection;
+
+static GHashTable *modem_hash;
+static GHashTable *context_hash;
+
+struct network_context {
+	char *path;
+	int index;
+
+	enum connman_ipconfig_method ipv4_method;
+	struct connman_ipaddress *ipv4_address;
+	char *ipv4_nameservers;
+
+	enum connman_ipconfig_method ipv6_method;
+	struct connman_ipaddress *ipv6_address;
+	char *ipv6_nameservers;
+};
+
+struct modem_data {
+	char *path;
+
+	struct connman_device *device;
+	struct connman_network *network;
+
+	struct network_context *context;
+
+	/* Modem Interface */
+	char *serial;
+	bool powered;
+	bool online;
+	uint8_t interfaces;
+	bool ignore;
+
+	bool set_powered;
+
+	/* CDMA ConnectionManager Interface */
+	bool cdma_cm_powered;
+
+	/* ConnectionManager Interface */
+	bool attached;
+	bool cm_powered;
+
+	/* ConnectionContext Interface */
+	bool active;
+	bool valid_apn; /* APN is 'valid' if length > 0 */
+
+	/* SimManager Interface */
+	char *imsi;
+
+	/* Netreg Interface */
+	char *name;
+	uint8_t strength;
+	uint8_t data_strength; /* 1xEVDO signal strength */
+	bool registered;
+	bool roaming;
+
+	/* pending calls */
+	DBusPendingCall	*call_set_property;
+	DBusPendingCall	*call_get_properties;
+	DBusPendingCall *call_get_contexts;
+};
+
+static const char *api2string(enum ofono_api api)
+{
+	switch (api) {
+	case OFONO_API_SIM:
+		return "sim";
+	case OFONO_API_NETREG:
+		return "netreg";
+	case OFONO_API_CM:
+		return "cm";
+	case OFONO_API_CDMA_NETREG:
+		return "cdma-netreg";
+	case OFONO_API_CDMA_CM:
+		return "cmda-cm";
+	}
+
+	return "unknown";
+}
+
+static char *get_ident(const char *path)
+{
+	char *pos;
+
+	if (*path != '/')
+		return NULL;
+
+	pos = strrchr(path, '/');
+	if (!pos)
+		return NULL;
+
+	return pos + 1;
+}
+
+static struct network_context *network_context_alloc(const char *path)
+{
+	struct network_context *context;
+
+	context = g_try_new0(struct network_context, 1);
+	if (!context)
+		return NULL;
+
+	context->path = g_strdup(path);
+	context->index = -1;
+
+	context->ipv4_method = CONNMAN_IPCONFIG_METHOD_UNKNOWN;
+	context->ipv4_address = NULL;
+	context->ipv4_nameservers = NULL;
+
+	context->ipv6_method = CONNMAN_IPCONFIG_METHOD_UNKNOWN;
+	context->ipv6_address = NULL;
+	context->ipv6_nameservers = NULL;
+
+	return context;
+}
+
+static void network_context_free(struct network_context *context)
+{
+	g_free(context->path);
+
+	connman_ipaddress_free(context->ipv4_address);
+	g_free(context->ipv4_nameservers);
+
+	connman_ipaddress_free(context->ipv6_address);
+	g_free(context->ipv6_nameservers);
+
+	free(context);
+}
+
+static void set_connected(struct modem_data *modem)
+{
+	struct connman_service *service;
+	bool setip = false;
+	enum connman_ipconfig_method method;
+	char *nameservers;
+	int index;
+
+	DBG("%s", modem->path);
+
+	index = modem->context->index;
+
+	method = modem->context->ipv4_method;
+	if (index < 0 || (!modem->context->ipv4_address &&
+				method == CONNMAN_IPCONFIG_METHOD_FIXED)) {
+		connman_error("Invalid index and/or address");
+		return;
+	}
+
+	service = connman_service_lookup_from_network(modem->network);
+	if (!service)
+		return;
+
+	connman_service_create_ip4config(service, index);
+	connman_network_set_ipv4_method(modem->network, method);
+
+	if (method == CONNMAN_IPCONFIG_METHOD_FIXED ||
+			method == CONNMAN_IPCONFIG_METHOD_DHCP)	{
+		setip = true;
+	}
+
+	if (method == CONNMAN_IPCONFIG_METHOD_FIXED) {
+		connman_network_set_ipaddress(modem->network,
+						modem->context->ipv4_address);
+	}
+
+	method = modem->context->ipv6_method;
+	connman_service_create_ip6config(service, index);
+	connman_network_set_ipv6_method(modem->network, method);
+
+	if (method == CONNMAN_IPCONFIG_METHOD_AUTO) {
+		setip = true;
+	}
+
+	/* Set the nameservers */
+	if (modem->context->ipv4_nameservers &&
+			modem->context->ipv6_nameservers) {
+		nameservers = g_strdup_printf("%s %s",
+					modem->context->ipv4_nameservers,
+					modem->context->ipv6_nameservers);
+		connman_network_set_nameservers(modem->network, nameservers);
+		g_free(nameservers);
+	} else if (modem->context->ipv4_nameservers) {
+		connman_network_set_nameservers(modem->network,
+					modem->context->ipv4_nameservers);
+	} else if (modem->context->ipv6_nameservers) {
+		connman_network_set_nameservers(modem->network,
+					modem->context->ipv6_nameservers);
+	}
+
+	if (setip) {
+		connman_network_set_index(modem->network, index);
+		connman_network_set_connected(modem->network, true);
+	}
+}
+
+static void set_disconnected(struct modem_data *modem)
+{
+	DBG("%s", modem->path);
+
+	if (modem->network)
+		connman_network_set_connected(modem->network, false);
+
+	if (modem->context) {
+		g_free(modem->context->ipv4_nameservers);
+		modem->context->ipv4_nameservers = NULL;
+		if (modem->context->ipv4_method != CONNMAN_IPCONFIG_METHOD_OFF)
+			modem->context->ipv4_method =
+					CONNMAN_IPCONFIG_METHOD_UNKNOWN;
+
+		g_free(modem->context->ipv6_nameservers);
+		modem->context->ipv6_nameservers = NULL;
+		if (modem->context->ipv6_method != CONNMAN_IPCONFIG_METHOD_OFF)
+			modem->context->ipv6_method =
+					CONNMAN_IPCONFIG_METHOD_UNKNOWN;
+	}
+}
+
+typedef void (*set_property_cb)(struct modem_data *data,
+				bool success);
+typedef void (*get_properties_cb)(struct modem_data *data,
+				DBusMessageIter *dict);
+
+struct property_info {
+	struct modem_data *modem;
+	const char *path;
+	const char *interface;
+	const char *property;
+	set_property_cb set_property_cb;
+	get_properties_cb get_properties_cb;
+};
+
+static void set_property_reply(DBusPendingCall *call, void *user_data)
+{
+	struct property_info *info = user_data;
+	DBusMessage *reply;
+	DBusError error;
+	bool success = true;
+
+	DBG("%s path %s %s.%s", info->modem->path,
+		info->path, info->interface, info->property);
+
+	info->modem->call_set_property = NULL;
+
+	dbus_error_init(&error);
+
+	reply = dbus_pending_call_steal_reply(call);
+
+	if (dbus_set_error_from_message(&error, reply)) {
+		connman_error("Failed to change property: %s %s.%s: %s %s",
+				info->path, info->interface, info->property,
+				error.name, error.message);
+		dbus_error_free(&error);
+		success = false;
+	}
+
+	if (info->set_property_cb)
+		(*info->set_property_cb)(info->modem, success);
+
+	dbus_message_unref(reply);
+
+	dbus_pending_call_unref(call);
+}
+
+static int set_property(struct modem_data *modem,
+			const char *path, const char *interface,
+			const char *property, int type, void *value,
+			set_property_cb notify)
+{
+	DBusMessage *message;
+	DBusMessageIter iter;
+	struct property_info *info;
+
+	DBG("%s path %s %s.%s", modem->path, path, interface, property);
+
+	if (modem->call_set_property) {
+		DBG("Cancel pending SetProperty");
+		dbus_pending_call_cancel(modem->call_set_property);
+		dbus_pending_call_unref(modem->call_set_property);
+		modem->call_set_property = NULL;
+	}
+
+	message = dbus_message_new_method_call(OFONO_SERVICE, path,
+					interface, SET_PROPERTY);
+	if (!message)
+		return -ENOMEM;
+
+	dbus_message_iter_init_append(message, &iter);
+	connman_dbus_property_append_basic(&iter, property, type, value);
+
+	if (!dbus_connection_send_with_reply(connection, message,
+					&modem->call_set_property, TIMEOUT)) {
+		connman_error("Failed to change property: %s %s.%s",
+				path, interface, property);
+		dbus_message_unref(message);
+		return -EINVAL;
+	}
+
+	if (!modem->call_set_property) {
+		connman_error("D-Bus connection not available");
+		dbus_message_unref(message);
+		return -EINVAL;
+	}
+
+	info = g_try_new0(struct property_info, 1);
+	if (!info) {
+		dbus_message_unref(message);
+		return -ENOMEM;
+	}
+
+	info->modem = modem;
+	info->path = path;
+	info->interface = interface;
+	info->property = property;
+	info->set_property_cb = notify;
+
+	dbus_pending_call_set_notify(modem->call_set_property,
+					set_property_reply, info, g_free);
+
+	dbus_message_unref(message);
+
+	return -EINPROGRESS;
+}
+
+static void get_properties_reply(DBusPendingCall *call, void *user_data)
+{
+	struct property_info *info = user_data;
+	DBusMessageIter array, dict;
+	DBusMessage *reply;
+	DBusError error;
+
+	DBG("%s path %s %s", info->modem->path, info->path, info->interface);
+
+	info->modem->call_get_properties = NULL;
+
+	dbus_error_init(&error);
+
+	reply = dbus_pending_call_steal_reply(call);
+
+	if (dbus_set_error_from_message(&error, reply)) {
+		connman_error("Failed to get properties: %s %s: %s %s",
+				info->path, info->interface,
+				error.name, error.message);
+		dbus_error_free(&error);
+
+		goto done;
+	}
+
+	if (!dbus_message_iter_init(reply, &array))
+		goto done;
+
+	if (dbus_message_iter_get_arg_type(&array) != DBUS_TYPE_ARRAY)
+		goto done;
+
+	dbus_message_iter_recurse(&array, &dict);
+
+	if (info->get_properties_cb)
+		(*info->get_properties_cb)(info->modem, &dict);
+
+done:
+
+	dbus_message_unref(reply);
+
+	dbus_pending_call_unref(call);
+}
+
+static int get_properties(const char *path, const char *interface,
+				get_properties_cb notify,
+				struct modem_data *modem)
+{
+	DBusMessage *message;
+	struct property_info *info;
+
+	DBG("%s path %s %s", modem->path, path, interface);
+
+	if (modem->call_get_properties) {
+		connman_error("Pending GetProperties");
+		return -EBUSY;
+	}
+
+	message = dbus_message_new_method_call(OFONO_SERVICE, path,
+					interface, GET_PROPERTIES);
+	if (!message)
+		return -ENOMEM;
+
+	if (!dbus_connection_send_with_reply(connection, message,
+					&modem->call_get_properties, TIMEOUT)) {
+		connman_error("Failed to call %s.GetProperties()", interface);
+		dbus_message_unref(message);
+		return -EINVAL;
+	}
+
+	if (!modem->call_get_properties) {
+		connman_error("D-Bus connection not available");
+		dbus_message_unref(message);
+		return -EINVAL;
+	}
+
+	info = g_try_new0(struct property_info, 1);
+	if (!info) {
+		dbus_message_unref(message);
+		return -ENOMEM;
+	}
+
+	info->modem = modem;
+	info->path = path;
+	info->interface = interface;
+	info->get_properties_cb = notify;
+
+	dbus_pending_call_set_notify(modem->call_get_properties,
+					get_properties_reply, info, g_free);
+
+	dbus_message_unref(message);
+
+	return -EINPROGRESS;
+}
+
+static void context_set_active_reply(struct modem_data *modem,
+					bool success)
+{
+	DBG("%s", modem->path);
+
+	if (success) {
+		/*
+		 * Don't handle do anything on success here. oFono will send
+		 * the change via PropertyChanged singal.
+		 */
+		return;
+	}
+
+	/*
+	 * Active = True might fail due a timeout. That means oFono
+	 * still tries to go online. If we retry to set Active = True,
+	 * we just get a InProgress error message. Should we power
+	 * cycle the modem in such cases?
+	 */
+
+	if (!modem->network) {
+		/*
+		 * In the case where we power down the device
+		 * we don't wait for the reply, therefore the network
+		 * might already be gone.
+		 */
+		return;
+	}
+
+	connman_network_set_error(modem->network,
+				CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL);
+}
+
+static int context_set_active(struct modem_data *modem,
+				dbus_bool_t active)
+{
+	int err;
+
+	DBG("%s active %d", modem->path, active);
+
+	err = set_property(modem, modem->context->path,
+				OFONO_CONTEXT_INTERFACE,
+				"Active", DBUS_TYPE_BOOLEAN,
+				&active,
+				context_set_active_reply);
+
+	if (!active && err == -EINPROGRESS)
+		return 0;
+
+	return err;
+}
+
+static void cdma_cm_set_powered_reply(struct modem_data *modem,
+					bool success)
+{
+	DBG("%s", modem->path);
+
+	if (success) {
+		/*
+		 * Don't handle do anything on success here. oFono will send
+		 * the change via PropertyChanged singal.
+		 */
+		return;
+	}
+
+	/*
+	 * Powered = True might fail due a timeout. That means oFono
+	 * still tries to go online. If we retry to set Powered = True,
+	 * we just get a InProgress error message. Should we power
+	 * cycle the modem in such cases?
+	 */
+
+	if (!modem->network) {
+		/*
+		 * In the case where we power down the device
+		 * we don't wait for the reply, therefore the network
+		 * might already be gone.
+		 */
+		return;
+	}
+
+	connman_network_set_error(modem->network,
+				CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL);
+}
+
+static int cdma_cm_set_powered(struct modem_data *modem, dbus_bool_t powered)
+{
+	int err;
+
+	DBG("%s powered %d", modem->path, powered);
+
+	err = set_property(modem, modem->path, OFONO_CDMA_CM_INTERFACE,
+				"Powered", DBUS_TYPE_BOOLEAN,
+				&powered,
+				cdma_cm_set_powered_reply);
+
+	if (!powered && err == -EINPROGRESS)
+		return 0;
+
+	return err;
+}
+
+static int modem_set_online(struct modem_data *modem, dbus_bool_t online)
+{
+	DBG("%s online %d", modem->path, online);
+
+	return set_property(modem, modem->path,
+				OFONO_MODEM_INTERFACE,
+				"Online", DBUS_TYPE_BOOLEAN,
+				&online,
+				NULL);
+}
+
+static int cm_set_powered(struct modem_data *modem, dbus_bool_t powered)
+{
+	int err;
+
+	DBG("%s powered %d", modem->path, powered);
+
+	err = set_property(modem, modem->path,
+				OFONO_CM_INTERFACE,
+				"Powered", DBUS_TYPE_BOOLEAN,
+				&powered,
+				NULL);
+
+	if (!powered && err == -EINPROGRESS)
+		return 0;
+
+	return err;
+}
+
+static int modem_set_powered(struct modem_data *modem, dbus_bool_t powered)
+{
+	int err;
+
+	DBG("%s powered %d", modem->path, powered);
+
+	modem->set_powered = powered;
+
+	err = set_property(modem, modem->path,
+				OFONO_MODEM_INTERFACE,
+				"Powered", DBUS_TYPE_BOOLEAN,
+				&powered,
+				NULL);
+
+	if (!powered && err == -EINPROGRESS)
+		return 0;
+
+	return err;
+}
+
+static bool has_interface(uint8_t interfaces,
+					enum ofono_api api)
+{
+	if ((interfaces & api) == api)
+		return true;
+
+	return false;
+}
+
+static uint8_t extract_interfaces(DBusMessageIter *array)
+{
+	DBusMessageIter entry;
+	uint8_t interfaces = 0;
+
+	dbus_message_iter_recurse(array, &entry);
+
+	while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
+		const char *name;
+
+		dbus_message_iter_get_basic(&entry, &name);
+
+		if (g_str_equal(name, OFONO_SIM_INTERFACE))
+			interfaces |= OFONO_API_SIM;
+		else if (g_str_equal(name, OFONO_NETREG_INTERFACE))
+			interfaces |= OFONO_API_NETREG;
+		else if (g_str_equal(name, OFONO_CM_INTERFACE))
+			interfaces |= OFONO_API_CM;
+		else if (g_str_equal(name, OFONO_CDMA_CM_INTERFACE))
+			interfaces |= OFONO_API_CDMA_CM;
+		else if (g_str_equal(name, OFONO_CDMA_NETREG_INTERFACE))
+			interfaces |= OFONO_API_CDMA_NETREG;
+
+		dbus_message_iter_next(&entry);
+	}
+
+	return interfaces;
+}
+
+static char *extract_nameservers(DBusMessageIter *array)
+{
+	DBusMessageIter entry;
+	char *nameservers = NULL;
+	char *tmp;
+
+	dbus_message_iter_recurse(array, &entry);
+
+	while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
+		const char *nameserver;
+
+		dbus_message_iter_get_basic(&entry, &nameserver);
+
+		if (!nameservers) {
+			nameservers = g_strdup(nameserver);
+		} else {
+			tmp = nameservers;
+			nameservers = g_strdup_printf("%s %s", tmp, nameserver);
+			g_free(tmp);
+		}
+
+		dbus_message_iter_next(&entry);
+	}
+
+	return nameservers;
+}
+
+static void extract_ipv4_settings(DBusMessageIter *array,
+				struct network_context *context)
+{
+	DBusMessageIter dict;
+	char *address = NULL, *netmask = NULL, *gateway = NULL;
+	char *nameservers = NULL;
+	const char *interface = NULL;
+	int index = -1;
+
+	connman_ipaddress_free(context->ipv4_address);
+	context->ipv4_address = NULL;
+	context->index = -1;
+
+	if (dbus_message_iter_get_arg_type(array) != DBUS_TYPE_ARRAY)
+		return;
+
+	dbus_message_iter_recurse(array, &dict);
+
+	while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
+		DBusMessageIter entry, value;
+		const char *key, *val;
+
+		dbus_message_iter_recurse(&dict, &entry);
+		dbus_message_iter_get_basic(&entry, &key);
+
+		dbus_message_iter_next(&entry);
+		dbus_message_iter_recurse(&entry, &value);
+
+		if (g_str_equal(key, "Interface")) {
+			dbus_message_iter_get_basic(&value, &interface);
+
+			DBG("Interface %s", interface);
+
+			index = connman_inet_ifindex(interface);
+
+			DBG("index %d", index);
+		} else if (g_str_equal(key, "Method")) {
+			dbus_message_iter_get_basic(&value, &val);
+
+			DBG("Method %s", val);
+
+			if (g_strcmp0(val, "static") == 0)
+				context->ipv4_method = CONNMAN_IPCONFIG_METHOD_FIXED;
+			else if (g_strcmp0(val, "dhcp") == 0)
+				context->ipv4_method = CONNMAN_IPCONFIG_METHOD_DHCP;
+
+		} else if (g_str_equal(key, "Address")) {
+			dbus_message_iter_get_basic(&value, &val);
+
+			address = g_strdup(val);
+
+			DBG("Address %s", address);
+		} else if (g_str_equal(key, "Netmask")) {
+			dbus_message_iter_get_basic(&value, &val);
+
+			netmask = g_strdup(val);
+
+			DBG("Netmask %s", netmask);
+		} else if (g_str_equal(key, "DomainNameServers")) {
+			nameservers = extract_nameservers(&value);
+
+			DBG("Nameservers %s", nameservers);
+		} else if (g_str_equal(key, "Gateway")) {
+			dbus_message_iter_get_basic(&value, &val);
+
+			gateway = g_strdup(val);
+
+			DBG("Gateway %s", gateway);
+		}
+
+		dbus_message_iter_next(&dict);
+	}
+
+	if (index < 0)
+		goto out;
+
+	context->index = index;
+
+	if (context->ipv4_method != CONNMAN_IPCONFIG_METHOD_FIXED)
+		goto out;
+
+	context->ipv4_address = connman_ipaddress_alloc(CONNMAN_IPCONFIG_TYPE_IPV4);
+	if (!context->ipv4_address) {
+		context->index = -1;
+		goto out;
+	}
+
+	connman_ipaddress_set_ipv4(context->ipv4_address, address,
+				netmask, gateway);
+
+	g_free(context->ipv4_nameservers);
+	context->ipv4_nameservers = nameservers;
+
+out:
+	if (context->ipv4_nameservers != nameservers)
+		g_free(nameservers);
+
+	g_free(address);
+	g_free(netmask);
+	g_free(gateway);
+}
+
+static void extract_ipv6_settings(DBusMessageIter *array,
+				struct network_context *context)
+{
+	DBusMessageIter dict;
+	char *address = NULL, *gateway = NULL;
+	unsigned char prefix_length = 0;
+	char *nameservers = NULL;
+	const char *interface = NULL;
+	int index = -1;
+
+	connman_ipaddress_free(context->ipv6_address);
+	context->ipv6_address = NULL;
+	context->index = -1;
+
+	if (dbus_message_iter_get_arg_type(array) != DBUS_TYPE_ARRAY)
+		return;
+
+	dbus_message_iter_recurse(array, &dict);
+
+	while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
+		DBusMessageIter entry, value;
+		const char *key, *val;
+
+		dbus_message_iter_recurse(&dict, &entry);
+		dbus_message_iter_get_basic(&entry, &key);
+
+		dbus_message_iter_next(&entry);
+		dbus_message_iter_recurse(&entry, &value);
+
+		if (g_str_equal(key, "Interface")) {
+			dbus_message_iter_get_basic(&value, &interface);
+
+			DBG("Interface %s", interface);
+
+			index = connman_inet_ifindex(interface);
+
+			DBG("index %d", index);
+		} else if (g_str_equal(key, "Address")) {
+			dbus_message_iter_get_basic(&value, &val);
+
+			address = g_strdup(val);
+
+			DBG("Address %s", address);
+		} else if (g_str_equal(key, "PrefixLength")) {
+			dbus_message_iter_get_basic(&value, &prefix_length);
+
+			DBG("prefix length %d", prefix_length);
+		} else if (g_str_equal(key, "DomainNameServers")) {
+			nameservers = extract_nameservers(&value);
+
+			DBG("Nameservers %s", nameservers);
+		} else if (g_str_equal(key, "Gateway")) {
+			dbus_message_iter_get_basic(&value, &val);
+
+			gateway = g_strdup(val);
+
+			DBG("Gateway %s", gateway);
+		}
+
+		dbus_message_iter_next(&dict);
+	}
+
+	if (index < 0)
+		goto out;
+
+	context->ipv6_method = CONNMAN_IPCONFIG_METHOD_AUTO;
+
+	context->ipv6_address =
+		connman_ipaddress_alloc(CONNMAN_IPCONFIG_TYPE_IPV6);
+	if (!context->ipv6_address)
+		goto out;
+
+	context->index = index;
+	connman_ipaddress_set_ipv6(context->ipv6_address, address,
+				prefix_length, gateway);
+
+	g_free(context->ipv6_nameservers);
+	context->ipv6_nameservers = nameservers;
+
+out:
+	if (context->ipv6_nameservers != nameservers)
+		g_free(nameservers);
+
+	g_free(address);
+	g_free(gateway);
+}
+
+static bool ready_to_create_device(struct modem_data *modem)
+{
+	/*
+	 * There are three different modem types which behave slightly
+	 * different:
+	 * - GSM modems will expose the SIM interface then the
+	 *   CM interface.
+	 * - CDMA modems will expose CM first and sometime later
+	 *   a unique serial number.
+	 *
+	 * This functions tests if we have the necessary information gathered
+	 * before we are able to create a device.
+	 */
+
+	if (modem->device)
+		return false;
+
+	if (modem->imsi || modem->serial)
+		return true;
+
+	return false;
+}
+
+static void create_device(struct modem_data *modem)
+{
+	struct connman_device *device;
+	char *ident = NULL;
+
+	DBG("%s", modem->path);
+
+	if (modem->imsi)
+		ident = modem->imsi;
+	else if (modem->serial)
+		ident = modem->serial;
+
+	if (!connman_dbus_validate_ident(ident))
+		ident = connman_dbus_encode_string(ident);
+	else
+		ident = g_strdup(ident);
+
+	device = connman_device_create("ofono", CONNMAN_DEVICE_TYPE_CELLULAR);
+	if (!device)
+		goto out;
+
+	DBG("device %p", device);
+
+	connman_device_set_ident(device, ident);
+
+	connman_device_set_string(device, "Path", modem->path);
+
+	connman_device_set_data(device, modem);
+
+	if (connman_device_register(device) < 0) {
+		connman_error("Failed to register cellular device");
+		connman_device_unref(device);
+		goto out;
+	}
+
+	modem->device = device;
+
+	connman_device_set_powered(modem->device, modem->online);
+out:
+	g_free(ident);
+}
+
+static void destroy_device(struct modem_data *modem)
+{
+	DBG("%s", modem->path);
+
+	connman_device_set_powered(modem->device, false);
+
+	if (modem->network) {
+		connman_device_remove_network(modem->device, modem->network);
+		connman_network_unref(modem->network);
+		modem->network = NULL;
+	}
+
+	connman_device_unregister(modem->device);
+	connman_device_unref(modem->device);
+
+	modem->device = NULL;
+}
+
+static void add_network(struct modem_data *modem)
+{
+	const char *group;
+
+	DBG("%s", modem->path);
+
+	if (modem->network)
+		return;
+
+	modem->network = connman_network_create(modem->context->path,
+						CONNMAN_NETWORK_TYPE_CELLULAR);
+	if (!modem->network)
+		return;
+
+	DBG("network %p", modem->network);
+
+	connman_network_set_data(modem->network, modem);
+
+	connman_network_set_string(modem->network, "Path",
+					modem->context->path);
+
+	if (modem->name)
+		connman_network_set_name(modem->network, modem->name);
+	else
+		connman_network_set_name(modem->network, "");
+
+	connman_network_set_strength(modem->network, modem->strength);
+
+	group = get_ident(modem->context->path);
+	connman_network_set_group(modem->network, group);
+
+	connman_network_set_bool(modem->network, "Roaming",
+					modem->roaming);
+
+	if (connman_device_add_network(modem->device, modem->network) < 0) {
+		connman_network_unref(modem->network);
+		modem->network = NULL;
+		return;
+	}
+}
+
+static void remove_network(struct modem_data *modem)
+{
+	DBG("%s", modem->path);
+
+	if (!modem->network)
+		return;
+
+	DBG("network %p", modem->network);
+
+	connman_device_remove_network(modem->device, modem->network);
+	connman_network_unref(modem->network);
+	modem->network = NULL;
+}
+
+static int set_context_ipconfig(struct network_context *context,
+				const char *protocol)
+{
+	DBG("context %p protocol %s", context, protocol);
+
+	if (!context || !protocol)
+		return -EINVAL;
+
+	if (g_str_equal(protocol, "ip")) {
+		if (context->ipv4_method == CONNMAN_IPCONFIG_METHOD_OFF)
+			context->ipv4_method = CONNMAN_IPCONFIG_METHOD_UNKNOWN;
+
+		context->ipv6_method = CONNMAN_IPCONFIG_METHOD_OFF;
+
+		connman_ipaddress_free(context->ipv6_address);
+		context->ipv6_address = NULL;
+
+	} else if (g_str_equal(protocol, "ipv6")) {
+		if (context->ipv6_method == CONNMAN_IPCONFIG_METHOD_OFF)
+			context->ipv6_method = CONNMAN_IPCONFIG_METHOD_UNKNOWN;
+
+		context->ipv4_method = CONNMAN_IPCONFIG_METHOD_OFF;
+
+		connman_ipaddress_free(context->ipv4_address);
+		context->ipv4_address = NULL;
+
+	} else if (g_str_equal(protocol, "dual")) {
+		if (context->ipv4_method == CONNMAN_IPCONFIG_METHOD_OFF)
+			context->ipv4_method = CONNMAN_IPCONFIG_METHOD_UNKNOWN;
+
+		if (context->ipv6_method == CONNMAN_IPCONFIG_METHOD_OFF)
+			context->ipv6_method = CONNMAN_IPCONFIG_METHOD_UNKNOWN;
+	}
+
+	DBG("ipv4 method %d ipv6 method %d", context->ipv4_method,
+		context->ipv6_method);
+
+	return 0;
+}
+
+static int add_cm_context(struct modem_data *modem, const char *context_path,
+				DBusMessageIter *dict)
+{
+	const char *context_type = NULL;
+	struct network_context *context = NULL;
+	dbus_bool_t active = FALSE;
+	const char *ip_protocol = NULL;
+
+	DBG("%s context path %s", modem->path, context_path);
+
+	if (modem->context) {
+		/*
+		 * We have already assigned a context to this modem
+		 * and we do only support one Internet context.
+		 */
+		return -EALREADY;
+	}
+
+	context = network_context_alloc(context_path);
+	if (!context)
+		return -ENOMEM;
+
+	while (dbus_message_iter_get_arg_type(dict) == DBUS_TYPE_DICT_ENTRY) {
+		DBusMessageIter entry, value;
+		const char *key;
+
+		dbus_message_iter_recurse(dict, &entry);
+		dbus_message_iter_get_basic(&entry, &key);
+
+		dbus_message_iter_next(&entry);
+		dbus_message_iter_recurse(&entry, &value);
+
+		if (g_str_equal(key, "Type")) {
+			dbus_message_iter_get_basic(&value, &context_type);
+
+			DBG("%s context %s type %s", modem->path,
+				context_path, context_type);
+		} else if (g_str_equal(key, "Settings")) {
+			DBG("%s Settings", modem->path);
+
+			extract_ipv4_settings(&value, context);
+		} else if (g_str_equal(key, "IPv6.Settings")) {
+			DBG("%s IPv6.Settings", modem->path);
+
+			extract_ipv6_settings(&value, context);
+		} else if (g_str_equal(key, "Active")) {
+			dbus_message_iter_get_basic(&value, &active);
+
+			DBG("%s Active %d", modem->path, active);
+		} else if (g_str_equal(key, "AccessPointName")) {
+			const char *apn;
+
+			dbus_message_iter_get_basic(&value, &apn);
+			if (apn && strlen(apn) > 0)
+				modem->valid_apn = true;
+			else
+				modem->valid_apn = false;
+
+			DBG("%s AccessPointName '%s'", modem->path, apn);
+		}  else if (g_str_equal(key, "Protocol") &&
+			dbus_message_iter_get_arg_type(&value) == DBUS_TYPE_STRING ) {
+
+			dbus_message_iter_get_basic(&value, &ip_protocol);
+
+			DBG("%s Protocol %s", modem->path, ip_protocol);
+		}
+
+		dbus_message_iter_next(dict);
+	}
+
+	if (g_strcmp0(context_type, "internet") != 0) {
+		network_context_free(context);
+		return -EINVAL;
+	}
+
+	if (ip_protocol)
+		set_context_ipconfig(context, ip_protocol);
+
+	modem->context = context;
+	modem->active = active;
+
+	g_hash_table_replace(context_hash, g_strdup(context_path), modem);
+
+	if (modem->valid_apn && modem->attached &&
+			has_interface(modem->interfaces,
+				OFONO_API_NETREG)) {
+		add_network(modem);
+	}
+
+	return 0;
+}
+
+static void remove_cm_context(struct modem_data *modem,
+				const char *context_path)
+{
+	if (!modem->context)
+		return;
+
+	if (modem->network)
+		remove_network(modem);
+
+	g_hash_table_remove(context_hash, context_path);
+
+	network_context_free(modem->context);
+	modem->context = NULL;
+
+	modem->valid_apn = false;
+
+	if (modem->network)
+		remove_network(modem);
+}
+
+static gboolean context_changed(DBusConnection *conn,
+				DBusMessage *message,
+				void *user_data)
+{
+	const char *context_path = dbus_message_get_path(message);
+	struct modem_data *modem = NULL;
+	DBusMessageIter iter, value;
+	const char *key;
+
+	DBG("context_path %s", context_path);
+
+	modem = g_hash_table_lookup(context_hash, context_path);
+	if (!modem)
+		return TRUE;
+
+	if (!dbus_message_iter_init(message, &iter))
+		return TRUE;
+
+	dbus_message_iter_get_basic(&iter, &key);
+
+	dbus_message_iter_next(&iter);
+	dbus_message_iter_recurse(&iter, &value);
+
+	/*
+	 * oFono guarantees the ordering of Settings and
+	 * Active. Settings will always be send before Active = True.
+	 * That means we don't have to order here.
+	 */
+	if (g_str_equal(key, "Settings")) {
+		DBG("%s Settings", modem->path);
+
+		extract_ipv4_settings(&value, modem->context);
+	} else if (g_str_equal(key, "IPv6.Settings")) {
+		DBG("%s IPv6.Settings", modem->path);
+
+		extract_ipv6_settings(&value, modem->context);
+	} else if (g_str_equal(key, "Active")) {
+		dbus_bool_t active;
+
+		dbus_message_iter_get_basic(&value, &active);
+		modem->active = active;
+
+		DBG("%s Active %d", modem->path, modem->active);
+
+		if (modem->active)
+			set_connected(modem);
+		else
+			set_disconnected(modem);
+	} else if (g_str_equal(key, "AccessPointName")) {
+		const char *apn;
+
+		dbus_message_iter_get_basic(&value, &apn);
+
+		DBG("%s AccessPointName %s", modem->path, apn);
+
+		if (apn && strlen(apn) > 0) {
+			modem->valid_apn = true;
+
+			if (modem->network)
+				return TRUE;
+
+			if (!modem->attached)
+				return TRUE;
+
+			if (!has_interface(modem->interfaces,
+						OFONO_API_NETREG))
+				return TRUE;
+
+			add_network(modem);
+
+			if (modem->active)
+				set_connected(modem);
+		} else {
+			modem->valid_apn = false;
+
+			if (!modem->network)
+				return TRUE;
+
+			remove_network(modem);
+		}
+
+	} else if (g_str_equal(key, "Protocol") &&
+		dbus_message_iter_get_arg_type(&value) == DBUS_TYPE_STRING ) {
+		const char *ip_protocol;
+
+		dbus_message_iter_get_basic(&value, &ip_protocol);
+
+		set_context_ipconfig(modem->context, ip_protocol);
+	}
+
+	return TRUE;
+}
+
+static void cm_get_contexts_reply(DBusPendingCall *call, void *user_data)
+{
+	struct modem_data *modem = user_data;
+	DBusMessageIter array, dict, entry, value;
+	DBusMessage *reply;
+	DBusError error;
+
+	DBG("%s", modem->path);
+
+	modem->call_get_contexts = NULL;
+
+	reply = dbus_pending_call_steal_reply(call);
+
+	dbus_error_init(&error);
+
+	if (dbus_set_error_from_message(&error, reply)) {
+		connman_error("%s", error.message);
+		dbus_error_free(&error);
+		goto done;
+	}
+
+	if (!dbus_message_iter_init(reply, &array))
+		goto done;
+
+	if (dbus_message_iter_get_arg_type(&array) != DBUS_TYPE_ARRAY)
+		goto done;
+
+	dbus_message_iter_recurse(&array, &dict);
+
+	while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_STRUCT) {
+		const char *context_path;
+
+		dbus_message_iter_recurse(&dict, &entry);
+		dbus_message_iter_get_basic(&entry, &context_path);
+
+		dbus_message_iter_next(&entry);
+		dbus_message_iter_recurse(&entry, &value);
+
+		if (add_cm_context(modem, context_path, &value) == 0)
+			break;
+
+		dbus_message_iter_next(&dict);
+	}
+
+done:
+	dbus_message_unref(reply);
+
+	dbus_pending_call_unref(call);
+}
+
+static int cm_get_contexts(struct modem_data *modem)
+{
+	DBusMessage *message;
+
+	DBG("%s", modem->path);
+
+	if (modem->call_get_contexts)
+		return -EBUSY;
+
+	message = dbus_message_new_method_call(OFONO_SERVICE, modem->path,
+					OFONO_CM_INTERFACE, GET_CONTEXTS);
+	if (!message)
+		return -ENOMEM;
+
+	if (!dbus_connection_send_with_reply(connection, message,
+					&modem->call_get_contexts, TIMEOUT)) {
+		connman_error("Failed to call GetContexts()");
+		dbus_message_unref(message);
+		return -EINVAL;
+	}
+
+	if (!modem->call_get_contexts) {
+		connman_error("D-Bus connection not available");
+		dbus_message_unref(message);
+		return -EINVAL;
+	}
+
+	dbus_pending_call_set_notify(modem->call_get_contexts,
+					cm_get_contexts_reply,
+					modem, NULL);
+
+	dbus_message_unref(message);
+
+	return -EINPROGRESS;
+}
+
+static gboolean cm_context_added(DBusConnection *conn,
+					DBusMessage *message,
+					void *user_data)
+{
+	const char *path = dbus_message_get_path(message);
+	char *context_path;
+	struct modem_data *modem;
+	DBusMessageIter iter, properties;
+
+	DBG("%s", path);
+
+	modem = g_hash_table_lookup(modem_hash, path);
+	if (!modem)
+		return TRUE;
+
+	if (!dbus_message_iter_init(message, &iter))
+		return TRUE;
+
+	dbus_message_iter_get_basic(&iter, &context_path);
+
+	dbus_message_iter_next(&iter);
+	dbus_message_iter_recurse(&iter, &properties);
+
+	if (add_cm_context(modem, context_path, &properties) != 0)
+		return TRUE;
+
+	return TRUE;
+}
+
+static gboolean cm_context_removed(DBusConnection *conn,
+					DBusMessage *message,
+					void *user_data)
+{
+	const char *path = dbus_message_get_path(message);
+	const char *context_path;
+	struct modem_data *modem;
+	DBusMessageIter iter;
+
+	DBG("context path %s", path);
+
+	if (!dbus_message_iter_init(message, &iter))
+		return TRUE;
+
+	dbus_message_iter_get_basic(&iter, &context_path);
+
+	modem = g_hash_table_lookup(context_hash, context_path);
+	if (!modem)
+		return TRUE;
+
+	remove_cm_context(modem, context_path);
+
+	return TRUE;
+}
+
+static void netreg_update_name(struct modem_data *modem,
+				DBusMessageIter* value)
+{
+	char *name;
+
+	dbus_message_iter_get_basic(value, &name);
+
+	DBG("%s Name %s", modem->path, name);
+
+	g_free(modem->name);
+	modem->name = g_strdup(name);
+
+	if (!modem->network)
+		return;
+
+	connman_network_set_name(modem->network, modem->name);
+	connman_network_update(modem->network);
+}
+
+static void netreg_update_strength(struct modem_data *modem,
+					DBusMessageIter *value)
+{
+	dbus_message_iter_get_basic(value, &modem->strength);
+
+	DBG("%s Strength %d", modem->path, modem->strength);
+
+	if (!modem->network)
+		return;
+
+	/*
+	 * GSM:
+	 * We don't have 2 signal notifications we always report the strength
+	 * signal. data_strength is always equal to 0.
+	 *
+	 * CDMA:
+	 * In the case we have a data_strength signal (from 1xEVDO network)
+	 * we don't need to update the value with strength signal (from 1xCDMA)
+	 * because the modem is registered to 1xEVDO network for data call.
+	 * In case we have no data_strength signal (not registered to 1xEVDO
+	 * network), we must report the strength signal (registered to 1xCDMA
+	 * network e.g slow mode).
+	 */
+	if (modem->data_strength != 0)
+		return;
+
+	connman_network_set_strength(modem->network, modem->strength);
+	connman_network_update(modem->network);
+}
+
+/* Retrieve 1xEVDO Data Strength signal */
+static void netreg_update_datastrength(struct modem_data *modem,
+					DBusMessageIter *value)
+{
+	dbus_message_iter_get_basic(value, &modem->data_strength);
+
+	DBG("%s Data Strength %d", modem->path, modem->data_strength);
+
+	if (!modem->network)
+		return;
+
+	/*
+	 * CDMA modem is not registered to 1xEVDO network, let
+	 * update_signal_strength() reporting the value on the Strength signal
+	 * notification.
+	 */
+	if (modem->data_strength == 0)
+		return;
+
+	connman_network_set_strength(modem->network, modem->data_strength);
+	connman_network_update(modem->network);
+}
+
+static void netreg_update_status(struct modem_data *modem,
+					DBusMessageIter *value)
+{
+	char *status;
+	bool roaming;
+
+	dbus_message_iter_get_basic(value, &status);
+
+	roaming = g_str_equal(status, "roaming");
+	modem->registered = roaming || g_str_equal(status, "registered");
+
+	if (roaming == modem->roaming)
+		return;
+
+	modem->roaming = roaming;
+
+	if (!modem->network)
+		return;
+
+	connman_network_set_bool(modem->network,
+				"Roaming", modem->roaming);
+	connman_network_update(modem->network);
+}
+
+static void netreg_update_regdom(struct modem_data *modem,
+				DBusMessageIter *value)
+{
+	char *mobile_country_code;
+	char *alpha2;
+	int mcc;
+
+	dbus_message_iter_get_basic(value, &mobile_country_code);
+
+	DBG("%s MobileContryCode %s", modem->path, mobile_country_code);
+
+
+	mcc = atoi(mobile_country_code);
+	if (mcc > 799 || mcc < 200)
+		return;
+
+	alpha2 = mcc_country_codes[mcc - 200];
+	if (alpha2)
+		connman_technology_set_regdom(alpha2);
+}
+
+static gboolean netreg_changed(DBusConnection *conn, DBusMessage *message,
+				void *user_data)
+{
+	const char *path = dbus_message_get_path(message);
+	struct modem_data *modem;
+	DBusMessageIter iter, value;
+	const char *key;
+
+	modem = g_hash_table_lookup(modem_hash, path);
+	if (!modem)
+		return TRUE;
+
+	if (modem->ignore)
+		return TRUE;
+
+	if (!dbus_message_iter_init(message, &iter))
+		return TRUE;
+
+	dbus_message_iter_get_basic(&iter, &key);
+
+	dbus_message_iter_next(&iter);
+	dbus_message_iter_recurse(&iter, &value);
+
+	if (g_str_equal(key, "Name"))
+		netreg_update_name(modem, &value);
+	else if (g_str_equal(key, "Strength"))
+		netreg_update_strength(modem, &value);
+	else if (g_str_equal(key, "Status"))
+		netreg_update_status(modem, &value);
+	else if (g_str_equal(key, "MobileCountryCode"))
+		netreg_update_regdom(modem, &value);
+
+	return TRUE;
+}
+
+static void netreg_properties_reply(struct modem_data *modem,
+					DBusMessageIter *dict)
+{
+	DBG("%s", modem->path);
+
+	while (dbus_message_iter_get_arg_type(dict) == DBUS_TYPE_DICT_ENTRY) {
+		DBusMessageIter entry, value;
+		const char *key;
+
+		dbus_message_iter_recurse(dict, &entry);
+		dbus_message_iter_get_basic(&entry, &key);
+
+		dbus_message_iter_next(&entry);
+		dbus_message_iter_recurse(&entry, &value);
+
+		if (g_str_equal(key, "Name"))
+			netreg_update_name(modem, &value);
+		else if (g_str_equal(key, "Strength"))
+			netreg_update_strength(modem, &value);
+		else if (g_str_equal(key, "Status"))
+			netreg_update_status(modem, &value);
+		else if (g_str_equal(key, "MobileCountryCode"))
+			netreg_update_regdom(modem, &value);
+
+		dbus_message_iter_next(dict);
+	}
+
+	if (!modem->context) {
+		/*
+		 * netgreg_get_properties() was issued after we got
+		 * cm_get_contexts_reply() where we create the
+		 * context. Though before we got the
+		 * netreg_properties_reply the context was removed
+		 * again. Therefore we have to skip the network
+		 * creation.
+		 */
+		return;
+	}
+
+	if (modem->valid_apn)
+		add_network(modem);
+
+	if (modem->active)
+		set_connected(modem);
+}
+
+static int netreg_get_properties(struct modem_data *modem)
+{
+	return get_properties(modem->path, OFONO_NETREG_INTERFACE,
+			netreg_properties_reply, modem);
+}
+
+static void add_cdma_network(struct modem_data *modem)
+{
+	/* Be sure that device is created before adding CDMA network */
+	if (!modem->device)
+		return;
+
+	/*
+	 * CDMA modems don't need contexts for data call, however the current
+	 * add_network() logic needs one, so we create one to proceed.
+	 */
+	if (!modem->context)
+		modem->context = network_context_alloc(modem->path);
+
+	if (!modem->name)
+		modem->name = g_strdup("CDMA Network");
+
+	add_network(modem);
+
+	if (modem->cdma_cm_powered)
+		set_connected(modem);
+}
+
+static gboolean cdma_netreg_changed(DBusConnection *conn,
+					DBusMessage *message,
+					void *user_data)
+{
+	const char *path = dbus_message_get_path(message);
+	struct modem_data *modem;
+	DBusMessageIter iter, value;
+	const char *key;
+
+	DBG("");
+
+	modem = g_hash_table_lookup(modem_hash, path);
+	if (!modem)
+		return TRUE;
+
+	if (modem->ignore)
+		return TRUE;
+
+	if (!dbus_message_iter_init(message, &iter))
+		return TRUE;
+
+	dbus_message_iter_get_basic(&iter, &key);
+
+	dbus_message_iter_next(&iter);
+	dbus_message_iter_recurse(&iter, &value);
+
+	if (g_str_equal(key, "Name"))
+		netreg_update_name(modem, &value);
+	else if (g_str_equal(key, "Strength"))
+		netreg_update_strength(modem, &value);
+	else if (g_str_equal(key, "DataStrength"))
+		netreg_update_datastrength(modem, &value);
+	else if (g_str_equal(key, "Status"))
+		netreg_update_status(modem, &value);
+
+	if (modem->registered)
+		add_cdma_network(modem);
+	else
+		remove_network(modem);
+
+	return TRUE;
+}
+
+static void cdma_netreg_properties_reply(struct modem_data *modem,
+					DBusMessageIter *dict)
+{
+	DBG("%s", modem->path);
+
+	while (dbus_message_iter_get_arg_type(dict) == DBUS_TYPE_DICT_ENTRY) {
+		DBusMessageIter entry, value;
+		const char *key;
+
+		dbus_message_iter_recurse(dict, &entry);
+		dbus_message_iter_get_basic(&entry, &key);
+
+		dbus_message_iter_next(&entry);
+		dbus_message_iter_recurse(&entry, &value);
+
+		if (g_str_equal(key, "Name"))
+			netreg_update_name(modem, &value);
+		else if (g_str_equal(key, "Strength"))
+			netreg_update_strength(modem, &value);
+		else if (g_str_equal(key, "DataStrength"))
+			netreg_update_datastrength(modem, &value);
+		else if (g_str_equal(key, "Status"))
+			netreg_update_status(modem, &value);
+
+		dbus_message_iter_next(dict);
+	}
+
+	if (modem->registered)
+		add_cdma_network(modem);
+	else
+		remove_network(modem);
+}
+
+static int cdma_netreg_get_properties(struct modem_data *modem)
+{
+	return get_properties(modem->path, OFONO_CDMA_NETREG_INTERFACE,
+			cdma_netreg_properties_reply, modem);
+}
+
+static void cm_update_attached(struct modem_data *modem,
+				DBusMessageIter *value)
+{
+	dbus_bool_t attached;
+
+	dbus_message_iter_get_basic(value, &attached);
+	modem->attached = attached;
+
+	DBG("%s Attached %d", modem->path, modem->attached);
+
+	if (!modem->attached) {
+		remove_network(modem);
+		return;
+	}
+
+	if (!has_interface(modem->interfaces, OFONO_API_NETREG))
+		return;
+
+	netreg_get_properties(modem);
+}
+
+static void cm_update_powered(struct modem_data *modem,
+				DBusMessageIter *value)
+{
+	dbus_bool_t cm_powered;
+
+	dbus_message_iter_get_basic(value, &cm_powered);
+	modem->cm_powered = cm_powered;
+
+	DBG("%s ConnnectionManager Powered %d", modem->path,
+		modem->cm_powered);
+
+	if (modem->cm_powered)
+		return;
+
+	cm_set_powered(modem, TRUE);
+}
+
+static gboolean cm_changed(DBusConnection *conn, DBusMessage *message,
+				void *user_data)
+{
+	const char *path = dbus_message_get_path(message);
+	struct modem_data *modem;
+	DBusMessageIter iter, value;
+	const char *key;
+
+	modem = g_hash_table_lookup(modem_hash, path);
+	if (!modem)
+		return TRUE;
+
+	if (modem->ignore)
+		return TRUE;
+
+	if (!dbus_message_iter_init(message, &iter))
+		return TRUE;
+
+	dbus_message_iter_get_basic(&iter, &key);
+
+	dbus_message_iter_next(&iter);
+	dbus_message_iter_recurse(&iter, &value);
+
+	if (g_str_equal(key, "Attached"))
+		cm_update_attached(modem, &value);
+	else if (g_str_equal(key, "Powered"))
+		cm_update_powered(modem, &value);
+
+	return TRUE;
+}
+
+static void cdma_cm_update_powered(struct modem_data *modem,
+					DBusMessageIter *value)
+{
+	dbus_bool_t cdma_cm_powered;
+
+	dbus_message_iter_get_basic(value, &cdma_cm_powered);
+	modem->cdma_cm_powered = cdma_cm_powered;
+
+	DBG("%s CDMA cm Powered %d", modem->path, modem->cdma_cm_powered);
+
+	if (!modem->network)
+		return;
+
+	if (modem->cdma_cm_powered)
+		set_connected(modem);
+	else
+		set_disconnected(modem);
+}
+
+static void cdma_cm_update_settings(struct modem_data *modem,
+					DBusMessageIter *value)
+{
+	DBG("%s Settings", modem->path);
+
+	extract_ipv4_settings(value, modem->context);
+}
+
+static gboolean cdma_cm_changed(DBusConnection *conn,
+				DBusMessage *message, void *user_data)
+{
+	const char *path = dbus_message_get_path(message);
+	struct modem_data *modem;
+	DBusMessageIter iter, value;
+	const char *key;
+
+	modem = g_hash_table_lookup(modem_hash, path);
+	if (!modem)
+		return TRUE;
+
+	if (modem->online && !modem->network)
+		cdma_netreg_get_properties(modem);
+
+	if (!dbus_message_iter_init(message, &iter))
+		return TRUE;
+
+	dbus_message_iter_get_basic(&iter, &key);
+
+	dbus_message_iter_next(&iter);
+	dbus_message_iter_recurse(&iter, &value);
+
+	if (g_str_equal(key, "Powered"))
+		cdma_cm_update_powered(modem, &value);
+	if (g_str_equal(key, "Settings"))
+		cdma_cm_update_settings(modem, &value);
+
+	return TRUE;
+}
+
+static void cm_properties_reply(struct modem_data *modem, DBusMessageIter *dict)
+{
+	DBG("%s", modem->path);
+
+	while (dbus_message_iter_get_arg_type(dict) == DBUS_TYPE_DICT_ENTRY) {
+		DBusMessageIter entry, value;
+		const char *key;
+
+		dbus_message_iter_recurse(dict, &entry);
+		dbus_message_iter_get_basic(&entry, &key);
+
+		dbus_message_iter_next(&entry);
+		dbus_message_iter_recurse(&entry, &value);
+
+		if (g_str_equal(key, "Attached"))
+			cm_update_attached(modem, &value);
+		else if (g_str_equal(key, "Powered"))
+			cm_update_powered(modem, &value);
+
+		dbus_message_iter_next(dict);
+	}
+}
+
+static int cm_get_properties(struct modem_data *modem)
+{
+	return get_properties(modem->path, OFONO_CM_INTERFACE,
+				cm_properties_reply, modem);
+}
+
+static void cdma_cm_properties_reply(struct modem_data *modem,
+					DBusMessageIter *dict)
+{
+	DBG("%s", modem->path);
+
+	if (modem->online)
+		cdma_netreg_get_properties(modem);
+
+	while (dbus_message_iter_get_arg_type(dict) == DBUS_TYPE_DICT_ENTRY) {
+		DBusMessageIter entry, value;
+		const char *key;
+
+		dbus_message_iter_recurse(dict, &entry);
+		dbus_message_iter_get_basic(&entry, &key);
+
+		dbus_message_iter_next(&entry);
+		dbus_message_iter_recurse(&entry, &value);
+
+		if (g_str_equal(key, "Powered"))
+			cdma_cm_update_powered(modem, &value);
+		if (g_str_equal(key, "Settings"))
+			cdma_cm_update_settings(modem, &value);
+
+		dbus_message_iter_next(dict);
+	}
+}
+
+static int cdma_cm_get_properties(struct modem_data *modem)
+{
+	return get_properties(modem->path, OFONO_CDMA_CM_INTERFACE,
+				cdma_cm_properties_reply, modem);
+}
+
+static void sim_update_imsi(struct modem_data *modem,
+				DBusMessageIter *value)
+{
+	char *imsi;
+
+	dbus_message_iter_get_basic(value, &imsi);
+
+	DBG("%s imsi %s", modem->path, imsi);
+
+	g_free(modem->imsi);
+	modem->imsi = g_strdup(imsi);
+}
+
+static gboolean sim_changed(DBusConnection *conn, DBusMessage *message,
+				void *user_data)
+{
+	const char *path = dbus_message_get_path(message);
+	struct modem_data *modem;
+	DBusMessageIter iter, value;
+	const char *key;
+
+	modem = g_hash_table_lookup(modem_hash, path);
+	if (!modem)
+		return TRUE;
+
+	if (modem->ignore)
+		return TRUE;
+
+	if (!dbus_message_iter_init(message, &iter))
+		return TRUE;
+
+	dbus_message_iter_get_basic(&iter, &key);
+
+	dbus_message_iter_next(&iter);
+	dbus_message_iter_recurse(&iter, &value);
+
+	if (g_str_equal(key, "SubscriberIdentity")) {
+		sim_update_imsi(modem, &value);
+
+		if (!ready_to_create_device(modem))
+			return TRUE;
+
+		/*
+		 * This is a GSM modem. Create the device and
+		 * register it at the core. Enabling (setting
+		 * it online is done through the
+		 * modem_enable() callback.
+		 */
+		create_device(modem);
+	}
+
+	return TRUE;
+}
+
+static void sim_properties_reply(struct modem_data *modem,
+					DBusMessageIter *dict)
+{
+	DBG("%s", modem->path);
+
+	while (dbus_message_iter_get_arg_type(dict) == DBUS_TYPE_DICT_ENTRY) {
+		DBusMessageIter entry, value;
+		const char *key;
+
+		dbus_message_iter_recurse(dict, &entry);
+		dbus_message_iter_get_basic(&entry, &key);
+
+		dbus_message_iter_next(&entry);
+		dbus_message_iter_recurse(&entry, &value);
+
+		if (g_str_equal(key, "SubscriberIdentity")) {
+			sim_update_imsi(modem, &value);
+
+			if (!ready_to_create_device(modem))
+				return;
+
+			/*
+			 * This is a GSM modem. Create the device and
+			 * register it at the core. Enabling (setting
+			 * it online is done through the
+			 * modem_enable() callback.
+			 */
+			create_device(modem);
+
+			if (!modem->online)
+				return;
+
+			/*
+			 * The modem is already online and we have the CM interface.
+			 * There will be no interface update and therefore our
+			 * state machine will not go to next step. We have to
+			 * trigger it from here.
+			 */
+			if (has_interface(modem->interfaces, OFONO_API_CM)) {
+				cm_get_properties(modem);
+				cm_get_contexts(modem);
+			}
+			return;
+		}
+
+		dbus_message_iter_next(dict);
+	}
+}
+
+static int sim_get_properties(struct modem_data *modem)
+{
+	return get_properties(modem->path, OFONO_SIM_INTERFACE,
+				sim_properties_reply, modem);
+}
+
+static bool api_added(uint8_t old_iface, uint8_t new_iface,
+				enum ofono_api api)
+{
+	if (!has_interface(old_iface, api) &&
+			has_interface(new_iface, api)) {
+		DBG("%s added", api2string(api));
+		return true;
+	}
+
+	return false;
+}
+
+static bool api_removed(uint8_t old_iface, uint8_t new_iface,
+				enum ofono_api api)
+{
+	if (has_interface(old_iface, api) &&
+			!has_interface(new_iface, api)) {
+		DBG("%s removed", api2string(api));
+		return true;
+	}
+
+	return false;
+}
+
+static void modem_update_interfaces(struct modem_data *modem,
+				uint8_t old_ifaces,
+				uint8_t new_ifaces)
+{
+	DBG("%s", modem->path);
+
+	if (api_added(old_ifaces, new_ifaces, OFONO_API_SIM)) {
+		if (!modem->imsi &&
+				!modem->set_powered) {
+			/*
+			 * Only use do GetProperties() when
+			 * device has not been powered up.
+			 */
+			sim_get_properties(modem);
+		}
+	}
+
+	if (api_added(old_ifaces, new_ifaces, OFONO_API_CM)) {
+		if (modem->device) {
+			cm_get_properties(modem);
+			cm_get_contexts(modem);
+		}
+	}
+
+	if (api_added(old_ifaces, new_ifaces, OFONO_API_CDMA_CM)) {
+		if (ready_to_create_device(modem)) {
+			create_device(modem);
+			if (modem->registered)
+				add_cdma_network(modem);
+		}
+
+		if (modem->device)
+			cdma_cm_get_properties(modem);
+	}
+
+	if (api_added(old_ifaces, new_ifaces, OFONO_API_NETREG)) {
+		if (modem->attached)
+			netreg_get_properties(modem);
+	}
+
+	if (api_added(old_ifaces, new_ifaces, OFONO_API_CDMA_NETREG))
+		cdma_netreg_get_properties(modem);
+
+	if (api_removed(old_ifaces, new_ifaces, OFONO_API_CM)) {
+		if (modem->call_get_contexts) {
+			DBG("cancelling pending GetContexts call");
+			dbus_pending_call_cancel(modem->call_get_contexts);
+			dbus_pending_call_unref(modem->call_get_contexts);
+			modem->call_get_contexts = NULL;
+		}
+		if (modem->context) {
+			DBG("removing context %s", modem->context->path);
+			remove_cm_context(modem, modem->context->path);
+		}
+	}
+
+	if (api_removed(old_ifaces, new_ifaces, OFONO_API_CDMA_CM))
+		remove_cm_context(modem, modem->context->path);
+
+	if (api_removed(old_ifaces, new_ifaces, OFONO_API_NETREG))
+		remove_network(modem);
+
+	if (api_removed(old_ifaces, new_ifaces, OFONO_API_CDMA_NETREG))
+		remove_network(modem);
+}
+
+static gboolean modem_changed(DBusConnection *conn, DBusMessage *message,
+				void *user_data)
+{
+	const char *path = dbus_message_get_path(message);
+	struct modem_data *modem;
+	DBusMessageIter iter, value;
+	const char *key;
+
+	modem = g_hash_table_lookup(modem_hash, path);
+	if (!modem)
+		return TRUE;
+
+	if (modem->ignore)
+		return TRUE;
+
+	if (!dbus_message_iter_init(message, &iter))
+		return TRUE;
+
+	dbus_message_iter_get_basic(&iter, &key);
+
+	dbus_message_iter_next(&iter);
+	dbus_message_iter_recurse(&iter, &value);
+
+	if (g_str_equal(key, "Powered")) {
+		dbus_bool_t powered;
+
+		dbus_message_iter_get_basic(&value, &powered);
+		modem->powered = powered;
+
+		DBG("%s Powered %d", modem->path, modem->powered);
+
+		if (!modem->powered)
+			modem_set_powered(modem, TRUE);
+	} else if (g_str_equal(key, "Online")) {
+		dbus_bool_t online;
+
+		dbus_message_iter_get_basic(&value, &online);
+		modem->online = online;
+
+		DBG("%s Online %d", modem->path, modem->online);
+
+		if (!modem->device)
+			return TRUE;
+
+		connman_device_set_powered(modem->device, modem->online);
+	} else if (g_str_equal(key, "Interfaces")) {
+		uint8_t interfaces;
+
+		interfaces = extract_interfaces(&value);
+
+		if (interfaces == modem->interfaces)
+			return TRUE;
+
+		DBG("%s Interfaces 0x%02x", modem->path, interfaces);
+
+		modem_update_interfaces(modem, modem->interfaces, interfaces);
+
+		modem->interfaces = interfaces;
+	} else if (g_str_equal(key, "Serial")) {
+		char *serial;
+
+		dbus_message_iter_get_basic(&value, &serial);
+
+		g_free(modem->serial);
+		modem->serial = g_strdup(serial);
+
+		DBG("%s Serial %s", modem->path, modem->serial);
+
+		if (has_interface(modem->interfaces,
+					 OFONO_API_CDMA_CM)) {
+			if (ready_to_create_device(modem)) {
+				create_device(modem);
+				if (modem->registered)
+					add_cdma_network(modem);
+			}
+		}
+	}
+
+	return TRUE;
+}
+
+static void add_modem(const char *path, DBusMessageIter *prop)
+{
+	struct modem_data *modem;
+
+	DBG("%s", path);
+
+	modem = g_hash_table_lookup(modem_hash, path);
+	if (modem) {
+		/*
+		 * When oFono powers up we ask for the modems and oFono is
+		 * reporting with modem_added signal the modems. Only
+		 * handle them once.
+		 */
+		return;
+	}
+
+	modem = g_try_new0(struct modem_data, 1);
+	if (!modem)
+		return;
+
+	modem->path = g_strdup(path);
+
+	g_hash_table_insert(modem_hash, g_strdup(path), modem);
+
+	while (dbus_message_iter_get_arg_type(prop) == DBUS_TYPE_DICT_ENTRY) {
+		DBusMessageIter entry, value;
+		const char *key;
+
+		dbus_message_iter_recurse(prop, &entry);
+		dbus_message_iter_get_basic(&entry, &key);
+
+		dbus_message_iter_next(&entry);
+		dbus_message_iter_recurse(&entry, &value);
+
+		if (g_str_equal(key, "Powered")) {
+			dbus_bool_t powered;
+
+			dbus_message_iter_get_basic(&value, &powered);
+			modem->powered = powered;
+
+			DBG("%s Powered %d", modem->path, modem->powered);
+		} else if (g_str_equal(key, "Online")) {
+			dbus_bool_t online;
+
+			dbus_message_iter_get_basic(&value, &online);
+			modem->online = online;
+
+			DBG("%s Online %d", modem->path, modem->online);
+		} else if (g_str_equal(key, "Interfaces")) {
+			modem->interfaces = extract_interfaces(&value);
+
+			DBG("%s Interfaces 0x%02x", modem->path,
+				modem->interfaces);
+		} else if (g_str_equal(key, "Serial")) {
+			char *serial;
+
+			dbus_message_iter_get_basic(&value, &serial);
+			modem->serial = g_strdup(serial);
+
+			DBG("%s Serial %s", modem->path, modem->serial);
+		} else if (g_str_equal(key, "Type")) {
+			char *type;
+
+			dbus_message_iter_get_basic(&value, &type);
+
+			DBG("%s Type %s", modem->path, type);
+			if (g_strcmp0(type, "hardware") != 0) {
+				DBG("%s Ignore this modem", modem->path);
+				modem->ignore = true;
+			}
+		}
+
+		dbus_message_iter_next(prop);
+	}
+
+	if (modem->ignore)
+		return;
+
+	if (!modem->powered) {
+		modem_set_powered(modem, TRUE);
+		return;
+	}
+
+	modem_update_interfaces(modem, 0, modem->interfaces);
+}
+
+static void modem_power_down(gpointer key, gpointer value, gpointer user_data)
+{
+	struct modem_data *modem = value;
+
+	DBG("%s", modem->path);
+
+	if (modem->ignore)
+		return;
+
+	modem_set_powered(modem, FALSE);
+}
+
+static void remove_modem(gpointer data)
+{
+	struct modem_data *modem = data;
+
+	DBG("%s", modem->path);
+
+	if (modem->call_set_property) {
+		dbus_pending_call_cancel(modem->call_set_property);
+		dbus_pending_call_unref(modem->call_set_property);
+	}
+
+	if (modem->call_get_properties) {
+		dbus_pending_call_cancel(modem->call_get_properties);
+		dbus_pending_call_unref(modem->call_get_properties);
+	}
+
+	if (modem->call_get_contexts) {
+		dbus_pending_call_cancel(modem->call_get_contexts);
+		dbus_pending_call_unref(modem->call_get_contexts);
+	}
+
+	if (modem->device)
+		destroy_device(modem);
+
+	if (modem->context)
+		remove_cm_context(modem, modem->context->path);
+
+	g_free(modem->serial);
+	g_free(modem->name);
+	g_free(modem->imsi);
+	g_free(modem->path);
+
+	g_free(modem);
+}
+
+static gboolean modem_added(DBusConnection *conn,
+				DBusMessage *message, void *user_data)
+{
+	DBusMessageIter iter, properties;
+	const char *path;
+
+	DBG("");
+
+	if (!dbus_message_iter_init(message, &iter))
+		return TRUE;
+
+	dbus_message_iter_get_basic(&iter, &path);
+
+	dbus_message_iter_next(&iter);
+	dbus_message_iter_recurse(&iter, &properties);
+
+	add_modem(path, &properties);
+
+	return TRUE;
+}
+
+static gboolean modem_removed(DBusConnection *conn,
+				DBusMessage *message, void *user_data)
+{
+	DBusMessageIter iter;
+	const char *path;
+
+	DBG("");
+
+	if (!dbus_message_iter_init(message, &iter))
+		return TRUE;
+
+	dbus_message_iter_get_basic(&iter, &path);
+
+	g_hash_table_remove(modem_hash, path);
+
+	return TRUE;
+}
+
+static void manager_get_modems_reply(DBusPendingCall *call, void *user_data)
+{
+	DBusMessage *reply;
+	DBusError error;
+	DBusMessageIter array, dict;
+
+	DBG("");
+
+	reply = dbus_pending_call_steal_reply(call);
+
+	dbus_error_init(&error);
+
+	if (dbus_set_error_from_message(&error, reply)) {
+		connman_error("%s", error.message);
+		dbus_error_free(&error);
+		goto done;
+	}
+
+	if (!dbus_message_iter_init(reply, &array))
+		goto done;
+
+	dbus_message_iter_recurse(&array, &dict);
+
+	while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_STRUCT) {
+		DBusMessageIter value, properties;
+		const char *path;
+
+		dbus_message_iter_recurse(&dict, &value);
+		dbus_message_iter_get_basic(&value, &path);
+
+		dbus_message_iter_next(&value);
+		dbus_message_iter_recurse(&value, &properties);
+
+		add_modem(path, &properties);
+
+		dbus_message_iter_next(&dict);
+	}
+
+done:
+	dbus_message_unref(reply);
+
+	dbus_pending_call_unref(call);
+}
+
+static int manager_get_modems(void)
+{
+	DBusMessage *message;
+	DBusPendingCall *call;
+
+	DBG("");
+
+	message = dbus_message_new_method_call(OFONO_SERVICE, "/",
+					OFONO_MANAGER_INTERFACE, GET_MODEMS);
+	if (!message)
+		return -ENOMEM;
+
+	if (!dbus_connection_send_with_reply(connection, message,
+						&call, TIMEOUT)) {
+		connman_error("Failed to call GetModems()");
+		dbus_message_unref(message);
+		return -EINVAL;
+	}
+
+	if (!call) {
+		connman_error("D-Bus connection not available");
+		dbus_message_unref(message);
+		return -EINVAL;
+	}
+
+	dbus_pending_call_set_notify(call, manager_get_modems_reply,
+					NULL, NULL);
+
+	dbus_message_unref(message);
+
+	return -EINPROGRESS;
+}
+
+static void ofono_connect(DBusConnection *conn, void *user_data)
+{
+	DBG("");
+
+	modem_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
+						g_free, remove_modem);
+	if (!modem_hash)
+		return;
+
+	context_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
+						g_free, NULL);
+	if (!context_hash) {
+		g_hash_table_destroy(modem_hash);
+		return;
+	}
+
+	manager_get_modems();
+}
+
+static void ofono_disconnect(DBusConnection *conn, void *user_data)
+{
+	DBG("");
+
+	if (!modem_hash || !context_hash)
+		return;
+
+	g_hash_table_destroy(modem_hash);
+	modem_hash = NULL;
+
+	g_hash_table_destroy(context_hash);
+	context_hash = NULL;
+}
+
+static int network_probe(struct connman_network *network)
+{
+	struct modem_data *modem = connman_network_get_data(network);
+
+	DBG("%s network %p", modem->path, network);
+
+	return 0;
+}
+
+static void network_remove(struct connman_network *network)
+{
+	struct modem_data *modem = connman_network_get_data(network);
+
+	DBG("%s network %p", modem->path, network);
+}
+
+static int network_connect(struct connman_network *network)
+{
+	struct modem_data *modem = connman_network_get_data(network);
+
+	DBG("%s network %p", modem->path, network);
+
+	if (has_interface(modem->interfaces, OFONO_API_CM))
+		return context_set_active(modem, TRUE);
+	else if (has_interface(modem->interfaces, OFONO_API_CDMA_CM))
+		return cdma_cm_set_powered(modem, TRUE);
+
+	connman_error("Connection manager interface not available");
+
+	return -ENOSYS;
+}
+
+static int network_disconnect(struct connman_network *network, bool user_initiated)
+{
+	struct modem_data *modem = connman_network_get_data(network);
+
+	DBG("%s network %p", modem->path, network);
+
+	if (has_interface(modem->interfaces, OFONO_API_CM))
+		return context_set_active(modem, FALSE);
+	else if (has_interface(modem->interfaces, OFONO_API_CDMA_CM))
+		return cdma_cm_set_powered(modem, FALSE);
+
+	connman_error("Connection manager interface not available");
+
+	return -ENOSYS;
+}
+
+static struct connman_network_driver network_driver = {
+	.name		= "cellular",
+	.type		= CONNMAN_NETWORK_TYPE_CELLULAR,
+	.probe		= network_probe,
+	.remove		= network_remove,
+	.connect	= network_connect,
+	.disconnect	= network_disconnect,
+};
+
+static int modem_probe(struct connman_device *device)
+{
+	struct modem_data *modem = connman_device_get_data(device);
+
+	DBG("%s device %p", modem->path, device);
+
+	return 0;
+}
+
+static void modem_remove(struct connman_device *device)
+{
+	struct modem_data *modem = connman_device_get_data(device);
+
+	DBG("%s device %p", modem->path, device);
+}
+
+static int modem_enable(struct connman_device *device)
+{
+	struct modem_data *modem = connman_device_get_data(device);
+
+	DBG("%s device %p", modem->path, device);
+
+	if (modem->online)
+		return 0;
+
+	return modem_set_online(modem, TRUE);
+}
+
+static int modem_disable(struct connman_device *device)
+{
+	struct modem_data *modem = connman_device_get_data(device);
+
+	DBG("%s device %p", modem->path, device);
+
+	if (!modem->online)
+		return 0;
+
+	return modem_set_online(modem, FALSE);
+}
+
+static struct connman_device_driver modem_driver = {
+	.name		= "modem",
+	.type		= CONNMAN_DEVICE_TYPE_CELLULAR,
+	.probe		= modem_probe,
+	.remove		= modem_remove,
+	.enable		= modem_enable,
+	.disable	= modem_disable,
+};
+
+static int tech_probe(struct connman_technology *technology)
+{
+	return 0;
+}
+
+static void tech_remove(struct connman_technology *technology)
+{
+}
+
+static struct connman_technology_driver tech_driver = {
+	.name		= "cellular",
+	.type		= CONNMAN_SERVICE_TYPE_CELLULAR,
+	.probe		= tech_probe,
+	.remove		= tech_remove,
+};
+
+static guint watch;
+static guint modem_added_watch;
+static guint modem_removed_watch;
+static guint modem_watch;
+static guint cm_watch;
+static guint sim_watch;
+static guint context_added_watch;
+static guint context_removed_watch;
+static guint netreg_watch;
+static guint context_watch;
+static guint cdma_cm_watch;
+static guint cdma_netreg_watch;
+
+static int ofono_init(void)
+{
+	int err;
+
+	DBG("");
+
+	connection = connman_dbus_get_connection();
+	if (!connection)
+		return -EIO;
+
+	watch = g_dbus_add_service_watch(connection,
+					OFONO_SERVICE, ofono_connect,
+					ofono_disconnect, NULL, NULL);
+
+	modem_added_watch = g_dbus_add_signal_watch(connection, OFONO_SERVICE,
+						NULL, OFONO_MANAGER_INTERFACE,
+						MODEM_ADDED,
+						modem_added,
+						NULL, NULL);
+
+	modem_removed_watch = g_dbus_add_signal_watch(connection,
+						OFONO_SERVICE, NULL,
+						OFONO_MANAGER_INTERFACE,
+						MODEM_REMOVED,
+						modem_removed,
+						NULL, NULL);
+
+	modem_watch = g_dbus_add_signal_watch(connection, OFONO_SERVICE, NULL,
+						OFONO_MODEM_INTERFACE,
+						PROPERTY_CHANGED,
+						modem_changed,
+						NULL, NULL);
+
+	cm_watch = g_dbus_add_signal_watch(connection, OFONO_SERVICE, NULL,
+						OFONO_CM_INTERFACE,
+						PROPERTY_CHANGED,
+						cm_changed,
+						NULL, NULL);
+
+	sim_watch = g_dbus_add_signal_watch(connection, OFONO_SERVICE, NULL,
+						OFONO_SIM_INTERFACE,
+						PROPERTY_CHANGED,
+						sim_changed,
+						NULL, NULL);
+
+	context_added_watch = g_dbus_add_signal_watch(connection,
+						OFONO_SERVICE, NULL,
+						OFONO_CM_INTERFACE,
+						CONTEXT_ADDED,
+						cm_context_added,
+						NULL, NULL);
+
+	context_removed_watch = g_dbus_add_signal_watch(connection,
+						OFONO_SERVICE, NULL,
+						OFONO_CM_INTERFACE,
+						CONTEXT_REMOVED,
+						cm_context_removed,
+						NULL, NULL);
+
+	context_watch = g_dbus_add_signal_watch(connection, OFONO_SERVICE,
+						NULL, OFONO_CONTEXT_INTERFACE,
+						PROPERTY_CHANGED,
+						context_changed,
+						NULL, NULL);
+
+	netreg_watch = g_dbus_add_signal_watch(connection, OFONO_SERVICE, NULL,
+						OFONO_NETREG_INTERFACE,
+						PROPERTY_CHANGED,
+						netreg_changed,
+						NULL, NULL);
+
+	cdma_cm_watch = g_dbus_add_signal_watch(connection, OFONO_SERVICE,
+						NULL, OFONO_CDMA_CM_INTERFACE,
+						PROPERTY_CHANGED,
+						cdma_cm_changed,
+						NULL, NULL);
+
+	cdma_netreg_watch = g_dbus_add_signal_watch(connection, OFONO_SERVICE,
+						NULL, OFONO_CDMA_NETREG_INTERFACE,
+						PROPERTY_CHANGED,
+						cdma_netreg_changed,
+						NULL, NULL);
+
+
+	if (watch == 0 || modem_added_watch == 0 || modem_removed_watch == 0 ||
+			modem_watch == 0 || cm_watch == 0 || sim_watch == 0 ||
+			context_added_watch == 0 ||
+			context_removed_watch == 0 ||
+			context_watch == 0 || netreg_watch == 0 ||
+			cdma_cm_watch == 0 || cdma_netreg_watch == 0) {
+		err = -EIO;
+		goto remove;
+	}
+
+	err = connman_network_driver_register(&network_driver);
+	if (err < 0)
+		goto remove;
+
+	err = connman_device_driver_register(&modem_driver);
+	if (err < 0) {
+		connman_network_driver_unregister(&network_driver);
+		goto remove;
+	}
+
+	err = connman_technology_driver_register(&tech_driver);
+	if (err < 0) {
+		connman_device_driver_unregister(&modem_driver);
+		connman_network_driver_unregister(&network_driver);
+		goto remove;
+	}
+
+	return 0;
+
+remove:
+	g_dbus_remove_watch(connection, cdma_netreg_watch);
+	g_dbus_remove_watch(connection, cdma_cm_watch);
+	g_dbus_remove_watch(connection, netreg_watch);
+	g_dbus_remove_watch(connection, context_watch);
+	g_dbus_remove_watch(connection, context_removed_watch);
+	g_dbus_remove_watch(connection, context_added_watch);
+	g_dbus_remove_watch(connection, sim_watch);
+	g_dbus_remove_watch(connection, cm_watch);
+	g_dbus_remove_watch(connection, modem_watch);
+	g_dbus_remove_watch(connection, modem_removed_watch);
+	g_dbus_remove_watch(connection, modem_added_watch);
+	g_dbus_remove_watch(connection, watch);
+	dbus_connection_unref(connection);
+
+	return err;
+}
+
+static void ofono_exit(void)
+{
+	DBG("");
+
+	if (modem_hash) {
+		/*
+		 * We should propably wait for the SetProperty() reply
+		 * message, because ...
+		 */
+		g_hash_table_foreach(modem_hash, modem_power_down, NULL);
+
+		/*
+		 * ... here we will cancel the call.
+		 */
+		g_hash_table_destroy(modem_hash);
+		modem_hash = NULL;
+	}
+
+	if (context_hash) {
+		g_hash_table_destroy(context_hash);
+		context_hash = NULL;
+	}
+
+	connman_technology_driver_unregister(&tech_driver);
+	connman_device_driver_unregister(&modem_driver);
+	connman_network_driver_unregister(&network_driver);
+
+	g_dbus_remove_watch(connection, cdma_netreg_watch);
+	g_dbus_remove_watch(connection, cdma_cm_watch);
+	g_dbus_remove_watch(connection, netreg_watch);
+	g_dbus_remove_watch(connection, context_watch);
+	g_dbus_remove_watch(connection, context_removed_watch);
+	g_dbus_remove_watch(connection, context_added_watch);
+	g_dbus_remove_watch(connection, sim_watch);
+	g_dbus_remove_watch(connection, cm_watch);
+	g_dbus_remove_watch(connection, modem_watch);
+	g_dbus_remove_watch(connection, modem_added_watch);
+	g_dbus_remove_watch(connection, modem_removed_watch);
+	g_dbus_remove_watch(connection, watch);
+
+	dbus_connection_unref(connection);
+}
+
+CONNMAN_PLUGIN_DEFINE(ofono, "oFono telephony plugin", VERSION,
+		CONNMAN_PLUGIN_PRIORITY_DEFAULT, ofono_init, ofono_exit)
diff --git a/connman/plugins/pacrunner.c b/connman/plugins/pacrunner.c
new file mode 100644
index 0000000..850139f
--- /dev/null
+++ b/connman/plugins/pacrunner.c
@@ -0,0 +1,477 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2013  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 <string.h>
+
+#include <gdbus.h>
+
+#define CONNMAN_API_SUBJECT_TO_CHANGE
+#include <connman/plugin.h>
+#include <connman/notifier.h>
+#include <connman/dbus.h>
+#include <connman/log.h>
+#include <connman/proxy.h>
+
+#define PACRUNNER_SERVICE	"org.pacrunner"
+#define PACRUNNER_INTERFACE	"org.pacrunner.Manager"
+#define PACRUNNER_PATH		"/org/pacrunner/manager"
+
+#define PACRUNNER_CLIENT_INTERFACE	"org.pacrunner.Client"
+#define PACRUNNER_CLIENT_PATH		"/org/pacrunner/client"
+
+#define DBUS_TIMEOUT	5000
+
+struct proxy_data {
+	struct connman_service *service;
+	char *url;
+};
+
+static DBusConnection *connection;
+static dbus_bool_t daemon_running = FALSE;
+
+static struct connman_service *default_service = NULL;
+static char *current_config = NULL;
+
+static void create_config_reply(DBusPendingCall *call, void *user_data)
+{
+	DBusMessage *reply = dbus_pending_call_steal_reply(call);
+	const char *path;
+
+	DBG("");
+
+	if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) {
+		connman_error("Failed to create proxy configuration");
+		goto done;
+	}
+
+	if (!dbus_message_get_args(reply, NULL, DBUS_TYPE_OBJECT_PATH,
+					&path, DBUS_TYPE_INVALID))
+		goto done;
+
+	g_free(current_config);
+	current_config = g_strdup(path);
+
+done:
+	dbus_message_unref(reply);
+}
+
+static void append_string(DBusMessageIter *iter, void *user_data)
+{
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, user_data);
+}
+
+static void append_string_list(DBusMessageIter *iter, void *user_data)
+{
+	char **list = user_data;
+	int i;
+
+	for (i = 0; list[i]; i++)
+		dbus_message_iter_append_basic(iter,
+					DBUS_TYPE_STRING, &list[i]);
+}
+
+static void create_proxy_configuration(void)
+{
+	DBusMessage *msg;
+	DBusMessageIter iter, dict;
+	DBusPendingCall *call;
+	dbus_bool_t result;
+	char *interface;
+	const char *method;
+	const char *str;
+	char **str_list;
+
+	if (!default_service)
+		return;
+
+	DBG("");
+
+	msg = dbus_message_new_method_call(PACRUNNER_SERVICE, PACRUNNER_PATH,
+			PACRUNNER_INTERFACE, "CreateProxyConfiguration");
+	if (!msg)
+		return;
+
+	dbus_message_set_auto_start(msg, FALSE);
+
+	dbus_message_iter_init_append(msg, &iter);
+	connman_dbus_dict_open(&iter, &dict);
+
+	switch(connman_service_get_proxy_method(default_service)) {
+	case CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN:
+		connman_dbus_dict_close(&iter, &dict);
+		goto done;
+	case CONNMAN_SERVICE_PROXY_METHOD_DIRECT:
+		method= "direct";
+		break;
+	case CONNMAN_SERVICE_PROXY_METHOD_MANUAL:
+		method = "manual";
+
+		str_list = connman_service_get_proxy_servers(default_service);
+		if (!str_list) {
+			connman_dbus_dict_close(&iter, &dict);
+			goto done;
+		}
+
+		connman_dbus_dict_append_array(&dict, "Servers",
+					DBUS_TYPE_STRING, append_string_list,
+					str_list);
+		g_strfreev(str_list);
+
+		str_list = connman_service_get_proxy_excludes(default_service);
+		if (!str_list)
+			break;
+
+		connman_dbus_dict_append_array(&dict, "Excludes",
+					DBUS_TYPE_STRING, append_string_list,
+					str_list);
+		g_strfreev(str_list);
+
+		break;
+	case CONNMAN_SERVICE_PROXY_METHOD_AUTO:
+		method = "auto";
+
+		str = connman_service_get_proxy_url(default_service);
+		if (!str) {
+			str = connman_service_get_proxy_autoconfig(
+							default_service);
+			if (!str) {
+				connman_dbus_dict_close(&iter, &dict);
+				goto done;
+			}
+		}
+
+		connman_dbus_dict_append_basic(&dict, "URL",
+					DBUS_TYPE_STRING, &str);
+		break;
+	}
+
+	connman_dbus_dict_append_basic(&dict, "Method",
+				DBUS_TYPE_STRING, &method);
+
+	interface = connman_service_get_interface(default_service);
+	if (interface) {
+		connman_dbus_dict_append_basic(&dict, "Interface",
+						DBUS_TYPE_STRING, &interface);
+		g_free(interface);
+	}
+
+	str = connman_service_get_domainname(default_service);
+	if (str)
+		connman_dbus_dict_append_array(&dict, "Domains",
+					DBUS_TYPE_STRING, append_string, &str);
+
+	str_list = connman_service_get_nameservers(default_service);
+	if (str_list)
+		connman_dbus_dict_append_array(&dict, "Nameservers",
+					DBUS_TYPE_STRING, append_string_list,
+					str_list);
+	g_strfreev(str_list);
+
+	connman_dbus_dict_close(&iter, &dict);
+
+	result = dbus_connection_send_with_reply(connection, msg,
+							&call, DBUS_TIMEOUT);
+
+	if (!result || !call)
+		goto done;
+
+	dbus_pending_call_set_notify(call, create_config_reply, NULL, NULL);
+
+	dbus_pending_call_unref(call);
+
+done:
+	dbus_message_unref(msg);
+}
+
+static void destroy_config_reply(DBusPendingCall *call, void *user_data)
+{
+	DBusMessage *reply = dbus_pending_call_steal_reply(call);
+
+	DBG("");
+
+	if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR)
+		connman_error("Failed to destoy proxy configuration");
+
+	dbus_message_unref(reply);
+}
+
+static void destroy_proxy_configuration(void)
+{
+	DBusMessage *msg;
+	DBusPendingCall *call;
+	dbus_bool_t result;
+
+	if (!current_config)
+		return;
+
+	DBG("");
+
+	msg = dbus_message_new_method_call(PACRUNNER_SERVICE, PACRUNNER_PATH,
+			PACRUNNER_INTERFACE, "DestroyProxyConfiguration");
+	if (!msg)
+		return;
+
+	dbus_message_set_auto_start(msg, FALSE);
+
+	dbus_message_append_args(msg, DBUS_TYPE_OBJECT_PATH, &current_config,
+							DBUS_TYPE_INVALID);
+
+	result = dbus_connection_send_with_reply(connection, msg,
+							&call, DBUS_TIMEOUT);
+
+	dbus_message_unref(msg);
+
+	if (!result || !call)
+		return;
+
+	dbus_pending_call_set_notify(call, destroy_config_reply, NULL, NULL);
+
+	dbus_pending_call_unref(call);
+
+	g_free(current_config);
+	current_config = NULL;
+}
+
+static void default_service_changed(struct connman_service *service)
+{
+	DBG("service %p", service);
+
+	if (service == default_service)
+		return;
+
+	default_service = service;
+
+	if (!daemon_running)
+		return;
+
+	destroy_proxy_configuration();
+
+	create_proxy_configuration();
+}
+
+static void proxy_changed(struct connman_service *service)
+{
+	DBG("service %p", service);
+
+	if (service != default_service)
+		return;
+
+	if (!daemon_running)
+		return;
+
+	destroy_proxy_configuration();
+
+	create_proxy_configuration();
+}
+
+static struct connman_notifier pacrunner_notifier = {
+	.name			= "pacrunner",
+	.default_changed	= default_service_changed,
+	.proxy_changed		= proxy_changed,
+};
+
+static void pacrunner_connect(DBusConnection *conn, void *user_data)
+{
+	DBG("");
+
+	daemon_running = TRUE;
+
+	create_proxy_configuration();
+}
+
+static void pacrunner_disconnect(DBusConnection *conn, void *user_data)
+{
+	DBG("");
+
+	daemon_running = FALSE;
+
+	g_free(current_config);
+	current_config = NULL;
+}
+
+static char * parse_url(const char *url)
+{
+	char *scheme, *host, *path, *host_ret;
+
+	scheme = g_strdup(url);
+	if (!scheme)
+		return NULL;
+
+	host = strstr(scheme, "://");
+	if (host) {
+		*host = '\0';
+		host += 3;
+	} else
+		host = scheme;
+
+	path = strchr(host, '/');
+	if (path)
+		*(path++) = '\0';
+
+	host_ret = g_strdup(host);
+
+	g_free(scheme);
+
+	return host_ret;
+}
+
+static void request_lookup_reply(DBusPendingCall *call, void *user_data)
+{
+	DBusMessage *reply = dbus_pending_call_steal_reply(call);
+	struct proxy_data *data = user_data;
+	const char *proxy;
+
+	DBG("");
+
+	if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) {
+		connman_error("Failed to find URL:%s", data->url);
+		proxy = NULL;
+		goto done;
+	}
+
+	if (!dbus_message_get_args(reply, NULL, DBUS_TYPE_STRING,
+					&proxy, DBUS_TYPE_INVALID))
+		proxy = NULL;
+
+done:
+	connman_proxy_driver_lookup_notify(data->service, data->url, proxy);
+
+	connman_service_unref(data->service);
+
+	g_free(data->url);
+	g_free(data);
+
+	dbus_message_unref(reply);
+}
+
+static int request_lookup(struct connman_service *service, const char *url)
+{
+	DBusMessage *msg;
+	DBusPendingCall *call;
+	dbus_bool_t result;
+	char *host;
+	struct proxy_data *data;
+
+	DBG("");
+
+	msg = dbus_message_new_method_call(PACRUNNER_SERVICE,
+						PACRUNNER_CLIENT_PATH,
+						PACRUNNER_CLIENT_INTERFACE,
+						"FindProxyForURL");
+	if (!msg)
+		return -1;
+
+	host = parse_url(url);
+	if (!host) {
+		dbus_message_unref(msg);
+		return -EINVAL;
+	}
+
+	data = g_try_new0(struct proxy_data, 1);
+	if (!data) {
+		dbus_message_unref(msg);
+		g_free(host);
+		return -ENOMEM;
+	}
+
+	data->url = g_strdup(url);
+	data->service = connman_service_ref(service);
+
+	dbus_message_append_args(msg, DBUS_TYPE_STRING, &url,
+					DBUS_TYPE_STRING, &host,
+					DBUS_TYPE_INVALID);
+
+	result = dbus_connection_send_with_reply(connection, msg,
+							&call, DBUS_TIMEOUT);
+
+	dbus_message_unref(msg);
+
+	if (!result || !call) {
+		g_free(host);
+		g_free(data->url);
+		g_free(data);
+		return -EINVAL;
+	}
+
+	dbus_pending_call_set_notify(call, request_lookup_reply,
+							data, NULL);
+
+	dbus_pending_call_unref(call);
+	g_free(host);
+
+	return 0;
+}
+
+static void cancel_lookup(struct connman_service *service, const char *url)
+{
+	DBG("");
+}
+
+static struct connman_proxy_driver pacrunner_proxy = {
+	.name		= "pacrunnerproxy",
+	.priority	= CONNMAN_PROXY_PRIORITY_HIGH,
+	.request_lookup	= request_lookup,
+	.cancel_lookup	= cancel_lookup,
+};
+
+static guint pacrunner_watch;
+
+static int pacrunner_init(void)
+{
+	connection = connman_dbus_get_connection();
+	if (!connection)
+		return -EIO;
+
+	pacrunner_watch = g_dbus_add_service_watch(connection,
+					PACRUNNER_SERVICE, pacrunner_connect,
+					pacrunner_disconnect, NULL, NULL);
+	if (pacrunner_watch == 0) {
+		dbus_connection_unref(connection);
+		return -EIO;
+	}
+
+	connman_notifier_register(&pacrunner_notifier);
+
+	connman_proxy_driver_register(&pacrunner_proxy);
+
+	return 0;
+}
+
+static void pacrunner_exit(void)
+{
+	connman_proxy_driver_unregister(&pacrunner_proxy);
+
+	connman_notifier_unregister(&pacrunner_notifier);
+
+	g_dbus_remove_watch(connection, pacrunner_watch);
+
+	destroy_proxy_configuration();
+
+	dbus_connection_unref(connection);
+}
+
+CONNMAN_PLUGIN_DEFINE(pacrunner, "PAC runner proxy plugin", VERSION,
+		CONNMAN_PLUGIN_PRIORITY_DEFAULT, pacrunner_init, pacrunner_exit)
diff --git a/connman/plugins/polkit.c b/connman/plugins/polkit.c
new file mode 100644
index 0000000..ae38364
--- /dev/null
+++ b/connman/plugins/polkit.c
@@ -0,0 +1,55 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2012  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 <gdbus.h>
+
+#define CONNMAN_API_SUBJECT_TO_CHANGE
+#include <connman/plugin.h>
+#include <connman/dbus.h>
+
+static const GDBusSecurityTable polkit_security[] = {
+	{ CONNMAN_PRIVILEGE_MODIFY, "net.connman.modify",
+				G_DBUS_SECURITY_FLAG_BUILTIN |
+				G_DBUS_SECURITY_FLAG_ALLOW_INTERACTION },
+	{ CONNMAN_PRIVILEGE_SECRET, "net.connman.secret",
+				G_DBUS_SECURITY_FLAG_BUILTIN |
+				G_DBUS_SECURITY_FLAG_ALLOW_INTERACTION },
+	{ }
+};
+
+static int polkit_init(void)
+{
+	g_dbus_register_security(polkit_security);
+
+	return 0;
+}
+
+static void polkit_exit(void)
+{
+	g_dbus_unregister_security(polkit_security);
+}
+
+CONNMAN_PLUGIN_DEFINE(polkit, "PolicyKit authorization plugin", VERSION,
+		CONNMAN_PLUGIN_PRIORITY_DEFAULT, polkit_init, polkit_exit)
diff --git a/connman/plugins/polkit.policy b/connman/plugins/polkit.policy
new file mode 100644
index 0000000..0de152c
--- /dev/null
+++ b/connman/plugins/polkit.policy
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE policyconfig PUBLIC
+ "-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN"
+ "http://www.freedesktop.org/standards/PolicyKit/1.0/policyconfig.dtd">
+
+<policyconfig>
+
+  <vendor>Connection Manager</vendor>
+  <icon_name>network-wireless</icon_name>
+
+  <action id="net.connman.modify">
+    <description>Settings configuration</description>
+    <message>Policy prevents modification of settings</message>
+    <defaults>
+      <allow_inactive>no</allow_inactive>
+      <allow_active>auth_self_keep</allow_active>
+    </defaults>
+  </action>
+
+  <action id="net.connman.secret">
+    <description>Secrets configuration</description>
+    <message>Policy prevents modification of secrets</message>
+    <defaults>
+      <allow_inactive>no</allow_inactive>
+      <allow_active>auth_admin_keep</allow_active>
+    </defaults>
+  </action>
+
+</policyconfig>
diff --git a/connman/plugins/session_policy_local.c b/connman/plugins/session_policy_local.c
new file mode 100644
index 0000000..b2369bd
--- /dev/null
+++ b/connman/plugins/session_policy_local.c
@@ -0,0 +1,823 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2012-2014  BMW Car IT GmbH.
+ *
+ *  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 <string.h>
+#include <sys/inotify.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <pwd.h>
+#include <grp.h>
+
+#include <glib.h>
+
+#include <gdbus.h>
+
+#define CONNMAN_API_SUBJECT_TO_CHANGE
+#include <connman/plugin.h>
+#include <connman/log.h>
+#include <connman/session.h>
+#include <connman/dbus.h>
+#include <connman/inotify.h>
+
+#include "src/shared/util.h"
+
+#define POLICYDIR STORAGEDIR "/session_policy_local"
+
+#define MODE		(S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | \
+			S_IXGRP | S_IROTH | S_IXOTH)
+
+static DBusConnection *connection;
+
+static GHashTable *file_hash;    /* (filename, policy_file) */
+static GHashTable *session_hash; /* (connman_session, policy_config) */
+
+/* Global lookup tables for mapping sessions to policies */
+static GHashTable *selinux_hash; /* (lsm context, policy_group) */
+static GHashTable *uid_hash;     /* (uid, policy_group) */
+static GHashTable *gid_hash;     /* (gid, policy_group) */
+
+/*
+ * A instance of struct policy_file is created per file in
+ * POLICYDIR.
+ */
+struct policy_file {
+	/*
+	 * A valid file is a keyfile with one ore more groups. All
+	 * groups are keept in this list.
+	 */
+	GSList *groups;
+};
+
+struct policy_group {
+	char *selinux;
+	char *uid;
+	char *gid;
+
+	/*
+	 * Each policy_group owns a config and is not shared with
+	 * sessions. Instead each session copies the valued from this
+	 * object.
+	 */
+	struct connman_session_config *config;
+
+	/* All 'users' of this policy. */
+	GSList *sessions;
+};
+
+/* A struct policy_config object is created and owned by a session. */
+struct policy_config {
+	char *selinux;
+	char *selinux_context;
+	char *uid;
+	GSList *gids;
+
+	/* The policy config owned by the session */
+	struct connman_session_config *config;
+
+	/* To which policy belongs this policy_config */
+	struct connman_session *session;
+	/*
+	 * Points to the policy_group when a config has been applied
+	 * from a file.
+	 */
+	struct policy_group *group;
+};
+
+static void copy_session_config(struct connman_session_config *dst,
+			struct connman_session_config *src)
+{
+	g_slist_free(dst->allowed_bearers);
+	dst->allowed_bearers = g_slist_copy(src->allowed_bearers);
+	dst->ecall = src->ecall;
+	dst->type = src->type;
+	dst->roaming_policy = src->roaming_policy;
+	dst->priority = src->priority;
+}
+
+static void set_policy(struct policy_config *policy,
+			struct policy_group *group)
+{
+	DBG("policy %p group %p", policy, group);
+
+	group->sessions = g_slist_prepend(group->sessions, policy);
+	policy->group = group;
+
+	copy_session_config(policy->config, group->config);
+}
+
+static char *parse_selinux_type(const char *context)
+{
+	char *ident, **tokens;
+
+	/*
+	 * SELinux combines Role-Based Access Control (RBAC), Type
+	 * Enforcment (TE) and optionally Multi-Level Security (MLS).
+	 *
+	 * When SELinux is enabled all processes and files are labeled
+	 * with a contex that contains information such as user, role
+	 * type (and optionally a level). E.g.
+	 *
+	 * $ ls -Z
+	 * -rwxrwxr-x. wagi wagi unconfined_u:object_r:haifux_exec_t:s0 session_ui.py
+	 *
+	 * For identifyng application we (ab)using the type
+	 * information. In the above example the haifux_exec_t type
+	 * will be transfered to haifux_t as defined in the domain
+	 * transition and thus we are able to identify the application
+	 * as haifux_t.
+	 */
+
+	tokens = g_strsplit(context, ":", 0);
+	if (g_strv_length(tokens) < 2) {
+		g_strfreev(tokens);
+		return NULL;
+	}
+
+	/* Use the SELinux type as identification token. */
+	ident = g_strdup(tokens[2]);
+
+	g_strfreev(tokens);
+
+	return ident;
+}
+
+static void cleanup_config(gpointer user_data);
+
+static void finish_create(struct policy_config *policy,
+				connman_session_config_func_t cb,
+				void *user_data)
+{
+	struct policy_group *group = NULL;
+	GSList *list;
+
+	if (policy->selinux)
+		group = g_hash_table_lookup(selinux_hash, policy->selinux);
+
+	if (group) {
+		set_policy(policy, group);
+
+		policy->config->id_type = CONNMAN_SESSION_ID_TYPE_LSM;
+		policy->config->id = g_strdup(policy->selinux_context);
+		goto done;
+	}
+
+	if (policy->uid)
+		group = g_hash_table_lookup(uid_hash, policy->uid);
+
+	if (group) {
+		set_policy(policy, group);
+
+		policy->config->id_type = CONNMAN_SESSION_ID_TYPE_UID;
+		policy->config->id = g_strdup(policy->uid);
+		goto done;
+	}
+
+	for (list = policy->gids; list; list = list->next) {
+		char *gid = list->data;
+
+		group = g_hash_table_lookup(gid_hash, gid);
+		if (!group)
+			continue;
+
+		set_policy(policy, group);
+
+		policy->config->id_type = CONNMAN_SESSION_ID_TYPE_GID;
+		policy->config->id = g_strdup(gid);
+		break;
+	}
+done:
+	g_hash_table_replace(session_hash, policy->session, policy);
+
+	(*cb)(policy->session, policy->config, user_data, 0);
+}
+
+static void failed_create(struct policy_config *policy,
+			connman_session_config_func_t cb,
+			void *user_data, int err)
+{
+	(*cb)(policy->session, NULL, user_data, err);
+
+	cleanup_config(policy);
+}
+
+static void selinux_context_reply(const unsigned char *context, void *user_data,
+					int err)
+{
+	struct cb_data *cbd = user_data;
+	connman_session_config_func_t cb = cbd->cb;
+	struct policy_config *policy = cbd->data;
+	char *ident = NULL;
+
+	DBG("session %p", policy->session);
+
+	if (err == -EIO) {
+		/* No SELinux support, drop back to UID/GID only mode */
+		finish_create(policy, cb, cbd->user_data);
+		goto done;
+	}
+
+	if (err < 0) {
+		failed_create(policy, cb, cbd->user_data, err);
+		goto done;
+	}
+
+	DBG("SELinux context %s", context);
+
+	policy->selinux_context = g_strdup((const char *)context);
+	ident = parse_selinux_type(policy->selinux_context);
+	if (ident)
+		policy->selinux = g_strdup(ident);
+
+	finish_create(policy, cb, cbd->user_data);
+
+done:
+	g_free(cbd);
+	g_free(ident);
+}
+
+static void get_uid_reply(unsigned int uid, void *user_data, int err)
+{
+	struct cb_data *cbd = user_data;
+	connman_session_config_func_t cb = cbd->cb;
+	struct policy_config *policy = cbd->data;
+	const char *owner;
+	struct passwd *pwd;
+	struct group *grp;
+	gid_t *groups = NULL;
+	int nrgroups, i;
+
+	DBG("session %p uid %d", policy->session, uid);
+
+	if (err < 0) {
+		cleanup_config(policy);
+		goto err;
+	}
+
+	pwd = getpwuid((uid_t)uid);
+	if (!pwd) {
+		if (errno != 0)
+			err = -errno;
+		else
+			err = -EINVAL;
+		goto err;
+	}
+
+	policy->uid = g_strdup(pwd->pw_name);
+
+	nrgroups = 0;
+	getgrouplist(pwd->pw_name, pwd->pw_gid, NULL, &nrgroups);
+	groups = g_try_new0(gid_t, nrgroups);
+	if (!groups) {
+		err = -ENOMEM;
+		goto err;
+	}
+
+	err = getgrouplist(pwd->pw_name, pwd->pw_gid, groups, &nrgroups);
+	if (err < 0)
+		goto err;
+
+	for (i = 0; i < nrgroups; i++) {
+		grp = getgrgid(groups[i]);
+		if (!grp) {
+			if (errno != 0)
+				err = -errno;
+			else
+				err = -EINVAL;
+			goto err;
+		}
+
+		policy->gids = g_slist_prepend(policy->gids,
+					g_strdup(grp->gr_name));
+	}
+	g_free(groups);
+
+	owner = connman_session_get_owner(policy->session);
+
+	err = connman_dbus_get_selinux_context(connection, owner,
+						selinux_context_reply, cbd);
+	if (err == 0) {
+		/*
+		 * We are able to ask for a SELinux context. Let's defer the
+		 * creation of the session config until we get the answer
+		 * from D-Bus.
+		 */
+		return;
+	}
+
+	finish_create(policy, cb, cbd->user_data);
+	g_free(cbd);
+
+	return;
+
+err:
+	failed_create(NULL, cb, cbd->user_data, err);
+	g_free(cbd);
+	g_free(groups);
+}
+
+static int policy_local_create(struct connman_session *session,
+				connman_session_config_func_t cb,
+				void *user_data)
+{
+	struct cb_data *cbd = cb_data_new(cb, user_data);
+	struct policy_config *policy;
+	const char *owner;
+	int err;
+
+	DBG("session %p", session);
+
+	policy = g_new0(struct policy_config, 1);
+	policy->config = connman_session_create_default_config();
+	policy->session = session;
+
+	cbd->data = policy;
+
+	owner = connman_session_get_owner(session);
+
+	err = connman_dbus_get_connection_unix_user(connection, owner,
+						get_uid_reply, cbd);
+	if (err < 0) {
+		connman_error("Could not get UID");
+		cleanup_config(policy);
+		g_free(cbd);
+		return err;
+	}
+
+	return 0;
+}
+
+static void policy_local_destroy(struct connman_session *session)
+{
+	struct policy_data *policy;
+
+	DBG("session %p", session);
+
+	policy = g_hash_table_lookup(session_hash, session);
+	if (!policy)
+		return;
+
+	g_hash_table_remove(session_hash, session);
+}
+
+static struct connman_session_policy session_policy_local = {
+	.name = "session local policy configuration",
+	.priority = CONNMAN_SESSION_POLICY_PRIORITY_DEFAULT,
+	.create = policy_local_create,
+	.destroy = policy_local_destroy,
+};
+
+static int load_keyfile(const char *pathname, GKeyFile **keyfile)
+{
+	GError *error = NULL;
+	int err;
+
+	*keyfile = g_key_file_new();
+
+	if (!g_key_file_load_from_file(*keyfile, pathname, 0, &error))
+		goto err;
+
+	return 0;
+
+err:
+	/*
+	 * The fancy G_FILE_ERROR_* codes are identical to the native
+	 * error codes.
+	 */
+	err = -error->code;
+
+	DBG("Unable to load %s: %s", pathname, error->message);
+	g_clear_error(&error);
+
+	g_key_file_free(*keyfile);
+	*keyfile = NULL;
+
+	return err;
+}
+
+static int load_policy(GKeyFile *keyfile, const char *groupname,
+			struct policy_group *group)
+{
+	struct connman_session_config *config = group->config;
+	char *str, **tokens;
+	int i, err = 0;
+
+	group->selinux = g_key_file_get_string(keyfile, groupname,
+						"selinux", NULL);
+
+	group->gid = g_key_file_get_string(keyfile, groupname,
+						"gid", NULL);
+
+	group->uid = g_key_file_get_string(keyfile, groupname,
+						"uid", NULL);
+
+	if (!group->selinux && !group->gid && !group->uid)
+		return -EINVAL;
+
+	config->priority = g_key_file_get_boolean(keyfile, groupname,
+						"Priority", NULL);
+
+	str = g_key_file_get_string(keyfile, groupname, "RoamingPolicy",
+				NULL);
+	if (str) {
+		config->roaming_policy = connman_session_parse_roaming_policy(str);
+		g_free(str);
+	}
+
+	str = g_key_file_get_string(keyfile, groupname, "ConnectionType",
+				NULL);
+	if (str) {
+		config->type = connman_session_parse_connection_type(str);
+		g_free(str);
+	}
+
+	config->ecall = g_key_file_get_boolean(keyfile, groupname,
+						"EmergencyCall", NULL);
+
+	str = g_key_file_get_string(keyfile, groupname, "AllowedBearers",
+				NULL);
+	if (str) {
+		tokens = g_strsplit(str, " ", 0);
+
+		for (i = 0; tokens[i]; i++) {
+			err = connman_session_parse_bearers(tokens[i],
+					&config->allowed_bearers);
+			if (err < 0)
+				break;
+		}
+
+		g_free(str);
+		g_strfreev(tokens);
+	}
+
+	DBG("group %p selinux %s uid %s gid %s", group, group->selinux,
+		group->uid, group->gid);
+
+	return err;
+}
+
+static void update_session(struct policy_config *policy)
+{
+	DBG("policy %p session %p", policy, policy->session);
+
+	if (!policy->session)
+		return;
+
+	if (connman_session_config_update(policy->session) < 0)
+		connman_session_destroy(policy->session);
+}
+
+static void set_default_config(gpointer user_data)
+{
+	struct policy_config *policy = user_data;
+
+	connman_session_set_default_config(policy->config);
+	policy->group = NULL;
+	update_session(policy);
+}
+
+static void cleanup_config(gpointer user_data)
+{
+	struct policy_config *policy = user_data;
+
+	DBG("policy %p group %p", policy, policy->group);
+
+	if (policy->group)
+		policy->group->sessions =
+			g_slist_remove(policy->group->sessions, policy);
+
+	g_slist_free(policy->config->allowed_bearers);
+	g_free(policy->config->id);
+	g_free(policy->config);
+	g_free(policy->selinux_context);
+	g_free(policy->selinux);
+	g_free(policy->uid);
+	g_slist_free_full(policy->gids, g_free);
+	g_free(policy);
+}
+
+static void cleanup_group(gpointer user_data)
+{
+	struct policy_group *group = user_data;
+
+	DBG("group %p", group);
+
+	g_slist_free_full(group->sessions, set_default_config);
+
+	g_slist_free(group->config->allowed_bearers);
+	g_free(group->config->id);
+	g_free(group->config);
+	if (group->selinux)
+		g_hash_table_remove(selinux_hash, group->selinux);
+	if (group->uid)
+		g_hash_table_remove(uid_hash, group->uid);
+	if (group->gid)
+		g_hash_table_remove(gid_hash, group->gid);
+	g_free(group->selinux);
+	g_free(group->uid);
+	g_free(group->gid);
+	g_free(group);
+}
+
+static void cleanup_file(gpointer user_data)
+{
+	struct policy_file *file = user_data;
+
+	DBG("file %p", file);
+
+	g_slist_free_full(file->groups, cleanup_group);
+	g_free(file);
+}
+
+static void recheck_sessions(void)
+{
+	GHashTableIter iter;
+	gpointer value, key;
+	struct policy_group *group = NULL;
+	GSList *list;
+
+	g_hash_table_iter_init(&iter, session_hash);
+	while (g_hash_table_iter_next(&iter, &key, &value)) {
+		struct policy_config *policy = value;
+
+		if (policy->group)
+			continue;
+
+		if (policy->selinux)
+			group = g_hash_table_lookup(selinux_hash,
+							policy->selinux);
+		if (group) {
+			policy->config->id_type = CONNMAN_SESSION_ID_TYPE_LSM;
+			g_free(policy->config->id);
+			policy->config->id = g_strdup(policy->selinux_context);
+			update_session(policy);
+			continue;
+		}
+
+		group = g_hash_table_lookup(uid_hash, policy->uid);
+		if (group) {
+			set_policy(policy, group);
+
+			policy->config->id_type = CONNMAN_SESSION_ID_TYPE_UID;
+			g_free(policy->config->id);
+			policy->config->id = g_strdup(policy->uid);
+			update_session(policy);
+			continue;
+		}
+
+		for (list = policy->gids; list; list = list->next) {
+			char *gid = list->data;
+			group = g_hash_table_lookup(gid_hash, gid);
+			if (group) {
+				set_policy(policy, group);
+
+				policy->config->id_type = CONNMAN_SESSION_ID_TYPE_GID;
+				g_free(policy->config->id);
+				policy->config->id = g_strdup(gid);
+				update_session(policy);
+			}
+		}
+	}
+}
+
+static int load_file(const char *filename, struct policy_file *file)
+{
+	GKeyFile *keyfile;
+	struct policy_group *group;
+	char **groupnames;
+	char *pathname;
+	int err = 0, i;
+
+	DBG("%s", filename);
+
+	pathname = g_strdup_printf("%s/%s", POLICYDIR, filename);
+	err = load_keyfile(pathname, &keyfile);
+	g_free(pathname);
+
+	if (err < 0)
+		return err;
+
+	groupnames = g_key_file_get_groups(keyfile, NULL);
+
+	for (i = 0; groupnames[i]; i++) {
+		group = g_new0(struct policy_group, 1);
+		group->config = g_new0(struct connman_session_config, 1);
+
+		err = load_policy(keyfile, groupnames[i], group);
+		if (err < 0) {
+			g_free(group->config);
+			g_free(group);
+			break;
+		}
+		if (group->selinux)
+			g_hash_table_replace(selinux_hash, group->selinux, group);
+
+		if (group->uid)
+			g_hash_table_replace(uid_hash, group->uid, group);
+
+		if (group->gid)
+			g_hash_table_replace(gid_hash, group->gid, group);
+
+		file->groups = g_slist_prepend(file->groups, group);
+	}
+
+	g_strfreev(groupnames);
+
+	if (err < 0)
+		g_slist_free_full(file->groups, cleanup_group);
+
+	g_key_file_free(keyfile);
+
+	return err;
+}
+
+static bool is_filename_valid(const char *filename)
+{
+	if (!filename)
+		return false;
+
+	if (filename[0] == '.')
+		return false;
+
+	return g_str_has_suffix(filename, ".policy");
+}
+
+static int read_policies(void)
+{
+	GDir *dir;
+	const gchar *filename;
+	struct policy_file *file;
+
+	DBG("");
+
+	dir = g_dir_open(POLICYDIR, 0, NULL);
+	if (!dir)
+		return -EINVAL;
+
+	while ((filename = g_dir_read_name(dir))) {
+		if (!is_filename_valid(filename))
+			continue;
+
+		file = g_new0(struct policy_file, 1);
+		if (load_file(filename, file) < 0) {
+			g_free(file);
+			continue;
+		}
+
+		g_hash_table_replace(file_hash, g_strdup(filename), file);
+	}
+
+	g_dir_close(dir);
+
+	return 0;
+}
+
+
+static void notify_handler(struct inotify_event *event,
+                                        const char *filename)
+{
+	struct policy_file *file;
+
+	DBG("event %x file %s", event->mask, filename);
+
+	if (event->mask & IN_CREATE)
+		return;
+
+	if (!is_filename_valid(filename))
+		return;
+
+	/*
+	 * load_file() will modify the global selinux/uid/gid hash
+	 * tables. We need to remove the old entries first before
+	 * else the table points to the wrong entries.
+	 */
+	g_hash_table_remove(file_hash, filename);
+
+	if (event->mask & (IN_DELETE | IN_MOVED_FROM))
+		return;
+
+	if (event->mask & (IN_MOVED_TO | IN_MODIFY)) {
+		connman_info("Policy update for '%s'", filename);
+
+		file = g_new0(struct policy_file, 1);
+		if (load_file(filename, file) < 0) {
+			g_free(file);
+			return;
+		}
+
+		g_hash_table_replace(file_hash, g_strdup(filename), file);
+		recheck_sessions();
+	}
+}
+
+static int session_policy_local_init(void)
+{
+	int err;
+
+	DBG("");
+
+	/* If the dir doesn't exist, create it */
+	if (!g_file_test(POLICYDIR, G_FILE_TEST_IS_DIR)) {
+		if (mkdir(POLICYDIR, MODE) < 0) {
+			if (errno != EEXIST)
+				return -errno;
+		}
+	}
+
+	connection = connman_dbus_get_connection();
+	if (!connection)
+		return -EIO;
+
+	file_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
+					g_free, cleanup_file);
+	session_hash = g_hash_table_new_full(g_direct_hash, g_direct_equal,
+						NULL, cleanup_config);
+	selinux_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
+					NULL, NULL);
+	uid_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
+					NULL, NULL);
+	gid_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
+					NULL, NULL);
+
+	err = connman_inotify_register(POLICYDIR, notify_handler);
+	if (err < 0)
+		goto err;
+
+	err = connman_session_policy_register(&session_policy_local);
+	if (err < 0)
+		goto err_notify;
+
+	read_policies();
+
+	return 0;
+
+err_notify:
+
+	connman_inotify_unregister(POLICYDIR, notify_handler);
+
+err:
+	if (file_hash)
+		g_hash_table_destroy(file_hash);
+
+	if (session_hash)
+		g_hash_table_destroy(session_hash);
+
+	if (selinux_hash)
+		g_hash_table_destroy(selinux_hash);
+
+	if (uid_hash)
+		g_hash_table_destroy(uid_hash);
+
+	if (gid_hash)
+		g_hash_table_destroy(gid_hash);
+
+	connman_session_policy_unregister(&session_policy_local);
+
+	dbus_connection_unref(connection);
+
+	return err;
+}
+
+static void session_policy_local_exit(void)
+{
+	DBG("");
+
+	g_hash_table_destroy(file_hash);
+	g_hash_table_destroy(session_hash);
+	g_hash_table_destroy(selinux_hash);
+	g_hash_table_destroy(uid_hash);
+	g_hash_table_destroy(gid_hash);
+
+	connman_session_policy_unregister(&session_policy_local);
+
+	dbus_connection_unref(connection);
+
+	connman_inotify_unregister(POLICYDIR, notify_handler);
+}
+
+CONNMAN_PLUGIN_DEFINE(session_policy_local,
+		"Session local file policy configuration plugin",
+		VERSION, CONNMAN_PLUGIN_PRIORITY_DEFAULT,
+		session_policy_local_init, session_policy_local_exit)
diff --git a/connman/plugins/tist.c b/connman/plugins/tist.c
new file mode 100644
index 0000000..ad5ef79
--- /dev/null
+++ b/connman/plugins/tist.c
@@ -0,0 +1,611 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2012  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
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <stdbool.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdint.h>
+#include <sys/ioctl.h>
+#include <termios.h>
+#include <unistd.h>
+
+#include <gdbus.h>
+
+#define CONNMAN_API_SUBJECT_TO_CHANGE
+#include <connman/plugin.h>
+#include <connman/log.h>
+
+#define TIST_SYSFS_INSTALL "/sys/devices/platform/kim/install"
+#define TIST_SYSFS_UART "/sys/devices/platform/kim/dev_name"
+#define TIST_SYSFS_BAUD "/sys/devices/platform/kim/baud_rate"
+
+/* Shared transport line discipline */
+#define N_TI_WL 22
+
+static GIOChannel *install_channel = NULL;
+static GIOChannel *uart_channel = NULL;
+static char uart_dev_name[32];
+static unsigned long baud_rate = 0;
+
+static guint install_watch = 0;
+static guint uart_watch = 0;
+
+static int install_count = 0;
+
+#define NCCS2 19
+struct termios2 {
+	tcflag_t c_iflag;		/* input mode flags */
+	tcflag_t c_oflag;		/* output mode flags */
+	tcflag_t c_cflag;		/* control mode flags */
+	tcflag_t c_lflag;		/* local mode flags */
+	cc_t c_line;			/* line discipline */
+	cc_t c_cc[NCCS2];		/* control characters */
+	speed_t c_ispeed;		/* input speed */
+	speed_t c_ospeed;		/* output speed */
+};
+
+#define  BOTHER         0x00001000
+
+/* HCI definitions */
+#define HCI_HDR_OPCODE          0xff36
+#define HCI_COMMAND_PKT         0x01
+#define HCI_EVENT_PKT           0x04
+#define EVT_CMD_COMPLETE        0x0E
+
+/* HCI Command structure to set the target baud rate */
+struct speed_change_cmd {
+	uint8_t uart_prefix;
+	uint16_t opcode;
+	uint8_t plen;
+	uint32_t speed;
+} __attribute__ ((packed));
+
+/* HCI Event structure to set the cusrom baud rate*/
+struct cmd_complete {
+	uint8_t uart_prefix;
+	uint8_t evt;
+	uint8_t plen;
+	uint8_t ncmd;
+	uint16_t opcode;
+	uint8_t status;
+	uint8_t data[16];
+} __attribute__ ((packed));
+
+static int read_baud_rate(unsigned long *baud)
+{
+	int err;
+	FILE *f;
+
+	DBG("");
+
+	f = fopen(TIST_SYSFS_BAUD, "r");
+	if (!f)
+		return -EIO;
+
+	err = fscanf(f, "%lu", baud);
+	fclose(f);
+
+	DBG("baud rate %lu", *baud);
+
+	return err;
+}
+
+static int read_uart_name(char uart_name[], size_t uart_name_len)
+{
+	int err;
+	FILE *f;
+
+	DBG("");
+
+	memset(uart_name, 0, uart_name_len);
+
+	f = fopen(TIST_SYSFS_UART, "r");
+	if (!f)
+		return -EIO;
+
+        err = fscanf(f, "%s", uart_name);
+	fclose(f);
+
+	DBG("UART name %s", uart_name);
+
+	return err;
+}
+
+static int read_hci_event(int fd, unsigned char *buf, int size)
+{
+	int prefix_len, param_len;
+
+	if (size <= 0)
+		return -EINVAL;
+
+	/* First 3 bytes are prefix, event and param length */
+	prefix_len = read(fd, buf, 3);
+	if (prefix_len < 0)
+		return prefix_len;
+
+	if (prefix_len < 3) {
+		connman_error("Truncated HCI prefix %d bytes 0x%x",
+						prefix_len, buf[0]);
+		return -EIO;
+	}
+
+	DBG("type 0x%x event 0x%x param len %d", buf[0], buf[1], buf[2]);
+
+	param_len = buf[2];
+	if (param_len > size - 3) {
+		connman_error("Buffer is too small %d", size);
+		return -EINVAL;
+	}
+
+	return read(fd, buf + 3, param_len);
+}
+
+static int read_command_complete(int fd, unsigned short opcode)
+{
+	struct cmd_complete resp;
+	int err;
+
+	DBG("");
+
+	err = read_hci_event(fd, (unsigned char *)&resp, sizeof(resp));
+	if (err < 0)
+		return err;
+
+	DBG("HCI event %d bytes", err);
+
+	if (resp.uart_prefix != HCI_EVENT_PKT) {
+		connman_error("Not an event packet");
+		return -EIO;
+	}
+
+	if (resp.evt != EVT_CMD_COMPLETE) {
+	        connman_error("Not a cmd complete event");
+		return -EIO;
+	}
+
+	if (resp.plen < 4) {
+		connman_error("HCI header length %d", resp.plen);
+		return -EIO;
+	}
+
+	if (resp.opcode != (unsigned short) opcode) {
+		connman_error("opcode 0x%04x 0x%04x", resp.opcode, opcode);
+		return -EIO;
+	}
+
+	return 0;
+}
+
+/* The default baud rate is 115200 */
+static int set_default_baud_rate(int fd)
+{
+	struct termios ti;
+	int err;
+
+	DBG("");
+
+	err = tcflush(fd, TCIOFLUSH);
+	if (err < 0)
+		goto err;
+
+	err = tcgetattr(fd, &ti);
+	if (err < 0)
+		goto err;
+
+	cfmakeraw(&ti);
+
+	ti.c_cflag |= 1;
+	ti.c_cflag |= CRTSCTS;
+
+	err = tcsetattr(fd, TCSANOW, &ti);
+	if (err < 0)
+		goto err;
+
+	cfsetospeed(&ti, B115200);
+	cfsetispeed(&ti, B115200);
+
+	err = tcsetattr(fd, TCSANOW, &ti);
+	if (err < 0)
+		goto err;
+
+	err = tcflush(fd, TCIOFLUSH);
+	if (err < 0)
+		goto err;
+
+	return 0;
+
+err:
+	connman_error("%s", strerror(errno));
+
+	return err;
+}
+
+static int set_custom_baud_rate(int fd, unsigned long cus_baud_rate, int flow_ctrl)
+{
+	struct termios ti;
+	struct termios2 ti2;
+	int err;
+
+	DBG("baud rate %lu flow_ctrl %d", cus_baud_rate, flow_ctrl);
+
+	err = tcflush(fd, TCIOFLUSH);
+	if (err < 0)
+		goto err;
+
+	err = tcgetattr(fd, &ti);
+	if (err < 0)
+		goto err;
+
+	if (flow_ctrl)
+		ti.c_cflag |= CRTSCTS;
+	else
+		ti.c_cflag &= ~CRTSCTS;
+
+	/*
+	 * Set the parameters associated with the UART
+	 * The change will occur immediately by using TCSANOW.
+	 */
+	err = tcsetattr(fd, TCSANOW, &ti);
+	if (err < 0)
+		goto err;
+
+	err = tcflush(fd, TCIOFLUSH);
+	if (err < 0)
+		goto err;
+
+	/* Set the actual baud rate */
+	err = ioctl(fd, TCGETS2, &ti2);
+	if (err < 0)
+		goto err;
+
+	ti2.c_cflag &= ~CBAUD;
+	ti2.c_cflag |= BOTHER;
+	ti2.c_ospeed = cus_baud_rate;
+
+	err = ioctl(fd, TCSETS2, &ti2);
+	if (err < 0)
+		goto err;
+
+	return 0;
+
+err:
+	DBG("%s", strerror(errno));
+
+	return err;
+}
+
+static gboolean uart_event(GIOChannel *channel,
+				GIOCondition cond, gpointer data)
+{
+	int uart_fd, ldisc;
+
+	DBG("");
+
+	uart_fd = g_io_channel_unix_get_fd(channel);
+
+	if (cond & (G_IO_NVAL | G_IO_HUP | G_IO_ERR)) {
+		connman_error("UART event 0x%x", cond);
+		if (uart_watch > 0)
+			g_source_remove(uart_watch);
+
+		goto err;
+	}
+
+	if (read_command_complete(uart_fd, HCI_HDR_OPCODE) < 0)
+		goto err;
+
+	if (set_custom_baud_rate(uart_fd, baud_rate, 1) < 0)
+		goto err;
+
+	ldisc = N_TI_WL;
+	if (ioctl(uart_fd, TIOCSETD, &ldisc) < 0)
+		goto err;
+
+	install_count = 1;
+	__sync_synchronize();
+
+	return FALSE;
+
+err:
+	install_count = 0;
+	__sync_synchronize();
+
+	g_io_channel_shutdown(channel, TRUE, NULL);
+	g_io_channel_unref(channel);
+
+	return FALSE;
+}
+
+static int install_ldisc(GIOChannel *channel, bool install)
+{
+	int uart_fd, err;
+	struct speed_change_cmd cmd;
+	GIOFlags flags;
+
+	DBG("%d %p", install, uart_channel);
+
+	if (!install) {
+		install_count = 0;
+		__sync_synchronize();
+
+		if (!uart_channel) {
+			DBG("UART channel is NULL");
+			return 0;
+		}
+
+		g_io_channel_shutdown(uart_channel, TRUE, NULL);
+		g_io_channel_unref(uart_channel);
+
+		uart_channel = NULL;
+
+		return 0;
+	}
+
+	if (uart_channel) {
+		g_io_channel_shutdown(uart_channel, TRUE, NULL);
+		g_io_channel_unref(uart_channel);
+		uart_channel = NULL;
+	}
+
+	DBG("opening %s custom baud %lu", uart_dev_name, baud_rate);
+
+	uart_fd = open(uart_dev_name, O_RDWR | O_CLOEXEC);
+	if (uart_fd < 0)
+		return -EIO;
+
+	uart_channel = g_io_channel_unix_new(uart_fd);
+	g_io_channel_set_close_on_unref(uart_channel, TRUE);
+
+	g_io_channel_set_encoding(uart_channel, NULL, NULL);
+	g_io_channel_set_buffered(uart_channel, FALSE);
+
+	flags = g_io_channel_get_flags(uart_channel);
+	flags |= G_IO_FLAG_NONBLOCK;
+	g_io_channel_set_flags(uart_channel, flags, NULL);
+
+        err = set_default_baud_rate(uart_fd);
+	if (err < 0) {
+		g_io_channel_shutdown(uart_channel, TRUE, NULL);
+		g_io_channel_unref(uart_channel);
+		uart_channel = NULL;
+
+		return err;
+	}
+
+	if (baud_rate == 115200) {
+		int ldisc;
+
+		ldisc = N_TI_WL;
+		if (ioctl(uart_fd, TIOCSETD, &ldisc) < 0) {
+			g_io_channel_shutdown(uart_channel, TRUE, NULL);
+			g_io_channel_unref(uart_channel);
+			uart_channel = NULL;
+		}
+
+		install_count = 0;
+		__sync_synchronize();
+
+		return 0;
+	}
+
+	cmd.uart_prefix = HCI_COMMAND_PKT;
+	cmd.opcode = HCI_HDR_OPCODE;
+	cmd.plen = sizeof(unsigned long);
+	cmd.speed = baud_rate;
+
+	uart_watch = g_io_add_watch(uart_channel,
+			G_IO_IN | G_IO_NVAL | G_IO_HUP | G_IO_ERR,
+				uart_event, NULL);
+
+	err = write(uart_fd, &cmd, sizeof(cmd));
+	if (err < 0) {
+		connman_error("Write failed %d", err);
+
+		g_io_channel_shutdown(uart_channel, TRUE, NULL);
+		g_io_channel_unref(uart_channel);
+		uart_channel = NULL;
+	}
+
+	return err;
+}
+
+
+static gboolean install_event(GIOChannel *channel,
+				GIOCondition cond, gpointer data)
+{
+	GIOStatus status = G_IO_STATUS_NORMAL;
+	unsigned int install_state;
+	bool install;
+	char buf[8];
+	gsize len;
+
+	DBG("");
+
+	if (cond & (G_IO_HUP | G_IO_NVAL)) {
+		connman_error("install event 0x%x", cond);
+		return FALSE;
+	}
+
+	__sync_synchronize();
+	if (install_count != 0) {
+		status = g_io_channel_seek_position(channel, 0, G_SEEK_SET, NULL);
+		if (status != G_IO_STATUS_NORMAL) {
+			g_io_channel_shutdown(channel, TRUE, NULL);
+			g_io_channel_unref(channel);
+			return FALSE;
+		}
+
+		/* Read the install value */
+		status = g_io_channel_read_chars(channel, (gchar *) buf,
+						8, &len, NULL);
+		if (status != G_IO_STATUS_NORMAL) {
+			g_io_channel_shutdown(channel, TRUE, NULL);
+			g_io_channel_unref(channel);
+			return FALSE;
+		}
+
+		install_state = atoi(buf);
+		DBG("install event while installing %d %c", install_state, buf[0]);
+
+		return TRUE;
+	} else {
+		install_count = 1;
+		__sync_synchronize();
+	}
+
+	status = g_io_channel_seek_position(channel, 0, G_SEEK_SET, NULL);
+	if (status != G_IO_STATUS_NORMAL) {
+		g_io_channel_shutdown(channel, TRUE, NULL);
+		g_io_channel_unref(channel);
+		return FALSE;
+	}
+
+	/* Read the install value */
+	status = g_io_channel_read_chars(channel, (gchar *) buf, 8, &len, NULL);
+	if (status != G_IO_STATUS_NORMAL) {
+		g_io_channel_shutdown(channel, TRUE, NULL);
+		g_io_channel_unref(channel);
+		return FALSE;
+	}
+
+	install_state = atoi(buf);
+
+	DBG("install state %d", install_state);
+
+	install = !!install_state;
+
+	if (install_ldisc(channel, install) < 0) {
+		connman_error("ldisc installation failed");
+		install_count = 0;
+		__sync_synchronize();
+		return TRUE;
+	}
+
+	return TRUE;
+}
+
+
+static int tist_init(void)
+{
+	GIOStatus status = G_IO_STATUS_NORMAL;
+	GIOFlags flags;
+	unsigned int install_state;
+	char buf[8];
+	int fd, err;
+	gsize len;
+
+	err = read_uart_name(uart_dev_name, sizeof(uart_dev_name));
+	if (err < 0) {
+		connman_error("Could not read the UART name");
+		return err;
+	}
+
+	err = read_baud_rate(&baud_rate);
+	if (err < 0) {
+		connman_error("Could not read the baud rate");
+		return err;
+	}
+
+	fd = open(TIST_SYSFS_INSTALL, O_RDONLY | O_CLOEXEC);
+	if (fd < 0) {
+		connman_error("Failed to open TI ST sysfs install file");
+		return -EIO;
+	}
+
+	install_channel = g_io_channel_unix_new(fd);
+	g_io_channel_set_close_on_unref(install_channel, TRUE);
+
+	g_io_channel_set_encoding(install_channel, NULL, NULL);
+	g_io_channel_set_buffered(install_channel, FALSE);
+
+	flags = g_io_channel_get_flags(install_channel);
+	flags |= G_IO_FLAG_NONBLOCK;
+	g_io_channel_set_flags(install_channel, flags, NULL);
+
+	status = g_io_channel_read_chars(install_channel, (gchar *) buf, 8,
+								&len, NULL);
+	if (status != G_IO_STATUS_NORMAL) {
+		g_io_channel_shutdown(install_channel, TRUE, NULL);
+		g_io_channel_unref(install_channel);
+		return status;
+	}
+
+	status = g_io_channel_seek_position(install_channel, 0, G_SEEK_SET, NULL);
+	if (status != G_IO_STATUS_NORMAL) {
+		connman_error("Initial seek failed");
+		g_io_channel_shutdown(install_channel, TRUE, NULL);
+		g_io_channel_unref(install_channel);
+		return -EIO;
+	}
+
+	install_state = atoi(buf);
+
+	DBG("Initial state %d", install_state);
+
+	install_watch = g_io_add_watch_full(install_channel, G_PRIORITY_HIGH,
+				G_IO_PRI | G_IO_ERR,
+					    install_event, NULL, NULL);
+
+	if (install_state) {
+		install_count = 1;
+		__sync_synchronize();
+
+		err = install_ldisc(install_channel, true);
+		if (err < 0) {
+			connman_error("ldisc installtion failed");
+			return err;
+		}
+	}
+
+	return 0;
+}
+
+
+static void tist_exit(void)
+{
+
+	if (install_watch > 0)
+		g_source_remove(install_watch);
+
+	DBG("uart_channel %p", uart_channel);
+
+	g_io_channel_shutdown(install_channel, TRUE, NULL);
+	g_io_channel_unref(install_channel);
+
+	if (uart_channel) {
+		g_io_channel_shutdown(uart_channel, TRUE, NULL);
+		g_io_channel_unref(uart_channel);
+		uart_channel = NULL;
+	}
+
+}
+
+CONNMAN_PLUGIN_DEFINE(tist, "TI shared transport support", VERSION,
+		CONNMAN_PLUGIN_PRIORITY_DEFAULT, tist_init, tist_exit)
diff --git a/connman/plugins/vpn.c b/connman/plugins/vpn.c
new file mode 100644
index 0000000..e6e4c8e
--- /dev/null
+++ b/connman/plugins/vpn.c
@@ -0,0 +1,1864 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2012-2013  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 <errno.h>
+#include <sys/socket.h>
+#include <stdlib.h>
+#include <glib.h>
+
+#include <gdbus.h>
+
+#define CONNMAN_API_SUBJECT_TO_CHANGE
+#include <connman/technology.h>
+#include <connman/plugin.h>
+#include <connman/log.h>
+#include <connman/dbus.h>
+#include <connman/provider.h>
+#include <connman/ipaddress.h>
+#include <connman/vpn-dbus.h>
+#include <connman/inet.h>
+#include <gweb/gresolv.h>
+
+#define DBUS_TIMEOUT 10000
+
+static DBusConnection *connection;
+
+static GHashTable *vpn_connections = NULL;
+static guint watch;
+static guint added_watch;
+static guint removed_watch;
+static guint property_watch;
+
+struct vpn_route {
+	int family;
+	char *network;
+	char *netmask;
+	char *gateway;
+};
+
+struct config_create_data {
+	connection_ready_cb callback;
+	DBusMessage *message;
+	char *path;
+};
+
+struct connection_data {
+	char *path;
+	char *ident;
+	struct connman_provider *provider;
+	int index;
+	DBusPendingCall *call;
+	bool connect_pending;
+	struct config_create_data *cb_data;
+
+	char *state;
+	char *type;
+	char *name;
+	char *host;
+	char **host_ip;
+	char *domain;
+	char **nameservers;
+	bool immutable;
+
+	GHashTable *server_routes;
+	GHashTable *user_routes;
+	GHashTable *setting_strings;
+
+	struct connman_ipaddress *ip;
+
+	GResolv *resolv;
+	guint resolv_id;
+};
+
+static int set_string(struct connman_provider *provider,
+					const char *key, const char *value)
+{
+	struct connection_data *data;
+
+	data = connman_provider_get_data(provider);
+	if (!data)
+		return -EINVAL;
+
+	DBG("data %p provider %p key %s value %s", data, provider, key, value);
+
+	if (g_str_equal(key, "Type")) {
+		g_free(data->type);
+		data->type = g_strdup(value);
+	} else if (g_str_equal(key, "Name")) {
+		g_free(data->name);
+		data->name = g_strdup(value);
+	} else if (g_str_equal(key, "Host")) {
+		g_free(data->host);
+		data->host = g_strdup(value);
+	} else if (g_str_equal(key, "VPN.Domain") ||
+				g_str_equal(key, "Domain")) {
+		g_free(data->domain);
+		data->domain = g_strdup(value);
+	} else
+		g_hash_table_replace(data->setting_strings,
+				g_strdup(key), g_strdup(value));
+	return 0;
+}
+
+static const char *get_string(struct connman_provider *provider,
+							const char *key)
+{
+	struct connection_data *data;
+
+	data = connman_provider_get_data(provider);
+	if (!data)
+		return NULL;
+
+	DBG("data %p provider %p key %s", data, provider, key);
+
+	if (g_str_equal(key, "Type"))
+		return data->type;
+	else if (g_str_equal(key, "Name"))
+		return data->name;
+	else if (g_str_equal(key, "Host"))
+		return data->host;
+	else if (g_str_equal(key, "HostIP")) {
+		if (!data->host_ip ||
+				!data->host_ip[0])
+			return data->host;
+		else
+			return data->host_ip[0];
+	} else if (g_str_equal(key, "VPN.Domain"))
+		return data->domain;
+
+	return g_hash_table_lookup(data->setting_strings, key);
+}
+
+static char *get_ident(const char *path)
+{
+	char *pos;
+
+	if (*path != '/')
+		return NULL;
+
+	pos = strrchr(path, '/');
+	if (!pos)
+		return NULL;
+
+	return pos + 1;
+}
+
+static void cancel_host_resolv(struct connection_data *data)
+{
+	if (data->resolv_id != 0)
+		g_resolv_cancel_lookup(data->resolv, data->resolv_id);
+
+	data->resolv_id = 0;
+
+	g_resolv_unref(data->resolv);
+	data->resolv = NULL;
+}
+
+static gboolean remove_resolv(gpointer user_data)
+{
+	struct connection_data *data = user_data;
+
+	cancel_host_resolv(data);
+
+	return FALSE;
+}
+
+static void resolv_result(GResolvResultStatus status,
+					char **results, gpointer user_data)
+{
+	struct connection_data *data = user_data;
+
+	DBG("status %d", status);
+
+	if (status == G_RESOLV_RESULT_STATUS_SUCCESS && results &&
+						g_strv_length(results) > 0) {
+		g_strfreev(data->host_ip);
+		data->host_ip = g_strdupv(results);
+	}
+
+	/*
+	 * We cannot unref the resolver here as resolv struct is manipulated
+	 * by gresolv.c after we return from this callback.
+	 */
+	g_timeout_add_seconds(0, remove_resolv, data);
+
+	data->resolv_id = 0;
+}
+
+static void resolv_host_addr(struct connection_data *data)
+{
+	if (!data->host)
+		return;
+
+	if (connman_inet_check_ipaddress(data->host) > 0)
+		return;
+
+	if (data->host_ip)
+		return;
+
+	data->resolv = g_resolv_new(0);
+	if (!data->resolv) {
+		DBG("Cannot resolv %s", data->host);
+		return;
+	}
+
+	DBG("Trying to resolv %s", data->host);
+
+	data->resolv_id = g_resolv_lookup_hostname(data->resolv, data->host,
+						resolv_result, data);
+}
+
+static void free_config_cb_data(struct config_create_data *cb_data)
+{
+	if (!cb_data)
+		return;
+
+	g_free(cb_data->path);
+	cb_data->path = NULL;
+
+	if (cb_data->message) {
+		dbus_message_unref(cb_data->message);
+		cb_data->message = NULL;
+	}
+
+	cb_data->callback = NULL;
+
+	g_free(cb_data);
+}
+
+static void set_provider_state(struct connection_data *data)
+{
+	enum connman_provider_state state = CONNMAN_PROVIDER_STATE_UNKNOWN;
+	int err = 0;
+
+	DBG("provider %p new state %s", data->provider, data->state);
+
+	if (g_str_equal(data->state, "ready")) {
+		state = CONNMAN_PROVIDER_STATE_READY;
+		goto set;
+	} else if (g_str_equal(data->state, "configuration")) {
+		state = CONNMAN_PROVIDER_STATE_CONNECT;
+	} else if (g_str_equal(data->state, "idle")) {
+		state = CONNMAN_PROVIDER_STATE_IDLE;
+	} else if (g_str_equal(data->state, "disconnect")) {
+		err = ECONNREFUSED;
+		state = CONNMAN_PROVIDER_STATE_DISCONNECT;
+		goto set;
+	} else if (g_str_equal(data->state, "failure")) {
+		err = ECONNREFUSED;
+		state = CONNMAN_PROVIDER_STATE_FAILURE;
+		goto set;
+	}
+
+	connman_provider_set_state(data->provider, state);
+	return;
+
+set:
+	if (data->cb_data)
+		data->cb_data->callback(data->cb_data->message,
+					err, data->ident);
+
+	connman_provider_set_state(data->provider, state);
+
+	free_config_cb_data(data->cb_data);
+	data->cb_data = NULL;
+}
+
+static int create_provider(struct connection_data *data, void *user_data)
+{
+	struct connman_provider_driver *driver = user_data;
+	int err;
+
+	DBG("%s", data->path);
+
+	data->provider = connman_provider_get(data->ident);
+	if (!data->provider)
+		return -ENOMEM;
+
+	DBG("provider %p name %s", data->provider, data->name);
+
+	connman_provider_set_data(data->provider, data);
+	connman_provider_set_driver(data->provider, driver);
+
+	err = connman_provider_create_service(data->provider);
+	if (err == 0) {
+		connman_provider_set_immutable(data->provider, data->immutable);
+		if (g_str_equal(data->state, "ready")) {
+			connman_provider_set_index(data->provider,
+							data->index);
+			if (data->ip)
+				connman_provider_set_ipaddress(data->provider,
+								data->ip);
+		}
+
+		set_provider_state(data);
+	}
+
+	return 0;
+}
+
+static void destroy_route(gpointer user_data)
+{
+	struct vpn_route *route = user_data;
+
+	g_free(route->network);
+	g_free(route->netmask);
+	g_free(route->gateway);
+	g_free(route);
+}
+
+static struct connection_data *create_connection_data(const char *path)
+{
+	struct connection_data *data;
+
+	data = g_try_new0(struct connection_data, 1);
+	if (!data)
+		return NULL;
+
+	DBG("path %s", path);
+
+	data->path = g_strdup(path);
+	data->ident = g_strdup(get_ident(path));
+	data->index = -1;
+
+	data->setting_strings = g_hash_table_new_full(g_str_hash,
+						g_str_equal, g_free, g_free);
+
+	data->server_routes = g_hash_table_new_full(g_direct_hash,
+					g_str_equal, g_free, destroy_route);
+	data->user_routes = g_hash_table_new_full(g_str_hash,
+					g_str_equal, g_free, destroy_route);
+
+	return data;
+}
+
+static int extract_ip(DBusMessageIter *array, int family,
+						struct connection_data *data)
+{
+	DBusMessageIter dict;
+	char *address = NULL, *gateway = NULL, *netmask = NULL, *peer = NULL;
+	unsigned char prefix_len;
+
+	if (dbus_message_iter_get_arg_type(array) != DBUS_TYPE_ARRAY)
+		return -EINVAL;
+
+	dbus_message_iter_recurse(array, &dict);
+
+	while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
+		DBusMessageIter entry, value;
+		const char *key;
+
+		dbus_message_iter_recurse(&dict, &entry);
+		dbus_message_iter_get_basic(&entry, &key);
+
+		dbus_message_iter_next(&entry);
+		dbus_message_iter_recurse(&entry, &value);
+
+		if (g_str_equal(key, "Address")) {
+			dbus_message_iter_get_basic(&value, &address);
+			DBG("address %s", address);
+		} else if (g_str_equal(key, "Netmask")) {
+			dbus_message_iter_get_basic(&value, &netmask);
+			DBG("netmask %s", netmask);
+		} else if (g_str_equal(key, "PrefixLength")) {
+			dbus_message_iter_get_basic(&value, &netmask);
+			DBG("prefix length %s", netmask);
+		} else if (g_str_equal(key, "Peer")) {
+			dbus_message_iter_get_basic(&value, &peer);
+			DBG("peer %s", peer);
+		} else if (g_str_equal(key, "Gateway")) {
+			dbus_message_iter_get_basic(&value, &gateway);
+			DBG("gateway %s", gateway);
+		}
+
+		dbus_message_iter_next(&dict);
+	}
+
+	connman_ipaddress_free(data->ip);
+	data->ip = connman_ipaddress_alloc(family);
+	if (!data->ip)
+		return -ENOMEM;
+
+	switch (family) {
+	case AF_INET:
+		connman_ipaddress_set_ipv4(data->ip, address, netmask,
+								gateway);
+		break;
+	case AF_INET6:
+		prefix_len = atoi(netmask);
+		connman_ipaddress_set_ipv6(data->ip, address, prefix_len,
+								gateway);
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	connman_ipaddress_set_peer(data->ip, peer);
+
+	return 0;
+}
+
+static int extract_nameservers(DBusMessageIter *array,
+						struct connection_data *data)
+{
+	DBusMessageIter entry;
+	char **nameservers = NULL;
+	int i = 0;
+
+	dbus_message_iter_recurse(array, &entry);
+
+	while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
+		const char *nameserver;
+
+		dbus_message_iter_get_basic(&entry, &nameserver);
+
+		nameservers = g_try_renew(char *, nameservers, i + 2);
+		if (!nameservers)
+			return -ENOMEM;
+
+		DBG("[%d] %s", i, nameserver);
+
+		nameservers[i] = g_strdup(nameserver);
+		if (!nameservers[i])
+			return -ENOMEM;
+
+		nameservers[++i] = NULL;
+
+		dbus_message_iter_next(&entry);
+	}
+
+	g_strfreev(data->nameservers);
+	data->nameservers = nameservers;
+
+	return 0;
+}
+
+static int errorstr2val(const char *error) {
+	if (g_strcmp0(error, CONNMAN_ERROR_INTERFACE ".InProgress") == 0)
+		return -EINPROGRESS;
+
+	if (g_strcmp0(error, CONNMAN_ERROR_INTERFACE ".AlreadyConnected") == 0)
+		return -EISCONN;
+
+	return -ECONNREFUSED;
+}
+
+static void connect_reply(DBusPendingCall *call, void *user_data)
+{
+	DBusMessage *reply;
+	DBusError error;
+	struct connection_data *data = user_data;
+	struct config_create_data *cb_data = data->cb_data;
+
+	if (!dbus_pending_call_get_completed(call))
+		return;
+
+	DBG("user_data %p path %s", user_data, cb_data ? cb_data->path : NULL);
+
+	reply = dbus_pending_call_steal_reply(call);
+
+	dbus_error_init(&error);
+
+	if (dbus_set_error_from_message(&error, reply)) {
+		int err = errorstr2val(error.name);
+		if (err != -EINPROGRESS) {
+			connman_error("Connect reply: %s (%s)", error.message,
+								error.name);
+			dbus_error_free(&error);
+
+			DBG("data %p cb_data %p", data, cb_data);
+			if (cb_data) {
+				cb_data->callback(cb_data->message, err, NULL);
+				free_config_cb_data(cb_data);
+				data->cb_data = NULL;
+			}
+			goto done;
+		}
+		dbus_error_free(&error);
+	}
+
+	/*
+	 * The vpn connection is up when we get a "ready" state
+	 * property so at this point we do nothing for the provider
+	 * state.
+	 */
+
+done:
+	dbus_message_unref(reply);
+
+	dbus_pending_call_unref(call);
+}
+
+static int connect_provider(struct connection_data *data, void *user_data)
+{
+	DBusPendingCall *call;
+	DBusMessage *message;
+	struct config_create_data *cb_data = user_data;
+
+	DBG("data %p user %p path %s", data, cb_data, data->path);
+
+	data->connect_pending = false;
+
+	message = dbus_message_new_method_call(VPN_SERVICE, data->path,
+					VPN_CONNECTION_INTERFACE,
+					VPN_CONNECT);
+	if (!message)
+		return -ENOMEM;
+
+	if (!dbus_connection_send_with_reply(connection, message,
+						&call, DBUS_TIMEOUT)) {
+		connman_error("Unable to call %s.%s()",
+			VPN_CONNECTION_INTERFACE, VPN_CONNECT);
+		dbus_message_unref(message);
+		return -EINVAL;
+	}
+
+	if (!call) {
+		dbus_message_unref(message);
+		return -EINVAL;
+	}
+
+	if (cb_data) {
+		g_free(cb_data->path);
+		cb_data->path = g_strdup(data->path);
+	}
+
+	dbus_pending_call_set_notify(call, connect_reply, data, NULL);
+
+	dbus_message_unref(message);
+
+	return -EINPROGRESS;
+}
+
+static void add_connection(const char *path, DBusMessageIter *properties,
+			void *user_data)
+{
+	struct connection_data *data;
+	int err;
+	char *ident = get_ident(path);
+	bool found = false;
+
+	data = g_hash_table_lookup(vpn_connections, ident);
+	if (data) {
+		/*
+		 * We might have a dummy connection struct here that
+		 * was created by configuration_create_reply() so in
+		 * that case just continue.
+		 */
+		if (!data->connect_pending)
+			return;
+
+		found = true;
+	} else {
+		data = create_connection_data(path);
+		if (!data)
+			return;
+	}
+
+	DBG("data %p path %s", data, path);
+
+	while (dbus_message_iter_get_arg_type(properties) ==
+			DBUS_TYPE_DICT_ENTRY) {
+		DBusMessageIter entry, value;
+		const char *key;
+		char *str;
+
+		dbus_message_iter_recurse(properties, &entry);
+		dbus_message_iter_get_basic(&entry, &key);
+
+		dbus_message_iter_next(&entry);
+		dbus_message_iter_recurse(&entry, &value);
+
+		if (g_str_equal(key, "State")) {
+			dbus_message_iter_get_basic(&value, &str);
+			DBG("state %s -> %s", data->state, str);
+			data->state = g_strdup(str);
+		} else if (g_str_equal(key, "IPv4")) {
+			extract_ip(&value, AF_INET, data);
+		} else if (g_str_equal(key, "IPv6")) {
+			extract_ip(&value, AF_INET6, data);
+		} else if (g_str_equal(key, "Name")) {
+			dbus_message_iter_get_basic(&value, &str);
+			data->name = g_strdup(str);
+		} else if (g_str_equal(key, "Type")) {
+			dbus_message_iter_get_basic(&value, &str);
+			data->type = g_strdup(str);
+		} else if (g_str_equal(key, "Immutable")) {
+			dbus_bool_t immutable;
+
+			dbus_message_iter_get_basic(&value, &immutable);
+			data->immutable = immutable;
+		} else if (g_str_equal(key, "Host")) {
+			dbus_message_iter_get_basic(&value, &str);
+			data->host = g_strdup(str);
+		} else if (g_str_equal(key, "Domain")) {
+			dbus_message_iter_get_basic(&value, &str);
+			g_free(data->domain);
+			data->domain = g_strdup(str);
+		} else if (g_str_equal(key, "Nameservers")) {
+			extract_nameservers(&value, data);
+		} else if (g_str_equal(key, "Index")) {
+			dbus_message_iter_get_basic(&value, &data->index);
+		} else if (g_str_equal(key, "ServerRoutes")) {
+			/* Ignored */
+		} else if (g_str_equal(key, "UserRoutes")) {
+			/* Ignored */
+		} else {
+			if (dbus_message_iter_get_arg_type(&value) ==
+							DBUS_TYPE_STRING) {
+				dbus_message_iter_get_basic(&value, &str);
+				g_hash_table_replace(data->setting_strings,
+						g_strdup(key), g_strdup(str));
+			} else {
+				DBG("unknown key %s", key);
+			}
+		}
+
+		dbus_message_iter_next(properties);
+	}
+
+	if (!found)
+		g_hash_table_insert(vpn_connections, g_strdup(data->ident),
+									data);
+
+	err = create_provider(data, user_data);
+	if (err < 0)
+		goto out;
+
+	resolv_host_addr(data);
+
+	if (data->nameservers)
+		connman_provider_set_nameservers(data->provider,
+						data->nameservers);
+
+	if (data->domain)
+		connman_provider_set_domain(data->provider,
+						data->domain);
+
+	if (data->connect_pending)
+		connect_provider(data, data->cb_data);
+
+	return;
+
+out:
+	DBG("removing %s", data->ident);
+	g_hash_table_remove(vpn_connections, data->ident);
+}
+
+static void get_connections_reply(DBusPendingCall *call, void *user_data)
+{
+	DBusMessage *reply;
+	DBusError error;
+	DBusMessageIter array, dict;
+	const char *signature = DBUS_TYPE_ARRAY_AS_STRING
+		DBUS_STRUCT_BEGIN_CHAR_AS_STRING
+		DBUS_TYPE_OBJECT_PATH_AS_STRING
+		DBUS_TYPE_ARRAY_AS_STRING
+		DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+		DBUS_TYPE_STRING_AS_STRING
+		DBUS_TYPE_VARIANT_AS_STRING
+		DBUS_DICT_ENTRY_END_CHAR_AS_STRING
+		DBUS_STRUCT_END_CHAR_AS_STRING;
+
+	if (!dbus_pending_call_get_completed(call))
+		return;
+
+	DBG("");
+
+	reply = dbus_pending_call_steal_reply(call);
+
+	dbus_error_init(&error);
+
+	if (dbus_set_error_from_message(&error, reply)) {
+		connman_error("%s", error.message);
+		dbus_error_free(&error);
+		goto done;
+	}
+
+	if (!dbus_message_has_signature(reply, signature)) {
+		connman_error("vpnd signature \"%s\" does not match "
+							"expected \"%s\"",
+			dbus_message_get_signature(reply), signature);
+		goto done;
+	}
+
+	if (!dbus_message_iter_init(reply, &array))
+		goto done;
+
+	dbus_message_iter_recurse(&array, &dict);
+
+	while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_STRUCT) {
+		DBusMessageIter value, properties;
+		const char *path;
+
+		dbus_message_iter_recurse(&dict, &value);
+		dbus_message_iter_get_basic(&value, &path);
+
+		dbus_message_iter_next(&value);
+		dbus_message_iter_recurse(&value, &properties);
+
+		add_connection(path, &properties, user_data);
+
+		dbus_message_iter_next(&dict);
+	}
+
+done:
+	dbus_message_unref(reply);
+
+	dbus_pending_call_unref(call);
+}
+
+static int get_connections(void *user_data)
+{
+	DBusPendingCall *call;
+	DBusMessage *message;
+
+	DBG("");
+
+	message = dbus_message_new_method_call(VPN_SERVICE, "/",
+					VPN_MANAGER_INTERFACE,
+					GET_CONNECTIONS);
+	if (!message)
+		return -ENOMEM;
+
+	if (!dbus_connection_send_with_reply(connection, message,
+						&call, DBUS_TIMEOUT)) {
+		connman_error("Unable to call %s.%s()", VPN_MANAGER_INTERFACE,
+							GET_CONNECTIONS);
+		dbus_message_unref(message);
+		return -EINVAL;
+	}
+
+	if (!call) {
+		dbus_message_unref(message);
+		return -EINVAL;
+	}
+
+	dbus_pending_call_set_notify(call, get_connections_reply,
+							user_data, NULL);
+
+	dbus_message_unref(message);
+
+	return -EINPROGRESS;
+}
+
+static int provider_probe(struct connman_provider *provider)
+{
+	return 0;
+}
+
+static void remove_connection_reply(DBusPendingCall *call, void *user_data)
+{
+	DBusMessage *reply;
+	DBusError error;
+
+	if (!dbus_pending_call_get_completed(call))
+		return;
+
+	DBG("");
+
+	reply = dbus_pending_call_steal_reply(call);
+
+	dbus_error_init(&error);
+
+	if (dbus_set_error_from_message(&error, reply)) {
+		/*
+		 * If the returned error is NotFound, it means that we
+		 * have actually removed the provider in vpnd already.
+		 */
+		if (!dbus_error_has_name(&error,
+				CONNMAN_ERROR_INTERFACE".NotFound"))
+			connman_error("%s", error.message);
+
+		dbus_error_free(&error);
+	}
+
+	dbus_message_unref(reply);
+
+	dbus_pending_call_unref(call);
+}
+
+static int provider_remove(struct connman_provider *provider)
+{
+	DBusPendingCall *call;
+	DBusMessage *message;
+	struct connection_data *data;
+
+	data = connman_provider_get_data(provider);
+
+	DBG("provider %p data %p", provider, data);
+
+	if (!data) {
+		/*
+		 * This means the provider is already removed,
+		 * just ignore the dbus in this case.
+		 */
+		return -EALREADY;
+	}
+
+	/*
+	 * When provider.c:provider_remove() calls this function,
+	 * it will remove the provider itself after the call.
+	 * This means that we cannot use the provider pointer later
+	 * as it is no longer valid.
+	 */
+	data->provider = NULL;
+
+	message = dbus_message_new_method_call(VPN_SERVICE, "/",
+					VPN_MANAGER_INTERFACE,
+					VPN_REMOVE);
+	if (!message)
+		return -ENOMEM;
+
+	dbus_message_append_args(message, DBUS_TYPE_OBJECT_PATH, &data->path,
+				NULL);
+
+	if (!dbus_connection_send_with_reply(connection, message,
+						&call, DBUS_TIMEOUT)) {
+		connman_error("Unable to call %s.%s()", VPN_MANAGER_INTERFACE,
+							VPN_REMOVE);
+		dbus_message_unref(message);
+		return -EINVAL;
+	}
+
+	if (!call) {
+		dbus_message_unref(message);
+		return -EINVAL;
+	}
+
+	dbus_pending_call_set_notify(call, remove_connection_reply,
+							NULL, NULL);
+
+	dbus_message_unref(message);
+
+	return 0;
+}
+
+static int provider_connect(struct connman_provider *provider)
+{
+	struct connection_data *data;
+
+	data = connman_provider_get_data(provider);
+	if (!data)
+		return -EINVAL;
+
+	return connect_provider(data, NULL);
+}
+
+static void disconnect_reply(DBusPendingCall *call, void *user_data)
+{
+	DBusMessage *reply;
+	DBusError error;
+
+	if (!dbus_pending_call_get_completed(call))
+		return;
+
+	DBG("user %p", user_data);
+
+	reply = dbus_pending_call_steal_reply(call);
+
+	dbus_error_init(&error);
+
+	if (dbus_set_error_from_message(&error, reply)) {
+		connman_error("%s", error.message);
+		dbus_error_free(&error);
+		goto done;
+	}
+
+done:
+	dbus_message_unref(reply);
+
+	dbus_pending_call_unref(call);
+}
+
+static int disconnect_provider(struct connection_data *data)
+{
+	DBusPendingCall *call;
+	DBusMessage *message;
+
+	DBG("data %p path %s", data, data->path);
+
+	message = dbus_message_new_method_call(VPN_SERVICE, data->path,
+					VPN_CONNECTION_INTERFACE,
+					VPN_DISCONNECT);
+	if (!message)
+		return -ENOMEM;
+
+	if (!dbus_connection_send_with_reply(connection, message,
+						&call, DBUS_TIMEOUT)) {
+		connman_error("Unable to call %s.%s()",
+			VPN_CONNECTION_INTERFACE, VPN_DISCONNECT);
+		dbus_message_unref(message);
+		return -EINVAL;
+	}
+
+	if (!call) {
+		dbus_message_unref(message);
+		return -EINVAL;
+	}
+
+	dbus_pending_call_set_notify(call, disconnect_reply, NULL, NULL);
+
+	dbus_message_unref(message);
+
+	connman_provider_set_state(data->provider,
+					CONNMAN_PROVIDER_STATE_DISCONNECT);
+	/*
+	 * We return 0 here instead of -EINPROGRESS because
+	 * __connman_service_disconnect() needs to return something
+	 * to gdbus so that gdbus will not call Disconnect() more
+	 * than once. This way we do not need to pass the dbus reply
+	 * message around the code.
+	 */
+	return 0;
+}
+
+static int provider_disconnect(struct connman_provider *provider)
+{
+	struct connection_data *data;
+
+	DBG("provider %p", provider);
+
+	data = connman_provider_get_data(provider);
+	if (!data)
+		return -EINVAL;
+
+	if (g_str_equal(data->state, "ready") ||
+			g_str_equal(data->state, "configuration"))
+		return disconnect_provider(data);
+
+	return 0;
+}
+
+static void configuration_create_reply(DBusPendingCall *call, void *user_data)
+{
+	DBusMessage *reply;
+	DBusError error;
+	DBusMessageIter iter;
+	const char *signature = DBUS_TYPE_OBJECT_PATH_AS_STRING;
+	const char *path;
+	char *ident;
+	struct connection_data *data;
+	struct config_create_data *cb_data = user_data;
+
+	if (!dbus_pending_call_get_completed(call))
+		return;
+
+	DBG("user %p", cb_data);
+
+	reply = dbus_pending_call_steal_reply(call);
+
+	dbus_error_init(&error);
+
+	if (dbus_set_error_from_message(&error, reply)) {
+		connman_error("dbus error: %s", error.message);
+		dbus_error_free(&error);
+		goto done;
+	}
+
+	if (!dbus_message_has_signature(reply, signature)) {
+		connman_error("vpn configuration signature \"%s\" does not "
+						"match expected \"%s\"",
+			dbus_message_get_signature(reply), signature);
+		goto done;
+	}
+
+	if (!dbus_message_iter_init(reply, &iter))
+		goto done;
+
+	dbus_message_iter_get_basic(&iter, &path);
+
+	/*
+	 * Then try to connect the VPN as expected by ConnectProvider API
+	 */
+	ident = get_ident(path);
+
+	data = g_hash_table_lookup(vpn_connections, ident);
+	if (!data) {
+		/*
+		 * Someone removed the data. We cannot really continue.
+		 */
+		DBG("Pending data not found for %s, cannot continue!", ident);
+	} else {
+		data->call = NULL;
+		data->connect_pending = true;
+
+		if (!data->cb_data)
+			data->cb_data = cb_data;
+		else
+			DBG("Connection callback data already in use!");
+
+		/*
+		 * Connection is created in add_connections() after
+		 * we have received the ConnectionAdded signal.
+		 */
+
+		DBG("cb %p msg %p", data->cb_data,
+			data->cb_data ? data->cb_data->message : NULL);
+	}
+
+done:
+	dbus_message_unref(reply);
+
+	dbus_pending_call_unref(call);
+}
+
+static void set_dbus_ident(char *ident)
+{
+	int i, len = strlen(ident);
+
+	for (i = 0; i < len; i++) {
+		if (ident[i] >= '0' && ident[i] <= '9')
+			continue;
+		if (ident[i] >= 'a' && ident[i] <= 'z')
+			continue;
+		if (ident[i] >= 'A' && ident[i] <= 'Z')
+			continue;
+		ident[i] = '_';
+	}
+}
+
+static struct vpn_route *parse_user_route(const char *user_route)
+{
+	char *network, *netmask;
+	struct vpn_route *route = NULL;
+	int family = PF_UNSPEC;
+	char **elems = g_strsplit(user_route, "/", 0);
+
+	if (!elems)
+		return NULL;
+
+	network = elems[0];
+	if (!network || *network == '\0') {
+		DBG("no network/netmask set");
+		goto out;
+	}
+
+	netmask = elems[1];
+	if (netmask && *netmask == '\0') {
+		DBG("no netmask set");
+		goto out;
+	}
+
+	if (g_strrstr(network, ":"))
+		family = AF_INET6;
+	else if (g_strrstr(network, ".")) {
+		family = AF_INET;
+
+		if (!g_strrstr(netmask, ".")) {
+			/* We have netmask length */
+			in_addr_t addr;
+			struct in_addr netmask_in;
+			unsigned char prefix_len = 32;
+
+			if (netmask) {
+				char *ptr;
+				long int value = strtol(netmask, &ptr, 10);
+				if (ptr != netmask && *ptr == '\0' &&
+						value && value <= 32)
+					prefix_len = value;
+			}
+
+			addr = 0xffffffff << (32 - prefix_len);
+			netmask_in.s_addr = htonl(addr);
+			netmask = inet_ntoa(netmask_in);
+
+			DBG("network %s netmask %s", network, netmask);
+		}
+	}
+
+	route = g_try_new(struct vpn_route, 1);
+	if (!route)
+		goto out;
+
+	route->network = g_strdup(network);
+	route->netmask = g_strdup(netmask);
+	route->gateway = NULL;
+	route->family = family;
+
+out:
+	g_strfreev(elems);
+	return route;
+}
+
+static GSList *get_user_networks(DBusMessageIter *array)
+{
+	DBusMessageIter entry;
+	GSList *list = NULL;
+
+	dbus_message_iter_recurse(array, &entry);
+
+	while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
+		const char *val;
+		struct vpn_route *route;
+
+		dbus_message_iter_get_basic(&entry, &val);
+
+		route = parse_user_route(val);
+		if (route)
+			list = g_slist_prepend(list, route);
+
+		dbus_message_iter_next(&entry);
+	}
+
+	return list;
+}
+
+static void append_route(DBusMessageIter *iter, void *user_data)
+{
+	struct vpn_route *route = user_data;
+	DBusMessageIter item;
+	int family = 0;
+
+	connman_dbus_dict_open(iter, &item);
+
+	if (!route)
+		goto empty_dict;
+
+	if (route->family == AF_INET)
+		family = 4;
+	else if (route->family == AF_INET6)
+		family = 6;
+
+	if (family != 0)
+		connman_dbus_dict_append_basic(&item, "ProtocolFamily",
+					DBUS_TYPE_INT32, &family);
+
+	if (route->network)
+		connman_dbus_dict_append_basic(&item, "Network",
+					DBUS_TYPE_STRING, &route->network);
+
+	if (route->netmask)
+		connman_dbus_dict_append_basic(&item, "Netmask",
+					DBUS_TYPE_STRING, &route->netmask);
+
+	if (route->gateway)
+		connman_dbus_dict_append_basic(&item, "Gateway",
+					DBUS_TYPE_STRING, &route->gateway);
+
+empty_dict:
+	connman_dbus_dict_close(iter, &item);
+}
+
+static void append_routes(DBusMessageIter *iter, void *user_data)
+{
+	GSList *list, *routes = user_data;
+
+	DBG("routes %p", routes);
+
+	for (list = routes; list; list = g_slist_next(list)) {
+		DBusMessageIter dict;
+		struct vpn_route *route = list->data;
+
+		dbus_message_iter_open_container(iter, DBUS_TYPE_STRUCT, NULL,
+						&dict);
+		append_route(&dict, route);
+		dbus_message_iter_close_container(iter, &dict);
+	}
+}
+
+static int create_configuration(DBusMessage *msg, connection_ready_cb callback)
+{
+	DBusMessage *new_msg = NULL;
+	DBusPendingCall *call;
+	DBusMessageIter iter, array, new_iter, new_dict;
+	const char *type = NULL, *name = NULL;
+	const char *host = NULL, *domain = NULL;
+	char *ident, *me = NULL;
+	int err = 0;
+	dbus_bool_t result;
+	struct connection_data *data;
+	struct config_create_data *user_data = NULL;
+	GSList *networks = NULL;
+
+	/*
+	 * We copy the old message data into new message. We cannot
+	 * just use the old message as is because the user route
+	 * information is not in the same format in vpnd.
+	 */
+	new_msg = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_CALL);
+	dbus_message_iter_init_append(new_msg, &new_iter);
+	connman_dbus_dict_open(&new_iter, &new_dict);
+
+	dbus_message_iter_init(msg, &iter);
+	dbus_message_iter_recurse(&iter, &array);
+
+	while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_DICT_ENTRY) {
+		DBusMessageIter entry, value;
+		void *item_value;
+		const char *key;
+		int value_type;
+
+		dbus_message_iter_recurse(&array, &entry);
+		dbus_message_iter_get_basic(&entry, &key);
+
+		dbus_message_iter_next(&entry);
+		dbus_message_iter_recurse(&entry, &value);
+
+		value_type = dbus_message_iter_get_arg_type(&value);
+		item_value = NULL;
+
+		switch (value_type) {
+		case DBUS_TYPE_STRING:
+			dbus_message_iter_get_basic(&value, &item_value);
+
+			if (g_str_equal(key, "Type"))
+				type = (const char *)item_value;
+			else if (g_str_equal(key, "Name"))
+				name = (const char *)item_value;
+			else if (g_str_equal(key, "Host"))
+				host = (const char *)item_value;
+			else if (g_str_equal(key, "VPN.Domain"))
+				domain = (const char *)item_value;
+
+			DBG("%s %s", key, (char *)item_value);
+
+			if (item_value)
+				connman_dbus_dict_append_basic(&new_dict, key,
+						value_type, &item_value);
+			break;
+		case DBUS_TYPE_ARRAY:
+			if (g_str_equal(key, "Networks")) {
+				networks = get_user_networks(&value);
+				connman_dbus_dict_append_array(&new_dict,
+							"UserRoutes",
+							DBUS_TYPE_DICT_ENTRY,
+							append_routes,
+							networks);
+			}
+			break;
+		}
+
+		dbus_message_iter_next(&array);
+	}
+
+	connman_dbus_dict_close(&new_iter, &new_dict);
+
+	DBG("VPN type %s name %s host %s domain %s networks %p",
+		type, name, host, domain, networks);
+
+	if (!host || !domain) {
+		err = -EINVAL;
+		goto done;
+	}
+
+	if (!type || !name) {
+		err = -EOPNOTSUPP;
+		goto done;
+	}
+
+	ident = g_strdup_printf("%s_%s", host, domain);
+	set_dbus_ident(ident);
+
+	DBG("ident %s", ident);
+
+	data = g_hash_table_lookup(vpn_connections, ident);
+	if (data) {
+		if (data->call || data->cb_data) {
+			DBG("create configuration call already pending");
+			err = -EINPROGRESS;
+			goto done;
+		}
+	} else {
+		char *path = g_strdup_printf("%s/connection/%s", VPN_PATH,
+								ident);
+		data = create_connection_data(path);
+		g_free(path);
+
+		if (!data) {
+			err = -ENOMEM;
+			goto done;
+		}
+
+		g_hash_table_insert(vpn_connections, g_strdup(ident), data);
+	}
+
+	/*
+	 * User called net.connman.Manager.ConnectProvider if we are here.
+	 * So use the data from original message in the new msg.
+	 */
+	me = g_strdup(dbus_message_get_destination(msg));
+
+	dbus_message_set_interface(new_msg, VPN_MANAGER_INTERFACE);
+	dbus_message_set_path(new_msg, "/");
+	dbus_message_set_destination(new_msg, VPN_SERVICE);
+	dbus_message_set_sender(new_msg, me);
+	dbus_message_set_member(new_msg, "Create");
+
+	user_data = g_try_new0(struct config_create_data, 1);
+	if (!user_data) {
+		err = -ENOMEM;
+		goto done;
+	}
+
+	user_data->callback = callback;
+	user_data->message = dbus_message_ref(msg);
+	user_data->path = NULL;
+
+	DBG("cb %p msg %p", user_data, msg);
+
+	result = dbus_connection_send_with_reply(connection, new_msg,
+						&call, DBUS_TIMEOUT);
+	if (!result || !call) {
+		err = -EIO;
+		goto done;
+	}
+
+	dbus_pending_call_set_notify(call, configuration_create_reply,
+							user_data, NULL);
+	data->call = call;
+
+done:
+	if (new_msg)
+		dbus_message_unref(new_msg);
+
+	if (networks)
+		g_slist_free_full(networks, destroy_route);
+
+	g_free(me);
+	return err;
+}
+
+static bool check_host(char **hosts, char *host)
+{
+	int i;
+
+	if (!hosts)
+		return false;
+
+	for (i = 0; hosts[i]; i++) {
+		if (g_strcmp0(hosts[i], host) == 0)
+			return true;
+	}
+
+	return false;
+}
+
+static void set_route(struct connection_data *data, struct vpn_route *route)
+{
+	/*
+	 * If the VPN administrator/user has given a route to
+	 * VPN server, then we must discard that because the
+	 * server cannot be contacted via VPN tunnel.
+	 */
+	if (check_host(data->host_ip, route->network)) {
+		DBG("Discarding VPN route to %s via %s at index %d",
+			route->network, route->gateway, data->index);
+		return;
+	}
+
+	if (route->family == AF_INET6) {
+		unsigned char prefix_len = atoi(route->netmask);
+
+		connman_inet_add_ipv6_network_route(data->index,
+							route->network,
+							route->gateway,
+							prefix_len);
+	} else {
+		connman_inet_add_network_route(data->index, route->network,
+						route->gateway,
+						route->netmask);
+	}
+}
+
+static int set_routes(struct connman_provider *provider,
+				enum connman_provider_route_type type)
+{
+	struct connection_data *data;
+	GHashTableIter iter;
+	gpointer value, key;
+
+	DBG("provider %p", provider);
+
+	data = connman_provider_get_data(provider);
+	if (!data)
+		return -EINVAL;
+
+	if (type == CONNMAN_PROVIDER_ROUTE_ALL ||
+					type == CONNMAN_PROVIDER_ROUTE_USER) {
+		g_hash_table_iter_init(&iter, data->user_routes);
+
+		while (g_hash_table_iter_next(&iter, &key, &value))
+			set_route(data, value);
+	}
+
+	if (type == CONNMAN_PROVIDER_ROUTE_ALL ||
+				type == CONNMAN_PROVIDER_ROUTE_SERVER) {
+		g_hash_table_iter_init(&iter, data->server_routes);
+
+		while (g_hash_table_iter_next(&iter, &key, &value))
+			set_route(data, value);
+	}
+
+	return 0;
+}
+
+static bool check_routes(struct connman_provider *provider)
+{
+	struct connection_data *data;
+
+	DBG("provider %p", provider);
+
+	data = connman_provider_get_data(provider);
+	if (!data)
+		return false;
+
+	if (data->user_routes &&
+			g_hash_table_size(data->user_routes) > 0)
+		return true;
+
+	if (data->server_routes &&
+			g_hash_table_size(data->server_routes) > 0)
+		return true;
+
+	return false;
+}
+
+static struct connman_provider_driver provider_driver = {
+	.name = "VPN",
+	.type = CONNMAN_PROVIDER_TYPE_VPN,
+	.probe = provider_probe,
+	.remove = provider_remove,
+	.connect = provider_connect,
+	.disconnect = provider_disconnect,
+	.set_property = set_string,
+	.get_property = get_string,
+	.create = create_configuration,
+	.set_routes = set_routes,
+	.check_routes = check_routes,
+};
+
+static void destroy_provider(struct connection_data *data)
+{
+	DBG("data %p", data);
+
+	if (g_str_equal(data->state, "ready") ||
+			g_str_equal(data->state, "configuration"))
+		connman_provider_disconnect(data->provider);
+
+	if (data->call)
+		dbus_pending_call_cancel(data->call);
+
+	connman_provider_set_data(data->provider, NULL);
+
+	connman_provider_remove(data->provider);
+
+	data->provider = NULL;
+}
+
+static void connection_destroy(gpointer hash_data)
+{
+	struct connection_data *data = hash_data;
+
+	DBG("data %p", data);
+
+	if (data->provider)
+		destroy_provider(data);
+
+	g_free(data->path);
+	g_free(data->ident);
+	g_free(data->state);
+	g_free(data->type);
+	g_free(data->name);
+	g_free(data->host);
+	g_free(data->host_ip);
+	g_free(data->domain);
+	g_hash_table_destroy(data->server_routes);
+	g_hash_table_destroy(data->user_routes);
+	g_strfreev(data->nameservers);
+	g_hash_table_destroy(data->setting_strings);
+	connman_ipaddress_free(data->ip);
+
+	cancel_host_resolv(data);
+
+	g_free(data);
+}
+
+static void vpnd_created(DBusConnection *conn, void *user_data)
+{
+	DBG("connection %p", conn);
+
+	get_connections(user_data);
+}
+
+static void vpnd_removed(DBusConnection *conn, void *user_data)
+{
+	DBG("connection %p", conn);
+
+	g_hash_table_remove_all(vpn_connections);
+}
+
+static void remove_connection(DBusConnection *conn, const char *path)
+{
+	DBG("path %s", path);
+
+	g_hash_table_remove(vpn_connections, get_ident(path));
+}
+
+static gboolean connection_removed(DBusConnection *conn, DBusMessage *message,
+				void *user_data)
+{
+	const char *path;
+	const char *signature = DBUS_TYPE_OBJECT_PATH_AS_STRING;
+	struct connection_data *data;
+
+	if (!dbus_message_has_signature(message, signature)) {
+		connman_error("vpn removed signature \"%s\" does not match "
+							"expected \"%s\"",
+			dbus_message_get_signature(message), signature);
+		return TRUE;
+	}
+
+	dbus_message_get_args(message, NULL, DBUS_TYPE_OBJECT_PATH, &path,
+				DBUS_TYPE_INVALID);
+
+	data = g_hash_table_lookup(vpn_connections, get_ident(path));
+	if (data)
+		remove_connection(conn, path);
+
+	return TRUE;
+}
+
+static gboolean connection_added(DBusConnection *conn, DBusMessage *message,
+				void *user_data)
+{
+	DBusMessageIter iter, properties;
+	const char *path;
+	const char *signature = DBUS_TYPE_OBJECT_PATH_AS_STRING
+		DBUS_TYPE_ARRAY_AS_STRING
+		DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+		DBUS_TYPE_STRING_AS_STRING
+		DBUS_TYPE_VARIANT_AS_STRING
+		DBUS_DICT_ENTRY_END_CHAR_AS_STRING;
+
+	if (!dbus_message_has_signature(message, signature)) {
+		connman_error("vpn ConnectionAdded signature \"%s\" does not "
+						"match expected \"%s\"",
+			dbus_message_get_signature(message), signature);
+		return TRUE;
+	}
+
+	DBG("");
+
+	if (!dbus_message_iter_init(message, &iter))
+		return TRUE;
+
+	dbus_message_iter_get_basic(&iter, &path);
+
+	dbus_message_iter_next(&iter);
+	dbus_message_iter_recurse(&iter, &properties);
+
+	add_connection(path, &properties, user_data);
+
+	return TRUE;
+}
+
+static int save_route(GHashTable *routes, int family, const char *network,
+			const char *netmask, const char *gateway)
+{
+	struct vpn_route *route;
+	char *key = g_strdup_printf("%d/%s/%s", family, network, netmask);
+
+	DBG("family %d network %s netmask %s", family, network, netmask);
+
+	route = g_hash_table_lookup(routes, key);
+	if (!route) {
+		route = g_try_new0(struct vpn_route, 1);
+		if (!route) {
+			connman_error("out of memory");
+			return -ENOMEM;
+		}
+
+		route->family = family;
+		route->network = g_strdup(network);
+		route->netmask = g_strdup(netmask);
+		route->gateway = g_strdup(gateway);
+
+		g_hash_table_replace(routes, key, route);
+	} else
+		g_free(key);
+
+	return 0;
+}
+
+static int read_route_dict(GHashTable *routes, DBusMessageIter *dicts)
+{
+	DBusMessageIter dict;
+	const char *network, *netmask, *gateway;
+	int family;
+
+	dbus_message_iter_recurse(dicts, &dict);
+
+	network = netmask = gateway = NULL;
+	family = PF_UNSPEC;
+
+	while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
+
+		DBusMessageIter entry, value;
+		const char *key;
+
+		dbus_message_iter_recurse(&dict, &entry);
+		dbus_message_iter_get_basic(&entry, &key);
+
+		dbus_message_iter_next(&entry);
+		dbus_message_iter_recurse(&entry, &value);
+
+		if (g_str_equal(key, "ProtocolFamily")) {
+			int pf;
+			dbus_message_iter_get_basic(&value, &pf);
+			switch (pf) {
+			case 4:
+				family = AF_INET;
+				break;
+			case 6:
+				family = AF_INET6;
+				break;
+			}
+			DBG("family %d", family);
+		} else if (g_str_equal(key, "Netmask")) {
+			dbus_message_iter_get_basic(&value, &netmask);
+			DBG("netmask %s", netmask);
+		} else if (g_str_equal(key, "Network")) {
+			dbus_message_iter_get_basic(&value, &network);
+			DBG("host %s", network);
+		} else if (g_str_equal(key, "Gateway")) {
+			dbus_message_iter_get_basic(&value, &gateway);
+			DBG("gateway %s", gateway);
+		}
+
+		dbus_message_iter_next(&dict);
+	}
+
+	if (!netmask || !network || !gateway) {
+		DBG("Value missing.");
+		return -EINVAL;
+	}
+
+	return save_route(routes, family, network, netmask, gateway);
+}
+
+static int routes_changed(DBusMessageIter *array, GHashTable *routes)
+{
+	DBusMessageIter entry;
+	int ret = -EINVAL;
+
+	if (dbus_message_iter_get_arg_type(array) != DBUS_TYPE_ARRAY) {
+		DBG("Expecting array, ignoring routes.");
+		return -EINVAL;
+	}
+
+	while (dbus_message_iter_get_arg_type(array) == DBUS_TYPE_ARRAY) {
+
+		dbus_message_iter_recurse(array, &entry);
+
+		while (dbus_message_iter_get_arg_type(&entry) ==
+							DBUS_TYPE_STRUCT) {
+			DBusMessageIter dicts;
+
+			dbus_message_iter_recurse(&entry, &dicts);
+
+			while (dbus_message_iter_get_arg_type(&dicts) ==
+							DBUS_TYPE_ARRAY) {
+				int err = read_route_dict(routes, &dicts);
+				if (ret != 0)
+					ret = err;
+				dbus_message_iter_next(&dicts);
+			}
+
+			dbus_message_iter_next(&entry);
+		}
+
+		dbus_message_iter_next(array);
+	}
+
+	return ret;
+}
+
+static gboolean property_changed(DBusConnection *conn,
+				DBusMessage *message,
+				void *user_data)
+{
+	const char *path = dbus_message_get_path(message);
+	struct connection_data *data = NULL;
+	DBusMessageIter iter, value;
+	bool ip_set = false;
+	int err;
+	char *str;
+	const char *key;
+	const char *signature =	DBUS_TYPE_STRING_AS_STRING
+		DBUS_TYPE_VARIANT_AS_STRING;
+
+	if (!dbus_message_has_signature(message, signature)) {
+		connman_error("vpn property signature \"%s\" does not match "
+							"expected \"%s\"",
+			dbus_message_get_signature(message), signature);
+		return TRUE;
+	}
+
+	data = g_hash_table_lookup(vpn_connections, get_ident(path));
+	if (!data)
+		return TRUE;
+
+	if (!dbus_message_iter_init(message, &iter))
+		return TRUE;
+
+	dbus_message_iter_get_basic(&iter, &key);
+
+	dbus_message_iter_next(&iter);
+	dbus_message_iter_recurse(&iter, &value);
+
+	DBG("key %s", key);
+
+	if (g_str_equal(key, "State")) {
+		dbus_message_iter_get_basic(&value, &str);
+
+		DBG("%s %s -> %s", data->path, data->state, str);
+
+		if (g_str_equal(data->state, str))
+			return TRUE;
+
+		g_free(data->state);
+		data->state = g_strdup(str);
+
+		set_provider_state(data);
+	} else if (g_str_equal(key, "Index")) {
+		dbus_message_iter_get_basic(&value, &data->index);
+		connman_provider_set_index(data->provider, data->index);
+	} else if (g_str_equal(key, "IPv4")) {
+		err = extract_ip(&value, AF_INET, data);
+		ip_set = true;
+	} else if (g_str_equal(key, "IPv6")) {
+		err = extract_ip(&value, AF_INET6, data);
+		ip_set = true;
+	} else if (g_str_equal(key, "ServerRoutes")) {
+		err = routes_changed(&value, data->server_routes);
+		/*
+		 * Note that the vpnd will delay the route sending a bit
+		 * (in order to collect the routes from VPN client),
+		 * so we might have got the State changed property before
+		 * we got ServerRoutes. This means that we must try to set
+		 * the routes here because they would be left unset otherwise.
+		 */
+		if (err == 0)
+			set_routes(data->provider,
+						CONNMAN_PROVIDER_ROUTE_SERVER);
+	} else if (g_str_equal(key, "UserRoutes")) {
+		err = routes_changed(&value, data->user_routes);
+		if (err == 0)
+			set_routes(data->provider,
+						CONNMAN_PROVIDER_ROUTE_USER);
+	} else if (g_str_equal(key, "Nameservers")) {
+		if (extract_nameservers(&value, data) == 0 &&
+						data->nameservers)
+			connman_provider_set_nameservers(data->provider,
+							data->nameservers);
+	} else if (g_str_equal(key, "Domain")) {
+		dbus_message_iter_get_basic(&value, &str);
+		g_free(data->domain);
+		data->domain = g_strdup(str);
+		connman_provider_set_domain(data->provider, data->domain);
+	}
+
+	if (ip_set && err == 0) {
+		err = connman_provider_set_ipaddress(data->provider, data->ip);
+		if (err < 0)
+			DBG("setting provider IP address failed (%s/%d)",
+				strerror(-err), -err);
+	}
+
+	return TRUE;
+}
+
+static int vpn_init(void)
+{
+	int err;
+
+	connection = connman_dbus_get_connection();
+	if (!connection)
+		return -EIO;
+
+	watch = g_dbus_add_service_watch(connection, VPN_SERVICE,
+			vpnd_created, vpnd_removed, &provider_driver, NULL);
+
+	added_watch = g_dbus_add_signal_watch(connection, VPN_SERVICE, NULL,
+					VPN_MANAGER_INTERFACE,
+					CONNECTION_ADDED, connection_added,
+					&provider_driver, NULL);
+
+	removed_watch = g_dbus_add_signal_watch(connection, VPN_SERVICE, NULL,
+					VPN_MANAGER_INTERFACE,
+					CONNECTION_REMOVED, connection_removed,
+					NULL, NULL);
+
+	property_watch = g_dbus_add_signal_watch(connection, VPN_SERVICE, NULL,
+					VPN_CONNECTION_INTERFACE,
+					PROPERTY_CHANGED, property_changed,
+					NULL, NULL);
+
+	if (added_watch == 0 || removed_watch == 0 || property_watch == 0) {
+		err = -EIO;
+		goto remove;
+	}
+
+	err = connman_provider_driver_register(&provider_driver);
+	if (err == 0) {
+		vpn_connections = g_hash_table_new_full(g_str_hash,
+						g_str_equal,
+						g_free, connection_destroy);
+
+		vpnd_created(connection, &provider_driver);
+	}
+
+	return err;
+
+remove:
+	g_dbus_remove_watch(connection, watch);
+	g_dbus_remove_watch(connection, added_watch);
+	g_dbus_remove_watch(connection, removed_watch);
+	g_dbus_remove_watch(connection, property_watch);
+
+	dbus_connection_unref(connection);
+
+	return err;
+}
+
+static void vpn_exit(void)
+{
+	g_dbus_remove_watch(connection, watch);
+	g_dbus_remove_watch(connection, added_watch);
+	g_dbus_remove_watch(connection, removed_watch);
+	g_dbus_remove_watch(connection, property_watch);
+
+	connman_provider_driver_unregister(&provider_driver);
+
+	if (vpn_connections)
+		g_hash_table_destroy(vpn_connections);
+
+	dbus_connection_unref(connection);
+}
+
+CONNMAN_PLUGIN_DEFINE(vpn, "VPN plugin", VERSION,
+		CONNMAN_PLUGIN_PRIORITY_DEFAULT, vpn_init, vpn_exit)
diff --git a/connman/plugins/wifi.c b/connman/plugins/wifi.c
new file mode 100644
index 0000000..b2fea87
--- /dev/null
+++ b/connman/plugins/wifi.c
@@ -0,0 +1,3392 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2014  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 <unistd.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <linux/if_arp.h>
+#include <linux/wireless.h>
+#include <net/ethernet.h>
+
+#ifndef IFF_LOWER_UP
+#define IFF_LOWER_UP	0x10000
+#endif
+
+#include <dbus/dbus.h>
+#include <glib.h>
+
+#define CONNMAN_API_SUBJECT_TO_CHANGE
+#include <connman/plugin.h>
+#include <connman/inet.h>
+#include <connman/device.h>
+#include <connman/rtnl.h>
+#include <connman/technology.h>
+#include <connman/service.h>
+#include <connman/peer.h>
+#include <connman/log.h>
+#include <connman/option.h>
+#include <connman/storage.h>
+#include <include/setting.h>
+#include <connman/provision.h>
+#include <connman/utsname.h>
+#include <connman/machine.h>
+
+#include <gsupplicant/gsupplicant.h>
+
+#define wifi_data_ref(wifi) \
+	wifi_data_ref_debug(wifi, __FILE__, __LINE__, __func__)
+
+#define wifi_data_unref(wifi) \
+	wifi_data_unref_debug(wifi, __FILE__, __LINE__, __func__)
+
+#define CLEANUP_TIMEOUT   8	/* in seconds */
+#define INACTIVE_TIMEOUT  12	/* in seconds */
+#define FAVORITE_MAXIMUM_RETRIES 2
+
+#define BGSCAN_DEFAULT "simple:30:-45:300"
+#define AUTOSCAN_DEFAULT "exponential:3:300"
+
+#define P2P_FIND_TIMEOUT 30
+#define P2P_CONNECTION_TIMEOUT 100
+#define P2P_LISTEN_PERIOD 500
+#define P2P_LISTEN_INTERVAL 2000
+
+static struct connman_technology *wifi_technology = NULL;
+static struct connman_technology *p2p_technology = NULL;
+
+enum wifi_ap_capability{
+	WIFI_AP_UNKNOWN 	= 0,
+	WIFI_AP_SUPPORTED 	= 1,
+	WIFI_AP_NOT_SUPPORTED 	= 2,
+};
+
+struct hidden_params {
+	char ssid[32];
+	unsigned int ssid_len;
+	char *identity;
+	char *passphrase;
+	char *security;
+	GSupplicantScanParams *scan_params;
+	gpointer user_data;
+};
+
+/**
+ * Used for autoscan "emulation".
+ * Should be removed when wpa_s autoscan support will be by default.
+ */
+struct autoscan_params {
+	int base;
+	int limit;
+	int interval;
+	unsigned int timeout;
+};
+
+struct wifi_tethering_info {
+	struct wifi_data *wifi;
+	struct connman_technology *technology;
+	char *ifname;
+	GSupplicantSSID *ssid;
+};
+
+struct wifi_data {
+	int refcount;
+	char *identifier;
+	struct connman_device *device;
+	struct connman_network *network;
+	struct connman_network *pending_network;
+	GSList *networks;
+	GSupplicantInterface *interface;
+	GSupplicantState state;
+	bool connected;
+	bool disconnecting;
+	bool tethering;
+	enum wifi_ap_capability ap_supported;
+	bool bridged;
+	bool interface_ready;
+	bool shutting_down;
+	const char *bridge;
+	int index;
+	unsigned flags;
+	unsigned int watch;
+	int retries;
+	struct hidden_params *hidden;
+	bool postpone_hidden;
+	struct wifi_tethering_info *tethering_param;
+	/**
+	 * autoscan "emulation".
+	 */
+	struct autoscan_params *autoscan;
+
+	GSupplicantScanParams *scan_params;
+	unsigned int p2p_find_timeout;
+	unsigned int p2p_connection_timeout;
+	struct connman_peer *pending_peer;
+	GSupplicantPeer *peer;
+	bool p2p_connecting;
+	bool p2p_device;
+	int servicing;
+	bool scanning;
+};
+
+static GList *iface_list = NULL;
+
+static GList *pending_wifi_device = NULL;
+static GList *p2p_iface_list = NULL;
+bool wfd_service_registered = false;
+
+static void start_autoscan(struct connman_device *device);
+static int tech_set_tethering(struct connman_technology *technology,
+				const char *identifier, const char *passphrase,
+				const char *bridge, bool enabled);
+
+static void wifi_data_ref_debug(struct wifi_data *wifi,
+				const char *file, int line, const char *caller)
+{
+	DBG("%p ref %d by %s:%d:%s()", wifi, wifi->refcount + 1,
+		file, line, caller);
+
+	__sync_fetch_and_add(&wifi->refcount, 1);
+}
+
+static void wifi_data_unref_debug(struct wifi_data *wifi,
+				const char *file, int line, const char *caller)
+{
+	DBG("%p unref %d by %s:%d:%s()", wifi, wifi->refcount - 1,
+	file, line, caller);
+
+	if (__sync_fetch_and_sub(&wifi->refcount, 1) != 1)
+		return;
+
+	g_free(wifi);
+}
+
+static inline bool wifi_link_removed(struct wifi_data *wifi)
+{
+	return (!wifi || wifi->shutting_down);
+}
+
+static int p2p_tech_probe(struct connman_technology *technology)
+{
+	p2p_technology = technology;
+
+	return 0;
+}
+
+static void p2p_tech_remove(struct connman_technology *technology)
+{
+	p2p_technology = NULL;
+}
+
+static struct connman_technology_driver p2p_tech_driver = {
+	.name		= "p2p",
+	.type		= CONNMAN_SERVICE_TYPE_P2P,
+	.probe		= p2p_tech_probe,
+	.remove		= p2p_tech_remove,
+};
+
+static bool is_p2p_connecting(void)
+{
+	GList *list;
+
+	for (list = iface_list; list; list = list->next) {
+		struct wifi_data *wifi = list->data;
+
+		if (wifi->p2p_connecting)
+			return true;
+	}
+
+	return false;
+}
+
+static void add_pending_wifi_device(struct wifi_data *wifi)
+{
+	if (g_list_find(pending_wifi_device, wifi))
+		return;
+
+	pending_wifi_device = g_list_append(pending_wifi_device, wifi);
+}
+
+static struct wifi_data *get_pending_wifi_data(const char *ifname)
+{
+	GList *list;
+
+	for (list = pending_wifi_device; list; list = list->next) {
+		struct wifi_data *wifi;
+		const char *dev_name;
+
+		wifi = list->data;
+		if (!wifi || !wifi->device)
+			continue;
+
+		dev_name = connman_device_get_string(wifi->device, "Interface");
+		if (!g_strcmp0(ifname, dev_name)) {
+			pending_wifi_device = g_list_delete_link(
+						pending_wifi_device, list);
+			return wifi;
+		}
+	}
+
+	return NULL;
+}
+
+static void remove_pending_wifi_device(struct wifi_data *wifi)
+{
+	GList *link;
+
+	link = g_list_find(pending_wifi_device, wifi);
+
+	if (!link)
+		return;
+
+	pending_wifi_device = g_list_delete_link(pending_wifi_device, link);
+}
+
+static void peer_cancel_timeout(struct wifi_data *wifi)
+{
+	if (wifi->p2p_connection_timeout > 0)
+		g_source_remove(wifi->p2p_connection_timeout);
+
+	wifi->p2p_connection_timeout = 0;
+	wifi->p2p_connecting = false;
+
+	if (wifi->pending_peer) {
+		connman_peer_unref(wifi->pending_peer);
+		wifi->pending_peer = NULL;
+	}
+
+	wifi->peer = NULL;
+}
+
+static gboolean peer_connect_timeout(gpointer data)
+{
+	struct wifi_data *wifi = data;
+
+	DBG("");
+
+	if (wifi->p2p_connecting) {
+		enum connman_peer_state state = CONNMAN_PEER_STATE_FAILURE;
+
+		if (g_supplicant_peer_has_requested_connection(wifi->peer))
+			state = CONNMAN_PEER_STATE_IDLE;
+
+		connman_peer_set_state(wifi->pending_peer, state);
+	}
+
+	peer_cancel_timeout(wifi);
+
+	return FALSE;
+}
+
+static void peer_connect_callback(int result, GSupplicantInterface *interface,
+							void *user_data)
+{
+	struct wifi_data *wifi = user_data;
+	struct connman_peer *peer = wifi->pending_peer;
+
+	DBG("peer %p - %d", peer, result);
+
+	if (!peer)
+		return;
+
+	if (result < 0) {
+		peer_connect_timeout(wifi);
+		return;
+	}
+
+	connman_peer_set_state(peer, CONNMAN_PEER_STATE_ASSOCIATION);
+
+	wifi->p2p_connection_timeout = g_timeout_add_seconds(
+						P2P_CONNECTION_TIMEOUT,
+						peer_connect_timeout, wifi);
+}
+
+static int peer_connect(struct connman_peer *peer,
+			enum connman_peer_wps_method wps_method,
+			const char *wps_pin)
+{
+	struct connman_device *device = connman_peer_get_device(peer);
+	GSupplicantPeerParams *peer_params;
+	GSupplicantPeer *gs_peer;
+	struct wifi_data *wifi;
+	bool pbc, pin;
+	int ret;
+
+	DBG("peer %p", peer);
+
+	if (!device)
+		return -ENODEV;
+
+	wifi = connman_device_get_data(device);
+	if (!wifi)
+		return -ENODEV;
+
+	if (wifi->p2p_connecting)
+		return -EBUSY;
+
+	wifi->peer = NULL;
+
+	gs_peer = g_supplicant_interface_peer_lookup(wifi->interface,
+					connman_peer_get_identifier(peer));
+	if (!gs_peer)
+		return -EINVAL;
+
+	pbc = g_supplicant_peer_is_wps_pbc(gs_peer);
+	pin = g_supplicant_peer_is_wps_pin(gs_peer);
+
+	switch (wps_method) {
+	case CONNMAN_PEER_WPS_UNKNOWN:
+		if ((pbc && pin) || pin)
+			return -ENOKEY;
+		break;
+	case CONNMAN_PEER_WPS_PBC:
+		if (!pbc)
+			return -EINVAL;
+		wps_pin = NULL;
+		break;
+	case CONNMAN_PEER_WPS_PIN:
+		if (!pin || !wps_pin)
+			return -EINVAL;
+		break;
+	}
+
+	peer_params = g_try_malloc0(sizeof(GSupplicantPeerParams));
+	if (!peer_params)
+		return -ENOMEM;
+
+	peer_params->path = g_strdup(g_supplicant_peer_get_path(gs_peer));
+	if (wps_pin)
+		peer_params->wps_pin = g_strdup(wps_pin);
+
+	peer_params->master = connman_peer_service_is_master();
+
+	ret = g_supplicant_interface_p2p_connect(wifi->interface, peer_params,
+						peer_connect_callback, wifi);
+	if (ret == -EINPROGRESS) {
+		wifi->pending_peer = connman_peer_ref(peer);
+		wifi->peer = gs_peer;
+		wifi->p2p_connecting = true;
+	} else if (ret < 0)
+		g_free(peer_params);
+
+	return ret;
+}
+
+static int peer_disconnect(struct connman_peer *peer)
+{
+	struct connman_device *device = connman_peer_get_device(peer);
+	GSupplicantPeerParams peer_params = {};
+	GSupplicantPeer *gs_peer;
+	struct wifi_data *wifi;
+	int ret;
+
+	DBG("peer %p", peer);
+
+	if (!device)
+		return -ENODEV;
+
+	wifi = connman_device_get_data(device);
+	if (!wifi)
+		return -ENODEV;
+
+	gs_peer = g_supplicant_interface_peer_lookup(wifi->interface,
+					connman_peer_get_identifier(peer));
+	if (!gs_peer)
+		return -EINVAL;
+
+	peer_params.path = g_strdup(g_supplicant_peer_get_path(gs_peer));
+
+	ret = g_supplicant_interface_p2p_disconnect(wifi->interface,
+							&peer_params);
+	g_free(peer_params.path);
+
+	if (ret == -EINPROGRESS)
+		peer_cancel_timeout(wifi);
+
+	return ret;
+}
+
+struct peer_service_registration {
+	peer_service_registration_cb_t callback;
+	void *user_data;
+};
+
+static bool is_service_wfd(const unsigned char *specs, int length)
+{
+	if (length < 9 || specs[0] != 0 || specs[1] != 0 || specs[2] != 6)
+		return false;
+
+	return true;
+}
+
+static void apply_p2p_listen_on_iface(gpointer data, gpointer user_data)
+{
+	struct wifi_data *wifi = data;
+
+	if (!wifi->interface ||
+			!g_supplicant_interface_has_p2p(wifi->interface))
+		return;
+
+	if (!wifi->servicing) {
+		g_supplicant_interface_p2p_listen(wifi->interface,
+				P2P_LISTEN_PERIOD, P2P_LISTEN_INTERVAL);
+	}
+
+	wifi->servicing++;
+}
+
+static void register_wfd_service_cb(int result,
+				GSupplicantInterface *iface, void *user_data)
+{
+	struct peer_service_registration *reg_data = user_data;
+
+	DBG("");
+
+	if (result == 0)
+		g_list_foreach(iface_list, apply_p2p_listen_on_iface, NULL);
+
+	if (reg_data && reg_data->callback) {
+		reg_data->callback(result, reg_data->user_data);
+		g_free(reg_data);
+	}
+}
+
+static GSupplicantP2PServiceParams *fill_in_peer_service_params(
+				const unsigned char *spec,
+				int spec_length, const unsigned char *query,
+				int query_length, int version)
+{
+	GSupplicantP2PServiceParams *params;
+
+	params = g_try_malloc0(sizeof(GSupplicantP2PServiceParams));
+	if (!params)
+		return NULL;
+
+	if (version > 0) {
+		params->version = version;
+		params->service = g_memdup(spec, spec_length);
+	} else if (query_length > 0 && spec_length > 0) {
+		params->query = g_memdup(query, query_length);
+		params->query_length = query_length;
+
+		params->response = g_memdup(spec, spec_length);
+		params->response_length = spec_length;
+	} else {
+		params->wfd_ies = g_memdup(spec, spec_length);
+		params->wfd_ies_length = spec_length;
+	}
+
+	return params;
+}
+
+static void free_peer_service_params(GSupplicantP2PServiceParams *params)
+{
+	if (!params)
+		return;
+
+	g_free(params->service);
+	g_free(params->query);
+	g_free(params->response);
+	g_free(params->wfd_ies);
+
+	g_free(params);
+}
+
+static int peer_register_wfd_service(const unsigned char *specification,
+				int specification_length,
+				peer_service_registration_cb_t callback,
+				void *user_data)
+{
+	struct peer_service_registration *reg_data = NULL;
+	static GSupplicantP2PServiceParams *params;
+	int ret;
+
+	DBG("");
+
+	if (wfd_service_registered)
+		return -EBUSY;
+
+	params = fill_in_peer_service_params(specification,
+					specification_length, NULL, 0, 0);
+	if (!params)
+		return -ENOMEM;
+
+	reg_data = g_try_malloc0(sizeof(*reg_data));
+	if (!reg_data) {
+		ret = -ENOMEM;
+		goto error;
+	}
+
+	reg_data->callback = callback;
+	reg_data->user_data = user_data;
+
+	ret = g_supplicant_set_widi_ies(params,
+					register_wfd_service_cb, reg_data);
+	if (ret < 0 && ret != -EINPROGRESS)
+		goto error;
+
+	wfd_service_registered = true;
+
+	return ret;
+error:
+	free_peer_service_params(params);
+	g_free(reg_data);
+
+	return ret;
+}
+
+static void register_peer_service_cb(int result,
+				GSupplicantInterface *iface, void *user_data)
+{
+	struct wifi_data *wifi = g_supplicant_interface_get_data(iface);
+	struct peer_service_registration *reg_data = user_data;
+
+	DBG("");
+
+	if (result == 0)
+		apply_p2p_listen_on_iface(wifi, NULL);
+
+	if (reg_data->callback)
+		reg_data->callback(result, reg_data->user_data);
+
+	g_free(reg_data);
+}
+
+static int peer_register_service(const unsigned char *specification,
+				int specification_length,
+				const unsigned char *query,
+				int query_length, int version,
+				peer_service_registration_cb_t callback,
+				void *user_data)
+{
+	struct peer_service_registration *reg_data;
+	GSupplicantP2PServiceParams *params;
+	bool found = false;
+	int ret, ret_f;
+	GList *list;
+
+	DBG("");
+
+	if (specification && !version && !query &&
+			is_service_wfd(specification, specification_length)) {
+		return peer_register_wfd_service(specification,
+				specification_length, callback, user_data);
+	}
+
+	reg_data = g_try_malloc0(sizeof(*reg_data));
+	if (!reg_data)
+		return -ENOMEM;
+
+	reg_data->callback = callback;
+	reg_data->user_data = user_data;
+
+	ret_f = -EOPNOTSUPP;
+
+	for (list = iface_list; list; list = list->next) {
+		struct wifi_data *wifi = list->data;
+		GSupplicantInterface *iface = wifi->interface;
+
+		if (!g_supplicant_interface_has_p2p(iface))
+			continue;
+
+		params = fill_in_peer_service_params(specification,
+						specification_length, query,
+						query_length, version);
+		if (!params) {
+			ret = -ENOMEM;
+			continue;
+		}
+
+		if (!found) {
+			ret_f = g_supplicant_interface_p2p_add_service(iface,
+				register_peer_service_cb, params, reg_data);
+			if (ret_f == 0 || ret_f == -EINPROGRESS)
+				found = true;
+			ret = ret_f;
+		} else
+			ret = g_supplicant_interface_p2p_add_service(iface,
+				register_peer_service_cb, params, NULL);
+		if (ret != 0 && ret != -EINPROGRESS)
+			free_peer_service_params(params);
+	}
+
+	if (ret_f != 0 && ret_f != -EINPROGRESS)
+		g_free(reg_data);
+
+	return ret_f;
+}
+
+static int peer_unregister_wfd_service(void)
+{
+	GSupplicantP2PServiceParams *params;
+	GList *list;
+
+	if (!wfd_service_registered)
+		return -EALREADY;
+
+	params = fill_in_peer_service_params(NULL, 0, NULL, 0, 0);
+	if (!params)
+		return -ENOMEM;
+
+	wfd_service_registered = false;
+
+	g_supplicant_set_widi_ies(params, NULL, NULL);
+
+	for (list = iface_list; list; list = list->next) {
+		struct wifi_data *wifi = list->data;
+
+		if (!g_supplicant_interface_has_p2p(wifi->interface))
+			continue;
+
+		wifi->servicing--;
+		if (!wifi->servicing || wifi->servicing < 0) {
+			g_supplicant_interface_p2p_listen(wifi->interface,
+									0, 0);
+			wifi->servicing = 0;
+		}
+	}
+
+	return 0;
+}
+
+static int peer_unregister_service(const unsigned char *specification,
+						int specification_length,
+						const unsigned char *query,
+						int query_length, int version)
+{
+	GSupplicantP2PServiceParams *params;
+	bool wfd = false;
+	GList *list;
+	int ret;
+
+	if (specification && !version && !query &&
+			is_service_wfd(specification, specification_length)) {
+		ret = peer_unregister_wfd_service();
+		if (ret != 0 && ret != -EINPROGRESS)
+			return ret;
+		wfd = true;
+	}
+
+	for (list = iface_list; list; list = list->next) {
+		struct wifi_data *wifi = list->data;
+		GSupplicantInterface *iface = wifi->interface;
+
+		if (wfd)
+			goto stop_listening;
+
+		if (!g_supplicant_interface_has_p2p(iface))
+			continue;
+
+		params = fill_in_peer_service_params(specification,
+						specification_length, query,
+						query_length, version);
+		if (!params) {
+			ret = -ENOMEM;
+			continue;
+		}
+
+		ret = g_supplicant_interface_p2p_del_service(iface, params);
+		if (ret != 0 && ret != -EINPROGRESS)
+			free_peer_service_params(params);
+stop_listening:
+		wifi->servicing--;
+		if (!wifi->servicing || wifi->servicing < 0) {
+			g_supplicant_interface_p2p_listen(iface, 0, 0);
+			wifi->servicing = 0;
+		}
+	}
+
+	return 0;
+}
+
+static struct connman_peer_driver peer_driver = {
+	.connect    = peer_connect,
+	.disconnect = peer_disconnect,
+	.register_service = peer_register_service,
+	.unregister_service = peer_unregister_service,
+};
+
+static void handle_tethering(struct wifi_data *wifi)
+{
+	if (!wifi->tethering)
+		return;
+
+	if (!wifi->bridge)
+		return;
+
+	if (wifi->bridged)
+		return;
+
+	DBG("index %d bridge %s", wifi->index, wifi->bridge);
+
+	if (connman_inet_add_to_bridge(wifi->index, wifi->bridge) < 0)
+		return;
+
+	wifi->bridged = true;
+}
+
+static void wifi_newlink(unsigned flags, unsigned change, void *user_data)
+{
+	struct connman_device *device = user_data;
+	struct wifi_data *wifi = connman_device_get_data(device);
+
+	if (wifi_link_removed(wifi))
+		return;
+
+	DBG("index %d flags %d change %d", wifi->index, flags, change);
+
+	if ((wifi->flags & IFF_UP) != (flags & IFF_UP)) {
+		if (flags & IFF_UP)
+			DBG("interface up");
+		else
+			DBG("interface down");
+	}
+
+	if ((wifi->flags & IFF_LOWER_UP) != (flags & IFF_LOWER_UP)) {
+		if (flags & IFF_LOWER_UP) {
+			DBG("carrier on");
+
+			handle_tethering(wifi);
+		} else
+			DBG("carrier off");
+	}
+
+	wifi->flags = flags;
+}
+
+static int wifi_probe(struct connman_device *device)
+{
+	struct wifi_data *wifi;
+
+	DBG("device %p", device);
+
+	wifi = g_try_new0(struct wifi_data, 1);
+	if (!wifi)
+		return -ENOMEM;
+
+	wifi->refcount = 1;
+	wifi->shutting_down = false;
+	wifi->scanning = false;
+
+    	DBG("wifi allocated %p ref count %d", wifi, wifi->refcount);
+	wifi->state = G_SUPPLICANT_STATE_INACTIVE;
+	wifi->ap_supported = WIFI_AP_UNKNOWN;
+	wifi->tethering_param = NULL;
+
+	connman_device_set_data(device, wifi);
+	wifi->device = connman_device_ref(device);
+
+	wifi->index = connman_device_get_index(device);
+	wifi->flags = 0;
+
+	wifi->watch = connman_rtnl_add_newlink_watch(wifi->index,
+							wifi_newlink, device);
+	if (is_p2p_connecting())
+		add_pending_wifi_device(wifi);
+	else
+		iface_list = g_list_append(iface_list, wifi);
+
+	return 0;
+}
+
+static void remove_networks(struct connman_device *device,
+				struct wifi_data *wifi)
+{
+	GSList *list;
+
+	for (list = wifi->networks; list; list = list->next) {
+		struct connman_network *network = list->data;
+
+		connman_device_remove_network(device, network);
+		connman_network_unref(network);
+	}
+
+	g_slist_free(wifi->networks);
+	wifi->networks = NULL;
+}
+
+static void reset_autoscan(struct connman_device *device)
+{
+	struct wifi_data *wifi = connman_device_get_data(device);
+	struct autoscan_params *autoscan;
+
+	DBG("");
+
+	if (!wifi || !wifi->autoscan)
+		return;
+
+	autoscan = wifi->autoscan;
+
+	if (autoscan->timeout == 0 && autoscan->interval == 0)
+		return;
+
+	g_source_remove(autoscan->timeout);
+
+	autoscan->timeout = 0;
+	autoscan->interval = 0;
+
+	connman_device_unref(device);
+}
+
+static void stop_autoscan(struct connman_device *device)
+{
+	const struct wifi_data *wifi = connman_device_get_data(device);
+
+	if (!wifi || !wifi->autoscan)
+		return;
+
+	reset_autoscan(device);
+
+	connman_device_set_scanning(device, CONNMAN_SERVICE_TYPE_WIFI, false);
+}
+
+static void check_p2p_technology(void)
+{
+	bool p2p_exists = false;
+	GList *list;
+
+	for (list = iface_list; list; list = list->next) {
+		struct wifi_data *w = list->data;
+
+		if (w->interface &&
+				g_supplicant_interface_has_p2p(w->interface))
+			p2p_exists = true;
+	}
+
+	if (!p2p_exists) {
+		connman_technology_driver_unregister(&p2p_tech_driver);
+		connman_peer_driver_unregister(&peer_driver);
+	}
+}
+
+static void wifi_remove(struct connman_device *device)
+{
+	struct wifi_data *wifi = connman_device_get_data(device);
+
+	DBG("device %p wifi %p", device, wifi);
+
+	if (wifi_link_removed(wifi))
+		return;
+
+    g_supplicant_interface_remove(wifi->interface, NULL, NULL);
+	stop_autoscan(device);
+
+	if (wifi->p2p_device)
+		p2p_iface_list = g_list_remove(p2p_iface_list, wifi);
+	else
+		iface_list = g_list_remove(iface_list, wifi);
+
+	check_p2p_technology();
+
+	remove_pending_wifi_device(wifi);
+
+	if (wifi->p2p_find_timeout) {
+		g_source_remove(wifi->p2p_find_timeout);
+		connman_device_unref(wifi->device);
+	}
+
+	if (wifi->p2p_connection_timeout)
+		g_source_remove(wifi->p2p_connection_timeout);
+
+	remove_networks(device, wifi);
+
+	connman_device_set_powered(device, false);
+	connman_device_set_data(device, NULL);
+	connman_device_unref(wifi->device);
+	wifi->device = NULL;
+
+	connman_rtnl_remove_watch(wifi->watch);
+	wifi->watch = 0;
+
+	g_supplicant_interface_set_data(wifi->interface, NULL);
+	wifi->interface = NULL;
+
+	g_supplicant_interface_cancel(wifi->interface);
+
+	if (wifi->scan_params) {
+		g_supplicant_free_scan_params(wifi->scan_params);
+		wifi->scan_params = NULL;
+	}
+
+	g_free(wifi->autoscan);
+	wifi->autoscan = NULL;
+
+	g_free(wifi->identifier);
+	wifi->identifier = NULL;
+
+	wifi->shutting_down = true;
+
+	/* Remove ref added in wifi_scan() if scan is ongoing */
+	if (wifi->scanning)
+		wifi_data_unref(wifi);
+
+	/* Remove ref added in wifi_probe */
+	wifi_data_unref(wifi);
+}
+
+static bool is_duplicate(GSList *list, gchar *ssid, int ssid_len)
+{
+	GSList *iter;
+
+	for (iter = list; iter; iter = g_slist_next(iter)) {
+		struct scan_ssid *scan_ssid = iter->data;
+
+		if (ssid_len == scan_ssid->ssid_len &&
+				memcmp(ssid, scan_ssid->ssid, ssid_len) == 0)
+			return true;
+	}
+
+	return false;
+}
+
+static int add_scan_param(gchar *hex_ssid, char *raw_ssid, int raw_ssid_len,
+			int freq, GSupplicantScanParams *scan_data,
+			int driver_max_scan_ssids, char *ssid_name)
+{
+	unsigned int i;
+	struct scan_ssid *scan_ssid;
+
+	if ((driver_max_scan_ssids == 0 ||
+			driver_max_scan_ssids > scan_data->num_ssids) &&
+			(hex_ssid || raw_ssid)) {
+		gchar *ssid;
+		unsigned int ssid_len = 0, hex;
+
+		if (hex_ssid) {
+			size_t hex_ssid_len = strlen(hex_ssid);
+
+			ssid = g_try_malloc0(hex_ssid_len / 2);
+			if (!ssid)
+				return -ENOMEM;
+
+			for (i = 0; i < hex_ssid_len; i += 2) {
+				sscanf(hex_ssid + i, "%02x", &hex);
+				ssid[ssid_len++] = hex;
+			}
+		} else {
+			ssid = raw_ssid;
+			ssid_len = raw_ssid_len;
+		}
+
+		/*
+		 * If we have already added hidden AP to the list,
+		 * then do not do it again. This might happen if you have
+		 * used or are using multiple wifi cards, so in that case
+		 * you might have multiple service files for same AP.
+		 */
+		if (is_duplicate(scan_data->ssids, ssid, ssid_len)) {
+			if (hex_ssid)
+				g_free(ssid);
+			return 0;
+		}
+
+		scan_ssid = g_try_new(struct scan_ssid, 1);
+		if (!scan_ssid) {
+			if (hex_ssid)
+				g_free(ssid);
+			return -ENOMEM;
+		}
+
+		memcpy(scan_ssid->ssid, ssid, ssid_len);
+		scan_ssid->ssid_len = ssid_len;
+		scan_data->ssids = g_slist_prepend(scan_data->ssids,
+								scan_ssid);
+
+		scan_data->num_ssids++;
+
+		DBG("SSID %s added to scanned list of %d entries", ssid_name,
+							scan_data->num_ssids);
+
+		if (hex_ssid)
+			g_free(ssid);
+	} else
+		return -EINVAL;
+
+	scan_data->ssids = g_slist_reverse(scan_data->ssids);
+
+	if (!scan_data->freqs) {
+		scan_data->freqs = g_try_malloc0(sizeof(uint16_t));
+		if (!scan_data->freqs) {
+			g_slist_free_full(scan_data->ssids, g_free);
+			return -ENOMEM;
+		}
+
+		scan_data->num_freqs = 1;
+		scan_data->freqs[0] = freq;
+	} else {
+		bool duplicate = false;
+
+		/* Don't add duplicate entries */
+		for (i = 0; i < scan_data->num_freqs; i++) {
+			if (scan_data->freqs[i] == freq) {
+				duplicate = true;
+				break;
+			}
+		}
+
+		if (!duplicate) {
+			scan_data->num_freqs++;
+			scan_data->freqs = g_try_realloc(scan_data->freqs,
+				sizeof(uint16_t) * scan_data->num_freqs);
+			if (!scan_data->freqs) {
+				g_slist_free_full(scan_data->ssids, g_free);
+				return -ENOMEM;
+			}
+			scan_data->freqs[scan_data->num_freqs - 1] = freq;
+		}
+	}
+
+	return 1;
+}
+
+static int get_hidden_connections(GSupplicantScanParams *scan_data)
+{
+	struct connman_config_entry **entries;
+	GKeyFile *keyfile;
+	gchar **services;
+	char *ssid, *name;
+	int i, ret;
+	bool value;
+	int num_ssids = 0, add_param_failed = 0;
+
+	services = connman_storage_get_services();
+	for (i = 0; services && services[i]; i++) {
+		if (strncmp(services[i], "wifi_", 5) != 0)
+			continue;
+
+		keyfile = connman_storage_load_service(services[i]);
+		if (!keyfile)
+			continue;
+
+		value = g_key_file_get_boolean(keyfile,
+					services[i], "Hidden", NULL);
+		if (!value) {
+			g_key_file_free(keyfile);
+			continue;
+		}
+
+		value = g_key_file_get_boolean(keyfile,
+					services[i], "Favorite", NULL);
+		if (!value) {
+			g_key_file_free(keyfile);
+			continue;
+		}
+
+		ssid = g_key_file_get_string(keyfile,
+					services[i], "SSID", NULL);
+
+		name = g_key_file_get_string(keyfile, services[i], "Name",
+								NULL);
+
+		ret = add_scan_param(ssid, NULL, 0, 0, scan_data, 0, name);
+		if (ret < 0)
+			add_param_failed++;
+		else if (ret > 0)
+			num_ssids++;
+
+		g_free(ssid);
+		g_free(name);
+		g_key_file_free(keyfile);
+	}
+
+	/*
+	 * Check if there are any hidden AP that needs to be provisioned.
+	 */
+	entries = connman_config_get_entries("wifi");
+	for (i = 0; entries && entries[i]; i++) {
+		int len;
+
+		if (!entries[i]->hidden)
+			continue;
+
+		if (!entries[i]->ssid) {
+			ssid = entries[i]->name;
+			len = strlen(ssid);
+		} else {
+			ssid = entries[i]->ssid;
+			len = entries[i]->ssid_len;
+		}
+
+		if (!ssid)
+			continue;
+
+		ret = add_scan_param(NULL, ssid, len, 0, scan_data, 0, ssid);
+		if (ret < 0)
+			add_param_failed++;
+		else if (ret > 0)
+			num_ssids++;
+	}
+
+	connman_config_free_entries(entries);
+
+	if (add_param_failed > 0)
+		DBG("Unable to scan %d out of %d SSIDs",
+					add_param_failed, num_ssids);
+
+	g_strfreev(services);
+
+	return num_ssids;
+}
+
+static int get_hidden_connections_params(struct wifi_data *wifi,
+					GSupplicantScanParams *scan_params)
+{
+	int driver_max_ssids, i;
+	GSupplicantScanParams *orig_params;
+
+	/*
+	 * Scan hidden networks so that we can autoconnect to them.
+	 * We will assume 1 as a default number of ssid to scan.
+	 */
+	driver_max_ssids = g_supplicant_interface_get_max_scan_ssids(
+							wifi->interface);
+	if (driver_max_ssids == 0)
+		driver_max_ssids = 1;
+
+	DBG("max ssids %d", driver_max_ssids);
+
+	if (!wifi->scan_params) {
+		wifi->scan_params = g_try_malloc0(sizeof(GSupplicantScanParams));
+		if (!wifi->scan_params)
+			return 0;
+
+		if (get_hidden_connections(wifi->scan_params) == 0) {
+			g_supplicant_free_scan_params(wifi->scan_params);
+			wifi->scan_params = NULL;
+
+			return 0;
+		}
+	}
+
+	orig_params = wifi->scan_params;
+
+	/* Let's transfer driver_max_ssids params */
+	for (i = 0; i < driver_max_ssids; i++) {
+		struct scan_ssid *ssid;
+
+		if (!wifi->scan_params->ssids)
+			break;
+
+		ssid = orig_params->ssids->data;
+		orig_params->ssids = g_slist_remove(orig_params->ssids, ssid);
+		scan_params->ssids = g_slist_prepend(scan_params->ssids, ssid);
+	}
+
+	if (i > 0) {
+		scan_params->num_ssids = i;
+		scan_params->ssids = g_slist_reverse(scan_params->ssids);
+
+		scan_params->freqs = g_memdup(orig_params->freqs,
+				sizeof(uint16_t) * orig_params->num_freqs);
+		if (!scan_params->freqs)
+			goto err;
+
+		scan_params->num_freqs = orig_params->num_freqs;
+
+	} else
+		goto err;
+
+	orig_params->num_ssids -= scan_params->num_ssids;
+
+	return scan_params->num_ssids;
+
+err:
+	g_slist_free_full(scan_params->ssids, g_free);
+	g_supplicant_free_scan_params(wifi->scan_params);
+	wifi->scan_params = NULL;
+
+	return 0;
+}
+
+static int throw_wifi_scan(struct connman_device *device,
+			GSupplicantInterfaceCallback callback)
+{
+	struct wifi_data *wifi = connman_device_get_data(device);
+	int ret;
+
+	if (wifi_link_removed(wifi))
+		return -ENODEV;
+
+	DBG("device %p %p %p", device, wifi->interface, wifi);
+
+	if (wifi->tethering)
+		return -EBUSY;
+
+	if (connman_device_get_scanning(device))
+		return -EALREADY;
+
+	connman_device_ref(device);
+	wifi_data_ref(wifi);
+
+	ret = g_supplicant_interface_scan(wifi->interface, NULL,
+						callback, device);
+	if (ret == 0) {
+		connman_device_set_scanning(device,
+				CONNMAN_SERVICE_TYPE_WIFI, true);
+	} else {
+		wifi_data_unref(wifi);
+		connman_device_unref(device);
+	}
+
+	return ret;
+}
+
+static void hidden_free(struct hidden_params *hidden)
+{
+	if (!hidden)
+		return;
+
+	if (hidden->scan_params)
+		g_supplicant_free_scan_params(hidden->scan_params);
+	g_free(hidden->identity);
+	g_free(hidden->passphrase);
+	g_free(hidden->security);
+	g_free(hidden);
+}
+
+static void scan_callback(int result, GSupplicantInterface *interface,
+						void *user_data)
+{
+	struct connman_device *device = user_data;
+	struct wifi_data *wifi = connman_device_get_data(device);
+	bool scanning;
+
+	DBG("result %d wifi %p", result, wifi);
+
+	if (wifi_link_removed(wifi))
+		goto done;
+
+	if (wifi->hidden && !wifi->postpone_hidden) {
+		connman_network_clear_hidden(wifi->hidden->user_data);
+		hidden_free(wifi->hidden);
+		wifi->hidden = NULL;
+	}
+
+	if (wifi->scan_params) {
+		g_supplicant_free_scan_params(wifi->scan_params);
+		wifi->scan_params = NULL;
+	}
+
+	if (result < 0)
+		connman_device_reset_scanning(device);
+
+	/* User is connecting to a hidden AP, let's wait for finished event */
+	if (wifi->hidden && wifi->postpone_hidden) {
+		GSupplicantScanParams *scan_params;
+		int ret;
+
+		wifi->postpone_hidden = false;
+		scan_params = wifi->hidden->scan_params;
+		wifi->hidden->scan_params = NULL;
+
+		reset_autoscan(device);
+
+		/* No addref on wifi_data, scan_callback already has one */
+		ret = g_supplicant_interface_scan(wifi->interface, scan_params,
+							scan_callback, device);
+		if (ret == 0)
+			return;
+
+		/* On error, let's recall scan_callback, which will cleanup */
+		return scan_callback(ret, interface, user_data);
+	}
+
+	/* Remove ref added in wifi_scan() */
+	if (wifi->scanning) {
+		wifi->scanning = false;
+		wifi_data_unref(wifi);
+	}
+
+done:
+	scanning = connman_device_get_scanning(device);
+
+	if (scanning) {
+		connman_device_set_scanning(device,
+				CONNMAN_SERVICE_TYPE_WIFI, false);
+	}
+
+	if (result != -ENOLINK)
+		start_autoscan(device);
+
+	/*
+	 * If we are here then we were scanning; however, if we are
+	 * also mid-flight disabling the interface, then wifi_disable
+	 * has already cleared the device scanning state and
+	 * unreferenced the device, obviating the need to do it here.
+	 */
+
+	if (scanning)
+		connman_device_unref(device);
+}
+
+static void scan_callback_hidden(int result,
+			GSupplicantInterface *interface, void *user_data)
+{
+	struct connman_device *device = user_data;
+	struct wifi_data *wifi = connman_device_get_data(device);
+	GSupplicantScanParams *scan_params;
+	int ret;
+
+	DBG("result %d wifi %p", result, wifi);
+
+	if (wifi_link_removed(wifi))
+		goto out;
+
+	/* User is trying to connect to a hidden AP */
+	if (wifi->hidden && wifi->postpone_hidden)
+		goto out;
+
+	scan_params = g_try_malloc0(sizeof(GSupplicantScanParams));
+	if (!scan_params)
+		goto out;
+
+	if (get_hidden_connections_params(wifi, scan_params) > 0) {
+		/* No addref on wifi_data, scan_callback_hidden already has one */
+		ret = g_supplicant_interface_scan(wifi->interface,
+							scan_params,
+							scan_callback_hidden,
+							device);
+		if (ret == 0)
+			return;
+	}
+
+	g_supplicant_free_scan_params(scan_params);
+
+out:
+	/* wifi_data struct unref'd in scan_callback */
+	scan_callback(result, interface, user_data);
+}
+
+static gboolean autoscan_timeout(gpointer data)
+{
+	struct connman_device *device = data;
+	struct wifi_data *wifi = connman_device_get_data(device);
+	struct autoscan_params *autoscan;
+	int interval;
+
+	if (wifi_link_removed(wifi))
+		return FALSE;
+
+	autoscan = wifi->autoscan;
+
+	if (autoscan->interval <= 0) {
+		interval = autoscan->base;
+		goto set_interval;
+	} else
+		interval = autoscan->interval * autoscan->base;
+
+	if (interval > autoscan->limit)
+		interval = autoscan->limit;
+
+	throw_wifi_scan(wifi->device, scan_callback_hidden);
+
+set_interval:
+	DBG("interval %d", interval);
+
+	autoscan->interval = interval;
+
+	autoscan->timeout = g_timeout_add_seconds(interval,
+						autoscan_timeout, device);
+
+	return FALSE;
+}
+
+static void start_autoscan(struct connman_device *device)
+{
+	struct wifi_data *wifi = connman_device_get_data(device);
+	struct autoscan_params *autoscan;
+
+	DBG("");
+
+	if (wifi_link_removed(wifi))
+		return;
+
+	if (wifi->p2p_device)
+		return;
+
+	if (wifi->connected)
+		return;
+
+	autoscan = wifi->autoscan;
+	if (!autoscan)
+		return;
+
+	if (autoscan->timeout > 0 || autoscan->interval > 0)
+		return;
+
+	connman_device_ref(device);
+
+	autoscan_timeout(device);
+}
+
+static struct autoscan_params *parse_autoscan_params(const char *params)
+{
+	struct autoscan_params *autoscan;
+	char **list_params;
+	int limit;
+	int base;
+
+	DBG("Emulating autoscan");
+
+	list_params = g_strsplit(params, ":", 0);
+	if (list_params == 0)
+		return NULL;
+
+	if (g_strv_length(list_params) < 3) {
+		g_strfreev(list_params);
+		return NULL;
+	}
+
+	base = atoi(list_params[1]);
+	limit = atoi(list_params[2]);
+
+	g_strfreev(list_params);
+
+	autoscan = g_try_malloc0(sizeof(struct autoscan_params));
+	if (!autoscan) {
+		DBG("Could not allocate memory for autoscan");
+		return NULL;
+	}
+
+	DBG("base %d - limit %d", base, limit);
+	autoscan->base = base;
+	autoscan->limit = limit;
+
+	return autoscan;
+}
+
+static void setup_autoscan(struct wifi_data *wifi)
+{
+	if (!wifi->autoscan)
+		wifi->autoscan = parse_autoscan_params(AUTOSCAN_DEFAULT);
+
+	start_autoscan(wifi->device);
+}
+
+static void finalize_interface_creation(struct wifi_data *wifi)
+{
+	DBG("interface is ready wifi %p tethering %d", wifi, wifi->tethering);
+
+	if (!wifi->device) {
+		connman_error("WiFi device not set");
+		return;
+	}
+
+	connman_device_set_powered(wifi->device, true);
+
+	if (!connman_setting_get_bool("BackgroundScanning"))
+		return;
+
+	if (wifi->p2p_device)
+		return;
+
+	setup_autoscan(wifi);
+}
+
+static void interface_create_callback(int result,
+					GSupplicantInterface *interface,
+							void *user_data)
+{
+	struct wifi_data *wifi = user_data;
+
+	DBG("result %d ifname %s, wifi %p", result,
+				g_supplicant_interface_get_ifname(interface),
+				wifi);
+
+	if (result < 0 || wifi_link_removed(wifi))
+		goto done;
+
+	wifi->interface = interface;
+	g_supplicant_interface_set_data(interface, wifi);
+
+	if (g_supplicant_interface_get_ready(interface)) {
+		wifi->interface_ready = true;
+		finalize_interface_creation(wifi);
+		wifi = NULL;
+	}
+
+done:
+	if (wifi != NULL) {
+		/* Remove ref added in wifi_enable */
+		wifi_data_unref(wifi);
+	}
+}
+
+static int wifi_enable(struct connman_device *device)
+{
+	struct wifi_data *wifi = connman_device_get_data(device);
+	int index;
+	char *interface;
+	const char *driver = connman_option_get_string("wifi");
+	int ret;
+
+	DBG("device %p %p", device, wifi);
+
+	index = connman_device_get_index(device);
+	DBG("index %d p2p %d", index, is_p2p_connecting());
+	if (!wifi || index < 0)
+		return -ENODEV;
+
+	if (is_p2p_connecting())
+		return -EINPROGRESS;
+	interface = connman_inet_ifname(index);
+
+	ret = g_supplicant_interface_create(interface, driver, NULL,
+						interface_create_callback,
+							wifi);
+	g_free(interface);
+	if (ret < 0)
+		return ret;
+
+	return -EINPROGRESS;
+}
+
+static int wifi_disable(struct connman_device *device)
+{
+	struct wifi_data *wifi = connman_device_get_data(device);
+	int ret;
+
+	DBG("device %p wifi %p", device, wifi);
+
+	if (wifi_link_removed(wifi))
+		return -ENODEV;
+
+	wifi->connected = false;
+	wifi->disconnecting = false;
+
+	if (wifi->pending_network)
+		wifi->pending_network = NULL;
+
+	stop_autoscan(device);
+
+	if (wifi->p2p_find_timeout) {
+		g_source_remove(wifi->p2p_find_timeout);
+		wifi->p2p_find_timeout = 0;
+		connman_device_set_scanning(device, CONNMAN_SERVICE_TYPE_P2P, false);
+		connman_device_unref(wifi->device);
+	}
+
+	/* In case of a user scan, device is still referenced */
+	if (connman_device_get_scanning(device)) {
+		connman_device_set_scanning(device,
+				CONNMAN_SERVICE_TYPE_WIFI, false);
+		connman_device_unref(wifi->device);
+	}
+
+	remove_networks(device, wifi);
+
+	ret = g_supplicant_interface_remove(wifi->interface, NULL, NULL);
+	if (ret < 0)
+		return ret;
+
+	return -EINPROGRESS;
+}
+
+struct last_connected {
+	GTimeVal modified;
+	gchar *ssid;
+	int freq;
+};
+
+static gint sort_entry(gconstpointer a, gconstpointer b, gpointer user_data)
+{
+	GTimeVal *aval = (GTimeVal *)a;
+	GTimeVal *bval = (GTimeVal *)b;
+
+	/* Note that the sort order is descending */
+	if (aval->tv_sec < bval->tv_sec)
+		return 1;
+
+	if (aval->tv_sec > bval->tv_sec)
+		return -1;
+
+	return 0;
+}
+
+static void free_entry(gpointer data)
+{
+	struct last_connected *entry = data;
+
+	g_free(entry->ssid);
+	g_free(entry);
+}
+
+static int get_latest_connections(int max_ssids,
+				GSupplicantScanParams *scan_data)
+{
+	GSequenceIter *iter;
+	GSequence *latest_list;
+	struct last_connected *entry;
+	GKeyFile *keyfile;
+	GTimeVal modified;
+	gchar **services;
+	gchar *str;
+	char *ssid;
+	int i, freq;
+	int num_ssids = 0;
+
+	latest_list = g_sequence_new(free_entry);
+	if (!latest_list)
+		return -ENOMEM;
+
+	services = connman_storage_get_services();
+	for (i = 0; services && services[i]; i++) {
+		if (strncmp(services[i], "wifi_", 5) != 0)
+			continue;
+
+		keyfile = connman_storage_load_service(services[i]);
+		if (!keyfile)
+			continue;
+
+		str = g_key_file_get_string(keyfile,
+					services[i], "Favorite", NULL);
+		if (!str || g_strcmp0(str, "true")) {
+			g_free(str);
+			g_key_file_free(keyfile);
+			continue;
+		}
+		g_free(str);
+
+		str = g_key_file_get_string(keyfile,
+					services[i], "AutoConnect", NULL);
+		if (!str || g_strcmp0(str, "true")) {
+			g_free(str);
+			g_key_file_free(keyfile);
+			continue;
+		}
+		g_free(str);
+
+		str = g_key_file_get_string(keyfile,
+					services[i], "Modified", NULL);
+		if (!str) {
+			g_key_file_free(keyfile);
+			continue;
+		}
+		g_time_val_from_iso8601(str, &modified);
+		g_free(str);
+
+		ssid = g_key_file_get_string(keyfile,
+					services[i], "SSID", NULL);
+
+		freq = g_key_file_get_integer(keyfile, services[i],
+					"Frequency", NULL);
+		if (freq) {
+			entry = g_try_new(struct last_connected, 1);
+			if (!entry) {
+				g_sequence_free(latest_list);
+				g_key_file_free(keyfile);
+				g_free(ssid);
+				return -ENOMEM;
+			}
+
+			entry->ssid = ssid;
+			entry->modified = modified;
+			entry->freq = freq;
+
+			g_sequence_insert_sorted(latest_list, entry,
+						sort_entry, NULL);
+			num_ssids++;
+		} else
+			g_free(ssid);
+
+		g_key_file_free(keyfile);
+	}
+
+	g_strfreev(services);
+
+	num_ssids = num_ssids > max_ssids ? max_ssids : num_ssids;
+
+	iter = g_sequence_get_begin_iter(latest_list);
+
+	for (i = 0; i < num_ssids; i++) {
+		entry = g_sequence_get(iter);
+
+		DBG("ssid %s freq %d modified %lu", entry->ssid, entry->freq,
+						entry->modified.tv_sec);
+
+		add_scan_param(entry->ssid, NULL, 0, entry->freq, scan_data,
+						max_ssids, entry->ssid);
+
+		iter = g_sequence_iter_next(iter);
+	}
+
+	g_sequence_free(latest_list);
+	return num_ssids;
+}
+
+static int wifi_scan_simple(struct connman_device *device)
+{
+	reset_autoscan(device);
+
+	return throw_wifi_scan(device, scan_callback_hidden);
+}
+
+static gboolean p2p_find_stop(gpointer data)
+{
+	struct connman_device *device = data;
+	struct wifi_data *wifi = connman_device_get_data(device);
+
+	DBG("");
+
+	wifi->p2p_find_timeout = 0;
+
+	connman_device_set_scanning(device, CONNMAN_SERVICE_TYPE_P2P, false);
+
+	g_supplicant_interface_p2p_stop_find(wifi->interface);
+
+	connman_device_unref(device);
+	reset_autoscan(device);
+
+	return FALSE;
+}
+
+static void p2p_find_callback(int result, GSupplicantInterface *interface,
+							void *user_data)
+{
+	struct connman_device *device = user_data;
+	struct wifi_data *wifi = connman_device_get_data(device);
+
+	if (wifi_link_removed(wifi))
+		goto done;
+
+	DBG("result %d wifi %p", result, wifi);
+
+	if (wifi->p2p_find_timeout) {
+		g_source_remove(wifi->p2p_find_timeout);
+		wifi->p2p_find_timeout = 0;
+	}
+
+	if (result)
+		goto error;
+
+	wifi->p2p_find_timeout = g_timeout_add_seconds(P2P_FIND_TIMEOUT,
+							p2p_find_stop, device);
+	if (!wifi->p2p_find_timeout)
+		goto error;
+done:
+	/* Remove ref added before call to g_supplicant_interface_p2p_find */
+	wifi_data_unref(wifi);
+
+	return;
+
+error:
+    /* Remove ref added before call to g_supplicant_interface_p2p_find */
+	wifi_data_unref(wifi);
+
+	p2p_find_stop(device);
+}
+
+static int p2p_find(struct connman_device *device)
+{
+	struct wifi_data *wifi;
+	int ret;
+
+	DBG("");
+
+	if (!p2p_technology)
+		return -ENOTSUP;
+
+	wifi = connman_device_get_data(device);
+
+	if (g_supplicant_interface_is_p2p_finding(wifi->interface))
+		return -EALREADY;
+
+	reset_autoscan(device);
+	connman_device_ref(device);
+
+	/* Add ref for duration of GSupplicant DBus call(s) */
+	wifi_data_ref(wifi);
+
+	ret = g_supplicant_interface_p2p_find(wifi->interface,
+						p2p_find_callback, device);
+	if (ret) {
+		/* Remove ref if GSupplicant call fails */
+		wifi_data_unref(wifi);
+
+		connman_device_unref(device);
+		start_autoscan(device);
+	} else {
+		connman_device_set_scanning(device,
+				CONNMAN_SERVICE_TYPE_P2P, true);
+	}
+
+	return ret;
+}
+
+/*
+ * Note that the hidden scan is only used when connecting to this specific
+ * hidden AP first time. It is not used when system autoconnects to hidden AP.
+ */
+static int wifi_scan(enum connman_service_type type,
+			struct connman_device *device,
+			const char *ssid, unsigned int ssid_len,
+			const char *identity, const char* passphrase,
+			const char *security, void *user_data)
+{
+	struct wifi_data *wifi = connman_device_get_data(device);
+	GSupplicantScanParams *scan_params = NULL;
+	struct scan_ssid *scan_ssid;
+	struct hidden_params *hidden;
+	int ret;
+	int driver_max_ssids = 0;
+	bool do_hidden;
+	bool scanning;
+
+	if (wifi_link_removed(wifi))
+		return -ENODEV;
+
+	if (wifi->p2p_device)
+		return 0;
+
+	if (type == CONNMAN_SERVICE_TYPE_P2P)
+		return p2p_find(device);
+
+	DBG("device %p wifi interface %p hidden ssid %s wifi %p", device, wifi->interface, ssid, wifi);
+
+	if (wifi->tethering)
+		return 0;
+
+	scanning = connman_device_get_scanning(device);
+
+	if (!ssid || ssid_len == 0 || ssid_len > 32) {
+		if (scanning)
+			return -EALREADY;
+
+		driver_max_ssids = g_supplicant_interface_get_max_scan_ssids(
+							wifi->interface);
+		DBG("max ssids %d", driver_max_ssids);
+		if (driver_max_ssids == 0)
+			return wifi_scan_simple(device);
+
+		do_hidden = false;
+	} else {
+		if (scanning && wifi->hidden && wifi->postpone_hidden)
+			return -EALREADY;
+
+		do_hidden = true;
+	}
+
+	scan_params = g_try_malloc0(sizeof(GSupplicantScanParams));
+	if (!scan_params)
+		return -ENOMEM;
+
+	if (do_hidden) {
+		scan_ssid = g_try_new(struct scan_ssid, 1);
+		if (!scan_ssid) {
+			g_free(scan_params);
+			return -ENOMEM;
+		}
+
+		memcpy(scan_ssid->ssid, ssid, ssid_len);
+		scan_ssid->ssid_len = ssid_len;
+		scan_params->ssids = g_slist_prepend(scan_params->ssids,
+								scan_ssid);
+		scan_params->num_ssids = 1;
+
+		hidden = g_try_new0(struct hidden_params, 1);
+		if (!hidden) {
+			g_supplicant_free_scan_params(scan_params);
+			return -ENOMEM;
+		}
+
+		if (wifi->hidden) {
+			hidden_free(wifi->hidden);
+			wifi->hidden = NULL;
+		}
+
+		memcpy(hidden->ssid, ssid, ssid_len);
+		hidden->ssid_len = ssid_len;
+		hidden->identity = g_strdup(identity);
+		hidden->passphrase = g_strdup(passphrase);
+		hidden->security = g_strdup(security);
+		hidden->user_data = user_data;
+		wifi->hidden = hidden;
+
+		if (scanning) {
+			/* Let's keep this active scan for later,
+			 * when current scan will be over. */
+			wifi->postpone_hidden = TRUE;
+			hidden->scan_params = scan_params;
+
+			return 0;
+		}
+	} else if (wifi->connected) {
+		g_supplicant_free_scan_params(scan_params);
+		return wifi_scan_simple(device);
+	} else {
+		ret = get_latest_connections(driver_max_ssids, scan_params);
+		if (ret <= 0) {
+			g_supplicant_free_scan_params(scan_params);
+			return wifi_scan_simple(device);
+		}
+	}
+
+	connman_device_ref(device);
+
+	reset_autoscan(device);
+
+	/* Add ref to duration of GSupplicant's DBus call(s) */
+	wifi_data_ref(wifi);
+	wifi->scanning = true;
+
+	ret = g_supplicant_interface_scan(wifi->interface, scan_params,
+						scan_callback, device);
+	if (ret == 0) {
+		connman_device_set_scanning(device,
+				CONNMAN_SERVICE_TYPE_WIFI, true);
+	} else {
+		wifi_data_unref(wifi);
+		wifi->scanning = false;
+		g_supplicant_free_scan_params(scan_params);
+		connman_device_unref(device);
+
+		if (do_hidden) {
+			hidden_free(wifi->hidden);
+			wifi->hidden = NULL;
+		}
+	}
+
+	return ret;
+}
+
+static void wifi_regdom_callback(int result,
+					const char *alpha2,
+						void *user_data)
+{
+	struct connman_device *device = user_data;
+	struct wifi_data *wifi = connman_device_get_data(device);
+
+	if (wifi_link_removed(wifi))
+		goto done;
+
+	connman_device_regdom_notify(device, result, alpha2);
+
+done:
+	wifi_data_unref(wifi);
+	connman_device_unref(device);
+}
+
+static int wifi_set_regdom(struct connman_device *device, const char *alpha2)
+{
+	struct wifi_data *wifi = connman_device_get_data(device);
+	int ret;
+
+	if (wifi_link_removed(wifi))
+		return -ENODEV;
+
+	connman_device_ref(device);
+	wifi_data_ref(wifi);
+
+	ret = g_supplicant_interface_set_country(wifi->interface,
+						wifi_regdom_callback,
+							alpha2, device);
+	if (ret != 0) {
+		wifi_data_unref(wifi);
+		connman_device_unref(device);
+	}
+
+	return ret;
+}
+
+static struct connman_device_driver wifi_ng_driver = {
+	.name		= "wifi",
+	.type		= CONNMAN_DEVICE_TYPE_WIFI,
+	.priority	= CONNMAN_DEVICE_PRIORITY_LOW,
+	.probe		= wifi_probe,
+	.remove		= wifi_remove,
+	.enable		= wifi_enable,
+	.disable	= wifi_disable,
+	.scan		= wifi_scan,
+	.set_regdom	= wifi_set_regdom,
+};
+
+static void system_ready(void)
+{
+	DBG("");
+
+	if (connman_device_driver_register(&wifi_ng_driver) < 0)
+		connman_error("Failed to register WiFi driver");
+}
+
+static void system_killed(void)
+{
+	DBG("");
+
+	connman_device_driver_unregister(&wifi_ng_driver);
+}
+
+static int network_probe(struct connman_network *network)
+{
+	DBG("network %p", network);
+
+	return 0;
+}
+
+static void network_remove(struct connman_network *network)
+{
+	struct connman_device *device = connman_network_get_device(network);
+	struct wifi_data *wifi;
+
+	DBG("network %p", network);
+
+	wifi = connman_device_get_data(device);
+	if (wifi_link_removed(wifi))
+		return;
+
+	if (wifi->network != network)
+		return;
+
+	wifi->network = NULL;
+}
+
+static void connect_callback(int result, GSupplicantInterface *interface,
+							void *user_data)
+{
+	struct connman_network *network = user_data;
+
+	DBG("network %p result %d", network, result);
+
+	if (result == -ENOKEY) {
+		connman_network_set_error(network,
+					CONNMAN_NETWORK_ERROR_INVALID_KEY);
+	} else if (result < 0) {
+		connman_network_set_error(network,
+					CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
+	}
+
+	connman_network_unref(network);
+}
+
+static GSupplicantSecurity network_security(const char *security)
+{
+	if (g_str_equal(security, "none"))
+		return G_SUPPLICANT_SECURITY_NONE;
+	else if (g_str_equal(security, "wep"))
+		return G_SUPPLICANT_SECURITY_WEP;
+	else if (g_str_equal(security, "psk"))
+		return G_SUPPLICANT_SECURITY_PSK;
+	else if (g_str_equal(security, "wpa"))
+		return G_SUPPLICANT_SECURITY_PSK;
+	else if (g_str_equal(security, "rsn"))
+		return G_SUPPLICANT_SECURITY_PSK;
+	else if (g_str_equal(security, "ieee8021x"))
+		return G_SUPPLICANT_SECURITY_IEEE8021X;
+
+	return G_SUPPLICANT_SECURITY_UNKNOWN;
+}
+
+static void ssid_init(GSupplicantSSID *ssid, struct connman_network *network)
+{
+	const char *security;
+
+	memset(ssid, 0, sizeof(*ssid));
+	ssid->mode = G_SUPPLICANT_MODE_INFRA;
+	ssid->ssid = connman_network_get_blob(network, "WiFi.SSID",
+						&ssid->ssid_len);
+	ssid->scan_ssid = 1;
+	security = connman_network_get_string(network, "WiFi.Security");
+	ssid->security = network_security(security);
+	ssid->passphrase = connman_network_get_string(network,
+						"WiFi.Passphrase");
+
+	ssid->eap = connman_network_get_string(network, "WiFi.EAP");
+
+	/*
+	 * If our private key password is unset,
+	 * we use the supplied passphrase. That is needed
+	 * for PEAP where 2 passphrases (identity and client
+	 * cert may have to be provided.
+	 */
+	if (!connman_network_get_string(network, "WiFi.PrivateKeyPassphrase"))
+		connman_network_set_string(network,
+						"WiFi.PrivateKeyPassphrase",
+						ssid->passphrase);
+	/* We must have an identity for both PEAP and TLS */
+	ssid->identity = connman_network_get_string(network, "WiFi.Identity");
+
+	/* Use agent provided identity as a fallback */
+	if (!ssid->identity || strlen(ssid->identity) == 0)
+		ssid->identity = connman_network_get_string(network,
+							"WiFi.AgentIdentity");
+
+	ssid->ca_cert_path = connman_network_get_string(network,
+							"WiFi.CACertFile");
+	ssid->client_cert_path = connman_network_get_string(network,
+							"WiFi.ClientCertFile");
+	ssid->private_key_path = connman_network_get_string(network,
+							"WiFi.PrivateKeyFile");
+	ssid->private_key_passphrase = connman_network_get_string(network,
+						"WiFi.PrivateKeyPassphrase");
+	ssid->phase2_auth = connman_network_get_string(network, "WiFi.Phase2");
+
+	ssid->use_wps = connman_network_get_bool(network, "WiFi.UseWPS");
+	ssid->pin_wps = connman_network_get_string(network, "WiFi.PinWPS");
+
+	if (connman_setting_get_bool("BackgroundScanning"))
+		ssid->bgscan = BGSCAN_DEFAULT;
+}
+
+static int network_connect(struct connman_network *network)
+{
+	struct connman_device *device = connman_network_get_device(network);
+	struct wifi_data *wifi;
+	GSupplicantInterface *interface;
+	GSupplicantSSID *ssid;
+	int ret;
+
+	DBG("network %p", network);
+
+	if (!device)
+		return -ENODEV;
+
+	wifi = connman_device_get_data(device);
+	if (wifi_link_removed(wifi))
+		return -ENODEV;
+
+	ssid = g_try_malloc0(sizeof(GSupplicantSSID));
+	if (!ssid)
+		return -ENOMEM;
+
+	interface = wifi->interface;
+
+	ssid_init(ssid, network);
+
+	if (wifi->disconnecting) {
+		wifi->pending_network = network;
+		g_free(ssid);
+	} else {
+		wifi->network = connman_network_ref(network);
+		wifi->retries = 0;
+
+		ret = g_supplicant_interface_connect(interface, ssid,
+						connect_callback, network);
+
+		if (ret < 0 && ret != -EINPROGRESS) {
+			connman_network_unref(network);
+		}
+
+		return ret;
+	}
+
+	return -EINPROGRESS;
+}
+
+static void disconnect_callback(int result, GSupplicantInterface *interface,
+								void *user_data)
+{
+	struct wifi_data *wifi = user_data;
+
+	DBG("result %d supplicant interface %p wifi %p",
+			result, interface, wifi);
+
+	if (wifi_link_removed(wifi))
+		return;
+
+	if (result == -ECONNABORTED) {
+		DBG("wifi interface no longer available");
+		goto done;
+	}
+
+	if (wifi->network) {
+		/*
+		 * if result < 0 supplican return an error because
+		 * the network is not current.
+		 * we wont receive G_SUPPLICANT_STATE_DISCONNECTED since it
+		 * failed, call connman_network_set_connected to report
+		 * disconnect is completed.
+		 */
+		if (result < 0)
+			connman_network_set_connected(wifi->network, false);
+	}
+
+	wifi->network = NULL;
+
+	wifi->disconnecting = false;
+
+	if (wifi->pending_network) {
+		network_connect(wifi->pending_network);
+		wifi->pending_network = NULL;
+	}
+
+	start_autoscan(wifi->device);
+
+done:
+	wifi_data_unref(wifi);
+}
+
+static int network_disconnect(struct connman_network *network, bool user_initiated)
+{
+	struct connman_device *device = connman_network_get_device(network);
+	struct wifi_data *wifi;
+	int err;
+
+	DBG("network %p", network);
+
+	wifi = connman_device_get_data(device);
+	if (!wifi || !wifi->interface)
+		return -ENODEV;
+
+	connman_network_set_associating(network, false);
+
+	if (wifi->disconnecting)
+		return -EALREADY;
+
+	wifi->disconnecting = true;
+
+	wifi_data_ref(wifi);
+	err = g_supplicant_interface_disconnect(wifi->interface,
+						disconnect_callback, wifi);
+	if (err < 0) {
+		wifi->disconnecting = false;
+		wifi_data_unref(wifi);
+	}
+
+	return err;
+}
+
+static struct connman_network_driver network_driver = {
+	.name		= "wifi",
+	.type		= CONNMAN_NETWORK_TYPE_WIFI,
+	.priority	= CONNMAN_NETWORK_PRIORITY_LOW,
+	.probe		= network_probe,
+	.remove		= network_remove,
+	.connect	= network_connect,
+	.disconnect	= network_disconnect,
+};
+
+static void interface_added(GSupplicantInterface *interface)
+{
+	const char *ifname = g_supplicant_interface_get_ifname(interface);
+	const char *driver = g_supplicant_interface_get_driver(interface);
+	struct wifi_data *wifi;
+
+	wifi = g_supplicant_interface_get_data(interface);
+	if (!wifi) {
+		wifi = get_pending_wifi_data(ifname);
+		if (!wifi)
+			return;
+
+		g_supplicant_interface_set_data(interface, wifi);
+		p2p_iface_list = g_list_append(p2p_iface_list, wifi);
+		wifi->p2p_device = true;
+	}
+	/*
+	 * We can get here with a NULL wifi pointer when
+	 * the interface added signal is sent before the
+	 * interface creation callback is called.
+	 */
+	if (wifi_link_removed(wifi))
+		return;
+
+	DBG("ifname %s driver %s wifi %p tethering %d",
+			ifname, driver, wifi, wifi->tethering);
+
+	if (!wifi->device) {
+		connman_error("WiFi device not set");
+		return;
+	}
+
+	connman_device_set_powered(wifi->device, true);
+}
+
+static bool is_idle(struct wifi_data *wifi)
+{
+	DBG("state %d", wifi->state);
+
+	switch (wifi->state) {
+	case G_SUPPLICANT_STATE_UNKNOWN:
+	case G_SUPPLICANT_STATE_DISABLED:
+	case G_SUPPLICANT_STATE_DISCONNECTED:
+	case G_SUPPLICANT_STATE_INACTIVE:
+	case G_SUPPLICANT_STATE_SCANNING:
+		return true;
+
+	case G_SUPPLICANT_STATE_AUTHENTICATING:
+	case G_SUPPLICANT_STATE_ASSOCIATING:
+	case G_SUPPLICANT_STATE_ASSOCIATED:
+	case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
+	case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
+	case G_SUPPLICANT_STATE_COMPLETED:
+		return false;
+	}
+
+	return false;
+}
+
+static bool is_idle_wps(GSupplicantInterface *interface,
+						struct wifi_data *wifi)
+{
+	/* First, let's check if WPS processing did not went wrong */
+	if (g_supplicant_interface_get_wps_state(interface) ==
+		G_SUPPLICANT_WPS_STATE_FAIL)
+		return false;
+
+	/* Unlike normal connection, being associated while processing wps
+	 * actually means that we are idling. */
+	switch (wifi->state) {
+	case G_SUPPLICANT_STATE_UNKNOWN:
+	case G_SUPPLICANT_STATE_DISABLED:
+	case G_SUPPLICANT_STATE_DISCONNECTED:
+	case G_SUPPLICANT_STATE_INACTIVE:
+	case G_SUPPLICANT_STATE_SCANNING:
+	case G_SUPPLICANT_STATE_ASSOCIATED:
+		return true;
+	case G_SUPPLICANT_STATE_AUTHENTICATING:
+	case G_SUPPLICANT_STATE_ASSOCIATING:
+	case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
+	case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
+	case G_SUPPLICANT_STATE_COMPLETED:
+		return false;
+	}
+
+	return false;
+}
+
+static bool handle_wps_completion(GSupplicantInterface *interface,
+					struct connman_network *network,
+					struct connman_device *device,
+					struct wifi_data *wifi)
+{
+	bool wps;
+
+	wps = connman_network_get_bool(network, "WiFi.UseWPS");
+	if (wps) {
+		const unsigned char *ssid, *wps_ssid;
+		unsigned int ssid_len, wps_ssid_len;
+		const char *wps_key;
+		int ret;
+
+		/* Checking if we got associated with requested
+		 * network */
+		ssid = connman_network_get_blob(network, "WiFi.SSID",
+						&ssid_len);
+
+		wps_ssid = g_supplicant_interface_get_wps_ssid(
+			interface, &wps_ssid_len);
+
+		if (!wps_ssid || wps_ssid_len != ssid_len ||
+				memcmp(ssid, wps_ssid, ssid_len) != 0) {
+			connman_network_set_associating(network, false);
+
+			wifi_data_ref(wifi);
+			ret = g_supplicant_interface_disconnect(wifi->interface,
+						disconnect_callback, wifi);
+			if (ret < 0) {
+				wifi_data_unref(wifi);
+            		}
+
+			return false;
+		}
+
+		wps_key = g_supplicant_interface_get_wps_key(interface);
+		connman_network_set_string(network, "WiFi.Passphrase",
+					wps_key);
+
+		connman_network_set_string(network, "WiFi.PinWPS", NULL);
+	}
+
+	return true;
+}
+
+static bool handle_4way_handshake_failure(GSupplicantInterface *interface,
+					struct connman_network *network,
+					struct wifi_data *wifi)
+{
+	struct connman_service *service;
+
+	if (wifi->state != G_SUPPLICANT_STATE_4WAY_HANDSHAKE)
+		return false;
+
+	if (wifi->connected)
+		return false;
+
+	service = connman_service_lookup_from_network(network);
+	if (!service)
+		return false;
+
+	wifi->retries++;
+
+	if (connman_service_get_favorite(service)) {
+		if (wifi->retries < FAVORITE_MAXIMUM_RETRIES)
+			return true;
+	}
+
+	wifi->retries = 0;
+	connman_network_set_error(network, CONNMAN_NETWORK_ERROR_INVALID_KEY);
+
+	return false;
+}
+
+static void interface_state(GSupplicantInterface *interface)
+{
+	struct connman_network *network;
+	struct connman_device *device;
+	struct wifi_data *wifi;
+	GSupplicantState state = g_supplicant_interface_get_state(interface);
+	bool wps;
+	bool old_connected;
+
+	wifi = g_supplicant_interface_get_data(interface);
+
+	DBG("wifi %p interface state %d", wifi, state);
+
+	if (wifi_link_removed(wifi))
+		return;
+
+	if (state == G_SUPPLICANT_STATE_COMPLETED) {
+		if (wifi->tethering_param) {
+			g_free(wifi->tethering_param->ssid);
+			g_free(wifi->tethering_param);
+			wifi->tethering_param = NULL;
+		}
+	}
+
+	device = wifi->device;
+	if (!device)
+		return;
+
+	if (g_supplicant_interface_get_ready(interface) &&
+					!wifi->interface_ready) {
+		wifi->interface_ready = true;
+		finalize_interface_creation(wifi);
+	}
+
+	network = wifi->network;
+	if (!network)
+		return;
+
+	switch (state) {
+	case G_SUPPLICANT_STATE_SCANNING:
+		if (wifi->connected)
+			connman_network_set_connected(network, false);
+
+		break;
+
+	case G_SUPPLICANT_STATE_AUTHENTICATING:
+	case G_SUPPLICANT_STATE_ASSOCIATING:
+		stop_autoscan(device);
+
+		if (!wifi->connected)
+			connman_network_set_associating(network, true);
+
+		break;
+
+	case G_SUPPLICANT_STATE_COMPLETED:
+		/* though it should be already stopped: */
+		stop_autoscan(device);
+
+		if (!handle_wps_completion(interface, network, device, wifi))
+			break;
+
+		connman_network_set_connected(network, true);
+		break;
+
+	case G_SUPPLICANT_STATE_DISCONNECTED:
+		/*
+		 * If we're in one of the idle modes, we have
+		 * not started association yet and thus setting
+		 * those ones to FALSE could cancel an association
+		 * in progress.
+		 */
+		wps = connman_network_get_bool(network, "WiFi.UseWPS");
+		if (wps)
+			if (is_idle_wps(interface, wifi))
+				break;
+
+		if (is_idle(wifi))
+			break;
+
+		/* If previous state was 4way-handshake, then
+		 * it's either: psk was incorrect and thus we retry
+		 * or if we reach the maximum retries we declare the
+		 * psk as wrong */
+		if (handle_4way_handshake_failure(interface,
+						network, wifi))
+			break;
+
+		/* We disable the selected network, if not then
+		 * wpa_supplicant will loop retrying */
+		if (g_supplicant_interface_enable_selected_network(interface,
+						FALSE) != 0)
+			DBG("Could not disables selected network");
+
+		connman_network_set_connected(network, false);
+		connman_network_set_associating(network, false);
+		wifi->disconnecting = false;
+
+		start_autoscan(device);
+
+		break;
+
+	case G_SUPPLICANT_STATE_INACTIVE:
+		connman_network_set_associating(network, false);
+		start_autoscan(device);
+
+		break;
+
+	case G_SUPPLICANT_STATE_UNKNOWN:
+	case G_SUPPLICANT_STATE_DISABLED:
+	case G_SUPPLICANT_STATE_ASSOCIATED:
+	case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
+	case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
+		break;
+	}
+
+	old_connected = wifi->connected;
+	wifi->state = state;
+
+	/* Saving wpa_s state policy:
+	 * If connected and if the state changes are roaming related:
+	 * --> We stay connected
+	 * If completed
+	 * --> We are connected
+	 * All other case:
+	 * --> We are not connected
+	 * */
+	switch (state) {
+	case G_SUPPLICANT_STATE_AUTHENTICATING:
+	case G_SUPPLICANT_STATE_ASSOCIATING:
+	case G_SUPPLICANT_STATE_ASSOCIATED:
+	case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
+	case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
+		if (wifi->connected)
+			connman_warn("Probably roaming right now!"
+						" Staying connected...");
+		else
+			wifi->connected = false;
+		break;
+	case G_SUPPLICANT_STATE_SCANNING:
+		wifi->connected = false;
+
+		if (old_connected)
+			start_autoscan(device);
+		break;
+	case G_SUPPLICANT_STATE_COMPLETED:
+		wifi->connected = true;
+		break;
+	default:
+		wifi->connected = false;
+		break;
+	}
+
+	DBG("DONE");
+}
+
+static void interface_removed(GSupplicantInterface *interface)
+{
+	const char *ifname = g_supplicant_interface_get_ifname(interface);
+	struct wifi_data *wifi;
+
+	DBG("ifname %s", ifname);
+
+	wifi = g_supplicant_interface_get_data(interface);
+
+	if (wifi)
+		wifi->interface = NULL;
+
+	if (wifi && wifi->tethering)
+		return;
+
+	if (!wifi || !wifi->device) {
+		DBG("wifi interface already removed");
+		return;
+	}
+
+	if (wifi->tethering || wifi->shutting_down)
+		return;
+
+	wifi->interface = NULL;
+	connman_device_set_powered(wifi->device, false);
+
+	check_p2p_technology();
+}
+
+static void set_device_type(const char *type, char dev_type[17])
+{
+	const char *oui = "0050F204";
+	const char *category = "0001";
+	const char *sub_category = "0000";
+
+	if (!g_strcmp0(type, "handset")) {
+		category = "000A";
+		sub_category = "0005";
+	} else if (!g_strcmp0(type, "vm") || !g_strcmp0(type, "container"))
+		sub_category = "0001";
+	else if (!g_strcmp0(type, "server"))
+		sub_category = "0002";
+	else if (!g_strcmp0(type, "laptop"))
+		sub_category = "0005";
+	else if (!g_strcmp0(type, "desktop"))
+		sub_category = "0006";
+	else if (!g_strcmp0(type, "tablet"))
+		sub_category = "0009";
+	else if (!g_strcmp0(type, "watch"))
+		category = "00FF";
+
+	snprintf(dev_type, 17, "%s%s%s", category, oui, sub_category);
+}
+
+static void p2p_support(GSupplicantInterface *interface)
+{
+	char dev_type[17] = {};
+	const char *hostname;
+
+	DBG("");
+
+	if (!g_supplicant_interface_has_p2p(interface))
+		return;
+
+	if (connman_technology_driver_register(&p2p_tech_driver) < 0) {
+		DBG("Could not register P2P technology driver");
+		return;
+	}
+
+	hostname = connman_utsname_get_hostname();
+	if (!hostname)
+		hostname = "ConnMan";
+
+	set_device_type(connman_machine_get_type(), dev_type);
+	g_supplicant_interface_set_p2p_device_config(interface,
+							hostname, dev_type);
+	connman_peer_driver_register(&peer_driver);
+}
+
+static void scan_started(GSupplicantInterface *interface)
+{
+	DBG("");
+}
+
+static void scan_finished(GSupplicantInterface *interface)
+{
+	DBG("");
+}
+
+static void ap_create_fail(GSupplicantInterface *interface)
+{
+	struct wifi_data *wifi = g_supplicant_interface_get_data(interface);
+	int ret;
+
+	if ((wifi->tethering) && (wifi->tethering_param)) {
+		DBG("%s create AP fail \n",
+				g_supplicant_interface_get_ifname(wifi->interface));
+
+		connman_inet_remove_from_bridge(wifi->index, wifi->bridge);
+		wifi->ap_supported = WIFI_AP_NOT_SUPPORTED;
+		wifi->tethering = false;
+
+		ret = tech_set_tethering(wifi->tethering_param->technology,
+				wifi->tethering_param->ssid->ssid,
+				wifi->tethering_param->ssid->passphrase,
+				wifi->bridge, true);
+
+		if ((ret == -EOPNOTSUPP) && (wifi_technology)) {
+			connman_technology_tethering_notify(wifi_technology,false);
+		}
+
+		g_free(wifi->tethering_param->ssid);
+		g_free(wifi->tethering_param);
+		wifi->tethering_param = NULL;
+	}
+
+	return;
+}
+
+static unsigned char calculate_strength(GSupplicantNetwork *supplicant_network)
+{
+	unsigned char strength;
+
+	strength = 120 + g_supplicant_network_get_signal(supplicant_network);
+	if (strength > 100)
+		strength = 100;
+
+	return strength;
+}
+
+static void network_added(GSupplicantNetwork *supplicant_network)
+{
+	struct connman_network *network;
+	GSupplicantInterface *interface;
+	struct wifi_data *wifi;
+	const char *name, *identifier, *security, *group, *mode;
+	const unsigned char *ssid;
+	unsigned int ssid_len;
+	bool wps;
+	bool wps_pbc;
+	bool wps_ready;
+	bool wps_advertizing;
+
+	mode = g_supplicant_network_get_mode(supplicant_network);
+	identifier = g_supplicant_network_get_identifier(supplicant_network);
+
+	DBG("%s", identifier);
+
+	if (!g_strcmp0(mode, "adhoc"))
+		return;
+
+	interface = g_supplicant_network_get_interface(supplicant_network);
+	wifi = g_supplicant_interface_get_data(interface);
+
+	if (wifi_link_removed(wifi))
+		return;
+
+	name = g_supplicant_network_get_name(supplicant_network);
+	security = g_supplicant_network_get_security(supplicant_network);
+	group = g_supplicant_network_get_identifier(supplicant_network);
+	wps = g_supplicant_network_get_wps(supplicant_network);
+	wps_pbc = g_supplicant_network_is_wps_pbc(supplicant_network);
+	wps_ready = g_supplicant_network_is_wps_active(supplicant_network);
+	wps_advertizing = g_supplicant_network_is_wps_advertizing(
+							supplicant_network);
+
+	ssid = g_supplicant_network_get_ssid(supplicant_network, &ssid_len);
+
+	network = connman_device_get_network(wifi->device, identifier);
+
+	if (!network) {
+		network = connman_network_create(identifier,
+						CONNMAN_NETWORK_TYPE_WIFI);
+		if (!network)
+			return;
+
+		connman_network_set_index(network, wifi->index);
+
+		if (connman_device_add_network(wifi->device, network) < 0) {
+			connman_network_unref(network);
+			return;
+		}
+
+		wifi->networks = g_slist_prepend(wifi->networks, network);
+	}
+
+	if (name && name[0] != '\0')
+		connman_network_set_name(network, name);
+
+	connman_network_set_blob(network, "WiFi.SSID",
+						ssid, ssid_len);
+	connman_network_set_string(network, "WiFi.Security", security);
+	connman_network_set_strength(network,
+				calculate_strength(supplicant_network));
+	connman_network_set_bool(network, "WiFi.WPS", wps);
+
+	if (wps) {
+		/* Is AP advertizing for WPS association?
+		 * If so, we decide to use WPS by default */
+		if (wps_ready && wps_pbc &&
+						wps_advertizing)
+			connman_network_set_bool(network, "WiFi.UseWPS", true);
+	}
+
+	connman_network_set_frequency(network,
+			g_supplicant_network_get_frequency(supplicant_network));
+
+	connman_network_set_available(network, true);
+	connman_network_set_string(network, "WiFi.Mode", mode);
+
+	if (ssid)
+		connman_network_set_group(network, group);
+
+	if (wifi->hidden && ssid) {
+		if (!g_strcmp0(wifi->hidden->security, security) &&
+				wifi->hidden->ssid_len == ssid_len &&
+				!memcmp(wifi->hidden->ssid, ssid, ssid_len)) {
+			connman_network_connect_hidden(network,
+					wifi->hidden->identity,
+					wifi->hidden->passphrase,
+					wifi->hidden->user_data);
+			wifi->hidden->user_data = NULL;
+			hidden_free(wifi->hidden);
+			wifi->hidden = NULL;
+		}
+	}
+}
+
+static void network_removed(GSupplicantNetwork *network)
+{
+	GSupplicantInterface *interface;
+	struct wifi_data *wifi;
+	const char *name, *identifier;
+	struct connman_network *connman_network;
+
+	interface = g_supplicant_network_get_interface(network);
+	wifi = g_supplicant_interface_get_data(interface);
+	identifier = g_supplicant_network_get_identifier(network);
+	name = g_supplicant_network_get_name(network);
+
+	DBG("name %s", name);
+
+	if (wifi_link_removed(wifi))
+		return;
+        
+	if (wifi->device == NULL)
+		return;
+
+	connman_network = connman_device_get_network(wifi->device, identifier);
+	if (!connman_network)
+		return;
+
+	wifi->networks = g_slist_remove(wifi->networks, connman_network);
+
+	connman_device_remove_network(wifi->device, connman_network);
+	connman_network_unref(connman_network);
+}
+
+static void network_changed(GSupplicantNetwork *network, const char *property)
+{
+	GSupplicantInterface *interface;
+	struct wifi_data *wifi;
+	const char *name, *identifier;
+	struct connman_network *connman_network;
+
+	interface = g_supplicant_network_get_interface(network);
+	wifi = g_supplicant_interface_get_data(interface);
+	identifier = g_supplicant_network_get_identifier(network);
+	name = g_supplicant_network_get_name(network);
+
+	DBG("name %s", name);
+
+	if (wifi_link_removed(wifi))
+		return;
+        
+	if (wifi->device == NULL)
+		return;
+
+	connman_network = connman_device_get_network(wifi->device, identifier);
+	if (!connman_network)
+		return;
+
+	if (g_str_equal(property, "Signal")) {
+		   connman_network_set_strength(connman_network,
+					calculate_strength(network));
+		   connman_network_update(connman_network);
+	}
+}
+
+static void apply_peer_services(GSupplicantPeer *peer,
+				struct connman_peer *connman_peer)
+{
+	const unsigned char *data;
+	int length;
+
+	DBG("");
+
+	connman_peer_reset_services(connman_peer);
+
+	data = g_supplicant_peer_get_widi_ies(peer, &length);
+	if (data) {
+		connman_peer_add_service(connman_peer,
+			CONNMAN_PEER_SERVICE_WIFI_DISPLAY, data, length);
+	}
+}
+
+static void peer_found(GSupplicantPeer *peer)
+{
+	GSupplicantInterface *iface = g_supplicant_peer_get_interface(peer);
+	struct wifi_data *wifi = g_supplicant_interface_get_data(iface);
+	struct connman_peer *connman_peer;
+	const char *identifier, *name;
+	int ret;
+
+	identifier = g_supplicant_peer_get_identifier(peer);
+	name = g_supplicant_peer_get_name(peer);
+
+	DBG("ident: %s", identifier);
+
+	connman_peer = connman_peer_get(wifi->device, identifier);
+	if (connman_peer)
+		return;
+
+	connman_peer = connman_peer_create(identifier);
+	connman_peer_set_name(connman_peer, name);
+	connman_peer_set_device(connman_peer, wifi->device);
+	apply_peer_services(peer, connman_peer);
+
+	ret = connman_peer_register(connman_peer);
+	if (ret < 0 && ret != -EALREADY)
+		connman_peer_unref(connman_peer);
+}
+
+static void peer_lost(GSupplicantPeer *peer)
+{
+	GSupplicantInterface *iface = g_supplicant_peer_get_interface(peer);
+	struct wifi_data *wifi = g_supplicant_interface_get_data(iface);
+	struct connman_peer *connman_peer;
+	const char *identifier;
+
+	if (!wifi)
+		return;
+
+	identifier = g_supplicant_peer_get_identifier(peer);
+
+	DBG("ident: %s", identifier);
+
+	connman_peer = connman_peer_get(wifi->device, identifier);
+	if (connman_peer) {
+		if (wifi->p2p_connecting &&
+				wifi->pending_peer == connman_peer) {
+			peer_connect_timeout(wifi);
+		}
+		connman_peer_unregister(connman_peer);
+		connman_peer_unref(connman_peer);
+	}
+}
+
+static void peer_changed(GSupplicantPeer *peer, GSupplicantPeerState state)
+{
+	GSupplicantInterface *iface = g_supplicant_peer_get_interface(peer);
+	struct wifi_data *wifi = g_supplicant_interface_get_data(iface);
+	enum connman_peer_state p_state = CONNMAN_PEER_STATE_UNKNOWN;
+	struct connman_peer *connman_peer;
+	const char *identifier;
+
+	identifier = g_supplicant_peer_get_identifier(peer);
+
+	DBG("ident: %s", identifier);
+
+	connman_peer = connman_peer_get(wifi->device, identifier);
+	if (!connman_peer)
+		return;
+
+	switch (state) {
+	case G_SUPPLICANT_PEER_SERVICES_CHANGED:
+		apply_peer_services(peer, connman_peer);
+		connman_peer_services_changed(connman_peer);
+		return;
+	case G_SUPPLICANT_PEER_GROUP_CHANGED:
+		if (!g_supplicant_peer_is_in_a_group(peer))
+			p_state = CONNMAN_PEER_STATE_IDLE;
+		else
+			p_state = CONNMAN_PEER_STATE_CONFIGURATION;
+		break;
+	case G_SUPPLICANT_PEER_GROUP_STARTED:
+		break;
+	case G_SUPPLICANT_PEER_GROUP_FINISHED:
+		p_state = CONNMAN_PEER_STATE_IDLE;
+		break;
+	case G_SUPPLICANT_PEER_GROUP_JOINED:
+		connman_peer_set_iface_address(connman_peer,
+				g_supplicant_peer_get_iface_address(peer));
+		break;
+	case G_SUPPLICANT_PEER_GROUP_DISCONNECTED:
+		p_state = CONNMAN_PEER_STATE_IDLE;
+		break;
+	case G_SUPPLICANT_PEER_GROUP_FAILED:
+		if (g_supplicant_peer_has_requested_connection(peer))
+			p_state = CONNMAN_PEER_STATE_IDLE;
+		else
+			p_state = CONNMAN_PEER_STATE_FAILURE;
+		break;
+	}
+
+	if (p_state == CONNMAN_PEER_STATE_CONFIGURATION ||
+					p_state == CONNMAN_PEER_STATE_FAILURE) {
+		if (wifi->p2p_connecting
+				&& connman_peer == wifi->pending_peer)
+			peer_cancel_timeout(wifi);
+		else
+			p_state = CONNMAN_PEER_STATE_UNKNOWN;
+	}
+
+	if (p_state == CONNMAN_PEER_STATE_UNKNOWN)
+		return;
+
+	if (p_state == CONNMAN_PEER_STATE_CONFIGURATION) {
+		GSupplicantInterface *g_iface;
+		struct wifi_data *g_wifi;
+
+		g_iface = g_supplicant_peer_get_group_interface(peer);
+		if (!g_iface)
+			return;
+
+		g_wifi = g_supplicant_interface_get_data(g_iface);
+		if (!g_wifi)
+			return;
+
+		connman_peer_set_as_master(connman_peer,
+					!g_supplicant_peer_is_client(peer));
+		connman_peer_set_sub_device(connman_peer, g_wifi->device);
+	}
+
+	connman_peer_set_state(connman_peer, p_state);
+}
+
+static void peer_request(GSupplicantPeer *peer)
+{
+	GSupplicantInterface *iface = g_supplicant_peer_get_interface(peer);
+	struct wifi_data *wifi = g_supplicant_interface_get_data(iface);
+	struct connman_peer *connman_peer;
+	const char *identifier;
+
+	identifier = g_supplicant_peer_get_identifier(peer);
+
+	DBG("ident: %s", identifier);
+
+	connman_peer = connman_peer_get(wifi->device, identifier);
+	if (!connman_peer)
+		return;
+
+	connman_peer_request_connection(connman_peer);
+}
+
+static void debug(const char *str)
+{
+	if (getenv("CONNMAN_SUPPLICANT_DEBUG"))
+		connman_debug("%s", str);
+}
+
+static const GSupplicantCallbacks callbacks = {
+	.system_ready		= system_ready,
+	.system_killed		= system_killed,
+	.interface_added	= interface_added,
+	.interface_state	= interface_state,
+	.interface_removed	= interface_removed,
+	.p2p_support		= p2p_support,
+	.scan_started		= scan_started,
+	.scan_finished		= scan_finished,
+	.ap_create_fail		= ap_create_fail,
+	.network_added		= network_added,
+	.network_removed	= network_removed,
+	.network_changed	= network_changed,
+	.peer_found		= peer_found,
+	.peer_lost		= peer_lost,
+	.peer_changed		= peer_changed,
+	.peer_request		= peer_request,
+	.debug			= debug,
+};
+
+
+static int tech_probe(struct connman_technology *technology)
+{
+	wifi_technology = technology;
+
+	return 0;
+}
+
+static void tech_remove(struct connman_technology *technology)
+{
+	wifi_technology = NULL;
+}
+
+static GSupplicantSSID *ssid_ap_init(const char *ssid, const char *passphrase)
+{
+	GSupplicantSSID *ap;
+
+	ap = g_try_malloc0(sizeof(GSupplicantSSID));
+	if (!ap)
+		return NULL;
+
+	ap->mode = G_SUPPLICANT_MODE_MASTER;
+	ap->ssid = ssid;
+	ap->ssid_len = strlen(ssid);
+	ap->scan_ssid = 0;
+	ap->freq = 2412;
+
+	if (!passphrase || strlen(passphrase) == 0) {
+		ap->security = G_SUPPLICANT_SECURITY_NONE;
+		ap->passphrase = NULL;
+	} else {
+		   ap->security = G_SUPPLICANT_SECURITY_PSK;
+		   ap->protocol = G_SUPPLICANT_PROTO_RSN;
+		   ap->pairwise_cipher = G_SUPPLICANT_PAIRWISE_CCMP;
+		   ap->group_cipher = G_SUPPLICANT_GROUP_CCMP;
+		   ap->passphrase = passphrase;
+	}
+
+	return ap;
+}
+
+static void ap_start_callback(int result, GSupplicantInterface *interface,
+							void *user_data)
+{
+	struct wifi_tethering_info *info = user_data;
+
+	if (!info->wifi || info->wifi->shutting_down)
+		goto done;
+
+	DBG("result %d index %d bridge %s",
+		result, info->wifi->index, info->wifi->bridge);
+
+	if ((result < 0) || (info->wifi->ap_supported != WIFI_AP_SUPPORTED)) {
+		connman_inet_remove_from_bridge(info->wifi->index,
+							info->wifi->bridge);
+
+		if (info->wifi->ap_supported == WIFI_AP_SUPPORTED) {
+			connman_technology_tethering_notify(info->technology, false);
+			g_free(info->wifi->tethering_param->ssid);
+			g_free(info->wifi->tethering_param);
+			info->wifi->tethering_param = NULL;
+		}
+	}
+
+done:
+	wifi_data_unref(info->wifi);
+	g_free(info->ifname);
+	g_free(info);
+}
+
+static void ap_create_callback(int result,
+				GSupplicantInterface *interface,
+					void *user_data)
+{
+	struct wifi_tethering_info *info = user_data;
+
+	DBG("result %d ifname %s", result,
+				g_supplicant_interface_get_ifname(interface));
+
+	if ((result < 0) || (info->wifi->ap_supported != WIFI_AP_SUPPORTED)) {
+		connman_inet_remove_from_bridge(info->wifi->index,
+						info->wifi->bridge);
+
+		if (info->wifi->ap_supported == WIFI_AP_SUPPORTED) {
+			connman_technology_tethering_notify(info->technology, false);
+		
+			g_free(info->wifi->tethering_param->ssid);
+			g_free(info->wifi->tethering_param);
+			info->wifi->tethering_param = NULL;
+		}
+		g_free(info->ifname);
+		g_free(info->ssid);
+		g_free(info);
+		return;
+	}
+
+	info->wifi->interface = interface;
+	g_supplicant_interface_set_data(interface, info->wifi);
+
+	if (g_supplicant_interface_set_apscan(interface, 2) < 0)
+		connman_error("Failed to set interface ap_scan property");
+
+	g_supplicant_interface_connect(interface, info->ssid,
+						ap_start_callback, info);
+}
+
+static void sta_remove_callback(int result,
+				GSupplicantInterface *interface,
+					void *user_data)
+{
+	struct wifi_tethering_info *info = user_data;
+	const char *driver = connman_option_get_string("wifi");
+
+	DBG("ifname %s result %d ", info->ifname, result);
+
+	if ((result < 0) || (info->wifi->ap_supported != WIFI_AP_SUPPORTED)) {
+		info->wifi->tethering = true;
+	
+		g_free(info->ifname);
+		g_free(info->ssid);
+		g_free(info);
+
+		if (info->wifi->ap_supported == WIFI_AP_SUPPORTED) {
+			g_free(info->wifi->tethering_param->ssid);
+			g_free(info->wifi->tethering_param);
+			info->wifi->tethering_param = NULL;
+		}
+		return;
+	}
+
+	info->wifi->interface = NULL;
+
+	connman_technology_tethering_notify(info->technology, true);
+
+	g_supplicant_interface_create(info->ifname, driver, 
+            info->wifi->bridge,	ap_create_callback, info);
+}
+
+static int tech_set_tethering(struct connman_technology *technology,
+				const char *identifier, const char *passphrase,
+				const char *bridge, bool enabled)
+{
+	GList *list;
+	GSupplicantInterface *interface;
+	struct wifi_data *wifi;
+	struct wifi_tethering_info *info;
+	const char *ifname;
+	unsigned int mode;
+	int err;
+
+	DBG("");
+
+	if (!enabled) {
+		for (list = iface_list; list; list = list->next) {
+			wifi = list->data;
+
+			if (wifi->tethering) {
+				wifi->tethering = false;
+
+				connman_inet_remove_from_bridge(wifi->index,
+									bridge);
+				wifi->bridged = false;
+			}
+		}
+
+		connman_technology_tethering_notify(technology, false);
+
+		return 0;
+	}
+
+	for (list = iface_list; list; list = list->next) {
+		wifi = list->data;
+
+		interface = wifi->interface;
+
+		if (!interface)
+			continue;
+
+		if (wifi->ap_supported == WIFI_AP_NOT_SUPPORTED)
+			continue;
+
+		ifname = g_supplicant_interface_get_ifname(wifi->interface);
+
+		mode = g_supplicant_interface_get_mode(interface);
+		if ((mode & G_SUPPLICANT_CAPABILITY_MODE_AP) == 0) {
+			wifi->ap_supported = WIFI_AP_NOT_SUPPORTED;
+			DBG("%s does not support AP mode", ifname);
+			continue;
+		}
+
+		info = g_try_malloc0(sizeof(struct wifi_tethering_info));
+		if (!info)
+			return -ENOMEM;
+
+		wifi->tethering_param = g_try_malloc0(sizeof(struct wifi_tethering_info));
+		if (!wifi->tethering_param) {
+			g_free(info);
+			return -ENOMEM;
+		}
+
+		info->wifi = wifi;
+		info->technology = technology;
+		info->wifi->bridge = bridge;
+		info->ssid = ssid_ap_init(identifier, passphrase);
+		if (!info->ssid) {
+			g_free(info);
+			g_free(wifi->tethering_param);
+			wifi->tethering_param = NULL;
+			continue;
+		}
+		info->ifname = g_strdup(ifname);
+		if (!info->ifname) {
+			g_free(info->ssid);
+			g_free(wifi->tethering_param);
+			g_free(info);
+			wifi->tethering_param = NULL;
+			continue;
+		}
+
+		wifi->tethering_param->technology = technology;
+		wifi->tethering_param->ssid = ssid_ap_init(identifier, passphrase);
+		if (!wifi->tethering_param->ssid) {
+			g_free(info->ifname);
+			g_free(info->ssid);
+			g_free(wifi->tethering_param);
+			g_free(info);
+			wifi->tethering_param = NULL;
+			continue;
+		}
+
+		info->wifi->tethering = true;
+		info->wifi->ap_supported = WIFI_AP_SUPPORTED;
+
+		/* Add ref for duration of GSupplicant DBus call(s) */
+		wifi_data_ref(info->wifi);
+
+		err = g_supplicant_interface_remove(interface,
+						sta_remove_callback,
+							info);
+		if (err == 0)
+			return err;
+		else
+			wifi_data_unref(info->wifi);
+	}
+
+	return -EOPNOTSUPP;
+}
+
+static void regdom_callback(int result, const char *alpha2, void *user_data)
+{
+	DBG("");
+
+	if (!wifi_technology)
+		return;
+
+	if (result != 0)
+		alpha2 = NULL;
+
+	connman_technology_regdom_notify(wifi_technology, alpha2);
+}
+
+static int tech_set_regdom(struct connman_technology *technology, const char *alpha2)
+{
+	return g_supplicant_set_country(alpha2, regdom_callback, NULL);
+}
+
+static struct connman_technology_driver tech_driver = {
+	.name		= "wifi",
+	.type		= CONNMAN_SERVICE_TYPE_WIFI,
+	.probe		= tech_probe,
+	.remove		= tech_remove,
+	.set_tethering	= tech_set_tethering,
+	.set_regdom	= tech_set_regdom,
+};
+
+static int wifi_init(void)
+{
+	int err;
+
+	err = connman_network_driver_register(&network_driver);
+	if (err < 0)
+		return err;
+
+	err = g_supplicant_register(&callbacks);
+	if (err < 0) {
+		connman_network_driver_unregister(&network_driver);
+		return err;
+	}
+
+	err = connman_technology_driver_register(&tech_driver);
+	if (err < 0) {
+		g_supplicant_unregister(&callbacks);
+		connman_network_driver_unregister(&network_driver);
+		return err;
+	}
+
+	return 0;
+}
+
+static void wifi_exit(void)
+{
+	DBG();
+
+	connman_technology_driver_unregister(&tech_driver);
+
+	g_supplicant_unregister(&callbacks);
+
+	connman_network_driver_unregister(&network_driver);
+}
+
+CONNMAN_PLUGIN_DEFINE(wifi, "WiFi interface plugin", VERSION,
+		CONNMAN_PLUGIN_PRIORITY_DEFAULT, wifi_init, wifi_exit)
diff --git a/connman/scripts/connman.in b/connman/scripts/connman.in
new file mode 100644
index 0000000..1692b95
--- /dev/null
+++ b/connman/scripts/connman.in
@@ -0,0 +1,46 @@
+#!/bin/sh
+
+DAEMON=@sbindir@/connmand
+DESC="Connection Manager"
+
+. /lib/lsb/init-functions
+
+if [ -f @sysconfdir@/default/connman ] ; then
+	. @sysconfdir@/default/connman
+fi
+
+set -e
+
+do_start() {
+	start-stop-daemon --start --oknodo --exec $DAEMON -- $DAEMON_OPTS
+}
+
+do_stop() {
+	start-stop-daemon --stop --oknodo --quiet --exec $DAEMON
+}
+
+case "$1" in
+  start)
+	log_daemon_msg "Starting $DESC"
+	do_start
+	log_end_msg $?
+	;;
+  stop)
+	log_daemon_msg "Stopping $DESC"
+	do_stop
+	log_end_msg $?
+	;;
+  restart|force-reload)
+	log_daemon_msg "Restarting $DESC"
+	do_stop
+	sleep 1
+	do_start
+	log_end_msg $?
+	;;
+  *)
+	log_success_msg "Usage: $0 {start|stop|restart|force-reload}" >&2
+	exit 1
+	;;
+esac
+
+exit 0
diff --git a/connman/scripts/libppp-plugin.c b/connman/scripts/libppp-plugin.c
new file mode 100644
index 0000000..0dd8b47
--- /dev/null
+++ b/connman/scripts/libppp-plugin.c
@@ -0,0 +1,317 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2012-2013  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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <pppd/pppd.h>
+#include <pppd/fsm.h>
+#include <pppd/ipcp.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#include <dbus/dbus.h>
+
+#define INET_ADDRES_LEN (INET_ADDRSTRLEN + 5)
+#define INET_DNS_LEN	(2*INET_ADDRSTRLEN + 9)
+
+static char *busname;
+static char *interface;
+static char *path;
+
+static DBusConnection *connection;
+static int prev_phase;
+
+char pppd_version[] = VERSION;
+
+int plugin_init(void);
+
+static void append(DBusMessageIter *dict, const char *key, const char *value)
+{
+	DBusMessageIter entry;
+
+	/* We clean the environment before invoking pppd, but
+	 * might as well still filter out the few things that get
+	 * added that we're not interested in
+	 */
+	if (!strcmp(key, "PWD") || !strcmp(key, "_") ||
+			!strcmp(key, "SHLVL") ||
+			!strcmp(key, "connman_busname") ||
+			!strcmp(key, "connman_network"))
+		return;
+
+	dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
+							NULL, &entry);
+
+	dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
+
+	dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &value);
+
+	dbus_message_iter_close_container(dict, &entry);
+}
+
+
+static int ppp_have_secret(void)
+{
+	return 1;
+}
+
+static int ppp_get_secret(char *username, char *password)
+{
+	DBusMessage *msg, *reply;
+	const char *user, *pass;
+	DBusError err;
+
+	if (!username && !password)
+		return -1;
+
+	if (!password)
+		return 1;
+
+	if (!connection)
+		return -1;
+
+	dbus_error_init(&err);
+
+	msg = dbus_message_new_method_call(busname, path, interface, "getsec");
+	if (!msg)
+		return -1;
+
+	dbus_message_append_args(msg, DBUS_TYPE_INVALID, DBUS_TYPE_INVALID);
+
+	reply = dbus_connection_send_with_reply_and_block(connection,
+								msg, -1, &err);
+	if (!reply) {
+		if (dbus_error_is_set(&err))
+			dbus_error_free(&err);
+
+		dbus_message_unref(msg);
+		return -1;
+	}
+
+	dbus_message_unref(msg);
+
+	dbus_error_init(&err);
+
+	if (!dbus_message_get_args(reply, &err, DBUS_TYPE_STRING, &user,
+					DBUS_TYPE_STRING, &pass,
+					DBUS_TYPE_INVALID)) {
+		if (dbus_error_is_set(&err))
+			dbus_error_free(&err);
+
+		dbus_message_unref(reply);
+		return -1;
+	}
+
+	if (username)
+		strcpy(username, user);
+
+	strcpy(password, pass);
+
+	dbus_message_unref(reply);
+
+	return 1;
+}
+
+static void ppp_up(void *data, int arg)
+{
+	char buf[INET_ADDRES_LEN];
+	char dns[INET_DNS_LEN];
+	const char *reason = "connect";
+	bool add_blank = FALSE;
+	DBusMessageIter iter, dict;
+	DBusMessage *msg;
+
+	if (!connection)
+		return;
+
+	if (ipcp_gotoptions[0].ouraddr == 0)
+		return;
+
+	msg = dbus_message_new_method_call(busname, path,
+						interface, "notify");
+	if (!msg)
+		return;
+
+	dbus_message_set_no_reply(msg, TRUE);
+
+	dbus_message_append_args(msg,
+			DBUS_TYPE_STRING, &reason, DBUS_TYPE_INVALID);
+
+	dbus_message_iter_init_append(msg, &iter);
+
+	dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
+			DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+			DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_STRING_AS_STRING
+			DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict);
+
+	append(&dict, "INTERNAL_IFNAME", ifname);
+
+	inet_ntop(AF_INET, &ipcp_gotoptions[0].ouraddr, buf, INET_ADDRSTRLEN);
+	append(&dict, "INTERNAL_IP4_ADDRESS", buf);
+
+	strcpy(buf, "255.255.255.255");
+	append(&dict, "INTERNAL_IP4_NETMASK", buf);
+
+	if (ipcp_gotoptions[0].dnsaddr[0] || ipcp_gotoptions[0].dnsaddr[1]) {
+		memset(dns, 0, sizeof(dns));
+		dns[0] = '\0';
+
+		if (ipcp_gotoptions[0].dnsaddr[0]) {
+			inet_ntop(AF_INET, &ipcp_gotoptions[0].dnsaddr[0],
+							buf, INET_ADDRSTRLEN);
+			strcat(dns, buf);
+
+			add_blank = TRUE;
+		}
+
+		if (ipcp_gotoptions[0].dnsaddr[1]) {
+			inet_ntop(AF_INET, &ipcp_gotoptions[0].dnsaddr[1],
+							buf, INET_ADDRSTRLEN);
+			if (add_blank)
+				strcat(dns, " ");
+
+			strcat(dns, buf);
+		}
+		append(&dict, "INTERNAL_IP4_DNS", dns);
+	}
+
+	append(&dict, "MTU", "1400");
+
+	dbus_message_iter_close_container(&iter, &dict);
+
+	dbus_connection_send(connection, msg, NULL);
+
+	dbus_connection_flush(connection);
+
+	dbus_message_unref(msg);
+}
+
+static void ppp_exit(void *data, int arg)
+{
+	if (connection) {
+		dbus_connection_unref(connection);
+		connection = NULL;
+	}
+
+	if (busname) {
+		free(busname);
+		busname = NULL;
+	}
+
+	if (interface) {
+		free(interface);
+		interface = NULL;
+	}
+
+	if (path) {
+		free(path);
+		path = NULL;
+	}
+}
+
+static void ppp_phase_change(void *data, int arg)
+{
+	const char *reason = "disconnect";
+	DBusMessage *msg;
+	int send_msg = 0;
+
+	if (!connection)
+		return;
+
+	if (prev_phase == PHASE_AUTHENTICATE &&
+				arg == PHASE_TERMINATE) {
+		reason = "auth failed";
+		send_msg = 1;
+	}
+
+	if (send_msg > 0 || arg == PHASE_DEAD || arg == PHASE_DISCONNECT) {
+		msg = dbus_message_new_method_call(busname, path,
+						interface, "notify");
+		if (!msg)
+			return;
+
+		dbus_message_set_no_reply(msg, TRUE);
+
+		dbus_message_append_args(msg,
+			DBUS_TYPE_STRING, &reason, DBUS_TYPE_INVALID);
+
+		dbus_connection_send(connection, msg, NULL);
+
+		dbus_connection_flush(connection);
+
+		dbus_message_unref(msg);
+	}
+
+	prev_phase = arg;
+}
+
+int plugin_init(void)
+{
+	DBusError error;
+	static const char *bus, *inter, *p;
+
+	dbus_error_init(&error);
+
+	bus = getenv("CONNMAN_BUSNAME");
+	inter = getenv("CONNMAN_INTERFACE");
+	p = getenv("CONNMAN_PATH");
+
+	if (!bus || !inter || !p)
+		return -1;
+
+	busname = strdup(bus);
+	interface = strdup(inter);
+	path = strdup(p);
+
+	if (!busname || !interface || !path) {
+		ppp_exit(NULL, 0);
+		return -1;
+	}
+
+	connection = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
+	if (!connection) {
+		if (dbus_error_is_set(&error))
+			dbus_error_free(&error);
+
+		ppp_exit(NULL, 0);
+		return -1;
+	}
+
+	pap_passwd_hook = ppp_get_secret;
+	chap_passwd_hook = ppp_get_secret;
+
+	chap_check_hook = ppp_have_secret;
+	pap_check_hook = ppp_have_secret;
+
+	add_notifier(&ip_up_notifier, ppp_up, NULL);
+	add_notifier(&phasechange, ppp_phase_change, NULL);
+	add_notifier(&exitnotify, ppp_exit, connection);
+
+	return 0;
+}
diff --git a/connman/scripts/openconnect-script.c b/connman/scripts/openconnect-script.c
new file mode 100644
index 0000000..5e04144
--- /dev/null
+++ b/connman/scripts/openconnect-script.c
@@ -0,0 +1,155 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2012  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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <syslog.h>
+#include <libgen.h>
+
+#include <dbus/dbus.h>
+
+extern char **environ;
+
+static void print(const char *format, ...)
+{
+	va_list ap;
+
+	va_start(ap, format);
+	vsyslog(LOG_INFO, format, ap);
+	va_end(ap);
+}
+
+static void append(DBusMessageIter *dict, const char *pattern)
+{
+	DBusMessageIter entry;
+	const char *key, *value;
+	char *delim;
+
+	delim = strchr(pattern, '=');
+	*delim = '\0';
+
+	key = pattern;
+	value = delim + 1;
+
+	/* We clean the environment before invoking openconnect, but
+	   might as well still filter out the few things that get
+	   added that we're not interested in */
+	if (!strcmp(key, "PWD") || !strcmp(key, "_") ||
+	    !strcmp(key, "SHLVL") || !strcmp(key, "connman_busname") ||
+	    !strcmp(key, "connman_network"))
+		return;
+
+	dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
+							NULL, &entry);
+
+	dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
+
+	dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &value);
+
+	dbus_message_iter_close_container(dict, &entry);
+}
+
+int main(int argc, char *argv[])
+{
+	DBusConnection *conn;
+	DBusError error;
+	DBusMessage *msg;
+	DBusMessageIter iter, dict;
+	char **envp, *busname, *reason, *interface, *path;
+	int ret = 0;
+
+	openlog(basename(argv[0]), LOG_NDELAY | LOG_PID, LOG_DAEMON);
+
+	busname = getenv("CONNMAN_BUSNAME");
+	interface = getenv("CONNMAN_INTERFACE");
+	path = getenv("CONNMAN_PATH");
+
+	reason = getenv("reason");
+
+	if (!busname || !interface || !path || !reason) {
+		print("Required environment variables not set");
+		ret = 1;
+		goto out;
+	}
+
+	if (strcmp(reason, "pre-init") == 0)
+		goto out;
+
+	dbus_error_init(&error);
+
+	conn = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
+	if (!conn) {
+		if (dbus_error_is_set(&error)) {
+			print("%s", error.message);
+			dbus_error_free(&error);
+		} else
+			print("Failed to get on system bus");
+
+		goto out;
+	}
+
+	msg = dbus_message_new_method_call(busname, path,
+						interface, "notify");
+	if (!msg) {
+		dbus_connection_unref(conn);
+		print("Failed to allocate method call");
+		goto out;
+	}
+
+	dbus_message_set_no_reply(msg, TRUE);
+
+	dbus_message_append_args(msg,
+				 DBUS_TYPE_STRING, &reason,
+				 DBUS_TYPE_INVALID);
+
+	dbus_message_iter_init_append(msg, &iter);
+
+	dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
+			DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+			DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_STRING_AS_STRING
+			DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict);
+
+	for (envp = environ; envp && *envp; envp++)
+		append(&dict, *envp);
+
+	dbus_message_iter_close_container(&iter, &dict);
+
+	if (!dbus_connection_send(conn, msg, NULL)) {
+		print("Failed to send message");
+		goto out;
+	}
+
+	dbus_connection_flush(conn);
+
+	dbus_message_unref(msg);
+
+	dbus_connection_unref(conn);
+
+out:
+	closelog();
+
+	return ret;
+}
diff --git a/connman/scripts/openvpn-script.c b/connman/scripts/openvpn-script.c
new file mode 100644
index 0000000..6ba0d29
--- /dev/null
+++ b/connman/scripts/openvpn-script.c
@@ -0,0 +1,146 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2012  Intel Corporation. All rights reserved.
+ *  Copyright (C) 2010,2012-2014  BMW Car IT GmbH.
+ *
+ *  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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <syslog.h>
+#include <libgen.h>
+
+#include <dbus/dbus.h>
+
+extern char **environ;
+
+static void print(const char *format, ...)
+{
+	va_list ap;
+
+	va_start(ap, format);
+	vsyslog(LOG_INFO, format, ap);
+	va_end(ap);
+}
+
+static void append(DBusMessageIter *dict, const char *pattern)
+{
+	DBusMessageIter entry;
+	const char *key, *value;
+	char *delim;
+
+	delim = strchr(pattern, '=');
+	*delim = '\0';
+
+	key = pattern;
+	value = delim + 1;
+
+	dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
+							NULL, &entry);
+
+	dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
+
+	dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &value);
+
+	dbus_message_iter_close_container(dict, &entry);
+}
+
+int main(int argc, char *argv[])
+{
+	DBusConnection *conn;
+	DBusError error;
+	DBusMessage *msg;
+	DBusMessageIter iter, dict;
+	char **envp, *busname, *interface, *path, *reason;
+	int ret = 0;
+
+	openlog(basename(argv[0]), LOG_NDELAY | LOG_PID, LOG_DAEMON);
+
+	busname = getenv("CONNMAN_BUSNAME");
+	interface = getenv("CONNMAN_INTERFACE");
+	path = getenv("CONNMAN_PATH");
+
+	reason = getenv("script_type");
+
+	if (!busname || !interface || !path || !reason) {
+		print("Required environment variables not set; "
+			"bus=%s iface=%s path=%s reason=%s",
+			busname, interface, path, reason);
+		ret = 1;
+		goto out;
+	}
+	dbus_error_init(&error);
+
+	conn = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
+	if (!conn) {
+		if (dbus_error_is_set(&error)) {
+			print("%s", error.message);
+			dbus_error_free(&error);
+		} else
+			print("Failed to get on system bus");
+
+		goto out;
+	}
+
+	msg = dbus_message_new_method_call(busname, path,
+						interface, "notify");
+	if (!msg) {
+		dbus_connection_unref(conn);
+		print("Failed to allocate method call");
+		goto out;
+	}
+
+	dbus_message_set_no_reply(msg, TRUE);
+
+	dbus_message_append_args(msg,
+				 DBUS_TYPE_STRING, &reason,
+				 DBUS_TYPE_INVALID);
+
+	dbus_message_iter_init_append(msg, &iter);
+
+	dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
+			DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+			DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_STRING_AS_STRING
+			DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict);
+
+	for (envp = environ; envp && *envp; envp++)
+		append(&dict, *envp);
+
+	dbus_message_iter_close_container(&iter, &dict);
+
+	if (!dbus_connection_send(conn, msg, NULL)) {
+		print("Failed to send message");
+		goto out;
+	}
+
+	dbus_connection_flush(conn);
+
+	dbus_message_unref(msg);
+
+	dbus_connection_unref(conn);
+
+out:
+	closelog();
+
+	return ret;
+}
diff --git a/connman/src/6to4.c b/connman/src/6to4.c
new file mode 100644
index 0000000..0e3a7a1
--- /dev/null
+++ b/connman/src/6to4.c
@@ -0,0 +1,492 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2011  Nokia Corporation. All rights reserved.
+ *  Copyright (C) Alexey Kuznetsov et al. from iproute2 package.
+ *
+ *  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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <net/if.h>
+#include <linux/ip.h>
+#include <linux/if_tunnel.h>
+#include <linux/netlink.h>
+#include <linux/rtnetlink.h>
+#include <sys/ioctl.h>
+#include <unistd.h>
+
+#include "connman.h"
+#include <connman/log.h>
+#include <connman/ipconfig.h>
+#include "gweb/gweb.h"
+
+static int tunnel_created;
+static int tunnel_pending;
+static char *tunnel_ip_address;
+static GWeb *web;
+static guint web_request_id;
+static unsigned int newlink_watch;
+static unsigned int newlink_flags;
+static int newlink_timeout_id;
+
+#define STATUS_URL "http://ipv6.connman.net/online/status.html"
+
+#ifndef IP_DF
+#define IP_DF		0x4000		/* Flag: "Don't Fragment"	*/
+#endif
+
+static int tunnel_create(struct in_addr *addr)
+{
+	struct ip_tunnel_parm p;
+	struct ifreq ifr;
+	int fd = -1;
+	int ret;
+
+	/* ip tunnel add tun6to4 mode sit remote any local 1.2.3.4 ttl 64 */
+
+	memset(&p, 0, sizeof(struct ip_tunnel_parm));
+	memset(&ifr, 0, sizeof(struct ifreq));
+
+	p.iph.version = 4;
+	p.iph.ihl = 5;
+	p.iph.frag_off = htons(IP_DF);
+	p.iph.protocol = IPPROTO_IPV6;
+	p.iph.saddr = addr->s_addr;
+	p.iph.ttl = 64;
+	strncpy(p.name, "tun6to4", sizeof(p.name) - 1);
+
+	strncpy(ifr.ifr_name, "sit0", sizeof(ifr.ifr_name) - 1);
+	ifr.ifr_ifru.ifru_data = (void *)&p;
+	fd = socket(AF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
+	if (fd < 0)
+		return -errno;
+	ret = ioctl(fd, SIOCADDTUNNEL, &ifr);
+	if (ret)
+		connman_error("add tunnel %s failed: %s", ifr.ifr_name,
+							strerror(errno));
+	close(fd);
+
+	return -ret;
+}
+
+static void tunnel_destroy(void)
+{
+	struct ip_tunnel_parm p;
+	struct ifreq ifr;
+	int fd = -1;
+	int ret;
+
+	if (tunnel_created == 0)
+		return;
+
+	/* ip tunnel del tun6to4 */
+
+	memset(&p, 0, sizeof(struct ip_tunnel_parm));
+	memset(&ifr, 0, sizeof(struct ifreq));
+
+	p.iph.version = 4;
+	p.iph.ihl = 5;
+	p.iph.protocol = IPPROTO_IPV6;
+	strncpy(p.name, "tun6to4", sizeof(p.name) - 1);
+
+	strncpy(ifr.ifr_name, "tun6to4", sizeof(ifr.ifr_name) - 1);
+	ifr.ifr_ifru.ifru_data = (void *)&p;
+	fd = socket(AF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
+	if (fd < 0) {
+		connman_error("socket failed: %s", strerror(errno));
+		return;
+	}
+
+	ret = ioctl(fd, SIOCDELTUNNEL, &ifr);
+	if (ret)
+		connman_error("del tunnel %s failed: %s", ifr.ifr_name,
+							strerror(errno));
+	else
+		tunnel_created = 0;
+
+	tunnel_pending = 0;
+	close(fd);
+
+	g_free(tunnel_ip_address);
+	tunnel_ip_address = NULL;
+}
+
+static int tunnel_add_route(void)
+{
+	struct __connman_inet_rtnl_handle rth;
+	struct in6_addr addr6;
+	int index;
+	int ret = 0;
+
+	/* ip -6 route add ::/0 via ::192.88.99.1 dev tun6to4 metric 1 */
+
+	index = if_nametoindex("tun6to4");
+	if (index == 0) {
+		DBG("Can not find device tun6to4");
+		return -1;
+	}
+
+	memset(&rth, 0, sizeof(rth));
+
+	rth.req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg));
+	rth.req.n.nlmsg_flags = NLM_F_REQUEST | NLM_F_CREATE | NLM_F_EXCL;
+	rth.req.n.nlmsg_type = RTM_NEWROUTE;
+	rth.req.u.r.rt.rtm_family = AF_INET6;
+	rth.req.u.r.rt.rtm_table = RT_TABLE_MAIN;
+	rth.req.u.r.rt.rtm_protocol = RTPROT_BOOT;
+	rth.req.u.r.rt.rtm_scope = RT_SCOPE_UNIVERSE;
+	rth.req.u.r.rt.rtm_type = RTN_UNICAST;
+	rth.req.u.r.rt.rtm_dst_len = 0;
+
+	inet_pton(AF_INET6, "::192.88.99.1", &addr6);
+
+	__connman_inet_rtnl_addattr_l(&rth.req.n, sizeof(rth.req), RTA_GATEWAY,
+					&addr6.s6_addr, 16);
+	__connman_inet_rtnl_addattr32(&rth.req.n, sizeof(rth.req), RTA_OIF,
+					index);
+	__connman_inet_rtnl_addattr32(&rth.req.n, sizeof(rth.req),
+					RTA_PRIORITY, 1);
+
+	ret = __connman_inet_rtnl_open(&rth);
+	if (ret < 0)
+		goto done;
+
+	ret = __connman_inet_rtnl_send(&rth, &rth.req.n);
+
+done:
+	__connman_inet_rtnl_close(&rth);
+	return ret;
+}
+
+static int tunnel_set_addr(unsigned int a, unsigned int b,
+			unsigned int c, unsigned int d)
+{
+	struct __connman_inet_rtnl_handle rth;
+	struct in6_addr addr6;
+	char *ip6addr;
+	int ret;
+
+	/* ip -6 addr add dev tun6to4 2002:0102:0304::1/64 */
+
+	memset(&rth, 0, sizeof(rth));
+
+	rth.req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg));
+	rth.req.n.nlmsg_flags = NLM_F_REQUEST | NLM_F_CREATE | NLM_F_EXCL;
+	rth.req.n.nlmsg_type = RTM_NEWADDR;
+	rth.req.u.i.ifa.ifa_family = AF_INET6;
+	rth.req.u.i.ifa.ifa_prefixlen = 64;
+	rth.req.u.i.ifa.ifa_index = if_nametoindex("tun6to4");
+	if (rth.req.u.i.ifa.ifa_index == 0) {
+		connman_error("Can not find device tun6to4");
+		ret = -1;
+		goto done;
+	}
+
+	ip6addr = g_strdup_printf("2002:%02x%02x:%02x%02x::1", a, b, c, d);
+	inet_pton(AF_INET6, ip6addr, &addr6);
+	DBG("ipv6 address %s", ip6addr);
+	g_free(ip6addr);
+
+	__connman_inet_rtnl_addattr_l(&rth.req.n, sizeof(rth.req), IFA_LOCAL,
+					&addr6.s6_addr, 16);
+	__connman_inet_rtnl_addattr_l(&rth.req.n, sizeof(rth.req), IFA_ADDRESS,
+					&addr6.s6_addr, 16);
+
+	ret = __connman_inet_rtnl_open(&rth);
+	if (ret < 0)
+		goto done;
+
+	ret = __connman_inet_rtnl_send(&rth, &rth.req.n);
+
+done:
+	__connman_inet_rtnl_close(&rth);
+	return ret;
+}
+
+static gboolean unref_web(gpointer user_data)
+{
+	g_web_unref(web);
+	return FALSE;
+}
+
+static bool web_result(GWebResult *result, gpointer user_data)
+{
+	guint16 status;
+
+	if (web_request_id == 0)
+		return false;
+
+	status = g_web_result_get_status(result);
+
+	DBG("status %u", status);
+
+	if (status >= 400 && status < 500)
+		tunnel_destroy();
+	else
+		tunnel_pending = 0;
+
+	web_request_id = 0;
+
+	g_timeout_add_seconds(1, unref_web, NULL);
+
+	return false;
+}
+
+static void web_debug(const char *str, void *data)
+{
+	connman_info("%s: %s\n", (const char *) data, str);
+}
+
+static gboolean newlink_timeout(gpointer user_data)
+{
+	/*
+	 * Stop if the timeout has been cancelled already by tun_newlink()
+	 */
+	if (newlink_timeout_id == 0)
+		return FALSE;
+
+	DBG("");
+
+	if (newlink_watch != 0) {
+		connman_rtnl_remove_watch(newlink_watch);
+		newlink_watch = 0;
+	}
+
+	newlink_flags = 0;
+
+	if (web_request_id == 0)
+		tunnel_destroy();
+
+	newlink_timeout_id = 0;
+
+	return FALSE;
+}
+
+static void tun_newlink(unsigned flags, unsigned change, void *user_data)
+{
+	int index = GPOINTER_TO_INT(user_data);
+
+	if ((newlink_flags & IFF_UP) == (flags & IFF_UP)) {
+		newlink_flags = flags;
+		return;
+	}
+
+	if (flags & IFF_UP) {
+		/*
+		 * We try to verify that connectivity through tunnel works ok.
+		 */
+		if (newlink_timeout_id > 0) {
+			g_source_remove(newlink_timeout_id);
+			newlink_timeout_id = 0;
+		}
+
+		web = g_web_new(index);
+		if (!web) {
+			tunnel_destroy();
+			return;
+		}
+
+		g_web_set_accept(web, NULL);
+		g_web_set_user_agent(web, "ConnMan/%s", VERSION);
+		g_web_set_close_connection(web, TRUE);
+
+		if (getenv("CONNMAN_WEB_DEBUG"))
+			g_web_set_debug(web, web_debug, "6to4");
+
+		web_request_id = g_web_request_get(web, STATUS_URL,
+				web_result, NULL,  NULL);
+
+		newlink_timeout(NULL);
+	}
+
+	newlink_flags = flags;
+}
+
+static int init_6to4(struct in_addr *ip4addr)
+{
+	unsigned int a, b, c, d;
+	int ret, if_index;
+	in_addr_t addr;
+
+	DBG("");
+
+	addr = ntohl(ip4addr->s_addr);
+
+	a = (addr & 0xff000000) >> 24;
+	b = (addr & 0x00ff0000) >> 16;
+	c = (addr & 0x0000ff00) >> 8;
+	d = addr & 0x000000ff;
+
+	ret = tunnel_create(ip4addr);
+	if (ret)
+		return -1;
+
+	tunnel_created = 1;
+
+	ret = connman_inet_setup_tunnel("tun6to4", 1472);
+	if (ret)
+		goto error;
+
+	ret = tunnel_set_addr(a, b, c, d);
+	if (ret)
+		goto error;
+
+	ret = tunnel_add_route();
+	if (ret)
+		goto error;
+
+	if_index = connman_inet_ifindex("tun6to4");
+	if (if_index < 0)
+		goto error;
+
+	newlink_watch = connman_rtnl_add_newlink_watch(if_index,
+				tun_newlink, GINT_TO_POINTER(if_index));
+
+	newlink_timeout_id = g_timeout_add_seconds(1, newlink_timeout, NULL);
+
+	return 0;
+
+error:
+	tunnel_destroy();
+	return -1;
+}
+
+static void receive_rs_reply(struct nd_router_advert *reply,
+			unsigned int length, void *user_data)
+{
+	char *address = user_data;
+	struct in_addr ip4addr;
+
+	DBG("reply %p len %d address %s", reply, length, address);
+
+	/* We try to create tunnel if autoconfiguration did not work i.e.,
+	 * we did not receive any reply to router solicitation message.
+	 */
+	if (!reply && inet_aton(address, &ip4addr) != 0)
+		init_6to4(&ip4addr);
+
+	g_free(address);
+}
+
+int __connman_6to4_probe(struct connman_service *service)
+{
+	struct connman_ipconfig *ip4config, *ip6config;
+	enum connman_ipconfig_method method;
+	unsigned int a, b;
+	struct in_addr ip4addr;
+	in_addr_t addr;
+	const char *address;
+	char *ip_address;
+	int index;
+
+	DBG("service %p", service);
+
+	if (tunnel_created || tunnel_pending)
+		return 0;
+
+	if (!service)
+		return -1;
+
+	ip4config = __connman_service_get_ip4config(service);
+	if (!ip4config)
+		return -1;
+
+	ip6config = __connman_service_get_ip6config(service);
+	if (!ip6config)
+		return -1;
+
+	method = __connman_ipconfig_get_method(ip6config);
+	if (method != CONNMAN_IPCONFIG_METHOD_AUTO)
+		return -1;
+
+	address = __connman_ipconfig_get_local(ip4config);
+	if (!address)
+		return -1;
+
+	if (inet_aton(address, &ip4addr) == 0)
+		return -1;
+
+	addr = ntohl(ip4addr.s_addr);
+
+	a = (addr & 0xff000000) >> 24;
+	b = (addr & 0x00ff0000) >> 16;
+
+	/* 6to4 tunnel is only usable if we have a public IPv4 address */
+	if (a == 10 || (a == 192 && b == 168) ||
+					(a == 172 && (b >= 16 && b <= 31)))
+		return -1;
+
+	index = __connman_ipconfig_get_index(ip4config);
+	ip_address = g_strdup(address);
+	tunnel_pending = 1;
+
+	g_free(tunnel_ip_address);
+	tunnel_ip_address = g_strdup(address);
+
+	return __connman_inet_ipv6_send_rs(index, 2, receive_rs_reply,
+							ip_address);
+}
+
+void __connman_6to4_remove(struct connman_ipconfig *ip4config)
+{
+	const char *address;
+
+	DBG("tunnel ip address %s", tunnel_ip_address);
+
+	if (!ip4config)
+		return;
+
+	address = __connman_ipconfig_get_local(ip4config);
+	if (!address)
+		return;
+
+	if (g_strcmp0(address, tunnel_ip_address) != 0)
+		return;
+
+	if (tunnel_created)
+		tunnel_destroy();
+}
+
+int __connman_6to4_check(struct connman_ipconfig *ip4config)
+{
+	const char *address;
+
+	if (!ip4config || tunnel_created == 0 ||
+					tunnel_pending == 1)
+		return -1;
+
+	DBG("tunnel ip address %s", tunnel_ip_address);
+
+	address = __connman_ipconfig_get_local(ip4config);
+	if (!address)
+		return -1;
+
+	if (g_strcmp0(address, tunnel_ip_address) == 0)
+		return 1;
+
+	return 0;
+}
diff --git a/connman/src/agent-connman.c b/connman/src/agent-connman.c
new file mode 100644
index 0000000..8440451
--- /dev/null
+++ b/connman/src/agent-connman.c
@@ -0,0 +1,798 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2012-2013  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 <string.h>
+
+#include <gdbus.h>
+#include <connman/agent.h>
+#include <connman/setting.h>
+#include <connman/service.h>
+
+#include "connman.h"
+
+static bool check_reply_has_dict(DBusMessage *reply)
+{
+	const char *signature = DBUS_TYPE_ARRAY_AS_STRING
+		DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+		DBUS_TYPE_STRING_AS_STRING
+		DBUS_TYPE_VARIANT_AS_STRING
+		DBUS_DICT_ENTRY_END_CHAR_AS_STRING;
+
+	if (dbus_message_has_signature(reply, signature))
+		return true;
+
+	connman_warn("Reply %s to %s from %s has wrong signature %s",
+			signature,
+			dbus_message_get_interface(reply),
+			dbus_message_get_sender(reply),
+			dbus_message_get_signature(reply));
+
+	return false;
+}
+
+struct request_input_reply {
+	struct connman_service *service;
+	struct connman_peer *peer;
+	union {
+		authentication_cb_t service_callback;
+		peer_wps_cb_t peer_callback;
+	};
+	bool wps_requested;
+	void *user_data;
+};
+
+static void request_input_passphrase_reply(DBusMessage *reply, void *user_data)
+{
+	struct request_input_reply *passphrase_reply = user_data;
+	bool values_received = false;
+	bool wps = false;
+	const char *error = NULL;
+	char *identity = NULL;
+	char *passphrase = NULL;
+	char *wpspin = NULL;
+	char *key;
+	char *name = NULL;
+	int name_len = 0;
+	DBusMessageIter iter, dict;
+
+	if (!reply) {
+		error = CONNMAN_ERROR_INTERFACE ".OperationAborted";
+		goto done;
+	}
+
+	if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) {
+		error = dbus_message_get_error_name(reply);
+		goto done;
+	}
+
+	if (!check_reply_has_dict(reply))
+		goto done;
+
+	values_received = true;
+
+	dbus_message_iter_init(reply, &iter);
+	dbus_message_iter_recurse(&iter, &dict);
+	while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
+		DBusMessageIter entry, value;
+
+		dbus_message_iter_recurse(&dict, &entry);
+		if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING)
+			break;
+
+		dbus_message_iter_get_basic(&entry, &key);
+
+		if (g_str_equal(key, "Identity")) {
+			dbus_message_iter_next(&entry);
+			if (dbus_message_iter_get_arg_type(&entry)
+							!= DBUS_TYPE_VARIANT)
+				break;
+			dbus_message_iter_recurse(&entry, &value);
+			dbus_message_iter_get_basic(&value, &identity);
+
+		} else if (g_str_equal(key, "Passphrase")) {
+			dbus_message_iter_next(&entry);
+			if (dbus_message_iter_get_arg_type(&entry)
+							!= DBUS_TYPE_VARIANT)
+				break;
+			dbus_message_iter_recurse(&entry, &value);
+			dbus_message_iter_get_basic(&value, &passphrase);
+
+		} else if (g_str_equal(key, "WPS")) {
+			wps = true;
+
+			dbus_message_iter_next(&entry);
+			if (dbus_message_iter_get_arg_type(&entry)
+							!= DBUS_TYPE_VARIANT)
+				break;
+			dbus_message_iter_recurse(&entry, &value);
+			dbus_message_iter_get_basic(&value, &wpspin);
+			break;
+		} else if (g_str_equal(key, "Name")) {
+			dbus_message_iter_next(&entry);
+			if (dbus_message_iter_get_arg_type(&entry)
+							!= DBUS_TYPE_VARIANT)
+				break;
+			dbus_message_iter_recurse(&entry, &value);
+			dbus_message_iter_get_basic(&value, &name);
+			name_len = strlen(name);
+		} else if (g_str_equal(key, "SSID")) {
+			dbus_message_iter_next(&entry);
+			if (dbus_message_iter_get_arg_type(&entry)
+							!= DBUS_TYPE_VARIANT)
+				break;
+			dbus_message_iter_recurse(&entry, &value);
+			if (dbus_message_iter_get_arg_type(&value)
+							!= DBUS_TYPE_VARIANT)
+				break;
+			if (dbus_message_iter_get_element_type(&value)
+							!= DBUS_TYPE_VARIANT)
+				break;
+			dbus_message_iter_get_fixed_array(&value, &name,
+							&name_len);
+		}
+		dbus_message_iter_next(&dict);
+	}
+
+done:
+	passphrase_reply->service_callback(passphrase_reply->service,
+					values_received, name, name_len,
+					identity, passphrase, wps, wpspin,
+					error, passphrase_reply->user_data);
+
+	g_free(passphrase_reply);
+}
+
+static void request_input_append_alternates(DBusMessageIter *iter,
+							void *user_data)
+{
+	const char *str = user_data;
+	char **alternates, **alternative;
+
+	if (!str)
+		return;
+
+	alternates = g_strsplit(str, ",", 0);
+	if (!alternates)
+		return;
+
+	for (alternative = alternates; *alternative; alternative++)
+		dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING,
+								alternative);
+
+	g_strfreev(alternates);
+}
+
+static void request_input_append_identity(DBusMessageIter *iter,
+							void *user_data)
+{
+	char *str = "string";
+
+	connman_dbus_dict_append_basic(iter, "Type",
+				DBUS_TYPE_STRING, &str);
+	str = "mandatory";
+	connman_dbus_dict_append_basic(iter, "Requirement",
+				DBUS_TYPE_STRING, &str);
+}
+
+static void request_input_append_passphrase(DBusMessageIter *iter,
+							void *user_data)
+{
+	struct connman_service *service = user_data;
+	char *value;
+	const char *phase2;
+
+	switch (__connman_service_get_security(service)) {
+	case CONNMAN_SERVICE_SECURITY_WEP:
+		value = "wep";
+		break;
+	case CONNMAN_SERVICE_SECURITY_PSK:
+		value = "psk";
+		break;
+	case CONNMAN_SERVICE_SECURITY_8021X:
+		phase2 = __connman_service_get_phase2(service);
+
+		if (phase2 && (
+				g_str_has_suffix(phase2, "GTC") ||
+				g_str_has_suffix(phase2, "OTP")))
+			value = "response";
+		else
+			value = "passphrase";
+
+		break;
+	default:
+		value = "string";
+		break;
+	}
+	connman_dbus_dict_append_basic(iter, "Type",
+				DBUS_TYPE_STRING, &value);
+	value = "mandatory";
+	connman_dbus_dict_append_basic(iter, "Requirement",
+				DBUS_TYPE_STRING, &value);
+
+	if (__connman_service_wps_enabled(service)) {
+		connman_dbus_dict_append_array(iter, "Alternates",
+					DBUS_TYPE_STRING,
+					request_input_append_alternates,
+					"WPS");
+	}
+}
+
+struct request_wps_data {
+	bool peer;
+};
+
+static void request_input_append_wps(DBusMessageIter *iter, void *user_data)
+{
+	struct request_wps_data *wps = user_data;
+	const char *str = "wpspin";
+
+	connman_dbus_dict_append_basic(iter, "Type",
+				DBUS_TYPE_STRING, &str);
+	if (wps && wps->peer)
+		str = "mandatory";
+	else
+		str = "alternate";
+	connman_dbus_dict_append_basic(iter, "Requirement",
+				DBUS_TYPE_STRING, &str);
+}
+
+static void request_input_append_name(DBusMessageIter *iter, void *user_data)
+{
+	const char *str = "string";
+
+	connman_dbus_dict_append_basic(iter, "Type",
+				DBUS_TYPE_STRING, &str);
+	str = "mandatory";
+	connman_dbus_dict_append_basic(iter, "Requirement",
+				DBUS_TYPE_STRING, &str);
+	connman_dbus_dict_append_array(iter, "Alternates",
+				DBUS_TYPE_STRING,
+				request_input_append_alternates,
+				"SSID");
+}
+
+static void request_input_append_ssid(DBusMessageIter *iter, void *user_data)
+{
+	const char *str = "ssid";
+
+	connman_dbus_dict_append_basic(iter, "Type",
+				DBUS_TYPE_STRING, &str);
+	str = "alternate";
+	connman_dbus_dict_append_basic(iter, "Requirement",
+				DBUS_TYPE_STRING, &str);
+}
+
+static void request_input_append_password(DBusMessageIter *iter,
+							void *user_data)
+{
+	char *str = "passphrase";
+
+	connman_dbus_dict_append_basic(iter, "Type",
+				DBUS_TYPE_STRING, &str);
+	str = "mandatory";
+	connman_dbus_dict_append_basic(iter, "Requirement",
+				DBUS_TYPE_STRING, &str);
+}
+
+struct previous_passphrase_data {
+	const char *passphrase;
+	const char *type;
+};
+
+static void request_input_append_previouspassphrase(DBusMessageIter *iter,
+							void *user_data)
+{
+	struct previous_passphrase_data *data = user_data;
+	const char *requirement = "informational";
+
+	connman_dbus_dict_append_basic(iter, "Type",
+				DBUS_TYPE_STRING, &data->type);
+
+	connman_dbus_dict_append_basic(iter, "Requirement",
+				DBUS_TYPE_STRING, &requirement);
+
+	connman_dbus_dict_append_basic(iter, "Value",
+				DBUS_TYPE_STRING, &data->passphrase);
+}
+
+static void previous_passphrase_handler(DBusMessageIter *iter,
+					struct connman_service *service)
+{
+	enum connman_service_security security;
+	struct previous_passphrase_data data;
+	struct connman_network *network;
+
+	network = __connman_service_get_network(service);
+	data.passphrase = connman_network_get_string(network, "WiFi.PinWPS");
+
+	if (connman_network_get_bool(network, "WiFi.UseWPS") &&
+						data.passphrase) {
+		data.type = "wpspin";
+	} else {
+		data.passphrase = __connman_service_get_passphrase(service);
+		if (!data.passphrase)
+			return;
+
+		security = __connman_service_get_security(service);
+		switch (security) {
+		case CONNMAN_SERVICE_SECURITY_WEP:
+			data.type = "wep";
+			break;
+		case CONNMAN_SERVICE_SECURITY_PSK:
+			data.type  = "psk";
+			break;
+		/*
+		 * This should never happen: no passphrase is set if security
+		 * is not one of the above. */
+		default:
+			break;
+		}
+	}
+
+	connman_dbus_dict_append_dict(iter, "PreviousPassphrase",
+			request_input_append_previouspassphrase, &data);
+}
+
+static void request_input_login_reply(DBusMessage *reply, void *user_data)
+{
+	struct request_input_reply *username_password_reply = user_data;
+	const char *error = NULL;
+	bool values_received = false;
+	char *username = NULL;
+	char *password = NULL;
+	char *key;
+	DBusMessageIter iter, dict;
+
+	if (!reply) {
+		error = CONNMAN_ERROR_INTERFACE ".OperationAborted";
+		goto done;
+	}
+
+	if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) {
+		error = dbus_message_get_error_name(reply);
+		goto done;
+	}
+
+	if (!check_reply_has_dict(reply))
+		goto done;
+
+	values_received = true;
+
+	dbus_message_iter_init(reply, &iter);
+	dbus_message_iter_recurse(&iter, &dict);
+	while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
+		DBusMessageIter entry, value;
+
+		dbus_message_iter_recurse(&dict, &entry);
+		if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING)
+			break;
+
+		dbus_message_iter_get_basic(&entry, &key);
+
+		if (g_str_equal(key, "Username")) {
+			dbus_message_iter_next(&entry);
+			if (dbus_message_iter_get_arg_type(&entry)
+							!= DBUS_TYPE_VARIANT)
+				break;
+			dbus_message_iter_recurse(&entry, &value);
+			dbus_message_iter_get_basic(&value, &username);
+
+		} else if (g_str_equal(key, "Password")) {
+			dbus_message_iter_next(&entry);
+			if (dbus_message_iter_get_arg_type(&entry) !=
+							DBUS_TYPE_VARIANT)
+				break;
+			dbus_message_iter_recurse(&entry, &value);
+			dbus_message_iter_get_basic(&value, &password);
+		}
+
+		dbus_message_iter_next(&dict);
+	}
+
+done:
+	username_password_reply->service_callback(
+			username_password_reply->service, values_received,
+			NULL, 0, username, password, FALSE, NULL, error,
+			username_password_reply->user_data);
+
+	g_free(username_password_reply);
+}
+
+int __connman_agent_request_passphrase_input(struct connman_service *service,
+				authentication_cb_t callback,
+				const char *dbus_sender, void *user_data)
+{
+	DBusMessage *message;
+	const char *path, *agent_sender, *agent_path;
+	DBusMessageIter iter;
+	DBusMessageIter dict;
+	struct request_input_reply *passphrase_reply;
+	int err;
+	void *agent;
+
+	agent = connman_agent_get_info(dbus_sender, &agent_sender,
+							&agent_path);
+
+	DBG("agent %p service %p path %s", agent, service, agent_path);
+
+	if (!service || !agent || !agent_path || !callback)
+		return -ESRCH;
+
+	message = dbus_message_new_method_call(agent_sender, agent_path,
+					CONNMAN_AGENT_INTERFACE,
+					"RequestInput");
+	if (!message)
+		return -ENOMEM;
+
+	dbus_message_iter_init_append(message, &iter);
+
+	path = __connman_service_get_path(service);
+	dbus_message_iter_append_basic(&iter,
+				DBUS_TYPE_OBJECT_PATH, &path);
+
+	connman_dbus_dict_open(&iter, &dict);
+
+	if (__connman_service_is_hidden(service)) {
+		connman_dbus_dict_append_dict(&dict, "Name",
+					request_input_append_name, NULL);
+		connman_dbus_dict_append_dict(&dict, "SSID",
+					request_input_append_ssid, NULL);
+	}
+
+	if (__connman_service_get_security(service) ==
+			CONNMAN_SERVICE_SECURITY_8021X) {
+		connman_dbus_dict_append_dict(&dict, "Identity",
+					request_input_append_identity, service);
+	}
+
+	if (__connman_service_get_security(service) !=
+			CONNMAN_SERVICE_SECURITY_NONE) {
+		connman_dbus_dict_append_dict(&dict, "Passphrase",
+				request_input_append_passphrase, service);
+
+		previous_passphrase_handler(&dict, service);
+	}
+
+	if (__connman_service_wps_enabled(service))
+		connman_dbus_dict_append_dict(&dict, "WPS",
+				request_input_append_wps, NULL);
+
+	connman_dbus_dict_close(&iter, &dict);
+
+	passphrase_reply = g_try_new0(struct request_input_reply, 1);
+	if (!passphrase_reply) {
+		dbus_message_unref(message);
+		return -ENOMEM;
+	}
+
+	passphrase_reply->service = service;
+	passphrase_reply->service_callback = callback;
+	passphrase_reply->user_data = user_data;
+
+	err = connman_agent_queue_message(service, message,
+			connman_timeout_input_request(),
+			request_input_passphrase_reply,
+			passphrase_reply, agent);
+
+	if (err < 0 && err != -EBUSY) {
+		DBG("error %d sending agent message", err);
+		dbus_message_unref(message);
+		g_free(passphrase_reply);
+		return err;
+	}
+
+	dbus_message_unref(message);
+
+	return -EINPROGRESS;
+}
+
+int __connman_agent_request_login_input(struct connman_service *service,
+				authentication_cb_t callback, void *user_data)
+{
+	DBusMessage *message;
+	const char *path, *agent_sender, *agent_path;
+	DBusMessageIter iter;
+	DBusMessageIter dict;
+	struct request_input_reply *username_password_reply;
+	int err;
+	void *agent;
+
+	agent = connman_agent_get_info(NULL, &agent_sender, &agent_path);
+
+	if (!service || !agent || !agent_path || !callback)
+		return -ESRCH;
+
+	message = dbus_message_new_method_call(agent_sender, agent_path,
+					CONNMAN_AGENT_INTERFACE,
+					"RequestInput");
+	if (!message)
+		return -ENOMEM;
+
+	dbus_message_iter_init_append(message, &iter);
+
+	path = __connman_service_get_path(service);
+	dbus_message_iter_append_basic(&iter,
+				DBUS_TYPE_OBJECT_PATH, &path);
+
+	connman_dbus_dict_open(&iter, &dict);
+
+	connman_dbus_dict_append_dict(&dict, "Username",
+				request_input_append_identity, service);
+
+	connman_dbus_dict_append_dict(&dict, "Password",
+				request_input_append_password, service);
+
+	connman_dbus_dict_close(&iter, &dict);
+
+	username_password_reply = g_try_new0(struct request_input_reply, 1);
+	if (!username_password_reply) {
+		dbus_message_unref(message);
+		return -ENOMEM;
+	}
+
+	username_password_reply->service = service;
+	username_password_reply->service_callback = callback;
+	username_password_reply->user_data = user_data;
+
+	err = connman_agent_queue_message(service, message,
+			connman_timeout_input_request(),
+			request_input_login_reply, username_password_reply,
+			agent);
+	if (err < 0 && err != -EBUSY) {
+		DBG("error %d sending agent request", err);
+		dbus_message_unref(message);
+		g_free(username_password_reply);
+		return err;
+	}
+
+	dbus_message_unref(message);
+
+	return -EINPROGRESS;
+}
+
+struct request_browser_reply_data {
+	struct connman_service *service;
+	browser_authentication_cb_t callback;
+	void *user_data;
+};
+
+static void request_browser_reply(DBusMessage *reply, void *user_data)
+{
+	struct request_browser_reply_data *browser_reply_data = user_data;
+	bool result = false;
+	const char *error = NULL;
+
+	if (!reply) {
+		error = CONNMAN_ERROR_INTERFACE ".OperationAborted";
+		goto done;
+	}
+
+	if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) {
+		error = dbus_message_get_error_name(reply);
+		goto done;
+	}
+
+	result = true;
+
+done:
+	browser_reply_data->callback(browser_reply_data->service, result,
+					error, browser_reply_data->user_data);
+	g_free(browser_reply_data);
+}
+
+int __connman_agent_request_browser(struct connman_service *service,
+				browser_authentication_cb_t callback,
+				const char *url, void *user_data)
+{
+	struct request_browser_reply_data *browser_reply_data;
+	DBusMessage *message;
+	DBusMessageIter iter;
+	const char *path, *agent_sender, *agent_path;
+	int err;
+	void *agent;
+
+	agent = connman_agent_get_info(NULL, &agent_sender, &agent_path);
+
+	if (!service || !agent || !agent_path || !callback)
+		return -ESRCH;
+
+	if (!url)
+		url = "";
+
+	message = dbus_message_new_method_call(agent_sender, agent_path,
+					CONNMAN_AGENT_INTERFACE,
+					"RequestBrowser");
+	if (!message)
+		return -ENOMEM;
+
+	dbus_message_iter_init_append(message, &iter);
+
+	path = __connman_service_get_path(service);
+	dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH, &path);
+
+	dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &url);
+
+	browser_reply_data = g_try_new0(struct request_browser_reply_data, 1);
+	if (!browser_reply_data) {
+		dbus_message_unref(message);
+		return -ENOMEM;
+	}
+
+	browser_reply_data->service = service;
+	browser_reply_data->callback = callback;
+	browser_reply_data->user_data = user_data;
+
+	err = connman_agent_queue_message(service, message,
+				connman_timeout_browser_launch(),
+				request_browser_reply, browser_reply_data,
+				agent);
+
+	if (err < 0 && err != -EBUSY) {
+		DBG("error %d sending browser request", err);
+		dbus_message_unref(message);
+		g_free(browser_reply_data);
+		return err;
+	}
+
+	dbus_message_unref(message);
+
+	return -EINPROGRESS;
+}
+
+int __connman_agent_report_peer_error(struct connman_peer *peer,
+					const char *path, const char *error,
+					report_error_cb_t callback,
+					const char *dbus_sender,
+					void *user_data)
+{
+	return connman_agent_report_error_full(peer, path, "ReportPeerError",
+				error, callback, dbus_sender, user_data);
+}
+
+static void request_peer_authorization_reply(DBusMessage *reply,
+							void *user_data)
+{
+	struct request_input_reply *auth_reply = user_data;
+	DBusMessageIter iter, dict;
+	const char *error = NULL;
+	bool choice_done = false;
+	char *wpspin = NULL;
+	char *key;
+
+	if (!reply) {
+		error = CONNMAN_ERROR_INTERFACE ".OperationAborted";
+		goto done;
+	}
+
+	if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) {
+		error = dbus_message_get_error_name(reply);
+		goto done;
+	}
+
+	if (!check_reply_has_dict(reply))
+		goto done;
+
+	dbus_message_iter_init(reply, &iter);
+	dbus_message_iter_recurse(&iter, &dict);
+	while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
+		DBusMessageIter entry, value;
+
+		dbus_message_iter_recurse(&dict, &entry);
+		if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING)
+			break;
+
+		dbus_message_iter_get_basic(&entry, &key);
+
+		if (g_str_equal(key, "WPS")) {
+			choice_done = true;
+
+			dbus_message_iter_next(&entry);
+			if (dbus_message_iter_get_arg_type(&entry)
+							!= DBUS_TYPE_VARIANT)
+				break;
+			dbus_message_iter_recurse(&entry, &value);
+			dbus_message_iter_get_basic(&value, &wpspin);
+			break;
+		}
+		dbus_message_iter_next(&dict);
+	}
+
+	if (!auth_reply->wps_requested)
+		choice_done = true;
+
+done:
+	auth_reply->peer_callback(auth_reply->peer, choice_done, wpspin,
+						error, auth_reply->user_data);
+
+	g_free(auth_reply);
+}
+
+int __connman_agent_request_peer_authorization(struct connman_peer *peer,
+						peer_wps_cb_t callback,
+						bool wps_requested,
+						const char *dbus_sender,
+						void *user_data)
+{
+	struct request_wps_data wps = { .peer = true };
+	const char *path, *agent_sender, *agent_path;
+	struct request_input_reply *auth_reply;
+	DBusMessageIter dict, iter;
+	DBusMessage *message;
+	void *agent;
+	int err;
+
+	agent = connman_agent_get_info(dbus_sender, &agent_sender,
+							&agent_path);
+	DBG("agent %p peer %p path %s", agent, peer, agent_path);
+
+	if (!peer || !agent || !agent_path || !callback)
+		return -ESRCH;
+
+	message = dbus_message_new_method_call(agent_sender, agent_path,
+			CONNMAN_AGENT_INTERFACE, "RequestPeerAuthorization");
+	if (!message)
+		return -ENOMEM;
+
+	dbus_message_iter_init_append(message, &iter);
+
+	path = __connman_peer_get_path(peer);
+	dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH, &path);
+
+	connman_dbus_dict_open(&iter, &dict);
+
+	if (wps_requested)
+		connman_dbus_dict_append_dict(&dict, "WPS",
+					request_input_append_wps, &wps);
+
+	connman_dbus_dict_close(&iter, &dict);
+
+	auth_reply = g_try_new0(struct request_input_reply, 1);
+	if (!auth_reply) {
+		dbus_message_unref(message);
+		return -ENOMEM;
+	}
+
+	auth_reply->peer = peer;
+	auth_reply->peer_callback = callback;
+	auth_reply->wps_requested = wps_requested;
+	auth_reply->user_data = user_data;
+
+	err = connman_agent_queue_message(peer, message,
+					connman_timeout_input_request(),
+					request_peer_authorization_reply,
+					auth_reply, agent);
+	if (err < 0 && err != -EBUSY) {
+		DBG("error %d sending agent message", err);
+		dbus_message_unref(message);
+		g_free(auth_reply);
+		return err;
+	}
+
+	dbus_message_unref(message);
+
+	return -EINPROGRESS;
+}
diff --git a/connman/src/agent.c b/connman/src/agent.c
new file mode 100644
index 0000000..bdeb0e7
--- /dev/null
+++ b/connman/src/agent.c
@@ -0,0 +1,684 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2013  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 <string.h>
+
+#include <gdbus.h>
+#include <connman/agent.h>
+#include <connman/setting.h>
+
+#include "connman.h"
+
+#define agent_ref(agent) \
+	agent_ref_debug(agent, __FILE__, __LINE__, __func__)
+#define agent_unref(agent) \
+	agent_unref_debug(agent, __FILE__, __LINE__, __func__)
+
+static DBusConnection *connection = NULL;
+static GHashTable *agent_hash = NULL;
+static struct connman_agent *default_agent = NULL;
+
+struct connman_agent {
+	int refcount;
+	char *owner;
+	char *path;
+	struct connman_agent_request *pending;
+	GList *queue;	/* queued requests for this agent */
+	guint watch;
+};
+
+struct connman_agent_request {
+	void *user_context;
+	void *user_data;
+	DBusMessage *msg;
+	DBusPendingCall *call;
+	int timeout;
+	agent_queue_cb callback;
+	struct connman_agent_driver *driver;
+};
+
+static GSList *driver_list = NULL;
+
+void *connman_agent_get_info(const char *dbus_sender, const char **sender,
+							const char **path)
+{
+	struct connman_agent *agent;
+
+	if (!dbus_sender)
+		agent = default_agent;
+	else {
+		agent = g_hash_table_lookup(agent_hash, dbus_sender);
+		if (!agent)
+			agent = default_agent;
+	}
+
+	if (agent) {
+		if (sender)
+			*sender = agent->owner;
+		if (path)
+			*path = agent->path;
+	} else {
+		if (sender)
+			*sender = NULL;
+		if (path)
+			*path = NULL;
+	}
+
+	return agent;
+}
+
+static void agent_request_free(struct connman_agent_request *request)
+{
+	if (!request)
+		return;
+
+	if (request->user_context) {
+		if (request->driver && request->driver->context_unref)
+			request->driver->context_unref(request->user_context);
+	}
+
+	if (request->msg)
+		dbus_message_unref(request->msg);
+
+	if (request->call) {
+		dbus_pending_call_cancel(request->call);
+		dbus_pending_call_unref(request->call);
+	}
+
+	g_free(request);
+}
+
+static void agent_finalize_pending(struct connman_agent *agent,
+				DBusMessage *reply)
+{
+	struct connman_agent_request *pending = agent->pending;
+	if (pending) {
+		agent->pending = NULL;
+		pending->callback(reply, pending->user_data);
+		agent_request_free(pending);
+	}
+}
+
+static void agent_receive_message(DBusPendingCall *call, void *user_data);
+
+static int agent_send_next_request(struct connman_agent *agent)
+{
+	if (agent->pending)
+		return -EBUSY;
+
+	if (!agent->queue)
+		return 0;
+
+	agent->pending = agent->queue->data;
+	agent->queue = g_list_remove(agent->queue, agent->pending);
+
+	if (!agent->pending->msg)
+		goto fail;
+
+	if (!dbus_connection_send_with_reply(connection, agent->pending->msg,
+						&agent->pending->call,
+						agent->pending->timeout))
+		goto fail;
+
+	if (!agent->pending->call)
+		goto fail;
+
+	if (!dbus_pending_call_set_notify(agent->pending->call,
+						agent_receive_message,
+						agent, NULL))
+		goto fail;
+
+	dbus_message_unref(agent->pending->msg);
+	agent->pending->msg = NULL;
+	return 0;
+
+fail:
+	agent_finalize_pending(agent, NULL);
+	return -ESRCH;
+}
+
+static int send_cancel_request(struct connman_agent *agent,
+			struct connman_agent_request *request)
+{
+	DBusMessage *message;
+
+	DBG("send cancel req to %s %s", agent->owner, agent->path);
+
+	message = dbus_message_new_method_call(agent->owner,
+					agent->path,
+					request->driver->interface,
+					"Cancel");
+	if (!message) {
+		connman_error("Couldn't allocate D-Bus message");
+		return -ENOMEM;
+	}
+
+	g_dbus_send_message(connection, message);
+	return 0;
+}
+
+static void agent_receive_message(DBusPendingCall *call, void *user_data)
+{
+	struct connman_agent *agent = user_data;
+	DBusMessage *reply;
+	int err;
+
+	DBG("agent %p req %p", agent, agent->pending);
+
+	reply = dbus_pending_call_steal_reply(call);
+	dbus_pending_call_unref(call);
+	agent->pending->call = NULL;
+
+	if (dbus_message_is_error(reply,
+			"org.freedesktop.DBus.Error.Timeout") ||
+			dbus_message_is_error(reply,
+			"org.freedesktop.DBus.Error.TimedOut")) {
+		send_cancel_request(agent, agent->pending);
+	}
+
+	agent_finalize_pending(agent, reply);
+	dbus_message_unref(reply);
+
+	err = agent_send_next_request(agent);
+	if (err < 0 && err != -EBUSY)
+		DBG("send next request failed (%s/%d)", strerror(-err), -err);
+}
+
+static struct connman_agent_driver *get_driver(void)
+{
+	return g_slist_nth_data(driver_list, 0);
+}
+
+int connman_agent_queue_message(void *user_context,
+				DBusMessage *msg, int timeout,
+				agent_queue_cb callback, void *user_data,
+				void *agent_data)
+{
+	struct connman_agent_request *queue_data;
+	struct connman_agent_driver *driver;
+	struct connman_agent *agent = agent_data;
+	int err;
+
+	if (!user_context || !callback)
+		return -EBADMSG;
+
+	queue_data = g_new0(struct connman_agent_request, 1);
+	if (!queue_data)
+		return -ENOMEM;
+
+	driver = get_driver();
+	DBG("driver %p", driver);
+
+	if (driver && driver->context_ref) {
+		queue_data->user_context = driver->context_ref(user_context);
+		queue_data->driver = driver;
+	} else
+		queue_data->user_context = user_context;
+
+	queue_data->msg = dbus_message_ref(msg);
+	queue_data->timeout = timeout;
+	queue_data->callback = callback;
+	queue_data->user_data = user_data;
+	agent->queue = g_list_append(agent->queue, queue_data);
+
+	err = agent_send_next_request(agent);
+	if (err < 0 && err != -EBUSY)
+		DBG("send next request failed (%s/%d)", strerror(-err), -err);
+
+	return err;
+}
+
+static void set_default_agent(void)
+{
+	struct connman_agent *agent = NULL;
+	GHashTableIter iter;
+	gpointer key, value;
+
+	if (default_agent)
+		return;
+
+	g_hash_table_iter_init(&iter, agent_hash);
+	if (g_hash_table_iter_next(&iter, &key, &value))
+		agent = value;
+
+	if (agent)
+		DBG("default agent set to %s %s", agent->owner, agent->path);
+	else
+		DBG("default agent cleared");
+
+	default_agent = agent;
+}
+
+static void agent_disconnect(DBusConnection *conn, void *user_data)
+{
+	struct connman_agent *agent = user_data;
+
+	DBG("agent %s disconnected", agent->owner);
+
+	if (agent->watch > 0) {
+		g_dbus_remove_watch(conn, agent->watch);
+		agent->watch = 0;
+	}
+
+	g_hash_table_remove(agent_hash, agent->owner);
+}
+
+static struct connman_agent *agent_ref_debug(struct connman_agent *agent,
+				const char *file, int line, const char *caller)
+{
+	DBG("%p ref %d by %s:%d:%s()", agent, agent->refcount + 1,
+		file, line, caller);
+
+	__sync_fetch_and_add(&agent->refcount, 1);
+
+	return agent;
+}
+
+static struct connman_agent *agent_create(const char *name, const char *path)
+{
+	struct connman_agent *agent;
+
+	agent = g_new0(struct connman_agent, 1);
+
+	agent->owner = g_strdup(name);
+	agent->path = g_strdup(path);
+
+	agent->watch = g_dbus_add_disconnect_watch(connection,
+							name, agent_disconnect,
+							agent, NULL);
+
+	return agent_ref(agent);
+}
+
+int connman_agent_register(const char *sender, const char *path)
+{
+	struct connman_agent *agent;
+
+	DBG("sender %s path %s", sender, path);
+
+	agent = g_hash_table_lookup(agent_hash, sender);
+	if (agent)
+		return -EEXIST;
+
+	agent = agent_create(sender, path);
+	if (!agent)
+		return -EINVAL;
+
+	DBG("agent %s", agent->owner);
+
+	g_hash_table_replace(agent_hash, agent->owner, agent);
+
+	if (!default_agent)
+		set_default_agent();
+
+	return 0;
+}
+
+struct report_error_data {
+	void *user_context;
+	report_error_cb_t callback;
+	void *user_data;
+};
+
+static void report_error_reply(DBusMessage *reply, void *user_data)
+{
+	struct report_error_data *report_error = user_data;
+	bool retry = false;
+	const char *dbus_err;
+
+	if (!reply)
+		goto out;
+
+	if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) {
+		dbus_err = dbus_message_get_error_name(reply);
+		if (dbus_err &&
+			strcmp(dbus_err,
+				CONNMAN_AGENT_INTERFACE ".Error.Retry") == 0)
+			retry = true;
+	}
+
+	report_error->callback(report_error->user_context, retry,
+			report_error->user_data);
+out:
+	g_free(report_error);
+}
+
+int connman_agent_report_error_full(void *user_context, const char *path,
+				const char *method, const char *error,
+				report_error_cb_t callback,
+				const char *dbus_sender, void *user_data)
+{
+	DBusMessage *message;
+	DBusMessageIter iter;
+	struct report_error_data *report_error;
+	struct connman_agent *agent;
+	int err;
+
+	agent = connman_agent_get_info(dbus_sender, NULL, NULL);
+
+	DBG("agent %p sender %s context %p path %s", agent,
+		dbus_sender, user_context, agent ? agent->path : "-");
+
+	if (!user_context || !agent || !agent->path || !error || !callback)
+		return -ESRCH;
+
+	message = dbus_message_new_method_call(agent->owner, agent->path,
+					CONNMAN_AGENT_INTERFACE, method);
+	if (!message)
+		return -ENOMEM;
+
+	dbus_message_iter_init_append(message, &iter);
+
+	dbus_message_iter_append_basic(&iter,
+				DBUS_TYPE_OBJECT_PATH, &path);
+	dbus_message_iter_append_basic(&iter,
+				DBUS_TYPE_STRING, &error);
+
+	report_error = g_try_new0(struct report_error_data, 1);
+	if (!report_error) {
+		dbus_message_unref(message);
+		return -ENOMEM;
+	}
+
+	report_error->user_context = user_context;
+	report_error->callback = callback;
+	report_error->user_data = user_data;
+
+	err = connman_agent_queue_message(user_context, message,
+					connman_timeout_input_request(),
+					report_error_reply, report_error,
+					agent);
+	if (err < 0 && err != -EBUSY) {
+		DBG("error %d sending error request", err);
+		g_free(report_error);
+		dbus_message_unref(message);
+		return -ESRCH;
+	}
+
+	dbus_message_unref(message);
+
+	return -EINPROGRESS;
+}
+
+int connman_agent_report_error(void *user_context, const char *path,
+				const char *error,
+				report_error_cb_t callback,
+				const char *dbus_sender, void *user_data)
+{
+	return connman_agent_report_error_full(user_context, path,
+				"ReportError", error, callback, dbus_sender,
+				user_data);
+}
+
+static gint compare_priority(gconstpointer a, gconstpointer b)
+{
+	const struct connman_agent_driver *driver1 = a;
+	const struct connman_agent_driver *driver2 = b;
+
+	return driver2->priority - driver1->priority;
+}
+
+/**
+ * connman_agent_driver_register:
+ * @driver: Agent driver definition
+ *
+ * Register a new agent driver
+ *
+ * Returns: %0 on success
+ */
+int connman_agent_driver_register(struct connman_agent_driver *driver)
+{
+	DBG("Registering driver %p name %s", driver, driver->name);
+
+	driver_list = g_slist_insert_sorted(driver_list, driver,
+							compare_priority);
+
+	return 0;
+}
+
+static void release_driver(void)
+{
+	connman_agent_driver_unregister(get_driver());
+}
+
+static void cancel_all_requests(struct connman_agent *agent)
+{
+	GList *list;
+
+	DBG("request %p pending %p", agent->pending, agent->queue);
+
+	if (agent->pending) {
+		if (agent->pending->call)
+			send_cancel_request(agent, agent->pending);
+
+		agent_finalize_pending(agent, NULL);
+	}
+
+	for (list = agent->queue; list; list = list->next) {
+		struct connman_agent_request *request = list->data;
+
+		if (!request)
+			continue;
+
+		request->callback(NULL, request->user_data);
+		agent_request_free(request);
+	}
+
+	g_list_free(agent->queue);
+	agent->queue = NULL;
+}
+
+void connman_agent_cancel(void *user_context)
+{
+	GHashTableIter iter;
+	gpointer key, value;
+	int err;
+
+	DBG("context %p", user_context);
+
+	g_hash_table_iter_init(&iter, agent_hash);
+	while (g_hash_table_iter_next(&iter, &key, &value)) {
+		GList *list, *next;
+		struct connman_agent *agent = value;
+
+		/*
+		 * Cancel all the pending requests to a given agent and service
+		 */
+		list = agent->queue;
+		while (list) {
+			struct connman_agent_request *request = list->data;
+
+			next = list->next;
+
+			if (request && request->user_context &&
+						request->user_context ==
+								user_context) {
+				DBG("cancel pending %p", request);
+
+				request->callback(NULL, request->user_data);
+
+				agent_request_free(request);
+
+				agent->queue = g_list_delete_link(agent->queue,
+									list);
+			}
+
+			list = next;
+		}
+
+		/*
+		 * If there is a request from client to a given service,
+		 * we need to cancel it.
+		 */
+		if (agent->pending && agent->pending->user_context &&
+				agent->pending->user_context == user_context) {
+			DBG("cancel request %p", agent->pending);
+
+			if (agent->pending->call)
+				send_cancel_request(agent, agent->pending);
+
+			agent_finalize_pending(agent, NULL);
+
+			err = agent_send_next_request(agent);
+			if (err < 0 && err != -EBUSY)
+				DBG("send next request failed (%s/%d)",
+						strerror(-err), -err);
+		}
+	}
+}
+
+static void agent_unref_debug(struct connman_agent *agent,
+			const char *file, int line, const char *caller)
+{
+	DBG("%p ref %d by %s:%d:%s()", agent, agent->refcount - 1,
+		file, line, caller);
+
+	if (__sync_fetch_and_sub(&agent->refcount, 1) != 1)
+		return;
+
+	cancel_all_requests(agent);
+
+	g_free(agent->owner);
+	g_free(agent->path);
+
+	if (agent == default_agent) {
+		default_agent = NULL;
+		set_default_agent();
+	}
+
+	g_free(agent);
+}
+
+static void agent_release(struct connman_agent *agent, const char *interface)
+{
+	DBusMessage *message;
+
+	DBG("release agent %s %s", agent->owner, agent->path);
+
+	message = dbus_message_new_method_call(agent->owner, agent->path,
+						interface, "Release");
+	if (message == NULL) {
+		connman_error("Couldn't allocate D-Bus message");
+		return;
+	}
+
+	dbus_message_set_no_reply(message, TRUE);
+	g_dbus_send_message(connection, message);
+}
+
+static void release_agents(void)
+{
+	GHashTableIter iter;
+	gpointer key, value;
+
+	g_hash_table_iter_init(&iter, agent_hash);
+	while (g_hash_table_iter_next(&iter, &key, &value))
+		agent_release(value, get_driver()->interface);
+}
+
+/**
+ * connman_agent_driver_unregister:
+ * @driver: Agent driver definition
+ *
+ * Remove a previously registered agent driver
+ */
+void connman_agent_driver_unregister(struct connman_agent_driver *driver)
+{
+	GSList *list;
+
+	if (!driver)
+		return;
+
+	DBG("Unregistering driver %p name %s", driver, driver->name);
+
+	release_agents();
+
+	for (list = driver_list; list; list = list->next) {
+		if (driver != list->data)
+			continue;
+
+		g_hash_table_remove_all(agent_hash);
+		break;
+	}
+
+	driver_list = g_slist_remove(driver_list, driver);
+}
+
+static void agent_destroy(gpointer data)
+{
+	struct connman_agent *agent = data;
+
+	DBG("agent %s req %p", agent->owner, agent->pending);
+
+	if (agent->watch > 0) {
+		g_dbus_remove_watch(connection, agent->watch);
+		agent->watch = 0;
+	}
+
+	agent_unref(agent);
+}
+
+int connman_agent_unregister(const char *sender, const char *path)
+{
+	DBG("sender %s path %s", sender, path);
+
+	if (!g_hash_table_remove(agent_hash, sender))
+		return -ESRCH;
+
+	return 0;
+}
+
+int __connman_agent_init(void)
+{
+	DBG("");
+
+	connection = connman_dbus_get_connection();
+	if (!connection)
+		return -EINVAL;
+
+	agent_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
+						NULL, agent_destroy);
+	if (!agent_hash)
+		return -ENOMEM;
+
+	return 0;
+}
+
+void __connman_agent_cleanup(void)
+{
+	DBG("");
+
+	if (!connection)
+		return;
+
+	g_hash_table_destroy(agent_hash);
+
+	release_driver();
+
+	dbus_connection_unref(connection);
+	connection = NULL;
+}
diff --git a/connman/src/bridge.c b/connman/src/bridge.c
new file mode 100644
index 0000000..ba20096
--- /dev/null
+++ b/connman/src/bridge.c
@@ -0,0 +1,141 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2013  Intel Corporation. All rights reserved.
+ *  Copyright (C) 2012-2014  BMW Car IT GmbH.
+ *
+ *  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 <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <sys/ioctl.h>
+#include <net/if.h>
+#include <linux/sockios.h>
+#include <string.h>
+#include <fcntl.h>
+#include <linux/if_tun.h>
+
+#include "connman.h"
+
+static int set_forward_delay(const char *name, unsigned int delay)
+{
+	FILE *f;
+	char *forward_delay_path;
+
+	forward_delay_path =
+		g_strdup_printf("/sys/class/net/%s/bridge/forward_delay", name);
+
+	if (!forward_delay_path)
+		return -ENOMEM;
+
+	f = fopen(forward_delay_path, "r+");
+
+	g_free(forward_delay_path);
+
+	if (!f)
+		return -errno;
+
+	fprintf(f, "%d", delay);
+
+	fclose(f);
+
+	return 0;
+}
+
+int __connman_bridge_create(const char *name)
+{
+	int sk, err;
+
+	DBG("name %s", name);
+
+	sk = socket(AF_INET, SOCK_STREAM | SOCK_CLOEXEC, 0);
+	if (sk < 0)
+		return -EOPNOTSUPP;
+
+	if (ioctl(sk, SIOCBRADDBR, name) == -1) {
+		err = -errno;
+		if (err != -EEXIST) {
+			close(sk);
+			return -EOPNOTSUPP;
+		}
+	}
+
+	err = set_forward_delay(name, 0);
+
+	if (err < 0)
+		ioctl(sk, SIOCBRDELBR, name);
+
+	close(sk);
+
+	return err;
+}
+
+int __connman_bridge_remove(const char *name)
+{
+	int sk, err;
+
+	DBG("name %s", name);
+
+	sk = socket(AF_INET, SOCK_STREAM | SOCK_CLOEXEC, 0);
+	if (sk < 0)
+		return -EOPNOTSUPP;
+
+	err = ioctl(sk, SIOCBRDELBR, name);
+
+	close(sk);
+
+	if (err < 0)
+		return -EOPNOTSUPP;
+
+	return 0;
+}
+
+int __connman_bridge_enable(const char *name, const char *ip_address,
+			int prefix_len, const char *broadcast)
+{
+	int err, index;
+
+	index = connman_inet_ifindex(name);
+	if (index < 0)
+		return index;
+
+	err = __connman_inet_modify_address(RTM_NEWADDR,
+				NLM_F_REPLACE | NLM_F_ACK, index, AF_INET,
+				ip_address, NULL, prefix_len, broadcast);
+	if (err < 0)
+		return err;
+
+	return connman_inet_ifup(index);
+}
+
+int __connman_bridge_disable(const char *name)
+{
+	int index;
+
+	index = connman_inet_ifindex(name);
+	if (index < 0)
+		return index;
+
+	return connman_inet_ifdown(index);
+}
diff --git a/connman/src/clock.c b/connman/src/clock.c
new file mode 100644
index 0000000..0fde2c3
--- /dev/null
+++ b/connman/src/clock.c
@@ -0,0 +1,440 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2013  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 <sys/time.h>
+
+#include <gdbus.h>
+
+#include "connman.h"
+
+enum timezone_updates {
+	TIMEZONE_UPDATES_UNKNOWN = 0,
+	TIMEZONE_UPDATES_MANUAL  = 1,
+	TIMEZONE_UPDATES_AUTO    = 2,
+};
+
+static enum time_updates time_updates_config = TIME_UPDATES_AUTO;
+static enum timezone_updates timezone_updates_config = TIMEZONE_UPDATES_AUTO;
+
+static char *timezone_config = NULL;
+
+static const char *time_updates2string(enum time_updates value)
+{
+	switch (value) {
+	case TIME_UPDATES_UNKNOWN:
+		break;
+	case TIME_UPDATES_MANUAL:
+		return "manual";
+	case TIME_UPDATES_AUTO:
+		return "auto";
+	}
+
+	return NULL;
+}
+
+static enum time_updates string2time_updates(const char *value)
+{
+	if (g_strcmp0(value, "manual") == 0)
+		return TIME_UPDATES_MANUAL;
+	else if (g_strcmp0(value, "auto") == 0)
+		return TIME_UPDATES_AUTO;
+
+	return TIME_UPDATES_UNKNOWN;
+}
+
+static const char *timezone_updates2string(enum timezone_updates value)
+{
+	switch (value) {
+	case TIMEZONE_UPDATES_UNKNOWN:
+		break;
+	case TIMEZONE_UPDATES_MANUAL:
+		return "manual";
+	case TIMEZONE_UPDATES_AUTO:
+		return "auto";
+	}
+
+	return NULL;
+}
+
+static enum timezone_updates string2timezone_updates(const char *value)
+{
+	if (g_strcmp0(value, "manual") == 0)
+		return TIMEZONE_UPDATES_MANUAL;
+	else if (g_strcmp0(value, "auto") == 0)
+		return TIMEZONE_UPDATES_AUTO;
+
+        return TIMEZONE_UPDATES_UNKNOWN;
+}
+
+static void clock_properties_load(void)
+{
+	GKeyFile *keyfile;
+	char *str;
+	enum time_updates time_value;
+	enum timezone_updates timezone_value;
+
+	keyfile = __connman_storage_load_global();
+	if (!keyfile)
+		return;
+
+	str = g_key_file_get_string(keyfile, "global", "TimeUpdates", NULL);
+
+	time_value = string2time_updates(str);
+	if (time_value != TIME_UPDATES_UNKNOWN)
+		time_updates_config = time_value;
+
+	g_free(str);
+
+	str = g_key_file_get_string(keyfile, "global", "TimezoneUpdates",
+			NULL);
+
+	timezone_value = string2timezone_updates(str);
+	if (timezone_value != TIMEZONE_UPDATES_UNKNOWN)
+		timezone_updates_config = timezone_value;
+
+	g_free(str);
+
+	g_key_file_free(keyfile);
+}
+
+static void clock_properties_save(void)
+{
+	GKeyFile *keyfile;
+	const char *str;
+
+	keyfile = __connman_storage_load_global();
+	if (!keyfile)
+		keyfile = g_key_file_new();
+
+	str = time_updates2string(time_updates_config);
+	if (str)
+		g_key_file_set_string(keyfile, "global", "TimeUpdates", str);
+	else
+		g_key_file_remove_key(keyfile, "global", "TimeUpdates", NULL);
+
+	str = timezone_updates2string(timezone_updates_config);
+	if (str)
+		g_key_file_set_string(keyfile, "global", "TimezoneUpdates",
+				str);
+	else
+		g_key_file_remove_key(keyfile, "global", "TimezoneUpdates",
+				NULL);
+
+	__connman_storage_save_global(keyfile);
+
+	g_key_file_free(keyfile);
+}
+
+enum time_updates __connman_clock_timeupdates(void)
+{
+	return time_updates_config;
+}
+
+static void append_timeservers(DBusMessageIter *iter, void *user_data)
+{
+	int i;
+	char **timeservers = __connman_timeserver_system_get();
+
+	if (!timeservers)
+		return;
+
+	for (i = 0; timeservers[i]; i++) {
+		dbus_message_iter_append_basic(iter,
+				DBUS_TYPE_STRING, &timeservers[i]);
+	}
+
+	g_strfreev(timeservers);
+}
+
+static DBusMessage *get_properties(DBusConnection *conn,
+					DBusMessage *msg, void *data)
+{
+	DBusMessage *reply;
+	DBusMessageIter array, dict;
+	struct timeval tv;
+	const char *str;
+
+	DBG("conn %p", conn);
+
+	reply = dbus_message_new_method_return(msg);
+	if (!reply)
+		return NULL;
+
+	dbus_message_iter_init_append(reply, &array);
+
+	connman_dbus_dict_open(&array, &dict);
+
+	if (gettimeofday(&tv, NULL) == 0) {
+		dbus_uint64_t val = tv.tv_sec;
+
+		connman_dbus_dict_append_basic(&dict, "Time",
+						DBUS_TYPE_UINT64, &val);
+	}
+
+	str = time_updates2string(time_updates_config);
+	if (str)
+		connman_dbus_dict_append_basic(&dict, "TimeUpdates",
+						DBUS_TYPE_STRING, &str);
+
+	if (timezone_config)
+		connman_dbus_dict_append_basic(&dict, "Timezone",
+					DBUS_TYPE_STRING, &timezone_config);
+
+	str = timezone_updates2string(timezone_updates_config);
+	if (str)
+		connman_dbus_dict_append_basic(&dict, "TimezoneUpdates",
+						DBUS_TYPE_STRING, &str);
+
+	connman_dbus_dict_append_array(&dict, "Timeservers",
+				DBUS_TYPE_STRING, append_timeservers, NULL);
+
+	connman_dbus_dict_close(&array, &dict);
+
+	return reply;
+}
+
+static DBusMessage *set_property(DBusConnection *conn,
+					DBusMessage *msg, void *data)
+{
+	DBusMessageIter iter, value;
+	const char *name;
+	int type;
+
+	DBG("conn %p", conn);
+
+	if (!dbus_message_iter_init(msg, &iter))
+		return __connman_error_invalid_arguments(msg);
+
+	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
+		return __connman_error_invalid_arguments(msg);
+
+	dbus_message_iter_get_basic(&iter, &name);
+	dbus_message_iter_next(&iter);
+
+	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT)
+		return __connman_error_invalid_arguments(msg);
+
+	dbus_message_iter_recurse(&iter, &value);
+
+	type = dbus_message_iter_get_arg_type(&value);
+
+	if (g_str_equal(name, "Time")) {
+		struct timeval tv;
+		dbus_uint64_t newval;
+
+		if (type != DBUS_TYPE_UINT64)
+			return __connman_error_invalid_arguments(msg);
+
+		if (time_updates_config != TIME_UPDATES_MANUAL)
+			return __connman_error_permission_denied(msg);
+
+		dbus_message_iter_get_basic(&value, &newval);
+
+		tv.tv_sec = newval;
+		tv.tv_usec = 0;
+
+		if (settimeofday(&tv, NULL) < 0)
+			return __connman_error_invalid_arguments(msg);
+
+		connman_dbus_property_changed_basic(CONNMAN_MANAGER_PATH,
+				CONNMAN_CLOCK_INTERFACE, "Time",
+				DBUS_TYPE_UINT64, &newval);
+	} else if (g_str_equal(name, "TimeUpdates")) {
+		const char *strval;
+		enum time_updates newval;
+
+		if (type != DBUS_TYPE_STRING)
+			return __connman_error_invalid_arguments(msg);
+
+		dbus_message_iter_get_basic(&value, &strval);
+		newval = string2time_updates(strval);
+
+		if (newval == TIME_UPDATES_UNKNOWN)
+			return __connman_error_invalid_arguments(msg);
+
+		if (newval == time_updates_config)
+			return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+
+		time_updates_config = newval;
+
+		clock_properties_save();
+		connman_dbus_property_changed_basic(CONNMAN_MANAGER_PATH,
+				CONNMAN_CLOCK_INTERFACE, "TimeUpdates",
+				DBUS_TYPE_STRING, &strval);
+	} else if (g_str_equal(name, "Timezone")) {
+		const char *strval;
+
+		if (type != DBUS_TYPE_STRING)
+			return __connman_error_invalid_arguments(msg);
+
+		if (timezone_updates_config != TIMEZONE_UPDATES_MANUAL)
+			return __connman_error_permission_denied(msg);
+
+		dbus_message_iter_get_basic(&value, &strval);
+
+		if (__connman_timezone_change(strval) < 0)
+			return __connman_error_invalid_arguments(msg);
+	} else if (g_str_equal(name, "TimezoneUpdates")) {
+		const char *strval;
+		enum timezone_updates newval;
+
+		if (type != DBUS_TYPE_STRING)
+			return __connman_error_invalid_arguments(msg);
+
+		dbus_message_iter_get_basic(&value, &strval);
+		newval = string2timezone_updates(strval);
+
+		if (newval == TIMEZONE_UPDATES_UNKNOWN)
+			return __connman_error_invalid_arguments(msg);
+
+		if (newval == timezone_updates_config)
+			return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+
+		timezone_updates_config = newval;
+
+		clock_properties_save();
+		connman_dbus_property_changed_basic(CONNMAN_MANAGER_PATH,
+				CONNMAN_CLOCK_INTERFACE, "TimezoneUpdates",
+				DBUS_TYPE_STRING, &strval);
+	} else if (g_str_equal(name, "Timeservers")) {
+		DBusMessageIter entry;
+		char **str = NULL;
+		GSList *list = NULL;
+		int count = 0;
+
+		if (type != DBUS_TYPE_ARRAY)
+			return __connman_error_invalid_arguments(msg);
+
+		dbus_message_iter_recurse(&value, &entry);
+
+		while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
+			const char *val;
+			GSList *new_head;
+
+			dbus_message_iter_get_basic(&entry, &val);
+
+			new_head = __connman_timeserver_add_list(list, val);
+			if (list != new_head) {
+				count++;
+				list = new_head;
+			}
+
+			dbus_message_iter_next(&entry);
+		}
+
+		if (list) {
+			str = g_new0(char *, count+1);
+
+			while (list) {
+				count--;
+				str[count] = list->data;
+				list = g_slist_delete_link(list, list);
+			};
+		}
+
+		__connman_timeserver_system_set(str);
+
+		if (str)
+			g_strfreev(str);
+
+		connman_dbus_property_changed_array(CONNMAN_MANAGER_PATH,
+				CONNMAN_CLOCK_INTERFACE, "Timeservers",
+				DBUS_TYPE_STRING, append_timeservers, NULL);
+	} else
+		return __connman_error_invalid_property(msg);
+
+	return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+}
+
+static const GDBusMethodTable clock_methods[] = {
+	{ GDBUS_METHOD("GetProperties",
+			NULL, GDBUS_ARGS({ "properties", "a{sv}" }),
+			get_properties) },
+	{ GDBUS_METHOD("SetProperty",
+			GDBUS_ARGS({ "name", "s" }, { "value", "v" }), NULL,
+			set_property)   },
+	{ },
+};
+
+static const GDBusSignalTable clock_signals[] = {
+	{ GDBUS_SIGNAL("PropertyChanged",
+			GDBUS_ARGS({ "name", "s" }, { "value", "v" })) },
+	{ },
+};
+
+static DBusConnection *connection = NULL;
+
+void __connman_clock_update_timezone(void)
+{
+	DBG("");
+
+	g_free(timezone_config);
+	timezone_config = __connman_timezone_lookup();
+
+	if (!timezone_config)
+		return;
+
+	connman_dbus_property_changed_basic(CONNMAN_MANAGER_PATH,
+				CONNMAN_CLOCK_INTERFACE, "Timezone",
+				DBUS_TYPE_STRING, &timezone_config);
+}
+
+int __connman_clock_init(void)
+{
+	DBG("");
+
+	connection = connman_dbus_get_connection();
+	if (!connection)
+		return -1;
+
+	__connman_timezone_init();
+
+	timezone_config = __connman_timezone_lookup();
+
+	g_dbus_register_interface(connection, CONNMAN_MANAGER_PATH,
+						CONNMAN_CLOCK_INTERFACE,
+						clock_methods, clock_signals,
+						NULL, NULL, NULL);
+
+	clock_properties_load();
+	return 0;
+}
+
+void __connman_clock_cleanup(void)
+{
+	DBG("");
+
+	if (!connection)
+		return;
+
+	g_dbus_unregister_interface(connection, CONNMAN_MANAGER_PATH,
+						CONNMAN_CLOCK_INTERFACE);
+
+	dbus_connection_unref(connection);
+
+	__connman_timezone_cleanup();
+
+	g_free(timezone_config);
+}
diff --git a/connman/src/config.c b/connman/src/config.c
new file mode 100644
index 0000000..5bf5cf1
--- /dev/null
+++ b/connman/src/config.c
@@ -0,0 +1,1623 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2013  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 <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <sys/vfs.h>
+#include <sys/inotify.h>
+#include <netdb.h>
+#include <glib.h>
+
+#include <connman/provision.h>
+#include <connman/ipaddress.h>
+#include "connman.h"
+
+struct connman_config_service {
+	char *ident;
+	char *name;
+	char *type;
+	void *ssid;
+	unsigned int ssid_len;
+	char *eap;
+	char *identity;
+	char *ca_cert_file;
+	char *client_cert_file;
+	char *private_key_file;
+	char *private_key_passphrase;
+	char *private_key_passphrase_type;
+	char *phase2;
+	char *passphrase;
+	enum connman_service_security security;
+	GSList *service_identifiers;
+	char *config_ident; /* file prefix */
+	char *config_entry; /* entry name */
+	bool hidden;
+	bool virtual;
+	char *virtual_file;
+	char *ipv4_address;
+	char *ipv4_netmask;
+	char *ipv4_gateway;
+	char *ipv6_address;
+	unsigned char ipv6_prefix_length;
+	char *ipv6_gateway;
+	char *ipv6_privacy;
+	char *mac;
+	char **nameservers;
+	char **search_domains;
+	char **timeservers;
+	char *domain_name;
+};
+
+struct connman_config {
+	char *ident;
+	char *name;
+	char *description;
+	GHashTable *service_table;
+};
+
+static GHashTable *config_table = NULL;
+
+static bool cleanup = false;
+
+/* Definition of possible strings in the .config files */
+#define CONFIG_KEY_NAME                "Name"
+#define CONFIG_KEY_DESC                "Description"
+
+#define SERVICE_KEY_TYPE               "Type"
+#define SERVICE_KEY_NAME               "Name"
+#define SERVICE_KEY_SSID               "SSID"
+#define SERVICE_KEY_EAP                "EAP"
+#define SERVICE_KEY_CA_CERT            "CACertFile"
+#define SERVICE_KEY_CL_CERT            "ClientCertFile"
+#define SERVICE_KEY_PRV_KEY            "PrivateKeyFile"
+#define SERVICE_KEY_PRV_KEY_PASS       "PrivateKeyPassphrase"
+#define SERVICE_KEY_PRV_KEY_PASS_TYPE  "PrivateKeyPassphraseType"
+#define SERVICE_KEY_IDENTITY           "Identity"
+#define SERVICE_KEY_PHASE2             "Phase2"
+#define SERVICE_KEY_PASSPHRASE         "Passphrase"
+#define SERVICE_KEY_SECURITY           "Security"
+#define SERVICE_KEY_HIDDEN             "Hidden"
+
+#define SERVICE_KEY_IPv4               "IPv4"
+#define SERVICE_KEY_IPv6               "IPv6"
+#define SERVICE_KEY_IPv6_PRIVACY       "IPv6.Privacy"
+#define SERVICE_KEY_MAC                "MAC"
+#define SERVICE_KEY_NAMESERVERS        "Nameservers"
+#define SERVICE_KEY_SEARCH_DOMAINS     "SearchDomains"
+#define SERVICE_KEY_TIMESERVERS        "Timeservers"
+#define SERVICE_KEY_DOMAIN             "Domain"
+
+static const char *config_possible_keys[] = {
+	CONFIG_KEY_NAME,
+	CONFIG_KEY_DESC,
+	NULL,
+};
+
+static const char *service_possible_keys[] = {
+	SERVICE_KEY_TYPE,
+	SERVICE_KEY_NAME,
+	SERVICE_KEY_SSID,
+	SERVICE_KEY_EAP,
+	SERVICE_KEY_CA_CERT,
+	SERVICE_KEY_CL_CERT,
+	SERVICE_KEY_PRV_KEY,
+	SERVICE_KEY_PRV_KEY_PASS,
+	SERVICE_KEY_PRV_KEY_PASS_TYPE,
+	SERVICE_KEY_IDENTITY,
+	SERVICE_KEY_PHASE2,
+	SERVICE_KEY_PASSPHRASE,
+	SERVICE_KEY_SECURITY,
+	SERVICE_KEY_HIDDEN,
+	SERVICE_KEY_IPv4,
+	SERVICE_KEY_IPv6,
+	SERVICE_KEY_IPv6_PRIVACY,
+	SERVICE_KEY_MAC,
+	SERVICE_KEY_NAMESERVERS,
+	SERVICE_KEY_SEARCH_DOMAINS,
+	SERVICE_KEY_TIMESERVERS,
+	SERVICE_KEY_DOMAIN,
+	NULL,
+};
+
+static void unregister_config(gpointer data)
+{
+	struct connman_config *config = data;
+
+	connman_info("Removing configuration %s", config->ident);
+
+	g_hash_table_destroy(config->service_table);
+
+	g_free(config->description);
+	g_free(config->name);
+	g_free(config->ident);
+	g_free(config);
+}
+
+static void unregister_service(gpointer data)
+{
+	struct connman_config_service *config_service = data;
+	struct connman_service *service;
+	char *service_id;
+	GSList *list;
+
+	if (cleanup)
+		goto free_only;
+
+	connman_info("Removing service configuration %s",
+						config_service->ident);
+
+	if (config_service->virtual)
+		goto free_only;
+
+	for (list = config_service->service_identifiers; list;
+							list = list->next) {
+		service_id = list->data;
+
+		service = __connman_service_lookup_from_ident(service_id);
+		if (service) {
+			__connman_service_set_immutable(service, false);
+			__connman_service_set_config(service, NULL, NULL);
+			__connman_service_remove(service);
+
+			/*
+			 * Ethernet or gadget service cannot be removed by
+			 * __connman_service_remove() so reset the ipconfig
+			 * here.
+			 */
+			if (connman_service_get_type(service) ==
+						CONNMAN_SERVICE_TYPE_ETHERNET ||
+					connman_service_get_type(service) ==
+						CONNMAN_SERVICE_TYPE_GADGET) {
+				__connman_service_disconnect(service);
+				__connman_service_reset_ipconfig(service,
+					CONNMAN_IPCONFIG_TYPE_IPV4, NULL, NULL);
+				__connman_service_reset_ipconfig(service,
+					CONNMAN_IPCONFIG_TYPE_IPV6, NULL, NULL);
+				__connman_service_set_ignore(service, true);
+
+				/*
+				 * After these operations, user needs to
+				 * reconnect ethernet cable to get IP
+				 * address.
+				 */
+			}
+		}
+
+		if (!__connman_storage_remove_service(service_id))
+			DBG("Could not remove all files for service %s",
+								service_id);
+	}
+
+free_only:
+	g_free(config_service->ident);
+	g_free(config_service->type);
+	g_free(config_service->name);
+	g_free(config_service->ssid);
+	g_free(config_service->eap);
+	g_free(config_service->identity);
+	g_free(config_service->ca_cert_file);
+	g_free(config_service->client_cert_file);
+	g_free(config_service->private_key_file);
+	g_free(config_service->private_key_passphrase);
+	g_free(config_service->private_key_passphrase_type);
+	g_free(config_service->phase2);
+	g_free(config_service->passphrase);
+	g_free(config_service->ipv4_address);
+	g_free(config_service->ipv4_gateway);
+	g_free(config_service->ipv4_netmask);
+	g_free(config_service->ipv6_address);
+	g_free(config_service->ipv6_gateway);
+	g_free(config_service->ipv6_privacy);
+	g_free(config_service->mac);
+	g_strfreev(config_service->nameservers);
+	g_strfreev(config_service->search_domains);
+	g_strfreev(config_service->timeservers);
+	g_free(config_service->domain_name);
+	g_slist_free_full(config_service->service_identifiers, g_free);
+	g_free(config_service->config_ident);
+	g_free(config_service->config_entry);
+	g_free(config_service->virtual_file);
+	g_free(config_service);
+}
+
+static void check_keys(GKeyFile *keyfile, const char *group,
+			const char **possible_keys)
+{
+	char **avail_keys;
+	gsize nb_avail_keys, i, j;
+
+	avail_keys = g_key_file_get_keys(keyfile, group, &nb_avail_keys, NULL);
+	if (!avail_keys)
+		return;
+
+	/*
+	 * For each key in the configuration file,
+	 * verify it is understood by connman
+	 */
+	for (i = 0 ; i < nb_avail_keys; i++) {
+		for (j = 0; possible_keys[j] ; j++)
+			if (g_strcmp0(avail_keys[i], possible_keys[j]) == 0)
+				break;
+
+		if (!possible_keys[j])
+			connman_warn("Unknown configuration key %s in [%s]",
+					avail_keys[i], group);
+	}
+
+	g_strfreev(avail_keys);
+}
+
+static int check_family(const char *address, int expected_family)
+{
+	int family;
+	int err = 0;
+
+	family = connman_inet_check_ipaddress(address);
+	if (family < 0) {
+		DBG("Cannot get address family of %s (%d/%s)", address,
+			family, gai_strerror(family));
+		err = -EINVAL;
+		goto out;
+	}
+
+	switch (family) {
+	case AF_INET:
+		if (expected_family != AF_INET) {
+			DBG("Wrong type address %s, expecting IPv4", address);
+			err = -EINVAL;
+			goto out;
+		}
+		break;
+	case AF_INET6:
+		if (expected_family != AF_INET6) {
+			DBG("Wrong type address %s, expecting IPv6", address);
+			err = -EINVAL;
+			goto out;
+		}
+		break;
+	default:
+		DBG("Unsupported address family %d", family);
+		err = -EINVAL;
+		goto out;
+	}
+
+out:
+	return err;
+}
+
+static int parse_address(const char *address_str, int address_family,
+			char **address, char **netmask, char **gateway)
+{
+	char *addr_str, *mask_str, *gw_str;
+	int err = 0;
+	char **route;
+
+	route = g_strsplit(address_str, "/", 0);
+	if (!route)
+		return -EINVAL;
+
+	addr_str = route[0];
+	if (!addr_str || addr_str[0] == '\0') {
+		err = -EINVAL;
+		goto out;
+	}
+
+	if ((err = check_family(addr_str, address_family)) < 0)
+		goto out;
+
+	mask_str = route[1];
+	if (!mask_str || mask_str[0] == '\0') {
+		err = -EINVAL;
+		goto out;
+	}
+
+	gw_str = route[2];
+	if (gw_str && gw_str[0]) {
+		if ((err = check_family(gw_str, address_family)) < 0)
+			goto out;
+	}
+
+	g_free(*address);
+	*address = g_strdup(addr_str);
+
+	g_free(*netmask);
+	*netmask = g_strdup(mask_str);
+
+	g_free(*gateway);
+	*gateway = g_strdup(gw_str);
+
+	if (*gateway)
+		DBG("address %s/%s via %s", *address, *netmask, *gateway);
+	else
+		DBG("address %s/%s", *address, *netmask);
+
+out:
+	g_strfreev(route);
+
+	return err;
+}
+
+static bool check_address(char *address_str, char **address)
+{
+	if (g_ascii_strcasecmp(address_str, "auto") == 0 ||
+			g_ascii_strcasecmp(address_str, "dhcp") == 0 ||
+			g_ascii_strcasecmp(address_str, "off") == 0) {
+		*address = address_str;
+		return false;
+	}
+
+	return true;
+}
+
+static bool load_service_generic(GKeyFile *keyfile,
+			const char *group, struct connman_config *config,
+			struct connman_config_service *service)
+{
+	char *str, *mask;
+	char **strlist;
+	gsize length;
+
+	str = __connman_config_get_string(keyfile, group, SERVICE_KEY_IPv4, NULL);
+	if (str && check_address(str, &service->ipv4_address)) {
+		mask = NULL;
+
+		if (parse_address(str, AF_INET, &service->ipv4_address,
+					&mask, &service->ipv4_gateway) < 0) {
+			connman_warn("Invalid format for IPv4 address %s",
+									str);
+			g_free(str);
+			goto err;
+		}
+
+		if (!g_strrstr(mask, ".")) {
+			/* We have netmask length */
+			in_addr_t addr;
+			struct in_addr netmask_in;
+			unsigned char prefix_len = 32;
+			char *ptr;
+			long int value = strtol(mask, &ptr, 10);
+
+			if (ptr != mask && *ptr == '\0' && value && value <= 32)
+				prefix_len = value;
+
+			addr = 0xffffffff << (32 - prefix_len);
+			netmask_in.s_addr = htonl(addr);
+			service->ipv4_netmask =
+				g_strdup(inet_ntoa(netmask_in));
+
+			g_free(mask);
+		} else
+			service->ipv4_netmask = mask;
+
+		g_free(str);
+	}
+
+	str =  __connman_config_get_string(keyfile, group, SERVICE_KEY_IPv6, NULL);
+	if (str && check_address(str, &service->ipv6_address)) {
+		long int value;
+		char *ptr;
+
+		mask = NULL;
+
+		if (parse_address(str, AF_INET6, &service->ipv6_address,
+					&mask, &service->ipv6_gateway) < 0) {
+			connman_warn("Invalid format for IPv6 address %s",
+									str);
+			g_free(str);
+			goto err;
+		}
+
+		value = strtol(mask, &ptr, 10);
+		if (ptr != mask && *ptr == '\0' && value <= 128)
+			service->ipv6_prefix_length = value;
+		else
+			service->ipv6_prefix_length = 128;
+
+		g_free(mask);
+		g_free(str);
+	}
+
+	str = __connman_config_get_string(keyfile, group, SERVICE_KEY_IPv6_PRIVACY,
+									NULL);
+	if (str) {
+		g_free(service->ipv6_privacy);
+		service->ipv6_privacy = str;
+	}
+
+	str = __connman_config_get_string(keyfile, group, SERVICE_KEY_MAC, NULL);
+	if (str) {
+		g_free(service->mac);
+		service->mac = str;
+	}
+
+	str = __connman_config_get_string(keyfile, group, SERVICE_KEY_DOMAIN, NULL);
+	if (str) {
+		g_free(service->domain_name);
+		service->domain_name = str;
+	}
+
+	strlist = __connman_config_get_string_list(keyfile, group,
+					SERVICE_KEY_NAMESERVERS,
+					&length, NULL);
+	if (strlist) {
+		if (length != 0) {
+			g_strfreev(service->nameservers);
+			service->nameservers = strlist;
+		} else
+			g_strfreev(strlist);
+	}
+
+	strlist = __connman_config_get_string_list(keyfile, group,
+					SERVICE_KEY_SEARCH_DOMAINS,
+					&length, NULL);
+	if (strlist) {
+		if (length != 0) {
+			g_strfreev(service->search_domains);
+			service->search_domains = strlist;
+		} else
+			g_strfreev(strlist);
+	}
+
+	strlist = __connman_config_get_string_list(keyfile, group,
+					SERVICE_KEY_TIMESERVERS,
+					&length, NULL);
+	if (strlist) {
+		if (length != 0) {
+			g_strfreev(service->timeservers);
+			service->timeservers = strlist;
+		} else
+			g_strfreev(strlist);
+	}
+
+	return true;
+
+err:
+	g_free(service->ident);
+	g_free(service->type);
+	g_free(service->ipv4_address);
+	g_free(service->ipv4_netmask);
+	g_free(service->ipv4_gateway);
+	g_free(service->ipv6_address);
+	g_free(service->ipv6_gateway);
+	g_free(service->mac);
+	g_free(service);
+
+	return false;
+}
+
+static bool load_service(GKeyFile *keyfile, const char *group,
+						struct connman_config *config)
+{
+	struct connman_config_service *service;
+	const char *ident;
+	char *str, *hex_ssid;
+	enum connman_service_security security;
+	bool service_created = false;
+
+	/* Strip off "service_" prefix */
+	ident = group + 8;
+
+	if (strlen(ident) < 1)
+		return false;
+
+	/* Verify that provided keys are good */
+	check_keys(keyfile, group, service_possible_keys);
+
+	service = g_hash_table_lookup(config->service_table, ident);
+	if (!service) {
+		service = g_try_new0(struct connman_config_service, 1);
+		if (!service)
+			return false;
+
+		service->ident = g_strdup(ident);
+
+		service_created = true;
+	}
+
+	str = __connman_config_get_string(keyfile, group, SERVICE_KEY_TYPE, NULL);
+	if (str) {
+		g_free(service->type);
+		service->type = str;
+	} else {
+		DBG("Type of the configured service is missing for group %s",
+									group);
+		goto err;
+	}
+
+	if (!load_service_generic(keyfile, group, config, service))
+		return false;
+
+	if (g_strcmp0(str, "ethernet") == 0) {
+		service->config_ident = g_strdup(config->ident);
+		service->config_entry = g_strdup_printf("service_%s",
+							service->ident);
+
+		g_hash_table_insert(config->service_table, service->ident,
+								service);
+		return true;
+	}
+
+	str = __connman_config_get_string(keyfile, group, SERVICE_KEY_NAME, NULL);
+	if (str) {
+		g_free(service->name);
+		service->name = str;
+	}
+
+	hex_ssid = __connman_config_get_string(keyfile, group, SERVICE_KEY_SSID,
+					 NULL);
+	if (hex_ssid) {
+		char *ssid;
+		unsigned int i, j = 0, hex;
+		size_t hex_ssid_len = strlen(hex_ssid);
+
+		ssid = g_try_malloc0(hex_ssid_len / 2);
+		if (!ssid) {
+			g_free(hex_ssid);
+			goto err;
+		}
+
+		for (i = 0; i < hex_ssid_len; i += 2) {
+			if (sscanf(hex_ssid + i, "%02x", &hex) <= 0) {
+				connman_warn("Invalid SSID %s", hex_ssid);
+				g_free(ssid);
+				g_free(hex_ssid);
+				goto err;
+			}
+			ssid[j++] = hex;
+		}
+
+		g_free(hex_ssid);
+
+		g_free(service->ssid);
+		service->ssid = ssid;
+		service->ssid_len = hex_ssid_len / 2;
+	} else if (service->name) {
+		char *ssid;
+		unsigned int ssid_len;
+
+		ssid_len = strlen(service->name);
+		ssid = g_try_malloc0(ssid_len);
+		if (!ssid)
+			goto err;
+
+		memcpy(ssid, service->name, ssid_len);
+		g_free(service->ssid);
+		service->ssid = ssid;
+		service->ssid_len = ssid_len;
+	}
+
+	str = __connman_config_get_string(keyfile, group, SERVICE_KEY_EAP, NULL);
+	if (str) {
+		g_free(service->eap);
+		service->eap = str;
+	}
+
+	str = __connman_config_get_string(keyfile, group, SERVICE_KEY_CA_CERT, NULL);
+	if (str) {
+		g_free(service->ca_cert_file);
+		service->ca_cert_file = str;
+	}
+
+	str = __connman_config_get_string(keyfile, group, SERVICE_KEY_CL_CERT, NULL);
+	if (str) {
+		g_free(service->client_cert_file);
+		service->client_cert_file = str;
+	}
+
+	str = __connman_config_get_string(keyfile, group, SERVICE_KEY_PRV_KEY, NULL);
+	if (str) {
+		g_free(service->private_key_file);
+		service->private_key_file = str;
+	}
+
+	str = __connman_config_get_string(keyfile, group,
+						SERVICE_KEY_PRV_KEY_PASS, NULL);
+	if (str) {
+		g_free(service->private_key_passphrase);
+		service->private_key_passphrase = str;
+	}
+
+	str = __connman_config_get_string(keyfile, group,
+					SERVICE_KEY_PRV_KEY_PASS_TYPE, NULL);
+	if (str) {
+		g_free(service->private_key_passphrase_type);
+		service->private_key_passphrase_type = str;
+	}
+
+	str = __connman_config_get_string(keyfile, group, SERVICE_KEY_IDENTITY, NULL);
+	if (str) {
+		g_free(service->identity);
+		service->identity = str;
+	}
+
+	str = __connman_config_get_string(keyfile, group, SERVICE_KEY_PHASE2, NULL);
+	if (str) {
+		g_free(service->phase2);
+		service->phase2 = str;
+	}
+
+	str = __connman_config_get_string(keyfile, group, SERVICE_KEY_PASSPHRASE,
+					NULL);
+	if (str) {
+		g_free(service->passphrase);
+		service->passphrase = str;
+	}
+
+	str = __connman_config_get_string(keyfile, group, SERVICE_KEY_SECURITY,
+			NULL);
+	security = __connman_service_string2security(str);
+
+	if (service->eap) {
+
+		if (str && security != CONNMAN_SERVICE_SECURITY_8021X)
+			connman_info("Mismatch between EAP configuration and "
+					"setting %s = %s",
+					SERVICE_KEY_SECURITY, str);
+
+		service->security = CONNMAN_SERVICE_SECURITY_8021X;
+
+	} else if (service->passphrase) {
+
+		if (str) {
+			if (security == CONNMAN_SERVICE_SECURITY_PSK ||
+					security == CONNMAN_SERVICE_SECURITY_WEP) {
+				service->security = security;
+			} else {
+				connman_info("Mismatch with passphrase and "
+						"setting %s = %s",
+						SERVICE_KEY_SECURITY, str);
+
+				service->security =
+					CONNMAN_SERVICE_SECURITY_PSK;
+			}
+
+		} else
+			service->security = CONNMAN_SERVICE_SECURITY_PSK;
+	} else if (str) {
+
+		if (security != CONNMAN_SERVICE_SECURITY_NONE)
+			connman_info("Mismatch no security and "
+					"setting %s = %s",
+					SERVICE_KEY_SECURITY, str);
+
+			service->security = CONNMAN_SERVICE_SECURITY_NONE;
+	} else
+			service->security = CONNMAN_SERVICE_SECURITY_NONE;
+
+	service->config_ident = g_strdup(config->ident);
+	service->config_entry = g_strdup_printf("service_%s", service->ident);
+
+	service->hidden = __connman_config_get_bool(keyfile, group,
+						SERVICE_KEY_HIDDEN, NULL);
+
+	if (service_created)
+		g_hash_table_insert(config->service_table, service->ident,
+					service);
+
+	connman_info("Adding service configuration %s", service->ident);
+
+	return true;
+
+err:
+	if (service_created) {
+		g_free(service->ident);
+		g_free(service->type);
+		g_free(service->name);
+		g_free(service->ssid);
+		g_free(service);
+	}
+
+	return false;
+}
+
+static bool load_service_from_keyfile(GKeyFile *keyfile,
+						struct connman_config *config)
+{
+	bool found = false;
+	char **groups;
+	int i;
+
+	groups = g_key_file_get_groups(keyfile, NULL);
+
+	for (i = 0; groups[i]; i++) {
+		if (!g_str_has_prefix(groups[i], "service_"))
+			continue;
+		if (load_service(keyfile, groups[i], config))
+			found = true;
+	}
+
+	g_strfreev(groups);
+
+	return found;
+}
+
+static int load_config(struct connman_config *config)
+{
+	GKeyFile *keyfile;
+	char *str;
+
+	DBG("config %p", config);
+
+	keyfile = __connman_storage_load_config(config->ident);
+	if (!keyfile)
+		return -EIO;
+
+	g_key_file_set_list_separator(keyfile, ',');
+
+	/* Verify keys validity of the global section */
+	check_keys(keyfile, "global", config_possible_keys);
+
+	str = __connman_config_get_string(keyfile, "global", CONFIG_KEY_NAME, NULL);
+	if (str) {
+		g_free(config->name);
+		config->name = str;
+	}
+
+	str = __connman_config_get_string(keyfile, "global", CONFIG_KEY_DESC, NULL);
+	if (str) {
+		g_free(config->description);
+		config->description = str;
+	}
+
+	if (!load_service_from_keyfile(keyfile, config))
+		connman_warn("Config file %s/%s.config does not contain any "
+			"configuration that can be provisioned!",
+			STORAGEDIR, config->ident);
+
+	g_key_file_free(keyfile);
+
+	return 0;
+}
+
+static struct connman_config *create_config(const char *ident)
+{
+	struct connman_config *config;
+
+	DBG("ident %s", ident);
+
+	if (g_hash_table_lookup(config_table, ident))
+		return NULL;
+
+	config = g_try_new0(struct connman_config, 1);
+	if (!config)
+		return NULL;
+
+	config->ident = g_strdup(ident);
+
+	config->service_table = g_hash_table_new_full(g_str_hash, g_str_equal,
+						NULL, unregister_service);
+
+	g_hash_table_insert(config_table, config->ident, config);
+
+	connman_info("Adding configuration %s", config->ident);
+
+	return config;
+}
+
+static bool validate_ident(const char *ident)
+{
+	unsigned int i;
+
+	if (!ident)
+		return false;
+
+	for (i = 0; i < strlen(ident); i++)
+		if (!g_ascii_isprint(ident[i]))
+			return false;
+
+	return true;
+}
+
+static int read_configs(void)
+{
+	GDir *dir;
+
+	DBG("");
+
+	dir = g_dir_open(STORAGEDIR, 0, NULL);
+	if (dir) {
+		const gchar *file;
+
+		while ((file = g_dir_read_name(dir))) {
+			GString *str;
+			gchar *ident;
+
+			if (!g_str_has_suffix(file, ".config"))
+				continue;
+
+			ident = g_strrstr(file, ".config");
+			if (!ident)
+				continue;
+
+			str = g_string_new_len(file, ident - file);
+			if (!str)
+				continue;
+
+			ident = g_string_free(str, FALSE);
+
+			if (validate_ident(ident)) {
+				struct connman_config *config;
+
+				config = create_config(ident);
+				if (config)
+					load_config(config);
+			} else {
+				connman_error("Invalid config ident %s", ident);
+			}
+			g_free(ident);
+		}
+
+		g_dir_close(dir);
+	}
+
+	return 0;
+}
+
+static void config_notify_handler(struct inotify_event *event,
+                                        const char *ident)
+{
+	char *ext;
+
+	if (!ident)
+		return;
+
+	if (!g_str_has_suffix(ident, ".config"))
+		return;
+
+	ext = g_strrstr(ident, ".config");
+	if (!ext)
+		return;
+
+	*ext = '\0';
+
+	if (!validate_ident(ident)) {
+		connman_error("Invalid config ident %s", ident);
+		return;
+	}
+
+	if (event->mask & IN_CREATE || event->mask & IN_MOVED_TO)
+		create_config(ident);
+
+	if (event->mask & IN_MODIFY) {
+		struct connman_config *config;
+
+		config = g_hash_table_lookup(config_table, ident);
+		if (config) {
+			int ret;
+
+			g_hash_table_remove_all(config->service_table);
+			load_config(config);
+			ret = __connman_service_provision_changed(ident);
+			if (ret > 0) {
+				/*
+				 * Re-scan the config file for any
+				 * changes
+				 */
+				g_hash_table_remove_all(config->service_table);
+				load_config(config);
+				__connman_service_provision_changed(ident);
+			}
+		}
+	}
+
+	if (event->mask & IN_DELETE)
+		g_hash_table_remove(config_table, ident);
+}
+
+int __connman_config_init(void)
+{
+	DBG("");
+
+	config_table = g_hash_table_new_full(g_str_hash, g_str_equal,
+						NULL, unregister_config);
+
+	connman_inotify_register(STORAGEDIR, config_notify_handler);
+
+	return read_configs();
+}
+
+void __connman_config_cleanup(void)
+{
+	DBG("");
+
+	cleanup = true;
+
+	connman_inotify_unregister(STORAGEDIR, config_notify_handler);
+
+	g_hash_table_destroy(config_table);
+	config_table = NULL;
+
+	cleanup = false;
+}
+
+char *__connman_config_get_string(GKeyFile *key_file,
+	const char *group_name, const char *key, GError **error)
+{
+	char *str = g_key_file_get_string(key_file, group_name, key, error);
+	if (!str)
+		return NULL;
+
+	return g_strchomp(str);
+}
+
+char **__connman_config_get_string_list(GKeyFile *key_file,
+	const char *group_name, const char *key, gsize *length, GError **error)
+{
+	char **p;
+	char **strlist = g_key_file_get_string_list(key_file, group_name, key,
+		length, error);
+	if (!strlist)
+		return NULL;
+
+	p = strlist;
+	while (*p) {
+		*p = g_strstrip(*p);
+		p++;
+	}
+
+	return strlist;
+}
+
+bool __connman_config_get_bool(GKeyFile *key_file,
+	const char *group_name, const char *key, GError **error)
+{
+	char *valstr;
+	bool val = false;
+
+	valstr = g_key_file_get_value(key_file, group_name, key, error);
+	if (!valstr)
+		return false;
+
+	valstr = g_strchomp(valstr);
+	if (strcmp(valstr, "true") == 0 || strcmp(valstr, "1") == 0)
+		val = true;
+
+	g_free(valstr);
+
+	return val;
+}
+
+static char *config_pem_fsid(const char *pem_file)
+{
+	struct statfs buf;
+	unsigned *fsid = (unsigned *) &buf.f_fsid;
+	unsigned long long fsid64;
+
+	if (!pem_file)
+		return NULL;
+
+	if (statfs(pem_file, &buf) < 0) {
+		connman_error("statfs error %s for %s",
+						strerror(errno), pem_file);
+		return NULL;
+	}
+
+	fsid64 = ((unsigned long long) fsid[0] << 32) | fsid[1];
+
+	return g_strdup_printf("%llx", fsid64);
+}
+
+static void provision_service_wifi(struct connman_config_service *config,
+				struct connman_service *service,
+				struct connman_network *network,
+				const void *ssid, unsigned int ssid_len)
+{
+	if (config->eap)
+		__connman_service_set_string(service, "EAP", config->eap);
+
+	if (config->identity)
+		__connman_service_set_string(service, "Identity",
+							config->identity);
+
+	if (config->ca_cert_file)
+		__connman_service_set_string(service, "CACertFile",
+							config->ca_cert_file);
+
+	if (config->client_cert_file)
+		__connman_service_set_string(service, "ClientCertFile",
+						config->client_cert_file);
+
+	if (config->private_key_file)
+		__connman_service_set_string(service, "PrivateKeyFile",
+						config->private_key_file);
+
+	if (g_strcmp0(config->private_key_passphrase_type, "fsid") == 0 &&
+					config->private_key_file) {
+		char *fsid;
+
+		fsid = config_pem_fsid(config->private_key_file);
+		if (!fsid)
+			return;
+
+		g_free(config->private_key_passphrase);
+		config->private_key_passphrase = fsid;
+	}
+
+	if (config->private_key_passphrase) {
+		__connman_service_set_string(service, "PrivateKeyPassphrase",
+						config->private_key_passphrase);
+		/*
+		 * TODO: Support for PEAP with both identity and key passwd.
+		 * In that case, we should check if both of them are found
+		 * from the config file. If not, we should not set the
+		 * service passphrase in order for the UI to request for an
+		 * additional passphrase.
+		 */
+	}
+
+	if (config->phase2)
+		__connman_service_set_string(service, "Phase2", config->phase2);
+
+	if (config->passphrase)
+		__connman_service_set_string(service, "Passphrase",
+						config->passphrase);
+
+	if (config->hidden)
+		__connman_service_set_hidden(service);
+}
+
+struct connect_virtual {
+	struct connman_service *service;
+	const char *vfile;
+};
+
+static gboolean remove_virtual_config(gpointer user_data)
+{
+	struct connect_virtual *virtual = user_data;
+
+	__connman_service_connect(virtual->service,
+				CONNMAN_SERVICE_CONNECT_REASON_AUTO);
+	g_hash_table_remove(config_table, virtual->vfile);
+
+	g_free(virtual);
+
+	return FALSE;
+}
+
+static int try_provision_service(struct connman_config_service *config,
+				struct connman_service *service)
+{
+	struct connman_network *network;
+	const void *service_id;
+	enum connman_service_type type;
+	const void *ssid;
+	unsigned int ssid_len;
+	const char *str;
+
+	network = __connman_service_get_network(service);
+	if (!network) {
+		connman_error("Service has no network set");
+		return -EINVAL;
+	}
+
+	DBG("network %p ident %s", network,
+				connman_network_get_identifier(network));
+
+	type = connman_service_get_type(service);
+
+	switch(type) {
+	case CONNMAN_SERVICE_TYPE_WIFI:
+		if (__connman_service_string2type(config->type) != type)
+			return -ENOENT;
+
+		ssid = connman_network_get_blob(network, "WiFi.SSID",
+						&ssid_len);
+		if (!ssid) {
+			connman_error("Network SSID not set");
+			return -EINVAL;
+		}
+
+		if (!config->ssid || ssid_len != config->ssid_len)
+			return -ENOENT;
+
+		if (memcmp(config->ssid, ssid, ssid_len))
+			return -ENOENT;
+
+		str = connman_network_get_string(network, "WiFi.Security");
+		if (config->security != __connman_service_string2security(str))
+			return -ENOENT;
+
+		break;
+
+	case CONNMAN_SERVICE_TYPE_ETHERNET:
+	case CONNMAN_SERVICE_TYPE_GADGET:
+
+		if (__connman_service_string2type(config->type) != type)
+			return -ENOENT;
+
+		break;
+
+	case CONNMAN_SERVICE_TYPE_UNKNOWN:
+	case CONNMAN_SERVICE_TYPE_SYSTEM:
+	case CONNMAN_SERVICE_TYPE_BLUETOOTH:
+	case CONNMAN_SERVICE_TYPE_CELLULAR:
+	case CONNMAN_SERVICE_TYPE_GPS:
+	case CONNMAN_SERVICE_TYPE_VPN:
+	case CONNMAN_SERVICE_TYPE_P2P:
+
+		return -ENOENT;
+	}
+
+	DBG("service %p ident %s", service,
+					__connman_service_get_ident(service));
+
+	if (config->mac) {
+		struct connman_device *device;
+		const char *device_addr;
+
+		device = connman_network_get_device(network);
+		if (!device) {
+			connman_error("Network device is missing");
+			return -ENODEV;
+		}
+
+		device_addr = connman_device_get_string(device, "Address");
+
+		DBG("wants %s has %s", config->mac, device_addr);
+
+		if (g_ascii_strcasecmp(device_addr, config->mac) != 0)
+			return -ENOENT;
+	}
+
+	if (!config->ipv6_address) {
+		connman_network_set_ipv6_method(network,
+						CONNMAN_IPCONFIG_METHOD_AUTO);
+	} else if (g_ascii_strcasecmp(config->ipv6_address, "off") == 0) {
+		connman_network_set_ipv6_method(network,
+						CONNMAN_IPCONFIG_METHOD_OFF);
+	} else if (g_ascii_strcasecmp(config->ipv6_address, "auto") == 0 ||
+			g_ascii_strcasecmp(config->ipv6_address, "dhcp") == 0) {
+		connman_network_set_ipv6_method(network,
+						CONNMAN_IPCONFIG_METHOD_AUTO);
+	} else {
+		struct connman_ipaddress *address;
+
+		if (config->ipv6_prefix_length == 0) {
+			DBG("IPv6 prefix missing");
+			return -EINVAL;
+		}
+
+		address = connman_ipaddress_alloc(AF_INET6);
+		if (!address)
+			return -ENOENT;
+
+		connman_ipaddress_set_ipv6(address, config->ipv6_address,
+					config->ipv6_prefix_length,
+					config->ipv6_gateway);
+
+		connman_network_set_ipv6_method(network,
+						CONNMAN_IPCONFIG_METHOD_FIXED);
+
+		if (connman_network_set_ipaddress(network, address) < 0)
+			DBG("Unable to set IPv6 address to network %p",
+								network);
+
+		connman_ipaddress_free(address);
+	}
+
+	if (config->ipv6_privacy) {
+		struct connman_ipconfig *ipconfig;
+
+		ipconfig = __connman_service_get_ip6config(service);
+		if (ipconfig)
+			__connman_ipconfig_ipv6_set_privacy(ipconfig,
+							config->ipv6_privacy);
+	}
+
+	if (!config->ipv4_address) {
+		connman_network_set_ipv4_method(network,
+						CONNMAN_IPCONFIG_METHOD_DHCP);
+	} else if (g_ascii_strcasecmp(config->ipv4_address, "off") == 0) {
+		connman_network_set_ipv4_method(network,
+						CONNMAN_IPCONFIG_METHOD_OFF);
+	} else if (g_ascii_strcasecmp(config->ipv4_address, "auto") == 0 ||
+			g_ascii_strcasecmp(config->ipv4_address, "dhcp") == 0) {
+		connman_network_set_ipv4_method(network,
+						CONNMAN_IPCONFIG_METHOD_DHCP);
+	} else {
+		struct connman_ipaddress *address;
+
+		if (!config->ipv4_netmask) {
+			DBG("IPv4 netmask missing");
+			return -EINVAL;
+		}
+
+		address = connman_ipaddress_alloc(AF_INET);
+		if (!address)
+			return -ENOENT;
+
+		connman_ipaddress_set_ipv4(address, config->ipv4_address,
+					config->ipv4_netmask,
+					config->ipv4_gateway);
+
+		connman_network_set_ipv4_method(network,
+						CONNMAN_IPCONFIG_METHOD_FIXED);
+
+		if (connman_network_set_ipaddress(network, address) < 0)
+			DBG("Unable to set IPv4 address to network %p",
+								network);
+
+		connman_ipaddress_free(address);
+	}
+
+	__connman_service_disconnect(service);
+
+	service_id = __connman_service_get_ident(service);
+	config->service_identifiers =
+		g_slist_prepend(config->service_identifiers,
+				g_strdup(service_id));
+
+	__connman_service_set_favorite_delayed(service, true, true);
+
+	__connman_service_set_config(service, config->config_ident,
+						config->config_entry);
+
+	if (config->domain_name)
+		__connman_service_set_domainname(service, config->domain_name);
+
+	if (config->nameservers) {
+		int i;
+
+		__connman_service_nameserver_clear(service);
+
+		for (i = 0; config->nameservers[i]; i++) {
+			__connman_service_nameserver_append(service,
+						config->nameservers[i], false);
+		}
+	}
+
+	if (config->search_domains)
+		__connman_service_set_search_domains(service,
+						config->search_domains);
+
+	if (config->timeservers)
+		__connman_service_set_timeservers(service,
+						config->timeservers);
+
+	if (type == CONNMAN_SERVICE_TYPE_WIFI) {
+		provision_service_wifi(config, service, network,
+							ssid, ssid_len);
+	}
+
+	__connman_service_mark_dirty();
+
+	__connman_service_load_modifiable(service);
+
+	if (config->virtual) {
+		struct connect_virtual *virtual;
+
+		virtual = g_malloc0(sizeof(struct connect_virtual));
+		virtual->service = service;
+		virtual->vfile = config->virtual_file;
+
+		g_timeout_add(0, remove_virtual_config, virtual);
+
+		return 0;
+	}
+
+	__connman_service_set_immutable(service, true);
+
+	if (type == CONNMAN_SERVICE_TYPE_ETHERNET ||
+			type == CONNMAN_SERVICE_TYPE_GADGET) {
+		__connman_service_connect(service,
+				CONNMAN_SERVICE_CONNECT_REASON_AUTO);
+
+		return 0;
+	}
+
+	__connman_service_auto_connect(CONNMAN_SERVICE_CONNECT_REASON_AUTO);
+
+	return 0;
+}
+
+static int find_and_provision_service(struct connman_service *service)
+{
+	GHashTableIter iter, iter_service;
+	gpointer value, key, value_service, key_service;
+
+	g_hash_table_iter_init(&iter, config_table);
+
+	while (g_hash_table_iter_next(&iter, &key, &value)) {
+		struct connman_config *config = value;
+
+		g_hash_table_iter_init(&iter_service, config->service_table);
+		while (g_hash_table_iter_next(&iter_service, &key_service,
+						&value_service)) {
+			if (!try_provision_service(value_service, service))
+				return 0;
+		}
+	}
+
+	return -ENOENT;
+}
+
+int __connman_config_provision_service(struct connman_service *service)
+{
+	enum connman_service_type type;
+
+	/* For now only WiFi, Gadget and Ethernet services are supported */
+	type = connman_service_get_type(service);
+
+	DBG("service %p type %d", service, type);
+
+	if (type != CONNMAN_SERVICE_TYPE_WIFI &&
+			type != CONNMAN_SERVICE_TYPE_ETHERNET &&
+			type != CONNMAN_SERVICE_TYPE_GADGET)
+		return -ENOSYS;
+
+	return find_and_provision_service(service);
+}
+
+int __connman_config_provision_service_ident(struct connman_service *service,
+			const char *ident, const char *file, const char *entry)
+{
+	enum connman_service_type type;
+	struct connman_config *config;
+	int ret = 0;
+
+	/* For now only WiFi, Gadget and Ethernet services are supported */
+	type = connman_service_get_type(service);
+
+	DBG("service %p type %d", service, type);
+
+	if (type != CONNMAN_SERVICE_TYPE_WIFI &&
+			type != CONNMAN_SERVICE_TYPE_ETHERNET &&
+			type != CONNMAN_SERVICE_TYPE_GADGET)
+		return -ENOSYS;
+
+	config = g_hash_table_lookup(config_table, ident);
+	if (config) {
+		GHashTableIter iter;
+		gpointer value, key;
+		bool found = false;
+
+		g_hash_table_iter_init(&iter, config->service_table);
+
+		/*
+		 * Check if we need to remove individual service if it
+		 * is missing from config file.
+		 */
+		if (file && entry) {
+			while (g_hash_table_iter_next(&iter, &key,
+							&value)) {
+				struct connman_config_service *config_service;
+
+				config_service = value;
+
+				if (g_strcmp0(config_service->config_ident,
+								file) != 0)
+					continue;
+
+				if (g_strcmp0(config_service->config_entry,
+								entry) != 0)
+					continue;
+
+				found = true;
+				break;
+			}
+
+			DBG("found %d ident %s file %s entry %s", found, ident,
+								file, entry);
+
+			if (!found) {
+				/*
+				 * The entry+8 will skip "service_" prefix
+				 */
+				g_hash_table_remove(config->service_table,
+						entry + 8);
+				ret = 1;
+			}
+		}
+
+		find_and_provision_service(service);
+	}
+
+	return ret;
+}
+
+static void generate_random_string(char *str, int length)
+{
+	uint8_t val;
+	int i;
+	uint64_t rand;
+
+	memset(str, '\0', length);
+
+	for (i = 0; i < length-1; i++) {
+		do {
+			__connman_util_get_random(&rand);
+			val = (uint8_t)(rand % 122);
+			if (val < 48)
+				val += 48;
+		} while((val > 57 && val < 65) || (val > 90 && val < 97));
+
+		str[i] = val;
+	}
+}
+
+int connman_config_provision_mutable_service(GKeyFile *keyfile)
+{
+	struct connman_config_service *service_config;
+	struct connman_config *config;
+	char *vfile, *group;
+	char rstr[11];
+
+	DBG("");
+
+	generate_random_string(rstr, 11);
+
+	vfile = g_strdup_printf("service_mutable_%s.config", rstr);
+
+	config = create_config(vfile);
+	if (!config)
+		return -ENOMEM;
+
+	if (!load_service_from_keyfile(keyfile, config))
+		goto error;
+
+	group = g_key_file_get_start_group(keyfile);
+
+	service_config = g_hash_table_lookup(config->service_table, group+8);
+	if (!service_config)
+		goto error;
+
+	/* Specific to non file based config: */
+	g_free(service_config->config_ident);
+	service_config->config_ident = NULL;
+	g_free(service_config->config_entry);
+	service_config->config_entry = NULL;
+
+	service_config->virtual = true;
+	service_config->virtual_file = vfile;
+
+	__connman_service_provision_changed(vfile);
+
+	if (g_strcmp0(service_config->type, "wifi") == 0)
+		__connman_device_request_scan(CONNMAN_SERVICE_TYPE_WIFI);
+
+	return 0;
+
+error:
+	DBG("Could not proceed");
+	g_hash_table_remove(config_table, vfile);
+	g_free(vfile);
+
+	return -EINVAL;
+}
+
+struct connman_config_entry **connman_config_get_entries(const char *type)
+{
+	GHashTableIter iter_file, iter_config;
+	gpointer value, key;
+	struct connman_config_entry **entries = NULL;
+	int i = 0, count;
+
+	g_hash_table_iter_init(&iter_file, config_table);
+	while (g_hash_table_iter_next(&iter_file, &key, &value)) {
+		struct connman_config *config_file = value;
+
+		count = g_hash_table_size(config_file->service_table);
+
+		entries = g_try_realloc(entries, (i + count + 1) *
+					sizeof(struct connman_config_entry *));
+		if (!entries)
+			return NULL;
+
+		g_hash_table_iter_init(&iter_config,
+						config_file->service_table);
+		while (g_hash_table_iter_next(&iter_config, &key,
+							&value)) {
+			struct connman_config_service *config = value;
+
+			if (type &&
+					g_strcmp0(config->type, type) != 0)
+				continue;
+
+			entries[i] = g_try_new0(struct connman_config_entry,
+						1);
+			if (!entries[i])
+				goto cleanup;
+
+			entries[i]->ident = g_strdup(config->ident);
+			entries[i]->name = g_strdup(config->name);
+			entries[i]->ssid = g_try_malloc0(config->ssid_len + 1);
+			if (!entries[i]->ssid)
+				goto cleanup;
+
+			memcpy(entries[i]->ssid, config->ssid,
+							config->ssid_len);
+			entries[i]->ssid_len = config->ssid_len;
+			entries[i]->hidden = config->hidden;
+
+			i++;
+		}
+	}
+
+	if (entries) {
+		entries = g_try_realloc(entries, (i + 1) *
+					sizeof(struct connman_config_entry *));
+		if (!entries)
+			return NULL;
+
+		entries[i] = NULL;
+
+		DBG("%d provisioned AP found", i);
+	}
+
+	return entries;
+
+cleanup:
+	connman_config_free_entries(entries);
+	return NULL;
+}
+
+void connman_config_free_entries(struct connman_config_entry **entries)
+{
+	int i;
+
+	if (!entries)
+		return;
+
+	for (i = 0; entries[i]; i++) {
+		g_free(entries[i]->ident);
+		g_free(entries[i]->name);
+		g_free(entries[i]->ssid);
+		g_free(entries[i]);
+	}
+
+	g_free(entries);
+	return;
+}
+
+bool __connman_config_address_provisioned(const char *address,
+					const char *netmask)
+{
+	GHashTableIter iter, siter;
+	gpointer value, key, svalue, skey;
+
+	if (!address || !netmask)
+		return false;
+
+	g_hash_table_iter_init(&iter, config_table);
+
+	while (g_hash_table_iter_next(&iter, &key, &value)) {
+		struct connman_config *config = value;
+
+		g_hash_table_iter_init(&siter, config->service_table);
+		while (g_hash_table_iter_next(&siter, &skey, &svalue)) {
+			struct connman_config_service *service = svalue;
+
+			if (!g_strcmp0(address, service->ipv4_address) &&
+					!g_strcmp0(netmask,
+						service->ipv4_netmask))
+				return true;
+		}
+	}
+
+	return false;
+}
diff --git a/connman/src/connection.c b/connman/src/connection.c
new file mode 100644
index 0000000..aa4e1c0
--- /dev/null
+++ b/connman/src/connection.c
@@ -0,0 +1,1136 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2013  Intel Corporation. All rights reserved.
+ *  Copyright (C) 2011-2014  BMW Car IT GmbH.
+ *
+ *  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 <string.h>
+#include <net/if.h>
+
+#include <gdbus.h>
+
+#include "connman.h"
+
+struct gateway_config {
+	bool active;
+	char *gateway;
+
+	/* VPN extra data */
+	bool vpn;
+	char *vpn_ip;
+	int vpn_phy_index;
+	char *vpn_phy_ip;
+};
+
+struct gateway_data {
+	int index;
+	struct connman_service *service;
+	unsigned int order;
+	struct gateway_config *ipv4_gateway;
+	struct gateway_config *ipv6_gateway;
+	bool default_checked;
+};
+
+static GHashTable *gateway_hash = NULL;
+
+static struct gateway_config *find_gateway(int index, const char *gateway)
+{
+	GHashTableIter iter;
+	gpointer value, key;
+
+	if (!gateway)
+		return NULL;
+
+	g_hash_table_iter_init(&iter, gateway_hash);
+
+	while (g_hash_table_iter_next(&iter, &key, &value)) {
+		struct gateway_data *data = value;
+
+		if (data->ipv4_gateway && data->index == index &&
+				g_str_equal(data->ipv4_gateway->gateway,
+					gateway))
+			return data->ipv4_gateway;
+
+		if (data->ipv6_gateway && data->index == index &&
+				g_str_equal(data->ipv6_gateway->gateway,
+					gateway))
+			return data->ipv6_gateway;
+	}
+
+	return NULL;
+}
+
+static struct gateway_data *lookup_gateway_data(struct gateway_config *config)
+{
+	GHashTableIter iter;
+	gpointer value, key;
+
+	if (!config)
+		return NULL;
+
+	g_hash_table_iter_init(&iter, gateway_hash);
+
+	while (g_hash_table_iter_next(&iter, &key, &value)) {
+		struct gateway_data *data = value;
+
+		if (data->ipv4_gateway &&
+				data->ipv4_gateway == config)
+			return data;
+
+		if (data->ipv6_gateway &&
+				data->ipv6_gateway == config)
+			return data;
+	}
+
+	return NULL;
+}
+
+static struct gateway_data *find_vpn_gateway(int index, const char *gateway)
+{
+	GHashTableIter iter;
+	gpointer value, key;
+
+	if (!gateway)
+		return NULL;
+
+	g_hash_table_iter_init(&iter, gateway_hash);
+
+	while (g_hash_table_iter_next(&iter, &key, &value)) {
+		struct gateway_data *data = value;
+
+		if (data->ipv4_gateway && data->index == index &&
+				g_str_equal(data->ipv4_gateway->gateway,
+					gateway))
+			return data;
+
+		if (data->ipv6_gateway && data->index == index &&
+				g_str_equal(data->ipv6_gateway->gateway,
+					gateway))
+			return data;
+	}
+
+	return NULL;
+}
+
+struct get_gateway_params {
+	char *vpn_gateway;
+	int vpn_index;
+};
+
+static void get_gateway_cb(const char *gateway, int index, void *user_data)
+{
+	struct gateway_config *config;
+	struct gateway_data *data;
+	struct get_gateway_params *params = user_data;
+	int family;
+
+	if (index < 0)
+		goto out;
+
+	DBG("phy index %d phy gw %s vpn index %d vpn gw %s", index, gateway,
+		params->vpn_index, params->vpn_gateway);
+
+	data = find_vpn_gateway(params->vpn_index, params->vpn_gateway);
+	if (!data) {
+		DBG("Cannot find VPN link route, index %d addr %s",
+			params->vpn_index, params->vpn_gateway);
+		goto out;
+	}
+
+	family = connman_inet_check_ipaddress(params->vpn_gateway);
+
+	if (family == AF_INET)
+		config = data->ipv4_gateway;
+	else if (family == AF_INET6)
+		config = data->ipv6_gateway;
+	else
+		goto out;
+
+	config->vpn_phy_index = index;
+
+	DBG("vpn %s phy index %d", config->vpn_ip, config->vpn_phy_index);
+
+out:
+	g_free(params->vpn_gateway);
+	g_free(params);
+}
+
+static void set_vpn_routes(struct gateway_data *new_gateway,
+			struct connman_service *service,
+			const char *gateway,
+			enum connman_ipconfig_type type,
+			const char *peer,
+			struct gateway_data *active_gateway)
+{
+	struct gateway_config *config;
+	struct connman_ipconfig *ipconfig;
+	char *dest;
+
+	DBG("new %p service %p gw %s type %d peer %s active %p",
+		new_gateway, service, gateway, type, peer, active_gateway);
+
+	if (type == CONNMAN_IPCONFIG_TYPE_IPV4) {
+		ipconfig = __connman_service_get_ip4config(service);
+		config = new_gateway->ipv4_gateway;
+	} else if (type == CONNMAN_IPCONFIG_TYPE_IPV6) {
+		ipconfig = __connman_service_get_ip6config(service);
+		config = new_gateway->ipv6_gateway;
+	} else
+		return;
+
+	if (config) {
+		int index = __connman_ipconfig_get_index(ipconfig);
+		struct get_gateway_params *params;
+
+		config->vpn = true;
+		if (peer)
+			config->vpn_ip = g_strdup(peer);
+		else if (gateway)
+			config->vpn_ip = g_strdup(gateway);
+
+		params = g_try_malloc(sizeof(struct get_gateway_params));
+		if (!params)
+			return;
+
+		params->vpn_index = index;
+		params->vpn_gateway = g_strdup(gateway);
+
+		/*
+		 * Find the gateway that is serving the VPN link
+		 */
+		__connman_inet_get_route(gateway, get_gateway_cb, params);
+	}
+
+	if (!active_gateway)
+		return;
+
+	if (type == CONNMAN_IPCONFIG_TYPE_IPV4) {
+		/*
+		 * Special route to VPN server via gateway. This
+		 * is needed so that we can access hosts behind
+		 * the VPN. The route might already exist depending
+		 * on network topology.
+		 */
+		if (!active_gateway->ipv4_gateway)
+			return;
+
+		DBG("active gw %s", active_gateway->ipv4_gateway->gateway);
+
+		if (g_strcmp0(active_gateway->ipv4_gateway->gateway,
+							"0.0.0.0") != 0)
+			dest = active_gateway->ipv4_gateway->gateway;
+		else
+			dest = NULL;
+
+		connman_inet_add_host_route(active_gateway->index, gateway,
+									dest);
+
+	} else if (type == CONNMAN_IPCONFIG_TYPE_IPV6) {
+
+		if (!active_gateway->ipv6_gateway)
+			return;
+
+		DBG("active gw %s", active_gateway->ipv6_gateway->gateway);
+
+		if (g_strcmp0(active_gateway->ipv6_gateway->gateway,
+								"::") != 0)
+			dest = active_gateway->ipv6_gateway->gateway;
+		else
+			dest = NULL;
+
+		connman_inet_add_ipv6_host_route(active_gateway->index,
+								gateway, dest);
+	}
+}
+
+static int del_routes(struct gateway_data *data,
+			enum connman_ipconfig_type type)
+{
+	int status4 = 0, status6 = 0;
+	bool do_ipv4 = false, do_ipv6 = false;
+
+	if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
+		do_ipv4 = true;
+	else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
+		do_ipv6 = true;
+	else
+		do_ipv4 = do_ipv6 = true;
+
+	if (do_ipv4 && data->ipv4_gateway) {
+		if (data->ipv4_gateway->vpn) {
+			status4 = connman_inet_clear_gateway_address(
+						data->index,
+						data->ipv4_gateway->vpn_ip);
+
+		} else if (g_strcmp0(data->ipv4_gateway->gateway,
+							"0.0.0.0") == 0) {
+			status4 = connman_inet_clear_gateway_interface(
+								data->index);
+		} else {
+			connman_inet_del_host_route(data->index,
+						data->ipv4_gateway->gateway);
+			status4 = connman_inet_clear_gateway_address(
+						data->index,
+						data->ipv4_gateway->gateway);
+		}
+	}
+
+	if (do_ipv6 && data->ipv6_gateway) {
+		if (data->ipv6_gateway->vpn) {
+			status6 = connman_inet_clear_ipv6_gateway_address(
+						data->index,
+						data->ipv6_gateway->vpn_ip);
+
+		} else if (g_strcmp0(data->ipv6_gateway->gateway, "::") == 0) {
+			status6 = connman_inet_clear_ipv6_gateway_interface(
+								data->index);
+		} else {
+			connman_inet_del_ipv6_host_route(data->index,
+						data->ipv6_gateway->gateway);
+			status6 = connman_inet_clear_ipv6_gateway_address(
+						data->index,
+						data->ipv6_gateway->gateway);
+		}
+	}
+
+	return (status4 < 0 ? status4 : status6);
+}
+
+static int disable_gateway(struct gateway_data *data,
+			enum connman_ipconfig_type type)
+{
+	bool active = false;
+
+	if (type == CONNMAN_IPCONFIG_TYPE_IPV4) {
+		if (data->ipv4_gateway)
+			active = data->ipv4_gateway->active;
+	} else if (type == CONNMAN_IPCONFIG_TYPE_IPV6) {
+		if (data->ipv6_gateway)
+			active = data->ipv6_gateway->active;
+	} else
+		active = true;
+
+	DBG("type %d active %d", type, active);
+
+	if (active)
+		return del_routes(data, type);
+
+	return 0;
+}
+
+static struct gateway_data *add_gateway(struct connman_service *service,
+					int index, const char *gateway,
+					enum connman_ipconfig_type type)
+{
+	struct gateway_data *data, *old;
+	struct gateway_config *config;
+
+	if (!gateway || strlen(gateway) == 0)
+		return NULL;
+
+	data = g_try_new0(struct gateway_data, 1);
+	if (!data)
+		return NULL;
+
+	data->index = index;
+
+	config = g_try_new0(struct gateway_config, 1);
+	if (!config) {
+		g_free(data);
+		return NULL;
+	}
+
+	config->gateway = g_strdup(gateway);
+	config->vpn_ip = NULL;
+	config->vpn_phy_ip = NULL;
+	config->vpn = false;
+	config->vpn_phy_index = -1;
+	config->active = false;
+
+	if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
+		data->ipv4_gateway = config;
+	else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
+		data->ipv6_gateway = config;
+	else {
+		g_free(config->gateway);
+		g_free(config);
+		g_free(data);
+		return NULL;
+	}
+
+	data->service = service;
+
+	data->order = __connman_service_get_order(service);
+
+	/*
+	 * If the service is already in the hash, then we
+	 * must not replace it blindly but disable the gateway
+	 * of the type we are replacing and take the other type
+	 * from old gateway settings.
+	 */
+	old = g_hash_table_lookup(gateway_hash, service);
+	if (old) {
+		DBG("Replacing gw %p ipv4 %p ipv6 %p", old,
+			old->ipv4_gateway, old->ipv6_gateway);
+		disable_gateway(old, type);
+		if (type == CONNMAN_IPCONFIG_TYPE_IPV4) {
+			data->ipv6_gateway = old->ipv6_gateway;
+			old->ipv6_gateway = NULL;
+		} else if (type == CONNMAN_IPCONFIG_TYPE_IPV6) {
+			data->ipv4_gateway = old->ipv4_gateway;
+			old->ipv4_gateway = NULL;
+		}
+	}
+
+	connman_service_ref(data->service);
+	g_hash_table_replace(gateway_hash, service, data);
+
+	return data;
+}
+
+static void set_default_gateway(struct gateway_data *data,
+				enum connman_ipconfig_type type)
+{
+	int index;
+	int status4 = 0, status6 = 0;
+	bool do_ipv4 = false, do_ipv6 = false;
+
+	if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
+		do_ipv4 = true;
+	else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
+		do_ipv6 = true;
+	else
+		do_ipv4 = do_ipv6 = true;
+
+	DBG("type %d gateway ipv4 %p ipv6 %p", type, data->ipv4_gateway,
+						data->ipv6_gateway);
+
+	if (do_ipv4 && data->ipv4_gateway &&
+					data->ipv4_gateway->vpn) {
+		connman_inet_set_gateway_interface(data->index);
+		data->ipv4_gateway->active = true;
+
+		DBG("set %p index %d vpn %s index %d phy %s",
+			data, data->index, data->ipv4_gateway->vpn_ip,
+			data->ipv4_gateway->vpn_phy_index,
+			data->ipv4_gateway->vpn_phy_ip);
+
+		__connman_service_indicate_default(data->service);
+
+		return;
+	}
+
+	if (do_ipv6 && data->ipv6_gateway &&
+					data->ipv6_gateway->vpn) {
+		connman_inet_set_ipv6_gateway_interface(data->index);
+		data->ipv6_gateway->active = true;
+
+		DBG("set %p index %d vpn %s index %d phy %s",
+			data, data->index, data->ipv6_gateway->vpn_ip,
+			data->ipv6_gateway->vpn_phy_index,
+			data->ipv6_gateway->vpn_phy_ip);
+
+		__connman_service_indicate_default(data->service);
+
+		return;
+	}
+
+	index = __connman_service_get_index(data->service);
+
+	if (do_ipv4 && data->ipv4_gateway &&
+			g_strcmp0(data->ipv4_gateway->gateway,
+							"0.0.0.0") == 0) {
+		if (connman_inet_set_gateway_interface(index) < 0)
+			return;
+		goto done;
+	}
+
+	if (do_ipv6 && data->ipv6_gateway &&
+			g_strcmp0(data->ipv6_gateway->gateway,
+							"::") == 0) {
+		if (connman_inet_set_ipv6_gateway_interface(index) < 0)
+			return;
+		goto done;
+	}
+
+	if (do_ipv6 && data->ipv6_gateway)
+		status6 = __connman_inet_add_default_to_table(RT_TABLE_MAIN,
+					index, data->ipv6_gateway->gateway);
+
+	if (do_ipv4 && data->ipv4_gateway)
+		status4 = __connman_inet_add_default_to_table(RT_TABLE_MAIN,
+					index, data->ipv4_gateway->gateway);
+
+	if (status4 < 0 || status6 < 0)
+		return;
+
+done:
+	__connman_service_indicate_default(data->service);
+}
+
+static void unset_default_gateway(struct gateway_data *data,
+				enum connman_ipconfig_type type)
+{
+	int index;
+	bool do_ipv4 = false, do_ipv6 = false;
+
+	if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
+		do_ipv4 = true;
+	else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
+		do_ipv6 = true;
+	else
+		do_ipv4 = do_ipv6 = true;
+
+	DBG("type %d gateway ipv4 %p ipv6 %p", type, data->ipv4_gateway,
+						data->ipv6_gateway);
+
+	if (do_ipv4 && data->ipv4_gateway &&
+					data->ipv4_gateway->vpn) {
+		connman_inet_clear_gateway_interface(data->index);
+		data->ipv4_gateway->active = false;
+
+		DBG("unset %p index %d vpn %s index %d phy %s",
+			data, data->index, data->ipv4_gateway->vpn_ip,
+			data->ipv4_gateway->vpn_phy_index,
+			data->ipv4_gateway->vpn_phy_ip);
+
+		return;
+	}
+
+	if (do_ipv6 && data->ipv6_gateway &&
+					data->ipv6_gateway->vpn) {
+		connman_inet_clear_ipv6_gateway_interface(data->index);
+		data->ipv6_gateway->active = false;
+
+		DBG("unset %p index %d vpn %s index %d phy %s",
+			data, data->index, data->ipv6_gateway->vpn_ip,
+			data->ipv6_gateway->vpn_phy_index,
+			data->ipv6_gateway->vpn_phy_ip);
+
+		return;
+	}
+
+	index = __connman_service_get_index(data->service);
+
+	if (do_ipv4 && data->ipv4_gateway &&
+			g_strcmp0(data->ipv4_gateway->gateway,
+							"0.0.0.0") == 0) {
+		connman_inet_clear_gateway_interface(index);
+		return;
+	}
+
+	if (do_ipv6 && data->ipv6_gateway &&
+			g_strcmp0(data->ipv6_gateway->gateway,
+							"::") == 0) {
+		connman_inet_clear_ipv6_gateway_interface(index);
+		return;
+	}
+
+	if (do_ipv6 && data->ipv6_gateway)
+		connman_inet_clear_ipv6_gateway_address(index,
+						data->ipv6_gateway->gateway);
+
+	if (do_ipv4 && data->ipv4_gateway)
+		connman_inet_clear_gateway_address(index,
+						data->ipv4_gateway->gateway);
+}
+
+static struct gateway_data *find_default_gateway(void)
+{
+	struct gateway_data *found = NULL;
+	unsigned int order = 0;
+	GHashTableIter iter;
+	gpointer value, key;
+
+	g_hash_table_iter_init(&iter, gateway_hash);
+
+	while (g_hash_table_iter_next(&iter, &key, &value)) {
+		struct gateway_data *data = value;
+
+		if (!found || data->order > order) {
+			found = data;
+			order = data->order;
+
+			DBG("default %p order %d", found, order);
+		}
+	}
+
+	return found;
+}
+
+static bool choose_default_gateway(struct gateway_data *data,
+					struct gateway_data *candidate)
+{
+	bool downgraded = false;
+
+	/*
+	 * If the current default is not active, then we mark
+	 * this one as default. If the other one is already active
+	 * we mark this one as non default.
+	 */
+	if (data->ipv4_gateway) {
+		if (candidate->ipv4_gateway &&
+				!candidate->ipv4_gateway->active) {
+			DBG("ipv4 downgrading %p", candidate);
+			unset_default_gateway(candidate,
+						CONNMAN_IPCONFIG_TYPE_IPV4);
+		}
+		if (candidate->ipv4_gateway &&
+				candidate->ipv4_gateway->active &&
+				candidate->order > data->order) {
+			DBG("ipv4 downgrading this %p", data);
+			unset_default_gateway(data,
+						CONNMAN_IPCONFIG_TYPE_IPV4);
+			downgraded = true;
+		}
+	}
+
+	if (data->ipv6_gateway) {
+		if (candidate->ipv6_gateway &&
+				!candidate->ipv6_gateway->active) {
+			DBG("ipv6 downgrading %p", candidate);
+			unset_default_gateway(candidate,
+						CONNMAN_IPCONFIG_TYPE_IPV6);
+		}
+
+		if (candidate->ipv6_gateway &&
+				candidate->ipv6_gateway->active &&
+				candidate->order > data->order) {
+			DBG("ipv6 downgrading this %p", data);
+			unset_default_gateway(data,
+						CONNMAN_IPCONFIG_TYPE_IPV6);
+			downgraded = true;
+		}
+	}
+
+	return downgraded;
+}
+
+static void connection_newgateway(int index, const char *gateway)
+{
+	struct gateway_config *config;
+	struct gateway_data *data;
+	GHashTableIter iter;
+	gpointer value, key;
+	bool found = false;
+
+	DBG("index %d gateway %s", index, gateway);
+
+	config = find_gateway(index, gateway);
+	if (!config)
+		return;
+
+	config->active = true;
+
+	/*
+	 * It is possible that we have two default routes atm
+	 * if there are two gateways waiting rtnl activation at the
+	 * same time.
+	 */
+	data = lookup_gateway_data(config);
+	if (!data)
+		return;
+
+	if (data->default_checked)
+		return;
+
+	/*
+	 * The next checks are only done once, otherwise setting
+	 * the default gateway could lead into rtnl forever loop.
+	 */
+
+	g_hash_table_iter_init(&iter, gateway_hash);
+
+	while (g_hash_table_iter_next(&iter, &key, &value)) {
+		struct gateway_data *candidate = value;
+
+		if (candidate == data)
+			continue;
+
+		found = choose_default_gateway(data, candidate);
+		if (found)
+			break;
+	}
+
+	if (!found) {
+		if (data->ipv4_gateway)
+			set_default_gateway(data, CONNMAN_IPCONFIG_TYPE_IPV4);
+
+		if (data->ipv6_gateway)
+			set_default_gateway(data, CONNMAN_IPCONFIG_TYPE_IPV6);
+	}
+
+	data->default_checked = true;
+}
+
+static void remove_gateway(gpointer user_data)
+{
+	struct gateway_data *data = user_data;
+
+	DBG("gateway ipv4 %p ipv6 %p", data->ipv4_gateway, data->ipv6_gateway);
+
+	if (data->ipv4_gateway) {
+		g_free(data->ipv4_gateway->gateway);
+		g_free(data->ipv4_gateway->vpn_ip);
+		g_free(data->ipv4_gateway->vpn_phy_ip);
+		g_free(data->ipv4_gateway);
+	}
+
+	if (data->ipv6_gateway) {
+		g_free(data->ipv6_gateway->gateway);
+		g_free(data->ipv6_gateway->vpn_ip);
+		g_free(data->ipv6_gateway->vpn_phy_ip);
+		g_free(data->ipv6_gateway);
+	}
+
+	connman_service_unref(data->service);
+
+	g_free(data);
+}
+
+static void connection_delgateway(int index, const char *gateway)
+{
+	struct gateway_config *config;
+	struct gateway_data *data;
+
+	DBG("index %d gateway %s", index, gateway);
+
+	config = find_gateway(index, gateway);
+	if (config)
+		config->active = false;
+
+	data = find_default_gateway();
+	if (data)
+		set_default_gateway(data, CONNMAN_IPCONFIG_TYPE_ALL);
+}
+
+static struct connman_rtnl connection_rtnl = {
+	.name		= "connection",
+	.newgateway	= connection_newgateway,
+	.delgateway	= connection_delgateway,
+};
+
+static struct gateway_data *find_active_gateway(void)
+{
+	GHashTableIter iter;
+	gpointer value, key;
+
+	DBG("");
+
+	g_hash_table_iter_init(&iter, gateway_hash);
+
+	while (g_hash_table_iter_next(&iter, &key, &value)) {
+		struct gateway_data *data = value;
+
+		if (data->ipv4_gateway &&
+				data->ipv4_gateway->active)
+			return data;
+
+		if (data->ipv6_gateway &&
+				data->ipv6_gateway->active)
+			return data;
+	}
+
+	return NULL;
+}
+
+static void update_order(void)
+{
+	GHashTableIter iter;
+	gpointer value, key;
+
+	DBG("");
+
+	g_hash_table_iter_init(&iter, gateway_hash);
+
+	while (g_hash_table_iter_next(&iter, &key, &value)) {
+		struct gateway_data *data = value;
+
+		data->order = __connman_service_get_order(data->service);
+	}
+}
+
+void __connman_connection_gateway_activate(struct connman_service *service,
+					enum connman_ipconfig_type type)
+{
+	struct gateway_data *data = NULL;
+
+	data = g_hash_table_lookup(gateway_hash, service);
+	if (!data)
+		return;
+
+	DBG("gateway %p/%p type %d", data->ipv4_gateway,
+					data->ipv6_gateway, type);
+
+	if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
+		data->ipv4_gateway->active = true;
+	else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
+		data->ipv6_gateway->active = true;
+}
+
+static void add_host_route(int family, int index, const char *gateway,
+			enum connman_service_type service_type)
+{
+	switch (family) {
+	case AF_INET:
+		if (g_strcmp0(gateway, "0.0.0.0") != 0) {
+			/*
+			 * We must not set route to the phy dev gateway in
+			 * VPN link. The packets to VPN link might be routed
+			 * back to itself and not routed into phy link gateway.
+			 */
+			if (service_type != CONNMAN_SERVICE_TYPE_VPN)
+				connman_inet_add_host_route(index, gateway,
+									NULL);
+		} else {
+			/*
+			 * Add host route to P-t-P link so that services can
+			 * be moved around and we can have some link to P-t-P
+			 * network (although those P-t-P links have limited
+			 * usage if default route is not directed to them)
+			 */
+			char *dest;
+			if (connman_inet_get_dest_addr(index, &dest) == 0) {
+				connman_inet_add_host_route(index, dest, NULL);
+				g_free(dest);
+			}
+		}
+		break;
+
+	case AF_INET6:
+		if (g_strcmp0(gateway, "::") != 0) {
+			if (service_type != CONNMAN_SERVICE_TYPE_VPN)
+				connman_inet_add_ipv6_host_route(index,
+								gateway, NULL);
+		} else {
+			/* P-t-P link, add route to destination */
+			char *dest;
+			if (connman_inet_ipv6_get_dest_addr(index,
+								&dest) == 0) {
+				connman_inet_add_ipv6_host_route(index, dest,
+								NULL);
+				g_free(dest);
+			}
+		}
+		break;
+	}
+}
+
+int __connman_connection_gateway_add(struct connman_service *service,
+					const char *gateway,
+					enum connman_ipconfig_type type,
+					const char *peer)
+{
+	struct gateway_data *active_gateway = NULL;
+	struct gateway_data *new_gateway = NULL;
+	enum connman_ipconfig_type type4 = CONNMAN_IPCONFIG_TYPE_UNKNOWN,
+		type6 = CONNMAN_IPCONFIG_TYPE_UNKNOWN;
+	enum connman_service_type service_type =
+					connman_service_get_type(service);
+	int index;
+
+	index = __connman_service_get_index(service);
+
+	/*
+	 * If gateway is NULL, it's a point to point link and the default
+	 * gateway for ipv4 is 0.0.0.0 and for ipv6 is ::, meaning the
+	 * interface
+	 */
+	if (!gateway && type == CONNMAN_IPCONFIG_TYPE_IPV4)
+		gateway = "0.0.0.0";
+
+	if (!gateway && type == CONNMAN_IPCONFIG_TYPE_IPV6)
+		gateway = "::";
+
+	DBG("service %p index %d gateway %s vpn ip %s type %d",
+		service, index, gateway, peer, type);
+
+	new_gateway = add_gateway(service, index, gateway, type);
+	if (!new_gateway)
+		return -EINVAL;
+
+	active_gateway = find_active_gateway();
+
+	DBG("active %p index %d new %p", active_gateway,
+		active_gateway ? active_gateway->index : -1, new_gateway);
+
+	if (type == CONNMAN_IPCONFIG_TYPE_IPV4 &&
+				new_gateway->ipv4_gateway) {
+		add_host_route(AF_INET, index, gateway, service_type);
+		__connman_service_nameserver_add_routes(service,
+					new_gateway->ipv4_gateway->gateway);
+		type4 = CONNMAN_IPCONFIG_TYPE_IPV4;
+	}
+
+	if (type == CONNMAN_IPCONFIG_TYPE_IPV6 &&
+				new_gateway->ipv6_gateway) {
+		add_host_route(AF_INET6, index, gateway, service_type);
+		__connman_service_nameserver_add_routes(service,
+					new_gateway->ipv6_gateway->gateway);
+		type6 = CONNMAN_IPCONFIG_TYPE_IPV6;
+	}
+
+	if (service_type == CONNMAN_SERVICE_TYPE_VPN) {
+
+		set_vpn_routes(new_gateway, service, gateway, type, peer,
+							active_gateway);
+
+	} else {
+		if (type == CONNMAN_IPCONFIG_TYPE_IPV4 &&
+					new_gateway->ipv4_gateway)
+			new_gateway->ipv4_gateway->vpn = false;
+
+		if (type == CONNMAN_IPCONFIG_TYPE_IPV6 &&
+					new_gateway->ipv6_gateway)
+			new_gateway->ipv6_gateway->vpn = false;
+	}
+
+	if (!active_gateway) {
+		set_default_gateway(new_gateway, type);
+		goto done;
+	}
+
+	if (type == CONNMAN_IPCONFIG_TYPE_IPV4 &&
+				new_gateway->ipv4_gateway &&
+				new_gateway->ipv4_gateway->vpn) {
+		if (!__connman_service_is_split_routing(new_gateway->service))
+			connman_inet_clear_gateway_address(
+					active_gateway->index,
+					active_gateway->ipv4_gateway->gateway);
+	}
+
+	if (type == CONNMAN_IPCONFIG_TYPE_IPV6 &&
+				new_gateway->ipv6_gateway &&
+				new_gateway->ipv6_gateway->vpn) {
+		if (!__connman_service_is_split_routing(new_gateway->service))
+			connman_inet_clear_ipv6_gateway_address(
+					active_gateway->index,
+					active_gateway->ipv6_gateway->gateway);
+	}
+
+done:
+	if (type4 == CONNMAN_IPCONFIG_TYPE_IPV4)
+		__connman_service_ipconfig_indicate_state(service,
+						CONNMAN_SERVICE_STATE_READY,
+						CONNMAN_IPCONFIG_TYPE_IPV4);
+
+	if (type6 == CONNMAN_IPCONFIG_TYPE_IPV6)
+		__connman_service_ipconfig_indicate_state(service,
+						CONNMAN_SERVICE_STATE_READY,
+						CONNMAN_IPCONFIG_TYPE_IPV6);
+	return 0;
+}
+
+void __connman_connection_gateway_remove(struct connman_service *service,
+					enum connman_ipconfig_type type)
+{
+	struct gateway_data *data = NULL;
+	bool set_default4 = false, set_default6 = false;
+        bool do_ipv4 = false, do_ipv6 = false;
+	int err;
+
+	DBG("service %p type %d", service, type);
+
+	if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
+		do_ipv4 = true;
+	else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
+		do_ipv6 = true;
+	else
+		do_ipv4 = do_ipv6 = true;
+
+	__connman_service_nameserver_del_routes(service, type);
+
+	data = g_hash_table_lookup(gateway_hash, service);
+	if (!data)
+		return;
+
+	if (do_ipv4 && data->ipv4_gateway)
+		set_default4 = data->ipv4_gateway->vpn;
+
+	if (do_ipv6 && data->ipv6_gateway)
+		set_default6 = data->ipv6_gateway->vpn;
+
+	DBG("ipv4 gateway %s ipv6 gateway %s vpn %d/%d",
+		data->ipv4_gateway ? data->ipv4_gateway->gateway : "<null>",
+		data->ipv6_gateway ? data->ipv6_gateway->gateway : "<null>",
+		set_default4, set_default6);
+
+	if (do_ipv4 && data->ipv4_gateway &&
+			data->ipv4_gateway->vpn && data->index >= 0)
+		connman_inet_del_host_route(data->ipv4_gateway->vpn_phy_index,
+						data->ipv4_gateway->gateway);
+
+	if (do_ipv6 && data->ipv6_gateway &&
+			data->ipv6_gateway->vpn && data->index >= 0)
+		connman_inet_del_ipv6_host_route(
+					data->ipv6_gateway->vpn_phy_index,
+						data->ipv6_gateway->gateway);
+
+	err = disable_gateway(data, type);
+
+	/*
+	 * We remove the service from the hash only if all the gateway
+	 * settings are to be removed.
+	 */
+	if (do_ipv4 == do_ipv6 ||
+		(data->ipv4_gateway && !data->ipv6_gateway
+			&& do_ipv4) ||
+		(data->ipv6_gateway && !data->ipv4_gateway
+			&& do_ipv6)) {
+		g_hash_table_remove(gateway_hash, service);
+	} else
+		DBG("Not yet removing gw ipv4 %p/%d ipv6 %p/%d",
+			data->ipv4_gateway, do_ipv4,
+			data->ipv6_gateway, do_ipv6);
+
+	/* with vpn this will be called after the network was deleted,
+	 * we need to call set_default here because we will not recieve any
+	 * gateway delete notification.
+	 * We hit the same issue if remove_gateway() fails.
+	 */
+	if (set_default4 || set_default6 || err < 0) {
+		data = find_default_gateway();
+		if (data)
+			set_default_gateway(data, type);
+	}
+}
+
+bool __connman_connection_update_gateway(void)
+{
+	struct gateway_data *default_gateway;
+	bool updated = false;
+	GHashTableIter iter;
+	gpointer value, key;
+
+	if (!gateway_hash)
+		return updated;
+
+	update_order();
+
+	default_gateway = find_default_gateway();
+
+	__connman_service_update_ordering();
+
+	DBG("default %p", default_gateway);
+
+	/*
+	 * There can be multiple active gateways so we need to
+	 * check them all.
+	 */
+	g_hash_table_iter_init(&iter, gateway_hash);
+
+	while (g_hash_table_iter_next(&iter, &key, &value)) {
+		struct gateway_data *active_gateway = value;
+
+		if (active_gateway == default_gateway)
+			continue;
+
+		if (active_gateway->ipv4_gateway &&
+				active_gateway->ipv4_gateway->active) {
+
+			unset_default_gateway(active_gateway,
+						CONNMAN_IPCONFIG_TYPE_IPV4);
+			updated = true;
+		}
+
+		if (active_gateway->ipv6_gateway &&
+				active_gateway->ipv6_gateway->active) {
+
+			unset_default_gateway(active_gateway,
+						CONNMAN_IPCONFIG_TYPE_IPV6);
+			updated = true;
+		}
+	}
+
+	if (updated && default_gateway) {
+		if (default_gateway->ipv4_gateway)
+			set_default_gateway(default_gateway,
+					CONNMAN_IPCONFIG_TYPE_IPV4);
+
+		if (default_gateway->ipv6_gateway)
+			set_default_gateway(default_gateway,
+					CONNMAN_IPCONFIG_TYPE_IPV6);
+	}
+
+	return updated;
+}
+
+int __connman_connection_get_vpn_index(int phy_index)
+{
+	GHashTableIter iter;
+	gpointer value, key;
+
+	g_hash_table_iter_init(&iter, gateway_hash);
+
+	while (g_hash_table_iter_next(&iter, &key, &value)) {
+		struct gateway_data *data = value;
+
+		if (data->ipv4_gateway &&
+				data->ipv4_gateway->vpn_phy_index == phy_index)
+			return data->index;
+
+		if (data->ipv6_gateway &&
+				data->ipv6_gateway->vpn_phy_index == phy_index)
+			return data->index;
+	}
+
+	return -1;
+}
+
+int __connman_connection_init(void)
+{
+	int err;
+
+	DBG("");
+
+	gateway_hash = g_hash_table_new_full(g_direct_hash, g_direct_equal,
+							NULL, remove_gateway);
+
+	err = connman_rtnl_register(&connection_rtnl);
+	if (err < 0)
+		connman_error("Failed to setup RTNL gateway driver");
+
+	return err;
+}
+
+void __connman_connection_cleanup(void)
+{
+	GHashTableIter iter;
+	gpointer value, key;
+
+	DBG("");
+
+	connman_rtnl_unregister(&connection_rtnl);
+
+	g_hash_table_iter_init(&iter, gateway_hash);
+
+	while (g_hash_table_iter_next(&iter, &key, &value)) {
+		struct gateway_data *data = value;
+
+		disable_gateway(data, CONNMAN_IPCONFIG_TYPE_ALL);
+	}
+
+	g_hash_table_destroy(gateway_hash);
+	gateway_hash = NULL;
+}
diff --git a/connman/src/connman-dbus.conf b/connman/src/connman-dbus.conf
new file mode 100644
index 0000000..98a773e
--- /dev/null
+++ b/connman/src/connman-dbus.conf
@@ -0,0 +1,17 @@
+<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
+ "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
+<busconfig>
+    <policy user="root">
+        <allow own="net.connman"/>
+        <allow send_destination="net.connman"/>
+        <allow send_interface="net.connman.Agent"/>
+        <allow send_interface="net.connman.Counter"/>
+        <allow send_interface="net.connman.Notification"/>
+    </policy>
+    <policy at_console="true">
+        <allow send_destination="net.connman"/>
+    </policy>
+    <policy context="default">
+        <deny send_destination="net.connman"/>
+    </policy>
+</busconfig>
diff --git a/connman/src/connman-polkit.conf b/connman/src/connman-polkit.conf
new file mode 100644
index 0000000..b13d339
--- /dev/null
+++ b/connman/src/connman-polkit.conf
@@ -0,0 +1,13 @@
+<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
+ "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
+<busconfig>
+    <policy user="root">
+        <allow own="net.connman"/>
+        <allow send_interface="net.connman.Agent"/>
+        <allow send_interface="net.connman.Counter"/>
+        <allow send_interface="net.connman.Notification"/>
+    </policy>
+    <policy context="default">
+        <allow send_destination="net.connman"/>
+    </policy>
+</busconfig>
diff --git a/connman/src/connman.h b/connman/src/connman.h
new file mode 100644
index 0000000..4fafbfe
--- /dev/null
+++ b/connman/src/connman.h
@@ -0,0 +1,1041 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2014  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
+ *
+ */
+
+#include <stdbool.h>
+
+#include <glib.h>
+
+#define CONNMAN_API_SUBJECT_TO_CHANGE
+
+#include <connman/dbus.h>
+
+dbus_bool_t __connman_dbus_append_objpath_dict_array(DBusMessage *msg,
+			connman_dbus_append_cb_t function, void *user_data);
+dbus_bool_t __connman_dbus_append_objpath_array(DBusMessage *msg,
+			connman_dbus_append_cb_t function, void *user_data);
+int __connman_dbus_init(DBusConnection *conn);
+void __connman_dbus_cleanup(void);
+
+DBusMessage *__connman_error_failed(DBusMessage *msg, int errnum);
+DBusMessage *__connman_error_invalid_arguments(DBusMessage *msg);
+DBusMessage *__connman_error_permission_denied(DBusMessage *msg);
+DBusMessage *__connman_error_passphrase_required(DBusMessage *msg);
+DBusMessage *__connman_error_not_registered(DBusMessage *msg);
+DBusMessage *__connman_error_not_unique(DBusMessage *msg);
+DBusMessage *__connman_error_not_supported(DBusMessage *msg);
+DBusMessage *__connman_error_not_implemented(DBusMessage *msg);
+DBusMessage *__connman_error_not_found(DBusMessage *msg);
+DBusMessage *__connman_error_no_carrier(DBusMessage *msg);
+DBusMessage *__connman_error_in_progress(DBusMessage *msg);
+DBusMessage *__connman_error_already_exists(DBusMessage *msg);
+DBusMessage *__connman_error_already_enabled(DBusMessage *msg);
+DBusMessage *__connman_error_already_disabled(DBusMessage *msg);
+DBusMessage *__connman_error_already_connected(DBusMessage *msg);
+DBusMessage *__connman_error_not_connected(DBusMessage *msg);
+DBusMessage *__connman_error_operation_aborted(DBusMessage *msg);
+DBusMessage *__connman_error_operation_timeout(DBusMessage *msg);
+DBusMessage *__connman_error_invalid_service(DBusMessage *msg);
+DBusMessage *__connman_error_invalid_property(DBusMessage *msg);
+
+int __connman_manager_init(void);
+void __connman_manager_cleanup(void);
+
+enum time_updates {
+	TIME_UPDATES_UNKNOWN = 0,
+	TIME_UPDATES_MANUAL  = 1,
+	TIME_UPDATES_AUTO    = 2,
+};
+
+enum time_updates __connman_clock_timeupdates(void);
+int __connman_clock_init(void);
+void __connman_clock_cleanup(void);
+
+void __connman_clock_update_timezone(void);
+
+int __connman_timezone_init(void);
+void __connman_timezone_cleanup(void);
+
+char *__connman_timezone_lookup(void);
+int __connman_timezone_change(const char *zone);
+
+int __connman_agent_init(void);
+void __connman_agent_cleanup(void);
+
+void __connman_counter_send_usage(const char *path,
+					DBusMessage *message);
+int __connman_counter_register(const char *owner, const char *path,
+						unsigned int interval);
+int __connman_counter_unregister(const char *owner, const char *path);
+
+int __connman_counter_init(void);
+void __connman_counter_cleanup(void);
+
+#include <connman/agent.h>
+
+struct connman_service;
+struct connman_peer;
+
+void __connman_agent_cancel(struct connman_service *service);
+
+typedef void (* authentication_cb_t) (struct connman_service *service,
+				bool values_received,
+				const char *name, int name_len,
+				const char *identifier, const char *secret,
+				bool wps, const char *wpspin,
+				const char *error, void *user_data);
+typedef void (* browser_authentication_cb_t) (struct connman_service *service,
+				bool authentication_done,
+				const char *error, void *user_data);
+typedef void (* peer_wps_cb_t) (struct connman_peer *peer, bool choice_done,
+				const char *wpspin, const char *error,
+				void *user_data);
+int __connman_agent_request_passphrase_input(struct connman_service *service,
+				authentication_cb_t callback,
+				const char *dbus_sender, void *user_data);
+int __connman_agent_request_login_input(struct connman_service *service,
+				authentication_cb_t callback, void *user_data);
+int __connman_agent_request_browser(struct connman_service *service,
+				browser_authentication_cb_t callback,
+				const char *url, void *user_data);
+int __connman_agent_report_peer_error(struct connman_peer *peer,
+					const char *path, const char *error,
+					report_error_cb_t callback,
+					const char *dbus_sender,
+					void *user_data);
+int __connman_agent_request_peer_authorization(struct connman_peer *peer,
+						peer_wps_cb_t callback,
+						bool wps_requested,
+						const char *dbus_sender,
+						void *user_data);
+
+#include <connman/log.h>
+
+int __connman_log_init(const char *program, const char *debug,
+		gboolean detach, gboolean backtrace,
+		const char *program_name, const char *program_version);
+void __connman_log_cleanup(gboolean backtrace);
+void __connman_log_enable(struct connman_debug_desc *start,
+					struct connman_debug_desc *stop);
+
+#include <connman/option.h>
+
+#include <connman/setting.h>
+
+#include <connman/plugin.h>
+
+int __connman_plugin_init(const char *pattern, const char *exclude);
+void __connman_plugin_cleanup(void);
+
+#include <connman/task.h>
+
+int __connman_task_init(void);
+void __connman_task_cleanup(void);
+
+#include <connman/inet.h>
+
+char **__connman_inet_get_running_interfaces(void);
+int __connman_inet_modify_address(int cmd, int flags, int index, int family,
+				const char *address,
+				const char *peer,
+				unsigned char prefixlen,
+				const char *broadcast);
+int __connman_inet_get_interface_address(int index, int family, void *address);
+int __connman_inet_get_interface_ll_address(int index, int family, void *address);
+
+#include <netinet/ip6.h>
+#include <netinet/icmp6.h>
+
+typedef void (*__connman_inet_rs_cb_t) (struct nd_router_advert *reply,
+					unsigned int length, void *user_data);
+
+int __connman_inet_ipv6_send_rs(int index, int timeout,
+			__connman_inet_rs_cb_t callback, void *user_data);
+int __connman_inet_ipv6_send_ra(int index, struct in6_addr *src_addr,
+				GSList *prefixes, int router_lifetime);
+
+typedef void (*__connman_inet_ns_cb_t) (struct nd_neighbor_advert *reply,
+					unsigned int length,
+					struct in6_addr *addr,
+					void *user_data);
+int __connman_inet_ipv6_do_dad(int index, int timeout_ms,
+			struct in6_addr *addr,
+			__connman_inet_ns_cb_t callback, void *user_data);
+
+typedef void (*__connman_inet_recv_rs_cb_t) (struct nd_router_solicit *reply,
+					unsigned int length, void *user_data);
+int __connman_inet_ipv6_start_recv_rs(int index,
+				__connman_inet_recv_rs_cb_t callback,
+				void *user_data, void **context);
+void __connman_inet_ipv6_stop_recv_rs(void *context);
+
+int __connman_network_refresh_rs_ipv6(struct connman_network *network, int index);
+
+GSList *__connman_inet_ipv6_get_prefixes(struct nd_router_advert *hdr,
+					unsigned int length);
+typedef void (*connman_inet_addr_cb_t) (const char *src_address, int index,
+					void *user_data);
+int __connman_inet_get_route(const char *dst_address,
+			connman_inet_addr_cb_t callback, void *user_data);
+
+struct __connman_inet_rtnl_handle {
+	int			fd;
+	struct sockaddr_nl	local;
+	struct sockaddr_nl	peer;
+	__u32			seq;
+	__u32			dump;
+
+	struct {
+		struct nlmsghdr n;
+		union {
+			struct {
+				struct rtmsg rt;
+			} r;
+			struct {
+				struct ifaddrmsg ifa;
+			} i;
+		} u;
+		char buf[1024];
+	} req;
+};
+
+int __connman_inet_rtnl_open(struct __connman_inet_rtnl_handle *rth);
+typedef void (*__connman_inet_rtnl_cb_t) (struct nlmsghdr *answer,
+					void *user_data);
+int __connman_inet_rtnl_talk(struct __connman_inet_rtnl_handle *rtnl,
+			struct nlmsghdr *n, int timeout,
+			__connman_inet_rtnl_cb_t callback, void *user_data);
+static inline
+int __connman_inet_rtnl_send(struct __connman_inet_rtnl_handle *rtnl,
+						struct nlmsghdr *n)
+{
+	return __connman_inet_rtnl_talk(rtnl, n, 0, NULL, NULL);
+}
+
+void __connman_inet_rtnl_close(struct __connman_inet_rtnl_handle *rth);
+int __connman_inet_rtnl_addattr_l(struct nlmsghdr *n, size_t max_length,
+			int type, const void *data, size_t data_length);
+int __connman_inet_rtnl_addattr32(struct nlmsghdr *n, size_t maxlen,
+			int type, __u32 data);
+
+int __connman_inet_add_fwmark_rule(uint32_t table_id, int family, uint32_t fwmark);
+int __connman_inet_del_fwmark_rule(uint32_t table_id, int family, uint32_t fwmark);
+int __connman_inet_add_default_to_table(uint32_t table_id, int ifindex, const char *gateway);
+int __connman_inet_del_default_from_table(uint32_t table_id, int ifindex, const char *gateway);
+int __connman_inet_get_address_netmask(int ifindex,
+		struct sockaddr_in *address, struct sockaddr_in *netmask);
+
+#include <connman/resolver.h>
+
+int __connman_resolver_init(gboolean dnsproxy);
+void __connman_resolver_cleanup(void);
+int __connman_resolvfile_append(int index, const char *domain, const char *server);
+int __connman_resolvfile_remove(int index, const char *domain, const char *server);
+int __connman_resolver_redo_servers(int index);
+
+GKeyFile *__connman_storage_open_global(void);
+GKeyFile *__connman_storage_load_global(void);
+int __connman_storage_save_global(GKeyFile *keyfile);
+void __connman_storage_delete_global(void);
+
+GKeyFile *__connman_storage_load_config(const char *ident);
+GKeyFile *__connman_storage_load_provider_config(const char *ident);
+
+GKeyFile *__connman_storage_open_service(const char *ident);
+int __connman_storage_save_service(GKeyFile *keyfile, const char *ident);
+GKeyFile *__connman_storage_load_provider(const char *identifier);
+void __connman_storage_save_provider(GKeyFile *keyfile, const char *identifier);
+bool __connman_storage_remove_provider(const char *identifier);
+char **__connman_storage_get_providers(void);
+bool __connman_storage_remove_service(const char *service_id);
+
+int __connman_detect_init(void);
+void __connman_detect_cleanup(void);
+
+#include <connman/inotify.h>
+
+int __connman_inotify_init(void);
+void __connman_inotify_cleanup(void);
+
+#include <connman/proxy.h>
+
+int __connman_proxy_init(void);
+void __connman_proxy_cleanup(void);
+
+#include <connman/ipconfig.h>
+
+struct connman_ipaddress {
+	int family;
+	unsigned char prefixlen;
+	char *local;
+	char *peer;
+	char *broadcast;
+	char *gateway;
+};
+
+struct connman_ipconfig_ops {
+	void (*up) (struct connman_ipconfig *ipconfig, const char *ifname);
+	void (*down) (struct connman_ipconfig *ipconfig, const char *ifname);
+	void (*lower_up) (struct connman_ipconfig *ipconfig, const char *ifname);
+	void (*lower_down) (struct connman_ipconfig *ipconfig, const char *ifname);
+	void (*ip_bound) (struct connman_ipconfig *ipconfig, const char *ifname);
+	void (*ip_release) (struct connman_ipconfig *ipconfig, const char *ifname);
+	void (*route_set) (struct connman_ipconfig *ipconfig, const char *ifname);
+	void (*route_unset) (struct connman_ipconfig *ipconfig, const char *ifname);
+};
+
+struct connman_ipconfig *__connman_ipconfig_create(int index,
+					enum connman_ipconfig_type type);
+
+#define __connman_ipconfig_ref(ipconfig) \
+	__connman_ipconfig_ref_debug(ipconfig, __FILE__, __LINE__, __func__)
+#define __connman_ipconfig_unref(ipconfig) \
+	__connman_ipconfig_unref_debug(ipconfig, __FILE__, __LINE__, __func__)
+
+struct connman_ipconfig *
+__connman_ipconfig_ref_debug(struct connman_ipconfig *ipconfig,
+			const char *file, int line, const char *caller);
+void __connman_ipconfig_unref_debug(struct connman_ipconfig *ipconfig,
+			const char *file, int line, const char *caller);
+
+void __connman_ipconfig_clear_address(struct connman_ipconfig *ipconfig);
+void *__connman_ipconfig_get_data(struct connman_ipconfig *ipconfig);
+void __connman_ipconfig_set_data(struct connman_ipconfig *ipconfig, void *data);
+
+int __connman_ipconfig_get_index(struct connman_ipconfig *ipconfig);
+
+void __connman_ipconfig_set_ops(struct connman_ipconfig *ipconfig,
+				const struct connman_ipconfig_ops *ops);
+int __connman_ipconfig_set_method(struct connman_ipconfig *ipconfig,
+					enum connman_ipconfig_method method);
+void __connman_ipconfig_disable_ipv6(struct connman_ipconfig *ipconfig);
+void __connman_ipconfig_enable_ipv6(struct connman_ipconfig *ipconfig);
+
+int __connman_ipconfig_init(void);
+void __connman_ipconfig_cleanup(void);
+
+struct rtnl_link_stats;
+
+void __connman_ipconfig_newlink(int index, unsigned short type,
+				unsigned int flags, const char *address,
+							unsigned short mtu,
+						struct rtnl_link_stats *stats);
+void __connman_ipconfig_dellink(int index, struct rtnl_link_stats *stats);
+int __connman_ipconfig_newaddr(int index, int family, const char *label,
+				unsigned char prefixlen, const char *address);
+void __connman_ipconfig_deladdr(int index, int family, const char *label,
+				unsigned char prefixlen, const char *address);
+void __connman_ipconfig_newroute(int index, int family, unsigned char scope,
+					const char *dst, const char *gateway);
+void __connman_ipconfig_delroute(int index, int family, unsigned char scope,
+					const char *dst, const char *gateway);
+
+void __connman_ipconfig_foreach(void (*function) (int index, void *user_data),
+							void *user_data);
+enum connman_ipconfig_type __connman_ipconfig_get_config_type(
+					struct connman_ipconfig *ipconfig);
+unsigned short __connman_ipconfig_get_type_from_index(int index);
+unsigned int __connman_ipconfig_get_flags_from_index(int index);
+const char *__connman_ipconfig_get_gateway_from_index(int index,
+	enum connman_ipconfig_type type);
+void __connman_ipconfig_set_index(struct connman_ipconfig *ipconfig, int index);
+
+const char *__connman_ipconfig_get_local(struct connman_ipconfig *ipconfig);
+void __connman_ipconfig_set_local(struct connman_ipconfig *ipconfig, const char *address);
+const char *__connman_ipconfig_get_peer(struct connman_ipconfig *ipconfig);
+void __connman_ipconfig_set_peer(struct connman_ipconfig *ipconfig, const char *address);
+const char *__connman_ipconfig_get_broadcast(struct connman_ipconfig *ipconfig);
+void __connman_ipconfig_set_broadcast(struct connman_ipconfig *ipconfig, const char *broadcast);
+const char *__connman_ipconfig_get_gateway(struct connman_ipconfig *ipconfig);
+void __connman_ipconfig_set_gateway(struct connman_ipconfig *ipconfig, const char *gateway);
+unsigned char __connman_ipconfig_get_prefixlen(struct connman_ipconfig *ipconfig);
+void __connman_ipconfig_set_prefixlen(struct connman_ipconfig *ipconfig, unsigned char prefixlen);
+
+int __connman_ipconfig_enable(struct connman_ipconfig *ipconfig);
+int __connman_ipconfig_disable(struct connman_ipconfig *ipconfig);
+bool __connman_ipconfig_is_usable(struct connman_ipconfig *ipconfig);
+
+const char *__connman_ipconfig_method2string(enum connman_ipconfig_method method);
+const char *__connman_ipconfig_type2string(enum connman_ipconfig_type type);
+enum connman_ipconfig_method __connman_ipconfig_string2method(const char *method);
+
+void __connman_ipconfig_append_ipv4(struct connman_ipconfig *ipconfig,
+							DBusMessageIter *iter);
+void __connman_ipconfig_append_ipv4config(struct connman_ipconfig *ipconfig,
+							DBusMessageIter *iter);
+void __connman_ipconfig_append_ipv6(struct connman_ipconfig *ipconfig,
+					DBusMessageIter *iter,
+					struct connman_ipconfig *ip4config);
+void __connman_ipconfig_append_ipv6config(struct connman_ipconfig *ipconfig,
+							DBusMessageIter *iter);
+int __connman_ipconfig_set_config(struct connman_ipconfig *ipconfig,
+							DBusMessageIter *array);
+void __connman_ipconfig_append_ethernet(struct connman_ipconfig *ipconfig,
+							DBusMessageIter *iter);
+enum connman_ipconfig_method __connman_ipconfig_get_method(
+				struct connman_ipconfig *ipconfig);
+
+int __connman_ipconfig_address_add(struct connman_ipconfig *ipconfig);
+int __connman_ipconfig_address_remove(struct connman_ipconfig *ipconfig);
+int __connman_ipconfig_address_unset(struct connman_ipconfig *ipconfig);
+int __connman_ipconfig_gateway_add(struct connman_ipconfig *ipconfig);
+void __connman_ipconfig_gateway_remove(struct connman_ipconfig *ipconfig);
+
+int __connman_ipconfig_set_proxy_autoconfig(struct connman_ipconfig *ipconfig,
+							const char *url);
+const char *__connman_ipconfig_get_proxy_autoconfig(struct connman_ipconfig *ipconfig);
+void __connman_ipconfig_set_dhcp_address(struct connman_ipconfig *ipconfig,
+					const char *address);
+char *__connman_ipconfig_get_dhcp_address(struct connman_ipconfig *ipconfig);
+void __connman_ipconfig_set_dhcpv6_prefixes(struct connman_ipconfig *ipconfig,
+					char **prefixes);
+char **__connman_ipconfig_get_dhcpv6_prefixes(struct connman_ipconfig *ipconfig);
+
+int __connman_ipconfig_load(struct connman_ipconfig *ipconfig,
+		GKeyFile *keyfile, const char *identifier, const char *prefix);
+int __connman_ipconfig_save(struct connman_ipconfig *ipconfig,
+		GKeyFile *keyfile, const char *identifier, const char *prefix);
+bool __connman_ipconfig_ipv6_privacy_enabled(struct connman_ipconfig *ipconfig);
+int __connman_ipconfig_ipv6_reset_privacy(struct connman_ipconfig *ipconfig);
+int __connman_ipconfig_ipv6_set_privacy(struct connman_ipconfig *ipconfig,
+					const char *value);
+bool __connman_ipconfig_ipv6_is_enabled(struct connman_ipconfig *ipconfig);
+
+int __connman_ipconfig_set_rp_filter();
+void __connman_ipconfig_unset_rp_filter(int old_value);
+
+#include <connman/utsname.h>
+
+int __connman_utsname_set_hostname(const char *hostname);
+int __connman_utsname_set_domainname(const char *domainname);
+
+#include <connman/timeserver.h>
+
+int __connman_timeserver_init(void);
+void __connman_timeserver_cleanup(void);
+
+char **__connman_timeserver_system_get();
+
+GSList *__connman_timeserver_add_list(GSList *server_list,
+		const char *timeserver);
+GSList *__connman_timeserver_get_all(struct connman_service *service);
+int __connman_timeserver_sync(struct connman_service *service);
+void __connman_timeserver_sync_next();
+
+enum __connman_dhcpv6_status {
+	CONNMAN_DHCPV6_STATUS_FAIL     = 0,
+	CONNMAN_DHCPV6_STATUS_SUCCEED  = 1,
+	CONNMAN_DHCPV6_STATUS_RESTART  = 2,
+};
+
+typedef void (* dhcpv6_cb) (struct connman_network *network,
+			enum __connman_dhcpv6_status status, gpointer data);
+
+typedef void (* dhcp_cb) (struct connman_ipconfig *ipconfig,
+			struct connman_network *opt_network,
+			bool success, gpointer data);
+char *__connman_dhcp_get_server_address(struct connman_ipconfig *ipconfig);
+int __connman_dhcp_start(struct connman_ipconfig *ipconfig,
+			struct connman_network *network, dhcp_cb callback,
+			gpointer user_data);
+void __connman_dhcp_stop(struct connman_ipconfig *ipconfig);
+int __connman_dhcp_init(void);
+void __connman_dhcp_cleanup(void);
+int __connman_dhcpv6_init(void);
+void __connman_dhcpv6_cleanup(void);
+int __connman_dhcpv6_start_info(struct connman_network *network,
+				dhcpv6_cb callback);
+void __connman_dhcpv6_stop(struct connman_network *network);
+int __connman_dhcpv6_start(struct connman_network *network,
+				GSList *prefixes, dhcpv6_cb callback);
+int __connman_dhcpv6_start_renew(struct connman_network *network,
+				dhcpv6_cb callback);
+int __connman_dhcpv6_start_release(struct connman_network *network,
+				dhcpv6_cb callback);
+int __connman_dhcpv6_start_pd(int index, GSList *prefixes, dhcpv6_cb callback);
+void __connman_dhcpv6_stop_pd(int index);
+int __connman_dhcpv6_start_pd_renew(struct connman_network *network,
+							dhcpv6_cb callback);
+int __connman_dhcpv6_start_pd_release(struct connman_network *network,
+				dhcpv6_cb callback);
+
+int __connman_ipv4_init(void);
+void __connman_ipv4_cleanup(void);
+
+int __connman_connection_init(void);
+void __connman_connection_cleanup(void);
+
+int __connman_connection_gateway_add(struct connman_service *service,
+					const char *gateway,
+					enum connman_ipconfig_type type,
+					const char *peer);
+void __connman_connection_gateway_remove(struct connman_service *service,
+					enum connman_ipconfig_type type);
+int __connman_connection_get_vpn_index(int phy_index);
+
+bool __connman_connection_update_gateway(void);
+void __connman_connection_gateway_activate(struct connman_service *service,
+					enum connman_ipconfig_type type);
+
+int __connman_ntp_start(char *server);
+void __connman_ntp_stop();
+
+int __connman_wpad_init(void);
+void __connman_wpad_cleanup(void);
+int __connman_wpad_start(struct connman_service *service);
+void __connman_wpad_stop(struct connman_service *service);
+
+int __connman_wispr_init(void);
+void __connman_wispr_cleanup(void);
+int __connman_wispr_start(struct connman_service *service,
+					enum connman_ipconfig_type type);
+void __connman_wispr_stop(struct connman_service *service);
+
+#include <connman/technology.h>
+
+void __connman_technology_list_struct(DBusMessageIter *array);
+
+int __connman_technology_add_device(struct connman_device *device);
+int __connman_technology_remove_device(struct connman_device *device);
+int __connman_technology_enabled(enum connman_service_type type);
+int __connman_technology_disabled(enum connman_service_type type);
+int __connman_technology_set_offlinemode(bool offlinemode);
+bool __connman_technology_get_offlinemode(void);
+void __connman_technology_set_connected(enum connman_service_type type,
+					bool connected);
+
+int __connman_technology_add_rfkill(unsigned int index,
+					enum connman_service_type type,
+						bool softblock,
+						bool hardblock);
+int __connman_technology_update_rfkill(unsigned int index,
+					enum connman_service_type type,
+						bool softblock,
+						bool hardblock);
+int __connman_technology_remove_rfkill(unsigned int index,
+					enum connman_service_type type);
+
+void __connman_technology_scan_started(struct connman_device *device);
+void __connman_technology_scan_stopped(struct connman_device *device,
+					enum connman_service_type type);
+void __connman_technology_add_interface(enum connman_service_type type,
+				int index, const char *ident);
+void __connman_technology_remove_interface(enum connman_service_type type,
+				int index, const char *ident);
+void __connman_technology_notify_regdom_by_device(struct connman_device *device,
+						int result, const char *alpha2);
+
+#include <connman/device.h>
+
+int __connman_device_init(const char *device, const char *nodevice);
+void __connman_device_cleanup(void);
+
+void __connman_device_list(DBusMessageIter *iter, void *user_data);
+
+enum connman_service_type __connman_device_get_service_type(struct connman_device *device);
+struct connman_device *__connman_device_find_device(enum connman_service_type type);
+int __connman_device_request_scan(enum connman_service_type type);
+int __connman_device_request_hidden_scan(struct connman_device *device,
+				const char *ssid, unsigned int ssid_len,
+				const char *identity, const char *passphrase,
+				const char *security, void *user_data);
+
+bool __connman_device_isfiltered(const char *devname);
+
+void __connman_device_set_network(struct connman_device *device,
+					struct connman_network *network);
+void __connman_device_cleanup_networks(struct connman_device *device);
+
+int __connman_device_enable(struct connman_device *device);
+int __connman_device_disable(struct connman_device *device);
+int __connman_device_disconnect(struct connman_device *device);
+
+bool __connman_device_has_driver(struct connman_device *device);
+
+const char *__connman_device_get_type(struct connman_device *device);
+
+int __connman_rfkill_init(void);
+void __connman_rfkill_cleanup(void);
+int __connman_rfkill_block(enum connman_service_type type, bool block);
+
+#include <connman/network.h>
+
+int __connman_network_init(void);
+void __connman_network_cleanup(void);
+
+void __connman_network_set_device(struct connman_network *network,
+					struct connman_device *device);
+
+int __connman_network_connect(struct connman_network *network);
+int __connman_network_disconnect(struct connman_network *network, bool user_initiated);
+int __connman_network_clear_ipconfig(struct connman_network *network,
+					struct connman_ipconfig *ipconfig);
+int __connman_network_enable_ipconfig(struct connman_network *network,
+				struct connman_ipconfig *ipconfig);
+
+const char *__connman_network_get_type(struct connman_network *network);
+const char *__connman_network_get_group(struct connman_network *network);
+const char *__connman_network_get_ident(struct connman_network *network);
+bool __connman_network_get_weakness(struct connman_network *network);
+
+int __connman_config_init();
+void __connman_config_cleanup(void);
+
+int __connman_config_load_service(GKeyFile *keyfile, const char *group,
+				  bool persistent);
+int __connman_config_provision_service(struct connman_service *service);
+int __connman_config_provision_service_ident(struct connman_service *service,
+		const char *ident, const char *file, const char *entry);
+
+char *__connman_config_get_string(GKeyFile *key_file,
+	const char *group_name, const char *key, GError **error);
+
+char **__connman_config_get_string_list(GKeyFile *key_file,
+	const char *group_name, const char *key, gsize *length, GError **error);
+
+bool __connman_config_get_bool(GKeyFile *key_file,
+	const char *group_name, const char *key, GError **error);
+bool __connman_config_address_provisioned(const char *address,
+					const char *netmask);
+
+int __connman_tethering_init(void);
+void __connman_tethering_cleanup(void);
+
+const char *__connman_tethering_get_bridge(void);
+void __connman_tethering_set_enabled(void);
+void __connman_tethering_set_disabled(void);
+
+int __connman_private_network_request(DBusMessage *msg, const char *owner);
+int __connman_private_network_release(const char *path);
+
+int __connman_ipv6pd_setup(const char *bridge);
+void __connman_ipv6pd_cleanup(void);
+
+#include <connman/provider.h>
+
+bool __connman_provider_check_routes(struct connman_provider *provider);
+int __connman_provider_append_user_route(struct connman_provider *provider,
+			int family, const char *network, const char *netmask);
+void __connman_provider_append_properties(struct connman_provider *provider, DBusMessageIter *iter);
+void __connman_provider_list(DBusMessageIter *iter, void *user_data);
+bool __connman_provider_is_immutable(struct connman_provider *provider);
+int __connman_provider_create_and_connect(DBusMessage *msg);
+const char * __connman_provider_get_ident(struct connman_provider *provider);
+int __connman_provider_indicate_state(struct connman_provider *provider,
+					enum connman_provider_state state);
+int __connman_provider_indicate_error(struct connman_provider *provider,
+					enum connman_provider_error error);
+int __connman_provider_connect(struct connman_provider *provider);
+int __connman_provider_remove_by_path(const char *path);
+void __connman_provider_cleanup(void);
+int __connman_provider_init(void);
+
+#include <connman/service.h>
+
+int __connman_service_init(void);
+void __connman_service_cleanup(void);
+int __connman_service_load_modifiable(struct connman_service *service);
+
+void __connman_service_list_struct(DBusMessageIter *iter);
+
+struct connman_service *__connman_service_lookup_from_index(int index);
+struct connman_service *__connman_service_lookup_from_ident(const char *identifier);
+struct connman_service *__connman_service_create_from_network(struct connman_network *network);
+struct connman_service *__connman_service_create_from_provider(struct connman_provider *provider);
+bool __connman_service_index_is_default(int index);
+struct connman_service *__connman_service_get_default(void);
+void __connman_service_update_from_network(struct connman_network *network);
+void __connman_service_remove_from_network(struct connman_network *network);
+void __connman_service_read_ip4config(struct connman_service *service);
+void __connman_service_read_ip6config(struct connman_service *service);
+
+struct connman_ipconfig *__connman_service_get_ip4config(
+				struct connman_service *service);
+struct connman_ipconfig *__connman_service_get_ip6config(
+				struct connman_service *service);
+struct connman_ipconfig *__connman_service_get_ipconfig(
+				struct connman_service *service, int family);
+bool __connman_service_is_connected_state(struct connman_service *service,
+					enum connman_ipconfig_type type);
+const char *__connman_service_get_ident(struct connman_service *service);
+const char *__connman_service_get_path(struct connman_service *service);
+const char *__connman_service_get_name(struct connman_service *service);
+unsigned int __connman_service_get_order(struct connman_service *service);
+enum connman_service_state __connman_service_get_state(struct connman_service *service);
+void __connman_service_update_ordering(void);
+struct connman_network *__connman_service_get_network(struct connman_service *service);
+enum connman_service_security __connman_service_get_security(struct connman_service *service);
+const char *__connman_service_get_phase2(struct connman_service *service);
+bool __connman_service_wps_enabled(struct connman_service *service);
+int __connman_service_set_favorite(struct connman_service *service,
+						bool favorite);
+int __connman_service_set_favorite_delayed(struct connman_service *service,
+					bool favorite,
+					bool delay_ordering);
+int __connman_service_set_immutable(struct connman_service *service,
+						bool immutable);
+int __connman_service_set_ignore(struct connman_service *service,
+						bool ignore);
+void __connman_service_set_search_domains(struct connman_service *service,
+					char **domains);
+
+void __connman_service_set_string(struct connman_service *service,
+					const char *key, const char *value);
+int __connman_service_online_check_failed(struct connman_service *service,
+					enum connman_ipconfig_type type);
+int __connman_service_ipconfig_indicate_state(struct connman_service *service,
+					enum connman_service_state new_state,
+					enum connman_ipconfig_type type);
+enum connman_service_state __connman_service_ipconfig_get_state(
+					struct connman_service *service,
+					enum connman_ipconfig_type type);
+
+int __connman_service_indicate_error(struct connman_service *service,
+					enum connman_service_error error);
+int __connman_service_clear_error(struct connman_service *service);
+int __connman_service_indicate_default(struct connman_service *service);
+
+int __connman_service_connect(struct connman_service *service,
+			enum connman_service_connect_reason reason);
+int __connman_service_disconnect(struct connman_service *service);
+int __connman_service_disconnect_all(void);
+int __connman_service_needs_input(struct connman_service *service);
+void __connman_service_set_active_session(bool enable, GSList *list);
+void __connman_service_auto_connect(enum connman_service_connect_reason reason);
+bool __connman_service_remove(struct connman_service *service);
+bool __connman_service_is_provider_pending(struct connman_service *service);
+void __connman_service_set_provider_pending(struct connman_service *service,
+							DBusMessage *msg);
+void __connman_service_set_hidden_data(struct connman_service *service,
+				gpointer user_data);
+void __connman_service_return_error(struct connman_service *service,
+				int error, gpointer user_data);
+
+int __connman_service_provision_changed(const char *ident);
+void __connman_service_set_config(struct connman_service *service,
+				const char *file_id, const char *section);
+
+const char *__connman_service_type2string(enum connman_service_type type);
+enum connman_service_type __connman_service_string2type(const char *str);
+enum connman_service_security __connman_service_string2security(const char *str);
+
+int __connman_service_nameserver_append(struct connman_service *service,
+				const char *nameserver, bool is_auto);
+int __connman_service_nameserver_remove(struct connman_service *service,
+				const char *nameserver, bool is_auto);
+void __connman_service_nameserver_clear(struct connman_service *service);
+void __connman_service_nameserver_add_routes(struct connman_service *service,
+						const char *gw);
+void __connman_service_nameserver_del_routes(struct connman_service *service,
+					enum connman_ipconfig_type type);
+void __connman_service_set_timeservers(struct connman_service *service,
+						char **timeservers);
+int __connman_service_timeserver_append(struct connman_service *service,
+						const char *timeserver);
+int __connman_service_timeserver_remove(struct connman_service *service,
+						const char *timeserver);
+void __connman_service_timeserver_changed(struct connman_service *service,
+		GSList *ts_list);
+void __connman_service_set_pac(struct connman_service *service,
+					const char *pac);
+bool __connman_service_is_hidden(struct connman_service *service);
+bool __connman_service_is_split_routing(struct connman_service *service);
+bool __connman_service_index_is_split_routing(int index);
+int __connman_service_get_index(struct connman_service *service);
+void __connman_service_set_hidden(struct connman_service *service);
+void __connman_service_set_hostname(struct connman_service *service,
+						const char *hostname);
+const char *__connman_service_get_hostname(struct connman_service *service);
+void __connman_service_set_domainname(struct connman_service *service,
+						const char *domainname);
+const char *__connman_service_get_nameserver(struct connman_service *service);
+void __connman_service_set_proxy_autoconfig(struct connman_service *service,
+							const char *url);
+
+void __connman_service_set_identity(struct connman_service *service,
+					const char *identity);
+void __connman_service_set_agent_identity(struct connman_service *service,
+						const char *agent_identity);
+int __connman_service_set_passphrase(struct connman_service *service,
+					const char *passphrase);
+const char *__connman_service_get_passphrase(struct connman_service *service);
+int __connman_service_reset_ipconfig(struct connman_service *service,
+		enum connman_ipconfig_type type, DBusMessageIter *array,
+		enum connman_service_state *new_state);
+
+void __connman_service_notify(struct connman_service *service,
+			unsigned int rx_packets, unsigned int tx_packets,
+			unsigned int rx_bytes, unsigned int tx_bytes,
+			unsigned int rx_error, unsigned int tx_error,
+			unsigned int rx_dropped, unsigned int tx_dropped);
+
+int __connman_service_counter_register(const char *counter);
+void __connman_service_counter_unregister(const char *counter);
+
+#include <connman/peer.h>
+
+int __connman_peer_init(void);
+void __connman_peer_cleanup(void);
+
+void __connman_peer_list_struct(DBusMessageIter *array);
+const char *__connman_peer_get_path(struct connman_peer *peer);
+
+int __connman_peer_service_init(void);
+void __connman_peer_service_cleanup(void);
+
+void __connman_peer_service_set_driver(struct connman_peer_driver *driver);
+int __connman_peer_service_register(const char *owner, DBusMessage *msg,
+					const unsigned char *specification,
+					int specification_length,
+					const unsigned char *query,
+					int query_length, int version,
+					bool master);
+int __connman_peer_service_unregister(const char *owner,
+					const unsigned char *specification,
+					int specification_length,
+					const unsigned char *query,
+					int query_length, int version);
+
+#include <connman/session.h>
+
+typedef void (* service_iterate_cb) (struct connman_service *service,
+					void *user_data);
+
+int __connman_service_iterate_services(service_iterate_cb cb, void *user_data);
+
+void __connman_service_mark_dirty();
+void __connman_service_save(struct connman_service *service);
+
+#include <connman/notifier.h>
+
+int __connman_technology_init(void);
+void __connman_technology_cleanup(void);
+
+int __connman_notifier_init(void);
+void __connman_notifier_cleanup(void);
+
+void __connman_notifier_service_add(struct connman_service *service,
+					const char *name);
+void __connman_notifier_service_remove(struct connman_service *service);
+void __connman_notifier_enter_online(enum connman_service_type type);
+void __connman_notifier_leave_online(enum connman_service_type type);
+void __connman_notifier_connect(enum connman_service_type type);
+void __connman_notifier_disconnect(enum connman_service_type type);
+void __connman_notifier_offlinemode(bool enabled);
+void __connman_notifier_default_changed(struct connman_service *service);
+void __connman_notifier_proxy_changed(struct connman_service *service);
+void __connman_notifier_service_state_changed(struct connman_service *service,
+					enum connman_service_state state);
+void __connman_notifier_ipconfig_changed(struct connman_service *service,
+					struct connman_ipconfig *ipconfig);
+void __connman_notifier_sleep_event(void *identifier, bool cansleep,
+					time_t valid_until);
+
+bool __connman_notifier_is_connected(void);
+const char *__connman_notifier_get_state(void);
+
+#include <connman/rtnl.h>
+
+int __connman_rtnl_init(void);
+void __connman_rtnl_start(void);
+void __connman_rtnl_cleanup(void);
+
+enum connman_device_type __connman_rtnl_get_device_type(int index);
+unsigned int __connman_rtnl_update_interval_add(unsigned int interval);
+unsigned int __connman_rtnl_update_interval_remove(unsigned int interval);
+int __connman_rtnl_request_update(void);
+int __connman_rtnl_send(const void *buf, size_t len);
+
+bool __connman_session_policy_autoconnect(enum connman_service_connect_reason reason);
+
+int __connman_session_create(DBusMessage *msg);
+int __connman_session_destroy(DBusMessage *msg);
+
+int __connman_session_init(void);
+void __connman_session_cleanup(void);
+
+struct connman_stats_data {
+	unsigned int rx_packets;
+	unsigned int tx_packets;
+	unsigned int rx_bytes;
+	unsigned int tx_bytes;
+	unsigned int rx_errors;
+	unsigned int tx_errors;
+	unsigned int rx_dropped;
+	unsigned int tx_dropped;
+	unsigned int time;
+};
+
+int __connman_stats_init(void);
+void __connman_stats_cleanup(void);
+int __connman_stats_service_register(struct connman_service *service);
+void __connman_stats_service_unregister(struct connman_service *service);
+int  __connman_stats_update(struct connman_service *service,
+				bool roaming,
+				struct connman_stats_data *data);
+int __connman_stats_get(struct connman_service *service,
+				bool roaming,
+				struct connman_stats_data *data);
+
+int __connman_iptables_dump(const char *table_name);
+int __connman_iptables_new_chain(const char *table_name,
+					const char *chain);
+int __connman_iptables_delete_chain(const char *table_name,
+					const char *chain);
+int __connman_iptables_flush_chain(const char *table_name,
+					const char *chain);
+int __connman_iptables_change_policy(const char *table_name,
+					const char *chain,
+					const char *policy);
+int __connman_iptables_append(const char *table_name,
+			const char *chain,
+			const char *rule_spec);
+int __connman_iptables_insert(const char *table_name,
+			const char *chain,
+			const char *rule_spec);
+int __connman_iptables_delete(const char *table_name,
+			const char *chain,
+			const char *rule_spec);
+
+typedef void (*connman_iptables_iterate_chains_cb_t) (const char *chain_name,
+							void *user_data);
+int __connman_iptables_iterate_chains(const char *table_name,
+				connman_iptables_iterate_chains_cb_t cb,
+				void *user_data);
+
+int __connman_iptables_init(void);
+void __connman_iptables_cleanup(void);
+int __connman_iptables_commit(const char *table_name);
+
+int __connman_dnsproxy_init(void);
+void __connman_dnsproxy_cleanup(void);
+int __connman_dnsproxy_add_listener(int index);
+void __connman_dnsproxy_remove_listener(int index);
+int __connman_dnsproxy_append(int index, const char *domain, const char *server);
+int __connman_dnsproxy_remove(int index, const char *domain, const char *server);
+
+int __connman_6to4_probe(struct connman_service *service);
+void __connman_6to4_remove(struct connman_ipconfig *ipconfig);
+int __connman_6to4_check(struct connman_ipconfig *ipconfig);
+
+struct connman_ippool;
+
+typedef void (*ippool_collision_cb_t) (struct connman_ippool *pool,
+					void *user_data);
+
+int __connman_ippool_init(void);
+void __connman_ippool_cleanup(void);
+
+#define __connman_ippool_ref(ipconfig) \
+	__connman_ippool_ref_debug(ipconfig, __FILE__, __LINE__, __func__)
+#define __connman_ippool_unref(ipconfig) \
+	__connman_ippool_unref_debug(ipconfig, __FILE__, __LINE__, __func__)
+
+struct connman_ippool *__connman_ippool_ref_debug(struct connman_ippool *pool,
+			const char *file, int line, const char *caller);
+void __connman_ippool_unref_debug(struct connman_ippool *pool,
+			const char *file, int line, const char *caller);
+
+struct connman_ippool *__connman_ippool_create(int index,
+					unsigned int start,
+					unsigned int range,
+					ippool_collision_cb_t collision_cb,
+					void *user_data);
+
+const char *__connman_ippool_get_gateway(struct connman_ippool *pool);
+const char *__connman_ippool_get_broadcast(struct connman_ippool *pool);
+const char *__connman_ippool_get_subnet_mask(struct connman_ippool *pool);
+const char *__connman_ippool_get_start_ip(struct connman_ippool *pool);
+const char *__connman_ippool_get_end_ip(struct connman_ippool *pool);
+
+void __connman_ippool_newaddr(int index, const char *address,
+				unsigned char prefixlen);
+void __connman_ippool_deladdr(int index, const char *address,
+				unsigned char prefixlen);
+
+int __connman_bridge_create(const char *name);
+int __connman_bridge_remove(const char *name);
+int __connman_bridge_enable(const char *name, const char *ip_address,
+			int prefix_len, const char *broadcast);
+int __connman_bridge_disable(const char *name);
+
+int __connman_nat_init(void);
+void __connman_nat_cleanup(void);
+
+int __connman_nat_enable(const char *name, const char *address,
+				unsigned char prefixlen);
+void __connman_nat_disable(const char *name);
+
+struct firewall_context;
+
+struct firewall_context *__connman_firewall_create(void);
+void __connman_firewall_destroy(struct firewall_context *ctx);
+int __connman_firewall_add_rule(struct firewall_context *ctx,
+				const char *table,
+				const char *chain,
+				const char *rule_fmt, ...);
+int __connman_firewall_enable(struct firewall_context *ctx);
+int __connman_firewall_disable(struct firewall_context *ctx);
+bool __connman_firewall_is_up(void);
+
+int __connman_firewall_init(void);
+void __connman_firewall_cleanup(void);
+
+typedef int (* connman_nfacct_flush_cb_t) (unsigned int error, void *user_data);
+
+int __connman_nfacct_flush(connman_nfacct_flush_cb_t cb, void *user_data);
+
+struct nfacct_context;
+
+typedef void (* connman_nfacct_enable_cb_t) (unsigned int error,
+						struct nfacct_context *ctx,
+						void *user_data);
+typedef void (* connman_nfacct_disable_cb_t) (unsigned int error,
+						struct nfacct_context *ctx,
+						void *user_data);
+typedef void (* connman_nfacct_stats_cb_t) (struct nfacct_context *ctx,
+						uint64_t packets,
+						uint64_t bytes,
+						void *user_data);
+
+struct nfacct_context *__connman_nfacct_create_context(void);
+void __connman_nfacct_destroy_context(struct nfacct_context *ctx);
+
+int __connman_nfacct_add(struct nfacct_context *ctx, const char *name,
+				connman_nfacct_stats_cb_t cb,
+				void *user_data);
+int __connman_nfacct_enable(struct nfacct_context *ctx,
+				connman_nfacct_enable_cb_t cb,
+				void *user_data);
+int __connman_nfacct_disable(struct nfacct_context *ctx,
+				connman_nfacct_disable_cb_t cb,
+				void *user_data);
+
+void __connman_nfacct_cleanup(void);
+
+#include <connman/machine.h>
+
+int __connman_machine_init(void);
+void __connman_machine_cleanup(void);
+
+int __connman_util_get_random(uint64_t *val);
+int __connman_util_init(void);
+void __connman_util_cleanup(void);
+int __connman_rlimits_init(const gchar *path);
diff --git a/connman/src/connman.service.in b/connman/src/connman.service.in
new file mode 100644
index 0000000..ba4dedd
--- /dev/null
+++ b/connman/src/connman.service.in
@@ -0,0 +1,16 @@
+[Unit]
+Description=Connection service
+Requires=dbus.socket
+After=dbus.socket
+Before=remote-fs-pre.target
+Wants=remote-fs-pre.target
+
+[Service]
+Type=dbus
+BusName=net.connman
+Restart=on-failure
+ExecStart=@sbindir@/connmand -n
+StandardOutput=null
+
+[Install]
+WantedBy=multi-user.target
diff --git a/connman/src/connman.ver b/connman/src/connman.ver
new file mode 100644
index 0000000..03a0eec
--- /dev/null
+++ b/connman/src/connman.ver
@@ -0,0 +1,7 @@
+{
+	global:
+		connman_*;
+		g_dbus_*;
+	local:
+		*;
+};
diff --git a/connman/src/counter.c b/connman/src/counter.c
new file mode 100644
index 0000000..8ea6205
--- /dev/null
+++ b/connman/src/counter.c
@@ -0,0 +1,200 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2012  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 <gdbus.h>
+
+#include "connman.h"
+
+static DBusConnection *connection;
+
+static GHashTable *counter_table;
+static GHashTable *owner_mapping;
+
+struct connman_counter {
+	char *owner;
+	char *path;
+	unsigned int interval;
+	guint watch;
+};
+
+static void remove_counter(gpointer user_data)
+{
+	struct connman_counter *counter = user_data;
+
+	DBG("owner %s path %s", counter->owner, counter->path);
+
+	__connman_rtnl_update_interval_remove(counter->interval);
+
+	__connman_service_counter_unregister(counter->path);
+
+	g_free(counter->owner);
+	g_free(counter->path);
+	g_free(counter);
+}
+
+static void owner_disconnect(DBusConnection *conn, void *user_data)
+{
+	struct connman_counter *counter = user_data;
+
+	DBG("owner %s path %s", counter->owner, counter->path);
+
+	g_hash_table_remove(owner_mapping, counter->owner);
+	g_hash_table_remove(counter_table, counter->path);
+}
+
+int __connman_counter_register(const char *owner, const char *path,
+						unsigned int interval)
+{
+	struct connman_counter *counter;
+	int err;
+
+	DBG("owner %s path %s interval %u", owner, path, interval);
+
+	counter = g_hash_table_lookup(counter_table, path);
+	if (counter)
+		return -EEXIST;
+
+	counter = g_try_new0(struct connman_counter, 1);
+	if (!counter)
+		return -ENOMEM;
+
+	counter->owner = g_strdup(owner);
+	counter->path = g_strdup(path);
+
+	err = __connman_service_counter_register(counter->path);
+	if (err < 0) {
+		g_free(counter->owner);
+		g_free(counter->path);
+		g_free(counter);
+		return err;
+	}
+
+	g_hash_table_replace(counter_table, counter->path, counter);
+	g_hash_table_replace(owner_mapping, counter->owner, counter);
+
+	counter->interval = interval;
+	__connman_rtnl_update_interval_add(counter->interval);
+
+	counter->watch = g_dbus_add_disconnect_watch(connection, owner,
+					owner_disconnect, counter, NULL);
+
+	return 0;
+}
+
+int __connman_counter_unregister(const char *owner, const char *path)
+{
+	struct connman_counter *counter;
+
+	DBG("owner %s path %s", owner, path);
+
+	counter = g_hash_table_lookup(counter_table, path);
+	if (!counter)
+		return -ESRCH;
+
+	if (g_strcmp0(owner, counter->owner) != 0)
+		return -EACCES;
+
+	if (counter->watch > 0)
+		g_dbus_remove_watch(connection, counter->watch);
+
+	g_hash_table_remove(owner_mapping, counter->owner);
+	g_hash_table_remove(counter_table, counter->path);
+
+	return 0;
+}
+
+void __connman_counter_send_usage(const char *path,
+					DBusMessage *message)
+{
+	struct connman_counter *counter;
+
+	counter = g_hash_table_lookup(counter_table, path);
+	if (!counter) {
+		if (message)
+			dbus_message_unref(message);
+		return;
+	}
+
+	dbus_message_set_destination(message, counter->owner);
+	dbus_message_set_path(message, counter->path);
+	dbus_message_set_interface(message, CONNMAN_COUNTER_INTERFACE);
+	dbus_message_set_member(message, "Usage");
+	dbus_message_set_no_reply(message, TRUE);
+
+	g_dbus_send_message(connection, message);
+}
+
+static void release_counter(gpointer key, gpointer value, gpointer user_data)
+{
+	struct connman_counter *counter = value;
+	DBusMessage *message;
+
+	DBG("owner %s path %s", counter->owner, counter->path);
+
+	if (counter->watch > 0)
+		g_dbus_remove_watch(connection, counter->watch);
+
+	message = dbus_message_new_method_call(counter->owner, counter->path,
+					CONNMAN_COUNTER_INTERFACE, "Release");
+	if (!message)
+		return;
+
+	dbus_message_set_no_reply(message, TRUE);
+
+	g_dbus_send_message(connection, message);
+}
+
+int __connman_counter_init(void)
+{
+	DBG("");
+
+	connection = connman_dbus_get_connection();
+	if (!connection)
+		return -1;
+
+	counter_table = g_hash_table_new_full(g_str_hash, g_str_equal,
+							NULL, remove_counter);
+	owner_mapping = g_hash_table_new_full(g_str_hash, g_str_equal,
+								NULL, NULL);
+
+	return 0;
+}
+
+void __connman_counter_cleanup(void)
+{
+	DBG("");
+
+	if (!connection)
+		return;
+
+	g_hash_table_foreach(counter_table, release_counter, NULL);
+
+	g_hash_table_destroy(owner_mapping);
+	g_hash_table_destroy(counter_table);
+
+	dbus_connection_unref(connection);
+}
diff --git a/connman/src/dbus.c b/connman/src/dbus.c
new file mode 100644
index 0000000..d80a46c
--- /dev/null
+++ b/connman/src/dbus.c
@@ -0,0 +1,710 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2012  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 <errno.h>
+#include <gdbus.h>
+
+#include "connman.h"
+
+dbus_bool_t connman_dbus_validate_ident(const char *ident)
+{
+	unsigned int i;
+
+	if (!ident)
+		return FALSE;
+
+	for (i = 0; i < strlen(ident); i++) {
+		if (ident[i] >= '0' && ident[i] <= '9')
+			continue;
+		if (ident[i] >= 'a' && ident[i] <= 'z')
+			continue;
+		if (ident[i] >= 'A' && ident[i] <= 'Z')
+			continue;
+		return FALSE;
+	}
+
+	return TRUE;
+}
+
+char *connman_dbus_encode_string(const char *value)
+{
+	GString *str;
+	unsigned int i, size;
+
+	if (!value)
+		return NULL;
+
+	size = strlen(value);
+
+	str = g_string_new(NULL);
+	if (!str)
+		return NULL;
+
+	for (i = 0; i < size; i++) {
+		const char tmp = value[i];
+		if ((tmp < '0' || tmp > '9') && (tmp < 'A' || tmp > 'Z') &&
+						(tmp < 'a' || tmp > 'z'))
+			g_string_append_printf(str, "_%02x", tmp);
+		else
+			str = g_string_append_c(str, tmp);
+	}
+
+	return g_string_free(str, FALSE);
+}
+
+void connman_dbus_property_append_basic(DBusMessageIter *iter,
+					const char *key, int type, void *val)
+{
+	DBusMessageIter value;
+	const char *signature;
+
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &key);
+
+	switch (type) {
+	case DBUS_TYPE_BOOLEAN:
+		signature = DBUS_TYPE_BOOLEAN_AS_STRING;
+		break;
+	case DBUS_TYPE_STRING:
+		signature = DBUS_TYPE_STRING_AS_STRING;
+		break;
+	case DBUS_TYPE_BYTE:
+		signature = DBUS_TYPE_BYTE_AS_STRING;
+		break;
+	case DBUS_TYPE_UINT16:
+		signature = DBUS_TYPE_UINT16_AS_STRING;
+		break;
+	case DBUS_TYPE_INT16:
+		signature = DBUS_TYPE_INT16_AS_STRING;
+		break;
+	case DBUS_TYPE_UINT32:
+		signature = DBUS_TYPE_UINT32_AS_STRING;
+		break;
+	case DBUS_TYPE_INT32:
+		signature = DBUS_TYPE_INT32_AS_STRING;
+		break;
+	case DBUS_TYPE_UINT64:
+		signature = DBUS_TYPE_UINT64_AS_STRING;
+		break;
+	case DBUS_TYPE_INT64:
+		signature = DBUS_TYPE_INT64_AS_STRING;
+		break;
+	case DBUS_TYPE_OBJECT_PATH:
+		signature = DBUS_TYPE_OBJECT_PATH_AS_STRING;
+		break;
+	default:
+		signature = DBUS_TYPE_VARIANT_AS_STRING;
+		break;
+	}
+
+	dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
+							signature, &value);
+	dbus_message_iter_append_basic(&value, type, val);
+	dbus_message_iter_close_container(iter, &value);
+}
+
+void connman_dbus_property_append_dict(DBusMessageIter *iter, const char *key,
+			connman_dbus_append_cb_t function, void *user_data)
+{
+	DBusMessageIter value, dict;
+
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &key);
+
+	dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
+			DBUS_TYPE_ARRAY_AS_STRING
+			DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+			DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
+			DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &value);
+
+	connman_dbus_dict_open(&value, &dict);
+	if (function)
+		function(&dict, user_data);
+	connman_dbus_dict_close(&value, &dict);
+
+	dbus_message_iter_close_container(iter, &value);
+}
+
+void connman_dbus_property_append_fixed_array(DBusMessageIter *iter,
+				const char *key, int type, void *val, int len)
+{
+	DBusMessageIter value, array;
+	const char *variant_sig, *array_sig;
+
+	switch (type) {
+	case DBUS_TYPE_BYTE:
+		variant_sig = DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_BYTE_AS_STRING;
+		array_sig = DBUS_TYPE_BYTE_AS_STRING;
+		break;
+	default:
+		return;
+	}
+
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &key);
+
+	dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
+							variant_sig, &value);
+
+	dbus_message_iter_open_container(&value, DBUS_TYPE_ARRAY,
+							array_sig, &array);
+	dbus_message_iter_append_fixed_array(&array, type, val, len);
+	dbus_message_iter_close_container(&value, &array);
+
+	dbus_message_iter_close_container(iter, &value);
+}
+
+void connman_dbus_property_append_array(DBusMessageIter *iter,
+						const char *key, int type,
+			connman_dbus_append_cb_t function, void *user_data)
+{
+	DBusMessageIter value, array;
+	const char *variant_sig, *array_sig;
+
+	switch (type) {
+	case DBUS_TYPE_STRING:
+		variant_sig = DBUS_TYPE_ARRAY_AS_STRING
+				DBUS_TYPE_STRING_AS_STRING;
+		array_sig = DBUS_TYPE_STRING_AS_STRING;
+		break;
+	case DBUS_TYPE_OBJECT_PATH:
+		variant_sig = DBUS_TYPE_ARRAY_AS_STRING
+				DBUS_TYPE_OBJECT_PATH_AS_STRING;
+		array_sig = DBUS_TYPE_OBJECT_PATH_AS_STRING;
+		break;
+	case DBUS_TYPE_DICT_ENTRY:
+		variant_sig = DBUS_TYPE_ARRAY_AS_STRING
+				DBUS_STRUCT_BEGIN_CHAR_AS_STRING
+				DBUS_TYPE_ARRAY_AS_STRING
+					DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+						DBUS_TYPE_STRING_AS_STRING
+						DBUS_TYPE_VARIANT_AS_STRING
+					DBUS_DICT_ENTRY_END_CHAR_AS_STRING
+				DBUS_STRUCT_END_CHAR_AS_STRING;
+		array_sig = DBUS_STRUCT_BEGIN_CHAR_AS_STRING
+				DBUS_TYPE_ARRAY_AS_STRING
+					DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+						DBUS_TYPE_STRING_AS_STRING
+						DBUS_TYPE_VARIANT_AS_STRING
+					DBUS_DICT_ENTRY_END_CHAR_AS_STRING
+				DBUS_STRUCT_END_CHAR_AS_STRING;
+		break;
+	default:
+		return;
+	}
+
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &key);
+
+	dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
+							variant_sig, &value);
+
+	dbus_message_iter_open_container(&value, DBUS_TYPE_ARRAY,
+							array_sig, &array);
+	if (function)
+		function(&array, user_data);
+	dbus_message_iter_close_container(&value, &array);
+
+	dbus_message_iter_close_container(iter, &value);
+}
+
+static DBusConnection *connection = NULL;
+
+dbus_bool_t connman_dbus_property_changed_basic(const char *path,
+				const char *interface, const char *key,
+							int type, void *val)
+{
+	DBusMessage *signal;
+	DBusMessageIter iter;
+
+	if (!path)
+		return FALSE;
+
+	signal = dbus_message_new_signal(path, interface, "PropertyChanged");
+	if (!signal)
+		return FALSE;
+
+	dbus_message_iter_init_append(signal, &iter);
+	connman_dbus_property_append_basic(&iter, key, type, val);
+
+	g_dbus_send_message(connection, signal);
+
+	return TRUE;
+}
+
+dbus_bool_t connman_dbus_property_changed_dict(const char *path,
+				const char *interface, const char *key,
+			connman_dbus_append_cb_t function, void *user_data)
+{
+	DBusMessage *signal;
+	DBusMessageIter iter;
+
+	if (!path)
+		return FALSE;
+
+	signal = dbus_message_new_signal(path, interface, "PropertyChanged");
+	if (!signal)
+		return FALSE;
+
+	dbus_message_iter_init_append(signal, &iter);
+	connman_dbus_property_append_dict(&iter, key, function, user_data);
+
+	g_dbus_send_message(connection, signal);
+
+	return TRUE;
+}
+
+dbus_bool_t connman_dbus_property_changed_array(const char *path,
+			const char *interface, const char *key, int type,
+			connman_dbus_append_cb_t function, void *user_data)
+{
+	DBusMessage *signal;
+	DBusMessageIter iter;
+
+	if (!path)
+		return FALSE;
+
+	signal = dbus_message_new_signal(path, interface, "PropertyChanged");
+	if (!signal)
+		return FALSE;
+
+	dbus_message_iter_init_append(signal, &iter);
+	connman_dbus_property_append_array(&iter, key, type,
+						function, user_data);
+
+	g_dbus_send_message(connection, signal);
+
+	return TRUE;
+}
+
+dbus_bool_t connman_dbus_setting_changed_basic(const char *owner,
+				const char *path, const char *key,
+				int type, void *val)
+{
+	DBusMessage *msg;
+	DBusMessageIter array, dict;
+
+	if (!owner || !path)
+		return FALSE;
+
+	msg = dbus_message_new_method_call(owner, path,
+						CONNMAN_NOTIFICATION_INTERFACE,
+						"Update");
+	if (!msg)
+		return FALSE;
+
+	dbus_message_iter_init_append(msg, &array);
+	connman_dbus_dict_open(&array, &dict);
+
+	connman_dbus_dict_append_basic(&dict, key, type, val);
+
+	connman_dbus_dict_close(&array, &dict);
+
+	g_dbus_send_message(connection, msg);
+
+	return TRUE;
+}
+
+dbus_bool_t connman_dbus_setting_changed_dict(const char *owner,
+				const char *path, const char *key,
+				connman_dbus_append_cb_t function,
+				void *user_data)
+{
+	DBusMessage *msg;
+	DBusMessageIter array, dict;
+
+	if (!owner || !path)
+		return FALSE;
+
+	msg = dbus_message_new_method_call(owner, path,
+						CONNMAN_NOTIFICATION_INTERFACE,
+						"Update");
+	if (!msg)
+		return FALSE;
+
+	dbus_message_iter_init_append(msg, &array);
+	connman_dbus_dict_open(&array, &dict);
+
+	connman_dbus_dict_append_dict(&dict, key, function, user_data);
+
+	connman_dbus_dict_close(&array, &dict);
+
+	g_dbus_send_message(connection, msg);
+
+	return TRUE;
+}
+
+dbus_bool_t connman_dbus_setting_changed_array(const char *owner,
+				const char *path, const char *key, int type,
+				connman_dbus_append_cb_t function,
+				void *user_data)
+{
+	DBusMessage *msg;
+	DBusMessageIter array, dict;
+
+	if (!owner || !path)
+		return FALSE;
+
+	msg = dbus_message_new_method_call(owner, path,
+						CONNMAN_NOTIFICATION_INTERFACE,
+						"Update");
+	if (!msg)
+		return FALSE;
+
+	dbus_message_iter_init_append(msg, &array);
+	connman_dbus_dict_open(&array, &dict);
+
+	connman_dbus_dict_append_array(&dict, key, type, function, user_data);
+
+	connman_dbus_dict_close(&array, &dict);
+
+	g_dbus_send_message(connection, msg);
+
+	return TRUE;
+}
+
+dbus_bool_t __connman_dbus_append_objpath_dict_array(DBusMessage *msg,
+		connman_dbus_append_cb_t function, void *user_data)
+{
+	DBusMessageIter iter, array;
+
+	if (!msg || !function)
+		return FALSE;
+
+	dbus_message_iter_init_append(msg, &iter);
+	dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
+			DBUS_STRUCT_BEGIN_CHAR_AS_STRING
+			DBUS_TYPE_OBJECT_PATH_AS_STRING
+			DBUS_TYPE_ARRAY_AS_STRING
+				DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+					DBUS_TYPE_STRING_AS_STRING
+					DBUS_TYPE_VARIANT_AS_STRING
+				DBUS_DICT_ENTRY_END_CHAR_AS_STRING
+			DBUS_STRUCT_END_CHAR_AS_STRING, &array);
+
+	function(&array, user_data);
+
+	dbus_message_iter_close_container(&iter, &array);
+
+	return TRUE;
+}
+
+dbus_bool_t __connman_dbus_append_objpath_array(DBusMessage *msg,
+			connman_dbus_append_cb_t function, void *user_data)
+{
+	DBusMessageIter iter, array;
+
+	if (!msg || !function)
+		return FALSE;
+
+	dbus_message_iter_init_append(msg, &iter);
+	dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
+				DBUS_TYPE_OBJECT_PATH_AS_STRING, &array);
+
+	function(&array, user_data);
+
+	dbus_message_iter_close_container(&iter, &array);
+
+	return TRUE;
+}
+
+struct callback_data {
+	void *cb;
+	void *user_data;
+};
+
+static void get_connection_unix_user_reply(DBusPendingCall *call,
+						void *user_data)
+{
+	struct callback_data *data = user_data;
+	connman_dbus_get_connection_unix_user_cb_t cb = data->cb;
+	DBusMessageIter iter;
+	DBusMessage *reply;
+	int err = 0;
+	unsigned int uid = 0;
+
+	reply = dbus_pending_call_steal_reply(call);
+
+	if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) {
+		DBG("Failed to retrieve UID");
+		err = -EIO;
+		goto done;
+	}
+
+	if (!dbus_message_has_signature(reply, "u")) {
+		DBG("Message signature is wrong");
+		err = -EINVAL;
+		goto done;
+	}
+
+	dbus_message_iter_init(reply, &iter);
+	dbus_message_iter_get_basic(&iter, &uid);
+
+done:
+	(*cb)(uid, data->user_data, err);
+
+	dbus_message_unref(reply);
+
+	dbus_pending_call_unref(call);
+}
+
+int connman_dbus_get_connection_unix_user(DBusConnection *connection,
+				const char *bus_name,
+				connman_dbus_get_connection_unix_user_cb_t func,
+				void *user_data)
+{
+	struct callback_data *data;
+	DBusPendingCall *call;
+	DBusMessage *msg = NULL;
+	int err;
+
+	data = g_try_new0(struct callback_data, 1);
+	if (!data) {
+		DBG("Can't allocate data structure");
+		return -ENOMEM;
+	}
+
+	msg = dbus_message_new_method_call(DBUS_SERVICE_DBUS, DBUS_PATH_DBUS,
+					DBUS_INTERFACE_DBUS,
+					"GetConnectionUnixUser");
+	if (!msg) {
+		DBG("Can't allocate new message");
+		err = -ENOMEM;
+		goto err;
+	}
+
+	dbus_message_append_args(msg, DBUS_TYPE_STRING, &bus_name,
+					DBUS_TYPE_INVALID);
+
+	if (!dbus_connection_send_with_reply(connection, msg, &call, -1)) {
+		DBG("Failed to execute method call");
+		err = -EINVAL;
+		goto err;
+	}
+
+	if (!call) {
+		DBG("D-Bus connection not available");
+		err = -EINVAL;
+		goto err;
+	}
+
+	data->cb = func;
+	data->user_data = user_data;
+
+	dbus_pending_call_set_notify(call, get_connection_unix_user_reply,
+							data, g_free);
+
+	dbus_message_unref(msg);
+
+	return 0;
+
+err:
+	dbus_message_unref(msg);
+	g_free(data);
+
+	return err;
+}
+
+static unsigned char *parse_context(DBusMessage *msg)
+{
+	DBusMessageIter iter, array;
+	unsigned char *ctx, *p;
+	int size = 0;
+
+	dbus_message_iter_init(msg, &iter);
+	dbus_message_iter_recurse(&iter, &array);
+	while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_BYTE) {
+		size++;
+
+		dbus_message_iter_next(&array);
+	}
+
+	if (size == 0)
+		return NULL;
+
+	ctx = g_try_malloc0(size + 1);
+	if (!ctx)
+		return NULL;
+
+	p = ctx;
+
+	dbus_message_iter_init(msg, &iter);
+	dbus_message_iter_recurse(&iter, &array);
+	while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_BYTE) {
+		dbus_message_iter_get_basic(&array, p);
+
+		p++;
+		dbus_message_iter_next(&array);
+	}
+
+	return ctx;
+}
+
+static void selinux_get_context_reply(DBusPendingCall *call, void *user_data)
+{
+	struct callback_data *data = user_data;
+	connman_dbus_get_context_cb_t cb = data->cb;
+	DBusMessage *reply;
+	unsigned char *context = NULL;
+	int err = 0;
+
+	reply = dbus_pending_call_steal_reply(call);
+
+	if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) {
+		DBG("Failed to retrieve SELinux context");
+		err = -EIO;
+		goto done;
+	}
+
+	if (!dbus_message_has_signature(reply, "ay")) {
+		DBG("Message signature is wrong");
+		err = -EINVAL;
+		goto done;
+	}
+
+	context = parse_context(reply);
+
+done:
+	(*cb)(context, data->user_data, err);
+
+	g_free(context);
+
+	dbus_message_unref(reply);
+
+	dbus_pending_call_unref(call);
+}
+
+int connman_dbus_get_selinux_context(DBusConnection *connection,
+				const char *service,
+				connman_dbus_get_context_cb_t func,
+				void *user_data)
+{
+	struct callback_data *data;
+	DBusPendingCall *call;
+	DBusMessage *msg = NULL;
+	int err;
+
+	if (!func)
+		return -EINVAL;
+
+	data = g_try_new0(struct callback_data, 1);
+	if (!data) {
+		DBG("Can't allocate data structure");
+		return -ENOMEM;
+	}
+
+	msg = dbus_message_new_method_call(DBUS_SERVICE_DBUS, DBUS_PATH_DBUS,
+					DBUS_INTERFACE_DBUS,
+					"GetConnectionSELinuxSecurityContext");
+	if (!msg) {
+		DBG("Can't allocate new message");
+		err = -ENOMEM;
+		goto err;
+	}
+
+	dbus_message_append_args(msg, DBUS_TYPE_STRING, &service,
+					DBUS_TYPE_INVALID);
+
+	if (!dbus_connection_send_with_reply(connection, msg, &call, -1)) {
+		DBG("Failed to execute method call");
+		err = -EINVAL;
+		goto err;
+	}
+
+	if (!call) {
+		DBG("D-Bus connection not available");
+		err = -EINVAL;
+		goto err;
+	}
+
+	data->cb = func;
+	data->user_data = user_data;
+
+	dbus_pending_call_set_notify(call, selinux_get_context_reply,
+							data, g_free);
+
+	dbus_message_unref(msg);
+
+	return 0;
+
+err:
+	dbus_message_unref(msg);
+	g_free(data);
+
+	return err;
+}
+
+void connman_dbus_reply_pending(DBusMessage *pending,
+					int error, const char *path)
+{
+	if (pending) {
+		if (error > 0) {
+			DBusMessage *reply;
+
+			reply = __connman_error_failed(pending,	error);
+			if (reply)
+				g_dbus_send_message(connection, reply);
+		} else {
+			const char *sender;
+
+			sender = dbus_message_get_interface(pending);
+			if (!path)
+				path = dbus_message_get_path(pending);
+
+			DBG("sender %s path %s", sender, path);
+
+			if (g_strcmp0(sender, CONNMAN_MANAGER_INTERFACE) == 0)
+				g_dbus_send_reply(connection, pending,
+					DBUS_TYPE_OBJECT_PATH, &path,
+							DBUS_TYPE_INVALID);
+			else
+				g_dbus_send_reply(connection, pending,
+							DBUS_TYPE_INVALID);
+		}
+
+		dbus_message_unref(pending);
+	}
+}
+
+DBusConnection *connman_dbus_get_connection(void)
+{
+	if (!connection)
+		return NULL;
+
+	return dbus_connection_ref(connection);
+}
+
+int __connman_dbus_init(DBusConnection *conn)
+{
+	DBG("");
+
+	connection = conn;
+
+	return 0;
+}
+
+void __connman_dbus_cleanup(void)
+{
+	DBG("");
+
+	connection = NULL;
+}
diff --git a/connman/src/detect.c b/connman/src/detect.c
new file mode 100644
index 0000000..03122b2
--- /dev/null
+++ b/connman/src/detect.c
@@ -0,0 +1,139 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2013  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 <glib.h>
+
+#include "connman.h"
+
+static GSList *device_list = NULL;
+
+static struct connman_device *find_device(int index)
+{
+	GSList *list;
+
+	for (list = device_list; list; list = list->next) {
+		struct connman_device *device = list->data;
+
+		if (connman_device_get_index(device) == index)
+			return device;
+	}
+
+	return NULL;
+}
+
+static void detect_newlink(unsigned short type, int index,
+					unsigned flags, unsigned change)
+{
+	struct connman_device *device;
+	enum connman_device_type devtype;
+
+	DBG("type %d index %d", type, index);
+
+	device = find_device(index);
+	if (device)
+		return;
+
+	devtype = __connman_rtnl_get_device_type(index);
+
+	DBG("device %p (%s) devtype %d", 
+        device, 
+        device ? connman_device_get_ident(device) : NULL,
+        devtype);
+
+	switch (devtype) {
+	case CONNMAN_DEVICE_TYPE_UNKNOWN:
+	case CONNMAN_DEVICE_TYPE_VENDOR:
+	case CONNMAN_DEVICE_TYPE_BLUETOOTH:
+	case CONNMAN_DEVICE_TYPE_CELLULAR:
+	case CONNMAN_DEVICE_TYPE_GPS:
+	case CONNMAN_DEVICE_TYPE_LOWPAN:
+		return;
+	case CONNMAN_DEVICE_TYPE_ETHERNET:
+	case CONNMAN_DEVICE_TYPE_WIFI:
+	case CONNMAN_DEVICE_TYPE_GADGET:
+		break;
+	}
+
+	device = connman_device_create_from_index(index);
+	if (!device)
+		return;
+
+	if (connman_device_register(device) < 0) {
+		connman_device_unref(device);
+		return;
+	}
+
+	device_list = g_slist_prepend(device_list, device);
+}
+
+static void detect_dellink(unsigned short type, int index,
+					unsigned flags, unsigned change)
+{
+	struct connman_device *device;
+
+	DBG("type %d index %d", type, index);
+
+	device = find_device(index);
+	if (!device)
+		return;
+
+	device_list = g_slist_remove(device_list, device);
+
+	connman_device_unregister(device);
+	connman_device_unref(device);
+}
+
+static struct connman_rtnl detect_rtnl = {
+	.name		= "detect",
+	.priority	= CONNMAN_RTNL_PRIORITY_LOW,
+	.newlink	= detect_newlink,
+	.dellink	= detect_dellink,
+};
+
+int __connman_detect_init(void)
+{
+	DBG("");
+
+	return connman_rtnl_register(&detect_rtnl);
+}
+
+void __connman_detect_cleanup(void)
+{
+	GSList *list;
+
+	DBG("");
+
+	connman_rtnl_unregister(&detect_rtnl);
+
+	for (list = device_list; list; list = list->next) {
+		struct connman_device *device = list->data;
+
+		connman_device_unregister(device);
+		connman_device_unref(device);
+	}
+
+	g_slist_free(device_list);
+	device_list = NULL;
+}
diff --git a/connman/src/device.c b/connman/src/device.c
new file mode 100644
index 0000000..fe772ea
--- /dev/null
+++ b/connman/src/device.c
@@ -0,0 +1,1500 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2014  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 <string.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/ioctl.h>
+#include <net/ethernet.h>
+#include <net/if.h>
+
+#include "connman.h"
+
+static GSList *device_list = NULL;
+static gchar **device_filter = NULL;
+static gchar **nodevice_filter = NULL;
+
+enum connman_pending_type {
+	PENDING_NONE	= 0,
+	PENDING_ENABLE	= 1,
+	PENDING_DISABLE = 2,
+};
+
+struct connman_device {
+	int refcount;
+	enum connman_device_type type;
+	enum connman_pending_type powered_pending;	/* Indicates a pending
+							 * enable/disable
+							 * request
+							 */
+	bool powered;
+	bool scanning;
+	bool disconnected;
+	char *name;
+	char *node;
+	char *address;
+	char *interface;
+	char *ident;
+	char *path;
+	int index;
+	guint pending_timeout;
+
+	struct connman_device_driver *driver;
+	void *driver_data;
+
+	char *last_network;
+	struct connman_network *network;
+	GHashTable *networks;
+};
+
+static void clear_pending_trigger(struct connman_device *device)
+{
+	if (device->pending_timeout > 0) {
+		g_source_remove(device->pending_timeout);
+		device->pending_timeout = 0;
+	}
+}
+
+static const char *type2description(enum connman_device_type type)
+{
+	switch (type) {
+	case CONNMAN_DEVICE_TYPE_UNKNOWN:
+	case CONNMAN_DEVICE_TYPE_VENDOR:
+		break;
+	case CONNMAN_DEVICE_TYPE_ETHERNET:
+		return "Ethernet";
+	case CONNMAN_DEVICE_TYPE_WIFI:
+		return "Wireless";
+	case CONNMAN_DEVICE_TYPE_BLUETOOTH:
+		return "Bluetooth";
+	case CONNMAN_DEVICE_TYPE_GPS:
+		return "GPS";
+	case CONNMAN_DEVICE_TYPE_CELLULAR:
+		return "Cellular";
+	case CONNMAN_DEVICE_TYPE_GADGET:
+		return "Gadget";
+	case CONNMAN_DEVICE_TYPE_LOWPAN:
+		return "Low-Power Wireless";
+
+	}
+
+	return NULL;
+}
+
+static const char *type2string(enum connman_device_type type)
+{
+	switch (type) {
+	case CONNMAN_DEVICE_TYPE_UNKNOWN:
+	case CONNMAN_DEVICE_TYPE_VENDOR:
+		break;
+	case CONNMAN_DEVICE_TYPE_ETHERNET:
+		return "ethernet";
+	case CONNMAN_DEVICE_TYPE_WIFI:
+		return "wifi";
+	case CONNMAN_DEVICE_TYPE_BLUETOOTH:
+		return "bluetooth";
+	case CONNMAN_DEVICE_TYPE_GPS:
+		return "gps";
+	case CONNMAN_DEVICE_TYPE_CELLULAR:
+		return "cellular";
+	case CONNMAN_DEVICE_TYPE_GADGET:
+		return "gadget";
+	case CONNMAN_DEVICE_TYPE_LOWPAN:
+		return "lowpan";
+	}
+
+	return NULL;
+}
+
+enum connman_service_type __connman_device_get_service_type(
+				struct connman_device *device)
+{
+	enum connman_device_type type = connman_device_get_type(device);
+
+	switch (type) {
+	case CONNMAN_DEVICE_TYPE_UNKNOWN:
+	case CONNMAN_DEVICE_TYPE_VENDOR:
+	case CONNMAN_DEVICE_TYPE_GPS:
+		break;
+	case CONNMAN_DEVICE_TYPE_ETHERNET:
+		return CONNMAN_SERVICE_TYPE_ETHERNET;
+	case CONNMAN_DEVICE_TYPE_WIFI:
+		return CONNMAN_SERVICE_TYPE_WIFI;
+	case CONNMAN_DEVICE_TYPE_BLUETOOTH:
+		return CONNMAN_SERVICE_TYPE_BLUETOOTH;
+	case CONNMAN_DEVICE_TYPE_CELLULAR:
+		return CONNMAN_SERVICE_TYPE_CELLULAR;
+	case CONNMAN_DEVICE_TYPE_GADGET:
+		return CONNMAN_SERVICE_TYPE_GADGET;
+	case CONNMAN_DEVICE_TYPE_LOWPAN:
+		return CONNMAN_SERVICE_TYPE_LOWPAN;
+
+	}
+
+	return CONNMAN_SERVICE_TYPE_UNKNOWN;
+}
+
+static gboolean device_pending_reset(gpointer user_data)
+{
+	struct connman_device *device = user_data;
+
+	DBG("device %p", device);
+
+	/* Power request timedout, reset power pending state. */
+	device->pending_timeout = 0;
+	device->powered_pending = PENDING_NONE;
+
+	return FALSE;
+}
+
+int __connman_device_enable(struct connman_device *device)
+{
+	int err;
+
+	DBG("device %p", device);
+
+	if (!device->driver || !device->driver->enable)
+		return -EOPNOTSUPP;
+
+	/* There is an ongoing power disable request. */
+	if (device->powered_pending == PENDING_DISABLE)
+		return -EBUSY;
+
+	if (device->powered_pending == PENDING_ENABLE)
+		return -EALREADY;
+
+	if (device->powered_pending == PENDING_NONE && device->powered)
+		return -EALREADY;
+
+	if (device->index > 0) {
+		err = connman_inet_ifup(device->index);
+		if (err < 0 && err != -EALREADY)
+			return err;
+	}
+
+	device->powered_pending = PENDING_ENABLE;
+
+	err = device->driver->enable(device);
+	/*
+	 * device gets enabled right away.
+	 * Invoke the callback
+	 */
+	if (err == 0) {
+		connman_device_set_powered(device, true);
+		goto done;
+	}
+
+	if (err == -EALREADY) {
+		/* If device is already powered, but connman is not updated */
+		connman_device_set_powered(device, true);
+		goto done;
+	}
+	/*
+	 * if err == -EINPROGRESS, then the DBus call to the respective daemon
+	 * was successful. We set a 4 sec timeout so if the daemon never
+	 * returns a reply, we would reset the pending request.
+	 */
+	if (err == -EINPROGRESS)
+		device->pending_timeout = g_timeout_add_seconds(4,
+					device_pending_reset, device);
+done:
+	return err;
+}
+
+int __connman_device_disable(struct connman_device *device)
+{
+	int err;
+
+	DBG("device %p", device);
+
+	/* Ongoing power enable request */
+	if (device->powered_pending == PENDING_ENABLE)
+		return -EBUSY;
+
+	if (device->powered_pending == PENDING_DISABLE)
+		return -EALREADY;
+
+	if (device->powered_pending == PENDING_NONE && !device->powered)
+		return -EALREADY;
+
+	device->powered_pending = PENDING_DISABLE;
+
+	if (device->network) {
+		struct connman_service *service =
+			connman_service_lookup_from_network(device->network);
+
+		if (service)
+			__connman_service_disconnect(service);
+		else
+			connman_network_set_connected(device->network, false);
+	}
+
+	if (!device->driver || !device->driver->disable)
+		return -EOPNOTSUPP;
+
+	err = device->driver->disable(device);
+	if (err == 0 || err == -EALREADY) {
+		connman_device_set_powered(device, false);
+		goto done;
+	}
+
+	if (err == -EINPROGRESS)
+		device->pending_timeout = g_timeout_add_seconds(4,
+					device_pending_reset, device);
+done:
+	return err;
+}
+
+static void probe_driver(struct connman_device_driver *driver)
+{
+	GSList *list;
+
+	DBG("driver %p name %s", driver, driver->name);
+
+	for (list = device_list; list; list = list->next) {
+		struct connman_device *device = list->data;
+
+		if (device->driver)
+			continue;
+
+		if (driver->type != device->type)
+			continue;
+
+		if (driver->probe(device) < 0)
+			continue;
+
+		device->driver = driver;
+
+		__connman_technology_add_device(device);
+	}
+}
+
+static void remove_device(struct connman_device *device)
+{
+	DBG("device %p", device);
+
+	__connman_device_disable(device);
+
+	__connman_technology_remove_device(device);
+
+	if (device->driver->remove)
+		device->driver->remove(device);
+
+	device->driver = NULL;
+}
+
+static void remove_driver(struct connman_device_driver *driver)
+{
+	GSList *list;
+
+	DBG("driver %p name %s", driver, driver->name);
+
+	for (list = device_list; list; list = list->next) {
+		struct connman_device *device = list->data;
+
+		if (device->driver == driver)
+			remove_device(device);
+	}
+}
+
+bool __connman_device_has_driver(struct connman_device *device)
+{
+	if (!device || !device->driver)
+		return false;
+
+	return true;
+}
+
+static GSList *driver_list = NULL;
+
+static gint compare_priority(gconstpointer a, gconstpointer b)
+{
+	const struct connman_device_driver *driver1 = a;
+	const struct connman_device_driver *driver2 = b;
+
+	return driver2->priority - driver1->priority;
+}
+
+/**
+ * connman_device_driver_register:
+ * @driver: device driver definition
+ *
+ * Register a new device driver
+ *
+ * Returns: %0 on success
+ */
+int connman_device_driver_register(struct connman_device_driver *driver)
+{
+	DBG("driver %p name %s", driver, driver->name);
+
+	driver_list = g_slist_insert_sorted(driver_list, driver,
+							compare_priority);
+	probe_driver(driver);
+
+	return 0;
+}
+
+/**
+ * connman_device_driver_unregister:
+ * @driver: device driver definition
+ *
+ * Remove a previously registered device driver
+ */
+void connman_device_driver_unregister(struct connman_device_driver *driver)
+{
+	DBG("driver %p name %s", driver, driver->name);
+
+	driver_list = g_slist_remove(driver_list, driver);
+
+	remove_driver(driver);
+}
+
+static void free_network(gpointer data)
+{
+	struct connman_network *network = data;
+
+	DBG("network %p", network);
+
+	__connman_network_set_device(network, NULL);
+
+	connman_network_unref(network);
+}
+
+static void device_destruct(struct connman_device *device)
+{
+	DBG("device %p name %s", device, device->name);
+
+	clear_pending_trigger(device);
+
+	g_free(device->ident);
+	g_free(device->node);
+	g_free(device->name);
+	g_free(device->address);
+	g_free(device->interface);
+	g_free(device->path);
+
+	g_free(device->last_network);
+
+	g_hash_table_destroy(device->networks);
+	device->networks = NULL;
+
+	g_free(device);
+}
+
+/**
+ * connman_device_create:
+ * @node: device node name (for example an address)
+ * @type: device type
+ *
+ * Allocate a new device of given #type and assign the #node name to it.
+ *
+ * Returns: a newly-allocated #connman_device structure
+ */
+struct connman_device *connman_device_create(const char *node,
+						enum connman_device_type type)
+{
+	struct connman_device *device;
+
+	DBG("node %s type %d", node, type);
+
+	device = g_try_new0(struct connman_device, 1);
+	if (!device)
+		return NULL;
+
+	DBG("device %p", device);
+
+	device->refcount = 1;
+
+	device->type = type;
+	device->name = g_strdup(type2description(device->type));
+
+	device->networks = g_hash_table_new_full(g_str_hash, g_str_equal,
+						g_free, free_network);
+
+	device_list = g_slist_prepend(device_list, device);
+
+	return device;
+}
+
+/**
+ * connman_device_ref:
+ * @device: device structure
+ *
+ * Increase reference counter of device
+ */
+struct connman_device *connman_device_ref_debug(struct connman_device *device,
+				const char *file, int line, const char *caller)
+{
+	DBG("%p ref %d by %s:%d:%s()", device, device->refcount + 1,
+		file, line, caller);
+
+	__sync_fetch_and_add(&device->refcount, 1);
+
+	return device;
+}
+
+/**
+ * connman_device_unref:
+ * @device: device structure
+ *
+ * Decrease reference counter of device
+ */
+void connman_device_unref_debug(struct connman_device *device,
+				const char *file, int line, const char *caller)
+{
+	DBG("%p unref %d by %s:%d:%s()", device, device->refcount - 1,
+		file, line, caller);
+
+	if (__sync_fetch_and_sub(&device->refcount, 1) != 1)
+		return;
+
+	if (device->driver) {
+		device->driver->remove(device);
+		device->driver = NULL;
+	}
+
+	device_list = g_slist_remove(device_list, device);
+
+	device_destruct(device);
+}
+
+const char *__connman_device_get_type(struct connman_device *device)
+{
+	return type2string(device->type);
+}
+
+/**
+ * connman_device_get_type:
+ * @device: device structure
+ *
+ * Get type of device
+ */
+enum connman_device_type connman_device_get_type(struct connman_device *device)
+{
+	return device->type;
+}
+
+/**
+ * connman_device_set_index:
+ * @device: device structure
+ * @index: index number
+ *
+ * Set index number of device
+ */
+void connman_device_set_index(struct connman_device *device, int index)
+{
+	device->index = index;
+}
+
+/**
+ * connman_device_get_index:
+ * @device: device structure
+ *
+ * Get index number of device
+ */
+int connman_device_get_index(struct connman_device *device)
+{
+	return device->index;
+}
+
+/**
+ * connman_device_set_interface:
+ * @device: device structure
+ * @interface: interface name
+ *
+ * Set interface name of device
+ */
+void connman_device_set_interface(struct connman_device *device,
+						const char *interface)
+{
+	g_free(device->interface);
+	device->interface = g_strdup(interface);
+
+	if (!device->name) {
+		const char *str = type2description(device->type);
+		if (str && device->interface)
+			device->name = g_strdup_printf("%s (%s)", str,
+							device->interface);
+	}
+}
+
+/**
+ * connman_device_set_ident:
+ * @device: device structure
+ * @ident: unique identifier
+ *
+ * Set unique identifier of device
+ */
+void connman_device_set_ident(struct connman_device *device,
+							const char *ident)
+{
+	g_free(device->ident);
+	device->ident = g_strdup(ident);
+}
+
+const char *connman_device_get_ident(struct connman_device *device)
+{
+	return device->ident;
+}
+
+/**
+ * connman_device_set_powered:
+ * @device: device structure
+ * @powered: powered state
+ *
+ * Change power state of device
+ */
+int connman_device_set_powered(struct connman_device *device,
+						bool powered)
+{
+	enum connman_service_type type;
+
+	DBG("driver %p powered %d", device, powered);
+
+	if (device->powered == powered)
+		return -EALREADY;
+
+	clear_pending_trigger(device);
+
+	device->powered_pending = PENDING_NONE;
+
+	device->powered = powered;
+
+	type = __connman_device_get_service_type(device);
+
+	if (!device->powered) {
+		__connman_technology_disabled(type);
+		return 0;
+	}
+
+	__connman_technology_enabled(type);
+
+	connman_device_set_disconnected(device, false);
+	device->scanning = false;
+
+	if (device->driver && device->driver->scan)
+		device->driver->scan(CONNMAN_SERVICE_TYPE_UNKNOWN, device,
+					NULL, 0, NULL, NULL, NULL, NULL);
+
+	return 0;
+}
+
+bool connman_device_get_powered(struct connman_device *device)
+{
+	return device->powered;
+}
+
+static int device_scan(enum connman_service_type type,
+				struct connman_device *device)
+{
+    DBG("type %d device %p device->driver %p device->driver->scan %p powered %d", type, device, device->driver, device->driver->scan, device->powered);
+	if (!device->driver || !device->driver->scan)
+		return -EOPNOTSUPP;
+
+	if (!device->powered)
+		return -ENOLINK;
+
+	connman_info("Requested scan for device %s interface %s.",
+		device->driver->name, device->interface);
+
+    DBG("type %d", type);
+	return device->driver->scan(type, device, NULL, 0,
+					NULL, NULL, NULL, NULL);
+}
+
+int __connman_device_disconnect(struct connman_device *device)
+{
+	GHashTableIter iter;
+	gpointer key, value;
+
+	DBG("device %p", device);
+
+	connman_device_set_disconnected(device, true);
+
+	g_hash_table_iter_init(&iter, device->networks);
+
+	while (g_hash_table_iter_next(&iter, &key, &value)) {
+		struct connman_network *network = value;
+
+		if (connman_network_get_connecting(network)) {
+			/*
+			 * Skip network in the process of connecting.
+			 * This is a workaround for WiFi networks serviced
+			 * by the supplicant plugin that hold a reference
+			 * to the network.  If we disconnect the network
+			 * here then the referenced object will not be
+			 * registered and usage (like launching DHCP client)
+			 * will fail.  There is nothing to be gained by
+			 * removing the network here anyway.
+			 */
+			connman_warn("Skipping disconnect of %s, network is connecting.",
+				connman_network_get_identifier(network));
+			continue;
+		}
+
+		__connman_network_disconnect(network, FALSE);
+	}
+
+	return 0;
+}
+
+int connman_device_reconnect_service(struct connman_device *device)
+{
+	DBG("device %p", device);
+
+	__connman_service_auto_connect(CONNMAN_SERVICE_CONNECT_REASON_AUTO);
+
+	return 0;
+}
+
+static void mark_network_available(gpointer key, gpointer value,
+							gpointer user_data)
+{
+	struct connman_network *network = value;
+
+	connman_network_set_available(network, true);
+}
+
+static void mark_network_unavailable(gpointer key, gpointer value,
+							gpointer user_data)
+{
+	struct connman_network *network = value;
+
+	if (connman_network_get_connected(network) ||
+			connman_network_get_connecting(network))
+		return;
+
+	connman_network_set_available(network, false);
+}
+
+static gboolean remove_unavailable_network(gpointer key, gpointer value,
+							gpointer user_data)
+{
+	struct connman_network *network = value;
+
+	if (connman_network_get_connected(network))
+		return FALSE;
+
+	if (connman_network_get_available(network))
+		return FALSE;
+
+	return TRUE;
+}
+
+void __connman_device_cleanup_networks(struct connman_device *device)
+{
+	g_hash_table_foreach_remove(device->networks,
+					remove_unavailable_network, NULL);
+}
+
+bool connman_device_get_scanning(struct connman_device *device)
+{
+	return device->scanning;
+}
+
+void connman_device_reset_scanning(struct connman_device *device)
+{
+	g_hash_table_foreach(device->networks,
+				mark_network_available, NULL);
+}
+
+/**
+ * connman_device_set_scanning:
+ * @device: device structure
+ * @scanning: scanning state
+ *
+ * Change scanning state of device
+ */
+int connman_device_set_scanning(struct connman_device *device,
+				enum connman_service_type type, bool scanning)
+{
+	DBG("device %p scanning %d", device, scanning);
+
+	if (!device->driver || !device->driver->scan)
+		return -EINVAL;
+
+	if (device->scanning == scanning)
+		return -EALREADY;
+
+	device->scanning = scanning;
+
+	if (scanning) {
+		__connman_technology_scan_started(device);
+
+		g_hash_table_foreach(device->networks,
+					mark_network_unavailable, NULL);
+
+		return 0;
+	}
+
+	__connman_device_cleanup_networks(device);
+
+	__connman_technology_scan_stopped(device, type);
+
+	__connman_service_auto_connect(CONNMAN_SERVICE_CONNECT_REASON_AUTO);
+
+	return 0;
+}
+
+/**
+ * connman_device_set_disconnected:
+ * @device: device structure
+ * @disconnected: disconnected state
+ *
+ * Change disconnected state of device (only for device with networks)
+ */
+int connman_device_set_disconnected(struct connman_device *device,
+						bool disconnected)
+{
+	DBG("device %p disconnected %d", device, disconnected);
+
+	if (device->disconnected == disconnected)
+		return -EALREADY;
+
+	device->disconnected = disconnected;
+
+	return 0;
+}
+
+/**
+ * connman_device_get_disconnected:
+ * @device: device structure
+ *
+ * Get device disconnected state
+ */
+bool connman_device_get_disconnected(struct connman_device *device)
+{
+	return device->disconnected;
+}
+
+/**
+ * connman_device_set_string:
+ * @device: device structure
+ * @key: unique identifier
+ * @value: string value
+ *
+ * Set string value for specific key
+ */
+int connman_device_set_string(struct connman_device *device,
+					const char *key, const char *value)
+{
+	DBG("device %p key %s value %s", device, key, value);
+
+	if (g_str_equal(key, "Address")) {
+		g_free(device->address);
+		device->address = g_strdup(value);
+	} else if (g_str_equal(key, "Name")) {
+		g_free(device->name);
+		device->name = g_strdup(value);
+	} else if (g_str_equal(key, "Node")) {
+		g_free(device->node);
+		device->node = g_strdup(value);
+	} else if (g_str_equal(key, "Path")) {
+		g_free(device->path);
+		device->path = g_strdup(value);
+	} else {
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+/**
+ * connman_device_get_string:
+ * @device: device structure
+ * @key: unique identifier
+ *
+ * Get string value for specific key
+ */
+const char *connman_device_get_string(struct connman_device *device,
+							const char *key)
+{
+	DBG("device %p key %s", device, key);
+
+	if (g_str_equal(key, "Address"))
+		return device->address;
+	else if (g_str_equal(key, "Name"))
+		return device->name;
+	else if (g_str_equal(key, "Node"))
+		return device->node;
+	else if (g_str_equal(key, "Interface"))
+		return device->interface;
+	else if (g_str_equal(key, "Path"))
+		return device->path;
+
+	return NULL;
+}
+
+/**
+ * connman_device_add_network:
+ * @device: device structure
+ * @network: network structure
+ *
+ * Add new network to the device
+ */
+int connman_device_add_network(struct connman_device *device,
+					struct connman_network *network)
+{
+	const char *identifier = connman_network_get_identifier(network);
+
+	DBG("device %p network %p identifier %s", device, network, identifier);
+
+	if (!identifier)
+		return -EINVAL;
+
+	connman_network_ref(network);
+
+	__connman_network_set_device(network, device);
+
+	g_hash_table_replace(device->networks, g_strdup(identifier),
+								network);
+
+	return 0;
+}
+
+/**
+ * connman_device_get_network:
+ * @device: device structure
+ * @identifier: network identifier
+ *
+ * Get network for given identifier
+ */
+struct connman_network *connman_device_get_network(struct connman_device *device,
+							const char *identifier)
+{
+	DBG("device %p identifier %s", device, identifier);
+
+	return g_hash_table_lookup(device->networks, identifier);
+}
+
+/**
+ * connman_device_remove_network:
+ * @device: device structure
+ * @identifier: network identifier
+ *
+ * Remove network for given identifier
+ */
+int connman_device_remove_network(struct connman_device *device,
+						struct connman_network *network)
+{
+	const char *identifier;
+
+	DBG("device %p network %p", device, network);
+
+	if (!network)
+		return 0;
+
+	identifier = connman_network_get_identifier(network);
+	g_hash_table_remove(device->networks, identifier);
+
+	return 0;
+}
+
+void __connman_device_set_network(struct connman_device *device,
+					struct connman_network *network)
+{
+	const char *name;
+
+	if (!device)
+		return;
+
+	if (device->network == network)
+		return;
+
+	if (network) {
+		name = connman_network_get_string(network, "Name");
+		g_free(device->last_network);
+		device->last_network = g_strdup(name);
+
+		device->network = network;
+	} else {
+		g_free(device->last_network);
+		device->last_network = NULL;
+
+		device->network = NULL;
+	}
+}
+
+void connman_device_set_network(struct connman_device *device,
+					struct connman_network *network)
+{
+	__connman_device_set_network(device, network);
+}
+
+void connman_device_cleanup_networks(struct connman_device *device)
+{
+	__connman_device_cleanup_networks(device);
+}
+
+static bool match_driver(struct connman_device *device,
+					struct connman_device_driver *driver)
+{
+	if (device->type == driver->type ||
+			driver->type == CONNMAN_DEVICE_TYPE_UNKNOWN)
+		return true;
+
+	return false;
+}
+
+/**
+ * connman_device_register:
+ * @device: device structure
+ *
+ * Register device with the system
+ */
+int connman_device_register(struct connman_device *device)
+{
+	GSList *list;
+
+	DBG("device %p name %s", device, device->name);
+
+	if (device->driver)
+		return -EALREADY;
+
+	for (list = driver_list; list; list = list->next) {
+		struct connman_device_driver *driver = list->data;
+
+		if (!match_driver(device, driver))
+			continue;
+
+		DBG("driver %p name %s", driver, driver->name);
+
+		if (driver->probe(device) == 0) {
+			device->driver = driver;
+			break;
+		}
+	}
+
+	if (!device->driver)
+		return 0;
+
+	return __connman_technology_add_device(device);
+}
+
+/**
+ * connman_device_unregister:
+ * @device: device structure
+ *
+ * Unregister device with the system
+ */
+void connman_device_unregister(struct connman_device *device)
+{
+	DBG("device %p name %s", device, device->name);
+
+	if (!device->driver)
+		return;
+
+	remove_device(device);
+}
+
+/**
+ * connman_device_get_data:
+ * @device: device structure
+ *
+ * Get private device data pointer
+ */
+void *connman_device_get_data(struct connman_device *device)
+{
+	return device->driver_data;
+}
+
+/**
+ * connman_device_set_data:
+ * @device: device structure
+ * @data: data pointer
+ *
+ * Set private device data pointer
+ */
+void connman_device_set_data(struct connman_device *device, void *data)
+{
+	device->driver_data = data;
+}
+
+struct connman_device *__connman_device_find_device(
+				enum connman_service_type type)
+{
+	GSList *list;
+
+	for (list = device_list; list; list = list->next) {
+		struct connman_device *device = list->data;
+		enum connman_service_type service_type =
+			__connman_device_get_service_type(device);
+
+		if (service_type != type)
+			continue;
+
+		return device;
+	}
+
+	return NULL;
+}
+
+struct connman_device *connman_device_find_by_index(int index)
+{
+	GSList *list;
+
+	for (list = device_list; list; list = list->next) {
+		struct connman_device *device = list->data;
+		if (device->index == index)
+			return device;
+	}
+
+	return NULL;
+}
+
+/**
+ * connman_device_set_regdom
+ * @device: device structure
+ * @alpha2: string representing regulatory domain
+ *
+ * Set regulatory domain on device basis
+ */
+int connman_device_set_regdom(struct connman_device *device,
+						const char *alpha2)
+{
+	if (!device->driver || !device->driver->set_regdom)
+		return -ENOTSUP;
+
+	if (!device->powered)
+		return -EINVAL;
+
+	return device->driver->set_regdom(device, alpha2);
+}
+
+/**
+ * connman_device_regdom_notify
+ * @device: device structure
+ * @alpha2: string representing regulatory domain
+ *
+ * Notify on setting regulatory domain on device basis
+ */
+void connman_device_regdom_notify(struct connman_device *device,
+					int result, const char *alpha2)
+{
+	__connman_technology_notify_regdom_by_device(device, result, alpha2);
+}
+
+int __connman_device_request_scan(enum connman_service_type type)
+{
+	bool success = false;
+	int last_err = -ENOSYS;
+	GSList *list;
+	int err;
+
+	switch (type) {
+	case CONNMAN_SERVICE_TYPE_UNKNOWN:
+	case CONNMAN_SERVICE_TYPE_SYSTEM:
+	case CONNMAN_SERVICE_TYPE_ETHERNET:
+	case CONNMAN_SERVICE_TYPE_BLUETOOTH:
+	case CONNMAN_SERVICE_TYPE_CELLULAR:
+	case CONNMAN_SERVICE_TYPE_GPS:
+	case CONNMAN_SERVICE_TYPE_VPN:
+	case CONNMAN_SERVICE_TYPE_GADGET:
+		return -EOPNOTSUPP;
+	case CONNMAN_SERVICE_TYPE_WIFI:
+	case CONNMAN_SERVICE_TYPE_P2P:
+	case CONNMAN_SERVICE_TYPE_LOWPAN:
+		break;
+	}
+
+	for (list = device_list; list; list = list->next) {
+		struct connman_device *device = list->data;
+		enum connman_service_type service_type =
+			__connman_device_get_service_type(device);
+
+		if (service_type != CONNMAN_SERVICE_TYPE_UNKNOWN) {
+			if (type == CONNMAN_SERVICE_TYPE_P2P) {
+				if (service_type != CONNMAN_SERVICE_TYPE_WIFI)
+					continue;
+			} else if (service_type != type)
+				continue;
+		}
+
+		err = device_scan(type, device);
+
+		/*
+		 * The upstream maintainers desire to collapse any
+		 * errors that are implicitly successes into explicit
+		 * successes as:
+		 *
+		 *   if (err == 0 || err == -EALREADY || err == -EINPROGRESS) {
+		 *
+		 * However, due to MEEGO-25990 <https://bugs.meego.com/
+		 * show_bug.cgi?id=25990>, this doesn't actually work
+		 * correctly and such collapes lead to a D-Bus pending
+		 * reply being lost and a D-Bus timeout for the
+		 * client. Instead, for now, simply short-circuit
+		 * these implicit successes as errors back to the
+		 * client (which will have to handle them gracefully).
+		 */
+
+		if (err == 0) {
+			success = true;
+		} else {
+			last_err = err;
+			DBG("device %p err %d", device, err);
+		}
+	}
+
+	if (success)
+		return 0;
+
+	return last_err;
+}
+
+int __connman_device_request_hidden_scan(struct connman_device *device,
+				const char *ssid, unsigned int ssid_len,
+				const char *identity, const char *passphrase,
+				const char *security, void *user_data)
+{
+	DBG("device %p", device);
+
+	if (!device || !device->driver ||
+			!device->driver->scan)
+		return -EINVAL;
+
+	return device->driver->scan(CONNMAN_SERVICE_TYPE_UNKNOWN,
+					device, ssid, ssid_len, identity,
+					passphrase, security, user_data);
+}
+
+static char *index2ident(int index, const char *prefix)
+{
+	struct ifreq ifr;
+	struct ether_addr eth;
+	char *str;
+	int sk, err, len;
+
+	if (index < 0)
+		return NULL;
+
+	sk = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
+	if (sk < 0)
+		return NULL;
+
+	memset(&ifr, 0, sizeof(ifr));
+	ifr.ifr_ifindex = index;
+
+	err = ioctl(sk, SIOCGIFNAME, &ifr);
+
+	if (err == 0)
+		err = ioctl(sk, SIOCGIFHWADDR, &ifr);
+
+	close(sk);
+
+	if (err < 0)
+		return NULL;
+
+	len = prefix ? strlen(prefix) + 18 : 18;
+
+	str = g_malloc(len);
+	if (!str)
+		return NULL;
+
+	memcpy(&eth, &ifr.ifr_hwaddr.sa_data, sizeof(eth));
+	snprintf(str, len, "%s%02x%02x%02x%02x%02x%02x",
+						prefix ? prefix : "",
+						eth.ether_addr_octet[0],
+						eth.ether_addr_octet[1],
+						eth.ether_addr_octet[2],
+						eth.ether_addr_octet[3],
+						eth.ether_addr_octet[4],
+						eth.ether_addr_octet[5]);
+
+	return str;
+}
+
+static char *index2addr(int index)
+{
+	struct ifreq ifr;
+	struct ether_addr eth;
+	char *str;
+	int sk, err;
+
+	if (index < 0)
+		return NULL;
+
+	sk = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
+	if (sk < 0)
+		return NULL;
+
+	memset(&ifr, 0, sizeof(ifr));
+	ifr.ifr_ifindex = index;
+
+	err = ioctl(sk, SIOCGIFNAME, &ifr);
+
+	if (err == 0)
+		err = ioctl(sk, SIOCGIFHWADDR, &ifr);
+
+	close(sk);
+
+	if (err < 0)
+		return NULL;
+
+	str = g_malloc(18);
+	if (!str)
+		return NULL;
+
+	memcpy(&eth, &ifr.ifr_hwaddr.sa_data, sizeof(eth));
+	snprintf(str, 18, "%02X:%02X:%02X:%02X:%02X:%02X",
+						eth.ether_addr_octet[0],
+						eth.ether_addr_octet[1],
+						eth.ether_addr_octet[2],
+						eth.ether_addr_octet[3],
+						eth.ether_addr_octet[4],
+						eth.ether_addr_octet[5]);
+
+	return str;
+}
+
+struct connman_device *connman_device_create_from_index(int index)
+{
+	enum connman_device_type type;
+	struct connman_device *device;
+	char *devname, *ident = NULL;
+	char *addr = NULL, *name = NULL;
+
+	if (index < 0)
+		return NULL;
+
+	devname = connman_inet_ifname(index);
+	if (!devname)
+		return NULL;
+
+	if (__connman_device_isfiltered(devname)) {
+		connman_info("Ignoring interface %s (filtered)", devname);
+		g_free(devname);
+		return NULL;
+	}
+
+	type = __connman_rtnl_get_device_type(index);
+
+	switch (type) {
+	case CONNMAN_DEVICE_TYPE_UNKNOWN:
+		connman_info("Ignoring interface %s (type unknown)", devname);
+		g_free(devname);
+		return NULL;
+	case CONNMAN_DEVICE_TYPE_ETHERNET:
+	case CONNMAN_DEVICE_TYPE_GADGET:
+	case CONNMAN_DEVICE_TYPE_WIFI:
+	case CONNMAN_DEVICE_TYPE_LOWPAN:
+		name = index2ident(index, "");
+		addr = index2addr(index);
+		break;
+	case CONNMAN_DEVICE_TYPE_BLUETOOTH:
+	case CONNMAN_DEVICE_TYPE_CELLULAR:
+	case CONNMAN_DEVICE_TYPE_GPS:
+	case CONNMAN_DEVICE_TYPE_VENDOR:
+		name = g_strdup(devname);
+		break;
+	}
+
+	device = connman_device_create(name, type);
+	if (!device)
+		goto done;
+
+	switch (type) {
+	case CONNMAN_DEVICE_TYPE_UNKNOWN:
+	case CONNMAN_DEVICE_TYPE_VENDOR:
+	case CONNMAN_DEVICE_TYPE_GPS:
+		break;
+	case CONNMAN_DEVICE_TYPE_ETHERNET:
+	case CONNMAN_DEVICE_TYPE_GADGET:
+		ident = index2ident(index, NULL);
+		break;
+	case CONNMAN_DEVICE_TYPE_WIFI:
+	case CONNMAN_DEVICE_TYPE_LOWPAN:
+		ident = index2ident(index, NULL);
+		break;
+	case CONNMAN_DEVICE_TYPE_BLUETOOTH:
+		break;
+	case CONNMAN_DEVICE_TYPE_CELLULAR:
+		ident = index2ident(index, NULL);
+		break;
+	}
+
+	connman_device_set_index(device, index);
+	connman_device_set_interface(device, devname);
+
+	if (ident) {
+		connman_device_set_ident(device, ident);
+		g_free(ident);
+	}
+
+	connman_device_set_string(device, "Address", addr);
+
+done:
+	g_free(devname);
+	g_free(name);
+	g_free(addr);
+
+	return device;
+}
+
+bool __connman_device_isfiltered(const char *devname)
+{
+	char **pattern;
+	char **blacklisted_interfaces;
+	bool match;
+
+	if (!device_filter)
+		goto nodevice;
+
+	for (pattern = device_filter, match = false; *pattern; pattern++) {
+		if (g_pattern_match_simple(*pattern, devname)) {
+			match = true;
+			break;
+		}
+	}
+
+	if (!match) {
+		DBG("ignoring device %s (match)", devname);
+		return true;
+	}
+
+nodevice:
+	if (g_pattern_match_simple("dummy*", devname)) {
+		DBG("ignoring dummy networking devices");
+		return true;
+	}
+
+	if (!nodevice_filter)
+		goto list;
+
+	for (pattern = nodevice_filter; *pattern; pattern++) {
+		if (g_pattern_match_simple(*pattern, devname)) {
+			DBG("ignoring device %s (no match)", devname);
+			return true;
+		}
+	}
+
+list:
+	blacklisted_interfaces =
+		connman_setting_get_string_list("NetworkInterfaceBlacklist");
+	if (!blacklisted_interfaces)
+		return false;
+
+	for (pattern = blacklisted_interfaces; *pattern; pattern++) {
+		if (g_str_has_prefix(devname, *pattern)) {
+			DBG("ignoring device %s (blacklist)", devname);
+			return true;
+		}
+	}
+
+	return false;
+}
+
+static void cleanup_devices(void)
+{
+	/*
+	 * Check what interfaces are currently up and if connman is
+	 * suppose to handle the interface, then cleanup the mess
+	 * related to that interface. There might be weird routes etc
+	 * that are related to that interface and that might confuse
+	 * connmand. So in this case we just turn the interface down
+	 * so that kernel removes routes/addresses automatically and
+	 * then proceed the startup.
+	 *
+	 * Note that this cleanup must be done before rtnl/detect code
+	 * has activated interface watches.
+	 */
+
+	char **interfaces;
+	int i;
+
+	interfaces = __connman_inet_get_running_interfaces();
+
+	if (!interfaces)
+		return;
+
+	for (i = 0; interfaces[i]; i++) {
+		bool filtered;
+		int index;
+		struct sockaddr_in sin_addr, sin_mask;
+
+		filtered = __connman_device_isfiltered(interfaces[i]);
+		if (filtered)
+			continue;
+
+		index = connman_inet_ifindex(interfaces[i]);
+		if (index < 0)
+			continue;
+
+		if (!__connman_inet_get_address_netmask(index, &sin_addr,
+							&sin_mask)) {
+			char *address = g_strdup(inet_ntoa(sin_addr.sin_addr));
+			char *netmask = g_strdup(inet_ntoa(sin_mask.sin_addr));
+
+			if (__connman_config_address_provisioned(address,
+								netmask)) {
+				DBG("Skip %s which is already provisioned "
+					"with %s/%s", interfaces[i], address,
+					netmask);
+				g_free(address);
+				g_free(netmask);
+				continue;
+			}
+
+			g_free(address);
+			g_free(netmask);
+		}
+
+		DBG("cleaning up %s index %d", interfaces[i], index);
+
+		connman_inet_ifdown(index);
+
+		/*
+		 * ConnMan will turn the interface UP automatically so
+		 * no need to do it here.
+		 */
+	}
+
+	g_strfreev(interfaces);
+}
+
+int __connman_device_init(const char *device, const char *nodevice)
+{
+	DBG("");
+
+	if (device)
+		device_filter = g_strsplit(device, ",", -1);
+
+	if (nodevice)
+		nodevice_filter = g_strsplit(nodevice, ",", -1);
+
+	cleanup_devices();
+
+	return 0;
+}
+
+void __connman_device_cleanup(void)
+{
+	DBG("");
+
+	g_strfreev(nodevice_filter);
+	g_strfreev(device_filter);
+}
diff --git a/connman/src/dhcp.c b/connman/src/dhcp.c
new file mode 100644
index 0000000..ef37ae5
--- /dev/null
+++ b/connman/src/dhcp.c
@@ -0,0 +1,708 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2013  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 <stdio.h>
+#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include <connman/ipconfig.h>
+#include <include/setting.h>
+
+#include <gdhcp/gdhcp.h>
+
+#include <glib.h>
+
+#include "connman.h"
+
+#define RATE_LIMIT_INTERVAL	60	/* delay between successive attempts */
+
+struct connman_dhcp {
+	struct connman_ipconfig *ipconfig;
+	struct connman_network *network;
+	dhcp_cb callback;
+	gpointer user_data;
+
+	char **nameservers;
+	char **timeservers;
+	char *pac;
+
+	unsigned int timeout;
+
+	GDHCPClient *ipv4ll_client;
+	GDHCPClient *dhcp_client;
+	char *ipv4ll_debug_prefix;
+	char *dhcp_debug_prefix;
+};
+
+static GHashTable *ipconfig_table;
+static bool ipv4ll_running;
+
+static void dhcp_free(struct connman_dhcp *dhcp)
+{
+	g_strfreev(dhcp->nameservers);
+	g_strfreev(dhcp->timeservers);
+	g_free(dhcp->pac);
+
+	dhcp->nameservers = NULL;
+	dhcp->timeservers = NULL;
+	dhcp->pac = NULL;
+
+	g_free(dhcp);
+}
+
+static void ipv4ll_stop_client(struct connman_dhcp *dhcp)
+{
+	if (!dhcp->ipv4ll_client)
+		return;
+
+	g_dhcp_client_stop(dhcp->ipv4ll_client);
+	g_dhcp_client_unref(dhcp->ipv4ll_client);
+	dhcp->ipv4ll_client = NULL;
+	ipv4ll_running = false;
+
+	g_free(dhcp->ipv4ll_debug_prefix);
+	dhcp->ipv4ll_debug_prefix = NULL;
+}
+
+static bool apply_dhcp_invalidate_on_network(struct connman_dhcp *dhcp)
+{
+	struct connman_service *service;
+	int i;
+
+	if (!dhcp->network)
+		return true;
+
+	service = connman_service_lookup_from_network(dhcp->network);
+	if (!service) {
+		connman_error("Can not lookup service");
+		return false;
+	}
+
+	__connman_service_set_domainname(service, NULL);
+	__connman_ipconfig_set_proxy_autoconfig(dhcp->ipconfig, NULL);
+
+	if (dhcp->timeservers) {
+		for (i = 0; dhcp->timeservers[i]; i++) {
+			__connman_service_timeserver_remove(service,
+							dhcp->timeservers[i]);
+		}
+	}
+	if (dhcp->nameservers) {
+		for (i = 0; dhcp->nameservers[i]; i++) {
+			__connman_service_nameserver_remove(service,
+						dhcp->nameservers[i], false);
+		}
+	}
+
+	return true;
+}
+
+/**
+ * dhcp_invalidate: Invalidate an existing DHCP lease
+ * @dhcp: pointer to the DHCP lease to invalidate.
+ * @callback: flag indicating whether or not to invoke the client callback
+ *            if present.
+ *
+ * Invalidates an existing DHCP lease, optionally invoking the client
+ * callback. The caller may wish to avoid the client callback invocation
+ * when the invocation of that callback might otherwise unnecessarily upset
+ * service state due to the IP configuration change implied by this
+ * invalidation.
+ */
+static void dhcp_invalidate(struct connman_dhcp *dhcp, bool callback)
+{
+	DBG("dhcp %p callback %u", dhcp, callback);
+
+	if (!dhcp)
+		return;
+
+	__connman_6to4_remove(dhcp->ipconfig);
+
+	if (!apply_dhcp_invalidate_on_network(dhcp))
+		return;
+
+	__connman_ipconfig_set_dhcp_address(dhcp->ipconfig,
+				__connman_ipconfig_get_local(dhcp->ipconfig));
+	DBG("last address %s",
+			__connman_ipconfig_get_dhcp_address(dhcp->ipconfig));
+
+	__connman_ipconfig_address_remove(dhcp->ipconfig);
+
+	__connman_ipconfig_set_local(dhcp->ipconfig, NULL);
+	__connman_ipconfig_set_broadcast(dhcp->ipconfig, NULL);
+	__connman_ipconfig_set_gateway(dhcp->ipconfig, NULL);
+	__connman_ipconfig_set_prefixlen(dhcp->ipconfig, 0);
+
+	if (dhcp->callback && callback)
+		dhcp->callback(dhcp->ipconfig, dhcp->network,
+						false, dhcp->user_data);
+}
+
+static void dhcp_valid(struct connman_dhcp *dhcp)
+{
+	if (dhcp->callback)
+		dhcp->callback(dhcp->ipconfig, dhcp->network,
+						true, dhcp->user_data);
+}
+
+static void dhcp_debug(const char *str, void *data)
+{
+	connman_info("%s: %s", (const char *) data, str);
+}
+
+static void ipv4ll_lost_cb(GDHCPClient *dhcp_client, gpointer user_data);
+static void ipv4ll_available_cb(GDHCPClient *ipv4ll_client, gpointer user_data);
+
+static int ipv4ll_start_client(struct connman_dhcp *dhcp)
+{
+	GDHCPClient *ipv4ll_client;
+	GDHCPClientError error;
+	const char *hostname;
+	int index;
+	int err;
+
+	if (dhcp->ipv4ll_client)
+		return -EALREADY;
+
+	index = __connman_ipconfig_get_index(dhcp->ipconfig);
+
+	ipv4ll_client = g_dhcp_client_new(G_DHCP_IPV4LL, index, &error);
+	if (error != G_DHCP_CLIENT_ERROR_NONE)
+		return -EINVAL;
+
+	if (getenv("CONNMAN_DHCP_DEBUG")) {
+		dhcp->ipv4ll_debug_prefix = g_strdup_printf("IPv4LL index %d",
+							index);
+		g_dhcp_client_set_debug(ipv4ll_client, dhcp_debug,
+					dhcp->ipv4ll_debug_prefix);
+	}
+
+	g_dhcp_client_set_id(ipv4ll_client);
+
+	if (dhcp->network) {
+		hostname = connman_utsname_get_hostname();
+		if (hostname)
+			g_dhcp_client_set_send(ipv4ll_client,
+						G_DHCP_HOST_NAME, hostname);
+	}
+
+	g_dhcp_client_register_event(ipv4ll_client,
+			G_DHCP_CLIENT_EVENT_IPV4LL_LOST, ipv4ll_lost_cb, dhcp);
+
+	g_dhcp_client_register_event(ipv4ll_client,
+			G_DHCP_CLIENT_EVENT_IPV4LL_AVAILABLE,
+						ipv4ll_available_cb, dhcp);
+
+	dhcp->ipv4ll_client = ipv4ll_client;
+
+	err = g_dhcp_client_start(dhcp->ipv4ll_client, NULL);
+	if (err < 0) {
+		ipv4ll_stop_client(dhcp);
+		return err;
+	}
+
+	ipv4ll_running = true;
+	return 0;
+}
+
+static gboolean dhcp_retry_cb(gpointer user_data)
+{
+	struct connman_dhcp *dhcp = user_data;
+
+	dhcp->timeout = 0;
+
+	g_dhcp_client_start(dhcp->dhcp_client,
+			__connman_ipconfig_get_dhcp_address(dhcp->ipconfig));
+
+	return FALSE;
+}
+
+static void no_lease_cb(GDHCPClient *dhcp_client, gpointer user_data)
+{
+	struct connman_dhcp *dhcp = user_data;
+	int err;
+
+	DBG("No lease available ipv4ll %d client %p", ipv4ll_running,
+		dhcp->ipv4ll_client);
+
+	dhcp->timeout = g_timeout_add_seconds(RATE_LIMIT_INTERVAL,
+						dhcp_retry_cb,
+						dhcp);
+	if (ipv4ll_running)
+		return;
+
+	err = ipv4ll_start_client(dhcp);
+	if (err < 0)
+		DBG("Cannot start ipv4ll client (%d/%s)", err, strerror(-err));
+
+	/* Only notify upper layer if we have a problem */
+	dhcp_invalidate(dhcp, !ipv4ll_running);
+}
+
+static void lease_lost_cb(GDHCPClient *dhcp_client, gpointer user_data)
+{
+	struct connman_dhcp *dhcp = user_data;
+
+	DBG("Lease lost");
+
+	/* Upper layer will decide what to do, e.g. nothing or retry. */
+	dhcp_invalidate(dhcp, true);
+}
+
+static void ipv4ll_lost_cb(GDHCPClient *dhcp_client, gpointer user_data)
+{
+	struct connman_dhcp *dhcp = user_data;
+
+	DBG("Lease lost");
+
+	ipv4ll_stop_client(dhcp);
+
+	/*
+	 * Since we lost our IPv4LL configuration we might as notify
+	 * the upper layers.
+	 */
+	dhcp_invalidate(dhcp, true);
+}
+
+static void wake_event_cb(GDHCPClient *dhcp_client, gpointer user_data)
+{
+    struct connman_dhcp *dhcp = user_data;
+    time_t valid_until;
+    bool can_sleep;
+
+    can_sleep = g_dhcp_get_next_event(dhcp_client, &valid_until);
+    DBG("can_sleep: %d until: %lld", can_sleep, (long long)valid_until);
+
+    __connman_notifier_sleep_event(dhcp,can_sleep, valid_until);
+}
+
+static bool compare_string_arrays(char **array_a, char **array_b)
+{
+	int i;
+
+	if (!array_a || !array_b)
+		return false;
+
+	if (g_strv_length(array_a) != g_strv_length(array_b))
+		return false;
+
+	for (i = 0; array_a[i] &&
+			     array_b[i]; i++) {
+		if (g_strcmp0(array_a[i], array_b[i]) != 0)
+			return false;
+	}
+
+	return true;
+}
+
+static bool apply_lease_available_on_network(GDHCPClient *dhcp_client,
+						struct connman_dhcp *dhcp)
+{
+	char **nameservers, **timeservers, *pac = NULL;
+	struct connman_service *service;
+	GList *list, *option = NULL;
+	int ns_entries;
+	int i;
+
+	if (!dhcp->network)
+		return true;
+
+	service = connman_service_lookup_from_network(dhcp->network);
+	if (!service) {
+		connman_error("Can not lookup service");
+		return false;
+	}
+
+	option = g_dhcp_client_get_option(dhcp_client, 252);
+	if (option)
+		pac = g_strdup(option->data);
+
+	option = g_dhcp_client_get_option(dhcp_client, G_DHCP_DNS_SERVER);
+	ns_entries = g_list_length(option);
+	nameservers = g_try_new0(char *, ns_entries + 1);
+	if (nameservers) {
+		for (i = 0, list = option;list; list = list->next, i++)
+			nameservers[i] = g_strdup(list->data);
+		nameservers[ns_entries] = NULL;
+	}
+
+	option = g_dhcp_client_get_option(dhcp_client, G_DHCP_DOMAIN_NAME);
+	if (option)
+		__connman_service_set_domainname(service, option->data);
+
+	option = g_dhcp_client_get_option(dhcp_client, G_DHCP_HOST_NAME);
+	if (option)
+		__connman_service_set_hostname(service, option->data);
+
+	option = g_dhcp_client_get_option(dhcp_client, G_DHCP_NTP_SERVER);
+	ns_entries = g_list_length(option);
+	timeservers = g_try_new0(char *, ns_entries + 1);
+	if (timeservers) {
+		for (i = 0, list = option; list; list = list->next, i++)
+			timeservers[i] = g_strdup(list->data);
+		timeservers[ns_entries] = NULL;
+	}
+
+	if (!compare_string_arrays(nameservers, dhcp->nameservers)) {
+		if (dhcp->nameservers) {
+			for (i = 0; dhcp->nameservers[i]; i++) {
+				__connman_service_nameserver_remove(service,
+						dhcp->nameservers[i], false);
+			}
+			g_strfreev(dhcp->nameservers);
+		}
+
+		dhcp->nameservers = nameservers;
+
+		for (i = 0; dhcp->nameservers && dhcp->nameservers[i]; i++) {
+			__connman_service_nameserver_append(service,
+						dhcp->nameservers[i], false);
+		}
+	} else {
+		g_strfreev(nameservers);
+	}
+
+	if (!compare_string_arrays(timeservers, dhcp->timeservers)) {
+		if (dhcp->timeservers) {
+			for (i = 0; dhcp->timeservers[i]; i++) {
+				__connman_service_timeserver_remove(service,
+							dhcp->timeservers[i]);
+			}
+			g_strfreev(dhcp->timeservers);
+		}
+
+		dhcp->timeservers = timeservers;
+
+		for (i = 0; dhcp->timeservers && dhcp->timeservers[i]; i++) {
+			__connman_service_timeserver_append(service,
+							dhcp->timeservers[i]);
+		}
+	} else {
+		g_strfreev(timeservers);
+	}
+
+	if (g_strcmp0(pac, dhcp->pac) != 0) {
+		g_free(dhcp->pac);
+		dhcp->pac = pac;
+
+		__connman_ipconfig_set_proxy_autoconfig(dhcp->ipconfig,
+								dhcp->pac);
+	}
+
+	if (connman_setting_get_bool("Enable6to4"))
+		__connman_6to4_probe(service);
+
+	return true;
+}
+
+static void lease_available_cb(GDHCPClient *dhcp_client, gpointer user_data)
+{
+	struct connman_dhcp *dhcp = user_data;
+	GList *option = NULL;
+	char *address, *netmask = NULL, *gateway = NULL;
+	const char *c_address, *c_gateway;
+	unsigned char prefixlen, c_prefixlen;
+	bool ip_change;
+
+	DBG("Lease available");
+
+	if (dhcp->ipv4ll_client) {
+		ipv4ll_stop_client(dhcp);
+		dhcp_invalidate(dhcp, false);
+	}
+
+	c_address = __connman_ipconfig_get_local(dhcp->ipconfig);
+	c_gateway = __connman_ipconfig_get_gateway(dhcp->ipconfig);
+	c_prefixlen = __connman_ipconfig_get_prefixlen(dhcp->ipconfig);
+
+	address = g_dhcp_client_get_address(dhcp_client);
+
+	__connman_ipconfig_set_dhcp_address(dhcp->ipconfig, address);
+	DBG("last address %s", address);
+
+	option = g_dhcp_client_get_option(dhcp_client, G_DHCP_SUBNET);
+	if (option)
+		netmask = g_strdup(option->data);
+
+	option = g_dhcp_client_get_option(dhcp_client, G_DHCP_ROUTER);
+	if (option)
+		gateway = g_strdup(option->data);
+
+	prefixlen = connman_ipaddress_calc_netmask_len(netmask);
+	if (prefixlen == 255)
+		connman_warn("netmask: %s is invalid", netmask);
+
+	DBG("c_address %s", c_address);
+
+	if (g_strcmp0(address, c_address))
+		ip_change = true;
+	else if (g_strcmp0(gateway, c_gateway))
+		ip_change = true;
+	else if (prefixlen != c_prefixlen)
+		ip_change = true;
+	else
+		ip_change = false;
+
+	__connman_ipconfig_set_method(dhcp->ipconfig,
+						CONNMAN_IPCONFIG_METHOD_DHCP);
+	if (ip_change) {
+		__connman_ipconfig_set_local(dhcp->ipconfig, address);
+		__connman_ipconfig_set_prefixlen(dhcp->ipconfig, prefixlen);
+		__connman_ipconfig_set_gateway(dhcp->ipconfig, gateway);
+	}
+
+	if (!apply_lease_available_on_network(dhcp_client, dhcp))
+		return;
+
+	if (ip_change)
+		dhcp_valid(dhcp);
+
+	g_free(address);
+	g_free(netmask);
+	g_free(gateway);
+}
+
+static void ipv4ll_available_cb(GDHCPClient *ipv4ll_client, gpointer user_data)
+{
+	struct connman_dhcp *dhcp = user_data;
+	char *address, *netmask;
+	unsigned char prefixlen;
+
+	DBG("IPV4LL available");
+
+	address = g_dhcp_client_get_address(ipv4ll_client);
+	netmask = g_dhcp_client_get_netmask(ipv4ll_client);
+
+	prefixlen = connman_ipaddress_calc_netmask_len(netmask);
+
+	__connman_ipconfig_set_method(dhcp->ipconfig,
+						CONNMAN_IPCONFIG_METHOD_DHCP);
+	__connman_ipconfig_set_local(dhcp->ipconfig, address);
+	__connman_ipconfig_set_prefixlen(dhcp->ipconfig, prefixlen);
+	__connman_ipconfig_set_gateway(dhcp->ipconfig, NULL);
+
+	dhcp_valid(dhcp);
+
+	g_free(address);
+	g_free(netmask);
+}
+
+static int dhcp_initialize(struct connman_dhcp *dhcp)
+{
+	GDHCPClient *dhcp_client;
+	GDHCPClientError error;
+	int index;
+
+	DBG("dhcp %p", dhcp);
+
+	index = __connman_ipconfig_get_index(dhcp->ipconfig);
+
+	dhcp_client = g_dhcp_client_new(G_DHCP_IPV4, index, &error);
+	if (error != G_DHCP_CLIENT_ERROR_NONE)
+		return -EINVAL;
+
+	if (getenv("CONNMAN_DHCP_DEBUG")) {
+		dhcp->dhcp_debug_prefix = g_strdup_printf("DHCP index %d",
+							index);
+		g_dhcp_client_set_debug(dhcp_client, dhcp_debug,
+					dhcp->dhcp_debug_prefix);
+	}
+
+	g_dhcp_client_set_id(dhcp_client);
+
+	if (dhcp->network) {
+		struct connman_service *service;
+		const char *hostname;
+
+		service = connman_service_lookup_from_network(dhcp->network);
+
+		hostname = __connman_service_get_hostname(service);
+		if (!hostname)
+			hostname = connman_utsname_get_hostname();
+
+		if (hostname)
+			g_dhcp_client_set_send(dhcp_client,
+						G_DHCP_HOST_NAME, hostname);
+
+		g_dhcp_client_set_request(dhcp_client, G_DHCP_HOST_NAME);
+		g_dhcp_client_set_request(dhcp_client, G_DHCP_DNS_SERVER);
+		g_dhcp_client_set_request(dhcp_client, G_DHCP_DOMAIN_NAME);
+		g_dhcp_client_set_request(dhcp_client, G_DHCP_NTP_SERVER);
+		g_dhcp_client_set_request(dhcp_client, 252);
+	}
+
+	g_dhcp_client_set_request(dhcp_client, G_DHCP_SUBNET);
+	g_dhcp_client_set_request(dhcp_client, G_DHCP_ROUTER);
+
+	g_dhcp_client_register_event(dhcp_client,
+			G_DHCP_CLIENT_EVENT_LEASE_AVAILABLE,
+						lease_available_cb, dhcp);
+
+	g_dhcp_client_register_event(dhcp_client,
+			G_DHCP_CLIENT_EVENT_WAKE_EVENT,
+					    wake_event_cb, dhcp);
+
+	g_dhcp_client_register_event(dhcp_client,
+			G_DHCP_CLIENT_EVENT_LEASE_LOST, lease_lost_cb, dhcp);
+
+	g_dhcp_client_register_event(dhcp_client,
+			G_DHCP_CLIENT_EVENT_NO_LEASE, no_lease_cb, dhcp);
+
+	dhcp->dhcp_client = dhcp_client;
+
+	return 0;
+}
+
+static int dhcp_release(struct connman_dhcp *dhcp)
+{
+	DBG("dhcp %p", dhcp);
+
+	if (dhcp == NULL)
+		return -EINVAL;
+
+	if (dhcp->timeout > 0) {
+		g_source_remove(dhcp->timeout);
+		dhcp->timeout = 0;
+	}
+
+	if (dhcp->dhcp_client) {
+		g_dhcp_client_stop(dhcp->dhcp_client);
+		g_dhcp_client_unref(dhcp->dhcp_client);
+	}
+
+	dhcp->dhcp_client = NULL;
+
+	g_free(dhcp->dhcp_debug_prefix);
+	dhcp->dhcp_debug_prefix = NULL;
+
+	ipv4ll_stop_client(dhcp);
+
+	return 0;
+}
+
+char *__connman_dhcp_get_server_address(struct connman_ipconfig *ipconfig)
+{
+	struct connman_dhcp *dhcp;
+
+	dhcp = g_hash_table_lookup(ipconfig_table, ipconfig);
+	if (!dhcp)
+		return NULL;
+
+	return g_dhcp_client_get_server_address(dhcp->dhcp_client);
+}
+
+int __connman_dhcp_start(struct connman_ipconfig *ipconfig,
+			struct connman_network *network, dhcp_cb callback,
+			gpointer user_data)
+{
+	const char *last_addr = NULL;
+	struct connman_dhcp *dhcp;
+	int err;
+
+	DBG("");
+
+	if (network) {
+		struct connman_service *service;
+
+		service = connman_service_lookup_from_network(network);
+		if (!service)
+			return -EINVAL;
+	}
+
+	last_addr = __connman_ipconfig_get_dhcp_address(ipconfig);
+
+	dhcp = g_hash_table_lookup(ipconfig_table, ipconfig);
+	if (!dhcp) {
+
+		dhcp = g_try_new0(struct connman_dhcp, 1);
+		if (!dhcp)
+			return -ENOMEM;
+
+		dhcp->ipconfig = ipconfig;
+		__connman_ipconfig_ref(ipconfig);
+
+		if (network) {
+			dhcp->network = network;
+			connman_network_ref(network);
+		}
+
+		err = dhcp_initialize(dhcp);
+
+		if (err < 0) {
+			if (network)
+				connman_network_unref(network);
+			g_free(dhcp);
+			return err;
+		}
+
+		g_hash_table_insert(ipconfig_table, ipconfig, dhcp);
+	}
+
+	dhcp->callback = callback;
+	dhcp->user_data = user_data;
+
+	return g_dhcp_client_start(dhcp->dhcp_client, last_addr);
+}
+
+void __connman_dhcp_stop(struct connman_ipconfig *ipconfig)
+{
+	struct connman_dhcp *dhcp;
+
+	DBG("ipconfig_table %p ipconfig %p", ipconfig_table, ipconfig);
+
+	if (!ipconfig_table)
+		return;
+
+	dhcp = g_hash_table_lookup(ipconfig_table, ipconfig);
+	if (dhcp) {
+		g_hash_table_remove(ipconfig_table, ipconfig);
+		__connman_ipconfig_unref(ipconfig);
+		if (dhcp->network)
+			connman_network_unref(dhcp->network);
+		dhcp_release(dhcp);
+		dhcp_invalidate(dhcp, false);
+		dhcp_free(dhcp);
+	}
+}
+
+int __connman_dhcp_init(void)
+{
+	DBG("");
+
+	ipconfig_table = g_hash_table_new_full(g_direct_hash, g_direct_equal,
+								NULL, NULL);
+
+	return 0;
+}
+
+void __connman_dhcp_cleanup(void)
+{
+	DBG("");
+
+	g_hash_table_destroy(ipconfig_table);
+	ipconfig_table = NULL;
+
+	dhcp_cleanup_random();
+}
diff --git a/connman/src/dhcpv6.c b/connman/src/dhcpv6.c
new file mode 100644
index 0000000..db9feb6
--- /dev/null
+++ b/connman/src/dhcpv6.c
@@ -0,0 +1,2684 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2012-2013  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 <stdio.h>
+#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
+#include <net/if.h>
+
+#include <connman/ipconfig.h>
+#include <connman/storage.h>
+
+#include <gdhcp/gdhcp.h>
+
+#include <glib.h>
+
+#include "connman.h"
+
+/* Transmission params in msec, RFC 3315 chapter 5.5 */
+#define INF_MAX_DELAY	(1 * 1000)
+#define INF_TIMEOUT	(1 * 1000)
+#define INF_MAX_RT	(120 * 1000)
+#define SOL_MAX_DELAY   (1 * 1000)
+#define SOL_TIMEOUT     (1 * 1000)
+#define SOL_MAX_RT      (120 * 1000)
+#define REQ_TIMEOUT	(1 * 1000)
+#define REQ_MAX_RT	(30 * 1000)
+#define REQ_MAX_RC	10
+#define REN_TIMEOUT     (10 * 1000)
+#define REN_MAX_RT      (600 * 1000)
+#define REB_TIMEOUT     (10 * 1000)
+#define REB_MAX_RT      (600 * 1000)
+#define CNF_MAX_DELAY   (1 * 1000)
+#define CNF_TIMEOUT	(1 * 1000)
+#define CNF_MAX_RT	(4 * 1000)
+#define CNF_MAX_RD	(10 * 1000)
+#define DEC_TIMEOUT     (1 * 1000)
+#define DEC_MAX_RC      5
+
+enum request_type {
+	REQ_REQUEST = 1,
+	REQ_REBIND = 2,
+	REQ_RENEW = 3,
+};
+
+struct connman_dhcpv6 {
+	struct connman_network *network;
+	dhcpv6_cb callback;
+
+	char **nameservers;
+	char **timeservers;
+
+	GDHCPClient *dhcp_client;
+
+	guint timeout;		/* operation timeout in msec */
+	guint MRD;		/* max operation timeout in msec */
+	guint RT;		/* in msec */
+	bool use_ta;		/* set to TRUE if IPv6 privacy is enabled */
+	GSList *prefixes;	/* network prefixes from radvd or dhcpv6 pd */
+	int request_count;	/* how many times REQUEST have been sent */
+	bool stateless;		/* TRUE if stateless DHCPv6 is used */
+	bool started;		/* TRUE if we have DHCPv6 started */
+};
+
+static GHashTable *network_table;
+static GHashTable *network_pd_table;
+
+static int dhcpv6_request(struct connman_dhcpv6 *dhcp, bool add_addresses);
+static int dhcpv6_pd_request(struct connman_dhcpv6 *dhcp);
+static gboolean start_solicitation(gpointer user_data);
+static int dhcpv6_renew(struct connman_dhcpv6 *dhcp);
+static int dhcpv6_rebind(struct connman_dhcpv6 *dhcp);
+
+static void clear_timer(struct connman_dhcpv6 *dhcp)
+{
+	if (dhcp->timeout > 0) {
+		g_source_remove(dhcp->timeout);
+		dhcp->timeout = 0;
+	}
+
+	if (dhcp->MRD > 0) {
+		g_source_remove(dhcp->MRD);
+		dhcp->MRD = 0;
+	}
+}
+
+static inline guint get_random(void)
+{
+	uint64_t val;
+
+	__connman_util_get_random(&val);
+
+	/* Make sure the value is always positive so strip MSB */
+	return ((uint32_t)val) >> 1;
+}
+
+static guint compute_random(guint val)
+{
+	return val - val / 10 +
+		(get_random() % (2 * 1000)) * val / 10 / 1000;
+}
+
+/* Calculate a random delay, RFC 3315 chapter 14 */
+/* RT and MRT are milliseconds */
+static guint calc_delay(guint RT, guint MRT)
+{
+	if (MRT && (RT > MRT / 2))
+		RT = compute_random(MRT);
+	else
+		RT += compute_random(RT);
+
+	return RT;
+}
+
+static guint initial_rt(guint timeout)
+{
+	return compute_random(timeout);
+}
+
+static void free_prefix(gpointer data)
+{
+	g_free(data);
+}
+
+static void dhcpv6_free(struct connman_dhcpv6 *dhcp)
+{
+	g_strfreev(dhcp->nameservers);
+	g_strfreev(dhcp->timeservers);
+
+	dhcp->nameservers = NULL;
+	dhcp->timeservers = NULL;
+	dhcp->started = false;
+
+	g_slist_free_full(dhcp->prefixes, free_prefix);
+}
+
+static bool compare_string_arrays(char **array_a, char **array_b)
+{
+	int i;
+
+	if (!array_a || !array_b)
+		return false;
+
+	if (g_strv_length(array_a) != g_strv_length(array_b))
+		return false;
+
+	for (i = 0; array_a[i] && array_b[i]; i++)
+		if (g_strcmp0(array_a[i], array_b[i]) != 0)
+			return false;
+
+	return true;
+}
+
+static void dhcpv6_debug(const char *str, void *data)
+{
+	connman_info("%s: %s\n", (const char *) data, str);
+}
+
+static gchar *convert_to_hex(unsigned char *buf, int len)
+{
+	gchar *ret = g_try_malloc(len * 2 + 1);
+	int i;
+
+	for (i = 0; ret && i < len; i++)
+		g_snprintf(ret + i * 2, 3, "%02x", buf[i]);
+
+	return ret;
+}
+
+/*
+ * DUID should not change over time so save it to file.
+ * See RFC 3315 chapter 9 for details.
+ */
+static int set_duid(struct connman_service *service,
+			struct connman_network *network,
+			GDHCPClient *dhcp_client, int index)
+{
+	GKeyFile *keyfile;
+	const char *ident;
+	char *hex_duid;
+	unsigned char *duid;
+	int duid_len;
+
+	ident = __connman_service_get_ident(service);
+
+	keyfile = connman_storage_load_service(ident);
+	if (!keyfile)
+		return -EINVAL;
+
+	hex_duid = g_key_file_get_string(keyfile, ident, "IPv6.DHCP.DUID",
+					NULL);
+	if (hex_duid) {
+		unsigned int i, j = 0, hex;
+		size_t hex_duid_len = strlen(hex_duid);
+
+		duid = g_try_malloc0(hex_duid_len / 2);
+		if (!duid) {
+			g_key_file_free(keyfile);
+			g_free(hex_duid);
+			return -ENOMEM;
+		}
+
+		for (i = 0; i < hex_duid_len; i += 2) {
+			sscanf(hex_duid + i, "%02x", &hex);
+			duid[j++] = hex;
+		}
+
+		duid_len = hex_duid_len / 2;
+	} else {
+		int ret;
+		int type = __connman_ipconfig_get_type_from_index(index);
+
+		ret = g_dhcpv6_create_duid(G_DHCPV6_DUID_LLT, index, type,
+					&duid, &duid_len);
+		if (ret < 0) {
+			g_key_file_free(keyfile);
+			return ret;
+		}
+
+		hex_duid = convert_to_hex(duid, duid_len);
+		if (!hex_duid) {
+			g_key_file_free(keyfile);
+			return -ENOMEM;
+		}
+
+		g_key_file_set_string(keyfile, ident, "IPv6.DHCP.DUID",
+				hex_duid);
+
+		__connman_storage_save_service(keyfile, ident);
+	}
+	g_free(hex_duid);
+
+	g_key_file_free(keyfile);
+
+	g_dhcpv6_client_set_duid(dhcp_client, duid, duid_len);
+
+	return 0;
+}
+
+static void clear_callbacks(GDHCPClient *dhcp_client)
+{
+	g_dhcp_client_register_event(dhcp_client,
+				G_DHCP_CLIENT_EVENT_SOLICITATION,
+				NULL, NULL);
+
+	g_dhcp_client_register_event(dhcp_client,
+				G_DHCP_CLIENT_EVENT_ADVERTISE,
+				NULL, NULL);
+
+	g_dhcp_client_register_event(dhcp_client,
+				G_DHCP_CLIENT_EVENT_REQUEST,
+				NULL, NULL);
+
+	g_dhcp_client_register_event(dhcp_client,
+				G_DHCP_CLIENT_EVENT_CONFIRM,
+				NULL, NULL);
+
+	g_dhcp_client_register_event(dhcp_client,
+				G_DHCP_CLIENT_EVENT_RENEW,
+				NULL, NULL);
+
+	g_dhcp_client_register_event(dhcp_client,
+				G_DHCP_CLIENT_EVENT_REBIND,
+				NULL, NULL);
+
+	g_dhcp_client_register_event(dhcp_client,
+				G_DHCP_CLIENT_EVENT_RELEASE,
+				NULL, NULL);
+
+	g_dhcp_client_register_event(dhcp_client,
+				G_DHCP_CLIENT_EVENT_DECLINE,
+				NULL, NULL);
+
+	g_dhcp_client_register_event(dhcp_client,
+				G_DHCP_CLIENT_EVENT_INFORMATION_REQ,
+				NULL, NULL);
+}
+
+static void info_req_cb(GDHCPClient *dhcp_client, gpointer user_data)
+{
+	struct connman_dhcpv6 *dhcp = user_data;
+	struct connman_service *service;
+	int entries, i;
+	GList *option, *list;
+	char **nameservers, **timeservers;
+
+	DBG("dhcpv6 information-request %p", dhcp);
+
+	service = connman_service_lookup_from_network(dhcp->network);
+	if (!service) {
+		connman_error("Can not lookup service");
+		return;
+	}
+
+	g_dhcpv6_client_clear_retransmit(dhcp_client);
+
+	option = g_dhcp_client_get_option(dhcp_client, G_DHCPV6_DNS_SERVERS);
+	entries = g_list_length(option);
+
+	nameservers = g_try_new0(char *, entries + 1);
+	if (nameservers) {
+		for (i = 0, list = option; list; list = list->next, i++)
+			nameservers[i] = g_strdup(list->data);
+	}
+
+	if (!compare_string_arrays(nameservers, dhcp->nameservers)) {
+		if (dhcp->nameservers) {
+			for (i = 0; dhcp->nameservers[i]; i++)
+				__connman_service_nameserver_remove(service,
+							dhcp->nameservers[i],
+							false);
+			g_strfreev(dhcp->nameservers);
+		}
+
+		dhcp->nameservers = nameservers;
+
+		for (i = 0; dhcp->nameservers &&
+					dhcp->nameservers[i]; i++)
+			__connman_service_nameserver_append(service,
+						dhcp->nameservers[i],
+						false);
+	} else
+		g_strfreev(nameservers);
+
+
+	option = g_dhcp_client_get_option(dhcp_client, G_DHCPV6_SNTP_SERVERS);
+	entries = g_list_length(option);
+
+	timeservers = g_try_new0(char *, entries + 1);
+	if (timeservers) {
+		for (i = 0, list = option; list; list = list->next, i++)
+			timeservers[i] = g_strdup(list->data);
+	}
+
+	if (!compare_string_arrays(timeservers, dhcp->timeservers)) {
+		if (dhcp->timeservers) {
+			for (i = 0; dhcp->timeservers[i]; i++)
+				__connman_service_timeserver_remove(service,
+							dhcp->timeservers[i]);
+			g_strfreev(dhcp->timeservers);
+		}
+
+		dhcp->timeservers = timeservers;
+
+		for (i = 0; dhcp->timeservers &&
+					dhcp->timeservers[i]; i++)
+			__connman_service_timeserver_append(service,
+							dhcp->timeservers[i]);
+	} else
+		g_strfreev(timeservers);
+
+
+	if (dhcp->callback) {
+		uint16_t status = g_dhcpv6_client_get_status(dhcp_client);
+		dhcp->callback(dhcp->network, status == 0 ?
+						CONNMAN_DHCPV6_STATUS_SUCCEED :
+						CONNMAN_DHCPV6_STATUS_FAIL,
+				NULL);
+	}
+}
+
+static int dhcpv6_info_request(struct connman_dhcpv6 *dhcp)
+{
+	struct connman_service *service;
+	GDHCPClient *dhcp_client;
+	GDHCPClientError error;
+	int index, ret;
+
+	DBG("dhcp %p", dhcp);
+
+	index = connman_network_get_index(dhcp->network);
+
+	dhcp_client = g_dhcp_client_new(G_DHCP_IPV6, index, &error);
+	if (error != G_DHCP_CLIENT_ERROR_NONE) {
+		clear_timer(dhcp);
+		return -EINVAL;
+	}
+
+	if (getenv("CONNMAN_DHCPV6_DEBUG"))
+		g_dhcp_client_set_debug(dhcp_client, dhcpv6_debug, "DHCPv6");
+
+	service = connman_service_lookup_from_network(dhcp->network);
+	if (!service) {
+		clear_timer(dhcp);
+		g_dhcp_client_unref(dhcp_client);
+		return -EINVAL;
+	}
+
+	ret = set_duid(service, dhcp->network, dhcp_client, index);
+	if (ret < 0) {
+		clear_timer(dhcp);
+		g_dhcp_client_unref(dhcp_client);
+		return ret;
+	}
+
+	g_dhcp_client_set_request(dhcp_client, G_DHCPV6_CLIENTID);
+	g_dhcp_client_set_request(dhcp_client, G_DHCPV6_DNS_SERVERS);
+	g_dhcp_client_set_request(dhcp_client, G_DHCPV6_DOMAIN_LIST);
+	g_dhcp_client_set_request(dhcp_client, G_DHCPV6_SNTP_SERVERS);
+
+	g_dhcpv6_client_set_oro(dhcp_client, 3, G_DHCPV6_DNS_SERVERS,
+				G_DHCPV6_DOMAIN_LIST, G_DHCPV6_SNTP_SERVERS);
+
+	g_dhcp_client_register_event(dhcp_client,
+			G_DHCP_CLIENT_EVENT_INFORMATION_REQ, info_req_cb, dhcp);
+
+	dhcp->dhcp_client = dhcp_client;
+
+	return g_dhcp_client_start(dhcp_client, NULL);
+}
+
+static int check_ipv6_addr_prefix(GSList *prefixes, char *address)
+{
+	struct in6_addr addr_prefix, addr;
+	GSList *list;
+	int ret = 128, len;
+
+	for (list = prefixes; list; list = list->next) {
+		char *prefix = list->data;
+		const char *slash = g_strrstr(prefix, "/");
+		const unsigned char bits[] = { 0x00, 0xFE, 0xFC, 0xF8,
+						0xF0, 0xE0, 0xC0, 0x80 };
+		int left, count, i, plen;
+
+		if (!slash)
+			continue;
+
+		prefix = g_strndup(prefix, slash - prefix);
+		len = strtol(slash + 1, NULL, 10);
+		if (len < 3 || len > 128)
+			break;
+
+		plen = 128 - len;
+
+		count = plen / 8;
+		left = plen % 8;
+		i = 16 - count;
+
+		inet_pton(AF_INET6, prefix, &addr_prefix);
+		inet_pton(AF_INET6, address, &addr);
+
+		memset(&addr_prefix.s6_addr[i], 0, count);
+		memset(&addr.s6_addr[i], 0, count);
+
+		if (left) {
+			addr_prefix.s6_addr[i - 1] &= bits[left];
+			addr.s6_addr[i - 1] &= bits[left];
+		}
+
+		g_free(prefix);
+
+		if (memcmp(&addr_prefix, &addr, 16) == 0) {
+			ret = len;
+			break;
+		}
+	}
+
+	return ret;
+}
+
+static int set_other_addresses(GDHCPClient *dhcp_client,
+						struct connman_dhcpv6 *dhcp)
+{
+	struct connman_service *service;
+	int entries, i;
+	GList *option, *list;
+	char **nameservers, **timeservers;
+
+	service = connman_service_lookup_from_network(dhcp->network);
+	if (!service) {
+		connman_error("Can not lookup service");
+		return -EINVAL;
+	}
+
+	/*
+	 * Check domains before nameservers so that the nameserver append
+	 * function will update domain list in service.c
+	 */
+	option = g_dhcp_client_get_option(dhcp_client, G_DHCPV6_DOMAIN_LIST);
+	entries = g_list_length(option);
+	if (entries > 0) {
+		char **domains = g_try_new0(char *, entries + 1);
+		if (domains) {
+			for (i = 0, list = option; list;
+						list = list->next, i++)
+				domains[i] = g_strdup(list->data);
+			__connman_service_set_search_domains(service, domains);
+			g_strfreev(domains);
+		}
+	}
+
+	option = g_dhcp_client_get_option(dhcp_client, G_DHCPV6_DNS_SERVERS);
+	entries = g_list_length(option);
+
+	nameservers = g_try_new0(char *, entries + 1);
+	if (nameservers) {
+		for (i = 0, list = option; list; list = list->next, i++)
+			nameservers[i] = g_strdup(list->data);
+	}
+
+	if (!compare_string_arrays(nameservers, dhcp->nameservers)) {
+		if (dhcp->nameservers) {
+			for (i = 0; dhcp->nameservers[i]; i++)
+				__connman_service_nameserver_remove(service,
+							dhcp->nameservers[i],
+							false);
+			g_strfreev(dhcp->nameservers);
+		}
+
+		dhcp->nameservers = nameservers;
+
+		for (i = 0; dhcp->nameservers &&
+					dhcp->nameservers[i]; i++)
+			__connman_service_nameserver_append(service,
+							dhcp->nameservers[i],
+							false);
+	} else
+		g_strfreev(nameservers);
+
+
+	option = g_dhcp_client_get_option(dhcp_client, G_DHCPV6_SNTP_SERVERS);
+	entries = g_list_length(option);
+
+	timeservers = g_try_new0(char *, entries + 1);
+	if (timeservers) {
+		for (i = 0, list = option; list; list = list->next, i++)
+			timeservers[i] = g_strdup(list->data);
+	}
+
+	if (!compare_string_arrays(timeservers, dhcp->timeservers)) {
+		if (dhcp->timeservers) {
+			for (i = 0; dhcp->timeservers[i]; i++)
+				__connman_service_timeserver_remove(service,
+							dhcp->timeservers[i]);
+			g_strfreev(dhcp->timeservers);
+		}
+
+		dhcp->timeservers = timeservers;
+
+		for (i = 0; dhcp->timeservers &&
+					dhcp->timeservers[i]; i++)
+			__connman_service_timeserver_append(service,
+							dhcp->timeservers[i]);
+	} else
+		g_strfreev(timeservers);
+
+	return 0;
+}
+
+static GSList *copy_prefixes(GSList *prefixes)
+{
+	GSList *list, *copy = NULL;
+
+	for (list = prefixes; list; list = list->next)
+		copy = g_slist_prepend(copy, g_strdup(list->data));
+
+	return copy;
+}
+
+/*
+ * Helper struct for doing DAD (duplicate address detection).
+ * It is refcounted and freed after all reply's to neighbor
+ * discovery request are received.
+ */
+struct own_address {
+	int refcount;
+
+	int ifindex;
+	GDHCPClient *dhcp_client;
+	struct connman_ipconfig *ipconfig;
+	GSList *prefixes;
+	dhcpv6_cb callback;
+
+	GSList *dad_failed;
+	GSList *dad_succeed;
+};
+
+static void free_own_address(struct own_address *data)
+{
+	g_dhcp_client_unref(data->dhcp_client);
+	__connman_ipconfig_unref(data->ipconfig);
+	g_slist_free_full(data->prefixes, free_prefix);
+	g_slist_free_full(data->dad_failed, g_free);
+	g_slist_free_full(data->dad_succeed, g_free);
+
+	g_free(data);
+}
+
+static struct own_address *ref_own_address(struct own_address *address)
+{
+	DBG("%p ref %d", address, address->refcount + 1);
+
+	__sync_fetch_and_add(&address->refcount, 1);
+
+	return address;
+}
+
+static void unref_own_address(struct own_address *address)
+{
+	if (!address)
+		return;
+
+	DBG("%p ref %d", address, address->refcount - 1);
+
+	if (__sync_fetch_and_sub(&address->refcount, 1) != 1)
+		return;
+
+	free_own_address(address);
+}
+
+static void set_address(int ifindex, struct connman_ipconfig *ipconfig,
+			GSList *prefixes, char *address)
+{
+	const char *c_address;
+
+	c_address = __connman_ipconfig_get_local(ipconfig);
+
+	if (address && ((c_address && g_strcmp0(address, c_address) != 0) ||
+								!c_address)) {
+		int prefix_len;
+
+		/* Is this prefix part of the subnet we are suppose to use? */
+		prefix_len = check_ipv6_addr_prefix(prefixes, address);
+
+		__connman_ipconfig_address_remove(ipconfig);
+		__connman_ipconfig_set_local(ipconfig, address);
+		__connman_ipconfig_set_prefixlen(ipconfig, prefix_len);
+
+		DBG("new address %s/%d", address, prefix_len);
+
+		__connman_ipconfig_set_dhcp_address(ipconfig, address);
+		__connman_service_save(
+			__connman_service_lookup_from_index(ifindex));
+	}
+}
+
+
+/*
+ * Helper struct that is used when waiting a reply to DECLINE message.
+ */
+struct decline_cb_data {
+	GDHCPClient *dhcp_client;
+	dhcpv6_cb callback;
+	int ifindex;
+	guint timeout;
+};
+
+static void decline_reply_callback(struct decline_cb_data *data)
+{
+	struct connman_network *network;
+	struct connman_service *service;
+
+	service = __connman_service_lookup_from_index(data->ifindex);
+	network = __connman_service_get_network(service);
+
+	if (data->callback)
+		data->callback(network, CONNMAN_DHCPV6_STATUS_RESTART, NULL);
+
+	g_dhcp_client_unref(data->dhcp_client);
+}
+
+static gboolean decline_timeout(gpointer user_data)
+{
+	struct decline_cb_data *data = user_data;
+
+	DBG("ifindex %d", data->ifindex);
+
+	/*
+	 * We ignore all DECLINE replies that are received after the timeout
+	 */
+	g_dhcp_client_register_event(data->dhcp_client,
+					G_DHCP_CLIENT_EVENT_DECLINE,
+					NULL, NULL);
+
+	decline_reply_callback(data);
+
+	g_free(data);
+
+	return FALSE;
+}
+
+static void decline_cb(GDHCPClient *dhcp_client, gpointer user_data)
+{
+	struct decline_cb_data *data = user_data;
+
+	DBG("ifindex %d", data->ifindex);
+
+	g_dhcpv6_client_clear_retransmit(dhcp_client);
+
+	if (data->timeout)
+		g_source_remove(data->timeout);
+
+	decline_reply_callback(data);
+
+	g_free(data);
+}
+
+static int dhcpv6_decline(GDHCPClient *dhcp_client, int ifindex,
+			dhcpv6_cb callback, GSList *failed)
+{
+	struct decline_cb_data *data;
+	GList *option;
+	int code;
+
+	DBG("dhcp_client %p", dhcp_client);
+
+	g_dhcp_client_clear_requests(dhcp_client);
+
+	g_dhcpv6_client_clear_send(dhcp_client, G_DHCPV6_ORO);
+
+	g_dhcp_client_set_request(dhcp_client, G_DHCPV6_CLIENTID);
+	g_dhcp_client_set_request(dhcp_client, G_DHCPV6_SERVERID);
+
+	option = g_dhcp_client_get_option(dhcp_client, G_DHCPV6_IA_NA);
+	if (!option) {
+		option = g_dhcp_client_get_option(dhcp_client, G_DHCPV6_IA_TA);
+		if (option)
+			code = G_DHCPV6_IA_TA;
+		else
+			return -EINVAL;
+	} else
+		code = G_DHCPV6_IA_NA;
+
+	g_dhcpv6_client_clear_send(dhcp_client, code);
+
+	g_dhcpv6_client_set_ias(dhcp_client, ifindex, code, NULL, NULL,
+				failed);
+
+	clear_callbacks(dhcp_client);
+
+	data = g_try_new(struct decline_cb_data, 1);
+	if (!data)
+		return -ENOMEM;
+
+	data->ifindex = ifindex;
+	data->callback = callback;
+	data->dhcp_client = g_dhcp_client_ref(dhcp_client);
+	data->timeout = g_timeout_add(DEC_TIMEOUT, decline_timeout, data);
+
+	g_dhcp_client_register_event(dhcp_client, G_DHCP_CLIENT_EVENT_DECLINE,
+				decline_cb, data);
+
+	return g_dhcp_client_start(dhcp_client, NULL);
+}
+
+static void dad_reply(struct nd_neighbor_advert *reply,
+		unsigned int length, struct in6_addr *addr, void *user_data)
+{
+	struct own_address *data = user_data;
+	GSList *list;
+	char address[INET6_ADDRSTRLEN];
+	enum __connman_dhcpv6_status status = CONNMAN_DHCPV6_STATUS_FAIL;
+
+	inet_ntop(AF_INET6, addr, address, INET6_ADDRSTRLEN);
+
+	DBG("user %p reply %p len %d address %s index %d data %p", user_data,
+		reply, length, address, data->ifindex, data);
+
+	if (!reply) {
+		if (length == 0)
+			DBG("DAD succeed for %s", address);
+		else
+			DBG("DAD cannot be done for %s", address);
+
+		data->dad_succeed = g_slist_prepend(data->dad_succeed,
+						g_strdup(address));
+
+	} else {
+		DBG("DAD failed for %s", address);
+
+		data->dad_failed = g_slist_prepend(data->dad_failed,
+						g_strdup(address));
+	}
+
+	/*
+	 * If refcount == 1 then we got the final reply and can continue.
+	 */
+	if (data->refcount > 1)
+		return;
+
+	for (list = data->dad_succeed; list; list = list->next)
+		set_address(data->ifindex, data->ipconfig, data->prefixes,
+								list->data);
+
+	if (data->dad_failed) {
+		dhcpv6_decline(data->dhcp_client, data->ifindex,
+			data->callback, data->dad_failed);
+	} else {
+		if (data->dad_succeed)
+			status = CONNMAN_DHCPV6_STATUS_SUCCEED;
+
+		if (data->callback) {
+			struct connman_network *network;
+			struct connman_service *service;
+
+			service = __connman_service_lookup_from_index(
+								data->ifindex);
+			network = __connman_service_get_network(service);
+			if (network)
+				data->callback(network, status, NULL);
+		}
+	}
+
+	unref_own_address(data);
+}
+
+/*
+ * Is the kernel configured to do DAD? If 0, then do not do DAD.
+ * See also RFC 4862 chapter 5.4 about DupAddrDetectTransmits
+ */
+static int dad_transmits(int ifindex)
+{
+	char name[IF_NAMESIZE];
+	gchar *path;
+	int value = 1;
+	FILE *f;
+
+	if (!if_indextoname(ifindex, name))
+		return value;
+
+	path = g_strdup_printf("/proc/sys/net/ipv6/conf/%s/dad_transmits",
+								name);
+
+	if (!path)
+		return value;
+
+	f = fopen(path, "r");
+
+	g_free(path);
+
+	if (f) {
+		if (fscanf(f, "%d", &value) < 0)
+			value = 1;
+
+		fclose(f);
+	}
+
+	return value;
+}
+
+static void do_dad(GDHCPClient *dhcp_client, struct connman_dhcpv6 *dhcp)
+{
+	struct connman_service *service;
+	struct connman_ipconfig *ipconfig;
+	int ifindex;
+	GList *option, *list;
+	struct own_address *user_data;
+
+	option = g_dhcp_client_get_option(dhcp_client, G_DHCPV6_IA_NA);
+	if (!option)
+		option = g_dhcp_client_get_option(dhcp_client, G_DHCPV6_IA_TA);
+
+	/*
+	 * Even if we didn't had any addresses, just try to set
+	 * the other options.
+	 */
+	set_other_addresses(dhcp_client, dhcp);
+
+	if (!option) {
+		DBG("Skip DAD as no addresses found in reply");
+		if (dhcp->callback)
+			dhcp->callback(dhcp->network,
+					CONNMAN_DHCPV6_STATUS_SUCCEED, NULL);
+
+		return;
+	}
+
+	ifindex = connman_network_get_index(dhcp->network);
+
+	DBG("index %d", ifindex);
+
+	service = connman_service_lookup_from_network(dhcp->network);
+	if (!service) {
+		connman_error("Can not lookup service for index %d", ifindex);
+		goto error;
+	}
+
+	ipconfig = __connman_service_get_ip6config(service);
+	if (!ipconfig) {
+		connman_error("Could not lookup ip6config for index %d",
+								ifindex);
+		goto error;
+	}
+
+	if (!dad_transmits(ifindex)) {
+		DBG("Skip DAD because of kernel configuration");
+
+		for (list = option; list; list = list->next)
+			set_address(ifindex, ipconfig, dhcp->prefixes,
+							option->data);
+
+		if (dhcp->callback)
+			dhcp->callback(dhcp->network,
+					CONNMAN_DHCPV6_STATUS_SUCCEED, NULL);
+
+		return;
+	}
+
+	if (g_list_length(option) == 0) {
+		DBG("No addresses when doing DAD");
+		if (dhcp->callback)
+			dhcp->callback(dhcp->network,
+					CONNMAN_DHCPV6_STATUS_SUCCEED, NULL);
+
+		return;
+	}
+
+	user_data = g_try_new0(struct own_address, 1);
+	if (!user_data)
+		goto error;
+
+	user_data->refcount = 0;
+	user_data->ifindex = ifindex;
+	user_data->dhcp_client = g_dhcp_client_ref(dhcp_client);
+	user_data->ipconfig = __connman_ipconfig_ref(ipconfig);
+	user_data->prefixes = copy_prefixes(dhcp->prefixes);
+	user_data->callback = dhcp->callback;
+
+	/*
+	 * We send one neighbor discovery request / address
+	 * and after all checks are done, then report the status
+	 * via dhcp callback.
+	 */
+
+	for (list = option; list; list = list->next) {
+		char *address = option->data;
+		struct in6_addr addr;
+		int ret;
+
+		ref_own_address(user_data);
+
+		if (inet_pton(AF_INET6, address, &addr) < 0) {
+			DBG("Invalid IPv6 address %s %d/%s", address,
+				-errno, strerror(errno));
+			goto fail;
+		}
+
+		DBG("user %p address %s client %p ipconfig %p prefixes %p",
+			user_data, address,
+			user_data->dhcp_client, user_data->ipconfig,
+			user_data->prefixes);
+
+		ret = __connman_inet_ipv6_do_dad(ifindex, 1000,
+						&addr,
+						dad_reply,
+						user_data);
+		if (ret < 0) {
+			DBG("Could not send neighbor solicitation for %s",
+								address);
+			dad_reply(NULL, -1, &addr, user_data);
+		} else {
+			DBG("Sent neighbor solicitation %d bytes", ret);
+		}
+	}
+
+	return;
+
+fail:
+	unref_own_address(user_data);
+
+error:
+	if (dhcp->callback)
+		dhcp->callback(dhcp->network, CONNMAN_DHCPV6_STATUS_FAIL,
+								NULL);
+}
+
+static gboolean timeout_request_resend(gpointer user_data)
+{
+	struct connman_dhcpv6 *dhcp = user_data;
+
+	if (dhcp->request_count >= REQ_MAX_RC) {
+		DBG("max request retry attempts %d", dhcp->request_count);
+		dhcp->request_count = 0;
+		if (dhcp->callback)
+			dhcp->callback(dhcp->network,
+					CONNMAN_DHCPV6_STATUS_FAIL, NULL);
+		return FALSE;
+	}
+
+	dhcp->request_count++;
+
+	dhcp->RT = calc_delay(dhcp->RT, REQ_MAX_RT);
+	DBG("request resend RT timeout %d msec", dhcp->RT);
+	dhcp->timeout = g_timeout_add(dhcp->RT, timeout_request_resend, dhcp);
+
+	g_dhcpv6_client_set_retransmit(dhcp->dhcp_client);
+
+	g_dhcp_client_start(dhcp->dhcp_client, NULL);
+
+	return FALSE;
+}
+
+static gboolean request_resend(gpointer user_data)
+{
+	struct connman_dhcpv6 *dhcp = user_data;
+
+	g_dhcpv6_client_set_retransmit(dhcp->dhcp_client);
+
+	dhcp->RT = calc_delay(dhcp->RT, REQ_MAX_RT);
+	DBG("request resend RT timeout %d msec", dhcp->RT);
+	dhcp->timeout = g_timeout_add(dhcp->RT, timeout_request_resend, dhcp);
+
+	dhcpv6_request(dhcp, true);
+
+	return FALSE;
+}
+
+static void do_resend_request(struct connman_dhcpv6 *dhcp)
+{
+	if (dhcp->request_count >= REQ_MAX_RC) {
+		DBG("max request retry attempts %d", dhcp->request_count);
+		dhcp->request_count = 0;
+		if (dhcp->callback)
+			dhcp->callback(dhcp->network,
+					CONNMAN_DHCPV6_STATUS_FAIL, NULL);
+		return;
+	}
+
+	dhcp->request_count++;
+
+	dhcp->RT = calc_delay(dhcp->RT, REQ_MAX_RT);
+	DBG("resending request after %d msec", dhcp->RT);
+	dhcp->timeout = g_timeout_add(dhcp->RT, request_resend, dhcp);
+}
+
+static void re_cb(enum request_type req_type, GDHCPClient *dhcp_client,
+		gpointer user_data)
+{
+	struct connman_dhcpv6 *dhcp = user_data;
+	uint16_t status;
+
+	clear_timer(dhcp);
+
+	status = g_dhcpv6_client_get_status(dhcp_client);
+
+	DBG("dhcpv6 cb msg %p status %d", dhcp, status);
+
+	/*
+	 * RFC 3315, 18.1.8 handle the resend if error
+	 */
+	if (status  == G_DHCPV6_ERROR_BINDING) {
+		dhcpv6_request(dhcp, false);
+	} else if (status  == G_DHCPV6_ERROR_MCAST) {
+		switch (req_type) {
+		case REQ_REQUEST:
+			dhcpv6_request(dhcp, true);
+			break;
+		case REQ_REBIND:
+			dhcpv6_rebind(dhcp);
+			break;
+		case REQ_RENEW:
+			dhcpv6_renew(dhcp);
+			break;
+		}
+	} else if (status  == G_DHCPV6_ERROR_LINK) {
+		if (req_type == REQ_REQUEST) {
+			g_dhcp_client_unref(dhcp->dhcp_client);
+			start_solicitation(dhcp);
+		} else {
+			if (dhcp->callback)
+				dhcp->callback(dhcp->network,
+					CONNMAN_DHCPV6_STATUS_FAIL, NULL);
+		}
+	} else if (status  == G_DHCPV6_ERROR_FAILURE) {
+		if (req_type == REQ_REQUEST) {
+			/* Rate limit the resend of request message */
+			do_resend_request(dhcp);
+		} else {
+			if (dhcp->callback)
+				dhcp->callback(dhcp->network,
+					CONNMAN_DHCPV6_STATUS_FAIL, NULL);
+		}
+	} else {
+
+		/*
+		 * If we did not got any addresses, then re-send
+		 * a request.
+		 */
+		GList *option;
+
+		option = g_dhcp_client_get_option(dhcp->dhcp_client,
+						G_DHCPV6_IA_NA);
+		if (!option) {
+			option = g_dhcp_client_get_option(dhcp->dhcp_client,
+							G_DHCPV6_IA_TA);
+			if (!option) {
+				switch (req_type) {
+				case REQ_REQUEST:
+					do_resend_request(dhcp);
+					break;
+				case REQ_REBIND:
+					dhcpv6_rebind(dhcp);
+					break;
+				case REQ_RENEW:
+					dhcpv6_renew(dhcp);
+					break;
+				}
+				return;
+			}
+		}
+
+		if (status == G_DHCPV6_ERROR_SUCCESS)
+			do_dad(dhcp_client, dhcp);
+		else if (dhcp->callback)
+			dhcp->callback(dhcp->network,
+				CONNMAN_DHCPV6_STATUS_FAIL, NULL);
+	}
+}
+
+static void rebind_cb(GDHCPClient *dhcp_client, gpointer user_data)
+{
+	DBG("");
+
+	g_dhcpv6_client_reset_request(dhcp_client);
+	g_dhcpv6_client_clear_retransmit(dhcp_client);
+
+	re_cb(REQ_REBIND, dhcp_client, user_data);
+}
+
+static int dhcpv6_rebind(struct connman_dhcpv6 *dhcp)
+{
+	GDHCPClient *dhcp_client;
+
+	DBG("dhcp %p", dhcp);
+
+	dhcp_client = dhcp->dhcp_client;
+
+	g_dhcp_client_clear_requests(dhcp_client);
+
+	g_dhcp_client_set_request(dhcp_client, G_DHCPV6_CLIENTID);
+	g_dhcp_client_set_request(dhcp_client, G_DHCPV6_DNS_SERVERS);
+	g_dhcp_client_set_request(dhcp_client, G_DHCPV6_DOMAIN_LIST);
+	g_dhcp_client_set_request(dhcp_client, G_DHCPV6_SNTP_SERVERS);
+
+	g_dhcpv6_client_set_oro(dhcp_client, 3, G_DHCPV6_DNS_SERVERS,
+				G_DHCPV6_DOMAIN_LIST, G_DHCPV6_SNTP_SERVERS);
+
+	g_dhcpv6_client_set_ia(dhcp_client,
+			connman_network_get_index(dhcp->network),
+			dhcp->use_ta ? G_DHCPV6_IA_TA : G_DHCPV6_IA_NA,
+			NULL, NULL, TRUE, NULL);
+
+	clear_callbacks(dhcp_client);
+
+	g_dhcp_client_register_event(dhcp_client, G_DHCP_CLIENT_EVENT_REBIND,
+					rebind_cb, dhcp);
+
+	dhcp->dhcp_client = dhcp_client;
+
+	return g_dhcp_client_start(dhcp_client, NULL);
+}
+
+static gboolean dhcpv6_restart(gpointer user_data)
+{
+	struct connman_dhcpv6 *dhcp = user_data;
+
+	if (dhcp->callback)
+		dhcp->callback(dhcp->network, CONNMAN_DHCPV6_STATUS_FAIL,
+								NULL);
+
+	return FALSE;
+}
+
+/*
+ * Check if we need to restart the solicitation procedure. This
+ * is done if all the addresses have expired. RFC 3315, 18.1.4
+ */
+static int check_restart(struct connman_dhcpv6 *dhcp)
+{
+	time_t current, expired;
+
+	g_dhcpv6_client_get_timeouts(dhcp->dhcp_client, NULL, NULL,
+				NULL, &expired);
+	current = time(NULL);
+
+	if (current >= expired) {
+		DBG("expired by %d secs", (int)(current - expired));
+
+		g_timeout_add(0, dhcpv6_restart, dhcp);
+
+		return -ETIMEDOUT;
+	}
+
+	return 0;
+}
+
+static gboolean timeout_rebind(gpointer user_data)
+{
+	struct connman_dhcpv6 *dhcp = user_data;
+
+	if (check_restart(dhcp) < 0)
+		return FALSE;
+
+	dhcp->RT = calc_delay(dhcp->RT, REB_MAX_RT);
+
+	DBG("rebind RT timeout %d msec", dhcp->RT);
+
+	dhcp->timeout = g_timeout_add(dhcp->RT, timeout_rebind, dhcp);
+
+	g_dhcpv6_client_set_retransmit(dhcp->dhcp_client);
+
+	g_dhcp_client_start(dhcp->dhcp_client, NULL);
+
+	return FALSE;
+}
+
+static gboolean start_rebind(gpointer user_data)
+{
+	struct connman_dhcpv6 *dhcp = user_data;
+
+	if (check_restart(dhcp) < 0)
+		return FALSE;
+
+	dhcp->RT = initial_rt(REB_TIMEOUT);
+
+	DBG("rebind initial RT timeout %d msec", dhcp->RT);
+
+	dhcp->timeout = g_timeout_add(dhcp->RT, timeout_rebind, dhcp);
+
+	dhcpv6_rebind(dhcp);
+
+	return FALSE;
+}
+
+static void request_cb(GDHCPClient *dhcp_client, gpointer user_data)
+{
+	DBG("");
+
+	g_dhcpv6_client_reset_request(dhcp_client);
+	g_dhcpv6_client_clear_retransmit(dhcp_client);
+
+	re_cb(REQ_REQUEST, dhcp_client, user_data);
+}
+
+static int dhcpv6_request(struct connman_dhcpv6 *dhcp,
+			bool add_addresses)
+{
+	GDHCPClient *dhcp_client;
+	uint32_t T1, T2;
+
+	DBG("dhcp %p add %d", dhcp, add_addresses);
+
+	dhcp_client = dhcp->dhcp_client;
+
+	g_dhcp_client_clear_requests(dhcp_client);
+
+	g_dhcp_client_set_request(dhcp_client, G_DHCPV6_CLIENTID);
+	g_dhcp_client_set_request(dhcp_client, G_DHCPV6_SERVERID);
+	g_dhcp_client_set_request(dhcp_client, G_DHCPV6_DNS_SERVERS);
+	g_dhcp_client_set_request(dhcp_client, G_DHCPV6_DOMAIN_LIST);
+	g_dhcp_client_set_request(dhcp_client, G_DHCPV6_SNTP_SERVERS);
+
+	g_dhcpv6_client_set_oro(dhcp_client, 3, G_DHCPV6_DNS_SERVERS,
+				G_DHCPV6_DOMAIN_LIST, G_DHCPV6_SNTP_SERVERS);
+
+	g_dhcpv6_client_get_timeouts(dhcp_client, &T1, &T2, NULL, NULL);
+	g_dhcpv6_client_set_ia(dhcp_client,
+			connman_network_get_index(dhcp->network),
+			dhcp->use_ta ? G_DHCPV6_IA_TA : G_DHCPV6_IA_NA,
+			&T1, &T2, add_addresses, NULL);
+
+	clear_callbacks(dhcp_client);
+
+	g_dhcp_client_register_event(dhcp_client, G_DHCP_CLIENT_EVENT_REQUEST,
+					request_cb, dhcp);
+
+	dhcp->dhcp_client = dhcp_client;
+
+	return g_dhcp_client_start(dhcp_client, NULL);
+}
+
+static gboolean timeout_request(gpointer user_data)
+{
+	struct connman_dhcpv6 *dhcp = user_data;
+
+	if (dhcp->request_count >= REQ_MAX_RC) {
+		DBG("max request retry attempts %d", dhcp->request_count);
+		dhcp->request_count = 0;
+		if (dhcp->callback)
+			dhcp->callback(dhcp->network,
+					CONNMAN_DHCPV6_STATUS_FAIL, NULL);
+		return FALSE;
+	}
+
+	dhcp->request_count++;
+
+	dhcp->RT = calc_delay(dhcp->RT, REQ_MAX_RT);
+	DBG("request RT timeout %d msec", dhcp->RT);
+	dhcp->timeout = g_timeout_add(dhcp->RT, timeout_request, dhcp);
+
+	g_dhcpv6_client_set_retransmit(dhcp->dhcp_client);
+
+	g_dhcp_client_start(dhcp->dhcp_client, NULL);
+
+	return FALSE;
+}
+
+static void renew_cb(GDHCPClient *dhcp_client, gpointer user_data)
+{
+	DBG("");
+
+	g_dhcpv6_client_reset_request(dhcp_client);
+	g_dhcpv6_client_clear_retransmit(dhcp_client);
+
+	re_cb(REQ_RENEW, dhcp_client, user_data);
+}
+
+static int dhcpv6_renew(struct connman_dhcpv6 *dhcp)
+{
+	GDHCPClient *dhcp_client;
+	uint32_t T1, T2;
+
+	DBG("dhcp %p", dhcp);
+
+	dhcp_client = dhcp->dhcp_client;
+
+	g_dhcp_client_clear_requests(dhcp_client);
+
+	g_dhcp_client_set_request(dhcp_client, G_DHCPV6_CLIENTID);
+	g_dhcp_client_set_request(dhcp_client, G_DHCPV6_SERVERID);
+	g_dhcp_client_set_request(dhcp_client, G_DHCPV6_DNS_SERVERS);
+	g_dhcp_client_set_request(dhcp_client, G_DHCPV6_DOMAIN_LIST);
+	g_dhcp_client_set_request(dhcp_client, G_DHCPV6_SNTP_SERVERS);
+
+	g_dhcpv6_client_set_oro(dhcp_client, 3, G_DHCPV6_DNS_SERVERS,
+				G_DHCPV6_DOMAIN_LIST, G_DHCPV6_SNTP_SERVERS);
+
+	g_dhcpv6_client_get_timeouts(dhcp_client, &T1, &T2, NULL, NULL);
+	g_dhcpv6_client_set_ia(dhcp_client,
+			connman_network_get_index(dhcp->network),
+			dhcp->use_ta ? G_DHCPV6_IA_TA : G_DHCPV6_IA_NA,
+			&T1, &T2, TRUE, NULL);
+
+	clear_callbacks(dhcp_client);
+
+	g_dhcp_client_register_event(dhcp_client, G_DHCP_CLIENT_EVENT_RENEW,
+					renew_cb, dhcp);
+
+	dhcp->dhcp_client = dhcp_client;
+
+	return g_dhcp_client_start(dhcp_client, NULL);
+}
+
+static gboolean timeout_renew(gpointer user_data)
+{
+	struct connman_dhcpv6 *dhcp = user_data;
+	time_t last_rebind, current;
+	uint32_t T2;
+
+	if (check_restart(dhcp) < 0)
+		return FALSE;
+
+	g_dhcpv6_client_get_timeouts(dhcp->dhcp_client, NULL, &T2,
+				&last_rebind, NULL);
+	current = time(NULL);
+	if ((unsigned)current >= (unsigned)last_rebind + T2) {
+		/*
+		 * Do rebind instead if past T2
+		 */
+		start_rebind(dhcp);
+		return FALSE;
+	}
+
+	dhcp->RT = calc_delay(dhcp->RT, REN_MAX_RT);
+
+	DBG("renew RT timeout %d msec", dhcp->RT);
+
+	dhcp->timeout = g_timeout_add(dhcp->RT, timeout_renew, dhcp);
+
+	g_dhcpv6_client_set_retransmit(dhcp->dhcp_client);
+
+	g_dhcp_client_start(dhcp->dhcp_client, NULL);
+
+	return FALSE;
+}
+
+static gboolean start_renew(gpointer user_data)
+{
+	struct connman_dhcpv6 *dhcp = user_data;
+
+	dhcp->RT = initial_rt(REN_TIMEOUT);
+
+	DBG("renew initial RT timeout %d msec", dhcp->RT);
+
+	dhcp->timeout = g_timeout_add(dhcp->RT, timeout_renew, dhcp);
+
+	dhcpv6_renew(dhcp);
+
+	return FALSE;
+}
+
+int __connman_dhcpv6_start_renew(struct connman_network *network,
+							dhcpv6_cb callback)
+{
+	struct connman_dhcpv6 *dhcp;
+	uint32_t T1, T2, delta;
+	time_t started, current, expired;
+
+	dhcp = g_hash_table_lookup(network_table, network);
+	if (!dhcp)
+		return -ENOENT;
+
+	DBG("network %p dhcp %p", network, dhcp);
+
+	clear_timer(dhcp);
+
+	g_dhcpv6_client_get_timeouts(dhcp->dhcp_client, &T1, &T2,
+				&started, &expired);
+
+	current = time(NULL);
+
+	DBG("T1 %u T2 %u expires %lu current %lu started %lu", T1, T2,
+		(unsigned long)expired, current, started);
+
+	if (T1 == 0xffffffff)
+		/* RFC 3315, 22.4 */
+		return 0;
+
+	if (T1 == 0) {
+		/* RFC 3315, 22.4
+		 * Client can choose the timeout.
+		 */
+		T1 = (expired - started) / 2;
+		T2 = (expired - started) / 10 * 8;
+	}
+
+	dhcp->callback = callback;
+
+	/* RFC 3315, 18.1.4, start solicit if expired */
+	if (check_restart(dhcp) < 0)
+		return 0;
+
+	if (T2 != 0xffffffff && T2 > 0) {
+		if ((unsigned)current >= (unsigned)started + T2) {
+			/* RFC 3315, chapter 18.1.3, start rebind */
+			DBG("start rebind immediately");
+
+			dhcp->timeout = g_timeout_add_seconds(0, start_rebind,
+							dhcp);
+
+		} else if ((unsigned)current < (unsigned)started + T1) {
+			delta = started + T1 - current;
+			DBG("renew after %d secs", delta);
+
+			dhcp->timeout = g_timeout_add_seconds(delta,
+					start_renew, dhcp);
+		} else {
+			delta = started + T2 - current;
+			DBG("rebind after %d secs", delta);
+
+			dhcp->timeout = g_timeout_add_seconds(delta,
+					start_rebind, dhcp);
+		}
+	}
+
+	return 0;
+}
+
+static void release_cb(GDHCPClient *dhcp_client, gpointer user_data)
+{
+	DBG("");
+}
+
+int __connman_dhcpv6_start_release(struct connman_network *network,
+				dhcpv6_cb callback)
+{
+	struct connman_dhcpv6 *dhcp;
+	GDHCPClient *dhcp_client;
+
+	if (!network_table)
+		return 0;   /* we are already released */
+
+	dhcp = g_hash_table_lookup(network_table, network);
+	if (!dhcp)
+		return -ENOENT;
+
+	DBG("network %p dhcp %p client %p stateless %d", network, dhcp,
+					dhcp->dhcp_client, dhcp->stateless);
+
+	if (dhcp->stateless)
+		return -EINVAL;
+
+	clear_timer(dhcp);
+
+	dhcp_client = dhcp->dhcp_client;
+	if (!dhcp_client) {
+		/*
+		 * We had started the DHCPv6 handshaking i.e., we have called
+		 * __connman_dhcpv6_start() but it has not yet sent
+		 * a solicitation message to server. This means that we do not
+		 * have DHCPv6 configured yet so we can just quit here.
+		 */
+		DBG("DHCPv6 was not started");
+		return 0;
+	}
+
+	g_dhcp_client_clear_requests(dhcp_client);
+	g_dhcp_client_clear_values(dhcp_client);
+
+	g_dhcp_client_set_request(dhcp_client, G_DHCPV6_CLIENTID);
+	g_dhcp_client_set_request(dhcp_client, G_DHCPV6_SERVERID);
+
+	g_dhcpv6_client_set_ia(dhcp_client,
+			connman_network_get_index(dhcp->network),
+			dhcp->use_ta ? G_DHCPV6_IA_TA : G_DHCPV6_IA_NA,
+			NULL, NULL, TRUE, NULL);
+
+	clear_callbacks(dhcp_client);
+
+	/*
+	 * Although we register a callback here we are really not interested in
+	 * the answer because it might take too long time and network code
+	 * might be in the middle of the disconnect.
+	 * So we just inform the server that we are done with the addresses
+	 * but ignore the reply from server. This is allowed by RFC 3315
+	 * chapter 18.1.6.
+	 */
+	g_dhcp_client_register_event(dhcp_client,
+				G_DHCP_CLIENT_EVENT_RELEASE,
+				release_cb, NULL);
+
+	dhcp->dhcp_client = dhcp_client;
+
+	return g_dhcp_client_start(dhcp_client, NULL);
+}
+
+static int dhcpv6_release(struct connman_dhcpv6 *dhcp)
+{
+	DBG("dhcp %p", dhcp);
+
+	clear_timer(dhcp);
+
+	dhcpv6_free(dhcp);
+
+	if (!dhcp->dhcp_client)
+		return 0;
+
+	g_dhcp_client_stop(dhcp->dhcp_client);
+	g_dhcp_client_unref(dhcp->dhcp_client);
+
+	dhcp->dhcp_client = NULL;
+
+	return 0;
+}
+
+static void remove_network(gpointer user_data)
+{
+	struct connman_dhcpv6 *dhcp = user_data;
+
+	DBG("dhcp %p", dhcp);
+
+	dhcpv6_release(dhcp);
+
+	g_free(dhcp);
+}
+
+static gboolean timeout_info_req(gpointer user_data)
+{
+	struct connman_dhcpv6 *dhcp = user_data;
+
+	dhcp->RT = calc_delay(dhcp->RT, INF_MAX_RT);
+
+	DBG("info RT timeout %d msec", dhcp->RT);
+
+	dhcp->timeout = g_timeout_add(dhcp->RT, timeout_info_req, dhcp);
+
+	g_dhcpv6_client_set_retransmit(dhcp->dhcp_client);
+
+	g_dhcp_client_start(dhcp->dhcp_client, NULL);
+
+	return FALSE;
+}
+
+static gboolean start_info_req(gpointer user_data)
+{
+	struct connman_dhcpv6 *dhcp = user_data;
+
+	/* Set the retransmission timeout, RFC 3315 chapter 14 */
+	dhcp->RT = initial_rt(INF_TIMEOUT);
+
+	DBG("info initial RT timeout %d msec", dhcp->RT);
+
+	dhcp->timeout = g_timeout_add(dhcp->RT, timeout_info_req, dhcp);
+
+	dhcpv6_info_request(dhcp);
+
+	return FALSE;
+}
+
+int __connman_dhcpv6_start_info(struct connman_network *network,
+				dhcpv6_cb callback)
+{
+	struct connman_dhcpv6 *dhcp;
+	int delay;
+	uint64_t rand;
+
+	DBG("");
+
+	if (network_table) {
+		dhcp = g_hash_table_lookup(network_table, network);
+		if (dhcp && dhcp->started)
+			return -EBUSY;
+	}
+
+	dhcp = g_try_new0(struct connman_dhcpv6, 1);
+	if (!dhcp)
+		return -ENOMEM;
+
+	dhcp->network = network;
+	dhcp->callback = callback;
+	dhcp->stateless = true;
+	dhcp->started = true;
+
+	connman_network_ref(network);
+
+	DBG("replace network %p dhcp %p", network, dhcp);
+
+	g_hash_table_replace(network_table, network, dhcp);
+
+	/* Initial timeout, RFC 3315, 18.1.5 */
+	__connman_util_get_random(&rand);
+	delay = rand % 1000;
+
+	dhcp->timeout = g_timeout_add(delay, start_info_req, dhcp);
+
+	return 0;
+}
+
+static void advertise_cb(GDHCPClient *dhcp_client, gpointer user_data)
+{
+	struct connman_dhcpv6 *dhcp = user_data;
+
+	DBG("dhcpv6 advertise msg %p", dhcp);
+
+	clear_timer(dhcp);
+
+	g_dhcpv6_client_clear_retransmit(dhcp_client);
+
+	if (g_dhcpv6_client_get_status(dhcp_client) != 0) {
+		if (dhcp->callback)
+			dhcp->callback(dhcp->network,
+					CONNMAN_DHCPV6_STATUS_FAIL, NULL);
+		return;
+	}
+
+	dhcp->RT = initial_rt(REQ_TIMEOUT);
+	DBG("request initial RT timeout %d msec", dhcp->RT);
+	dhcp->timeout = g_timeout_add(dhcp->RT, timeout_request, dhcp);
+
+	dhcp->request_count = 1;
+
+	dhcpv6_request(dhcp, true);
+}
+
+static void solicitation_cb(GDHCPClient *dhcp_client, gpointer user_data)
+{
+	/* We get here if server supports rapid commit */
+	struct connman_dhcpv6 *dhcp = user_data;
+
+	DBG("dhcpv6 solicitation msg %p", dhcp);
+
+	clear_timer(dhcp);
+
+	g_dhcpv6_client_clear_retransmit(dhcp_client);
+
+	if (g_dhcpv6_client_get_status(dhcp_client) != 0) {
+		if (dhcp->callback)
+			dhcp->callback(dhcp->network,
+					CONNMAN_DHCPV6_STATUS_FAIL, NULL);
+		return;
+	}
+
+	do_dad(dhcp_client, dhcp);
+}
+
+static gboolean timeout_solicitation(gpointer user_data)
+{
+	struct connman_dhcpv6 *dhcp = user_data;
+
+	dhcp->RT = calc_delay(dhcp->RT, SOL_MAX_RT);
+
+	DBG("solicit RT timeout %d msec", dhcp->RT);
+
+	dhcp->timeout = g_timeout_add(dhcp->RT, timeout_solicitation, dhcp);
+
+	g_dhcpv6_client_set_retransmit(dhcp->dhcp_client);
+
+	g_dhcp_client_start(dhcp->dhcp_client, NULL);
+
+	return FALSE;
+}
+
+static int dhcpv6_solicitation(struct connman_dhcpv6 *dhcp)
+{
+	struct connman_service *service;
+	struct connman_ipconfig *ipconfig_ipv6;
+	GDHCPClient *dhcp_client;
+	GDHCPClientError error;
+	int index, ret;
+
+	DBG("dhcp %p", dhcp);
+
+	index = connman_network_get_index(dhcp->network);
+
+	dhcp_client = g_dhcp_client_new(G_DHCP_IPV6, index, &error);
+	if (error != G_DHCP_CLIENT_ERROR_NONE) {
+		clear_timer(dhcp);
+		return -EINVAL;
+	}
+
+	if (getenv("CONNMAN_DHCPV6_DEBUG"))
+		g_dhcp_client_set_debug(dhcp_client, dhcpv6_debug, "DHCPv6");
+
+	service = connman_service_lookup_from_network(dhcp->network);
+	if (!service) {
+		clear_timer(dhcp);
+		g_dhcp_client_unref(dhcp_client);
+		return -EINVAL;
+	}
+
+	ret = set_duid(service, dhcp->network, dhcp_client, index);
+	if (ret < 0) {
+		clear_timer(dhcp);
+		g_dhcp_client_unref(dhcp_client);
+		return ret;
+	}
+
+	g_dhcp_client_set_request(dhcp_client, G_DHCPV6_CLIENTID);
+	g_dhcp_client_set_request(dhcp_client, G_DHCPV6_RAPID_COMMIT);
+	g_dhcp_client_set_request(dhcp_client, G_DHCPV6_DNS_SERVERS);
+	g_dhcp_client_set_request(dhcp_client, G_DHCPV6_DOMAIN_LIST);
+	g_dhcp_client_set_request(dhcp_client, G_DHCPV6_SNTP_SERVERS);
+
+	g_dhcpv6_client_set_oro(dhcp_client, 3, G_DHCPV6_DNS_SERVERS,
+				G_DHCPV6_DOMAIN_LIST, G_DHCPV6_SNTP_SERVERS);
+
+	ipconfig_ipv6 = __connman_service_get_ip6config(service);
+	dhcp->use_ta = __connman_ipconfig_ipv6_privacy_enabled(ipconfig_ipv6);
+
+	g_dhcpv6_client_set_ia(dhcp_client, index,
+			dhcp->use_ta ? G_DHCPV6_IA_TA : G_DHCPV6_IA_NA,
+			NULL, NULL, FALSE, NULL);
+
+	clear_callbacks(dhcp_client);
+
+	g_dhcp_client_register_event(dhcp_client,
+				G_DHCP_CLIENT_EVENT_SOLICITATION,
+				solicitation_cb, dhcp);
+
+	g_dhcp_client_register_event(dhcp_client,
+				G_DHCP_CLIENT_EVENT_ADVERTISE,
+				advertise_cb, dhcp);
+
+	dhcp->dhcp_client = dhcp_client;
+
+	return g_dhcp_client_start(dhcp_client, NULL);
+}
+
+static gboolean start_solicitation(gpointer user_data)
+{
+	struct connman_dhcpv6 *dhcp = user_data;
+
+	/* Set the retransmission timeout, RFC 3315 chapter 14 */
+	dhcp->RT = initial_rt(SOL_TIMEOUT);
+
+	DBG("solicit initial RT timeout %d msec", dhcp->RT);
+
+	dhcp->timeout = g_timeout_add(dhcp->RT, timeout_solicitation, dhcp);
+
+	dhcpv6_solicitation(dhcp);
+
+	return FALSE;
+}
+
+int __connman_dhcpv6_start(struct connman_network *network,
+				GSList *prefixes, dhcpv6_cb callback)
+{
+	struct connman_service *service;
+	struct connman_dhcpv6 *dhcp;
+	int delay;
+	uint64_t rand;
+
+	DBG("");
+
+	if (network_table) {
+		dhcp = g_hash_table_lookup(network_table, network);
+		if (dhcp && dhcp->started)
+			return -EBUSY;
+	}
+
+	service = connman_service_lookup_from_network(network);
+	if (!service)
+		return -EINVAL;
+
+	dhcp = g_try_new0(struct connman_dhcpv6, 1);
+	if (!dhcp)
+		return -ENOMEM;
+
+	dhcp->network = network;
+	dhcp->callback = callback;
+	dhcp->prefixes = prefixes;
+	dhcp->started = true;
+
+	connman_network_ref(network);
+
+	DBG("replace network %p dhcp %p", network, dhcp);
+
+	g_hash_table_replace(network_table, network, dhcp);
+
+	/* Initial timeout, RFC 3315, 17.1.2 */
+	__connman_util_get_random(&rand);
+	delay = rand % 1000;
+
+	/*
+	 * Start from scratch.
+	 * RFC 3315, chapter 17.1.2 Solicitation message
+	 *
+	 * Note that we do not send CONFIRM message here as it does
+	 * not make much sense because we do not save expiration time
+	 * so we cannot really know how long the saved address is valid
+	 * anyway. The reply to CONFIRM message does not send
+	 * expiration times back to us. Because of this we need to
+	 * start using SOLICITATION anyway.
+	 */
+	dhcp->timeout = g_timeout_add(delay, start_solicitation, dhcp);
+
+	return 0;
+}
+
+void __connman_dhcpv6_stop(struct connman_network *network)
+{
+	DBG("");
+
+	if (!network_table)
+		return;
+
+	if (g_hash_table_remove(network_table, network))
+		connman_network_unref(network);
+}
+
+static int save_prefixes(struct connman_ipconfig *ipconfig,
+			GSList *prefixes)
+{
+	GSList *list;
+	int i = 0, count = g_slist_length(prefixes);
+	char **array;
+
+	if (count == 0)
+		return 0;
+
+	array = g_try_new0(char *, count + 1);
+	if (!array)
+		return -ENOMEM;
+
+	for (list = prefixes; list; list = list->next) {
+		char *elem, addr_str[INET6_ADDRSTRLEN];
+		GDHCPIAPrefix *prefix = list->data;
+
+		elem = g_strdup_printf("%s/%d", inet_ntop(AF_INET6,
+				&prefix->prefix, addr_str, INET6_ADDRSTRLEN),
+				prefix->prefixlen);
+		if (!elem) {
+			g_strfreev(array);
+			return -ENOMEM;
+		}
+
+		array[i++] = elem;
+	}
+
+	__connman_ipconfig_set_dhcpv6_prefixes(ipconfig, array);
+	return 0;
+}
+
+static GSList *load_prefixes(struct connman_ipconfig *ipconfig)
+{
+	int i;
+	GSList *list = NULL;
+	char **array =  __connman_ipconfig_get_dhcpv6_prefixes(ipconfig);
+
+	if (!array)
+		return NULL;
+
+	for (i = 0; array[i]; i++) {
+		GDHCPIAPrefix *prefix;
+		long int value;
+		char *ptr, **elems = g_strsplit(array[i], "/", 0);
+
+		if (!elems)
+			return list;
+
+		value = strtol(elems[1], &ptr, 10);
+		if (ptr != elems[1] && *ptr == '\0' && value <= 128) {
+			struct in6_addr addr;
+
+			if (inet_pton(AF_INET6, elems[0], &addr) == 1) {
+				prefix = g_try_new0(GDHCPIAPrefix, 1);
+				if (!prefix) {
+					g_strfreev(elems);
+					return list;
+				}
+				memcpy(&prefix->prefix, &addr,
+					sizeof(struct in6_addr));
+				prefix->prefixlen = value;
+
+				list = g_slist_prepend(list, prefix);
+			}
+		}
+
+		g_strfreev(elems);
+	}
+
+	return list;
+}
+
+static GDHCPIAPrefix *copy_prefix(gpointer data)
+{
+	GDHCPIAPrefix *copy, *prefix = data;
+
+	copy = g_try_new(GDHCPIAPrefix, 1);
+	if (!copy)
+		return NULL;
+
+	memcpy(copy, prefix, sizeof(GDHCPIAPrefix));
+
+	return copy;
+}
+
+static GSList *copy_and_convert_prefixes(GList *prefixes)
+{
+	GSList *copy = NULL;
+	GList *list;
+
+	for (list = prefixes; list; list = list->next)
+		copy = g_slist_prepend(copy, copy_prefix(list->data));
+
+	return copy;
+}
+
+static int set_prefixes(GDHCPClient *dhcp_client, struct connman_dhcpv6 *dhcp)
+{
+	if (dhcp->prefixes)
+		g_slist_free_full(dhcp->prefixes, free_prefix);
+
+	dhcp->prefixes =
+		copy_and_convert_prefixes(g_dhcp_client_get_option(dhcp_client,
+							G_DHCPV6_IA_PD));
+
+	DBG("Got %d prefix", g_slist_length(dhcp->prefixes));
+
+	if (dhcp->callback) {
+		uint16_t status = g_dhcpv6_client_get_status(dhcp_client);
+		if (status == G_DHCPV6_ERROR_NO_PREFIX)
+			dhcp->callback(dhcp->network,
+					CONNMAN_DHCPV6_STATUS_FAIL, NULL);
+		else {
+			struct connman_service *service;
+			struct connman_ipconfig *ipconfig;
+			int ifindex = connman_network_get_index(dhcp->network);
+
+			service = __connman_service_lookup_from_index(ifindex);
+			if (service) {
+				ipconfig = __connman_service_get_ip6config(
+								service);
+				save_prefixes(ipconfig, dhcp->prefixes);
+				__connman_service_save(service);
+			}
+
+			dhcp->callback(dhcp->network,
+				CONNMAN_DHCPV6_STATUS_SUCCEED, dhcp->prefixes);
+		}
+	} else {
+		g_slist_free_full(dhcp->prefixes, free_prefix);
+		dhcp->prefixes = NULL;
+	}
+
+	return 0;
+}
+
+static void re_pd_cb(GDHCPClient *dhcp_client, gpointer user_data)
+{
+	struct connman_dhcpv6 *dhcp = user_data;
+	uint16_t status;
+	int ret;
+
+	status = g_dhcpv6_client_get_status(dhcp_client);
+
+	DBG("dhcpv6 cb msg %p status %d", dhcp, status);
+
+	if (status  == G_DHCPV6_ERROR_BINDING) {
+		/* RFC 3315, 18.1.8 */
+		dhcpv6_pd_request(dhcp);
+	} else {
+		ret = set_prefixes(dhcp_client, dhcp);
+		if (ret < 0) {
+			if (dhcp->callback)
+				dhcp->callback(dhcp->network,
+					CONNMAN_DHCPV6_STATUS_FAIL, NULL);
+			return;
+		}
+	}
+}
+
+static void rebind_pd_cb(GDHCPClient *dhcp_client, gpointer user_data)
+{
+	DBG("");
+
+	g_dhcpv6_client_clear_retransmit(dhcp_client);
+
+	re_pd_cb(dhcp_client, user_data);
+}
+
+static GDHCPClient *create_pd_client(struct connman_dhcpv6 *dhcp, int *err)
+{
+	GDHCPClient *dhcp_client;
+	GDHCPClientError error;
+	struct connman_service *service;
+	int index, ret;
+	uint32_t iaid;
+
+	index = connman_network_get_index(dhcp->network);
+
+	dhcp_client = g_dhcp_client_new(G_DHCP_IPV6, index, &error);
+	if (error != G_DHCP_CLIENT_ERROR_NONE) {
+		*err = -EINVAL;
+		return NULL;
+	}
+
+	if (getenv("CONNMAN_DHCPV6_DEBUG"))
+		g_dhcp_client_set_debug(dhcp_client, dhcpv6_debug, "DHCPv6:PD");
+
+	service = connman_service_lookup_from_network(dhcp->network);
+	if (!service) {
+		g_dhcp_client_unref(dhcp_client);
+		*err = -EINVAL;
+		return NULL;
+	}
+
+	ret = set_duid(service, dhcp->network, dhcp_client, index);
+	if (ret < 0) {
+		g_dhcp_client_unref(dhcp_client);
+		*err = ret;
+		return NULL;
+	}
+
+	g_dhcpv6_client_create_iaid(dhcp_client, index, (unsigned char *)&iaid);
+	g_dhcpv6_client_set_iaid(dhcp_client, iaid);
+
+	return dhcp_client;
+}
+
+static int dhcpv6_pd_rebind(struct connman_dhcpv6 *dhcp)
+{
+	GDHCPClient *dhcp_client;
+	uint32_t T1, T2;
+
+	DBG("dhcp %p", dhcp);
+
+	if (!dhcp->dhcp_client) {
+		/*
+		 * We skipped the solicitation phase
+		 */
+		int err;
+
+		dhcp->dhcp_client = create_pd_client(dhcp, &err);
+		if (!dhcp->dhcp_client) {
+			clear_timer(dhcp);
+			return err;
+		}
+	}
+
+	dhcp_client = dhcp->dhcp_client;
+
+	g_dhcp_client_clear_requests(dhcp_client);
+
+	g_dhcp_client_set_request(dhcp_client, G_DHCPV6_CLIENTID);
+	g_dhcp_client_set_request(dhcp_client, G_DHCPV6_DNS_SERVERS);
+	g_dhcp_client_set_request(dhcp_client, G_DHCPV6_SNTP_SERVERS);
+
+	g_dhcpv6_client_get_timeouts(dhcp_client, &T1, &T2, NULL, NULL);
+	g_dhcpv6_client_set_pd(dhcp_client, &T1, &T2, dhcp->prefixes);
+
+	clear_callbacks(dhcp_client);
+
+	g_dhcp_client_register_event(dhcp_client, G_DHCP_CLIENT_EVENT_REBIND,
+					rebind_pd_cb, dhcp);
+
+	return g_dhcp_client_start(dhcp_client, NULL);
+}
+
+static void renew_pd_cb(GDHCPClient *dhcp_client, gpointer user_data)
+{
+	DBG("");
+
+	g_dhcpv6_client_clear_retransmit(dhcp_client);
+
+	re_pd_cb(dhcp_client, user_data);
+}
+
+static int dhcpv6_pd_renew(struct connman_dhcpv6 *dhcp)
+{
+	GDHCPClient *dhcp_client;
+	uint32_t T1, T2;
+
+	DBG("dhcp %p", dhcp);
+
+	dhcp_client = dhcp->dhcp_client;
+
+	g_dhcp_client_clear_requests(dhcp_client);
+
+	g_dhcp_client_set_request(dhcp_client, G_DHCPV6_CLIENTID);
+	g_dhcp_client_set_request(dhcp_client, G_DHCPV6_SERVERID);
+	g_dhcp_client_set_request(dhcp_client, G_DHCPV6_DNS_SERVERS);
+	g_dhcp_client_set_request(dhcp_client, G_DHCPV6_SNTP_SERVERS);
+
+	g_dhcpv6_client_get_timeouts(dhcp_client, &T1, &T2, NULL, NULL);
+	g_dhcpv6_client_set_pd(dhcp_client, &T1, &T2, dhcp->prefixes);
+
+	clear_callbacks(dhcp_client);
+
+	g_dhcp_client_register_event(dhcp_client, G_DHCP_CLIENT_EVENT_RENEW,
+					renew_pd_cb, dhcp);
+
+	return g_dhcp_client_start(dhcp_client, NULL);
+}
+
+/*
+ * Check if we need to restart the solicitation procedure. This
+ * is done if all the prefixes have expired.
+ */
+static int check_pd_restart(struct connman_dhcpv6 *dhcp)
+{
+	time_t current, expired;
+
+	g_dhcpv6_client_get_timeouts(dhcp->dhcp_client, NULL, NULL,
+				NULL, &expired);
+	current = time(NULL);
+
+	if (current > expired) {
+		DBG("expired by %d secs", (int)(current - expired));
+
+		g_timeout_add(0, dhcpv6_restart, dhcp);
+
+		return -ETIMEDOUT;
+	}
+
+	return 0;
+}
+
+static gboolean timeout_pd_rebind(gpointer user_data)
+{
+	struct connman_dhcpv6 *dhcp = user_data;
+
+	if (check_pd_restart(dhcp) < 0)
+		return FALSE;
+
+	dhcp->RT = calc_delay(dhcp->RT, REB_MAX_RT);
+
+	DBG("rebind RT timeout %d msec", dhcp->RT);
+
+	dhcp->timeout = g_timeout_add(dhcp->RT, timeout_pd_rebind, dhcp);
+
+	g_dhcpv6_client_set_retransmit(dhcp->dhcp_client);
+
+	g_dhcp_client_start(dhcp->dhcp_client, NULL);
+
+	return FALSE;
+}
+
+static gboolean start_pd_rebind(gpointer user_data)
+{
+	struct connman_dhcpv6 *dhcp = user_data;
+
+	if (check_pd_restart(dhcp) < 0)
+		return FALSE;
+
+	dhcp->RT = initial_rt(REB_TIMEOUT);
+
+	DBG("rebind initial RT timeout %d msec", dhcp->RT);
+
+	dhcp->timeout = g_timeout_add(dhcp->RT, timeout_pd_rebind, dhcp);
+
+	dhcpv6_pd_rebind(dhcp);
+
+	return FALSE;
+}
+
+static gboolean timeout_pd_rebind_confirm(gpointer user_data)
+{
+	struct connman_dhcpv6 *dhcp = user_data;
+
+	dhcp->RT = calc_delay(dhcp->RT, CNF_MAX_RT);
+
+	DBG("rebind with confirm RT timeout %d msec", dhcp->RT);
+
+	dhcp->timeout = g_timeout_add(dhcp->RT,
+					timeout_pd_rebind_confirm, dhcp);
+
+	g_dhcpv6_client_set_retransmit(dhcp->dhcp_client);
+
+	g_dhcp_client_start(dhcp->dhcp_client, NULL);
+
+	return FALSE;
+}
+
+static gboolean timeout_pd_max_confirm(gpointer user_data)
+{
+	struct connman_dhcpv6 *dhcp = user_data;
+
+	dhcp->MRD = 0;
+
+	clear_timer(dhcp);
+
+	DBG("rebind with confirm max retransmit duration timeout");
+
+	g_dhcpv6_client_clear_retransmit(dhcp->dhcp_client);
+
+	if (dhcp->callback)
+		dhcp->callback(dhcp->network,
+			CONNMAN_DHCPV6_STATUS_FAIL, NULL);
+
+	return FALSE;
+}
+
+static gboolean start_pd_rebind_with_confirm(gpointer user_data)
+{
+	struct connman_dhcpv6 *dhcp = user_data;
+
+	dhcp->RT = initial_rt(CNF_TIMEOUT);
+
+	DBG("rebind with confirm initial RT timeout %d msec", dhcp->RT);
+
+	dhcp->timeout = g_timeout_add(dhcp->RT,
+					timeout_pd_rebind_confirm, dhcp);
+	dhcp->MRD = g_timeout_add(CNF_MAX_RD, timeout_pd_max_confirm, dhcp);
+
+	dhcpv6_pd_rebind(dhcp);
+
+	return FALSE;
+}
+
+static gboolean timeout_pd_renew(gpointer user_data)
+{
+	struct connman_dhcpv6 *dhcp = user_data;
+
+	if (check_pd_restart(dhcp) < 0)
+		return FALSE;
+
+	dhcp->RT = calc_delay(dhcp->RT, REN_MAX_RT);
+
+	DBG("renew RT timeout %d msec", dhcp->RT);
+
+	dhcp->timeout = g_timeout_add(dhcp->RT, timeout_renew, dhcp);
+
+	g_dhcpv6_client_set_retransmit(dhcp->dhcp_client);
+
+	g_dhcp_client_start(dhcp->dhcp_client, NULL);
+
+	return FALSE;
+}
+
+static gboolean start_pd_renew(gpointer user_data)
+{
+	struct connman_dhcpv6 *dhcp = user_data;
+
+	dhcp->RT = initial_rt(REN_TIMEOUT);
+
+	DBG("renew initial RT timeout %d msec", dhcp->RT);
+
+	dhcp->timeout = g_timeout_add(dhcp->RT, timeout_pd_renew, dhcp);
+
+	dhcpv6_pd_renew(dhcp);
+
+	return FALSE;
+}
+
+int __connman_dhcpv6_start_pd_renew(struct connman_network *network,
+				dhcpv6_cb callback)
+{
+	struct connman_dhcpv6 *dhcp;
+	uint32_t T1, T2;
+	time_t started, current, expired;
+
+	dhcp = g_hash_table_lookup(network_pd_table, network);
+	if (!dhcp)
+		return -ENOENT;
+
+	DBG("network %p dhcp %p", network, dhcp);
+
+	clear_timer(dhcp);
+
+	g_dhcpv6_client_get_timeouts(dhcp->dhcp_client, &T1, &T2,
+				&started, &expired);
+
+	current = time(NULL);
+
+	DBG("T1 %u T2 %u expires %lu current %lu started %lu", T1, T2,
+		expired, current, started);
+
+	if (T1 == 0xffffffff)
+		/* RFC 3633, ch 9 */
+		return 0;
+
+	if (T1 == 0)
+		/* RFC 3633, ch 9
+		 * Client can choose the timeout.
+		 */
+		T1 = 120;
+
+	dhcp->callback = callback;
+
+	/* RFC 3315, 18.1.4, start solicit if expired */
+	if (check_pd_restart(dhcp) < 0)
+		return 0;
+
+	if (T2 != 0xffffffff && T2 > 0) {
+		if ((unsigned)current >= (unsigned)started + T2) {
+			/* RFC 3315, chapter 18.1.3, start rebind */
+			DBG("rebind after %d secs", T2);
+
+			dhcp->timeout = g_timeout_add_seconds(T2,
+							start_pd_rebind,
+							dhcp);
+
+		} else if ((unsigned)current < (unsigned)started + T1) {
+			DBG("renew after %d secs", T1);
+
+			dhcp->timeout = g_timeout_add_seconds(T1,
+							start_pd_renew,
+							dhcp);
+		} else {
+			DBG("rebind after %d secs", T2 - T1);
+
+			dhcp->timeout = g_timeout_add_seconds(T2 - T1,
+							start_pd_rebind,
+							dhcp);
+		}
+	}
+
+	return 0;
+}
+
+static void release_pd_cb(GDHCPClient *dhcp_client, gpointer user_data)
+{
+	DBG("");
+}
+
+int __connman_dhcpv6_start_pd_release(struct connman_network *network,
+				dhcpv6_cb callback)
+{
+	struct connman_dhcpv6 *dhcp;
+	GDHCPClient *dhcp_client;
+	uint32_t T1, T2;
+
+	if (!network_table)
+		return 0;   /* we are already released */
+
+	dhcp = g_hash_table_lookup(network_pd_table, network);
+	if (!dhcp)
+		return -ENOENT;
+
+	DBG("network %p dhcp %p client %p", network, dhcp, dhcp->dhcp_client);
+
+	clear_timer(dhcp);
+
+	dhcp_client = dhcp->dhcp_client;
+	if (!dhcp_client) {
+		DBG("DHCPv6 PD was not started");
+		return 0;
+	}
+
+	g_dhcp_client_clear_requests(dhcp_client);
+	g_dhcp_client_clear_values(dhcp_client);
+
+	g_dhcp_client_set_request(dhcp_client, G_DHCPV6_CLIENTID);
+	g_dhcp_client_set_request(dhcp_client, G_DHCPV6_SERVERID);
+
+	g_dhcpv6_client_get_timeouts(dhcp_client, &T1, &T2, NULL, NULL);
+	g_dhcpv6_client_set_pd(dhcp_client, &T1, &T2, dhcp->prefixes);
+
+	clear_callbacks(dhcp_client);
+
+	g_dhcp_client_register_event(dhcp_client, G_DHCP_CLIENT_EVENT_RELEASE,
+					release_pd_cb, dhcp);
+
+	dhcp->dhcp_client = dhcp_client;
+
+	return g_dhcp_client_start(dhcp_client, NULL);
+}
+
+static gboolean timeout_pd_request(gpointer user_data)
+{
+	struct connman_dhcpv6 *dhcp = user_data;
+
+	if (dhcp->request_count >= REQ_MAX_RC) {
+		DBG("max request retry attempts %d", dhcp->request_count);
+		dhcp->request_count = 0;
+		if (dhcp->callback)
+			dhcp->callback(dhcp->network,
+					CONNMAN_DHCPV6_STATUS_FAIL, NULL);
+		return FALSE;
+	}
+
+	dhcp->request_count++;
+
+	dhcp->RT = calc_delay(dhcp->RT, REQ_MAX_RT);
+	DBG("request RT timeout %d msec", dhcp->RT);
+	dhcp->timeout = g_timeout_add(dhcp->RT, timeout_pd_request, dhcp);
+
+	g_dhcpv6_client_set_retransmit(dhcp->dhcp_client);
+
+	g_dhcp_client_start(dhcp->dhcp_client, NULL);
+
+	return FALSE;
+}
+
+static void request_pd_cb(GDHCPClient *dhcp_client, gpointer user_data)
+{
+	struct connman_dhcpv6 *dhcp = user_data;
+	uint16_t status;
+
+	DBG("");
+
+	g_dhcpv6_client_clear_retransmit(dhcp_client);
+
+	status = g_dhcpv6_client_get_status(dhcp_client);
+
+	DBG("dhcpv6 pd cb msg %p status %d", dhcp, status);
+
+	if (status  == G_DHCPV6_ERROR_BINDING) {
+		/* RFC 3315, 18.1.8 */
+		dhcpv6_pd_request(dhcp);
+	} else {
+		set_prefixes(dhcp_client, dhcp);
+	}
+}
+
+static int dhcpv6_pd_request(struct connman_dhcpv6 *dhcp)
+{
+	GDHCPClient *dhcp_client;
+	uint32_t T1 = 0, T2 = 0;
+
+	DBG("dhcp %p", dhcp);
+
+	dhcp_client = dhcp->dhcp_client;
+
+	g_dhcp_client_clear_requests(dhcp_client);
+
+	g_dhcp_client_set_request(dhcp_client, G_DHCPV6_CLIENTID);
+	g_dhcp_client_set_request(dhcp_client, G_DHCPV6_SERVERID);
+	g_dhcp_client_set_request(dhcp_client, G_DHCPV6_DNS_SERVERS);
+	g_dhcp_client_set_request(dhcp_client, G_DHCPV6_SNTP_SERVERS);
+
+	g_dhcpv6_client_get_timeouts(dhcp_client, &T1, &T2, NULL, NULL);
+	g_dhcpv6_client_set_pd(dhcp_client, &T1, &T2, dhcp->prefixes);
+
+	clear_callbacks(dhcp_client);
+
+	g_dhcp_client_register_event(dhcp_client, G_DHCP_CLIENT_EVENT_REQUEST,
+					request_pd_cb, dhcp);
+
+	return g_dhcp_client_start(dhcp_client, NULL);
+}
+
+static void advertise_pd_cb(GDHCPClient *dhcp_client, gpointer user_data)
+{
+	struct connman_dhcpv6 *dhcp = user_data;
+
+	DBG("dhcpv6 advertise pd msg %p", dhcp);
+
+	clear_timer(dhcp);
+
+	g_dhcpv6_client_clear_retransmit(dhcp_client);
+
+	if (g_dhcpv6_client_get_status(dhcp_client) != 0) {
+		if (dhcp->callback)
+			dhcp->callback(dhcp->network,
+					CONNMAN_DHCPV6_STATUS_FAIL, NULL);
+		return;
+	}
+
+	dhcp->RT = initial_rt(REQ_TIMEOUT);
+	DBG("request initial RT timeout %d msec", dhcp->RT);
+	dhcp->timeout = g_timeout_add(dhcp->RT, timeout_pd_request, dhcp);
+
+	dhcp->request_count = 1;
+
+	dhcpv6_pd_request(dhcp);
+}
+
+static void solicitation_pd_cb(GDHCPClient *dhcp_client, gpointer user_data)
+{
+	/*
+	 * This callback is here so that g_dhcp_client_start()
+	 * will enter the proper L3 mode.
+	 */
+	DBG("DHCPv6 %p solicitation msg received, ignoring it", user_data);
+}
+
+static int dhcpv6_pd_solicitation(struct connman_dhcpv6 *dhcp)
+{
+	GDHCPClient *dhcp_client;
+	int ret;
+
+	DBG("dhcp %p", dhcp);
+
+	dhcp_client = create_pd_client(dhcp, &ret);
+	if (!dhcp_client) {
+		clear_timer(dhcp);
+		return ret;
+	}
+
+	g_dhcp_client_set_request(dhcp_client, G_DHCPV6_CLIENTID);
+
+	g_dhcpv6_client_set_pd(dhcp_client, NULL, NULL, NULL);
+
+	clear_callbacks(dhcp_client);
+
+	g_dhcp_client_register_event(dhcp_client,
+				G_DHCP_CLIENT_EVENT_ADVERTISE,
+				advertise_pd_cb, dhcp);
+
+	g_dhcp_client_register_event(dhcp_client,
+				G_DHCP_CLIENT_EVENT_SOLICITATION,
+				solicitation_pd_cb, dhcp);
+
+	dhcp->dhcp_client = dhcp_client;
+
+	return g_dhcp_client_start(dhcp_client, NULL);
+}
+
+static gboolean start_pd_solicitation(gpointer user_data)
+{
+	struct connman_dhcpv6 *dhcp = user_data;
+
+	/* Set the retransmission timeout, RFC 3315 chapter 14 */
+	dhcp->RT = initial_rt(SOL_TIMEOUT);
+
+	DBG("solicit initial RT timeout %d msec", dhcp->RT);
+
+	dhcp->timeout = g_timeout_add(dhcp->RT, timeout_solicitation, dhcp);
+
+	dhcpv6_pd_solicitation(dhcp);
+
+	return FALSE;
+}
+
+int __connman_dhcpv6_start_pd(int index, GSList *prefixes, dhcpv6_cb callback)
+{
+	struct connman_service *service;
+	struct connman_network *network;
+	struct connman_dhcpv6 *dhcp;
+
+	if (index < 0)
+		return 0;
+
+	DBG("index %d", index);
+
+	service = __connman_service_lookup_from_index(index);
+	if (!service)
+		return -EINVAL;
+
+	network = __connman_service_get_network(service);
+	if (!network)
+		return -EINVAL;
+
+	if (network_pd_table) {
+		dhcp = g_hash_table_lookup(network_pd_table, network);
+		if (dhcp && dhcp->started)
+			return -EBUSY;
+	}
+
+	dhcp = g_try_new0(struct connman_dhcpv6, 1);
+	if (!dhcp)
+		return -ENOMEM;
+
+	dhcp->network = network;
+	dhcp->callback = callback;
+	dhcp->started = true;
+
+	if (!prefixes) {
+		/*
+		 * Try to load the earlier prefixes if caller did not supply
+		 * any that we could use.
+		 */
+		struct connman_ipconfig *ipconfig;
+		ipconfig = __connman_service_get_ip6config(service);
+
+		dhcp->prefixes = load_prefixes(ipconfig);
+	} else
+		dhcp->prefixes = prefixes;
+
+	connman_network_ref(network);
+
+	DBG("replace network %p dhcp %p", network, dhcp);
+
+	g_hash_table_replace(network_pd_table, network, dhcp);
+
+	if (!dhcp->prefixes) {
+		/*
+		 * Refresh start, try to get prefixes.
+		 */
+		start_pd_solicitation(dhcp);
+	} else {
+		/*
+		 * We used to have prefixes, try to use them again.
+		 * We need to use timeouts from confirm msg, RFC 3633, ch 12.1
+		 */
+		start_pd_rebind_with_confirm(dhcp);
+	}
+
+	return 0;
+}
+
+void __connman_dhcpv6_stop_pd(int index)
+{
+	struct connman_service *service;
+	struct connman_network *network;
+
+	if (index < 0)
+		return;
+
+	DBG("index %d", index);
+
+	if (!network_pd_table)
+		return;
+
+	service = __connman_service_lookup_from_index(index);
+	if (!service)
+		return;
+
+	network = __connman_service_get_network(service);
+	if (!network)
+		return;
+
+	__connman_dhcpv6_start_pd_release(network, NULL);
+
+	if (g_hash_table_remove(network_pd_table, network))
+		connman_network_unref(network);
+}
+
+int __connman_dhcpv6_init(void)
+{
+	DBG("");
+
+	network_table = g_hash_table_new_full(g_direct_hash, g_direct_equal,
+							NULL, remove_network);
+
+	network_pd_table = g_hash_table_new_full(g_direct_hash, g_direct_equal,
+							NULL, remove_network);
+
+	return 0;
+}
+
+void __connman_dhcpv6_cleanup(void)
+{
+	DBG("");
+
+	g_hash_table_destroy(network_table);
+	network_table = NULL;
+
+	g_hash_table_destroy(network_pd_table);
+	network_pd_table = NULL;
+}
diff --git a/connman/src/dnsproxy.c b/connman/src/dnsproxy.c
new file mode 100644
index 0000000..3a369bc
--- /dev/null
+++ b/connman/src/dnsproxy.c
@@ -0,0 +1,3887 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2014  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 <string.h>
+#include <stdint.h>
+#include <arpa/inet.h>
+#include <netinet/in.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <fcntl.h>
+#include <netdb.h>
+#include <resolv.h>
+#include <gweb/gresolv.h>
+
+#include <glib.h>
+
+#include "connman.h"
+
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+struct domain_hdr {
+	uint16_t id;
+	uint8_t rd:1;
+	uint8_t tc:1;
+	uint8_t aa:1;
+	uint8_t opcode:4;
+	uint8_t qr:1;
+	uint8_t rcode:4;
+	uint8_t z:3;
+	uint8_t ra:1;
+	uint16_t qdcount;
+	uint16_t ancount;
+	uint16_t nscount;
+	uint16_t arcount;
+} __attribute__ ((packed));
+#elif __BYTE_ORDER == __BIG_ENDIAN
+struct domain_hdr {
+	uint16_t id;
+	uint8_t qr:1;
+	uint8_t opcode:4;
+	uint8_t aa:1;
+	uint8_t tc:1;
+	uint8_t rd:1;
+	uint8_t ra:1;
+	uint8_t z:3;
+	uint8_t rcode:4;
+	uint16_t qdcount;
+	uint16_t ancount;
+	uint16_t nscount;
+	uint16_t arcount;
+} __attribute__ ((packed));
+#else
+#error "Unknown byte order"
+#endif
+
+struct partial_reply {
+	uint16_t len;
+	uint16_t received;
+	unsigned char buf[];
+};
+
+struct server_data {
+	int index;
+	GList *domains;
+	char *server;
+	struct sockaddr *server_addr;
+	socklen_t server_addr_len;
+	int protocol;
+	GIOChannel *channel;
+	guint watch;
+	guint timeout;
+	bool enabled;
+	bool connected;
+	struct partial_reply *incoming_reply;
+};
+
+struct request_data {
+	union {
+		struct sockaddr_in6 __sin6; /* Only for the length */
+		struct sockaddr sa;
+	};
+	socklen_t sa_len;
+	int client_sk;
+	int protocol;
+	int family;
+	guint16 srcid;
+	guint16 dstid;
+	guint16 altid;
+	guint timeout;
+	guint watch;
+	guint numserv;
+	guint numresp;
+	gpointer request;
+	gsize request_len;
+	gpointer name;
+	gpointer resp;
+	gsize resplen;
+	struct listener_data *ifdata;
+	bool append_domain;
+};
+
+struct listener_data {
+	int index;
+
+	GIOChannel *udp4_listener_channel;
+	GIOChannel *tcp4_listener_channel;
+	guint udp4_listener_watch;
+	guint tcp4_listener_watch;
+
+	GIOChannel *udp6_listener_channel;
+	GIOChannel *tcp6_listener_channel;
+	guint udp6_listener_watch;
+	guint tcp6_listener_watch;
+};
+
+/*
+ * The TCP client requires some extra handling as we need to
+ * be prepared to receive also partial DNS requests.
+ */
+struct tcp_partial_client_data {
+	int family;
+	struct listener_data *ifdata;
+	GIOChannel *channel;
+	guint watch;
+	unsigned char *buf;
+	unsigned int buf_end;
+	guint timeout;
+};
+
+struct cache_data {
+	time_t inserted;
+	time_t valid_until;
+	time_t cache_until;
+	int timeout;
+	uint16_t type;
+	uint16_t answers;
+	unsigned int data_len;
+	unsigned char *data; /* contains DNS header + body */
+};
+
+struct cache_entry {
+	char *key;
+	bool want_refresh;
+	int hits;
+	struct cache_data *ipv4;
+	struct cache_data *ipv6;
+};
+
+struct domain_question {
+	uint16_t type;
+	uint16_t class;
+} __attribute__ ((packed));
+
+struct domain_rr {
+	uint16_t type;
+	uint16_t class;
+	uint32_t ttl;
+	uint16_t rdlen;
+} __attribute__ ((packed));
+
+/*
+ * Max length of the DNS TCP packet.
+ */
+#define TCP_MAX_BUF_LEN 4096
+
+/*
+ * We limit how long the cached DNS entry stays in the cache.
+ * By default the TTL (time-to-live) of the DNS response is used
+ * when setting the cache entry life time. The value is in seconds.
+ */
+#define MAX_CACHE_TTL (60 * 30)
+/*
+ * Also limit the other end, cache at least for 30 seconds.
+ */
+#define MIN_CACHE_TTL (30)
+
+/*
+ * We limit the cache size to some sane value so that cached data does
+ * not occupy too much memory. Each cached entry occupies on average
+ * about 100 bytes memory (depending on DNS name length).
+ * Example: caching www.connman.net uses 97 bytes memory.
+ * The value is the max amount of cached DNS responses (count).
+ */
+#define MAX_CACHE_SIZE 256
+
+static int cache_size;
+static GHashTable *cache;
+static int cache_refcount;
+static GSList *server_list = NULL;
+static GSList *request_list = NULL;
+static GHashTable *listener_table = NULL;
+static time_t next_refresh;
+static GHashTable *partial_tcp_req_table;
+static guint cache_timer = 0;
+
+static guint16 get_id(void)
+{
+	uint64_t rand;
+
+	__connman_util_get_random(&rand);
+
+	return rand;
+}
+
+static int protocol_offset(int protocol)
+{
+	switch (protocol) {
+	case IPPROTO_UDP:
+		return 0;
+
+	case IPPROTO_TCP:
+		return 2;
+
+	default:
+		return -EINVAL;
+	}
+
+}
+
+/*
+ * There is a power and efficiency benefit to have entries
+ * in our cache expire at the same time. To this extend,
+ * we round down the cache valid time to common boundaries.
+ */
+static time_t round_down_ttl(time_t end_time, int ttl)
+{
+	if (ttl < 15)
+		return end_time;
+
+	/* Less than 5 minutes, round to 10 second boundary */
+	if (ttl < 300) {
+		end_time = end_time / 10;
+		end_time = end_time * 10;
+	} else { /* 5 or more minutes, round to 30 seconds */
+		end_time = end_time / 30;
+		end_time = end_time * 30;
+	}
+	return end_time;
+}
+
+static struct request_data *find_request(guint16 id)
+{
+	GSList *list;
+
+	for (list = request_list; list; list = list->next) {
+		struct request_data *req = list->data;
+
+		if (req->dstid == id || req->altid == id)
+			return req;
+	}
+
+	return NULL;
+}
+
+static struct server_data *find_server(int index,
+					const char *server,
+						int protocol)
+{
+	GSList *list;
+
+	DBG("index %d server %s proto %d", index, server, protocol);
+
+	for (list = server_list; list; list = list->next) {
+		struct server_data *data = list->data;
+
+		if (index < 0 && data->index < 0 &&
+				g_str_equal(data->server, server) &&
+				data->protocol == protocol)
+			return data;
+
+		if (index < 0 ||
+				data->index < 0 || !data->server)
+			continue;
+
+		if (data->index == index &&
+				g_str_equal(data->server, server) &&
+				data->protocol == protocol)
+			return data;
+	}
+
+	return NULL;
+}
+
+/* we can keep using the same resolve's */
+static GResolv *ipv4_resolve;
+static GResolv *ipv6_resolve;
+
+static void dummy_resolve_func(GResolvResultStatus status,
+					char **results, gpointer user_data)
+{
+}
+
+/*
+ * Refresh a DNS entry, but also age the hit count a bit */
+static void refresh_dns_entry(struct cache_entry *entry, char *name)
+{
+	int age = 1;
+
+	if (!ipv4_resolve) {
+		ipv4_resolve = g_resolv_new(0);
+		g_resolv_set_address_family(ipv4_resolve, AF_INET);
+		g_resolv_add_nameserver(ipv4_resolve, "127.0.0.1", 53, 0);
+	}
+
+	if (!ipv6_resolve) {
+		ipv6_resolve = g_resolv_new(0);
+		g_resolv_set_address_family(ipv6_resolve, AF_INET6);
+		g_resolv_add_nameserver(ipv6_resolve, "::1", 53, 0);
+	}
+
+	if (!entry->ipv4) {
+		DBG("Refresing A record for %s", name);
+		g_resolv_lookup_hostname(ipv4_resolve, name,
+					dummy_resolve_func, NULL);
+		age = 4;
+	}
+
+	if (!entry->ipv6) {
+		DBG("Refresing AAAA record for %s", name);
+		g_resolv_lookup_hostname(ipv6_resolve, name,
+					dummy_resolve_func, NULL);
+		age = 4;
+	}
+
+	entry->hits -= age;
+	if (entry->hits < 0)
+		entry->hits = 0;
+}
+
+static int dns_name_length(unsigned char *buf)
+{
+	if ((buf[0] & NS_CMPRSFLGS) == NS_CMPRSFLGS) /* compressed name */
+		return 2;
+	return strlen((char *)buf);
+}
+
+static void update_cached_ttl(unsigned char *buf, int len, int new_ttl)
+{
+	unsigned char *c;
+	uint16_t w;
+	int l;
+
+	/* skip the header */
+	c = buf + 12;
+	len -= 12;
+
+	/* skip the query, which is a name and 2 16 bit words */
+	l = dns_name_length(c);
+	c += l;
+	len -= l;
+	c += 4;
+	len -= 4;
+
+	/* now we get the answer records */
+
+	while (len > 0) {
+		/* first a name */
+		l = dns_name_length(c);
+		c += l;
+		len -= l;
+		if (len < 0)
+			break;
+		/* then type + class, 2 bytes each */
+		c += 4;
+		len -= 4;
+		if (len < 0)
+			break;
+
+		/* now the 4 byte TTL field */
+		c[0] = new_ttl >> 24 & 0xff;
+		c[1] = new_ttl >> 16 & 0xff;
+		c[2] = new_ttl >> 8 & 0xff;
+		c[3] = new_ttl & 0xff;
+		c += 4;
+		len -= 4;
+		if (len < 0)
+			break;
+
+		/* now the 2 byte rdlen field */
+		w = c[0] << 8 | c[1];
+		c += w + 2;
+		len -= w + 2;
+	}
+}
+
+static void send_cached_response(int sk, unsigned char *buf, int len,
+				const struct sockaddr *to, socklen_t tolen,
+				int protocol, int id, uint16_t answers, int ttl)
+{
+	struct domain_hdr *hdr;
+	unsigned char *ptr = buf;
+	int err, offset, dns_len, adj_len = len - 2;
+
+	/*
+	 * The cached packet contains always the TCP offset (two bytes)
+	 * so skip them for UDP.
+	 */
+	switch (protocol) {
+	case IPPROTO_UDP:
+		ptr += 2;
+		len -= 2;
+		dns_len = len;
+		offset = 0;
+		break;
+	case IPPROTO_TCP:
+		offset = 2;
+		dns_len = ptr[0] * 256 + ptr[1];
+		break;
+	default:
+		return;
+	}
+
+	if (len < 12)
+		return;
+
+	hdr = (void *) (ptr + offset);
+
+	hdr->id = id;
+	hdr->qr = 1;
+	hdr->rcode = ns_r_noerror;
+	hdr->ancount = htons(answers);
+	hdr->nscount = 0;
+	hdr->arcount = 0;
+
+	/* if this is a negative reply, we are authorative */
+	if (answers == 0)
+		hdr->aa = 1;
+	else
+		update_cached_ttl((unsigned char *)hdr, adj_len, ttl);
+
+	DBG("sk %d id 0x%04x answers %d ptr %p length %d dns %d",
+		sk, hdr->id, answers, ptr, len, dns_len);
+
+	err = sendto(sk, ptr, len, MSG_NOSIGNAL, to, tolen);
+	if (err < 0) {
+		connman_error("Cannot send cached DNS response: %s",
+				strerror(errno));
+		return;
+	}
+
+	if (err != len || (dns_len != (len - 2) && protocol == IPPROTO_TCP) ||
+				(dns_len != len && protocol == IPPROTO_UDP))
+		DBG("Packet length mismatch, sent %d wanted %d dns %d",
+			err, len, dns_len);
+}
+
+static void send_response(int sk, unsigned char *buf, int len,
+				const struct sockaddr *to, socklen_t tolen,
+				int protocol)
+{
+	struct domain_hdr *hdr;
+	int err, offset = protocol_offset(protocol);
+
+	DBG("sk %d", sk);
+
+	if (offset < 0)
+		return;
+
+	if (len < 12)
+		return;
+
+	hdr = (void *) (buf + offset);
+
+	DBG("id 0x%04x qr %d opcode %d", hdr->id, hdr->qr, hdr->opcode);
+
+	hdr->qr = 1;
+	hdr->rcode = ns_r_servfail;
+
+	hdr->ancount = 0;
+	hdr->nscount = 0;
+	hdr->arcount = 0;
+
+	err = sendto(sk, buf, len, MSG_NOSIGNAL, to, tolen);
+	if (err < 0) {
+		connman_error("Failed to send DNS response to %d: %s",
+				sk, strerror(errno));
+		return;
+	}
+}
+
+static int get_req_udp_socket(struct request_data *req)
+{
+	GIOChannel *channel;
+
+	if (req->family == AF_INET)
+		channel = req->ifdata->udp4_listener_channel;
+	else
+		channel = req->ifdata->udp6_listener_channel;
+
+	if (!channel)
+		return -1;
+
+	return g_io_channel_unix_get_fd(channel);
+}
+
+static void destroy_request_data(struct request_data *req)
+{
+	if (req->timeout > 0)
+		g_source_remove(req->timeout);
+
+	g_free(req->resp);
+	g_free(req->request);
+	g_free(req->name);
+	g_free(req);
+}
+
+static gboolean request_timeout(gpointer user_data)
+{
+	struct request_data *req = user_data;
+	struct sockaddr *sa;
+	int sk;
+
+	if (!req)
+		return FALSE;
+
+	DBG("id 0x%04x", req->srcid);
+
+	request_list = g_slist_remove(request_list, req);
+
+	if (req->protocol == IPPROTO_UDP) {
+		sk = get_req_udp_socket(req);
+		sa = &req->sa;
+	} else if (req->protocol == IPPROTO_TCP) {
+		sk = req->client_sk;
+		sa = NULL;
+	} else
+		goto out;
+
+	if (req->resplen > 0 && req->resp) {
+		/*
+		 * Here we have received at least one reply (probably telling
+		 * "not found" result), so send that back to client instead
+		 * of more fatal server failed error.
+		 */
+		if (sk >= 0)
+			sendto(sk, req->resp, req->resplen, MSG_NOSIGNAL,
+				sa, req->sa_len);
+
+	} else if (req->request) {
+		/*
+		 * There was not reply from server at all.
+		 */
+		struct domain_hdr *hdr;
+
+		hdr = (void *)(req->request + protocol_offset(req->protocol));
+		hdr->id = req->srcid;
+
+		if (sk >= 0)
+			send_response(sk, req->request, req->request_len,
+				sa, req->sa_len, req->protocol);
+	}
+
+	/*
+	 * We cannot leave TCP client hanging so just kick it out
+	 * if we get a request timeout from server.
+	 */
+	if (req->protocol == IPPROTO_TCP) {
+		DBG("client %d removed", req->client_sk);
+		g_hash_table_remove(partial_tcp_req_table,
+				GINT_TO_POINTER(req->client_sk));
+	}
+
+out:
+	req->timeout = 0;
+	destroy_request_data(req);
+
+	return FALSE;
+}
+
+static int append_query(unsigned char *buf, unsigned int size,
+				const char *query, const char *domain)
+{
+	unsigned char *ptr = buf;
+	int len;
+
+	DBG("query %s domain %s", query, domain);
+
+	while (query) {
+		const char *tmp;
+
+		tmp = strchr(query, '.');
+		if (!tmp) {
+			len = strlen(query);
+			if (len == 0)
+				break;
+			*ptr = len;
+			memcpy(ptr + 1, query, len);
+			ptr += len + 1;
+			break;
+		}
+
+		*ptr = tmp - query;
+		memcpy(ptr + 1, query, tmp - query);
+		ptr += tmp - query + 1;
+
+		query = tmp + 1;
+	}
+
+	while (domain) {
+		const char *tmp;
+
+		tmp = strchr(domain, '.');
+		if (!tmp) {
+			len = strlen(domain);
+			if (len == 0)
+				break;
+			*ptr = len;
+			memcpy(ptr + 1, domain, len);
+			ptr += len + 1;
+			break;
+		}
+
+		*ptr = tmp - domain;
+		memcpy(ptr + 1, domain, tmp - domain);
+		ptr += tmp - domain + 1;
+
+		domain = tmp + 1;
+	}
+
+	*ptr++ = 0x00;
+
+	return ptr - buf;
+}
+
+static bool cache_check_is_valid(struct cache_data *data,
+				time_t current_time)
+{
+	if (!data)
+		return false;
+
+	if (data->cache_until < current_time)
+		return false;
+
+	return true;
+}
+
+/*
+ * remove stale cached entries so that they can be refreshed
+ */
+static void cache_enforce_validity(struct cache_entry *entry)
+{
+	time_t current_time = time(NULL);
+
+	if (!cache_check_is_valid(entry->ipv4, current_time)
+							&& entry->ipv4) {
+		DBG("cache timeout \"%s\" type A", entry->key);
+		g_free(entry->ipv4->data);
+		g_free(entry->ipv4);
+		entry->ipv4 = NULL;
+
+	}
+
+	if (!cache_check_is_valid(entry->ipv6, current_time)
+							&& entry->ipv6) {
+		DBG("cache timeout \"%s\" type AAAA", entry->key);
+		g_free(entry->ipv6->data);
+		g_free(entry->ipv6);
+		entry->ipv6 = NULL;
+	}
+}
+
+static uint16_t cache_check_validity(char *question, uint16_t type,
+				struct cache_entry *entry)
+{
+	time_t current_time = time(NULL);
+	bool want_refresh = false;
+
+	/*
+	 * if we have a popular entry, we want a refresh instead of
+	 * total destruction of the entry.
+	 */
+	if (entry->hits > 2)
+		want_refresh = true;
+
+	cache_enforce_validity(entry);
+
+	switch (type) {
+	case 1:		/* IPv4 */
+		if (!cache_check_is_valid(entry->ipv4, current_time)) {
+			DBG("cache %s \"%s\" type A", entry->ipv4 ?
+					"timeout" : "entry missing", question);
+
+			if (want_refresh)
+				entry->want_refresh = true;
+
+			/*
+			 * We do not remove cache entry if there is still
+			 * valid IPv6 entry found in the cache.
+			 */
+			if (!cache_check_is_valid(entry->ipv6, current_time) && !want_refresh) {
+				g_hash_table_remove(cache, question);
+				type = 0;
+			}
+		}
+		break;
+
+	case 28:	/* IPv6 */
+		if (!cache_check_is_valid(entry->ipv6, current_time)) {
+			DBG("cache %s \"%s\" type AAAA", entry->ipv6 ?
+					"timeout" : "entry missing", question);
+
+			if (want_refresh)
+				entry->want_refresh = true;
+
+			if (!cache_check_is_valid(entry->ipv4, current_time) && !want_refresh) {
+				g_hash_table_remove(cache, question);
+				type = 0;
+			}
+		}
+		break;
+	}
+
+	return type;
+}
+
+static void cache_element_destroy(gpointer value)
+{
+	struct cache_entry *entry = value;
+
+	if (!entry)
+		return;
+
+	if (entry->ipv4) {
+		g_free(entry->ipv4->data);
+		g_free(entry->ipv4);
+	}
+
+	if (entry->ipv6) {
+		g_free(entry->ipv6->data);
+		g_free(entry->ipv6);
+	}
+
+	g_free(entry->key);
+	g_free(entry);
+
+	if (--cache_size < 0)
+		cache_size = 0;
+}
+
+static gboolean try_remove_cache(gpointer user_data)
+{
+	cache_timer = 0;
+
+	if (__sync_fetch_and_sub(&cache_refcount, 1) == 1) {
+		DBG("No cache users, removing it.");
+
+		g_hash_table_destroy(cache);
+		cache = NULL;
+	}
+
+	return FALSE;
+}
+
+static void create_cache(void)
+{
+	if (__sync_fetch_and_add(&cache_refcount, 1) == 0)
+		cache = g_hash_table_new_full(g_str_hash,
+					g_str_equal,
+					NULL,
+					cache_element_destroy);
+}
+
+static struct cache_entry *cache_check(gpointer request, int *qtype, int proto)
+{
+	char *question;
+	struct cache_entry *entry;
+	struct domain_question *q;
+	uint16_t type;
+	int offset, proto_offset;
+
+	if (!request)
+		return NULL;
+
+	proto_offset = protocol_offset(proto);
+	if (proto_offset < 0)
+		return NULL;
+
+	question = request + proto_offset + 12;
+
+	offset = strlen(question) + 1;
+	q = (void *) (question + offset);
+	type = ntohs(q->type);
+
+	/* We only cache either A (1) or AAAA (28) requests */
+	if (type != 1 && type != 28)
+		return NULL;
+
+	if (!cache) {
+		create_cache();
+		return NULL;
+	}
+
+	entry = g_hash_table_lookup(cache, question);
+	if (!entry)
+		return NULL;
+
+	type = cache_check_validity(question, type, entry);
+	if (type == 0)
+		return NULL;
+
+	*qtype = type;
+	return entry;
+}
+
+/*
+ * Get a label/name from DNS resource record. The function decompresses the
+ * label if necessary. The function does not convert the name to presentation
+ * form. This means that the result string will contain label lengths instead
+ * of dots between labels. We intentionally do not want to convert to dotted
+ * format so that we can cache the wire format string directly.
+ */
+static int get_name(int counter,
+		unsigned char *pkt, unsigned char *start, unsigned char *max,
+		unsigned char *output, int output_max, int *output_len,
+		unsigned char **end, char *name, int *name_len)
+{
+	unsigned char *p;
+
+	/* Limit recursion to 10 (this means up to 10 labels in domain name) */
+	if (counter > 10)
+		return -EINVAL;
+
+	p = start;
+	while (*p) {
+		if ((*p & NS_CMPRSFLGS) == NS_CMPRSFLGS) {
+			uint16_t offset = (*p & 0x3F) * 256 + *(p + 1);
+
+			if (offset >= max - pkt)
+				return -ENOBUFS;
+
+			if (!*end)
+				*end = p + 2;
+
+			return get_name(counter + 1, pkt, pkt + offset, max,
+					output, output_max, output_len, end,
+					name, name_len);
+		} else {
+			unsigned label_len = *p;
+
+			if (pkt + label_len > max)
+				return -ENOBUFS;
+
+			if (*output_len > output_max)
+				return -ENOBUFS;
+
+			/*
+			 * We need the original name in order to check
+			 * if this answer is the correct one.
+			 */
+			name[(*name_len)++] = label_len;
+			memcpy(name + *name_len, p + 1,	label_len + 1);
+			*name_len += label_len;
+
+			/* We compress the result */
+			output[0] = NS_CMPRSFLGS;
+			output[1] = 0x0C;
+			*output_len = 2;
+
+			p += label_len + 1;
+
+			if (!*end)
+				*end = p;
+
+			if (p >= max)
+				return -ENOBUFS;
+		}
+	}
+
+	return 0;
+}
+
+static int parse_rr(unsigned char *buf, unsigned char *start,
+			unsigned char *max,
+			unsigned char *response, unsigned int *response_size,
+			uint16_t *type, uint16_t *class, int *ttl, int *rdlen,
+			unsigned char **end,
+			char *name)
+{
+	struct domain_rr *rr;
+	int err, offset;
+	int name_len = 0, output_len = 0, max_rsp = *response_size;
+
+	err = get_name(0, buf, start, max, response, max_rsp,
+		&output_len, end, name, &name_len);
+	if (err < 0)
+		return err;
+
+	offset = output_len;
+
+	if ((unsigned int) offset > *response_size)
+		return -ENOBUFS;
+
+	rr = (void *) (*end);
+
+	if (!rr)
+		return -EINVAL;
+
+	*type = ntohs(rr->type);
+	*class = ntohs(rr->class);
+	*ttl = ntohl(rr->ttl);
+	*rdlen = ntohs(rr->rdlen);
+
+	if (*ttl < 0)
+		return -EINVAL;
+
+	memcpy(response + offset, *end, sizeof(struct domain_rr));
+
+	offset += sizeof(struct domain_rr);
+	*end += sizeof(struct domain_rr);
+
+	if ((unsigned int) (offset + *rdlen) > *response_size)
+		return -ENOBUFS;
+
+	memcpy(response + offset, *end, *rdlen);
+
+	*end += *rdlen;
+
+	*response_size = offset + *rdlen;
+
+	return 0;
+}
+
+static bool check_alias(GSList *aliases, char *name)
+{
+	GSList *list;
+
+	if (aliases) {
+		for (list = aliases; list; list = list->next) {
+			int len = strlen((char *)list->data);
+			if (strncmp((char *)list->data, name, len) == 0)
+				return true;
+		}
+	}
+
+	return false;
+}
+
+static int parse_response(unsigned char *buf, int buflen,
+			char *question, int qlen,
+			uint16_t *type, uint16_t *class, int *ttl,
+			unsigned char *response, unsigned int *response_len,
+			uint16_t *answers)
+{
+	struct domain_hdr *hdr = (void *) buf;
+	struct domain_question *q;
+	unsigned char *ptr;
+	uint16_t qdcount = ntohs(hdr->qdcount);
+	uint16_t ancount = ntohs(hdr->ancount);
+	int err, i;
+	uint16_t qtype, qclass;
+	unsigned char *next = NULL;
+	unsigned int maxlen = *response_len;
+	GSList *aliases = NULL, *list;
+	char name[NS_MAXDNAME + 1];
+
+	if (buflen < 12)
+		return -EINVAL;
+
+	DBG("qr %d qdcount %d", hdr->qr, qdcount);
+
+	/* We currently only cache responses where question count is 1 */
+	if (hdr->qr != 1 || qdcount != 1)
+		return -EINVAL;
+
+	ptr = buf + sizeof(struct domain_hdr);
+
+	strncpy(question, (char *) ptr, qlen);
+	qlen = strlen(question);
+	ptr += qlen + 1; /* skip \0 */
+
+	q = (void *) ptr;
+	qtype = ntohs(q->type);
+
+	/* We cache only A and AAAA records */
+	if (qtype != 1 && qtype != 28)
+		return -ENOMSG;
+
+	qclass = ntohs(q->class);
+
+	ptr += 2 + 2; /* ptr points now to answers */
+
+	err = -ENOMSG;
+	*response_len = 0;
+	*answers = 0;
+
+	memset(name, 0, sizeof(name));
+
+	/*
+	 * We have a bunch of answers (like A, AAAA, CNAME etc) to
+	 * A or AAAA question. We traverse the answers and parse the
+	 * resource records. Only A and AAAA records are cached, all
+	 * the other records in answers are skipped.
+	 */
+	for (i = 0; i < ancount; i++) {
+		/*
+		 * Get one address at a time to this buffer.
+		 * The max size of the answer is
+		 *   2 (pointer) + 2 (type) + 2 (class) +
+		 *   4 (ttl) + 2 (rdlen) + addr (16 or 4) = 28
+		 * for A or AAAA record.
+		 * For CNAME the size can be bigger.
+		 */
+		unsigned char rsp[NS_MAXCDNAME];
+		unsigned int rsp_len = sizeof(rsp) - 1;
+		int ret, rdlen;
+
+		memset(rsp, 0, sizeof(rsp));
+
+		ret = parse_rr(buf, ptr, buf + buflen, rsp, &rsp_len,
+			type, class, ttl, &rdlen, &next, name);
+		if (ret != 0) {
+			err = ret;
+			goto out;
+		}
+
+		/*
+		 * Now rsp contains compressed or uncompressed resource
+		 * record. Next we check if this record answers the question.
+		 * The name var contains the uncompressed label.
+		 * One tricky bit is the CNAME records as they alias
+		 * the name we might be interested in.
+		 */
+
+		/*
+		 * Go to next answer if the class is not the one we are
+		 * looking for.
+		 */
+		if (*class != qclass) {
+			ptr = next;
+			next = NULL;
+			continue;
+		}
+
+		/*
+		 * Try to resolve aliases also, type is CNAME(5).
+		 * This is important as otherwise the aliased names would not
+		 * be cached at all as the cache would not contain the aliased
+		 * question.
+		 *
+		 * If any CNAME is found in DNS packet, then we cache the alias
+		 * IP address instead of the question (as the server
+		 * said that question has only an alias).
+		 * This means in practice that if e.g., ipv6.google.com is
+		 * queried, DNS server returns CNAME of that name which is
+		 * ipv6.l.google.com. We then cache the address of the CNAME
+		 * but return the question name to client. So the alias
+		 * status of the name is not saved in cache and thus not
+		 * returned to the client. We do not return DNS packets from
+		 * cache to client saying that ipv6.google.com is an alias to
+		 * ipv6.l.google.com but we return instead a DNS packet that
+		 * says ipv6.google.com has address xxx which is in fact the
+		 * address of ipv6.l.google.com. For caching purposes this
+		 * should not cause any issues.
+		 */
+		if (*type == 5 && strncmp(question, name, qlen) == 0) {
+			/*
+			 * So now the alias answered the question. This is
+			 * not very useful from caching point of view as
+			 * the following A or AAAA records will not match the
+			 * question. We need to find the real A/AAAA record
+			 * of the alias and cache that.
+			 */
+			unsigned char *end = NULL;
+			int name_len = 0, output_len = 0;
+
+			memset(rsp, 0, sizeof(rsp));
+			rsp_len = sizeof(rsp) - 1;
+
+			/*
+			 * Alias is in rdata part of the message,
+			 * and next-rdlen points to it. So we need to get
+			 * the real name of the alias.
+			 */
+			ret = get_name(0, buf, next - rdlen, buf + buflen,
+					rsp, rsp_len, &output_len, &end,
+					name, &name_len);
+			if (ret != 0) {
+				/* just ignore the error at this point */
+				ptr = next;
+				next = NULL;
+				continue;
+			}
+
+			/*
+			 * We should now have the alias of the entry we might
+			 * want to cache. Just remember it for a while.
+			 * We check the alias list when we have parsed the
+			 * A or AAAA record.
+			 */
+			aliases = g_slist_prepend(aliases, g_strdup(name));
+
+			ptr = next;
+			next = NULL;
+			continue;
+		}
+
+		if (*type == qtype) {
+			/*
+			 * We found correct type (A or AAAA)
+			 */
+			if (check_alias(aliases, name) ||
+				(!aliases && strncmp(question, name,
+							qlen) == 0)) {
+				/*
+				 * We found an alias or the name of the rr
+				 * matches the question. If so, we append
+				 * the compressed label to the cache.
+				 * The end result is a response buffer that
+				 * will contain one or more cached and
+				 * compressed resource records.
+				 */
+				if (*response_len + rsp_len > maxlen) {
+					err = -ENOBUFS;
+					goto out;
+				}
+				memcpy(response + *response_len, rsp, rsp_len);
+				*response_len += rsp_len;
+				(*answers)++;
+				err = 0;
+			}
+		}
+
+		ptr = next;
+		next = NULL;
+	}
+
+out:
+	for (list = aliases; list; list = list->next)
+		g_free(list->data);
+	g_slist_free(aliases);
+
+	return err;
+}
+
+struct cache_timeout {
+	time_t current_time;
+	int max_timeout;
+	int try_harder;
+};
+
+static gboolean cache_check_entry(gpointer key, gpointer value,
+					gpointer user_data)
+{
+	struct cache_timeout *data = user_data;
+	struct cache_entry *entry = value;
+	int max_timeout;
+
+	/* Scale the number of hits by half as part of cache aging */
+
+	entry->hits /= 2;
+
+	/*
+	 * If either IPv4 or IPv6 cached entry has expired, we
+	 * remove both from the cache.
+	 */
+
+	if (entry->ipv4 && entry->ipv4->timeout > 0) {
+		max_timeout = entry->ipv4->cache_until;
+		if (max_timeout > data->max_timeout)
+			data->max_timeout = max_timeout;
+
+		if (entry->ipv4->cache_until < data->current_time)
+			return TRUE;
+	}
+
+	if (entry->ipv6 && entry->ipv6->timeout > 0) {
+		max_timeout = entry->ipv6->cache_until;
+		if (max_timeout > data->max_timeout)
+			data->max_timeout = max_timeout;
+
+		if (entry->ipv6->cache_until < data->current_time)
+			return TRUE;
+	}
+
+	/*
+	 * if we're asked to try harder, also remove entries that have
+	 * few hits
+	 */
+	if (data->try_harder && entry->hits < 4)
+		return TRUE;
+
+	return FALSE;
+}
+
+static void cache_cleanup(void)
+{
+	static int max_timeout;
+	struct cache_timeout data;
+	int count = 0;
+
+	data.current_time = time(NULL);
+	data.max_timeout = 0;
+	data.try_harder = 0;
+
+	/*
+	 * In the first pass, we only remove entries that have timed out.
+	 * We use a cache of the first time to expire to do this only
+	 * when it makes sense.
+	 */
+	if (max_timeout <= data.current_time) {
+		count = g_hash_table_foreach_remove(cache, cache_check_entry,
+						&data);
+	}
+	DBG("removed %d in the first pass", count);
+
+	/*
+	 * In the second pass, if the first pass turned up blank,
+	 * we also expire entries with a low hit count,
+	 * while aging the hit count at the same time.
+	 */
+	data.try_harder = 1;
+	if (count == 0)
+		count = g_hash_table_foreach_remove(cache, cache_check_entry,
+						&data);
+
+	if (count == 0)
+		/*
+		 * If we could not remove anything, then remember
+		 * what is the max timeout and do nothing if we
+		 * have not yet reached it. This will prevent
+		 * constant traversal of the cache if it is full.
+		 */
+		max_timeout = data.max_timeout;
+	else
+		max_timeout = 0;
+}
+
+static gboolean cache_invalidate_entry(gpointer key, gpointer value,
+					gpointer user_data)
+{
+	struct cache_entry *entry = value;
+
+	/* first, delete any expired elements */
+	cache_enforce_validity(entry);
+
+	/* if anything is not expired, mark the entry for refresh */
+	if (entry->hits > 0 && (entry->ipv4 || entry->ipv6))
+		entry->want_refresh = true;
+
+	/* delete the cached data */
+	if (entry->ipv4) {
+		g_free(entry->ipv4->data);
+		g_free(entry->ipv4);
+		entry->ipv4 = NULL;
+	}
+
+	if (entry->ipv6) {
+		g_free(entry->ipv6->data);
+		g_free(entry->ipv6);
+		entry->ipv6 = NULL;
+	}
+
+	/* keep the entry if we want it refreshed, delete it otherwise */
+	if (entry->want_refresh)
+		return FALSE;
+	else
+		return TRUE;
+}
+
+/*
+ * cache_invalidate is called from places where the DNS landscape
+ * has changed, say because connections are added or we entered a VPN.
+ * The logic is to wipe all cache data, but mark all non-expired
+ * parts of the cache for refresh rather than deleting the whole cache.
+ */
+static void cache_invalidate(void)
+{
+	DBG("Invalidating the DNS cache %p", cache);
+
+	if (!cache)
+		return;
+
+	g_hash_table_foreach_remove(cache, cache_invalidate_entry, NULL);
+}
+
+static void cache_refresh_entry(struct cache_entry *entry)
+{
+
+	cache_enforce_validity(entry);
+
+	if (entry->hits > 2 && !entry->ipv4)
+		entry->want_refresh = true;
+	if (entry->hits > 2 && !entry->ipv6)
+		entry->want_refresh = true;
+
+	if (entry->want_refresh) {
+		char *c;
+		char dns_name[NS_MAXDNAME + 1];
+		entry->want_refresh = false;
+
+		/* turn a DNS name into a hostname with dots */
+		strncpy(dns_name, entry->key, NS_MAXDNAME);
+		c = dns_name;
+		while (c && *c) {
+			int jump;
+			jump = *c;
+			*c = '.';
+			c += jump + 1;
+		}
+		DBG("Refreshing %s\n", dns_name);
+		/* then refresh the hostname */
+		refresh_dns_entry(entry, &dns_name[1]);
+	}
+}
+
+static void cache_refresh_iterator(gpointer key, gpointer value,
+					gpointer user_data)
+{
+	struct cache_entry *entry = value;
+
+	cache_refresh_entry(entry);
+}
+
+static void cache_refresh(void)
+{
+	if (!cache)
+		return;
+
+	g_hash_table_foreach(cache, cache_refresh_iterator, NULL);
+}
+
+static int reply_query_type(unsigned char *msg, int len)
+{
+	unsigned char *c;
+	int l;
+	int type;
+
+	/* skip the header */
+	c = msg + sizeof(struct domain_hdr);
+	len -= sizeof(struct domain_hdr);
+
+	if (len < 0)
+		return 0;
+
+	/* now the query, which is a name and 2 16 bit words */
+	l = dns_name_length(c) + 1;
+	c += l;
+	type = c[0] << 8 | c[1];
+
+	return type;
+}
+
+static int cache_update(struct server_data *srv, unsigned char *msg,
+			unsigned int msg_len)
+{
+	int offset = protocol_offset(srv->protocol);
+	int err, qlen, ttl = 0;
+	uint16_t answers = 0, type = 0, class = 0;
+	struct domain_hdr *hdr = (void *)(msg + offset);
+	struct domain_question *q;
+	struct cache_entry *entry;
+	struct cache_data *data;
+	char question[NS_MAXDNAME + 1];
+	unsigned char response[NS_MAXDNAME + 1];
+	unsigned char *ptr;
+	unsigned int rsplen;
+	bool new_entry = true;
+	time_t current_time;
+
+	if (cache_size >= MAX_CACHE_SIZE) {
+		cache_cleanup();
+		if (cache_size >= MAX_CACHE_SIZE)
+			return 0;
+	}
+
+	current_time = time(NULL);
+
+	/* don't do a cache refresh more than twice a minute */
+	if (next_refresh < current_time) {
+		cache_refresh();
+		next_refresh = current_time + 30;
+	}
+
+	if (offset < 0)
+		return 0;
+
+	DBG("offset %d hdr %p msg %p rcode %d", offset, hdr, msg, hdr->rcode);
+
+	/* Continue only if response code is 0 (=ok) */
+	if (hdr->rcode != ns_r_noerror)
+		return 0;
+
+	if (!cache)
+		create_cache();
+
+	rsplen = sizeof(response) - 1;
+	question[sizeof(question) - 1] = '\0';
+
+	err = parse_response(msg + offset, msg_len - offset,
+				question, sizeof(question) - 1,
+				&type, &class, &ttl,
+				response, &rsplen, &answers);
+
+	/*
+	 * special case: if we do a ipv6 lookup and get no result
+	 * for a record that's already in our ipv4 cache.. we want
+	 * to cache the negative response.
+	 */
+	if ((err == -ENOMSG || err == -ENOBUFS) &&
+			reply_query_type(msg + offset,
+					msg_len - offset) == 28) {
+		entry = g_hash_table_lookup(cache, question);
+		if (entry && entry->ipv4 && !entry->ipv6) {
+			int cache_offset = 0;
+
+			data = g_try_new(struct cache_data, 1);
+			if (!data)
+				return -ENOMEM;
+			data->inserted = entry->ipv4->inserted;
+			data->type = type;
+			data->answers = ntohs(hdr->ancount);
+			data->timeout = entry->ipv4->timeout;
+			if (srv->protocol == IPPROTO_UDP)
+				cache_offset = 2;
+			data->data_len = msg_len + cache_offset;
+			data->data = ptr = g_malloc(data->data_len);
+			ptr[0] = (data->data_len - 2) / 256;
+			ptr[1] = (data->data_len - 2) - ptr[0] * 256;
+			if (srv->protocol == IPPROTO_UDP)
+				ptr += 2;
+			data->valid_until = entry->ipv4->valid_until;
+			data->cache_until = entry->ipv4->cache_until;
+			memcpy(ptr, msg, msg_len);
+			entry->ipv6 = data;
+			/*
+			 * we will get a "hit" when we serve the response
+			 * out of the cache
+			 */
+			entry->hits--;
+			if (entry->hits < 0)
+				entry->hits = 0;
+			return 0;
+		}
+	}
+
+	if (err < 0 || ttl == 0)
+		return 0;
+
+	qlen = strlen(question);
+
+	/*
+	 * If the cache contains already data, check if the
+	 * type of the cached data is the same and do not add
+	 * to cache if data is already there.
+	 * This is needed so that we can cache both A and AAAA
+	 * records for the same name.
+	 */
+	entry = g_hash_table_lookup(cache, question);
+	if (!entry) {
+		entry = g_try_new(struct cache_entry, 1);
+		if (!entry)
+			return -ENOMEM;
+
+		data = g_try_new(struct cache_data, 1);
+		if (!data) {
+			g_free(entry);
+			return -ENOMEM;
+		}
+
+		entry->key = g_strdup(question);
+		entry->ipv4 = entry->ipv6 = NULL;
+		entry->want_refresh = false;
+		entry->hits = 0;
+
+		if (type == 1)
+			entry->ipv4 = data;
+		else
+			entry->ipv6 = data;
+	} else {
+		if (type == 1 && entry->ipv4)
+			return 0;
+
+		if (type == 28 && entry->ipv6)
+			return 0;
+
+		data = g_try_new(struct cache_data, 1);
+		if (!data)
+			return -ENOMEM;
+
+		if (type == 1)
+			entry->ipv4 = data;
+		else
+			entry->ipv6 = data;
+
+		/*
+		 * compensate for the hit we'll get for serving
+		 * the response out of the cache
+		 */
+		entry->hits--;
+		if (entry->hits < 0)
+			entry->hits = 0;
+
+		new_entry = false;
+	}
+
+	if (ttl < MIN_CACHE_TTL)
+		ttl = MIN_CACHE_TTL;
+
+	data->inserted = current_time;
+	data->type = type;
+	data->answers = answers;
+	data->timeout = ttl;
+	/*
+	 * The "2" in start of the length is the TCP offset. We allocate it
+	 * here even for UDP packet because it simplifies the sending
+	 * of cached packet.
+	 */
+	data->data_len = 2 + 12 + qlen + 1 + 2 + 2 + rsplen;
+	data->data = ptr = g_malloc(data->data_len);
+	data->valid_until = current_time + ttl;
+
+	/*
+	 * Restrict the cached DNS record TTL to some sane value
+	 * in order to prevent data staying in the cache too long.
+	 */
+	if (ttl > MAX_CACHE_TTL)
+		ttl = MAX_CACHE_TTL;
+
+	data->cache_until = round_down_ttl(current_time + ttl, ttl);
+
+	if (!data->data) {
+		g_free(entry->key);
+		g_free(data);
+		g_free(entry);
+		return -ENOMEM;
+	}
+
+	/*
+	 * We cache the two extra bytes at the start of the message
+	 * in a TCP packet. When sending UDP packet, we skip the first
+	 * two bytes. This way we do not need to know the format
+	 * (UDP/TCP) of the cached message.
+	 */
+	if (srv->protocol == IPPROTO_UDP)
+		memcpy(ptr + 2, msg, offset + 12);
+	else
+		memcpy(ptr, msg, offset + 12);
+
+	ptr[0] = (data->data_len - 2) / 256;
+	ptr[1] = (data->data_len - 2) - ptr[0] * 256;
+	if (srv->protocol == IPPROTO_UDP)
+		ptr += 2;
+
+	memcpy(ptr + offset + 12, question, qlen + 1); /* copy also the \0 */
+
+	q = (void *) (ptr + offset + 12 + qlen + 1);
+	q->type = htons(type);
+	q->class = htons(class);
+	memcpy(ptr + offset + 12 + qlen + 1 + sizeof(struct domain_question),
+		response, rsplen);
+
+	if (new_entry) {
+		g_hash_table_replace(cache, entry->key, entry);
+		cache_size++;
+	}
+
+	DBG("cache %d %squestion \"%s\" type %d ttl %d size %zd packet %u "
+								"dns len %u",
+		cache_size, new_entry ? "new " : "old ",
+		question, type, ttl,
+		sizeof(*entry) + sizeof(*data) + data->data_len + qlen,
+		data->data_len,
+		srv->protocol == IPPROTO_TCP ?
+			(unsigned int)(data->data[0] * 256 + data->data[1]) :
+			data->data_len);
+
+	return 0;
+}
+
+static int ns_resolv(struct server_data *server, struct request_data *req,
+				gpointer request, gpointer name)
+{
+	GList *list;
+	int sk, err, type = 0;
+	char *dot, *lookup = (char *) name;
+	struct cache_entry *entry;
+
+	entry = cache_check(request, &type, req->protocol);
+	if (entry) {
+		int ttl_left = 0;
+		struct cache_data *data;
+
+		DBG("cache hit %s type %s", lookup, type == 1 ? "A" : "AAAA");
+		if (type == 1)
+			data = entry->ipv4;
+		else
+			data = entry->ipv6;
+
+		if (data) {
+			ttl_left = data->valid_until - time(NULL);
+			entry->hits++;
+		}
+
+		if (data && req->protocol == IPPROTO_TCP) {
+			send_cached_response(req->client_sk, data->data,
+					data->data_len, NULL, 0, IPPROTO_TCP,
+					req->srcid, data->answers, ttl_left);
+			return 1;
+		}
+
+		if (data && req->protocol == IPPROTO_UDP) {
+			int udp_sk = get_req_udp_socket(req);
+
+			if (udp_sk < 0)
+				return -EIO;
+
+			send_cached_response(udp_sk, data->data,
+				data->data_len, &req->sa, req->sa_len,
+				IPPROTO_UDP, req->srcid, data->answers,
+				ttl_left);
+			return 1;
+		}
+	}
+
+	sk = g_io_channel_unix_get_fd(server->channel);
+
+	err = sendto(sk, request, req->request_len, MSG_NOSIGNAL,
+			server->server_addr, server->server_addr_len);
+	if (err < 0) {
+		DBG("Cannot send message to server %s sock %d "
+			"protocol %d (%s/%d)",
+			server->server, sk, server->protocol,
+			strerror(errno), errno);
+		return -EIO;
+	}
+
+	req->numserv++;
+
+	/* If we have more than one dot, we don't add domains */
+	dot = strchr(lookup, '.');
+	if (dot && dot != lookup + strlen(lookup) - 1)
+		return 0;
+
+	if (server->domains && server->domains->data)
+		req->append_domain = true;
+
+	for (list = server->domains; list; list = list->next) {
+		char *domain;
+		unsigned char alt[1024];
+		struct domain_hdr *hdr = (void *) &alt;
+		int altlen, domlen, offset;
+
+		domain = list->data;
+
+		if (!domain)
+			continue;
+
+		offset = protocol_offset(server->protocol);
+		if (offset < 0)
+			return offset;
+
+		domlen = strlen(domain) + 1;
+		if (domlen < 5)
+			return -EINVAL;
+
+		alt[offset] = req->altid & 0xff;
+		alt[offset + 1] = req->altid >> 8;
+
+		memcpy(alt + offset + 2, request + offset + 2, 10);
+		hdr->qdcount = htons(1);
+
+		altlen = append_query(alt + offset + 12, sizeof(alt) - 12,
+					name, domain);
+		if (altlen < 0)
+			return -EINVAL;
+
+		altlen += 12;
+
+		memcpy(alt + offset + altlen,
+			request + offset + altlen - domlen,
+				req->request_len - altlen - offset + domlen);
+
+		if (server->protocol == IPPROTO_TCP) {
+			int req_len = req->request_len + domlen - 2;
+
+			alt[0] = (req_len >> 8) & 0xff;
+			alt[1] = req_len & 0xff;
+		}
+
+		DBG("req %p dstid 0x%04x altid 0x%04x", req, req->dstid,
+				req->altid);
+
+		err = send(sk, alt, req->request_len + domlen, MSG_NOSIGNAL);
+		if (err < 0)
+			return -EIO;
+
+		req->numserv++;
+	}
+
+	return 0;
+}
+
+static char *convert_label(char *start, char *end, char *ptr, char *uptr,
+			int remaining_len, int *used_comp, int *used_uncomp)
+{
+	int pos, comp_pos;
+	char name[NS_MAXLABEL];
+
+	pos = dn_expand((u_char *)start, (u_char *)end, (u_char *)ptr,
+			name, NS_MAXLABEL);
+	if (pos < 0) {
+		DBG("uncompress error [%d/%s]", errno, strerror(errno));
+		goto out;
+	}
+
+	/*
+	 * We need to compress back the name so that we get back to internal
+	 * label presentation.
+	 */
+	comp_pos = dn_comp(name, (u_char *)uptr, remaining_len, NULL, NULL);
+	if (comp_pos < 0) {
+		DBG("compress error [%d/%s]", errno, strerror(errno));
+		goto out;
+	}
+
+	*used_comp = pos;
+	*used_uncomp = comp_pos;
+
+	return ptr;
+
+out:
+	return NULL;
+}
+
+static char *uncompress(int16_t field_count, char *start, char *end,
+			char *ptr, char *uncompressed, int uncomp_len,
+			char **uncompressed_ptr)
+{
+	char *uptr = *uncompressed_ptr; /* position in result buffer */
+
+	DBG("count %d ptr %p end %p uptr %p", field_count, ptr, end, uptr);
+
+	while (field_count-- > 0 && ptr < end) {
+		int dlen;		/* data field length */
+		int ulen;		/* uncompress length */
+		int pos;		/* position in compressed string */
+		char name[NS_MAXLABEL]; /* tmp label */
+		uint16_t dns_type, dns_class;
+		int comp_pos;
+
+		if (!convert_label(start, end, ptr, name, NS_MAXLABEL,
+					&pos, &comp_pos))
+			goto out;
+
+		/*
+		 * Copy the uncompressed resource record, type, class and \0 to
+		 * tmp buffer.
+		 */
+
+		ulen = strlen(name);
+		strncpy(uptr, name, uncomp_len - (uptr - uncompressed));
+
+		DBG("pos %d ulen %d left %d name %s", pos, ulen,
+			(int)(uncomp_len - (uptr - uncompressed)), uptr);
+
+		uptr += ulen;
+		*uptr++ = '\0';
+
+		ptr += pos;
+
+		/*
+		 * We copy also the fixed portion of the result (type, class,
+		 * ttl, address length and the address)
+		 */
+		memcpy(uptr, ptr, NS_RRFIXEDSZ);
+
+		dns_type = uptr[0] << 8 | uptr[1];
+		dns_class = uptr[2] << 8 | uptr[3];
+
+		if (dns_class != ns_c_in)
+			goto out;
+
+		ptr += NS_RRFIXEDSZ;
+		uptr += NS_RRFIXEDSZ;
+
+		/*
+		 * Then the variable portion of the result (data length).
+		 * Typically this portion is also compressed
+		 * so we need to uncompress it also when necessary.
+		 */
+		if (dns_type == ns_t_cname) {
+			if (!convert_label(start, end, ptr, uptr,
+					uncomp_len - (uptr - uncompressed),
+						&pos, &comp_pos))
+				goto out;
+
+			uptr[-2] = comp_pos << 8;
+			uptr[-1] = comp_pos & 0xff;
+
+			uptr += comp_pos;
+			ptr += pos;
+
+		} else if (dns_type == ns_t_a || dns_type == ns_t_aaaa) {
+			dlen = uptr[-2] << 8 | uptr[-1];
+
+			if (ptr + dlen > end) {
+				DBG("data len %d too long", dlen);
+				goto out;
+			}
+
+			memcpy(uptr, ptr, dlen);
+			uptr += dlen;
+			ptr += dlen;
+
+		} else if (dns_type == ns_t_soa) {
+			int total_len = 0;
+			char *len_ptr;
+
+			/* Primary name server expansion */
+			if (!convert_label(start, end, ptr, uptr,
+					uncomp_len - (uptr - uncompressed),
+						&pos, &comp_pos))
+				goto out;
+
+			total_len += comp_pos;
+			len_ptr = &uptr[-2];
+			ptr += pos;
+			uptr += comp_pos;
+
+			/* Responsible authority's mailbox */
+			if (!convert_label(start, end, ptr, uptr,
+					uncomp_len - (uptr - uncompressed),
+						&pos, &comp_pos))
+				goto out;
+
+			total_len += comp_pos;
+			ptr += pos;
+			uptr += comp_pos;
+
+			/*
+			 * Copy rest of the soa fields (serial number,
+			 * refresh interval, retry interval, expiration
+			 * limit and minimum ttl). They are 20 bytes long.
+			 */
+			memcpy(uptr, ptr, 20);
+			uptr += 20;
+			ptr += 20;
+			total_len += 20;
+
+			/*
+			 * Finally fix the length of the data part
+			 */
+			len_ptr[0] = total_len << 8;
+			len_ptr[1] = total_len & 0xff;
+		}
+
+		*uncompressed_ptr = uptr;
+	}
+
+	return ptr;
+
+out:
+	return NULL;
+}
+
+static int strip_domains(char *name, char *answers, int maxlen)
+{
+	uint16_t data_len;
+	int name_len = strlen(name);
+	char *ptr, *start = answers, *end = answers + maxlen;
+
+	while (maxlen > 0) {
+		ptr = strstr(answers, name);
+		if (ptr) {
+			char *domain = ptr + name_len;
+
+			if (*domain) {
+				int domain_len = strlen(domain);
+
+				memmove(answers + name_len,
+					domain + domain_len,
+					end - (domain + domain_len));
+
+				end -= domain_len;
+				maxlen -= domain_len;
+			}
+		}
+
+		answers += strlen(answers) + 1;
+		answers += 2 + 2 + 4;  /* skip type, class and ttl fields */
+
+		data_len = answers[0] << 8 | answers[1];
+		answers += 2; /* skip the length field */
+
+		if (answers + data_len > end)
+			return -EINVAL;
+
+		answers += data_len;
+		maxlen -= answers - ptr;
+	}
+
+	return end - start;
+}
+
+static int forward_dns_reply(unsigned char *reply, int reply_len, int protocol,
+				struct server_data *data)
+{
+	struct domain_hdr *hdr;
+	struct request_data *req;
+	int dns_id, sk, err, offset = protocol_offset(protocol);
+
+	if (offset < 0)
+		return offset;
+
+	hdr = (void *)(reply + offset);
+	dns_id = reply[offset] | reply[offset + 1] << 8;
+
+	DBG("Received %d bytes (id 0x%04x)", reply_len, dns_id);
+
+	req = find_request(dns_id);
+	if (!req)
+		return -EINVAL;
+
+	DBG("req %p dstid 0x%04x altid 0x%04x rcode %d",
+			req, req->dstid, req->altid, hdr->rcode);
+
+	reply[offset] = req->srcid & 0xff;
+	reply[offset + 1] = req->srcid >> 8;
+
+	req->numresp++;
+
+	if (hdr->rcode == ns_r_noerror || !req->resp) {
+		unsigned char *new_reply = NULL;
+
+		/*
+		 * If the domain name was append
+		 * remove it before forwarding the reply.
+		 * If there were more than one question, then this
+		 * domain name ripping can be hairy so avoid that
+		 * and bail out in that that case.
+		 *
+		 * The reason we are doing this magic is that if the
+		 * user's DNS client tries to resolv hostname without
+		 * domain part, it also expects to get the result without
+		 * a domain name part.
+		 */
+		if (req->append_domain && ntohs(hdr->qdcount) == 1) {
+			uint16_t domain_len = 0;
+			uint16_t header_len;
+			uint16_t dns_type, dns_class;
+			uint8_t host_len, dns_type_pos;
+			char uncompressed[NS_MAXDNAME], *uptr;
+			char *ptr, *eom = (char *)reply + reply_len;
+
+			/*
+			 * ptr points to the first char of the hostname.
+			 * ->hostname.domain.net
+			 */
+			header_len = offset + sizeof(struct domain_hdr);
+			ptr = (char *)reply + header_len;
+
+			host_len = *ptr;
+			if (host_len > 0)
+				domain_len = strnlen(ptr + 1 + host_len,
+						reply_len - header_len);
+
+			/*
+			 * If the query type is anything other than A or AAAA,
+			 * then bail out and pass the message as is.
+			 * We only want to deal with IPv4 or IPv6 addresses.
+			 */
+			dns_type_pos = host_len + 1 + domain_len + 1;
+
+			dns_type = ptr[dns_type_pos] << 8 |
+							ptr[dns_type_pos + 1];
+			dns_class = ptr[dns_type_pos + 2] << 8 |
+							ptr[dns_type_pos + 3];
+			if (dns_type != ns_t_a && dns_type != ns_t_aaaa &&
+					dns_class != ns_c_in) {
+				DBG("Pass msg dns type %d class %d",
+					dns_type, dns_class);
+				goto pass;
+			}
+
+			/*
+			 * Remove the domain name and replace it by the end
+			 * of reply. Check if the domain is really there
+			 * before trying to copy the data. We also need to
+			 * uncompress the answers if necessary.
+			 * The domain_len can be 0 because if the original
+			 * query did not contain a domain name, then we are
+			 * sending two packets, first without the domain name
+			 * and the second packet with domain name.
+			 * The append_domain is set to true even if we sent
+			 * the first packet without domain name. In this
+			 * case we end up in this branch.
+			 */
+			if (domain_len > 0) {
+				int len = host_len + 1;
+				int new_len, fixed_len;
+				char *answers;
+
+				/*
+				 * First copy host (without domain name) into
+				 * tmp buffer.
+				 */
+				uptr = &uncompressed[0];
+				memcpy(uptr, ptr, len);
+
+				uptr[len] = '\0'; /* host termination */
+				uptr += len + 1;
+
+				/*
+				 * Copy type and class fields of the question.
+				 */
+				ptr += len + domain_len + 1;
+				memcpy(uptr, ptr, NS_QFIXEDSZ);
+
+				/*
+				 * ptr points to answers after this
+				 */
+				ptr += NS_QFIXEDSZ;
+				uptr += NS_QFIXEDSZ;
+				answers = uptr;
+				fixed_len = answers - uncompressed;
+
+				/*
+				 * We then uncompress the result to buffer
+				 * so that we can rip off the domain name
+				 * part from the question. First answers,
+				 * then name server (authority) information,
+				 * and finally additional record info.
+				 */
+
+				ptr = uncompress(ntohs(hdr->ancount),
+						(char *)reply + offset, eom,
+						ptr, uncompressed, NS_MAXDNAME,
+						&uptr);
+				if (ptr == NULL)
+					goto out;
+
+				ptr = uncompress(ntohs(hdr->nscount),
+						(char *)reply + offset, eom,
+						ptr, uncompressed, NS_MAXDNAME,
+						&uptr);
+				if (ptr == NULL)
+					goto out;
+
+				ptr = uncompress(ntohs(hdr->arcount),
+						(char *)reply + offset, eom,
+						ptr, uncompressed, NS_MAXDNAME,
+						&uptr);
+				if (ptr == NULL)
+					goto out;
+
+				/*
+				 * The uncompressed buffer now contains almost
+				 * valid response. Final step is to get rid of
+				 * the domain name because at least glibc
+				 * gethostbyname() implementation does extra
+				 * checks and expects to find an answer without
+				 * domain name if we asked a query without
+				 * domain part. Note that glibc getaddrinfo()
+				 * works differently and accepts FQDN in answer
+				 */
+				new_len = strip_domains(uncompressed, answers,
+							uptr - answers);
+				if (new_len < 0) {
+					DBG("Corrupted packet");
+					return -EINVAL;
+				}
+
+				/*
+				 * Because we have now uncompressed the answers
+				 * we might have to create a bigger buffer to
+				 * hold all that data.
+				 */
+
+				reply_len = header_len + new_len + fixed_len;
+
+				new_reply = g_try_malloc(reply_len);
+				if (!new_reply)
+					return -ENOMEM;
+
+				memcpy(new_reply, reply, header_len);
+				memcpy(new_reply + header_len, uncompressed,
+					new_len + fixed_len);
+
+				reply = new_reply;
+			}
+		}
+
+	pass:
+		g_free(req->resp);
+		req->resplen = 0;
+
+		req->resp = g_try_malloc(reply_len);
+		if (!req->resp)
+			return -ENOMEM;
+
+		memcpy(req->resp, reply, reply_len);
+		req->resplen = reply_len;
+
+		cache_update(data, reply, reply_len);
+
+		g_free(new_reply);
+	}
+
+out:
+	if (req->numresp < req->numserv) {
+		if (hdr->rcode > ns_r_noerror) {
+			return -EINVAL;
+		} else if (hdr->ancount == 0 && req->append_domain) {
+			return -EINVAL;
+		}
+	}
+
+	request_list = g_slist_remove(request_list, req);
+
+	if (protocol == IPPROTO_UDP) {
+		sk = get_req_udp_socket(req);
+		if (sk < 0) {
+			errno = -EIO;
+			err = -EIO;
+		} else
+			err = sendto(sk, req->resp, req->resplen, 0,
+				&req->sa, req->sa_len);
+	} else {
+		sk = req->client_sk;
+		err = send(sk, req->resp, req->resplen, MSG_NOSIGNAL);
+	}
+
+	if (err < 0)
+		DBG("Cannot send msg, sk %d proto %d errno %d/%s", sk,
+			protocol, errno, strerror(errno));
+	else
+		DBG("proto %d sent %d bytes to %d", protocol, err, sk);
+
+	destroy_request_data(req);
+
+	return err;
+}
+
+static void server_destroy_socket(struct server_data *data)
+{
+	DBG("index %d server %s proto %d", data->index,
+					data->server, data->protocol);
+
+	if (data->watch > 0) {
+		g_source_remove(data->watch);
+		data->watch = 0;
+	}
+
+	if (data->timeout > 0) {
+		g_source_remove(data->timeout);
+		data->timeout = 0;
+	}
+
+	if (data->channel) {
+		g_io_channel_shutdown(data->channel, TRUE, NULL);
+		g_io_channel_unref(data->channel);
+		data->channel = NULL;
+	}
+
+	g_free(data->incoming_reply);
+	data->incoming_reply = NULL;
+}
+
+static void destroy_server(struct server_data *server)
+{
+	DBG("index %d server %s sock %d", server->index, server->server,
+			server->channel ?
+			g_io_channel_unix_get_fd(server->channel): -1);
+
+	server_list = g_slist_remove(server_list, server);
+	server_destroy_socket(server);
+
+	if (server->protocol == IPPROTO_UDP && server->enabled)
+		DBG("Removing DNS server %s", server->server);
+
+	g_free(server->server);
+	g_list_free_full(server->domains, g_free);
+	g_free(server->server_addr);
+
+	/*
+	 * We do not remove cache right away but delay it few seconds.
+	 * The idea is that when IPv6 DNS server is added via RDNSS, it has a
+	 * lifetime. When the lifetime expires we decrease the refcount so it
+	 * is possible that the cache is then removed. Because a new DNS server
+	 * is usually created almost immediately we would then loose the cache
+	 * without any good reason. The small delay allows the new RDNSS to
+	 * create a new DNS server instance and the refcount does not go to 0.
+	 */
+	if (cache && !cache_timer)
+		cache_timer = g_timeout_add_seconds(3, try_remove_cache, NULL);
+
+	g_free(server);
+}
+
+static gboolean udp_server_event(GIOChannel *channel, GIOCondition condition,
+							gpointer user_data)
+{
+	unsigned char buf[4096];
+	int sk, err, len;
+	struct server_data *data = user_data;
+
+	if (condition & (G_IO_NVAL | G_IO_ERR | G_IO_HUP)) {
+		connman_error("Error with UDP server %s", data->server);
+		server_destroy_socket(data);
+		return FALSE;
+	}
+
+	sk = g_io_channel_unix_get_fd(channel);
+
+	len = recv(sk, buf, sizeof(buf), 0);
+	if (len < 12)
+		return TRUE;
+
+	err = forward_dns_reply(buf, len, IPPROTO_UDP, data);
+	if (err < 0)
+		return TRUE;
+
+	return TRUE;
+}
+
+static gboolean tcp_server_event(GIOChannel *channel, GIOCondition condition,
+							gpointer user_data)
+{
+	int sk;
+	struct server_data *server = user_data;
+
+	sk = g_io_channel_unix_get_fd(channel);
+	if (sk == 0)
+		return FALSE;
+
+	if (condition & (G_IO_NVAL | G_IO_ERR | G_IO_HUP)) {
+		GSList *list;
+hangup:
+		DBG("TCP server channel closed, sk %d", sk);
+
+		/*
+		 * Discard any partial response which is buffered; better
+		 * to get a proper response from a working server.
+		 */
+		g_free(server->incoming_reply);
+		server->incoming_reply = NULL;
+
+		for (list = request_list; list; list = list->next) {
+			struct request_data *req = list->data;
+			struct domain_hdr *hdr;
+
+			if (req->protocol == IPPROTO_UDP)
+				continue;
+
+			if (!req->request)
+				continue;
+
+			/*
+			 * If we're not waiting for any further response
+			 * from another name server, then we send an error
+			 * response to the client.
+			 */
+			if (req->numserv && --(req->numserv))
+				continue;
+
+			hdr = (void *) (req->request + 2);
+			hdr->id = req->srcid;
+			send_response(req->client_sk, req->request,
+				req->request_len, NULL, 0, IPPROTO_TCP);
+
+			request_list = g_slist_remove(request_list, req);
+		}
+
+		destroy_server(server);
+
+		return FALSE;
+	}
+
+	if ((condition & G_IO_OUT) && !server->connected) {
+		GSList *list;
+		GList *domains;
+		bool no_request_sent = true;
+		struct server_data *udp_server;
+
+		udp_server = find_server(server->index, server->server,
+								IPPROTO_UDP);
+		if (udp_server) {
+			for (domains = udp_server->domains; domains;
+						domains = domains->next) {
+				char *dom = domains->data;
+
+				DBG("Adding domain %s to %s",
+						dom, server->server);
+
+				server->domains = g_list_append(server->domains,
+								g_strdup(dom));
+			}
+		}
+
+		server->connected = true;
+		server_list = g_slist_append(server_list, server);
+
+		if (server->timeout > 0) {
+			g_source_remove(server->timeout);
+			server->timeout = 0;
+		}
+
+		for (list = request_list; list; ) {
+			struct request_data *req = list->data;
+			int status;
+
+			if (req->protocol == IPPROTO_UDP) {
+				list = list->next;
+				continue;
+			}
+
+			DBG("Sending req %s over TCP", (char *)req->name);
+
+			status = ns_resolv(server, req,
+						req->request, req->name);
+			if (status > 0) {
+				/*
+				 * A cached result was sent,
+				 * so the request can be released
+				 */
+				list = list->next;
+				request_list = g_slist_remove(request_list, req);
+				destroy_request_data(req);
+				continue;
+			}
+
+			if (status < 0) {
+				list = list->next;
+				continue;
+			}
+
+			no_request_sent = false;
+
+			if (req->timeout > 0)
+				g_source_remove(req->timeout);
+
+			req->timeout = g_timeout_add_seconds(30,
+						request_timeout, req);
+			list = list->next;
+		}
+
+		if (no_request_sent) {
+			destroy_server(server);
+			return FALSE;
+		}
+
+	} else if (condition & G_IO_IN) {
+		struct partial_reply *reply = server->incoming_reply;
+		int bytes_recv;
+
+		if (!reply) {
+			unsigned char reply_len_buf[2];
+			uint16_t reply_len;
+
+			bytes_recv = recv(sk, reply_len_buf, 2, MSG_PEEK);
+			if (!bytes_recv) {
+				goto hangup;
+			} else if (bytes_recv < 0) {
+				if (errno == EAGAIN || errno == EWOULDBLOCK)
+					return TRUE;
+
+				connman_error("DNS proxy error %s",
+						strerror(errno));
+				goto hangup;
+			} else if (bytes_recv < 2)
+				return TRUE;
+
+			reply_len = reply_len_buf[1] | reply_len_buf[0] << 8;
+			reply_len += 2;
+
+			DBG("TCP reply %d bytes from %d", reply_len, sk);
+
+			reply = g_try_malloc(sizeof(*reply) + reply_len + 2);
+			if (!reply)
+				return TRUE;
+
+			reply->len = reply_len;
+			reply->received = 0;
+
+			server->incoming_reply = reply;
+		}
+
+		while (reply->received < reply->len) {
+			bytes_recv = recv(sk, reply->buf + reply->received,
+					reply->len - reply->received, 0);
+			if (!bytes_recv) {
+				connman_error("DNS proxy TCP disconnect");
+				break;
+			} else if (bytes_recv < 0) {
+				if (errno == EAGAIN || errno == EWOULDBLOCK)
+					return TRUE;
+
+				connman_error("DNS proxy error %s",
+						strerror(errno));
+				break;
+			}
+			reply->received += bytes_recv;
+		}
+
+		forward_dns_reply(reply->buf, reply->received, IPPROTO_TCP,
+					server);
+
+		g_free(reply);
+		server->incoming_reply = NULL;
+
+		destroy_server(server);
+
+		return FALSE;
+	}
+
+	return TRUE;
+}
+
+static gboolean tcp_idle_timeout(gpointer user_data)
+{
+	struct server_data *server = user_data;
+
+	DBG("");
+
+	if (!server)
+		return FALSE;
+
+	destroy_server(server);
+
+	return FALSE;
+}
+
+static int server_create_socket(struct server_data *data)
+{
+	int sk, err;
+	char *interface;
+
+	DBG("index %d server %s proto %d", data->index,
+					data->server, data->protocol);
+
+	sk = socket(data->server_addr->sa_family,
+		data->protocol == IPPROTO_TCP ? SOCK_STREAM : SOCK_DGRAM,
+		data->protocol);
+	if (sk < 0) {
+		err = errno;
+		connman_error("Failed to create server %s socket",
+							data->server);
+		server_destroy_socket(data);
+		return -err;
+	}
+
+	DBG("sk %d", sk);
+
+	interface = connman_inet_ifname(data->index);
+	if (interface) {
+		if (setsockopt(sk, SOL_SOCKET, SO_BINDTODEVICE,
+					interface,
+					strlen(interface) + 1) < 0) {
+			err = errno;
+			connman_error("Failed to bind server %s "
+						"to interface %s",
+						data->server, interface);
+			close(sk);
+			server_destroy_socket(data);
+			g_free(interface);
+			return -err;
+		}
+		g_free(interface);
+	}
+
+	data->channel = g_io_channel_unix_new(sk);
+	if (!data->channel) {
+		connman_error("Failed to create server %s channel",
+							data->server);
+		close(sk);
+		server_destroy_socket(data);
+		return -ENOMEM;
+	}
+
+	g_io_channel_set_close_on_unref(data->channel, TRUE);
+
+	if (data->protocol == IPPROTO_TCP) {
+		g_io_channel_set_flags(data->channel, G_IO_FLAG_NONBLOCK, NULL);
+		data->watch = g_io_add_watch(data->channel,
+			G_IO_OUT | G_IO_IN | G_IO_HUP | G_IO_NVAL | G_IO_ERR,
+						tcp_server_event, data);
+		data->timeout = g_timeout_add_seconds(30, tcp_idle_timeout,
+								data);
+	} else
+		data->watch = g_io_add_watch(data->channel,
+			G_IO_IN | G_IO_NVAL | G_IO_ERR | G_IO_HUP,
+						udp_server_event, data);
+
+	if (connect(sk, data->server_addr, data->server_addr_len) < 0) {
+		err = errno;
+
+		if ((data->protocol == IPPROTO_TCP && errno != EINPROGRESS) ||
+				data->protocol == IPPROTO_UDP) {
+
+			connman_error("Failed to connect to server %s",
+								data->server);
+			server_destroy_socket(data);
+			return -err;
+		}
+	}
+
+	create_cache();
+
+	return 0;
+}
+
+static struct server_data *create_server(int index,
+					const char *domain, const char *server,
+					int protocol)
+{
+	struct server_data *data;
+	struct addrinfo hints, *rp;
+	int ret;
+
+	DBG("index %d server %s", index, server);
+
+	data = g_try_new0(struct server_data, 1);
+	if (!data) {
+		connman_error("Failed to allocate server %s data", server);
+		return NULL;
+	}
+
+	data->index = index;
+	if (domain)
+		data->domains = g_list_append(data->domains, g_strdup(domain));
+	data->server = g_strdup(server);
+	data->protocol = protocol;
+
+	memset(&hints, 0, sizeof(hints));
+
+	switch (protocol) {
+	case IPPROTO_UDP:
+		hints.ai_socktype = SOCK_DGRAM;
+		break;
+
+	case IPPROTO_TCP:
+		hints.ai_socktype = SOCK_STREAM;
+		break;
+
+	default:
+		destroy_server(data);
+		return NULL;
+	}
+	hints.ai_family = AF_UNSPEC;
+	hints.ai_flags = AI_NUMERICSERV | AI_NUMERICHOST;
+
+	ret = getaddrinfo(data->server, "53", &hints, &rp);
+	if (ret) {
+		connman_error("Failed to parse server %s address: %s\n",
+			      data->server, gai_strerror(ret));
+		destroy_server(data);
+		return NULL;
+	}
+
+	/* Do not blindly copy this code elsewhere; it doesn't loop over the
+	   results using ->ai_next as it should. That's OK in *this* case
+	   because it was a numeric lookup; we *know* there's only one. */
+
+	data->server_addr_len = rp->ai_addrlen;
+
+	switch (rp->ai_family) {
+	case AF_INET:
+		data->server_addr = (struct sockaddr *)
+					g_try_new0(struct sockaddr_in, 1);
+		break;
+	case AF_INET6:
+		data->server_addr = (struct sockaddr *)
+					g_try_new0(struct sockaddr_in6, 1);
+		break;
+	default:
+		connman_error("Wrong address family %d", rp->ai_family);
+		break;
+	}
+	if (!data->server_addr) {
+		freeaddrinfo(rp);
+		destroy_server(data);
+		return NULL;
+	}
+	memcpy(data->server_addr, rp->ai_addr, rp->ai_addrlen);
+	freeaddrinfo(rp);
+
+	if (server_create_socket(data) != 0) {
+		destroy_server(data);
+		return NULL;
+	}
+
+	if (protocol == IPPROTO_UDP) {
+		if (__connman_service_index_is_default(data->index) ||
+				__connman_service_index_is_split_routing(
+								data->index)) {
+			data->enabled = true;
+			DBG("Adding DNS server %s", data->server);
+		}
+
+		server_list = g_slist_append(server_list, data);
+	}
+
+	return data;
+}
+
+static bool resolv(struct request_data *req,
+				gpointer request, gpointer name)
+{
+	GSList *list;
+
+	for (list = server_list; list; list = list->next) {
+		struct server_data *data = list->data;
+
+		if (data->protocol == IPPROTO_TCP) {
+			DBG("server %s ignored proto TCP", data->server);
+			continue;
+		}
+
+		DBG("server %s enabled %d", data->server, data->enabled);
+
+		if (!data->enabled)
+			continue;
+
+		if (!data->channel && data->protocol == IPPROTO_UDP) {
+			if (server_create_socket(data) < 0) {
+				DBG("socket creation failed while resolving");
+				continue;
+			}
+		}
+
+		if (ns_resolv(data, req, request, name) > 0)
+			return true;
+	}
+
+	return false;
+}
+
+static void append_domain(int index, const char *domain)
+{
+	GSList *list;
+
+	DBG("index %d domain %s", index, domain);
+
+	if (!domain)
+		return;
+
+	for (list = server_list; list; list = list->next) {
+		struct server_data *data = list->data;
+		GList *dom_list;
+		char *dom;
+		bool dom_found = false;
+
+		if (data->index < 0)
+			continue;
+
+		if (data->index != index)
+			continue;
+
+		for (dom_list = data->domains; dom_list;
+				dom_list = dom_list->next) {
+			dom = dom_list->data;
+
+			if (g_str_equal(dom, domain)) {
+				dom_found = true;
+				break;
+			}
+		}
+
+		if (!dom_found) {
+			data->domains =
+				g_list_append(data->domains, g_strdup(domain));
+		}
+	}
+}
+
+static void flush_requests(struct server_data *server)
+{
+	GSList *list;
+
+	list = request_list;
+	while (list) {
+		struct request_data *req = list->data;
+
+		list = list->next;
+
+		if (ns_resolv(server, req, req->request, req->name)) {
+			/*
+			 * A cached result was sent,
+			 * so the request can be released
+			 */
+			request_list =
+				g_slist_remove(request_list, req);
+			destroy_request_data(req);
+			continue;
+		}
+
+		if (req->timeout > 0)
+			g_source_remove(req->timeout);
+
+		req->timeout = g_timeout_add_seconds(5, request_timeout, req);
+	}
+}
+
+int __connman_dnsproxy_append(int index, const char *domain,
+							const char *server)
+{
+	struct server_data *data;
+
+	DBG("index %d server %s", index, server);
+
+	if (!server && !domain)
+		return -EINVAL;
+
+	if (!server) {
+		append_domain(index, domain);
+
+		return 0;
+	}
+
+	if (g_str_equal(server, "127.0.0.1"))
+		return -ENODEV;
+
+	if (g_str_equal(server, "::1"))
+		return -ENODEV;
+
+	data = find_server(index, server, IPPROTO_UDP);
+	if (data) {
+		append_domain(index, domain);
+		return 0;
+	}
+
+	data = create_server(index, domain, server, IPPROTO_UDP);
+	if (!data)
+		return -EIO;
+
+	flush_requests(data);
+
+	return 0;
+}
+
+static void remove_server(int index, const char *domain,
+			const char *server, int protocol)
+{
+	struct server_data *data;
+
+	data = find_server(index, server, protocol);
+	if (!data)
+		return;
+
+	destroy_server(data);
+}
+
+int __connman_dnsproxy_remove(int index, const char *domain,
+							const char *server)
+{
+	DBG("index %d server %s", index, server);
+
+	if (!server)
+		return -EINVAL;
+
+	if (g_str_equal(server, "127.0.0.1"))
+		return -ENODEV;
+
+	if (g_str_equal(server, "::1"))
+		return -ENODEV;
+
+	remove_server(index, domain, server, IPPROTO_UDP);
+	remove_server(index, domain, server, IPPROTO_TCP);
+
+	return 0;
+}
+
+static void dnsproxy_offline_mode(bool enabled)
+{
+	GSList *list;
+
+	DBG("enabled %d", enabled);
+
+	for (list = server_list; list; list = list->next) {
+		struct server_data *data = list->data;
+
+		if (!enabled) {
+			DBG("Enabling DNS server %s", data->server);
+			data->enabled = true;
+			cache_invalidate();
+			cache_refresh();
+		} else {
+			DBG("Disabling DNS server %s", data->server);
+			data->enabled = false;
+			cache_invalidate();
+		}
+	}
+}
+
+static void dnsproxy_default_changed(struct connman_service *service)
+{
+	GSList *list;
+	int index;
+
+	DBG("service %p", service);
+
+	/* DNS has changed, invalidate the cache */
+	cache_invalidate();
+
+	if (!service) {
+		/* When no services are active, then disable DNS proxying */
+		dnsproxy_offline_mode(true);
+		return;
+	}
+
+	index = __connman_service_get_index(service);
+	if (index < 0)
+		return;
+
+	for (list = server_list; list; list = list->next) {
+		struct server_data *data = list->data;
+
+		if (data->index == index) {
+			DBG("Enabling DNS server %s", data->server);
+			data->enabled = true;
+		} else {
+			DBG("Disabling DNS server %s", data->server);
+			data->enabled = false;
+		}
+	}
+
+	cache_refresh();
+}
+
+static struct connman_notifier dnsproxy_notifier = {
+	.name			= "dnsproxy",
+	.default_changed	= dnsproxy_default_changed,
+	.offline_mode		= dnsproxy_offline_mode,
+};
+
+static unsigned char opt_edns0_type[2] = { 0x00, 0x29 };
+
+static int parse_request(unsigned char *buf, int len,
+					char *name, unsigned int size)
+{
+	struct domain_hdr *hdr = (void *) buf;
+	uint16_t qdcount = ntohs(hdr->qdcount);
+	uint16_t arcount = ntohs(hdr->arcount);
+	unsigned char *ptr;
+	char *last_label = NULL;
+	unsigned int remain, used = 0;
+
+	if (len < 12)
+		return -EINVAL;
+
+	DBG("id 0x%04x qr %d opcode %d qdcount %d arcount %d",
+					hdr->id, hdr->qr, hdr->opcode,
+							qdcount, arcount);
+
+	if (hdr->qr != 0 || qdcount != 1)
+		return -EINVAL;
+
+	name[0] = '\0';
+
+	ptr = buf + sizeof(struct domain_hdr);
+	remain = len - sizeof(struct domain_hdr);
+
+	while (remain > 0) {
+		uint8_t label_len = *ptr;
+
+		if (label_len == 0x00) {
+			last_label = (char *) (ptr + 1);
+			break;
+		}
+
+		if (used + label_len + 1 > size)
+			return -ENOBUFS;
+
+		strncat(name, (char *) (ptr + 1), label_len);
+		strcat(name, ".");
+
+		used += label_len + 1;
+
+		ptr += label_len + 1;
+		remain -= label_len + 1;
+	}
+
+	if (last_label && arcount && remain >= 9 && last_label[4] == 0 &&
+				!memcmp(last_label + 5, opt_edns0_type, 2)) {
+		uint16_t edns0_bufsize;
+
+		edns0_bufsize = last_label[7] << 8 | last_label[8];
+
+		DBG("EDNS0 buffer size %u", edns0_bufsize);
+
+		/* This is an evil hack until full TCP support has been
+		 * implemented.
+		 *
+		 * Somtimes the EDNS0 request gets send with a too-small
+		 * buffer size. Since glibc doesn't seem to crash when it
+		 * gets a response biffer then it requested, just bump
+		 * the buffer size up to 4KiB.
+		 */
+		if (edns0_bufsize < 0x1000) {
+			last_label[7] = 0x10;
+			last_label[8] = 0x00;
+		}
+	}
+
+	DBG("query %s", name);
+
+	return 0;
+}
+
+static void client_reset(struct tcp_partial_client_data *client)
+{
+	if (!client)
+		return;
+
+	if (client->channel) {
+		DBG("client %d closing",
+			g_io_channel_unix_get_fd(client->channel));
+
+		g_io_channel_unref(client->channel);
+		client->channel = NULL;
+	}
+
+	if (client->watch > 0) {
+		g_source_remove(client->watch);
+		client->watch = 0;
+	}
+
+	if (client->timeout > 0) {
+		g_source_remove(client->timeout);
+		client->timeout = 0;
+	}
+
+	g_free(client->buf);
+	client->buf = NULL;
+
+	client->buf_end = 0;
+}
+
+static unsigned int get_msg_len(unsigned char *buf)
+{
+	return buf[0]<<8 | buf[1];
+}
+
+static bool read_tcp_data(struct tcp_partial_client_data *client,
+				void *client_addr, socklen_t client_addr_len,
+				int read_len)
+{
+	char query[TCP_MAX_BUF_LEN];
+	struct request_data *req;
+	int client_sk, err;
+	unsigned int msg_len;
+	GSList *list;
+	bool waiting_for_connect = false;
+	int qtype = 0;
+	struct cache_entry *entry;
+
+	client_sk = g_io_channel_unix_get_fd(client->channel);
+
+	if (read_len == 0) {
+		DBG("client %d closed, pending %d bytes",
+			client_sk, client->buf_end);
+		g_hash_table_remove(partial_tcp_req_table,
+					GINT_TO_POINTER(client_sk));
+		return false;
+	}
+
+	DBG("client %d received %d bytes", client_sk, read_len);
+
+	client->buf_end += read_len;
+
+	if (client->buf_end < 2)
+		return true;
+
+	msg_len = get_msg_len(client->buf);
+	if (msg_len > TCP_MAX_BUF_LEN) {
+		DBG("client %d sent too much data %d", client_sk, msg_len);
+		g_hash_table_remove(partial_tcp_req_table,
+					GINT_TO_POINTER(client_sk));
+		return false;
+	}
+
+read_another:
+	DBG("client %d msg len %d end %d past end %d", client_sk, msg_len,
+		client->buf_end, client->buf_end - (msg_len + 2));
+
+	if (client->buf_end < (msg_len + 2)) {
+		DBG("client %d still missing %d bytes",
+			client_sk,
+			msg_len + 2 - client->buf_end);
+		return true;
+	}
+
+	DBG("client %d all data %d received", client_sk, msg_len);
+
+	err = parse_request(client->buf + 2, msg_len,
+			query, sizeof(query));
+	if (err < 0 || (g_slist_length(server_list) == 0)) {
+		send_response(client_sk, client->buf, msg_len + 2,
+			NULL, 0, IPPROTO_TCP);
+		return true;
+	}
+
+	req = g_try_new0(struct request_data, 1);
+	if (!req)
+		return true;
+
+	memcpy(&req->sa, client_addr, client_addr_len);
+	req->sa_len = client_addr_len;
+	req->client_sk = client_sk;
+	req->protocol = IPPROTO_TCP;
+	req->family = client->family;
+
+	req->srcid = client->buf[2] | (client->buf[3] << 8);
+	req->dstid = get_id();
+	req->altid = get_id();
+	req->request_len = msg_len + 2;
+
+	client->buf[2] = req->dstid & 0xff;
+	client->buf[3] = req->dstid >> 8;
+
+	req->numserv = 0;
+	req->ifdata = client->ifdata;
+	req->append_domain = false;
+
+	/*
+	 * Check if the answer is found in the cache before
+	 * creating sockets to the server.
+	 */
+	entry = cache_check(client->buf, &qtype, IPPROTO_TCP);
+	if (entry) {
+		int ttl_left = 0;
+		struct cache_data *data;
+
+		DBG("cache hit %s type %s", query, qtype == 1 ? "A" : "AAAA");
+		if (qtype == 1)
+			data = entry->ipv4;
+		else
+			data = entry->ipv6;
+
+		if (data) {
+			ttl_left = data->valid_until - time(NULL);
+			entry->hits++;
+
+			send_cached_response(client_sk, data->data,
+					data->data_len, NULL, 0, IPPROTO_TCP,
+					req->srcid, data->answers, ttl_left);
+
+			g_free(req);
+			goto out;
+		} else
+			DBG("data missing, ignoring cache for this query");
+	}
+
+	for (list = server_list; list; list = list->next) {
+		struct server_data *data = list->data;
+
+		if (data->protocol != IPPROTO_UDP || !data->enabled)
+			continue;
+
+		if (!create_server(data->index, NULL, data->server,
+					IPPROTO_TCP))
+			continue;
+
+		waiting_for_connect = true;
+	}
+
+	if (!waiting_for_connect) {
+		/* No server is waiting for connect */
+		send_response(client_sk, client->buf,
+			req->request_len, NULL, 0, IPPROTO_TCP);
+		g_free(req);
+		return true;
+	}
+
+	/*
+	 * The server is not connected yet.
+	 * Copy the relevant buffers.
+	 * The request will actually be sent once we're
+	 * properly connected over TCP to the nameserver.
+	 */
+	req->request = g_try_malloc0(req->request_len);
+	if (!req->request) {
+		send_response(client_sk, client->buf,
+			req->request_len, NULL, 0, IPPROTO_TCP);
+		g_free(req);
+		goto out;
+	}
+	memcpy(req->request, client->buf, req->request_len);
+
+	req->name = g_try_malloc0(sizeof(query));
+	if (!req->name) {
+		send_response(client_sk, client->buf,
+			req->request_len, NULL, 0, IPPROTO_TCP);
+		g_free(req->request);
+		g_free(req);
+		goto out;
+	}
+	memcpy(req->name, query, sizeof(query));
+
+	req->timeout = g_timeout_add_seconds(30, request_timeout, req);
+
+	request_list = g_slist_append(request_list, req);
+
+out:
+	if (client->buf_end > (msg_len + 2)) {
+		DBG("client %d buf %p -> %p end %d len %d new %d",
+			client_sk,
+			client->buf + msg_len + 2,
+			client->buf, client->buf_end,
+			TCP_MAX_BUF_LEN - client->buf_end,
+			client->buf_end - (msg_len + 2));
+		memmove(client->buf, client->buf + msg_len + 2,
+			TCP_MAX_BUF_LEN - client->buf_end);
+		client->buf_end = client->buf_end - (msg_len + 2);
+
+		/*
+		 * If we have a full message waiting, just read it
+		 * immediately.
+		 */
+		msg_len = get_msg_len(client->buf);
+		if ((msg_len + 2) == client->buf_end) {
+			DBG("client %d reading another %d bytes", client_sk,
+								msg_len + 2);
+			goto read_another;
+		}
+	} else {
+		DBG("client %d clearing reading buffer", client_sk);
+
+		client->buf_end = 0;
+		memset(client->buf, 0, TCP_MAX_BUF_LEN);
+
+		/*
+		 * We received all the packets from client so we must also
+		 * remove the timeout handler here otherwise we might get
+		 * timeout while waiting the results from server.
+		 */
+		g_source_remove(client->timeout);
+		client->timeout = 0;
+	}
+
+	return true;
+}
+
+static gboolean tcp_client_event(GIOChannel *channel, GIOCondition condition,
+				gpointer user_data)
+{
+	struct tcp_partial_client_data *client = user_data;
+	struct sockaddr_in6 client_addr6;
+	socklen_t client_addr6_len = sizeof(client_addr6);
+	struct sockaddr_in client_addr4;
+	socklen_t client_addr4_len = sizeof(client_addr4);
+	void *client_addr;
+	socklen_t *client_addr_len;
+	int len, client_sk;
+
+	client_sk = g_io_channel_unix_get_fd(channel);
+
+	if (condition & (G_IO_NVAL | G_IO_ERR | G_IO_HUP)) {
+		g_hash_table_remove(partial_tcp_req_table,
+					GINT_TO_POINTER(client_sk));
+
+		connman_error("Error with TCP client %d channel", client_sk);
+		return FALSE;
+	}
+
+	switch (client->family) {
+	case AF_INET:
+		client_addr = &client_addr4;
+		client_addr_len = &client_addr4_len;
+		break;
+	case AF_INET6:
+		client_addr = &client_addr6;
+		client_addr_len = &client_addr6_len;
+		break;
+	default:
+		g_hash_table_remove(partial_tcp_req_table,
+					GINT_TO_POINTER(client_sk));
+		connman_error("client %p corrupted", client);
+		return FALSE;
+	}
+
+	len = recvfrom(client_sk, client->buf + client->buf_end,
+			TCP_MAX_BUF_LEN - client->buf_end, 0,
+			client_addr, client_addr_len);
+	if (len < 0) {
+		if (errno == EAGAIN || errno == EWOULDBLOCK)
+			return TRUE;
+
+		DBG("client %d cannot read errno %d/%s", client_sk, -errno,
+			strerror(errno));
+		g_hash_table_remove(partial_tcp_req_table,
+					GINT_TO_POINTER(client_sk));
+		return FALSE;
+	}
+
+	return read_tcp_data(client, client_addr, *client_addr_len, len);
+}
+
+static gboolean client_timeout(gpointer user_data)
+{
+	struct tcp_partial_client_data *client = user_data;
+	int sock;
+
+	sock = g_io_channel_unix_get_fd(client->channel);
+
+	DBG("client %d timeout pending %d bytes", sock, client->buf_end);
+
+	g_hash_table_remove(partial_tcp_req_table, GINT_TO_POINTER(sock));
+
+	return FALSE;
+}
+
+static bool tcp_listener_event(GIOChannel *channel, GIOCondition condition,
+				struct listener_data *ifdata, int family,
+				guint *listener_watch)
+{
+	int sk, client_sk, len;
+	unsigned int msg_len;
+	struct tcp_partial_client_data *client;
+	struct sockaddr_in6 client_addr6;
+	socklen_t client_addr6_len = sizeof(client_addr6);
+	struct sockaddr_in client_addr4;
+	socklen_t client_addr4_len = sizeof(client_addr4);
+	void *client_addr;
+	socklen_t *client_addr_len;
+	struct timeval tv;
+	fd_set readfds;
+
+	DBG("condition 0x%02x channel %p ifdata %p family %d",
+		condition, channel, ifdata, family);
+
+	if (condition & (G_IO_NVAL | G_IO_ERR | G_IO_HUP)) {
+		if (*listener_watch > 0)
+			g_source_remove(*listener_watch);
+		*listener_watch = 0;
+
+		connman_error("Error with TCP listener channel");
+
+		return false;
+	}
+
+	sk = g_io_channel_unix_get_fd(channel);
+
+	if (family == AF_INET) {
+		client_addr = &client_addr4;
+		client_addr_len = &client_addr4_len;
+	} else {
+		client_addr = &client_addr6;
+		client_addr_len = &client_addr6_len;
+	}
+
+	tv.tv_sec = tv.tv_usec = 0;
+	FD_ZERO(&readfds);
+	FD_SET(sk, &readfds);
+
+	select(sk + 1, &readfds, NULL, NULL, &tv);
+	if (FD_ISSET(sk, &readfds)) {
+		client_sk = accept(sk, client_addr, client_addr_len);
+		DBG("client %d accepted", client_sk);
+	} else {
+		DBG("No data to read from master %d, waiting.", sk);
+		return true;
+	}
+
+	if (client_sk < 0) {
+		connman_error("Accept failure on TCP listener");
+		*listener_watch = 0;
+		return false;
+	}
+
+	fcntl(client_sk, F_SETFL, O_NONBLOCK);
+
+	client = g_hash_table_lookup(partial_tcp_req_table,
+					GINT_TO_POINTER(client_sk));
+	if (!client) {
+		client = g_try_new0(struct tcp_partial_client_data, 1);
+		if (!client) {
+			close(client_sk);
+			return false;
+		}
+
+		g_hash_table_insert(partial_tcp_req_table,
+					GINT_TO_POINTER(client_sk),
+					client);
+
+		client->channel = g_io_channel_unix_new(client_sk);
+		g_io_channel_set_close_on_unref(client->channel, TRUE);
+
+		client->watch = g_io_add_watch(client->channel,
+						G_IO_IN, tcp_client_event,
+						(gpointer)client);
+
+		client->ifdata = ifdata;
+
+		DBG("client %d created %p", client_sk, client);
+	} else {
+		DBG("client %d already exists %p", client_sk, client);
+	}
+
+	if (!client->buf) {
+		client->buf = g_try_malloc(TCP_MAX_BUF_LEN);
+		if (!client->buf)
+			return false;
+	}
+	memset(client->buf, 0, TCP_MAX_BUF_LEN);
+	client->buf_end = 0;
+	client->family = family;
+
+	if (client->timeout == 0)
+		client->timeout = g_timeout_add_seconds(2, client_timeout,
+							client);
+
+	/*
+	 * Check how much data there is. If all is there, then we can
+	 * proceed normally, otherwise read the bits until everything
+	 * is received or timeout occurs.
+	 */
+	len = recv(client_sk, client->buf, TCP_MAX_BUF_LEN, 0);
+	if (len < 0) {
+		if (errno == EAGAIN || errno == EWOULDBLOCK) {
+			DBG("client %d no data to read, waiting", client_sk);
+			return true;
+		}
+
+		DBG("client %d cannot read errno %d/%s", client_sk, -errno,
+			strerror(errno));
+		g_hash_table_remove(partial_tcp_req_table,
+					GINT_TO_POINTER(client_sk));
+		return true;
+	}
+
+	if (len < 2) {
+		DBG("client %d not enough data to read, waiting", client_sk);
+		client->buf_end += len;
+		return true;
+	}
+
+	msg_len = get_msg_len(client->buf);
+	if (msg_len > TCP_MAX_BUF_LEN) {
+		DBG("client %d invalid message length %u ignoring packet",
+			client_sk, msg_len);
+		g_hash_table_remove(partial_tcp_req_table,
+					GINT_TO_POINTER(client_sk));
+		return true;
+	}
+
+	/*
+	 * The packet length bytes do not contain the total message length,
+	 * that is the reason to -2 below.
+	 */
+	if (msg_len != (unsigned int)(len - 2)) {
+		DBG("client %d sent %d bytes but expecting %u pending %d",
+			client_sk, len, msg_len + 2, msg_len + 2 - len);
+
+		client->buf_end += len;
+		return true;
+	}
+
+	return read_tcp_data(client, client_addr, *client_addr_len, len);
+}
+
+static gboolean tcp4_listener_event(GIOChannel *channel, GIOCondition condition,
+				gpointer user_data)
+{
+	struct listener_data *ifdata = user_data;
+
+	return tcp_listener_event(channel, condition, ifdata, AF_INET,
+				&ifdata->tcp4_listener_watch);
+}
+
+static gboolean tcp6_listener_event(GIOChannel *channel, GIOCondition condition,
+				gpointer user_data)
+{
+	struct listener_data *ifdata = user_data;
+
+	return tcp_listener_event(channel, condition, user_data, AF_INET6,
+				&ifdata->tcp6_listener_watch);
+}
+
+static bool udp_listener_event(GIOChannel *channel, GIOCondition condition,
+				struct listener_data *ifdata, int family,
+				guint *listener_watch)
+{
+	unsigned char buf[768];
+	char query[512];
+	struct request_data *req;
+	struct sockaddr_in6 client_addr6;
+	socklen_t client_addr6_len = sizeof(client_addr6);
+	struct sockaddr_in client_addr4;
+	socklen_t client_addr4_len = sizeof(client_addr4);
+	void *client_addr;
+	socklen_t *client_addr_len;
+	int sk, err, len;
+
+	if (condition & (G_IO_NVAL | G_IO_ERR | G_IO_HUP)) {
+		connman_error("Error with UDP listener channel");
+		*listener_watch = 0;
+		return false;
+	}
+
+	sk = g_io_channel_unix_get_fd(channel);
+
+	if (family == AF_INET) {
+		client_addr = &client_addr4;
+		client_addr_len = &client_addr4_len;
+	} else {
+		client_addr = &client_addr6;
+		client_addr_len = &client_addr6_len;
+	}
+
+	memset(client_addr, 0, *client_addr_len);
+	len = recvfrom(sk, buf, sizeof(buf), 0, client_addr, client_addr_len);
+	if (len < 2)
+		return true;
+
+	DBG("Received %d bytes (id 0x%04x)", len, buf[0] | buf[1] << 8);
+
+	err = parse_request(buf, len, query, sizeof(query));
+	if (err < 0 || (g_slist_length(server_list) == 0)) {
+		send_response(sk, buf, len, client_addr,
+				*client_addr_len, IPPROTO_UDP);
+		return true;
+	}
+
+	req = g_try_new0(struct request_data, 1);
+	if (!req)
+		return true;
+
+	memcpy(&req->sa, client_addr, *client_addr_len);
+	req->sa_len = *client_addr_len;
+	req->client_sk = 0;
+	req->protocol = IPPROTO_UDP;
+	req->family = family;
+
+	req->srcid = buf[0] | (buf[1] << 8);
+	req->dstid = get_id();
+	req->altid = get_id();
+	req->request_len = len;
+
+	buf[0] = req->dstid & 0xff;
+	buf[1] = req->dstid >> 8;
+
+	req->numserv = 0;
+	req->ifdata = ifdata;
+	req->append_domain = false;
+
+	if (resolv(req, buf, query)) {
+		/* a cached result was sent, so the request can be released */
+	        g_free(req);
+		return true;
+	}
+
+	req->name = g_strdup(query);
+	req->request = g_malloc(len);
+	memcpy(req->request, buf, len);
+	req->timeout = g_timeout_add_seconds(5, request_timeout, req);
+	request_list = g_slist_append(request_list, req);
+
+	return true;
+}
+
+static gboolean udp4_listener_event(GIOChannel *channel, GIOCondition condition,
+				gpointer user_data)
+{
+	struct listener_data *ifdata = user_data;
+
+	return udp_listener_event(channel, condition, ifdata, AF_INET,
+				&ifdata->udp4_listener_watch);
+}
+
+static gboolean udp6_listener_event(GIOChannel *channel, GIOCondition condition,
+				gpointer user_data)
+{
+	struct listener_data *ifdata = user_data;
+
+	return udp_listener_event(channel, condition, user_data, AF_INET6,
+				&ifdata->udp6_listener_watch);
+}
+
+static GIOChannel *get_listener(int family, int protocol, int index)
+{
+	GIOChannel *channel;
+	const char *proto;
+	union {
+		struct sockaddr sa;
+		struct sockaddr_in6 sin6;
+		struct sockaddr_in sin;
+	} s;
+	socklen_t slen;
+	int sk, type;
+	char *interface;
+
+	DBG("family %d protocol %d index %d", family, protocol, index);
+
+	switch (protocol) {
+	case IPPROTO_UDP:
+		proto = "UDP";
+		type = SOCK_DGRAM | SOCK_CLOEXEC;
+		break;
+
+	case IPPROTO_TCP:
+		proto = "TCP";
+		type = SOCK_STREAM | SOCK_CLOEXEC;
+		break;
+
+	default:
+		return NULL;
+	}
+
+	sk = socket(family, type, protocol);
+	if (sk < 0 && family == AF_INET6 && errno == EAFNOSUPPORT) {
+		connman_error("No IPv6 support");
+		return NULL;
+	}
+
+	if (sk < 0) {
+		connman_error("Failed to create %s listener socket", proto);
+		return NULL;
+	}
+
+	interface = connman_inet_ifname(index);
+	if (!interface || setsockopt(sk, SOL_SOCKET, SO_BINDTODEVICE,
+					interface,
+					strlen(interface) + 1) < 0) {
+		connman_error("Failed to bind %s listener interface "
+			"for %s (%d/%s)",
+			proto, family == AF_INET ? "IPv4" : "IPv6",
+			-errno, strerror(errno));
+		close(sk);
+		g_free(interface);
+		return NULL;
+	}
+	g_free(interface);
+
+	if (family == AF_INET6) {
+		memset(&s.sin6, 0, sizeof(s.sin6));
+		s.sin6.sin6_family = AF_INET6;
+		s.sin6.sin6_port = htons(53);
+		slen = sizeof(s.sin6);
+
+		if (__connman_inet_get_interface_address(index,
+						AF_INET6,
+						&s.sin6.sin6_addr) < 0) {
+			/* So we could not find suitable IPv6 address for
+			 * the interface. This could happen if we have
+			 * disabled IPv6 for the interface.
+			 */
+			close(sk);
+			return NULL;
+		}
+
+	} else if (family == AF_INET) {
+		memset(&s.sin, 0, sizeof(s.sin));
+		s.sin.sin_family = AF_INET;
+		s.sin.sin_port = htons(53);
+		slen = sizeof(s.sin);
+
+		if (__connman_inet_get_interface_address(index,
+						AF_INET,
+						&s.sin.sin_addr) < 0) {
+			close(sk);
+			return NULL;
+		}
+	} else {
+		close(sk);
+		return NULL;
+	}
+
+	if (bind(sk, &s.sa, slen) < 0) {
+		connman_error("Failed to bind %s listener socket", proto);
+		close(sk);
+		return NULL;
+	}
+
+	if (protocol == IPPROTO_TCP) {
+
+		if (listen(sk, 10) < 0) {
+			connman_error("Failed to listen on TCP socket %d/%s",
+				-errno, strerror(errno));
+			close(sk);
+			return NULL;
+		}
+
+		fcntl(sk, F_SETFL, O_NONBLOCK);
+	}
+
+	channel = g_io_channel_unix_new(sk);
+	if (!channel) {
+		connman_error("Failed to create %s listener channel", proto);
+		close(sk);
+		return NULL;
+	}
+
+	g_io_channel_set_close_on_unref(channel, TRUE);
+
+	return channel;
+}
+
+#define UDP_IPv4_FAILED 0x01
+#define TCP_IPv4_FAILED 0x02
+#define UDP_IPv6_FAILED 0x04
+#define TCP_IPv6_FAILED 0x08
+#define UDP_FAILED (UDP_IPv4_FAILED | UDP_IPv6_FAILED)
+#define TCP_FAILED (TCP_IPv4_FAILED | TCP_IPv6_FAILED)
+#define IPv6_FAILED (UDP_IPv6_FAILED | TCP_IPv6_FAILED)
+#define IPv4_FAILED (UDP_IPv4_FAILED | TCP_IPv4_FAILED)
+
+static int create_dns_listener(int protocol, struct listener_data *ifdata)
+{
+	int ret = 0;
+
+	if (protocol == IPPROTO_TCP) {
+		ifdata->tcp4_listener_channel = get_listener(AF_INET, protocol,
+							ifdata->index);
+		if (ifdata->tcp4_listener_channel)
+			ifdata->tcp4_listener_watch =
+				g_io_add_watch(ifdata->tcp4_listener_channel,
+					G_IO_IN, tcp4_listener_event,
+					(gpointer)ifdata);
+		else
+			ret |= TCP_IPv4_FAILED;
+
+		ifdata->tcp6_listener_channel = get_listener(AF_INET6, protocol,
+							ifdata->index);
+		if (ifdata->tcp6_listener_channel)
+			ifdata->tcp6_listener_watch =
+				g_io_add_watch(ifdata->tcp6_listener_channel,
+					G_IO_IN, tcp6_listener_event,
+					(gpointer)ifdata);
+		else
+			ret |= TCP_IPv6_FAILED;
+	} else {
+		ifdata->udp4_listener_channel = get_listener(AF_INET, protocol,
+							ifdata->index);
+		if (ifdata->udp4_listener_channel)
+			ifdata->udp4_listener_watch =
+				g_io_add_watch(ifdata->udp4_listener_channel,
+					G_IO_IN, udp4_listener_event,
+					(gpointer)ifdata);
+		else
+			ret |= UDP_IPv4_FAILED;
+
+		ifdata->udp6_listener_channel = get_listener(AF_INET6, protocol,
+							ifdata->index);
+		if (ifdata->udp6_listener_channel)
+			ifdata->udp6_listener_watch =
+				g_io_add_watch(ifdata->udp6_listener_channel,
+					G_IO_IN, udp6_listener_event,
+					(gpointer)ifdata);
+		else
+			ret |= UDP_IPv6_FAILED;
+	}
+
+	return ret;
+}
+
+static void destroy_udp_listener(struct listener_data *ifdata)
+{
+	DBG("index %d", ifdata->index);
+
+	if (ifdata->udp4_listener_watch > 0)
+		g_source_remove(ifdata->udp4_listener_watch);
+
+	if (ifdata->udp6_listener_watch > 0)
+		g_source_remove(ifdata->udp6_listener_watch);
+
+	if (ifdata->udp4_listener_channel)
+		g_io_channel_unref(ifdata->udp4_listener_channel);
+	if (ifdata->udp6_listener_channel)
+		g_io_channel_unref(ifdata->udp6_listener_channel);
+}
+
+static void destroy_tcp_listener(struct listener_data *ifdata)
+{
+	DBG("index %d", ifdata->index);
+
+	if (ifdata->tcp4_listener_watch > 0)
+		g_source_remove(ifdata->tcp4_listener_watch);
+	if (ifdata->tcp6_listener_watch > 0)
+		g_source_remove(ifdata->tcp6_listener_watch);
+
+	if (ifdata->tcp4_listener_channel)
+		g_io_channel_unref(ifdata->tcp4_listener_channel);
+	if (ifdata->tcp6_listener_channel)
+		g_io_channel_unref(ifdata->tcp6_listener_channel);
+}
+
+static int create_listener(struct listener_data *ifdata)
+{
+	int err, index;
+
+	err = create_dns_listener(IPPROTO_UDP, ifdata);
+	if ((err & UDP_FAILED) == UDP_FAILED)
+		return -EIO;
+
+	err |= create_dns_listener(IPPROTO_TCP, ifdata);
+	if ((err & TCP_FAILED) == TCP_FAILED) {
+		destroy_udp_listener(ifdata);
+		return -EIO;
+	}
+
+	index = connman_inet_ifindex("lo");
+	if (ifdata->index == index) {
+		if ((err & IPv6_FAILED) != IPv6_FAILED)
+			__connman_resolvfile_append(index, NULL, "::1");
+
+		if ((err & IPv4_FAILED) != IPv4_FAILED)
+			__connman_resolvfile_append(index, NULL, "127.0.0.1");
+	}
+
+	return 0;
+}
+
+static void destroy_listener(struct listener_data *ifdata)
+{
+	int index;
+	GSList *list;
+
+	index = connman_inet_ifindex("lo");
+	if (ifdata->index == index) {
+		__connman_resolvfile_remove(index, NULL, "127.0.0.1");
+		__connman_resolvfile_remove(index, NULL, "::1");
+	}
+
+	for (list = request_list; list; list = list->next) {
+		struct request_data *req = list->data;
+
+		DBG("Dropping request (id 0x%04x -> 0x%04x)",
+						req->srcid, req->dstid);
+		destroy_request_data(req);
+		list->data = NULL;
+	}
+
+	g_slist_free(request_list);
+	request_list = NULL;
+
+	destroy_tcp_listener(ifdata);
+	destroy_udp_listener(ifdata);
+}
+
+int __connman_dnsproxy_add_listener(int index)
+{
+	struct listener_data *ifdata;
+	int err;
+
+	DBG("index %d", index);
+
+	if (index < 0)
+		return -EINVAL;
+
+	if (!listener_table)
+		return -ENOENT;
+
+	if (g_hash_table_lookup(listener_table, GINT_TO_POINTER(index)))
+		return 0;
+
+	ifdata = g_try_new0(struct listener_data, 1);
+	if (!ifdata)
+		return -ENOMEM;
+
+	ifdata->index = index;
+	ifdata->udp4_listener_channel = NULL;
+	ifdata->udp4_listener_watch = 0;
+	ifdata->tcp4_listener_channel = NULL;
+	ifdata->tcp4_listener_watch = 0;
+	ifdata->udp6_listener_channel = NULL;
+	ifdata->udp6_listener_watch = 0;
+	ifdata->tcp6_listener_channel = NULL;
+	ifdata->tcp6_listener_watch = 0;
+
+	err = create_listener(ifdata);
+	if (err < 0) {
+		connman_error("Couldn't create listener for index %d err %d",
+				index, err);
+		g_free(ifdata);
+		return err;
+	}
+	g_hash_table_insert(listener_table, GINT_TO_POINTER(ifdata->index),
+			ifdata);
+	return 0;
+}
+
+void __connman_dnsproxy_remove_listener(int index)
+{
+	struct listener_data *ifdata;
+
+	DBG("index %d", index);
+
+	if (!listener_table)
+		return;
+
+	ifdata = g_hash_table_lookup(listener_table, GINT_TO_POINTER(index));
+	if (!ifdata)
+		return;
+
+	destroy_listener(ifdata);
+
+	g_hash_table_remove(listener_table, GINT_TO_POINTER(index));
+}
+
+static void remove_listener(gpointer key, gpointer value, gpointer user_data)
+{
+	int index = GPOINTER_TO_INT(key);
+	struct listener_data *ifdata = value;
+
+	DBG("index %d", index);
+
+	destroy_listener(ifdata);
+}
+
+static void free_partial_reqs(gpointer value)
+{
+	struct tcp_partial_client_data *data = value;
+
+	client_reset(data);
+	g_free(data);
+}
+
+int __connman_dnsproxy_init(void)
+{
+	int err, index;
+
+	DBG("");
+
+	listener_table = g_hash_table_new_full(g_direct_hash, g_direct_equal,
+							NULL, g_free);
+
+	partial_tcp_req_table = g_hash_table_new_full(g_direct_hash,
+							g_direct_equal,
+							NULL,
+							free_partial_reqs);
+
+	index = connman_inet_ifindex("lo");
+	err = __connman_dnsproxy_add_listener(index);
+	if (err < 0)
+		return err;
+
+	err = connman_notifier_register(&dnsproxy_notifier);
+	if (err < 0)
+		goto destroy;
+
+	return 0;
+
+destroy:
+	__connman_dnsproxy_remove_listener(index);
+	g_hash_table_destroy(listener_table);
+	g_hash_table_destroy(partial_tcp_req_table);
+
+	return err;
+}
+
+void __connman_dnsproxy_cleanup(void)
+{
+	DBG("");
+
+	if (cache_timer) {
+		g_source_remove(cache_timer);
+		cache_timer = 0;
+	}
+
+	if (cache) {
+		g_hash_table_destroy(cache);
+		cache = NULL;
+	}
+
+	connman_notifier_unregister(&dnsproxy_notifier);
+
+	g_hash_table_foreach(listener_table, remove_listener, NULL);
+
+	g_hash_table_destroy(listener_table);
+
+	g_hash_table_destroy(partial_tcp_req_table);
+}
diff --git a/connman/src/eduroam.config b/connman/src/eduroam.config
new file mode 100644
index 0000000..768b7b4
--- /dev/null
+++ b/connman/src/eduroam.config
@@ -0,0 +1,5 @@
+[service_eduroam]
+Type = wifi
+Name = eduroam
+EAP = peap
+Phase2 = MSCHAPV2
diff --git a/connman/src/error.c b/connman/src/error.c
new file mode 100644
index 0000000..4f24ae2
--- /dev/null
+++ b/connman/src/error.c
@@ -0,0 +1,187 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2013  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 <string.h>
+
+#include <gdbus.h>
+
+#include "connman.h"
+
+DBusMessage *__connman_error_failed(DBusMessage *msg, int errnum)
+{
+	const char *str = strerror(errnum);
+
+	switch (errnum) {
+	case ESRCH:
+		return __connman_error_not_registered(msg);
+	case ENXIO:
+		return __connman_error_not_found(msg);
+	case EACCES:
+		return __connman_error_permission_denied(msg);
+	case EEXIST:
+		return __connman_error_already_exists(msg);
+	case EINVAL:
+		return __connman_error_invalid_arguments(msg);
+	case ENOSYS:
+		return __connman_error_not_implemented(msg);
+	case ENOLINK:
+		return __connman_error_no_carrier(msg);
+	case ENOTUNIQ:
+		return __connman_error_not_unique(msg);
+	case EOPNOTSUPP:
+		return __connman_error_not_supported(msg);
+	case ECONNABORTED:
+		return __connman_error_operation_aborted(msg);
+	case EISCONN:
+		return __connman_error_already_connected(msg);
+	case ENOTCONN:
+	case ECONNREFUSED:
+		return __connman_error_not_connected(msg);
+	case ETIMEDOUT:
+		return __connman_error_operation_timeout(msg);
+	case EALREADY:
+	case EINPROGRESS:
+		return __connman_error_in_progress(msg);
+	case ENOKEY:
+		return __connman_error_passphrase_required(msg);
+	}
+
+	return g_dbus_create_error(msg, CONNMAN_ERROR_INTERFACE
+					".Failed", "%s", str);
+}
+
+DBusMessage *__connman_error_invalid_arguments(DBusMessage *msg)
+{
+	return g_dbus_create_error(msg, CONNMAN_ERROR_INTERFACE
+				".InvalidArguments", "Invalid arguments");
+}
+
+DBusMessage *__connman_error_permission_denied(DBusMessage *msg)
+{
+	return g_dbus_create_error(msg, CONNMAN_ERROR_INTERFACE
+				".PermissionDenied", "Permission denied");
+}
+
+DBusMessage *__connman_error_passphrase_required(DBusMessage *msg)
+{
+	return g_dbus_create_error(msg, CONNMAN_ERROR_INTERFACE
+				".PassphraseRequired", "Passphrase required");
+}
+
+DBusMessage *__connman_error_not_registered(DBusMessage *msg)
+{
+	return g_dbus_create_error(msg, CONNMAN_ERROR_INTERFACE
+					".NotRegistered", "Not registered");
+}
+
+DBusMessage *__connman_error_not_unique(DBusMessage *msg)
+{
+	return g_dbus_create_error(msg, CONNMAN_ERROR_INTERFACE
+					".NotUnique", "Not unique");
+}
+
+DBusMessage *__connman_error_not_supported(DBusMessage *msg)
+{
+	return g_dbus_create_error(msg, CONNMAN_ERROR_INTERFACE
+					".NotSupported", "Not supported");
+}
+
+DBusMessage *__connman_error_not_implemented(DBusMessage *msg)
+{
+	return g_dbus_create_error(msg, CONNMAN_ERROR_INTERFACE
+					".NotImplemented", "Not implemented");
+}
+
+DBusMessage *__connman_error_not_found(DBusMessage *msg)
+{
+	return g_dbus_create_error(msg, CONNMAN_ERROR_INTERFACE
+						".NotFound", "Not found");
+}
+
+DBusMessage *__connman_error_no_carrier(DBusMessage *msg)
+{
+	return g_dbus_create_error(msg, CONNMAN_ERROR_INTERFACE
+						".NoCarrier", "No carrier");
+}
+
+DBusMessage *__connman_error_in_progress(DBusMessage *msg)
+{
+	return g_dbus_create_error(msg, CONNMAN_ERROR_INTERFACE
+						".InProgress", "In progress");
+}
+
+DBusMessage *__connman_error_already_exists(DBusMessage *msg)
+{
+	return g_dbus_create_error(msg, CONNMAN_ERROR_INTERFACE
+				".AlreadyExists", "Already exists");
+}
+
+DBusMessage *__connman_error_already_enabled(DBusMessage *msg)
+{
+	return g_dbus_create_error(msg, CONNMAN_ERROR_INTERFACE
+				".AlreadyEnabled", "Already enabled");
+}
+
+DBusMessage *__connman_error_already_disabled(DBusMessage *msg)
+{
+	return g_dbus_create_error(msg, CONNMAN_ERROR_INTERFACE
+				".AlreadyDisabled", "Already disabled");
+}
+
+DBusMessage *__connman_error_already_connected(DBusMessage *msg)
+{
+	return g_dbus_create_error(msg, CONNMAN_ERROR_INTERFACE
+				".AlreadyConnected", "Already connected");
+}
+
+DBusMessage *__connman_error_not_connected(DBusMessage *msg)
+{
+	return g_dbus_create_error(msg, CONNMAN_ERROR_INTERFACE
+					".NotConnected", "Not connected");
+}
+DBusMessage *__connman_error_operation_aborted(DBusMessage *msg)
+{
+	return g_dbus_create_error(msg, CONNMAN_ERROR_INTERFACE
+				".OperationAborted", "Operation aborted");
+}
+
+DBusMessage *__connman_error_operation_timeout(DBusMessage *msg)
+{
+	return g_dbus_create_error(msg, CONNMAN_ERROR_INTERFACE
+				".OperationTimeout", "Operation timeout");
+}
+
+DBusMessage *__connman_error_invalid_service(DBusMessage *msg)
+{
+	return g_dbus_create_error(msg, CONNMAN_ERROR_INTERFACE
+				".InvalidService", "Invalid service");
+}
+
+DBusMessage *__connman_error_invalid_property(DBusMessage *msg)
+{
+	return g_dbus_create_error(msg, CONNMAN_ERROR_INTERFACE
+				".InvalidProperty", "Invalid property");
+}
diff --git a/connman/src/firewall.c b/connman/src/firewall.c
new file mode 100644
index 0000000..90c3d3c
--- /dev/null
+++ b/connman/src/firewall.c
@@ -0,0 +1,460 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2013  BMW Car IT GmbH.
+ *
+ *  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 <xtables.h>
+#include <linux/netfilter_ipv4/ip_tables.h>
+
+#include "connman.h"
+
+#define CHAIN_PREFIX "connman-"
+
+static const char *builtin_chains[] = {
+	[NF_IP_PRE_ROUTING]	= "PREROUTING",
+	[NF_IP_LOCAL_IN]	= "INPUT",
+	[NF_IP_FORWARD]		= "FORWARD",
+	[NF_IP_LOCAL_OUT]	= "OUTPUT",
+	[NF_IP_POST_ROUTING]	= "POSTROUTING",
+};
+
+struct connman_managed_table {
+	char *name;
+	unsigned int chains[NF_INET_NUMHOOKS];
+};
+
+struct fw_rule {
+	char *table;
+	char *chain;
+	char *rule_spec;
+};
+
+struct firewall_context {
+	GList *rules;
+};
+
+static GSList *managed_tables;
+
+static bool firewall_is_up;
+
+static int chain_to_index(const char *chain_name)
+{
+	if (!g_strcmp0(builtin_chains[NF_IP_PRE_ROUTING], chain_name))
+		return NF_IP_PRE_ROUTING;
+	if (!g_strcmp0(builtin_chains[NF_IP_LOCAL_IN], chain_name))
+		return NF_IP_LOCAL_IN;
+	if (!g_strcmp0(builtin_chains[NF_IP_FORWARD], chain_name))
+		return NF_IP_FORWARD;
+	if (!g_strcmp0(builtin_chains[NF_IP_LOCAL_OUT], chain_name))
+		return NF_IP_LOCAL_OUT;
+	if (!g_strcmp0(builtin_chains[NF_IP_POST_ROUTING], chain_name))
+		return NF_IP_POST_ROUTING;
+
+	return -1;
+}
+
+static int managed_chain_to_index(const char *chain_name)
+{
+	if (!g_str_has_prefix(chain_name, CHAIN_PREFIX))
+		return -1;
+
+	return chain_to_index(chain_name + strlen(CHAIN_PREFIX));
+}
+
+static int insert_managed_chain(const char *table_name, int id)
+{
+	char *rule, *managed_chain;
+	int err;
+
+	managed_chain = g_strdup_printf("%s%s", CHAIN_PREFIX,
+					builtin_chains[id]);
+
+	err = __connman_iptables_new_chain(table_name, managed_chain);
+	if (err < 0)
+		goto out;
+
+	rule = g_strdup_printf("-j %s", managed_chain);
+	err = __connman_iptables_insert(table_name, builtin_chains[id], rule);
+	g_free(rule);
+	if (err < 0) {
+		__connman_iptables_delete_chain(table_name, managed_chain);
+		goto out;
+	}
+
+out:
+	g_free(managed_chain);
+
+	return err;
+}
+
+static int delete_managed_chain(const char *table_name, int id)
+{
+	char *rule, *managed_chain;
+	int err;
+
+	managed_chain = g_strdup_printf("%s%s", CHAIN_PREFIX,
+					builtin_chains[id]);
+
+	rule = g_strdup_printf("-j %s", managed_chain);
+	err = __connman_iptables_delete(table_name, builtin_chains[id], rule);
+	g_free(rule);
+
+	if (err < 0)
+		goto out;
+
+	err =  __connman_iptables_delete_chain(table_name, managed_chain);
+
+out:
+	g_free(managed_chain);
+
+	return err;
+}
+
+static int insert_managed_rule(const char *table_name,
+				const char *chain_name,
+				const char *rule_spec)
+{
+	struct connman_managed_table *mtable = NULL;
+	GSList *list;
+	char *chain;
+	int id, err;
+
+	id = chain_to_index(chain_name);
+	if (id < 0) {
+		/* This chain is not managed */
+		chain = g_strdup(chain_name);
+		goto out;
+	}
+
+	for (list = managed_tables; list; list = list->next) {
+		mtable = list->data;
+
+		if (g_strcmp0(mtable->name, table_name) == 0)
+			break;
+
+		mtable = NULL;
+	}
+
+	if (!mtable) {
+		mtable = g_new0(struct connman_managed_table, 1);
+		mtable->name = g_strdup(table_name);
+
+		managed_tables = g_slist_prepend(managed_tables, mtable);
+	}
+
+	if (mtable->chains[id] == 0) {
+		DBG("table %s add managed chain for %s",
+			table_name, chain_name);
+
+		err = insert_managed_chain(table_name, id);
+		if (err < 0)
+			return err;
+	}
+
+	mtable->chains[id]++;
+	chain = g_strdup_printf("%s%s", CHAIN_PREFIX, chain_name);
+
+out:
+	err = __connman_iptables_append(table_name, chain, rule_spec);
+
+	g_free(chain);
+
+	return err;
+ }
+
+static int delete_managed_rule(const char *table_name,
+				const char *chain_name,
+				const char *rule_spec)
+ {
+	struct connman_managed_table *mtable = NULL;
+	GSList *list;
+	int id, err;
+	char *managed_chain;
+
+	id = chain_to_index(chain_name);
+	if (id < 0) {
+		/* This chain is not managed */
+		return __connman_iptables_delete(table_name, chain_name,
+							rule_spec);
+	}
+
+	managed_chain = g_strdup_printf("%s%s", CHAIN_PREFIX, chain_name);
+
+	err = __connman_iptables_delete(table_name, managed_chain,
+					rule_spec);
+
+	for (list = managed_tables; list; list = list->next) {
+		mtable = list->data;
+
+		if (g_strcmp0(mtable->name, table_name) == 0)
+			break;
+
+		mtable = NULL;
+	}
+
+	if (!mtable) {
+		err = -ENOENT;
+		goto out;
+	}
+
+	mtable->chains[id]--;
+	if (mtable->chains[id] > 0)
+		goto out;
+
+	DBG("table %s remove managed chain for %s",
+			table_name, chain_name);
+
+	err = delete_managed_chain(table_name, id);
+
+ out:
+	g_free(managed_chain);
+
+	return err;
+}
+
+static void cleanup_managed_table(gpointer user_data)
+{
+	struct connman_managed_table *table = user_data;
+
+	g_free(table->name);
+	g_free(table);
+}
+
+static void cleanup_fw_rule(gpointer user_data)
+{
+	struct fw_rule *rule = user_data;
+
+	g_free(rule->rule_spec);
+	g_free(rule->chain);
+	g_free(rule->table);
+	g_free(rule);
+}
+
+struct firewall_context *__connman_firewall_create(void)
+{
+	struct firewall_context *ctx;
+
+	ctx = g_new0(struct firewall_context, 1);
+
+	return ctx;
+}
+
+void __connman_firewall_destroy(struct firewall_context *ctx)
+{
+	g_list_free_full(ctx->rules, cleanup_fw_rule);
+	g_free(ctx);
+}
+
+int __connman_firewall_add_rule(struct firewall_context *ctx,
+				const char *table,
+				const char *chain,
+				const char *rule_fmt, ...)
+{
+	va_list args;
+	char *rule_spec;
+	struct fw_rule *rule;
+
+	va_start(args, rule_fmt);
+
+	rule_spec = g_strdup_vprintf(rule_fmt, args);
+
+	va_end(args);
+
+	rule = g_new0(struct fw_rule, 1);
+
+	rule->table = g_strdup(table);
+	rule->chain = g_strdup(chain);
+	rule->rule_spec = rule_spec;
+
+	ctx->rules = g_list_append(ctx->rules, rule);
+
+	return 0;
+}
+
+static int firewall_disable(GList *rules)
+{
+	struct fw_rule *rule;
+	GList *list;
+	int err;
+
+	for (list = rules; list; list = g_list_previous(list)) {
+		rule = list->data;
+
+		err = delete_managed_rule(rule->table,
+						rule->chain, rule->rule_spec);
+		if (err < 0) {
+			connman_error("Cannot remove previously installed "
+				"iptables rules: %s", strerror(-err));
+			return err;
+		}
+
+		err = __connman_iptables_commit(rule->table);
+		if (err < 0) {
+			connman_error("Cannot remove previously installed "
+				"iptables rules: %s", strerror(-err));
+			return err;
+		}
+	}
+
+	return 0;
+}
+
+int __connman_firewall_enable(struct firewall_context *ctx)
+{
+	struct fw_rule *rule;
+	GList *list;
+	int err;
+
+	for (list = g_list_first(ctx->rules); list;
+			list = g_list_next(list)) {
+		rule = list->data;
+
+		DBG("%s %s %s", rule->table, rule->chain, rule->rule_spec);
+
+		err = insert_managed_rule(rule->table,
+						rule->chain, rule->rule_spec);
+		if (err < 0)
+			goto err;
+
+		err = __connman_iptables_commit(rule->table);
+		if (err < 0)
+			goto err;
+	}
+
+	firewall_is_up = true;
+
+	return 0;
+
+err:
+	connman_warn("Failed to install iptables rules: %s", strerror(-err));
+
+	firewall_disable(g_list_previous(list));
+
+	return err;
+}
+
+int __connman_firewall_disable(struct firewall_context *ctx)
+{
+	return firewall_disable(g_list_last(ctx->rules));
+}
+
+bool __connman_firewall_is_up(void)
+{
+	return firewall_is_up;
+}
+
+static void iterate_chains_cb(const char *chain_name, void *user_data)
+{
+	GSList **chains = user_data;
+	int id;
+
+	id = managed_chain_to_index(chain_name);
+	if (id < 0)
+		return;
+
+	*chains = g_slist_prepend(*chains, GINT_TO_POINTER(id));
+}
+
+static void flush_table(const char *table_name)
+{
+	GSList *chains = NULL, *list;
+	char *rule, *managed_chain;
+	int id, err;
+
+	__connman_iptables_iterate_chains(table_name, iterate_chains_cb,
+						&chains);
+
+	for (list = chains; list; list = list->next) {
+		id = GPOINTER_TO_INT(list->data);
+
+		managed_chain = g_strdup_printf("%s%s", CHAIN_PREFIX,
+						builtin_chains[id]);
+
+		rule = g_strdup_printf("-j %s", managed_chain);
+		err = __connman_iptables_delete(table_name,
+						builtin_chains[id], rule);
+		if (err < 0) {
+			connman_warn("Failed to delete jump rule '%s': %s",
+				rule, strerror(-err));
+		}
+		g_free(rule);
+
+		err = __connman_iptables_flush_chain(table_name, managed_chain);
+		if (err < 0) {
+			connman_warn("Failed to flush chain '%s': %s",
+				managed_chain, strerror(-err));
+		}
+		err = __connman_iptables_delete_chain(table_name, managed_chain);
+		if (err < 0) {
+			connman_warn("Failed to delete chain '%s': %s",
+				managed_chain, strerror(-err));
+		}
+
+		g_free(managed_chain);
+	}
+
+	err = __connman_iptables_commit(table_name);
+	if (err < 0) {
+		connman_warn("Failed to flush table '%s': %s",
+			table_name, strerror(-err));
+	}
+
+	g_slist_free(chains);
+}
+
+static void flush_all_tables(void)
+{
+	/* Flush the tables ConnMan might have modified
+	 * But do so if only ConnMan has done something with
+	 * iptables */
+
+	if (!g_file_test("/proc/net/ip_tables_names",
+			G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
+		firewall_is_up = false;
+		return;
+	}
+
+	firewall_is_up = true;
+
+	flush_table("filter");
+	flush_table("mangle");
+	flush_table("nat");
+}
+
+int __connman_firewall_init(void)
+{
+	DBG("");
+
+	flush_all_tables();
+
+	return 0;
+}
+
+void __connman_firewall_cleanup(void)
+{
+	DBG("");
+
+	g_slist_free_full(managed_tables, cleanup_managed_table);
+}
diff --git a/connman/src/genbuiltin b/connman/src/genbuiltin
new file mode 100755
index 0000000..3e1bb0c
--- /dev/null
+++ b/connman/src/genbuiltin
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+for i in $*
+do
+	echo "extern struct connman_plugin_desc __connman_builtin_$i;"
+done
+
+echo
+echo "static struct connman_plugin_desc *__connman_builtin[] = {"
+
+for i in $*
+do
+	echo "  &__connman_builtin_$i,"
+done
+
+echo "  NULL"
+echo "};"
diff --git a/connman/src/inet.c b/connman/src/inet.c
new file mode 100644
index 0000000..e06d9c8
--- /dev/null
+++ b/connman/src/inet.c
@@ -0,0 +1,2961 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2013  Intel Corporation. All rights reserved.
+ *  Copyright (C) 2003-2005  Go-Core Project
+ *  Copyright (C) 2003-2006  Helsinki University of Technology
+ *
+ *  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
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <errno.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <linux/sockios.h>
+#include <netdb.h>
+#include <arpa/inet.h>
+#include <net/route.h>
+#include <net/ethernet.h>
+#include <net/if.h>
+#include <net/if_arp.h>
+#include <netinet/icmp6.h>
+#include <fcntl.h>
+#include <linux/if_tun.h>
+#include <ctype.h>
+#include <ifaddrs.h>
+#include <linux/fib_rules.h>
+
+#include "connman.h"
+#include <gdhcp/gdhcp.h>
+
+#define NLMSG_TAIL(nmsg)				\
+	((struct rtattr *) (((uint8_t*) (nmsg)) +	\
+	NLMSG_ALIGN((nmsg)->nlmsg_len)))
+
+int __connman_inet_rtnl_addattr_l(struct nlmsghdr *n, size_t max_length,
+				int type, const void *data, size_t data_length)
+{
+	size_t length;
+	struct rtattr *rta;
+
+	length = RTA_LENGTH(data_length);
+
+	if (NLMSG_ALIGN(n->nlmsg_len) + RTA_ALIGN(length) > max_length)
+		return -E2BIG;
+
+	rta = NLMSG_TAIL(n);
+	rta->rta_type = type;
+	rta->rta_len = length;
+	memcpy(RTA_DATA(rta), data, data_length);
+	n->nlmsg_len = NLMSG_ALIGN(n->nlmsg_len) + RTA_ALIGN(length);
+
+	return 0;
+}
+
+int __connman_inet_modify_address(int cmd, int flags,
+				int index, int family,
+				const char *address,
+				const char *peer,
+				unsigned char prefixlen,
+				const char *broadcast)
+{
+	uint8_t request[NLMSG_ALIGN(sizeof(struct nlmsghdr)) +
+			NLMSG_ALIGN(sizeof(struct ifaddrmsg)) +
+			RTA_LENGTH(sizeof(struct in6_addr)) +
+			RTA_LENGTH(sizeof(struct in6_addr))];
+
+	struct nlmsghdr *header;
+	struct sockaddr_nl nl_addr;
+	struct ifaddrmsg *ifaddrmsg;
+	struct in6_addr ipv6_addr;
+	struct in_addr ipv4_addr, ipv4_dest, ipv4_bcast;
+	int sk, err;
+
+	DBG("cmd %#x flags %#x index %d family %d address %s peer %s "
+		"prefixlen %hhu broadcast %s", cmd, flags, index, family,
+		address, peer, prefixlen, broadcast);
+
+	if (!address)
+		return -EINVAL;
+
+	if (family != AF_INET && family != AF_INET6)
+		return -EINVAL;
+
+	memset(&request, 0, sizeof(request));
+
+	header = (struct nlmsghdr *)request;
+	header->nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg));
+	header->nlmsg_type = cmd;
+	header->nlmsg_flags = NLM_F_REQUEST | flags;
+	header->nlmsg_seq = 1;
+
+	ifaddrmsg = NLMSG_DATA(header);
+	ifaddrmsg->ifa_family = family;
+	ifaddrmsg->ifa_prefixlen = prefixlen;
+	ifaddrmsg->ifa_flags = IFA_F_PERMANENT;
+	ifaddrmsg->ifa_scope = RT_SCOPE_UNIVERSE;
+	ifaddrmsg->ifa_index = index;
+
+	if (family == AF_INET) {
+		if (inet_pton(AF_INET, address, &ipv4_addr) < 1)
+			return -1;
+
+		if (broadcast)
+			inet_pton(AF_INET, broadcast, &ipv4_bcast);
+		else
+			ipv4_bcast.s_addr = ipv4_addr.s_addr |
+				htonl(0xfffffffflu >> prefixlen);
+
+		if (peer) {
+			if (inet_pton(AF_INET, peer, &ipv4_dest) < 1)
+				return -1;
+
+			err = __connman_inet_rtnl_addattr_l(header,
+							sizeof(request),
+							IFA_ADDRESS,
+							&ipv4_dest,
+							sizeof(ipv4_dest));
+			if (err < 0)
+				return err;
+		}
+
+		err = __connman_inet_rtnl_addattr_l(header,
+						sizeof(request),
+						IFA_LOCAL,
+						&ipv4_addr,
+						sizeof(ipv4_addr));
+		if (err < 0)
+			return err;
+
+		err = __connman_inet_rtnl_addattr_l(header,
+						sizeof(request),
+						IFA_BROADCAST,
+						&ipv4_bcast,
+						sizeof(ipv4_bcast));
+		if (err < 0)
+			return err;
+
+	} else if (family == AF_INET6) {
+		if (inet_pton(AF_INET6, address, &ipv6_addr) < 1)
+			return -1;
+
+		err = __connman_inet_rtnl_addattr_l(header,
+						sizeof(request),
+						IFA_LOCAL,
+						&ipv6_addr,
+						sizeof(ipv6_addr));
+		if (err < 0)
+			return err;
+	}
+
+	sk = socket(AF_NETLINK, SOCK_DGRAM | SOCK_CLOEXEC, NETLINK_ROUTE);
+	if (sk < 0)
+		return -errno;
+
+	memset(&nl_addr, 0, sizeof(nl_addr));
+	nl_addr.nl_family = AF_NETLINK;
+
+	if ((err = sendto(sk, request, header->nlmsg_len, 0,
+			(struct sockaddr *) &nl_addr, sizeof(nl_addr))) < 0)
+		goto done;
+
+	err = 0;
+
+done:
+	close(sk);
+
+	return err;
+}
+
+int connman_inet_ifindex(const char *name)
+{
+	struct ifreq ifr;
+	int sk, err;
+
+	if (!name)
+		return -1;
+
+	sk = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
+	if (sk < 0)
+		return -1;
+
+	memset(&ifr, 0, sizeof(ifr));
+	strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name) - 1);
+
+	err = ioctl(sk, SIOCGIFINDEX, &ifr);
+
+	close(sk);
+
+	if (err < 0)
+		return -1;
+
+	return ifr.ifr_ifindex;
+}
+
+char *connman_inet_ifname(int index)
+{
+	struct ifreq ifr;
+	int sk, err;
+
+	if (index < 0)
+		return NULL;
+
+	sk = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
+	if (sk < 0)
+		return NULL;
+
+	memset(&ifr, 0, sizeof(ifr));
+	ifr.ifr_ifindex = index;
+
+	err = ioctl(sk, SIOCGIFNAME, &ifr);
+
+	close(sk);
+
+	if (err < 0)
+		return NULL;
+
+	return g_strdup(ifr.ifr_name);
+}
+
+int connman_inet_ifup(int index)
+{
+	struct ifreq ifr;
+	int sk, err;
+
+	sk = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
+	if (sk < 0)
+		return -errno;
+
+	memset(&ifr, 0, sizeof(ifr));
+	ifr.ifr_ifindex = index;
+
+	if (ioctl(sk, SIOCGIFNAME, &ifr) < 0) {
+		err = -errno;
+		goto done;
+	}
+
+	if (ioctl(sk, SIOCGIFFLAGS, &ifr) < 0) {
+		err = -errno;
+		goto done;
+	}
+
+	if (ifr.ifr_flags & IFF_UP) {
+		err = -EALREADY;
+		goto done;
+	}
+
+	ifr.ifr_flags |= (IFF_UP|IFF_DYNAMIC);
+
+	if (ioctl(sk, SIOCSIFFLAGS, &ifr) < 0) {
+		err = -errno;
+		goto done;
+	}
+
+	err = 0;
+
+done:
+	close(sk);
+
+	return err;
+}
+
+int connman_inet_ifdown(int index)
+{
+	struct ifreq ifr, addr_ifr;
+	struct sockaddr_in *addr;
+	int sk, err;
+
+	sk = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
+	if (sk < 0)
+		return -errno;
+
+	memset(&ifr, 0, sizeof(ifr));
+	ifr.ifr_ifindex = index;
+
+	if (ioctl(sk, SIOCGIFNAME, &ifr) < 0) {
+		err = -errno;
+		goto done;
+	}
+
+	if (ioctl(sk, SIOCGIFFLAGS, &ifr) < 0) {
+		err = -errno;
+		goto done;
+	}
+
+	memset(&addr_ifr, 0, sizeof(addr_ifr));
+	memcpy(&addr_ifr.ifr_name, &ifr.ifr_name, sizeof(ifr.ifr_name) - 1);
+	addr = (struct sockaddr_in *)&addr_ifr.ifr_addr;
+	addr->sin_family = AF_INET;
+	if (ioctl(sk, SIOCSIFADDR, &addr_ifr) < 0)
+		connman_warn("Could not clear IPv4 address index %d", index);
+
+	if (!(ifr.ifr_flags & IFF_UP)) {
+		err = -EALREADY;
+		goto done;
+	}
+
+	ifr.ifr_flags = (ifr.ifr_flags & ~IFF_UP) | IFF_DYNAMIC;
+
+	if (ioctl(sk, SIOCSIFFLAGS, &ifr) < 0)
+		err = -errno;
+	else
+		err = 0;
+
+done:
+	close(sk);
+
+	return err;
+}
+
+struct in6_ifreq {
+	struct in6_addr ifr6_addr;
+	__u32 ifr6_prefixlen;
+	unsigned int ifr6_ifindex;
+};
+
+int connman_inet_set_ipv6_address(int index,
+		struct connman_ipaddress *ipaddress)
+{
+	int err;
+	unsigned char prefix_len;
+	const char *address;
+
+	if (!ipaddress->local)
+		return 0;
+
+	prefix_len = ipaddress->prefixlen;
+	address = ipaddress->local;
+
+	DBG("index %d address %s prefix_len %d", index, address, prefix_len);
+
+	err = __connman_inet_modify_address(RTM_NEWADDR,
+				NLM_F_REPLACE | NLM_F_ACK, index, AF_INET6,
+				address, NULL, prefix_len, NULL);
+	if (err < 0) {
+		connman_error("%s: %s", __func__, strerror(-err));
+		return err;
+	}
+
+	return 0;
+}
+
+int connman_inet_set_address(int index, struct connman_ipaddress *ipaddress)
+{
+	int err;
+	unsigned char prefix_len;
+	const char *address, *broadcast, *peer;
+
+	if (!ipaddress->local)
+		return -1;
+
+	prefix_len = ipaddress->prefixlen;
+	address = ipaddress->local;
+	broadcast = ipaddress->broadcast;
+	peer = ipaddress->peer;
+
+	DBG("index %d address %s prefix_len %d", index, address, prefix_len);
+
+	err = __connman_inet_modify_address(RTM_NEWADDR,
+				NLM_F_REPLACE | NLM_F_ACK, index, AF_INET,
+				address, peer, prefix_len, broadcast);
+	if (err < 0) {
+		connman_error("%s: %s", __func__, strerror(-err));
+		return err;
+	}
+
+	return 0;
+}
+
+int connman_inet_clear_ipv6_address(int index, const char *address,
+							int prefix_len)
+{
+	int err;
+
+	DBG("index %d address %s prefix_len %d", index, address, prefix_len);
+
+	if (!address)
+		return -EINVAL;
+
+	err = __connman_inet_modify_address(RTM_DELADDR, 0, index, AF_INET6,
+				address, NULL, prefix_len, NULL);
+	if (err < 0) {
+		connman_error("%s: %s", __func__, strerror(-err));
+		return err;
+	}
+
+	return 0;
+}
+
+int connman_inet_clear_address(int index, struct connman_ipaddress *ipaddress)
+{
+	int err;
+	unsigned char prefix_len;
+	const char *address, *broadcast, *peer;
+
+	prefix_len = ipaddress->prefixlen;
+	address = ipaddress->local;
+	broadcast = ipaddress->broadcast;
+	peer = ipaddress->peer;
+
+	DBG("index %d address %s prefix_len %d peer %s broadcast %s", index,
+		address, prefix_len, peer, broadcast);
+
+	if (!address)
+		return -EINVAL;
+
+	err = __connman_inet_modify_address(RTM_DELADDR, 0, index, AF_INET,
+				address, peer, prefix_len, broadcast);
+	if (err < 0) {
+		connman_error("%s: %s", __func__, strerror(-err));
+		return err;
+	}
+
+	return 0;
+}
+
+int connman_inet_add_host_route(int index, const char *host,
+				const char *gateway)
+{
+	return connman_inet_add_network_route(index, host, gateway, NULL);
+}
+
+int connman_inet_del_host_route(int index, const char *host)
+{
+	return connman_inet_del_network_route(index, host);
+}
+
+int connman_inet_add_network_route(int index, const char *host,
+					const char *gateway,
+					const char *netmask)
+{
+	struct ifreq ifr;
+	struct rtentry rt;
+	struct sockaddr_in addr;
+	int sk, err = 0;
+
+	DBG("index %d host %s gateway %s netmask %s", index,
+		host, gateway, netmask);
+
+	sk = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
+	if (sk < 0) {
+		err = -errno;
+		goto out;
+	}
+
+	memset(&ifr, 0, sizeof(ifr));
+	ifr.ifr_ifindex = index;
+
+	if (ioctl(sk, SIOCGIFNAME, &ifr) < 0) {
+		err = -errno;
+		close(sk);
+		goto out;
+	}
+
+	DBG("ifname %s", ifr.ifr_name);
+
+	memset(&rt, 0, sizeof(rt));
+	rt.rt_flags = RTF_UP;
+	if (gateway)
+		rt.rt_flags |= RTF_GATEWAY;
+	if (!netmask)
+		rt.rt_flags |= RTF_HOST;
+
+	memset(&addr, 0, sizeof(addr));
+	addr.sin_family = AF_INET;
+	addr.sin_addr.s_addr = inet_addr(host);
+	memcpy(&rt.rt_dst, &addr, sizeof(rt.rt_dst));
+
+	memset(&addr, 0, sizeof(addr));
+	addr.sin_family = AF_INET;
+	if (gateway)
+		addr.sin_addr.s_addr = inet_addr(gateway);
+	else
+		addr.sin_addr.s_addr = INADDR_ANY;
+	memcpy(&rt.rt_gateway, &addr, sizeof(rt.rt_gateway));
+
+	memset(&addr, 0, sizeof(addr));
+	addr.sin_family = AF_INET;
+	addr.sin_addr.s_addr = INADDR_ANY;
+	if (netmask)
+		addr.sin_addr.s_addr = inet_addr(netmask);
+	else
+		addr.sin_addr.s_addr = INADDR_ANY;
+	memcpy(&rt.rt_genmask, &addr, sizeof(rt.rt_genmask));
+
+	rt.rt_dev = ifr.ifr_name;
+
+	if (ioctl(sk, SIOCADDRT, &rt) < 0 && errno != EEXIST)
+		err = -errno;
+
+	close(sk);
+
+out:
+	if (err < 0)
+		connman_error("Adding host route failed (%s)",
+							strerror(-err));
+
+	return err;
+}
+
+int connman_inet_del_network_route(int index, const char *host)
+{
+	struct ifreq ifr;
+	struct rtentry rt;
+	struct sockaddr_in addr;
+	int sk, err = 0;
+
+	DBG("index %d host %s", index, host);
+
+	sk = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
+	if (sk < 0) {
+		err = -errno;
+		goto out;
+	}
+
+	memset(&ifr, 0, sizeof(ifr));
+	ifr.ifr_ifindex = index;
+
+	if (ioctl(sk, SIOCGIFNAME, &ifr) < 0) {
+		err = -errno;
+		close(sk);
+		goto out;
+	}
+
+	DBG("ifname %s", ifr.ifr_name);
+
+	memset(&rt, 0, sizeof(rt));
+	rt.rt_flags = RTF_UP | RTF_HOST;
+
+	memset(&addr, 0, sizeof(addr));
+	addr.sin_family = AF_INET;
+	addr.sin_addr.s_addr = inet_addr(host);
+	memcpy(&rt.rt_dst, &addr, sizeof(rt.rt_dst));
+
+	rt.rt_dev = ifr.ifr_name;
+
+	if (ioctl(sk, SIOCDELRT, &rt) < 0 && errno != ESRCH)
+		err = -errno;
+
+	close(sk);
+
+out:
+	if (err < 0)
+		connman_error("Deleting host route failed (%s)",
+							strerror(-err));
+
+	return err;
+}
+
+int connman_inet_del_ipv6_network_route(int index, const char *host,
+						unsigned char prefix_len)
+{
+	struct in6_rtmsg rt;
+	int sk, err = 0;
+
+	DBG("index %d host %s", index, host);
+
+	if (!host)
+		return -EINVAL;
+
+	memset(&rt, 0, sizeof(rt));
+
+	rt.rtmsg_dst_len = prefix_len;
+
+	if (inet_pton(AF_INET6, host, &rt.rtmsg_dst) < 0) {
+		err = -errno;
+		goto out;
+	}
+
+	rt.rtmsg_flags = RTF_UP | RTF_HOST;
+
+	rt.rtmsg_metric = 1;
+	rt.rtmsg_ifindex = index;
+
+	sk = socket(AF_INET6, SOCK_DGRAM | SOCK_CLOEXEC, 0);
+	if (sk < 0) {
+		err = -errno;
+		goto out;
+	}
+
+	if (ioctl(sk, SIOCDELRT, &rt) < 0 && errno != ESRCH)
+		err = -errno;
+
+	close(sk);
+
+out:
+	if (err < 0)
+		connman_error("Del IPv6 host route error (%s)",
+						strerror(-err));
+
+	return err;
+}
+
+int connman_inet_del_ipv6_host_route(int index, const char *host)
+{
+	return connman_inet_del_ipv6_network_route(index, host, 128);
+}
+
+int connman_inet_add_ipv6_network_route(int index, const char *host,
+					const char *gateway,
+					unsigned char prefix_len)
+{
+	struct in6_rtmsg rt;
+	int sk, err = 0;
+
+	DBG("index %d host %s gateway %s", index, host, gateway);
+
+	if (!host)
+		return -EINVAL;
+
+	memset(&rt, 0, sizeof(rt));
+
+	rt.rtmsg_dst_len = prefix_len;
+
+	if (inet_pton(AF_INET6, host, &rt.rtmsg_dst) < 0) {
+		err = -errno;
+		goto out;
+	}
+
+	rt.rtmsg_flags = RTF_UP | RTF_HOST;
+
+	if (gateway) {
+		rt.rtmsg_flags |= RTF_GATEWAY;
+		inet_pton(AF_INET6, gateway, &rt.rtmsg_gateway);
+	}
+
+	rt.rtmsg_metric = 1;
+	rt.rtmsg_ifindex = index;
+
+	sk = socket(AF_INET6, SOCK_DGRAM | SOCK_CLOEXEC, 0);
+	if (sk < 0) {
+		err = -errno;
+		goto out;
+	}
+
+	if (ioctl(sk, SIOCADDRT, &rt) < 0 && errno != EEXIST)
+		err = -errno;
+
+	close(sk);
+
+out:
+	if (err < 0)
+		connman_error("Set IPv6 host route error (%s)",
+						strerror(-err));
+
+	return err;
+}
+
+int connman_inet_add_ipv6_host_route(int index, const char *host,
+					const char *gateway)
+{
+	return connman_inet_add_ipv6_network_route(index, host, gateway, 128);
+}
+
+int connman_inet_clear_ipv6_gateway_address(int index, const char *gateway)
+{
+	struct in6_rtmsg rt;
+	int sk, err = 0;
+
+	DBG("index %d gateway %s", index, gateway);
+
+	if (!gateway)
+		return -EINVAL;
+
+	memset(&rt, 0, sizeof(rt));
+
+	if (inet_pton(AF_INET6, gateway, &rt.rtmsg_gateway) < 0) {
+		err = -errno;
+		goto out;
+	}
+
+	rt.rtmsg_flags = RTF_UP | RTF_GATEWAY;
+	rt.rtmsg_metric = 1;
+	rt.rtmsg_dst_len = 0;
+	rt.rtmsg_ifindex = index;
+
+	sk = socket(AF_INET6, SOCK_DGRAM | SOCK_CLOEXEC, 0);
+	if (sk < 0) {
+		err = -errno;
+		goto out;
+	}
+
+	if (ioctl(sk, SIOCDELRT, &rt) < 0 && errno != ESRCH)
+		err = -errno;
+
+	close(sk);
+
+out:
+	if (err < 0)
+		connman_error("Clear default IPv6 gateway error (%s)",
+						strerror(-err));
+
+	return err;
+}
+
+int connman_inet_set_gateway_interface(int index)
+{
+	struct ifreq ifr;
+	struct rtentry rt;
+	struct sockaddr_in addr;
+	int sk, err = 0;
+
+	DBG("index %d", index);
+
+	sk = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
+	if (sk < 0) {
+		err = -errno;
+		goto out;
+	}
+
+	memset(&ifr, 0, sizeof(ifr));
+	ifr.ifr_ifindex = index;
+
+	if (ioctl(sk, SIOCGIFNAME, &ifr) < 0) {
+		err = -errno;
+		close(sk);
+		goto out;
+	}
+
+	DBG("ifname %s", ifr.ifr_name);
+
+	memset(&rt, 0, sizeof(rt));
+	rt.rt_flags = RTF_UP;
+
+	memset(&addr, 0, sizeof(addr));
+	addr.sin_family = AF_INET;
+	addr.sin_addr.s_addr = INADDR_ANY;
+
+	memcpy(&rt.rt_genmask, &addr, sizeof(rt.rt_genmask));
+	memcpy(&rt.rt_dst, &addr, sizeof(rt.rt_dst));
+	memcpy(&rt.rt_gateway, &addr, sizeof(rt.rt_gateway));
+
+	rt.rt_dev = ifr.ifr_name;
+
+	if (ioctl(sk, SIOCADDRT, &rt) < 0 && errno != EEXIST)
+		err = -errno;
+
+	close(sk);
+
+out:
+	if (err < 0)
+		connman_error("Setting default interface route failed (%s)",
+							strerror(-err));
+
+	return err;
+}
+
+int connman_inet_set_ipv6_gateway_interface(int index)
+{
+	struct ifreq ifr;
+	struct rtentry rt;
+	struct sockaddr_in6 addr;
+	const struct in6_addr any = IN6ADDR_ANY_INIT;
+	int sk, err = 0;
+
+	DBG("index %d", index);
+
+	sk = socket(PF_INET6, SOCK_DGRAM | SOCK_CLOEXEC, 0);
+	if (sk < 0) {
+		err = -errno;
+		goto out;
+	}
+
+	memset(&ifr, 0, sizeof(ifr));
+	ifr.ifr_ifindex = index;
+
+	if (ioctl(sk, SIOCGIFNAME, &ifr) < 0) {
+		err = -errno;
+		close(sk);
+		goto out;
+	}
+
+	DBG("ifname %s", ifr.ifr_name);
+
+	memset(&rt, 0, sizeof(rt));
+	rt.rt_flags = RTF_UP;
+
+	memset(&addr, 0, sizeof(addr));
+	addr.sin6_family = AF_INET6;
+	addr.sin6_addr = any;
+
+	memcpy(&rt.rt_genmask, &addr, sizeof(rt.rt_genmask));
+	memcpy(&rt.rt_dst, &addr, sizeof(rt.rt_dst));
+	memcpy(&rt.rt_gateway, &addr, sizeof(rt.rt_gateway));
+
+	rt.rt_dev = ifr.ifr_name;
+
+	if (ioctl(sk, SIOCADDRT, &rt) < 0 && errno != EEXIST)
+		err = -errno;
+
+	close(sk);
+
+out:
+	if (err < 0)
+		connman_error("Setting default interface route failed (%s)",
+							strerror(-err));
+
+	return err;
+}
+
+int connman_inet_clear_gateway_address(int index, const char *gateway)
+{
+	struct ifreq ifr;
+	struct rtentry rt;
+	struct sockaddr_in addr;
+	int sk, err = 0;
+
+	DBG("index %d gateway %s", index, gateway);
+
+	sk = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
+	if (sk < 0) {
+		err = -errno;
+		goto out;
+	}
+
+	memset(&ifr, 0, sizeof(ifr));
+	ifr.ifr_ifindex = index;
+
+	if (ioctl(sk, SIOCGIFNAME, &ifr) < 0) {
+		err = -errno;
+		close(sk);
+		goto out;
+	}
+
+	DBG("ifname %s", ifr.ifr_name);
+
+	memset(&rt, 0, sizeof(rt));
+	rt.rt_flags = RTF_UP | RTF_GATEWAY;
+
+	memset(&addr, 0, sizeof(addr));
+	addr.sin_family = AF_INET;
+	addr.sin_addr.s_addr = INADDR_ANY;
+	memcpy(&rt.rt_dst, &addr, sizeof(rt.rt_dst));
+
+	memset(&addr, 0, sizeof(addr));
+	addr.sin_family = AF_INET;
+	addr.sin_addr.s_addr = inet_addr(gateway);
+	memcpy(&rt.rt_gateway, &addr, sizeof(rt.rt_gateway));
+
+	memset(&addr, 0, sizeof(addr));
+	addr.sin_family = AF_INET;
+	addr.sin_addr.s_addr = INADDR_ANY;
+	memcpy(&rt.rt_genmask, &addr, sizeof(rt.rt_genmask));
+
+	if (ioctl(sk, SIOCDELRT, &rt) < 0 && errno != ESRCH)
+		err = -errno;
+
+	close(sk);
+
+out:
+	if (err < 0)
+		connman_error("Removing default gateway route failed (%s)",
+							strerror(-err));
+
+	return err;
+}
+
+int connman_inet_clear_gateway_interface(int index)
+{
+	struct ifreq ifr;
+	struct rtentry rt;
+	struct sockaddr_in addr;
+	int sk, err = 0;
+
+	DBG("index %d", index);
+
+	sk = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
+	if (sk < 0) {
+		err = -errno;
+		goto out;
+	}
+
+	memset(&ifr, 0, sizeof(ifr));
+	ifr.ifr_ifindex = index;
+
+	if (ioctl(sk, SIOCGIFNAME, &ifr) < 0) {
+		err = -errno;
+		close(sk);
+		goto out;
+	}
+
+	DBG("ifname %s", ifr.ifr_name);
+
+	memset(&rt, 0, sizeof(rt));
+	rt.rt_flags = RTF_UP;
+
+	memset(&addr, 0, sizeof(addr));
+	addr.sin_family = AF_INET;
+	addr.sin_addr.s_addr = INADDR_ANY;
+
+	memcpy(&rt.rt_genmask, &addr, sizeof(rt.rt_genmask));
+	memcpy(&rt.rt_dst, &addr, sizeof(rt.rt_dst));
+	memcpy(&rt.rt_gateway, &addr, sizeof(rt.rt_gateway));
+
+	rt.rt_dev = ifr.ifr_name;
+
+	if (ioctl(sk, SIOCDELRT, &rt) < 0 && errno != ESRCH)
+		err = -errno;
+
+	close(sk);
+
+out:
+	if (err < 0)
+		connman_error("Removing default interface route failed (%s)",
+							strerror(-err));
+
+	return err;
+}
+
+int connman_inet_clear_ipv6_gateway_interface(int index)
+{
+	struct ifreq ifr;
+	struct rtentry rt;
+	struct sockaddr_in6 addr;
+	const struct in6_addr any = IN6ADDR_ANY_INIT;
+	int sk, err = 0;
+
+	DBG("index %d", index);
+
+	sk = socket(PF_INET6, SOCK_DGRAM | SOCK_CLOEXEC, 0);
+	if (sk < 0) {
+		err = -errno;
+		goto out;
+	}
+
+	memset(&ifr, 0, sizeof(ifr));
+	ifr.ifr_ifindex = index;
+
+	if (ioctl(sk, SIOCGIFNAME, &ifr) < 0) {
+		err = -errno;
+		close(sk);
+		goto out;
+	}
+
+	DBG("ifname %s", ifr.ifr_name);
+
+	memset(&rt, 0, sizeof(rt));
+	rt.rt_flags = RTF_UP;
+
+	memset(&addr, 0, sizeof(addr));
+	addr.sin6_family = AF_INET6;
+	addr.sin6_addr = any;
+
+	memcpy(&rt.rt_genmask, &addr, sizeof(rt.rt_genmask));
+	memcpy(&rt.rt_dst, &addr, sizeof(rt.rt_dst));
+	memcpy(&rt.rt_gateway, &addr, sizeof(rt.rt_gateway));
+
+	rt.rt_dev = ifr.ifr_name;
+
+	if (ioctl(sk, SIOCDELRT, &rt) < 0 && errno != ESRCH)
+		err = -errno;
+
+	close(sk);
+
+out:
+	if (err < 0)
+		connman_error("Removing default interface route failed (%s)",
+							strerror(-err));
+
+	return err;
+}
+
+bool connman_inet_compare_subnet(int index, const char *host)
+{
+	struct ifreq ifr;
+	struct in_addr _host_addr;
+	in_addr_t host_addr, netmask_addr, if_addr;
+	struct sockaddr_in *netmask, *addr;
+	int sk;
+
+	DBG("host %s", host);
+
+	if (!host)
+		return false;
+
+	if (inet_aton(host, &_host_addr) == 0)
+		return -1;
+	host_addr = _host_addr.s_addr;
+
+	sk = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
+	if (sk < 0)
+		return false;
+
+	memset(&ifr, 0, sizeof(ifr));
+	ifr.ifr_ifindex = index;
+
+	if (ioctl(sk, SIOCGIFNAME, &ifr) < 0) {
+		close(sk);
+		return false;
+	}
+
+	if (ioctl(sk, SIOCGIFNETMASK, &ifr) < 0) {
+		close(sk);
+		return false;
+	}
+
+	netmask = (struct sockaddr_in *)&ifr.ifr_netmask;
+	netmask_addr = netmask->sin_addr.s_addr;
+
+	if (ioctl(sk, SIOCGIFADDR, &ifr) < 0) {
+		close(sk);
+		return false;
+	}
+
+	close(sk);
+
+	addr = (struct sockaddr_in *)&ifr.ifr_addr;
+	if_addr = addr->sin_addr.s_addr;
+
+	return ((if_addr & netmask_addr) == (host_addr & netmask_addr));
+}
+
+int connman_inet_remove_from_bridge(int index, const char *bridge)
+{
+	struct ifreq ifr;
+	int sk, err = 0;
+
+	if (!bridge)
+		return -EINVAL;
+
+	sk = socket(AF_INET, SOCK_STREAM | SOCK_CLOEXEC, 0);
+	if (sk < 0) {
+		err = -errno;
+		goto out;
+	}
+
+	memset(&ifr, 0, sizeof(ifr));
+	strncpy(ifr.ifr_name, bridge, sizeof(ifr.ifr_name) - 1);
+	ifr.ifr_ifindex = index;
+
+	if (ioctl(sk, SIOCBRDELIF, &ifr) < 0)
+		err = -errno;
+
+	close(sk);
+
+out:
+	if (err < 0)
+		connman_error("Remove interface from bridge error %s",
+							strerror(-err));
+
+	return err;
+}
+
+int connman_inet_add_to_bridge(int index, const char *bridge)
+{
+	struct ifreq ifr;
+	int sk, err = 0;
+
+	if (!bridge)
+		return -EINVAL;
+
+	sk = socket(AF_INET, SOCK_STREAM | SOCK_CLOEXEC, 0);
+	if (sk < 0) {
+		err = -errno;
+		goto out;
+	}
+
+	memset(&ifr, 0, sizeof(ifr));
+	strncpy(ifr.ifr_name, bridge, sizeof(ifr.ifr_name) - 1);
+	ifr.ifr_ifindex = index;
+
+	if (ioctl(sk, SIOCBRADDIF, &ifr) < 0)
+		err = -errno;
+
+	close(sk);
+
+out:
+	if (err < 0)
+		connman_error("Add interface to bridge error %s",
+							strerror(-err));
+
+	return err;
+}
+
+int connman_inet_set_mtu(int index, int mtu)
+{
+	struct ifreq ifr;
+	int sk, err;
+
+	sk = socket(AF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
+	if (sk < 0)
+		return sk;
+
+	memset(&ifr, 0, sizeof(ifr));
+	ifr.ifr_ifindex = index;
+
+	err = ioctl(sk, SIOCGIFNAME, &ifr);
+	if (err == 0) {
+		ifr.ifr_mtu = mtu;
+		err = ioctl(sk, SIOCSIFMTU, &ifr);
+	}
+
+	close(sk);
+	return err;
+}
+
+int connman_inet_setup_tunnel(char *tunnel, int mtu)
+{
+	struct ifreq ifr;
+	int sk, err, index;
+	__u32 mask;
+	__u32 flags;
+
+	if (!tunnel)
+		return -EINVAL;
+
+	sk = socket(AF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
+	if (sk < 0)
+		return sk;
+
+	index = if_nametoindex(tunnel);
+
+	err = connman_inet_set_mtu(index, mtu);
+	if (err != 0)
+		goto done;
+
+	memset(&ifr, 0, sizeof(ifr));
+	strncpy(ifr.ifr_name, tunnel, sizeof(ifr.ifr_name) - 1);
+	err = ioctl(sk, SIOCGIFFLAGS, &ifr);
+	if (err)
+		goto done;
+
+	mask = IFF_UP;
+	flags = IFF_UP;
+
+	if ((ifr.ifr_flags ^ flags) & mask) {
+		ifr.ifr_flags &= ~mask;
+		ifr.ifr_flags |= mask & flags;
+		err = ioctl(sk, SIOCSIFFLAGS, &ifr);
+		if (err)
+			connman_error("SIOCSIFFLAGS failed: %s",
+							strerror(errno));
+	}
+
+done:
+	close(sk);
+	return err;
+}
+
+int connman_inet_create_tunnel(char **iface)
+{
+	struct ifreq ifr;
+	int i, fd;
+
+	fd = open("/dev/net/tun", O_RDWR | O_CLOEXEC);
+	if (fd < 0) {
+		i = -errno;
+		connman_error("Failed to open /dev/net/tun: %s",
+				strerror(errno));
+		return i;
+	}
+
+	memset(&ifr, 0, sizeof(ifr));
+	ifr.ifr_flags = IFF_TUN | IFF_NO_PI;
+
+	for (i = 0; i < 256; i++) {
+		sprintf(ifr.ifr_name, "tun%d", i);
+
+		if (!ioctl(fd, TUNSETIFF, (void *)&ifr))
+			break;
+	}
+
+	if (i == 256) {
+		connman_error("Failed to find available tun device");
+		close(fd);
+		return -ENODEV;
+	}
+
+	*iface = g_strdup(ifr.ifr_name);
+
+	return fd;
+}
+
+/*
+ * This callback struct is used when sending router and neighbor
+ * solicitation and advertisement messages.
+ */
+struct xs_cb_data {
+	GIOChannel *channel;
+	void *callback;
+	struct sockaddr_in6 addr;
+	guint timeout;
+	guint watch_id;
+	void *user_data;
+};
+
+#define CMSG_BUF_LEN 512
+#define IN6ADDR_ALL_NODES_MC_INIT \
+	{ { { 0xff,0x02,0,0,0,0,0,0,0,0,0,0,0,0,0,0x1 } } } /* ff02::1 */
+#define IN6ADDR_ALL_ROUTERS_MC_INIT \
+	{ { { 0xff,0x02,0,0,0,0,0,0,0,0,0,0,0,0,0,0x2 } } } /* ff02::2 */
+
+static const struct in6_addr in6addr_all_nodes_mc = IN6ADDR_ALL_NODES_MC_INIT;
+static const struct in6_addr in6addr_all_routers_mc =
+						IN6ADDR_ALL_ROUTERS_MC_INIT;
+
+static void xs_cleanup(struct xs_cb_data *data)
+{
+	if (data->channel) {
+		g_io_channel_shutdown(data->channel, TRUE, NULL);
+		g_io_channel_unref(data->channel);
+		data->channel = NULL;
+	}
+
+	if (data->timeout > 0)
+		g_source_remove(data->timeout);
+
+	if (data->watch_id > 0)
+		g_source_remove(data->watch_id);
+
+	g_free(data);
+}
+
+static gboolean rs_timeout_cb(gpointer user_data)
+{
+	struct xs_cb_data *data = user_data;
+
+	DBG("user data %p", user_data);
+
+	if (!data)
+		return FALSE;
+
+	if (data->callback) {
+		__connman_inet_rs_cb_t cb = data->callback;
+		cb(NULL, 0, data->user_data);
+	}
+
+	data->timeout = 0;
+	xs_cleanup(data);
+	return FALSE;
+}
+
+static int icmpv6_recv(int fd, gpointer user_data)
+{
+	struct msghdr mhdr;
+	struct iovec iov;
+	unsigned char chdr[CMSG_BUF_LEN];
+	unsigned char buf[1540];
+	struct xs_cb_data *data = user_data;
+	struct nd_router_advert *hdr;
+	struct sockaddr_in6 saddr;
+	ssize_t len;
+	__connman_inet_rs_cb_t cb = data->callback;
+
+	DBG("");
+
+	iov.iov_len = sizeof(buf);
+	iov.iov_base = buf;
+
+	mhdr.msg_name = (void *)&saddr;
+	mhdr.msg_namelen = sizeof(struct sockaddr_in6);
+	mhdr.msg_flags = 0;
+	mhdr.msg_iov = &iov;
+	mhdr.msg_iovlen = 1;
+	mhdr.msg_control = (void *)chdr;
+	mhdr.msg_controllen = CMSG_BUF_LEN;
+
+	len = recvmsg(fd, &mhdr, 0);
+	if (len < 0) {
+		cb(NULL, 0, data->user_data);
+		xs_cleanup(data);
+		return -errno;
+	}
+
+	hdr = (struct nd_router_advert *)buf;
+	DBG("code %d len %zd hdr %zd", hdr->nd_ra_code, len,
+				sizeof(struct nd_router_advert));
+	if (hdr->nd_ra_code != 0)
+		return 0;
+
+	cb(hdr, len, data->user_data);
+	xs_cleanup(data);
+
+	return len;
+}
+
+static gboolean icmpv6_event(GIOChannel *chan, GIOCondition cond, gpointer data)
+{
+	int fd, ret;
+
+	DBG("");
+
+	if (cond & (G_IO_NVAL | G_IO_HUP | G_IO_ERR))
+		return FALSE;
+
+	fd = g_io_channel_unix_get_fd(chan);
+	ret = icmpv6_recv(fd, data);
+	if (ret == 0)
+		return TRUE;
+
+	return FALSE;
+}
+
+/* Adapted from RFC 1071 "C" Implementation Example */
+static uint16_t csum(const void *phdr, const void *data, socklen_t datalen,
+		const void *extra_data, socklen_t extra_datalen)
+{
+	register unsigned long sum = 0;
+	socklen_t count;
+	uint16_t *addr;
+	int i;
+
+	/* caller must make sure datalen is even */
+
+	addr = (uint16_t *)phdr;
+	for (i = 0; i < 20; i++)
+		sum += *addr++;
+
+	count = datalen;
+	addr = (uint16_t *)data;
+
+	while (count > 1) {
+		sum += *(addr++);
+		count -= 2;
+	}
+
+	if (extra_data) {
+		count = extra_datalen;
+		addr = (uint16_t *)extra_data;
+
+		while (count > 1) {
+			sum += *(addr++);
+			count -= 2;
+		}
+	}
+
+	while (sum >> 16)
+		sum = (sum & 0xffff) + (sum >> 16);
+
+	return (uint16_t)~sum;
+}
+
+static int ndisc_send_unspec(int type, int oif, const struct in6_addr *dest,
+			const struct in6_addr *source,
+			unsigned char *buf, size_t len, uint16_t lifetime)
+{
+	struct _phdr {
+		struct in6_addr src;
+		struct in6_addr dst;
+		uint32_t plen;
+		uint8_t reserved[3];
+		uint8_t nxt;
+	} phdr;
+
+	struct {
+		struct ip6_hdr ip;
+		union {
+			struct icmp6_hdr icmp;
+			struct nd_neighbor_solicit ns;
+			struct nd_router_solicit rs;
+			struct nd_router_advert ra;
+		} i;
+	} frame;
+
+	struct msghdr msgh;
+	struct cmsghdr *cmsg;
+	struct in6_pktinfo *pinfo;
+	struct sockaddr_in6 dst, src;
+	char cbuf[CMSG_SPACE(sizeof(*pinfo))];
+	struct iovec iov[2];
+	int fd, datalen, ret, iovlen = 1;
+
+	DBG("");
+
+	fd = socket(AF_INET6, SOCK_RAW | SOCK_CLOEXEC, IPPROTO_RAW);
+	if (fd < 0)
+		return -errno;
+
+	memset(&frame, 0, sizeof(frame));
+	memset(&dst, 0, sizeof(dst));
+
+	if (type == ND_ROUTER_SOLICIT)
+		datalen = sizeof(frame.i.rs); /* 8, csum() safe */
+	else if (type == ND_ROUTER_ADVERT) {
+		datalen = sizeof(frame.i.ra); /* 16, csum() safe */
+		frame.i.ra.nd_ra_router_lifetime = htons(lifetime);
+	} else if (type == ND_NEIGHBOR_SOLICIT) {
+		datalen = sizeof(frame.i.ns); /* 24, csum() safe */
+		memcpy(&frame.i.ns.nd_ns_target, buf, sizeof(struct in6_addr));
+	} else {
+		close(fd);
+		return -EINVAL;
+	}
+
+	dst.sin6_addr = *dest;
+
+	if (source)
+		src.sin6_addr = *source;
+	else
+		src.sin6_addr = in6addr_any;
+
+	/* Fill in the IPv6 header */
+	frame.ip.ip6_vfc = 0x60;
+	frame.ip.ip6_plen = htons(datalen + len);
+	frame.ip.ip6_nxt = IPPROTO_ICMPV6;
+	frame.ip.ip6_hlim = 255;
+	frame.ip.ip6_dst = dst.sin6_addr;
+	frame.ip.ip6_src = src.sin6_addr;
+	/* all other fields are already set to zero */
+
+	/* Prepare pseudo header for csum */
+	memset(&phdr, 0, sizeof(phdr));
+	phdr.dst = dst.sin6_addr;
+	phdr.src = src.sin6_addr;
+	phdr.plen = htonl(datalen + len);
+	phdr.nxt = IPPROTO_ICMPV6;
+
+	/* Fill in remaining ICMP header fields */
+	frame.i.icmp.icmp6_type = type;
+	frame.i.icmp.icmp6_cksum = csum(&phdr, &frame.i, datalen, buf, len);
+
+	iov[0].iov_base = &frame;
+	iov[0].iov_len = sizeof(frame.ip) + datalen;
+
+	if (buf) {
+		iov[1].iov_base = buf;
+		iov[1].iov_len = len;
+		iovlen = 2;
+	}
+
+	dst.sin6_family = AF_INET6;
+	msgh.msg_name = &dst;
+	msgh.msg_namelen = sizeof(dst);
+	msgh.msg_iov = iov;
+	msgh.msg_iovlen = iovlen;
+	msgh.msg_flags = 0;
+
+	memset(cbuf, 0, CMSG_SPACE(sizeof(*pinfo)));
+	cmsg = (struct cmsghdr *)cbuf;
+	pinfo = (struct in6_pktinfo *)CMSG_DATA(cmsg);
+	pinfo->ipi6_ifindex = oif;
+
+	cmsg->cmsg_len = CMSG_LEN(sizeof(*pinfo));
+	cmsg->cmsg_level = IPPROTO_IPV6;
+	cmsg->cmsg_type = IPV6_PKTINFO;
+	msgh.msg_control = cmsg;
+	msgh.msg_controllen = cmsg->cmsg_len;
+
+	ret = sendmsg(fd, &msgh, 0);
+
+	close(fd);
+	return ret;
+}
+
+static inline void ipv6_addr_set(struct in6_addr *addr,
+				uint32_t w1, uint32_t w2,
+				uint32_t w3, uint32_t w4)
+{
+	addr->s6_addr32[0] = w1;
+	addr->s6_addr32[1] = w2;
+	addr->s6_addr32[2] = w3;
+	addr->s6_addr32[3] = w4;
+}
+
+static inline void ipv6_addr_solict_mult(const struct in6_addr *addr,
+					struct in6_addr *solicited)
+{
+	ipv6_addr_set(solicited, htonl(0xFF020000), 0, htonl(0x1),
+			htonl(0xFF000000) | addr->s6_addr32[3]);
+}
+
+static int if_mc_group(int sock, int ifindex, const struct in6_addr *mc_addr,
+								int cmd)
+{
+	unsigned int val = 0;
+	struct ipv6_mreq mreq;
+	int ret;
+
+	memset(&mreq, 0, sizeof(mreq));
+	mreq.ipv6mr_interface = ifindex;
+	mreq.ipv6mr_multiaddr = *mc_addr;
+
+	ret = setsockopt(sock, IPPROTO_IPV6, IPV6_MULTICAST_LOOP,
+			&val, sizeof(int));
+	if (ret < 0) {
+		ret = -errno;
+		DBG("Cannot set IPV6_MULTICAST_LOOP %d/%s", ret,
+			strerror(-ret));
+		return ret;
+	}
+
+	ret = setsockopt(sock, IPPROTO_IPV6, cmd, &mreq, sizeof(mreq));
+	if (ret < 0) {
+		ret = -errno;
+		DBG("Cannot set option %d %d/%s", cmd, ret, strerror(-ret));
+		return ret;
+	}
+
+	return 0;
+}
+
+int __connman_inet_ipv6_send_rs(int index, int timeout,
+			__connman_inet_rs_cb_t callback, void *user_data)
+{
+	struct xs_cb_data *data;
+	struct icmp6_filter filter;
+	struct in6_addr solicit;
+	struct in6_addr dst = in6addr_all_routers_mc;
+	int sk;
+
+	if (timeout <= 0)
+		return -EINVAL;
+
+	data = g_try_malloc0(sizeof(struct xs_cb_data));
+	if (!data)
+		return -ENOMEM;
+
+	data->callback = callback;
+	data->user_data = user_data;
+	data->timeout = g_timeout_add_seconds(timeout, rs_timeout_cb, data);
+
+	sk = socket(AF_INET6, SOCK_RAW | SOCK_CLOEXEC, IPPROTO_ICMPV6);
+	if (sk < 0)
+		return -errno;
+
+	DBG("sock %d", sk);
+
+	ICMP6_FILTER_SETBLOCKALL(&filter);
+	ICMP6_FILTER_SETPASS(ND_ROUTER_ADVERT, &filter);
+
+	setsockopt(sk, IPPROTO_ICMPV6, ICMP6_FILTER, &filter,
+						sizeof(struct icmp6_filter));
+
+	ipv6_addr_solict_mult(&dst, &solicit);
+	if_mc_group(sk, index, &in6addr_all_nodes_mc, IPV6_JOIN_GROUP);
+	if_mc_group(sk, index, &solicit, IPV6_JOIN_GROUP);
+
+	data->channel = g_io_channel_unix_new(sk);
+	g_io_channel_set_close_on_unref(data->channel, TRUE);
+
+	g_io_channel_set_encoding(data->channel, NULL, NULL);
+	g_io_channel_set_buffered(data->channel, FALSE);
+
+	data->watch_id = g_io_add_watch(data->channel,
+			G_IO_IN | G_IO_NVAL | G_IO_HUP | G_IO_ERR,
+			icmpv6_event, data);
+
+	ndisc_send_unspec(ND_ROUTER_SOLICIT, index, &dst, NULL, NULL, 0, 0);
+
+	return 0;
+}
+
+static inline void ipv6_addr_advert_mult(const struct in6_addr *addr,
+					struct in6_addr *advert)
+{
+	ipv6_addr_set(advert, htonl(0xFF020000), 0, htonl(0x2),
+			htonl(0xFF000000) | addr->s6_addr32[3]);
+}
+
+#define MSG_SIZE_SEND 1452
+
+static int inc_len(int len, int inc)
+{
+	if (len > MSG_SIZE_SEND)
+		return -EINVAL;
+
+	len += inc;
+	return len;
+}
+
+int __connman_inet_ipv6_send_ra(int index, struct in6_addr *src_addr,
+				GSList *prefixes, int router_lifetime)
+{
+	GSList *list;
+	struct in6_addr src, *source;
+	struct in6_addr dst = in6addr_all_nodes_mc;
+	GDHCPIAPrefix *prefix;
+	unsigned char buf[MSG_SIZE_SEND];
+	char addr_str[INET6_ADDRSTRLEN];
+	int sk, err = 0;
+	int len, count = 0;
+
+	if (!prefixes)
+		return -EINVAL;
+
+	sk = socket(AF_INET6, SOCK_RAW | SOCK_CLOEXEC, IPPROTO_ICMPV6);
+	if (sk < 0)
+		return -errno;
+
+	if (!src_addr) {
+		__connman_inet_get_interface_ll_address(index, AF_INET6, &src);
+		source = &src;
+	} else
+		source = src_addr;
+
+	DBG("sock %d index %d prefixes %p src %s lifetime %d", sk, index,
+		prefixes, inet_ntop(AF_INET6, source, addr_str,
+				INET6_ADDRSTRLEN),
+		router_lifetime);
+
+	memset(buf, 0, MSG_SIZE_SEND);
+	len = 0;
+
+	for (list = prefixes; list; list = list->next) {
+		struct nd_opt_prefix_info *pinfo;
+
+		prefix = list->data;
+		pinfo = (struct nd_opt_prefix_info *)(buf + len);
+
+		len = inc_len(len, sizeof(*pinfo));
+		if (len < 0) {
+			err = len;
+			goto out;
+		}
+
+		pinfo->nd_opt_pi_type = ND_OPT_PREFIX_INFORMATION;
+		pinfo->nd_opt_pi_len = 4;
+		pinfo->nd_opt_pi_prefix_len = prefix->prefixlen;
+		pinfo->nd_opt_pi_flags_reserved = ND_OPT_PI_FLAG_ONLINK;
+		pinfo->nd_opt_pi_flags_reserved	|= ND_OPT_PI_FLAG_AUTO;
+		if (router_lifetime > 0) {
+			pinfo->nd_opt_pi_valid_time = htonl(prefix->valid);
+			pinfo->nd_opt_pi_preferred_time =
+						htonl(prefix->preferred);
+		}
+		pinfo->nd_opt_pi_reserved2 = 0;
+
+		memcpy(&pinfo->nd_opt_pi_prefix, &prefix->prefix,
+						sizeof(struct in6_addr));
+
+		DBG("[%d] index %d prefix %s/%d", count, index,
+			inet_ntop(AF_INET6, &prefix->prefix, addr_str,
+				INET6_ADDRSTRLEN), prefix->prefixlen);
+
+		count++;
+	}
+
+	if (count > 0) {
+		err = ndisc_send_unspec(ND_ROUTER_ADVERT, index, &dst, source,
+					buf, len, router_lifetime);
+		if (err < 0)
+			DBG("cannot send RA %d/%s", err, strerror(-err));
+	}
+
+out:
+	close(sk);
+	return err;
+}
+
+void __connman_inet_ipv6_stop_recv_rs(void *context)
+{
+	if (!context)
+		return;
+
+	xs_cleanup(context);
+}
+
+static int icmpv6_rs_recv(int fd, gpointer user_data)
+{
+	struct msghdr mhdr;
+	struct iovec iov;
+	unsigned char chdr[CMSG_BUF_LEN];
+	unsigned char buf[1540];
+	struct xs_cb_data *data = user_data;
+	struct nd_router_solicit *hdr;
+	struct sockaddr_in6 saddr;
+	ssize_t len;
+	__connman_inet_recv_rs_cb_t cb = data->callback;
+
+	DBG("");
+
+	iov.iov_len = sizeof(buf);
+	iov.iov_base = buf;
+
+	mhdr.msg_name = (void *)&saddr;
+	mhdr.msg_namelen = sizeof(struct sockaddr_in6);
+	mhdr.msg_flags = 0;
+	mhdr.msg_iov = &iov;
+	mhdr.msg_iovlen = 1;
+	mhdr.msg_control = (void *)chdr;
+	mhdr.msg_controllen = CMSG_BUF_LEN;
+
+	len = recvmsg(fd, &mhdr, 0);
+	if (len < 0) {
+		cb(NULL, 0, data->user_data);
+		return -errno;
+	}
+
+	hdr = (struct nd_router_solicit *)buf;
+	DBG("code %d len %zd hdr %zd", hdr->nd_rs_code, len,
+				sizeof(struct nd_router_solicit));
+	if (hdr->nd_rs_code != 0)
+		return 0;
+
+	cb(hdr, len, data->user_data);
+	return len;
+}
+
+static gboolean icmpv6_rs_event(GIOChannel *chan, GIOCondition cond,
+								gpointer data)
+{
+	int fd, ret;
+
+	DBG("");
+
+	if (cond & (G_IO_NVAL | G_IO_HUP | G_IO_ERR))
+		return FALSE;
+
+	fd = g_io_channel_unix_get_fd(chan);
+	ret = icmpv6_rs_recv(fd, data);
+	if (ret == 0)
+		return TRUE;
+
+	return FALSE;
+}
+
+int __connman_inet_ipv6_start_recv_rs(int index,
+					__connman_inet_recv_rs_cb_t callback,
+					void *user_data,
+					void **context)
+{
+	struct xs_cb_data *data;
+	struct icmp6_filter filter;
+	char addr_str[INET6_ADDRSTRLEN];
+	int sk, err;
+
+	data = g_try_malloc0(sizeof(struct xs_cb_data));
+	if (!data)
+		return -ENOMEM;
+
+	data->callback = callback;
+	data->user_data = user_data;
+
+	sk = socket(AF_INET6, SOCK_RAW | SOCK_CLOEXEC, IPPROTO_ICMPV6);
+	if (sk < 0) {
+		g_free(data);
+		return -errno;
+	}
+
+	DBG("sock %d", sk);
+
+	ICMP6_FILTER_SETBLOCKALL(&filter);
+	ICMP6_FILTER_SETPASS(ND_ROUTER_SOLICIT, &filter);
+
+	setsockopt(sk, IPPROTO_ICMPV6, ICMP6_FILTER, &filter,
+						sizeof(struct icmp6_filter));
+
+	err = if_mc_group(sk, index, &in6addr_all_routers_mc, IPV6_JOIN_GROUP);
+	if (err < 0)
+		DBG("Cannot join mc %s %d/%s", inet_ntop(AF_INET6,
+			&in6addr_all_routers_mc, addr_str, INET6_ADDRSTRLEN),
+			err, strerror(-err));
+
+	data->channel = g_io_channel_unix_new(sk);
+	g_io_channel_set_close_on_unref(data->channel, TRUE);
+
+	g_io_channel_set_encoding(data->channel, NULL, NULL);
+	g_io_channel_set_buffered(data->channel, FALSE);
+
+	data->watch_id = g_io_add_watch(data->channel,
+			G_IO_IN | G_IO_NVAL | G_IO_HUP | G_IO_ERR,
+			icmpv6_rs_event, data);
+
+	*context = data;
+
+	return 0;
+}
+
+static gboolean ns_timeout_cb(gpointer user_data)
+{
+	struct xs_cb_data *data = user_data;
+
+	DBG("user data %p", user_data);
+
+	if (!data)
+		return FALSE;
+
+	if (data->callback) {
+		__connman_inet_ns_cb_t cb = data->callback;
+		cb(NULL, 0, &data->addr.sin6_addr, data->user_data);
+	}
+
+	data->timeout = 0;
+	xs_cleanup(data);
+	return FALSE;
+}
+
+static int icmpv6_nd_recv(int fd, gpointer user_data)
+{
+	struct msghdr mhdr;
+	struct iovec iov;
+	unsigned char chdr[CMSG_BUF_LEN];
+	unsigned char buf[1540];
+	struct xs_cb_data *data = user_data;
+	struct nd_neighbor_advert *hdr;
+	struct sockaddr_in6 saddr;
+	ssize_t len;
+	__connman_inet_ns_cb_t cb = data->callback;
+
+	DBG("");
+
+	iov.iov_len = sizeof(buf);
+	iov.iov_base = buf;
+
+	mhdr.msg_name = (void *)&saddr;
+	mhdr.msg_namelen = sizeof(struct sockaddr_in6);
+	mhdr.msg_flags = 0;
+	mhdr.msg_iov = &iov;
+	mhdr.msg_iovlen = 1;
+	mhdr.msg_control = (void *)chdr;
+	mhdr.msg_controllen = CMSG_BUF_LEN;
+
+	len = recvmsg(fd, &mhdr, 0);
+	if (len < 0) {
+		cb(NULL, 0, &data->addr.sin6_addr, data->user_data);
+		xs_cleanup(data);
+		return -errno;
+	}
+
+	hdr = (struct nd_neighbor_advert *)buf;
+	DBG("code %d len %zd hdr %zd", hdr->nd_na_code, len,
+				sizeof(struct nd_neighbor_advert));
+	if (hdr->nd_na_code != 0)
+		return 0;
+
+	/*
+	 * We can receive any neighbor advertisement so we need to check if the
+	 * packet was meant for us and ignore the packet otherwise.
+	 */
+	if (memcmp(&data->addr.sin6_addr, &hdr->nd_na_target,
+			sizeof(struct in6_addr)))
+		return 0;
+
+	cb(hdr, len, &data->addr.sin6_addr, data->user_data);
+	xs_cleanup(data);
+
+	return len;
+}
+
+static gboolean icmpv6_nd_event(GIOChannel *chan, GIOCondition cond,
+								gpointer data)
+{
+	int fd, ret;
+
+	DBG("");
+
+	if (cond & (G_IO_NVAL | G_IO_HUP | G_IO_ERR))
+		return FALSE;
+
+	fd = g_io_channel_unix_get_fd(chan);
+	ret = icmpv6_nd_recv(fd, data);
+	if (ret == 0)
+		return TRUE;
+
+	return FALSE;
+}
+
+int __connman_inet_ipv6_do_dad(int index, int timeout_ms,
+				struct in6_addr *addr,
+				__connman_inet_ns_cb_t callback,
+				void *user_data)
+{
+	struct xs_cb_data *data;
+	struct icmp6_filter filter;
+	struct in6_addr solicit;
+	int sk, err, val = 1;
+
+	if (timeout_ms <= 0)
+		return -EINVAL;
+
+	data = g_try_malloc0(sizeof(struct xs_cb_data));
+	if (!data)
+		return -ENOMEM;
+
+	data->callback = callback;
+	data->user_data = user_data;
+	data->timeout = g_timeout_add_full(G_PRIORITY_DEFAULT,
+					(guint)timeout_ms,
+					ns_timeout_cb,
+					data,
+                                        NULL);
+	memcpy(&data->addr.sin6_addr, addr, sizeof(struct in6_addr));
+
+	sk = socket(AF_INET6, SOCK_RAW | SOCK_CLOEXEC, IPPROTO_ICMPV6);
+	if (sk < 0)
+		return -errno;
+
+	DBG("sock %d", sk);
+
+	ICMP6_FILTER_SETBLOCKALL(&filter);
+	ICMP6_FILTER_SETPASS(ND_NEIGHBOR_ADVERT, &filter);
+
+	setsockopt(sk, IPPROTO_ICMPV6, ICMP6_FILTER, &filter,
+						sizeof(struct icmp6_filter));
+
+        if (setsockopt(sk, IPPROTO_IPV6, IPV6_RECVPKTINFO,
+						&val, sizeof(val)) < 0) {
+		err = -errno;
+                DBG("Cannot set IPV6_RECVPKTINFO %d/%s", err,
+							strerror(-err));
+		close(sk);
+		return err;
+        }
+
+        if (setsockopt(sk, IPPROTO_IPV6, IPV6_RECVHOPLIMIT,
+						&val, sizeof(val)) < 0) {
+		err = -errno;
+                DBG("Cannot set IPV6_RECVHOPLIMIT %d/%s", err,
+							strerror(-err));
+		close(sk);
+		return err;
+        }
+
+	val = 0;
+	setsockopt(sk, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, &val, sizeof(val));
+
+	ipv6_addr_solict_mult(addr, &solicit);
+	if_mc_group(sk, index, &in6addr_all_nodes_mc, IPV6_JOIN_GROUP);
+	if_mc_group(sk, index, &solicit, IPV6_JOIN_GROUP);
+
+	data->channel = g_io_channel_unix_new(sk);
+	g_io_channel_set_close_on_unref(data->channel, TRUE);
+
+	g_io_channel_set_encoding(data->channel, NULL, NULL);
+	g_io_channel_set_buffered(data->channel, FALSE);
+
+	data->watch_id = g_io_add_watch(data->channel,
+			G_IO_IN | G_IO_NVAL | G_IO_HUP | G_IO_ERR,
+			icmpv6_nd_event, data);
+
+	err = ndisc_send_unspec(ND_NEIGHBOR_SOLICIT, index, &solicit, NULL,
+			(unsigned char *)addr, 0, 0);
+	if (err < 0) {
+		DBG("Cannot send NS %d/%s", err, strerror(-err));
+		xs_cleanup(data);
+	}
+
+	return err;
+}
+
+GSList *__connman_inet_ipv6_get_prefixes(struct nd_router_advert *hdr,
+					unsigned int length)
+{
+	GSList *prefixes = NULL;
+	uint8_t *pos;
+	int len;
+
+	if (length <= sizeof(struct nd_router_advert))
+		return NULL;
+
+	len = length - sizeof(struct nd_router_advert);
+	pos = (uint8_t *)hdr + sizeof(struct nd_router_advert);
+
+	while (len > 0) {
+		struct nd_opt_prefix_info *pinfo;
+		char prefix_str[INET6_ADDRSTRLEN+1], *str;
+		const char *prefix;
+		int optlen;
+
+		if (len < 2)
+			break;
+
+		optlen = pos[1] << 3;
+		if (optlen == 0 || optlen > len)
+			break;
+
+		switch (pos[0]) {
+		case ND_OPT_PREFIX_INFORMATION:
+			pinfo = (struct nd_opt_prefix_info *)pos;
+			prefix = inet_ntop(AF_INET6, &pinfo->nd_opt_pi_prefix,
+					prefix_str, INET6_ADDRSTRLEN);
+			if (!prefix)
+				break;
+
+			str = g_strdup_printf("%s/%d", prefix,
+						pinfo->nd_opt_pi_prefix_len);
+			prefixes = g_slist_prepend(prefixes, str);
+
+			DBG("prefix %s", str);
+
+			break;
+		}
+
+		len -= optlen;
+		pos += optlen;
+	}
+
+	return prefixes;
+}
+
+static int get_dest_addr(int family, int index, char *buf, int len)
+{
+	struct ifreq ifr;
+	void *addr;
+	int sk;
+
+	sk = socket(family, SOCK_DGRAM | SOCK_CLOEXEC, 0);
+	if (sk < 0)
+		return -errno;
+
+	memset(&ifr, 0, sizeof(ifr));
+	ifr.ifr_ifindex = index;
+
+	if (ioctl(sk, SIOCGIFNAME, &ifr) < 0) {
+		DBG("SIOCGIFNAME (%d/%s)", errno, strerror(errno));
+		close(sk);
+		return -errno;
+	}
+
+	if (ioctl(sk, SIOCGIFFLAGS, &ifr) < 0) {
+		DBG("SIOCGIFFLAGS (%d/%s)", errno, strerror(errno));
+		close(sk);
+		return -errno;
+	}
+
+	if ((ifr.ifr_flags & IFF_POINTOPOINT) == 0) {
+		close(sk);
+		errno = EINVAL;
+		return -errno;
+	}
+
+	DBG("index %d %s", index, ifr.ifr_name);
+
+	if (ioctl(sk, SIOCGIFDSTADDR, &ifr) < 0) {
+		connman_error("Get destination address failed (%s)",
+							strerror(errno));
+		close(sk);
+		return -errno;
+	}
+
+	close(sk);
+
+	switch (family) {
+	case AF_INET:
+		addr = &((struct sockaddr_in *)&ifr.ifr_dstaddr)->sin_addr;
+		break;
+	case AF_INET6:
+		addr = &((struct sockaddr_in6 *)&ifr.ifr_dstaddr)->sin6_addr;
+		break;
+	default:
+		errno = EINVAL;
+		return -errno;
+	}
+
+	if (!inet_ntop(family, addr, buf, len)) {
+		DBG("error %d/%s", errno, strerror(errno));
+		return -errno;
+	}
+
+	return 0;
+}
+
+int connman_inet_get_dest_addr(int index, char **dest)
+{
+	char addr[INET_ADDRSTRLEN];
+	int ret;
+
+	ret = get_dest_addr(PF_INET, index, addr, INET_ADDRSTRLEN);
+	if (ret < 0)
+		return ret;
+
+	*dest = g_strdup(addr);
+
+	DBG("destination %s", *dest);
+
+	return 0;
+}
+
+int connman_inet_ipv6_get_dest_addr(int index, char **dest)
+{
+	char addr[INET6_ADDRSTRLEN];
+	int ret;
+
+	ret = get_dest_addr(PF_INET6, index, addr, INET6_ADDRSTRLEN);
+	if (ret < 0)
+		return ret;
+
+	*dest = g_strdup(addr);
+
+	DBG("destination %s", *dest);
+
+	return 0;
+}
+
+int __connman_inet_rtnl_open(struct __connman_inet_rtnl_handle *rth)
+{
+	int sndbuf = 1024;
+	int rcvbuf = 1024 * 4;
+
+	rth->fd = socket(AF_NETLINK, SOCK_RAW | SOCK_CLOEXEC, NETLINK_ROUTE);
+	if (rth->fd < 0) {
+		connman_error("Can not open netlink socket: %s",
+						strerror(errno));
+		return -errno;
+	}
+
+	if (setsockopt(rth->fd, SOL_SOCKET, SO_SNDBUF, &sndbuf,
+			sizeof(sndbuf)) < 0) {
+		connman_error("SO_SNDBUF: %s", strerror(errno));
+		return -errno;
+	}
+
+	if (setsockopt(rth->fd, SOL_SOCKET, SO_RCVBUF, &rcvbuf,
+			sizeof(rcvbuf)) < 0) {
+		connman_error("SO_RCVBUF: %s", strerror(errno));
+		return -errno;
+	}
+
+	memset(&rth->local, 0, sizeof(rth->local));
+	rth->local.nl_family = AF_NETLINK;
+	rth->local.nl_groups = 0;
+
+	if (bind(rth->fd, (struct sockaddr *)&rth->local,
+						sizeof(rth->local)) < 0) {
+		connman_error("Can not bind netlink socket: %s",
+							strerror(errno));
+		return -errno;
+	}
+
+	rth->seq = time(NULL);
+
+	DBG("fd %d", rth->fd);
+
+	return 0;
+}
+
+struct inet_rtnl_cb_data {
+	GIOChannel *channel;
+	__connman_inet_rtnl_cb_t callback;
+	guint rtnl_timeout;
+	guint watch_id;
+	struct __connman_inet_rtnl_handle *rtnl;
+	void *user_data;
+};
+
+static void inet_rtnl_cleanup(struct inet_rtnl_cb_data *data)
+{
+	struct __connman_inet_rtnl_handle *rth = data->rtnl;
+
+	if (data->channel) {
+		g_io_channel_shutdown(data->channel, TRUE, NULL);
+		g_io_channel_unref(data->channel);
+		data->channel = NULL;
+	}
+
+	DBG("data %p", data);
+
+	if (data->rtnl_timeout > 0)
+		g_source_remove(data->rtnl_timeout);
+
+	if (data->watch_id > 0)
+		g_source_remove(data->watch_id);
+
+	if (rth) {
+		__connman_inet_rtnl_close(rth);
+		g_free(rth);
+	}
+
+	g_free(data);
+}
+
+static gboolean inet_rtnl_timeout_cb(gpointer user_data)
+{
+	struct inet_rtnl_cb_data *data = user_data;
+
+	DBG("user data %p", user_data);
+
+	if (!data)
+		return FALSE;
+
+	if (data->callback)
+		data->callback(NULL, data->user_data);
+
+	data->rtnl_timeout = 0;
+	inet_rtnl_cleanup(data);
+	return FALSE;
+}
+
+static int inet_rtnl_recv(GIOChannel *chan, gpointer user_data)
+{
+	struct inet_rtnl_cb_data *rtnl_data = user_data;
+	struct __connman_inet_rtnl_handle *rth = rtnl_data->rtnl;
+	struct nlmsghdr *h = NULL;
+	struct sockaddr_nl nladdr;
+	socklen_t addr_len = sizeof(nladdr);
+	unsigned char buf[4096];
+	void *ptr = buf;
+	gsize len;
+	int status, fd;
+
+	memset(buf, 0, sizeof(buf));
+	memset(&nladdr, 0, sizeof(nladdr));
+
+	fd = g_io_channel_unix_get_fd(chan);
+
+	status = recvfrom(fd, buf, sizeof(buf), 0,
+                       (struct sockaddr *) &nladdr, &addr_len);
+	if (status < 0) {
+		if (errno == EINTR || errno == EAGAIN)
+			return 0;
+
+		return -1;
+	}
+
+	if (status == 0)
+		return -1;
+
+	if (nladdr.nl_pid != 0) { /* not sent by kernel, ignore */
+		DBG("Received msg from %u, ignoring it", nladdr.nl_pid);
+		return 0;
+	}
+
+	len = status;
+
+	while (len > 0) {
+		struct nlmsgerr *err;
+
+		h = ptr;
+
+		if (!NLMSG_OK(h, len))
+			return -1;
+
+		if (h->nlmsg_seq != rth->seq) {
+			/* Skip this msg */
+			DBG("skip %d/%d len %d", rth->seq,
+				h->nlmsg_seq, h->nlmsg_len);
+
+			len -= h->nlmsg_len;
+			ptr += h->nlmsg_len;
+			continue;
+		}
+
+		switch (h->nlmsg_type) {
+		case NLMSG_NOOP:
+		case NLMSG_OVERRUN:
+			return -1;
+
+		case NLMSG_ERROR:
+			err = (struct nlmsgerr *)NLMSG_DATA(h);
+			connman_error("RTNETLINK answers %s (%d)",
+				strerror(-err->error), -err->error);
+			return err->error;
+		}
+
+		break;
+	}
+
+	if (h->nlmsg_seq == rth->seq) {
+		DBG("received %d seq %d", h->nlmsg_len, h->nlmsg_seq);
+
+		rtnl_data->callback(h, rtnl_data->user_data);
+
+		inet_rtnl_cleanup(rtnl_data);
+	}
+
+	return 0;
+}
+
+static gboolean inet_rtnl_event(GIOChannel *chan, GIOCondition cond,
+							gpointer user_data)
+{
+	int ret;
+
+	DBG("");
+
+	if (cond & (G_IO_NVAL | G_IO_HUP | G_IO_ERR))
+		return FALSE;
+
+	ret = inet_rtnl_recv(chan, user_data);
+	if (ret != 0)
+		return TRUE;
+
+	return FALSE;
+}
+
+int __connman_inet_rtnl_talk(struct __connman_inet_rtnl_handle *rtnl,
+			struct nlmsghdr *n, int timeout,
+			__connman_inet_rtnl_cb_t callback, void *user_data)
+{
+	struct sockaddr_nl nladdr;
+	struct inet_rtnl_cb_data *data;
+	unsigned seq;
+	int err;
+
+	memset(&nladdr, 0, sizeof(nladdr));
+	nladdr.nl_family = AF_NETLINK;
+
+	n->nlmsg_seq = seq = ++rtnl->seq;
+
+	if (callback) {
+		data = g_try_malloc0(sizeof(struct inet_rtnl_cb_data));
+		if (!data)
+			return -ENOMEM;
+
+		data->callback = callback;
+		data->user_data = user_data;
+		data->rtnl = rtnl;
+		data->rtnl_timeout = g_timeout_add_seconds(timeout,
+						inet_rtnl_timeout_cb, data);
+
+		data->channel = g_io_channel_unix_new(rtnl->fd);
+		g_io_channel_set_close_on_unref(data->channel, TRUE);
+
+		g_io_channel_set_encoding(data->channel, NULL, NULL);
+		g_io_channel_set_buffered(data->channel, FALSE);
+
+		data->watch_id = g_io_add_watch(data->channel,
+				G_IO_IN | G_IO_NVAL | G_IO_HUP | G_IO_ERR,
+						inet_rtnl_event, data);
+	} else
+		n->nlmsg_flags |= NLM_F_ACK;
+
+	err = sendto(rtnl->fd, &rtnl->req.n, rtnl->req.n.nlmsg_len, 0,
+		(struct sockaddr *) &nladdr, sizeof(nladdr));
+	DBG("handle %p len %d", rtnl, rtnl->req.n.nlmsg_len);
+	if (err < 0) {
+		connman_error("Can not talk to rtnetlink err %d %s",
+			-errno, strerror(errno));
+		return -errno;
+	}
+
+	if ((unsigned int)err != rtnl->req.n.nlmsg_len) {
+		connman_error("Sent %d bytes, msg truncated", err);
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+void __connman_inet_rtnl_close(struct __connman_inet_rtnl_handle *rth)
+{
+	DBG("handle %p", rth);
+
+	if (rth->fd >= 0) {
+		close(rth->fd);
+		rth->fd = -1;
+	}
+}
+
+int __connman_inet_rtnl_addattr32(struct nlmsghdr *n, size_t maxlen, int type,
+				__u32 data)
+{
+	int len = RTA_LENGTH(4);
+	struct rtattr *rta;
+
+	if (NLMSG_ALIGN(n->nlmsg_len) + len > maxlen) {
+		DBG("Error! max allowed bound %zd exceeded", maxlen);
+		return -1;
+	}
+	rta = NLMSG_TAIL(n);
+	rta->rta_type = type;
+	rta->rta_len = len;
+	memcpy(RTA_DATA(rta), &data, 4);
+	n->nlmsg_len = NLMSG_ALIGN(n->nlmsg_len) + len;
+
+	return 0;
+}
+
+static int parse_rtattr(struct rtattr *tb[], int max,
+			struct rtattr *rta, int len)
+{
+	memset(tb, 0, sizeof(struct rtattr *) * (max + 1));
+	while (RTA_OK(rta, len)) {
+		if ((rta->rta_type <= max) && (!tb[rta->rta_type]))
+			tb[rta->rta_type] = rta;
+		rta = RTA_NEXT(rta, len);
+	}
+	if (len)
+		connman_error("Deficit %d, rta_len=%d", len, rta->rta_len);
+
+	return 0;
+}
+
+struct get_route_cb_data {
+	connman_inet_addr_cb_t callback;
+	void *user_data;
+};
+
+static void get_route_cb(struct nlmsghdr *answer, void *user_data)
+{
+	struct get_route_cb_data *data = user_data;
+	struct rtattr *tb[RTA_MAX+1];
+	struct rtmsg *r = NLMSG_DATA(answer);
+	int len, index = -1;
+	char abuf[256];
+	const char *addr = NULL;
+
+	DBG("answer %p data %p", answer, user_data);
+
+	if (!answer)
+		goto out;
+
+	len = answer->nlmsg_len;
+
+	if (answer->nlmsg_type != RTM_NEWROUTE &&
+				answer->nlmsg_type != RTM_DELROUTE) {
+		connman_error("Not a route: %08x %08x %08x",
+			answer->nlmsg_len, answer->nlmsg_type,
+			answer->nlmsg_flags);
+		goto out;
+	}
+
+	len -= NLMSG_LENGTH(sizeof(*r));
+	if (len < 0) {
+		connman_error("BUG: wrong nlmsg len %d", len);
+		goto out;
+	}
+
+	parse_rtattr(tb, RTA_MAX, RTM_RTA(r), len);
+
+	if (tb[RTA_OIF])
+		index = *(int *)RTA_DATA(tb[RTA_OIF]);
+
+	if (tb[RTA_GATEWAY])
+		addr = inet_ntop(r->rtm_family,
+				RTA_DATA(tb[RTA_GATEWAY]),
+				abuf, sizeof(abuf));
+
+	DBG("addr %s index %d user %p", addr, index, data->user_data);
+
+out:
+	if (data && data->callback)
+		data->callback(addr, index, data->user_data);
+
+	g_free(data);
+
+	return;
+}
+
+/*
+ * Return the interface index that contains route to host.
+ */
+int __connman_inet_get_route(const char *dest_address,
+			connman_inet_addr_cb_t callback, void *user_data)
+{
+	struct get_route_cb_data *data;
+	struct addrinfo hints, *rp;
+	struct __connman_inet_rtnl_handle *rth;
+	int err;
+
+	DBG("dest %s", dest_address);
+
+	if (!dest_address)
+		return -EINVAL;
+
+	memset(&hints, 0, sizeof(hints));
+	hints.ai_family = AF_UNSPEC;
+	hints.ai_flags = AI_PASSIVE | AI_NUMERICSERV | AI_NUMERICHOST;
+
+	err = getaddrinfo(dest_address, NULL, &hints, &rp);
+	if (err)
+		return -EINVAL;
+
+	rth = g_try_malloc0(sizeof(struct __connman_inet_rtnl_handle));
+	if (!rth) {
+		freeaddrinfo(rp);
+		return -ENOMEM;
+	}
+
+	rth->req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg));
+	rth->req.n.nlmsg_flags = NLM_F_REQUEST;
+	rth->req.n.nlmsg_type = RTM_GETROUTE;
+	rth->req.u.r.rt.rtm_family = rp->ai_family;
+	rth->req.u.r.rt.rtm_table = 0;
+	rth->req.u.r.rt.rtm_protocol = 0;
+	rth->req.u.r.rt.rtm_scope = 0;
+	rth->req.u.r.rt.rtm_type = 0;
+	rth->req.u.r.rt.rtm_src_len = 0;
+	rth->req.u.r.rt.rtm_dst_len = rp->ai_addrlen << 3;
+	rth->req.u.r.rt.rtm_tos = 0;
+
+	__connman_inet_rtnl_addattr_l(&rth->req.n, sizeof(rth->req), RTA_DST,
+				&rp->ai_addr, rp->ai_addrlen);
+
+	freeaddrinfo(rp);
+
+	err = __connman_inet_rtnl_open(rth);
+	if (err < 0)
+		goto fail;
+
+	data = g_try_malloc(sizeof(struct get_route_cb_data));
+	if (!data) {
+		err = -ENOMEM;
+		goto done;
+	}
+
+	data->callback = callback;
+	data->user_data = user_data;
+
+#define GET_ROUTE_TIMEOUT 2
+	err = __connman_inet_rtnl_talk(rth, &rth->req.n, GET_ROUTE_TIMEOUT,
+				get_route_cb, data);
+	if (err < 0) {
+		g_free(data);
+		goto done;
+	}
+
+	return 0;
+
+done:
+	__connman_inet_rtnl_close(rth);
+
+fail:
+	g_free(rth);
+	return err;
+}
+
+int connman_inet_check_ipaddress(const char *host)
+{
+	struct addrinfo hints;
+	struct addrinfo *addr;
+	int result;
+
+	memset(&hints, 0, sizeof(struct addrinfo));
+	hints.ai_flags = AI_NUMERICHOST;
+	addr = NULL;
+
+	result = getaddrinfo(host, NULL, &hints, &addr);
+	if (result == 0)
+		result = addr->ai_family;
+	freeaddrinfo(addr);
+
+	return result;
+}
+
+/* Check routine modified from ics-dhcp 4.2.3-P2 */
+bool connman_inet_check_hostname(const char *ptr, size_t len)
+{
+	const char *p;
+
+	/*
+	 * Not empty or complete length not over 255 characters.
+	 */
+	if ((len == 0) || (len > 256))
+		return false;
+
+	/*
+	 * Consists of [[:alnum:]-]+ labels separated by [.]
+	 * a [_] is against RFC but seems to be "widely used"
+	 */
+	for (p = ptr; (*p != 0) && (len-- > 0); p++) {
+
+		if ((*p == '-') || (*p == '_')) {
+			/*
+			 * Not allowed at begin or end of a label.
+			 */
+			if (((p - ptr) == 0) || (len == 0) || (p[1] == '.'))
+				return false;
+
+		} else if (*p == '.') {
+			/*
+			 * Each label has to be 1-63 characters;
+			 * we allow [.] at the end ('foo.bar.')
+			 */
+			size_t d = p - ptr;
+
+			if ((d <= 0) || (d >= 64))
+				return false;
+
+			ptr = p + 1; /* Jump to the next label */
+
+		} else if (isalnum((unsigned char)*p) == 0) {
+			/*
+			 * Also numbers at the begin are fine
+			 */
+			return false;
+		}
+	}
+
+	return true;
+}
+
+char **__connman_inet_get_running_interfaces(void)
+{
+	char **result;
+	struct ifconf ifc;
+	struct ifreq *ifr = NULL;
+	int sk, i, numif, count = 0;
+
+	memset(&ifc, 0, sizeof(ifc));
+
+	sk = socket(AF_INET, SOCK_DGRAM, 0);
+	if (sk < 0)
+		return NULL;
+
+	if (ioctl(sk, SIOCGIFCONF, &ifc) < 0)
+		goto error;
+
+	/*
+	 * Allocate some extra bytes just in case there will
+	 * be new interfaces added between two SIOCGIFCONF
+	 * calls.
+	 */
+	ifr = g_try_malloc0(ifc.ifc_len * 2);
+	if (!ifr)
+		goto error;
+
+	ifc.ifc_req = ifr;
+
+	if (ioctl(sk, SIOCGIFCONF, &ifc) < 0)
+		goto error;
+
+	numif = ifc.ifc_len / sizeof(struct ifreq);
+
+	result = g_try_malloc0((numif + 1) * sizeof(char *));
+	if (!result)
+		goto error;
+
+	close(sk);
+
+	for (i = 0; i < numif; i++) {
+		struct ifreq *r = &ifr[i];
+		struct in6_addr *addr6;
+		in_addr_t addr4;
+
+		/*
+		 * Note that we do not return loopback interfaces here as they
+		 * are not needed for our purposes.
+		 */
+		switch (r->ifr_addr.sa_family) {
+		case AF_INET:
+			addr4 = ntohl(((struct sockaddr_in *)
+						&r->ifr_addr)->sin_addr.s_addr);
+			if (((addr4 & 0xff000000) >> 24) == 127)
+				continue;
+			break;
+		case AF_INET6:
+			addr6 = &((struct sockaddr_in6 *)
+						&r->ifr_addr)->sin6_addr;
+			if (IN6_IS_ADDR_LINKLOCAL(addr6))
+				continue;
+			break;
+		}
+
+		result[count++] = g_strdup(r->ifr_name);
+	}
+
+	g_free(ifr);
+
+	if (count < numif)
+		result = g_try_realloc(result, (count + 1) * sizeof(char *));
+
+	return result;
+
+error:
+	close(sk);
+	g_free(ifr);
+	return NULL;
+}
+
+bool connman_inet_is_ipv6_supported()
+{
+	int sk;
+
+	sk = socket(PF_INET6, SOCK_DGRAM | SOCK_CLOEXEC, 0);
+	if (sk < 0)
+		return false;
+
+	close(sk);
+	return true;
+}
+
+int __connman_inet_get_interface_address(int index, int family, void *address)
+{
+	struct ifaddrs *ifaddr, *ifa;
+	int err = -ENOENT;
+	char name[IF_NAMESIZE];
+
+	if (!if_indextoname(index, name))
+		return -EINVAL;
+
+	DBG("index %d interface %s", index, name);
+
+	if (getifaddrs(&ifaddr) < 0) {
+		err = -errno;
+		DBG("Cannot get addresses err %d/%s", err, strerror(-err));
+		return err;
+	}
+
+	for (ifa = ifaddr; ifa; ifa = ifa->ifa_next) {
+		if (!ifa->ifa_addr)
+			continue;
+
+		if (strncmp(ifa->ifa_name, name, IF_NAMESIZE) == 0 &&
+					ifa->ifa_addr->sa_family == family) {
+			if (family == AF_INET) {
+				struct sockaddr_in *in4 = (struct sockaddr_in *)
+					ifa->ifa_addr;
+				if (in4->sin_addr.s_addr == INADDR_ANY)
+					continue;
+				memcpy(address, &in4->sin_addr,
+							sizeof(struct in_addr));
+			} else if (family == AF_INET6) {
+				struct sockaddr_in6 *in6 =
+					(struct sockaddr_in6 *)ifa->ifa_addr;
+				if (memcmp(&in6->sin6_addr, &in6addr_any,
+						sizeof(struct in6_addr)) == 0)
+					continue;
+				memcpy(address, &in6->sin6_addr,
+						sizeof(struct in6_addr));
+
+			} else {
+				err = -EINVAL;
+				goto out;
+			}
+
+			err = 0;
+			break;
+		}
+	}
+
+out:
+	freeifaddrs(ifaddr);
+	return err;
+}
+
+static int iprule_modify(int cmd, int family, uint32_t table_id,
+			uint32_t fwmark)
+{
+	struct __connman_inet_rtnl_handle rth;
+	int ret;
+
+	memset(&rth, 0, sizeof(rth));
+
+	rth.req.n.nlmsg_type = cmd;
+	rth.req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg));
+	rth.req.n.nlmsg_flags = NLM_F_REQUEST;
+	rth.req.u.r.rt.rtm_family = family;
+	rth.req.u.r.rt.rtm_protocol = RTPROT_BOOT;
+	rth.req.u.r.rt.rtm_scope = RT_SCOPE_UNIVERSE;
+	rth.req.u.r.rt.rtm_table = table_id;
+	rth.req.u.r.rt.rtm_type = RTN_UNSPEC;
+	rth.req.u.r.rt.rtm_flags = 0;
+
+	if (cmd == RTM_NEWRULE) {
+		rth.req.n.nlmsg_flags |= NLM_F_CREATE|NLM_F_EXCL;
+		rth.req.u.r.rt.rtm_type = RTN_UNICAST;
+	}
+
+	__connman_inet_rtnl_addattr32(&rth.req.n, sizeof(rth.req),
+							FRA_FWMARK, fwmark);
+
+	if (table_id < 256) {
+		rth.req.u.r.rt.rtm_table = table_id;
+	} else {
+		rth.req.u.r.rt.rtm_table = RT_TABLE_UNSPEC;
+		__connman_inet_rtnl_addattr32(&rth.req.n, sizeof(rth.req),
+						FRA_TABLE, table_id);
+	}
+
+	if (rth.req.u.r.rt.rtm_family == AF_UNSPEC)
+		rth.req.u.r.rt.rtm_family = AF_INET;
+
+	ret = __connman_inet_rtnl_open(&rth);
+	if (ret < 0)
+		goto done;
+
+	ret = __connman_inet_rtnl_send(&rth, &rth.req.n);
+
+done:
+	__connman_inet_rtnl_close(&rth);
+
+	return ret;
+}
+
+int __connman_inet_add_fwmark_rule(uint32_t table_id, int family, uint32_t fwmark)
+{
+	/* ip rule add fwmark 9876 table 1234 */
+
+	return iprule_modify(RTM_NEWRULE, family, table_id, fwmark);
+}
+
+int __connman_inet_del_fwmark_rule(uint32_t table_id, int family, uint32_t fwmark)
+{
+	return iprule_modify(RTM_DELRULE, family, table_id, fwmark);
+}
+
+static int iproute_default_modify(int cmd, uint32_t table_id, int ifindex,
+			const char *gateway)
+{
+	struct __connman_inet_rtnl_handle rth;
+	unsigned char buf[sizeof(struct in6_addr)];
+	int ret, len;
+	int family = connman_inet_check_ipaddress(gateway);
+
+	switch (family) {
+	case AF_INET:
+		len = 4;
+		break;
+	case AF_INET6:
+		len = 16;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	ret = inet_pton(family, gateway, buf);
+	if (ret <= 0)
+		return -EINVAL;
+
+	memset(&rth, 0, sizeof(rth));
+
+	rth.req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg));
+	rth.req.n.nlmsg_flags = NLM_F_REQUEST | NLM_F_CREATE | NLM_F_EXCL;
+	rth.req.n.nlmsg_type = cmd;
+	rth.req.u.r.rt.rtm_family = family;
+	rth.req.u.r.rt.rtm_table = RT_TABLE_MAIN;
+	rth.req.u.r.rt.rtm_scope = RT_SCOPE_NOWHERE;
+	rth.req.u.r.rt.rtm_protocol = RTPROT_BOOT;
+	rth.req.u.r.rt.rtm_scope = RT_SCOPE_UNIVERSE;
+	rth.req.u.r.rt.rtm_type = RTN_UNICAST;
+
+	__connman_inet_rtnl_addattr_l(&rth.req.n, sizeof(rth.req), RTA_GATEWAY,
+								buf, len);
+	if (table_id < 256) {
+		rth.req.u.r.rt.rtm_table = table_id;
+	} else {
+		rth.req.u.r.rt.rtm_table = RT_TABLE_UNSPEC;
+		__connman_inet_rtnl_addattr32(&rth.req.n, sizeof(rth.req),
+							RTA_TABLE, table_id);
+	}
+
+	__connman_inet_rtnl_addattr32(&rth.req.n, sizeof(rth.req),
+							RTA_OIF, ifindex);
+
+	ret = __connman_inet_rtnl_open(&rth);
+	if (ret < 0)
+		goto done;
+
+	ret = __connman_inet_rtnl_send(&rth, &rth.req.n);
+
+done:
+	__connman_inet_rtnl_close(&rth);
+
+	return ret;
+}
+
+int __connman_inet_add_default_to_table(uint32_t table_id, int ifindex,
+						const char *gateway)
+{
+	/* ip route add default via 1.2.3.4 dev wlan0 table 1234 */
+
+	return iproute_default_modify(RTM_NEWROUTE, table_id, ifindex, gateway);
+}
+
+int __connman_inet_del_default_from_table(uint32_t table_id, int ifindex,
+						const char *gateway)
+{
+	/* ip route del default via 1.2.3.4 dev wlan0 table 1234 */
+
+	return iproute_default_modify(RTM_DELROUTE, table_id, ifindex, gateway);
+}
+
+int __connman_inet_get_interface_ll_address(int index, int family,
+								void *address)
+{
+	struct ifaddrs *ifaddr, *ifa;
+	int err = -ENOENT;
+	char name[IF_NAMESIZE];
+
+	if (!if_indextoname(index, name))
+		return -EINVAL;
+
+	DBG("index %d interface %s", index, name);
+
+	if (getifaddrs(&ifaddr) < 0) {
+		err = -errno;
+		DBG("Cannot get addresses err %d/%s", err, strerror(-err));
+		return err;
+	}
+
+	for (ifa = ifaddr; ifa; ifa = ifa->ifa_next) {
+		if (!ifa->ifa_addr)
+			continue;
+
+		if (strncmp(ifa->ifa_name, name, IF_NAMESIZE) == 0 &&
+					ifa->ifa_addr->sa_family == family) {
+			if (family == AF_INET) {
+				struct sockaddr_in *in4 = (struct sockaddr_in *)
+					ifa->ifa_addr;
+				if (in4->sin_addr.s_addr == INADDR_ANY)
+					continue;
+				if ((in4->sin_addr.s_addr & IN_CLASSB_NET) !=
+						((in_addr_t) 0xa9fe0000))
+					continue;
+				memcpy(address, &in4->sin_addr,
+							sizeof(struct in_addr));
+			} else if (family == AF_INET6) {
+				struct sockaddr_in6 *in6 =
+					(struct sockaddr_in6 *)ifa->ifa_addr;
+				if (memcmp(&in6->sin6_addr, &in6addr_any,
+						sizeof(struct in6_addr)) == 0)
+					continue;
+				if (!IN6_IS_ADDR_LINKLOCAL(&in6->sin6_addr))
+					continue;
+
+				memcpy(address, &in6->sin6_addr,
+						sizeof(struct in6_addr));
+			} else {
+				err = -EINVAL;
+				goto out;
+			}
+
+			err = 0;
+			break;
+		}
+	}
+
+out:
+	freeifaddrs(ifaddr);
+	return err;
+}
+
+int __connman_inet_get_address_netmask(int ifindex,
+					struct sockaddr_in *address,
+					struct sockaddr_in *netmask)
+{
+	int sk, ret = -EINVAL;
+	struct ifreq ifr;
+
+	DBG("index %d", ifindex);
+
+	sk = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
+	if (sk < 0)
+		return -EINVAL;
+
+	memset(&ifr, 0, sizeof(ifr));
+	ifr.ifr_ifindex = ifindex;
+
+	if (ioctl(sk, SIOCGIFNAME, &ifr) < 0)
+		goto out;
+
+	if (ioctl(sk, SIOCGIFNETMASK, &ifr) < 0)
+		goto out;
+
+	memcpy(netmask, (struct sockaddr_in *)&ifr.ifr_netmask,
+						sizeof(struct sockaddr_in));
+
+	if (ioctl(sk, SIOCGIFADDR, &ifr) < 0)
+		goto out;
+
+	memcpy(address, (struct sockaddr_in *)&ifr.ifr_addr,
+						sizeof(struct sockaddr_in));
+	ret = 0;
+
+out:
+	close(sk);
+	return ret;
+}
diff --git a/connman/src/inotify.c b/connman/src/inotify.c
new file mode 100644
index 0000000..c251c6f
--- /dev/null
+++ b/connman/src/inotify.c
@@ -0,0 +1,261 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2012  Intel Corporation. All rights reserved.
+ *  Copyright (C) 2012-2014  BMW Car IT GmbH.
+ *
+ *  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 <unistd.h>
+#include <sys/stat.h>
+#include <dirent.h>
+#include <sys/inotify.h>
+
+#include <connman/storage.h>
+
+#include "connman.h"
+
+struct connman_inotify {
+	unsigned int refcount;
+
+	GIOChannel *channel;
+	uint watch;
+	int wd;
+
+	GSList *list;
+};
+
+static void cleanup_inotify(gpointer user_data);
+
+static void connman_inotify_ref(struct connman_inotify *i)
+{
+	__sync_fetch_and_add(&i->refcount, 1);
+}
+
+static void connman_inotify_unref(gpointer data)
+{
+	struct connman_inotify *i = data;
+
+	if (__sync_fetch_and_sub(&i->refcount, 1) != 1)
+		return;
+
+	cleanup_inotify(data);
+}
+
+static GHashTable *inotify_hash;
+
+static gboolean inotify_data(GIOChannel *channel, GIOCondition cond,
+							gpointer user_data)
+{
+	struct connman_inotify *inotify = user_data;
+	char buffer[sizeof(struct inotify_event) + NAME_MAX + 1];
+	char *next_event;
+	gsize bytes_read;
+	GIOStatus status;
+	GSList *list;
+
+	if (cond & (G_IO_NVAL | G_IO_ERR | G_IO_HUP)) {
+		inotify->watch = 0;
+		return FALSE;
+	}
+
+	status = g_io_channel_read_chars(channel, buffer,
+					sizeof(buffer), &bytes_read, NULL);
+
+	switch (status) {
+	case G_IO_STATUS_NORMAL:
+		break;
+	case G_IO_STATUS_AGAIN:
+		return TRUE;
+	default:
+		connman_error("Reading from inotify channel failed");
+		inotify->watch = 0;
+		return FALSE;
+	}
+
+	next_event = buffer;
+
+	connman_inotify_ref(inotify);
+
+	while (bytes_read > 0) {
+		struct inotify_event *event;
+		gchar *ident;
+		gsize len;
+
+		event = (struct inotify_event *) next_event;
+		if (event->len)
+			ident = next_event + sizeof(struct inotify_event);
+		else
+			ident = NULL;
+
+		len = sizeof(struct inotify_event) + event->len;
+
+		/* check if inotify_event block fit */
+		if (len > bytes_read)
+			break;
+
+		next_event += len;
+		bytes_read -= len;
+
+		for (list = inotify->list; list; list = list->next) {
+			inotify_event_cb callback = list->data;
+
+			(*callback)(event, ident);
+		}
+	}
+
+	connman_inotify_unref(inotify);
+
+	return TRUE;
+}
+
+static int create_watch(const char *path, struct connman_inotify *inotify)
+{
+	int fd;
+
+	DBG("Add directory watch for %s", path);
+
+	fd = inotify_init();
+	if (fd < 0)
+		return -EIO;
+
+	inotify->wd = inotify_add_watch(fd, path,
+					IN_MODIFY | IN_CREATE | IN_DELETE |
+					IN_MOVED_TO | IN_MOVED_FROM);
+	if (inotify->wd < 0) {
+		connman_error("Creation of %s watch failed", path);
+		close(fd);
+		return -EIO;
+	}
+
+	inotify->channel = g_io_channel_unix_new(fd);
+	if (!inotify->channel) {
+		connman_error("Creation of inotify channel failed");
+		inotify_rm_watch(fd, inotify->wd);
+		inotify->wd = 0;
+
+		close(fd);
+		return -EIO;
+	}
+
+	g_io_channel_set_close_on_unref(inotify->channel, TRUE);
+	g_io_channel_set_encoding(inotify->channel, NULL, NULL);
+	g_io_channel_set_buffered(inotify->channel, FALSE);
+
+	inotify->watch = g_io_add_watch(inotify->channel,
+				G_IO_IN | G_IO_HUP | G_IO_NVAL | G_IO_ERR,
+				inotify_data, inotify);
+
+	return 0;
+}
+
+static void remove_watch(struct connman_inotify *inotify)
+{
+	int fd;
+
+	if (!inotify->channel)
+		return;
+
+	if (inotify->watch > 0)
+		g_source_remove(inotify->watch);
+
+	fd = g_io_channel_unix_get_fd(inotify->channel);
+
+	if (inotify->wd >= 0)
+		inotify_rm_watch(fd, inotify->wd);
+
+	g_io_channel_unref(inotify->channel);
+}
+
+int connman_inotify_register(const char *path, inotify_event_cb callback)
+{
+	struct connman_inotify *inotify;
+	int err;
+
+	if (!callback)
+		return -EINVAL;
+
+	inotify = g_hash_table_lookup(inotify_hash, path);
+	if (inotify)
+		goto update;
+
+	inotify = g_try_new0(struct connman_inotify, 1);
+	if (!inotify)
+		return -ENOMEM;
+
+	inotify->refcount = 1;
+	inotify->wd = -1;
+
+	err = create_watch(path, inotify);
+	if (err < 0) {
+		g_free(inotify);
+		return err;
+	}
+
+	g_hash_table_replace(inotify_hash, g_strdup(path), inotify);
+
+update:
+	inotify->list = g_slist_prepend(inotify->list, callback);
+
+	return 0;
+}
+
+static void cleanup_inotify(gpointer user_data)
+{
+	struct connman_inotify *inotify = user_data;
+
+	g_slist_free(inotify->list);
+
+	remove_watch(inotify);
+	g_free(inotify);
+}
+
+void connman_inotify_unregister(const char *path, inotify_event_cb callback)
+{
+	struct connman_inotify *inotify;
+
+	inotify = g_hash_table_lookup(inotify_hash, path);
+	if (!inotify)
+		return;
+
+	inotify->list = g_slist_remove(inotify->list, callback);
+	if (inotify->list)
+		return;
+
+	g_hash_table_remove(inotify_hash, path);
+}
+
+int __connman_inotify_init(void)
+{
+	DBG("");
+
+	inotify_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
+						g_free, connman_inotify_unref);
+	return 0;
+}
+
+void __connman_inotify_cleanup(void)
+{
+	DBG("");
+
+	g_hash_table_destroy(inotify_hash);
+}
diff --git a/connman/src/ipaddress.c b/connman/src/ipaddress.c
new file mode 100644
index 0000000..d63d95c
--- /dev/null
+++ b/connman/src/ipaddress.c
@@ -0,0 +1,228 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2013  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 <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <glib.h>
+
+#include <connman/ipaddress.h>
+
+#include "connman.h"
+
+unsigned char connman_ipaddress_calc_netmask_len(const char *netmask)
+{
+	unsigned char bits;
+	in_addr_t mask;
+	in_addr_t host;
+
+	if (!netmask)
+		return 32;
+
+	mask = inet_network(netmask);
+	host = ~mask;
+
+	/* a valid netmask must be 2^n - 1 */
+	if ((host & (host + 1)) != 0)
+		return -1;
+
+	bits = 0;
+	for (; mask; mask <<= 1)
+		++bits;
+
+	return bits;
+}
+
+struct connman_ipaddress *connman_ipaddress_alloc(int family)
+{
+	struct connman_ipaddress *ipaddress;
+
+	ipaddress = g_try_new0(struct connman_ipaddress, 1);
+	if (!ipaddress)
+		return NULL;
+
+	ipaddress->family = family;
+	ipaddress->prefixlen = 0;
+	ipaddress->local = NULL;
+	ipaddress->peer = NULL;
+	ipaddress->broadcast = NULL;
+	ipaddress->gateway = NULL;
+
+	return ipaddress;
+}
+
+void connman_ipaddress_free(struct connman_ipaddress *ipaddress)
+{
+	if (!ipaddress)
+		return;
+
+	g_free(ipaddress->broadcast);
+	g_free(ipaddress->peer);
+	g_free(ipaddress->local);
+	g_free(ipaddress->gateway);
+	g_free(ipaddress);
+}
+
+static bool check_ipv6_address(const char *address)
+{
+	unsigned char buf[sizeof(struct in6_addr)];
+	int err;
+
+	if (!address)
+		return false;
+
+	err = inet_pton(AF_INET6, address, buf);
+	if (err > 0)
+		return true;
+
+	return false;
+}
+
+int connman_ipaddress_set_ipv6(struct connman_ipaddress *ipaddress,
+				const char *address,
+				unsigned char prefix_length,
+				const char *gateway)
+{
+	if (!ipaddress)
+		return -EINVAL;
+
+	if (!check_ipv6_address(address))
+		return -EINVAL;
+
+	DBG("prefix_len %d address %s gateway %s",
+			prefix_length, address, gateway);
+
+	ipaddress->family = AF_INET6;
+
+	ipaddress->prefixlen = prefix_length;
+
+	g_free(ipaddress->local);
+	ipaddress->local = g_strdup(address);
+
+	g_free(ipaddress->gateway);
+	ipaddress->gateway = g_strdup(gateway);
+
+	return 0;
+}
+
+int connman_ipaddress_get_ip(struct connman_ipaddress *ipaddress,
+			const char **address,
+			unsigned char *netmask_prefix_length)
+{
+	if (!ipaddress)
+		return -EINVAL;
+
+	*netmask_prefix_length = ipaddress->prefixlen;
+	*address = ipaddress->local;
+
+	return 0;
+}
+
+int connman_ipaddress_set_ipv4(struct connman_ipaddress *ipaddress,
+		const char *address, const char *netmask, const char *gateway)
+{
+	if (!ipaddress)
+		return -EINVAL;
+
+	ipaddress->family = AF_INET;
+
+	ipaddress->prefixlen = connman_ipaddress_calc_netmask_len(netmask);
+
+	g_free(ipaddress->local);
+	ipaddress->local = g_strdup(address);
+
+	g_free(ipaddress->gateway);
+	ipaddress->gateway = g_strdup(gateway);
+
+	return 0;
+}
+
+void connman_ipaddress_set_peer(struct connman_ipaddress *ipaddress,
+				const char *peer)
+{
+	if (!ipaddress)
+		return;
+
+	g_free(ipaddress->peer);
+	ipaddress->peer = g_strdup(peer);
+}
+
+void connman_ipaddress_clear(struct connman_ipaddress *ipaddress)
+{
+	if (!ipaddress)
+		return;
+
+	ipaddress->prefixlen = 0;
+
+	g_free(ipaddress->local);
+	ipaddress->local = NULL;
+
+	g_free(ipaddress->peer);
+	ipaddress->peer = NULL;
+
+	g_free(ipaddress->broadcast);
+	ipaddress->broadcast = NULL;
+
+	g_free(ipaddress->gateway);
+	ipaddress->gateway = NULL;
+}
+
+/*
+ * Note that this copy function only copies the actual address and
+ * prefixlen. Use the other copy function to copy the whole struct.
+ */
+void connman_ipaddress_copy_address(struct connman_ipaddress *ipaddress,
+					struct connman_ipaddress *source)
+{
+	if (!ipaddress || !source)
+		return;
+
+	ipaddress->family = source->family;
+	ipaddress->prefixlen = source->prefixlen;
+
+	g_free(ipaddress->local);
+	ipaddress->local = g_strdup(source->local);
+}
+
+struct connman_ipaddress *
+connman_ipaddress_copy(struct connman_ipaddress *ipaddress)
+{
+	struct connman_ipaddress *copy;
+
+	if (!ipaddress)
+		return NULL;
+
+	copy = g_new0(struct connman_ipaddress, 1);
+
+	copy->family = ipaddress->family;
+	copy->prefixlen = ipaddress->prefixlen;
+	copy->local = g_strdup(ipaddress->local);
+	copy->peer = g_strdup(ipaddress->peer);
+	copy->broadcast = g_strdup(ipaddress->broadcast);
+	copy->gateway = g_strdup(ipaddress->gateway);
+
+	return copy;
+}
diff --git a/connman/src/ipconfig.c b/connman/src/ipconfig.c
new file mode 100644
index 0000000..a638c41
--- /dev/null
+++ b/connman/src/ipconfig.c
@@ -0,0 +1,2472 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2013  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 <stdio.h>
+#include <net/if.h>
+#include <net/if_arp.h>
+#include <linux/if_link.h>
+#include <string.h>
+#include <stdlib.h>
+
+#ifndef IFF_LOWER_UP
+#define IFF_LOWER_UP	0x10000
+#endif
+
+#include <gdbus.h>
+#include <connman/ipaddress.h>
+
+#include "connman.h"
+
+struct connman_ipconfig {
+	int refcount;
+	int index;
+	enum connman_ipconfig_type type;
+
+	const struct connman_ipconfig_ops *ops;
+	void *ops_data;
+
+	bool enabled;
+	enum connman_ipconfig_method method;
+	struct connman_ipaddress *address;
+	struct connman_ipaddress *system;
+
+	int ipv6_privacy_config;
+	char *last_dhcp_address;
+	char **last_dhcpv6_prefixes;
+};
+
+struct connman_ipdevice {
+	int index;
+	unsigned short type;
+	unsigned int flags;
+	char *address;
+	uint16_t mtu;
+	uint32_t rx_packets;
+	uint32_t tx_packets;
+	uint32_t rx_bytes;
+	uint32_t tx_bytes;
+	uint32_t rx_errors;
+	uint32_t tx_errors;
+	uint32_t rx_dropped;
+	uint32_t tx_dropped;
+
+	GSList *address_list;
+	char *ipv4_gateway;
+	char *ipv6_gateway;
+
+	char *pac;
+
+	struct connman_ipconfig *config_ipv4;
+	struct connman_ipconfig *config_ipv6;
+
+	bool ipv6_enabled;
+	int ipv6_privacy;
+};
+
+static GHashTable *ipdevice_hash = NULL;
+static GList *ipconfig_list = NULL;
+static bool is_ipv6_supported = false;
+
+void __connman_ipconfig_clear_address(struct connman_ipconfig *ipconfig)
+{
+	if (!ipconfig)
+		return;
+
+	connman_ipaddress_clear(ipconfig->address);
+}
+
+static void free_address_list(struct connman_ipdevice *ipdevice)
+{
+	GSList *list;
+
+	for (list = ipdevice->address_list; list; list = list->next) {
+		struct connman_ipaddress *ipaddress = list->data;
+
+		connman_ipaddress_free(ipaddress);
+		list->data = NULL;
+	}
+
+	g_slist_free(ipdevice->address_list);
+	ipdevice->address_list = NULL;
+}
+
+static struct connman_ipaddress *find_ipaddress(struct connman_ipdevice *ipdevice,
+				unsigned char prefixlen, const char *local)
+{
+	GSList *list;
+
+	for (list = ipdevice->address_list; list; list = list->next) {
+		struct connman_ipaddress *ipaddress = list->data;
+
+		if (g_strcmp0(ipaddress->local, local) == 0 &&
+					ipaddress->prefixlen == prefixlen)
+			return ipaddress;
+	}
+
+	return NULL;
+}
+
+const char *__connman_ipconfig_type2string(enum connman_ipconfig_type type)
+{
+	switch (type) {
+	case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
+	case CONNMAN_IPCONFIG_TYPE_ALL:
+		return "unknown";
+	case CONNMAN_IPCONFIG_TYPE_IPV4:
+		return "IPv4";
+	case CONNMAN_IPCONFIG_TYPE_IPV6:
+		return "IPv6";
+	}
+
+	return NULL;
+}
+
+static const char *type2str(unsigned short type)
+{
+	switch (type) {
+	case ARPHRD_ETHER:
+		return "ETHER";
+	case ARPHRD_LOOPBACK:
+		return "LOOPBACK";
+	case ARPHRD_PPP:
+		return "PPP";
+	case ARPHRD_NONE:
+		return "NONE";
+	case ARPHRD_VOID:
+		return "VOID";
+	}
+
+	return "";
+}
+
+static const char *scope2str(unsigned char scope)
+{
+	switch (scope) {
+	case 0:
+		return "UNIVERSE";
+	case 253:
+		return "LINK";
+	}
+
+	return "";
+}
+
+static bool get_ipv6_state(gchar *ifname)
+{
+	int disabled;
+	gchar *path;
+	FILE *f;
+	bool enabled = false;
+
+	if (!ifname)
+		path = g_strdup("/proc/sys/net/ipv6/conf/all/disable_ipv6");
+	else
+		path = g_strdup_printf(
+			"/proc/sys/net/ipv6/conf/%s/disable_ipv6", ifname);
+
+	if (!path)
+		return enabled;
+
+	f = fopen(path, "r");
+
+	g_free(path);
+
+	if (f) {
+		if (fscanf(f, "%d", &disabled) > 0)
+			enabled = !disabled;
+		fclose(f);
+	}
+
+	return enabled;
+}
+
+static void set_ipv6_state(gchar *ifname, bool enable)
+{
+	gchar *path;
+	FILE *f;
+
+	DBG("on %s", ifname);
+
+	if (!ifname)
+	{
+	    /* Fix for SAPPHRIE-11680:
+	     * We see that sometimes when wifi interface is disabled, connman
+	     * removes all ipv6 addresses and routes from all other interfaces as well.
+	     * The line below is the trigger point for this bug. Basically if the ifname
+	     * is NULL, connman goes ahead and disables IPv6 on all interfaces.
+	     * Connman calls this function from free_ipdevice() when removing the interface
+	     * (it happens indirectly when the ipdevice is removed from g_hash_table and the
+	     * element is freed). To get the interface name in free_ipdevice() connman uses
+	     * connman_inet_ifname() which itself gets the name using ioctl (asking the kernel).
+	     * So if the interface is already down when calling this function, we can get a null
+	     * return value.
+	     *
+	     * To fix this, we remove this line and immediately return if ifname is null.
+	     *
+	     * The side-effect of keeping ipv6 enabled for wlan during restarts is far less than
+	     * the damage this line causes by removing ipv6 for all interfaces!!
+	     */
+	    // path = g_strdup("/proc/sys/net/ipv6/conf/all/disable_ipv6");
+	    return;
+	}
+	else
+		path = g_strdup_printf(
+			"/proc/sys/net/ipv6/conf/%s/disable_ipv6", ifname);
+
+	if (!path)
+		return;
+
+	f = fopen(path, "r+");
+
+	g_free(path);
+
+	if (!f)
+		return;
+
+	if (!enable)
+		fprintf(f, "1");
+	else
+		fprintf(f, "0");
+
+	fclose(f);
+}
+
+static int get_ipv6_privacy(gchar *ifname)
+{
+	gchar *path;
+	FILE *f;
+	int value;
+
+	if (!ifname)
+		return 0;
+
+	path = g_strdup_printf("/proc/sys/net/ipv6/conf/%s/use_tempaddr",
+								ifname);
+
+	if (!path)
+		return 0;
+
+	f = fopen(path, "r");
+
+	g_free(path);
+
+	if (!f)
+		return 0;
+
+	if (fscanf(f, "%d", &value) <= 0)
+		value = 0;
+
+	fclose(f);
+
+	return value;
+}
+
+/* Enable the IPv6 privacy extension for stateless address autoconfiguration.
+ * The privacy extension is described in RFC 3041 and RFC 4941
+ */
+static void set_ipv6_privacy(gchar *ifname, int value)
+{
+	gchar *path;
+	FILE *f;
+
+	if (!ifname)
+		return;
+
+	path = g_strdup_printf("/proc/sys/net/ipv6/conf/%s/use_tempaddr",
+								ifname);
+
+	if (!path)
+		return;
+
+	if (value < 0)
+		value = 0;
+
+	f = fopen(path, "r+");
+
+	g_free(path);
+
+	if (!f)
+		return;
+
+	fprintf(f, "%d", value);
+	fclose(f);
+}
+
+static int get_rp_filter(void)
+{
+	FILE *f;
+	int value = -EINVAL, tmp;
+
+	f = fopen("/proc/sys/net/ipv4/conf/all/rp_filter", "r");
+
+	if (f) {
+		if (fscanf(f, "%d", &tmp) == 1)
+			value = tmp;
+		fclose(f);
+	}
+
+	return value;
+}
+
+static void set_rp_filter(int value)
+{
+	FILE *f;
+
+	f = fopen("/proc/sys/net/ipv4/conf/all/rp_filter", "r+");
+
+	if (!f)
+		return;
+
+	fprintf(f, "%d", value);
+
+	fclose(f);
+}
+
+int __connman_ipconfig_set_rp_filter()
+{
+	int value;
+
+	value = get_rp_filter();
+
+	if (value < 0)
+		return value;
+
+	set_rp_filter(2);
+
+	connman_info("rp_filter set to 2 (loose mode routing), "
+			"old value was %d", value);
+
+	return value;
+}
+
+void __connman_ipconfig_unset_rp_filter(int old_value)
+{
+	set_rp_filter(old_value);
+
+	connman_info("rp_filter restored to %d", old_value);
+}
+
+bool __connman_ipconfig_ipv6_privacy_enabled(struct connman_ipconfig *ipconfig)
+{
+	if (!ipconfig)
+		return false;
+
+	return ipconfig->ipv6_privacy_config == 0 ? FALSE : TRUE;
+}
+
+bool __connman_ipconfig_ipv6_is_enabled(struct connman_ipconfig *ipconfig)
+{
+	struct connman_ipdevice *ipdevice;
+	char *ifname;
+	bool ret;
+
+	if (!ipconfig)
+		return false;
+
+	ipdevice = g_hash_table_lookup(ipdevice_hash,
+					GINT_TO_POINTER(ipconfig->index));
+	if (!ipdevice)
+		return false;
+
+	ifname = connman_inet_ifname(ipconfig->index);
+	ret = get_ipv6_state(ifname);
+	g_free(ifname);
+
+	return ret;
+}
+
+static void free_ipdevice(gpointer data)
+{
+	struct connman_ipdevice *ipdevice = data;
+	char *ifname = connman_inet_ifname(ipdevice->index);
+
+	connman_info("%s {remove} index %d", ifname, ipdevice->index);
+
+	if (ipdevice->config_ipv4) {
+		__connman_ipconfig_unref(ipdevice->config_ipv4);
+		ipdevice->config_ipv4 = NULL;
+	}
+
+	if (ipdevice->config_ipv6) {
+		__connman_ipconfig_unref(ipdevice->config_ipv6);
+		ipdevice->config_ipv6 = NULL;
+	}
+
+	free_address_list(ipdevice);
+	g_free(ipdevice->ipv4_gateway);
+	g_free(ipdevice->ipv6_gateway);
+	g_free(ipdevice->pac);
+
+	g_free(ipdevice->address);
+
+	set_ipv6_state(ifname, ipdevice->ipv6_enabled);
+	set_ipv6_privacy(ifname, ipdevice->ipv6_privacy);
+
+	g_free(ifname);
+	g_free(ipdevice);
+}
+
+static void __connman_ipconfig_lower_up(struct connman_ipdevice *ipdevice)
+{
+	DBG("ipconfig ipv4 %p ipv6 %p", ipdevice->config_ipv4,
+					ipdevice->config_ipv6);
+}
+
+static void __connman_ipconfig_lower_down(struct connman_ipdevice *ipdevice)
+{
+	DBG("ipconfig ipv4 %p ipv6 %p", ipdevice->config_ipv4,
+					ipdevice->config_ipv6);
+
+	if (ipdevice->config_ipv4)
+		connman_inet_clear_address(ipdevice->index,
+					ipdevice->config_ipv4->address);
+
+	if (ipdevice->config_ipv6)
+		connman_inet_clear_ipv6_address(ipdevice->index,
+				ipdevice->config_ipv6->address->local,
+				ipdevice->config_ipv6->address->prefixlen);
+}
+
+static void update_stats(struct connman_ipdevice *ipdevice,
+			const char *ifname, struct rtnl_link_stats *stats)
+{
+	struct connman_service *service;
+
+	if (stats->rx_packets == 0 && stats->tx_packets == 0)
+		return;
+
+	connman_info("%s {RX} %u packets %u bytes", ifname,
+					stats->rx_packets, stats->rx_bytes);
+	connman_info("%s {TX} %u packets %u bytes", ifname,
+					stats->tx_packets, stats->tx_bytes);
+
+	if (!ipdevice->config_ipv4 && !ipdevice->config_ipv6)
+		return;
+
+	service = __connman_service_lookup_from_index(ipdevice->index);
+
+	DBG("service %p", service);
+
+	if (!service)
+		return;
+
+	ipdevice->rx_packets = stats->rx_packets;
+	ipdevice->tx_packets = stats->tx_packets;
+	ipdevice->rx_bytes = stats->rx_bytes;
+	ipdevice->tx_bytes = stats->tx_bytes;
+	ipdevice->rx_errors = stats->rx_errors;
+	ipdevice->tx_errors = stats->tx_errors;
+	ipdevice->rx_dropped = stats->rx_dropped;
+	ipdevice->tx_dropped = stats->tx_dropped;
+
+	__connman_service_notify(service,
+				ipdevice->rx_packets, ipdevice->tx_packets,
+				ipdevice->rx_bytes, ipdevice->tx_bytes,
+				ipdevice->rx_errors, ipdevice->tx_errors,
+				ipdevice->rx_dropped, ipdevice->tx_dropped);
+}
+
+struct connman_ipdevice *
+connman_ipdevice_lookup_from_index(int index)
+{
+	return g_hash_table_lookup(ipdevice_hash, GINT_TO_POINTER(index));
+}
+
+void
+connman_ipdevice_set_address(struct connman_ipdevice *ipdevice, const char* address)
+{
+	if(ipdevice->address)
+		g_free(ipdevice->address);
+
+	if(0 != strcmp(address,"00:00:00:00:00:00"))
+		ipdevice->address = g_strdup(address);
+	else
+		ipdevice->address = NULL;
+}
+
+void __connman_ipconfig_newlink(int index, unsigned short type,
+				unsigned int flags, const char *address,
+							unsigned short mtu,
+						struct rtnl_link_stats *stats)
+{
+	struct connman_ipdevice *ipdevice;
+	GList *list, *ipconfig_copy;
+	GString *str;
+	bool up = false, down = false;
+	bool lower_up = false, lower_down = false;
+	char *ifname;
+
+	DBG("index %d", index);
+
+	if (type == ARPHRD_LOOPBACK)
+		return;
+
+	ifname = connman_inet_ifname(index);
+
+	// null name means the lookup failed so ignore the request. 
+	// This will cause bad side effects later on.
+	// For example, a NULL means to disable ipv6 for all!
+	if (!ifname) {
+		DBG("interface name is (null)");
+		goto out;
+	}
+
+	ipdevice = g_hash_table_lookup(ipdevice_hash, GINT_TO_POINTER(index));
+	if (ipdevice)
+		goto update;
+
+	ipdevice = g_try_new0(struct connman_ipdevice, 1);
+	if (!ipdevice)
+		goto out;
+
+	ipdevice->index = index;
+	ipdevice->type = type;
+
+	ipdevice->ipv6_enabled = get_ipv6_state(ifname);
+	ipdevice->ipv6_privacy = get_ipv6_privacy(ifname);
+
+	connman_ipdevice_set_address(ipdevice, address);
+
+	g_hash_table_insert(ipdevice_hash, GINT_TO_POINTER(index), ipdevice);
+
+	connman_info("%s {create} index %d type %d <%s>", ifname,
+						index, type, type2str(type));
+
+update:
+	ipdevice->mtu = mtu;
+
+	update_stats(ipdevice, ifname, stats);
+
+	if (flags == ipdevice->flags)
+		goto out;
+
+	if ((ipdevice->flags & IFF_UP) != (flags & IFF_UP)) {
+		if (flags & IFF_UP)
+			up = true;
+		else
+			down = true;
+	}
+
+	if ((ipdevice->flags & (IFF_RUNNING | IFF_LOWER_UP)) !=
+				(flags & (IFF_RUNNING | IFF_LOWER_UP))) {
+		if ((flags & (IFF_RUNNING | IFF_LOWER_UP)) ==
+					(IFF_RUNNING | IFF_LOWER_UP))
+			lower_up = true;
+		else if ((flags & (IFF_RUNNING | IFF_LOWER_UP)) == 0)
+			lower_down = true;
+	}
+
+	ipdevice->flags = flags;
+
+	str = g_string_new(NULL);
+	if (!str)
+		goto out;
+
+	if (flags & IFF_UP)
+		g_string_append(str, "UP");
+	else
+		g_string_append(str, "DOWN");
+
+	if (flags & IFF_RUNNING)
+		g_string_append(str, ",RUNNING");
+
+	if (flags & IFF_LOWER_UP)
+		g_string_append(str, ",LOWER_UP");
+
+	connman_info("%s {update} flags %u <%s>", ifname, flags, str->str);
+
+	g_string_free(str, TRUE);
+
+	ipconfig_copy = g_list_copy(ipconfig_list);
+
+	for (list = g_list_first(ipconfig_copy); list;
+						list = g_list_next(list)) {
+		struct connman_ipconfig *ipconfig = list->data;
+
+		if (index != ipconfig->index)
+			continue;
+
+		if (!ipconfig->ops)
+			continue;
+
+		if (up && ipconfig->ops->up)
+			ipconfig->ops->up(ipconfig, ifname);
+		if (lower_up && ipconfig->ops->lower_up)
+			ipconfig->ops->lower_up(ipconfig, ifname);
+
+		if (lower_down && ipconfig->ops->lower_down)
+			ipconfig->ops->lower_down(ipconfig, ifname);
+		if (down && ipconfig->ops->down)
+			ipconfig->ops->down(ipconfig, ifname);
+	}
+
+	g_list_free(ipconfig_copy);
+
+	if (lower_up)
+		__connman_ipconfig_lower_up(ipdevice);
+	if (lower_down)
+		__connman_ipconfig_lower_down(ipdevice);
+
+out:
+	g_free(ifname);
+}
+
+void __connman_ipconfig_dellink(int index, struct rtnl_link_stats *stats)
+{
+	struct connman_ipdevice *ipdevice;
+	GList *list;
+	char *ifname;
+
+	DBG("index %d", index);
+
+	ipdevice = g_hash_table_lookup(ipdevice_hash, GINT_TO_POINTER(index));
+	if (!ipdevice)
+		return;
+
+	ifname = connman_inet_ifname(index);
+
+	update_stats(ipdevice, ifname, stats);
+
+	for (list = g_list_first(ipconfig_list); list;
+						list = g_list_next(list)) {
+		struct connman_ipconfig *ipconfig = list->data;
+
+		if (index != ipconfig->index)
+			continue;
+
+		ipconfig->index = -1;
+
+		if (!ipconfig->ops)
+			continue;
+
+		if (ipconfig->ops->lower_down)
+			ipconfig->ops->lower_down(ipconfig, ifname);
+		if (ipconfig->ops->down)
+			ipconfig->ops->down(ipconfig, ifname);
+	}
+
+	g_free(ifname);
+
+	__connman_ipconfig_lower_down(ipdevice);
+
+	g_hash_table_remove(ipdevice_hash, GINT_TO_POINTER(index));
+}
+
+static inline gint check_duplicate_address(gconstpointer a, gconstpointer b)
+{
+	const struct connman_ipaddress *addr1 = a;
+	const struct connman_ipaddress *addr2 = b;
+
+	if (addr1->prefixlen != addr2->prefixlen)
+		return addr2->prefixlen - addr1->prefixlen;
+
+	return g_strcmp0(addr1->local, addr2->local);
+}
+
+int __connman_ipconfig_newaddr(int index, int family, const char *label,
+				unsigned char prefixlen, const char *address)
+{
+	struct connman_ipdevice *ipdevice;
+	struct connman_ipaddress *ipaddress;
+	enum connman_ipconfig_type type;
+	GList *list;
+	char *ifname;
+
+	DBG("index %d", index);
+
+	ipdevice = g_hash_table_lookup(ipdevice_hash, GINT_TO_POINTER(index));
+	if (!ipdevice)
+		return -ENXIO;
+
+	ipaddress = connman_ipaddress_alloc(family);
+	if (!ipaddress)
+		return -ENOMEM;
+
+	ipaddress->prefixlen = prefixlen;
+	ipaddress->local = g_strdup(address);
+
+	if (g_slist_find_custom(ipdevice->address_list, ipaddress,
+					check_duplicate_address)) {
+		connman_ipaddress_free(ipaddress);
+		return -EALREADY;
+	}
+
+	if (family == AF_INET)
+		type = CONNMAN_IPCONFIG_TYPE_IPV4;
+	else if (family == AF_INET6)
+		type = CONNMAN_IPCONFIG_TYPE_IPV6;
+	else
+		return -EINVAL;
+
+	ipdevice->address_list = g_slist_prepend(ipdevice->address_list,
+								ipaddress);
+
+	ifname = connman_inet_ifname(index);
+	connman_info("%s {add} address %s/%u label %s family %d",
+		ifname, address, prefixlen, label, family);
+
+	if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
+		__connman_ippool_newaddr(index, address, prefixlen);
+
+	if (ipdevice->config_ipv4 && family == AF_INET)
+		connman_ipaddress_copy_address(ipdevice->config_ipv4->system,
+					ipaddress);
+
+	else if (ipdevice->config_ipv6 && family == AF_INET6)
+		connman_ipaddress_copy_address(ipdevice->config_ipv6->system,
+					ipaddress);
+	else
+		goto out;
+
+	if ((ipdevice->flags & (IFF_RUNNING | IFF_LOWER_UP)) != (IFF_RUNNING | IFF_LOWER_UP))
+		goto out;
+
+	for (list = g_list_first(ipconfig_list); list;
+						list = g_list_next(list)) {
+		struct connman_ipconfig *ipconfig = list->data;
+
+		if (index != ipconfig->index)
+			continue;
+
+		if (type != ipconfig->type)
+			continue;
+
+		if (!ipconfig->ops)
+			continue;
+
+		if (ipconfig->ops->ip_bound)
+			ipconfig->ops->ip_bound(ipconfig, ifname);
+	}
+
+out:
+	g_free(ifname);
+	return 0;
+}
+
+void __connman_ipconfig_deladdr(int index, int family, const char *label,
+				unsigned char prefixlen, const char *address)
+{
+	struct connman_ipdevice *ipdevice;
+	struct connman_ipaddress *ipaddress;
+	enum connman_ipconfig_type type;
+	GList *list;
+	char *ifname;
+
+	DBG("index %d", index);
+
+	ipdevice = g_hash_table_lookup(ipdevice_hash, GINT_TO_POINTER(index));
+	if (!ipdevice)
+		return;
+
+	ipaddress = find_ipaddress(ipdevice, prefixlen, address);
+	if (!ipaddress)
+		return;
+
+	if (family == AF_INET)
+		type = CONNMAN_IPCONFIG_TYPE_IPV4;
+	else if (family == AF_INET6)
+		type = CONNMAN_IPCONFIG_TYPE_IPV6;
+	else
+		return;
+
+	ipdevice->address_list = g_slist_remove(ipdevice->address_list,
+								ipaddress);
+
+	if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
+		__connman_ippool_deladdr(index, address, prefixlen);
+
+	connman_ipaddress_clear(ipaddress);
+	g_free(ipaddress);
+
+	ifname = connman_inet_ifname(index);
+	connman_info("%s {del} address %s/%u label %s", ifname,
+						address, prefixlen, label);
+
+	if ((ipdevice->flags & (IFF_RUNNING | IFF_LOWER_UP)) != (IFF_RUNNING | IFF_LOWER_UP))
+		goto out;
+
+	if (g_slist_length(ipdevice->address_list) > 0)
+		goto out;
+
+	for (list = g_list_first(ipconfig_list); list;
+						list = g_list_next(list)) {
+		struct connman_ipconfig *ipconfig = list->data;
+
+		if (index != ipconfig->index)
+			continue;
+
+		if (type != ipconfig->type)
+			continue;
+
+		if (!ipconfig->ops)
+			continue;
+
+		if (ipconfig->ops->ip_release)
+			ipconfig->ops->ip_release(ipconfig, ifname);
+	}
+
+out:
+	g_free(ifname);
+}
+
+void __connman_ipconfig_newroute(int index, int family, unsigned char scope,
+					const char *dst, const char *gateway)
+{
+	struct connman_ipdevice *ipdevice;
+	char *ifname;
+
+	DBG("index %d", index);
+
+	ipdevice = g_hash_table_lookup(ipdevice_hash, GINT_TO_POINTER(index));
+	if (!ipdevice)
+		return;
+
+	ifname = connman_inet_ifname(index);
+
+	if (scope == 0 && (g_strcmp0(dst, "0.0.0.0") == 0 ||
+						g_strcmp0(dst, "::") == 0)) {
+		GList *config_list;
+		enum connman_ipconfig_type type;
+
+		if (family == AF_INET6) {
+			type = CONNMAN_IPCONFIG_TYPE_IPV6;
+			g_free(ipdevice->ipv6_gateway);
+			ipdevice->ipv6_gateway = g_strdup(gateway);
+
+			if (ipdevice->config_ipv6 &&
+				ipdevice->config_ipv6->system) {
+				g_free(ipdevice->config_ipv6->system->gateway);
+				ipdevice->config_ipv6->system->gateway =
+					g_strdup(gateway);
+			}
+		} else if (family == AF_INET) {
+			type = CONNMAN_IPCONFIG_TYPE_IPV4;
+			g_free(ipdevice->ipv4_gateway);
+			ipdevice->ipv4_gateway = g_strdup(gateway);
+
+			if (ipdevice->config_ipv4 &&
+				ipdevice->config_ipv4->system) {
+				g_free(ipdevice->config_ipv4->system->gateway);
+				ipdevice->config_ipv4->system->gateway =
+					g_strdup(gateway);
+			}
+		} else
+			goto out;
+
+		for (config_list = g_list_first(ipconfig_list); config_list;
+					config_list = g_list_next(config_list)) {
+			struct connman_ipconfig *ipconfig = config_list->data;
+
+			if (index != ipconfig->index)
+				continue;
+
+			if (type != ipconfig->type)
+				continue;
+
+			if (!ipconfig->ops)
+				continue;
+
+			if (ipconfig->ops->route_set)
+				ipconfig->ops->route_set(ipconfig, ifname);
+		}
+	}
+
+	connman_info("%s {add} route %s gw %s scope %u <%s>",
+		ifname, dst, gateway, scope, scope2str(scope));
+
+out:
+	g_free(ifname);
+}
+
+void __connman_ipconfig_delroute(int index, int family, unsigned char scope,
+					const char *dst, const char *gateway)
+{
+	struct connman_ipdevice *ipdevice;
+	char *ifname;
+
+	DBG("index %d", index);
+
+	ipdevice = g_hash_table_lookup(ipdevice_hash, GINT_TO_POINTER(index));
+	if (!ipdevice)
+		return;
+
+	ifname = connman_inet_ifname(index);
+
+	if (scope == 0 && (g_strcmp0(dst, "0.0.0.0") == 0 ||
+						g_strcmp0(dst, "::") == 0)) {
+		GList *config_list;
+		enum connman_ipconfig_type type;
+
+		if (family == AF_INET6) {
+			type = CONNMAN_IPCONFIG_TYPE_IPV6;
+			g_free(ipdevice->ipv6_gateway);
+			ipdevice->ipv6_gateway = NULL;
+
+			if (ipdevice->config_ipv6 &&
+				ipdevice->config_ipv6->system) {
+				g_free(ipdevice->config_ipv6->system->gateway);
+				ipdevice->config_ipv6->system->gateway = NULL;
+			}
+		} else if (family == AF_INET) {
+			type = CONNMAN_IPCONFIG_TYPE_IPV4;
+			g_free(ipdevice->ipv4_gateway);
+			ipdevice->ipv4_gateway = NULL;
+
+			if (ipdevice->config_ipv4 &&
+				ipdevice->config_ipv4->system) {
+				g_free(ipdevice->config_ipv4->system->gateway);
+				ipdevice->config_ipv4->system->gateway = NULL;
+			}
+		} else
+			goto out;
+
+		for (config_list = g_list_first(ipconfig_list); config_list;
+					config_list = g_list_next(config_list)) {
+			struct connman_ipconfig *ipconfig = config_list->data;
+
+			if (index != ipconfig->index)
+				continue;
+
+			if (type != ipconfig->type)
+				continue;
+
+			if (!ipconfig->ops)
+				continue;
+
+			if (ipconfig->ops->route_unset)
+				ipconfig->ops->route_unset(ipconfig, ifname);
+		}
+	}
+
+	connman_info("%s {del} route %s gw %s scope %u <%s>",
+		ifname, dst, gateway, scope, scope2str(scope));
+
+out:
+	g_free(ifname);
+}
+
+void __connman_ipconfig_foreach(void (*function) (int index, void *user_data),
+							void *user_data)
+{
+	GList *list, *keys;
+
+	keys = g_hash_table_get_keys(ipdevice_hash);
+	if (!keys)
+		return;
+
+	for (list = g_list_first(keys); list; list = g_list_next(list)) {
+		int index = GPOINTER_TO_INT(list->data);
+
+		function(index, user_data);
+	}
+
+	g_list_free(keys);
+}
+
+enum connman_ipconfig_type __connman_ipconfig_get_config_type(
+					struct connman_ipconfig *ipconfig)
+{
+	return ipconfig ? ipconfig->type : CONNMAN_IPCONFIG_TYPE_UNKNOWN;
+}
+
+unsigned short __connman_ipconfig_get_type_from_index(int index)
+{
+	struct connman_ipdevice *ipdevice;
+
+	ipdevice = g_hash_table_lookup(ipdevice_hash, GINT_TO_POINTER(index));
+	if (!ipdevice)
+		return ARPHRD_VOID;
+
+	return ipdevice->type;
+}
+
+unsigned int __connman_ipconfig_get_flags_from_index(int index)
+{
+	struct connman_ipdevice *ipdevice;
+
+	ipdevice = g_hash_table_lookup(ipdevice_hash, GINT_TO_POINTER(index));
+	if (!ipdevice)
+		return 0;
+
+	return ipdevice->flags;
+}
+
+const char *__connman_ipconfig_get_gateway_from_index(int index,
+	enum connman_ipconfig_type type)
+{
+	struct connman_ipdevice *ipdevice;
+
+	ipdevice = g_hash_table_lookup(ipdevice_hash, GINT_TO_POINTER(index));
+	if (!ipdevice)
+		return NULL;
+
+	if (type != CONNMAN_IPCONFIG_TYPE_IPV6) {
+		if (ipdevice->ipv4_gateway)
+			return ipdevice->ipv4_gateway;
+
+		if (ipdevice->config_ipv4 &&
+				ipdevice->config_ipv4->address)
+			return ipdevice->config_ipv4->address->gateway;
+	}
+
+	if (type != CONNMAN_IPCONFIG_TYPE_IPV4) {
+		if (ipdevice->ipv6_gateway)
+			return ipdevice->ipv6_gateway;
+
+		if (ipdevice->config_ipv6 &&
+				ipdevice->config_ipv6->address)
+			return ipdevice->config_ipv6->address->gateway;
+	}
+
+	return NULL;
+}
+
+void __connman_ipconfig_set_index(struct connman_ipconfig *ipconfig, int index)
+{
+	ipconfig->index = index;
+}
+
+const char *__connman_ipconfig_get_local(struct connman_ipconfig *ipconfig)
+{
+	if (!ipconfig->address)
+		return NULL;
+
+	return ipconfig->address->local;
+}
+
+void __connman_ipconfig_set_local(struct connman_ipconfig *ipconfig,
+					const char *address)
+{
+	if (!ipconfig->address)
+		return;
+
+	g_free(ipconfig->address->local);
+	ipconfig->address->local = g_strdup(address);
+}
+
+const char *__connman_ipconfig_get_peer(struct connman_ipconfig *ipconfig)
+{
+	if (!ipconfig->address)
+		return NULL;
+
+	return ipconfig->address->peer;
+}
+
+void __connman_ipconfig_set_peer(struct connman_ipconfig *ipconfig,
+					const char *address)
+{
+	if (!ipconfig->address)
+		return;
+
+	g_free(ipconfig->address->peer);
+	ipconfig->address->peer = g_strdup(address);
+}
+
+const char *__connman_ipconfig_get_broadcast(struct connman_ipconfig *ipconfig)
+{
+	if (!ipconfig->address)
+		return NULL;
+
+	return ipconfig->address->broadcast;
+}
+
+void __connman_ipconfig_set_broadcast(struct connman_ipconfig *ipconfig,
+					const char *broadcast)
+{
+	if (!ipconfig->address)
+		return;
+
+	g_free(ipconfig->address->broadcast);
+	ipconfig->address->broadcast = g_strdup(broadcast);
+}
+
+const char *__connman_ipconfig_get_gateway(struct connman_ipconfig *ipconfig)
+{
+	if (!ipconfig->address)
+		return NULL;
+
+	return ipconfig->address->gateway;
+}
+
+void __connman_ipconfig_set_gateway(struct connman_ipconfig *ipconfig,
+					const char *gateway)
+{
+	DBG("");
+
+	if (!ipconfig->address)
+		return;
+	g_free(ipconfig->address->gateway);
+	ipconfig->address->gateway = g_strdup(gateway);
+}
+
+int __connman_ipconfig_gateway_add(struct connman_ipconfig *ipconfig)
+{
+	struct connman_service *service;
+
+	DBG("");
+
+	if (!ipconfig->address)
+		return -EINVAL;
+
+	service = __connman_service_lookup_from_index(ipconfig->index);
+	if (!service)
+		return -EINVAL;
+
+	DBG("type %d gw %s peer %s", ipconfig->type,
+		ipconfig->address->gateway, ipconfig->address->peer);
+
+	if (ipconfig->type == CONNMAN_IPCONFIG_TYPE_IPV6 ||
+				ipconfig->type == CONNMAN_IPCONFIG_TYPE_IPV4)
+		return __connman_connection_gateway_add(service,
+						ipconfig->address->gateway,
+						ipconfig->type,
+						ipconfig->address->peer);
+
+	return 0;
+}
+
+void __connman_ipconfig_gateway_remove(struct connman_ipconfig *ipconfig)
+{
+	struct connman_service *service;
+
+	DBG("");
+
+	service = __connman_service_lookup_from_index(ipconfig->index);
+	if (service)
+		__connman_connection_gateway_remove(service, ipconfig->type);
+}
+
+unsigned char __connman_ipconfig_get_prefixlen(struct connman_ipconfig *ipconfig)
+{
+	if (!ipconfig->address)
+		return 0;
+
+	return ipconfig->address->prefixlen;
+}
+
+void __connman_ipconfig_set_prefixlen(struct connman_ipconfig *ipconfig,
+					unsigned char prefixlen)
+{
+	if (!ipconfig->address)
+		return;
+
+	ipconfig->address->prefixlen = prefixlen;
+}
+
+static struct connman_ipconfig *create_ipv6config(int index)
+{
+	struct connman_ipconfig *ipv6config;
+	struct connman_ipdevice *ipdevice;
+
+	DBG("index %d", index);
+
+	ipv6config = g_try_new0(struct connman_ipconfig, 1);
+	if (!ipv6config)
+		return NULL;
+
+	ipv6config->refcount = 1;
+
+	ipv6config->index = index;
+	ipv6config->enabled = false;
+	ipv6config->type = CONNMAN_IPCONFIG_TYPE_IPV6;
+
+	if (!is_ipv6_supported)
+		ipv6config->method = CONNMAN_IPCONFIG_METHOD_OFF;
+	else
+		ipv6config->method = CONNMAN_IPCONFIG_METHOD_AUTO;
+
+	ipdevice = g_hash_table_lookup(ipdevice_hash, GINT_TO_POINTER(index));
+	if (ipdevice)
+		ipv6config->ipv6_privacy_config = ipdevice->ipv6_privacy;
+
+	ipv6config->address = connman_ipaddress_alloc(AF_INET6);
+	if (!ipv6config->address) {
+		g_free(ipv6config);
+		return NULL;
+	}
+
+	ipv6config->system = connman_ipaddress_alloc(AF_INET6);
+
+	DBG("ipconfig %p method %s", ipv6config,
+		__connman_ipconfig_method2string(ipv6config->method));
+
+	return ipv6config;
+}
+
+/**
+ * connman_ipconfig_create:
+ *
+ * Allocate a new ipconfig structure.
+ *
+ * Returns: a newly-allocated #connman_ipconfig structure
+ */
+struct connman_ipconfig *__connman_ipconfig_create(int index,
+					enum connman_ipconfig_type type)
+{
+	struct connman_ipconfig *ipconfig;
+
+	if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
+		return create_ipv6config(index);
+
+	DBG("index %d", index);
+
+	ipconfig = g_try_new0(struct connman_ipconfig, 1);
+	if (!ipconfig)
+		return NULL;
+
+	ipconfig->refcount = 1;
+
+	ipconfig->index = index;
+	ipconfig->enabled = false;
+	ipconfig->type = CONNMAN_IPCONFIG_TYPE_IPV4;
+
+	ipconfig->address = connman_ipaddress_alloc(AF_INET);
+	if (!ipconfig->address) {
+		g_free(ipconfig);
+		return NULL;
+	}
+
+	ipconfig->system = connman_ipaddress_alloc(AF_INET);
+
+	DBG("ipconfig %p", ipconfig);
+
+	return ipconfig;
+}
+
+
+/**
+ * connman_ipconfig_ref:
+ * @ipconfig: ipconfig structure
+ *
+ * Increase reference counter of ipconfig
+ */
+struct connman_ipconfig *
+__connman_ipconfig_ref_debug(struct connman_ipconfig *ipconfig,
+				const char *file, int line, const char *caller)
+{
+	DBG("%p ref %d by %s:%d:%s()", ipconfig, ipconfig->refcount + 1,
+		file, line, caller);
+
+	__sync_fetch_and_add(&ipconfig->refcount, 1);
+
+	return ipconfig;
+}
+
+/**
+ * connman_ipconfig_unref:
+ * @ipconfig: ipconfig structure
+ *
+ * Decrease reference counter of ipconfig
+ */
+void __connman_ipconfig_unref_debug(struct connman_ipconfig *ipconfig,
+				const char *file, int line, const char *caller)
+{
+	if (!ipconfig)
+		return;
+
+	DBG("%p ref %d by %s:%d:%s()", ipconfig, ipconfig->refcount - 1,
+		file, line, caller);
+
+	if (__sync_fetch_and_sub(&ipconfig->refcount, 1) != 1)
+		return;
+
+	if (__connman_ipconfig_disable(ipconfig) < 0)
+		ipconfig_list = g_list_remove(ipconfig_list, ipconfig);
+
+	__connman_ipconfig_set_ops(ipconfig, NULL);
+
+	connman_ipaddress_free(ipconfig->system);
+	connman_ipaddress_free(ipconfig->address);
+	g_free(ipconfig->last_dhcp_address);
+	g_strfreev(ipconfig->last_dhcpv6_prefixes);
+	g_free(ipconfig);
+}
+
+/**
+ * connman_ipconfig_get_data:
+ * @ipconfig: ipconfig structure
+ *
+ * Get private data pointer
+ */
+void *__connman_ipconfig_get_data(struct connman_ipconfig *ipconfig)
+{
+	if (!ipconfig)
+		return NULL;
+
+	return ipconfig->ops_data;
+}
+
+/**
+ * connman_ipconfig_set_data:
+ * @ipconfig: ipconfig structure
+ * @data: data pointer
+ *
+ * Set private data pointer
+ */
+void __connman_ipconfig_set_data(struct connman_ipconfig *ipconfig, void *data)
+{
+	ipconfig->ops_data = data;
+}
+
+/**
+ * connman_ipconfig_get_index:
+ * @ipconfig: ipconfig structure
+ *
+ * Get interface index
+ */
+int __connman_ipconfig_get_index(struct connman_ipconfig *ipconfig)
+{
+	if (!ipconfig)
+		return -1;
+
+	return ipconfig->index;
+}
+
+/**
+ * connman_ipconfig_set_ops:
+ * @ipconfig: ipconfig structure
+ * @ops: operation callbacks
+ *
+ * Set the operation callbacks
+ */
+void __connman_ipconfig_set_ops(struct connman_ipconfig *ipconfig,
+				const struct connman_ipconfig_ops *ops)
+{
+	ipconfig->ops = ops;
+}
+
+/**
+ * connman_ipconfig_set_method:
+ * @ipconfig: ipconfig structure
+ * @method: configuration method
+ *
+ * Set the configuration method
+ */
+int __connman_ipconfig_set_method(struct connman_ipconfig *ipconfig,
+					enum connman_ipconfig_method method)
+{
+	ipconfig->method = method;
+
+	return 0;
+}
+
+enum connman_ipconfig_method __connman_ipconfig_get_method(
+				struct connman_ipconfig *ipconfig)
+{
+	if (!ipconfig)
+		return CONNMAN_IPCONFIG_METHOD_UNKNOWN;
+
+	return ipconfig->method;
+}
+
+int __connman_ipconfig_address_add(struct connman_ipconfig *ipconfig)
+{
+	DBG("");
+
+	switch (ipconfig->method) {
+	case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
+	case CONNMAN_IPCONFIG_METHOD_OFF:
+		break;
+	case CONNMAN_IPCONFIG_METHOD_AUTO:
+	case CONNMAN_IPCONFIG_METHOD_FIXED:
+	case CONNMAN_IPCONFIG_METHOD_DHCP:
+	case CONNMAN_IPCONFIG_METHOD_MANUAL:
+		if (ipconfig->type == CONNMAN_IPCONFIG_TYPE_IPV4)
+			return connman_inet_set_address(ipconfig->index,
+							ipconfig->address);
+		else if (ipconfig->type == CONNMAN_IPCONFIG_TYPE_IPV6)
+			return connman_inet_set_ipv6_address(
+					ipconfig->index, ipconfig->address);
+	}
+
+	return 0;
+}
+
+int __connman_ipconfig_address_remove(struct connman_ipconfig *ipconfig)
+{
+	int err;
+
+	DBG("");
+
+	if (!ipconfig)
+		return 0;
+
+	DBG("method %d", ipconfig->method);
+
+	switch (ipconfig->method) {
+	case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
+	case CONNMAN_IPCONFIG_METHOD_OFF:
+		break;
+	case CONNMAN_IPCONFIG_METHOD_AUTO:
+	case CONNMAN_IPCONFIG_METHOD_FIXED:
+	case CONNMAN_IPCONFIG_METHOD_DHCP:
+	case CONNMAN_IPCONFIG_METHOD_MANUAL:
+		err = __connman_ipconfig_address_unset(ipconfig);
+		connman_ipaddress_clear(ipconfig->address);
+
+		return err;
+	}
+
+	return 0;
+}
+
+int __connman_ipconfig_address_unset(struct connman_ipconfig *ipconfig)
+{
+	int err;
+
+	DBG("");
+
+	if (!ipconfig)
+		return 0;
+
+	DBG("method %d", ipconfig->method);
+
+	switch (ipconfig->method) {
+	case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
+	case CONNMAN_IPCONFIG_METHOD_OFF:
+		break;
+	case CONNMAN_IPCONFIG_METHOD_AUTO:
+	case CONNMAN_IPCONFIG_METHOD_FIXED:
+	case CONNMAN_IPCONFIG_METHOD_DHCP:
+	case CONNMAN_IPCONFIG_METHOD_MANUAL:
+		if (ipconfig->type == CONNMAN_IPCONFIG_TYPE_IPV4)
+			err = connman_inet_clear_address(ipconfig->index,
+							ipconfig->address);
+		else if (ipconfig->type == CONNMAN_IPCONFIG_TYPE_IPV6)
+			err = connman_inet_clear_ipv6_address(
+						ipconfig->index,
+						ipconfig->address->local,
+						ipconfig->address->prefixlen);
+		else
+			err = -EINVAL;
+
+		return err;
+	}
+
+	return 0;
+}
+
+int __connman_ipconfig_set_proxy_autoconfig(struct connman_ipconfig *ipconfig,
+                                                        const char *url)
+{
+	struct connman_ipdevice *ipdevice;
+
+	DBG("ipconfig %p", ipconfig);
+
+	if (!ipconfig || ipconfig->index < 0)
+		return -ENODEV;
+
+	ipdevice = g_hash_table_lookup(ipdevice_hash,
+					GINT_TO_POINTER(ipconfig->index));
+	if (!ipdevice)
+		return -ENXIO;
+
+	g_free(ipdevice->pac);
+	ipdevice->pac = g_strdup(url);
+
+	return 0;
+}
+
+const char *__connman_ipconfig_get_proxy_autoconfig(struct connman_ipconfig *ipconfig)
+{
+	struct connman_ipdevice *ipdevice;
+
+	DBG("ipconfig %p", ipconfig);
+
+	if (!ipconfig || ipconfig->index < 0)
+		return NULL;
+
+	ipdevice = g_hash_table_lookup(ipdevice_hash,
+					GINT_TO_POINTER(ipconfig->index));
+	if (!ipdevice)
+		return NULL;
+
+	return ipdevice->pac;
+}
+
+void __connman_ipconfig_set_dhcp_address(struct connman_ipconfig *ipconfig,
+					const char *address)
+{
+	if (!ipconfig)
+		return;
+
+	g_free(ipconfig->last_dhcp_address);
+	ipconfig->last_dhcp_address = g_strdup(address);
+}
+
+char *__connman_ipconfig_get_dhcp_address(struct connman_ipconfig *ipconfig)
+{
+	if (!ipconfig)
+		return NULL;
+
+	return ipconfig->last_dhcp_address;
+}
+
+void __connman_ipconfig_set_dhcpv6_prefixes(struct connman_ipconfig *ipconfig,
+					char **prefixes)
+{
+	if (!ipconfig)
+		return;
+
+	g_strfreev(ipconfig->last_dhcpv6_prefixes);
+	ipconfig->last_dhcpv6_prefixes = prefixes;
+}
+
+char **__connman_ipconfig_get_dhcpv6_prefixes(struct connman_ipconfig *ipconfig)
+{
+	if (!ipconfig)
+		return NULL;
+
+	return ipconfig->last_dhcpv6_prefixes;
+}
+
+static void disable_ipv6(struct connman_ipconfig *ipconfig)
+{
+	struct connman_ipdevice *ipdevice;
+	char *ifname;
+
+	DBG("");
+
+	ipdevice = g_hash_table_lookup(ipdevice_hash,
+					GINT_TO_POINTER(ipconfig->index));
+	if (!ipdevice)
+		return;
+
+	ifname = connman_inet_ifname(ipconfig->index);
+
+	set_ipv6_state(ifname, false);
+
+	g_free(ifname);
+}
+
+static void enable_ipv6(struct connman_ipconfig *ipconfig)
+{
+	struct connman_ipdevice *ipdevice;
+	char *ifname;
+
+	DBG("");
+
+	ipdevice = g_hash_table_lookup(ipdevice_hash,
+					GINT_TO_POINTER(ipconfig->index));
+	if (!ipdevice)
+		return;
+
+	ifname = connman_inet_ifname(ipconfig->index);
+
+	if (ipconfig->method == CONNMAN_IPCONFIG_METHOD_AUTO)
+		set_ipv6_privacy(ifname, ipconfig->ipv6_privacy_config);
+
+	set_ipv6_state(ifname, true);
+
+	g_free(ifname);
+}
+
+void __connman_ipconfig_enable_ipv6(struct connman_ipconfig *ipconfig)
+{
+	if (!ipconfig || ipconfig->type != CONNMAN_IPCONFIG_TYPE_IPV6)
+		return;
+
+	enable_ipv6(ipconfig);
+}
+
+void __connman_ipconfig_disable_ipv6(struct connman_ipconfig *ipconfig)
+{
+	if (!ipconfig || ipconfig->type != CONNMAN_IPCONFIG_TYPE_IPV6)
+		return;
+
+	disable_ipv6(ipconfig);
+}
+
+bool __connman_ipconfig_is_usable(struct connman_ipconfig *ipconfig)
+{
+	if (!ipconfig)
+		return false;
+
+	switch (ipconfig->method) {
+	case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
+	case CONNMAN_IPCONFIG_METHOD_OFF:
+		return false;
+	case CONNMAN_IPCONFIG_METHOD_AUTO:
+	case CONNMAN_IPCONFIG_METHOD_FIXED:
+	case CONNMAN_IPCONFIG_METHOD_DHCP:
+	case CONNMAN_IPCONFIG_METHOD_MANUAL:
+		break;
+	}
+
+	return true;
+}
+
+int __connman_ipconfig_enable(struct connman_ipconfig *ipconfig)
+{
+	struct connman_ipdevice *ipdevice;
+	bool up = false, down = false;
+	bool lower_up = false, lower_down = false;
+	enum connman_ipconfig_type type;
+	char *ifname;
+
+	DBG("ipconfig %p", ipconfig);
+
+	if (!ipconfig || ipconfig->index < 0)
+		return -ENODEV;
+
+	ipdevice = g_hash_table_lookup(ipdevice_hash,
+					GINT_TO_POINTER(ipconfig->index));
+	if (!ipdevice)
+		return -ENXIO;
+
+	if (ipconfig->type == CONNMAN_IPCONFIG_TYPE_IPV4) {
+		if (ipdevice->config_ipv4 == ipconfig)
+			return -EALREADY;
+		type = CONNMAN_IPCONFIG_TYPE_IPV4;
+	} else if (ipconfig->type == CONNMAN_IPCONFIG_TYPE_IPV6) {
+		if (ipdevice->config_ipv6 == ipconfig)
+			return -EALREADY;
+		type = CONNMAN_IPCONFIG_TYPE_IPV6;
+	} else
+		return -EINVAL;
+
+	ipconfig->enabled = true;
+
+	if (type == CONNMAN_IPCONFIG_TYPE_IPV4 &&
+					ipdevice->config_ipv4) {
+		ipconfig_list = g_list_remove(ipconfig_list,
+							ipdevice->config_ipv4);
+
+		connman_ipaddress_clear(ipdevice->config_ipv4->system);
+
+		__connman_ipconfig_unref(ipdevice->config_ipv4);
+	}
+
+	if (type == CONNMAN_IPCONFIG_TYPE_IPV6 &&
+					ipdevice->config_ipv6) {
+		ipconfig_list = g_list_remove(ipconfig_list,
+							ipdevice->config_ipv6);
+
+		connman_ipaddress_clear(ipdevice->config_ipv6->system);
+
+		__connman_ipconfig_unref(ipdevice->config_ipv6);
+	}
+
+	if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
+		ipdevice->config_ipv4 = __connman_ipconfig_ref(ipconfig);
+	else if (type == CONNMAN_IPCONFIG_TYPE_IPV6) {
+		ipdevice->config_ipv6 = __connman_ipconfig_ref(ipconfig);
+
+		enable_ipv6(ipdevice->config_ipv6);
+	}
+	ipconfig_list = g_list_append(ipconfig_list, ipconfig);
+
+	if (ipdevice->flags & IFF_UP)
+		up = true;
+	else
+		down = true;
+
+	if ((ipdevice->flags & (IFF_RUNNING | IFF_LOWER_UP)) ==
+			(IFF_RUNNING | IFF_LOWER_UP))
+		lower_up = true;
+	else if ((ipdevice->flags & (IFF_RUNNING | IFF_LOWER_UP)) == 0)
+		lower_down = true;
+
+	ifname = connman_inet_ifname(ipconfig->index);
+
+	if (up && ipconfig->ops->up)
+		ipconfig->ops->up(ipconfig, ifname);
+	if (lower_up && ipconfig->ops->lower_up)
+		ipconfig->ops->lower_up(ipconfig, ifname);
+
+	if (lower_down && ipconfig->ops->lower_down)
+		ipconfig->ops->lower_down(ipconfig, ifname);
+	if (down && ipconfig->ops->down)
+		ipconfig->ops->down(ipconfig, ifname);
+
+	g_free(ifname);
+
+	return 0;
+}
+
+int __connman_ipconfig_disable(struct connman_ipconfig *ipconfig)
+{
+	struct connman_ipdevice *ipdevice;
+
+	DBG("ipconfig %p", ipconfig);
+
+	if (!ipconfig || ipconfig->index < 0)
+		return -ENODEV;
+
+	ipdevice = g_hash_table_lookup(ipdevice_hash,
+					GINT_TO_POINTER(ipconfig->index));
+	if (!ipdevice)
+		return -ENXIO;
+
+	if (!ipdevice->config_ipv4 && !ipdevice->config_ipv6)
+		return -EINVAL;
+
+	ipconfig->enabled = false;
+
+	if (ipdevice->config_ipv4 == ipconfig) {
+		ipconfig_list = g_list_remove(ipconfig_list, ipconfig);
+
+		connman_ipaddress_clear(ipdevice->config_ipv4->system);
+		__connman_ipconfig_unref(ipdevice->config_ipv4);
+		ipdevice->config_ipv4 = NULL;
+		return 0;
+	}
+
+	if (ipdevice->config_ipv6 == ipconfig) {
+		ipconfig_list = g_list_remove(ipconfig_list, ipconfig);
+
+		connman_ipaddress_clear(ipdevice->config_ipv6->system);
+		__connman_ipconfig_unref(ipdevice->config_ipv6);
+		ipdevice->config_ipv6 = NULL;
+		return 0;
+	}
+
+	return -EINVAL;
+}
+
+const char *__connman_ipconfig_method2string(enum connman_ipconfig_method method)
+{
+	switch (method) {
+	case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
+		break;
+	case CONNMAN_IPCONFIG_METHOD_OFF:
+		return "off";
+	case CONNMAN_IPCONFIG_METHOD_FIXED:
+		return "fixed";
+	case CONNMAN_IPCONFIG_METHOD_MANUAL:
+		return "manual";
+	case CONNMAN_IPCONFIG_METHOD_DHCP:
+		return "dhcp";
+	case CONNMAN_IPCONFIG_METHOD_AUTO:
+		return "auto";
+	}
+
+	return NULL;
+}
+
+enum connman_ipconfig_method __connman_ipconfig_string2method(const char *method)
+{
+	if (g_strcmp0(method, "off") == 0)
+		return CONNMAN_IPCONFIG_METHOD_OFF;
+	else if (g_strcmp0(method, "fixed") == 0)
+		return CONNMAN_IPCONFIG_METHOD_FIXED;
+	else if (g_strcmp0(method, "manual") == 0)
+		return CONNMAN_IPCONFIG_METHOD_MANUAL;
+	else if (g_strcmp0(method, "dhcp") == 0)
+		return CONNMAN_IPCONFIG_METHOD_DHCP;
+	else if (g_strcmp0(method, "auto") == 0)
+		return CONNMAN_IPCONFIG_METHOD_AUTO;
+	else
+		return CONNMAN_IPCONFIG_METHOD_UNKNOWN;
+}
+
+static const char *privacy2string(int privacy)
+{
+	if (privacy <= 0)
+		return "disabled";
+	else if (privacy == 1)
+		return "enabled";
+	else
+		return "prefered";
+}
+
+static int string2privacy(const char *privacy)
+{
+	if (g_strcmp0(privacy, "disabled") == 0)
+		return 0;
+	else if (g_strcmp0(privacy, "enabled") == 0)
+		return 1;
+	else if (g_strcmp0(privacy, "preferred") == 0)
+		return 2;
+	else if (g_strcmp0(privacy, "prefered") == 0)
+		return 2;
+	else
+		return 0;
+}
+
+int __connman_ipconfig_ipv6_reset_privacy(struct connman_ipconfig *ipconfig)
+{
+	struct connman_ipdevice *ipdevice;
+	int err;
+
+	if (!ipconfig)
+		return -EINVAL;
+
+	ipdevice = g_hash_table_lookup(ipdevice_hash,
+						GINT_TO_POINTER(ipconfig->index));
+	if (!ipdevice)
+		return -ENODEV;
+
+	err = __connman_ipconfig_ipv6_set_privacy(ipconfig, privacy2string(
+							ipdevice->ipv6_privacy));
+
+	return err;
+}
+
+int __connman_ipconfig_ipv6_set_privacy(struct connman_ipconfig *ipconfig,
+					const char *value)
+{
+	int privacy;
+
+	if (!ipconfig)
+		return -EINVAL;
+
+	DBG("ipconfig %p privacy %s", ipconfig, value);
+
+	privacy = string2privacy(value);
+
+	ipconfig->ipv6_privacy_config = privacy;
+
+	enable_ipv6(ipconfig);
+
+	return 0;
+}
+
+void __connman_ipconfig_append_ipv4(struct connman_ipconfig *ipconfig,
+							DBusMessageIter *iter)
+{
+	struct connman_ipaddress *append_addr = NULL;
+	const char *str;
+
+	DBG("");
+
+	if (ipconfig->type != CONNMAN_IPCONFIG_TYPE_IPV4)
+		return;
+
+	str = __connman_ipconfig_method2string(ipconfig->method);
+	if (!str)
+		return;
+
+	connman_dbus_dict_append_basic(iter, "Method", DBUS_TYPE_STRING, &str);
+
+	switch (ipconfig->method) {
+	case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
+	case CONNMAN_IPCONFIG_METHOD_OFF:
+	case CONNMAN_IPCONFIG_METHOD_AUTO:
+		return;
+
+	case CONNMAN_IPCONFIG_METHOD_FIXED:
+		append_addr = ipconfig->address;
+		break;
+
+	case CONNMAN_IPCONFIG_METHOD_MANUAL:
+	case CONNMAN_IPCONFIG_METHOD_DHCP:
+		append_addr = ipconfig->system;
+		break;
+	}
+
+	if (!append_addr)
+		return;
+
+	if (append_addr->local) {
+		in_addr_t addr;
+		struct in_addr netmask;
+		char *mask;
+
+		connman_dbus_dict_append_basic(iter, "Address",
+				DBUS_TYPE_STRING, &append_addr->local);
+
+		addr = 0xffffffff << (32 - append_addr->prefixlen);
+		netmask.s_addr = htonl(addr);
+		mask = inet_ntoa(netmask);
+		connman_dbus_dict_append_basic(iter, "Netmask",
+						DBUS_TYPE_STRING, &mask);
+	}
+
+	if (append_addr->gateway)
+		connman_dbus_dict_append_basic(iter, "Gateway",
+				DBUS_TYPE_STRING, &append_addr->gateway);
+}
+
+void __connman_ipconfig_append_ipv6(struct connman_ipconfig *ipconfig,
+					DBusMessageIter *iter,
+					struct connman_ipconfig *ipconfig_ipv4)
+{
+	struct connman_ipaddress *append_addr = NULL;
+	const char *str, *privacy;
+
+	DBG("");
+
+	if (ipconfig->type != CONNMAN_IPCONFIG_TYPE_IPV6)
+		return;
+
+	str = __connman_ipconfig_method2string(ipconfig->method);
+	if (!str)
+		return;
+
+	if (ipconfig_ipv4 &&
+			ipconfig->method == CONNMAN_IPCONFIG_METHOD_AUTO) {
+		if (__connman_6to4_check(ipconfig_ipv4) == 1)
+			str = "6to4";
+	}
+
+	connman_dbus_dict_append_basic(iter, "Method", DBUS_TYPE_STRING, &str);
+
+	switch (ipconfig->method) {
+	case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
+	case CONNMAN_IPCONFIG_METHOD_OFF:
+		return;
+
+	case CONNMAN_IPCONFIG_METHOD_FIXED:
+		append_addr = ipconfig->address;
+		break;
+
+	case CONNMAN_IPCONFIG_METHOD_MANUAL:
+	case CONNMAN_IPCONFIG_METHOD_DHCP:
+	case CONNMAN_IPCONFIG_METHOD_AUTO:
+		append_addr = ipconfig->system;
+		break;
+	}
+
+	if (!append_addr)
+		return;
+
+	if (append_addr->local) {
+		connman_dbus_dict_append_basic(iter, "Address",
+				DBUS_TYPE_STRING, &append_addr->local);
+		connman_dbus_dict_append_basic(iter, "PrefixLength",
+						DBUS_TYPE_BYTE,
+						&append_addr->prefixlen);
+	}
+
+	if (append_addr->gateway)
+		connman_dbus_dict_append_basic(iter, "Gateway",
+				DBUS_TYPE_STRING, &append_addr->gateway);
+
+	privacy = privacy2string(ipconfig->ipv6_privacy_config);
+	connman_dbus_dict_append_basic(iter, "Privacy",
+				DBUS_TYPE_STRING, &privacy);
+}
+
+void __connman_ipconfig_append_ipv6config(struct connman_ipconfig *ipconfig,
+							DBusMessageIter *iter)
+{
+	const char *str, *privacy;
+
+	DBG("");
+
+	str = __connman_ipconfig_method2string(ipconfig->method);
+	if (!str)
+		return;
+
+	connman_dbus_dict_append_basic(iter, "Method", DBUS_TYPE_STRING, &str);
+
+	switch (ipconfig->method) {
+	case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
+	case CONNMAN_IPCONFIG_METHOD_OFF:
+	case CONNMAN_IPCONFIG_METHOD_DHCP:
+		return;
+	case CONNMAN_IPCONFIG_METHOD_FIXED:
+	case CONNMAN_IPCONFIG_METHOD_MANUAL:
+	case CONNMAN_IPCONFIG_METHOD_AUTO:
+		break;
+	}
+
+	if (!ipconfig->address)
+		return;
+
+	if (ipconfig->address->local) {
+		connman_dbus_dict_append_basic(iter, "Address",
+				DBUS_TYPE_STRING, &ipconfig->address->local);
+		connman_dbus_dict_append_basic(iter, "PrefixLength",
+						DBUS_TYPE_BYTE,
+						&ipconfig->address->prefixlen);
+	}
+
+	if (ipconfig->address->gateway)
+		connman_dbus_dict_append_basic(iter, "Gateway",
+				DBUS_TYPE_STRING, &ipconfig->address->gateway);
+
+	privacy = privacy2string(ipconfig->ipv6_privacy_config);
+	connman_dbus_dict_append_basic(iter, "Privacy",
+				DBUS_TYPE_STRING, &privacy);
+}
+
+void __connman_ipconfig_append_ipv4config(struct connman_ipconfig *ipconfig,
+							DBusMessageIter *iter)
+{
+	const char *str;
+
+	DBG("");
+
+	str = __connman_ipconfig_method2string(ipconfig->method);
+	if (!str)
+		return;
+
+	connman_dbus_dict_append_basic(iter, "Method", DBUS_TYPE_STRING, &str);
+
+	switch (ipconfig->method) {
+	case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
+	case CONNMAN_IPCONFIG_METHOD_OFF:
+	case CONNMAN_IPCONFIG_METHOD_DHCP:
+	case CONNMAN_IPCONFIG_METHOD_AUTO:
+		return;
+	case CONNMAN_IPCONFIG_METHOD_FIXED:
+	case CONNMAN_IPCONFIG_METHOD_MANUAL:
+		break;
+	}
+
+	if (!ipconfig->address)
+		return;
+
+	if (ipconfig->address->local) {
+		in_addr_t addr;
+		struct in_addr netmask;
+		char *mask;
+
+		connman_dbus_dict_append_basic(iter, "Address",
+				DBUS_TYPE_STRING, &ipconfig->address->local);
+
+		addr = 0xffffffff << (32 - ipconfig->address->prefixlen);
+		netmask.s_addr = htonl(addr);
+		mask = inet_ntoa(netmask);
+		connman_dbus_dict_append_basic(iter, "Netmask",
+						DBUS_TYPE_STRING, &mask);
+	}
+
+	if (ipconfig->address->gateway)
+		connman_dbus_dict_append_basic(iter, "Gateway",
+				DBUS_TYPE_STRING, &ipconfig->address->gateway);
+}
+
+int __connman_ipconfig_set_config(struct connman_ipconfig *ipconfig,
+							DBusMessageIter *array)
+{
+	enum connman_ipconfig_method method = CONNMAN_IPCONFIG_METHOD_UNKNOWN;
+	const char *address = NULL, *netmask = NULL, *gateway = NULL,
+		*privacy_string = NULL;
+	int prefix_length = 0, privacy = 0;
+	DBusMessageIter dict;
+	int type = -1;
+
+	DBG("ipconfig %p", ipconfig);
+
+	if (dbus_message_iter_get_arg_type(array) != DBUS_TYPE_ARRAY)
+		return -EINVAL;
+
+	dbus_message_iter_recurse(array, &dict);
+
+	while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
+		DBusMessageIter entry, value;
+		const char *key;
+		int type;
+
+		dbus_message_iter_recurse(&dict, &entry);
+
+		if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING)
+			return -EINVAL;
+
+		dbus_message_iter_get_basic(&entry, &key);
+		dbus_message_iter_next(&entry);
+
+		if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_VARIANT)
+			return -EINVAL;
+
+		dbus_message_iter_recurse(&entry, &value);
+
+		type = dbus_message_iter_get_arg_type(&value);
+
+		if (g_str_equal(key, "Method")) {
+			const char *str;
+
+			if (type != DBUS_TYPE_STRING)
+				return -EINVAL;
+
+			dbus_message_iter_get_basic(&value, &str);
+			method = __connman_ipconfig_string2method(str);
+		} else if (g_str_equal(key, "Address")) {
+			if (type != DBUS_TYPE_STRING)
+				return -EINVAL;
+
+			dbus_message_iter_get_basic(&value, &address);
+		} else if (g_str_equal(key, "PrefixLength")) {
+			if (type != DBUS_TYPE_BYTE)
+				return -EINVAL;
+
+			dbus_message_iter_get_basic(&value, &prefix_length);
+
+			if (prefix_length < 0 || prefix_length > 128)
+				return -EINVAL;
+		} else if (g_str_equal(key, "Netmask")) {
+			if (type != DBUS_TYPE_STRING)
+				return -EINVAL;
+
+			dbus_message_iter_get_basic(&value, &netmask);
+		} else if (g_str_equal(key, "Gateway")) {
+			if (type != DBUS_TYPE_STRING)
+				return -EINVAL;
+
+			dbus_message_iter_get_basic(&value, &gateway);
+		} else if (g_str_equal(key, "Privacy")) {
+			if (type != DBUS_TYPE_STRING)
+				return -EINVAL;
+
+			dbus_message_iter_get_basic(&value, &privacy_string);
+			privacy = string2privacy(privacy_string);
+		}
+
+		dbus_message_iter_next(&dict);
+	}
+
+	DBG("method %d address %s netmask %s gateway %s prefix_length %d "
+		"privacy %s",
+		method, address, netmask, gateway, prefix_length,
+		privacy_string);
+
+	switch (method) {
+	case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
+	case CONNMAN_IPCONFIG_METHOD_FIXED:
+		return -EINVAL;
+
+	case CONNMAN_IPCONFIG_METHOD_OFF:
+		ipconfig->method = method;
+
+		break;
+
+	case CONNMAN_IPCONFIG_METHOD_AUTO:
+		if (ipconfig->type != CONNMAN_IPCONFIG_TYPE_IPV6)
+			return -EOPNOTSUPP;
+
+		ipconfig->method = method;
+		if (privacy_string)
+			ipconfig->ipv6_privacy_config = privacy;
+
+		break;
+
+	case CONNMAN_IPCONFIG_METHOD_MANUAL:
+		switch (ipconfig->type) {
+		case CONNMAN_IPCONFIG_TYPE_IPV4:
+			type = AF_INET;
+			break;
+		case CONNMAN_IPCONFIG_TYPE_IPV6:
+			type = AF_INET6;
+			break;
+		case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
+		case CONNMAN_IPCONFIG_TYPE_ALL:
+			type = -1;
+			break;
+		}
+
+		if ((address && connman_inet_check_ipaddress(address)
+						!= type) ||
+				(netmask &&
+				connman_inet_check_ipaddress(netmask)
+						!= type) ||
+				(gateway &&
+				connman_inet_check_ipaddress(gateway)
+						!= type))
+			return -EINVAL;
+
+		ipconfig->method = method;
+
+		if (ipconfig->type == CONNMAN_IPCONFIG_TYPE_IPV4)
+			connman_ipaddress_set_ipv4(ipconfig->address,
+						address, netmask, gateway);
+		else
+			return connman_ipaddress_set_ipv6(
+					ipconfig->address, address,
+						prefix_length, gateway);
+
+		break;
+
+	case CONNMAN_IPCONFIG_METHOD_DHCP:
+		if (ipconfig->type != CONNMAN_IPCONFIG_TYPE_IPV4)
+			return -EOPNOTSUPP;
+
+		ipconfig->method = method;
+		break;
+	}
+
+	return 0;
+}
+
+void __connman_ipconfig_append_ethernet(struct connman_ipconfig *ipconfig,
+							DBusMessageIter *iter)
+{
+	struct connman_ipdevice *ipdevice;
+	const char *method = "auto";
+
+	connman_dbus_dict_append_basic(iter, "Method",
+						DBUS_TYPE_STRING, &method);
+
+	ipdevice = g_hash_table_lookup(ipdevice_hash,
+					GINT_TO_POINTER(ipconfig->index));
+	if (!ipdevice)
+		return;
+
+	if (ipconfig->index >= 0) {
+		char *ifname = connman_inet_ifname(ipconfig->index);
+		if (ifname) {
+			connman_dbus_dict_append_basic(iter, "Interface",
+						DBUS_TYPE_STRING, &ifname);
+			g_free(ifname);
+		}
+	}
+
+	if (ipdevice->address)
+		connman_dbus_dict_append_basic(iter, "Address",
+					DBUS_TYPE_STRING, &ipdevice->address);
+
+	if (ipdevice->mtu > 0)
+		connman_dbus_dict_append_basic(iter, "MTU",
+					DBUS_TYPE_UINT16, &ipdevice->mtu);
+}
+
+int __connman_ipconfig_load(struct connman_ipconfig *ipconfig,
+		GKeyFile *keyfile, const char *identifier, const char *prefix)
+{
+	char *method;
+	char *key;
+	char *str;
+
+	DBG("ipconfig %p identifier %s", ipconfig, identifier);
+
+	key = g_strdup_printf("%smethod", prefix);
+	method = g_key_file_get_string(keyfile, identifier, key, NULL);
+	if (!method) {
+		switch (ipconfig->type) {
+		case CONNMAN_IPCONFIG_TYPE_IPV4:
+			ipconfig->method = CONNMAN_IPCONFIG_METHOD_DHCP;
+			break;
+		case CONNMAN_IPCONFIG_TYPE_IPV6:
+			ipconfig->method = CONNMAN_IPCONFIG_METHOD_AUTO;
+			break;
+		case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
+		case CONNMAN_IPCONFIG_TYPE_ALL:
+			ipconfig->method = CONNMAN_IPCONFIG_METHOD_OFF;
+			break;
+		}
+	} else
+		ipconfig->method = __connman_ipconfig_string2method(method);
+
+	if (ipconfig->method == CONNMAN_IPCONFIG_METHOD_UNKNOWN)
+		ipconfig->method = CONNMAN_IPCONFIG_METHOD_OFF;
+
+	if (ipconfig->type == CONNMAN_IPCONFIG_TYPE_IPV6) {
+		gsize length;
+		char *pprefix;
+
+		if (ipconfig->method == CONNMAN_IPCONFIG_METHOD_AUTO ||
+			ipconfig->method == CONNMAN_IPCONFIG_METHOD_MANUAL) {
+			char *privacy;
+
+			pprefix = g_strdup_printf("%sprivacy", prefix);
+			privacy = g_key_file_get_string(keyfile, identifier,
+							pprefix, NULL);
+			ipconfig->ipv6_privacy_config = string2privacy(privacy);
+			g_free(pprefix);
+			g_free(privacy);
+		}
+
+		pprefix = g_strdup_printf("%sDHCP.LastPrefixes", prefix);
+		ipconfig->last_dhcpv6_prefixes =
+			g_key_file_get_string_list(keyfile, identifier, pprefix,
+						&length, NULL);
+		if (ipconfig->last_dhcpv6_prefixes && length == 0) {
+			g_free(ipconfig->last_dhcpv6_prefixes);
+			ipconfig->last_dhcpv6_prefixes = NULL;
+		}
+		g_free(pprefix);
+	}
+
+	g_free(method);
+	g_free(key);
+
+	switch (ipconfig->method) {
+	case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
+	case CONNMAN_IPCONFIG_METHOD_OFF:
+		break;
+
+	case CONNMAN_IPCONFIG_METHOD_FIXED:
+	case CONNMAN_IPCONFIG_METHOD_MANUAL:
+
+		key = g_strdup_printf("%snetmask_prefixlen", prefix);
+		ipconfig->address->prefixlen = g_key_file_get_integer(
+				keyfile, identifier, key, NULL);
+		g_free(key);
+
+		key = g_strdup_printf("%slocal_address", prefix);
+		g_free(ipconfig->address->local);
+		ipconfig->address->local = g_key_file_get_string(
+			keyfile, identifier, key, NULL);
+		g_free(key);
+
+		key = g_strdup_printf("%speer_address", prefix);
+		g_free(ipconfig->address->peer);
+		ipconfig->address->peer = g_key_file_get_string(
+				keyfile, identifier, key, NULL);
+		g_free(key);
+
+		key = g_strdup_printf("%sbroadcast_address", prefix);
+		g_free(ipconfig->address->broadcast);
+		ipconfig->address->broadcast = g_key_file_get_string(
+				keyfile, identifier, key, NULL);
+		g_free(key);
+
+		key = g_strdup_printf("%sgateway", prefix);
+		g_free(ipconfig->address->gateway);
+		ipconfig->address->gateway = g_key_file_get_string(
+				keyfile, identifier, key, NULL);
+		g_free(key);
+		break;
+
+	case CONNMAN_IPCONFIG_METHOD_DHCP:
+
+		key = g_strdup_printf("%sDHCP.LastAddress", prefix);
+		str = g_key_file_get_string(keyfile, identifier, key, NULL);
+		if (str) {
+			g_free(ipconfig->last_dhcp_address);
+			ipconfig->last_dhcp_address = str;
+		}
+		g_free(key);
+
+		break;
+
+	case CONNMAN_IPCONFIG_METHOD_AUTO:
+		break;
+	}
+
+	return 0;
+}
+
+int __connman_ipconfig_save(struct connman_ipconfig *ipconfig,
+		GKeyFile *keyfile, const char *identifier, const char *prefix)
+{
+	const char *method;
+	char *key;
+
+	method = __connman_ipconfig_method2string(ipconfig->method);
+
+	DBG("ipconfig %p identifier %s method %s", ipconfig, identifier,
+								method);
+	if (method) {
+		key = g_strdup_printf("%smethod", prefix);
+		g_key_file_set_string(keyfile, identifier, key, method);
+		g_free(key);
+	}
+
+	if (ipconfig->type == CONNMAN_IPCONFIG_TYPE_IPV6) {
+		const char *privacy;
+		privacy = privacy2string(ipconfig->ipv6_privacy_config);
+		key = g_strdup_printf("%sprivacy", prefix);
+		g_key_file_set_string(keyfile, identifier, key, privacy);
+		g_free(key);
+
+		key = g_strdup_printf("%sDHCP.LastAddress", prefix);
+		if (ipconfig->last_dhcp_address &&
+				strlen(ipconfig->last_dhcp_address) > 0)
+			g_key_file_set_string(keyfile, identifier, key,
+					ipconfig->last_dhcp_address);
+		else
+			g_key_file_remove_key(keyfile, identifier, key, NULL);
+		g_free(key);
+
+		key = g_strdup_printf("%sDHCP.LastPrefixes", prefix);
+		if (ipconfig->last_dhcpv6_prefixes &&
+				ipconfig->last_dhcpv6_prefixes[0]) {
+			guint len =
+				g_strv_length(ipconfig->last_dhcpv6_prefixes);
+
+			g_key_file_set_string_list(keyfile, identifier, key,
+				(const gchar **)ipconfig->last_dhcpv6_prefixes,
+						len);
+		} else
+			g_key_file_remove_key(keyfile, identifier, key, NULL);
+		g_free(key);
+	}
+
+	switch (ipconfig->method) {
+	case CONNMAN_IPCONFIG_METHOD_FIXED:
+	case CONNMAN_IPCONFIG_METHOD_MANUAL:
+		break;
+	case CONNMAN_IPCONFIG_METHOD_DHCP:
+		key = g_strdup_printf("%sDHCP.LastAddress", prefix);
+		if (ipconfig->last_dhcp_address &&
+				strlen(ipconfig->last_dhcp_address) > 0)
+			g_key_file_set_string(keyfile, identifier, key,
+					ipconfig->last_dhcp_address);
+		else
+			g_key_file_remove_key(keyfile, identifier, key, NULL);
+		g_free(key);
+		/* fall through */
+	case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
+	case CONNMAN_IPCONFIG_METHOD_OFF:
+	case CONNMAN_IPCONFIG_METHOD_AUTO:
+		return 0;
+	}
+
+	key = g_strdup_printf("%snetmask_prefixlen", prefix);
+	if (ipconfig->address->prefixlen != 0)
+		g_key_file_set_integer(keyfile, identifier,
+				key, ipconfig->address->prefixlen);
+	g_free(key);
+
+	key = g_strdup_printf("%slocal_address", prefix);
+	if (ipconfig->address->local)
+		g_key_file_set_string(keyfile, identifier,
+				key, ipconfig->address->local);
+	g_free(key);
+
+	key = g_strdup_printf("%speer_address", prefix);
+	if (ipconfig->address->peer)
+		g_key_file_set_string(keyfile, identifier,
+				key, ipconfig->address->peer);
+	g_free(key);
+
+	key = g_strdup_printf("%sbroadcast_address", prefix);
+	if (ipconfig->address->broadcast)
+		g_key_file_set_string(keyfile, identifier,
+			key, ipconfig->address->broadcast);
+	g_free(key);
+
+	key = g_strdup_printf("%sgateway", prefix);
+	if (ipconfig->address->gateway)
+		g_key_file_set_string(keyfile, identifier,
+			key, ipconfig->address->gateway);
+	g_free(key);
+
+	return 0;
+}
+
+int __connman_ipconfig_init(void)
+{
+	DBG("");
+
+	ipdevice_hash = g_hash_table_new_full(g_direct_hash, g_direct_equal,
+							NULL, free_ipdevice);
+
+	is_ipv6_supported = connman_inet_is_ipv6_supported();
+
+	return 0;
+}
+
+void __connman_ipconfig_cleanup(void)
+{
+	DBG("");
+
+	g_hash_table_destroy(ipdevice_hash);
+	ipdevice_hash = NULL;
+}
diff --git a/connman/src/ippool.c b/connman/src/ippool.c
new file mode 100644
index 0000000..bb8568d
--- /dev/null
+++ b/connman/src/ippool.c
@@ -0,0 +1,469 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2013  Intel Corporation. All rights reserved.
+ *  Copyright (C) 2012-2014  BMW Car IT GmbH.
+ *
+ *  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 <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/errno.h>
+#include <sys/socket.h>
+
+#include "connman.h"
+
+struct address_info {
+	int index;
+	uint32_t start;
+	uint32_t end;
+
+	unsigned int use_count;
+	struct connman_ippool *pool;
+};
+
+struct connman_ippool {
+	unsigned int refcount;
+
+	struct address_info *info;
+
+	char *gateway;
+	char *broadcast;
+	char *start_ip;
+	char *end_ip;
+	char *subnet_mask;
+
+	ippool_collision_cb_t collision_cb;
+	void *user_data;
+};
+
+GSList *allocated_blocks;
+GHashTable *pool_hash;
+
+static uint32_t last_block;
+static uint32_t block_16_bits;
+static uint32_t block_20_bits;
+static uint32_t block_24_bits;
+static uint32_t subnet_mask_24;
+
+struct connman_ippool *
+__connman_ippool_ref_debug(struct connman_ippool *pool,
+				const char *file, int line, const char *caller)
+{
+	DBG("%p ref %d by %s:%d:%s()", pool, pool->refcount + 1,
+		file, line, caller);
+
+	__sync_fetch_and_add(&pool->refcount, 1);
+
+	return pool;
+}
+
+void __connman_ippool_unref_debug(struct connman_ippool *pool,
+				const char *file, int line, const char *caller)
+{
+	if (!pool)
+		return;
+
+	DBG("%p ref %d by %s:%d:%s()", pool, pool->refcount - 1,
+		file, line, caller);
+
+	if (__sync_fetch_and_sub(&pool->refcount, 1) != 1)
+		return;
+
+	g_hash_table_remove(pool_hash, pool);
+}
+
+static char *get_ip(uint32_t ip)
+{
+	struct in_addr addr;
+
+	addr.s_addr = htonl(ip);
+
+	return g_strdup(inet_ntoa(addr));
+}
+
+static uint32_t next_block(uint32_t block)
+{
+	uint32_t next;
+
+	/*
+	 * Return the next IP block within the private IP range
+	 *
+	 * 16-bit block 192.168.0.0 – 192.168.255.255
+	 * 20-bit block  172.16.0.0 –  172.31.255.255
+	 * 24-bit block    10.0.0.0 –  10.255.255.255
+	 */
+
+	next = (block & 0x0000ff00) >> 8;
+	next += 1;
+
+	if (next == 255) {
+		if ((block & 0xffff0000) == block_16_bits) {
+			/*
+			 * Reached the end of the 16 bit block, switch
+			 * to the 20-bit block.
+			 */
+			return block_20_bits;
+		}
+
+		if ((block & 0xffff0000) >= block_20_bits) {
+			next = (block & 0x00ff0000) >> 16;
+			if (next >= 16 && next < 32)
+				next += 1;
+
+			if (next == 32) {
+				/*
+				 * Reached the end of the 20 bit
+				 * block, switch to the 24-bit block.
+				 */
+				return block_24_bits;
+			}
+
+			return (block & 0xff000000) |
+				((next << 16) & 0x00ff0000);
+		}
+
+		if ((block & 0xff000000) == block_24_bits) {
+			next = (block & 0x00ff0000) >> 16;
+			if (next < 255)
+				next += 1;
+
+			if (next == 255) {
+				/*
+				 * Reached the end of the 24 bit
+				 * block, switch to the 16-bit block.
+				 */
+				return block_16_bits;
+			}
+
+			return (block & 0xff000000) |
+				((next << 16) & 0x00ff0000);
+		}
+	}
+
+	return (block & 0xffff0000) | ((next << 8) & 0x0000ff00);
+}
+
+static uint32_t get_free_block(unsigned int size)
+{
+	struct address_info *info;
+	uint32_t block;
+	GSList *list;
+	bool collision;
+
+	/*
+	 * Instead starting always from the 16 bit block, we start
+	 * from the last assigned block. This is a simple optimimazion
+	 * for the case where a lot of blocks have been assigned, e.g.
+	 * the first half of the private IP pool is in use and a new
+	 * we need to find a new block.
+	 *
+	 * To only thing we have to make sure is that we terminated if
+	 * there is no block left.
+	 */
+	if (last_block == 0)
+		block = block_16_bits;
+	else
+		block = next_block(last_block);
+
+	do {
+		collision = false;
+		for (list = allocated_blocks; list; list = list->next) {
+			info = list->data;
+
+			if (info->start <= block && block <= info->end) {
+				collision = true;
+				break;
+			}
+		}
+
+		if (!collision)
+			return block;
+
+		block = next_block(block);
+	} while (block != last_block);
+
+	return 0;
+}
+
+static struct address_info *lookup_info(int index, uint32_t start)
+{
+	GSList *list;
+
+	for (list = allocated_blocks; list; list = list->next) {
+		struct address_info *info = list->data;
+
+		if (info->index == index && info->start == start)
+			return info;
+	}
+
+	return NULL;
+}
+
+static bool is_private_address(uint32_t address)
+{
+	unsigned int a, b;
+
+	a = (address & 0xff000000) >> 24;
+	b = (address & 0x00ff0000) >> 16;
+
+	if (a == 10 || (a == 192 && b == 168) ||
+					(a == 172 && (b >= 16 && b <= 31)))
+		return true;
+
+	return false;
+}
+
+void __connman_ippool_newaddr(int index, const char *address,
+				unsigned char prefixlen)
+{
+	struct address_info *info, *it;
+	struct in_addr inp;
+	uint32_t start, end, mask;
+	GSList *list;
+
+	if (inet_aton(address, &inp) == 0)
+		return;
+
+	start = ntohl(inp.s_addr);
+	if (!is_private_address(start))
+		return;
+
+	if (prefixlen >= 32)
+		mask = 0xffffffff;
+	else
+		mask = ~(0xffffffff >> prefixlen);
+
+	start = start & mask;
+	end = start | ~mask;
+
+	info = lookup_info(index, start);
+	if (info)
+		goto update;
+
+	info = g_try_new0(struct address_info, 1);
+	if (!info)
+		return;
+
+	info->index = index;
+	info->start = start;
+	info->end = end;
+
+	allocated_blocks = g_slist_prepend(allocated_blocks, info);
+
+update:
+	info->use_count = info->use_count + 1;
+
+	if (info->use_count > 1 || info->pool) {
+		/*
+		 * We need only to check for the first IP in a block for
+		 * collisions.
+		 */
+		return;
+	}
+
+	for (list = allocated_blocks; list; list = list->next) {
+		it = list->data;
+
+		if (it == info)
+			continue;
+
+		if (!(info->start >= it->start && info->start <= it->end))
+			continue;
+
+		if (it->pool && it->pool->collision_cb)
+			it->pool->collision_cb(it->pool, it->pool->user_data);
+
+		return;
+	}
+}
+
+void __connman_ippool_deladdr(int index, const char *address,
+				unsigned char prefixlen)
+{
+	struct address_info *info;
+	struct in_addr inp;
+	uint32_t start, mask;
+
+	if (inet_aton(address, &inp) == 0)
+		return;
+
+	start = ntohl(inp.s_addr);
+	if (!is_private_address(start))
+		return;
+
+	mask = ~(0xffffffff >> prefixlen);
+	start = start & mask;
+
+	info = lookup_info(index, start);
+	if (!info) {
+		/* In theory this should never happen */
+		connman_error("Inconsistent IP pool management (start not found)");
+		return;
+	}
+
+	info->use_count = info->use_count - 1;
+	if (info->pool)
+		return;
+
+	if (info->use_count > 0)
+		return;
+
+	allocated_blocks = g_slist_remove(allocated_blocks, info);
+	g_free(info);
+}
+
+struct connman_ippool *__connman_ippool_create(int index,
+					unsigned int start,
+					unsigned int range,
+					ippool_collision_cb_t collision_cb,
+					void *user_data)
+{
+	struct connman_ippool *pool;
+	struct address_info *info;
+	uint32_t block;
+
+	DBG("");
+
+	/*
+	 * The range is at max 255 and we don't support overlapping
+	 * blocks.
+	 */
+	if (start + range > 254) {
+		connman_error("IP pool does not support pool size larger than 254");
+		return NULL;
+	}
+
+	block = get_free_block(start + range);
+	if (block == 0) {
+		connman_warn("Could not find a free IP block");
+		return NULL;
+	}
+
+	pool = g_try_new0(struct connman_ippool, 1);
+	if (!pool)
+		return NULL;
+
+	info = g_try_new0(struct address_info, 1);
+	if (!info) {
+		g_free(pool);
+		return NULL;
+	}
+
+	last_block = block;
+
+	info->index = index;
+	info->start = block;
+	info->end = block + range;
+
+	pool->refcount = 1;
+	pool->info = info;
+	pool->collision_cb = collision_cb;
+	pool->user_data = user_data;
+
+	info->pool = pool;
+
+	if (range == 0)
+		range = 1;
+
+	pool->gateway = get_ip(info->start + 1);
+	pool->broadcast = get_ip(info->start + 255);
+	pool->subnet_mask = get_ip(subnet_mask_24);
+	pool->start_ip = get_ip(block + start);
+	pool->end_ip = get_ip(block + start + range);
+
+	allocated_blocks = g_slist_prepend(allocated_blocks, info);
+	g_hash_table_insert(pool_hash, pool, pool);
+
+	return pool;
+}
+
+const char *__connman_ippool_get_gateway(struct connman_ippool *pool)
+{
+	return pool->gateway;
+}
+
+const char *__connman_ippool_get_broadcast(struct connman_ippool *pool)
+{
+	return pool->broadcast;
+}
+
+const char *__connman_ippool_get_start_ip(struct connman_ippool *pool)
+{
+	return pool->start_ip;
+}
+
+const char *__connman_ippool_get_end_ip(struct connman_ippool *pool)
+{
+	return pool->end_ip;
+}
+
+const char *__connman_ippool_get_subnet_mask(struct connman_ippool *pool)
+{
+	return pool->subnet_mask;
+}
+
+static void pool_free(gpointer data)
+{
+	struct connman_ippool *pool = data;
+
+	if (pool->info) {
+		allocated_blocks = g_slist_remove(allocated_blocks, pool->info);
+		g_free(pool->info);
+	}
+
+	g_free(pool->gateway);
+	g_free(pool->broadcast);
+	g_free(pool->start_ip);
+	g_free(pool->end_ip);
+	g_free(pool->subnet_mask);
+
+	g_free(pool);
+}
+
+int __connman_ippool_init(void)
+{
+	DBG("");
+
+	block_16_bits = ntohl(inet_addr("192.168.0.0"));
+	block_20_bits = ntohl(inet_addr("172.16.0.0"));
+	block_24_bits = ntohl(inet_addr("10.0.0.0"));
+	subnet_mask_24 = ntohl(inet_addr("255.255.255.0"));
+
+	pool_hash = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL,
+					pool_free);
+
+	return 0;
+}
+
+void __connman_ippool_cleanup(void)
+{
+	DBG("");
+
+	g_hash_table_destroy(pool_hash);
+	pool_hash = NULL;
+
+	g_slist_free_full(allocated_blocks, g_free);
+	last_block = 0;
+	allocated_blocks = NULL;
+}
diff --git a/connman/src/iptables.c b/connman/src/iptables.c
new file mode 100644
index 0000000..2602dfd
--- /dev/null
+++ b/connman/src/iptables.c
@@ -0,0 +1,2449 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2013  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 <getopt.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/errno.h>
+#include <sys/socket.h>
+#include <xtables.h>
+#include <inttypes.h>
+
+#include <linux/netfilter_ipv4/ip_tables.h>
+
+#include "connman.h"
+#include "src/shared/util.h"
+
+/*
+ * Some comments on how the iptables API works (some of them from the
+ * source code from iptables and the kernel):
+ *
+ * - valid_hooks: bit indicates valid IDs for hook_entry
+ * - hook_entry[ID] offset to the chain start
+ * - overflows should be end of entry chains, and uncodintional policy nodes.
+ * - policy entry: last entry in a chain
+ * - user chain: end of last builtin + policy entry
+ * - final entry must be error node
+ * - Underflows must be unconditional and use the STANDARD target with
+ *   ACCEPT/DROP
+ * - IPT_SO_GET_INFO and IPT_SO_GET_ENTRIES are used to read a table
+ * - IPT_SO_GET_INFO: struct ipt_getinfo (note the lack of table content)
+ * - IPT_SO_GET_ENTRIES: struct ipt_get_entries (contains only parts of the
+ *   table header/meta info. The table is appended after the header. The entries
+ *   are of the type struct ipt_entry.
+ * - After the ipt_entry the matches are appended. After the matches
+ *   the target is appended.
+ * - ipt_entry->target_offset =  Size of ipt_entry + matches
+ * - ipt_entry->next_offset =  Size of ipt_entry + matches + target
+ * - IPT_SO_SET_REPLACE is used to write a table (contains the complete
+ * - hook_entry and overflow mark the begining and the end of a chain, e.g
+ *     entry hook: pre/in/fwd/out/post -1/0/352/504/-1
+ *     underflow:  pre/in/fwd/out/post -1/200/352/904/-1
+ *   means that INPUT starts at offset 0 and ends at 200 (the start offset to
+ *   the last element). FORWARD has one entry starting/ending at 352. The entry
+ *   has a size of 152. 352 + 152 = 504 which is the start of the OUTPUT chain
+ *   which then ends at 904. PREROUTING and POSTROUTING are invalid hooks in
+ *   the filter table.
+ * - 'iptables -t filter -A INPUT -m mark --mark 999 -j LOG'
+ *   writing that table looks like this:
+ *
+ *   filter valid_hooks 0x0000000e  num_entries 5  size 856
+ *   entry hook: pre/in/fwd/out/post -1/0/376/528/-1
+ *   underflow:  pre/in/fwd/out/post -1/224/376/528/-1
+ *   entry 0x699d30  offset 0  size 224
+ *     RULE  match 0x699da0  target 0x699dd0
+ *             match  mark match 0x3e7
+ *             target  LOG flags 0 level 4
+ *             src 0.0.0.0/0.0.0.0
+ *             dst 0.0.0.0/0.0.0.0
+ *   entry 0x699e10  offset 224  size 152
+ *     RULE  match 0x699e80  target 0x699e80
+ *             target ACCEPT
+ *             src 0.0.0.0/0.0.0.0
+ *             dst 0.0.0.0/0.0.0.0
+ *   entry 0x699ea8  offset 376  size 152
+ *     RULE  match 0x699f18  target 0x699f18
+ *             target ACCEPT
+ *             src 0.0.0.0/0.0.0.0
+ *             dst 0.0.0.0/0.0.0.0
+ *   entry 0x699f40  offset 528  size 152
+ *     RULE  match 0x699fb0  target 0x699fb0
+ *             target ACCEPT
+ *             src 0.0.0.0/0.0.0.0
+ *             dst 0.0.0.0/0.0.0.0
+ *   entry 0x699fd8  offset 680  size 176
+ *     USER CHAIN (ERROR)  match 0x69a048  target 0x69a048
+ *
+ *   Reading the filter table looks like this:
+ *
+ *   filter valid_hooks 0x0000000e  num_entries 5  size 856
+ *   entry hook: pre/in/fwd/out/post -1/0/376/528/-1
+ *   underflow:  pre/in/fwd/out/post -1/224/376/528/-1
+ *   entry 0x25fec28  offset 0  size 224
+ *     CHAIN (INPUT)  match 0x25fec98  target 0x25fecc8
+ *             match  mark match 0x3e7
+ *             target  LOG flags 0 level 4
+ *             src 0.0.0.0/0.0.0.0
+ *             dst 0.0.0.0/0.0.0.0
+ *   entry 0x25fed08  offset 224  size 152
+ *     RULE  match 0x25fed78  target 0x25fed78
+ *             target ACCEPT
+ *             src 0.0.0.0/0.0.0.0
+ *             dst 0.0.0.0/0.0.0.0
+ *   entry 0x25feda0  offset 376  size 152
+ *     CHAIN (FORWARD)  match 0x25fee10  target 0x25fee10
+ *             target ACCEPT
+ *             src 0.0.0.0/0.0.0.0
+ *             dst 0.0.0.0/0.0.0.0
+ *   entry 0x25fee38  offset 528  size 152
+ *     CHAIN (OUTPUT)  match 0x25feea8  target 0x25feea8
+ *             target ACCEPT
+ *             src 0.0.0.0/0.0.0.0
+ *             dst 0.0.0.0/0.0.0.0
+ *   entry 0x25feed0  offset 680  size 176
+ *     End of CHAIN
+ */
+
+static const char *hooknames[] = {
+	[NF_IP_PRE_ROUTING]	= "PREROUTING",
+	[NF_IP_LOCAL_IN]	= "INPUT",
+	[NF_IP_FORWARD]		= "FORWARD",
+	[NF_IP_LOCAL_OUT]	= "OUTPUT",
+	[NF_IP_POST_ROUTING]	= "POSTROUTING",
+};
+
+#define LABEL_ACCEPT  "ACCEPT"
+#define LABEL_DROP    "DROP"
+#define LABEL_QUEUE   "QUEUE"
+#define LABEL_RETURN  "RETURN"
+
+#define XT_OPTION_OFFSET_SCALE 256
+
+#define MIN_ALIGN (__alignof__(struct ipt_entry))
+
+#define ALIGN(s) (((s) + ((MIN_ALIGN)-1)) & ~((MIN_ALIGN)-1))
+
+struct error_target {
+	struct xt_entry_target t;
+	char error[IPT_TABLE_MAXNAMELEN];
+};
+
+struct connman_iptables_entry {
+	int offset;
+	int builtin;
+	int counter_idx;
+
+	struct ipt_entry *entry;
+};
+
+struct connman_iptables {
+	char *name;
+	int ipt_sock;
+
+	struct ipt_getinfo *info;
+	struct ipt_get_entries *blob_entries;
+
+	unsigned int num_entries;
+	unsigned int old_entries;
+	unsigned int size;
+
+	unsigned int underflow[NF_INET_NUMHOOKS];
+	unsigned int hook_entry[NF_INET_NUMHOOKS];
+
+	GList *entries;
+};
+
+static GHashTable *table_hash = NULL;
+static bool debug_enabled = false;
+
+typedef int (*iterate_entries_cb_t)(struct ipt_entry *entry, int builtin,
+					unsigned int hook, size_t size,
+					unsigned int offset, void *user_data);
+
+static unsigned int next_hook_entry_index(unsigned int *valid_hooks)
+{
+	unsigned int h;
+
+	if (*valid_hooks == 0)
+		return NF_INET_NUMHOOKS;
+
+	h = __builtin_ffs(*valid_hooks) - 1;
+	*valid_hooks ^= (1 << h);
+
+	return h;
+}
+
+static int iterate_entries(struct ipt_entry *entries,
+				unsigned int valid_hooks,
+				unsigned int *hook_entry,
+				unsigned int *underflow,
+				size_t size, iterate_entries_cb_t cb,
+				void *user_data)
+{
+	unsigned int offset, h, hook;
+	int builtin, err;
+	struct ipt_entry *entry;
+
+	h = next_hook_entry_index(&valid_hooks);
+	hook = h;
+
+	for (offset = 0, entry = entries; offset < size;
+			offset += entry->next_offset) {
+		builtin = -1;
+		entry = (void *)entries + offset;
+
+		/*
+		 * Updating builtin, hook and h is very tricky.
+		 * The rules are:
+		 * - builtin is only set to the current hook number
+		 *   if the current entry is the hook entry (aka chain
+		 *   head). And only for builtin chains, never for
+		 *   the user chains.
+		 * - hook is the current hook number. If we
+		 *   look at user chains it needs to be NF_INET_NETNUMHOOKS.
+		 * - h is the next hook entry. Thous we need to be carefully
+		 *   not to access the table when h is NF_INET_NETNUMHOOKS.
+		 */
+		if (h < NF_INET_NUMHOOKS && hook_entry[h] == offset) {
+			builtin = h;
+			hook = h;
+		}
+
+		if (h == NF_INET_NUMHOOKS)
+			hook = h;
+
+		if (h < NF_INET_NUMHOOKS && underflow[h] <= offset)
+			h = next_hook_entry_index(&valid_hooks);
+
+		err = cb(entry, builtin, hook, size, offset, user_data);
+		if (err < 0)
+			return err;
+	}
+
+	return 0;
+}
+
+static int print_entry(struct ipt_entry *entry, int builtin, unsigned int hook,
+					size_t size, unsigned int offset,
+					void *user_data)
+{
+	iterate_entries_cb_t cb = user_data;
+
+	DBG("entry %p  hook %u  offset %u  size %u  packets %"PRIu64"  bytes %"PRIu64,
+			entry, hook, offset, (unsigned int) entry->next_offset,
+			(uint64_t) entry->counters.pcnt, (uint64_t) entry->counters.bcnt);
+
+	return cb(entry, builtin, hook, size, offset, NULL);
+}
+
+static int target_to_verdict(const char *target_name)
+{
+	if (!g_strcmp0(target_name, LABEL_ACCEPT))
+		return -NF_ACCEPT - 1;
+
+	if (!g_strcmp0(target_name, LABEL_DROP))
+		return -NF_DROP - 1;
+
+	if (!g_strcmp0(target_name, LABEL_QUEUE))
+		return -NF_QUEUE - 1;
+
+	if (!g_strcmp0(target_name, LABEL_RETURN))
+		return XT_RETURN;
+
+	return 0;
+}
+
+static bool is_builtin_target(const char *target_name)
+{
+	if (!g_strcmp0(target_name, LABEL_ACCEPT) ||
+		!g_strcmp0(target_name, LABEL_DROP) ||
+		!g_strcmp0(target_name, LABEL_QUEUE) ||
+		!g_strcmp0(target_name, LABEL_RETURN))
+		return true;
+
+	return false;
+}
+
+static bool is_jump(struct connman_iptables_entry *e)
+{
+	struct xt_entry_target *target;
+
+	target = ipt_get_target(e->entry);
+
+	if (!g_strcmp0(target->u.user.name, IPT_STANDARD_TARGET)) {
+		struct xt_standard_target *t;
+
+		t = (struct xt_standard_target *)target;
+
+		switch (t->verdict) {
+		case XT_RETURN:
+		case -NF_ACCEPT - 1:
+		case -NF_DROP - 1:
+		case -NF_QUEUE - 1:
+		case -NF_STOP - 1:
+			return false;
+
+		default:
+			return true;
+		}
+	}
+
+	return false;
+}
+
+static bool is_fallthrough(struct connman_iptables_entry *e)
+{
+	struct xt_entry_target *target;
+
+	target = ipt_get_target(e->entry);
+	if (!g_strcmp0(target->u.user.name, IPT_STANDARD_TARGET)) {
+		struct xt_standard_target *t;
+
+		t = (struct xt_standard_target *)target;
+		if (t->verdict == 0)
+			return true;
+	}
+	return false;
+}
+
+static bool is_chain(struct connman_iptables *table,
+				struct connman_iptables_entry *e)
+{
+	struct ipt_entry *entry;
+	struct xt_entry_target *target;
+
+	entry = e->entry;
+	if (e->builtin >= 0)
+		return true;
+
+	target = ipt_get_target(entry);
+	if (!g_strcmp0(target->u.user.name, IPT_ERROR_TARGET))
+		return true;
+
+	return false;
+}
+
+static GList *find_chain_head(struct connman_iptables *table,
+				const char *chain_name)
+{
+	GList *list;
+	struct connman_iptables_entry *head;
+	struct ipt_entry *entry;
+	struct xt_entry_target *target;
+	int builtin;
+
+	for (list = table->entries; list; list = list->next) {
+		head = list->data;
+		entry = head->entry;
+
+		/* Buit-in chain */
+		builtin = head->builtin;
+		if (builtin >= 0 && !g_strcmp0(hooknames[builtin], chain_name))
+			break;
+
+		/* User defined chain */
+		target = ipt_get_target(entry);
+		if (!g_strcmp0(target->u.user.name, IPT_ERROR_TARGET) &&
+		    !g_strcmp0((char *)target->data, chain_name))
+			break;
+	}
+
+	return list;
+}
+
+static GList *find_chain_tail(struct connman_iptables *table,
+				const char *chain_name)
+{
+	struct connman_iptables_entry *tail;
+	GList *chain_head, *list;
+
+	chain_head = find_chain_head(table, chain_name);
+	if (!chain_head)
+		return NULL;
+
+	/* Then we look for the next chain */
+	for (list = chain_head->next; list; list = list->next) {
+		tail = list->data;
+
+		if (is_chain(table, tail))
+			return list;
+	}
+
+	/* Nothing found, we return the table end */
+	return g_list_last(table->entries);
+}
+
+
+static void update_offsets(struct connman_iptables *table)
+{
+	GList *list, *prev;
+	struct connman_iptables_entry *entry, *prev_entry;
+
+	for (list = table->entries; list; list = list->next) {
+		entry = list->data;
+
+		if (list == table->entries) {
+			entry->offset = 0;
+
+			continue;
+		}
+
+		prev = list->prev;
+		prev_entry = prev->data;
+
+		entry->offset = prev_entry->offset +
+					prev_entry->entry->next_offset;
+	}
+}
+
+static void update_targets_reference(struct connman_iptables *table,
+				struct connman_iptables_entry *entry_before,
+				struct connman_iptables_entry *modified_entry,
+				bool is_removing)
+{
+	struct connman_iptables_entry *tmp;
+	struct xt_standard_target *t;
+	GList *list;
+	int offset;
+
+	offset = modified_entry->entry->next_offset;
+
+	for (list = table->entries; list; list = list->next) {
+		tmp = list->data;
+
+		if (!is_jump(tmp))
+			continue;
+
+		t = (struct xt_standard_target *)ipt_get_target(tmp->entry);
+
+		if (is_removing) {
+			if (t->verdict >= entry_before->offset)
+				t->verdict -= offset;
+		} else {
+			if (t->verdict > entry_before->offset)
+				t->verdict += offset;
+		}
+	}
+
+	if (is_fallthrough(modified_entry)) {
+		t = (struct xt_standard_target *)
+			ipt_get_target(modified_entry->entry);
+
+		t->verdict = entry_before->offset +
+			modified_entry->entry->target_offset +
+			ALIGN(sizeof(struct xt_standard_target));
+		t->target.u.target_size =
+			ALIGN(sizeof(struct xt_standard_target));
+	}
+}
+
+static int iptables_add_entry(struct connman_iptables *table,
+				struct ipt_entry *entry, GList *before,
+					int builtin, int counter_idx)
+{
+	struct connman_iptables_entry *e, *entry_before;
+
+	if (!table)
+		return -1;
+
+	e = g_try_malloc0(sizeof(struct connman_iptables_entry));
+	if (!e)
+		return -1;
+
+	e->entry = entry;
+	e->builtin = builtin;
+	e->counter_idx = counter_idx;
+
+	table->entries = g_list_insert_before(table->entries, before, e);
+	table->num_entries++;
+	table->size += entry->next_offset;
+
+	if (!before) {
+		e->offset = table->size - entry->next_offset;
+
+		return 0;
+	}
+
+	entry_before = before->data;
+
+	/*
+	 * We've just appended/insterted a new entry. All references
+	 * should be bumped accordingly.
+	 */
+	update_targets_reference(table, entry_before, e, false);
+
+	update_offsets(table);
+
+	return 0;
+}
+
+static int remove_table_entry(struct connman_iptables *table,
+				struct connman_iptables_entry *entry)
+{
+	int removed = 0;
+
+	table->num_entries--;
+	table->size -= entry->entry->next_offset;
+	removed = entry->entry->next_offset;
+
+	table->entries = g_list_remove(table->entries, entry);
+
+	g_free(entry->entry);
+	g_free(entry);
+
+	return removed;
+}
+
+static void delete_update_hooks(struct connman_iptables *table,
+				int builtin, GList *chain_head,
+				int removed)
+{
+	struct connman_iptables_entry *e;
+	GList *list;
+
+	e = chain_head->data;
+	e->builtin = builtin;
+
+	table->underflow[builtin] -= removed;
+
+	for (list = chain_head->next; list; list = list->next) {
+		e = list->data;
+
+		if (e->builtin < 0)
+			continue;
+
+		table->hook_entry[e->builtin] -= removed;
+		table->underflow[e->builtin] -= removed;
+	}
+}
+
+static int iptables_flush_chain(struct connman_iptables *table,
+						const char *name)
+{
+	GList *chain_head, *chain_tail, *list, *next;
+	struct connman_iptables_entry *entry;
+	int builtin, removed = 0;
+
+	DBG("table %s chain %s", table->name, name);
+
+	chain_head = find_chain_head(table, name);
+	if (!chain_head)
+		return -EINVAL;
+
+	chain_tail = find_chain_tail(table, name);
+	if (!chain_tail)
+		return -EINVAL;
+
+	entry = chain_head->data;
+	builtin = entry->builtin;
+
+	if (builtin >= 0)
+		list = chain_head;
+	else
+		list = chain_head->next;
+
+	if (list == chain_tail->prev)
+		return 0;
+
+	while (list != chain_tail->prev) {
+		entry = list->data;
+		next = g_list_next(list);
+
+		removed += remove_table_entry(table, entry);
+
+		list = next;
+	}
+
+	if (builtin >= 0)
+		delete_update_hooks(table, builtin, chain_tail->prev, removed);
+
+	update_offsets(table);
+
+	return 0;
+}
+
+static int iptables_add_chain(struct connman_iptables *table,
+				const char *name)
+{
+	GList *last;
+	struct ipt_entry *entry_head;
+	struct ipt_entry *entry_return;
+	struct error_target *error;
+	struct ipt_standard_target *standard;
+	u_int16_t entry_head_size, entry_return_size;
+
+	DBG("table %s chain %s", table->name, name);
+
+	last = g_list_last(table->entries);
+
+	/*
+	 * An empty chain is composed of:
+	 * - A head entry, with no match and an error target.
+	 *   The error target data is the chain name.
+	 * - A tail entry, with no match and a standard target.
+	 *   The standard target verdict is XT_RETURN (return to the
+	 *   caller).
+	 */
+
+	/* head entry */
+	entry_head_size = ALIGN(sizeof(struct ipt_entry)) +
+			ALIGN(sizeof(struct error_target));
+	entry_head = g_try_malloc0(entry_head_size);
+	if (!entry_head)
+		goto err_head;
+
+	entry_head->target_offset = ALIGN(sizeof(struct ipt_entry));
+	entry_head->next_offset = entry_head_size;
+
+	error = (struct error_target *) entry_head->elems;
+	g_stpcpy(error->t.u.user.name, IPT_ERROR_TARGET);
+	error->t.u.user.target_size = ALIGN(sizeof(struct error_target));
+	g_stpcpy(error->error, name);
+
+	if (iptables_add_entry(table, entry_head, last, -1, -1) < 0)
+		goto err_head;
+
+	/* tail entry */
+	entry_return_size = ALIGN(sizeof(struct ipt_entry))+
+			ALIGN(sizeof(struct ipt_standard_target));
+	entry_return = g_try_malloc0(entry_return_size);
+	if (!entry_return)
+		goto err;
+
+	entry_return->target_offset = ALIGN(sizeof(struct ipt_entry));
+	entry_return->next_offset = entry_return_size;
+
+	standard = (struct ipt_standard_target *) entry_return->elems;
+	standard->target.u.user.target_size =
+				ALIGN(sizeof(struct ipt_standard_target));
+	standard->verdict = XT_RETURN;
+
+	if (iptables_add_entry(table, entry_return, last, -1, -1) < 0)
+		goto err;
+
+	return 0;
+
+err:
+	g_free(entry_return);
+err_head:
+	g_free(entry_head);
+
+	return -ENOMEM;
+}
+
+static int iptables_delete_chain(struct connman_iptables *table,
+					const char *name)
+{
+	struct connman_iptables_entry *entry;
+	GList *chain_head, *chain_tail;
+
+	DBG("table %s chain %s", table->name, name);
+
+	chain_head = find_chain_head(table, name);
+	if (!chain_head)
+		return -EINVAL;
+
+	entry = chain_head->data;
+
+	/* We cannot remove builtin chain */
+	if (entry->builtin >= 0)
+		return -EINVAL;
+
+	chain_tail = find_chain_tail(table, name);
+	if (!chain_tail)
+		return -EINVAL;
+
+	/* Chain must be flushed */
+	if (chain_head->next != chain_tail->prev)
+		return -EINVAL;
+
+	remove_table_entry(table, entry);
+
+	entry = chain_tail->prev->data;
+	remove_table_entry(table, entry);
+
+	update_offsets(table);
+
+	return 0;
+}
+
+static struct ipt_entry *new_rule(struct ipt_ip *ip,
+		const char *target_name, struct xtables_target *xt_t,
+		struct xtables_rule_match *xt_rm)
+{
+	struct xtables_rule_match *tmp_xt_rm;
+	struct ipt_entry *new_entry;
+	size_t match_size, target_size;
+
+	match_size = 0;
+	for (tmp_xt_rm = xt_rm; tmp_xt_rm; tmp_xt_rm = tmp_xt_rm->next)
+		match_size += tmp_xt_rm->match->m->u.match_size;
+
+	if (xt_t)
+		target_size = xt_t->t->u.target_size;
+	else
+		target_size = ALIGN(sizeof(struct xt_standard_target));
+
+	new_entry = g_try_malloc0(ALIGN(sizeof(struct ipt_entry)) +
+				target_size + match_size);
+	if (!new_entry)
+		return NULL;
+
+	memcpy(&new_entry->ip, ip, sizeof(struct ipt_ip));
+
+	new_entry->target_offset = ALIGN(sizeof(struct ipt_entry)) +
+							match_size;
+	new_entry->next_offset = ALIGN(sizeof(struct ipt_entry)) +
+					target_size + match_size;
+
+	match_size = 0;
+	for (tmp_xt_rm = xt_rm; tmp_xt_rm;
+				tmp_xt_rm = tmp_xt_rm->next) {
+		memcpy(new_entry->elems + match_size, tmp_xt_rm->match->m,
+					tmp_xt_rm->match->m->u.match_size);
+		match_size += tmp_xt_rm->match->m->u.match_size;
+	}
+
+	if (xt_t) {
+		struct xt_entry_target *entry_target;
+
+		entry_target = ipt_get_target(new_entry);
+		memcpy(entry_target, xt_t->t, target_size);
+	}
+
+	return new_entry;
+}
+
+static void update_hooks(struct connman_iptables *table, GList *chain_head,
+				struct ipt_entry *entry)
+{
+	GList *list;
+	struct connman_iptables_entry *head, *e;
+	int builtin;
+
+	if (!chain_head)
+		return;
+
+	head = chain_head->data;
+
+	builtin = head->builtin;
+	if (builtin < 0)
+		return;
+
+	table->underflow[builtin] += entry->next_offset;
+
+	for (list = chain_head->next; list; list = list->next) {
+		e = list->data;
+
+		builtin = e->builtin;
+		if (builtin < 0)
+			continue;
+
+		table->hook_entry[builtin] += entry->next_offset;
+		table->underflow[builtin] += entry->next_offset;
+	}
+}
+
+static struct ipt_entry *prepare_rule_inclusion(struct connman_iptables *table,
+				struct ipt_ip *ip, const char *chain_name,
+				const char *target_name,
+				struct xtables_target *xt_t,
+				int *builtin, struct xtables_rule_match *xt_rm,
+				bool insert)
+{
+	GList *chain_tail, *chain_head;
+	struct ipt_entry *new_entry;
+	struct connman_iptables_entry *head;
+
+	chain_head = find_chain_head(table, chain_name);
+	if (!chain_head)
+		return NULL;
+
+	chain_tail = find_chain_tail(table, chain_name);
+	if (!chain_tail)
+		return NULL;
+
+	new_entry = new_rule(ip, target_name, xt_t, xt_rm);
+	if (!new_entry)
+		return NULL;
+
+	update_hooks(table, chain_head, new_entry);
+
+	/*
+	 * If the chain is builtin, and does not have any rule,
+	 * then the one that we're inserting is becoming the head
+	 * and thus needs the builtin flag.
+	 */
+	head = chain_head->data;
+	if (head->builtin < 0)
+		*builtin = -1;
+	else if (insert || chain_head == chain_tail->prev) {
+		*builtin = head->builtin;
+		head->builtin = -1;
+	}
+
+	return new_entry;
+}
+
+static int iptables_append_rule(struct connman_iptables *table,
+				struct ipt_ip *ip, const char *chain_name,
+				const char *target_name,
+				struct xtables_target *xt_t,
+				struct xtables_rule_match *xt_rm)
+{
+	struct ipt_entry *new_entry;
+	int builtin = -1, ret;
+	GList *chain_tail;
+
+	DBG("table %s chain %s", table->name, chain_name);
+
+	chain_tail = find_chain_tail(table, chain_name);
+	if (!chain_tail)
+		return -EINVAL;
+
+	new_entry = prepare_rule_inclusion(table, ip, chain_name,
+				target_name, xt_t, &builtin, xt_rm, false);
+	if (!new_entry)
+		return -EINVAL;
+
+	ret = iptables_add_entry(table, new_entry, chain_tail->prev, builtin, -1);
+	if (ret < 0)
+		g_free(new_entry);
+
+	return ret;
+}
+
+static int iptables_insert_rule(struct connman_iptables *table,
+				struct ipt_ip *ip, const char *chain_name,
+				const char *target_name,
+				struct xtables_target *xt_t,
+				struct xtables_rule_match *xt_rm)
+{
+	struct ipt_entry *new_entry;
+	int builtin = -1, ret;
+	GList *chain_head;
+
+	DBG("table %s chain %s", table->name, chain_name);
+
+	chain_head = find_chain_head(table, chain_name);
+	if (!chain_head)
+		return -EINVAL;
+
+	new_entry = prepare_rule_inclusion(table, ip, chain_name,
+				target_name, xt_t, &builtin, xt_rm, true);
+	if (!new_entry)
+		return -EINVAL;
+
+	if (builtin == -1)
+		chain_head = chain_head->next;
+
+	ret = iptables_add_entry(table, new_entry, chain_head, builtin, -1);
+	if (ret < 0)
+		g_free(new_entry);
+
+	return ret;
+}
+
+static bool is_same_ipt_entry(struct ipt_entry *i_e1,
+					struct ipt_entry *i_e2)
+{
+	if (memcmp(&i_e1->ip, &i_e2->ip, sizeof(struct ipt_ip)) != 0)
+		return false;
+
+	if (i_e1->target_offset != i_e2->target_offset)
+		return false;
+
+	if (i_e1->next_offset != i_e2->next_offset)
+		return false;
+
+	return true;
+}
+
+static bool is_same_target(struct xt_entry_target *xt_e_t1,
+					struct xt_entry_target *xt_e_t2)
+{
+	unsigned int i;
+
+	if (!xt_e_t1 || !xt_e_t2)
+		return false;
+
+	if (g_strcmp0(xt_e_t1->u.user.name, "") == 0 &&
+			g_strcmp0(xt_e_t2->u.user.name, "") == 0) {
+		/* fallthrough */
+		return true;
+	} else if (g_strcmp0(xt_e_t1->u.user.name, IPT_STANDARD_TARGET) == 0) {
+		struct xt_standard_target *xt_s_t1;
+		struct xt_standard_target *xt_s_t2;
+
+		xt_s_t1 = (struct xt_standard_target *) xt_e_t1;
+		xt_s_t2 = (struct xt_standard_target *) xt_e_t2;
+
+		if (xt_s_t1->verdict != xt_s_t2->verdict)
+			return false;
+	} else {
+		if (xt_e_t1->u.target_size != xt_e_t2->u.target_size)
+			return false;
+
+		if (g_strcmp0(xt_e_t1->u.user.name, xt_e_t2->u.user.name) != 0)
+			return false;
+
+		for (i = 0; i < xt_e_t1->u.target_size -
+				sizeof(struct xt_standard_target); i++) {
+			if ((xt_e_t1->data[i] ^ xt_e_t2->data[i]) != 0)
+				return false;
+		}
+	}
+
+	return true;
+}
+
+static bool is_same_match(struct xt_entry_match *xt_e_m1,
+				struct xt_entry_match *xt_e_m2)
+{
+	unsigned int i;
+
+	if (!xt_e_m1 || !xt_e_m2)
+		return false;
+
+	if (xt_e_m1->u.match_size != xt_e_m2->u.match_size)
+		return false;
+
+	if (xt_e_m1->u.user.revision != xt_e_m2->u.user.revision)
+		return false;
+
+	if (g_strcmp0(xt_e_m1->u.user.name, xt_e_m2->u.user.name) != 0)
+		return false;
+
+	for (i = 0; i < xt_e_m1->u.match_size - sizeof(struct xt_entry_match);
+			i++) {
+		if ((xt_e_m1->data[i] ^ xt_e_m2->data[i]) != 0)
+			return false;
+	}
+
+	return true;
+}
+
+static GList *find_existing_rule(struct connman_iptables *table,
+				struct ipt_ip *ip, const char *chain_name,
+				const char *target_name,
+				struct xtables_target *xt_t,
+				GList *matches,
+				struct xtables_rule_match *xt_rm)
+{
+	GList *chain_tail, *chain_head, *list;
+	struct xt_entry_target *xt_e_t = NULL;
+	struct xt_entry_match *xt_e_m = NULL;
+	struct connman_iptables_entry *entry;
+	struct ipt_entry *entry_test;
+	int builtin;
+
+	chain_head = find_chain_head(table, chain_name);
+	if (!chain_head)
+		return NULL;
+
+	chain_tail = find_chain_tail(table, chain_name);
+	if (!chain_tail)
+		return NULL;
+
+	if (!xt_t && !matches)
+		return NULL;
+
+	entry_test = new_rule(ip, target_name, xt_t, xt_rm);
+	if (!entry_test)
+		return NULL;
+
+	if (xt_t)
+		xt_e_t = ipt_get_target(entry_test);
+	if (matches)
+		xt_e_m = (struct xt_entry_match *)entry_test->elems;
+
+	entry = chain_head->data;
+	builtin = entry->builtin;
+
+	if (builtin >= 0)
+		list = chain_head;
+	else
+		list = chain_head->next;
+
+	for (; list != chain_tail->prev; list = list->next) {
+		struct connman_iptables_entry *tmp;
+		struct ipt_entry *tmp_e;
+
+		tmp = list->data;
+		tmp_e = tmp->entry;
+
+		if (!is_same_ipt_entry(entry_test, tmp_e))
+			continue;
+
+		if (xt_t) {
+			struct xt_entry_target *tmp_xt_e_t;
+
+			tmp_xt_e_t = ipt_get_target(tmp_e);
+
+			if (!is_same_target(tmp_xt_e_t, xt_e_t))
+				continue;
+		}
+
+		if (matches) {
+			struct xt_entry_match *tmp_xt_e_m;
+
+			tmp_xt_e_m = (struct xt_entry_match *)tmp_e->elems;
+
+			if (!is_same_match(tmp_xt_e_m, xt_e_m))
+				continue;
+		}
+
+		break;
+	}
+
+	g_free(entry_test);
+
+	if (list != chain_tail->prev)
+		return list;
+
+	return NULL;
+}
+
+static int iptables_delete_rule(struct connman_iptables *table,
+				struct ipt_ip *ip, const char *chain_name,
+				const char *target_name,
+				struct xtables_target *xt_t,
+				GList *matches,
+				struct xtables_rule_match *xt_rm)
+{
+	struct connman_iptables_entry *entry;
+	GList *chain_head, *chain_tail, *list;
+	int builtin, removed;
+
+
+	DBG("table %s chain %s", table->name, chain_name);
+
+	removed = 0;
+
+	chain_head = find_chain_head(table, chain_name);
+	if (!chain_head)
+		return -EINVAL;
+
+	chain_tail = find_chain_tail(table, chain_name);
+	if (!chain_tail)
+		return -EINVAL;
+
+	list = find_existing_rule(table, ip, chain_name, target_name,
+							xt_t, matches, xt_rm);
+	if (!list)
+		return -EINVAL;
+
+	entry = chain_head->data;
+	builtin = entry->builtin;
+
+	if (builtin >= 0 && list == chain_head) {
+		/*
+		 * We are about to remove the first rule in the
+		 * chain. In this case we need to store the builtin
+		 * value to the new chain_head.
+		 *
+		 * Note, for builtin chains, chain_head->next is
+		 * always valid. A builtin chain has always a policy
+		 * rule at the end.
+		 */
+		chain_head = chain_head->next;
+
+		entry = chain_head->data;
+		entry->builtin = builtin;
+	}
+
+	entry = list->data;
+	if (!entry)
+		return -EINVAL;
+
+	/* We have deleted a rule,
+	 * all references should be bumped accordingly */
+	if (list->next)
+		update_targets_reference(table, list->next->data,
+						list->data, true);
+
+	removed += remove_table_entry(table, entry);
+
+	if (builtin >= 0)
+		delete_update_hooks(table, builtin, chain_head, removed);
+
+	update_offsets(table);
+
+	return 0;
+}
+
+static int iptables_change_policy(struct connman_iptables *table,
+				const char *chain_name, const char *policy)
+{
+	GList *chain_head, *chain_tail;
+	struct connman_iptables_entry *entry;
+	struct xt_entry_target *target;
+	struct xt_standard_target *t;
+	int verdict;
+
+	DBG("table %s chain %s policy %s", table->name, chain_name, policy);
+
+	verdict = target_to_verdict(policy);
+	switch (verdict) {
+	case -NF_ACCEPT - 1:
+	case -NF_DROP - 1:
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	chain_head = find_chain_head(table, chain_name);
+	if (!chain_head)
+		return -EINVAL;
+
+	entry = chain_head->data;
+	if (entry->builtin < 0)
+		return -EINVAL;
+
+	chain_tail = find_chain_tail(table, chain_name);
+	if (!chain_tail)
+		return -EINVAL;
+
+	entry = chain_tail->prev->data;
+	target = ipt_get_target(entry->entry);
+
+	t = (struct xt_standard_target *)target;
+	if (t->verdict != verdict)
+		entry->counter_idx = -1;
+	t->verdict = verdict;
+
+	return 0;
+}
+
+static struct ipt_replace *iptables_blob(struct connman_iptables *table)
+{
+	struct ipt_replace *r;
+	GList *list;
+	struct connman_iptables_entry *e;
+	unsigned char *entry_index;
+
+	r = g_try_malloc0(sizeof(struct ipt_replace) + table->size);
+	if (!r)
+		return NULL;
+
+	memset(r, 0, sizeof(*r) + table->size);
+
+	r->counters = g_try_malloc0(sizeof(struct xt_counters)
+				* table->old_entries);
+	if (!r->counters) {
+		g_free(r);
+		return NULL;
+	}
+
+	g_stpcpy(r->name, table->info->name);
+	r->num_entries = table->num_entries;
+	r->size = table->size;
+
+	r->num_counters = table->old_entries;
+	r->valid_hooks  = table->info->valid_hooks;
+
+	memcpy(r->hook_entry, table->hook_entry, sizeof(table->hook_entry));
+	memcpy(r->underflow, table->underflow, sizeof(table->underflow));
+
+	entry_index = (unsigned char *)r->entries;
+	for (list = table->entries; list; list = list->next) {
+		e = list->data;
+
+		memcpy(entry_index, e->entry, e->entry->next_offset);
+		entry_index += e->entry->next_offset;
+	}
+
+	return r;
+}
+
+static void dump_ip(struct ipt_entry *entry)
+{
+	struct ipt_ip *ip = &entry->ip;
+	char ip_string[INET6_ADDRSTRLEN];
+	char ip_mask[INET6_ADDRSTRLEN];
+
+	if (strlen(ip->iniface))
+		DBG("\tin %s", ip->iniface);
+
+	if (strlen(ip->outiface))
+		DBG("\tout %s", ip->outiface);
+
+	if (inet_ntop(AF_INET, &ip->src, ip_string, INET6_ADDRSTRLEN) &&
+			inet_ntop(AF_INET, &ip->smsk, ip_mask,
+				INET6_ADDRSTRLEN))
+		DBG("\tsrc %s/%s", ip_string, ip_mask);
+
+	if (inet_ntop(AF_INET, &ip->dst, ip_string, INET6_ADDRSTRLEN) &&
+			inet_ntop(AF_INET, &ip->dmsk, ip_mask,
+				INET6_ADDRSTRLEN))
+		DBG("\tdst %s/%s", ip_string, ip_mask);
+}
+
+static void dump_target(struct ipt_entry *entry)
+
+{
+	struct xtables_target *xt_t;
+	struct xt_entry_target *target;
+
+	target = ipt_get_target(entry);
+
+	if (!g_strcmp0(target->u.user.name, IPT_STANDARD_TARGET)) {
+		struct xt_standard_target *t;
+
+		t = (struct xt_standard_target *)target;
+
+		switch (t->verdict) {
+		case XT_RETURN:
+			DBG("\ttarget RETURN");
+			break;
+
+		case -NF_ACCEPT - 1:
+			DBG("\ttarget ACCEPT");
+			break;
+
+		case -NF_DROP - 1:
+			DBG("\ttarget DROP");
+			break;
+
+		case -NF_QUEUE - 1:
+			DBG("\ttarget QUEUE");
+			break;
+
+		case -NF_STOP - 1:
+			DBG("\ttarget STOP");
+			break;
+
+		default:
+			DBG("\tJUMP %u", t->verdict);
+			break;
+		}
+
+		xt_t = xtables_find_target(IPT_STANDARD_TARGET,
+						XTF_LOAD_MUST_SUCCEED);
+
+		if (xt_t->print)
+			xt_t->print(NULL, target, 1);
+	} else {
+		xt_t = xtables_find_target(target->u.user.name, XTF_TRY_LOAD);
+		if (!xt_t) {
+			DBG("\ttarget %s", target->u.user.name);
+			return;
+		}
+
+		if (xt_t->print) {
+			DBG("\ttarget ");
+			xt_t->print(NULL, target, 1);
+		}
+	}
+
+	if (xt_t == xt_t->next)
+		free(xt_t);
+}
+
+static void dump_match(struct ipt_entry *entry)
+{
+	struct xtables_match *xt_m;
+	struct xt_entry_match *match;
+
+	if (entry->elems == (unsigned char *)entry + entry->target_offset)
+		return;
+
+	match = (struct xt_entry_match *) entry->elems;
+
+	if (!strlen(match->u.user.name))
+		return;
+
+	xt_m = xtables_find_match(match->u.user.name, XTF_TRY_LOAD, NULL);
+	if (!xt_m)
+		goto out;
+
+	if (xt_m->print) {
+		DBG("\tmatch ");
+		xt_m->print(NULL, match, 1);
+
+		return;
+	}
+	if (xt_m == xt_m->next)
+		free(xt_m);
+
+out:
+	DBG("\tmatch %s", match->u.user.name);
+
+}
+
+static int dump_entry(struct ipt_entry *entry, int builtin,
+			unsigned int hook, size_t size, unsigned int offset,
+			void *user_data)
+{
+	struct xt_entry_target *target;
+
+	target = ipt_get_target(entry);
+
+	if (offset + entry->next_offset == size) {
+		DBG("\tEnd of CHAIN");
+		return 0;
+	}
+
+	if (!g_strcmp0(target->u.user.name, IPT_ERROR_TARGET)) {
+		DBG("\tUSER CHAIN (%s) match %p  target %p",
+			target->data, entry->elems,
+			(char *)entry + entry->target_offset);
+
+		return 0;
+	} else if (builtin >= 0) {
+		DBG("\tCHAIN (%s) match %p  target %p",
+			hooknames[builtin], entry->elems,
+			(char *)entry + entry->target_offset);
+	} else {
+		DBG("\tRULE  match %p  target %p",
+			entry->elems,
+			(char *)entry + entry->target_offset);
+	}
+
+	dump_match(entry);
+	dump_target(entry);
+	dump_ip(entry);
+
+	return 0;
+}
+
+static void dump_table(struct connman_iptables *table)
+{
+	DBG("%s valid_hooks=0x%08x, num_entries=%u, size=%u",
+			table->info->name,
+			table->info->valid_hooks, table->info->num_entries,
+				table->info->size);
+
+	DBG("entry hook: pre/in/fwd/out/post %d/%d/%d/%d/%d",
+		table->info->hook_entry[NF_IP_PRE_ROUTING],
+		table->info->hook_entry[NF_IP_LOCAL_IN],
+		table->info->hook_entry[NF_IP_FORWARD],
+		table->info->hook_entry[NF_IP_LOCAL_OUT],
+		table->info->hook_entry[NF_IP_POST_ROUTING]);
+	DBG("underflow:  pre/in/fwd/out/post %d/%d/%d/%d/%d",
+		table->info->underflow[NF_IP_PRE_ROUTING],
+		table->info->underflow[NF_IP_LOCAL_IN],
+		table->info->underflow[NF_IP_FORWARD],
+		table->info->underflow[NF_IP_LOCAL_OUT],
+		table->info->underflow[NF_IP_POST_ROUTING]);
+
+	iterate_entries(table->blob_entries->entrytable,
+			table->info->valid_hooks,
+			table->info->hook_entry,
+			table->info->underflow,
+			table->blob_entries->size,
+			print_entry, dump_entry);
+}
+
+static void dump_ipt_replace(struct ipt_replace *repl)
+{
+	DBG("%s valid_hooks 0x%08x  num_entries %u  size %u",
+			repl->name, repl->valid_hooks, repl->num_entries,
+			repl->size);
+
+	DBG("entry hook: pre/in/fwd/out/post %d/%d/%d/%d/%d",
+		repl->hook_entry[NF_IP_PRE_ROUTING],
+		repl->hook_entry[NF_IP_LOCAL_IN],
+		repl->hook_entry[NF_IP_FORWARD],
+		repl->hook_entry[NF_IP_LOCAL_OUT],
+		repl->hook_entry[NF_IP_POST_ROUTING]);
+	DBG("underflow:  pre/in/fwd/out/post %d/%d/%d/%d/%d",
+		repl->underflow[NF_IP_PRE_ROUTING],
+		repl->underflow[NF_IP_LOCAL_IN],
+		repl->underflow[NF_IP_FORWARD],
+		repl->underflow[NF_IP_LOCAL_OUT],
+		repl->underflow[NF_IP_POST_ROUTING]);
+
+	iterate_entries(repl->entries, repl->valid_hooks,
+			repl->hook_entry, repl->underflow,
+			repl->size, print_entry, dump_entry);
+}
+
+static int iptables_get_entries(struct connman_iptables *table)
+{
+	socklen_t entry_size;
+	int err;
+
+	entry_size = sizeof(struct ipt_get_entries) + table->info->size;
+
+	err = getsockopt(table->ipt_sock, IPPROTO_IP, IPT_SO_GET_ENTRIES,
+				table->blob_entries, &entry_size);
+	if (err < 0)
+		return -errno;
+
+	return 0;
+}
+
+static int iptables_replace(struct connman_iptables *table,
+					struct ipt_replace *r)
+{
+	int err;
+
+	err = setsockopt(table->ipt_sock, IPPROTO_IP, IPT_SO_SET_REPLACE, r,
+			sizeof(*r) + r->size);
+	if (err < 0)
+		return -errno;
+
+	return 0;
+}
+
+static int iptables_add_counters(struct connman_iptables *table,
+		struct xt_counters_info *c)
+{
+	int err;
+
+	err = setsockopt(table->ipt_sock, IPPROTO_IP, IPT_SO_SET_ADD_COUNTERS, c,
+			sizeof(*c) + sizeof(struct xt_counters) * c->num_counters);
+	if (err < 0)
+		return -errno;
+
+	return 0;
+}
+
+static int add_entry(struct ipt_entry *entry, int builtin, unsigned int hook,
+			size_t size, unsigned offset, void *user_data)
+{
+	struct connman_iptables *table = user_data;
+	struct ipt_entry *new_entry;
+
+	new_entry = g_try_malloc0(entry->next_offset);
+	if (!new_entry)
+		return -ENOMEM;
+
+	memcpy(new_entry, entry, entry->next_offset);
+
+	return iptables_add_entry(table, new_entry, NULL, builtin,
+			table->num_entries);
+}
+
+static void table_cleanup(struct connman_iptables *table)
+{
+	GList *list;
+	struct connman_iptables_entry *entry;
+
+	if (!table)
+		return;
+
+	if (table->ipt_sock >= 0)
+		close(table->ipt_sock);
+
+	for (list = table->entries; list; list = list->next) {
+		entry = list->data;
+
+		g_free(entry->entry);
+		g_free(entry);
+	}
+
+	g_list_free(table->entries);
+	g_free(table->name);
+	g_free(table->info);
+	g_free(table->blob_entries);
+	g_free(table);
+}
+
+static struct connman_iptables *iptables_init(const char *table_name)
+{
+	struct connman_iptables *table = NULL;
+	char *module = NULL;
+	socklen_t s;
+
+	DBG("%s", table_name);
+
+	if (xtables_insmod("ip_tables", NULL, TRUE) != 0)
+		DBG("ip_tables module loading gives error but trying anyway");
+
+	module = g_strconcat("iptable_", table_name, NULL);
+	if (!module)
+		return NULL;
+
+	if (xtables_insmod(module, NULL, TRUE) != 0)
+		DBG("%s module loading gives error but trying anyway", module);
+
+	g_free(module);
+
+	table = g_try_new0(struct connman_iptables, 1);
+	if (!table)
+		return NULL;
+
+	table->info = g_try_new0(struct ipt_getinfo, 1);
+	if (!table->info)
+		goto err;
+
+	table->ipt_sock = socket(AF_INET, SOCK_RAW | SOCK_CLOEXEC, IPPROTO_RAW);
+	if (table->ipt_sock < 0)
+		goto err;
+
+	s = sizeof(*table->info);
+	g_stpcpy(table->info->name, table_name);
+	if (getsockopt(table->ipt_sock, IPPROTO_IP, IPT_SO_GET_INFO,
+						table->info, &s) < 0) {
+		connman_error("iptables support missing error %d (%s)", errno,
+			strerror(errno));
+		goto err;
+	}
+
+	table->blob_entries = g_try_malloc0(sizeof(struct ipt_get_entries) +
+						table->info->size);
+	if (!table->blob_entries)
+		goto err;
+
+	g_stpcpy(table->blob_entries->name, table_name);
+	table->blob_entries->size = table->info->size;
+
+	if (iptables_get_entries(table) < 0)
+		goto err;
+
+	table->num_entries = 0;
+	table->old_entries = table->info->num_entries;
+	table->size = 0;
+
+	memcpy(table->underflow, table->info->underflow,
+				sizeof(table->info->underflow));
+	memcpy(table->hook_entry, table->info->hook_entry,
+				sizeof(table->info->hook_entry));
+
+	iterate_entries(table->blob_entries->entrytable,
+			table->info->valid_hooks, table->info->hook_entry,
+			table->info->underflow, table->blob_entries->size,
+			add_entry, table);
+
+	if (debug_enabled)
+		dump_table(table);
+
+	return table;
+
+err:
+	table_cleanup(table);
+
+	return NULL;
+}
+
+static struct option iptables_opts[] = {
+	{.name = "append",        .has_arg = 1, .val = 'A'},
+	{.name = "compare",       .has_arg = 1, .val = 'C'},
+	{.name = "delete",        .has_arg = 1, .val = 'D'},
+	{.name = "flush-chain",   .has_arg = 1, .val = 'F'},
+	{.name = "insert",        .has_arg = 1, .val = 'I'},
+	{.name = "list",          .has_arg = 2, .val = 'L'},
+	{.name = "new-chain",     .has_arg = 1, .val = 'N'},
+	{.name = "policy",        .has_arg = 1, .val = 'P'},
+	{.name = "delete-chain",  .has_arg = 1, .val = 'X'},
+	{.name = "destination",   .has_arg = 1, .val = 'd'},
+	{.name = "in-interface",  .has_arg = 1, .val = 'i'},
+	{.name = "jump",          .has_arg = 1, .val = 'j'},
+	{.name = "match",         .has_arg = 1, .val = 'm'},
+	{.name = "out-interface", .has_arg = 1, .val = 'o'},
+	{.name = "source",        .has_arg = 1, .val = 's'},
+	{.name = "table",         .has_arg = 1, .val = 't'},
+	{NULL},
+};
+
+struct xtables_globals iptables_globals = {
+	.option_offset = 0,
+	.opts = iptables_opts,
+	.orig_opts = iptables_opts,
+};
+
+static struct xtables_target *prepare_target(struct connman_iptables *table,
+							const char *target_name)
+{
+	struct xtables_target *xt_t = NULL;
+	bool is_builtin, is_user_defined;
+	GList *chain_head = NULL;
+	size_t target_size;
+
+	is_builtin = false;
+	is_user_defined = false;
+
+	if (is_builtin_target(target_name))
+		is_builtin = true;
+	else {
+		chain_head = find_chain_head(table, target_name);
+		if (chain_head && chain_head->next)
+			is_user_defined = true;
+	}
+
+	if (is_builtin || is_user_defined)
+		xt_t = xtables_find_target(IPT_STANDARD_TARGET,
+						XTF_LOAD_MUST_SUCCEED);
+	else
+		xt_t = xtables_find_target(target_name, XTF_TRY_LOAD);
+
+	if (!xt_t)
+		return NULL;
+
+	target_size = ALIGN(sizeof(struct ipt_entry_target)) + xt_t->size;
+
+	xt_t->t = g_try_malloc0(target_size);
+	if (!xt_t->t)
+		return NULL;
+
+	xt_t->t->u.target_size = target_size;
+
+	if (is_builtin || is_user_defined) {
+		struct xt_standard_target *target;
+
+		target = (struct xt_standard_target *)(xt_t->t);
+		g_stpcpy(target->target.u.user.name, IPT_STANDARD_TARGET);
+
+		if (is_builtin)
+			target->verdict = target_to_verdict(target_name);
+		else if (is_user_defined) {
+			struct connman_iptables_entry *target_rule;
+
+			target_rule = chain_head->next->data;
+			target->verdict = target_rule->offset;
+		}
+	} else {
+		g_stpcpy(xt_t->t->u.user.name, target_name);
+		xt_t->t->u.user.revision = xt_t->revision;
+		if (xt_t->init)
+			xt_t->init(xt_t->t);
+	}
+
+	if (xt_t->x6_options)
+		iptables_globals.opts =
+			xtables_options_xfrm(
+				iptables_globals.orig_opts,
+				iptables_globals.opts,
+				xt_t->x6_options,
+				&xt_t->option_offset);
+	else
+		iptables_globals.opts =
+			xtables_merge_options(
+				iptables_globals.orig_opts,
+				iptables_globals.opts,
+				xt_t->extra_opts,
+				&xt_t->option_offset);
+
+	if (!iptables_globals.opts) {
+		g_free(xt_t->t);
+		xt_t = NULL;
+	}
+
+	return xt_t;
+}
+
+static struct xtables_match *prepare_matches(struct connman_iptables *table,
+					struct xtables_rule_match **xt_rm,
+					const char *match_name)
+{
+	struct xtables_match *xt_m;
+	size_t match_size;
+
+	if (!match_name)
+		return NULL;
+
+	xt_m = xtables_find_match(match_name, XTF_LOAD_MUST_SUCCEED, xt_rm);
+	match_size = ALIGN(sizeof(struct ipt_entry_match)) + xt_m->size;
+
+	xt_m->m = g_try_malloc0(match_size);
+	if (!xt_m->m)
+		return NULL;
+
+	xt_m->m->u.match_size = match_size;
+	g_stpcpy(xt_m->m->u.user.name, xt_m->name);
+	xt_m->m->u.user.revision = xt_m->revision;
+
+	if (xt_m->init)
+		xt_m->init(xt_m->m);
+
+	if (xt_m->x6_options)
+		iptables_globals.opts =
+			xtables_options_xfrm(
+				iptables_globals.orig_opts,
+				iptables_globals.opts,
+				xt_m->x6_options,
+				&xt_m->option_offset);
+	else
+			iptables_globals.opts =
+			xtables_merge_options(
+				iptables_globals.orig_opts,
+				iptables_globals.opts,
+				xt_m->extra_opts,
+				&xt_m->option_offset);
+
+	if (!iptables_globals.opts) {
+		g_free(xt_m->m);
+
+		if (xt_m == xt_m->next)
+			free(xt_m);
+
+		xt_m = NULL;
+	}
+
+	return xt_m;
+}
+
+static int parse_ip_and_mask(const char *str, struct in_addr *ip,
+				struct in_addr *mask)
+{
+	char **tokens;
+	uint32_t prefixlength;
+	uint32_t tmp;
+	int err;
+
+	tokens = g_strsplit(str, "/", 2);
+	if (!tokens)
+		return -1;
+
+	if (!inet_pton(AF_INET, tokens[0], ip)) {
+		err = -1;
+		goto out;
+	}
+
+	if (tokens[1]) {
+		prefixlength = strtol(tokens[1], NULL, 10);
+		if (prefixlength > 31) {
+			err = -1;
+			goto out;
+		}
+
+		tmp = ~(0xffffffff >> prefixlength);
+	} else {
+		tmp = 0xffffffff;
+	}
+
+	mask->s_addr = htonl(tmp);
+	ip->s_addr = ip->s_addr & mask->s_addr;
+	err = 0;
+out:
+	g_strfreev(tokens);
+
+	return err;
+}
+
+static struct connman_iptables *get_table(const char *table_name)
+{
+	struct connman_iptables *table;
+
+	if (!table_name)
+		table_name = "filter";
+
+	table = g_hash_table_lookup(table_hash, table_name);
+	if (table)
+		return table;
+
+	table = iptables_init(table_name);
+	if (!table)
+		return NULL;
+
+	table->name = g_strdup(table_name);
+	g_hash_table_replace(table_hash, table->name, table);
+
+	return table;
+}
+
+struct parse_context {
+	int argc;
+	char **argv;
+	struct ipt_ip *ip;
+	struct xtables_target *xt_t;
+	GList *xt_m;
+	struct xtables_rule_match *xt_rm;
+};
+
+static int prepare_getopt_args(const char *str, struct parse_context *ctx)
+{
+	char **tokens;
+	int i;
+
+	tokens = g_strsplit_set(str, " ", -1);
+
+	i = g_strv_length(tokens);
+
+	/* Add space for the argv[0] value */
+	ctx->argc = i + 1;
+
+	/* Don't forget the last NULL entry */
+	ctx->argv = g_try_malloc0((ctx->argc + 1) * sizeof(char *));
+	if (!ctx->argv) {
+		g_strfreev(tokens);
+		return -ENOMEM;
+	}
+
+	/*
+	 * getopt_long() jumps over the first token; we need to add some
+	 * random argv[0] entry.
+	 */
+	ctx->argv[0] = g_strdup("argh");
+	for (i = 1; i < ctx->argc; i++)
+		ctx->argv[i] = tokens[i - 1];
+
+	g_free(tokens);
+
+	return 0;
+}
+
+static int parse_xt_modules(int c, bool invert,
+				struct parse_context *ctx)
+{
+	struct xtables_match *m;
+	struct xtables_rule_match *rm;
+
+	for (rm = ctx->xt_rm; rm; rm = rm->next) {
+		if (rm->completed != 0)
+			continue;
+
+		m = rm->match;
+
+		if (!m->x6_parse && !m->parse)
+			continue;
+
+		if (c < (int) m->option_offset ||
+				c >= (int) m->option_offset
+					+ XT_OPTION_OFFSET_SCALE)
+			continue;
+
+		xtables_option_mpcall(c, ctx->argv, invert, m, NULL);
+	}
+
+	if (!ctx->xt_t)
+		return 0;
+
+	if (!ctx->xt_t->x6_parse && !ctx->xt_t->parse)
+		return 0;
+
+	if (c < (int) ctx->xt_t->option_offset ||
+			c >= (int) ctx->xt_t->option_offset
+					+ XT_OPTION_OFFSET_SCALE)
+		return 0;
+
+	xtables_option_tpcall(c, ctx->argv, invert, ctx->xt_t, NULL);
+
+	return 0;
+}
+
+static int final_check_xt_modules(struct parse_context *ctx)
+{
+	struct xtables_rule_match *rm;
+
+	for (rm = ctx->xt_rm; rm; rm = rm->next)
+		xtables_option_mfcall(rm->match);
+
+	if (ctx->xt_t)
+		xtables_option_tfcall(ctx->xt_t);
+
+	return 0;
+}
+
+static int parse_rule_spec(struct connman_iptables *table,
+				struct parse_context *ctx)
+{
+	/*
+	 * How the parser works:
+	 *
+	 *  - If getopt finds 's', 'd', 'i', 'o'.
+	 *    just extract the information.
+	 *  - if '!' is found, set the invert flag to true and
+	 *    removes the '!' from the optarg string and jumps
+	 *    back to getopt to reparse the current optarg string.
+	 *    After reparsing the invert flag is reseted to false.
+	 *  - If 'm' or 'j' is found then call either
+	 *    prepare_matches() or prepare_target(). Those function
+	 *    will modify (extend) the longopts for getopt_long.
+	 *    That means getopt will change its matching context according
+	 *    the loaded target.
+	 *
+	 *    Here an example with iptables-test
+	 *
+	 *    argv[0] = ./tools/iptables-test
+	 *    argv[1] = -t
+	 *    argv[2] = filter
+	 *    argv[3] = -A
+	 *    argv[4] = INPUT
+	 *    argv[5] = -m
+	 *    argv[6] = mark
+	 *    argv[7] = --mark
+	 *    argv[8] = 999
+	 *    argv[9] = -j
+	 *    argv[10] = LOG
+	 *
+	 *    getopt found 'm' then the optarg is "mark" and optind 7
+	 *    The longopts array containts before hitting the `case 'm'`
+	 *
+	 *    val A has_arg 1 name append
+	 *    val C has_arg 1 name compare
+	 *    val D has_arg 1 name delete
+	 *    val F has_arg 1 name flush-chain
+	 *    val I has_arg 1 name insert
+	 *    val L has_arg 2 name list
+	 *    val N has_arg 1 name new-chain
+	 *    val P has_arg 1 name policy
+	 *    val X has_arg 1 name delete-chain
+	 *    val d has_arg 1 name destination
+	 *    val i has_arg 1 name in-interface
+	 *    val j has_arg 1 name jump
+	 *    val m has_arg 1 name match
+	 *    val o has_arg 1 name out-interface
+	 *    val s has_arg 1 name source
+	 *    val t has_arg 1 name table
+	 *
+	 *    After executing the `case 'm'` block longopts is
+	 *
+	 *    val A has_arg 1 name append
+	 *    val C has_arg 1 name compare
+	 *    val D has_arg 1 name delete
+	 *    val F has_arg 1 name flush-chain
+	 *    val I has_arg 1 name insert
+	 *    val L has_arg 2 name list
+	 *    val N has_arg 1 name new-chain
+	 *    val P has_arg 1 name policy
+	 *    val X has_arg 1 name delete-chain
+	 *    val d has_arg 1 name destination
+	 *    val i has_arg 1 name in-interface
+	 *    val j has_arg 1 name jump
+	 *    val m has_arg 1 name match
+	 *    val o has_arg 1 name out-interface
+	 *    val s has_arg 1 name source
+	 *    val t has_arg 1 name table
+	 *    val   has_arg 1 name mark
+	 *
+	 *    So the 'mark' matcher has added the 'mark' options
+	 *    and getopt will then return c '256' optarg "999" optind 9
+	 *    And we will hit the 'default' statement which then
+	 *    will call the matchers parser (xt_m->parser() or
+	 *    xtables_option_mpcall() depending on which version
+	 *    of libxtables is found.
+	 */
+	struct xtables_match *xt_m;
+	bool invert = false;
+	int len, c, err;
+
+	ctx->ip = g_try_new0(struct ipt_ip, 1);
+	if (!ctx->ip)
+		return -ENOMEM;
+
+	/*
+	 * Tell getopt_long not to generate error messages for unknown
+	 * options and also reset optind back to 0.
+	 */
+	opterr = 0;
+	optind = 0;
+
+	while ((c = getopt_long(ctx->argc, ctx->argv,
+					"-:d:i:o:s:m:j:",
+					iptables_globals.opts, NULL)) != -1) {
+		switch (c) {
+		case 's':
+			/* Source specification */
+			if (!parse_ip_and_mask(optarg,
+						&ctx->ip->src,
+						&ctx->ip->smsk))
+				break;
+
+			if (invert)
+				ctx->ip->invflags |= IPT_INV_SRCIP;
+
+			break;
+		case 'd':
+			/* Destination specification */
+			if (!parse_ip_and_mask(optarg,
+						&ctx->ip->dst,
+						&ctx->ip->dmsk))
+				break;
+
+			if (invert)
+				ctx->ip->invflags |= IPT_INV_DSTIP;
+			break;
+		case 'i':
+			/* In interface specification */
+			len = strlen(optarg);
+
+			if (len + 1 > IFNAMSIZ)
+				break;
+
+			g_stpcpy(ctx->ip->iniface, optarg);
+			memset(ctx->ip->iniface_mask, 0xff, len + 1);
+
+			if (invert)
+				ctx->ip->invflags |= IPT_INV_VIA_IN;
+
+			break;
+		case 'o':
+			/* Out interface specification */
+			len = strlen(optarg);
+
+			if (len + 1 > IFNAMSIZ)
+				break;
+
+			g_stpcpy(ctx->ip->outiface, optarg);
+			memset(ctx->ip->outiface_mask, 0xff, len + 1);
+
+			if (invert)
+				ctx->ip->invflags |= IPT_INV_VIA_OUT;
+
+			break;
+		case 'm':
+			/* Matches */
+			xt_m = prepare_matches(table, &ctx->xt_rm, optarg);
+			if (!xt_m) {
+				err = -EINVAL;
+				goto out;
+			}
+			ctx->xt_m = g_list_append(ctx->xt_m, xt_m);
+
+			break;
+		case 'j':
+			/* Target */
+			ctx->xt_t = prepare_target(table, optarg);
+			if (!ctx->xt_t) {
+				err = -EINVAL;
+				goto out;
+			}
+
+			break;
+		case 1:
+			if (optarg[0] == '!' && optarg[1] == '\0') {
+				invert = true;
+
+				/* Remove the '!' from the optarg */
+				optarg[0] = '\0';
+
+				/*
+				 * And recall getopt_long without reseting
+				 * invert.
+				 */
+				continue;
+			}
+
+			break;
+		default:
+			err = parse_xt_modules(c, invert, ctx);
+			if (err == 1)
+				continue;
+
+			break;
+		}
+
+		invert = false;
+	}
+
+	err = final_check_xt_modules(ctx);
+
+out:
+	return err;
+}
+
+static void reset_xtables(void)
+{
+	struct xtables_match *xt_m;
+	struct xtables_target *xt_t;
+
+	/*
+	 * As side effect parsing a rule sets some global flags
+	 * which will be evaluated/verified. Let's reset them
+	 * to ensure we can parse more than one rule.
+	 *
+	 * Clear all flags because the flags are only valid
+	 * for one rule.
+	 */
+	for (xt_m = xtables_matches; xt_m; xt_m = xt_m->next)
+		xt_m->mflags = 0;
+
+	for (xt_t = xtables_targets; xt_t; xt_t = xt_t->next) {
+		xt_t->tflags = 0;
+		xt_t->used = 0;
+	}
+
+	/*
+	 * We need also to free the memory implicitly allocated
+	 * during parsing (see xtables_options_xfrm()).
+	 * Note xt_params is actually iptables_globals.
+	 */
+	if (xt_params->opts != xt_params->orig_opts) {
+		g_free(xt_params->opts);
+		xt_params->opts = xt_params->orig_opts;
+	}
+	xt_params->option_offset = 0;
+}
+
+static void cleanup_parse_context(struct parse_context *ctx)
+{
+	struct xtables_rule_match *rm, *tmp;
+	GList *list;
+
+	g_strfreev(ctx->argv);
+	g_free(ctx->ip);
+	if (ctx->xt_t) {
+		g_free(ctx->xt_t->t);
+		ctx->xt_t->t = NULL;
+	}
+
+	for (list = ctx->xt_m; list; list = list->next) {
+		struct xtables_match *xt_m = list->data;
+
+		g_free(xt_m->m);
+
+		if (xt_m != xt_m->next)
+			continue;
+
+		g_free(xt_m);
+	}
+	g_list_free(ctx->xt_m);
+
+	for (tmp = NULL, rm = ctx->xt_rm; rm; rm = rm->next) {
+		if (tmp)
+			g_free(tmp);
+		tmp = rm;
+	}
+	g_free(tmp);
+
+	g_free(ctx);
+}
+
+int __connman_iptables_dump(const char *table_name)
+{
+	struct connman_iptables *table;
+
+	DBG("-t %s -L", table_name);
+
+	table = get_table(table_name);
+	if (!table)
+		return -EINVAL;
+
+	dump_table(table);
+
+	return 0;
+}
+
+int __connman_iptables_new_chain(const char *table_name,
+					const char *chain)
+{
+	struct connman_iptables *table;
+
+	DBG("-t %s -N %s", table_name, chain);
+
+	table = get_table(table_name);
+	if (!table)
+		return -EINVAL;
+
+	return iptables_add_chain(table, chain);
+}
+
+int __connman_iptables_delete_chain(const char *table_name,
+					const char *chain)
+{
+	struct connman_iptables *table;
+
+	DBG("-t %s -X %s", table_name, chain);
+
+	table = get_table(table_name);
+	if (!table)
+		return -EINVAL;
+
+	return iptables_delete_chain(table, chain);
+}
+
+int __connman_iptables_flush_chain(const char *table_name,
+					const char *chain)
+{
+	struct connman_iptables *table;
+
+	DBG("-t %s -F %s", table_name, chain);
+
+	table = get_table(table_name);
+	if (!table)
+		return -EINVAL;
+
+	return iptables_flush_chain(table, chain);
+}
+
+int __connman_iptables_change_policy(const char *table_name,
+					const char *chain,
+					const char *policy)
+{
+	struct connman_iptables *table;
+
+	DBG("-t %s -F %s", table_name, chain);
+
+	table = get_table(table_name);
+	if (!table)
+		return -EINVAL;
+
+	return iptables_change_policy(table, chain, policy);
+}
+
+int __connman_iptables_append(const char *table_name,
+				const char *chain,
+				const char *rule_spec)
+{
+	struct connman_iptables *table;
+	struct parse_context *ctx;
+	const char *target_name;
+	int err;
+
+	ctx = g_try_new0(struct parse_context, 1);
+	if (!ctx)
+		return -ENOMEM;
+
+	DBG("-t %s -A %s %s", table_name, chain, rule_spec);
+
+	err = prepare_getopt_args(rule_spec, ctx);
+	if (err < 0)
+		goto out;
+
+	table = get_table(table_name);
+	if (!table) {
+		err = -EINVAL;
+		goto out;
+	}
+
+	err = parse_rule_spec(table, ctx);
+	if (err < 0)
+		goto out;
+
+	if (!ctx->xt_t)
+		target_name = NULL;
+	else
+		target_name = ctx->xt_t->name;
+
+	err = iptables_append_rule(table, ctx->ip, chain,
+				target_name, ctx->xt_t, ctx->xt_rm);
+out:
+	cleanup_parse_context(ctx);
+	reset_xtables();
+
+	return err;
+}
+
+int __connman_iptables_insert(const char *table_name,
+				const char *chain,
+				const char *rule_spec)
+{
+	struct connman_iptables *table;
+	struct parse_context *ctx;
+	const char *target_name;
+	int err;
+
+	ctx = g_try_new0(struct parse_context, 1);
+	if (!ctx)
+		return -ENOMEM;
+
+	DBG("-t %s -I %s %s", table_name, chain, rule_spec);
+
+	err = prepare_getopt_args(rule_spec, ctx);
+	if (err < 0)
+		goto out;
+
+	table = get_table(table_name);
+	if (!table) {
+		err = -EINVAL;
+		goto out;
+	}
+
+	err = parse_rule_spec(table, ctx);
+	if (err < 0)
+		goto out;
+
+	if (!ctx->xt_t)
+		target_name = NULL;
+	else
+		target_name = ctx->xt_t->name;
+
+	err = iptables_insert_rule(table, ctx->ip, chain,
+				target_name, ctx->xt_t, ctx->xt_rm);
+out:
+	cleanup_parse_context(ctx);
+	reset_xtables();
+
+	return err;
+}
+
+int __connman_iptables_delete(const char *table_name,
+				const char *chain,
+				const char *rule_spec)
+{
+	struct connman_iptables *table;
+	struct parse_context *ctx;
+	const char *target_name;
+	int err;
+
+	ctx = g_try_new0(struct parse_context, 1);
+	if (!ctx)
+		return -ENOMEM;
+
+	DBG("-t %s -D %s %s", table_name, chain, rule_spec);
+
+	err = prepare_getopt_args(rule_spec, ctx);
+	if (err < 0)
+		goto out;
+
+	table = get_table(table_name);
+	if (!table) {
+		err = -EINVAL;
+		goto out;
+	}
+
+	err = parse_rule_spec(table, ctx);
+	if (err < 0)
+		goto out;
+
+	if (!ctx->xt_t)
+		target_name = NULL;
+	else
+		target_name = ctx->xt_t->name;
+
+	err = iptables_delete_rule(table, ctx->ip, chain,
+				target_name, ctx->xt_t, ctx->xt_m,
+				ctx->xt_rm);
+out:
+	cleanup_parse_context(ctx);
+	reset_xtables();
+
+	return err;
+}
+
+int __connman_iptables_commit(const char *table_name)
+{
+	struct connman_iptables *table;
+	struct ipt_replace *repl;
+	int err;
+	struct xt_counters_info *counters;
+	struct connman_iptables_entry *e;
+	GList *list;
+	unsigned int cnt;
+
+	DBG("%s", table_name);
+
+	table = g_hash_table_lookup(table_hash, table_name);
+	if (!table)
+		return -EINVAL;
+
+	repl = iptables_blob(table);
+	if (!repl)
+		return -ENOMEM;
+
+	if (debug_enabled)
+		dump_ipt_replace(repl);
+
+	err = iptables_replace(table, repl);
+
+	if (err < 0)
+		goto out_free;
+
+	counters = g_try_malloc0(sizeof(*counters) +
+			sizeof(struct xt_counters) * table->num_entries);
+	if (!counters) {
+		err = -ENOMEM;
+		goto out_hash_remove;
+	}
+	g_stpcpy(counters->name, table->info->name);
+	counters->num_counters = table->num_entries;
+	for (list = table->entries, cnt = 0; list; list = list->next, cnt++) {
+		e = list->data;
+		if (e->counter_idx >= 0)
+			counters->counters[cnt] = repl->counters[e->counter_idx];
+	}
+	err = iptables_add_counters(table, counters);
+	g_free(counters);
+
+	if (err < 0)
+		goto out_hash_remove;
+
+	err = 0;
+
+out_hash_remove:
+	g_hash_table_remove(table_hash, table_name);
+out_free:
+	g_free(repl->counters);
+	g_free(repl);
+	return err;
+}
+
+static void remove_table(gpointer user_data)
+{
+	struct connman_iptables *table = user_data;
+
+	table_cleanup(table);
+}
+
+static int iterate_chains_cb(struct ipt_entry *entry, int builtin,
+				unsigned int hook, size_t size,
+				unsigned int offset, void *user_data)
+{
+	struct cb_data *cbd = user_data;
+	connman_iptables_iterate_chains_cb_t cb = cbd->cb;
+	struct xt_entry_target *target;
+
+	if (offset + entry->next_offset == size)
+		return 0;
+
+	target = ipt_get_target(entry);
+
+	if (!g_strcmp0(target->u.user.name, IPT_ERROR_TARGET))
+		(*cb)((const char *)target->data, cbd->user_data);
+	else if (builtin >= 0)
+		(*cb)(hooknames[builtin], cbd->user_data);
+
+	return 0;
+}
+
+int __connman_iptables_iterate_chains(const char *table_name,
+				connman_iptables_iterate_chains_cb_t cb,
+				void *user_data)
+{
+	struct cb_data *cbd = cb_data_new(cb, user_data);
+	struct connman_iptables *table;
+
+	table = get_table(table_name);
+	if (!table)
+		return -EINVAL;
+
+	iterate_entries(table->blob_entries->entrytable,
+			table->info->valid_hooks,
+			table->info->hook_entry,
+			table->info->underflow,
+			table->blob_entries->size,
+			iterate_chains_cb, cbd);
+
+	g_free(cbd);
+
+	return 0;
+}
+
+int __connman_iptables_init(void)
+{
+	DBG("");
+
+	if (getenv("CONNMAN_IPTABLES_DEBUG"))
+		debug_enabled = true;
+
+	table_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
+						NULL, remove_table);
+
+	xtables_init_all(&iptables_globals, NFPROTO_IPV4);
+
+	return 0;
+}
+
+void __connman_iptables_cleanup(void)
+{
+	DBG("");
+
+	g_hash_table_destroy(table_hash);
+}
diff --git a/connman/src/ipv6pd.c b/connman/src/ipv6pd.c
new file mode 100644
index 0000000..0d221f0
--- /dev/null
+++ b/connman/src/ipv6pd.c
@@ -0,0 +1,385 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2013  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 <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <stdio.h>
+
+#include "connman.h"
+
+#include <gdhcp/gdhcp.h>
+
+#define DEFAULT_ROUTER_LIFETIME 180  /* secs */
+#define DEFAULT_RA_INTERVAL 120  /* secs */
+
+static int bridge_index = -1;
+static guint timer_uplink;
+static guint timer_ra;
+static char *default_interface;
+static GSList *prefixes;
+static GHashTable *timer_hash;
+static void *rs_context;
+
+static int setup_prefix_delegation(struct connman_service *service);
+static void dhcpv6_callback(struct connman_network *network,
+			enum __connman_dhcpv6_status status, gpointer data);
+
+static int enable_ipv6_forward(bool enable)
+{
+	FILE *f;
+
+	f = fopen("/proc/sys/net/ipv6/ip_forward", "r+");
+	if (!f)
+		return -errno;
+
+	if (enable)
+		fprintf(f, "1");
+	else
+		fprintf(f, "0");
+
+	fclose(f);
+
+	return 0;
+}
+
+static gboolean send_ra(gpointer data)
+{
+	__connman_inet_ipv6_send_ra(bridge_index, NULL, prefixes,
+					DEFAULT_ROUTER_LIFETIME);
+
+	return TRUE;
+}
+
+static void start_ra(int ifindex, GSList *prefix)
+{
+	if (prefixes)
+		g_slist_free_full(prefixes, g_free);
+
+	prefixes = g_dhcpv6_copy_prefixes(prefix);
+
+	enable_ipv6_forward(true);
+
+	if (timer_ra > 0)
+		g_source_remove(timer_ra);
+
+	send_ra(NULL);
+
+	timer_ra = g_timeout_add_seconds(DEFAULT_RA_INTERVAL, send_ra, NULL);
+}
+
+static void stop_ra(int ifindex)
+{
+	__connman_inet_ipv6_send_ra(ifindex, NULL, prefixes, 0);
+
+	if (timer_ra > 0) {
+		g_source_remove(timer_ra);
+		timer_ra = 0;
+	}
+
+	enable_ipv6_forward(false);
+
+	if (prefixes) {
+		g_slist_free_full(prefixes, g_free);
+		prefixes = NULL;
+	}
+}
+
+static void rs_received(struct nd_router_solicit *reply,
+			unsigned int length, void *user_data)
+{
+	GDHCPIAPrefix *prefix;
+	GSList *list;
+
+	if (!prefixes)
+		return;
+
+	DBG("");
+
+	for (list = prefixes; list; list = list->next) {
+		prefix = list->data;
+
+		prefix->valid -= time(NULL) - prefix->expire;
+		prefix->preferred -= time(NULL) - prefix->expire;
+	}
+
+	__connman_inet_ipv6_send_ra(bridge_index, NULL, prefixes,
+					DEFAULT_ROUTER_LIFETIME);
+}
+
+static gboolean do_setup(gpointer data)
+{
+	int ret;
+
+	timer_uplink = 0;
+
+	if (!default_interface)
+		DBG("No uplink connection, retrying prefix delegation");
+
+	ret = setup_prefix_delegation(__connman_service_get_default());
+	if (ret < 0 && ret != -EINPROGRESS)
+		return TRUE; /* delegation error, try again */
+
+	return FALSE;
+}
+
+static void dhcpv6_renew_callback(struct connman_network *network,
+				enum __connman_dhcpv6_status status,
+				gpointer data)
+{
+	DBG("network %p status %d data %p", network, status, data);
+
+	if (status == CONNMAN_DHCPV6_STATUS_SUCCEED)
+		dhcpv6_callback(network, status, data);
+	else
+		setup_prefix_delegation(__connman_service_get_default());
+}
+
+static void cleanup(void)
+{
+	if (timer_uplink != 0) {
+		g_source_remove(timer_uplink);
+		timer_uplink = 0;
+	}
+
+	if (timer_hash) {
+		g_hash_table_destroy(timer_hash);
+		timer_hash = NULL;
+	}
+
+	if (prefixes) {
+		g_slist_free_full(prefixes, g_free);
+		prefixes = NULL;
+	}
+}
+
+static void dhcpv6_callback(struct connman_network *network,
+			enum __connman_dhcpv6_status status, gpointer data)
+{
+	GSList *prefix_list = data;
+
+	DBG("network %p status %d data %p", network, status, data);
+
+	if (status == CONNMAN_DHCPV6_STATUS_FAIL) {
+		DBG("Prefix delegation request failed");
+		cleanup();
+		return;
+	}
+
+	if (!prefix_list) {
+		DBG("No prefixes, retrying");
+		if (timer_uplink == 0)
+			timer_uplink = g_timeout_add_seconds(10, do_setup,
+									NULL);
+		return;
+	}
+
+	/*
+	 * After we have got a list of prefixes, we can start to send router
+	 * advertisements (RA) to tethering interface.
+	 */
+	start_ra(bridge_index, prefix_list);
+
+	if (__connman_dhcpv6_start_pd_renew(network,
+					dhcpv6_renew_callback) == -ETIMEDOUT)
+		dhcpv6_renew_callback(network, CONNMAN_DHCPV6_STATUS_FAIL,
+									NULL);
+}
+
+static int setup_prefix_delegation(struct connman_service *service)
+{
+	struct connman_ipconfig *ipconfig;
+	char *interface;
+	int err = 0, ifindex;
+
+	if (!service) {
+		/*
+		 * We do not have uplink connection. We just wait until
+		 * default interface is updated.
+		 */
+		return -EINPROGRESS;
+	}
+
+	interface = connman_service_get_interface(service);
+
+	DBG("interface %s bridge_index %d", interface, bridge_index);
+
+	if (default_interface) {
+		stop_ra(bridge_index);
+
+		ifindex = connman_inet_ifindex(default_interface);
+		__connman_dhcpv6_stop_pd(ifindex);
+	}
+
+	g_free(default_interface);
+
+	ipconfig = __connman_service_get_ip6config(service);
+	if (!__connman_ipconfig_ipv6_is_enabled(ipconfig)) {
+		g_free(interface);
+		default_interface = NULL;
+		return -EPFNOSUPPORT;
+	}
+
+	default_interface = interface;
+
+	if (default_interface) {
+		ifindex = connman_inet_ifindex(default_interface);
+
+		/*
+		 * Try to get a IPv6 prefix so we can start to advertise it.
+		 */
+		err = __connman_dhcpv6_start_pd(ifindex, prefixes,
+						dhcpv6_callback);
+		if (err < 0)
+			DBG("prefix delegation %d/%s", err, strerror(-err));
+	}
+
+	return err;
+}
+
+static void cleanup_timer(gpointer user_data)
+{
+	guint timer = GPOINTER_TO_UINT(user_data);
+
+	g_source_remove(timer);
+}
+
+static void update_default_interface(struct connman_service *service)
+{
+	setup_prefix_delegation(service);
+}
+
+static void update_ipconfig(struct connman_service *service,
+				struct connman_ipconfig *ipconfig)
+{
+	if (!service || service != __connman_service_get_default())
+		return;
+
+	if (ipconfig != __connman_service_get_ip6config(service))
+		return;
+
+	if (!__connman_ipconfig_ipv6_is_enabled(ipconfig)) {
+		if (default_interface) {
+			int ifindex;
+
+			ifindex = connman_inet_ifindex(default_interface);
+			__connman_dhcpv6_stop_pd(ifindex);
+
+			g_free(default_interface);
+			default_interface = NULL;
+		}
+
+		DBG("No IPv6 support for interface index %d",
+			__connman_ipconfig_get_index(ipconfig));
+		return;
+	}
+
+	/*
+	 * Did we had PD activated already? If not, then start it.
+	 */
+	if (!default_interface) {
+		DBG("IPv6 ipconfig %p changed for interface index %d", ipconfig,
+			__connman_ipconfig_get_index(ipconfig));
+
+		setup_prefix_delegation(service);
+	}
+}
+
+static struct connman_notifier pd_notifier = {
+	.name			= "IPv6 prefix delegation",
+	.default_changed	= update_default_interface,
+	.ipconfig_changed	= update_ipconfig,
+};
+
+int __connman_ipv6pd_setup(const char *bridge)
+{
+	struct connman_service *service;
+	int err;
+
+	if (!connman_inet_is_ipv6_supported())
+		return -EPFNOSUPPORT;
+
+	if (bridge_index >= 0) {
+		DBG("Prefix delegation already running");
+		return -EALREADY;
+	}
+
+	err = connman_notifier_register(&pd_notifier);
+	if (err < 0)
+		return err;
+
+	bridge_index = connman_inet_ifindex(bridge);
+
+	timer_hash = g_hash_table_new_full(g_direct_hash, g_direct_equal,
+						NULL, cleanup_timer);
+
+	err = __connman_inet_ipv6_start_recv_rs(bridge_index, rs_received,
+						NULL, &rs_context);
+	if (err < 0)
+		DBG("Cannot receive router solicitation %d/%s",
+			err, strerror(-err));
+
+	service = __connman_service_get_default();
+	if (service) {
+		/*
+		 * We have an uplink connection already, try to use it.
+		 */
+		return setup_prefix_delegation(service);
+	}
+
+	/*
+	 * The prefix delegation is started after have got the uplink
+	 * connection up i.e., when the default service is setup in which
+	 * case the update_default_interface() will be called.
+	 */
+	return -EINPROGRESS;
+}
+
+void __connman_ipv6pd_cleanup(void)
+{
+	int ifindex;
+
+	if (!connman_inet_is_ipv6_supported())
+		return;
+
+	connman_notifier_unregister(&pd_notifier);
+
+	__connman_inet_ipv6_stop_recv_rs(rs_context);
+	rs_context = NULL;
+
+	cleanup();
+
+	stop_ra(bridge_index);
+
+	if (default_interface) {
+		ifindex = connman_inet_ifindex(default_interface);
+		__connman_dhcpv6_stop_pd(ifindex);
+		g_free(default_interface);
+		default_interface = NULL;
+	}
+
+	bridge_index = -1;
+}
diff --git a/connman/src/log.c b/connman/src/log.c
new file mode 100644
index 0000000..f81f45f
--- /dev/null
+++ b/connman/src/log.c
@@ -0,0 +1,392 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2013  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
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <unistd.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <string.h>
+#include <syslog.h>
+#include <execinfo.h>
+#include <dlfcn.h>
+
+#include "connman.h"
+
+static const char *program_exec;
+static const char *program_path;
+
+#if CONNMAN_DEBUG
+unsigned int trace_depth = 0;
+static const char * trace_tabs = "\t\t\t\t" "\t\t\t\t" "\t\t\t\t" "\t\t\t\t" "\t\t\t\t";
+char trace_tabbuf[24] = { 0 };
+
+void connman_create_indent(unsigned int depth, char *buffer)
+{
+	if (buffer == NULL)
+		return;
+
+	if (depth > 22) {
+		depth = 22;
+	}
+
+	if (depth == 0) {
+		buffer[0] = 0;
+	} else {
+		strncpy(buffer, trace_tabs, depth);
+		buffer[depth] = 0;
+	}
+}
+#endif
+
+void connman_assert_handler(const char *name, const char *predicate, const char *message, const char *file, unsigned int line, void *value, int terminate)
+{
+	connman_debug("assertion: %s%s%s, %s file: %s, line: %d: value: %p\n",
+		name != NULL ? name : "",
+		name != NULL ? ": " : "",
+		predicate,
+		message != NULL ? message : "",
+		file,
+		line,
+		value);
+
+	if (terminate) {
+		abort();
+	}
+}
+
+/**
+ * connman_info:
+ * @format: format string
+ * @Varargs: list of arguments
+ *
+ * Output general information
+ */
+void connman_info(const char *format, ...)
+{
+	va_list ap;
+
+	va_start(ap, format);
+
+	vsyslog(LOG_INFO, format, ap);
+
+	va_end(ap);
+}
+
+/**
+ * connman_warn:
+ * @format: format string
+ * @Varargs: list of arguments
+ *
+ * Output warning messages
+ */
+void connman_warn(const char *format, ...)
+{
+	va_list ap;
+
+	va_start(ap, format);
+
+	vsyslog(LOG_WARNING, format, ap);
+
+	va_end(ap);
+}
+
+/**
+ * connman_error:
+ * @format: format string
+ * @varargs: list of arguments
+ *
+ * Output error messages
+ */
+void connman_error(const char *format, ...)
+{
+	va_list ap;
+
+	va_start(ap, format);
+
+	vsyslog(LOG_ERR, format, ap);
+
+	va_end(ap);
+}
+
+/**
+ * connman_debug:
+ * @format: format string
+ * @varargs: list of arguments
+ *
+ * Output debug message
+ */
+void connman_debug(const char *format, ...)
+{
+	va_list ap;
+
+	va_start(ap, format);
+
+	vsyslog(LOG_DEBUG, format, ap);
+
+	va_end(ap);
+}
+
+static void print_backtrace(unsigned int offset)
+{
+	void *frames[99];
+	size_t n_ptrs;
+	unsigned int i;
+	int outfd[2], infd[2];
+	int pathlen;
+	pid_t pid;
+
+	if (!program_exec)
+		return;
+
+	pathlen = strlen(program_path);
+
+	n_ptrs = backtrace(frames, G_N_ELEMENTS(frames));
+	if (n_ptrs < offset)
+		return;
+
+	if (pipe(outfd) < 0)
+		return;
+
+	if (pipe(infd) < 0) {
+		close(outfd[0]);
+		close(outfd[1]);
+		return;
+	}
+
+	pid = fork();
+	if (pid < 0) {
+		close(outfd[0]);
+		close(outfd[1]);
+		close(infd[0]);
+		close(infd[1]);
+		return;
+	}
+
+	if (pid == 0) {
+		close(outfd[1]);
+		close(infd[0]);
+
+		dup2(outfd[0], STDIN_FILENO);
+		dup2(infd[1], STDOUT_FILENO);
+
+		execlp("addr2line", "-C", "-f", "-e", program_exec, NULL);
+
+		exit(EXIT_FAILURE);
+	}
+
+	close(outfd[0]);
+	close(infd[1]);
+
+	connman_error("++++++++ backtrace ++++++++");
+
+	for (i = offset; i < n_ptrs - 1; i++) {
+		Dl_info info;
+		char addr[20], buf[PATH_MAX * 2];
+		int len, written;
+		char *ptr, *pos;
+
+		dladdr(frames[i], &info);
+
+		len = snprintf(addr, sizeof(addr), "%p\n", frames[i]);
+		if (len < 0)
+			break;
+
+		if (outfd[1] >= 0)
+		{
+			written = write(outfd[1], addr, len);
+			if (written < 0)
+				break;
+
+			len = read(infd[0], buf, sizeof(buf) - 1);
+			if (len < 0)
+				break;
+			else if (len == 0)
+			{
+				// if we got nothing, that means we got EOF, which means the read end was closed
+				// so close the FD and set it to invalid so we know to not to bother with further
+				// symbolication
+				close(outfd[1]);
+				outfd[1] = -1;
+			}
+		}
+		else
+		{
+			len = 0;
+		}
+
+		buf[len] = '\0';
+
+		pos = strchr(buf, '\n');
+		if (pos != NULL)
+		{
+		    *pos++ = '\0';
+		}
+
+		if ((len == 0) || (strcmp(buf, "??") == 0)) {
+			connman_error("#%-2u %p in %s", i - offset,
+						frames[i], info.dli_fname);
+			continue;
+		}
+
+		ptr = strchr(pos, '\n');
+		*ptr++ = '\0';
+
+		if (strncmp(pos, program_path, pathlen) == 0)
+			pos += pathlen + 1;
+
+		connman_error("#%-2u %p in %s() at %s", i - offset,
+						frames[i], buf, pos);
+	}
+
+	connman_error("+++++++++++++++++++++++++++");
+
+	kill(pid, SIGTERM);
+
+	if (outfd[1] >= 0)
+	{
+		close(outfd[1]);
+	}
+	close(infd[0]);
+}
+
+static void signal_handler(int signo)
+{
+	connman_error("Aborting (signal %d) [%s]", signo, program_exec);
+
+	print_backtrace(2);
+
+	exit(EXIT_FAILURE);
+}
+
+static void signal_setup(sighandler_t handler)
+{
+	struct sigaction sa;
+	sigset_t mask;
+
+	sigemptyset(&mask);
+	sa.sa_handler = handler;
+	sa.sa_mask = mask;
+	sa.sa_flags = 0;
+	sigaction(SIGBUS, &sa, NULL);
+	sigaction(SIGILL, &sa, NULL);
+	sigaction(SIGFPE, &sa, NULL);
+	sigaction(SIGSEGV, &sa, NULL);
+	sigaction(SIGABRT, &sa, NULL);
+	sigaction(SIGPIPE, &sa, NULL);
+}
+
+extern struct connman_debug_desc __start___debug[];
+extern struct connman_debug_desc __stop___debug[];
+
+static gchar **enabled = NULL;
+
+static bool is_enabled(struct connman_debug_desc *desc)
+{
+	int i;
+
+	if (!enabled)
+		return false;
+
+	for (i = 0; enabled[i]; i++) {
+		if (desc->name && g_pattern_match_simple(enabled[i],
+							desc->name))
+			return true;
+		if (desc->file && g_pattern_match_simple(enabled[i],
+							desc->file))
+			return true;
+	}
+
+	return false;
+}
+
+void __connman_log_enable(struct connman_debug_desc *start,
+					struct connman_debug_desc *stop)
+{
+	struct connman_debug_desc *desc;
+	const char *name = NULL, *file = NULL;
+
+	if (!start || !stop)
+		return;
+
+	for (desc = start; desc < stop; desc++) {
+		if (desc->flags & CONNMAN_DEBUG_FLAG_ALIAS) {
+			file = desc->file;
+			name = desc->name;
+			continue;
+		}
+
+		if (file || name) {
+			if (g_strcmp0(desc->file, file) == 0) {
+				if (!desc->name)
+					desc->name = name;
+			} else
+				file = NULL;
+		}
+
+		if (is_enabled(desc))
+			desc->flags |= CONNMAN_DEBUG_FLAG_PRINT;
+	}
+}
+
+int __connman_log_init(const char *program, const char *debug,
+		gboolean detach, gboolean backtrace,
+		const char *program_name, const char *program_version)
+{
+	static char path[PATH_MAX];
+	int option = LOG_NDELAY | LOG_PID;
+
+	program_exec = program;
+	program_path = getcwd(path, sizeof(path));
+
+	if (debug)
+		enabled = g_strsplit_set(debug, ":, ", 0);
+
+	__connman_log_enable(__start___debug, __stop___debug);
+
+	if (!detach)
+		option |= LOG_PERROR;
+
+	if (backtrace)
+		signal_setup(signal_handler);
+
+	openlog(basename(program), option, LOG_DAEMON);
+
+	syslog(LOG_INFO, "%s version %s", program_name, program_version);
+
+	return 0;
+}
+
+void __connman_log_cleanup(gboolean backtrace)
+{
+	syslog(LOG_INFO, "Exit");
+
+	closelog();
+
+	if (backtrace)
+		signal_setup(SIG_DFL);
+
+	g_strfreev(enabled);
+}
diff --git a/connman/src/machine.c b/connman/src/machine.c
new file mode 100644
index 0000000..14ea366
--- /dev/null
+++ b/connman/src/machine.c
@@ -0,0 +1,125 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2014  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 <gdbus.h>
+
+#include "connman.h"
+
+#define DEFAULT_MACHINE_TYPE	"laptop"
+
+#define HOSTNAMED_SERVICE	"org.freedesktop.hostname1"
+#define HOSTNAMED_INTERFACE	HOSTNAMED_SERVICE
+#define HOSTNAMED_PATH		"/org/freedesktop/hostname1"
+
+static GDBusClient *hostnamed_client = NULL;
+static GDBusProxy *hostnamed_proxy = NULL;
+static char *machine_type = NULL;
+
+const char *connman_machine_get_type(void)
+{
+	if (machine_type)
+		return machine_type;
+
+	return DEFAULT_MACHINE_TYPE;
+}
+
+static void machine_property_changed(GDBusProxy *proxy, const char *name,
+					DBusMessageIter *iter, void *user_data)
+{
+	DBG("Property %s", name);
+
+	if (g_str_equal(name, "Chassis")) {
+		const char *str;
+
+		if (!iter) {
+			g_dbus_proxy_refresh_property(proxy, name);
+			return;
+		}
+
+		if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_STRING)
+			return;
+
+		dbus_message_iter_get_basic(iter, &str);
+		g_free(machine_type);
+		machine_type = g_strdup(str);
+
+		DBG("Machine type set to %s", machine_type);
+	}
+}
+
+int __connman_machine_init(void)
+{
+	DBusConnection *connection;
+	int err = -EIO;
+
+	DBG("");
+
+	connection = connman_dbus_get_connection();
+
+	hostnamed_client = g_dbus_client_new(connection, HOSTNAMED_SERVICE,
+							HOSTNAMED_PATH);
+	if (!hostnamed_client)
+		goto error;
+
+	hostnamed_proxy = g_dbus_proxy_new(hostnamed_client, HOSTNAMED_PATH,
+							HOSTNAMED_INTERFACE);
+	if (!hostnamed_proxy)
+		goto error;
+
+	g_dbus_proxy_set_property_watch(hostnamed_proxy,
+					machine_property_changed, NULL);
+
+	dbus_connection_unref(connection);
+
+	return 0;
+error:
+	if (hostnamed_client) {
+		g_dbus_client_unref(hostnamed_client);
+		hostnamed_client = NULL;
+	}
+
+	dbus_connection_unref(connection);
+
+	return err;
+}
+
+void __connman_machine_cleanup(void)
+{
+	DBG("");
+
+	if (hostnamed_proxy) {
+		g_dbus_proxy_unref(hostnamed_proxy);
+		hostnamed_proxy = NULL;
+	}
+
+	if (hostnamed_client) {
+		g_dbus_client_unref(hostnamed_client);
+		hostnamed_client = NULL;
+	}
+
+	g_free(machine_type);
+	machine_type = NULL;
+}
diff --git a/connman/src/main.c b/connman/src/main.c
new file mode 100644
index 0000000..bd80f30
--- /dev/null
+++ b/connman/src/main.c
@@ -0,0 +1,811 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2013  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 <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <signal.h>
+#include <sys/signalfd.h>
+#include <getopt.h>
+#include <sys/stat.h>
+#include <net/if.h>
+#include <netdb.h>
+
+#include <gdbus.h>
+
+#include "connman.h"
+
+#define DEFAULT_INPUT_REQUEST_TIMEOUT (120 * 1000)
+#define DEFAULT_BROWSER_LAUNCH_TIMEOUT (300 * 1000)
+
+#define MAINFILE "main.conf"
+#define CONFIGMAINFILE CONFIGDIR "/" MAINFILE
+
+static char *default_auto_connect[] = {
+	"wifi",
+	"ethernet",
+	"cellular",
+	NULL
+};
+
+static char *default_blacklist[] = {
+	"vmnet",
+	"vboxnet",
+	"virbr",
+	"ifb",
+	NULL
+};
+
+static struct {
+	bool bg_scan;
+	char **pref_timeservers;
+	unsigned int *auto_connect;
+	unsigned int *preferred_techs;
+	char **fallback_nameservers;
+	unsigned int timeout_inputreq;
+	unsigned int timeout_browserlaunch;
+	char **blacklisted_interfaces;
+	bool allow_hostname_updates;
+	bool single_tech;
+	char **tethering_technologies;
+	bool persistent_tethering_mode;
+	bool enable_6to4;
+} connman_settings  = {
+	.bg_scan = true,
+	.pref_timeservers = NULL,
+	.auto_connect = NULL,
+	.preferred_techs = NULL,
+	.fallback_nameservers = NULL,
+	.timeout_inputreq = DEFAULT_INPUT_REQUEST_TIMEOUT,
+	.timeout_browserlaunch = DEFAULT_BROWSER_LAUNCH_TIMEOUT,
+	.blacklisted_interfaces = NULL,
+	.allow_hostname_updates = true,
+	.single_tech = false,
+	.tethering_technologies = NULL,
+	.persistent_tethering_mode = false,
+	.enable_6to4 = false,
+};
+
+#define CONF_BG_SCAN                    "BackgroundScanning"
+#define CONF_PREF_TIMESERVERS           "FallbackTimeservers"
+#define CONF_AUTO_CONNECT               "DefaultAutoConnectTechnologies"
+#define CONF_PREFERRED_TECHS            "PreferredTechnologies"
+#define CONF_FALLBACK_NAMESERVERS       "FallbackNameservers"
+#define CONF_TIMEOUT_INPUTREQ           "InputRequestTimeout"
+#define CONF_TIMEOUT_BROWSERLAUNCH      "BrowserLaunchTimeout"
+#define CONF_BLACKLISTED_INTERFACES     "NetworkInterfaceBlacklist"
+#define CONF_ALLOW_HOSTNAME_UPDATES     "AllowHostnameUpdates"
+#define CONF_SINGLE_TECH                "SingleConnectedTechnology"
+#define CONF_TETHERING_TECHNOLOGIES      "TetheringTechnologies"
+#define CONF_PERSISTENT_TETHERING_MODE  "PersistentTetheringMode"
+#define CONF_ENABLE_6TO4                "Enable6to4"
+
+static const char *supported_options[] = {
+	CONF_BG_SCAN,
+	CONF_PREF_TIMESERVERS,
+	CONF_AUTO_CONNECT,
+	CONF_PREFERRED_TECHS,
+	CONF_FALLBACK_NAMESERVERS,
+	CONF_TIMEOUT_INPUTREQ,
+	CONF_TIMEOUT_BROWSERLAUNCH,
+	CONF_BLACKLISTED_INTERFACES,
+	CONF_ALLOW_HOSTNAME_UPDATES,
+	CONF_SINGLE_TECH,
+	CONF_TETHERING_TECHNOLOGIES,
+	CONF_PERSISTENT_TETHERING_MODE,
+	CONF_ENABLE_6TO4,
+	NULL
+};
+
+static GKeyFile *load_config(const char *file)
+{
+	GError *err = NULL;
+	GKeyFile *keyfile;
+
+	keyfile = g_key_file_new();
+
+	g_key_file_set_list_separator(keyfile, ',');
+
+	if (!g_key_file_load_from_file(keyfile, file, 0, &err)) {
+		if (err->code != G_FILE_ERROR_NOENT) {
+			connman_error("Parsing %s failed: %s", file,
+								err->message);
+		}
+
+		g_error_free(err);
+		g_key_file_free(keyfile);
+		return NULL;
+	}
+
+	return keyfile;
+}
+
+static uint *parse_service_types(char **str_list, gsize len)
+{
+	unsigned int *type_list;
+	int i, j;
+	enum connman_service_type type;
+
+	type_list = g_try_new0(unsigned int, len + 1);
+	if (!type_list)
+		return NULL;
+
+	i = 0;
+	j = 0;
+	while (str_list[i]) {
+		type = __connman_service_string2type(str_list[i]);
+
+		if (type != CONNMAN_SERVICE_TYPE_UNKNOWN) {
+			type_list[j] = type;
+			j += 1;
+		}
+		i += 1;
+	}
+
+	type_list[j] = CONNMAN_SERVICE_TYPE_UNKNOWN;
+
+	return type_list;
+}
+
+static char **parse_fallback_nameservers(char **nameservers, gsize len)
+{
+	char **servers;
+	int i, j;
+
+	servers = g_try_new0(char *, len + 1);
+	if (!servers)
+		return NULL;
+
+	i = 0;
+	j = 0;
+	while (nameservers[i]) {
+		if (connman_inet_check_ipaddress(nameservers[i]) > 0) {
+			servers[j] = g_strdup(nameservers[i]);
+			j += 1;
+		}
+		i += 1;
+	}
+
+	return servers;
+}
+
+static void check_config(GKeyFile *config)
+{
+	char **keys;
+	int j;
+
+	if (!config)
+		return;
+
+	keys = g_key_file_get_groups(config, NULL);
+
+	for (j = 0; keys && keys[j]; j++) {
+		if (g_strcmp0(keys[j], "General") != 0)
+			connman_warn("Unknown group %s in %s",
+						keys[j], MAINFILE);
+	}
+
+	g_strfreev(keys);
+
+	keys = g_key_file_get_keys(config, "General", NULL, NULL);
+
+	for (j = 0; keys && keys[j]; j++) {
+		bool found;
+		int i;
+
+		found = false;
+		for (i = 0; supported_options[i]; i++) {
+			if (g_strcmp0(keys[j], supported_options[i]) == 0) {
+				found = true;
+				break;
+			}
+		}
+		if (!found && !supported_options[i])
+			connman_warn("Unknown option %s in %s",
+						keys[j], MAINFILE);
+	}
+
+	g_strfreev(keys);
+}
+
+static void parse_config(GKeyFile *config)
+{
+	GError *error = NULL;
+	bool boolean;
+	char **timeservers;
+	char **interfaces;
+	char **str_list;
+	char **tethering;
+	gsize len;
+	int timeout;
+
+	if (!config) {
+		connman_settings.auto_connect =
+			parse_service_types(default_auto_connect, 3);
+		connman_settings.blacklisted_interfaces =
+			g_strdupv(default_blacklist);
+		return;
+	}
+
+	DBG("parsing %s", MAINFILE);
+
+	boolean = g_key_file_get_boolean(config, "General",
+						CONF_BG_SCAN, &error);
+	if (!error)
+		connman_settings.bg_scan = boolean;
+
+	g_clear_error(&error);
+
+	timeservers = __connman_config_get_string_list(config, "General",
+					CONF_PREF_TIMESERVERS, NULL, &error);
+	if (!error)
+		connman_settings.pref_timeservers = timeservers;
+
+	g_clear_error(&error);
+
+	str_list = __connman_config_get_string_list(config, "General",
+			CONF_AUTO_CONNECT, &len, &error);
+
+	if (!error)
+		connman_settings.auto_connect =
+			parse_service_types(str_list, len);
+	else
+		connman_settings.auto_connect =
+			parse_service_types(default_auto_connect, 3);
+
+	g_strfreev(str_list);
+
+	g_clear_error(&error);
+
+	str_list = __connman_config_get_string_list(config, "General",
+			CONF_PREFERRED_TECHS, &len, &error);
+
+	if (!error)
+		connman_settings.preferred_techs =
+			parse_service_types(str_list, len);
+
+	g_strfreev(str_list);
+
+	g_clear_error(&error);
+
+	str_list = __connman_config_get_string_list(config, "General",
+			CONF_FALLBACK_NAMESERVERS, &len, &error);
+
+	if (!error)
+		connman_settings.fallback_nameservers =
+			parse_fallback_nameservers(str_list, len);
+
+	g_strfreev(str_list);
+
+	g_clear_error(&error);
+
+	timeout = g_key_file_get_integer(config, "General",
+			CONF_TIMEOUT_INPUTREQ, &error);
+	if (!error && timeout >= 0)
+		connman_settings.timeout_inputreq = timeout * 1000;
+
+	g_clear_error(&error);
+
+	timeout = g_key_file_get_integer(config, "General",
+			CONF_TIMEOUT_BROWSERLAUNCH, &error);
+	if (!error && timeout >= 0)
+		connman_settings.timeout_browserlaunch = timeout * 1000;
+
+	g_clear_error(&error);
+
+	interfaces = __connman_config_get_string_list(config, "General",
+			CONF_BLACKLISTED_INTERFACES, &len, &error);
+
+	if (!error)
+		connman_settings.blacklisted_interfaces = interfaces;
+	else
+		connman_settings.blacklisted_interfaces =
+			g_strdupv(default_blacklist);
+
+	g_clear_error(&error);
+
+	boolean = __connman_config_get_bool(config, "General",
+					CONF_ALLOW_HOSTNAME_UPDATES,
+					&error);
+	if (!error)
+		connman_settings.allow_hostname_updates = boolean;
+
+	g_clear_error(&error);
+
+	boolean = __connman_config_get_bool(config, "General",
+			CONF_SINGLE_TECH, &error);
+	if (!error)
+		connman_settings.single_tech = boolean;
+
+	g_clear_error(&error);
+
+	tethering = __connman_config_get_string_list(config, "General",
+			CONF_TETHERING_TECHNOLOGIES, &len, &error);
+
+	if (!error)
+		connman_settings.tethering_technologies = tethering;
+
+	g_clear_error(&error);
+
+	boolean = __connman_config_get_bool(config, "General",
+					CONF_PERSISTENT_TETHERING_MODE,
+					&error);
+	if (!error)
+		connman_settings.persistent_tethering_mode = boolean;
+
+	g_clear_error(&error);
+
+	boolean = __connman_config_get_bool(config, "General",
+					CONF_ENABLE_6TO4, &error);
+	if (!error)
+		connman_settings.enable_6to4 = boolean;
+
+	g_clear_error(&error);
+}
+
+static int config_init(const char *file, bool rlimits)
+{
+	GKeyFile *config;
+	int err = 0;
+
+	config = load_config(file);
+	check_config(config);
+
+	if (rlimits) {
+		err = __connman_rlimits_init(file);
+		if (err < 0)
+			goto done;
+	}
+
+	parse_config(config);
+
+done:
+	if (config)
+		g_key_file_free(config);
+
+	return err;
+}
+
+static GMainLoop *main_loop = NULL;
+
+static unsigned int __terminated = 0;
+
+static gboolean signal_handler(GIOChannel *channel, GIOCondition cond,
+							gpointer user_data)
+{
+	struct signalfd_siginfo si;
+	ssize_t result;
+	int fd;
+
+	if (cond & (G_IO_NVAL | G_IO_ERR | G_IO_HUP))
+		return FALSE;
+
+	fd = g_io_channel_unix_get_fd(channel);
+
+	result = read(fd, &si, sizeof(si));
+	if (result != sizeof(si))
+		return FALSE;
+
+	switch (si.ssi_signo) {
+	case SIGINT:
+	case SIGTERM:
+		if (__terminated == 0) {
+			connman_info("Terminating");
+			g_main_loop_quit(main_loop);
+		}
+
+		__terminated = 1;
+		break;
+	}
+
+	return TRUE;
+}
+
+static guint setup_signalfd(void)
+{
+	GIOChannel *channel;
+	guint source;
+	sigset_t mask;
+	int fd;
+
+	sigemptyset(&mask);
+	sigaddset(&mask, SIGINT);
+	sigaddset(&mask, SIGTERM);
+
+	if (sigprocmask(SIG_BLOCK, &mask, NULL) < 0) {
+		perror("Failed to set signal mask");
+		return 0;
+	}
+
+	fd = signalfd(-1, &mask, 0);
+	if (fd < 0) {
+		perror("Failed to create signal descriptor");
+		return 0;
+	}
+
+	channel = g_io_channel_unix_new(fd);
+
+	g_io_channel_set_close_on_unref(channel, TRUE);
+	g_io_channel_set_encoding(channel, NULL, NULL);
+	g_io_channel_set_buffered(channel, FALSE);
+
+	source = g_io_add_watch(channel,
+				G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
+				signal_handler, NULL);
+
+	g_io_channel_unref(channel);
+
+	return source;
+}
+
+static void disconnect_callback(DBusConnection *conn, void *user_data)
+{
+	connman_error("D-Bus disconnect");
+
+	g_main_loop_quit(main_loop);
+}
+
+static gchar *option_config = NULL;
+static gchar *option_debug = NULL;
+static gchar *option_device = NULL;
+static gchar *option_pidfile = NULL;
+static gchar *option_plugin = NULL;
+static gchar *option_nodevice = NULL;
+static gchar *option_noplugin = NULL;
+static gchar *option_wifi = NULL;
+static gboolean option_detach = TRUE;
+static gboolean option_dnsproxy = TRUE;
+static gboolean option_backtrace = TRUE;
+static gboolean option_version = FALSE;
+static gboolean option_rlimits = TRUE;
+
+static bool parse_debug(const char *key, const char *value,
+					gpointer user_data, GError **error)
+{
+	if (value)
+		option_debug = g_strdup(value);
+	else
+		option_debug = g_strdup("*");
+
+	return true;
+}
+
+static GOptionEntry options[] = {
+	{ "config", 'c', 0, G_OPTION_ARG_STRING, &option_config,
+				"Load the specified configuration file "
+				"instead of " CONFIGMAINFILE, "FILE" },
+	{ "debug", 'd', G_OPTION_FLAG_OPTIONAL_ARG,
+				G_OPTION_ARG_CALLBACK, parse_debug,
+				"Specify debug options to enable", "DEBUG" },
+	{ "device", 'i', 0, G_OPTION_ARG_STRING, &option_device,
+			"Specify networking device or interface", "DEV" },
+	{ "nodevice", 'I', 0, G_OPTION_ARG_STRING, &option_nodevice,
+			"Specify networking interface to ignore", "DEV" },
+	{ "plugin", 'p', 0, G_OPTION_ARG_STRING, &option_plugin,
+				"Specify plugins to load", "NAME,..." },
+	{ "noplugin", 'P', 0, G_OPTION_ARG_STRING, &option_noplugin,
+				"Specify plugins not to load", "NAME,..." },
+	{ "wifi", 'W', 0, G_OPTION_ARG_STRING, &option_wifi,
+				"Specify driver for WiFi/Supplicant", "NAME" },
+	{ "nodaemon", 'n', G_OPTION_FLAG_REVERSE,
+				G_OPTION_ARG_NONE, &option_detach,
+				"Don't fork daemon to background" },
+	{ "nodnsproxy", 'r', G_OPTION_FLAG_REVERSE,
+				G_OPTION_ARG_NONE, &option_dnsproxy,
+				"Don't enable DNS Proxy" },
+	{ "nobacktrace", 0, G_OPTION_FLAG_REVERSE,
+				G_OPTION_ARG_NONE, &option_backtrace,
+				"Don't print out backtrace information" },
+	{ "norlimits", 0, G_OPTION_FLAG_REVERSE,
+				G_OPTION_ARG_NONE, &option_rlimits,
+				"Don't enforce resource limits" },
+	{ "pidfile", 0, 0, G_OPTION_ARG_STRING, &option_pidfile,
+				"Path to PID file", "PIDFILE" },
+	{ "version", 'v', 0, G_OPTION_ARG_NONE, &option_version,
+				"Show version information and exit" },
+	{ NULL },
+};
+
+const char *connman_option_get_string(const char *key)
+{
+	if (g_strcmp0(key, "wifi") == 0) {
+		if (!option_wifi)
+			return "nl80211,wext";
+		else
+			return option_wifi;
+	}
+
+	return NULL;
+}
+
+bool connman_setting_get_bool(const char *key)
+{
+	if (g_str_equal(key, CONF_BG_SCAN))
+		return connman_settings.bg_scan;
+
+	if (g_str_equal(key, CONF_ALLOW_HOSTNAME_UPDATES))
+		return connman_settings.allow_hostname_updates;
+
+	if (g_str_equal(key, CONF_SINGLE_TECH))
+		return connman_settings.single_tech;
+
+	if (g_str_equal(key, CONF_PERSISTENT_TETHERING_MODE))
+		return connman_settings.persistent_tethering_mode;
+
+	if (g_str_equal(key, CONF_ENABLE_6TO4))
+		return connman_settings.enable_6to4;
+
+	return false;
+}
+
+char **connman_setting_get_string_list(const char *key)
+{
+	if (g_str_equal(key, CONF_PREF_TIMESERVERS))
+		return connman_settings.pref_timeservers;
+
+	if (g_str_equal(key, CONF_FALLBACK_NAMESERVERS))
+		return connman_settings.fallback_nameservers;
+
+	if (g_str_equal(key, CONF_BLACKLISTED_INTERFACES))
+		return connman_settings.blacklisted_interfaces;
+
+	if (g_str_equal(key, CONF_TETHERING_TECHNOLOGIES))
+		return connman_settings.tethering_technologies;
+
+	return NULL;
+}
+
+unsigned int *connman_setting_get_uint_list(const char *key)
+{
+	if (g_str_equal(key, CONF_AUTO_CONNECT))
+		return connman_settings.auto_connect;
+
+	if (g_str_equal(key, CONF_PREFERRED_TECHS))
+		return connman_settings.preferred_techs;
+
+	return NULL;
+}
+
+unsigned int connman_timeout_input_request(void)
+{
+	return connman_settings.timeout_inputreq;
+}
+
+unsigned int connman_timeout_browser_launch(void)
+{
+	return connman_settings.timeout_browserlaunch;
+}
+
+static void connman_daemon_init(const char *pidfile)
+{
+	FILE *file;
+
+	if (daemon(0, 0)) {
+		perror("Can't start daemon");
+		exit(EXIT_FAILURE);
+	}
+
+	if (pidfile != NULL) {
+		file = fopen(pidfile, "w");
+		if (file != NULL) {
+			fprintf(file, "%u\n", getpid());
+			fclose(file);
+		}
+	}
+}
+
+static void connman_daemon_cleanup(const char *pidfile)
+{
+	if (pidfile != NULL) {
+		unlink(pidfile);
+	}
+}
+
+int main(int argc, char *argv[])
+{
+	GOptionContext *context;
+	GError *error = NULL;
+	DBusConnection *conn;
+	DBusError err;
+	guint signal;
+
+	context = g_option_context_new(NULL);
+	g_option_context_add_main_entries(context, options, NULL);
+
+	if (!g_option_context_parse(context, &argc, &argv, &error)) {
+		if (error) {
+			g_printerr("%s\n", error->message);
+			g_error_free(error);
+		} else
+			g_printerr("An unknown error occurred\n");
+		exit(1);
+	}
+
+	g_option_context_free(context);
+
+	if (option_version) {
+		printf("%s\n", VERSION);
+		exit(0);
+	}
+
+	if (option_detach) {
+		connman_daemon_init(option_pidfile);
+	}
+
+	if (mkdir(STORAGEDIR, S_IRUSR | S_IWUSR | S_IXUSR |
+				S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) < 0) {
+		if (errno != EEXIST)
+			perror("Failed to create storage directory");
+	}
+
+	umask(0077);
+
+	main_loop = g_main_loop_new(NULL, FALSE);
+
+	signal = setup_signalfd();
+
+	dbus_error_init(&err);
+
+	conn = g_dbus_setup_bus(DBUS_BUS_SYSTEM, CONNMAN_SERVICE, &err);
+	if (!conn) {
+		if (dbus_error_is_set(&err)) {
+			fprintf(stderr, "%s\n", err.message);
+			dbus_error_free(&err);
+		} else
+			fprintf(stderr, "Can't register with system bus\n");
+		exit(1);
+	}
+
+	g_dbus_set_disconnect_function(conn, disconnect_callback, NULL, NULL);
+
+	__connman_log_init(argv[0], option_debug, option_detach,
+			option_backtrace, "Connection Manager", VERSION);
+
+	__connman_dbus_init(conn);
+
+	if (!option_config)
+		config_init(CONFIGMAINFILE, option_rlimits);
+	else
+		config_init(option_config, option_rlimits);
+
+	__connman_util_init();
+	__connman_inotify_init();
+	__connman_technology_init();
+	__connman_notifier_init();
+	__connman_agent_init();
+	__connman_service_init();
+	__connman_peer_service_init();
+	__connman_peer_init();
+	__connman_provider_init();
+	__connman_network_init();
+	__connman_config_init();
+	__connman_device_init(option_device, option_nodevice);
+
+	__connman_ippool_init();
+	__connman_iptables_init();
+	__connman_firewall_init();
+	__connman_nat_init();
+	__connman_tethering_init();
+	__connman_counter_init();
+	__connman_manager_init();
+	__connman_stats_init();
+	__connman_clock_init();
+
+	__connman_ipconfig_init();
+	__connman_rtnl_init();
+	__connman_task_init();
+	__connman_proxy_init();
+	__connman_detect_init();
+	__connman_session_init();
+	__connman_timeserver_init();
+	__connman_connection_init();
+
+	__connman_plugin_init(option_plugin, option_noplugin);
+	__connman_resolver_init(option_dnsproxy);
+
+	__connman_rtnl_start();
+	__connman_dhcp_init();
+	__connman_dhcpv6_init();
+	__connman_wpad_init();
+	__connman_wispr_init();
+	__connman_rfkill_init();
+	__connman_machine_init();
+
+	g_free(option_config);
+	g_free(option_device);
+	g_free(option_plugin);
+	g_free(option_nodevice);
+	g_free(option_noplugin);
+
+	g_main_loop_run(main_loop);
+
+	g_source_remove(signal);
+
+	__connman_machine_cleanup();
+	__connman_rfkill_cleanup();
+	__connman_wispr_cleanup();
+	__connman_wpad_cleanup();
+	__connman_dhcpv6_cleanup();
+	__connman_session_cleanup();
+	__connman_plugin_cleanup();
+	__connman_provider_cleanup();
+	__connman_connection_cleanup();
+	__connman_timeserver_cleanup();
+	__connman_detect_cleanup();
+	__connman_proxy_cleanup();
+	__connman_task_cleanup();
+	__connman_rtnl_cleanup();
+	__connman_resolver_cleanup();
+
+	__connman_clock_cleanup();
+	__connman_stats_cleanup();
+	__connman_config_cleanup();
+	__connman_manager_cleanup();
+	__connman_counter_cleanup();
+	__connman_tethering_cleanup();
+	__connman_nat_cleanup();
+	__connman_firewall_cleanup();
+	__connman_iptables_cleanup();
+	__connman_peer_service_cleanup();
+	__connman_peer_cleanup();
+	__connman_ippool_cleanup();
+	__connman_device_cleanup();
+	__connman_network_cleanup();
+	__connman_dhcp_cleanup();
+	__connman_service_cleanup();
+	__connman_agent_cleanup();
+	__connman_ipconfig_cleanup();
+	__connman_notifier_cleanup();
+	__connman_technology_cleanup();
+	__connman_inotify_cleanup();
+
+	__connman_util_cleanup();
+	__connman_dbus_cleanup();
+
+	__connman_log_cleanup(option_backtrace);
+
+	dbus_connection_unref(conn);
+
+	g_main_loop_unref(main_loop);
+
+	if (connman_settings.pref_timeservers)
+		g_strfreev(connman_settings.pref_timeservers);
+
+	g_free(connman_settings.auto_connect);
+	g_free(connman_settings.preferred_techs);
+	g_strfreev(connman_settings.fallback_nameservers);
+	g_strfreev(connman_settings.blacklisted_interfaces);
+	g_strfreev(connman_settings.tethering_technologies);
+
+	connman_daemon_cleanup(option_pidfile);
+
+	g_free(option_pidfile);
+	g_free(option_debug);
+	g_free(option_wifi);
+
+	return 0;
+}
diff --git a/connman/src/main.conf b/connman/src/main.conf
new file mode 100644
index 0000000..8f661d9
--- /dev/null
+++ b/connman/src/main.conf
@@ -0,0 +1,131 @@
+# This file is part of Connection Manager.
+#
+# Connection Manager 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.
+#
+# Connection Manager 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
+
+[General]
+
+# Set input request timeout. Default is 120 seconds
+# The request for inputs like passphrase will timeout
+# after certain amount of time. Use this setting to
+# increase the value in case of different user
+# interface designs.
+# InputRequestTimeout = 120
+
+# Set browser launch timeout. Default is 300 seconds
+# The request for launching a browser for portal pages
+# will timeout after certain amount of time. Use this
+# setting to increase the value in case of different
+# user interface designs.
+# BrowserLaunchTimeout = 300
+
+# Enable background scanning. Default is true.
+# Background scanning will start every 5 minutes unless
+# the scan list is empty. In that case, a simple backoff
+# mechanism starting from 10s up to 5 minutes will run.
+# BackgroundScanning = true
+
+# List of Fallback timeservers separated by ",".
+# These timeservers are used for NTP sync when there are
+# no timeserver set by the user or by the service.
+# These can contain mixed combination of fully qualified
+# domain names, IPv4 and IPv6 addresses.
+# FallbackTimeservers =
+
+# List of fallback nameservers separated by "," used if no
+# nameservers are otherwise provided by the service. The
+# nameserver entries must be in numeric format, host
+# names are ignored.
+# FallbackNameservers =
+
+# List of technologies that are marked autoconnectable
+# by default, separated by commas ",". The default value
+# for this entry when empty is ethernet,wifi,cellular.
+# Services that are automatically connected must have been
+# set up and saved to storage beforehand.
+# DefaultAutoConnectTechnologies =
+
+# List of preferred technologies from the most preferred
+# one to the least preferred one separated by commas ",".
+# Services of the listed technology type will be tried one
+# by one in the order given, until one of them gets connected
+# or they are all tried. A service of a preferred technology
+# type in state 'ready' will get the default route when
+# compared to another preferred type further down the list
+# with state 'ready' or with a non-preferred type; a service
+# of a preferred technology type in state 'online' will get
+# the default route when compared to either a non-preferred
+# type or a preferred type further down in the list.
+# PreferredTechnologies =
+
+# List of blacklisted network interfaces separated by ",".
+# Found interfaces will be compared to the list and will
+# not be handled by connman, if their first characters
+# match any of the list entries. Default value is
+# vmnet,vboxnet,virbr,ifb.
+# NetworkInterfaceBlacklist = vmnet,vboxnet,virbr,ifb
+
+# Allow connman to change the system hostname. This can
+# happen for example if we receive DHCP hostname option.
+# Default value is true.
+# AllowHostnameUpdates = true
+
+# Keep only a single connected technology at any time. When a new
+# service is connected by the user or a better one is found according
+# to PreferredTechnologies, the new service is kept connected and all
+# the other previously connected services are disconnected. With this
+# setting it does not matter whether the previously connected services
+# are in 'online' or 'ready' states, the newly connected service is
+# the only one that will be kept connected. A service connected by the
+# user will be used until going out of network coverage. With this
+# setting enabled applications will notice more network breaks than
+# normal. Default value is false.
+# SingleConnectedTechnology = false
+
+# List of technologies for which tethering is allowed separated by ",".
+# The default value is wifi,bluetooth,gadget. Only those technologies
+# listed here are used for tethering. If ethernet tethering is desired,
+# then ethernet should be added to the list. The technologies listed here
+# have to support tethering, currently tethering is implemented for wifi,
+# bluetooth, gadget and ethernet.
+# NOTE that if ethernet tethering is enabled, then a DHCP server is
+# started on all ethernet interfaces. Tethered ethernet should
+# never be connected to corporate or home network as it will disrupt
+# normal operation of these networks. Due to this ethernet is not
+# tethered by default. Do not activate ethernet tethering unless you
+# really know what you are doing.
+# TetheringTechnologies = wifi,bluetooth,gadget
+
+# Restore earlier tethering status when returning from offline mode,
+# re-enabling a technology, and after restarts and reboots.
+# Default value is false.
+# PersistentTetheringMode = false
+
+# Automatically enable Anycast 6to4 if possible. This is not recommended, as
+# the use of 6to4 will generally lead to a severe degradation of connection
+# quality. See RFC6343. Default value is false (as recommended by RFC6343
+# section 4.1).
+# Enable6to4 = false
+[rlimits]
+
+# Connection Manager resource limits. See setrlimit(2) for more information.
+
+rlimit-as=5242880
+rlimit-core=0
+rlimit-data=3145728
+#rlimit-fsize=0
+rlimit-nofile=768
+rlimit-stack=262144
+rlimit-nproc=3
+rlimit-memlock=0
diff --git a/connman/src/manager.c b/connman/src/manager.c
new file mode 100644
index 0000000..d15ce20
--- /dev/null
+++ b/connman/src/manager.c
@@ -0,0 +1,616 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2013  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 <gdbus.h>
+
+#include <connman/agent.h>
+
+#include "connman.h"
+
+static bool connman_state_idle;
+static dbus_bool_t sessionmode;
+
+static DBusMessage *get_properties(DBusConnection *conn,
+					DBusMessage *msg, void *data)
+{
+	DBusMessage *reply;
+	DBusMessageIter array, dict;
+	dbus_bool_t offlinemode;
+	const char *str;
+
+	DBG("conn %p", conn);
+
+	reply = dbus_message_new_method_return(msg);
+	if (!reply)
+		return NULL;
+
+	dbus_message_iter_init_append(reply, &array);
+
+	connman_dbus_dict_open(&array, &dict);
+
+	str = __connman_notifier_get_state();
+	connman_dbus_dict_append_basic(&dict, "State",
+						DBUS_TYPE_STRING, &str);
+
+	offlinemode = __connman_technology_get_offlinemode();
+	connman_dbus_dict_append_basic(&dict, "OfflineMode",
+					DBUS_TYPE_BOOLEAN, &offlinemode);
+
+	connman_dbus_dict_append_basic(&dict, "SessionMode",
+					DBUS_TYPE_BOOLEAN,
+					&sessionmode);
+
+	connman_dbus_dict_close(&array, &dict);
+
+	return reply;
+}
+
+static DBusMessage *set_property(DBusConnection *conn,
+					DBusMessage *msg, void *data)
+{
+	DBusMessageIter iter, value;
+	const char *name;
+	int type;
+
+	DBG("conn %p", conn);
+
+	if (!dbus_message_iter_init(msg, &iter))
+		return __connman_error_invalid_arguments(msg);
+
+	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
+		return __connman_error_invalid_arguments(msg);
+
+	dbus_message_iter_get_basic(&iter, &name);
+	dbus_message_iter_next(&iter);
+
+	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT)
+		return __connman_error_invalid_arguments(msg);
+
+	dbus_message_iter_recurse(&iter, &value);
+
+	type = dbus_message_iter_get_arg_type(&value);
+
+	if (g_str_equal(name, "OfflineMode")) {
+		dbus_bool_t offlinemode;
+
+		if (type != DBUS_TYPE_BOOLEAN)
+			return __connman_error_invalid_arguments(msg);
+
+		dbus_message_iter_get_basic(&value, &offlinemode);
+
+		__connman_technology_set_offlinemode(offlinemode);
+	} else if (g_str_equal(name, "SessionMode")) {
+
+		if (type != DBUS_TYPE_BOOLEAN)
+			return __connman_error_invalid_arguments(msg);
+
+		dbus_message_iter_get_basic(&value, &sessionmode);
+
+	} else
+		return __connman_error_invalid_property(msg);
+
+	return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+}
+
+static void append_technology_structs(DBusMessageIter *iter, void *user_data)
+{
+	__connman_technology_list_struct(iter);
+}
+
+static DBusMessage *get_technologies(DBusConnection *conn,
+		DBusMessage *msg, void *data)
+{
+	DBusMessage *reply;
+
+	DBG("");
+
+	reply = dbus_message_new_method_return(msg);
+	if (!reply)
+		return NULL;
+
+	__connman_dbus_append_objpath_dict_array(reply,
+			append_technology_structs, NULL);
+
+	return reply;
+}
+
+static DBusMessage *remove_provider(DBusConnection *conn,
+				    DBusMessage *msg, void *data)
+{
+	const char *path;
+	int err;
+
+	DBG("conn %p", conn);
+
+	dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
+							DBUS_TYPE_INVALID);
+
+	err = __connman_provider_remove_by_path(path);
+	if (err < 0)
+		return __connman_error_failed(msg, -err);
+
+	return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+}
+
+static DBusConnection *connection = NULL;
+
+static void idle_state(bool idle)
+{
+
+	DBG("idle %d", idle);
+
+	connman_state_idle = idle;
+
+	if (!connman_state_idle)
+		return;
+}
+
+static struct connman_notifier technology_notifier = {
+	.name		= "manager",
+	.priority	= CONNMAN_NOTIFIER_PRIORITY_HIGH,
+	.idle_state	= idle_state,
+};
+
+static void append_service_structs(DBusMessageIter *iter, void *user_data)
+{
+	__connman_service_list_struct(iter);
+}
+
+static DBusMessage *get_services(DBusConnection *conn,
+					DBusMessage *msg, void *data)
+{
+	DBusMessage *reply;
+
+	reply = dbus_message_new_method_return(msg);
+	if (!reply)
+		return NULL;
+
+	__connman_dbus_append_objpath_dict_array(reply,
+			append_service_structs, NULL);
+
+	return reply;
+}
+
+static void append_peer_structs(DBusMessageIter *iter, void *user_data)
+{
+	__connman_peer_list_struct(iter);
+}
+
+static DBusMessage *get_peers(DBusConnection *conn,
+					DBusMessage *msg, void *data)
+{
+	DBusMessage *reply;
+
+	reply = dbus_message_new_method_return(msg);
+	if (!reply)
+		return NULL;
+
+	__connman_dbus_append_objpath_dict_array(reply,
+					append_peer_structs, NULL);
+	return reply;
+}
+
+static DBusMessage *connect_provider(DBusConnection *conn,
+					DBusMessage *msg, void *data)
+{
+	int err;
+
+	DBG("conn %p", conn);
+
+	err = __connman_provider_create_and_connect(msg);
+	if (err < 0)
+		return __connman_error_failed(msg, -err);
+
+	return NULL;
+}
+
+static DBusMessage *register_agent(DBusConnection *conn,
+					DBusMessage *msg, void *data)
+{
+	const char *sender, *path;
+	int err;
+
+	DBG("conn %p", conn);
+
+	sender = dbus_message_get_sender(msg);
+
+	dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
+							DBUS_TYPE_INVALID);
+
+	err = connman_agent_register(sender, path);
+	if (err < 0)
+		return __connman_error_failed(msg, -err);
+
+	return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+}
+
+static DBusMessage *unregister_agent(DBusConnection *conn,
+					DBusMessage *msg, void *data)
+{
+	const char *sender, *path;
+	int err;
+
+	DBG("conn %p", conn);
+
+	sender = dbus_message_get_sender(msg);
+
+	dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
+							DBUS_TYPE_INVALID);
+
+	err = connman_agent_unregister(sender, path);
+	if (err < 0)
+		return __connman_error_failed(msg, -err);
+
+	return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+}
+
+static DBusMessage *register_counter(DBusConnection *conn,
+					DBusMessage *msg, void *data)
+{
+	const char *sender, *path;
+	unsigned int accuracy, period;
+	int err;
+
+	DBG("conn %p", conn);
+
+	sender = dbus_message_get_sender(msg);
+
+	dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
+						DBUS_TYPE_UINT32, &accuracy,
+						DBUS_TYPE_UINT32, &period,
+							DBUS_TYPE_INVALID);
+
+	/* FIXME: add handling of accuracy parameter */
+
+	err = __connman_counter_register(sender, path, period);
+	if (err < 0)
+		return __connman_error_failed(msg, -err);
+
+	return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+}
+
+static DBusMessage *unregister_counter(DBusConnection *conn,
+					DBusMessage *msg, void *data)
+{
+	const char *sender, *path;
+	int err;
+
+	DBG("conn %p", conn);
+
+	sender = dbus_message_get_sender(msg);
+
+	dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
+							DBUS_TYPE_INVALID);
+
+	err = __connman_counter_unregister(sender, path);
+	if (err < 0)
+		return __connman_error_failed(msg, -err);
+
+	return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+}
+
+static DBusMessage *create_session(DBusConnection *conn,
+					DBusMessage *msg, void *data)
+{
+	int err;
+
+	DBG("conn %p", conn);
+
+	err = __connman_session_create(msg);
+	if (err < 0) {
+		if (err == -EINPROGRESS)
+			return NULL;
+
+		return __connman_error_failed(msg, -err);
+	}
+
+	return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+}
+
+static DBusMessage *destroy_session(DBusConnection *conn,
+					DBusMessage *msg, void *data)
+{
+	int err;
+
+	DBG("conn %p", conn);
+
+	err = __connman_session_destroy(msg);
+	if (err < 0)
+		return __connman_error_failed(msg, -err);
+
+	return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+}
+
+static DBusMessage *request_private_network(DBusConnection *conn,
+					DBusMessage *msg, void *data)
+{
+	const char *sender;
+	int  err;
+
+	DBG("conn %p", conn);
+
+	sender = dbus_message_get_sender(msg);
+
+	err = __connman_private_network_request(msg, sender);
+	if (err < 0)
+		return __connman_error_failed(msg, -err);
+
+	return NULL;
+}
+
+static DBusMessage *release_private_network(DBusConnection *conn,
+					DBusMessage *msg, void *data)
+{
+	const char *path;
+	int err;
+
+	DBG("conn %p", conn);
+
+	dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
+							DBUS_TYPE_INVALID);
+
+	err = __connman_private_network_release(path);
+	if (err < 0)
+		return __connman_error_failed(msg, -err);
+
+	return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+}
+
+static int parse_peers_service_specs(DBusMessageIter *array,
+			const unsigned char **spec, int *spec_len,
+			const unsigned char **query, int *query_len,
+			int *version)
+{
+	*spec = *query = NULL;
+	*spec_len = *query_len = *version = 0;
+
+	while (dbus_message_iter_get_arg_type(array) ==
+							DBUS_TYPE_DICT_ENTRY) {
+		DBusMessageIter entry, inter, value;
+		const char *key;
+
+		dbus_message_iter_recurse(array, &entry);
+		dbus_message_iter_get_basic(&entry, &key);
+
+		dbus_message_iter_next(&entry);
+
+		dbus_message_iter_recurse(&entry, &inter);
+
+		if  (!g_strcmp0(key, "BonjourResponse")) {
+			dbus_message_iter_recurse(&inter, &value);
+			dbus_message_iter_get_fixed_array(&value,
+							spec, spec_len);
+		} else if (!g_strcmp0(key, "BonjourQuery")) {
+			dbus_message_iter_recurse(&inter, &value);
+			dbus_message_iter_get_fixed_array(&value,
+							query, query_len);
+		} else if (!g_strcmp0(key, "UpnpService")) {
+			dbus_message_iter_get_basic(&inter, spec);
+			*spec_len = strlen((const char *)*spec)+1;
+		} else if (!g_strcmp0(key, "UpnpVersion")) {
+			dbus_message_iter_get_basic(&inter, version);
+		} else if (!g_strcmp0(key, "WiFiDisplayIEs")) {
+			if (*spec || *query)
+				return -EINVAL;
+
+			dbus_message_iter_recurse(&inter, &value);
+			dbus_message_iter_get_fixed_array(&value,
+							spec, spec_len);
+		} else
+			return -EINVAL;
+
+		dbus_message_iter_next(array);
+	}
+
+	if ((*query && !*spec && !*version) ||
+				(!*spec && !*query) || (!*spec && *version))
+		return -EINVAL;
+
+	return 0;
+}
+
+static DBusMessage *register_peer_service(DBusConnection *conn,
+						DBusMessage *msg, void *data)
+{
+	const unsigned char *spec, *query;
+	DBusMessageIter iter, array;
+	int spec_len, query_len;
+	dbus_bool_t master;
+	const char *owner;
+	int version;
+	int ret;
+
+	DBG("");
+
+	owner = dbus_message_get_sender(msg);
+
+	dbus_message_iter_init(msg, &iter);
+	dbus_message_iter_recurse(&iter, &array);
+
+	ret = parse_peers_service_specs(&array, &spec, &spec_len,
+						&query, &query_len, &version);
+	if (ret)
+		goto error;
+
+	dbus_message_iter_next(&iter);
+	dbus_message_iter_get_basic(&iter, &master);
+
+	ret = __connman_peer_service_register(owner, msg, spec, spec_len,
+					query, query_len, version,master);
+	if (!ret)
+		return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+	if (ret == -EINPROGRESS)
+		return NULL;
+error:
+	return __connman_error_failed(msg, -ret);
+}
+
+static DBusMessage *unregister_peer_service(DBusConnection *conn,
+						DBusMessage *msg, void *data)
+{
+	const unsigned char *spec, *query;
+	DBusMessageIter iter, array;
+	int spec_len, query_len;
+	const char *owner;
+	int version;
+	int ret;
+
+	DBG("");
+
+	owner = dbus_message_get_sender(msg);
+
+	dbus_message_iter_init(msg, &iter);
+	dbus_message_iter_recurse(&iter, &array);
+
+	ret = parse_peers_service_specs(&array, &spec, &spec_len,
+						&query, &query_len, &version);
+	if (ret)
+		goto error;
+
+	ret = __connman_peer_service_unregister(owner, spec, spec_len,
+						query, query_len, version);
+	if (!ret)
+		return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+error:
+	return __connman_error_failed(msg, -ret);
+
+}
+
+static const GDBusMethodTable manager_methods[] = {
+	{ GDBUS_METHOD("GetProperties",
+			NULL, GDBUS_ARGS({ "properties", "a{sv}" }),
+			get_properties) },
+	{ GDBUS_ASYNC_METHOD("SetProperty",
+			GDBUS_ARGS({ "name", "s" }, { "value", "v" }),
+			NULL, set_property) },
+	{ GDBUS_METHOD("GetTechnologies",
+			NULL, GDBUS_ARGS({ "technologies", "a(oa{sv})" }),
+			get_technologies) },
+	{ GDBUS_DEPRECATED_METHOD("RemoveProvider",
+			GDBUS_ARGS({ "provider", "o" }), NULL,
+			remove_provider) },
+	{ GDBUS_METHOD("GetServices",
+			NULL, GDBUS_ARGS({ "services", "a(oa{sv})" }),
+			get_services) },
+	{ GDBUS_METHOD("GetPeers",
+			NULL, GDBUS_ARGS({ "peers", "a(oa{sv})" }),
+			get_peers) },
+	{ GDBUS_DEPRECATED_ASYNC_METHOD("ConnectProvider",
+			      GDBUS_ARGS({ "provider", "a{sv}" }),
+			      GDBUS_ARGS({ "path", "o" }),
+			      connect_provider) },
+	{ GDBUS_METHOD("RegisterAgent",
+			GDBUS_ARGS({ "path", "o" }), NULL,
+			register_agent) },
+	{ GDBUS_METHOD("UnregisterAgent",
+			GDBUS_ARGS({ "path", "o" }), NULL,
+			unregister_agent) },
+	{ GDBUS_METHOD("RegisterCounter",
+			GDBUS_ARGS({ "path", "o" }, { "accuracy", "u" },
+					{ "period", "u" }),
+			NULL, register_counter) },
+	{ GDBUS_METHOD("UnregisterCounter",
+			GDBUS_ARGS({ "path", "o" }), NULL,
+			unregister_counter) },
+	{ GDBUS_ASYNC_METHOD("CreateSession",
+			GDBUS_ARGS({ "settings", "a{sv}" },
+						{ "notifier", "o" }),
+			GDBUS_ARGS({ "session", "o" }),
+			create_session) },
+	{ GDBUS_METHOD("DestroySession",
+			GDBUS_ARGS({ "session", "o" }), NULL,
+			destroy_session) },
+	{ GDBUS_ASYNC_METHOD("RequestPrivateNetwork",
+			      NULL, GDBUS_ARGS({ "path", "o" },
+					       { "settings", "a{sv}" },
+					       { "socket", "h" }),
+			      request_private_network) },
+	{ GDBUS_METHOD("ReleasePrivateNetwork",
+			GDBUS_ARGS({ "path", "o" }), NULL,
+			release_private_network) },
+	{ GDBUS_ASYNC_METHOD("RegisterPeerService",
+			GDBUS_ARGS({ "specification", "a{sv}" },
+				   { "master", "b" }), NULL,
+			register_peer_service) },
+	{ GDBUS_METHOD("UnregisterPeerService",
+			GDBUS_ARGS({ "specification", "a{sv}" }), NULL,
+			unregister_peer_service) },
+	{ },
+};
+
+static const GDBusSignalTable manager_signals[] = {
+	{ GDBUS_SIGNAL("PropertyChanged",
+			GDBUS_ARGS({ "name", "s" }, { "value", "v" })) },
+	{ GDBUS_SIGNAL("TechnologyAdded",
+			GDBUS_ARGS({ "path", "o" },
+				   { "properties", "a{sv}" })) },
+	{ GDBUS_SIGNAL("TechnologyRemoved",
+			GDBUS_ARGS({ "path", "o" })) },
+	{ GDBUS_SIGNAL("ServicesChanged",
+			GDBUS_ARGS({ "changed", "a(oa{sv})" },
+					{ "removed", "ao" })) },
+	{ GDBUS_SIGNAL("PeersChanged",
+			GDBUS_ARGS({ "changed", "a(oa{sv})" },
+					{ "removed", "ao" })) },
+	{ },
+};
+
+int __connman_manager_init(void)
+{
+	DBG("");
+
+	connection = connman_dbus_get_connection();
+	if (!connection)
+		return -1;
+
+	if (connman_notifier_register(&technology_notifier) < 0)
+		connman_error("Failed to register technology notifier");
+
+	g_dbus_register_interface(connection, CONNMAN_MANAGER_PATH,
+					CONNMAN_MANAGER_INTERFACE,
+					manager_methods,
+					manager_signals, NULL, NULL, NULL);
+
+	connman_state_idle = true;
+
+	return 0;
+}
+
+void __connman_manager_cleanup(void)
+{
+	DBG("");
+
+	if (!connection)
+		return;
+
+	connman_notifier_unregister(&technology_notifier);
+
+	g_dbus_unregister_interface(connection, CONNMAN_MANAGER_PATH,
+						CONNMAN_MANAGER_INTERFACE);
+
+	dbus_connection_unref(connection);
+}
diff --git a/connman/src/nat.c b/connman/src/nat.c
new file mode 100644
index 0000000..063f085
--- /dev/null
+++ b/connman/src/nat.c
@@ -0,0 +1,226 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2012  Intel Corporation. All rights reserved.
+ *  Copyright (C) 2012-2014  BMW Car IT GmbH.
+ *
+ *  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 <stdio.h>
+
+#include "connman.h"
+
+static char *default_interface;
+static GHashTable *nat_hash;
+
+struct connman_nat {
+	char *address;
+	unsigned char prefixlen;
+	struct firewall_context *fw;
+
+	char *interface;
+};
+
+static int enable_ip_forward(bool enable)
+{
+	FILE *f;
+
+	f = fopen("/proc/sys/net/ipv4/ip_forward", "r+");
+	if (!f)
+		return -errno;
+
+	if (enable)
+		fprintf(f, "1");
+	else
+		fprintf(f, "0");
+
+	fclose(f);
+
+	return 0;
+}
+
+static int enable_nat(struct connman_nat *nat)
+{
+	char *cmd;
+	int err;
+
+	g_free(nat->interface);
+	nat->interface = g_strdup(default_interface);
+
+	if (!nat->interface)
+		return 0;
+
+	/* Enable masquerading */
+	cmd = g_strdup_printf("-s %s/%d -o %s -j MASQUERADE",
+					nat->address,
+					nat->prefixlen,
+					nat->interface);
+
+	err = __connman_firewall_add_rule(nat->fw, "nat",
+				"POSTROUTING", cmd);
+	g_free(cmd);
+	if (err < 0)
+		return err;
+
+	return __connman_firewall_enable(nat->fw);
+}
+
+static void disable_nat(struct connman_nat *nat)
+{
+	if (!nat->interface)
+		return;
+
+	/* Disable masquerading */
+	__connman_firewall_disable(nat->fw);
+}
+
+int __connman_nat_enable(const char *name, const char *address,
+				unsigned char prefixlen)
+{
+	struct connman_nat *nat;
+	int err;
+
+	if (g_hash_table_size(nat_hash) == 0) {
+		err = enable_ip_forward(true);
+		if (err < 0)
+			return err;
+	}
+
+	nat = g_try_new0(struct connman_nat, 1);
+	if (!nat)
+		goto err;
+
+	nat->fw = __connman_firewall_create();
+	if (!nat->fw)
+		goto err;
+
+	nat->address = g_strdup(address);
+	nat->prefixlen = prefixlen;
+
+	g_hash_table_replace(nat_hash, g_strdup(name), nat);
+
+	return enable_nat(nat);
+
+err:
+	if (nat) {
+		if (nat->fw)
+			__connman_firewall_destroy(nat->fw);
+		g_free(nat);
+	}
+
+	if (g_hash_table_size(nat_hash) == 0)
+		enable_ip_forward(false);
+
+	return -ENOMEM;
+}
+
+void __connman_nat_disable(const char *name)
+{
+	struct connman_nat *nat;
+
+	nat = g_hash_table_lookup(nat_hash, name);
+	if (!nat)
+		return;
+
+	disable_nat(nat);
+
+	g_hash_table_remove(nat_hash, name);
+
+	if (g_hash_table_size(nat_hash) == 0)
+		enable_ip_forward(false);
+}
+
+static void update_default_interface(struct connman_service *service)
+{
+	GHashTableIter iter;
+	gpointer key, value;
+	char *interface;
+	int err;
+
+	interface = connman_service_get_interface(service);
+
+	DBG("interface %s", interface);
+
+	g_free(default_interface);
+	default_interface = interface;
+
+	g_hash_table_iter_init(&iter, nat_hash);
+
+	while (g_hash_table_iter_next(&iter, &key, &value)) {
+		const char *name = key;
+		struct connman_nat *nat = value;
+
+		disable_nat(nat);
+		err = enable_nat(nat);
+		if (err < 0)
+			DBG("Failed to enable nat for %s", name);
+	}
+}
+
+static void shutdown_nat(gpointer key, gpointer value, gpointer user_data)
+{
+	const char *name = key;
+
+	__connman_nat_disable(name);
+}
+
+static void cleanup_nat(gpointer data)
+{
+	struct connman_nat *nat = data;
+
+	__connman_firewall_destroy(nat->fw);
+	g_free(nat->address);
+	g_free(nat->interface);
+	g_free(nat);
+}
+
+static struct connman_notifier nat_notifier = {
+	.name			= "nat",
+	.default_changed	= update_default_interface,
+};
+
+int __connman_nat_init(void)
+{
+	int err;
+
+	DBG("");
+
+	err = connman_notifier_register(&nat_notifier);
+	if (err < 0)
+		return err;
+
+	nat_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
+						g_free, cleanup_nat);
+
+	return 0;
+}
+
+void __connman_nat_cleanup(void)
+{
+	DBG("");
+
+	g_hash_table_foreach(nat_hash, shutdown_nat, NULL);
+	g_hash_table_destroy(nat_hash);
+	nat_hash = NULL;
+
+	connman_notifier_unregister(&nat_notifier);
+}
diff --git a/connman/src/net.connman.service.in b/connman/src/net.connman.service.in
new file mode 100644
index 0000000..f7f6a7c
--- /dev/null
+++ b/connman/src/net.connman.service.in
@@ -0,0 +1,5 @@
+[D-BUS Service]
+Name=net.connman
+Exec=@sbindir@/connmand -n
+User=root
+SystemdService=connman.service
diff --git a/connman/src/network.c b/connman/src/network.c
new file mode 100644
index 0000000..38ee8b7
--- /dev/null
+++ b/connman/src/network.c
@@ -0,0 +1,2122 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2014  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 <string.h>
+
+#include "connman.h"
+
+/*
+ * How many times to send RS with the purpose of
+ * refreshing RDNSS entries before they actually expire.
+ * With a value of 1, one RS will be sent, with no retries.
+ */
+#define RS_REFRESH_COUNT	1
+
+/*
+ * Value in seconds to wait for RA after RS was sent.
+ * After this time elapsed, we can send another RS.
+ */
+#define RS_REFRESH_TIMEOUT	3
+
+static GSList *network_list = NULL;
+static GSList *driver_list = NULL;
+
+struct connman_network {
+	int refcount;
+	enum connman_network_type type;
+	bool available;
+	bool connected;
+	bool roaming;
+	uint8_t strength;
+	uint16_t frequency;
+	char *identifier;
+	char *name;
+	char *node;
+	char *group;
+	char *path;
+	int index;
+	int router_solicit_count;
+	int router_solicit_refresh_count;
+
+	struct connman_network_driver *driver;
+	void *driver_data;
+
+	bool connecting;
+	bool associating;
+
+	struct connman_device *device;
+
+	struct {
+		void *ssid;
+		int ssid_len;
+		char *mode;
+		unsigned short channel;
+		char *security;
+		char *passphrase;
+		char *eap;
+		char *identity;
+		char *agent_identity;
+		char *ca_cert_path;
+		char *client_cert_path;
+		char *private_key_path;
+		char *private_key_passphrase;
+		char *phase2_auth;
+		bool wps;
+		bool use_wps;
+		char *pin_wps;
+	} wifi;
+
+	struct {
+		bool joining_permitted;
+		char *parent_address;
+	} lowpan;
+
+};
+
+static const char *type2string(enum connman_network_type type)
+{
+	switch (type) {
+	case CONNMAN_NETWORK_TYPE_UNKNOWN:
+	case CONNMAN_NETWORK_TYPE_VENDOR:
+		break;
+	case CONNMAN_NETWORK_TYPE_ETHERNET:
+		return "ethernet";
+	case CONNMAN_NETWORK_TYPE_GADGET:
+		return "gadget";
+	case CONNMAN_NETWORK_TYPE_WIFI:
+		return "wifi";
+	case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
+	case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
+		return "bluetooth";
+	case CONNMAN_NETWORK_TYPE_CELLULAR:
+		return "cellular";
+	case CONNMAN_NETWORK_TYPE_LOWPAN:
+		return "lowpan";
+	}
+
+	return NULL;
+}
+
+static bool match_driver(struct connman_network *network,
+					struct connman_network_driver *driver)
+{
+	if (network->type == driver->type ||
+			driver->type == CONNMAN_NETWORK_TYPE_UNKNOWN)
+		return true;
+
+	return false;
+}
+
+static void set_configuration(struct connman_network *network,
+			enum connman_ipconfig_type type)
+{
+	struct connman_service *service;
+
+	DBG("network %p", network);
+
+	if (!network->device)
+		return;
+
+	__connman_device_set_network(network->device, network);
+
+	connman_device_set_disconnected(network->device, false);
+
+	service = connman_service_lookup_from_network(network);
+	__connman_service_ipconfig_indicate_state(service,
+					CONNMAN_SERVICE_STATE_CONFIGURATION,
+					type);
+}
+
+static void dhcp_success(struct connman_network *network)
+{
+	struct connman_service *service;
+	struct connman_ipconfig *ipconfig_ipv4;
+	int err;
+
+	service = connman_service_lookup_from_network(network);
+	if (!service)
+		goto err;
+
+	ipconfig_ipv4 = __connman_service_get_ip4config(service);
+
+	DBG("lease acquired for ipconfig %p", ipconfig_ipv4);
+
+	if (!ipconfig_ipv4)
+		return;
+
+	err = __connman_ipconfig_address_add(ipconfig_ipv4);
+	if (err < 0)
+		goto err;
+
+	err = __connman_ipconfig_gateway_add(ipconfig_ipv4);
+	if (err < 0)
+		goto err;
+
+	return;
+
+err:
+	connman_network_set_error(network,
+				CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
+}
+
+static void dhcp_failure(struct connman_network *network)
+{
+	struct connman_service *service;
+	struct connman_ipconfig *ipconfig_ipv4;
+
+	service = connman_service_lookup_from_network(network);
+	if (!service)
+		return;
+
+	ipconfig_ipv4 = __connman_service_get_ip4config(service);
+
+	DBG("lease lost for ipconfig %p", ipconfig_ipv4);
+
+	if (!ipconfig_ipv4)
+		return;
+
+	__connman_ipconfig_address_remove(ipconfig_ipv4);
+	__connman_ipconfig_gateway_remove(ipconfig_ipv4);
+}
+
+static void dhcp_callback(struct connman_ipconfig *ipconfig,
+			struct connman_network *network,
+			bool success, gpointer data)
+{
+	network->connecting = false;
+
+	if (success)
+		dhcp_success(network);
+	else
+		dhcp_failure(network);
+}
+
+static int set_connected_manual(struct connman_network *network)
+{
+	int err = 0;
+	struct connman_service *service;
+	struct connman_ipconfig *ipconfig;
+
+	DBG("network %p", network);
+
+	network->connecting = false;
+
+	service = connman_service_lookup_from_network(network);
+
+	ipconfig = __connman_service_get_ip4config(service);
+
+	if (!__connman_ipconfig_get_local(ipconfig))
+		__connman_service_read_ip4config(service);
+
+	err = __connman_ipconfig_address_add(ipconfig);
+	if (err < 0)
+		goto err;
+
+	err = __connman_ipconfig_gateway_add(ipconfig);
+	if (err < 0)
+		goto err;
+
+err:
+	return err;
+}
+
+static int set_connected_dhcp(struct connman_network *network)
+{
+	struct connman_service *service;
+	struct connman_ipconfig *ipconfig_ipv4;
+	int err;
+
+	DBG("network %p", network);
+
+	service = connman_service_lookup_from_network(network);
+	ipconfig_ipv4 = __connman_service_get_ip4config(service);
+
+	err = __connman_dhcp_start(ipconfig_ipv4, network,
+							dhcp_callback, NULL);
+	if (err < 0) {
+		connman_error("Can not request DHCP lease");
+		return err;
+	}
+
+	return 0;
+}
+
+static int manual_ipv6_set(struct connman_network *network,
+				struct connman_ipconfig *ipconfig_ipv6)
+{
+	struct connman_service *service;
+	int err;
+
+	DBG("network %p ipv6 %p", network, ipconfig_ipv6);
+
+	service = connman_service_lookup_from_network(network);
+	if (!service)
+		return -EINVAL;
+
+	if (!__connman_ipconfig_get_local(ipconfig_ipv6))
+		__connman_service_read_ip6config(service);
+
+	__connman_ipconfig_enable_ipv6(ipconfig_ipv6);
+
+	err = __connman_ipconfig_address_add(ipconfig_ipv6);
+	if (err < 0) {
+		connman_network_set_error(network,
+			CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
+		return err;
+	}
+
+	err = __connman_ipconfig_gateway_add(ipconfig_ipv6);
+	if (err < 0)
+		return err;
+
+	__connman_connection_gateway_activate(service,
+						CONNMAN_IPCONFIG_TYPE_IPV6);
+
+	__connman_device_set_network(network->device, network);
+
+	connman_device_set_disconnected(network->device, false);
+
+	connman_network_set_associating(network, false);
+
+	network->connecting = false;
+
+	return 0;
+}
+
+static void stop_dhcpv6(struct connman_network *network)
+{
+	network->connecting = false;
+
+	__connman_dhcpv6_stop(network);
+}
+
+static void dhcpv6_release_callback(struct connman_network *network,
+				enum __connman_dhcpv6_status status,
+				gpointer data)
+{
+	DBG("status %d", status);
+
+	stop_dhcpv6(network);
+}
+
+static void release_dhcpv6(struct connman_network *network)
+{
+	__connman_dhcpv6_start_release(network, dhcpv6_release_callback);
+	stop_dhcpv6(network);
+}
+
+static void dhcpv6_info_callback(struct connman_network *network,
+				enum __connman_dhcpv6_status status,
+				gpointer data)
+{
+	DBG("status %d", status);
+
+	stop_dhcpv6(network);
+}
+
+static int dhcpv6_set_addresses(struct connman_network *network)
+{
+	struct connman_service *service;
+	struct connman_ipconfig *ipconfig_ipv6;
+	int err = -EINVAL;
+
+	service = connman_service_lookup_from_network(network);
+	if (!service)
+		goto err;
+
+	network->connecting = false;
+
+	ipconfig_ipv6 = __connman_service_get_ip6config(service);
+	err = __connman_ipconfig_address_add(ipconfig_ipv6);
+	if (err < 0)
+		goto err;
+
+	return 0;
+
+err:
+	connman_network_set_error(network,
+				CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
+	return err;
+}
+
+static void autoconf_ipv6_set(struct connman_network *network);
+static void dhcpv6_callback(struct connman_network *network,
+			enum __connman_dhcpv6_status status, gpointer data);
+
+/*
+ * Have a separate callback for renew so that we do not do autoconf
+ * in wrong phase as the dhcpv6_callback() is also called when doing
+ * DHCPv6 solicitation.
+ */
+static void dhcpv6_renew_callback(struct connman_network *network,
+				enum __connman_dhcpv6_status status,
+				gpointer data)
+{
+	switch (status) {
+	case CONNMAN_DHCPV6_STATUS_SUCCEED:
+		dhcpv6_callback(network, status, data);
+		break;
+	case CONNMAN_DHCPV6_STATUS_FAIL:
+	case CONNMAN_DHCPV6_STATUS_RESTART:
+		stop_dhcpv6(network);
+
+		/* restart and do solicit again. */
+		autoconf_ipv6_set(network);
+		break;
+	}
+}
+
+static void dhcpv6_callback(struct connman_network *network,
+			enum __connman_dhcpv6_status status, gpointer data)
+{
+	DBG("status %d", status);
+
+	/* Start the renew process if necessary */
+	if (status == CONNMAN_DHCPV6_STATUS_SUCCEED) {
+
+		if (dhcpv6_set_addresses(network) < 0) {
+			stop_dhcpv6(network);
+			return;
+		}
+
+		if (__connman_dhcpv6_start_renew(network,
+					dhcpv6_renew_callback) == -ETIMEDOUT)
+			dhcpv6_renew_callback(network,
+						CONNMAN_DHCPV6_STATUS_FAIL,
+						data);
+
+	} else if (status == CONNMAN_DHCPV6_STATUS_RESTART) {
+		stop_dhcpv6(network);
+		autoconf_ipv6_set(network);
+	} else
+		stop_dhcpv6(network);
+}
+
+static void check_dhcpv6(struct nd_router_advert *reply,
+			unsigned int length, void *user_data)
+{
+	struct connman_network *network = user_data;
+	struct connman_service *service;
+	GSList *prefixes;
+
+	DBG("reply %p", reply);
+
+	if (!reply) {
+		/*
+		 * Router solicitation message seem to get lost easily so
+		 * try to send it again.
+		 */
+		if (network->router_solicit_count > 0) {
+			DBG("re-send router solicitation %d",
+						network->router_solicit_count);
+			network->router_solicit_count--;
+			__connman_inet_ipv6_send_rs(network->index, 1,
+						check_dhcpv6, network);
+			return;
+		}
+		connman_network_unref(network);
+		return;
+	}
+
+	network->router_solicit_count = 0;
+
+	/*
+	 * If we were disconnected while waiting router advertisement,
+	 * we just quit and do not start DHCPv6
+	 */
+	if (!network->connected) {
+		connman_network_unref(network);
+		return;
+	}
+
+	prefixes = __connman_inet_ipv6_get_prefixes(reply, length);
+
+	/*
+	 * If IPv6 config is missing from service, then create it.
+	 * The ipconfig might be missing if we got a rtnl message
+	 * that disabled IPv6 config and thus removed it. This
+	 * can happen if we are switching from one service to
+	 * another in the same interface. The only way to get IPv6
+	 * config back is to re-create it here.
+	 */
+	service = connman_service_lookup_from_network(network);
+	if (service) {
+		connman_service_create_ip6config(service, network->index);
+
+		connman_network_set_associating(network, false);
+
+		__connman_service_ipconfig_indicate_state(service,
+					CONNMAN_SERVICE_STATE_CONFIGURATION,
+					CONNMAN_IPCONFIG_TYPE_IPV6);
+	}
+
+	/*
+	 * We do stateful/stateless DHCPv6 if router advertisement says so.
+	 */
+	if (reply->nd_ra_flags_reserved & ND_RA_FLAG_MANAGED) {
+		__connman_dhcpv6_start(network, prefixes, dhcpv6_callback);
+	} else {
+		if (reply->nd_ra_flags_reserved & ND_RA_FLAG_OTHER)
+			__connman_dhcpv6_start_info(network,
+							dhcpv6_info_callback);
+
+		g_slist_free_full(prefixes, g_free);
+		network->connecting = false;
+	}
+
+	connman_network_unref(network);
+}
+
+static void receive_refresh_rs_reply(struct nd_router_advert *reply,
+		unsigned int length, void *user_data)
+{
+	struct connman_network *network = user_data;
+
+	DBG("reply %p", reply);
+
+	if (!reply) {
+		/*
+		 * Router solicitation message seem to get lost easily so
+		 * try to send it again.
+		 */
+		if (network->router_solicit_refresh_count > 1) {
+			network->router_solicit_refresh_count--;
+			DBG("re-send router solicitation %d",
+					network->router_solicit_refresh_count);
+			__connman_inet_ipv6_send_rs(network->index,
+					RS_REFRESH_TIMEOUT,
+					receive_refresh_rs_reply,
+					network);
+			return;
+		}
+	}
+
+	/* RS refresh not in progress anymore */
+	network->router_solicit_refresh_count = 0;
+
+	connman_network_unref(network);
+	return;
+}
+
+int __connman_network_refresh_rs_ipv6(struct connman_network *network,
+					int index)
+{
+	int ret = 0;
+
+	DBG("network %p index %d", network, index);
+
+	/* Send only one RS for all RDNSS entries which are about to expire */
+	if (network->router_solicit_refresh_count > 0) {
+		DBG("RS refresh already started");
+		return 0;
+	}
+
+	network->router_solicit_refresh_count = RS_REFRESH_COUNT;
+
+	connman_network_ref(network);
+
+	ret = __connman_inet_ipv6_send_rs(index, RS_REFRESH_TIMEOUT,
+			receive_refresh_rs_reply, network);
+	return ret;
+}
+
+static void autoconf_ipv6_set(struct connman_network *network)
+{
+	struct connman_service *service;
+	struct connman_ipconfig *ipconfig;
+	int index;
+
+	DBG("network %p", network);
+
+	if (network->router_solicit_count > 0) {
+		/*
+		 * The autoconfiguration is already pending and we have sent
+		 * router solicitation messages and are now waiting answers.
+		 * There is no need to continue any further.
+		 */
+		DBG("autoconfiguration already started");
+		return;
+	}
+
+	__connman_device_set_network(network->device, network);
+
+	connman_device_set_disconnected(network->device, false);
+
+	service = connman_service_lookup_from_network(network);
+	if (!service)
+		return;
+
+	ipconfig = __connman_service_get_ip6config(service);
+	if (!ipconfig)
+		return;
+
+	__connman_ipconfig_enable_ipv6(ipconfig);
+
+	__connman_ipconfig_address_remove(ipconfig);
+
+	index = __connman_ipconfig_get_index(ipconfig);
+
+	connman_network_ref(network);
+
+	/* Try to get stateless DHCPv6 information, RFC 3736 */
+	network->router_solicit_count = 3;
+	__connman_inet_ipv6_send_rs(index, 1, check_dhcpv6, network);
+}
+
+static void set_connected(struct connman_network *network)
+{
+	struct connman_ipconfig *ipconfig_ipv4, *ipconfig_ipv6;
+	struct connman_service *service;
+
+	if (network->connected)
+		return;
+
+	connman_network_set_associating(network, false);
+
+	network->connected = true;
+
+	service = connman_service_lookup_from_network(network);
+
+	ipconfig_ipv4 = __connman_service_get_ip4config(service);
+	ipconfig_ipv6 = __connman_service_get_ip6config(service);
+
+	DBG("service %p ipv4 %p ipv6 %p", service, ipconfig_ipv4,
+		ipconfig_ipv6);
+
+	__connman_network_enable_ipconfig(network, ipconfig_ipv4);
+	__connman_network_enable_ipconfig(network, ipconfig_ipv6);
+}
+
+static void set_disconnected(struct connman_network *network)
+{
+	struct connman_ipconfig *ipconfig_ipv4, *ipconfig_ipv6;
+	enum connman_ipconfig_method ipv4_method, ipv6_method;
+	enum connman_service_state state;
+	struct connman_service *service;
+
+	service = connman_service_lookup_from_network(network);
+
+	ipconfig_ipv4 = __connman_service_get_ip4config(service);
+	ipconfig_ipv6 = __connman_service_get_ip6config(service);
+
+	DBG("service %p ipv4 %p ipv6 %p", service, ipconfig_ipv4,
+		ipconfig_ipv6);
+
+	ipv4_method = __connman_ipconfig_get_method(ipconfig_ipv4);
+	ipv6_method = __connman_ipconfig_get_method(ipconfig_ipv6);
+
+	DBG("method ipv4 %d ipv6 %d", ipv4_method, ipv6_method);
+
+	/*
+	 * Resetting solicit count here will prevent the RS resend loop
+	 * from sending packets in check_dhcpv6()
+	 */
+	network->router_solicit_count = 0;
+
+	__connman_device_set_network(network->device, NULL);
+
+	if (network->connected) {
+		switch (ipv6_method) {
+		case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
+		case CONNMAN_IPCONFIG_METHOD_OFF:
+		case CONNMAN_IPCONFIG_METHOD_FIXED:
+		case CONNMAN_IPCONFIG_METHOD_MANUAL:
+			break;
+		case CONNMAN_IPCONFIG_METHOD_DHCP:
+		case CONNMAN_IPCONFIG_METHOD_AUTO:
+			release_dhcpv6(network);
+			break;
+		}
+
+		switch (ipv4_method) {
+		case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
+		case CONNMAN_IPCONFIG_METHOD_OFF:
+		case CONNMAN_IPCONFIG_METHOD_AUTO:
+		case CONNMAN_IPCONFIG_METHOD_FIXED:
+		case CONNMAN_IPCONFIG_METHOD_MANUAL:
+			break;
+		case CONNMAN_IPCONFIG_METHOD_DHCP:
+			__connman_dhcp_stop(ipconfig_ipv4);
+			break;
+		}
+	}
+
+	/*
+	 * We only set the disconnect state if we were not in idle
+	 * or in failure. It does not make sense to go to disconnect
+	 * state if we were not connected.
+	 */
+	state = __connman_service_ipconfig_get_state(service,
+						CONNMAN_IPCONFIG_TYPE_IPV4);
+	if (state != CONNMAN_SERVICE_STATE_IDLE &&
+			state != CONNMAN_SERVICE_STATE_FAILURE)
+		__connman_service_ipconfig_indicate_state(service,
+					CONNMAN_SERVICE_STATE_DISCONNECT,
+					CONNMAN_IPCONFIG_TYPE_IPV4);
+
+	state = __connman_service_ipconfig_get_state(service,
+						CONNMAN_IPCONFIG_TYPE_IPV6);
+	if (state != CONNMAN_SERVICE_STATE_IDLE &&
+				state != CONNMAN_SERVICE_STATE_FAILURE)
+		__connman_service_ipconfig_indicate_state(service,
+					CONNMAN_SERVICE_STATE_DISCONNECT,
+					CONNMAN_IPCONFIG_TYPE_IPV6);
+
+	if (network->connected) {
+		__connman_connection_gateway_remove(service,
+						CONNMAN_IPCONFIG_TYPE_ALL);
+
+		__connman_ipconfig_address_unset(ipconfig_ipv4);
+		__connman_ipconfig_address_unset(ipconfig_ipv6);
+
+		/*
+		 * Special handling for IPv6 autoconfigured address.
+		 * The simplest way to remove autoconfigured routes is to
+		 * disable IPv6 temporarily so that kernel will do the cleanup
+		 * automagically.
+		 */
+		if (ipv6_method == CONNMAN_IPCONFIG_METHOD_AUTO) {
+			__connman_ipconfig_disable_ipv6(ipconfig_ipv6);
+			__connman_ipconfig_enable_ipv6(ipconfig_ipv6);
+		}
+	}
+
+	__connman_service_ipconfig_indicate_state(service,
+						CONNMAN_SERVICE_STATE_IDLE,
+						CONNMAN_IPCONFIG_TYPE_IPV4);
+
+	__connman_service_ipconfig_indicate_state(service,
+						CONNMAN_SERVICE_STATE_IDLE,
+						CONNMAN_IPCONFIG_TYPE_IPV6);
+
+	network->connecting = false;
+	network->connected = false;
+
+	connman_network_set_associating(network, false);
+}
+
+
+
+static int network_probe(struct connman_network *network)
+{
+	GSList *list;
+	struct connman_network_driver *driver = NULL;
+
+	DBG("network %p name %s", network, network->name);
+
+	if (network->driver)
+		return -EALREADY;
+
+	for (list = driver_list; list; list = list->next) {
+		driver = list->data;
+
+		if (!match_driver(network, driver)) {
+			driver = NULL;
+			continue;
+		}
+
+		DBG("driver %p name %s", driver, driver->name);
+
+		if (driver->probe(network) == 0)
+			break;
+
+		driver = NULL;
+	}
+
+	if (!driver)
+		return -ENODEV;
+
+	if (!network->group)
+		return -EINVAL;
+
+	switch (network->type) {
+	case CONNMAN_NETWORK_TYPE_UNKNOWN:
+	case CONNMAN_NETWORK_TYPE_VENDOR:
+		return 0;
+	case CONNMAN_NETWORK_TYPE_ETHERNET:
+	case CONNMAN_NETWORK_TYPE_GADGET:
+	case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
+	case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
+	case CONNMAN_NETWORK_TYPE_CELLULAR:
+	case CONNMAN_NETWORK_TYPE_WIFI:
+	case CONNMAN_NETWORK_TYPE_LOWPAN:
+		network->driver = driver;
+		if (!__connman_service_create_from_network(network)) {
+			network->driver = NULL;
+			return -EINVAL;
+		}
+	}
+
+	return 0;
+}
+
+static void network_remove(struct connman_network *network)
+{
+	DBG("network %p name %s", network, network->name);
+
+	if (!network->driver)
+		return;
+
+	if (network->connected)
+		set_disconnected(network);
+
+	switch (network->type) {
+	case CONNMAN_NETWORK_TYPE_UNKNOWN:
+	case CONNMAN_NETWORK_TYPE_VENDOR:
+		break;
+	case CONNMAN_NETWORK_TYPE_ETHERNET:
+	case CONNMAN_NETWORK_TYPE_GADGET:
+	case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
+	case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
+	case CONNMAN_NETWORK_TYPE_CELLULAR:
+	case CONNMAN_NETWORK_TYPE_WIFI:
+	case CONNMAN_NETWORK_TYPE_LOWPAN:
+		if (network->group) {
+			__connman_service_remove_from_network(network);
+
+			g_free(network->group);
+			network->group = NULL;
+		}
+		break;
+	}
+
+	if (network->driver->remove)
+		network->driver->remove(network);
+
+	network->driver = NULL;
+}
+
+static void network_change(struct connman_network *network)
+{
+	DBG("network %p name %s", network, network->name);
+
+	if (!network->connected)
+		return;
+
+	connman_device_set_disconnected(network->device, true);
+
+	if (network->driver && network->driver->disconnect) {
+		network->driver->disconnect(network, FALSE);
+		return;
+	}
+
+	network->connected = false;
+}
+
+static void probe_driver(struct connman_network_driver *driver)
+{
+	GSList *list;
+
+	DBG("driver %p name %s", driver, driver->name);
+
+	for (list = network_list; list; list = list->next) {
+		struct connman_network *network = list->data;
+
+		if (network->driver)
+			continue;
+
+		if (driver->type != network->type)
+			continue;
+
+		if (driver->probe(network) < 0)
+			continue;
+
+		network->driver = driver;
+	}
+}
+
+static void remove_driver(struct connman_network_driver *driver)
+{
+	GSList *list;
+
+	DBG("driver %p name %s", driver, driver->name);
+
+	for (list = network_list; list; list = list->next) {
+		struct connman_network *network = list->data;
+
+		if (network->driver == driver)
+			network_remove(network);
+	}
+}
+
+static gint compare_priority(gconstpointer a, gconstpointer b)
+{
+	const struct connman_network_driver *driver1 = a;
+	const struct connman_network_driver *driver2 = b;
+
+	return driver2->priority - driver1->priority;
+}
+
+/**
+ * connman_network_driver_register:
+ * @driver: network driver definition
+ *
+ * Register a new network driver
+ *
+ * Returns: %0 on success
+ */
+int connman_network_driver_register(struct connman_network_driver *driver)
+{
+	DBG("driver %p name %s", driver, driver->name);
+
+	driver_list = g_slist_insert_sorted(driver_list, driver,
+							compare_priority);
+
+	probe_driver(driver);
+
+	return 0;
+}
+
+/**
+ * connman_network_driver_unregister:
+ * @driver: network driver definition
+ *
+ * Remove a previously registered network driver
+ */
+void connman_network_driver_unregister(struct connman_network_driver *driver)
+{
+	DBG("driver %p name %s", driver, driver->name);
+
+	driver_list = g_slist_remove(driver_list, driver);
+
+	remove_driver(driver);
+}
+
+static void network_destruct(struct connman_network *network)
+{
+	DBG("network %p name %s", network, network->name);
+
+	g_free(network->wifi.ssid);
+	g_free(network->wifi.mode);
+	g_free(network->wifi.security);
+	g_free(network->wifi.passphrase);
+	g_free(network->wifi.eap);
+	g_free(network->wifi.identity);
+	g_free(network->wifi.agent_identity);
+	g_free(network->wifi.ca_cert_path);
+	g_free(network->wifi.client_cert_path);
+	g_free(network->wifi.private_key_path);
+	g_free(network->wifi.private_key_passphrase);
+	g_free(network->wifi.phase2_auth);
+	g_free(network->wifi.pin_wps);
+
+	g_free(network->path);
+	g_free(network->group);
+	g_free(network->node);
+	g_free(network->name);
+	g_free(network->identifier);
+
+	network->device = NULL;
+
+	g_free(network);
+}
+
+/**
+ * connman_network_create:
+ * @identifier: network identifier (for example an unqiue name)
+ *
+ * Allocate a new network and assign the #identifier to it.
+ *
+ * Returns: a newly-allocated #connman_network structure
+ */
+struct connman_network *connman_network_create(const char *identifier,
+						enum connman_network_type type)
+{
+	struct connman_network *network;
+	char *ident;
+
+	DBG("identifier %s type %d", identifier, type);
+
+	network = g_try_new0(struct connman_network, 1);
+	if (!network)
+		return NULL;
+
+	DBG("network %p", network);
+
+	network->refcount = 1;
+
+	ident = g_strdup(identifier);
+
+	if (!ident) {
+		g_free(network);
+		return NULL;
+	}
+
+	network->type       = type;
+	network->identifier = ident;
+
+	network_list = g_slist_prepend(network_list, network);
+
+	return network;
+}
+
+/**
+ * connman_network_ref:
+ * @network: network structure
+ *
+ * Increase reference counter of  network
+ */
+struct connman_network *
+connman_network_ref_debug(struct connman_network *network,
+			const char *file, int line, const char *caller)
+{
+	DBG("%p name %s ref %d by %s:%d:%s()", network, network->name,
+		network->refcount + 1, file, line, caller);
+
+	__sync_fetch_and_add(&network->refcount, 1);
+
+	return network;
+}
+
+/**
+ * connman_network_unref:
+ * @network: network structure
+ *
+ * Decrease reference counter of network
+ */
+void connman_network_unref_debug(struct connman_network *network,
+				const char *file, int line, const char *caller)
+{
+	DBG("%p name %s ref %d by %s:%d:%s()", network, network->name,
+		network->refcount - 1, file, line, caller);
+
+	if (__sync_fetch_and_sub(&network->refcount, 1) != 1)
+		return;
+
+	network_list = g_slist_remove(network_list, network);
+
+	network_destruct(network);
+}
+
+const char *__connman_network_get_type(struct connman_network *network)
+{
+	return type2string(network->type);
+}
+
+/**
+ * connman_network_get_type:
+ * @network: network structure
+ *
+ * Get type of network
+ */
+enum connman_network_type connman_network_get_type(
+				struct connman_network *network)
+{
+	return network->type;
+}
+
+/**
+ * connman_network_get_identifier:
+ * @network: network structure
+ *
+ * Get identifier of network
+ */
+const char *connman_network_get_identifier(struct connman_network *network)
+{
+	return network->identifier;
+}
+
+/**
+ * connman_network_set_index:
+ * @network: network structure
+ * @index: index number
+ *
+ * Set index number of network
+ */
+void connman_network_set_index(struct connman_network *network, int index)
+{
+	struct connman_service *service;
+	struct connman_ipconfig *ipconfig;
+
+	service = connman_service_lookup_from_network(network);
+	if (!service)
+		goto done;
+
+	ipconfig = __connman_service_get_ip4config(service);
+	if (ipconfig) {
+		/* If index changed, the index of ipconfig must be reset. */
+		__connman_ipconfig_set_index(ipconfig, index);
+		DBG("index %d service %p ip4config %p", network->index,
+			service, ipconfig);
+	}
+
+	ipconfig = __connman_service_get_ip6config(service);
+	if (ipconfig) {
+		__connman_ipconfig_set_index(ipconfig, index);
+
+		DBG("index %d service %p ip6config %p", network->index,
+			service, ipconfig);
+	}
+
+done:
+	network->index = index;
+}
+
+/**
+ * connman_network_get_index:
+ * @network: network structure
+ *
+ * Get index number of network
+ */
+int connman_network_get_index(struct connman_network *network)
+{
+	return network->index;
+}
+
+/**
+ * connman_network_set_group:
+ * @network: network structure
+ * @group: group name
+ *
+ * Set group name for automatic clustering
+ */
+void connman_network_set_group(struct connman_network *network,
+							const char *group)
+{
+	switch (network->type) {
+	case CONNMAN_NETWORK_TYPE_UNKNOWN:
+	case CONNMAN_NETWORK_TYPE_VENDOR:
+		return;
+	case CONNMAN_NETWORK_TYPE_ETHERNET:
+	case CONNMAN_NETWORK_TYPE_GADGET:
+	case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
+	case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
+	case CONNMAN_NETWORK_TYPE_CELLULAR:
+	case CONNMAN_NETWORK_TYPE_WIFI:
+	case CONNMAN_NETWORK_TYPE_LOWPAN:
+		break;
+	}
+
+	if (g_strcmp0(network->group, group) == 0) {
+		if (group)
+			__connman_service_update_from_network(network);
+		return;
+	}
+
+	if (network->group) {
+		__connman_service_remove_from_network(network);
+
+		g_free(network->group);
+	}
+
+	network->group = g_strdup(group);
+
+	if (network->group)
+		network_probe(network);
+}
+
+/**
+ * connman_network_get_group:
+ * @network: network structure
+ *
+ * Get group name for automatic clustering
+ */
+const char *connman_network_get_group(struct connman_network *network)
+{
+	return network->group;
+}
+
+const char *__connman_network_get_ident(struct connman_network *network)
+{
+	if (!network->device)
+		return NULL;
+
+	return connman_device_get_ident(network->device);
+}
+
+bool __connman_network_get_weakness(struct connman_network *network)
+{
+	switch (network->type) {
+	case CONNMAN_NETWORK_TYPE_UNKNOWN:
+	case CONNMAN_NETWORK_TYPE_VENDOR:
+	case CONNMAN_NETWORK_TYPE_ETHERNET:
+	case CONNMAN_NETWORK_TYPE_GADGET:
+	case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
+	case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
+	case CONNMAN_NETWORK_TYPE_CELLULAR:
+	case CONNMAN_NETWORK_TYPE_LOWPAN:
+		break;
+	case CONNMAN_NETWORK_TYPE_WIFI:
+		if (network->strength > 0 && network->strength < 20)
+			return true;
+		break;
+	}
+
+	return false;
+}
+
+bool connman_network_get_connecting(struct connman_network *network)
+{
+	return network->connecting;
+}
+
+/**
+ * connman_network_set_available:
+ * @network: network structure
+ * @available: availability state
+ *
+ * Change availability state of network (in range)
+ */
+int connman_network_set_available(struct connman_network *network,
+						bool available)
+{
+	DBG("network %p available %d", network, available);
+
+	if (network->available == available)
+		return -EALREADY;
+
+	network->available = available;
+
+	return 0;
+}
+
+/**
+ * connman_network_get_available:
+ * @network: network structure
+ *
+ * Get network available setting
+ */
+bool connman_network_get_available(struct connman_network *network)
+{
+	return network->available;
+}
+
+/**
+ * connman_network_set_associating:
+ * @network: network structure
+ * @associating: associating state
+ *
+ * Change associating state of network
+ */
+int connman_network_set_associating(struct connman_network *network,
+						bool associating)
+{
+	DBG("network %p associating %d", network, associating);
+
+	if (network->associating == associating)
+		return -EALREADY;
+
+	network->associating = associating;
+
+	if (associating) {
+		struct connman_service *service;
+
+		service = connman_service_lookup_from_network(network);
+		__connman_service_ipconfig_indicate_state(service,
+					CONNMAN_SERVICE_STATE_ASSOCIATION,
+					CONNMAN_IPCONFIG_TYPE_IPV4);
+		__connman_service_ipconfig_indicate_state(service,
+					CONNMAN_SERVICE_STATE_ASSOCIATION,
+					CONNMAN_IPCONFIG_TYPE_IPV6);
+	}
+
+	return 0;
+}
+
+static void set_associate_error(struct connman_network *network)
+{
+	struct connman_service *service;
+
+	service = connman_service_lookup_from_network(network);
+
+	__connman_service_indicate_error(service,
+					CONNMAN_SERVICE_ERROR_CONNECT_FAILED);
+}
+
+static void set_configure_error(struct connman_network *network)
+{
+	struct connman_service *service;
+
+	service = connman_service_lookup_from_network(network);
+
+	__connman_service_indicate_error(service,
+					CONNMAN_SERVICE_ERROR_CONNECT_FAILED);
+}
+
+static void set_invalid_key_error(struct connman_network *network)
+{
+	struct connman_service *service;
+
+	service = connman_service_lookup_from_network(network);
+
+	__connman_service_indicate_error(service,
+					CONNMAN_SERVICE_ERROR_INVALID_KEY);
+}
+
+static void set_connect_error(struct connman_network *network)
+{
+	struct connman_service *service;
+
+	service = connman_service_lookup_from_network(network);
+
+	__connman_service_indicate_error(service,
+					CONNMAN_SERVICE_ERROR_CONNECT_FAILED);
+}
+
+void connman_network_set_ipv4_method(struct connman_network *network,
+					enum connman_ipconfig_method method)
+{
+	struct connman_service *service;
+	struct connman_ipconfig *ipconfig;
+
+	service = connman_service_lookup_from_network(network);
+	if (!service)
+		return;
+
+	ipconfig = __connman_service_get_ip4config(service);
+	if (!ipconfig)
+		return;
+
+	__connman_ipconfig_set_method(ipconfig, method);
+}
+
+void connman_network_set_ipv6_method(struct connman_network *network,
+					enum connman_ipconfig_method method)
+{
+	struct connman_service *service;
+	struct connman_ipconfig *ipconfig;
+
+	service = connman_service_lookup_from_network(network);
+	if (!service)
+		return;
+
+	ipconfig = __connman_service_get_ip6config(service);
+	if (!ipconfig)
+		return;
+
+	__connman_ipconfig_set_method(ipconfig, method);
+}
+
+void connman_network_set_error(struct connman_network *network,
+					enum connman_network_error error)
+{
+	DBG("network %p error %d", network, error);
+
+	network->connecting = false;
+	network->associating = false;
+
+	switch (error) {
+	case CONNMAN_NETWORK_ERROR_UNKNOWN:
+		return;
+	case CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL:
+		set_associate_error(network);
+		break;
+	case CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL:
+		set_configure_error(network);
+		break;
+	case CONNMAN_NETWORK_ERROR_INVALID_KEY:
+		set_invalid_key_error(network);
+		break;
+	case CONNMAN_NETWORK_ERROR_CONNECT_FAIL:
+		set_connect_error(network);
+		break;
+	}
+
+	network_change(network);
+}
+
+/**
+ * connman_network_set_connected:
+ * @network: network structure
+ * @connected: connected state
+ *
+ * Change connected state of network
+ */
+int connman_network_set_connected(struct connman_network *network,
+						bool connected)
+{
+	DBG("network %p connected %d/%d connecting %d associating %d",
+		network, network->connected, connected, network->connecting,
+		network->associating);
+
+	if ((network->connecting || network->associating) &&
+							!connected) {
+		connman_network_set_error(network,
+					CONNMAN_NETWORK_ERROR_CONNECT_FAIL);
+		if (__connman_network_disconnect(network, FALSE) == 0)
+			return 0;
+	}
+
+	if (network->connected == connected)
+		return -EALREADY;
+
+	if (!connected)
+		set_disconnected(network);
+	else
+		set_connected(network);
+
+	return 0;
+}
+
+/**
+ * connman_network_get_connected:
+ * @network: network structure
+ *
+ * Get network connection status
+ */
+bool connman_network_get_connected(struct connman_network *network)
+{
+	return network->connected;
+}
+
+/**
+ * connman_network_get_associating:
+ * @network: network structure
+ *
+ * Get network associating status
+ */
+bool connman_network_get_associating(struct connman_network *network)
+{
+	return network->associating;
+}
+
+void connman_network_clear_hidden(void *user_data)
+{
+	if (!user_data)
+		return;
+
+	DBG("user_data %p", user_data);
+
+	/*
+	 * Hidden service does not have a connect timeout so
+	 * we do not need to remove it. We can just return
+	 * error to the caller telling that we could not find
+	 * any network that we could connect to.
+	 */
+	connman_dbus_reply_pending(user_data, EIO, NULL);
+}
+
+int connman_network_connect_hidden(struct connman_network *network,
+			char *identity, char *passphrase, void *user_data)
+{
+	int err = 0;
+	struct connman_service *service;
+
+	service = connman_service_lookup_from_network(network);
+
+	DBG("network %p service %p user_data %p", network, service, user_data);
+
+	if (!service)
+		return -EINVAL;
+
+	if (identity)
+		__connman_service_set_agent_identity(service, identity);
+
+	if (passphrase)
+		err = __connman_service_set_passphrase(service, passphrase);
+
+	if (err == -ENOKEY) {
+		__connman_service_indicate_error(service,
+					CONNMAN_SERVICE_ERROR_INVALID_KEY);
+		goto out;
+	} else {
+		__connman_service_set_hidden(service);
+		__connman_service_set_hidden_data(service, user_data);
+		return __connman_service_connect(service,
+					CONNMAN_SERVICE_CONNECT_REASON_USER);
+	}
+
+out:
+	__connman_service_return_error(service, -err, user_data);
+	return err;
+}
+
+/**
+ * __connman_network_connect:
+ * @network: network structure
+ *
+ * Connect network
+ */
+int __connman_network_connect(struct connman_network *network)
+{
+	int err;
+
+	DBG("network %p", network);
+
+	if (network->connected)
+		return -EISCONN;
+
+	if (network->connecting || network->associating)
+		return -EALREADY;
+
+	if (!network->driver) {
+		DBG("network %p assert network->driver == NULL", network);
+		return -EUNATCH;
+	}
+
+	if (!network->driver->connect)
+		return -ENOSYS;
+
+	if (!network->device) {
+		DBG("network %p assert network->device == NULL", network);
+		return -ENODEV;
+	}
+
+	network->connecting = true;
+
+	__connman_device_disconnect(network->device);
+
+	connman_info("Requesting connection to network \"%s\" "
+		"identifier \"%s\".", network->name, network->identifier);
+
+	err = network->driver->connect(network);
+	if (err < 0) {
+		if (err == -EINPROGRESS)
+			connman_network_set_associating(network, true);
+		else
+			network->connecting = false;
+
+		return err;
+	}
+
+	set_connected(network);
+
+	return err;
+}
+
+int
+connman_network_needs_input(struct connman_network *network)
+{
+	struct connman_service *service;
+	int err = -EINVAL;
+
+	if(!network->connecting && !network->associating)
+		goto bail;
+
+	service = connman_service_lookup_from_network(network);
+	if (service == NULL)
+		goto bail;
+
+	network->connecting = FALSE;
+	network->associating = FALSE;
+
+	err = __connman_service_needs_input(service);
+
+bail:
+	return err;
+}
+
+
+/**
+ * __connman_network_disconnect:
+ * @network: network structure
+ *
+ * Disconnect network
+ */
+int __connman_network_disconnect(struct connman_network *network, bool user_initiated)
+{
+	int err = 0;
+
+	DBG("network %p", network);
+
+	if (!network->connected && !network->connecting &&
+						!network->associating)
+		return -ENOTCONN;
+
+	if (!network->driver)
+		return -EUNATCH;
+
+	network->connecting = false;
+
+	if (network->driver->disconnect)
+		err = network->driver->disconnect(network, user_initiated);
+
+	connman_info("Requesting disconnection from network \"%s\" "
+		"identifier \"%s\".", network->name, network->identifier);
+
+	if (err != -EINPROGRESS)
+		set_disconnected(network);
+
+	return err;
+}
+
+int __connman_network_clear_ipconfig(struct connman_network *network,
+					struct connman_ipconfig *ipconfig)
+{
+	struct connman_service *service;
+	struct connman_ipconfig *ipconfig_ipv4;
+	enum connman_ipconfig_method method;
+	enum connman_ipconfig_type type;
+
+	service = connman_service_lookup_from_network(network);
+	if (!service)
+		return -EINVAL;
+
+	ipconfig_ipv4 = __connman_service_get_ip4config(service);
+	method = __connman_ipconfig_get_method(ipconfig);
+	type = __connman_ipconfig_get_config_type(ipconfig);
+
+	switch (method) {
+	case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
+	case CONNMAN_IPCONFIG_METHOD_OFF:
+	case CONNMAN_IPCONFIG_METHOD_FIXED:
+		return -EINVAL;
+	case CONNMAN_IPCONFIG_METHOD_AUTO:
+		release_dhcpv6(network);
+		break;
+	case CONNMAN_IPCONFIG_METHOD_MANUAL:
+		__connman_ipconfig_address_remove(ipconfig);
+		break;
+	case CONNMAN_IPCONFIG_METHOD_DHCP:
+		__connman_dhcp_stop(ipconfig_ipv4);
+		break;
+	}
+
+	if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
+		__connman_service_ipconfig_indicate_state(service,
+					CONNMAN_SERVICE_STATE_CONFIGURATION,
+					CONNMAN_IPCONFIG_TYPE_IPV6);
+	else if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
+		__connman_service_ipconfig_indicate_state(service,
+					CONNMAN_SERVICE_STATE_CONFIGURATION,
+					CONNMAN_IPCONFIG_TYPE_IPV4);
+
+	return 0;
+}
+
+int __connman_network_enable_ipconfig(struct connman_network *network,
+				struct connman_ipconfig *ipconfig)
+{
+	int r = 0;
+	enum connman_ipconfig_type type;
+	enum connman_ipconfig_method method;
+
+	if (!network || !ipconfig)
+		return -EINVAL;
+
+	type = __connman_ipconfig_get_config_type(ipconfig);
+
+	switch (type) {
+	case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
+	case CONNMAN_IPCONFIG_TYPE_ALL:
+		return -ENOSYS;
+
+	case CONNMAN_IPCONFIG_TYPE_IPV6:
+		set_configuration(network, type);
+
+		method = __connman_ipconfig_get_method(ipconfig);
+
+		DBG("ipv6 ipconfig method %d", method);
+
+		switch (method) {
+		case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
+			break;
+
+		case CONNMAN_IPCONFIG_METHOD_OFF:
+			__connman_ipconfig_disable_ipv6(ipconfig);
+			break;
+
+		case CONNMAN_IPCONFIG_METHOD_AUTO:
+			autoconf_ipv6_set(network);
+			break;
+
+		case CONNMAN_IPCONFIG_METHOD_FIXED:
+		case CONNMAN_IPCONFIG_METHOD_MANUAL:
+			r = manual_ipv6_set(network, ipconfig);
+			break;
+
+		case CONNMAN_IPCONFIG_METHOD_DHCP:
+			r = -ENOSYS;
+			break;
+		}
+
+		break;
+
+	case CONNMAN_IPCONFIG_TYPE_IPV4:
+		set_configuration(network, type);
+
+		method = __connman_ipconfig_get_method(ipconfig);
+
+		DBG("ipv4 ipconfig method %d", method);
+
+		switch (method) {
+		case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
+		case CONNMAN_IPCONFIG_METHOD_OFF:
+			break;
+
+		case CONNMAN_IPCONFIG_METHOD_AUTO:
+			r = -ENOSYS;
+			break;
+
+		case CONNMAN_IPCONFIG_METHOD_FIXED:
+		case CONNMAN_IPCONFIG_METHOD_MANUAL:
+			r = set_connected_manual(network);
+			break;
+
+		case CONNMAN_IPCONFIG_METHOD_DHCP:
+			r = set_connected_dhcp(network);
+			break;
+		}
+
+		break;
+	}
+
+	if (r < 0)
+		connman_network_set_error(network,
+					CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
+
+	return r;
+}
+
+int connman_network_set_ipaddress(struct connman_network *network,
+					struct connman_ipaddress *ipaddress)
+{
+	struct connman_service *service;
+	struct connman_ipconfig *ipconfig = NULL;
+
+	DBG("network %p", network);
+
+	service = connman_service_lookup_from_network(network);
+	if (!service)
+		return -EINVAL;
+
+	ipconfig = __connman_service_get_ipconfig(service, ipaddress->family);
+	if (!ipconfig)
+		return -EINVAL;
+
+	__connman_ipconfig_set_local(ipconfig, ipaddress->local);
+	__connman_ipconfig_set_peer(ipconfig, ipaddress->peer);
+	__connman_ipconfig_set_broadcast(ipconfig, ipaddress->broadcast);
+	__connman_ipconfig_set_prefixlen(ipconfig, ipaddress->prefixlen);
+	__connman_ipconfig_set_gateway(ipconfig, ipaddress->gateway);
+
+	return 0;
+}
+
+int connman_network_set_nameservers(struct connman_network *network,
+				const char *nameservers)
+{
+	struct connman_service *service;
+	char **nameservers_array;
+	int i;
+
+	DBG("network %p nameservers %s", network, nameservers);
+
+	service = connman_service_lookup_from_network(network);
+	if (!service)
+		return -EINVAL;
+
+	__connman_service_nameserver_clear(service);
+
+	if (!nameservers)
+		return 0;
+
+	nameservers_array = g_strsplit(nameservers, " ", 0);
+
+	for (i = 0; nameservers_array[i]; i++) {
+		__connman_service_nameserver_append(service,
+						nameservers_array[i], false);
+	}
+
+	g_strfreev(nameservers_array);
+
+	return 0;
+}
+
+int connman_network_set_domain(struct connman_network *network,
+				const char *domain)
+{
+	struct connman_service *service;
+
+	DBG("network %p domain %s", network, domain);
+
+	service = connman_service_lookup_from_network(network);
+	if (!service)
+		return -EINVAL;
+
+	__connman_service_set_domainname(service, domain);
+
+	return 0;
+}
+
+/**
+ * connman_network_set_name:
+ * @network: network structure
+ * @name: name value
+ *
+ * Set display name value for network
+ */
+int connman_network_set_name(struct connman_network *network,
+							const char *name)
+{
+	DBG("network %p name %s", network, name);
+
+	g_free(network->name);
+	network->name = g_strdup(name);
+
+	return 0;
+}
+
+/**
+ * connman_network_set_strength:
+ * @network: network structure
+ * @strength: strength value
+ *
+ * Set signal strength value for network
+ */
+
+int connman_network_set_strength(struct connman_network *network,
+						uint8_t strength)
+{
+	DBG("network %p strengh %d", network, strength);
+
+	network->strength = strength;
+
+	return 0;
+}
+
+uint8_t connman_network_get_strength(struct connman_network *network)
+{
+	return network->strength;
+}
+
+int connman_network_set_frequency(struct connman_network *network,
+						uint16_t frequency)
+{
+	DBG("network %p frequency %d", network, frequency);
+
+	network->frequency = frequency;
+
+	return 0;
+}
+
+uint16_t connman_network_get_frequency(struct connman_network *network)
+{
+	return network->frequency;
+}
+
+int connman_network_set_wifi_channel(struct connman_network *network,
+						uint16_t channel)
+{
+	DBG("network %p wifi channel %d", network, channel);
+
+	network->wifi.channel = channel;
+
+	return 0;
+}
+
+uint16_t connman_network_get_wifi_channel(struct connman_network *network)
+{
+	return network->wifi.channel;
+}
+
+/**
+ * connman_network_set_string:
+ * @network: network structure
+ * @key: unique identifier
+ * @value: string value
+ *
+ * Set string value for specific key
+ */
+int connman_network_set_string(struct connman_network *network,
+					const char *key, const char *value)
+{
+	DBG("network %p key %s value %s", network, key, value);
+
+	if (g_strcmp0(key, "Name") == 0)
+		return connman_network_set_name(network, value);
+
+	if (g_str_equal(key, "Path")) {
+		g_free(network->path);
+		network->path = g_strdup(value);
+	} else if (g_str_equal(key, "Node")) {
+		g_free(network->node);
+		network->node = g_strdup(value);
+	} else if (g_str_equal(key, "WiFi.Mode")) {
+		g_free(network->wifi.mode);
+		network->wifi.mode = g_strdup(value);
+	} else if (g_str_equal(key, "WiFi.Security")) {
+		g_free(network->wifi.security);
+		network->wifi.security = g_strdup(value);
+	} else if (g_str_equal(key, "WiFi.Passphrase")) {
+		g_free(network->wifi.passphrase);
+		network->wifi.passphrase = g_strdup(value);
+	} else if (g_str_equal(key, "WiFi.EAP")) {
+		g_free(network->wifi.eap);
+		network->wifi.eap = g_strdup(value);
+	} else if (g_str_equal(key, "WiFi.Identity")) {
+		g_free(network->wifi.identity);
+		network->wifi.identity = g_strdup(value);
+	} else if (g_str_equal(key, "WiFi.AgentIdentity")) {
+		g_free(network->wifi.agent_identity);
+		network->wifi.agent_identity = g_strdup(value);
+	} else if (g_str_equal(key, "WiFi.CACertFile")) {
+		g_free(network->wifi.ca_cert_path);
+		network->wifi.ca_cert_path = g_strdup(value);
+	} else if (g_str_equal(key, "WiFi.ClientCertFile")) {
+		g_free(network->wifi.client_cert_path);
+		network->wifi.client_cert_path = g_strdup(value);
+	} else if (g_str_equal(key, "WiFi.PrivateKeyFile")) {
+		g_free(network->wifi.private_key_path);
+		network->wifi.private_key_path = g_strdup(value);
+	} else if (g_str_equal(key, "WiFi.PrivateKeyPassphrase")) {
+		g_free(network->wifi.private_key_passphrase);
+		network->wifi.private_key_passphrase = g_strdup(value);
+	} else if (g_str_equal(key, "WiFi.Phase2")) {
+		g_free(network->wifi.phase2_auth);
+		network->wifi.phase2_auth = g_strdup(value);
+	} else if (g_str_equal(key, "WiFi.PinWPS")) {
+		g_free(network->wifi.pin_wps);
+		network->wifi.pin_wps = g_strdup(value);
+	} else if (g_str_equal(key, "LoWPAN.ParentAddress")) {
+		g_free(network->lowpan.parent_address);
+		network->lowpan.parent_address = g_strdup(value);
+	} else {
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+/**
+ * connman_network_get_string:
+ * @network: network structure
+ * @key: unique identifier
+ *
+ * Get string value for specific key
+ */
+const char *connman_network_get_string(struct connman_network *network,
+							const char *key)
+{
+	DBG("network %p key %s", network, key);
+
+	if (g_str_equal(key, "Path"))
+		return network->path;
+	else if (g_str_equal(key, "Name"))
+		return network->name;
+	else if (g_str_equal(key, "Node"))
+		return network->node;
+	else if (g_str_equal(key, "WiFi.Mode"))
+		return network->wifi.mode;
+	else if (g_str_equal(key, "WiFi.Security"))
+		return network->wifi.security;
+	else if (g_str_equal(key, "WiFi.Passphrase"))
+		return network->wifi.passphrase;
+	else if (g_str_equal(key, "WiFi.EAP"))
+		return network->wifi.eap;
+	else if (g_str_equal(key, "WiFi.Identity"))
+		return network->wifi.identity;
+	else if (g_str_equal(key, "WiFi.AgentIdentity"))
+		return network->wifi.agent_identity;
+	else if (g_str_equal(key, "WiFi.CACertFile"))
+		return network->wifi.ca_cert_path;
+	else if (g_str_equal(key, "WiFi.ClientCertFile"))
+		return network->wifi.client_cert_path;
+	else if (g_str_equal(key, "WiFi.PrivateKeyFile"))
+		return network->wifi.private_key_path;
+	else if (g_str_equal(key, "WiFi.PrivateKeyPassphrase"))
+		return network->wifi.private_key_passphrase;
+	else if (g_str_equal(key, "WiFi.Phase2"))
+		return network->wifi.phase2_auth;
+	else if (g_str_equal(key, "WiFi.PinWPS"))
+		return network->wifi.pin_wps;
+	else if (g_str_equal(key, "LoWPAN.ParentAddress"))
+		return network->lowpan.parent_address;
+
+	return NULL;
+}
+
+/**
+ * connman_network_set_bool:
+ * @network: network structure
+ * @key: unique identifier
+ * @value: boolean value
+ *
+ * Set boolean value for specific key
+ */
+int connman_network_set_bool(struct connman_network *network,
+					const char *key, bool value)
+{
+	DBG("network %p key %s value %d", network, key, value);
+
+	if (g_strcmp0(key, "Roaming") == 0)
+		network->roaming = value;
+	else if (g_strcmp0(key, "WiFi.WPS") == 0)
+		network->wifi.wps = value;
+	else if (g_strcmp0(key, "WiFi.UseWPS") == 0)
+		network->wifi.use_wps = value;
+	else if (g_strcmp0(key, "LoWPAN.PermitJoining") == 0)
+		network->lowpan.joining_permitted = value;
+
+	return -EINVAL;
+}
+
+/**
+ * connman_network_get_bool:
+ * @network: network structure
+ * @key: unique identifier
+ *
+ * Get boolean value for specific key
+ */
+bool connman_network_get_bool(struct connman_network *network,
+							const char *key)
+{
+	DBG("network %p key %s", network, key);
+
+	if (g_str_equal(key, "Roaming"))
+		return network->roaming;
+	else if (g_str_equal(key, "WiFi.WPS"))
+		return network->wifi.wps;
+	else if (g_str_equal(key, "WiFi.UseWPS"))
+		return network->wifi.use_wps;
+	else if (g_str_equal(key, "LoWPAN.PermitJoining") == TRUE)
+		return network->lowpan.joining_permitted;
+
+	return false;
+}
+
+/**
+ * connman_network_set_blob:
+ * @network: network structure
+ * @key: unique identifier
+ * @data: blob data
+ * @size: blob size
+ *
+ * Set binary blob value for specific key
+ */
+int connman_network_set_blob(struct connman_network *network,
+			const char *key, const void *data, unsigned int size)
+{
+	DBG("network %p key %s size %d", network, key, size);
+
+	if (g_str_equal(key, "WiFi.SSID")) {
+		g_free(network->wifi.ssid);
+		network->wifi.ssid = g_try_malloc(size);
+		if (network->wifi.ssid) {
+			memcpy(network->wifi.ssid, data, size);
+			network->wifi.ssid_len = size;
+		} else
+			network->wifi.ssid_len = 0;
+	} else {
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+/**
+ * connman_network_get_blob:
+ * @network: network structure
+ * @key: unique identifier
+ * @size: pointer to blob size
+ *
+ * Get binary blob value for specific key
+ */
+const void *connman_network_get_blob(struct connman_network *network,
+					const char *key, unsigned int *size)
+{
+	DBG("network %p key %s", network, key);
+
+	if (g_str_equal(key, "WiFi.SSID")) {
+		if (size)
+			*size = network->wifi.ssid_len;
+		return network->wifi.ssid;
+	}
+
+	return NULL;
+}
+
+void __connman_network_set_device(struct connman_network *network,
+					struct connman_device *device)
+{
+	if (network->device == device)
+		return;
+
+	if (network->device)
+		network_remove(network);
+
+	network->device = device;
+
+	if (network->device)
+		network_probe(network);
+}
+
+/**
+ * connman_network_get_device:
+ * @network: network structure
+ *
+ * Get parent device of network
+ */
+struct connman_device *connman_network_get_device(struct connman_network *network)
+{
+	return network->device;
+}
+
+/**
+ * connman_network_get_data:
+ * @network: network structure
+ *
+ * Get private network data pointer
+ */
+void *connman_network_get_data(struct connman_network *network)
+{
+	return network->driver_data;
+}
+
+/**
+ * connman_network_set_data:
+ * @network: network structure
+ * @data: data pointer
+ *
+ * Set private network data pointer
+ */
+void connman_network_set_data(struct connman_network *network, void *data)
+{
+	network->driver_data = data;
+}
+
+void connman_network_update(struct connman_network *network)
+{
+    DBG("");
+	switch (network->type) {
+	case CONNMAN_NETWORK_TYPE_UNKNOWN:
+	case CONNMAN_NETWORK_TYPE_VENDOR:
+		return;
+	case CONNMAN_NETWORK_TYPE_ETHERNET:
+	case CONNMAN_NETWORK_TYPE_GADGET:
+	case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
+	case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
+	case CONNMAN_NETWORK_TYPE_CELLULAR:
+	case CONNMAN_NETWORK_TYPE_WIFI:
+	case CONNMAN_NETWORK_TYPE_LOWPAN:
+		break;
+	}
+
+	if (network->group)
+		__connman_service_update_from_network(network);
+}
+
+int __connman_network_init(void)
+{
+	DBG("");
+
+	return 0;
+}
+
+void __connman_network_cleanup(void)
+{
+	DBG("");
+}
diff --git a/connman/src/notifier.c b/connman/src/notifier.c
new file mode 100644
index 0000000..9ddd987
--- /dev/null
+++ b/connman/src/notifier.c
@@ -0,0 +1,408 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2013  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 <gdbus.h>
+
+#include "connman.h"
+
+static DBusConnection *connection = NULL;
+
+static GSList *notifier_list = NULL;
+static GHashTable *service_hash = NULL;
+
+static const char *notifier_state;
+
+static gint compare_priority(gconstpointer a, gconstpointer b)
+{
+	const struct connman_notifier *notifier1 = a;
+	const struct connman_notifier *notifier2 = b;
+
+	return notifier2->priority - notifier1->priority;
+}
+
+/**
+ * connman_notifier_register:
+ * @notifier: notifier module
+ *
+ * Register a new notifier module
+ *
+ * Returns: %0 on success
+ */
+int connman_notifier_register(struct connman_notifier *notifier)
+{
+	DBG("notifier %p name %s", notifier, notifier->name);
+
+	notifier_list = g_slist_insert_sorted(notifier_list, notifier,
+							compare_priority);
+
+	return 0;
+}
+
+/**
+ * connman_notifier_unregister:
+ * @notifier: notifier module
+ *
+ * Remove a previously registered notifier module
+ */
+void connman_notifier_unregister(struct connman_notifier *notifier)
+{
+	DBG("notifier %p name %s", notifier, notifier->name);
+
+	notifier_list = g_slist_remove(notifier_list, notifier);
+}
+
+static int connected[MAX_CONNMAN_SERVICE_TYPES];
+static int online[MAX_CONNMAN_SERVICE_TYPES];
+
+static bool notifier_is_online(void)
+{
+	unsigned int i;
+
+	__sync_synchronize();
+	for (i = 0; i < MAX_CONNMAN_SERVICE_TYPES; i++) {
+		if (online[i] > 0)
+			return true;
+	}
+
+	return false;
+}
+
+bool __connman_notifier_is_connected(void)
+{
+	unsigned int i;
+
+	__sync_synchronize();
+	for (i = 0; i < MAX_CONNMAN_SERVICE_TYPES; i++) {
+		if (connected[i] > 0)
+			return true;
+	}
+
+	return false;
+}
+
+static const char *evaluate_notifier_state(void)
+{
+	if (notifier_is_online())
+		return "online";
+
+	if (__connman_notifier_is_connected())
+		return "ready";
+
+	if (__connman_technology_get_offlinemode())
+		return "offline";
+
+	return "idle";
+}
+
+const char *__connman_notifier_get_state(void)
+{
+	return notifier_state;
+}
+
+static void state_changed(void)
+{
+	const char *state;
+
+	state = evaluate_notifier_state();
+
+	if (g_strcmp0(state, notifier_state) == 0)
+		return;
+
+	notifier_state = state;
+
+	connman_dbus_property_changed_basic(CONNMAN_MANAGER_PATH,
+				CONNMAN_MANAGER_INTERFACE, "State",
+					DBUS_TYPE_STRING, &notifier_state);
+}
+
+void __connman_notifier_connect(enum connman_service_type type)
+{
+	DBG("type %d", type);
+
+	switch (type) {
+	case CONNMAN_SERVICE_TYPE_UNKNOWN:
+	case CONNMAN_SERVICE_TYPE_SYSTEM:
+	case CONNMAN_SERVICE_TYPE_GPS:
+	case CONNMAN_SERVICE_TYPE_VPN:
+		return;
+	case CONNMAN_SERVICE_TYPE_ETHERNET:
+	case CONNMAN_SERVICE_TYPE_GADGET:
+	case CONNMAN_SERVICE_TYPE_WIFI:
+	case CONNMAN_SERVICE_TYPE_BLUETOOTH:
+	case CONNMAN_SERVICE_TYPE_CELLULAR:
+	case CONNMAN_SERVICE_TYPE_LOWPAN:
+	case CONNMAN_SERVICE_TYPE_P2P:
+		break;
+	}
+
+	if (__sync_fetch_and_add(&connected[type], 1) == 0) {
+		__connman_technology_set_connected(type, true);
+		state_changed();
+	}
+}
+
+void __connman_notifier_enter_online(enum connman_service_type type)
+{
+	DBG("type %d", type);
+
+	if (__sync_fetch_and_add(&online[type], 1) == 0)
+		state_changed();
+}
+
+void __connman_notifier_leave_online(enum connman_service_type type)
+{
+	DBG("type %d", type);
+
+	if (__sync_fetch_and_sub(&online[type], 1) == 1)
+		state_changed();
+}
+
+void __connman_notifier_disconnect(enum connman_service_type type)
+{
+	DBG("type %d", type);
+
+	__sync_synchronize();
+	if (connected[type] == 0) {
+		connman_error("notifier disconnect underflow");
+		return;
+	}
+
+	switch (type) {
+	case CONNMAN_SERVICE_TYPE_UNKNOWN:
+	case CONNMAN_SERVICE_TYPE_SYSTEM:
+	case CONNMAN_SERVICE_TYPE_GPS:
+	case CONNMAN_SERVICE_TYPE_VPN:
+		return;
+	case CONNMAN_SERVICE_TYPE_ETHERNET:
+	case CONNMAN_SERVICE_TYPE_GADGET:
+	case CONNMAN_SERVICE_TYPE_WIFI:
+	case CONNMAN_SERVICE_TYPE_BLUETOOTH:
+	case CONNMAN_SERVICE_TYPE_CELLULAR:
+	case CONNMAN_SERVICE_TYPE_LOWPAN:
+	case CONNMAN_SERVICE_TYPE_P2P:
+		break;
+	}
+
+	if (__sync_fetch_and_sub(&connected[type], 1) != 1)
+		return;
+
+	__connman_technology_set_connected(type, false);
+	state_changed();
+}
+
+void __connman_notifier_default_changed(struct connman_service *service)
+{
+	GSList *list;
+
+	for (list = notifier_list; list; list = list->next) {
+		struct connman_notifier *notifier = list->data;
+
+		if (notifier->default_changed)
+			notifier->default_changed(service);
+	}
+}
+
+void __connman_notifier_service_add(struct connman_service *service,
+					const char *name)
+{
+	GSList *list;
+
+	for (list = notifier_list; list; list = list->next) {
+		struct connman_notifier *notifier = list->data;
+
+		if (notifier->service_add)
+			notifier->service_add(service, name);
+	}
+}
+
+void __connman_notifier_service_remove(struct connman_service *service)
+{
+	GSList *list;
+
+	if (g_hash_table_lookup(service_hash, service)) {
+		/*
+		 * This is a tempory check for consistency. It can be
+		 * removed when there are no reports for the following
+		 * error message.
+		 */
+		connman_error("Service state machine inconsistency detected.");
+
+		g_hash_table_remove(service_hash, service);
+	}
+
+	for (list = notifier_list; list; list = list->next) {
+		struct connman_notifier *notifier = list->data;
+
+		if (notifier->service_remove)
+			notifier->service_remove(service);
+	}
+}
+
+void __connman_notifier_proxy_changed(struct connman_service *service)
+{
+	GSList *list;
+
+	for (list = notifier_list; list; list = list->next) {
+		struct connman_notifier *notifier = list->data;
+
+		if (notifier->proxy_changed)
+			notifier->proxy_changed(service);
+	}
+}
+
+static void offlinemode_changed(dbus_bool_t enabled)
+{
+	DBG("enabled %d", enabled);
+
+	connman_dbus_property_changed_basic(CONNMAN_MANAGER_PATH,
+				CONNMAN_MANAGER_INTERFACE, "OfflineMode",
+						DBUS_TYPE_BOOLEAN, &enabled);
+}
+
+void __connman_notifier_offlinemode(bool enabled)
+{
+	GSList *list;
+
+	DBG("enabled %d", enabled);
+
+	offlinemode_changed(enabled);
+	state_changed();
+
+	for (list = notifier_list; list; list = list->next) {
+		struct connman_notifier *notifier = list->data;
+
+		if (notifier->offline_mode)
+			notifier->offline_mode(enabled);
+	}
+}
+
+static void notify_idle_state(bool idle)
+{
+	GSList *list;
+
+	DBG("idle %d", idle);
+
+	for (list = notifier_list; list; list = list->next) {
+		struct connman_notifier *notifier = list->data;
+
+		if (notifier->idle_state)
+			notifier->idle_state(idle);
+	}
+}
+
+void __connman_notifier_service_state_changed(struct connman_service *service,
+					enum connman_service_state state)
+{
+	GSList *list;
+	unsigned int old_size;
+	bool found;
+
+	for (list = notifier_list; list; list = list->next) {
+		struct connman_notifier *notifier = list->data;
+
+		if (notifier->service_state_changed)
+			notifier->service_state_changed(service, state);
+	}
+
+	old_size = g_hash_table_size(service_hash);
+	found = g_hash_table_lookup(service_hash, service);
+
+	switch (state) {
+	case CONNMAN_SERVICE_STATE_UNKNOWN:
+	case CONNMAN_SERVICE_STATE_FAILURE:
+	case CONNMAN_SERVICE_STATE_DISCONNECT:
+	case CONNMAN_SERVICE_STATE_IDLE:
+		if (!found)
+			break;
+
+		g_hash_table_remove(service_hash, service);
+		if (old_size == 1)
+			notify_idle_state(true);
+
+		break;
+	case CONNMAN_SERVICE_STATE_ASSOCIATION:
+	case CONNMAN_SERVICE_STATE_CONFIGURATION:
+	case CONNMAN_SERVICE_STATE_READY:
+	case CONNMAN_SERVICE_STATE_ONLINE:
+		if (found)
+			break;
+
+		g_hash_table_insert(service_hash, service, service);
+		if (old_size == 0)
+			notify_idle_state(false);
+
+		break;
+	}
+}
+
+void __connman_notifier_ipconfig_changed(struct connman_service *service,
+					struct connman_ipconfig *ipconfig)
+{
+	GSList *list;
+
+	for (list = notifier_list; list; list = list->next) {
+		struct connman_notifier *notifier = list->data;
+
+		if (notifier->ipconfig_changed)
+			notifier->ipconfig_changed(service, ipconfig);
+	}
+}
+
+void __connman_notifier_sleep_event(void *identifier, bool canSleep, time_t valid_until)
+{
+	GSList *list;
+
+	for (list = notifier_list; list; list = list->next) {
+		struct connman_notifier *notifier = list->data;
+
+		if (notifier->sleep_event)
+			notifier->sleep_event(identifier, canSleep, valid_until);
+	}
+}
+
+
+int __connman_notifier_init(void)
+{
+	DBG("");
+
+	connection = connman_dbus_get_connection();
+
+	service_hash = g_hash_table_new_full(g_direct_hash, g_direct_equal,
+						NULL, NULL);
+
+	notifier_state = evaluate_notifier_state();
+
+	return 0;
+}
+
+void __connman_notifier_cleanup(void)
+{
+	DBG("");
+
+	g_hash_table_destroy(service_hash);
+	service_hash = NULL;
+
+	dbus_connection_unref(connection);
+}
diff --git a/connman/src/ntp.c b/connman/src/ntp.c
new file mode 100644
index 0000000..3250959
--- /dev/null
+++ b/connman/src/ntp.c
@@ -0,0 +1,608 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2014  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
+
+#define _GNU_SOURCE
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/time.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netinet/ip.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+
+#include <glib.h>
+
+#include "connman.h"
+
+struct ntp_short {
+	uint16_t seconds;
+	uint16_t fraction;
+} __attribute__ ((packed));
+
+struct ntp_time {
+	uint32_t seconds;
+	uint32_t fraction;
+} __attribute__ ((packed));
+
+struct ntp_msg {
+	uint8_t flags;			/* Mode, version and leap indicator */
+	uint8_t stratum;		/* Stratum details */
+	int8_t poll;			/* Maximum interval in log2 seconds */
+	int8_t precision;		/* Clock precision in log2 seconds */
+	struct ntp_short rootdelay;	/* Root delay */
+	struct ntp_short rootdisp;	/* Root dispersion */
+	uint32_t refid;			/* Reference ID */
+	struct ntp_time reftime;	/* Reference timestamp */
+	struct ntp_time orgtime;	/* Origin timestamp */
+	struct ntp_time rectime;	/* Receive timestamp */
+	struct ntp_time xmttime;	/* Transmit timestamp */
+} __attribute__ ((packed));
+
+#define OFFSET_1900_1970  2208988800UL	/* 1970 - 1900 in seconds */
+
+#define STEPTIME_MIN_OFFSET  0.128
+
+#define LOGTOD(a)  ((a) < 0 ? 1. / (1L << -(a)) : 1L << (int)(a))
+
+#define NTP_SEND_TIMEOUT       2
+#define NTP_SEND_RETRIES       3
+
+#define NTP_FLAG_LI_SHIFT      6
+#define NTP_FLAG_LI_MASK       0x3
+#define NTP_FLAG_LI_NOWARNING  0x0
+#define NTP_FLAG_LI_ADDSECOND  0x1
+#define NTP_FLAG_LI_DELSECOND  0x2
+#define NTP_FLAG_LI_NOTINSYNC  0x3
+
+#define NTP_FLAG_VN_SHIFT      3
+#define NTP_FLAG_VN_MASK       0x7
+
+#define NTP_FLAG_MD_SHIFT      0
+#define NTP_FLAG_MD_MASK       0x7
+#define NTP_FLAG_MD_UNSPEC     0
+#define NTP_FLAG_MD_ACTIVE     1
+#define NTP_FLAG_MD_PASSIVE    2
+#define NTP_FLAG_MD_CLIENT     3
+#define NTP_FLAG_MD_SERVER     4
+#define NTP_FLAG_MD_BROADCAST  5
+#define NTP_FLAG_MD_CONTROL    6
+#define NTP_FLAG_MD_PRIVATE    7
+
+#define NTP_FLAG_VN_VER3       3
+#define NTP_FLAG_VN_VER4       4
+
+#define NTP_FLAGS_ENCODE(li, vn, md)  ((uint8_t)( \
+                      (((li) & NTP_FLAG_LI_MASK) << NTP_FLAG_LI_SHIFT) | \
+                      (((vn) & NTP_FLAG_VN_MASK) << NTP_FLAG_VN_SHIFT) | \
+                      (((md) & NTP_FLAG_MD_MASK) << NTP_FLAG_MD_SHIFT)))
+
+#define NTP_FLAGS_LI_DECODE(flags)    ((uint8_t)(((flags) >> NTP_FLAG_LI_SHIFT) & NTP_FLAG_LI_MASK))
+#define NTP_FLAGS_VN_DECODE(flags)    ((uint8_t)(((flags) >> NTP_FLAG_VN_SHIFT) & NTP_FLAG_VN_MASK))
+#define NTP_FLAGS_MD_DECODE(flags)    ((uint8_t)(((flags) >> NTP_FLAG_MD_SHIFT) & NTP_FLAG_MD_MASK))
+
+#define NTP_PRECISION_S    0
+#define NTP_PRECISION_DS   -3
+#define NTP_PRECISION_CS   -6
+#define NTP_PRECISION_MS   -9
+#define NTP_PRECISION_US   -19
+#define NTP_PRECISION_NS   -29
+
+static guint channel_watch = 0;
+static struct timespec mtx_time;
+static int transmit_fd = 0;
+
+static char *timeserver = NULL;
+static struct sockaddr_storage timeserver_addr;
+static gint poll_id = 0;
+static gint timeout_id = 0;
+static guint retries = 0;
+
+static void send_packet(int fd, const char *server, uint32_t timeout, int family);
+
+static void next_server(void)
+{
+	if (timeserver) {
+		g_free(timeserver);
+		timeserver = NULL;
+	}
+
+	__connman_timeserver_sync_next();
+}
+
+static gboolean send_timeout(gpointer user_data)
+{
+	uint32_t timeout = GPOINTER_TO_UINT(user_data);
+
+	DBG("send timeout %u (retries %d)", timeout, retries);
+
+	if (retries++ == NTP_SEND_RETRIES)
+		next_server();
+	else
+		send_packet(transmit_fd, timeserver, timeout << 1, timeserver_addr.ss_family);
+
+	return FALSE;
+}
+
+static void send_packet(int fd, const char *server, uint32_t timeout, int family)
+{
+	struct ntp_msg msg;
+	struct sockaddr_in in4addr;
+	struct sockaddr_in6 in6addr;
+	struct sockaddr * addr;
+	struct timeval transmit_timeval;
+	ssize_t len;
+	int size;
+	unsigned char * addrptr;
+
+	/*
+	 * At some point, we could specify the actual system precision with:
+	 *
+	 *   clock_getres(CLOCK_REALTIME, &ts);
+	 *   msg.precision = (int)log2(ts.tv_sec + (ts.tv_nsec * 1.0e-9));
+	 */
+	memset(&msg, 0, sizeof(msg));
+	msg.flags = NTP_FLAGS_ENCODE(NTP_FLAG_LI_NOTINSYNC, NTP_FLAG_VN_VER4,
+	    NTP_FLAG_MD_CLIENT);
+	msg.poll = 4;	// min
+	msg.poll = 10;	// max
+	msg.precision = NTP_PRECISION_S;
+
+	if (family == AF_INET) {
+		memset(&in4addr, 0, sizeof(in4addr));
+		in4addr.sin_family = AF_INET;
+		in4addr.sin_port = htons(123);
+		size = sizeof(in4addr);
+		addrptr = (unsigned char *)&in4addr.sin_addr.s_addr;
+		addr = (struct sockaddr *)&in4addr;
+	} else if (family == AF_INET6){
+		memset(&in6addr, 0, sizeof(in6addr));
+		in6addr.sin6_family = AF_INET6;
+		in6addr.sin6_port = htons(123);
+		size = sizeof(in6addr);
+		addrptr = in6addr.sin6_addr.__in6_u.__u6_addr8;
+		addr = (struct sockaddr *)&in6addr;
+	} else {
+		DBG("wrong family type");
+		return;
+	}
+	if (inet_pton(family, server, addrptr) == 0)
+	{
+		DBG("cannot convert ip address string");
+		return;
+	}
+
+	gettimeofday(&transmit_timeval, NULL);
+	clock_gettime(CLOCK_MONOTONIC, &mtx_time);
+
+	msg.xmttime.seconds = htonl(transmit_timeval.tv_sec + OFFSET_1900_1970);
+	msg.xmttime.fraction = htonl(transmit_timeval.tv_usec * 1000);
+
+	len = sendto(fd, &msg, sizeof(msg), MSG_DONTWAIT,
+						addr, size);
+	if (len < 0) {
+		connman_error("Time request for server %s failed (%d/%s)",
+			server, errno, strerror(errno));
+
+		if (errno == ENETUNREACH)
+			__connman_timeserver_sync_next();
+
+		return;
+	}
+
+	if (len != sizeof(msg)) {
+		connman_error("Broken time request for server %s", server);
+		return;
+	}
+
+	/*
+	 * Add an exponential retry timeout to retry the existing
+	 * request. After a set number of retries, we'll fallback to
+	 * trying another server.
+	 */
+
+	timeout_id = g_timeout_add_seconds(timeout, send_timeout,
+					GUINT_TO_POINTER(timeout));
+}
+
+static gboolean next_poll(gpointer user_data)
+{
+	poll_id = 0;
+
+	if (!timeserver || transmit_fd == 0)
+		return FALSE;
+
+	send_packet(transmit_fd, timeserver, NTP_SEND_TIMEOUT, timeserver_addr.ss_family);
+
+	return FALSE;
+}
+
+static void reset_timeout(void)
+{
+	if (timeout_id > 0) {
+		g_source_remove(timeout_id);
+		timeout_id = 0;
+	}
+
+	retries = 0;
+}
+
+static void decode_msg(void *base, size_t len, struct timeval *tv,
+		struct timespec *mrx_time)
+{
+	struct ntp_msg *msg = base;
+	double m_delta, org, rec, xmt, dst;
+	double delay, offset;
+	static guint transmit_delay;
+
+	if (len < sizeof(*msg)) {
+		connman_error("Invalid response from time server");
+		return;
+	}
+
+	if (!tv) {
+		connman_error("Invalid packet timestamp from time server");
+		return;
+	}
+
+	DBG("flags      : 0x%02x", msg->flags);
+	DBG("stratum    : %u", msg->stratum);
+	DBG("poll       : %f seconds (%d)",
+				LOGTOD(msg->poll), msg->poll);
+	DBG("precision  : %f seconds (%d)",
+				LOGTOD(msg->precision), msg->precision);
+	DBG("root delay : %u seconds (fraction %u)",
+			msg->rootdelay.seconds, msg->rootdelay.fraction);
+	DBG("root disp. : %u seconds (fraction %u)",
+			msg->rootdisp.seconds, msg->rootdisp.fraction);
+	DBG("reference  : 0x%04x", msg->refid);
+
+	if (!msg->stratum) {
+		/* RFC 4330 ch 8 Kiss-of-Death packet */
+		uint32_t code = ntohl(msg->refid);
+
+		connman_info("Skipping server %s KoD code %c%c%c%c",
+			timeserver, code >> 24, code >> 16 & 0xff,
+			code >> 8 & 0xff, code & 0xff);
+		next_server();
+		return;
+	}
+
+	transmit_delay = LOGTOD(msg->poll);
+
+	if (NTP_FLAGS_LI_DECODE(msg->flags) == NTP_FLAG_LI_NOTINSYNC) {
+		DBG("ignoring unsynchronized peer");
+		return;
+	}
+
+
+	if (NTP_FLAGS_VN_DECODE(msg->flags) != NTP_FLAG_VN_VER4) {
+		if (NTP_FLAGS_VN_DECODE(msg->flags) == NTP_FLAG_VN_VER3) {
+			DBG("requested version %d, accepting version %d",
+				NTP_FLAG_VN_VER4, NTP_FLAGS_VN_DECODE(msg->flags));
+		} else {
+			DBG("unsupported version %d", NTP_FLAGS_VN_DECODE(msg->flags));
+			return;
+		}
+	}
+
+	if (NTP_FLAGS_MD_DECODE(msg->flags) != NTP_FLAG_MD_SERVER) {
+		DBG("unsupported mode %d", NTP_FLAGS_MD_DECODE(msg->flags));
+		return;
+	}
+
+	m_delta = mrx_time->tv_sec - mtx_time.tv_sec +
+		1.0e-9 * (mrx_time->tv_nsec - mtx_time.tv_nsec);
+
+	org = tv->tv_sec + (1.0e-6 * tv->tv_usec) - m_delta + OFFSET_1900_1970;
+	rec = ntohl(msg->rectime.seconds) +
+			((double) ntohl(msg->rectime.fraction) / UINT_MAX);
+	xmt = ntohl(msg->xmttime.seconds) +
+			((double) ntohl(msg->xmttime.fraction) / UINT_MAX);
+	dst = tv->tv_sec + (1.0e-6 * tv->tv_usec) + OFFSET_1900_1970;
+
+	DBG("org=%f rec=%f xmt=%f dst=%f", org, rec, xmt, dst);
+
+	offset = ((rec - org) + (xmt - dst)) / 2;
+	delay = (dst - org) - (xmt - rec);
+
+	DBG("offset=%f delay=%f", offset, delay);
+
+	/* Remove the timeout, as timeserver has responded */
+
+	reset_timeout();
+
+	/*
+	 * Now poll the server every transmit_delay seconds
+	 * for time correction.
+	 */
+	if (poll_id > 0)
+		g_source_remove(poll_id);
+
+	DBG("Timeserver %s, next sync in %d seconds", timeserver, transmit_delay);
+
+	poll_id = g_timeout_add_seconds(transmit_delay, next_poll, NULL);
+
+	connman_info("ntp: time slew %+.6f s", offset);
+
+	if (offset < STEPTIME_MIN_OFFSET && offset > -STEPTIME_MIN_OFFSET) {
+		struct timeval adj;
+
+		adj.tv_sec = (long) offset;
+		adj.tv_usec = (offset - adj.tv_sec) * 1000000;
+
+		DBG("adjusting time");
+
+		if (adjtime(&adj, &adj) < 0) {
+			connman_error("Failed to adjust time");
+			return;
+		}
+
+		DBG("%lu seconds, %lu msecs", adj.tv_sec, adj.tv_usec);
+	} else {
+		struct timeval cur;
+		double dtime;
+
+		gettimeofday(&cur, NULL);
+		dtime = offset + cur.tv_sec + 1.0e-6 * cur.tv_usec;
+		cur.tv_sec = (long) dtime;
+		cur.tv_usec = (dtime - cur.tv_sec) * 1000000;
+
+		DBG("setting time");
+
+		if (settimeofday(&cur, NULL) < 0) {
+			connman_error("Failed to set time");
+			return;
+		}
+
+		DBG("%lu seconds, %lu msecs", cur.tv_sec, cur.tv_usec);
+	}
+}
+
+static gboolean received_data(GIOChannel *channel, GIOCondition condition,
+							gpointer user_data)
+{
+	unsigned char buf[128];
+	struct sockaddr_storage sender_addr;
+	struct msghdr msg;
+	struct iovec iov;
+	struct cmsghdr *cmsg;
+	struct timeval *tv;
+	struct timespec mrx_time;
+	char aux[128];
+	ssize_t len;
+	int fd;
+
+	if (condition & (G_IO_HUP | G_IO_ERR | G_IO_NVAL)) {
+		connman_error("Problem with timer server channel");
+		channel_watch = 0;
+		return FALSE;
+	}
+
+	fd = g_io_channel_unix_get_fd(channel);
+
+	iov.iov_base = buf;
+	iov.iov_len = sizeof(buf);
+
+	memset(&msg, 0, sizeof(msg));
+	msg.msg_iov = &iov;
+	msg.msg_iovlen = 1;
+	msg.msg_control = aux;
+	msg.msg_controllen = sizeof(aux);
+	msg.msg_name = &sender_addr;
+	msg.msg_namelen = sizeof(sender_addr);
+
+	len = recvmsg(fd, &msg, MSG_DONTWAIT);
+	if (len < 0)
+		return TRUE;
+
+	if (sender_addr.ss_family == AF_INET) {
+		if (((struct sockaddr_in *)&timeserver_addr)->sin_addr.s_addr != ((struct sockaddr_in *)&sender_addr)->sin_addr.s_addr)
+			return TRUE;
+	} else if(sender_addr.ss_family == AF_INET6) {
+		if (memcmp(((struct sockaddr_in6 *)&timeserver_addr)->sin6_addr.__in6_u.__u6_addr8,
+					((struct sockaddr_in6 *)&sender_addr)->sin6_addr.__in6_u.__u6_addr8,
+					16) != 0)
+			return TRUE;
+	} else {
+		connman_error("Not a valid family type");
+		return TRUE;
+        }
+
+	tv = NULL;
+	clock_gettime(CLOCK_MONOTONIC, &mrx_time);
+
+	for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) {
+		if (cmsg->cmsg_level != SOL_SOCKET)
+			continue;
+
+		switch (cmsg->cmsg_type) {
+		case SCM_TIMESTAMP:
+			tv = (struct timeval *) CMSG_DATA(cmsg);
+			break;
+		}
+	}
+
+	decode_msg(iov.iov_base, iov.iov_len, tv, &mrx_time);
+
+	return TRUE;
+}
+
+static void start_ntp(char *server, int family)
+{
+	GIOChannel *channel;
+	struct sockaddr * addr;
+	struct sockaddr_in in4addr;
+	struct sockaddr_in6 in6addr;
+	int tos = IPTOS_LOWDELAY, timestamp = 1;
+	int size;
+
+	if (!server)
+		return;
+
+	DBG("server %s family %d", server, family);
+
+	if (channel_watch > 0)
+		goto send;
+
+	transmit_fd = socket(family, SOCK_DGRAM | SOCK_CLOEXEC, 0);
+	if (transmit_fd <= 0) {
+		connman_error("Failed to open time server socket");
+		return;
+	}
+
+	if (family == AF_INET) {
+		memset(&in4addr, 0, sizeof(in4addr));
+		in4addr.sin_family = family;
+		addr = (struct sockaddr *)&in4addr;
+		size = sizeof(in4addr);
+	} else if (family == AF_INET6) {
+		memset(&in6addr, 0, sizeof(in6addr));
+		in6addr.sin6_family = family;
+		addr = (struct sockaddr *)&in6addr;
+		size = sizeof(in6addr);
+	} else {
+		connman_error("Family not correct");
+		return;
+	}
+
+	if (bind(transmit_fd, (struct sockaddr *) addr, size) < 0) {
+		connman_error("Failed to bind time server socket");
+		close(transmit_fd);
+		return;
+	}
+	if (family == AF_INET) {
+		if (setsockopt(transmit_fd, IPPROTO_IP, IP_TOS, &tos, sizeof(tos)) < 0) {
+			connman_error("Failed to set type of service option");
+			close(transmit_fd);
+			return;
+		}
+	} else if (family == AF_INET6) {
+            //TO Do
+	}
+
+	if (setsockopt(transmit_fd, SOL_SOCKET, SO_TIMESTAMP, &timestamp,
+						sizeof(timestamp)) < 0) {
+		connman_error("Failed to enable timestamp support");
+		close(transmit_fd);
+		return;
+	}
+
+	channel = g_io_channel_unix_new(transmit_fd);
+	if (!channel) {
+		close(transmit_fd);
+		return;
+	}
+
+	g_io_channel_set_encoding(channel, NULL, NULL);
+	g_io_channel_set_buffered(channel, FALSE);
+
+	g_io_channel_set_close_on_unref(channel, TRUE);
+
+	channel_watch = g_io_add_watch_full(channel, G_PRIORITY_DEFAULT,
+				G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
+				received_data, NULL, NULL);
+
+	g_io_channel_unref(channel);
+
+send:
+	send_packet(transmit_fd, server, NTP_SEND_TIMEOUT, family);
+}
+
+int __connman_ntp_start(char *server)
+{
+	DBG("%s", server);
+	struct addrinfo hint;
+	struct addrinfo *info;
+	int family;
+	int ret;
+
+	if (!server)
+		return -EINVAL;
+
+	if (timeserver)
+		g_free(timeserver);
+
+	memset(&hint, 0, sizeof(hint));
+	hint.ai_family = AF_UNSPEC;
+	hint.ai_flags = AI_NUMERICHOST;
+	ret = getaddrinfo(server, NULL, &hint, &info);
+
+	if (ret) {
+		connman_error("cannot get the server info");
+		return -1;
+	}
+
+	family = info->ai_family;
+	if (family == AF_INET) {
+		if (inet_pton(family, server, &(((struct sockaddr_in *)&timeserver_addr)->sin_addr.s_addr)) == 0) {
+			connman_error("cannot convert ip address string");
+			return -1;
+		}
+	} else if (family == AF_INET6) {
+		if (inet_pton(family, server, ((struct sockaddr_in6 *)&timeserver_addr)->sin6_addr.__in6_u.__u6_addr8) == 0) {
+			connman_error("cannot convert ipv6 address string");
+			return -1;
+		}
+	} else {
+		connman_error("Neither IPv4 nor IPv6 type");
+		return -1;
+	}
+
+	timeserver_addr.ss_family = family;
+	timeserver = g_strdup(server);
+
+	freeaddrinfo(info);
+
+	start_ntp(timeserver, family);
+
+	return 0;
+}
+
+void __connman_ntp_stop()
+{
+	DBG("");
+
+	if (poll_id > 0) {
+		g_source_remove(poll_id);
+		poll_id = 0;
+	}
+
+	reset_timeout();
+
+	if (channel_watch > 0) {
+		g_source_remove(channel_watch);
+		channel_watch = 0;
+		transmit_fd = 0;
+	}
+
+	if (timeserver) {
+		g_free(timeserver);
+		timeserver = NULL;
+	}
+}
diff --git a/connman/src/peer.c b/connman/src/peer.c
new file mode 100644
index 0000000..8a380c9
--- /dev/null
+++ b/connman/src/peer.c
@@ -0,0 +1,1207 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2014  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 <ctype.h>
+#include <gdbus.h>
+#include <gdhcp/gdhcp.h>
+#include <netinet/if_ether.h>
+
+#include <connman/agent.h>
+
+#include "connman.h"
+
+static DBusConnection *connection = NULL;
+
+static GHashTable *peers_table = NULL;
+
+static struct connman_peer_driver *peer_driver;
+
+struct _peers_notify {
+	int id;
+	GHashTable *add;
+	GHashTable *remove;
+} *peers_notify;
+
+struct _peer_service {
+	enum connman_peer_service_type type;
+	unsigned char *data;
+	int length;
+};
+
+struct connman_peer {
+	int refcount;
+	struct connman_device *device;
+	struct connman_device *sub_device;
+	unsigned char *iface_address[ETH_ALEN];
+	char *identifier;
+	char *name;
+	char *path;
+	enum connman_peer_state state;
+	struct connman_ipconfig *ipconfig;
+	DBusMessage *pending;
+	bool registered;
+	bool connection_master;
+	struct connman_ippool *ip_pool;
+	GDHCPServer *dhcp_server;
+	uint32_t lease_ip;
+	GSList *services;
+};
+
+static void settings_changed(struct connman_peer *peer);
+
+static void stop_dhcp_server(struct connman_peer *peer)
+{
+	DBG("");
+
+	if (peer->dhcp_server)
+		g_dhcp_server_unref(peer->dhcp_server);
+
+	peer->dhcp_server = NULL;
+
+	if (peer->ip_pool)
+		__connman_ippool_unref(peer->ip_pool);
+	peer->ip_pool = NULL;
+	peer->lease_ip = 0;
+}
+
+static void dhcp_server_debug(const char *str, void *data)
+{
+	connman_info("%s: %s\n", (const char *) data, str);
+}
+
+static void lease_added(unsigned char *mac, uint32_t ip)
+{
+	GList *list, *start;
+
+	start = list = g_hash_table_get_values(peers_table);
+	for (; list; list = list->next) {
+		struct connman_peer *temp = list->data;
+
+		if (!memcmp(temp->iface_address, mac, ETH_ALEN)) {
+			temp->lease_ip = ip;
+			settings_changed(temp);
+			break;
+		}
+	}
+
+	g_list_free(start);
+}
+
+static gboolean dhcp_server_started(gpointer data)
+{
+	struct connman_peer *peer = data;
+
+	connman_peer_set_state(peer, CONNMAN_PEER_STATE_READY);
+	connman_peer_unref(peer);
+
+	return FALSE;
+}
+
+static int start_dhcp_server(struct connman_peer *peer)
+{
+	const char *start_ip, *end_ip;
+	GDHCPServerError dhcp_error;
+	const char *broadcast;
+	const char *gateway;
+	const char *subnet;
+	int prefixlen;
+	int index;
+	int err;
+
+	DBG("");
+
+	err = -ENOMEM;
+
+	if (peer->sub_device)
+		index = connman_device_get_index(peer->sub_device);
+	else
+		index = connman_device_get_index(peer->device);
+
+	peer->ip_pool = __connman_ippool_create(index, 2, 1, NULL, NULL);
+	if (!peer->ip_pool)
+		goto error;
+
+	gateway = __connman_ippool_get_gateway(peer->ip_pool);
+	subnet = __connman_ippool_get_subnet_mask(peer->ip_pool);
+	broadcast = __connman_ippool_get_broadcast(peer->ip_pool);
+	start_ip = __connman_ippool_get_start_ip(peer->ip_pool);
+	end_ip = __connman_ippool_get_end_ip(peer->ip_pool);
+
+	prefixlen = connman_ipaddress_calc_netmask_len(subnet);
+
+	err = __connman_inet_modify_address(RTM_NEWADDR,
+				NLM_F_REPLACE | NLM_F_ACK, index, AF_INET,
+				gateway, NULL, prefixlen, broadcast);
+	if (err < 0)
+		goto error;
+
+	peer->dhcp_server = g_dhcp_server_new(G_DHCP_IPV4, index, &dhcp_error);
+	if (!peer->dhcp_server)
+		goto error;
+
+	g_dhcp_server_set_debug(peer->dhcp_server,
+					dhcp_server_debug, "Peer DHCP server");
+	g_dhcp_server_set_lease_time(peer->dhcp_server, 3600);
+	g_dhcp_server_set_option(peer->dhcp_server, G_DHCP_SUBNET, subnet);
+	g_dhcp_server_set_option(peer->dhcp_server, G_DHCP_ROUTER, gateway);
+	g_dhcp_server_set_option(peer->dhcp_server, G_DHCP_DNS_SERVER, NULL);
+	g_dhcp_server_set_ip_range(peer->dhcp_server, start_ip, end_ip);
+
+	g_dhcp_server_set_lease_added_cb(peer->dhcp_server, lease_added);
+
+	err = g_dhcp_server_start(peer->dhcp_server);
+	if (err < 0)
+		goto error;
+
+	g_timeout_add_seconds(0, dhcp_server_started, connman_peer_ref(peer));
+
+	return 0;
+
+error:
+	stop_dhcp_server(peer);
+	return err;
+}
+
+static void reply_pending(struct connman_peer *peer, int error)
+{
+	if (!peer->pending)
+		return;
+
+	connman_dbus_reply_pending(peer->pending, error, NULL);
+	peer->pending = NULL;
+}
+
+static void peer_free(gpointer data)
+{
+	struct connman_peer *peer = data;
+
+	reply_pending(peer, ENOENT);
+
+	connman_peer_unregister(peer);
+
+	if (peer->path) {
+		g_free(peer->path);
+		peer->path = NULL;
+	}
+
+	if (peer->ipconfig) {
+		__connman_ipconfig_set_ops(peer->ipconfig, NULL);
+		__connman_ipconfig_set_data(peer->ipconfig, NULL);
+		__connman_ipconfig_unref(peer->ipconfig);
+		peer->ipconfig = NULL;
+	}
+
+	stop_dhcp_server(peer);
+
+	if (peer->device) {
+		connman_device_unref(peer->device);
+		peer->device = NULL;
+	}
+
+	if (peer->services)
+		connman_peer_reset_services(peer);
+
+	g_free(peer->identifier);
+	g_free(peer->name);
+
+	g_free(peer);
+}
+
+static const char *state2string(enum connman_peer_state state)
+{
+	switch (state) {
+	case CONNMAN_PEER_STATE_UNKNOWN:
+		break;
+	case CONNMAN_PEER_STATE_IDLE:
+		return "idle";
+	case CONNMAN_PEER_STATE_ASSOCIATION:
+		return "association";
+	case CONNMAN_PEER_STATE_CONFIGURATION:
+		return "configuration";
+	case CONNMAN_PEER_STATE_READY:
+		return "ready";
+	case CONNMAN_PEER_STATE_DISCONNECT:
+		return "disconnect";
+	case CONNMAN_PEER_STATE_FAILURE:
+		return "failure";
+	}
+
+	return NULL;
+}
+
+static bool is_connecting(struct connman_peer *peer)
+{
+	if (peer->state == CONNMAN_PEER_STATE_ASSOCIATION ||
+			peer->state == CONNMAN_PEER_STATE_CONFIGURATION ||
+			peer->pending)
+		return true;
+
+	return false;
+}
+
+static bool is_connected(struct connman_peer *peer)
+{
+	if (peer->state == CONNMAN_PEER_STATE_READY)
+		return true;
+
+	return false;
+}
+
+static bool allow_property_changed(struct connman_peer *peer)
+{
+	if (g_hash_table_lookup_extended(peers_notify->add, peer->path,
+								NULL, NULL))
+		return false;
+
+	return true;
+}
+
+static void append_ipv4(DBusMessageIter *iter, void *user_data)
+{
+	struct connman_peer *peer = user_data;
+	char trans[INET_ADDRSTRLEN+1] = {};
+	const char *local = "";
+	const char *remote = "";
+	char *dhcp = NULL;
+
+	if (!is_connected(peer))
+		return;
+
+	if (peer->connection_master) {
+		struct in_addr addr;
+
+		addr.s_addr = peer->lease_ip;
+		inet_ntop(AF_INET, &addr, trans, INET_ADDRSTRLEN);
+
+		local = __connman_ippool_get_gateway(peer->ip_pool);
+		remote = trans;
+	} else if (peer->ipconfig) {
+		local = __connman_ipconfig_get_local(peer->ipconfig);
+
+		remote = __connman_ipconfig_get_gateway(peer->ipconfig);
+		if (!remote) {
+			remote = dhcp = __connman_dhcp_get_server_address(
+							peer->ipconfig);
+			if (!dhcp)
+				remote = "";
+		}
+	}
+
+	connman_dbus_dict_append_basic(iter, "Local",
+						DBUS_TYPE_STRING, &local);
+	connman_dbus_dict_append_basic(iter, "Remote",
+						DBUS_TYPE_STRING, &remote);
+	if (dhcp)
+		g_free(dhcp);
+}
+
+static void append_peer_service(DBusMessageIter *iter,
+					struct _peer_service *service)
+{
+	DBusMessageIter dict;
+
+	connman_dbus_dict_open(iter, &dict);
+
+	switch (service->type) {
+	case CONNMAN_PEER_SERVICE_UNKNOWN:
+		/* Should never happen */
+		break;
+	case CONNMAN_PEER_SERVICE_WIFI_DISPLAY:
+		connman_dbus_dict_append_fixed_array(&dict,
+				"WiFiDisplayIEs", DBUS_TYPE_BYTE,
+				&service->data, service->length);
+		break;
+	}
+
+	connman_dbus_dict_close(iter, &dict);
+}
+
+static void append_peer_services(DBusMessageIter *iter, void *user_data)
+{
+	struct connman_peer *peer = user_data;
+	DBusMessageIter container;
+	GSList *list;
+
+	dbus_message_iter_open_container(iter, DBUS_TYPE_STRUCT,
+							NULL, &container);
+
+	if (!peer->services) {
+		DBusMessageIter dict;
+
+		connman_dbus_dict_open(&container, &dict);
+		connman_dbus_dict_close(&container, &dict);
+	} else {
+		for (list = peer->services; list; list = list->next)
+			append_peer_service(&container, list->data);
+	}
+
+	dbus_message_iter_close_container(iter, &container);
+}
+
+static void append_properties(DBusMessageIter *iter, struct connman_peer *peer)
+{
+	const char *state = state2string(peer->state);
+	DBusMessageIter dict;
+
+	connman_dbus_dict_open(iter, &dict);
+
+	connman_dbus_dict_append_basic(&dict, "State",
+					DBUS_TYPE_STRING, &state);
+	connman_dbus_dict_append_basic(&dict, "Name",
+					DBUS_TYPE_STRING, &peer->name);
+	connman_dbus_dict_append_dict(&dict, "IPv4", append_ipv4, peer);
+	connman_dbus_dict_append_array(&dict, "Services",
+					DBUS_TYPE_DICT_ENTRY,
+					append_peer_services, peer);
+	connman_dbus_dict_close(iter, &dict);
+}
+
+static void settings_changed(struct connman_peer *peer)
+{
+	if (!allow_property_changed(peer))
+		return;
+
+	connman_dbus_property_changed_dict(peer->path,
+					CONNMAN_PEER_INTERFACE, "IPv4",
+					append_ipv4, peer);
+}
+
+static DBusMessage *get_peer_properties(DBusConnection *conn,
+						DBusMessage *msg, void *data)
+{
+	struct connman_peer *peer = data;
+	DBusMessageIter dict;
+	DBusMessage *reply;
+
+	reply = dbus_message_new_method_return(msg);
+	if (!reply)
+		return NULL;
+
+	dbus_message_iter_init_append(reply, &dict);
+	append_properties(&dict, peer);
+
+	return reply;
+}
+
+static void append_peer_struct(gpointer key, gpointer value,
+						gpointer user_data)
+{
+	DBusMessageIter *array = user_data;
+	struct connman_peer *peer = value;
+	DBusMessageIter entry;
+
+	dbus_message_iter_open_container(array, DBUS_TYPE_STRUCT,
+							NULL, &entry);
+	dbus_message_iter_append_basic(&entry, DBUS_TYPE_OBJECT_PATH,
+							&peer->path);
+	append_properties(&entry, peer);
+	dbus_message_iter_close_container(array, &entry);
+}
+
+static void state_changed(struct connman_peer *peer)
+{
+	const char *state;
+
+	state = state2string(peer->state);
+	if (!state || !allow_property_changed(peer))
+		return;
+
+	connman_dbus_property_changed_basic(peer->path,
+					 CONNMAN_PEER_INTERFACE, "State",
+					 DBUS_TYPE_STRING, &state);
+}
+
+static void append_existing_and_new_peers(gpointer key,
+					gpointer value, gpointer user_data)
+{
+	struct connman_peer *peer = value;
+	DBusMessageIter *iter = user_data;
+	DBusMessageIter entry, dict;
+
+	if (!peer || !peer->registered)
+		return;
+
+	if (g_hash_table_lookup(peers_notify->add, peer->path)) {
+		DBG("new %s", peer->path);
+
+		append_peer_struct(key, peer, iter);
+		g_hash_table_remove(peers_notify->add, peer->path);
+	} else if (!g_hash_table_lookup(peers_notify->remove, peer->path)) {
+		DBG("existing %s", peer->path);
+
+		dbus_message_iter_open_container(iter, DBUS_TYPE_STRUCT,
+								NULL, &entry);
+		dbus_message_iter_append_basic(&entry, DBUS_TYPE_OBJECT_PATH,
+								&peer->path);
+		connman_dbus_dict_open(&entry, &dict);
+		connman_dbus_dict_close(&entry, &dict);
+
+		dbus_message_iter_close_container(iter, &entry);
+	}
+}
+
+static void peer_append_all(DBusMessageIter *iter, void *user_data)
+{
+	g_hash_table_foreach(peers_table, append_existing_and_new_peers, iter);
+}
+
+static void append_removed(gpointer key, gpointer value, gpointer user_data)
+{
+	DBusMessageIter *iter = user_data;
+	char *objpath = key;
+
+	DBG("removed %s", objpath);
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH, &objpath);
+}
+
+static void peer_append_removed(DBusMessageIter *iter, void *user_data)
+{
+	g_hash_table_foreach(peers_notify->remove, append_removed, iter);
+}
+
+static gboolean peer_send_changed(gpointer data)
+{
+	DBusMessage *signal;
+
+	DBG("");
+
+	peers_notify->id = 0;
+
+	signal = dbus_message_new_signal(CONNMAN_MANAGER_PATH,
+				CONNMAN_MANAGER_INTERFACE, "PeersChanged");
+	if (!signal)
+		return FALSE;
+
+	__connman_dbus_append_objpath_dict_array(signal,
+						peer_append_all, NULL);
+	__connman_dbus_append_objpath_array(signal,
+						peer_append_removed, NULL);
+
+	dbus_connection_send(connection, signal, NULL);
+	dbus_message_unref(signal);
+
+	g_hash_table_remove_all(peers_notify->remove);
+	g_hash_table_remove_all(peers_notify->add);
+
+	return FALSE;
+}
+
+static void peer_schedule_changed(void)
+{
+	if (peers_notify->id != 0)
+		return;
+
+	peers_notify->id = g_timeout_add(100, peer_send_changed, NULL);
+}
+
+static void peer_added(struct connman_peer *peer)
+{
+	DBG("peer %p", peer);
+
+	g_hash_table_remove(peers_notify->remove, peer->path);
+	g_hash_table_replace(peers_notify->add, peer->path, peer);
+
+	peer_schedule_changed();
+}
+
+static void peer_removed(struct connman_peer *peer)
+{
+	DBG("peer %p", peer);
+
+	g_hash_table_remove(peers_notify->add, peer->path);
+	g_hash_table_replace(peers_notify->remove, g_strdup(peer->path), NULL);
+
+	peer_schedule_changed();
+}
+
+static const char *get_dbus_sender(struct connman_peer *peer)
+{
+	if (!peer->pending)
+		return NULL;
+
+	return dbus_message_get_sender(peer->pending);
+}
+
+static enum connman_peer_wps_method check_wpspin(struct connman_peer *peer,
+							const char *wpspin)
+{
+	int len, i;
+
+	if (!wpspin)
+		return CONNMAN_PEER_WPS_PBC;
+
+	len = strlen(wpspin);
+	if (len == 0)
+		return CONNMAN_PEER_WPS_PBC;
+
+	if (len != 8)
+		return CONNMAN_PEER_WPS_UNKNOWN;
+	for (i = 0; i < 8; i++) {
+		if (!isdigit((unsigned char) wpspin[i]))
+			return CONNMAN_PEER_WPS_UNKNOWN;
+	}
+
+	return CONNMAN_PEER_WPS_PIN;
+}
+
+static void request_authorization_cb(struct connman_peer *peer,
+					bool choice_done, const char *wpspin,
+					const char *error, void *user_data)
+{
+	enum connman_peer_wps_method wps_method;
+	int err;
+
+	DBG("RequestInput return, %p", peer);
+
+	if (error) {
+		if (g_strcmp0(error,
+				"net.connman.Agent.Error.Canceled") == 0 ||
+			g_strcmp0(error,
+				"net.connman.Agent.Error.Rejected") == 0) {
+			err = -EINVAL;
+			goto out;
+		}
+	}
+
+	if (!choice_done || !peer_driver->connect) {
+		err = -EINVAL;
+		goto out;
+	}
+
+	wps_method = check_wpspin(peer, wpspin);
+
+	err = peer_driver->connect(peer, wps_method, wpspin);
+	if (err == -EINPROGRESS)
+		return;
+
+out:
+	reply_pending(peer, EIO);
+	connman_peer_set_state(peer, CONNMAN_PEER_STATE_IDLE);
+}
+
+static int peer_connect(struct connman_peer *peer)
+{
+	int err = -ENOTSUP;
+
+	if (peer_driver->connect)
+		err = peer_driver->connect(peer,
+					CONNMAN_PEER_WPS_UNKNOWN, NULL);
+
+	if (err == -ENOKEY) {
+		err = __connman_agent_request_peer_authorization(peer,
+						request_authorization_cb, true,
+						get_dbus_sender(peer), NULL);
+	}
+
+	return err;
+}
+
+static int peer_disconnect(struct connman_peer *peer)
+{
+	int err = -ENOTSUP;
+
+	connman_agent_cancel(peer);
+	reply_pending(peer, ECONNABORTED);
+
+	connman_peer_set_state(peer, CONNMAN_PEER_STATE_DISCONNECT);
+
+	if (peer->connection_master)
+		stop_dhcp_server(peer);
+	else
+		__connman_dhcp_stop(peer->ipconfig);
+
+	if (peer_driver->disconnect)
+		err = peer_driver->disconnect(peer);
+
+	connman_peer_set_state(peer, CONNMAN_PEER_STATE_IDLE);
+
+	return err;
+}
+
+static DBusMessage *connect_peer(DBusConnection *conn,
+					DBusMessage *msg, void *user_data)
+{
+	struct connman_peer *peer = user_data;
+	GList *list, *start;
+	int err;
+
+	DBG("peer %p", peer);
+
+	if (peer->pending)
+		return __connman_error_in_progress(msg);
+
+	list = g_hash_table_get_values(peers_table);
+	start = list;
+	for (; list; list = list->next) {
+		struct connman_peer *temp = list->data;
+
+		if (temp == peer || temp->device != peer->device)
+			continue;
+
+		if (is_connecting(temp) || is_connected(temp)) {
+			if (peer_disconnect(temp) == -EINPROGRESS) {
+				g_list_free(start);
+				return __connman_error_in_progress(msg);
+			}
+		}
+	}
+
+	g_list_free(start);
+
+	peer->pending = dbus_message_ref(msg);
+
+	err = peer_connect(peer);
+	if (err == -EINPROGRESS)
+		return NULL;
+
+	if (err < 0) {
+		dbus_message_unref(peer->pending);
+		peer->pending = NULL;
+
+		return __connman_error_failed(msg, -err);
+	}
+
+	return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+}
+
+static DBusMessage *disconnect_peer(DBusConnection *conn,
+					DBusMessage *msg, void *user_data)
+{
+	struct connman_peer *peer = user_data;
+	int err;
+
+	DBG("peer %p", peer);
+
+	err = peer_disconnect(peer);
+	if (err < 0 && err != -EINPROGRESS)
+		return __connman_error_failed(msg, -err);
+
+	return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+}
+
+struct connman_peer *connman_peer_create(const char *identifier)
+{
+	struct connman_peer *peer;
+
+	peer = g_malloc0(sizeof(struct connman_peer));
+	peer->identifier = g_strdup(identifier);
+	peer->state = CONNMAN_PEER_STATE_IDLE;
+
+	peer->refcount = 1;
+
+	return peer;
+}
+
+struct connman_peer *connman_peer_ref_debug(struct connman_peer *peer,
+				const char *file, int line, const char *caller)
+{
+	DBG("%p ref %d by %s:%d:%s()", peer, peer->refcount + 1,
+						file, line, caller);
+
+	__sync_fetch_and_add(&peer->refcount, 1);
+
+	return peer;
+}
+
+void connman_peer_unref_debug(struct connman_peer *peer,
+				const char *file, int line, const char *caller)
+{
+	DBG("%p ref %d by %s:%d:%s()", peer, peer->refcount - 1,
+						file, line, caller);
+
+	if (__sync_fetch_and_sub(&peer->refcount, 1) != 1)
+		return;
+
+	if (!peer->registered && !peer->path)
+		return peer_free(peer);
+
+	g_hash_table_remove(peers_table, peer->path);
+}
+
+const char *connman_peer_get_identifier(struct connman_peer *peer)
+{
+	if (!peer)
+		return NULL;
+
+	return peer->identifier;
+}
+
+void connman_peer_set_name(struct connman_peer *peer, const char *name)
+{
+	g_free(peer->name);
+	peer->name = g_strdup(name);
+}
+
+void connman_peer_set_iface_address(struct connman_peer *peer,
+					const unsigned char *iface_address)
+{
+	memset(peer->iface_address, 0, ETH_ALEN);
+	memcpy(peer->iface_address, iface_address, ETH_ALEN);
+}
+
+void connman_peer_set_device(struct connman_peer *peer,
+				struct connman_device *device)
+{
+	if (!peer || !device)
+		return;
+
+	peer->device = device;
+	connman_device_ref(device);
+}
+
+struct connman_device *connman_peer_get_device(struct connman_peer *peer)
+{
+	if (!peer)
+		return NULL;
+
+	return peer->device;
+}
+
+void connman_peer_set_sub_device(struct connman_peer *peer,
+					struct connman_device *device)
+{
+	if (!peer || !device || peer->sub_device)
+		return;
+
+	peer->sub_device = device;
+}
+
+void connman_peer_set_as_master(struct connman_peer *peer, bool master)
+{
+	if (!peer || !is_connecting(peer))
+		return;
+
+	peer->connection_master = master;
+}
+
+static void dhcp_callback(struct connman_ipconfig *ipconfig,
+			struct connman_network *network,
+			bool success, gpointer data)
+{
+	struct connman_peer *peer = data;
+	int err;
+
+	if (!success)
+		goto error;
+
+	DBG("lease acquired for ipconfig %p", ipconfig);
+
+	err = __connman_ipconfig_address_add(ipconfig);
+	if (err < 0)
+		goto error;
+
+	return;
+
+error:
+	__connman_ipconfig_address_remove(ipconfig);
+	connman_peer_set_state(peer, CONNMAN_PEER_STATE_FAILURE);
+}
+
+static int start_dhcp_client(struct connman_peer *peer)
+{
+	if (peer->sub_device)
+		__connman_ipconfig_set_index(peer->ipconfig,
+				connman_device_get_index(peer->sub_device));
+
+	__connman_ipconfig_enable(peer->ipconfig);
+
+	return __connman_dhcp_start(peer->ipconfig, NULL, dhcp_callback, peer);
+}
+
+static void report_error_cb(void *user_context, bool retry, void *user_data)
+{
+	struct connman_peer *peer = user_context;
+
+	if (retry) {
+		int err;
+		err = peer_connect(peer);
+
+		if (err == 0 || err == -EINPROGRESS)
+			return;
+	}
+
+	reply_pending(peer, ENOTCONN);
+
+	peer_disconnect(peer);
+
+	if (!peer->connection_master) {
+		__connman_dhcp_stop(peer->ipconfig);
+		__connman_ipconfig_disable(peer->ipconfig);
+	} else
+		stop_dhcp_server(peer);
+
+	peer->connection_master = false;
+	peer->sub_device = NULL;
+}
+
+static int manage_peer_error(struct connman_peer *peer)
+{
+	int err;
+
+	err = __connman_agent_report_peer_error(peer, peer->path,
+					"connect-failed", report_error_cb,
+					get_dbus_sender(peer), NULL);
+	if (err != -EINPROGRESS) {
+		report_error_cb(peer, false, NULL);
+		return err;
+	}
+
+	return 0;
+}
+
+int connman_peer_set_state(struct connman_peer *peer,
+					enum connman_peer_state new_state)
+{
+	enum connman_peer_state old_state = peer->state;
+	int err;
+
+	DBG("peer (%s) old state %d new state %d", peer->name,
+				old_state, new_state);
+
+	if (old_state == new_state)
+		return -EALREADY;
+
+	switch (new_state) {
+	case CONNMAN_PEER_STATE_UNKNOWN:
+		return -EINVAL;
+	case CONNMAN_PEER_STATE_IDLE:
+		if (is_connecting(peer) || is_connected(peer))
+			return peer_disconnect(peer);
+		peer->sub_device = NULL;
+		break;
+	case CONNMAN_PEER_STATE_ASSOCIATION:
+		break;
+	case CONNMAN_PEER_STATE_CONFIGURATION:
+		if (peer->connection_master)
+			err = start_dhcp_server(peer);
+		else
+			err = start_dhcp_client(peer);
+		if (err < 0)
+			return connman_peer_set_state(peer,
+						CONNMAN_PEER_STATE_FAILURE);
+		break;
+	case CONNMAN_PEER_STATE_READY:
+		reply_pending(peer, 0);
+		break;
+	case CONNMAN_PEER_STATE_DISCONNECT:
+		if (peer->connection_master)
+			stop_dhcp_server(peer);
+		else
+			__connman_dhcp_stop(peer->ipconfig);
+		peer->connection_master = false;
+		peer->sub_device = NULL;
+
+		break;
+	case CONNMAN_PEER_STATE_FAILURE:
+		if (manage_peer_error(peer) == 0)
+			return 0;
+		break;
+	};
+
+	peer->state = new_state;
+	state_changed(peer);
+
+	if (peer->state == CONNMAN_PEER_STATE_READY ||
+				peer->state == CONNMAN_PEER_STATE_DISCONNECT)
+		settings_changed(peer);
+
+	return 0;
+}
+
+int connman_peer_request_connection(struct connman_peer *peer)
+{
+	return __connman_agent_request_peer_authorization(peer,
+					request_authorization_cb, false,
+					NULL, NULL);
+}
+
+static void peer_service_free(gpointer data)
+{
+	struct _peer_service *service = data;
+
+	if (!service)
+		return;
+
+	g_free(service->data);
+	g_free(service);
+}
+
+void connman_peer_reset_services(struct connman_peer *peer)
+{
+	if (!peer)
+		return;
+
+	g_slist_free_full(peer->services, peer_service_free);
+	peer->services = NULL;
+}
+
+void connman_peer_services_changed(struct connman_peer *peer)
+{
+	if (!peer || !peer->registered || !allow_property_changed(peer))
+		return;
+
+	connman_dbus_property_changed_array(peer->path,
+			CONNMAN_PEER_INTERFACE, "Services",
+			DBUS_TYPE_DICT_ENTRY, append_peer_services, peer);
+}
+
+void connman_peer_add_service(struct connman_peer *peer,
+				enum connman_peer_service_type type,
+				const unsigned char *data, int data_length)
+{
+	struct _peer_service *service;
+
+	if (!peer || !data || type == CONNMAN_PEER_SERVICE_UNKNOWN)
+		return;
+
+	service = g_malloc0(sizeof(struct _peer_service));
+	service->type = type;
+	service->data = g_memdup(data, data_length * sizeof(unsigned char));
+	service->length = data_length;
+
+	peer->services = g_slist_prepend(peer->services, service);
+}
+
+static void peer_up(struct connman_ipconfig *ipconfig, const char *ifname)
+{
+	DBG("%s up", ifname);
+}
+
+static void peer_down(struct connman_ipconfig *ipconfig, const char *ifname)
+{
+	DBG("%s down", ifname);
+}
+
+static void peer_lower_up(struct connman_ipconfig *ipconfig,
+							const char *ifname)
+{
+	DBG("%s lower up", ifname);
+}
+
+static void peer_lower_down(struct connman_ipconfig *ipconfig,
+							const char *ifname)
+{
+	struct connman_peer *peer = __connman_ipconfig_get_data(ipconfig);
+
+	DBG("%s lower down", ifname);
+
+	__connman_ipconfig_disable(ipconfig);
+	connman_peer_set_state(peer, CONNMAN_PEER_STATE_DISCONNECT);
+}
+
+static void peer_ip_bound(struct connman_ipconfig *ipconfig,
+							const char *ifname)
+{
+	struct connman_peer *peer = __connman_ipconfig_get_data(ipconfig);
+
+	DBG("%s ip bound", ifname);
+
+	if (peer->state == CONNMAN_PEER_STATE_READY)
+		settings_changed(peer);
+	connman_peer_set_state(peer, CONNMAN_PEER_STATE_READY);
+}
+
+static void peer_ip_release(struct connman_ipconfig *ipconfig,
+							const char *ifname)
+{
+	struct connman_peer *peer = __connman_ipconfig_get_data(ipconfig);
+
+	DBG("%s ip release", ifname);
+
+	if (peer->state == CONNMAN_PEER_STATE_READY)
+		settings_changed(peer);
+}
+
+static const struct connman_ipconfig_ops peer_ip_ops = {
+	.up		= peer_up,
+	.down		= peer_down,
+	.lower_up	= peer_lower_up,
+	.lower_down	= peer_lower_down,
+	.ip_bound	= peer_ip_bound,
+	.ip_release	= peer_ip_release,
+	.route_set	= NULL,
+	.route_unset	= NULL,
+};
+
+static struct connman_ipconfig *create_ipconfig(int index, void *user_data)
+{
+	struct connman_ipconfig *ipconfig;
+
+	ipconfig = __connman_ipconfig_create(index,
+						CONNMAN_IPCONFIG_TYPE_IPV4);
+	if (!ipconfig)
+		return NULL;
+
+	__connman_ipconfig_set_method(ipconfig, CONNMAN_IPCONFIG_METHOD_DHCP);
+	__connman_ipconfig_set_data(ipconfig, user_data);
+	__connman_ipconfig_set_ops(ipconfig, &peer_ip_ops);
+
+	return ipconfig;
+}
+
+static const GDBusMethodTable peer_methods[] = {
+	{ GDBUS_METHOD("GetProperties",
+			NULL, GDBUS_ARGS({ "properties", "a{sv}" }),
+			get_peer_properties) },
+	{ GDBUS_ASYNC_METHOD("Connect", NULL, NULL, connect_peer) },
+	{ GDBUS_METHOD("Disconnect", NULL, NULL, disconnect_peer) },
+	{ },
+};
+
+static const GDBusSignalTable peer_signals[] = {
+	{ GDBUS_SIGNAL("PropertyChanged",
+			GDBUS_ARGS({ "name", "s" }, { "value", "v" })) },
+	{ },
+};
+
+static char *get_peer_path(struct connman_device *device,
+					const char *identifier)
+{
+	return g_strdup_printf("%s/peer/peer_%s_%s", CONNMAN_PATH,
+				connman_device_get_ident(device), identifier);
+}
+
+int connman_peer_register(struct connman_peer *peer)
+{
+	int index;
+
+	DBG("peer %p", peer);
+
+	if (peer->path && peer->registered)
+		return -EALREADY;
+
+	index = connman_device_get_index(peer->device);
+	peer->ipconfig = create_ipconfig(index, peer);
+	if (!peer->ipconfig)
+		return -ENOMEM;
+
+	peer->path = get_peer_path(peer->device, peer->identifier);
+	DBG("path %s", peer->path);
+
+	g_hash_table_insert(peers_table, peer->path, peer);
+
+	g_dbus_register_interface(connection, peer->path,
+					CONNMAN_PEER_INTERFACE,
+					peer_methods, peer_signals,
+					NULL, peer, NULL);
+	peer->registered = true;
+	peer_added(peer);
+
+	return 0;
+}
+
+void connman_peer_unregister(struct connman_peer *peer)
+{
+	DBG("peer %p", peer);
+
+	if (!peer->path || !peer->registered)
+		return;
+
+	connman_agent_cancel(peer);
+	reply_pending(peer, EIO);
+
+	g_dbus_unregister_interface(connection, peer->path,
+					CONNMAN_PEER_INTERFACE);
+	peer->registered = false;
+	peer_removed(peer);
+}
+
+struct connman_peer *connman_peer_get(struct connman_device *device,
+						const char *identifier)
+{
+	char *ident = get_peer_path(device, identifier);
+	struct connman_peer *peer;
+
+	peer = g_hash_table_lookup(peers_table, ident);
+	g_free(ident);
+
+	return peer;
+}
+
+int connman_peer_driver_register(struct connman_peer_driver *driver)
+{
+	if (peer_driver && peer_driver != driver)
+		return -EINVAL;
+
+	peer_driver = driver;
+
+	__connman_peer_service_set_driver(driver);
+
+	return 0;
+}
+
+void connman_peer_driver_unregister(struct connman_peer_driver *driver)
+{
+	if (peer_driver != driver)
+		return;
+
+	peer_driver = NULL;
+
+	__connman_peer_service_set_driver(NULL);
+}
+
+void __connman_peer_list_struct(DBusMessageIter *array)
+{
+	g_hash_table_foreach(peers_table, append_peer_struct, array);
+}
+
+const char *__connman_peer_get_path(struct connman_peer *peer)
+{
+	if (!peer || !peer->registered)
+		return NULL;
+
+	return peer->path;
+}
+
+int __connman_peer_init(void)
+{
+	DBG("");
+
+	connection = connman_dbus_get_connection();
+
+	peers_table = g_hash_table_new_full(g_str_hash, g_str_equal,
+							NULL, peer_free);
+
+	peers_notify = g_new0(struct _peers_notify, 1);
+	peers_notify->add = g_hash_table_new(g_str_hash, g_str_equal);
+	peers_notify->remove = g_hash_table_new_full(g_str_hash, g_str_equal,
+								g_free, NULL);
+	return 0;
+}
+
+void __connman_peer_cleanup(void)
+{
+	DBG("");
+
+	g_hash_table_destroy(peers_notify->remove);
+	g_hash_table_destroy(peers_notify->add);
+	g_free(peers_notify);
+
+	g_hash_table_destroy(peers_table);
+	peers_table = NULL;
+	dbus_connection_unref(connection);
+	connection = NULL;
+}
diff --git a/connman/src/peer_service.c b/connman/src/peer_service.c
new file mode 100644
index 0000000..053672a
--- /dev/null
+++ b/connman/src/peer_service.c
@@ -0,0 +1,429 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2014  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 <gdbus.h>
+
+#include "connman.h"
+
+static DBusConnection *connection;
+
+struct _peer_service {
+	bool registered;
+	const char *owner;
+	DBusMessage *pending;
+
+	GBytes *specification;
+	GBytes *query;
+	int version;
+
+	bool master;
+};
+
+struct _peer_service_owner {
+	char *owner;
+	guint watch;
+	GList *services;
+};
+
+static struct connman_peer_driver *peer_driver;
+
+static GHashTable *owners_map;
+static GHashTable *services_map;
+static int peer_master;
+
+static void reply_pending(struct _peer_service *service, int error)
+{
+	if (!service->pending)
+		return;
+
+	connman_dbus_reply_pending(service->pending, error, NULL);
+	service->pending = NULL;
+}
+
+static struct _peer_service *find_peer_service(GBytes *specification,
+					GBytes *query, int version,
+					const char *owner, bool remove)
+{
+	struct _peer_service *service = NULL;
+	struct _peer_service_owner *ps_owner;
+	GList *list;
+
+	ps_owner = g_hash_table_lookup(services_map, specification);
+	if (!ps_owner)
+		return NULL;
+
+	if (owner && g_strcmp0(owner, ps_owner->owner) != 0)
+		return NULL;
+
+	for (list = ps_owner->services; list; list = list->next) {
+		service = list->data;
+
+		if (service->specification == specification)
+			break;
+
+		if (version) {
+			if (!service->version)
+				continue;
+			if (version != service->version)
+				continue;
+		}
+
+		if (query) {
+			if (!service->query)
+				continue;
+			if (g_bytes_equal(service->query, query))
+				continue;
+		}
+
+		if (g_bytes_equal(service->specification, specification))
+			break;
+	}
+
+	if (!service)
+		return NULL;
+
+	if (owner && remove)
+		ps_owner->services = g_list_delete_link(ps_owner->services,
+									list);
+
+	return service;
+}
+
+static void unregister_peer_service(struct _peer_service *service)
+{
+	gsize spec_length, query_length = 0;
+	const void *spec, *query = NULL;
+
+	if (!peer_driver || !service->specification)
+		return;
+
+	spec = g_bytes_get_data(service->specification, &spec_length);
+	if (service->query)
+		query = g_bytes_get_data(service->query, &query_length);
+
+	peer_driver->unregister_service(spec, spec_length, query,
+					query_length, service->version);
+}
+
+static void remove_peer_service(gpointer user_data)
+{
+	struct _peer_service *service = user_data;
+
+	reply_pending(service, ECONNABORTED);
+
+	if (service->registered)
+		unregister_peer_service(service);
+
+	if (service->specification) {
+		if (service->owner) {
+			find_peer_service(service->specification,
+					service->query, service->version,
+					service->owner, true);
+		}
+
+		g_hash_table_remove(services_map, service->specification);
+		g_bytes_unref(service->specification);
+	}
+
+	if (service->query)
+		g_bytes_unref(service->query);
+
+	if (service->master)
+		peer_master--;
+
+	g_free(service);
+}
+
+static void apply_peer_service_removal(gpointer user_data)
+{
+	struct _peer_service *service = user_data;
+
+	service->owner = NULL;
+	remove_peer_service(user_data);
+}
+
+static void remove_peer_service_owner(gpointer user_data)
+{
+	struct _peer_service_owner *ps_owner = user_data;
+
+	DBG("owner %s", ps_owner->owner);
+
+	if (ps_owner->watch > 0)
+		g_dbus_remove_watch(connection, ps_owner->watch);
+
+	if (ps_owner->services) {
+		g_list_free_full(ps_owner->services,
+					apply_peer_service_removal);
+	}
+
+	g_free(ps_owner->owner);
+	g_free(ps_owner);
+}
+
+static void owner_disconnect(DBusConnection *conn, void *user_data)
+{
+	struct _peer_service_owner *ps_owner = user_data;
+
+	ps_owner->watch = 0;
+	g_hash_table_remove(owners_map, ps_owner->owner);
+}
+
+static void service_registration_result(int result, void *user_data)
+{
+	struct _peer_service *service = user_data;
+
+	reply_pending(service, -result);
+
+	if (service->registered)
+		return;
+
+	if (result == 0) {
+		service->registered = true;
+		if (service->master)
+			peer_master++;
+		return;
+	}
+
+	remove_peer_service(service);
+}
+
+static int register_peer_service(struct _peer_service *service)
+{
+	gsize spec_length, query_length = 0;
+	const void *spec, *query = NULL;
+
+	if (!peer_driver)
+		return 0;
+
+	spec = g_bytes_get_data(service->specification, &spec_length);
+	if (service->query)
+		query = g_bytes_get_data(service->query, &query_length);
+
+	return peer_driver->register_service(spec, spec_length, query,
+					query_length, service->version,
+					service_registration_result, service);
+}
+
+static void register_all_services(gpointer key, gpointer value,
+						gpointer user_data)
+{
+	struct _peer_service_owner *ps_owner = value;
+	GList *list;
+
+	for (list = ps_owner->services; list; list = list->next) {
+		struct _peer_service *service = list->data;
+
+		if (service->registered)
+			register_peer_service(service);
+	}
+}
+
+void __connman_peer_service_set_driver(struct connman_peer_driver *driver)
+{
+	peer_driver = driver;
+	if (!peer_driver)
+		return;
+
+	g_hash_table_foreach(owners_map, register_all_services, NULL);
+}
+
+int __connman_peer_service_register(const char *owner, DBusMessage *msg,
+					const unsigned char *specification,
+					int specification_length,
+					const unsigned char *query,
+					int query_length, int version,
+					bool master)
+{
+	struct _peer_service_owner *ps_owner;
+	GBytes *spec, *query_spec = NULL;
+	struct _peer_service *service;
+	bool new = false;
+	int ret = 0;
+
+	DBG("owner %s - spec %p/length %d - query %p/length %d - version %d",
+				owner,specification, specification_length,
+				query, query_length, version);
+
+	if (!specification || specification_length == 0)
+		return -EINVAL;
+
+	ps_owner = g_hash_table_lookup(owners_map, owner);
+	if (!ps_owner) {
+		ps_owner = g_try_new0(struct _peer_service_owner, 1);
+		if (!ps_owner)
+			return -ENOMEM;
+
+		ps_owner->owner = g_strdup(owner);
+		ps_owner->watch = g_dbus_add_disconnect_watch(connection,
+						owner, owner_disconnect,
+						ps_owner, NULL);
+		g_hash_table_insert(owners_map, ps_owner->owner, ps_owner);
+		new = true;
+	}
+
+	spec = g_bytes_new(specification, specification_length);
+	if (query)
+		query_spec = g_bytes_new(query, query_length);
+
+	service = find_peer_service(spec, query_spec, version, NULL, false);
+	if (service) {
+		DBG("Found one existing service %p", service);
+
+		if (g_strcmp0(service->owner, owner))
+			ret = -EBUSY;
+
+		if (service->pending)
+			ret = -EINPROGRESS;
+		else
+			ret = -EEXIST;
+
+		service = NULL;
+		goto error;
+	}
+
+	service = g_try_new0(struct _peer_service, 1);
+	if (!service) {
+		ret = -ENOMEM;
+		goto error;
+	}
+
+	service->owner = ps_owner->owner;
+	service->specification = spec;
+	service->query = query_spec;
+	service->version = version;
+	service->master = master;
+
+	g_hash_table_insert(services_map, spec, ps_owner);
+	spec = query_spec = NULL;
+
+	ret = register_peer_service(service);
+	if (ret != 0 && ret != -EINPROGRESS)
+		goto error;
+	else if (ret == -EINPROGRESS)
+		service->pending = dbus_message_ref(msg);
+	else {
+		service->registered = true;
+		if (master)
+			peer_master++;
+	}
+
+	ps_owner->services = g_list_prepend(ps_owner->services, service);
+
+	return ret;
+error:
+	if (spec)
+		g_bytes_unref(spec);
+	if (query_spec)
+		g_bytes_unref(query_spec);
+
+	if (service)
+		remove_peer_service(service);
+
+	if (new)
+		g_hash_table_remove(owners_map, ps_owner->owner);
+
+	return ret;
+}
+
+int __connman_peer_service_unregister(const char *owner,
+					const unsigned char *specification,
+					int specification_length,
+					const unsigned char *query,
+					int query_length, int version)
+{
+	struct _peer_service_owner *ps_owner;
+	GBytes *spec, *query_spec = NULL;
+	struct _peer_service *service;
+
+	DBG("owner %s - spec %p/length %d - query %p/length %d - version %d",
+				owner,specification, specification_length,
+				query, query_length, version);
+
+	ps_owner = g_hash_table_lookup(owners_map, owner);
+	if (!ps_owner)
+		return -ESRCH;
+
+	spec = g_bytes_new(specification, specification_length);
+	if (query)
+		query_spec = g_bytes_new(query, query_length);
+
+	service = find_peer_service(spec, query_spec, version, owner, true);
+
+	g_bytes_unref(spec);
+	g_bytes_unref(query_spec);
+
+	if (!service)
+		return -ESRCH;
+
+	remove_peer_service(service);
+
+	if (!ps_owner->services)
+		g_hash_table_remove(owners_map, ps_owner->owner);
+
+	return 0;
+}
+
+bool connman_peer_service_is_master(void)
+{
+	if (!peer_master || !peer_driver)
+		return false;
+
+	return true;
+}
+
+int __connman_peer_service_init(void)
+{
+	DBG("");
+	connection = connman_dbus_get_connection();
+	if (!connection)
+		return -1;
+
+	peer_driver = NULL;
+
+	owners_map = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
+						remove_peer_service_owner);
+	services_map = g_hash_table_new_full(g_bytes_hash, g_bytes_equal,
+								NULL, NULL);
+	peer_master = 0;
+
+	return 0;
+}
+
+void __connman_peer_service_cleanup(void)
+{
+	DBG("");
+
+	if (!connection)
+		return;
+
+	g_hash_table_destroy(owners_map);
+	g_hash_table_destroy(services_map);
+	peer_master = 0;
+
+	dbus_connection_unref(connection);
+	connection = NULL;
+}
diff --git a/connman/src/plugin.c b/connman/src/plugin.c
new file mode 100644
index 0000000..7d73058
--- /dev/null
+++ b/connman/src/plugin.c
@@ -0,0 +1,209 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2012  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 <dlfcn.h>
+
+#include <glib.h>
+
+#ifdef CONNMAN_PLUGIN_BUILTIN
+#undef CONNMAN_PLUGIN_BUILTIN
+#endif
+
+#include "connman.h"
+
+static GSList *plugins = NULL;
+
+struct connman_plugin {
+	void *handle;
+	bool active;
+	struct connman_plugin_desc *desc;
+};
+
+static gint compare_priority(gconstpointer a, gconstpointer b)
+{
+	const struct connman_plugin *plugin1 = a;
+	const struct connman_plugin *plugin2 = b;
+
+	return plugin2->desc->priority - plugin1->desc->priority;
+}
+
+static bool add_plugin(void *handle, struct connman_plugin_desc *desc)
+{
+	struct connman_plugin *plugin;
+
+	if (!desc->init)
+		return false;
+
+	if (!g_str_equal(desc->version, CONNMAN_VERSION)) {
+		connman_error("Invalid version %s for %s", desc->version,
+							desc->description);
+		return false;
+	}
+
+	plugin = g_try_new0(struct connman_plugin, 1);
+	if (!plugin)
+		return false;
+
+	plugin->handle = handle;
+	plugin->active = false;
+	plugin->desc = desc;
+
+	__connman_log_enable(desc->debug_start, desc->debug_stop);
+
+	plugins = g_slist_insert_sorted(plugins, plugin, compare_priority);
+
+	return true;
+}
+
+static bool check_plugin(struct connman_plugin_desc *desc,
+				char **patterns, char **excludes)
+{
+	if (excludes) {
+		for (; *excludes; excludes++)
+			if (g_pattern_match_simple(*excludes, desc->name))
+				break;
+		if (*excludes) {
+			connman_info("Excluding %s", desc->description);
+			return false;
+		}
+	}
+
+	if (patterns) {
+		for (; *patterns; patterns++)
+			if (g_pattern_match_simple(*patterns, desc->name))
+				break;
+		if (!*patterns) {
+			connman_info("Ignoring %s", desc->description);
+			return false;
+		}
+	}
+
+	return true;
+}
+
+#include <builtin.h>
+
+int __connman_plugin_init(const char *pattern, const char *exclude)
+{
+	gchar **patterns = NULL;
+	gchar **excludes = NULL;
+	GSList *list;
+	GDir *dir;
+	const gchar *file;
+	gchar *filename;
+	unsigned int i;
+
+	DBG("");
+
+	if (pattern)
+		patterns = g_strsplit_set(pattern, ":, ", -1);
+
+	if (exclude)
+		excludes = g_strsplit_set(exclude, ":, ", -1);
+
+	for (i = 0; __connman_builtin[i]; i++) {
+		if (!check_plugin(__connman_builtin[i], patterns, excludes))
+			continue;
+
+		add_plugin(NULL, __connman_builtin[i]);
+	}
+
+	dir = g_dir_open(PLUGINDIR, 0, NULL);
+	if (dir) {
+		while ((file = g_dir_read_name(dir))) {
+			void *handle;
+			struct connman_plugin_desc *desc;
+
+			if (g_str_has_prefix(file, "lib") ||
+					!g_str_has_suffix(file, ".so"))
+				continue;
+
+			filename = g_build_filename(PLUGINDIR, file, NULL);
+
+			handle = dlopen(filename, RTLD_NOW);
+			if (!handle) {
+				connman_error("Can't load %s: %s",
+							filename, dlerror());
+				g_free(filename);
+				continue;
+			}
+
+			g_free(filename);
+
+			desc = dlsym(handle, "connman_plugin_desc");
+			if (!desc) {
+				connman_error("Can't load symbol: %s",
+								dlerror());
+				dlclose(handle);
+				continue;
+			}
+
+			if (!check_plugin(desc, patterns, excludes)) {
+				dlclose(handle);
+				continue;
+			}
+
+			if (!add_plugin(handle, desc))
+				dlclose(handle);
+		}
+
+		g_dir_close(dir);
+	}
+
+	for (list = plugins; list; list = list->next) {
+		struct connman_plugin *plugin = list->data;
+
+		if (plugin->desc->init() < 0)
+			continue;
+
+		plugin->active = true;
+	}
+
+	g_strfreev(patterns);
+	g_strfreev(excludes);
+
+	return 0;
+}
+
+void __connman_plugin_cleanup(void)
+{
+	GSList *list;
+
+	DBG("");
+
+	for (list = plugins; list; list = list->next) {
+		struct connman_plugin *plugin = list->data;
+
+		if (plugin->active && plugin->desc->exit)
+			plugin->desc->exit();
+
+		if (plugin->handle)
+			dlclose(plugin->handle);
+
+		g_free(plugin);
+	}
+
+	g_slist_free(plugins);
+}
diff --git a/connman/src/provider.c b/connman/src/provider.c
new file mode 100644
index 0000000..693552e
--- /dev/null
+++ b/connman/src/provider.c
@@ -0,0 +1,787 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2013  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 <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <gdbus.h>
+#include <gweb/gresolv.h>
+
+#include "connman.h"
+
+static DBusConnection *connection = NULL;
+
+static GHashTable *provider_hash = NULL;
+
+static GSList *driver_list = NULL;
+
+struct connman_provider {
+	int refcount;
+	bool immutable;
+	struct connman_service *vpn_service;
+	int index;
+	char *identifier;
+	int family;
+	struct connman_provider_driver *driver;
+	void *driver_data;
+};
+
+void __connman_provider_append_properties(struct connman_provider *provider,
+							DBusMessageIter *iter)
+{
+	const char *host, *domain, *type;
+
+	if (!provider->driver || !provider->driver->get_property)
+		return;
+
+	host = provider->driver->get_property(provider, "Host");
+	domain = provider->driver->get_property(provider, "Domain");
+	type = provider->driver->get_property(provider, "Type");
+
+	if (host)
+		connman_dbus_dict_append_basic(iter, "Host",
+					DBUS_TYPE_STRING, &host);
+
+	if (domain)
+		connman_dbus_dict_append_basic(iter, "Domain",
+					DBUS_TYPE_STRING, &domain);
+
+	if (type)
+		connman_dbus_dict_append_basic(iter, "Type", DBUS_TYPE_STRING,
+						 &type);
+}
+
+struct connman_provider *
+connman_provider_ref_debug(struct connman_provider *provider,
+			const char *file, int line, const char *caller)
+{
+	DBG("%p ref %d by %s:%d:%s()", provider, provider->refcount + 1,
+		file, line, caller);
+
+	__sync_fetch_and_add(&provider->refcount, 1);
+
+	return provider;
+}
+
+static void provider_remove(struct connman_provider *provider)
+{
+	if (provider->driver) {
+		provider->driver->remove(provider);
+		provider->driver = NULL;
+	}
+}
+
+static void provider_destruct(struct connman_provider *provider)
+{
+	DBG("provider %p", provider);
+
+	g_free(provider->identifier);
+	g_free(provider);
+}
+
+void connman_provider_unref_debug(struct connman_provider *provider,
+				const char *file, int line, const char *caller)
+{
+	DBG("%p ref %d by %s:%d:%s()", provider, provider->refcount - 1,
+		file, line, caller);
+
+	if (__sync_fetch_and_sub(&provider->refcount, 1) != 1)
+		return;
+
+	provider_destruct(provider);
+}
+
+static int provider_indicate_state(struct connman_provider *provider,
+					enum connman_service_state state)
+{
+	DBG("state %d", state);
+
+	__connman_service_ipconfig_indicate_state(provider->vpn_service, state,
+					CONNMAN_IPCONFIG_TYPE_IPV4);
+
+	return __connman_service_ipconfig_indicate_state(provider->vpn_service,
+					state, CONNMAN_IPCONFIG_TYPE_IPV6);
+}
+
+int connman_provider_disconnect(struct connman_provider *provider)
+{
+	int err;
+
+	DBG("provider %p", provider);
+
+	if (provider->driver && provider->driver->disconnect)
+		err = provider->driver->disconnect(provider);
+	else
+		return -EOPNOTSUPP;
+
+	if (provider->vpn_service)
+		provider_indicate_state(provider,
+					CONNMAN_SERVICE_STATE_DISCONNECT);
+
+	if (err < 0) {
+		if (err != -EINPROGRESS)
+			return err;
+
+		return -EINPROGRESS;
+	}
+
+	return 0;
+}
+
+int connman_provider_remove(struct connman_provider *provider)
+{
+	DBG("Removing VPN %s", provider->identifier);
+
+	provider_remove(provider);
+
+	connman_provider_set_state(provider, CONNMAN_PROVIDER_STATE_IDLE);
+
+	g_hash_table_remove(provider_hash, provider->identifier);
+
+	return 0;
+}
+
+int __connman_provider_connect(struct connman_provider *provider)
+{
+	int err;
+
+	DBG("provider %p", provider);
+
+	if (provider->driver && provider->driver->connect)
+		err = provider->driver->connect(provider);
+	else
+		return -EOPNOTSUPP;
+
+	if (err < 0) {
+		if (err != -EINPROGRESS)
+			return err;
+
+		provider_indicate_state(provider,
+					CONNMAN_SERVICE_STATE_ASSOCIATION);
+
+		return -EINPROGRESS;
+	}
+
+	return 0;
+}
+
+int __connman_provider_remove_by_path(const char *path)
+{
+	struct connman_provider *provider;
+	GHashTableIter iter;
+	gpointer value, key;
+
+	DBG("path %s", path);
+
+	g_hash_table_iter_init(&iter, provider_hash);
+	while (g_hash_table_iter_next(&iter, &key, &value)) {
+		const char *srv_path;
+		provider = value;
+
+		if (!provider->vpn_service)
+			continue;
+
+		srv_path = __connman_service_get_path(provider->vpn_service);
+
+		if (g_strcmp0(srv_path, path) == 0) {
+			DBG("Removing VPN %s", provider->identifier);
+
+			provider_remove(provider);
+
+			connman_provider_set_state(provider,
+						CONNMAN_PROVIDER_STATE_IDLE);
+
+			g_hash_table_remove(provider_hash,
+						provider->identifier);
+			return 0;
+		}
+	}
+
+	return -ENXIO;
+}
+
+static int set_connected(struct connman_provider *provider,
+					bool connected)
+{
+	struct connman_service *service = provider->vpn_service;
+	struct connman_ipconfig *ipconfig;
+
+	if (!service)
+		return -ENODEV;
+
+	ipconfig = __connman_service_get_ipconfig(service, provider->family);
+
+	if (connected) {
+		if (!ipconfig) {
+			provider_indicate_state(provider,
+						CONNMAN_SERVICE_STATE_FAILURE);
+			return -EIO;
+		}
+
+		__connman_ipconfig_address_add(ipconfig);
+		__connman_ipconfig_gateway_add(ipconfig);
+
+		provider_indicate_state(provider,
+					CONNMAN_SERVICE_STATE_READY);
+
+		if (provider->driver && provider->driver->set_routes)
+			provider->driver->set_routes(provider,
+						CONNMAN_PROVIDER_ROUTE_ALL);
+
+	} else {
+		if (ipconfig) {
+			provider_indicate_state(provider,
+					CONNMAN_SERVICE_STATE_DISCONNECT);
+			__connman_ipconfig_gateway_remove(ipconfig);
+		}
+
+		provider_indicate_state(provider,
+					CONNMAN_SERVICE_STATE_IDLE);
+	}
+
+	return 0;
+}
+
+int connman_provider_set_state(struct connman_provider *provider,
+					enum connman_provider_state state)
+{
+	if (!provider || !provider->vpn_service)
+		return -EINVAL;
+
+	switch (state) {
+	case CONNMAN_PROVIDER_STATE_UNKNOWN:
+		return -EINVAL;
+	case CONNMAN_PROVIDER_STATE_IDLE:
+		return set_connected(provider, false);
+	case CONNMAN_PROVIDER_STATE_CONNECT:
+		return provider_indicate_state(provider,
+					CONNMAN_SERVICE_STATE_ASSOCIATION);
+	case CONNMAN_PROVIDER_STATE_READY:
+		return set_connected(provider, true);
+	case CONNMAN_PROVIDER_STATE_DISCONNECT:
+		return provider_indicate_state(provider,
+					CONNMAN_SERVICE_STATE_DISCONNECT);
+	case CONNMAN_PROVIDER_STATE_FAILURE:
+		return provider_indicate_state(provider,
+					CONNMAN_SERVICE_STATE_FAILURE);
+	}
+
+	return -EINVAL;
+}
+
+int connman_provider_indicate_error(struct connman_provider *provider,
+					enum connman_provider_error error)
+{
+	enum connman_service_error service_error;
+
+	switch (error) {
+	case CONNMAN_PROVIDER_ERROR_LOGIN_FAILED:
+		service_error = CONNMAN_SERVICE_ERROR_LOGIN_FAILED;
+		break;
+	case CONNMAN_PROVIDER_ERROR_AUTH_FAILED:
+		service_error = CONNMAN_SERVICE_ERROR_AUTH_FAILED;
+		break;
+	case CONNMAN_PROVIDER_ERROR_CONNECT_FAILED:
+		service_error = CONNMAN_SERVICE_ERROR_CONNECT_FAILED;
+		break;
+	default:
+		service_error = CONNMAN_SERVICE_ERROR_UNKNOWN;
+		break;
+	}
+
+	return __connman_service_indicate_error(provider->vpn_service,
+							service_error);
+}
+
+int connman_provider_create_service(struct connman_provider *provider)
+{
+	if (provider->vpn_service) {
+		bool connected;
+
+		connected = __connman_service_is_connected_state(
+			provider->vpn_service, CONNMAN_IPCONFIG_TYPE_IPV4);
+		if (connected)
+			return -EALREADY;
+
+		connected = __connman_service_is_connected_state(
+			provider->vpn_service, CONNMAN_IPCONFIG_TYPE_IPV6);
+		if (connected)
+			return -EALREADY;
+
+		return 0;
+	}
+
+	provider->vpn_service =
+		__connman_service_create_from_provider(provider);
+
+	if (!provider->vpn_service) {
+		connman_warn("service creation failed for provider %s",
+			provider->identifier);
+
+		g_hash_table_remove(provider_hash, provider->identifier);
+		return -EOPNOTSUPP;
+	}
+
+	return 0;
+}
+
+bool __connman_provider_is_immutable(struct connman_provider *provider)
+
+{
+	if (provider)
+		return provider->immutable;
+
+	return false;
+}
+
+int connman_provider_set_immutable(struct connman_provider *provider,
+						bool immutable)
+{
+	if (!provider)
+		return -EINVAL;
+
+	provider->immutable = immutable;
+
+	return 0;
+}
+
+static struct connman_provider *provider_lookup(const char *identifier)
+{
+	return g_hash_table_lookup(provider_hash, identifier);
+}
+
+static void connection_ready(DBusMessage *msg, int error_code, void *user_data)
+{
+	DBusMessage *reply;
+	const char *identifier = user_data;
+
+	DBG("msg %p error %d", msg, error_code);
+
+	if (error_code != 0) {
+		reply = __connman_error_failed(msg, -error_code);
+		if (!g_dbus_send_message(connection, reply))
+			DBG("reply %p send failed", reply);
+	} else {
+		const char *path;
+		struct connman_provider *provider;
+
+		provider = provider_lookup(identifier);
+		if (!provider) {
+			reply = __connman_error_failed(msg, EINVAL);
+			g_dbus_send_message(connection, reply);
+			return;
+		}
+
+		path = __connman_service_get_path(provider->vpn_service);
+
+		g_dbus_send_reply(connection, msg,
+				DBUS_TYPE_OBJECT_PATH, &path,
+				DBUS_TYPE_INVALID);
+	}
+}
+
+int __connman_provider_create_and_connect(DBusMessage *msg)
+{
+	struct connman_provider_driver *driver;
+
+	if (!driver_list)
+		return -EINVAL;
+
+	driver = driver_list->data;
+	if (!driver || !driver->create)
+		return -EINVAL;
+
+	DBG("msg %p", msg);
+
+	return driver->create(msg, connection_ready);
+}
+
+const char *__connman_provider_get_ident(struct connman_provider *provider)
+{
+	if (!provider)
+		return NULL;
+
+	return provider->identifier;
+}
+
+int connman_provider_set_string(struct connman_provider *provider,
+					const char *key, const char *value)
+{
+	if (provider->driver && provider->driver->set_property)
+		return provider->driver->set_property(provider, key, value);
+
+	return 0;
+}
+
+const char *connman_provider_get_string(struct connman_provider *provider,
+							const char *key)
+{
+	if (provider->driver && provider->driver->get_property)
+		return provider->driver->get_property(provider, key);
+
+	return NULL;
+}
+
+bool
+__connman_provider_check_routes(struct connman_provider *provider)
+{
+	if (!provider)
+		return false;
+
+	if (provider->driver && provider->driver->check_routes)
+		return provider->driver->check_routes(provider);
+
+	return false;
+}
+
+void *connman_provider_get_data(struct connman_provider *provider)
+{
+	return provider->driver_data;
+}
+
+void connman_provider_set_data(struct connman_provider *provider, void *data)
+{
+	provider->driver_data = data;
+}
+
+void connman_provider_set_index(struct connman_provider *provider, int index)
+{
+	struct connman_service *service = provider->vpn_service;
+	struct connman_ipconfig *ipconfig;
+
+	DBG("");
+
+	if (!service)
+		return;
+
+	ipconfig = __connman_service_get_ip4config(service);
+
+	if (!ipconfig) {
+		connman_service_create_ip4config(service, index);
+
+		ipconfig = __connman_service_get_ip4config(service);
+		if (!ipconfig) {
+			DBG("Couldnt create ipconfig");
+			goto done;
+		}
+	}
+
+	__connman_ipconfig_set_method(ipconfig, CONNMAN_IPCONFIG_METHOD_OFF);
+	__connman_ipconfig_set_index(ipconfig, index);
+
+	ipconfig = __connman_service_get_ip6config(service);
+
+	if (!ipconfig) {
+		connman_service_create_ip6config(service, index);
+
+		ipconfig = __connman_service_get_ip6config(service);
+		if (!ipconfig) {
+			DBG("Couldnt create ipconfig for IPv6");
+			goto done;
+		}
+	}
+
+	__connman_ipconfig_set_method(ipconfig, CONNMAN_IPCONFIG_METHOD_OFF);
+	__connman_ipconfig_set_index(ipconfig, index);
+
+done:
+	provider->index = index;
+}
+
+int connman_provider_get_index(struct connman_provider *provider)
+{
+	return provider->index;
+}
+
+int connman_provider_set_ipaddress(struct connman_provider *provider,
+					struct connman_ipaddress *ipaddress)
+{
+	struct connman_ipconfig *ipconfig = NULL;
+
+	ipconfig = __connman_service_get_ipconfig(provider->vpn_service,
+							ipaddress->family);
+	if (!ipconfig)
+		return -EINVAL;
+
+	provider->family = ipaddress->family;
+
+	__connman_ipconfig_set_method(ipconfig, CONNMAN_IPCONFIG_METHOD_FIXED);
+
+	__connman_ipconfig_set_local(ipconfig, ipaddress->local);
+	__connman_ipconfig_set_peer(ipconfig, ipaddress->peer);
+	__connman_ipconfig_set_broadcast(ipconfig, ipaddress->broadcast);
+	__connman_ipconfig_set_gateway(ipconfig, ipaddress->gateway);
+	__connman_ipconfig_set_prefixlen(ipconfig, ipaddress->prefixlen);
+
+	return 0;
+}
+
+int connman_provider_set_pac(struct connman_provider *provider, const char *pac)
+{
+	DBG("provider %p pac %s", provider, pac);
+
+	__connman_service_set_pac(provider->vpn_service, pac);
+
+	return 0;
+}
+
+
+int connman_provider_set_domain(struct connman_provider *provider,
+					const char *domain)
+{
+	DBG("provider %p domain %s", provider, domain);
+
+	__connman_service_set_domainname(provider->vpn_service, domain);
+
+	return 0;
+}
+
+int connman_provider_set_nameservers(struct connman_provider *provider,
+					char * const *nameservers)
+{
+	int i;
+
+	DBG("provider %p nameservers %p", provider, nameservers);
+
+	__connman_service_nameserver_clear(provider->vpn_service);
+
+	if (!nameservers)
+		return 0;
+
+	for (i = 0; nameservers[i]; i++)
+		__connman_service_nameserver_append(provider->vpn_service,
+						nameservers[i], false);
+
+	return 0;
+}
+
+static void unregister_provider(gpointer data)
+{
+	struct connman_provider *provider = data;
+
+	DBG("provider %p service %p", provider, provider->vpn_service);
+
+	if (provider->vpn_service) {
+		connman_service_unref(provider->vpn_service);
+		provider->vpn_service = NULL;
+	}
+
+	connman_provider_unref(provider);
+}
+
+static gint compare_priority(gconstpointer a, gconstpointer b)
+{
+	return 0;
+}
+
+int connman_provider_driver_register(struct connman_provider_driver *driver)
+{
+	DBG("driver %p name %s", driver, driver->name);
+
+	driver_list = g_slist_insert_sorted(driver_list, driver,
+							compare_priority);
+	return 0;
+}
+
+void connman_provider_driver_unregister(struct connman_provider_driver *driver)
+{
+	DBG("driver %p name %s", driver, driver->name);
+
+	driver_list = g_slist_remove(driver_list, driver);
+}
+
+void connman_provider_set_driver(struct connman_provider *provider,
+				struct connman_provider_driver *driver)
+{
+	provider->driver = driver;
+}
+
+static void provider_disconnect_all(gpointer key, gpointer value,
+						gpointer user_data)
+{
+	struct connman_provider *provider = value;
+
+	connman_provider_disconnect(provider);
+}
+
+static void provider_offline_mode(bool enabled)
+{
+	DBG("enabled %d", enabled);
+
+	if (enabled)
+		g_hash_table_foreach(provider_hash, provider_disconnect_all,
+									NULL);
+
+}
+
+static void provider_initialize(struct connman_provider *provider)
+{
+	DBG("provider %p", provider);
+
+	provider->index = 0;
+	provider->identifier = NULL;
+}
+
+static struct connman_provider *provider_new(void)
+{
+	struct connman_provider *provider;
+
+	provider = g_try_new0(struct connman_provider, 1);
+	if (!provider)
+		return NULL;
+
+	provider->refcount = 1;
+
+	DBG("provider %p", provider);
+	provider_initialize(provider);
+
+	return provider;
+}
+
+struct connman_provider *connman_provider_get(const char *identifier)
+{
+	struct connman_provider *provider;
+
+	provider = g_hash_table_lookup(provider_hash, identifier);
+	if (provider)
+		return provider;
+
+	provider = provider_new();
+	if (!provider)
+		return NULL;
+
+	DBG("provider %p", provider);
+
+	provider->identifier = g_strdup(identifier);
+
+	g_hash_table_insert(provider_hash, provider->identifier, provider);
+
+	return provider;
+}
+
+void connman_provider_put(struct connman_provider *provider)
+{
+	g_hash_table_remove(provider_hash, provider->identifier);
+}
+
+static struct connman_provider *provider_get(int index)
+{
+	GHashTableIter iter;
+	gpointer value, key;
+
+	g_hash_table_iter_init(&iter, provider_hash);
+
+	while (g_hash_table_iter_next(&iter, &key, &value)) {
+		struct connman_provider *provider = value;
+
+		if (provider->index == index)
+			return provider;
+	}
+
+	return NULL;
+}
+
+static void provider_service_changed(struct connman_service *service,
+				enum connman_service_state state)
+{
+	struct connman_provider *provider;
+	int vpn_index, service_index;
+
+	if (!service)
+		return;
+
+	switch (state) {
+	case CONNMAN_SERVICE_STATE_UNKNOWN:
+	case CONNMAN_SERVICE_STATE_IDLE:
+	case CONNMAN_SERVICE_STATE_ASSOCIATION:
+	case CONNMAN_SERVICE_STATE_CONFIGURATION:
+	case CONNMAN_SERVICE_STATE_READY:
+	case CONNMAN_SERVICE_STATE_ONLINE:
+		return;
+	case CONNMAN_SERVICE_STATE_DISCONNECT:
+	case CONNMAN_SERVICE_STATE_FAILURE:
+		break;
+	}
+
+	service_index = __connman_service_get_index(service);
+
+	vpn_index = __connman_connection_get_vpn_index(service_index);
+
+	DBG("service %p %s state %d index %d/%d", service,
+		__connman_service_get_ident(service),
+		state, service_index, vpn_index);
+
+	if (vpn_index < 0)
+		return;
+
+	provider = provider_get(vpn_index);
+	if (!provider)
+		return;
+
+	DBG("disconnect %p index %d", provider, vpn_index);
+
+	connman_provider_disconnect(provider);
+
+	return;
+}
+
+static struct connman_notifier provider_notifier = {
+	.name			= "provider",
+	.offline_mode		= provider_offline_mode,
+	.service_state_changed	= provider_service_changed,
+};
+
+int __connman_provider_init(void)
+{
+	int err;
+
+	DBG("");
+
+	connection = connman_dbus_get_connection();
+
+	provider_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
+						NULL, unregister_provider);
+
+	err = connman_notifier_register(&provider_notifier);
+	if (err < 0) {
+		g_hash_table_destroy(provider_hash);
+		dbus_connection_unref(connection);
+	}
+
+	return err;
+}
+
+void __connman_provider_cleanup(void)
+{
+	DBG("");
+
+	connman_notifier_unregister(&provider_notifier);
+
+	g_hash_table_destroy(provider_hash);
+	provider_hash = NULL;
+
+	dbus_connection_unref(connection);
+}
diff --git a/connman/src/proxy.c b/connman/src/proxy.c
new file mode 100644
index 0000000..f331de9
--- /dev/null
+++ b/connman/src/proxy.c
@@ -0,0 +1,251 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2012  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 <glib.h>
+
+#include "connman.h"
+
+static unsigned int next_lookup_token = 1;
+
+static GSList *driver_list = NULL;
+static GSList *lookup_list = NULL;
+
+struct proxy_lookup {
+	unsigned int token;
+	connman_proxy_lookup_cb cb;
+	void *user_data;
+	struct connman_service *service;
+	char *url;
+	guint watch;
+	struct connman_proxy_driver *proxy;
+};
+
+static void remove_lookup(struct proxy_lookup *lookup)
+{
+	if (lookup->watch > 0)
+		g_source_remove(lookup->watch);
+
+	lookup_list = g_slist_remove(lookup_list, lookup);
+
+	connman_service_unref(lookup->service);
+	g_free(lookup->url);
+	g_free(lookup);
+}
+
+static void remove_lookups(GSList *lookups)
+{
+	GSList *list;
+
+	for (list = lookups; list; list = list->next) {
+		struct proxy_lookup *lookup = list->data;
+
+		remove_lookup(lookup);
+	}
+
+	g_slist_free(lookups);
+}
+
+static gboolean lookup_callback(gpointer user_data)
+{
+	struct proxy_lookup *lookup = user_data;
+	GSList *list;
+
+	if (!lookup)
+		return FALSE;
+
+	lookup->watch = 0;
+
+	for (list = driver_list; list; list = list->next) {
+		struct connman_proxy_driver *proxy = list->data;
+
+		if (!proxy->request_lookup)
+			continue;
+
+		lookup->proxy = proxy;
+		break;
+	}
+
+	if (!lookup->proxy ||
+		lookup->proxy->request_lookup(lookup->service,
+						lookup->url) < 0) {
+
+		if (lookup->cb)
+			lookup->cb(NULL, lookup->user_data);
+
+		remove_lookup(lookup);
+	}
+
+	return FALSE;
+}
+
+unsigned int connman_proxy_lookup(const char *interface, const char *url,
+					struct connman_service *service,
+					connman_proxy_lookup_cb cb,
+					void *user_data)
+{
+	struct proxy_lookup *lookup;
+
+	DBG("interface %s url %s", interface, url);
+
+	if (!interface)
+		return 0;
+
+	lookup = g_try_new0(struct proxy_lookup, 1);
+	if (!lookup)
+		return 0;
+
+	lookup->token = next_lookup_token++;
+
+	lookup->cb = cb;
+	lookup->user_data = user_data;
+	lookup->url = g_strdup(url);
+	lookup->service = connman_service_ref(service);
+
+	lookup->watch = g_timeout_add_seconds(0, lookup_callback, lookup);
+	if (lookup->watch == 0) {
+		g_free(lookup->url);
+		g_free(lookup);
+		return 0;
+	}
+
+	DBG("token %u", lookup->token);
+	lookup_list = g_slist_prepend(lookup_list, lookup);
+
+	return lookup->token;
+}
+
+void connman_proxy_lookup_cancel(unsigned int token)
+{
+	GSList *list;
+	struct proxy_lookup *lookup = NULL;
+
+	DBG("token %u", token);
+
+	for (list = lookup_list; list; list = list->next) {
+		lookup = list->data;
+
+		if (lookup->token == token)
+			break;
+
+		lookup = NULL;
+	}
+
+	if (lookup) {
+		if (lookup->proxy &&
+					lookup->proxy->cancel_lookup)
+			lookup->proxy->cancel_lookup(lookup->service,
+								lookup->url);
+
+		remove_lookup(lookup);
+	}
+}
+
+void connman_proxy_driver_lookup_notify(struct connman_service *service,
+					const char *url, const char *result)
+{
+	GSList *list, *matches = NULL;
+
+	DBG("service %p url %s result %s", service, url, result);
+
+	for (list = lookup_list; list; list = list->next) {
+		struct proxy_lookup *lookup = list->data;
+
+		if (service != lookup->service)
+			continue;
+
+		if (g_strcmp0(lookup->url, url) == 0) {
+			if (lookup->cb)
+				lookup->cb(result, lookup->user_data);
+
+			matches = g_slist_prepend(matches, lookup);
+		}
+	}
+
+	if (matches)
+		remove_lookups(matches);
+}
+
+static gint compare_priority(gconstpointer a, gconstpointer b)
+{
+	const struct connman_proxy_driver *driver1 = a;
+	const struct connman_proxy_driver *driver2 = b;
+
+	return driver2->priority - driver1->priority;
+}
+
+/**
+ * connman_proxy_driver_register:
+ * @driver: Proxy driver definition
+ *
+ * Register a new proxy driver
+ *
+ * Returns: %0 on success
+ */
+int connman_proxy_driver_register(struct connman_proxy_driver *driver)
+{
+	DBG("driver %p name %s", driver, driver->name);
+
+	driver_list = g_slist_insert_sorted(driver_list, driver,
+							compare_priority);
+
+	return 0;
+}
+
+/**
+ * connman_proxy_driver_unregister:
+ * @driver: Proxy driver definition
+ *
+ * Remove a previously registered proxy driver
+ */
+void connman_proxy_driver_unregister(struct connman_proxy_driver *driver)
+{
+	GSList *list;
+
+	DBG("driver %p name %s", driver, driver->name);
+
+	driver_list = g_slist_remove(driver_list, driver);
+
+	for (list = lookup_list; list; list = list->next) {
+		struct proxy_lookup *lookup = list->data;
+
+		if (lookup->proxy == driver)
+			lookup->proxy = NULL;
+	}
+
+}
+
+int __connman_proxy_init(void)
+{
+	DBG("");
+
+	return 0;
+}
+
+void __connman_proxy_cleanup(void)
+{
+	DBG("");
+
+	remove_lookups(lookup_list);
+}
diff --git a/connman/src/resolver.c b/connman/src/resolver.c
new file mode 100644
index 0000000..6a64938
--- /dev/null
+++ b/connman/src/resolver.c
@@ -0,0 +1,668 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2013  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
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <resolv.h>
+#include <netdb.h>
+
+#include "connman.h"
+
+#define RESOLVER_FLAG_PUBLIC (1 << 0)
+
+/*
+ * Threshold for RDNSS lifetime. Will be used to trigger RS
+ * before RDNSS entries actually expire
+ */
+#define RESOLVER_LIFETIME_REFRESH_THRESHOLD 0.8
+
+struct entry_data {
+	int index;
+	char *domain;
+	char *server;
+	int family;
+	unsigned int flags;
+	unsigned int lifetime;
+	guint timeout;
+};
+
+static GSList *entry_list = NULL;
+static bool dnsproxy_enabled = false;
+
+struct resolvfile_entry {
+	int index;
+	char *domain;
+	char *server;
+};
+
+static GList *resolvfile_list = NULL;
+
+static void resolvfile_remove_entries(GList *entries)
+{
+	GList *list;
+
+	for (list = entries; list; list = list->next) {
+		struct resolvfile_entry *entry = list->data;
+
+		resolvfile_list = g_list_remove(resolvfile_list, entry);
+
+		g_free(entry->server);
+		g_free(entry->domain);
+		g_free(entry);
+	}
+
+	g_list_free(entries);
+}
+
+static int resolvfile_export(void)
+{
+	GList *list;
+	GString *content;
+	int fd, err;
+	unsigned int count;
+	mode_t old_umask;
+
+	content = g_string_new("# Generated by Connection Manager\n");
+
+	/*
+	 * Domains and nameservers are added in reverse so that the most
+	 * recently appended entry is the primary one. No more than
+	 * MAXDNSRCH/MAXNS entries are used.
+	 */
+
+	for (count = 0, list = g_list_last(resolvfile_list);
+						list && (count < MAXDNSRCH);
+						list = g_list_previous(list)) {
+		struct resolvfile_entry *entry = list->data;
+
+		if (!entry->domain)
+			continue;
+
+		if (count == 0)
+			g_string_append_printf(content, "search ");
+
+		g_string_append_printf(content, "%s ", entry->domain);
+		count++;
+	}
+
+	if (count)
+		g_string_append_printf(content, "\n");
+
+	for (count = 0, list = g_list_last(resolvfile_list);
+						list && (count < MAXNS);
+						list = g_list_previous(list)) {
+		struct resolvfile_entry *entry = list->data;
+
+		if (!entry->server)
+			continue;
+
+		g_string_append_printf(content, "nameserver %s\n",
+								entry->server);
+		count++;
+	}
+
+	old_umask = umask(022);
+
+	fd = open("/etc/resolv.conf", O_RDWR | O_CREAT | O_CLOEXEC,
+					S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+	if (fd < 0) {
+		err = -errno;
+		goto done;
+	}
+
+	if (ftruncate(fd, 0) < 0) {
+		err = -errno;
+		goto failed;
+	}
+
+	err = 0;
+
+	if (write(fd, content->str, content->len) < 0)
+		err = -errno;
+
+failed:
+	close(fd);
+
+done:
+	g_string_free(content, TRUE);
+	umask(old_umask);
+
+	return err;
+}
+
+int __connman_resolvfile_append(int index, const char *domain,
+							const char *server)
+{
+	struct resolvfile_entry *entry;
+
+	DBG("index %d server %s", index, server);
+
+	if (index < 0)
+		return -ENOENT;
+
+	entry = g_try_new0(struct resolvfile_entry, 1);
+	if (!entry)
+		return -ENOMEM;
+
+	entry->index = index;
+	entry->domain = g_strdup(domain);
+	entry->server = g_strdup(server);
+
+	resolvfile_list = g_list_append(resolvfile_list, entry);
+
+	return resolvfile_export();
+}
+
+int __connman_resolvfile_remove(int index, const char *domain,
+							const char *server)
+{
+	GList *list, *matches = NULL;
+
+	DBG("index %d server %s", index, server);
+
+	for (list = resolvfile_list; list; list = g_list_next(list)) {
+		struct resolvfile_entry *entry = list->data;
+
+		if (index >= 0 && entry->index != index)
+			continue;
+
+		if (domain && g_strcmp0(entry->domain, domain) != 0)
+			continue;
+
+		if (g_strcmp0(entry->server, server) != 0)
+			continue;
+
+		matches = g_list_append(matches, entry);
+	}
+
+	resolvfile_remove_entries(matches);
+
+	return resolvfile_export();
+}
+
+static void append_fallback_nameservers(void)
+{
+	GSList *list;
+
+	for (list = entry_list; list; list = list->next) {
+		struct entry_data *entry = list->data;
+
+		if (entry->index >= 0 && entry->server)
+			return;
+	}
+
+	for (list = entry_list; list; list = list->next) {
+		struct entry_data *entry = list->data;
+
+		if (entry->index != -1 || !entry->server)
+			continue;
+
+		DBG("index %d server %s", entry->index, entry->server);
+
+		if (dnsproxy_enabled) {
+			__connman_dnsproxy_append(entry->index, entry->domain,
+					entry->server);
+		} else {
+			__connman_resolvfile_append(entry->index,
+					entry->domain, entry->server);
+		}
+	}
+}
+
+static void remove_fallback_nameservers(void)
+{
+	GSList *list;
+
+	for (list = entry_list; list; list = list->next) {
+		struct entry_data *entry = list->data;
+
+		if (entry->index >= 0 || !entry->server)
+			continue;
+
+		DBG("index %d server %s", entry->index, entry->server);
+
+		if (dnsproxy_enabled) {
+			__connman_dnsproxy_remove(entry->index, entry->domain,
+					entry->server);
+		} else {
+			__connman_resolvfile_remove(entry->index,
+					entry->domain, entry->server);
+		}
+	}
+}
+
+static void remove_entries(GSList *entries)
+{
+	GSList *list;
+
+	for (list = entries; list; list = list->next) {
+		struct entry_data *entry = list->data;
+
+		entry_list = g_slist_remove(entry_list, entry);
+
+		if (dnsproxy_enabled) {
+			__connman_dnsproxy_remove(entry->index, entry->domain,
+							entry->server);
+		} else {
+			__connman_resolvfile_remove(entry->index, entry->domain,
+							entry->server);
+		}
+
+		if (entry->timeout)
+			g_source_remove(entry->timeout);
+		g_free(entry->server);
+		g_free(entry->domain);
+		g_free(entry);
+	}
+
+	g_slist_free(entries);
+
+	append_fallback_nameservers();
+}
+
+static gboolean resolver_expire_cb(gpointer user_data)
+{
+	struct entry_data *entry = user_data;
+	GSList *list;
+
+	DBG("index %d domain %s server %s",
+			entry->index, entry->domain, entry->server);
+
+	list = g_slist_prepend(NULL, entry);
+
+	if (entry->index >= 0) {
+		struct connman_service *service;
+		service = __connman_service_lookup_from_index(entry->index);
+		if (service)
+			__connman_service_nameserver_remove(service,
+							entry->server, true);
+	}
+
+	remove_entries(list);
+
+	return FALSE;
+}
+
+static gboolean resolver_refresh_cb(gpointer user_data)
+{
+	struct entry_data *entry = user_data;
+	unsigned int interval;
+	struct connman_service *service = NULL;
+
+	/* Round up what we have left from lifetime */
+	interval = entry->lifetime *
+		(1 - RESOLVER_LIFETIME_REFRESH_THRESHOLD) + 1.0;
+
+	DBG("RDNSS start index %d domain %s "
+			"server %s remaining lifetime %d",
+			entry->index, entry->domain,
+			entry->server, interval);
+
+	entry->timeout = g_timeout_add_seconds(interval,
+			resolver_expire_cb, entry);
+
+	if (entry->index >= 0) {
+		service = __connman_service_lookup_from_index(entry->index);
+		if (service) {
+			/*
+			 * Send Router Solicitation to refresh RDNSS entries
+			 * before their lifetime expires
+			 */
+			__connman_network_refresh_rs_ipv6(
+					__connman_service_get_network(service),
+					entry->index);
+		}
+	}
+	return FALSE;
+}
+
+static int append_resolver(int index, const char *domain,
+				const char *server, unsigned int lifetime,
+							unsigned int flags)
+{
+	struct entry_data *entry;
+	unsigned int interval;
+
+	DBG("index %d domain %s server %s lifetime %d flags %d",
+				index, domain, server, lifetime, flags);
+
+	if (!server && !domain)
+		return -EINVAL;
+
+	entry = g_try_new0(struct entry_data, 1);
+	if (!entry)
+		return -ENOMEM;
+
+	entry->index = index;
+	entry->domain = g_strdup(domain);
+	entry->server = g_strdup(server);
+	entry->flags = flags;
+	entry->lifetime = lifetime;
+
+	if (server)
+		entry->family = connman_inet_check_ipaddress(server);
+
+	if (lifetime) {
+		interval = lifetime * RESOLVER_LIFETIME_REFRESH_THRESHOLD;
+
+		DBG("RDNSS start index %d domain %s "
+				"server %s lifetime threshold %d",
+				index, domain, server, interval);
+
+		entry->timeout = g_timeout_add_seconds(interval,
+				resolver_refresh_cb, entry);
+
+		/*
+		 * We update the service only for those nameservers
+		 * that are automagically added via netlink (lifetime > 0)
+		 */
+		if (server && entry->index >= 0) {
+			struct connman_service *service;
+			service = __connman_service_lookup_from_index(entry->index);
+			if (service)
+				__connman_service_nameserver_append(service,
+								server, true);
+		}
+	}
+
+	if (entry->index >= 0 && entry->server)
+		remove_fallback_nameservers();
+
+	entry_list = g_slist_append(entry_list, entry);
+
+	if (dnsproxy_enabled)
+		__connman_dnsproxy_append(entry->index, domain, server);
+	else
+		__connman_resolvfile_append(entry->index, domain, server);
+
+	return 0;
+}
+
+/**
+ * connman_resolver_append:
+ * @index: network interface index
+ * @domain: domain limitation
+ * @server: server address
+ *
+ * Append resolver server address to current list
+ */
+int connman_resolver_append(int index, const char *domain,
+						const char *server)
+{
+	GSList *list;
+
+	DBG("index %d domain %s server %s", index, domain, server);
+
+	if (!server && !domain)
+		return -EINVAL;
+
+	for (list = entry_list; list; list = list->next) {
+		struct entry_data *entry = list->data;
+
+		if (entry->timeout > 0)
+			continue;
+
+		if (entry->index == index &&
+				g_strcmp0(entry->domain, domain) == 0 &&
+				g_strcmp0(entry->server, server) == 0) {
+			if (dnsproxy_enabled)
+				__connman_dnsproxy_append(entry->index, domain,
+						server);
+
+			return -EEXIST;
+		}
+	}
+
+	return append_resolver(index, domain, server, 0, 0);
+}
+
+/**
+ * connman_resolver_append_lifetime:
+ * @index: network interface index
+ * @domain: domain limitation
+ * @server: server address
+ * @timeout: server lifetime in seconds
+ *
+ * Append resolver server address to current list
+ */
+int connman_resolver_append_lifetime(int index, const char *domain,
+				const char *server, unsigned int lifetime)
+{
+	GSList *list;
+	unsigned int interval;
+
+	DBG("index %d domain %s server %s lifetime %d",
+				index, domain, server, lifetime);
+
+	if (!server && !domain)
+		return -EINVAL;
+
+	for (list = entry_list; list; list = list->next) {
+		struct entry_data *entry = list->data;
+
+		if (entry->timeout == 0 ||
+				entry->index != index ||
+				g_strcmp0(entry->domain, domain) != 0 ||
+				g_strcmp0(entry->server, server) != 0)
+			continue;
+
+		g_source_remove(entry->timeout);
+
+		if (lifetime == 0) {
+			resolver_expire_cb(entry);
+			return 0;
+		}
+
+		interval = lifetime * RESOLVER_LIFETIME_REFRESH_THRESHOLD;
+
+		DBG("RDNSS start index %d domain %s "
+				"server %s lifetime threshold %d",
+				index, domain, server, interval);
+
+		entry->timeout = g_timeout_add_seconds(interval,
+				resolver_refresh_cb, entry);
+		return 0;
+	}
+
+	return append_resolver(index, domain, server, lifetime, 0);
+}
+
+/**
+ * connman_resolver_remove:
+ * @index: network interface index
+ * @domain: domain limitation
+ * @server: server address
+ *
+ * Remover resolver server address from current list
+ */
+int connman_resolver_remove(int index, const char *domain, const char *server)
+{
+	GSList *list, *matches = NULL;
+
+	DBG("index %d domain %s server %s", index, domain, server);
+
+	for (list = entry_list; list; list = list->next) {
+		struct entry_data *entry = list->data;
+
+		if (entry->index != index)
+			continue;
+
+		if (g_strcmp0(entry->domain, domain) != 0)
+			continue;
+
+		if (g_strcmp0(entry->server, server) != 0)
+			continue;
+
+		matches = g_slist_prepend(matches, entry);
+		break;
+	}
+
+	if (!matches)
+		return -ENOENT;
+
+	remove_entries(matches);
+
+	return 0;
+}
+
+/**
+ * connman_resolver_remove_all:
+ * @index: network interface index
+ *
+ * Remove all resolver server address for the specified interface index
+ */
+int connman_resolver_remove_all(int index)
+{
+	GSList *list, *matches = NULL;
+
+	DBG("index %d", index);
+
+	if (index < 0)
+		return -EINVAL;
+
+	for (list = entry_list; list; list = list->next) {
+		struct entry_data *entry = list->data;
+
+		if (entry->index != index)
+			continue;
+
+		matches = g_slist_prepend(matches, entry);
+	}
+
+	if (!matches)
+		return -ENOENT;
+
+	remove_entries(matches);
+
+	return 0;
+}
+
+int __connman_resolver_redo_servers(int index)
+{
+	GSList *list;
+
+	if (!dnsproxy_enabled)
+		return 0;
+
+	DBG("index %d", index);
+
+	if (index < 0)
+		return -EINVAL;
+
+	for (list = entry_list; list; list = list->next) {
+		struct entry_data *entry = list->data;
+
+		if (entry->timeout == 0 || entry->index != index)
+			continue;
+
+		/*
+		 * This function must only check IPv6 server addresses so
+		 * do not remove IPv4 name servers unnecessarily.
+		 */
+		if (entry->family != AF_INET6)
+			continue;
+
+		/*
+		 * We remove the server, and then re-create so that it will
+		 * use proper source addresses when sending DNS queries.
+		 */
+		__connman_dnsproxy_remove(entry->index, entry->domain,
+					entry->server);
+
+		__connman_dnsproxy_append(entry->index, entry->domain,
+					entry->server);
+	}
+
+	return 0;
+}
+
+static void free_entry(gpointer data)
+{
+	struct entry_data *entry = data;
+	g_free(entry->domain);
+	g_free(entry->server);
+	g_free(entry);
+}
+
+static void free_resolvfile(gpointer data)
+{
+	struct resolvfile_entry *entry = data;
+	g_free(entry->domain);
+	g_free(entry->server);
+	g_free(entry);
+}
+
+int __connman_resolver_init(gboolean dnsproxy)
+{
+	int i;
+	char **ns;
+
+	DBG("dnsproxy %d", dnsproxy);
+
+	if (!dnsproxy)
+		return 0;
+
+	if (__connman_dnsproxy_init() < 0) {
+		/* Fall back to resolv.conf */
+		return 0;
+	}
+
+	dnsproxy_enabled = true;
+
+	ns = connman_setting_get_string_list("FallbackNameservers");
+	for (i = 0; ns && ns[i]; i += 1) {
+		DBG("server %s", ns[i]);
+		append_resolver(-1, NULL, ns[i], 0, RESOLVER_FLAG_PUBLIC);
+	}
+
+	return 0;
+}
+
+void __connman_resolver_cleanup(void)
+{
+	DBG("");
+
+	if (dnsproxy_enabled)
+		__connman_dnsproxy_cleanup();
+	else {
+		GList *list;
+		GSList *slist;
+
+		for (list = resolvfile_list; list; list = g_list_next(list))
+			free_resolvfile(list->data);
+		g_list_free(resolvfile_list);
+		resolvfile_list = NULL;
+
+		for (slist = entry_list; slist; slist = g_slist_next(slist))
+			free_entry(slist->data);
+		g_slist_free(entry_list);
+		entry_list = NULL;
+	}
+}
diff --git a/connman/src/rfkill.c b/connman/src/rfkill.c
new file mode 100644
index 0000000..ecd3aa6
--- /dev/null
+++ b/connman/src/rfkill.c
@@ -0,0 +1,236 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2013  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
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdint.h>
+
+#include "connman.h"
+
+enum rfkill_type {
+	RFKILL_TYPE_ALL = 0,
+	RFKILL_TYPE_WLAN,
+	RFKILL_TYPE_BLUETOOTH,
+	RFKILL_TYPE_UWB,
+	RFKILL_TYPE_WWAN,
+	RFKILL_TYPE_GPS,
+	RFKILL_TYPE_FM,
+	NUM_RFKILL_TYPES,
+};
+
+enum rfkill_operation {
+	RFKILL_OP_ADD = 0,
+	RFKILL_OP_DEL,
+	RFKILL_OP_CHANGE,
+	RFKILL_OP_CHANGE_ALL,
+};
+
+struct rfkill_event {
+	uint32_t idx;
+	uint8_t  type;
+	uint8_t  op;
+	uint8_t  soft;
+	uint8_t  hard;
+};
+
+static enum connman_service_type convert_type(uint8_t type)
+{
+	switch (type) {
+	case RFKILL_TYPE_WLAN:
+		return CONNMAN_SERVICE_TYPE_WIFI;
+	case RFKILL_TYPE_BLUETOOTH:
+		return CONNMAN_SERVICE_TYPE_BLUETOOTH;
+	case RFKILL_TYPE_WWAN:
+		return CONNMAN_SERVICE_TYPE_CELLULAR;
+	}
+
+	return CONNMAN_SERVICE_TYPE_UNKNOWN;
+}
+
+static enum rfkill_type convert_service_type(enum connman_service_type type)
+{
+	switch (type) {
+	case CONNMAN_SERVICE_TYPE_LOWPAN:
+	case CONNMAN_SERVICE_TYPE_WIFI:
+		return RFKILL_TYPE_WLAN;
+	case CONNMAN_SERVICE_TYPE_BLUETOOTH:
+		return RFKILL_TYPE_BLUETOOTH;
+	case CONNMAN_SERVICE_TYPE_CELLULAR:
+		return RFKILL_TYPE_WWAN;
+	case CONNMAN_SERVICE_TYPE_GPS:
+		return RFKILL_TYPE_GPS;
+	case CONNMAN_SERVICE_TYPE_SYSTEM:
+	case CONNMAN_SERVICE_TYPE_ETHERNET:
+	case CONNMAN_SERVICE_TYPE_VPN:
+	case CONNMAN_SERVICE_TYPE_GADGET:
+	case CONNMAN_SERVICE_TYPE_P2P:
+	case CONNMAN_SERVICE_TYPE_UNKNOWN:
+		return NUM_RFKILL_TYPES;
+	}
+
+	return NUM_RFKILL_TYPES;
+}
+
+static GIOStatus rfkill_process(GIOChannel *chan)
+{
+	unsigned char buf[32];
+	struct rfkill_event *event = (void *) buf;
+	enum connman_service_type type;
+	gsize len;
+	GIOStatus status;
+
+	DBG("");
+
+	memset(buf, 0, sizeof(buf));
+
+	status = g_io_channel_read_chars(chan, (gchar *) buf,
+			sizeof(struct rfkill_event), &len, NULL);
+
+	if (status != G_IO_STATUS_NORMAL)
+		return status;
+
+	if (len != sizeof(struct rfkill_event))
+		return status;
+
+	DBG("idx %u type %u op %u soft %u hard %u", event->idx,
+						event->type, event->op,
+						event->soft, event->hard);
+
+	type = convert_type(event->type);
+
+	switch (event->op) {
+	case RFKILL_OP_ADD:
+		__connman_technology_add_rfkill(event->idx, type,
+						event->soft, event->hard);
+		break;
+	case RFKILL_OP_DEL:
+		__connman_technology_remove_rfkill(event->idx, type);
+		break;
+	case RFKILL_OP_CHANGE:
+		__connman_technology_update_rfkill(event->idx, type,
+						event->soft, event->hard);
+		break;
+	default:
+		break;
+	}
+
+	return status;
+}
+
+static gboolean rfkill_event(GIOChannel *chan, GIOCondition cond, gpointer data)
+{
+	if (cond & (G_IO_NVAL | G_IO_HUP | G_IO_ERR))
+		return FALSE;
+
+	if (rfkill_process(chan) == G_IO_STATUS_ERROR)
+		return FALSE;
+
+	return TRUE;
+}
+
+static guint watch = 0;
+
+int __connman_rfkill_block(enum connman_service_type type, bool block)
+{
+	uint8_t rfkill_type;
+	struct rfkill_event event;
+	ssize_t len;
+	int fd, err = 0;
+
+	DBG("type %d block %d", type, block);
+
+	rfkill_type = convert_service_type(type);
+	if (rfkill_type == NUM_RFKILL_TYPES)
+		return -EINVAL;
+
+	fd = open("/dev/rfkill", O_RDWR | O_CLOEXEC);
+	if (fd < 0)
+		return -errno;
+
+	memset(&event, 0, sizeof(event));
+	event.op = RFKILL_OP_CHANGE_ALL;
+	event.type = rfkill_type;
+	event.soft = block;
+
+	len = write(fd, &event, sizeof(event));
+	if (len < 0) {
+		err = -errno;
+		connman_error("Failed to change RFKILL state");
+	}
+
+	close(fd);
+
+	return err;
+}
+
+int __connman_rfkill_init(void)
+{
+	GIOChannel *channel;
+	GIOFlags flags;
+	int fd;
+
+	DBG("");
+
+	fd = open("/dev/rfkill", O_RDWR | O_CLOEXEC);
+	if (fd < 0) {
+		connman_error("Failed to open RFKILL control device");
+		return -EIO;
+	}
+
+	channel = g_io_channel_unix_new(fd);
+	g_io_channel_set_close_on_unref(channel, TRUE);
+
+	g_io_channel_set_encoding(channel, NULL, NULL);
+	g_io_channel_set_buffered(channel, FALSE);
+
+	flags = g_io_channel_get_flags(channel);
+	flags |= G_IO_FLAG_NONBLOCK;
+	g_io_channel_set_flags(channel, flags, NULL);
+
+	/* Process current RFKILL events sent on device open */
+	while (rfkill_process(channel) == G_IO_STATUS_NORMAL);
+
+	watch = g_io_add_watch(channel,
+				G_IO_IN | G_IO_NVAL | G_IO_HUP | G_IO_ERR,
+				rfkill_event, NULL);
+
+	g_io_channel_unref(channel);
+
+	return watch ? 0 : -EIO;
+}
+
+void __connman_rfkill_cleanup(void)
+{
+	DBG("");
+
+	if (watch) {
+		g_source_remove(watch);
+		watch = 0;
+	}
+}
diff --git a/connman/src/rlimits.c b/connman/src/rlimits.c
new file mode 100644
index 0000000..2499bc1
--- /dev/null
+++ b/connman/src/rlimits.c
@@ -0,0 +1,236 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2011 Nest Labs, Inc. All rights reserved.
+ *
+ *    Author: Grant Erickson <grant@nestlabs.com>
+ *
+ *  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 <string.h>
+
+#include <sys/resource.h>
+
+#include <glib.h>
+
+#include <connman/log.h>
+
+#define CONNMAN_RLIMIT_SET(r, lp, err, label)				\
+	do {								\
+		err = __connman_rlimit_set(r, lp, #r);			\
+		if (err < 0)						\
+			goto label;					\
+	} while (0)
+
+struct connman_rlimit {
+	gboolean set;
+	rlim_t limit;
+};
+
+struct connman_rlimits {
+#if defined(RLIMIT_AS)
+	struct connman_rlimit as;
+#endif
+	struct connman_rlimit core, data, fsize, nofile, stack;
+#if defined(RLIMIT_MEMLOCK)
+	struct connman_rlimit memlock;
+#endif
+#if defined(RLIMIT_NPROC)
+	struct connman_rlimit nproc;
+#endif
+};
+
+#if defined(RLIMIT_AS)
+static const char * RLIMIT_AS_KEY	= "rlimit-as";
+#endif
+static const char * RLIMIT_CORE_KEY	= "rlimit-core";
+static const char * RLIMIT_DATA_KEY	= "rlimit-data";
+static const char * RLIMIT_FSIZE_KEY	= "rlimit-fsize";
+static const char * RLIMIT_NOFILE_KEY	= "rlimit-nofile";
+static const char * RLIMIT_STACK_KEY 	= "rlimit-stack";
+#if defined(RLIMIT_NPROC)
+static const char * RLIMIT_NPROC_KEY 	= "rlimit-nproc";
+#endif
+#if defined(RLIMIT_MEMLOCK)
+static const char * RLIMIT_MEMLOCK_KEY	= "rlimit-memlock";
+#endif
+
+static int set_one_rlimit(int resource, rlim_t limit, const char *name)
+{
+	int err;
+	struct rlimit rl;
+	rl.rlim_cur = rl.rlim_max = limit;
+
+	DBG("resource %d limit %u name %s", resource, (unsigned)limit, name);
+
+	err = setrlimit(resource, &rl);
+
+	if (err < 0) {
+		connman_warn("setrlimit(%s, {%u, %u}) failed: %s",
+			     name, (unsigned)limit,
+			     (unsigned)limit,
+			     strerror(errno));
+
+		return -errno;
+	}
+
+	return err;
+}
+
+static inline int __connman_rlimit_set(int resource,
+				       const struct connman_rlimit *limit,
+				       const char *name)
+{
+	int err = 0;
+
+	if (limit->set)
+		err = set_one_rlimit(resource, limit->limit, name);
+
+	return err;
+}
+
+static int __connman_rlimits_enforce(const struct connman_rlimits *limits)
+{
+	int err;
+
+	if (limits == NULL)
+		return 0;
+
+#if defined(RLIMIT_AS)
+	CONNMAN_RLIMIT_SET(RLIMIT_AS,	   &limits->as,	     err, done);
+#endif
+	CONNMAN_RLIMIT_SET(RLIMIT_CORE,	   &limits->core,    err, done);
+	CONNMAN_RLIMIT_SET(RLIMIT_DATA,	   &limits->data,    err, done);
+	CONNMAN_RLIMIT_SET(RLIMIT_FSIZE,   &limits->fsize,   err, done);
+	CONNMAN_RLIMIT_SET(RLIMIT_NOFILE,  &limits->nofile,  err, done);
+	CONNMAN_RLIMIT_SET(RLIMIT_STACK,   &limits->stack,   err, done);
+#if defined(RLIMIT_MEMLOCK)
+	CONNMAN_RLIMIT_SET(RLIMIT_MEMLOCK, &limits->memlock, err, done);
+#endif
+#if defined(RLIMIT_NPROC)
+	CONNMAN_RLIMIT_SET(RLIMIT_NPROC,   &limits->nproc,   err, done);
+#endif
+
+ done:
+	return err;
+}
+
+static void __connman_rlimit_read(GKeyFile *keyfile, const gchar *key,
+				  struct connman_rlimit *limit)
+{
+	const char *group = "rlimits";
+	gint temp;
+	GError *error = NULL;
+
+	if (keyfile != NULL && key != NULL && limit != NULL) {
+		temp = g_key_file_get_integer(keyfile, group, key, &error);
+
+		DBG("key %s temp %d error %p", key, temp, error);
+
+		if (error == NULL) {
+			limit->set = TRUE;
+			limit->limit = temp;
+		} else {
+			limit->set = FALSE;
+			limit->limit = 0;
+			g_clear_error(&error);
+		}
+
+		DBG("set %u limit %u", limit->set, (unsigned)limit->limit);
+	}
+}
+
+static GKeyFile *__connman_rlimits_open(const gchar *path)
+{
+	GKeyFile *keyfile;
+	gchar *data = NULL;
+	gboolean result;
+	gsize length;
+
+	DBG("path %s", path);
+
+	result = g_file_get_contents(path, &data, &length, NULL);
+
+	keyfile = g_key_file_new();
+
+	if (result == FALSE)
+		goto done;
+
+	if (length > 0)
+		g_key_file_load_from_data(keyfile, data, length, 0, NULL);
+
+	g_free(data);
+
+done:
+	DBG("keyfile %p", keyfile);
+
+	return keyfile;
+}
+
+static int __connman_rlimits_load(const gchar *path,
+				  struct connman_rlimits *limits)
+{
+	GKeyFile *keyfile;
+
+	if (limits == NULL)
+		return -EINVAL;
+
+	keyfile = __connman_rlimits_open(path);
+
+	if (keyfile == NULL)
+		return -EIO;
+
+#if defined(RLIMIT_AS)
+	__connman_rlimit_read(keyfile, RLIMIT_AS_KEY,      &limits->as);
+#endif
+	__connman_rlimit_read(keyfile, RLIMIT_CORE_KEY,    &limits->core);
+	__connman_rlimit_read(keyfile, RLIMIT_DATA_KEY,    &limits->data);
+	__connman_rlimit_read(keyfile, RLIMIT_FSIZE_KEY,   &limits->fsize);
+	__connman_rlimit_read(keyfile, RLIMIT_NOFILE_KEY,  &limits->nofile);
+	__connman_rlimit_read(keyfile, RLIMIT_STACK_KEY,   &limits->stack);
+#if defined(RLIMIT_NPROC)
+	__connman_rlimit_read(keyfile, RLIMIT_NPROC_KEY,   &limits->nproc);
+#endif
+#if defined(RLIMIT_MEMLOCK)
+	__connman_rlimit_read(keyfile, RLIMIT_MEMLOCK_KEY, &limits->memlock);
+#endif
+
+	g_key_file_free(keyfile);
+
+	return 0;
+}
+
+int __connman_rlimits_init(const gchar *path)
+{
+	struct connman_rlimits rlimits;
+	int err;
+
+	if (path == NULL)
+		return -EINVAL;
+
+	err = __connman_rlimits_load(path, &rlimits);
+
+	if (err < 0)
+		return err;
+
+	return __connman_rlimits_enforce(&rlimits);
+}
diff --git a/connman/src/rtnl.c b/connman/src/rtnl.c
new file mode 100644
index 0000000..409729c
--- /dev/null
+++ b/connman/src/rtnl.c
@@ -0,0 +1,1699 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2013  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 <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <sys/socket.h>
+#include <sys/ioctl.h>
+#include <arpa/inet.h>
+#include <netinet/ether.h>
+#include <netinet/icmp6.h>
+#include <net/if_arp.h>
+#include <linux/if.h>
+#include <linux/netlink.h>
+#include <linux/rtnetlink.h>
+#include <linux/wireless.h>
+
+#include <glib.h>
+
+#include "connman.h"
+
+#ifndef ARPHDR_PHONET_PIPE
+#define ARPHDR_PHONET_PIPE (821)
+#endif
+
+#define print(arg...) do { if (0) connman_info(arg); } while (0)
+//#define print(arg...) connman_info(arg)
+
+struct watch_data {
+	unsigned int id;
+	int index;
+	connman_rtnl_link_cb_t newlink;
+	void *user_data;
+};
+
+static GSList *watch_list = NULL;
+static unsigned int watch_id = 0;
+
+static GSList *update_list = NULL;
+static guint update_interval = G_MAXUINT;
+static guint update_timeout = 0;
+
+struct interface_data {
+	int index;
+	char *ident;
+	enum connman_service_type service_type;
+	enum connman_device_type device_type;
+};
+
+static GHashTable *interface_list = NULL;
+
+static void free_interface(gpointer data)
+{
+	struct interface_data *interface = data;
+
+	__connman_technology_remove_interface(interface->service_type,
+			interface->index, interface->ident);
+
+	g_free(interface->ident);
+	g_free(interface);
+}
+
+static bool ether_blacklisted(const char *name)
+{
+	if (!name)
+		return true;
+
+	if (__connman_device_isfiltered(name))
+		return true;
+
+	return false;
+}
+
+static bool wext_interface(char *ifname)
+{
+	struct iwreq wrq;
+	int fd, err;
+
+	fd = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
+	if (fd < 0)
+		return false;
+
+	memset(&wrq, 0, sizeof(wrq));
+	strncpy(wrq.ifr_name, ifname, sizeof(wrq.ifr_name) - 1);
+
+	err = ioctl(fd, SIOCGIWNAME, &wrq);
+
+	close(fd);
+
+	if (err < 0)
+		return false;
+
+	return true;
+}
+
+static void read_uevent(struct interface_data *interface)
+{
+	char *filename, *name, line[128];
+	bool found_devtype;
+	FILE *f;
+
+	name = connman_inet_ifname(interface->index);
+
+	if (ether_blacklisted(name)) {
+		interface->service_type = CONNMAN_SERVICE_TYPE_UNKNOWN;
+		interface->device_type = CONNMAN_DEVICE_TYPE_UNKNOWN;
+	} else {
+		interface->service_type = CONNMAN_SERVICE_TYPE_ETHERNET;
+		interface->device_type = CONNMAN_DEVICE_TYPE_ETHERNET;
+	}
+
+	filename = g_strdup_printf("/sys/class/net/%s/uevent", name);
+
+	f = fopen(filename, "re");
+
+	g_free(filename);
+
+	if (!f) {
+		interface->service_type = CONNMAN_SERVICE_TYPE_UNKNOWN;
+		interface->device_type = CONNMAN_DEVICE_TYPE_UNKNOWN;
+		goto out;
+	}
+
+	found_devtype = false;
+	while (fgets(line, sizeof(line), f)) {
+		char *pos;
+
+		pos = strchr(line, '\n');
+		if (!pos)
+			continue;
+		pos[0] = '\0';
+
+		if (strncmp(line, "DEVTYPE=", 8) != 0)
+			continue;
+
+		found_devtype = true;
+
+		if (strcmp(line + 8, "wlan") == 0) {
+			interface->service_type = CONNMAN_SERVICE_TYPE_WIFI;
+			interface->device_type = CONNMAN_DEVICE_TYPE_WIFI;
+		} else if (strcmp(line + 8, "wwan") == 0) {
+			interface->service_type = CONNMAN_SERVICE_TYPE_CELLULAR;
+			interface->device_type = CONNMAN_DEVICE_TYPE_CELLULAR;
+		} else if (strcmp(line + 8, "bluetooth") == 0) {
+			interface->service_type = CONNMAN_SERVICE_TYPE_BLUETOOTH;
+			interface->device_type = CONNMAN_DEVICE_TYPE_BLUETOOTH;
+		} else if (strcmp(line + 8, "gadget") == 0) {
+			interface->service_type = CONNMAN_SERVICE_TYPE_GADGET;
+			interface->device_type = CONNMAN_DEVICE_TYPE_GADGET;
+		} else if (strcmp(line + 8, "vlan") == 0) {
+			interface->service_type = CONNMAN_SERVICE_TYPE_ETHERNET;
+			interface->device_type = CONNMAN_DEVICE_TYPE_ETHERNET;
+		} else if (strcmp(line + 8, "lowpan") == 0) {
+			interface->service_type = CONNMAN_SERVICE_TYPE_LOWPAN;
+			interface->device_type = CONNMAN_DEVICE_TYPE_LOWPAN;
+		} else if (strcmp(line + 8, "lowpan") == 0) {
+			interface->service_type = CONNMAN_SERVICE_TYPE_LOWPAN;
+			interface->device_type = CONNMAN_DEVICE_TYPE_LOWPAN;
+		} else {
+			interface->service_type = CONNMAN_SERVICE_TYPE_UNKNOWN;
+			interface->device_type = CONNMAN_DEVICE_TYPE_UNKNOWN;
+		}
+	}
+
+	fclose(f);
+
+	if (found_devtype)
+		goto out;
+
+	/* We haven't got a DEVTYPE, let's check if it's a wireless device */
+	if (wext_interface(name)) {
+		interface->service_type = CONNMAN_SERVICE_TYPE_WIFI;
+		interface->device_type = CONNMAN_DEVICE_TYPE_WIFI;
+
+		connman_error("%s runs an unsupported 802.11 driver", name);
+	}
+
+out:
+	g_free(name);
+}
+
+enum connman_device_type __connman_rtnl_get_device_type(int index)
+{
+	struct interface_data *interface;
+
+	interface = g_hash_table_lookup(interface_list,
+					GINT_TO_POINTER(index));
+	if (!interface)
+		return CONNMAN_DEVICE_TYPE_UNKNOWN;
+
+	return interface->device_type;
+}
+
+/**
+ * connman_rtnl_add_newlink_watch:
+ * @index: network device index
+ * @callback: callback function
+ * @user_data: callback data;
+ *
+ * Add a new RTNL watch for newlink events
+ *
+ * Returns: %0 on failure and a unique id on success
+ */
+unsigned int connman_rtnl_add_newlink_watch(int index,
+			connman_rtnl_link_cb_t callback, void *user_data)
+{
+	struct watch_data *watch;
+
+	watch = g_try_new0(struct watch_data, 1);
+	if (!watch)
+		return 0;
+
+	watch->id = ++watch_id;
+	watch->index = index;
+
+	watch->newlink = callback;
+	watch->user_data = user_data;
+
+	watch_list = g_slist_prepend(watch_list, watch);
+
+	DBG("id %d", watch->id);
+
+	if (callback) {
+		unsigned int flags = __connman_ipconfig_get_flags_from_index(index);
+
+		if (flags > 0)
+			callback(flags, 0, user_data);
+	}
+
+	return watch->id;
+}
+
+/**
+ * connman_rtnl_remove_watch:
+ * @id: watch identifier
+ *
+ * Remove the RTNL watch for the identifier
+ */
+void connman_rtnl_remove_watch(unsigned int id)
+{
+	GSList *list;
+
+	DBG("id %d", id);
+
+	if (id == 0)
+		return;
+
+	for (list = watch_list; list; list = list->next) {
+		struct watch_data *watch = list->data;
+
+		if (watch->id  == id) {
+			watch_list = g_slist_remove(watch_list, watch);
+			g_free(watch);
+			break;
+		}
+	}
+}
+
+static void trigger_rtnl(int index, void *user_data)
+{
+	struct connman_rtnl *rtnl = user_data;
+
+	if (rtnl->newlink) {
+		unsigned short type = __connman_ipconfig_get_type_from_index(index);
+		unsigned int flags = __connman_ipconfig_get_flags_from_index(index);
+
+		rtnl->newlink(type, index, flags, 0);
+	}
+
+	if (rtnl->newgateway) {
+		const char *gateway =
+			__connman_ipconfig_get_gateway_from_index(index,
+					CONNMAN_IPCONFIG_TYPE_ALL);
+
+		if (gateway)
+			rtnl->newgateway(index, gateway);
+	}
+}
+
+static GSList *rtnl_list = NULL;
+
+static gint compare_priority(gconstpointer a, gconstpointer b)
+{
+	const struct connman_rtnl *rtnl1 = a;
+	const struct connman_rtnl *rtnl2 = b;
+
+	return rtnl2->priority - rtnl1->priority;
+}
+
+/**
+ * connman_rtnl_register:
+ * @rtnl: RTNL module
+ *
+ * Register a new RTNL module
+ *
+ * Returns: %0 on success
+ */
+int connman_rtnl_register(struct connman_rtnl *rtnl)
+{
+	DBG("rtnl %p name %s", rtnl, rtnl->name);
+
+	rtnl_list = g_slist_insert_sorted(rtnl_list, rtnl,
+							compare_priority);
+
+	__connman_ipconfig_foreach(trigger_rtnl, rtnl);
+
+	return 0;
+}
+
+/**
+ * connman_rtnl_unregister:
+ * @rtnl: RTNL module
+ *
+ * Remove a previously registered RTNL module
+ */
+void connman_rtnl_unregister(struct connman_rtnl *rtnl)
+{
+	DBG("rtnl %p name %s", rtnl, rtnl->name);
+
+	rtnl_list = g_slist_remove(rtnl_list, rtnl);
+}
+
+static const char *operstate2str(unsigned char operstate)
+{
+	switch (operstate) {
+	case IF_OPER_UNKNOWN:
+		return "UNKNOWN";
+	case IF_OPER_NOTPRESENT:
+		return "NOT-PRESENT";
+	case IF_OPER_DOWN:
+		return "DOWN";
+	case IF_OPER_LOWERLAYERDOWN:
+		return "LOWER-LAYER-DOWN";
+	case IF_OPER_TESTING:
+		return "TESTING";
+	case IF_OPER_DORMANT:
+		return "DORMANT";
+	case IF_OPER_UP:
+		return "UP";
+	}
+
+	return "";
+}
+
+static bool extract_link(struct ifinfomsg *msg, int bytes,
+				struct ether_addr *address, const char **ifname,
+				unsigned int *mtu, unsigned char *operstate,
+				struct rtnl_link_stats *stats)
+{
+	struct rtattr *attr;
+
+	for (attr = IFLA_RTA(msg); RTA_OK(attr, bytes);
+					attr = RTA_NEXT(attr, bytes)) {
+		switch (attr->rta_type) {
+		case IFLA_ADDRESS:
+			if (address)
+				memcpy(address, RTA_DATA(attr), ETH_ALEN);
+			break;
+		case IFLA_IFNAME:
+			if (ifname)
+				*ifname = RTA_DATA(attr);
+			break;
+		case IFLA_MTU:
+			if (mtu)
+				*mtu = *((unsigned int *) RTA_DATA(attr));
+			break;
+		case IFLA_STATS:
+			if (stats)
+				memcpy(stats, RTA_DATA(attr),
+					sizeof(struct rtnl_link_stats));
+			break;
+		case IFLA_OPERSTATE:
+			if (operstate)
+				*operstate = *((unsigned char *) RTA_DATA(attr));
+			break;
+		case IFLA_LINKMODE:
+			break;
+		case IFLA_WIRELESS:
+			return false;
+		}
+	}
+
+	return true;
+}
+
+static void process_newlink(unsigned short type, int index, unsigned flags,
+			unsigned change, struct ifinfomsg *msg, int bytes)
+{
+	struct ether_addr address = {{ 0, 0, 0, 0, 0, 0 }};
+	struct rtnl_link_stats stats;
+	unsigned char operstate = 0xff;
+	struct interface_data *interface;
+	const char *ifname = NULL;
+	unsigned int mtu = 0;
+	char ident[13], str[18];
+	GSList *list;
+
+	memset(&stats, 0, sizeof(stats));
+	if (!extract_link(msg, bytes, &address, &ifname, &mtu, &operstate, &stats))
+		return;
+
+	snprintf(ident, 13, "%02x%02x%02x%02x%02x%02x",
+						address.ether_addr_octet[0],
+						address.ether_addr_octet[1],
+						address.ether_addr_octet[2],
+						address.ether_addr_octet[3],
+						address.ether_addr_octet[4],
+						address.ether_addr_octet[5]);
+
+	snprintf(str, 18, "%02X:%02X:%02X:%02X:%02X:%02X",
+						address.ether_addr_octet[0],
+						address.ether_addr_octet[1],
+						address.ether_addr_octet[2],
+						address.ether_addr_octet[3],
+						address.ether_addr_octet[4],
+						address.ether_addr_octet[5]);
+
+	if (flags & IFF_SLAVE) {
+		connman_info("%s {newlink} ignoring slave, index %d address %s",
+						ifname, index, str);
+		return;
+	}
+
+	switch (type) {
+	case ARPHRD_ETHER:
+	case ARPHRD_LOOPBACK:
+	case ARPHDR_PHONET_PIPE:
+	case ARPHRD_PPP:
+	case ARPHRD_NONE:
+		__connman_ipconfig_newlink(index, type, flags,
+							str, mtu, &stats);
+		break;
+	}
+
+	connman_info("%s {newlink} index %d address %s mtu %u",
+					ifname, index, str, mtu);
+
+	if (operstate != 0xff)
+		connman_info("%s {newlink} index %d operstate %u <%s>",
+						ifname, index, operstate,
+						operstate2str(operstate));
+
+	interface = g_hash_table_lookup(interface_list, GINT_TO_POINTER(index));
+	if (!interface) {
+		interface = g_new0(struct interface_data, 1);
+		interface->index = index;
+		interface->ident = g_strdup(ident);
+
+		g_hash_table_insert(interface_list,
+					GINT_TO_POINTER(index), interface);
+
+		if (type == ARPHRD_ETHER)
+			read_uevent(interface);
+	} else
+		interface = NULL;
+
+	for (list = rtnl_list; list; list = list->next) {
+		struct connman_rtnl *rtnl = list->data;
+
+		if (rtnl->newlink)
+			rtnl->newlink(type, index, flags, change);
+	}
+
+	/*
+	 * The interface needs to be added after the newlink call.
+	 * The newlink will create the technology when needed and
+	 * __connman_technology_add_interface() expects the
+	 * technology to be there already.
+	 */
+	if (interface)
+		__connman_technology_add_interface(interface->service_type,
+			interface->index, interface->ident);
+
+	for (list = watch_list; list; list = list->next) {
+		struct watch_data *watch = list->data;
+
+		if (watch->index != index)
+			continue;
+
+		if (watch->newlink)
+			watch->newlink(flags, change, watch->user_data);
+	}
+}
+
+static void process_dellink(unsigned short type, int index, unsigned flags,
+			unsigned change, struct ifinfomsg *msg, int bytes)
+{
+	struct rtnl_link_stats stats;
+	unsigned char operstate = 0xff;
+	const char *ifname = NULL;
+	GSList *list;
+
+	memset(&stats, 0, sizeof(stats));
+	if (!extract_link(msg, bytes, NULL, &ifname, NULL, &operstate, &stats))
+		return;
+
+	if (operstate != 0xff)
+		connman_info("%s {dellink} index %d operstate %u <%s>",
+						ifname, index, operstate,
+						operstate2str(operstate));
+
+	for (list = rtnl_list; list; list = list->next) {
+		struct connman_rtnl *rtnl = list->data;
+
+		if (rtnl->dellink)
+			rtnl->dellink(type, index, flags, change);
+	}
+
+	switch (type) {
+	case ARPHRD_ETHER:
+	case ARPHRD_LOOPBACK:
+	case ARPHDR_PHONET_PIPE:
+	case ARPHRD_PPP:
+	case ARPHRD_NONE:
+		__connman_ipconfig_dellink(index, &stats);
+		break;
+	}
+
+	g_hash_table_remove(interface_list, GINT_TO_POINTER(index));
+}
+
+static void extract_ipv4_addr(struct ifaddrmsg *msg, int bytes,
+						const char **label,
+						struct in_addr *local,
+						struct in_addr *address,
+						struct in_addr *broadcast)
+{
+	struct rtattr *attr;
+
+	for (attr = IFA_RTA(msg); RTA_OK(attr, bytes);
+					attr = RTA_NEXT(attr, bytes)) {
+		switch (attr->rta_type) {
+		case IFA_ADDRESS:
+			if (address)
+				*address = *((struct in_addr *) RTA_DATA(attr));
+			break;
+		case IFA_LOCAL:
+			if (local)
+				*local = *((struct in_addr *) RTA_DATA(attr));
+			break;
+		case IFA_BROADCAST:
+			if (broadcast)
+				*broadcast = *((struct in_addr *) RTA_DATA(attr));
+			break;
+		case IFA_LABEL:
+			if (label)
+				*label = RTA_DATA(attr);
+			break;
+		}
+	}
+}
+
+static void extract_ipv6_addr(struct ifaddrmsg *msg, int bytes,
+						struct in6_addr *addr,
+						struct in6_addr *local)
+{
+	struct rtattr *attr;
+
+	for (attr = IFA_RTA(msg); RTA_OK(attr, bytes);
+					attr = RTA_NEXT(attr, bytes)) {
+		switch (attr->rta_type) {
+		case IFA_ADDRESS:
+			if (addr)
+				*addr = *((struct in6_addr *) RTA_DATA(attr));
+			break;
+		case IFA_LOCAL:
+			if (local)
+				*local = *((struct in6_addr *) RTA_DATA(attr));
+			break;
+		}
+	}
+}
+
+static void process_newaddr(unsigned char family, unsigned char prefixlen,
+				int index, struct ifaddrmsg *msg, int bytes)
+{
+	struct in_addr ipv4_addr = { INADDR_ANY };
+	struct in6_addr ipv6_address, ipv6_local;
+	const char *label = NULL;
+	void *src;
+	char ip_string[INET6_ADDRSTRLEN];
+
+	if (family == AF_INET) {
+
+		extract_ipv4_addr(msg, bytes, &label, &ipv4_addr, NULL, NULL);
+		src = &ipv4_addr;
+	} else if (family == AF_INET6) {
+		extract_ipv6_addr(msg, bytes, &ipv6_address, &ipv6_local);
+		if (IN6_IS_ADDR_LINKLOCAL(&ipv6_address))
+			return;
+
+		src = &ipv6_address;
+	} else {
+		return;
+	}
+
+	if (!inet_ntop(family, src, ip_string, INET6_ADDRSTRLEN))
+		return;
+
+	if (__connman_ipconfig_newaddr(index, family, label,
+					prefixlen, ip_string) >= 0) {
+		if (family == AF_INET6) {
+			/*
+			 * Re-create RDNSS configured servers if there
+			 * are any for this interface. This is done
+			 * because we might have now properly
+			 * configured interface with proper
+			 * autoconfigured address.
+			 */
+			__connman_resolver_redo_servers(index);
+		}
+	}
+}
+
+static void process_deladdr(unsigned char family, unsigned char prefixlen,
+				int index, struct ifaddrmsg *msg, int bytes)
+{
+	struct in_addr ipv4_addr = { INADDR_ANY };
+	struct in6_addr ipv6_address, ipv6_local;
+	const char *label = NULL;
+	void *src;
+	char ip_string[INET6_ADDRSTRLEN];
+
+	if (family == AF_INET) {
+		extract_ipv4_addr(msg, bytes, &label, &ipv4_addr, NULL, NULL);
+		src = &ipv4_addr;
+	} else if (family == AF_INET6) {
+		extract_ipv6_addr(msg, bytes, &ipv6_address, &ipv6_local);
+		if (IN6_IS_ADDR_LINKLOCAL(&ipv6_address))
+			return;
+
+		src = &ipv6_address;
+	} else {
+		return;
+	}
+
+	if (!inet_ntop(family, src, ip_string, INET6_ADDRSTRLEN))
+		return;
+
+	__connman_ipconfig_deladdr(index, family, label,
+					prefixlen, ip_string);
+}
+
+static void extract_ipv4_route(struct rtmsg *msg, int bytes, int *index,
+						struct in_addr *dst,
+						struct in_addr *gateway)
+{
+	struct rtattr *attr;
+
+	for (attr = RTM_RTA(msg); RTA_OK(attr, bytes);
+					attr = RTA_NEXT(attr, bytes)) {
+		switch (attr->rta_type) {
+		case RTA_DST:
+			if (dst)
+				*dst = *((struct in_addr *) RTA_DATA(attr));
+			break;
+		case RTA_GATEWAY:
+			if (gateway)
+				*gateway = *((struct in_addr *) RTA_DATA(attr));
+			break;
+		case RTA_OIF:
+			if (index)
+				*index = *((int *) RTA_DATA(attr));
+			break;
+		}
+	}
+}
+
+static void extract_ipv6_route(struct rtmsg *msg, int bytes, int *index,
+						struct in6_addr *dst,
+						struct in6_addr *gateway)
+{
+	struct rtattr *attr;
+
+	for (attr = RTM_RTA(msg); RTA_OK(attr, bytes);
+					attr = RTA_NEXT(attr, bytes)) {
+		switch (attr->rta_type) {
+		case RTA_DST:
+			if (dst)
+				*dst = *((struct in6_addr *) RTA_DATA(attr));
+			break;
+		case RTA_GATEWAY:
+			if (gateway)
+				*gateway =
+					*((struct in6_addr *) RTA_DATA(attr));
+			break;
+		case RTA_OIF:
+			if (index)
+				*index = *((int *) RTA_DATA(attr));
+			break;
+		}
+	}
+}
+
+static void process_newroute(unsigned char family, unsigned char scope,
+						struct rtmsg *msg, int bytes)
+{
+	GSList *list;
+	char dststr[INET6_ADDRSTRLEN], gatewaystr[INET6_ADDRSTRLEN];
+	int index = -1;
+
+	if (family == AF_INET) {
+		struct in_addr dst = { INADDR_ANY }, gateway = { INADDR_ANY };
+
+		extract_ipv4_route(msg, bytes, &index, &dst, &gateway);
+
+		inet_ntop(family, &dst, dststr, sizeof(dststr));
+		inet_ntop(family, &gateway, gatewaystr, sizeof(gatewaystr));
+
+		__connman_ipconfig_newroute(index, family, scope, dststr,
+								gatewaystr);
+
+		/* skip host specific routes */
+		if (scope != RT_SCOPE_UNIVERSE &&
+			!(scope == RT_SCOPE_LINK && dst.s_addr == INADDR_ANY))
+			return;
+
+		if (dst.s_addr != INADDR_ANY)
+			return;
+
+	} else if (family == AF_INET6) {
+		struct in6_addr dst = IN6ADDR_ANY_INIT,
+				gateway = IN6ADDR_ANY_INIT;
+
+		extract_ipv6_route(msg, bytes, &index, &dst, &gateway);
+
+		inet_ntop(family, &dst, dststr, sizeof(dststr));
+		inet_ntop(family, &gateway, gatewaystr, sizeof(gatewaystr));
+
+		__connman_ipconfig_newroute(index, family, scope, dststr,
+								gatewaystr);
+
+		/* skip host specific routes */
+		if (scope != RT_SCOPE_UNIVERSE &&
+			!(scope == RT_SCOPE_LINK &&
+				IN6_IS_ADDR_UNSPECIFIED(&dst)))
+			return;
+
+		if (!IN6_IS_ADDR_UNSPECIFIED(&dst))
+			return;
+	} else
+		return;
+
+	for (list = rtnl_list; list; list = list->next) {
+		struct connman_rtnl *rtnl = list->data;
+
+		if (rtnl->newgateway)
+			rtnl->newgateway(index, gatewaystr);
+	}
+}
+
+static void process_delroute(unsigned char family, unsigned char scope,
+						struct rtmsg *msg, int bytes)
+{
+	GSList *list;
+	char dststr[INET6_ADDRSTRLEN], gatewaystr[INET6_ADDRSTRLEN];
+	int index = -1;
+
+	if (family == AF_INET) {
+		struct in_addr dst = { INADDR_ANY }, gateway = { INADDR_ANY };
+
+		extract_ipv4_route(msg, bytes, &index, &dst, &gateway);
+
+		inet_ntop(family, &dst, dststr, sizeof(dststr));
+		inet_ntop(family, &gateway, gatewaystr, sizeof(gatewaystr));
+
+		__connman_ipconfig_delroute(index, family, scope, dststr,
+								gatewaystr);
+
+		/* skip host specific routes */
+		if (scope != RT_SCOPE_UNIVERSE &&
+			!(scope == RT_SCOPE_LINK && dst.s_addr == INADDR_ANY))
+			return;
+
+		if (dst.s_addr != INADDR_ANY)
+			return;
+
+	}  else if (family == AF_INET6) {
+		struct in6_addr dst = IN6ADDR_ANY_INIT,
+				gateway = IN6ADDR_ANY_INIT;
+
+		extract_ipv6_route(msg, bytes, &index, &dst, &gateway);
+
+		inet_ntop(family, &dst, dststr, sizeof(dststr));
+		inet_ntop(family, &gateway, gatewaystr, sizeof(gatewaystr));
+
+		__connman_ipconfig_delroute(index, family, scope, dststr,
+						gatewaystr);
+
+		/* skip host specific routes */
+		if (scope != RT_SCOPE_UNIVERSE &&
+			!(scope == RT_SCOPE_LINK &&
+				IN6_IS_ADDR_UNSPECIFIED(&dst)))
+			return;
+
+		if (!IN6_IS_ADDR_UNSPECIFIED(&dst))
+			return;
+	} else
+		return;
+
+	for (list = rtnl_list; list; list = list->next) {
+		struct connman_rtnl *rtnl = list->data;
+
+		if (rtnl->delgateway)
+			rtnl->delgateway(index, gatewaystr);
+	}
+}
+
+static inline void print_ether(struct rtattr *attr, const char *name)
+{
+	int len = (int) RTA_PAYLOAD(attr);
+
+	if (len == ETH_ALEN) {
+		struct ether_addr eth;
+		memcpy(&eth, RTA_DATA(attr), ETH_ALEN);
+		print("  attr %s (len %d) %s\n", name, len, ether_ntoa(&eth));
+	} else
+		print("  attr %s (len %d)\n", name, len);
+}
+
+static inline void print_inet(struct rtattr *attr, const char *name,
+							unsigned char family)
+{
+	int len = (int) RTA_PAYLOAD(attr);
+
+	if (family == AF_INET && len == sizeof(struct in_addr)) {
+		struct in_addr addr;
+		addr = *((struct in_addr *) RTA_DATA(attr));
+		print("  attr %s (len %d) %s\n", name, len, inet_ntoa(addr));
+	} else
+		print("  attr %s (len %d)\n", name, len);
+}
+
+static inline void print_string(struct rtattr *attr, const char *name)
+{
+	print("  attr %s (len %d) %s\n", name, (int) RTA_PAYLOAD(attr),
+						(char *) RTA_DATA(attr));
+}
+
+static inline void print_byte(struct rtattr *attr, const char *name)
+{
+	print("  attr %s (len %d) 0x%02x\n", name, (int) RTA_PAYLOAD(attr),
+					*((unsigned char *) RTA_DATA(attr)));
+}
+
+static inline void print_integer(struct rtattr *attr, const char *name)
+{
+	print("  attr %s (len %d) %d\n", name, (int) RTA_PAYLOAD(attr),
+						*((int *) RTA_DATA(attr)));
+}
+
+static inline void print_attr(struct rtattr *attr, const char *name)
+{
+	int len = (int) RTA_PAYLOAD(attr);
+
+	if (name && len > 0)
+		print("  attr %s (len %d)\n", name, len);
+	else
+		print("  attr %d (len %d)\n", attr->rta_type, len);
+}
+
+static void rtnl_link(struct nlmsghdr *hdr)
+{
+	struct ifinfomsg *msg;
+	struct rtattr *attr;
+	int bytes;
+
+	msg = (struct ifinfomsg *) NLMSG_DATA(hdr);
+	bytes = IFLA_PAYLOAD(hdr);
+
+	print("ifi_index %d ifi_flags 0x%04x", msg->ifi_index, msg->ifi_flags);
+
+	for (attr = IFLA_RTA(msg); RTA_OK(attr, bytes);
+					attr = RTA_NEXT(attr, bytes)) {
+		switch (attr->rta_type) {
+		case IFLA_ADDRESS:
+			print_ether(attr, "address");
+			break;
+		case IFLA_BROADCAST:
+			print_ether(attr, "broadcast");
+			break;
+		case IFLA_IFNAME:
+			print_string(attr, "ifname");
+			break;
+		case IFLA_MTU:
+			print_integer(attr, "mtu");
+			break;
+		case IFLA_LINK:
+			print_attr(attr, "link");
+			break;
+		case IFLA_QDISC:
+			print_attr(attr, "qdisc");
+			break;
+		case IFLA_STATS:
+			print_attr(attr, "stats");
+			break;
+		case IFLA_COST:
+			print_attr(attr, "cost");
+			break;
+		case IFLA_PRIORITY:
+			print_attr(attr, "priority");
+			break;
+		case IFLA_MASTER:
+			print_attr(attr, "master");
+			break;
+		case IFLA_WIRELESS:
+			print_attr(attr, "wireless");
+			break;
+		case IFLA_PROTINFO:
+			print_attr(attr, "protinfo");
+			break;
+		case IFLA_TXQLEN:
+			print_integer(attr, "txqlen");
+			break;
+		case IFLA_MAP:
+			print_attr(attr, "map");
+			break;
+		case IFLA_WEIGHT:
+			print_attr(attr, "weight");
+			break;
+		case IFLA_OPERSTATE:
+			print_byte(attr, "operstate");
+			break;
+		case IFLA_LINKMODE:
+			print_byte(attr, "linkmode");
+			break;
+		default:
+			print_attr(attr, NULL);
+			break;
+		}
+	}
+}
+
+static void rtnl_newlink(struct nlmsghdr *hdr)
+{
+	struct ifinfomsg *msg = (struct ifinfomsg *) NLMSG_DATA(hdr);
+
+	rtnl_link(hdr);
+
+	if (hdr->nlmsg_type == IFLA_WIRELESS)
+		connman_warn_once("Obsolete WEXT WiFi driver detected");
+
+	process_newlink(msg->ifi_type, msg->ifi_index, msg->ifi_flags,
+				msg->ifi_change, msg, IFA_PAYLOAD(hdr));
+}
+
+static void rtnl_dellink(struct nlmsghdr *hdr)
+{
+	struct ifinfomsg *msg = (struct ifinfomsg *) NLMSG_DATA(hdr);
+
+	rtnl_link(hdr);
+
+	process_dellink(msg->ifi_type, msg->ifi_index, msg->ifi_flags,
+				msg->ifi_change, msg, IFA_PAYLOAD(hdr));
+}
+
+static void rtnl_addr(struct nlmsghdr *hdr)
+{
+	struct ifaddrmsg *msg;
+	struct rtattr *attr;
+	int bytes;
+
+	msg = (struct ifaddrmsg *) NLMSG_DATA(hdr);
+	bytes = IFA_PAYLOAD(hdr);
+
+	print("ifa_family %d ifa_index %d", msg->ifa_family, msg->ifa_index);
+
+	for (attr = IFA_RTA(msg); RTA_OK(attr, bytes);
+					attr = RTA_NEXT(attr, bytes)) {
+		switch (attr->rta_type) {
+		case IFA_ADDRESS:
+			print_inet(attr, "address", msg->ifa_family);
+			break;
+		case IFA_LOCAL:
+			print_inet(attr, "local", msg->ifa_family);
+			break;
+		case IFA_LABEL:
+			print_string(attr, "label");
+			break;
+		case IFA_BROADCAST:
+			print_inet(attr, "broadcast", msg->ifa_family);
+			break;
+		case IFA_ANYCAST:
+			print_attr(attr, "anycast");
+			break;
+		case IFA_CACHEINFO:
+			print_attr(attr, "cacheinfo");
+			break;
+		case IFA_MULTICAST:
+			print_attr(attr, "multicast");
+			break;
+		default:
+			print_attr(attr, NULL);
+			break;
+		}
+	}
+}
+
+static void rtnl_newaddr(struct nlmsghdr *hdr)
+{
+	struct ifaddrmsg *msg = (struct ifaddrmsg *) NLMSG_DATA(hdr);
+
+	rtnl_addr(hdr);
+
+	process_newaddr(msg->ifa_family, msg->ifa_prefixlen, msg->ifa_index,
+						msg, IFA_PAYLOAD(hdr));
+}
+
+static void rtnl_deladdr(struct nlmsghdr *hdr)
+{
+	struct ifaddrmsg *msg = (struct ifaddrmsg *) NLMSG_DATA(hdr);
+
+	rtnl_addr(hdr);
+
+	process_deladdr(msg->ifa_family, msg->ifa_prefixlen, msg->ifa_index,
+						msg, IFA_PAYLOAD(hdr));
+}
+
+static void rtnl_route(struct nlmsghdr *hdr)
+{
+	struct rtmsg *msg;
+	struct rtattr *attr;
+	int bytes;
+
+	msg = (struct rtmsg *) NLMSG_DATA(hdr);
+	bytes = RTM_PAYLOAD(hdr);
+
+	print("rtm_family %d rtm_table %d rtm_protocol %d",
+			msg->rtm_family, msg->rtm_table, msg->rtm_protocol);
+	print("rtm_scope %d rtm_type %d rtm_flags 0x%04x",
+				msg->rtm_scope, msg->rtm_type, msg->rtm_flags);
+
+	for (attr = RTM_RTA(msg); RTA_OK(attr, bytes);
+					attr = RTA_NEXT(attr, bytes)) {
+		switch (attr->rta_type) {
+		case RTA_DST:
+			print_inet(attr, "dst", msg->rtm_family);
+			break;
+		case RTA_SRC:
+			print_inet(attr, "src", msg->rtm_family);
+			break;
+		case RTA_IIF:
+			print_string(attr, "iif");
+			break;
+		case RTA_OIF:
+			print_integer(attr, "oif");
+			break;
+		case RTA_GATEWAY:
+			print_inet(attr, "gateway", msg->rtm_family);
+			break;
+		case RTA_PRIORITY:
+			print_attr(attr, "priority");
+			break;
+		case RTA_PREFSRC:
+			print_inet(attr, "prefsrc", msg->rtm_family);
+			break;
+		case RTA_METRICS:
+			print_attr(attr, "metrics");
+			break;
+		case RTA_TABLE:
+			print_integer(attr, "table");
+			break;
+		default:
+			print_attr(attr, NULL);
+			break;
+		}
+	}
+}
+
+static bool is_route_rtmsg(struct rtmsg *msg)
+{
+	if (msg->rtm_flags & RTM_F_CLONED)
+		return false;
+
+	if (msg->rtm_table != RT_TABLE_MAIN)
+		return false;
+
+	if (msg->rtm_protocol != RTPROT_BOOT &&
+			msg->rtm_protocol != RTPROT_KERNEL)
+		return false;
+
+	if (msg->rtm_type != RTN_UNICAST)
+		return false;
+
+	return true;
+}
+
+static void rtnl_newroute(struct nlmsghdr *hdr)
+{
+	struct rtmsg *msg = (struct rtmsg *) NLMSG_DATA(hdr);
+
+	rtnl_route(hdr);
+
+	if (is_route_rtmsg(msg))
+		process_newroute(msg->rtm_family, msg->rtm_scope,
+						msg, RTM_PAYLOAD(hdr));
+}
+
+static void rtnl_delroute(struct nlmsghdr *hdr)
+{
+	struct rtmsg *msg = (struct rtmsg *) NLMSG_DATA(hdr);
+
+	rtnl_route(hdr);
+
+	if (is_route_rtmsg(msg))
+		process_delroute(msg->rtm_family, msg->rtm_scope,
+						msg, RTM_PAYLOAD(hdr));
+}
+
+static void *rtnl_nd_opt_rdnss(struct nd_opt_hdr *opt, guint32 *lifetime,
+			       int *nr_servers)
+{
+	guint32 *optint = (void *)opt;
+
+	if (opt->nd_opt_len < 3)
+		return NULL;
+
+	if (*lifetime > ntohl(optint[1]))
+		*lifetime = ntohl(optint[1]);
+
+	/* nd_opt_len is in units of 8 bytes. The header is 1 unit (8 bytes)
+	   and each address is another 2 units (16 bytes).
+	   So the number of addresses (given rounding) is nd_opt_len/2 */
+	*nr_servers = opt->nd_opt_len / 2;
+
+	/* And they start 8 bytes into the packet, or two guint32s in. */
+	return optint + 2;
+}
+
+static const char **rtnl_nd_opt_dnssl(struct nd_opt_hdr *opt, guint32 *lifetime)
+{
+	const char **domains = NULL;
+	guint32 *optint = (void *)opt;
+	unsigned char *optc = (void *)&optint[2];
+	int data_len = (opt->nd_opt_len * 8) - 8;
+	int nr_domains = 0;
+	int i, tmp;
+
+	if (*lifetime > ntohl(optint[1]))
+		*lifetime = ntohl(optint[1]);
+
+	/* Turn it into normal strings by converting the length bytes into '.',
+	   and count how many search domains there are while we're at it. */
+	i = 0;
+	while (i < data_len) {
+		if (optc[i] > 0x3f) {
+			DBG("DNSSL contains compressed elements in violation of RFC6106");
+			return NULL;
+		}
+
+		if (optc[i] == 0) {
+			nr_domains++;
+			i++;
+			/* Check for double zero */
+			if (i < data_len && optc[i] == 0)
+				break;
+			continue;
+		}
+
+		tmp = i;
+		i += optc[i] + 1;
+
+		if (i >= data_len) {
+			DBG("DNSSL data overflows option length");
+			return NULL;
+		}
+
+		optc[tmp] = '.';
+	}
+
+	domains = g_try_new0(const char *, nr_domains + 1);
+	if (!domains)
+		return NULL;
+
+	/* Now point to the normal strings, missing out the leading '.' that
+	   each of them will have now. */
+	for (i = 0; i < nr_domains; i++) {
+		domains[i] = (char *)optc + 1;
+		optc += strlen((char *)optc) + 1;
+	}
+
+	return domains;
+}
+
+static void rtnl_newnduseropt(struct nlmsghdr *hdr)
+{
+	struct nduseroptmsg *msg = (struct nduseroptmsg *) NLMSG_DATA(hdr);
+	struct nd_opt_hdr *opt;
+	guint32 lifetime = -1;
+	const char **domains = NULL;
+	struct in6_addr *servers = NULL;
+	int i, nr_servers = 0;
+	int msglen = msg->nduseropt_opts_len;
+	int index;
+
+	DBG("family %d index %d len %d type %d code %d",
+		msg->nduseropt_family, msg->nduseropt_ifindex,
+		msg->nduseropt_opts_len, msg->nduseropt_icmp_type,
+		msg->nduseropt_icmp_code);
+
+	if (msg->nduseropt_family != AF_INET6 ||
+			msg->nduseropt_icmp_type != ND_ROUTER_ADVERT ||
+			msg->nduseropt_icmp_code != 0)
+		return;
+
+	index = msg->nduseropt_ifindex;
+	if (index < 0)
+		return;
+
+	for (opt = (void *)&msg[1];
+			msglen > 0;
+			msglen -= opt->nd_opt_len * 8,
+			opt = ((void *)opt) + opt->nd_opt_len*8) {
+
+		DBG("remaining %d nd opt type %d len %d\n",
+			msglen, opt->nd_opt_type, opt->nd_opt_len);
+
+		if (opt->nd_opt_type == 25) { /* ND_OPT_RDNSS */
+			char buf[40];
+
+			servers = rtnl_nd_opt_rdnss(opt, &lifetime,
+								&nr_servers);
+			for (i = 0; i < nr_servers; i++) {
+				if (!inet_ntop(AF_INET6, servers + i, buf,
+								sizeof(buf)))
+					continue;
+
+				connman_resolver_append_lifetime(index,
+							NULL, buf, lifetime);
+			}
+
+		} else if (opt->nd_opt_type == 31) { /* ND_OPT_DNSSL */
+			g_free(domains);
+
+			domains = rtnl_nd_opt_dnssl(opt, &lifetime);
+			for (i = 0; domains && domains[i]; i++)
+				connman_resolver_append_lifetime(index,
+						domains[i], NULL, lifetime);
+		}
+	}
+
+	g_free(domains);
+}
+
+static const char *type2string(uint16_t type)
+{
+	switch (type) {
+	case NLMSG_NOOP:
+		return "NOOP";
+	case NLMSG_ERROR:
+		return "ERROR";
+	case NLMSG_DONE:
+		return "DONE";
+	case NLMSG_OVERRUN:
+		return "OVERRUN";
+	case RTM_GETLINK:
+		return "GETLINK";
+	case RTM_NEWLINK:
+		return "NEWLINK";
+	case RTM_DELLINK:
+		return "DELLINK";
+	case RTM_GETADDR:
+		return "GETADDR";
+	case RTM_NEWADDR:
+		return "NEWADDR";
+	case RTM_DELADDR:
+		return "DELADDR";
+	case RTM_GETROUTE:
+		return "GETROUTE";
+	case RTM_NEWROUTE:
+		return "NEWROUTE";
+	case RTM_DELROUTE:
+		return "DELROUTE";
+	case RTM_NEWNDUSEROPT:
+		return "NEWNDUSEROPT";
+	default:
+		return "UNKNOWN";
+	}
+}
+
+static GIOChannel *channel = NULL;
+static guint channel_watch = 0;
+
+struct rtnl_request {
+	struct nlmsghdr hdr;
+	struct rtgenmsg msg;
+};
+#define RTNL_REQUEST_SIZE  (sizeof(struct nlmsghdr) + sizeof(struct rtgenmsg))
+
+static GSList *request_list = NULL;
+static guint32 request_seq = 0;
+
+static struct rtnl_request *find_request(guint32 seq)
+{
+	GSList *list;
+
+	for (list = request_list; list; list = list->next) {
+		struct rtnl_request *req = list->data;
+
+		if (req->hdr.nlmsg_seq == seq)
+			return req;
+	}
+
+	return NULL;
+}
+
+static int send_request(struct rtnl_request *req)
+{
+	struct sockaddr_nl addr;
+	int sk;
+
+	DBG("%s len %d type %d flags 0x%04x seq %d",
+				type2string(req->hdr.nlmsg_type),
+				req->hdr.nlmsg_len, req->hdr.nlmsg_type,
+				req->hdr.nlmsg_flags, req->hdr.nlmsg_seq);
+
+	sk = g_io_channel_unix_get_fd(channel);
+
+	memset(&addr, 0, sizeof(addr));
+	addr.nl_family = AF_NETLINK;
+
+	return sendto(sk, req, req->hdr.nlmsg_len, 0,
+				(struct sockaddr *) &addr, sizeof(addr));
+}
+
+static int queue_request(struct rtnl_request *req)
+{
+	request_list = g_slist_append(request_list, req);
+
+	if (g_slist_length(request_list) > 1)
+		return 0;
+
+	return send_request(req);
+}
+
+static int process_response(guint32 seq)
+{
+	struct rtnl_request *req;
+
+	DBG("seq %d", seq);
+
+	req = find_request(seq);
+	if (req) {
+		request_list = g_slist_remove(request_list, req);
+		g_free(req);
+	}
+
+	req = g_slist_nth_data(request_list, 0);
+	if (!req)
+		return 0;
+
+	return send_request(req);
+}
+
+static void rtnl_message(void *buf, size_t len)
+{
+	DBG("buf %p len %zd", buf, len);
+
+	while (len > 0) {
+		struct nlmsghdr *hdr = buf;
+		struct nlmsgerr *err;
+
+		if (!NLMSG_OK(hdr, len))
+			break;
+
+		DBG("%s len %d type %d flags 0x%04x seq %d pid %d",
+					type2string(hdr->nlmsg_type),
+					hdr->nlmsg_len, hdr->nlmsg_type,
+					hdr->nlmsg_flags, hdr->nlmsg_seq,
+					hdr->nlmsg_pid);
+
+		switch (hdr->nlmsg_type) {
+		case NLMSG_NOOP:
+		case NLMSG_OVERRUN:
+			return;
+		case NLMSG_DONE:
+			process_response(hdr->nlmsg_seq);
+			return;
+		case NLMSG_ERROR:
+			err = NLMSG_DATA(hdr);
+			DBG("error %d (%s)", -err->error,
+						strerror(-err->error));
+			return;
+		case RTM_NEWLINK:
+			rtnl_newlink(hdr);
+			break;
+		case RTM_DELLINK:
+			rtnl_dellink(hdr);
+			break;
+		case RTM_NEWADDR:
+			rtnl_newaddr(hdr);
+			break;
+		case RTM_DELADDR:
+			rtnl_deladdr(hdr);
+			break;
+		case RTM_NEWROUTE:
+			rtnl_newroute(hdr);
+			break;
+		case RTM_DELROUTE:
+			rtnl_delroute(hdr);
+			break;
+		case RTM_NEWNDUSEROPT:
+			rtnl_newnduseropt(hdr);
+			break;
+		}
+
+		len -= hdr->nlmsg_len;
+		buf += hdr->nlmsg_len;
+	}
+}
+
+static gboolean netlink_event(GIOChannel *chan, GIOCondition cond, gpointer data)
+{
+	unsigned char buf[4096];
+	struct sockaddr_nl nladdr;
+	socklen_t addr_len = sizeof(nladdr);
+	ssize_t status;
+	int fd;
+
+	if (cond & (G_IO_NVAL | G_IO_HUP | G_IO_ERR))
+		return FALSE;
+
+	memset(buf, 0, sizeof(buf));
+	memset(&nladdr, 0, sizeof(nladdr));
+
+	fd = g_io_channel_unix_get_fd(chan);
+
+	status = recvfrom(fd, buf, sizeof(buf), 0,
+                       (struct sockaddr *) &nladdr, &addr_len);
+	if (status < 0) {
+		if (errno == EINTR || errno == EAGAIN)
+			return TRUE;
+
+		return FALSE;
+	}
+
+	if (status == 0)
+		return FALSE;
+
+	if (nladdr.nl_pid != 0) { /* not sent by kernel, ignore */
+		DBG("Received msg from %u, ignoring it", nladdr.nl_pid);
+		return TRUE;
+	}
+
+	rtnl_message(buf, status);
+
+	return TRUE;
+}
+
+static int send_getlink(void)
+{
+	struct rtnl_request *req;
+
+	DBG("");
+
+	req = g_try_malloc0(RTNL_REQUEST_SIZE);
+	if (!req)
+		return -ENOMEM;
+
+	req->hdr.nlmsg_len = RTNL_REQUEST_SIZE;
+	req->hdr.nlmsg_type = RTM_GETLINK;
+	req->hdr.nlmsg_flags = NLM_F_REQUEST | NLM_F_DUMP;
+	req->hdr.nlmsg_pid = 0;
+	req->hdr.nlmsg_seq = request_seq++;
+	req->msg.rtgen_family = AF_INET;
+
+	return queue_request(req);
+}
+
+static int send_getaddr(void)
+{
+	struct rtnl_request *req;
+
+	DBG("");
+
+	req = g_try_malloc0(RTNL_REQUEST_SIZE);
+	if (!req)
+		return -ENOMEM;
+
+	req->hdr.nlmsg_len = RTNL_REQUEST_SIZE;
+	req->hdr.nlmsg_type = RTM_GETADDR;
+	req->hdr.nlmsg_flags = NLM_F_REQUEST | NLM_F_DUMP;
+	req->hdr.nlmsg_pid = 0;
+	req->hdr.nlmsg_seq = request_seq++;
+	req->msg.rtgen_family = AF_INET;
+
+	return queue_request(req);
+}
+
+static int send_getroute(void)
+{
+	struct rtnl_request *req;
+
+	DBG("");
+
+	req = g_try_malloc0(RTNL_REQUEST_SIZE);
+	if (!req)
+		return -ENOMEM;
+
+	req->hdr.nlmsg_len = RTNL_REQUEST_SIZE;
+	req->hdr.nlmsg_type = RTM_GETROUTE;
+	req->hdr.nlmsg_flags = NLM_F_REQUEST | NLM_F_DUMP;
+	req->hdr.nlmsg_pid = 0;
+	req->hdr.nlmsg_seq = request_seq++;
+	req->msg.rtgen_family = AF_INET;
+
+	return queue_request(req);
+}
+
+static gboolean update_timeout_cb(gpointer user_data)
+{
+	__connman_rtnl_request_update();
+
+	return TRUE;
+}
+
+static void update_interval_callback(guint min)
+{
+	if (update_timeout > 0)
+		g_source_remove(update_timeout);
+
+	if (min < G_MAXUINT) {
+		update_interval = min;
+		update_timeout = g_timeout_add_seconds(update_interval,
+						update_timeout_cb, NULL);
+	} else {
+		update_timeout = 0;
+		update_interval = G_MAXUINT;
+	}
+}
+
+static gint compare_interval(gconstpointer a, gconstpointer b)
+{
+	guint val_a = GPOINTER_TO_UINT(a);
+	guint val_b = GPOINTER_TO_UINT(b);
+
+	return val_a - val_b;
+}
+
+unsigned int __connman_rtnl_update_interval_add(unsigned int interval)
+{
+	guint min;
+
+	if (interval == 0)
+		return 0;
+
+	update_list = g_slist_insert_sorted(update_list,
+			GUINT_TO_POINTER(interval), compare_interval);
+
+	min = GPOINTER_TO_UINT(g_slist_nth_data(update_list, 0));
+	if (min < update_interval) {
+		update_interval_callback(min);
+		__connman_rtnl_request_update();
+	}
+
+	return update_interval;
+}
+
+unsigned int __connman_rtnl_update_interval_remove(unsigned int interval)
+{
+	guint min = G_MAXUINT;
+
+	if (interval == 0)
+		return 0;
+
+	update_list = g_slist_remove(update_list, GINT_TO_POINTER(interval));
+
+	if (update_list)
+		min = GPOINTER_TO_UINT(g_slist_nth_data(update_list, 0));
+
+	if (min > update_interval)
+		update_interval_callback(min);
+
+	return min;
+}
+
+int __connman_rtnl_request_update(void)
+{
+	return send_getlink();
+}
+
+int __connman_rtnl_init(void)
+{
+	struct sockaddr_nl addr;
+	int sk;
+
+	DBG("");
+
+	interface_list = g_hash_table_new_full(g_direct_hash, g_direct_equal,
+							NULL, free_interface);
+
+	sk = socket(PF_NETLINK, SOCK_DGRAM | SOCK_CLOEXEC, NETLINK_ROUTE);
+	if (sk < 0)
+		return -1;
+
+	memset(&addr, 0, sizeof(addr));
+	addr.nl_family = AF_NETLINK;
+	addr.nl_groups = RTMGRP_LINK | RTMGRP_IPV4_IFADDR | RTMGRP_IPV4_ROUTE |
+				RTMGRP_IPV6_IFADDR | RTMGRP_IPV6_ROUTE |
+				(1<<(RTNLGRP_ND_USEROPT-1));
+
+	if (bind(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
+		close(sk);
+		return -1;
+	}
+
+	channel = g_io_channel_unix_new(sk);
+	g_io_channel_set_close_on_unref(channel, TRUE);
+
+	g_io_channel_set_encoding(channel, NULL, NULL);
+	g_io_channel_set_buffered(channel, FALSE);
+
+	channel_watch = g_io_add_watch(channel,
+				G_IO_IN | G_IO_NVAL | G_IO_HUP | G_IO_ERR,
+				netlink_event, NULL);
+
+	return 0;
+}
+
+void __connman_rtnl_start(void)
+{
+	DBG("");
+
+	send_getlink();
+	send_getaddr();
+	send_getroute();
+}
+
+void __connman_rtnl_cleanup(void)
+{
+	GSList *list;
+
+	DBG("");
+
+	for (list = watch_list; list; list = list->next) {
+		struct watch_data *watch = list->data;
+
+		DBG("removing watch %d", watch->id);
+
+		g_free(watch);
+		list->data = NULL;
+	}
+
+	g_slist_free(watch_list);
+	watch_list = NULL;
+
+	g_slist_free(update_list);
+	update_list = NULL;
+
+	for (list = request_list; list; list = list->next) {
+		struct rtnl_request *req = list->data;
+
+		DBG("%s len %d type %d flags 0x%04x seq %d",
+				type2string(req->hdr.nlmsg_type),
+				req->hdr.nlmsg_len, req->hdr.nlmsg_type,
+				req->hdr.nlmsg_flags, req->hdr.nlmsg_seq);
+
+		g_free(req);
+		list->data = NULL;
+	}
+
+	g_slist_free(request_list);
+	request_list = NULL;
+
+	if (channel_watch) {
+		g_source_remove(channel_watch);
+		channel_watch = 0;
+	}
+
+	g_io_channel_shutdown(channel, TRUE, NULL);
+	g_io_channel_unref(channel);
+
+	channel = NULL;
+
+	g_hash_table_destroy(interface_list);
+}
diff --git a/connman/src/service.c b/connman/src/service.c
new file mode 100644
index 0000000..81b28ae
--- /dev/null
+++ b/connman/src/service.c
@@ -0,0 +1,7198 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2014  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 <stdio.h>
+#include <string.h>
+#include <netdb.h>
+#include <gdbus.h>
+#include <ctype.h>
+#include <stdint.h>
+
+#include <connman/storage.h>
+#include <connman/setting.h>
+#include <connman/agent.h>
+
+#include "connman.h"
+
+#define CONNECT_TIMEOUT		120
+
+static DBusConnection *connection = NULL;
+
+static GList *service_list = NULL;
+static GHashTable *service_hash = NULL;
+static GSList *counter_list = NULL;
+static unsigned int autoconnect_timeout = 0;
+static unsigned int vpn_autoconnect_timeout = 0;
+static struct connman_service *current_default = NULL;
+static bool services_dirty = false;
+
+struct connman_stats {
+	bool valid;
+	bool enabled;
+	struct connman_stats_data data_last;
+	struct connman_stats_data data;
+	GTimer *timer;
+};
+
+struct connman_stats_counter {
+	bool append_all;
+	struct connman_stats stats;
+	struct connman_stats stats_roaming;
+};
+
+struct connman_service {
+	int refcount;
+	char *identifier;
+	char *path;
+	enum connman_service_type type;
+	enum connman_service_security security;
+	enum connman_service_state state;
+	enum connman_service_state state_ipv4;
+	enum connman_service_state state_ipv6;
+	enum connman_service_error error;
+	enum connman_service_connect_reason connect_reason;
+	uint8_t strength;
+	bool favorite;
+	bool immutable;
+	bool hidden;
+	bool ignore;
+	bool autoconnect;
+	GTimeVal modified;
+	unsigned int order;
+	char *name;
+	char *passphrase;
+	bool roaming;
+	struct connman_ipconfig *ipconfig_ipv4;
+	struct connman_ipconfig *ipconfig_ipv6;
+	struct connman_network *network;
+	struct connman_provider *provider;
+	char **nameservers;
+	char **nameservers_config;
+	char **nameservers_auto;
+	char **domains;
+	char *hostname;
+	char *domainname;
+	char **timeservers;
+	char **timeservers_config;
+	/* 802.1x settings from the config files */
+	char *eap;
+	char *identity;
+	char *agent_identity;
+	char *ca_cert_file;
+	char *client_cert_file;
+	char *private_key_file;
+	char *private_key_passphrase;
+	char *phase2;
+	DBusMessage *pending;
+	DBusMessage *provider_pending;
+	guint timeout;
+	struct connman_stats stats;
+	struct connman_stats stats_roaming;
+	GHashTable *counter_table;
+	enum connman_service_proxy_method proxy;
+	enum connman_service_proxy_method proxy_config;
+	char **proxies;
+	char **excludes;
+	char *pac;
+	bool wps;
+	int online_check_count;
+	bool do_split_routing;
+	bool new_service;
+	bool hidden_service;
+	char *config_file;
+	char *config_entry;
+};
+
+static bool allow_property_changed(struct connman_service *service);
+
+static struct connman_ipconfig *create_ip4config(struct connman_service *service,
+		int index, enum connman_ipconfig_method method);
+static struct connman_ipconfig *create_ip6config(struct connman_service *service,
+		int index);
+
+
+struct find_data {
+	const char *path;
+	struct connman_service *service;
+};
+
+static void compare_path(gpointer value, gpointer user_data)
+{
+	struct connman_service *service = value;
+	struct find_data *data = user_data;
+
+	if (data->service)
+		return;
+
+	if (g_strcmp0(service->path, data->path) == 0)
+		data->service = service;
+}
+
+static struct connman_service *find_service(const char *path)
+{
+	struct find_data data = { .path = path, .service = NULL };
+
+	DBG("path %s", path);
+
+	g_list_foreach(service_list, compare_path, &data);
+
+	return data.service;
+}
+
+static const char *reason2string(enum connman_service_connect_reason reason)
+{
+
+	switch (reason) {
+	case CONNMAN_SERVICE_CONNECT_REASON_NONE:
+		return "none";
+	case CONNMAN_SERVICE_CONNECT_REASON_USER:
+		return "user";
+	case CONNMAN_SERVICE_CONNECT_REASON_AUTO:
+		return "auto";
+	case CONNMAN_SERVICE_CONNECT_REASON_SESSION:
+		return "session";
+	}
+
+	return "unknown";
+}
+
+const char *__connman_service_type2string(enum connman_service_type type)
+{
+	switch (type) {
+	case CONNMAN_SERVICE_TYPE_UNKNOWN:
+		break;
+	case CONNMAN_SERVICE_TYPE_SYSTEM:
+		return "system";
+	case CONNMAN_SERVICE_TYPE_ETHERNET:
+		return "ethernet";
+	case CONNMAN_SERVICE_TYPE_WIFI:
+		return "wifi";
+	case CONNMAN_SERVICE_TYPE_BLUETOOTH:
+		return "bluetooth";
+	case CONNMAN_SERVICE_TYPE_CELLULAR:
+		return "cellular";
+	case CONNMAN_SERVICE_TYPE_GPS:
+		return "gps";
+	case CONNMAN_SERVICE_TYPE_VPN:
+		return "vpn";
+	case CONNMAN_SERVICE_TYPE_GADGET:
+		return "gadget";
+	case CONNMAN_SERVICE_TYPE_P2P:
+		return "p2p";
+	case CONNMAN_SERVICE_TYPE_LOWPAN:
+		return "lowpan";
+	
+	}
+
+	return NULL;
+}
+
+enum connman_service_type __connman_service_string2type(const char *str)
+{
+	if (!str)
+		return CONNMAN_SERVICE_TYPE_UNKNOWN;
+
+	if (strcmp(str, "ethernet") == 0)
+		return CONNMAN_SERVICE_TYPE_ETHERNET;
+	if (strcmp(str, "gadget") == 0)
+		return CONNMAN_SERVICE_TYPE_GADGET;
+	if (strcmp(str, "wifi") == 0)
+		return CONNMAN_SERVICE_TYPE_WIFI;
+	if (strcmp(str, "cellular") == 0)
+		return CONNMAN_SERVICE_TYPE_CELLULAR;
+	if (strcmp(str, "bluetooth") == 0)
+		return CONNMAN_SERVICE_TYPE_BLUETOOTH;
+	if (strcmp(str, "vpn") == 0)
+		return CONNMAN_SERVICE_TYPE_VPN;
+	if (strcmp(str, "gps") == 0)
+		return CONNMAN_SERVICE_TYPE_GPS;
+	if (strcmp(str, "system") == 0)
+		return CONNMAN_SERVICE_TYPE_SYSTEM;
+	if (strcmp(str, "p2p") == 0)
+		return CONNMAN_SERVICE_TYPE_P2P;
+
+	return CONNMAN_SERVICE_TYPE_UNKNOWN;
+}
+
+enum connman_service_security __connman_service_string2security(const char *str)
+{
+	if (!str)
+		return CONNMAN_SERVICE_SECURITY_UNKNOWN;
+
+	if (!strcmp(str, "psk"))
+		return CONNMAN_SERVICE_SECURITY_PSK;
+	if (!strcmp(str, "ieee8021x"))
+		return CONNMAN_SERVICE_SECURITY_8021X;
+	if (!strcmp(str, "none"))
+		return CONNMAN_SERVICE_SECURITY_NONE;
+	if (!strcmp(str, "wep"))
+		return CONNMAN_SERVICE_SECURITY_WEP;
+
+	return CONNMAN_SERVICE_SECURITY_UNKNOWN;
+}
+
+static const char *security2string(enum connman_service_security security)
+{
+	switch (security) {
+	case CONNMAN_SERVICE_SECURITY_UNKNOWN:
+		break;
+	case CONNMAN_SERVICE_SECURITY_NONE:
+		return "none";
+	case CONNMAN_SERVICE_SECURITY_WEP:
+		return "wep";
+	case CONNMAN_SERVICE_SECURITY_PSK:
+	case CONNMAN_SERVICE_SECURITY_WPA:
+	case CONNMAN_SERVICE_SECURITY_RSN:
+		return "psk";
+	case CONNMAN_SERVICE_SECURITY_8021X:
+		return "ieee8021x";
+	}
+
+	return NULL;
+}
+
+static const char *state2string(enum connman_service_state state)
+{
+	switch (state) {
+	case CONNMAN_SERVICE_STATE_UNKNOWN:
+		break;
+	case CONNMAN_SERVICE_STATE_IDLE:
+		return "idle";
+	case CONNMAN_SERVICE_STATE_ASSOCIATION:
+		return "association";
+	case CONNMAN_SERVICE_STATE_CONFIGURATION:
+		return "configuration";
+	case CONNMAN_SERVICE_STATE_READY:
+		return "ready";
+	case CONNMAN_SERVICE_STATE_ONLINE:
+		return "online";
+	case CONNMAN_SERVICE_STATE_DISCONNECT:
+		return "disconnect";
+	case CONNMAN_SERVICE_STATE_FAILURE:
+		return "failure";
+	}
+
+	return NULL;
+}
+
+static const char *error2string(enum connman_service_error error)
+{
+	switch (error) {
+	case CONNMAN_SERVICE_ERROR_UNKNOWN:
+		break;
+	case CONNMAN_SERVICE_ERROR_OUT_OF_RANGE:
+		return "out-of-range";
+	case CONNMAN_SERVICE_ERROR_PIN_MISSING:
+		return "pin-missing";
+	case CONNMAN_SERVICE_ERROR_DHCP_FAILED:
+		return "dhcp-failed";
+	case CONNMAN_SERVICE_ERROR_CONNECT_FAILED:
+		return "connect-failed";
+	case CONNMAN_SERVICE_ERROR_LOGIN_FAILED:
+		return "login-failed";
+	case CONNMAN_SERVICE_ERROR_AUTH_FAILED:
+		return "auth-failed";
+	case CONNMAN_SERVICE_ERROR_INVALID_KEY:
+		return "invalid-key";
+	}
+
+	return NULL;
+}
+
+static const char *proxymethod2string(enum connman_service_proxy_method method)
+{
+	switch (method) {
+	case CONNMAN_SERVICE_PROXY_METHOD_DIRECT:
+		return "direct";
+	case CONNMAN_SERVICE_PROXY_METHOD_MANUAL:
+		return "manual";
+	case CONNMAN_SERVICE_PROXY_METHOD_AUTO:
+		return "auto";
+	case CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN:
+		break;
+	}
+
+	return NULL;
+}
+
+static enum connman_service_proxy_method string2proxymethod(const char *method)
+{
+	if (g_strcmp0(method, "direct") == 0)
+		return CONNMAN_SERVICE_PROXY_METHOD_DIRECT;
+	else if (g_strcmp0(method, "auto") == 0)
+		return CONNMAN_SERVICE_PROXY_METHOD_AUTO;
+	else if (g_strcmp0(method, "manual") == 0)
+		return CONNMAN_SERVICE_PROXY_METHOD_MANUAL;
+	else
+		return CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN;
+}
+
+int __connman_service_load_modifiable(struct connman_service *service)
+{
+	GKeyFile *keyfile;
+	GError *error = NULL;
+	gchar *str;
+	bool autoconnect;
+
+	DBG("service %p", service);
+
+	keyfile = connman_storage_load_service(service->identifier);
+	if (!keyfile)
+		return -EIO;
+
+	switch (service->type) {
+	case CONNMAN_SERVICE_TYPE_UNKNOWN:
+	case CONNMAN_SERVICE_TYPE_SYSTEM:
+	case CONNMAN_SERVICE_TYPE_GPS:
+	case CONNMAN_SERVICE_TYPE_P2P:
+		break;
+	case CONNMAN_SERVICE_TYPE_VPN:
+		service->do_split_routing = g_key_file_get_boolean(keyfile,
+				service->identifier, "SplitRouting", NULL);
+		/* fall through */
+	case CONNMAN_SERVICE_TYPE_WIFI:
+	case CONNMAN_SERVICE_TYPE_GADGET:
+	case CONNMAN_SERVICE_TYPE_BLUETOOTH:
+	case CONNMAN_SERVICE_TYPE_CELLULAR:
+	case CONNMAN_SERVICE_TYPE_ETHERNET:
+		autoconnect = g_key_file_get_boolean(keyfile,
+				service->identifier, "AutoConnect", &error);
+		if (!error)
+			service->autoconnect = autoconnect;
+		g_clear_error(&error);
+		break;
+	}
+
+	str = g_key_file_get_string(keyfile,
+				service->identifier, "Modified", NULL);
+	if (str) {
+		g_time_val_from_iso8601(str, &service->modified);
+		g_free(str);
+	}
+
+	g_key_file_free(keyfile);
+
+	return 0;
+}
+
+static int service_load(struct connman_service *service)
+{
+	GKeyFile *keyfile;
+	GError *error = NULL;
+	gsize length;
+	gchar *str;
+	bool autoconnect;
+	unsigned int ssid_len;
+	int err = 0;
+
+	DBG("service %p", service);
+
+	keyfile = connman_storage_load_service(service->identifier);
+	if (!keyfile) {
+		service->new_service = true;
+		return -EIO;
+	} else
+		service->new_service = false;
+
+	switch (service->type) {
+	case CONNMAN_SERVICE_TYPE_UNKNOWN:
+	case CONNMAN_SERVICE_TYPE_SYSTEM:
+	case CONNMAN_SERVICE_TYPE_GPS:
+	case CONNMAN_SERVICE_TYPE_P2P:
+		break;
+	case CONNMAN_SERVICE_TYPE_VPN:
+		service->do_split_routing = g_key_file_get_boolean(keyfile,
+				service->identifier, "SplitRouting", NULL);
+		autoconnect = g_key_file_get_boolean(keyfile,
+				service->identifier, "AutoConnect", &error);
+		if (!error)
+			service->autoconnect = autoconnect;
+		g_clear_error(&error);
+		break;
+	case CONNMAN_SERVICE_TYPE_WIFI:
+		if (!service->name) {
+			gchar *name;
+
+			name = g_key_file_get_string(keyfile,
+					service->identifier, "Name", NULL);
+			if (name) {
+				g_free(service->name);
+				service->name = name;
+			}
+
+			if (service->network)
+				connman_network_set_name(service->network,
+									name);
+		}
+
+		if (service->network &&
+				!connman_network_get_blob(service->network,
+						"WiFi.SSID", &ssid_len)) {
+			gchar *hex_ssid;
+
+			hex_ssid = g_key_file_get_string(keyfile,
+							service->identifier,
+								"SSID", NULL);
+
+			if (hex_ssid) {
+				gchar *ssid;
+				unsigned int i, j = 0, hex;
+				size_t hex_ssid_len = strlen(hex_ssid);
+
+				ssid = g_try_malloc0(hex_ssid_len / 2);
+				if (!ssid) {
+					g_free(hex_ssid);
+					err = -ENOMEM;
+					goto done;
+				}
+
+				for (i = 0; i < hex_ssid_len; i += 2) {
+					sscanf(hex_ssid + i, "%02x", &hex);
+					ssid[j++] = hex;
+				}
+
+				connman_network_set_blob(service->network,
+					"WiFi.SSID", ssid, hex_ssid_len / 2);
+			}
+
+			g_free(hex_ssid);
+		}
+		/* fall through */
+
+	case CONNMAN_SERVICE_TYPE_GADGET:
+	case CONNMAN_SERVICE_TYPE_LOWPAN:
+	case CONNMAN_SERVICE_TYPE_BLUETOOTH:
+	case CONNMAN_SERVICE_TYPE_CELLULAR:
+		service->favorite = g_key_file_get_boolean(keyfile,
+				service->identifier, "Favorite", NULL);
+
+		/* fall through */
+
+	case CONNMAN_SERVICE_TYPE_ETHERNET:
+		autoconnect = g_key_file_get_boolean(keyfile,
+				service->identifier, "AutoConnect", &error);
+		if (!error)
+			service->autoconnect = autoconnect;
+		g_clear_error(&error);
+		break;
+	}
+
+	str = g_key_file_get_string(keyfile,
+				service->identifier, "Modified", NULL);
+	if (str) {
+		g_time_val_from_iso8601(str, &service->modified);
+		g_free(str);
+	}
+
+	str = g_key_file_get_string(keyfile,
+				service->identifier, "Passphrase", NULL);
+	if (str) {
+		g_free(service->passphrase);
+		service->passphrase = str;
+	}
+
+	if (service->ipconfig_ipv4)
+		__connman_ipconfig_load(service->ipconfig_ipv4, keyfile,
+					service->identifier, "IPv4.");
+
+	if (service->ipconfig_ipv6)
+		__connman_ipconfig_load(service->ipconfig_ipv6, keyfile,
+					service->identifier, "IPv6.");
+
+	service->nameservers_config = g_key_file_get_string_list(keyfile,
+			service->identifier, "Nameservers", &length, NULL);
+	if (service->nameservers_config && length == 0) {
+		g_strfreev(service->nameservers_config);
+		service->nameservers_config = NULL;
+	}
+
+	service->timeservers_config = g_key_file_get_string_list(keyfile,
+			service->identifier, "Timeservers", &length, NULL);
+	if (service->timeservers_config && length == 0) {
+		g_strfreev(service->timeservers_config);
+		service->timeservers_config = NULL;
+	}
+
+	service->domains = g_key_file_get_string_list(keyfile,
+			service->identifier, "Domains", &length, NULL);
+	if (service->domains && length == 0) {
+		g_strfreev(service->domains);
+		service->domains = NULL;
+	}
+
+	str = g_key_file_get_string(keyfile,
+				service->identifier, "Proxy.Method", NULL);
+	if (str)
+		service->proxy_config = string2proxymethod(str);
+
+	g_free(str);
+
+	service->proxies = g_key_file_get_string_list(keyfile,
+			service->identifier, "Proxy.Servers", &length, NULL);
+	if (service->proxies && length == 0) {
+		g_strfreev(service->proxies);
+		service->proxies = NULL;
+	}
+
+	service->excludes = g_key_file_get_string_list(keyfile,
+			service->identifier, "Proxy.Excludes", &length, NULL);
+	if (service->excludes && length == 0) {
+		g_strfreev(service->excludes);
+		service->excludes = NULL;
+	}
+
+	str = g_key_file_get_string(keyfile,
+				service->identifier, "Proxy.URL", NULL);
+	if (str) {
+		g_free(service->pac);
+		service->pac = str;
+	}
+
+	service->hidden_service = g_key_file_get_boolean(keyfile,
+					service->identifier, "Hidden", NULL);
+
+done:
+	g_key_file_free(keyfile);
+
+	return err;
+}
+
+static int service_save(struct connman_service *service)
+{
+	GKeyFile *keyfile;
+	gchar *str;
+	guint freq;
+	const char *cst_str = NULL;
+	int err = 0;
+
+	DBG("service %p new %d", service, service->new_service);
+
+	if (service->new_service)
+		return -ESRCH;
+
+	keyfile = __connman_storage_open_service(service->identifier);
+	if (!keyfile)
+		return -EIO;
+
+	if (service->name)
+		g_key_file_set_string(keyfile, service->identifier,
+						"Name", service->name);
+
+	switch (service->type) {
+	case CONNMAN_SERVICE_TYPE_UNKNOWN:
+	case CONNMAN_SERVICE_TYPE_SYSTEM:
+	case CONNMAN_SERVICE_TYPE_GPS:
+	case CONNMAN_SERVICE_TYPE_P2P:
+		break;
+	case CONNMAN_SERVICE_TYPE_VPN:
+		g_key_file_set_boolean(keyfile, service->identifier,
+				"SplitRouting", service->do_split_routing);
+		if (service->favorite)
+			g_key_file_set_boolean(keyfile, service->identifier,
+					"AutoConnect", service->autoconnect);
+		break;
+	case CONNMAN_SERVICE_TYPE_WIFI:
+		if (service->network) {
+			const unsigned char *ssid;
+			unsigned int ssid_len = 0;
+
+			ssid = connman_network_get_blob(service->network,
+							"WiFi.SSID", &ssid_len);
+
+			if (ssid && ssid_len > 0 && ssid[0] != '\0') {
+				char *identifier = service->identifier;
+				GString *ssid_str;
+				unsigned int i;
+
+				ssid_str = g_string_sized_new(ssid_len * 2);
+				if (!ssid_str) {
+					err = -ENOMEM;
+					goto done;
+				}
+
+				for (i = 0; i < ssid_len; i++)
+					g_string_append_printf(ssid_str,
+							"%02x", ssid[i]);
+
+				g_key_file_set_string(keyfile, identifier,
+							"SSID", ssid_str->str);
+
+				g_string_free(ssid_str, TRUE);
+			}
+
+			freq = connman_network_get_frequency(service->network);
+			g_key_file_set_integer(keyfile, service->identifier,
+						"Frequency", freq);
+		}
+		/* fall through */
+
+	case CONNMAN_SERVICE_TYPE_GADGET:
+	case CONNMAN_SERVICE_TYPE_LOWPAN:
+	case CONNMAN_SERVICE_TYPE_BLUETOOTH:
+	case CONNMAN_SERVICE_TYPE_CELLULAR:
+		g_key_file_set_boolean(keyfile, service->identifier,
+					"Favorite", service->favorite);
+
+		g_key_file_remove_key(keyfile, service->identifier,
+				"Failure", NULL);
+
+		/* fall through */
+
+	case CONNMAN_SERVICE_TYPE_ETHERNET:
+		if (service->favorite)
+			g_key_file_set_boolean(keyfile, service->identifier,
+					"AutoConnect", service->autoconnect);
+		break;
+	}
+
+	str = g_time_val_to_iso8601(&service->modified);
+	if (str) {
+		g_key_file_set_string(keyfile, service->identifier,
+							"Modified", str);
+		g_free(str);
+	}
+
+	if (service->passphrase && strlen(service->passphrase) > 0)
+		g_key_file_set_string(keyfile, service->identifier,
+					"Passphrase", service->passphrase);
+	else
+		g_key_file_remove_key(keyfile, service->identifier,
+							"Passphrase", NULL);
+
+	if (service->ipconfig_ipv4)
+		__connman_ipconfig_save(service->ipconfig_ipv4, keyfile,
+					service->identifier, "IPv4.");
+
+	if (service->ipconfig_ipv6)
+		__connman_ipconfig_save(service->ipconfig_ipv6, keyfile,
+						service->identifier, "IPv6.");
+
+	if (service->nameservers_config) {
+		guint len = g_strv_length(service->nameservers_config);
+
+		g_key_file_set_string_list(keyfile, service->identifier,
+								"Nameservers",
+				(const gchar **) service->nameservers_config, len);
+	} else
+	g_key_file_remove_key(keyfile, service->identifier,
+							"Nameservers", NULL);
+
+	if (service->timeservers_config) {
+		guint len = g_strv_length(service->timeservers_config);
+
+		g_key_file_set_string_list(keyfile, service->identifier,
+								"Timeservers",
+				(const gchar **) service->timeservers_config, len);
+	} else
+		g_key_file_remove_key(keyfile, service->identifier,
+							"Timeservers", NULL);
+
+	if (service->domains) {
+		guint len = g_strv_length(service->domains);
+
+		g_key_file_set_string_list(keyfile, service->identifier,
+								"Domains",
+				(const gchar **) service->domains, len);
+	} else
+		g_key_file_remove_key(keyfile, service->identifier,
+							"Domains", NULL);
+
+	cst_str = proxymethod2string(service->proxy_config);
+	if (cst_str)
+		g_key_file_set_string(keyfile, service->identifier,
+				"Proxy.Method", cst_str);
+
+	if (service->proxies) {
+		guint len = g_strv_length(service->proxies);
+
+		g_key_file_set_string_list(keyfile, service->identifier,
+				"Proxy.Servers",
+				(const gchar **) service->proxies, len);
+	} else
+		g_key_file_remove_key(keyfile, service->identifier,
+						"Proxy.Servers", NULL);
+
+	if (service->excludes) {
+		guint len = g_strv_length(service->excludes);
+
+		g_key_file_set_string_list(keyfile, service->identifier,
+				"Proxy.Excludes",
+				(const gchar **) service->excludes, len);
+	} else
+		g_key_file_remove_key(keyfile, service->identifier,
+						"Proxy.Excludes", NULL);
+
+	if (service->pac && strlen(service->pac) > 0)
+		g_key_file_set_string(keyfile, service->identifier,
+					"Proxy.URL", service->pac);
+	else
+		g_key_file_remove_key(keyfile, service->identifier,
+							"Proxy.URL", NULL);
+
+	if (service->hidden_service)
+		g_key_file_set_boolean(keyfile, service->identifier, "Hidden",
+									TRUE);
+
+	if (service->config_file && strlen(service->config_file) > 0)
+		g_key_file_set_string(keyfile, service->identifier,
+				"Config.file", service->config_file);
+
+	if (service->config_entry &&
+					strlen(service->config_entry) > 0)
+		g_key_file_set_string(keyfile, service->identifier,
+				"Config.ident", service->config_entry);
+
+done:
+	__connman_storage_save_service(keyfile, service->identifier);
+
+	g_key_file_free(keyfile);
+
+	return err;
+}
+
+void __connman_service_save(struct connman_service *service)
+{
+	if (!service)
+		return;
+
+	service_save(service);
+}
+
+static enum connman_service_state combine_state(
+					enum connman_service_state state_a,
+					enum connman_service_state state_b)
+{
+	enum connman_service_state result;
+
+	if (state_a == state_b) {
+		result = state_a;
+		goto done;
+	}
+
+	if (state_a == CONNMAN_SERVICE_STATE_UNKNOWN) {
+		result = state_b;
+		goto done;
+	}
+
+	if (state_b == CONNMAN_SERVICE_STATE_UNKNOWN) {
+		result = state_a;
+		goto done;
+	}
+
+	if (state_a == CONNMAN_SERVICE_STATE_IDLE) {
+		result = state_b;
+		goto done;
+	}
+
+	if (state_b == CONNMAN_SERVICE_STATE_IDLE) {
+		result = state_a;
+		goto done;
+	}
+
+	if (state_a == CONNMAN_SERVICE_STATE_ONLINE) {
+		result = state_a;
+		goto done;
+	}
+
+	if (state_b == CONNMAN_SERVICE_STATE_ONLINE) {
+		result = state_b;
+		goto done;
+	}
+
+	if (state_a == CONNMAN_SERVICE_STATE_READY) {
+		result = state_a;
+		goto done;
+	}
+
+	if (state_b == CONNMAN_SERVICE_STATE_READY) {
+		result = state_b;
+		goto done;
+	}
+
+	if (state_a == CONNMAN_SERVICE_STATE_CONFIGURATION) {
+		result = state_a;
+		goto done;
+	}
+
+	if (state_b == CONNMAN_SERVICE_STATE_CONFIGURATION) {
+		result = state_b;
+		goto done;
+	}
+
+	if (state_a == CONNMAN_SERVICE_STATE_ASSOCIATION) {
+		result = state_a;
+		goto done;
+	}
+
+	if (state_b == CONNMAN_SERVICE_STATE_ASSOCIATION) {
+		result = state_b;
+		goto done;
+	}
+
+	if (state_a == CONNMAN_SERVICE_STATE_DISCONNECT) {
+		result = state_a;
+		goto done;
+	}
+
+	if (state_b == CONNMAN_SERVICE_STATE_DISCONNECT) {
+		result = state_b;
+		goto done;
+	}
+
+	result = CONNMAN_SERVICE_STATE_FAILURE;
+
+done:
+	return result;
+}
+
+static bool is_connecting_state(struct connman_service *service,
+					enum connman_service_state state)
+{
+	switch (state) {
+	case CONNMAN_SERVICE_STATE_UNKNOWN:
+	case CONNMAN_SERVICE_STATE_IDLE:
+	case CONNMAN_SERVICE_STATE_FAILURE:
+		if (service->network)
+			return connman_network_get_connecting(service->network);
+	case CONNMAN_SERVICE_STATE_DISCONNECT:
+	case CONNMAN_SERVICE_STATE_READY:
+	case CONNMAN_SERVICE_STATE_ONLINE:
+		break;
+	case CONNMAN_SERVICE_STATE_ASSOCIATION:
+	case CONNMAN_SERVICE_STATE_CONFIGURATION:
+		return true;
+	}
+
+	return false;
+}
+
+static bool is_connected_state(const struct connman_service *service,
+					enum connman_service_state state)
+{
+	switch (state) {
+	case CONNMAN_SERVICE_STATE_UNKNOWN:
+	case CONNMAN_SERVICE_STATE_IDLE:
+	case CONNMAN_SERVICE_STATE_ASSOCIATION:
+	case CONNMAN_SERVICE_STATE_CONFIGURATION:
+	case CONNMAN_SERVICE_STATE_DISCONNECT:
+	case CONNMAN_SERVICE_STATE_FAILURE:
+		break;
+	case CONNMAN_SERVICE_STATE_READY:
+	case CONNMAN_SERVICE_STATE_ONLINE:
+		return true;
+	}
+
+	return false;
+}
+
+static bool is_idle_state(const struct connman_service *service,
+				enum connman_service_state state)
+{
+	switch (state) {
+	case CONNMAN_SERVICE_STATE_UNKNOWN:
+	case CONNMAN_SERVICE_STATE_ASSOCIATION:
+	case CONNMAN_SERVICE_STATE_CONFIGURATION:
+	case CONNMAN_SERVICE_STATE_READY:
+	case CONNMAN_SERVICE_STATE_ONLINE:
+	case CONNMAN_SERVICE_STATE_DISCONNECT:
+	case CONNMAN_SERVICE_STATE_FAILURE:
+		break;
+	case CONNMAN_SERVICE_STATE_IDLE:
+		return true;
+	}
+
+	return false;
+}
+
+static bool is_connecting(struct connman_service *service)
+{
+	return is_connecting_state(service, service->state);
+}
+
+static bool is_connected(struct connman_service *service)
+{
+	return is_connected_state(service, service->state);
+}
+
+static bool nameserver_available(struct connman_service *service,
+				enum connman_ipconfig_type type,
+				const char *ns)
+{
+	int family;
+
+	family = connman_inet_check_ipaddress(ns);
+
+	if (family == AF_INET) {
+		if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
+			return false;
+
+		return is_connected_state(service, service->state_ipv4);
+	}
+
+	if (family == AF_INET6) {
+		if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
+			return false;
+
+		return is_connected_state(service, service->state_ipv6);
+	}
+
+	return false;
+}
+
+static int nameserver_add(struct connman_service *service,
+			enum connman_ipconfig_type type,
+			const char *nameserver)
+{
+	int index;
+
+	if (!nameserver_available(service, type, nameserver))
+		return 0;
+
+	index = __connman_service_get_index(service);
+	if (index < 0)
+		return -ENXIO;
+
+	return connman_resolver_append(index, NULL, nameserver);
+}
+
+static int nameserver_add_all(struct connman_service *service,
+			enum connman_ipconfig_type type)
+{
+	int i = 0;
+
+	if (service->nameservers_config) {
+		while (service->nameservers_config[i]) {
+			nameserver_add(service, type,
+				service->nameservers_config[i]);
+			i++;
+		}
+
+		return 0;
+	}
+
+	if (service->nameservers) {
+		while (service->nameservers[i]) {
+			nameserver_add(service, type,
+				service->nameservers[i]);
+			i++;
+		}
+	}
+
+	return 0;
+}
+
+static int nameserver_remove(struct connman_service *service,
+			enum connman_ipconfig_type type,
+			const char *nameserver)
+{
+	int index;
+
+	if (!nameserver_available(service, type, nameserver))
+		return 0;
+
+	index = __connman_service_get_index(service);
+	if (index < 0)
+		return -ENXIO;
+
+	return connman_resolver_remove(index, NULL, nameserver);
+}
+
+static int nameserver_remove_all(struct connman_service *service,
+				enum connman_ipconfig_type type)
+{
+	int index, i = 0;
+
+	index = __connman_service_get_index(service);
+	if (index < 0)
+		return -ENXIO;
+
+	while (service->nameservers_config && service->nameservers_config[i]) {
+
+		nameserver_remove(service, type,
+				service->nameservers_config[i]);
+		i++;
+	}
+
+	i = 0;
+	while (service->nameservers && service->nameservers[i]) {
+		nameserver_remove(service, type, service->nameservers[i]);
+		i++;
+	}
+
+	return 0;
+}
+
+static int searchdomain_add_all(struct connman_service *service)
+{
+	int index, i = 0;
+
+	if (!is_connected(service))
+		return -ENOTCONN;
+
+	index = __connman_service_get_index(service);
+	if (index < 0)
+		return -ENXIO;
+
+	if (service->domains) {
+		while (service->domains[i]) {
+			connman_resolver_append(index, service->domains[i],
+						NULL);
+			i++;
+		}
+
+		return 0;
+	}
+
+	if (service->domainname)
+		connman_resolver_append(index, service->domainname, NULL);
+
+	return 0;
+
+}
+
+static int searchdomain_remove_all(struct connman_service *service)
+{
+	int index, i = 0;
+
+	if (!is_connected(service))
+		return -ENOTCONN;
+
+	index = __connman_service_get_index(service);
+	if (index < 0)
+		return -ENXIO;
+
+	while (service->domains && service->domains[i]) {
+		connman_resolver_remove(index, service->domains[i], NULL);
+		i++;
+	}
+
+	if (service->domainname)
+		connman_resolver_remove(index, service->domainname, NULL);
+
+	return 0;
+}
+
+/*
+ * The is_auto variable is set to true when IPv6 autoconf nameservers are
+ * inserted to resolver via netlink message (see rtnl.c:rtnl_newnduseropt()
+ * for details) and not through service.c
+ */
+int __connman_service_nameserver_append(struct connman_service *service,
+				const char *nameserver, bool is_auto)
+{
+	char **nameservers;
+	int len, i;
+
+	DBG("service %p nameserver %s auto %d",	service, nameserver, is_auto);
+
+	if (!nameserver)
+		return -EINVAL;
+
+	if (is_auto)
+		nameservers = service->nameservers_auto;
+	else
+		nameservers = service->nameservers;
+
+	for (i = 0; nameservers && nameservers[i]; i++)
+		if (g_strcmp0(nameservers[i], nameserver) == 0)
+			return -EEXIST;
+
+	if (nameservers) {
+		len = g_strv_length(nameservers);
+		nameservers = g_try_renew(char *, nameservers, len + 2);
+	} else {
+		len = 0;
+		nameservers = g_try_new0(char *, len + 2);
+	}
+
+	if (!nameservers)
+		return -ENOMEM;
+
+	nameservers[len] = g_strdup(nameserver);
+	if (!nameservers[len])
+		return -ENOMEM;
+
+	nameservers[len + 1] = NULL;
+
+	if (is_auto) {
+		service->nameservers_auto = nameservers;
+	} else {
+		service->nameservers = nameservers;
+		nameserver_add(service, CONNMAN_IPCONFIG_TYPE_ALL, nameserver);
+	}
+
+	return 0;
+}
+
+int __connman_service_nameserver_remove(struct connman_service *service,
+				const char *nameserver, bool is_auto)
+{
+	char **servers, **nameservers;
+	bool found = false;
+	int len, i, j;
+
+	DBG("service %p nameserver %s auto %d", service, nameserver, is_auto);
+
+	if (!nameserver)
+		return -EINVAL;
+
+	if (is_auto)
+		nameservers = service->nameservers_auto;
+	else
+		nameservers = service->nameservers;
+
+	if (!nameservers)
+		return 0;
+
+	for (i = 0; nameservers && nameservers[i]; i++)
+		if (g_strcmp0(nameservers[i], nameserver) == 0) {
+			found = true;
+			break;
+		}
+
+	if (!found)
+		return 0;
+
+	len = g_strv_length(nameservers);
+
+	if (len == 1) {
+		servers = NULL;
+		goto set_servers;
+	}
+
+	servers = g_try_new0(char *, len);
+	if (!servers)
+		return -ENOMEM;
+
+	for (i = 0, j = 0; i < len; i++) {
+		if (g_strcmp0(nameservers[i], nameserver)) {
+			servers[j] = nameservers[i];
+			j++;
+		} else
+			g_free(nameservers[i]);
+
+		nameservers[i] = NULL;
+	}
+	servers[len - 1] = NULL;
+
+set_servers:
+	g_strfreev(nameservers);
+	nameservers = servers;
+
+	if (is_auto) {
+		service->nameservers_auto = nameservers;
+	} else {
+		service->nameservers = nameservers;
+		nameserver_remove(service, CONNMAN_IPCONFIG_TYPE_ALL,
+				nameserver);
+	}
+
+	return 0;
+}
+
+void __connman_service_nameserver_clear(struct connman_service *service)
+{
+	nameserver_remove_all(service, CONNMAN_IPCONFIG_TYPE_ALL);
+
+	g_strfreev(service->nameservers);
+	service->nameservers = NULL;
+
+	nameserver_add_all(service, CONNMAN_IPCONFIG_TYPE_ALL);
+}
+
+static void add_nameserver_route(int family, int index, char *nameserver,
+				const char *gw)
+{
+	switch (family) {
+	case AF_INET:
+		if (connman_inet_compare_subnet(index, nameserver))
+			break;
+
+		if (connman_inet_add_host_route(index, nameserver, gw) < 0)
+			/* For P-t-P link the above route add will fail */
+			connman_inet_add_host_route(index, nameserver, NULL);
+		break;
+
+	case AF_INET6:
+		if (connman_inet_add_ipv6_host_route(index, nameserver,
+								gw) < 0)
+			connman_inet_add_ipv6_host_route(index, nameserver,
+							NULL);
+		break;
+	}
+}
+
+static void nameserver_add_routes(int index, char **nameservers,
+					const char *gw)
+{
+	int i, ns_family, gw_family;
+
+	gw_family = connman_inet_check_ipaddress(gw);
+	if (gw_family < 0)
+		return;
+
+	for (i = 0; nameservers[i]; i++) {
+		ns_family = connman_inet_check_ipaddress(nameservers[i]);
+		if (ns_family < 0 || ns_family != gw_family)
+			continue;
+
+		add_nameserver_route(ns_family, index, nameservers[i], gw);
+	}
+}
+
+static void nameserver_del_routes(int index, char **nameservers,
+				enum connman_ipconfig_type type)
+{
+	int i, family;
+
+	for (i = 0; nameservers[i]; i++) {
+		family = connman_inet_check_ipaddress(nameservers[i]);
+		if (family < 0)
+			continue;
+
+		switch (family) {
+		case AF_INET:
+			if (type != CONNMAN_IPCONFIG_TYPE_IPV6)
+				connman_inet_del_host_route(index,
+							nameservers[i]);
+			break;
+		case AF_INET6:
+			if (type != CONNMAN_IPCONFIG_TYPE_IPV4)
+				connman_inet_del_ipv6_host_route(index,
+							nameservers[i]);
+			break;
+		}
+	}
+}
+
+void __connman_service_nameserver_add_routes(struct connman_service *service,
+						const char *gw)
+{
+	int index;
+
+	if (!service)
+		return;
+
+	index = __connman_service_get_index(service);
+
+	if (service->nameservers_config) {
+		/*
+		 * Configured nameserver takes preference over the
+		 * discoverd nameserver gathered from DHCP, VPN, etc.
+		 */
+		nameserver_add_routes(index, service->nameservers_config, gw);
+	} else if (service->nameservers) {
+		/*
+		 * We add nameservers host routes for nameservers that
+		 * are not on our subnet. For those who are, the subnet
+		 * route will be installed by the time the dns proxy code
+		 * tries to reach them. The subnet route is installed
+		 * when setting the interface IP address.
+		 */
+		nameserver_add_routes(index, service->nameservers, gw);
+	}
+}
+
+void __connman_service_nameserver_del_routes(struct connman_service *service,
+					enum connman_ipconfig_type type)
+{
+	int index;
+
+	if (!service)
+		return;
+
+	index = __connman_service_get_index(service);
+
+	if (service->nameservers_config)
+		nameserver_del_routes(index, service->nameservers_config,
+					type);
+	else if (service->nameservers)
+		nameserver_del_routes(index, service->nameservers, type);
+}
+
+static struct connman_stats *stats_get(struct connman_service *service)
+{
+	if (service->roaming)
+		return &service->stats_roaming;
+	else
+		return &service->stats;
+}
+
+static bool stats_enabled(struct connman_service *service)
+{
+	struct connman_stats *stats = stats_get(service);
+
+	return stats->enabled;
+}
+
+static void stats_start(struct connman_service *service)
+{
+	struct connman_stats *stats = stats_get(service);
+
+	DBG("service %p", service);
+
+	connman_verify_execute(stats != NULL, return);
+
+	if (!stats->timer)
+		return;
+
+	stats->enabled = true;
+	stats->data_last.time = stats->data.time;
+
+	g_timer_start(stats->timer);
+}
+
+static void stats_stop(struct connman_service *service)
+{
+	struct connman_stats *stats = stats_get(service);
+	unsigned int seconds;
+
+	DBG("service %p", service);
+
+	connman_verify_execute(stats != NULL, return);
+
+	if (!stats->timer)
+		return;
+
+	if (!stats->enabled)
+		return;
+
+	g_timer_stop(stats->timer);
+
+	seconds = g_timer_elapsed(stats->timer, NULL);
+	stats->data.time = stats->data_last.time + seconds;
+
+	stats->enabled = false;
+}
+
+static void reset_stats(struct connman_service *service)
+{
+	DBG("service %p", service);
+
+	/* home */
+	service->stats.valid = false;
+
+	service->stats.data.rx_packets = 0;
+	service->stats.data.tx_packets = 0;
+	service->stats.data.rx_bytes = 0;
+	service->stats.data.tx_bytes = 0;
+	service->stats.data.rx_errors = 0;
+	service->stats.data.tx_errors = 0;
+	service->stats.data.rx_dropped = 0;
+	service->stats.data.tx_dropped = 0;
+	service->stats.data.time = 0;
+	service->stats.data_last.time = 0;
+
+	g_timer_reset(service->stats.timer);
+
+	/* roaming */
+	service->stats_roaming.valid = false;
+
+	service->stats_roaming.data.rx_packets = 0;
+	service->stats_roaming.data.tx_packets = 0;
+	service->stats_roaming.data.rx_bytes = 0;
+	service->stats_roaming.data.tx_bytes = 0;
+	service->stats_roaming.data.rx_errors = 0;
+	service->stats_roaming.data.tx_errors = 0;
+	service->stats_roaming.data.rx_dropped = 0;
+	service->stats_roaming.data.tx_dropped = 0;
+	service->stats_roaming.data.time = 0;
+	service->stats_roaming.data_last.time = 0;
+
+	g_timer_reset(service->stats_roaming.timer);
+}
+
+struct connman_service *__connman_service_get_default(void)
+{
+	struct connman_service *service;
+
+	if (!service_list)
+		return NULL;
+
+	service = service_list->data;
+
+	if (!is_connected(service))
+		return NULL;
+
+	return service;
+}
+
+bool __connman_service_index_is_default(int index)
+{
+	struct connman_service *service;
+
+	if (index < 0)
+		return false;
+
+	service = __connman_service_get_default();
+
+	return __connman_service_get_index(service) == index;
+}
+
+static void default_changed(void)
+{
+	struct connman_service *service = __connman_service_get_default();
+
+	if (service == current_default)
+		return;
+
+	DBG("current default %p %s", current_default,
+		current_default ? current_default->identifier : "");
+	DBG("new default %p %s", service, service ? service->identifier : "");
+
+	__connman_service_timeserver_changed(current_default, NULL);
+
+	current_default = service;
+
+	if (service) {
+		if (service->hostname &&
+				connman_setting_get_bool("AllowHostnameUpdates"))
+			__connman_utsname_set_hostname(service->hostname);
+
+		if (service->domainname)
+			__connman_utsname_set_domainname(service->domainname);
+	}
+
+	__connman_notifier_default_changed(service);
+}
+
+static void state_changed(struct connman_service *service)
+{
+	const char *str;
+
+	__connman_notifier_service_state_changed(service, service->state);
+
+	str = state2string(service->state);
+	if (!str)
+		return;
+
+	if (!allow_property_changed(service))
+		return;
+
+	connman_dbus_property_changed_basic(service->path,
+				CONNMAN_SERVICE_INTERFACE, "State",
+						DBUS_TYPE_STRING, &str);
+}
+
+static void strength_changed(struct connman_service *service)
+{
+	if (service->strength == 0)
+		return;
+
+	if (!allow_property_changed(service))
+		return;
+
+	connman_dbus_property_changed_basic(service->path,
+				CONNMAN_SERVICE_INTERFACE, "Strength",
+					DBUS_TYPE_BYTE, &service->strength);
+}
+
+static void favorite_changed(struct connman_service *service)
+{
+	dbus_bool_t favorite;
+
+	if (!service->path)
+		return;
+
+	if (!allow_property_changed(service))
+		return;
+
+	favorite = service->favorite;
+	connman_dbus_property_changed_basic(service->path,
+				CONNMAN_SERVICE_INTERFACE, "Favorite",
+					DBUS_TYPE_BOOLEAN, &favorite);
+}
+
+static void immutable_changed(struct connman_service *service)
+{
+	dbus_bool_t immutable;
+
+	if (!service->path)
+		return;
+
+	if (!allow_property_changed(service))
+		return;
+
+	immutable = service->immutable;
+	connman_dbus_property_changed_basic(service->path,
+				CONNMAN_SERVICE_INTERFACE, "Immutable",
+					DBUS_TYPE_BOOLEAN, &immutable);
+}
+
+static void roaming_changed(struct connman_service *service)
+{
+	dbus_bool_t roaming;
+
+	if (!service->path)
+		return;
+
+	if (!allow_property_changed(service))
+		return;
+
+	roaming = service->roaming;
+	connman_dbus_property_changed_basic(service->path,
+				CONNMAN_SERVICE_INTERFACE, "Roaming",
+					DBUS_TYPE_BOOLEAN, &roaming);
+}
+
+static void autoconnect_changed(struct connman_service *service)
+{
+	dbus_bool_t autoconnect;
+
+	if (!service->path)
+		return;
+
+	if (!allow_property_changed(service))
+		return;
+
+	autoconnect = service->autoconnect;
+	connman_dbus_property_changed_basic(service->path,
+				CONNMAN_SERVICE_INTERFACE, "AutoConnect",
+				DBUS_TYPE_BOOLEAN, &autoconnect);
+}
+
+static void append_security(DBusMessageIter *iter, void *user_data)
+{
+	struct connman_service *service = user_data;
+	const char *str;
+
+	str = security2string(service->security);
+	if (str)
+		dbus_message_iter_append_basic(iter,
+				DBUS_TYPE_STRING, &str);
+
+	/*
+	 * Some access points incorrectly advertise WPS even when they
+	 * are configured as open or no security, so filter
+	 * appropriately.
+	 */
+	if (service->wps) {
+		switch (service->security) {
+		case CONNMAN_SERVICE_SECURITY_PSK:
+		case CONNMAN_SERVICE_SECURITY_WPA:
+		case CONNMAN_SERVICE_SECURITY_RSN:
+			str = "wps";
+			dbus_message_iter_append_basic(iter,
+						DBUS_TYPE_STRING, &str);
+			break;
+		case CONNMAN_SERVICE_SECURITY_UNKNOWN:
+		case CONNMAN_SERVICE_SECURITY_NONE:
+		case CONNMAN_SERVICE_SECURITY_WEP:
+		case CONNMAN_SERVICE_SECURITY_8021X:
+			break;
+		}
+	}
+}
+
+static void append_ethernet(DBusMessageIter *iter, void *user_data)
+{
+	struct connman_service *service = user_data;
+
+	if (service->ipconfig_ipv4)
+		__connman_ipconfig_append_ethernet(service->ipconfig_ipv4,
+									iter);
+	else if (service->ipconfig_ipv6)
+		__connman_ipconfig_append_ethernet(service->ipconfig_ipv6,
+									iter);
+}
+
+static void append_ipv4(DBusMessageIter *iter, void *user_data)
+{
+	struct connman_service *service = user_data;
+
+	if (!is_connected_state(service, service->state_ipv4))
+		return;
+
+	if (service->ipconfig_ipv4)
+		__connman_ipconfig_append_ipv4(service->ipconfig_ipv4, iter);
+}
+
+static void append_ipv6(DBusMessageIter *iter, void *user_data)
+{
+	struct connman_service *service = user_data;
+
+	if (!is_connected_state(service, service->state_ipv6))
+		return;
+
+	if (service->ipconfig_ipv6)
+		__connman_ipconfig_append_ipv6(service->ipconfig_ipv6, iter,
+						service->ipconfig_ipv4);
+}
+
+static void append_ipv4config(DBusMessageIter *iter, void *user_data)
+{
+	struct connman_service *service = user_data;
+
+	if (service->ipconfig_ipv4)
+		__connman_ipconfig_append_ipv4config(service->ipconfig_ipv4,
+							iter);
+}
+
+static void append_ipv6config(DBusMessageIter *iter, void *user_data)
+{
+	struct connman_service *service = user_data;
+
+	if (service->ipconfig_ipv6)
+		__connman_ipconfig_append_ipv6config(service->ipconfig_ipv6,
+							iter);
+}
+
+static void append_nameservers(DBusMessageIter *iter,
+		struct connman_service *service, char **servers)
+{
+	int i;
+	bool available = true;
+
+	for (i = 0; servers[i]; i++) {
+		if (service)
+			available = nameserver_available(service,
+						CONNMAN_IPCONFIG_TYPE_ALL,
+						servers[i]);
+
+		DBG("servers[%d] %s available %d", i, servers[i], available);
+
+		if (available)
+			dbus_message_iter_append_basic(iter,
+					DBUS_TYPE_STRING, &servers[i]);
+	}
+}
+
+static void append_dns(DBusMessageIter *iter, void *user_data)
+{
+	struct connman_service *service = user_data;
+
+	if (!is_connected(service))
+		return;
+
+	if (service->nameservers_config) {
+		append_nameservers(iter, service, service->nameservers_config);
+		return;
+	} else {
+		if (service->nameservers)
+			append_nameservers(iter, service,
+					service->nameservers);
+
+		if (service->nameservers_auto)
+			append_nameservers(iter, service,
+					service->nameservers_auto);
+
+		if (!service->nameservers && !service->nameservers_auto) {
+			char **ns;
+
+			DBG("append fallback nameservers");
+
+			ns = connman_setting_get_string_list("FallbackNameservers");
+			if (ns)
+				append_nameservers(iter, service, ns);
+		}
+	}
+}
+
+static void append_dnsconfig(DBusMessageIter *iter, void *user_data)
+{
+	struct connman_service *service = user_data;
+
+	if (!service->nameservers_config)
+		return;
+
+	append_nameservers(iter, NULL, service->nameservers_config);
+}
+
+static void append_ts(DBusMessageIter *iter, void *user_data)
+{
+	GSList *list = user_data;
+
+	while (list) {
+		char *timeserver = list->data;
+
+		if (timeserver)
+			dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING,
+					&timeserver);
+
+		list = g_slist_next(list);
+	}
+}
+
+static void append_tsconfig(DBusMessageIter *iter, void *user_data)
+{
+	struct connman_service *service = user_data;
+	int i;
+
+	if (!service->timeservers_config)
+		return;
+
+	for (i = 0; service->timeservers_config[i]; i++) {
+		dbus_message_iter_append_basic(iter,
+				DBUS_TYPE_STRING,
+				&service->timeservers_config[i]);
+	}
+}
+
+static void append_domainconfig(DBusMessageIter *iter, void *user_data)
+{
+	struct connman_service *service = user_data;
+	int i;
+
+	if (!service->domains)
+		return;
+
+	for (i = 0; service->domains[i]; i++)
+		dbus_message_iter_append_basic(iter,
+				DBUS_TYPE_STRING, &service->domains[i]);
+}
+
+static void append_domain(DBusMessageIter *iter, void *user_data)
+{
+	struct connman_service *service = user_data;
+
+	if (!is_connected(service) &&
+				!is_connecting(service))
+		return;
+
+	if (service->domains)
+		append_domainconfig(iter, user_data);
+	else if (service->domainname)
+		dbus_message_iter_append_basic(iter,
+				DBUS_TYPE_STRING, &service->domainname);
+}
+
+static void append_proxies(DBusMessageIter *iter, void *user_data)
+{
+	struct connman_service *service = user_data;
+	int i;
+
+	if (!service->proxies)
+		return;
+
+	for (i = 0; service->proxies[i]; i++)
+		dbus_message_iter_append_basic(iter,
+				DBUS_TYPE_STRING, &service->proxies[i]);
+}
+
+static void append_excludes(DBusMessageIter *iter, void *user_data)
+{
+	struct connman_service *service = user_data;
+	int i;
+
+	if (!service->excludes)
+		return;
+
+	for (i = 0; service->excludes[i]; i++)
+		dbus_message_iter_append_basic(iter,
+				DBUS_TYPE_STRING, &service->excludes[i]);
+}
+
+static void append_proxy(DBusMessageIter *iter, void *user_data)
+{
+	struct connman_service *service = user_data;
+	enum connman_service_proxy_method proxy;
+	const char *pac = NULL;
+	const char *method = proxymethod2string(
+		CONNMAN_SERVICE_PROXY_METHOD_DIRECT);
+
+	if (!is_connected(service))
+		return;
+
+	proxy = connman_service_get_proxy_method(service);
+
+	switch (proxy) {
+	case CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN:
+		return;
+	case CONNMAN_SERVICE_PROXY_METHOD_DIRECT:
+		goto done;
+	case CONNMAN_SERVICE_PROXY_METHOD_MANUAL:
+		connman_dbus_dict_append_array(iter, "Servers",
+					DBUS_TYPE_STRING, append_proxies,
+					service);
+
+		connman_dbus_dict_append_array(iter, "Excludes",
+					DBUS_TYPE_STRING, append_excludes,
+					service);
+		break;
+	case CONNMAN_SERVICE_PROXY_METHOD_AUTO:
+		/* Maybe DHCP, or WPAD,  has provided an url for a pac file */
+		if (service->ipconfig_ipv4)
+			pac = __connman_ipconfig_get_proxy_autoconfig(
+				service->ipconfig_ipv4);
+		else if (service->ipconfig_ipv6)
+			pac = __connman_ipconfig_get_proxy_autoconfig(
+				service->ipconfig_ipv6);
+
+		if (!service->pac && !pac)
+			goto done;
+
+		if (service->pac)
+			pac = service->pac;
+
+		connman_dbus_dict_append_basic(iter, "URL",
+					DBUS_TYPE_STRING, &pac);
+		break;
+	}
+
+	method = proxymethod2string(proxy);
+
+done:
+	connman_dbus_dict_append_basic(iter, "Method",
+					DBUS_TYPE_STRING, &method);
+}
+
+static void append_proxyconfig(DBusMessageIter *iter, void *user_data)
+{
+	struct connman_service *service = user_data;
+	const char *method;
+
+	if (service->proxy_config == CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN)
+		return;
+
+	switch (service->proxy_config) {
+	case CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN:
+		return;
+	case CONNMAN_SERVICE_PROXY_METHOD_DIRECT:
+		break;
+	case CONNMAN_SERVICE_PROXY_METHOD_MANUAL:
+		if (service->proxies)
+			connman_dbus_dict_append_array(iter, "Servers",
+						DBUS_TYPE_STRING,
+						append_proxies, service);
+
+		if (service->excludes)
+			connman_dbus_dict_append_array(iter, "Excludes",
+						DBUS_TYPE_STRING,
+						append_excludes, service);
+		break;
+	case CONNMAN_SERVICE_PROXY_METHOD_AUTO:
+		if (service->pac)
+			connman_dbus_dict_append_basic(iter, "URL",
+					DBUS_TYPE_STRING, &service->pac);
+		break;
+	}
+
+	method = proxymethod2string(service->proxy_config);
+
+	connman_dbus_dict_append_basic(iter, "Method",
+				DBUS_TYPE_STRING, &method);
+}
+
+static void append_provider(DBusMessageIter *iter, void *user_data)
+{
+	struct connman_service *service = user_data;
+
+	if (!is_connected(service))
+		return;
+
+	if (service->provider)
+		__connman_provider_append_properties(service->provider, iter);
+}
+
+
+static void settings_changed(struct connman_service *service,
+				struct connman_ipconfig *ipconfig)
+{
+	enum connman_ipconfig_type type;
+
+	if (!allow_property_changed(service))
+		return;
+
+	type = __connman_ipconfig_get_config_type(ipconfig);
+
+	if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
+		connman_dbus_property_changed_dict(service->path,
+					CONNMAN_SERVICE_INTERFACE, "IPv4",
+					append_ipv4, service);
+	else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
+		connman_dbus_property_changed_dict(service->path,
+					CONNMAN_SERVICE_INTERFACE, "IPv6",
+					append_ipv6, service);
+
+	__connman_notifier_ipconfig_changed(service, ipconfig);
+}
+
+static void ipv4_configuration_changed(struct connman_service *service)
+{
+	if (!allow_property_changed(service))
+		return;
+
+	connman_dbus_property_changed_dict(service->path,
+					CONNMAN_SERVICE_INTERFACE,
+							"IPv4.Configuration",
+							append_ipv4config,
+							service);
+}
+
+static void ipv6_configuration_changed(struct connman_service *service)
+{
+	if (!allow_property_changed(service))
+		return;
+
+	connman_dbus_property_changed_dict(service->path,
+					CONNMAN_SERVICE_INTERFACE,
+							"IPv6.Configuration",
+							append_ipv6config,
+							service);
+}
+
+static void dns_changed(struct connman_service *service)
+{
+	if (!allow_property_changed(service))
+		return;
+
+	connman_dbus_property_changed_array(service->path,
+				CONNMAN_SERVICE_INTERFACE, "Nameservers",
+					DBUS_TYPE_STRING, append_dns, service);
+}
+
+static void dns_configuration_changed(struct connman_service *service)
+{
+	if (!allow_property_changed(service))
+		return;
+
+	connman_dbus_property_changed_array(service->path,
+				CONNMAN_SERVICE_INTERFACE,
+				"Nameservers.Configuration",
+				DBUS_TYPE_STRING, append_dnsconfig, service);
+
+	dns_changed(service);
+}
+
+static void domain_changed(struct connman_service *service)
+{
+	if (!allow_property_changed(service))
+		return;
+
+	connman_dbus_property_changed_array(service->path,
+				CONNMAN_SERVICE_INTERFACE, "Domains",
+				DBUS_TYPE_STRING, append_domain, service);
+}
+
+static void domain_configuration_changed(struct connman_service *service)
+{
+	if (!allow_property_changed(service))
+		return;
+
+	connman_dbus_property_changed_array(service->path,
+				CONNMAN_SERVICE_INTERFACE,
+				"Domains.Configuration",
+				DBUS_TYPE_STRING, append_domainconfig, service);
+}
+
+static void proxy_changed(struct connman_service *service)
+{
+	if (!allow_property_changed(service))
+		return;
+
+	connman_dbus_property_changed_dict(service->path,
+					CONNMAN_SERVICE_INTERFACE, "Proxy",
+							append_proxy, service);
+}
+
+static void proxy_configuration_changed(struct connman_service *service)
+{
+	if (!allow_property_changed(service))
+		return;
+
+	connman_dbus_property_changed_dict(service->path,
+			CONNMAN_SERVICE_INTERFACE, "Proxy.Configuration",
+						append_proxyconfig, service);
+
+	proxy_changed(service);
+}
+
+static void timeservers_configuration_changed(struct connman_service *service)
+{
+	if (!allow_property_changed(service))
+		return;
+
+	connman_dbus_property_changed_array(service->path,
+			CONNMAN_SERVICE_INTERFACE,
+			"Timeservers.Configuration",
+			DBUS_TYPE_STRING,
+			append_tsconfig, service);
+}
+
+static void link_changed(struct connman_service *service)
+{
+	if (!allow_property_changed(service))
+		return;
+
+	connman_dbus_property_changed_dict(service->path,
+					CONNMAN_SERVICE_INTERFACE, "Ethernet",
+						append_ethernet, service);
+}
+
+static void stats_append_counters(DBusMessageIter *dict,
+			struct connman_stats_data *stats,
+			struct connman_stats_data *counters,
+			bool append_all)
+{
+	if (counters->rx_packets != stats->rx_packets || append_all) {
+		counters->rx_packets = stats->rx_packets;
+		connman_dbus_dict_append_basic(dict, "RX.Packets",
+					DBUS_TYPE_UINT32, &stats->rx_packets);
+	}
+
+	if (counters->tx_packets != stats->tx_packets || append_all) {
+		counters->tx_packets = stats->tx_packets;
+		connman_dbus_dict_append_basic(dict, "TX.Packets",
+					DBUS_TYPE_UINT32, &stats->tx_packets);
+	}
+
+	if (counters->rx_bytes != stats->rx_bytes || append_all) {
+		counters->rx_bytes = stats->rx_bytes;
+		connman_dbus_dict_append_basic(dict, "RX.Bytes",
+					DBUS_TYPE_UINT32, &stats->rx_bytes);
+	}
+
+	if (counters->tx_bytes != stats->tx_bytes || append_all) {
+		counters->tx_bytes = stats->tx_bytes;
+		connman_dbus_dict_append_basic(dict, "TX.Bytes",
+					DBUS_TYPE_UINT32, &stats->tx_bytes);
+	}
+
+	if (counters->rx_errors != stats->rx_errors || append_all) {
+		counters->rx_errors = stats->rx_errors;
+		connman_dbus_dict_append_basic(dict, "RX.Errors",
+					DBUS_TYPE_UINT32, &stats->rx_errors);
+	}
+
+	if (counters->tx_errors != stats->tx_errors || append_all) {
+		counters->tx_errors = stats->tx_errors;
+		connman_dbus_dict_append_basic(dict, "TX.Errors",
+					DBUS_TYPE_UINT32, &stats->tx_errors);
+	}
+
+	if (counters->rx_dropped != stats->rx_dropped || append_all) {
+		counters->rx_dropped = stats->rx_dropped;
+		connman_dbus_dict_append_basic(dict, "RX.Dropped",
+					DBUS_TYPE_UINT32, &stats->rx_dropped);
+	}
+
+	if (counters->tx_dropped != stats->tx_dropped || append_all) {
+		counters->tx_dropped = stats->tx_dropped;
+		connman_dbus_dict_append_basic(dict, "TX.Dropped",
+					DBUS_TYPE_UINT32, &stats->tx_dropped);
+	}
+
+	if (counters->time != stats->time || append_all) {
+		counters->time = stats->time;
+		connman_dbus_dict_append_basic(dict, "Time",
+					DBUS_TYPE_UINT32, &stats->time);
+	}
+}
+
+static void stats_append(struct connman_service *service,
+				const char *counter,
+				struct connman_stats_counter *counters,
+				bool append_all)
+{
+	DBusMessageIter array, dict;
+	DBusMessage *msg;
+
+	DBG("service %p counter %s", service, counter);
+
+	msg = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_CALL);
+	if (!msg)
+		return;
+
+	dbus_message_append_args(msg, DBUS_TYPE_OBJECT_PATH,
+				&service->path, DBUS_TYPE_INVALID);
+
+	dbus_message_iter_init_append(msg, &array);
+
+	/* home counter */
+	connman_dbus_dict_open(&array, &dict);
+
+	stats_append_counters(&dict, &service->stats.data,
+				&counters->stats.data, append_all);
+
+	connman_dbus_dict_close(&array, &dict);
+
+	/* roaming counter */
+	connman_dbus_dict_open(&array, &dict);
+
+	stats_append_counters(&dict, &service->stats_roaming.data,
+				&counters->stats_roaming.data, append_all);
+
+	connman_dbus_dict_close(&array, &dict);
+
+	__connman_counter_send_usage(counter, msg);
+}
+
+static void stats_update(struct connman_service *service,
+				unsigned int rx_packets, unsigned int tx_packets,
+				unsigned int rx_bytes, unsigned int tx_bytes,
+				unsigned int rx_errors, unsigned int tx_errors,
+				unsigned int rx_dropped, unsigned int tx_dropped)
+{
+	struct connman_stats *stats = stats_get(service);
+	struct connman_stats_data *data_last = &stats->data_last;
+	struct connman_stats_data *data = &stats->data;
+	unsigned int seconds;
+
+	DBG("service %p", service);
+
+	if (stats->valid) {
+		data->rx_packets +=
+			rx_packets - data_last->rx_packets;
+		data->tx_packets +=
+			tx_packets - data_last->tx_packets;
+		data->rx_bytes +=
+			rx_bytes - data_last->rx_bytes;
+		data->tx_bytes +=
+			tx_bytes - data_last->tx_bytes;
+		data->rx_errors +=
+			rx_errors - data_last->rx_errors;
+		data->tx_errors +=
+			tx_errors - data_last->tx_errors;
+		data->rx_dropped +=
+			rx_dropped - data_last->rx_dropped;
+		data->tx_dropped +=
+			tx_dropped - data_last->tx_dropped;
+	} else {
+		stats->valid = true;
+	}
+
+	data_last->rx_packets = rx_packets;
+	data_last->tx_packets = tx_packets;
+	data_last->rx_bytes = rx_bytes;
+	data_last->tx_bytes = tx_bytes;
+	data_last->rx_errors = rx_errors;
+	data_last->tx_errors = tx_errors;
+	data_last->rx_dropped = rx_dropped;
+	data_last->tx_dropped = tx_dropped;
+
+	seconds = g_timer_elapsed(stats->timer, NULL);
+	stats->data.time = stats->data_last.time + seconds;
+}
+
+void __connman_service_notify(struct connman_service *service,
+			unsigned int rx_packets, unsigned int tx_packets,
+			unsigned int rx_bytes, unsigned int tx_bytes,
+			unsigned int rx_errors, unsigned int tx_errors,
+			unsigned int rx_dropped, unsigned int tx_dropped)
+{
+	GHashTableIter iter;
+	gpointer key, value;
+	const char *counter;
+	struct connman_stats_counter *counters;
+	struct connman_stats_data *data;
+	int err;
+
+	if (!service)
+		return;
+
+	if (!is_connected(service))
+		return;
+
+	stats_update(service,
+		rx_packets, tx_packets,
+		rx_bytes, tx_bytes,
+		rx_errors, tx_errors,
+		rx_dropped, tx_dropped);
+
+	data = &stats_get(service)->data;
+	err = __connman_stats_update(service, service->roaming, data);
+	if (err < 0)
+		connman_error("Failed to store statistics for %s",
+				service->identifier);
+
+	g_hash_table_iter_init(&iter, service->counter_table);
+	while (g_hash_table_iter_next(&iter, &key, &value)) {
+		counter = key;
+		counters = value;
+
+		stats_append(service, counter, counters, counters->append_all);
+		counters->append_all = false;
+	}
+}
+
+int __connman_service_counter_register(const char *counter)
+{
+	struct connman_service *service;
+	GList *list;
+	struct connman_stats_counter *counters;
+
+	DBG("counter %s", counter);
+
+	counter_list = g_slist_prepend(counter_list, (gpointer)counter);
+
+	for (list = service_list; list; list = list->next) {
+		service = list->data;
+
+		counters = g_try_new0(struct connman_stats_counter, 1);
+		if (!counters)
+			return -ENOMEM;
+
+		counters->append_all = true;
+
+		g_hash_table_replace(service->counter_table, (gpointer)counter,
+					counters);
+	}
+
+	return 0;
+}
+
+void __connman_service_counter_unregister(const char *counter)
+{
+	struct connman_service *service;
+	GList *list;
+
+	DBG("counter %s", counter);
+
+	for (list = service_list; list; list = list->next) {
+		service = list->data;
+
+		g_hash_table_remove(service->counter_table, counter);
+	}
+
+	counter_list = g_slist_remove(counter_list, counter);
+}
+
+int __connman_service_iterate_services(service_iterate_cb cb, void *user_data)
+{
+	GList *list;
+
+	for (list = service_list; list; list = list->next) {
+		struct connman_service *service = list->data;
+
+		cb(service, user_data);
+	}
+
+	return 0;
+}
+
+static void append_properties(DBusMessageIter *dict, dbus_bool_t limited,
+					struct connman_service *service)
+{
+	dbus_bool_t val;
+	const char *str;
+	GSList *list;
+
+	str = __connman_service_type2string(service->type);
+	if (str)
+		connman_dbus_dict_append_basic(dict, "Type",
+						DBUS_TYPE_STRING, &str);
+
+	connman_dbus_dict_append_array(dict, "Security",
+				DBUS_TYPE_STRING, append_security, service);
+
+	// TODO: This is a temporary hack to support fetching the passphrase
+	// from lowpan networks!
+
+	// Long term, I’d rather have a way for a ConnMan client to be able to
+	// explicitly query authentication credentials for a service instead of always
+	// providing them with the service dictionary. My reasoning is that since
+	// the dictionary has never had sensitive information in it before that
+	// there might be code that is using it in a way that would not be
+	// appropriate for network security credentials. More about hardening
+	// than anything else.
+
+	if ((service->type == CONNMAN_SERVICE_TYPE_LOWPAN || service->type == CONNMAN_SERVICE_TYPE_WIFI)
+		&& (service->passphrase != NULL))
+		connman_dbus_dict_append_basic(dict, "Passphrase",
+					DBUS_TYPE_STRING, &service->passphrase);
+
+	str = state2string(service->state);
+	if (str)
+		connman_dbus_dict_append_basic(dict, "State",
+						DBUS_TYPE_STRING, &str);
+
+	str = error2string(service->error);
+	if (str)
+		connman_dbus_dict_append_basic(dict, "Error",
+						DBUS_TYPE_STRING, &str);
+
+	if (service->strength > 0)
+		connman_dbus_dict_append_basic(dict, "Strength",
+					DBUS_TYPE_BYTE, &service->strength);
+
+	val = service->favorite;
+	connman_dbus_dict_append_basic(dict, "Favorite",
+					DBUS_TYPE_BOOLEAN, &val);
+
+	val = service->immutable;
+	connman_dbus_dict_append_basic(dict, "Immutable",
+					DBUS_TYPE_BOOLEAN, &val);
+
+	if (service->favorite)
+		val = service->autoconnect;
+	else
+		val = service->favorite;
+
+	connman_dbus_dict_append_basic(dict, "AutoConnect",
+				DBUS_TYPE_BOOLEAN, &val);
+
+	if (service->name)
+		connman_dbus_dict_append_basic(dict, "Name",
+					DBUS_TYPE_STRING, &service->name);
+
+	switch (service->type) {
+	case CONNMAN_SERVICE_TYPE_UNKNOWN:
+	case CONNMAN_SERVICE_TYPE_SYSTEM:
+	case CONNMAN_SERVICE_TYPE_GPS:
+	case CONNMAN_SERVICE_TYPE_VPN:
+	case CONNMAN_SERVICE_TYPE_P2P:
+		break;
+	case CONNMAN_SERVICE_TYPE_CELLULAR:
+		val = service->roaming;
+		connman_dbus_dict_append_basic(dict, "Roaming",
+					DBUS_TYPE_BOOLEAN, &val);
+
+		connman_dbus_dict_append_dict(dict, "Ethernet",
+						append_ethernet, service);
+		break;
+	case CONNMAN_SERVICE_TYPE_WIFI:
+	case CONNMAN_SERVICE_TYPE_LOWPAN:
+	case CONNMAN_SERVICE_TYPE_ETHERNET:
+	case CONNMAN_SERVICE_TYPE_BLUETOOTH:
+	case CONNMAN_SERVICE_TYPE_GADGET:
+		connman_dbus_dict_append_dict(dict, "Ethernet",
+						append_ethernet, service);
+		break;
+	}
+
+	connman_dbus_dict_append_dict(dict, "IPv4", append_ipv4, service);
+
+	connman_dbus_dict_append_dict(dict, "IPv4.Configuration",
+						append_ipv4config, service);
+
+	connman_dbus_dict_append_dict(dict, "IPv6", append_ipv6, service);
+
+	connman_dbus_dict_append_dict(dict, "IPv6.Configuration",
+						append_ipv6config, service);
+
+	connman_dbus_dict_append_array(dict, "Nameservers",
+				DBUS_TYPE_STRING, append_dns, service);
+
+	connman_dbus_dict_append_array(dict, "Nameservers.Configuration",
+				DBUS_TYPE_STRING, append_dnsconfig, service);
+
+	if (service->state == CONNMAN_SERVICE_STATE_READY ||
+			service->state == CONNMAN_SERVICE_STATE_ONLINE)
+		list = __connman_timeserver_get_all(service);
+	else
+		list = NULL;
+
+	connman_dbus_dict_append_array(dict, "Timeservers",
+				DBUS_TYPE_STRING, append_ts, list);
+
+	g_slist_free_full(list, g_free);
+
+	connman_dbus_dict_append_array(dict, "Timeservers.Configuration",
+				DBUS_TYPE_STRING, append_tsconfig, service);
+
+	connman_dbus_dict_append_array(dict, "Domains",
+				DBUS_TYPE_STRING, append_domain, service);
+
+	connman_dbus_dict_append_array(dict, "Domains.Configuration",
+				DBUS_TYPE_STRING, append_domainconfig, service);
+
+	connman_dbus_dict_append_dict(dict, "Proxy", append_proxy, service);
+
+	connman_dbus_dict_append_dict(dict, "Proxy.Configuration",
+						append_proxyconfig, service);
+
+	connman_dbus_dict_append_dict(dict, "Provider",
+						append_provider, service);
+}
+
+static void append_struct_service(DBusMessageIter *iter,
+		connman_dbus_append_cb_t function,
+		struct connman_service *service)
+{
+	DBusMessageIter entry, dict;
+
+	dbus_message_iter_open_container(iter, DBUS_TYPE_STRUCT, NULL, &entry);
+
+	dbus_message_iter_append_basic(&entry, DBUS_TYPE_OBJECT_PATH,
+							&service->path);
+
+	connman_dbus_dict_open(&entry, &dict);
+	if (function)
+		function(&dict, service);
+	connman_dbus_dict_close(&entry, &dict);
+
+	dbus_message_iter_close_container(iter, &entry);
+}
+
+static void append_dict_properties(DBusMessageIter *dict, void *user_data)
+{
+	struct connman_service *service = user_data;
+
+	append_properties(dict, TRUE, service);
+}
+
+static void append_struct(gpointer value, gpointer user_data)
+{
+	struct connman_service *service = value;
+	DBusMessageIter *iter = user_data;
+
+	if (!service->path)
+		return;
+
+	append_struct_service(iter, append_dict_properties, service);
+}
+
+void __connman_service_list_struct(DBusMessageIter *iter)
+{
+	g_list_foreach(service_list, append_struct, iter);
+}
+
+bool __connman_service_is_hidden(struct connman_service *service)
+{
+	return service->hidden;
+}
+
+bool
+__connman_service_is_split_routing(struct connman_service *service)
+{
+	return service->do_split_routing;
+}
+
+bool __connman_service_index_is_split_routing(int index)
+{
+	struct connman_service *service;
+
+	if (index < 0)
+		return false;
+
+	service = __connman_service_lookup_from_index(index);
+	if (!service)
+		return false;
+
+	return __connman_service_is_split_routing(service);
+}
+
+int __connman_service_get_index(struct connman_service *service)
+{
+	if (!service)
+		return -1;
+
+	if (service->network)
+		return connman_network_get_index(service->network);
+	else if (service->provider)
+		return connman_provider_get_index(service->provider);
+
+	return -1;
+}
+
+void __connman_service_set_hidden(struct connman_service *service)
+{
+	if (!service || service->hidden)
+		return;
+
+	service->hidden_service = true;
+}
+
+void __connman_service_set_hostname(struct connman_service *service,
+						const char *hostname)
+{
+	if (!service || service->hidden)
+		return;
+
+	g_free(service->hostname);
+	service->hostname = g_strdup(hostname);
+}
+
+const char *__connman_service_get_hostname(struct connman_service *service)
+{
+	if (!service)
+		return NULL;
+
+	return service->hostname;
+}
+
+void __connman_service_set_domainname(struct connman_service *service,
+						const char *domainname)
+{
+	if (!service || service->hidden)
+		return;
+
+	g_free(service->domainname);
+	service->domainname = g_strdup(domainname);
+
+	domain_changed(service);
+}
+
+const char *connman_service_get_domainname(struct connman_service *service)
+{
+	if (!service)
+		return NULL;
+
+	if (service->domains)
+		return service->domains[0];
+	else
+		return service->domainname;
+}
+
+char **connman_service_get_nameservers(struct connman_service *service)
+{
+	if (!service)
+		return NULL;
+
+	if (service->nameservers_config)
+		return g_strdupv(service->nameservers_config);
+	else if (service->nameservers ||
+					service->nameservers_auto) {
+		int len = 0, len_auto = 0, i;
+		char **nameservers;
+
+		if (service->nameservers)
+			len = g_strv_length(service->nameservers);
+		if (service->nameservers_auto)
+			len_auto = g_strv_length(service->nameservers_auto);
+
+		nameservers = g_try_new0(char *, len + len_auto + 1);
+		if (!nameservers)
+			return NULL;
+
+		for (i = 0; i < len; i++)
+			nameservers[i] = g_strdup(service->nameservers[i]);
+
+		for (i = 0; i < len_auto; i++)
+			nameservers[i + len] =
+				g_strdup(service->nameservers_auto[i]);
+
+		return nameservers;
+	}
+
+	return g_strdupv(connman_setting_get_string_list("FallbackNameservers"));
+}
+
+char **connman_service_get_timeservers_config(struct connman_service *service)
+{
+	if (!service)
+		return NULL;
+
+	return service->timeservers_config;
+}
+
+char **connman_service_get_timeservers(struct connman_service *service)
+{
+	if (!service)
+		return NULL;
+
+	return service->timeservers;
+}
+
+void connman_service_set_proxy_method(struct connman_service *service,
+					enum connman_service_proxy_method method)
+{
+	if (!service || service->hidden)
+		return;
+
+	service->proxy = method;
+
+	proxy_changed(service);
+
+	if (method != CONNMAN_SERVICE_PROXY_METHOD_AUTO)
+		__connman_notifier_proxy_changed(service);
+}
+
+enum connman_service_proxy_method connman_service_get_proxy_method(
+					struct connman_service *service)
+{
+	if (!service)
+		return CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN;
+
+	if (service->proxy_config != CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN) {
+		if (service->proxy_config == CONNMAN_SERVICE_PROXY_METHOD_AUTO &&
+				!service->pac)
+			return service->proxy;
+
+		return service->proxy_config;
+	}
+
+	return service->proxy;
+}
+
+char **connman_service_get_proxy_servers(struct connman_service *service)
+{
+	return g_strdupv(service->proxies);
+}
+
+char **connman_service_get_proxy_excludes(struct connman_service *service)
+{
+	return g_strdupv(service->excludes);
+}
+
+const char *connman_service_get_proxy_url(struct connman_service *service)
+{
+	if (!service)
+		return NULL;
+
+	return service->pac;
+}
+
+void __connman_service_set_proxy_autoconfig(struct connman_service *service,
+							const char *url)
+{
+	if (!service || service->hidden)
+		return;
+
+	service->proxy = CONNMAN_SERVICE_PROXY_METHOD_AUTO;
+
+	if (service->ipconfig_ipv4) {
+		if (__connman_ipconfig_set_proxy_autoconfig(
+			    service->ipconfig_ipv4, url) < 0)
+			return;
+	} else if (service->ipconfig_ipv6) {
+		if (__connman_ipconfig_set_proxy_autoconfig(
+			    service->ipconfig_ipv6, url) < 0)
+			return;
+	} else
+		return;
+
+	proxy_changed(service);
+
+	__connman_notifier_proxy_changed(service);
+}
+
+const char *connman_service_get_proxy_autoconfig(struct connman_service *service)
+{
+	if (!service)
+		return NULL;
+
+	if (service->ipconfig_ipv4)
+		return __connman_ipconfig_get_proxy_autoconfig(
+						service->ipconfig_ipv4);
+	else if (service->ipconfig_ipv6)
+		return __connman_ipconfig_get_proxy_autoconfig(
+						service->ipconfig_ipv6);
+	return NULL;
+}
+
+void __connman_service_set_timeservers(struct connman_service *service,
+				char **timeservers)
+{
+	int i;
+
+	if (!service)
+		return;
+
+	g_strfreev(service->timeservers);
+	service->timeservers = NULL;
+
+	for (i = 0; timeservers && timeservers[i]; i++)
+		__connman_service_timeserver_append(service, timeservers[i]);
+}
+
+int __connman_service_timeserver_append(struct connman_service *service,
+						const char *timeserver)
+{
+	int len;
+
+	DBG("service %p timeserver %s", service, timeserver);
+
+	if (!timeserver)
+		return -EINVAL;
+
+	if (service->timeservers) {
+		int i;
+
+		for (i = 0; service->timeservers[i]; i++)
+			if (g_strcmp0(service->timeservers[i], timeserver) == 0)
+				return -EEXIST;
+
+		len = g_strv_length(service->timeservers);
+		service->timeservers = g_try_renew(char *, service->timeservers,
+							len + 2);
+	} else {
+		len = 0;
+		service->timeservers = g_try_new0(char *, len + 2);
+	}
+
+	if (!service->timeservers)
+		return -ENOMEM;
+
+	service->timeservers[len] = g_strdup(timeserver);
+	service->timeservers[len + 1] = NULL;
+
+	return 0;
+}
+
+int __connman_service_timeserver_remove(struct connman_service *service,
+						const char *timeserver)
+{
+	char **servers;
+	int len, i, j, found = 0;
+
+	DBG("service %p timeserver %s", service, timeserver);
+
+	if (!timeserver)
+		return -EINVAL;
+
+	if (!service->timeservers)
+		return 0;
+
+	for (i = 0; service->timeservers &&
+					service->timeservers[i]; i++)
+		if (g_strcmp0(service->timeservers[i], timeserver) == 0) {
+			found = 1;
+			break;
+		}
+
+	if (found == 0)
+		return 0;
+
+	len = g_strv_length(service->timeservers);
+
+	if (len == 1) {
+		g_strfreev(service->timeservers);
+		service->timeservers = NULL;
+
+		return 0;
+	}
+
+	servers = g_try_new0(char *, len);
+	if (!servers)
+		return -ENOMEM;
+
+	for (i = 0, j = 0; i < len; i++) {
+		if (g_strcmp0(service->timeservers[i], timeserver) != 0) {
+			servers[j] = g_strdup(service->timeservers[i]);
+			if (!servers[j])
+				return -ENOMEM;
+			j++;
+		}
+	}
+	servers[len - 1] = NULL;
+
+	g_strfreev(service->timeservers);
+	service->timeservers = servers;
+
+	return 0;
+}
+
+void __connman_service_timeserver_changed(struct connman_service *service,
+		GSList *ts_list)
+{
+	if (!service)
+		return;
+
+	if (!allow_property_changed(service))
+		return;
+
+	connman_dbus_property_changed_array(service->path,
+			CONNMAN_SERVICE_INTERFACE, "Timeservers",
+			DBUS_TYPE_STRING, append_ts, ts_list);
+}
+
+void __connman_service_set_pac(struct connman_service *service,
+					const char *pac)
+{
+	if (service->hidden)
+		return;
+	g_free(service->pac);
+	service->pac = g_strdup(pac);
+
+	proxy_changed(service);
+}
+
+void __connman_service_set_identity(struct connman_service *service,
+					const char *identity)
+{
+	if (service->immutable || service->hidden)
+		return;
+
+	g_free(service->identity);
+	service->identity = g_strdup(identity);
+
+	if (service->network)
+		connman_network_set_string(service->network,
+					"WiFi.Identity",
+					service->identity);
+}
+
+void __connman_service_set_agent_identity(struct connman_service *service,
+						const char *agent_identity)
+{
+	if (service->hidden)
+		return;
+	g_free(service->agent_identity);
+	service->agent_identity = g_strdup(agent_identity);
+
+	if (service->network)
+		connman_network_set_string(service->network,
+					"WiFi.AgentIdentity",
+					service->agent_identity);
+}
+
+static int check_passphrase(enum connman_service_security security,
+		const char *passphrase)
+{
+	guint i;
+	gsize length;
+
+	if (!passphrase)
+		return 0;
+
+	length = strlen(passphrase);
+
+	switch (security) {
+	case CONNMAN_SERVICE_SECURITY_UNKNOWN:
+	case CONNMAN_SERVICE_SECURITY_NONE:
+	case CONNMAN_SERVICE_SECURITY_WPA:
+	case CONNMAN_SERVICE_SECURITY_RSN:
+
+		DBG("service security '%s' (%d) not handled",
+				security2string(security), security);
+
+		return -EOPNOTSUPP;
+
+	case CONNMAN_SERVICE_SECURITY_PSK:
+		/* A raw key is always 64 bytes length,
+		 * its content is in hex representation.
+		 * A PSK key must be between [8..63].
+		 */
+		if (length == 64) {
+			for (i = 0; i < 64; i++)
+				if (!isxdigit((unsigned char)
+					      passphrase[i]))
+					return -ENOKEY;
+		} else if (length < 8 || length > 63)
+			return -ENOKEY;
+		break;
+	case CONNMAN_SERVICE_SECURITY_WEP:
+		/* length of WEP key is 10 or 26
+		 * length of WEP passphrase is 5 or 13
+		 */
+		if (length == 10 || length == 26) {
+			for (i = 0; i < length; i++)
+				if (!isxdigit((unsigned char)
+					      passphrase[i]))
+					return -ENOKEY;
+		} else if (length != 5 && length != 13)
+			return -ENOKEY;
+		break;
+
+	case CONNMAN_SERVICE_SECURITY_8021X:
+		break;
+	}
+
+	return 0;
+}
+
+int __connman_service_set_passphrase(struct connman_service *service,
+					const char *passphrase)
+{
+	int err;
+
+	if (service->hidden)
+		return -EINVAL;
+
+	if (service->immutable &&
+			service->security != CONNMAN_SERVICE_SECURITY_8021X)
+		return -EINVAL;
+
+	err = check_passphrase(service->security, passphrase);
+
+	if (err < 0)
+		return err;
+
+	g_free(service->passphrase);
+	service->passphrase = g_strdup(passphrase);
+
+	if (service->network)
+		connman_network_set_string(service->network, "WiFi.Passphrase",
+				service->passphrase);
+
+	return 0;
+}
+
+const char *__connman_service_get_passphrase(struct connman_service *service)
+{
+	if (!service)
+		return NULL;
+
+	return service->passphrase;
+}
+
+static DBusMessage *get_properties(DBusConnection *conn,
+					DBusMessage *msg, void *user_data)
+{
+	struct connman_service *service = user_data;
+	DBusMessage *reply;
+	DBusMessageIter array, dict;
+
+	DBG("service %p", service);
+
+	reply = dbus_message_new_method_return(msg);
+	if (!reply)
+		return NULL;
+
+	dbus_message_iter_init_append(reply, &array);
+
+	connman_dbus_dict_open(&array, &dict);
+	append_properties(&dict, FALSE, service);
+	connman_dbus_dict_close(&array, &dict);
+
+	return reply;
+}
+
+static int update_proxy_configuration(struct connman_service *service,
+				DBusMessageIter *array)
+{
+	DBusMessageIter dict;
+	enum connman_service_proxy_method method;
+	GString *servers_str = NULL;
+	GString *excludes_str = NULL;
+	const char *url = NULL;
+
+	method = CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN;
+
+	dbus_message_iter_recurse(array, &dict);
+
+	while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
+		DBusMessageIter entry, variant;
+		const char *key;
+		int type;
+
+		dbus_message_iter_recurse(&dict, &entry);
+
+		if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING)
+			goto error;
+
+		dbus_message_iter_get_basic(&entry, &key);
+		dbus_message_iter_next(&entry);
+
+		if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_VARIANT)
+			goto error;
+
+		dbus_message_iter_recurse(&entry, &variant);
+
+		type = dbus_message_iter_get_arg_type(&variant);
+
+		if (g_str_equal(key, "Method")) {
+			const char *val;
+
+			if (type != DBUS_TYPE_STRING)
+				goto error;
+
+			dbus_message_iter_get_basic(&variant, &val);
+			method = string2proxymethod(val);
+		} else if (g_str_equal(key, "URL")) {
+			if (type != DBUS_TYPE_STRING)
+				goto error;
+
+			dbus_message_iter_get_basic(&variant, &url);
+		} else if (g_str_equal(key, "Servers")) {
+			DBusMessageIter str_array;
+
+			if (type != DBUS_TYPE_ARRAY)
+				goto error;
+
+			servers_str = g_string_new(NULL);
+			if (!servers_str)
+				goto error;
+
+			dbus_message_iter_recurse(&variant, &str_array);
+
+			while (dbus_message_iter_get_arg_type(&str_array) ==
+							DBUS_TYPE_STRING) {
+				char *val = NULL;
+
+				dbus_message_iter_get_basic(&str_array, &val);
+
+				if (servers_str->len > 0)
+					g_string_append_printf(servers_str,
+							" %s", val);
+				else
+					g_string_append(servers_str, val);
+
+				dbus_message_iter_next(&str_array);
+			}
+		} else if (g_str_equal(key, "Excludes")) {
+			DBusMessageIter str_array;
+
+			if (type != DBUS_TYPE_ARRAY)
+				goto error;
+
+			excludes_str = g_string_new(NULL);
+			if (!excludes_str)
+				goto error;
+
+			dbus_message_iter_recurse(&variant, &str_array);
+
+			while (dbus_message_iter_get_arg_type(&str_array) ==
+							DBUS_TYPE_STRING) {
+				char *val = NULL;
+
+				dbus_message_iter_get_basic(&str_array, &val);
+
+				if (excludes_str->len > 0)
+					g_string_append_printf(excludes_str,
+							" %s", val);
+				else
+					g_string_append(excludes_str, val);
+
+				dbus_message_iter_next(&str_array);
+			}
+		}
+
+		dbus_message_iter_next(&dict);
+	}
+
+	switch (method) {
+	case CONNMAN_SERVICE_PROXY_METHOD_DIRECT:
+		break;
+	case CONNMAN_SERVICE_PROXY_METHOD_MANUAL:
+		if (!servers_str && !service->proxies)
+			goto error;
+
+		if (servers_str) {
+			g_strfreev(service->proxies);
+
+			if (servers_str->len > 0)
+				service->proxies = g_strsplit_set(
+					servers_str->str, " ", 0);
+			else
+				service->proxies = NULL;
+		}
+
+		if (excludes_str) {
+			g_strfreev(service->excludes);
+
+			if (excludes_str->len > 0)
+				service->excludes = g_strsplit_set(
+					excludes_str->str, " ", 0);
+			else
+				service->excludes = NULL;
+		}
+
+		if (!service->proxies)
+			method = CONNMAN_SERVICE_PROXY_METHOD_DIRECT;
+
+		break;
+	case CONNMAN_SERVICE_PROXY_METHOD_AUTO:
+		g_free(service->pac);
+
+		if (url && strlen(url) > 0)
+			service->pac = g_strdup(url);
+		else
+			service->pac = NULL;
+
+		/* if we are connected:
+		   - if service->pac == NULL
+		   - if __connman_ipconfig_get_proxy_autoconfig(
+		   service->ipconfig) == NULL
+		   --> We should start WPAD */
+
+		break;
+	case CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN:
+		goto error;
+	}
+
+	if (servers_str)
+		g_string_free(servers_str, TRUE);
+
+	if (excludes_str)
+		g_string_free(excludes_str, TRUE);
+
+	service->proxy_config = method;
+
+	return 0;
+
+error:
+	if (servers_str)
+		g_string_free(servers_str, TRUE);
+
+	if (excludes_str)
+		g_string_free(excludes_str, TRUE);
+
+	return -EINVAL;
+}
+
+int __connman_service_reset_ipconfig(struct connman_service *service,
+		enum connman_ipconfig_type type, DBusMessageIter *array,
+		enum connman_service_state *new_state)
+{
+	struct connman_ipconfig *ipconfig, *new_ipconfig;
+	enum connman_ipconfig_method old_method, new_method;
+	enum connman_service_state state;
+	int err = 0, index;
+
+	if (type == CONNMAN_IPCONFIG_TYPE_IPV4) {
+		ipconfig = service->ipconfig_ipv4;
+		state = service->state_ipv4;
+		new_method = CONNMAN_IPCONFIG_METHOD_DHCP;
+	} else if (type == CONNMAN_IPCONFIG_TYPE_IPV6) {
+		ipconfig = service->ipconfig_ipv6;
+		state = service->state_ipv6;
+		new_method = CONNMAN_IPCONFIG_METHOD_AUTO;
+	} else
+		return -EINVAL;
+
+	if (!ipconfig)
+		return -ENXIO;
+
+	old_method = __connman_ipconfig_get_method(ipconfig);
+	index = __connman_ipconfig_get_index(ipconfig);
+
+	if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
+		new_ipconfig = create_ip4config(service, index,
+				CONNMAN_IPCONFIG_METHOD_UNKNOWN);
+	else
+		new_ipconfig = create_ip6config(service, index);
+
+	if (array) {
+		err = __connman_ipconfig_set_config(new_ipconfig, array);
+		if (err < 0) {
+			__connman_ipconfig_unref(new_ipconfig);
+			return err;
+		}
+
+		new_method = __connman_ipconfig_get_method(new_ipconfig);
+	}
+
+	if (is_connecting_state(service, state) ||
+					is_connected_state(service, state))
+		__connman_network_clear_ipconfig(service->network, ipconfig);
+
+	__connman_ipconfig_unref(ipconfig);
+
+	if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
+		service->ipconfig_ipv4 = new_ipconfig;
+	else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
+		service->ipconfig_ipv6 = new_ipconfig;
+
+	if (is_connecting_state(service, state) ||
+					is_connected_state(service, state))
+		__connman_ipconfig_enable(new_ipconfig);
+
+	if (new_state && new_method != old_method) {
+		if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
+			*new_state = service->state_ipv4;
+		else
+			*new_state = service->state_ipv6;
+
+		__connman_service_auto_connect(CONNMAN_SERVICE_CONNECT_REASON_AUTO);
+	}
+
+	DBG("err %d ipconfig %p type %d method %d state %s", err,
+		new_ipconfig, type, new_method,
+		!new_state  ? "-" : state2string(*new_state));
+
+	return err;
+}
+
+static DBusMessage *set_property(DBusConnection *conn,
+					DBusMessage *msg, void *user_data)
+{
+	struct connman_service *service = user_data;
+	DBusMessageIter iter, value;
+	const char *name;
+	int type;
+
+	DBG("service %p", service);
+
+	if (!dbus_message_iter_init(msg, &iter))
+		return __connman_error_invalid_arguments(msg);
+
+	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
+		return __connman_error_invalid_arguments(msg);
+
+	dbus_message_iter_get_basic(&iter, &name);
+	dbus_message_iter_next(&iter);
+
+	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT)
+		return __connman_error_invalid_arguments(msg);
+
+	dbus_message_iter_recurse(&iter, &value);
+
+	type = dbus_message_iter_get_arg_type(&value);
+
+	if (g_str_equal(name, "AutoConnect")) {
+		dbus_bool_t autoconnect;
+
+		if (type != DBUS_TYPE_BOOLEAN)
+			return __connman_error_invalid_arguments(msg);
+
+		if (!service->favorite)
+			return __connman_error_invalid_service(msg);
+
+		dbus_message_iter_get_basic(&value, &autoconnect);
+
+		if (service->autoconnect == autoconnect)
+			return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+
+		service->autoconnect = autoconnect;
+
+		autoconnect_changed(service);
+
+		if (autoconnect)
+			__connman_service_auto_connect(CONNMAN_SERVICE_CONNECT_REASON_AUTO);
+
+		service_save(service);
+	} else if (g_str_equal(name, "Nameservers.Configuration")) {
+		DBusMessageIter entry;
+		GString *str;
+		int index;
+		const char *gw;
+
+		if (__connman_provider_is_immutable(service->provider) ||
+				service->immutable)
+			return __connman_error_not_supported(msg);
+
+		if (type != DBUS_TYPE_ARRAY)
+			return __connman_error_invalid_arguments(msg);
+
+		str = g_string_new(NULL);
+		if (!str)
+			return __connman_error_invalid_arguments(msg);
+
+		index = __connman_service_get_index(service);
+		gw = __connman_ipconfig_get_gateway_from_index(index,
+			CONNMAN_IPCONFIG_TYPE_ALL);
+
+		if (gw && strlen(gw))
+			__connman_service_nameserver_del_routes(service,
+						CONNMAN_IPCONFIG_TYPE_ALL);
+
+		dbus_message_iter_recurse(&value, &entry);
+
+		while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
+			const char *val;
+			dbus_message_iter_get_basic(&entry, &val);
+			dbus_message_iter_next(&entry);
+			if (connman_inet_check_ipaddress(val) > 0) {
+				if (str->len > 0)
+					g_string_append_printf(str, " %s", val);
+				else
+					g_string_append(str, val);
+			}
+		}
+
+		nameserver_remove_all(service, CONNMAN_IPCONFIG_TYPE_ALL);
+		g_strfreev(service->nameservers_config);
+
+		if (str->len > 0) {
+			service->nameservers_config =
+				g_strsplit_set(str->str, " ", 0);
+		} else {
+			service->nameservers_config = NULL;
+		}
+
+		g_string_free(str, TRUE);
+
+		if (gw && strlen(gw))
+			__connman_service_nameserver_add_routes(service, gw);
+
+		nameserver_add_all(service, CONNMAN_IPCONFIG_TYPE_ALL);
+		dns_configuration_changed(service);
+
+		if (__connman_service_is_connected_state(service,
+						CONNMAN_IPCONFIG_TYPE_IPV4))
+			__connman_wispr_start(service,
+						CONNMAN_IPCONFIG_TYPE_IPV4);
+
+		if (__connman_service_is_connected_state(service,
+						CONNMAN_IPCONFIG_TYPE_IPV6))
+			__connman_wispr_start(service,
+						CONNMAN_IPCONFIG_TYPE_IPV6);
+
+		service_save(service);
+	} else if (g_str_equal(name, "Timeservers.Configuration")) {
+		DBusMessageIter entry;
+		GSList *list = NULL;
+		int count = 0;
+
+		if (service->immutable)
+			return __connman_error_not_supported(msg);
+
+		if (type != DBUS_TYPE_ARRAY)
+			return __connman_error_invalid_arguments(msg);
+
+		dbus_message_iter_recurse(&value, &entry);
+
+		while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
+			const char *val;
+			GSList *new_head;
+
+			dbus_message_iter_get_basic(&entry, &val);
+
+			new_head = __connman_timeserver_add_list(list, val);
+			if (list != new_head) {
+				count++;
+				list = new_head;
+			}
+
+			dbus_message_iter_next(&entry);
+		}
+
+		g_strfreev(service->timeservers_config);
+		service->timeservers_config = NULL;
+
+		if (list) {
+			service->timeservers_config = g_new0(char *, count+1);
+
+			while (list) {
+				count--;
+				service->timeservers_config[count] = list->data;
+				list = g_slist_delete_link(list, list);
+			};
+		}
+
+		service_save(service);
+		timeservers_configuration_changed(service);
+
+		if (service == __connman_service_get_default())
+			__connman_timeserver_sync(service);
+
+	} else if (g_str_equal(name, "Domains.Configuration")) {
+		DBusMessageIter entry;
+		GString *str;
+
+		if (service->immutable)
+			return __connman_error_not_supported(msg);
+
+		if (type != DBUS_TYPE_ARRAY)
+			return __connman_error_invalid_arguments(msg);
+
+		str = g_string_new(NULL);
+		if (!str)
+			return __connman_error_invalid_arguments(msg);
+
+		dbus_message_iter_recurse(&value, &entry);
+
+		while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
+			const char *val;
+			dbus_message_iter_get_basic(&entry, &val);
+			dbus_message_iter_next(&entry);
+			if (str->len > 0)
+				g_string_append_printf(str, " %s", val);
+			else
+				g_string_append(str, val);
+		}
+
+		searchdomain_remove_all(service);
+		g_strfreev(service->domains);
+
+		if (str->len > 0)
+			service->domains = g_strsplit_set(str->str, " ", 0);
+		else
+			service->domains = NULL;
+
+		g_string_free(str, TRUE);
+
+		searchdomain_add_all(service);
+		domain_configuration_changed(service);
+		domain_changed(service);
+
+		service_save(service);
+	} else if (g_str_equal(name, "Proxy.Configuration")) {
+		int err;
+
+		if (service->immutable)
+			return __connman_error_not_supported(msg);
+
+		if (type != DBUS_TYPE_ARRAY)
+			return __connman_error_invalid_arguments(msg);
+
+		err = update_proxy_configuration(service, &value);
+
+		if (err < 0)
+			return __connman_error_failed(msg, -err);
+
+		proxy_configuration_changed(service);
+
+		__connman_notifier_proxy_changed(service);
+
+		service_save(service);
+	} else if (g_str_equal(name, "IPv4.Configuration") ||
+			g_str_equal(name, "IPv6.Configuration")) {
+
+		enum connman_service_state state =
+						CONNMAN_SERVICE_STATE_UNKNOWN;
+		enum connman_ipconfig_type type =
+			CONNMAN_IPCONFIG_TYPE_UNKNOWN;
+		int err = 0;
+
+		if (service->type == CONNMAN_SERVICE_TYPE_VPN ||
+				service->immutable)
+			return __connman_error_not_supported(msg);
+
+		DBG("%s", name);
+
+		if (!service->ipconfig_ipv4 &&
+					!service->ipconfig_ipv6)
+			return __connman_error_invalid_property(msg);
+
+		if (g_str_equal(name, "IPv4.Configuration"))
+			type = CONNMAN_IPCONFIG_TYPE_IPV4;
+		else
+			type = CONNMAN_IPCONFIG_TYPE_IPV6;
+
+		err = __connman_service_reset_ipconfig(service, type, &value,
+								&state);
+
+		if (err < 0) {
+			if (is_connected_state(service, state) ||
+					is_connecting_state(service, state)) {
+				__connman_network_enable_ipconfig(service->network,
+							service->ipconfig_ipv4);
+				__connman_network_enable_ipconfig(service->network,
+							service->ipconfig_ipv6);
+			}
+
+			return __connman_error_failed(msg, -err);
+		}
+
+		if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
+			ipv4_configuration_changed(service);
+		else
+			ipv6_configuration_changed(service);
+
+		if (is_connecting(service) || is_connected(service)) {
+			__connman_network_enable_ipconfig(service->network,
+							service->ipconfig_ipv4);
+			__connman_network_enable_ipconfig(service->network,
+							service->ipconfig_ipv6);
+		}
+
+		service_save(service);
+	} else
+		return __connman_error_invalid_property(msg);
+
+	return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+}
+
+static void set_error(struct connman_service *service,
+					enum connman_service_error error)
+{
+	const char *str;
+
+	if (service->error == error)
+		return;
+
+	service->error = error;
+
+	if (!service->path)
+		return;
+
+	if (!allow_property_changed(service))
+		return;
+
+	str = error2string(service->error);
+
+	if (!str)
+		str = "";
+
+	connman_dbus_property_changed_basic(service->path,
+				CONNMAN_SERVICE_INTERFACE, "Error",
+				DBUS_TYPE_STRING, &str);
+}
+
+static DBusMessage *clear_property(DBusConnection *conn,
+					DBusMessage *msg, void *user_data)
+{
+	struct connman_service *service = user_data;
+	const char *name;
+
+	DBG("service %p", service);
+
+	dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &name,
+							DBUS_TYPE_INVALID);
+
+	if (g_str_equal(name, "Error")) {
+		set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN);
+
+		g_get_current_time(&service->modified);
+		service_save(service);
+		__connman_service_clear_error(service);
+	} else
+		return __connman_error_invalid_property(msg);
+
+	return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+}
+
+static bool is_ipconfig_usable(struct connman_service *service)
+{
+	if (!__connman_ipconfig_is_usable(service->ipconfig_ipv4) &&
+			!__connman_ipconfig_is_usable(service->ipconfig_ipv6))
+		return false;
+
+	return true;
+}
+
+static bool is_ignore(struct connman_service *service)
+{
+	if (!service->autoconnect)
+		return true;
+
+	if (service->roaming)
+		return true;
+
+	if (service->ignore)
+		return true;
+
+	if (service->state == CONNMAN_SERVICE_STATE_FAILURE)
+		return true;
+
+	if (!is_ipconfig_usable(service))
+		return true;
+
+	return false;
+}
+
+static void disconnect_on_last_session(enum connman_service_type type)
+{
+	GList *list;
+
+	for (list = service_list; list; list = list->next) {
+		struct connman_service *service = list->data;
+
+		if (service->type != type)
+			continue;
+
+		if (service->connect_reason != CONNMAN_SERVICE_CONNECT_REASON_SESSION)
+			 continue;
+
+		__connman_service_disconnect(service);
+		return;
+	}
+}
+
+static int active_sessions[MAX_CONNMAN_SERVICE_TYPES] = {};
+static int active_count = 0;
+
+void __connman_service_set_active_session(bool enable, GSList *list)
+{
+	if (!list)
+		return;
+
+	if (enable)
+		active_count++;
+	else
+		active_count--;
+
+	while (list != NULL) {
+		enum connman_service_type type = GPOINTER_TO_INT(list->data);
+
+		switch (type) {
+		case CONNMAN_SERVICE_TYPE_ETHERNET:
+		case CONNMAN_SERVICE_TYPE_WIFI:
+		case CONNMAN_SERVICE_TYPE_BLUETOOTH:
+		case CONNMAN_SERVICE_TYPE_CELLULAR:
+		case CONNMAN_SERVICE_TYPE_GADGET:
+        case CONNMAN_SERVICE_TYPE_LOWPAN:
+			if (enable)
+				active_sessions[type]++;
+			else
+				active_sessions[type]--;
+			break;
+
+		case CONNMAN_SERVICE_TYPE_UNKNOWN:
+		case CONNMAN_SERVICE_TYPE_SYSTEM:
+		case CONNMAN_SERVICE_TYPE_GPS:
+		case CONNMAN_SERVICE_TYPE_VPN:
+		case CONNMAN_SERVICE_TYPE_P2P:
+			break;
+		}
+
+		if (active_sessions[type] == 0)
+			disconnect_on_last_session(type);
+
+		list = g_slist_next(list);
+	}
+
+	DBG("eth %d wifi %d bt %d cellular %d gadget %d sessions %d",
+			active_sessions[CONNMAN_SERVICE_TYPE_ETHERNET],
+			active_sessions[CONNMAN_SERVICE_TYPE_WIFI],
+			active_sessions[CONNMAN_SERVICE_TYPE_BLUETOOTH],
+			active_sessions[CONNMAN_SERVICE_TYPE_CELLULAR],
+			active_sessions[CONNMAN_SERVICE_TYPE_GADGET],
+			active_count);
+}
+
+struct preferred_tech_data {
+	GList *preferred_list;
+	enum connman_service_type type;
+};
+
+static void preferred_tech_add_by_type(gpointer data, gpointer user_data)
+{
+	struct connman_service *service = data;
+	struct preferred_tech_data *tech_data = user_data;
+
+	if (service->type == tech_data->type) {
+		tech_data->preferred_list =
+			g_list_append(tech_data->preferred_list, service);
+
+		DBG("type %d service %p %s", tech_data->type, service,
+				service->name);
+	}
+}
+
+static GList *preferred_tech_list_get(void)
+{
+	unsigned int *tech_array;
+	struct preferred_tech_data tech_data = { 0, };
+	int i;
+
+	tech_array = connman_setting_get_uint_list("PreferredTechnologies");
+	if (!tech_array)
+		return NULL;
+
+	if (connman_setting_get_bool("SingleConnectedTechnology")) {
+		GList *list;
+		for (list = service_list; list; list = list->next) {
+			struct connman_service *service = list->data;
+
+			if (!is_connected(service))
+				break;
+
+			if (service->connect_reason ==
+					CONNMAN_SERVICE_CONNECT_REASON_USER) {
+				DBG("service %p name %s is user connected",
+						service, service->name);
+				return NULL;
+			}
+		}
+	}
+
+	for (i = 0; tech_array[i] != 0; i += 1) {
+		tech_data.type = tech_array[i];
+		g_list_foreach(service_list, preferred_tech_add_by_type,
+				&tech_data);
+	}
+
+	return tech_data.preferred_list;
+}
+
+static bool auto_connect_service(GList *services,
+				enum connman_service_connect_reason reason,
+				bool preferred)
+{
+	struct connman_service *service = NULL;
+	bool ignore[MAX_CONNMAN_SERVICE_TYPES] = { };
+	bool autoconnecting = false;
+	GList *list;
+
+	DBG("preferred %d sessions %d reason %s", preferred, active_count,
+		reason2string(reason));
+
+	ignore[CONNMAN_SERVICE_TYPE_VPN] = true;
+
+	for (list = services; list; list = list->next) {
+		service = list->data;
+
+		if (ignore[service->type]) {
+			DBG("service %p type %s ignore", service,
+				__connman_service_type2string(service->type));
+			continue;
+		}
+
+		if (service->pending ||
+				is_connecting(service) ||
+				is_connected(service)) {
+			if (!active_count)
+				return true;
+
+			ignore[service->type] = true;
+			autoconnecting = true;
+
+			DBG("service %p type %s busy", service,
+				__connman_service_type2string(service->type));
+
+			continue;
+		}
+
+		if (!service->favorite) {
+			if (preferred)
+			       continue;
+
+			return autoconnecting;
+		}
+
+		if (is_ignore(service) || service->state !=
+				CONNMAN_SERVICE_STATE_IDLE)
+			continue;
+
+		if (autoconnecting && !active_sessions[service->type]) {
+			DBG("service %p type %s has no users", service,
+				__connman_service_type2string(service->type));
+			continue;
+		}
+
+		DBG("service %p %s %s", service, service->name,
+			(preferred) ? "preferred" : reason2string(reason));
+
+		__connman_service_connect(service, reason);
+
+		if (!active_count)
+			return true;
+
+		ignore[service->type] = true;
+	}
+
+	return autoconnecting;
+}
+
+static gboolean run_auto_connect(gpointer data)
+{
+	enum connman_service_connect_reason reason = GPOINTER_TO_UINT(data);
+	bool autoconnecting = false;
+	GList *preferred_tech;
+
+	autoconnect_timeout = 0;
+
+	DBG("");
+
+	preferred_tech = preferred_tech_list_get();
+	if (preferred_tech) {
+		autoconnecting = auto_connect_service(preferred_tech, reason,
+							true);
+		g_list_free(preferred_tech);
+	}
+
+	if (!autoconnecting || active_count)
+		auto_connect_service(service_list, reason, false);
+
+	return FALSE;
+}
+
+void __connman_service_auto_connect(enum connman_service_connect_reason reason)
+{
+	DBG("");
+
+	if (autoconnect_timeout != 0)
+		return;
+
+	if (!__connman_session_policy_autoconnect(reason))
+		return;
+
+	autoconnect_timeout = g_timeout_add_seconds(0, run_auto_connect,
+						GUINT_TO_POINTER(reason));
+}
+
+static gboolean run_vpn_auto_connect(gpointer data) {
+	GList *list;
+	bool need_split = false;
+
+	vpn_autoconnect_timeout = 0;
+
+	for (list = service_list; list; list = list->next) {
+		struct connman_service *service = list->data;
+		int res;
+
+		if (service->type != CONNMAN_SERVICE_TYPE_VPN)
+			continue;
+
+		if (is_connected(service) || is_connecting(service)) {
+			if (!service->do_split_routing)
+				need_split = true;
+			continue;
+		}
+
+		if (is_ignore(service) || !service->favorite)
+			continue;
+
+		if (need_split && !service->do_split_routing) {
+			DBG("service %p no split routing", service);
+			continue;
+		}
+
+		DBG("service %p %s %s", service, service->name,
+				service->do_split_routing ?
+				"split routing" : "");
+
+		res = __connman_service_connect(service,
+				CONNMAN_SERVICE_CONNECT_REASON_AUTO);
+		if (res < 0 && res != -EINPROGRESS)
+			continue;
+
+		if (!service->do_split_routing)
+			need_split = true;
+	}
+
+	return FALSE;
+}
+
+static void vpn_auto_connect(void)
+{
+	if (vpn_autoconnect_timeout)
+		return;
+
+	vpn_autoconnect_timeout =
+		g_timeout_add_seconds(0, run_vpn_auto_connect, NULL);
+}
+
+static void remove_timeout(struct connman_service *service)
+{
+	if (service->timeout > 0) {
+		g_source_remove(service->timeout);
+		service->timeout = 0;
+	}
+}
+
+static void reply_pending(struct connman_service *service, int error)
+{
+	remove_timeout(service);
+
+	if (service->pending) {
+		connman_dbus_reply_pending(service->pending, error, NULL);
+		service->pending = NULL;
+	}
+
+	if (service->provider_pending) {
+		connman_dbus_reply_pending(service->provider_pending,
+						error, service->path);
+		service->provider_pending = NULL;
+	}
+}
+
+bool
+__connman_service_is_provider_pending(struct connman_service *service)
+{
+	if (!service)
+		return false;
+
+	if (service->provider_pending)
+		return true;
+
+	return false;
+}
+
+void __connman_service_set_provider_pending(struct connman_service *service,
+							DBusMessage *msg)
+{
+	if (service->provider_pending) {
+		DBG("service %p provider pending msg %p already exists",
+			service, service->provider_pending);
+		return;
+	}
+
+	service->provider_pending = msg;
+	return;
+}
+
+static void check_pending_msg(struct connman_service *service)
+{
+	if (!service->pending)
+		return;
+
+	DBG("service %p pending msg %p already exists", service,
+						service->pending);
+	dbus_message_unref(service->pending);
+}
+
+void __connman_service_set_hidden_data(struct connman_service *service,
+							gpointer user_data)
+{
+	DBusMessage *pending = user_data;
+
+	DBG("service %p pending %p", service, pending);
+
+	if (!pending)
+		return;
+
+	check_pending_msg(service);
+
+	service->pending = pending;
+}
+
+void __connman_service_return_error(struct connman_service *service,
+				int error, gpointer user_data)
+{
+	DBG("service %p error %d user_data %p", service, error, user_data);
+
+	__connman_service_set_hidden_data(service, user_data);
+
+	reply_pending(service, error);
+}
+
+static gboolean connect_timeout(gpointer user_data)
+{
+	struct connman_service *service = user_data;
+	bool autoconnect = false;
+
+	DBG("service %p", service);
+
+	service->timeout = 0;
+
+	if (service->network)
+		__connman_network_disconnect(service->network, FALSE);
+	else if (service->provider)
+		connman_provider_disconnect(service->provider);
+
+	__connman_ipconfig_disable(service->ipconfig_ipv4);
+	__connman_ipconfig_disable(service->ipconfig_ipv6);
+
+	__connman_stats_service_unregister(service);
+
+	if (service->pending) {
+		DBusMessage *reply;
+
+		reply = __connman_error_operation_timeout(service->pending);
+		if (reply)
+			g_dbus_send_message(connection, reply);
+
+		dbus_message_unref(service->pending);
+		service->pending = NULL;
+	} else
+		autoconnect = true;
+
+	__connman_service_ipconfig_indicate_state(service,
+					CONNMAN_SERVICE_STATE_FAILURE,
+					CONNMAN_IPCONFIG_TYPE_IPV4);
+	__connman_service_ipconfig_indicate_state(service,
+					CONNMAN_SERVICE_STATE_FAILURE,
+					CONNMAN_IPCONFIG_TYPE_IPV6);
+
+	if (autoconnect &&
+			service->connect_reason !=
+				CONNMAN_SERVICE_CONNECT_REASON_USER)
+		__connman_service_auto_connect(CONNMAN_SERVICE_CONNECT_REASON_AUTO);
+
+	return FALSE;
+}
+
+static DBusMessage *connect_service(DBusConnection *conn,
+					DBusMessage *msg, void *user_data)
+{
+	struct connman_service *service = user_data;
+	int index, err = 0;
+	GList *list;
+
+	DBG("service %p", service);
+
+	if (service->pending)
+		return __connman_error_in_progress(msg);
+
+	index = __connman_service_get_index(service);
+
+	for (list = service_list; list; list = list->next) {
+		struct connman_service *temp = list->data;
+
+		if (!is_connecting(temp) && !is_connected(temp))
+			break;
+
+		if (service == temp)
+			continue;
+
+		if (service->type != temp->type)
+			continue;
+
+		if (__connman_service_get_index(temp) == index &&
+				__connman_service_disconnect(temp) == -EINPROGRESS)
+			err = -EINPROGRESS;
+
+	}
+	if (err == -EINPROGRESS)
+		return __connman_error_operation_timeout(msg);
+
+	service->ignore = false;
+
+	service->pending = dbus_message_ref(msg);
+
+	err = __connman_service_connect(service,
+			CONNMAN_SERVICE_CONNECT_REASON_USER);
+
+	if (err == -EINPROGRESS)
+		return NULL;
+
+	if (service->pending) {
+		dbus_message_unref(service->pending);
+		service->pending = NULL;
+	}
+
+	if (err < 0)
+		return __connman_error_failed(msg, -err);
+
+	return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+}
+
+static DBusMessage *disconnect_service(DBusConnection *conn,
+					DBusMessage *msg, void *user_data)
+{
+	struct connman_service *service = user_data;
+	int err;
+
+	DBG("service %p", service);
+
+	service->ignore = true;
+
+	err = __connman_service_disconnect(service);
+	if (err < 0 && err != -EINPROGRESS)
+		return __connman_error_failed(msg, -err);
+
+	return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+}
+
+bool __connman_service_remove(struct connman_service *service)
+{
+	if (service->type == CONNMAN_SERVICE_TYPE_ETHERNET ||
+			service->type == CONNMAN_SERVICE_TYPE_GADGET)
+		return false;
+
+	if (service->immutable || service->hidden ||
+			__connman_provider_is_immutable(service->provider))
+		return false;
+
+	if (!service->favorite && service->state !=
+						CONNMAN_SERVICE_STATE_FAILURE)
+		return false;
+
+	__connman_service_disconnect(service);
+
+	g_free(service->passphrase);
+	service->passphrase = NULL;
+
+	g_free(service->identity);
+	service->identity = NULL;
+
+	g_free(service->agent_identity);
+	service->agent_identity = NULL;
+
+	g_free(service->eap);
+	service->eap = NULL;
+
+	service->error = CONNMAN_SERVICE_ERROR_UNKNOWN;
+
+	__connman_service_set_favorite(service, false);
+
+	__connman_ipconfig_ipv6_reset_privacy(service->ipconfig_ipv6);
+
+	service_save(service);
+
+	return true;
+}
+
+static DBusMessage *remove_service(DBusConnection *conn,
+					DBusMessage *msg, void *user_data)
+{
+	struct connman_service *service = user_data;
+
+	DBG("service %p", service);
+
+	if (!__connman_service_remove(service))
+		return __connman_error_not_supported(msg);
+
+	return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+}
+
+static bool check_suitable_state(enum connman_service_state a,
+					enum connman_service_state b)
+{
+	/*
+	 * Special check so that "ready" service can be moved before
+	 * "online" one.
+	 */
+	if ((a == CONNMAN_SERVICE_STATE_ONLINE &&
+			b == CONNMAN_SERVICE_STATE_READY) ||
+		(b == CONNMAN_SERVICE_STATE_ONLINE &&
+			a == CONNMAN_SERVICE_STATE_READY))
+		return true;
+
+	return a == b;
+}
+
+static void downgrade_state(struct connman_service *service)
+{
+	if (!service)
+		return;
+
+	DBG("service %p state4 %d state6 %d", service, service->state_ipv4,
+						service->state_ipv6);
+
+	if (service->state_ipv4 == CONNMAN_SERVICE_STATE_ONLINE)
+		__connman_service_ipconfig_indicate_state(service,
+						CONNMAN_SERVICE_STATE_READY,
+						CONNMAN_IPCONFIG_TYPE_IPV4);
+
+	if (service->state_ipv6 == CONNMAN_SERVICE_STATE_ONLINE)
+		__connman_service_ipconfig_indicate_state(service,
+						CONNMAN_SERVICE_STATE_READY,
+						CONNMAN_IPCONFIG_TYPE_IPV6);
+}
+
+static void apply_relevant_default_downgrade(struct connman_service *service)
+{
+	struct connman_service *def_service;
+
+	def_service = __connman_service_get_default();
+	if (!def_service)
+		return;
+
+	if (def_service == service &&
+			def_service->state == CONNMAN_SERVICE_STATE_ONLINE) {
+		def_service->state = CONNMAN_SERVICE_STATE_READY;
+		__connman_notifier_leave_online(def_service->type);
+		state_changed(def_service);
+	}
+}
+
+static void switch_default_service(struct connman_service *default_service,
+		struct connman_service *downgrade_service)
+{
+	struct connman_service *service;
+	GList *src, *dst;
+
+	apply_relevant_default_downgrade(default_service);
+	src = g_list_find(service_list, downgrade_service);
+	dst = g_list_find(service_list, default_service);
+
+	/* Nothing to do */
+	if (src == dst || src->next == dst)
+		return;
+
+	service = src->data;
+	service_list = g_list_delete_link(service_list, src);
+	service_list = g_list_insert_before(service_list, dst, service);
+
+	downgrade_state(downgrade_service);
+}
+
+static DBusMessage *move_service(DBusConnection *conn,
+					DBusMessage *msg, void *user_data,
+								bool before)
+{
+	struct connman_service *service = user_data;
+	struct connman_service *target;
+	const char *path;
+	enum connman_ipconfig_method target4, target6;
+	enum connman_ipconfig_method service4, service6;
+
+	DBG("service %p", service);
+
+	dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
+							DBUS_TYPE_INVALID);
+
+	if (!service->favorite)
+		return __connman_error_not_supported(msg);
+
+	target = find_service(path);
+	if (!target || !target->favorite || target == service)
+		return __connman_error_invalid_service(msg);
+
+	if (target->type == CONNMAN_SERVICE_TYPE_VPN) {
+		/*
+		 * We only allow VPN route splitting if there are
+		 * routes defined for a given VPN.
+		 */
+		if (!__connman_provider_check_routes(target->provider)) {
+			connman_info("Cannot move service. "
+				"No routes defined for provider %s",
+				__connman_provider_get_ident(target->provider));
+			return __connman_error_invalid_service(msg);
+		}
+
+		target->do_split_routing = true;
+	} else
+		target->do_split_routing = false;
+
+	service->do_split_routing = false;
+
+	target4 = __connman_ipconfig_get_method(target->ipconfig_ipv4);
+	target6 = __connman_ipconfig_get_method(target->ipconfig_ipv6);
+	service4 = __connman_ipconfig_get_method(service->ipconfig_ipv4);
+	service6 = __connman_ipconfig_get_method(service->ipconfig_ipv6);
+
+	DBG("target %s method %d/%d state %d/%d split %d", target->identifier,
+		target4, target6, target->state_ipv4, target->state_ipv6,
+		target->do_split_routing);
+
+	DBG("service %s method %d/%d state %d/%d", service->identifier,
+				service4, service6,
+				service->state_ipv4, service->state_ipv6);
+
+	/*
+	 * If method is OFF, then we do not need to check the corresponding
+	 * ipconfig state.
+	 */
+	if (target4 == CONNMAN_IPCONFIG_METHOD_OFF) {
+		if (service6 != CONNMAN_IPCONFIG_METHOD_OFF) {
+			if (!check_suitable_state(target->state_ipv6,
+							service->state_ipv6))
+				return __connman_error_invalid_service(msg);
+		}
+	}
+
+	if (target6 == CONNMAN_IPCONFIG_METHOD_OFF) {
+		if (service4 != CONNMAN_IPCONFIG_METHOD_OFF) {
+			if (!check_suitable_state(target->state_ipv4,
+							service->state_ipv4))
+				return __connman_error_invalid_service(msg);
+		}
+	}
+
+	if (service4 == CONNMAN_IPCONFIG_METHOD_OFF) {
+		if (target6 != CONNMAN_IPCONFIG_METHOD_OFF) {
+			if (!check_suitable_state(target->state_ipv6,
+							service->state_ipv6))
+				return __connman_error_invalid_service(msg);
+		}
+	}
+
+	if (service6 == CONNMAN_IPCONFIG_METHOD_OFF) {
+		if (target4 != CONNMAN_IPCONFIG_METHOD_OFF) {
+			if (!check_suitable_state(target->state_ipv4,
+							service->state_ipv4))
+				return __connman_error_invalid_service(msg);
+		}
+	}
+
+	g_get_current_time(&service->modified);
+	service_save(service);
+	service_save(target);
+
+	/*
+	 * If the service which goes down is the default service and is
+	 * online, we downgrade directly its state to ready so:
+	 * the service which goes up, needs to recompute its state which
+	 * is triggered via downgrading it - if relevant - to state ready.
+	 */
+	if (before)
+		switch_default_service(target, service);
+	else
+		switch_default_service(service, target);
+
+	__connman_connection_update_gateway();
+
+	return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+}
+
+static DBusMessage *move_before(DBusConnection *conn,
+					DBusMessage *msg, void *user_data)
+{
+	return move_service(conn, msg, user_data, true);
+}
+
+static DBusMessage *move_after(DBusConnection *conn,
+					DBusMessage *msg, void *user_data)
+{
+	return move_service(conn, msg, user_data, false);
+}
+
+static DBusMessage *reset_counters(DBusConnection *conn,
+					DBusMessage *msg, void *user_data)
+{
+	struct connman_service *service = user_data;
+
+	reset_stats(service);
+
+	return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+}
+
+static struct _services_notify {
+	int id;
+	GHashTable *add;
+	GHashTable *remove;
+} *services_notify;
+
+static void service_append_added_foreach(gpointer data, gpointer user_data)
+{
+	struct connman_service *service = data;
+	DBusMessageIter *iter = user_data;
+
+	if (!service || !service->path) {
+		DBG("service %p or path is NULL", service);
+		return;
+	}
+
+	if (g_hash_table_lookup(services_notify->add, service->path)) {
+		DBG("new %s", service->path);
+
+		append_struct(service, iter);
+		g_hash_table_remove(services_notify->add, service->path);
+	} else {
+		DBG("changed %s", service->path);
+
+		append_struct_service(iter, NULL, service);
+	}
+}
+
+static void service_append_ordered(DBusMessageIter *iter, void *user_data)
+{
+	g_list_foreach(service_list, service_append_added_foreach, iter);
+}
+
+static void append_removed(gpointer key, gpointer value, gpointer user_data)
+{
+	char *objpath = key;
+	DBusMessageIter *iter = user_data;
+
+	DBG("removed %s", objpath);
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH, &objpath);
+}
+
+static void service_append_removed(DBusMessageIter *iter, void *user_data)
+{
+	g_hash_table_foreach(services_notify->remove, append_removed, iter);
+}
+
+static gboolean service_send_changed(gpointer data)
+{
+	DBusMessage *signal;
+
+	DBG("");
+
+	services_notify->id = 0;
+
+	signal = dbus_message_new_signal(CONNMAN_MANAGER_PATH,
+			CONNMAN_MANAGER_INTERFACE, "ServicesChanged");
+	if (!signal)
+		return FALSE;
+
+	__connman_dbus_append_objpath_dict_array(signal,
+					service_append_ordered, NULL);
+	__connman_dbus_append_objpath_array(signal,
+					service_append_removed, NULL);
+
+	dbus_connection_send(connection, signal, NULL);
+	dbus_message_unref(signal);
+
+	g_hash_table_remove_all(services_notify->remove);
+	g_hash_table_remove_all(services_notify->add);
+
+	return FALSE;
+}
+
+static void service_schedule_changed(void)
+{
+	if (services_notify->id != 0)
+		return;
+
+	services_notify->id = g_timeout_add(100, service_send_changed, NULL);
+}
+
+static void service_schedule_added(struct connman_service *service)
+{
+	DBG("service %p", service);
+
+	g_hash_table_remove(services_notify->remove, service->path);
+	g_hash_table_replace(services_notify->add, service->path, service);
+
+	service_schedule_changed();
+}
+
+static void service_schedule_removed(struct connman_service *service)
+{
+	if (!service || !service->path) {
+		DBG("service %p or path is NULL", service);
+		return;
+	}
+
+	DBG("service %p %s", service, service->path);
+
+	g_hash_table_remove(services_notify->add, service->path);
+	g_hash_table_replace(services_notify->remove, g_strdup(service->path),
+			NULL);
+
+	service_schedule_changed();
+}
+
+static bool allow_property_changed(struct connman_service *service)
+{
+	if (g_hash_table_lookup_extended(services_notify->add, service->path,
+					NULL, NULL)) {
+		DBG("no property updates for service %p", service);
+		return false;
+	}
+
+	return true;
+}
+
+static const GDBusMethodTable service_methods[] = {
+	{ GDBUS_DEPRECATED_METHOD("GetProperties",
+			NULL, GDBUS_ARGS({ "properties", "a{sv}" }),
+			get_properties) },
+	{ GDBUS_METHOD("SetProperty",
+			GDBUS_ARGS({ "name", "s" }, { "value", "v" }),
+			NULL, set_property) },
+	{ GDBUS_METHOD("ClearProperty",
+			GDBUS_ARGS({ "name", "s" }), NULL,
+			clear_property) },
+	{ GDBUS_ASYNC_METHOD("Connect", NULL, NULL,
+			      connect_service) },
+	{ GDBUS_METHOD("Disconnect", NULL, NULL,
+			disconnect_service) },
+	{ GDBUS_METHOD("Remove", NULL, NULL, remove_service) },
+	{ GDBUS_METHOD("MoveBefore",
+			GDBUS_ARGS({ "service", "o" }), NULL,
+			move_before) },
+	{ GDBUS_METHOD("MoveAfter",
+			GDBUS_ARGS({ "service", "o" }), NULL,
+			move_after) },
+	{ GDBUS_METHOD("ResetCounters", NULL, NULL, reset_counters) },
+	{ },
+};
+
+static const GDBusSignalTable service_signals[] = {
+	{ GDBUS_SIGNAL("PropertyChanged",
+			GDBUS_ARGS({ "name", "s" }, { "value", "v" })) },
+	{ },
+};
+
+static void service_free(gpointer user_data)
+{
+	struct connman_service *service = user_data;
+	char *path = service->path;
+
+	DBG("service %p", service);
+
+	reply_pending(service, ENOENT);
+
+	__connman_notifier_service_remove(service);
+	service_schedule_removed(service);
+
+	__connman_wispr_stop(service);
+	stats_stop(service);
+
+	service->path = NULL;
+
+	if (path) {
+		__connman_connection_update_gateway();
+
+		g_dbus_unregister_interface(connection, path,
+						CONNMAN_SERVICE_INTERFACE);
+		g_free(path);
+	}
+
+	g_hash_table_destroy(service->counter_table);
+
+	if (service->network) {
+		__connman_network_disconnect(service->network, FALSE);
+		connman_network_unref(service->network);
+		service->network = NULL;
+	}
+
+	if (service->provider)
+		connman_provider_unref(service->provider);
+
+	if (service->ipconfig_ipv4) {
+		__connman_ipconfig_set_ops(service->ipconfig_ipv4, NULL);
+		__connman_ipconfig_set_data(service->ipconfig_ipv4, NULL);
+		__connman_ipconfig_unref(service->ipconfig_ipv4);
+		service->ipconfig_ipv4 = NULL;
+	}
+
+	if (service->ipconfig_ipv6) {
+		__connman_ipconfig_set_ops(service->ipconfig_ipv6, NULL);
+		__connman_ipconfig_set_data(service->ipconfig_ipv6, NULL);
+		__connman_ipconfig_unref(service->ipconfig_ipv6);
+		service->ipconfig_ipv6 = NULL;
+	}
+
+	g_strfreev(service->timeservers);
+	g_strfreev(service->timeservers_config);
+	g_strfreev(service->nameservers);
+	g_strfreev(service->nameservers_config);
+	g_strfreev(service->nameservers_auto);
+	g_strfreev(service->domains);
+	g_strfreev(service->proxies);
+	g_strfreev(service->excludes);
+
+	g_free(service->hostname);
+	g_free(service->domainname);
+	g_free(service->pac);
+	g_free(service->name);
+	g_free(service->passphrase);
+	g_free(service->identifier);
+	g_free(service->eap);
+	g_free(service->identity);
+	g_free(service->agent_identity);
+	g_free(service->ca_cert_file);
+	g_free(service->client_cert_file);
+	g_free(service->private_key_file);
+	g_free(service->private_key_passphrase);
+	g_free(service->phase2);
+	g_free(service->config_file);
+	g_free(service->config_entry);
+
+	if (service->stats.timer)
+		g_timer_destroy(service->stats.timer);
+	if (service->stats_roaming.timer)
+		g_timer_destroy(service->stats_roaming.timer);
+
+	if (current_default == service)
+		current_default = NULL;
+
+	g_free(service);
+}
+
+static void stats_init(struct connman_service *service)
+{
+	/* home */
+	service->stats.valid = false;
+	service->stats.enabled = false;
+	service->stats.timer = g_timer_new();
+
+	/* roaming */
+	service->stats_roaming.valid = false;
+	service->stats_roaming.enabled = false;
+	service->stats_roaming.timer = g_timer_new();
+}
+
+static void service_initialize(struct connman_service *service)
+{
+	DBG("service %p", service);
+
+	service->refcount = 1;
+
+	service->error = CONNMAN_SERVICE_ERROR_UNKNOWN;
+
+	service->type     = CONNMAN_SERVICE_TYPE_UNKNOWN;
+	service->security = CONNMAN_SERVICE_SECURITY_UNKNOWN;
+
+	service->state = CONNMAN_SERVICE_STATE_UNKNOWN;
+	service->state_ipv4 = CONNMAN_SERVICE_STATE_UNKNOWN;
+	service->state_ipv6 = CONNMAN_SERVICE_STATE_UNKNOWN;
+
+	service->favorite  = false;
+	service->immutable = false;
+	service->hidden = false;
+
+	service->ignore = false;
+
+	service->connect_reason = CONNMAN_SERVICE_CONNECT_REASON_NONE;
+
+	service->order = 0;
+
+	stats_init(service);
+
+	service->provider = NULL;
+
+	service->wps = false;
+}
+
+/**
+ * connman_service_create:
+ *
+ * Allocate a new service.
+ *
+ * Returns: a newly-allocated #connman_service structure
+ */
+struct connman_service *connman_service_create(void)
+{
+	GSList *list;
+	struct connman_stats_counter *counters;
+	const char *counter;
+
+	struct connman_service *service;
+
+	service = g_try_new0(struct connman_service, 1);
+	if (!service)
+		return NULL;
+
+	DBG("service %p", service);
+
+	service->counter_table = g_hash_table_new_full(g_str_hash,
+						g_str_equal, NULL, g_free);
+
+	for (list = counter_list; list; list = list->next) {
+		counter = list->data;
+
+		counters = g_try_new0(struct connman_stats_counter, 1);
+		if (!counters) {
+			g_hash_table_destroy(service->counter_table);
+			g_free(service);
+			return NULL;
+		}
+
+		counters->append_all = true;
+
+		g_hash_table_replace(service->counter_table, (gpointer)counter,
+				counters);
+	}
+
+	service_initialize(service);
+
+	return service;
+}
+
+/**
+ * connman_service_ref:
+ * @service: service structure
+ *
+ * Increase reference counter of service
+ */
+struct connman_service *
+connman_service_ref_debug(struct connman_service *service,
+			const char *file, int line, const char *caller)
+{
+	DBG("%p ref %d by %s:%d:%s()", service, service->refcount + 1,
+		file, line, caller);
+
+	__sync_fetch_and_add(&service->refcount, 1);
+
+	return service;
+}
+
+/**
+ * connman_service_unref:
+ * @service: service structure
+ *
+ * Decrease reference counter of service and release service if no
+ * longer needed.
+ */
+void connman_service_unref_debug(struct connman_service *service,
+			const char *file, int line, const char *caller)
+{
+	DBG("%p ref %d by %s:%d:%s()", service, service->refcount - 1,
+		file, line, caller);
+
+	if (__sync_fetch_and_sub(&service->refcount, 1) != 1)
+		return;
+
+	service_list = g_list_remove(service_list, service);
+
+	__connman_service_disconnect(service);
+
+	g_hash_table_remove(service_hash, service->identifier);
+}
+
+static gint service_compare(gconstpointer a, gconstpointer b)
+{
+	struct connman_service *service_a = (void *) a;
+	struct connman_service *service_b = (void *) b;
+	enum connman_service_state state_a, state_b;
+	bool a_connected, b_connected;
+	gint strength;
+
+	state_a = service_a->state;
+	state_b = service_b->state;
+	a_connected = is_connected(service_a);
+	b_connected = is_connected(service_b);
+
+	if (a_connected && b_connected) {
+		if (service_a->order > service_b->order)
+			return -1;
+
+		if (service_a->order < service_b->order)
+			return 1;
+	}
+
+	if (state_a != state_b) {
+		if (a_connected && b_connected) {
+			/* We prefer online over ready state */
+			if (state_a == CONNMAN_SERVICE_STATE_ONLINE)
+				return -1;
+
+			if (state_b == CONNMAN_SERVICE_STATE_ONLINE)
+				return 1;
+		}
+
+		if (a_connected)
+			return -1;
+		if (b_connected)
+			return 1;
+
+		if (is_connecting(service_a))
+			return -1;
+		if (is_connecting(service_b))
+			return 1;
+	}
+
+	if (service_a->favorite && !service_b->favorite)
+		return -1;
+
+	if (!service_a->favorite && service_b->favorite)
+		return 1;
+
+	if (service_a->type != service_b->type) {
+
+		if (service_a->type == CONNMAN_SERVICE_TYPE_ETHERNET)
+			return -1;
+		if (service_b->type == CONNMAN_SERVICE_TYPE_ETHERNET)
+			return 1;
+
+		if (service_a->type == CONNMAN_SERVICE_TYPE_WIFI)
+			return -1;
+		if (service_b->type == CONNMAN_SERVICE_TYPE_WIFI)
+			return 1;
+
+		if (service_a->type == CONNMAN_SERVICE_TYPE_CELLULAR)
+			return -1;
+		if (service_b->type == CONNMAN_SERVICE_TYPE_CELLULAR)
+			return 1;
+
+		if (service_a->type == CONNMAN_SERVICE_TYPE_BLUETOOTH)
+			return -1;
+		if (service_b->type == CONNMAN_SERVICE_TYPE_BLUETOOTH)
+			return 1;
+
+		if (service_a->type == CONNMAN_SERVICE_TYPE_VPN)
+			return -1;
+		if (service_b->type == CONNMAN_SERVICE_TYPE_VPN)
+			return 1;
+
+		if (service_a->type == CONNMAN_SERVICE_TYPE_GADGET)
+			return -1;
+		if (service_b->type == CONNMAN_SERVICE_TYPE_GADGET)
+			return 1;
+
+		if (service_a->type == CONNMAN_SERVICE_TYPE_LOWPAN)
+			return -1;
+		if (service_b->type == CONNMAN_SERVICE_TYPE_LOWPAN)
+			return 1;
+	}
+
+	strength = (gint) service_b->strength - (gint) service_a->strength;
+	if (strength)
+		return strength;
+
+	return g_strcmp0(service_a->name, service_b->name);
+}
+
+static void service_list_sort(void)
+{
+	if (service_list && service_list->next) {
+		service_list = g_list_sort(service_list, service_compare);
+		service_schedule_changed();
+	}
+}
+
+/**
+ * connman_service_get_type:
+ * @service: service structure
+ *
+ * Get the type of service
+ */
+enum connman_service_type connman_service_get_type(struct connman_service *service)
+{
+	if (!service)
+		return CONNMAN_SERVICE_TYPE_UNKNOWN;
+
+	return service->type;
+}
+
+/**
+ * connman_service_get_interface:
+ * @service: service structure
+ *
+ * Get network interface of service
+ */
+char *connman_service_get_interface(struct connman_service *service)
+{
+	int index;
+
+	if (!service)
+		return NULL;
+
+	index = __connman_service_get_index(service);
+
+	return connman_inet_ifname(index);
+}
+
+/**
+ * connman_service_get_network:
+ * @service: service structure
+ *
+ * Get the service network
+ */
+struct connman_network *
+__connman_service_get_network(struct connman_service *service)
+{
+	if (!service)
+		return NULL;
+
+	return service->network;
+}
+
+struct connman_ipconfig *
+__connman_service_get_ip4config(struct connman_service *service)
+{
+	if (!service)
+		return NULL;
+
+	return service->ipconfig_ipv4;
+}
+
+struct connman_ipconfig *
+__connman_service_get_ip6config(struct connman_service *service)
+{
+	if (!service)
+		return NULL;
+
+	return service->ipconfig_ipv6;
+}
+
+struct connman_ipconfig *
+__connman_service_get_ipconfig(struct connman_service *service, int family)
+{
+	if (family == AF_INET)
+		return __connman_service_get_ip4config(service);
+	else if (family == AF_INET6)
+		return __connman_service_get_ip6config(service);
+	else
+		return NULL;
+
+}
+
+bool __connman_service_is_connected_state(struct connman_service *service,
+					enum connman_ipconfig_type type)
+{
+	if (!service)
+		return false;
+
+	switch (type) {
+	case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
+		break;
+	case CONNMAN_IPCONFIG_TYPE_IPV4:
+		return is_connected_state(service, service->state_ipv4);
+	case CONNMAN_IPCONFIG_TYPE_IPV6:
+		return is_connected_state(service, service->state_ipv6);
+	case CONNMAN_IPCONFIG_TYPE_ALL:
+		return is_connected_state(service,
+					CONNMAN_IPCONFIG_TYPE_IPV4) &&
+			is_connected_state(service,
+					CONNMAN_IPCONFIG_TYPE_IPV6);
+	}
+
+	return false;
+}
+enum connman_service_security __connman_service_get_security(
+				struct connman_service *service)
+{
+	if (!service)
+		return CONNMAN_SERVICE_SECURITY_UNKNOWN;
+
+	return service->security;
+}
+
+const char *__connman_service_get_phase2(struct connman_service *service)
+{
+	if (!service)
+		return NULL;
+
+	return service->phase2;
+}
+
+bool __connman_service_wps_enabled(struct connman_service *service)
+{
+	if (!service)
+		return false;
+
+	return service->wps;
+}
+
+void __connman_service_mark_dirty(void)
+{
+	services_dirty = true;
+}
+
+/**
+ * __connman_service_set_favorite_delayed:
+ * @service: service structure
+ * @favorite: favorite value
+ * @delay_ordering: do not order service sequence
+ *
+ * Change the favorite setting of service
+ */
+int __connman_service_set_favorite_delayed(struct connman_service *service,
+					bool favorite,
+					bool delay_ordering)
+{
+	if (service->hidden)
+		return -EOPNOTSUPP;
+
+	if (service->favorite == favorite)
+		return -EALREADY;
+
+	service->favorite = favorite;
+
+	if (!delay_ordering)
+		__connman_service_get_order(service);
+
+	favorite_changed(service);
+
+	if (!delay_ordering) {
+
+		service_list_sort();
+
+		__connman_connection_update_gateway();
+	}
+
+	return 0;
+}
+
+/**
+ * __connman_service_set_favorite:
+ * @service: service structure
+ * @favorite: favorite value
+ *
+ * Change the favorite setting of service
+ */
+int __connman_service_set_favorite(struct connman_service *service,
+						bool favorite)
+{
+	return __connman_service_set_favorite_delayed(service, favorite,
+							false);
+}
+
+bool connman_service_get_favorite(struct connman_service *service)
+{
+	return service->favorite;
+}
+
+bool connman_service_get_autoconnect(struct connman_service *service)
+{
+	return service->autoconnect;
+}
+
+int __connman_service_set_immutable(struct connman_service *service,
+						bool immutable)
+{
+	if (service->hidden)
+		return -EOPNOTSUPP;
+
+	if (service->immutable == immutable)
+		return 0;
+
+	service->immutable = immutable;
+
+	immutable_changed(service);
+
+	return 0;
+}
+
+int __connman_service_set_ignore(struct connman_service *service,
+						bool ignore)
+{
+	if (!service)
+		return -EINVAL;
+
+	service->ignore = ignore;
+
+	return 0;
+}
+
+void __connman_service_set_string(struct connman_service *service,
+				  const char *key, const char *value)
+{
+	if (service->hidden)
+		return;
+	if (g_str_equal(key, "EAP")) {
+		g_free(service->eap);
+		service->eap = g_strdup(value);
+	} else if (g_str_equal(key, "Identity")) {
+		g_free(service->identity);
+		service->identity = g_strdup(value);
+	} else if (g_str_equal(key, "CACertFile")) {
+		g_free(service->ca_cert_file);
+		service->ca_cert_file = g_strdup(value);
+	} else if (g_str_equal(key, "ClientCertFile")) {
+		g_free(service->client_cert_file);
+		service->client_cert_file = g_strdup(value);
+	} else if (g_str_equal(key, "PrivateKeyFile")) {
+		g_free(service->private_key_file);
+		service->private_key_file = g_strdup(value);
+	} else if (g_str_equal(key, "PrivateKeyPassphrase")) {
+		g_free(service->private_key_passphrase);
+		service->private_key_passphrase = g_strdup(value);
+	} else if (g_str_equal(key, "Phase2")) {
+		g_free(service->phase2);
+		service->phase2 = g_strdup(value);
+	} else if (g_str_equal(key, "Passphrase"))
+		__connman_service_set_passphrase(service, value);
+}
+
+void __connman_service_set_search_domains(struct connman_service *service,
+					char **domains)
+{
+	searchdomain_remove_all(service);
+
+	if (service->domains)
+		g_strfreev(service->domains);
+
+	service->domains = g_strdupv(domains);
+
+	searchdomain_add_all(service);
+}
+
+static void service_complete(struct connman_service *service)
+{
+	reply_pending(service, EIO);
+
+	if (service->connect_reason != CONNMAN_SERVICE_CONNECT_REASON_USER)
+		__connman_service_auto_connect(service->connect_reason);
+
+	g_get_current_time(&service->modified);
+	service_save(service);
+}
+
+static void report_error_cb(void *user_context, bool retry,
+							void *user_data)
+{
+	struct connman_service *service = user_context;
+
+	if (retry)
+		__connman_service_connect(service,
+					CONNMAN_SERVICE_CONNECT_REASON_USER);
+	else {
+		/* It is not relevant to stay on Failure state
+		 * when failing is due to wrong user input */
+		__connman_service_clear_error(service);
+
+		service_complete(service);
+		__connman_connection_update_gateway();
+	}
+}
+
+static int check_wpspin(struct connman_service *service, const char *wpspin)
+{
+	int length;
+	guint i;
+
+	if (!wpspin)
+		return 0;
+
+	length = strlen(wpspin);
+
+	/* If 0, it will mean user wants to use PBC method */
+	if (length == 0) {
+		connman_network_set_string(service->network,
+							"WiFi.PinWPS", NULL);
+		return 0;
+	}
+
+	/* A WPS PIN is always 8 chars length,
+	 * its content is in digit representation.
+	 */
+	if (length != 8)
+		return -ENOKEY;
+
+	for (i = 0; i < 8; i++)
+		if (!isdigit((unsigned char) wpspin[i]))
+			return -ENOKEY;
+
+	connman_network_set_string(service->network, "WiFi.PinWPS", wpspin);
+
+	return 0;
+}
+
+static void request_input_cb(struct connman_service *service,
+			bool values_received,
+			const char *name, int name_len,
+			const char *identity, const char *passphrase,
+			bool wps, const char *wpspin,
+			const char *error, void *user_data)
+{
+	struct connman_device *device;
+	const char *security;
+	int err = 0;
+
+	DBG("RequestInput return, %p", service);
+
+	if (error) {
+		DBG("error: %s", error);
+
+		if (g_strcmp0(error,
+				"net.connman.Agent.Error.Canceled") == 0) {
+			err = -EINVAL;
+
+			if (service->hidden)
+				__connman_service_return_error(service,
+							ECANCELED, user_data);
+			goto done;
+		} else {
+			if (service->hidden)
+				__connman_service_return_error(service,
+							ETIMEDOUT, user_data);
+		}
+	}
+
+	if (service->hidden && name_len > 0 && name_len <= 32) {
+		device = connman_network_get_device(service->network);
+		security = connman_network_get_string(service->network,
+							"WiFi.Security");
+		err = __connman_device_request_hidden_scan(device,
+						name, name_len,
+						identity, passphrase,
+						security, user_data);
+		if (err < 0)
+			__connman_service_return_error(service,	-err,
+							user_data);
+	}
+
+	if (!values_received || service->hidden) {
+		err = -EINVAL;
+		goto done;
+	}
+
+	if (wps && service->network) {
+		err = check_wpspin(service, wpspin);
+		if (err < 0)
+			goto done;
+
+		connman_network_set_bool(service->network, "WiFi.UseWPS", wps);
+	}
+
+	if (identity)
+		__connman_service_set_agent_identity(service, identity);
+
+	if (passphrase)
+		err = __connman_service_set_passphrase(service, passphrase);
+
+ done:
+	if (err >= 0) {
+		/* We forget any previous error. */
+		set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN);
+
+		service->state = CONNMAN_SERVICE_STATE_IDLE;
+
+		__connman_service_connect(service,
+					CONNMAN_SERVICE_CONNECT_REASON_USER);
+
+	} else if (err == -ENOKEY) {
+		__connman_service_indicate_error(service,
+					CONNMAN_SERVICE_ERROR_INVALID_KEY);
+	} else {
+		/* It is not relevant to stay on Failure state
+		 * when failing is due to wrong user input */
+		service->state = CONNMAN_SERVICE_STATE_IDLE;
+
+		if (!service->hidden) {
+			/*
+			 * If there was a real error when requesting
+			 * hidden scan, then that error is returned already
+			 * to the user somewhere above so do not try to
+			 * do this again.
+			 */
+			__connman_service_return_error(service,	-err,
+							user_data);
+		}
+
+		service_complete(service);
+		__connman_connection_update_gateway();
+	}
+}
+
+static void downgrade_connected_services(void)
+{
+	struct connman_service *up_service;
+	GList *list;
+
+	for (list = service_list; list; list = list->next) {
+		up_service = list->data;
+
+		if (!is_connected(up_service))
+			continue;
+
+		if (up_service->state == CONNMAN_SERVICE_STATE_ONLINE)
+			return;
+
+		downgrade_state(up_service);
+	}
+}
+
+static int service_update_preferred_order(struct connman_service *default_service,
+		struct connman_service *new_service,
+		enum connman_service_state new_state)
+{
+	unsigned int *tech_array;
+	int i;
+
+	if (!default_service || default_service == new_service ||
+			default_service->state != new_state)
+		return 0;
+
+	tech_array = connman_setting_get_uint_list("PreferredTechnologies");
+	if (tech_array) {
+
+		for (i = 0; tech_array[i] != 0; i += 1) {
+			if (default_service->type == tech_array[i])
+				return -EALREADY;
+
+			if (new_service->type == tech_array[i]) {
+				switch_default_service(default_service,
+						new_service);
+				__connman_connection_update_gateway();
+				return 0;
+			}
+		}
+	}
+
+	return -EALREADY;
+}
+
+static void single_connected_tech(struct connman_service *allowed)
+{
+	struct connman_service *service;
+	GSList *services = NULL, *list;
+	GList *iter;
+
+	DBG("keeping %p %s", allowed, allowed->path);
+
+	for (iter = service_list; iter; iter = iter->next) {
+		service = iter->data;
+
+		if (!is_connected(service))
+			break;
+
+		if (service == allowed)
+			continue;
+
+		services = g_slist_prepend(services, service);
+	}
+
+	for (list = services; list; list = list->next) {
+		service = list->data;
+
+		DBG("disconnecting %p %s", service, service->path);
+		__connman_service_disconnect(service);
+	}
+
+	g_slist_free(services);
+}
+
+static const char *get_dbus_sender(struct connman_service *service)
+{
+	if (!service->pending)
+		return NULL;
+
+	return dbus_message_get_sender(service->pending);
+}
+
+static int service_indicate_state(struct connman_service *service)
+{
+	enum connman_service_state old_state, new_state;
+	struct connman_service *def_service;
+	enum connman_ipconfig_method method;
+	int result;
+
+	if (!service)
+		return -EINVAL;
+
+	old_state = service->state;
+	new_state = combine_state(service->state_ipv4, service->state_ipv6);
+
+	DBG("service %p old %s - new %s/%s => %s",
+					service,
+					state2string(old_state),
+					state2string(service->state_ipv4),
+					state2string(service->state_ipv6),
+					state2string(new_state));
+
+	if (old_state == new_state)
+		return -EALREADY;
+
+	def_service = __connman_service_get_default();
+
+	if (new_state == CONNMAN_SERVICE_STATE_ONLINE) {
+		result = service_update_preferred_order(def_service,
+				service, new_state);
+		if (result == -EALREADY)
+			return result;
+	}
+
+	if (old_state == CONNMAN_SERVICE_STATE_ONLINE)
+		__connman_notifier_leave_online(service->type);
+
+	if (is_connected_state(service, old_state) &&
+			!is_connected_state(service, new_state))
+		searchdomain_remove_all(service);
+
+	service->state = new_state;
+	state_changed(service);
+
+	switch(new_state) {
+	case CONNMAN_SERVICE_STATE_UNKNOWN:
+
+		break;
+
+	case CONNMAN_SERVICE_STATE_IDLE:
+		if (old_state != CONNMAN_SERVICE_STATE_DISCONNECT)
+			__connman_service_disconnect(service);
+
+		break;
+
+	case CONNMAN_SERVICE_STATE_ASSOCIATION:
+
+		break;
+
+	case CONNMAN_SERVICE_STATE_CONFIGURATION:
+		if (!service->new_service &&
+				__connman_stats_service_register(service) == 0) {
+			/*
+			 * For new services the statistics are updated after
+			 * we have successfully connected.
+			 */
+			__connman_stats_get(service, false,
+						&service->stats.data);
+			__connman_stats_get(service, true,
+						&service->stats_roaming.data);
+		}
+
+		break;
+
+	case CONNMAN_SERVICE_STATE_READY:
+		set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN);
+
+		if (service->new_service &&
+				__connman_stats_service_register(service) == 0) {
+			/*
+			 * This is normally done after configuring state
+			 * but for new service do this after we have connected
+			 * successfully.
+			 */
+			__connman_stats_get(service, false,
+						&service->stats.data);
+			__connman_stats_get(service, true,
+						&service->stats_roaming.data);
+		}
+
+		service->new_service = false;
+
+		default_changed();
+
+		def_service = __connman_service_get_default();
+
+		service_update_preferred_order(def_service, service, new_state);
+
+		__connman_service_set_favorite(service, true);
+
+		reply_pending(service, 0);
+
+		g_get_current_time(&service->modified);
+		service_save(service);
+
+		searchdomain_add_all(service);
+		dns_changed(service);
+		domain_changed(service);
+		proxy_changed(service);
+
+		if (old_state != CONNMAN_SERVICE_STATE_ONLINE)
+			__connman_notifier_connect(service->type);
+
+		if (service->type == CONNMAN_SERVICE_TYPE_WIFI &&
+			connman_network_get_bool(service->network,
+						"WiFi.UseWPS")) {
+			const char *pass;
+
+			pass = connman_network_get_string(service->network,
+							"WiFi.Passphrase");
+
+			__connman_service_set_passphrase(service, pass);
+
+			connman_network_set_bool(service->network,
+							"WiFi.UseWPS", false);
+		}
+
+		method = __connman_ipconfig_get_method(service->ipconfig_ipv6);
+		if (method == CONNMAN_IPCONFIG_METHOD_OFF)
+			__connman_ipconfig_disable_ipv6(
+						service->ipconfig_ipv6);
+
+		if (connman_setting_get_bool("SingleConnectedTechnology"))
+			single_connected_tech(service);
+		else if (service->type != CONNMAN_SERVICE_TYPE_VPN)
+			vpn_auto_connect();
+
+		break;
+
+	case CONNMAN_SERVICE_STATE_ONLINE:
+
+		break;
+
+	case CONNMAN_SERVICE_STATE_DISCONNECT:
+		set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN);
+
+		reply_pending(service, ECONNABORTED);
+
+		def_service = __connman_service_get_default();
+
+		if (!__connman_notifier_is_connected() &&
+			def_service &&
+				def_service->provider)
+			connman_provider_disconnect(def_service->provider);
+
+		default_changed();
+
+		__connman_wispr_stop(service);
+
+		__connman_wpad_stop(service);
+
+		dns_changed(service);
+		domain_changed(service);
+		proxy_changed(service);
+
+		/*
+		 * Previous services which are connected and which states
+		 * are set to online should reset relevantly ipconfig_state
+		 * to ready so wispr/portal will be rerun on those
+		 */
+		downgrade_connected_services();
+
+		__connman_service_auto_connect(CONNMAN_SERVICE_CONNECT_REASON_AUTO);
+		break;
+
+	case CONNMAN_SERVICE_STATE_FAILURE:
+
+		if (service->connect_reason == CONNMAN_SERVICE_CONNECT_REASON_USER &&
+			connman_agent_report_error(service, service->path,
+					error2string(service->error),
+					report_error_cb,
+					get_dbus_sender(service),
+					NULL) == -EINPROGRESS)
+			return 0;
+		service_complete(service);
+
+		break;
+	}
+
+	service_list_sort();
+
+	__connman_connection_update_gateway();
+
+	if ((old_state == CONNMAN_SERVICE_STATE_ONLINE &&
+			new_state != CONNMAN_SERVICE_STATE_READY) ||
+		(old_state == CONNMAN_SERVICE_STATE_READY &&
+			new_state != CONNMAN_SERVICE_STATE_ONLINE)) {
+		__connman_notifier_disconnect(service->type);
+	}
+
+	if (new_state == CONNMAN_SERVICE_STATE_ONLINE) {
+		__connman_notifier_enter_online(service->type);
+		default_changed();
+	}
+
+	return 0;
+}
+
+int __connman_service_indicate_error(struct connman_service *service,
+					enum connman_service_error error)
+{
+	DBG("service %p error %d", service, error);
+
+	if (!service)
+		return -EINVAL;
+
+	if (service->state == CONNMAN_SERVICE_STATE_FAILURE)
+		return -EALREADY;
+
+	set_error(service, error);
+
+	__connman_service_ipconfig_indicate_state(service,
+						CONNMAN_SERVICE_STATE_FAILURE,
+						CONNMAN_IPCONFIG_TYPE_IPV4);
+	__connman_service_ipconfig_indicate_state(service,
+						CONNMAN_SERVICE_STATE_FAILURE,
+						CONNMAN_IPCONFIG_TYPE_IPV6);
+	return 0;
+}
+
+int __connman_service_clear_error(struct connman_service *service)
+{
+	DBusMessage *pending, *provider_pending;
+
+	DBG("service %p", service);
+
+	if (!service)
+		return -EINVAL;
+
+	if (service->state != CONNMAN_SERVICE_STATE_FAILURE)
+		return -EINVAL;
+
+	pending = service->pending;
+	service->pending = NULL;
+	provider_pending = service->provider_pending;
+	service->provider_pending = NULL;
+
+	__connman_service_ipconfig_indicate_state(service,
+						CONNMAN_SERVICE_STATE_IDLE,
+						CONNMAN_IPCONFIG_TYPE_IPV6);
+
+	__connman_service_ipconfig_indicate_state(service,
+						CONNMAN_SERVICE_STATE_IDLE,
+						CONNMAN_IPCONFIG_TYPE_IPV4);
+
+	service->pending = pending;
+	service->provider_pending = provider_pending;
+
+	return 0;
+}
+
+int __connman_service_indicate_default(struct connman_service *service)
+{
+	DBG("service %p state %s", service, state2string(service->state));
+
+	if (!is_connected(service)) {
+		/*
+		 * If service is not yet fully connected, then we must not
+		 * change the default yet. The default gw will be changed
+		 * after the service state is in ready.
+		 */
+		return -EINPROGRESS;
+	}
+
+	default_changed();
+
+	return 0;
+}
+
+enum connman_service_state __connman_service_ipconfig_get_state(
+					struct connman_service *service,
+					enum connman_ipconfig_type type)
+{
+	if (!service)
+		return CONNMAN_SERVICE_STATE_UNKNOWN;
+
+	if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
+		return service->state_ipv4;
+
+	if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
+		return service->state_ipv6;
+
+	return CONNMAN_SERVICE_STATE_UNKNOWN;
+}
+
+static void check_proxy_setup(struct connman_service *service)
+{
+	/*
+	 * We start WPAD if we haven't got a PAC URL from DHCP and
+	 * if our proxy manual configuration is either empty or set
+	 * to AUTO with an empty URL.
+	 */
+
+	if (service->proxy != CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN)
+		goto done;
+
+	if (service->proxy_config != CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN &&
+		(service->proxy_config != CONNMAN_SERVICE_PROXY_METHOD_AUTO ||
+			service->pac))
+		goto done;
+
+	if (__connman_wpad_start(service) < 0) {
+		service->proxy = CONNMAN_SERVICE_PROXY_METHOD_DIRECT;
+		__connman_notifier_proxy_changed(service);
+		goto done;
+	}
+
+	return;
+
+done:
+	__connman_wispr_start(service, CONNMAN_IPCONFIG_TYPE_IPV4);
+}
+
+/*
+ * How many networks are connected at the same time. If more than 1,
+ * then set the rp_filter setting properly (loose mode routing) so that network
+ * connectivity works ok. This is only done for IPv4 networks as IPv6
+ * does not have rp_filter knob.
+ */
+static int connected_networks_count;
+static int original_rp_filter;
+
+static void service_rp_filter(struct connman_service *service,
+				bool connected)
+{
+	enum connman_ipconfig_method method;
+
+	method = __connman_ipconfig_get_method(service->ipconfig_ipv4);
+
+	switch (method) {
+	case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
+	case CONNMAN_IPCONFIG_METHOD_OFF:
+	case CONNMAN_IPCONFIG_METHOD_AUTO:
+		return;
+	case CONNMAN_IPCONFIG_METHOD_FIXED:
+	case CONNMAN_IPCONFIG_METHOD_MANUAL:
+	case CONNMAN_IPCONFIG_METHOD_DHCP:
+		break;
+	}
+
+	if (connected) {
+		if (connected_networks_count == 1) {
+			int filter_value;
+			filter_value = __connman_ipconfig_set_rp_filter();
+			if (filter_value < 0)
+				return;
+
+			original_rp_filter = filter_value;
+		}
+		connected_networks_count++;
+
+	} else {
+		if (connected_networks_count == 2)
+			__connman_ipconfig_unset_rp_filter(original_rp_filter);
+
+		connected_networks_count--;
+		if (connected_networks_count < 0)
+			connected_networks_count = 0;
+	}
+
+	DBG("%s %s ipconfig %p method %d count %d filter %d",
+		connected ? "connected" : "disconnected", service->identifier,
+		service->ipconfig_ipv4, method,
+		connected_networks_count, original_rp_filter);
+}
+
+static gboolean redo_wispr(gpointer user_data)
+{
+	struct connman_service *service = user_data;
+	int refcount = service->refcount - 1;
+
+	connman_service_unref(service);
+	if (refcount == 0) {
+		DBG("Service %p already removed", service);
+		return FALSE;
+	}
+
+	__connman_wispr_start(service, CONNMAN_IPCONFIG_TYPE_IPV6);
+
+	return FALSE;
+}
+
+int __connman_service_online_check_failed(struct connman_service *service,
+					enum connman_ipconfig_type type)
+{
+	DBG("service %p type %d count %d", service, type,
+						service->online_check_count);
+
+	/* currently we only retry IPv6 stuff */
+	if (type == CONNMAN_IPCONFIG_TYPE_IPV4 ||
+			service->online_check_count != 1) {
+		connman_warn("Online check failed for %p %s", service,
+			service->name);
+		return 0;
+	}
+
+	service->online_check_count = 0;
+
+	/*
+	 * We set the timeout to 1 sec so that we have a chance to get
+	 * necessary IPv6 router advertisement messages that might have
+	 * DNS data etc.
+	 */
+	g_timeout_add_seconds(1, redo_wispr, connman_service_ref(service));
+
+	return EAGAIN;
+}
+
+int __connman_service_ipconfig_indicate_state(struct connman_service *service,
+					enum connman_service_state new_state,
+					enum connman_ipconfig_type type)
+{
+	struct connman_ipconfig *ipconfig = NULL;
+	enum connman_service_state old_state;
+	enum connman_ipconfig_method method;
+
+	if (!service)
+		return -EINVAL;
+
+	switch (type) {
+	case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
+	case CONNMAN_IPCONFIG_TYPE_ALL:
+		return -EINVAL;
+
+	case CONNMAN_IPCONFIG_TYPE_IPV4:
+		old_state = service->state_ipv4;
+		ipconfig = service->ipconfig_ipv4;
+
+		break;
+
+	case CONNMAN_IPCONFIG_TYPE_IPV6:
+		old_state = service->state_ipv6;
+		ipconfig = service->ipconfig_ipv6;
+
+		break;
+	}
+
+	if (!ipconfig)
+		return -EINVAL;
+
+	method = __connman_ipconfig_get_method(ipconfig);
+
+	switch (method) {
+	case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
+	case CONNMAN_IPCONFIG_METHOD_OFF:
+		if (new_state != CONNMAN_SERVICE_STATE_IDLE)
+			connman_warn("ipconfig state %d ipconfig method %d",
+				new_state, method);
+
+		new_state = CONNMAN_SERVICE_STATE_IDLE;
+		break;
+
+	case CONNMAN_IPCONFIG_METHOD_FIXED:
+	case CONNMAN_IPCONFIG_METHOD_MANUAL:
+	case CONNMAN_IPCONFIG_METHOD_DHCP:
+	case CONNMAN_IPCONFIG_METHOD_AUTO:
+		break;
+
+	}
+
+	/* Any change? */
+	if (old_state == new_state)
+		return -EALREADY;
+
+	DBG("service %p (%s) old state %d (%s) new state %d (%s) type %d (%s)",
+		service, service ? service->identifier : NULL,
+		old_state, state2string(old_state),
+		new_state, state2string(new_state),
+		type, __connman_ipconfig_type2string(type));
+
+	switch (new_state) {
+	case CONNMAN_SERVICE_STATE_UNKNOWN:
+	case CONNMAN_SERVICE_STATE_IDLE:
+	case CONNMAN_SERVICE_STATE_ASSOCIATION:
+		break;
+	case CONNMAN_SERVICE_STATE_CONFIGURATION:
+		__connman_ipconfig_enable(ipconfig);
+		break;
+	case CONNMAN_SERVICE_STATE_READY:
+		if (type == CONNMAN_IPCONFIG_TYPE_IPV4) {
+			check_proxy_setup(service);
+			service_rp_filter(service, true);
+		} else {
+			service->online_check_count = 1;
+			__connman_wispr_start(service, type);
+		}
+		break;
+	case CONNMAN_SERVICE_STATE_ONLINE:
+		break;
+	case CONNMAN_SERVICE_STATE_DISCONNECT:
+		if (service->state == CONNMAN_SERVICE_STATE_IDLE)
+			return -EINVAL;
+
+		if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
+			service_rp_filter(service, false);
+
+		break;
+	case CONNMAN_SERVICE_STATE_FAILURE:
+		break;
+	}
+
+	if (is_connected_state(service, old_state) &&
+			!is_connected_state(service, new_state))
+		nameserver_remove_all(service, type);
+
+	if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
+		service->state_ipv4 = new_state;
+	else
+		service->state_ipv6 = new_state;
+
+	if (!is_connected_state(service, old_state) &&
+			is_connected_state(service, new_state))
+		nameserver_add_all(service, type);
+
+	__connman_timeserver_sync(service);
+
+	return service_indicate_state(service);
+}
+
+static bool prepare_network(struct connman_service *service)
+{
+	enum connman_network_type type;
+	unsigned int ssid_len;
+
+	type = connman_network_get_type(service->network);
+
+	switch (type) {
+	case CONNMAN_NETWORK_TYPE_UNKNOWN:
+	case CONNMAN_NETWORK_TYPE_VENDOR:
+		return false;
+	case CONNMAN_NETWORK_TYPE_WIFI:
+		if (!connman_network_get_blob(service->network, "WiFi.SSID",
+						&ssid_len))
+			return false;
+
+		if (service->passphrase)
+			connman_network_set_string(service->network,
+				"WiFi.Passphrase", service->passphrase);
+		break;
+	case CONNMAN_NETWORK_TYPE_LOWPAN:
+	case CONNMAN_NETWORK_TYPE_ETHERNET:
+	case CONNMAN_NETWORK_TYPE_GADGET:
+	case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
+	case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
+	case CONNMAN_NETWORK_TYPE_CELLULAR:
+		break;
+	}
+
+	return true;
+}
+
+static void prepare_8021x(struct connman_service *service)
+{
+	if (service->eap)
+		connman_network_set_string(service->network, "WiFi.EAP",
+								service->eap);
+
+	if (service->identity)
+		connman_network_set_string(service->network, "WiFi.Identity",
+							service->identity);
+
+	if (service->ca_cert_file)
+		connman_network_set_string(service->network, "WiFi.CACertFile",
+							service->ca_cert_file);
+
+	if (service->client_cert_file)
+		connman_network_set_string(service->network,
+						"WiFi.ClientCertFile",
+						service->client_cert_file);
+
+	if (service->private_key_file)
+		connman_network_set_string(service->network,
+						"WiFi.PrivateKeyFile",
+						service->private_key_file);
+
+	if (service->private_key_passphrase)
+		connman_network_set_string(service->network,
+					"WiFi.PrivateKeyPassphrase",
+					service->private_key_passphrase);
+
+	if (service->phase2)
+		connman_network_set_string(service->network, "WiFi.Phase2",
+							service->phase2);
+}
+
+static int service_connect(struct connman_service *service)
+{
+	int err;
+
+	if (service->hidden)
+		return -EPERM;
+
+	switch (service->type) {
+	case CONNMAN_SERVICE_TYPE_UNKNOWN:
+	case CONNMAN_SERVICE_TYPE_SYSTEM:
+	case CONNMAN_SERVICE_TYPE_GPS:
+	case CONNMAN_SERVICE_TYPE_P2P:
+		return -EINVAL;
+	case CONNMAN_SERVICE_TYPE_ETHERNET:
+	case CONNMAN_SERVICE_TYPE_GADGET:
+	case CONNMAN_SERVICE_TYPE_BLUETOOTH:
+	case CONNMAN_SERVICE_TYPE_CELLULAR:
+	case CONNMAN_SERVICE_TYPE_VPN:
+	case CONNMAN_SERVICE_TYPE_LOWPAN:
+		break;
+	case CONNMAN_SERVICE_TYPE_WIFI:
+		switch (service->security) {
+		case CONNMAN_SERVICE_SECURITY_UNKNOWN:
+		case CONNMAN_SERVICE_SECURITY_NONE:
+			break;
+		case CONNMAN_SERVICE_SECURITY_WEP:
+		case CONNMAN_SERVICE_SECURITY_PSK:
+		case CONNMAN_SERVICE_SECURITY_WPA:
+		case CONNMAN_SERVICE_SECURITY_RSN:
+			if (service->error == CONNMAN_SERVICE_ERROR_INVALID_KEY)
+				return -ENOKEY;
+
+			if (!service->passphrase) {
+				if (!service->network)
+					return -EOPNOTSUPP;
+
+				if (!service->wps ||
+					!connman_network_get_bool(service->network, "WiFi.UseWPS"))
+					return -ENOKEY;
+			}
+			break;
+
+		case CONNMAN_SERVICE_SECURITY_8021X:
+			if (!service->eap)
+				return -EINVAL;
+
+			/*
+			 * never request credentials if using EAP-TLS
+			 * (EAP-TLS networks need to be fully provisioned)
+			 */
+			if (g_str_equal(service->eap, "tls"))
+				break;
+
+			/*
+			 * Return -ENOKEY if either identity or passphrase is
+			 * missing. Agent provided credentials can be used as
+			 * fallback if needed.
+			 */
+			if (((!service->identity &&
+					!service->agent_identity) ||
+					!service->passphrase) ||
+					service->error == CONNMAN_SERVICE_ERROR_INVALID_KEY)
+				return -ENOKEY;
+
+			break;
+		}
+		break;
+	}
+
+	if (service->network) {
+		if (!prepare_network(service))
+			return -EINVAL;
+
+		switch (service->security) {
+		case CONNMAN_SERVICE_SECURITY_UNKNOWN:
+		case CONNMAN_SERVICE_SECURITY_NONE:
+		case CONNMAN_SERVICE_SECURITY_WEP:
+		case CONNMAN_SERVICE_SECURITY_PSK:
+		case CONNMAN_SERVICE_SECURITY_WPA:
+		case CONNMAN_SERVICE_SECURITY_RSN:
+			break;
+		case CONNMAN_SERVICE_SECURITY_8021X:
+			prepare_8021x(service);
+			break;
+		}
+
+		if (__connman_stats_service_register(service) == 0) {
+			__connman_stats_get(service, false,
+						&service->stats.data);
+			__connman_stats_get(service, true,
+						&service->stats_roaming.data);
+		}
+
+		if (service->ipconfig_ipv4)
+			__connman_ipconfig_enable(service->ipconfig_ipv4);
+		if (service->ipconfig_ipv6)
+			__connman_ipconfig_enable(service->ipconfig_ipv6);
+
+		err = __connman_network_connect(service->network);
+	} else if (service->type == CONNMAN_SERVICE_TYPE_VPN &&
+					service->provider)
+		err = __connman_provider_connect(service->provider);
+	else
+		return -EOPNOTSUPP;
+
+	if (err < 0) {
+		if (err != -EINPROGRESS) {
+			__connman_ipconfig_disable(service->ipconfig_ipv4);
+			__connman_ipconfig_disable(service->ipconfig_ipv6);
+			__connman_stats_service_unregister(service);
+		}
+	}
+
+	return err;
+}
+
+int connman_service_connect(struct connman_service *service,
+			enum connman_service_connect_reason reason)
+{
+	set_error(service, CONNMAN_SERVICE_ERROR_UNKNOWN);
+    service->ignore = FALSE;
+
+	return __connman_service_connect(service, reason);
+}
+
+int connman_service_disconnect(struct connman_service *service)
+{
+	reply_pending(service, ECONNABORTED);
+	service->ignore = TRUE;
+
+	return __connman_service_disconnect(service);
+}
+
+int __connman_service_connect(struct connman_service *service,
+			enum connman_service_connect_reason reason)
+{
+	int err;
+
+	DBG("service %p state %s connect reason %s -> %s",
+		service, state2string(service->state),
+		reason2string(service->connect_reason),
+		reason2string(reason));
+
+	if (is_connected(service))
+		return -EISCONN;
+
+	if (is_connecting(service))
+		return -EALREADY;
+
+	switch (service->type) {
+	case CONNMAN_SERVICE_TYPE_UNKNOWN:
+	case CONNMAN_SERVICE_TYPE_SYSTEM:
+	case CONNMAN_SERVICE_TYPE_GPS:
+	case CONNMAN_SERVICE_TYPE_P2P:
+		DBG("service %p Bad service type \"%s\"", service, __connman_service_type2string(service->type));
+		return -EINVAL;
+
+	case CONNMAN_SERVICE_TYPE_ETHERNET:
+	case CONNMAN_SERVICE_TYPE_GADGET:
+	case CONNMAN_SERVICE_TYPE_BLUETOOTH:
+	case CONNMAN_SERVICE_TYPE_CELLULAR:
+	case CONNMAN_SERVICE_TYPE_VPN:
+	case CONNMAN_SERVICE_TYPE_WIFI:
+		break;
+	}
+
+	if (!is_ipconfig_usable(service))
+		return -ENOLINK;
+
+	__connman_service_clear_error(service);
+
+	err = service_connect(service);
+
+	service->connect_reason = reason;
+
+	if (err >= 0)
+		return 0;
+
+	if (err == -EINPROGRESS) {
+		if (service->timeout == 0)
+			service->timeout = g_timeout_add_seconds(
+				CONNECT_TIMEOUT, connect_timeout, service);
+
+		return -EINPROGRESS;
+	}
+
+	if (service->network)
+		__connman_network_disconnect(service->network, FALSE);
+	else if (service->type == CONNMAN_SERVICE_TYPE_VPN &&
+				service->provider)
+			connman_provider_disconnect(service->provider);
+
+	if (service->connect_reason == CONNMAN_SERVICE_CONNECT_REASON_USER) {
+		if (err == -ENOKEY || err == -EPERM) {
+			err = __connman_service_needs_input(service);
+		} else {
+			reply_pending(service, -err);
+		}
+	}
+
+	return err;
+}
+
+int __connman_service_needs_input(struct connman_service *service)
+{
+	int err;
+	DBusMessage *pending = NULL;
+
+	DBG("service %p state %s", service, state2string(service->state));
+
+	/*
+	 * We steal the reply here. The idea is that the
+	 * connecting client will see the connection status
+	 * after the real hidden network is connected or
+	 * connection failed.
+	 */
+	if (service->hidden) {
+		pending = service->pending;
+		service->pending = NULL;
+	}
+
+	err = __connman_agent_request_passphrase_input(service,
+            request_input_cb,
+			get_dbus_sender(service),
+            pending);
+
+	DBG("service %p state %s err %d", service, state2string(service->state), err);
+
+	if (service->hidden && err != -EINPROGRESS)
+		service->pending = pending;
+
+	if (err && (err != -EINPROGRESS)) {
+		reply_pending(service, -err);
+	}
+
+	return err;
+}
+
+int __connman_service_disconnect(struct connman_service *service)
+{
+	int err;
+
+	DBG("service %p", service);
+
+	service->connect_reason = CONNMAN_SERVICE_CONNECT_REASON_NONE;
+	service->proxy = CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN;
+
+	connman_agent_cancel(service);
+
+	reply_pending(service, ECONNABORTED);
+
+	if (service->network) {
+		err = __connman_network_disconnect(service->network, service->ignore);
+	} else if (service->type == CONNMAN_SERVICE_TYPE_VPN &&
+					service->provider)
+		err = connman_provider_disconnect(service->provider);
+	else
+		return -EOPNOTSUPP;
+
+	if (err < 0 && err != -EINPROGRESS)
+		return err;
+
+	__connman_6to4_remove(service->ipconfig_ipv4);
+
+	if (service->ipconfig_ipv4)
+		__connman_ipconfig_set_proxy_autoconfig(service->ipconfig_ipv4,
+							NULL);
+	else
+		__connman_ipconfig_set_proxy_autoconfig(service->ipconfig_ipv6,
+							NULL);
+
+	__connman_ipconfig_address_remove(service->ipconfig_ipv4);
+	settings_changed(service, service->ipconfig_ipv4);
+
+	__connman_ipconfig_address_remove(service->ipconfig_ipv6);
+	settings_changed(service, service->ipconfig_ipv6);
+
+	__connman_ipconfig_disable(service->ipconfig_ipv4);
+	__connman_ipconfig_disable(service->ipconfig_ipv6);
+
+	__connman_stats_service_unregister(service);
+
+	return err;
+}
+
+int __connman_service_disconnect_all(void)
+{
+	struct connman_service *service;
+	GSList *services = NULL, *list;
+	GList *iter;
+
+	DBG("");
+
+	for (iter = service_list; iter; iter = iter->next) {
+		service = iter->data;
+
+		if (!is_connected(service))
+			break;
+
+		services = g_slist_prepend(services, service);
+	}
+
+	for (list = services; list; list = list->next) {
+		struct connman_service *service = list->data;
+
+		service->ignore = true;
+
+		__connman_service_disconnect(service);
+	}
+
+	g_slist_free(services);
+
+	return 0;
+}
+
+/**
+ * lookup_by_identifier:
+ * @identifier: service identifier
+ *
+ * Look up a service by identifier (reference count will not be increased)
+ */
+static struct connman_service *lookup_by_identifier(const char *identifier)
+{
+	return g_hash_table_lookup(service_hash, identifier);
+}
+
+struct provision_user_data {
+	const char *ident;
+	int ret;
+};
+
+static void provision_changed(gpointer value, gpointer user_data)
+{
+	struct connman_service *service = value;
+	struct provision_user_data *data = user_data;
+	const char *path = data->ident;
+	int ret;
+
+	ret = __connman_config_provision_service_ident(service, path,
+			service->config_file, service->config_entry);
+	if (ret > 0)
+		data->ret = ret;
+}
+
+int __connman_service_provision_changed(const char *ident)
+{
+	struct provision_user_data data = {
+		.ident = ident,
+		.ret = 0
+	};
+
+	g_list_foreach(service_list, provision_changed, (void *)&data);
+
+	/*
+	 * Because the provision_changed() might have set some services
+	 * as favorite, we must sort the sequence now.
+	 */
+	if (services_dirty) {
+		services_dirty = false;
+
+		service_list_sort();
+
+		__connman_connection_update_gateway();
+	}
+
+	return data.ret;
+}
+
+void __connman_service_set_config(struct connman_service *service,
+				const char *file_id, const char *entry)
+{
+	if (!service)
+		return;
+
+	g_free(service->config_file);
+	service->config_file = g_strdup(file_id);
+
+	g_free(service->config_entry);
+	service->config_entry = g_strdup(entry);
+}
+
+/**
+ * __connman_service_get:
+ * @identifier: service identifier
+ *
+ * Look up a service by identifier or create a new one if not found
+ */
+static struct connman_service *service_get(const char *identifier)
+{
+	struct connman_service *service;
+
+	service = g_hash_table_lookup(service_hash, identifier);
+	if (service) {
+		connman_service_ref(service);
+		return service;
+	}
+
+	service = connman_service_create();
+	if (!service)
+		return NULL;
+
+	DBG("service %p", service);
+
+	service->identifier = g_strdup(identifier);
+
+	service_list = g_list_insert_sorted(service_list, service,
+						service_compare);
+
+	g_hash_table_insert(service_hash, service->identifier, service);
+
+	return service;
+}
+
+static int service_register(struct connman_service *service)
+{
+	DBG("service %p", service);
+
+	if (service->path)
+		return -EALREADY;
+
+	service->path = g_strdup_printf("%s/service/%s", CONNMAN_PATH,
+						service->identifier);
+
+	DBG("path %s", service->path);
+
+	if (__connman_config_provision_service(service) < 0)
+		service_load(service);
+
+	g_dbus_register_interface(connection, service->path,
+					CONNMAN_SERVICE_INTERFACE,
+					service_methods, service_signals,
+							NULL, service, NULL);
+
+	service_list_sort();
+
+	__connman_connection_update_gateway();
+
+	return 0;
+}
+
+static void service_up(struct connman_ipconfig *ipconfig,
+		const char *ifname)
+{
+	struct connman_service *service = __connman_ipconfig_get_data(ipconfig);
+
+	DBG("%s up", ifname);
+
+	link_changed(service);
+
+	service->stats.valid = false;
+	service->stats_roaming.valid = false;
+}
+
+static void service_down(struct connman_ipconfig *ipconfig,
+			const char *ifname)
+{
+	DBG("%s down", ifname);
+}
+
+static void service_lower_up(struct connman_ipconfig *ipconfig,
+			const char *ifname)
+{
+	struct connman_service *service = __connman_ipconfig_get_data(ipconfig);
+
+	DBG("%s lower up", ifname);
+
+	stats_start(service);
+}
+
+static void service_lower_down(struct connman_ipconfig *ipconfig,
+			const char *ifname)
+{
+	struct connman_service *service = __connman_ipconfig_get_data(ipconfig);
+
+	DBG("%s lower down", ifname);
+
+	if (!is_idle_state(service, service->state_ipv4))
+		__connman_ipconfig_disable(service->ipconfig_ipv4);
+
+	if (!is_idle_state(service, service->state_ipv6))
+		__connman_ipconfig_disable(service->ipconfig_ipv6);
+
+	stats_stop(service);
+	service_save(service);
+}
+
+static void service_ip_bound(struct connman_ipconfig *ipconfig,
+			const char *ifname)
+{
+	struct connman_service *service = __connman_ipconfig_get_data(ipconfig);
+	enum connman_ipconfig_method method = CONNMAN_IPCONFIG_METHOD_UNKNOWN;
+	enum connman_ipconfig_type type = CONNMAN_IPCONFIG_TYPE_UNKNOWN;
+
+	DBG("%s ip bound", ifname);
+
+	type = __connman_ipconfig_get_config_type(ipconfig);
+	method = __connman_ipconfig_get_method(ipconfig);
+
+	DBG("service %p ipconfig %p type %d method %d", service, ipconfig,
+							type, method);
+
+	if (type == CONNMAN_IPCONFIG_TYPE_IPV6 &&
+			method == CONNMAN_IPCONFIG_METHOD_AUTO)
+		__connman_service_ipconfig_indicate_state(service,
+						CONNMAN_SERVICE_STATE_READY,
+						CONNMAN_IPCONFIG_TYPE_IPV6);
+
+	settings_changed(service, ipconfig);
+}
+
+static void service_ip_release(struct connman_ipconfig *ipconfig,
+			const char *ifname)
+{
+	struct connman_service *service = __connman_ipconfig_get_data(ipconfig);
+	enum connman_ipconfig_method method = CONNMAN_IPCONFIG_METHOD_UNKNOWN;
+	enum connman_ipconfig_type type = CONNMAN_IPCONFIG_TYPE_UNKNOWN;
+
+	DBG("%s ip release", ifname);
+
+	type = __connman_ipconfig_get_config_type(ipconfig);
+	method = __connman_ipconfig_get_method(ipconfig);
+
+	DBG("service %p ipconfig %p type %d method %d", service, ipconfig,
+							type, method);
+
+	if (type == CONNMAN_IPCONFIG_TYPE_IPV6 &&
+			method == CONNMAN_IPCONFIG_METHOD_OFF)
+		__connman_service_ipconfig_indicate_state(service,
+					CONNMAN_SERVICE_STATE_DISCONNECT,
+					CONNMAN_IPCONFIG_TYPE_IPV6);
+
+	if (type == CONNMAN_IPCONFIG_TYPE_IPV4 &&
+			method == CONNMAN_IPCONFIG_METHOD_OFF)
+		__connman_service_ipconfig_indicate_state(service,
+					CONNMAN_SERVICE_STATE_DISCONNECT,
+					CONNMAN_IPCONFIG_TYPE_IPV4);
+
+	settings_changed(service, ipconfig);
+}
+
+static void service_route_changed(struct connman_ipconfig *ipconfig,
+				const char *ifname)
+{
+	struct connman_service *service = __connman_ipconfig_get_data(ipconfig);
+
+	DBG("%s route changed", ifname);
+
+	settings_changed(service, ipconfig);
+}
+
+static const struct connman_ipconfig_ops service_ops = {
+	.up		= service_up,
+	.down		= service_down,
+	.lower_up	= service_lower_up,
+	.lower_down	= service_lower_down,
+	.ip_bound	= service_ip_bound,
+	.ip_release	= service_ip_release,
+	.route_set	= service_route_changed,
+	.route_unset	= service_route_changed,
+};
+
+static struct connman_ipconfig *create_ip4config(struct connman_service *service,
+		int index, enum connman_ipconfig_method method)
+{
+	struct connman_ipconfig *ipconfig_ipv4;
+
+	ipconfig_ipv4 = __connman_ipconfig_create(index,
+						CONNMAN_IPCONFIG_TYPE_IPV4);
+	if (!ipconfig_ipv4)
+		return NULL;
+
+	__connman_ipconfig_set_method(ipconfig_ipv4, method);
+
+	__connman_ipconfig_set_data(ipconfig_ipv4, service);
+
+	__connman_ipconfig_set_ops(ipconfig_ipv4, &service_ops);
+
+	return ipconfig_ipv4;
+}
+
+static struct connman_ipconfig *create_ip6config(struct connman_service *service,
+		int index)
+{
+	struct connman_ipconfig *ipconfig_ipv6;
+
+	ipconfig_ipv6 = __connman_ipconfig_create(index,
+						CONNMAN_IPCONFIG_TYPE_IPV6);
+	if (!ipconfig_ipv6)
+		return NULL;
+
+	__connman_ipconfig_set_data(ipconfig_ipv6, service);
+
+	__connman_ipconfig_set_ops(ipconfig_ipv6, &service_ops);
+
+	return ipconfig_ipv6;
+}
+
+void __connman_service_read_ip4config(struct connman_service *service)
+{
+	GKeyFile *keyfile;
+
+	if (!service->ipconfig_ipv4)
+		return;
+
+	keyfile = connman_storage_load_service(service->identifier);
+	if (!keyfile)
+		return;
+
+	__connman_ipconfig_load(service->ipconfig_ipv4, keyfile,
+				service->identifier, "IPv4.");
+
+	g_key_file_free(keyfile);
+}
+
+void connman_service_create_ip4config(struct connman_service *service,
+					int index)
+{
+	DBG("ipv4 %p", service->ipconfig_ipv4);
+
+	if (service->ipconfig_ipv4)
+		return;
+
+	service->ipconfig_ipv4 = create_ip4config(service, index,
+			CONNMAN_IPCONFIG_METHOD_DHCP);
+	__connman_service_read_ip4config(service);
+}
+
+void __connman_service_read_ip6config(struct connman_service *service)
+{
+	GKeyFile *keyfile;
+
+	if (!service->ipconfig_ipv6)
+		return;
+
+	keyfile = connman_storage_load_service(service->identifier);
+	if (!keyfile)
+		return;
+
+	__connman_ipconfig_load(service->ipconfig_ipv6, keyfile,
+				service->identifier, "IPv6.");
+
+	g_key_file_free(keyfile);
+}
+
+void connman_service_create_ip6config(struct connman_service *service,
+								int index)
+{
+	DBG("ipv6 %p", service->ipconfig_ipv6);
+
+	if (service->ipconfig_ipv6)
+		return;
+
+	service->ipconfig_ipv6 = create_ip6config(service, index);
+
+	__connman_service_read_ip6config(service);
+}
+
+/**
+ * connman_service_lookup_from_network:
+ * @network: network structure
+ *
+ * Look up a service by network (reference count will not be increased)
+ */
+struct connman_service *connman_service_lookup_from_network(struct connman_network *network)
+{
+	struct connman_service *service;
+	const char *ident, *group;
+	char *name;
+
+	if (!network)
+		return NULL;
+
+	ident = __connman_network_get_ident(network);
+	if (!ident) {
+		DBG("network %p is missing ident", network);
+		return NULL;
+	}
+
+	group = connman_network_get_group(network);
+	if (!group) {
+		DBG("network %p is missing group", network);
+		return NULL;
+	}
+
+	name = g_strdup_printf("%s_%s_%s",
+			__connman_network_get_type(network), ident, group);
+	service = lookup_by_identifier(name);
+
+	DBG("service_name %s",name);
+	DBG("service %p", service);
+
+	g_free(name);
+
+	return service;
+}
+
+struct connman_service *__connman_service_lookup_from_index(int index)
+{
+	struct connman_service *service;
+	GList *list;
+
+	for (list = service_list; list; list = list->next) {
+		service = list->data;
+
+		if (__connman_ipconfig_is_usable(service->ipconfig_ipv4) &&
+			__connman_ipconfig_get_index(service->ipconfig_ipv4) == index)
+			return service;
+
+		if (__connman_ipconfig_is_usable(service->ipconfig_ipv6) &&
+			__connman_ipconfig_get_index(service->ipconfig_ipv6) == index)
+			return service;
+	}
+
+	return NULL;
+}
+
+struct connman_service *__connman_service_lookup_from_ident(const char *identifier)
+{
+	return lookup_by_identifier(identifier);
+}
+
+const char *__connman_service_get_ident(struct connman_service *service)
+{
+	return service->identifier;
+}
+
+const char *__connman_service_get_path(struct connman_service *service)
+{
+	return service->path;
+}
+
+const char *__connman_service_get_name(struct connman_service *service)
+{
+	return service->name;
+}
+
+enum connman_service_state __connman_service_get_state(struct connman_service *service)
+{
+	return service->state;
+}
+
+unsigned int __connman_service_get_order(struct connman_service *service)
+{
+	unsigned int order = 0;
+
+	if (!service)
+		return 0;
+
+	service->order = 0;
+
+	if (!service->favorite)
+		return 0;
+
+	if (service == service_list->data)
+		order = 1;
+
+	if (service->type == CONNMAN_SERVICE_TYPE_VPN &&
+			!service->do_split_routing) {
+		service->order = 10;
+		order = 10;
+	}
+
+	DBG("service %p name %s order %d split %d", service, service->name,
+		order, service->do_split_routing);
+
+	return order;
+}
+
+void __connman_service_update_ordering(void)
+{
+	if (service_list && service_list->next)
+		service_list = g_list_sort(service_list, service_compare);
+}
+
+static enum connman_service_type convert_network_type(struct connman_network *network)
+{
+	enum connman_network_type type = connman_network_get_type(network);
+
+	switch (type) {
+	case CONNMAN_NETWORK_TYPE_UNKNOWN:
+	case CONNMAN_NETWORK_TYPE_VENDOR:
+		break;
+	case CONNMAN_NETWORK_TYPE_ETHERNET:
+		return CONNMAN_SERVICE_TYPE_ETHERNET;
+	case CONNMAN_NETWORK_TYPE_WIFI:
+		return CONNMAN_SERVICE_TYPE_WIFI;
+	case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
+	case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
+		return CONNMAN_SERVICE_TYPE_BLUETOOTH;
+	case CONNMAN_NETWORK_TYPE_CELLULAR:
+		return CONNMAN_SERVICE_TYPE_CELLULAR;
+	case CONNMAN_NETWORK_TYPE_GADGET:
+		return CONNMAN_SERVICE_TYPE_GADGET;
+	case CONNMAN_NETWORK_TYPE_LOWPAN:
+		return CONNMAN_SERVICE_TYPE_LOWPAN;
+	}
+
+	return CONNMAN_SERVICE_TYPE_UNKNOWN;
+}
+
+static enum connman_service_security convert_wifi_security(const char *security)
+{
+	if (!security)
+		return CONNMAN_SERVICE_SECURITY_UNKNOWN;
+	else if (g_str_equal(security, "none"))
+		return CONNMAN_SERVICE_SECURITY_NONE;
+	else if (g_str_equal(security, "wep"))
+		return CONNMAN_SERVICE_SECURITY_WEP;
+	else if (g_str_equal(security, "psk"))
+		return CONNMAN_SERVICE_SECURITY_PSK;
+	else if (g_str_equal(security, "ieee8021x"))
+		return CONNMAN_SERVICE_SECURITY_8021X;
+	else if (g_str_equal(security, "wpa"))
+		return CONNMAN_SERVICE_SECURITY_WPA;
+	else if (g_str_equal(security, "rsn"))
+		return CONNMAN_SERVICE_SECURITY_RSN;
+	else
+		return CONNMAN_SERVICE_SECURITY_UNKNOWN;
+}
+
+static void update_from_network(struct connman_service *service,
+					struct connman_network *network)
+{
+	uint8_t strength = service->strength;
+	const char *str;
+
+	DBG("service %p network %p", service, network);
+
+	if (is_connected(service))
+		return;
+
+	if (is_connecting(service))
+		return;
+
+	str = connman_network_get_string(network, "Name");
+	if (str) {
+		g_free(service->name);
+		service->name = g_strdup(str);
+		service->hidden = false;
+	} else {
+		g_free(service->name);
+		service->name = NULL;
+		service->hidden = true;
+	}
+
+	service->strength = connman_network_get_strength(network);
+	service->roaming = connman_network_get_bool(network, "Roaming");
+
+	if (service->strength == 0) {
+		/*
+		 * Filter out 0-values; it's unclear what they mean
+		 * and they cause anomalous sorting of the priority list.
+		 */
+		service->strength = strength;
+	}
+
+	str = connman_network_get_string(network, "WiFi.Security");
+	service->security = convert_wifi_security(str);
+
+	if (service->type == CONNMAN_SERVICE_TYPE_WIFI)
+		service->wps = connman_network_get_bool(network, "WiFi.WPS");
+
+	if (service->strength > strength && service->network) {
+		connman_network_unref(service->network);
+		service->network = connman_network_ref(network);
+
+		strength_changed(service);
+	}
+
+	if (!service->network)
+		service->network = connman_network_ref(network);
+
+	service_list_sort();
+}
+
+/**
+ * __connman_service_create_from_network:
+ * @network: network structure
+ *
+ * Look up service by network and if not found, create one
+ */
+struct connman_service * __connman_service_create_from_network(struct connman_network *network)
+{
+	struct connman_service *service;
+	struct connman_device *device;
+	const char *ident, *group;
+	char *name;
+	unsigned int *auto_connect_types;
+	int i, index;
+
+	DBG("network %p", network);
+
+	if (!network)
+		return NULL;
+
+	ident = __connman_network_get_ident(network);
+	if (!ident)
+		return NULL;
+
+	group = connman_network_get_group(network);
+	if (!group)
+		return NULL;
+
+	name = g_strdup_printf("%s_%s_%s",
+			__connman_network_get_type(network), ident, group);
+	service = service_get(name);
+	g_free(name);
+
+	if (!service)
+		return NULL;
+
+	if (__connman_network_get_weakness(network))
+		return service;
+
+	if (service->path) {
+		update_from_network(service, network);
+		__connman_connection_update_gateway();
+		return service;
+	}
+
+	service->type = convert_network_type(network);
+
+	auto_connect_types = connman_setting_get_uint_list("DefaultAutoConnectTechnologies");
+	service->autoconnect = false;
+	for (i = 0; auto_connect_types &&
+		     auto_connect_types[i] != 0; i++) {
+		if (service->type == auto_connect_types[i]) {
+			service->autoconnect = true;
+			break;
+		}
+	}
+
+	switch (service->type) {
+	case CONNMAN_SERVICE_TYPE_UNKNOWN:
+	case CONNMAN_SERVICE_TYPE_SYSTEM:
+	case CONNMAN_SERVICE_TYPE_BLUETOOTH:
+	case CONNMAN_SERVICE_TYPE_GPS:
+	case CONNMAN_SERVICE_TYPE_VPN:
+	case CONNMAN_SERVICE_TYPE_GADGET:
+	case CONNMAN_SERVICE_TYPE_WIFI:
+	case CONNMAN_SERVICE_TYPE_CELLULAR:
+	case CONNMAN_SERVICE_TYPE_P2P:
+	case CONNMAN_SERVICE_TYPE_LOWPAN:
+		break;
+	case CONNMAN_SERVICE_TYPE_ETHERNET:
+		service->favorite = true;
+		break;
+	}
+
+	service->state_ipv4 = service->state_ipv6 = CONNMAN_SERVICE_STATE_IDLE;
+	service->state = combine_state(service->state_ipv4, service->state_ipv6);
+
+	update_from_network(service, network);
+
+	index = connman_network_get_index(network);
+
+	if (!service->ipconfig_ipv4)
+		service->ipconfig_ipv4 = create_ip4config(service, index,
+				CONNMAN_IPCONFIG_METHOD_DHCP);
+
+	if (!service->ipconfig_ipv6)
+		service->ipconfig_ipv6 = create_ip6config(service, index);
+
+	service_register(service);
+
+	if (service->favorite) {
+		device = connman_network_get_device(service->network);
+		if (device && !connman_device_get_scanning(device)) {
+
+			switch (service->type) {
+			case CONNMAN_SERVICE_TYPE_UNKNOWN:
+			case CONNMAN_SERVICE_TYPE_SYSTEM:
+			case CONNMAN_SERVICE_TYPE_P2P:
+				break;
+
+			case CONNMAN_SERVICE_TYPE_GADGET:
+			case CONNMAN_SERVICE_TYPE_ETHERNET:
+				if (service->autoconnect) {
+					__connman_service_connect(service,
+						CONNMAN_SERVICE_CONNECT_REASON_AUTO);
+					break;
+				}
+
+				/* fall through */
+			case CONNMAN_SERVICE_TYPE_BLUETOOTH:
+			case CONNMAN_SERVICE_TYPE_GPS:
+			case CONNMAN_SERVICE_TYPE_VPN:
+			case CONNMAN_SERVICE_TYPE_WIFI:
+			case CONNMAN_SERVICE_TYPE_CELLULAR:
+				__connman_service_auto_connect(CONNMAN_SERVICE_CONNECT_REASON_AUTO);
+				break;
+			}
+		}
+	}
+
+	__connman_notifier_service_add(service, service->name);
+	service_schedule_added(service);
+
+	return service;
+}
+
+void __connman_service_update_from_network(struct connman_network *network)
+{
+	bool need_sort = false;
+	struct connman_service *service;
+	uint8_t strength;
+	bool roaming;
+	const char *name;
+	const char *passphrase;
+	bool stats_enable;
+
+	service = connman_service_lookup_from_network(network);
+	if (!service)
+		return;
+
+	if (!service->network)
+		return;
+
+	name = connman_network_get_string(service->network, "Name");
+	if (g_strcmp0(service->name, name) != 0) {
+		g_free(service->name);
+		service->name = g_strdup(name);
+
+		if (allow_property_changed(service))
+			connman_dbus_property_changed_basic(service->path,
+					CONNMAN_SERVICE_INTERFACE, "Name",
+					DBUS_TYPE_STRING, &service->name);
+	}
+
+	if (service->type == CONNMAN_SERVICE_TYPE_WIFI)
+		service->wps = connman_network_get_bool(network, "WiFi.WPS");
+
+	passphrase = connman_network_get_string(service->network, "WiFi.Passphrase");
+	if (passphrase) {
+		__connman_service_set_string(service, "Passphrase", passphrase);
+		__connman_service_save(service);
+
+		if ((service->type == CONNMAN_SERVICE_TYPE_LOWPAN) ||
+		    (service->type == CONNMAN_SERVICE_TYPE_WIFI)) {
+			// This will eventually trigger a service changed event.
+			// We need to do this so that we can be sure that
+			// the client has received the most recent passphrase
+			// on 6LoWPAN networks.
+			// This can be removed once the code to fetch the
+			// passphrase explicitly has been added.
+			if (allow_property_changed(service) == TRUE)
+			{
+			    connman_dbus_property_changed_basic(service->path,
+			        CONNMAN_SERVICE_INTERFACE, "Passphrase",
+				    DBUS_TYPE_STRING, &service->passphrase);
+			    service_schedule_changed();
+			}
+		}
+	}
+
+	strength = connman_network_get_strength(service->network);
+	if (strength == service->strength)
+		goto roaming;
+
+	service->strength = strength;
+	need_sort = true;
+
+	strength_changed(service);
+
+roaming:
+	roaming = connman_network_get_bool(service->network, "Roaming");
+	if (roaming == service->roaming)
+		goto sorting;
+
+	stats_enable = stats_enabled(service);
+	if (stats_enable)
+		stats_stop(service);
+
+	service->roaming = roaming;
+	need_sort = true;
+
+	if (stats_enable)
+		stats_start(service);
+
+	roaming_changed(service);
+
+sorting:
+	if (need_sort) {
+		service_list_sort();
+	}
+}
+
+void __connman_service_remove_from_network(struct connman_network *network)
+{
+	struct connman_service *service;
+
+	service = connman_service_lookup_from_network(network);
+
+	DBG("network %p service %p", network, service);
+
+	if (!service)
+		return;
+
+	service->ignore = true;
+
+	__connman_connection_gateway_remove(service,
+					CONNMAN_IPCONFIG_TYPE_ALL);
+
+	connman_service_unref(service);
+}
+
+/**
+ * __connman_service_create_from_provider:
+ * @provider: provider structure
+ *
+ * Look up service by provider and if not found, create one
+ */
+struct connman_service *
+__connman_service_create_from_provider(struct connman_provider *provider)
+{
+	struct connman_service *service;
+	const char *ident, *str;
+	char *name;
+	int index = connman_provider_get_index(provider);
+
+	DBG("provider %p", provider);
+
+	ident = __connman_provider_get_ident(provider);
+	if (!ident)
+		return NULL;
+
+	name = g_strdup_printf("vpn_%s", ident);
+	service = service_get(name);
+	g_free(name);
+
+	if (!service)
+		return NULL;
+
+	service->type = CONNMAN_SERVICE_TYPE_VPN;
+	service->provider = connman_provider_ref(provider);
+	service->autoconnect = false;
+	service->favorite = true;
+
+	service->state_ipv4 = service->state_ipv6 = CONNMAN_SERVICE_STATE_IDLE;
+	service->state = combine_state(service->state_ipv4, service->state_ipv6);
+
+	str = connman_provider_get_string(provider, "Name");
+	if (str) {
+		g_free(service->name);
+		service->name = g_strdup(str);
+		service->hidden = false;
+	} else {
+		g_free(service->name);
+		service->name = NULL;
+		service->hidden = true;
+	}
+
+	service->strength = 0;
+
+	if (!service->ipconfig_ipv4)
+		service->ipconfig_ipv4 = create_ip4config(service, index,
+				CONNMAN_IPCONFIG_METHOD_MANUAL);
+
+	if (!service->ipconfig_ipv6)
+		service->ipconfig_ipv6 = create_ip6config(service, index);
+
+	service_register(service);
+
+	__connman_notifier_service_add(service, service->name);
+	service_schedule_added(service);
+
+	return service;
+}
+
+static void remove_unprovisioned_services(void)
+{
+	gchar **services;
+	GKeyFile *keyfile, *configkeyfile;
+	char *file, *section;
+	int i = 0;
+
+	services = connman_storage_get_services();
+	if (!services)
+		return;
+
+	for (; services[i]; i++) {
+		file = section = NULL;
+		keyfile = configkeyfile = NULL;
+
+		keyfile = connman_storage_load_service(services[i]);
+		if (!keyfile)
+			continue;
+
+		file = g_key_file_get_string(keyfile, services[i],
+					"Config.file", NULL);
+		if (!file)
+			goto next;
+
+		section = g_key_file_get_string(keyfile, services[i],
+					"Config.ident", NULL);
+		if (!section)
+			goto next;
+
+		configkeyfile = __connman_storage_load_config(file);
+		if (!configkeyfile) {
+			/*
+			 * Config file is missing, remove the provisioned
+			 * service.
+			 */
+			__connman_storage_remove_service(services[i]);
+			goto next;
+		}
+
+		if (!g_key_file_has_group(configkeyfile, section))
+			/*
+			 * Config section is missing, remove the provisioned
+			 * service.
+			 */
+			__connman_storage_remove_service(services[i]);
+
+	next:
+		if (keyfile)
+			g_key_file_free(keyfile);
+
+		if (configkeyfile)
+			g_key_file_free(configkeyfile);
+
+		g_free(section);
+		g_free(file);
+	}
+
+	g_strfreev(services);
+}
+
+static int agent_probe(struct connman_agent *agent)
+{
+	DBG("agent %p", agent);
+	return 0;
+}
+
+static void agent_remove(struct connman_agent *agent)
+{
+	DBG("agent %p", agent);
+}
+
+static void *agent_context_ref(void *context)
+{
+	struct connman_service *service = context;
+
+	return (void *)connman_service_ref(service);
+}
+
+static void agent_context_unref(void *context)
+{
+	struct connman_service *service = context;
+
+	connman_service_unref(service);
+}
+
+static struct connman_agent_driver agent_driver = {
+	.name		= "service",
+	.interface      = CONNMAN_AGENT_INTERFACE,
+	.probe		= agent_probe,
+	.remove		= agent_remove,
+	.context_ref	= agent_context_ref,
+	.context_unref	= agent_context_unref,
+};
+
+int __connman_service_init(void)
+{
+	int err;
+
+	DBG("");
+
+	err = connman_agent_driver_register(&agent_driver);
+	if (err < 0) {
+		connman_error("Cannot register agent driver for %s",
+						agent_driver.name);
+		return err;
+	}
+
+	connection = connman_dbus_get_connection();
+
+	service_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
+							NULL, service_free);
+
+	services_notify = g_new0(struct _services_notify, 1);
+	services_notify->remove = g_hash_table_new_full(g_str_hash,
+			g_str_equal, g_free, NULL);
+	services_notify->add = g_hash_table_new(g_str_hash, g_str_equal);
+
+	remove_unprovisioned_services();
+
+	return 0;
+}
+
+// TODO: Remove at some point
+int connman_service_ipconfig_indicate_state(struct connman_service *service,
+					enum connman_service_state new_state,
+					enum connman_ipconfig_type type)
+{
+	return __connman_service_ipconfig_indicate_state(service,new_state,type);
+}
+
+
+void __connman_service_cleanup(void)
+{
+	DBG("");
+
+	if (vpn_autoconnect_timeout) {
+		g_source_remove(vpn_autoconnect_timeout);
+		vpn_autoconnect_timeout = 0;
+	}
+
+	if (autoconnect_timeout != 0) {
+		g_source_remove(autoconnect_timeout);
+		autoconnect_timeout = 0;
+	}
+
+	connman_agent_driver_unregister(&agent_driver);
+
+	g_list_free(service_list);
+	service_list = NULL;
+
+	g_hash_table_destroy(service_hash);
+	service_hash = NULL;
+
+	g_slist_free(counter_list);
+	counter_list = NULL;
+
+	if (services_notify->id != 0) {
+		g_source_remove(services_notify->id);
+		service_send_changed(NULL);
+		g_hash_table_destroy(services_notify->remove);
+		g_hash_table_destroy(services_notify->add);
+	}
+	g_free(services_notify);
+
+	dbus_connection_unref(connection);
+}
diff --git a/connman/src/session.c b/connman/src/session.c
new file mode 100644
index 0000000..4dff930
--- /dev/null
+++ b/connman/src/session.c
@@ -0,0 +1,1760 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2014  Intel Corporation. All rights reserved.
+ *  Copyright (C) 2011-2014  BMW Car IT GmbH.
+ *
+ *  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 <gdbus.h>
+
+#include <connman/session.h>
+
+#include "connman.h"
+
+static DBusConnection *connection;
+static GHashTable *session_hash;
+static GHashTable *service_hash;
+static struct connman_session *ecall_session;
+static uint32_t session_mark = 256;
+static struct firewall_context *global_firewall = NULL;
+
+enum connman_session_state {
+	CONNMAN_SESSION_STATE_DISCONNECTED   = 0,
+	CONNMAN_SESSION_STATE_CONNECTED      = 1,
+	CONNMAN_SESSION_STATE_ONLINE         = 2,
+};
+
+struct session_info {
+	struct connman_session_config config;
+	enum connman_session_state state;
+};
+
+struct connman_session {
+	char *owner;
+	char *session_path;
+	char *notify_path;
+	guint notify_watch;
+
+	bool active;
+	bool append_all;
+	struct session_info *info;
+	struct session_info *info_last;
+	struct connman_service *service;
+	struct connman_service *service_last;
+	struct connman_session_config *policy_config;
+	GSList *user_allowed_bearers;
+
+	bool ecall;
+
+	enum connman_session_id_type id_type;
+	struct firewall_context *fw;
+	uint32_t mark;
+	int index;
+	char *gateway;
+	bool policy_routing;
+};
+
+struct connman_service_info {
+	struct connman_service *service;
+	GSList *sessions;
+};
+
+static struct connman_session_policy *policy;
+static void session_activate(struct connman_session *session);
+static void session_deactivate(struct connman_session *session);
+static void update_session_state(struct connman_session *session);
+
+static void cleanup_service(gpointer data)
+{
+	struct connman_service_info *info = data;
+
+	g_slist_free(info->sessions);
+	g_free(info);
+}
+
+static const char *state2string(enum connman_session_state state)
+{
+	switch (state) {
+	case CONNMAN_SESSION_STATE_DISCONNECTED:
+		return "disconnected";
+	case CONNMAN_SESSION_STATE_CONNECTED:
+		return "connected";
+	case CONNMAN_SESSION_STATE_ONLINE:
+		return "online";
+	}
+
+	return NULL;
+}
+
+static const char *type2string(enum connman_session_type type)
+{
+	switch (type) {
+	case CONNMAN_SESSION_TYPE_UNKNOWN:
+		return "";
+	case CONNMAN_SESSION_TYPE_ANY:
+		return "any";
+	case CONNMAN_SESSION_TYPE_LOCAL:
+		return "local";
+	case CONNMAN_SESSION_TYPE_INTERNET:
+		return "internet";
+	}
+
+	return NULL;
+}
+
+enum connman_session_roaming_policy connman_session_parse_roaming_policy(const char *policy)
+{
+	if (g_strcmp0(policy, "default") == 0)
+		return CONNMAN_SESSION_ROAMING_POLICY_DEFAULT;
+	else if (g_strcmp0(policy, "always") == 0)
+		return CONNMAN_SESSION_ROAMING_POLICY_ALWAYS;
+	else if (g_strcmp0(policy, "forbidden") == 0)
+		return CONNMAN_SESSION_ROAMING_POLICY_FORBIDDEN;
+	else if (g_strcmp0(policy, "national") == 0)
+		return CONNMAN_SESSION_ROAMING_POLICY_NATIONAL;
+	else if (g_strcmp0(policy, "international") == 0)
+		return CONNMAN_SESSION_ROAMING_POLICY_INTERNATIONAL;
+	else
+		return CONNMAN_SESSION_ROAMING_POLICY_UNKNOWN;
+}
+
+enum connman_session_type connman_session_parse_connection_type(const char *type)
+{
+	if (g_strcmp0(type, "any") == 0)
+		return CONNMAN_SESSION_TYPE_ANY;
+	if (g_strcmp0(type, "local") == 0)
+		return CONNMAN_SESSION_TYPE_LOCAL;
+	else if (g_strcmp0(type, "internet") == 0)
+		return CONNMAN_SESSION_TYPE_INTERNET;
+
+	return CONNMAN_SESSION_TYPE_UNKNOWN;
+}
+
+static int bearer2service(const char *bearer, enum connman_service_type *type)
+{
+	if (g_strcmp0(bearer, "ethernet") == 0)
+		*type = CONNMAN_SERVICE_TYPE_ETHERNET;
+	else if (g_strcmp0(bearer, "wifi") == 0)
+		*type = CONNMAN_SERVICE_TYPE_WIFI;
+	else if (g_strcmp0(bearer, "gadget") == 0)
+		*type = CONNMAN_SERVICE_TYPE_GADGET;
+	else if (g_strcmp0(bearer, "bluetooth") == 0)
+		*type = CONNMAN_SERVICE_TYPE_BLUETOOTH;
+	else if (g_strcmp0(bearer, "cellular") == 0)
+		*type = CONNMAN_SERVICE_TYPE_CELLULAR;
+	else if (g_strcmp0(bearer, "vpn") == 0)
+		*type = CONNMAN_SERVICE_TYPE_VPN;
+	else if (g_strcmp0(bearer, "lowpan") == 0)
+		*type = CONNMAN_SERVICE_TYPE_LOWPAN;
+	else
+		return -EINVAL;
+
+	return 0;
+}
+
+static char *service2bearer(enum connman_service_type type)
+{
+	switch (type) {
+	case CONNMAN_SERVICE_TYPE_ETHERNET:
+		return "ethernet";
+	case CONNMAN_SERVICE_TYPE_GADGET:
+		return "gadget";
+	case CONNMAN_SERVICE_TYPE_WIFI:
+		return "wifi";
+	case CONNMAN_SERVICE_TYPE_BLUETOOTH:
+		return "bluetooth";
+	case CONNMAN_SERVICE_TYPE_CELLULAR:
+		return "cellular";
+	case CONNMAN_SERVICE_TYPE_VPN:
+		return "vpn";
+	case CONNMAN_SERVICE_TYPE_LOWPAN:
+		return "lowpan";
+	case CONNMAN_SERVICE_TYPE_SYSTEM:
+	case CONNMAN_SERVICE_TYPE_GPS:
+	case CONNMAN_SERVICE_TYPE_P2P:
+	case CONNMAN_SERVICE_TYPE_UNKNOWN:
+		return "";
+	}
+
+	return "";
+}
+
+static int init_firewall(void)
+{
+	struct firewall_context *fw;
+	int err;
+
+	if (global_firewall)
+		return 0;
+
+	fw = __connman_firewall_create();
+
+	err = __connman_firewall_add_rule(fw, "mangle", "INPUT",
+					"-j CONNMARK --restore-mark");
+	if (err < 0)
+		goto err;
+
+	err = __connman_firewall_add_rule(fw, "mangle", "POSTROUTING",
+					"-j CONNMARK --save-mark");
+	if (err < 0)
+		goto err;
+
+	err = __connman_firewall_enable(fw);
+	if (err < 0)
+		goto err;
+
+	global_firewall = fw;
+
+	return 0;
+
+err:
+	__connman_firewall_destroy(fw);
+
+	return err;
+}
+
+static void cleanup_firewall(void)
+{
+	if (!global_firewall)
+		return;
+
+	__connman_firewall_disable(global_firewall);
+	__connman_firewall_destroy(global_firewall);
+}
+
+static int init_firewall_session(struct connman_session *session)
+{
+	struct firewall_context *fw;
+	int err;
+
+	if (session->policy_config->id_type == CONNMAN_SESSION_ID_TYPE_UNKNOWN)
+		return 0;
+
+	DBG("");
+
+	err = init_firewall();
+	if (err < 0)
+		return err;
+
+	fw = __connman_firewall_create();
+	if (!fw)
+		return -ENOMEM;
+
+	switch (session->policy_config->id_type) {
+	case CONNMAN_SESSION_ID_TYPE_UID:
+		err = __connman_firewall_add_rule(fw, "mangle", "OUTPUT",
+				"-m owner --uid-owner %s -j MARK --set-mark %d",
+						session->policy_config->id,
+						session->mark);
+		break;
+	case CONNMAN_SESSION_ID_TYPE_GID:
+		err = __connman_firewall_add_rule(fw, "mangle", "OUTPUT",
+				"-m owner --gid-owner %s -j MARK --set-mark %d",
+						session->policy_config->id,
+						session->mark);
+		break;
+	case CONNMAN_SESSION_ID_TYPE_LSM:
+	default:
+		err = -EINVAL;
+	}
+
+	if (err < 0)
+		goto err;
+
+	session->id_type = session->policy_config->id_type;
+
+	err = __connman_firewall_enable(fw);
+	if (err)
+		goto err;
+
+	session->fw = fw;
+
+	return 0;
+
+err:
+	__connman_firewall_destroy(fw);
+
+	return err;
+}
+
+static void cleanup_firewall_session(struct connman_session *session)
+{
+	if (!session->fw)
+		return;
+
+	__connman_firewall_disable(session->fw);
+	__connman_firewall_destroy(session->fw);
+
+	session->fw = NULL;
+}
+
+static int init_routing_table(struct connman_session *session)
+{
+	int err;
+
+	if (session->policy_config->id_type == CONNMAN_SESSION_ID_TYPE_UNKNOWN)
+		return 0;
+
+	DBG("");
+
+	err = __connman_inet_add_fwmark_rule(session->mark,
+						AF_INET, session->mark);
+	if (err < 0)
+		return err;
+
+	err = __connman_inet_add_fwmark_rule(session->mark,
+						AF_INET6, session->mark);
+	if (err < 0)
+		__connman_inet_del_fwmark_rule(session->mark,
+						AF_INET, session->mark);
+	session->policy_routing = true;
+
+	return err;
+}
+
+static void del_default_route(struct connman_session *session)
+{
+	if (!session->gateway)
+		return;
+
+	DBG("index %d routing table %d default gateway %s",
+		session->index, session->mark, session->gateway);
+
+	__connman_inet_del_default_from_table(session->mark,
+					session->index, session->gateway);
+	g_free(session->gateway);
+	session->gateway = NULL;
+	session->index = -1;
+}
+
+static void add_default_route(struct connman_session *session)
+{
+	struct connman_ipconfig *ipconfig;
+	int err;
+
+	if (!session->service)
+		return;
+
+	ipconfig = __connman_service_get_ip4config(session->service);
+	session->index = __connman_ipconfig_get_index(ipconfig);
+	session->gateway = g_strdup(__connman_ipconfig_get_gateway(ipconfig));
+
+	DBG("index %d routing table %d default gateway %s",
+		session->index, session->mark, session->gateway);
+
+	err = __connman_inet_add_default_to_table(session->mark,
+					session->index, session->gateway);
+	if (err < 0)
+		DBG("session %p %s", session, strerror(-err));
+}
+
+static void cleanup_routing_table(struct connman_session *session)
+{
+	DBG("");
+
+	if (session->policy_routing) {
+		__connman_inet_del_fwmark_rule(session->mark,
+					AF_INET6, session->mark);
+
+		__connman_inet_del_fwmark_rule(session->mark,
+					AF_INET, session->mark);
+		session->policy_routing = false;
+	}
+
+	del_default_route(session);
+}
+
+static void update_routing_table(struct connman_session *session)
+{
+	del_default_route(session);
+	add_default_route(session);
+}
+
+static void destroy_policy_config(struct connman_session *session)
+{
+	if (!policy) {
+		g_free(session->policy_config);
+		return;
+	}
+
+	policy->destroy(session);
+}
+
+static void free_session(struct connman_session *session)
+{
+	if (!session)
+		return;
+
+	if (session->notify_watch > 0)
+		g_dbus_remove_watch(connection, session->notify_watch);
+
+	destroy_policy_config(session);
+	g_slist_free(session->info->config.allowed_bearers);
+	g_free(session->owner);
+	g_free(session->session_path);
+	g_free(session->notify_path);
+	g_free(session->info);
+	g_free(session->info_last);
+	g_free(session->gateway);
+
+	g_free(session);
+}
+
+static void set_active_session(struct connman_session *session, bool enable)
+{
+
+	if (policy && policy->session_changed)
+		policy->session_changed(session, enable,
+					session->info->config.allowed_bearers);
+
+	__connman_service_set_active_session(enable,
+				session->info->config.allowed_bearers);
+}
+
+static void cleanup_session(gpointer user_data)
+{
+	struct connman_session *session = user_data;
+
+	DBG("remove %s", session->session_path);
+
+	cleanup_routing_table(session);
+	cleanup_firewall_session(session);
+
+	if (session->active)
+		set_active_session(session, false);
+
+	session_deactivate(session);
+	update_session_state(session);
+
+	g_slist_free(session->user_allowed_bearers);
+
+	free_session(session);
+}
+
+struct creation_data {
+	DBusMessage *pending;
+	struct connman_session *session;
+
+	/* user config */
+	enum connman_session_type type;
+	GSList *allowed_bearers;
+};
+
+static void cleanup_creation_data(struct creation_data *creation_data)
+{
+	if (!creation_data)
+		return;
+
+	if (creation_data->pending)
+		dbus_message_unref(creation_data->pending);
+
+	g_slist_free(creation_data->allowed_bearers);
+	g_free(creation_data);
+}
+
+static int create_policy_config(struct connman_session *session,
+				connman_session_config_func_t cb,
+				struct creation_data *creation_data)
+{
+	struct connman_session_config *config;
+
+	if (!policy) {
+		config = connman_session_create_default_config();
+		if (!config) {
+			free_session(session);
+			cleanup_creation_data(creation_data);
+			return -ENOMEM;
+		}
+
+		return cb(session, config, creation_data, 0);
+	}
+
+	return policy->create(session, cb, creation_data);
+}
+
+int connman_session_policy_register(struct connman_session_policy *plugin)
+{
+	if (policy)
+		return -EINVAL;
+
+	if (!plugin->create || !plugin->destroy)
+		return -EINVAL;
+
+	DBG("name %s", plugin->name);
+
+	policy = plugin;
+
+	return 0;
+}
+
+void connman_session_policy_unregister(struct connman_session_policy *plugin)
+{
+	if (plugin != policy)
+		return;
+
+	DBG("name %s", policy->name);
+
+	policy = NULL;
+}
+
+static int default_bearers[] = {
+	CONNMAN_SERVICE_TYPE_ETHERNET,
+	CONNMAN_SERVICE_TYPE_WIFI,
+	CONNMAN_SERVICE_TYPE_BLUETOOTH,
+	CONNMAN_SERVICE_TYPE_CELLULAR,
+	CONNMAN_SERVICE_TYPE_GADGET,
+	CONNMAN_SERVICE_TYPE_LOWPAN,
+};
+
+static void add_default_bearer_types(GSList **list)
+{
+	unsigned int i;
+
+	for (i = 0; i < G_N_ELEMENTS(default_bearers); i++)
+		*list = g_slist_append(*list,
+				GINT_TO_POINTER(default_bearers[i]));
+}
+
+void connman_session_set_default_config(struct connman_session_config *config)
+{
+	config->id_type = CONNMAN_SESSION_ID_TYPE_UNKNOWN;
+	g_free(config->id);
+	config->id = NULL;
+
+	config->priority = FALSE;
+	config->roaming_policy = CONNMAN_SESSION_ROAMING_POLICY_DEFAULT;
+	config->type = CONNMAN_SESSION_TYPE_ANY;
+	config->ecall = FALSE;
+
+	g_slist_free(config->allowed_bearers);
+	add_default_bearer_types(&config->allowed_bearers);
+}
+
+struct connman_session_config *connman_session_create_default_config(void)
+{
+	struct connman_session_config *config;
+
+	config = g_new0(struct connman_session_config, 1);
+	connman_session_set_default_config(config);
+
+	return config;
+}
+
+static enum connman_session_type apply_policy_on_type(
+			enum connman_session_type policy,
+			enum connman_session_type type)
+{
+	if (type == CONNMAN_SESSION_TYPE_UNKNOWN)
+		return CONNMAN_SESSION_TYPE_UNKNOWN;
+
+	if (policy == CONNMAN_SESSION_TYPE_ANY)
+		return type;
+
+	if (policy == CONNMAN_SESSION_TYPE_LOCAL)
+		return CONNMAN_SESSION_TYPE_LOCAL;
+
+	return CONNMAN_SESSION_TYPE_INTERNET;
+}
+
+int connman_session_parse_bearers(const char *token, GSList **list)
+{
+	enum connman_service_type bearer;
+	int err;
+
+	if (g_strcmp0(token, "") == 0)
+		return 0;
+
+	if (g_strcmp0(token, "*") == 0) {
+		add_default_bearer_types(list);
+		return 0;
+	}
+
+	err = bearer2service(token, &bearer);
+	if (err < 0)
+		return err;
+
+	*list = g_slist_append(*list, GINT_TO_POINTER(bearer));
+
+	return 0;
+}
+
+static int parse_bearers(DBusMessageIter *iter, GSList **list)
+{
+	DBusMessageIter array;
+	int type, err;
+
+	dbus_message_iter_recurse(iter, &array);
+
+	*list = NULL;
+
+	while ((type = dbus_message_iter_get_arg_type(&array)) !=
+			DBUS_TYPE_INVALID) {
+		char *bearer_name = NULL;
+
+		if (type != DBUS_TYPE_STRING) {
+			g_slist_free(*list);
+			*list = NULL;
+			return -EINVAL;
+		}
+
+		dbus_message_iter_get_basic(&array, &bearer_name);
+
+		err = connman_session_parse_bearers(bearer_name, list);
+		if (err < 0) {
+			g_slist_free(*list);
+			*list = NULL;
+			return err;
+		}
+
+		dbus_message_iter_next(&array);
+	}
+
+	return 0;
+}
+
+static void filter_bearer(GSList *policy_bearers,
+				enum connman_service_type bearer,
+				GSList **list)
+{
+	enum connman_service_type policy;
+	GSList *it;
+
+	if (!policy_bearers)
+		return;
+
+	for (it = policy_bearers; it; it = it->next) {
+		policy = GPOINTER_TO_INT(it->data);
+
+		if (policy != bearer)
+			continue;
+
+		*list = g_slist_append(*list, GINT_TO_POINTER(bearer));
+		return;
+	}
+}
+
+static void apply_policy_on_bearers(GSList *policy_bearers, GSList *bearers,
+				GSList **list)
+{
+	enum connman_service_type bearer;
+	GSList *it;
+
+	*list = NULL;
+
+	for (it = bearers; it; it = it->next) {
+		bearer = GPOINTER_TO_INT(it->data);
+
+		filter_bearer(policy_bearers, bearer, list);
+	}
+}
+
+const char *connman_session_get_owner(struct connman_session *session)
+{
+	return session->owner;
+}
+
+static void append_allowed_bearers(DBusMessageIter *iter, void *user_data)
+{
+	struct session_info *info = user_data;
+	GSList *list;
+
+	for (list = info->config.allowed_bearers;
+			list; list = list->next) {
+		enum connman_service_type bearer = GPOINTER_TO_INT(list->data);
+		const char *name = __connman_service_type2string(bearer);
+
+		if (!name)
+			name = "";
+
+		dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING,
+						&name);
+	}
+}
+
+static void append_ipconfig_ipv4(DBusMessageIter *iter, void *user_data)
+{
+	struct connman_service *service = user_data;
+	struct connman_ipconfig *ipconfig_ipv4;
+
+	if (!service)
+		return;
+
+	if (!__connman_service_is_connected_state(service,
+						CONNMAN_IPCONFIG_TYPE_IPV4))
+		return;
+
+	ipconfig_ipv4 = __connman_service_get_ip4config(service);
+	if (!ipconfig_ipv4)
+		return;
+
+	__connman_ipconfig_append_ipv4(ipconfig_ipv4, iter);
+}
+
+static void append_ipconfig_ipv6(DBusMessageIter *iter, void *user_data)
+{
+	struct connman_service *service = user_data;
+	struct connman_ipconfig *ipconfig_ipv4, *ipconfig_ipv6;
+
+	if (!service)
+		return;
+
+	if (!__connman_service_is_connected_state(service,
+						CONNMAN_IPCONFIG_TYPE_IPV6))
+		return;
+
+	ipconfig_ipv4 = __connman_service_get_ip4config(service);
+	ipconfig_ipv6 = __connman_service_get_ip6config(service);
+	if (!ipconfig_ipv6)
+		return;
+
+	__connman_ipconfig_append_ipv6(ipconfig_ipv6, iter, ipconfig_ipv4);
+}
+
+static void append_notify(DBusMessageIter *dict,
+					struct connman_session *session)
+{
+	struct session_info *info = session->info;
+	struct session_info *info_last = session->info_last;
+	struct connman_service *service;
+	enum connman_service_type type;
+	const char *name, *bearer;
+	char *ifname;
+	int idx;
+
+	if (session->append_all || info->state != info_last->state) {
+		const char *state = state2string(info->state);
+
+		connman_dbus_dict_append_basic(dict, "State",
+						DBUS_TYPE_STRING,
+						&state);
+		info_last->state = info->state;
+	}
+
+	if (session->append_all || session->service != session->service_last) {
+		if (session->service) {
+			service = session->service;
+			name = __connman_service_get_name(service);
+			idx = __connman_service_get_index(service);
+
+			ifname = connman_inet_ifname(idx);
+			if (!ifname)
+				ifname = g_strdup("");
+
+			type = connman_service_get_type(service);
+			bearer = service2bearer(type);
+		} else {
+			service = NULL;
+			name = "";
+			ifname = g_strdup("");
+			bearer = "";
+		}
+
+		connman_dbus_dict_append_basic(dict, "Name",
+						DBUS_TYPE_STRING,
+						&name);
+
+		connman_dbus_dict_append_dict(dict, "IPv4",
+						append_ipconfig_ipv4,
+						service);
+
+		connman_dbus_dict_append_dict(dict, "IPv6",
+						append_ipconfig_ipv6,
+						service);
+
+		connman_dbus_dict_append_basic(dict, "Interface",
+						DBUS_TYPE_STRING,
+						&ifname);
+
+		connman_dbus_dict_append_basic(dict, "Bearer",
+						DBUS_TYPE_STRING,
+						&bearer);
+
+		g_free(ifname);
+
+		session->service_last = session->service;
+	}
+
+	if (session->append_all ||
+			info->config.type != info_last->config.type) {
+		const char *type = type2string(info->config.type);
+
+		connman_dbus_dict_append_basic(dict, "ConnectionType",
+						DBUS_TYPE_STRING,
+						&type);
+		info_last->config.type = info->config.type;
+	}
+
+	if (session->append_all ||
+			info->config.allowed_bearers != info_last->config.allowed_bearers) {
+		connman_dbus_dict_append_array(dict, "AllowedBearers",
+						DBUS_TYPE_STRING,
+						append_allowed_bearers,
+						info);
+		info_last->config.allowed_bearers = info->config.allowed_bearers;
+	}
+
+	session->append_all = false;
+}
+
+static bool compute_notifiable_changes(struct connman_session *session)
+{
+	struct session_info *info_last = session->info_last;
+	struct session_info *info = session->info;
+
+	if (session->append_all)
+		return true;
+
+	if (info->state != info_last->state)
+		return true;
+
+	if (session->service != session->service_last &&
+			info->state >= CONNMAN_SESSION_STATE_CONNECTED)
+		return true;
+
+	if (info->config.allowed_bearers != info_last->config.allowed_bearers ||
+			info->config.type != info_last->config.type)
+		return true;
+
+	return false;
+}
+
+static gboolean session_notify(gpointer user_data)
+{
+	struct connman_session *session = user_data;
+	DBusMessage *msg;
+	DBusMessageIter array, dict;
+
+	if (!compute_notifiable_changes(session))
+		return FALSE;
+
+	DBG("session %p owner %s notify_path %s", session,
+		session->owner, session->notify_path);
+
+	msg = dbus_message_new_method_call(session->owner, session->notify_path,
+						CONNMAN_NOTIFICATION_INTERFACE,
+						"Update");
+	if (!msg)
+		return FALSE;
+
+	dbus_message_iter_init_append(msg, &array);
+	connman_dbus_dict_open(&array, &dict);
+
+	append_notify(&dict, session);
+
+	connman_dbus_dict_close(&array, &dict);
+
+	g_dbus_send_message(connection, msg);
+
+	return FALSE;
+}
+
+static void ipconfig_ipv4_changed(struct connman_session *session)
+{
+	connman_dbus_setting_changed_dict(session->owner, session->notify_path,
+						"IPv4", append_ipconfig_ipv4,
+						session->service);
+}
+
+static void ipconfig_ipv6_changed(struct connman_session *session)
+{
+	connman_dbus_setting_changed_dict(session->owner, session->notify_path,
+						"IPv6", append_ipconfig_ipv6,
+						session->service);
+}
+
+int connman_session_config_update(struct connman_session *session)
+{
+	struct session_info *info = session->info;
+	GSList *allowed_bearers;
+	int err;
+
+	DBG("session %p", session);
+
+	/*
+	 * We update all configuration even though only one entry
+	 * might have changed. We can still optimize this later.
+	 */
+
+	if (session->id_type != session->policy_config->id_type) {
+		cleanup_firewall_session(session);
+		err = init_firewall_session(session);
+		if (err < 0) {
+			connman_session_destroy(session);
+			return err;
+		}
+
+		session->id_type = session->policy_config->id_type;
+	}
+
+	apply_policy_on_bearers(
+		session->policy_config->allowed_bearers,
+		session->user_allowed_bearers,
+		&allowed_bearers);
+
+	if (session->active)
+		set_active_session(session, false);
+
+	session->active = false;
+	session_deactivate(session);
+
+	g_slist_free(info->config.allowed_bearers);
+	info->config.allowed_bearers = allowed_bearers;
+
+	session_activate(session);
+
+	info->config.type = apply_policy_on_type(
+				session->policy_config->type,
+				info->config.type);
+
+	info->config.roaming_policy = session->policy_config->roaming_policy;
+
+	info->config.ecall = session->policy_config->ecall;
+	if (info->config.ecall)
+		ecall_session = session;
+
+	info->config.priority = session->policy_config->priority;
+
+	session_notify(session);
+
+	return 0;
+}
+
+static DBusMessage *connect_session(DBusConnection *conn,
+					DBusMessage *msg, void *user_data)
+{
+	struct connman_session *session = user_data;
+
+	DBG("session %p", session);
+
+	if (ecall_session) {
+		if (ecall_session->ecall && ecall_session != session)
+			return __connman_error_failed(msg, EBUSY);
+
+		session->ecall = true;
+	}
+
+	if (!session->active) {
+		session->active = true;
+		set_active_session(session, true);
+	}
+
+	session_activate(session);
+
+	__connman_service_auto_connect(CONNMAN_SERVICE_CONNECT_REASON_SESSION);
+
+	return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+}
+
+static DBusMessage *disconnect_session(DBusConnection *conn,
+					DBusMessage *msg, void *user_data)
+{
+	struct connman_session *session = user_data;
+
+	DBG("session %p", session);
+
+	if (ecall_session) {
+		if (ecall_session->ecall && ecall_session != session)
+			return __connman_error_failed(msg, EBUSY);
+
+		session->ecall = false;
+	}
+
+	if (session->active) {
+		session->active = false;
+		set_active_session(session, false);
+	}
+
+	session_deactivate(session);
+	update_session_state(session);
+
+	return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+}
+
+static DBusMessage *change_session(DBusConnection *conn,
+					DBusMessage *msg, void *user_data)
+{
+	struct connman_session *session = user_data;
+	struct session_info *info = session->info;
+	DBusMessageIter iter, value;
+	const char *name;
+	const char *val;
+	GSList *allowed_bearers;
+	int err;
+
+	DBG("session %p", session);
+	if (!dbus_message_iter_init(msg, &iter))
+		return __connman_error_invalid_arguments(msg);
+
+	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
+		return __connman_error_invalid_arguments(msg);
+
+	dbus_message_iter_get_basic(&iter, &name);
+	dbus_message_iter_next(&iter);
+
+	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT)
+		return __connman_error_invalid_arguments(msg);
+
+	dbus_message_iter_recurse(&iter, &value);
+
+	switch (dbus_message_iter_get_arg_type(&value)) {
+	case DBUS_TYPE_ARRAY:
+		if (g_str_equal(name, "AllowedBearers")) {
+			err = parse_bearers(&value, &allowed_bearers);
+			if (err < 0)
+				return __connman_error_failed(msg, -err);
+
+			if (session->active)
+				set_active_session(session, false);
+
+			session->active = false;
+			session_deactivate(session);
+
+			g_slist_free(info->config.allowed_bearers);
+			session->user_allowed_bearers = allowed_bearers;
+
+			apply_policy_on_bearers(
+					session->policy_config->allowed_bearers,
+					session->user_allowed_bearers,
+					&info->config.allowed_bearers);
+
+			session_activate(session);
+		} else {
+			goto err;
+		}
+		break;
+	case DBUS_TYPE_STRING:
+		if (g_str_equal(name, "ConnectionType")) {
+			dbus_message_iter_get_basic(&value, &val);
+			info->config.type = apply_policy_on_type(
+				session->policy_config->type,
+				connman_session_parse_connection_type(val));
+		} else {
+			goto err;
+		}
+		break;
+	default:
+		goto err;
+	}
+
+	session_notify(session);
+
+	return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+
+err:
+	return __connman_error_invalid_arguments(msg);
+}
+
+static void release_session(gpointer key, gpointer value, gpointer user_data)
+{
+	struct connman_session *session = value;
+	DBusMessage *message;
+
+	DBG("owner %s path %s", session->owner, session->notify_path);
+
+	if (session->notify_watch > 0)
+		g_dbus_remove_watch(connection, session->notify_watch);
+
+	g_dbus_unregister_interface(connection, session->session_path,
+						CONNMAN_SESSION_INTERFACE);
+
+	message = dbus_message_new_method_call(session->owner,
+						session->notify_path,
+						CONNMAN_NOTIFICATION_INTERFACE,
+						"Release");
+	if (!message)
+		return;
+
+	dbus_message_set_no_reply(message, TRUE);
+
+	g_dbus_send_message(connection, message);
+}
+
+static int session_disconnect(struct connman_session *session)
+{
+	DBG("session %p, %s", session, session->owner);
+
+	if (session->notify_watch > 0)
+		g_dbus_remove_watch(connection, session->notify_watch);
+
+	g_dbus_unregister_interface(connection, session->session_path,
+						CONNMAN_SESSION_INTERFACE);
+
+	g_hash_table_remove(session_hash, session->session_path);
+
+	return 0;
+}
+
+static void owner_disconnect(DBusConnection *conn, void *user_data)
+{
+	struct connman_session *session = user_data;
+
+	DBG("session %p, %s died", session, session->owner);
+
+	session_disconnect(session);
+}
+
+static DBusMessage *destroy_session(DBusConnection *conn,
+					DBusMessage *msg, void *user_data)
+{
+	struct connman_session *session = user_data;
+
+	DBG("session %p", session);
+
+	if (ecall_session && ecall_session != session)
+		return __connman_error_failed(msg, EBUSY);
+
+	session_disconnect(session);
+
+	return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+}
+
+static const GDBusMethodTable session_methods[] = {
+	{ GDBUS_METHOD("Destroy", NULL, NULL, destroy_session) },
+	{ GDBUS_METHOD("Connect", NULL, NULL, connect_session) },
+	{ GDBUS_METHOD("Disconnect", NULL, NULL,
+			disconnect_session ) },
+	{ GDBUS_METHOD("Change",
+			GDBUS_ARGS({ "name", "s" }, { "value", "v" }),
+			NULL, change_session) },
+	{ },
+};
+
+static int session_policy_config_cb(struct connman_session *session,
+				struct connman_session_config *config,
+				void *user_data, int err)
+{
+	struct creation_data *creation_data = user_data;
+	struct session_info *info, *info_last;
+	DBusMessage *reply;
+
+	DBG("session %p config %p", session, config);
+
+	if (err < 0)
+		goto err;
+
+	session->policy_config = config;
+
+	session->mark = session_mark++;
+	session->index = -1;
+
+	err = init_firewall_session(session);
+	if (err < 0)
+		goto err;
+
+	err = init_routing_table(session);
+	if (err < 0)
+		goto err;
+
+	info = session->info;
+	info_last = session->info_last;
+
+	if (session->policy_config->ecall)
+		ecall_session = session;
+
+	info->state = CONNMAN_SESSION_STATE_DISCONNECTED;
+	info->config.type = apply_policy_on_type(
+				session->policy_config->type,
+				creation_data->type);
+	info->config.priority = session->policy_config->priority;
+	info->config.roaming_policy = session->policy_config->roaming_policy;
+
+	session->user_allowed_bearers = creation_data->allowed_bearers;
+	creation_data->allowed_bearers = NULL;
+
+	apply_policy_on_bearers(
+			session->policy_config->allowed_bearers,
+			session->user_allowed_bearers,
+			&info->config.allowed_bearers);
+
+	g_hash_table_replace(session_hash, session->session_path, session);
+
+	DBG("add %s", session->session_path);
+
+	if (!g_dbus_register_interface(connection, session->session_path,
+					CONNMAN_SESSION_INTERFACE,
+					session_methods, NULL, NULL,
+					session, NULL)) {
+		connman_error("Failed to register %s", session->session_path);
+		g_hash_table_remove(session_hash, session->session_path);
+		err = -EINVAL;
+		goto err;
+	}
+
+	reply = g_dbus_create_reply(creation_data->pending,
+				DBUS_TYPE_OBJECT_PATH, &session->session_path,
+				DBUS_TYPE_INVALID);
+	g_dbus_send_message(connection, reply);
+	creation_data->pending = NULL;
+
+	info_last->state = info->state;
+	info_last->config.priority = info->config.priority;
+	info_last->config.roaming_policy = info->config.roaming_policy;
+	info_last->config.allowed_bearers = info->config.allowed_bearers;
+
+	session->append_all = true;
+
+	cleanup_creation_data(creation_data);
+
+	session_activate(session);
+
+	return 0;
+
+err:
+	reply = __connman_error_failed(creation_data->pending, -err);
+	g_dbus_send_message(connection, reply);
+	creation_data->pending = NULL;
+
+	cleanup_session(session);
+	cleanup_creation_data(creation_data);
+
+	return err;
+}
+
+int __connman_session_create(DBusMessage *msg)
+{
+	const char *owner, *notify_path;
+	char *session_path = NULL;
+	DBusMessageIter iter, array;
+	struct connman_session *session = NULL;
+	struct creation_data *creation_data = NULL;
+	bool user_allowed_bearers = false;
+	bool user_connection_type = false;
+	int err, i;
+	char *str;
+
+	owner = dbus_message_get_sender(msg);
+
+	DBG("owner %s", owner);
+
+	if (ecall_session && ecall_session->ecall) {
+		/*
+		 * If there is an emergency call already going on,
+		 * ignore session creation attempt
+		 */
+		err = -EBUSY;
+		goto err;
+	}
+
+	creation_data = g_try_new0(struct creation_data, 1);
+	if (!creation_data) {
+		err = -ENOMEM;
+		goto err;
+	}
+
+	creation_data->pending = dbus_message_ref(msg);
+
+	dbus_message_iter_init(msg, &iter);
+	dbus_message_iter_recurse(&iter, &array);
+
+	while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_DICT_ENTRY) {
+		DBusMessageIter entry, value;
+		const char *key, *val;
+
+		dbus_message_iter_recurse(&array, &entry);
+		dbus_message_iter_get_basic(&entry, &key);
+
+		dbus_message_iter_next(&entry);
+		dbus_message_iter_recurse(&entry, &value);
+
+		switch (dbus_message_iter_get_arg_type(&value)) {
+		case DBUS_TYPE_ARRAY:
+			if (g_str_equal(key, "AllowedBearers")) {
+				err = parse_bearers(&value,
+					&creation_data->allowed_bearers);
+				if (err < 0)
+					goto err;
+
+				user_allowed_bearers = true;
+			} else {
+				err = -EINVAL;
+				goto err;
+			}
+			break;
+		case DBUS_TYPE_STRING:
+			if (g_str_equal(key, "ConnectionType")) {
+				dbus_message_iter_get_basic(&value, &val);
+				creation_data->type =
+					connman_session_parse_connection_type(val);
+
+				user_connection_type = true;
+			} else {
+				err = -EINVAL;
+				goto err;
+			}
+		}
+		dbus_message_iter_next(&array);
+	}
+
+	/*
+	 * If the user hasn't provided a configuration, we set
+	 * the default configuration.
+	 *
+	 * For AllowedBearers this is '*', ...
+	 */
+	if (!user_allowed_bearers) {
+		add_default_bearer_types(&creation_data->allowed_bearers);
+		if (!creation_data->allowed_bearers) {
+			err = -ENOMEM;
+			goto err;
+		}
+	}
+
+	/* ... and for ConnectionType it is 'any'. */
+	if (!user_connection_type)
+		creation_data->type = CONNMAN_SESSION_TYPE_ANY;
+
+	dbus_message_iter_next(&iter);
+	dbus_message_iter_get_basic(&iter, &notify_path);
+
+	if (!notify_path) {
+		err = -EINVAL;
+		goto err;
+	}
+
+	str = g_strdup(owner);
+	for (i = 0; str[i] != '\0'; i++)
+		if (str[i] == ':' || str[i] == '.')
+			str[i] = '_';
+	session_path = g_strdup_printf("/sessions/%s%s", str, notify_path);
+	g_free(str);
+
+	if (!session_path) {
+		err = -ENOMEM;
+		goto err;
+	}
+
+	session = g_hash_table_lookup(session_hash, session_path);
+	if (session) {
+		g_free(session_path);
+		session = NULL;
+		err = -EEXIST;
+		goto err;
+	}
+
+	session = g_try_new0(struct connman_session, 1);
+	if (!session) {
+		g_free(session_path);
+		err = -ENOMEM;
+		goto err;
+	}
+
+	creation_data->session = session;
+	session->session_path = session_path;
+
+	session->info = g_try_new0(struct session_info, 1);
+	if (!session->info) {
+		err = -ENOMEM;
+		goto err;
+	}
+
+	session->info_last = g_try_new0(struct session_info, 1);
+	if (!session->info_last) {
+		err = -ENOMEM;
+		goto err;
+	}
+
+	session->owner = g_strdup(owner);
+	session->notify_path = g_strdup(notify_path);
+	session->notify_watch =
+		g_dbus_add_disconnect_watch(connection, session->owner,
+					owner_disconnect, session, NULL);
+
+	err = create_policy_config(session, session_policy_config_cb,
+					creation_data);
+	if (err < 0 && err != -EINPROGRESS)
+		return err;
+
+	return -EINPROGRESS;
+
+err:
+	connman_error("Failed to create session");
+
+	free_session(session);
+
+	cleanup_creation_data(creation_data);
+	return err;
+}
+
+bool __connman_session_policy_autoconnect(enum connman_service_connect_reason reason)
+{
+	if (!policy || !policy->autoconnect)
+		return true;
+
+	return policy->autoconnect(reason);
+}
+
+void connman_session_destroy(struct connman_session *session)
+{
+	DBG("session %p", session);
+
+	session_disconnect(session);
+}
+
+int __connman_session_destroy(DBusMessage *msg)
+{
+	const char *owner, *session_path;
+	struct connman_session *session;
+
+	owner = dbus_message_get_sender(msg);
+
+	DBG("owner %s", owner);
+
+	dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &session_path,
+							DBUS_TYPE_INVALID);
+	if (!session_path)
+		return -EINVAL;
+
+	session = g_hash_table_lookup(session_hash, session_path);
+	if (!session)
+		return -EINVAL;
+
+	if (g_strcmp0(owner, session->owner) != 0)
+		return -EACCES;
+
+	connman_session_destroy(session);
+
+	return 0;
+}
+
+int connman_session_connect(struct connman_service *service)
+{
+	DBG("service %p name %s", service, __connman_service_get_name(service));
+
+	return __connman_service_connect(service,
+				CONNMAN_SERVICE_CONNECT_REASON_SESSION);
+}
+
+int connman_session_disconnect(struct connman_service *service)
+{
+	DBG("service %p", service);
+
+	return __connman_service_disconnect(service);
+}
+
+static enum connman_session_state service_to_session_state(
+					enum connman_service_state state)
+{
+	switch (state) {
+	case CONNMAN_SERVICE_STATE_UNKNOWN:
+	case CONNMAN_SERVICE_STATE_IDLE:
+	case CONNMAN_SERVICE_STATE_ASSOCIATION:
+	case CONNMAN_SERVICE_STATE_CONFIGURATION:
+	case CONNMAN_SERVICE_STATE_DISCONNECT:
+	case CONNMAN_SERVICE_STATE_FAILURE:
+		break;
+	case CONNMAN_SERVICE_STATE_READY:
+		return CONNMAN_SESSION_STATE_CONNECTED;
+	case CONNMAN_SERVICE_STATE_ONLINE:
+		return CONNMAN_SESSION_STATE_ONLINE;
+	}
+
+	return CONNMAN_SESSION_STATE_DISCONNECTED;
+}
+
+static void update_session_state(struct connman_session *session)
+{
+	enum connman_service_state service_state;
+	enum connman_session_state state = CONNMAN_SESSION_STATE_DISCONNECTED;
+
+	if (session->service) {
+		service_state = __connman_service_get_state(session->service);
+		state = service_to_session_state(service_state);
+		session->info->state = state;
+	}
+	session->info->state = state;
+
+	DBG("session %p state %s", session, state2string(state));
+
+	update_routing_table(session);
+	session_notify(session);
+}
+
+static bool session_match_service(struct connman_session *session,
+				struct connman_service *service)
+{
+	enum connman_service_type bearer_type;
+	enum connman_service_type service_type;
+	GSList *list;
+
+	if (policy && policy->allowed)
+		return policy->allowed(session, service);
+
+	for (list = session->info->config.allowed_bearers; list; list = list->next) {
+		bearer_type = GPOINTER_TO_INT(list->data);
+		service_type = connman_service_get_type(service);
+
+		if (bearer_type == service_type)
+			return true;
+	}
+
+	return false;
+}
+
+static bool is_session_connected(struct connman_session *session,
+				enum connman_service_state state)
+
+{
+	switch (state) {
+	case CONNMAN_SERVICE_STATE_UNKNOWN:
+	case CONNMAN_SERVICE_STATE_IDLE:
+	case CONNMAN_SERVICE_STATE_ASSOCIATION:
+	case CONNMAN_SERVICE_STATE_CONFIGURATION:
+	case CONNMAN_SERVICE_STATE_DISCONNECT:
+	case CONNMAN_SERVICE_STATE_FAILURE:
+			  break;
+	case CONNMAN_SERVICE_STATE_READY:
+		if (session->info->config.type == CONNMAN_SESSION_TYPE_INTERNET)
+			return false;
+	case CONNMAN_SERVICE_STATE_ONLINE:
+		return true;
+	}
+
+	return false;
+}
+
+static void session_activate(struct connman_session *session)
+{
+	GHashTableIter iter;
+	gpointer key, value;
+
+	if (!service_hash)
+		return;
+
+	g_hash_table_iter_init(&iter, service_hash);
+	while (g_hash_table_iter_next(&iter, &key, &value)) {
+		struct connman_service_info *info = value;
+		enum connman_service_state state;
+
+		state = __connman_service_get_state(info->service);
+
+		if (is_session_connected(session, state) &&
+				session_match_service(session, info->service)) {
+			DBG("session %p add service %p", session, info->service);
+
+			info->sessions = g_slist_prepend(info->sessions,
+							session);
+			session->service = info->service;
+			update_session_state(session);
+
+			return;
+		}
+	}
+
+	session_notify(session);
+}
+
+static void session_deactivate(struct connman_session *session)
+{
+	struct connman_service_info *info;
+
+	if (!service_hash)
+		return;
+
+	if (!session->service)
+		return;
+
+	info = g_hash_table_lookup(service_hash, session->service);
+	if (!info)
+		return;
+
+	info->sessions = g_slist_remove(info->sessions, session);
+	session->service = NULL;
+
+	session->info->state = CONNMAN_SESSION_STATE_DISCONNECTED;
+}
+
+static void handle_service_state_online(struct connman_service *service,
+					enum connman_service_state state,
+					struct connman_service_info *info)
+{
+	GHashTableIter iter;
+	gpointer key, value;
+
+	g_hash_table_iter_init(&iter, session_hash);
+	while (g_hash_table_iter_next(&iter, &key, &value)) {
+		struct connman_session *session = value;
+		bool connected;
+
+		connected = is_session_connected(session, state);
+
+		if (session->service == service) {
+			if (!connected) {
+				DBG("session %p remove service %p", session, service);
+				info->sessions = g_slist_remove(info->sessions,
+							session);
+				session->service = NULL;
+				update_session_state(session);
+			}
+		} else if (connected && session_match_service(session, service)) {
+			DBG("session %p add service %p", session, service);
+
+			info->sessions = g_slist_prepend(info->sessions,
+							session);
+			session->service = service;
+			update_session_state(session);
+		}
+	}
+}
+
+static void handle_service_state_offline(struct connman_service *service,
+					struct connman_service_info *info)
+{
+	GSList *list;
+
+	for (list = info->sessions; list; list = list->next) {
+		struct connman_session *session = list->data;
+
+		if (session->service != service) {
+			connman_warn("session %p should have session %p assigned",
+					session, service);
+			continue;
+		}
+
+		DBG("session %p remove service %p", session, service);
+
+		session->service = NULL;
+		update_session_state(session);
+	}
+}
+
+
+static void service_state_changed(struct connman_service *service,
+				enum connman_service_state state)
+{
+	struct connman_service_info *info;
+
+	DBG("service %p state %d", service, state);
+
+	info = g_hash_table_lookup(service_hash, service);
+
+	switch (state) {
+	case CONNMAN_SERVICE_STATE_UNKNOWN:
+	case CONNMAN_SERVICE_STATE_IDLE:
+	case CONNMAN_SERVICE_STATE_ASSOCIATION:
+	case CONNMAN_SERVICE_STATE_CONFIGURATION:
+	case CONNMAN_SERVICE_STATE_FAILURE:
+	case CONNMAN_SERVICE_STATE_DISCONNECT:
+		if (!info)
+			return;
+
+		handle_service_state_offline(service, info);
+
+		g_hash_table_remove(service_hash, service);
+
+		return;
+	case CONNMAN_SERVICE_STATE_READY:
+	case CONNMAN_SERVICE_STATE_ONLINE:
+		if (!info) {
+			info = g_new0(struct connman_service_info, 1);
+			g_hash_table_replace(service_hash, service, info);
+		}
+
+		info->service = service;
+		handle_service_state_online(service, state, info);
+	}
+}
+
+static void ipconfig_changed(struct connman_service *service,
+				struct connman_ipconfig *ipconfig)
+{
+	GHashTableIter iter;
+	gpointer key, value;
+	struct connman_session *session;
+	struct session_info *info;
+	enum connman_ipconfig_type type;
+
+	DBG("service %p ipconfig %p", service, ipconfig);
+
+	type = __connman_ipconfig_get_config_type(ipconfig);
+
+	g_hash_table_iter_init(&iter, session_hash);
+
+	while (g_hash_table_iter_next(&iter, &key, &value)) {
+		session = value;
+		info = session->info;
+
+		if (info->state == CONNMAN_SESSION_STATE_DISCONNECTED)
+			continue;
+
+		if (session->service && session->service == service) {
+			update_routing_table(session);
+
+			if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
+				ipconfig_ipv4_changed(session);
+			else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
+				ipconfig_ipv6_changed(session);
+		}
+	}
+}
+
+static struct connman_notifier session_notifier = {
+	.name			= "session",
+	.service_state_changed	= service_state_changed,
+	.ipconfig_changed	= ipconfig_changed,
+};
+
+int __connman_session_init(void)
+{
+	int err;
+
+	DBG("");
+
+	connection = connman_dbus_get_connection();
+	if (!connection)
+		return -1;
+
+	err = connman_notifier_register(&session_notifier);
+	if (err < 0) {
+		dbus_connection_unref(connection);
+		return err;
+	}
+
+	session_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
+						NULL, cleanup_session);
+
+	service_hash = g_hash_table_new_full(g_direct_hash, g_direct_equal,
+						NULL, cleanup_service);
+
+	return 0;
+}
+
+void __connman_session_cleanup(void)
+{
+	DBG("");
+
+	if (!connection)
+		return;
+
+	cleanup_firewall();
+
+	connman_notifier_unregister(&session_notifier);
+
+	g_hash_table_foreach(session_hash, release_session, NULL);
+	g_hash_table_destroy(session_hash);
+	session_hash = NULL;
+	g_hash_table_destroy(service_hash);
+	service_hash = NULL;
+
+	dbus_connection_unref(connection);
+}
diff --git a/connman/src/shared/debugfs.c b/connman/src/shared/debugfs.c
new file mode 100644
index 0000000..f522c51
--- /dev/null
+++ b/connman/src/shared/debugfs.c
@@ -0,0 +1,66 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2012  Intel Corporation. All rights reserved.
+ *
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  This library 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
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; 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 <stdio.h>
+#include <stdbool.h>
+#include <string.h>
+#include <limits.h>
+
+#include "src/shared/debugfs.h"
+
+#define STRINGIFY(x) STRINGIFY_ARG(x)
+#define STRINGIFY_ARG(x) #x
+
+const char *debugfs_get_path(void)
+{
+	static char path[PATH_MAX + 1];
+	static bool found = false;
+	char type[100];
+	FILE *fp;
+
+	if (found)
+		return path;
+
+	fp = fopen("/proc/mounts", "r");
+	if (!fp)
+		return NULL;
+
+	while (fscanf(fp, "%*s %" STRINGIFY(PATH_MAX) "s %99s %*s %*d %*d\n",
+							path, type) == 2) {
+		if (!strcmp(type, "debugfs")) {
+			found = true;
+			break;
+		}
+	}
+
+	fclose(fp);
+
+	if (!found)
+		return NULL;
+
+	return path;
+}
diff --git a/connman/src/shared/debugfs.h b/connman/src/shared/debugfs.h
new file mode 100644
index 0000000..7f41ca7
--- /dev/null
+++ b/connman/src/shared/debugfs.h
@@ -0,0 +1,24 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2012  Intel Corporation. All rights reserved.
+ *
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  This library 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
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+const char *debugfs_get_path(void);
diff --git a/connman/src/shared/netlink.c b/connman/src/shared/netlink.c
new file mode 100644
index 0000000..cf54131
--- /dev/null
+++ b/connman/src/shared/netlink.c
@@ -0,0 +1,665 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2011-2012  Intel Corporation. All rights reserved.
+ *  Copyright (C) 2013-2014  BMW Car IT GmbH.
+ *
+ *  This program is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License version 2.1 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 Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser 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
+ *
+ */
+
+/*
+ * This file is a copy from ELL which has been ported to use GLib's
+ * data structures.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <string.h>
+#include <unistd.h>
+#include <sys/socket.h>
+#include <linux/netlink.h>
+
+#include <gdbus.h>
+
+#include "src/shared/util.h"
+#include "src/shared/netlink.h"
+
+#ifndef SOL_NETLINK
+#define SOL_NETLINK 270
+#endif
+
+struct command {
+	unsigned int id;
+	uint32_t seq;
+	uint32_t len;
+	netlink_command_func_t handler;
+	netlink_destroy_func_t destroy;
+	void *user_data;
+};
+
+struct notify {
+	uint32_t group;
+	netlink_notify_func_t handler;
+	netlink_destroy_func_t destroy;
+	void *user_data;
+};
+
+struct netlink_info {
+	uint32_t pid;
+	GIOChannel *channel;
+	uint32_t next_seq;
+	GQueue *command_queue;
+	GHashTable *command_pending;
+	GHashTable *command_lookup;
+	unsigned int next_command_id;
+	GHashTable *notify_groups;
+	GHashTable *notify_lookup;
+	unsigned int next_notify_id;
+	netlink_debug_func_t debug_handler;
+	netlink_destroy_func_t debug_destroy;
+	void *debug_data;
+};
+
+
+static void destroy_command(struct command *command)
+{
+	if (command->destroy)
+		command->destroy(command->user_data);
+
+	g_free(command);
+}
+
+static void destroy_notify(struct notify *notify)
+{
+	if (notify->destroy)
+		notify->destroy(notify->user_data);
+
+	g_free(notify);
+}
+
+static gboolean can_write_data(GIOChannel *chan,
+				GIOCondition cond, gpointer user_data)
+{
+	struct netlink_info *netlink = user_data;
+	struct command *command;
+	struct sockaddr_nl addr;
+	const void *data;
+	ssize_t written;
+	int sk;
+
+	command = g_queue_pop_head(netlink->command_queue);
+	if (!command)
+		return FALSE;
+
+	sk = g_io_channel_unix_get_fd(chan);
+
+	memset(&addr, 0, sizeof(addr));
+	addr.nl_family = AF_NETLINK;
+	addr.nl_pid = 0;
+
+	data = ((void *) command) + NLMSG_ALIGN(sizeof(struct command));
+
+	written = sendto(sk, data, command->len, 0,
+				(struct sockaddr *) &addr, sizeof(addr));
+	if (written < 0 || (uint32_t) written != command->len) {
+		g_hash_table_remove(netlink->command_lookup,
+					GUINT_TO_POINTER(command->id));
+		destroy_command(command);
+		return FALSE;
+	}
+
+	util_hexdump('<', data, command->len,
+				netlink->debug_handler, netlink->debug_data);
+
+	g_hash_table_replace(netlink->command_pending,
+				GUINT_TO_POINTER(command->seq), command);
+
+	return g_queue_get_length(netlink->command_queue) > 0;
+}
+
+static void do_notify(gpointer key, gpointer value, gpointer user_data)
+{
+	struct nlmsghdr *nlmsg = user_data;
+	struct notify *notify = value;
+
+	if (notify->handler) {
+		notify->handler(nlmsg->nlmsg_type, NLMSG_DATA(nlmsg),
+			nlmsg->nlmsg_len - NLMSG_HDRLEN, notify->user_data);
+	}
+}
+
+static void process_broadcast(struct netlink_info *netlink, uint32_t group,
+						struct nlmsghdr *nlmsg)
+{
+	GHashTable *notify_list;
+
+	notify_list = g_hash_table_lookup(netlink->notify_groups,
+					       GUINT_TO_POINTER(group));
+	if (!notify_list)
+		return;
+
+	g_hash_table_foreach(notify_list, do_notify, nlmsg);
+}
+
+static void process_message(struct netlink_info *netlink,
+				struct nlmsghdr *nlmsg)
+{
+	const void *data = nlmsg;
+	struct command *command;
+
+	command = g_hash_table_lookup(netlink->command_pending,
+					GUINT_TO_POINTER(nlmsg->nlmsg_seq));
+	if (!command)
+		return;
+
+	g_hash_table_remove(netlink->command_pending,
+					GUINT_TO_POINTER(nlmsg->nlmsg_seq));
+
+	if (!command->handler)
+		goto done;
+
+	if (nlmsg->nlmsg_type < NLMSG_MIN_TYPE) {
+		const struct nlmsgerr *err;
+
+		switch (nlmsg->nlmsg_type) {
+		case NLMSG_ERROR:
+			err = data + NLMSG_HDRLEN;
+
+			command->handler(-err->error, 0, NULL, 0,
+							command->user_data);
+			break;
+		}
+	} else {
+		command->handler(0, nlmsg->nlmsg_type, data + NLMSG_HDRLEN,
+					nlmsg->nlmsg_len - NLMSG_HDRLEN,
+					command->user_data);
+	}
+
+done:
+	g_hash_table_remove(netlink->command_lookup,
+				GUINT_TO_POINTER(command->id));
+
+	destroy_command(command);
+}
+
+static void process_multi(struct netlink_info *netlink, struct nlmsghdr *nlmsg)
+{
+	const void *data = nlmsg;
+	struct command *command;
+
+	command = g_hash_table_lookup(netlink->command_pending,
+					GUINT_TO_POINTER(nlmsg->nlmsg_seq));
+	if (!command)
+		return;
+
+	if (!command->handler)
+		goto done;
+
+	if (nlmsg->nlmsg_type < NLMSG_MIN_TYPE) {
+		const struct nlmsgerr *err;
+
+		switch (nlmsg->nlmsg_type) {
+		case NLMSG_DONE:
+		case NLMSG_ERROR:
+			err = data + NLMSG_HDRLEN;
+
+			command->handler(-err->error, 0, NULL, 0,
+							command->user_data);
+			break;
+		}
+	} else {
+		command->handler(0, nlmsg->nlmsg_type, data + NLMSG_HDRLEN,
+					nlmsg->nlmsg_len - NLMSG_HDRLEN,
+					command->user_data);
+		return;
+	}
+
+done:
+	g_hash_table_remove(netlink->command_pending,
+			GUINT_TO_POINTER(nlmsg->nlmsg_seq));
+
+	g_hash_table_remove(netlink->command_lookup,
+			GUINT_TO_POINTER(command->id));
+
+	destroy_command(command);
+}
+
+static gboolean can_read_data(GIOChannel *chan,
+				GIOCondition cond, gpointer data)
+{
+	struct netlink_info *netlink = data;
+	struct cmsghdr *cmsg;
+	struct msghdr msg;
+	struct iovec iov;
+	struct nlmsghdr *nlmsg;
+	unsigned char buffer[4096];
+	unsigned char control[32];
+	uint32_t group = 0;
+	ssize_t len;
+	int sk;
+
+	sk = g_io_channel_unix_get_fd(chan);
+
+	iov.iov_base = buffer;
+	iov.iov_len = sizeof(buffer);
+
+	memset(&msg, 0, sizeof(msg));
+	msg.msg_iov = &iov;
+	msg.msg_iovlen = 1;
+	msg.msg_control = control;
+	msg.msg_controllen = sizeof(control);
+
+	len = recvmsg(sk, &msg, 0);
+	if (len < 0)
+		return FALSE;
+
+	util_hexdump('>', buffer, len, netlink->debug_handler,
+			netlink->debug_data);
+
+	for (cmsg = CMSG_FIRSTHDR(&msg); cmsg;
+					cmsg = CMSG_NXTHDR(&msg, cmsg)) {
+		struct nl_pktinfo *pktinfo;
+
+		if (cmsg->cmsg_level != SOL_NETLINK)
+			continue;
+
+		if (cmsg->cmsg_type != NETLINK_PKTINFO)
+			continue;
+
+		pktinfo = (void *) CMSG_DATA(cmsg);
+
+		group = pktinfo->group;
+	}
+
+	for (nlmsg = iov.iov_base; NLMSG_OK(nlmsg, (uint32_t) len);
+					nlmsg = NLMSG_NEXT(nlmsg, len)) {
+		if (group > 0 && nlmsg->nlmsg_seq == 0) {
+			process_broadcast(netlink, group, nlmsg);
+			continue;
+		}
+
+		if (nlmsg->nlmsg_pid != netlink->pid)
+			continue;
+
+		if (nlmsg->nlmsg_flags & NLM_F_MULTI)
+			process_multi(netlink, nlmsg);
+		else
+			process_message(netlink, nlmsg);
+	}
+
+	return TRUE;
+}
+
+static gboolean netlink_event(GIOChannel *chan,
+				GIOCondition cond, gpointer data)
+{
+	if (cond & (G_IO_NVAL | G_IO_HUP | G_IO_ERR))
+		return FALSE;
+
+	return TRUE;
+}
+
+static int create_netlink_socket(int protocol, uint32_t *pid)
+{
+	struct sockaddr_nl addr;
+	socklen_t addrlen = sizeof(addr);
+	int sk, pktinfo = 1;
+
+	sk = socket(PF_NETLINK, SOCK_DGRAM | SOCK_CLOEXEC | SOCK_NONBLOCK,
+								protocol);
+	if (sk < 0)
+		return -1;
+
+	memset(&addr, 0, sizeof(addr));
+	addr.nl_family = AF_NETLINK;
+
+	if (bind(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
+		close(sk);
+		return -1;
+	}
+
+	if (getsockname(sk, (struct sockaddr *) &addr, &addrlen) < 0) {
+		close(sk);
+		return -1;
+	}
+
+	if (setsockopt(sk, SOL_NETLINK, NETLINK_PKTINFO,
+					&pktinfo, sizeof(pktinfo)) < 0) {
+		close(sk);
+		return -1;
+	}
+
+	if (pid)
+		*pid = addr.nl_pid;
+
+	return sk;
+}
+
+struct netlink_info *netlink_new(int protocol)
+{
+	struct netlink_info *netlink;
+	int sk;
+
+	netlink = g_try_new0(struct netlink_info, 1);
+	if (!netlink)
+		return NULL;
+
+	netlink->next_seq = 1;
+	netlink->next_command_id = 1;
+	netlink->next_notify_id = 1;
+
+	sk = create_netlink_socket(protocol, &netlink->pid);
+	if (sk < 0) {
+		g_free(netlink);
+		return NULL;
+	}
+
+	netlink->channel = g_io_channel_unix_new(sk);
+	g_io_channel_set_close_on_unref(netlink->channel, TRUE);
+
+	g_io_channel_set_encoding(netlink->channel, NULL, NULL);
+	g_io_channel_set_buffered(netlink->channel, FALSE);
+
+	g_io_add_watch(netlink->channel, G_IO_IN, can_read_data, netlink);
+	g_io_add_watch(netlink->channel, G_IO_NVAL | G_IO_HUP | G_IO_ERR,
+			netlink_event, netlink);
+
+	netlink->command_queue = g_queue_new();
+	netlink->command_pending = g_hash_table_new(g_direct_hash,
+							g_direct_equal);
+	netlink->command_lookup = g_hash_table_new(g_direct_hash,
+							g_direct_equal);
+
+	netlink->notify_groups = g_hash_table_new(g_direct_hash,
+							g_direct_equal);
+	netlink->notify_lookup = g_hash_table_new(g_direct_hash,
+							g_direct_equal);
+
+	return netlink;
+}
+
+static gboolean cleanup_notify(gpointer key, gpointer value, gpointer user_data)
+{
+	struct notify *notify = value;
+
+	destroy_notify(notify);
+
+	return TRUE;
+
+}
+
+static gboolean cleanup_notify_group(gpointer key, gpointer value,
+					gpointer user_data)
+{
+	GHashTable *notify_list = value;
+
+	g_hash_table_foreach_remove(notify_list, cleanup_notify, user_data);
+	g_hash_table_destroy(notify_list);
+
+	return TRUE;
+}
+
+static gboolean cleanup_command(gpointer key, gpointer value,
+					gpointer user_data)
+{
+	struct command *command = value;
+
+	destroy_command(command);
+
+	return TRUE;
+}
+
+void netlink_destroy(struct netlink_info *netlink)
+{
+	g_hash_table_destroy(netlink->notify_lookup);
+
+	g_hash_table_foreach_remove(netlink->notify_groups,
+				cleanup_notify_group, NULL);
+	g_hash_table_destroy(netlink->notify_groups);
+
+	g_queue_free(netlink->command_queue);
+
+	g_hash_table_destroy(netlink->command_pending);
+
+	g_hash_table_foreach_remove(netlink->command_lookup,
+				cleanup_command, NULL);
+	g_hash_table_destroy(netlink->command_lookup);
+
+	g_io_channel_shutdown(netlink->channel, TRUE, NULL);
+	g_io_channel_unref(netlink->channel);
+
+	g_free(netlink);
+}
+
+unsigned int netlink_send(struct netlink_info *netlink,
+			uint16_t type, uint16_t flags, const void *data,
+			uint32_t len, netlink_command_func_t function,
+			void *user_data, netlink_destroy_func_t destroy)
+{
+	struct command *command;
+	struct nlmsghdr *nlmsg;
+	size_t size;
+
+	if (!netlink)
+		return 0;
+
+	if (!netlink->command_queue ||
+			!netlink->command_pending ||
+			!netlink->command_lookup)
+		return 0;
+
+	size = NLMSG_ALIGN(sizeof(struct command)) +
+					NLMSG_HDRLEN + NLMSG_ALIGN(len);
+
+	command = g_try_malloc0(size);
+	if (!command)
+		return 0;
+
+	command->handler = function;
+	command->destroy = destroy;
+	command->user_data = user_data;
+
+	command->id = netlink->next_command_id;
+
+	g_hash_table_replace(netlink->command_lookup,
+				GUINT_TO_POINTER(command->id), command);
+
+	command->seq = netlink->next_seq++;
+	command->len = NLMSG_HDRLEN + NLMSG_ALIGN(len);
+
+	nlmsg = ((void *) command) + NLMSG_ALIGN(sizeof(struct command));
+
+	nlmsg->nlmsg_len = command->len;
+	nlmsg->nlmsg_type = type;
+	nlmsg->nlmsg_flags = NLM_F_REQUEST | flags;
+	nlmsg->nlmsg_seq = command->seq;
+	nlmsg->nlmsg_pid = netlink->pid;
+
+	if (data && len > 0)
+		memcpy(((void *) nlmsg) + NLMSG_HDRLEN, data, len);
+
+	g_queue_push_tail(netlink->command_queue, command);
+
+	netlink->next_command_id++;
+
+	/* Arm IOChannel to call can_write_data in case it is not armed yet. */
+	if (g_queue_get_length(netlink->command_queue) == 1)
+		g_io_add_watch(netlink->channel, G_IO_OUT, can_write_data,
+				netlink);
+
+	return command->id;
+}
+
+bool netlink_cancel(struct netlink_info *netlink, unsigned int id)
+{
+	struct command *command;
+
+	if (!netlink || id == 0)
+		return false;
+
+	if (!netlink->command_queue ||
+			!netlink->command_pending ||
+			!netlink->command_lookup)
+		return false;
+
+	command = g_hash_table_lookup(netlink->command_lookup,
+					GUINT_TO_POINTER(id));
+	if (!command)
+		return false;
+
+	g_hash_table_remove(netlink->command_lookup, GUINT_TO_POINTER(id));
+
+	g_queue_remove(netlink->command_queue, command);
+
+	g_hash_table_remove(netlink->command_pending, GUINT_TO_POINTER(command->seq));
+
+	destroy_command(command);
+
+	return true;
+}
+
+static bool add_membership(struct netlink_info *netlink, uint32_t group)
+{
+	int sk, value = group;
+
+	sk = g_io_channel_unix_get_fd(netlink->channel);
+
+	if (setsockopt(sk, SOL_NETLINK, NETLINK_ADD_MEMBERSHIP,
+						&value, sizeof(value)) < 0)
+		return false;
+
+	return true;
+}
+
+static bool drop_membership(struct netlink_info *netlink, uint32_t group)
+{
+	int sk, value = group;
+
+	sk = g_io_channel_unix_get_fd(netlink->channel);
+
+	if (setsockopt(sk, SOL_NETLINK, NETLINK_DROP_MEMBERSHIP,
+						&value, sizeof(value)) < 0)
+		return false;
+
+	return true;
+}
+
+unsigned int netlink_register(struct netlink_info *netlink,
+			uint32_t group, netlink_notify_func_t function,
+			void *user_data, netlink_destroy_func_t destroy)
+{
+	GHashTable *notify_list;
+	struct notify *notify;
+	unsigned int id;
+
+	if (!netlink)
+		return 0;
+
+	if (!netlink->notify_groups || !netlink->notify_lookup)
+		return 0;
+
+	notify_list = g_hash_table_lookup(netlink->notify_groups,
+						GUINT_TO_POINTER(group));
+	if (!notify_list) {
+		notify_list = g_hash_table_new(g_direct_hash, g_direct_equal);
+		if (!notify_list)
+			return 0;
+
+		g_hash_table_replace(netlink->notify_groups,
+					GUINT_TO_POINTER(group), notify_list);
+	}
+
+	notify = g_new(struct notify, 1);
+
+	notify->group = group;
+	notify->handler = function;
+	notify->destroy = destroy;
+	notify->user_data = user_data;
+
+	id = netlink->next_notify_id;
+
+	g_hash_table_replace(netlink->notify_lookup,
+				GUINT_TO_POINTER(id), notify_list);
+	g_hash_table_replace(notify_list, GUINT_TO_POINTER(id), notify);
+
+	if (g_hash_table_size(notify_list) == 1) {
+		if (add_membership(netlink, notify->group) == false)
+			goto remove_notify;
+	}
+
+	netlink->next_notify_id++;
+
+	return id;
+
+remove_notify:
+	g_hash_table_remove(notify_list, GUINT_TO_POINTER(id));
+	g_hash_table_remove(netlink->notify_lookup, GUINT_TO_POINTER(id));
+	g_free(notify);
+
+	return 0;
+}
+
+bool netlink_unregister(struct netlink_info *netlink, unsigned int id)
+{
+	GHashTable *notify_list;
+	struct notify *notify;
+
+	if (!netlink || id == 0)
+		return false;
+
+	if (!netlink->notify_groups || !netlink->notify_lookup)
+		return false;
+
+	notify_list = g_hash_table_lookup(netlink->notify_lookup,
+						GUINT_TO_POINTER(id));
+
+	if (!notify_list)
+		return false;
+
+	g_hash_table_remove(netlink->notify_lookup, GUINT_TO_POINTER(id));
+
+	notify = g_hash_table_lookup(notify_list, GUINT_TO_POINTER(id));
+	if (!notify)
+		return false;
+
+	g_hash_table_remove(notify_list, GUINT_TO_POINTER(id));
+
+	if (g_hash_table_size(notify_list) == 0)
+		drop_membership(netlink, notify->group);
+
+	destroy_notify(notify);
+
+	return true;
+}
+
+bool netlink_set_debug(struct netlink_info *netlink,
+			netlink_debug_func_t function,
+			void *user_data, netlink_destroy_func_t destroy)
+{
+	if (!netlink)
+		return false;
+
+	if (netlink->debug_destroy)
+		netlink->debug_destroy(netlink->debug_data);
+
+	netlink->debug_handler = function;
+	netlink->debug_destroy = destroy;
+	netlink->debug_data = user_data;
+
+	return true;
+}
diff --git a/connman/src/shared/netlink.h b/connman/src/shared/netlink.h
new file mode 100644
index 0000000..62bb3e0
--- /dev/null
+++ b/connman/src/shared/netlink.h
@@ -0,0 +1,53 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2011-2012  Intel Corporation. All rights reserved.
+ *  Copyright (C) 2013  BMW Car IT GbmH.
+ *
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License version 2.1 as published by the Free Software Foundation.
+ *
+ *  This library 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 Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#include <stdint.h>
+#include <stdbool.h>
+
+typedef void (*netlink_debug_func_t) (const char *str, void *user_data);
+typedef void (*netlink_command_func_t) (unsigned int error,
+						uint16_t type, const void *data,
+						uint32_t len, void *user_data);
+typedef void (*netlink_notify_func_t) (uint16_t type, const void *data,
+						uint32_t len, void *user_data);
+typedef void (*netlink_destroy_func_t) (void *user_data);
+
+struct netlink_info;
+
+struct netlink_info *netlink_new(int protocol);
+void netlink_destroy(struct netlink_info *netlink);
+
+unsigned int netlink_send(struct netlink_info *netlink,
+			uint16_t type, uint16_t flags, const void *data,
+			uint32_t len, netlink_command_func_t function,
+			void *user_data, netlink_destroy_func_t destroy);
+bool netlink_cancel(struct netlink_info *netlink, unsigned int id);
+
+unsigned int netlink_register(struct netlink_info *netlink,
+			uint32_t group, netlink_notify_func_t function,
+			void *user_data, netlink_destroy_func_t destroy);
+bool netlink_unregister(struct netlink_info *netlink, unsigned int id);
+
+bool netlink_set_debug(struct netlink_info *netlink,
+			netlink_debug_func_t function,
+			void *user_data, netlink_destroy_func_t destroy);
diff --git a/connman/src/shared/util.c b/connman/src/shared/util.c
new file mode 100644
index 0000000..df045c5
--- /dev/null
+++ b/connman/src/shared/util.c
@@ -0,0 +1,90 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2012  Intel Corporation. All rights reserved.
+ *
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  This library 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
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; 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 <stdio.h>
+#include <ctype.h>
+#include <stdarg.h>
+
+#include "src/shared/util.h"
+
+void util_debug(util_debug_func_t function, void *user_data,
+						const char *format, ...)
+{
+	char str[78];
+	va_list ap;
+
+	if (!function || !format)
+		return;
+
+	va_start(ap, format);
+	vsnprintf(str, sizeof(str), format, ap);
+	va_end(ap);
+
+	function(str, user_data);
+}
+
+void util_hexdump(const char dir, const unsigned char *buf, size_t len,
+				util_debug_func_t function, void *user_data)
+{
+	static const char hexdigits[] = "0123456789abcdef";
+	char str[68];
+	size_t i;
+
+	if (!function || !len)
+		return;
+
+	str[0] = dir;
+
+	for (i = 0; i < len; i++) {
+		str[((i % 16) * 3) + 1] = ' ';
+		str[((i % 16) * 3) + 2] = hexdigits[buf[i] >> 4];
+		str[((i % 16) * 3) + 3] = hexdigits[buf[i] & 0xf];
+		str[(i % 16) + 51] = isprint(buf[i]) ? buf[i] : '.';
+
+		if ((i + 1) % 16 == 0) {
+			str[49] = ' ';
+			str[50] = ' ';
+			str[67] = '\0';
+			function(str, user_data);
+			str[0] = ' ';
+		}
+	}
+
+	if (i % 16 > 0) {
+		size_t j;
+		for (j = (i % 16); j < 16; j++) {
+			str[(j * 3) + 1] = ' ';
+			str[(j * 3) + 2] = ' ';
+			str[(j * 3) + 3] = ' ';
+			str[j + 51] = ' ';
+		}
+		str[49] = ' ';
+		str[50] = ' ';
+		str[67] = '\0';
+		function(str, user_data);
+	}
+}
diff --git a/connman/src/shared/util.h b/connman/src/shared/util.h
new file mode 100644
index 0000000..293fb3a
--- /dev/null
+++ b/connman/src/shared/util.h
@@ -0,0 +1,50 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2012  Intel Corporation. All rights reserved.
+ *
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  This library 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
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#include <glib.h>
+
+typedef void (*util_debug_func_t)(const char *str, void *user_data);
+
+void util_debug(util_debug_func_t function, void *user_data,
+						const char *format, ...)
+					__attribute__((format(printf, 3, 4)));
+
+void util_hexdump(const char dir, const unsigned char *buf, size_t len,
+				util_debug_func_t function, void *user_data);
+
+struct cb_data {
+	void *cb;
+	void *user_data;
+	void *data;
+};
+
+static inline struct cb_data *cb_data_new(void *cb, void *user_data)
+{
+	struct cb_data *ret;
+
+	ret = g_new0(struct cb_data, 1);
+	ret->cb = cb;
+	ret->user_data = user_data;
+
+	return ret;
+}
diff --git a/connman/src/stats.c b/connman/src/stats.c
new file mode 100644
index 0000000..26343b1
--- /dev/null
+++ b/connman/src/stats.c
@@ -0,0 +1,825 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2010-2014  BMW Car IT GmbH.
+ *
+ *  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
+
+#define _GNU_SOURCE
+#include <errno.h>
+#include <sys/mman.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <string.h>
+#include <limits.h>
+#include <sys/stat.h>
+
+#include "connman.h"
+
+#define MODE		(S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | \
+			S_IXGRP | S_IROTH | S_IXOTH)
+
+#ifdef TEMP_FAILURE_RETRY
+#define TFR TEMP_FAILURE_RETRY
+#else
+#define TFR
+#endif
+
+#define MAGIC 0xFA00B916
+
+/*
+ * Statistics counters are stored into a ring buffer which is stored
+ * into a file
+ *
+ * File properties:
+ *   The ring buffer is mmap to a file
+ *   Initialy only the smallest possible amount of disk space is allocated
+ *   The files grow to the configured maximal size
+ *   The grows by _SC_PAGESIZE step size
+ *   For each service a file is created
+ *   Each file has a header where the indexes are stored
+ *
+ * Entries properties:
+ *   Each entry has a timestamp
+ *   A flag to mark if the entry is either home (0) or roaming (1) entry
+ *   The entries are fixed sized (stats_record)
+ *
+ * Ring buffer properties:
+ *   There are to indexes 'begin', 'end', 'home' and 'roaming'
+ *   'begin' points to the oldest entry
+ *   'end' points to the newest/current entry
+ *   'home' points to the current home entry
+ *   'roaming' points to the current roaming entry
+ *   If 'begin' == 'end' then the buffer is empty
+ *   If 'end' + 1 == 'begin then it's full
+ *   The ring buffer is valid in the range (begin, end]
+ *   If 'home' has the value UINT_MAX', 'home' is invalid
+ *   if 'roaming' has the value UINT_MAX', 'roaming' is invalid
+ *   'first' points to the first entry in the ring buffer
+ *   'last' points to the last entry in the ring buffer
+ *
+ * History file:
+ *   Same format as the ring buffer file
+ *   For a period of at least 2 months dayly records are keept
+ *   If older, then only a monthly record is keept
+ */
+
+
+struct stats_file_header {
+	unsigned int magic;
+	unsigned int begin;
+	unsigned int end;
+	unsigned int home;
+	unsigned int roaming;
+};
+
+struct stats_record {
+	time_t ts;
+	unsigned int roaming;
+	struct connman_stats_data data;
+};
+
+struct stats_file {
+	int fd;
+	char *name;
+	char *addr;
+	size_t len;
+	size_t max_len;
+
+	/* cached values */
+	struct stats_record *first;
+	struct stats_record *last;
+	struct stats_record *home;
+	struct stats_record *roaming;
+
+	/* history */
+	char *history_name;
+	int account_period_offset;
+};
+
+struct stats_iter {
+	struct stats_file *file;
+	struct stats_record *begin;
+	struct stats_record *end;
+	struct stats_record *it;
+};
+
+static GHashTable *stats_hash = NULL;
+
+static struct stats_file_header *get_hdr(struct stats_file *file)
+{
+	return (struct stats_file_header *)file->addr;
+}
+
+static struct stats_record *get_begin(struct stats_file *file)
+{
+	unsigned int off = get_hdr(file)->begin;
+
+	return (struct stats_record *)(file->addr + off);
+}
+
+static struct stats_record *get_end(struct stats_file *file)
+{
+	unsigned int off = get_hdr(file)->end;
+
+	return (struct stats_record *)(file->addr + off);
+}
+
+static struct stats_record *get_home(struct stats_file *file)
+{
+	struct stats_file_header *hdr;
+
+	hdr = get_hdr(file);
+
+	if (hdr->home == UINT_MAX)
+		return NULL;
+
+	return (struct stats_record *)(file->addr + hdr->home);
+}
+
+static struct stats_record *get_roaming(struct stats_file *file)
+{
+	struct stats_file_header *hdr;
+
+	hdr = get_hdr(file);
+
+	if (hdr->roaming == UINT_MAX)
+		return NULL;
+
+	return (struct stats_record *)(file->addr + hdr->roaming);
+}
+
+static void set_end(struct stats_file *file, struct stats_record *end)
+{
+	struct stats_file_header *hdr;
+
+	hdr = get_hdr(file);
+	hdr->end = (char *)end - file->addr;
+}
+
+static void set_home(struct stats_file *file, struct stats_record *home)
+{
+	struct stats_file_header *hdr;
+
+	hdr = get_hdr(file);
+	hdr->home = (char *)home - file->addr;
+}
+
+static void set_roaming(struct stats_file *file, struct stats_record *roaming)
+{
+	struct stats_file_header *hdr;
+
+	hdr = get_hdr(file);
+	hdr->roaming = (char *)roaming - file->addr;
+}
+
+static struct stats_record *get_next(struct stats_file *file,
+					struct stats_record *cur)
+{
+	cur++;
+
+	if (cur > file->last)
+		cur = file->first;
+
+	return cur;
+}
+
+static struct stats_record *get_iterator_begin(struct stats_file *file)
+{
+	return get_next(file, get_begin(file));
+}
+
+static struct stats_record *get_iterator_end(struct stats_file *file)
+{
+	return get_next(file, get_end(file));
+}
+
+static void stats_free(gpointer user_data)
+{
+	struct stats_file *file = user_data;
+
+	if (!file)
+		return;
+
+	msync(file->addr, file->len, MS_SYNC);
+
+	munmap(file->addr, file->len);
+	file->addr = NULL;
+
+	TFR(close(file->fd));
+	file->fd = -1;
+
+	if (file->history_name) {
+		g_free(file->history_name);
+		file->history_name = NULL;
+	}
+
+	if (file->name) {
+		g_free(file->name);
+		file->name = NULL;
+	}
+
+	g_free(file);
+}
+
+static void update_first(struct stats_file *file)
+{
+	file->first = (struct stats_record *)
+			(file->addr + sizeof(struct stats_file_header));
+}
+
+static void update_last(struct stats_file *file)
+{
+	unsigned int max_entries;
+
+	max_entries = (file->len - sizeof(struct stats_file_header)) /
+			sizeof(struct stats_record);
+	file->last = file->first + max_entries - 1;
+}
+
+static void update_home(struct stats_file *file)
+{
+	file->home = get_home(file);
+}
+
+static void update_roaming(struct stats_file *file)
+{
+	file->roaming = get_roaming(file);
+}
+
+static void stats_file_update_cache(struct stats_file *file)
+{
+	update_first(file);
+	update_last(file);
+	update_home(file);
+	update_roaming(file);
+}
+
+static int stats_file_remap(struct stats_file *file, size_t size)
+{
+	size_t page_size, new_size;
+	void *addr;
+	int err;
+
+	DBG("file %p size %zu addr %p len %zu", file, size, file->addr,
+		file->len);
+
+	page_size = sysconf(_SC_PAGESIZE);
+	new_size = (size + page_size - 1) & ~(page_size - 1);
+
+	err = ftruncate(file->fd, new_size);
+	if (err < 0) {
+		connman_error("ftrunctate error %s for %s",
+				strerror(errno), file->name);
+		return -errno;
+	}
+
+	if (!file->addr) {
+		/*
+		 * Though the buffer is not shared between processes, we still
+		 * have to take MAP_SHARED because MAP_PRIVATE does not
+		 * guarantee that writes will hit the file without an explicit
+		 * call to munmap or msync. For more details please read the
+		 * mmap man pages.
+		 */
+		addr = mmap(NULL, new_size, PROT_READ | PROT_WRITE,
+				MAP_SHARED, file->fd, 0);
+	} else {
+		addr = mremap(file->addr, file->len, new_size, MREMAP_MAYMOVE);
+	}
+
+	if (addr == MAP_FAILED) {
+		connman_error("mmap error %s for %s",
+				strerror(errno), file->name);
+		if (errno == EINVAL) {
+			connman_error("%s might be on a file system, such as "
+					"JFFS2, that does not allow shared "
+					"writable mappings.", file->name);
+		}
+		return -errno;
+	}
+
+	file->addr = addr;
+	file->len = new_size;
+
+	stats_file_update_cache(file);
+
+	return 0;
+}
+
+static int stats_open(struct stats_file *file,
+			const char *name)
+{
+	DBG("file %p name %s", file, name);
+
+	file->name = g_strdup(name);
+
+	file->fd = TFR(open(file->name, O_RDWR | O_CREAT | O_CLOEXEC, 0644));
+	if (file->fd < 0) {
+		connman_error("open error %s for %s",
+				strerror(errno), file->name);
+		g_free(file->name);
+		file->name = NULL;
+		return -errno;
+	}
+
+	return 0;
+}
+
+static int stats_open_temp(struct stats_file *file)
+{
+	file->name = g_strdup_printf("%s/stats.XXXXXX.tmp",
+					STORAGEDIR);
+	file->fd = g_mkstemp_full(file->name, O_RDWR | O_CREAT, 0644);
+	if (file->fd < 0) {
+		connman_error("create tempory file error %s for %s",
+				strerror(errno), file->name);
+		g_free(file->name);
+		file->name = NULL;
+		return -errno;
+	}
+
+	return 0;
+}
+
+static int stats_file_setup(struct stats_file *file)
+{
+	struct stats_file_header *hdr;
+	struct stat st;
+	size_t size = 0;
+	int err;
+
+	DBG("file %p fd %d name %s", file, file->fd, file->name);
+
+	err = fstat(file->fd, &st);
+	if (err < 0) {
+		connman_error("fstat error %s for %s\n",
+			strerror(errno), file->name);
+
+		TFR(close(file->fd));
+		g_free(file->name);
+		file->name = NULL;
+
+		return -errno;
+	}
+
+	size = (size_t)st.st_size;
+	file->max_len = STATS_MAX_FILE_SIZE;
+
+	if (size < (size_t)sysconf(_SC_PAGESIZE))
+		size = sysconf(_SC_PAGESIZE);
+
+	err = stats_file_remap(file, size);
+	if (err < 0) {
+		TFR(close(file->fd));
+		g_free(file->name);
+		file->name = NULL;
+
+		return err;
+	}
+
+	hdr = get_hdr(file);
+
+	if (hdr->magic != MAGIC ||
+			hdr->begin < sizeof(struct stats_file_header) ||
+			hdr->end < sizeof(struct stats_file_header) ||
+			hdr->home < sizeof(struct stats_file_header) ||
+			hdr->roaming < sizeof(struct stats_file_header) ||
+			hdr->begin > file->len ||
+			hdr->end > file->len) {
+		hdr->magic = MAGIC;
+		hdr->begin = sizeof(struct stats_file_header);
+		hdr->end = sizeof(struct stats_file_header);
+		hdr->home = UINT_MAX;
+		hdr->roaming = UINT_MAX;
+
+		stats_file_update_cache(file);
+	}
+
+	return 0;
+}
+
+
+static struct stats_record *get_next_record(struct stats_iter *iter)
+{
+	if (iter->it != iter->end) {
+		struct stats_record *tmp;
+
+		tmp = iter->it;
+		iter->it = get_next(iter->file, iter->it);
+
+		return tmp;
+	}
+
+	return NULL;
+}
+
+static int append_record(struct stats_file *file,
+				struct stats_record *rec)
+{
+	struct stats_record *cur, *next;
+	int err;
+
+	if (file->last == get_end(file)) {
+		err = stats_file_remap(file, file->len +
+					sysconf(_SC_PAGESIZE));
+		if (err < 0)
+			return err;
+
+		stats_file_update_cache(file);
+	}
+
+	cur = get_end(file);
+	next = get_next(file, cur);
+
+	memcpy(next, rec, sizeof(struct stats_record));
+
+	set_end(file, next);
+
+	return 0;
+}
+
+static struct stats_record *process_file(struct stats_iter *iter,
+					struct stats_file *temp_file,
+					struct stats_record *cur,
+					GDate *date_change_step_size,
+					int account_period_offset)
+{
+	struct stats_record *home, *roaming;
+	struct stats_record *next;
+
+	home = NULL;
+	roaming = NULL;
+
+	if (!cur)
+		cur = get_next_record(iter);
+	next = get_next_record(iter);
+
+	while (next) {
+		GDate date_cur;
+		GDate date_next;
+		bool append;
+
+		append = false;
+
+		if (cur->roaming)
+			roaming = cur;
+		else
+			home = cur;
+
+		g_date_set_time_t(&date_cur, cur->ts);
+		g_date_set_time_t(&date_next, next->ts);
+
+		if (g_date_compare(&date_cur, date_change_step_size) < 0) {
+			/* month period size */
+			GDateDay day_cur, day_next;
+			GDateMonth month_cur, month_next;
+
+			month_cur = g_date_get_month(&date_cur);
+			month_next = g_date_get_month(&date_next);
+
+			day_cur = g_date_get_day(&date_cur);
+			day_next = g_date_get_day(&date_next);
+
+			if (day_cur == day_next && month_cur != month_next) {
+				append = true;
+			} else if (day_cur < account_period_offset &&
+					day_next >= account_period_offset) {
+				append = true;
+			}
+		} else {
+			/* day period size */
+			if (g_date_days_between(&date_cur, &date_next) > 0)
+				append = true;
+		}
+
+		if (append) {
+			if (home) {
+				append_record(temp_file, home);
+				home = NULL;
+			}
+
+			if (roaming) {
+				append_record(temp_file, roaming);
+				roaming = NULL;
+			}
+		}
+
+		cur = next;
+		next = get_next_record(iter);
+	}
+
+	return cur;
+}
+
+static int summarize(struct stats_file *data_file,
+			struct stats_file *history_file,
+			struct stats_file *temp_file)
+{
+	struct stats_iter data_iter;
+	struct stats_iter history_iter;
+	struct stats_record *cur, *next;
+
+	GDate today, date_change_step_size;
+
+	/*
+	 * First calculate the date when switch from monthly
+	 * accounting period size to daily size
+	 */
+	g_date_set_time_t(&today, time(NULL));
+
+	date_change_step_size = today;
+	if (g_date_get_day(&today) - data_file->account_period_offset >= 0)
+		g_date_subtract_months(&date_change_step_size, 2);
+	else
+		g_date_subtract_months(&date_change_step_size, 3);
+
+	g_date_set_day(&date_change_step_size,
+			data_file->account_period_offset);
+
+
+	/* Now process history file */
+	cur = NULL;
+
+	if (history_file) {
+		history_iter.file = history_file;
+		history_iter.begin = get_iterator_begin(history_iter.file);
+		history_iter.end = get_iterator_end(history_iter.file);
+		history_iter.it = history_iter.begin;
+
+		cur = process_file(&history_iter, temp_file, NULL,
+					&date_change_step_size,
+					data_file->account_period_offset);
+	}
+
+	data_iter.file = data_file;
+	data_iter.begin = get_iterator_begin(data_iter.file);
+	data_iter.end = get_iterator_end(data_iter.file);
+	data_iter.it = data_iter.begin;
+
+	/*
+	 * Ensure date_file records are newer than the history_file
+	 * record
+	 */
+	if (cur) {
+		next = get_next_record(&data_iter);
+		while (next && cur->ts > next->ts)
+			next = get_next_record(&data_iter);
+	}
+
+	/* And finally process the new data records */
+	cur = process_file(&data_iter, temp_file, cur,
+				&date_change_step_size,
+				data_file->account_period_offset);
+
+	if (cur)
+		append_record(temp_file, cur);
+
+	return 0;
+}
+
+static void stats_file_unmap(struct stats_file *file)
+{
+	msync(file->addr, file->len, MS_SYNC);
+	munmap(file->addr, file->len);
+	file->addr = NULL;
+}
+
+static void stats_file_cleanup(struct stats_file *file)
+{
+	file->fd = -1;
+	g_free(file->name);
+	file->name = NULL;
+}
+
+static int stats_file_close_swap(struct stats_file *history_file,
+					struct stats_file *temp_file)
+{
+	int err;
+
+	stats_file_unmap(history_file);
+	stats_file_unmap(temp_file);
+
+	TFR(close(temp_file->fd));
+
+	unlink(history_file->name);
+
+	err = link(temp_file->name, history_file->name);
+
+	unlink(temp_file->name);
+
+	TFR(close(history_file->fd));
+
+	stats_file_cleanup(history_file);
+	stats_file_cleanup(temp_file);
+
+	return err;
+}
+
+static int stats_file_history_update(struct stats_file *data_file)
+{
+	struct stats_file _history_file, *history_file;
+	struct stats_file _temp_file, *temp_file;
+	int err;
+
+	history_file = &_history_file;
+	temp_file = &_temp_file;
+
+	bzero(history_file, sizeof(struct stats_file));
+	bzero(temp_file, sizeof(struct stats_file));
+
+	err = stats_open(history_file, data_file->history_name);
+	if (err < 0)
+		return err;
+	stats_file_setup(history_file);
+
+	err = stats_open_temp(temp_file);
+	if (err < 0) {
+		stats_free(history_file);
+		return err;
+	}
+	stats_file_setup(temp_file);
+
+	summarize(data_file, history_file, temp_file);
+
+	err = stats_file_close_swap(history_file, temp_file);
+
+	return err;
+}
+
+int __connman_stats_service_register(struct connman_service *service)
+{
+	struct stats_file *file;
+	char *name, *dir;
+	int err;
+
+	DBG("service %p", service);
+
+	file = g_hash_table_lookup(stats_hash, service);
+	if (!file) {
+		file = g_try_new0(struct stats_file, 1);
+		if (!file)
+			return -ENOMEM;
+
+		g_hash_table_insert(stats_hash, service, file);
+	} else {
+		return -EALREADY;
+	}
+
+	dir = g_strdup_printf("%s/%s", STORAGEDIR,
+				__connman_service_get_ident(service));
+
+	/* If the dir doesn't exist, create it */
+	if (!g_file_test(dir, G_FILE_TEST_IS_DIR)) {
+		if (mkdir(dir, MODE) < 0) {
+			if (errno != EEXIST) {
+				g_free(dir);
+
+				err = -errno;
+				goto err;
+			}
+		}
+	}
+
+	g_free(dir);
+
+	name = g_strdup_printf("%s/%s/data", STORAGEDIR,
+				__connman_service_get_ident(service));
+	file->history_name = g_strdup_printf("%s/%s/history", STORAGEDIR,
+				__connman_service_get_ident(service));
+
+	/* TODO: Use a global config file instead of hard coded value. */
+	file->account_period_offset = 1;
+
+	err = stats_open(file, name);
+	g_free(name);
+	if (err < 0)
+		goto err;
+
+	err = stats_file_setup(file);
+	if (err < 0)
+		goto err;
+
+	return 0;
+
+err:
+	g_hash_table_remove(stats_hash, service);
+
+	return err;
+}
+
+void __connman_stats_service_unregister(struct connman_service *service)
+{
+	DBG("service %p", service);
+
+	g_hash_table_remove(stats_hash, service);
+}
+
+int  __connman_stats_update(struct connman_service *service,
+				bool roaming,
+				struct connman_stats_data *data)
+{
+	struct stats_file *file;
+	struct stats_record *next;
+	int err;
+
+	file = g_hash_table_lookup(stats_hash, service);
+	if (!file)
+		return -EEXIST;
+
+	if (file->len < file->max_len &&
+			file->last == get_end(file)) {
+		DBG("grow file %s", file->name);
+
+		err = stats_file_remap(file, file->len + sysconf(_SC_PAGESIZE));
+		if (err < 0)
+			return err;
+	}
+
+	next = get_next(file, get_end(file));
+
+	if (next == get_begin(file)) {
+		DBG("ring buffer is full, update history file");
+
+		if (stats_file_history_update(file) < 0) {
+			connman_warn("history file update failed %s",
+					file->history_name);
+		}
+	}
+
+	next->ts = time(NULL);
+	next->roaming = roaming;
+	memcpy(&next->data, data, sizeof(struct connman_stats_data));
+
+	if (!roaming)
+		set_home(file, next);
+	else
+		set_roaming(file, next);
+
+	set_end(file, next);
+
+	return 0;
+}
+
+int __connman_stats_get(struct connman_service *service,
+				bool roaming,
+				struct connman_stats_data *data)
+{
+	struct stats_file *file;
+	struct stats_record *rec;
+
+	file = g_hash_table_lookup(stats_hash, service);
+	if (!file)
+		return -EEXIST;
+
+	if (!roaming)
+		rec = file->home;
+	else
+		rec = file->roaming;
+
+	if (rec) {
+		memcpy(data, &rec->data,
+			sizeof(struct connman_stats_data));
+	}
+
+	return 0;
+}
+
+int __connman_stats_init(void)
+{
+	DBG("");
+
+	stats_hash = g_hash_table_new_full(g_direct_hash, g_direct_equal,
+							NULL, stats_free);
+
+	return 0;
+}
+
+void __connman_stats_cleanup(void)
+{
+	DBG("");
+
+	g_hash_table_destroy(stats_hash);
+	stats_hash = NULL;
+}
diff --git a/connman/src/storage.c b/connman/src/storage.c
new file mode 100644
index 0000000..7d03130
--- /dev/null
+++ b/connman/src/storage.c
@@ -0,0 +1,478 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2013  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 <unistd.h>
+#include <sys/stat.h>
+#include <dirent.h>
+
+#include <connman/storage.h>
+
+#include "connman.h"
+
+#define SETTINGS	"settings"
+#define DEFAULT		"default.profile"
+
+#define MODE		(S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | \
+			S_IXGRP | S_IROTH | S_IXOTH)
+
+static GKeyFile *storage_load(const char *pathname)
+{
+	GKeyFile *keyfile = NULL;
+	GError *error = NULL;
+
+	DBG("Loading %s", pathname);
+
+	keyfile = g_key_file_new();
+
+	if (!g_key_file_load_from_file(keyfile, pathname, 0, &error)) {
+		DBG("Unable to load %s: %s", pathname, error->message);
+		g_clear_error(&error);
+
+		g_key_file_free(keyfile);
+		keyfile = NULL;
+	}
+
+	return keyfile;
+}
+
+static int storage_save(GKeyFile *keyfile, char *pathname)
+{
+	gchar *data = NULL;
+	gsize length = 0;
+	GError *error = NULL;
+	int ret = 0;
+
+	data = g_key_file_to_data(keyfile, &length, NULL);
+
+	if (!g_file_set_contents(pathname, data, length, &error)) {
+		DBG("Failed to store information: %s", error->message);
+		g_error_free(error);
+		ret = -EIO;
+	}
+
+	g_free(data);
+
+	return ret;
+}
+
+static void storage_delete(const char *pathname)
+{
+	DBG("file path %s", pathname);
+
+	if (unlink(pathname) < 0)
+		connman_error("Failed to remove %s", pathname);
+}
+
+GKeyFile *__connman_storage_load_global(void)
+{
+	gchar *pathname;
+	GKeyFile *keyfile = NULL;
+
+	pathname = g_strdup_printf("%s/%s", STORAGEDIR, SETTINGS);
+	if (!pathname)
+		return NULL;
+
+	keyfile = storage_load(pathname);
+
+	g_free(pathname);
+
+	return keyfile;
+}
+
+int __connman_storage_save_global(GKeyFile *keyfile)
+{
+	gchar *pathname;
+	int ret;
+
+	pathname = g_strdup_printf("%s/%s", STORAGEDIR, SETTINGS);
+	if (!pathname)
+		return -ENOMEM;
+
+	ret = storage_save(keyfile, pathname);
+
+	g_free(pathname);
+
+	return ret;
+}
+
+void __connman_storage_delete_global(void)
+{
+	gchar *pathname;
+
+	pathname = g_strdup_printf("%s/%s", STORAGEDIR, SETTINGS);
+	if (!pathname)
+		return;
+
+	storage_delete(pathname);
+
+	g_free(pathname);
+}
+
+GKeyFile *__connman_storage_load_config(const char *ident)
+{
+	gchar *pathname;
+	GKeyFile *keyfile = NULL;
+
+	pathname = g_strdup_printf("%s/%s.config", STORAGEDIR, ident);
+	if (!pathname)
+		return NULL;
+
+	keyfile = storage_load(pathname);
+
+	g_free(pathname);
+
+	return keyfile;
+}
+
+GKeyFile *__connman_storage_load_provider_config(const char *ident)
+{
+	gchar *pathname;
+	GKeyFile *keyfile = NULL;
+
+	pathname = g_strdup_printf("%s/%s.config", VPN_STORAGEDIR, ident);
+	if (!pathname)
+		return NULL;
+
+	keyfile = storage_load(pathname);
+
+	g_free(pathname);
+
+	return keyfile;
+}
+
+GKeyFile *__connman_storage_open_service(const char *service_id)
+{
+	gchar *pathname;
+	GKeyFile *keyfile = NULL;
+
+	pathname = g_strdup_printf("%s/%s/%s", STORAGEDIR, service_id, SETTINGS);
+	if (!pathname)
+		return NULL;
+
+	keyfile =  storage_load(pathname);
+	if (keyfile) {
+		g_free(pathname);
+		return keyfile;
+	}
+
+	g_free(pathname);
+
+	keyfile = g_key_file_new();
+
+	return keyfile;
+}
+
+gchar **connman_storage_get_services(void)
+{
+	struct dirent *d;
+	gchar *str;
+	DIR *dir;
+	GString *result;
+	gchar **services = NULL;
+	struct stat buf;
+	int ret;
+
+	dir = opendir(STORAGEDIR);
+	if (!dir)
+		return NULL;
+
+	result = g_string_new(NULL);
+
+	while ((d = readdir(dir))) {
+		if (strcmp(d->d_name, ".") == 0 ||
+				strcmp(d->d_name, "..") == 0 ||
+				strncmp(d->d_name, "provider_", 9) == 0)
+			continue;
+
+		switch (d->d_type) {
+		case DT_DIR:
+		case DT_UNKNOWN:
+			/*
+			 * If the settings file is not found, then
+			 * assume this directory is not a services dir.
+			 */
+			str = g_strdup_printf("%s/%s/settings", STORAGEDIR,
+								d->d_name);
+			ret = stat(str, &buf);
+			g_free(str);
+			if (ret < 0)
+				continue;
+
+			g_string_append_printf(result, "%s/", d->d_name);
+			break;
+		}
+	}
+
+	closedir(dir);
+
+	str = g_string_free(result, FALSE);
+	if (str && str[0] != '\0') {
+		/*
+		 * Remove the trailing separator so that services doesn't end up
+		 * with an empty element.
+		 */
+		str[strlen(str) - 1] = '\0';
+		services = g_strsplit(str, "/", -1);
+	}
+	g_free(str);
+
+	return services;
+}
+
+GKeyFile *connman_storage_load_service(const char *service_id)
+{
+	gchar *pathname;
+	GKeyFile *keyfile = NULL;
+
+	pathname = g_strdup_printf("%s/%s/%s", STORAGEDIR, service_id, SETTINGS);
+	if (!pathname)
+		return NULL;
+
+	keyfile =  storage_load(pathname);
+	g_free(pathname);
+
+	return keyfile;
+}
+
+int __connman_storage_save_service(GKeyFile *keyfile, const char *service_id)
+{
+	int ret = 0;
+	gchar *pathname, *dirname;
+
+	dirname = g_strdup_printf("%s/%s", STORAGEDIR, service_id);
+	if (!dirname)
+		return -ENOMEM;
+
+	/* If the dir doesn't exist, create it */
+	if (!g_file_test(dirname, G_FILE_TEST_IS_DIR)) {
+		if (mkdir(dirname, MODE) < 0) {
+			if (errno != EEXIST) {
+				g_free(dirname);
+				return -errno;
+			}
+		}
+	}
+
+	pathname = g_strdup_printf("%s/%s", dirname, SETTINGS);
+
+	g_free(dirname);
+
+	ret = storage_save(keyfile, pathname);
+
+	g_free(pathname);
+
+	return ret;
+}
+
+static bool remove_file(const char *service_id, const char *file)
+{
+	gchar *pathname;
+	bool ret = false;
+
+	pathname = g_strdup_printf("%s/%s/%s", STORAGEDIR, service_id, file);
+	if (!pathname)
+		return false;
+
+	if (!g_file_test(pathname, G_FILE_TEST_EXISTS)) {
+		ret = true;
+	} else if (g_file_test(pathname, G_FILE_TEST_IS_REGULAR)) {
+		unlink(pathname);
+		ret = true;
+	}
+
+	g_free(pathname);
+	return ret;
+}
+
+static bool remove_dir(const char *service_id)
+{
+	gchar *pathname;
+	bool ret = false;
+
+	pathname = g_strdup_printf("%s/%s", STORAGEDIR, service_id);
+	if (!pathname)
+		return false;
+
+	if (!g_file_test(pathname, G_FILE_TEST_EXISTS)) {
+		ret = true;
+	} else if (g_file_test(pathname, G_FILE_TEST_IS_DIR)) {
+		rmdir(pathname);
+		ret = true;
+	}
+
+	g_free(pathname);
+	return ret;
+}
+
+bool __connman_storage_remove_service(const char *service_id)
+{
+	bool removed;
+
+	/* Remove service configuration file */
+	removed = remove_file(service_id, SETTINGS);
+	if (!removed)
+		return false;
+
+	/* Remove the statistics file also */
+	removed = remove_file(service_id, "data");
+	if (!removed)
+		return false;
+
+	removed = remove_dir(service_id);
+	if (!removed)
+		return false;
+
+	DBG("Removed service dir %s/%s", STORAGEDIR, service_id);
+
+	return true;
+}
+
+GKeyFile *__connman_storage_load_provider(const char *identifier)
+{
+	gchar *pathname;
+	GKeyFile *keyfile;
+
+	pathname = g_strdup_printf("%s/%s_%s/%s", STORAGEDIR, "provider",
+			identifier, SETTINGS);
+	if (!pathname)
+		return NULL;
+
+	keyfile = storage_load(pathname);
+	g_free(pathname);
+
+	return keyfile;
+}
+
+void __connman_storage_save_provider(GKeyFile *keyfile, const char *identifier)
+{
+	gchar *pathname, *dirname;
+
+	dirname = g_strdup_printf("%s/%s_%s", STORAGEDIR,
+			"provider", identifier);
+	if (!dirname)
+		return;
+
+	if (!g_file_test(dirname, G_FILE_TEST_IS_DIR) &&
+			mkdir(dirname, MODE) < 0) {
+		g_free(dirname);
+		return;
+	}
+
+	pathname = g_strdup_printf("%s/%s", dirname, SETTINGS);
+	g_free(dirname);
+
+	storage_save(keyfile, pathname);
+	g_free(pathname);
+}
+
+static bool remove_all(const char *id)
+{
+	bool removed;
+
+	remove_file(id, SETTINGS);
+	remove_file(id, "data");
+
+	removed = remove_dir(id);
+	if (!removed)
+		return false;
+
+	return true;
+}
+
+bool __connman_storage_remove_provider(const char *identifier)
+{
+	bool removed;
+	gchar *id;
+
+	id = g_strdup_printf("%s_%s", "provider", identifier);
+	if (!id)
+		return false;
+
+	if (remove_all(id))
+		DBG("Removed provider dir %s/%s", STORAGEDIR, id);
+
+	g_free(id);
+
+	id = g_strdup_printf("%s_%s", "vpn", identifier);
+	if (!id)
+		return false;
+
+	if ((removed = remove_all(id)))
+		DBG("Removed vpn dir %s/%s", STORAGEDIR, id);
+
+	g_free(id);
+
+	return removed;
+}
+
+gchar **__connman_storage_get_providers(void)
+{
+	GSList *list = NULL;
+	int num = 0, i = 0;
+	struct dirent *d;
+	gchar *str;
+	DIR *dir;
+	struct stat buf;
+	int ret;
+	char **providers;
+	GSList *iter;
+
+	dir = opendir(STORAGEDIR);
+	if (!dir)
+		return NULL;
+
+	while ((d = readdir(dir))) {
+		if (strcmp(d->d_name, ".") == 0 ||
+				strcmp(d->d_name, "..") == 0 ||
+				strncmp(d->d_name, "provider_", 9) != 0)
+			continue;
+
+		if (d->d_type == DT_DIR) {
+			str = g_strdup_printf("%s/%s/settings", STORAGEDIR,
+					d->d_name);
+			ret = stat(str, &buf);
+			g_free(str);
+			if (ret < 0)
+				continue;
+			list = g_slist_prepend(list, g_strdup(d->d_name));
+			num += 1;
+		}
+	}
+
+	closedir(dir);
+
+	providers = g_try_new0(char *, num + 1);
+	for (iter = list; iter; iter = g_slist_next(iter)) {
+		if (providers)
+			providers[i] = iter->data;
+		else
+			g_free(iter->data);
+		i += 1;
+	}
+	g_slist_free(list);
+
+	return providers;
+}
diff --git a/connman/src/task.c b/connman/src/task.c
new file mode 100644
index 0000000..8b9e1d9
--- /dev/null
+++ b/connman/src/task.c
@@ -0,0 +1,498 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2012  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 <unistd.h>
+#include <stdarg.h>
+#include <sys/wait.h>
+#include <signal.h>
+
+#include <glib.h>
+
+#include "connman.h"
+
+struct notify_data {
+	connman_task_notify_t func;
+	void *data;
+};
+
+struct connman_task {
+	char *path;
+	pid_t pid;
+	guint child_watch;
+	GPtrArray *argv;
+	GPtrArray *envp;
+	connman_task_exit_t exit_func;
+	void *exit_data;
+	GHashTable *notify;
+};
+
+static GHashTable *task_hash = NULL;
+
+static volatile int task_counter;
+
+static DBusConnection *connection;
+
+static void free_pointer(gpointer data, gpointer user_data)
+{
+	g_free(data);
+}
+
+static void free_task(gpointer data)
+{
+	struct connman_task *task = data;
+
+	DBG("task %p", task);
+
+	g_hash_table_destroy(task->notify);
+	task->notify = NULL;
+
+	if (task->pid > 0)
+		kill(task->pid, SIGTERM);
+
+	if (task->child_watch > 0)
+		g_source_remove(task->child_watch);
+
+	g_ptr_array_foreach(task->envp, free_pointer, NULL);
+	g_ptr_array_free(task->envp, TRUE);
+
+	g_ptr_array_foreach(task->argv, free_pointer, NULL);
+	g_ptr_array_free(task->argv, TRUE);
+
+	g_free(task->path);
+	g_free(task);
+}
+
+/**
+ * connman_task_create:
+ * @program: name of executable
+ *
+ * Allocate a new task of given #program
+ *
+ * Returns: a newly-allocated #connman_task structure
+ */
+struct connman_task *connman_task_create(const char *program)
+{
+	struct connman_task *task;
+	gint counter;
+	char *str;
+
+	DBG("");
+
+	task = g_try_new0(struct connman_task, 1);
+	if (!task)
+		return NULL;
+
+	counter = __sync_fetch_and_add(&task_counter, 1);
+
+	task->path = g_strdup_printf("/task/%d", counter);
+	task->pid = -1;
+
+	task->argv = g_ptr_array_new();
+	task->envp = g_ptr_array_new();
+
+	str = g_strdup(program);
+	g_ptr_array_add(task->argv, str);
+
+	task->notify = g_hash_table_new_full(g_str_hash, g_str_equal,
+							g_free, g_free);
+
+	DBG("task %p", task);
+
+	g_hash_table_insert(task_hash, task->path, task);
+
+	return task;
+}
+
+/**
+ * connman_task_destory:
+ * @task: task structure
+ *
+ * Remove and destory #task
+ */
+void connman_task_destroy(struct connman_task *task)
+{
+	DBG("task %p", task);
+
+	g_hash_table_remove(task_hash, task->path);
+}
+
+/**
+ * connman_task_get_path:
+ * @task: task structure
+ *
+ * Get object path
+ */
+const char *connman_task_get_path(struct connman_task *task)
+{
+	return task->path;
+}
+
+/**
+ * connman_task_add_argument:
+ * @task: task structure
+ * @name: argument name
+ * @format: format string
+ * @Varargs: list of arguments
+ *
+ * Add a new command line argument
+ */
+int connman_task_add_argument(struct connman_task *task,
+				const char *name, const char *format, ...)
+{
+	va_list ap;
+	char *str;
+
+	DBG("task %p arg %s", task, name);
+
+	if (!name)
+		return -EINVAL;
+
+	str = g_strdup(name);
+	g_ptr_array_add(task->argv, str);
+
+	va_start(ap, format);
+
+	if (format) {
+		str = g_strdup_vprintf(format, ap);
+		g_ptr_array_add(task->argv, str);
+	}
+
+	va_end(ap);
+
+	return 0;
+}
+
+/**
+ * connman_task_add_variable:
+ * @task: task structure
+ * @key: variable name
+ * @format: format string
+ * @Varargs: list of arguments
+ *
+ * Add a new environment variable
+ */
+int connman_task_add_variable(struct connman_task *task,
+				const char *key, const char *format, ...)
+{
+	va_list ap;
+	char *str, *val;
+
+	DBG("task %p key %s", task, key);
+
+	if (!key)
+		return -EINVAL;
+
+	va_start(ap, format);
+
+	val = g_strdup_vprintf(format, ap);
+	str = g_strdup_printf("%s=%s", key, format ? format : "");
+	g_ptr_array_add(task->envp, str);
+	g_free(val);
+
+	va_end(ap);
+
+	return 0;
+}
+
+/**
+ * connman_task_set_notify:
+ * @task: task structure
+ * @member: notifcation method name
+ * @function: notification callback
+ * @user_data: optional notification user data
+ *
+ * Set notification handler for #member
+ */
+int connman_task_set_notify(struct connman_task *task, const char *member,
+			connman_task_notify_t function, void *user_data)
+{
+	struct notify_data *notify;
+
+	DBG("task %p", task);
+
+	notify = g_try_new0(struct notify_data, 1);
+	if (!notify)
+		return -ENOMEM;
+
+	notify->func = function;
+	notify->data = user_data;
+
+	g_hash_table_replace(task->notify, g_strdup(member), notify);
+
+	return 0;
+}
+
+static void task_died(GPid pid, gint status, gpointer user_data)
+{
+	struct connman_task *task = user_data;
+	int exit_code;
+
+	if (WIFEXITED(status)) {
+		exit_code = WEXITSTATUS(status);
+		DBG("task %p exit status %d", task, exit_code);
+	} else {
+		exit_code = 0;
+		DBG("task %p signal %d", task, WTERMSIG(status));
+	}
+
+	g_spawn_close_pid(pid);
+	task->pid = -1;
+
+	task->child_watch = 0;
+
+	if (task->exit_func)
+		task->exit_func(task, exit_code, task->exit_data);
+}
+
+static void task_setup(gpointer user_data)
+{
+	sigset_t mask;
+	struct connman_task *task = user_data;
+
+	DBG("task %p", task);
+
+	sigemptyset(&mask);
+	if (sigprocmask(SIG_SETMASK, &mask, NULL) < 0)
+		connman_error("Failed to clean signal mask");
+}
+
+/**
+ * connman_task_run:
+ * @task: task structure
+ * @function: exit callback
+ * @user_data: optional exit user data
+ * @fd: optional spawn with pipe
+ *
+ * Execute program specified by #task
+ */
+int connman_task_run(struct connman_task *task,
+			connman_task_exit_t function, void *user_data,
+			int *stdin_fd, int *stdout_fd, int *stderr_fd)
+{
+	GSpawnFlags flags = G_SPAWN_DO_NOT_REAP_CHILD;
+	bool result;
+	char **argv, **envp;
+
+	DBG("task %p", task);
+
+	if (task->pid > 0)
+		return -EALREADY;
+
+	if (!stdout_fd)
+		flags |= G_SPAWN_STDOUT_TO_DEV_NULL;
+
+	if (!stderr_fd)
+		flags |= G_SPAWN_STDERR_TO_DEV_NULL;
+
+	task->exit_func = function;
+	task->exit_data = user_data;
+
+	if (g_ptr_array_index(task->argv, task->argv->len - 1))
+		g_ptr_array_add(task->argv, NULL);
+
+	if (task->envp->len == 0 ||
+			g_ptr_array_index(task->envp, task->envp->len - 1)) {
+		if (g_hash_table_size(task->notify) > 0) {
+			const char *busname;
+			char *str;
+
+			busname = dbus_bus_get_unique_name(connection);
+			str = g_strdup_printf("CONNMAN_BUSNAME=%s", busname);
+			g_ptr_array_add(task->envp, str);
+
+			str = g_strdup_printf("CONNMAN_INTERFACE=%s",
+						CONNMAN_TASK_INTERFACE);
+			g_ptr_array_add(task->envp, str);
+
+			str = g_strdup_printf("CONNMAN_PATH=%s", task->path);
+			g_ptr_array_add(task->envp, str);
+		}
+
+		g_ptr_array_add(task->envp, NULL);
+	}
+
+	argv = (char **) task->argv->pdata;
+	envp = (char **) task->envp->pdata;
+
+	result = g_spawn_async_with_pipes(NULL, argv, envp, flags,
+					task_setup, task, &task->pid,
+					stdin_fd, stdout_fd, stderr_fd, NULL);
+	if (!result) {
+		connman_error("Failed to spawn %s", argv[0]);
+		return -EIO;
+	}
+
+	task->child_watch = g_child_watch_add(task->pid, task_died, task);
+
+	return 0;
+}
+
+static gboolean force_kill_timeout(gpointer user_data)
+{
+	pid_t pid = GPOINTER_TO_INT(user_data);
+	if (pid > 0) {
+		if (kill(pid, SIGKILL) == 0)
+			connman_warn("killing pid %d by force", pid);
+	}
+
+	return FALSE;
+}
+
+static gboolean kill_timeout(gpointer user_data)
+{
+	pid_t pid = GPOINTER_TO_INT(user_data);
+	if (pid > 0) {
+		if (kill(pid, SIGINT) == 0)
+			g_timeout_add_seconds(1, force_kill_timeout,
+					GINT_TO_POINTER(pid));
+	}
+
+	return FALSE;
+}
+
+static gboolean check_kill(gpointer user_data)
+{
+	pid_t pid = GPOINTER_TO_INT(user_data);
+	if (pid > 0) {
+		if (kill(pid, 0) == 0) {
+			connman_info("pid %d was not killed, "
+					"retrying after 2 sec", pid);
+			g_timeout_add_seconds(2, kill_timeout,
+					GINT_TO_POINTER(pid));
+		}
+	}
+
+	return FALSE;
+}
+
+/**
+ * connman_task_stop:
+ * @task: task structure
+ *
+ * Stop program specified by #task
+ */
+int connman_task_stop(struct connman_task *task)
+{
+	DBG("task %p", task);
+
+	if (task->pid > 0) {
+		kill(task->pid, SIGTERM);
+
+		g_timeout_add_seconds(0, check_kill,
+				GINT_TO_POINTER(task->pid));
+	}
+
+	return 0;
+}
+
+static DBusHandlerResult task_filter(DBusConnection *conn,
+					DBusMessage *message, void *user_data)
+{
+	struct connman_task *task;
+	struct notify_data *notify;
+	const char *path, *member;
+	DBusMessage *reply = NULL;
+
+	if (dbus_message_get_type(message) != DBUS_MESSAGE_TYPE_METHOD_CALL)
+		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+	if (!dbus_message_has_interface(message, CONNMAN_TASK_INTERFACE))
+		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+	path = dbus_message_get_path(message);
+	if (!path)
+		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+	task = g_hash_table_lookup(task_hash, path);
+	if (!task)
+		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+	member = dbus_message_get_member(message);
+	if (!member)
+		goto send_reply;
+
+	notify = g_hash_table_lookup(task->notify, member);
+	if (!notify)
+		goto send_reply;
+
+	if (notify->func)
+		reply = notify->func(task, message, notify->data);
+
+send_reply:
+	if (!dbus_message_get_no_reply(message) &&
+						!reply) {
+
+		reply = dbus_message_new_method_return(message);
+		if (!reply)
+			return DBUS_HANDLER_RESULT_NEED_MEMORY;
+	}
+
+	if (reply) {
+		dbus_connection_send(conn, reply, NULL);
+
+		dbus_message_unref(reply);
+	}
+
+	return DBUS_HANDLER_RESULT_HANDLED;
+}
+
+static const char *task_rule = "type=method_call"
+					",interface=" CONNMAN_TASK_INTERFACE;
+
+int __connman_task_init(void)
+{
+	DBG("");
+
+	connection = connman_dbus_get_connection();
+
+	dbus_connection_add_filter(connection, task_filter, NULL, NULL);
+
+	task_counter = 0;
+	__sync_synchronize();
+
+	task_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
+							NULL, free_task);
+
+	dbus_bus_add_match(connection, task_rule, NULL);
+	dbus_connection_flush(connection);
+
+	return 0;
+}
+
+void __connman_task_cleanup(void)
+{
+	DBG("");
+
+	dbus_bus_remove_match(connection, task_rule, NULL);
+	dbus_connection_flush(connection);
+
+	g_hash_table_destroy(task_hash);
+	task_hash = NULL;
+
+	dbus_connection_remove_filter(connection, task_filter, NULL);
+
+	dbus_connection_unref(connection);
+}
diff --git a/connman/src/technology.c b/connman/src/technology.c
new file mode 100644
index 0000000..bd5aaa8
--- /dev/null
+++ b/connman/src/technology.c
@@ -0,0 +1,1850 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2013  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 <string.h>
+
+#include <gdbus.h>
+
+#include "connman.h"
+
+static DBusConnection *connection;
+
+static GSList *technology_list = NULL;
+
+/*
+ * List of devices with no technology associated with them either because of
+ * no compiled in support or the driver is not yet loaded.
+*/
+static GSList *techless_device_list = NULL;
+static GHashTable *rfkill_list;
+
+static bool global_offlinemode;
+
+struct connman_rfkill {
+	unsigned int index;
+	enum connman_service_type type;
+	bool softblock;
+	bool hardblock;
+};
+
+struct connman_technology {
+	int refcount;
+	enum connman_service_type type;
+	char *path;
+	GSList *device_list;
+	bool enabled;
+	char *regdom;
+	bool connected;
+
+	bool tethering;
+	bool tethering_persistent; /* Tells the save status, needed
+					      * as offline mode might set
+					      * tethering OFF.
+					      */
+	char *tethering_ident;
+	char *tethering_passphrase;
+
+	bool enable_persistent; /* Save the tech state */
+
+	GSList *driver_list;
+
+	DBusMessage *pending_reply;
+	guint pending_timeout;
+
+	GSList *scan_pending;
+
+	bool rfkill_driven;
+	bool softblocked;
+	bool hardblocked;
+	bool dbus_registered;
+};
+
+static GSList *driver_list = NULL;
+
+static int technology_enabled(struct connman_technology *technology);
+static int technology_disabled(struct connman_technology *technology);
+
+static gint compare_priority(gconstpointer a, gconstpointer b)
+{
+	const struct connman_technology_driver *driver1 = a;
+	const struct connman_technology_driver *driver2 = b;
+
+	return driver2->priority - driver1->priority;
+}
+
+static void rfkill_check(gpointer key, gpointer value, gpointer user_data)
+{
+	struct connman_rfkill *rfkill = value;
+	enum connman_service_type type = GPOINTER_TO_INT(user_data);
+
+	/* Calling _technology_rfkill_add will update the tech. */
+	if (rfkill->type == type)
+		__connman_technology_add_rfkill(rfkill->index, type,
+				rfkill->softblock, rfkill->hardblock);
+}
+
+bool
+connman_technology_is_tethering_allowed(enum connman_service_type type)
+{
+	static char *allowed_default[] = { "wifi", "bluetooth", "gadget",
+					   NULL };
+	const char *type_str = __connman_service_type2string(type);
+	char **allowed;
+	int i;
+
+	if (!type_str)
+		return false;
+
+	allowed = connman_setting_get_string_list("TetheringTechnologies");
+	if (!allowed)
+		allowed = allowed_default;
+
+	for (i = 0; allowed[i]; i++) {
+		if (g_strcmp0(allowed[i], type_str) == 0)
+			return true;
+	}
+
+	return false;
+}
+
+static const char *get_name(enum connman_service_type type)
+{
+	switch (type) {
+	case CONNMAN_SERVICE_TYPE_UNKNOWN:
+	case CONNMAN_SERVICE_TYPE_SYSTEM:
+	case CONNMAN_SERVICE_TYPE_GPS:
+	case CONNMAN_SERVICE_TYPE_VPN:
+		break;
+	case CONNMAN_SERVICE_TYPE_GADGET:
+		return "Gadget";
+	case CONNMAN_SERVICE_TYPE_ETHERNET:
+		return "Wired";
+	case CONNMAN_SERVICE_TYPE_WIFI:
+		return "WiFi";
+	case CONNMAN_SERVICE_TYPE_BLUETOOTH:
+		return "Bluetooth";
+	case CONNMAN_SERVICE_TYPE_CELLULAR:
+		return "Cellular";
+	case CONNMAN_SERVICE_TYPE_P2P:
+		return "P2P";
+	case CONNMAN_SERVICE_TYPE_LOWPAN:
+		return "Thread";
+	}
+
+	return NULL;
+}
+
+static void technology_save(struct connman_technology *technology)
+{
+	GKeyFile *keyfile;
+	gchar *identifier;
+	const char *name = get_name(technology->type);
+
+	DBG("technology %p type %d name %s", technology, technology->type,
+									name);
+	if (!name)
+		return;
+
+	keyfile = __connman_storage_load_global();
+	if (!keyfile)
+		keyfile = g_key_file_new();
+
+	identifier = g_strdup_printf("%s", name);
+	if (!identifier)
+		goto done;
+
+	g_key_file_set_boolean(keyfile, identifier, "Enable",
+				technology->enable_persistent);
+
+	g_key_file_set_boolean(keyfile, identifier, "Tethering",
+				technology->tethering_persistent);
+
+	if (technology->tethering_ident)
+		g_key_file_set_string(keyfile, identifier,
+					"Tethering.Identifier",
+					technology->tethering_ident);
+
+	if (technology->tethering_passphrase)
+		g_key_file_set_string(keyfile, identifier,
+					"Tethering.Passphrase",
+					technology->tethering_passphrase);
+
+done:
+	g_free(identifier);
+
+	__connman_storage_save_global(keyfile);
+
+	g_key_file_free(keyfile);
+
+	return;
+}
+
+static void tethering_changed(struct connman_technology *technology)
+{
+	dbus_bool_t tethering = technology->tethering;
+
+	connman_dbus_property_changed_basic(technology->path,
+				CONNMAN_TECHNOLOGY_INTERFACE, "Tethering",
+						DBUS_TYPE_BOOLEAN, &tethering);
+
+	technology_save(technology);
+}
+
+void connman_technology_tethering_notify(struct connman_technology *technology,
+							bool enabled)
+{
+	DBG("technology %p enabled %u", technology, enabled);
+
+	if (technology->tethering == enabled)
+		return;
+
+	technology->tethering = enabled;
+
+	tethering_changed(technology);
+
+	if (enabled)
+		__connman_tethering_set_enabled();
+	else
+		__connman_tethering_set_disabled();
+}
+
+static int set_tethering(struct connman_technology *technology,
+				bool enabled)
+{
+	int result = -EOPNOTSUPP;
+	int err;
+	const char *ident, *passphrase, *bridge;
+	GSList *tech_drivers;
+
+	ident = technology->tethering_ident;
+	passphrase = technology->tethering_passphrase;
+
+	__sync_synchronize();
+	if (!technology->enabled)
+		return -EACCES;
+
+	bridge = __connman_tethering_get_bridge();
+	if (!bridge)
+		return -EOPNOTSUPP;
+
+	if (technology->type == CONNMAN_SERVICE_TYPE_WIFI &&
+	    (!ident || !passphrase))
+		return -EINVAL;
+
+	for (tech_drivers = technology->driver_list; tech_drivers;
+	     tech_drivers = g_slist_next(tech_drivers)) {
+		struct connman_technology_driver *driver = tech_drivers->data;
+
+		if (!driver || !driver->set_tethering)
+			continue;
+
+		err = driver->set_tethering(technology, ident, passphrase,
+				bridge, enabled);
+
+		if (result == -EINPROGRESS)
+			continue;
+
+		if (err == -EINPROGRESS || err == 0) {
+			result = err;
+			continue;
+		}
+	}
+
+	return result;
+}
+
+void connman_technology_regdom_notify(struct connman_technology *technology,
+							const char *alpha2)
+{
+	DBG("");
+
+	if (!alpha2)
+		connman_error("Failed to set regulatory domain");
+	else
+		DBG("Regulatory domain set to %s", alpha2);
+
+	g_free(technology->regdom);
+	technology->regdom = g_strdup(alpha2);
+}
+
+static int set_regdom_by_device(struct connman_technology *technology,
+							const char *alpha2)
+{
+	GSList *list;
+
+	for (list = technology->device_list; list; list = list->next) {
+		struct connman_device *device = list->data;
+
+		if (connman_device_set_regdom(device, alpha2) != 0)
+			return -ENOTSUP;
+	}
+
+	return 0;
+}
+
+int connman_technology_set_regdom(const char *alpha2)
+{
+	GSList *list, *tech_drivers;
+
+	for (list = technology_list; list; list = list->next) {
+		struct connman_technology *technology = list->data;
+
+		if (set_regdom_by_device(technology, alpha2) != 0) {
+
+			for (tech_drivers = technology->driver_list;
+			     tech_drivers;
+			     tech_drivers = g_slist_next(tech_drivers)) {
+
+				struct connman_technology_driver *driver =
+					tech_drivers->data;
+
+				if (driver->set_regdom)
+					driver->set_regdom(technology, alpha2);
+			}
+		}
+	}
+
+	return 0;
+}
+
+static struct connman_technology *technology_find(enum connman_service_type type)
+{
+	GSList *list;
+
+	DBG("type %d", type);
+
+	for (list = technology_list; list; list = list->next) {
+		struct connman_technology *technology = list->data;
+
+		if (technology->type == type)
+			return technology;
+	}
+
+	return NULL;
+}
+
+bool connman_technology_get_wifi_tethering(const char **ssid,
+							const char **psk)
+{
+	struct connman_technology *technology;
+
+	if (!ssid || !psk)
+		return false;
+
+	*ssid = *psk = NULL;
+
+	technology = technology_find(CONNMAN_SERVICE_TYPE_WIFI);
+	if (!technology)
+		return false;
+
+	if (!technology->tethering)
+		return false;
+
+	*ssid = technology->tethering_ident;
+	*psk = technology->tethering_passphrase;
+
+	return true;
+}
+
+static void free_rfkill(gpointer data)
+{
+	struct connman_rfkill *rfkill = data;
+
+	g_free(rfkill);
+}
+
+static void technology_load(struct connman_technology *technology)
+{
+	GKeyFile *keyfile;
+	gchar *identifier;
+	GError *error = NULL;
+	bool enable, need_saving = false;
+
+	DBG("technology %p", technology);
+
+	keyfile = __connman_storage_load_global();
+	/* Fallback on disabling technology if file not found. */
+	if (!keyfile) {
+		if (technology->type == CONNMAN_SERVICE_TYPE_ETHERNET)
+			/* We enable ethernet by default */
+			technology->enable_persistent = true;
+		else
+			technology->enable_persistent = false;
+		return;
+	}
+
+	identifier = g_strdup_printf("%s", get_name(technology->type));
+	if (!identifier)
+		goto done;
+
+	enable = g_key_file_get_boolean(keyfile, identifier, "Enable", &error);
+	if (!error)
+		technology->enable_persistent = enable;
+	else {
+		if (technology->type == CONNMAN_SERVICE_TYPE_ETHERNET)
+			technology->enable_persistent = true;
+		else
+			technology->enable_persistent = false;
+
+		need_saving = true;
+		g_clear_error(&error);
+	}
+
+	enable = g_key_file_get_boolean(keyfile, identifier,
+					"Tethering", &error);
+	if (!error)
+		technology->tethering_persistent = enable;
+	else {
+		need_saving = true;
+		g_clear_error(&error);
+	}
+
+	if (need_saving)
+		technology_save(technology);
+
+	technology->tethering_ident = g_key_file_get_string(keyfile,
+				identifier, "Tethering.Identifier", NULL);
+
+	technology->tethering_passphrase = g_key_file_get_string(keyfile,
+				identifier, "Tethering.Passphrase", NULL);
+done:
+	g_free(identifier);
+
+	g_key_file_free(keyfile);
+
+	return;
+}
+
+bool __connman_technology_get_offlinemode(void)
+{
+	return global_offlinemode;
+}
+
+static void connman_technology_save_offlinemode(void)
+{
+	GKeyFile *keyfile;
+
+	keyfile = __connman_storage_load_global();
+	if (!keyfile)
+		keyfile = g_key_file_new();
+
+	g_key_file_set_boolean(keyfile, "global",
+					"OfflineMode", global_offlinemode);
+
+	__connman_storage_save_global(keyfile);
+
+	g_key_file_free(keyfile);
+
+	return;
+}
+
+static bool connman_technology_load_offlinemode(void)
+{
+	GKeyFile *keyfile;
+	GError *error = NULL;
+	bool offlinemode;
+
+	/* If there is a error, we enable offlinemode */
+	keyfile = __connman_storage_load_global();
+	if (!keyfile)
+		return false;
+
+	offlinemode = g_key_file_get_boolean(keyfile, "global",
+						"OfflineMode", &error);
+	if (error) {
+		offlinemode = false;
+		g_clear_error(&error);
+	}
+
+	g_key_file_free(keyfile);
+
+	return offlinemode;
+}
+
+static void append_properties(DBusMessageIter *iter,
+		struct connman_technology *technology)
+{
+	DBusMessageIter dict;
+	dbus_bool_t val;
+	const char *str;
+
+	connman_dbus_dict_open(iter, &dict);
+
+	str = get_name(technology->type);
+	if (str)
+		connman_dbus_dict_append_basic(&dict, "Name",
+						DBUS_TYPE_STRING, &str);
+
+	str = __connman_service_type2string(technology->type);
+	if (str)
+		connman_dbus_dict_append_basic(&dict, "Type",
+						DBUS_TYPE_STRING, &str);
+
+	__sync_synchronize();
+	val = technology->enabled;
+	connman_dbus_dict_append_basic(&dict, "Powered",
+					DBUS_TYPE_BOOLEAN,
+					&val);
+
+	val = technology->connected;
+	connman_dbus_dict_append_basic(&dict, "Connected",
+					DBUS_TYPE_BOOLEAN,
+					&val);
+
+	val = technology->tethering;
+	connman_dbus_dict_append_basic(&dict, "Tethering",
+					DBUS_TYPE_BOOLEAN,
+					&val);
+
+	if (technology->tethering_ident)
+		connman_dbus_dict_append_basic(&dict, "TetheringIdentifier",
+					DBUS_TYPE_STRING,
+					&technology->tethering_ident);
+
+	if (technology->tethering_passphrase)
+		connman_dbus_dict_append_basic(&dict, "TetheringPassphrase",
+					DBUS_TYPE_STRING,
+					&technology->tethering_passphrase);
+
+	connman_dbus_dict_close(iter, &dict);
+}
+
+static void technology_added_signal(struct connman_technology *technology)
+{
+	DBusMessage *signal;
+	DBusMessageIter iter;
+
+	signal = dbus_message_new_signal(CONNMAN_MANAGER_PATH,
+			CONNMAN_MANAGER_INTERFACE, "TechnologyAdded");
+	if (!signal)
+		return;
+
+	dbus_message_iter_init_append(signal, &iter);
+	dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
+							&technology->path);
+	append_properties(&iter, technology);
+
+	dbus_connection_send(connection, signal, NULL);
+	dbus_message_unref(signal);
+}
+
+static void technology_removed_signal(struct connman_technology *technology)
+{
+	g_dbus_emit_signal(connection, CONNMAN_MANAGER_PATH,
+			CONNMAN_MANAGER_INTERFACE, "TechnologyRemoved",
+			DBUS_TYPE_OBJECT_PATH, &technology->path,
+			DBUS_TYPE_INVALID);
+}
+
+static DBusMessage *get_properties(DBusConnection *conn,
+					DBusMessage *message, void *user_data)
+{
+	struct connman_technology *technology = user_data;
+	DBusMessage *reply;
+	DBusMessageIter iter;
+
+	reply = dbus_message_new_method_return(message);
+	if (!reply)
+		return NULL;
+
+	dbus_message_iter_init_append(reply, &iter);
+	append_properties(&iter, technology);
+
+	return reply;
+}
+
+void __connman_technology_list_struct(DBusMessageIter *array)
+{
+	GSList *list;
+	DBusMessageIter entry;
+
+	for (list = technology_list; list; list = list->next) {
+		struct connman_technology *technology = list->data;
+
+		if (!technology->path ||
+				(technology->rfkill_driven &&
+				 technology->hardblocked))
+			continue;
+
+		dbus_message_iter_open_container(array, DBUS_TYPE_STRUCT,
+				NULL, &entry);
+		dbus_message_iter_append_basic(&entry, DBUS_TYPE_OBJECT_PATH,
+				&technology->path);
+		append_properties(&entry, technology);
+		dbus_message_iter_close_container(array, &entry);
+	}
+}
+
+static gboolean technology_pending_reply(gpointer user_data)
+{
+	struct connman_technology *technology = user_data;
+	DBusMessage *reply;
+
+	/* Power request timedout, send ETIMEDOUT. */
+	if (technology->pending_reply) {
+		reply = __connman_error_failed(technology->pending_reply, ETIMEDOUT);
+		if (reply)
+			g_dbus_send_message(connection, reply);
+
+		dbus_message_unref(technology->pending_reply);
+		technology->pending_reply = NULL;
+		technology->pending_timeout = 0;
+	}
+
+	return FALSE;
+}
+
+static int technology_affect_devices(struct connman_technology *technology,
+						bool enable_device)
+{
+	int err = 0, err_dev;
+	GSList *list;
+
+	if (technology->type == CONNMAN_SERVICE_TYPE_P2P) {
+		if (enable_device)
+			__connman_technology_enabled(technology->type);
+		else
+			__connman_technology_disabled(technology->type);
+		return 0;
+	}
+
+	for (list = technology->device_list; list; list = list->next) {
+		struct connman_device *device = list->data;
+
+		if (enable_device)
+			err_dev = __connman_device_enable(device);
+		else
+			err_dev = __connman_device_disable(device);
+
+		if (err_dev < 0 && err_dev != -EALREADY)
+			err = err_dev;
+	}
+
+	return err;
+}
+
+static void powered_changed(struct connman_technology *technology)
+{
+	dbus_bool_t enabled;
+
+	if (!technology->dbus_registered)
+		return;
+
+	if (technology->pending_reply) {
+		g_dbus_send_reply(connection,
+				technology->pending_reply, DBUS_TYPE_INVALID);
+		dbus_message_unref(technology->pending_reply);
+		technology->pending_reply = NULL;
+
+		g_source_remove(technology->pending_timeout);
+		technology->pending_timeout = 0;
+	}
+
+	__sync_synchronize();
+	enabled = technology->enabled;
+	connman_dbus_property_changed_basic(technology->path,
+			CONNMAN_TECHNOLOGY_INTERFACE, "Powered",
+			DBUS_TYPE_BOOLEAN, &enabled);
+}
+
+static void enable_tethering(struct connman_technology *technology)
+{
+	int ret;
+
+	if (!connman_setting_get_bool("PersistentTetheringMode"))
+		return;
+
+	ret = set_tethering(technology, true);
+	if (ret < 0 && ret != -EALREADY)
+		DBG("Cannot enable tethering yet for %s (%d/%s)",
+			get_name(technology->type),
+			-ret, strerror(-ret));
+}
+
+static int technology_enabled(struct connman_technology *technology)
+{
+	__sync_synchronize();
+	if (technology->enabled)
+		return -EALREADY;
+
+	technology->enabled = true;
+
+	if (technology->type == CONNMAN_SERVICE_TYPE_WIFI) {
+		struct connman_technology *p2p;
+
+		p2p = technology_find(CONNMAN_SERVICE_TYPE_P2P);
+		if (p2p && !p2p->enabled && p2p->enable_persistent)
+			technology_enabled(p2p);
+	}
+
+	if (technology->tethering_persistent)
+		enable_tethering(technology);
+
+	powered_changed(technology);
+
+	return 0;
+}
+
+static int technology_enable(struct connman_technology *technology)
+{
+	int err = 0;
+	int err_dev;
+
+	DBG("technology %p enable", technology);
+
+	__sync_synchronize();
+
+	if (technology->type == CONNMAN_SERVICE_TYPE_P2P) {
+		struct connman_technology *wifi;
+
+		wifi = technology_find(CONNMAN_SERVICE_TYPE_WIFI);
+		if (wifi && wifi->enabled)
+			return technology_enabled(technology);
+		return 0;
+	}
+
+	if (technology->enabled)
+		return -EALREADY;
+
+	if (technology->pending_reply)
+		return -EBUSY;
+
+	if (connman_setting_get_bool("PersistentTetheringMode")	&&
+					technology->tethering)
+		set_tethering(technology, true);
+
+	if (technology->rfkill_driven)
+		err = __connman_rfkill_block(technology->type, false);
+
+	err_dev = technology_affect_devices(technology, true);
+
+	if (!technology->rfkill_driven)
+		err = err_dev;
+
+	return err;
+}
+
+static int technology_disabled(struct connman_technology *technology)
+{
+	__sync_synchronize();
+	if (!technology->enabled)
+		return -EALREADY;
+
+	technology->enabled = false;
+
+	powered_changed(technology);
+
+	return 0;
+}
+
+static int technology_disable(struct connman_technology *technology)
+{
+	int err;
+
+	DBG("technology %p disable", technology);
+
+	__sync_synchronize();
+
+	if (technology->type == CONNMAN_SERVICE_TYPE_P2P) {
+		technology->enable_persistent = false;
+		return technology_disabled(technology);
+	} else if (technology->type == CONNMAN_SERVICE_TYPE_WIFI) {
+		struct connman_technology *p2p;
+
+		p2p = technology_find(CONNMAN_SERVICE_TYPE_P2P);
+		if (p2p && p2p->enabled) {
+			p2p->enable_persistent = true;
+			technology_disabled(p2p);
+		}
+	}
+
+	if (!technology->enabled)
+		return -EALREADY;
+
+	if (technology->pending_reply)
+		return -EBUSY;
+
+	if (technology->tethering)
+		set_tethering(technology, false);
+
+	err = technology_affect_devices(technology, false);
+
+	if (technology->rfkill_driven)
+		err = __connman_rfkill_block(technology->type, true);
+
+	return err;
+}
+
+static DBusMessage *set_powered(struct connman_technology *technology,
+				DBusMessage *msg, bool powered)
+{
+	DBusMessage *reply = NULL;
+	int err = 0;
+
+	if (technology->rfkill_driven && technology->hardblocked) {
+		err = -EACCES;
+		goto make_reply;
+	}
+
+	if (powered)
+		err = technology_enable(technology);
+	else
+		err = technology_disable(technology);
+
+	if (err != -EBUSY) {
+		technology->enable_persistent = powered;
+		technology_save(technology);
+	}
+
+make_reply:
+	if (err == -EINPROGRESS) {
+		technology->pending_reply = dbus_message_ref(msg);
+		technology->pending_timeout = g_timeout_add_seconds(10,
+					technology_pending_reply, technology);
+	} else if (err == -EALREADY) {
+		if (powered)
+			reply = __connman_error_already_enabled(msg);
+		else
+			reply = __connman_error_already_disabled(msg);
+	} else if (err < 0)
+		reply = __connman_error_failed(msg, -err);
+	else
+		reply = g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+
+	return reply;
+}
+
+static DBusMessage *set_property(DBusConnection *conn,
+					DBusMessage *msg, void *data)
+{
+	struct connman_technology *technology = data;
+	DBusMessageIter iter, value;
+	const char *name;
+	int type;
+
+	DBG("conn %p", conn);
+
+	if (!dbus_message_iter_init(msg, &iter))
+		return __connman_error_invalid_arguments(msg);
+
+	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
+		return __connman_error_invalid_arguments(msg);
+
+	dbus_message_iter_get_basic(&iter, &name);
+	dbus_message_iter_next(&iter);
+
+	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT)
+		return __connman_error_invalid_arguments(msg);
+
+	dbus_message_iter_recurse(&iter, &value);
+
+	type = dbus_message_iter_get_arg_type(&value);
+
+	DBG("property %s", name);
+
+	if (g_str_equal(name, "Tethering")) {
+		dbus_bool_t tethering;
+		int err;
+
+		if (type != DBUS_TYPE_BOOLEAN)
+			return __connman_error_invalid_arguments(msg);
+
+		if (!connman_technology_is_tethering_allowed(technology->type)) {
+			DBG("%s tethering not allowed by config file",
+				__connman_service_type2string(technology->type));
+			return __connman_error_not_supported(msg);
+		}
+
+		dbus_message_iter_get_basic(&value, &tethering);
+
+		if (technology->tethering == tethering) {
+			if (!tethering)
+				return __connman_error_already_disabled(msg);
+			else
+				return __connman_error_already_enabled(msg);
+		}
+
+		err = set_tethering(technology, tethering);
+		if (err < 0)
+			return __connman_error_failed(msg, -err);
+
+		technology->tethering_persistent = tethering;
+
+		technology_save(technology);
+
+	} else if (g_str_equal(name, "TetheringIdentifier")) {
+		const char *str;
+
+		dbus_message_iter_get_basic(&value, &str);
+
+		if (technology->type != CONNMAN_SERVICE_TYPE_WIFI)
+			return __connman_error_not_supported(msg);
+
+		if (strlen(str) < 1 || strlen(str) > 32)
+			return __connman_error_invalid_arguments(msg);
+
+		if (g_strcmp0(technology->tethering_ident, str) != 0) {
+			g_free(technology->tethering_ident);
+			technology->tethering_ident = g_strdup(str);
+			technology_save(technology);
+
+			connman_dbus_property_changed_basic(technology->path,
+						CONNMAN_TECHNOLOGY_INTERFACE,
+						"TetheringIdentifier",
+						DBUS_TYPE_STRING,
+						&technology->tethering_ident);
+		}
+	} else if (g_str_equal(name, "TetheringPassphrase")) {
+		const char *str;
+
+		dbus_message_iter_get_basic(&value, &str);
+
+		if (technology->type != CONNMAN_SERVICE_TYPE_WIFI)
+			return __connman_error_not_supported(msg);
+
+		if (strlen(str) < 8 || strlen(str) > 63)
+			return __connman_error_passphrase_required(msg);
+
+		if (g_strcmp0(technology->tethering_passphrase, str) != 0) {
+			g_free(technology->tethering_passphrase);
+			technology->tethering_passphrase = g_strdup(str);
+			technology_save(technology);
+
+			connman_dbus_property_changed_basic(technology->path,
+					CONNMAN_TECHNOLOGY_INTERFACE,
+					"TetheringPassphrase",
+					DBUS_TYPE_STRING,
+					&technology->tethering_passphrase);
+		}
+	} else if (g_str_equal(name, "Powered")) {
+		dbus_bool_t enable;
+
+		if (type != DBUS_TYPE_BOOLEAN)
+			return __connman_error_invalid_arguments(msg);
+
+		dbus_message_iter_get_basic(&value, &enable);
+
+		return set_powered(technology, msg, enable);
+	} else
+		return __connman_error_invalid_property(msg);
+
+	return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+}
+
+static void reply_scan_pending(struct connman_technology *technology, int err)
+{
+	DBusMessage *reply;
+
+	DBG("technology %p err %d", technology, err);
+
+	while (technology->scan_pending) {
+		DBusMessage *msg = technology->scan_pending->data;
+
+		DBG("reply to %s", dbus_message_get_sender(msg));
+
+		if (err == 0)
+			reply = g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+		else
+			reply = __connman_error_failed(msg, -err);
+		g_dbus_send_message(connection, reply);
+		dbus_message_unref(msg);
+
+		technology->scan_pending =
+			g_slist_delete_link(technology->scan_pending,
+					technology->scan_pending);
+	}
+}
+
+void __connman_technology_scan_started(struct connman_device *device)
+{
+	DBG("device %p", device);
+}
+
+void __connman_technology_scan_stopped(struct connman_device *device,
+					enum connman_service_type type)
+{
+	int count = 0;
+	struct connman_technology *technology;
+	GSList *list;
+
+	technology = technology_find(type);
+
+	DBG("technology %p device %p", technology, device);
+
+	if (!technology)
+		return;
+
+	for (list = technology->device_list; list; list = list->next) {
+		struct connman_device *other_device = list->data;
+
+		if (device == other_device)
+			continue;
+
+		if (__connman_device_get_service_type(other_device) != type)
+			continue;
+
+		if (connman_device_get_scanning(other_device))
+			count += 1;
+	}
+
+	if (count == 0)
+		reply_scan_pending(technology, 0);
+}
+
+void __connman_technology_notify_regdom_by_device(struct connman_device *device,
+						int result, const char *alpha2)
+{
+	bool regdom_set = false;
+	struct connman_technology *technology;
+	enum connman_service_type type;
+	GSList *tech_drivers;
+
+	type = __connman_device_get_service_type(device);
+	technology = technology_find(type);
+
+	if (!technology)
+		return;
+
+	if (result < 0) {
+
+		for (tech_drivers = technology->driver_list;
+		     tech_drivers;
+		     tech_drivers = g_slist_next(tech_drivers)) {
+			struct connman_technology_driver *driver =
+				tech_drivers->data;
+
+			if (driver->set_regdom) {
+				driver->set_regdom(technology, alpha2);
+				regdom_set = true;
+			}
+
+		}
+
+		if (!regdom_set)
+			alpha2 = NULL;
+	}
+
+	connman_technology_regdom_notify(technology, alpha2);
+}
+
+static DBusMessage *scan(DBusConnection *conn, DBusMessage *msg, void *data)
+{
+	struct connman_technology *technology = data;
+	int err;
+
+	DBG("technology %p request from %s", technology,
+			dbus_message_get_sender(msg));
+
+	dbus_message_ref(msg);
+	technology->scan_pending =
+		g_slist_prepend(technology->scan_pending, msg);
+
+	err = __connman_device_request_scan(technology->type);
+	if (err < 0)
+		reply_scan_pending(technology, err);
+
+	return NULL;
+}
+
+static const GDBusMethodTable technology_methods[] = {
+	{ GDBUS_DEPRECATED_METHOD("GetProperties",
+			NULL, GDBUS_ARGS({ "properties", "a{sv}" }),
+			get_properties) },
+	{ GDBUS_ASYNC_METHOD("SetProperty",
+			GDBUS_ARGS({ "name", "s" }, { "value", "v" }),
+			NULL, set_property) },
+	{ GDBUS_ASYNC_METHOD("Scan", NULL, NULL, scan) },
+	{ },
+};
+
+static const GDBusSignalTable technology_signals[] = {
+	{ GDBUS_SIGNAL("PropertyChanged",
+			GDBUS_ARGS({ "name", "s" }, { "value", "v" })) },
+	{ },
+};
+
+static bool technology_dbus_register(struct connman_technology *technology)
+{
+	if (technology->dbus_registered ||
+				(technology->rfkill_driven &&
+				 technology->hardblocked))
+		return true;
+
+	if (!g_dbus_register_interface(connection, technology->path,
+					CONNMAN_TECHNOLOGY_INTERFACE,
+					technology_methods, technology_signals,
+					NULL, technology, NULL)) {
+		connman_error("Failed to register %s", technology->path);
+		return false;
+	}
+
+	technology_added_signal(technology);
+	technology->dbus_registered = true;
+
+	return true;
+}
+
+static void technology_dbus_unregister(struct connman_technology *technology)
+{
+	if (!technology->dbus_registered)
+		return;
+
+	technology_removed_signal(technology);
+	g_dbus_unregister_interface(connection, technology->path,
+		CONNMAN_TECHNOLOGY_INTERFACE);
+
+	technology->dbus_registered = false;
+}
+
+static void technology_put(struct connman_technology *technology)
+{
+	DBG("technology %p", technology);
+
+	if (__sync_sub_and_fetch(&technology->refcount, 1) > 0)
+		return;
+
+	reply_scan_pending(technology, -EINTR);
+
+	while (technology->driver_list) {
+		struct connman_technology_driver *driver;
+
+		driver = technology->driver_list->data;
+
+		if (driver->remove)
+			driver->remove(technology);
+
+		technology->driver_list =
+			g_slist_delete_link(technology->driver_list,
+					technology->driver_list);
+	}
+
+	technology_list = g_slist_remove(technology_list, technology);
+
+	technology_dbus_unregister(technology);
+
+	g_slist_free(technology->device_list);
+
+	/*
+	 *	Once set_powered is called, technology is not powered
+	 *	immediately. The device driver enable function returns
+	 * -EINPROGRESS and a timer of 10 sec is started. If the
+	 *	technology is powered within 10 sec, this timer is cancelled.
+	 *  In case technology is not powered, from timeout handler
+	 *  -ETIMEDOUT is return to the application. But if technology
+	 *  is disabled within that 10 sec, technology pointer is freed
+	 *  but timer is left running. On expiry of timer, it would try
+	 *  to access the technology pointer which is already freed and
+	 *  would cause crash.
+	 */
+	if (technology->pending_reply) {
+		dbus_message_unref(technology->pending_reply);
+		technology->pending_reply = NULL;
+		g_source_remove(technology->pending_timeout);
+		technology->pending_timeout = 0;
+	}
+
+	g_free(technology->path);
+	g_free(technology->regdom);
+	g_free(technology->tethering_ident);
+	g_free(technology->tethering_passphrase);
+	g_free(technology);
+}
+
+static struct connman_technology *technology_get(enum connman_service_type type)
+{
+	GSList *tech_drivers = NULL;
+	struct connman_technology_driver *driver;
+	struct connman_technology *technology;
+	const char *str;
+	GSList *list;
+
+	DBG("type %d", type);
+
+	str = __connman_service_type2string(type);
+	if (!str)
+		return NULL;
+
+	technology = technology_find(type);
+	if (technology) {
+		if (type != CONNMAN_SERVICE_TYPE_P2P)
+			__sync_fetch_and_add(&technology->refcount, 1);
+		return technology;
+	}
+
+	/* First check if we have a driver for this technology type */
+	for (list = driver_list; list; list = list->next) {
+		driver = list->data;
+
+		if (driver->type == type) {
+			DBG("technology %p driver %p", technology, driver);
+			tech_drivers = g_slist_append(tech_drivers, driver);
+		}
+	}
+
+	if (!tech_drivers) {
+		DBG("No matching drivers found for %s.",
+				__connman_service_type2string(type));
+		return NULL;
+	}
+
+	technology = g_try_new0(struct connman_technology, 1);
+	if (!technology)
+		return NULL;
+
+	technology->refcount = 1;
+	technology->type = type;
+	technology->path = g_strdup_printf("%s/technology/%s",
+							CONNMAN_PATH, str);
+
+	technology_load(technology);
+	technology_list = g_slist_prepend(technology_list, technology);
+	technology->driver_list = tech_drivers;
+
+	for (list = tech_drivers; list; list = list->next) {
+		driver = list->data;
+
+		if (driver->probe && driver->probe(technology) < 0)
+			DBG("Driver probe failed for technology %p",
+					technology);
+	}
+
+	if (!technology_dbus_register(technology)) {
+		technology_put(technology);
+		return NULL;
+	}
+
+	if (type == CONNMAN_SERVICE_TYPE_P2P) {
+		struct connman_technology *wifi;
+		bool enable;
+
+		enable = technology->enable_persistent;
+
+		wifi = technology_find(CONNMAN_SERVICE_TYPE_WIFI);
+		if (enable && wifi)
+			enable = wifi->enabled;
+
+		technology_affect_devices(technology, enable);
+	}
+
+	DBG("technology %p %s", technology, get_name(technology->type));
+
+	return technology;
+}
+
+int connman_technology_driver_register(struct connman_technology_driver *driver)
+{
+	GSList *list;
+	struct connman_device *device;
+	enum connman_service_type type;
+
+	for (list = driver_list; list; list = list->next) {
+		if (list->data == driver)
+			goto exist;
+	}
+
+	DBG("Registering %s driver", driver->name);
+
+	driver_list = g_slist_insert_sorted(driver_list, driver,
+							compare_priority);
+
+	/*
+	 * Check for technology less devices if this driver
+	 * can service any of them.
+	*/
+	for (list = techless_device_list; list; list = list->next) {
+		device = list->data;
+
+		type = __connman_device_get_service_type(device);
+		if (type != driver->type)
+			continue;
+
+		techless_device_list = g_slist_remove(techless_device_list,
+								device);
+
+		__connman_technology_add_device(device);
+	}
+
+	/* Check for orphaned rfkill switches. */
+	g_hash_table_foreach(rfkill_list, rfkill_check,
+					GINT_TO_POINTER(driver->type));
+
+exist:
+	if (driver->type == CONNMAN_SERVICE_TYPE_P2P) {
+		if (!technology_get(CONNMAN_SERVICE_TYPE_P2P))
+			return -ENOMEM;
+	}
+
+	return 0;
+}
+
+void connman_technology_driver_unregister(struct connman_technology_driver *driver)
+{
+	GSList *list, *tech_drivers;
+	struct connman_technology *technology;
+	struct connman_technology_driver *current;
+
+	DBG("Unregistering driver %p name %s", driver, driver->name);
+
+	for (list = technology_list; list; list = list->next) {
+		technology = list->data;
+
+		for (tech_drivers = technology->driver_list; tech_drivers;
+				tech_drivers = g_slist_next(tech_drivers)) {
+			current = tech_drivers->data;
+			if (driver != current)
+				continue;
+
+			if (driver->remove)
+				driver->remove(technology);
+
+			technology->driver_list =
+				g_slist_remove(technology->driver_list,
+								driver);
+			break;
+		}
+	}
+
+	driver_list = g_slist_remove(driver_list, driver);
+
+	if (driver->type == CONNMAN_SERVICE_TYPE_P2P) {
+		technology = technology_find(CONNMAN_SERVICE_TYPE_P2P);
+		if (technology)
+			technology_put(technology);
+	}
+}
+
+void __connman_technology_add_interface(enum connman_service_type type,
+				int index, const char *ident)
+{
+	struct connman_technology *technology;
+	GSList *tech_drivers;
+	struct connman_technology_driver *driver;
+	char *name;
+
+	switch (type) {
+	case CONNMAN_SERVICE_TYPE_UNKNOWN:
+	case CONNMAN_SERVICE_TYPE_SYSTEM:
+		return;
+	case CONNMAN_SERVICE_TYPE_ETHERNET:
+	case CONNMAN_SERVICE_TYPE_WIFI:
+	case CONNMAN_SERVICE_TYPE_LOWPAN:
+	case CONNMAN_SERVICE_TYPE_BLUETOOTH:
+	case CONNMAN_SERVICE_TYPE_CELLULAR:
+	case CONNMAN_SERVICE_TYPE_GPS:
+	case CONNMAN_SERVICE_TYPE_VPN:
+	case CONNMAN_SERVICE_TYPE_GADGET:
+	case CONNMAN_SERVICE_TYPE_P2P:
+		break;
+	}
+
+	name = connman_inet_ifname(index);
+	connman_info("Adding interface %s [ %s ]", name,
+				__connman_service_type2string(type));
+
+	technology = technology_find(type);
+
+	if (!technology)
+		goto out;
+
+	for (tech_drivers = technology->driver_list; tech_drivers;
+	     tech_drivers = g_slist_next(tech_drivers)) {
+		driver = tech_drivers->data;
+
+		if (driver->add_interface)
+			driver->add_interface(technology, index, name, ident);
+	}
+
+	/*
+	 * At this point we can try to enable tethering automatically as
+	 * now the interfaces are set properly.
+	 */
+	if (technology->tethering_persistent)
+		enable_tethering(technology);
+
+out:
+	g_free(name);
+}
+
+void __connman_technology_remove_interface(enum connman_service_type type,
+				int index, const char *ident)
+{
+	struct connman_technology *technology;
+	GSList *tech_drivers;
+	struct connman_technology_driver *driver;
+	char *name;
+
+	switch (type) {
+	case CONNMAN_SERVICE_TYPE_UNKNOWN:
+	case CONNMAN_SERVICE_TYPE_SYSTEM:
+		return;
+	case CONNMAN_SERVICE_TYPE_ETHERNET:
+	case CONNMAN_SERVICE_TYPE_WIFI:
+	case CONNMAN_SERVICE_TYPE_LOWPAN:
+	case CONNMAN_SERVICE_TYPE_BLUETOOTH:
+	case CONNMAN_SERVICE_TYPE_CELLULAR:
+	case CONNMAN_SERVICE_TYPE_GPS:
+	case CONNMAN_SERVICE_TYPE_VPN:
+	case CONNMAN_SERVICE_TYPE_GADGET:
+	case CONNMAN_SERVICE_TYPE_P2P:
+		break;
+	}
+
+	name = connman_inet_ifname(index);
+	connman_info("Remove interface %s [ %s ]", name,
+				__connman_service_type2string(type));
+	g_free(name);
+
+	technology = technology_find(type);
+
+	if (!technology)
+		return;
+
+	for (tech_drivers = technology->driver_list; tech_drivers;
+	     tech_drivers = g_slist_next(tech_drivers)) {
+		driver = tech_drivers->data;
+
+		if (driver->remove_interface)
+			driver->remove_interface(technology, index);
+	}
+}
+
+int __connman_technology_add_device(struct connman_device *device)
+{
+	struct connman_technology *technology;
+	enum connman_service_type type;
+
+	type = __connman_device_get_service_type(device);
+
+	DBG("device %p type %s", device, get_name(type));
+
+	technology = technology_get(type);
+	if (!technology) {
+		/*
+		 * Since no driver can be found for this device at the moment we
+		 * add it to the techless device list.
+		*/
+		techless_device_list = g_slist_prepend(techless_device_list,
+								device);
+
+		return -ENXIO;
+	}
+
+	__sync_synchronize();
+    DBG("rf kill %d enable %d persistent %d global %d", technology->rfkill_driven, technology->enabled, technology->enable_persistent, global_offlinemode);  
+	if (technology->rfkill_driven) {
+		if (technology->enabled)
+			__connman_device_enable(device);
+		else
+			__connman_device_disable(device);
+
+		goto done;
+	}
+
+	if (technology->enable_persistent &&
+					!global_offlinemode) {
+		int err = __connman_device_enable(device);
+		/*
+		 * connman_technology_add_device() calls __connman_device_enable()
+		 * but since the device is already enabled, the calls does not
+		 * propagate through to connman_technology_enabled via
+		 * connman_device_set_powered.
+		 */
+		if (err == -EALREADY)
+			__connman_technology_enabled(type);
+	}
+	/* if technology persistent state is offline */
+	if (!technology->enable_persistent)
+		__connman_device_disable(device);
+
+done:
+	technology->device_list = g_slist_prepend(technology->device_list,
+								device);
+
+	return 0;
+}
+
+int __connman_technology_remove_device(struct connman_device *device)
+{
+	struct connman_technology *technology;
+	enum connman_service_type type;
+
+	DBG("device %p", device);
+
+	type = __connman_device_get_service_type(device);
+
+	technology = technology_find(type);
+	if (!technology) {
+		techless_device_list = g_slist_remove(techless_device_list,
+								device);
+		return -ENXIO;
+	}
+
+	technology->device_list = g_slist_remove(technology->device_list,
+								device);
+
+	if (technology->tethering)
+		set_tethering(technology, false);
+
+	technology_put(technology);
+
+	return 0;
+}
+
+int __connman_technology_enabled(enum connman_service_type type)
+{
+	struct connman_technology *technology;
+
+	technology = technology_find(type);
+	if (!technology)
+		return -ENXIO;
+
+	DBG("technology %p type %s rfkill %d enabled %d", technology,
+		get_name(type), technology->rfkill_driven,
+		technology->enabled);
+
+	if (technology->rfkill_driven) {
+		if (technology->tethering_persistent)
+			enable_tethering(technology);
+		return 0;
+	}
+
+	return technology_enabled(technology);
+}
+
+int __connman_technology_disabled(enum connman_service_type type)
+{
+	struct connman_technology *technology;
+	GSList *list;
+
+	technology = technology_find(type);
+	if (!technology)
+		return -ENXIO;
+
+	if (technology->rfkill_driven)
+		return 0;
+
+	for (list = technology->device_list; list; list = list->next) {
+		struct connman_device *device = list->data;
+
+		if (connman_device_get_powered(device))
+			return 0;
+	}
+
+	return technology_disabled(technology);
+}
+
+int __connman_technology_set_offlinemode(bool offlinemode)
+{
+	GSList *list;
+	int err = -EINVAL, enabled_tech_count = 0;
+
+	if (global_offlinemode == offlinemode)
+		return 0;
+
+	DBG("offlinemode %s", offlinemode ? "On" : "Off");
+
+	/*
+	 * This is a bit tricky. When you set offlinemode, there is no
+	 * way to differentiate between attempting offline mode and
+	 * resuming offlinemode from last saved profile. We need that
+	 * information in rfkill_update, otherwise it falls back on the
+	 * technology's persistent state. Hence we set the offline mode here
+	 * but save it & call the notifier only if its successful.
+	 */
+
+	global_offlinemode = offlinemode;
+
+	/* Traverse technology list, enable/disable each technology. */
+	for (list = technology_list; list; list = list->next) {
+		struct connman_technology *technology = list->data;
+
+		if (offlinemode)
+			err = technology_disable(technology);
+		else {
+			if (technology->hardblocked)
+				continue;
+
+			if (technology->enable_persistent) {
+				err = technology_enable(technology);
+				enabled_tech_count++;
+			}
+		}
+	}
+
+	if (err == 0 || err == -EINPROGRESS || err == -EALREADY ||
+			(err == -EINVAL && enabled_tech_count == 0)) {
+		connman_technology_save_offlinemode();
+		__connman_notifier_offlinemode(offlinemode);
+	} else
+		global_offlinemode = connman_technology_load_offlinemode();
+
+	return err;
+}
+
+void __connman_technology_set_connected(enum connman_service_type type,
+		bool connected)
+{
+	struct connman_technology *technology;
+	dbus_bool_t val;
+
+	technology = technology_find(type);
+	if (!technology)
+		return;
+
+	DBG("technology %p connected %d", technology, connected);
+
+	technology->connected = connected;
+
+	val = connected;
+	connman_dbus_property_changed_basic(technology->path,
+			CONNMAN_TECHNOLOGY_INTERFACE, "Connected",
+			DBUS_TYPE_BOOLEAN, &val);
+}
+
+static bool technology_apply_rfkill_change(struct connman_technology *technology,
+						bool softblock,
+						bool hardblock,
+						bool new_rfkill)
+{
+	bool hardblock_changed = false;
+	bool apply = true;
+	GList *start, *list;
+
+	DBG("technology %p --> %d/%d vs %d/%d",
+			technology, softblock, hardblock,
+			technology->softblocked, technology->hardblocked);
+
+	if (technology->hardblocked == hardblock)
+		goto softblock_change;
+
+	if (!(new_rfkill && !hardblock)) {
+		start = g_hash_table_get_values(rfkill_list);
+
+		for (list = start; list; list = list->next) {
+			struct connman_rfkill *rfkill = list->data;
+
+			if (rfkill->type != technology->type)
+				continue;
+
+			if (rfkill->hardblock != hardblock)
+				apply = false;
+		}
+
+		g_list_free(start);
+	}
+
+	if (!apply)
+		goto softblock_change;
+
+	technology->hardblocked = hardblock;
+	hardblock_changed = true;
+
+softblock_change:
+	if (!apply && technology->softblocked != softblock)
+		apply = true;
+
+	if (!apply)
+		return technology->hardblocked;
+
+	technology->softblocked = softblock;
+
+	if (technology->hardblocked ||
+					technology->softblocked) {
+		if (technology_disabled(technology) != -EALREADY)
+			technology_affect_devices(technology, false);
+	} else if (!technology->hardblocked &&
+					!technology->softblocked) {
+		if (technology_enabled(technology) != -EALREADY)
+			technology_affect_devices(technology, true);
+	}
+
+	if (hardblock_changed) {
+		if (technology->hardblocked) {
+			DBG("%s is switched off.", get_name(technology->type));
+			technology_dbus_unregister(technology);
+		} else {
+			DBG("%s is switched on.", get_name(technology->type));
+			technology_dbus_register(technology);
+
+			if (global_offlinemode)
+				__connman_rfkill_block(technology->type, true);
+		}
+	}
+
+	return technology->hardblocked;
+}
+
+int __connman_technology_add_rfkill(unsigned int index,
+					enum connman_service_type type,
+						bool softblock,
+						bool hardblock)
+{
+	struct connman_technology *technology;
+	struct connman_rfkill *rfkill;
+
+	DBG("index %u type %d soft %u hard %u", index, type,
+							softblock, hardblock);
+
+	rfkill = g_hash_table_lookup(rfkill_list, GINT_TO_POINTER(index));
+	if (rfkill)
+		goto done;
+
+	rfkill = g_try_new0(struct connman_rfkill, 1);
+	if (!rfkill)
+		return -ENOMEM;
+
+	rfkill->index = index;
+	rfkill->type = type;
+	rfkill->softblock = softblock;
+	rfkill->hardblock = hardblock;
+
+	g_hash_table_insert(rfkill_list, GINT_TO_POINTER(index), rfkill);
+
+done:
+	technology = technology_get(type);
+	/* If there is no driver for this type, ignore it. */
+	if (!technology)
+		return -ENXIO;
+
+	technology->rfkill_driven = true;
+
+	/* If hardblocked, there is no need to handle softblocked state */
+	if (technology_apply_rfkill_change(technology,
+				softblock, hardblock, true))
+		return 0;
+
+	if (global_offlinemode)
+		return 0;
+
+	/*
+	 * Depending on softblocked state we unblock/block according to
+	 * offlinemode and persistente state.
+	 */
+	if (technology->softblocked &&
+				technology->enable_persistent)
+		return __connman_rfkill_block(type, false);
+	else if (!technology->softblocked &&
+				!technology->enable_persistent)
+		return __connman_rfkill_block(type, true);
+
+	return 0;
+}
+
+int __connman_technology_update_rfkill(unsigned int index,
+					enum connman_service_type type,
+						bool softblock,
+						bool hardblock)
+{
+	struct connman_technology *technology;
+	struct connman_rfkill *rfkill;
+
+	DBG("index %u soft %u hard %u", index, softblock, hardblock);
+
+	rfkill = g_hash_table_lookup(rfkill_list, GINT_TO_POINTER(index));
+	if (!rfkill)
+		return -ENXIO;
+
+	if (rfkill->softblock == softblock &&
+				rfkill->hardblock == hardblock)
+		return 0;
+
+	rfkill->softblock = softblock;
+	rfkill->hardblock = hardblock;
+
+	technology = technology_find(type);
+	/* If there is no driver for this type, ignore it. */
+	if (!technology)
+		return -ENXIO;
+
+	technology_apply_rfkill_change(technology, softblock, hardblock,
+								false);
+
+	if (technology->hardblocked)
+		DBG("%s hardblocked", get_name(technology->type));
+	else
+		DBG("%s is%s softblocked", get_name(technology->type),
+			technology->softblocked ? "" : " not");
+
+	return 0;
+}
+
+int __connman_technology_remove_rfkill(unsigned int index,
+					enum connman_service_type type)
+{
+	struct connman_technology *technology;
+	struct connman_rfkill *rfkill;
+
+	DBG("index %u", index);
+
+	rfkill = g_hash_table_lookup(rfkill_list, GINT_TO_POINTER(index));
+	if (!rfkill)
+		return -ENXIO;
+
+	g_hash_table_remove(rfkill_list, GINT_TO_POINTER(index));
+
+	technology = technology_find(type);
+	if (!technology)
+		return -ENXIO;
+
+	technology_apply_rfkill_change(technology,
+		technology->softblocked, !technology->hardblocked, false);
+
+	technology_put(technology);
+
+	return 0;
+}
+
+int __connman_technology_init(void)
+{
+	DBG("");
+
+	connection = connman_dbus_get_connection();
+
+	rfkill_list = g_hash_table_new_full(g_direct_hash, g_direct_equal,
+							NULL, free_rfkill);
+
+	global_offlinemode = connman_technology_load_offlinemode();
+
+	/* This will create settings file if it is missing */
+	connman_technology_save_offlinemode();
+
+	return 0;
+}
+
+void __connman_technology_cleanup(void)
+{
+	DBG("");
+
+	while (technology_list) {
+		struct connman_technology *technology = technology_list->data;
+		technology_list = g_slist_remove(technology_list, technology);
+		technology_put(technology);
+	}
+
+	g_hash_table_destroy(rfkill_list);
+
+	dbus_connection_unref(connection);
+}
diff --git a/connman/src/tethering.c b/connman/src/tethering.c
new file mode 100644
index 0000000..ceeec74
--- /dev/null
+++ b/connman/src/tethering.c
@@ -0,0 +1,558 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2013  Intel Corporation. All rights reserved.
+ *  Copyright (C) 2011	ProFUSION embedded systems
+ *
+ *  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 <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <sys/ioctl.h>
+#include <net/if.h>
+#include <linux/sockios.h>
+#include <string.h>
+#include <fcntl.h>
+#include <linux/if_tun.h>
+#include <netinet/in.h>
+#include <linux/if_bridge.h>
+
+#include "connman.h"
+
+#include <gdhcp/gdhcp.h>
+
+#include <gdbus.h>
+
+#ifndef DBUS_TYPE_UNIX_FD
+#define DBUS_TYPE_UNIX_FD -1
+#endif
+
+#define BRIDGE_NAME "tether"
+
+#define DEFAULT_MTU	1500
+
+static char *private_network_primary_dns = NULL;
+static char *private_network_secondary_dns = NULL;
+
+static volatile int tethering_enabled;
+static GDHCPServer *tethering_dhcp_server = NULL;
+static struct connman_ippool *dhcp_ippool = NULL;
+static DBusConnection *connection;
+static GHashTable *pn_hash;
+
+struct connman_private_network {
+	char *owner;
+	char *path;
+	guint watch;
+	DBusMessage *msg;
+	DBusMessage *reply;
+	int fd;
+	char *interface;
+	int index;
+	guint iface_watch;
+	struct connman_ippool *pool;
+	char *primary_dns;
+	char *secondary_dns;
+};
+
+const char *__connman_tethering_get_bridge(void)
+{
+	int sk, err;
+	unsigned long args[3];
+
+	sk = socket(AF_INET, SOCK_STREAM, 0);
+	if (sk < 0)
+		return NULL;
+
+	args[0] = BRCTL_GET_VERSION;
+	args[1] = args[2] = 0;
+	err = ioctl(sk, SIOCGIFBR, &args);
+	close(sk);
+	if (err == -1) {
+		connman_error("Missing support for 802.1d ethernet bridging");
+		return NULL;
+	}
+
+	return BRIDGE_NAME;
+}
+
+static void dhcp_server_debug(const char *str, void *data)
+{
+	connman_info("%s: %s\n", (const char *) data, str);
+}
+
+static void dhcp_server_error(GDHCPServerError error)
+{
+	switch (error) {
+	case G_DHCP_SERVER_ERROR_NONE:
+		connman_error("OK");
+		break;
+	case G_DHCP_SERVER_ERROR_INTERFACE_UNAVAILABLE:
+		connman_error("Interface unavailable");
+		break;
+	case G_DHCP_SERVER_ERROR_INTERFACE_IN_USE:
+		connman_error("Interface in use");
+		break;
+	case G_DHCP_SERVER_ERROR_INTERFACE_DOWN:
+		connman_error("Interface down");
+		break;
+	case G_DHCP_SERVER_ERROR_NOMEM:
+		connman_error("No memory");
+		break;
+	case G_DHCP_SERVER_ERROR_INVALID_INDEX:
+		connman_error("Invalid index");
+		break;
+	case G_DHCP_SERVER_ERROR_INVALID_OPTION:
+		connman_error("Invalid option");
+		break;
+	case G_DHCP_SERVER_ERROR_IP_ADDRESS_INVALID:
+		connman_error("Invalid address");
+		break;
+	}
+}
+
+static GDHCPServer *dhcp_server_start(const char *bridge,
+				const char *router, const char *subnet,
+				const char *start_ip, const char *end_ip,
+				unsigned int lease_time, const char *dns)
+{
+	GDHCPServerError error;
+	GDHCPServer *dhcp_server;
+	int index;
+
+	DBG("");
+
+	index = connman_inet_ifindex(bridge);
+	if (index < 0)
+		return NULL;
+
+	dhcp_server = g_dhcp_server_new(G_DHCP_IPV4, index, &error);
+	if (!dhcp_server) {
+		dhcp_server_error(error);
+		return NULL;
+	}
+
+	g_dhcp_server_set_debug(dhcp_server, dhcp_server_debug, "DHCP server");
+
+	g_dhcp_server_set_lease_time(dhcp_server, lease_time);
+	g_dhcp_server_set_option(dhcp_server, G_DHCP_SUBNET, subnet);
+	g_dhcp_server_set_option(dhcp_server, G_DHCP_ROUTER, router);
+	g_dhcp_server_set_option(dhcp_server, G_DHCP_DNS_SERVER, dns);
+	g_dhcp_server_set_ip_range(dhcp_server, start_ip, end_ip);
+
+	g_dhcp_server_start(dhcp_server);
+
+	return dhcp_server;
+}
+
+static void dhcp_server_stop(GDHCPServer *server)
+{
+	if (!server)
+		return;
+
+	g_dhcp_server_unref(server);
+}
+
+static void tethering_restart(struct connman_ippool *pool, void *user_data)
+{
+	DBG("pool %p", pool);
+	__connman_tethering_set_disabled();
+	__connman_tethering_set_enabled();
+}
+
+void __connman_tethering_set_enabled(void)
+{
+	int index;
+	int err;
+	const char *gateway;
+	const char *broadcast;
+	const char *subnet_mask;
+	const char *start_ip;
+	const char *end_ip;
+	const char *dns;
+	unsigned char prefixlen;
+	char **ns;
+
+	DBG("enabled %d", tethering_enabled + 1);
+
+	if (__sync_fetch_and_add(&tethering_enabled, 1) != 0)
+		return;
+
+	err = __connman_bridge_create(BRIDGE_NAME);
+	if (err < 0) {
+		__sync_fetch_and_sub(&tethering_enabled, 1);
+		return;
+	}
+
+	index = connman_inet_ifindex(BRIDGE_NAME);
+	dhcp_ippool = __connman_ippool_create(index, 2, 252,
+						tethering_restart, NULL);
+	if (!dhcp_ippool) {
+		connman_error("Fail to create IP pool");
+		__connman_bridge_remove(BRIDGE_NAME);
+		__sync_fetch_and_sub(&tethering_enabled, 1);
+		return;
+	}
+
+	gateway = __connman_ippool_get_gateway(dhcp_ippool);
+	broadcast = __connman_ippool_get_broadcast(dhcp_ippool);
+	subnet_mask = __connman_ippool_get_subnet_mask(dhcp_ippool);
+	start_ip = __connman_ippool_get_start_ip(dhcp_ippool);
+	end_ip = __connman_ippool_get_end_ip(dhcp_ippool);
+
+	err = __connman_bridge_enable(BRIDGE_NAME, gateway,
+			connman_ipaddress_calc_netmask_len(subnet_mask),
+			broadcast);
+	if (err < 0 && err != -EALREADY) {
+		__connman_ippool_unref(dhcp_ippool);
+		__connman_bridge_remove(BRIDGE_NAME);
+		__sync_fetch_and_sub(&tethering_enabled, 1);
+		return;
+	}
+
+	ns = connman_setting_get_string_list("FallbackNameservers");
+	if (ns) {
+		if (ns[0]) {
+			g_free(private_network_primary_dns);
+			private_network_primary_dns = g_strdup(ns[0]);
+		}
+		if (ns[1]) {
+			g_free(private_network_secondary_dns);
+			private_network_secondary_dns = g_strdup(ns[1]);
+		}
+
+		DBG("Fallback ns primary %s secondary %s",
+			private_network_primary_dns,
+			private_network_secondary_dns);
+	}
+
+	dns = gateway;
+	if (__connman_dnsproxy_add_listener(index) < 0) {
+		connman_error("Can't add listener %s to DNS proxy",
+								BRIDGE_NAME);
+		dns = private_network_primary_dns;
+		DBG("Serving %s nameserver to clients", dns);
+	}
+
+	tethering_dhcp_server = dhcp_server_start(BRIDGE_NAME,
+						gateway, subnet_mask,
+						start_ip, end_ip,
+						24 * 3600, dns);
+	if (!tethering_dhcp_server) {
+		__connman_bridge_disable(BRIDGE_NAME);
+		__connman_ippool_unref(dhcp_ippool);
+		__connman_bridge_remove(BRIDGE_NAME);
+		__sync_fetch_and_sub(&tethering_enabled, 1);
+		return;
+	}
+
+	prefixlen = connman_ipaddress_calc_netmask_len(subnet_mask);
+	err = __connman_nat_enable(BRIDGE_NAME, start_ip, prefixlen);
+	if (err < 0) {
+		connman_error("Cannot enable NAT %d/%s", err, strerror(-err));
+		dhcp_server_stop(tethering_dhcp_server);
+		__connman_bridge_disable(BRIDGE_NAME);
+		__connman_ippool_unref(dhcp_ippool);
+		__connman_bridge_remove(BRIDGE_NAME);
+		__sync_fetch_and_sub(&tethering_enabled, 1);
+		return;
+	}
+
+	err = __connman_ipv6pd_setup(BRIDGE_NAME);
+	if (err < 0 && err != -EINPROGRESS)
+		DBG("Cannot setup IPv6 prefix delegation %d/%s", err,
+			strerror(-err));
+
+	DBG("tethering started");
+}
+
+void __connman_tethering_set_disabled(void)
+{
+	int index;
+
+	DBG("enabled %d", tethering_enabled - 1);
+
+	if (__sync_fetch_and_sub(&tethering_enabled, 1) != 1)
+		return;
+
+	__connman_ipv6pd_cleanup();
+
+	index = connman_inet_ifindex(BRIDGE_NAME);
+	__connman_dnsproxy_remove_listener(index);
+
+	__connman_nat_disable(BRIDGE_NAME);
+
+	dhcp_server_stop(tethering_dhcp_server);
+
+	tethering_dhcp_server = NULL;
+
+	__connman_bridge_disable(BRIDGE_NAME);
+
+	__connman_ippool_unref(dhcp_ippool);
+
+	__connman_bridge_remove(BRIDGE_NAME);
+
+	g_free(private_network_primary_dns);
+	private_network_primary_dns = NULL;
+	g_free(private_network_secondary_dns);
+	private_network_secondary_dns = NULL;
+
+	DBG("tethering stopped");
+}
+
+static void setup_tun_interface(unsigned int flags, unsigned change,
+		void *data)
+{
+	struct connman_private_network *pn = data;
+	unsigned char prefixlen;
+	DBusMessageIter array, dict;
+	const char *server_ip;
+	const char *peer_ip;
+	const char *subnet_mask;
+	int err;
+
+	DBG("index %d flags %d change %d", pn->index,  flags, change);
+
+	if (flags & IFF_UP)
+		return;
+
+	subnet_mask = __connman_ippool_get_subnet_mask(pn->pool);
+	server_ip = __connman_ippool_get_start_ip(pn->pool);
+	peer_ip = __connman_ippool_get_end_ip(pn->pool);
+	prefixlen = connman_ipaddress_calc_netmask_len(subnet_mask);
+
+	if ((__connman_inet_modify_address(RTM_NEWADDR,
+				NLM_F_REPLACE | NLM_F_ACK, pn->index, AF_INET,
+				server_ip, peer_ip, prefixlen, NULL)) < 0) {
+		DBG("address setting failed");
+		return;
+	}
+
+	connman_inet_ifup(pn->index);
+
+	err = __connman_nat_enable(BRIDGE_NAME, server_ip, prefixlen);
+	if (err < 0) {
+		connman_error("failed to enable NAT");
+		goto error;
+	}
+
+	dbus_message_iter_init_append(pn->reply, &array);
+
+	dbus_message_iter_append_basic(&array, DBUS_TYPE_OBJECT_PATH,
+						&pn->path);
+
+	connman_dbus_dict_open(&array, &dict);
+
+	connman_dbus_dict_append_basic(&dict, "ServerIPv4",
+					DBUS_TYPE_STRING, &server_ip);
+	connman_dbus_dict_append_basic(&dict, "PeerIPv4",
+					DBUS_TYPE_STRING, &peer_ip);
+	if (pn->primary_dns)
+		connman_dbus_dict_append_basic(&dict, "PrimaryDNS",
+					DBUS_TYPE_STRING, &pn->primary_dns);
+
+	if (pn->secondary_dns)
+		connman_dbus_dict_append_basic(&dict, "SecondaryDNS",
+					DBUS_TYPE_STRING, &pn->secondary_dns);
+
+	connman_dbus_dict_close(&array, &dict);
+
+	dbus_message_iter_append_basic(&array, DBUS_TYPE_UNIX_FD, &pn->fd);
+
+	g_dbus_send_message(connection, pn->reply);
+
+	return;
+
+error:
+	pn->reply = __connman_error_failed(pn->msg, -err);
+	g_dbus_send_message(connection, pn->reply);
+
+	g_hash_table_remove(pn_hash, pn->path);
+}
+
+static void remove_private_network(gpointer user_data)
+{
+	struct connman_private_network *pn = user_data;
+
+	__connman_nat_disable(BRIDGE_NAME);
+	connman_rtnl_remove_watch(pn->iface_watch);
+	__connman_ippool_unref(pn->pool);
+
+	if (pn->watch > 0) {
+		g_dbus_remove_watch(connection, pn->watch);
+		pn->watch = 0;
+	}
+
+	close(pn->fd);
+
+	g_free(pn->interface);
+	g_free(pn->owner);
+	g_free(pn->path);
+	g_free(pn->primary_dns);
+	g_free(pn->secondary_dns);
+	g_free(pn);
+}
+
+static void owner_disconnect(DBusConnection *conn, void *user_data)
+{
+	struct connman_private_network *pn = user_data;
+
+	DBG("%s died", pn->owner);
+
+	pn->watch = 0;
+
+	g_hash_table_remove(pn_hash, pn->path);
+}
+
+static void ippool_disconnect(struct connman_ippool *pool, void *user_data)
+{
+	struct connman_private_network *pn = user_data;
+
+	DBG("block used externally");
+
+	g_hash_table_remove(pn_hash, pn->path);
+}
+
+int __connman_private_network_request(DBusMessage *msg, const char *owner)
+{
+	struct connman_private_network *pn;
+	char *iface = NULL;
+	char *path = NULL;
+	int index, fd, err;
+
+	if (DBUS_TYPE_UNIX_FD < 0)
+		return -EINVAL;
+
+	fd = connman_inet_create_tunnel(&iface);
+	if (fd < 0)
+		return fd;
+
+	path = g_strdup_printf("/tethering/%s", iface);
+
+	pn = g_hash_table_lookup(pn_hash, path);
+	if (pn) {
+		g_free(path);
+		g_free(iface);
+		close(fd);
+		return -EEXIST;
+	}
+
+	index = connman_inet_ifindex(iface);
+	if (index < 0) {
+		err = -ENODEV;
+		goto error;
+	}
+	DBG("interface %s", iface);
+
+	err = connman_inet_set_mtu(index, DEFAULT_MTU);
+
+	pn = g_try_new0(struct connman_private_network, 1);
+	if (!pn) {
+		err = -ENOMEM;
+		goto error;
+	}
+
+	pn->owner = g_strdup(owner);
+	pn->path = path;
+	pn->watch = g_dbus_add_disconnect_watch(connection, pn->owner,
+					owner_disconnect, pn, NULL);
+	pn->msg = msg;
+	pn->reply = dbus_message_new_method_return(pn->msg);
+	if (!pn->reply)
+		goto error;
+
+	pn->fd = fd;
+	pn->interface = iface;
+	pn->index = index;
+	pn->pool = __connman_ippool_create(pn->index, 1, 1, ippool_disconnect, pn);
+	if (!pn->pool) {
+		errno = -ENOMEM;
+		goto error;
+	}
+
+	pn->primary_dns = g_strdup(private_network_primary_dns);
+	pn->secondary_dns = g_strdup(private_network_secondary_dns);
+
+	pn->iface_watch = connman_rtnl_add_newlink_watch(index,
+						setup_tun_interface, pn);
+
+	g_hash_table_insert(pn_hash, pn->path, pn);
+
+	return 0;
+
+error:
+	close(fd);
+	g_free(iface);
+	g_free(path);
+	g_free(pn);
+	return err;
+}
+
+int __connman_private_network_release(const char *path)
+{
+	struct connman_private_network *pn;
+
+	pn = g_hash_table_lookup(pn_hash, path);
+	if (!pn)
+		return -EACCES;
+
+	g_hash_table_remove(pn_hash, path);
+	return 0;
+}
+
+int __connman_tethering_init(void)
+{
+	DBG("");
+
+	tethering_enabled = 0;
+
+	connection = connman_dbus_get_connection();
+	if (!connection)
+		return -EFAULT;
+
+	pn_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
+						NULL, remove_private_network);
+
+	return 0;
+}
+
+void __connman_tethering_cleanup(void)
+{
+	DBG("enabled %d", tethering_enabled);
+
+	__sync_synchronize();
+	if (tethering_enabled > 0) {
+		if (tethering_dhcp_server)
+			dhcp_server_stop(tethering_dhcp_server);
+		__connman_bridge_disable(BRIDGE_NAME);
+		__connman_bridge_remove(BRIDGE_NAME);
+		__connman_nat_disable(BRIDGE_NAME);
+	}
+
+	if (!connection)
+		return;
+
+	g_hash_table_destroy(pn_hash);
+	dbus_connection_unref(connection);
+}
diff --git a/connman/src/timeserver.c b/connman/src/timeserver.c
new file mode 100644
index 0000000..f0d33e5
--- /dev/null
+++ b/connman/src/timeserver.c
@@ -0,0 +1,439 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2013  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 <glib.h>
+#include <stdlib.h>
+#include <gweb/gresolv.h>
+#include <netdb.h>
+
+#include "connman.h"
+
+#define TS_RECHECK_INTERVAL     7200
+
+static GSList *ts_list = NULL;
+static char *ts_current = NULL;
+static int ts_recheck_id = 0;
+
+static GResolv *resolv = NULL;
+static int resolv_id = 0;
+
+static void resolv_debug(const char *str, void *data)
+{
+	connman_info("%s: %s\n", (const char *) data, str);
+}
+static void save_timeservers(char **servers)
+{
+	GKeyFile *keyfile;
+	int cnt;
+
+	keyfile = __connman_storage_load_global();
+	if (!keyfile)
+		keyfile = g_key_file_new();
+
+	for (cnt = 0; servers && servers[cnt]; cnt++);
+
+	g_key_file_set_string_list(keyfile, "global", "Timeservers",
+			   (const gchar **)servers, cnt);
+
+	__connman_storage_save_global(keyfile);
+
+	g_key_file_free(keyfile);
+
+	return;
+}
+
+static char **load_timeservers(void)
+{
+	GKeyFile *keyfile;
+	char **servers = NULL;
+
+	keyfile = __connman_storage_load_global();
+	if (!keyfile)
+		return NULL;
+
+	servers = g_key_file_get_string_list(keyfile, "global",
+						"Timeservers", NULL, NULL);
+
+	g_key_file_free(keyfile);
+
+	return servers;
+}
+
+static void resolv_result(GResolvResultStatus status, char **results,
+				gpointer user_data)
+{
+	int i;
+
+	DBG("status %d", status);
+
+	if (status == G_RESOLV_RESULT_STATUS_SUCCESS) {
+		if (results) {
+			for (i = 0; results[i]; i++) {
+				DBG("result[%d]: %s", i, results[i]);
+				if (i == 0)
+					continue;
+
+				ts_list = __connman_timeserver_add_list(
+							ts_list, results[i]);
+			}
+
+			DBG("Using timeserver %s", results[0]);
+
+			__connman_ntp_start(results[0]);
+
+			return;
+		}
+	}
+
+	/* If resolving fails, move to the next server */
+	__connman_timeserver_sync_next();
+}
+
+/*
+ * Once the timeserver list (ts_list) is created, we start querying the
+ * servers one by one. If resolving fails on one of them, we move to the
+ * next one. The user can enter either an IP address or a URL for the
+ * timeserver. We only resolve the URLs. Once we have an IP for the NTP
+ * server, we start querying it for time corrections.
+ */
+void __connman_timeserver_sync_next()
+{
+	if (ts_current) {
+		g_free(ts_current);
+		ts_current = NULL;
+	}
+
+	__connman_ntp_stop();
+
+	/* Get the 1st server in the list */
+	if (!ts_list)
+		return;
+
+	ts_current = ts_list->data;
+
+	ts_list = g_slist_delete_link(ts_list, ts_list);
+
+	/* if it's an IP, directly query it. */
+	if (connman_inet_check_ipaddress(ts_current) > 0) {
+		DBG("Using timeserver %s", ts_current);
+
+		__connman_ntp_start(ts_current);
+
+		return;
+	}
+
+	DBG("Resolving timeserver %s", ts_current);
+
+	resolv_id = g_resolv_lookup_hostname(resolv, ts_current,
+						resolv_result, NULL);
+
+	return;
+}
+
+GSList *__connman_timeserver_add_list(GSList *server_list,
+		const char *timeserver)
+{
+	GSList *list = server_list;
+
+	if (!timeserver)
+		return server_list;
+
+	while (list) {
+		char *existing_server = list->data;
+		if (strcmp(timeserver, existing_server) == 0)
+			return server_list;
+		list = g_slist_next(list);
+	}
+	return g_slist_prepend(server_list, g_strdup(timeserver));
+}
+
+/*
+ * __connman_timeserver_get_all function creates the timeserver
+ * list which will be used to determine NTP server for time corrections.
+ * The service settings take priority over the global timeservers.
+ */
+GSList *__connman_timeserver_get_all(struct connman_service *service)
+{
+	GSList *list = NULL;
+	struct connman_network *network;
+	char **timeservers;
+	char **service_ts;
+	char **service_ts_config;
+	const char *service_gw;
+	char **fallback_ts;
+	int index, i;
+
+	if (__connman_clock_timeupdates() == TIME_UPDATES_MANUAL)
+		return NULL;
+
+	service_ts_config = connman_service_get_timeservers_config(service);
+
+	/* First add Service Timeservers.Configuration to the list */
+	for (i = 0; service_ts_config && service_ts_config[i];
+			i++)
+		list = __connman_timeserver_add_list(list,
+				service_ts_config[i]);
+
+	service_ts = connman_service_get_timeservers(service);
+
+	/* Then add Service Timeservers via DHCP to the list */
+	for (i = 0; service_ts && service_ts[i]; i++)
+		list = __connman_timeserver_add_list(list, service_ts[i]);
+
+	network = __connman_service_get_network(service);
+	if (network) {
+		index = connman_network_get_index(network);
+		service_gw = __connman_ipconfig_get_gateway_from_index(index,
+			CONNMAN_IPCONFIG_TYPE_ALL);
+
+		/* Then add Service Gateway to the list */
+		if (service_gw)
+			list = __connman_timeserver_add_list(list, service_gw);
+	}
+
+	/* Then add Global Timeservers to the list */
+	timeservers = load_timeservers();
+
+	for (i = 0; timeservers && timeservers[i]; i++)
+		list = __connman_timeserver_add_list(list, timeservers[i]);
+
+	g_strfreev(timeservers);
+
+	fallback_ts = connman_setting_get_string_list("FallbackTimeservers");
+
+	/* Lastly add the fallback servers */
+	for (i = 0; fallback_ts && fallback_ts[i]; i++)
+		list = __connman_timeserver_add_list(list, fallback_ts[i]);
+
+	return g_slist_reverse(list);
+}
+
+static gboolean ts_recheck(gpointer user_data)
+{
+	GSList *ts;
+
+	ts = __connman_timeserver_get_all(__connman_service_get_default());
+
+	if (!ts) {
+		DBG("timeservers disabled");
+
+		return TRUE;
+	}
+
+	if (g_strcmp0(ts_current, ts->data) != 0) {
+		DBG("current %s preferred %s", ts_current, (char *)ts->data);
+
+		g_slist_free_full(ts, g_free);
+
+		__connman_timeserver_sync(NULL);
+
+		return FALSE;
+	}
+
+	DBG("");
+
+	g_slist_free_full(ts, g_free);
+
+	return TRUE;
+}
+
+static void ts_recheck_disable(void)
+{
+	if (ts_recheck_id == 0)
+		return;
+
+	g_source_remove(ts_recheck_id);
+	ts_recheck_id = 0;
+
+	if (ts_current) {
+		g_free(ts_current);
+		ts_current = NULL;
+	}
+}
+
+static void ts_recheck_enable(void)
+{
+	if (ts_recheck_id > 0)
+		return;
+
+	ts_recheck_id = g_timeout_add_seconds(TS_RECHECK_INTERVAL, ts_recheck,
+			NULL);
+}
+
+/*
+ * This function must be called everytime the default service changes, the
+ * service timeserver(s) or gateway changes or the global timeserver(s) changes.
+ */
+int __connman_timeserver_sync(struct connman_service *default_service)
+{
+	struct connman_service *service;
+
+	if (default_service)
+		service = default_service;
+	else
+		service = __connman_service_get_default();
+
+	if (!service)
+		return -EINVAL;
+
+	if (!resolv)
+		return 0;
+	/*
+	 * Before we start creating the new timeserver list we must stop
+	 * any ongoing ntp query and server resolution.
+	 */
+
+	__connman_ntp_stop();
+
+	ts_recheck_disable();
+
+	if (resolv_id > 0)
+		g_resolv_cancel_lookup(resolv, resolv_id);
+
+	g_slist_free_full(ts_list, g_free);
+
+	ts_list = __connman_timeserver_get_all(service);
+
+	__connman_service_timeserver_changed(service, ts_list);
+
+	if (!ts_list) {
+		DBG("No timeservers set.");
+		return 0;
+	}
+
+	ts_recheck_enable();
+
+	__connman_timeserver_sync_next();
+
+	return 0;
+}
+
+static int timeserver_start(struct connman_service *service)
+{
+	char **nameservers;
+	int i;
+
+	DBG("service %p", service);
+
+	i = __connman_service_get_index(service);
+	if (i < 0)
+		return -EINVAL;
+
+	nameservers = connman_service_get_nameservers(service);
+	if (!nameservers)
+		return -EINVAL;
+
+	/* Stop an already ongoing resolution, if there is one */
+	if (resolv && resolv_id > 0)
+		g_resolv_cancel_lookup(resolv, resolv_id);
+
+	/* get rid of the old resolver */
+	if (resolv) {
+		g_resolv_unref(resolv);
+		resolv = NULL;
+	}
+
+	resolv = g_resolv_new(i);
+	if (!resolv) {
+		g_strfreev(nameservers);
+		return -ENOMEM;
+	}
+
+	if (getenv("CONNMAN_RESOLV_DEBUG"))
+		g_resolv_set_debug(resolv, resolv_debug, "RESOLV");
+
+	for (i = 0; nameservers[i]; i++)
+		g_resolv_add_nameserver(resolv, nameservers[i], 53, 0);
+
+	g_strfreev(nameservers);
+
+	return __connman_timeserver_sync(service);
+}
+
+static void timeserver_stop(void)
+{
+	DBG(" ");
+
+	if (resolv) {
+		g_resolv_unref(resolv);
+		resolv = NULL;
+	}
+
+	g_slist_free_full(ts_list, g_free);
+
+	ts_list = NULL;
+
+	__connman_ntp_stop();
+
+	ts_recheck_disable();
+}
+
+int __connman_timeserver_system_set(char **servers)
+{
+	save_timeservers(servers);
+
+	__connman_timeserver_sync(NULL);
+
+	return 0;
+}
+
+char **__connman_timeserver_system_get()
+{
+	char **servers;
+
+	servers = load_timeservers();
+	return servers;
+}
+
+static void default_changed(struct connman_service *default_service)
+{
+	if (default_service)
+		timeserver_start(default_service);
+	else
+		timeserver_stop();
+}
+
+static struct connman_notifier timeserver_notifier = {
+	.name			= "timeserver",
+	.default_changed	= default_changed,
+};
+
+int __connman_timeserver_init(void)
+{
+	DBG("");
+
+	connman_notifier_register(&timeserver_notifier);
+
+	return 0;
+}
+
+void __connman_timeserver_cleanup(void)
+{
+	DBG("");
+
+	connman_notifier_unregister(&timeserver_notifier);
+}
diff --git a/connman/src/timezone.c b/connman/src/timezone.c
new file mode 100644
index 0000000..e346b11
--- /dev/null
+++ b/connman/src/timezone.c
@@ -0,0 +1,454 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2012  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
+
+#define _GNU_SOURCE
+#include <errno.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <dirent.h>
+#include <sys/stat.h>
+#include <sys/mman.h>
+#include <sys/inotify.h>
+
+#include <glib.h>
+
+#include "connman.h"
+
+#define ETC_LOCALTIME		"/etc/localtime"
+#define ETC_SYSCONFIG_CLOCK	"/etc/sysconfig/clock"
+#define USR_SHARE_ZONEINFO	"/usr/share/zoneinfo"
+
+static char *read_key_file(const char *pathname, const char *key)
+{
+	struct stat st;
+	char *map, *ptr, *str;
+	off_t ptrlen, keylen;
+	int fd;
+
+	fd = open(pathname, O_RDONLY | O_CLOEXEC);
+	if (fd < 0)
+		return NULL;
+
+	if (fstat(fd, &st) < 0) {
+		close(fd);
+		return NULL;
+	}
+
+	map = mmap(0, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
+	if (!map || map == MAP_FAILED) {
+		close(fd);
+		return NULL;
+	}
+
+	ptr = map;
+	ptrlen = st.st_size;
+	keylen = strlen(key);
+
+	while (ptrlen > keylen + 1) {
+		int cmp = strncmp(ptr, key, keylen);
+
+		if (cmp == 0) {
+			if (ptr == map)
+				break;
+
+			if (*(ptr - 1) == '\n' && *(ptr + keylen) == '=')
+				break;
+		}
+
+		ptr = memchr(ptr + 1, key[0], ptrlen - 1);
+		if (!ptr)
+			break;
+
+		ptrlen = st.st_size - (ptr - map);
+	}
+
+	if (ptr) {
+		char *end, *val;
+
+		ptrlen = st.st_size - (ptr - map);
+
+		end = memchr(ptr, '\n', ptrlen);
+		if (end)
+			ptrlen = end - ptr;
+
+		val = memchr(ptr, '"', ptrlen);
+		if (val) {
+			end = memchr(val + 1, '"', end - val - 1);
+			if (end)
+				str = g_strndup(val + 1, end - val - 1);
+			else
+				str = NULL;
+		} else
+			str = g_strndup(ptr + keylen + 1, ptrlen - keylen - 1);
+	} else
+		str = NULL;
+
+	munmap(map, st.st_size);
+
+	close(fd);
+
+	return str;
+}
+
+static int compare_file(void *src_map, struct stat *src_st,
+						const char *pathname)
+{
+	struct stat dst_st;
+	void *dst_map;
+	int fd, result;
+
+	fd = open(pathname, O_RDONLY | O_CLOEXEC);
+	if (fd < 0)
+		return -1;
+
+	if (fstat(fd, &dst_st) < 0) {
+		close(fd);
+		return -1;
+	}
+
+	if (src_st->st_size != dst_st.st_size) {
+		close(fd);
+		return -1;
+	}
+
+	dst_map = mmap(0, dst_st.st_size, PROT_READ, MAP_SHARED, fd, 0);
+	if (!dst_map || dst_map == MAP_FAILED) {
+		close(fd);
+		return -1;
+	}
+
+	result = memcmp(src_map, dst_map, src_st->st_size);
+
+	munmap(dst_map, dst_st.st_size);
+
+	close(fd);
+
+	return result;
+}
+
+static char *find_origin(void *src_map, struct stat *src_st,
+				const char *basepath, const char *subpath)
+{
+	DIR *dir;
+	struct dirent *d;
+	char *str, pathname[PATH_MAX];
+	struct stat buf;
+	int ret;
+
+	if (!subpath)
+		strncpy(pathname, basepath, sizeof(pathname) - 1);
+	else
+		snprintf(pathname, sizeof(pathname),
+					"%s/%s", basepath, subpath);
+
+	dir = opendir(pathname);
+	if (!dir)
+		return NULL;
+
+	while ((d = readdir(dir))) {
+		if (strcmp(d->d_name, ".") == 0 ||
+				strcmp(d->d_name, "..") == 0 ||
+				strcmp(d->d_name, "posix") == 0 ||
+				strcmp(d->d_name, "right") == 0)
+			continue;
+
+		switch (d->d_type) {
+		case DT_REG:
+			if (!subpath)
+				snprintf(pathname, PATH_MAX,
+						"%s/%s", basepath, d->d_name);
+			else
+				snprintf(pathname, PATH_MAX,
+						"%s/%s/%s", basepath,
+							subpath, d->d_name);
+
+			if (compare_file(src_map, src_st, pathname) == 0) {
+				str = g_strdup_printf("%s/%s",
+							subpath, d->d_name);
+				closedir(dir);
+				return str;
+			}
+			break;
+		case DT_UNKNOWN:
+			/*
+			 * If there is no d_type support use fstatat()
+			 * to check if d_name is directory
+			 */
+			ret = fstatat(dirfd(dir), d->d_name, &buf, 0);
+			if (ret < 0)
+				continue;
+			if ((buf.st_mode & S_IFDIR) == 0)
+				continue;
+			/* fall through */
+		case DT_DIR:
+			if (!subpath)
+				strncpy(pathname, d->d_name, sizeof(pathname));
+			else
+				snprintf(pathname, sizeof(pathname),
+						"%s/%s", subpath, d->d_name);
+
+			str = find_origin(src_map, src_st, basepath, pathname);
+			if (str) {
+				closedir(dir);
+				return str;
+			}
+			break;
+		}
+	}
+
+	closedir(dir);
+
+	return NULL;
+}
+
+char *__connman_timezone_lookup(void)
+{
+	struct stat st;
+	void *map;
+	int fd;
+	char *zone;
+
+	zone = read_key_file(ETC_SYSCONFIG_CLOCK, "ZONE");
+
+	DBG("sysconfig zone %s", zone);
+
+	fd = open(ETC_LOCALTIME, O_RDONLY | O_CLOEXEC);
+	if (fd < 0) {
+		g_free(zone);
+		return NULL;
+	}
+
+	if (fstat(fd, &st) < 0)
+		goto done;
+
+	if (S_ISREG(st.st_mode)) {
+		map = mmap(0, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
+		if (!map || map == MAP_FAILED) {
+			g_free(zone);
+			zone = NULL;
+
+			goto done;
+		}
+
+		if (zone) {
+			char pathname[PATH_MAX];
+
+			snprintf(pathname, PATH_MAX, "%s/%s",
+						USR_SHARE_ZONEINFO, zone);
+
+			if (compare_file(map, &st, pathname) != 0) {
+				g_free(zone);
+				zone = NULL;
+			}
+		}
+
+		if (!zone)
+			zone = find_origin(map, &st, USR_SHARE_ZONEINFO, NULL);
+
+		munmap(map, st.st_size);
+	} else {
+		g_free(zone);
+		zone = NULL;
+	}
+
+done:
+	close(fd);
+
+	DBG("localtime zone %s", zone);
+
+	return zone;
+}
+
+static int write_file(void *src_map, struct stat *src_st, const char *pathname)
+{
+	struct stat st;
+	int fd;
+	ssize_t written;
+
+	DBG("pathname %s", pathname);
+
+	if (lstat(pathname, &st) == 0) {
+		if (S_ISLNK(st.st_mode))
+			unlink(pathname);
+	}
+
+	fd = open(pathname, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644);
+	if (fd < 0)
+		return -EIO;
+
+	written = write(fd, src_map, src_st->st_size);
+
+	close(fd);
+
+	if (written < 0)
+		return -EIO;
+
+	return 0;
+}
+
+int __connman_timezone_change(const char *zone)
+{
+	struct stat st;
+	char *map, pathname[PATH_MAX];
+	int fd, err;
+
+	DBG("zone %s", zone);
+
+	snprintf(pathname, PATH_MAX, "%s/%s", USR_SHARE_ZONEINFO, zone);
+
+	fd = open(pathname, O_RDONLY | O_CLOEXEC);
+	if (fd < 0)
+		return -EINVAL;
+
+	if (fstat(fd, &st) < 0) {
+		close(fd);
+		return -EIO;
+	}
+
+	map = mmap(0, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
+	if (!map || map == MAP_FAILED) {
+		close(fd);
+		return -EIO;
+	}
+
+	err = write_file(map, &st, ETC_LOCALTIME);
+
+	munmap(map, st.st_size);
+
+	close(fd);
+
+	return err;
+}
+
+static guint inotify_watch = 0;
+
+static gboolean inotify_data(GIOChannel *channel, GIOCondition cond,
+							gpointer user_data)
+{
+	char buffer[256];
+	void *ptr = buffer;
+	GIOStatus status;
+	gsize bytes_read;
+
+	DBG("");
+
+	if (cond & (G_IO_NVAL | G_IO_ERR | G_IO_HUP)) {
+		inotify_watch = 0;
+		return FALSE;
+	}
+
+	status = g_io_channel_read_chars(channel, buffer, sizeof(buffer),
+							&bytes_read, NULL);
+
+	switch (status) {
+	case G_IO_STATUS_NORMAL:
+		break;
+	case G_IO_STATUS_AGAIN:
+		return TRUE;
+	default:
+		inotify_watch = 0;
+		return FALSE;
+	}
+
+	DBG("bytes read %zd", bytes_read);
+
+	while (bytes_read > 0) {
+		struct inotify_event *event = ptr;
+
+		if (bytes_read < sizeof(*event))
+			break;
+
+		ptr += sizeof(*event);
+		bytes_read -= sizeof(*event);
+
+		if (event->len == 0)
+			continue;
+
+		if (bytes_read < event->len)
+			break;
+
+		ptr += event->len;
+		bytes_read -= event->len;
+
+		if (g_strcmp0(event->name, "localtime") == 0)
+			__connman_clock_update_timezone();
+	}
+
+	return TRUE;
+}
+
+int __connman_timezone_init(void)
+{
+	GIOChannel *channel;
+	char *dirname;
+	int fd, wd;
+
+	DBG("");
+
+	fd = inotify_init1(IN_NONBLOCK | IN_CLOEXEC);
+	if (fd < 0)
+		return -EIO;
+
+	channel = g_io_channel_unix_new(fd);
+	if (!channel) {
+		close(fd);
+		return -EIO;
+	}
+
+	g_io_channel_set_close_on_unref(channel, TRUE);
+	g_io_channel_set_encoding(channel, NULL, NULL);
+	g_io_channel_set_buffered(channel, FALSE);
+
+	inotify_watch = g_io_add_watch(channel,
+				G_IO_IN | G_IO_HUP | G_IO_NVAL | G_IO_ERR,
+				inotify_data, NULL);
+
+	g_io_channel_unref(channel);
+
+	dirname = g_path_get_dirname(ETC_LOCALTIME);
+
+	wd = inotify_add_watch(fd, dirname, IN_DONT_FOLLOW |
+						IN_CLOSE_WRITE | IN_MOVED_TO);
+
+	g_free(dirname);
+
+	if (wd < 0)
+		return -EIO;
+
+	return 0;
+}
+
+void __connman_timezone_cleanup(void)
+{
+	DBG("");
+
+	if (inotify_watch > 0) {
+		g_source_remove(inotify_watch);
+		inotify_watch = 0;
+	}
+}
diff --git a/connman/src/util.c b/connman/src/util.c
new file mode 100644
index 0000000..da32cc5
--- /dev/null
+++ b/connman/src/util.c
@@ -0,0 +1,88 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2014  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 <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <stdint.h>
+#include <unistd.h>
+#include <errno.h>
+#include <stdlib.h>
+
+#include "connman.h"
+
+#define URANDOM "/dev/urandom"
+
+int f = -1;
+
+int __connman_util_get_random(uint64_t *val)
+{
+	int r = 0;
+
+	if (!val)
+		return -EINVAL;
+
+	if (read(f, val, sizeof(uint64_t)) < 0) {
+		r = -errno;
+		connman_warn_once("Could not read from "URANDOM);
+		*val = random();
+	}
+
+	return r;
+}
+
+int __connman_util_init(void)
+{
+	int r = 0;
+
+	if (f > 0)
+		return 0;
+
+	f = open(URANDOM, O_RDONLY);
+	if (f < 0) {
+		r = -errno;
+		connman_warn("Could not open "URANDOM);
+		srandom(time(NULL));
+	} else {
+		uint64_t val;
+
+		r = __connman_util_get_random(&val);
+		if (r < 0)
+			srandom(time(NULL));
+		else
+			srandom(val);
+	}
+
+	return r;
+}
+
+void __connman_util_cleanup(void)
+{
+	if (f > 0)
+		close(f);
+
+	f = -1;
+}
diff --git a/connman/src/utsname.c b/connman/src/utsname.c
new file mode 100644
index 0000000..1dd5e0f
--- /dev/null
+++ b/connman/src/utsname.c
@@ -0,0 +1,139 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2012  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 <glib.h>
+
+#include "connman.h"
+
+static GSList *driver_list = NULL;
+
+static gint compare_priority(gconstpointer a, gconstpointer b)
+{
+	const struct connman_utsname_driver *driver1 = a;
+	const struct connman_utsname_driver *driver2 = b;
+
+	return driver2->priority - driver1->priority;
+}
+
+/**
+ * connman_utsname_driver_register:
+ * @driver: utsname driver definition
+ *
+ * Register a new utsname driver
+ *
+ * Returns: %0 on success
+ */
+int connman_utsname_driver_register(struct connman_utsname_driver *driver)
+{
+	DBG("driver %p name %s", driver, driver->name);
+
+	driver_list = g_slist_insert_sorted(driver_list, driver,
+							compare_priority);
+
+	return 0;
+}
+
+/**
+ * connman_utsname_driver_unregister:
+ * @driver: utsname driver definition
+ *
+ * Remove a previously registered utsname driver
+ */
+void connman_utsname_driver_unregister(struct connman_utsname_driver *driver)
+{
+	DBG("driver %p name %s", driver, driver->name);
+
+	driver_list = g_slist_remove(driver_list, driver);
+}
+
+/**
+ * connman_utsname_get_hostname:
+ *
+ * Returns current hostname
+ */
+const char *connman_utsname_get_hostname(void)
+{
+	GSList *list;
+
+	DBG("");
+
+	for (list = driver_list; list; list = list->next) {
+		struct connman_utsname_driver *driver = list->data;
+		const char *hostname;
+
+		DBG("driver %p name %s", driver, driver->name);
+
+		if (!driver->get_hostname)
+			continue;
+
+		hostname = driver->get_hostname();
+		if (hostname)
+			return hostname;
+	}
+
+	return NULL;
+}
+
+int __connman_utsname_set_hostname(const char *hostname)
+{
+	GSList *list;
+
+	DBG("hostname %s", hostname);
+
+	for (list = driver_list; list; list = list->next) {
+		struct connman_utsname_driver *driver = list->data;
+
+		DBG("driver %p name %s", driver, driver->name);
+
+		if (!driver->set_hostname)
+			continue;
+
+		if (driver->set_hostname(hostname) == 0)
+			break;
+	}
+
+	return 0;
+}
+
+int __connman_utsname_set_domainname(const char *domainname)
+{
+	GSList *list;
+
+	DBG("domainname %s", domainname);
+
+	for (list = driver_list; list; list = list->next) {
+		struct connman_utsname_driver *driver = list->data;
+
+		DBG("driver %p name %s", driver, driver->name);
+
+		if (!driver->set_domainname)
+			continue;
+
+		if (driver->set_domainname(domainname) == 0)
+			break;
+	}
+
+	return 0;
+}
diff --git a/connman/src/wispr.c b/connman/src/wispr.c
new file mode 100644
index 0000000..10f869b
--- /dev/null
+++ b/connman/src/wispr.c
@@ -0,0 +1,1008 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2013  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 <gweb/gweb.h>
+
+#include "connman.h"
+
+#define STATUS_URL_IPV4  "http://ipv4.connman.net/online/status.html"
+#define STATUS_URL_IPV6  "http://ipv6.connman.net/online/status.html"
+
+struct connman_wispr_message {
+	bool has_error;
+	const char *current_element;
+	int message_type;
+	int response_code;
+	char *login_url;
+	char *abort_login_url;
+	char *logoff_url;
+	char *access_procedure;
+	char *access_location;
+	char *location_name;
+};
+
+enum connman_wispr_result {
+	CONNMAN_WISPR_RESULT_UNKNOWN = 0,
+	CONNMAN_WISPR_RESULT_LOGIN   = 1,
+	CONNMAN_WISPR_RESULT_ONLINE  = 2,
+	CONNMAN_WISPR_RESULT_FAILED  = 3,
+};
+
+struct wispr_route {
+	char *address;
+	int if_index;
+};
+
+struct connman_wispr_portal_context {
+	struct connman_service *service;
+	enum connman_ipconfig_type type;
+	struct connman_wispr_portal *wispr_portal;
+
+	/* Portal/WISPr common */
+	GWeb *web;
+	unsigned int token;
+	guint request_id;
+
+	const char *status_url;
+
+	char *redirect_url;
+
+	/* WISPr specific */
+	GWebParser *wispr_parser;
+	struct connman_wispr_message wispr_msg;
+
+	char *wispr_username;
+	char *wispr_password;
+	char *wispr_formdata;
+
+	enum connman_wispr_result wispr_result;
+
+	GSList *route_list;
+
+	guint timeout;
+};
+
+struct connman_wispr_portal {
+	struct connman_wispr_portal_context *ipv4_context;
+	struct connman_wispr_portal_context *ipv6_context;
+};
+
+static bool wispr_portal_web_result(GWebResult *result, gpointer user_data);
+
+static GHashTable *wispr_portal_list = NULL;
+
+static void connman_wispr_message_init(struct connman_wispr_message *msg)
+{
+	DBG("");
+
+	msg->has_error = false;
+	msg->current_element = NULL;
+
+	msg->message_type = -1;
+	msg->response_code = -1;
+
+	g_free(msg->login_url);
+	msg->login_url = NULL;
+
+	g_free(msg->abort_login_url);
+	msg->abort_login_url = NULL;
+
+	g_free(msg->logoff_url);
+	msg->logoff_url = NULL;
+
+	g_free(msg->access_procedure);
+	msg->access_procedure = NULL;
+
+	g_free(msg->access_location);
+	msg->access_location = NULL;
+
+	g_free(msg->location_name);
+	msg->location_name = NULL;
+}
+
+static void free_wispr_routes(struct connman_wispr_portal_context *wp_context)
+{
+	while (wp_context->route_list) {
+		struct wispr_route *route = wp_context->route_list->data;
+
+		DBG("free route to %s if %d type %d", route->address,
+				route->if_index, wp_context->type);
+
+		switch (wp_context->type) {
+		case CONNMAN_IPCONFIG_TYPE_IPV4:
+			connman_inet_del_host_route(route->if_index,
+					route->address);
+			break;
+		case CONNMAN_IPCONFIG_TYPE_IPV6:
+			connman_inet_del_ipv6_host_route(route->if_index,
+					route->address);
+			break;
+		case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
+		case CONNMAN_IPCONFIG_TYPE_ALL:
+			break;
+		}
+
+		g_free(route->address);
+		g_free(route);
+
+		wp_context->route_list =
+			g_slist_delete_link(wp_context->route_list,
+					wp_context->route_list);
+	}
+}
+
+static void free_connman_wispr_portal_context(
+		struct connman_wispr_portal_context *wp_context)
+{
+	DBG("context %p", wp_context);
+
+	if (!wp_context)
+		return;
+
+	if (wp_context->wispr_portal) {
+		if (wp_context->wispr_portal->ipv4_context == wp_context)
+			wp_context->wispr_portal->ipv4_context = NULL;
+
+		if (wp_context->wispr_portal->ipv6_context == wp_context)
+			wp_context->wispr_portal->ipv6_context = NULL;
+	}
+
+	if (wp_context->token > 0)
+		connman_proxy_lookup_cancel(wp_context->token);
+
+	if (wp_context->request_id > 0)
+		g_web_cancel_request(wp_context->web, wp_context->request_id);
+
+	if (wp_context->timeout > 0)
+		g_source_remove(wp_context->timeout);
+
+	if (wp_context->web)
+		g_web_unref(wp_context->web);
+
+	g_free(wp_context->redirect_url);
+
+	if (wp_context->wispr_parser)
+		g_web_parser_unref(wp_context->wispr_parser);
+
+	connman_wispr_message_init(&wp_context->wispr_msg);
+
+	g_free(wp_context->wispr_username);
+	g_free(wp_context->wispr_password);
+	g_free(wp_context->wispr_formdata);
+
+	free_wispr_routes(wp_context);
+
+	g_free(wp_context);
+}
+
+static struct connman_wispr_portal_context *create_wispr_portal_context(void)
+{
+	return g_try_new0(struct connman_wispr_portal_context, 1);
+}
+
+static void free_connman_wispr_portal(gpointer data)
+{
+	struct connman_wispr_portal *wispr_portal = data;
+
+	DBG("");
+
+	if (!wispr_portal)
+		return;
+
+	free_connman_wispr_portal_context(wispr_portal->ipv4_context);
+	free_connman_wispr_portal_context(wispr_portal->ipv6_context);
+
+	g_free(wispr_portal);
+}
+
+static const char *message_type_to_string(int message_type)
+{
+	switch (message_type) {
+	case 100:
+		return "Initial redirect message";
+	case 110:
+		return "Proxy notification";
+	case 120:
+		return "Authentication notification";
+	case 130:
+		return "Logoff notification";
+	case 140:
+		return "Response to Authentication Poll";
+	case 150:
+		return "Response to Abort Login";
+	}
+
+	return NULL;
+}
+
+static const char *response_code_to_string(int response_code)
+{
+	switch (response_code) {
+	case 0:
+		return "No error";
+	case 50:
+		return "Login succeeded";
+	case 100:
+		return "Login failed";
+	case 102:
+		return "RADIUS server error/timeout";
+	case 105:
+		return "RADIUS server not enabled";
+	case 150:
+		return "Logoff succeeded";
+	case 151:
+		return "Login aborted";
+	case 200:
+		return "Proxy detection/repeat operation";
+	case 201:
+		return "Authentication pending";
+	case 255:
+		return "Access gateway internal error";
+	}
+
+	return NULL;
+}
+
+static struct {
+	const char *str;
+	enum {
+		WISPR_ELEMENT_NONE              = 0,
+		WISPR_ELEMENT_ACCESS_PROCEDURE  = 1,
+		WISPR_ELEMENT_ACCESS_LOCATION   = 2,
+		WISPR_ELEMENT_LOCATION_NAME     = 3,
+		WISPR_ELEMENT_LOGIN_URL         = 4,
+		WISPR_ELEMENT_ABORT_LOGIN_URL   = 5,
+		WISPR_ELEMENT_MESSAGE_TYPE      = 6,
+		WISPR_ELEMENT_RESPONSE_CODE     = 7,
+		WISPR_ELEMENT_NEXT_URL          = 8,
+		WISPR_ELEMENT_DELAY             = 9,
+		WISPR_ELEMENT_REPLY_MESSAGE     = 10,
+		WISPR_ELEMENT_LOGIN_RESULTS_URL = 11,
+		WISPR_ELEMENT_LOGOFF_URL        = 12,
+	} element;
+} wispr_element_map[] = {
+	{ "AccessProcedure",	WISPR_ELEMENT_ACCESS_PROCEDURE	},
+	{ "AccessLocation",	WISPR_ELEMENT_ACCESS_LOCATION	},
+	{ "LocationName",	WISPR_ELEMENT_LOCATION_NAME	},
+	{ "LoginURL",		WISPR_ELEMENT_LOGIN_URL		},
+	{ "AbortLoginURL",	WISPR_ELEMENT_ABORT_LOGIN_URL	},
+	{ "MessageType",	WISPR_ELEMENT_MESSAGE_TYPE	},
+	{ "ResponseCode",	WISPR_ELEMENT_RESPONSE_CODE	},
+	{ "NextURL",		WISPR_ELEMENT_NEXT_URL		},
+	{ "Delay",		WISPR_ELEMENT_DELAY		},
+	{ "ReplyMessage",	WISPR_ELEMENT_REPLY_MESSAGE	},
+	{ "LoginResultsURL",	WISPR_ELEMENT_LOGIN_RESULTS_URL	},
+	{ "LogoffURL",		WISPR_ELEMENT_LOGOFF_URL	},
+	{ NULL,			WISPR_ELEMENT_NONE		},
+};
+
+static void xml_wispr_start_element_handler(GMarkupParseContext *context,
+					const gchar *element_name,
+					const gchar **attribute_names,
+					const gchar **attribute_values,
+					gpointer user_data, GError **error)
+{
+	struct connman_wispr_message *msg = user_data;
+
+	msg->current_element = element_name;
+}
+
+static void xml_wispr_end_element_handler(GMarkupParseContext *context,
+					const gchar *element_name,
+					gpointer user_data, GError **error)
+{
+	struct connman_wispr_message *msg = user_data;
+
+	msg->current_element = NULL;
+}
+
+static void xml_wispr_text_handler(GMarkupParseContext *context,
+					const gchar *text, gsize text_len,
+					gpointer user_data, GError **error)
+{
+	struct connman_wispr_message *msg = user_data;
+	int i;
+
+	if (!msg->current_element)
+		return;
+
+	for (i = 0; wispr_element_map[i].str; i++) {
+		if (!g_str_equal(wispr_element_map[i].str, msg->current_element))
+			continue;
+
+		switch (wispr_element_map[i].element) {
+		case WISPR_ELEMENT_NONE:
+		case WISPR_ELEMENT_ACCESS_PROCEDURE:
+			g_free(msg->access_procedure);
+			msg->access_procedure = g_strdup(text);
+			break;
+		case WISPR_ELEMENT_ACCESS_LOCATION:
+			g_free(msg->access_location);
+			msg->access_location = g_strdup(text);
+			break;
+		case WISPR_ELEMENT_LOCATION_NAME:
+			g_free(msg->location_name);
+			msg->location_name = g_strdup(text);
+			break;
+		case WISPR_ELEMENT_LOGIN_URL:
+			g_free(msg->login_url);
+			msg->login_url = g_strdup(text);
+			break;
+		case WISPR_ELEMENT_ABORT_LOGIN_URL:
+			g_free(msg->abort_login_url);
+			msg->abort_login_url = g_strdup(text);
+			break;
+		case WISPR_ELEMENT_MESSAGE_TYPE:
+			msg->message_type = atoi(text);
+			break;
+		case WISPR_ELEMENT_RESPONSE_CODE:
+			msg->response_code = atoi(text);
+			break;
+		case WISPR_ELEMENT_NEXT_URL:
+		case WISPR_ELEMENT_DELAY:
+		case WISPR_ELEMENT_REPLY_MESSAGE:
+		case WISPR_ELEMENT_LOGIN_RESULTS_URL:
+			break;
+		case WISPR_ELEMENT_LOGOFF_URL:
+			g_free(msg->logoff_url);
+			msg->logoff_url = g_strdup(text);
+			break;
+		}
+	}
+}
+
+static void xml_wispr_error_handler(GMarkupParseContext *context,
+					GError *error, gpointer user_data)
+{
+	struct connman_wispr_message *msg = user_data;
+
+	msg->has_error = true;
+}
+
+static const GMarkupParser xml_wispr_parser_handlers = {
+	xml_wispr_start_element_handler,
+	xml_wispr_end_element_handler,
+	xml_wispr_text_handler,
+	NULL,
+	xml_wispr_error_handler,
+};
+
+static void xml_wispr_parser_callback(const char *str, gpointer user_data)
+{
+	struct connman_wispr_portal_context *wp_context = user_data;
+	GMarkupParseContext *parser_context = NULL;
+	bool result;
+
+	DBG("");
+
+	parser_context = g_markup_parse_context_new(&xml_wispr_parser_handlers,
+					G_MARKUP_TREAT_CDATA_AS_TEXT,
+					&(wp_context->wispr_msg), NULL);
+
+	result = g_markup_parse_context_parse(parser_context,
+					str, strlen(str), NULL);
+	if (result)
+		g_markup_parse_context_end_parse(parser_context, NULL);
+
+	g_markup_parse_context_free(parser_context);
+}
+
+static void web_debug(const char *str, void *data)
+{
+	connman_info("%s: %s\n", (const char *) data, str);
+}
+
+static void wispr_portal_error(struct connman_wispr_portal_context *wp_context)
+{
+	DBG("Failed to proceed wispr/portal web request");
+
+	wp_context->wispr_result = CONNMAN_WISPR_RESULT_FAILED;
+}
+
+static void portal_manage_status(GWebResult *result,
+			struct connman_wispr_portal_context *wp_context)
+{
+	struct connman_service *service = wp_context->service;
+	enum connman_ipconfig_type type = wp_context->type;
+	const char *str = NULL;
+
+	DBG("");
+
+	/* We currently don't do anything with this info */
+	if (g_web_result_get_header(result, "X-ConnMan-Client-IP",
+				&str))
+		connman_info("Client-IP: %s", str);
+
+	if (g_web_result_get_header(result, "X-ConnMan-Client-Country",
+				&str))
+		connman_info("Client-Country: %s", str);
+
+	if (g_web_result_get_header(result, "X-ConnMan-Client-Region",
+				&str))
+		connman_info("Client-Region: %s", str);
+
+	if (g_web_result_get_header(result, "X-ConnMan-Client-Timezone",
+				&str))
+		connman_info("Client-Timezone: %s", str);
+
+	free_connman_wispr_portal_context(wp_context);
+
+	__connman_service_ipconfig_indicate_state(service,
+					CONNMAN_SERVICE_STATE_ONLINE, type);
+}
+
+static bool wispr_route_request(const char *address, int ai_family,
+		int if_index, gpointer user_data)
+{
+	int result = -1;
+	struct connman_wispr_portal_context *wp_context = user_data;
+	const char *gateway;
+	struct wispr_route *route;
+
+	gateway = __connman_ipconfig_get_gateway_from_index(if_index,
+		wp_context->type);
+
+	DBG("address %s if %d gw %s", address, if_index, gateway);
+
+	if (!gateway)
+		return false;
+
+	route = g_try_new0(struct wispr_route, 1);
+	if (route == 0) {
+		DBG("could not create struct");
+		return false;
+	}
+
+	switch (wp_context->type) {
+	case CONNMAN_IPCONFIG_TYPE_IPV4:
+		result = connman_inet_add_host_route(if_index, address,
+				gateway);
+		break;
+	case CONNMAN_IPCONFIG_TYPE_IPV6:
+		result = connman_inet_add_ipv6_host_route(if_index, address,
+				gateway);
+		break;
+	case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
+	case CONNMAN_IPCONFIG_TYPE_ALL:
+		break;
+	}
+
+	if (result < 0) {
+		g_free(route);
+		return false;
+	}
+
+	route->address = g_strdup(address);
+	route->if_index = if_index;
+	wp_context->route_list = g_slist_prepend(wp_context->route_list, route);
+
+	return true;
+}
+
+static void wispr_portal_request_portal(
+		struct connman_wispr_portal_context *wp_context)
+{
+	DBG("");
+
+	wp_context->request_id = g_web_request_get(wp_context->web,
+					wp_context->status_url,
+					wispr_portal_web_result,
+					wispr_route_request,
+					wp_context);
+
+	if (wp_context->request_id == 0)
+		wispr_portal_error(wp_context);
+}
+
+static bool wispr_input(const guint8 **data, gsize *length,
+						gpointer user_data)
+{
+	struct connman_wispr_portal_context *wp_context = user_data;
+	GString *buf;
+	gsize count;
+
+	DBG("");
+
+	buf = g_string_sized_new(100);
+
+	g_string_append(buf, "button=Login&UserName=");
+	g_string_append_uri_escaped(buf, wp_context->wispr_username,
+								NULL, FALSE);
+	g_string_append(buf, "&Password=");
+	g_string_append_uri_escaped(buf, wp_context->wispr_password,
+								NULL, FALSE);
+	g_string_append(buf, "&FNAME=0&OriginatingServer=");
+	g_string_append_uri_escaped(buf, wp_context->status_url, NULL, FALSE);
+
+	count = buf->len;
+
+	g_free(wp_context->wispr_formdata);
+	wp_context->wispr_formdata = g_string_free(buf, FALSE);
+
+	*data = (guint8 *) wp_context->wispr_formdata;
+	*length = count;
+
+	return false;
+}
+
+static void wispr_portal_browser_reply_cb(struct connman_service *service,
+					bool authentication_done,
+					const char *error, void *user_data)
+{
+	struct connman_wispr_portal_context *wp_context = user_data;
+
+	DBG("");
+
+	if (!service || !wp_context)
+		return;
+
+	if (!authentication_done) {
+		wispr_portal_error(wp_context);
+		free_wispr_routes(wp_context);
+		return;
+	}
+
+	/* Restarting the test */
+	__connman_wispr_start(service, wp_context->type);
+}
+
+static void wispr_portal_request_wispr_login(struct connman_service *service,
+				bool success,
+				const char *ssid, int ssid_len,
+				const char *username, const char *password,
+				bool wps, const char *wpspin,
+				const char *error, void *user_data)
+{
+	struct connman_wispr_portal_context *wp_context = user_data;
+
+	DBG("");
+
+	if (error) {
+		if (g_strcmp0(error,
+			"net.connman.Agent.Error.LaunchBrowser") == 0) {
+			if (__connman_agent_request_browser(service,
+					wispr_portal_browser_reply_cb,
+					wp_context->redirect_url,
+					wp_context) == -EINPROGRESS)
+				return;
+		}
+
+		free_connman_wispr_portal_context(wp_context);
+		return;
+	}
+
+	g_free(wp_context->wispr_username);
+	wp_context->wispr_username = g_strdup(username);
+
+	g_free(wp_context->wispr_password);
+	wp_context->wispr_password = g_strdup(password);
+
+	wp_context->request_id = g_web_request_post(wp_context->web,
+					wp_context->wispr_msg.login_url,
+					"application/x-www-form-urlencoded",
+					wispr_input, wispr_portal_web_result,
+					wp_context);
+
+	connman_wispr_message_init(&wp_context->wispr_msg);
+}
+
+static bool wispr_manage_message(GWebResult *result,
+			struct connman_wispr_portal_context *wp_context)
+{
+	DBG("Message type: %s (%d)",
+		message_type_to_string(wp_context->wispr_msg.message_type),
+					wp_context->wispr_msg.message_type);
+	DBG("Response code: %s (%d)",
+		response_code_to_string(wp_context->wispr_msg.response_code),
+					wp_context->wispr_msg.response_code);
+
+	if (wp_context->wispr_msg.access_procedure)
+		DBG("Access procedure: %s",
+			wp_context->wispr_msg.access_procedure);
+	if (wp_context->wispr_msg.access_location)
+		DBG("Access location: %s",
+			wp_context->wispr_msg.access_location);
+	if (wp_context->wispr_msg.location_name)
+		DBG("Location name: %s",
+			wp_context->wispr_msg.location_name);
+	if (wp_context->wispr_msg.login_url)
+		DBG("Login URL: %s", wp_context->wispr_msg.login_url);
+	if (wp_context->wispr_msg.abort_login_url)
+		DBG("Abort login URL: %s",
+			wp_context->wispr_msg.abort_login_url);
+	if (wp_context->wispr_msg.logoff_url)
+		DBG("Logoff URL: %s", wp_context->wispr_msg.logoff_url);
+
+	switch (wp_context->wispr_msg.message_type) {
+	case 100:
+		DBG("Login required");
+
+		wp_context->wispr_result = CONNMAN_WISPR_RESULT_LOGIN;
+
+		if (__connman_agent_request_login_input(wp_context->service,
+					wispr_portal_request_wispr_login,
+					wp_context) != -EINPROGRESS)
+			wispr_portal_error(wp_context);
+		else
+			return true;
+
+		break;
+	case 120: /* Falling down */
+	case 140:
+		if (wp_context->wispr_msg.response_code == 50) {
+			wp_context->wispr_result = CONNMAN_WISPR_RESULT_ONLINE;
+
+			g_free(wp_context->wispr_username);
+			wp_context->wispr_username = NULL;
+
+			g_free(wp_context->wispr_password);
+			wp_context->wispr_password = NULL;
+
+			g_free(wp_context->wispr_formdata);
+			wp_context->wispr_formdata = NULL;
+
+			wispr_portal_request_portal(wp_context);
+
+			return true;
+		} else
+			wispr_portal_error(wp_context);
+
+		break;
+	default:
+		break;
+	}
+
+	return false;
+}
+
+static bool wispr_portal_web_result(GWebResult *result, gpointer user_data)
+{
+	struct connman_wispr_portal_context *wp_context = user_data;
+	const char *redirect = NULL;
+	const guint8 *chunk = NULL;
+	const char *str = NULL;
+	guint16 status;
+	gsize length;
+
+	DBG("");
+
+	if (wp_context->wispr_result != CONNMAN_WISPR_RESULT_ONLINE) {
+		g_web_result_get_chunk(result, &chunk, &length);
+
+		if (length > 0) {
+			g_web_parser_feed_data(wp_context->wispr_parser,
+								chunk, length);
+			return true;
+		}
+
+		g_web_parser_end_data(wp_context->wispr_parser);
+
+		if (wp_context->wispr_msg.message_type >= 0) {
+			if (wispr_manage_message(result, wp_context))
+				goto done;
+		}
+	}
+
+	status = g_web_result_get_status(result);
+
+	DBG("status: %03u", status);
+
+	switch (status) {
+	case 000:
+		__connman_agent_request_browser(wp_context->service,
+				wispr_portal_browser_reply_cb,
+				wp_context->status_url, wp_context);
+		break;
+	case 200:
+		if (wp_context->wispr_msg.message_type >= 0)
+			break;
+
+		if (g_web_result_get_header(result, "X-ConnMan-Status",
+						&str)) {
+			portal_manage_status(result, wp_context);
+			return false;
+		} else
+			__connman_agent_request_browser(wp_context->service,
+					wispr_portal_browser_reply_cb,
+					wp_context->redirect_url, wp_context);
+
+		break;
+	case 302:
+		if (!g_web_supports_tls() ||
+			!g_web_result_get_header(result, "Location",
+							&redirect)) {
+
+			__connman_agent_request_browser(wp_context->service,
+					wispr_portal_browser_reply_cb,
+					wp_context->status_url, wp_context);
+			break;
+		}
+
+		DBG("Redirect URL: %s", redirect);
+
+		wp_context->redirect_url = g_strdup(redirect);
+
+		wp_context->request_id = g_web_request_get(wp_context->web,
+				redirect, wispr_portal_web_result,
+				wispr_route_request, wp_context);
+
+		goto done;
+	case 400:
+	case 404:
+		if (__connman_service_online_check_failed(wp_context->service,
+						wp_context->type) == 0) {
+			wispr_portal_error(wp_context);
+			free_connman_wispr_portal_context(wp_context);
+			return false;
+		}
+
+		break;
+	case 505:
+		__connman_agent_request_browser(wp_context->service,
+				wispr_portal_browser_reply_cb,
+				wp_context->status_url, wp_context);
+		break;
+	default:
+		break;
+	}
+
+	free_wispr_routes(wp_context);
+	wp_context->request_id = 0;
+done:
+	wp_context->wispr_msg.message_type = -1;
+	return false;
+}
+
+static void proxy_callback(const char *proxy, void *user_data)
+{
+	struct connman_wispr_portal_context *wp_context = user_data;
+
+	DBG("proxy %s", proxy);
+
+	if (!wp_context)
+		return;
+
+	wp_context->token = 0;
+
+	if (proxy && g_strcmp0(proxy, "DIRECT") != 0) {
+		if (g_str_has_prefix(proxy, "PROXY")) {
+			proxy += 5;
+			for (; *proxy == ' ' && *proxy != '\0'; proxy++);
+		}
+		g_web_set_proxy(wp_context->web, proxy);
+	}
+
+	g_web_set_accept(wp_context->web, NULL);
+	g_web_set_user_agent(wp_context->web, "ConnMan/%s wispr", VERSION);
+	g_web_set_close_connection(wp_context->web, TRUE);
+
+	connman_wispr_message_init(&wp_context->wispr_msg);
+
+	wp_context->wispr_parser = g_web_parser_new(
+					"<WISPAccessGatewayParam",
+					"WISPAccessGatewayParam>",
+					xml_wispr_parser_callback, wp_context);
+
+	wispr_portal_request_portal(wp_context);
+}
+
+static gboolean no_proxy_callback(gpointer user_data)
+{
+	struct connman_wispr_portal_context *wp_context = user_data;
+
+	wp_context->timeout = 0;
+
+	proxy_callback("DIRECT", wp_context);
+
+	return FALSE;
+}
+
+static int wispr_portal_detect(struct connman_wispr_portal_context *wp_context)
+{
+	enum connman_service_proxy_method proxy_method;
+	enum connman_service_type service_type;
+	char *interface = NULL;
+	char **nameservers = NULL;
+	int if_index;
+	int err = 0;
+	int i;
+
+	DBG("wispr/portal context %p", wp_context);
+	DBG("service %p", wp_context->service);
+
+	service_type = connman_service_get_type(wp_context->service);
+
+	switch (service_type) {
+	case CONNMAN_SERVICE_TYPE_ETHERNET:
+	case CONNMAN_SERVICE_TYPE_WIFI:
+	case CONNMAN_SERVICE_TYPE_BLUETOOTH:
+	case CONNMAN_SERVICE_TYPE_CELLULAR:
+	case CONNMAN_SERVICE_TYPE_GADGET:
+		break;
+	case CONNMAN_SERVICE_TYPE_UNKNOWN:
+	case CONNMAN_SERVICE_TYPE_SYSTEM:
+	case CONNMAN_SERVICE_TYPE_GPS:
+	case CONNMAN_SERVICE_TYPE_VPN:
+	case CONNMAN_SERVICE_TYPE_P2P:
+	case CONNMAN_SERVICE_TYPE_LOWPAN:
+		return -EOPNOTSUPP;
+	}
+
+	interface = connman_service_get_interface(wp_context->service);
+	if (!interface)
+		return -EINVAL;
+
+	DBG("interface %s", interface);
+
+	if_index = connman_inet_ifindex(interface);
+	if (if_index < 0) {
+		DBG("Could not get ifindex");
+		err = -EINVAL;
+		goto done;
+	}
+
+	nameservers = connman_service_get_nameservers(wp_context->service);
+	if (!nameservers) {
+		DBG("Could not get nameservers");
+		err = -EINVAL;
+		goto done;
+	}
+
+	wp_context->web = g_web_new(if_index);
+	if (!wp_context->web) {
+		DBG("Could not set up GWeb");
+		err = -ENOMEM;
+		goto done;
+	}
+
+	if (getenv("CONNMAN_WEB_DEBUG"))
+		g_web_set_debug(wp_context->web, web_debug, "WEB");
+
+	if (wp_context->type == CONNMAN_IPCONFIG_TYPE_IPV4) {
+		g_web_set_address_family(wp_context->web, AF_INET);
+		wp_context->status_url = STATUS_URL_IPV4;
+	} else {
+		g_web_set_address_family(wp_context->web, AF_INET6);
+		wp_context->status_url = STATUS_URL_IPV6;
+	}
+
+	for (i = 0; nameservers[i]; i++)
+		g_web_add_nameserver(wp_context->web, nameservers[i]);
+
+	proxy_method = connman_service_get_proxy_method(wp_context->service);
+
+	if (proxy_method != CONNMAN_SERVICE_PROXY_METHOD_DIRECT) {
+		wp_context->token = connman_proxy_lookup(interface,
+						wp_context->status_url,
+						wp_context->service,
+						proxy_callback, wp_context);
+
+		if (wp_context->token == 0) {
+			err = -EINVAL;
+			free_connman_wispr_portal_context(wp_context);
+		}
+	} else if (wp_context->timeout == 0) {
+		wp_context->timeout =
+			g_timeout_add_seconds(0, no_proxy_callback, wp_context);
+	}
+
+done:
+	g_strfreev(nameservers);
+
+	g_free(interface);
+	return err;
+}
+
+int __connman_wispr_start(struct connman_service *service,
+					enum connman_ipconfig_type type)
+{
+	struct connman_wispr_portal_context *wp_context = NULL;
+	struct connman_wispr_portal *wispr_portal = NULL;
+	int index;
+
+	DBG("service %p", service);
+
+	if (!wispr_portal_list)
+		return -EINVAL;
+
+	index = __connman_service_get_index(service);
+	if (index < 0)
+		return -EINVAL;
+
+	wispr_portal = g_hash_table_lookup(wispr_portal_list,
+					GINT_TO_POINTER(index));
+	if (!wispr_portal) {
+		wispr_portal = g_try_new0(struct connman_wispr_portal, 1);
+		if (!wispr_portal)
+			return -ENOMEM;
+
+		g_hash_table_replace(wispr_portal_list,
+					GINT_TO_POINTER(index), wispr_portal);
+	}
+
+	if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
+		wp_context = wispr_portal->ipv4_context;
+	else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
+		wp_context = wispr_portal->ipv6_context;
+	else
+		return -EINVAL;
+
+	/* If there is already an existing context, we wipe it */
+	if (wp_context)
+		free_connman_wispr_portal_context(wp_context);
+
+	wp_context = create_wispr_portal_context();
+	if (!wp_context)
+		return -ENOMEM;
+
+	wp_context->service = service;
+	wp_context->type = type;
+	wp_context->wispr_portal = wispr_portal;
+
+	if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
+		wispr_portal->ipv4_context = wp_context;
+	else
+		wispr_portal->ipv6_context = wp_context;
+
+	return wispr_portal_detect(wp_context);
+}
+
+void __connman_wispr_stop(struct connman_service *service)
+{
+	int index;
+
+	DBG("service %p", service);
+
+	if (!wispr_portal_list)
+		return;
+
+	index = __connman_service_get_index(service);
+	if (index < 0)
+		return;
+
+	g_hash_table_remove(wispr_portal_list, GINT_TO_POINTER(index));
+}
+
+int __connman_wispr_init(void)
+{
+	DBG("");
+
+	wispr_portal_list = g_hash_table_new_full(g_direct_hash,
+						g_direct_equal, NULL,
+						free_connman_wispr_portal);
+
+	return 0;
+}
+
+void __connman_wispr_cleanup(void)
+{
+	DBG("");
+
+	g_hash_table_destroy(wispr_portal_list);
+	wispr_portal_list = NULL;
+}
diff --git a/connman/src/wpad.c b/connman/src/wpad.c
new file mode 100644
index 0000000..d40959b
--- /dev/null
+++ b/connman/src/wpad.c
@@ -0,0 +1,217 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2012  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 <string.h>
+
+#include <gweb/gresolv.h>
+
+#include "connman.h"
+
+struct connman_wpad {
+	struct connman_service *service;
+	GResolv *resolv;
+	char *hostname;
+	char **addrlist;
+};
+
+static GHashTable *wpad_list = NULL;
+
+static void resolv_debug(const char *str, void *data)
+{
+	connman_info("%s: %s\n", (const char *) data, str);
+}
+
+static void free_wpad(gpointer data)
+{
+        struct connman_wpad *wpad = data;
+
+	g_resolv_unref(wpad->resolv);
+
+	g_strfreev(wpad->addrlist);
+	g_free(wpad->hostname);
+	g_free(wpad);
+}
+
+static void download_pac(struct connman_wpad *wpad, const char *target)
+{
+}
+
+static void wpad_result(GResolvResultStatus status,
+					char **results, gpointer user_data)
+{
+	struct connman_wpad *wpad = user_data;
+	const char *ptr;
+	char *hostname;
+
+	DBG("status %d", status);
+
+	if (status == G_RESOLV_RESULT_STATUS_SUCCESS) {
+		char *url;
+
+		if (!results || g_strv_length(results) == 0)
+			goto failed;
+
+		url = g_strdup_printf("http://%s/wpad.dat", wpad->hostname);
+
+		__connman_service_set_proxy_autoconfig(wpad->service, url);
+
+		wpad->addrlist = g_strdupv(results);
+		if (wpad->addrlist)
+			download_pac(wpad, "wpad.dat");
+
+		g_free(url);
+
+		__connman_wispr_start(wpad->service,
+					CONNMAN_IPCONFIG_TYPE_IPV4);
+
+		return;
+	}
+
+	hostname = wpad->hostname;
+
+	if (strlen(hostname) < 6)
+		goto failed;
+
+	ptr = strchr(hostname + 5, '.');
+	if (!ptr || strlen(ptr) < 2)
+		goto failed;
+
+	if (!strchr(ptr + 1, '.'))
+		goto failed;
+
+	wpad->hostname = g_strdup_printf("wpad.%s", ptr + 1);
+	g_free(hostname);
+
+	DBG("hostname %s", wpad->hostname);
+
+	g_resolv_lookup_hostname(wpad->resolv, wpad->hostname,
+							wpad_result, wpad);
+
+	return;
+
+failed:
+	connman_service_set_proxy_method(wpad->service,
+				CONNMAN_SERVICE_PROXY_METHOD_DIRECT);
+
+	__connman_wispr_start(wpad->service,
+					CONNMAN_IPCONFIG_TYPE_IPV4);
+}
+
+int __connman_wpad_start(struct connman_service *service)
+{
+	struct connman_wpad *wpad;
+	const char *domainname;
+	char **nameservers;
+	int index;
+	int i;
+
+	DBG("service %p", service);
+
+	if (!wpad_list)
+		return -EINVAL;
+
+	index = __connman_service_get_index(service);
+	if (index < 0)
+		return -EINVAL;
+
+	domainname = connman_service_get_domainname(service);
+	if (!domainname)
+		return -EINVAL;
+
+	nameservers = connman_service_get_nameservers(service);
+	if (!nameservers)
+		return -EINVAL;
+
+	wpad = g_try_new0(struct connman_wpad, 1);
+	if (!wpad) {
+		g_strfreev(nameservers);
+		return -ENOMEM;
+	}
+
+	wpad->service = service;
+	wpad->resolv = g_resolv_new(index);
+	if (!wpad->resolv) {
+		g_strfreev(nameservers);
+		g_free(wpad);
+		return -ENOMEM;
+	}
+
+	if (getenv("CONNMAN_RESOLV_DEBUG"))
+		g_resolv_set_debug(wpad->resolv, resolv_debug, "RESOLV");
+
+	for (i = 0; nameservers[i]; i++)
+		g_resolv_add_nameserver(wpad->resolv, nameservers[i], 53, 0);
+
+	g_strfreev(nameservers);
+
+	wpad->hostname = g_strdup_printf("wpad.%s", domainname);
+
+	DBG("hostname %s", wpad->hostname);
+
+	g_resolv_lookup_hostname(wpad->resolv, wpad->hostname,
+							wpad_result, wpad);
+
+	connman_service_ref(service);
+	g_hash_table_replace(wpad_list, GINT_TO_POINTER(index), wpad);
+
+	return 0;
+}
+
+void __connman_wpad_stop(struct connman_service *service)
+{
+	int index;
+
+	DBG("service %p", service);
+
+	if (!wpad_list)
+		return;
+
+	index = __connman_service_get_index(service);
+	if (index < 0)
+		return;
+
+	if (g_hash_table_remove(wpad_list, GINT_TO_POINTER(index)))
+		connman_service_unref(service);
+}
+
+int __connman_wpad_init(void)
+{
+	DBG("");
+
+	wpad_list = g_hash_table_new_full(g_direct_hash, g_direct_equal,
+							NULL, free_wpad);
+
+	return 0;
+}
+
+void __connman_wpad_cleanup(void)
+{
+	DBG("");
+
+	g_hash_table_destroy(wpad_list);
+	wpad_list = NULL;
+}
diff --git a/connman/test/backtrace b/connman/test/backtrace
new file mode 100755
index 0000000..c906f36
--- /dev/null
+++ b/connman/test/backtrace
@@ -0,0 +1,57 @@
+#!/usr/bin/python
+
+import os
+import re
+import sys
+import subprocess
+
+if (len(sys.argv) < 3):
+	print "Usage: %s [binary] [log]" % (sys.argv[0])
+	sys.exit(1)
+
+binary = sys.argv[1]
+count = 0
+frames = []
+addrs = []
+
+log_file = open(sys.argv[2], 'r')
+
+# Extract addresses
+for line in log_file:
+	matchobj = re.compile(r'\[(0x[0-9a-f]+)\]$').search(line)
+	if matchobj:
+		addrs.append(matchobj.group(1))
+
+log_file.close()
+
+# Feed into addr2line
+command = ['addr2line', '--demangle', '--functions', '--basename',
+							'-e', binary]
+command.extend(addrs)
+
+p = subprocess.Popen(command, shell=False, bufsize=0,
+		stdin=subprocess.PIPE, stdout=subprocess.PIPE, close_fds=True)
+(child_stdin, child_stdout) = (p.stdin, p.stdout)
+
+child_stdin.close()
+
+# Backtrace display
+for line in child_stdout:
+
+	if line.startswith("??"):
+		continue
+
+	line = line.strip()
+
+	frames.append(line)
+
+child_stdout.close()
+
+frame_count = len(frames);
+
+count = 0
+print "-------- backtrace --------"
+while count < frame_count:
+	print "[%d]: %s() [%s]" % (count/2, frames[count], frames[count + 1])
+	count = count + 2
+print "---------------------------"
diff --git a/connman/test/connect-provider b/connman/test/connect-provider
new file mode 100755
index 0000000..15128c8
--- /dev/null
+++ b/connman/test/connect-provider
@@ -0,0 +1,73 @@
+#!/usr/bin/python
+
+import sys
+import dbus
+
+if (len(sys.argv) < 4):
+	print "Usage: %s <type> ... " % (sys.argv[0])
+	print "  type: openconnect"
+	print "      <name> <host> <domain> <cookie> [servercert]"
+	print "  type: openvpn"
+	print "      <name> <host> <domain> [<cafile> <certfile> <keyfile>]"
+	print "  type: pptp"
+	print "      <name> <host> <domain> <user> <password>"
+	print "  type: l2tp"
+	print "      <name> <host> <domain> <user> <password>"
+	sys.exit(1)
+
+bus = dbus.SystemBus()
+
+manager = dbus.Interface(bus.get_object("net.connman", "/"),
+					"net.connman.Manager")
+
+print "Attempting to connect service %s" % (sys.argv[3])
+
+if sys.argv[1] == "openconnect":
+	if (len(sys.argv) > 6):
+		path = manager.ConnectProvider(({ "Type": "openconnect",
+					"Name": sys.argv[2],
+					"Host": sys.argv[3],
+					"VPN.Domain": sys.argv[4],
+					"OpenConnect.Cookie": sys.argv[5],
+					"OpenConnect.ServerCert": sys.argv[6]}))
+	else:
+		path = manager.ConnectProvider(({ "Type": "openconnect",
+					"Name": sys.argv[2],
+					"Host": sys.argv[3],
+					"VPN.Domain": sys.argv[4],
+					"OpenConnect.Cookie": sys.argv[5]}))
+elif sys.argv[1] == "openvpn":
+	if (len(sys.argv) < 6):
+		path = manager.ConnectProvider(({ "Type": "openvpn",
+						  "Name": sys.argv[2],
+						  "Host": sys.argv[3],
+						  "VPN.Domain": sys.argv[4] }))
+	else:
+		path = manager.ConnectProvider(({ "Type": "openvpn",
+						  "Name": sys.argv[2],
+						  "Host": sys.argv[3],
+						  "VPN.Domain": sys.argv[4],
+						  "OpenVPN.CACert": sys.argv[5],
+						  "OpenVPN.Cert": sys.argv[6],
+						  "OpenVPN.Key": sys.argv[7]}))
+
+elif sys.argv[1] == "pptp":
+	path = manager.ConnectProvider(({ "Type": "pptp",
+					"Name": sys.argv[2],
+					"Host": sys.argv[3],
+					"VPN.Domain": sys.argv[4],
+					"PPTP.User": sys.argv[5],
+					"PPTP.Password": sys.argv[6]}))
+elif sys.argv[1] == "l2tp":
+	path = manager.ConnectProvider(({ "Type": "l2tp",
+					"Name": sys.argv[2],
+					"Host": sys.argv[3],
+					"VPN.Domain": sys.argv[4],
+					"L2TP.User": sys.argv[5],
+					"L2TP.Password": sys.argv[6]}))
+
+else:
+	print "Unknown VPN type"
+	sys.exit(1)
+
+print "VPN service path is %s" %(path)
diff --git a/connman/test/disable-tethering b/connman/test/disable-tethering
new file mode 100755
index 0000000..a3d5908
--- /dev/null
+++ b/connman/test/disable-tethering
@@ -0,0 +1,40 @@
+#!/usr/bin/python
+
+import sys
+import dbus
+
+if (len(sys.argv) != 2):
+	print "Usage: %s type" % (sys.argv[0])
+	sys.exit(1)
+
+bus = dbus.SystemBus()
+
+manager = dbus.Interface(bus.get_object('net.connman', "/"),
+					'net.connman.Manager')
+
+def technology_disable_tethering(path, tech_type):
+	tech = dbus.Interface(bus.get_object("net.connman", path),
+						"net.connman.Technology")
+
+	properties = tech.GetProperties()
+
+	for key in properties.keys():
+		if key in ["Type"]:
+			if properties[key] == tech_type:
+				print "Disabling %s tethering" % tech_type
+				tech.SetProperty("Tethering", dbus.Boolean(0))
+
+				return tech_type
+			else:
+				return None
+
+technologies = manager.GetTechnologies()
+tech = None
+
+for path,_ in technologies:
+	tech = technology_disable_tethering(path, sys.argv[1])
+	if tech != None:
+		break;
+
+if tech == None:
+	print "Failed to disable %s tethering" % (sys.argv[1])
diff --git a/connman/test/enable-tethering b/connman/test/enable-tethering
new file mode 100755
index 0000000..cbcd4e7
--- /dev/null
+++ b/connman/test/enable-tethering
@@ -0,0 +1,54 @@
+#!/usr/bin/python
+
+import sys
+import dbus
+
+if (len(sys.argv) >= 3 and len(sys.argv) != 4 and sys.argv[1] == "wifi"):
+	print "Usage: %s wifi [SSID] [passphrase]" % (sys.argv[0])
+	sys.exit(1)
+elif (len(sys.argv) < 2):
+	print "Usage: %s type" % (sys.argv[0])
+	sys.exit(1)
+
+bus = dbus.SystemBus()
+
+manager = dbus.Interface(bus.get_object('net.connman', "/"),
+					'net.connman.Manager')
+
+def technology_enable_tethering(path, tech_type, ssid, psk):
+	tech = dbus.Interface(bus.get_object("net.connman", path),
+						"net.connman.Technology")
+
+	properties = tech.GetProperties()
+
+	for key in properties.keys():
+		if key in ["Type"]:
+			if properties[key] == tech_type:
+				if len(ssid) > 0:
+					tech.SetProperty("TetheringIdentifier",
+								ssid)
+				if len(psk) > 0:
+					tech.SetProperty("TetheringPassphrase",
+								psk)
+				print "Enabling %s tethering" % tech_type
+				tech.SetProperty("Tethering", dbus.Boolean(1))
+
+				return tech_type
+			else:
+				return None
+
+technologies = manager.GetTechnologies()
+tech = None
+
+for path,_ in technologies:
+	if (len(sys.argv) == 4):
+		tech = technology_enable_tethering(path,
+					sys.argv[1], sys.argv[2], sys.argv[3])
+	else:
+		tech = technology_enable_tethering(path, sys.argv[1], "", "")
+
+	if tech != None:
+		break;
+
+if tech == None:
+	print "Failed to enable %s tethering" % (sys.argv[1])
diff --git a/connman/test/get-global-timeservers b/connman/test/get-global-timeservers
new file mode 100755
index 0000000..adcf175
--- /dev/null
+++ b/connman/test/get-global-timeservers
@@ -0,0 +1,12 @@
+#!/usr/bin/python
+
+import dbus
+
+bus = dbus.SystemBus()
+
+clock = dbus.Interface(bus.get_object('net.connman', '/'),
+					'net.connman.Clock')
+
+properties = clock.GetProperties()
+
+print "Timeserver is %s" % (properties["Timeservers"])
diff --git a/connman/test/get-proxy-autoconfig b/connman/test/get-proxy-autoconfig
new file mode 100755
index 0000000..6709a9e
--- /dev/null
+++ b/connman/test/get-proxy-autoconfig
@@ -0,0 +1,37 @@
+#!/usr/bin/python
+
+import dbus
+import urllib
+
+def get_pac(url):
+	conn = urllib.urlopen(url, proxies={})
+	data = conn.read()
+	print data
+	conn.close()
+
+bus = dbus.SystemBus()
+
+manager = dbus.Interface(bus.get_object('net.connman', '/'),
+					'net.connman.Manager')
+
+services = manager.GetServices()
+
+for entry in services:
+	path = entry[0]
+	properties = entry[1]
+
+	proxy = properties["Proxy"]
+
+	if "Method" in proxy:
+		print "[ %s ]" % (path)
+
+		method = proxy["Method"]
+		print "Method = %s" % (method)
+
+		if method in ["auto"]:
+			url = proxy["URL"]
+			print "URL = %s" % (url)
+			print
+			get_pac(url)
+		else:
+			print
diff --git a/connman/test/get-services b/connman/test/get-services
new file mode 100755
index 0000000..0956480
--- /dev/null
+++ b/connman/test/get-services
@@ -0,0 +1,58 @@
+#!/usr/bin/python
+
+import dbus
+
+def extract_values(values):
+	val = "{"
+	for key in values.keys():
+		val += " " + key + "="
+		if key in ["Servers", "Excludes"]:
+			val += extract_list(values[key])
+		else:
+			val += str(values[key])
+	val += " }"
+	return val
+
+def extract_list(list):
+	val = "["
+	for i in list:
+		val += " " + str(i)
+	val += " ]"
+	return val
+
+bus = dbus.SystemBus()
+
+manager = dbus.Interface(bus.get_object('net.connman', '/'),
+					'net.connman.Manager')
+
+services = manager.GetServices()
+
+for entry in services:
+	path = entry[0]
+	properties = entry[1]
+
+	print "[ %s ]" % (path)
+
+	for key in properties.keys():
+		if key in ["IPv4", "IPv4.Configuration",
+					"IPv6", "IPv6.Configuration",
+					"Proxy", "Proxy.Configuration",
+						"Ethernet", "Provider"]:
+			val = extract_values(properties[key])
+		elif key in ["Nameservers", "Nameservers.Configuration",
+					"Domains", "Domains.Configuration",
+						"Security"]:
+			val = extract_list(properties[key])
+		elif key in ["Favorite", "Immutable", "AutoConnect",
+				"PassphraseRequired"]:
+			if properties[key] == dbus.Boolean(1):
+				val = "true"
+			else:
+				val = "false"
+		elif key in ["Strength"]:
+			val = int(properties[key])
+		else:
+			val = str(properties[key])
+		print "    %s = %s" % (key, val)
+
+	print
diff --git a/connman/test/get-state b/connman/test/get-state
new file mode 100755
index 0000000..75d5a16
--- /dev/null
+++ b/connman/test/get-state
@@ -0,0 +1,12 @@
+#!/usr/bin/python
+
+import dbus
+
+bus = dbus.SystemBus()
+
+manager = dbus.Interface(bus.get_object('net.connman', "/"),
+					'net.connman.Manager')
+
+properties = manager.GetProperties()
+
+print "System is %s" % (properties["State"])
diff --git a/connman/test/list-services b/connman/test/list-services
new file mode 100755
index 0000000..6be4945
--- /dev/null
+++ b/connman/test/list-services
@@ -0,0 +1,60 @@
+#!/usr/bin/python
+
+import dbus
+
+def extract_values(values):
+	val = "{"
+	for key in values.keys():
+		val += " " + key + "="
+		if key in ["PrefixLength"]:
+			val += "%s" % (int(values[key]))
+		else:
+			if key in ["Servers", "Excludes"]:
+				val += extract_list(values[key])
+			else:
+				val += str(values[key])
+	val += " }"
+	return val
+
+def extract_list(list):
+	val = "["
+	for i in list:
+		val += " " + str(i)
+	val += " ]"
+	return val
+
+bus = dbus.SystemBus()
+
+manager = dbus.Interface(bus.get_object("net.connman", "/"),
+					"net.connman.Manager")
+
+for path, properties in manager.GetServices():
+	service = dbus.Interface(bus.get_object("net.connman", path),
+						"net.connman.Service")
+	identifier = path[path.rfind("/") + 1:]
+	print "[ %s ]" % (identifier)
+
+	for key in properties.keys():
+		if key in ["IPv4", "IPv4.Configuration",
+				"IPv6", "IPv6.Configuration",
+					"Proxy", "Proxy.Configuration",
+						"Ethernet", "Provider"]:
+			val = extract_values(properties[key])
+		elif key in ["Nameservers", "Nameservers.Configuration",
+			     "Domains", "Domains.Configuration",
+			     "Timeservers", "Timeservers.Configuration",
+			     "Security"]:
+			val = extract_list(properties[key])
+		elif key in ["Favorite", "Immutable", "AutoConnect",
+					"LoginRequired", "PassphraseRequired"]:
+			if properties[key] == dbus.Boolean(1):
+				val = "true"
+			else:
+				val = "false"
+		elif key in ["Strength"]:
+			val = int(properties[key])
+		else:
+			val = properties[key]
+		print "    %s = %s" % (key, val)
+
+	print
diff --git a/connman/test/monitor-connman b/connman/test/monitor-connman
new file mode 100755
index 0000000..1b3b84c
--- /dev/null
+++ b/connman/test/monitor-connman
@@ -0,0 +1,87 @@
+#!/usr/bin/python
+
+import gobject
+
+import dbus
+import dbus.mainloop.glib
+
+from dbus.lowlevel import MethodCallMessage, HANDLER_RESULT_NOT_YET_HANDLED
+
+def extract_list(list):
+	val = "["
+	for i in list:
+		if type(i).__name__ == 'Dictionary':
+			val = extract_values(i)
+		else:
+			val += " " + str(i)
+	val += " ]"
+	return val
+
+def extract_values(values):
+	val = "{"
+	for key in values.keys():
+		val += " " + key + "="
+		if key in ["PrefixLength"]:
+			val += "%s" % (int(values[key]))
+		elif key in ["IPv4", "IPv6", "Ethernet" ]:
+			val += extract_values(values[key])
+		elif key in [ "AllowedBearers" ]:
+			val += extract_list(values[key])
+		else:
+			if key in ["Servers", "Excludes"]:
+				val += extract_list(values[key])
+			else:
+				val += str(values[key])
+	val += " }"
+	return val
+
+def extract(name, value):
+	val = None
+
+	if name in ["Strength", "Priority"]:
+		val = int(value)
+	elif name in ["IPv4", "IPv6", "Ethernet", "Proxy" ]:
+		val = extract_values(value)
+	elif name in ["Services", "Technologies",
+			"Nameservers", "Domains", "Timeservers"]:
+		val = extract_list(value)
+	else:
+		val = str(value)
+
+	return val
+
+def property_changed(name, value, path, interface):
+	iface = interface[interface.rfind(".") + 1:]
+	val = extract(name, value)
+
+	print "{%s} [%s] %s = %s" % (iface, path, name, val)
+
+def message_filter(connection, message):
+	if not isinstance(message, MethodCallMessage):
+		return HANDLER_RESULT_NOT_YET_HANDLED
+
+	interface = message.get_interface()
+	path = message.get_path()
+	name = message.get_member()
+	args = message.get_args_list()
+
+	property_changed(name, args, path, interface)
+
+if __name__ == '__main__':
+	dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
+
+	bus = dbus.SystemBus()
+
+	bus.add_signal_receiver(property_changed,
+					bus_name="net.connman",
+					signal_name = "PropertyChanged",
+						path_keyword="path",
+						interface_keyword="interface")
+
+	bus.add_match_string("member=Change,interface=net.connman.Session")
+	bus.add_match_string("member=Update,interface=net.connman.Notification")
+	bus.add_message_filter(message_filter)
+
+	mainloop = gobject.MainLoop()
+
+	mainloop.run()
diff --git a/connman/test/monitor-services b/connman/test/monitor-services
new file mode 100755
index 0000000..9476bf8
--- /dev/null
+++ b/connman/test/monitor-services
@@ -0,0 +1,106 @@
+#!/usr/bin/python
+
+import gobject
+
+import dbus
+import dbus.mainloop.glib
+
+def extract_values(values):
+	val = "{"
+	for key in values.keys():
+		val += " " + key + "="
+		if key in ["Servers", "Excludes"]:
+			val += extract_list(values[key])
+		else:
+			val += str(values[key])
+	val += " }"
+	return val
+
+def extract_list(list):
+	val = "["
+	for i in list:
+		val += " " + str(i)
+	val += " ]"
+	return val
+
+def property_changed(name, value, path):
+	service = path[path.rfind("/") + 1:]
+	if name in ["Services"]:
+		val = "["
+		for i in value:
+			val = val + " " + i[i.rfind("/") + 1:]
+		val = val + " ]"
+	elif name in ["IPv4", "IPv4.Configuration",
+			"IPv6", "IPv6.Configuration",
+			"Proxy", "Proxy.Configuration", "Ethernet", "Provider"]:
+		val = extract_values(value)
+	elif name in ["Nameservers", "Nameservers.Configuration",
+			"Domains", "Domains.Configuration",
+			"Timeservers", "Timeservers.Configuration", "Security"]:
+		val = extract_list(value)
+	elif name in ["Strength", "Priority"]:
+		val = int(value)
+	else:
+		val = str(value)
+	print "[%s] %s = %s" % (service, name, val)
+
+def services_changed(services, removed):
+	for i in services:
+		service = i[0][i[0].rfind("/") + 1:]
+		print "[%s] changed" % (service)
+		for n in i[1].keys():
+			property_changed(n, i[1][n], i[0])
+	for i in removed:
+		service = i[i.rfind("/") + 1:]
+		print "[%s] removed" % (service)
+
+def technology_added(path, properties):
+	technology = path[path.rfind("/") + 1:]
+	print "[%s] added" % (technology)
+	for n in properties.keys():
+		property_changed(n, properties[n], technology)
+
+def technology_removed(path):
+	technology = path[path.rfind("/") + 1:]
+	print "[%s] removed" % (technology)
+
+if __name__ == '__main__':
+	dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
+
+	bus = dbus.SystemBus()
+
+	bus.add_signal_receiver(property_changed,
+				bus_name="net.connman",
+				dbus_interface="net.connman.Manager",
+				signal_name="PropertyChanged",
+				path_keyword="path")
+
+	bus.add_signal_receiver(services_changed,
+				bus_name="net.connman",
+				dbus_interface="net.connman.Manager",
+				signal_name="ServicesChanged")
+
+	bus.add_signal_receiver(property_changed,
+				bus_name="net.connman",
+				dbus_interface="net.connman.Service",
+				signal_name="PropertyChanged",
+				path_keyword="path")
+
+	bus.add_signal_receiver(technology_added,
+				bus_name="net.connman",
+				dbus_interface="net.connman.Manager",
+				signal_name="TechnologyAdded")
+
+	bus.add_signal_receiver(technology_removed,
+				bus_name="net.connman",
+				dbus_interface="net.connman.Manager",
+				signal_name="TechnologyRemoved")
+
+	bus.add_signal_receiver(property_changed,
+				bus_name="net.connman",
+				dbus_interface="net.connman.Technology",
+				signal_name="PropertyChanged",
+				path_keyword="path")
+
+	mainloop = gobject.MainLoop()
+	mainloop.run()
diff --git a/connman/test/monitor-vpn b/connman/test/monitor-vpn
new file mode 100755
index 0000000..2b63687
--- /dev/null
+++ b/connman/test/monitor-vpn
@@ -0,0 +1,81 @@
+#!/usr/bin/python
+
+import gobject
+
+import dbus
+import dbus.mainloop.glib
+
+from dbus.lowlevel import MethodCallMessage, HANDLER_RESULT_NOT_YET_HANDLED
+
+def extract_list(list):
+	val = "["
+	for i in list:
+		if type(i).__name__ == 'Dictionary':
+			val += extract_values(i)
+		elif type(i).__name__ == 'Struct':
+			val += extract_list(i)
+		else:
+			val += " " + str(i)
+	val += "]"
+	return val
+
+def extract_values(values):
+	val = "{"
+	for key in values.keys():
+		val += " " + key + "="
+		if key in ["ProtocolFamily"]:
+			val += "%s" % (int(values[key]))
+		elif key in ["IPv4", "IPv6"]:
+			val += extract_values(values[key])
+		else:
+			val += str(values[key])
+	val += " }"
+	return val
+
+def extract(name, value):
+	val = None
+
+	if name in ["Index"]:
+		val = int(value)
+	elif name in ["IPv4", "IPv6" ]:
+		val = extract_values(value)
+	elif name in ["UserRoutes", "ServerRoutes", "Nameservers"]:
+		val = extract_list(value)
+	else:
+		val = str(value)
+
+	return val
+
+def property_changed(name, value, path, interface):
+	iface = interface[interface.rfind(".") + 1:]
+	val = extract(name, value)
+
+	print "{%s} [%s] %s = %s" % (iface, path, name, val)
+
+def message_filter(connection, message):
+	if not isinstance(message, MethodCallMessage):
+		return HANDLER_RESULT_NOT_YET_HANDLED
+
+	interface = message.get_interface()
+	path = message.get_path()
+	name = message.get_member()
+	args = message.get_args_list()
+
+	property_changed(name, args, path, interface)
+
+if __name__ == '__main__':
+	dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
+
+	bus = dbus.SystemBus()
+
+	bus.add_signal_receiver(property_changed,
+					bus_name="net.connman.vpn",
+					signal_name = "PropertyChanged",
+						path_keyword="path",
+						interface_keyword="interface")
+
+	bus.add_message_filter(message_filter)
+
+	mainloop = gobject.MainLoop()
+
+	mainloop.run()
diff --git a/connman/test/p2p-on-supplicant b/connman/test/p2p-on-supplicant
new file mode 100755
index 0000000..8cc76e8
--- /dev/null
+++ b/connman/test/p2p-on-supplicant
@@ -0,0 +1,649 @@
+#!/usr/bin/python
+
+from os import O_NONBLOCK
+from sys import stdin, stdout, exit, version_info, argv
+from fcntl import fcntl, F_GETFL, F_SETFL
+import glib
+import dbus
+import dbus.mainloop.glib
+import gobject
+import argparse
+
+WPA_NAME='fi.w1.wpa_supplicant1'
+WPA_INTF='fi.w1.wpa_supplicant1'
+WPA_PATH='/fi/w1/wpa_supplicant1'
+WPA_IF_INTF = WPA_INTF + '.Interface'
+WPA_P2P_INTF = WPA_IF_INTF + '.P2PDevice'
+WPA_GROUP_INTF = WPA_INTF + '.Group'
+WPA_PEER_INTF = WPA_INTF + '.Peer'
+DBUS_PROPERTIES_INTF = 'org.freedesktop.DBus.Properties'
+
+P2P_GROUP_CAPAB_GROUP_OWNER = 1 << 0
+
+class ArgFields:
+    for field in ('help', 'metavar'):
+        exec('{}="{}"'.format(field, field))
+
+class InputLine:
+    def __init__(self, handler):
+        self.line = ''
+        self.handler = handler
+
+        flags = fcntl(stdin.fileno(), F_GETFL)
+        flags |= O_NONBLOCK
+        fcntl(stdin.fileno(), F_SETFL, flags)
+        glib.io_add_watch(stdin, glib.IO_IN, self.input_cb)
+
+        self.prompt()
+
+    def prompt(self):
+        self.line = ''
+        print '> ',
+        stdout.flush()
+
+    def input_cb(self, fd, event):
+        if event != glib.IO_IN:
+            return
+
+        self.line += fd.read();
+        for line in self.line.split('\n'):
+            line = line.strip()
+            if len(line) == 0:
+                break
+
+            self.handler(line.strip())
+
+        self.prompt()
+
+        return True
+
+def error_print(ex):
+    print 'Command Error: %s' % ex
+
+def checkarg(nb_args = 0, min_args = False):
+    def under(function):
+        def wrapper(*args, **kwargs):
+            resuls = True
+
+            if min_args:
+                result = len(args[1]) < nb_args
+            else:
+                result = len(args[1]) != nb_args
+
+            if result:
+                raise Exception('Command %s takes %s arguments' %
+                                    (function.__name__, nb_args))
+            return function(*args, **kwargs)
+        return wrapper
+    return under
+
+def print_dict(d):
+    for k in d:
+        try:
+            if type(d[k]) is dbus.Byte:
+                print 'Key %s --> 0x%x' % (k, d[k])
+            else:
+                print 'Key %s --> %s' % (k, d[k])
+        except:
+            print "Error: Key %s content cannot be printed" % k
+            pass
+
+def print_tuple(t):
+    for e in t:
+        if type(e) is dbus.Dictionary:
+            print_dict(e)
+        else:
+            print 'Element: %s' % e
+
+class Wpa_s:
+    def __init__(self, bus, iface_name, command):
+        self.wpa = dbus.Interface(bus.get_object(WPA_NAME, WPA_PATH), WPA_INTF)
+        bus.add_signal_receiver(self.__wpa_property_changed, path=WPA_PATH,
+                                member_keyword='signal')
+        bus.add_signal_receiver(self.__InterfaceAdded, path=WPA_PATH,
+                                signal_name='InterfaceAdded')
+        bus.add_signal_receiver(self.__InterfaceRemoved, path=WPA_PATH,
+                                signal_name='InterfaceRemoved')
+        self.__reset()
+
+        self.bus = bus
+
+        self.debug = False
+
+        self.line_in = InputLine(self.__command)
+
+        if iface_name:
+            try:
+                self.create_if([iface_name])
+            except:
+                print "Error creating interface: %s" % iface_name
+
+        if len(command.strip(' ')):
+            self.__command(command)
+
+    def help(self, args):
+        list = self.command_list.keys()
+        list.sort()
+        for key in list:
+            help = ''
+            if (self.command_list[key].has_key(ArgFields.help)):
+                help = self.command_list[key][ArgFields.help]
+
+            print "%s\t%s" % (key.rjust(25), help.ljust(50))
+
+    def __command(self, cmd_line):
+        cmd = cmd_line.split(' ')
+
+        try:
+            func = getattr(self, cmd[0])
+        except Exception, e:
+            print 'Error: command unknown - %s' % e
+            return
+
+        try:
+            func(cmd[1:])
+        except Exception, e:
+            error_print(e)
+
+    def __wpa_property_changed(*args, **kwargs):
+        print 'WPA - Signal:  %s' % kwargs.get('signal')
+
+    def __if_property_changed(*args, **kwargs):
+        signal = kwargs.get('signal')
+        print 'IF - Signal:  %s' % signal
+
+        if signal == 'BSSAdded':
+            return
+
+        if args[0].debug:
+            print_tuple(args[1:])
+
+    def __p2p_property_changed(*args, **kwargs):
+        print 'IF P2P - Signal:  %s' % kwargs.get('signal')
+        if args[0].debug:
+            print_tuple(args[1:])
+
+    def __peer_if_p2p_property_changed(*args, **kwargs):
+        print 'Peer - ',
+        args[0].__p2p_property_changed(*args, **kwargs)
+
+    def __DeviceFound(self, object_path):
+        self.peers[object_path] = None
+
+        peer = self.bus.get_object(WPA_INTF, object_path)
+        peer_if = dbus.Interface(peer, DBUS_PROPERTIES_INTF)
+
+        self.bus.add_signal_receiver(self.__peer_if_p2p_property_changed,
+                                     dbus_interface=WPA_PEER_INTF,
+                                     path=object_path, member_keyword='signal')
+
+        self.peers[object_path] = peer_if.GetAll(WPA_PEER_INTF)
+
+        if self.debug:
+            print_dict(self.peers[object_path])
+
+    def __DeviceLost(self, object_path):
+        if object_path in self.peers:
+            del self.peers[object_path]
+
+    def __PeerJoined(self, object_path):
+        print 'Peer %s joined' % object_path
+
+    def __PeerDisconnected(self, object_path):
+        print 'Peer %s disconnected' % object_path
+
+    def __group_if_property_changed(*args, **kwargs):
+        print 'Group - ',
+        args[0].__if_property_changed(*args, **kwargs)
+
+    def __group_if_p2p_property_changed(*args, **kwargs):
+        print 'Group - ',
+        args[0].__p2p_property_changed(*args, **kwargs)
+
+    def __GroupFinished(self, properties):
+        print 'Group running on %s is being removed' % ifname
+        self.group_obj = self.group_if = self.group_iface_path = None
+
+        if self.debug:
+            print_dict(properties)
+
+    def __InvitationResult(self, response):
+        print 'Invitation result status: %d ' % response['status']
+
+        if response.has_key('bssid'):
+            print 'bssid: %s' % response['bssid']
+
+        if self.debug:
+            print_dict(response)
+
+    def __GroupStarted(self, properties):
+        self.group_obj = properties['group_object']
+        self.bus.add_signal_receiver(self.__PeerJoined,
+                                dbus_interface=WPA_GROUP_INTF,
+                                path=self.group_obj,
+                                signal_name='PeerJoined')
+        self.bus.add_signal_receiver(self.__PeerDisconnected,
+                                dbus_interface=WPA_GROUP_INTF,
+                                path=self.group_obj,
+                                signal_name='PeerDisconnected')
+
+        self.group_iface_path = properties['interface_object']
+        self.group_if = dbus.Interface(self.bus.get_object(WPA_INTF,
+                                       self.group_iface_path),
+                                       WPA_P2P_INTF)
+        self.bus.add_signal_receiver(self.__group_if_property_changed,
+                                dbus_interface=WPA_IF_INTF,
+                                path=self.group_iface_path,
+                                member_keyword='signal')
+        self.bus.add_signal_receiver(self.__group_if_p2p_property_changed,
+                                dbus_interface=WPA_P2P_INTF,
+                                path=self.group_iface_path,
+                                member_keyword='signal')
+        self.bus.add_signal_receiver(self.__GroupFinished,
+                                dbus_interface=WPA_P2P_INTF,
+                                path=self.group_iface_path,
+                                signal_name='GroupFinished')
+        self.bus.add_signal_receiver(self.__InvitationResult,
+                                dbus_interface=WPA_P2P_INTF,
+                                path=self.iface_path,
+                                signal_name='InvitationResult')
+
+        if self.debug:
+            group = dbus.Interface(self.bus.get_object(WPA_INTF,
+                                                       self.group_obj),
+                                                       DBUS_PROPERTIES_INTF)
+            print_dict(group.GetAll(WPA_GROUP_INTF))
+
+    def __ServiceDiscoveryResponse(self, response):
+        peer = response['peer_object']
+        if peer in self.peers:
+            print 'Peer %s has this TLVs:' % (self.peers[peer]['DeviceName'])
+            print response['tlvs']
+
+    def __InterfaceAdded(self, path, properties):
+        print 'Interface %s Added (%s)' % (properties['Ifname'], path)
+        if self.debug:
+            print_dict(properties)
+            p2p = dbus.Interface(self.bus.get_object(WPA_INTF,
+                                 path), DBUS_PROPERTIES_INTF)
+            print_dict(p2p.GetAll(WPA_P2P_INTF))
+
+    def __InterfaceRemoved(self, path):
+        print 'Interface Removed (%s)' % (path)
+
+    def __listen_if_signals(self):
+        self.bus.add_signal_receiver(self.__if_property_changed,
+                                dbus_interface=WPA_IF_INTF,
+                                path=self.iface_path,
+                                member_keyword='signal')
+        self.bus.add_signal_receiver(self.__p2p_property_changed,
+                                dbus_interface=WPA_P2P_INTF,
+                                path=self.iface_path,
+                                member_keyword='signal')
+        self.bus.add_signal_receiver(self.__GroupStarted,
+                                dbus_interface=WPA_P2P_INTF,
+                                path=self.iface_path,
+                                signal_name='GroupStarted')
+        self.bus.add_signal_receiver(self.__DeviceFound,
+                                dbus_interface=WPA_P2P_INTF,
+                                path=self.iface_path,
+                                signal_name='DeviceFound')
+        self.bus.add_signal_receiver(self.__DeviceLost,
+                                dbus_interface=WPA_P2P_INTF,
+                                path=self.iface_path,
+                                signal_name='DeviceLost')
+        self.bus.add_signal_receiver(self.__ServiceDiscoveryResponse,
+                                dbus_interface=WPA_P2P_INTF,
+                                path=self.iface_path,
+                                signal_name='ServiceDiscoveryResponse')
+
+    def __reset(self):
+        self.iface_path = self.iface_name = self.iface = None
+        self.p2p = self.group_if = self.group_obj = None
+        self.peers = {}
+
+    def __set_if(self, iface_name):
+        self.iface = dbus.Interface(self.bus.get_object(WPA_INTF,
+                                    self.iface_path), WPA_IF_INTF)
+        self.p2p = dbus.Interface(self.bus.get_object(WPA_INTF,
+                                    self.iface_path), WPA_P2P_INTF)
+
+        p2p_if = dbus.Interface(self.p2p, DBUS_PROPERTIES_INTF)
+        p2p_if.Set(WPA_P2P_INTF, 'P2PDeviceConfig',
+                   dbus.Dictionary({ 'DeviceName' : 'ConnManP2P' },
+                                   signature='sv'))
+        print 'Interface %s: %s' % (iface_name, self.iface_path)
+        self.iface_name = iface_name
+        self.__listen_if_signals()
+
+    @checkarg()
+    def enable_debug(self, args):
+        self.debug = True
+
+    @checkarg()
+    def disable_debug(self, args):
+        self.debug = False
+
+    @checkarg(nb_args=1)
+    def create_if(self, args):
+        self.__reset()
+        self.iface_path = self.wpa.CreateInterface(({ 'Ifname' : args[0]} ))
+        self.__set_if(args[0])
+
+    @checkarg(nb_args=1)
+    def get_if(self, args):
+        self.__reset()
+        self.iface_path = self.wpa.GetInterface(args[0])
+        self.__set_if(args[0])
+
+    @checkarg()
+    def del_if(self, args = None):
+        if not self.iface_path:
+            return
+
+        self.wpa.RemoveInterface(self.iface_path)
+        print 'Interface %s removed' % self.iface_name
+        self.__reset()
+
+    @checkarg()
+    def scan(self, args = None):
+        if not self.iface:
+            return
+
+        self.iface.Scan(({ 'Type': 'passive' }))
+        print 'Scan started'
+
+    @checkarg()
+    def quit(self, args = None):
+        self.del_if(args)
+        exit(0)
+
+    @checkarg(nb_args=1)
+    def set_command_list(self, command_list):
+        self.command_list = command_list[0]
+
+    @checkarg()
+    def p2p_find(self, args = None):
+        if not self.p2p:
+            return
+
+        self.p2p.Find(({}))
+
+    @checkarg()
+    def p2p_stop_find(self, args = None):
+        if not self.p2p:
+            return
+
+        self.p2p.StopFind()
+
+    @checkarg()
+    def p2p_peers(self, args = None):
+        if not self.iface:
+            return
+
+        for p in self.peers:
+            print 'Peer Name=%s' % (self.peers[p]['DeviceName'])
+
+    def __find_peer(self, peer_name, ret_object_path = False):
+        if len(self.peers) == 0:
+            return None
+
+        peer = None
+        for p in self.peers:
+            if self.peers[p]['DeviceName'] == peer_name:
+                peer = self.peers[p]
+                break
+
+        if not peer:
+            print 'No peer found under the name: %s' % peer_name
+            p = None
+
+        if ret_object_path:
+            return p
+        else:
+            return peer
+
+    @checkarg(nb_args = 1)
+    def p2p_peer(self, args):
+        peer_path = self.__find_peer(args[0], True)
+        if peer_path:
+            peer = self.bus.get_object(WPA_INTF, peer_path)
+            peer_if = dbus.Interface(peer, DBUS_PROPERTIES_INTF)
+            self.peers[peer_path] = peer_if.GetAll(WPA_PEER_INTF)
+
+            print_dict(self.peers[peer_path])
+
+    @checkarg(nb_args = 1)
+    def p2p_connect(self, args):
+        if not self.p2p:
+            return
+
+        peer = self.__find_peer(args[0])
+        if not peer:
+            return
+
+        peer_path = self.__find_peer(args[0], True)
+
+        if (peer['groupcapability'] & P2P_GROUP_CAPAB_GROUP_OWNER ==
+                                            P2P_GROUP_CAPAB_GROUP_OWNER):
+            print 'Joining an existing P2P group'
+            pin = self.p2p.Connect(({ 'peer' : peer_path,
+                                      'wps_method' : 'pbc',
+                                      'join' : True,
+                                      'go_intent' : 0 }))
+        else:
+            print 'Associating with another P2P device'
+            pin = self.p2p.Connect(({ 'peer' : peer_path,
+                                      'wps_method' : 'pbc',
+                                      'join' : False,
+                                      'go_intent' : 7 }))
+            if not pin:
+                print 'WPS PIN in use: %s' % pin
+
+    @checkarg(nb_args = 1)
+    def p2p_disconnect(self, args):
+        if not self.p2p:
+            return
+
+        peer = self.__find_peer(args[0])
+        if not peer:
+            return
+
+        if not self.group_if:
+            print 'Peer %s is not connected' % (peer['DeviceName'])
+            return
+
+        self.group_if.Disconnect()
+
+    @checkarg()
+    def p2p_group_add(self, args):
+        if not self.p2p:
+            return
+
+        self.p2p.GroupAdd(({ 'persistent' : dbus.Boolean(1) }))
+
+    @checkarg()
+    def p2p_group_remove(self, args):
+        if not self.group_if:
+            return
+
+        self.group_if.Disconnect()
+
+    @checkarg()
+    def p2p_group(self, args):
+        if not self.group_obj:
+            return
+
+        group = dbus.Interface(self.bus.get_object(WPA_INTF,
+                               self.group_obj), DBUS_PROPERTIES_INTF)
+        print_dict(group.GetAll(WPA_GROUP_INTF))
+
+    @checkarg()
+    def p2p_flush(self, args):
+        if not self.p2p:
+            return
+
+        self.p2p.Flush()
+
+    @checkarg()
+    def p2p_serv_disc_req(self, args = None):
+        if not self.p2p:
+            return
+
+        """ We request all kind of services """
+        sd_req = dbus.Array(signature='y', variant_level=1)
+        for a in [2,0,0,1]:
+            sd_req.append(dbus.Byte(a))
+
+        ref = self.p2p.ServiceDiscoveryRequest(({ 'tlv' : sd_req }))
+        print 'Service discovery reference: %s' % ref
+
+    @checkarg(nb_args = 1)
+    def p2p_serv_disc_cancel_req(self, args):
+        if not self.p2p:
+            return
+
+        self.p2p.ServiceDiscoveryCancelRequest(int(args[0]))
+
+    @checkarg(nb_args = 3)
+    def p2p_service_add(self, args):
+        if not self.p2p:
+            return
+
+        service = { 'service_type' : args[0] }
+        if args[0] == 'upnp':
+            service['version'] = args[1]
+            service['service'] = args[2]
+        elif args[0] == 'bonjour':
+            service['query'] = args[1]
+            service['response'] = args[2]
+        else:
+            print 'Unknown service: %s' % args[0]
+            return
+
+        self.p2p.AddService((service))
+
+    @checkarg(nb_args = 2, min_args = True)
+    def p2p_service_del(self, args):
+        if not self.p2p:
+            return
+
+        service = { 'service_type' : args[0] }
+        if args[0] == 'upnp':
+            service['version'] = args[1]
+            service['service'] = args[2]
+        elif args[0] == 'bonjour':
+            service['query'] = args[1]
+        else:
+            print 'Unknown service: %s' % args[0]
+            return
+
+        self.p2p.DeleteService((service))
+
+    @checkarg()
+    def p2p_service_flush(self, args = None):
+        if not self.p2p:
+            return
+
+        self.p2p.FlushService()
+
+    @checkarg(nb_args = 1)
+    def p2p_invite(self, args):
+        if not self.p2p or not self.group_if:
+            return
+
+        peer_path = self.__find_peer(args[0], True)
+
+        if not peer_path:
+            return
+
+        self.group_if.Invite({ 'peer' : peer_path})
+
+def build_args(parser):
+    parser.add_argument('-d', default=False, action='store_true',
+                       dest='debug', help='enable debug')
+    parser.add_argument('-i', metavar='<interface>', dest='ifname',
+                        help='interface name')
+
+    command = {}
+    command['quit'] = {}
+    command['enable_debug'] = {}
+    command['disable_debug'] = {}
+    command['create_if'] = {ArgFields.help:'<iface_name> - create interface'}
+    command['get_if'] = {ArgFields.help:'<iface_name> - get interface'}
+    command['del_if'] = {ArgFields.help:'removes current interface'}
+    command['scan'] = {}
+    command['p2p_find'] = {}
+    command['p2p_stop_find'] = {}
+    command['p2p_flush'] = {}
+    command['p2p_group_add'] = {ArgFields.help:'adds an autonomous group'}
+    command['p2p_group_remove'] = {}
+    command['p2p_group'] = {}
+    command['p2p_peers'] = {}
+    command['p2p_peer'] = {ArgFields.help:'<p2p device name> - get info for a '
+                                'peer'}
+    command['p2p_connect'] = {ArgFields.help:'<p2p device name>'}
+    command['p2p_disconnect'] = {ArgFields.help:'<p2p device name>'}
+    command['p2p_serv_disc_req'] = {}
+    command['p2p_serv_disc_cancel_req'] = {ArgFields.help:'<identifier>'}
+    command['p2p_service_add'] = {ArgFields.help:'<service type> '
+                                  '<version/query> <service/response>'}
+    command['p2p_service_del'] = {ArgFields.help:'<service type> '
+                                  '<version/query> [<service>]'}
+    command['p2p_service_flush'] = {}
+    command['p2p_invite'] = {ArgFields.help:'<p2p device name>'}
+
+    command_list = command.keys()
+    command_list.sort()
+    subparsers = parser.add_subparsers(help='commands', dest='command')
+    subparsers.add_parser('')
+    for key in command_list:
+        help=None
+        metavar=None
+        if command[key].has_key(ArgFields.help):
+            help = command[key][ArgFields.help]
+        if command[key].has_key(ArgFields.metavar):
+            metavar = command[key][ArgFields.metavar]
+        command_parser = subparsers.add_parser(key, help=help)
+        command_parser.add_argument(key, nargs='*', metavar=metavar, help=help)
+
+    return command
+
+def main():
+    if version_info.major != 2:
+        print 'You need to run this under Python 2.x'
+        exit(1)
+
+    parser = argparse.ArgumentParser(description='Connman P2P Test')
+
+    command_list = build_args(parser)
+
+    argv[1:] += ['']
+
+    args = parser.parse_args(argv[1:])
+
+    dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
+
+    opts = []
+    if args.command:
+        opts = getattr(args, args.command)
+
+    params = ''
+    if opts and len(opts[0]):
+        params = ' ' + ''.join(opts)
+
+    bus = dbus.SystemBus()
+
+    mainloop = gobject.MainLoop()
+
+    wpa_s = Wpa_s(bus, args.ifname, args.command + params)
+
+    if (args.debug):
+            wpa_s.enable_debug([])
+
+    wpa_s.set_command_list([command_list])
+
+    mainloop.run()
+
+if __name__ == '__main__':
+    main()
diff --git a/connman/test/remove-provider b/connman/test/remove-provider
new file mode 100755
index 0000000..39f8de7
--- /dev/null
+++ b/connman/test/remove-provider
@@ -0,0 +1,19 @@
+#!/usr/bin/python
+
+import sys
+import dbus
+
+if (len(sys.argv) < 2):
+	print "Usage: %s <VPN service path> " % (sys.argv[0])
+	sys.exit(1)
+
+bus = dbus.SystemBus()
+
+manager = dbus.Interface(bus.get_object("net.connman", "/"),
+					"net.connman.Manager")
+
+path = "" + sys.argv[1]
+
+print "remove path is %s" %(path)
+
+manager.RemoveProvider(sys.argv[1])
diff --git a/connman/test/service-move-before b/connman/test/service-move-before
new file mode 100755
index 0000000..d912c88
--- /dev/null
+++ b/connman/test/service-move-before
@@ -0,0 +1,27 @@
+#!/usr/bin/python
+
+import sys
+import dbus
+
+def print_usage():
+	print "Usage: %s <service> <target service>" % (sys.argv[0])
+
+
+if (len(sys.argv) < 2):
+	print_usage()
+	sys.exit(1)
+
+bus = dbus.SystemBus()
+path = "/net/connman/service/" + sys.argv[1]
+service = dbus.Interface(bus.get_object('net.connman', path),
+					'net.connman.Service')
+
+path2 = "/net/connman/service/" + sys.argv[2]
+service2 = dbus.Interface(bus.get_object('net.connman', path2),
+					'net.connman.Service')
+
+print "Moving %s before %s" % (sys.argv[1], sys.argv[2])
+
+service.MoveBefore(service2)
+
+print
diff --git a/connman/test/set-clock b/connman/test/set-clock
new file mode 100755
index 0000000..a9db3e3
--- /dev/null
+++ b/connman/test/set-clock
@@ -0,0 +1,32 @@
+#!/usr/bin/python
+
+import sys
+import dbus
+
+def print_usage():
+	print "Usage: %s TimeUpdates|TimezoneUpdates manual|auto" % (sys.argv[0])
+	sys.exit(1)
+
+
+def make_variant(string):
+	return dbus.String(string, variant_level=1)
+
+
+if (len(sys.argv) != 3):
+	print_usage()
+
+if (sys.argv[1] != "TimeUpdates" and sys.argv[1] != "TimezoneUpdates"):
+	print_usage()
+
+if (sys.argv[2] != "manual" and sys.argv[2] != "auto"):
+	print_usage()
+
+bus = dbus.SystemBus()
+
+clock = dbus.Interface(bus.get_object('net.connman', '/'),
+					'net.connman.Clock')
+
+print "Setting %s to %s" % (sys.argv[1], sys.argv[2])
+
+clock.SetProperty(sys.argv[1], make_variant(sys.argv[2]),
+		  signature=dbus.Signature('sv'))
diff --git a/connman/test/set-domains b/connman/test/set-domains
new file mode 100755
index 0000000..87e563e
--- /dev/null
+++ b/connman/test/set-domains
@@ -0,0 +1,20 @@
+#!/usr/bin/python
+
+import sys
+import dbus
+
+if (len(sys.argv) < 2):
+	print "Usage: %s <service> [domain*]" % (sys.argv[0])
+	sys.exit(1)
+
+bus = dbus.SystemBus()
+path = "/net/connman/service/" + sys.argv[1]
+service = dbus.Interface(bus.get_object('net.connman', path),
+					'net.connman.Service')
+
+properties = service.GetProperties()
+
+print "Setting domains to %s" % (sys.argv[2:])
+
+service.SetProperty("Domains.Configuration", 
+	dbus.Array(sys.argv[2:], signature=dbus.Signature('s')))
diff --git a/connman/test/set-global-timeservers b/connman/test/set-global-timeservers
new file mode 100755
index 0000000..d7551a1
--- /dev/null
+++ b/connman/test/set-global-timeservers
@@ -0,0 +1,18 @@
+#!/usr/bin/python
+
+import sys
+import dbus
+
+if (len(sys.argv) < 1):
+	print "Usage: %s [timeserver*]" % (sys.argv[0])
+	sys.exit(1)
+
+bus = dbus.SystemBus()
+
+clock = dbus.Interface(bus.get_object('net.connman', '/'),
+					'net.connman.Clock')
+
+print "Setting timeserver to %s" % (sys.argv[1:])
+
+clock.SetProperty("Timeservers", dbus.Array(sys.argv[1:],
+					signature=dbus.Signature('s')))
diff --git a/connman/test/set-ipv4-method b/connman/test/set-ipv4-method
new file mode 100755
index 0000000..235113f
--- /dev/null
+++ b/connman/test/set-ipv4-method
@@ -0,0 +1,37 @@
+#!/usr/bin/python
+
+import sys
+import dbus
+
+def make_variant(string):
+	return dbus.String(string, variant_level=1)
+
+def print_usage():
+	print "Usage: %s <service> [off|dhcp|manual <address> [netmask] [gateway]]" % (sys.argv[0])
+
+
+if (len(sys.argv) < 3):
+	print_usage()
+	sys.exit(1)
+
+bus = dbus.SystemBus()
+path = "/net/connman/service/" + sys.argv[1]
+service = dbus.Interface(bus.get_object('net.connman', path),
+					'net.connman.Service')
+
+properties = service.GetProperties()
+
+print "Setting method %s for %s" % (sys.argv[2], sys.argv[1])
+
+ipv4_configuration = { "Method": make_variant(sys.argv[2]) }
+if (len(sys.argv) > 3):
+	ipv4_configuration["Address"] = make_variant(sys.argv[3])
+if (len(sys.argv) > 4):
+	ipv4_configuration["Netmask"] = make_variant(sys.argv[4])
+if (len(sys.argv) > 5):
+        ipv4_configuration["Gateway"] = make_variant(sys.argv[5])
+
+service.SetProperty("IPv4.Configuration", ipv4_configuration)
+print "New IPv4.Configuration: ", ipv4_configuration
+
+print
diff --git a/connman/test/set-ipv6-method b/connman/test/set-ipv6-method
new file mode 100755
index 0000000..eb1f1b5
--- /dev/null
+++ b/connman/test/set-ipv6-method
@@ -0,0 +1,43 @@
+#!/usr/bin/python
+
+import sys
+import dbus
+
+def make_variant(string):
+	return dbus.String(string, variant_level=1)
+
+def make_byte_variant(string):
+    return dbus.Byte(int(string), variant_level=1)
+
+def print_usage():
+	print "Usage: %s <service> off|manual|auto [<address> [prefixlen] [gateway]] [<privacy>]" % (sys.argv[0])
+
+if (len(sys.argv) < 3):
+	print_usage()
+	sys.exit(1)
+
+bus = dbus.SystemBus()
+path = "/net/connman/service/" + sys.argv[1]
+service = dbus.Interface(bus.get_object('net.connman', path),
+					'net.connman.Service')
+
+properties = service.GetProperties()
+
+print "Setting method %s for %s" % (sys.argv[2], sys.argv[1])
+
+ipv6_configuration = { "Method": make_variant(sys.argv[2])}
+if sys.argv[2] == "auto":
+	if (len(sys.argv) > 3):
+		ipv6_configuration["Privacy"] = make_variant(sys.argv[3])
+else:
+	if (len(sys.argv) > 3):
+		ipv6_configuration["Address"] = make_variant(sys.argv[3])
+	if (len(sys.argv) > 4):
+		ipv6_configuration["PrefixLength"] = make_byte_variant(sys.argv[4])
+	if (len(sys.argv) > 5):
+		ipv6_configuration["Gateway"] = make_variant(sys.argv[5])
+
+service.SetProperty("IPv6.Configuration", ipv6_configuration)
+print "New IPv6.Configuration: ", ipv6_configuration
+
+print
diff --git a/connman/test/set-nameservers b/connman/test/set-nameservers
new file mode 100755
index 0000000..ece69b8
--- /dev/null
+++ b/connman/test/set-nameservers
@@ -0,0 +1,20 @@
+#!/usr/bin/python
+
+import sys
+import dbus
+
+if (len(sys.argv) < 2):
+	print "Usage: %s <service> [nameserver*]" % (sys.argv[0])
+	sys.exit(1)
+
+bus = dbus.SystemBus()
+path = "/net/connman/service/" + sys.argv[1]
+service = dbus.Interface(bus.get_object('net.connman', path),
+					'net.connman.Service')
+
+properties = service.GetProperties()
+
+print "Setting nameserver to %s" % (sys.argv[2:])
+
+service.SetProperty("Nameservers.Configuration", 
+	dbus.Array(sys.argv[2:], signature=dbus.Signature('s')))
diff --git a/connman/test/set-proxy b/connman/test/set-proxy
new file mode 100755
index 0000000..b9da7b0
--- /dev/null
+++ b/connman/test/set-proxy
@@ -0,0 +1,44 @@
+#!/usr/bin/python
+
+import sys
+import dbus
+
+if (len(sys.argv) < 2):
+	print "Usage:"
+	print "%s <service> direct" % (sys.argv[0])
+	print "%s <service> manual [servers=uri1,uri2,...] [excludes=host1,host2,...]" % (sys.argv[0])
+	print "%s <service> auto url=[pac-url]" % (sys.argv[0])
+	print "Example: %s service0 manual servers=proxy.example.com:8080" % sys.argv[0]
+	print "         This would set the proxy uri and the method to manual"
+	sys.exit(1)
+
+bus = dbus.SystemBus()
+path = "/net/connman/service/" + sys.argv[1]
+service = dbus.Interface(bus.get_object('net.connman', path),
+					'net.connman.Service')
+
+values = { "Method" : sys.argv[2] }
+
+properties = service.GetProperties()
+
+for arg in sys.argv[3:]:
+	if arg.startswith("url="):
+		url = arg.replace("url=", "", 1)
+		values["URL"] = url
+	if arg.startswith("servers="):
+		try:
+			servers_uris = arg.replace("servers=","",1).split(",")
+		except:
+			servers_uris = []
+		values["Servers"] = servers_uris
+	if arg.startswith("excludes="):
+		try:
+			excludes_uris = arg.replace("excludes=","",1).split(",")
+		except:
+			excludes_uris = []
+		values["Excludes"] = excludes_uris
+
+try:
+	service.SetProperty("Proxy.Configuration", dbus.Dictionary(values, signature='sv'))
+except dbus.exceptions.DBusException, e_msg:
+	print e_msg
diff --git a/connman/test/set-timeservers b/connman/test/set-timeservers
new file mode 100755
index 0000000..19cc938
--- /dev/null
+++ b/connman/test/set-timeservers
@@ -0,0 +1,20 @@
+#!/usr/bin/python
+
+import sys
+import dbus
+
+if (len(sys.argv) < 2):
+	print "Usage: %s <service> [timeserver*]" % (sys.argv[0])
+	sys.exit(1)
+
+bus = dbus.SystemBus()
+path = "/net/connman/service/" + sys.argv[1]
+service = dbus.Interface(bus.get_object('net.connman', path),
+					'net.connman.Service')
+
+properties = service.GetProperties()
+
+print "Setting timeserver to %s" % (sys.argv[2:])
+
+service.SetProperty("Timeservers.Configuration",
+	dbus.Array(sys.argv[2:], signature=dbus.Signature('s')))
diff --git a/connman/test/set-timezone b/connman/test/set-timezone
new file mode 100755
index 0000000..dfc1c98
--- /dev/null
+++ b/connman/test/set-timezone
@@ -0,0 +1,21 @@
+#!/usr/bin/python
+
+import sys
+import dbus
+
+if (len(sys.argv) != 2):
+	print "Usage: %s <timezone>" % (sys.argv[0])
+	sys.exit(1)
+
+bus = dbus.SystemBus()
+
+clock = dbus.Interface(bus.get_object('net.connman', '/'),
+					'net.connman.Clock')
+
+print "Setting timezone to %s" % (sys.argv[1])
+
+try:
+	clock.SetProperty("Timezone", dbus.String(sys.argv[1], variant_level=1),
+			  signature=dbus.Signature('sv'))
+except dbus.exceptions.DBusException, e_msg:
+	print e_msg
diff --git a/connman/test/show-introspection b/connman/test/show-introspection
new file mode 100755
index 0000000..4b6450f
--- /dev/null
+++ b/connman/test/show-introspection
@@ -0,0 +1,21 @@
+#!/usr/bin/python
+
+import dbus
+
+bus = dbus.SystemBus()
+
+object = dbus.Interface(bus.get_object("net.connman", '/'),
+				"org.freedesktop.DBus.Introspectable")
+
+print object.Introspect()
+
+manager = dbus.Interface(bus.get_object("net.connman", "/"),
+					"net.connman.Manager")
+
+technologies = manager.GetTechnologies()
+
+for path, properties in technologies:
+	object = dbus.Interface(bus.get_object("net.connman", path),
+					"org.freedesktop.DBus.Introspectable")
+
+	print object.Introspect()
diff --git a/connman/test/simple-agent b/connman/test/simple-agent
new file mode 100755
index 0000000..01c82ba
--- /dev/null
+++ b/connman/test/simple-agent
@@ -0,0 +1,357 @@
+#!/usr/bin/python
+
+import gobject
+
+import dbus
+import dbus.service
+import dbus.mainloop.glib
+import sys
+
+class Canceled(dbus.DBusException):
+	_dbus_error_name = "net.connman.Error.Canceled"
+
+class LaunchBrowser(dbus.DBusException):
+	_dbus_error_name = "net.connman.Agent.Error.LaunchBrowser"
+
+class Agent(dbus.service.Object):
+	name = None
+	ssid = None
+	identity = None
+	passphrase = None
+	wpspin = None
+	username = None
+	password = None
+
+	@dbus.service.method("net.connman.Agent",
+					in_signature='', out_signature='')
+	def Release(self):
+		print("Release")
+		mainloop.quit()
+
+	def input_passphrase(self):
+		response = {}
+
+		if not self.identity and not self.passphrase and not self.wpspin:
+			print "Service credentials requested, type cancel to cancel"
+			args = raw_input('Answer: ')
+
+			for arg in args.split():
+				if arg.startswith("cancel"):
+					response["Error"] = arg
+				if arg.startswith("Identity="):
+					identity = arg.replace("Identity=", "", 1)
+					response["Identity"] = identity
+				if arg.startswith("Passphrase="):
+					passphrase = arg.replace("Passphrase=", "", 1)
+					response["Passphrase"] = passphrase
+				if arg.startswith("WPS="):
+					wpspin = arg.replace("WPS=", "", 1)
+					response["WPS"] = wpspin
+					break
+		else:
+			if self.identity:
+				response["Identity"] = self.identity
+			if self.passphrase:
+				response["Passphrase"] = self.passphrase
+			if self.wpspin:
+				response["WPS"] = self.wpspin
+
+		return response
+
+	def input_username(self):
+		response = {}
+
+		if not self.username and not self.password:
+			print "User login requested, type cancel to cancel"
+			print "or browser to login through the browser by yourself."
+			args = raw_input('Answer: ')
+
+			for arg in args.split():
+				if arg.startswith("cancel") or arg.startswith("browser"):
+					response["Error"] = arg
+				if arg.startswith("Username="):
+					username = arg.replace("Username=", "", 1)
+					response["Username"] = username
+				if arg.startswith("Password="):
+					password = arg.replace("Password=", "", 1)
+					response["Password"] = password
+		else:
+			if self.username:
+				response["Username"] = self.username
+			if self.password:
+				response["Password"] = self.password
+
+		return response
+
+	def input_hidden(self):
+		response = {}
+
+		if not self.name and not self.ssid:
+			args = raw_input('Answer ')
+
+			for arg in args.split():
+				if arg.startswith("Name="):
+					name = arg.replace("Name=", "", 1)
+					response["Name"] = name
+					break
+				if arg.startswith("SSID="):
+					ssid = arg.replace("SSID", "", 1)
+					response["SSID"] = ssid
+					break
+		else:
+			if self.name:
+				response["Name"] = self.name
+			if self.ssid:
+				response["SSID"] = self.ssid
+
+		return response
+
+	@dbus.service.method("net.connman.Agent",
+					in_signature='oa{sv}',
+					out_signature='a{sv}')
+	def RequestInput(self, path, fields):
+		print "RequestInput (%s,%s)" % (path, fields)
+
+		response = {}
+
+		if fields.has_key("Name"):
+			response.update(self.input_hidden())
+		if fields.has_key("Passphrase"):
+			response.update(self.input_passphrase())
+		if fields.has_key("Username"):
+			response.update(self.input_username())
+
+		if response.has_key("Error"):
+			if response["Error"] == "cancel":
+				raise Canceled("canceled")
+				return
+			if response["Error"] == "browser":
+				raise LaunchBrowser("launch browser")
+				return
+
+		print "returning (%s)" % (response)
+
+		return response
+
+	@dbus.service.method("net.connman.Agent",
+					in_signature='os',
+					out_signature='')
+	def RequestBrowser(self, path, url):
+		print "RequestBrowser (%s,%s)" % (path, url)
+
+		print "Please login through the given url in a browser"
+		print "Then press enter to accept or some text to cancel"
+
+		args = raw_input('> ')
+
+		if len(args) > 0:
+			raise Canceled("canceled")
+
+		return
+
+	@dbus.service.method("net.connman.Agent",
+					in_signature='os',
+					out_signature='')
+	def ReportError(self, path, error):
+		print "ReportError %s, %s" % (path, error)
+		retry = raw_input("Retry service (yes/no): ")
+		if (retry == "yes"):
+			class Retry(dbus.DBusException):
+				_dbus_error_name = "net.connman.Agent.Error.Retry"
+
+			raise Retry("retry service")
+		else:
+			return
+
+
+	@dbus.service.method("net.connman.Agent",
+					in_signature='', out_signature='')
+	def Cancel(self):
+		print "Cancel"
+
+class VpnAgent(dbus.service.Object):
+	name = None
+	host = None
+	cookie = None
+	username = None
+	password = None
+
+	@dbus.service.method("net.connman.vpn.Agent",
+					in_signature='', out_signature='')
+	def Release(self):
+		print("Release VPN agent")
+
+	def input_cookie(self):
+		response = {}
+
+		if not self.cookie:
+			print "VPN credentials requested, type cancel to cancel"
+			args = raw_input('Answer: ')
+
+			for arg in args.split():
+				if arg.startswith("cancel"):
+					response["Error"] = arg
+				if arg.startswith("Cookie="):
+					cookie = arg.replace("Cookie=", "", 1)
+					response["OpenConnect.Cookie"] = cookie
+		else:
+			if self.cookie:
+				response["OpenConnect.Cookie"] = self.cookie
+
+		return response
+
+	def input_username(self):
+		response = {}
+
+		if not self.username and not self.password:
+			print "User login requested, type cancel to cancel"
+			args = raw_input('Answer: ')
+
+			for arg in args.split():
+				if arg.startswith("cancel"):
+					response["Error"] = arg
+				if arg.startswith("Username="):
+					username = arg.replace("Username=", "", 1)
+					response["Username"] = username
+				if arg.startswith("Password="):
+					password = arg.replace("Password=", "", 1)
+					response["Password"] = password
+		else:
+			if self.username:
+				response["Username"] = self.username
+			if self.password:
+				response["Password"] = self.password
+
+		return response
+
+	@dbus.service.method("net.connman.vpn.Agent",
+					in_signature='oa{sv}',
+					out_signature='a{sv}')
+	def RequestInput(self, path, fields):
+		print "RequestInput (%s,%s)" % (path, fields)
+
+		response = {}
+
+		if fields.has_key("OpenConnect.Cookie"):
+			response.update(self.input_cookie())
+		if fields.has_key("Username") or fields.has_key("Password"):
+			response.update(self.input_username())
+
+		if response.has_key("Error"):
+			if response["Error"] == "cancel":
+				raise Canceled("canceled")
+				return
+
+		print "returning (%s)" % (response)
+
+		return response
+
+	@dbus.service.method("net.connman.vpn.Agent",
+					in_signature='os',
+					out_signature='')
+	def ReportError(self, path, error):
+		print "ReportError %s, %s" % (path, error)
+		retry = raw_input("Retry service (yes/no): ")
+		if (retry == "yes"):
+			class Retry(dbus.DBusException):
+				_dbus_error_name = "net.connman.vpn.Agent.Error.Retry"
+
+			raise Retry("retry service")
+		else:
+			return
+
+
+	@dbus.service.method("net.connman.vpn.Agent",
+					in_signature='', out_signature='')
+	def Cancel(self):
+		print "Cancel"
+
+def vpnNameOwnerChanged(proxy):
+	if proxy:
+		print("vpnd is connected to system bus")
+		try:
+			path = "/test/vpn_agent"
+			vpn_manager = dbus.Interface(bus.get_object('net.connman.vpn',
+								    "/"),
+						     'net.connman.vpn.Manager')
+			vpn_manager.RegisterAgent(path)
+		except:
+			print "vpn agent is not registered"
+	else:
+		print("vpnd is disconnected from system bus")
+		vpn_manager = None
+
+def print_usage():
+	print "Usage:"
+	print "For hidden service:"
+	print "%s Name=<hidden service name> [SSID=<hidden ssid>]" % (sys.argv[0])
+	print "For EAP/WPA input:"
+	print "%s Identity=<identity> Passphrase=<passphrase> WPS=<wpspin>" % (sys.argv[0])
+	print "For WISPr login, L2TP or PPTP input:"
+	print "%s Username=<username> Password=<password>" % (sys.argv[0])
+	print "For OpenConnect input:"
+	print "%s Cookie=<string>" % (sys.argv[0])
+	print "Help: %s help" % (sys.argv[0])
+	sys.exit(1)
+
+if __name__ == '__main__':
+	if len(sys.argv) == 2 and sys.argv[1] == "help":
+		print_usage()
+
+	dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
+
+	bus = dbus.SystemBus()
+	manager = dbus.Interface(bus.get_object('net.connman', "/"),
+					'net.connman.Manager')
+
+	path = "/test/agent"
+	object = Agent(bus, path)
+
+	try:
+		vpn_manager = dbus.Interface(bus.get_object('net.connman.vpn', "/"),
+					    'net.connman.vpn.Manager')
+		vpn_path = "/test/vpn_agent"
+		vpn_object = VpnAgent(bus, vpn_path)
+	except:
+		vpn_manager = None
+		print "net.connman.vpn is not present"
+
+	if len(sys.argv) >= 2:
+		for arg in sys.argv[1:]:
+			if arg.startswith("Name="):
+				object.name = arg.replace("Name=", "", 1)
+			elif arg.startswith("SSID="):
+				object.ssid = arg.replace("SSID=", "", 1)
+			elif arg.startswith("Identity="):
+				object.identity = arg.replace("Identity=", "", 1)
+			elif arg.startswith("Passphrase="):
+				object.passphrase = arg.replace("Passphrase=", "", 1)
+			elif arg.startswith("WPS="):
+				object.wpspin = arg.replace("WPS=", "", 1)
+			elif arg.startswith("Username="):
+				object.username = arg.replace("Username=", "", 1)
+				vpn_object.username = arg.replace("Username=", "", 1)
+			elif arg.startswith("Password="):
+				object.password = arg.replace("Password=", "", 1)
+				vpn_object.password = arg.replace("Password=", "", 1)
+			elif arg.startswith("Cookie="):
+				vpn_object.cookie = arg.replace("Cookie=", "", 1)
+			else:
+				print_usage()
+
+	try:
+		manager.RegisterAgent(path)
+	except:
+		print "Cannot register connman agent."
+
+	if vpn_manager != None:
+		try:
+			vpn_manager.RegisterAgent(vpn_path)
+			bus.watch_name_owner('net.connman.vpn', vpnNameOwnerChanged)
+		except:
+			"Cannot register vpn agent"
+
+	mainloop = gobject.MainLoop()
+	mainloop.run()
+
+	#manager.UnregisterAgent(path)
diff --git a/connman/test/test-clock b/connman/test/test-clock
new file mode 100755
index 0000000..e9b76fc
--- /dev/null
+++ b/connman/test/test-clock
@@ -0,0 +1,19 @@
+#!/usr/bin/python
+
+import dbus
+
+bus = dbus.SystemBus()
+
+clock = dbus.Interface(bus.get_object("net.connman", "/"),
+					"net.connman.Clock")
+
+properties = clock.GetProperties()
+
+for key in properties.keys():
+	if key in ["Timeservers"]:
+		list = ""
+		for val in properties[key]:
+			list = list + val + " "
+		print "%s = [ %s]" % (key, list)
+	else:
+		print "%s = %s" % (key, properties[key])
diff --git a/connman/test/test-compat b/connman/test/test-compat
new file mode 100755
index 0000000..cd1ca7a
--- /dev/null
+++ b/connman/test/test-compat
@@ -0,0 +1,15 @@
+#!/usr/bin/python
+
+import dbus
+
+bus = dbus.SystemBus()
+
+manager = dbus.Interface(bus.get_object('org.freedesktop.NetworkManager',
+				'/org/freedesktop/NetworkManager'),
+					'org.freedesktop.NetworkManager')
+
+states = [ "unknown", "asleep", "connecting", "connected", "disconnected" ]
+
+state = manager.state()
+
+print "System is %s" % (states[state])
diff --git a/connman/test/test-connman b/connman/test/test-connman
new file mode 100755
index 0000000..d047c86
--- /dev/null
+++ b/connman/test/test-connman
@@ -0,0 +1,193 @@
+#!/usr/bin/python
+
+import sys
+import dbus
+
+bus = dbus.SystemBus()
+
+manager = dbus.Interface(bus.get_object("net.connman", "/"),
+					"net.connman.Manager")
+
+if len(sys.argv) < 2:
+	print "Usage: %s <command>" % (sys.argv[0])
+	print ""
+	print "  state"
+	print "  services"
+	print "  autoconnect <service> [autoconnect]"
+	print "  connect <service>"
+	print "  disconnect <service>"
+	print "  remove <service>"
+	print ""
+	print "  scan <type>"
+	print "  enable <type>"
+	print "  disable <type>"
+	print "  offlinemode [on|off]"
+	sys.exit(1)
+
+def print_services(services):
+	for path, properties in services:
+		identifier = path[path.rfind("/") + 1:]
+		state = " "
+		autoconnect = "  "
+
+		if properties["Favorite"] == dbus.Boolean(1):
+			favorite = "*"
+
+			if properties["AutoConnect"] == dbus.Boolean(1):
+				autoconnect = " A"
+			else:
+				autoconnect = "  "
+
+			if properties["State"] == "ready":
+				state = "R"
+			elif properties["State"] == "online":
+				state = "O"
+		else:
+			favorite = " "
+
+		if "Name" in properties.keys():
+			name = properties["Name"]
+		else:
+			name = "{" + properties["Type"] + "}"
+
+		print "%s%s%s %-26s { %s }" % (favorite, autoconnect, state,
+					       name, identifier)
+
+if sys.argv[1] == "state":
+	properties = manager.GetProperties()
+
+	print "System is %s" % (properties["State"])
+
+elif sys.argv[1] in ["services", "list", "show"]:
+	print_services(manager.GetServices())
+
+elif sys.argv[1] in ["autoconnect", "autoconn"]:
+	if (len(sys.argv) < 3):
+		print "Need at least service parameter"
+		sys.exit(1)
+
+	path = "/net/connman/service/" + sys.argv[2]
+
+	service = dbus.Interface(bus.get_object("net.connman", path),
+						"net.connman.Service")
+
+	if (len(sys.argv) > 3):
+		flag = sys.argv[3].strip().lower()
+		autoconnect = dbus.Boolean(flag not in ['false', 'f', 'n', '0'])
+
+		service.SetProperty("AutoConnect", autoconnect);
+
+		print "Auto connect %s for %s" % (autoconnect, sys.argv[2])
+	else:
+		properties = service.GetProperties()
+
+		if "Name" in properties.keys():
+			name = properties["Name"]
+		else:
+			name = "{" + properties["Type"] + "}"
+
+		if "AutoConnect" in properties.keys():
+			autoconnect = properties["AutoConnect"]
+		else:
+			autoconnect = dbus.Boolean(0)
+
+		print "Auto connect %s for %s" % (autoconnect, name)
+
+elif sys.argv[1] in ["connect", "conn"]:
+	if (len(sys.argv) < 3):
+		print "Need at least service parameter"
+		sys.exit(1)
+
+	path = "/net/connman/service/" + sys.argv[2]
+
+	service = dbus.Interface(bus.get_object("net.connman", path),
+						"net.connman.Service")
+
+	try:
+		service.Connect(timeout=60000)
+	except dbus.DBusException, error:
+		print "%s: %s" % (error._dbus_error_name, error.message)
+
+elif sys.argv[1] in ["disconnect", "disc"]:
+	if (len(sys.argv) < 3):
+		print "Need at least service parameter"
+		sys.exit(1)
+
+	path = "/net/connman/service/" + sys.argv[2]
+
+	service = dbus.Interface(bus.get_object("net.connman", path),
+						"net.connman.Service")
+
+	try:
+		service.Disconnect()
+	except dbus.DBusException, error:
+		print "%s: %s" % (error._dbus_error_name, error.message)
+
+elif sys.argv[1] in ["remove"]:
+	if (len(sys.argv) < 3):
+		print "Need at least service parameter"
+		sys.exit(1)
+
+	path = "/net/connman/service/" + sys.argv[2]
+
+	service = dbus.Interface(bus.get_object("net.connman", path),
+						"net.connman.Service")
+
+	properties = service.GetProperties()
+
+	if properties["Favorite"] == dbus.Boolean(0):
+		print "Only favorite services can be removed"
+		sys.exit(1)
+
+	try:
+		service.Remove()
+	except dbus.DBusException, error:
+		print "%s: %s" % (error._dbus_error_name, error.message)
+
+elif sys.argv[1] == "scan":
+	if len(sys.argv) == 3:
+		path = "/net/connman/technology/" + sys.argv[2]
+		technology = dbus.Interface(bus.get_object("net.connman", path),
+						"net.connman.Technology")
+		technology.Scan()
+	else:
+		print "'%s' takes two arguments" % sys.argv[1]
+
+elif sys.argv[1] == "enable":
+	if len(sys.argv) == 3:
+		path = "/net/connman/technology/" + sys.argv[2]
+		technology = dbus.Interface(bus.get_object("net.connman", path),
+					    "net.connman.Technology")
+		technology.SetProperty("Powered", True)
+	else:
+		print "'%s' takes two arguments" % sys.argv[1]
+
+elif sys.argv[1] == "disable":
+	if len(sys.argv) == 3:
+		path = "/net/connman/technology/" + sys.argv[2]
+		technology = dbus.Interface(bus.get_object("net.connman", path),
+					    "net.connman.Technology")
+		technology.SetProperty("Powered", False)
+	else:
+		print "'%s' takes two arguments" % sys.argv[1]
+
+
+elif sys.argv[1] in ["offlinemode", "flightmode"]:
+	if len(sys.argv) == 3:
+		if sys.argv[2] == "on" or sys.argv[2] == "1" or sys.argv[2] == "yes":
+			active = dbus.Boolean(1)
+		elif sys.argv[2] == "off" or sys.argv[2] == "0" or sys.argv[2] == "no":
+			active = dbus.Boolean(0)
+		else:
+			print "Use either 'on', '1', 'yes', 'off', '0' or 'no'"
+			exit()
+
+		manager.SetProperty("OfflineMode", active)
+	elif len(sys.argv) == 2:
+		properties = manager.GetProperties()
+		print "Offline mode is %s" % (properties["OfflineMode"])
+	else:
+		print "'%s' takes max. two arguments" % sys.argv[1]
+
+else:
+	print "Unknown command"
diff --git a/connman/test/test-counter b/connman/test/test-counter
new file mode 100755
index 0000000..ce83580
--- /dev/null
+++ b/connman/test/test-counter
@@ -0,0 +1,79 @@
+#!/usr/bin/python
+
+import sys
+import gobject
+
+import dbus
+import dbus.service
+import dbus.mainloop.glib
+
+def make_bytes_readable(bytes):
+	SUFFIXES = [ 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB' ]
+	size = 1024
+
+	if bytes < size:
+		return ''
+
+	for suffix in SUFFIXES:
+		if bytes > size * 1024:
+			size = size * 1024
+			continue
+
+		return '%.1f %s' % (bytes / float(size), suffix)
+
+	return ''
+
+def print_stats(stats):
+	keys = stats.keys()
+	keys.sort()
+
+	for key in keys:
+		val = int(stats[key])
+		str = "    %s = %s" % (key, val)
+
+		if key in ["RX.Bytes", "TX.Bytes"]:
+			hstr = make_bytes_readable(val)
+			if hstr:
+				str = "%s (%s)" % (str, hstr)
+
+		print str
+
+class Counter(dbus.service.Object):
+	@dbus.service.method("net.connman.Counter",
+				in_signature='', out_signature='')
+	def Release(self):
+		print("Release")
+		mainloop.quit()
+
+	@dbus.service.method("net.connman.Counter",
+				in_signature='oa{sv}a{sv}', out_signature='')
+	def Usage(self, path, home, roaming):
+		print "%s" % (path)
+
+		if len(home) > 0:
+			print "  Home"
+			print_stats(home)
+		if len(roaming) > 0:
+			print "  Roaming"
+			print_stats(roaming)
+
+if __name__ == '__main__':
+	dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
+
+	bus = dbus.SystemBus()
+	manager = dbus.Interface(bus.get_object('net.connman', "/"),
+					'net.connman.Manager')
+
+	period = 2
+	if len(sys.argv) > 1:
+		period = sys.argv[1]
+
+	path = "/test/counter%s" % period
+	object = Counter(bus, path)
+
+	manager.RegisterCounter(path, dbus.UInt32(10), dbus.UInt32(period))
+
+	mainloop = gobject.MainLoop()
+	mainloop.run()
+
+	#manager.UnregisterCounter(path)
diff --git a/connman/test/test-manager b/connman/test/test-manager
new file mode 100755
index 0000000..2b4493c
--- /dev/null
+++ b/connman/test/test-manager
@@ -0,0 +1,93 @@
+#!/usr/bin/python
+
+import dbus
+
+def extract_values(values):
+	val = "{"
+	for key in values.keys():
+		val += " " + key + "="
+		if key in ["PrefixLength"]:
+			val += "%s" % (int(values[key]))
+		else:
+			if key in ["Servers", "Excludes"]:
+				val += extract_list(values[key])
+			else:
+				val += str(values[key])
+	val += " }"
+	return val
+
+def extract_list(list):
+	val = "["
+	for i in list:
+		val += " " + str(i)
+	val += " ]"
+	return val
+
+bus = dbus.SystemBus()
+
+manager = dbus.Interface(bus.get_object("net.connman", "/"),
+					"net.connman.Manager")
+
+properties = manager.GetProperties()
+
+for key in properties.keys():
+	if key in ["OfflineMode", "SessionMode"]:
+		print "%s" % (key)
+		if properties[key] == dbus.Boolean(1):
+			print "    true"
+		else:
+			print "    false"
+	else:
+		print "%s" % (key)
+		print "    %s" % (properties[key])
+
+print ("Services")
+services = manager.GetServices()
+
+for (path, properties) in services:
+	print "    %s" % (path)
+	for key in properties.keys():
+		if key in ["Available", "Remember", "Default",
+				"Favorite", "Immutable", "AutoConnect",
+					"LoginRequired",
+					"PassphraseRequired"]:
+			if properties[key] == dbus.Boolean(1):
+				val = "true"
+			else:
+				val = "false"
+
+		elif key in ["IPv4", "IPv4.Configuration",
+				"IPv6", "IPv6.Configuration",
+					"Proxy", "Proxy.Configuration",
+						"Ethernet", "Provider"]:
+			val = extract_values(properties[key])
+
+		elif key in ["Nameservers", "Nameservers.Configuration",
+				"Domains", "Domains.Configuration",
+					"Security"]:
+			val = extract_list(properties[key])
+
+		elif key in ["Strength", "Priority"]:
+			val = int(properties[key])
+
+		else:
+			val = str(properties[key])
+
+		print "        %s = %s" % (key, val)
+
+print ("Technologies")
+technologies = manager.GetTechnologies()
+
+for (path, properties) in technologies:
+	print "    %s" % (path)
+	for key in properties.keys():
+
+		if key in ["Connected", "Powered", "Tethering"]:
+			if properties[key] == dbus.Boolean(1):
+				val = "true"
+			else:
+				val = "false"
+		else:
+			val = properties[key]
+
+		print "        %s = %s" % (key, val)
diff --git a/connman/test/test-new-supplicant b/connman/test/test-new-supplicant
new file mode 100755
index 0000000..be230dc
--- /dev/null
+++ b/connman/test/test-new-supplicant
@@ -0,0 +1,14 @@
+#!/usr/bin/python
+
+import dbus
+
+WPA_NAME='fi.w1.wpa_supplicant1'
+WPA_INTF='fi.w1.wpa_supplicant1'
+WPA_PATH='/fi/w1/wpa_supplicant1'
+
+bus = dbus.SystemBus()
+
+dummy = dbus.Interface(bus.get_object(WPA_NAME, WPA_PATH),
+				'org.freedesktop.DBus.Introspectable')
+
+print dummy.Introspect()
diff --git a/connman/test/test-session b/connman/test/test-session
new file mode 100755
index 0000000..2d82fb6
--- /dev/null
+++ b/connman/test/test-session
@@ -0,0 +1,341 @@
+#!/usr/bin/python
+
+import sys
+import gobject
+import string
+
+import dbus
+import dbus.service
+import dbus.mainloop.glib
+
+import glib
+
+import traceback
+
+def extract_list(list):
+	val = "["
+	for i in list:
+		val += " " + str(i)
+	val += " ]"
+	return val
+
+def extract_values(values):
+	val = "{"
+	for key in values.keys():
+		val += " " + key + "="
+		if key in ["PrefixLength"]:
+			val += "%s" % (int(values[key]))
+		else:
+			if key in ["Servers", "Excludes"]:
+				val += extract_list(values[key])
+			else:
+				val += str(values[key])
+	val += " }"
+	return val
+
+class Notification(dbus.service.Object):
+	def __init__(self, bus, app, notify_path):
+		dbus.service.Object.__init__(self)
+		self.app = app
+
+	@dbus.service.method("net.connman.Notification",
+				in_signature='', out_signature='')
+	def Release(self):
+		print "Release %s" % (self._object_path)
+		session_name = self._object_path.split('/')[-1]
+		self.app.release(session_name)
+
+	@dbus.service.method("net.connman.Notification",
+				in_signature='a{sv}', out_signature='')
+	def Update(self, settings):
+		print "Update called at %s" % (self._object_path)
+
+		try:
+			for key in settings.keys():
+				if key in ["IPv4", "IPv6"]:
+					val = extract_values(settings[key])
+				elif key in  ["AllowedBearers"]:
+					val = extract_list(settings[key])
+				else:
+					val = settings[key]
+				print "    %s = %s" % (key, val)
+		except:
+			print "Exception:"
+			traceback.print_exc()
+
+class SessionApplication(dbus.service.Object):
+	def __init__(self, bus, object_path, mainloop):
+		dbus.service.Object.__init__(self, bus, object_path)
+
+		self.manager = None
+		self.mainloop = mainloop
+		self.sessions = {}
+
+		try:
+			bus = dbus.SystemBus()
+			bus.watch_name_owner('net.connman', self.connman_name_owner_changed)
+		except dbus.DBusException:
+			traceback.print_exc()
+
+	def connman_name_owner_changed(self, proxy):
+		try:
+			if proxy:
+				print "connman appeared on D-Bus ", str(proxy)
+
+				bus = dbus.SystemBus()
+				self.manager = dbus.Interface(bus.get_object("net.connman", "/"),
+							      "net.connman.Manager")
+			else:
+				print "connman disappeared on D-Bus"
+				self.manager = None
+				for s in self.sessions.keys():
+					self.sessions[s]['notify'].remove_from_connection()
+					self.sessions[s]['notify'] = None
+
+				self.sessions = {}
+
+		except dbus.DBusException:
+			traceback.print_exc()
+
+	def release(self, session_name):
+		s = self.find_session(session_name)
+		if not s:
+			return
+		if s['session']:
+			s['session'].Destroy()
+			s['session'] = None
+		if s['notify']:
+			s['notify'].remove_from_connection()
+			s['notify'] = None
+		del self.sessions[session_name]
+
+	def type_convert(self, key, value):
+		if key in [ "AllowedBearers" ]:
+			return value
+		elif key in [ "RoamingPolicy", "ConnectionType" ]:
+			if len(value) > 0:
+				return value[0]
+		elif key in [ "Priority", "AvoidHandover",
+			      "StayConnected", "EmergencyCall" ]:
+			flag = str(value[0]).strip().lower()
+			val = flag not in ['false', 'f', 'n', '0']
+			return dbus.Boolean(val)
+		elif key in [ "PeriodicConnect", "IdleTimeout" ]:
+			val = value[0]
+			return dbus.UInt32(val)
+
+		return value
+
+	def find_session(self, session_name):
+		if not session_name in self.sessions.keys():
+			return None
+		return self.sessions[session_name]
+
+	@dbus.service.method("com.example.TestSession",
+				in_signature='', out_signature='')
+	def CreateSession(self, session_name):
+		print "Create session"
+
+		s = self.find_session(session_name)
+		if s and s['session'] :
+			print "Session %s already created-> drop reqest" % (session_name)
+			return
+
+		try:
+			bus = dbus.SystemBus()
+
+			if s == None:
+				s = {}
+			s['notify_path'] = self._object_path + "/" + session_name
+			s['notify'] = Notification(bus, self, s['notify_path'])
+			s['notify'].add_to_connection(bus, s['notify_path'])
+			if not 'settings' in s.keys():
+				s['settings'] = {};
+			s['session_path'] = self.manager.CreateSession(s['settings'], s['notify_path'])
+			print "notify path %s" % (s['notify_path'])
+			print "session path %s" % (s['session_path'])
+			s['session'] = dbus.Interface(bus.get_object("net.connman", s['session_path']),
+						      "net.connman.Session")
+			self.sessions[session_name] = s
+
+		except dbus.DBusException, e:
+			if e.get_dbus_name() in ['net.connman.Error.Failed']:
+				print e.get_dbus_message()
+				return
+			traceback.print_exc()
+
+	@dbus.service.method("com.example.TestSession",
+				in_signature='', out_signature='')
+	def DestroySession(self, session_name):
+		print "Destroy session"
+
+		s = self.find_session(session_name)
+		if s == None or s['session'] == None:
+			print "The session is not running -> drop request"
+			return
+
+		try:
+			self.release(session_name)
+		except dbus.DBusException:
+			traceback.print_exc()
+
+	@dbus.service.method("com.example.TestSession",
+				in_signature='', out_signature='')
+	def Connect(self, session_name):
+		print "Connect session"
+
+		s = self.find_session(session_name)
+		if s == None or s['session'] == None:
+			print "The session is not running -> drop request"
+			return
+
+		try:
+			s['session'].Connect()
+		except dbus.DBusException, e:
+			if e.get_dbus_name() in ['net.connman.Error.Failed']:
+				print e.get_dbus_message()
+				return
+			traceback.print_exc()
+
+	@dbus.service.method("com.example.TestSession",
+				in_signature='', out_signature='')
+	def Disconnect(self, session_name):
+		print "Disconnect session"
+
+		s = self.find_session(session_name)
+		if s == None or s['session'] == None:
+			print "The session is not running -> drop request"
+			return
+
+		try:
+			s['session'].Disconnect()
+		except dbus.DBusException, e:
+			if e.get_dbus_name() in ['net.connman.Error.Failed']:
+				print e.get_dbus_message()
+				return
+			traceback.print_exc()
+
+	@dbus.service.method("com.example.TestSession",
+				in_signature='', out_signature='')
+	def Change(self, session_name, key, value):
+		print "Update session settings"
+
+		s = self.find_session(session_name)
+		if s == None or s['session'] == None:
+			print "The session is not running -> drop request"
+			return
+
+		try:
+			val = self.type_convert(key, value)
+			s['session'].Change(key, val)
+		except dbus.DBusException, e:
+			if e.get_dbus_name() in ['net.connman.Error.Failed']:
+				print e.get_dbus_message()
+				return
+			traceback.print_exc()
+
+	@dbus.service.method("com.example.TestSession",
+				in_signature='', out_signature='')
+	def Configure(self, session_name, key, value):
+		print "Configure session settings"
+		s = self.find_session(session_name)
+		if s == None:
+			s = {}
+			s['notify_path'] = None
+			s['notify'] = None
+			if not 'settings' in s.keys():
+				s['settings'] = {};
+			s['session_path'] = None
+			s['session'] = None
+			self.sessions[session_name] = s
+		if s and s['session']:
+			print "The session is running, use change -> drop request"
+			return
+		val = self.type_convert(key, value)
+		s['settings'][key] = val
+
+def main():
+	if len(sys.argv) < 2:
+		print "Usage: %s <command>" % (sys.argv[0])
+		print ""
+		print "  enable"
+		print "  disable"
+		print "  create <app_path> <session_name>"
+		print "  destroy <app_path> <session_name>"
+		print "  connect <app_path> <session_name>"
+		print "  disconnect <app_path> <session_name>"
+		print "  change <app_path> <session_name> <key> <value>"
+		print "  configure <app_path> <session_name> <key> <value>"
+		print ""
+		print "  run <app_path>"
+		sys.exit(1)
+
+	dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
+
+	if sys.argv[1] == "enable":
+		bus = dbus.SystemBus()
+		manager = dbus.Interface(bus.get_object("net.connman", "/"),
+					 "net.connman.Manager")
+		manager.SetProperty("SessionMode", True)
+		return
+
+	elif sys.argv[1] == "disable":
+		bus = dbus.SystemBus()
+		manager = dbus.Interface(bus.get_object("net.connman", "/"),
+					 "net.connman.Manager")
+		manager.SetProperty("SessionMode", False)
+		return
+
+	if (len(sys.argv) < 3):
+		print "Need test application path"
+		sys.exit(1)
+
+	app_path = sys.argv[2]
+	bus = dbus.SessionBus()
+
+	app_name = "com.example.SessionApplication.%s" % (string.strip(app_path, "/"))
+
+	if sys.argv[1] == "run":
+		name = dbus.service.BusName(app_name, bus)
+		mainloop = gobject.MainLoop()
+
+		app = SessionApplication(bus, app_path, mainloop)
+
+		mainloop.run()
+		return
+
+	app = dbus.Interface(bus.get_object(app_name, app_path),
+			     "com.example.TestSession")
+
+	if sys.argv[1] == "create":
+		app.CreateSession(sys.argv[3])
+
+	elif sys.argv[1] == "destroy":
+		app.DestroySession(sys.argv[3])
+
+	elif sys.argv[1] == "connect":
+		app.Connect(sys.argv[3])
+
+	elif sys.argv[1] == "disconnect":
+		app.Disconnect(sys.argv[3])
+
+	elif sys.argv[1] == "change":
+		if len(sys.argv) < 5:
+			print "Arguments missing"
+			sys.exit(1)
+
+		app.Change(sys.argv[3], sys.argv[4], sys.argv[5:])
+
+	elif sys.argv[1] == "configure":
+		if len(sys.argv) < 5:
+			print "Arguments missing"
+			sys.exit(1)
+
+		app.Configure(sys.argv[3], sys.argv[4], sys.argv[5:])
+
+	else:
+		print "Unknown command '%s'" % sys.argv[1]
+		sys.exit(1)
+
+if __name__ == '__main__':
+	main()
diff --git a/connman/test/vpn-connect b/connman/test/vpn-connect
new file mode 100755
index 0000000..0f8636d
--- /dev/null
+++ b/connman/test/vpn-connect
@@ -0,0 +1,24 @@
+#!/usr/bin/python
+
+import sys
+import dbus
+
+if (len(sys.argv) < 2):
+	print "Usage: %s <VPN connection id>" % (sys.argv[0])
+	sys.exit(1)
+
+bus = dbus.SystemBus()
+
+manager = dbus.Interface(bus.get_object("net.connman.vpn", "/"),
+					"net.connman.vpn.Manager")
+
+connections = manager.GetConnections()
+
+path = "/net/connman/vpn/connection/" + sys.argv[1]
+
+print "Attempting to connect VPN %s" % (path)
+
+connection = dbus.Interface(bus.get_object("net.connman.vpn", path),
+					    "net.connman.vpn.Connection")
+
+connection.Connect()
diff --git a/connman/test/vpn-disconnect b/connman/test/vpn-disconnect
new file mode 100755
index 0000000..d7a49ba
--- /dev/null
+++ b/connman/test/vpn-disconnect
@@ -0,0 +1,24 @@
+#!/usr/bin/python
+
+import sys
+import dbus
+
+if (len(sys.argv) < 1):
+	print "Usage: %s <VPN connection id>" % (sys.argv[0])
+	sys.exit(1)
+
+bus = dbus.SystemBus()
+
+manager = dbus.Interface(bus.get_object("net.connman.vpn", "/"),
+					"net.connman.vpn.Manager")
+
+connections = manager.GetConnections()
+
+path = "/net/connman/vpn/connection/" + sys.argv[1]
+
+print "Attempting to disconnect VPN %s" % (path)
+
+connection = dbus.Interface(bus.get_object("net.connman.vpn", path),
+					    "net.connman.vpn.Connection")
+
+connection.Disconnect()
diff --git a/connman/test/vpn-get b/connman/test/vpn-get
new file mode 100755
index 0000000..f1f760c
--- /dev/null
+++ b/connman/test/vpn-get
@@ -0,0 +1,48 @@
+#!/usr/bin/python
+
+import dbus
+
+def extract_values(values):
+	val = "{"
+	for key in values.keys():
+		val += " " + key + "="
+		if key in ["Servers", "Excludes"]:
+			val += extract_list(values[key])
+		else:
+			val += str(values[key])
+	val += " }"
+	return val
+
+def extract_list(list):
+	val = "["
+	for i in list:
+		if type(i).__name__ == 'Dictionary':
+			val += extract_values(i)
+		elif type(i).__name__ == 'Struct':
+			val += extract_list(i)
+		else:
+			val += " " + str(i)
+	val += "]"
+	return val
+
+bus = dbus.SystemBus()
+
+manager = dbus.Interface(bus.get_object('net.connman.vpn', '/'),
+					'net.connman.vpn.Manager')
+
+for entry in manager.GetConnections():
+	path = entry[0]
+	properties = entry[1]
+
+	print "[ %s ]" % (path)
+
+	for key in properties.keys():
+		if key in ["IPv4", "IPv6" ]:
+			val = extract_values(properties[key])
+		elif key in ["Nameservers","ServerRoutes","UserRoutes"]:
+			val = extract_list(properties[key])
+		else:
+			val = str(properties[key])
+		print "    %s = %s" % (key, val)
+
+	print
diff --git a/connman/test/vpn-property b/connman/test/vpn-property
new file mode 100755
index 0000000..d05f4c7
--- /dev/null
+++ b/connman/test/vpn-property
@@ -0,0 +1,72 @@
+#!/usr/bin/python
+
+import sys
+import dbus
+
+def make_variant(string):
+	return dbus.String(string, variant_level=1)
+
+def extract_values(values):
+	val = "{"
+	for key in values.keys():
+		val += " " + key + "="
+		if key in ["Servers", "Excludes"]:
+			val += extract_list(values[key])
+		else:
+			val += str(values[key])
+	val += " }"
+	return val
+
+def extract_list(list):
+	val = "["
+	for i in list:
+		if type(i).__name__ == 'Dictionary':
+			val += extract_values(i)
+		elif type(i).__name__ == 'Struct':
+			val += extract_list(i)
+		else:
+			val += " " + str(i)
+	val += "]"
+	return val
+
+argc = len(sys.argv)
+
+if (argc < 2):
+	print "Usage: %s <VPN connection id> [<property name>] [<property values>]" % (sys.argv[0])
+	sys.exit(1)
+
+bus = dbus.SystemBus()
+
+manager = dbus.Interface(bus.get_object("net.connman.vpn", "/"),
+					"net.connman.vpn.Manager")
+
+connections = manager.GetConnections()
+
+path = "/net/connman/vpn/connection/" + sys.argv[1]
+
+print "Attempting to connect VPN %s" % (path)
+
+connection = dbus.Interface(bus.get_object("net.connman.vpn", path),
+					    "net.connman.vpn.Connection")
+
+if (argc < 3):
+	properties = connection.GetProperties()
+	for key in properties.keys():
+		if key in ["IPv4", "IPv6" ]:
+			val = extract_values(properties[key])
+		elif key in ["Nameservers","ServerRoutes","UserRoutes"]:
+			val = extract_list(properties[key])
+		else:
+			val = str(properties[key])
+		print "    %s = %s" % (key, val)
+
+elif (argc < 4):
+	try:
+		connection.ClearProperty(sys.argv[2])
+	except dbus.DBusException, error:
+		print "%s: %s" % (error._dbus_error_name, error.message)
+else:
+	try:
+		connection.SetProperty(sys.argv[2], sys.argv[3])
+	except dbus.DBusException, error:
+		print "%s: %s" % (error._dbus_error_name, error.message)
diff --git a/connman/tools/addr-test.c b/connman/tools/addr-test.c
new file mode 100644
index 0000000..273ab02
--- /dev/null
+++ b/connman/tools/addr-test.c
@@ -0,0 +1,66 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2012  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 <stdio.h>
+#include <arpa/inet.h>
+
+static unsigned char netmask2prefixlen(const char *netmask)
+{
+	unsigned char bits = 0;
+	in_addr_t mask = inet_network(netmask);
+	in_addr_t host = ~mask;
+
+	/* a valid netmask must be 2^n - 1 */
+	if ((host & (host + 1)) != 0)
+		return -1;
+
+	for (; mask; mask <<= 1)
+		++bits;
+
+	return bits;
+}
+
+int main(int argc, char *argv[])
+{
+	const char *masks[] = { "255.255.255.255", "255.255.255.0",
+						"255.255.0.0", "255.0.0.0" };
+	struct in_addr addr;
+	int i, len;
+
+	for (i = 0; i < 4; i++) {
+		printf("subnet %-16s  prefixlen %u\n", masks[i],
+						netmask2prefixlen(masks[i]));
+	}
+
+	printf("\n");
+
+	for (i = 0; i < 4; i++) {
+		len = (i + 1) * 8;
+		addr.s_addr = htonl(~(0xfffffffflu >> len));
+		printf("prefixlen %-2u  netmask %s\n", len, inet_ntoa(addr));
+	}
+
+	return 0;
+}
diff --git a/connman/tools/dbus-test.c b/connman/tools/dbus-test.c
new file mode 100644
index 0000000..ece5d19
--- /dev/null
+++ b/connman/tools/dbus-test.c
@@ -0,0 +1,85 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2012  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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <signal.h>
+
+#include <gdbus.h>
+
+#define DBG(fmt, arg...) do { \
+	printf("%s() " fmt "\n", __FUNCTION__ , ## arg); \
+} while (0)
+
+static GMainLoop *main_loop = NULL;
+
+static void sig_term(int sig)
+{
+	g_main_loop_quit(main_loop);
+}
+
+static void disconnect_callback(DBusConnection *conn, void *user_data)
+{
+	printf("D-Bus disconnect\n");
+
+	g_main_loop_quit(main_loop);
+}
+
+int main(int argc, char *argv[])
+{
+	DBusConnection *conn;
+	DBusError err;
+	struct sigaction sa;
+
+	main_loop = g_main_loop_new(NULL, FALSE);
+
+	dbus_error_init(&err);
+
+	conn = g_dbus_setup_bus(DBUS_BUS_SYSTEM, NULL, &err);
+	if (!conn) {
+		if (dbus_error_is_set(&err)) {
+			fprintf(stderr, "%s\n", err.message);
+			dbus_error_free(&err);
+		} else
+			fprintf(stderr, "Can't register with system bus\n");
+		exit(1);
+	}
+
+	g_dbus_set_disconnect_function(conn, disconnect_callback, NULL, NULL);
+
+	memset(&sa, 0, sizeof(sa));
+	sa.sa_handler = sig_term;
+	sigaction(SIGINT, &sa, NULL);
+	sigaction(SIGTERM, &sa, NULL);
+
+	g_main_loop_run(main_loop);
+
+	dbus_connection_unref(conn);
+
+	g_main_loop_unref(main_loop);
+
+	return 0;
+}
diff --git a/connman/tools/dhcp-server-test.c b/connman/tools/dhcp-server-test.c
new file mode 100644
index 0000000..b7d2e54
--- /dev/null
+++ b/connman/tools/dhcp-server-test.c
@@ -0,0 +1,123 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2012  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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <gdhcp/gdhcp.h>
+
+static GMainLoop *main_loop;
+
+static void sig_term(int sig)
+{
+	g_main_loop_quit(main_loop);
+}
+
+static void handle_error(GDHCPServerError error)
+{
+	switch (error) {
+	case G_DHCP_SERVER_ERROR_NONE:
+		printf("dhcp server ok\n");
+		break;
+	case G_DHCP_SERVER_ERROR_INTERFACE_UNAVAILABLE:
+		printf("Interface unavailable\n");
+		break;
+	case G_DHCP_SERVER_ERROR_INTERFACE_IN_USE:
+		printf("Interface in use\n");
+		break;
+	case G_DHCP_SERVER_ERROR_INTERFACE_DOWN:
+		printf("Interface down\n");
+		break;
+	case G_DHCP_SERVER_ERROR_NOMEM:
+		printf("No memory\n");
+		break;
+	case G_DHCP_SERVER_ERROR_INVALID_INDEX:
+		printf("Invalid index\n");
+		break;
+	case G_DHCP_SERVER_ERROR_INVALID_OPTION:
+		printf("Invalid option\n");
+		break;
+	case G_DHCP_SERVER_ERROR_IP_ADDRESS_INVALID:
+		printf("Invalid address\n");
+		break;
+	}
+}
+
+static void dhcp_debug(const char *str, void *data)
+{
+	printf("%s: %s\n", (const char *) data, str);
+}
+
+
+int main(int argc, char *argv[])
+{
+	struct sigaction sa;
+	GDHCPServerError error;
+	GDHCPServer *dhcp_server;
+	int index;
+
+	if (argc < 2) {
+		printf("Usage: dhcp-server-test <interface index>\n");
+		exit(0);
+	}
+
+	index = atoi(argv[1]);
+
+	printf("Create DHCP server for interface %d\n", index);
+
+	dhcp_server = g_dhcp_server_new(G_DHCP_IPV4, index, &error);
+	if (!dhcp_server) {
+		handle_error(error);
+		exit(0);
+	}
+
+	g_dhcp_server_set_debug(dhcp_server, dhcp_debug, "DHCP");
+
+	g_dhcp_server_set_lease_time(dhcp_server, 3600);
+	g_dhcp_server_set_option(dhcp_server, G_DHCP_SUBNET, "255.255.0.0");
+	g_dhcp_server_set_option(dhcp_server, G_DHCP_ROUTER, "192.168.0.2");
+	g_dhcp_server_set_option(dhcp_server, G_DHCP_DNS_SERVER, "192.168.0.3");
+	g_dhcp_server_set_ip_range(dhcp_server, "192.168.0.101",
+							"192.168.0.102");
+	main_loop = g_main_loop_new(NULL, FALSE);
+
+	printf("Start DHCP Server operation\n");
+
+	g_dhcp_server_start(dhcp_server);
+
+	memset(&sa, 0, sizeof(sa));
+	sa.sa_handler = sig_term;
+	sigaction(SIGINT, &sa, NULL);
+	sigaction(SIGTERM, &sa, NULL);
+
+	g_main_loop_run(main_loop);
+
+	g_dhcp_server_unref(dhcp_server);
+
+	g_main_loop_unref(main_loop);
+
+	return 0;
+}
diff --git a/connman/tools/dhcp-test.c b/connman/tools/dhcp-test.c
new file mode 100644
index 0000000..c34e10a
--- /dev/null
+++ b/connman/tools/dhcp-test.c
@@ -0,0 +1,189 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2012  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 <stdio.h>
+#include <errno.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>
+#include <net/route.h>
+#include <net/ethernet.h>
+#include <linux/if_arp.h>
+
+#include <gdhcp/gdhcp.h>
+
+static GTimer *timer;
+
+static GMainLoop *main_loop;
+
+static void sig_term(int sig)
+{
+	g_main_loop_quit(main_loop);
+}
+
+static void print_elapsed(void)
+{
+	gdouble elapsed;
+
+	elapsed = g_timer_elapsed(timer, NULL);
+
+	printf("elapsed: %f seconds\n", elapsed);
+}
+
+static void handle_error(GDHCPClientError error)
+{
+	switch (error) {
+	case G_DHCP_CLIENT_ERROR_NONE:
+		printf("dhcp client ok\n");
+		break;
+	case G_DHCP_CLIENT_ERROR_INTERFACE_UNAVAILABLE:
+		printf("Interface unavailable\n");
+		break;
+	case G_DHCP_CLIENT_ERROR_INTERFACE_IN_USE:
+		printf("Interface in use\n");
+		break;
+	case G_DHCP_CLIENT_ERROR_INTERFACE_DOWN:
+		printf("Interface down\n");
+		break;
+	case G_DHCP_CLIENT_ERROR_NOMEM:
+		printf("No memory\n");
+		break;
+	case G_DHCP_CLIENT_ERROR_INVALID_INDEX:
+		printf("Invalid index\n");
+		break;
+	case G_DHCP_CLIENT_ERROR_INVALID_OPTION:
+		printf("Invalid option\n");
+		break;
+	}
+}
+
+static void no_lease_cb(GDHCPClient *dhcp_client, gpointer user_data)
+{
+	print_elapsed();
+
+	printf("No lease available\n");
+
+	g_main_loop_quit(main_loop);
+}
+
+static void lease_available_cb(GDHCPClient *dhcp_client, gpointer user_data)
+{
+	GList *list, *option_value = NULL;
+	char *address;
+
+	print_elapsed();
+
+	printf("Lease available\n");
+
+	address = g_dhcp_client_get_address(dhcp_client);
+	printf("address %s\n", address);
+	if (!address)
+		return;
+
+	option_value = g_dhcp_client_get_option(dhcp_client, G_DHCP_SUBNET);
+	for (list = option_value; list; list = list->next)
+		printf("sub-mask %s\n", (char *) list->data);
+
+	option_value = g_dhcp_client_get_option(dhcp_client, G_DHCP_DNS_SERVER);
+	for (list = option_value; list; list = list->next)
+		printf("domain-name-servers %s\n", (char *) list->data);
+
+	option_value = g_dhcp_client_get_option(dhcp_client, G_DHCP_DOMAIN_NAME);
+	for (list = option_value; list; list = list->next)
+		printf("domain-name %s\n", (char *) list->data);
+
+	option_value = g_dhcp_client_get_option(dhcp_client, G_DHCP_ROUTER);
+	for (list = option_value; list; list = list->next)
+		printf("routers %s\n", (char *) list->data);
+
+	option_value = g_dhcp_client_get_option(dhcp_client, G_DHCP_HOST_NAME);
+	for (list = option_value; list; list = list->next)
+		printf("hostname %s\n", (char *) list->data);
+}
+
+int main(int argc, char *argv[])
+{
+	struct sigaction sa;
+	GDHCPClientError error;
+	GDHCPClient *dhcp_client;
+	int index;
+
+	if (argc < 2) {
+		printf("Usage: dhcp-test <interface index>\n");
+		exit(0);
+	}
+
+	index = atoi(argv[1]);
+
+	printf("Create DHCP client for interface %d\n", index);
+
+	dhcp_client = g_dhcp_client_new(G_DHCP_IPV4, index, &error);
+	if (!dhcp_client) {
+		handle_error(error);
+		exit(0);
+	}
+
+	g_dhcp_client_set_send(dhcp_client, G_DHCP_HOST_NAME, "<hostname>");
+
+	g_dhcp_client_set_request(dhcp_client, G_DHCP_HOST_NAME);
+	g_dhcp_client_set_request(dhcp_client, G_DHCP_SUBNET);
+	g_dhcp_client_set_request(dhcp_client, G_DHCP_DNS_SERVER);
+	g_dhcp_client_set_request(dhcp_client, G_DHCP_DOMAIN_NAME);
+	g_dhcp_client_set_request(dhcp_client, G_DHCP_NTP_SERVER);
+	g_dhcp_client_set_request(dhcp_client, G_DHCP_ROUTER);
+
+	g_dhcp_client_register_event(dhcp_client,
+			G_DHCP_CLIENT_EVENT_LEASE_AVAILABLE,
+						lease_available_cb, NULL);
+
+	g_dhcp_client_register_event(dhcp_client,
+			G_DHCP_CLIENT_EVENT_NO_LEASE, no_lease_cb, NULL);
+
+	main_loop = g_main_loop_new(NULL, FALSE);
+
+	printf("Start DHCP operation\n");
+
+	timer = g_timer_new();
+
+	g_dhcp_client_start(dhcp_client, NULL);
+
+	memset(&sa, 0, sizeof(sa));
+	sa.sa_handler = sig_term;
+	sigaction(SIGINT, &sa, NULL);
+	sigaction(SIGTERM, &sa, NULL);
+
+	g_main_loop_run(main_loop);
+
+	g_timer_destroy(timer);
+
+	g_dhcp_client_unref(dhcp_client);
+
+	g_main_loop_unref(main_loop);
+
+	return 0;
+}
diff --git a/connman/tools/dnsproxy-test.c b/connman/tools/dnsproxy-test.c
new file mode 100644
index 0000000..551cae9
--- /dev/null
+++ b/connman/tools/dnsproxy-test.c
@@ -0,0 +1,466 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2013  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 <string.h>
+#include <unistd.h>
+#include <arpa/inet.h>
+#include <netinet/in.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netdb.h>
+#include <resolv.h>
+#include <glib.h>
+#include <fcntl.h>
+
+#if 0
+#define DEBUG
+#endif
+#ifdef DEBUG
+#include <stdio.h>
+
+#define LOG(fmt, arg...) do { \
+	fprintf(stdout, "%s:%s() " fmt "\n",   \
+			__FILE__, __func__ , ## arg); \
+} while (0)
+#else
+#define LOG(fmt, arg...)
+#endif
+
+static unsigned char msg[] = {
+	0x00, 0x1c, /* len 28 */
+	0x31, 0x82, /* tran id */
+	0x01, 0x00, /* flags (recursion required) */
+	0x00, 0x01, /* questions (1) */
+	0x00, 0x00, /* answer rr */
+	0x00, 0x00, /* authority rr */
+	0x00, 0x00, /* additional rr */
+	0x06, 0x6c, 0x6f, 0x6c, 0x67, 0x65, 0x30, /* lolge0, just some name */
+	0x03, 0x63, 0x6f, 0x6d, /* com */
+	0x00,       /* null terminator */
+	0x00, 0x01, /* type A */
+	0x00, 0x01, /* class IN */
+};
+
+static unsigned char msg2[] = {
+	0x00, 0x1c, /* len 28 */
+	0x31, 0x83, /* tran id */
+	0x01, 0x00, /* flags (recursion required) */
+	0x00, 0x01, /* questions (1) */
+	0x00, 0x00, /* answer rr */
+	0x00, 0x00, /* authority rr */
+	0x00, 0x00, /* additional rr */
+	0x06, 0x6c, 0x6f, 0x67, 0x6c, 0x67, 0x65, /* loelge */
+	0x03, 0x63, 0x6f, 0x6d, /* com */
+	0x00,       /* null terminator */
+	0x00, 0x01, /* type A */
+	0x00, 0x01, /* class IN */
+
+	0x00, 0x1c, /* len 28 */
+	0x31, 0x84, /* tran id */
+	0x01, 0x00, /* flags (recursion required) */
+	0x00, 0x01, /* questions (1) */
+	0x00, 0x00, /* answer rr */
+	0x00, 0x00, /* authority rr */
+	0x00, 0x00, /* additional rr */
+	0x06, 0x6c, 0x6f, 0x67, 0x6c, 0x67, 0x65, /* loelge */
+	0x03, 0x6e, 0x65, 0x74, /* net */
+	0x00,       /* null terminator */
+	0x00, 0x01, /* type A */
+	0x00, 0x01, /* class IN */
+};
+
+static unsigned char msg_invalid[] = {
+	0x00, 0x1c, /* len 28 */
+	0x31, 0xC0, /* tran id */
+};
+
+static int create_tcp_socket(int family)
+{
+	int sk, err;
+
+	sk = socket(family, SOCK_STREAM, IPPROTO_TCP);
+	if (sk < 0) {
+		err = errno;
+		LOG("Failed to create TCP socket %d/%s", err, strerror(err));
+		return -err;
+	}
+
+	return sk;
+}
+
+static int create_udp_socket(int family)
+{
+	int sk, err;
+
+	sk = socket(family, SOCK_DGRAM, IPPROTO_UDP);
+	if (sk < 0) {
+		err = errno;
+		LOG("Failed to create UDP socket %d/%s", err, strerror(err));
+		return -err;
+	}
+
+	return sk;
+}
+
+static int connect_tcp_socket(char *server)
+{
+	int sk;
+	int err = 0;
+
+	struct addrinfo hints, *rp;
+
+	memset(&hints, 0, sizeof(hints));
+
+	hints.ai_socktype = SOCK_STREAM;
+	hints.ai_family = AF_UNSPEC;
+	hints.ai_flags = AI_NUMERICSERV | AI_NUMERICHOST;
+	getaddrinfo(server, "53", &hints, &rp);
+
+	sk = create_tcp_socket(rp->ai_family);
+	err = sk;
+
+	LOG("sk %d family %d", sk, rp->ai_family);
+
+	if (sk >= 0 && connect(sk, rp->ai_addr, rp->ai_addrlen) < 0) {
+		err = -errno;
+		close(sk);
+		sk = -1;
+
+		fprintf(stderr, "Failed to connect to DNS server at %s "
+				"errno %d/%s\n",
+			server, -err, strerror(-err));
+	}
+
+	if (sk >= 0)
+		fcntl(sk, F_SETFL, O_NONBLOCK);
+
+	freeaddrinfo(rp);
+
+	return err;
+}
+
+static int send_msg(int sk, unsigned char *msg, unsigned int len,
+		int sleep_between)
+{
+	unsigned int i;
+	int err;
+
+	for (i = 0; i < len; i++) {
+		err = write(sk, &msg[i], 1);
+		if (err < 0) {
+			err = -errno;
+			LOG("write failed errno %d/%s", -err, strerror(-err));
+		}
+
+		g_assert_cmpint(err, >=, 0);
+		if (err < 0)
+			return err;
+
+		if (sleep_between)
+			usleep(1000);
+	}
+
+	return 0;
+}
+
+static int connect_udp_socket(char *server, struct sockaddr *sa,
+							socklen_t *sa_len)
+{
+	int sk;
+	int err = 0;
+
+	struct addrinfo hints, *rp;
+
+	memset(&hints, 0, sizeof(hints));
+
+	hints.ai_socktype = SOCK_DGRAM;
+	hints.ai_family = AF_UNSPEC;
+	hints.ai_flags = AI_NUMERICSERV | AI_NUMERICHOST;
+	getaddrinfo(server, "53", &hints, &rp);
+
+	sk = create_udp_socket(rp->ai_family);
+	err = sk;
+
+	LOG("sk %d family %d", sk, rp->ai_family);
+
+	if (sk < 0) {
+		err = -errno;
+		fprintf(stderr, "Failed to connect to DNS server at %s "
+				"errno %d/%s\n",
+			server, -err, strerror(-err));
+	} else {
+		memcpy(sa, rp->ai_addr, *sa_len);
+		*sa_len = rp->ai_addrlen;
+	}
+
+	freeaddrinfo(rp);
+
+	return err;
+}
+
+static int sendto_msg(int sk, struct sockaddr *sa, socklen_t salen,
+		unsigned char *msg, unsigned int len)
+{
+	int err;
+
+	err = sendto(sk, msg, len, MSG_NOSIGNAL, sa, salen);
+	if (err < 0) {
+		err = -errno;
+		LOG("sendto failed errno %d/%s", -err, strerror(-err));
+	}
+
+	g_assert_cmpint(err, >=, 0);
+	if (err < 0)
+		return err;
+
+	return 0;
+}
+
+static unsigned short get_id(void)
+{
+	return random();
+}
+
+static void change_msg(unsigned char *msg, unsigned int tranid,
+		unsigned int host_loc, unsigned char host_count)
+{
+	unsigned short id = get_id();
+
+	msg[tranid] = id >> 8;
+	msg[tranid+1] = id;
+	msg[host_loc] = host_count;
+}
+
+static void change_msg2(unsigned char *msg, unsigned char host_count)
+{
+	change_msg(msg, 2, 20, host_count);
+	change_msg(msg, 32, 50, host_count+1);
+}
+
+static int receive_message(int sk, int timeout, int expected, int *server_closed)
+{
+	int ret, received = 0;
+	unsigned char buf[512];
+
+	while (timeout > 0) {
+		ret = read(sk, buf, sizeof(buf));
+		if (ret > 0) {
+			LOG("received %d bytes from server %d", ret, sk);
+			received += ret;
+			if (received >= expected)
+				break;
+		} else if (ret == 0) {
+			LOG("server %d closed socket", sk);
+			if (server_closed)
+				*server_closed = 1;
+			break;
+		} else {
+			if (errno != EAGAIN && errno != EWOULDBLOCK)
+				break;
+		}
+
+		sleep(1);
+		timeout--;
+	}
+
+	return received;
+}
+
+static int receive_from_message(int sk, struct sockaddr *sa, socklen_t len,
+				int timeout, int expected)
+{
+	int ret, received = 0;
+	unsigned char buf[512];
+
+	fcntl(sk, F_SETFL, O_NONBLOCK);
+
+	while (timeout > 0) {
+		ret = recvfrom(sk, buf, sizeof(buf), 0, sa, &len);
+		if (ret > 0) {
+			LOG("received %d bytes from server %d", ret, sk);
+			received += ret;
+			if (received >= expected)
+				break;
+		} else if (ret < 0) {
+			if (errno != EAGAIN && errno != EWOULDBLOCK)
+				break;
+		}
+
+		sleep(1);
+		timeout--;
+	}
+
+	return received;
+}
+
+static void test_ipv4_udp_msg(void)
+{
+	int sk, received = 0;
+	struct sockaddr_in sa;
+	socklen_t len = sizeof(sa);
+
+	sk = connect_udp_socket("127.0.0.1", (struct sockaddr *)&sa, &len);
+	g_assert_cmpint(sk, >=, 0);
+	change_msg(msg, 2, 20, '1');
+	sendto_msg(sk, (struct sockaddr *)&sa, len, msg, sizeof(msg));
+	received = receive_from_message(sk, (struct sockaddr *)&sa, len,
+					10, sizeof(msg));
+	close(sk);
+
+	g_assert_cmpint(received, >=, sizeof(msg));
+}
+
+static void test_ipv6_udp_msg(void)
+{
+	int sk, received = 0;
+	struct sockaddr_in6 sa;
+	socklen_t len = sizeof(sa);
+
+	sk = connect_udp_socket("::1", (struct sockaddr *)&sa, &len);
+	g_assert_cmpint(sk, >=, 0);
+	change_msg(msg, 2, 20, '1');
+	sendto_msg(sk, (struct sockaddr *)&sa, len, msg, sizeof(msg));
+	received = receive_from_message(sk, (struct sockaddr *)&sa, len,
+					10, sizeof(msg));
+	close(sk);
+
+	g_assert_cmpint(received, >=, sizeof(msg));
+}
+
+static void test_partial_ipv4_tcp_msg(void)
+{
+	int sk, received = 0;
+
+	sk = connect_tcp_socket("127.0.0.1");
+	g_assert_cmpint(sk, >=, 0);
+	change_msg(msg, 2, 20, '1');
+	send_msg(sk, msg, sizeof(msg), 1);
+	received = receive_message(sk, 10, sizeof(msg), NULL);
+	close(sk);
+
+	g_assert_cmpint(received, >=, sizeof(msg));
+}
+
+static void test_partial_ipv6_tcp_msg(void)
+{
+	int sk, received = 0;
+
+	sk = connect_tcp_socket("::1");
+	g_assert_cmpint(sk, >=, 0);
+	change_msg(msg, 2, 20, '2');
+	send_msg(sk, msg, sizeof(msg), 1);
+	received = receive_message(sk, 10, sizeof(msg), NULL);
+	close(sk);
+
+	g_assert_cmpint(received, >=, sizeof(msg));
+}
+
+static void test_multiple_ipv4_tcp_msg(void)
+{
+	int sk, received = 0, server_closed = 0;
+
+	sk = connect_tcp_socket("127.0.0.1");
+	g_assert_cmpint(sk, >=, 0);
+	change_msg2(msg2, '1');
+	send_msg(sk, msg2, sizeof(msg2), 0);
+	received = receive_message(sk, 35, sizeof(msg2), &server_closed);
+	close(sk);
+
+	/* If the final DNS server refuses to serve us, then do not consider
+	 * it an error. This happens very often with unbound.
+	 */
+	if (server_closed == 0)
+		g_assert_cmpint(received, >=, sizeof(msg2));
+}
+
+static void test_multiple_ipv6_tcp_msg(void)
+{
+	int sk, received = 0, server_closed = 0;
+
+	sk = connect_tcp_socket("::1");
+	g_assert_cmpint(sk, >=, 0);
+	change_msg2(msg2, '2');
+	send_msg(sk, msg2, sizeof(msg2), 0);
+	received = receive_message(sk, 35, sizeof(msg2), &server_closed);
+	close(sk);
+
+	if (server_closed == 0)
+		g_assert_cmpint(received, >=, sizeof(msg2));
+}
+
+static void test_failure_tcp_msg(void)
+{
+	int sk, received = 0;
+
+	sk = connect_tcp_socket("127.0.0.1");
+	g_assert_cmpint(sk, >=, 0);
+	send_msg(sk, msg_invalid, sizeof(msg_invalid), 0);
+	received = receive_message(sk, 10, 0, NULL);
+	close(sk);
+
+	g_assert_cmpint(received, ==, 0);
+}
+
+int main(int argc, char *argv[])
+{
+	g_test_init(&argc, &argv, NULL);
+
+	g_test_add_func("/dnsproxy/ipv4 udp msg",
+			test_ipv4_udp_msg);
+
+	g_test_add_func("/dnsproxy/ipv6 udp msg",
+			test_ipv6_udp_msg);
+
+	g_test_add_func("/dnsproxy/failure tcp msg ",
+			test_failure_tcp_msg);
+
+	g_test_add_func("/dnsproxy/partial ipv4 tcp msg",
+			test_partial_ipv4_tcp_msg);
+
+	g_test_add_func("/dnsproxy/partial ipv6 tcp msg",
+			test_partial_ipv6_tcp_msg);
+
+	g_test_add_func("/dnsproxy/partial ipv4 tcp msg from cache",
+			test_partial_ipv4_tcp_msg);
+
+	g_test_add_func("/dnsproxy/partial ipv6 tcp msg from cache",
+			test_partial_ipv6_tcp_msg);
+
+	g_test_add_func("/dnsproxy/multiple ipv4 tcp msg",
+			test_multiple_ipv4_tcp_msg);
+
+	g_test_add_func("/dnsproxy/multiple ipv6 tcp msg",
+			test_multiple_ipv6_tcp_msg);
+
+	g_test_add_func("/dnsproxy/multiple ipv4 tcp msg from cache",
+			test_multiple_ipv4_tcp_msg);
+
+	g_test_add_func("/dnsproxy/multiple ipv6 tcp msg from cache",
+			test_multiple_ipv6_tcp_msg);
+
+	return g_test_run();
+}
diff --git a/connman/tools/iptables-test.c b/connman/tools/iptables-test.c
new file mode 100644
index 0000000..2df53cc
--- /dev/null
+++ b/connman/tools/iptables-test.c
@@ -0,0 +1,161 @@
+/*
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2012  Intel Corporation. All rights reserved.
+ *  Copyright (C) 2013  BMW Car IT GmbH.
+ *
+ *  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
+ *
+ */
+
+#include <getopt.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+
+#include <glib.h>
+
+#include "../src/connman.h"
+
+enum iptables_command {
+	IPTABLES_COMMAND_APPEND,
+	IPTABLES_COMMAND_INSERT,
+	IPTABLES_COMMAND_DELETE,
+	IPTABLES_COMMAND_POLICY,
+	IPTABLES_COMMAND_CHAIN_INSERT,
+	IPTABLES_COMMAND_CHAIN_DELETE,
+	IPTABLES_COMMAND_CHAIN_FLUSH,
+	IPTABLES_COMMAND_DUMP,
+	IPTABLES_COMMAND_UNKNOWN,
+};
+
+int main(int argc, char *argv[])
+{
+	enum iptables_command cmd = IPTABLES_COMMAND_UNKNOWN;
+	char *table = NULL, *chain = NULL, *rule = NULL, *tmp;
+	int err, c, i;
+
+	opterr = 0;
+
+	while ((c = getopt_long(argc, argv,
+				"-A:I:D:P:N:X:F:Lt:", NULL, NULL)) != -1) {
+		switch (c) {
+		case 'A':
+			chain = optarg;
+			cmd = IPTABLES_COMMAND_APPEND;
+			break;
+		case 'I':
+			chain = optarg;
+			cmd = IPTABLES_COMMAND_INSERT;
+			break;
+		case 'D':
+			chain = optarg;
+			cmd = IPTABLES_COMMAND_DELETE;
+			break;
+		case 'P':
+			chain = optarg;
+			/* The policy will be stored in rule. */
+			cmd = IPTABLES_COMMAND_POLICY;
+			break;
+		case 'N':
+			chain = optarg;
+			cmd = IPTABLES_COMMAND_CHAIN_INSERT;
+			break;
+		case 'X':
+			chain = optarg;
+			cmd = IPTABLES_COMMAND_CHAIN_DELETE;
+			break;
+		case 'F':
+			chain = optarg;
+			cmd = IPTABLES_COMMAND_CHAIN_FLUSH;
+			break;
+		case 'L':
+			cmd = IPTABLES_COMMAND_DUMP;
+			break;
+		case 't':
+			table = optarg;
+			break;
+		default:
+			goto out;
+		}
+	}
+
+out:
+	if (!table)
+		table = "filter";
+
+	for (i = optind - 1; i < argc; i++) {
+		if (rule) {
+			tmp = rule;
+			rule = g_strdup_printf("%s %s", rule,  argv[i]);
+			g_free(tmp);
+		} else
+			rule = g_strdup(argv[i]);
+	}
+
+	__connman_iptables_init();
+
+	switch (cmd) {
+	case IPTABLES_COMMAND_APPEND:
+		err = __connman_iptables_append(table, chain, rule);
+		break;
+	case IPTABLES_COMMAND_INSERT:
+		err = __connman_iptables_insert(table, chain, rule);
+		break;
+	case IPTABLES_COMMAND_DELETE:
+		err = __connman_iptables_delete(table, chain, rule);
+		break;
+	case IPTABLES_COMMAND_POLICY:
+		err = __connman_iptables_change_policy(table, chain, rule);
+		break;
+	case IPTABLES_COMMAND_CHAIN_INSERT:
+		err = __connman_iptables_new_chain(table, chain);
+		break;
+	case IPTABLES_COMMAND_CHAIN_DELETE:
+		err = __connman_iptables_delete_chain(table, chain);
+		break;
+	case IPTABLES_COMMAND_CHAIN_FLUSH:
+		err = __connman_iptables_flush_chain(table, chain);
+		break;
+	case IPTABLES_COMMAND_DUMP:
+		__connman_log_init(argv[0], "*", false, false,
+			"iptables-test", "1");
+		err = __connman_iptables_dump(table);
+		break;
+	case IPTABLES_COMMAND_UNKNOWN:
+		printf("Missing command\n");
+		printf("usage: iptables-test [-t table] {-A|-I|-D} chain rule\n");
+		printf("       iptables-test [-t table] {-N|-X|-F} chain\n");
+		printf("       iptables-test [-t table] -L\n");
+		printf("       iptables-test [-t table] -P chain target\n");
+		exit(-EINVAL);
+	}
+
+	if (err < 0) {
+		printf("Error: %s\n", strerror(-err));
+		exit(err);
+	}
+
+	err = __connman_iptables_commit(table);
+	if (err < 0) {
+		printf("Failed to commit changes: %s\n", strerror(-err));
+		exit(err);
+	}
+
+	g_free(rule);
+
+	__connman_iptables_cleanup();
+
+	return 0;
+}
diff --git a/connman/tools/iptables-unit.c b/connman/tools/iptables-unit.c
new file mode 100644
index 0000000..7e427e2
--- /dev/null
+++ b/connman/tools/iptables-unit.c
@@ -0,0 +1,556 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2013-2014  BMW Car IT GmbH.
+ *
+ *  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 <glib.h>
+
+#include "../src/connman.h"
+
+static bool assert_rule(const char *table_name, const char *rule)
+{
+	char *cmd, *output, **lines;
+	GError **error = NULL;
+	int i;
+
+	cmd = g_strdup_printf(IPTABLES_SAVE " -t %s", table_name);
+	g_spawn_command_line_sync(cmd, &output, NULL, NULL, error);
+	g_free(cmd);
+
+	lines = g_strsplit(output, "\n", 0);
+	g_free(output);
+
+	for (i = 0; lines[i]; i++) {
+		DBG("lines[%02d]: %s\n", i, lines[i]);
+		if (g_strcmp0(lines[i], rule) == 0)
+			break;
+	}
+	g_strfreev(lines);
+
+	if (!lines[i])
+		return false;
+
+	return true;
+}
+
+static void assert_rule_exists(const char *table_name, const char *rule)
+{
+	if (g_strcmp0(IPTABLES_SAVE, "") == 0) {
+		DBG("iptables-save is missing, no assertion possible");
+		return;
+	}
+
+	g_assert(assert_rule(table_name, rule));
+}
+
+static void assert_rule_not_exists(const char *table_name, const char *rule)
+{
+	if (g_strcmp0(IPTABLES_SAVE, "") == 0) {
+		DBG("iptables-save is missing, no assertion possible");
+		return;
+	}
+
+	g_assert(!assert_rule(table_name, rule));
+}
+
+static void test_iptables_chain0(void)
+{
+	int err;
+
+	err = __connman_iptables_new_chain("filter", "foo");
+	g_assert(err == 0);
+
+	err = __connman_iptables_commit("filter");
+	g_assert(err == 0);
+
+	assert_rule_exists("filter", ":foo - [0:0]");
+
+	err = __connman_iptables_delete_chain("filter", "foo");
+	g_assert(err == 0);
+
+	err = __connman_iptables_commit("filter");
+	g_assert(err == 0);
+
+	assert_rule_not_exists("filter", ":foo - [0:0]");
+}
+
+static void test_iptables_chain1(void)
+{
+	int err;
+
+	err = __connman_iptables_new_chain("filter", "foo");
+	g_assert(err == 0);
+
+	err = __connman_iptables_commit("filter");
+	g_assert(err == 0);
+
+	err = __connman_iptables_flush_chain("filter", "foo");
+	g_assert(err == 0);
+
+	err = __connman_iptables_commit("filter");
+	g_assert(err == 0);
+
+	err = __connman_iptables_delete_chain("filter", "foo");
+	g_assert(err == 0);
+
+	err = __connman_iptables_commit("filter");
+	g_assert(err == 0);
+}
+
+static void test_iptables_chain2(void)
+{
+	int err;
+
+	err = __connman_iptables_change_policy("filter", "INPUT", "DROP");
+	g_assert(err == 0);
+
+	err = __connman_iptables_commit("filter");
+	g_assert(err == 0);
+
+	err = __connman_iptables_change_policy("filter", "INPUT", "ACCEPT");
+	g_assert(err == 0);
+
+	err = __connman_iptables_commit("filter");
+	g_assert(err == 0);
+}
+
+static void test_iptables_chain3(void)
+{
+	int err;
+
+	err = __connman_iptables_new_chain("filter", "user-chain-0");
+	g_assert(err == 0);
+
+	err = __connman_iptables_commit("filter");
+	g_assert(err == 0);
+
+	assert_rule_exists("filter", ":user-chain-0 - [0:0]");
+
+	err = __connman_iptables_new_chain("filter", "user-chain-1");
+	g_assert(err == 0);
+
+	err = __connman_iptables_commit("filter");
+	g_assert(err == 0);
+
+	assert_rule_exists("filter", ":user-chain-0 - [0:0]");
+	assert_rule_exists("filter", ":user-chain-1 - [0:0]");
+
+	err = __connman_iptables_delete_chain("filter", "user-chain-1");
+	g_assert(err == 0);
+
+	err = __connman_iptables_commit("filter");
+	g_assert(err == 0);
+
+	assert_rule_exists("filter", ":user-chain-0 - [0:0]");
+	assert_rule_not_exists("filter", ":user-chain-1 - [0:0]");
+
+	err = __connman_iptables_delete_chain("filter", "user-chain-0");
+	g_assert(err == 0);
+
+	err = __connman_iptables_commit("filter");
+	g_assert(err == 0);
+
+	assert_rule_not_exists("filter", ":user-chain-0 - [0:0]");
+}
+
+static void test_iptables_rule0(void)
+{
+	int err;
+
+	/* Test simple appending and removing a rule */
+
+	err = __connman_iptables_append("filter", "INPUT",
+					"-m mark --mark 1 -j LOG");
+	g_assert(err == 0);
+
+	err = __connman_iptables_commit("filter");
+	g_assert(err == 0);
+
+	assert_rule_exists("filter",
+				"-A INPUT -m mark --mark 0x1 -j LOG");
+
+	err = __connman_iptables_delete("filter", "INPUT",
+					"-m mark --mark 1 -j LOG");
+	g_assert(err == 0);
+
+	err = __connman_iptables_commit("filter");
+	g_assert(err == 0);
+
+	assert_rule_not_exists("filter",
+				"-A INPUT -m mark --mark 0x1 -j LOG");
+}
+
+static void test_iptables_rule1(void)
+{
+	int err;
+
+	/* Test if we can do NAT stuff */
+
+	err = __connman_iptables_append("nat", "POSTROUTING",
+				"-s 10.10.1.0/24 -o eth0 -j MASQUERADE");
+
+	err = __connman_iptables_commit("nat");
+	g_assert(err == 0);
+
+	assert_rule_exists("nat",
+		"-A POSTROUTING -s 10.10.1.0/24 -o eth0 -j MASQUERADE");
+
+	err = __connman_iptables_delete("nat", "POSTROUTING",
+				"-s 10.10.1.0/24 -o eth0 -j MASQUERADE");
+
+	err = __connman_iptables_commit("nat");
+	g_assert(err == 0);
+
+	assert_rule_not_exists("nat",
+		"-A POSTROUTING -s 10.10.1.0/24 -o eth0 -j MASQUERADE");
+}
+
+static void test_iptables_rule2(void)
+{
+	int err;
+
+	/* Test if the right rule is removed */
+
+	err = __connman_iptables_append("filter", "INPUT",
+					"-m mark --mark 1 -j LOG");
+	g_assert(err == 0);
+
+	err = __connman_iptables_commit("filter");
+	g_assert(err == 0);
+
+	assert_rule_exists("filter",
+				"-A INPUT -m mark --mark 0x1 -j LOG");
+
+	err = __connman_iptables_append("filter", "INPUT",
+					"-m mark --mark 2 -j LOG");
+	g_assert(err == 0);
+
+	err = __connman_iptables_commit("filter");
+	g_assert(err == 0);
+
+	assert_rule_exists("filter",
+				"-A INPUT -m mark --mark 0x1 -j LOG");
+	assert_rule_exists("filter",
+				"-A INPUT -m mark --mark 0x2 -j LOG");
+
+	err = __connman_iptables_delete("filter", "INPUT",
+					"-m mark --mark 2 -j LOG");
+	g_assert(err == 0);
+
+	err = __connman_iptables_commit("filter");
+	g_assert(err == 0);
+
+	assert_rule_exists("filter",
+				"-A INPUT -m mark --mark 0x1 -j LOG");
+	assert_rule_not_exists("filter",
+				"-A INPUT -m mark --mark 0x2 -j LOG");
+
+	err = __connman_iptables_delete("filter", "INPUT",
+					"-m mark --mark 1 -j LOG");
+	g_assert(err == 0);
+
+	err = __connman_iptables_commit("filter");
+	g_assert(err == 0);
+
+	assert_rule_not_exists("filter",
+				"-A INPUT -m mark --mark 0x1 -j LOG");
+}
+
+static void test_iptables_target0(void)
+{
+	int err;
+
+	/* Test if 'fallthrough' targets work */
+
+	err = __connman_iptables_append("filter", "INPUT",
+					"-m mark --mark 1");
+	g_assert(err == 0);
+
+	err = __connman_iptables_append("filter", "INPUT",
+					"-m mark --mark 2");
+	g_assert(err == 0);
+
+	err = __connman_iptables_commit("filter");
+	g_assert(err == 0);
+
+	assert_rule_exists("filter", "-A INPUT -m mark --mark 0x1");
+	assert_rule_exists("filter", "-A INPUT -m mark --mark 0x2");
+
+	err = __connman_iptables_delete("filter", "INPUT",
+					"-m mark --mark 1");
+	g_assert(err == 0);
+
+	err = __connman_iptables_commit("filter");
+	g_assert(err == 0);
+
+	err = __connman_iptables_delete("filter", "INPUT",
+					"-m mark --mark 2");
+	g_assert(err == 0);
+
+	err = __connman_iptables_commit("filter");
+	g_assert(err == 0);
+
+	assert_rule_not_exists("filter", "-A INPUT -m mark --mark 0x1");
+	assert_rule_not_exists("filter", "-A INPUT -m mark --mark 0x2");
+}
+
+struct connman_notifier *nat_notifier;
+
+struct connman_service {
+	char *dummy;
+};
+
+char *connman_service_get_interface(struct connman_service *service)
+{
+	return "eth0";
+}
+
+int connman_notifier_register(struct connman_notifier *notifier)
+{
+	nat_notifier = notifier;
+
+	return 0;
+}
+
+void connman_notifier_unregister(struct connman_notifier *notifier)
+{
+	nat_notifier = NULL;
+}
+
+static void test_nat_basic0(void)
+{
+	int err;
+
+	err = __connman_nat_enable("bridge", "192.168.2.1", 24);
+	g_assert(err == 0);
+
+	/* test that table is empty */
+	err = __connman_iptables_append("nat", "POSTROUTING",
+					"-s 192.168.2.1/24 -o eth0 -j MASQUERADE");
+	g_assert(err == 0);
+
+	err = __connman_iptables_commit("nat");
+	g_assert(err == 0);
+
+	assert_rule_exists("nat",
+		"-A POSTROUTING -s 192.168.2.0/24 -o eth0 -j MASQUERADE");
+
+	err = __connman_iptables_delete("nat", "POSTROUTING",
+					"-s 192.168.2.1/24 -o eth0 -j MASQUERADE");
+	g_assert(err == 0);
+
+	err = __connman_iptables_commit("nat");
+	g_assert(err == 0);
+
+	assert_rule_not_exists("nat",
+		"-A POSTROUTING -s 192.168.2.0/24 -o eth0 -j MASQUERADE");
+
+	__connman_nat_disable("bridge");
+}
+
+static void test_nat_basic1(void)
+{
+	struct connman_service *service;
+	int err;
+
+	service = g_try_new0(struct connman_service, 1);
+	g_assert(service);
+
+	nat_notifier->default_changed(service);
+
+	err = __connman_nat_enable("bridge", "192.168.2.1", 24);
+	g_assert(err == 0);
+
+	/* test that table is not empty */
+	err = __connman_iptables_append("nat", "POSTROUTING",
+					"-s 192.168.2.1/24 -o eth0 -j MASQUERADE");
+	g_assert(err == 0);
+
+	err = __connman_iptables_commit("nat");
+	g_assert(err == 0);
+
+	__connman_nat_disable("bridge");
+
+	/* test that table is empty again */
+	err = __connman_iptables_delete("nat", "POSTROUTING",
+					"-s 192.168.2.1/24 -o eth0 -j MASQUERADE");
+	g_assert(err == 0);
+
+	err = __connman_iptables_commit("nat");
+	g_assert(err == 0);
+
+	g_free(service);
+}
+
+static void test_firewall_basic0(void)
+{
+	struct firewall_context *ctx;
+	int err;
+
+	ctx = __connman_firewall_create();
+	g_assert(ctx);
+
+	err = __connman_firewall_add_rule(ctx, "filter", "INPUT",
+					"-m mark --mark 999 -j LOG");
+	g_assert(err == 0);
+
+	err = __connman_firewall_enable(ctx);
+	g_assert(err == 0);
+
+	assert_rule_exists("filter", ":connman-INPUT - [0:0]");
+	assert_rule_exists("filter", "-A INPUT -j connman-INPUT");
+	assert_rule_exists("filter", "-A connman-INPUT -m mark --mark 0x3e7 -j LOG");
+
+	err = __connman_firewall_disable(ctx);
+	g_assert(err == 0);
+
+	assert_rule_not_exists("filter", ":connman-INPUT - [0:0]");
+	assert_rule_not_exists("filter", "-A INPUT -j connman-INPUT");
+	assert_rule_not_exists("filter", "-A connman-INPUT -m mark --mark 0x3e7 -j LOG");
+
+	__connman_firewall_destroy(ctx);
+}
+
+static void test_firewall_basic1(void)
+{
+	struct firewall_context *ctx;
+	int err;
+
+	ctx = __connman_firewall_create();
+	g_assert(ctx);
+
+	err = __connman_firewall_add_rule(ctx, "filter", "INPUT",
+					"-m mark --mark 999 -j LOG");
+	g_assert(err == 0);
+
+	err = __connman_firewall_add_rule(ctx, "filter", "OUTPUT",
+					"-m mark --mark 999 -j LOG");
+	g_assert(err == 0);
+
+	err = __connman_firewall_enable(ctx);
+	g_assert(err == 0);
+
+	err = __connman_firewall_disable(ctx);
+	g_assert(err == 0);
+
+	__connman_firewall_destroy(ctx);
+}
+
+static void test_firewall_basic2(void)
+{
+	struct firewall_context *ctx;
+	int err;
+
+	ctx = __connman_firewall_create();
+	g_assert(ctx);
+
+	err = __connman_firewall_add_rule(ctx, "mangle", "INPUT",
+					"-j CONNMARK --restore-mark");
+	g_assert(err == 0);
+
+	err = __connman_firewall_add_rule(ctx, "mangle", "POSTROUTING",
+					"-j CONNMARK --save-mark");
+	g_assert(err == 0);
+
+	err = __connman_firewall_enable(ctx);
+	g_assert(err == 0);
+
+	err = __connman_firewall_disable(ctx);
+	g_assert(err == 0);
+
+	__connman_firewall_destroy(ctx);
+}
+
+static gchar *option_debug = NULL;
+
+static bool parse_debug(const char *key, const char *value,
+					gpointer user_data, GError **error)
+{
+	if (value)
+		option_debug = g_strdup(value);
+	else
+		option_debug = g_strdup("*");
+
+	return true;
+}
+
+static GOptionEntry options[] = {
+	{ "debug", 'd', G_OPTION_FLAG_OPTIONAL_ARG,
+				G_OPTION_ARG_CALLBACK, parse_debug,
+				"Specify debug options to enable", "DEBUG" },
+	{ NULL },
+};
+
+int main(int argc, char *argv[])
+{
+	GOptionContext *context;
+	GError *error = NULL;
+	int err;
+
+	g_test_init(&argc, &argv, NULL);
+
+	context = g_option_context_new(NULL);
+	g_option_context_add_main_entries(context, options, NULL);
+
+	if (!g_option_context_parse(context, &argc, &argv, &error)) {
+		if (error) {
+			g_printerr("%s\n", error->message);
+			g_error_free(error);
+		} else
+			g_printerr("An unknown error occurred\n");
+		return 1;
+	}
+
+	g_option_context_free(context);
+
+	__connman_log_init(argv[0], option_debug, false, false,
+			"Unit Tests Connection Manager", VERSION);
+
+	__connman_iptables_init();
+	__connman_firewall_init();
+	__connman_nat_init();
+
+	g_test_add_func("/iptables/chain0", test_iptables_chain0);
+	g_test_add_func("/iptables/chain1", test_iptables_chain1);
+	g_test_add_func("/iptables/chain2", test_iptables_chain2);
+	g_test_add_func("/iptables/chain3", test_iptables_chain3);
+	g_test_add_func("/iptables/rule0",  test_iptables_rule0);
+	g_test_add_func("/iptables/rule1",  test_iptables_rule1);
+	g_test_add_func("/iptables/rule2",  test_iptables_rule2);
+	g_test_add_func("/iptables/target0", test_iptables_target0);
+	g_test_add_func("/nat/basic0", test_nat_basic0);
+	g_test_add_func("/nat/basic1", test_nat_basic1);
+	g_test_add_func("/firewall/basic0", test_firewall_basic0);
+	g_test_add_func("/firewall/basic1", test_firewall_basic1);
+	g_test_add_func("/firewall/basic2", test_firewall_basic2);
+
+	err = g_test_run();
+
+	__connman_nat_cleanup();
+	__connman_firewall_cleanup();
+	__connman_iptables_cleanup();
+
+	g_free(option_debug);
+
+	return err;
+}
diff --git a/connman/tools/manager-api.c b/connman/tools/manager-api.c
new file mode 100644
index 0000000..e082962
--- /dev/null
+++ b/connman/tools/manager-api.c
@@ -0,0 +1,264 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2011-2014  BMW Car IT GmbH.
+ *
+ *  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 <stdio.h>
+
+#include "session-test.h"
+
+static DBusMessage *set_property(DBusConnection *connection,
+				const char *property, int type, void *value)
+{
+	DBusMessage *message, *reply;
+	DBusError error;
+	DBusMessageIter iter;
+
+	message = dbus_message_new_method_call(CONNMAN_SERVICE,
+						CONNMAN_MANAGER_PATH,
+						CONNMAN_MANAGER_INTERFACE,
+						"SetProperty");
+	if (!message)
+		return NULL;
+
+	dbus_message_iter_init_append(message, &iter);
+	connman_dbus_property_append_basic(&iter, property, type, value);
+
+	dbus_error_init(&error);
+
+	reply = dbus_connection_send_with_reply_and_block(connection,
+							message, -1, &error);
+	if (!reply) {
+		if (dbus_error_is_set(&error)) {
+			LOG("%s", error.message);
+			dbus_error_free(&error);
+		} else {
+			LOG("Failed to get properties");
+		}
+		dbus_message_unref(message);
+		return NULL;
+	}
+
+	dbus_message_unref(message);
+
+	return reply;
+}
+
+DBusMessage *manager_get_services(DBusConnection *connection)
+{
+	DBusMessage *message, *reply;
+	DBusError error;
+
+	message = dbus_message_new_method_call(CONNMAN_SERVICE,
+						CONNMAN_MANAGER_PATH,
+						CONNMAN_MANAGER_INTERFACE,
+							"GetServices");
+	if (!message)
+		return NULL;
+
+	dbus_error_init(&error);
+
+	reply = dbus_connection_send_with_reply_and_block(connection,
+							message, -1, &error);
+	if (!reply) {
+		if (dbus_error_is_set(&error)) {
+			LOG("%s", error.message);
+			dbus_error_free(&error);
+		} else {
+			LOG("Failed to get properties");
+		}
+		dbus_message_unref(message);
+		return NULL;
+	}
+
+	dbus_message_unref(message);
+
+	return reply;
+}
+
+DBusMessage *manager_get_properties(DBusConnection *connection)
+{
+	DBusMessage *message, *reply;
+	DBusError error;
+
+	message = dbus_message_new_method_call(CONNMAN_SERVICE,
+						CONNMAN_MANAGER_PATH,
+						CONNMAN_MANAGER_INTERFACE,
+							"GetProperties");
+	if (!message)
+		return NULL;
+
+	dbus_error_init(&error);
+
+	reply = dbus_connection_send_with_reply_and_block(connection,
+							message, -1, &error);
+	if (!reply) {
+		if (dbus_error_is_set(&error)) {
+			LOG("%s", error.message);
+			dbus_error_free(&error);
+		} else {
+			LOG("%s", error.message);
+		}
+		dbus_message_unref(message);
+		return NULL;
+	}
+
+	dbus_message_unref(message);
+
+	return reply;
+}
+
+DBusMessage *manager_create_session(DBusConnection *connection,
+					struct test_session_info *info,
+					const char *notifier_path)
+{
+	DBusMessage *message, *reply;
+	DBusError error;
+	DBusMessageIter array, dict;
+
+	message = dbus_message_new_method_call(CONNMAN_SERVICE,
+						CONNMAN_MANAGER_PATH,
+						CONNMAN_MANAGER_INTERFACE,
+							"CreateSession");
+	if (!message)
+		return NULL;
+
+	dbus_error_init(&error);
+
+	dbus_message_iter_init_append(message, &array);
+
+	connman_dbus_dict_open(&array, &dict);
+
+	session_append_settings(&dict, info);
+
+	connman_dbus_dict_close(&array, &dict);
+
+	dbus_message_iter_append_basic(&array, DBUS_TYPE_OBJECT_PATH,
+				&notifier_path);
+
+	reply = dbus_connection_send_with_reply_and_block(connection,
+							message, -1, &error);
+	if (!reply) {
+		if (dbus_error_is_set(&error)) {
+			LOG("%s", error.message);
+			dbus_error_free(&error);
+		} else {
+			LOG("Failed to get properties");
+		}
+		dbus_message_unref(message);
+		return NULL;
+	}
+
+	dbus_message_unref(message);
+
+	return reply;
+}
+
+DBusMessage *manager_destroy_session(DBusConnection *connection,
+					const char *notifier_path)
+{
+	DBusMessage *message, *reply;
+	DBusError error;
+	DBusMessageIter array;
+
+	message = dbus_message_new_method_call(CONNMAN_SERVICE,
+						CONNMAN_MANAGER_PATH,
+						CONNMAN_MANAGER_INTERFACE,
+							"DestroySession");
+	if (!message)
+		return NULL;
+
+	dbus_error_init(&error);
+
+	dbus_message_iter_init_append(message, &array);
+
+	dbus_message_iter_append_basic(&array, DBUS_TYPE_OBJECT_PATH,
+				&notifier_path);
+
+	reply = dbus_connection_send_with_reply_and_block(connection,
+							message, -1, &error);
+	if (!reply) {
+		if (dbus_error_is_set(&error)) {
+			LOG("%s", error.message);
+			dbus_error_free(&error);
+		} else {
+			LOG("%s", error.message);
+		}
+		dbus_message_unref(message);
+		return NULL;
+	}
+
+	dbus_message_unref(message);
+
+	return reply;
+}
+
+DBusMessage *manager_set_session_mode(DBusConnection *connection,
+					bool enable)
+{
+	dbus_bool_t val = enable;
+
+	return set_property(connection, "SessionMode",
+				DBUS_TYPE_BOOLEAN, &val);
+}
+
+int manager_parse_properties(DBusMessage *msg,
+				struct test_manager *manager)
+{
+	DBusMessageIter iter, array;
+
+	dbus_message_iter_init(msg, &iter);
+	dbus_message_iter_recurse(&iter, &array);
+
+	while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_DICT_ENTRY) {
+		DBusMessageIter entry, value;
+		const char *key;
+
+		dbus_message_iter_recurse(&array, &entry);
+		dbus_message_iter_get_basic(&entry, &key);
+
+		dbus_message_iter_next(&entry);
+		dbus_message_iter_recurse(&entry, &value);
+
+		switch (dbus_message_iter_get_arg_type(&value)) {
+		case DBUS_TYPE_STRING:
+			if (g_str_equal(key, "State")) {
+				const char *val;
+				dbus_message_iter_get_basic(&value, &val);
+
+				if (manager->state)
+					g_free(manager->state);
+
+				LOG("State %s", val);
+
+				manager->state = g_strdup(val);
+			}
+			break;
+		default:
+			break;
+		}
+		dbus_message_iter_next(&array);
+	}
+
+	return 0;
+}
diff --git a/connman/tools/netlink-test.c b/connman/tools/netlink-test.c
new file mode 100644
index 0000000..221e349
--- /dev/null
+++ b/connman/tools/netlink-test.c
@@ -0,0 +1,123 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2013-2014  BMW Car IT GmbH.
+ *
+ *  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 <sys/socket.h>
+#include <linux/netlink.h>
+#include <linux/rtnetlink.h>
+#include <linux/genetlink.h>
+#include <linux/netfilter/nfnetlink.h>
+#include <net/if.h>
+
+#include <string.h>
+#include <stdio.h>
+#include <inttypes.h>
+#include <errno.h>
+
+#include <glib.h>
+
+#include "../src/shared/netlink.h"
+
+#define NFGEN_DATA(nlh) ((void *)((char *)(nlh) +			\
+				NLMSG_ALIGN(sizeof(struct nfgenmsg))))
+#define NLA_DATA(nla)  ((void *)((char*)(nla) + NLA_HDRLEN))
+#define NLA_OK(nla,len) ((len) >= (int)sizeof(struct nlattr) &&		\
+				(nla)->nla_len >= sizeof(struct nlattr) && \
+				(nla)->nla_len <= (len))
+#define NLA_NEXT(nla,attrlen) ((attrlen) -= NLA_ALIGN((nla)->nla_len),	\
+				(struct nlattr*)(((char*)(nla)) +       \
+						NLA_ALIGN((nla)->nla_len)))
+
+static GMainLoop *mainloop;
+
+static void do_debug(const char *str, void *user_data)
+{
+	const char *prefix = user_data;
+
+	printf("%s%s\n", prefix, str);
+}
+
+static void getlink_callback(unsigned int error, uint16_t type, const void *data,
+						uint32_t len, void *user_data)
+{
+	const struct ifinfomsg *ifi = data;
+	struct rtattr *rta;
+	int bytes;
+	char ifname[IF_NAMESIZE];
+	uint32_t index, flags;
+
+	g_assert_cmpuint(error, ==, 0);
+
+	bytes = len - NLMSG_ALIGN(sizeof(struct ifinfomsg));
+
+	memset(ifname, 0, sizeof(ifname));
+
+	index = ifi->ifi_index;
+	flags = ifi->ifi_flags;
+
+	for (rta = IFLA_RTA(ifi); RTA_OK(rta, bytes);
+					rta = RTA_NEXT(rta, bytes)) {
+		switch (rta->rta_type) {
+		case IFLA_IFNAME:
+			if (RTA_PAYLOAD(rta) <= IF_NAMESIZE)
+				strcpy(ifname, RTA_DATA(rta));
+			break;
+		}
+	}
+
+	printf("index=%d flags=0x%08x name=%s\n", index, flags, ifname);
+
+	g_main_loop_quit(mainloop);
+}
+
+static void test_case_1(void)
+{
+	struct netlink_info *netlink;
+	struct ifinfomsg msg;
+
+	netlink = netlink_new(NETLINK_ROUTE);
+
+	printf("\n");
+	netlink_set_debug(netlink, do_debug, "[NETLINK] ", NULL);
+
+	memset(&msg, 0, sizeof(msg));
+
+	netlink_send(netlink, RTM_GETLINK, NLM_F_DUMP, &msg, sizeof(msg),
+						getlink_callback, NULL, NULL);
+
+	mainloop = g_main_loop_new(NULL, FALSE);
+	g_main_loop_run(mainloop);
+	g_main_loop_unref(mainloop);
+
+	netlink_destroy(netlink);
+}
+
+int main(int argc, char *argv[])
+{
+	g_test_init(&argc, &argv, NULL);
+
+	g_test_add_func("/netlink/Test case 1", test_case_1);
+
+	return g_test_run();
+}
diff --git a/connman/tools/polkit-test.c b/connman/tools/polkit-test.c
new file mode 100644
index 0000000..ea1d24a
--- /dev/null
+++ b/connman/tools/polkit-test.c
@@ -0,0 +1,184 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2012  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 <stdio.h>
+#include <errno.h>
+
+#include <string.h>
+#include <signal.h>
+
+#include <dbus/dbus.h>
+
+static volatile sig_atomic_t __io_terminate = 0;
+
+static void sig_term(int sig)
+{
+	__io_terminate = 1;
+}
+
+static void add_dict_with_string_value(DBusMessageIter *iter,
+					const char *key, const char *str)
+{
+	DBusMessageIter dict, entry, value;
+
+	dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY,
+			DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+			DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
+			DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict);
+	dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY,
+								NULL, &entry);
+
+	dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
+
+	dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT,
+					DBUS_TYPE_STRING_AS_STRING, &value);
+	dbus_message_iter_append_basic(&value, DBUS_TYPE_STRING, &str);
+	dbus_message_iter_close_container(&entry, &value);
+
+	dbus_message_iter_close_container(&dict, &entry);
+	dbus_message_iter_close_container(iter, &dict);
+}
+
+static void add_empty_string_dict(DBusMessageIter *iter)
+{
+	DBusMessageIter dict;
+
+	dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY,
+			DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+			DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_STRING_AS_STRING
+			DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict);
+
+	dbus_message_iter_close_container(iter, &dict);
+}
+
+static void add_arguments(DBusConnection *conn, DBusMessageIter *iter)
+{
+	const char *busname = dbus_bus_get_unique_name(conn);
+	const char *kind = "system-bus-name";
+	const char *action = "org.freedesktop.policykit.exec";
+	const char *cancel = "";
+	dbus_uint32_t flags = 0x00000001;
+	DBusMessageIter subject;
+
+	dbus_message_iter_open_container(iter, DBUS_TYPE_STRUCT,
+							NULL, &subject);
+	dbus_message_iter_append_basic(&subject, DBUS_TYPE_STRING, &kind);
+	add_dict_with_string_value(&subject, "name", busname);
+	dbus_message_iter_close_container(iter, &subject);
+
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &action);
+	add_empty_string_dict(iter);
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT32, &flags);
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &cancel);
+}
+
+static void print_arguments(DBusMessageIter *iter)
+{
+	DBusMessageIter result;
+	dbus_bool_t authorized, challenge;
+
+	dbus_message_iter_recurse(iter, &result);
+
+	dbus_message_iter_get_basic(&result, &authorized);
+	dbus_message_iter_get_basic(&result, &challenge);
+
+	printf("Authorized %d (Challenge %d)\n", authorized, challenge);
+}
+
+#define AUTHORITY_DBUS	"org.freedesktop.PolicyKit1"
+#define AUTHORITY_INTF	"org.freedesktop.PolicyKit1.Authority"
+#define AUTHORITY_PATH	"/org/freedesktop/PolicyKit1/Authority"
+
+static int check_authorization(DBusConnection *conn)
+{
+	DBusMessage *msg, *reply;
+	DBusMessageIter iter;
+	DBusError err;
+
+	msg = dbus_message_new_method_call(AUTHORITY_DBUS, AUTHORITY_PATH,
+				AUTHORITY_INTF, "CheckAuthorization");
+	if (!msg) {
+		fprintf(stderr, "Can't allocate new method call\n");
+		return -ENOMEM;
+	}
+
+	dbus_message_iter_init_append(msg, &iter);
+	add_arguments(conn, &iter);
+
+	dbus_error_init(&err);
+
+	reply = dbus_connection_send_with_reply_and_block(conn, msg, -1, &err);
+
+	dbus_message_unref(msg);
+
+	if (!reply) {
+		if (dbus_error_is_set(&err)) {
+			fprintf(stderr, "%s\n", err.message);
+			dbus_error_free(&err);
+		} else
+			fprintf(stderr, "Can't check authorization\n");
+		return -EIO;
+	}
+
+	if (dbus_message_has_signature(reply, "(bba{ss})")) {
+		dbus_message_iter_init(reply, &iter);
+		print_arguments(&iter);
+	}
+
+	dbus_message_unref(reply);
+
+	return 0;
+}
+
+int main(int argc, char *argv[])
+{
+	DBusConnection *conn;
+	struct sigaction sa;
+
+	conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
+	if (!conn) {
+		fprintf(stderr, "Can't get on system bus");
+		return 1;
+	}
+
+	check_authorization(conn);
+
+	memset(&sa, 0, sizeof(sa));
+	sa.sa_flags   = SA_NOCLDSTOP;
+	sa.sa_handler = sig_term;
+	sigaction(SIGTERM, &sa, NULL);
+	sigaction(SIGINT,  &sa, NULL);
+
+#if 0
+	while (!__io_terminate) {
+		if (dbus_connection_read_write_dispatch(conn, 500) == FALSE)
+			break;
+	}
+#endif
+
+	dbus_connection_unref(conn);
+
+	return 0;
+}
diff --git a/connman/tools/private-network-test.c b/connman/tools/private-network-test.c
new file mode 100644
index 0000000..3dd115b
--- /dev/null
+++ b/connman/tools/private-network-test.c
@@ -0,0 +1,268 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2012  Intel Corporation. All rights reserved.
+ *  Copyright (C) 2011	ProFUSION embedded systems
+ *
+ *  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
+ *
+ */
+
+#define CONNMAN_SERVICE "net.connman"
+
+#define MANAGER_PATH	"/"
+#define MANAGER_INTERFACE CONNMAN_SERVICE ".Manager"
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <gdbus.h>
+#include <stdlib.h>
+#include <string.h>
+#include <signal.h>
+#include <sys/poll.h>
+#include <sys/signalfd.h>
+#include <unistd.h>
+
+#include <dbus/dbus.h>
+
+#ifndef DBUS_TYPE_UNIX_FD
+#define DBUS_TYPE_UNIX_FD -1
+#endif
+
+static int release_private_network(DBusConnection *conn)
+{
+	DBusMessage *msg, *reply;
+	DBusError error;
+
+	msg = dbus_message_new_method_call(CONNMAN_SERVICE, MANAGER_PATH,
+				MANAGER_INTERFACE, "ReleasePrivateNetwork");
+
+	dbus_error_init(&error);
+
+	printf("Releasing private-network...\n");
+	reply = dbus_connection_send_with_reply_and_block(conn, msg, -1,
+									&error);
+	dbus_message_unref(msg);
+
+	if (!reply) {
+		if (dbus_error_is_set(&error)) {
+			fprintf(stderr, "1. %s\n", error.message);
+			dbus_error_free(&error);
+		} else {
+			fprintf(stderr, "Release() failed");
+		}
+
+		return -1;
+	}
+
+	return 0;
+}
+
+static void request_private_network(DBusConnection *conn, int *out_fd,
+					char **out_server_ip,
+					char **out_peer_ip,
+					char **out_primary_dns,
+					char **out_secondary_dns)
+{
+	DBusMessageIter array, dict, entry;
+	DBusMessage *msg, *reply;
+	DBusError error;
+
+	msg = dbus_message_new_method_call(CONNMAN_SERVICE, MANAGER_PATH,
+				MANAGER_INTERFACE, "RequestPrivateNetwork");
+
+	dbus_error_init(&error);
+
+	printf("Requesting private-network...\n");
+	reply = dbus_connection_send_with_reply_and_block(conn, msg, -1,
+									&error);
+	dbus_message_unref(msg);
+
+	if (!reply) {
+		if (dbus_error_is_set(&error)) {
+			fprintf(stderr, "1. %s\n", error.message);
+			dbus_error_free(&error);
+		} else {
+			fprintf(stderr, "Request() failed");
+		}
+		return;
+	}
+
+	if (!dbus_message_iter_init(reply, &array))
+		goto done;
+
+	if (dbus_message_iter_get_arg_type(&array) != DBUS_TYPE_UNIX_FD)
+		goto done;
+
+	dbus_message_iter_get_basic(&array, out_fd);
+	printf("Fildescriptor = %d\n", *out_fd);
+
+	dbus_message_iter_next(&array);
+
+	if (dbus_message_iter_get_arg_type(&array) != DBUS_TYPE_ARRAY)
+		goto done;
+
+	dbus_message_iter_recurse(&array, &dict);
+
+	while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
+		DBusMessageIter iter;
+		const char *key;
+		int type;
+
+		dbus_message_iter_recurse(&dict, &entry);
+
+		dbus_message_iter_get_basic(&entry, &key);
+
+		printf("key %s", key);
+
+		dbus_message_iter_next(&entry);
+		dbus_message_iter_recurse(&entry, &iter);
+
+		type = dbus_message_iter_get_arg_type(&iter);
+		if (type != DBUS_TYPE_STRING)
+			break;
+
+		if (g_str_equal(key, "ServerIPv4")
+				&& type == DBUS_TYPE_STRING) {
+			dbus_message_iter_get_basic(&iter, out_server_ip);
+			printf(" = %s\n", *out_server_ip);
+
+		} else if (g_str_equal(key, "PeerIPv4")
+				&& type == DBUS_TYPE_STRING) {
+			dbus_message_iter_get_basic(&iter, out_peer_ip);
+			printf(" = %s\n", *out_peer_ip);
+
+		} else if (g_str_equal(key, "PrimaryDNS")
+				&& type == DBUS_TYPE_STRING) {
+			dbus_message_iter_get_basic(&iter, out_primary_dns);
+			printf(" = %s\n", *out_primary_dns);
+
+		} else if (g_str_equal(key, "SecondaryDNS")
+				&& type == DBUS_TYPE_STRING) {
+			dbus_message_iter_get_basic(&iter, out_secondary_dns);
+			printf(" = %s\n", *out_secondary_dns);
+		}
+
+		dbus_message_iter_next(&dict);
+	}
+
+done:
+	dbus_message_unref(reply);
+}
+
+int main(int argc, char *argv[])
+{
+	DBusConnection *conn;
+	int fd = -1;
+	char *server_ip;
+	char *peer_ip;
+	char *primary_dns;
+	char *secondary_dns;
+
+	/*
+	 * IP packet: src: 192.168.219.2 dst www.connman.net
+	 * HTTP GET / request
+	 */
+	int buf1[81] = { 0x45, 0x00, 0x00, 0x51, 0x5a, 0xbe, 0x00, 0x00, 0x40,
+			 0x06, 0x50, 0x73, 0xc0, 0xa8, 0xdb, 0x01, 0x3e, 0x4b,
+			 0xf5, 0x80, 0x30, 0x3b, 0x00, 0x50, 0x00, 0x00, 0x00,
+			 0x28, 0x04, 0xfd, 0xac, 0x9b, 0x50, 0x18, 0x02, 0x00,
+			 0xa1, 0xb3, 0x00, 0x00, 0x47, 0x45, 0x54, 0x20, 0x2f,
+			 0x20, 0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, 0x2e, 0x31,
+			 0x0d, 0x0a, 0x48, 0x6f, 0x73, 0x74, 0x3a, 0x20, 0x77,
+			 0x77, 0x77, 0x2e, 0x63, 0x6f, 0x6e, 0x6e, 0x6d, 0x61,
+			 0x6e, 0x2e, 0x6e, 0x65, 0x74, 0x0d, 0x0a, 0x0d, 0x0a};
+
+
+	int buf2[81] = { 0x45, 0x00, 0x00, 0x51, 0x57, 0x9d, 0x00, 0x00, 0x40,
+			 0x06, 0x53, 0x93, 0xc0, 0xa8, 0xdb, 0x02, 0x3e, 0x4b,
+			 0xf5, 0x80, 0x30, 0x3b, 0x00, 0x50, 0x00, 0x00, 0x00,
+			 0x28, 0x17, 0xdb, 0x2e, 0x6d, 0x50, 0x18, 0x02, 0x00,
+			 0x0d, 0x03, 0x00, 0x00, 0x47, 0x45, 0x54, 0x20, 0x2f,
+			 0x20, 0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, 0x2e, 0x31,
+			 0x0d, 0x0a, 0x48, 0x6f, 0x73, 0x74, 0x3a, 0x20, 0x77,
+			 0x77, 0x77, 0x2e, 0x63, 0x6f, 0x6e, 0x6e, 0x6d, 0x61,
+			 0x6e, 0x2e, 0x6e, 0x65, 0x74, 0x0d, 0x0a, 0x0d, 0x0a};
+
+	if (DBUS_TYPE_UNIX_FD < 0) {
+		fprintf(stderr, "File-descriptor passing not supported\n");
+		exit(1);
+	}
+
+	conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
+	if (!conn) {
+		fprintf(stderr, "Can't get on system bus\n");
+		exit(1);
+	}
+
+	request_private_network(conn, &fd, &server_ip, &peer_ip,
+					&primary_dns, &secondary_dns);
+	if (fd < 0)
+		return -1;
+
+	fcntl(fd, F_SETFL, O_NONBLOCK);
+
+	printf("Press ENTER to write data to the network.\n");
+	getchar();
+
+
+	if (!fork()) {
+		if (write(fd, buf1, sizeof(buf1)) < 0) {
+			fprintf(stderr, "err on write() buf1\n");
+			return -1;
+		}
+
+		if (write(fd, buf2, sizeof(buf2)) < 0) {
+			fprintf(stderr, "err on write() buf2\n");
+			return -1;
+		}
+
+		printf("Press ENTER to release private network.\n");
+		getchar();
+
+		if (release_private_network(conn) < 0)
+			return -1;
+
+		close(fd);
+
+		dbus_connection_unref(conn);
+
+	} else {
+		struct pollfd p;
+		char buf[1500];
+		int len;
+
+		p.fd = fd;
+		p.events = POLLIN | POLLERR | POLLHUP;
+
+		while (1) {
+			p.revents = 0;
+			if (poll(&p, 1, -1) <= 0)
+				return -1;
+
+			if (p.revents & (POLLERR | POLLHUP))
+				return -1;
+
+			len = read(fd, buf, sizeof(buf));
+			if (len < 0)
+				return -1;
+
+			printf("%d bytes received\n", len);
+		}
+	}
+
+	return 0;
+}
diff --git a/connman/tools/resolv-test.c b/connman/tools/resolv-test.c
new file mode 100644
index 0000000..8953acd
--- /dev/null
+++ b/connman/tools/resolv-test.c
@@ -0,0 +1,166 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2012  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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <signal.h>
+
+#include <gweb/gresolv.h>
+
+static GTimer *timer;
+
+static GMainLoop *main_loop;
+
+static void resolv_debug(const char *str, void *data)
+{
+	g_print("%s: %s\n", (const char *) data, str);
+}
+
+static void sig_term(int sig)
+{
+	g_main_loop_quit(main_loop);
+}
+
+static const char *status2str(GResolvResultStatus status)
+{
+	switch (status) {
+	case G_RESOLV_RESULT_STATUS_SUCCESS:
+		return "success";
+	case G_RESOLV_RESULT_STATUS_ERROR:
+		return "error";
+	case G_RESOLV_RESULT_STATUS_NO_RESPONSE:
+		return "no response";
+	case G_RESOLV_RESULT_STATUS_FORMAT_ERROR:
+		return "format error";
+	case G_RESOLV_RESULT_STATUS_SERVER_FAILURE:
+		return "server failure";
+	case G_RESOLV_RESULT_STATUS_NAME_ERROR:
+		return "name error";
+	case G_RESOLV_RESULT_STATUS_NOT_IMPLEMENTED:
+		return "not implemented";
+	case G_RESOLV_RESULT_STATUS_REFUSED:
+		return "refused";
+	}
+
+	return NULL;
+}
+
+static void resolv_result(GResolvResultStatus status,
+					char **results, gpointer user_data)
+{
+	gdouble elapsed;
+	int i;
+
+	elapsed = g_timer_elapsed(timer, NULL);
+
+	g_print("elapse: %f seconds\n", elapsed);
+
+	g_print("status: %s\n", status2str(status));
+
+	if (results) {
+		for (i = 0; results[i]; i++)
+			g_print("result: %s\n", results[i]);
+	}
+
+	g_main_loop_quit(main_loop);
+}
+
+static bool option_debug = false;
+
+static GOptionEntry options[] = {
+	{ "debug", 'd', 0, G_OPTION_ARG_NONE, &option_debug,
+					"Enable debug output" },
+	{ NULL },
+};
+
+int main(int argc, char *argv[])
+{
+	GOptionContext *context;
+	GError *error = NULL;
+	struct sigaction sa;
+	GResolv *resolv;
+	int index = 0;
+
+	context = g_option_context_new(NULL);
+	g_option_context_add_main_entries(context, options, NULL);
+
+	if (!g_option_context_parse(context, &argc, &argv, &error)) {
+		if (error) {
+			g_printerr("%s\n", error->message);
+			g_error_free(error);
+		} else
+			g_printerr("An unknown error occurred\n");
+		exit(1);
+	}
+
+	g_option_context_free(context);
+
+	if (argc < 2) {
+		printf("missing argument\n");
+		return 1;
+	}
+
+	resolv = g_resolv_new(index);
+	if (!resolv) {
+		printf("failed to create resolver\n");
+		return 1;
+	}
+
+	if (option_debug)
+		g_resolv_set_debug(resolv, resolv_debug, "RESOLV");
+
+	main_loop = g_main_loop_new(NULL, FALSE);
+
+	if (argc > 2) {
+		int i;
+
+		for (i = 2; i < argc; i++)
+			g_resolv_add_nameserver(resolv, argv[i], 53, 0);
+	}
+
+	timer = g_timer_new();
+
+	if (g_resolv_lookup_hostname(resolv, argv[1],
+					resolv_result, NULL) == 0) {
+		printf("failed to start lookup\n");
+		return 1;
+	}
+
+	memset(&sa, 0, sizeof(sa));
+	sa.sa_handler = sig_term;
+	sigaction(SIGINT, &sa, NULL);
+	sigaction(SIGTERM, &sa, NULL);
+
+	g_main_loop_run(main_loop);
+
+	g_timer_destroy(timer);
+
+	g_resolv_unref(resolv);
+
+	g_main_loop_unref(main_loop);
+
+	return 0;
+}
diff --git a/connman/tools/session-api.c b/connman/tools/session-api.c
new file mode 100644
index 0000000..b97cfc0
--- /dev/null
+++ b/connman/tools/session-api.c
@@ -0,0 +1,326 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2011-2014  BMW Car IT GmbH.
+ *
+ *  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 <gdbus.h>
+
+#include "session-test.h"
+
+static enum connman_session_state string2state(const char *state)
+{
+	if (g_strcmp0(state, "connected") == 0)
+		return CONNMAN_SESSION_STATE_CONNECTED;
+	if (g_strcmp0(state, "online") == 0)
+		return CONNMAN_SESSION_STATE_ONLINE;
+
+	return CONNMAN_SESSION_STATE_DISCONNECTED;
+}
+
+static enum connman_session_type string2type(const char *type)
+{
+	if (g_strcmp0(type, "any") == 0)
+		return CONNMAN_SESSION_TYPE_ANY;
+	if (g_strcmp0(type, "local") == 0)
+		return CONNMAN_SESSION_TYPE_LOCAL;
+	if (g_strcmp0(type, "internet") == 0)
+		return CONNMAN_SESSION_TYPE_INTERNET;
+
+	return CONNMAN_SESSION_TYPE_UNKNOWN;
+}
+
+void bearer_info_cleanup(gpointer data, gpointer user_data)
+{
+	struct test_bearer_info *info = data;
+
+	g_free(info->name);
+	g_free(info);
+}
+
+static GSList *session_parse_allowed_bearers(DBusMessageIter *iter)
+{
+	struct test_bearer_info *info;
+	DBusMessageIter array;
+	GSList *list = NULL;
+
+	dbus_message_iter_recurse(iter, &array);
+
+	while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_STRING) {
+		char *bearer = NULL;
+
+		dbus_message_iter_get_basic(&array, &bearer);
+
+		info = g_try_new0(struct test_bearer_info, 1);
+		if (!info) {
+			g_slist_foreach(list, bearer_info_cleanup, NULL);
+			g_slist_free(list);
+
+			return NULL;
+		}
+
+		info->name = g_strdup(bearer);
+
+		list = g_slist_append(list, info);
+
+		dbus_message_iter_next(&array);
+	}
+
+	return list;
+}
+
+static DBusMessage *notify_release(DBusConnection *conn,
+					DBusMessage *msg, void *user_data)
+{
+	struct test_session *session = user_data;
+
+	LOG("session %p", session);
+
+	if (session->notify)
+		session->notify(session);
+
+	return NULL;
+}
+
+static DBusMessage *notify_update(DBusConnection *conn,
+					DBusMessage *msg, void *user_data)
+{
+	struct test_session *session = user_data;
+	struct test_session_info *info = session->info;
+	DBusMessageIter iter, array;
+	GSList *allowed_bearers;
+
+	LOG("session %p notify %s", session, session->notify_path);
+
+	dbus_message_iter_init(msg, &iter);
+	dbus_message_iter_recurse(&iter, &array);
+
+	while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_DICT_ENTRY) {
+		DBusMessageIter entry, value;
+		const char *key;
+
+		dbus_message_iter_recurse(&array, &entry);
+		dbus_message_iter_get_basic(&entry, &key);
+
+		dbus_message_iter_next(&entry);
+		dbus_message_iter_recurse(&entry, &value);
+
+		switch (dbus_message_iter_get_arg_type(&value)) {
+		case DBUS_TYPE_ARRAY:
+			if (g_str_equal(key, "AllowedBearers")) {
+				allowed_bearers = session_parse_allowed_bearers(&value);
+
+				g_slist_foreach(info->allowed_bearers,
+						bearer_info_cleanup, NULL);
+				g_slist_free(info->allowed_bearers);
+
+				info->allowed_bearers = allowed_bearers;
+
+			} else if (g_str_equal(key, "IPv4")) {
+				/* XXX */
+
+			} else if (g_str_equal(key, "IPv6")) {
+				/* XXX */
+
+			} else {
+				g_assert(FALSE);
+				return __connman_error_invalid_arguments(msg);
+			}
+			break;
+		case DBUS_TYPE_STRING:
+			if (g_str_equal(key, "State")) {
+				const char *val;
+				dbus_message_iter_get_basic(&value, &val);
+
+				info->state = string2state(val);
+			} else if (g_str_equal(key, "Bearer")) {
+				const char *val;
+				dbus_message_iter_get_basic(&value, &val);
+
+				if (info->bearer)
+					g_free(info->bearer);
+
+				info->bearer = g_strdup(val);
+
+			} else if (g_str_equal(key, "Name")) {
+				const char *val;
+				dbus_message_iter_get_basic(&value, &val);
+
+				if (info->name)
+					g_free(info->name);
+
+				info->name = g_strdup(val);
+
+			} else if (g_str_equal(key, "Interface")) {
+				const char *val;
+				dbus_message_iter_get_basic(&value, &val);
+
+				if (info->interface)
+					g_free(info->interface);
+
+				info->interface = g_strdup(val);
+
+			} else if (g_str_equal(key, "ConnectionType")
+								) {
+				const char *val;
+				dbus_message_iter_get_basic(&value, &val);
+
+				info->type = string2type(val);
+			} else {
+				g_assert(FALSE);
+				return __connman_error_invalid_arguments(msg);
+			}
+			break;
+		default:
+			g_assert(FALSE);
+			return __connman_error_invalid_arguments(msg);
+		}
+		dbus_message_iter_next(&array);
+	}
+
+	if (session->notify)
+		session->notify(session);
+
+	return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+}
+
+static const GDBusMethodTable notify_methods[] = {
+	{ GDBUS_METHOD("Release", NULL, NULL, notify_release) },
+	{ GDBUS_METHOD("Update",
+			GDBUS_ARGS({ "settings", "a{sv}" }), NULL,
+			notify_update) },
+	{ },
+};
+
+int session_notify_register(struct test_session *session,
+				const char *notify_path)
+{
+	if (!g_dbus_register_interface(session->connection, notify_path, CONNMAN_NOTIFICATION_INTERFACE, notify_methods, NULL, NULL, session, NULL)) {
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+int session_notify_unregister(struct test_session *session,
+				const char *notify_path)
+{
+	if (!g_dbus_unregister_interface(session->connection, notify_path, CONNMAN_NOTIFICATION_INTERFACE)) {
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static void append_allowed_bearers(DBusMessageIter *iter, void *user_data)
+{
+	struct test_session_info *info = user_data;
+	GSList *list;
+
+	for (list = info->allowed_bearers;
+			list; list = list->next) {
+		struct test_bearer_info *bearer_info = list->data;
+
+		dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING,
+						&bearer_info->name);
+	}
+}
+
+void session_append_settings(DBusMessageIter *dict,
+				struct test_session_info *info)
+{
+	if (!info->allowed_bearers)
+		return;
+
+	connman_dbus_dict_append_array(dict, "AllowedBearers",
+						DBUS_TYPE_STRING,
+						append_allowed_bearers,
+						info);
+}
+
+DBusMessage *session_connect(DBusConnection *connection,
+				struct test_session *session)
+{
+	DBusMessage *message, *reply;
+	DBusError error;
+
+	message = dbus_message_new_method_call(CONNMAN_SERVICE,
+						session->session_path,
+						CONNMAN_SESSION_INTERFACE,
+							"Connect");
+	if (!message)
+		return NULL;
+
+	dbus_error_init(&error);
+
+	reply = dbus_connection_send_with_reply_and_block(connection,
+							message, -1, &error);
+	if (!reply) {
+		if (dbus_error_is_set(&error)) {
+			LOG("%s", error.message);
+			dbus_error_free(&error);
+		} else {
+			LOG("Failed to get properties");
+		}
+		dbus_message_unref(message);
+		return NULL;
+	}
+
+	dbus_message_unref(message);
+
+	return reply;
+}
+
+DBusMessage *session_disconnect(DBusConnection *connection,
+					struct test_session *session)
+{
+	DBusMessage *message, *reply;
+	DBusError error;
+
+	message = dbus_message_new_method_call(CONNMAN_SERVICE,
+						session->session_path,
+						CONNMAN_SESSION_INTERFACE,
+							"Disconnect");
+	if (!message)
+		return NULL;
+
+	dbus_error_init(&error);
+
+	reply = dbus_connection_send_with_reply_and_block(connection,
+							message, -1, &error);
+	if (!reply) {
+		if (dbus_error_is_set(&error)) {
+			LOG("%s", error.message);
+			dbus_error_free(&error);
+		} else {
+			LOG("Failed to get properties");
+		}
+		dbus_message_unref(message);
+		return NULL;
+	}
+
+	dbus_message_unref(message);
+
+	return reply;
+}
diff --git a/connman/tools/session-test.c b/connman/tools/session-test.c
new file mode 100644
index 0000000..4319e5a
--- /dev/null
+++ b/connman/tools/session-test.c
@@ -0,0 +1,699 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2011  BMW Car IT GmbH.
+ *
+ *  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 <stdio.h>
+#include <unistd.h>
+#include <pwd.h>
+#include <sys/types.h>
+
+#include <gdbus.h>
+
+#include "session-test.h"
+
+#define POLICYDIR STORAGEDIR "/session_policy_local"
+
+enum test_session_state {
+	TEST_SESSION_STATE_0 = 0,
+	TEST_SESSION_STATE_1 = 1,
+	TEST_SESSION_STATE_2 = 2,
+	TEST_SESSION_STATE_3 = 3,
+};
+
+static enum test_session_state get_session_state(struct test_session *session)
+{
+	return GPOINTER_TO_UINT(session->fix->user_data);
+}
+
+static void set_session_state(struct test_session *session,
+				enum test_session_state state)
+{
+	session->fix->user_data = GUINT_TO_POINTER(state);
+}
+
+static struct test_session *get_session(struct test_session *session,
+					unsigned int index)
+{
+	return &session->fix->session[index];
+}
+
+static void test_session_create_no_notify(struct test_fix *fix)
+{
+	DBusMessage *msg;
+
+	util_session_create(fix, 1);
+
+	msg = manager_create_session(fix->session->connection,
+					fix->session->info, "/foo");
+	g_assert(msg);
+	g_assert(dbus_message_get_type(msg) != DBUS_MESSAGE_TYPE_ERROR);
+
+	dbus_message_unref(msg);
+
+	util_idle_call(fix, util_quit_loop, util_session_destroy);
+}
+
+static void test_session_destroy_no_notify(struct test_fix *fix)
+{
+	DBusMessage *msg;
+
+	util_session_create(fix, 1);
+
+	msg = manager_destroy_session(fix->session->connection, "/foo");
+	g_assert(!msg);
+
+	util_idle_call(fix, util_quit_loop, util_session_destroy);
+}
+
+static void test_session_create_notify(struct test_session *session)
+{
+	LOG("session %p", session);
+
+	util_idle_call(session->fix, util_quit_loop, util_session_destroy);
+}
+
+static void test_session_create(struct test_fix *fix)
+{
+	struct test_session *session;
+	DBusMessage *msg;
+	int err;
+
+	util_session_create(fix, 1);
+	session = fix->session;
+
+	session->notify_path = "/foo";
+	session->notify = test_session_create_notify;
+
+	err = session_notify_register(session, session->notify_path);
+	g_assert(err == 0);
+
+	msg = manager_create_session(session->connection,
+					session->info,
+					session->notify_path);
+	g_assert(msg);
+	g_assert(dbus_message_get_type(msg) != DBUS_MESSAGE_TYPE_ERROR);
+
+	dbus_message_unref(msg);
+}
+
+static void test_session_create_destroy(struct test_fix *fix)
+{
+	struct test_session *session;
+
+	util_session_create(fix, 1);
+	session = fix->session;
+
+	session->notify_path = g_strdup("/foo");
+
+	util_session_init(fix->session);
+	util_session_cleanup(fix->session);
+
+	util_idle_call(fix, util_quit_loop, util_session_destroy);
+}
+
+static void test_session_create_dup_notification(struct test_fix *fix)
+{
+	struct test_session *session0, *session1;
+	DBusMessage *msg;
+
+	util_session_create(fix, 2);
+	session0 = &fix->session[0];
+	session1 = &fix->session[1];
+
+	session0->notify_path = g_strdup("/foo");
+	session1->notify_path = session0->notify_path;
+
+	util_session_init(session0);
+
+	msg = manager_create_session(session1->connection,
+					session1->info,
+					session1->notify_path);
+	g_assert(msg);
+
+	util_session_cleanup(session0);
+
+	util_idle_call(fix, util_quit_loop, util_session_destroy);
+}
+
+static void test_session_create_many_notify(struct test_session *session)
+{
+	unsigned int nr;
+
+	LOG("session %p", session);
+
+	nr = GPOINTER_TO_UINT(session->fix->user_data);
+	nr--;
+	session->fix->user_data = GUINT_TO_POINTER(nr);
+
+	if (nr > 0)
+		return;
+
+	util_idle_call(session->fix, util_quit_loop, util_session_destroy);
+}
+
+static void test_session_create_many(struct test_fix *fix)
+{
+	struct test_session *session;
+	unsigned int i, max;
+
+	max = 100;
+
+	fix->user_data = GUINT_TO_POINTER(max);
+
+	util_session_create(fix, max);
+
+	for (i = 0; i < max; i++) {
+		session = &fix->session[i];
+
+		session->notify_path = g_strdup_printf("/foo/%d", i);
+		session->notify = test_session_create_many_notify;
+
+		util_session_init(session);
+	}
+}
+
+static void set_session_mode(struct test_fix *fix,
+					bool enable)
+{
+	DBusMessage *msg;
+
+	msg = manager_set_session_mode(fix->main_connection, enable);
+	g_assert(msg);
+	g_assert(dbus_message_get_type(msg) != DBUS_MESSAGE_TYPE_ERROR);
+
+	dbus_message_unref(msg);
+}
+
+static void test_session_connect_notify(struct test_session *session)
+{
+	LOG("session %p state %d", session, session->info->state);
+
+	if (session->info->state == CONNMAN_SESSION_STATE_DISCONNECTED)
+		return;
+
+	util_session_cleanup(session);
+
+	util_idle_call(session->fix, util_quit_loop, util_session_destroy);
+}
+
+static void test_session_connect(struct test_fix *fix)
+{
+	struct test_session *session;
+	DBusMessage *msg;
+
+	util_session_create(fix, 1);
+	session = fix->session;
+
+	session->notify_path = g_strdup("/foo");
+	session->notify =  test_session_connect_notify;
+	util_session_init(session);
+
+	msg = session_connect(session->connection, session);
+	g_assert(msg);
+	g_assert(dbus_message_get_type(msg) != DBUS_MESSAGE_TYPE_ERROR);
+
+	dbus_message_unref(msg);
+}
+
+static void test_session_disconnect_notify(struct test_session *session)
+{
+	LOG("session %p state %d", session, session->info->state);
+
+	if (session->info->state >= CONNMAN_SESSION_STATE_CONNECTED)
+		return;
+
+	util_session_cleanup(session);
+
+	util_idle_call(session->fix, util_quit_loop, util_session_destroy);
+}
+
+static void test_session_disconnect(struct test_fix *fix)
+{
+	struct test_session *session;
+	DBusMessage *msg;
+
+	util_session_create(fix, 1);
+	session = fix->session;
+
+	session->notify_path = g_strdup("/foo");
+	session->notify =  test_session_disconnect_notify;
+	util_session_init(session);
+
+	msg = session_disconnect(session->connection, session);
+	g_assert(msg);
+	dbus_message_unref(msg);
+}
+
+static void test_session_connect_disconnect_notify(struct test_session *session)
+{
+	enum test_session_state state = get_session_state(session);
+	enum test_session_state next_state = state;
+	DBusMessage *msg;
+
+	LOG("state %d session %p %s state %d", state, session,
+		session->notify_path, session->info->state);
+
+	switch (state) {
+	case TEST_SESSION_STATE_0:
+		if (session->info->state == CONNMAN_SESSION_STATE_DISCONNECTED)
+			next_state = TEST_SESSION_STATE_1;
+		if (session->info->state == CONNMAN_SESSION_STATE_CONNECTED) {
+			LOG("state was already connected, continuing");
+			next_state = TEST_SESSION_STATE_2;
+		}
+		break;
+	case TEST_SESSION_STATE_1:
+		if (session->info->state >= CONNMAN_SESSION_STATE_CONNECTED)
+			next_state = TEST_SESSION_STATE_2;
+		break;
+	case TEST_SESSION_STATE_2:
+		if (session->info->state == CONNMAN_SESSION_STATE_DISCONNECTED)
+			next_state = TEST_SESSION_STATE_3;
+	default:
+		break;
+	}
+
+	if (state == next_state)
+		return;
+
+	set_session_state(session, next_state);
+
+	LOG("next_state %d", next_state);
+
+	switch (next_state) {
+	case TEST_SESSION_STATE_1:
+		msg = session_connect(session->connection, session);
+		g_assert(msg);
+		dbus_message_unref(msg);
+		return;
+	case TEST_SESSION_STATE_2:
+		msg = session_disconnect(session->connection, session);
+		g_assert(msg);
+		dbus_message_unref(msg);
+		return;
+	case TEST_SESSION_STATE_3:
+		util_session_cleanup(session);
+		util_idle_call(session->fix, util_quit_loop,
+				util_session_destroy);
+		return;
+	default:
+		return;
+	}
+}
+
+static void test_session_connect_disconnect(struct test_fix *fix)
+{
+	struct test_session *session;
+
+	/*
+	 * +-------------------+
+	 * |       START       |
+	 * +-------------------+
+	 *   |
+	 *   | connect foo
+	 *   v
+	 * +-------------------+
+	 * |   FOO-CONNECTED   |
+	 * +-------------------+
+	 *  |
+	 *  | disconnect foo
+	 *  v
+	 * +-------------------+
+	 * |        END        |
+	 * +-------------------+
+	 */
+
+	util_session_create(fix, 1);
+	session = fix->session;
+
+	session->notify_path = g_strdup("/foo");
+	session->notify =  test_session_connect_disconnect_notify;
+
+	util_session_init(session);
+
+	set_session_state(session, TEST_SESSION_STATE_0);
+}
+
+static void test_session_connect_free_ride_notify(struct test_session *session)
+{
+	struct test_session *session0 = get_session(session, 0);
+	struct test_session *session1 = get_session(session, 1);
+	enum test_session_state state = get_session_state(session);
+	enum test_session_state next_state = state;
+	DBusMessage *msg;
+
+	LOG("state %d session %p %s state %d", state, session,
+		session->notify_path, session->info->state);
+
+	switch (state) {
+	case TEST_SESSION_STATE_0:
+		if (session0->info->state == CONNMAN_SESSION_STATE_DISCONNECTED
+				&& session1->info->state ==
+					CONNMAN_SESSION_STATE_DISCONNECTED) {
+			next_state = TEST_SESSION_STATE_1;
+		}
+		if (session0->info->state == CONNMAN_SESSION_STATE_CONNECTED &&
+				session1->info->state ==
+				CONNMAN_SESSION_STATE_CONNECTED) {
+			LOG("state was already connected, continuing");
+			next_state = TEST_SESSION_STATE_2;
+		}
+
+		break;
+	case TEST_SESSION_STATE_1:
+		if (session0->info->state >= CONNMAN_SESSION_STATE_CONNECTED &&
+				session1->info->state >=
+					CONNMAN_SESSION_STATE_CONNECTED) {
+			next_state = TEST_SESSION_STATE_2;
+		}
+
+		break;
+	case TEST_SESSION_STATE_2:
+		if (session0->info->state == CONNMAN_SESSION_STATE_DISCONNECTED
+				&& (session1->info->state ==
+					CONNMAN_SESSION_STATE_DISCONNECTED ||
+						session1->info->state ==
+					CONNMAN_SESSION_STATE_CONNECTED) ) {
+			LOG("session0 /foo is disconnected, session1 /bar "
+				"can be either connected or disconnected");
+			next_state = TEST_SESSION_STATE_3;
+		}
+
+		break;
+	case TEST_SESSION_STATE_3:
+
+		return;
+	}
+
+	if (state == next_state)
+		return;
+
+	set_session_state(session, next_state);
+
+	LOG("next_state %d", next_state);
+
+	switch (next_state) {
+	case TEST_SESSION_STATE_0:
+
+		return;
+	case TEST_SESSION_STATE_1:
+		msg = session_connect(session0->connection, session0);
+		g_assert(msg);
+		dbus_message_unref(msg);
+
+		return;
+
+	case TEST_SESSION_STATE_2:
+		msg = session_disconnect(session0->connection, session0);
+		g_assert(msg);
+		dbus_message_unref(msg);
+
+		return;
+	case TEST_SESSION_STATE_3:
+		util_session_cleanup(session0);
+		util_session_cleanup(session1);
+
+		util_idle_call(session0->fix, util_quit_loop,
+				util_session_destroy);
+
+		return;
+	}
+}
+
+static void test_session_connect_free_ride(struct test_fix *fix)
+{
+	struct test_session *session0, *session1;
+
+	/*
+	 * +-------------------+
+	 * |       START       |
+	 * +-------------------+
+	 *   |
+	 *   | connect foo
+	 *   v
+	 * +-------------------+
+	 * |   FOO-CONNECTED   |
+	 * +-------------------+
+	 *   |
+	 *   | free-ride bar
+	 *   v
+	 * +-------------------+
+	 * | FOO-BAR-CONNECTED |
+	 * +-------------------+
+	 *  |
+	 *  | disconnect foo
+	 *  v
+	 * +-------------------+
+	 * |        END        |
+	 * +-------------------+
+	 */
+
+	util_session_create(fix, 2);
+	session0 = &fix->session[0];
+	session1 = &fix->session[1];
+
+	session0->notify_path = g_strdup("/foo");
+	session1->notify_path = g_strdup("/bar");
+	session0->notify = test_session_connect_free_ride_notify;
+	session1->notify = test_session_connect_free_ride_notify;
+
+	util_session_init(session0);
+	util_session_init(session1);
+
+	set_session_state(session0, TEST_SESSION_STATE_0);
+}
+
+static void policy_save(GKeyFile *keyfile, char *pathname)
+{
+	gchar *data = NULL;
+	gsize length = 0;
+	GError *error = NULL;
+
+	data = g_key_file_to_data(keyfile, &length, NULL);
+
+	if (!g_file_set_contents(pathname, data, length, &error)) {
+		DBG("Failed to store information: %s", error->message);
+		g_error_free(error);
+		g_assert(0);
+	}
+
+	g_free(data);
+}
+
+static void policy_allowed_bearers(const char *allowed_bearers)
+{
+	struct passwd *pwd;
+	uid_t uid;
+	char *pathname;
+	GKeyFile *keyfile;
+
+	LOG("update to '%s'", allowed_bearers);
+
+	uid = getuid();
+	pwd = getpwuid(uid);
+	g_assert(pwd);
+
+	keyfile = g_key_file_new();
+	g_key_file_set_string(keyfile, "policy_foo", "uid", pwd->pw_name);
+	g_key_file_set_string(keyfile, "policy_foo", "AllowedBearers",
+				allowed_bearers);
+
+	pathname = g_strdup_printf("%s/foo.policy", POLICYDIR);
+	policy_save(keyfile, pathname);
+
+	g_free(pathname);
+	g_key_file_free(keyfile);
+}
+
+static void policy_remove_file(void)
+{
+	char *pathname;
+
+	pathname = g_strdup_printf("%s/foo.policy", POLICYDIR);
+	unlink(pathname);
+	g_free(pathname);
+}
+
+static void test_session_policy_notify(struct test_session *session)
+{
+	enum test_session_state state = get_session_state(session);
+	enum test_session_state next_state = state;
+	DBusMessage *msg;
+
+	LOG("state %d session %p %s state %d", state, session,
+		session->notify_path, session->info->state);
+
+	switch (state) {
+	case TEST_SESSION_STATE_0:
+		if (session->info->state == CONNMAN_SESSION_STATE_DISCONNECTED)
+			next_state = TEST_SESSION_STATE_1;
+		break;
+	case TEST_SESSION_STATE_1:
+		if (session->info->state >= CONNMAN_SESSION_STATE_CONNECTED)
+			next_state = TEST_SESSION_STATE_2;
+		break;
+	case TEST_SESSION_STATE_2:
+		if (session->info->state == CONNMAN_SESSION_STATE_DISCONNECTED)
+			next_state = TEST_SESSION_STATE_3;
+	default:
+		break;
+	}
+
+	if (state == next_state)
+		return;
+
+	set_session_state(session, next_state);
+
+	LOG("next_state %d", next_state);
+
+	switch (next_state) {
+	case TEST_SESSION_STATE_1:
+		policy_allowed_bearers("ethernet");
+
+		msg = session_connect(session->connection, session);
+		g_assert(msg);
+		dbus_message_unref(msg);
+		return;
+	case TEST_SESSION_STATE_2:
+		policy_allowed_bearers("");
+		return;
+	case TEST_SESSION_STATE_3:
+		policy_remove_file();
+		util_session_cleanup(session);
+		util_idle_call(session->fix, util_quit_loop,
+				util_session_destroy);
+		return;
+	default:
+		return;
+	}
+}
+
+static void test_session_policy(struct test_fix *fix)
+{
+	struct test_session *session;
+
+	/*
+	 * +-------------------+
+	 * |       START       |
+	 * +-------------------+
+	 *   |
+	 *   | write policy AllowedBearers = ethernet
+	 *   v
+	 * +-------------------+
+	 * |   FOO-CONNECTED   |
+	 * +-------------------+
+	 *  |
+	 *  | write policy AllowedBearers =
+	 *  v
+	 * +-------------------+
+	 * |        END        |
+	 * +-------------------+
+	 */
+
+	policy_remove_file();
+
+	util_session_create(fix, 1);
+	session = fix->session;
+
+	session->notify_path = g_strdup("/foo");
+	session->notify =  test_session_policy_notify;
+
+	util_session_init(session);
+
+	set_session_state(session, TEST_SESSION_STATE_0);
+}
+
+static bool is_online(struct test_fix *fix)
+{
+	if (g_strcmp0(fix->manager.state, "online") == 0)
+		return true;
+
+	return false;
+}
+
+static void enable_session_mode(struct test_fix *fix)
+{
+	set_session_mode(fix, true);
+
+	if (!is_online(fix))
+		util_idle_call(fix, util_quit_loop, NULL);
+}
+
+static void manager_state_changed(struct test_fix *fix)
+{
+	if (!is_online(fix)) {
+		fix->manager_changed = NULL;
+		util_idle_call(fix, util_quit_loop, NULL);
+	}
+}
+
+static void disable_session_mode(struct test_fix *fix)
+{
+	set_session_mode(fix, false);
+}
+
+static void setup_cb(struct test_fix *fix)
+{
+	fix->manager_changed = manager_state_changed;
+
+	util_call(fix, enable_session_mode, NULL);
+}
+
+static void teardown_cb(struct test_fix *fix)
+{
+	util_call(fix, disable_session_mode, NULL);
+	util_idle_call(fix, util_quit_loop, NULL);
+}
+
+int main(int argc, char *argv[])
+{
+	g_test_init(&argc, &argv, NULL);
+
+	util_test_add("/manager/session create no notify",
+		test_session_create_no_notify, setup_cb, teardown_cb);
+	util_test_add("/manager/session destroy no notify",
+		test_session_destroy_no_notify, setup_cb, teardown_cb);
+	util_test_add("/manager/session create",
+		test_session_create, setup_cb, teardown_cb);
+	util_test_add("/manager/session create destroy",
+		test_session_create_destroy, setup_cb, teardown_cb);
+	util_test_add("/manager/session create duplicate notification",
+		test_session_create_dup_notification, setup_cb, teardown_cb);
+	util_test_add("/manager/session create many",
+		test_session_create_many, setup_cb, teardown_cb);
+
+	util_test_add("/session/connect",
+		test_session_connect, setup_cb, teardown_cb);
+	util_test_add("/session/disconnect",
+		test_session_disconnect, setup_cb, teardown_cb);
+	util_test_add("/session/connect disconnect",
+		test_session_connect_disconnect, setup_cb, teardown_cb);
+	util_test_add("/session/connect free-ride",
+		test_session_connect_free_ride, setup_cb, teardown_cb);
+
+	util_test_add("/session/policy",
+		test_session_policy, setup_cb, teardown_cb);
+
+	return g_test_run();
+}
diff --git a/connman/tools/session-test.h b/connman/tools/session-test.h
new file mode 100644
index 0000000..5e6d196
--- /dev/null
+++ b/connman/tools/session-test.h
@@ -0,0 +1,142 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2012  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
+ *
+ */
+
+#include <glib.h>
+
+#include <connman/dbus.h>
+
+#include "../src/connman.h"
+
+struct test_session;
+struct test_fix;
+
+struct test_manager {
+	char *state;
+};
+
+typedef void (* util_test_func_t) (struct test_fix *fix);
+
+struct test_fix {
+	gpointer user_data;
+
+	GMainLoop *main_loop;
+	DBusConnection *main_connection;
+	unsigned int watch;
+	unsigned int manager_watch;
+
+	struct test_manager manager;
+	util_test_func_t manager_changed;
+
+	/* session test cases */
+	unsigned int max_sessions;
+	struct test_session *session;
+};
+
+void util_quit_loop(struct test_fix *fix);
+void util_idle_call(struct test_fix *fix, util_test_func_t func,
+			util_test_func_t destroy);
+void util_call(struct test_fix *fix, util_test_func_t func,
+		util_test_func_t destroy);
+void util_test_add(const char *test_name, util_test_func_t test,
+			util_test_func_t setup,
+			util_test_func_t teardown);
+void util_setup(struct test_fix *fix);
+void util_teardown(struct test_fix *fix);
+
+void util_session_create(struct test_fix *fix, unsigned int max_sessions);
+void util_session_destroy(struct test_fix *fix);
+void util_session_init(struct test_session *session);
+void util_session_cleanup(struct test_session *session);
+
+typedef void (* notify_func_t) (struct test_session *session);
+
+enum connman_session_state {
+	CONNMAN_SESSION_STATE_DISCONNECTED   = 0,
+	CONNMAN_SESSION_STATE_CONNECTED      = 1,
+	CONNMAN_SESSION_STATE_ONLINE         = 2,
+};
+
+struct test_session_info {
+	enum connman_session_state state;
+	char *name;
+	char *bearer;
+	char *interface;
+	enum connman_session_type type;
+	/* ipv4, ipv6 dicts */
+	GSList *allowed_bearers;
+};
+
+struct test_session {
+	void *user_data;
+
+	struct test_fix *fix;
+	DBusConnection *connection;
+
+	char *session_path;
+	char *notify_path;
+	notify_func_t notify;
+
+	struct test_session_info *info;
+};
+
+struct test_bearer_info {
+	char *name;
+};
+
+/* session-api.c */
+void bearer_info_cleanup(gpointer bearer_info, gpointer user_data);
+
+void session_append_settings(DBusMessageIter *dict,
+				struct test_session_info *info);
+int session_notify_register(struct test_session *session,
+				const char *notify_path);
+int session_notify_unregister(struct test_session *session,
+				const char *notify_path);
+
+DBusMessage *session_connect(DBusConnection *connection,
+				struct test_session *session);
+DBusMessage *session_disconnect(DBusConnection *connection,
+					struct test_session *session);
+
+/* manager-api.c */
+DBusMessage *manager_get_services(DBusConnection *connection);
+DBusMessage *manager_get_properties(DBusConnection *connection);
+DBusMessage *manager_create_session(DBusConnection *connection,
+					struct test_session_info *info,
+					const char *notifier_path);
+DBusMessage *manager_destroy_session(DBusConnection *connection,
+					const char *notifier_path);
+DBusMessage *manager_set_session_mode(DBusConnection *connection,
+					bool enable);
+int manager_parse_properties(DBusMessage *msg,
+				struct test_manager *manager);
+
+/* #define DEBUG */
+#ifdef DEBUG
+#include <stdio.h>
+
+#define LOG(fmt, arg...) do { \
+	fprintf(stdout, "%s:%s() " fmt "\n", \
+			__FILE__, __FUNCTION__ , ## arg); \
+} while (0)
+#else
+#define LOG(fmt, arg...)
+#endif
diff --git a/connman/tools/session-utils.c b/connman/tools/session-utils.c
new file mode 100644
index 0000000..51cec5c
--- /dev/null
+++ b/connman/tools/session-utils.c
@@ -0,0 +1,311 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2011-2014  BMW Car IT GmbH.
+ *
+ *  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 <stdlib.h>
+
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+
+#include <gdbus.h>
+
+#include "../src/shared/util.h"
+#include "session-test.h"
+
+#define ENABLE_WRAPPER 1
+#define PROPERTY_CHANGED		"PropertyChanged"
+
+void util_quit_loop(struct test_fix *fix)
+{
+	g_main_loop_quit(fix->main_loop);
+}
+
+static gboolean func_cb(gpointer data)
+{
+	struct cb_data *cbd = data;
+	util_test_func_t cb = cbd->cb;
+	struct test_fix *fix = cbd->user_data;
+
+	(*cb)(fix);
+
+	return FALSE;
+}
+
+static void destroy_cb(gpointer data)
+{
+	struct cb_data *cbd = data;
+	util_test_func_t cb = cbd->data;
+	struct test_fix *fix = cbd->user_data;
+
+	if (cb)
+		(*cb)(fix);
+
+	g_free(cbd);
+}
+
+void util_call(struct test_fix *fix, util_test_func_t func,
+		util_test_func_t destroy)
+{
+	struct cb_data *cbd = cb_data_new(func, fix);
+	GSource *source;
+
+	cbd->data = destroy;
+
+	source = g_timeout_source_new(0);
+	g_source_set_callback(source, func_cb, cbd, destroy_cb);
+	g_source_attach(source, g_main_loop_get_context(fix->main_loop));
+	g_source_unref(source);
+}
+
+void util_idle_call(struct test_fix *fix, util_test_func_t func,
+			util_test_func_t destroy)
+{
+	struct cb_data *cbd = cb_data_new(func, fix);
+	GSource *source;
+
+	cbd->data = destroy;
+
+	source = g_idle_source_new();
+	g_source_set_callback(source, func_cb, cbd, destroy_cb);
+	g_source_attach(source, g_main_loop_get_context(fix->main_loop));
+	g_source_unref(source);
+}
+
+static void connman_died(DBusConnection *connection, void *user_data)
+{
+	g_assert(FALSE);
+}
+
+static void manager_changed(struct test_fix *fix, DBusMessageIter *entry)
+{
+	DBusMessageIter iter;
+	const char *key;
+	const char *value;
+	int type;
+
+	dbus_message_iter_get_basic(entry, &key);
+
+	LOG("key %s", key);
+
+	dbus_message_iter_next(entry);
+
+	dbus_message_iter_recurse(entry, &iter);
+
+	type = dbus_message_iter_get_arg_type(&iter);
+
+	if (type != DBUS_TYPE_STRING)
+		return;
+
+	dbus_message_iter_get_basic(&iter, &value);
+
+	if (g_str_equal(key, "State")) {
+		LOG("State %s", value);
+
+		if (fix->manager.state)
+			g_free(fix->manager.state);
+
+		fix->manager.state = g_strdup(value);
+	}
+
+	if (fix->manager_changed)
+		fix->manager_changed(fix);
+}
+
+static gboolean handle_manager_changed(DBusConnection *connection,
+				DBusMessage *message,
+				void *user_data)
+{
+	struct test_fix *fix = user_data;
+
+	DBusMessageIter iter;
+
+	if (dbus_message_iter_init(message, &iter))
+		manager_changed(fix, &iter);
+
+	return TRUE;
+}
+
+static struct test_fix *create_fix(void)
+{
+	struct test_fix *fix;
+	DBusMessage *msg;
+
+	fix = g_new0(struct test_fix, 1);
+
+	fix->main_loop = g_main_loop_new(NULL, FALSE);
+	fix->main_connection = g_dbus_setup_private(DBUS_BUS_SYSTEM,
+							NULL, NULL);
+	fix->watch = g_dbus_add_service_watch(fix->main_connection,
+						CONNMAN_SERVICE,
+						NULL,
+						connman_died,
+						NULL, NULL);
+	fix->manager_watch = g_dbus_add_signal_watch(fix->main_connection,
+						CONNMAN_SERVICE, NULL,
+						CONNMAN_MANAGER_INTERFACE,
+						PROPERTY_CHANGED,
+						handle_manager_changed,
+						fix, NULL);
+
+	msg = manager_get_properties(fix->main_connection);
+	manager_parse_properties(msg, &fix->manager);
+	dbus_message_unref(msg);
+
+	return fix;
+}
+
+static void cleanup_fix(struct test_fix *fix)
+{
+	g_dbus_remove_watch(fix->main_connection, fix->watch);
+	g_dbus_remove_watch(fix->main_connection, fix->manager_watch);
+	dbus_connection_close(fix->main_connection);
+	dbus_connection_unref(fix->main_connection);
+
+	g_main_loop_unref(fix->main_loop);
+
+	g_free(fix);
+}
+
+struct test_data_cb {
+	util_test_func_t func;
+	util_test_func_t setup;
+	util_test_func_t teardown;
+};
+
+static void run_test_cb(gconstpointer data)
+{
+	const struct test_data_cb *cbd = data;
+	struct test_fix *fix;
+
+	fix = create_fix();
+
+	util_call(fix, cbd->setup, NULL);
+	g_main_loop_run(fix->main_loop);
+
+#if ENABLE_WRAPPER
+	if (g_test_trap_fork(60 * 1000 * 1000, 0)) {
+		util_call(fix, cbd->func, NULL);
+		g_main_loop_run(fix->main_loop);
+		exit(0);
+	}
+
+	g_test_trap_assert_passed();
+#else
+	util_call(fix, func, NULL);
+	g_main_loop_run(fix->main_loop);
+#endif
+
+	util_call(fix, cbd->teardown, NULL);
+	g_main_loop_run(fix->main_loop);
+
+	cleanup_fix(fix);
+}
+
+void util_test_add(const char *test_name, util_test_func_t test_func,
+		util_test_func_t setup, util_test_func_t teardown)
+{
+	struct test_data_cb *cbd = g_new0(struct test_data_cb, 1);
+
+	cbd->func = test_func;
+	cbd->setup = setup;
+	cbd->teardown = teardown;
+
+	g_test_add_vtable(test_name, 0, cbd, NULL,
+			(GTestFixtureFunc) run_test_cb,
+			(GTestFixtureFunc) g_free);
+}
+
+void util_session_create(struct test_fix *fix, unsigned int max_sessions)
+{
+	unsigned int i;
+
+	fix->max_sessions = max_sessions;
+	fix->session = g_try_new0(struct test_session, max_sessions);
+
+	for (i = 0; i < max_sessions; i++) {
+		fix->session[i].fix = fix;
+		fix->session[i].info = g_try_new0(struct test_session_info, 1);
+		fix->session[i].connection = g_dbus_setup_private(
+						DBUS_BUS_SYSTEM, NULL, NULL);
+	}
+}
+
+void util_session_destroy(struct test_fix *fix)
+{
+	unsigned int i;
+
+	for (i = 0; i < fix->max_sessions; i++) {
+		dbus_connection_close(fix->session[i].connection);
+		g_free(fix->session[i].info);
+	}
+
+	g_free(fix->session);
+}
+
+void util_session_init(struct test_session *session)
+{
+	DBusMessage *msg;
+	DBusMessageIter iter;
+	const char *path;
+	int err;
+
+	err = session_notify_register(session, session->notify_path);
+	g_assert(err == 0);
+
+	msg = manager_create_session(session->connection,
+					session->info,
+					session->notify_path);
+	g_assert(msg);
+	dbus_message_iter_init(msg, &iter);
+
+	dbus_message_iter_get_basic(&iter, &path);
+	session->session_path = g_strdup(path);
+
+	dbus_message_unref(msg);
+}
+
+void util_session_cleanup(struct test_session *session)
+{
+	DBusMessage *msg;
+	int err;
+
+	msg = manager_destroy_session(session->connection,
+					session->session_path);
+	g_assert(msg);
+	dbus_message_unref(msg);
+
+	err = session_notify_unregister(session,
+					session->notify_path);
+	g_assert(err == 0);
+
+	g_free(session->info->bearer);
+	g_free(session->info->name);
+	g_free(session->info->interface);
+	g_slist_foreach(session->info->allowed_bearers,
+			bearer_info_cleanup, NULL);
+	g_slist_free(session->info->allowed_bearers);
+
+	session->notify = NULL;
+	g_free(session->notify_path);
+	g_free(session->session_path);
+}
diff --git a/connman/tools/stats-tool.c b/connman/tools/stats-tool.c
new file mode 100644
index 0000000..7d117fd
--- /dev/null
+++ b/connman/tools/stats-tool.c
@@ -0,0 +1,915 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2010-2014  BMW Car IT GmbH.
+ *
+ *  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
+
+#define _GNU_SOURCE
+#include <sys/mman.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <string.h>
+
+#include <sys/time.h>
+#include <time.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <errno.h>
+
+#include <glib.h>
+#include <glib/gstdio.h>
+
+#ifdef TEMP_FAILURE_RETRY
+#define TFR TEMP_FAILURE_RETRY
+#else
+#define TFR
+#endif
+
+#define MAGIC 0xFA00B916
+
+struct connman_stats_data {
+	unsigned int rx_packets;
+	unsigned int tx_packets;
+	unsigned int rx_bytes;
+	unsigned int tx_bytes;
+	unsigned int rx_errors;
+	unsigned int tx_errors;
+	unsigned int rx_dropped;
+	unsigned int tx_dropped;
+	unsigned int time;
+};
+
+struct stats_file_header {
+	unsigned int magic;
+	unsigned int begin;
+	unsigned int end;
+	unsigned int home;
+	unsigned int roaming;
+};
+
+struct stats_record {
+	time_t ts;
+	unsigned int roaming;
+	struct connman_stats_data data;
+};
+
+struct stats_file {
+	int fd;
+	char *name;
+	char *addr;
+	size_t len;
+	size_t max_len;
+
+	/* cached values */
+	int max_nr;
+	int nr;
+	struct stats_record *first;
+	struct stats_record *last;
+	struct stats_record *home_first;
+	struct stats_record *roaming_first;
+};
+
+struct stats_iter {
+	struct stats_file *file;
+	struct stats_record *begin;
+	struct stats_record *end;
+	struct stats_record *it;
+};
+
+static gint option_create = 0;
+static gint option_interval = 3;
+static bool option_dump = false;
+static bool option_summary = false;
+static char *option_info_file_name = NULL;
+static time_t option_start_ts = -1;
+static char *option_last_file_name = NULL;
+
+static bool parse_start_ts(const char *key, const char *value,
+					gpointer user_data, GError **error)
+{
+	GTimeVal time_val;
+
+	if (!g_time_val_from_iso8601(value, &time_val))
+		return false;
+
+	option_start_ts = time_val.tv_sec;
+
+	return true;
+}
+
+static GOptionEntry options[] = {
+	{ "create", 'c', 0, G_OPTION_ARG_INT, &option_create,
+			"Create a .data file with NR faked entries", "NR" },
+	{ "interval", 'i', 0, G_OPTION_ARG_INT, &option_interval,
+			"Interval in seconds (used with create)", "INTERVAL" },
+	{ "dump", 'd', 0, G_OPTION_ARG_NONE, &option_dump,
+			"Dump contents of .data file" },
+	{ "summary", 's', 0, G_OPTION_ARG_NONE, &option_summary,
+			"Summary of .data file" },
+	{ "info", 'f', 0, G_OPTION_ARG_FILENAME, &option_info_file_name,
+			".info file name" },
+	{ "startts", 't', 0, G_OPTION_ARG_CALLBACK, parse_start_ts,
+			"Set start time for creating .data file "
+			"(example 2010-11-05T23:00:12Z)", "TS"},
+	{ "last", 'l', 0, G_OPTION_ARG_FILENAME, &option_last_file_name,
+			  "Start values from last .data file" },
+	{ NULL },
+};
+
+static struct stats_file_header *get_hdr(struct stats_file *file)
+{
+	return (struct stats_file_header *)file->addr;
+}
+
+static struct stats_record *get_begin(struct stats_file *file)
+{
+	unsigned int off = get_hdr(file)->begin;
+
+	return (struct stats_record *)(file->addr + off);
+}
+
+static struct stats_record *get_end(struct stats_file *file)
+{
+	unsigned int off = get_hdr(file)->end;
+
+	return (struct stats_record *)(file->addr + off);
+}
+
+static struct stats_record *get_home(struct stats_file *file)
+{
+	struct stats_file_header *hdr;
+
+	hdr = get_hdr(file);
+
+	if (hdr->home == UINT_MAX)
+		return NULL;
+
+	return (struct stats_record *)(file->addr + hdr->home);
+}
+
+static struct stats_record *get_roaming(struct stats_file *file)
+{
+	struct stats_file_header *hdr;
+
+	hdr = get_hdr(file);
+
+	if (hdr->roaming == UINT_MAX)
+		return NULL;
+
+	return (struct stats_record *)(file->addr + hdr->roaming);
+}
+
+static void set_end(struct stats_file *file, struct stats_record *end)
+{
+	struct stats_file_header *hdr;
+
+	hdr = get_hdr(file);
+	hdr->end = (char *)end - file->addr;
+}
+
+static int get_index(struct stats_file *file, struct stats_record *rec)
+{
+	return rec - file->first;
+}
+
+static struct stats_record *get_next(struct stats_file *file,
+					struct stats_record *cur)
+{
+	cur++;
+
+	if (cur > file->last)
+		cur = file->first;
+
+	return cur;
+}
+
+static struct stats_record *get_iterator_begin(struct stats_file *file)
+{
+	return get_next(file, get_begin(file));
+}
+
+static struct stats_record *get_iterator_end(struct stats_file *file)
+{
+	return get_next(file, get_end(file));
+}
+
+static void stats_print_record(struct stats_record *rec)
+{
+	char buffer[30];
+
+	strftime(buffer, 30, "%d-%m-%Y %T", localtime(&rec->ts));
+	printf("%p %lld %s %01d %d %d %d %d %d %d %d %d %d\n",
+		rec, (long long int)rec->ts, buffer,
+		rec->roaming,
+		rec->data.rx_packets,
+		rec->data.tx_packets,
+		rec->data.rx_bytes,
+		rec->data.tx_bytes,
+		rec->data.rx_errors,
+		rec->data.tx_errors,
+		rec->data.rx_dropped,
+		rec->data.tx_dropped,
+		rec->data.time);
+}
+
+static void stats_hdr_info(struct stats_file *file)
+{
+	struct stats_file_header *hdr;
+	struct stats_record *begin, *end, *home, *roaming;
+	unsigned int home_idx, roaming_idx;
+
+	hdr = get_hdr(file);
+	begin = get_begin(file);
+	end = get_end(file);
+
+	home = get_home(file);
+	if (!home)
+		home_idx = UINT_MAX;
+	else
+		home_idx = get_index(file, home);
+
+	roaming = get_roaming(file);
+	if (!roaming)
+		roaming_idx = UINT_MAX;
+	else
+		roaming_idx = get_index(file, roaming);
+
+	printf("Data Structure Sizes\n");
+	printf("  sizeof header   %zd/0x%02zx\n",
+		sizeof(struct stats_file_header),
+		sizeof(struct stats_file_header));
+	printf("  sizeof entry    %zd/0%02zx\n\n",
+		sizeof(struct stats_record),
+		sizeof(struct stats_record));
+
+	printf("File\n");
+	printf("  addr            %p\n",  file->addr);
+	printf("  len             %zd\n", file->len);
+
+	printf("  max nr entries  %d\n", file->max_nr);
+	printf("  nr entries      %d\n\n", file->nr);
+
+	printf("Header\n");
+	printf("  magic           0x%08x\n", hdr->magic);
+	printf("  begin           [%d] 0x%08x\n",
+		get_index(file, begin), hdr->begin);
+	printf("  end             [%d] 0x%08x\n",
+		get_index(file, end), hdr->end);
+	printf("  home            [%d] 0x%08x\n",
+		home_idx, hdr->home);
+	printf("  roaming         [%d] 0x%08x\n\n",
+		roaming_idx, hdr->roaming);
+
+
+	printf("Pointers\n");
+	printf("  hdr             %p\n", hdr);
+	printf("  begin           %p\n", begin);
+	printf("  end             %p\n", end);
+	printf("  home            %p\n", home);
+	printf("  romaing         %p\n", roaming);
+	printf("  first           %p\n", file->first);
+	printf("  last            %p\n\n", file->last);
+}
+
+static void stats_print_entries(struct stats_file *file)
+{
+	struct stats_record *it;
+	int i;
+
+	printf("[ idx] ptr ts ts rx_packets tx_packets rx_bytes "
+		"tx_bytes rx_errors tx_errors rx_dropped tx_dropped time\n\n");
+
+	for (i = 0, it = file->first; it <= file->last; it++, i++) {
+		printf("[%04d] ", i);
+		stats_print_record(it);
+	}
+}
+
+static void stats_print_rec_diff(struct stats_record *begin,
+					struct stats_record *end)
+{
+	printf("\trx_packets: %d\n",
+		end->data.rx_packets - begin->data.rx_packets);
+	printf("\ttx_packets: %d\n",
+		end->data.tx_packets - begin->data.tx_packets);
+	printf("\trx_bytes:   %d\n",
+		end->data.rx_bytes - begin->data.rx_bytes);
+	printf("\ttx_bytes:   %d\n",
+		end->data.tx_bytes - begin->data.tx_bytes);
+	printf("\trx_errors:  %d\n",
+		end->data.rx_errors - begin->data.rx_errors);
+	printf("\ttx_errors:  %d\n",
+		end->data.tx_errors - begin->data.tx_errors);
+	printf("\trx_dropped: %d\n",
+		end->data.rx_dropped - begin->data.rx_dropped);
+	printf("\ttx_dropped: %d\n",
+		end->data.tx_dropped - begin->data.tx_dropped);
+	printf("\ttime:       %d\n",
+		end->data.time - begin->data.time);
+}
+
+static void stats_print_diff(struct stats_file *file)
+{
+	struct stats_record *begin, *end;
+
+	begin = get_begin(file);
+	begin = get_next(file, begin);
+	end = get_end(file);
+
+	printf("\n(begin + 1)\n");
+	printf("\t[%04d] ", get_index(file, begin));
+	stats_print_record(begin);
+	printf("end\n");
+	printf("\t[%04d] ", get_index(file, end));
+	stats_print_record(end);
+
+	if (file->home_first && get_home(file)) {
+		printf("\nhome\n");
+		stats_print_rec_diff(file->home_first, get_home(file));
+	}
+
+	if (file->roaming_first && get_roaming(file)) {
+		printf("\roaming\n");
+		stats_print_rec_diff(file->roaming_first, get_roaming(file));
+	}
+}
+
+static void update_max_nr_entries(struct stats_file *file)
+{
+	file->max_nr = (file->len - sizeof(struct stats_file_header)) /
+		sizeof(struct stats_record);
+}
+
+static void update_nr_entries(struct stats_file *file)
+{
+	struct stats_record *begin, *end;
+	int nr;
+
+	begin = get_begin(file);
+	end = get_end(file);
+
+	nr = get_index(file, end) - get_index(file, begin);
+
+	if (nr < 0)
+		nr += file->max_nr;
+
+	file->nr = nr;
+}
+
+static void update_first(struct stats_file *file)
+{
+	file->first = (struct stats_record *)(file->addr +
+					sizeof(struct stats_file_header));
+}
+
+static void update_last(struct stats_file *file)
+{
+	struct stats_record *last;
+
+	last = file->first;
+	last += file->max_nr - 1;
+
+	file->last = last;
+}
+
+static int stats_file_update_cache(struct stats_file *file)
+{
+	struct stats_record *it, *end;
+
+	update_max_nr_entries(file);
+	update_nr_entries(file);
+	update_first(file);
+	update_last(file);
+	file->home_first = NULL;
+	file->roaming_first = NULL;
+
+	end = get_iterator_end(file);
+	for (it = get_iterator_begin(file);
+			it != end;
+			it = get_next(file, it)) {
+
+		if (!file->home_first && it->roaming == 0)
+			file->home_first = it;
+
+		if (!file->roaming_first && it->roaming == 1)
+			file->roaming_first = it;
+
+		if (file->home_first && file->roaming_first)
+			break;
+	}
+
+	return 0;
+}
+
+static int stats_file_remap(struct stats_file *file, size_t size)
+{
+	size_t page_size, new_size;
+	void *addr;
+	int err;
+
+	page_size = sysconf(_SC_PAGESIZE);
+	new_size = (size + page_size - 1) & ~(page_size - 1);
+
+	err = ftruncate(file->fd, new_size);
+	if (err < 0) {
+		fprintf(stderr, "ftrunctate error %s for %s",
+				strerror(errno), file->name);
+		return -errno;
+	}
+
+	if (!file->addr) {
+		addr = mmap(NULL, new_size, PROT_READ | PROT_WRITE,
+				MAP_SHARED, file->fd, 0);
+	} else {
+		addr = mremap(file->addr, file->len, new_size, MREMAP_MAYMOVE);
+	}
+
+	if (addr == MAP_FAILED) {
+		fprintf(stderr, "mmap error %s for %s\n",
+			strerror(errno), file->name);
+		return -errno;
+	}
+
+	file->addr = addr;
+	file->len = new_size;
+	file->max_len = new_size;
+
+	return 0;
+}
+
+static int stats_open(struct stats_file *file, const char *name)
+{
+	struct stats_file_header *hdr;
+	struct stat tm;
+	int err;
+	size_t size = 0;
+
+	bzero(file, sizeof(struct stats_file));
+
+	if (name) {
+		file->name = g_strdup(name);
+
+		file->fd = TFR(open(file->name,
+					O_RDWR | O_CREAT | O_CLOEXEC, 0644));
+		if (file->fd == -1) {
+			fprintf(stderr, "open error %s for %s\n",
+				strerror(errno), file->name);
+			return -errno;
+		}
+
+		err = fstat(file->fd, &tm);
+		if (err < 0) {
+			fprintf(stderr, "fstat error %s for %s\n",
+				strerror(errno), file->name);
+			return err;
+		}
+
+		size = (size_t)tm.st_size;
+	} else {
+		file->name = g_strdup("stats.XXXXXX.tmp");
+		file->fd = g_mkstemp_full(file->name, O_RDWR | O_CREAT, 0644);
+		if (file->fd == -1) {
+			fprintf(stderr, "creating tmp failed\n");
+			return -1;
+		}
+	}
+
+	if (size == 0)
+		size = sysconf(_SC_PAGESIZE);
+
+	err = stats_file_remap(file, size);
+	if (err < 0) {
+		fprintf(stderr, "remap failed\n");
+		return err;
+	}
+
+	/* Initialize new file */
+	hdr = get_hdr(file);
+	if (hdr->magic != MAGIC ||
+			hdr->begin < sizeof(struct stats_file_header) ||
+			hdr->end < sizeof(struct stats_file_header) ||
+			hdr->home < sizeof(struct stats_file_header) ||
+			hdr->roaming < sizeof(struct stats_file_header) ||
+			hdr->begin > file->len ||
+			hdr->end > file->len) {
+		hdr->magic = MAGIC;
+		hdr->begin = sizeof(struct stats_file_header);
+		hdr->end = sizeof(struct stats_file_header);
+		hdr->home = UINT_MAX;
+		hdr->roaming = UINT_MAX;
+
+	}
+	stats_file_update_cache(file);
+
+	return 0;
+}
+
+static void stats_close(struct stats_file *file)
+{
+	munmap(file->addr, file->len);
+	close(file->fd);
+	g_free(file->name);
+}
+
+static int stats_create(struct stats_file *file, unsigned int nr,
+			unsigned int interval, time_t start_ts,
+			struct stats_record *start)
+{
+	unsigned int i;
+	int err;
+	struct stats_record *cur, *next;
+	struct stats_file_header *hdr;
+	unsigned int pkt;
+	unsigned int step_ts;
+	unsigned int roaming = FALSE;
+
+	hdr = get_hdr(file);
+
+	hdr->magic = MAGIC;
+	hdr->begin = sizeof(struct stats_file_header);
+	hdr->end = sizeof(struct stats_file_header);
+	hdr->home = UINT_MAX;
+	hdr->roaming = UINT_MAX;
+
+	stats_file_update_cache(file);
+
+	if (start) {
+		struct stats_record *rec;
+
+		rec = get_end(file);
+		memcpy(rec, start, sizeof(struct stats_record));
+	} else {
+		get_end(file)->ts = start_ts;
+	}
+
+	for (i = 0; i < nr; i++) {
+		if (file->last == get_end(file)) {
+			err = stats_file_remap(file, file->len +
+						sysconf(_SC_PAGESIZE));
+			if (err < 0)
+				return err;
+
+			stats_file_update_cache(file);
+		}
+		cur = get_end(file);
+		next = get_next(file, cur);
+
+		step_ts = (rand() % interval);
+		if (step_ts == 0)
+			step_ts = 1;
+
+		next->ts = cur->ts + step_ts;
+		next->roaming = roaming;
+		next->data.time = cur->data.time + step_ts;
+
+		next->data.rx_packets = cur->data.rx_packets;
+		next->data.rx_bytes = cur->data.rx_bytes;
+
+		if (rand() % 3 == 0) {
+			pkt = rand() % 5;
+			next->data.rx_packets += pkt;
+			next->data.rx_bytes += pkt * (rand() % 1500);
+		}
+
+		next->data.tx_packets = cur->data.tx_packets;
+		next->data.tx_bytes = cur->data.tx_bytes;
+
+		if (rand() % 3 == 0) {
+			pkt = rand() % 5;
+			next->data.tx_packets += pkt;
+			next->data.tx_bytes += pkt * (rand() % 1500);
+		}
+
+		set_end(file, next);
+
+		if ((rand() % 50) == 0)
+			roaming = roaming ? FALSE : TRUE;
+
+	}
+
+	return 0;
+}
+
+static struct stats_record *get_next_record(struct stats_iter *iter)
+{
+	if (iter->it != iter->end) {
+		struct stats_record *tmp;
+
+		tmp = iter->it;
+		iter->it = get_next(iter->file, iter->it);
+
+		return tmp;
+	}
+
+	return NULL;
+}
+
+static int append_record(struct stats_file *file,
+				struct stats_record *rec)
+{
+	struct stats_record *cur, *next;
+	int err;
+
+	if (file->last == get_end(file)) {
+		err = stats_file_remap(file, file->len +
+					sysconf(_SC_PAGESIZE));
+		if (err < 0)
+			return err;
+
+		stats_file_update_cache(file);
+	}
+
+	cur = get_end(file);
+	next = get_next(file, cur);
+
+	memcpy(next, rec, sizeof(struct stats_record));
+
+	set_end(file, next);
+
+	return 0;
+}
+
+static struct stats_record *process_file(struct stats_iter *iter,
+					struct stats_file *temp_file,
+					struct stats_record *cur,
+					GDate *date_change_step_size,
+					int account_period_offset)
+{
+	struct stats_record *home, *roaming;
+	struct stats_record *next;
+
+	home = NULL;
+	roaming = NULL;
+
+	if (!cur)
+		cur = get_next_record(iter);
+	next = get_next_record(iter);
+
+	while (next) {
+		GDate date_cur;
+		GDate date_next;
+		int append;
+
+		append = FALSE;
+
+		if (cur->roaming)
+			roaming = cur;
+		else
+			home = cur;
+
+		g_date_set_time_t(&date_cur, cur->ts);
+		g_date_set_time_t(&date_next, next->ts);
+
+		if (g_date_compare(&date_cur, date_change_step_size) < 0) {
+			/* month period size */
+			GDateDay day_cur, day_next;
+			GDateMonth month_cur, month_next;
+
+			month_cur = g_date_get_month(&date_cur);
+			month_next = g_date_get_month(&date_next);
+
+			day_cur = g_date_get_day(&date_cur);
+			day_next = g_date_get_day(&date_next);
+
+			if (day_cur == day_next && month_cur != month_next)
+				append = TRUE;
+			else if (day_cur < account_period_offset
+					&& day_next >= account_period_offset)
+				append = TRUE;
+		} else {
+			/* day period size */
+			if (g_date_days_between(&date_cur, &date_next) > 0)
+				append = TRUE;
+		}
+
+		if (append) {
+			if (home) {
+				append_record(temp_file, home);
+				home = NULL;
+			}
+
+			if (roaming) {
+				append_record(temp_file, roaming);
+				roaming = NULL;
+			}
+		}
+
+		cur = next;
+		next = get_next_record(iter);
+	}
+
+	return cur;
+}
+
+static int summarize(struct stats_file *data_file,
+			struct stats_file *history_file,
+			struct stats_file *temp_file,
+			int account_period_offset)
+{
+	struct stats_iter data_iter;
+	struct stats_iter history_iter;
+	struct stats_record *cur, *next;
+
+	GDate today, date_change_step_size;
+
+	/*
+	 * First calculate the date when switch from monthly
+	 * accounting period size to daily size
+	 */
+	g_date_set_time_t(&today, time(NULL));
+
+	date_change_step_size = today;
+	if (g_date_get_day(&today) - account_period_offset >= 0)
+		g_date_subtract_months(&date_change_step_size, 2);
+	else
+		g_date_subtract_months(&date_change_step_size, 3);
+
+	g_date_set_day(&date_change_step_size, account_period_offset);
+
+
+	/* Now process history file */
+	cur = NULL;
+
+	if (history_file) {
+		history_iter.file = history_file;
+		history_iter.begin = get_iterator_begin(history_iter.file);
+		history_iter.end = get_iterator_end(history_iter.file);
+		history_iter.it = history_iter.begin;
+
+		cur = process_file(&history_iter, temp_file, NULL,
+					&date_change_step_size,
+					account_period_offset);
+	}
+
+	data_iter.file = data_file;
+	data_iter.begin = get_iterator_begin(data_iter.file);
+	data_iter.end = get_iterator_end(data_iter.file);
+	data_iter.it = data_iter.begin;
+
+	/*
+	 * Ensure date_file records are newer than the history_file
+	 * record
+	 */
+	if (cur) {
+		next = get_next_record(&data_iter);
+		while (next && cur->ts > next->ts)
+			next = get_next_record(&data_iter);
+	}
+
+	/* And finally process the new data records */
+	cur = process_file(&data_iter, temp_file, cur,
+				&date_change_step_size, account_period_offset);
+
+	if (cur)
+		append_record(temp_file, cur);
+
+	return 0;
+}
+
+static void swap_and_close_files(struct stats_file *history_file,
+			struct stats_file *temp_file)
+{
+	munmap(history_file->addr, history_file->len);
+	munmap(temp_file->addr, temp_file->len);
+
+	TFR(close(temp_file->fd));
+
+	unlink(history_file->name);
+
+	if (link(temp_file->name, history_file->name) < 0)
+		return;
+
+	unlink(temp_file->name);
+	TFR(close(history_file->fd));
+}
+
+static void history_file_update(struct stats_file *data_file,
+				const char *history_file_name)
+{
+	struct stats_file _history_file;
+	struct stats_file tempory_file;
+
+	struct stats_file *history_file = NULL;
+
+	if (stats_open(&_history_file, history_file_name) == 0)
+		history_file = &_history_file;
+
+	if (stats_open(&tempory_file, NULL) < 0) {
+		if (history_file)
+			stats_close(history_file);
+		return;
+	}
+
+	summarize(data_file, history_file, &tempory_file, 13);
+
+	swap_and_close_files(history_file, &tempory_file);
+}
+
+int main(int argc, char *argv[])
+{
+	GOptionContext *context;
+	GError *error = NULL;
+
+	struct stats_file_header *hdr;
+	struct stats_file data, *data_file;
+	struct stats_record *rec;
+	time_t start_ts;
+	int err;
+
+	rec = NULL;
+
+	data_file = &data;
+
+	putenv("TZ=GMT0");
+
+	context = g_option_context_new(NULL);
+	g_option_context_add_main_entries(context, options, NULL);
+
+	if (!g_option_context_parse(context, &argc, &argv, &error)) {
+		if (error) {
+			g_printerr("%s\n", error->message);
+			g_error_free(error);
+		} else
+			g_printerr("An unknown error occurred\n");
+		exit(1);
+	}
+
+	g_option_context_free(context);
+
+	if (argc < 2) {
+		printf("Usage: %s [FILENAME]\n", argv[0]);
+		exit(0);
+	}
+
+	err = stats_open(data_file, argv[1]);
+	if (err < 0) {
+		fprintf(stderr, "failed open file %s\n", argv[1]);
+		exit(1);
+	}
+
+	if (option_last_file_name) {
+		struct stats_file last;
+		if (stats_open(&last, option_last_file_name) < 0) {
+			fprintf(stderr, "failed open file %s\n",
+				option_last_file_name);
+			exit(1);
+		}
+
+		rec = get_end(&last);
+	}
+
+	if (option_start_ts == -1)
+		start_ts = time(NULL);
+	else
+		start_ts = option_start_ts;
+
+	if (option_create > 0)
+		stats_create(data_file, option_create, option_interval,
+				start_ts, rec);
+
+	hdr = get_hdr(data_file);
+	if (hdr->magic != MAGIC) {
+		fprintf(stderr, "header file magic test failed\n");
+		goto err;
+	}
+
+	stats_file_update_cache(data_file);
+
+	stats_hdr_info(data_file);
+
+	if (option_dump)
+		stats_print_entries(data_file);
+
+	if (option_summary)
+		stats_print_diff(data_file);
+
+	if (option_info_file_name)
+		history_file_update(data_file, option_info_file_name);
+
+err:
+	stats_close(data_file);
+
+	return 0;
+}
diff --git a/connman/tools/supplicant-dbus.c b/connman/tools/supplicant-dbus.c
new file mode 100644
index 0000000..d409da2
--- /dev/null
+++ b/connman/tools/supplicant-dbus.c
@@ -0,0 +1,411 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2012  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 <string.h>
+#include <dbus/dbus.h>
+
+#include "supplicant-dbus.h"
+
+#define TIMEOUT 5000
+
+static DBusConnection *connection = NULL;
+
+void supplicant_dbus_setup(DBusConnection *conn)
+{
+	connection = conn;
+}
+
+void supplicant_dbus_array_foreach(DBusMessageIter *iter,
+				supplicant_dbus_array_function function,
+							void *user_data)
+{
+	DBusMessageIter entry;
+
+	if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_ARRAY)
+		return;
+
+	dbus_message_iter_recurse(iter, &entry);
+
+	while (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_INVALID) {
+		if (function)
+			function(&entry, user_data);
+
+		dbus_message_iter_next(&entry);
+	}
+}
+
+void supplicant_dbus_property_foreach(DBusMessageIter *iter,
+				supplicant_dbus_property_function function,
+							void *user_data)
+{
+	DBusMessageIter dict;
+
+	if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_ARRAY)
+		return;
+
+	dbus_message_iter_recurse(iter, &dict);
+
+	while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
+		DBusMessageIter entry, value;
+		const char *key;
+
+		dbus_message_iter_recurse(&dict, &entry);
+
+		if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING)
+			return;
+
+		dbus_message_iter_get_basic(&entry, &key);
+		dbus_message_iter_next(&entry);
+
+		if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_VARIANT)
+			return;
+
+		dbus_message_iter_recurse(&entry, &value);
+
+		if (key) {
+			if (strcmp(key, "Properties") == 0)
+				supplicant_dbus_property_foreach(&value,
+							function, user_data);
+			else if (function)
+				function(key, &value, user_data);
+		}
+
+		dbus_message_iter_next(&dict);
+	}
+}
+
+struct property_get_data {
+	supplicant_dbus_property_function function;
+	void *user_data;
+};
+
+static void property_get_all_reply(DBusPendingCall *call, void *user_data)
+{
+	struct property_get_data *data = user_data;
+	DBusMessage *reply;
+	DBusMessageIter iter;
+
+	reply = dbus_pending_call_steal_reply(call);
+
+	if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR)
+		goto done;
+
+	if (!dbus_message_iter_init(reply, &iter))
+		goto done;
+
+	supplicant_dbus_property_foreach(&iter, data->function,
+							data->user_data);
+
+	if (data->function)
+		data->function(NULL, NULL, data->user_data);
+
+done:
+	dbus_message_unref(reply);
+
+	dbus_pending_call_unref(call);
+}
+
+int supplicant_dbus_property_get_all(const char *path, const char *interface,
+				supplicant_dbus_property_function function,
+							void *user_data)
+{
+	struct property_get_data *data;
+	DBusMessage *message;
+	DBusPendingCall *call;
+
+	if (!connection)
+		return -EINVAL;
+
+	if (!path || !interface)
+		return -EINVAL;
+
+	data = dbus_malloc0(sizeof(*data));
+	if (!data)
+		return -ENOMEM;
+
+	message = dbus_message_new_method_call(SUPPLICANT_SERVICE, path,
+					DBUS_INTERFACE_PROPERTIES, "GetAll");
+	if (!message) {
+		dbus_free(data);
+		return -ENOMEM;
+	}
+
+	dbus_message_set_auto_start(message, FALSE);
+
+	dbus_message_append_args(message, DBUS_TYPE_STRING, &interface, NULL);
+
+	if (!dbus_connection_send_with_reply(connection, message,
+							&call, TIMEOUT)) {
+		dbus_message_unref(message);
+		dbus_free(data);
+		return -EIO;
+	}
+
+	if (!call) {
+		dbus_message_unref(message);
+		dbus_free(data);
+		return -EIO;
+	}
+
+	data->function = function;
+	data->user_data = user_data;
+
+	dbus_pending_call_set_notify(call, property_get_all_reply,
+							data, dbus_free);
+
+	dbus_message_unref(message);
+
+	return 0;
+}
+
+struct property_set_data {
+	supplicant_dbus_result_function function;
+	void *user_data;
+};
+
+static void property_set_reply(DBusPendingCall *call, void *user_data)
+{
+	struct property_set_data *data = user_data;
+	DBusMessage *reply;
+	DBusMessageIter iter;
+	const char *error;
+
+	reply = dbus_pending_call_steal_reply(call);
+
+	if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR)
+		error = dbus_message_get_error_name(reply);
+	else
+		error = NULL;
+
+	if (!dbus_message_iter_init(reply, &iter))
+		goto done;
+
+	if (data->function)
+		data->function(error, &iter, data->user_data);
+
+done:
+	dbus_message_unref(reply);
+
+	dbus_pending_call_unref(call);
+}
+
+int supplicant_dbus_property_set(const char *path, const char *interface,
+				const char *key, const char *signature,
+				supplicant_dbus_setup_function setup,
+				supplicant_dbus_result_function function,
+							void *user_data)
+{
+	struct property_set_data *data;
+	DBusMessage *message;
+	DBusMessageIter iter, value;
+	DBusPendingCall *call;
+
+	if (!connection)
+		return -EINVAL;
+
+	if (!path || !interface)
+		return -EINVAL;
+
+	if (!key || !signature || !setup)
+		return -EINVAL;
+
+	data = dbus_malloc0(sizeof(*data));
+	if (!data)
+		return -ENOMEM;
+
+	message = dbus_message_new_method_call(SUPPLICANT_SERVICE, path,
+					DBUS_INTERFACE_PROPERTIES, "Set");
+	if (!message) {
+		dbus_free(data);
+		return -ENOMEM;
+	}
+
+	dbus_message_set_auto_start(message, FALSE);
+
+	dbus_message_iter_init_append(message, &iter);
+	dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &interface);
+	dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key);
+
+	dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT,
+							signature, &value);
+	setup(&value, user_data);
+	dbus_message_iter_close_container(&iter, &value);
+
+	if (!dbus_connection_send_with_reply(connection, message,
+						&call, TIMEOUT)) {
+		dbus_message_unref(message);
+		dbus_free(data);
+		return -EIO;
+	}
+
+	if (!call) {
+		dbus_message_unref(message);
+		dbus_free(data);
+		return -EIO;
+	}
+
+	data->function = function;
+	data->user_data = user_data;
+
+	dbus_pending_call_set_notify(call, property_set_reply,
+							data, dbus_free);
+
+	dbus_message_unref(message);
+
+	return 0;
+}
+
+struct method_call_data {
+	supplicant_dbus_result_function function;
+	void *user_data;
+};
+
+static void method_call_reply(DBusPendingCall *call, void *user_data)
+{
+	struct method_call_data *data = user_data;
+	DBusMessage *reply;
+	DBusMessageIter iter;
+	const char *error;
+
+	reply = dbus_pending_call_steal_reply(call);
+
+	if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR)
+		error = dbus_message_get_error_name(reply);
+	else
+		error = NULL;
+
+	dbus_message_iter_init(reply, &iter);
+
+	if (data->function)
+		data->function(error, &iter, data->user_data);
+
+	dbus_message_unref(reply);
+
+	dbus_pending_call_unref(call);
+}
+
+int supplicant_dbus_method_call(const char *path,
+				const char *interface, const char *method,
+				supplicant_dbus_setup_function setup,
+				supplicant_dbus_result_function function,
+							void *user_data)
+{
+	struct method_call_data *data;
+	DBusMessage *message;
+	DBusMessageIter iter;
+	DBusPendingCall *call;
+
+	if (!connection)
+		return -EINVAL;
+
+	if (!path || !interface || !method)
+		return -EINVAL;
+
+	data = dbus_malloc0(sizeof(*data));
+	if (!data)
+		return -ENOMEM;
+
+	message = dbus_message_new_method_call(SUPPLICANT_SERVICE, path,
+							interface, method);
+	if (!message) {
+		dbus_free(data);
+		return -ENOMEM;
+	}
+
+	dbus_message_set_auto_start(message, FALSE);
+
+	dbus_message_iter_init_append(message, &iter);
+	if (setup)
+		setup(&iter, user_data);
+
+	if (!dbus_connection_send_with_reply(connection, message,
+						&call, TIMEOUT)) {
+		dbus_message_unref(message);
+		dbus_free(data);
+		return -EIO;
+	}
+
+	if (!call) {
+		dbus_message_unref(message);
+		dbus_free(data);
+		return -EIO;
+	}
+
+	data->function = function;
+	data->user_data = user_data;
+
+	dbus_pending_call_set_notify(call, method_call_reply,
+							data, dbus_free);
+
+	dbus_message_unref(message);
+
+	return 0;
+}
+
+void supplicant_dbus_property_append_basic(DBusMessageIter *iter,
+					const char *key, int type, void *val)
+{
+	DBusMessageIter value;
+	const char *signature;
+
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &key);
+
+	switch (type) {
+	case DBUS_TYPE_BOOLEAN:
+		signature = DBUS_TYPE_BOOLEAN_AS_STRING;
+		break;
+	case DBUS_TYPE_STRING:
+		signature = DBUS_TYPE_STRING_AS_STRING;
+		break;
+	case DBUS_TYPE_BYTE:
+		signature = DBUS_TYPE_BYTE_AS_STRING;
+		break;
+	case DBUS_TYPE_UINT16:
+		signature = DBUS_TYPE_UINT16_AS_STRING;
+		break;
+	case DBUS_TYPE_INT16:
+		signature = DBUS_TYPE_INT16_AS_STRING;
+		break;
+	case DBUS_TYPE_UINT32:
+		signature = DBUS_TYPE_UINT32_AS_STRING;
+		break;
+	case DBUS_TYPE_INT32:
+		signature = DBUS_TYPE_INT32_AS_STRING;
+		break;
+	case DBUS_TYPE_OBJECT_PATH:
+		signature = DBUS_TYPE_OBJECT_PATH_AS_STRING;
+		break;
+	default:
+		signature = DBUS_TYPE_VARIANT_AS_STRING;
+		break;
+	}
+
+	dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
+							signature, &value);
+	dbus_message_iter_append_basic(&value, type, val);
+	dbus_message_iter_close_container(iter, &value);
+}
diff --git a/connman/tools/supplicant-dbus.h b/connman/tools/supplicant-dbus.h
new file mode 100644
index 0000000..4452894
--- /dev/null
+++ b/connman/tools/supplicant-dbus.h
@@ -0,0 +1,93 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2012  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
+ *
+ */
+
+#include <dbus/dbus.h>
+
+#define SUPPLICANT_SERVICE	"fi.w1.wpa_supplicant1"
+#define SUPPLICANT_INTERFACE	"fi.w1.wpa_supplicant1"
+#define SUPPLICANT_PATH		"/fi/w1/wpa_supplicant1"
+
+typedef void (* supplicant_dbus_array_function) (DBusMessageIter *iter,
+							void *user_data);
+
+typedef void (* supplicant_dbus_property_function) (const char *key,
+				DBusMessageIter *iter, void *user_data);
+
+typedef void (* supplicant_dbus_setup_function) (DBusMessageIter *iter,
+							void *user_data);
+
+typedef void (* supplicant_dbus_result_function) (const char *error,
+				DBusMessageIter *iter, void *user_data);
+
+void supplicant_dbus_setup(DBusConnection *conn);
+
+void supplicant_dbus_array_foreach(DBusMessageIter *iter,
+				supplicant_dbus_array_function function,
+							void *user_data);
+
+void supplicant_dbus_property_foreach(DBusMessageIter *iter,
+				supplicant_dbus_property_function function,
+							void *user_data);
+
+int supplicant_dbus_property_get_all(const char *path, const char *interface,
+				supplicant_dbus_property_function function,
+							void *user_data);
+
+int supplicant_dbus_property_set(const char *path, const char *interface,
+				const char *key, const char *signature,
+				supplicant_dbus_setup_function setup,
+				supplicant_dbus_result_function function,
+							void *user_data);
+
+int supplicant_dbus_method_call(const char *path,
+				const char *interface, const char *method,
+				supplicant_dbus_setup_function setup,
+				supplicant_dbus_result_function function,
+							void *user_data);
+
+void supplicant_dbus_property_append_basic(DBusMessageIter *iter,
+					const char *key, int type, void *val);
+
+static inline void supplicant_dbus_dict_open(DBusMessageIter *iter,
+							DBusMessageIter *dict)
+{
+	dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY,
+			DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+			DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
+			DBUS_DICT_ENTRY_END_CHAR_AS_STRING, dict);
+}
+
+static inline void supplicant_dbus_dict_close(DBusMessageIter *iter,
+							DBusMessageIter *dict)
+{
+	dbus_message_iter_close_container(iter, dict);
+}
+
+static inline void supplicant_dbus_dict_append_basic(DBusMessageIter *dict,
+					const char *key, int type, void *val)
+{
+	DBusMessageIter entry;
+
+	dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
+								NULL, &entry);
+	supplicant_dbus_property_append_basic(&entry, key, type, val);
+	dbus_message_iter_close_container(dict, &entry);
+}
diff --git a/connman/tools/supplicant-test.c b/connman/tools/supplicant-test.c
new file mode 100644
index 0000000..a640807
--- /dev/null
+++ b/connman/tools/supplicant-test.c
@@ -0,0 +1,198 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2012  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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <signal.h>
+#include <syslog.h>
+
+#include <gdbus.h>
+
+#include "supplicant.h"
+
+#define DBG(fmt, arg...) do { \
+	syslog(LOG_DEBUG, "%s() " fmt, __FUNCTION__ , ## arg); \
+} while (0)
+
+static void create_callback(int result, struct supplicant_interface *interface,
+							void *user_data)
+{
+	DBG("* result %d ifname %s", result,
+				supplicant_interface_get_ifname(interface));
+
+	if (result < 0)
+		return;
+
+	//supplicant_set_debug_level(1);
+}
+
+static void system_ready(void)
+{
+	DBG("*");
+
+	supplicant_interface_create("wlan0", "nl80211,wext",
+						create_callback, NULL);
+}
+
+static void system_killed(void)
+{
+	DBG("*");
+}
+
+static void scan_callback(int result, void *user_data)
+{
+	DBG("* result %d", result);
+
+	if (result < 0)
+		return;
+}
+
+static void interface_added(struct supplicant_interface *interface)
+{
+	const char *ifname = supplicant_interface_get_ifname(interface);
+	const char *driver = supplicant_interface_get_driver(interface);
+
+	DBG("* ifname %s driver %s", ifname, driver);
+
+	if (supplicant_interface_scan(interface, scan_callback, NULL) < 0)
+		DBG("scan failed");
+}
+
+static void interface_removed(struct supplicant_interface *interface)
+{
+	const char *ifname = supplicant_interface_get_ifname(interface);
+
+	DBG("* ifname %s", ifname);
+}
+
+static void scan_started(struct supplicant_interface *interface)
+{
+	const char *ifname = supplicant_interface_get_ifname(interface);
+
+	DBG("* ifname %s", ifname);
+}
+
+static void scan_finished(struct supplicant_interface *interface)
+{
+	const char *ifname = supplicant_interface_get_ifname(interface);
+
+	DBG("* ifname %s", ifname);
+}
+
+static void network_added(struct supplicant_network *network)
+{
+	const char *name = supplicant_network_get_name(network);
+
+	DBG("* name %s", name);
+
+	DBG("* %s", supplicant_network_get_identifier(network));
+}
+
+static void network_removed(struct supplicant_network *network)
+{
+	const char *name = supplicant_network_get_name(network);
+
+	DBG("* name %s", name);
+}
+
+static const struct supplicant_callbacks callbacks = {
+	.system_ready		= system_ready,
+	.system_killed		= system_killed,
+	.interface_added	= interface_added,
+	.interface_removed	= interface_removed,
+	.scan_started		= scan_started,
+	.scan_finished		= scan_finished,
+	.network_added		= network_added,
+	.network_removed	= network_removed,
+};
+
+static GMainLoop *main_loop = NULL;
+
+static void sig_term(int sig)
+{
+	syslog(LOG_INFO, "Terminating");
+
+	g_main_loop_quit(main_loop);
+}
+
+static void disconnect_callback(DBusConnection *conn, void *user_data)
+{
+	syslog(LOG_ERR, "D-Bus disconnect");
+
+	g_main_loop_quit(main_loop);
+}
+
+int main(int argc, char *argv[])
+{
+	DBusConnection *conn;
+	DBusError err;
+	struct sigaction sa;
+
+	main_loop = g_main_loop_new(NULL, FALSE);
+
+	dbus_error_init(&err);
+
+	conn = g_dbus_setup_bus(DBUS_BUS_SYSTEM, NULL, &err);
+	if (!conn) {
+		if (dbus_error_is_set(&err)) {
+			fprintf(stderr, "%s\n", err.message);
+			dbus_error_free(&err);
+		} else
+			fprintf(stderr, "Can't register with system bus\n");
+		exit(1);
+	}
+
+	openlog("supplicant", LOG_NDELAY | LOG_PERROR, LOG_USER);
+
+	g_dbus_set_disconnect_function(conn, disconnect_callback, NULL, NULL);
+
+	memset(&sa, 0, sizeof(sa));
+	sa.sa_handler = sig_term;
+	sigaction(SIGINT, &sa, NULL);
+	sigaction(SIGTERM, &sa, NULL);
+
+	syslog(LOG_INFO, "Startup");
+
+	if (supplicant_register(&callbacks) < 0) {
+		syslog(LOG_ERR, "Failed to init supplicant");
+		goto done;
+	}
+
+	g_main_loop_run(main_loop);
+
+	supplicant_unregister(&callbacks);
+
+done:
+	syslog(LOG_INFO, "Exit");
+
+	dbus_connection_unref(conn);
+
+	g_main_loop_unref(main_loop);
+
+	closelog();
+
+	return 0;
+}
diff --git a/connman/tools/supplicant.c b/connman/tools/supplicant.c
new file mode 100644
index 0000000..e2e6fea
--- /dev/null
+++ b/connman/tools/supplicant.c
@@ -0,0 +1,1939 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2012  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 <string.h>
+#include <stdint.h>
+#include <syslog.h>
+
+#include <glib.h>
+#include <gdbus.h>
+
+#include "supplicant-dbus.h"
+#include "supplicant.h"
+
+#define DBG(fmt, arg...) do { \
+	syslog(LOG_DEBUG, "%s() " fmt, __FUNCTION__ , ## arg); \
+} while (0)
+
+#define TIMEOUT 5000
+
+#define IEEE80211_CAP_ESS	0x0001
+#define IEEE80211_CAP_IBSS	0x0002
+#define IEEE80211_CAP_PRIVACY	0x0010
+
+static DBusConnection *connection;
+
+static const struct supplicant_callbacks *callbacks_pointer;
+
+static dbus_bool_t system_available = FALSE;
+static dbus_bool_t system_ready = FALSE;
+
+static dbus_int32_t debug_level = 0;
+static dbus_bool_t debug_timestamp = FALSE;
+static dbus_bool_t debug_showkeys = FALSE;
+
+static const char *debug_strings[] = {
+	"msgdump", "debug", "info", "warning", "error", NULL
+};
+
+static unsigned int eap_methods;
+
+struct strvalmap {
+	const char *str;
+	unsigned int val;
+};
+
+static struct strvalmap eap_method_map[] = {
+	{ "MD5",	SUPPLICANT_EAP_METHOD_MD5	},
+	{ "TLS",	SUPPLICANT_EAP_METHOD_TLS	},
+	{ "MSCHAPV2",	SUPPLICANT_EAP_METHOD_MSCHAPV2	},
+	{ "PEAP",	SUPPLICANT_EAP_METHOD_PEAP	},
+	{ "TTLS",	SUPPLICANT_EAP_METHOD_TTLS	},
+	{ "GTC",	SUPPLICANT_EAP_METHOD_GTC	},
+	{ "OTP",	SUPPLICANT_EAP_METHOD_OTP	},
+	{ "LEAP",	SUPPLICANT_EAP_METHOD_LEAP	},
+	{ "WSC",	SUPPLICANT_EAP_METHOD_WSC	},
+	{ }
+};
+
+static struct strvalmap keymgmt_capa_map[] = {
+	{ "none",	SUPPLICANT_CAPABILITY_KEYMGMT_NONE	},
+	{ "ieee8021x",	SUPPLICANT_CAPABILITY_KEYMGMT_IEEE8021X	},
+	{ "wpa-none",	SUPPLICANT_CAPABILITY_KEYMGMT_WPA_NONE	},
+	{ "wpa-psk",	SUPPLICANT_CAPABILITY_KEYMGMT_WPA_PSK	},
+	{ "wpa-eap",	SUPPLICANT_CAPABILITY_KEYMGMT_WPA_EAP	},
+	{ "wps",	SUPPLICANT_CAPABILITY_KEYMGMT_WPS	},
+	{ }
+};
+
+static struct strvalmap authalg_capa_map[] = {
+	{ "open",	SUPPLICANT_CAPABILITY_AUTHALG_OPEN	},
+	{ "shared",	SUPPLICANT_CAPABILITY_AUTHALG_SHARED	},
+	{ "leap",	SUPPLICANT_CAPABILITY_AUTHALG_LEAP	},
+	{ }
+};
+
+static struct strvalmap proto_capa_map[] = {
+	{ "wpa",	SUPPLICANT_CAPABILITY_PROTO_WPA		},
+	{ "rsn",	SUPPLICANT_CAPABILITY_PROTO_RSN		},
+	{ }
+};
+
+static struct strvalmap group_capa_map[] = {
+	{ "wep40",	SUPPLICANT_CAPABILITY_GROUP_WEP40	},
+	{ "wep104",	SUPPLICANT_CAPABILITY_GROUP_WEP104	},
+	{ "tkip",	SUPPLICANT_CAPABILITY_GROUP_TKIP	},
+	{ "ccmp",	SUPPLICANT_CAPABILITY_GROUP_CCMP	},
+	{ }
+};
+
+static struct strvalmap pairwise_capa_map[] = {
+	{ "none",	SUPPLICANT_CAPABILITY_PAIRWISE_NONE	},
+	{ "tkip",	SUPPLICANT_CAPABILITY_PAIRWISE_TKIP	},
+	{ "ccmp",	SUPPLICANT_CAPABILITY_PAIRWISE_CCMP	},
+	{ }
+};
+
+static struct strvalmap scan_capa_map[] = {
+	{ "active",	SUPPLICANT_CAPABILITY_SCAN_ACTIVE	},
+	{ "passive",	SUPPLICANT_CAPABILITY_SCAN_PASSIVE	},
+	{ "ssid",	SUPPLICANT_CAPABILITY_SCAN_SSID		},
+	{ }
+};
+
+static struct strvalmap mode_capa_map[] = {
+	{ "infrastructure",	SUPPLICANT_CAPABILITY_MODE_INFRA	},
+	{ "ad-hoc",		SUPPLICANT_CAPABILITY_MODE_IBSS		},
+	{ "ap",			SUPPLICANT_CAPABILITY_MODE_AP		},
+	{ }
+};
+
+static GHashTable *interface_table;
+static GHashTable *bss_mapping;
+
+struct supplicant_interface {
+	char *path;
+	unsigned int keymgmt_capa;
+	unsigned int authalg_capa;
+	unsigned int proto_capa;
+	unsigned int group_capa;
+	unsigned int pairwise_capa;
+	unsigned int scan_capa;
+	unsigned int mode_capa;
+	dbus_bool_t ready;
+	enum supplicant_state state;
+	dbus_bool_t scanning;
+	supplicant_interface_scan_callback scan_callback;
+	void *scan_data;
+	int apscan;
+	char *ifname;
+	char *driver;
+	char *bridge;
+	GHashTable *network_table;
+	GHashTable *net_mapping;
+	GHashTable *bss_mapping;
+};
+
+struct supplicant_network {
+	struct supplicant_interface *interface;
+	char *path;
+	char *group;
+	char *name;
+	enum supplicant_mode mode;
+	GHashTable *bss_table;
+	GHashTable *config_table;
+};
+
+struct supplicant_bss {
+	struct supplicant_interface *interface;
+	char *path;
+	unsigned char bssid[6];
+	unsigned char ssid[32];
+	unsigned int ssid_len;
+	dbus_uint16_t frequency;
+	dbus_uint32_t maxrate;
+	enum supplicant_mode mode;
+	enum supplicant_security security;
+	dbus_bool_t privacy;
+	dbus_bool_t psk;
+	dbus_bool_t ieee8021x;
+};
+
+static enum supplicant_mode string2mode(const char *mode)
+{
+	if (!mode)
+		return SUPPLICANT_MODE_UNKNOWN;
+
+	if (g_str_equal(mode, "infrastructure"))
+		return SUPPLICANT_MODE_INFRA;
+	else if (g_str_equal(mode, "ad-hoc"))
+		return SUPPLICANT_MODE_IBSS;
+
+	return SUPPLICANT_MODE_UNKNOWN;
+}
+
+static const char *mode2string(enum supplicant_mode mode)
+{
+	switch (mode) {
+	case SUPPLICANT_MODE_UNKNOWN:
+		break;
+	case SUPPLICANT_MODE_INFRA:
+		return "infra";
+	case SUPPLICANT_MODE_IBSS:
+		return "adhoc";
+	}
+
+	return NULL;
+}
+
+static const char *security2string(enum supplicant_security security)
+{
+	switch (security) {
+	case SUPPLICANT_SECURITY_UNKNOWN:
+		break;
+	case SUPPLICANT_SECURITY_NONE:
+		return "none";
+	case SUPPLICANT_SECURITY_WEP:
+		return "wep";
+	case SUPPLICANT_SECURITY_PSK:
+		return "psk";
+	case SUPPLICANT_SECURITY_IEEE8021X:
+		return "ieee8021x";
+	}
+
+	return NULL;
+}
+
+static enum supplicant_state string2state(const char *state)
+{
+	if (!state)
+		return SUPPLICANT_STATE_UNKNOWN;
+
+	if (g_str_equal(state, "unknown"))
+		return SUPPLICANT_STATE_UNKNOWN;
+	else if (g_str_equal(state, "disconnected"))
+		return SUPPLICANT_STATE_DISCONNECTED;
+	else if (g_str_equal(state, "inactive"))
+		return SUPPLICANT_STATE_INACTIVE;
+	else if (g_str_equal(state, "scanning"))
+		return SUPPLICANT_STATE_SCANNING;
+	else if (g_str_equal(state, "authenticating"))
+		return SUPPLICANT_STATE_AUTHENTICATING;
+	else if (g_str_equal(state, "associating"))
+		return SUPPLICANT_STATE_ASSOCIATING;
+	else if (g_str_equal(state, "associated"))
+		return SUPPLICANT_STATE_ASSOCIATED;
+	else if (g_str_equal(state, "group_handshake"))
+		return SUPPLICANT_STATE_GROUP_HANDSHAKE;
+	else if (g_str_equal(state, "4way_handshake"))
+		return SUPPLICANT_STATE_4WAY_HANDSHAKE;
+	else if (g_str_equal(state, "completed"))
+		return SUPPLICANT_STATE_COMPLETED;
+
+	return SUPPLICANT_STATE_UNKNOWN;
+}
+
+static void callback_system_ready(void)
+{
+	if (system_ready)
+		return;
+
+	system_ready = TRUE;
+
+	if (!callbacks_pointer)
+		return;
+
+	if (!callbacks_pointer->system_ready)
+		return;
+
+	callbacks_pointer->system_ready();
+}
+
+static void callback_system_killed(void)
+{
+	system_ready = FALSE;
+
+	if (!callbacks_pointer)
+		return;
+
+	if (!callbacks_pointer->system_killed)
+		return;
+
+	callbacks_pointer->system_killed();
+}
+
+static void callback_interface_added(struct supplicant_interface *interface)
+{
+	if (!callbacks_pointer)
+		return;
+
+	if (!callbacks_pointer->interface_added)
+		return;
+
+	callbacks_pointer->interface_added(interface);
+}
+
+static void callback_interface_removed(struct supplicant_interface *interface)
+{
+	if (!callbacks_pointer)
+		return;
+
+	if (!callbacks_pointer->interface_removed)
+		return;
+
+	callbacks_pointer->interface_removed(interface);
+}
+
+static void callback_scan_started(struct supplicant_interface *interface)
+{
+	if (!callbacks_pointer)
+		return;
+
+	if (!callbacks_pointer->scan_started)
+		return;
+
+	callbacks_pointer->scan_started(interface);
+}
+
+static void callback_scan_finished(struct supplicant_interface *interface)
+{
+	if (!callbacks_pointer)
+		return;
+
+	if (!callbacks_pointer->scan_finished)
+		return;
+
+	callbacks_pointer->scan_finished(interface);
+}
+
+static void callback_network_added(struct supplicant_network *network)
+{
+	if (!callbacks_pointer)
+		return;
+
+	if (!callbacks_pointer->network_added)
+		return;
+
+	callbacks_pointer->network_added(network);
+}
+
+static void callback_network_removed(struct supplicant_network *network)
+{
+	if (!callbacks_pointer)
+		return;
+
+	if (!callbacks_pointer->network_removed)
+		return;
+
+	callbacks_pointer->network_removed(network);
+}
+
+static void remove_interface(gpointer data)
+{
+	struct supplicant_interface *interface = data;
+
+	g_hash_table_destroy(interface->bss_mapping);
+	g_hash_table_destroy(interface->net_mapping);
+	g_hash_table_destroy(interface->network_table);
+
+	callback_interface_removed(interface);
+
+	g_free(interface->path);
+	g_free(interface->ifname);
+	g_free(interface->driver);
+	g_free(interface->bridge);
+	g_free(interface);
+}
+
+static void remove_network(gpointer data)
+{
+	struct supplicant_network *network = data;
+
+	g_hash_table_destroy(network->bss_table);
+
+	callback_network_removed(network);
+
+	g_hash_table_destroy(network->config_table);
+
+	g_free(network->group);
+	g_free(network->name);
+	g_free(network);
+}
+
+static void remove_bss(gpointer data)
+{
+	struct supplicant_bss *bss = data;
+
+	g_free(bss->path);
+	g_free(bss);
+}
+
+static void debug_strvalmap(const char *label, struct strvalmap *map,
+							unsigned int val)
+{
+	int i;
+
+	for (i = 0; map[i].str; i++) {
+		if (val & map[i].val)
+			DBG("%s: %s", label, map[i].str);
+	}
+}
+
+static void interface_capability_keymgmt(DBusMessageIter *iter, void *user_data)
+{
+	struct supplicant_interface *interface = user_data;
+	const char *str = NULL;
+	int i;
+
+	dbus_message_iter_get_basic(iter, &str);
+	if (!str)
+		return;
+
+	for (i = 0; keymgmt_capa_map[i].str; i++)
+		if (strcmp(str, keymgmt_capa_map[i].str) == 0) {
+			interface->keymgmt_capa |= keymgmt_capa_map[i].val;
+			break;
+		}
+}
+
+static void interface_capability_authalg(DBusMessageIter *iter, void *user_data)
+{
+	struct supplicant_interface *interface = user_data;
+	const char *str = NULL;
+	int i;
+
+	dbus_message_iter_get_basic(iter, &str);
+	if (!str)
+		return;
+
+	for (i = 0; authalg_capa_map[i].str; i++)
+		if (strcmp(str, authalg_capa_map[i].str) == 0) {
+			interface->authalg_capa |= authalg_capa_map[i].val;
+			break;
+		}
+}
+
+static void interface_capability_proto(DBusMessageIter *iter, void *user_data)
+{
+	struct supplicant_interface *interface = user_data;
+	const char *str = NULL;
+	int i;
+
+	dbus_message_iter_get_basic(iter, &str);
+	if (!str)
+		return;
+
+	for (i = 0; proto_capa_map[i].str; i++)
+		if (strcmp(str, proto_capa_map[i].str) == 0) {
+			interface->proto_capa |= proto_capa_map[i].val;
+			break;
+		}
+}
+
+static void interface_capability_pairwise(DBusMessageIter *iter, void *user_data)
+{
+	struct supplicant_interface *interface = user_data;
+	const char *str = NULL;
+	int i;
+
+	dbus_message_iter_get_basic(iter, &str);
+	if (!str)
+		return;
+
+	for (i = 0; pairwise_capa_map[i].str; i++)
+		if (strcmp(str, pairwise_capa_map[i].str) == 0) {
+			interface->pairwise_capa |= pairwise_capa_map[i].val;
+			break;
+		}
+}
+
+static void interface_capability_group(DBusMessageIter *iter, void *user_data)
+{
+	struct supplicant_interface *interface = user_data;
+	const char *str = NULL;
+	int i;
+
+	dbus_message_iter_get_basic(iter, &str);
+	if (!str)
+		return;
+
+	for (i = 0; group_capa_map[i].str; i++)
+		if (strcmp(str, group_capa_map[i].str) == 0) {
+			interface->group_capa |= group_capa_map[i].val;
+			break;
+		}
+}
+
+static void interface_capability_scan(DBusMessageIter *iter, void *user_data)
+{
+	struct supplicant_interface *interface = user_data;
+	const char *str = NULL;
+	int i;
+
+	dbus_message_iter_get_basic(iter, &str);
+	if (!str)
+		return;
+
+	for (i = 0; scan_capa_map[i].str; i++)
+		if (strcmp(str, scan_capa_map[i].str) == 0) {
+			interface->scan_capa |= scan_capa_map[i].val;
+			break;
+		}
+}
+
+static void interface_capability_mode(DBusMessageIter *iter, void *user_data)
+{
+	struct supplicant_interface *interface = user_data;
+	const char *str = NULL;
+	int i;
+
+	dbus_message_iter_get_basic(iter, &str);
+	if (!str)
+		return;
+
+	for (i = 0; mode_capa_map[i].str; i++)
+		if (strcmp(str, mode_capa_map[i].str) == 0) {
+			interface->mode_capa |= mode_capa_map[i].val;
+			break;
+		}
+}
+
+static void interface_capability(const char *key, DBusMessageIter *iter,
+							void *user_data)
+{
+	struct supplicant_interface *interface = user_data;
+
+	if (!key)
+		return;
+
+	if (g_strcmp0(key, "KeyMgmt") == 0)
+		supplicant_dbus_array_foreach(iter,
+				interface_capability_keymgmt, interface);
+	else if (g_strcmp0(key, "AuthAlg") == 0)
+		supplicant_dbus_array_foreach(iter,
+				interface_capability_authalg, interface);
+	else if (g_strcmp0(key, "Protocol") == 0)
+		supplicant_dbus_array_foreach(iter,
+				interface_capability_proto, interface);
+	else if (g_strcmp0(key, "Pairwise") == 0)
+		supplicant_dbus_array_foreach(iter,
+				interface_capability_pairwise, interface);
+	else if (g_strcmp0(key, "Group") == 0)
+		supplicant_dbus_array_foreach(iter,
+				interface_capability_group, interface);
+	else if (g_strcmp0(key, "Scan") == 0)
+		supplicant_dbus_array_foreach(iter,
+				interface_capability_scan, interface);
+	else if (g_strcmp0(key, "Modes") == 0)
+		supplicant_dbus_array_foreach(iter,
+				interface_capability_mode, interface);
+	else
+		DBG("key %s type %c",
+				key, dbus_message_iter_get_arg_type(iter));
+}
+
+const char *supplicant_interface_get_ifname(struct supplicant_interface *interface)
+{
+	if (!interface)
+		return NULL;
+
+	return interface->ifname;
+}
+
+const char *supplicant_interface_get_driver(struct supplicant_interface *interface)
+{
+	if (!interface)
+		return NULL;
+
+	return interface->driver;
+}
+
+struct supplicant_interface *supplicant_network_get_interface(struct supplicant_network *network)
+{
+	if (!network)
+		return NULL;
+
+	return network->interface;
+}
+
+const char *supplicant_network_get_name(struct supplicant_network *network)
+{
+	if (!network || !network->name)
+		return "";
+
+	return network->name;
+}
+
+const char *supplicant_network_get_identifier(struct supplicant_network *network)
+{
+	if (!network || !network->group)
+		return "";
+
+	return network->group;
+}
+
+enum supplicant_mode supplicant_network_get_mode(struct supplicant_network *network)
+{
+	if (!network)
+		return SUPPLICANT_MODE_UNKNOWN;
+
+	return network->mode;
+}
+
+static void merge_network(struct supplicant_network *network)
+{
+	GString *str;
+	const char *ssid, *mode, *key_mgmt;
+	unsigned int i, ssid_len;
+	char *group;
+
+	ssid = g_hash_table_lookup(network->config_table, "ssid");
+	mode = g_hash_table_lookup(network->config_table, "mode");
+	key_mgmt = g_hash_table_lookup(network->config_table, "key_mgmt");
+
+	DBG("ssid %s mode %s", ssid, mode);
+
+	if (ssid)
+		ssid_len = strlen(ssid);
+	else
+		ssid_len = 0;
+
+	str = g_string_sized_new((ssid_len * 2) + 24);
+	if (!str)
+		return;
+
+	for (i = 0; i < ssid_len; i++)
+		g_string_append_printf(str, "%02x", ssid[i]);
+
+	if (g_strcmp0(mode, "0") == 0)
+		g_string_append_printf(str, "_infra");
+	else if (g_strcmp0(mode, "1") == 0)
+		g_string_append_printf(str, "_adhoc");
+
+	if (g_strcmp0(key_mgmt, "WPA-PSK") == 0)
+		g_string_append_printf(str, "_psk");
+
+	group = g_string_free(str, FALSE);
+
+	DBG("%s", group);
+
+	g_free(group);
+
+	g_hash_table_destroy(network->config_table);
+
+	g_free(network->path);
+	g_free(network);
+}
+
+static void network_property(const char *key, DBusMessageIter *iter,
+							void *user_data)
+{
+	struct supplicant_network *network = user_data;
+
+	if (!network->interface)
+		return;
+
+	if (!key) {
+		merge_network(network);
+		return;
+	}
+
+	if (g_strcmp0(key, "Enabled") == 0) {
+		dbus_bool_t enabled = FALSE;
+
+		dbus_message_iter_get_basic(iter, &enabled);
+	} else if (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_STRING) {
+		const char *str = NULL;
+
+		dbus_message_iter_get_basic(iter, &str);
+		if (str)
+			g_hash_table_replace(network->config_table,
+						g_strdup(key), g_strdup(str));
+	} else
+		DBG("key %s type %c",
+				key, dbus_message_iter_get_arg_type(iter));
+}
+
+static void interface_network_added(DBusMessageIter *iter, void *user_data)
+{
+	struct supplicant_interface *interface = user_data;
+	struct supplicant_network *network;
+	const char *path = NULL;
+
+	dbus_message_iter_get_basic(iter, &path);
+	if (!path)
+		return;
+
+	if (g_strcmp0(path, "/") == 0)
+		return;
+
+	network = g_hash_table_lookup(interface->net_mapping, path);
+	if (network)
+		return;
+
+	network = g_try_new0(struct supplicant_network, 1);
+	if (!network)
+		return;
+
+	network->interface = interface;
+	network->path = g_strdup(path);
+
+	network->config_table = g_hash_table_new_full(g_str_hash, g_str_equal,
+							g_free, g_free);
+
+	dbus_message_iter_next(iter);
+	if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) {
+		supplicant_dbus_property_foreach(iter, network_property,
+								network);
+		network_property(NULL, NULL, network);
+		return;
+	}
+
+	supplicant_dbus_property_get_all(path,
+				SUPPLICANT_INTERFACE ".Interface.Network",
+						network_property, network);
+}
+
+static void interface_network_removed(DBusMessageIter *iter, void *user_data)
+{
+	struct supplicant_interface *interface = user_data;
+	struct supplicant_network *network;
+	const char *path = NULL;
+
+	dbus_message_iter_get_basic(iter, &path);
+	if (!path)
+		return;
+
+	network = g_hash_table_lookup(interface->net_mapping, path);
+	if (!network)
+		return;
+
+	g_hash_table_remove(interface->net_mapping, path);
+}
+
+static char *create_name(unsigned char *ssid, int ssid_len)
+{
+	char *name;
+	int i;
+
+	if (ssid_len < 1 || ssid[0] == '\0')
+		name = NULL;
+	else
+		name = g_try_malloc0(ssid_len + 1);
+
+	if (!name)
+		return g_strdup("");
+
+	for (i = 0; i < ssid_len; i++) {
+		if (g_ascii_isprint(ssid[i]))
+			name[i] = ssid[i];
+		else
+			name[i] = ' ';
+	}
+
+	return name;
+}
+
+static char *create_group(struct supplicant_bss *bss)
+{
+	GString *str;
+	unsigned int i;
+	const char *mode, *security;
+
+	str = g_string_sized_new((bss->ssid_len * 2) + 24);
+	if (!str)
+		return NULL;
+
+	if (bss->ssid_len > 0 && bss->ssid[0] != '\0') {
+		for (i = 0; i < bss->ssid_len; i++)
+			g_string_append_printf(str, "%02x", bss->ssid[i]);
+	} else
+		g_string_append_printf(str, "hidden");
+
+	mode = mode2string(bss->mode);
+	if (mode)
+		g_string_append_printf(str, "_%s", mode);
+
+	security = security2string(bss->security);
+	if (security)
+		g_string_append_printf(str, "_%s", security);
+
+	return g_string_free(str, FALSE);
+}
+
+static void add_bss_to_network(struct supplicant_bss *bss)
+{
+	struct supplicant_interface *interface = bss->interface;
+	struct supplicant_network *network;
+	char *group;
+
+	group = create_group(bss);
+	if (!group)
+		return;
+
+	network = g_hash_table_lookup(interface->network_table, group);
+	if (network) {
+		g_free(group);
+		goto done;
+	}
+
+	network = g_try_new0(struct supplicant_network, 1);
+	if (!network) {
+		g_free(group);
+		return;
+	}
+
+	network->group = group;
+	network->name = create_name(bss->ssid, bss->ssid_len);
+	network->mode = bss->mode;
+
+	network->bss_table = g_hash_table_new_full(g_str_hash, g_str_equal,
+							NULL, remove_bss);
+
+	network->config_table = g_hash_table_new_full(g_str_hash, g_str_equal,
+							g_free, g_free);
+
+	g_hash_table_replace(interface->network_table,
+						network->group, network);
+
+	callback_network_added(network);
+
+done:
+	g_hash_table_replace(interface->bss_mapping, bss->path, network);
+	g_hash_table_replace(network->bss_table, bss->path, bss);
+
+	g_hash_table_replace(bss_mapping, bss->path, interface);
+}
+
+static unsigned char wifi_oui[3]      = { 0x00, 0x50, 0xf2 };
+static unsigned char ieee80211_oui[3] = { 0x00, 0x0f, 0xac };
+
+static void extract_rsn(struct supplicant_bss *bss,
+					const unsigned char *buf, int len)
+{
+	uint16_t count;
+	int i;
+
+	/* Version */
+	if (len < 2)
+		return;
+
+	buf += 2;
+	len -= 2;
+
+	/* Group cipher */
+	if (len < 4)
+		return;
+
+	buf += 4;
+	len -= 4;
+
+	/* Pairwise cipher */
+	if (len < 2)
+		return;
+
+	count = buf[0] | (buf[1] << 8);
+	if (2 + (count * 4) > len)
+		return;
+
+	buf += 2 + (count * 4);
+	len -= 2 + (count * 4);
+
+	/* Authentication */
+	if (len < 2)
+		return;
+
+	count = buf[0] | (buf[1] << 8);
+	if (2 + (count * 4) > len)
+		return;
+
+	for (i = 0; i < count; i++) {
+		const unsigned char *ptr = buf + 2 + (i * 4);
+
+		if (memcmp(ptr, wifi_oui, 3) == 0) {
+			switch (ptr[3]) {
+			case 1:
+				bss->ieee8021x = TRUE;
+				break;
+			case 2:
+				bss->psk = TRUE;
+				break;
+			}
+		} else if (memcmp(ptr, ieee80211_oui, 3) == 0) {
+			switch (ptr[3]) {
+			case 1:
+				bss->ieee8021x = TRUE;
+				break;
+			case 2:
+				bss->psk = TRUE;
+				break;
+			}
+		}
+	}
+
+}
+
+static void bss_rates(DBusMessageIter *iter, void *user_data)
+{
+	struct supplicant_bss *bss = user_data;
+	dbus_uint32_t rate = 0;
+
+	dbus_message_iter_get_basic(iter, &rate);
+	if (rate == 0)
+		return;
+
+	if (rate > bss->maxrate)
+		bss->maxrate = rate;
+}
+
+static void bss_property(const char *key, DBusMessageIter *iter,
+							void *user_data)
+{
+	struct supplicant_bss *bss = user_data;
+
+	if (!bss->interface)
+		return;
+
+	if (!key) {
+		if (bss->ieee8021x)
+			bss->security = SUPPLICANT_SECURITY_IEEE8021X;
+		else if (bss->psk)
+			bss->security = SUPPLICANT_SECURITY_PSK;
+		else if (bss->privacy)
+			bss->security = SUPPLICANT_SECURITY_WEP;
+		else
+			bss->security = SUPPLICANT_SECURITY_NONE;
+
+		add_bss_to_network(bss);
+		return;
+	}
+
+	if (g_strcmp0(key, "BSSID") == 0) {
+		DBusMessageIter array;
+		unsigned char *addr;
+		int addr_len;
+
+		dbus_message_iter_recurse(iter, &array);
+		dbus_message_iter_get_fixed_array(&array, &addr, &addr_len);
+
+		if (addr_len == 6)
+			memcpy(bss->bssid, addr, addr_len);
+	} else if (g_strcmp0(key, "SSID") == 0) {
+		DBusMessageIter array;
+		unsigned char *ssid;
+		int ssid_len;
+
+		dbus_message_iter_recurse(iter, &array);
+		dbus_message_iter_get_fixed_array(&array, &ssid, &ssid_len);
+
+		if (ssid_len > 0 && ssid_len < 33) {
+			memcpy(bss->ssid, ssid, ssid_len);
+			bss->ssid_len = ssid_len;
+		} else {
+			memset(bss->ssid, 0, sizeof(bss->ssid));
+			bss->ssid_len = 0;
+		}
+	} else if (g_strcmp0(key, "Capabilities") == 0) {
+		dbus_uint16_t capabilities = 0x0000;
+
+		dbus_message_iter_get_basic(iter, &capabilities);
+
+		if (capabilities & IEEE80211_CAP_ESS)
+			bss->mode = SUPPLICANT_MODE_INFRA;
+		else if (capabilities & IEEE80211_CAP_IBSS)
+			bss->mode = SUPPLICANT_MODE_IBSS;
+
+		if (capabilities & IEEE80211_CAP_PRIVACY)
+			bss->privacy = TRUE;
+	} else if (g_strcmp0(key, "Mode") == 0) {
+		const char *mode = NULL;
+
+		dbus_message_iter_get_basic(iter, &mode);
+		bss->mode = string2mode(mode);
+	} else if (g_strcmp0(key, "Frequency") == 0) {
+		dbus_uint16_t frequency = 0;
+
+		dbus_message_iter_get_basic(iter, &frequency);
+		bss->frequency = frequency;
+	} else if (g_strcmp0(key, "Signal") == 0) {
+		dbus_int16_t signal = 0;
+
+		dbus_message_iter_get_basic(iter, &signal);
+	} else if (g_strcmp0(key, "Level") == 0) {
+		dbus_int32_t level = 0;
+
+		dbus_message_iter_get_basic(iter, &level);
+	} else if (g_strcmp0(key, "Rates") == 0) {
+		supplicant_dbus_array_foreach(iter, bss_rates, bss);
+	} else if (g_strcmp0(key, "MaxRate") == 0) {
+		dbus_uint32_t maxrate = 0;
+
+		dbus_message_iter_get_basic(iter, &maxrate);
+		if (maxrate != 0)
+			bss->maxrate =maxrate;
+	} else if (g_strcmp0(key, "Privacy") == 0) {
+		dbus_bool_t privacy = FALSE;
+
+		dbus_message_iter_get_basic(iter, &privacy);
+		bss->privacy = privacy;
+	} else if (g_strcmp0(key, "RSNIE") == 0) {
+		DBusMessageIter array;
+		unsigned char *ie;
+		int ie_len;
+
+		dbus_message_iter_recurse(iter, &array);
+		dbus_message_iter_get_fixed_array(&array, &ie, &ie_len);
+
+		if (ie_len > 2)
+			extract_rsn(bss, ie + 2, ie_len - 2);
+	} else if (g_strcmp0(key, "WPAIE") == 0) {
+		DBusMessageIter array;
+		unsigned char *ie;
+		int ie_len;
+
+		dbus_message_iter_recurse(iter, &array);
+		dbus_message_iter_get_fixed_array(&array, &ie, &ie_len);
+
+		if (ie_len > 6)
+			extract_rsn(bss, ie + 6, ie_len - 6);
+	} else if (g_strcmp0(key, "WPSIE") == 0) {
+		DBusMessageIter array;
+		unsigned char *ie;
+		int ie_len;
+
+		dbus_message_iter_recurse(iter, &array);
+		dbus_message_iter_get_fixed_array(&array, &ie, &ie_len);
+	} else
+		DBG("key %s type %c",
+				key, dbus_message_iter_get_arg_type(iter));
+}
+
+static void interface_bss_added(DBusMessageIter *iter, void *user_data)
+{
+	struct supplicant_interface *interface = user_data;
+	struct supplicant_network *network;
+	struct supplicant_bss *bss;
+	const char *path = NULL;
+
+	dbus_message_iter_get_basic(iter, &path);
+	if (!path)
+		return;
+
+	if (g_strcmp0(path, "/") == 0)
+		return;
+
+	network = g_hash_table_lookup(interface->bss_mapping, path);
+	if (network) {
+		bss = g_hash_table_lookup(network->bss_table, path);
+		if (bss)
+			return;
+	}
+
+	bss = g_try_new0(struct supplicant_bss, 1);
+	if (!bss)
+		return;
+
+	bss->interface = interface;
+	bss->path = g_strdup(path);
+
+	dbus_message_iter_next(iter);
+	if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) {
+		supplicant_dbus_property_foreach(iter, bss_property, bss);
+		bss_property(NULL, NULL, bss);
+		return;
+	}
+
+	supplicant_dbus_property_get_all(path,
+					SUPPLICANT_INTERFACE ".Interface.BSS",
+							bss_property, bss);
+}
+
+static void interface_bss_removed(DBusMessageIter *iter, void *user_data)
+{
+	struct supplicant_interface *interface = user_data;
+	struct supplicant_network *network;
+	const char *path = NULL;
+
+	dbus_message_iter_get_basic(iter, &path);
+	if (!path)
+		return;
+
+	network = g_hash_table_lookup(interface->bss_mapping, path);
+	if (!network)
+		return;
+
+	g_hash_table_remove(bss_mapping, path);
+
+	g_hash_table_remove(interface->bss_mapping, path);
+	g_hash_table_remove(network->bss_table, path);
+
+	if (g_hash_table_size(network->bss_table) == 0)
+		g_hash_table_remove(interface->network_table, network->group);
+}
+
+static void interface_property(const char *key, DBusMessageIter *iter,
+							void *user_data)
+{
+	struct supplicant_interface *interface = user_data;
+
+	if (!interface)
+		return;
+
+	if (!key) {
+		debug_strvalmap("KeyMgmt capability", keymgmt_capa_map,
+						interface->keymgmt_capa);
+		debug_strvalmap("AuthAlg capability", authalg_capa_map,
+						interface->authalg_capa);
+		debug_strvalmap("Protocol capability", proto_capa_map,
+						interface->proto_capa);
+		debug_strvalmap("Pairwise capability", pairwise_capa_map,
+						interface->pairwise_capa);
+		debug_strvalmap("Group capability", group_capa_map,
+						interface->group_capa);
+		debug_strvalmap("Scan capability", scan_capa_map,
+						interface->scan_capa);
+		debug_strvalmap("Mode capability", mode_capa_map,
+						interface->mode_capa);
+
+		interface->ready = TRUE;
+		callback_interface_added(interface);
+		return;
+	}
+
+	if (g_strcmp0(key, "Capabilities") == 0) {
+		supplicant_dbus_property_foreach(iter, interface_capability,
+								interface);
+	} else if (g_strcmp0(key, "State") == 0) {
+		const char *str = NULL;
+
+		dbus_message_iter_get_basic(iter, &str);
+		if (str)
+			interface->state = string2state(str);
+
+		DBG("state %s (%d)", str, interface->state);
+	} else if (g_strcmp0(key, "Scanning") == 0) {
+		dbus_bool_t scanning = FALSE;
+
+		dbus_message_iter_get_basic(iter, &scanning);
+		interface->scanning = scanning;
+
+		if (interface->ready) {
+			if (interface->scanning)
+				callback_scan_started(interface);
+			else
+				callback_scan_finished(interface);
+		}
+	} else if (g_strcmp0(key, "ApScan") == 0) {
+		int apscan = 1;
+
+		dbus_message_iter_get_basic(iter, &apscan);
+		interface->apscan = apscan;
+	} else if (g_strcmp0(key, "Ifname") == 0) {
+		const char *str = NULL;
+
+		dbus_message_iter_get_basic(iter, &str);
+		if (str)
+			interface->ifname = g_strdup(str);
+	} else if (g_strcmp0(key, "Driver") == 0) {
+		const char *str = NULL;
+
+		dbus_message_iter_get_basic(iter, &str);
+		if (str)
+			interface->driver = g_strdup(str);
+	} else if (g_strcmp0(key, "BridgeIfname") == 0) {
+		const char *str = NULL;
+
+		dbus_message_iter_get_basic(iter, &str);
+		if (str)
+			interface->bridge = g_strdup(str);
+	} else if (g_strcmp0(key, "CurrentBSS") == 0) {
+		interface_bss_added(iter, interface);
+	} else if (g_strcmp0(key, "CurrentNetwork") == 0) {
+		interface_network_added(iter, interface);
+	} else if (g_strcmp0(key, "BSSs") == 0) {
+		supplicant_dbus_array_foreach(iter, interface_bss_added,
+								interface);
+	} else if (g_strcmp0(key, "Blobs") == 0) {
+	} else if (g_strcmp0(key, "Networks") == 0) {
+		supplicant_dbus_array_foreach(iter, interface_network_added,
+								interface);
+	} else
+		DBG("key %s type %c",
+				key, dbus_message_iter_get_arg_type(iter));
+}
+
+static struct supplicant_interface *interface_alloc(const char *path)
+{
+	struct supplicant_interface *interface;
+
+	interface = g_try_new0(struct supplicant_interface, 1);
+	if (!interface)
+		return NULL;
+
+	interface->path = g_strdup(path);
+
+	interface->network_table = g_hash_table_new_full(g_str_hash, g_str_equal,
+							NULL, remove_network);
+
+	interface->net_mapping = g_hash_table_new_full(g_str_hash, g_str_equal,
+								NULL, NULL);
+	interface->bss_mapping = g_hash_table_new_full(g_str_hash, g_str_equal,
+								NULL, NULL);
+
+	g_hash_table_replace(interface_table, interface->path, interface);
+
+	return interface;
+}
+
+static void interface_added(DBusMessageIter *iter, void *user_data)
+{
+	struct supplicant_interface *interface;
+	const char *path = NULL;
+
+	dbus_message_iter_get_basic(iter, &path);
+	if (!path)
+		return;
+
+	if (g_strcmp0(path, "/") == 0)
+		return;
+
+	interface = g_hash_table_lookup(interface_table, path);
+	if (interface)
+		return;
+
+	interface = interface_alloc(path);
+	if (!interface)
+		return;
+
+	dbus_message_iter_next(iter);
+	if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) {
+		supplicant_dbus_property_foreach(iter, interface_property,
+								interface);
+		interface_property(NULL, NULL, interface);
+		return;
+	}
+
+	supplicant_dbus_property_get_all(path,
+					SUPPLICANT_INTERFACE ".Interface",
+						interface_property, interface);
+}
+
+static void interface_removed(DBusMessageIter *iter, void *user_data)
+{
+	const char *path = NULL;
+
+	dbus_message_iter_get_basic(iter, &path);
+	if (!path)
+		return;
+
+	g_hash_table_remove(interface_table, path);
+}
+
+static void eap_method(DBusMessageIter *iter, void *user_data)
+{
+	const char *str = NULL;
+	int i;
+
+	dbus_message_iter_get_basic(iter, &str);
+	if (!str)
+		return;
+
+	for (i = 0; eap_method_map[i].str; i++)
+		if (strcmp(str, eap_method_map[i].str) == 0) {
+			eap_methods |= eap_method_map[i].val;
+			break;
+		}
+}
+
+static void service_property(const char *key, DBusMessageIter *iter,
+							void *user_data)
+{
+	if (!key) {
+		callback_system_ready();
+		return;
+	}
+
+	if (g_strcmp0(key, "DebugLevel") == 0) {
+		const char *str = NULL;
+		int i;
+
+		dbus_message_iter_get_basic(iter, &str);
+		for (i = 0; debug_strings[i]; i++)
+			if (g_strcmp0(debug_strings[i], str) == 0) {
+				debug_level = i;
+				break;
+			}
+		DBG("Debug level %d", debug_level);
+	} else if (g_strcmp0(key, "DebugTimestamp") == 0) {
+		dbus_message_iter_get_basic(iter, &debug_timestamp);
+		DBG("Debug timestamp %u", debug_timestamp);
+	} else if (g_strcmp0(key, "DebugShowKeys") == 0) {
+		dbus_message_iter_get_basic(iter, &debug_showkeys);
+		DBG("Debug show keys %u", debug_showkeys);
+	} else if (g_strcmp0(key, "Interfaces") == 0) {
+		supplicant_dbus_array_foreach(iter, interface_added, NULL);
+	} else if (g_strcmp0(key, "EapMethods") == 0) {
+		supplicant_dbus_array_foreach(iter, eap_method, NULL);
+		debug_strvalmap("EAP method", eap_method_map, eap_methods);
+	} else
+		DBG("key %s type %c",
+				key, dbus_message_iter_get_arg_type(iter));
+}
+
+static void supplicant_bootstrap(void)
+{
+	supplicant_dbus_property_get_all(SUPPLICANT_PATH,
+						SUPPLICANT_INTERFACE,
+						service_property, NULL);
+}
+
+static void signal_name_owner_changed(const char *path, DBusMessageIter *iter)
+{
+	const char *name = NULL, *old = NULL, *new = NULL;
+
+	if (g_strcmp0(path, DBUS_PATH_DBUS) != 0)
+		return;
+
+	dbus_message_iter_get_basic(iter, &name);
+	if (!name)
+		return;
+
+	if (g_strcmp0(name, SUPPLICANT_SERVICE) != 0)
+		return;
+
+	dbus_message_iter_next(iter);
+	dbus_message_iter_get_basic(iter, &old);
+	dbus_message_iter_next(iter);
+	dbus_message_iter_get_basic(iter, &new);
+
+	if (!old || !new)
+		return;
+
+	if (strlen(old) > 0 && strlen(new) == 0) {
+		system_available = FALSE;
+		g_hash_table_remove_all(bss_mapping);
+		g_hash_table_remove_all(interface_table);
+		callback_system_killed();
+	}
+
+	if (strlen(new) > 0 && strlen(old) == 0) {
+		system_available = TRUE;
+		supplicant_bootstrap();
+	}
+}
+
+static void signal_properties_changed(const char *path, DBusMessageIter *iter)
+{
+	if (g_strcmp0(path, SUPPLICANT_PATH) != 0)
+		return;
+
+	supplicant_dbus_property_foreach(iter, service_property, NULL);
+}
+
+static void signal_interface_added(const char *path, DBusMessageIter *iter)
+{
+	if (g_strcmp0(path, SUPPLICANT_PATH) == 0)
+		interface_added(iter, NULL);
+}
+
+static void signal_interface_removed(const char *path, DBusMessageIter *iter)
+{
+	if (g_strcmp0(path, SUPPLICANT_PATH) == 0)
+		interface_removed(iter, NULL);
+}
+
+static void signal_interface_changed(const char *path, DBusMessageIter *iter)
+{
+	struct supplicant_interface *interface;
+
+	interface = g_hash_table_lookup(interface_table, path);
+	if (!interface)
+		return;
+
+	supplicant_dbus_property_foreach(iter, interface_property, interface);
+}
+
+static void signal_scan_done(const char *path, DBusMessageIter *iter)
+{
+	struct supplicant_interface *interface;
+	dbus_bool_t success = FALSE;
+
+	interface = g_hash_table_lookup(interface_table, path);
+	if (!interface)
+		return;
+
+	dbus_message_iter_get_basic(iter, &success);
+
+	if (interface->scan_callback) {
+		int result = 0;
+
+		if (!success)
+			result = -EIO;
+
+		interface->scan_callback(result, interface->scan_data);
+	}
+
+	interface->scan_callback = NULL;
+	interface->scan_data = NULL;
+}
+
+static void signal_bss_added(const char *path, DBusMessageIter *iter)
+{
+	struct supplicant_interface *interface;
+
+	interface = g_hash_table_lookup(interface_table, path);
+	if (!interface)
+		return;
+
+	interface_bss_added(iter, interface);
+}
+
+static void signal_bss_removed(const char *path, DBusMessageIter *iter)
+{
+	struct supplicant_interface *interface;
+
+	interface = g_hash_table_lookup(interface_table, path);
+	if (!interface)
+		return;
+
+	interface_bss_removed(iter, interface);
+}
+
+static void signal_network_added(const char *path, DBusMessageIter *iter)
+{
+	struct supplicant_interface *interface;
+
+	interface = g_hash_table_lookup(interface_table, path);
+	if (!interface)
+		return;
+
+	interface_network_added(iter, interface);
+}
+
+static void signal_network_removed(const char *path, DBusMessageIter *iter)
+{
+	struct supplicant_interface *interface;
+
+	interface = g_hash_table_lookup(interface_table, path);
+	if (!interface)
+		return;
+
+	interface_network_removed(iter, interface);
+}
+
+static void signal_bss_changed(const char *path, DBusMessageIter *iter)
+{
+	struct supplicant_interface *interface;
+	struct supplicant_network *network;
+	struct supplicant_bss *bss;
+
+	interface = g_hash_table_lookup(bss_mapping, path);
+	if (!interface)
+		return;
+
+	network = g_hash_table_lookup(interface->bss_mapping, path);
+	if (!network)
+		return;
+
+	bss = g_hash_table_lookup(network->bss_table, path);
+	if (!bss)
+		return;
+
+	supplicant_dbus_property_foreach(iter, bss_property, bss);
+}
+
+static struct {
+	const char *interface;
+	const char *member;
+	void (*function) (const char *path, DBusMessageIter *iter);
+} signal_map[] = {
+	{ DBUS_INTERFACE_DBUS,  "NameOwnerChanged",  signal_name_owner_changed },
+
+	{ SUPPLICANT_INTERFACE, "PropertiesChanged", signal_properties_changed },
+	{ SUPPLICANT_INTERFACE, "InterfaceAdded",    signal_interface_added    },
+	{ SUPPLICANT_INTERFACE, "InterfaceCreated",  signal_interface_added    },
+	{ SUPPLICANT_INTERFACE, "InterfaceRemoved",  signal_interface_removed  },
+
+	{ SUPPLICANT_INTERFACE ".Interface", "PropertiesChanged", signal_interface_changed },
+	{ SUPPLICANT_INTERFACE ".Interface", "ScanDone",          signal_scan_done         },
+	{ SUPPLICANT_INTERFACE ".Interface", "BSSAdded",          signal_bss_added         },
+	{ SUPPLICANT_INTERFACE ".Interface", "BSSRemoved",        signal_bss_removed       },
+	{ SUPPLICANT_INTERFACE ".Interface", "NetworkAdded",      signal_network_added     },
+	{ SUPPLICANT_INTERFACE ".Interface", "NetworkRemoved",    signal_network_removed   },
+
+	{ SUPPLICANT_INTERFACE ".Interface.BSS", "PropertiesChanged", signal_bss_changed   },
+
+	{ }
+};
+
+static DBusHandlerResult supplicant_filter(DBusConnection *conn,
+					DBusMessage *message, void *data)
+{
+	DBusMessageIter iter;
+	const char *path;
+	int i;
+
+	path = dbus_message_get_path(message);
+	if (!path)
+		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+	if (!dbus_message_iter_init(message, &iter))
+		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+	for (i = 0; signal_map[i].interface; i++) {
+		if (!dbus_message_has_interface(message, signal_map[i].interface))
+			continue;
+
+		if (!dbus_message_has_member(message, signal_map[i].member))
+			continue;
+
+		signal_map[i].function(path, &iter);
+		break;
+	}
+
+	return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+
+static const char *supplicant_rule0 = "type=signal,"
+					"path=" DBUS_PATH_DBUS ","
+					"sender=" DBUS_SERVICE_DBUS ","
+					"interface=" DBUS_INTERFACE_DBUS ","
+					"member=NameOwnerChanged,"
+					"arg0=" SUPPLICANT_SERVICE;
+static const char *supplicant_rule1 = "type=signal,"
+			"interface=" SUPPLICANT_INTERFACE;
+static const char *supplicant_rule2 = "type=signal,"
+			"interface=" SUPPLICANT_INTERFACE ".Interface";
+static const char *supplicant_rule3 = "type=signal,"
+			"interface=" SUPPLICANT_INTERFACE ".Interface.WPS";
+static const char *supplicant_rule4 = "type=signal,"
+			"interface=" SUPPLICANT_INTERFACE ".Interface.BSS";
+static const char *supplicant_rule5 = "type=signal,"
+			"interface=" SUPPLICANT_INTERFACE ".Interface.Network";
+static const char *supplicant_rule6 = "type=signal,"
+			"interface=" SUPPLICANT_INTERFACE ".Interface.Blob";
+
+int supplicant_register(const struct supplicant_callbacks *callbacks)
+{
+	connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
+	if (!connection)
+		return -EIO;
+
+	if (!dbus_connection_add_filter(connection, supplicant_filter, NULL, NULL)) {
+		dbus_connection_unref(connection);
+		connection = NULL;
+		return -EIO;
+	}
+
+	callbacks_pointer = callbacks;
+	eap_methods = 0;
+
+	interface_table = g_hash_table_new_full(g_str_hash, g_str_equal,
+						NULL, remove_interface);
+
+	bss_mapping = g_hash_table_new_full(g_str_hash, g_str_equal,
+								NULL, NULL);
+
+	supplicant_dbus_setup(connection);
+
+	dbus_bus_add_match(connection, supplicant_rule0, NULL);
+	dbus_bus_add_match(connection, supplicant_rule1, NULL);
+	dbus_bus_add_match(connection, supplicant_rule2, NULL);
+	dbus_bus_add_match(connection, supplicant_rule3, NULL);
+	dbus_bus_add_match(connection, supplicant_rule4, NULL);
+	dbus_bus_add_match(connection, supplicant_rule5, NULL);
+	dbus_bus_add_match(connection, supplicant_rule6, NULL);
+	dbus_connection_flush(connection);
+
+	if (dbus_bus_name_has_owner(connection,
+					SUPPLICANT_SERVICE, NULL)) {
+		system_available = TRUE;
+		supplicant_bootstrap();
+	}
+
+	return 0;
+}
+
+void supplicant_unregister(const struct supplicant_callbacks *callbacks)
+{
+	if (connection) {
+		dbus_bus_remove_match(connection, supplicant_rule6, NULL);
+		dbus_bus_remove_match(connection, supplicant_rule5, NULL);
+		dbus_bus_remove_match(connection, supplicant_rule4, NULL);
+		dbus_bus_remove_match(connection, supplicant_rule3, NULL);
+		dbus_bus_remove_match(connection, supplicant_rule2, NULL);
+		dbus_bus_remove_match(connection, supplicant_rule1, NULL);
+		dbus_bus_remove_match(connection, supplicant_rule0, NULL);
+		dbus_connection_flush(connection);
+
+		dbus_connection_remove_filter(connection,
+						supplicant_filter, NULL);
+	}
+
+	if (bss_mapping) {
+		g_hash_table_destroy(bss_mapping);
+		bss_mapping = NULL;
+	}
+
+	if (interface_table) {
+		g_hash_table_destroy(interface_table);
+		interface_table = NULL;
+	}
+
+	if (system_available)
+		callback_system_killed();
+
+	if (connection) {
+		dbus_connection_unref(connection);
+		connection = NULL;
+	}
+
+	callbacks_pointer = NULL;
+	eap_methods = 0;
+}
+
+static void debug_level_result(const char *error,
+				DBusMessageIter *iter, void *user_data)
+{
+	if (error)
+		DBG("debug level failure: %s", error);
+}
+
+static void debug_level_params(DBusMessageIter *iter, void *user_data)
+{
+	guint level = GPOINTER_TO_UINT(user_data);
+	const char *str;
+
+	if (level > 4)
+		level = 4;
+
+	str = debug_strings[level];
+
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &str);
+}
+
+void supplicant_set_debug_level(unsigned int level)
+{
+	if (!system_available)
+		return;
+
+	supplicant_dbus_property_set(SUPPLICANT_PATH, SUPPLICANT_INTERFACE,
+				"DebugLevel", DBUS_TYPE_STRING_AS_STRING,
+				debug_level_params, debug_level_result,
+						GUINT_TO_POINTER(level));
+}
+
+struct interface_create_data {
+	const char *ifname;
+	const char *driver;
+	struct supplicant_interface *interface;
+	supplicant_interface_create_callback callback;
+	void *user_data;
+};
+
+static void interface_create_property(const char *key, DBusMessageIter *iter,
+							void *user_data)
+{
+	struct interface_create_data *data = user_data;
+	struct supplicant_interface *interface = data->interface;
+
+	if (!key) {
+		if (data->callback)
+			data->callback(0, data->interface, data->user_data);
+
+		dbus_free(data);
+	}
+
+	interface_property(key, iter, interface);
+}
+
+static void interface_create_result(const char *error,
+				DBusMessageIter *iter, void *user_data)
+{
+	struct interface_create_data *data = user_data;
+	const char *path = NULL;
+	int err;
+
+	if (error) {
+		err = -EIO;
+		goto done;
+	}
+
+	dbus_message_iter_get_basic(iter, &path);
+	if (!path) {
+		err = -EINVAL;
+		goto done;
+	}
+
+	if (!system_available) {
+		err = -EFAULT;
+		goto done;
+	}
+
+	data->interface = g_hash_table_lookup(interface_table, path);
+	if (!data->interface) {
+		data->interface = interface_alloc(path);
+		if (!data->interface) {
+			err = -ENOMEM;
+			goto done;
+		}
+	}
+
+	err = supplicant_dbus_property_get_all(path,
+					SUPPLICANT_INTERFACE ".Interface",
+					interface_create_property, data);
+	if (err == 0)
+		return;
+
+done:
+	if (data->callback)
+		data->callback(err, NULL, data->user_data);
+
+	dbus_free(data);
+}
+
+static void interface_create_params(DBusMessageIter *iter, void *user_data)
+{
+	struct interface_create_data *data = user_data;
+	DBusMessageIter dict;
+
+	supplicant_dbus_dict_open(iter, &dict);
+
+	supplicant_dbus_dict_append_basic(&dict, "Ifname",
+					DBUS_TYPE_STRING, &data->ifname);
+
+	if (data->driver)
+		supplicant_dbus_dict_append_basic(&dict, "Driver",
+					DBUS_TYPE_STRING, &data->driver);
+
+	supplicant_dbus_dict_close(iter, &dict);
+}
+
+static void interface_get_result(const char *error,
+				DBusMessageIter *iter, void *user_data)
+{
+	struct interface_create_data *data = user_data;
+	struct supplicant_interface *interface;
+	const char *path = NULL;
+	int err;
+
+	if (error)
+		goto create;
+
+	dbus_message_iter_get_basic(iter, &path);
+	if (!path) {
+		err = -EINVAL;
+		goto done;
+	}
+
+	interface = g_hash_table_lookup(interface_table, path);
+	if (!interface) {
+		err = -ENOENT;
+		goto done;
+	}
+
+	if (data->callback)
+		data->callback(0, interface, data->user_data);
+
+	dbus_free(data);
+
+	return;
+
+create:
+	if (!system_available) {
+		err = -EFAULT;
+		goto done;
+	}
+
+	err = supplicant_dbus_method_call(SUPPLICANT_PATH,
+						SUPPLICANT_INTERFACE,
+						"CreateInterface",
+						interface_create_params,
+						interface_create_result, data);
+	if (err == 0)
+		return;
+
+done:
+	if (data->callback)
+		data->callback(err, NULL, data->user_data);
+
+	dbus_free(data);
+}
+
+static void interface_get_params(DBusMessageIter *iter, void *user_data)
+{
+	struct interface_create_data *data = user_data;
+
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &data->ifname);
+}
+
+int supplicant_interface_create(const char *ifname, const char *driver,
+			supplicant_interface_create_callback callback,
+							void *user_data)
+{
+	struct interface_create_data *data;
+
+	if (!ifname)
+		return -EINVAL;
+
+	if (!system_available)
+		return -EFAULT;
+
+	data = dbus_malloc0(sizeof(*data));
+	if (!data)
+		return -ENOMEM;
+
+	data->ifname = ifname;
+	data->driver = driver;
+	data->callback = callback;
+	data->user_data = user_data;
+
+	return supplicant_dbus_method_call(SUPPLICANT_PATH,
+						SUPPLICANT_INTERFACE,
+						"GetInterface",
+						interface_get_params,
+						interface_get_result, data);
+}
+
+int supplicant_interface_remove(struct supplicant_interface *interface,
+			supplicant_interface_remove_callback callback,
+							void *user_data)
+{
+	if (!interface)
+		return -EINVAL;
+
+	if (!system_available)
+		return -EFAULT;
+
+	return 0;
+}
+
+struct interface_scan_data {
+	struct supplicant_interface *interface;
+	supplicant_interface_scan_callback callback;
+	void *user_data;
+};
+
+static void interface_scan_result(const char *error,
+				DBusMessageIter *iter, void *user_data)
+{
+	struct interface_scan_data *data = user_data;
+
+	if (error) {
+		if (data->callback)
+			data->callback(-EIO, data->user_data);
+	} else {
+		data->interface->scan_callback = data->callback;
+		data->interface->scan_data = data->user_data;
+	}
+
+	dbus_free(data);
+}
+
+static void interface_scan_params(DBusMessageIter *iter, void *user_data)
+{
+	DBusMessageIter dict;
+	const char *type = "passive";
+
+	supplicant_dbus_dict_open(iter, &dict);
+
+	supplicant_dbus_dict_append_basic(&dict, "Type",
+						DBUS_TYPE_STRING, &type);
+
+	supplicant_dbus_dict_close(iter, &dict);
+}
+
+int supplicant_interface_scan(struct supplicant_interface *interface,
+			supplicant_interface_scan_callback callback,
+							void *user_data)
+{
+	struct interface_scan_data *data;
+
+	if (!interface)
+		return -EINVAL;
+
+	if (!system_available)
+		return -EFAULT;
+
+	if (interface->scanning)
+		return -EALREADY;
+
+	data = dbus_malloc0(sizeof(*data));
+	if (!data)
+		return -ENOMEM;
+
+	data->interface = interface;
+	data->callback = callback;
+	data->user_data = user_data;
+
+	return supplicant_dbus_method_call(interface->path,
+			SUPPLICANT_INTERFACE ".Interface", "Scan",
+			interface_scan_params, interface_scan_result, data);
+}
+
+struct interface_disconnect_data {
+	supplicant_interface_disconnect_callback callback;
+	void *user_data;
+};
+
+static void interface_disconnect_result(const char *error,
+				DBusMessageIter *iter, void *user_data)
+{
+	struct interface_disconnect_data *data = user_data;
+	int result = 0;
+
+	if (error)
+		result = -EIO;
+
+	if (data->callback)
+		data->callback(result, data->user_data);
+
+	dbus_free(data);
+}
+
+int supplicant_interface_disconnect(struct supplicant_interface *interface,
+			supplicant_interface_disconnect_callback callback,
+							void *user_data)
+{
+	struct interface_disconnect_data *data;
+
+	if (!interface)
+		return -EINVAL;
+
+	if (!system_available)
+		return -EFAULT;
+
+	data = dbus_malloc0(sizeof(*data));
+	if (!data)
+		return -ENOMEM;
+
+	data->callback = callback;
+	data->user_data = user_data;
+
+	return supplicant_dbus_method_call(interface->path,
+			SUPPLICANT_INTERFACE ".Interface", "Disconnect",
+				NULL, interface_disconnect_result, data);
+}
diff --git a/connman/tools/supplicant.h b/connman/tools/supplicant.h
new file mode 100644
index 0000000..556dc7d
--- /dev/null
+++ b/connman/tools/supplicant.h
@@ -0,0 +1,139 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2012  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
+ *
+ */
+
+#define SUPPLICANT_EAP_METHOD_MD5	(1 << 0)
+#define SUPPLICANT_EAP_METHOD_TLS	(1 << 1)
+#define SUPPLICANT_EAP_METHOD_MSCHAPV2	(1 << 2)
+#define SUPPLICANT_EAP_METHOD_PEAP	(1 << 3)
+#define SUPPLICANT_EAP_METHOD_TTLS	(1 << 4)
+#define SUPPLICANT_EAP_METHOD_GTC	(1 << 5)
+#define SUPPLICANT_EAP_METHOD_OTP	(1 << 6)
+#define SUPPLICANT_EAP_METHOD_LEAP	(1 << 7)
+#define SUPPLICANT_EAP_METHOD_WSC	(1 << 8)
+
+#define SUPPLICANT_CAPABILITY_KEYMGMT_NONE	(1 << 0)
+#define SUPPLICANT_CAPABILITY_KEYMGMT_IEEE8021X	(1 << 1)
+#define SUPPLICANT_CAPABILITY_KEYMGMT_WPA_NONE	(1 << 2)
+#define SUPPLICANT_CAPABILITY_KEYMGMT_WPA_PSK	(1 << 3)
+#define SUPPLICANT_CAPABILITY_KEYMGMT_WPA_EAP	(1 << 4)
+#define SUPPLICANT_CAPABILITY_KEYMGMT_WPS	(1 << 5)
+
+#define SUPPLICANT_CAPABILITY_AUTHALG_OPEN	(1 << 0)
+#define SUPPLICANT_CAPABILITY_AUTHALG_SHARED	(1 << 1)
+#define SUPPLICANT_CAPABILITY_AUTHALG_LEAP	(1 << 2)
+
+#define SUPPLICANT_CAPABILITY_PROTO_WPA		(1 << 0)
+#define SUPPLICANT_CAPABILITY_PROTO_RSN		(1 << 1)
+
+#define SUPPLICANT_CAPABILITY_GROUP_WEP40	(1 << 0)
+#define SUPPLICANT_CAPABILITY_GROUP_WEP104	(1 << 1)
+#define SUPPLICANT_CAPABILITY_GROUP_TKIP	(1 << 2)
+#define SUPPLICANT_CAPABILITY_GROUP_CCMP	(1 << 3)
+
+#define SUPPLICANT_CAPABILITY_PAIRWISE_NONE	(1 << 0)
+#define SUPPLICANT_CAPABILITY_PAIRWISE_TKIP	(1 << 1)
+#define SUPPLICANT_CAPABILITY_PAIRWISE_CCMP	(1 << 2)
+
+#define SUPPLICANT_CAPABILITY_SCAN_ACTIVE	(1 << 0)
+#define SUPPLICANT_CAPABILITY_SCAN_PASSIVE	(1 << 1)
+#define SUPPLICANT_CAPABILITY_SCAN_SSID		(1 << 2)
+
+#define SUPPLICANT_CAPABILITY_MODE_INFRA	(1 << 0)
+#define SUPPLICANT_CAPABILITY_MODE_IBSS		(1 << 1)
+#define SUPPLICANT_CAPABILITY_MODE_AP		(1 << 2)
+
+enum supplicant_mode {
+	SUPPLICANT_MODE_UNKNOWN,
+	SUPPLICANT_MODE_INFRA,
+	SUPPLICANT_MODE_IBSS,
+};
+
+enum supplicant_security {
+	SUPPLICANT_SECURITY_UNKNOWN,
+	SUPPLICANT_SECURITY_NONE,
+	SUPPLICANT_SECURITY_WEP,
+	SUPPLICANT_SECURITY_PSK,
+	SUPPLICANT_SECURITY_IEEE8021X,
+};
+
+enum supplicant_state {
+	SUPPLICANT_STATE_UNKNOWN,
+	SUPPLICANT_STATE_DISCONNECTED,
+	SUPPLICANT_STATE_INACTIVE,
+	SUPPLICANT_STATE_SCANNING,
+	SUPPLICANT_STATE_AUTHENTICATING,
+	SUPPLICANT_STATE_ASSOCIATING,
+	SUPPLICANT_STATE_ASSOCIATED,
+	SUPPLICANT_STATE_4WAY_HANDSHAKE,
+	SUPPLICANT_STATE_GROUP_HANDSHAKE,
+	SUPPLICANT_STATE_COMPLETED,
+};
+
+struct supplicant_interface;
+
+typedef void (* supplicant_interface_create_callback) (int result,
+				struct supplicant_interface *interface,
+							void *user_data);
+typedef void (* supplicant_interface_remove_callback) (int result,
+							void *user_data);
+typedef void (* supplicant_interface_scan_callback) (int result,
+							void *user_data);
+typedef void (* supplicant_interface_disconnect_callback) (int result,
+							void *user_data);
+
+int supplicant_interface_create(const char *ifname, const char *driver,
+			supplicant_interface_create_callback callback,
+							void *user_data);
+int supplicant_interface_remove(struct supplicant_interface *interface,
+			supplicant_interface_remove_callback callback,
+							void *user_data);
+int supplicant_interface_scan(struct supplicant_interface *interface,
+			supplicant_interface_scan_callback callback,
+							void *user_data);
+int supplicant_interface_disconnect(struct supplicant_interface *interface,
+			supplicant_interface_disconnect_callback callback,
+							void *user_data);
+
+const char *supplicant_interface_get_ifname(struct supplicant_interface *interface);
+const char *supplicant_interface_get_driver(struct supplicant_interface *interface);
+
+struct supplicant_network;
+
+struct supplicant_interface *supplicant_network_get_interface(struct supplicant_network *network);
+const char *supplicant_network_get_name(struct supplicant_network *network);
+const char *supplicant_network_get_identifier(struct supplicant_network *network);
+enum supplicant_mode supplicant_network_get_mode(struct supplicant_network *network);
+
+struct supplicant_callbacks {
+	void (*system_ready) (void);
+	void (*system_killed) (void);
+	void (*interface_added) (struct supplicant_interface *interface);
+	void (*interface_removed) (struct supplicant_interface *interface);
+	void (*scan_started) (struct supplicant_interface *interface);
+	void (*scan_finished) (struct supplicant_interface *interface);
+	void (*network_added) (struct supplicant_network *network);
+	void (*network_removed) (struct supplicant_network *network);
+};
+
+int supplicant_register(const struct supplicant_callbacks *callbacks);
+void supplicant_unregister(const struct supplicant_callbacks *callbacks);
+
+void supplicant_set_debug_level(unsigned int level);
diff --git a/connman/tools/tap-test.c b/connman/tools/tap-test.c
new file mode 100644
index 0000000..fdc098a
--- /dev/null
+++ b/connman/tools/tap-test.c
@@ -0,0 +1,198 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2012  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
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <string.h>
+#include <sys/poll.h>
+#include <sys/ioctl.h>
+
+#include <netinet/in.h>
+#include <netinet/ip.h>
+#include <net/ethernet.h>
+#include <net/if.h>
+#include <net/if_arp.h>
+#include <linux/if_tun.h>
+
+static int inet_ifup(const char *ifname)
+{
+	struct ifreq ifr;
+	int sk, err;
+
+	sk = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
+	if (sk < 0)
+		return -errno;
+
+	memset(&ifr, 0, sizeof(ifr));
+	strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name) - 1);
+
+	if (ioctl(sk, SIOCGIFFLAGS, &ifr) < 0) {
+		err = -errno;
+		goto done;
+	}
+
+	if (ifr.ifr_flags & IFF_UP) {
+		err = -EALREADY;
+		goto done;
+	}
+
+	ifr.ifr_flags |= IFF_UP;
+
+	if (ioctl(sk, SIOCSIFFLAGS, &ifr) < 0) {
+		err = -errno;
+		goto done;
+	}
+
+	err = 0;
+
+done:
+	close(sk);
+
+	return err;
+}
+
+static int create_tap(const char *ifname)
+{
+	struct ifreq ifr;
+	int fd, val;
+
+	fd = open("/dev/net/tun", O_RDWR | O_CLOEXEC);
+	if (fd < 0) {
+		perror("Failed to open TUN/TAP device");
+		return -1;
+	}
+
+	memset(&ifr, 0, sizeof(ifr));
+	ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
+	strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name) - 1);
+
+	if (ioctl(fd, TUNSETIFF, (void *) &ifr) < 0) {
+		perror("Failed to set TUN/TAP interface");
+		close(fd);
+		return -1;
+	}
+
+	val = ARPHRD_ETHER;
+
+	if (ioctl(fd, TUNSETLINK, (unsigned long) val) < 0)
+		perror("Failed to set TUN/TAP link type");
+
+	return fd;
+}
+
+static void dump_packet(unsigned char *buf, int len)
+{
+	int i;
+
+	printf("[");
+	for (i = 0; i < len; i++) {
+		printf(" %02x", buf[i]);
+		if ((i + 1) % 16 == 0)
+			printf("\n ");
+		else if ((i + 1) % 8 == 0)
+			printf(" ");
+	}
+	printf(" ]\n");
+}
+
+static void decode_ip(unsigned char *buf, int len)
+{
+	struct iphdr *ip = (void *) buf;
+
+	printf("    IP proto %d saddr 0x%08x daddr 0x%08x\n",
+					ip->protocol, ip->saddr, ip->daddr);
+}
+
+static void decode_packet(unsigned char *buf, int len)
+{
+	struct ether_header *eh = (void *) buf;
+	char src[18], dst[18];
+	uint16_t type;
+
+	snprintf(dst, sizeof(dst), "%02x:%02x:%02x:%02x:%02x:%02x",
+				eh->ether_dhost[0], eh->ether_dhost[1],
+				eh->ether_dhost[2], eh->ether_dhost[3],
+				eh->ether_dhost[4], eh->ether_dhost[5]);
+
+	snprintf(src, sizeof(src), "%02x:%02x:%02x:%02x:%02x:%02x",
+				eh->ether_shost[0], eh->ether_shost[1],
+				eh->ether_shost[2], eh->ether_shost[3],
+				eh->ether_shost[4], eh->ether_shost[5]);
+
+	type = ntohs(eh->ether_type);
+
+	printf("> type 0x%04x src %s dst %s <\n", type, src, dst);
+
+	switch (type) {
+	case ETHERTYPE_IP:
+		decode_ip(buf + 14, len - 14);
+		break;
+	case ETHERTYPE_LOOPBACK:
+		dump_packet(buf, len);
+		break;
+	}
+}
+
+int main(int argc, char *argv[])
+{
+	const char *ifname = "xxx";
+	struct pollfd p;
+	int fd;
+
+	fd = create_tap(ifname);
+	if (fd < 0)
+		return 1;
+
+	if (inet_ifup(ifname) < 0) {
+		close(fd);
+		return 1;
+	}
+
+	memset(&p, 0, sizeof(p));
+	p.fd = fd;
+	p.events = POLLHUP | POLLIN;
+
+	while (1) {
+		unsigned char buf[2048];
+		int len;
+
+		len = poll(&p, 1, -1);
+		if (len < 0)
+			break;
+		if (len == 0)
+			continue;
+
+		len = read(fd, buf, sizeof(buf));
+		if (len < 0)
+			break;
+
+		decode_packet(buf, len);
+	}
+
+	return 0;
+}
diff --git a/connman/tools/web-test.c b/connman/tools/web-test.c
new file mode 100644
index 0000000..55c58af
--- /dev/null
+++ b/connman/tools/web-test.c
@@ -0,0 +1,172 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2012  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 <stdio.h>
+#include <string.h>
+#include <signal.h>
+
+#include <gweb/gweb.h>
+
+static GTimer *timer;
+
+static GMainLoop *main_loop;
+
+static void web_debug(const char *str, void *data)
+{
+	g_print("%s: %s\n", (const char *) data, str);
+}
+
+static void sig_term(int sig)
+{
+	g_main_loop_quit(main_loop);
+}
+
+static bool web_result(GWebResult *result, gpointer user_data)
+{
+	const guint8 *chunk;
+	gsize length;
+	guint16 status;
+	gdouble elapsed;
+
+	g_web_result_get_chunk(result, &chunk, &length);
+
+	if (length > 0) {
+		printf("%s\n", (char *) chunk);
+		return true;
+	}
+
+	status = g_web_result_get_status(result);
+
+	g_print("status: %03u\n", status);
+
+	elapsed = g_timer_elapsed(timer, NULL);
+
+	g_print("elapse: %f seconds\n", elapsed);
+
+	g_main_loop_quit(main_loop);
+
+	return false;
+}
+
+static bool option_debug = false;
+static gchar *option_proxy = NULL;
+static gchar *option_nameserver = NULL;
+static gchar *option_user_agent = NULL;
+static gchar *option_http_version = NULL;
+
+static GOptionEntry options[] = {
+	{ "debug", 'd', 0, G_OPTION_ARG_NONE, &option_debug,
+					"Enable debug output" },
+	{ "proxy", 'p', 0, G_OPTION_ARG_STRING, &option_proxy,
+					"Specify proxy", "ADDRESS" },
+	{ "nameserver", 'n', 0, G_OPTION_ARG_STRING, &option_nameserver,
+					"Specify nameserver", "ADDRESS" },
+	{ "user-agent", 'A', 0, G_OPTION_ARG_STRING, &option_user_agent,
+					"Specific user agent", "STRING" },
+	{ "http-version", 'H', 0, G_OPTION_ARG_STRING, &option_http_version,
+					"Specific HTTP version", "STRING" },
+	{ NULL },
+};
+
+int main(int argc, char *argv[])
+{
+	GOptionContext *context;
+	GError *error = NULL;
+	struct sigaction sa;
+	GWeb *web;
+	int index = 0;
+
+	context = g_option_context_new(NULL);
+	g_option_context_add_main_entries(context, options, NULL);
+
+	if (!g_option_context_parse(context, &argc, &argv, &error)) {
+		if (error) {
+			g_printerr("%s\n", error->message);
+			g_error_free(error);
+		} else
+			g_printerr("An unknown error occurred\n");
+		return 1;
+	}
+
+	g_option_context_free(context);
+
+	if (argc < 2) {
+		fprintf(stderr, "Missing argument\n");
+		return 1;
+	}
+
+	web = g_web_new(index);
+	if (!web) {
+		fprintf(stderr, "Failed to create web service\n");
+		return 1;
+	}
+
+	if (option_debug)
+		g_web_set_debug(web, web_debug, "WEB");
+
+	main_loop = g_main_loop_new(NULL, FALSE);
+
+	if (option_proxy) {
+		g_web_set_proxy(web, option_proxy);
+		g_free(option_proxy);
+	}
+
+	if (option_nameserver) {
+		g_web_add_nameserver(web, option_nameserver);
+		g_free(option_nameserver);
+	}
+
+	if (option_user_agent) {
+		g_web_set_user_agent(web, "%s", option_user_agent);
+		g_free(option_user_agent);
+	}
+
+	if (option_http_version) {
+		g_web_set_http_version(web, option_http_version);
+		g_free(option_http_version);
+	}
+
+	timer = g_timer_new();
+
+	if (g_web_request_get(web, argv[1], web_result, NULL,  NULL) == 0) {
+		fprintf(stderr, "Failed to start request\n");
+		return 1;
+	}
+
+	memset(&sa, 0, sizeof(sa));
+	sa.sa_handler = sig_term;
+	sigaction(SIGINT, &sa, NULL);
+	sigaction(SIGTERM, &sa, NULL);
+
+	g_main_loop_run(main_loop);
+
+	g_timer_destroy(timer);
+
+	g_web_unref(web);
+
+	g_main_loop_unref(main_loop);
+
+	return 0;
+}
diff --git a/connman/tools/wispr.c b/connman/tools/wispr.c
new file mode 100644
index 0000000..d5f9341
--- /dev/null
+++ b/connman/tools/wispr.c
@@ -0,0 +1,727 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2012  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
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <signal.h>
+#include <termios.h>
+#include <netdb.h>
+
+#include <gweb/gweb.h>
+
+#define DEFAULT_URL  "http://www.connman.net/online/status.html"
+
+static GTimer *timer;
+
+static GMainLoop *main_loop;
+
+static void web_debug(const char *str, void *data)
+{
+	g_print("%s: %s\n", (const char *) data, str);
+}
+
+static void sig_term(int sig)
+{
+	g_main_loop_quit(main_loop);
+}
+
+static const char *message_type_to_string(int message_type)
+{
+	switch (message_type) {
+	case 100:
+		return "Initial redirect message";
+	case 110:
+		return "Proxy notification";
+	case 120:
+		return "Authentication notification";
+	case 130:
+		return "Logoff notification";
+	case 140:
+		return "Response to Authentication Poll";
+	case 150:
+		return "Response to Abort Login";
+	}
+
+	return NULL;
+}
+
+static const char *response_code_to_string(int response_code)
+{
+	switch (response_code) {
+	case 0:
+		return "No error";
+	case 50:
+		return "Login succeeded";
+	case 100:
+		return "Login failed";
+	case 102:
+		return "RADIUS server error/timeout";
+	case 105:
+		return "RADIUS server not enabled";
+	case 150:
+		return "Logoff succeeded";
+	case 151:
+		return "Login aborted";
+	case 200:
+		return "Proxy detection/repeat operation";
+	case 201:
+		return "Authentication pending";
+	case 255:
+		return "Access gateway internal error";
+	}
+
+	return NULL;
+}
+
+struct wispr_msg {
+	bool has_error;
+	const char *current_element;
+	int message_type;
+	int response_code;
+	char *login_url;
+	char *abort_login_url;
+	char *logoff_url;
+	char *access_procedure;
+	char *access_location;
+	char *location_name;
+};
+
+static inline void wispr_msg_init(struct wispr_msg *msg)
+{
+	msg->has_error = false;
+	msg->current_element = NULL;
+
+	msg->message_type = -1;
+	msg->response_code = -1;
+
+	g_free(msg->login_url);
+	msg->login_url = NULL;
+
+	g_free(msg->abort_login_url);
+	msg->abort_login_url = NULL;
+
+	g_free(msg->logoff_url);
+	msg->logoff_url = NULL;
+
+	g_free(msg->access_procedure);
+	msg->access_procedure = NULL;
+
+	g_free(msg->access_location);
+	msg->access_location = NULL;
+
+	g_free(msg->location_name);
+	msg->location_name = NULL;
+}
+
+struct wispr_session {
+	GWeb *web;
+	GWebParser *parser;
+	guint request;
+	struct wispr_msg msg;
+	char *username;
+	char *password;
+	char *originurl;
+	char *formdata;
+};
+
+static gboolean execute_login(gpointer user_data);
+
+static struct {
+	const char *str;
+	enum {
+		WISPR_ELEMENT_NONE,
+		WISPR_ELEMENT_ACCESS_PROCEDURE,
+		WISPR_ELEMENT_ACCESS_LOCATION,
+		WISPR_ELEMENT_LOCATION_NAME,
+		WISPR_ELEMENT_LOGIN_URL,
+		WISPR_ELEMENT_ABORT_LOGIN_URL,
+		WISPR_ELEMENT_MESSAGE_TYPE,
+		WISPR_ELEMENT_RESPONSE_CODE,
+		WISPR_ELEMENT_NEXT_URL,
+		WISPR_ELEMENT_DELAY,
+		WISPR_ELEMENT_REPLY_MESSAGE,
+		WISPR_ELEMENT_LOGIN_RESULTS_URL,
+		WISPR_ELEMENT_LOGOFF_URL,
+	} element;
+} wispr_element_map[] = {
+	{ "AccessProcedure",	WISPR_ELEMENT_ACCESS_PROCEDURE	},
+	{ "AccessLocation",	WISPR_ELEMENT_ACCESS_LOCATION	},
+	{ "LocationName",	WISPR_ELEMENT_LOCATION_NAME	},
+	{ "LoginURL",		WISPR_ELEMENT_LOGIN_URL		},
+	{ "AbortLoginURL",	WISPR_ELEMENT_ABORT_LOGIN_URL	},
+	{ "MessageType",	WISPR_ELEMENT_MESSAGE_TYPE	},
+	{ "ResponseCode",	WISPR_ELEMENT_RESPONSE_CODE	},
+	{ "NextURL",		WISPR_ELEMENT_NEXT_URL		},
+	{ "Delay",		WISPR_ELEMENT_DELAY		},
+	{ "ReplyMessage",	WISPR_ELEMENT_REPLY_MESSAGE	},
+	{ "LoginResultsURL",	WISPR_ELEMENT_LOGIN_RESULTS_URL	},
+	{ "LogoffURL",		WISPR_ELEMENT_LOGOFF_URL	},
+	{ NULL,			WISPR_ELEMENT_NONE		},
+};
+
+static void start_element_handler(GMarkupParseContext *context,
+					const gchar *element_name,
+					const gchar **attribute_names,
+					const gchar **attribute_values,
+					gpointer user_data, GError **error)
+{
+	struct wispr_msg *msg = user_data;
+
+	msg->current_element = element_name;
+}
+
+static void end_element_handler(GMarkupParseContext *context,
+					const gchar *element_name,
+					gpointer user_data, GError **error)
+{
+	struct wispr_msg *msg = user_data;
+
+	msg->current_element = NULL;
+}
+
+static void text_handler(GMarkupParseContext *context,
+					const gchar *text, gsize text_len,
+					gpointer user_data, GError **error)
+{
+	struct wispr_msg *msg = user_data;
+	int i;
+
+	if (!msg->current_element)
+		return;
+
+	for (i = 0; wispr_element_map[i].str; i++) {
+		if (!g_str_equal(wispr_element_map[i].str, msg->current_element))
+			continue;
+
+		switch (wispr_element_map[i].element) {
+		case WISPR_ELEMENT_NONE:
+		case WISPR_ELEMENT_ACCESS_PROCEDURE:
+			g_free(msg->access_procedure);
+			msg->access_procedure = g_strdup(text);
+			break;
+		case WISPR_ELEMENT_ACCESS_LOCATION:
+			g_free(msg->access_location);
+			msg->access_location = g_strdup(text);
+			break;
+		case WISPR_ELEMENT_LOCATION_NAME:
+			g_free(msg->location_name);
+			msg->location_name = g_strdup(text);
+			break;
+		case WISPR_ELEMENT_LOGIN_URL:
+			g_free(msg->login_url);
+			msg->login_url = g_strdup(text);
+			break;
+		case WISPR_ELEMENT_ABORT_LOGIN_URL:
+			g_free(msg->abort_login_url);
+			msg->abort_login_url = g_strdup(text);
+			break;
+		case WISPR_ELEMENT_MESSAGE_TYPE:
+			msg->message_type = atoi(text);
+			break;
+		case WISPR_ELEMENT_RESPONSE_CODE:
+			msg->response_code = atoi(text);
+			break;
+		case WISPR_ELEMENT_NEXT_URL:
+		case WISPR_ELEMENT_DELAY:
+		case WISPR_ELEMENT_REPLY_MESSAGE:
+		case WISPR_ELEMENT_LOGIN_RESULTS_URL:
+			break;
+		case WISPR_ELEMENT_LOGOFF_URL:
+			g_free(msg->logoff_url);
+			msg->logoff_url = g_strdup(text);
+			break;
+		}
+	}
+}
+
+static void error_handler(GMarkupParseContext *context,
+					GError *error, gpointer user_data)
+{
+	struct wispr_msg *msg = user_data;
+
+	msg->has_error = true;
+}
+
+static const GMarkupParser wispr_parser = {
+	start_element_handler,
+	end_element_handler,
+	text_handler,
+	NULL,
+	error_handler,
+};
+
+static void parser_callback(const char *str, gpointer user_data)
+{
+	struct wispr_session *wispr = user_data;
+	GMarkupParseContext *context;
+	bool result;
+
+	//printf("%s\n", str);
+
+	context = g_markup_parse_context_new(&wispr_parser,
+			G_MARKUP_TREAT_CDATA_AS_TEXT, &wispr->msg, NULL);
+
+	result = g_markup_parse_context_parse(context, str, strlen(str), NULL);
+	if (result)
+		g_markup_parse_context_end_parse(context, NULL);
+
+	g_markup_parse_context_free(context);
+}
+
+typedef void (*user_input_cb)(const char *value, gpointer user_data);
+
+struct user_input_data {
+	GString *str;
+	user_input_cb cb;
+	gpointer user_data;
+	bool hidden;
+	int fd;
+	struct termios saved_termios;
+};
+
+static void user_callback(struct user_input_data *data)
+{
+	char *value;
+
+	if (data->hidden) {
+		ssize_t len;
+
+		len = write(data->fd, "\n", 1);
+		if (len < 0)
+			return;
+	}
+
+	tcsetattr(data->fd, TCSADRAIN, &data->saved_termios);
+
+	close(data->fd);
+
+	value = g_string_free(data->str, FALSE);
+
+	if (data->cb)
+		data->cb(value, data->user_data);
+
+	g_free(value);
+
+	g_free(data);
+}
+
+static gboolean keyboard_input(GIOChannel *channel, GIOCondition condition,
+							gpointer user_data)
+{
+	struct user_input_data *data = user_data;
+	char buf[1];
+	int len;
+
+	len = read(data->fd, buf, 1);
+
+	if (len != 1)
+		return TRUE;
+
+	if (buf[0] == '\n') {
+		user_callback(data);
+		return FALSE;
+	}
+
+	g_string_append_c(data->str, buf[0]);
+
+	if (data->hidden)
+		len = write(data->fd, "*", 1);
+
+	return TRUE;
+}
+
+static bool user_input(const char *label, bool hidden,
+				user_input_cb func, gpointer user_data)
+{
+	struct user_input_data *data;
+	struct termios new_termios;
+	GIOChannel *channel;
+	guint watch;
+	ssize_t len;
+
+	data = g_try_new0(struct user_input_data, 1);
+	if (!data)
+		return false;
+
+	data->str = g_string_sized_new(32);
+	data->cb = func;
+	data->user_data = user_data;
+	data->hidden = hidden;
+
+	data->fd = open("/dev/tty", O_RDWR | O_NOCTTY | O_CLOEXEC);
+	if (data->fd < 0)
+		goto error;
+
+	if (tcgetattr(data->fd, &data->saved_termios) < 0) {
+		close(data->fd);
+		goto error;
+	}
+
+	new_termios = data->saved_termios;
+	if (data->hidden)
+		new_termios.c_lflag &= ~(ICANON|ECHO);
+	else
+		new_termios.c_lflag &= ~ICANON;
+	new_termios.c_cc[VMIN] = 1;
+	new_termios.c_cc[VTIME] = 0;
+
+	tcsetattr(data->fd, TCSADRAIN, &new_termios);
+
+	channel = g_io_channel_unix_new(data->fd);
+	g_io_channel_set_encoding(channel, NULL, NULL);
+	g_io_channel_set_buffered(channel, FALSE);
+	watch = g_io_add_watch(channel, G_IO_IN, keyboard_input, data);
+	g_io_channel_unref(channel);
+
+	if (watch == 0)
+		goto error;
+
+	len = write(data->fd, label, strlen(label));
+	if (len < 0)
+		goto error;
+
+	len = write(data->fd, ": ", 2);
+	if (len < 0)
+		goto error;
+
+	return true;
+
+error:
+	g_string_free(data->str, TRUE);
+	g_free(data);
+
+	return false;
+}
+
+static void password_callback(const char *value, gpointer user_data)
+{
+	struct wispr_session *wispr = user_data;
+
+	g_free(wispr->password);
+	wispr->password = g_strdup(value);
+
+	printf("\n");
+
+	execute_login(wispr);
+}
+
+static void username_callback(const char *value, gpointer user_data)
+{
+	struct wispr_session *wispr = user_data;
+
+	g_free(wispr->username);
+	wispr->username = g_strdup(value);
+
+	if (!wispr->password) {
+		user_input("Password", true, password_callback, wispr);
+		return;
+	}
+
+	printf("\n");
+
+	execute_login(wispr);
+}
+
+static bool wispr_input(const guint8 **data, gsize *length,
+						gpointer user_data)
+{
+	struct wispr_session *wispr = user_data;
+	GString *buf;
+	gsize count;
+
+	buf = g_string_sized_new(100);
+
+	g_string_append(buf, "button=Login&UserName=");
+	g_string_append_uri_escaped(buf, wispr->username, NULL, FALSE);
+	g_string_append(buf, "&Password=");
+	g_string_append_uri_escaped(buf, wispr->password, NULL, FALSE);
+	g_string_append(buf, "&FNAME=0&OriginatingServer=");
+	g_string_append_uri_escaped(buf, wispr->originurl, NULL, FALSE);
+
+	count = buf->len;
+
+	g_free(wispr->formdata);
+	wispr->formdata = g_string_free(buf, FALSE);
+
+	*data = (guint8 *) wispr->formdata;
+	*length = count;
+
+	return false;
+}
+
+static bool wispr_route(const char *addr, int ai_family, int if_index,
+		gpointer user_data)
+{
+	char *family = "unknown";
+
+	if (ai_family == AF_INET)
+		family = "IPv4";
+	else if (ai_family == AF_INET6)
+		family = "IPv6";
+
+	printf("Route request: %s %s index %d\n", family, addr, if_index);
+
+	if (ai_family != AF_INET && ai_family != AF_INET6)
+		return false;
+
+	return true;
+}
+
+static bool wispr_result(GWebResult *result, gpointer user_data)
+{
+	struct wispr_session *wispr = user_data;
+	const guint8 *chunk;
+	gsize length;
+	guint16 status;
+	gdouble elapsed;
+
+	g_web_result_get_chunk(result, &chunk, &length);
+
+	if (length > 0) {
+		//printf("%s\n", (char *) chunk);
+		g_web_parser_feed_data(wispr->parser, chunk, length);
+		return true;
+	}
+
+	g_web_parser_end_data(wispr->parser);
+
+	status = g_web_result_get_status(result);
+
+	g_print("status: %03u\n", status);
+
+	elapsed = g_timer_elapsed(timer, NULL);
+
+	g_print("elapse: %f seconds\n", elapsed);
+
+	if (wispr->msg.message_type < 0) {
+		const char *redirect;
+
+		if (status != 302)
+			goto done;
+
+		if (!g_web_result_get_header(result, "Location", &redirect))
+			goto done;
+
+		printf("Redirect URL: %s\n", redirect);
+		printf("\n");
+
+		wispr->request = g_web_request_get(wispr->web, redirect,
+				wispr_result, wispr_route, wispr);
+
+		return false;
+	}
+
+	printf("Message type: %s (%d)\n",
+			message_type_to_string(wispr->msg.message_type),
+						wispr->msg.message_type);
+	printf("Response code: %s (%d)\n",
+			response_code_to_string(wispr->msg.response_code),
+						wispr->msg.response_code);
+	if (wispr->msg.access_procedure)
+		printf("Access procedure: %s\n", wispr->msg.access_procedure);
+	if (wispr->msg.access_location)
+		printf("Access location: %s\n", wispr->msg.access_location);
+	if (wispr->msg.location_name)
+		printf("Location name: %s\n", wispr->msg.location_name);
+	if (wispr->msg.login_url)
+		printf("Login URL: %s\n", wispr->msg.login_url);
+	if (wispr->msg.abort_login_url)
+		printf("Abort login URL: %s\n", wispr->msg.abort_login_url);
+	if (wispr->msg.logoff_url)
+		printf("Logoff URL: %s\n", wispr->msg.logoff_url);
+	printf("\n");
+
+	if (status != 200 && status != 302 && status != 404)
+		goto done;
+
+	if (wispr->msg.message_type == 100) {
+		if (!wispr->username) {
+			user_input("Username", false,
+				   username_callback, wispr);
+			return false;
+		}
+
+		if (!wispr->password) {
+			user_input("Password", true, password_callback, wispr);
+			return false;
+		}
+
+		g_idle_add(execute_login, wispr);
+		return false;
+	} else if (wispr->msg.message_type == 120 ||
+					wispr->msg.message_type == 140) {
+		int code = wispr->msg.response_code;
+		printf("Login process: %s\n",
+					code == 50 ? "SUCCESS" : "FAILURE");
+	}
+
+	if (status == 302) {
+		const char *redirect;
+
+		if (!g_web_result_get_header(result, "Location", &redirect))
+			goto done;
+
+		printf("\n");
+		printf("Redirect URL: %s\n", redirect);
+		printf("\n");
+
+		wispr->request = g_web_request_get(wispr->web, redirect,
+				wispr_result, NULL, wispr);
+
+		return false;
+	}
+
+done:
+	g_main_loop_quit(main_loop);
+
+	return false;
+}
+
+static gboolean execute_login(gpointer user_data)
+{
+	struct wispr_session *wispr = user_data;
+
+	wispr->request = g_web_request_post(wispr->web, wispr->msg.login_url,
+					"application/x-www-form-urlencoded",
+					wispr_input, wispr_result, wispr);
+
+	wispr_msg_init(&wispr->msg);
+
+	return FALSE;
+}
+
+static bool option_debug = false;
+static gchar *option_nameserver = NULL;
+static gchar *option_username = NULL;
+static gchar *option_password = NULL;
+static gchar *option_url = NULL;
+
+static GOptionEntry options[] = {
+	{ "debug", 'd', 0, G_OPTION_ARG_NONE, &option_debug,
+					"Enable debug output" },
+	{ "nameserver", 'n', 0, G_OPTION_ARG_STRING, &option_nameserver,
+					"Specify nameserver", "ADDRESS" },
+	{ "username", 'u', 0, G_OPTION_ARG_STRING, &option_username,
+					"Specify username", "USERNAME" },
+	{ "password", 'p', 0, G_OPTION_ARG_STRING, &option_password,
+					"Specify password", "PASSWORD" },
+	{ "url", 'U', 0, G_OPTION_ARG_STRING, &option_url,
+					"Specify arbitrary request", "URL" },
+	{ NULL },
+};
+
+int main(int argc, char *argv[])
+{
+	GOptionContext *context;
+	GError *error = NULL;
+	struct sigaction sa;
+	struct wispr_session wispr;
+	int index = 0;
+
+	context = g_option_context_new(NULL);
+	g_option_context_add_main_entries(context, options, NULL);
+
+	if (!g_option_context_parse(context, &argc, &argv, &error)) {
+		if (error) {
+			g_printerr("%s\n", error->message);
+			g_error_free(error);
+		} else
+			g_printerr("An unknown error occurred\n");
+		return 1;
+	}
+
+	g_option_context_free(context);
+
+	memset(&wispr, 0, sizeof(wispr));
+	wispr_msg_init(&wispr.msg);
+
+	wispr.web = g_web_new(index);
+	if (!wispr.web) {
+		fprintf(stderr, "Failed to create web service\n");
+		return 1;
+	}
+
+	if (option_debug)
+		g_web_set_debug(wispr.web, web_debug, "WEB");
+
+	main_loop = g_main_loop_new(NULL, FALSE);
+
+	if (option_nameserver) {
+		g_web_add_nameserver(wispr.web, option_nameserver);
+		g_free(option_nameserver);
+	}
+
+	g_web_set_accept(wispr.web, NULL);
+	g_web_set_user_agent(wispr.web, "SmartClient/%s wispr", VERSION);
+	g_web_set_close_connection(wispr.web, TRUE);
+
+	if (!option_url)
+		option_url = g_strdup(DEFAULT_URL);
+
+	wispr.username = option_username;
+	wispr.password = option_password;
+	wispr.originurl = option_url;
+
+	timer = g_timer_new();
+
+	wispr.parser = g_web_parser_new("<WISPAccessGatewayParam",
+						"WISPAccessGatewayParam>",
+						parser_callback, &wispr);
+
+	wispr.request = g_web_request_get(wispr.web, option_url,
+			wispr_result, wispr_route, &wispr);
+
+	if (wispr.request == 0) {
+		fprintf(stderr, "Failed to start request\n");
+		return 1;
+	}
+
+	memset(&sa, 0, sizeof(sa));
+	sa.sa_handler = sig_term;
+	sigaction(SIGINT, &sa, NULL);
+	sigaction(SIGTERM, &sa, NULL);
+
+	g_main_loop_run(main_loop);
+
+	g_timer_destroy(timer);
+
+	if (wispr.request > 0)
+		g_web_cancel_request(wispr.web, wispr.request);
+
+	g_web_parser_unref(wispr.parser);
+	g_web_unref(wispr.web);
+
+	g_main_loop_unref(main_loop);
+
+	g_free(wispr.username);
+	g_free(wispr.password);
+	g_free(wispr.originurl);
+
+	return 0;
+}
diff --git a/connman/tools/wpad-test.c b/connman/tools/wpad-test.c
new file mode 100644
index 0000000..2ecbcda
--- /dev/null
+++ b/connman/tools/wpad-test.c
@@ -0,0 +1,200 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2012  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 <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <signal.h>
+
+#include <gweb/gresolv.h>
+
+static GTimer *timer;
+
+static GMainLoop *main_loop;
+
+static GResolv *resolv;
+
+static void resolv_debug(const char *str, void *data)
+{
+	g_print("%s: %s\n", (const char *) data, str);
+}
+
+static void sig_term(int sig)
+{
+	g_main_loop_quit(main_loop);
+}
+
+static void resolv_result(GResolvResultStatus status,
+					char **results, gpointer user_data)
+{
+	char *hostname = user_data;
+	char *str, *ptr;
+	gdouble elapsed;
+	int i;
+
+	if (status == G_RESOLV_RESULT_STATUS_SUCCESS) {
+		g_print("Found %s\n", hostname);
+		goto done;
+	}
+
+	g_print("No result for %s\n", hostname);
+
+	ptr = strchr(hostname + 5, '.');
+	if (!ptr || strlen(ptr) < 2) {
+		g_print("No more names\n");
+		goto done;
+	}
+
+	if (!strchr(ptr + 1, '.')) {
+		g_print("Not found\n");
+		goto done;
+	}
+
+	str = g_strdup_printf("wpad.%s", ptr + 1);
+
+	g_resolv_lookup_hostname(resolv, str, resolv_result, str);
+
+	g_free(hostname);
+
+	return;
+
+done:
+	elapsed = g_timer_elapsed(timer, NULL);
+
+	g_print("elapse: %f seconds\n", elapsed);
+
+	if (results) {
+		for (i = 0; results[i]; i++)
+			g_print("result: %s\n", results[i]);
+	}
+
+	g_free(hostname);
+
+	g_main_loop_quit(main_loop);
+}
+
+static void start_wpad(const char *search)
+{
+	char domainname[256];
+	char *hostname;
+
+	if (!search) {
+		if (getdomainname(domainname, sizeof(domainname)) < 0) {
+			g_printerr("Failed to get domain name\n");
+			goto quit;
+		}
+	} else
+		snprintf(domainname, sizeof(domainname), "%s", search);
+
+	if (strlen(domainname) == 0) {
+		g_printerr("Domain name is not set\n");
+		goto quit;
+	}
+
+	g_print("domainname: %s\n", domainname);
+
+	hostname = g_strdup_printf("wpad.%s", domainname);
+
+	g_resolv_lookup_hostname(resolv, hostname, resolv_result, hostname);
+
+	return;
+
+quit:
+	g_main_loop_quit(main_loop);
+}
+
+static bool option_debug = false;
+static gchar *option_search = NULL;
+
+static GOptionEntry options[] = {
+	{ "debug", 'd', 0, G_OPTION_ARG_NONE, &option_debug,
+					"Enable debug output" },
+	{ "search", 's', 0, G_OPTION_ARG_STRING, &option_search,
+					"Specify search domain name" },
+	{ NULL },
+};
+
+int main(int argc, char *argv[])
+{
+	GOptionContext *context;
+	GError *error = NULL;
+	struct sigaction sa;
+	int index = 0;
+
+	context = g_option_context_new(NULL);
+	g_option_context_add_main_entries(context, options, NULL);
+
+	if (!g_option_context_parse(context, &argc, &argv, &error)) {
+		if (error) {
+			g_printerr("%s\n", error->message);
+			g_error_free(error);
+		} else
+			g_printerr("An unknown error occurred\n");
+		exit(1);
+	}
+
+	g_option_context_free(context);
+
+	resolv = g_resolv_new(index);
+	if (!resolv) {
+		g_printerr("Failed to create resolver\n");
+		return 1;
+	}
+
+	if (option_debug)
+		g_resolv_set_debug(resolv, resolv_debug, "RESOLV");
+
+	main_loop = g_main_loop_new(NULL, FALSE);
+
+	if (argc > 1) {
+		int i;
+
+		for (i = 1; i < argc; i++)
+			g_resolv_add_nameserver(resolv, argv[i], 53, 0);
+	} else
+		g_resolv_add_nameserver(resolv, "127.0.0.1", 53, 0);
+
+	timer = g_timer_new();
+
+	start_wpad(option_search);
+
+	g_free(option_search);
+
+	memset(&sa, 0, sizeof(sa));
+	sa.sa_handler = sig_term;
+	sigaction(SIGINT, &sa, NULL);
+	sigaction(SIGTERM, &sa, NULL);
+
+	g_main_loop_run(main_loop);
+
+	g_timer_destroy(timer);
+
+	g_resolv_unref(resolv);
+
+	g_main_loop_unref(main_loop);
+
+	return 0;
+}
diff --git a/connman/unit/test-ippool.c b/connman/unit/test-ippool.c
new file mode 100644
index 0000000..e8d077a
--- /dev/null
+++ b/connman/unit/test-ippool.c
@@ -0,0 +1,448 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2012-2014  BMW Car IT GmbH.
+ *
+ *  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 <glib.h>
+
+#include "../src/connman.h"
+
+/* #define DEBUG */
+#ifdef DEBUG
+#include <stdio.h>
+
+#define LOG(fmt, arg...) do { \
+	fprintf(stdout, "%s:%s() " fmt "\n", \
+			__FILE__, __func__ , ## arg); \
+} while (0)
+#else
+#define LOG(fmt, arg...)
+#endif
+
+static void test_case_1(void)
+{
+	struct connman_ippool *pool;
+	int i;
+
+	__connman_ippool_init();
+
+	pool = __connman_ippool_create(23, 1, 500, NULL, NULL);
+	g_assert(!pool);
+
+	for (i = 0; i < 100000; i++) {
+		pool = __connman_ippool_create(23, 1, 20, NULL, NULL);
+		g_assert(pool);
+
+		__connman_ippool_unref(pool);
+	}
+
+	__connman_ippool_cleanup();
+}
+
+static void test_case_2(void)
+{
+	struct connman_ippool *pool;
+	const char *gateway;
+	const char *broadcast;
+	const char *subnet_mask;
+	const char *start_ip;
+	const char *end_ip;
+	int i;
+
+	__connman_ippool_init();
+
+	/* Test the IP range */
+	for (i = 1; i < 254; i++) {
+		pool = __connman_ippool_create(23, 1, i, NULL, NULL);
+		g_assert(pool);
+
+		gateway = __connman_ippool_get_gateway(pool);
+		broadcast = __connman_ippool_get_broadcast(pool);
+		subnet_mask = __connman_ippool_get_subnet_mask(pool);
+		start_ip = __connman_ippool_get_start_ip(pool);
+		end_ip = __connman_ippool_get_end_ip(pool);
+
+		g_assert(gateway);
+		g_assert(broadcast);
+		g_assert(subnet_mask);
+		g_assert(start_ip);
+		g_assert(end_ip);
+
+		LOG("\n\tIP range %s --> %s\n"
+			"\tgateway %s broadcast %s mask %s", start_ip, end_ip,
+			gateway, broadcast, subnet_mask);
+
+		__connman_ippool_unref(pool);
+	}
+
+	__connman_ippool_cleanup();
+}
+
+static void test_case_3(void)
+{
+	struct connman_ippool *pool;
+	const char *gateway;
+	const char *broadcast;
+	const char *subnet_mask;
+	const char *start_ip;
+	const char *end_ip;
+	GSList *list = NULL, *it;
+	int i = 0;
+
+	__connman_ippool_init();
+
+	/*
+	 *                                             Number of addresses
+	 * 24-bit block         10.0.0.0    – 10.255.255.255    16,777,216
+	 * 20-bit block         172.16.0.0  – 172.31.255.255     1,048,576
+	 * 16-bit block         192.168.0.0 – 192.168.255.255       65,536
+	 *
+	 * Total                                                17,891,328
+	 *
+	 * Total numbers of 256 blocks:                             69,888
+	 */
+
+	/*
+	 * Completely exhaust the first two pools because they are a bit
+	 * too large.
+	 */
+	__connman_ippool_newaddr(45, "10.0.0.1", 8);
+	__connman_ippool_newaddr(46, "172.16.0.1", 11);
+
+	while (TRUE) {
+		pool = __connman_ippool_create(23, 1, 100, NULL, NULL);
+		if (!pool)
+			break;
+		i += 1;
+
+		list = g_slist_prepend(list, pool);
+
+		gateway = __connman_ippool_get_gateway(pool);
+		broadcast = __connman_ippool_get_broadcast(pool);
+		subnet_mask = __connman_ippool_get_subnet_mask(pool);
+		start_ip = __connman_ippool_get_start_ip(pool);
+		end_ip = __connman_ippool_get_end_ip(pool);
+
+		g_assert(gateway);
+		g_assert(broadcast);
+		g_assert(subnet_mask);
+		g_assert(start_ip);
+		g_assert(end_ip);
+	}
+
+	g_assert(i == 255);
+
+	LOG("Number of blocks %d", i);
+
+	for (it = list; it; it = it->next) {
+		pool = it->data;
+
+		__connman_ippool_unref(pool);
+	}
+
+	g_slist_free(list);
+
+	__connman_ippool_cleanup();
+}
+
+static void collision_cb(struct connman_ippool *pool, void *user_data)
+{
+	int *flag = user_data;
+
+	LOG("collision detected");
+
+	g_assert(*flag == 0);
+	g_assert(pool);
+
+	*flag = 1;
+}
+
+static void test_case_4(void)
+{
+	struct connman_ippool *pool;
+	const char *gateway;
+	const char *broadcast;
+	const char *subnet_mask;
+	const char *start_ip;
+	const char *end_ip;
+	int flag;
+
+	__connman_ippool_init();
+
+	/* Test the IP range collision */
+
+	flag = 0;
+	pool = __connman_ippool_create(23, 1, 100, collision_cb, &flag);
+	g_assert(pool);
+
+	gateway = __connman_ippool_get_gateway(pool);
+	broadcast = __connman_ippool_get_broadcast(pool);
+	subnet_mask = __connman_ippool_get_subnet_mask(pool);
+	start_ip = __connman_ippool_get_start_ip(pool);
+	end_ip = __connman_ippool_get_end_ip(pool);
+
+	g_assert(gateway);
+	g_assert(broadcast);
+	g_assert(subnet_mask);
+	g_assert(start_ip);
+	g_assert(end_ip);
+
+	LOG("\n\tIP range %s --> %s\n"
+		"\tgateway %s broadcast %s mask %s", start_ip, end_ip,
+		gateway, broadcast, subnet_mask);
+
+	__connman_ippool_newaddr(23, start_ip, 24);
+
+	g_assert(flag == 0);
+
+	__connman_ippool_newaddr(42, start_ip, 16);
+
+	g_assert(flag == 1);
+
+	__connman_ippool_unref(pool);
+
+	flag = 0;
+
+	pool = __connman_ippool_create(23, 1, 100, collision_cb, &flag);
+	g_assert(pool);
+
+	gateway = __connman_ippool_get_gateway(pool);
+	broadcast = __connman_ippool_get_broadcast(pool);
+	subnet_mask = __connman_ippool_get_subnet_mask(pool);
+	start_ip = __connman_ippool_get_start_ip(pool);
+	end_ip = __connman_ippool_get_end_ip(pool);
+
+	g_assert(gateway);
+	g_assert(broadcast);
+	g_assert(subnet_mask);
+	g_assert(start_ip);
+	g_assert(end_ip);
+
+	LOG("\n\tIP range %s --> %s\n"
+		"\tgateway %s broadcast %s mask %s", start_ip, end_ip,
+		gateway, broadcast, subnet_mask);
+
+	__connman_ippool_newaddr(45, start_ip, 22);
+
+	g_assert(flag == 1);
+
+	__connman_ippool_unref(pool);
+
+	__connman_ippool_cleanup();
+}
+
+static void test_case_5(void)
+{
+	struct connman_ippool *pool;
+	const char *gateway;
+	const char *broadcast;
+	const char *subnet_mask;
+	const char *start_ip;
+	const char *end_ip;
+	int flag;
+
+	__connman_ippool_init();
+
+	/* Test the IP range collision */
+
+	flag = 0;
+	start_ip = "192.168.1.2";
+	__connman_ippool_newaddr(25, start_ip, 24);
+	g_assert(flag == 0);
+
+	/* pool should return 192.168.0.1 now */
+	pool = __connman_ippool_create(26, 1, 100, collision_cb, &flag);
+	g_assert(pool);
+
+	gateway = __connman_ippool_get_gateway(pool);
+	broadcast = __connman_ippool_get_broadcast(pool);
+	subnet_mask = __connman_ippool_get_subnet_mask(pool);
+	start_ip = __connman_ippool_get_start_ip(pool);
+	end_ip = __connman_ippool_get_end_ip(pool);
+
+	g_assert(gateway);
+	g_assert(broadcast);
+	g_assert(subnet_mask);
+	g_assert(start_ip);
+	g_assert(end_ip);
+
+	g_assert_cmpstr(gateway, ==, "192.168.0.1");
+	g_assert_cmpstr(broadcast, ==, "192.168.0.255");
+	g_assert_cmpstr(subnet_mask, ==, "255.255.255.0");
+	g_assert_cmpstr(start_ip, ==, "192.168.0.1");
+	g_assert_cmpstr(end_ip, ==, "192.168.0.101");
+
+	LOG("\n\tIP range %s --> %s\n"
+		"\tgateway %s broadcast %s mask %s", start_ip, end_ip,
+		gateway, broadcast, subnet_mask);
+
+	__connman_ippool_unref(pool);
+
+	/*
+	 * Now create the pool again, we should not get collision
+	 * with existing allocated address.
+	 */
+
+	/* pool should return 192.168.2.1 now */
+	flag = 0;
+	pool = __connman_ippool_create(23, 1, 100, collision_cb, &flag);
+	g_assert(pool);
+
+	gateway = __connman_ippool_get_gateway(pool);
+	broadcast = __connman_ippool_get_broadcast(pool);
+	subnet_mask = __connman_ippool_get_subnet_mask(pool);
+	start_ip = __connman_ippool_get_start_ip(pool);
+	end_ip = __connman_ippool_get_end_ip(pool);
+
+	g_assert(gateway);
+	g_assert(broadcast);
+	g_assert(subnet_mask);
+	g_assert(start_ip);
+	g_assert(end_ip);
+
+	g_assert_cmpstr(gateway, ==, "192.168.2.1");
+	g_assert_cmpstr(broadcast, ==, "192.168.2.255");
+	g_assert_cmpstr(subnet_mask, ==, "255.255.255.0");
+	g_assert_cmpstr(start_ip, ==, "192.168.2.1");
+	g_assert_cmpstr(end_ip, ==, "192.168.2.101");
+
+	LOG("\n\tIP range %s --> %s\n"
+		"\tgateway %s broadcast %s mask %s", start_ip, end_ip,
+		gateway, broadcast, subnet_mask);
+
+	g_assert(flag == 0);
+
+	__connman_ippool_unref(pool);
+
+	__connman_ippool_cleanup();
+}
+
+static void test_case_6(void)
+{
+	struct connman_ippool *pool;
+	const char *gateway;
+	const char *broadcast;
+	const char *subnet_mask;
+	const char *start_ip;
+	const char *end_ip;
+	int flag;
+
+	__connman_ippool_init();
+
+	/* Test the IP range collision */
+
+	flag = 0;
+	start_ip = "192.168.1.2";
+	__connman_ippool_newaddr(25, start_ip, 24);
+	g_assert(flag == 0);
+
+	flag = 0;
+	start_ip = "192.168.0.2";
+	__connman_ippool_newaddr(25, start_ip, 24);
+	g_assert(flag == 0);
+
+	/* pool should return 192.168.2.1 now */
+	pool = __connman_ippool_create(26, 1, 100, collision_cb, &flag);
+	g_assert(pool);
+
+	gateway = __connman_ippool_get_gateway(pool);
+	broadcast = __connman_ippool_get_broadcast(pool);
+	subnet_mask = __connman_ippool_get_subnet_mask(pool);
+	start_ip = __connman_ippool_get_start_ip(pool);
+	end_ip = __connman_ippool_get_end_ip(pool);
+
+	g_assert(gateway);
+	g_assert(broadcast);
+	g_assert(subnet_mask);
+	g_assert(start_ip);
+	g_assert(end_ip);
+
+	g_assert_cmpstr(gateway, ==, "192.168.2.1");
+	g_assert_cmpstr(broadcast, ==, "192.168.2.255");
+	g_assert_cmpstr(subnet_mask, ==, "255.255.255.0");
+	g_assert_cmpstr(start_ip, ==, "192.168.2.1");
+	g_assert_cmpstr(end_ip, ==, "192.168.2.101");
+
+	LOG("\n\tIP range %s --> %s\n"
+		"\tgateway %s broadcast %s mask %s", start_ip, end_ip,
+		gateway, broadcast, subnet_mask);
+
+	__connman_ippool_unref(pool);
+
+	/*
+	 * Now create the pool again, we should not get collision
+	 * with existing allocated address.
+	 */
+
+	/* pool should return 192.168.3.1 now */
+	flag = 0;
+	pool = __connman_ippool_create(23, 1, 100, collision_cb, &flag);
+	g_assert(pool);
+
+	gateway = __connman_ippool_get_gateway(pool);
+	broadcast = __connman_ippool_get_broadcast(pool);
+	subnet_mask = __connman_ippool_get_subnet_mask(pool);
+	start_ip = __connman_ippool_get_start_ip(pool);
+	end_ip = __connman_ippool_get_end_ip(pool);
+
+	g_assert(gateway);
+	g_assert(broadcast);
+	g_assert(subnet_mask);
+	g_assert(start_ip);
+	g_assert(end_ip);
+
+	g_assert_cmpstr(gateway, ==, "192.168.3.1");
+	g_assert_cmpstr(broadcast, ==, "192.168.3.255");
+	g_assert_cmpstr(subnet_mask, ==, "255.255.255.0");
+	g_assert_cmpstr(start_ip, ==, "192.168.3.1");
+	g_assert_cmpstr(end_ip, ==, "192.168.3.101");
+
+	LOG("\n\tIP range %s --> %s\n"
+		"\tgateway %s broadcast %s mask %s", start_ip, end_ip,
+		gateway, broadcast, subnet_mask);
+
+	g_assert(flag == 0);
+
+	flag = 0;
+	start_ip = "192.168.3.2";
+	__connman_ippool_newaddr(25, start_ip, 24);
+	g_assert(flag == 1);
+
+	__connman_ippool_unref(pool);
+
+	__connman_ippool_cleanup();
+}
+
+int main(int argc, char *argv[])
+{
+	g_test_init(&argc, &argv, NULL);
+
+	g_test_add_func("/ippool/Test case 1", test_case_1);
+	g_test_add_func("/ippool/Test case 2", test_case_2);
+	g_test_add_func("/ippool/Test case 3", test_case_3);
+	g_test_add_func("/ippool/Test case 4", test_case_4);
+	g_test_add_func("/ippool/Test case 5", test_case_5);
+	g_test_add_func("/ippool/Test case 6", test_case_6);
+
+	return g_test_run();
+}
diff --git a/connman/vpn/connman-task.te b/connman/vpn/connman-task.te
new file mode 100644
index 0000000..dd77710
--- /dev/null
+++ b/connman/vpn/connman-task.te
@@ -0,0 +1,16 @@
+# SElinux policy file for allowing various vpn clients
+# to access net.connman.Task dbus interface
+
+module connman-task 1.0;
+
+require {
+	type openvpn_t;
+	type openconnect_t;
+	type vpnc_t;
+	type initrc_t;
+	class dbus send_msg;
+}
+
+allow openvpn_t initrc_t:dbus send_msg;
+allow openconnect_t initrc_t:dbus send_msg;
+allow vpnc_t initrc_t:dbus send_msg;
diff --git a/connman/vpn/connman-vpn.conf b/connman/vpn/connman-vpn.conf
new file mode 100644
index 0000000..99a96ce
--- /dev/null
+++ b/connman/vpn/connman-vpn.conf
@@ -0,0 +1,8 @@
+[General]
+
+# Set input request timeout. Default is 300 seconds
+# The request for inputs like passphrase will timeout
+# after certain amount of time. Use this setting to
+# increase the value in case of different user
+# interface designs.
+# InputRequestTimeout = 300
diff --git a/connman/vpn/connman-vpn.service.in b/connman/vpn/connman-vpn.service.in
new file mode 100644
index 0000000..de65a70
--- /dev/null
+++ b/connman/vpn/connman-vpn.service.in
@@ -0,0 +1,13 @@
+[Unit]
+Description=ConnMan VPN service
+Requires=dbus.socket
+After=dbus.socket
+
+[Service]
+Type=dbus
+BusName=net.connman.vpn
+ExecStart=@sbindir@/connman-vpnd -n
+StandardOutput=null
+
+[Install]
+WantedBy=multi-user.target
diff --git a/connman/vpn/main.c b/connman/vpn/main.c
new file mode 100644
index 0000000..ee88aac
--- /dev/null
+++ b/connman/vpn/main.c
@@ -0,0 +1,359 @@
+/*
+ *
+ *  ConnMan VPN daemon
+ *
+ *  Copyright (C) 2012-2013  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 <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <signal.h>
+#include <sys/signalfd.h>
+#include <getopt.h>
+#include <sys/stat.h>
+#include <net/if.h>
+#include <netdb.h>
+
+#include <gdbus.h>
+
+#include "../src/connman.h"
+#include "vpn.h"
+
+#include "connman/vpn-dbus.h"
+
+#define CONFIGMAINFILE CONFIGDIR "/connman-vpn.conf"
+
+#define DEFAULT_INPUT_REQUEST_TIMEOUT 300 * 1000
+
+static GMainLoop *main_loop = NULL;
+
+static unsigned int __terminated = 0;
+
+static struct {
+	unsigned int timeout_inputreq;
+} connman_vpn_settings  = {
+	.timeout_inputreq = DEFAULT_INPUT_REQUEST_TIMEOUT,
+};
+
+static GKeyFile *load_config(const char *file)
+{
+	GError *err = NULL;
+	GKeyFile *keyfile;
+
+	keyfile = g_key_file_new();
+
+	g_key_file_set_list_separator(keyfile, ',');
+
+	if (!g_key_file_load_from_file(keyfile, file, 0, &err)) {
+		if (err->code != G_FILE_ERROR_NOENT) {
+			connman_error("Parsing %s failed: %s", file,
+								err->message);
+		}
+
+		g_error_free(err);
+		g_key_file_free(keyfile);
+		return NULL;
+	}
+
+	return keyfile;
+}
+
+static void parse_config(GKeyFile *config, const char *file)
+{
+	GError *error = NULL;
+	int timeout;
+
+	if (!config)
+		return;
+
+	DBG("parsing %s", file);
+
+	timeout = g_key_file_get_integer(config, "General",
+			"InputRequestTimeout", &error);
+	if (!error && timeout >= 0)
+		connman_vpn_settings.timeout_inputreq = timeout * 1000;
+
+	g_clear_error(&error);
+}
+
+static int config_init(const char *file)
+{
+	GKeyFile *config;
+
+	config = load_config(file);
+	parse_config(config, file);
+	if (config)
+		g_key_file_free(config);
+
+	return 0;
+}
+
+static gboolean signal_handler(GIOChannel *channel, GIOCondition cond,
+							gpointer user_data)
+{
+	struct signalfd_siginfo si;
+	ssize_t result;
+	int fd;
+
+	if (cond & (G_IO_NVAL | G_IO_ERR | G_IO_HUP))
+		return FALSE;
+
+	fd = g_io_channel_unix_get_fd(channel);
+
+	result = read(fd, &si, sizeof(si));
+	if (result != sizeof(si))
+		return FALSE;
+
+	switch (si.ssi_signo) {
+	case SIGINT:
+	case SIGTERM:
+		if (__terminated == 0) {
+			connman_info("Terminating");
+			g_main_loop_quit(main_loop);
+		}
+
+		__terminated = 1;
+		break;
+	}
+
+	return TRUE;
+}
+
+static guint setup_signalfd(void)
+{
+	GIOChannel *channel;
+	guint source;
+	sigset_t mask;
+	int fd;
+
+	sigemptyset(&mask);
+	sigaddset(&mask, SIGINT);
+	sigaddset(&mask, SIGTERM);
+
+	if (sigprocmask(SIG_BLOCK, &mask, NULL) < 0) {
+		perror("Failed to set signal mask");
+		return 0;
+	}
+
+	fd = signalfd(-1, &mask, 0);
+	if (fd < 0) {
+		perror("Failed to create signal descriptor");
+		return 0;
+	}
+
+	channel = g_io_channel_unix_new(fd);
+
+	g_io_channel_set_close_on_unref(channel, TRUE);
+	g_io_channel_set_encoding(channel, NULL, NULL);
+	g_io_channel_set_buffered(channel, FALSE);
+
+	source = g_io_add_watch(channel,
+				G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
+				signal_handler, NULL);
+
+	g_io_channel_unref(channel);
+
+	return source;
+}
+
+static void disconnect_callback(DBusConnection *conn, void *user_data)
+{
+	connman_error("D-Bus disconnect");
+
+	g_main_loop_quit(main_loop);
+}
+
+static gchar *option_config = NULL;
+static gchar *option_debug = NULL;
+static gchar *option_plugin = NULL;
+static gchar *option_noplugin = NULL;
+static bool option_detach = true;
+static bool option_version = false;
+static bool option_routes = false;
+
+static bool parse_debug(const char *key, const char *value,
+					gpointer user_data, GError **error)
+{
+	if (value)
+		option_debug = g_strdup(value);
+	else
+		option_debug = g_strdup("*");
+
+	return true;
+}
+
+static GOptionEntry options[] = {
+	{ "config", 'c', 0, G_OPTION_ARG_STRING, &option_config,
+				"Load the specified configuration file "
+				"instead of " CONFIGMAINFILE, "FILE" },
+	{ "debug", 'd', G_OPTION_FLAG_OPTIONAL_ARG,
+				G_OPTION_ARG_CALLBACK, parse_debug,
+				"Specify debug options to enable", "DEBUG" },
+	{ "plugin", 'p', 0, G_OPTION_ARG_STRING, &option_plugin,
+				"Specify plugins to load", "NAME,..." },
+	{ "noplugin", 'P', 0, G_OPTION_ARG_STRING, &option_noplugin,
+				"Specify plugins not to load", "NAME,..." },
+	{ "nodaemon", 'n', G_OPTION_FLAG_REVERSE,
+				G_OPTION_ARG_NONE, &option_detach,
+				"Don't fork daemon to background" },
+	{ "routes", 'r', 0, G_OPTION_ARG_NONE, &option_routes,
+				"Create/delete VPN routes" },
+	{ "version", 'v', 0, G_OPTION_ARG_NONE, &option_version,
+				"Show version information and exit" },
+	{ NULL },
+};
+
+/*
+ * This function will be called from generic src/agent.c code so we have
+ * to use connman_ prefix instead of vpn_ one.
+ */
+unsigned int connman_timeout_input_request(void)
+{
+	return connman_vpn_settings.timeout_inputreq;
+}
+
+int main(int argc, char *argv[])
+{
+	GOptionContext *context;
+	GError *error = NULL;
+	DBusConnection *conn;
+	DBusError err;
+	guint signal;
+
+	context = g_option_context_new(NULL);
+	g_option_context_add_main_entries(context, options, NULL);
+
+	if (!g_option_context_parse(context, &argc, &argv, &error)) {
+		if (error) {
+			g_printerr("%s\n", error->message);
+			g_error_free(error);
+		} else
+			g_printerr("An unknown error occurred\n");
+		exit(1);
+	}
+
+	g_option_context_free(context);
+
+	if (option_version) {
+		printf("%s\n", VERSION);
+		exit(0);
+	}
+
+	if (option_detach) {
+		if (daemon(0, 0)) {
+			perror("Can't start daemon");
+			exit(1);
+		}
+	}
+
+	if (mkdir(VPN_STATEDIR, S_IRUSR | S_IWUSR | S_IXUSR |
+				S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) < 0) {
+		if (errno != EEXIST)
+			perror("Failed to create state directory");
+	}
+
+	/*
+	 * At some point the VPN stuff is migrated into VPN_STORAGEDIR
+	 * and this mkdir() call can be removed.
+	 */
+	if (mkdir(STORAGEDIR, S_IRUSR | S_IWUSR | S_IXUSR |
+				S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) < 0) {
+		if (errno != EEXIST)
+			perror("Failed to create storage directory");
+	}
+
+	if (mkdir(VPN_STORAGEDIR, S_IRUSR | S_IWUSR | S_IXUSR |
+				S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) < 0) {
+		if (errno != EEXIST)
+			perror("Failed to create VPN storage directory");
+	}
+
+	umask(0077);
+
+	main_loop = g_main_loop_new(NULL, FALSE);
+
+	signal = setup_signalfd();
+
+	dbus_error_init(&err);
+
+	conn = g_dbus_setup_bus(DBUS_BUS_SYSTEM, VPN_SERVICE, &err);
+	if (!conn) {
+		if (dbus_error_is_set(&err)) {
+			fprintf(stderr, "%s\n", err.message);
+			dbus_error_free(&err);
+		} else
+			fprintf(stderr, "Can't register with system bus\n");
+		exit(1);
+	}
+
+	g_dbus_set_disconnect_function(conn, disconnect_callback, NULL, NULL);
+
+	__connman_log_init(argv[0], option_debug, option_detach, false,
+			"Connection Manager VPN daemon", VERSION);
+	__connman_dbus_init(conn);
+
+	if (!option_config)
+		config_init(CONFIGMAINFILE);
+	else
+		config_init(option_config);
+
+	__connman_inotify_init();
+	__connman_agent_init();
+	__vpn_provider_init(option_routes);
+	__vpn_manager_init();
+	__vpn_ipconfig_init();
+	__vpn_rtnl_init();
+	__connman_task_init();
+	__connman_plugin_init(option_plugin, option_noplugin);
+	__vpn_config_init();
+
+	__vpn_rtnl_start();
+
+	g_free(option_plugin);
+	g_free(option_noplugin);
+
+	g_main_loop_run(main_loop);
+
+	g_source_remove(signal);
+
+	__vpn_config_cleanup();
+	__connman_plugin_cleanup();
+	__connman_task_cleanup();
+	__vpn_rtnl_cleanup();
+	__vpn_ipconfig_cleanup();
+	__vpn_manager_cleanup();
+	__vpn_provider_cleanup();
+	__connman_agent_cleanup();
+	__connman_inotify_cleanup();
+	__connman_dbus_cleanup();
+	__connman_log_cleanup(false);
+
+	dbus_connection_unref(conn);
+
+	g_main_loop_unref(main_loop);
+
+	g_free(option_debug);
+
+	return 0;
+}
diff --git a/connman/vpn/net.connman.vpn.service.in b/connman/vpn/net.connman.vpn.service.in
new file mode 100644
index 0000000..e473ea9
--- /dev/null
+++ b/connman/vpn/net.connman.vpn.service.in
@@ -0,0 +1,5 @@
+[D-BUS Service]
+Name=net.connman.vpn
+Exec=@sbindir@/connman-vpnd -n
+User=root
+SystemdService=connman-vpn.service
diff --git a/connman/vpn/plugins/l2tp.c b/connman/vpn/plugins/l2tp.c
new file mode 100644
index 0000000..22f9dcf
--- /dev/null
+++ b/connman/vpn/plugins/l2tp.c
@@ -0,0 +1,811 @@
+/*
+ *
+ *  ConnMan VPN daemon
+ *
+ *  Copyright (C) 2010,2013  BMW Car IT GmbH.
+ *  Copyright (C) 2012-2013  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 <errno.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#include <stdio.h>
+#include <net/if.h>
+
+#include <dbus/dbus.h>
+#include <glib.h>
+
+#define CONNMAN_API_SUBJECT_TO_CHANGE
+#include <connman/plugin.h>
+#include <connman/provider.h>
+#include <connman/log.h>
+#include <connman/task.h>
+#include <connman/dbus.h>
+#include <connman/inet.h>
+#include <connman/agent.h>
+#include <connman/setting.h>
+#include <connman/vpn-dbus.h>
+
+#include "../vpn-provider.h"
+#include "../vpn-agent.h"
+
+#include "vpn.h"
+
+#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
+
+enum {
+	OPT_STRING = 1,
+	OPT_BOOL = 2,
+};
+
+enum {
+	OPT_ALL = 1,
+	OPT_L2G = 2,
+	OPT_L2	= 3,
+	OPT_PPPD = 4,
+};
+
+struct {
+	const char *cm_opt;
+	const char *pppd_opt;
+	int sub;
+	const char *vpn_default;
+	int type;
+} pppd_options[] = {
+	{ "L2TP.User", "name", OPT_ALL, NULL, OPT_STRING },
+	{ "L2TP.BPS", "bps", OPT_L2, NULL, OPT_STRING },
+	{ "L2TP.TXBPS", "tx bps", OPT_L2, NULL, OPT_STRING },
+	{ "L2TP.RXBPS", "rx bps", OPT_L2, NULL, OPT_STRING },
+	{ "L2TP.LengthBit", "length bit", OPT_L2, NULL, OPT_STRING },
+	{ "L2TP.Challenge", "challenge", OPT_L2, NULL, OPT_STRING },
+	{ "L2TP.DefaultRoute", "defaultroute", OPT_L2, NULL, OPT_STRING },
+	{ "L2TP.FlowBit", "flow bit", OPT_L2, NULL, OPT_STRING },
+	{ "L2TP.TunnelRWS", "tunnel rws", OPT_L2, NULL, OPT_STRING },
+	{ "L2TP.Exclusive", "exclusive", OPT_L2, NULL, OPT_STRING },
+	{ "L2TP.Autodial", "autodial", OPT_L2, "yes", OPT_STRING },
+	{ "L2TP.Redial", "redial", OPT_L2, "yes", OPT_STRING },
+	{ "L2TP.RedialTimeout", "redial timeout", OPT_L2, "10", OPT_STRING },
+	{ "L2TP.MaxRedials", "max redials", OPT_L2, NULL, OPT_STRING },
+	{ "L2TP.RequirePAP", "require pap", OPT_L2, "no", OPT_STRING },
+	{ "L2TP.RequireCHAP", "require chap", OPT_L2, "yes", OPT_STRING },
+	{ "L2TP.ReqAuth", "require authentication", OPT_L2, "no", OPT_STRING },
+	{ "L2TP.AccessControl", "access control", OPT_L2G, "yes", OPT_STRING },
+	{ "L2TP.AuthFile", "auth file", OPT_L2G, NULL, OPT_STRING },
+	{ "L2TP.ForceUserSpace", "force userspace", OPT_L2G, NULL, OPT_STRING },
+	{ "L2TP.ListenAddr", "listen-addr", OPT_L2G, NULL, OPT_STRING },
+	{ "L2TP.Rand Source", "rand source", OPT_L2G, NULL, OPT_STRING },
+	{ "L2TP.IPsecSaref", "ipsec saref", OPT_L2G, NULL, OPT_STRING },
+	{ "L2TP.Port", "port", OPT_L2G, NULL, OPT_STRING },
+	{ "PPPD.EchoFailure", "lcp-echo-failure", OPT_PPPD, "0", OPT_STRING },
+	{ "PPPD.EchoInterval", "lcp-echo-interval", OPT_PPPD, "0", OPT_STRING },
+	{ "PPPD.Debug", "debug", OPT_PPPD, NULL, OPT_STRING },
+	{ "PPPD.RefuseEAP", "refuse-eap", OPT_PPPD, NULL, OPT_BOOL },
+	{ "PPPD.RefusePAP", "refuse-pap", OPT_PPPD, NULL, OPT_BOOL },
+	{ "PPPD.RefuseCHAP", "refuse-chap", OPT_PPPD, NULL, OPT_BOOL },
+	{ "PPPD.RefuseMSCHAP", "refuse-mschap", OPT_PPPD, NULL, OPT_BOOL },
+	{ "PPPD.RefuseMSCHAP2", "refuse-mschapv2", OPT_PPPD, NULL, OPT_BOOL },
+	{ "PPPD.NoBSDComp", "nobsdcomp", OPT_PPPD, NULL, OPT_BOOL },
+	{ "PPPD.NoPcomp", "nopcomp", OPT_PPPD, NULL, OPT_BOOL },
+	{ "PPPD.UseAccomp", "accomp", OPT_PPPD, NULL, OPT_BOOL },
+	{ "PPPD.NoDeflate", "nodeflate", OPT_PPPD, NULL, OPT_BOOL },
+	{ "PPPD.ReqMPPE", "require-mppe", OPT_PPPD, NULL, OPT_BOOL },
+	{ "PPPD.ReqMPPE40", "require-mppe-40", OPT_PPPD, NULL, OPT_BOOL },
+	{ "PPPD.ReqMPPE128", "require-mppe-128", OPT_PPPD, NULL, OPT_BOOL },
+	{ "PPPD.ReqMPPEStateful", "mppe-stateful", OPT_PPPD, NULL, OPT_BOOL },
+	{ "PPPD.NoVJ", "no-vj-comp", OPT_PPPD, NULL, OPT_BOOL },
+};
+
+static DBusConnection *connection;
+
+struct l2tp_private_data {
+	struct connman_task *task;
+	char *if_name;
+	vpn_provider_connect_cb_t cb;
+	void *user_data;
+};
+
+static DBusMessage *l2tp_get_sec(struct connman_task *task,
+			DBusMessage *msg, void *user_data)
+{
+	const char *user, *passwd;
+	struct vpn_provider *provider = user_data;
+
+	if (!dbus_message_get_no_reply(msg)) {
+		DBusMessage *reply;
+
+		user = vpn_provider_get_string(provider, "L2TP.User");
+		passwd = vpn_provider_get_string(provider, "L2TP.Password");
+
+		if (!user || strlen(user) == 0 ||
+				!passwd || strlen(passwd) == 0)
+			return NULL;
+
+		reply = dbus_message_new_method_return(msg);
+		if (!reply)
+			return NULL;
+
+		dbus_message_append_args(reply, DBUS_TYPE_STRING, &user,
+						DBUS_TYPE_STRING, &passwd,
+						DBUS_TYPE_INVALID);
+
+		return reply;
+	}
+
+	return NULL;
+}
+
+static int l2tp_notify(DBusMessage *msg, struct vpn_provider *provider)
+{
+	DBusMessageIter iter, dict;
+	const char *reason, *key, *value;
+	char *addressv4 = NULL, *netmask = NULL, *gateway = NULL;
+	char *ifname = NULL, *nameservers = NULL;
+	struct connman_ipaddress *ipaddress = NULL;
+
+	dbus_message_iter_init(msg, &iter);
+
+	dbus_message_iter_get_basic(&iter, &reason);
+	dbus_message_iter_next(&iter);
+
+	if (!provider) {
+		connman_error("No provider found");
+		return VPN_STATE_FAILURE;
+	}
+
+	if (strcmp(reason, "auth failed") == 0) {
+		DBG("authentication failure");
+
+		vpn_provider_set_string(provider, "L2TP.User", NULL);
+		vpn_provider_set_string(provider, "L2TP.Password", NULL);
+
+		return VPN_STATE_AUTH_FAILURE;
+	}
+
+	if (strcmp(reason, "connect"))
+		return VPN_STATE_DISCONNECT;
+
+	dbus_message_iter_recurse(&iter, &dict);
+
+	while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
+		DBusMessageIter entry;
+
+		dbus_message_iter_recurse(&dict, &entry);
+		dbus_message_iter_get_basic(&entry, &key);
+		dbus_message_iter_next(&entry);
+		dbus_message_iter_get_basic(&entry, &value);
+
+		DBG("%s = %s", key, value);
+
+		if (!strcmp(key, "INTERNAL_IP4_ADDRESS"))
+			addressv4 = g_strdup(value);
+
+		if (!strcmp(key, "INTERNAL_IP4_NETMASK"))
+			netmask = g_strdup(value);
+
+		if (!strcmp(key, "INTERNAL_IP4_DNS"))
+			nameservers = g_strdup(value);
+
+		if (!strcmp(key, "INTERNAL_IFNAME"))
+			ifname = g_strdup(value);
+
+		dbus_message_iter_next(&dict);
+	}
+
+	if (vpn_set_ifname(provider, ifname) < 0) {
+		g_free(ifname);
+		g_free(addressv4);
+		g_free(netmask);
+		g_free(nameservers);
+		return VPN_STATE_FAILURE;
+	}
+
+	if (addressv4)
+		ipaddress = connman_ipaddress_alloc(AF_INET);
+
+	g_free(ifname);
+
+	if (!ipaddress) {
+		connman_error("No IP address for provider");
+		g_free(addressv4);
+		g_free(netmask);
+		g_free(nameservers);
+		return VPN_STATE_FAILURE;
+	}
+
+	value = vpn_provider_get_string(provider, "HostIP");
+	if (value) {
+		vpn_provider_set_string(provider, "Gateway", value);
+		gateway = g_strdup(value);
+	}
+
+	if (addressv4)
+		connman_ipaddress_set_ipv4(ipaddress, addressv4, netmask,
+					gateway);
+
+	vpn_provider_set_ipaddress(provider, ipaddress);
+	vpn_provider_set_nameservers(provider, nameservers);
+
+	g_free(addressv4);
+	g_free(netmask);
+	g_free(gateway);
+	g_free(nameservers);
+	connman_ipaddress_free(ipaddress);
+
+	return VPN_STATE_CONNECT;
+}
+
+static int l2tp_save(struct vpn_provider *provider, GKeyFile *keyfile)
+{
+	const char *option;
+	bool l2tp_option, pppd_option;
+	int i;
+
+	for (i = 0; i < (int)ARRAY_SIZE(pppd_options); i++) {
+		l2tp_option = pppd_option = false;
+
+		if (strncmp(pppd_options[i].cm_opt, "L2TP.", 5) == 0)
+			l2tp_option = true;
+
+		if (strncmp(pppd_options[i].cm_opt, "PPPD.", 5) == 0)
+			pppd_option = true;
+
+		if (l2tp_option || pppd_option) {
+			option = vpn_provider_get_string(provider,
+						pppd_options[i].cm_opt);
+			if (!option) {
+				/*
+				 * Check if the option prefix is L2TP as the
+				 * PPPD options were using L2TP prefix earlier.
+				 */
+				char *l2tp_str;
+
+				if (!pppd_option)
+					continue;
+
+				l2tp_str = g_strdup_printf("L2TP.%s",
+						&pppd_options[i].cm_opt[5]);
+				option = vpn_provider_get_string(provider,
+								l2tp_str);
+				g_free(l2tp_str);
+
+				if (!option)
+					continue;
+			}
+
+			g_key_file_set_string(keyfile,
+					vpn_provider_get_save_group(provider),
+					pppd_options[i].cm_opt, option);
+		}
+	}
+
+	return 0;
+}
+
+static ssize_t full_write(int fd, const void *buf, size_t len)
+{
+	ssize_t byte_write;
+
+	while (len) {
+		byte_write = write(fd, buf, len);
+		if (byte_write < 0) {
+			connman_error("failed to write config to l2tp: %s\n",
+					strerror(errno));
+			return byte_write;
+		}
+		len -= byte_write;
+		buf += byte_write;
+	}
+
+	return 0;
+}
+
+static ssize_t l2tp_write_bool_option(int fd,
+					const char *key, const char *value)
+{
+	gchar *buf;
+	ssize_t ret = 0;
+
+	if (key && value) {
+		if (strcasecmp(value, "yes") == 0 ||
+				strcasecmp(value, "true") == 0 ||
+				strcmp(value, "1") == 0) {
+			buf = g_strdup_printf("%s\n", key);
+			ret = full_write(fd, buf, strlen(buf));
+
+			g_free(buf);
+		}
+	}
+
+	return ret;
+}
+
+static int l2tp_write_option(int fd, const char *key, const char *value)
+{
+	gchar *buf;
+	ssize_t ret = 0;
+
+	if (key) {
+		if (value)
+			buf = g_strdup_printf("%s %s\n", key, value);
+		else
+			buf = g_strdup_printf("%s\n", key);
+
+		ret = full_write(fd, buf, strlen(buf));
+
+		g_free(buf);
+	}
+
+	return ret;
+}
+
+static int l2tp_write_section(int fd, const char *key, const char *value)
+{
+	gchar *buf;
+	ssize_t ret = 0;
+
+	if (key && value) {
+		buf = g_strdup_printf("%s = %s\n", key, value);
+		ret = full_write(fd, buf, strlen(buf));
+
+		g_free(buf);
+	}
+
+	return ret;
+}
+
+static int write_pppd_option(struct vpn_provider *provider, int fd)
+{
+	int i;
+	const char *opt_s;
+
+	l2tp_write_option(fd, "nodetach", NULL);
+	l2tp_write_option(fd, "lock", NULL);
+	l2tp_write_option(fd, "usepeerdns", NULL);
+	l2tp_write_option(fd, "noipdefault", NULL);
+	l2tp_write_option(fd, "noauth", NULL);
+	l2tp_write_option(fd, "nodefaultroute", NULL);
+	l2tp_write_option(fd, "ipparam", "l2tp_plugin");
+
+	for (i = 0; i < (int)ARRAY_SIZE(pppd_options); i++) {
+		if (pppd_options[i].sub != OPT_ALL &&
+			pppd_options[i].sub != OPT_PPPD)
+			continue;
+
+		opt_s = vpn_provider_get_string(provider,
+					pppd_options[i].cm_opt);
+		if (!opt_s)
+			opt_s = pppd_options[i].vpn_default;
+
+		if (!opt_s)
+			continue;
+
+		if (pppd_options[i].type == OPT_STRING)
+			l2tp_write_option(fd,
+				pppd_options[i].pppd_opt, opt_s);
+		else if (pppd_options[i].type == OPT_BOOL)
+			l2tp_write_bool_option(fd,
+				pppd_options[i].pppd_opt, opt_s);
+	}
+
+	l2tp_write_option(fd, "plugin",
+				SCRIPTDIR "/libppp-plugin.so");
+
+	return 0;
+}
+
+
+static int l2tp_write_fields(struct vpn_provider *provider,
+						int fd, int sub)
+{
+	int i;
+	const char *opt_s;
+
+	for (i = 0; i < (int)ARRAY_SIZE(pppd_options); i++) {
+		if (pppd_options[i].sub != sub)
+			continue;
+
+		opt_s = vpn_provider_get_string(provider,
+					pppd_options[i].cm_opt);
+		if (!opt_s)
+			opt_s = pppd_options[i].vpn_default;
+
+		if (!opt_s)
+			continue;
+
+		if (pppd_options[i].type == OPT_STRING)
+			l2tp_write_section(fd,
+				pppd_options[i].pppd_opt, opt_s);
+		else if (pppd_options[i].type == OPT_BOOL)
+			l2tp_write_bool_option(fd,
+				pppd_options[i].pppd_opt, opt_s);
+	}
+
+	return 0;
+}
+
+static int l2tp_write_config(struct vpn_provider *provider,
+					const char *pppd_name, int fd)
+{
+	const char *option;
+
+	l2tp_write_option(fd, "[global]", NULL);
+	l2tp_write_fields(provider, fd, OPT_L2G);
+
+	l2tp_write_option(fd, "[lac l2tp]", NULL);
+
+	option = vpn_provider_get_string(provider, "Host");
+	l2tp_write_option(fd, "lns =", option);
+
+	l2tp_write_fields(provider, fd, OPT_ALL);
+	l2tp_write_fields(provider, fd, OPT_L2);
+
+	l2tp_write_option(fd, "pppoptfile =", pppd_name);
+
+	return 0;
+}
+
+static void l2tp_died(struct connman_task *task, int exit_code, void *user_data)
+{
+	char *conf_file;
+
+	vpn_died(task, exit_code, user_data);
+
+	conf_file = g_strdup_printf(VPN_STATEDIR "/connman-xl2tpd.conf");
+	unlink(conf_file);
+	g_free(conf_file);
+
+	conf_file = g_strdup_printf(VPN_STATEDIR "/connman-ppp-option.conf");
+	unlink(conf_file);
+	g_free(conf_file);
+}
+
+struct request_input_reply {
+	struct vpn_provider *provider;
+	vpn_provider_password_cb_t callback;
+	void *user_data;
+};
+
+static void request_input_reply(DBusMessage *reply, void *user_data)
+{
+	struct request_input_reply *l2tp_reply = user_data;
+	const char *error = NULL;
+	char *username = NULL, *password = NULL;
+	char *key;
+	DBusMessageIter iter, dict;
+
+	DBG("provider %p", l2tp_reply->provider);
+
+	if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) {
+		error = dbus_message_get_error_name(reply);
+		goto done;
+	}
+
+	if (!vpn_agent_check_reply_has_dict(reply))
+		goto done;
+
+	dbus_message_iter_init(reply, &iter);
+	dbus_message_iter_recurse(&iter, &dict);
+	while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
+		DBusMessageIter entry, value;
+		const char *str;
+
+		dbus_message_iter_recurse(&dict, &entry);
+		if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING)
+			break;
+
+		dbus_message_iter_get_basic(&entry, &key);
+
+		if (g_str_equal(key, "Username")) {
+			dbus_message_iter_next(&entry);
+			if (dbus_message_iter_get_arg_type(&entry)
+							!= DBUS_TYPE_VARIANT)
+				break;
+			dbus_message_iter_recurse(&entry, &value);
+			if (dbus_message_iter_get_arg_type(&value)
+							!= DBUS_TYPE_STRING)
+				break;
+			dbus_message_iter_get_basic(&value, &str);
+			username = g_strdup(str);
+		}
+
+		if (g_str_equal(key, "Password")) {
+			dbus_message_iter_next(&entry);
+			if (dbus_message_iter_get_arg_type(&entry)
+							!= DBUS_TYPE_VARIANT)
+				break;
+			dbus_message_iter_recurse(&entry, &value);
+			if (dbus_message_iter_get_arg_type(&value)
+							!= DBUS_TYPE_STRING)
+				break;
+			dbus_message_iter_get_basic(&value, &str);
+			password = g_strdup(str);
+		}
+
+		dbus_message_iter_next(&dict);
+	}
+
+done:
+	l2tp_reply->callback(l2tp_reply->provider, username, password, error,
+				l2tp_reply->user_data);
+
+	g_free(username);
+	g_free(password);
+
+	g_free(l2tp_reply);
+}
+
+typedef void (* request_cb_t)(struct vpn_provider *provider,
+				const char *username, const char *password,
+				const char *error, void *user_data);
+
+static int request_input(struct vpn_provider *provider,
+			request_cb_t callback, const char *dbus_sender,
+			void *user_data)
+{
+	DBusMessage *message;
+	const char *path, *agent_sender, *agent_path;
+	DBusMessageIter iter;
+	DBusMessageIter dict;
+	struct request_input_reply *l2tp_reply;
+	int err;
+	void *agent;
+
+	agent = connman_agent_get_info(dbus_sender, &agent_sender,
+							&agent_path);
+	if (!provider || !agent || !agent_path || !callback)
+		return -ESRCH;
+
+	message = dbus_message_new_method_call(agent_sender, agent_path,
+					VPN_AGENT_INTERFACE,
+					"RequestInput");
+	if (!message)
+		return -ENOMEM;
+
+	dbus_message_iter_init_append(message, &iter);
+
+	path = vpn_provider_get_path(provider);
+	dbus_message_iter_append_basic(&iter,
+				DBUS_TYPE_OBJECT_PATH, &path);
+
+	connman_dbus_dict_open(&iter, &dict);
+
+	vpn_agent_append_user_info(&dict, provider, "L2TP.User");
+
+	vpn_agent_append_host_and_name(&dict, provider);
+
+	connman_dbus_dict_close(&iter, &dict);
+
+	l2tp_reply = g_try_new0(struct request_input_reply, 1);
+	if (!l2tp_reply) {
+		dbus_message_unref(message);
+		return -ENOMEM;
+	}
+
+	l2tp_reply->provider = provider;
+	l2tp_reply->callback = callback;
+	l2tp_reply->user_data = user_data;
+
+	err = connman_agent_queue_message(provider, message,
+			connman_timeout_input_request(),
+			request_input_reply, l2tp_reply, agent);
+	if (err < 0 && err != -EBUSY) {
+		DBG("error %d sending agent request", err);
+		dbus_message_unref(message);
+		g_free(l2tp_reply);
+		return err;
+	}
+
+	dbus_message_unref(message);
+
+	return -EINPROGRESS;
+}
+
+static int run_connect(struct vpn_provider *provider,
+			struct connman_task *task, const char *if_name,
+			vpn_provider_connect_cb_t cb, void *user_data,
+			const char *username, const char *password)
+{
+	char *l2tp_name, *pppd_name;
+	int l2tp_fd, pppd_fd;
+	int err;
+
+	if (!username || !password) {
+		DBG("Cannot connect username %s password %p",
+						username, password);
+		err = -EINVAL;
+		goto done;
+	}
+
+	DBG("username %s password %p", username, password);
+
+	l2tp_name = g_strdup_printf(VPN_STATEDIR "/connman-xl2tpd.conf");
+
+	l2tp_fd = open(l2tp_name, O_RDWR|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR);
+	if (l2tp_fd < 0) {
+		g_free(l2tp_name);
+		connman_error("Error writing l2tp config");
+		err = -EIO;
+		goto done;
+	}
+
+	pppd_name = g_strdup_printf(VPN_STATEDIR "/connman-ppp-option.conf");
+
+	pppd_fd = open(pppd_name, O_RDWR|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR);
+	if (pppd_fd < 0) {
+		connman_error("Error writing pppd config");
+		g_free(l2tp_name);
+		g_free(pppd_name);
+		close(l2tp_fd);
+		err = -EIO;
+		goto done;
+	}
+
+	l2tp_write_config(provider, pppd_name, l2tp_fd);
+
+	write_pppd_option(provider, pppd_fd);
+
+	connman_task_add_argument(task, "-D", NULL);
+	connman_task_add_argument(task, "-c", l2tp_name);
+
+	g_free(l2tp_name);
+	g_free(pppd_name);
+	close(l2tp_fd);
+	close(pppd_fd);
+
+	err = connman_task_run(task, l2tp_died, provider,
+				NULL, NULL, NULL);
+	if (err < 0) {
+		connman_error("l2tp failed to start");
+		err = -EIO;
+		goto done;
+	}
+
+done:
+	if (cb)
+		cb(provider, user_data, err);
+
+	return err;
+}
+
+static void free_private_data(struct l2tp_private_data *data)
+{
+	g_free(data->if_name);
+	g_free(data);
+}
+
+static void request_input_cb(struct vpn_provider *provider,
+			const char *username,
+			const char *password,
+			const char *error, void *user_data)
+{
+	struct l2tp_private_data *data = user_data;
+
+	if (!username || !password)
+		DBG("Requesting username %s or password failed, error %s",
+			username, error);
+	else if (error)
+		DBG("error %s", error);
+
+	vpn_provider_set_string(provider, "L2TP.User", username);
+	vpn_provider_set_string_hide_value(provider, "L2TP.Password",
+								password);
+
+	run_connect(provider, data->task, data->if_name, data->cb,
+		data->user_data, username, password);
+
+	free_private_data(data);
+}
+
+static int l2tp_connect(struct vpn_provider *provider,
+			struct connman_task *task, const char *if_name,
+			vpn_provider_connect_cb_t cb, const char *dbus_sender,
+			void *user_data)
+{
+	const char *username, *password;
+	int err;
+
+	if (connman_task_set_notify(task, "getsec",
+					l2tp_get_sec, provider) != 0) {
+		err = -ENOMEM;
+		goto error;
+	}
+
+	username = vpn_provider_get_string(provider, "L2TP.User");
+	password = vpn_provider_get_string(provider, "L2TP.Password");
+
+	DBG("user %s password %p", username, password);
+
+	if (!username || !password) {
+		struct l2tp_private_data *data;
+
+		data = g_try_new0(struct l2tp_private_data, 1);
+		if (!data)
+			return -ENOMEM;
+
+		data->task = task;
+		data->if_name = g_strdup(if_name);
+		data->cb = cb;
+		data->user_data = user_data;
+
+		err = request_input(provider, request_input_cb, dbus_sender,
+									data);
+		if (err != -EINPROGRESS) {
+			free_private_data(data);
+			goto done;
+		}
+		return err;
+	}
+
+done:
+	return run_connect(provider, task, if_name, cb, user_data,
+							username, password);
+
+error:
+	if (cb)
+		cb(provider, user_data, err);
+
+	return err;
+}
+
+static int l2tp_error_code(struct vpn_provider *provider, int exit_code)
+{
+	switch (exit_code) {
+	case 1:
+		return CONNMAN_PROVIDER_ERROR_CONNECT_FAILED;
+	default:
+		return CONNMAN_PROVIDER_ERROR_UNKNOWN;
+	}
+}
+
+static void l2tp_disconnect(struct vpn_provider *provider)
+{
+	vpn_provider_set_string(provider, "L2TP.Password", NULL);
+}
+
+static struct vpn_driver vpn_driver = {
+	.flags		= VPN_FLAG_NO_TUN,
+	.notify		= l2tp_notify,
+	.connect	= l2tp_connect,
+	.error_code	= l2tp_error_code,
+	.save		= l2tp_save,
+	.disconnect	= l2tp_disconnect,
+};
+
+static int l2tp_init(void)
+{
+	connection = connman_dbus_get_connection();
+
+	return vpn_register("l2tp", &vpn_driver, L2TP);
+}
+
+static void l2tp_exit(void)
+{
+	vpn_unregister("l2tp");
+
+	dbus_connection_unref(connection);
+}
+
+CONNMAN_PLUGIN_DEFINE(l2tp, "l2tp plugin", VERSION,
+	CONNMAN_PLUGIN_PRIORITY_DEFAULT, l2tp_init, l2tp_exit)
diff --git a/connman/vpn/plugins/openconnect.c b/connman/vpn/plugins/openconnect.c
new file mode 100644
index 0000000..5feaed9
--- /dev/null
+++ b/connman/vpn/plugins/openconnect.c
@@ -0,0 +1,582 @@
+/*
+ *
+ *  ConnMan VPN daemon
+ *
+ *  Copyright (C) 2007-2013  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 <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <unistd.h>
+#include <net/if.h>
+
+#include <glib.h>
+
+#define CONNMAN_API_SUBJECT_TO_CHANGE
+#include <connman/plugin.h>
+#include <connman/log.h>
+#include <connman/task.h>
+#include <connman/ipconfig.h>
+#include <connman/dbus.h>
+#include <connman/agent.h>
+#include <connman/setting.h>
+#include <connman/vpn-dbus.h>
+
+#include "../vpn-provider.h"
+#include "../vpn-agent.h"
+
+#include "vpn.h"
+
+#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
+
+struct {
+	const char *cm_opt;
+	const char *oc_opt;
+	char       has_value;
+} oc_options[] = {
+	{ "OpenConnect.NoCertCheck", "--no-cert-check", 0 },
+};
+
+struct oc_private_data {
+	struct vpn_provider *provider;
+	struct connman_task *task;
+	char *if_name;
+	vpn_provider_connect_cb_t cb;
+	void *user_data;
+};
+
+static void free_private_data(struct oc_private_data *data)
+{
+	g_free(data->if_name);
+	g_free(data);
+}
+
+static int task_append_config_data(struct vpn_provider *provider,
+					struct connman_task *task)
+{
+	const char *option;
+	int i;
+
+	for (i = 0; i < (int)ARRAY_SIZE(oc_options); i++) {
+		if (!oc_options[i].oc_opt)
+			continue;
+
+		option = vpn_provider_get_string(provider,
+					oc_options[i].cm_opt);
+		if (!option)
+			continue;
+
+		if (connman_task_add_argument(task,
+				oc_options[i].oc_opt,
+				oc_options[i].has_value ? option : NULL) < 0)
+			return -EIO;
+	}
+
+	return 0;
+}
+
+static int oc_notify(DBusMessage *msg, struct vpn_provider *provider)
+{
+	DBusMessageIter iter, dict;
+	const char *reason, *key, *value;
+	char *domain = NULL;
+	char *addressv4 = NULL, *addressv6 = NULL;
+	char *netmask = NULL, *gateway = NULL;
+	unsigned char prefix_len = 0;
+	struct connman_ipaddress *ipaddress;
+
+	dbus_message_iter_init(msg, &iter);
+
+	dbus_message_iter_get_basic(&iter, &reason);
+	dbus_message_iter_next(&iter);
+
+	if (!provider) {
+		connman_error("No provider found");
+		return VPN_STATE_FAILURE;
+	}
+
+	if (strcmp(reason, "connect"))
+		return VPN_STATE_DISCONNECT;
+
+	domain = g_strdup(vpn_provider_get_string(provider, "VPN.Domain"));
+
+	dbus_message_iter_recurse(&iter, &dict);
+
+	while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
+		DBusMessageIter entry;
+
+		dbus_message_iter_recurse(&dict, &entry);
+		dbus_message_iter_get_basic(&entry, &key);
+		dbus_message_iter_next(&entry);
+		dbus_message_iter_get_basic(&entry, &value);
+
+		if (strcmp(key, "CISCO_CSTP_OPTIONS"))
+			DBG("%s = %s", key, value);
+
+		if (!strcmp(key, "VPNGATEWAY"))
+			gateway = g_strdup(value);
+
+		if (!strcmp(key, "INTERNAL_IP4_ADDRESS"))
+			addressv4 = g_strdup(value);
+
+		if (!strcmp(key, "INTERNAL_IP6_ADDRESS")) {
+			addressv6 = g_strdup(value);
+			prefix_len = 128;
+		}
+
+		if (!strcmp(key, "INTERNAL_IP4_NETMASK"))
+			netmask = g_strdup(value);
+
+		if (!strcmp(key, "INTERNAL_IP6_NETMASK")) {
+			char *sep;
+
+			/* The netmask contains the address and the prefix */
+			sep = strchr(value, '/');
+			if (sep) {
+				unsigned char ip_len = sep - value;
+
+				addressv6 = g_strndup(value, ip_len);
+				prefix_len = (unsigned char)
+						strtol(sep + 1, NULL, 10);
+			}
+		}
+
+		if (!strcmp(key, "INTERNAL_IP4_DNS") ||
+				!strcmp(key, "INTERNAL_IP6_DNS"))
+			vpn_provider_set_nameservers(provider, value);
+
+		if (!strcmp(key, "CISCO_PROXY_PAC"))
+			vpn_provider_set_pac(provider, value);
+
+		if (!domain && !strcmp(key, "CISCO_DEF_DOMAIN")) {
+			g_free(domain);
+			domain = g_strdup(value);
+		}
+
+		if (g_str_has_prefix(key, "CISCO_SPLIT_INC") ||
+			g_str_has_prefix(key, "CISCO_IPV6_SPLIT_INC"))
+			vpn_provider_append_route(provider, key, value);
+
+		dbus_message_iter_next(&dict);
+	}
+
+	DBG("%p %p", addressv4, addressv6);
+
+	if (addressv4)
+		ipaddress = connman_ipaddress_alloc(AF_INET);
+	else if (addressv6)
+		ipaddress = connman_ipaddress_alloc(AF_INET6);
+	else
+		ipaddress = NULL;
+
+	if (!ipaddress) {
+		g_free(addressv4);
+		g_free(addressv6);
+		g_free(netmask);
+		g_free(gateway);
+		g_free(domain);
+
+		return VPN_STATE_FAILURE;
+	}
+
+	if (addressv4)
+		connman_ipaddress_set_ipv4(ipaddress, addressv4,
+						netmask, gateway);
+	else
+		connman_ipaddress_set_ipv6(ipaddress, addressv6,
+						prefix_len, gateway);
+	vpn_provider_set_ipaddress(provider, ipaddress);
+	vpn_provider_set_domain(provider, domain);
+
+	g_free(addressv4);
+	g_free(addressv6);
+	g_free(netmask);
+	g_free(gateway);
+	g_free(domain);
+	connman_ipaddress_free(ipaddress);
+
+	return VPN_STATE_CONNECT;
+}
+
+static int run_connect(struct vpn_provider *provider,
+			struct connman_task *task, const char *if_name,
+			vpn_provider_connect_cb_t cb, void *user_data)
+{
+	const char *vpnhost, *vpncookie, *servercert, *mtu;
+	int fd, err = 0, len;
+
+	vpnhost = vpn_provider_get_string(provider, "OpenConnect.VPNHost");
+	if (!vpnhost)
+		vpnhost = vpn_provider_get_string(provider, "Host");
+	vpncookie = vpn_provider_get_string(provider, "OpenConnect.Cookie");
+	servercert = vpn_provider_get_string(provider,
+			"OpenConnect.ServerCert");
+
+	if (!vpncookie || !servercert) {
+		err = -EINVAL;
+		goto done;
+	}
+
+	task_append_config_data(provider, task);
+
+	connman_task_add_argument(task, "--servercert", servercert);
+
+	mtu = vpn_provider_get_string(provider, "VPN.MTU");
+
+	if (mtu)
+		connman_task_add_argument(task, "--mtu", (char *)mtu);
+
+	connman_task_add_argument(task, "--syslog", NULL);
+	connman_task_add_argument(task, "--cookie-on-stdin", NULL);
+
+	connman_task_add_argument(task, "--script",
+				  SCRIPTDIR "/openconnect-script");
+
+	connman_task_add_argument(task, "--interface", if_name);
+
+	connman_task_add_argument(task, (char *)vpnhost, NULL);
+
+	err = connman_task_run(task, vpn_died, provider,
+			       &fd, NULL, NULL);
+	if (err < 0) {
+		connman_error("openconnect failed to start");
+		err = -EIO;
+		goto done;
+	}
+
+	len = strlen(vpncookie);
+	if (write(fd, vpncookie, len) != (ssize_t)len ||
+			write(fd, "\n", 1) != 1) {
+		connman_error("openconnect failed to take cookie on stdin");
+		err = -EIO;
+		goto done;
+	}
+
+done:
+	if (cb)
+		cb(provider, user_data, err);
+
+	return err;
+}
+
+static void request_input_append_informational(DBusMessageIter *iter,
+		void *user_data)
+{
+	const char *str;
+
+	str = "string";
+	connman_dbus_dict_append_basic(iter, "Type", DBUS_TYPE_STRING, &str);
+
+	str = "informational";
+	connman_dbus_dict_append_basic(iter, "Requirement", DBUS_TYPE_STRING,
+			&str);
+
+	str = user_data;
+	connman_dbus_dict_append_basic(iter, "Value", DBUS_TYPE_STRING, &str);
+}
+
+static void request_input_append_mandatory(DBusMessageIter *iter,
+		void *user_data)
+{
+	char *str = "string";
+
+	connman_dbus_dict_append_basic(iter, "Type",
+				DBUS_TYPE_STRING, &str);
+	str = "mandatory";
+	connman_dbus_dict_append_basic(iter, "Requirement",
+				DBUS_TYPE_STRING, &str);
+}
+
+static void request_input_cookie_reply(DBusMessage *reply, void *user_data)
+{
+	struct oc_private_data *data = user_data;
+	char *cookie = NULL, *servercert = NULL, *vpnhost = NULL;
+	char *key;
+	DBusMessageIter iter, dict;
+
+	DBG("provider %p", data->provider);
+
+	if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR)
+		goto err;
+
+	if (!vpn_agent_check_reply_has_dict(reply))
+		goto err;
+
+	dbus_message_iter_init(reply, &iter);
+	dbus_message_iter_recurse(&iter, &dict);
+	while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
+		DBusMessageIter entry, value;
+
+		dbus_message_iter_recurse(&dict, &entry);
+		if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING)
+			break;
+
+		dbus_message_iter_get_basic(&entry, &key);
+
+		if (g_str_equal(key, "OpenConnect.Cookie")) {
+			dbus_message_iter_next(&entry);
+			if (dbus_message_iter_get_arg_type(&entry)
+							!= DBUS_TYPE_VARIANT)
+				break;
+			dbus_message_iter_recurse(&entry, &value);
+			if (dbus_message_iter_get_arg_type(&value)
+							!= DBUS_TYPE_STRING)
+				break;
+			dbus_message_iter_get_basic(&value, &cookie);
+			vpn_provider_set_string_hide_value(data->provider,
+					key, cookie);
+
+		} else if (g_str_equal(key, "OpenConnect.ServerCert")) {
+			dbus_message_iter_next(&entry);
+			if (dbus_message_iter_get_arg_type(&entry)
+							!= DBUS_TYPE_VARIANT)
+				break;
+			dbus_message_iter_recurse(&entry, &value);
+			if (dbus_message_iter_get_arg_type(&value)
+							!= DBUS_TYPE_STRING)
+				break;
+			dbus_message_iter_get_basic(&value, &servercert);
+			vpn_provider_set_string(data->provider, key,
+					servercert);
+
+		} else if (g_str_equal(key, "OpenConnect.VPNHost")) {
+			dbus_message_iter_next(&entry);
+			if (dbus_message_iter_get_arg_type(&entry)
+							!= DBUS_TYPE_VARIANT)
+				break;
+			dbus_message_iter_recurse(&entry, &value);
+			if (dbus_message_iter_get_arg_type(&value)
+							!= DBUS_TYPE_STRING)
+				break;
+			dbus_message_iter_get_basic(&value, &vpnhost);
+			vpn_provider_set_string(data->provider, key, vpnhost);
+		}
+
+		dbus_message_iter_next(&dict);
+	}
+
+	if (!cookie || !servercert || !vpnhost)
+		goto err;
+
+	run_connect(data->provider, data->task, data->if_name, data->cb,
+		data->user_data);
+
+	free_private_data(data);
+
+	return;
+
+err:
+	vpn_provider_indicate_error(data->provider,
+			VPN_PROVIDER_ERROR_AUTH_FAILED);
+
+	free_private_data(data);
+}
+
+static int request_cookie_input(struct vpn_provider *provider,
+				struct oc_private_data *data,
+				const char *dbus_sender)
+{
+	DBusMessage *message;
+	const char *path, *agent_sender, *agent_path;
+	DBusMessageIter iter;
+	DBusMessageIter dict;
+	const char *str;
+	int err;
+	void *agent;
+
+	agent = connman_agent_get_info(dbus_sender, &agent_sender,
+							&agent_path);
+	if (!provider || !agent || !agent_path)
+		return -ESRCH;
+
+	message = dbus_message_new_method_call(agent_sender, agent_path,
+					VPN_AGENT_INTERFACE,
+					"RequestInput");
+	if (!message)
+		return -ENOMEM;
+
+	dbus_message_iter_init_append(message, &iter);
+
+	path = vpn_provider_get_path(provider);
+	dbus_message_iter_append_basic(&iter,
+				DBUS_TYPE_OBJECT_PATH, &path);
+
+	connman_dbus_dict_open(&iter, &dict);
+
+	str = vpn_provider_get_string(provider, "OpenConnect.CACert");
+	if (str)
+		connman_dbus_dict_append_dict(&dict, "OpenConnect.CACert",
+				request_input_append_informational,
+				(void *)str);
+
+	str = vpn_provider_get_string(provider, "OpenConnect.ClientCert");
+	if (str)
+		connman_dbus_dict_append_dict(&dict, "OpenConnect.ClientCert",
+				request_input_append_informational,
+				(void *)str);
+
+	connman_dbus_dict_append_dict(&dict, "OpenConnect.ServerCert",
+			request_input_append_mandatory, NULL);
+
+	connman_dbus_dict_append_dict(&dict, "OpenConnect.VPNHost",
+			request_input_append_mandatory, NULL);
+
+	connman_dbus_dict_append_dict(&dict, "OpenConnect.Cookie",
+			request_input_append_mandatory, NULL);
+
+	vpn_agent_append_host_and_name(&dict, provider);
+
+	connman_dbus_dict_close(&iter, &dict);
+
+	err = connman_agent_queue_message(provider, message,
+			connman_timeout_input_request(),
+			request_input_cookie_reply, data, agent);
+
+	if (err < 0 && err != -EBUSY) {
+		DBG("error %d sending agent request", err);
+		dbus_message_unref(message);
+
+		return err;
+	}
+
+	dbus_message_unref(message);
+
+	return -EINPROGRESS;
+}
+
+static int oc_connect(struct vpn_provider *provider,
+			struct connman_task *task, const char *if_name,
+			vpn_provider_connect_cb_t cb,
+			const char *dbus_sender, void *user_data)
+{
+	const char *vpnhost, *vpncookie, *servercert;
+	int err;
+
+	vpnhost = vpn_provider_get_string(provider, "Host");
+	if (!vpnhost) {
+		connman_error("Host not set; cannot enable VPN");
+		return -EINVAL;
+	}
+
+	vpncookie = vpn_provider_get_string(provider, "OpenConnect.Cookie");
+	servercert = vpn_provider_get_string(provider,
+			"OpenConnect.ServerCert");
+	if (!vpncookie || !servercert) {
+		struct oc_private_data *data;
+
+		data = g_try_new0(struct oc_private_data, 1);
+		if (!data)
+			return -ENOMEM;
+
+		data->provider = provider;
+		data->task = task;
+		data->if_name = g_strdup(if_name);
+		data->cb = cb;
+		data->user_data = user_data;
+
+		err = request_cookie_input(provider, data, dbus_sender);
+		if (err != -EINPROGRESS) {
+			vpn_provider_indicate_error(data->provider,
+					VPN_PROVIDER_ERROR_LOGIN_FAILED);
+			free_private_data(data);
+		}
+		return err;
+	}
+
+	return run_connect(provider, task, if_name, cb, user_data);
+}
+
+static int oc_save(struct vpn_provider *provider, GKeyFile *keyfile)
+{
+	const char *setting, *option;
+	int i;
+
+	setting = vpn_provider_get_string(provider,
+					"OpenConnect.ServerCert");
+	if (setting)
+		g_key_file_set_string(keyfile,
+				vpn_provider_get_save_group(provider),
+				"OpenConnect.ServerCert", setting);
+
+	setting = vpn_provider_get_string(provider,
+					"OpenConnect.CACert");
+	if (setting)
+		g_key_file_set_string(keyfile,
+				vpn_provider_get_save_group(provider),
+				"OpenConnect.CACert", setting);
+
+	setting = vpn_provider_get_string(provider,
+					"VPN.MTU");
+	if (setting)
+		g_key_file_set_string(keyfile,
+				vpn_provider_get_save_group(provider),
+				"VPN.MTU", setting);
+
+	for (i = 0; i < (int)ARRAY_SIZE(oc_options); i++) {
+		if (strncmp(oc_options[i].cm_opt, "OpenConnect.", 12) == 0) {
+			option = vpn_provider_get_string(provider,
+							oc_options[i].cm_opt);
+			if (!option)
+				continue;
+
+			g_key_file_set_string(keyfile,
+					vpn_provider_get_save_group(provider),
+					oc_options[i].cm_opt, option);
+		}
+	}
+
+	return 0;
+}
+
+static int oc_error_code(struct vpn_provider *provider, int exit_code)
+{
+
+	switch (exit_code) {
+	case 1:
+	case 2:
+		vpn_provider_set_string_hide_value(provider,
+				"OpenConnect.Cookie", NULL);
+		return VPN_PROVIDER_ERROR_LOGIN_FAILED;
+	default:
+		return VPN_PROVIDER_ERROR_UNKNOWN;
+	}
+}
+
+static struct vpn_driver vpn_driver = {
+	.notify         = oc_notify,
+	.connect	= oc_connect,
+	.error_code	= oc_error_code,
+	.save		= oc_save,
+};
+
+static int openconnect_init(void)
+{
+	return vpn_register("openconnect", &vpn_driver, OPENCONNECT);
+}
+
+static void openconnect_exit(void)
+{
+	vpn_unregister("openconnect");
+}
+
+CONNMAN_PLUGIN_DEFINE(openconnect, "OpenConnect VPN plugin", VERSION,
+	CONNMAN_PLUGIN_PRIORITY_DEFAULT, openconnect_init, openconnect_exit)
diff --git a/connman/vpn/plugins/openvpn.c b/connman/vpn/plugins/openvpn.c
new file mode 100644
index 0000000..9ee5795
--- /dev/null
+++ b/connman/vpn/plugins/openvpn.c
@@ -0,0 +1,419 @@
+/*
+ *
+ *  ConnMan VPN daemon
+ *
+ *  Copyright (C) 2010-2014  BMW Car IT GmbH.
+ *
+ *  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 <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <net/if.h>
+
+#include <glib.h>
+
+#define CONNMAN_API_SUBJECT_TO_CHANGE
+#include <connman/plugin.h>
+#include <connman/log.h>
+#include <connman/task.h>
+#include <connman/dbus.h>
+#include <connman/ipconfig.h>
+
+#include "../vpn-provider.h"
+
+#include "vpn.h"
+
+#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
+
+static DBusConnection *connection;
+
+struct {
+	const char *cm_opt;
+	const char *ov_opt;
+	char       has_value;
+} ov_options[] = {
+	{ "Host", "--remote", 1 },
+	{ "OpenVPN.CACert", "--ca", 1 },
+	{ "OpenVPN.Cert", "--cert", 1 },
+	{ "OpenVPN.Key", "--key", 1 },
+	{ "OpenVPN.MTU", "--mtu", 1 },
+	{ "OpenVPN.NSCertType", "--ns-cert-type", 1 },
+	{ "OpenVPN.Proto", "--proto", 1 },
+	{ "OpenVPN.Port", "--port", 1 },
+	{ "OpenVPN.AuthUserPass", "--auth-user-pass", 1 },
+	{ "OpenVPN.AskPass", "--askpass", 1 },
+	{ "OpenVPN.AuthNoCache", "--auth-nocache", 0 },
+	{ "OpenVPN.TLSRemote", "--tls-remote", 1 },
+	{ "OpenVPN.TLSAuth", NULL, 1 },
+	{ "OpenVPN.TLSAuthDir", NULL, 1 },
+	{ "OpenVPN.Cipher", "--cipher", 1 },
+	{ "OpenVPN.Auth", "--auth", 1 },
+	{ "OpenVPN.CompLZO", "--comp-lzo", 0 },
+	{ "OpenVPN.RemoteCertTls", "--remote-cert-tls", 1 },
+	{ "OpenVPN.ConfigFile", "--config", 1 },
+};
+
+struct nameserver_entry {
+	int id;
+	char *nameserver;
+};
+
+static struct nameserver_entry *ov_append_dns_entries(const char *key,
+						const char *value)
+{
+	struct nameserver_entry *entry = NULL;
+	gchar **options;
+
+	if (!g_str_has_prefix(key, "foreign_option_"))
+		return NULL;
+
+	options = g_strsplit(value, " ", 3);
+	if (options[0] &&
+		!strcmp(options[0], "dhcp-option") &&
+			options[1] &&
+			!strcmp(options[1], "DNS") &&
+				options[2]) {
+
+		entry = g_try_new(struct nameserver_entry, 1);
+		if (!entry)
+			return NULL;
+
+		entry->nameserver = g_strdup(options[2]);
+		entry->id = atoi(key + 15); /* foreign_option_XXX */
+	}
+
+	g_strfreev(options);
+
+	return entry;
+}
+
+static char *ov_get_domain_name(const char *key, const char *value)
+{
+	gchar **options;
+	char *domain = NULL;
+
+	if (!g_str_has_prefix(key, "foreign_option_"))
+		return NULL;
+
+	options = g_strsplit(value, " ", 3);
+	if (options[0] &&
+		!strcmp(options[0], "dhcp-option") &&
+			options[1] &&
+			!strcmp(options[1], "DOMAIN") &&
+				options[2]) {
+
+		domain = g_strdup(options[2]);
+	}
+
+	g_strfreev(options);
+
+	return domain;
+}
+
+static gint cmp_ns(gconstpointer a, gconstpointer b)
+{
+	struct nameserver_entry *entry_a = (struct nameserver_entry *)a;
+	struct nameserver_entry *entry_b = (struct nameserver_entry *)b;
+
+	if (entry_a->id < entry_b->id)
+		return -1;
+
+	if (entry_a->id > entry_b->id)
+		return 1;
+
+	return 0;
+}
+
+static void free_ns_entry(gpointer data)
+{
+	struct nameserver_entry *entry = data;
+
+	g_free(entry->nameserver);
+	g_free(entry);
+}
+
+static int ov_notify(DBusMessage *msg, struct vpn_provider *provider)
+{
+	DBusMessageIter iter, dict;
+	const char *reason, *key, *value;
+	char *address = NULL, *gateway = NULL, *peer = NULL;
+	struct connman_ipaddress *ipaddress;
+	GSList *nameserver_list = NULL;
+
+	dbus_message_iter_init(msg, &iter);
+
+	dbus_message_iter_get_basic(&iter, &reason);
+	dbus_message_iter_next(&iter);
+
+	if (!provider) {
+		connman_error("No provider found");
+		return VPN_STATE_FAILURE;
+	}
+
+	if (strcmp(reason, "up"))
+		return VPN_STATE_DISCONNECT;
+
+	dbus_message_iter_recurse(&iter, &dict);
+
+	while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
+		struct nameserver_entry *ns_entry = NULL;
+		DBusMessageIter entry;
+
+		dbus_message_iter_recurse(&dict, &entry);
+		dbus_message_iter_get_basic(&entry, &key);
+		dbus_message_iter_next(&entry);
+		dbus_message_iter_get_basic(&entry, &value);
+
+		DBG("%s = %s", key, value);
+
+		if (!strcmp(key, "trusted_ip"))
+			gateway = g_strdup(value);
+
+		if (!strcmp(key, "ifconfig_local"))
+			address = g_strdup(value);
+
+		if (!strcmp(key, "ifconfig_remote"))
+			peer = g_strdup(value);
+
+		if (g_str_has_prefix(key, "route_"))
+			vpn_provider_append_route(provider, key, value);
+
+		if ((ns_entry = ov_append_dns_entries(key, value)))
+			nameserver_list = g_slist_prepend(nameserver_list,
+							ns_entry);
+		else {
+			char *domain = ov_get_domain_name(key, value);
+			if (domain) {
+				vpn_provider_set_domain(provider, domain);
+				g_free(domain);
+			}
+		}
+
+		dbus_message_iter_next(&dict);
+	}
+
+	ipaddress = connman_ipaddress_alloc(AF_INET);
+	if (!ipaddress) {
+		g_slist_free_full(nameserver_list, free_ns_entry);
+		g_free(address);
+		g_free(gateway);
+		g_free(peer);
+
+		return VPN_STATE_FAILURE;
+	}
+
+	connman_ipaddress_set_ipv4(ipaddress, address, NULL, gateway);
+	connman_ipaddress_set_peer(ipaddress, peer);
+	vpn_provider_set_ipaddress(provider, ipaddress);
+
+	if (nameserver_list) {
+		char *nameservers = NULL;
+		GSList *tmp;
+
+		nameserver_list = g_slist_sort(nameserver_list, cmp_ns);
+		for (tmp = nameserver_list; tmp;
+						tmp = g_slist_next(tmp)) {
+			struct nameserver_entry *ns = tmp->data;
+
+			if (!nameservers) {
+				nameservers = g_strdup(ns->nameserver);
+			} else {
+				char *str;
+				str = g_strjoin(" ", nameservers,
+						ns->nameserver, NULL);
+				g_free(nameservers);
+				nameservers = str;
+			}
+		}
+
+		g_slist_free_full(nameserver_list, free_ns_entry);
+
+		vpn_provider_set_nameservers(provider, nameservers);
+
+		g_free(nameservers);
+	}
+
+	g_free(address);
+	g_free(gateway);
+	g_free(peer);
+	connman_ipaddress_free(ipaddress);
+
+	return VPN_STATE_CONNECT;
+}
+
+static int ov_save(struct vpn_provider *provider, GKeyFile *keyfile)
+{
+	const char *option;
+	int i;
+
+	for (i = 0; i < (int)ARRAY_SIZE(ov_options); i++) {
+		if (strncmp(ov_options[i].cm_opt, "OpenVPN.", 8) == 0) {
+			option = vpn_provider_get_string(provider,
+							ov_options[i].cm_opt);
+			if (!option)
+				continue;
+
+			g_key_file_set_string(keyfile,
+					vpn_provider_get_save_group(provider),
+					ov_options[i].cm_opt, option);
+		}
+	}
+	return 0;
+}
+
+static int task_append_config_data(struct vpn_provider *provider,
+					struct connman_task *task)
+{
+	const char *option;
+	int i;
+
+	for (i = 0; i < (int)ARRAY_SIZE(ov_options); i++) {
+		if (!ov_options[i].ov_opt)
+			continue;
+
+		option = vpn_provider_get_string(provider,
+					ov_options[i].cm_opt);
+		if (!option)
+			continue;
+
+		if (connman_task_add_argument(task,
+				ov_options[i].ov_opt,
+				ov_options[i].has_value ? option : NULL) < 0) {
+			return -EIO;
+		}
+	}
+
+	return 0;
+}
+
+static int ov_connect(struct vpn_provider *provider,
+			struct connman_task *task, const char *if_name,
+			vpn_provider_connect_cb_t cb, const char *dbus_sender,
+			void *user_data)
+{
+	const char *option;
+	int err = 0, fd;
+
+	option = vpn_provider_get_string(provider, "Host");
+	if (!option) {
+		connman_error("Host not set; cannot enable VPN");
+		return -EINVAL;
+	}
+
+	task_append_config_data(provider, task);
+
+	option = vpn_provider_get_string(provider, "OpenVPN.ConfigFile");
+	if (!option) {
+		/*
+		 * Set some default options if user has no config file.
+		 */
+		option = vpn_provider_get_string(provider, "OpenVPN.TLSAuth");
+		if (option) {
+			connman_task_add_argument(task, "--tls-auth", option);
+			option = vpn_provider_get_string(provider,
+							"OpenVPN.TLSAuthDir");
+			if (option)
+				connman_task_add_argument(task, option, NULL);
+		}
+
+		connman_task_add_argument(task, "--nobind", NULL);
+		connman_task_add_argument(task, "--persist-key", NULL);
+		connman_task_add_argument(task, "--client", NULL);
+	}
+
+	connman_task_add_argument(task, "--syslog", NULL);
+
+	connman_task_add_argument(task, "--script-security", "2");
+
+	connman_task_add_argument(task, "--up",
+					SCRIPTDIR "/openvpn-script");
+	connman_task_add_argument(task, "--up-restart", NULL);
+
+	connman_task_add_argument(task, "--setenv", NULL);
+	connman_task_add_argument(task, "CONNMAN_BUSNAME",
+					dbus_bus_get_unique_name(connection));
+
+	connman_task_add_argument(task, "--setenv", NULL);
+	connman_task_add_argument(task, "CONNMAN_INTERFACE",
+					CONNMAN_TASK_INTERFACE);
+
+	connman_task_add_argument(task, "--setenv", NULL);
+	connman_task_add_argument(task, "CONNMAN_PATH",
+					connman_task_get_path(task));
+
+	connman_task_add_argument(task, "--dev", if_name);
+	connman_task_add_argument(task, "--dev-type", "tun");
+
+	connman_task_add_argument(task, "--persist-tun", NULL);
+
+	connman_task_add_argument(task, "--route-noexec", NULL);
+	connman_task_add_argument(task, "--ifconfig-noexec", NULL);
+
+	/*
+	 * Disable client restarts because we can't handle this at the
+	 * moment. The problem is that when OpenVPN decides to switch
+	 * from CONNECTED state to RECONNECTING and then to RESOLVE,
+	 * it is not possible to do a DNS lookup. The DNS server is
+	 * not accessable through the tunnel anymore and so we end up
+	 * trying to resolve the OpenVPN servers address.
+	 */
+	connman_task_add_argument(task, "--ping-restart", "0");
+
+	fd = fileno(stderr);
+	err = connman_task_run(task, vpn_died, provider,
+			NULL, &fd, &fd);
+	if (err < 0) {
+		connman_error("openvpn failed to start");
+		err = -EIO;
+		goto done;
+	}
+
+done:
+	if (cb)
+		cb(provider, user_data, err);
+
+	return err;
+}
+
+static struct vpn_driver vpn_driver = {
+	.notify	= ov_notify,
+	.connect	= ov_connect,
+	.save		= ov_save,
+};
+
+static int openvpn_init(void)
+{
+	connection = connman_dbus_get_connection();
+
+	return vpn_register("openvpn", &vpn_driver, OPENVPN);
+}
+
+static void openvpn_exit(void)
+{
+	vpn_unregister("openvpn");
+
+	dbus_connection_unref(connection);
+}
+
+CONNMAN_PLUGIN_DEFINE(openvpn, "OpenVPN plugin", VERSION,
+	CONNMAN_PLUGIN_PRIORITY_DEFAULT, openvpn_init, openvpn_exit)
diff --git a/connman/vpn/plugins/pptp.c b/connman/vpn/plugins/pptp.c
new file mode 100644
index 0000000..9f2a214
--- /dev/null
+++ b/connman/vpn/plugins/pptp.c
@@ -0,0 +1,622 @@
+/*
+ *
+ *  ConnMan VPN daemon
+ *
+ *  Copyright (C) 2010,2013-2014  BMW Car IT GmbH.
+ *  Copyright (C) 2012-2013  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 <errno.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <net/if.h>
+
+#include <dbus/dbus.h>
+#include <glib.h>
+
+#define CONNMAN_API_SUBJECT_TO_CHANGE
+#include <connman/plugin.h>
+#include <connman/provider.h>
+#include <connman/log.h>
+#include <connman/task.h>
+#include <connman/dbus.h>
+#include <connman/inet.h>
+#include <connman/agent.h>
+#include <connman/setting.h>
+#include <connman/vpn-dbus.h>
+
+#include "../vpn-provider.h"
+#include "../vpn-agent.h"
+
+#include "vpn.h"
+
+#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
+
+enum {
+	OPT_STRING = 1,
+	OPT_BOOL = 2,
+};
+
+struct {
+	const char *cm_opt;
+	const char *pptp_opt;
+	const char *vpnc_default;
+	int type;
+} pptp_options[] = {
+	{ "PPTP.User", "user", NULL, OPT_STRING },
+	{ "PPPD.EchoFailure", "lcp-echo-failure", "0", OPT_STRING },
+	{ "PPPD.EchoInterval", "lcp-echo-interval", "0", OPT_STRING },
+	{ "PPPD.Debug", "debug", NULL, OPT_STRING },
+	{ "PPPD.RefuseEAP", "refuse-eap", NULL, OPT_BOOL },
+	{ "PPPD.RefusePAP", "refuse-pap", NULL, OPT_BOOL },
+	{ "PPPD.RefuseCHAP", "refuse-chap", NULL, OPT_BOOL },
+	{ "PPPD.RefuseMSCHAP", "refuse-mschap", NULL, OPT_BOOL },
+	{ "PPPD.RefuseMSCHAP2", "refuse-mschapv2", NULL, OPT_BOOL },
+	{ "PPPD.NoBSDComp", "nobsdcomp", NULL, OPT_BOOL },
+	{ "PPPD.NoDeflate", "nodeflate", NULL, OPT_BOOL },
+	{ "PPPD.RequirMPPE", "require-mppe", NULL, OPT_BOOL },
+	{ "PPPD.RequirMPPE40", "require-mppe-40", NULL, OPT_BOOL },
+	{ "PPPD.RequirMPPE128", "require-mppe-128", NULL, OPT_BOOL },
+	{ "PPPD.RequirMPPEStateful", "mppe-stateful", NULL, OPT_BOOL },
+	{ "PPPD.NoVJ", "no-vj-comp", NULL, OPT_BOOL },
+};
+
+static DBusConnection *connection;
+
+struct pptp_private_data {
+	struct connman_task *task;
+	char *if_name;
+	vpn_provider_connect_cb_t cb;
+	void *user_data;
+};
+
+static DBusMessage *pptp_get_sec(struct connman_task *task,
+				DBusMessage *msg, void *user_data)
+{
+	const char *user, *passwd;
+	struct vpn_provider *provider = user_data;
+	DBusMessage *reply;
+
+	if (dbus_message_get_no_reply(msg))
+		return NULL;
+
+	user = vpn_provider_get_string(provider, "PPTP.User");
+	passwd = vpn_provider_get_string(provider, "PPTP.Password");
+	if (!user || strlen(user) == 0 ||
+				!passwd || strlen(passwd) == 0)
+		return NULL;
+
+	reply = dbus_message_new_method_return(msg);
+	if (!reply)
+		return NULL;
+
+	dbus_message_append_args(reply, DBUS_TYPE_STRING, &user,
+				DBUS_TYPE_STRING, &passwd,
+				DBUS_TYPE_INVALID);
+	return reply;
+}
+
+static int pptp_notify(DBusMessage *msg, struct vpn_provider *provider)
+{
+	DBusMessageIter iter, dict;
+	const char *reason, *key, *value;
+	char *addressv4 = NULL, *netmask = NULL, *gateway = NULL;
+	char *ifname = NULL, *nameservers = NULL;
+	struct connman_ipaddress *ipaddress = NULL;
+
+	dbus_message_iter_init(msg, &iter);
+
+	dbus_message_iter_get_basic(&iter, &reason);
+	dbus_message_iter_next(&iter);
+
+	if (!provider) {
+		connman_error("No provider found");
+		return VPN_STATE_FAILURE;
+	}
+
+	if (strcmp(reason, "auth failed") == 0) {
+		DBG("authentication failure");
+
+		vpn_provider_set_string(provider, "PPTP.User", NULL);
+		vpn_provider_set_string(provider, "PPTP.Password", NULL);
+
+		return VPN_STATE_AUTH_FAILURE;
+	}
+
+	if (strcmp(reason, "connect"))
+		return VPN_STATE_DISCONNECT;
+
+	dbus_message_iter_recurse(&iter, &dict);
+
+	while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
+		DBusMessageIter entry;
+
+		dbus_message_iter_recurse(&dict, &entry);
+		dbus_message_iter_get_basic(&entry, &key);
+		dbus_message_iter_next(&entry);
+		dbus_message_iter_get_basic(&entry, &value);
+
+		DBG("%s = %s", key, value);
+
+		if (!strcmp(key, "INTERNAL_IP4_ADDRESS"))
+			addressv4 = g_strdup(value);
+
+		if (!strcmp(key, "INTERNAL_IP4_NETMASK"))
+			netmask = g_strdup(value);
+
+		if (!strcmp(key, "INTERNAL_IP4_DNS"))
+			nameservers = g_strdup(value);
+
+		if (!strcmp(key, "INTERNAL_IFNAME"))
+			ifname = g_strdup(value);
+
+		dbus_message_iter_next(&dict);
+	}
+
+	if (vpn_set_ifname(provider, ifname) < 0) {
+		g_free(ifname);
+		g_free(addressv4);
+		g_free(netmask);
+		g_free(nameservers);
+		return VPN_STATE_FAILURE;
+	}
+
+	if (addressv4)
+		ipaddress = connman_ipaddress_alloc(AF_INET);
+
+	g_free(ifname);
+
+	if (!ipaddress) {
+		connman_error("No IP address for provider");
+		g_free(addressv4);
+		g_free(netmask);
+		g_free(nameservers);
+		return VPN_STATE_FAILURE;
+	}
+
+	value = vpn_provider_get_string(provider, "HostIP");
+	if (value) {
+		vpn_provider_set_string(provider, "Gateway", value);
+		gateway = g_strdup(value);
+	}
+
+	if (addressv4)
+		connman_ipaddress_set_ipv4(ipaddress, addressv4, netmask,
+					gateway);
+
+	vpn_provider_set_ipaddress(provider, ipaddress);
+	vpn_provider_set_nameservers(provider, nameservers);
+
+	g_free(addressv4);
+	g_free(netmask);
+	g_free(gateway);
+	g_free(nameservers);
+	connman_ipaddress_free(ipaddress);
+
+	return VPN_STATE_CONNECT;
+}
+
+static int pptp_save(struct vpn_provider *provider, GKeyFile *keyfile)
+{
+	const char *option;
+	bool pptp_option, pppd_option;
+	int i;
+
+	for (i = 0; i < (int)ARRAY_SIZE(pptp_options); i++) {
+		pptp_option = pppd_option = false;
+
+		if (strncmp(pptp_options[i].cm_opt, "PPTP.", 5) == 0)
+			pptp_option = true;
+
+		if (strncmp(pptp_options[i].cm_opt, "PPPD.", 5) == 0)
+			pppd_option = true;
+
+		if (pptp_option || pppd_option) {
+			option = vpn_provider_get_string(provider,
+							pptp_options[i].cm_opt);
+			if (!option) {
+				/*
+				 * Check if the option prefix is PPTP as the
+				 * PPPD options were using PPTP prefix earlier.
+				 */
+				char *pptp_str;
+
+				if (!pppd_option)
+					continue;
+
+				pptp_str = g_strdup_printf("PPTP.%s",
+						&pptp_options[i].cm_opt[5]);
+				option = vpn_provider_get_string(provider,
+								pptp_str);
+				g_free(pptp_str);
+
+				if (!option)
+					continue;
+			}
+
+			g_key_file_set_string(keyfile,
+					vpn_provider_get_save_group(provider),
+					pptp_options[i].cm_opt, option);
+		}
+	}
+
+	return 0;
+}
+
+static void pptp_write_bool_option(struct connman_task *task,
+				const char *key, const char *value)
+{
+	if (key && value) {
+		if (strcasecmp(value, "yes") == 0 ||
+				strcasecmp(value, "true") == 0 ||
+				strcmp(value, "1") == 0)
+			connman_task_add_argument(task, key, NULL);
+	}
+}
+
+struct request_input_reply {
+	struct vpn_provider *provider;
+	vpn_provider_password_cb_t callback;
+	void *user_data;
+};
+
+static void request_input_reply(DBusMessage *reply, void *user_data)
+{
+	struct request_input_reply *pptp_reply = user_data;
+	const char *error = NULL;
+	char *username = NULL, *password = NULL;
+	char *key;
+	DBusMessageIter iter, dict;
+
+	DBG("provider %p", pptp_reply->provider);
+
+	if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) {
+		error = dbus_message_get_error_name(reply);
+		goto done;
+	}
+
+	if (!vpn_agent_check_reply_has_dict(reply))
+		goto done;
+
+	dbus_message_iter_init(reply, &iter);
+	dbus_message_iter_recurse(&iter, &dict);
+	while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
+		DBusMessageIter entry, value;
+		const char *str;
+
+		dbus_message_iter_recurse(&dict, &entry);
+		if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING)
+			break;
+
+		dbus_message_iter_get_basic(&entry, &key);
+
+		if (g_str_equal(key, "Username")) {
+			dbus_message_iter_next(&entry);
+			if (dbus_message_iter_get_arg_type(&entry)
+							!= DBUS_TYPE_VARIANT)
+				break;
+			dbus_message_iter_recurse(&entry, &value);
+			if (dbus_message_iter_get_arg_type(&value)
+							!= DBUS_TYPE_STRING)
+				break;
+			dbus_message_iter_get_basic(&value, &str);
+			username = g_strdup(str);
+		}
+
+		if (g_str_equal(key, "Password")) {
+			dbus_message_iter_next(&entry);
+			if (dbus_message_iter_get_arg_type(&entry)
+							!= DBUS_TYPE_VARIANT)
+				break;
+			dbus_message_iter_recurse(&entry, &value);
+			if (dbus_message_iter_get_arg_type(&value)
+							!= DBUS_TYPE_STRING)
+				break;
+			dbus_message_iter_get_basic(&value, &str);
+			password = g_strdup(str);
+		}
+
+		dbus_message_iter_next(&dict);
+	}
+
+done:
+	pptp_reply->callback(pptp_reply->provider, username, password, error,
+				pptp_reply->user_data);
+
+	g_free(username);
+	g_free(password);
+
+	g_free(pptp_reply);
+}
+
+typedef void (* request_cb_t)(struct vpn_provider *provider,
+				const char *username, const char *password,
+				const char *error, void *user_data);
+
+static int request_input(struct vpn_provider *provider,
+			request_cb_t callback, const char *dbus_sender,
+			void *user_data)
+{
+	DBusMessage *message;
+	const char *path, *agent_sender, *agent_path;
+	DBusMessageIter iter;
+	DBusMessageIter dict;
+	struct request_input_reply *pptp_reply;
+	int err;
+	void *agent;
+
+	agent = connman_agent_get_info(dbus_sender, &agent_sender,
+							&agent_path);
+	if (!provider || !agent || !agent_path || !callback)
+		return -ESRCH;
+
+	message = dbus_message_new_method_call(agent_sender, agent_path,
+					VPN_AGENT_INTERFACE,
+					"RequestInput");
+	if (!message)
+		return -ENOMEM;
+
+	dbus_message_iter_init_append(message, &iter);
+
+	path = vpn_provider_get_path(provider);
+	dbus_message_iter_append_basic(&iter,
+				DBUS_TYPE_OBJECT_PATH, &path);
+
+	connman_dbus_dict_open(&iter, &dict);
+
+	vpn_agent_append_user_info(&dict, provider, "PPTP.User");
+
+	vpn_agent_append_host_and_name(&dict, provider);
+
+	connman_dbus_dict_close(&iter, &dict);
+
+	pptp_reply = g_try_new0(struct request_input_reply, 1);
+	if (!pptp_reply) {
+		dbus_message_unref(message);
+		return -ENOMEM;
+	}
+
+	pptp_reply->provider = provider;
+	pptp_reply->callback = callback;
+	pptp_reply->user_data = user_data;
+
+	err = connman_agent_queue_message(provider, message,
+			connman_timeout_input_request(),
+			request_input_reply, pptp_reply, agent);
+	if (err < 0 && err != -EBUSY) {
+		DBG("error %d sending agent request", err);
+		dbus_message_unref(message);
+		g_free(pptp_reply);
+		return err;
+	}
+
+	dbus_message_unref(message);
+
+	return -EINPROGRESS;
+}
+
+static int run_connect(struct vpn_provider *provider,
+			struct connman_task *task, const char *if_name,
+			vpn_provider_connect_cb_t cb, void *user_data,
+			const char *username, const char *password)
+{
+	const char *opt_s, *host;
+	char *str;
+	int err, i;
+
+	host = vpn_provider_get_string(provider, "Host");
+	if (!host) {
+		connman_error("Host not set; cannot enable VPN");
+		err = -EINVAL;
+		goto done;
+	}
+
+	if (!username || !password) {
+		DBG("Cannot connect username %s password %p",
+						username, password);
+		err = -EINVAL;
+		goto done;
+	}
+
+	DBG("username %s password %p", username, password);
+
+	str = g_strdup_printf("%s %s --nolaunchpppd --loglevel 2",
+				PPTP, host);
+	if (!str) {
+		connman_error("can not allocate memory");
+		err = -ENOMEM;
+		goto done;
+	}
+
+	connman_task_add_argument(task, "pty", str);
+	g_free(str);
+
+	connman_task_add_argument(task, "nodetach", NULL);
+	connman_task_add_argument(task, "lock", NULL);
+	connman_task_add_argument(task, "usepeerdns", NULL);
+	connman_task_add_argument(task, "noipdefault", NULL);
+	connman_task_add_argument(task, "noauth", NULL);
+	connman_task_add_argument(task, "nodefaultroute", NULL);
+	connman_task_add_argument(task, "ipparam", "pptp_plugin");
+
+	for (i = 0; i < (int)ARRAY_SIZE(pptp_options); i++) {
+		opt_s = vpn_provider_get_string(provider,
+					pptp_options[i].cm_opt);
+		if (!opt_s)
+			opt_s = pptp_options[i].vpnc_default;
+
+		if (!opt_s)
+			continue;
+
+		if (pptp_options[i].type == OPT_STRING)
+			connman_task_add_argument(task,
+					pptp_options[i].pptp_opt, opt_s);
+		else if (pptp_options[i].type == OPT_BOOL)
+			pptp_write_bool_option(task,
+					pptp_options[i].pptp_opt, opt_s);
+	}
+
+	connman_task_add_argument(task, "plugin",
+				SCRIPTDIR "/libppp-plugin.so");
+
+	err = connman_task_run(task, vpn_died, provider,
+				NULL, NULL, NULL);
+	if (err < 0) {
+		connman_error("pptp failed to start");
+		err = -EIO;
+		goto done;
+	}
+
+done:
+	if (cb)
+		cb(provider, user_data, err);
+
+	return err;
+}
+
+static void free_private_data(struct pptp_private_data *data)
+{
+	g_free(data->if_name);
+	g_free(data);
+}
+
+static void request_input_cb(struct vpn_provider *provider,
+			const char *username,
+			const char *password,
+			const char *error, void *user_data)
+{
+	struct pptp_private_data *data = user_data;
+
+	if (!username || !password)
+		DBG("Requesting username %s or password failed, error %s",
+			username, error);
+	else if (error)
+		DBG("error %s", error);
+
+	vpn_provider_set_string(provider, "PPTP.User", username);
+	vpn_provider_set_string_hide_value(provider, "PPTP.Password",
+								password);
+
+	run_connect(provider, data->task, data->if_name, data->cb,
+		data->user_data, username, password);
+
+	free_private_data(data);
+}
+
+static int pptp_connect(struct vpn_provider *provider,
+			struct connman_task *task, const char *if_name,
+			vpn_provider_connect_cb_t cb, const char *dbus_sender,
+			void *user_data)
+{
+	const char *username, *password;
+	int err;
+
+	DBG("iface %s provider %p user %p", if_name, provider, user_data);
+
+	if (connman_task_set_notify(task, "getsec",
+					pptp_get_sec, provider)) {
+		err = -ENOMEM;
+		goto error;
+	}
+
+	username = vpn_provider_get_string(provider, "PPTP.User");
+	password = vpn_provider_get_string(provider, "PPTP.Password");
+
+	DBG("user %s password %p", username, password);
+
+	if (!username || !password) {
+		struct pptp_private_data *data;
+
+		data = g_try_new0(struct pptp_private_data, 1);
+		if (!data)
+			return -ENOMEM;
+
+		data->task = task;
+		data->if_name = g_strdup(if_name);
+		data->cb = cb;
+		data->user_data = user_data;
+
+		err = request_input(provider, request_input_cb, dbus_sender,
+									data);
+		if (err != -EINPROGRESS) {
+			free_private_data(data);
+			goto done;
+		}
+		return err;
+	}
+
+done:
+	return run_connect(provider, task, if_name, cb, user_data,
+							username, password);
+
+error:
+	if (cb)
+		cb(provider, user_data, err);
+
+	return err;
+}
+
+static int pptp_error_code(struct vpn_provider *provider, int exit_code)
+{
+
+	switch (exit_code) {
+	case 1:
+		return CONNMAN_PROVIDER_ERROR_CONNECT_FAILED;
+	case 2:
+		return CONNMAN_PROVIDER_ERROR_LOGIN_FAILED;
+	case 16:
+		return CONNMAN_PROVIDER_ERROR_AUTH_FAILED;
+	default:
+		return CONNMAN_PROVIDER_ERROR_UNKNOWN;
+	}
+}
+
+static void pptp_disconnect(struct vpn_provider *provider)
+{
+	vpn_provider_set_string(provider, "PPTP.Password", NULL);
+}
+
+static struct vpn_driver vpn_driver = {
+	.flags		= VPN_FLAG_NO_TUN,
+	.notify		= pptp_notify,
+	.connect	= pptp_connect,
+	.error_code     = pptp_error_code,
+	.save		= pptp_save,
+	.disconnect	= pptp_disconnect,
+};
+
+static int pptp_init(void)
+{
+	connection = connman_dbus_get_connection();
+
+	return vpn_register("pptp", &vpn_driver, PPPD);
+}
+
+static void pptp_exit(void)
+{
+	vpn_unregister("pptp");
+
+	dbus_connection_unref(connection);
+}
+
+CONNMAN_PLUGIN_DEFINE(pptp, "pptp plugin", VERSION,
+	CONNMAN_PLUGIN_PRIORITY_DEFAULT, pptp_init, pptp_exit)
diff --git a/connman/vpn/plugins/vpn.c b/connman/vpn/plugins/vpn.c
new file mode 100644
index 0000000..b438d06
--- /dev/null
+++ b/connman/vpn/plugins/vpn.c
@@ -0,0 +1,608 @@
+/*
+ *
+ *  ConnMan VPN daemon
+ *
+ *  Copyright (C) 2007-2013  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
+
+#define _GNU_SOURCE
+#include <string.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <stdio.h>
+#include <errno.h>
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <linux/if_tun.h>
+#include <net/if.h>
+
+#include <dbus/dbus.h>
+
+#include <glib/gprintf.h>
+
+#include <connman/log.h>
+#include <connman/rtnl.h>
+#include <connman/task.h>
+#include <connman/inet.h>
+
+#include "../vpn-rtnl.h"
+#include "../vpn-provider.h"
+
+#include "vpn.h"
+
+struct vpn_data {
+	struct vpn_provider *provider;
+	char *if_name;
+	unsigned flags;
+	unsigned int watch;
+	enum vpn_state state;
+	struct connman_task *task;
+};
+
+struct vpn_driver_data {
+	const char *name;
+	const char *program;
+	struct vpn_driver *vpn_driver;
+	struct vpn_provider_driver provider_driver;
+};
+
+GHashTable *driver_hash = NULL;
+
+static int stop_vpn(struct vpn_provider *provider)
+{
+	struct vpn_data *data = vpn_provider_get_data(provider);
+	struct vpn_driver_data *vpn_driver_data;
+	const char *name;
+	struct ifreq ifr;
+	int fd, err;
+
+	if (!data)
+		return -EINVAL;
+
+	name = vpn_provider_get_driver_name(provider);
+	if (!name)
+		return -EINVAL;
+
+	vpn_driver_data = g_hash_table_lookup(driver_hash, name);
+
+	if (vpn_driver_data && vpn_driver_data->vpn_driver &&
+			vpn_driver_data->vpn_driver->flags == VPN_FLAG_NO_TUN)
+		return 0;
+
+	memset(&ifr, 0, sizeof(ifr));
+	ifr.ifr_flags = IFF_TUN | IFF_NO_PI;
+	sprintf(ifr.ifr_name, "%s", data->if_name);
+
+	fd = open("/dev/net/tun", O_RDWR | O_CLOEXEC);
+	if (fd < 0) {
+		err = -errno;
+		connman_error("Failed to open /dev/net/tun to device %s: %s",
+			      data->if_name, strerror(errno));
+		return err;
+	}
+
+	if (ioctl(fd, TUNSETIFF, (void *)&ifr)) {
+		err = -errno;
+		connman_error("Failed to TUNSETIFF for device %s to it: %s",
+			      data->if_name, strerror(errno));
+		close(fd);
+		return err;
+	}
+
+	if (ioctl(fd, TUNSETPERSIST, 0)) {
+		err = -errno;
+		connman_error("Failed to set tun device %s nonpersistent: %s",
+			      data->if_name, strerror(errno));
+		close(fd);
+		return err;
+	}
+	close(fd);
+	DBG("Killed tun device %s", data->if_name);
+	return 0;
+}
+
+void vpn_died(struct connman_task *task, int exit_code, void *user_data)
+{
+	struct vpn_provider *provider = user_data;
+	struct vpn_data *data = vpn_provider_get_data(provider);
+	int state = VPN_STATE_FAILURE;
+	enum vpn_provider_error ret;
+
+	DBG("provider %p data %p", provider, data);
+
+	if (!data)
+		goto vpn_exit;
+
+	state = data->state;
+
+	stop_vpn(provider);
+	vpn_provider_set_data(provider, NULL);
+
+	if (data->watch != 0) {
+		vpn_rtnl_remove_watch(data->watch);
+		data->watch = 0;
+		vpn_provider_unref(provider);
+	}
+
+vpn_exit:
+	if (state != VPN_STATE_READY && state != VPN_STATE_DISCONNECT) {
+		const char *name;
+		struct vpn_driver_data *vpn_data = NULL;
+
+		name = vpn_provider_get_driver_name(provider);
+		if (name)
+			vpn_data = g_hash_table_lookup(driver_hash, name);
+
+		if (vpn_data &&
+				vpn_data->vpn_driver->error_code)
+			ret = vpn_data->vpn_driver->error_code(provider,
+					exit_code);
+		else
+			ret = VPN_PROVIDER_ERROR_UNKNOWN;
+
+		vpn_provider_indicate_error(provider, ret);
+	} else
+		vpn_provider_set_state(provider, VPN_PROVIDER_STATE_IDLE);
+
+	vpn_provider_set_index(provider, -1);
+
+	if (data) {
+		vpn_provider_unref(data->provider);
+		g_free(data->if_name);
+		g_free(data);
+	}
+
+	connman_task_destroy(task);
+}
+
+int vpn_set_ifname(struct vpn_provider *provider, const char *ifname)
+{
+	struct vpn_data *data = vpn_provider_get_data(provider);
+	int index;
+
+	if (!ifname || !data)
+		return  -EIO;
+
+	index = connman_inet_ifindex(ifname);
+	if (index < 0)
+		return  -EIO;
+
+	if (data->if_name)
+		g_free(data->if_name);
+
+	data->if_name = (char *)g_strdup(ifname);
+	vpn_provider_set_index(provider, index);
+
+	return 0;
+}
+
+static void vpn_newlink(unsigned flags, unsigned change, void *user_data)
+{
+	struct vpn_provider *provider = user_data;
+	struct vpn_data *data = vpn_provider_get_data(provider);
+
+	if ((data->flags & IFF_UP) != (flags & IFF_UP)) {
+		if (flags & IFF_UP) {
+			data->state = VPN_STATE_READY;
+			vpn_provider_set_state(provider,
+					VPN_PROVIDER_STATE_READY);
+		}
+	}
+	data->flags = flags;
+}
+
+static DBusMessage *vpn_notify(struct connman_task *task,
+			DBusMessage *msg, void *user_data)
+{
+	struct vpn_provider *provider = user_data;
+	struct vpn_data *data;
+	struct vpn_driver_data *vpn_driver_data;
+	const char *name;
+	int state, index, err;
+
+	data = vpn_provider_get_data(provider);
+
+	name = vpn_provider_get_driver_name(provider);
+
+	if (!name) {
+		DBG("Cannot find VPN driver for provider %p", provider);
+		vpn_provider_set_state(provider, VPN_PROVIDER_STATE_FAILURE);
+		return NULL;
+	}
+
+	vpn_driver_data = g_hash_table_lookup(driver_hash, name);
+	if (!vpn_driver_data) {
+		DBG("Cannot find VPN driver data for name %s", name);
+		vpn_provider_set_state(provider, VPN_PROVIDER_STATE_FAILURE);
+		return NULL;
+	}
+
+	state = vpn_driver_data->vpn_driver->notify(msg, provider);
+
+	DBG("provider %p driver %s state %d", provider, name, state);
+
+	switch (state) {
+	case VPN_STATE_CONNECT:
+	case VPN_STATE_READY:
+		if (data->state == VPN_STATE_READY) {
+			/*
+			 * This is the restart case, in which case we must
+			 * just set the IP address.
+			 *
+			 * We need to remove first the old address, just
+			 * replacing the old address will not work as expected
+			 * because the old address will linger in the interface
+			 * and not disapper so the clearing is needed here.
+			 *
+			 * Also the state must change, otherwise the routes
+			 * will not be set properly.
+			 */
+			vpn_provider_set_state(provider,
+						VPN_PROVIDER_STATE_CONNECT);
+
+			vpn_provider_clear_address(provider, AF_INET);
+			vpn_provider_clear_address(provider, AF_INET6);
+
+			vpn_provider_change_address(provider);
+			vpn_provider_set_state(provider,
+						VPN_PROVIDER_STATE_READY);
+			break;
+		}
+
+		index = vpn_provider_get_index(provider);
+		vpn_provider_ref(provider);
+		data->watch = vpn_rtnl_add_newlink_watch(index,
+						     vpn_newlink, provider);
+		err = connman_inet_ifup(index);
+		if (err < 0) {
+			if (err == -EALREADY)
+				/*
+				 * So the interface is up already, that is just
+				 * great. Unfortunately in this case the
+				 * newlink watch might not have been called at
+				 * all. We must manually call it here so that
+				 * the provider can go to ready state and the
+				 * routes are setup properly.
+				 */
+				vpn_newlink(IFF_UP, 0, provider);
+			else
+				DBG("Cannot take interface %d up err %d/%s",
+					index, -err, strerror(-err));
+		}
+		break;
+
+	case VPN_STATE_UNKNOWN:
+	case VPN_STATE_IDLE:
+	case VPN_STATE_DISCONNECT:
+	case VPN_STATE_FAILURE:
+		vpn_provider_set_state(provider,
+					VPN_PROVIDER_STATE_DISCONNECT);
+		break;
+
+	case VPN_STATE_AUTH_FAILURE:
+		vpn_provider_indicate_error(provider,
+					VPN_PROVIDER_ERROR_AUTH_FAILED);
+		break;
+	}
+
+	return NULL;
+}
+
+static int vpn_create_tun(struct vpn_provider *provider)
+{
+	struct vpn_data *data = vpn_provider_get_data(provider);
+	struct ifreq ifr;
+	int i, fd, index;
+	int ret = 0;
+
+	if (!data)
+		return -EISCONN;
+
+	fd = open("/dev/net/tun", O_RDWR | O_CLOEXEC);
+	if (fd < 0) {
+		i = -errno;
+		connman_error("Failed to open /dev/net/tun: %s",
+			      strerror(errno));
+		ret = i;
+		goto exist_err;
+	}
+
+	memset(&ifr, 0, sizeof(ifr));
+	ifr.ifr_flags = IFF_TUN | IFF_NO_PI;
+
+	for (i = 0; i < 256; i++) {
+		sprintf(ifr.ifr_name, "vpn%d", i);
+
+		if (!ioctl(fd, TUNSETIFF, (void *)&ifr))
+			break;
+	}
+
+	if (i == 256) {
+		connman_error("Failed to find available tun device");
+		close(fd);
+		ret = -ENODEV;
+		goto exist_err;
+	}
+
+	data->if_name = (char *)g_strdup(ifr.ifr_name);
+	if (!data->if_name) {
+		connman_error("Failed to allocate memory");
+		close(fd);
+		ret = -ENOMEM;
+		goto exist_err;
+	}
+
+	if (ioctl(fd, TUNSETPERSIST, 1)) {
+		i = -errno;
+		connman_error("Failed to set tun persistent: %s",
+			      strerror(errno));
+		close(fd);
+		ret = i;
+		goto exist_err;
+	}
+
+	close(fd);
+
+	index = connman_inet_ifindex(data->if_name);
+	if (index < 0) {
+		connman_error("Failed to get tun ifindex");
+		stop_vpn(provider);
+		ret = -EIO;
+		goto exist_err;
+	}
+	vpn_provider_set_index(provider, index);
+
+	return 0;
+
+exist_err:
+	return ret;
+}
+
+static int vpn_connect(struct vpn_provider *provider,
+			vpn_provider_connect_cb_t cb,
+			const char *dbus_sender, void *user_data)
+{
+	struct vpn_data *data = vpn_provider_get_data(provider);
+	struct vpn_driver_data *vpn_driver_data;
+	const char *name;
+	int ret = 0;
+	enum vpn_state state = VPN_STATE_UNKNOWN;
+
+	if (data)
+		state = data->state;
+
+	DBG("data %p state %d", data, state);
+
+	switch (state) {
+	case VPN_STATE_UNKNOWN:
+		data = g_try_new0(struct vpn_data, 1);
+		if (!data)
+			return -ENOMEM;
+
+		data->provider = vpn_provider_ref(provider);
+		data->watch = 0;
+		data->flags = 0;
+		data->task = NULL;
+
+		vpn_provider_set_data(provider, data);
+		/* fall through */
+
+	case VPN_STATE_DISCONNECT:
+	case VPN_STATE_IDLE:
+	case VPN_STATE_FAILURE:
+	case VPN_STATE_AUTH_FAILURE:
+		data->state = VPN_STATE_IDLE;
+		break;
+
+	case VPN_STATE_CONNECT:
+		return -EINPROGRESS;
+
+	case VPN_STATE_READY:
+		return -EISCONN;
+	}
+
+	name = vpn_provider_get_driver_name(provider);
+	if (!name)
+		return -EINVAL;
+
+	vpn_driver_data = g_hash_table_lookup(driver_hash, name);
+
+	if (!vpn_driver_data || !vpn_driver_data->vpn_driver) {
+		ret = -EINVAL;
+		goto exist_err;
+	}
+
+	if (vpn_driver_data->vpn_driver->flags != VPN_FLAG_NO_TUN) {
+		ret = vpn_create_tun(provider);
+		if (ret < 0)
+			goto exist_err;
+	}
+
+	data->task = connman_task_create(vpn_driver_data->program);
+
+	if (!data->task) {
+		ret = -ENOMEM;
+		stop_vpn(provider);
+		goto exist_err;
+	}
+
+	if (connman_task_set_notify(data->task, "notify",
+					vpn_notify, provider)) {
+		ret = -ENOMEM;
+		stop_vpn(provider);
+		connman_task_destroy(data->task);
+		data->task = NULL;
+		goto exist_err;
+	}
+
+	ret = vpn_driver_data->vpn_driver->connect(provider, data->task,
+						data->if_name, cb, dbus_sender,
+						user_data);
+	if (ret < 0 && ret != -EINPROGRESS) {
+		stop_vpn(provider);
+		connman_task_destroy(data->task);
+		data->task = NULL;
+		goto exist_err;
+	}
+
+	DBG("%s started with dev %s",
+		vpn_driver_data->provider_driver.name, data->if_name);
+
+	data->state = VPN_STATE_CONNECT;
+
+	return -EINPROGRESS;
+
+exist_err:
+	vpn_provider_set_index(provider, -1);
+	vpn_provider_set_data(provider, NULL);
+	vpn_provider_unref(data->provider);
+	g_free(data->if_name);
+	g_free(data);
+
+	return ret;
+}
+
+static int vpn_probe(struct vpn_provider *provider)
+{
+	return 0;
+}
+
+static int vpn_disconnect(struct vpn_provider *provider)
+{
+	struct vpn_data *data = vpn_provider_get_data(provider);
+	struct vpn_driver_data *vpn_driver_data;
+	const char *name;
+
+	DBG("disconnect provider %p:", provider);
+
+	if (!data)
+		return 0;
+
+	name = vpn_provider_get_driver_name(provider);
+	if (!name)
+		return 0;
+
+	vpn_driver_data = g_hash_table_lookup(driver_hash, name);
+	if (vpn_driver_data->vpn_driver->disconnect)
+		vpn_driver_data->vpn_driver->disconnect(provider);
+
+	if (data->watch != 0) {
+		vpn_provider_unref(provider);
+		vpn_rtnl_remove_watch(data->watch);
+		data->watch = 0;
+	}
+
+	data->state = VPN_STATE_DISCONNECT;
+	connman_task_stop(data->task);
+
+	return 0;
+}
+
+static int vpn_remove(struct vpn_provider *provider)
+{
+	struct vpn_data *data;
+
+	data = vpn_provider_get_data(provider);
+	if (!data)
+		return 0;
+
+	if (data->watch != 0) {
+		vpn_provider_unref(provider);
+		vpn_rtnl_remove_watch(data->watch);
+		data->watch = 0;
+	}
+
+	connman_task_stop(data->task);
+
+	g_usleep(G_USEC_PER_SEC);
+	stop_vpn(provider);
+	return 0;
+}
+
+static int vpn_save(struct vpn_provider *provider, GKeyFile *keyfile)
+{
+	struct vpn_driver_data *vpn_driver_data;
+	const char *name;
+
+	name = vpn_provider_get_driver_name(provider);
+	vpn_driver_data = g_hash_table_lookup(driver_hash, name);
+	if (vpn_driver_data &&
+			vpn_driver_data->vpn_driver->save)
+		return vpn_driver_data->vpn_driver->save(provider, keyfile);
+
+	return 0;
+}
+
+int vpn_register(const char *name, struct vpn_driver *vpn_driver,
+			const char *program)
+{
+	struct vpn_driver_data *data;
+
+	data = g_try_new0(struct vpn_driver_data, 1);
+	if (!data)
+		return -ENOMEM;
+
+	data->name = name;
+	data->program = program;
+
+	data->vpn_driver = vpn_driver;
+
+	data->provider_driver.name = name;
+	data->provider_driver.disconnect = vpn_disconnect;
+	data->provider_driver.connect = vpn_connect;
+	data->provider_driver.probe = vpn_probe;
+	data->provider_driver.remove = vpn_remove;
+	data->provider_driver.save = vpn_save;
+
+	if (!driver_hash)
+		driver_hash = g_hash_table_new_full(g_str_hash,
+							g_str_equal,
+							NULL, g_free);
+
+	if (!driver_hash) {
+		connman_error("driver_hash not initialized for %s", name);
+		g_free(data);
+		return -ENOMEM;
+	}
+
+	g_hash_table_replace(driver_hash, (char *)name, data);
+
+	vpn_provider_driver_register(&data->provider_driver);
+
+	return 0;
+}
+
+void vpn_unregister(const char *name)
+{
+	struct vpn_driver_data *data;
+
+	data = g_hash_table_lookup(driver_hash, name);
+	if (!data)
+		return;
+
+	vpn_provider_driver_unregister(&data->provider_driver);
+
+	g_hash_table_remove(driver_hash, name);
+
+	if (g_hash_table_size(driver_hash) == 0)
+		g_hash_table_destroy(driver_hash);
+}
diff --git a/connman/vpn/plugins/vpn.h b/connman/vpn/plugins/vpn.h
new file mode 100644
index 0000000..bf56728
--- /dev/null
+++ b/connman/vpn/plugins/vpn.h
@@ -0,0 +1,65 @@
+/*
+ *
+ *  ConnMan VPN daemon
+ *
+ *  Copyright (C) 2010,2014  BMW Car IT GmbH.
+ *
+ *  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 __CONNMAN_VPND_VPN_H
+#define __CONNMAN_VPND_VPN_H
+
+#include "../vpn-provider.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define VPN_FLAG_NO_TUN	1
+
+enum vpn_state {
+	VPN_STATE_UNKNOWN       = 0,
+	VPN_STATE_IDLE          = 1,
+	VPN_STATE_CONNECT       = 2,
+	VPN_STATE_READY         = 3,
+	VPN_STATE_DISCONNECT    = 4,
+	VPN_STATE_FAILURE       = 5,
+	VPN_STATE_AUTH_FAILURE  = 6,
+};
+
+struct vpn_driver {
+	int flags;
+	int (*notify) (DBusMessage *msg, struct vpn_provider *provider);
+	int (*connect) (struct vpn_provider *provider,
+			struct connman_task *task, const char *if_name,
+			vpn_provider_connect_cb_t cb, const char *dbus_sender,
+			void *user_data);
+	void (*disconnect) (struct vpn_provider *provider);
+	int (*error_code) (struct vpn_provider *provider, int exit_code);
+	int (*save) (struct vpn_provider *provider, GKeyFile *keyfile);
+};
+
+int vpn_register(const char *name, struct vpn_driver *driver,
+			const char *program);
+void vpn_unregister(const char *provider_name);
+void vpn_died(struct connman_task *task, int exit_code, void *user_data);
+int vpn_set_ifname(struct vpn_provider *provider, const char *ifname);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CONNMAN_VPND_VPN_H */
diff --git a/connman/vpn/plugins/vpnc.c b/connman/vpn/plugins/vpnc.c
new file mode 100644
index 0000000..09674bd
--- /dev/null
+++ b/connman/vpn/plugins/vpnc.c
@@ -0,0 +1,354 @@
+/*
+ *
+ *  ConnMan VPN daemon
+ *
+ *  Copyright (C) 2010,2013  BMW Car IT GmbH.
+ *  Copyright (C) 2010,2012-2013  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 <errno.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <net/if.h>
+
+#include <glib.h>
+
+#define CONNMAN_API_SUBJECT_TO_CHANGE
+#include <connman/plugin.h>
+#include <connman/log.h>
+#include <connman/task.h>
+#include <connman/ipconfig.h>
+#include <connman/dbus.h>
+
+#include "../vpn-provider.h"
+
+#include "vpn.h"
+
+#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
+
+static DBusConnection *connection;
+
+enum {
+	OPT_STRING = 1,
+	OPT_BOOLEAN = 2,
+};
+
+struct {
+	const char *cm_opt;
+	const char *vpnc_opt;
+	const char *vpnc_default;
+	int type;
+	bool cm_save;
+} vpnc_options[] = {
+	{ "Host", "IPSec gateway", NULL, OPT_STRING, true },
+	{ "VPNC.IPSec.ID", "IPSec ID", NULL, OPT_STRING, true },
+	{ "VPNC.IPSec.Secret", "IPSec secret", NULL, OPT_STRING, false },
+	{ "VPNC.Xauth.Username", "Xauth username", NULL, OPT_STRING, false },
+	{ "VPNC.Xauth.Password", "Xauth password", NULL, OPT_STRING, false },
+	{ "VPNC.IKE.Authmode", "IKE Authmode", NULL, OPT_STRING, true },
+	{ "VPNC.IKE.DHGroup", "IKE DH Group", NULL, OPT_STRING, true },
+	{ "VPNC.PFS", "Perfect Forward Secrecy", NULL, OPT_STRING, true },
+	{ "VPNC.Domain", "Domain", NULL, OPT_STRING, true },
+	{ "VPNC.Vendor", "Vendor", NULL, OPT_STRING, true },
+	{ "VPNC.LocalPort", "Local Port", "0", OPT_STRING, true, },
+	{ "VPNC.CiscoPort", "Cisco UDP Encapsulation Port", "0", OPT_STRING,
+									true },
+	{ "VPNC.AppVersion", "Application Version", NULL, OPT_STRING, true },
+	{ "VPNC.NATTMode", "NAT Traversal Mode", "cisco-udp", OPT_STRING,
+									true },
+	{ "VPNC.DPDTimeout", "DPD idle timeout (our side)", NULL, OPT_STRING,
+									true },
+	{ "VPNC.SingleDES", "Enable Single DES", NULL, OPT_BOOLEAN, true },
+	{ "VPNC.NoEncryption", "Enable no encryption", NULL, OPT_BOOLEAN,
+									true },
+};
+
+static int vc_notify(DBusMessage *msg, struct vpn_provider *provider)
+{
+	DBusMessageIter iter, dict;
+	char *address = NULL, *netmask = NULL, *gateway = NULL;
+	struct connman_ipaddress *ipaddress;
+	const char *reason, *key, *value;
+
+	dbus_message_iter_init(msg, &iter);
+
+	dbus_message_iter_get_basic(&iter, &reason);
+	dbus_message_iter_next(&iter);
+
+	if (!provider) {
+		connman_error("No provider found");
+		return VPN_STATE_FAILURE;
+	}
+
+	if (strcmp(reason, "connect"))
+		return VPN_STATE_DISCONNECT;
+
+	dbus_message_iter_recurse(&iter, &dict);
+
+	while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
+		DBusMessageIter entry;
+
+		dbus_message_iter_recurse(&dict, &entry);
+		dbus_message_iter_get_basic(&entry, &key);
+		dbus_message_iter_next(&entry);
+		dbus_message_iter_get_basic(&entry, &value);
+
+		DBG("%s = %s", key, value);
+
+		if (!strcmp(key, "VPNGATEWAY"))
+			gateway = g_strdup(value);
+
+		if (!strcmp(key, "INTERNAL_IP4_ADDRESS"))
+			address = g_strdup(value);
+
+		if (!strcmp(key, "INTERNAL_IP4_NETMASK"))
+			netmask = g_strdup(value);
+
+		if (!strcmp(key, "INTERNAL_IP4_DNS"))
+			vpn_provider_set_nameservers(provider, value);
+
+		if (!strcmp(key, "CISCO_DEF_DOMAIN"))
+			vpn_provider_set_domain(provider, value);
+
+		if (g_str_has_prefix(key, "CISCO_SPLIT_INC") ||
+			g_str_has_prefix(key, "CISCO_IPV6_SPLIT_INC"))
+			vpn_provider_append_route(provider, key, value);
+
+		dbus_message_iter_next(&dict);
+	}
+
+
+	ipaddress = connman_ipaddress_alloc(AF_INET);
+	if (!ipaddress) {
+		g_free(address);
+		g_free(netmask);
+		g_free(gateway);
+
+		return VPN_STATE_FAILURE;
+	}
+
+	connman_ipaddress_set_ipv4(ipaddress, address, netmask, gateway);
+	vpn_provider_set_ipaddress(provider, ipaddress);
+
+	g_free(address);
+	g_free(netmask);
+	g_free(gateway);
+	connman_ipaddress_free(ipaddress);
+
+	return VPN_STATE_CONNECT;
+}
+
+static ssize_t full_write(int fd, const void *buf, size_t len)
+{
+	ssize_t byte_write;
+
+	while (len) {
+		byte_write = write(fd, buf, len);
+		if (byte_write < 0) {
+			connman_error("failed to write config to vpnc: %s\n",
+					strerror(errno));
+			return byte_write;
+		}
+		len -= byte_write;
+		buf += byte_write;
+	}
+
+	return 0;
+}
+
+static ssize_t write_option(int fd, const char *key, const char *value)
+{
+	gchar *buf;
+	ssize_t ret = 0;
+
+	if (key && value) {
+		buf = g_strdup_printf("%s %s\n", key, value);
+		ret = full_write(fd, buf, strlen(buf));
+
+		g_free(buf);
+	}
+
+	return ret;
+}
+
+static ssize_t write_bool_option(int fd, const char *key, const char *value)
+{
+	gchar *buf;
+	ssize_t ret = 0;
+
+	if (key && value) {
+		if (strcasecmp(value, "yes") == 0 ||
+				strcasecmp(value, "true") == 0 ||
+				strcmp(value, "1") == 0) {
+			buf = g_strdup_printf("%s\n", key);
+			ret = full_write(fd, buf, strlen(buf));
+
+			g_free(buf);
+		}
+	}
+
+	return ret;
+}
+
+static int vc_write_config_data(struct vpn_provider *provider, int fd)
+{
+	const char *opt_s;
+	int i;
+
+	for (i = 0; i < (int)ARRAY_SIZE(vpnc_options); i++) {
+		opt_s = vpn_provider_get_string(provider,
+					vpnc_options[i].cm_opt);
+		if (!opt_s)
+			opt_s = vpnc_options[i].vpnc_default;
+
+		if (!opt_s)
+			continue;
+
+		if (vpnc_options[i].type == OPT_STRING) {
+			if (write_option(fd,
+					vpnc_options[i].vpnc_opt, opt_s) < 0)
+				return -EIO;
+		} else if (vpnc_options[i].type == OPT_BOOLEAN) {
+			if (write_bool_option(fd,
+					vpnc_options[i].vpnc_opt, opt_s) < 0)
+				return -EIO;
+		}
+
+	}
+
+	return 0;
+}
+
+static int vc_save(struct vpn_provider *provider, GKeyFile *keyfile)
+{
+	const char *option;
+	int i;
+
+	for (i = 0; i < (int)ARRAY_SIZE(vpnc_options); i++) {
+		if (strncmp(vpnc_options[i].cm_opt, "VPNC.", 5) == 0) {
+
+			if (!vpnc_options[i].cm_save)
+				continue;
+
+			option = vpn_provider_get_string(provider,
+							vpnc_options[i].cm_opt);
+			if (!option)
+				continue;
+
+			g_key_file_set_string(keyfile,
+					vpn_provider_get_save_group(provider),
+					vpnc_options[i].cm_opt, option);
+		}
+	}
+	return 0;
+}
+
+static int vc_connect(struct vpn_provider *provider,
+			struct connman_task *task, const char *if_name,
+			vpn_provider_connect_cb_t cb, const char *dbus_sender,
+			void *user_data)
+{
+	const char *option;
+	int err = 0, fd;
+
+	option = vpn_provider_get_string(provider, "Host");
+	if (!option) {
+		connman_error("Host not set; cannot enable VPN");
+		err = -EINVAL;
+		goto done;
+	}
+	option = vpn_provider_get_string(provider, "VPNC.IPSec.ID");
+	if (!option) {
+		connman_error("Group not set; cannot enable VPN");
+		err = -EINVAL;
+		goto done;
+	}
+
+	connman_task_add_argument(task, "--non-inter", NULL);
+	connman_task_add_argument(task, "--no-detach", NULL);
+
+	connman_task_add_argument(task, "--ifname", if_name);
+	connman_task_add_argument(task, "--ifmode", "tun");
+
+	connman_task_add_argument(task, "--script",
+				SCRIPTDIR "/openconnect-script");
+
+	option = vpn_provider_get_string(provider, "VPNC.Debug");
+	if (option)
+		connman_task_add_argument(task, "--debug", option);
+
+	connman_task_add_argument(task, "-", NULL);
+
+	err = connman_task_run(task, vpn_died, provider,
+				&fd, NULL, NULL);
+	if (err < 0) {
+		connman_error("vpnc failed to start");
+		err = -EIO;
+		goto done;
+	}
+
+	err = vc_write_config_data(provider, fd);
+
+	close(fd);
+
+done:
+	if (cb)
+		cb(provider, user_data, err);
+
+	return err;
+}
+
+static int vc_error_code(struct vpn_provider *provider, int exit_code)
+{
+	switch (exit_code) {
+	case 1:
+		return VPN_PROVIDER_ERROR_CONNECT_FAILED;
+	case 2:
+		return VPN_PROVIDER_ERROR_LOGIN_FAILED;
+	default:
+		return VPN_PROVIDER_ERROR_UNKNOWN;
+	}
+}
+
+static struct vpn_driver vpn_driver = {
+	.notify		= vc_notify,
+	.connect	= vc_connect,
+	.error_code	= vc_error_code,
+	.save		= vc_save,
+};
+
+static int vpnc_init(void)
+{
+	connection = connman_dbus_get_connection();
+
+	return vpn_register("vpnc", &vpn_driver, VPNC);
+}
+
+static void vpnc_exit(void)
+{
+	vpn_unregister("vpnc");
+
+	dbus_connection_unref(connection);
+}
+
+CONNMAN_PLUGIN_DEFINE(vpnc, "vpnc plugin", VERSION,
+	CONNMAN_PLUGIN_PRIORITY_DEFAULT, vpnc_init, vpnc_exit)
diff --git a/connman/vpn/vpn-agent.c b/connman/vpn/vpn-agent.c
new file mode 100644
index 0000000..b0b582b
--- /dev/null
+++ b/connman/vpn/vpn-agent.c
@@ -0,0 +1,145 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2012  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 <string.h>
+
+#include <gdbus.h>
+#include <connman/log.h>
+#include <connman/agent.h>
+#include <vpn/vpn-provider.h>
+
+#include "vpn-agent.h"
+#include "vpn.h"
+
+bool vpn_agent_check_reply_has_dict(DBusMessage *reply)
+{
+	const char *signature = DBUS_TYPE_ARRAY_AS_STRING
+		DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+		DBUS_TYPE_STRING_AS_STRING
+		DBUS_TYPE_VARIANT_AS_STRING
+		DBUS_DICT_ENTRY_END_CHAR_AS_STRING;
+
+	if (dbus_message_has_signature(reply, signature))
+		return true;
+
+	connman_warn("Reply %s to %s from %s has wrong signature %s",
+			signature,
+			dbus_message_get_interface(reply),
+			dbus_message_get_sender(reply),
+			dbus_message_get_signature(reply));
+
+	return false;
+}
+
+static void request_input_append_name(DBusMessageIter *iter, void *user_data)
+{
+	struct vpn_provider *provider = user_data;
+	const char *str = "string";
+
+	connman_dbus_dict_append_basic(iter, "Type",
+				DBUS_TYPE_STRING, &str);
+	str = "informational";
+	connman_dbus_dict_append_basic(iter, "Requirement",
+				DBUS_TYPE_STRING, &str);
+
+	str = vpn_provider_get_name(provider);
+	connman_dbus_dict_append_basic(iter, "Value",
+				DBUS_TYPE_STRING, &str);
+}
+
+static void request_input_append_host(DBusMessageIter *iter, void *user_data)
+{
+	struct vpn_provider *provider = user_data;
+	const char *str = "string";
+
+	connman_dbus_dict_append_basic(iter, "Type",
+				DBUS_TYPE_STRING, &str);
+	str = "informational";
+	connman_dbus_dict_append_basic(iter, "Requirement",
+				DBUS_TYPE_STRING, &str);
+
+	str = vpn_provider_get_host(provider);
+	connman_dbus_dict_append_basic(iter, "Value",
+				DBUS_TYPE_STRING, &str);
+}
+
+void vpn_agent_append_host_and_name(DBusMessageIter *iter,
+				struct vpn_provider *provider)
+{
+	connman_dbus_dict_append_dict(iter, "Host",
+				request_input_append_host,
+				provider);
+
+	connman_dbus_dict_append_dict(iter, "Name",
+				request_input_append_name,
+				provider);
+}
+
+struct user_info_data {
+	struct vpn_provider *provider;
+	const char *username_str;
+};
+
+static void request_input_append_user_info(DBusMessageIter *iter,
+						void *user_data)
+{
+	struct user_info_data *data = user_data;
+	struct vpn_provider *provider = data->provider;
+	const char *str = "string";
+
+	connman_dbus_dict_append_basic(iter, "Type",
+				DBUS_TYPE_STRING, &str);
+	str = "mandatory";
+	connman_dbus_dict_append_basic(iter, "Requirement",
+				DBUS_TYPE_STRING, &str);
+
+	if (data->username_str) {
+		str = vpn_provider_get_string(provider, data->username_str);
+		if (str)
+			connman_dbus_dict_append_basic(iter, "Value",
+						DBUS_TYPE_STRING, &str);
+	}
+}
+
+void vpn_agent_append_user_info(DBusMessageIter *iter,
+				struct vpn_provider *provider,
+				const char *username_str)
+{
+	struct user_info_data data = {
+		.provider = provider,
+		.username_str = username_str
+	};
+
+	connman_dbus_dict_append_dict(iter, "Username",
+				request_input_append_user_info,
+				&data);
+
+	data.username_str = NULL;
+	connman_dbus_dict_append_dict(iter, "Password",
+				request_input_append_user_info,
+				&data);
+}
diff --git a/connman/vpn/vpn-agent.h b/connman/vpn/vpn-agent.h
new file mode 100644
index 0000000..c7328d7
--- /dev/null
+++ b/connman/vpn/vpn-agent.h
@@ -0,0 +1,46 @@
+/*
+ *
+ *  ConnMan VPN daemon
+ *
+ *  Copyright (C) 2012  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 __VPN_AGENT_H
+#define __VPN_AGENT_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * SECTION:agent
+ * @title: Agent premitives
+ * @short_description: Functions for interaction with agent
+ */
+
+void vpn_agent_append_host_and_name(DBusMessageIter *iter,
+				struct vpn_provider *provider);
+bool vpn_agent_check_reply_has_dict(DBusMessage *reply);
+void vpn_agent_append_user_info(DBusMessageIter *iter,
+				struct vpn_provider *provider,
+				const char *username_str);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __VPN_AGENT_H */
diff --git a/connman/vpn/vpn-config.c b/connman/vpn/vpn-config.c
new file mode 100644
index 0000000..293c64e
--- /dev/null
+++ b/connman/vpn/vpn-config.c
@@ -0,0 +1,581 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2012-2013  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 <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <sys/vfs.h>
+#include <sys/inotify.h>
+#include <glib.h>
+
+#include <connman/log.h>
+#include "../src/connman.h"
+
+#include "vpn.h"
+
+enum what {
+	REMOVE = 1,
+	ADD = 2,
+};
+
+struct vpn_config_provider {
+	char *provider_identifier;
+	char *ident;
+	char *name;
+	char *type;
+	char *host;
+	char *domain;
+	char *networks;
+	GHashTable *setting_strings;
+
+	char *config_ident; /* file prefix */
+	char *config_entry; /* entry name */
+};
+
+struct vpn_config {
+	char *ident;
+	char *name;
+	char *description;
+	GHashTable *provider_table;
+};
+
+static GHashTable *config_table = NULL;
+
+static bool cleanup = false;
+
+/* Definition of possible strings in the .config files */
+#define CONFIG_KEY_NAME                "Name"
+#define CONFIG_KEY_DESC                "Description"
+
+static const char *config_possible_keys[] = {
+	CONFIG_KEY_NAME,
+	CONFIG_KEY_DESC,
+	NULL,
+};
+
+static void unregister_config(gpointer data)
+{
+	struct vpn_config *config = data;
+
+	connman_info("Removing configuration %s", config->ident);
+
+	g_hash_table_destroy(config->provider_table);
+
+	g_free(config->description);
+	g_free(config->name);
+	g_free(config->ident);
+	g_free(config);
+}
+
+static void unregister_provider(gpointer data)
+{
+	struct vpn_config_provider *config_provider = data;
+	struct vpn_provider *provider;
+	char *provider_id;
+
+	if (cleanup)
+		goto free_only;
+
+	provider_id = config_provider->provider_identifier;
+
+	connman_info("Removing provider configuration %s provider %s",
+				config_provider->ident, provider_id);
+
+	provider = __vpn_provider_lookup(provider_id);
+	if (provider)
+		__vpn_provider_delete(provider);
+	else {
+		if (!__connman_storage_remove_provider(provider_id))
+			DBG("Could not remove all files for provider %s",
+								provider_id);
+	}
+
+free_only:
+	g_free(config_provider->ident);
+	g_free(config_provider->type);
+	g_free(config_provider->name);
+	g_free(config_provider->host);
+	g_free(config_provider->domain);
+	g_free(config_provider->networks);
+	g_hash_table_destroy(config_provider->setting_strings);
+	g_free(config_provider->provider_identifier);
+	g_free(config_provider->config_ident);
+	g_free(config_provider->config_entry);
+	g_free(config_provider);
+}
+
+static int set_string(struct vpn_config_provider *config_provider,
+					const char *key, const char *value)
+{
+	DBG("provider %p key %s value %s", config_provider, key, value);
+
+	if (g_str_equal(key, "Type")) {
+		g_free(config_provider->type);
+		config_provider->type = g_strdup(value);
+	} else if (g_str_equal(key, "Name")) {
+		g_free(config_provider->name);
+		config_provider->name = g_strdup(value);
+	} else if (g_str_equal(key, "Host")) {
+		g_free(config_provider->host);
+		config_provider->host = g_strdup(value);
+	} else if (g_str_equal(key, "Domain")) {
+		g_free(config_provider->domain);
+		config_provider->domain = g_strdup(value);
+	} else if (g_str_equal(key, "Networks")) {
+		g_free(config_provider->networks);
+		config_provider->networks = g_strdup(value);
+	}
+
+	g_hash_table_replace(config_provider->setting_strings,
+					g_strdup(key), g_strdup(value));
+	return 0;
+}
+
+static const char *get_string(struct vpn_config_provider *config_provider,
+							const char *key)
+{
+	DBG("provider %p key %s", config_provider, key);
+
+	if (g_str_equal(key, "Type"))
+		return config_provider->type;
+	else if (g_str_equal(key, "Name"))
+		return config_provider->name;
+	else if (g_str_equal(key, "Host"))
+		return config_provider->host;
+	else if (g_str_equal(key, "Domain"))
+		return config_provider->domain;
+	else if (g_str_equal(key, "Networks"))
+		return config_provider->networks;
+
+	return g_hash_table_lookup(config_provider->setting_strings, key);
+}
+
+static void add_keys(struct vpn_config_provider *config_provider,
+			GKeyFile *keyfile, const char *group)
+{
+	char **avail_keys;
+	gsize nb_avail_keys, i;
+
+	avail_keys = g_key_file_get_keys(keyfile, group, &nb_avail_keys, NULL);
+	if (!avail_keys)
+		return;
+
+	for (i = 0 ; i < nb_avail_keys; i++) {
+		char *value = g_key_file_get_value(keyfile, group,
+						avail_keys[i], NULL);
+		if (!value) {
+			connman_warn("Cannot find value for %s",
+							avail_keys[i]);
+			continue;
+		}
+
+		set_string(config_provider, avail_keys[i], value);
+		g_free(value);
+	}
+
+	g_strfreev(avail_keys);
+}
+
+static int load_provider(GKeyFile *keyfile, const char *group,
+				struct vpn_config *config, enum what action)
+{
+	struct vpn_config_provider *config_provider;
+	const char *ident, *host, *domain;
+	int err;
+
+	/* Strip off "provider_" prefix */
+	ident = group + 9;
+
+	if (strlen(ident) < 1)
+		return -EINVAL;
+
+	config_provider = g_hash_table_lookup(config->provider_table, ident);
+	if (config_provider)
+		return -EALREADY;
+
+	config_provider = g_try_new0(struct vpn_config_provider, 1);
+	if (!config_provider)
+		return -ENOMEM;
+
+	config_provider->ident = g_strdup(ident);
+
+	config_provider->setting_strings = g_hash_table_new_full(g_str_hash,
+						g_str_equal, g_free, g_free);
+
+	add_keys(config_provider, keyfile, group);
+
+	host = get_string(config_provider, "Host");
+	domain = get_string(config_provider, "Domain");
+	if (host && domain) {
+		char *id = __vpn_provider_create_identifier(host, domain);
+
+		struct vpn_provider *provider;
+		provider = __vpn_provider_lookup(id);
+		if (provider) {
+			if (action == REMOVE) {
+				__vpn_provider_delete(provider);
+				err = 0;
+			} else {
+				connman_warn("Provider configuration %s "
+						"already exist", id);
+				err = -EALREADY;
+			}
+
+			g_free(id);
+			goto err;
+		}
+
+		config_provider->provider_identifier = id;
+
+		DBG("provider identifier %s", id);
+	} else {
+		DBG("invalid values host %s domain %s", host, domain);
+		err = -EINVAL;
+		goto err;
+	}
+
+	config_provider->config_ident = g_strdup(config->ident);
+	config_provider->config_entry = g_strdup_printf("provider_%s",
+						config_provider->ident);
+
+	g_hash_table_insert(config->provider_table,
+				config_provider->ident,	config_provider);
+
+	err = __vpn_provider_create_from_config(
+					config_provider->setting_strings,
+					config_provider->config_ident,
+					config_provider->config_entry);
+	if (err != 0) {
+		DBG("Cannot create provider from config file (%d/%s)",
+			-err, strerror(-err));
+		goto err;
+	}
+
+	connman_info("Added provider configuration %s",
+						config_provider->ident);
+	return 0;
+
+err:
+	g_free(config_provider->ident);
+	g_free(config_provider->type);
+	g_free(config_provider->name);
+	g_free(config_provider->host);
+	g_free(config_provider->domain);
+	g_free(config_provider->networks);
+	g_hash_table_destroy(config_provider->setting_strings);
+	g_free(config_provider);
+
+	return err;
+}
+
+static void check_keys(GKeyFile *keyfile, const char *group,
+			const char **possible_keys)
+{
+	char **avail_keys;
+	gsize nb_avail_keys, i, j;
+
+	avail_keys = g_key_file_get_keys(keyfile, group, &nb_avail_keys, NULL);
+	if (!avail_keys)
+		return;
+
+	for (i = 0 ; i < nb_avail_keys; i++) {
+		for (j = 0; possible_keys[j] ; j++)
+			if (g_strcmp0(avail_keys[i], possible_keys[j]) == 0)
+				break;
+
+		if (!possible_keys[j])
+			connman_warn("Unknown configuration key %s in [%s]",
+					avail_keys[i], group);
+	}
+
+	g_strfreev(avail_keys);
+}
+
+static int load_config(struct vpn_config *config, char *path, enum what action)
+{
+	GKeyFile *keyfile;
+	gsize length;
+	char **groups;
+	char *str;
+	bool found = false;
+	int i;
+
+	DBG("config %p", config);
+
+	keyfile = __connman_storage_load_provider_config(config->ident);
+	if (!keyfile)
+		return -EIO;
+
+	/* Verify keys validity of the global section */
+	check_keys(keyfile, "global", config_possible_keys);
+
+	str = __vpn_config_get_string(keyfile, "global", CONFIG_KEY_NAME, NULL);
+	if (str) {
+		g_free(config->name);
+		config->name = str;
+	}
+
+	str = __vpn_config_get_string(keyfile, "global", CONFIG_KEY_DESC, NULL);
+	if (str) {
+		g_free(config->description);
+		config->description = str;
+	}
+
+	groups = g_key_file_get_groups(keyfile, &length);
+
+	for (i = 0; groups[i]; i++) {
+		if (g_str_has_prefix(groups[i], "provider_")) {
+			int ret = load_provider(keyfile, groups[i], config,
+						action);
+			if (ret == 0 || ret == -EALREADY)
+				found = true;
+		}
+	}
+
+	if (!found)
+		connman_warn("Config file %s/%s.config does not contain any "
+			"configuration that can be provisioned!",
+			path, config->ident);
+
+	g_strfreev(groups);
+
+	g_key_file_free(keyfile);
+
+	return 0;
+}
+
+static struct vpn_config *create_config(const char *ident)
+{
+	struct vpn_config *config;
+
+	DBG("ident %s", ident);
+
+	if (g_hash_table_lookup(config_table, ident))
+		return NULL;
+
+	config = g_try_new0(struct vpn_config, 1);
+	if (!config)
+		return NULL;
+
+	config->ident = g_strdup(ident);
+
+	config->provider_table = g_hash_table_new_full(g_str_hash, g_str_equal,
+						NULL, unregister_provider);
+
+	g_hash_table_insert(config_table, config->ident, config);
+
+	connman_info("Adding configuration %s", config->ident);
+
+	return config;
+}
+
+static bool validate_ident(const char *ident)
+{
+	unsigned int i;
+
+	if (!ident)
+		return false;
+
+	for (i = 0; i < strlen(ident); i++)
+		if (!g_ascii_isprint(ident[i]))
+			return false;
+
+	return true;
+}
+
+static char *get_dir(void)
+{
+	return g_strdup_printf("%s", VPN_STORAGEDIR);
+}
+
+static int read_configs(void)
+{
+	GDir *dir;
+	char *path = get_dir();
+
+	DBG("path %s", path);
+
+	dir = g_dir_open(path, 0, NULL);
+	if (dir) {
+		const gchar *file;
+
+		while ((file = g_dir_read_name(dir))) {
+			GString *str;
+			gchar *ident;
+
+			if (!g_str_has_suffix(file, ".config"))
+				continue;
+
+			ident = g_strrstr(file, ".config");
+			if (!ident)
+				continue;
+
+			str = g_string_new_len(file, ident - file);
+			if (!str)
+				continue;
+
+			ident = g_string_free(str, FALSE);
+
+			if (validate_ident(ident)) {
+				struct vpn_config *config;
+
+				config = create_config(ident);
+				if (config)
+					load_config(config, path, ADD);
+			} else {
+				connman_error("Invalid config ident %s", ident);
+			}
+			g_free(ident);
+		}
+
+		g_dir_close(dir);
+	}
+
+	g_free(path);
+
+	return 0;
+}
+
+static void config_notify_handler(struct inotify_event *event,
+                                        const char *ident)
+{
+	char *ext;
+
+	if (!ident)
+		return;
+
+	if (!g_str_has_suffix(ident, ".config"))
+		return;
+
+	ext = g_strrstr(ident, ".config");
+	if (!ext)
+		return;
+
+	*ext = '\0';
+
+	if (!validate_ident(ident)) {
+		connman_error("Invalid config ident %s", ident);
+		return;
+	}
+
+	if (event->mask & IN_CREATE)
+		return;
+
+	if (event->mask & IN_DELETE) {
+		g_hash_table_remove(config_table, ident);
+		return;
+	}
+
+	if (event->mask & IN_MODIFY) {
+		struct vpn_config *config;
+		char *path = get_dir();
+
+		config = g_hash_table_lookup(config_table, ident);
+		if (config) {
+			g_hash_table_remove_all(config->provider_table);
+			load_config(config, path, REMOVE);
+
+			/* Re-scan the config file for any changes */
+			g_hash_table_remove_all(config->provider_table);
+			load_config(config, path, ADD);
+		} else {
+			/*
+			 * Inotify will send create event followed by modify
+			 * event for any config file that is copied to
+			 * monitored directory. So in practice we should just
+			 * ignore the create event and trust only the modify
+			 * one in order to avoid create/remove/create loop
+			 */
+			config = create_config(ident);
+			if (config)
+				load_config(config, path, ADD);
+		}
+
+		g_free(path);
+	}
+}
+
+int __vpn_config_init(void)
+{
+	char *dir = get_dir();
+
+	DBG("");
+
+	config_table = g_hash_table_new_full(g_str_hash, g_str_equal,
+						NULL, unregister_config);
+
+	connman_inotify_register(dir, config_notify_handler);
+
+	g_free(dir);
+
+	return read_configs();
+}
+
+void __vpn_config_cleanup(void)
+{
+	char *dir = get_dir();
+
+	DBG("");
+
+	cleanup = true;
+
+	connman_inotify_unregister(dir, config_notify_handler);
+
+	g_free(dir);
+
+	g_hash_table_destroy(config_table);
+	config_table = NULL;
+
+	cleanup = false;
+}
+
+char *__vpn_config_get_string(GKeyFile *key_file,
+	const char *group_name, const char *key, GError **error)
+{
+	char *str = g_key_file_get_string(key_file, group_name, key, error);
+	if (!str)
+		return NULL;
+
+	return g_strchomp(str);
+}
+
+char **__vpn_config_get_string_list(GKeyFile *key_file,
+	const char *group_name, const char *key, gsize *length, GError **error)
+{
+	char **p;
+	char **strlist = g_key_file_get_string_list(key_file, group_name, key,
+		length, error);
+	if (!strlist)
+		return NULL;
+
+	p = strlist;
+	while (*p) {
+		*p = g_strstrip(*p);
+		p++;
+	}
+
+	return strlist;
+}
diff --git a/connman/vpn/vpn-dbus.conf b/connman/vpn/vpn-dbus.conf
new file mode 100644
index 0000000..0f0c8da
--- /dev/null
+++ b/connman/vpn/vpn-dbus.conf
@@ -0,0 +1,15 @@
+<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
+ "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
+<busconfig>
+    <policy user="root">
+        <allow own="net.connman.vpn"/>
+        <allow send_destination="net.connman.vpn"/>
+        <allow send_interface="net.connman.vpn.Agent"/>
+    </policy>
+    <policy at_console="true">
+        <allow send_destination="net.connman.vpn"/>
+    </policy>
+    <policy context="default">
+        <deny send_destination="net.connman.vpn"/>
+    </policy>
+</busconfig>
diff --git a/connman/vpn/vpn-ipconfig.c b/connman/vpn/vpn-ipconfig.c
new file mode 100644
index 0000000..c096fa3
--- /dev/null
+++ b/connman/vpn/vpn-ipconfig.c
@@ -0,0 +1,453 @@
+/*
+ *
+ *  ConnMan VPN daemon
+ *
+ *  Copyright (C) 2012  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 <stdio.h>
+#include <net/if.h>
+#include <net/if_arp.h>
+#include <linux/if_link.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <arpa/inet.h>
+
+#ifndef IFF_LOWER_UP
+#define IFF_LOWER_UP	0x10000
+#endif
+
+#include <gdbus.h>
+
+#include "../src/connman.h"
+
+#include "vpn.h"
+
+struct vpn_ipconfig {
+	int refcount;
+	int index;
+	int family;
+	bool enabled;
+	struct connman_ipaddress *address;
+	struct connman_ipaddress *system;
+};
+
+struct vpn_ipdevice {
+	int index;
+	char *ifname;
+	unsigned short type;
+	unsigned int flags;
+	char *address;
+	uint16_t mtu;
+
+	GSList *address_list;
+	char *ipv4_gateway;
+	char *ipv6_gateway;
+
+	char *pac;
+};
+
+static GHashTable *ipdevice_hash = NULL;
+
+struct connman_ipaddress *
+__vpn_ipconfig_get_address(struct vpn_ipconfig *ipconfig)
+{
+	if (!ipconfig)
+		return NULL;
+
+	return ipconfig->address;
+}
+
+const char *__vpn_ipconfig_get_peer(struct vpn_ipconfig *ipconfig)
+{
+	if (!ipconfig->address)
+		return NULL;
+
+	return ipconfig->address->peer;
+}
+
+unsigned short __vpn_ipconfig_get_type_from_index(int index)
+{
+	struct vpn_ipdevice *ipdevice;
+
+	ipdevice = g_hash_table_lookup(ipdevice_hash, GINT_TO_POINTER(index));
+	if (!ipdevice)
+		return ARPHRD_VOID;
+
+	return ipdevice->type;
+}
+
+unsigned int __vpn_ipconfig_get_flags_from_index(int index)
+{
+	struct vpn_ipdevice *ipdevice;
+
+	ipdevice = g_hash_table_lookup(ipdevice_hash, GINT_TO_POINTER(index));
+	if (!ipdevice)
+		return 0;
+
+	return ipdevice->flags;
+}
+
+void __vpn_ipconfig_foreach(void (*function) (int index,
+					void *user_data), void *user_data)
+{
+	GList *list, *keys;
+
+	keys = g_hash_table_get_keys(ipdevice_hash);
+	if (!keys)
+		return;
+
+	for (list = g_list_first(keys); list; list = g_list_next(list)) {
+		int index = GPOINTER_TO_INT(list->data);
+
+		function(index, user_data);
+	}
+
+	g_list_free(keys);
+}
+
+void __vpn_ipconfig_set_local(struct vpn_ipconfig *ipconfig,
+							const char *address)
+{
+	if (!ipconfig->address)
+		return;
+
+	g_free(ipconfig->address->local);
+	ipconfig->address->local = g_strdup(address);
+}
+
+const char *__vpn_ipconfig_get_local(struct vpn_ipconfig *ipconfig)
+{
+	if (!ipconfig->address)
+		return NULL;
+
+	return ipconfig->address->local;
+}
+
+void __vpn_ipconfig_set_peer(struct vpn_ipconfig *ipconfig,
+							const char *address)
+{
+	if (!ipconfig->address)
+		return;
+
+	g_free(ipconfig->address->peer);
+	ipconfig->address->peer = g_strdup(address);
+}
+
+void __vpn_ipconfig_set_broadcast(struct vpn_ipconfig *ipconfig,
+					const char *broadcast)
+{
+	if (!ipconfig->address)
+		return;
+
+	g_free(ipconfig->address->broadcast);
+	ipconfig->address->broadcast = g_strdup(broadcast);
+}
+
+void __vpn_ipconfig_set_gateway(struct vpn_ipconfig *ipconfig,
+							const char *gateway)
+{
+	DBG("");
+
+	if (!ipconfig->address)
+		return;
+	g_free(ipconfig->address->gateway);
+	ipconfig->address->gateway = g_strdup(gateway);
+}
+
+const char *
+__vpn_ipconfig_get_gateway(struct vpn_ipconfig *ipconfig)
+{
+	if (!ipconfig->address)
+		return NULL;
+
+	return ipconfig->address->gateway;
+}
+
+void __vpn_ipconfig_set_prefixlen(struct vpn_ipconfig *ipconfig,
+					unsigned char prefixlen)
+{
+	if (!ipconfig->address)
+		return;
+
+	ipconfig->address->prefixlen = prefixlen;
+}
+
+unsigned char
+__vpn_ipconfig_get_prefixlen(struct vpn_ipconfig *ipconfig)
+{
+	if (!ipconfig->address)
+		return 0;
+
+	return ipconfig->address->prefixlen;
+}
+
+int __vpn_ipconfig_address_add(struct vpn_ipconfig *ipconfig, int family)
+{
+	DBG("ipconfig %p family %d", ipconfig, family);
+
+	if (!ipconfig)
+		return -EINVAL;
+
+	if (family == AF_INET)
+		return connman_inet_set_address(ipconfig->index,
+						ipconfig->address);
+	else if (family == AF_INET6)
+		return connman_inet_set_ipv6_address(ipconfig->index,
+							ipconfig->address);
+
+	return 0;
+}
+
+int __vpn_ipconfig_gateway_add(struct vpn_ipconfig *ipconfig, int family)
+{
+	DBG("ipconfig %p family %d", ipconfig, family);
+
+	if (!ipconfig || !ipconfig->address)
+		return -EINVAL;
+
+	DBG("family %d gw %s peer %s", family,
+		ipconfig->address->gateway, ipconfig->address->peer);
+
+	if (family == AF_INET)
+		connman_inet_add_host_route(ipconfig->index,
+					ipconfig->address->gateway,
+					ipconfig->address->peer);
+	else if (family == AF_INET6)
+		connman_inet_add_ipv6_host_route(ipconfig->index,
+						ipconfig->address->gateway,
+						ipconfig->address->peer);
+	else
+		return -EINVAL;
+
+	return 0;
+}
+
+void __vpn_ipconfig_unref_debug(struct vpn_ipconfig *ipconfig,
+				const char *file, int line, const char *caller)
+{
+	if (!ipconfig)
+		return;
+
+	DBG("%p ref %d by %s:%d:%s()", ipconfig, ipconfig->refcount - 1,
+		file, line, caller);
+
+	if (__sync_fetch_and_sub(&ipconfig->refcount, 1) != 1)
+		return;
+
+	connman_ipaddress_free(ipconfig->system);
+	connman_ipaddress_free(ipconfig->address);
+	g_free(ipconfig);
+}
+
+static struct vpn_ipconfig *create_ipv6config(int index)
+{
+	struct vpn_ipconfig *ipv6config;
+
+	DBG("index %d", index);
+
+	ipv6config = g_try_new0(struct vpn_ipconfig, 1);
+	if (!ipv6config)
+		return NULL;
+
+	ipv6config->refcount = 1;
+
+	ipv6config->index = index;
+	ipv6config->enabled = false;
+	ipv6config->family = AF_INET6;
+
+	ipv6config->address = connman_ipaddress_alloc(AF_INET6);
+	if (!ipv6config->address) {
+		g_free(ipv6config);
+		return NULL;
+	}
+
+	ipv6config->system = connman_ipaddress_alloc(AF_INET6);
+
+	DBG("ipconfig %p", ipv6config);
+
+	return ipv6config;
+}
+
+struct vpn_ipconfig *__vpn_ipconfig_create(int index, int family)
+{
+	struct vpn_ipconfig *ipconfig;
+
+	if (family == AF_INET6)
+		return create_ipv6config(index);
+
+	DBG("index %d", index);
+
+	ipconfig = g_try_new0(struct vpn_ipconfig, 1);
+	if (!ipconfig)
+		return NULL;
+
+	ipconfig->refcount = 1;
+
+	ipconfig->index = index;
+	ipconfig->enabled = false;
+	ipconfig->family = family;
+
+	ipconfig->address = connman_ipaddress_alloc(AF_INET);
+	if (!ipconfig->address) {
+		g_free(ipconfig);
+		return NULL;
+	}
+
+	ipconfig->system = connman_ipaddress_alloc(AF_INET);
+
+	DBG("ipconfig %p", ipconfig);
+
+	return ipconfig;
+}
+
+void __vpn_ipconfig_set_index(struct vpn_ipconfig *ipconfig, int index)
+{
+	ipconfig->index = index;
+}
+
+static const char *type2str(unsigned short type)
+{
+	switch (type) {
+	case ARPHRD_ETHER:
+		return "ETHER";
+	case ARPHRD_LOOPBACK:
+		return "LOOPBACK";
+	case ARPHRD_PPP:
+		return "PPP";
+	case ARPHRD_NONE:
+		return "NONE";
+	case ARPHRD_VOID:
+		return "VOID";
+	}
+
+	return "";
+}
+
+void __vpn_ipconfig_newlink(int index, unsigned short type,
+				unsigned int flags,
+				const char *address,
+				unsigned short mtu,
+				struct rtnl_link_stats *stats)
+{
+	struct vpn_ipdevice *ipdevice;
+	GString *str;
+
+	if (type == ARPHRD_LOOPBACK)
+		return;
+
+	ipdevice = g_hash_table_lookup(ipdevice_hash, GINT_TO_POINTER(index));
+	if (ipdevice)
+		goto update;
+
+	ipdevice = g_try_new0(struct vpn_ipdevice, 1);
+	if (!ipdevice)
+		return;
+
+	ipdevice->index = index;
+	ipdevice->ifname = connman_inet_ifname(index);
+	ipdevice->type = type;
+
+	ipdevice->address = g_strdup(address);
+
+	g_hash_table_insert(ipdevice_hash, GINT_TO_POINTER(index), ipdevice);
+
+	connman_info("%s {create} index %d type %d <%s>", ipdevice->ifname,
+						index, type, type2str(type));
+
+update:
+	ipdevice->mtu = mtu;
+
+	if (flags == ipdevice->flags)
+		return;
+
+	ipdevice->flags = flags;
+
+	str = g_string_new(NULL);
+	if (!str)
+		return;
+
+	if (flags & IFF_UP)
+		g_string_append(str, "UP");
+	else
+		g_string_append(str, "DOWN");
+
+	if (flags & IFF_RUNNING)
+		g_string_append(str, ",RUNNING");
+
+	if (flags & IFF_LOWER_UP)
+		g_string_append(str, ",LOWER_UP");
+
+	connman_info("%s {update} flags %u <%s>", ipdevice->ifname,
+							flags, str->str);
+
+	g_string_free(str, TRUE);
+}
+
+void __vpn_ipconfig_dellink(int index, struct rtnl_link_stats *stats)
+{
+	struct vpn_ipdevice *ipdevice;
+
+	DBG("index %d", index);
+
+	ipdevice = g_hash_table_lookup(ipdevice_hash, GINT_TO_POINTER(index));
+	if (!ipdevice)
+		return;
+
+	g_hash_table_remove(ipdevice_hash, GINT_TO_POINTER(index));
+}
+
+static void free_ipdevice(gpointer data)
+{
+	struct vpn_ipdevice *ipdevice = data;
+
+	connman_info("%s {remove} index %d", ipdevice->ifname,
+							ipdevice->index);
+
+	g_free(ipdevice->ipv4_gateway);
+	g_free(ipdevice->ipv6_gateway);
+	g_free(ipdevice->pac);
+
+	g_free(ipdevice->address);
+
+	g_free(ipdevice->ifname);
+	g_free(ipdevice);
+}
+
+int __vpn_ipconfig_init(void)
+{
+	DBG("");
+
+	ipdevice_hash = g_hash_table_new_full(g_direct_hash, g_direct_equal,
+							NULL, free_ipdevice);
+
+	return 0;
+}
+
+void __vpn_ipconfig_cleanup(void)
+{
+	DBG("");
+
+	g_hash_table_destroy(ipdevice_hash);
+	ipdevice_hash = NULL;
+}
diff --git a/connman/vpn/vpn-manager.c b/connman/vpn/vpn-manager.c
new file mode 100644
index 0000000..021d625
--- /dev/null
+++ b/connman/vpn/vpn-manager.c
@@ -0,0 +1,189 @@
+/*
+ *
+ *  ConnMan VPN daemon
+ *
+ *  Copyright (C) 2012-2013  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 <gdbus.h>
+#include <connman/log.h>
+#include <connman/agent.h>
+
+#include "../src/connman.h"
+
+#include "vpn.h"
+#include "connman/vpn-dbus.h"
+
+static int vpn_connect_count;
+static DBusConnection *connection;
+
+static DBusMessage *create(DBusConnection *conn, DBusMessage *msg, void *data)
+{
+	int err;
+
+	DBG("conn %p", conn);
+
+	err = __vpn_provider_create(msg);
+	if (err < 0) {
+		if (err == -EINPROGRESS) {
+			connman_error("Invalid return code (%d) "
+					"from connect", err);
+			err = -EINVAL;
+		}
+
+		return __connman_error_failed(msg, -err);
+	}
+
+	return NULL;
+}
+
+static DBusMessage *remove(DBusConnection *conn, DBusMessage *msg, void *data)
+{
+	const char *path;
+	int err;
+
+	dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
+							DBUS_TYPE_INVALID);
+
+	DBG("conn %p path %s", conn, path);
+
+	err = __vpn_provider_remove(path);
+	if (err < 0)
+		return __connman_error_failed(msg, -err);
+
+	return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+}
+
+static DBusMessage *get_connections(DBusConnection *conn, DBusMessage *msg,
+								void *data)
+{
+	DBusMessage *reply;
+
+	DBG("conn %p", conn);
+
+	reply = __vpn_provider_get_connections(msg);
+	if (!reply)
+		return __connman_error_failed(msg, EINVAL);
+
+	return reply;
+}
+
+static DBusMessage *register_agent(DBusConnection *conn,
+					DBusMessage *msg, void *data)
+{
+	const char *sender, *path;
+	int err;
+
+	DBG("conn %p", conn);
+
+	sender = dbus_message_get_sender(msg);
+
+	dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
+							DBUS_TYPE_INVALID);
+
+	err = connman_agent_register(sender, path);
+	if (err < 0)
+		return __connman_error_failed(msg, -err);
+
+	return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+}
+
+static DBusMessage *unregister_agent(DBusConnection *conn,
+					DBusMessage *msg, void *data)
+{
+	const char *sender, *path;
+	int err;
+
+	DBG("conn %p", conn);
+
+	sender = dbus_message_get_sender(msg);
+
+	dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
+							DBUS_TYPE_INVALID);
+
+	err = connman_agent_unregister(sender, path);
+	if (err < 0)
+		return __connman_error_failed(msg, -err);
+
+	return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+}
+
+static const GDBusMethodTable manager_methods[] = {
+	{ GDBUS_ASYNC_METHOD("Create",
+			GDBUS_ARGS({ "properties", "a{sv}" }),
+			GDBUS_ARGS({ "path", "o" }),
+			create) },
+	{ GDBUS_ASYNC_METHOD("Remove",
+			GDBUS_ARGS({ "identifier", "o" }), NULL,
+			remove) },
+	{ GDBUS_METHOD("GetConnections", NULL,
+			GDBUS_ARGS({ "connections", "a(oa{sv})" }),
+			get_connections) },
+	{ GDBUS_METHOD("RegisterAgent",
+			GDBUS_ARGS({ "path", "o" }), NULL,
+			register_agent) },
+	{ GDBUS_METHOD("UnregisterAgent",
+			GDBUS_ARGS({ "path", "o" }), NULL,
+			unregister_agent) },
+	{ },
+};
+
+static const GDBusSignalTable manager_signals[] = {
+	{ GDBUS_SIGNAL("ConnectionAdded",
+			GDBUS_ARGS({ "identifier", "o" },
+				{ "properties", "a{sv}" })) },
+	{ GDBUS_SIGNAL("ConnectionRemoved",
+			GDBUS_ARGS({ "identifier", "o" })) },
+	{ },
+};
+
+int __vpn_manager_init(void)
+{
+	DBG("");
+
+	connection = connman_dbus_get_connection();
+	if (!connection)
+		return -1;
+
+	g_dbus_register_interface(connection, VPN_MANAGER_PATH,
+					VPN_MANAGER_INTERFACE,
+					manager_methods,
+					manager_signals, NULL, NULL, NULL);
+
+	vpn_connect_count = 0;
+
+	return 0;
+}
+
+void __vpn_manager_cleanup(void)
+{
+	DBG("");
+
+	if (!connection)
+		return;
+
+	g_dbus_unregister_interface(connection, VPN_MANAGER_PATH,
+						VPN_MANAGER_INTERFACE);
+
+	dbus_connection_unref(connection);
+}
diff --git a/connman/vpn/vpn-polkit.conf b/connman/vpn/vpn-polkit.conf
new file mode 100644
index 0000000..a1dc617
--- /dev/null
+++ b/connman/vpn/vpn-polkit.conf
@@ -0,0 +1,11 @@
+<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
+ "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
+<busconfig>
+    <policy user="root">
+        <allow own="net.connman.vpn"/>
+        <allow send_interface="net.connman.vpn.Agent"/>
+    </policy>
+    <policy context="default">
+        <allow send_destination="net.connman.vpn"/>
+    </policy>
+</busconfig>
diff --git a/connman/vpn/vpn-polkit.policy b/connman/vpn/vpn-polkit.policy
new file mode 100644
index 0000000..0c42722
--- /dev/null
+++ b/connman/vpn/vpn-polkit.policy
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE policyconfig PUBLIC
+ "-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN"
+ "http://www.freedesktop.org/standards/PolicyKit/1.0/policyconfig.dtd">
+
+<policyconfig>
+
+  <vendor>Connection Manager VPN daemon</vendor>
+  <icon_name>network-wireless</icon_name>
+
+  <action id="net.connman.vpn.modify">
+    <description>Settings configuration</description>
+    <message>Policy prevents modification of settings</message>
+    <defaults>
+      <allow_inactive>no</allow_inactive>
+      <allow_active>auth_self_keep_session</allow_active>
+    </defaults>
+  </action>
+
+  <action id="net.connman.vpn.secret">
+    <description>Secrets configuration</description>
+    <message>Policy prevents modification of secrets</message>
+    <defaults>
+      <allow_inactive>no</allow_inactive>
+      <allow_active>auth_admin_keep_session</allow_active>
+    </defaults>
+  </action>
+
+</policyconfig>
diff --git a/connman/vpn/vpn-provider.c b/connman/vpn/vpn-provider.c
new file mode 100644
index 0000000..16c0c2b
--- /dev/null
+++ b/connman/vpn/vpn-provider.c
@@ -0,0 +1,2739 @@
+/*
+ *
+ *  ConnMan VPN daemon
+ *
+ *  Copyright (C) 2012-2013  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 <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <gdbus.h>
+#include <connman/log.h>
+#include <gweb/gresolv.h>
+#include <netdb.h>
+
+#include "../src/connman.h"
+#include "connman/agent.h"
+#include "connman/vpn-dbus.h"
+#include "vpn-provider.h"
+#include "vpn.h"
+
+static DBusConnection *connection;
+static GHashTable *provider_hash;
+static GSList *driver_list;
+static int configuration_count;
+static bool handle_routes;
+
+struct vpn_route {
+	int family;
+	char *network;
+	char *netmask;
+	char *gateway;
+};
+
+struct vpn_setting {
+	bool hide_value;
+	bool immutable;
+	char *value;
+};
+
+struct vpn_provider {
+	int refcount;
+	int index;
+	int fd;
+	enum vpn_provider_state state;
+	char *path;
+	char *identifier;
+	char *name;
+	char *type;
+	char *host;
+	char *domain;
+	int family;
+	GHashTable *routes;
+	struct vpn_provider_driver *driver;
+	void *driver_data;
+	GHashTable *setting_strings;
+	GHashTable *user_routes;
+	GSList *user_networks;
+	GResolv *resolv;
+	char **host_ip;
+	struct vpn_ipconfig *ipconfig_ipv4;
+	struct vpn_ipconfig *ipconfig_ipv6;
+	char **nameservers;
+	guint notify_id;
+	char *config_file;
+	char *config_entry;
+	bool immutable;
+	struct connman_ipaddress *prev_ipv4_addr;
+	struct connman_ipaddress *prev_ipv6_addr;
+};
+
+static void append_properties(DBusMessageIter *iter,
+				struct vpn_provider *provider);
+
+static void free_route(gpointer data)
+{
+	struct vpn_route *route = data;
+
+	g_free(route->network);
+	g_free(route->netmask);
+	g_free(route->gateway);
+
+	g_free(route);
+}
+
+static void free_setting(gpointer data)
+{
+	struct vpn_setting *setting = data;
+
+	g_free(setting->value);
+	g_free(setting);
+}
+
+static void append_route(DBusMessageIter *iter, void *user_data)
+{
+	struct vpn_route *route = user_data;
+	DBusMessageIter item;
+	int family = 0;
+
+	connman_dbus_dict_open(iter, &item);
+
+	if (!route)
+		goto empty_dict;
+
+	if (route->family == AF_INET)
+		family = 4;
+	else if (route->family == AF_INET6)
+		family = 6;
+
+	if (family != 0)
+		connman_dbus_dict_append_basic(&item, "ProtocolFamily",
+					DBUS_TYPE_INT32, &family);
+
+	if (route->network)
+		connman_dbus_dict_append_basic(&item, "Network",
+					DBUS_TYPE_STRING, &route->network);
+
+	if (route->netmask)
+		connman_dbus_dict_append_basic(&item, "Netmask",
+					DBUS_TYPE_STRING, &route->netmask);
+
+	if (route->gateway)
+		connman_dbus_dict_append_basic(&item, "Gateway",
+					DBUS_TYPE_STRING, &route->gateway);
+
+empty_dict:
+	connman_dbus_dict_close(iter, &item);
+}
+
+static void append_routes(DBusMessageIter *iter, void *user_data)
+{
+	GHashTable *routes = user_data;
+	GHashTableIter hash;
+	gpointer value, key;
+
+	if (!routes) {
+		append_route(iter, NULL);
+		return;
+	}
+
+	g_hash_table_iter_init(&hash, routes);
+
+	while (g_hash_table_iter_next(&hash, &key, &value)) {
+		DBusMessageIter dict;
+
+		dbus_message_iter_open_container(iter, DBUS_TYPE_STRUCT, NULL,
+						&dict);
+		append_route(&dict, value);
+		dbus_message_iter_close_container(iter, &dict);
+	}
+}
+
+static void send_routes(struct vpn_provider *provider, GHashTable *routes,
+			const char *name)
+{
+	connman_dbus_property_changed_array(provider->path,
+					VPN_CONNECTION_INTERFACE,
+					name,
+					DBUS_TYPE_DICT_ENTRY,
+					append_routes,
+					routes);
+}
+
+static int provider_routes_changed(struct vpn_provider *provider)
+{
+	DBG("provider %p", provider);
+
+	send_routes(provider, provider->routes, "ServerRoutes");
+
+	return 0;
+}
+
+static GSList *read_route_dict(GSList *routes, DBusMessageIter *dicts)
+{
+	DBusMessageIter dict, value, entry;
+	const char *network, *netmask, *gateway;
+	struct vpn_route *route;
+	int family, type;
+	const char *key;
+
+	dbus_message_iter_recurse(dicts, &entry);
+
+	network = netmask = gateway = NULL;
+	family = PF_UNSPEC;
+
+	while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_DICT_ENTRY) {
+
+		dbus_message_iter_recurse(&entry, &dict);
+		dbus_message_iter_get_basic(&dict, &key);
+
+		dbus_message_iter_next(&dict);
+		dbus_message_iter_recurse(&dict, &value);
+
+		type = dbus_message_iter_get_arg_type(&value);
+
+		switch (type) {
+		case DBUS_TYPE_INT32:
+			if (g_str_equal(key, "ProtocolFamily"))
+				dbus_message_iter_get_basic(&value, &family);
+			break;
+
+		case DBUS_TYPE_STRING:
+			if (g_str_equal(key, "Network"))
+				dbus_message_iter_get_basic(&value, &network);
+			else if (g_str_equal(key, "Netmask"))
+				dbus_message_iter_get_basic(&value, &netmask);
+			else if (g_str_equal(key, "Gateway"))
+				dbus_message_iter_get_basic(&value, &gateway);
+			break;
+		}
+
+		dbus_message_iter_next(&entry);
+	}
+
+	DBG("family %d network %s netmask %s gateway %s", family,
+		network, netmask, gateway);
+
+	if (!network || !netmask) {
+		DBG("Ignoring route as network/netmask is missing");
+		return routes;
+	}
+
+	route = g_try_new(struct vpn_route, 1);
+	if (!route) {
+		g_slist_free_full(routes, free_route);
+		return NULL;
+	}
+
+	if (family == PF_UNSPEC) {
+		family = connman_inet_check_ipaddress(network);
+		if (family < 0) {
+			DBG("Cannot get address family of %s (%d/%s)", network,
+				family, gai_strerror(family));
+
+			g_free(route);
+			return routes;
+		}
+	} else {
+		switch (family) {
+		case '4':
+			family = AF_INET;
+			break;
+		case '6':
+			family = AF_INET6;
+			break;
+		default:
+			family = PF_UNSPEC;
+			break;
+		}
+	}
+
+	route->family = family;
+	route->network = g_strdup(network);
+	route->netmask = g_strdup(netmask);
+	route->gateway = g_strdup(gateway);
+
+	routes = g_slist_prepend(routes, route);
+	return routes;
+}
+
+static GSList *get_user_networks(DBusMessageIter *array)
+{
+	DBusMessageIter entry;
+	GSList *list = NULL;
+
+	while (dbus_message_iter_get_arg_type(array) == DBUS_TYPE_ARRAY) {
+
+		dbus_message_iter_recurse(array, &entry);
+
+		while (dbus_message_iter_get_arg_type(&entry) ==
+							DBUS_TYPE_STRUCT) {
+			DBusMessageIter dicts;
+
+			dbus_message_iter_recurse(&entry, &dicts);
+
+			while (dbus_message_iter_get_arg_type(&dicts) ==
+							DBUS_TYPE_ARRAY) {
+
+				list = read_route_dict(list, &dicts);
+				dbus_message_iter_next(&dicts);
+			}
+
+			dbus_message_iter_next(&entry);
+		}
+
+		dbus_message_iter_next(array);
+	}
+
+	return list;
+}
+
+static void set_user_networks(struct vpn_provider *provider, GSList *networks)
+{
+	GSList *list;
+
+	for (list = networks; list; list = g_slist_next(list)) {
+		struct vpn_route *route = list->data;
+
+		if (__vpn_provider_append_user_route(provider,
+					route->family, route->network,
+					route->netmask, route->gateway) != 0)
+			break;
+	}
+}
+
+static void del_routes(struct vpn_provider *provider)
+{
+	GHashTableIter hash;
+	gpointer value, key;
+
+	g_hash_table_iter_init(&hash, provider->user_routes);
+	while (handle_routes && g_hash_table_iter_next(&hash,
+						&key, &value)) {
+		struct vpn_route *route = value;
+		if (route->family == AF_INET6) {
+			unsigned char prefixlen = atoi(route->netmask);
+			connman_inet_del_ipv6_network_route(provider->index,
+							route->network,
+							prefixlen);
+		} else
+			connman_inet_del_host_route(provider->index,
+						route->network);
+	}
+
+	g_hash_table_remove_all(provider->user_routes);
+	g_slist_free_full(provider->user_networks, free_route);
+	provider->user_networks = NULL;
+}
+
+static void send_value(const char *path, const char *key, const char *value)
+{
+	const char *empty = "";
+	const char *str;
+
+	if (value)
+		str = value;
+	else
+		str = empty;
+
+	connman_dbus_property_changed_basic(path,
+					VPN_CONNECTION_INTERFACE,
+					key,
+					DBUS_TYPE_STRING,
+					&str);
+}
+
+static gboolean provider_send_changed(gpointer data)
+{
+	struct vpn_provider *provider = data;
+
+	provider_routes_changed(provider);
+
+	provider->notify_id = 0;
+
+	return FALSE;
+}
+
+static void provider_schedule_changed(struct vpn_provider *provider)
+{
+	if (provider->notify_id != 0)
+		g_source_remove(provider->notify_id);
+
+	provider->notify_id = g_timeout_add(100, provider_send_changed,
+								provider);
+}
+
+static DBusMessage *get_properties(DBusConnection *conn,
+					DBusMessage *msg, void *data)
+{
+	struct vpn_provider *provider = data;
+	DBusMessage *reply;
+	DBusMessageIter array;
+
+	DBG("provider %p", provider);
+
+	reply = dbus_message_new_method_return(msg);
+	if (!reply)
+		return NULL;
+
+	dbus_message_iter_init_append(reply, &array);
+
+	append_properties(&array, provider);
+
+	return reply;
+}
+
+static DBusMessage *set_property(DBusConnection *conn, DBusMessage *msg,
+								void *data)
+{
+	struct vpn_provider *provider = data;
+	DBusMessageIter iter, value;
+	const char *name;
+	int type;
+
+	DBG("conn %p", conn);
+
+	if (provider->immutable)
+		return __connman_error_not_supported(msg);
+
+	if (!dbus_message_iter_init(msg, &iter))
+		return __connman_error_invalid_arguments(msg);
+
+	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
+		return __connman_error_invalid_arguments(msg);
+
+	dbus_message_iter_get_basic(&iter, &name);
+	dbus_message_iter_next(&iter);
+
+	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT)
+		return __connman_error_invalid_arguments(msg);
+
+	dbus_message_iter_recurse(&iter, &value);
+
+	type = dbus_message_iter_get_arg_type(&value);
+
+	if (g_str_equal(name, "UserRoutes")) {
+		GSList *networks;
+
+		if (type != DBUS_TYPE_ARRAY)
+			return __connman_error_invalid_arguments(msg);
+
+		networks = get_user_networks(&value);
+		if (networks) {
+			del_routes(provider);
+			provider->user_networks = networks;
+			set_user_networks(provider, provider->user_networks);
+
+			if (!handle_routes)
+				send_routes(provider, provider->user_routes,
+								"UserRoutes");
+		}
+	} else {
+		const char *str;
+
+		dbus_message_iter_get_basic(&value, &str);
+		vpn_provider_set_string(provider, name, str);
+	}
+
+	return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+}
+
+static DBusMessage *clear_property(DBusConnection *conn, DBusMessage *msg,
+								void *data)
+{
+	struct vpn_provider *provider = data;
+	const char *name;
+
+	DBG("conn %p", conn);
+
+	if (provider->immutable)
+		return __connman_error_not_supported(msg);
+
+	dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &name,
+							DBUS_TYPE_INVALID);
+
+	if (g_str_equal(name, "UserRoutes")) {
+		del_routes(provider);
+
+		if (!handle_routes)
+			send_routes(provider, provider->user_routes, name);
+	} else if (vpn_provider_get_string(provider, name)) {
+		vpn_provider_set_string(provider, name, NULL);
+	} else {
+		return __connman_error_invalid_property(msg);
+	}
+
+	return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+}
+
+static DBusMessage *do_connect(DBusConnection *conn, DBusMessage *msg,
+								void *data)
+{
+	struct vpn_provider *provider = data;
+	int err;
+
+	DBG("conn %p provider %p", conn, provider);
+
+	err = __vpn_provider_connect(provider, msg);
+	if (err < 0)
+		return __connman_error_failed(msg, -err);
+
+	return NULL;
+}
+
+static DBusMessage *do_disconnect(DBusConnection *conn, DBusMessage *msg,
+								void *data)
+{
+	struct vpn_provider *provider = data;
+	int err;
+
+	DBG("conn %p provider %p", conn, provider);
+
+	err = __vpn_provider_disconnect(provider);
+	if (err < 0 && err != -EINPROGRESS)
+		return __connman_error_failed(msg, -err);
+
+	return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+}
+
+static const GDBusMethodTable connection_methods[] = {
+	{ GDBUS_METHOD("GetProperties",
+			NULL, GDBUS_ARGS({ "properties", "a{sv}" }),
+			get_properties) },
+	{ GDBUS_METHOD("SetProperty",
+			GDBUS_ARGS({ "name", "s" }, { "value", "v" }),
+			NULL, set_property) },
+	{ GDBUS_METHOD("ClearProperty",
+			GDBUS_ARGS({ "name", "s" }), NULL,
+			clear_property) },
+	{ GDBUS_ASYNC_METHOD("Connect", NULL, NULL, do_connect) },
+	{ GDBUS_METHOD("Disconnect", NULL, NULL, do_disconnect) },
+	{ },
+};
+
+static const GDBusSignalTable connection_signals[] = {
+	{ GDBUS_SIGNAL("PropertyChanged",
+			GDBUS_ARGS({ "name", "s" }, { "value", "v" })) },
+	{ },
+};
+
+static void resolv_result(GResolvResultStatus status,
+					char **results, gpointer user_data)
+{
+	struct vpn_provider *provider = user_data;
+
+	DBG("status %d", status);
+
+	if (status == G_RESOLV_RESULT_STATUS_SUCCESS && results &&
+						g_strv_length(results) > 0)
+		provider->host_ip = g_strdupv(results);
+
+	vpn_provider_unref(provider);
+}
+
+static void provider_resolv_host_addr(struct vpn_provider *provider)
+{
+	if (!provider->host)
+		return;
+
+	if (connman_inet_check_ipaddress(provider->host) > 0)
+		return;
+
+	if (provider->host_ip)
+		return;
+
+	/*
+	 * If the hostname is not numeric, try to resolv it. We do not wait
+	 * the result as it might take some time. We will get the result
+	 * before VPN will feed routes to us because VPN client will need
+	 * the IP address also before VPN connection can be established.
+	 */
+	provider->resolv = g_resolv_new(0);
+	if (!provider->resolv) {
+		DBG("Cannot resolv %s", provider->host);
+		return;
+	}
+
+	DBG("Trying to resolv %s", provider->host);
+
+	vpn_provider_ref(provider);
+
+	g_resolv_lookup_hostname(provider->resolv, provider->host,
+				resolv_result, provider);
+}
+
+void __vpn_provider_append_properties(struct vpn_provider *provider,
+							DBusMessageIter *iter)
+{
+	if (provider->host)
+		connman_dbus_dict_append_basic(iter, "Host",
+					DBUS_TYPE_STRING, &provider->host);
+
+	if (provider->domain)
+		connman_dbus_dict_append_basic(iter, "Domain",
+					DBUS_TYPE_STRING, &provider->domain);
+
+	if (provider->type)
+		connman_dbus_dict_append_basic(iter, "Type", DBUS_TYPE_STRING,
+						 &provider->type);
+}
+
+int __vpn_provider_append_user_route(struct vpn_provider *provider,
+				int family, const char *network,
+				const char *netmask, const char *gateway)
+{
+	struct vpn_route *route;
+	char *key = g_strdup_printf("%d/%s/%s/%s", family, network,
+				netmask, gateway ? gateway : "");
+
+	DBG("family %d network %s netmask %s gw %s", family, network,
+							netmask, gateway);
+
+	route = g_hash_table_lookup(provider->user_routes, key);
+	if (!route) {
+		route = g_try_new0(struct vpn_route, 1);
+		if (!route) {
+			connman_error("out of memory");
+			return -ENOMEM;
+		}
+
+		route->family = family;
+		route->network = g_strdup(network);
+		route->netmask = g_strdup(netmask);
+		route->gateway = g_strdup(gateway);
+
+		g_hash_table_replace(provider->user_routes, key, route);
+	} else
+		g_free(key);
+
+	return 0;
+}
+
+static struct vpn_route *get_route(char *route_str)
+{
+	char **elems = g_strsplit(route_str, "/", 0);
+	char *network, *netmask, *gateway, *family_str;
+	int family = PF_UNSPEC;
+	struct vpn_route *route = NULL;
+
+	if (!elems)
+		return NULL;
+
+	family_str = elems[0];
+
+	network = elems[1];
+	if (!network || network[0] == '\0')
+		goto out;
+
+	netmask = elems[2];
+	if (!netmask || netmask[0] == '\0')
+		goto out;
+
+	gateway = elems[3];
+
+	route = g_try_new0(struct vpn_route, 1);
+	if (!route)
+		goto out;
+
+	if (family_str[0] == '\0' || atoi(family_str) == 0) {
+		family = PF_UNSPEC;
+	} else {
+		switch (family_str[0]) {
+		case '4':
+			family = AF_INET;
+			break;
+		case '6':
+			family = AF_INET6;
+			break;
+		}
+	}
+
+	if (g_strrstr(network, ":")) {
+		if (family != PF_UNSPEC && family != AF_INET6)
+			DBG("You have IPv6 address but you have non IPv6 route");
+	} else if (g_strrstr(network, ".")) {
+		if (family != PF_UNSPEC && family != AF_INET)
+			DBG("You have IPv4 address but you have non IPv4 route");
+
+		if (!g_strrstr(netmask, ".")) {
+			/* We have netmask length */
+			in_addr_t addr;
+			struct in_addr netmask_in;
+			unsigned char prefix_len = 32;
+
+			if (netmask) {
+				char *ptr;
+				long int value = strtol(netmask, &ptr, 10);
+				if (ptr != netmask && *ptr == '\0' &&
+								value <= 32)
+					prefix_len = value;
+			}
+
+			addr = 0xffffffff << (32 - prefix_len);
+			netmask_in.s_addr = htonl(addr);
+			netmask = inet_ntoa(netmask_in);
+
+			DBG("network %s netmask %s", network, netmask);
+		}
+	}
+
+	if (family == PF_UNSPEC) {
+		family = connman_inet_check_ipaddress(network);
+		if (family < 0 || family == PF_UNSPEC)
+			goto out;
+	}
+
+	route->family = family;
+	route->network = g_strdup(network);
+	route->netmask = g_strdup(netmask);
+	route->gateway = g_strdup(gateway);
+
+out:
+	g_strfreev(elems);
+	return route;
+}
+
+static GSList *get_routes(gchar **networks)
+{
+	struct vpn_route *route;
+	GSList *routes = NULL;
+	int i;
+
+	for (i = 0; networks[i]; i++) {
+		route = get_route(networks[i]);
+		if (route)
+			routes = g_slist_prepend(routes, route);
+	}
+
+	return routes;
+}
+
+static int provider_load_from_keyfile(struct vpn_provider *provider,
+		GKeyFile *keyfile)
+{
+	gsize idx = 0;
+	gchar **settings;
+	gchar *key, *value;
+	gsize length, num_user_networks;
+	gchar **networks = NULL;
+
+	settings = g_key_file_get_keys(keyfile, provider->identifier, &length,
+				NULL);
+	if (!settings) {
+		g_key_file_free(keyfile);
+		return -ENOENT;
+	}
+
+	while (idx < length) {
+		key = settings[idx];
+		if (key) {
+			if (g_str_equal(key, "Networks")) {
+				networks = __vpn_config_get_string_list(keyfile,
+						provider->identifier,
+						key,
+						&num_user_networks,
+						NULL);
+				provider->user_networks = get_routes(networks);
+
+			} else {
+				value = __vpn_config_get_string(keyfile,
+							provider->identifier,
+							key, NULL);
+				vpn_provider_set_string(provider, key,
+							value);
+				g_free(value);
+			}
+		}
+		idx += 1;
+	}
+	g_strfreev(settings);
+	g_strfreev(networks);
+
+	if (provider->user_networks)
+		set_user_networks(provider, provider->user_networks);
+
+	return 0;
+}
+
+
+static int vpn_provider_load(struct vpn_provider *provider)
+{
+	GKeyFile *keyfile;
+
+	DBG("provider %p", provider);
+
+	keyfile = __connman_storage_load_provider(provider->identifier);
+	if (!keyfile)
+		return -ENOENT;
+
+	provider_load_from_keyfile(provider, keyfile);
+
+	g_key_file_free(keyfile);
+	return 0;
+}
+
+static gchar **create_network_list(GSList *networks, gsize *count)
+{
+	GSList *list;
+	gchar **result = NULL;
+	unsigned int num_elems = 0;
+
+	for (list = networks; list; list = g_slist_next(list)) {
+		struct vpn_route *route = list->data;
+		int family;
+
+		result = g_try_realloc(result,
+				(num_elems + 1) * sizeof(gchar *));
+		if (!result)
+			return NULL;
+
+		switch (route->family) {
+		case AF_INET:
+			family = 4;
+			break;
+		case AF_INET6:
+			family = 6;
+			break;
+		default:
+			family = 0;
+			break;
+		}
+
+		result[num_elems] = g_strdup_printf("%d/%s/%s/%s",
+				family, route->network, route->netmask,
+				!route->gateway ? "" : route->gateway);
+
+		num_elems++;
+	}
+
+	result = g_try_realloc(result, (num_elems + 1) * sizeof(gchar *));
+	if (!result)
+		return NULL;
+
+	result[num_elems] = NULL;
+	*count = num_elems;
+	return result;
+}
+
+static int vpn_provider_save(struct vpn_provider *provider)
+{
+	GKeyFile *keyfile;
+
+	DBG("provider %p immutable %s", provider,
+					provider->immutable ? "yes" : "no");
+
+	if (provider->immutable) {
+		/*
+		 * Do not save providers that are provisioned via .config
+		 * file.
+		 */
+		return -EPERM;
+	}
+
+	keyfile = g_key_file_new();
+	if (!keyfile)
+		return -ENOMEM;
+
+	g_key_file_set_string(keyfile, provider->identifier,
+			"Name", provider->name);
+	g_key_file_set_string(keyfile, provider->identifier,
+			"Type", provider->type);
+	g_key_file_set_string(keyfile, provider->identifier,
+			"Host", provider->host);
+	g_key_file_set_string(keyfile, provider->identifier,
+			"VPN.Domain", provider->domain);
+	if (provider->user_networks) {
+		gchar **networks;
+		gsize network_count;
+
+		networks = create_network_list(provider->user_networks,
+							&network_count);
+		if (networks) {
+			g_key_file_set_string_list(keyfile,
+						provider->identifier,
+						"Networks",
+						(const gchar ** const)networks,
+						network_count);
+			g_strfreev(networks);
+		}
+	}
+
+	if (provider->config_file && strlen(provider->config_file) > 0)
+		g_key_file_set_string(keyfile, provider->identifier,
+				"Config.file", provider->config_file);
+
+	if (provider->config_entry &&
+					strlen(provider->config_entry) > 0)
+		g_key_file_set_string(keyfile, provider->identifier,
+				"Config.ident", provider->config_entry);
+
+	if (provider->driver && provider->driver->save)
+		provider->driver->save(provider, keyfile);
+
+	__connman_storage_save_provider(keyfile, provider->identifier);
+	g_key_file_free(keyfile);
+
+	return 0;
+}
+
+struct vpn_provider *__vpn_provider_lookup(const char *identifier)
+{
+	struct vpn_provider *provider = NULL;
+
+	provider = g_hash_table_lookup(provider_hash, identifier);
+
+	return provider;
+}
+
+static bool match_driver(struct vpn_provider *provider,
+				struct vpn_provider_driver *driver)
+{
+	if (g_strcmp0(driver->name, provider->type) == 0)
+		return true;
+
+	return false;
+}
+
+static int provider_probe(struct vpn_provider *provider)
+{
+	GSList *list;
+
+	DBG("provider %p driver %p name %s", provider, provider->driver,
+						provider->name);
+
+	if (provider->driver)
+		return -EALREADY;
+
+	for (list = driver_list; list; list = list->next) {
+		struct vpn_provider_driver *driver = list->data;
+
+		if (!match_driver(provider, driver))
+			continue;
+
+		DBG("driver %p name %s", driver, driver->name);
+
+		if (driver->probe && driver->probe(provider) == 0) {
+			provider->driver = driver;
+			break;
+		}
+	}
+
+	if (!provider->driver)
+		return -ENODEV;
+
+	return 0;
+}
+
+static void provider_remove(struct vpn_provider *provider)
+{
+	if (provider->driver) {
+		provider->driver->remove(provider);
+		provider->driver = NULL;
+	}
+}
+
+static int provider_register(struct vpn_provider *provider)
+{
+	return provider_probe(provider);
+}
+
+static void provider_unregister(struct vpn_provider *provider)
+{
+	provider_remove(provider);
+}
+
+struct vpn_provider *
+vpn_provider_ref_debug(struct vpn_provider *provider,
+			const char *file, int line, const char *caller)
+{
+	DBG("%p ref %d by %s:%d:%s()", provider, provider->refcount + 1,
+		file, line, caller);
+
+	__sync_fetch_and_add(&provider->refcount, 1);
+
+	return provider;
+}
+
+static void provider_destruct(struct vpn_provider *provider)
+{
+	DBG("provider %p", provider);
+
+	if (provider->notify_id != 0)
+		g_source_remove(provider->notify_id);
+
+	g_free(provider->name);
+	g_free(provider->type);
+	g_free(provider->host);
+	g_free(provider->domain);
+	g_free(provider->identifier);
+	g_free(provider->path);
+	g_slist_free_full(provider->user_networks, free_route);
+	g_strfreev(provider->nameservers);
+	g_hash_table_destroy(provider->routes);
+	g_hash_table_destroy(provider->user_routes);
+	g_hash_table_destroy(provider->setting_strings);
+	if (provider->resolv) {
+		g_resolv_unref(provider->resolv);
+		provider->resolv = NULL;
+	}
+	__vpn_ipconfig_unref(provider->ipconfig_ipv4);
+	__vpn_ipconfig_unref(provider->ipconfig_ipv6);
+
+	g_strfreev(provider->host_ip);
+	g_free(provider->config_file);
+	g_free(provider->config_entry);
+	connman_ipaddress_free(provider->prev_ipv4_addr);
+	connman_ipaddress_free(provider->prev_ipv6_addr);
+	g_free(provider);
+}
+
+void vpn_provider_unref_debug(struct vpn_provider *provider,
+				const char *file, int line, const char *caller)
+{
+	DBG("%p ref %d by %s:%d:%s()", provider, provider->refcount - 1,
+		file, line, caller);
+
+	if (__sync_fetch_and_sub(&provider->refcount, 1) != 1)
+		return;
+
+	provider_remove(provider);
+
+	provider_destruct(provider);
+}
+
+static void configuration_count_add(void)
+{
+	DBG("count %d", configuration_count + 1);
+
+	__sync_fetch_and_add(&configuration_count, 1);
+}
+
+static void configuration_count_del(void)
+{
+	DBG("count %d", configuration_count - 1);
+
+	if (__sync_fetch_and_sub(&configuration_count, 1) != 1)
+		return;
+}
+
+int __vpn_provider_disconnect(struct vpn_provider *provider)
+{
+	int err;
+
+	DBG("provider %p", provider);
+
+	if (provider->driver && provider->driver->disconnect)
+		err = provider->driver->disconnect(provider);
+	else
+		return -EOPNOTSUPP;
+
+	if (err == -EINPROGRESS)
+		vpn_provider_set_state(provider, VPN_PROVIDER_STATE_CONNECT);
+
+	return err;
+}
+
+static void connect_cb(struct vpn_provider *provider, void *user_data,
+								int error)
+{
+	DBusMessage *pending = user_data;
+
+	DBG("provider %p user %p error %d", provider, user_data, error);
+
+	if (error != 0) {
+		DBusMessage *reply = __connman_error_failed(pending, error);
+		if (reply)
+			g_dbus_send_message(connection, reply);
+
+		vpn_provider_indicate_error(provider,
+					VPN_PROVIDER_ERROR_CONNECT_FAILED);
+		vpn_provider_set_state(provider, VPN_PROVIDER_STATE_FAILURE);
+	} else
+		g_dbus_send_reply(connection, pending, DBUS_TYPE_INVALID);
+
+	dbus_message_unref(pending);
+}
+
+int __vpn_provider_connect(struct vpn_provider *provider, DBusMessage *msg)
+{
+	int err;
+
+	DBG("provider %p", provider);
+
+	if (provider->driver && provider->driver->connect) {
+		dbus_message_ref(msg);
+		err = provider->driver->connect(provider, connect_cb,
+						dbus_message_get_sender(msg),
+						msg);
+	} else
+		return -EOPNOTSUPP;
+
+	if (err == -EINPROGRESS)
+		vpn_provider_set_state(provider, VPN_PROVIDER_STATE_CONNECT);
+
+	return err;
+}
+
+static void connection_removed_signal(struct vpn_provider *provider)
+{
+	DBusMessage *signal;
+	DBusMessageIter iter;
+
+	signal = dbus_message_new_signal(VPN_MANAGER_PATH,
+			VPN_MANAGER_INTERFACE, "ConnectionRemoved");
+	if (!signal)
+		return;
+
+	dbus_message_iter_init_append(signal, &iter);
+	dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
+							&provider->path);
+	dbus_connection_send(connection, signal, NULL);
+	dbus_message_unref(signal);
+}
+
+static char *get_ident(const char *path)
+{
+	char *pos;
+
+	if (*path != '/')
+		return NULL;
+
+	pos = strrchr(path, '/');
+	if (!pos)
+		return NULL;
+
+	return pos + 1;
+}
+
+int __vpn_provider_remove(const char *path)
+{
+	struct vpn_provider *provider;
+	char *ident;
+
+	DBG("path %s", path);
+
+	ident = get_ident(path);
+
+	provider = __vpn_provider_lookup(ident);
+	if (provider)
+		return __vpn_provider_delete(provider);
+
+	return -ENXIO;
+}
+
+int __vpn_provider_delete(struct vpn_provider *provider)
+{
+	DBG("Deleting VPN %s", provider->identifier);
+
+	connection_removed_signal(provider);
+
+	provider_unregister(provider);
+
+	__connman_storage_remove_provider(provider->identifier);
+
+	g_hash_table_remove(provider_hash, provider->identifier);
+
+	return 0;
+}
+
+static void append_ipv4(DBusMessageIter *iter, void *user_data)
+{
+	struct vpn_provider *provider = user_data;
+	const char *address, *gateway, *peer;
+
+	address = __vpn_ipconfig_get_local(provider->ipconfig_ipv4);
+	if (address) {
+		in_addr_t addr;
+		struct in_addr netmask;
+		char *mask;
+		int prefixlen;
+
+		prefixlen = __vpn_ipconfig_get_prefixlen(
+						provider->ipconfig_ipv4);
+
+		addr = 0xffffffff << (32 - prefixlen);
+		netmask.s_addr = htonl(addr);
+		mask = inet_ntoa(netmask);
+
+		connman_dbus_dict_append_basic(iter, "Address",
+						DBUS_TYPE_STRING, &address);
+
+		connman_dbus_dict_append_basic(iter, "Netmask",
+						DBUS_TYPE_STRING, &mask);
+	}
+
+	gateway = __vpn_ipconfig_get_gateway(provider->ipconfig_ipv4);
+	if (gateway)
+		connman_dbus_dict_append_basic(iter, "Gateway",
+						DBUS_TYPE_STRING, &gateway);
+
+	peer = __vpn_ipconfig_get_peer(provider->ipconfig_ipv4);
+	if (peer)
+		connman_dbus_dict_append_basic(iter, "Peer",
+						DBUS_TYPE_STRING, &peer);
+}
+
+static void append_ipv6(DBusMessageIter *iter, void *user_data)
+{
+	struct vpn_provider *provider = user_data;
+	const char *address, *gateway, *peer;
+
+	address = __vpn_ipconfig_get_local(provider->ipconfig_ipv6);
+	if (address) {
+		unsigned char prefixlen;
+
+		connman_dbus_dict_append_basic(iter, "Address",
+						DBUS_TYPE_STRING, &address);
+
+		prefixlen = __vpn_ipconfig_get_prefixlen(
+						provider->ipconfig_ipv6);
+
+		connman_dbus_dict_append_basic(iter, "PrefixLength",
+						DBUS_TYPE_BYTE, &prefixlen);
+	}
+
+	gateway = __vpn_ipconfig_get_gateway(provider->ipconfig_ipv6);
+	if (gateway)
+		connman_dbus_dict_append_basic(iter, "Gateway",
+						DBUS_TYPE_STRING, &gateway);
+
+	peer = __vpn_ipconfig_get_peer(provider->ipconfig_ipv6);
+	if (peer)
+		connman_dbus_dict_append_basic(iter, "Peer",
+						DBUS_TYPE_STRING, &peer);
+}
+
+static const char *state2string(enum vpn_provider_state state)
+{
+	switch (state) {
+	case VPN_PROVIDER_STATE_UNKNOWN:
+		break;
+	case VPN_PROVIDER_STATE_IDLE:
+		return "idle";
+	case VPN_PROVIDER_STATE_CONNECT:
+		return "configuration";
+	case VPN_PROVIDER_STATE_READY:
+		return "ready";
+	case VPN_PROVIDER_STATE_DISCONNECT:
+		return "disconnect";
+	case VPN_PROVIDER_STATE_FAILURE:
+		return "failure";
+	}
+
+	return NULL;
+}
+
+static void append_nameservers(DBusMessageIter *iter, char **servers)
+{
+	int i;
+
+	DBG("%p", servers);
+
+	for (i = 0; servers[i]; i++) {
+		DBG("servers[%d] %s", i, servers[i]);
+		dbus_message_iter_append_basic(iter,
+					DBUS_TYPE_STRING, &servers[i]);
+	}
+}
+
+static void append_dns(DBusMessageIter *iter, void *user_data)
+{
+	struct vpn_provider *provider = user_data;
+
+	if (provider->nameservers)
+		append_nameservers(iter, provider->nameservers);
+}
+
+static int provider_indicate_state(struct vpn_provider *provider,
+				enum vpn_provider_state state)
+{
+	const char *str;
+	enum vpn_provider_state old_state;
+
+	str = state2string(state);
+	DBG("provider %p state %s/%d", provider, str, state);
+	if (!str)
+		return -EINVAL;
+
+	old_state = provider->state;
+	provider->state = state;
+
+	if (state == VPN_PROVIDER_STATE_READY) {
+		connman_dbus_property_changed_basic(provider->path,
+					VPN_CONNECTION_INTERFACE, "Index",
+					DBUS_TYPE_INT32, &provider->index);
+
+		if (provider->family == AF_INET)
+			connman_dbus_property_changed_dict(provider->path,
+					VPN_CONNECTION_INTERFACE, "IPv4",
+					append_ipv4, provider);
+		else if (provider->family == AF_INET6)
+			connman_dbus_property_changed_dict(provider->path,
+					VPN_CONNECTION_INTERFACE, "IPv6",
+					append_ipv6, provider);
+
+		connman_dbus_property_changed_array(provider->path,
+						VPN_CONNECTION_INTERFACE,
+						"Nameservers",
+						DBUS_TYPE_STRING,
+						append_dns, provider);
+
+		if (provider->domain)
+			connman_dbus_property_changed_basic(provider->path,
+						VPN_CONNECTION_INTERFACE,
+						"Domain",
+						DBUS_TYPE_STRING,
+						&provider->domain);
+	}
+
+	if (old_state != state)
+		connman_dbus_property_changed_basic(provider->path,
+					VPN_CONNECTION_INTERFACE, "State",
+					DBUS_TYPE_STRING, &str);
+
+	return 0;
+}
+
+static void append_state(DBusMessageIter *iter,
+					struct vpn_provider *provider)
+{
+	char *str;
+
+	switch (provider->state) {
+	case VPN_PROVIDER_STATE_UNKNOWN:
+	case VPN_PROVIDER_STATE_IDLE:
+		str = "idle";
+		break;
+	case VPN_PROVIDER_STATE_CONNECT:
+		str = "configuration";
+		break;
+	case VPN_PROVIDER_STATE_READY:
+		str = "ready";
+		break;
+	case VPN_PROVIDER_STATE_DISCONNECT:
+		str = "disconnect";
+		break;
+	case VPN_PROVIDER_STATE_FAILURE:
+		str = "failure";
+		break;
+	}
+
+	connman_dbus_dict_append_basic(iter, "State",
+				DBUS_TYPE_STRING, &str);
+}
+
+static void append_properties(DBusMessageIter *iter,
+					struct vpn_provider *provider)
+{
+	DBusMessageIter dict;
+	GHashTableIter hash;
+	gpointer value, key;
+	dbus_bool_t immutable;
+
+	connman_dbus_dict_open(iter, &dict);
+
+	append_state(&dict, provider);
+
+	if (provider->type)
+		connman_dbus_dict_append_basic(&dict, "Type",
+					DBUS_TYPE_STRING, &provider->type);
+
+	if (provider->name)
+		connman_dbus_dict_append_basic(&dict, "Name",
+					DBUS_TYPE_STRING, &provider->name);
+
+	if (provider->host)
+		connman_dbus_dict_append_basic(&dict, "Host",
+					DBUS_TYPE_STRING, &provider->host);
+	if (provider->index >= 0)
+		connman_dbus_dict_append_basic(&dict, "Index",
+					DBUS_TYPE_INT32, &provider->index);
+	if (provider->domain)
+		connman_dbus_dict_append_basic(&dict, "Domain",
+					DBUS_TYPE_STRING, &provider->domain);
+
+	immutable = provider->immutable;
+	connman_dbus_dict_append_basic(&dict, "Immutable", DBUS_TYPE_BOOLEAN,
+					&immutable);
+
+	if (provider->family == AF_INET)
+		connman_dbus_dict_append_dict(&dict, "IPv4", append_ipv4,
+						provider);
+	else if (provider->family == AF_INET6)
+		connman_dbus_dict_append_dict(&dict, "IPv6", append_ipv6,
+						provider);
+
+	connman_dbus_dict_append_array(&dict, "Nameservers",
+				DBUS_TYPE_STRING, append_dns, provider);
+
+	connman_dbus_dict_append_array(&dict, "UserRoutes",
+				DBUS_TYPE_DICT_ENTRY, append_routes,
+				provider->user_routes);
+
+	connman_dbus_dict_append_array(&dict, "ServerRoutes",
+				DBUS_TYPE_DICT_ENTRY, append_routes,
+				provider->routes);
+
+	if (provider->setting_strings) {
+		g_hash_table_iter_init(&hash, provider->setting_strings);
+
+		while (g_hash_table_iter_next(&hash, &key, &value)) {
+			struct vpn_setting *setting = value;
+
+			if (!setting->hide_value &&
+							setting->value)
+				connman_dbus_dict_append_basic(&dict, key,
+							DBUS_TYPE_STRING,
+							&setting->value);
+		}
+	}
+
+	connman_dbus_dict_close(iter, &dict);
+}
+
+static void connection_added_signal(struct vpn_provider *provider)
+{
+	DBusMessage *signal;
+	DBusMessageIter iter;
+
+	signal = dbus_message_new_signal(VPN_MANAGER_PATH,
+			VPN_MANAGER_INTERFACE, "ConnectionAdded");
+	if (!signal)
+		return;
+
+	dbus_message_iter_init_append(signal, &iter);
+	dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
+							&provider->path);
+	append_properties(&iter, provider);
+
+	dbus_connection_send(connection, signal, NULL);
+	dbus_message_unref(signal);
+}
+
+static bool check_host(char **hosts, char *host)
+{
+	int i;
+
+	if (!hosts)
+		return false;
+
+	for (i = 0; hosts[i]; i++) {
+		if (g_strcmp0(hosts[i], host) == 0)
+			return true;
+	}
+
+	return false;
+}
+
+static void provider_append_routes(gpointer key, gpointer value,
+					gpointer user_data)
+{
+	struct vpn_route *route = value;
+	struct vpn_provider *provider = user_data;
+	int index = provider->index;
+
+	if (!handle_routes)
+		return;
+
+	/*
+	 * If the VPN administrator/user has given a route to
+	 * VPN server, then we must discard that because the
+	 * server cannot be contacted via VPN tunnel.
+	 */
+	if (check_host(provider->host_ip, route->network)) {
+		DBG("Discarding VPN route to %s via %s at index %d",
+			route->network, route->gateway, index);
+		return;
+	}
+
+	if (route->family == AF_INET6) {
+		unsigned char prefix_len = atoi(route->netmask);
+
+		connman_inet_add_ipv6_network_route(index, route->network,
+							route->gateway,
+							prefix_len);
+	} else {
+		connman_inet_add_network_route(index, route->network,
+						route->gateway,
+						route->netmask);
+	}
+}
+
+static int set_connected(struct vpn_provider *provider,
+					bool connected)
+{
+	struct vpn_ipconfig *ipconfig;
+
+	DBG("provider %p id %s connected %d", provider,
+					provider->identifier, connected);
+
+	if (connected) {
+		if (provider->family == AF_INET6)
+			ipconfig = provider->ipconfig_ipv6;
+		else
+			ipconfig = provider->ipconfig_ipv4;
+
+		__vpn_ipconfig_address_add(ipconfig, provider->family);
+
+		if (handle_routes)
+			__vpn_ipconfig_gateway_add(ipconfig, provider->family);
+
+		provider_indicate_state(provider,
+					VPN_PROVIDER_STATE_READY);
+
+		g_hash_table_foreach(provider->routes, provider_append_routes,
+					provider);
+
+		g_hash_table_foreach(provider->user_routes,
+					provider_append_routes, provider);
+
+	} else {
+		provider_indicate_state(provider,
+					VPN_PROVIDER_STATE_DISCONNECT);
+
+		provider_indicate_state(provider,
+					VPN_PROVIDER_STATE_IDLE);
+	}
+
+	return 0;
+}
+
+int vpn_provider_set_state(struct vpn_provider *provider,
+					enum vpn_provider_state state)
+{
+	if (!provider)
+		return -EINVAL;
+
+	switch (state) {
+	case VPN_PROVIDER_STATE_UNKNOWN:
+		return -EINVAL;
+	case VPN_PROVIDER_STATE_IDLE:
+		return set_connected(provider, false);
+	case VPN_PROVIDER_STATE_CONNECT:
+		return provider_indicate_state(provider, state);
+	case VPN_PROVIDER_STATE_READY:
+		return set_connected(provider, true);
+	case VPN_PROVIDER_STATE_DISCONNECT:
+		return provider_indicate_state(provider, state);
+	case VPN_PROVIDER_STATE_FAILURE:
+		return provider_indicate_state(provider, state);
+	}
+	return -EINVAL;
+}
+
+int vpn_provider_indicate_error(struct vpn_provider *provider,
+					enum vpn_provider_error error)
+{
+	DBG("provider %p id %s error %d", provider, provider->identifier,
+									error);
+
+	vpn_provider_set_state(provider, VPN_PROVIDER_STATE_FAILURE);
+
+	switch (error) {
+	case VPN_PROVIDER_ERROR_UNKNOWN:
+	case VPN_PROVIDER_ERROR_CONNECT_FAILED:
+		break;
+
+        case VPN_PROVIDER_ERROR_LOGIN_FAILED:
+        case VPN_PROVIDER_ERROR_AUTH_FAILED:
+		vpn_provider_set_state(provider, VPN_PROVIDER_STATE_IDLE);
+		break;
+	}
+
+	return 0;
+}
+
+static int connection_unregister(struct vpn_provider *provider)
+{
+	DBG("provider %p path %s", provider, provider->path);
+
+	if (!provider->path)
+		return -EALREADY;
+
+	g_dbus_unregister_interface(connection, provider->path,
+				VPN_CONNECTION_INTERFACE);
+
+	g_free(provider->path);
+	provider->path = NULL;
+
+	return 0;
+}
+
+static int connection_register(struct vpn_provider *provider)
+{
+	DBG("provider %p path %s", provider, provider->path);
+
+	if (provider->path)
+		return -EALREADY;
+
+	provider->path = g_strdup_printf("%s/connection/%s", VPN_PATH,
+						provider->identifier);
+
+	g_dbus_register_interface(connection, provider->path,
+				VPN_CONNECTION_INTERFACE,
+				connection_methods, connection_signals,
+				NULL, provider, NULL);
+
+	return 0;
+}
+
+static void unregister_provider(gpointer data)
+{
+	struct vpn_provider *provider = data;
+
+	configuration_count_del();
+
+	connection_unregister(provider);
+
+	vpn_provider_unref(provider);
+}
+
+static void provider_initialize(struct vpn_provider *provider)
+{
+	DBG("provider %p", provider);
+
+	provider->index = 0;
+	provider->fd = -1;
+	provider->name = NULL;
+	provider->type = NULL;
+	provider->domain = NULL;
+	provider->identifier = NULL;
+	provider->immutable = false;
+	provider->user_networks = NULL;
+	provider->routes = g_hash_table_new_full(g_direct_hash, g_direct_equal,
+					NULL, free_route);
+	provider->user_routes = g_hash_table_new_full(g_str_hash, g_str_equal,
+					g_free, free_route);
+	provider->setting_strings = g_hash_table_new_full(g_str_hash,
+					g_str_equal, g_free, free_setting);
+}
+
+static struct vpn_provider *vpn_provider_new(void)
+{
+	struct vpn_provider *provider;
+
+	provider = g_try_new0(struct vpn_provider, 1);
+	if (!provider)
+		return NULL;
+
+	provider->refcount = 1;
+
+	DBG("provider %p", provider);
+	provider_initialize(provider);
+
+	return provider;
+}
+
+static struct vpn_provider *vpn_provider_get(const char *identifier)
+{
+	struct vpn_provider *provider;
+
+	provider = g_hash_table_lookup(provider_hash, identifier);
+	if (provider)
+		return provider;
+
+	provider = vpn_provider_new();
+	if (!provider)
+		return NULL;
+
+	DBG("provider %p", provider);
+
+	provider->identifier = g_strdup(identifier);
+
+	g_hash_table_insert(provider_hash, provider->identifier, provider);
+
+	configuration_count_add();
+
+	return provider;
+}
+
+static void provider_dbus_ident(char *ident)
+{
+	int i, len = strlen(ident);
+
+	for (i = 0; i < len; i++) {
+		if (ident[i] >= '0' && ident[i] <= '9')
+			continue;
+		if (ident[i] >= 'a' && ident[i] <= 'z')
+			continue;
+		if (ident[i] >= 'A' && ident[i] <= 'Z')
+			continue;
+		ident[i] = '_';
+	}
+}
+
+static struct vpn_provider *provider_create_from_keyfile(GKeyFile *keyfile,
+		const char *ident)
+{
+	struct vpn_provider *provider;
+
+	if (!keyfile || !ident)
+		return NULL;
+
+	provider = __vpn_provider_lookup(ident);
+	if (!provider) {
+		provider = vpn_provider_get(ident);
+		if (!provider) {
+			DBG("can not create provider");
+			return NULL;
+		}
+
+		provider_load_from_keyfile(provider, keyfile);
+
+		if (!provider->name || !provider->host ||
+				!provider->domain) {
+			DBG("cannot get name, host or domain");
+			vpn_provider_unref(provider);
+			return NULL;
+		}
+
+		if (provider_register(provider) == 0)
+			connection_register(provider);
+	}
+	return provider;
+}
+
+static void provider_create_all_from_type(const char *provider_type)
+{
+	unsigned int i;
+	char **providers;
+	char *id, *type;
+	GKeyFile *keyfile;
+
+	DBG("provider type %s", provider_type);
+
+	providers = __connman_storage_get_providers();
+
+	if (!providers)
+		return;
+
+	for (i = 0; providers[i]; i += 1) {
+
+		if (strncmp(providers[i], "provider_", 9) != 0)
+			continue;
+
+		id = providers[i] + 9;
+		keyfile = __connman_storage_load_provider(id);
+
+		if (!keyfile)
+			continue;
+
+		type = __vpn_config_get_string(keyfile, id, "Type", NULL);
+
+		DBG("keyfile %p id %s type %s", keyfile, id, type);
+
+		if (strcmp(provider_type, type) != 0) {
+			g_free(type);
+			g_key_file_free(keyfile);
+			continue;
+		}
+
+		if (!provider_create_from_keyfile(keyfile, id))
+			DBG("could not create provider");
+
+		g_free(type);
+		g_key_file_free(keyfile);
+	}
+	g_strfreev(providers);
+}
+
+char *__vpn_provider_create_identifier(const char *host, const char *domain)
+{
+	char *ident;
+
+	ident = g_strdup_printf("%s_%s", host, domain);
+	if (!ident)
+		return NULL;
+
+	provider_dbus_ident(ident);
+
+	return ident;
+}
+
+int __vpn_provider_create(DBusMessage *msg)
+{
+	struct vpn_provider *provider;
+	DBusMessageIter iter, array;
+	const char *type = NULL, *name = NULL;
+	const char *host = NULL, *domain = NULL;
+	GSList *networks = NULL;
+	char *ident;
+	int err;
+
+	dbus_message_iter_init(msg, &iter);
+	dbus_message_iter_recurse(&iter, &array);
+
+	while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_DICT_ENTRY) {
+		DBusMessageIter entry, value;
+		const char *key;
+
+		dbus_message_iter_recurse(&array, &entry);
+		dbus_message_iter_get_basic(&entry, &key);
+
+		dbus_message_iter_next(&entry);
+		dbus_message_iter_recurse(&entry, &value);
+
+		switch (dbus_message_iter_get_arg_type(&value)) {
+		case DBUS_TYPE_STRING:
+			if (g_str_equal(key, "Type"))
+				dbus_message_iter_get_basic(&value, &type);
+			else if (g_str_equal(key, "Name"))
+				dbus_message_iter_get_basic(&value, &name);
+			else if (g_str_equal(key, "Host"))
+				dbus_message_iter_get_basic(&value, &host);
+			else if (g_str_equal(key, "VPN.Domain") ||
+					g_str_equal(key, "Domain"))
+				dbus_message_iter_get_basic(&value, &domain);
+			break;
+		case DBUS_TYPE_ARRAY:
+			if (g_str_equal(key, "UserRoutes"))
+				networks = get_user_networks(&value);
+			break;
+		}
+
+		dbus_message_iter_next(&array);
+	}
+
+	if (!host || !domain)
+		return -EINVAL;
+
+	DBG("Type %s name %s networks %p", type, name, networks);
+
+	if (!type || !name)
+		return -EOPNOTSUPP;
+
+	ident = __vpn_provider_create_identifier(host, domain);
+	DBG("ident %s", ident);
+
+	provider = __vpn_provider_lookup(ident);
+	if (!provider) {
+		provider = vpn_provider_get(ident);
+		if (!provider) {
+			DBG("can not create provider");
+			g_free(ident);
+			return -EOPNOTSUPP;
+		}
+
+		provider->host = g_strdup(host);
+		provider->domain = g_strdup(domain);
+		provider->name = g_strdup(name);
+		provider->type = g_strdup(type);
+
+		if (provider_register(provider) == 0)
+			vpn_provider_load(provider);
+
+		provider_resolv_host_addr(provider);
+	}
+
+	if (networks) {
+		g_slist_free_full(provider->user_networks, free_route);
+		provider->user_networks = networks;
+		set_user_networks(provider, provider->user_networks);
+	}
+
+	dbus_message_iter_init(msg, &iter);
+	dbus_message_iter_recurse(&iter, &array);
+
+	while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_DICT_ENTRY) {
+		DBusMessageIter entry, value;
+		const char *key, *str;
+
+		dbus_message_iter_recurse(&array, &entry);
+		dbus_message_iter_get_basic(&entry, &key);
+
+		dbus_message_iter_next(&entry);
+		dbus_message_iter_recurse(&entry, &value);
+
+		switch (dbus_message_iter_get_arg_type(&value)) {
+		case DBUS_TYPE_STRING:
+			dbus_message_iter_get_basic(&value, &str);
+			vpn_provider_set_string(provider, key, str);
+			break;
+		}
+
+		dbus_message_iter_next(&array);
+	}
+
+	g_free(ident);
+
+	vpn_provider_save(provider);
+
+	err = provider_register(provider);
+	if (err != 0 && err != -EALREADY)
+		return err;
+
+	connection_register(provider);
+
+	DBG("provider %p index %d path %s", provider, provider->index,
+							provider->path);
+
+	g_dbus_send_reply(connection, msg,
+				DBUS_TYPE_OBJECT_PATH, &provider->path,
+				DBUS_TYPE_INVALID);
+
+	connection_added_signal(provider);
+
+	return 0;
+}
+
+static const char *get_string(GHashTable *settings, const char *key)
+{
+	DBG("settings %p key %s", settings, key);
+
+	return g_hash_table_lookup(settings, key);
+}
+
+static GSList *parse_user_networks(const char *network_str)
+{
+	GSList *networks = NULL;
+	char **elems;
+	int i = 0;
+
+	if (!network_str)
+		return NULL;
+
+	elems = g_strsplit(network_str, ",", 0);
+	if (!elems)
+		return NULL;
+
+	while (elems[i]) {
+		struct vpn_route *vpn_route;
+		char *network, *netmask, *gateway;
+		int family;
+		char **route;
+
+		route = g_strsplit(elems[i], "/", 0);
+		if (!route)
+			goto next;
+
+		network = route[0];
+		if (!network || network[0] == '\0')
+			goto next;
+
+		family = connman_inet_check_ipaddress(network);
+		if (family < 0) {
+			DBG("Cannot get address family of %s (%d/%s)", network,
+				family, gai_strerror(family));
+
+			goto next;
+		}
+
+		switch (family) {
+		case AF_INET:
+			break;
+		case AF_INET6:
+			break;
+		default:
+			DBG("Unsupported address family %d", family);
+			goto next;
+		}
+
+		netmask = route[1];
+		if (!netmask || netmask[0] == '\0')
+			goto next;
+
+		gateway = route[2];
+
+		vpn_route = g_try_new0(struct vpn_route, 1);
+		if (!vpn_route) {
+			g_strfreev(route);
+			break;
+		}
+
+		vpn_route->family = family;
+		vpn_route->network = g_strdup(network);
+		vpn_route->netmask = g_strdup(netmask);
+		vpn_route->gateway = g_strdup(gateway);
+
+		DBG("route %s/%s%s%s", network, netmask,
+			gateway ? " via " : "", gateway ? gateway : "");
+
+		networks = g_slist_prepend(networks, vpn_route);
+
+	next:
+		g_strfreev(route);
+		i++;
+	}
+
+	g_strfreev(elems);
+
+	return g_slist_reverse(networks);
+}
+
+int __vpn_provider_create_from_config(GHashTable *settings,
+				const char *config_ident,
+				const char *config_entry)
+{
+	struct vpn_provider *provider;
+	const char *type, *name, *host, *domain, *networks_str;
+	GSList *networks;
+	char *ident = NULL;
+	GHashTableIter hash;
+	gpointer value, key;
+	int err;
+
+	type = get_string(settings, "Type");
+	name = get_string(settings, "Name");
+	host = get_string(settings, "Host");
+	domain = get_string(settings, "Domain");
+	networks_str = get_string(settings, "Networks");
+	networks = parse_user_networks(networks_str);
+
+	if (!host || !domain) {
+		err = -EINVAL;
+		goto fail;
+	}
+
+	DBG("type %s name %s networks %s", type, name, networks_str);
+
+	if (!type || !name) {
+		err = -EOPNOTSUPP;
+		goto fail;
+	}
+
+	ident = __vpn_provider_create_identifier(host, domain);
+	DBG("ident %s", ident);
+
+	provider = __vpn_provider_lookup(ident);
+	if (!provider) {
+		provider = vpn_provider_get(ident);
+		if (!provider) {
+			DBG("can not create provider");
+			err = -EOPNOTSUPP;
+			goto fail;
+		}
+
+		provider->host = g_strdup(host);
+		provider->domain = g_strdup(domain);
+		provider->name = g_strdup(name);
+		provider->type = g_ascii_strdown(type, -1);
+
+		provider->config_file = g_strdup(config_ident);
+		provider->config_entry = g_strdup(config_entry);
+
+		provider_register(provider);
+
+		provider_resolv_host_addr(provider);
+	}
+
+	if (networks) {
+		g_slist_free_full(provider->user_networks, free_route);
+		provider->user_networks = networks;
+		set_user_networks(provider, provider->user_networks);
+	}
+
+	g_hash_table_iter_init(&hash, settings);
+
+	while (g_hash_table_iter_next(&hash, &key, &value))
+		__vpn_provider_set_string_immutable(provider, key, value);
+
+	provider->immutable = true;
+
+	vpn_provider_save(provider);
+
+	err = provider_register(provider);
+	if (err != 0 && err != -EALREADY)
+		goto fail;
+
+	connection_register(provider);
+
+	DBG("provider %p index %d path %s", provider, provider->index,
+							provider->path);
+
+	connection_added_signal(provider);
+
+	g_free(ident);
+
+	return 0;
+
+fail:
+	g_free(ident);
+	g_slist_free_full(networks, free_route);
+
+	return err;
+}
+
+static void append_connection_structs(DBusMessageIter *iter, void *user_data)
+{
+	DBusMessageIter entry;
+	GHashTableIter hash;
+	gpointer value, key;
+
+	g_hash_table_iter_init(&hash, provider_hash);
+
+	while (g_hash_table_iter_next(&hash, &key, &value)) {
+		struct vpn_provider *provider = value;
+
+		DBG("path %s", provider->path);
+
+		if (!provider->identifier)
+			continue;
+
+		dbus_message_iter_open_container(iter, DBUS_TYPE_STRUCT,
+				NULL, &entry);
+		dbus_message_iter_append_basic(&entry, DBUS_TYPE_OBJECT_PATH,
+				&provider->path);
+		append_properties(&entry, provider);
+		dbus_message_iter_close_container(iter, &entry);
+	}
+}
+
+DBusMessage *__vpn_provider_get_connections(DBusMessage *msg)
+{
+	DBusMessage *reply;
+
+	DBG("");
+
+	reply = dbus_message_new_method_return(msg);
+	if (!reply)
+		return NULL;
+
+	__connman_dbus_append_objpath_dict_array(reply,
+			append_connection_structs, NULL);
+
+	return reply;
+}
+
+const char *__vpn_provider_get_ident(struct vpn_provider *provider)
+{
+	if (!provider)
+		return NULL;
+
+	return provider->identifier;
+}
+
+static int set_string(struct vpn_provider *provider,
+			const char *key, const char *value,
+			bool hide_value, bool immutable)
+{
+	DBG("provider %p key %s immutable %s value %s", provider, key,
+		immutable ? "yes" : "no",
+		hide_value ? "<not printed>" : value);
+
+	if (g_str_equal(key, "Type")) {
+		g_free(provider->type);
+		provider->type = g_ascii_strdown(value, -1);
+		send_value(provider->path, "Type", provider->type);
+	} else if (g_str_equal(key, "Name")) {
+		g_free(provider->name);
+		provider->name = g_strdup(value);
+		send_value(provider->path, "Name", provider->name);
+	} else if (g_str_equal(key, "Host")) {
+		g_free(provider->host);
+		provider->host = g_strdup(value);
+		send_value(provider->path, "Host", provider->host);
+	} else if (g_str_equal(key, "VPN.Domain") ||
+			g_str_equal(key, "Domain")) {
+		g_free(provider->domain);
+		provider->domain = g_strdup(value);
+		send_value(provider->path, "Domain", provider->domain);
+	} else {
+		struct vpn_setting *setting;
+
+		setting = g_hash_table_lookup(provider->setting_strings, key);
+		if (setting && !immutable &&
+						setting->immutable) {
+			DBG("Trying to set immutable variable %s", key);
+			return -EPERM;
+		}
+
+		setting = g_try_new0(struct vpn_setting, 1);
+		if (!setting)
+			return -ENOMEM;
+
+		setting->value = g_strdup(value);
+		setting->hide_value = hide_value;
+
+		if (immutable)
+			setting->immutable = true;
+
+		if (!hide_value)
+			send_value(provider->path, key, setting->value);
+
+		g_hash_table_replace(provider->setting_strings,
+				g_strdup(key), setting);
+	}
+
+	return 0;
+}
+
+int vpn_provider_set_string(struct vpn_provider *provider,
+					const char *key, const char *value)
+{
+	return set_string(provider, key, value, false, false);
+}
+
+int vpn_provider_set_string_hide_value(struct vpn_provider *provider,
+					const char *key, const char *value)
+{
+	return set_string(provider, key, value, true, false);
+}
+
+int __vpn_provider_set_string_immutable(struct vpn_provider *provider,
+					const char *key, const char *value)
+{
+	return set_string(provider, key, value, false, true);
+}
+
+const char *vpn_provider_get_string(struct vpn_provider *provider,
+							const char *key)
+{
+	struct vpn_setting *setting;
+
+	DBG("provider %p key %s", provider, key);
+
+	if (g_str_equal(key, "Type"))
+		return provider->type;
+	else if (g_str_equal(key, "Name"))
+		return provider->name;
+	else if (g_str_equal(key, "Host"))
+		return provider->host;
+	else if (g_str_equal(key, "HostIP")) {
+		if (!provider->host_ip ||
+				!provider->host_ip[0])
+			return provider->host;
+		else
+			return provider->host_ip[0];
+	} else if (g_str_equal(key, "VPN.Domain") ||
+			g_str_equal(key, "Domain"))
+		return provider->domain;
+
+	setting = g_hash_table_lookup(provider->setting_strings, key);
+	if (!setting)
+		return NULL;
+
+	return setting->value;
+}
+
+bool __vpn_provider_check_routes(struct vpn_provider *provider)
+{
+	if (!provider)
+		return false;
+
+	if (provider->user_routes &&
+			g_hash_table_size(provider->user_routes) > 0)
+		return true;
+
+	if (provider->routes &&
+			g_hash_table_size(provider->routes) > 0)
+		return true;
+
+	return false;
+}
+
+void *vpn_provider_get_data(struct vpn_provider *provider)
+{
+	return provider->driver_data;
+}
+
+void vpn_provider_set_data(struct vpn_provider *provider, void *data)
+{
+	provider->driver_data = data;
+}
+
+void vpn_provider_set_index(struct vpn_provider *provider, int index)
+{
+	DBG("index %d provider %p", index, provider);
+
+	if (!provider->ipconfig_ipv4) {
+		provider->ipconfig_ipv4 = __vpn_ipconfig_create(index,
+								AF_INET);
+		if (!provider->ipconfig_ipv4) {
+			DBG("Couldnt create ipconfig for IPv4");
+			goto done;
+		}
+	}
+
+	__vpn_ipconfig_set_index(provider->ipconfig_ipv4, index);
+
+	if (!provider->ipconfig_ipv6) {
+		provider->ipconfig_ipv6 = __vpn_ipconfig_create(index,
+								AF_INET6);
+		if (!provider->ipconfig_ipv6) {
+			DBG("Couldnt create ipconfig for IPv6");
+			goto done;
+		}
+	}
+
+	__vpn_ipconfig_set_index(provider->ipconfig_ipv6, index);
+
+done:
+	provider->index = index;
+}
+
+int vpn_provider_get_index(struct vpn_provider *provider)
+{
+	return provider->index;
+}
+
+int vpn_provider_set_ipaddress(struct vpn_provider *provider,
+					struct connman_ipaddress *ipaddress)
+{
+	struct vpn_ipconfig *ipconfig = NULL;
+
+	switch (ipaddress->family) {
+	case AF_INET:
+		ipconfig = provider->ipconfig_ipv4;
+		break;
+	case AF_INET6:
+		ipconfig = provider->ipconfig_ipv6;
+		break;
+	default:
+		break;
+	}
+
+	DBG("provider %p state %d ipconfig %p family %d", provider,
+		provider->state, ipconfig, ipaddress->family);
+
+	if (!ipconfig)
+		return -EINVAL;
+
+	provider->family = ipaddress->family;
+
+	if (provider->state == VPN_PROVIDER_STATE_CONNECT ||
+			provider->state == VPN_PROVIDER_STATE_READY) {
+		struct connman_ipaddress *addr =
+					__vpn_ipconfig_get_address(ipconfig);
+
+		/*
+		 * Remember the old address so that we can remove it in notify
+		 * function in plugins/vpn.c if we ever restart
+		 */
+		if (ipaddress->family == AF_INET6) {
+			connman_ipaddress_free(provider->prev_ipv6_addr);
+			provider->prev_ipv6_addr =
+						connman_ipaddress_copy(addr);
+		} else {
+			connman_ipaddress_free(provider->prev_ipv4_addr);
+			provider->prev_ipv4_addr =
+						connman_ipaddress_copy(addr);
+		}
+	}
+
+	if (ipaddress->local) {
+		__vpn_ipconfig_set_local(ipconfig, ipaddress->local);
+		__vpn_ipconfig_set_peer(ipconfig, ipaddress->peer);
+		__vpn_ipconfig_set_broadcast(ipconfig, ipaddress->broadcast);
+		__vpn_ipconfig_set_gateway(ipconfig, ipaddress->gateway);
+		__vpn_ipconfig_set_prefixlen(ipconfig, ipaddress->prefixlen);
+	}
+
+	return 0;
+}
+
+int vpn_provider_set_pac(struct vpn_provider *provider,
+				const char *pac)
+{
+	DBG("provider %p pac %s", provider, pac);
+
+	return 0;
+}
+
+
+int vpn_provider_set_domain(struct vpn_provider *provider,
+					const char *domain)
+{
+	DBG("provider %p domain %s", provider, domain);
+
+	g_free(provider->domain);
+	provider->domain = g_strdup(domain);
+
+	return 0;
+}
+
+int vpn_provider_set_nameservers(struct vpn_provider *provider,
+					const char *nameservers)
+{
+	DBG("provider %p nameservers %s", provider, nameservers);
+
+	g_strfreev(provider->nameservers);
+	provider->nameservers = NULL;
+
+	if (!nameservers)
+		return 0;
+
+	provider->nameservers = g_strsplit(nameservers, " ", 0);
+
+	return 0;
+}
+
+enum provider_route_type {
+	PROVIDER_ROUTE_TYPE_NONE = 0,
+	PROVIDER_ROUTE_TYPE_MASK = 1,
+	PROVIDER_ROUTE_TYPE_ADDR = 2,
+	PROVIDER_ROUTE_TYPE_GW   = 3,
+};
+
+static int route_env_parse(struct vpn_provider *provider, const char *key,
+				int *family, unsigned long *idx,
+				enum provider_route_type *type)
+{
+	char *end;
+	const char *start;
+
+	DBG("name %s", provider->name);
+
+	if (!strcmp(provider->type, "openvpn")) {
+		if (g_str_has_prefix(key, "route_network_")) {
+			start = key + strlen("route_network_");
+			*type = PROVIDER_ROUTE_TYPE_ADDR;
+		} else if (g_str_has_prefix(key, "route_netmask_")) {
+			start = key + strlen("route_netmask_");
+			*type = PROVIDER_ROUTE_TYPE_MASK;
+		} else if (g_str_has_prefix(key, "route_gateway_")) {
+			start = key + strlen("route_gateway_");
+			*type = PROVIDER_ROUTE_TYPE_GW;
+		} else
+			return -EINVAL;
+
+		*family = AF_INET;
+		*idx = g_ascii_strtoull(start, &end, 10);
+
+	} else if (!strcmp(provider->type, "openconnect")) {
+		if (g_str_has_prefix(key, "CISCO_SPLIT_INC_")) {
+			*family = AF_INET;
+			start = key + strlen("CISCO_SPLIT_INC_");
+		} else if (g_str_has_prefix(key,
+					"CISCO_IPV6_SPLIT_INC_")) {
+			*family = AF_INET6;
+			start = key + strlen("CISCO_IPV6_SPLIT_INC_");
+		} else
+			return -EINVAL;
+
+		*idx = g_ascii_strtoull(start, &end, 10);
+
+		if (strncmp(end, "_ADDR", 5) == 0)
+			*type = PROVIDER_ROUTE_TYPE_ADDR;
+		else if (strncmp(end, "_MASK", 5) == 0)
+			*type = PROVIDER_ROUTE_TYPE_MASK;
+		else if (strncmp(end, "_MASKLEN", 8) == 0 &&
+				*family == AF_INET6) {
+			*type = PROVIDER_ROUTE_TYPE_MASK;
+		} else
+			return -EINVAL;
+	}
+
+	return 0;
+}
+
+int vpn_provider_append_route(struct vpn_provider *provider,
+					const char *key, const char *value)
+{
+	struct vpn_route *route;
+	int ret, family = 0;
+	unsigned long idx = 0;
+	enum provider_route_type type = PROVIDER_ROUTE_TYPE_NONE;
+
+	DBG("key %s value %s", key, value);
+
+	ret = route_env_parse(provider, key, &family, &idx, &type);
+	if (ret < 0)
+		return ret;
+
+	DBG("idx %lu family %d type %d", idx, family, type);
+
+	route = g_hash_table_lookup(provider->routes, GINT_TO_POINTER(idx));
+	if (!route) {
+		route = g_try_new0(struct vpn_route, 1);
+		if (!route) {
+			connman_error("out of memory");
+			return -ENOMEM;
+		}
+
+		route->family = family;
+
+		g_hash_table_replace(provider->routes, GINT_TO_POINTER(idx),
+						route);
+	}
+
+	switch (type) {
+	case PROVIDER_ROUTE_TYPE_NONE:
+		break;
+	case PROVIDER_ROUTE_TYPE_MASK:
+		route->netmask = g_strdup(value);
+		break;
+	case PROVIDER_ROUTE_TYPE_ADDR:
+		route->network = g_strdup(value);
+		break;
+	case PROVIDER_ROUTE_TYPE_GW:
+		route->gateway = g_strdup(value);
+		break;
+	}
+
+	if (!handle_routes) {
+		if (route->netmask && route->gateway &&
+							route->network)
+			provider_schedule_changed(provider);
+	}
+
+	return 0;
+}
+
+const char *vpn_provider_get_driver_name(struct vpn_provider *provider)
+{
+	if (!provider->driver)
+		return NULL;
+
+	return provider->driver->name;
+}
+
+const char *vpn_provider_get_save_group(struct vpn_provider *provider)
+{
+	return provider->identifier;
+}
+
+static gint compare_priority(gconstpointer a, gconstpointer b)
+{
+	return 0;
+}
+
+static void clean_provider(gpointer key, gpointer value, gpointer user_data)
+{
+	struct vpn_provider *provider = value;
+
+	if (provider->driver && provider->driver->remove)
+		provider->driver->remove(provider);
+
+	connection_unregister(provider);
+}
+
+int vpn_provider_driver_register(struct vpn_provider_driver *driver)
+{
+	DBG("driver %p name %s", driver, driver->name);
+
+	driver_list = g_slist_insert_sorted(driver_list, driver,
+							compare_priority);
+	provider_create_all_from_type(driver->name);
+	return 0;
+}
+
+void vpn_provider_driver_unregister(struct vpn_provider_driver *driver)
+{
+	GHashTableIter iter;
+	gpointer value, key;
+
+	DBG("driver %p name %s", driver, driver->name);
+
+	driver_list = g_slist_remove(driver_list, driver);
+
+	g_hash_table_iter_init(&iter, provider_hash);
+	while (g_hash_table_iter_next(&iter, &key, &value)) {
+		struct vpn_provider *provider = value;
+
+		if (provider && provider->driver &&
+				provider->driver->type == driver->type &&
+				g_strcmp0(provider->driver->name,
+							driver->name) == 0) {
+			provider->driver = NULL;
+		}
+	}
+}
+
+const char *vpn_provider_get_name(struct vpn_provider *provider)
+{
+	return provider->name;
+}
+
+const char *vpn_provider_get_host(struct vpn_provider *provider)
+{
+	return provider->host;
+}
+
+const char *vpn_provider_get_path(struct vpn_provider *provider)
+{
+	return provider->path;
+}
+
+void vpn_provider_change_address(struct vpn_provider *provider)
+{
+	switch (provider->family) {
+	case AF_INET:
+		connman_inet_set_address(provider->index,
+			__vpn_ipconfig_get_address(provider->ipconfig_ipv4));
+		break;
+	case AF_INET6:
+		connman_inet_set_ipv6_address(provider->index,
+			__vpn_ipconfig_get_address(provider->ipconfig_ipv6));
+		break;
+	default:
+		break;
+	}
+}
+
+void vpn_provider_clear_address(struct vpn_provider *provider, int family)
+{
+	const char *address;
+	unsigned char len;
+
+	DBG("provider %p family %d ipv4 %p ipv6 %p", provider, family,
+		provider->prev_ipv4_addr, provider->prev_ipv6_addr);
+
+	switch (family) {
+	case AF_INET:
+		if (provider->prev_ipv4_addr) {
+			connman_ipaddress_get_ip(provider->prev_ipv4_addr,
+						&address, &len);
+
+			DBG("ipv4 %s/%d", address, len);
+
+			connman_inet_clear_address(provider->index,
+					provider->prev_ipv4_addr);
+			connman_ipaddress_free(provider->prev_ipv4_addr);
+			provider->prev_ipv4_addr = NULL;
+		}
+		break;
+	case AF_INET6:
+		if (provider->prev_ipv6_addr) {
+			connman_ipaddress_get_ip(provider->prev_ipv6_addr,
+						&address, &len);
+
+			DBG("ipv6 %s/%d", address, len);
+
+			connman_inet_clear_ipv6_address(provider->index,
+							address, len);
+
+			connman_ipaddress_free(provider->prev_ipv6_addr);
+			provider->prev_ipv6_addr = NULL;
+		}
+		break;
+	default:
+		break;
+	}
+}
+
+static int agent_probe(struct connman_agent *agent)
+{
+	DBG("agent %p", agent);
+	return 0;
+}
+
+static void agent_remove(struct connman_agent *agent)
+{
+	DBG("agent %p", agent);
+}
+
+static struct connman_agent_driver agent_driver = {
+	.name		= "vpn",
+	.interface      = VPN_AGENT_INTERFACE,
+	.probe		= agent_probe,
+	.remove		= agent_remove,
+};
+
+static void remove_unprovisioned_providers(void)
+{
+	gchar **providers;
+	GKeyFile *keyfile, *configkeyfile;
+	char *file, *section;
+	int i = 0;
+
+	providers = __connman_storage_get_providers();
+	if (!providers)
+		return;
+
+	for (; providers[i]; i++) {
+		char *group = providers[i] + sizeof("provider_") - 1;
+		file = section = NULL;
+		keyfile = configkeyfile = NULL;
+
+		keyfile = __connman_storage_load_provider(group);
+		if (!keyfile)
+			continue;
+
+		file = __vpn_config_get_string(keyfile, group,
+					"Config.file", NULL);
+		if (!file)
+			goto next;
+
+		section = __vpn_config_get_string(keyfile, group,
+					"Config.ident", NULL);
+		if (!section)
+			goto next;
+
+		configkeyfile = __connman_storage_load_provider_config(file);
+		if (!configkeyfile) {
+			/*
+			 * Config file is missing, remove the provisioned
+			 * service.
+			 */
+			__connman_storage_remove_provider(group);
+			goto next;
+		}
+
+		if (!g_key_file_has_group(configkeyfile, section))
+			/*
+			 * Config section is missing, remove the provisioned
+			 * service.
+			 */
+			__connman_storage_remove_provider(group);
+
+	next:
+		if (keyfile)
+			g_key_file_free(keyfile);
+
+		if (configkeyfile)
+			g_key_file_free(configkeyfile);
+
+		g_free(section);
+		g_free(file);
+	}
+
+	g_strfreev(providers);
+}
+
+int __vpn_provider_init(bool do_routes)
+{
+	int err;
+
+	DBG("");
+
+	handle_routes = do_routes;
+
+	err = connman_agent_driver_register(&agent_driver);
+	if (err < 0) {
+		connman_error("Cannot register agent driver for %s",
+						agent_driver.name);
+		return err;
+	}
+
+	connection = connman_dbus_get_connection();
+
+	remove_unprovisioned_providers();
+
+	provider_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
+						NULL, unregister_provider);
+	return 0;
+}
+
+void __vpn_provider_cleanup(void)
+{
+	DBG("");
+
+	connman_agent_driver_unregister(&agent_driver);
+
+	g_hash_table_foreach(provider_hash, clean_provider, NULL);
+
+	g_hash_table_destroy(provider_hash);
+	provider_hash = NULL;
+
+	dbus_connection_unref(connection);
+}
diff --git a/connman/vpn/vpn-provider.h b/connman/vpn/vpn-provider.h
new file mode 100644
index 0000000..8105d7f
--- /dev/null
+++ b/connman/vpn/vpn-provider.h
@@ -0,0 +1,144 @@
+/*
+ *
+ *  ConnMan VPN daemon
+ *
+ *  Copyright (C) 2007-2013  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 __VPN_PROVIDER_H
+#define __VPN_PROVIDER_H
+
+#include <stdbool.h>
+
+#include <glib.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * SECTION:provider
+ * @title: Provider premitives
+ * @short_description: Functions for handling providers
+ */
+
+enum vpn_provider_type {
+	VPN_PROVIDER_TYPE_UNKNOWN = 0,
+	VPN_PROVIDER_TYPE_VPN     = 1,
+};
+
+enum vpn_provider_state {
+	VPN_PROVIDER_STATE_UNKNOWN       = 0,
+	VPN_PROVIDER_STATE_IDLE          = 1,
+	VPN_PROVIDER_STATE_CONNECT       = 2,
+	VPN_PROVIDER_STATE_READY         = 3,
+	VPN_PROVIDER_STATE_DISCONNECT    = 4,
+	VPN_PROVIDER_STATE_FAILURE       = 5,
+};
+
+enum vpn_provider_error {
+	VPN_PROVIDER_ERROR_UNKNOWN		= 0,
+	VPN_PROVIDER_ERROR_CONNECT_FAILED	= 1,
+	VPN_PROVIDER_ERROR_LOGIN_FAILED	= 2,
+	VPN_PROVIDER_ERROR_AUTH_FAILED	= 3,
+};
+
+struct vpn_provider;
+struct connman_ipaddress;
+
+#define vpn_provider_ref(provider) \
+	vpn_provider_ref_debug(provider, __FILE__, __LINE__, __func__)
+
+#define vpn_provider_unref(provider) \
+	vpn_provider_unref_debug(provider, __FILE__, __LINE__, __func__)
+
+struct vpn_provider *
+vpn_provider_ref_debug(struct vpn_provider *provider,
+			const char *file, int line, const char *caller);
+void vpn_provider_unref_debug(struct vpn_provider *provider,
+			const char *file, int line, const char *caller);
+
+int vpn_provider_set_string(struct vpn_provider *provider,
+					const char *key, const char *value);
+int vpn_provider_set_string_hide_value(struct vpn_provider *provider,
+					const char *key, const char *value);
+const char *vpn_provider_get_string(struct vpn_provider *provider,
+							const char *key);
+
+int vpn_provider_set_state(struct vpn_provider *provider,
+					enum vpn_provider_state state);
+
+int vpn_provider_indicate_error(struct vpn_provider *provider,
+					enum vpn_provider_error error);
+
+void vpn_provider_set_index(struct vpn_provider *provider, int index);
+int vpn_provider_get_index(struct vpn_provider *provider);
+
+void vpn_provider_set_data(struct vpn_provider *provider, void *data);
+void *vpn_provider_get_data(struct vpn_provider *provider);
+int vpn_provider_set_ipaddress(struct vpn_provider *provider,
+					struct connman_ipaddress *ipaddress);
+int vpn_provider_set_pac(struct vpn_provider *provider,
+				const char *pac);
+int vpn_provider_set_domain(struct vpn_provider *provider,
+				const char *domain);
+int vpn_provider_set_nameservers(struct vpn_provider *provider,
+					const char *nameservers);
+int vpn_provider_append_route(struct vpn_provider *provider,
+					const char *key, const char *value);
+
+const char *vpn_provider_get_driver_name(struct vpn_provider *provider);
+const char *vpn_provider_get_save_group(struct vpn_provider *provider);
+
+const char *vpn_provider_get_name(struct vpn_provider *provider);
+const char *vpn_provider_get_host(struct vpn_provider *provider);
+const char *vpn_provider_get_path(struct vpn_provider *provider);
+void vpn_provider_change_address(struct vpn_provider *provider);
+void vpn_provider_clear_address(struct vpn_provider *provider, int family);
+
+typedef void (* vpn_provider_connect_cb_t) (struct vpn_provider *provider,
+					void *user_data, int error);
+
+typedef void (* vpn_provider_auth_cb_t) (struct vpn_provider *provider,
+					const char *authenticator,
+					const char *error, void *user_data);
+
+typedef void (* vpn_provider_password_cb_t) (struct vpn_provider *provider,
+					const char *username,
+					const char *password,
+					const char *error, void *user_data);
+
+struct vpn_provider_driver {
+	const char *name;
+	enum vpn_provider_type type;
+	int (*probe) (struct vpn_provider *provider);
+	int (*remove) (struct vpn_provider *provider);
+	int (*connect) (struct vpn_provider *provider,
+			vpn_provider_connect_cb_t cb, const char *dbus_sender,
+			void *user_data);
+	int (*disconnect) (struct vpn_provider *provider);
+	int (*save) (struct vpn_provider *provider, GKeyFile *keyfile);
+};
+
+int vpn_provider_driver_register(struct vpn_provider_driver *driver);
+void vpn_provider_driver_unregister(struct vpn_provider_driver *driver);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __VPN_PROVIDER_H */
diff --git a/connman/vpn/vpn-rtnl.c b/connman/vpn/vpn-rtnl.c
new file mode 100644
index 0000000..a7565db
--- /dev/null
+++ b/connman/vpn/vpn-rtnl.c
@@ -0,0 +1,1181 @@
+/*
+ *
+ *  ConnMan VPN daemon
+ *
+ *  Copyright (C) 2012-2013  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 <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <sys/socket.h>
+#include <sys/ioctl.h>
+#include <arpa/inet.h>
+#include <netinet/ether.h>
+#include <netinet/icmp6.h>
+#include <net/if_arp.h>
+#include <linux/if.h>
+#include <linux/netlink.h>
+#include <linux/rtnetlink.h>
+#include <linux/wireless.h>
+
+#include <glib.h>
+
+#include <connman/log.h>
+
+#include "vpn.h"
+
+#include "vpn-rtnl.h"
+
+#ifndef ARPHDR_PHONET_PIPE
+#define ARPHDR_PHONET_PIPE (821)
+#endif
+
+#define print(arg...) do { if (0) connman_info(arg); } while (0)
+#define debug(arg...) do { if (0) DBG(arg); } while (0)
+
+struct watch_data {
+	unsigned int id;
+	int index;
+	vpn_rtnl_link_cb_t newlink;
+	void *user_data;
+};
+
+static GSList *watch_list = NULL;
+static unsigned int watch_id = 0;
+
+static GSList *update_list = NULL;
+static guint update_interval = G_MAXUINT;
+static guint update_timeout = 0;
+
+struct interface_data {
+	int index;
+	char *ident;
+};
+
+static GHashTable *interface_list = NULL;
+
+static void free_interface(gpointer data)
+{
+	struct interface_data *interface = data;
+
+	g_free(interface->ident);
+	g_free(interface);
+}
+
+/**
+ * vpn_rtnl_add_newlink_watch:
+ * @index: network device index
+ * @callback: callback function
+ * @user_data: callback data;
+ *
+ * Add a new RTNL watch for newlink events
+ *
+ * Returns: %0 on failure and a unique id on success
+ */
+unsigned int vpn_rtnl_add_newlink_watch(int index,
+			vpn_rtnl_link_cb_t callback, void *user_data)
+{
+	struct watch_data *watch;
+
+	watch = g_try_new0(struct watch_data, 1);
+	if (!watch)
+		return 0;
+
+	watch->id = ++watch_id;
+	watch->index = index;
+
+	watch->newlink = callback;
+	watch->user_data = user_data;
+
+	watch_list = g_slist_prepend(watch_list, watch);
+
+	DBG("id %d", watch->id);
+
+	if (callback) {
+		unsigned int flags = __vpn_ipconfig_get_flags_from_index(index);
+
+		if (flags > 0)
+			callback(flags, 0, user_data);
+	}
+
+	return watch->id;
+}
+
+/**
+ * vpn_rtnl_remove_watch:
+ * @id: watch identifier
+ *
+ * Remove the RTNL watch for the identifier
+ */
+void vpn_rtnl_remove_watch(unsigned int id)
+{
+	GSList *list;
+
+	DBG("id %d", id);
+
+	if (id == 0)
+		return;
+
+	for (list = watch_list; list; list = list->next) {
+		struct watch_data *watch = list->data;
+
+		if (watch->id  == id) {
+			watch_list = g_slist_remove(watch_list, watch);
+			g_free(watch);
+			break;
+		}
+	}
+}
+
+static void trigger_rtnl(int index, void *user_data)
+{
+	struct vpn_rtnl *rtnl = user_data;
+
+	if (rtnl->newlink) {
+		unsigned short type = __vpn_ipconfig_get_type_from_index(index);
+		unsigned int flags = __vpn_ipconfig_get_flags_from_index(index);
+
+		rtnl->newlink(type, index, flags, 0);
+	}
+}
+
+static GSList *rtnl_list = NULL;
+
+static gint compare_priority(gconstpointer a, gconstpointer b)
+{
+	const struct vpn_rtnl *rtnl1 = a;
+	const struct vpn_rtnl *rtnl2 = b;
+
+	return rtnl2->priority - rtnl1->priority;
+}
+
+/**
+ * vpn_rtnl_register:
+ * @rtnl: RTNL module
+ *
+ * Register a new RTNL module
+ *
+ * Returns: %0 on success
+ */
+int vpn_rtnl_register(struct vpn_rtnl *rtnl)
+{
+	DBG("rtnl %p name %s", rtnl, rtnl->name);
+
+	rtnl_list = g_slist_insert_sorted(rtnl_list, rtnl,
+							compare_priority);
+
+	__vpn_ipconfig_foreach(trigger_rtnl, rtnl);
+
+	return 0;
+}
+
+/**
+ * vpn_rtnl_unregister:
+ * @rtnl: RTNL module
+ *
+ * Remove a previously registered RTNL module
+ */
+void vpn_rtnl_unregister(struct vpn_rtnl *rtnl)
+{
+	DBG("rtnl %p name %s", rtnl, rtnl->name);
+
+	rtnl_list = g_slist_remove(rtnl_list, rtnl);
+}
+
+static const char *operstate2str(unsigned char operstate)
+{
+	switch (operstate) {
+	case IF_OPER_UNKNOWN:
+		return "UNKNOWN";
+	case IF_OPER_NOTPRESENT:
+		return "NOT-PRESENT";
+	case IF_OPER_DOWN:
+		return "DOWN";
+	case IF_OPER_LOWERLAYERDOWN:
+		return "LOWER-LAYER-DOWN";
+	case IF_OPER_TESTING:
+		return "TESTING";
+	case IF_OPER_DORMANT:
+		return "DORMANT";
+	case IF_OPER_UP:
+		return "UP";
+	}
+
+	return "";
+}
+
+static void extract_link(struct ifinfomsg *msg, int bytes,
+				struct ether_addr *address, const char **ifname,
+				unsigned int *mtu, unsigned char *operstate,
+						struct rtnl_link_stats *stats)
+{
+	struct rtattr *attr;
+
+	for (attr = IFLA_RTA(msg); RTA_OK(attr, bytes);
+					attr = RTA_NEXT(attr, bytes)) {
+		switch (attr->rta_type) {
+		case IFLA_ADDRESS:
+			if (address)
+				memcpy(address, RTA_DATA(attr), ETH_ALEN);
+			break;
+		case IFLA_IFNAME:
+			if (ifname)
+				*ifname = RTA_DATA(attr);
+			break;
+		case IFLA_MTU:
+			if (mtu)
+				*mtu = *((unsigned int *) RTA_DATA(attr));
+			break;
+		case IFLA_STATS:
+			if (stats)
+				memcpy(stats, RTA_DATA(attr),
+					sizeof(struct rtnl_link_stats));
+			break;
+		case IFLA_OPERSTATE:
+			if (operstate)
+				*operstate = *((unsigned char *) RTA_DATA(attr));
+			break;
+		case IFLA_LINKMODE:
+			break;
+		}
+	}
+}
+
+static void process_newlink(unsigned short type, int index, unsigned flags,
+			unsigned change, struct ifinfomsg *msg, int bytes)
+{
+	struct ether_addr address = {{ 0, 0, 0, 0, 0, 0 }};
+	struct ether_addr compare = {{ 0, 0, 0, 0, 0, 0 }};
+	struct rtnl_link_stats stats;
+	unsigned char operstate = 0xff;
+	struct interface_data *interface;
+	const char *ifname = NULL;
+	unsigned int mtu = 0;
+	char ident[13], str[18];
+	GSList *list;
+
+	memset(&stats, 0, sizeof(stats));
+	extract_link(msg, bytes, &address, &ifname, &mtu, &operstate, &stats);
+
+	snprintf(ident, 13, "%02x%02x%02x%02x%02x%02x",
+						address.ether_addr_octet[0],
+						address.ether_addr_octet[1],
+						address.ether_addr_octet[2],
+						address.ether_addr_octet[3],
+						address.ether_addr_octet[4],
+						address.ether_addr_octet[5]);
+
+	snprintf(str, 18, "%02X:%02X:%02X:%02X:%02X:%02X",
+						address.ether_addr_octet[0],
+						address.ether_addr_octet[1],
+						address.ether_addr_octet[2],
+						address.ether_addr_octet[3],
+						address.ether_addr_octet[4],
+						address.ether_addr_octet[5]);
+
+	switch (type) {
+	case ARPHRD_ETHER:
+	case ARPHRD_LOOPBACK:
+	case ARPHDR_PHONET_PIPE:
+	case ARPHRD_NONE:
+		__vpn_ipconfig_newlink(index, type, flags,
+							str, mtu, &stats);
+		break;
+	}
+
+	if (memcmp(&address, &compare, ETH_ALEN) != 0)
+		connman_info("%s {newlink} index %d address %s mtu %u",
+						ifname, index, str, mtu);
+
+	if (operstate != 0xff)
+		connman_info("%s {newlink} index %d operstate %u <%s>",
+						ifname, index, operstate,
+						operstate2str(operstate));
+
+	interface = g_hash_table_lookup(interface_list, GINT_TO_POINTER(index));
+	if (!interface) {
+		interface = g_new0(struct interface_data, 1);
+		interface->index = index;
+		interface->ident = g_strdup(ident);
+
+		g_hash_table_insert(interface_list,
+					GINT_TO_POINTER(index), interface);
+	}
+
+	for (list = rtnl_list; list; list = list->next) {
+		struct vpn_rtnl *rtnl = list->data;
+
+		if (rtnl->newlink)
+			rtnl->newlink(type, index, flags, change);
+	}
+
+	for (list = watch_list; list; list = list->next) {
+		struct watch_data *watch = list->data;
+
+		if (watch->index != index)
+			continue;
+
+		if (watch->newlink)
+			watch->newlink(flags, change, watch->user_data);
+	}
+}
+
+static void process_dellink(unsigned short type, int index, unsigned flags,
+			unsigned change, struct ifinfomsg *msg, int bytes)
+{
+	struct rtnl_link_stats stats;
+	unsigned char operstate = 0xff;
+	const char *ifname = NULL;
+	GSList *list;
+
+	memset(&stats, 0, sizeof(stats));
+	extract_link(msg, bytes, NULL, &ifname, NULL, &operstate, &stats);
+
+	if (operstate != 0xff)
+		connman_info("%s {dellink} index %d operstate %u <%s>",
+						ifname, index, operstate,
+						operstate2str(operstate));
+
+	for (list = rtnl_list; list; list = list->next) {
+		struct vpn_rtnl *rtnl = list->data;
+
+		if (rtnl->dellink)
+			rtnl->dellink(type, index, flags, change);
+	}
+
+	switch (type) {
+	case ARPHRD_ETHER:
+	case ARPHRD_LOOPBACK:
+	case ARPHRD_NONE:
+		__vpn_ipconfig_dellink(index, &stats);
+		break;
+	}
+
+	g_hash_table_remove(interface_list, GINT_TO_POINTER(index));
+}
+
+static void extract_ipv4_route(struct rtmsg *msg, int bytes, int *index,
+						struct in_addr *dst,
+						struct in_addr *gateway)
+{
+	struct rtattr *attr;
+
+	for (attr = RTM_RTA(msg); RTA_OK(attr, bytes);
+					attr = RTA_NEXT(attr, bytes)) {
+		switch (attr->rta_type) {
+		case RTA_DST:
+			if (dst)
+				*dst = *((struct in_addr *) RTA_DATA(attr));
+			break;
+		case RTA_GATEWAY:
+			if (gateway)
+				*gateway = *((struct in_addr *) RTA_DATA(attr));
+			break;
+		case RTA_OIF:
+			if (index)
+				*index = *((int *) RTA_DATA(attr));
+			break;
+		}
+	}
+}
+
+static void extract_ipv6_route(struct rtmsg *msg, int bytes, int *index,
+						struct in6_addr *dst,
+						struct in6_addr *gateway)
+{
+	struct rtattr *attr;
+
+	for (attr = RTM_RTA(msg); RTA_OK(attr, bytes);
+					attr = RTA_NEXT(attr, bytes)) {
+		switch (attr->rta_type) {
+		case RTA_DST:
+			if (dst)
+				*dst = *((struct in6_addr *) RTA_DATA(attr));
+			break;
+		case RTA_GATEWAY:
+			if (gateway)
+				*gateway =
+					*((struct in6_addr *) RTA_DATA(attr));
+			break;
+		case RTA_OIF:
+			if (index)
+				*index = *((int *) RTA_DATA(attr));
+			break;
+		}
+	}
+}
+
+static void process_newroute(unsigned char family, unsigned char scope,
+						struct rtmsg *msg, int bytes)
+{
+	GSList *list;
+	char dststr[INET6_ADDRSTRLEN], gatewaystr[INET6_ADDRSTRLEN];
+	int index = -1;
+
+	if (family == AF_INET) {
+		struct in_addr dst = { INADDR_ANY }, gateway = { INADDR_ANY };
+
+		extract_ipv4_route(msg, bytes, &index, &dst, &gateway);
+
+		inet_ntop(family, &dst, dststr, sizeof(dststr));
+		inet_ntop(family, &gateway, gatewaystr, sizeof(gatewaystr));
+
+		/* skip host specific routes */
+		if (scope != RT_SCOPE_UNIVERSE &&
+			!(scope == RT_SCOPE_LINK && dst.s_addr == INADDR_ANY))
+			return;
+
+		if (dst.s_addr != INADDR_ANY)
+			return;
+
+	} else if (family == AF_INET6) {
+		struct in6_addr dst = IN6ADDR_ANY_INIT,
+				gateway = IN6ADDR_ANY_INIT;
+
+		extract_ipv6_route(msg, bytes, &index, &dst, &gateway);
+
+		inet_ntop(family, &dst, dststr, sizeof(dststr));
+		inet_ntop(family, &gateway, gatewaystr, sizeof(gatewaystr));
+
+		/* skip host specific routes */
+		if (scope != RT_SCOPE_UNIVERSE &&
+			!(scope == RT_SCOPE_LINK &&
+				IN6_IS_ADDR_UNSPECIFIED(&dst)))
+			return;
+
+		if (!IN6_IS_ADDR_UNSPECIFIED(&dst))
+			return;
+	} else
+		return;
+
+	for (list = rtnl_list; list; list = list->next) {
+		struct vpn_rtnl *rtnl = list->data;
+
+		if (rtnl->newgateway)
+			rtnl->newgateway(index, gatewaystr);
+	}
+}
+
+static void process_delroute(unsigned char family, unsigned char scope,
+						struct rtmsg *msg, int bytes)
+{
+	GSList *list;
+	char dststr[INET6_ADDRSTRLEN], gatewaystr[INET6_ADDRSTRLEN];
+	int index = -1;
+
+	if (family == AF_INET) {
+		struct in_addr dst = { INADDR_ANY }, gateway = { INADDR_ANY };
+
+		extract_ipv4_route(msg, bytes, &index, &dst, &gateway);
+
+		inet_ntop(family, &dst, dststr, sizeof(dststr));
+		inet_ntop(family, &gateway, gatewaystr, sizeof(gatewaystr));
+
+		/* skip host specific routes */
+		if (scope != RT_SCOPE_UNIVERSE &&
+			!(scope == RT_SCOPE_LINK && dst.s_addr == INADDR_ANY))
+			return;
+
+		if (dst.s_addr != INADDR_ANY)
+			return;
+
+	}  else if (family == AF_INET6) {
+		struct in6_addr dst = IN6ADDR_ANY_INIT,
+				gateway = IN6ADDR_ANY_INIT;
+
+		extract_ipv6_route(msg, bytes, &index, &dst, &gateway);
+
+		inet_ntop(family, &dst, dststr, sizeof(dststr));
+		inet_ntop(family, &gateway, gatewaystr, sizeof(gatewaystr));
+
+		/* skip host specific routes */
+		if (scope != RT_SCOPE_UNIVERSE &&
+			!(scope == RT_SCOPE_LINK &&
+				IN6_IS_ADDR_UNSPECIFIED(&dst)))
+			return;
+
+		if (!IN6_IS_ADDR_UNSPECIFIED(&dst))
+			return;
+	} else
+		return;
+
+	for (list = rtnl_list; list; list = list->next) {
+		struct vpn_rtnl *rtnl = list->data;
+
+		if (rtnl->delgateway)
+			rtnl->delgateway(index, gatewaystr);
+	}
+}
+
+static inline void print_ether(struct rtattr *attr, const char *name)
+{
+	int len = (int) RTA_PAYLOAD(attr);
+
+	if (len == ETH_ALEN) {
+		struct ether_addr eth;
+		memcpy(&eth, RTA_DATA(attr), ETH_ALEN);
+		print("  attr %s (len %d) %s\n", name, len, ether_ntoa(&eth));
+	} else
+		print("  attr %s (len %d)\n", name, len);
+}
+
+static inline void print_inet(struct rtattr *attr, const char *name,
+							unsigned char family)
+{
+	int len = (int) RTA_PAYLOAD(attr);
+
+	if (family == AF_INET && len == sizeof(struct in_addr)) {
+		struct in_addr addr;
+		addr = *((struct in_addr *) RTA_DATA(attr));
+		print("  attr %s (len %d) %s\n", name, len, inet_ntoa(addr));
+	} else
+		print("  attr %s (len %d)\n", name, len);
+}
+
+static inline void print_string(struct rtattr *attr, const char *name)
+{
+	print("  attr %s (len %d) %s\n", name, (int) RTA_PAYLOAD(attr),
+						(char *) RTA_DATA(attr));
+}
+
+static inline void print_byte(struct rtattr *attr, const char *name)
+{
+	print("  attr %s (len %d) 0x%02x\n", name, (int) RTA_PAYLOAD(attr),
+					*((unsigned char *) RTA_DATA(attr)));
+}
+
+static inline void print_integer(struct rtattr *attr, const char *name)
+{
+	print("  attr %s (len %d) %d\n", name, (int) RTA_PAYLOAD(attr),
+						*((int *) RTA_DATA(attr)));
+}
+
+static inline void print_attr(struct rtattr *attr, const char *name)
+{
+	int len = (int) RTA_PAYLOAD(attr);
+
+	if (name && len > 0)
+		print("  attr %s (len %d)\n", name, len);
+	else
+		print("  attr %d (len %d)\n", attr->rta_type, len);
+}
+
+static void rtnl_link(struct nlmsghdr *hdr)
+{
+	struct ifinfomsg *msg;
+	struct rtattr *attr;
+	int bytes;
+
+	msg = (struct ifinfomsg *) NLMSG_DATA(hdr);
+	bytes = IFLA_PAYLOAD(hdr);
+
+	print("ifi_index %d ifi_flags 0x%04x", msg->ifi_index, msg->ifi_flags);
+
+	for (attr = IFLA_RTA(msg); RTA_OK(attr, bytes);
+					attr = RTA_NEXT(attr, bytes)) {
+		switch (attr->rta_type) {
+		case IFLA_ADDRESS:
+			print_ether(attr, "address");
+			break;
+		case IFLA_BROADCAST:
+			print_ether(attr, "broadcast");
+			break;
+		case IFLA_IFNAME:
+			print_string(attr, "ifname");
+			break;
+		case IFLA_MTU:
+			print_integer(attr, "mtu");
+			break;
+		case IFLA_LINK:
+			print_attr(attr, "link");
+			break;
+		case IFLA_QDISC:
+			print_attr(attr, "qdisc");
+			break;
+		case IFLA_STATS:
+			print_attr(attr, "stats");
+			break;
+		case IFLA_COST:
+			print_attr(attr, "cost");
+			break;
+		case IFLA_PRIORITY:
+			print_attr(attr, "priority");
+			break;
+		case IFLA_MASTER:
+			print_attr(attr, "master");
+			break;
+		case IFLA_WIRELESS:
+			print_attr(attr, "wireless");
+			break;
+		case IFLA_PROTINFO:
+			print_attr(attr, "protinfo");
+			break;
+		case IFLA_TXQLEN:
+			print_integer(attr, "txqlen");
+			break;
+		case IFLA_MAP:
+			print_attr(attr, "map");
+			break;
+		case IFLA_WEIGHT:
+			print_attr(attr, "weight");
+			break;
+		case IFLA_OPERSTATE:
+			print_byte(attr, "operstate");
+			break;
+		case IFLA_LINKMODE:
+			print_byte(attr, "linkmode");
+			break;
+		default:
+			print_attr(attr, NULL);
+			break;
+		}
+	}
+}
+
+static void rtnl_newlink(struct nlmsghdr *hdr)
+{
+	struct ifinfomsg *msg = (struct ifinfomsg *) NLMSG_DATA(hdr);
+
+	rtnl_link(hdr);
+
+	process_newlink(msg->ifi_type, msg->ifi_index, msg->ifi_flags,
+				msg->ifi_change, msg, IFA_PAYLOAD(hdr));
+}
+
+static void rtnl_dellink(struct nlmsghdr *hdr)
+{
+	struct ifinfomsg *msg = (struct ifinfomsg *) NLMSG_DATA(hdr);
+
+	rtnl_link(hdr);
+
+	process_dellink(msg->ifi_type, msg->ifi_index, msg->ifi_flags,
+				msg->ifi_change, msg, IFA_PAYLOAD(hdr));
+}
+
+static void rtnl_route(struct nlmsghdr *hdr)
+{
+	struct rtmsg *msg;
+	struct rtattr *attr;
+	int bytes;
+
+	msg = (struct rtmsg *) NLMSG_DATA(hdr);
+	bytes = RTM_PAYLOAD(hdr);
+
+	print("rtm_family %d rtm_table %d rtm_protocol %d",
+			msg->rtm_family, msg->rtm_table, msg->rtm_protocol);
+	print("rtm_scope %d rtm_type %d rtm_flags 0x%04x",
+				msg->rtm_scope, msg->rtm_type, msg->rtm_flags);
+
+	for (attr = RTM_RTA(msg); RTA_OK(attr, bytes);
+					attr = RTA_NEXT(attr, bytes)) {
+		switch (attr->rta_type) {
+		case RTA_DST:
+			print_inet(attr, "dst", msg->rtm_family);
+			break;
+		case RTA_SRC:
+			print_inet(attr, "src", msg->rtm_family);
+			break;
+		case RTA_IIF:
+			print_string(attr, "iif");
+			break;
+		case RTA_OIF:
+			print_integer(attr, "oif");
+			break;
+		case RTA_GATEWAY:
+			print_inet(attr, "gateway", msg->rtm_family);
+			break;
+		case RTA_PRIORITY:
+			print_attr(attr, "priority");
+			break;
+		case RTA_PREFSRC:
+			print_inet(attr, "prefsrc", msg->rtm_family);
+			break;
+		case RTA_METRICS:
+			print_attr(attr, "metrics");
+			break;
+		case RTA_TABLE:
+			print_integer(attr, "table");
+			break;
+		default:
+			print_attr(attr, NULL);
+			break;
+		}
+	}
+}
+
+static bool is_route_rtmsg(struct rtmsg *msg)
+{
+
+	if (msg->rtm_table != RT_TABLE_MAIN)
+		return false;
+
+	if (msg->rtm_protocol != RTPROT_BOOT &&
+			msg->rtm_protocol != RTPROT_KERNEL)
+		return false;
+
+	if (msg->rtm_type != RTN_UNICAST)
+		return false;
+
+	return true;
+}
+
+static void rtnl_newroute(struct nlmsghdr *hdr)
+{
+	struct rtmsg *msg = (struct rtmsg *) NLMSG_DATA(hdr);
+
+	rtnl_route(hdr);
+
+	if (is_route_rtmsg(msg))
+		process_newroute(msg->rtm_family, msg->rtm_scope,
+						msg, RTM_PAYLOAD(hdr));
+}
+
+static void rtnl_delroute(struct nlmsghdr *hdr)
+{
+	struct rtmsg *msg = (struct rtmsg *) NLMSG_DATA(hdr);
+
+	rtnl_route(hdr);
+
+	if (is_route_rtmsg(msg))
+		process_delroute(msg->rtm_family, msg->rtm_scope,
+						msg, RTM_PAYLOAD(hdr));
+}
+
+static const char *type2string(uint16_t type)
+{
+	switch (type) {
+	case NLMSG_NOOP:
+		return "NOOP";
+	case NLMSG_ERROR:
+		return "ERROR";
+	case NLMSG_DONE:
+		return "DONE";
+	case NLMSG_OVERRUN:
+		return "OVERRUN";
+	case RTM_GETLINK:
+		return "GETLINK";
+	case RTM_NEWLINK:
+		return "NEWLINK";
+	case RTM_DELLINK:
+		return "DELLINK";
+	case RTM_NEWADDR:
+		return "NEWADDR";
+	case RTM_DELADDR:
+		return "DELADDR";
+	case RTM_GETROUTE:
+		return "GETROUTE";
+	case RTM_NEWROUTE:
+		return "NEWROUTE";
+	case RTM_DELROUTE:
+		return "DELROUTE";
+	case RTM_NEWNDUSEROPT:
+		return "NEWNDUSEROPT";
+	default:
+		return "UNKNOWN";
+	}
+}
+
+static GIOChannel *channel = NULL;
+
+struct rtnl_request {
+	struct nlmsghdr hdr;
+	struct rtgenmsg msg;
+};
+#define RTNL_REQUEST_SIZE  (sizeof(struct nlmsghdr) + sizeof(struct rtgenmsg))
+
+static GSList *request_list = NULL;
+static guint32 request_seq = 0;
+
+static struct rtnl_request *find_request(guint32 seq)
+{
+	GSList *list;
+
+	for (list = request_list; list; list = list->next) {
+		struct rtnl_request *req = list->data;
+
+		if (req->hdr.nlmsg_seq == seq)
+			return req;
+	}
+
+	return NULL;
+}
+
+static int send_request(struct rtnl_request *req)
+{
+	struct sockaddr_nl addr;
+	int sk;
+
+	debug("%s len %d type %d flags 0x%04x seq %d",
+				type2string(req->hdr.nlmsg_type),
+				req->hdr.nlmsg_len, req->hdr.nlmsg_type,
+				req->hdr.nlmsg_flags, req->hdr.nlmsg_seq);
+
+	sk = g_io_channel_unix_get_fd(channel);
+
+	memset(&addr, 0, sizeof(addr));
+	addr.nl_family = AF_NETLINK;
+
+	return sendto(sk, req, req->hdr.nlmsg_len, 0,
+				(struct sockaddr *) &addr, sizeof(addr));
+}
+
+static int queue_request(struct rtnl_request *req)
+{
+	request_list = g_slist_append(request_list, req);
+
+	if (g_slist_length(request_list) > 1)
+		return 0;
+
+	return send_request(req);
+}
+
+static int process_response(guint32 seq)
+{
+	struct rtnl_request *req;
+
+	debug("seq %d", seq);
+
+	req = find_request(seq);
+	if (req) {
+		request_list = g_slist_remove(request_list, req);
+		g_free(req);
+	}
+
+	req = g_slist_nth_data(request_list, 0);
+	if (!req)
+		return 0;
+
+	return send_request(req);
+}
+
+static void rtnl_message(void *buf, size_t len)
+{
+	debug("buf %p len %zd", buf, len);
+
+	while (len > 0) {
+		struct nlmsghdr *hdr = buf;
+		struct nlmsgerr *err;
+
+		if (!NLMSG_OK(hdr, len))
+			break;
+
+		debug("%s len %d type %d flags 0x%04x seq %d pid %d",
+					type2string(hdr->nlmsg_type),
+					hdr->nlmsg_len, hdr->nlmsg_type,
+					hdr->nlmsg_flags, hdr->nlmsg_seq,
+					hdr->nlmsg_pid);
+
+		switch (hdr->nlmsg_type) {
+		case NLMSG_NOOP:
+		case NLMSG_OVERRUN:
+			return;
+		case NLMSG_DONE:
+			process_response(hdr->nlmsg_seq);
+			return;
+		case NLMSG_ERROR:
+			err = NLMSG_DATA(hdr);
+			DBG("error %d (%s)", -err->error,
+						strerror(-err->error));
+			return;
+		case RTM_NEWLINK:
+			rtnl_newlink(hdr);
+			break;
+		case RTM_DELLINK:
+			rtnl_dellink(hdr);
+			break;
+		case RTM_NEWADDR:
+			break;
+		case RTM_DELADDR:
+			break;
+		case RTM_NEWROUTE:
+			rtnl_newroute(hdr);
+			break;
+		case RTM_DELROUTE:
+			rtnl_delroute(hdr);
+			break;
+		}
+
+		len -= hdr->nlmsg_len;
+		buf += hdr->nlmsg_len;
+	}
+}
+
+static gboolean netlink_event(GIOChannel *chan, GIOCondition cond, gpointer data)
+{
+	unsigned char buf[4096];
+	struct sockaddr_nl nladdr;
+	socklen_t addr_len = sizeof(nladdr);
+	ssize_t status;
+	int fd;
+
+	if (cond & (G_IO_NVAL | G_IO_HUP | G_IO_ERR))
+		return FALSE;
+
+	memset(buf, 0, sizeof(buf));
+	memset(&nladdr, 0, sizeof(nladdr));
+
+	fd = g_io_channel_unix_get_fd(chan);
+
+	status = recvfrom(fd, buf, sizeof(buf), 0,
+                       (struct sockaddr *) &nladdr, &addr_len);
+	if (status < 0) {
+		if (errno == EINTR || errno == EAGAIN)
+			return TRUE;
+
+		return FALSE;
+	}
+
+	if (status == 0)
+		return FALSE;
+
+	if (nladdr.nl_pid != 0) { /* not sent by kernel, ignore */
+		DBG("Received msg from %u, ignoring it", nladdr.nl_pid);
+		return TRUE;
+	}
+
+	rtnl_message(buf, status);
+
+	return TRUE;
+}
+
+static int send_getlink(void)
+{
+	struct rtnl_request *req;
+
+	debug("");
+
+	req = g_try_malloc0(RTNL_REQUEST_SIZE);
+	if (!req)
+		return -ENOMEM;
+
+	req->hdr.nlmsg_len = RTNL_REQUEST_SIZE;
+	req->hdr.nlmsg_type = RTM_GETLINK;
+	req->hdr.nlmsg_flags = NLM_F_REQUEST | NLM_F_DUMP;
+	req->hdr.nlmsg_pid = 0;
+	req->hdr.nlmsg_seq = request_seq++;
+	req->msg.rtgen_family = AF_INET;
+
+	return queue_request(req);
+}
+
+static int send_getaddr(void)
+{
+	struct rtnl_request *req;
+
+	debug("");
+
+	req = g_try_malloc0(RTNL_REQUEST_SIZE);
+	if (!req)
+		return -ENOMEM;
+
+	req->hdr.nlmsg_len = RTNL_REQUEST_SIZE;
+	req->hdr.nlmsg_type = RTM_GETADDR;
+	req->hdr.nlmsg_flags = NLM_F_REQUEST | NLM_F_DUMP;
+	req->hdr.nlmsg_pid = 0;
+	req->hdr.nlmsg_seq = request_seq++;
+	req->msg.rtgen_family = AF_INET;
+
+	return queue_request(req);
+}
+
+static int send_getroute(void)
+{
+	struct rtnl_request *req;
+
+	debug("");
+
+	req = g_try_malloc0(RTNL_REQUEST_SIZE);
+	if (!req)
+		return -ENOMEM;
+
+	req->hdr.nlmsg_len = RTNL_REQUEST_SIZE;
+	req->hdr.nlmsg_type = RTM_GETROUTE;
+	req->hdr.nlmsg_flags = NLM_F_REQUEST | NLM_F_DUMP;
+	req->hdr.nlmsg_pid = 0;
+	req->hdr.nlmsg_seq = request_seq++;
+	req->msg.rtgen_family = AF_INET;
+
+	return queue_request(req);
+}
+
+static gboolean update_timeout_cb(gpointer user_data)
+{
+	__vpn_rtnl_request_update();
+
+	return TRUE;
+}
+
+static void update_interval_callback(guint min)
+{
+	if (update_timeout > 0)
+		g_source_remove(update_timeout);
+
+	if (min < G_MAXUINT) {
+		update_interval = min;
+		update_timeout = g_timeout_add_seconds(update_interval,
+						update_timeout_cb, NULL);
+	} else {
+		update_timeout = 0;
+		update_interval = G_MAXUINT;
+	}
+}
+
+static gint compare_interval(gconstpointer a, gconstpointer b)
+{
+	guint val_a = GPOINTER_TO_UINT(a);
+	guint val_b = GPOINTER_TO_UINT(b);
+
+	return val_a - val_b;
+}
+
+unsigned int __vpn_rtnl_update_interval_add(unsigned int interval)
+{
+	guint min;
+
+	if (interval == 0)
+		return 0;
+
+	update_list = g_slist_insert_sorted(update_list,
+			GUINT_TO_POINTER(interval), compare_interval);
+
+	min = GPOINTER_TO_UINT(g_slist_nth_data(update_list, 0));
+	if (min < update_interval) {
+		update_interval_callback(min);
+		__vpn_rtnl_request_update();
+	}
+
+	return update_interval;
+}
+
+unsigned int __vpn_rtnl_update_interval_remove(unsigned int interval)
+{
+	guint min = G_MAXUINT;
+
+	if (interval == 0)
+		return 0;
+
+	update_list = g_slist_remove(update_list, GINT_TO_POINTER(interval));
+
+	if (update_list)
+		min = GPOINTER_TO_UINT(g_slist_nth_data(update_list, 0));
+
+	if (min > update_interval)
+		update_interval_callback(min);
+
+	return min;
+}
+
+int __vpn_rtnl_request_update(void)
+{
+	return send_getlink();
+}
+
+int __vpn_rtnl_init(void)
+{
+	struct sockaddr_nl addr;
+	int sk;
+
+	DBG("");
+
+	interface_list = g_hash_table_new_full(g_direct_hash, g_direct_equal,
+							NULL, free_interface);
+
+	sk = socket(PF_NETLINK, SOCK_DGRAM | SOCK_CLOEXEC, NETLINK_ROUTE);
+	if (sk < 0)
+		return -1;
+
+	memset(&addr, 0, sizeof(addr));
+	addr.nl_family = AF_NETLINK;
+	addr.nl_groups = RTMGRP_LINK | RTMGRP_IPV4_IFADDR | RTMGRP_IPV4_ROUTE |
+				RTMGRP_IPV6_IFADDR | RTMGRP_IPV6_ROUTE |
+				(1<<(RTNLGRP_ND_USEROPT-1));
+
+	if (bind(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
+		close(sk);
+		return -1;
+	}
+
+	channel = g_io_channel_unix_new(sk);
+	g_io_channel_set_close_on_unref(channel, TRUE);
+
+	g_io_channel_set_encoding(channel, NULL, NULL);
+	g_io_channel_set_buffered(channel, FALSE);
+
+	g_io_add_watch(channel, G_IO_IN | G_IO_NVAL | G_IO_HUP | G_IO_ERR,
+							netlink_event, NULL);
+
+	return 0;
+}
+
+void __vpn_rtnl_start(void)
+{
+	DBG("");
+
+	send_getlink();
+	send_getaddr();
+	send_getroute();
+}
+
+void __vpn_rtnl_cleanup(void)
+{
+	GSList *list;
+
+	DBG("");
+
+	for (list = watch_list; list; list = list->next) {
+		struct watch_data *watch = list->data;
+
+		DBG("removing watch %d", watch->id);
+
+		g_free(watch);
+		list->data = NULL;
+	}
+
+	g_slist_free(watch_list);
+	watch_list = NULL;
+
+	g_slist_free(update_list);
+	update_list = NULL;
+
+	for (list = request_list; list; list = list->next) {
+		struct rtnl_request *req = list->data;
+
+		debug("%s len %d type %d flags 0x%04x seq %d",
+				type2string(req->hdr.nlmsg_type),
+				req->hdr.nlmsg_len, req->hdr.nlmsg_type,
+				req->hdr.nlmsg_flags, req->hdr.nlmsg_seq);
+
+		g_free(req);
+		list->data = NULL;
+	}
+
+	g_slist_free(request_list);
+	request_list = NULL;
+
+	g_io_channel_shutdown(channel, TRUE, NULL);
+	g_io_channel_unref(channel);
+
+	channel = NULL;
+
+	g_hash_table_destroy(interface_list);
+}
diff --git a/connman/vpn/vpn-rtnl.h b/connman/vpn/vpn-rtnl.h
new file mode 100644
index 0000000..aa640a6
--- /dev/null
+++ b/connman/vpn/vpn-rtnl.h
@@ -0,0 +1,65 @@
+/*
+ *
+ *  ConnMan VPN daemon
+ *
+ *  Copyright (C) 2012  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 __VPN_RTNL_H
+#define __VPN_RTNL_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * SECTION:rtnl
+ * @title: RTNL premitives
+ * @short_description: Functions for registering RTNL modules
+ */
+
+typedef void (* vpn_rtnl_link_cb_t) (unsigned flags, unsigned change,
+							void *user_data);
+
+unsigned int vpn_rtnl_add_newlink_watch(int index,
+			vpn_rtnl_link_cb_t callback, void *user_data);
+
+void vpn_rtnl_remove_watch(unsigned int id);
+
+#define VPN_RTNL_PRIORITY_LOW      -100
+#define VPN_RTNL_PRIORITY_DEFAULT     0
+#define VPN_RTNL_PRIORITY_HIGH      100
+
+struct vpn_rtnl {
+	const char *name;
+	int priority;
+	void (*newlink) (unsigned short type, int index,
+					unsigned flags, unsigned change);
+	void (*dellink) (unsigned short type, int index,
+					unsigned flags, unsigned change);
+	void (*newgateway) (int index, const char *gateway);
+	void (*delgateway) (int index, const char *gateway);
+};
+
+int vpn_rtnl_register(struct vpn_rtnl *rtnl);
+void vpn_rtnl_unregister(struct vpn_rtnl *rtnl);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __VPN_RTNL_H */
diff --git a/connman/vpn/vpn.h b/connman/vpn/vpn.h
new file mode 100644
index 0000000..8bf86bd
--- /dev/null
+++ b/connman/vpn/vpn.h
@@ -0,0 +1,118 @@
+/*
+ *
+ *  ConnMan VPN daemon
+ *
+ *  Copyright (C) 2012-2013  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
+ *
+ */
+
+#include <stdbool.h>
+
+#include <glib.h>
+
+#define VPN_API_SUBJECT_TO_CHANGE
+
+#include <connman/dbus.h>
+
+int __vpn_manager_init(void);
+void __vpn_manager_cleanup(void);
+
+struct vpn_ipconfig;
+
+struct connman_ipaddress *__vpn_ipconfig_get_address(struct vpn_ipconfig *ipconfig);
+unsigned short __vpn_ipconfig_get_type_from_index(int index);
+unsigned int __vpn_ipconfig_get_flags_from_index(int index);
+void __vpn_ipconfig_foreach(void (*function) (int index,
+				    void *user_data), void *user_data);
+void __vpn_ipconfig_set_local(struct vpn_ipconfig *ipconfig,
+							const char *address);
+const char *__vpn_ipconfig_get_local(struct vpn_ipconfig *ipconfig);
+void __vpn_ipconfig_set_peer(struct vpn_ipconfig *ipconfig,
+						const char *address);
+const char *__vpn_ipconfig_get_peer(struct vpn_ipconfig *ipconfig);
+void __vpn_ipconfig_set_broadcast(struct vpn_ipconfig *ipconfig,
+						const char *broadcast);
+void __vpn_ipconfig_set_gateway(struct vpn_ipconfig *ipconfig,
+						const char *gateway);
+const char *__vpn_ipconfig_get_gateway(struct vpn_ipconfig *ipconfig);
+void __vpn_ipconfig_set_prefixlen(struct vpn_ipconfig *ipconfig,
+						unsigned char prefixlen);
+unsigned char __vpn_ipconfig_get_prefixlen(struct vpn_ipconfig *ipconfig);
+int __vpn_ipconfig_address_add(struct vpn_ipconfig *ipconfig, int family);
+int __vpn_ipconfig_gateway_add(struct vpn_ipconfig *ipconfig, int family);
+void __vpn_ipconfig_unref_debug(struct vpn_ipconfig *ipconfig,
+			const char *file, int line, const char *caller);
+#define __vpn_ipconfig_unref(ipconfig) \
+	__vpn_ipconfig_unref_debug(ipconfig, __FILE__, __LINE__, __func__)
+struct vpn_ipconfig *__vpn_ipconfig_create(int index, int family);
+void __vpn_ipconfig_set_index(struct vpn_ipconfig *ipconfig,
+								int index);
+struct rtnl_link_stats;
+
+void __vpn_ipconfig_newlink(int index, unsigned short type,
+				unsigned int flags, const char *address,
+				unsigned short mtu,
+				struct rtnl_link_stats *stats);
+void __vpn_ipconfig_dellink(int index, struct rtnl_link_stats *stats);
+int __vpn_ipconfig_init(void);
+void __vpn_ipconfig_cleanup(void);
+
+#include "vpn-provider.h"
+
+char *__vpn_provider_create_identifier(const char *host, const char *domain);
+bool __vpn_provider_check_routes(struct vpn_provider *provider);
+int __vpn_provider_append_user_route(struct vpn_provider *provider,
+				int family, const char *network,
+				const char *netmask, const char *gateway);
+void __vpn_provider_append_properties(struct vpn_provider *provider, DBusMessageIter *iter);
+void __vpn_provider_list(DBusMessageIter *iter, void *user_data);
+int __vpn_provider_create(DBusMessage *msg);
+int __vpn_provider_create_from_config(GHashTable *settings,
+			const char *config_ident, const char *config_entry);
+int __vpn_provider_set_string_immutable(struct vpn_provider *provider,
+					const char *key, const char *value);
+DBusMessage *__vpn_provider_get_connections(DBusMessage *msg);
+const char * __vpn_provider_get_ident(struct vpn_provider *provider);
+struct vpn_provider *__vpn_provider_lookup(const char *identifier);
+int __vpn_provider_indicate_state(struct vpn_provider *provider,
+					enum vpn_provider_state state);
+int __vpn_provider_indicate_error(struct vpn_provider *provider,
+					enum vpn_provider_error error);
+int __vpn_provider_connect(struct vpn_provider *provider, DBusMessage *msg);
+int __vpn_provider_connect_path(const char *path);
+int __vpn_provider_disconnect(struct vpn_provider *provider);
+int __vpn_provider_remove(const char *path);
+int __vpn_provider_delete(struct vpn_provider *provider);
+void __vpn_provider_cleanup(void);
+int __vpn_provider_init(bool handle_routes);
+
+#include "vpn-rtnl.h"
+
+int __vpn_rtnl_init(void);
+void __vpn_rtnl_start(void);
+void __vpn_rtnl_cleanup(void);
+
+unsigned int __vpn_rtnl_update_interval_add(unsigned int interval);
+unsigned int __vpn_rtnl_update_interval_remove(unsigned int interval);
+int __vpn_rtnl_request_update(void);
+int __vpn_rtnl_send(const void *buf, size_t len);
+
+int __vpn_config_init(void);
+void __vpn_config_cleanup(void);
+char *__vpn_config_get_string(GKeyFile *key_file,
+        const char *group_name, const char *key, GError **error);
+char **__vpn_config_get_string_list(GKeyFile *key_file,
+        const char *group_name, const char *key, gsize *length, GError **error);
diff --git a/connman/vpn/vpn.ver b/connman/vpn/vpn.ver
new file mode 100644
index 0000000..b887706
--- /dev/null
+++ b/connman/vpn/vpn.ver
@@ -0,0 +1,8 @@
+{
+	global:
+		connman_*;
+		vpn_*;
+		g_dbus_*;
+	local:
+		*;
+};