-1

I am using Ubuntu 18 and trying to write code to use a smart card. I am using ACS APG8201-b2 smart card reader, and I have installed the official driver (PC/SC Driver Package 3.04 MB, Version 1.1.8, 10-Jan-2020), and libpcsclite-dev. As a starting point, I am trying to run Ludovic Rousseau's sample C code here. I can compile my code ApduTool.c as:

    #ifdef WIN32
    #undef UNICODE
    #endif
    
    #include <stdio.h>
    #include <stdlib.h>
    #include <winscard.h>
    
    #ifdef WIN32
    static char *pcsc_stringify_error(LONG rv)
    {
     static char out[20];
     sprintf_s(out, sizeof(out), "0x%08X", rv);
    
     return out;
    }
    #endif
    
    #define CHECK(f, rv) \
        if (SCARD_S_SUCCESS != rv) \
        { \
            printf(f ": %s\n", pcsc_stringify_error(rv)); \
            return -1; \
        }
    
    int main(void)
    {
        LONG rv;
    
        SCARDCONTEXT hContext;
        LPTSTR mszReaders;
        SCARDHANDLE hCard;
        DWORD dwReaders, dwActiveProtocol, dwRecvLength;
    
        SCARD_IO_REQUEST pioSendPci;
        BYTE pbRecvBuffer[258];
        BYTE cmd1[] = { 0x00, 0xA4, 0x04, 0x00, 0x0A, 0xA0, 0x00, 0x00, 0x00, 0x62, 0x03, 0x01, 0x0C, 0x06, 0x01 };
        BYTE cmd2[] = { 0x00, 0x00, 0x00, 0x00 };
    
        unsigned int i;
    
        rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext);
        CHECK("SCardEstablishContext", rv)
    
        #ifdef SCARD_AUTOALLOCATE
            dwReaders = SCARD_AUTOALLOCATE;
            rv = SCardListReaders(hContext, NULL, (LPTSTR)&mszReaders, &dwReaders);
            CHECK("SCardListReaders", rv)
        #else
            rv = SCardListReaders(hContext, NULL, NULL, &dwReaders);
            CHECK("SCardListReaders", rv)
            mszReaders = calloc(dwReaders, sizeof(char));
            rv = SCardListReaders(hContext, NULL, mszReaders, &dwReaders);
            CHECK("SCardListReaders", rv)
        #endif
    
        printf("reader name: %s\n", mszReaders);
        return 0;
    }

using Makefile:

all: ApduTool.c
    gcc -c ApduTool.c -lsqlite3 -lpcsclite -lcrypto -lssl -I/usr/local/include/PCSC/ -I/usr/lib/ -I.
    gcc ApduTool.o -o ApduTool -lsqlite3 -lpcsclite -lcrypto -lssl -I/usr/local/include/PCSC/ -I/usr/lib/ -I.
clean:
    rm -f ApduTool *.o

When I run ApduTool binary file the SCardListReaders function returns: SCardListReaders: Cannot find a smart card reader. I cannot Guess what the problem can be since I can see my USB reader when running lsusb:

Bus 001 Device 003: ID 072f:8206 Advanced Card Systems, Ltd 
Bus 001 Device 002: ID 80ee:0021 VirtualBox USB Tablet
Bus 001 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub

and I have run the PCSC daemon (pcscd) while running the code.

Can anyone help me solve this? Have I missed to install a specific driver or so?

MJay
  • 987
  • 1
  • 13
  • 36

2 Answers2

1

pcscd should log what is happening and if the reader driver is found.

See https://pcsclite.apdu.fr/#support to know how to generate a correct pcscd log.

0

The fact, that your system identifies the USB reader as existing and connected is insufficent for knowing how to address it.

I assume, that the respective driver is missing (not sure, whether ACS provides one for Linux).

guidot
  • 5,095
  • 2
  • 25
  • 37