public static async Task <IHidDevice> GetWindowsConnectedLedgerHidDeviceAsync() { var devices = new List <DeviceInformation>(); var collection = WindowsHidDevice.GetConnectedDeviceInformations(); foreach (var ids in WellKnownLedgerWallets) { if (ids.ProductId == null) { devices.AddRange(collection.Where(c => c.VendorId == ids.VendorId)); } else { devices.AddRange(collection.Where(c => c.VendorId == ids.VendorId && c.ProductId == ids.ProductId)); } } var deviceFound = devices .FirstOrDefault(d => _usageSpecification == null || _usageSpecification.Length == 0 || _usageSpecification.Any(u => d.UsagePage == u.UsagePage && d.Usage == u.Usage)); var ledgerHidDevice = new WindowsHidDevice(deviceFound); await ledgerHidDevice.InitializeAsync().ConfigureAwait(false); return(ledgerHidDevice); }
private static async Task <IHidDevice> Connect() { DeviceInformation trezorDeviceInformation = null; WindowsHidDevice retVal = null; retVal = new WindowsHidDevice(); Console.Write("Waiting for Trezor ."); while (trezorDeviceInformation == null) { var devices = WindowsHidDevice.GetConnectedDeviceInformations(); var trezors = devices.Where(d => d.VendorId == TrezorManager.TrezorVendorId && TrezorManager.TrezorProductId == 1).ToList(); trezorDeviceInformation = trezors.FirstOrDefault(t => t.Product == TrezorManager.USBOneName); if (trezorDeviceInformation != null) { break; } await Task.Delay(1000); Console.Write("."); } retVal.DeviceInformation = trezorDeviceInformation; await retVal.InitializeAsync(); Console.WriteLine("Connected"); return(retVal); }
public Task <IEnumerable <HIDDeviceInformation> > EnumerateDeviceDescriptions(IEnumerable <VendorProductIds> vendorProductIds, UsageSpecification[] acceptedUsages) { var devices = new List <DeviceInformation>(); var collection = WindowsHidDevice.GetConnectedDeviceInformations(); foreach (var ids in vendorProductIds) { if (ids.ProductId == null) { devices.AddRange(collection.Where(c => c.VendorId == ids.VendorId)); } else { devices.AddRange(collection.Where(c => c.VendorId == ids.VendorId && c.ProductId == ids.ProductId)); } } var retVal = devices .Where(d => acceptedUsages == null || acceptedUsages.Length == 0 || acceptedUsages.Any(u => d.UsagePage == u.UsagePage && d.Usage == u.Usage)).ToList(); return(Task.FromResult <IEnumerable <HIDDeviceInformation> >(retVal.Select(r => new HIDDeviceInformation() { ProductId = r.ProductId, VendorId = r.VendorId, DevicePath = r.DevicePath, ProviderInformation = r }))); }
private async Task GetLedger(ErrorPromptDelegate errorPrompt = null) { var devices = new List <DeviceInformation>(); var collection = WindowsHidDevice.GetConnectedDeviceInformations(); foreach (var ids in WellKnownLedgerWallets) { if (ids.ProductId == null) { devices.AddRange(collection.Where(c => c.VendorId == ids.VendorId)); } else { devices.AddRange(collection.Where(c => c.VendorId == ids.VendorId && c.ProductId == ids.ProductId)); } } var retVal = devices .FirstOrDefault(d => _UsageSpecification == null || _UsageSpecification.Length == 0 || _UsageSpecification.Any(u => d.UsagePage == u.UsagePage && d.Usage == u.Usage)); var ledgerHidDevice = new WindowsHidDevice(retVal); await ledgerHidDevice.InitializeAsync(); _LedgerManager = new LedgerManager(ledgerHidDevice, null, Prompt); }
private async Task <IHidDevice> Connect() { DeviceInformation keepKeyDeviceInformation = null; WindowsHidDevice retVal = null; retVal = new WindowsHidDevice(); Console.Write("Waiting for KeepKey ."); while (keepKeyDeviceInformation == null) { var devices = WindowsHidDevice.GetConnectedDeviceInformations(); var keepKeys = devices.Where(d => d.VendorId == KeepKeyManager.VendorId && d.ProductId == KeepKeyManager.ProductId).ToList(); keepKeyDeviceInformation = keepKeys.FirstOrDefault(); if (keepKeyDeviceInformation != null) { break; } await Task.Delay(1000); Console.Write("."); } retVal.DeviceInformation = keepKeyDeviceInformation; retVal.DataHasExtraByte = false; await retVal.InitializeAsync(); Console.WriteLine("Connected"); return(retVal); }
protected override async Task <IDevice> Connect() { WindowsHidDeviceInformation trezorDeviceInformation = null; WindowsHidDevice retVal = null; retVal = new WindowsHidDevice(); Console.Write("Waiting for Trezor ."); while (trezorDeviceInformation == null) { var devices = WindowsHidDevice.GetConnectedDeviceInformations().Cast <WindowsHidDeviceInformation>(); var trezors = devices.Where(d => d.VendorId == TrezorManager.TrezorVendorId && TrezorManager.TrezorProductId == d.ProductId).ToList(); trezorDeviceInformation = trezors.FirstOrDefault(t => t.UsagePage == TrezorManager.AcceptedUsagePages[0]); if (trezorDeviceInformation != null) { break; } await Task.Delay(1000); Console.Write("."); } retVal.DeviceInformation = trezorDeviceInformation; await retVal.InitializeAsync(); Console.WriteLine("Connected"); return(retVal); }
private async Task <IHidDevice> Connect() { DeviceInformation ledgerDeviceInformation = null; WindowsHidDevice retVal = null; retVal = new WindowsHidDevice(); Console.Write("Waiting for Trezor ."); while (ledgerDeviceInformation == null) { var devices = WindowsHidDevice.GetConnectedDeviceInformations(); ledgerDeviceInformation = devices.FirstOrDefault(d => d.VendorId == 0x2c97); if (ledgerDeviceInformation != null) { break; } await Task.Delay(1000); Console.Write("."); } retVal.DeviceInformation = ledgerDeviceInformation; await retVal.InitializeAsync(); Console.WriteLine("Connected"); return(retVal); }
public void Initialize(IDevice device) { _device = (WindowsHidDevice)device; _device.InitializeAsync().Wait(); //Initialize Base usb_buf[00] = 0x11; usb_buf[01] = 0xFF; usb_buf[02] = 0x04; //Initialize 3E usb_buf[03] = 0x3E; usb_buf[04] = 0x00; _device.WriteAsync(usb_buf).Wait(); Thread.Sleep(20); usb_buf[04] = 0x01; _device.WriteAsync(usb_buf).Wait(); Thread.Sleep(20); usb_buf[04] = 0x02; _device.WriteAsync(usb_buf).Wait(); Thread.Sleep(20); usb_buf[04] = 0x03; _device.WriteAsync(usb_buf).Wait(); Thread.Sleep(20); //Initialize CE usb_buf[03] = 0xCE; usb_buf[04] = 0x02; _device.WriteAsync(usb_buf).Wait(); Thread.Sleep(20); usb_buf[04] = 0x01; _device.WriteAsync(usb_buf).Wait(); Thread.Sleep(20); usb_buf[04] = 0x03; _device.WriteAsync(usb_buf).Wait(); Thread.Sleep(20); usb_buf[04] = 0x00; _device.WriteAsync(usb_buf).Wait(); Thread.Sleep(20); //Initialize Send Lights usb_buf[03] = 0x3E; usb_buf[05] = 0x01; //Mode usb_buf[09] = 0x02; _currentColors[0] = Color.Black; _currentColors[1] = Color.Black; _currentColors[2] = Color.Black; _currentColors[3] = Color.Black; _newColors[0] = Color.Black; _newColors[1] = Color.Black; _newColors[2] = Color.Black; _newColors[3] = Color.Black; _sendTimer = new Timer(new TimerCallback(SendColors), null, 55, 55); }
public static async Task <IHidDevice> GetWindowsConnectedLedgerHidDeviceAsync() { var connectedDevices = WindowsHidDevice.GetConnectedDeviceInformations(); var trezorDevices = connectedDevices.Where(d => d.VendorId == TrezorManager.TrezorVendorId && TrezorManager.TrezorProductId == 1).ToList(); var trezorDeviceInformation = trezorDevices.FirstOrDefault(t => t.Product == TrezorManager.USBOneName); var trezorHidDevice = new WindowsHidDevice(trezorDeviceInformation); await trezorHidDevice.InitializeAsync().ConfigureAwait(false); return(trezorHidDevice); }
public void Initialize(IDevice device) { _device = (WindowsHidDevice)device; _device.InitializeAsync().Wait(); usb_buf[0x00] = 0x11; usb_buf[0x01] = 0x07; usb_buf[0x02] = 0x0B; usb_buf[0x03] = 0x3E; usb_buf[0x04] = 0x00; //Zone usb_buf[0x05] = 0x01; //Mode usb_buf[0x09] = 0x02; }
/// <summary> /// Inits and connect to a usb device /// </summary> /// <returns></returns> public async Task Init() { if(Info.DeviceType == DeviceType.Hid) { HidHandle = new WindowsHidDevice(Info.DeviceId, 131, 131); await HidInitWithRetries(); } else { Handle = new UsbDevice(Info.DeviceId, new WindowsUsbInterfaceManager(Info.DeviceId)); await UsbInitWithRetries(); } }
private static async Task <IHidDevice> Connect() { var devices = WindowsHidDevice.GetConnectedDeviceInformations(); var keepKeyDeviceInformation = devices.FirstOrDefault(d => d.VendorId == KeepKeyManager.VendorId && d.ProductId == KeepKeyManager.ProductId); if (keepKeyDeviceInformation == null) { throw new Exception("No KeepKey is not connected or USB access was not granted to this application."); } var keepKeyHidDevice = new WindowsHidDevice(keepKeyDeviceInformation); keepKeyHidDevice.DataHasExtraByte = false; await keepKeyHidDevice.InitializeAsync(); return(keepKeyHidDevice); }
private static async Task <WindowsHidDevice> InitializeWindowsHidDevice(bool isReadonly) { const string deviceId = "test"; var hidService = Substitute.For <IHidApiService>(); var invalidSafeFileHandle = new SafeFileHandle((IntPtr)(-1), true); var validSafeFileHandle = new SafeFileHandle((IntPtr)100, true); hidService.CreateReadConnection("", Windows.FileAccessRights.None).ReturnsForAnyArgs(validSafeFileHandle); hidService.CreateWriteConnection("").ReturnsForAnyArgs(!isReadonly ? validSafeFileHandle : invalidSafeFileHandle); hidService.GetDeviceDefinition(deviceId, validSafeFileHandle).ReturnsForAnyArgs(new ConnectedDeviceDefinition(deviceId) { ReadBufferSize = 64, WriteBufferSize = 64 }); var readStream = Substitute.For <Stream>(); readStream.CanRead.ReturnsForAnyArgs(true); hidService.OpenRead(null, 0).ReturnsForAnyArgs(readStream); var writeStream = Substitute.For <Stream>(); writeStream.CanWrite.ReturnsForAnyArgs(true); hidService.OpenWrite(null, 0).ReturnsForAnyArgs(writeStream); var logger = Substitute.For <ILogger>(); var windowsHidDevice = new WindowsHidDevice(deviceId, null, null, logger, Substitute.For <ITracer>(), hidService); await windowsHidDevice.InitializeAsync(); if (!isReadonly) { logger.Received().Log(Messages.SuccessMessageReadFileStreamOpened, nameof(WindowsHidDevice), null, LogLevel.Information); } else { logger.Received().Log(Messages.WarningMessageOpeningInReadonlyMode(deviceId), nameof(WindowsHidDevice), null, LogLevel.Warning); } Assert.AreEqual(true, windowsHidDevice.IsInitialized); return(windowsHidDevice); }