static unsafe void Test(Win32HidDevice device) { var init = new InitializationPacket(); init.CommandIdentifier = (byte)U2FHidCommand.Init; init.ChannelIdentifier = U2FHID_BROADCAST_CID; init.PayloadLength = 8; var caps = device.Information.Capabilities; var buffer = new byte[caps.InputReportByteLength]; fixed(byte *pBuffer = buffer) { Marshal.StructureToPtr(init, new IntPtr(pBuffer + 1), false); buffer[0] = 0x00; buffer[8] = 0xCA; buffer[9] = 0xFE; buffer[10] = 0xBA; buffer[11] = 0xBE; buffer[12] = 0xDE; buffer[13] = 0xAD; buffer[14] = 0xBA; buffer[15] = 0xBE; WriteBuffer(buffer); var task = Kernel32Dll.WriteFileAsync(device.Handle, new IntPtr(pBuffer), buffer.Length); var writen = task.Result; Console.WriteLine("Writen {0} bytes", writen); } var bufferOut = new byte[caps.OutputReportByteLength]; fixed(byte *pBuffer = bufferOut) { var intPtr = new IntPtr(pBuffer); var task = Kernel32Dll.ReadFileAsync(device.Handle, intPtr, bufferOut.Length); var read = task.Result; Console.WriteLine("Read {0} bytes", read); } WriteBuffer(bufferOut); Wink(device, bufferOut[16], bufferOut[17], bufferOut[18], bufferOut[19]); }
public async Task <HidInputReport> GetInputReportAsync( CancellationToken cancellationToken = default(CancellationToken)) { try { var bytes = await Kernel32Dll.ReadFileAsync <byte>(Handle, Information.Capabilities.InputReportByteLength, cancellationToken); log.Trace(bytes.ToLoggableAsHex("Received input report:")); return(new HidInputReport(bytes)); } catch (Win32Exception exception) { log.Error("Receiving input report failed", exception); throw ExceptionConversion.ConvertException(exception); } catch (Exception exception) { log.Error("Receiving input report failed", exception); throw; } }
static unsafe void Wink(Win32HidDevice device, byte b1, byte b2, byte b3, byte b4) { var msg = new FidoU2FHidMessage( (uint)(unchecked (b1 << 24 | b2 << 16 | b3 << 8 | b4)), U2FHidCommand.Wink); device.WriteFidoU2FHidMessageAsync(msg, CancellationToken.None).Wait(); var caps = device.Information.Capabilities; var bufferOut = new byte[caps.OutputReportByteLength]; fixed(byte *pBuffer = bufferOut) { var intPtr = new IntPtr(pBuffer); var task = Kernel32Dll.ReadFileAsync(device.Handle, intPtr, bufferOut.Length); var read = task.Result; Console.WriteLine("Read {0} bytes", read); } WriteBuffer(bufferOut); }