简体   繁体   中英

C++ SmartCard communication

I'm using Windows.Devices.SmartCards namespace for communicating with a smart card. I found the reader, and also the card. I can also send APDU commands to the card. But the problem is that after couple of ADPU's I receive response 0x63 00 instead of 0x90 00. Most of the time it stops receiving commands after the second or third APDU and after this the response is always 0x63 00 until I remove the card and reconnect.

Here is my code for transmitting:

String^ NFC::transmit(Array<unsigned char>^ outgoing)
{
    String^ response = "";
    IBuffer^ out = CryptographicBuffer::CreateFromByteArray(outgoing);
    auto task = create_task(connection->TransmitAsync(out)).then([](IBuffer^ buffer) {
        return buffer;
    });
    IBuffer^ responseBuffer = task.get();
    response = CryptographicBuffer::EncodeToHexString(responseBuffer);
    return response;
}

The connection is a valid SmartCardConnection^ object.

The create_task function is from the concurrency namespace.

  1. Am I missing something in communication?
  2. As I found the 0x63 00 means generic error. Do you know more about this?
  3. I found nothing in this namespace how to use protocol t=0 or t=1. Is this important or it finds automatically?

You need to catch the exceptions to see whats is really happens.

For example, try something like this when you get the buffer:

    try
    {
        IBuffer^ responseBuffer = task.get();
    }
    catch (COMException ^ex)
    {
        std::cout << "Transmit APDU failed with exception:" + ex->ToString() << std::endl;
    }

Ref

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM