Esempio n. 1
0
        static void initFilterFromDevice(ref USBFILTER aFilter, DeviceNode aDevice)
        {
            int mVid, mPid, mRev, mMi;

            WindowsUsbDeviceRegistry.DecodeDeviceIDs(aDevice, out mVid, out mPid, out mRev, out mMi);
            if (mVid != -1)
            {
                aFilter.SetNumExact(USBFILTERIDX.USBFILTERIDX_VENDOR_ID, (ushort)mVid, true);
            }
            if (mPid != -1)
            {
                aFilter.SetNumExact(USBFILTERIDX.USBFILTERIDX_PRODUCT_ID, (ushort)mPid, true);
            }
            if (mRev != -1)
            {
                int mRevBCD = (((mRev % 10) / 1) << 0) | (((mRev % 100) / 10) << 4) | (((mRev % 1000) / 100) << 8) | (((mRev % 10000) / 1000) << 12);
                aFilter.SetNumExact(USBFILTERIDX.USBFILTERIDX_DEVICE_REV, (ushort)mRevBCD, true);
            }
            //aFilter.SetNumExact(USBFILTERIDX.USBFILTERIDX_DEVICE_CLASS, 0xff, true);
            //aFilter.SetNumExact(USBFILTERIDX.USBFILTERIDX_DEVICE_SUB_CLASS, 0x00, true);
            //aFilter.SetNumExact(USBFILTERIDX.USBFILTERIDX_DEVICE_PROTOCOL, 0x00, true);
            //aFilter.SetNumExact(USBFILTERIDX.USBFILTERIDX_PORT, 0, true);
            //aFilter.SetNumExact(USBFILTERIDX.USBFILTERIDX_BUS, 0, true);
            //if (pDev->pszSerialNumber) aFilter.SetStringExact(USBFILTERIDX.USBFILTERIDX_SERIAL_NUMBER_STR, pDev->pszSerialNumber, true);
            //if (pDev->pszProduct) aFilter.SetStringExact(USBFILTERIDX.USBFILTERIDX_PRODUCT_STR, pDev->pszProduct, true);
            //if (pDev->pszManufacturer) aFilter.SetStringExact(USBFILTERIDX.USBFILTERIDX_MANUFACTURER_STR, pDev->pszManufacturer, true);
        }
Esempio n. 2
0
        static unsafe IntPtr USBLibAddFilter(ref USBFILTER filter)
        {
            USBSUP_FLTADDOUT FltAddRc;

            fixed(USBFILTER *pFilter = &filter) SyncIoControl(hMonitor, SUPUSBFLT_IOCTL_ADD_FILTER, pFilter, sizeof(USBFILTER), &FltAddRc, sizeof(USBSUP_FLTADDOUT));

            if (FltAddRc.rc != 0)
            {
                throw new Exception(String.Format("rc={0}", FltAddRc.rc));
            }
            return(FltAddRc.uId);
        }
Esempio n. 3
0
        public unsafe static void Release(DeviceNode aDevice)
        {
            InitMonitor();
            USBFILTER Filter = new USBFILTER(USBFILTERTYPE.USBFILTERTYPE_ONESHOT_IGNORE);

            initFilterFromDevice(ref Filter, aDevice);
            IntPtr pvId = USBLibAddFilter(ref Filter);

            if (pvId == IntPtr.Zero)
            {
                throw new Exception("Add one-shot Filter failed");
            }
            USBLibRunFilters();
            //aDevice.Reenumerate(0);
        }