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);
        }
Esempio n. 2
0
            // return a down stream external hub
            public USBHub GetHub()
            {
                if (!PortIsHub)
                {
                    return null;
                }
                USBHub Hub = new USBHub();
                IntPtr h, h2;
                Hub.HubIsRootHub = false;
                Hub.HubDeviceDesc = "External Hub";

                // Open a handle to the Host Controller
                h = CreateFile(PortHubDevicePath, GENERIC_WRITE, FILE_SHARE_WRITE, IntPtr.Zero, OPEN_EXISTING, 0, IntPtr.Zero);
                if (h.ToInt32() != INVALID_HANDLE_VALUE)
                {
                    // Get the DevicePath for downstream hub
                    int nBytesReturned;
                    USB_NODE_CONNECTION_NAME NodeName = new USB_NODE_CONNECTION_NAME();
                    NodeName.ConnectionIndex = PortPortNumber;
                    int nBytes = Marshal.SizeOf(NodeName);
                    IntPtr ptrNodeName = Marshal.AllocHGlobal(nBytes);
                    Marshal.StructureToPtr(NodeName, ptrNodeName, true);

                    // Use an IOCTL call to request the Node Name
                    if (DeviceIoControl(h, IOCTL_USB_GET_NODE_CONNECTION_NAME, ptrNodeName, nBytes, ptrNodeName, nBytes, out nBytesReturned, IntPtr.Zero))
                    {
                        NodeName = (USB_NODE_CONNECTION_NAME)Marshal.PtrToStructure(ptrNodeName, typeof(USB_NODE_CONNECTION_NAME));
                        Hub.HubDevicePath = @"\\.\" + NodeName.NodeName;
                    }

                    // Now let's open the Hub (based upon the HubName we got above)
                    h2 = CreateFile(Hub.HubDevicePath, GENERIC_WRITE, FILE_SHARE_WRITE, IntPtr.Zero, OPEN_EXISTING, 0, IntPtr.Zero);
                    if (h2.ToInt32() != INVALID_HANDLE_VALUE)
                    {
                        USB_NODE_INFORMATION NodeInfo = new USB_NODE_INFORMATION();
                        NodeInfo.NodeType = (int)USB_HUB_NODE.UsbHub;
                        nBytes = Marshal.SizeOf(NodeInfo);
                        IntPtr ptrNodeInfo = Marshal.AllocHGlobal(nBytes);
                        Marshal.StructureToPtr(NodeInfo, ptrNodeInfo, true);

                        // get the Hub Information
                        if (DeviceIoControl(h2, IOCTL_USB_GET_NODE_INFORMATION, ptrNodeInfo, nBytes, ptrNodeInfo, nBytes, out nBytesReturned, IntPtr.Zero))
                        {
                            NodeInfo = (USB_NODE_INFORMATION)Marshal.PtrToStructure(ptrNodeInfo, typeof(USB_NODE_INFORMATION));
                            Hub.HubIsBusPowered = Convert.ToBoolean(NodeInfo.HubInformation.HubIsBusPowered);
                            Hub.HubPortCount = NodeInfo.HubInformation.HubDescriptor.bNumberOfPorts;
                        }
                        Marshal.FreeHGlobal(ptrNodeInfo);
                        CloseHandle(h2);
                    }

                    // Fill in the missing Manufacture, Product, and SerialNumber values
                    // values by just creating a Device instance and copying the values
                    USBDevice Device = GetDevice();
                    Hub.HubInstanceID = Device.DeviceInstanceID;
                    Hub.HubManufacturer = Device.Manufacturer;
                    Hub.HubProduct = Device.Product;
                    Hub.HubSerialNumber = Device.SerialNumber;
                    Hub.HubDriverKey = Device.DriverKey;

                    Marshal.FreeHGlobal(ptrNodeName);
                    CloseHandle(h);
                }
                return Hub;
            }
Esempio n. 3
0
            // return a down stream external hub
            public USBHub GetHub()
            {
                if (!PortIsHub)
                {
                    return(null);
                }

                var Hub = new USBHub {
                    HubIsRootHub = false, HubDeviceDesc = "External Hub"
                };

                // Open a handle to the Host Controller
                var h = CreateFile(PortHubDevicePath, GENERIC_WRITE, FILE_SHARE_WRITE, IntPtr.Zero, OPEN_EXISTING, 0, IntPtr.Zero);

                if (h.ToInt32() == INVALID_HANDLE_VALUE)
                {
                    return(Hub);
                }

                // Get the DevicePath for downstream hub
                int nBytesReturned;
                var NodeName = new USB_NODE_CONNECTION_NAME {
                    ConnectionIndex = PortPortNumber
                };
                var nBytes      = Marshal.SizeOf(NodeName);
                var ptrNodeName = Marshal.AllocHGlobal(nBytes);

                Marshal.StructureToPtr(NodeName, ptrNodeName, true);

                // Use an IOCTL call to request the Node Name
                if (DeviceIoControl(h, IOCTL_USB_GET_NODE_CONNECTION_NAME, ptrNodeName, nBytes, ptrNodeName, nBytes, out nBytesReturned, IntPtr.Zero))
                {
                    NodeName          = (USB_NODE_CONNECTION_NAME)Marshal.PtrToStructure(ptrNodeName, typeof(USB_NODE_CONNECTION_NAME));
                    Hub.HubDevicePath = @"\\.\" + NodeName.NodeName;
                }

                // Now let's open the Hub (based upon the HubName we got above)
                var h2 = CreateFile(Hub.HubDevicePath, GENERIC_WRITE, FILE_SHARE_WRITE, IntPtr.Zero, OPEN_EXISTING, 0, IntPtr.Zero);

                if (h2.ToInt32() != INVALID_HANDLE_VALUE)
                {
                    var NodeInfo = new USB_NODE_INFORMATION {
                        NodeType = (int)USB_HUB_NODE.UsbHub
                    };
                    nBytes = Marshal.SizeOf(NodeInfo);
                    var ptrNodeInfo = Marshal.AllocHGlobal(nBytes);
                    Marshal.StructureToPtr(NodeInfo, ptrNodeInfo, true);

                    // get the Hub Information
                    if (DeviceIoControl(h2, IOCTL_USB_GET_NODE_INFORMATION, ptrNodeInfo, nBytes, ptrNodeInfo, nBytes, out nBytesReturned, IntPtr.Zero))
                    {
                        NodeInfo            = (USB_NODE_INFORMATION)Marshal.PtrToStructure(ptrNodeInfo, typeof(USB_NODE_INFORMATION));
                        Hub.HubIsBusPowered = Convert.ToBoolean(NodeInfo.HubInformation.HubIsBusPowered);
                        Hub.HubPortCount    = NodeInfo.HubInformation.HubDescriptor.bNumberOfPorts;
                    }
                    Marshal.FreeHGlobal(ptrNodeInfo);
                    CloseHandle(h2);
                }

                // Fill in the missing Manufacture, Product, and SerialNumber values
                // values by just creating a Device instance and copying the values
                var Device = GetDevice();

                Hub.HubInstanceID   = Device.DeviceInstanceID;
                Hub.HubManufacturer = Device.Manufacturer;
                Hub.HubProduct      = Device.Product;
                Hub.HubSerialNumber = Device.SerialNumber;
                Hub.HubDriverKey    = Device.DriverKey;

                Marshal.FreeHGlobal(ptrNodeName);
                CloseHandle(h);
                return(Hub);
            }