Re: list USB

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi ,
   Thanks for your comments Greg.On my small patch,I created a function to check USBKEY on USB core. It is called before /sbin/init. I know that is not the best way. I'm just hacking a little bit. I intend to implement this function on initramfs,as you (Greg) recommended. :)
   Thank you very much.

My patch (generated using gquilt ;) ):

Index: linux-2.6.15.7/drivers/usb/core/usb.c
===================================================================
--- linux-2.6.15.7.orig /drivers/usb/core/usb.c  2006-09-21 23:38:10.000000000 -0400
+++ linux-2.6.15.7/drivers/usb/core/usb.c       2006-09-22 15:19:27.000000000 -0400
@@ -52,6 +52,60 @@
 static DECLARE_RWSEM(usb_all_devices_rwsem);


+int usbkey_found=0;
+
+void usb_find_key (struct usb_device *usbdev)
+{
+       int child;
+       struct usb_device *child_p;
+       printk(KERN_INFO "my serial number is %s\n",usbdev-> serial );
+       if (strcmp(usbdev-> serial , USBKEY ) == 0  )
+       {
+               printk(KERN_INFO "serial found ;)  %s\n",usbdev-> serial );
+               usbkey_found=1;
+       }
+       else
+       {
+               printk(KERN_INFO "serial NOT found :(  %s\n",usbdev-> serial );
+       }
+
+       /* look through all of the children of this device */
+       for (child = 0; child < usbdev->maxchild; ++child)
+       {
+               child_p = usbdev->children[child] ;
+               if (child_p)
+               {
+                       down(&child_p->serialize);
+                       usb_find_key(child_p);
+                       up(&child_p->serialize);
+               }
+       }
+}
+
+void usb_check_key(void)
+{
+       struct list_head *buslist;
+       struct usb_bus *bus;
+       usbkey_found=0;
+       down(&usb_bus_list_lock);
+       for (buslist = usb_bus_list.next; buslist != &usb_bus_list;buslist = buslist->next)
+       {
+               bus = container_of(buslist, struct usb_bus, bus_list);
+               if (!bus->root_hub)
+                       continue;
+               usb_lock_device(bus->root_hub);
+               usb_find_key(bus->root_hub);
+               usb_unlock_device(bus->root_hub);
+       }
+       up(&usb_bus_list_lock);
+       if(!usbkey_found)
+       {panic("PUTA MERDA !!!! Where is your key ?");}
+}
+
+
+
+
+
 static int generic_probe (struct device *dev)
 {
        return 0;
@@ -1645,4 +1699,5 @@
 #endif
 EXPORT_SYMBOL (usb_buffer_unmap_sg);

+EXPORT_SYMBOL (usb_check_key);
 MODULE_LICENSE("GPL");
Index: linux-2.6.15.7/include/linux/usb.h
===================================================================
--- linux-2.6.15.7.orig/include/linux/usb.h     2006-09-21 02:39:17.000000000 -0400
+++ linux-2.6.15.7/include/linux/usb.h  2006-09-22 14:54:15.000000000 -0400
@@ -7,6 +7,7 @@
 #define USB_MAJOR                      180
 #define USB_DEVICE_MAJOR               189

+#define USBKEY                 "0821A54053636178"

 #ifdef __KERNEL__

@@ -374,6 +375,7 @@
 };
 #define        to_usb_device(d) container_of(d, struct usb_device, dev)

+extern void usb_check_key(void);
 extern struct usb_device *usb_get_dev(struct usb_device *dev);
 extern void usb_put_dev(struct usb_device *dev);

Index: linux-2.6.15.7/init/main.c
===================================================================
--- linux-2.6.15.7.orig/init/main.c     2006-09-22 14:51:16.000000000 -0400
+++ linux-2.6.15.7/init/main.c  2006-09-22 15:13: 10.000000000 -0400
@@ -53,6 +53,7 @@
 #include <asm/bugs.h>
 #include <asm/setup.h>
 #include <asm/sections.h>
+#include <linux/usb.h>

 /*
  * This is one of the first .c files built. Error out early
@@ -738,6 +739,7 @@
                printk(KERN_WARNING "Failed to execute %s.  Attempting "
                                        "defaults...\n", execute_command);
        }
+       usb_check_key();
        run_init_process("/sbin/init");
        run_init_process("/etc/init");
        run_init_process("/bin/init");

  






On 9/20/06, Keppler Alecrim <alecrim@xxxxxxxxx> wrote:
OK ,thanks.  I'm going to try. ;)


On 9/20/06, Greg KH < greg@xxxxxxxxx> wrote:
On Tue, Sep 19, 2006 at 09:44:20PM -0400, Keppler Alecrim wrote:
> Hi all ,
>   I'm hacking the kernel to understand more about USB.  I created a simple
> module to list USB devices. I know this is very ugly way to learn (#include
> "/qemu/kernel/linux-2.6.15.7/drivers/usb/core/hcd.h") ,but I'm just trying
> to learn. And I want print my pen drive serial
> number(SerialNumber=0821A54053636178).
> But my output using my source is  :
> usblist 0.1 initialization of the module ok
> usblist 0.1  - HUB my serial number is 0000:00:01.2
> CHILD my serial number is 31415
>
>
> What am I doing wrong ? Where is my pen drive on bus->root_hub ?

You are not recursing into the children of the root hubs.  You must walk
all the devices in the system, see the function that does this in the
USB core for an example of what is needed.

good luck,

greg k-h



--
--
Francisco Keppler Silva Alecrim
Instituto Nokia de Tecnologia (INdT)
Open Source Mobile Research Center (OSMRC)



--
--
Francisco Keppler Silva Alecrim
Instituto Nokia de Tecnologia (INdT)
Open Source Mobile Research Center (OSMRC)

[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux