dump.c (cf109686d0a89f698ba59a65d3199bdfc151f88a) | dump.c (eabe30fc9c3f2d6a3bc2fdcce18a0b9543b6c96e) |
---|---|
1/* $FreeBSD$ */ 2/*- 3 * Copyright (c) 2008 Hans Petter Selasky. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 82 unchanged lines hidden (view full) --- 91 return ("UNKNOWN"); 92 } 93} 94 95static void 96dump_field(struct libusb20_device *pdev, const char *plevel, 97 const char *field, uint32_t value) 98{ | 1/* $FreeBSD$ */ 2/*- 3 * Copyright (c) 2008 Hans Petter Selasky. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 82 unchanged lines hidden (view full) --- 91 return ("UNKNOWN"); 92 } 93} 94 95static void 96dump_field(struct libusb20_device *pdev, const char *plevel, 97 const char *field, uint32_t value) 98{ |
99 struct LIBUSB20_CONTROL_SETUP_DECODED req; 100 uint16_t lang_id; 101 uint8_t index; |
|
99 uint8_t temp_string[256]; 100 101 printf("%s%s = 0x%04x ", plevel, field, value); 102 | 102 uint8_t temp_string[256]; 103 104 printf("%s%s = 0x%04x ", plevel, field, value); 105 |
103 if (strlen(plevel) == 8) { 104 /* Endpoint Descriptor */ | 106 if ((field[0] != 'i') || (field[1] == 'd')) { 107 printf("\n"); 108 return; 109 } 110 if (value == 0) { 111 printf(" <no string> \n"); 112 return; 113 } 114 LIBUSB20_INIT(LIBUSB20_CONTROL_SETUP, &req); |
105 | 115 |
106 if (strcmp(field, "bEndpointAddress") == 0) { 107 if (value & 0x80) 108 printf(" <IN>\n"); 109 else 110 printf(" <OUT>\n"); 111 return; 112 } | 116 lang_id = 0; 117 index = 0; |
113 | 118 |
114 if (strcmp(field, "bmAttributes") == 0) { 115 switch (value & 0x03) { 116 case 0: 117 printf(" <CONTROL>\n"); 118 break; 119 case 1: 120 switch (value & 0x0C) { 121 case 0x00: 122 printf(" <ISOCHRONOUS>\n"); 123 break; 124 case 0x04: 125 printf(" <ASYNC-ISOCHRONOUS>\n"); 126 break; 127 case 0x08: 128 printf(" <ADAPT-ISOCHRONOUS>\n"); 129 break; 130 default: 131 printf(" <SYNC-ISOCHRONOUS>\n"); 132 break; 133 } 134 break; 135 case 2: 136 printf(" <BULK>\n"); 137 break; 138 default: 139 printf(" <INTERRUPT>\n"); 140 break; 141 } 142 return; 143 } | 119 req.bmRequestType = 120 LIBUSB20_REQUEST_TYPE_STANDARD | 121 LIBUSB20_RECIPIENT_DEVICE | 122 LIBUSB20_ENDPOINT_IN; 123 req.bRequest = LIBUSB20_REQUEST_GET_DESCRIPTOR; 124 req.wValue = (256 * LIBUSB20_DT_STRING) | index; 125 req.wIndex = lang_id; 126 req.wLength = 4; /* bytes */ 127 128 if (libusb20_dev_request_sync(pdev, &req, 129 temp_string, NULL, 1000, 0)) { 130 goto done; |
144 } | 131 } |
132 lang_id = temp_string[2] | (temp_string[3] << 8); |
|
145 | 133 |
146 if ((field[0] == 'i') && (field[1] != 'd')) { 147 /* Indirect String Descriptor */ 148 if (value == 0) { 149 printf(" <no string>\n"); 150 return; 151 } 152 if (libusb20_dev_req_string_simple_sync(pdev, value, 153 temp_string, sizeof(temp_string))) { 154 printf(" <retrieving string failed>\n"); 155 return; 156 } 157 printf(" <%s>\n", temp_string); 158 return; | 134 printf(" LangId:0x%04x <", lang_id); 135 136 index = value; 137 138 req.wValue = (256 * LIBUSB20_DT_STRING) | index; 139 req.wIndex = lang_id; 140 req.wLength = 4; /* bytes */ 141 142 if (libusb20_dev_request_sync(pdev, &req, 143 temp_string, NULL, 1000, 0)) { 144 printf("ERROR>\n"); 145 goto done; |
159 } | 146 } |
147 req.wValue = (256 * LIBUSB20_DT_STRING) | index; 148 req.wIndex = lang_id; 149 req.wLength = temp_string[0]; /* bytes */ |
|
160 | 150 |
161 /* No additional information */ 162 printf("\n"); | 151 if (libusb20_dev_request_sync(pdev, &req, 152 temp_string, NULL, 1000, 0)) { 153 printf("ERROR>\n"); 154 goto done; 155 } 156 req.wLength /= 2; 157 158 for (index = 1; index != req.wLength; index++) { 159 if (isprint(temp_string[(2 * index) + 0])) { 160 printf("%c", temp_string[(2 * index) + 0]); 161 } else if (isprint(temp_string[(2 * index) + 1])) { 162 printf("%c", temp_string[(2 * index) + 1]); 163 } else { 164 printf("?"); 165 } 166 } 167 printf(">\n"); 168done: 169 return; |
163} 164 165static void 166dump_extra(struct libusb20_me_struct *str, const char *plevel) 167{ 168 const uint8_t *ptr; 169 uint8_t x; 170 --- 45 unchanged lines hidden (view full) --- 216 for (z = 0; z != iface->num_endpoints; z++) { 217 printf("\n Endpoint %u\n", z); 218 dump_endpoint(pdev, iface->endpoints + z); 219 } 220 return; 221} 222 223void | 170} 171 172static void 173dump_extra(struct libusb20_me_struct *str, const char *plevel) 174{ 175 const uint8_t *ptr; 176 uint8_t x; 177 --- 45 unchanged lines hidden (view full) --- 223 for (z = 0; z != iface->num_endpoints; z++) { 224 printf("\n Endpoint %u\n", z); 225 dump_endpoint(pdev, iface->endpoints + z); 226 } 227 return; 228} 229 230void |
224dump_device_info(struct libusb20_device *pdev, uint8_t show_ifdrv) | 231dump_device_info(struct libusb20_device *pdev) |
225{ | 232{ |
226 char buf[128]; 227 uint8_t n; 228 | |
229 printf("%s, cfg=%u md=%s spd=%s pwr=%s\n", 230 libusb20_dev_get_desc(pdev), 231 libusb20_dev_get_config_index(pdev), 232 dump_mode(libusb20_dev_get_mode(pdev)), 233 dump_speed(libusb20_dev_get_speed(pdev)), 234 dump_power_mode(libusb20_dev_get_power_mode(pdev))); | 233 printf("%s, cfg=%u md=%s spd=%s pwr=%s\n", 234 libusb20_dev_get_desc(pdev), 235 libusb20_dev_get_config_index(pdev), 236 dump_mode(libusb20_dev_get_mode(pdev)), 237 dump_speed(libusb20_dev_get_speed(pdev)), 238 dump_power_mode(libusb20_dev_get_power_mode(pdev))); |
235 236 if (!show_ifdrv) 237 return; 238 239 for (n = 0; n != 255; n++) { 240 if (libusb20_dev_get_iface_desc(pdev, n, buf, sizeof(buf))) 241 break; 242 if (buf[0] == 0) 243 continue; 244 printf("ugen%u.%u.%u: %s\n", 245 libusb20_dev_get_bus_number(pdev), 246 libusb20_dev_get_address(pdev), n, buf); 247 } | 239 return; |
248} 249 250void 251dump_be_quirk_names(struct libusb20_backend *pbe) 252{ 253 struct libusb20_quirk q; 254 uint16_t x; | 240} 241 242void 243dump_be_quirk_names(struct libusb20_backend *pbe) 244{ 245 struct libusb20_quirk q; 246 uint16_t x; |
255 int error; | 247 int err; |
256 257 memset(&q, 0, sizeof(q)); 258 259 printf("\nDumping list of supported quirks:\n\n"); 260 261 for (x = 0; x != 0xFFFF; x++) { 262 | 248 249 memset(&q, 0, sizeof(q)); 250 251 printf("\nDumping list of supported quirks:\n\n"); 252 253 for (x = 0; x != 0xFFFF; x++) { 254 |
263 error = libusb20_be_get_quirk_name(pbe, x, &q); 264 if (error) { | 255 err = libusb20_be_get_quirk_name(pbe, x, &q); 256 if (err) { |
265 if (x == 0) { 266 printf("No quirk names - maybe the USB quirk " 267 "module has not been loaded.\n"); 268 } 269 break; 270 } 271 if (strcmp(q.quirkname, "UQ_NONE")) 272 printf("%s\n", q.quirkname); 273 } 274 printf("\n"); 275 return; 276} 277 278void 279dump_be_dev_quirks(struct libusb20_backend *pbe) 280{ 281 struct libusb20_quirk q; 282 uint16_t x; | 257 if (x == 0) { 258 printf("No quirk names - maybe the USB quirk " 259 "module has not been loaded.\n"); 260 } 261 break; 262 } 263 if (strcmp(q.quirkname, "UQ_NONE")) 264 printf("%s\n", q.quirkname); 265 } 266 printf("\n"); 267 return; 268} 269 270void 271dump_be_dev_quirks(struct libusb20_backend *pbe) 272{ 273 struct libusb20_quirk q; 274 uint16_t x; |
283 int error; | 275 int err; |
284 285 memset(&q, 0, sizeof(q)); 286 287 printf("\nDumping current device quirks:\n\n"); 288 289 for (x = 0; x != 0xFFFF; x++) { 290 | 276 277 memset(&q, 0, sizeof(q)); 278 279 printf("\nDumping current device quirks:\n\n"); 280 281 for (x = 0; x != 0xFFFF; x++) { 282 |
291 error = libusb20_be_get_dev_quirk(pbe, x, &q); 292 if (error) { | 283 err = libusb20_be_get_dev_quirk(pbe, x, &q); 284 if (err) { |
293 if (x == 0) { 294 printf("No device quirks - maybe the USB quirk " 295 "module has not been loaded.\n"); 296 } 297 break; 298 } 299 if (strcmp(q.quirkname, "UQ_NONE")) { 300 printf("VID=0x%04x PID=0x%04x REVLO=0x%04x " 301 "REVHI=0x%04x QUIRK=%s\n", 302 q.vid, q.pid, q.bcdDeviceLow, 303 q.bcdDeviceHigh, q.quirkname); 304 } 305 } 306 printf("\n"); 307 return; 308} 309 310void | 285 if (x == 0) { 286 printf("No device quirks - maybe the USB quirk " 287 "module has not been loaded.\n"); 288 } 289 break; 290 } 291 if (strcmp(q.quirkname, "UQ_NONE")) { 292 printf("VID=0x%04x PID=0x%04x REVLO=0x%04x " 293 "REVHI=0x%04x QUIRK=%s\n", 294 q.vid, q.pid, q.bcdDeviceLow, 295 q.bcdDeviceHigh, q.quirkname); 296 } 297 } 298 printf("\n"); 299 return; 300} 301 302void |
303dump_be_access(struct libusb20_backend *pbe) 304{ 305 struct group *gr; 306 struct passwd *pw; 307 const char *owner; 308 const char *group; 309 uid_t uid; 310 gid_t gid; 311 mode_t mode; 312 313 if (libusb20_be_get_owner(pbe, &uid, &gid)) { 314 err(1, "could not get owner"); 315 } 316 if (libusb20_be_get_perm(pbe, &mode)) { 317 err(1, "could not get permission"); 318 } 319 owner = (pw = getpwuid(uid)) ? pw->pw_name : "UNKNOWN"; 320 group = (gr = getgrgid(gid)) ? gr->gr_name : "UNKNOWN"; 321 322 if (mode || 1) { 323 printf("Global Access: %s:%s 0%o\n", owner, group, mode); 324 } else { 325 printf("Global Access: <not set>\n"); 326 } 327 return; 328} 329 330void 331dump_device_access(struct libusb20_device *pdev, uint8_t iface) 332{ 333 struct group *gr; 334 struct passwd *pw; 335 const char *owner; 336 const char *group; 337 uid_t uid; 338 gid_t gid; 339 mode_t mode; 340 341 if (libusb20_dev_get_owner(pdev, &uid, &gid)) { 342 err(1, "could not get owner"); 343 } 344 if (libusb20_dev_get_perm(pdev, &mode)) { 345 err(1, "could not get permission"); 346 } 347 if (mode) { 348 owner = (pw = getpwuid(uid)) ? pw->pw_name : "UNKNOWN"; 349 group = (gr = getgrgid(gid)) ? gr->gr_name : "UNKNOWN"; 350 351 printf(" " "Device Access: %s:%s 0%o\n", owner, group, mode); 352 353 } else { 354 printf(" " "Device Access: <not set>\n"); 355 } 356 357 if (iface == 0xFF) { 358 for (iface = 0; iface != 0xFF; iface++) { 359 if (dump_device_iface_access(pdev, iface)) { 360 break; 361 } 362 } 363 } else { 364 if (dump_device_iface_access(pdev, iface)) { 365 err(1, "could not get interface access info"); 366 } 367 } 368 return; 369} 370 371int 372dump_device_iface_access(struct libusb20_device *pdev, uint8_t iface) 373{ 374 struct group *gr; 375 struct passwd *pw; 376 const char *owner; 377 const char *group; 378 uid_t uid; 379 gid_t gid; 380 mode_t mode; 381 int error; 382 383 if ((error = libusb20_dev_get_iface_owner(pdev, iface, &uid, &gid))) { 384 return (error); 385 } 386 if ((error = libusb20_dev_get_iface_perm(pdev, iface, &mode))) { 387 return (error); 388 } 389 if (mode) { 390 391 owner = (pw = getpwuid(uid)) ? pw->pw_name : "UNKNOWN"; 392 group = (gr = getgrgid(gid)) ? gr->gr_name : "UNKNOWN"; 393 394 printf(" " "Interface %u Access: %s:%s 0%o\n", iface, owner, group, mode); 395 } else { 396 printf(" " "Interface %u Access: <not set>\n", iface); 397 } 398 399 return (0); 400} 401 402void |
|
311dump_device_desc(struct libusb20_device *pdev) 312{ 313 struct LIBUSB20_DEVICE_DESC_DECODED *ddesc; 314 315 ddesc = libusb20_dev_get_device_desc(pdev); 316 LIBUSB20_DEVICE_DESC(DUMP0, ddesc); 317 return; 318} --- 41 unchanged lines hidden (view full) --- 360 printf("\n"); 361 } 362 } 363 printf("\n"); 364 free(pcfg); 365 } 366 return; 367} | 403dump_device_desc(struct libusb20_device *pdev) 404{ 405 struct LIBUSB20_DEVICE_DESC_DECODED *ddesc; 406 407 ddesc = libusb20_dev_get_device_desc(pdev); 408 LIBUSB20_DEVICE_DESC(DUMP0, ddesc); 409 return; 410} --- 41 unchanged lines hidden (view full) --- 452 printf("\n"); 453 } 454 } 455 printf("\n"); 456 free(pcfg); 457 } 458 return; 459} |
368 369void 370dump_string_by_index(struct libusb20_device *pdev, uint8_t str_index) 371{ 372 char *pbuf; 373 uint8_t n; 374 uint8_t len; 375 376 pbuf = malloc(256); 377 if (pbuf == NULL) 378 err(1, "out of memory"); 379 380 if (str_index == 0) { 381 /* language table */ 382 if (libusb20_dev_req_string_sync(pdev, 383 str_index, 0, pbuf, 256)) { 384 printf("STRING_0x%02x = <read error>\n", str_index); 385 } else { 386 printf("STRING_0x%02x = ", str_index); 387 len = (uint8_t)pbuf[0]; 388 for (n = 0; n != len; n++) { 389 printf("0x%02x%s", (uint8_t)pbuf[n], 390 (n != (len-1)) ? ", " : ""); 391 } 392 printf("\n"); 393 } 394 } else { 395 /* ordinary string */ 396 if (libusb20_dev_req_string_simple_sync(pdev, 397 str_index, pbuf, 256)) { 398 printf("STRING_0x%02x = <read error>\n", str_index); 399 } else { 400 printf("STRING_0x%02x = <%s>\n", str_index, pbuf); 401 } 402 } 403 free(pbuf); 404} | |