X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=windows.c;h=523b8d0ac034ba0ebbb486df1c0b6b025ae817c4;hb=d66bbceaa7f86262bc8e758e7a665fcce7340f01;hp=730870a4c1671200e0dbb4b88062b57375eb34ca;hpb=8eb18f7b5a459cde640f307ce46248851fdaec42;p=libserialport.git diff --git a/windows.c b/windows.c index 730870a..523b8d0 100644 --- a/windows.c +++ b/windows.c @@ -24,51 +24,6 @@ /* USB path is a string of at most 8 decimal numbers < 128 separated by dots */ #define MAX_USB_PATH (8*3 + 7*1 + 1) -/* The stuff below is not yet available in MinGW apparently. Define it here. */ - -#ifndef USB_NODE_CONNECTION_INFORMATION_EX -typedef struct _USB_NODE_CONNECTION_INFORMATION_EX { - ULONG ConnectionIndex; - USB_DEVICE_DESCRIPTOR DeviceDescriptor; - UCHAR CurrentConfigurationValue; - UCHAR Speed; - BOOLEAN DeviceIsHub; - USHORT DeviceAddress; - ULONG NumberOfOpenPipes; - USB_CONNECTION_STATUS ConnectionStatus; - USB_PIPE_INFO PipeList[]; -} USB_NODE_CONNECTION_INFORMATION_EX, *PUSB_NODE_CONNECTION_INFORMATION_EX; -#endif - -#ifndef USB_GET_NODE_CONNECTION_INFORMATION_EX -#define USB_GET_NODE_CONNECTION_INFORMATION_EX 274 -#endif - -#ifndef IOCTL_USB_GET_NODE_CONNECTION_INFORMATION_EX -#define IOCTL_USB_GET_NODE_CONNECTION_INFORMATION_EX \ - CTL_CODE(FILE_DEVICE_USB, USB_GET_NODE_CONNECTION_INFORMATION_EX, \ - METHOD_BUFFERED, FILE_ANY_ACCESS) -#endif - -#ifndef CM_DRP_COMPATIBLEIDS -#define CM_DRP_COMPATIBLEIDS 0x03 -#endif -#ifndef CM_DRP_CLASS -#define CM_DRP_CLASS 0x08 -#endif -#ifndef CM_DRP_FRIENDLYNAME -#define CM_DRP_FRIENDLYNAME 0x0d -#endif -#ifndef CM_DRP_ADDRESS -#define CM_DRP_ADDRESS 0x1d -#endif - -#ifndef CM_Get_DevNode_Registry_PropertyA -CMAPI CONFIGRET WINAPI CM_Get_DevNode_Registry_PropertyA(DEVINST dnDevInst, \ - ULONG ulProperty, PULONG pulRegDataType, PVOID Buffer, \ - PULONG pulLength, ULONG ulFlags); -#endif - static void enumerate_hub(struct sp_port *port, char *hub_name, char *parent_path); @@ -298,7 +253,7 @@ static void enumerate_hub(struct sp_port *port, char *hub_name, /* get the number of ports of the hub */ if (DeviceIoControl(hub_device, IOCTL_USB_GET_NODE_INFORMATION, &hub_info, size, &hub_info, size, &size, NULL)) - /* enumarate the ports of the hub */ + /* enumerate the ports of the hub */ enumerate_hub_ports(port, hub_device, hub_info.u.HubInformation.HubDescriptor.bNumberOfPorts, parent_path); @@ -404,8 +359,10 @@ SP_PRIV enum sp_return get_port_details(struct sp_port *port) continue; size = sizeof(value); if (RegQueryValueExA(device_key, "PortName", NULL, &type, (LPBYTE)value, - &size) != ERROR_SUCCESS || type != REG_SZ) + &size) != ERROR_SUCCESS || type != REG_SZ) { + RegCloseKey(device_key); continue; + } RegCloseKey(device_key); value[sizeof(value)-1] = 0; if (strcmp(value, port->name)) @@ -491,12 +448,14 @@ SP_PRIV enum sp_return get_port_details(struct sp_port *port) free(escaped_port_name); CloseHandle(handle); - /* retrive USB device details from the device descriptor */ + /* retrieve USB device details from the device descriptor */ get_usb_details(port, device_info_data.DevInst); } break; } + SetupDiDestroyDeviceInfoList(device_info); + RETURN_OK(); } @@ -539,28 +498,30 @@ SP_PRIV enum sp_return list_ports(struct sp_port ***list) RegEnumValue(key, index, value, &value_len, NULL, &type, (LPBYTE)data, &data_size) == ERROR_SUCCESS) { - data_len = data_size / sizeof(TCHAR); - data[data_len] = '\0'; + if (type == REG_SZ) { + data_len = data_size / sizeof(TCHAR); + data[data_len] = '\0'; #ifdef UNICODE - name_len = WideCharToMultiByte(CP_ACP, 0, data, -1, NULL, 0, NULL, NULL); + name_len = WideCharToMultiByte(CP_ACP, 0, data, -1, NULL, 0, NULL, NULL); #else - name_len = data_len + 1; + name_len = data_len + 1; #endif - if (!(name = malloc(name_len))) { - SET_ERROR(ret, SP_ERR_MEM, "registry port name malloc failed"); - goto out; - } + if (!(name = malloc(name_len))) { + SET_ERROR(ret, SP_ERR_MEM, "registry port name malloc failed"); + goto out; + } #ifdef UNICODE - WideCharToMultiByte(CP_ACP, 0, data, -1, name, name_len, NULL, NULL); + WideCharToMultiByte(CP_ACP, 0, data, -1, name, name_len, NULL, NULL); #else - strcpy(name, data); + strcpy(name, data); #endif - if (type == REG_SZ) { - DEBUG("Found port %s", name); + DEBUG_FMT("Found port %s", name); if (!(*list = list_append(*list, name))) { SET_ERROR(ret, SP_ERR_MEM, "list append failed"); + free(name); goto out; } + free(name); } index++; }