handle no USB BT found

This commit is contained in:
matthias.ringwald 2011-01-12 19:45:29 +00:00
parent c30257d4f4
commit aac0272b3e

View File

@ -91,8 +91,7 @@ static struct libusb_transfer *bulk_in_transfer;
static struct libusb_transfer *bulk_out_transfer; static struct libusb_transfer *bulk_out_transfer;
int find_bt(libusb_device **devs) static libusb_device * find_bt(libusb_device **devs) {
{
int i = 0; int i = 0;
while ((dev = devs[i++]) != NULL) { while ((dev = devs[i++]) != NULL) {
int r = libusb_get_device_descriptor(dev, &desc); int r = libusb_get_device_descriptor(dev, &desc);
@ -113,10 +112,10 @@ int find_bt(libusb_device **devs)
if (desc.bDeviceClass == 0xe0 && desc.bDeviceSubClass == 0x01 && desc.bDeviceProtocol == 0x01){ if (desc.bDeviceClass == 0xe0 && desc.bDeviceSubClass == 0x01 && desc.bDeviceProtocol == 0x01){
// if (desc.idVendor == 0x0a12 && desc.idProduct == 0x0001){ // if (desc.idVendor == 0x0a12 && desc.idProduct == 0x0001){
printf("BT Dongle found.\n"); printf("BT Dongle found.\n");
return 1; return dev;
} }
} }
return 0; return NULL;
} }
static void control_callback(struct libusb_transfer *transfer){ static void control_callback(struct libusb_transfer *transfer){
@ -192,31 +191,33 @@ static int usb_open(void *transport_config){
// USB init // USB init
r = libusb_init(NULL); r = libusb_init(NULL);
if (r < 0) { if (r < 0) return -1;
return r;
}
libusb_state = LIB_USB_OPENED; libusb_state = LIB_USB_OPENED;
// Get Devices // Get Devices
cnt = libusb_get_device_list(NULL, &devs); cnt = libusb_get_device_list(NULL, &devs);
if (cnt < 0) { if (cnt < 0) {
usb_close(); usb_close();
return (int) cnt; return -1;
} }
// Find BT modul // Find BT modul
r = find_bt(devs); libusb_device * aDev = find_bt(devs);
if (r) { if (!aDev){
r = libusb_open(dev, &handle); libusb_free_device_list(devs, 1);
printf("libusb open %d, handle %xu\n", r, (int) handle); usb_close();
libusb_state = LIB_USB_OPENED; return -1;
} }
dev = aDev;
r = libusb_open(dev, &handle);
printf("libusb open %d, handle %xu\n", r, (int) handle);
libusb_state = LIB_USB_OPENED;
libusb_free_device_list(devs, 1); libusb_free_device_list(devs, 1);
if (r < 0) { if (r < 0) {
usb_close(); usb_close();
return r; return r;
} }
// libusb_set_debug(0,3); libusb_set_debug(0,3);
// Detach OS driver (not possible for OS X) // Detach OS driver (not possible for OS X)
#ifndef __APPLE__ #ifndef __APPLE__