Ejemplo n.º 1
0
        /// <inheritdoc />
        public ErrorCode Transmit(ICardCommand command, ICardResponse response)
        {
            switch (InteractiveController.Mode)
            {
            case InteractiveMode.Replay:
            {
                var nextAction = InteractiveController.ActionsList[InteractiveController.ActionsListId] as TransmitAction;

                if (nextAction == null || nextAction.Command != command.ToString())
                {
                    return(ErrorCode.UnsupportedFeature);
                }

                // Retrieve response to send
                response.Parse(nextAction.Response.FromHexa());
                // Seek id to next action and check limits
                if (++InteractiveController.ActionsListId == InteractiveController.ActionsList.Count)
                {
                    InteractiveController.Mode = InteractiveMode.Transparent;
                }

                return(ErrorCode.Success);
            }

            default:
                var ret = stack.RequestLayer(this, SearchMode.Next).Transmit(command, response);

                if (InteractiveController.Mode == InteractiveMode.Record)
                {
                    InteractiveController.ActionsList.Add(new TransmitAction(command.ToString(), response.ToString()));
                }

                return(ret);
            }
        }
Ejemplo n.º 2
0
        public ErrorCode Transmit(ICardCommand command, ICardResponse response)
        {
            ErrorCode ret;
            var       cAPDU = (CommandAPDU)command;

            if ((cAPDU.Ins == 0xA4) && cAPDU.IsCc4)
            {
                var le = cAPDU.Le;
                cAPDU.HasLe = false;
                // As an example, direct use of the layer to transmit the command
                ret = stack.RequestLayer(this, SearchMode.Next).Transmit(command, response);
                var rAPDU = (ResponseAPDU)response;
                if ((ret == ErrorCode.Success) && (rAPDU.Sw1 == 0x61))
                {
                    if (le > rAPDU.Sw2)
                    {
                        le = rAPDU.Sw2;
                    }
                    // As an example, use of a CommandResponsePair object to manage the dialog
                    var crpGetResponse = new CommandResponsePair(new GetResponseCommand(le))
                    {
                        RApdu = rAPDU
                    };
                    ret = crpGetResponse.Transmit(stack.RequestLayer(this, SearchMode.Next));
                }
            }
            else
            {
                ret = stack.RequestLayer(this, SearchMode.Next).Transmit(command, response);
            }

            return(ret);
        }
Ejemplo n.º 3
0
        /// <inheritdoc />
        public virtual ErrorCode Transmit(ICardCommand command, ICardResponse response)
        {
            var recvSize = Primitives.Api.AutoAllocate;

            byte[] recvBuffer = null;
            var    ret        = __transmit(command, ref recvBuffer, ref recvSize);

            response.Parse(recvBuffer, recvSize);
            return(ret);
        }
Ejemplo n.º 4
0
        /// <inheritdoc />
        public virtual ErrorCode Transmit(ICardCommand command, ICardResponse response)
        {
            var result = _fakeCard.ExecuteCommand(new CommandAPDU(command.BinaryCommand));

            if (result.ErrorCode == ErrorCode.Success)
            {
                var rApdu = result.RApdu;
                response.Parse(rApdu.Udr.Concat(new byte[] { rApdu.Sw1, rApdu.Sw2 }).ToArray());
            }

            return(result.ErrorCode);
        }
Ejemplo n.º 5
0
        /// <inheritdoc />
        public ErrorCode Transmit(ICardCommand command, ICardResponse response)
        {
            BeforeTransmitEvent.Raise(this, new BeforeTransmitEventArgs {
                Command = command, Response = response
            });

            var ret = channel.Transmit(command, response);

            AfterTransmitEvent.Raise(this, new AfterTransmitEventArgs {
                Command = command, Response = response, ReturnValue = ret
            });

            return(ret);
        }
Ejemplo n.º 6
0
        /// <inheritdoc />
        public ErrorCode Transmit(ICardCommand command, ICardResponse response)
        {
            ErrorCode ret;

            // Adapt APDU for T=0 smartcards
            if (Protocol == Protocol.T0)
            {
                ret = TransmitT0((CommandAPDU)command, (ResponseAPDU)response);
            }
            // T=1 smartcards
            else
            {
                ret = _cardChannel.Transmit(command, response);
            }

            return(ret);
        }
Ejemplo n.º 7
0
 /// <inheritdoc/>
 public ErrorCode Transmit(ICardCommand command, ICardResponse response)
 {
     return(cardChannel.Transmit(command, response));
 }
Ejemplo n.º 8
0
 /// <inheritdoc />
 public ErrorCode Transmit(ICardCommand command, ICardResponse response)
 {
     return(RequestLayer(null, SearchMode.Top).Transmit(command, response));
 }
Ejemplo n.º 9
0
 public void BeforeTransmit(ICardChannel cardChannel, ICardCommand cardCommand, ICardResponse cardResponse)
 {
     gui.guiDetailedLogs.SelectionColor = highlightColor;
     gui.guiDetailedLogs.AppendText(String.Format(header + "transmit({0})\n", cardCommand));
     gui.guiDetailedLogs.SelectionColor = standardColor;
 }
Ejemplo n.º 10
0
 public void NotifyTransmit(ICardChannel cardChannel, ICardCommand cardCommand, ICardResponse cardResponse, ErrorCode errorCode)
 {
     if (errorCode == ErrorCode.Success)
     {
         gui.guiDetailedLogs.AppendText(String.Format(header + ">> Error: {0}\n", errorCode));
         gui.guiDetailedLogs.AppendText(String.Format(header + ">> RAPDU: [{0}]\n", cardResponse));
     }
     else
     {
         gui.guiDetailedLogs.AppendText(String.Format(header + ">> Error: {0}\n", errorCode));
     }
 }