Http://blog.csdn.net/CaesarZou/article/details/7999624
Because PC/SC is a Windows system, it serves applications at the system API level. So for a long time, card readers and tools related to smart cards have been concentrated on Windows, while on Unix systems, card readers have been reluctant to accept. Fortunately, with the open-source organization m.u. s. c.l. with the active efforts of E (movment for the use of smart in Linux environment), pcsclite has become a de facto standard for the PC/SC device framework and application interfaces under xnix, the Mac lion system has already integrated this service in the release version. The following uses the Ubuntu 12.0.4 release as an example.
# First install the pcsc daemon pcscd and tools
Sudo apt-get-y install libusb-Dev
Sudo apt-get-y install pcscd
# Then install a card reader driver that supports pcsc (for example, the built-in ACR acs38u, and other card readers can download and install it on the website)
Sudo apt-get-y install libacr38u
# Connect the card reader, plug the card, and run the scan tool to verify the installation result
Pcsc_scan
The result is as follows:
PC/SC device restart
V 1.4.18 (c) 2001-2011, Ludovic Rousseau <ludovic.rousseau@free.fr>
Compiled with PC/SC Lite version: 1.7.4
Using Reader plug 'n' play mechanic
Scanning present readers...
0: ACS acr38u 00
Thu Sep 20 12:55:08 2012
Reader 0: ACS acr38u 00 00
Card state: card inserted, shared mode,
Recognition: 3B 1D 94 42 72 6f 61 64 54 68 69 6e 6B 69 00 00
Recognition: 3B 1D 94 42 72 6f 61 64 54 68 69 6e 6B 69 00 00
+ Ts = 3B --> direct convention
+ T0 = 1d, y (1): 0001, 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 = & gt; 78125 bits/s
+ Historical Bytes: 42 72 6f 61 64 54 68 69 6e 6B 69 00 00
CATEGORY Indicator byte: 42 (proprietary format)
Possibly identified card (using/usr/share/pcsc/smartcard_list.txt ):
None
Your card is not present in the database.
You can get the latest version of the database from
Http://ludovic.rousseau.free.fr/softwares/pcsc-tools/smartcard_list.txt
Or use: wget http://ludovic.rousseau.free.fr/softwares/pcsc-tools/smartcard_list.txt -- output-document =/home/caesarzou/.smartcard_list.txt
If your ASD is still not in the latest version then please send a mail
To <ludovic.rousseau@free.fr> containing:
# So far, the PC/SC driver has been connected. Now let's try to send an APDU
Sudo apt-get-y install pcsc-Tools
Gscriptor
This is a graphical interface tool. In the script box, enter:
00a4040000
Click the run button. The connection prompt is displayed, and the result is displayed:
Beginning script execution...
Sending: 00 A4 04 00 00
Written ed: 6C 12
Wrong length le: shocould be 0x12
Script was executed without error...
# Congratulations, card access is successful. Now you must be impatient. Do you want to create your own applications?
# Install the Development Library
Sudo apt-Get install libpcsclite-Dev
# Install eclipse CDT as the development environment
Sudo apt-get-y install g ++
Sudo apt-get-y install eclipse-CDT
# Open eclipse, create a new C Project, and add
# Include <pcsc/winscard. h>
# Link to the pcsclite Library: Add pcsclite in C/C ++ build/GCC linker/Libraries
# Now you will be happy to find that the Type Definitions and interfaces provided in winscard. h are the same as those provided in windows. We copy a piece of code from Windows:
[CPP]View plaincopyprint?
- # Include <stdio. h>
- # Include <pcsc/winscard. h>
- Int main (void ){
- Scardcontext m_hcontext;
- Scardhandle m_hcard;
- Scard_io_request IO;
- Char pmszreaders [100];
- Byte capdu [] = {0x00, 0xa4, 0x04,0x00,0x00 };
- Byte rapdu [256 + 2];
- Dword cch = 100;
- DWORD I = 0;
- // Insert
- If (scard_s_success! = Scardestablishcontext (scard_scope_user, null, null, & m_hcontext ))
- {
- Printf ("context error ");
- Return-1;
- }
- // List Reader
- If (scard_s_success! = Scardlistreaders (m_hcontext, null, pmszreaders, & CCH ))
- {
- Printf ("list reader error ");
- Return-2;
- }
- Printf ("list readers \ n ");
- While (I <CCH)
- {
- Printf ("% s \ n", pmszreaders + I );
- I + = strlen (pmszreaders );
- I ++;
- }
- // Connect First Reader
- Io. cbpcilength = sizeof (scard_io_request );
- If (scard_s_success! = Scardconnect (m_hcontext, pmszreaders, scard_mongo_shared, scard_protocol_t0 | scard_protocol_t1, & m_hcard, & Io. dwprotocol ))
- {
- Printf ("Connect card error ");
- Return-3;
- }
- // Transmit APDU
- CCH = 256 + 2;
- If (scard_s_success! = Scardtransmit (m_hcard, & Io, capdu, 5, null, rapdu, & CCH ))
- {
- Printf ("transmit APDU error ");
- Return-4;
- }
- // Echo
- Printf ("transmit APDU \ n ");
- Printf ("capdu :");
- For (I = 0; I <5; I ++)
- {
- Sprintf (pmszreaders, "% 02x", capdu [I]);
- Printf ("% s", pmszreaders );
- }
- Printf ("\ n ");
- Printf ("rapdu :");
- For (I = 0; I <CCH; I ++)
- {
- Sprintf (pmszreaders, "% 02x", rapdu [I]);
- Printf ("% s", pmszreaders );
- }
- Printf ("\ n ");
- // Disconnect
- Scarddisconnect (m_hcard, scard_eject_card );
- // Eject
- Scardreleasecontext (m_hcontext );
- // Puts ("!!! Hello world !!! ");/* Prints !!! Hello world !!! */
- Return 0;
- }
# Compile, run, and output:
List readers
ACS acr38u 00
Transmit APDU
Capdu: 00a4040000
Rapdu: 6c12
Success! Next, I will talk about the configuration based on the javacard environment and tool on Ubuntu, so stay tuned.
Note:
The header file of libpcsclite on Ubuntu is located in/usr/include/pcsc by default. multiple directories are added. Some versions may have # include file errors during compilation. You can modify them as follows:
Sudo Vim/usr/include/pcsc/winscard. h
Change # include <pcsclite. h> to # include <pcsc/pcsclite>, save and exit
Sudo Vim/usr/include/pcsc/pcsclite. h
Change # include <wintypes. h> to # include <pcsc/wintypes. h>.
Attachment:
Eclipse project on Ubuntu: Click to download
Xcode project on Mac: Click to download