From 4fb8c75480f5d30000aeab0a91563e71697f0d64 Mon Sep 17 00:00:00 2001 From: Samuel Ortiz Date: Fri, 8 Oct 2010 18:53:08 +0200 Subject: [PATCH] rtnl: Export device type detection routine Since ConnMan is now relying only on rtnl for device detection, the rtnl.c code should be responsible for providing device types. And this is done by parsing the device uevent DEVTYPE label. --- src/connman.h | 1 + src/rtnl.c | 56 +++++++++++++++++++++++++++++++++++++++----------------- 2 files changed, 40 insertions(+), 17 deletions(-) diff --git a/src/connman.h b/src/connman.h index b65ad6d..56e0723 100644 --- a/src/connman.h +++ b/src/connman.h @@ -551,6 +551,7 @@ 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); diff --git a/src/rtnl.c b/src/rtnl.c index 5c0fa36..87f4945 100644 --- a/src/rtnl.c +++ b/src/rtnl.c @@ -63,7 +63,8 @@ struct interface_data { int index; char *name; char *ident; - enum connman_service_type type; + enum connman_service_type service_type; + enum connman_device_type device_type; }; static GHashTable *interface_list = NULL; @@ -72,7 +73,7 @@ static void free_interface(gpointer data) { struct interface_data *interface = data; - __connman_technology_remove_interface(interface->type, + __connman_technology_remove_interface(interface->service_type, interface->index, interface->name, interface->ident); g_free(interface->ident); @@ -105,10 +106,13 @@ static void read_uevent(struct interface_data *interface) char *filename, line[128]; FILE *f; - if (ether_blacklisted(interface->name) == TRUE) - interface->type = CONNMAN_SERVICE_TYPE_UNKNOWN; - else - interface->type = CONNMAN_SERVICE_TYPE_ETHERNET; + if (ether_blacklisted(interface->name) == TRUE) { + 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", interface->name); @@ -131,21 +135,39 @@ static void read_uevent(struct interface_data *interface) if (strncmp(line, "DEVTYPE=", 8) != 0) continue; - if (strcmp(line + 8, "wlan") == 0) - interface->type = CONNMAN_SERVICE_TYPE_WIFI; - else if (strcmp(line + 8, "wwan") == 0) - interface->type = CONNMAN_SERVICE_TYPE_CELLULAR; - else if (strcmp(line + 8, "bluetooth") == 0) - interface->type = CONNMAN_SERVICE_TYPE_BLUETOOTH; - else if (strcmp(line + 8, "wimax") == 0) - interface->type = CONNMAN_SERVICE_TYPE_WIMAX; - else - interface->type = CONNMAN_SERVICE_TYPE_UNKNOWN; + 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, "wimax") == 0) { + interface->service_type = CONNMAN_SERVICE_TYPE_WIMAX; + interface->device_type = CONNMAN_DEVICE_TYPE_WIMAX; + } else { + interface->service_type = CONNMAN_SERVICE_TYPE_UNKNOWN; + interface->device_type = CONNMAN_DEVICE_TYPE_UNKNOWN; + } } fclose(f); } +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 == NULL) + return CONNMAN_DEVICE_TYPE_UNKNOWN; + + return interface->device_type; +} + /** * connman_rtnl_add_newlink_watch: * @index: network device index @@ -397,7 +419,7 @@ static void process_newlink(unsigned short type, int index, unsigned flags, if (type == ARPHRD_ETHER) read_uevent(interface); - __connman_technology_add_interface(interface->type, + __connman_technology_add_interface(interface->service_type, interface->index, interface->name, interface->ident); } -- 2.7.4