2 Copyright (C) 2006 by Michal Schulz
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with this program; if not, write to the
17 Free Software Foundation, Inc.,
18 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #include <aros/debug.h>
25 #include <proto/exec.h>
26 #include <proto/dos.h>
27 #include <proto/oop.h>
31 #include <usb/usb_core.h>
35 OOP_AttrBase HiddUSBAttrBase
;
36 OOP_AttrBase HiddUSBDeviceAttrBase
;
37 OOP_AttrBase HiddUSBHubAttrBase
;
39 void scan_hub(OOP_Object
*hub
, int depth
)
43 intptr_t productid
=0, vendorid
=0;
47 for (i
=0; i
< depth
; i
++)
51 OOP_GetAttr(hub
, aHidd_USBHub_NumPorts
, &nports
);
52 OOP_GetAttr(hub
, aHidd_USBDevice_ProductName
, (intptr_t *)&name
);
53 OOP_GetAttr(hub
, aHidd_USBDevice_Address
, &address
);
54 OOP_GetAttr(hub
, aHidd_USBDevice_ProductID
, &productid
);
55 OOP_GetAttr(hub
, aHidd_USBDevice_VendorID
, &vendorid
);
57 D(bug("[lsusb] hub with %d ports\n", nports
));
59 printf("%s%03d: %04x:%04x %s\n", pad
, (int)address
, (int)productid
, (int)vendorid
, name
);
61 for (i
=1; i
<= nports
; i
++)
64 OOP_Object
*child
= HIDD_USBHub_GetChild(hub
, i
);
68 OOP_GetAttr(child
, aHidd_USBHub_NumPorts
, &ports
);
69 OOP_GetAttr(child
, aHidd_USBDevice_ProductName
, (intptr_t *)&name
);
70 OOP_GetAttr(child
, aHidd_USBDevice_Address
, &address
);
71 OOP_GetAttr(child
, aHidd_USBDevice_ProductID
, &productid
);
72 OOP_GetAttr(child
, aHidd_USBDevice_VendorID
, &vendorid
);
75 scan_hub(child
, depth
+1);
77 printf("%s %03d: %04x:%04x %s\n", pad
, (int)address
, (int)productid
, (int)vendorid
, name
);
79 D(bug("[lsusb] Child %d: %p (%s) with %d ports\n", i
, child
, name
, nports
));
86 struct OOP_ABDescr attrbases
[] = {
87 { (STRPTR
)IID_Hidd_USB
, &HiddUSBAttrBase
},
88 { (STRPTR
)IID_Hidd_USBDevice
, &HiddUSBDeviceAttrBase
},
89 { (STRPTR
)IID_Hidd_USBHub
, &HiddUSBHubAttrBase
},
93 OOP_ObtainAttrBases(attrbases
);
95 OOP_Object
*usb
= OOP_NewObject(NULL
, CLID_Hidd_USB
, NULL
);
96 OOP_Object
*bus
= NULL
;
98 D(bug("[lsusb] USB object @ %p\n", usb
));
102 PutStr("USB device tree:\n");
105 OOP_GetAttr(usb
, aHidd_USB_Bus
, (IPTR
*)&bus
);
108 D(bug("[lsusb] bus=%p\n", bus
));
110 printf("Bus %p:\n", bus
);
115 OOP_DisposeObject(usb
);
119 PutStr("Please use C:LoadResource...\n");
122 OOP_ReleaseAttrBases(attrbases
);