Ejemplo n.º 1
0
        internal UsbDevice(WDU_DEVICE_HANDLE hDev, ref WDU_DEVICE pDeviceInfo)
        {
            WDU_CONFIGURATION pConfig = (WDU_CONFIGURATION)Marshal.PtrToStructure(pDeviceInfo.pActiveConfig,
                                                                                  typeof(WDU_CONFIGURATION));

            dwNumOfInterfaces = pConfig.dwNumInterfaces;
            interfacesInfo    = new INTERFACE_INFO[dwNumOfInterfaces];
            hDevice           = hDev;

            for (uint i = 0; i < dwNumOfInterfaces; ++i)
            {
                interfacesInfo[i].wduInterface = (WDU_INTERFACE)Marshal.PtrToStructure(
                    pDeviceInfo.pActiveInterface(i), typeof(WDU_INTERFACE));
                WDU_ALTERNATE_SETTING pAltSetting = (WDU_ALTERNATE_SETTING)Marshal.PtrToStructure(
                    interfacesInfo[i].wduInterface.pActiveAltSetting, typeof(WDU_ALTERNATE_SETTING));

                if (i == 0)
                {
                    dwInterfaceNum  = pAltSetting.Descriptor.bInterfaceNumber;
                    dwAltSettingNum = pAltSetting.Descriptor.bAlternateSetting;
                    pPipesList      = new PipeList(pDeviceInfo.Pipe0, pAltSetting, hDevice);
                }

                interfacesInfo[i].bInterfaceNumber = pAltSetting.Descriptor.bInterfaceNumber;

                dwNumOfAltSettingsTotal += interfacesInfo[i].wduInterface.dwNumAltSettings;
            }

            DWORD dwStatus = wdu_lib_decl.WDU_GetDeviceAddr(hDevice,
                                                            ref dwAddr);

            wVid = (WORD)pDeviceInfo.Descriptor.idVendor;
            wPid = (WORD)pDeviceInfo.Descriptor.idProduct;
        }
Ejemplo n.º 2
0
        internal PipeList(WDU_PIPE_INFO pPipe0, WDU_ALTERNATE_SETTING
                          pActiveAltSetting, WDU_DEVICE_HANDLE hDev)
        {
            WDU_PIPE_INFO pipe_info;
            DWORD         dwPipeIndex  = 0;
            DWORD         dwNumOfPipes = pActiveAltSetting.Descriptor.bNumEndpoints;
            DWORD         dwPipeSize   = (DWORD)Marshal.SizeOf(typeof(WDU_PIPE_INFO));

            //inserting the control pipe to the list
            this.Insert(0, new UsbPipe(pPipe0, hDev));

            //retrieving the rest of the pipes from the active alternating
            //settings struct and inserting them into the pipes' list
            for (dwPipeIndex = 0; dwPipeIndex < dwNumOfPipes; ++dwPipeIndex)
            {
                pipe_info = (WDU_PIPE_INFO)Convert.ChangeType
                                (Marshal.PtrToStructure(new
                                                        IntPtr(pActiveAltSetting.pPipes.ToInt64()
                                                               + dwPipeIndex * dwPipeSize), typeof(WDU_PIPE_INFO)),
                                typeof(WDU_PIPE_INFO));
                UsbPipe pipe = new UsbPipe(pipe_info, hDev);

                this.Insert((int)dwPipeIndex + 1, pipe);
            }
        }
Ejemplo n.º 3
0
        public DWORD ChangeAlternateSetting(DWORD newInterface, DWORD newSetting)
        {
            DWORD dwStatus = (DWORD)WD_ERROR_CODES.WD_STATUS_SUCCESS;

            // if the chosen setting is the same as it was - do nothing
            if (newInterface == this.dwInterfaceNum && newSetting == this.dwAltSettingNum)
            {
                return(dwStatus);
            }

            dwStatus = wdu_lib_decl.WDU_SetInterface(hDevice, newInterface,
                                                     newSetting);
            if (dwStatus != (DWORD)WD_ERROR_CODES.WD_STATUS_SUCCESS)
            {
                return(dwStatus);
            }

            IntPtr ppDeviceInfo = (System.IntPtr) 0;

            dwStatus = (DWORD)wdu_lib_decl.WDU_GetDeviceInfo(hDevice,
                                                             ref ppDeviceInfo);
            if (dwStatus != (DWORD)WD_ERROR_CODES.WD_STATUS_SUCCESS)
            {
                return(dwStatus);
            }

            WDU_DEVICE pDeviceInfo = (WDU_DEVICE)Marshal.PtrToStructure(ppDeviceInfo,
                                                                        typeof(WDU_DEVICE));

            int index = GetInterfaceIndexByNumber(newInterface);

            interfacesInfo[index].wduInterface = (WDU_INTERFACE)Marshal.PtrToStructure(
                pDeviceInfo.pActiveInterface((uint)index), typeof(WDU_INTERFACE));

            WDU_ALTERNATE_SETTING pActiveAltSetting =
                (WDU_ALTERNATE_SETTING)Marshal.PtrToStructure(interfacesInfo[index].
                                                              wduInterface.pActiveAltSetting, typeof(WDU_ALTERNATE_SETTING));

            dwInterfaceNum  = newInterface;
            dwAltSettingNum = newSetting;
            pPipesList      = new PipeList(((UsbPipe)(pPipesList[0])).GetPipeInfo(),
                                           pActiveAltSetting, hDevice);
            wdu_lib_decl.WDU_PutDeviceInfo(ppDeviceInfo);

            return(dwStatus);
        }