Linux debugging smart card environment, including Linux dynamic library

Posted by le007 on Mon, 24 Jan 2022 01:40:52 +0100

Some of the resources required below have been uploaded to CSDN resources

1, Download the offline installation package for CentOS (note that you can't download only after installation)

CentOS downloads the rpm package using yum and installs it offline

1. Install the rpm package online and prepare the downloaded package

#yum install --downloadonly --downloaddir=/home/samba  samba

among samba Yes yum Installed packages,/home/samba Is to store the downloaded yum Save path of installation package and its dependent packages

2. On the offline machine, execute the following script in the folder where rpm is located

#rpm -Uvh --force --nodeps *.rpm

3. CentOS uninstall software

# Query software list
# rpm -qa | grep software name
rpm -qa | grep mysql
 
# Uninstall software
# sudo yum remove software name
sudo yum remove mysql
2, Common instructions:
yum install opensc
opensc-tool --list-readers(Restart to take effect)

Enumerate current PC Card reader in    opensc-tool --list-readers   (If installed openSC tool) 

enumeration PC Medium USB equipment       sudo lsusb 

start-up pcsc service            /usr/local/sbin/pcscd -adf   (If already installed pcsc-lite)
						If the following similar information is displayed, the installation is successful
						00017575 pcscdaemon.c:518:main() pcsc-lite 1.8.1 daemon ready.
						
restart PCSC service            sudo service pcscd restart


replace gcc edition             update-alternatives --config gcc
3, CentOS environment installation:

Linux environment: CentOS7 gcc-4.8.5 g + ± 4.8.5

1. Install libudev

on ubuntu

apt-get install libudev-dev

----------------------

on centos

yum install systemd-devel

2. General installation libusb-1.0.21 tar. bz2 ,pcsc-lite_1.8.23.orig.tar.bz2,ccid_1.4.36.orig.tar.bz2

When installing CCID, you need to specify the path of libusb and PCSC:
Select according to different libusb versions:

./configure PCSC_CFLAGS="-I/usr/local/include/PCSC" LIBUSB_CFLAGS="-I/usr/local/include/libusb-1.0" LIBUSB_LIBS="-L/usr/local/lib -lusb-1.0" --enable-usbdropdir="/usr/local/lib/pcsc/drivers"   PCSC_LIBS="-L/usr/local/lib -lpcsclite"

./configure PCSC_CFLAGS="-I/usr/local/include/PCSC" LIBUSB_CFLAGS="-I/usr/local/include/libusb" LIBUSB_LIBS="-L/usr/local/lib -lusb" --enable-usbdropdir="/usr/local/lib/pcsc/drivers"   PCSC_LIBS="-L/usr/local/lib -lpcsclite"

3. Install the perl interpreter plug-in (some systems may lack this interpreter, Ubuntu 16.04 is not missing, but CentOS 7 is missing)

yum install perl-devel

4. Start the pcsc service / usr/local/sbin/pcscd -adf. Displaying ACR38 indicates success

If you can't recognize it, you can plug and unplug the card reader

4, General steps for ubuntu installation:

Ubuntu compilation environment:

Linux system: Ubuntu 16 04
GCC version: gcc-4.7.4 g + ± 4.7.4

If you use a card reader that supports PCSC, you need to install the libusb CCID PCSC Lite driver

1. Install libusb

 # tar zxvf  libusb-0.1.12.tar.gz 
 # cd libusb-0.1.12  
 # chmod +x configure                        
 # ./configure                             
 # make                                    
 # make install          ( Login as a root to install driver )     
The following errors may occur and Solutions:
configure: error: compiler with C11 support is required to build libusb

replace gcc 5.4,Replace with a higher version gcc,Or download and use libusb-1.0.21.tar.bz2,support C99

configure: error: udev support requested but libudev header not installed

see CSDN Blog:
https://blog.csdn.net/liuyan20092009/article/details/52577262

2. Install PCSC Lite

 # tar zxvf  pcsc-lite-1.9.1.tar.gz 
 # cd pcsc-lite-1.9.1.tar.gz 
 # chmod +x configure 
 # ./configure                             
 # make                                    
 # make install          (Login as a root to install driver) 
Errors and Solutions:
configure: error: install libsystemd-dev or use --disable-libsystemd

apt-get install libsystemd-dev

3. Install ccid

 # tar zxvf  ccid_1.4.36.orig.tar.gz 
 # cd ccid-1.4.36  
 # ./configure                             
 # make                                    
 # make install          (Login as a root to install driver) 

4,
Finally, start the pcsc service

 /usr/local/sbin/pcscd 
 perhaps /usr/local/sbin/pcscd -adf

Linux dynamic library related:

1, The Linux dynamic library selection order refers to:

  1. When compiling the program, you need to find the dynamic library from where and in what order?

  2. When running a program, you need a dynamic library. Where should you find it? In what order?

2, When gcc compiles the program, the search order of SO is as follows:

  1. The path specified by the gcc compile time parameter - L

  2. Environment variable LIBRARY_PATH

  3. System default library location / lib /usr/lib

3, The sequence of searching SO when Linux program is running is as follows:

  1. Runtime library path specified at gcc compile time - Wl,-rpath

  2. Environment variable LD_LIBRARY_PATH

  3. ldconfig cache / etc / LD so. cache

4. System default library location / lib /usr/lib

4, LIBRARY_PATH and LD_ LIBRARY_ Differences between path environment variables

LIBRARY_PATH and LD_LIBRARY_PATH is two environment variables under Linux. Their meanings and functions are as follows:

LIBRARY_ The path environment variable is used to specify the path to find the shared library when finding the dynamic link library during program compilation. For example, specify the directory of the dynamic link library required for gcc compilation. The setting method is as follows (LIBDIR1 and LIBDIR2 are two library directories):

export LIBRARY_PATH=LIBDIR1:LIBDIR2:$LIBRARY_PATH

LD_ LIBRARY_ The path environment variable is used to specify a path other than the system default path when finding the dynamic link library during program loading and running. Note that LD_ LIBRARY_ The path specified in path is found before the system default path. The setting method is as follows (LIBDIR1 and LIBDIR2 are two library directories):

export LD_LIBRARY_PATH=LIBDIR1:LIBDIR2:$LD_LIBRARY_PATH

For example, when we develop a program, we often need to use one or some dynamic link libraries. In order to ensure the portability of the program, we can first put these compiled dynamic link libraries in the directory specified by ourselves, and then add these directories to the LD in the above way_ LIBRARY_ Path environment variable, so that your program can load the library file after dynamic link and run.

Difference and use:

When developing, set LIBRARY_PATH so that gcc can find the dynamic link library needed at compile time.

Set LD when publishing_ LIBRARY_ Path, so that when the program is loaded and run, it can automatically find the required dynamic link library.

Topics: Linux CentOS server