libusb/winusb: track open/close state

This commit is contained in:
Matthias Ringwald 2018-09-24 09:59:04 +02:00
parent 1b5d2ea069
commit d2b52257dc
2 changed files with 26 additions and 1 deletions

View File

@ -227,6 +227,9 @@ static int sco_out_addr;
static int usb_path_len;
static uint8_t usb_path[USB_MAX_PATH_LEN];
// transport interface state
static int usb_transport_open;
#ifdef ENABLE_SCO_OVER_HCI
static void sco_ring_init(void){
@ -921,6 +924,8 @@ static void usb_sco_stop(void){
static int usb_open(void){
int r;
if (usb_transport_open) return 0;
handle_packet = NULL;
// default endpoint addresses
@ -1113,6 +1118,8 @@ static int usb_open(void){
usb_timer_active = 1;
}
usb_transport_open = 1;
return 0;
}
@ -1120,6 +1127,8 @@ static int usb_close(void){
int c;
int completed = 0;
if (!usb_transport_open) return 0;
log_info("usb_close");
switch (libusb_state){
@ -1252,6 +1261,7 @@ static int usb_close(void){
libusb_state = LIB_USB_CLOSED;
handle = NULL;
usb_transport_open = 0;
return 0;
}

View File

@ -251,6 +251,8 @@ static int usb_acl_out_active;
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];
// transport interface state
static int usb_transport_open;
#ifdef ENABLE_SCO_OVER_HCI
@ -1078,6 +1080,8 @@ static BOOL usb_lookup_symbols(void){
// returns 0 on success, -1 otherwise
static int usb_open(void){
if (usb_transport_open) return 0;
int r = -1;
#ifdef ENABLE_SCO_OVER_HCI
@ -1200,13 +1204,20 @@ static int usb_open(void){
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;
}
static int usb_close(void){
if (!usb_transport_open == 0) return 0;
// remove data sources
btstack_run_loop_remove_data_source(&usb_data_source_command_out);
btstack_run_loop_remove_data_source(&usb_data_source_event_in);
@ -1246,6 +1257,10 @@ static int usb_close(void){
// free everything
usb_free_resources();
// transport closed
usb_transport_open = 0;
return 0;
}