Exemple #1
0
        public static async Task <CTAPHID> OpenAsync(IHidDevice hidDevice)
        {
            var device = new CTAPHID(hidDevice);
            await device.InitAsync();

            return(device);
        }
Exemple #2
0
        public static async Task <SendCommandandResponseResult> SendCommandandResponse(List <HidParam> hidParams, byte[] send, int timeoutms)
        {
            var        result    = new SendCommandandResponseResult();
            IHidDevice hidDevice = null;

            try {
                hidDevice = CTAPHID.find(hidParams);
                if (hidDevice == null)
                {
                    return(null);
                }
                using (var openedDevice = await CTAPHID.OpenAsync(hidDevice)) {
                    openedDevice.ReceiveResponseTotalTimeoutMs = timeoutms;
                    result.responseData = await openedDevice.CborAsync(send);

                    result.isTimeout = openedDevice.isReceiveResponseTotalTimeout;
                }
            } catch (Exception) {
            } finally {
                if (hidDevice != null)
                {
                    hidDevice.Dispose();
                }
            }
            return(result);
        }
Exemple #3
0
        protected static async Task <CTAPResponseInner> sendCommandandResponse(DevParam devParam, byte[] send, int timeoutms)
        {
            var response = new CTAPResponseInner();

            byte[] byteresponse = null;

            // HID
            if (devParam.hidparams != null)
            {
                var res = await CTAPHID.SendCommandandResponse(devParam.hidparams, send, timeoutms);

                if (res != null)
                {
                    if (res.isTimeout == true)
                    {
                        response.Status = -2;
                        return(response);
                    }
                    response.DevType = 1;
                    byteresponse     = res.responseData;
                }
            }

            // NFC
            if (byteresponse == null && devParam.nfcparams != null)
            {
                byteresponse = CTAPNFC.SendCommandandResponse(devParam.nfcparams, send);
                if (byteresponse != null)
                {
                    response.DevType = 2;
                }
            }

            if (byteresponse == null)
            {
                response.Status = -1;
                return(response);
            }
            response.StatusCodeCTAP = byteresponse[0];

            if (byteresponse.Length > 1)
            {
                try {
                    var cobrbyte = byteresponse.Skip(1).ToArray();
                    response.ResponseDataCbor = CBORObject.DecodeFromBytes(cobrbyte, CBOREncodeOptions.Default);

                    var json = response.ResponseDataCbor.ToJSONString();
                    System.Diagnostics.Debug.WriteLine($"Recv: {json}");
                } catch (Exception ex) {
                    System.Diagnostics.Debug.WriteLine($"CBOR DecordError:{ex.Message}");
                }
            }

            return(response);
        }