Smart Card is a pocket-sized card with embedded integrated circuits. It provides identification, authentication, data storage and application processing on simple medium. There are two big categories of smart card: contact and contactless. To identify and authenticate a smart card properly we need a smart card reader. There are many smart card reader and the way we operate is depend on what smart card it can detect.
To detect and use smart card, there is a specification for smart card integration into computing environments. It is called PC/SC (Personal Computer / Smart Card). The standard has been implemented to various operating system: Windows (since NT/9x), Linux, Unix.
We can however create a small device which can make use of smart card reader, instead of using our PC. That’s what we will discuss on this article.
As title suggest, after we have smart card connected we will use PHP as a programming environment.
For this article, we use:
- Working Raspberry Pi model B (+SD card)
- Raspbian Wheezy release date 2013-09-25
- Smart Card Reader, ACR122
- USB power hub
Grab the Materials
Make sure the Raspberry Pi is working properly with Raspbian Wheezy installed. Also make sure all the hardware are available.
We need USB power hub as the ACR122 Smart Card Reader gives too high load for Raspberry Pi so we will feed electricity from somewhere else.
Install the drivers and related package
apt-get install build-essential libusb-dev libusb++-dev libpcsclite-dev libccid
- build-essential is package for building a application
- libusb-dev and libusb++-dev are package for user-space USB programming
- libpcsclite-dev is a middleware to access a smart card using PC/SC (development files) using PC\SC-lite definition
- libccid is a smart card driver
Install PHP and all needed development tool
apt-get install php5-dev php5-cli php-pear
Once PHP installed, we need a PHP extension for smart card:
pecl install pcsc-alpha
You can see the documentation here.
On some case, we need to add an entry to php.ini manually for registering pcsc extension. To do this, open up php.ini and add following entry:
extension = pcsc.soembedded, rpi, smart card