1

I am working to an application to read EMV card using C#. I use Winscard.dll . and i established the conncetion - Selected the reader - connect to card and get ATR . but when sending comand Slecetd Application usin AID list, I did not recive any data, I expected to receive SW1SW2 as 61XX( where XX the length of data ) I sent the command as 00A4040007A0000000031010 .

The code is:

    // Private/Internal Types
    [StructLayout(LayoutKind.Sequential)]
    internal class SCARD_IO_REQUEST
    {
        internal uint dwProtocol;
        internal int cbPciLength;
        public SCARD_IO_REQUEST()
        {
            dwProtocol = 0;
        }
    }

    public static IntPtr GetPciT0()
    {
        IntPtr handle = LoadLibrary("Winscard.dll");
        IntPtr pci = GetProcAddress(handle, "g_rgSCardT0Pci");
        FreeLibrary(handle);
        return pci;
    }
   // public static byte[] GetSendBuffer(string cla, string ins , string p1 ,string p2 , string lc,string body )

    public byte[] GetSendBuffer()
     {
        // Select application 00A4040007A0000000031010
        string cla = "00";
        string ins = "A4";
        string p1 =  "04";
        string p2 =  "00";
        string lc =  "07";
        string body = "A0000000031010";
        string script = String.Format("{0}{1}{2}{3}{4}{5}", cla, ins, p1, p2,
        lc, body);
        byte[] buffer = new byte[ script.Length / 2];
        //Console.WriteLine("buffer {0}", buffer);
        for (int i = 0; i < script.Length; i = i + 2)
        {

            string temp = script.Substring(i, 2);
            buffer[i / 2] = byte.Parse(temp,
            System.Globalization.NumberStyles.HexNumber);
        }
        return buffer;

    }

//===================================== public void ScardTransmit() { SCARD_IO_REQUEST ioRecv = new SCARD_IO_REQUEST(); byte[] pbRecvBuffer = new byte[255]; int pcbRecvLength = 255; byte[] pbsendBuffer = this.GetSendBuffer();

 int pbsendBufLen = pbsendBuffer.Length;
 ioRecv.cbPciLength = ioRecv.ToString().Length;
 IntPtr SCARD_PCI_T0 = GetPciT0();
 uint uintret = SCardTransmit(pCardHandle, ref ioRecv, pbsendBuffer,
 pbsendBufLen, SCARD_PCI_T0, pbRecvBuffer, ref pcbRecvLength);

}

HelmiB
  • 12,303
  • 5
  • 41
  • 68
  • Far too much code. Trim this down to a minimal snippet that illustrates the problem and then describe the problem and ask your question. – Timwi Aug 22 '10 at 22:16
  • Thanks , i included onlt the functions has problem , please check SCardTransmit function as it did not get any data rsult of select AID comand – hany_elsaid Aug 24 '10 at 00:04

1 Answers1

0

Try just sending the following:

0x00A4040000

That should at least return something. The bytes at the end are optional. They do serve a purpose but just see if you can get something from that first.

Brad
  • 9,113
  • 10
  • 44
  • 68