grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / devs / USB / tools / lsusb / main.c
blob62c2abbf9901d04a8321dcdec98f144904f5f1b9
1 /*
2 Copyright (C) 2006 by Michal Schulz
3 $Id$
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.
21 #define DEBUG 1
23 #include <aros/debug.h>
25 #include <proto/exec.h>
26 #include <proto/dos.h>
27 #include <proto/oop.h>
29 #include <usb/usb.h>
30 #include <usb/hid.h>
31 #include <usb/usb_core.h>
33 #include <stdio.h>
35 OOP_AttrBase HiddUSBAttrBase;
36 OOP_AttrBase HiddUSBDeviceAttrBase;
37 OOP_AttrBase HiddUSBHubAttrBase;
39 void scan_hub(OOP_Object *hub, int depth)
41 intptr_t nports, i;
42 intptr_t address = 0;
43 intptr_t productid=0, vendorid=0;
44 STRPTR name = NULL;
46 char pad[depth+1];
47 for (i=0; i < depth; i++)
48 pad[i]=' ';
49 pad[depth] = 0;
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);
65 if (child)
67 intptr_t ports = 0;
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);
74 if (ports > 0)
75 scan_hub(child, depth+1);
76 else
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));
84 int main(void)
86 struct OOP_ABDescr attrbases[] = {
87 { (STRPTR)IID_Hidd_USB, &HiddUSBAttrBase },
88 { (STRPTR)IID_Hidd_USBDevice, &HiddUSBDeviceAttrBase },
89 { (STRPTR)IID_Hidd_USBHub, &HiddUSBHubAttrBase },
90 { NULL, NULL }
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));
100 if(usb)
102 PutStr("USB device tree:\n");
104 do {
105 OOP_GetAttr(usb, aHidd_USB_Bus, (IPTR *)&bus);
106 if (bus)
108 D(bug("[lsusb] bus=%p\n", bus));
110 printf("Bus %p:\n", bus);
111 scan_hub(bus, 1);
114 } while(bus);
115 OOP_DisposeObject(usb);
117 }else
119 PutStr("Please use C:LoadResource...\n");
122 OOP_ReleaseAttrBases(attrbases);
124 return RETURN_OK;