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* ieee1394_compute_udi(HalDevice* d, int append_num)
00060 {
00061 const char* serial;
00062 const char* format;
00063 static char buf[256];
00064
00065 if (append_num == -1) {
00066 snprintf(buf, 256, "/org/freedesktop/Hal/devices/ieee1394_%s",
00067 ds_property_get_string(d, "linux.sysfs_bus_id"));
00068 } else {
00069 snprintf(buf, 256, "/org/freedesktop/Hal/devices/ieee1394_%s-%d",
00070 ds_property_get_string(d, "linux.sysfs_bus_id"),
00071 append_num);
00072 }
00073
00074 return buf;
00075 }
00076
00084 static void visit_device_ieee1394_got_parent(HalDevice* parent,
00085 void* data1, void* data2)
00086 {
00087 char* new_udi = NULL;
00088 HalDevice* new_d = NULL;
00089 int bus_number;
00090 const char* bus_id;
00091 HalDevice* d = (HalDevice*) data1;
00092
00093 if( parent!=NULL )
00094 {
00095 ds_property_set_string(d, "info.parent", parent->udi);
00096 }
00097 else
00098 {
00099
00100 HAL_WARNING(("No parent for IEEE1394 device!"));
00101 }
00102
00103 new_udi = rename_and_merge(d, ieee1394_compute_udi, "ieee1394");
00104 if( new_udi!=NULL )
00105 {
00106 new_d = ds_device_find(new_udi);
00107 if( new_d!=NULL )
00108 {
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
00125 if( sysfs_get_name_from_path(cur->path,
00126 attr_name, 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 = sysfs_open_device (link->target);
00146
00147 extract_properties (real_device, d);
00148 }
00149
00150 } else if (strcmp (attr_name, "model_name") == 0) {
00151 ds_property_set_string (d, "info.product", cur->value);
00152
00153 } else if (strcmp (attr_name, "vendor_name") == 0) {
00154 ds_property_set_string (d, "info.vendor", cur->value);
00155
00156 } else if (strcmp (attr_name, "capabilities") == 0) {
00157 ds_property_set_int (d, "ieee1394.capabilities",
00158 parse_hex(cur->value));
00159
00160 } else if (strcmp (attr_name, "guid") == 0) {
00161
00162 ds_property_set_string (d, "ieee1394.guid",
00163 cur->value);
00164
00165 } else if (strcmp (attr_name, "guid_vendor_id") == 0) {
00166 ds_property_set_int (d, "ieee1394.guid_vendor_id",
00167 parse_hex(cur->value));
00168
00169 } else if (strcmp (attr_name, "guid_vendor_oui") == 0) {
00170 ds_property_set_string (d, "ieee1394.guid_vendor_oui",
00171 cur->value);
00172
00173 } else if (strcmp (attr_name, "model_id") == 0) {
00174 ds_property_set_int (d, "ieee1394.model_id",
00175 parse_hex(cur->value));
00176
00177 } else if (strcmp (attr_name, "model_name") == 0) {
00178 ds_property_set_string (d, "ieee1394.model_name",
00179 cur->value);
00180
00181 } else if (strcmp (attr_name, "nodeid") == 0) {
00182 ds_property_set_int (d, "ieee1394.nodeid",
00183 parse_hex(cur->value));
00184
00185 } else if (strcmp (attr_name, "specifier_id") == 0) {
00186 ds_property_set_int (d, "ieee1394.specifier_id",
00187 parse_hex(cur->value));
00188
00189 } else if (strcmp (attr_name, "vendor_id") == 0) {
00190 ds_property_set_int (d, "ieee1394.vendor_id",
00191 parse_hex(cur->value));
00192
00193 } else if (strcmp (attr_name, "vendor_name") == 0) {
00194 ds_property_set_string (d, "ieee1394.vendor_name",
00195 cur->value);
00196
00197 } else if (strcmp (attr_name, "vendor_oui") == 0) {
00198 ds_property_set_string (d, "ieee1394.vendor_oui",
00199 cur->value);
00200
00201 } else if (strcmp (attr_name, "version") == 0) {
00202 ds_property_set_int (d, "ieee1394.version",
00203 parse_hex (cur->value));
00204 }
00205
00206 }
00207 }
00208
00209 static void
00210 add_capabilities (HalDevice *d)
00211 {
00212 int specifier_id;
00213
00214 specifier_id = ds_property_get_int (d, "ieee1394.specifier_id");
00215
00216
00217
00218
00219
00220
00221
00222 if (specifier_id == 0x00609e) {
00223 ds_add_capability(d, "storage_controller");
00224 ds_property_set_string(d, "info.category", "storage_controller");
00225 } else if (specifier_id == 0x00005e) {
00226 ds_add_capability(d, "net");
00227 ds_add_capability(d, "net.ethernet");
00228 ds_property_set_string(d, "info.category", "net");
00229 }
00230 }
00231
00240 void visit_device_ieee1394(const char* path, struct sysfs_device *device)
00241 {
00242 dbus_bool_t is_interface;
00243 HalDevice* d;
00244 int vendor_id=0;
00245 int product_id=0;
00246 char* vendor_name;
00247 char* product_name;
00248 char* vendor_name_kernel = NULL;
00249 char* product_name_kernel = NULL;
00250 const char* driver;
00251 char* parent_sysfs_path;
00252 char numeric_name[32];
00253
00254
00255
00256 if( device->directory==NULL || device->directory->attributes==NULL )
00257 return;
00258
00259 d = ds_device_new();
00260 ds_property_set_string(d, "info.bus", "ieee1394");
00261 ds_property_set_string(d, "linux.sysfs_path", path);
00262 ds_property_set_string(d, "linux.sysfs_bus_id", device->bus_id);
00263 ds_property_set_string(d, "linux.sysfs_path_device", path);
00264
00265
00266
00267
00268 driver = drivers_lookup(path);
00269 if( driver!=NULL )
00270 ds_property_set_string(d, "linux.driver", driver);
00271
00272 extract_properties (device, d);
00273
00274 add_capabilities (d);
00275
00276 parent_sysfs_path = get_parent_sysfs_path(path);
00277
00278
00279
00280
00281
00282 ds_device_async_find_by_key_value_string("linux.sysfs_path_device",
00283 parent_sysfs_path,
00284 TRUE,
00285 visit_device_ieee1394_got_parent,
00286 (void*) d, NULL,
00287 is_probing ? 0 :
00288 HAL_LINUX_HOTPLUG_TIMEOUT);
00289
00290 free(parent_sysfs_path);
00291 }
00292
00296 void linux_ieee1394_init()
00297 {
00298
00299
00300 drivers_collect("ieee1394");
00301 }
00302
00307 void linux_ieee1394_detection_done()
00308 {
00309 }
00310
00314 void linux_ieee1394_shutdown()
00315 {
00316 }
00317