【问题标题】:Ubuntu does not recognize my smart card readerUbuntu 无法识别我的智能卡读卡器
【发布时间】:2021-12-31 08:45:13
【问题描述】:

我正在使用 Ubuntu 18 并尝试编写代码以使用智能卡。 我正在使用 ACS APG8201-b2 智能卡读卡器,并且已安装 the official driver(PC/SC 驱动程序包 3.04 MB,版本 1.1.8,2020 年 1 月 10 日)和 libpcsclite-dev。 作为一个起点,我正在尝试运行 Ludovic Rousseau 的示例 C 代码here。 我可以将我的代码ApduTool.c 编译为:

#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;
}

使用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

当我运行 ApduTool 二进制文件时,SCardListReaders 函数返回:SCardListReaders: Cannot find a smart card reader. 我猜不出问题是什么,因为我可以在运行lsusb 时看到我的 USB 读卡器:

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

并且我在运行代码时运行了 PCSC 守护程序 (pcscd)。

谁能帮我解决这个问题?我是否错过了安装特定驱动程序?

【问题讨论】:

    标签: ubuntu smartcard smartcard-reader pcsc


    【解决方案1】:

    您的系统将 USB 阅读器识别为现有并已连接这一事实不足以知道如何解决它。

    我假设缺少相应的驱动程序(不确定 ACS 是否为 Linux 提供了一个)。

    【讨论】:

    • 我已经为这个阅读器安装了官方驱动。还是不行
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多