2 Smartcard Reader Installation Under Linux X86 6

Total Page:16

File Type:pdf, Size:1020Kb

2 Smartcard Reader Installation Under Linux X86 6

THE INFORMATION CONTAINED HEREIN IS CONFIDENTIAL AND PROPRIETARY TO SMSC, SHALL BE USED SOLELY IN ACCORDANCE WITH THE AGREEMENT PURSUANT TO WHICH IT IS PROVIDED, AND SHALL NOT BE REPRODUCED OR DISCLOSED TO OTHERS WITHOUT THE PRIOR WRITTEN CONSENT OF SMSC. ALTHOUGH THE INFORMATION IS BELIEVED TO BE ACCURATE, NO RESPONSIBILITY IS ASSUMED FOR INACCURACIES. SMSC RESERVES THE RIGHT TO MAKE CHANGES TO THIS DOCUMENT AND TO SPECIFICATIONS AND PRODUCT DESCRIPTIONS AT ANY TIME WITHOUT NOTICE. NEITHER THE PROVISION OF THIS INFORMATION NOR THE SALE OF THE DESCRIBED SEMICONDUCTOR DEVICES CONVEYS ANY LICENSES UNDER ANY PATENT RIGHTS OR OTHER INTELLECTUAL PROPERTY RIGHTS OF SMSC OR OTHERS. THE PRODUCT MAY CONTAIN DESIGN DEFECTS OR ERRORS KNOWN AS ANOMALIES, INCLUDING BUT NOT NECESSARILY LIMITED TO ANY WHICH MAY BE IDENTIFIED IN THIS DOCUMENT, WHICH MAY CAUSE THE PRODUCT TO DEVIATE FROM PUBLISHED SPECIFICATIONS. SMSC PRODUCTS ARE NOT DESIGNED, INTENDED, AUTHORIZED OR WARRANTED FOR USE IN ANY LIFE SUPPORT OR OTHER APPLICATION WHERE PRODUCT FAILURE COULD CAUSE OR CONTRIBUTE TO PERSONAL INJURY OR SEVERE PROPERTY DAMAGE.

THE CUSTOMER IS THE BEST JUDGE OF THE VALUE AND IMPORTANCE OF THE DATA HELD ON THE SMSC HARDWARE OR SOFTWARE AND SHOULD INSTITUTE AND OPERATE ALL NECESSARY BACKUP PROCEDURES TO ENSURE THAT DATA INTEGRITY CAN BE MAINTAINED IN THE EVENT OF LOSS OF DATA FOR ANY REASON. IN ADDITION, THE CUSTOMER MAY WISH TO CONSIDER TAKING OUT AN INSURANCE POLICY OR OTHER FINANCIAL COVER FOR LOSS OR DAMAGE, WHICH MAY ARISE FROM LOSS OF DATA. SMSC CANNOT BE RESPONSIBLE FOR LOSS OF DATA. Change Information

Date Issue Author Description of changes July 18, 1.0 SMSC Initial version 2011 Team July 22, 1.1 SMSC Smartcard Reader Setup in ARM Platform 2011 Team July 25, 1.2 SMSC Debugging in Linux 2011 Team Oct 1.3 SMSC Formatting 10,2011 Team December 1.4 Remove ldconfig in ARM setup 20,2011 Table of Contents 1 Introduction This document explains the installation of SEC1110/SEC1210CCID reader in Linux on different platforms.

1.1 Smartcard reader installation under Linux x86 The below described setup was done using Fedora 14 with kernel version 2.6.35.6- 45

1.1.1 Required Libraries

The following libraries are prerequisite to install a USB smartcard reader under Linux x86. 1. libusb 1.0.8 2. pcsc-tools 3. libpcsc-lite 4. libccid

Following are the dependencies for the installation of above libraries

1. gnu gcc,make 2. libudev 3. libtool 4. perl-Gtk2

1.1.2 libusb-1.0.8 Obtain the libusb package from sourceforge.net/projects/libusb/ % tar xvjf libusb-1.0.8.tar.bz2 % cd libusb-1.0.8

%su #As ROOT perform % ./configure % make % make install

Note: 1. There is a limitation in using SMSC’s Dual Slot Reader with libusb where the slot with card always present is not accessible or simply stated, the second interface of the reader is not accessible. The limitation is not noticed when tested with pcsclite-1.7.4 compiled using libudev enabled and libusb disabled.

2. The author has added support for libudev since pcsclite -1.6.8, while removing libhal. http://ludovicrousseau.blogspot.com/2011/02/pcscd-now-uses-libudev-instead- of.html 1.1.3 libudev-dev

In case of a Fedora system Install libudev development files as

%yum install libudev-devel

Or in case of Ubuntu use

%sudo apt-get install libudev-dev

1.1.4 pcsc-lite Obtain tar file for the pcsc-lite version 1.7.4 from https://alioth.debian.org/frs/?group_id=30105

% tar xvjf pcsc-lite-1.7.4.tar.bz2 % cd pcsc-lite-1.7.4

%su #As ROOT perform % ./configure –enable-libusb –disable-libudev --enable-debugatr % make % make install

In case of following with section2.1.3 use below configuration

% ./configure –enable-libudev –disable-libusb --enable-debugatr % make % make install

1.1.5 pcsc-tools Obtain tar file for pcsc-tools from http://ludovic.rousseau.free.fr/softwares/pcsc-tools/pcsc-tools-1.4.17.tar.gz % tar xvf pcsc-tools-1.4.17.tar.gz % cd pcsc-tools-1.4.17 %su #As ROOT perform % ./configure % make % make install 1.1.6 CCID free software driver Obtain a copy of the free driver ccid-1.4.4.tar.bz2 from http://pcsclite.alioth.debian.org/ccid.html

% tar xvjf ccid-1.4.4.tar.bz2 % cd ccid-1.4.4 % cd readers

Here is present a file “supported_readers.txt” containing the list of supported readers. SMSC's smart card reader USX101x needs to be added to this list along with its VID and PID. Add the following at the end of the “supported_readers.txt” for SMSC device to be detected as smartcard reader.

For Single Slot device # SMSC 0x0424:0x1104:USX101x SmartCard Reader

For Dual Slot device # SMSC 0x0424:0x1202:USX101x Dual Slot SmartCard Reader

Where 0x0424 Stands for SMSC’s VID and following value corresponds to the PID of the Device.

Now as ROOT do % ./configure % make % make install

1.1.7 perl-Gtk2 This dependency will be required to run the tools obtained using pcsc-tools. In Fedora use %su %yum install perl-Gtk2

1.1.8 Other Dependencies For other dependency library installation follow the general steps

% tar xvf library.tar.gz (or) % tar xvjf library.tar.bz2 % cd library As ROOT perform % ./configure % make % make install

1.1.9 OpenSC OpenSC is a tool that can be used to list the smartcard readers installed in a system. This tool can be installed manually as

% tar xvf opensc-0.12.0.tar.gz % cd opensc-0.12.0

%su #As ROOT perform % ./configure % make % make install

Note:A possible issue while running OpenSC after manual installation would be with accessing libpcsclite.so.In that case, follow the solution mentioned in OpenSC website http://www.opensc-project.org/opensc/wiki/FrequentlyAskedQuestions 2 Smart Card Reader Installation Under ARM Platform To Setup the SmartCard Reader on an embedded ARM platform we will be using a HOST Linux PC to Cross Compile the required libraries and then copy the compiled libraries and resources to the ARM device. In this Setup

HOST DEVICE : Ubuntu Linux 11.04 TARGET DEVICE : OpenRD Tasman System

2.1 Required Libraries and tools Create a directory to copy the libraries required for the cross compilation Toolchain.

% cd /home/smsc/Desktop/

% mkdir toolchain

Obtain the source tar bals for the libraries from their online repositories

1. libusb-1.0.8.tar.bz2

2. pcsc-lite 1.7.4.tar.bz2

3. ccid-1.4.4.tar.bz2

Copy these source files to our toolchain directory (/home/smsc/Desktop/toolchain/) from the place of Download. Copy OpenRD’s gcc compiler for their ARM platform from the given media to the toolchain directory

% cp /home/openrd/openrd-tasman-devkit-v1.0/openrd- tasman_host_swsupportpackage/linux/gcc.tar.bz2 /home/smsc/Desktop/toolchain/

% cd /home/smsc/Desktop/toolchain/

% tar -xjvf /home/smsc/Desktop/toolchain/gcc.tar.bz2

Add this gcc location to the PATH environment variable

% export PATH=/home/smsc/Desktop/toolchain/gcc/bin: $PATH

Now Set the compiler variables to utilize the OpenRD compiler. % export CC=arm-none-linux-gnueabi-gcc AR= arm-none-linux-gnueabi -ar LD= arm-none-linux-gnueabi -ld STRIP= arm-none-linux-gnueabi-strip

The above variables CC, AR, LD, STRIP and the corresponding names will be present as executables in the declared PATH variable

2.2 Extract Libraries Libusb,Pcsclite,Ccid

Create a Separate Directory to install the cross-compiled toolchain.

% mkdir –p /home/smsc/Desktop/Target % cd /home/smsc/Desktop/Target

2.2.1 libusb-1.0.8 Obtain the libusb package from sourceforge.net/projects/libusb/ % tar xvjf libusb-1.0.8.tar.bz2 % cd libusb-1.0.8 %./configure --host=arm-none-linux-gnueabi --prefix=/usr % make %su #As ROOT perform % make install prefix=/home/smsc/Desktop/Target/

Now just make sure that the compiled library files support the ARM platform and not the host architecture i.e X86

Cd =/home/smsc/Desktop/Target/lib/ File lib*

The command output should show that the file is supported for ARM.

2.2.2 pcsc-lite

% tar xvjf pcsc-lite-1.7.4.tar.bz2 % cd pcsc-lite-1.7.4 % ./configure --host=arm-none-linux-gnueabi --prefix=/usr –enable-libusb –disable-libudev --enable-debugatr PKG_CONFIG_PATH==/home/smsc/Desktop/toolchain/OpenRD/l ib/pkg-config LIBUSB_CFLAGS=- I/home/smsc/Desktop/Target/include/libusb-1.0/ LIBUSB_LIBS=/home/smsc/Desktop/Target/lib/libusb-1.0.so % make % make install prefix=/home/smsc/Desktop/Target/

Check the compatibility for ARM as done before

2.2.3 CCID free software driver Obtain a copy of the free driver ccid-1.4.4.tar.bz2 from http://pcsclite.alioth.debian.org/ccid.html .

% tar xvjf ccid-1.4.4.tar.bz2 % cd ccid-1.4.4 % cd readers

Here is present a file “supported_readers.txt” containing the list of supported readers. SMSC's smart card reader USX101x needs to be added to this list along with its VID and PID. Add the following at the end of the “supported_readers.txt” for SMSC device to be detected as smartcard reader.

# SMSC 0x0424:0x1011:USX101x SmartCard Reader 0x0424:0x1200:USX101x Dual Slot SmartCard Reader

Where 0x0424 Stands for SMSC’s VID and following value corresponds to the PID of the Device.

%cd /home/smsc/Desktop/toolchain/ccid-1.4.4

% ./configure --host=arm-none-linux-gnueabi –prefi x=/usr PCSC_CFLAGS=- I/home/smsc/Desktop/Target/include/PCSC/ LIBUSB_CFLAGS=- I/home/smsc/Desktop/Target/include/libusb-1.0/ LIBUSB_LIBS=/home/smsc/Desktop/Target/lib/libusb- 1.0.so --enable- usbdropdir=/home/smsc/Desktop/Target/lib/drivers PCSC_LIBS=/home/smsc/Desktop/Target/lib/libpcsclite.so .1.0.0

//(Kindly check NOTE: in section2.3 method1)

% make % make install prefix=/home/smsc/Desktop/Target/ Check the compatibility for ARM as done before .Also check for the driver file at /home/smsc/Desktop/Target//lib/drivers/ifd- ccid.bundle/Contents/Linux/libccid.so

2.3 Copying the Installed Libraries to the ARM Device:

The Directory used as prefix in the library configuration will now hold the following cross compiled Resources

/home/smsc/Desktop/Target/lib /home/smsc/Desktop/Target/include /home/smsc/Desktop/Target/sbin /home/smsc/Desktop/Target/share

The contents of these directories now need to be copied to their corresponding directories in the ARM device as follows /usr/include /usr/lib /usr/share /usr/sbin

To copy the compiled libraries from the host to OpenRD ,two methods can be followed

Method 1: Tar the folder containing the libraries in the host and copy to the OpenRD using a USB storage device and untar the file To create a tar file of the location /home/smsc/Desktop/Target type..

%tar cvjf tools.bzip2 /home/smsc/Desktop/Target

%cp –f /home/smsc/Desktop/Target/tools.bzip2 /media/pendrive

Move the pendrive to the OpenRD system and mount it

%cp –f /media/pendrive/tools.bzip2 /home/openrd/Desktop

%cd /home/openrd/Desktop

%tar xvjf tools.bzip2

%cd Target %cp –fr include/ /usr/ %cp –fr /lib /usr/ %cp –fr /sbin /usr/

The current method of setup requires a copy of the driver “libccid.so” to be copied in the same directory structure as in the host. So Create the below directory

%mkdir -p /home/smsc/Desktop/Target/lib/pcsc/drivers/ifd- ccid.bundle/Contents/Linux/

Now make a copy of the libccid.so file created in section3.2.3 to the new directory

Note: this can be overcome while cross-compiling ccid-1.4.4 , by changing the flag

--enable-usbdropdir=/usr/lib/pcsc/drivers/ifd- ccid.bundle/Contents/Linux/

And copy the libccid.so to the OpenRD

Method2: If tar is not possible,simply copy the directory

/home/smsc/Desktop/Target

While doing so an error like “the filesystem does not support copying symbolic links”, may be posted if the pendrive is in FAT filesystem. This can be resolved later. Now copy the libraries to the corresponding directory structure in OpenRD

%cd Target %cp –fr include/ /usr/ %cp –fr /lib /usr/ %cp –fr /sbin /usr/

Now to resolve the missing symbolic links

%cd /usr/lib %ln -s libusb-1.0.so.0.0.0 libusb-1.0.so.0

%ln -s libusb-1.0.so.0.0.0 libusb-1.0.so

2.4 Setup In ARM Summary

1. Setup a Host Linux System for Cross Compilation using gcc provided by OpenRD 2. Obtain the source tars for the Libraries required to setup a smart reader.

3. Configure using –host=arm-none-linux-gnueabi and Cross Compile the Libraries to a separate directory

4. Move the cross compiled resources from the created directory to the target ARM device.

3 Cross Compilation for Making FileSystem Image

%mkdir –p /home/openrd/Debian_Lenny_OpenRD-Tasman

Obtain the FileSystem source Tar file to /home/openrd

%cd /home/openrd/Debian_Lenny_OpenRD-Tasman

Extract the FileSystem source tar Debian_Lenny_OpenRD-Tasman.tar.gz here

%tar xvf /home/openrd/Debian_Lenny_OpenRD- Tasman.tar.gz /home/openrd/Debian_Lenny_OpenRD-Tasman

%export INSTALL_PATH=/home/openrd/Debian_Lenny_OpenRD- Tasman/

Follow Section 3.1 to setup gcc cross compiler

3.1.1 libusb-1.0.8 Obtain the libusb package from sourceforge.net/projects/libusb/

% tar xvjf libusb-1.0.8.tar.bz2 % cd libusb-1.0.8 % . /configure --host=arm-none-linux-gnueabi --prefix=/usr

% make %su #As ROOT perform % make install DESTDIR=$( INSTALL_PATH)

3.1.2 pcsc-lite

% tar xvjf pcsc-lite-1.7.4.tar.bz2 % cd pcsc-lite-1.7.4

%./configure --host=arm-none-linux-gnueabi --prefix=/usr --enable-libusb --disable-libudev --enable-debugatr LIBUSB_CFLAGS=-I$( INSTALL_PATH)/usr/include/libusb-1.0 LDFLAGS=-L$( INSTALL_PATH)/usr/lib/ LIBUSB_LIBS=-lusb-1.0

% make %make install DESTDIR=$( INSTALL_PATH)

3.1.3 CCID free software driver Obtain a copy of the free driver ccid-1.4.4.tar.bz2 from http://pcsclite.alioth.debian.org/ccid.html .

% tar xvjf ccid-1.4.4.tar.bz2 % cd ccid-1.4.4

%./configure --host=arm-none-linux-gnueabi --prefix=/usr LIBUSB_CFLAGS=-I$( INSTALL_PATH)/usr/include/libusb-1.0 LDFLAGS=-L$( INSTALL_PATH)/usr/lib/ LIBUSB_LIBS=-lusb-1.0 PCSC_CFLAGS=-I$( INSTALL_PATH)/usr/include/PCSC/ --enable-usbdropdir=/usr/lib/pcsc/drivers PCSC_LIBS=-lpcsclite

% make %make install DESTDIR=$( INSTALL_PATH)

3.1.4 Building the UBI FileSystem Image

Once the above libraries have been installed in the filesystem directory, follow the steps to build the Filesystem image using MTD-Utils as documented by OpenRD. The resulting build image will need to be flashed onto the OpenRD Flash memory ,the steps for which are provided by OpenRD documentation.

4 Debugging in Linux

4.1 USB Traces

Sometimes getting a USB bus trace is required to debug field issues. Some of the manufacturers of USB analyzers have been listed below:

Ellisys, LeCroy

4.2 PCSCD debug log 1. Check whether pcscd is running or not. Use command “ps –ef | grep pcscd”. If it lists any running pcscd, stop the process using the command “service pcscd stop”.

2. Start logging using the command “tail –f /var/log/messages > debuglog.txt”

3. Open a new command terminal and run pcscd in debug mode using command “pcscd –df”. All debug messages will be available in a text file named debuglog.txt in current directory.

4. After the issue scenario has been simulated, stop the logging by pressing ctrl+c in the terminal where “tail -...” is running.

5 Appendix

5.1 SIM explorer for Linux-Fedora Install the following packages using yum install in Fedora

%yum install gtk-sharp2 libmono-system-runtime2.0-cil

%yum install monosim

Use a Smartcard to SIM adapter and insert a SIM card in it.

Launch monoSIM % monosim

Select Sim -> Connect to Sim Select SMSC smart card reader. The contacts stored in the SIM card can be viewed as shown below. 5.2 Scriptor - Perl script to send commands to a smart card scriptor is a program that sends commands to a smart card using a batch file or stdin. USAGE: scriptor [-h] [-r reader] [-p protocol] [file]

APDU Commands can be given from command line or a file can also be given instead of stdin to read commands (APDUs)

The commands are of the form: CLA INS P1 P2 Lc [data] [le].Commands need to be sent according to the type of the smart card.

Example: The below sequence of commands can be used on a Airtel SIM card

Method 1: From Command prompt. Step 1: [root@localhost Desktop]# scriptor –r “SMSC USX1011 Smart Card Reader (0123456789AF) 00 00 “ -p “T=0”

Note: If you get a response as shown below just re-run it .It is a utility issue.

Step 2: # reset the card reset Step 3: # Select MF 3F00 A0 A4 00 00 02 3F 00 Step 4: # Get Reponse # 16 is the value of second SW from the previous command A0 C0 00 00 16 Step 5:

# Select DF Telecom (7F10) A0 A4 00 00 02 7F 10

Method 2: Using Batch-file as input

Create a file having contents like below.

# reset the card reset # Select MF 3F00 A0 A4 00 00 02 3F 00 # Get Reponse # 16 is the expected value of second SW from the previous command A0 C0 00 00 16 # Select DF Telecom (7F10) A0 A4 00 00 02 7F 10

Save the file as file.txt (any file name).

Step1: root@localhost Desktop]# scriptor –r “SMSC USX1011 Smart Card Reader (0123456789AF) 00 00 “ -p “T=0” file.txt

This is the output from the Airtel simcard. Note: No need to worry about the error messages below. That is not the proper commands to the card.

5.3 CCID driver fix for Dual Slot Reader using Libusb

As mentioned in section 2.1.2, The Dual Slot reader does not enumerate properly with PCSC lite compiled using libusb.

This issue can be overcome by compiling the ccid driver with a type of hack in its source file CCID_USB.c

Locate the following code

r = libusb_claim_interface(dev_handle, interface); if (r < 0) { (void)libusb_close(dev_handle); DEBUG_CRITICAL4("Can't claim interface %d/%d: %d", bus_number, device_address, r); claim_failed = TRUE; interface_number = -1; continue; }

And make the change as

r = libusb_claim_interface(dev_handle, interface); if (r < 0) { interface=interface+1; r = libusb_claim_interface(dev_handle, interface); if(r<0) { (void)libusb_close(dev_handle); DEBUG_CRITICAL4("Can't claim interface %d/%d: %d", bus_number, device_address, r); claim_failed = TRUE; interface_number = -2; continue; } }

This code shall try to access the second interface which doesn’t happen in the actual driver.

Recommended publications