public USBHub GetHub() { if (!this.PortIsHub) { return(null); } USBHub uSBHub = new USBHub(); uSBHub.HubIsRootHub = false; uSBHub.HubDeviceDesc = "External Hub"; IntPtr intPtr = Acer_USB_Library.CreateFile(this.PortHubDevicePath, 1073741824, 2, IntPtr.Zero, 3, 0, IntPtr.Zero); if (intPtr.ToInt32() != -1) { USB_NODE_CONNECTION_NAME uSB_NODE_CONNECTION_NAME = default(USB_NODE_CONNECTION_NAME); uSB_NODE_CONNECTION_NAME.ConnectionIndex = this.PortPortNumber; int num = Marshal.SizeOf(uSB_NODE_CONNECTION_NAME); IntPtr intPtr2 = Marshal.AllocHGlobal(num); Marshal.StructureToPtr(uSB_NODE_CONNECTION_NAME, intPtr2, true); int num2 = default(int); if (Acer_USB_Library.DeviceIoControl(intPtr, 2229268, intPtr2, num, intPtr2, num, out num2, IntPtr.Zero)) { uSB_NODE_CONNECTION_NAME = (USB_NODE_CONNECTION_NAME)Marshal.PtrToStructure(intPtr2, typeof(USB_NODE_CONNECTION_NAME)); uSBHub.HubDevicePath = "\\\\.\\" + uSB_NODE_CONNECTION_NAME.NodeName; } IntPtr intPtr3 = Acer_USB_Library.CreateFile(uSBHub.HubDevicePath, 1073741824, 2, IntPtr.Zero, 3, 0, IntPtr.Zero); if (intPtr3.ToInt32() != -1) { USB_NODE_INFORMATION uSB_NODE_INFORMATION = default(USB_NODE_INFORMATION); uSB_NODE_INFORMATION.NodeType = 0; num = Marshal.SizeOf(uSB_NODE_INFORMATION); IntPtr intPtr4 = Marshal.AllocHGlobal(num); Marshal.StructureToPtr(uSB_NODE_INFORMATION, intPtr4, true); if (Acer_USB_Library.DeviceIoControl(intPtr3, 2229256, intPtr4, num, intPtr4, num, out num2, IntPtr.Zero)) { uSB_NODE_INFORMATION = (USB_NODE_INFORMATION)Marshal.PtrToStructure(intPtr4, typeof(USB_NODE_INFORMATION)); uSBHub.HubIsBusPowered = Convert.ToBoolean(uSB_NODE_INFORMATION.HubInformation.HubIsBusPowered); uSBHub.HubPortCount = uSB_NODE_INFORMATION.HubInformation.HubDescriptor.bNumberOfPorts; } Marshal.FreeHGlobal(intPtr4); Acer_USB_Library.CloseHandle(intPtr3); } USBDevice device = this.GetDevice(); uSBHub.HubInstanceID = device.DeviceInstanceID; uSBHub.HubManufacturer = device.Manufacturer; uSBHub.HubProduct = device.Product; uSBHub.HubSerialNumber = device.SerialNumber; uSBHub.HubDriverKey = device.DriverKey; Marshal.FreeHGlobal(intPtr2); Acer_USB_Library.CloseHandle(intPtr); } return(uSBHub); }
public USBHub GetRootHub() { USBHub uSBHub = new USBHub(); uSBHub.HubIsRootHub = true; uSBHub.HubDeviceDesc = "Root Hub"; IntPtr intPtr = Acer_USB_Library.CreateFile(this.ControllerDevicePath, 1073741824, 2, IntPtr.Zero, 3, 0, IntPtr.Zero); if (intPtr.ToInt32() != -1) { int num = Marshal.SizeOf(default(USB_ROOT_HUB_NAME)); IntPtr intPtr2 = Marshal.AllocHGlobal(num); int num2 = default(int); if (Acer_USB_Library.DeviceIoControl(intPtr, 2229256, intPtr2, num, intPtr2, num, out num2, IntPtr.Zero)) { USB_ROOT_HUB_NAME uSB_ROOT_HUB_NAME = (USB_ROOT_HUB_NAME)Marshal.PtrToStructure(intPtr2, typeof(USB_ROOT_HUB_NAME)); uSBHub.HubDevicePath = "\\\\.\\" + uSB_ROOT_HUB_NAME.RootHubName; } IntPtr intPtr3 = Acer_USB_Library.CreateFile(uSBHub.HubDevicePath, 1073741824, 2, IntPtr.Zero, 3, 0, IntPtr.Zero); if (intPtr3.ToInt32() != -1) { USB_NODE_INFORMATION uSB_NODE_INFORMATION = default(USB_NODE_INFORMATION); uSB_NODE_INFORMATION.NodeType = 0; num = Marshal.SizeOf(uSB_NODE_INFORMATION); IntPtr intPtr4 = Marshal.AllocHGlobal(num); Marshal.StructureToPtr(uSB_NODE_INFORMATION, intPtr4, true); if (Acer_USB_Library.DeviceIoControl(intPtr3, 2229256, intPtr4, num, intPtr4, num, out num2, IntPtr.Zero)) { uSB_NODE_INFORMATION = (USB_NODE_INFORMATION)Marshal.PtrToStructure(intPtr4, typeof(USB_NODE_INFORMATION)); uSBHub.HubIsBusPowered = Convert.ToBoolean(uSB_NODE_INFORMATION.HubInformation.HubIsBusPowered); uSBHub.HubPortCount = uSB_NODE_INFORMATION.HubInformation.HubDescriptor.bNumberOfPorts; } Marshal.FreeHGlobal(intPtr4); Acer_USB_Library.CloseHandle(intPtr3); } Marshal.FreeHGlobal(intPtr2); Acer_USB_Library.CloseHandle(intPtr); } return(uSBHub); }
public ReadOnlyCollection <USBPort> GetPorts() { List <USBPort> list = new List <USBPort>(); IntPtr intPtr = Acer_USB_Library.CreateFile(this.HubDevicePath, 1073741824, 2, IntPtr.Zero, 3, 0, IntPtr.Zero); if (intPtr.ToInt32() != -1) { int num = Marshal.SizeOf(typeof(USB_NODE_CONNECTION_INFORMATION_EX)); IntPtr intPtr2 = Marshal.AllocHGlobal(num); for (int i = 1; i <= this.HubPortCount; i++) { USB_NODE_CONNECTION_INFORMATION_EX uSB_NODE_CONNECTION_INFORMATION_EX = default(USB_NODE_CONNECTION_INFORMATION_EX); uSB_NODE_CONNECTION_INFORMATION_EX.ConnectionIndex = i; Marshal.StructureToPtr(uSB_NODE_CONNECTION_INFORMATION_EX, intPtr2, true); int num2 = default(int); if (Acer_USB_Library.DeviceIoControl(intPtr, 2229320, intPtr2, num, intPtr2, num, out num2, IntPtr.Zero)) { uSB_NODE_CONNECTION_INFORMATION_EX = (USB_NODE_CONNECTION_INFORMATION_EX)Marshal.PtrToStructure(intPtr2, typeof(USB_NODE_CONNECTION_INFORMATION_EX)); USBPort uSBPort = new USBPort(); uSBPort.PortPortNumber = i; uSBPort.PortHubDevicePath = this.HubDevicePath; USB_CONNECTION_STATUS connectionStatus = (USB_CONNECTION_STATUS)uSB_NODE_CONNECTION_INFORMATION_EX.ConnectionStatus; uSBPort.PortStatus = connectionStatus.ToString(); USB_DEVICE_SPEED speed = (USB_DEVICE_SPEED)uSB_NODE_CONNECTION_INFORMATION_EX.Speed; uSBPort.PortSpeed = speed.ToString(); uSBPort.PortIsDeviceConnected = (uSB_NODE_CONNECTION_INFORMATION_EX.ConnectionStatus == 1); uSBPort.PortIsHub = Convert.ToBoolean(uSB_NODE_CONNECTION_INFORMATION_EX.DeviceIsHub); uSBPort.PortDeviceDescriptor = uSB_NODE_CONNECTION_INFORMATION_EX.DeviceDescriptor; list.Add(uSBPort); } } Marshal.FreeHGlobal(intPtr2); Acer_USB_Library.CloseHandle(intPtr); } return(new ReadOnlyCollection <USBPort>(list)); }
public USBDevice GetDevice() { if (!this.PortIsDeviceConnected) { return(null); } USBDevice uSBDevice = new USBDevice(); uSBDevice.DevicePortNumber = this.PortPortNumber; uSBDevice.DeviceHubDevicePath = this.PortHubDevicePath; uSBDevice.DeviceDescriptor = this.PortDeviceDescriptor; uSBDevice.DeviceVID = this.PortDeviceDescriptor.idVendor; uSBDevice.DevicePID = this.PortDeviceDescriptor.idProduct; IntPtr intPtr = Acer_USB_Library.CreateFile(this.PortHubDevicePath, 1073741824, 2, IntPtr.Zero, 3, 0, IntPtr.Zero); if (intPtr.ToInt32() != -1) { int num = 2048; string s = new string('\0', 2048 / Marshal.SystemDefaultCharSize); int num2 = default(int); if (this.PortDeviceDescriptor.iManufacturer > 0) { USB_DESCRIPTOR_REQUEST structure = default(USB_DESCRIPTOR_REQUEST); structure.ConnectionIndex = this.PortPortNumber; structure.SetupPacket.wValue = (short)(768 + this.PortDeviceDescriptor.iManufacturer); structure.SetupPacket.wLength = (short)(num - Marshal.SizeOf(structure)); structure.SetupPacket.wIndex = 1033; IntPtr intPtr2 = Marshal.StringToHGlobalAuto(s); Marshal.StructureToPtr(structure, intPtr2, true); if (Acer_USB_Library.DeviceIoControl(intPtr, 2229264, intPtr2, num, intPtr2, num, out num2, IntPtr.Zero)) { USB_STRING_DESCRIPTOR uSB_STRING_DESCRIPTOR = (USB_STRING_DESCRIPTOR)Marshal.PtrToStructure(new IntPtr(intPtr2.ToInt32() + Marshal.SizeOf(structure)), typeof(USB_STRING_DESCRIPTOR)); uSBDevice.DeviceManufacturer = uSB_STRING_DESCRIPTOR.bString; } Marshal.FreeHGlobal(intPtr2); } if (this.PortDeviceDescriptor.iProduct > 0) { USB_DESCRIPTOR_REQUEST structure2 = default(USB_DESCRIPTOR_REQUEST); structure2.ConnectionIndex = this.PortPortNumber; structure2.SetupPacket.wValue = (short)(768 + this.PortDeviceDescriptor.iProduct); structure2.SetupPacket.wLength = (short)(num - Marshal.SizeOf(structure2)); structure2.SetupPacket.wIndex = 1033; IntPtr intPtr3 = Marshal.StringToHGlobalAuto(s); Marshal.StructureToPtr(structure2, intPtr3, true); if (Acer_USB_Library.DeviceIoControl(intPtr, 2229264, intPtr3, num, intPtr3, num, out num2, IntPtr.Zero)) { USB_STRING_DESCRIPTOR uSB_STRING_DESCRIPTOR2 = (USB_STRING_DESCRIPTOR)Marshal.PtrToStructure(new IntPtr(intPtr3.ToInt32() + Marshal.SizeOf(structure2)), typeof(USB_STRING_DESCRIPTOR)); uSBDevice.DeviceProduct = uSB_STRING_DESCRIPTOR2.bString; } Marshal.FreeHGlobal(intPtr3); } if (this.PortDeviceDescriptor.iSerialNumber > 0) { USB_DESCRIPTOR_REQUEST structure3 = default(USB_DESCRIPTOR_REQUEST); structure3.ConnectionIndex = this.PortPortNumber; structure3.SetupPacket.wValue = (short)(768 + this.PortDeviceDescriptor.iSerialNumber); structure3.SetupPacket.wLength = (short)(num - Marshal.SizeOf(structure3)); structure3.SetupPacket.wIndex = 1033; IntPtr intPtr4 = Marshal.StringToHGlobalAuto(s); Marshal.StructureToPtr(structure3, intPtr4, true); if (Acer_USB_Library.DeviceIoControl(intPtr, 2229264, intPtr4, num, intPtr4, num, out num2, IntPtr.Zero)) { USB_STRING_DESCRIPTOR uSB_STRING_DESCRIPTOR3 = (USB_STRING_DESCRIPTOR)Marshal.PtrToStructure(new IntPtr(intPtr4.ToInt32() + Marshal.SizeOf(structure3)), typeof(USB_STRING_DESCRIPTOR)); uSBDevice.DeviceSerialNumber = uSB_STRING_DESCRIPTOR3.bString; } Marshal.FreeHGlobal(intPtr4); } USB_NODE_CONNECTION_DRIVERKEY_NAME uSB_NODE_CONNECTION_DRIVERKEY_NAME = default(USB_NODE_CONNECTION_DRIVERKEY_NAME); uSB_NODE_CONNECTION_DRIVERKEY_NAME.ConnectionIndex = this.PortPortNumber; num = Marshal.SizeOf(uSB_NODE_CONNECTION_DRIVERKEY_NAME); IntPtr intPtr5 = Marshal.AllocHGlobal(num); Marshal.StructureToPtr(uSB_NODE_CONNECTION_DRIVERKEY_NAME, intPtr5, true); if (Acer_USB_Library.DeviceIoControl(intPtr, 2229280, intPtr5, num, intPtr5, num, out num2, IntPtr.Zero)) { uSB_NODE_CONNECTION_DRIVERKEY_NAME = (USB_NODE_CONNECTION_DRIVERKEY_NAME)Marshal.PtrToStructure(intPtr5, typeof(USB_NODE_CONNECTION_DRIVERKEY_NAME)); uSBDevice.DeviceDriverKey = uSB_NODE_CONNECTION_DRIVERKEY_NAME.DriverKeyName; uSBDevice.DeviceName = Acer_USB_Library.GetDescriptionByKeyName(uSBDevice.DeviceDriverKey); uSBDevice.DeviceInstanceID = Acer_USB_Library.GetInstanceIDByKeyName(uSBDevice.DeviceDriverKey); } Marshal.FreeHGlobal(intPtr5); Acer_USB_Library.CloseHandle(intPtr); } return(uSBDevice); }