Main Page | Modules | Data Structures | File List | Data Fields | Related Pages

usbif_bus_device.c

00001 /***************************************************************************
00002  * CVSID: $Id: usbif_bus_device.c,v 1.5 2004/04/21 18:44:41 david Exp $
00003  *
00004  * linux_usb.c : USB handling on Linux 2.6
00005  *
00006  * Copyright (C) 2003 David Zeuthen, <david@fubar.dk>
00007  *
00008  * Licensed under the Academic Free License version 2.0
00009  *
00010  * This program is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with this program; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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     /* only USB interfaces got a : in the bus_id */
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     /*hal_device_print (d);*/
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         /* strip whitespace */
00127         len = strlen (cur->value);
00128         for (i = len - 1; i > 0 && isspace (cur->value[i]); --i)
00129             cur->value[i] = '\0';
00130 
00131         /*printf("attr_name=%s -> '%s'\n", attr_name, cur->value); */
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 

Generated on Sat Apr 24 19:57:45 2004 for HAL by doxygen 1.3.6-20040222