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
00027 #ifdef HAVE_CONFIG_H
00028 # include <config.h>
00029 #endif
00030
00031 #include <ctype.h>
00032 #include <stdio.h>
00033 #include <stdlib.h>
00034 #include <string.h>
00035 #include <getopt.h>
00036 #include <assert.h>
00037 #include <unistd.h>
00038 #include <stdarg.h>
00039
00040 #include "../logger.h"
00041 #include "linux_ieee1394.h"
00042
00059 static char *
00060 ieee1394_compute_udi (HalDevice * d, int append_num)
00061 {
00062 const char *serial;
00063 const char *format;
00064 static char buf[256];
00065
00066 if (append_num == -1) {
00067 snprintf (buf, 256,
00068 "/org/freedesktop/Hal/devices/ieee1394_%s",
00069 ds_property_get_string (d,
00070 "linux.sysfs_bus_id"));
00071 } else {
00072 snprintf (buf, 256,
00073 "/org/freedesktop/Hal/devices/ieee1394_%s-%d",
00074 ds_property_get_string (d, "linux.sysfs_bus_id"),
00075 append_num);
00076 }
00077
00078 return buf;
00079 }
00080
00088 static void
00089 visit_device_ieee1394_got_parent (HalDevice * parent,
00090 void *data1, void *data2)
00091 {
00092 char *new_udi = NULL;
00093 HalDevice *new_d = NULL;
00094 int bus_number;
00095 const char *bus_id;
00096 HalDevice *d = (HalDevice *) data1;
00097
00098 if (parent != NULL) {
00099 ds_property_set_string (d, "info.parent", parent->udi);
00100 } else {
00101
00102 HAL_WARNING (("No parent for IEEE1394 device!"));
00103 }
00104
00105 new_udi = rename_and_merge (d, ieee1394_compute_udi, "ieee1394");
00106 if (new_udi != NULL) {
00107 new_d = ds_device_find (new_udi);
00108 if (new_d != NULL) {
00109 ds_gdl_add (new_d);
00110 }
00111 }
00112 }
00113
00114 static void
00115 extract_properties (struct sysfs_device *device, HalDevice * d)
00116 {
00117 struct sysfs_attribute *cur;
00118 char attr_name[SYSFS_NAME_LEN];
00119 int len, i;
00120
00121 dlist_for_each_data (sysfs_get_device_attributes (device), cur,
00122 struct sysfs_attribute) {
00123
00124 if (sysfs_get_name_from_path (cur->path,
00125 attr_name,
00126 SYSFS_NAME_LEN) != 0)
00127 continue;
00128
00129
00130 len = strlen (cur->value);
00131 for (i = len - 1; i >= 0 && isspace (cur->value[i]); --i)
00132 cur->value[i] = '\0';
00133
00134
00135
00136 if (strcmp (attr_name, "is_root") == 0) {
00137 struct sysfs_link *link;
00138
00139 link = sysfs_get_directory_link (device->directory,
00140 "host_id");
00141
00142 if (link != NULL) {
00143 struct sysfs_device *real_device;
00144
00145 real_device =
00146 sysfs_open_device (link->target);
00147
00148 extract_properties (real_device, d);
00149 }
00150
00151 } else if (strcmp (attr_name, "model_name") == 0) {
00152 ds_property_set_string (d, "info.product",
00153 cur->value);
00154
00155 } else if (strcmp (attr_name, "vendor_name") == 0) {
00156 ds_property_set_string (d, "info.vendor",
00157 cur->value);
00158
00159 } else if (strcmp (attr_name, "capabilities") == 0) {
00160 ds_property_set_int (d, "ieee1394.capabilities",
00161 parse_hex (cur->value));
00162
00163 } else if (strcmp (attr_name, "guid") == 0) {
00164
00165 ds_property_set_string (d, "ieee1394.guid",
00166 cur->value);
00167
00168 } else if (strcmp (attr_name, "guid_vendor_id") == 0) {
00169 ds_property_set_int (d, "ieee1394.guid_vendor_id",
00170 parse_hex (cur->value));
00171
00172 } else if (strcmp (attr_name, "guid_vendor_oui") == 0) {
00173 ds_property_set_string (d,
00174 "ieee1394.guid_vendor_oui",
00175 cur->value);
00176
00177 } else if (strcmp (attr_name, "model_id") == 0) {
00178 ds_property_set_int (d, "ieee1394.model_id",
00179 parse_hex (cur->value));
00180
00181 } else if (strcmp (attr_name, "model_name") == 0) {
00182 ds_property_set_string (d, "ieee1394.model_name",
00183 cur->value);
00184
00185 } else if (strcmp (attr_name, "nodeid") == 0) {
00186 ds_property_set_int (d, "ieee1394.nodeid",
00187 parse_hex (cur->value));
00188
00189 } else if (strcmp (attr_name, "specifier_id") == 0) {
00190 ds_property_set_int (d, "ieee1394.specifier_id",
00191 parse_hex (cur->value));
00192
00193 } else if (strcmp (attr_name, "vendor_id") == 0) {
00194 ds_property_set_int (d, "ieee1394.vendor_id",
00195 parse_hex (cur->value));
00196
00197 } else if (strcmp (attr_name, "vendor_name") == 0) {
00198 ds_property_set_string (d, "ieee1394.vendor_name",
00199 cur->value);
00200
00201 } else if (strcmp (attr_name, "vendor_oui") == 0) {
00202 ds_property_set_string (d, "ieee1394.vendor_oui",
00203 cur->value);
00204
00205 } else if (strcmp (attr_name, "version") == 0) {
00206 ds_property_set_int (d, "ieee1394.version",
00207 parse_hex (cur->value));
00208 }
00209
00210 }
00211 }
00212
00213 static void
00214 add_capabilities (HalDevice * d)
00215 {
00216 int specifier_id;
00217
00218 specifier_id = ds_property_get_int (d, "ieee1394.specifier_id");
00219
00220
00221
00222
00223
00224
00225
00226 if (specifier_id == 0x00609e) {
00227 ds_add_capability (d, "storage_controller");
00228 ds_property_set_string (d, "info.category",
00229 "storage_controller");
00230 } else if (specifier_id == 0x00005e) {
00231 ds_add_capability (d, "net");
00232 ds_add_capability (d, "net.ethernet");
00233 ds_property_set_string (d, "info.category", "net");
00234 }
00235 }
00236
00245 void
00246 visit_device_ieee1394 (const char *path, struct sysfs_device *device)
00247 {
00248 dbus_bool_t is_interface;
00249 HalDevice *d;
00250 int vendor_id = 0;
00251 int product_id = 0;
00252 char *vendor_name;
00253 char *product_name;
00254 char *vendor_name_kernel = NULL;
00255 char *product_name_kernel = NULL;
00256 const char *driver;
00257 char *parent_sysfs_path;
00258 char numeric_name[32];
00259
00260
00261
00262 if (device->directory == NULL
00263 || device->directory->attributes == NULL)
00264 return;
00265
00266 d = ds_device_new ();
00267 ds_property_set_string (d, "info.bus", "ieee1394");
00268 ds_property_set_string (d, "linux.sysfs_path", path);
00269 ds_property_set_string (d, "linux.sysfs_bus_id", device->bus_id);
00270 ds_property_set_string (d, "linux.sysfs_path_device", path);
00271
00272
00273
00274
00275 driver = drivers_lookup (path);
00276 if (driver != NULL)
00277 ds_property_set_string (d, "linux.driver", driver);
00278
00279 extract_properties (device, d);
00280
00281 add_capabilities (d);
00282
00283 parent_sysfs_path = get_parent_sysfs_path (path);
00284
00285
00286
00287
00288
00289 ds_device_async_find_by_key_value_string
00290 ("linux.sysfs_path_device", parent_sysfs_path, TRUE,
00291 visit_device_ieee1394_got_parent, (void *) d, NULL,
00292 is_probing ? 0 : HAL_LINUX_HOTPLUG_TIMEOUT);
00293
00294 free (parent_sysfs_path);
00295 }
00296
00300 void
00301 linux_ieee1394_init ()
00302 {
00303
00304
00305 drivers_collect ("ieee1394");
00306 }
00307
00312 void
00313 linux_ieee1394_detection_done ()
00314 {
00315 }
00316
00320 void
00321 linux_ieee1394_shutdown ()
00322 {
00323 }
00324