00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifdef HAVE_CONFIG_H
00027 # include <config.h>
00028 #endif
00029
00030 #include <ctype.h>
00031 #include <stdio.h>
00032 #include <stdlib.h>
00033 #include <string.h>
00034 #include <getopt.h>
00035 #include <assert.h>
00036 #include <unistd.h>
00037 #include <stdarg.h>
00038
00039 #include "../logger.h"
00040 #include "../device_store.h"
00041 #include "bus_device.h"
00042 #include "common.h"
00043
00059 static dbus_bool_t
00060 usbif_device_accept (BusDeviceHandler *self, const char *path,
00061 struct sysfs_device *device, dbus_bool_t is_probing)
00062 {
00063 unsigned int i;
00064
00065 if (strcmp (device->bus, "usb") != 0)
00066 return FALSE;
00067
00068
00069 for (i = 0; device->bus_id[i] != 0; i++) {
00070 if (device->bus_id[i] == ':') {
00071 return TRUE;
00072 }
00073 }
00074
00075 return FALSE;
00076 }
00077
00078 static char *
00079 usbif_device_compute_udi (HalDevice *d, int append_num)
00080 {
00081 int i, len;
00082 const char *format;
00083 const char *pd;
00084 const char *name;
00085 static char buf[256];
00086
00087 if (append_num == -1)
00088 format = "/org/freedesktop/Hal/devices/usbif_%s_%d";
00089 else
00090 format = "/org/freedesktop/Hal/devices/usbif_%s_%d-%d";
00091
00092
00093
00094 pd = hal_device_property_get_string (d, "info.parent");
00095 len = strlen (pd);
00096 for (i = len - 1; pd[i] != '/' && i >= 0; i--);
00097 name = pd + i + 1;
00098
00099 snprintf (buf, 256, format,
00100 name,
00101 hal_device_property_get_int (d, "usbif.number"), append_num);
00102
00103 return buf;
00104 }
00105
00106
00107 static void
00108 usbif_device_pre_process (BusDeviceHandler *self,
00109 HalDevice *d,
00110 const char *sysfs_path,
00111 struct sysfs_device *device)
00112 {
00113 int i;
00114 int len;
00115 struct sysfs_attribute *cur;
00116 char attr_name[SYSFS_NAME_LEN];
00117
00118 dlist_for_each_data (sysfs_get_device_attributes (device), cur,
00119 struct sysfs_attribute) {
00120
00121 if (sysfs_get_name_from_path (cur->path,
00122 attr_name,
00123 SYSFS_NAME_LEN) != 0)
00124 continue;
00125
00126
00127 len = strlen (cur->value);
00128 for (i = len - 1; i > 0 && isspace (cur->value[i]); --i)
00129 cur->value[i] = '\0';
00130
00131
00132
00133 if (strcmp (attr_name, "bInterfaceClass") == 0)
00134 hal_device_property_set_int (d, "usbif.interface_class",
00135 parse_dec (cur->value));
00136 else if (strcmp (attr_name, "bInterfaceSubClass") == 0)
00137 hal_device_property_set_int (d, "usbif.interface_subclass",
00138 parse_dec (cur->value));
00139 else if (strcmp (attr_name, "bInterfaceProtocol") == 0)
00140 hal_device_property_set_int (d, "usbif.interface_protocol",
00141 parse_dec (cur->value));
00142 else if (strcmp (attr_name, "bInterfaceNumber") == 0)
00143 hal_device_property_set_int (d, "usbif.number",
00144 parse_dec (cur->value));
00145 }
00146
00147 hal_device_property_set_bool (d, "info.virtual", TRUE);
00148 }
00149
00151 BusDeviceHandler usbif_bus_handler = {
00152 bus_device_init,
00153 bus_device_detection_done,
00154 bus_device_shutdown,
00155 bus_device_tick,
00156 usbif_device_accept,
00157 bus_device_visit,
00158 bus_device_removed,
00159 usbif_device_compute_udi,
00160 usbif_device_pre_process,
00161 bus_device_got_udi,
00162 "usb",
00163 "usbif"
00164 };
00165