The reason I mention a smart card reader is because I am currently working with blank SIM cards. This post is about setting up the smart card reader with an appropriate kernel driver, a middle-ware to make it hustle-free to detect and use the card and test some code snippets from around the inter-webs. The reader I have is a BLUTRONICS BLUDRIVE II which is about $39 on ebay. We will install the Chip/Smart Card Interface Devices(CCID) free software driver, pcsclite and some pcsc tools as middelware for testing. We can in later posts learn more about the protocols and actually writing to the different types of smart cards.
- install CCID
This can be done by grabbing a zipped file with sources or cloning a git repo. Since this post is not about developing CCID, lets take the easier option and save you some miles 😛 by grabbing the zipped file.
cd into your favorite sources folder
get the CCID sources, extract and cd into the CCID source folder
wget https://alioth.debian.org/frs/download.php/file/4140/ccid-1.4.20.tar.bz2 && tar -xjf ccid-1.4.20.tar.bz2 && cd ccid-1.4.20
configure the installation
At this point, there are some options that can be passed to configure to customize the installation. An important one I noticed is one which forces the CCID driver to use udev events so that pcscd will not poll the USB bus every second. Unfortunately, configure doesn’t understand that option, at least in the latest version we pulled. You can check the available options by issuing the command ./configure — and adding double tabs
./configure -- --bindir= --disable-FEATURE --dvidir= --enable-maintainer-mode --exec-prefix= --libexecdir= --program-prefix= --sysconfdir= --build= --disable-libtool-lock --enable-bundle= --enable-serialconfdir= --help --localedir= --program-suffix= --version --cache-file= --disable-libusb --enable-ccidtwindir= --enable-shared --help= --localstatedir= --program-transform-name= --with-gnu-ld --config-cache --disable-multi-thread --enable-composite-as-multislot --enable-silent-rules --host= --mandir= --psdir= --without-PACKAGE --datadir= --disable-option-checking --enable-dependency-tracking --enable-static --htmldir= --no-create --quiet --with-PACKAGE --datarootdir= --disable-pcsclite --enable-embedded --enable-syslog --includedir= --oldincludedir= --sbindir= --with-pic --disable-class --disable-silent-rules --enable-fast-install --enable-twinserial --infodir= --pdfdir= --sharedstatedir= --with-sysroot= --disable-dependency-tracking --docdir= --enable-FEATURE --enable-usbdropdir= --libdir= --prefix= --srcdir=
Let’s hope that’s because it was integrated into the driver by default.
More information on the authors blog about hot-plug mechanisms. It seems libusb was favored as opposed to libhal and hence udev hot-plugging, and lesson to learn is that hot-plugging has been a moving target in the past in Linux.
make the binaries and install the CCID driver
make -j4 sudo make install
- Udev rules
Copy udev rules to /etc/udev/rules.d , there is a rule in there to alter usb auto-suspend kernel configuration. Pcsc is supposed to use usb auto-suspend for CCID devices only.
sudo cp src/92_pcscd_ccid.rules /etc/udev/rules.d/
- Install middleware:
sudo apt-get install libpcsclite1 pcscd pcsc-tools
Detect the card reader/writer
run the pcscd daemon with debug option, in foreground
sudo pcscd -d -a -f
on another terminal run pcsc_scan
PC/SC device scanner V 1.4.22 (c) 2001-2011, Ludovic Rousseau <firstname.lastname@example.org> Compiled with PC/SC lite version: 1.8.10 Using reader plug'n play mechanism Scanning present readers... 0: BLUTRONICS BLUDRIVE II CCID (62657374) 00 00 Tue Sep 1 21:27:43 2015 Reader 0: BLUTRONICS BLUDRIVE II CCID (62657374) 00 00 Card state: Card inserted, ATR: 3B 7D 94 00 00 55 55 53 0A 74 86 93 0B 24 7C 4D 54 68 ATR: 3B 7D 94 00 00 55 55 53 0A 74 86 93 0B 24 7C 4D 54 68 + TS = 3B --> Direct Convention + T0 = 7D, Y(1): 0111, K: 13 (historical bytes) TA(1) = 94 --> Fi=512, Di=8, 64 cycles/ETU 62500 bits/s at 4 MHz, fMax for Fi = 5 MHz => 78125 bits/s TB(1) = 00 --> VPP is not electrically connected TC(1) = 00 --> Extra guard time: 0 + Historical bytes: 55 55 53 0A 74 86 93 0B 24 7C 4D 54 68 Category indicator byte: 55 (proprietary format) Possibly identified card (using /usr/share/pcsc/smartcard_list.txt): 3B 7D 94 00 00 55 55 53 0A 74 86 93 0B 24 7C 4D 54 68 SIM from sysmocom sysmoSIM-GR2
Now to the snippets 🙂
Test code snippet in different languages
We have installed a driver and some middleware application for a CCID smart card reader/writer, and tested that the reader, and some blank SIM card inserted into the reader/writer can be detected. There also exists high-level wrappers for languages like C, Python(my favorite), Perl and Java. We have tested C and python, and so far so good. Next is about what to write in there and how, then probably build a nifty interface 🙂 .
1. Debian driver: http://pcsclite.alioth.debian.org/ccid.html
2. code snippet in different languages: http://ludovicrousseau.blogspot.com/2010/04/pcsc-sample-in-different-languages.html
3. Git repos: https://alioth.debian.org/plugins/scmgit/cgi-bin/gitweb.cgi?a=project_list;pf=pcsclite
4. Hotplugging: http://ludovicrousseau.blogspot.co.ke/2011/02/pcscd-now-uses-libudev-instead-of.html