Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added function to libusb interface that allows addressing of devices … #288

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion platform/libusb/hci_transport_h2_libusb.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ static int sco_out_addr;

// device path
static int usb_path_len;
static uint8_t dev_addr;
static uint8_t usb_path[USB_MAX_PATH_LEN];

// transport interface state
Expand All @@ -245,11 +246,15 @@ void hci_transport_usb_set_path(int len, uint8_t * port_numbers){
if (len > USB_MAX_PATH_LEN || !port_numbers){
log_error("hci_transport_usb_set_path: len or port numbers invalid");
return;
}
}
usb_path_len = len;
memcpy(usb_path, port_numbers, len);
}

void hci_transport_usb_set_address(uint8_t _dev_addr){
dev_addr = _dev_addr;
}

//
static void queue_transfer(struct libusb_transfer *transfer){

Expand Down Expand Up @@ -1019,6 +1024,37 @@ static int usb_open(void){
printf("USB device with given path not found\n");
return -1;
}
} else if(dev_addr) {

for (int i=0;i<num_devices;i++)
{
if(libusb_get_device_address(devs[i]) == dev_addr)
{
printf("Found Specified USB device\n");
handle = try_open_device(devs[i]);

if (!handle) continue;

r = prepare_device(handle);
if (r < 0) {
handle = NULL;
continue;
}

dev = devs[i];
r = scan_for_bt_endpoints(dev);
if (r < 0) {
handle = NULL;
continue;
}

libusb_state = LIB_USB_INTERFACE_CLAIMED;
break;
}
}
if(!handle)
printf("Did not find Specified USB device\n");

} else {

int deviceIndex = -1;
Expand Down
5 changes: 5 additions & 0 deletions src/hci_transport.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ const hci_transport_t * hci_transport_usb_instance(void);
*/
void hci_transport_usb_set_path(int len, uint8_t * port_numbers);

/**
* @brief Specify USB Bluetooth device via device address
*/
void hci_transport_usb_set_address(uint8_t _dev_addr);

/* API_END */

#if defined __cplusplus
Expand Down