gpuguy
gpuguy

Reputation: 4585

CT_init failing with error -8 when using CT-API library for smart card reader communication ACR122U

OS: Windows API: LINK from verion 1.0.1.1 Description:

I'm developing an application in C++ that interacts with a smart card reader using the CT-API library. However, I'm encountering an issue where the CT_init function fails with error code -8.

Here's the relevant code snippet:

#include "framework.h"
#include "test.h"

#include <stdio.h>
#include <ct_api.h>

int main(int argc, char* argv[])
{
    char ret;
    unsigned short ctn=0;
    unsigned short pn = 0; // Initialize 'pn' with a default value of 0
    unsigned char sad;
    unsigned char dad;
    // REQUEST ICC
    unsigned char command[] = { 0x20, 0x12, 0x01, 0x00, 0x00 };
    unsigned short lenc = sizeof(command);
    unsigned char response[300];
    unsigned short lenr = sizeof(response);
    unsigned short i;

    // Hardcoded values for card terminal and ICC interfaces
    const char* ctacs_content =
        "[CardTerminal]\n"
        "CTN1=ACS ACR122\n\n"
        "[ACS ACR122]\n"
        "ICC1=ACS ACR122 0\n"
        "ICC2=Broadcom Corp Contacted SmartCard 0\n";

    // Initialize card terminal
    ret = CT_init(ctn, pn);
    if (ret != OK)
    {
        printf("Error: CT_init failed with error %d\n", ret);
        return 1;
    }

    sad = 2; // Source = Host
    dad = 1; // Destination = Card Terminal

    // Send command
    ret = CT_data(ctn, &dad, &sad, lenc, command, &lenr, response);
    if (ret != OK)
        printf("Error: CT_data failed with error %d\n", ret);
    else
    {
        // Display response
        printf("Response: ");
        for (i = 0; i < lenr; i++)
            printf("%02X ", response[i]);
        printf("\n");
    }

    // Close card terminal
    ret = CT_close(ctn);
    if (ret != OK)
        printf("Error: CT_close failed with error %d\n", ret);

    return 0;
}

The error message I'm getting is:

Error: CT_init failed with error -8

Additionally, here's the content of my ctacs.ini file, which I hardcoded in my code as you can see above:

[CardTerminal]
CTN1=ACS ACR122

[ACS ACR122]
ICC1=ACS ACR122 0
ICC2=Broadcom Corp Contacted SmartCard 0
```

I've checked the documentation for the CT-API library, but I couldn't find any specific information about what error code -8 signifies. I've also verified that the parameters passed to CT_init are correct.

Could someone please help me understand what this error code means and how I can resolve it? Are there any common reasons why CT_init might fail with error -8?

Any assistance or insights would be greatly appreciated. Thank you!

Device manger detected the card reader

enter image description here

I wrote a python script to see the nfc reader details:

import smartcard.System

def list_readers():
    readers = smartcard.System.readers()
    if len(readers) == 0:
        print("No smart card readers found")
    else:
        for reader in readers:
            print("Reader:", reader)

if __name__ == "__main__":
    list_readers()

and here is the output

C:\Users\DELL\source\pytrhon>python test_reader.py Reader: ACS ACR122 0 Reader: Broadcom Corp Contacted SmartCard 0

Do you think my ini stufs are correct ?

// Hardcoded values for card terminal and ICC interfaces
 const char* ctacs_content =
     "[CardTerminal]\n"
     "CTN1=ACS ACR122\n\n"
     "[ACS ACR122]\n"
     "ICC1=ACS ACR122 0\n"
     "ICC2=Broadcom Corp Contacted SmartCard 0\n";

Upvotes: 0

Views: 63

Answers (0)

Related Questions