Summary of the experience of interacting with USB devices through the CCID protocol under Linux

1. Goal

  Under the linux system, it communicates with the USB device through the ccid protocol.

2. Implementation method

  By referring to other people's blogs, I decided to use the following methods to realize ccid communication.

2.1 Install libudev

  udev is a function in the Linux 2.6 kernel. It replaces the original devfs and becomes the current Linux default device management tool . udev runs as a daemon process , and manages the device files in the / dev directory by listening to the uevent sent by the kernel . Unlike previous device management tools, udev runs in user space, not in kernel space.

2.1.1 Compile and install

  If it is Centos, you can execute: sudo yum install systemd-devel or sudo yum install libudev-devel; if it is Ubuntu, you can pass: sudo apt-get install systemd-devel or sudo apt-get install libudev-devel; if you already have libudev- For devel.rpm package, you can execute sudo rpm -ivh libudev-devel.rpm.

2.1.2 Installation prompt error

  Under Ubuntu 14.04, directly execute sudo apt-get install systemd-devel or sudo apt-get install libudev-devel. Sometimes the installation fails, and the following prompt will appear:
Insert picture description here
  Generally, apt-get appears in the above situation, which is The APT library is not updated, just install the update as follows (it will take a while~):

sudo apt-get update
sudo apt-get upgrade

  After the execution is over, we then execute sudo apt-get install libudev-devel to succeed.

2.2 Compile and install libusb

  For USB devices connected to the computer, it is generally necessary to install the corresponding USB driver to support it. There is an open source cross-platform USB driver, libusb, which can be used to develop custom USB device drivers.
  libusb is a library written in C language, which can be used by upper-level applications to communicate with USB devices connected to the notebook. It is easy to transplant and has corresponding libusb-API documentation, which can be used in Linux, OS X, Windows, Android, OpenBSD and other systems. And it supports USB 1.0 to 3.1 specifications. Generally, libusb comes with Linux systems. Other platforms generally need to install libusb.

2.2.1 Download libusb

Choose a version to download   in https://github.com/libusb/libusb/releases/ address, this article uses libusb-1.0.18.

2.2.2 Compile and install process

(1) Decompress the libusb-1.0.18.tar.gz installation package and execute tar -xvf libusb-1.0.18.tar.gz.
(2) Enter the libusb-1.0.18 file and perform three steps: (a)./configure; (b) make; (c) sudo make install;

2.2.3 Errors prompted during installation

(1) Error prompt
  checking for inline… inline
  checking operating system… Linux
  checking for library containing clock_gettime… -lrt
  checking libudev.h usability… no
  checking libudev.h presence… no
  checking for libudev.h… no
  configure: error: “udev support requested but libudev not installed"
(2) Solution
  Install libudev-devel to solve it. The installation method has been introduced in section 2.1.

2.3 Compile and install pcsc-lite

  pcsc-lite encapsulates a development kit for accessing smart card devices using SCard API (PC/SC).

2.3.1 Download pcsc-lite

Choose a version to download in https://alioth-archive.debian.org/releases/pcsclite/pcsclite/ address, this article chooses pcsc-lite-1.8.11 version.

2.3.2 Compile and install process

(1) Unzip the pcsc-lite-1.8.11.tar.bz2 installation package and execute tar -xvf pcsc-lite-1.8.11.tar.bz2.
(2) Enter the pcsc-lite-1.8.11 folder and perform three steps: (a)./configure; (b) make; (c) sudo make install

2.4 Compile and install ccid

  This library provides a PC/SC IFD processing program implementation for the USB smart card driver that complies with the CCID protocol. This software package is required to communicate with the CCID smart card reader through the PC/SC Lite Explorer (pcscd).

2.4.1 Download ccid

Choose a version to download   from https://alioth-archive.debian.org/releases/pcsclite/ccid/ . This article uses the ccid-1.4.16 version.

2.4.2 Compile and install process

(1) Decompress the ccid-1.4.16.tar.bz2 installation package and execute tar -xvf ccid-1.4.16.tar.bz2.
(2) Enter the ccid-1.4.16 file, find the readers/supported_readers.txt file, and make the following modifications: (a) Add: device name (custom); (b) add: VID: PID: device descriptor;
( 3) Perform compilation and installation, (a)./configure; (b) make; (c) sudo make install;

2.5 Configure environment variables

  Add the path of the compiled shared library to the environment variable. Perform the following operations:
(1) Open the profile file through the command of vim /etc/profile.
(2) Add: export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH, save and exit.
(3) Execute source /etc/profile.

2.6 ccid communication protocol test

2.6.1 Start pcsc service

  Execute pcscd in the command line. Note that if it is not the root account, execute sudo pcscd.

2.6.2 Test results

  Find the testpcsc executable file in the path of pcsc-lite-1.8.11/src/, after inserting the device, execute ./testpcsc, the result is as follows, it proves that the CCID protocol communication is successful.
Insert picture description here

2.7 Installation of other software packages

  Because the project needs to install some other open source libraries, so record it here.

2.7.1 Compile and install boost

  Boost is a general term for some C++ program libraries that provide extensions to the C++ language standard library. The Boost library is a portable C++ library that provides source code. As a backup to the standard library, it is one of the development engines of the C++ standardization process. It is a general term for some C++ program libraries that provide extensions to the C++ language standard library.

2.7.1.1 Download boost

Choose a version to download in https://sourceforge.net/projects/boost/files/boost/ . In this article, boost_1_43_0 is used.

2.7.1.2 Compile and install process

(1) Unzip the boost_1_43_0.tar.gz installation package and execute tar -xvf boost_1_43_0.tar.gz.
(2) Enter the boost_1_43_0 file and perform the following steps: (a)./bootstrap.sh; (b)./bjam (need to wait a long time~);

2.7.1.3 Prompt error during installation

Insert picture description here
  From the first line, we can see that 78 targets failed. After analysis, there are several problems that need to be modified:
(1)./boost/python/detail/wrap_python.hpp:50:23: fatal error: pyconfig.h: No such file or directory, that is, the pyconfig.h file cannot be found. The reason for this problem is that the required files are in the /usr/include/python2.7 path, which needs to be configured to the system path. Open the /etc/profile file and add the following content, and then execute source /etc/profile

export PATH=/usr/include/python2.7:$PATH

Then execute ./bjam, and the results are as follows:
Insert picture description here
(2) Not finished. . .

5. Reference link

(1)https://blog.csdn.net/fafactx/article/details/22931141
(2)https://blog.51cto.com/seiang/1950594
(3)https://blog.csdn.net/suxiang198/article/details/75106296
(4)https://www.jianshu.com/p/8581d232dd6c
(5)https://blog.csdn.net/magic_ninja/article/details/87981662
(6)https://baike.baidu.com/item/boost/69144?fr=aladdin
(7)https://blog.csdn.net/yujun_huoxu/article/details/7913135

Guess you like

Origin blog.csdn.net/qq_39661206/article/details/109239137