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 ?
My module source is :
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/usb.h>
#include <linux/list.h>
#include "/qemu/kernel/linux-2.6.15.7/drivers/usb/core/hcd.h " // I know this is very ugly :(
#define VERSION "0.1"
#define MODULE_NAME "usblist"
static int __init init_procfs_wrk(void)
{
struct list_head *buslist;
struct usb_bus *bus;
int child ;
printk(KERN_INFO "%s %s initialization of the module ok\n",MODULE_NAME, VERSION);
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);
printk(KERN_INFO "%s %s - HUB my serial number is %s\n",MODULE_NAME, VERSION, bus->root_hub->serial );
/* look through all of the children of this device */
for (child = 0; child < bus->root_hub->maxchild; ++child)
{
if ( bus->root_hub->children[child])
{
printk(KERN_INFO "CHILD my serial number is %s\n",bus->root_hub->children[child]-> serial );
}
}
usb_unlock_device(bus->root_hub);
}
up(&usb_bus_list_lock);
return 0;
}
static void __exit cleanup_procfs_wrk(void)
{
printk(KERN_INFO "%s %s removed\n",MODULE_NAME, VERSION);
}
And my usb devices are :
T: Bus=01 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#= 1 Spd=12 MxCh= 2
B: Alloc= 12/900 us ( 1%), #Int= 1, #Iso= 0
D: Ver= 1.10 Cls=09(hub ) Sub=00 Prot=00 MxPS=64 #Cfgs= 1
P: Vendor=0000 ProdID=0000 Rev= 2.06
S: Manufacturer=Linux 2.6.15.7 uhci_hcd
S: Product=UHCI Host Controller
S: SerialNumber=0000:00: 01.2
C:* #Ifs= 1 Cfg#= 1 Atr=c0 MxPwr= 0mA
I: If#= 0 Alt= 0 #EPs= 1 Cls=09(hub ) Sub=00 Prot=00 Driver=hub
E: Ad=81(I) Atr=03(Int.) MxPS= 2 Ivl=255ms
T: Bus=01 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#= 2 Spd=12 MxCh= 8
D: Ver= 1.10 Cls=09(hub ) Sub=00 Prot=00 MxPS= 8 #Cfgs= 1
P: Vendor=0000 ProdID=0000 Rev= 1.01
S: Manufacturer=QEMU 0.8.
S: Product=QEMU USB Hu
S: SerialNumber=31415
C:* #Ifs= 1 Cfg#= 1 Atr=c0 MxPwr= 0mA
I: If#= 0 Alt= 0 #EPs= 1 Cls=09(hub ) Sub=00 Prot=00 Driver=hub
E: Ad=81(I) Atr=03(Int.) MxPS= 2 Ivl=255ms
T: Bus=01 Lev=02 Prnt=02 Port=00 Cnt=01 Dev#= 3 Spd=12 MxCh= 0
D: Ver= 2.00 Cls=00(>ifc ) Sub=00 Prot=00 MxPS=64 #Cfgs= 1
P: Vendor=08ec ProdID=0012 Rev= 2.00
S: Manufacturer=Kingston
S: Product=DataTraveler2.0
S: SerialNumber=0821A54053636178
C:* #Ifs= 1 Cfg#= 1 Atr=80 MxPwr=178mA
I: If#= 0 Alt= 0 #EPs= 2 Cls=08(stor.) Sub=06 Prot=50 Driver=usb-storage
E: Ad=81(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms
E: Ad=02(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms
PS : I'm using qemu to test this module.
Thank you all. ;)
On 9/14/06, Keppler Alecrim <alecrim@xxxxxxxxx> wrote:
Greg,thank you very much. :)On 9/14/06, Greg KH < greg@xxxxxxxxx> wrote:On Thu, Sep 14, 2006 at 12:32:29PM -0400, Keppler Alecrim wrote:
> On 9/14/06, Greg KH <greg@xxxxxxxxx> wrote:
> >
> >On Thu, Sep 14, 2006 at 09:53:33AM -0400, Keppler Alecrim wrote:
> >> Hi all ,
> >> I'm trying to create a module to list all usb devices like
> >> /proc/bus/usb/devices read function.
> >
> >Why do you want to do this?
>
>
> I'm trying block kernel boot(/sbin/init) if a specfic USB is not
> plugged.Like a USBKEY,but I need to check devices plugged and theirs serial
> number.
You can do that from userspace in an initramfs, don't do that within the
kernel itself.
> >The main structs are on include/linux/usb.h,including usb_device. What
> >> variable contain all usb devices?
> >
> >Depending on the kernel version, you might be able to do this, and you
> >might not. What kernel version are you using?
>
>
> I'm using 2.6.15.7.
Ah, no, sorry, the ability to walk the USB device list isn't possible
outside of the USB core anymore. In 2.4, it's still possible I think.
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)