Revision 5fafdf24 usb-linux.c

b/usb-linux.c
2 2
 * Linux host USB redirector
3 3
 *
4 4
 * Copyright (c) 2005 Fabrice Bellard
5
 * 
5
 *
6 6
 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 7
 * of this software and associated documentation files (the "Software"), to deal
8 8
 * in the Software without restriction, including without limitation the rights
......
41 41
};
42 42

  
43 43
typedef int USBScanFunc(void *opaque, int bus_num, int addr, int class_id,
44
                        int vendor_id, int product_id, 
44
                        int vendor_id, int product_id,
45 45
                        const char *product_name, int speed);
46
static int usb_host_find_device(int *pbus_num, int *paddr, 
46
static int usb_host_find_device(int *pbus_num, int *paddr,
47 47
                                char *product_name, int product_name_size,
48 48
                                const char *devname);
49 49

  
......
65 65
       done by the host OS */
66 66
    ioctl(s->fd, USBDEVFS_RESET);
67 67
#endif
68
} 
68
}
69 69

  
70 70
static void usb_host_handle_destroy(USBDevice *dev)
71 71
{
......
157 157
    int bus_num, addr;
158 158
    char product_name[PRODUCT_NAME_SZ];
159 159

  
160
    if (usb_host_find_device(&bus_num, &addr, 
160
    if (usb_host_find_device(&bus_num, &addr,
161 161
                             product_name, sizeof(product_name),
162
                             devname) < 0) 
162
                             devname) < 0)
163 163
        return NULL;
164
    
165
    snprintf(buf, sizeof(buf), USBDEVFS_PATH "/%03d/%03d", 
164
   
165
    snprintf(buf, sizeof(buf), USBDEVFS_PATH "/%03d/%03d",
166 166
             bus_num, addr);
167 167
    fd = open(buf, O_RDWR);
168 168
    if (fd < 0) {
......
176 176
        perror("read descr");
177 177
        goto fail;
178 178
    }
179
    
179
   
180 180
    i = 0;
181 181
    dev_descr_len = descr[0];
182 182
    if (dev_descr_len > descr_len)
......
228 228

  
229 229
#ifdef DEBUG
230 230
    printf("host USB device %d.%d grabbed\n", bus_num, addr);
231
#endif    
231
#endif   
232 232

  
233 233
    dev = qemu_mallocz(sizeof(USBHostDevice));
234 234
    if (!dev)
......
256 256
}
257 257

  
258 258
static int get_tag_value(char *buf, int buf_size,
259
                         const char *str, const char *tag, 
259
                         const char *str, const char *tag,
260 260
                         const char *stopchars)
261 261
{
262 262
    const char *p;
......
285 285
    int bus_num, addr, speed, device_count, class_id, product_id, vendor_id;
286 286
    int ret;
287 287
    char product_name[512];
288
    
288
   
289 289
    f = fopen(USBDEVFS_PATH "/devices", "r");
290 290
    if (!f) {
291 291
        term_printf("Could not open %s\n", USBDEVFS_PATH "/devices");
......
302 302
        if (line[0] == 'T' && line[1] == ':') {
303 303
            if (device_count && (vendor_id || product_id)) {
304 304
                /* New device.  Add the previously discovered device.  */
305
                ret = func(opaque, bus_num, addr, class_id, vendor_id, 
305
                ret = func(opaque, bus_num, addr, class_id, vendor_id,
306 306
                           product_id, product_name, speed);
307 307
                if (ret)
308 308
                    goto the_end;
......
346 346
    }
347 347
    if (device_count && (vendor_id || product_id)) {
348 348
        /* Add the last device.  */
349
        ret = func(opaque, bus_num, addr, class_id, vendor_id, 
349
        ret = func(opaque, bus_num, addr, class_id, vendor_id,
350 350
                   product_id, product_name, speed);
351 351
    }
352 352
 the_end:
......
362 362
    char product_name[PRODUCT_NAME_SZ];
363 363
} FindDeviceState;
364 364

  
365
static int usb_host_find_device_scan(void *opaque, int bus_num, int addr, 
365
static int usb_host_find_device_scan(void *opaque, int bus_num, int addr,
366 366
                                     int class_id,
367
                                     int vendor_id, int product_id, 
367
                                     int vendor_id, int product_id,
368 368
                                     const char *product_name, int speed)
369 369
{
370 370
    FindDeviceState *s = opaque;
......
381 381
    }
382 382
}
383 383

  
384
/* the syntax is : 
385
   'bus.addr' (decimal numbers) or 
384
/* the syntax is :
385
   'bus.addr' (decimal numbers) or
386 386
   'vendor_id:product_id' (hexa numbers) */
387
static int usb_host_find_device(int *pbus_num, int *paddr, 
387
static int usb_host_find_device(int *pbus_num, int *paddr,
388 388
                                char *product_name, int product_name_size,
389 389
                                const char *devname)
390 390
{
......
454 454
}
455 455

  
456 456
void usb_info_device(int bus_num, int addr, int class_id,
457
                     int vendor_id, int product_id, 
457
                     int vendor_id, int product_id,
458 458
                     const char *product_name,
459 459
                     int speed)
460 460
{
461 461
    const char *class_str, *speed_str;
462 462

  
463 463
    switch(speed) {
464
    case USB_SPEED_LOW: 
465
        speed_str = "1.5"; 
464
    case USB_SPEED_LOW:
465
        speed_str = "1.5";
466 466
        break;
467
    case USB_SPEED_FULL: 
468
        speed_str = "12"; 
467
    case USB_SPEED_FULL:
468
        speed_str = "12";
469 469
        break;
470
    case USB_SPEED_HIGH: 
471
        speed_str = "480"; 
470
    case USB_SPEED_HIGH:
471
        speed_str = "480";
472 472
        break;
473 473
    default:
474
        speed_str = "?"; 
474
        speed_str = "?";
475 475
        break;
476 476
    }
477 477

  
478
    term_printf("  Device %d.%d, speed %s Mb/s\n", 
478
    term_printf("  Device %d.%d, speed %s Mb/s\n",
479 479
                bus_num, addr, speed_str);
480 480
    class_str = usb_class_str(class_id);
481
    if (class_str) 
481
    if (class_str)
482 482
        term_printf("    %s:", class_str);
483 483
    else
484 484
        term_printf("    Class %02x:", class_id);
......
488 488
    term_printf("\n");
489 489
}
490 490

  
491
static int usb_host_info_device(void *opaque, int bus_num, int addr, 
491
static int usb_host_info_device(void *opaque, int bus_num, int addr,
492 492
                                int class_id,
493
                                int vendor_id, int product_id, 
493
                                int vendor_id, int product_id,
494 494
                                const char *product_name,
495 495
                                int speed)
496 496
{

Also available in: Unified diff