rtnl: Export device type detection routine
authorSamuel Ortiz <sameo@linux.intel.com>
Fri, 8 Oct 2010 16:53:08 +0000 (18:53 +0200)
committerSamuel Ortiz <sameo@linux.intel.com>
Fri, 8 Oct 2010 17:00:06 +0000 (19:00 +0200)
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
src/rtnl.c

index b65ad6d..56e0723 100644 (file)
@@ -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);
index 5c0fa36..87f4945 100644 (file)
@@ -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);
        }