diff options
author | Marcel Holtmann <marcel@holtmann.org> | 2010-10-04 14:22:18 +0200 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2010-10-04 14:22:18 +0200 |
commit | 9f961b7c62e70d4ca1027fbe077c66123b8cfd12 (patch) | |
tree | 97cb94ac08725dad39a6547ce78a4532c3f313bb | |
parent | b3f3bd59de6bb0d3412f7a991d90a375ed1e61b7 (diff) | |
download | connman-9f961b7c62e70d4ca1027fbe077c66123b8cfd12.tar.gz connman-9f961b7c62e70d4ca1027fbe077c66123b8cfd12.tar.bz2 connman-9f961b7c62e70d4ca1027fbe077c66123b8cfd12.zip |
Remove dependency on udev
-rw-r--r-- | Makefile.am | 13 | ||||
-rw-r--r-- | README | 1 | ||||
-rw-r--r-- | configure.ac | 18 | ||||
-rw-r--r-- | src/connman.h | 13 | ||||
-rw-r--r-- | src/detect.c (renamed from src/udev-compat.c) | 18 | ||||
-rw-r--r-- | src/device.c | 2 | ||||
-rw-r--r-- | src/element.c | 2 | ||||
-rw-r--r-- | src/inet.c | 2 | ||||
-rw-r--r-- | src/main.c | 4 | ||||
-rw-r--r-- | src/rfkill.c | 2 | ||||
-rw-r--r-- | src/udev.c | 514 |
11 files changed, 18 insertions, 571 deletions
diff --git a/Makefile.am b/Makefile.am index 13587efd..4551dcee 100644 --- a/Makefile.am +++ b/Makefile.am @@ -67,7 +67,7 @@ src_connmand_SOURCES = $(gdbus_sources) $(gdhcp_sources) $(gresolv_sources) \ src/device.c src/network.c src/connection.c \ src/manager.c src/profile.c src/service.c \ src/agent.c src/notifier.c src/provider.c \ - src/resolver.c src/ipconfig.c \ + src/resolver.c src/ipconfig.c src/detect.c \ src/ipv4.c src/dhcp.c src/rtnl.c src/inet.c \ src/utsname.c src/timeserver.c src/rfkill.c \ src/wifi.c src/storage.c src/dbus.c src/config.c \ @@ -75,18 +75,12 @@ src_connmand_SOURCES = $(gdbus_sources) $(gdhcp_sources) $(gresolv_sources) \ src/session.c src/tethering.c src/ondemand.c \ src/wpad.c src/stats.c -if UDEV -src_connmand_SOURCES += src/udev.c -else -src_connmand_SOURCES += src/udev-compat.c -endif - if WIFI src_connmand_SOURCES += $(gsupplicant_sources) endif src_connmand_LDADD = $(builtin_libadd) @GLIB_LIBS@ @DBUS_LIBS@ \ - @CAPNG_LIBS@ @UDEV_LIBS@ -lresolv -ldl + @CAPNG_LIBS@ -lresolv -ldl src_connmand_LDFLAGS = -Wl,--export-dynamic \ -Wl,--version-script=$(srcdir)/src/connman.ver @@ -109,7 +103,7 @@ build_plugindir = $(plugindir) build_scriptdir = $(scriptdir) endif -AM_CFLAGS = @UDEV_CFLAGS@ @IPTC_CFLAGS@ @NETLINK_CFLAGS@ @CAPNG_CFLAGS@ \ +AM_CFLAGS = @IPTC_CFLAGS@ @NETLINK_CFLAGS@ @CAPNG_CFLAGS@ \ @DBUS_CFLAGS@ @GLIB_CFLAGS@ $(builtin_cflags) \ -DCONNMAN_PLUGIN_BUILTIN \ -DSTATEDIR=\""$(statedir)"\" \ @@ -227,7 +221,6 @@ DISTCHECK_CONFIGURE_FLAGS = --disable-gtk-doc \ --enable-pacrunner \ --enable-google \ --enable-meego \ - --enable-udev \ --enable-client \ --enable-portal \ --enable-hh2serial-gps \ @@ -31,7 +31,6 @@ In order to compile Connection Manager you need following software packages: - GCC compiler - GLib library - D-Bus library - - udev library (optional) - PolicyKit (optional) To configure run: diff --git a/configure.ac b/configure.ac index 3867f719..1b52a930 100644 --- a/configure.ac +++ b/configure.ac @@ -380,24 +380,6 @@ if (test "${enable_capng}" = "yes"); then AC_DEFINE(HAVE_CAPNG, 1, [Define to 1 if you have capabilities library.]) fi -AC_ARG_ENABLE(udev, AC_HELP_STRING([--disable-udev], - [don't use udev support even if available]), - [enable_udev=${enableval}]) -if (test "${enable_udev}" != "no"); then - PKG_CHECK_MODULES(UDEV, libudev >= 143, [enable_udev="yes"], - AC_MSG_ERROR(libudev >= 143 is required)) - UDEV_DATADIR="`$PKG_CONFIG --variable=udevdir udev`" - if (test -z "${UDEV_DATADIR}"); then - UDEV_DATADIR="${sysconfdir}/udev/rules.d" - else - UDEV_DATADIR="${UDEV_DATADIR}/rules.d" - fi - AC_SUBST(UDEV_DATADIR) -fi -AC_SUBST(UDEV_CFLAGS) -AC_SUBST(UDEV_LIBS) -AM_CONDITIONAL(UDEV, test "${enable_udev}" = "yes") - AC_ARG_ENABLE(datafiles, AC_HELP_STRING([--disable-datafiles], [don't install configuration and data files]), [enable_datafiles=${enableval}]) diff --git a/src/connman.h b/src/connman.h index 55e72ec3..4e116784 100644 --- a/src/connman.h +++ b/src/connman.h @@ -184,6 +184,12 @@ int __connman_element_disable_technology(enum connman_service_type type); gboolean __connman_element_device_isfiltered(const char *devname); +int __connman_detect_init(void); +void __connman_detect_start(void); +void __connman_detect_cleanup(void); + +connman_bool_t __connman_detect_get_blocked(int phyindex); + #include <connman/ipconfig.h> int __connman_ipconfig_init(void); @@ -280,13 +286,6 @@ void __connman_connection_cleanup(void); gboolean __connman_connection_update_gateway(void); -int __connman_udev_init(void); -void __connman_udev_start(void); -void __connman_udev_cleanup(void); -char *__connman_udev_get_devtype(const char *ifname); -void __connman_udev_rfkill(const char *sysname, connman_bool_t blocked); -connman_bool_t __connman_udev_get_blocked(int phyindex); - int __connman_wpad_init(void); void __connman_wpad_cleanup(void); void __connman_wpad_start(struct connman_service *service); diff --git a/src/udev-compat.c b/src/detect.c index 78b0233a..68a02873 100644 --- a/src/udev-compat.c +++ b/src/detect.c @@ -106,34 +106,24 @@ static struct connman_rtnl detect_rtnl = { .dellink = detect_dellink, }; -char *__connman_udev_get_devtype(const char *ifname) -{ - return NULL; -} - -void __connman_udev_rfkill(const char *sysname, connman_bool_t blocked) -{ - DBG("sysname %s blocked %d", sysname, blocked); -} - -connman_bool_t __connman_udev_get_blocked(int phyindex) +connman_bool_t __connman_detect_get_blocked(int phyindex) { return FALSE; } -int __connman_udev_init(void) +int __connman_detect_init(void) { DBG(""); return connman_rtnl_register(&detect_rtnl); } -void __connman_udev_start(void) +void __connman_detect_start(void) { DBG(""); } -void __connman_udev_cleanup(void) +void __connman_detect_cleanup(void) { GSList *list; diff --git a/src/device.c b/src/device.c index ad976b5a..315c5148 100644 --- a/src/device.c +++ b/src/device.c @@ -559,7 +559,7 @@ static int setup_device(struct connman_device *device) break; } - if (__connman_udev_get_blocked(device->phyindex) == TRUE) + if (__connman_detect_get_blocked(device->phyindex) == TRUE) return 0; if (device->offlinemode == FALSE && diff --git a/src/element.c b/src/element.c index 77b65e94..18c73e87 100644 --- a/src/element.c +++ b/src/element.c @@ -1385,7 +1385,7 @@ void __connman_element_start(void) started = TRUE; __connman_rtnl_start(); - __connman_udev_start(); + __connman_detect_start(); __connman_connection_init(); __connman_ipv4_init(); @@ -436,8 +436,6 @@ struct connman_device *connman_inet_create_device(int index) return NULL; } - __connman_udev_get_devtype(devname); - type = __connman_inet_get_device_type(index); switch (type) { @@ -236,8 +236,8 @@ int main(int argc, char *argv[]) __connman_resolver_init(); __connman_ipconfig_init(); __connman_rtnl_init(); - __connman_udev_init(); __connman_task_init(); + __connman_detect_init(); __connman_session_init(); __connman_timeserver_init(); @@ -263,8 +263,8 @@ int main(int argc, char *argv[]) __connman_timeserver_cleanup(); __connman_session_cleanup(); + __connman_detect_cleanup(); __connman_task_cleanup(); - __connman_udev_cleanup(); __connman_rtnl_cleanup(); __connman_ipconfig_cleanup(); __connman_resolver_cleanup(); diff --git a/src/rfkill.c b/src/rfkill.c index 37923054..0f54185c 100644 --- a/src/rfkill.c +++ b/src/rfkill.c @@ -125,7 +125,7 @@ static GIOStatus rfkill_process(GIOChannel *chan) switch (event->type) { case RFKILL_TYPE_ALL: case RFKILL_TYPE_WLAN: - __connman_udev_rfkill(sysname, blocked); + /* FIXME: unblock device */ break; default: break; diff --git a/src/udev.c b/src/udev.c deleted file mode 100644 index 70c760d7..00000000 --- a/src/udev.c +++ /dev/null @@ -1,514 +0,0 @@ -/* - * - * Connection Manager - * - * Copyright (C) 2007-2010 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 <sys/types.h> - -#include <libudev.h> - -#include <glib.h> - -#include "connman.h" - -static GSList *device_list = NULL; - -static struct connman_device *find_device(int index) -{ - GSList *list; - - if (index < 0) - return NULL; - - 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 enum connman_device_type string2devtype(const char *devtype) -{ - if (g_strcmp0(devtype, "wlan") == 0) - return CONNMAN_DEVICE_TYPE_WIFI; - else if (g_strcmp0(devtype, "wimax") == 0) - return CONNMAN_DEVICE_TYPE_WIMAX; - else if (g_strcmp0(devtype, "wwan") == 0) - return CONNMAN_DEVICE_TYPE_CELLULAR; - - return CONNMAN_DEVICE_TYPE_UNKNOWN; -} - -static enum connman_device_type get_device_type( - struct udev_device *udev_device, int index) -{ - const char *devtype; - - devtype = udev_device_get_devtype(udev_device); - if (devtype == NULL) - return __connman_inet_get_device_type(index); - - return string2devtype(devtype); -} - -static void add_net_device(struct udev_device *udev_device) -{ - struct udev_list_entry *entry; - struct connman_device *device; - enum connman_device_type devtype; - const char *value, *systype; - int index = -1; - - DBG(""); - - systype = udev_device_get_sysattr_value(udev_device, "type"); - if (systype == NULL || atoi(systype) != 1) - return; - - entry = udev_device_get_properties_list_entry(udev_device); - while (entry) { - const char *name = udev_list_entry_get_name(entry); - - if (g_str_has_prefix(name, "IFINDEX") == TRUE) { - const char *value = udev_list_entry_get_value(entry); - if (value != NULL) - index = atoi(value); - } - - entry = udev_list_entry_get_next(entry); - } - - if (index < 0) - return; - - devtype = get_device_type(udev_device, index); - - DBG("devtype %d", devtype); - - switch (devtype) { - case CONNMAN_DEVICE_TYPE_UNKNOWN: - case CONNMAN_DEVICE_TYPE_VENDOR: - case CONNMAN_DEVICE_TYPE_WIMAX: - case CONNMAN_DEVICE_TYPE_BLUETOOTH: - case CONNMAN_DEVICE_TYPE_CELLULAR: - case CONNMAN_DEVICE_TYPE_GPS: - return; - case CONNMAN_DEVICE_TYPE_ETHERNET: - case CONNMAN_DEVICE_TYPE_WIFI: - break; - } - - device = find_device(index); - if (device != NULL) - return; - - device = connman_inet_create_device(index); - if (device == NULL) - return; - - value = udev_device_get_sysattr_value(udev_device, "phy80211/index"); - if (value != NULL) - __connman_device_set_phyindex(device, atoi(value)); - - if (connman_device_register(device) < 0) { - connman_device_unref(device); - return; - } - - device_list = g_slist_append(device_list, device); -} - -static void remove_net_device(struct udev_device *udev_device) -{ - struct udev_list_entry *entry; - struct connman_device *device; - int index = -1; - - DBG(""); - - entry = udev_device_get_properties_list_entry(udev_device); - while (entry) { - const char *name = udev_list_entry_get_name(entry); - - if (g_str_has_prefix(name, "IFINDEX") == TRUE) { - const char *value = udev_list_entry_get_value(entry); - if (value != NULL) - index = atoi(value); - } - - entry = udev_list_entry_get_next(entry); - } - - if (index < 0) - return; - - device = find_device(index); - if (device == NULL) - return; - - device_list = g_slist_remove(device_list, device); - - connman_device_unregister(device); - connman_device_unref(device); -} - -static GSList *rfkill_list = NULL; - -struct rfkill_data { - int phyindex; - connman_bool_t blocked; -}; - -connman_bool_t __connman_udev_get_blocked(int phyindex) -{ - GSList *list; - - if (phyindex < 0) - return FALSE; - - for (list = rfkill_list; list; list = rfkill_list->next) { - struct rfkill_data *block = list->data; - - if (block->phyindex == phyindex) - return block->blocked; - } - - return FALSE; -} - -static void update_rfkill_state(int phyindex, connman_bool_t blocked) -{ - GSList *list; - struct rfkill_data *block; - - DBG("index %d blocked %d", phyindex, blocked); - - for (list = rfkill_list; list; list = rfkill_list->next) { - block = list->data; - - if (block->phyindex == phyindex) { - block->blocked = blocked; - return; - } - } - - block = g_try_new0(struct rfkill_data, 1); - if (block == NULL) - return; - - block->phyindex = phyindex; - block->blocked = blocked; - - rfkill_list = g_slist_prepend(rfkill_list, block); -} - -static void phyindex_rfkill(int phyindex, connman_bool_t blocked) -{ - GSList *list; - - if (phyindex < 0) - return; - - update_rfkill_state(phyindex, blocked); - - for (list = device_list; list; list = list->next) { - struct connman_device *device = list->data; - - if (__connman_device_get_phyindex(device) == phyindex) - __connman_device_set_blocked(device, blocked); - } -} - -static void print_properties(struct udev_device *device, const char *prefix) -{ - struct udev_list_entry *entry; - - entry = udev_device_get_properties_list_entry(device); - while (entry) { - const char *name = udev_list_entry_get_name(entry); - const char *value = udev_list_entry_get_value(entry); - - if (g_str_has_prefix(name, "CONNMAN") == TRUE || - g_str_has_prefix(name, "RFKILL") == TRUE || - g_str_has_prefix(name, "ID_MODEM") == TRUE || - g_str_equal(name, "ID_VENDOR") == TRUE || - g_str_equal(name, "ID_MODEL") == TRUE || - g_str_equal(name, "INTERFACE") == TRUE || - g_str_equal(name, "IFINDEX") == TRUE || - g_str_equal(name, "DEVNAME") == TRUE || - g_str_equal(name, "DEVPATH") == TRUE) - DBG("%s%s = %s", prefix, name, value); - - entry = udev_list_entry_get_next(entry); - } -} - -static void print_device(struct udev_device *device, const char *action) -{ - const char *subsystem, *sysname, *driver, *devtype = NULL; - struct udev_device *parent; - - DBG("=== %s ===", action); - print_properties(device, ""); - - parent = udev_device_get_parent(device); - if (parent == NULL) - return; - - subsystem = udev_device_get_subsystem(parent); - - if (subsystem != NULL && - g_str_equal(subsystem, "usb-serial") == TRUE) { - subsystem = "usb"; - devtype = "usb_device"; - } - - parent = udev_device_get_parent_with_subsystem_devtype(device, - subsystem, devtype); - print_properties(parent, " "); - - driver = udev_device_get_driver(device); - if (driver == NULL) { - driver = udev_device_get_driver(parent); - if (driver == NULL) - return; - } - - devtype = udev_device_get_devtype(device); - - DBG("devtype %s", devtype); - - sysname = udev_device_get_sysname(device); - - driver = udev_device_get_driver(parent); -} - -static void enumerate_devices(struct udev *context) -{ - struct udev_enumerate *enumerate; - struct udev_list_entry *entry; - - enumerate = udev_enumerate_new(context); - if (enumerate == NULL) - return; - - udev_enumerate_add_match_subsystem(enumerate, "net"); - - udev_enumerate_scan_devices(enumerate); - - entry = udev_enumerate_get_list_entry(enumerate); - while (entry) { - const char *syspath = udev_list_entry_get_name(entry); - struct udev_device *device; - - device = udev_device_new_from_syspath(context, syspath); - if (device != NULL) { - const char *subsystem; - - print_device(device, "coldplug"); - - subsystem = udev_device_get_subsystem(device); - - if (g_strcmp0(subsystem, "net") == 0) - add_net_device(device); - - udev_device_unref(device); - } - - entry = udev_list_entry_get_next(entry); - } - - udev_enumerate_unref(enumerate); -} - -static gboolean udev_event(GIOChannel *channel, - GIOCondition condition, gpointer user_data) -{ - struct udev_monitor *monitor = user_data; - struct udev_device *device; - const char *subsystem, *action; - - device = udev_monitor_receive_device(monitor); - if (device == NULL) - return TRUE; - - subsystem = udev_device_get_subsystem(device); - if (subsystem == NULL) - goto done; - - action = udev_device_get_action(device); - if (action == NULL) - goto done; - - print_device(device, action); - - if (g_str_equal(action, "add") == TRUE) { - if (g_str_equal(subsystem, "net") == TRUE) - add_net_device(device); - } else if (g_str_equal(action, "remove") == TRUE) { - if (g_str_equal(subsystem, "net") == TRUE) - remove_net_device(device); - } - -done: - udev_device_unref(device); - - return TRUE; -} - -static struct udev *udev_ctx; -static struct udev_monitor *udev_mon; -static guint udev_watch = 0; - -char *__connman_udev_get_devtype(const char *ifname) -{ - struct udev_device *device; - const char *devtype; - - device = udev_device_new_from_subsystem_sysname(udev_ctx, - "net", ifname); - if (device == NULL) - return NULL; - - devtype = udev_device_get_devtype(device); - if (devtype == NULL) - goto done; - -done: - udev_device_unref(device); - - return NULL; -} - -void __connman_udev_rfkill(const char *sysname, connman_bool_t blocked) -{ - struct udev_device *device, *parent; - const char *value; - - device = udev_device_new_from_subsystem_sysname(udev_ctx, - "rfkill", sysname); - if (device == NULL) - return; - - parent = udev_device_get_parent(device); - if (parent == NULL) - return; - - value = udev_device_get_sysattr_value(parent, "index"); - if (value == NULL) - return; - - phyindex_rfkill(atoi(value), blocked); -} - -int __connman_udev_init(void) -{ - DBG(""); - - udev_ctx = udev_new(); - if (udev_ctx == NULL) { - connman_error("Failed to create udev context"); - return -1; - } - - udev_mon = udev_monitor_new_from_netlink(udev_ctx, "udev"); - if (udev_mon == NULL) { - connman_error("Failed to create udev monitor"); - udev_unref(udev_ctx); - udev_ctx = NULL; - return -1; - } - - udev_monitor_filter_add_match_subsystem_devtype(udev_mon, - "net", NULL); - - udev_monitor_filter_update(udev_mon); - - return 0; -} - -void __connman_udev_start(void) -{ - GIOChannel *channel; - int fd; - - DBG(""); - - if (udev_monitor_enable_receiving(udev_mon) < 0) { - connman_error("Failed to enable udev monitor"); - return; - } - - enumerate_devices(udev_ctx); - - fd = udev_monitor_get_fd(udev_mon); - - channel = g_io_channel_unix_new(fd); - if (channel == NULL) - return; - - udev_watch = g_io_add_watch(channel, G_IO_IN, udev_event, udev_mon); - - g_io_channel_unref(channel); -} - -void __connman_udev_cleanup(void) -{ - GSList *list; - - DBG(""); - - if (udev_watch > 0) - g_source_remove(udev_watch); - - 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; - - for (list = rfkill_list; list; list = list->next) { - struct rfkill_data *block = list->data; - g_free(block); - } - - g_slist_free(rfkill_list); - rfkill_list = NULL; - - if (udev_ctx == NULL) - return; - - udev_monitor_filter_remove(udev_mon); - - udev_monitor_unref(udev_mon); - udev_unref(udev_ctx); -} |