S9 Reader Reference Manual
S9 Reader Reference Manual
Reference Manual
Page 1 of 71
S9 Contactless Smart Card Reader Reference Manual
Contents
1.1 Overview................................................................................................... 3
1.2 Features .................................................................................................... 3
1.3 Device Interface ......................................................................................... 4
1.4 Reader Packing List..................................................................................... 4
1.5 Software ................................................................................................... 5
1.6 Typical Application ..................................................................................... 5
1.7 Reader Type Description ............................................................................. 5
1.8 Function Description .................................................................................. 6
1.9 API Functions List ....................................................................................... 7
1.10 Error codes and meanings ....................................................................... 13
1.11 Desfire return codes and meanings .......................................................... 15
Page 2 of 71
S9 Contactless Smart Card Reader Reference Manual
1.1 Overview
1.2 Features
Page 3 of 71
S9 Contactless Smart Card Reader Reference Manual
Programming languages:
a variety of programming languages available, with luxuriant Examples (refer
to "1.5 Software" for more information)
OS: Windows 98, Me, 2K, XP, 2003, Vista ,Unix and Linux
Connection cable: length 1.5M, can choose serial K Line or usb cable
Dimensions(L*W*H): 123 * 95 * 27 mm
RS232 Serial Interface or USB been used for communicating with PC.
Page 4 of 71
S9 Contactless Smart Card Reader Reference Manual
1.5 Software
Page 5 of 71
S9 Contactless Smart Card Reader Reference Manual
Page 6 of 71
S9 Contactless Smart Card Reader Reference Manual
Common Functions
Function Name Description
fw_anticoll anti-collision
fw_select Select a card
fw_load_key Load keys of sectors
fw_authentication Authenticate sector key
fw_read Read card (for S50 and S70 cards)
fw_write Writer card (for S50 and S70 cards)
Page 7 of 71
S9 Contactless Smart Card Reader Reference Manual
Device Functions:
CPU(SAM)card-specific functions
Page 8 of 71
S9 Contactless Smart Card Reader Reference Manual
Page 9 of 71
S9 Contactless Smart Card Reader Reference Manual
Page 10of 71
S9 Contactless Smart Card Reader Reference Manual
Page 11of 71
S9 Contactless Smart Card Reader Reference Manual
Page 12of 71
S9 Contactless Smart Card Reader Reference Manual
Page 13of 71
S9 Contactless Smart Card Reader Reference Manual
Page 14of 71
S9 Contactless Smart Card Reader Reference Manual
Error Meanings
Codes
0x00 success
0x01 No card in operation area
0x02 CRC checksum error
0x03 Numerical overflow
0x05 Parity error
0x06 Communication error
Page 15of 71
S9 Contactless Smart Card Reader Reference Manual
2. API Function
Page 16of 71
S9 Contactless Smart Card Reader Reference Manual
Page 17of 71
S9 Contactless Smart Card Reader Reference Manual
Description
Find card, Get the card serial Number in working area. (hex string)
Parameters
icdev:Value of Device Handle.
_Mode: Model of find card.
Value:
0——IDLE mode,can operate one card once;
1——ALL mode,can operate serval card once;
_ Snrbuf: the hex string card number returned(8 bytes)
Return Value
0 if successful; otherwise, Nonzero.
Example
int st;
unsigned char snr[9]={0};
st=fw_card_hex(icdev,1,snr);
Page 18of 71
S9 Contactless Smart Card Reader Reference Manual
2 S70
8 MIFARE PRO
68 ULTRA LIGHT
Return Value
0 if successful; otherwise, Nonzero.
Example
int st;
unsigned int *tagtype;
st=fw_request(icdev,0,tagtype);
Page 19of 71
S9 Contactless Smart Card Reader Reference Manual
4 - KEYSET0 of KEYB
5 - KEYSET1 of KEYB
6 - KEYSET2 of KEYB
_SecNr:Section number(M1 Card:0~15; ML Card:0)
_Nkey:.Card key written to the reader
Return Value
0 if successful; otherwise, Nonzero.
Example
//key A and key B
unsigned char password[7]={0xa0,0xa1,0xa2,0xa3,0xa4,0xa5};
/*Load key of section 1 */
if((fw_load_key(icdev,0,1,password))!=0)
{
printf("Load key error!");
fw_exit(icdev);
}
Page 20of 71
S9 Contactless Smart Card Reader Reference Manual
Page 21of 71
S9 Contactless Smart Card Reader Reference Manual
Remark
the difference between HEX function and normal function is, the string of HEX
function is in the form of hex, while the string of the corresponding normal function
is in the form of ASC codes. For example, if the actual data of second block is:
"1234567890abcedf", then called function fw_read_hex will return the string:
"31323334353637383930616263646566." The same below.
Remark
The second parameter of this function is the block number. For the M1 card, the 4th
block of each sector is the password block; for S70 card, the 4th blocks of the first
32 sectors , and the 16 th block of the last eight sectors, is the password block;
rewriting password block must be carefully, because the sector may damage after the
rewrite operation.
Page 22of 71
S9 Contactless Smart Card Reader Reference Manual
st=fw_halt(icdev);
Remark
There is a parameter _Mode in function fw_card(),card been setted HALT state
when it is setted value 0,the card should be take out the operating area and put
in again.
Page 23of 71
S9 Contactless Smart Card Reader Reference Manual
Page 24of 71
S9 Contactless Smart Card Reader Reference Manual
assign to value * /
Page 25of 71
S9 Contactless Smart Card Reader Reference Manual
_Adr:the address on the card to which the contents of the internal register is
transferred to
Return Value
0 if successful; otherwise, Nonzero.
Example
fw_restore(icdev,1);
fw_transfer(icdev,2);
this two lines will transfer the contents of block 1 to block 2.
Remark
reference the description of fw_ restore
Page 26of 71
S9 Contactless Smart Card Reader Reference Manual
Parameters
icdev:Value of Device Handle.
mode:Modelof display ,
0—— date, format is"year - month - day (yy-mm-dd)"
1—— time, format is "hours - minutes - seconds (hh-mm-ss)"
Return Value
0 if successful; otherwise, Nonzero.
Example
st=fw_disp_mode(icdev,0x01);//set time model
Page 27of 71
S9 Contactless Smart Card Reader Reference Manual
Example
int st;
unsigned char datetime[7];
st=fw_gettime(icdev,datetime);
//datetime is“0x04,0x01,0x04,0x19,0x17,0x23,0x10”,
//means 17:23:10 of April 19th, 2004,Monday
Return Value
0 if successful; otherwise, Nonzero.
Example
int st;
unsigned char datetime[7]={0x04,0x01,0x04,0x19,0x16,0x35,0x10};
st=fw_settime(icdev,datetime);
Page 28of 71
S9 Contactless Smart Card Reader Reference Manual
Example
int st;
unsigned char buffer[100];
st=fw_srd_eeprom(icdev,0,100,buffer);
Page 29of 71
S9 Contactless Smart Card Reader Reference Manual
Page 30of 71
S9 Contactless Smart Card Reader Reference Manual
*rbuff)
Description
Power-on reset function of CPU Card, it will automatically judge card
protocol after reset.
Parameters
ICDev: Handle of Reader Device
Rlen: [out] Length of returned reset information
Rbuff: store returned reset information
Return Value
<0 error, its absolute value is error number
=0 successful
Example
unsigned char rlen;
unsigned char DataBuffer [100];
St=fw_cpureset (ICDev, &rlen, DataBuffer);
Page 31of 71
S9 Contactless Smart Card Reader Reference Manual
slen=5;
senddata[0]=0x00;senddata[1]=0x84;senddata[2]=0x00;
senddata[3]=0x00;senddata[4]=0x04;
st= fw_cpuapdu ( icdev,slen,senddata,&rlen,recdata)
/*send the random number command to the card*/
int fw_read_S70 (int icdev, unsigned char _Adr, unsigned char *_Data);
Description
Read S70 card, only can read one block once, 16 bytes.
Parameters
icdev: Value of Device Handle.
_Adr: Block address (0-255);
_Data: Read data
Return Value
0 if successful; otherwise, nonzero.
Example
int st;
unsigned char data [16];
St=fw_read_S70 (icdev, 100, data); //read block 100 of S70 card
int fw_write_S70 (int icdev, unsigned char _Adr, unsigned char *_Data);
Description
Write S70 card, only can write one block once, 16 bytes.
Page 32of 71
S9 Contactless Smart Card Reader Reference Manual
Parameters
icdev: Value of Device Handle.
_Adr: Block address (0-255);
_Data: data to write
Return Value
0 if successful; otherwise, Nonzero.
Example
int st;
unsigned char *data=”1234567890abcdef”;
st=fw_write_S70 (icdev, 100, data); //write data to block 100
Page 33of 71
S9 Contactless Smart Card Reader Reference Manual
st= fw_write_ultralt(icdev,ipage,sendbuffer);
Page 34of 71
S9 Contactless Smart Card Reader Reference Manual
Example
int st;
st= fw_halt_ultralt(icdev);
Remark
When you finish calling this functionl,you should call the below functions
before read data next time: fw_request_ultralt first, fw_anticall_ultralt second
and fw_select_ultralt finally.
Description
Information transfer between Mifaere Pro Card and APDU(Application
Protocol Unit)
Parameters
icdev: Value of Device Handle.
slen : Length of information for send
sbuff : buff for Information to send
rlen : Length of returned Information
rbuff : buff for returned Information
Return Value
0 if successful; otherwise, Nonzero.
Example
int st;
unsigned char slen,rlen,recdata[100];
slen=7;
unsigned char *senddata=”00A40000022F02”;
Page 35of 71
S9 Contactless Smart Card Reader Reference Manual
st= fw_apdu_mifarepro(icdev,slen,senddata,&rlen,recdata)
Page 36of 71
S9 Contactless Smart Card Reader Reference Manual
Page 37of 71
S9 Contactless Smart Card Reader Reference Manual
Page 38of 71
S9 Contactless Smart Card Reader Reference Manual
Page 39of 71
S9 Contactless Smart Card Reader Reference Manual
Page 40of 71
S9 Contactless Smart Card Reader Reference Manual
0: IDLE mode (only the cards in IDLE state can respond to this
function)
1: ALL mode (cards in IDLE and HALT states, can respond to this
function)
AFI: application identification number (0x00 or 0x01)
N: channel number (current effective value is 0, set to 0)
ATQB: Returned information
ATQB [0] APA, must be 0x50
ATQB [1] PUPI (1st byte), consistent with the card PUPI
/ / the first byte in PUPI
ATQB [2] PUPI (2nd byte) / / the second byte in PUPI
ATQB [3] PUPI (3rd byte) / / the third byte in PUPI
ATQB [4] PUPI (fourth byte) / / the fourth byte in PUPI
ATQB [5] APPLICATION DATA (1st byte), consistent with the card
(First byte)
ATQB [6] APPLICATION DATA (2nd byte) / / the second byte
ATQB [7] APPLICATION DATA (3rd byte) / / The third byte
ATQB [8] APPLICATION DATA (4th byte) / / the Fourth byte
ATQB [9] protocol info (1st byte), 0x00 / / protocol information (the first
byte)
ATQB [10] protocol info (2nd byte), 0x00 / / protocol information (the
second byte)
ATQB [11] protocol info (3rd byte), 0x41 / / protocol information (the third
byte)
ATQB [12] Other
ATQB [13] Other
Return Value
0 if successful; otherwise, Nonzero.
Example
__int16 st;
unsigned char rData[15];
st= fw_request_b(icdev,0,0,0,&UID[1], rData);
Page 41of 71
S9 Contactless Smart Card Reader Reference Manual
__int16 st;
unsigned char rData[15];
st= fw_request_b(icdev,0,0,0,&UID[1], rData);
unsigned char PUPI[4];
for(int j=0;j<4;j++)
PUPI[j]= rData[1+j];
st=fw_attrib(icdev,PUPI,0);
Remark:
if several seleted cards are in active state, you can operate multi cards at
the same time according to the CID (card ID number).
Page 42of 71
S9 Contactless Smart Card Reader Reference Manual
Description
Write card according to CID, one page each time.
Parameters
icdev: Value of Device Handle.
Adr: the page address to write (0 ~ 31)
rbuffer: 8 bytes data to write
Return Value
0 if successful; otherwise, Nonzero.
Example
//to write page 4
__int16 st;
unsigned char data[8]={0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8};
st= fw_write_at(icdev,4,data);
Page 43of 71
S9 Contactless Smart Card Reader Reference Manual
Description
Halt the operation of card, this function is invalid when the card in active
state.
Parameters
icdev: Value of Device Handle.
cid : card ID number, see parameter CID in “fw_attrib”
key : 8 bytes password
Return Value
0 if successful; otherwise, Nonzero.
Example
__int16 st;
unsigned char key[8]={0};
st= fw_halt_at(icdev,0,key);
Page 44of 71
S9 Contactless Smart Card Reader Reference Manual
Page 45of 71
S9 Contactless Smart Card Reader Reference Manual
Page 46of 71
S9 Contactless Smart Card Reader Reference Manual
int st;
char
curkey[17]={0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88,0x11,0x22,0x33,0x4
4,
0x55,0x66,0x77,0x88};
unsigned char sessionkey[50];
st= fw_authen_desfire(icdev,1,curkey,sessionkey);
Description
Get application identifier
Parameters
icdev: Value of Device Handle.
rlen: length of returned data
AIDS: Return of the identification number of all applications
Return Value
0 if successful; otherwise, Nonzero. Reference Table 1.11
Example
int st;
unsigned char revlen;
unsigned char aids[50];
st= fw_getver_desfire (icdev,&rlen,aids);
Page 47of 71
S9 Contactless Smart Card Reader Reference Manual
Return Value
0 if successful; otherwise, Nonzero. Reference Table 1.11
Example
int st;
unsigned char aid[4]={0x01,0x00,0x00};
st= fw_selectApp_desfire(icdev,aid);
Page 48of 71
S9 Contactless Smart Card Reader Reference Manual
Return Value
0 if successful; otherwise, Nonzero. Reference Table 1.11
Example
int st;
unsigned char aid[4]={0x02,0x00,0x00};
unsigned char setting=0xef;
st= fw_createApp_desfire(icdev,aid,setting,0x0e);/* With 14 keys */
Example
int st;
unsigned char aid[3]={0x02,0x00,0x00};
st= fw_delAID_desfire(icdev,aid);
Page 49of 71
S9 Contactless Smart Card Reader Reference Manual
Bit2: Code which determines if it needs certification for card’s master keys
when creating /deleting application:
0: you can not create / delete applications until the master key of card
has been authenticated successfully,.
1: the application is also permitted to creat without certificating card
master key (the default settings).
Before deleting the application, you must authenticate the master key of
application or the master key of card successfully.
Bit1: this byte dertermines whether it needs to certificate the card master key
for access to the application directory:
0:fw_getAIDs_desfire and fw_getKeySetting_desfire: need to
successfully authenticate the master key of card.
1: fw_getAIDs_desfire and fw_getKeySetting_desfire: do not need to
authenticate the master key of card (Default setting).
Bit0: Code which determines whether the master key of card can be
modified:
0: card master key can not be modified (frozen).
1: Card master key can be modified (the current card master key must
be certified, default settings).
sessionKey: session key
Return Value
0 if successful; otherwise, Nonzero. Reference Table 1.11
Example
Page 50of 71
S9 Contactless Smart Card Reader Reference Manual
int st;
unsigned char set=0x0f;
st= fw_changeKeySetting_desfire (icdev,set,key);
Page 51of 71
S9 Contactless Smart Card Reader Reference Manual
Description
Get File Settings
Parameters
icdev: Value of Device Handle.
fileNo: File ID
rlen: length of returned data
fileProper: file property settings
Return Value
0 if successful; otherwise, Nonzero. Reference Table 1.11
Example
int st;
unsigned char revlen;
unsigned char fileset[20];
st= fw_getFileProper (icdev,&revlen,fileset);
Page 52of 71
S9 Contactless Smart Card Reader Reference Manual
Page 53of 71
S9 Contactless Smart Card Reader Reference Manual
Page 54of 71
S9 Contactless Smart Card Reader Reference Manual
st= fw_createCsyRecord_desfire
(icdev,0x03,comSetting,accessRights,recordLen,number);
Page 55of 71
S9 Contactless Smart Card Reader Reference Manual
Page 56of 71
S9 Contactless Smart Card Reader Reference Manual
value,char* sessionKey);
Description
decrement
Parameters
icdev: Value of Device Handle.
fileNo: File ID
value: the gotten value
sessionKey: session key
Return Value
0 if successful; otherwise, Nonzero. Reference Table 1.11
Example
int st;
unsigned int value=100;/*set the value to 100*/
st= fw_debit_desfire (icdev,0x02,value,sesskey);/ *sesskey means the session
key obtained by verifying key */
Remark
After this function called successfully, you should also call the function
fw_commitTransfer_desfire to make the operation into effect.
Page 57of 71
S9 Contactless Smart Card Reader Reference Manual
Page 58of 71
S9 Contactless Smart Card Reader Reference Manual
Note: after the operations of Increase / impairment, writing / clearing the record
are done, you must call this function to make the operations into effect.
Page 59of 71
S9 Contactless Smart Card Reader Reference Manual
Remarks: 1.Length should not exceed 256, otherwise the whole 256 bytes will
be read.
Page 60of 71
S9 Contactless Smart Card Reader Reference Manual
*_Data,int length);
Description
Write protected bits.
Parameters
icdev:Value of Device Handle.
_Adr: Starting address for writing(0~32).
_Data:Data for writing.
length: Length of data to write(0~32).
Return Value
0 if successful; otherwise, Nonzero.
Example
int st;
unsigned char rbuf[2]={0xa2,0x1e};
st=fw_setProtectData_4442(icdev,0, rbuf,2);
Remark
1: parameter _Adr should be set to 0~32;
2: Data for writing must be Consistent with the data stored in the card;
3: value of parameter “length” should not exceed 32;
Page 61of 71
S9 Contactless Smart Card Reader Reference Manual
Page 62of 71
S9 Contactless Smart Card Reader Reference Manual
Page 63of 71
S9 Contactless Smart Card Reader Reference Manual
Return Value
0 if successful; otherwise, Nonzero.
Example
int st;
unsigned char rbuf[2]={0xa2,0x1e};
st=fw_setProtectData_4428(icdev,0, rbuf,2);
Remark:
1: parameter _Adr should value between 0 and 1023;
2: written data should be consistent with the corresponding data which stored
in card;
3: parameter length should not exceed 1024;
Page 64of 71
S9 Contactless Smart Card Reader Reference Manual
Parameters
icdev: Value of Device Handle.
cntReadError : the count of read-error
Return Value
0 if successful; otherwise, Nonzero.
Example
int st;
unsigned char nerror;
st= fw_cntReadError_4428(icdev,&nerror);
Page 65of 71
S9 Contactless Smart Card Reader Reference Manual
Features:
1K bytes of memory, Composed of 16 sectors, each sector has 4 blocks,
and each block has 16 bytes.
Page 66of 71
S9 Contactless Smart Card Reader Reference Manual
Storage structure:
M1 card is divided into 16 sectors, each sector has 4 blocks (block 0~3), a
total of 64 blocks, addressable by block number from 0 to 63. Block 0 of sector
0 (the absolute address 0 block) is used to store Manufacturer code, which has
been Solidified, and can not be changed. The block 0, block 1, block 2 of other
sectord is the data blocks, used for storing data; block 3 is the control block,
stored passwords A, access control, password B, its structure as follows:
A0 A1 A2 A3 A4 A5 FF 07 80 69 B0 B1 B2 B3 B4 B5
Key A(6 bytes) access control (4 bytes) key B(6 bytes)
Page 67of 71
S9 Contactless Smart Card Reader Reference Manual
∶
∶
0 Data 60
15 1 Data 61
2 Data 62
3 KeyA Acces Key B Sector 63
s Trailer
15
X X X X 0 0 1 0 Philips’
Manufacturer code
0 1 2 3 4 5 6 7 8 9 1 1 1 1 14 15
0 1 2 3
Data Block : the first three blocks of all sectors are used to
store data (block 0 of sector 0 can only be read,
block 1, block 2 can be used to store data)
Control Properties:
Page 68of 71
S9 Contactless Smart Card Reader Reference Manual
1. the key and access control of each sector are independent, it may set
their own password and access control according to the actually need.
In the access control ,Each block has three control bits corresponding,
defined as follows:
Block 0: C10 C20 C30
Block 1: C11 C21 C31
Block 2: C12 C22 C32
Block 3: C13 C23 C33
Three control bits exists in the access control byte by positive or negative
form, determines access rights to the block (such as impairment operation
must verify KEY A, for value-added operations must verify KEY B, etc). the
position of three control bits in the access control byte as follows (byte 9 is
spare byte, default is 0x69):
A0 A1 A2 A3 A4 A5 FF 07 80 69 B0 B1 B2 B3 B4 B5
keyA control bits key B
bit 7 6 5 4 3 2 1
0
Byte 6 C23 C22 C21 C20 C13 C12 C11 C10
_b _b _b _b _b _b _b _b
Byte 7 C13 C12 C11 C10 C33 C32 C31 C30
_b _b _b _b
Byte 8 C33 C32 C31 C30 C23 C22 C21 C20
Byte 9
Page 69of 71
S9 Contactless Smart Card Reader Reference Manual
Page 70of 71