/// <summary> /// Transmits the given command to the card. If the command conatins variables, teh variables are resolved using the <see cref="ResolveVariable"/> method. /// </summary> protected internal CardResponse Transmit(CardCommand command, IVariableResolver resolver) { if (command is VariableCardCommand) { //Resolve variables VariableCardCommand VariableCommand = (VariableCardCommand)command; foreach (Variable Variable in VariableCommand.Variables) { if (Variable.IsResolved == false) { this.ResolveVariable(Variable, resolver); } } } return(new CardResponse(this.Transmit(command.Serialize(this.SmartCard.Protocol == Protocol.T1)))); }
private CardResponse SendCommandToReader(CardCommand command) { // Write command to a buffer that contains a SCARD_CONTROL_REQUEST header needed by the MKT byte[] SerializedCommand = command.Serialize(); byte[] ReaderCommand = new byte[20 + SerializedCommand.Length]; ReaderCommand[0] = 0x01; //int value! ReaderCommand[4] = 0x02; //int value! ReaderCommand[8] = (byte)(SerializedCommand.Length); //int value! ReaderCommand[13] = 4; Array.Copy(SerializedCommand, 0, ReaderCommand, 20, SerializedCommand.Length); //Call card reader byte[] ReaderResponse = this.scardApi.ControlCardReader(this.CardHandle, ReaderCommand); //Extract Response (strip header) byte[] SerializedResponse = new byte[ReaderResponse.Length - 20]; Array.Copy(ReaderResponse, 20, SerializedResponse, 0, SerializedResponse.Length); return(new CardResponse(SerializedResponse)); }
internal CardCommand GetCommand(CardCommand command, CardResponse response) { this.commandMatch = this.originalCommandTrigger.Match(Conversion.ToHexString(command.Serialize())); this.responseMatch = this.originalResponseTrigger.Match(Conversion.ToHexString(response.Serialize())); string DynamicCommand = this.Resolve(this.dynamicCommandConstructionExpression); this.commandMatch = null; this.responseMatch = null; return(new CardCommand(Conversion.ToByteArray(DynamicCommand))); }
internal bool IsMatch(CardCommand command, CardResponse response) { return(this.originalCommandTrigger.IsMatch(Conversion.ToHexString(command.Serialize())) && this.originalResponseTrigger.IsMatch(Conversion.ToHexString(response.Serialize()))); }