Example #1
0
        internal ErrorCode GetCustomDeviceKeyValue(SafeFileHandle usbHandle, string key, out byte[] propData, int maxDataLength)
        {
            ErrorCode eReturn = ErrorCode.None;
            int       iReturnBytes;

            propData = null;
            byte[]   bytesReq   = LibUsbDeviceRegistryKeyRequest.RegGetRequest(key, maxDataLength);
            GCHandle gcbytesReq = GCHandle.Alloc(bytesReq, GCHandleType.Pinned);

            bool bSuccess = LibUsbDriverIO.UsbIOSync(usbHandle,
                                                     LibUsbIoCtl.GET_CUSTOM_REG_PROPERTY,
                                                     bytesReq,
                                                     bytesReq.Length,
                                                     gcbytesReq.AddrOfPinnedObject(),
                                                     bytesReq.Length,
                                                     out iReturnBytes);

            gcbytesReq.Free();
            if (bSuccess)
            {
                propData = new byte[iReturnBytes];
                Array.Copy(bytesReq, propData, iReturnBytes);
            }
            else
            {
                eReturn = ErrorCode.GetDeviceKeyValueFailed;
                // dont log this as an error;
                //UsbError.Error(eReturn,0, "Failed getting device registry Key:" + key, this);
            }
            return(eReturn);
        }
Example #2
0
        private bool GetObjectName(SafeFileHandle usbHandle, int objectNameIndex, out string objectName)
        {
            int objNameLength;

            Byte[]   regKeyPathname   = new byte[512];
            GCHandle gcRegKeyPathname = GCHandle.Alloc(regKeyPathname, GCHandleType.Pinned);

#if RESERVED_FOR_FUTURE_USE
            LibUsbRequest req = new LibUsbRequest();
            req.ObjectName.Index = objectNameIndex;
            Marshal.Copy(req.Bytes, 0, gcRegKeyPathname.AddrOfPinnedObject(), LibUsbRequest.Size);
#endif

            bool bSuccess = LibUsbDriverIO.UsbIOSync(usbHandle,
                                                     LibUsbIoCtl.GET_OBJECT_NAME,
                                                     regKeyPathname,
                                                     regKeyPathname.Length,
                                                     gcRegKeyPathname.AddrOfPinnedObject(),
                                                     regKeyPathname.Length,
                                                     out objNameLength);

            gcRegKeyPathname.Free();

            if (bSuccess && objNameLength > 1)
            {
                objectName = Encoding.ASCII.GetString(regKeyPathname, 0, objNameLength - 1);
            }
            else
            {
                objectName = String.Empty;
            }

            return(bSuccess);
        }
Example #3
0
        private void GetPropertiesSPDRP(SafeHandle usbHandle)
        {
            byte[]   propBuffer   = new byte[1024];
            GCHandle gcPropBuffer = GCHandle.Alloc(propBuffer, GCHandleType.Pinned);

            LibUsbRequest            req      = new LibUsbRequest();
            Dictionary <string, int> allProps = Helper.GetEnumData(typeof(DevicePropertyType));

            foreach (KeyValuePair <string, int> prop in allProps)
            {
                object oValue = String.Empty;

                req.DeviceProperty.ID = prop.Value;
                int  iReturnBytes;
                bool bSuccess = LibUsbDriverIO.UsbIOSync(usbHandle,
                                                         LibUsbIoCtl.GET_REG_PROPERTY,
                                                         req,
                                                         LibUsbRequest.Size,
                                                         gcPropBuffer.AddrOfPinnedObject(),
                                                         propBuffer.Length,
                                                         out iReturnBytes);
                if (bSuccess)
                {
                    switch ((DevicePropertyType)prop.Value)
                    {
                    case DevicePropertyType.PhysicalDeviceObjectName:
                    case DevicePropertyType.LocationInformation:
                    case DevicePropertyType.Class:
                    case DevicePropertyType.Mfg:
                    case DevicePropertyType.DeviceDesc:
                    case DevicePropertyType.Driver:
                    case DevicePropertyType.EnumeratorName:
                    case DevicePropertyType.FriendlyName:
                    case DevicePropertyType.ClassGuid:
                        oValue = GetAsString(propBuffer, iReturnBytes);
                        break;

                    case DevicePropertyType.HardwareId:
                    case DevicePropertyType.CompatibleIds:
                        oValue = GetAsStringArray(propBuffer, iReturnBytes);
                        break;

                    case DevicePropertyType.BusNumber:
                    case DevicePropertyType.InstallState:
                    case DevicePropertyType.LegacyBusType:
                    case DevicePropertyType.RemovalPolicy:
                    case DevicePropertyType.UiNumber:
                    case DevicePropertyType.Address:
                        oValue = GetAsStringInt32(propBuffer, iReturnBytes);
                        break;

                    case DevicePropertyType.BusTypeGuid:
                        oValue = GetAsGuid(propBuffer, iReturnBytes);
                        break;
                    }
                }
                else
                {
                    oValue = String.Empty;
                }

                mDeviceProperties.Add(prop.Key, oValue);
            }
            gcPropBuffer.Free();
        }
Example #4
0
 internal bool UsbIoSync(int controlCode, Object inBuffer, int inSize, IntPtr outBuffer, int outSize, out int ret)
 {
     return(LibUsbDriverIO.UsbIOSync(mUsbHandle, controlCode, inBuffer, inSize, outBuffer, outSize, out ret));
 }