public bool ValidResponse(APDUResponse Response)
 {
     return Response.Status == SC_OK /*|| Response.SW1 == SC_PENDING1 || Response.SW1 == SC_PENDING2*/;
 }
Esempio n. 2
0
        public static void ThrowError(this APDUResponse response)
        {
            if (response.SW1 == 0x90)
            {
                return;
            }

            var simple = new Dictionary <byte, string>
            {
                { 0x90, "No further qualification" },
                { 0x61, "SW2 indicates the number of response bytes still available" },
                { 0x64, "State of non-volatile memory unchanged" },
                { 0x66, "Reserved for security-related issues" },
                { 0x67, "Wrong length" },
                { 0x6B, "Wrong parameter(s) P1-P2" },
                { 0x6C, "Wrong length Le: SW2 indicates the exact length " },
                { 0x6D, "Instruction code not supported or invalid" },
                { 0x6E, "Class not supported" },
                { 0x6F, "No precise diagnosis" },
            };
            var complex =
                new Dictionary <byte, Dictionary <byte, string> >
            {
                { 0x62, new Dictionary <byte, string>
                  {
                      { 0x00, "State of non-volatile memory unchanged, No information given" },
                      { 0x81, "State of non-volatile memory unchanged, Part of returned data may be corrupted" },
                      { 0x82, "State of non-volatile memory unchanged, End of file/record reached before reading Le bytes" },
                      { 0x83, "State of non-volatile memory unchanged, Selected file invalidated" },
                      { 0x84, "State of non-volatile memory unchanged, FCI not formatted according to 5.1.5" },
                  } },
                { 0x63, new Dictionary <byte, string>
                  {
                      { 0x00, "State of non-volatile memory changed, No information given" },
                      { 0x81, "State of non-volatile memory changed, File filled up by the last write" }
                      //           {0xCX, "State of non-volatile memory changed, Counter provided by 'X' (valued from 0 to 15) (exact meaning depending on the command)"},
                  } },
                { 0x65, new Dictionary <byte, string>
                  {
                      { 0x00, "State of non-volatile memory changed, No information given" },
                      { 0x81, "State of non-volatile memory changed, Memory failure" },
                  } },
                { 0x68, new Dictionary <byte, string>
                  {
                      { 0x00, "Functions in CLA not supported, No information given" },
                      { 0x81, "Functions in CLA not supported, Logical channel not supported" },
                      { 0x82, "Functions in CLA not supported, Secure messaging not supported" },
                  } },

                { 0x69, new Dictionary <byte, string>
                  {
                      { 0x00, "Command not allowed, No information given" },
                      { 0x81, "Command not allowed, Command incompatible with file structure " },
                      { 0x82, "Command not allowed, Security status not satisfied" },
                      { 0x83, "Command not allowed, Authentication method blocked" },
                      { 0x84, "Command not allowed, Referenced data invalidated" },
                      { 0x85, "Command not allowed, Conditions of use not satisfied" },
                      { 0x86, "Command not allowed, Command not allowed (no current EF)" },
                      { 0x87, "Command not allowed, Expected SM data objects missing" },
                      { 0x88, "Command not allowed, SM data objects incorrect" },
                  } },
                { 0x6A, new Dictionary <byte, string>
                  {
                      { 0x00, "Wrong parameter(s) P1-P2, No information given" },
                      { 0x80, "Wrong parameter(s) P1-P2, Incorrect parameters in the data field" },
                      { 0x81, "Wrong parameter(s) P1-P2, Function not supported" },
                      { 0x82, "Wrong parameter(s) P1-P2, File not found" },
                      { 0x83, "Wrong parameter(s) P1-P2, Record not found" },
                      { 0x84, "Wrong parameter(s) P1-P2, Not enough memory space in the file" },
                      { 0x85, "Wrong parameter(s) P1-P2, Lc inconsistent with TLV structure" },
                      { 0x86, "Wrong parameter(s) P1-P2, Incorrect parameters P1-P2" },
                      { 0x87, "Wrong parameter(s) P1-P2, Lc inconsistent with P1-P2" },
                      { 0x88, "Wrong parameter(s) P1-P2, Referenced data not found" }
                  } }
            };

            var error = default(string);

            if (simple.ContainsKey(response.SW1))
            {
                error = simple[response.SW1];
            }

            else if (complex.ContainsKey(response.SW1) &&
                     complex[response.SW1].ContainsKey(response.SW2))
            {
                error = complex[response.SW1][response.SW2];
            }
            else
            {
                error = "Unknown error";
            }
            throw new Exception(error);
        }
 public bool Execute(string LogMessage, APDUCommand Command)
 {
     var State = Card.State; // получаем состояние карты - без этого Transmit в realtime выдает ошибку (может быть карта на успевает отработать...
       Response = Card.Transmit(Command);
       bool Result = ValidResponse(Response);
       if (LogMessage.Length > 0)
     Log.Log(2, LogMessage + " " + (Result ? "success: " + Response.Status.ToString("X") : "failed: " + Response.Status.ToString("X")));
       /*if (Response.SW1 == SC_PENDING1 || Response.SW1 == SC_PENDING2)
       {
     State = Card.State;
     GetResponseCommand.Le = Response.SW2;
     Response = Card.Transmit(GetResponseCommand);
     Result = ValidResponse(Response);
     if (LogMessage.Length > 0)
       Log.Log(3, "GET RESPONSE " + (Result ? "success: " + Response.Status.ToString("X") : "failed: " + Response.Status.ToString("X")) + " Data: "+Functions.ByteArrayToString(Response.Data));
       }*/
       return Result;
 }