public ApduResponse SendCommand(ApduCommand apduCommand) { CardQ.EnqueueToInput(new CardRequest(apduCommand, CardinterfaceServiceRequestEnum.ADPU)); CardResponse response = CardQ.DequeueFromOutput(false); //this will poll indefinetely return(response.ApduResponse); }
private async Task <ApduResponse> Transceive(ApduCommand apduCommand) { ApduResponse apduRes = Activator.CreateInstance(apduCommand.ApduResponseType) as ApduResponse; byte[] dataIn = apduCommand.Serialize(); bool debugOut = true; if (debugOut) { StringBuilder sb = new StringBuilder(); sb.AppendLine("********************************************************************************************************"); sb.AppendLine(apduCommand.ToString()); sb.Append("Raw Data Sent:" + Formatting.ByteArrayToHexString(dataIn)); Logger.Log(sb.ToString()); } byte[] dataOut = await CardInterfaceManger.TransmitAsync(dataIn); if (debugOut) { StringBuilder sb = new StringBuilder(); sb.AppendLine("Raw Data Received:" + Formatting.ByteArrayToHexString(dataOut)); sb.AppendLine("********************************************************************************************************"); Logger.Log(sb.ToString()); } apduRes.Deserialize(dataOut); if (apduRes.SW1 == 0x61) { GetResponseRequest getResponseRequest = new GetResponseRequest(apduRes.SW2); ApduResponse getResponseResponse = await Transceive(getResponseRequest); if (getResponseResponse.Succeeded || (getResponseResponse.SW1 == 0x62 && getResponseResponse.SW2 == 0x83)) { apduRes.ResponseData = Formatting.ConcatArrays(apduRes.ResponseData, getResponseResponse.ResponseData, new byte[] { 0x90, 0x00 }); apduRes.Deserialize(apduRes.ResponseData); } else { throw new Exception("GetResponse failed"); } } if (apduRes.SW1 == 0x6C) { //repeat command with correct Le apduCommand.Le = apduRes.SW2; apduRes = await Transceive(apduCommand); } return(apduRes); }
public CardRequest(ApduCommand apduCommand, CardinterfaceServiceRequestEnum kernel1CardinterfaceServiceRequestEnum) { this.ApduCommand = apduCommand; this.CardinterfaceServiceRequestEnum = kernel1CardinterfaceServiceRequestEnum; }