mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-04-17 20:42:47 +00:00
libusb/winusb: track open/close state
This commit is contained in:
parent
1b5d2ea069
commit
d2b52257dc
@ -227,6 +227,9 @@ static int sco_out_addr;
|
|||||||
static int usb_path_len;
|
static int usb_path_len;
|
||||||
static uint8_t usb_path[USB_MAX_PATH_LEN];
|
static uint8_t usb_path[USB_MAX_PATH_LEN];
|
||||||
|
|
||||||
|
// transport interface state
|
||||||
|
static int usb_transport_open;
|
||||||
|
|
||||||
|
|
||||||
#ifdef ENABLE_SCO_OVER_HCI
|
#ifdef ENABLE_SCO_OVER_HCI
|
||||||
static void sco_ring_init(void){
|
static void sco_ring_init(void){
|
||||||
@ -921,6 +924,8 @@ static void usb_sco_stop(void){
|
|||||||
static int usb_open(void){
|
static int usb_open(void){
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
|
if (usb_transport_open) return 0;
|
||||||
|
|
||||||
handle_packet = NULL;
|
handle_packet = NULL;
|
||||||
|
|
||||||
// default endpoint addresses
|
// default endpoint addresses
|
||||||
@ -1113,6 +1118,8 @@ static int usb_open(void){
|
|||||||
usb_timer_active = 1;
|
usb_timer_active = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
usb_transport_open = 1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1120,6 +1127,8 @@ static int usb_close(void){
|
|||||||
int c;
|
int c;
|
||||||
int completed = 0;
|
int completed = 0;
|
||||||
|
|
||||||
|
if (!usb_transport_open) return 0;
|
||||||
|
|
||||||
log_info("usb_close");
|
log_info("usb_close");
|
||||||
|
|
||||||
switch (libusb_state){
|
switch (libusb_state){
|
||||||
@ -1252,6 +1261,7 @@ static int usb_close(void){
|
|||||||
|
|
||||||
libusb_state = LIB_USB_CLOSED;
|
libusb_state = LIB_USB_CLOSED;
|
||||||
handle = NULL;
|
handle = NULL;
|
||||||
|
usb_transport_open = 0;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -251,6 +251,8 @@ static int usb_acl_out_active;
|
|||||||
static uint8_t hci_event_in_buffer[2 + 255];
|
static uint8_t hci_event_in_buffer[2 + 255];
|
||||||
static uint8_t hci_acl_in_buffer[HCI_INCOMING_PRE_BUFFER_SIZE + HCI_ACL_BUFFER_SIZE];
|
static uint8_t hci_acl_in_buffer[HCI_INCOMING_PRE_BUFFER_SIZE + HCI_ACL_BUFFER_SIZE];
|
||||||
|
|
||||||
|
// transport interface state
|
||||||
|
static int usb_transport_open;
|
||||||
|
|
||||||
#ifdef ENABLE_SCO_OVER_HCI
|
#ifdef ENABLE_SCO_OVER_HCI
|
||||||
|
|
||||||
@ -1078,6 +1080,8 @@ static BOOL usb_lookup_symbols(void){
|
|||||||
// returns 0 on success, -1 otherwise
|
// returns 0 on success, -1 otherwise
|
||||||
static int usb_open(void){
|
static int usb_open(void){
|
||||||
|
|
||||||
|
if (usb_transport_open) return 0;
|
||||||
|
|
||||||
int r = -1;
|
int r = -1;
|
||||||
|
|
||||||
#ifdef ENABLE_SCO_OVER_HCI
|
#ifdef ENABLE_SCO_OVER_HCI
|
||||||
@ -1200,13 +1204,20 @@ static int usb_open(void){
|
|||||||
|
|
||||||
SetupDiDestroyDeviceInfoList(hDevInfo);
|
SetupDiDestroyDeviceInfoList(hDevInfo);
|
||||||
|
|
||||||
log_info("usb_open: done");
|
log_info("usb_open: done, r = %x", r);
|
||||||
|
|
||||||
|
if (r == 0){
|
||||||
|
// opened
|
||||||
|
usb_transport_open = 1;
|
||||||
|
}
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int usb_close(void){
|
static int usb_close(void){
|
||||||
|
|
||||||
|
if (!usb_transport_open == 0) return 0;
|
||||||
|
|
||||||
// remove data sources
|
// remove data sources
|
||||||
btstack_run_loop_remove_data_source(&usb_data_source_command_out);
|
btstack_run_loop_remove_data_source(&usb_data_source_command_out);
|
||||||
btstack_run_loop_remove_data_source(&usb_data_source_event_in);
|
btstack_run_loop_remove_data_source(&usb_data_source_event_in);
|
||||||
@ -1246,6 +1257,10 @@ static int usb_close(void){
|
|||||||
|
|
||||||
// free everything
|
// free everything
|
||||||
usb_free_resources();
|
usb_free_resources();
|
||||||
|
|
||||||
|
// transport closed
|
||||||
|
usb_transport_open = 0;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user