1 /* *********************************************************************
2 * Broadcom Common Firmware Environment (CFE)
4 * USB debugging code File: usbdebug.c
6 * This module contains debug code for USB.
8 * Author: Mitch Lichtenberg (mpl@broadcom.com)
10 *********************************************************************
12 * Copyright 2000,2001,2002,2003
13 * Broadcom Corporation. All rights reserved.
15 * This software is furnished under license and may be used and
16 * copied only in accordance with the following terms and
17 * conditions. Subject to these conditions, you may download,
18 * copy, install, use, modify and distribute modified or unmodified
19 * copies of this software in source and/or binary form. No title
20 * or ownership is transferred hereby.
22 * 1) Any source code used, modified or distributed must reproduce
23 * and retain this copyright notice and list of conditions
24 * as they appear in the source file.
26 * 2) No right is granted to use any trade name, trademark, or
27 * logo of Broadcom Corporation. The "Broadcom Corporation"
28 * name may not be used to endorse or promote products derived
29 * from this software without the prior written permission of
30 * Broadcom Corporation.
32 * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR
33 * IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED
34 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
35 * PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT
36 * SHALL BROADCOM BE LIABLE FOR ANY DAMAGES WHATSOEVER, AND IN
37 * PARTICULAR, BROADCOM SHALL NOT BE LIABLE FOR DIRECT, INDIRECT,
38 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
39 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
40 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
41 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
42 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
43 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE), EVEN IF ADVISED OF
44 * THE POSSIBILITY OF SUCH DAMAGE.
45 ********************************************************************* */
55 #include "lib_types.h"
56 #include "lib_string.h"
57 #include "lib_printf.h"
60 #include "lib_malloc.h"
61 #include "lib_queue.h"
66 void usb_dbg_dumpportstatus(int port
,usb_port_status_t
*portstatus
,int level
)
71 for (idx
= 0; idx
< level
; idx
++) printf(" ");
72 printf("PORT %d STATUS\n",port
);
74 for (idx
= 0; idx
< level
; idx
++) printf(" ");
75 x
= GETUSBFIELD((portstatus
),wPortStatus
);
76 printf("wPortStatus = %04X ",x
);
77 if (x
& 1) printf("DevicePresent ");
78 if (x
& 2) printf("Enabled ");
79 if (x
& 4) printf("Suspend ");
80 if (x
& 8) printf("OverCurrent ");
81 if (x
& 16) printf("InReset ");
82 if (x
& 256) printf("Powered ");
83 if (x
& 512) printf("LowSpeed ");
85 for (idx
= 0; idx
< level
; idx
++) printf(" ");
86 x
= GETUSBFIELD((portstatus
),wPortChange
);
87 printf("wPortChange = %04X ",x
);
88 if (x
& 1) printf("ConnectChange ");
89 if (x
& 2) printf("EnableChange ");
90 if (x
& 4) printf("SuspendChange ");
91 if (x
& 8) printf("OverCurrentChange ");
92 if (x
& 16) printf("ResetChange ");
96 void usb_dbg_dumpeptdescr(usb_endpoint_descr_t
* epdscr
)
98 printf("---------------------------------------------------\n");
99 printf("ENDPOINT DESCRIPTOR\n");
101 printf("bLength = %d\n",epdscr
->bLength
);
102 printf("bDescriptorType = %d\n",epdscr
->bDescriptorType
);
103 printf("bEndpointAddr = %02X\n",epdscr
->bEndpointAddress
);
104 printf("bmAttrbutes = %02X\n",epdscr
->bmAttributes
);
105 printf("wMaxPacketSize = %d\n",GETUSBFIELD(epdscr
,wMaxPacketSize
));
106 printf("bInterval = %d\n",epdscr
->bInterval
);
109 static char *getstringmaybe(usbdev_t
*dev
,int string
)
111 static char buf
[256];
120 memset(buf
,0,sizeof(buf
));
122 usb_get_string(dev
,string
,buf
,sizeof(buf
));
127 void usb_dbg_dumpdescriptors(usbdev_t
*dev
,uint8_t *ptr
,int len
)
130 usb_config_descr_t
*cfgdscr
;
131 usb_interface_descr_t
*ifdscr
;
132 usb_device_descr_t
*devdscr
;
133 usb_endpoint_descr_t
*epdscr
;
134 usb_hid_descr_t
*hiddscr
;
135 usb_hub_descr_t
*hubdscr
;
136 static char *eptattribs
[4] = {"Control","Isoc","Bulk","Interrupt"};
141 while (ptr
< endptr
) {
143 cfgdscr
= (usb_config_descr_t
*) ptr
;
145 switch (cfgdscr
->bDescriptorType
) {
146 case USB_DEVICE_DESCRIPTOR_TYPE
:
147 devdscr
= (usb_device_descr_t
*) ptr
;
148 printf("---------------------------------------------------\n");
149 printf("DEVICE DESCRIPTOR\n");
150 printf("bLength = %d\n",devdscr
->bLength
);
151 printf("bDescriptorType = %d\n",devdscr
->bDescriptorType
);
152 printf("bcdUSB = %04X\n",GETUSBFIELD(devdscr
,bcdUSB
));
153 printf("bDeviceClass = %d\n",devdscr
->bDeviceClass
);
154 printf("bDeviceSubClass = %d\n",devdscr
->bDeviceSubClass
);
155 printf("bDeviceProtocol = %d\n",devdscr
->bDeviceProtocol
);
156 printf("bMaxPktSize0 = %d\n",devdscr
->bMaxPacketSize0
);
157 if (endptr
-ptr
<= 8) break;
158 printf("idVendor = %04X (%d)\n",
159 GETUSBFIELD(devdscr
,idVendor
),
160 GETUSBFIELD(devdscr
,idVendor
));
161 printf("idProduct = %04X (%d)\n",
162 GETUSBFIELD(devdscr
,idProduct
),
163 GETUSBFIELD(devdscr
,idProduct
));
164 printf("bcdDevice = %04X\n",GETUSBFIELD(devdscr
,bcdDevice
));
165 printf("iManufacturer = %d (%s)\n",
166 devdscr
->iManufacturer
,
167 getstringmaybe(dev
,devdscr
->iManufacturer
));
168 printf("iProduct = %d (%s)\n",
170 getstringmaybe(dev
,devdscr
->iProduct
));
171 printf("iSerialNumber = %d (%s)\n",
172 devdscr
->iSerialNumber
,
173 getstringmaybe(dev
,devdscr
->iSerialNumber
));
174 printf("bNumConfigs = %d\n",devdscr
->bNumConfigurations
);
176 case USB_CONFIGURATION_DESCRIPTOR_TYPE
:
178 cfgdscr
= (usb_config_descr_t
*) ptr
;
179 printf("---------------------------------------------------\n");
180 printf("CONFIG DESCRIPTOR\n");
182 printf("bLength = %d\n",cfgdscr
->bLength
);
183 printf("bDescriptorType = %d\n",cfgdscr
->bDescriptorType
);
184 printf("wTotalLength = %d\n",GETUSBFIELD(cfgdscr
,wTotalLength
));
185 printf("bNumInterfaces = %d\n",cfgdscr
->bNumInterfaces
);
186 printf("bConfigValue = %d\n",cfgdscr
->bConfigurationValue
);
187 printf("iConfiguration = %d (%s)\n",
188 cfgdscr
->iConfiguration
,
189 getstringmaybe(dev
,cfgdscr
->iConfiguration
));
190 printf("bmAttributes = %02X\n",cfgdscr
->bmAttributes
);
191 printf("MaxPower = %d (%dma)\n",cfgdscr
->MaxPower
,cfgdscr
->MaxPower
*2);
194 case USB_INTERFACE_DESCRIPTOR_TYPE
:
195 printf("---------------------------------------------------\n");
196 printf("INTERFACE DESCRIPTOR\n");
198 ifdscr
= (usb_interface_descr_t
*) ptr
;
200 printf("bLength = %d\n",ifdscr
->bLength
);
201 printf("bDescriptorType = %d\n",ifdscr
->bDescriptorType
);
202 printf("bInterfaceNum = %d\n",ifdscr
->bInterfaceNumber
);
203 printf("bAlternateSet = %d\n",ifdscr
->bAlternateSetting
);
204 printf("bNumEndpoints = %d\n",ifdscr
->bNumEndpoints
);
205 printf("bInterfaceClass = %d\n",ifdscr
->bInterfaceClass
);
206 printf("bInterSubClass = %d\n",ifdscr
->bInterfaceSubClass
);
207 printf("bInterfaceProto = %d\n",ifdscr
->bInterfaceProtocol
);
208 printf("iInterface = %d (%s)\n",
210 getstringmaybe(dev
,ifdscr
->iInterface
));
213 case USB_ENDPOINT_DESCRIPTOR_TYPE
:
214 printf("---------------------------------------------------\n");
215 printf("ENDPOINT DESCRIPTOR\n");
217 epdscr
= (usb_endpoint_descr_t
*) ptr
;
219 printf("bLength = %d\n",epdscr
->bLength
);
220 printf("bDescriptorType = %d\n",epdscr
->bDescriptorType
);
221 printf("bEndpointAddr = %02X (%d,%s)\n",
222 epdscr
->bEndpointAddress
,
223 epdscr
->bEndpointAddress
& 0x0F,
224 (epdscr
->bEndpointAddress
& USB_ENDPOINT_DIRECTION_IN
) ? "IN" : "OUT"
226 printf("bmAttrbutes = %02X (%s)\n",
227 epdscr
->bmAttributes
,
228 eptattribs
[epdscr
->bmAttributes
&3]);
229 printf("wMaxPacketSize = %d\n",GETUSBFIELD(epdscr
,wMaxPacketSize
));
230 printf("bInterval = %d\n",epdscr
->bInterval
);
233 case USB_HID_DESCRIPTOR_TYPE
:
234 printf("---------------------------------------------------\n");
235 printf("HID DESCRIPTOR\n");
237 hiddscr
= (usb_hid_descr_t
*) ptr
;
239 printf("bLength = %d\n",hiddscr
->bLength
);
240 printf("bDescriptorType = %d\n",hiddscr
->bDescriptorType
);
241 printf("bcdHID = %04X\n",GETUSBFIELD(hiddscr
,bcdHID
));
242 printf("bCountryCode = %d\n",hiddscr
->bCountryCode
);
243 printf("bNumDescriptors = %d\n",hiddscr
->bNumDescriptors
);
244 printf("bClassDescrType = %d\n",hiddscr
->bClassDescrType
);
245 printf("wClassDescrLen = %d\n",GETUSBFIELD(hiddscr
,wClassDescrLength
));
248 case USB_HUB_DESCRIPTOR_TYPE
:
249 printf("---------------------------------------------------\n");
250 printf("HUB DESCRIPTOR\n");
252 hubdscr
= (usb_hub_descr_t
*) ptr
;
254 printf("bLength = %d\n",hubdscr
->bDescriptorLength
);
255 printf("bDescriptorType = %d\n",hubdscr
->bDescriptorType
);
256 printf("bNumberOfPorts = %d\n",hubdscr
->bNumberOfPorts
);
257 printf("wHubCharacters = %04X\n",GETUSBFIELD(hubdscr
,wHubCharacteristics
));
258 printf("bPowerOnToPwrGd = %d\n",hubdscr
->bPowerOnToPowerGood
);
259 printf("bHubControlCurr = %d (ma)\n",hubdscr
->bHubControlCurrent
);
260 printf("bRemPwerMask[0] = %02X\n",hubdscr
->bRemoveAndPowerMask
[0]);
265 printf("---------------------------------------------------\n");
266 printf("UNKNOWN DESCRIPTOR\n");
267 printf("bLength = %d\n",cfgdscr
->bLength
);
268 printf("bDescriptorType = %d\n",cfgdscr
->bDescriptorType
);
269 printf("Data Bytes = ");
270 for (idx
= 0; idx
< cfgdscr
->bLength
; idx
++) {
271 printf("%02X ",ptr
[idx
]);
277 ptr
+= cfgdscr
->bLength
;
283 void usb_dbg_dumpcfgdescr(usbdev_t
*dev
)
288 usb_config_descr_t
*cfgdscr
;
290 memset(buffer
,0,sizeof(buffer
));
292 cfgdscr
= (usb_config_descr_t
*) &buffer
[0];
294 res
= usb_get_config_descriptor(dev
,cfgdscr
,0,sizeof(usb_config_descr_t
));
295 if (res
!= sizeof(usb_config_descr_t
)) {
296 printf("[a]usb_get_config_descriptor returns %d\n",res
);
299 len
= GETUSBFIELD(cfgdscr
,wTotalLength
);
301 res
= usb_get_config_descriptor(dev
,cfgdscr
,0,len
);
303 printf("[b]usb_get_config_descriptor returns %d\n",res
);
306 usb_dbg_dumpdescriptors(dev
,&buffer
[0],res
);