private async Task SendRequestAsync(FidoHidMsgType msgType, byte[] data = null) { if (data == null) { data = new byte[0]; } var size = data.Length; var payloadData = data.Take(HidReportSize - 7).ToArray(); var payloadBuilder = new ByteArrayBuilder(); payloadBuilder.Append(_channelId); payloadBuilder.Append((byte)msgType); payloadBuilder.Append((byte)(size >> 8 & 0xff)); payloadBuilder.Append((byte)(size & 0xff)); payloadBuilder.Append(payloadData); payloadBuilder.AppendZerosTill(HidReportSize); var report = _hidDevice.CreateReport(); report.Data = payloadBuilder.GetBytes(); if (!await _hidDevice.WriteReportAsync(report, HidTimeoutMs).ConfigureAwait(false)) { throw new FidoException(FidoError.InterruptedIO, "Error writing to token"); } var remainingData = data.Skip(HidReportSize - 7).ToArray(); var seq = 0; while (remainingData.Length > 0) { payloadData = remainingData.Take(HidReportSize - 5).ToArray(); payloadBuilder.Clear(); payloadBuilder.Append(_channelId); payloadBuilder.Append((byte)(0x7f & seq)); payloadBuilder.Append(payloadData); payloadBuilder.AppendZerosTill(HidReportSize); report = _hidDevice.CreateReport(); report.Data = payloadBuilder.GetBytes(); if (!await _hidDevice.WriteReportAsync(report, HidTimeoutMs).ConfigureAwait(false)) { throw new FidoException(FidoError.InterruptedIO, "Error writing to token"); } remainingData = remainingData.Skip(HidReportSize - 5).ToArray(); seq++; } }