Пример #1
0
            // Return Root Hub for this Controller
            public USBHub GetRootHub()
            {
                var Root = new USBHub {
                    HubIsRootHub = true, HubDeviceDesc = "Root Hub"
                };

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

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

                int nBytesReturned;
                var HubName    = new USB_ROOT_HUB_NAME();
                var nBytes     = Marshal.SizeOf(HubName);
                var ptrHubName = Marshal.AllocHGlobal(nBytes);

                // get the Hub Name
                if (DeviceIoControl(h, IOCTL_USB_GET_ROOT_HUB_NAME, ptrHubName, nBytes, ptrHubName, nBytes, out nBytesReturned, IntPtr.Zero))
                {
                    HubName            = (USB_ROOT_HUB_NAME)Marshal.PtrToStructure(ptrHubName, typeof(USB_ROOT_HUB_NAME));
                    Root.HubDevicePath = @"\\.\" + HubName.RootHubName;
                }

                // TODO: Get DriverKeyName for Root Hub

                // Now let's open the Hub (based upon the HubName we got above)
                var h2 = CreateFile(Root.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));
                        Root.HubIsBusPowered = Convert.ToBoolean(NodeInfo.HubInformation.HubIsBusPowered);
                        Root.HubPortCount    = NodeInfo.HubInformation.HubDescriptor.bNumberOfPorts;
                    }
                    Marshal.FreeHGlobal(ptrNodeInfo);
                    CloseHandle(h2);
                }

                Marshal.FreeHGlobal(ptrHubName);
                CloseHandle(h);
                return(Root);
            }
        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);
        }
Пример #3
0
 internal static string DevicePath(this USB_ROOT_HUB_NAME rootHubName)
 {
     return(@"\\.\" + rootHubName.RootHubName);
 }
Пример #4
0
            // Return Root Hub for this Controller
            public USBHub GetRootHub()
            {
                IntPtr h, h2;
                USBHub Root = new USBHub();
                Root.HubIsRootHub = true;
                Root.HubDeviceDesc = "Root Hub";

                // Open a handle to the Host Controller
                h = CreateFile(ControllerDevicePath, GENERIC_WRITE, FILE_SHARE_WRITE, IntPtr.Zero, OPEN_EXISTING, 0, IntPtr.Zero);
                if (h.ToInt32() != INVALID_HANDLE_VALUE)
                {
                    int nBytesReturned;
                    USB_ROOT_HUB_NAME HubName = new USB_ROOT_HUB_NAME();
                    int nBytes = Marshal.SizeOf(HubName);
                    IntPtr ptrHubName = Marshal.AllocHGlobal(nBytes);

                    // get the Hub Name
                    if (DeviceIoControl(h, IOCTL_USB_GET_ROOT_HUB_NAME, ptrHubName, nBytes, ptrHubName, nBytes, out nBytesReturned, IntPtr.Zero))
                    {
                        HubName = (USB_ROOT_HUB_NAME)Marshal.PtrToStructure(ptrHubName, typeof(USB_ROOT_HUB_NAME));
                        Root.HubDevicePath = @"\\.\" + HubName.RootHubName;
                    }

                    // TODO: Get DriverKeyName for Root Hub

                    // Now let's open the Hub (based upon the HubName we got above)
                    h2 = CreateFile(Root.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));
                            Root.HubIsBusPowered = Convert.ToBoolean(NodeInfo.HubInformation.HubIsBusPowered);
                            Root.HubPortCount = NodeInfo.HubInformation.HubDescriptor.bNumberOfPorts;
                        }
                        Marshal.FreeHGlobal(ptrNodeInfo);
                        CloseHandle(h2);
                    }

                    Marshal.FreeHGlobal(ptrHubName);
                    CloseHandle(h);
                }
                return Root;
            }