API Programmer Guide_RFID-M1
API Programmer Guide_RFID-M1
RFID-M1
API
Programmer Guide
Revision 2.00
Information furnished by IT WORKS, Ltd. is believed to be accurate and reliable. However, no responsibility is
assumed by IT WORKS, Ltd. for its use; nor for any infringement of patents or other rights of third parties which may
result from its use.
Table of Contents
1 API FUNCTIONS 4
2
RFID-M1 – API Programmer Guide
1.4.7 int MF_HLRequest ( int DeviceAddress, unsigned char mode, int &length, unsigned char *UID)
18
2 ADDITIONAL INFORMATION 24
3
RFID-M1 – API Programmer Guide
1 API Functions
Parameter Description
VersionAPI Character pointer to C string which return the Version Number of the API
Return 0x00 – Successful
Description
1.1.2 int ActiveLED ( int DeviceAddress, unsigned char NumLED, unsigned char ontime, ussigned char cycle)
Parameter Description
Description
The LED is blinking for the number of cycles. Each cycle is one second. The turn-on time of the LED in each cycle is
set by the “on-time”.
Example
The Green LED will be toggled (turn on and off ) for three times. Each time the LED will be turned on for 400ms.
DeviceAddress=0x00;
unsigned char NumLED = 0x02; //Select Green LED
unsigned char ontime = 4; //LED on time =400ms
unsigned char cycle = 3; //on-off 3 times (3 second)
if(!ToggleLED(DeviceAddress, NumLED, ontime, cycle))
{ //successful }
Parameter Description
4
RFID-M1 – API Programmer Guide
Description
1.1.4 int ActiveBuzzer ( int DeviceAddress, unsigned char mode, unsigned char *pattern)
Parameter Description
4 – Play a sound pattern. The pattern is a sequence of on-off-on-off sound controlled by the
parameter array “pattern”.
pattern Pointer to a parameter array which controls the sound pattern.
pattern[0]: Units of first on time. Each unit is 100ms.
pattern[1]: Units of first off time.
pattern[2]: Units of second on time.
pattern[3]: Units of second off time.
pattern[4]: Cycle
Return 0x00 – Successful
(Refer the API return code for other values)
Description
Control the buzzer. You can control the buzzer to play a sound pattern by using mode 4.
Example
A sound pattern (on 0.5sec – off 0.3sec – on 1sec –off 0.6sec ) will be played for 7 times.
DeviceAddress=0x00;
pattern[0] = 5;
pattern[1] = 3;
pattern[2] = 10;
pattern[3] = 6;
pattern[4] = 7;
if (!BuzzerControl(DeviceAddress, 0x04, pattern))
{ //successful }
else
{ //Not successful }
5
RFID-M1 – API Programmer Guide
Parameter Description
Description
Turn off the RF field for the units of time after that the RF will be on again. The value 0x00 will turn off the field
forever until a new RF_Field( ) command is issued.
6
RFID-M1 – API Programmer Guide
1.2.1 int MF_Request ( int DeviceAddress, unsigned char mode, unsigned char *ATQ)
Parameter Description
Description
Send the ISO14443 A REQUEST command to the card. The two-byte ATQ string will be returned.
Example
A REQUEST-ALL command will be sent to the card. The ATQ (0x0004) of the card will be returned if the request
command is successful.
DeviceAddress=0x00;
unsigned char ATQ[2];
if (!Request(DeviceAddress, 0x00, ATQ))
{ //successful ATQ[0]= 0x04; ATQ[1] = 0x00 }
else
{ //Not successful }
NOTE: The ATQ for the MIFARE®1 card is 0x0004, other value may be return from cards other then MIFARE®1.
1.2.2 int MF_Anticoll ( int DeviceAddress, unsigned char *UID, unsigned char &Collision)
Parameter Description
Description
Enable the ISO14443A anti-collision loop of cascade level1, the card’s UID of cascade level1 will be returned. The
Collision flag indicates that a collision is happened. (There are more than one card in the Halt mode within the field)
int MF_Anticoll2 ( int DeviceAddress, unsigned char *UID, unsigned char &Collision)
7
RFID-M1 – API Programmer Guide
Parameter Description
Description
Enable the ISO14443A anti-collision loop of cascade level2, the card’s UID of cascade level2 will be returned. The
Collision flag indicates that a collision is happened. (There are more than one card in the Halt mode within the field)
int MF_Anticoll3 ( int DeviceAddress, unsigned char *UID, unsigned char &Collision)
Parameter Description
Description
Enable the ISO14443A anti-collision loop of cascade level3, the card’s UID of cascade level3 will be returned. The
Collision flag indicates that a collision is happened. (There are more than one card in the Halt mode within the field)
Parameter Description
Description
ISO14443A SELECT command of Cascadelevel1. The requested card with the specified UID of Cascadelevel1 will
be (open) for further card commands.
8
RFID-M1 – API Programmer Guide
Parameter Description
Description
ISO14443A SELECT command of Cascadelevel2. The requested card with the specified UID of Cascadelevel2 will
be (open) for further card commands.
Parameter Description
Description
ISO14443A SELECT command of Cascadelevel3. The requested card with the specified UID of Cascadelevel3 will
be (open) for further card commands.
Example
Parameter Description
9
RFID-M1 – API Programmer Guide
0x00 – Standard ISO14443-A Halt command. Use the 16 bit CRC as checksum.
0x01 – Special mode for the SLE55Rxx. The four-byte MAC is used to replace the CRC
checksum. This special mode is used to halt a SLE55Rxx card which is under protected
mode.
Return 0x00 – Successful
(Refer the API return code for other values)
Description
ISO14443A Halt command. The MAC mode is a special mode for the SLE55Rxx card. The SLE55Rxx card enters
protected mode after a successful AUTHENTICATION and uses the four-byte MAC to replace the 16-bit CRC
checksum. Under the protected mode, you need to use the MAC mode to halt the SLE55Rxx cards. For normal
MIFARE® card mode 0x00 should be used for the normal CRC checksum.
1.2.5 int SLE_Generic(int DeviceAddress,unsigned char CRC_Flag,unsigned char &length,unsigned char *buffer)
Parameter Description
Description
ISO14443A general command. Used to Access ISO14443A CPU Card, e.g. Pro(X), DesFire.
10
RFID-M1 – API Programmer Guide
1.3.1 int MF_Auth(int DeviceAddress, unsigned char KeyAB, unsigned char *snr, unsigned char add_blk)
Parameter Description
Description
This command is used to authenticate the selected Mifare® card. Further read/write and value related operations are
allowed only after the successful authentication.
1.3.2 int MF_Read ( int DeviceAddress,unsigned char add_blk, unsigned char num_blk, unsigned char *buffer);
Parameter Description
Description
1.3.3 int MF_Write(int DeviceAddress,unsigned char add_blk, unsigned char num_blk, unsigned char *buffer)
Parameter Description
11
RFID-M1 – API Programmer Guide
Description
Note: The blocks to be written must be in the same sector. Writing data to the sector trailer (block address = N*4+3,
where N is the sector number) should be handled carefully; otherwise you may corrupt the KEY area and lock the
sector.
Parameter Description
Description
Transfer a value amount from the Mifare® Reader Chip’s internal value buffer register to the selected value block.
1.3.5 int MF_Incremnet( int DeviceAddress, unsigned char add_blk, int value )
Parameter Description
Description
Increase the value of a MIFARE® Value Block. The value block must be pre-initialized according to the MIFARE®
Value Block Format.
Note: The VALUE is in plain format, the user is no need to take care the MIFARE® value block format.
Note: The result of the MIFARE®’s Decrement or Increment operation is stored within the on-chip buffer register.
The value in the selected value block will not be updated until the Transfer command is done.
1.3.6 int MF_Decrement( int DeviceAddress, unsigned char add_blk, int value )
Parameter Description
Description
Decrease the value of a MIFARE® Value Block. The value block must be initialized according to the MIFARE®
Value Block Format.
12
RFID-M1 – API Programmer Guide
Note: The VALUE is in plain format, the user is no need to take care the MIFARE® value block format.
Parameter Description
Description
Restore the content of the selected Value Block to the MIFARE® Reader Chip’s internal value buffer register.
1.3.8 int MF_InitValue( int DeviceAddress, unsigned char add_blk, int value )
Parameter Description
Description
Write (initialize) a value to a MIAFARE value block. The block to be written will be automatically formatted with the
MIFARE® Value Block Format.
Parameter Description
Description
Parameter Description
Description
13
RFID-M1 – API Programmer Guide
Directly load the key to the Master Key Buffer. A Master Key must be loaded to the Master Key Buffer (by
MF_LoadKey ( ) or MF_LoadKeyFromEeprom( ) ) before executing the Authentication command.
1.3.11 int MF_StoreKeyToEE(int DeviceAddress, unsigned char KeyAB, unsigned char Sector, unsigned char *Key)
Parameter Description
Description
1.3.12 int MF_LoadKeyFromEF(int DeviceAddress, unsigned char KeyAB, unsigned char Sector)
Parameter Description
Description
Load key to the Master Key Buffer from the MFRC500 chip’s internal EEPROM. This function has the same
function as the MF_LoadKey( ), but the key is loaded from the internal EEPROM instead providing the 6-byte un-
coded key string
14
RFID-M1 – API Programmer Guide
The High Level command integrated the low level commands – Request, Anti-Collision – Select – LoadKey –
Authentication – Read/Write/Increment/Decrement to a single one-step operation.
1.4.1 int MF_HLRead ( int DeviceAddress, unsigned char mode, unsigned char add_blk, unsigned char num_blk,
unsigned char *snr, unsigned char *buffer);
Parameter Description
Description
1.4.2 int MF_HLWrite ( int DeviceAddress, unsigned char mode, unsigned char add_blk, unsigned char num_blk,
unsigned char *snr, unsigned char *buffer);
Parameter Description
15
RFID-M1 – API Programmer Guide
Description
Note: The blocks to be written must be in the same sector. Writing data to the sector trailer (block address = N*4+3,
where N is the sector number) should be handled carefully, otherwise you may corrupt the KEY area and lock the
sector.
1.4.3 int MF_HLInitVal ( int DeviceAddress, unsigned char mode, unsigned char sect_num, unsigned char *snr,
int value); 1
Parameter Description
Description
Initials the value block (Block 1) and the back-up block (Block 2) to the MIFARE® VALUE BLOCK format with the
initial value.
1.4.4 int MF_HLInc ( int DeviceAddress, unsigned char mode, unsigned char sect_num, unsigned char *snr, int
*value)
Parameter Description
1
For the functions MF_HLInitVal, MF_HLInc and MF_HLDec (High Level Value related commands), the
second block (Block 1) is used as the Value Block of the selected sector. The third block (Block 2) is used as the backup of
the value block and the first block (Block0) is free for use.
16
RFID-M1 – API Programmer Guide
The serial number of the card selected will be return by the snr after the function is called
successfully.
value The value to be increment.
The content of the value block will be returned after the increment is done.
Return 0x00 – Successful
(Refer the API return code for other values)
Description
Increase the value of a MIFARE® Value Block and also copy the value block to the backup block.
1.4.5 int MF_HLDec ( int DeviceAddress, unsigned char mode, unsigned char sect_num, unsigned char *snr, int
*value)
Parameter Description
Description
Decrease the value of a MIFARE® Value Block and also copy the value block to the backup block.
1.4.6 int MF_StoreKeyToEE(int DeviceAddress, unsigned char KeyAB, unsigned char Sector, unsigned char *Key)
Parameter Description
17
RFID-M1 – API Programmer Guide
Description
1.4.7 int MF_HLRequest ( int DeviceAddress, unsigned char mode, int &length, unsigned char *UID)
Parameter Description
Description
The MF_HLRequest command integrated the low level commands – Request, Anti-Collision – Select(AntiColl2-
Seledt2, AntiColl3-Select) to a single one-step operation.
18
RFID-M1 – API Programmer Guide
Parameter Description
Description
Note: the SetRDRBaudrate() modify the default baud rate stored in the reader’s internal EEPROM. The new setting
will not take effect until the next reset of the reader.
Note: Need to change the baud rate of the Host controller correspondly.
Parameter Description
Description
The SetDeviceAddress() function programs a device address to the reader. If the Enable Serial Number Checking
Flag is set, the correct Reader Serial Number must be submitted to program the device address.
Example
To program a new device address (0x04) to a reader whose current address is 0x01 and the serial number is
"12345678"
DeviceAddress=0x01;
unsigned char newAddress=0x04;
unsigned char mode=0x01;
if(SetDeviceAddress(DeviceAddress,newAddress,mode,"12345678") )
19
RFID-M1 – API Programmer Guide
{ //successful }
else
{ //Not successful }
Parameter Description
Description
Parameter Description
Description
Get the Device Address and the Serial Number from the reader.
Example
To program a new device address (0x04) to a reader whose current address is 0x01 and the serial number is
"12345678"
DeviceAddress=0x00;
int CurrentAddress;
char SerialNum[8];
if(!GetSerialNum(DeviceAddress,CurrentAddress,SerialNum))
{ //successful
CurrentAddress = 1,
SerialNum =”12345678”
}
else
{ //Not successful }
Parameter Description
20
RFID-M1 – API Programmer Guide
Description
Parameter Description
Description
Parameter Description
bit1 1 ----- Prompt from Buzzer and LED after successful read
bit4
Description
Set Wiegand Status of the reader, setting will be saved after power out.
Parameter Description
21
RFID-M1 – API Programmer Guide
bit1 1 ----- Prompt from Buzzer and LED after successful read
Description
Set Wiegand Status of the reader, setting will not be saved after power out.
Parameter Description
Description
Parameter Description
Description
Parameter Description
22
RFID-M1 – API Programmer Guide
Description
Parameter Description
Description
Parameter Description
Description
23
RFID-M1 – API Programmer Guide
2 Additional Information
<To be defined>
<To be defined>
24