unit declaredll;

interface
//system command
{***************************************************************
  FUNCTION:Get Dll Version(2Byte)
  RETURN:  SUCCESS -0
***************************************************************}
function lib_ver(Ver:word):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION: DES Encrypt
  PARAMETERS:
	szOut:  DES resulted data
	szIn:   encrypted data
	inlen:  encrypted data length 
	key:    key
	keylen: key length
		keylen = 8 -> des
		keylen = 16-> 3des
  RETURN: SUCCESS - 0
***************************************************************}
function des_encrypt(var szOut:byte; var szIn:Byte;inlen:word;var key:Byte;keylen:word):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION: DES decrypt
  PARAMETERS:
	szOut:  DES resulted data
	szIn:   encrypted data
	inlen:  encrypted data length 
	key:    key
	keylen: key length
		keylen = 8 -> des
		keylen = 16-> 3des
RETURN: SUCCESS - 0
***************************************************************}
function des_decrypt(var szOut:byte;var szIn:byte; inlen:word;var key:byte; keylen:word):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION: Initialize COM or TCP/IP
  PARAMETERS:
	port: Port Number(0~256)
        band: baudrate
  RETURN: SUCCESS - 0
  Note:
      	Uart Reader: (port >=0)&&)(port <= 255) ->COM
	Net Reader:  port = 256 ->TCP{IP(band -> configure number in "ipaddr.ini" file)
***************************************************************}
function rf_init_com(port:word;band:LongInt):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION: Initialize TCP{IP Port
  PARAMETERS:
	ipaddr: ip address(eg: 192.168.0.115) 
  	port:   net remote port(eg: 10002)
  RETURN:SUCCESS - 0
***************************************************************}
function rf_init_net(ipaddr:PChar; port:LongInt):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION: Close Reader
  PARAMETERS:
	icdev: device address
  RETURN:SUCCESS - 0
***************************************************************}
function rf_ClosePort(icdev:word):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION: Inialize device address
  PARAMETERS:
	icdev: device address
  RETURN:SUCCESS - 0
***************************************************************}
function rf_init_device_number(icdev:word):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION: Get device address
  PARAMETERS:
	icdev:device address
  RETURN:SUCCESS - 0      
***************************************************************}
function rf_get_device_number(var Icdev:word):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION: Get hardware version
  PARAMETERS:
	icdev: device address
        Version:version information
  RETURN:SUCCESS - 0
***************************************************************}
function rf_get_model(icdev:word; var Version:word):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION: Get serial number of hardware(8Byte) 
  PARAMETERS:
	icdev: device address
        Snr:   return serial number
  RETURN:SUCCESS - 0
***************************************************************}
function rf_get_snr(icdev:word;var Snr:byte):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION: Beep  
  PARAMETERS:
	icdev: device address
        msec:  beep time(unit : 10 ms)
  RETURN:SUCCESS - 0
***************************************************************}
function rf_beep(icdev:word;msec:byte):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION: select the type of card of reading
  PARAMETERS:
	icdev: device address
        type:  card type
  RETURN:SUCCESS - 0
  NOTE: 
	type='A':typeA card(mifare one¡¢mifareplus£¬ultralight and so on)
        type='B':TYPE_B(ISO14443-4TypeB)
        type='r':AT88RF020
        type='s':SR176
        type='1':ISO15693
***************************************************************}
function rf_init_type(icdev:word;type1:byte):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION: set the status of antenna   
  PARAMETERS:
	icdev: device address
        model: status of antenna
  RETURN:SUCCESS - 0
  Note:
	mode=0: turn off antenna
        mode=1: turn on antenna
***************************************************************}
function rf_antenna_sta(icdev:word; mode:byte):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION: LED Control  
  PARAMETERS:
	icdev: device address
        color: 0 ,turn off all LED
               1 ,turn on Red-LED
               2 ,turn on Green-LED
               3 ,turn on Yellow-LED
  RETURN:SUCCESS - 0
***************************************************************}
function rf_light(icdev:word;color:byte):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION: display data on digital-LED
  PARAMETERS:
	icdev: device address
        cDecodeModel: decode mode
        cDpPosition: position of dot(0~7)
        cDisplayData: data of displaying
  RETURN:SUCCESS - 0
  NOTE:
	cDecodeModel=0: display 7 segment data, it is not decode
        cDecodeModel=1: display number(0~9, 0x0A turn off data)

        cDecodeModel = 0 decode table:
        display		code
        '0'		0x7E
        '1'		0x30
        '2'		0x6D
        '3'		0x79
        '4'		0x33
        '5'		0x5B
        '6'		0x5F
        '7'		0x70
        '8'		0x7F
        '9'		0x7B
***************************************************************}
function rf_display(icdev:word; cDecodeModel:byte; cDpPosition:byte; var DisplayData:byte):integer;stdcall;external 'MasterRD.dll';

//Mifareone
{***************************************************************
  FUNCTION: Search the card accord with ISO14443 TYPE_A
  PARAMETERS:
	icdev:  device address
        model:  request mode
        TagType:type of requested card
  RETURN:SUCCESS - 0
  NOTE:
       mode=0x26: request not halted card in antenna(REQA)
       mode=0x52: request all card in antenna(WUPA)
***************************************************************}
function rf_request(icdev:word; mode:byte; var TagType:word):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION:ISO14443-3 TYPE_A card defend collide(only for cascade Level1)
  PARAMETERS:
	icdev:  device address
        bcnt:   length of inputted data
        pSnr:   inputted data
        pRLength:length of returned data
 RETURN:SUCCESS - 0
***************************************************************}
function rf_anticoll(icdev:word; bcnt:byte; var pSnr:byte;var pRLength:byte):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION:ISO14443-3 TYPE_A card defend collide(all cascade Level)  
  PARAMETERS:
	icdev: device address
        CLn:   cascade Level
           0x01:Level1
           0x02:Level2
           0x03:Level3
  	pSnr:   returned data
  RETURN:SUCCESS - 0
***************************************************************}
function rf_anticollCLn(icdev:word; CLn:byte; var pSnr:byte):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION: select card accord with ISO14443 TYPE_A(Only for cascade Level1)
  PARAMETERS:
	icdev: device address
        pSnr: card serial number
        srcLen: length of serial number(if the card is mifareone, then srcLen equal 4)
        Size: size of the carde
  RETURN:SUCCESS - 0
***************************************************************}
function rf_select(icdev:word;var pSnr:byte; srcLen:byte;var Size:byte):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION:select card accord with ISO14443 TYPE_A(all cascade Level)
  PARAMETERS:
	icdev: device address
        CLn:   cascade Level
           0x01:Level1
           0x02:Level2
           0x03:Level3
        pSnr: card serial number
        srcLen: length of serial number(if the card is mifareone, then srcLen equal 4)
        Size: size of the carde
  RETURN:SUCCESS - 0
***************************************************************}
function rf_selectCLn(icdev:word; CLn:byte; var pSnr:byte;var Size:byte):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION: Search card accord with ISO14443 TYPEA
  PARAMETERS:
	icdev: device address
        cModel:request mode
        pData: Returned data
        pLen:  length of returned data
        pUidLength: ength of UID
  RETURN:SUCCESS - 0
  NOTE:
  	1.mode=0x26:request not halted card in antenna(REQA)
      	  mode=0x52:request all card in antenna(WUPA)
  	2.pData:ATQA)(2Byte)+SAK)(1Byte)+SNR)(4{7{10 Byte)
	3.The function include rquest¡¢anticollide and select card.
***************************************************************}
function rf_search_type_a(icdev:word; cModel:byte; var pData:byte; var pLen:byte; var pUidLength:byte):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION: let actived card into disactive
  PARAMETERS:
	icdev: device address
  RETURN:SUCCESS - 0
***************************************************************}
function rf_halt(icdev:word):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION: Load the key of mifareone into RC5XX EEPROM for save
  PARAMETERS:
	icdev:    device addres
        KeyIndex: index of key(0~31)
        key:      key(6byte)
  RETURN:SUCCESS - 0
***************************************************************}
function rf_download_key (icdev:word; KeyIndex:byte; var key:byte):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION: set the encrypted standard of miareone card
  PARAMETERS:
	icdev:   device addres
        cStandard:
            0x00: Philips standard
            0x01: SHANGHAI standard
  RETURN:SUCCESS - 0
***************************************************************}
function rf_set_authentication_standard(icdev:word; cStandard:word):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION: authenticate the mifareone card in the key saved in RC5XX EEPROM
  PARAMETERS:
	icdev: device addres
        model: authentication mode
        block: block number
        keyIndex:index of key saved in RC5XX EEPROM
  RETURN:SUCCESS - 0
  NOTE: 
	model=0x60: authenticate in key A
        model=0x61: authenticate in key B
***************************************************************}
function rf_M1_authentication1(icdev:word; mode:byte; block:byte; KeyIndex:byte):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION: authenticate the mifareone card in current key
  PARAMETERS:
	icdev: device address
        mode: authentication mode
        block:block number
        key:  key
  RETURN:SUCCESS - 0
  NOTE: 
	model=0x60: authenticate in key A
        model=0x61: authenticate in key B
***************************************************************}
function rf_M1_authentication2(icdev:word;mode:byte; block:byte;var key:byte):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION: read the block data from mifareone card
  PARAMETERS:
	icdev: device address
        block: block absolute address
        pData: returned data
	pLen:  length of returned data
  RETURN:SUCCESS - 0
***************************************************************}
function rf_M1_read(icdev:word; block:byte; var pData:byte; var pLen:byte):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION: write the block data to mifareone card
  PARAMETERS:
	icdev: device address
        block: block absolute address
        Data:  written data
  RETURN:SUCCESS - 0
***************************************************************}
function rf_M1_write(icdev:word; block:byte; var data:byte):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION: Initialize a block as a purse function in mifareone card
  PARAMETERS:
	icdev: device address
        block: block absolute address
        value: initiale value
  RETURN:SUCCESS - 0
***************************************************************}
function rf_M1_initval(icdev:word; block:byte; value:LongInt):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION: read purse value in mifareone card
  PARAMETERS:
	icdev: device address
        block: block absolute address
        pValue:purse value
  RETURN:SUCCESS - 0
***************************************************************}
function rf_M1_readval(icdev:word; block:byte; var pValue:LongInt):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION: decrement purse 
  PARAMETERS:
	icdev: device address
        block: block absolute address
        value: decreased value
  RETURN:SUCCESS - 0
***************************************************************}
function rf_M1_decrement(icdev:word; block:byte; value:LongInt):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION: increase purse
  PARAMETERS:
	icdev: device address
        block: absolute address of block
        value: increased value
  RETURN:SUCCESS - 0
***************************************************************}
function rf_M1_increment(icdev:word; block:byte; value:LongInt):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION: restore purse value to card buffer
  PARAMETERS:
	icdev: device address
        block: absolute address of block
  RETURN:SUCCESS - 0
***************************************************************}
function rf_M1_restore(icdev:word; block:byte):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION: transfer card buffer to purse block
  PARAMETERS:
	icdev: device address
        block: absolute address of block
  RETURN:SUCCESS - 0
***************************************************************}
function rf_M1_transfer(icdev:word; block:byte):integer;stdcall;external 'MasterRD.dll';

//UltraLight
{***************************************************************
  FUNCTION: select one Ultralight card
  PARAMETERS:
	icdev:device address
        pSnr: UltraLight serial number
        pLene:length of serial number
  RETURN:SUCCESS - 0
***************************************************************}
function rf_ul_select(icdev:word; var pSnr:byte;var pLen:byte):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION: write data to UltraLight
  PARAMETERS:
	icdev: device address
        page:  ultralight Page address(0¡«0x0f)
        data:  written data(4Btye)
  RETURN:SUCCESS - 0
***************************************************************}
function rf_ul_write(Wicdev:word; page:byte; var data:byte):integer;stdcall;external 'MasterRD.dll';

    //AT88F020
{***************************************************************
  FUNCTION: check AT88RF020 key
  PARAMETERS:
	icdev:device address
        key:  key(8Byte)
  RETURN:SUCCESS - 0
***************************************************************}
function rf_at020_check(icdev:word; var key:byte):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION: read the data of AT88RF020 card
  PARAMETERS:
	icdev:device address
	adr:  Page address(0¡«31)
	Date: returned page data(8Byte)
  RETURN:SUCCESS - 0
***************************************************************}
function rf_at020_read(icdev:word; adr:byte; var pData:byte; var pMsgLen:byte):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION: write the data of AT88RF020 card
  PARAMETERS:
	icdev:device address
        adr:  Page address(0¡«31)
        Date: written page data(8Byte)
  RETURN:SUCCESS - 0
***************************************************************}
function rf_at020_write(icdev:word; adr:byte; var data:byte):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION: write the lock register of AT88F020 card
  PARAMETERS:
	icdev:device address
        date: register data(4Byte)
  RETURN:SUCCESS - 0
***************************************************************}
function rf_at020_lock(icdev:word;var data:byte):integer;stdcall;external 'MasterRD.dll';

{*************************************************************** 
  FUNCTION:count
  PARAMETERS:
	icdev:device address
        date: data(6Byte)
  RETURN:SUCCESS - 0
***************************************************************}
function rf_at020_count(icdev:word;var data:byte):integer;stdcall;external 'MasterRD.dll';

{*************************************************************** 
  FUNCTION: deselect AT88RF020 card
  PARAMETERS:
	icdev:device address
  RETURN:SUCCESS - 0
***************************************************************}
function rf_at020_deselect(icdev:word):integer;stdcall;external 'MasterRD.dll';

{*************************************************************** 
  FUNCTION: Halt the card accord with ISO14443 TypeB
  PARAMETERS:
	icdev:device address
        PUPI: card PUPI
  RETURN:SUCCESS - 0
***************************************************************}
function rf_hltb(icdev:word;PUPI:word):integer;stdcall;external 'MasterRD.dll';

    //SR176
{***************************************************************
  FUNCTION:Initial and select ST card(SR176 or SRIX4K)
  PARAMETERS:
	icdev: device address
        Chip_ID: chip id
  RETURN:SUCCESS - 0
***************************************************************}
function rf_st_select(icdev:word; var pChip_ID:byte):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION: let ST card enter into desactive status
  PARAMETERS:
	icdev: device address
  RETURN:SUCCESS - 0
***************************************************************}
function rf_st_completion(icdev:word):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION: read datas of SR176 card
  PARAMETERS:
	icdev: device address
        block: block address
        pData: returned data
        pLen:  length of returned data
  RETURN:SUCCESS - 0
***************************************************************}
function rf_sr176_readblock(icdev:word; block:byte; var pData:byte;var pLen:byte):integer;stdcall;external 'MasterRD.dll';

{***************************************************************  
  FUNCTION: write datas of SR176 card
  PARAMETERS:
	icdev: device address
        block: block address
        data:  written data(2Byte)
  RETURN:SUCCESS - 0
***************************************************************}
function rf_sr176_writeblock(icdev:word; block:byte; var data:byte):integer;stdcall;external 'MasterRD.dll';

{***************************************************************  
  FUNCTION: write the lock register of SR176 card
  PARAMETERS:
	icdev: device address
        lockreg:LOCKREG
  RETURN:SUCCESS - 0
***************************************************************}
function rf_sr176_protectblock(icdev:word; lockreg:byte):integer;stdcall;external 'MasterRD.dll';

{***************************************************************  
  FUNCTION: get the lock register of SR176 card
  PARAMETERS:
	icdev:   device address
        lockreg: value of Lock register
  RETURN:SUCCESS - 0
***************************************************************}
function rf_sr176_getprotectreg(icdev:word; var lockreg:byte):integer;stdcall;external 'MasterRD.dll';

//SRIX4K
{***************************************************************  
  FUNCTION: read the datas of SRIX4K card
  PARAMETERS:
	icdev: device address
        block: block address
        pData: returned data
        pLen:  length of returned data
  RETURN:SUCCESS - 0
***************************************************************}
function rf_srix4k_readblock(icdev:word; block:byte; var pData:byte;var pLen:byte):integer;stdcall;external 'MasterRD.dll';

{*************************************************************** 
  FUNCTION: write the datas of SRIX4K card
  PARAMETERS:
	icdev: device address
        block: block address
        pData: written data(4Byte)
  RETURN:SUCCESS - 0
***************************************************************}
function rf_srix4k_writeblock(icdev:word; block:byte; var pData:byte):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION: authenticate SRIX4K card
  PARAMETERS:
	icdev:device address
        pData: RND(6Byte)
        pSIG:  signature
        pLen:  length of SIG
  RETURN:SUCCESS - 0
***************************************************************}
function rf_srix4k_authenticate(icdev:word; var pRND:byte; var pSIG:byte; var pLen:byte):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION: get SRIX4K UID
  PARAMETERS:
	icdev: device address
        pUID:  UID
        pLen:  length of UID
  RETURN:SUCCESS - 0
***************************************************************}
function rf_srix4k_getuid(icdev:word; var Puid:byte; var pLen:byte):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION: write lock register of SRIX4K card
  PARAMETERS:
	icdev: device address
        lockreg: LOCK register
***************************************************************}
function rf_srix4k_writelockreg(icdev:word; lockreg:byte):integer;stdcall;external 'MasterRD.dll';

//ISO14443
{*************************************************************** 
  FUNCTION: search and reset card accord with ISO14443-4 TypeA
  PARAMETERS: 
	icdev: device address
        model: request mode(0x26-REQA,0x52-WUPA)
        pData: returned data
	pMsgLg:length of returned data
  RETURN:SUCCESS - 0
***************************************************************}
function rf_typea_rst(icdev:word;model:byte;var pData:byte;var pMsgLg:byte):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION: send cos command to card accord with ISO14443 -TypeA{B
  PARAMETERS: 
	icdev:   device address
	command: cos command
	MsgLg:   length of returned data
	Date:    returned data include SW1 and SW2
  RETURN: SUCCESS - 0
***************************************************************}
function rf_cos_command(icdev:word; var command:byte;cmdLen:byte;var pData:byte;var pMsgLg:byte):integer;stdcall;external 'MasterRD.dll';

{*************************************************************** 
  FUNCTION: reset the card accord with ISO14443-4 TypeA
  PARAMETERS: 
	icdev:   device address
        pBuffer: returned data
	pLen:    length of resetting card
  RETURN:SUCCESS - 0
***************************************************************}
function rf_iso14443_4_type_a_reset(icdev:word; var pBuffer:byte; var pLen:byte):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION: Search and select card accord with ISO14443-TypeB
  PARAMETERS: 
	icdev: device address
	model: request mode(0-REQB,1-WUPB)
	pData: returned data
	MsgLg: length of returned data
  RETURN: SUCCESS - 0
***************************************************************}
function rf_atqb(icdev:word; model:byte; var pData:byte; var pMsgLg:byte):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION: attrib a card accord with ISO14443-TypeB
  PARAMETERS: 
	icdev:device address
        PUPI: card PUPI
        CID:  card CID(0~14)
  RETURN: SUCCESS - 0
***************************************************************}
function rf_attrib(icdev:word; PUPI:LongInt; CID:byte):integer;stdcall;external 'MasterRD.dll';

    //ISO15693
{***************************************************************
  FUNCTION:Inventory one tag accord with ISO15693
  PARAMETERS:
	icdev: device address
        Pdata: returned data(DSFID(1Byte)+UID(8Byte))
        pLen:  length of returned data
  RETURN:SUCCESS - 0
***************************************************************}
function ISO15693_Inventory(icdev:word;var pData:byte;var pLen:byte):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION: inventory multi-tags accord with ISO15693
  PARAMETERS:
	icdev: device address
	cAFIEnable: AFI enable flag
	AFI: AFI
        Pdata: returned data (1DSFID+8UID) * N
        pLen:  length of returned data
  RETURN:SUCCESS - 0
***************************************************************}
function ISO15693_MultiInventory(icdev:word; cAFIEnable:byte; AFI:byte; var pData:byte; var pLen:byte):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION: stay quiet tags accord with ISO15693
  PARAMETERS:
	icdev:device address
        UID:   UID(8Byte)
  RETURN:SUCCESS - 0
***************************************************************}
function ISO15693_Stay_Quiet(icdev:word; var UID:byte):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION: select tag
  PARAMETERS:
	icdev:device address
        UID:	 UID (8Byte)
  RETURN:SUCCESS - 0
***************************************************************}
function ISO15693_Select(icdev:word; var UID:byte):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION: reset tag to ready status
  PARAMETERS:
	icdev:device address
        model: bit0=Select_flags,bit1=Addres_flags
        UID:	 UID(8Byte)
  RETURN:SUCCESS - 0
***************************************************************}
function ISO15693_Reset_To_Ready(icdev:word; model:byte; var UID:byte):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION: read multi-block of tag
  PARAMETERS:
	icdev: device address
        model: bit0=Select_flags,bit1=Addres_flags
        UID:	 UID(8Byte)
        block: block address
        number:block number
        Pdata: returned data 
        pLen:  length of returned data
  RETURN:SUCCESS - 0
***************************************************************}
function ISO15693_Read(icdev:word; model:byte; var UID:byte; block:byte; number:byte;var Pdata:byte;var pLen:byte):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION: write one block of tag
  PARAMETERS:
	icdev: device address
        model: bit0=Select_flags,bit1=Addres_flags
        UID:   UID(8Byte)
        block: block address
        data:  written datas(4Byte)
  RETURN:SUCCESS - 0
***************************************************************}
function ISO15693_Write(icdev:word; model:byte; var UID:byte; block:byte; var data:byte):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION: lock block
  PARAMETERS:
	icdev: device address
        model: bit0=Select_flags,bit1=Addres_flags
        UID:   UID(8Byte)
        block: block address
  RETURN:SUCCESS - 0
***************************************************************}
function ISO15693_Lock_Block(icdev:word; model:byte; var UID:byte; block:byte):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION: write AFI flag
  PARAMETERS:
	icdev: device address
        model: bit0=Select_flags,bit1=Addres_flags
        UID:   UID(8Byte)
        AFI:   AFI
  RETURN:SUCCESS - 0
***************************************************************}
function ISO15693_Write_AFI(icdev:word; model:byte; var UID:byte; AFI:byte):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION: lock AFI flag
  PARAMETERS:
	icdev: device address
        model: bit0=Select_flags,bit1=Addres_flags
        UID:   UID(8Byte)
  RETURN:SUCCESS - 0
***************************************************************}
function ISO15693_Lock_AFI(icdev:word; model:byte; var UID:byte):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION:ISO15693_Write_DSFID
  PARAMETERS:
	icdev: device address
        model: bit0=Select_flags,bit1=Addres_flags
        UID:   UID(8Byte)
        DSFID: written DSFID
  RETURN:SUCCESS - 0
***************************************************************}
function ISO15693_Write_DSFID(icdev:word; model:byte; var UID:byte; DSFID:byte):integer;stdcall;external 'MasterRD.dll';

{*************************************************************** 
  FUNCTION: lock DSFID
  PARAMETERS:
	icdev: device address
        model: bit0=Select_flags,bit1=Addres_flags
        UID:   UID(8Byte)
  RETURN:SUCCESS - 0
***************************************************************}
function ISO15693_Lock_DSFID(icdev:word; model:byte; var UID:byte):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION: get system information
  PARAMETERS:
	icdev: device address
        model: bit0=Select_flags,bit1=Addres_flags
        UID:   UID(8Byte)
        Pdata: return data
        pLen:  length of returned data
  RETURN:SUCCESS - 0
***************************************************************}
function ISO15693_Get_System_Information(icdev:word; model:byte; var UID:byte; var Pdata:byte; var pLen:byte):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION: get the security status of tags
  PARAMETERS:
	icdev: device address
        model: bit0=Select_flags,bit1=Addres_flags
        UID:   UID(8Byte)
        block: block address
        number:block number(< 0x40)
        Pdata: returned data
        pLen:  length of returned data
  RETURN:SUCCESS - 0
***************************************************************}
function ISO15693_Get_Block_Security(icdev:word; model:byte; var UID:byte; block:byte; number:byte; var Pdata:byte; var pLen:byte):integer;stdcall;external 'MasterRD.dll';

    //ISO7816-SAM
{***************************************************************
  FUNCTION: Set sam baudrate by sam number
  PARAMETERS: 
	icdev: device address
	m_samNO: sam number(1~4)
        bound: sam baudrate
	 	0: 9600 
		1:19200 
		2:38400 
		3:55800 
		4:57600 
		5:76800 
		6:115200
  RETURN: SUCCESS - 0
  NOTE:
	1. Baudrate is 9600(default)
	2. Not at all baudrates are surpported by every kind of sam
***************************************************************}
function rf_init_sam_byid(icdev:word; m_samNo:byte; bound:byte):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION: reset sam by sam number
  PARAMETERS: 
	icdev: device address
        pData: return reseted information 
	m_samNo:SAM number(1~4)
        pMsgLg: length of returned information
  RETURN: SUCCESS - 0
***************************************************************}
function rf_sam_rst_byid(icdev:word; m_samNo:byte; var pData:byte;var pMsgLg:byte):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION: send cos command to sam by sam number  
  PARAMETERS: 
	icdev:   device address
	m_samNo: SAM number(1~4)
        command: cos command
        cmdLen:  length of sended cos command
        pDate:   returned data include SW1 and SW2
        pMsgLg:  length of returned data
  RETURN: SUCCESS - 0
***************************************************************}
function rf_sam_cos_byid(icdev:word; m_samNo:byte;var command:byte;cmdLen:byte;var pData:byte;var Length:byte):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION: set sam protocol by sam number 
  PARAMETERS: 
	icdev: device address
	m_samNo: SAM number(1~4)
        cProtocol: sam protocol
		0 £­ T0
		1 £­ T1
		0xFF £­ auto-select sam protocol based reset information(default)
  RETURN: SUCCESS - 0
***************************************************************}
function rf_sam_set_protocol_byid(icdev:word; m_samNo:byte; cProtocol:byte):integer;stdcall;external 'MasterRD.dll';

//MifarePlus
{***************************************************************
  FUNCTION: Level0 write perso
  PARAMETERS: 
	icdev: device address
	block: block address(2Byte)
	data:  written data(16Byte)
  RETURN: SUCCESS - 0
  NOTE: only Level0
***************************************************************}
function MFP_L0WritePerso(icdev:word; block:word;var data:byte):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION: Level0 Commit Perso
  PARAMETERS: 
	icdev: device address
  RETURN: SUCCESS - 0
  NOTE: 
	1¡¢only Level0
	2¡¢MifarePlus switch to Level1 or Level3 from Level0
	3¡¢before running the function, it must to be excuted that
           Maseter Key¡¢configure Key£¬switch2 key and switch3 key
	   are written to mifareplus using MFP_L0WritePerso function.
***************************************************************}
function MFP_L0CommitPerso(icdev:word):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION: switch mifareplus to Level2 or Level3
  PARAMETERS: 
	icdev: device address
        cLevel: dest-level
	switchkey: switch key(16Byte)
  RETURN: SUCCESS - 0
  NOTE: 
	1¡¢only Security Level1{2
***************************************************************}
function MFP_SwitchToHighLevel(icdev:word;cLevel:byte;var switchkey:byte):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION: Authenticate data block of mifare plus(not include configure¡¢KEY block and so on)
  PARAMETERS: 
	icdev: device address
        keytype: Key type('A' or 'B')
	blockid: block address
	keydata: AES key data(16Byte)
  RETURN: SUCCESS - 0
  NOTE: 
	1¡¢only Security Level3
***************************************************************}
function MFP_DataBlockAuthentication(icdev:word; keytype:byte; blockid:byte; var keydata:byte):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION: read data block of mifareplus
  PARAMETERS: 
	icdev:   device address
        blockid:    started block address
	blockcount: number of read block
	data:       read data
  RETURN: SUCCESS - 0
  NOTE: 
	1¡¢only Security Level3
***************************************************************}
function MFP_L3ReadDataBlock(icdev:word; blockid:byte; blockcount:byte; var data:byte):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION: write data to block(not configure¡¢key block and so on)of mifareplus
  PARAMETERS: 
	icdev:   device address
        blockid: started block addressr
	blockcount: number of written block
	data:    written data
  RETURN: SUCCESS - 0
  NOTE: 
	1¡¢only Security Level3
***************************************************************}
function MFP_L3WriteDataBlock(icdev:word; blockid:byte; blockcount:byte; var data:byte):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION: initialize a block of mifareplus as purse function
  PARAMETERS: 
	icdev:    device address
        blockid:  block address(1Byte)
	purseval: initial purse value
  RETURN: SUCCESS - 0
  NOTE: 
	1¡¢only Security Level3
***************************************************************}
function MFP_L3PurseInitial(icdev:word; blockid:byte; purseval:word):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION: read purse value of mifareplus
  PARAMETERS: 
	icdev:   device address
        blockid:  block address(1byte)
	purseval: purse value
  RETURN: SUCCESS - 0
  NOTE: 
	1¡¢only Security Level3
***************************************************************}
function MFP_L3PurseRead(icdev:word; blockid:byte; var purseval:word):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION: increase purse value 0f mifareplus
  PARAMETERS: 
	icdev:   device address
        blockid:  block address(1byte)
	purseval: purse value
  RETURN: SUCCESS - 0
  NOTE: 
	1¡¢only Security Level3
***************************************************************}
function MFP_L3PurseIncrement(icdev:word; blockid:byte; purseval:word):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION: decrease purse value of mifareplus
  PARAMETERS: 
	icdev:   device address
        blockid:  block address(1byte)
	purseval: purse value
  RETURN: SUCCESS - 0
  NOTE: 
	1¡¢only Security Level3
***************************************************************}
function MFP_L3PurseDecrement(icdev:word; blockid:byte; purseval:word):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION: backup purse value of mifareplus
  PARAMETERS: 
	icdev:            device address
        sourceblockid:    source purse block
	destnationblockid:dest purse block
  RETURN: SUCCESS - 0
  NOTE: 
	1¡¢only Security Level3
***************************************************************}
function MFP_L3PurseBackup(icdev:word; sourceblockid:byte; destnationblockid:byte):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION: first authentication to mifareplus
  PARAMETERS: 
	icdev:       device address
        AES_keyaddr: the block address of AES Key
	AES_keydata: AES key data
  RETURN: SUCCESS - 0
  NOTE: 
	1¡¢only Security Level1{3
***************************************************************}
function MFP_FirstAuthentication(icdev:word; AES_keyaddr:word; var AES_keydata:byte):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION: following authentication to mifareplus
  PARAMETERS: 
	icdev:       device address
        AES_keyaddr: the block address of AES Key
	AES_keydata: AES key data
  RETURN: SUCCESS - 0
  NOTE: 
	1¡¢only Security Level1{3
***************************************************************}
function MFP_FollowingAuthentication(icdev:word; AES_keyaddr:word; var AES_keydata:byte):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION:  read block of MifarePlus card(data¡¢configure¡¢key block and so on)
  PARAMETERS: 
	icdev:     device address
        blockid:   the started block address
	blockcount:number of block
	data:	   returned data
  RETURN: SUCCESS - 0
  NOTE: 
	1¡¢only Security Level3
***************************************************************}
function MFP_L3CommonRead(icdev:word; blockid:word; blockcount:byte; var data:byte):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION: write block of MifarePlus card(data¡¢configure¡¢key block and so on)
  PARAMETERS: 
	icdev:      device address
        blockid:    the started block address
	blockcount: number of block
	data:	    returned data
  RETURN: SUCCESS - 0
  NOTE: 
	1¡¢only Security Level3
***************************************************************}
function MFP_L3CommonWrite(icdev:word; blockid:word; blockcount:byte; var data:byte):integer;stdcall;external 'MasterRD.dll';

//Flash
{***************************************************************
  FUNCTION: read data of flash in reader
  PARAMETERS:
	icdev:  device address
        iBlock: block address
        cStartAddress: started byte address in a block
        cBytes: number of read data
        pData:  read data
  RETURN:SUCCESS - 0
***************************************************************}
function rf_flash_read(icdev:word; iBlock:word; cStartAddress:byte; cBytes:byte; var pData:byte):integer;stdcall;external 'MasterRD.dll';

{***************************************************************
  FUNCTION: read data of flash in reader
  PARAMETERS:
	icdev:  device address
        iBlock: block address
        cStartAddress: started byte address in a block
        cBytes: number of read data
        pData:  read data
  RETURN:SUCCESS - 0
***************************************************************}
function rf_flash_write(icdev:word; iBlock:word; cStartAddress:byte; cBytes:byte; var WriteData:byte):integer;stdcall;external 'MasterRD.dll';

implementation

end.
