NFC Mifare Library Manual (Version 1.01)

CASIO Computer Co., Ltd. Copyright ©2012. All rights reserved. February 2012

Table of the Contents Chapter 1. Chapter 2. Chapter 3. 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 3.10 3.11 3.12 3.13 3.14 3.15 3.16 3.17 3.18 Chapter 4. 4.1 4.1.1 4.1.2 4.2 4.3

Editorial Record Overview Operation Environment Functions List NFCMifareOpen NFCMifareClose NFCMifarePolling NFCMifareStopPolling NFCMifareGetCardResponse NFCMifareRadioOff NFCMifareAuthentication NFCMifareRead NFCMifareWrite NFCMifareWrite4 NFCMifareValue NFCMifareSetEventNotification NFCMifareGetEventNotification NFCMifareSetAutoRadioOff NFCMifareGetAutoRadioOff NFCMifareSetPollingMode NFCMifareGetPollingMode NFCMifareGetCardResponseEx Notes to Programming Notification for Radio Wave Stop Using Window Message Notification Using Event Notification Communication with Mifare Cards About search method

3 4 5 6 9 10 11 13 14 16 17 19 21 23 25 27 28 29 30 31 33 34 37 37 37 40 43 44

No part of this document may be produced or transmitted in any form or by any means, electronic or mechanical, for any purpose, without the express written permission of CASIO Computer Co., Ltd. in Tokyo Japan. Information in this document is subject to change without advance notice. CASIO Computer Co., Ltd. makes no representations or warranties with respect to the contents or use of this manual and specifically disclaims any express or implied warranties of merchantability or fitness for any particular purpose. © 2012 CASIO Computer Co., Ltd. All rights reserved. 2

Editorial Record Manual Version no. 1.00

Date edited

Page

Content

May 2010

Original DT-X8, IT-9000 is added. In Chapter 3.16,NFCMifareSetPollingMode function is added. In Chapter 3.16,NFCMifareGetPollingMode function is added. In Chapter 3.18,NFCMifareGetCardResponseEx function is added. In Chapter 4.3,”About search method“ is added. In Chapter 1,Overview explanation is corrected. In Chapter 3,Functions List explation is added.

all 31 33 1.01

February 2012 34 44 4 7 to 8

3

1. Overview The Near Field Communication (NFC) Mifare Library provides functions for communicating with MIFARE contactless smart cards. When accessing MIFARE card using NFC Library, your application needs to create MIFARE command by itself, and needs to transmit it to MIFARE card. NFC Mifare Library creates MIFARE command instead of your application, and supports access to MIFARE card. When the smart cards in question belong exclusively to the MIFARE card system, applications can be developed more efficiently using the NFC Mifare Library rather than the NFC Library. Using the NFC Mifare Library enables enhanced application source code compatibility without the need to be mindful of the terminal model. Regardless of the model of handheld terminal, the NFC Mifare Library provides all of the functions as well as the behavior of a 'virtual machine' from the perspective of the application. Each of the NFC Mifare Library functions returns an unsupported function error (FUNCTION_UNSUPPORT) when the subject device function cannot be controlled in response to a request from the application. In addition, configuring a parameter which is not available due to a difference in the functions of the equipped device will result in a parameter error being returned. The NFC Mifare Library is designed to enhance the compatibility of application source codes and is not intended to ensure compatibility of the equipped device functions. Please therefore be sure to correctly judge unsupported function and parameter errors and notify the operator that the function is not supported or, alternatively, invalidate the process altogether.

4

2. Operation Environment Applicable Handheld Terminals • IT-800 series • DT-X8 series • IT-9000 series

OS • Microsoft® WindowsCE 6.0 • Microsoft® Windows Mobile® 6.5

IDE and Programming Languages Table 2.1 Integrated Development Environment (IDE)

Visual C++

Microsoft Visual Studio 2005 + SP1 Microsoft Visual Studio 2008 + SP1

Y Y

Visual Basic, Visual C# Y Y

Provided files Table 2.2 File

Visual C++

NFCMifareLib.h NFCMifareLib.lib NFCMifareLib.dll NFCMifareLibNet.dll

Y Y Y -

Visual Basic, Visual C# Y Y

How to Use the Library When using Visual C++ • Include NFCMifareLib.h and NFCLib.h within the program source and designate NFCMifareLib.lib as the linker dependent file. • NFCMifareLib.dll is stored within the handheld terminal.

When using Visual Basic or Visual C# • Add reference NFCMifareLibNet.dll into project. • NFCMifareLib.dll is stored within the handheld terminal. • Copy NFCMifareLibNet.dll into same folder with execute module.

5

3. Functions List The following functions are provided by the NFC Mifare Library.

NFCMifareOpen NFCMifareClose NFCMifarePolling NFCMifareStopPolling NFCMifareGetCardResponse NFCMifareRadioOff NFCMifareAuthentication NFCMifareRead NFCMifareWrite NFCMifareWrite4 NFCMifareValue NFCMifareSetEventNotification NFCMifareGetEventNotification NFCMifareSetAutoRadioOff NFCMifareGetAutoRadioOff NFCMifareSetPollingMode NFCMifareGetPollingMode NFCMifareGetCardResponseEx

Description

Sets up NFC driver in communication permit state and turns on NFC device power. Sets up NFC driver in communication prohibit state and turns off NFC device power. Searches MIFARE cards located in the communication range and retrieves their UID. Terminates search MIFARE cards located in communication range. Retrieves detailed information about activated MIFARE cards. Terminates radio wave transmission. Carries out access authorization using a key check. Reads specified address data (16 bytes). Writes data to a specified address (16 bytes). Writes data to a specified address (4 bytes). Calculates data for a specified address. Sets up timing notification method for radio wave automatic stop. Retrieves timing notification method for radio wave automatic stop. Sets up a period of time until when radio wave is automatically stopped. Retrieves a period of time until when radio wave is automatically stopped. Sets up IC card search method. Retrieves IC card search method. Retrieves detailed information of activated smart card.

Y: Function supported - : Function not supported

6

IT-9000

Function

DT-X8

Security functions IT-800

Table 3.1

Y

Y

Y

Y

Y

Y

Y

Y

Y

Y

Y

Y

Y

Y

Y

Y

Y

Y

Y

Y

Y

Y Y Y Y

Y Y Y Y

Y Y Y Y

Y

Y

Y

Y

Y

Y

Y

Y

Y

Y

Y

Y

-

Y Y

Y Y

-

Y

Y

Function call procedure 1. When initiating the application, carry out NFCMifareOpen function to turn on the NFC device. See note. 2. When initiating communication process, carry out NFCMifarePolling function to search Mifare card and activate it that is located in the communication range. 3. When you have successfully activated the Mifare card and if you require to retrieve its detailed information, carry out NFCMifareGetCardResponse function to retrieve the card response information (at your will). 4. Initiate communication with the Mifare card. See next page. 5. When communication with the Mifare card is complete, carry out NFCMifareRadioOff function to terminate radio wave output. 6. When closing the application, carry out NFCMifareClose function to turn off the NFC device.

NFCMifarePolling

Response received from card?

No

Yes NFCMifareGet CardResponse

Communication with Card

NFCMifareOpen

At application launch

NFCMifareRadioOff

When communicating with MIFARE card

NFCMifareClose

At application close

Note: Since NFC device goes to standby mode while not communicating with MIFARE card, electric power is hardly used.

7

Communication with Card 1. Carry out NFCMifareAuthentication function to authorize access to Mifare card. 2. Carry out either NFCMifareRead, NFCMifareWrite or NFCMifareValue function. 3. To continue process and change the sector to other sectors, return to Step 1 and repeat the process. 4. To continue process but not to change the sector, return to Step 2 and repeat the process.

NFCMifareAuthentication

NFCMifareRead NFCMifareWrite NFCMifareValue

Process End?

Yes

No No

Sector change? Yes

8

3.1 NFCMifareOpen This function sets up the NFC driver in communication permit state (open state) and turns on the NFC device power. While the state is being kept effect, communication starts as soon as NFCMifarePolling function is carried out. This state remains until when NFCMifareClose function is carried out. Calling Sequence [C++] int NFCMifareOpen( HWND hWnd ) [Visual Basic] Public Shared Function NFCMifareOpen( ByVal hWnd As IntPtr_ ) As Int32 [C#] Public static Int32 NFCMifareOpen( IntPtr hWnd )

Parameters hWnd Specifies the application window handle. A message is sent to the specified window handle when the radio wave automatic stop is set effect and the event notification method is set to 'message'. If 'NULL' is set in this parameter the message is sent to 'BROADCAST'. Return Values The following values are returned. NFC_OK : Normal termination NFC_PON : The NFC driver is being opened. See note. : NFC driver error. In the Device Emulator, the value is not NFC_NOT_DEVICE returned. : No response from the module. In the Device Emulator, the value NFC_ERROR_MODULE is not returned. Note: If NFCMifareOpen function is carried out twice or more in the same process, the function returns NFC_OK.

9

3.2 NFCMifareClose This function sets the NFC driver in communication prohibit state (close state) and turns off the NFC device power. Calling Sequence [C++] int NFCMifareClose() [Visual Basic] Public Shared Function NFCMifareClose() As Int32 [C#] Public static Int32 NFCMifareClose()

Parameters None Return Values The following values are returned. NFC_OK : Normal termination NFC_NOT_DEVICE : NFC driver error. In the Device Emulator, the value is not returned.

10

3.3 NFCMifarePolling This function searches Mifare cards that are located in the communication range. When the function detects a Mifare card, it activates the card for data communication. The function continues to search Mifare cards that are located in the communication range until either it detects a Mifare card, the specified timeout elapses, or the specified callback function returns 'FALSE'. In the Device Emulator, the function checks parameters only. Calling Sequence [C++] int NFCMifarePolling( DWORD dwTimeout, BOOL (*fpCallBack)(void), DWORD dwReserved ) [Visual Basic] Public Shared Function NFCMifarePolling( ByVal dwTimeout As Int32, _ ByVal fpCallBack As IntPtr, _ ByVal dwReserved As Int32, _ ) As Int32 [C#] Public static Int32 NFCMifarePolling( Int32 dwTimeout, IntPtr fpCallBack, Int32 dwReserved )

Parameters dwTimeout Specifies a period of time in the range of 100 to 60,000 (milliseconds) for timeout starting from when a Mifare card is found and until when the card is initiated. If '0' is set in this parameter, the function searches Mifare cards without spending time period of the timeout. fpCallBack Specifies the callback function that determines whether searching Mifare cards should be continued or not. When the callback function returns 'TRUE' the search process is continued, or the process is terminated when it returns 'FALSE'. Specifying “NULL” in this parameter continues the search process irrespective of the return value. dwReserved This parameter is not supported in the current version. Specify '0'. 11

Return Values The following values are returned. NFC_OK : Normal termination : NFC driver error. In the Device Emulator, the value is not NFC_NOT_DEVICE returned. NFC_POF : Unopened error NFC_PRM : Parameter error : Timeout error. In the Device Emulator, the value is not NFC_ERROR_TIMEOUT returned. : Callback function error. In the Device Emulator, the value is NFC_ERROR_CALLBACK not returned. : No response from the module. In the Device Emulator, the NFC_ERROR_MODULE value is not returned. : Suspend error caused by the stop function. In the Device NFC_ERROR_STOP Emulator, the value is not returned.

12

3.4 NFCMifareStopPolling This function stops searching Mifare cards that are located in the communication range. Carrying out NFCMifareStopPolling function can stop searching Mifare cards if NFCMifarePolling function is carried out without specifying the callback function. Calling Sequence [C++] int NFCMifareStopPolling() [Visual Basic] Public Shared Function NFCMifareStopPolling() As Int32 [C#] Public static Int32 NFCMifareStopPolling()

Parameters None Return Values The following values are returned. NFC_OK : Normal termination NFC_NOT_DEVICE : NFC driver error. In the Device Emulator, the value is not returned. NFC_POF : Unopened error

13

3.5 NFCMifareGetCardResponse This function retrieves response information about activated Mifare cards. The function can retrieve response information after NFCMifarePolling function has been carried out. The response information is stored once in the driver upon successful activation of Mifare card. The function then retrieves the information from the driver. In the Device Emulator, the function checks parameters only. Calling Sequence [C++] int NFCMifareGetCardResponse( BYTE *pATQ, BYTE *pSAK, BYTE *pUid, BYTE *pUidLen, DWORD dwReserved ) [Visual Basic] Public Shared Function NFCFelicaGetCardResponse( ByVal pATQ As Byte(), _ ByVal pSAK As Byte(), _ ByVal pUid As Byte(), _ ByVal pUidLen As Byte(), _ ByVal dwReserved As Int32, _ ) As Int32 [C#] Public static Byte[] Byte[] Byte[] Byte[] Int32 )

Int32 NFCFelicaGetCardResponse( pATQ, pSAK, pUid, pUidLen, dwReserved

Parameters pATQ Retrieves ATQ from successfully activated Mifare card. Specify a pointer with 2 bytes area. pSAK Retrieves SAK from successfully activated Mifare card. Specify a pointer with 1 byte area. pUid Retrieves Uid from successfully activated Mifare card. Specify a pointer with 7 bytes area. 14

pUidLen Retrieves the length of Uid from successfully activated Mifare card. “4” is retrieved for Mifare standard cards, or “7” for Mifare Ultralight cards. Specify a pointer with 1 byte. dwReserved This parameter is not supported in the current version. Specify '0'. Return Values The following values are returned. NFC_OK : Normal termination NFC_NOT_DEVICE : NFC driver error. In the Device Emulator, the value is not returned. NFC_POF : Unopened error NFC_PRM : Parameter error

15

3.6 NFCMifareRadioOff This function terminates radio wave transmission by the NFC module. Calling Sequence [C++] int NFCMifareRadioOff() [Visual Basic] Public Shared Function NFCMifareRadioOff() As Int32 [C#] Public static Int32 NFCMifareRadioOff()

Parameters None Return Values The following values are returned. NFC_OK : Normal termination : NFC driver error. In the Device Emulator, the value is not NFC_NOT_DEVICE returned. NFC_POF : Unopened error : No response from the module. In the Device Emulator, the value NFC_ERROR_MODULE is not returned.

16

3.7 NFCMifareAuthentication This function authorizes access with a key check. First, the function compares the key information recorded in the specified block (Sector Trailer) in activated Mifare card (Standard) with the specified key information. If both information match, the function permits access to a sector in which the block belongs to. To access to other sectors, checking a key for each sector must be performed. In the Device Emulator, the function checks parameters only. Calling Sequence [C++] int NFCMifareAuthentication( DWORD dwMode, BYTE *pKey, DWORD dwBlockNumber, DWORD dwTimeout ) [Visual Basic] Public Shared Function NFCMifareAuthentication( ByVal dwMode As Int32, _ ByVal pKey As Byte(), _ ByVal dwBlockNumber As Int32, _ ByVal dwReserved As Int32 _ ) As Int32 [C#] Public static Int32 Byte[] Int32 Int32 )

Int32 NFCMifareAuthentication( dwMode, pKey, dwBlockNumber, dwReserved

Parameters dwMode Specifies either one of the keys below to compare with key in specified block. NFC_MIFARE_KEYA : Compare with Key A NFC_MIFARE_KEYB : Compare with Key B pKey Specifies a key. (6 bytes). dwMode Specifies the block number that stores key. 17

Standard1k Standard4k

: 0 to 63 : 0 to 255

dwReserved This parameter is not supported in the current version. Specify '0'. Return Values The following values are returned. NFC_OK : Normal termination : NFC driver error. In the Device Emulator, the value is not NFC_NOT_DEVICE returned. NFC_POF : Unopened error NFC_PRM : Parameter error NFC_ERROR_TIMEOUT : Timeout error : Card not activated error. In the Device Emulator, the value is NFC_NOT_ACTIVATION not returned. : No response from the module. In the Device Emulator, the NFC_ERROR_MODULE value is not returned. : Terminal OFF error. In the Device Emulator, the value is not NFC_ERROR_SUSPEND returned. : Radio wave automatic stop error. In the Device Emulator, the NFC_ERROR_AUTOOFF value is not returned. Memory Configuration of Mifare Standard In case of “Standard1k”, it consists of 64 sectors, and each sector configures with 4 blocks (1 block = 16 bytes). Of these 4 blocks, the first block is Sector Trailer which stores keys. The rest are data blocks to store data.

18

3.8 NFCMifareRead This function reads data from activated Mifare card (Standard, Ultralight). In the Device Emulator, the function checks parameters only. Calling Sequence [C++] int NFCMifareRead( DWORD dwBlockNumber, BYTE *pData, DWORD dwReserved ) [Visual Basic] Public Shared Function NFCMifareRead( ByVal dwBlockNumber As Int32, _ ByRef pData As Byte(), _ ByVal dwReserved As Int32 _ ) As Int32 [C#] Public static Int32 Byte[] Int32 )

Int32 NFCMifareRead( dwBlockNumber, pData, dwReserved

Parameters dwBlockNumber Specifies address in the range below where data are stored. Standard1k : 0 to 63 Standard4k : 0 to 255 Ultralight : 0 to 15 pData Retrieves read data. Specify a pointer with 16 bytes. dwReserved This parameter is not supported in the current version. Specify '0'.

19

Return Values The following values are returned. NFC_OK : Normal termination : NFC driver error. In the Device Emulator, the value is not NFC_NOT_DEVICE returned. NFC_POF : Unopened error NFC_PRM : Parameter error NFC_ERROR_TIMEOUT : Timeout error : Card not activated error. In the Device Emulator, the value is NFC_NOT_ACTIVATION not returned. : No response from the module. In the Device Emulator, the NFC_ERROR_MODULE value is not returned. : Terminal OFF error. In the Device Emulator, the value is not NFC_ERROR_SUSPEND returned. : Radio wave automatic stop error. In the Device Emulator, the NFC_ERROR_AUTOOFF value is not returned.

20

3.9 NFCMifareWrite This function writes data to activated Mifare card (Standard). In the Device Emulator, the function checks parameters only. Calling Sequence [C++] int NFCMifareWrite( DWORD dwBlockNumber, BYTE *pData, DWORD dwReserved ) [Visual Basic] Public Shared Function NFCMifareWrite( ByVal dwBlockNumber As Int32, _ ByRef pData As Byte(), _ ByVal dwReserved As Int32 _ ) As Int32 [C#] Public static Int32 Byte[] Int32 )

Int32 NFCMifareWrite( dwBlockNumber, pData, dwReserved

Parameters dwBlockNumber Specifies address in the range below to write data. Standard1k : 0 to 63 Standard4k : 0 to 255 pData Specifies data to write. Specify a pointer with 16 bytes area. dwReserved This parameter is not supported in the current version. Specify '0'.

21

Return Values The following values are returned. NFC_OK : Normal termination : NFC driver error. In the Device Emulator, the value is not NFC_NOT_DEVICE returned. NFC_POF : Unopened error NFC_PRM : Parameter error NFC_ERROR_TIMEOUT : Timeout error : Card not activated error. In the Device Emulator, the value is NFC_NOT_ACTIVATION not returned. : No response from the module. In the Device Emulator, the NFC_ERROR_MODULE value is not returned. : Terminal OFF error. In the Device Emulator, the value is not NFC_ERROR_SUSPEND returned. : Radio wave automatic stop error. In the Device Emulator, the NFC_ERROR_AUTOOFF value is not returned.

22

3.10 NFCMifareWrite4 This function writes data into activated Mifare card (Ultralight). In the Device Emulator, the function checks parameters only. Calling Sequence [C++] int NFCMifareWrite4( DWORD dwBlockNumber, BYTE *pData, DWORD dwReserved ) [Visual Basic] Public Shared Function NFCMifareWrite4( ByVal dwBlockNumber As Int32, _ ByRef pData As Byte(), _ ByVal dwReserved As Int32 _ ) As Int32 [C#] Public static Int32 Byte[] Int32 )

Int32 NFCMifareWrite4( dwBlockNumber, pData, dwReserved

Parameters dwBlockNumber Specifies address in the range below to write data. Ultralight : 0 to 15 pData Specifies data to write. Specify a pointer with 16 bytes area. dwReserved This parameter is not supported in the current version. Specify '0'.

23

Return Values The following values are returned. NFC_OK : Normal termination : NFC driver error. In the Device Emulator, the value is not NFC_NOT_DEVICE returned. NFC_POF : Unopened error NFC_PRM : Parameter error NFC_ERROR_TIMEOUT : Timeout error : Card not activated error. In the Device Emulator, the value is NFC_NOT_ACTIVATION not returned. : No response from the module. In the Device Emulator, the NFC_ERROR_MODULE value is not returned. : Terminal OFF error. In the Device Emulator, the value is not NFC_ERROR_SUSPEND returned. : Radio wave automatic stop error. In the Device Emulator, the NFC_ERROR_AUTOOFF value is not returned.

24

3.11 NFCMifareValue This function retrieves data from activated Mifare card (Standard) and then carries out a specified calculation (addition, subtraction, and block copy). It writes a result of the calculation into specified address. The function requires “Value Block” for the object memory area. In the Device Emulator, the function checks parameters only. Calling Sequence [C++] int NFCMifareValue( DWORD dwMode, DWORD dwBlockNumber, BYTE *pValue, DWORD dwTransBlock, DWORD dwReserved ) [Visual Basic] Public Shared Function NFCMifareValue( ByVal dwMode As Int32, _ ByVal dwBlockNumber As Int32, _ ByRef pData As Byte(), _ ByVal dwTransBlock As Int32 _ ByVal dwReserved As Int32 _ ) As Int32 [C#] Public static Int32 Int32 Byte[] Int32 Int32 )

Int32 NFCMifareValue( dwMode, dwBlockNumber, pData, dwTransBlock, dwReserved

Parameters dwMode Specifies calculation mode. NFC_MIFARE_INCREMENT : Addition NFC_MIFARE_DECREMENT : Subtraction NFC_MIFARE_RESTORE : Block copy dwBlockNumber Specifies address in the range below where original data for calculation is stored. Standard1k : 0 to 63 25

Standard4k

: 0 to 255

pValue Specifies value to be used in the calculation. Specify a pointer with 4 bytes area. dwTransBlock Specify address in the range below to write calculation result. Standard1k : 0 to 63 Standard4k : 0 to 255 dwReserved This parameter is not supported in the current version. Specify '0'. Return Values The following values are returned. NFC_OK : Normal termination : NFC driver error. In the Device Emulator, the value is not NFC_NOT_DEVICE returned. NFC_POF : Unopened error NFC_PRM : Parameter error NFC_ERROR_TIMEOUT : Timeout error : Card not activated error. In the Device Emulator, the value is NFC_NOT_ACTIVATION not returned. : No response from the module. In the Device Emulator, the NFC_ERROR_MODULE value is not returned. : Terminal OFF error. In the Device Emulator, the value is not NFC_ERROR_SUSPEND returned. : Radio wave automatic stop error. In the Device Emulator, the NFC_ERROR_AUTOOFF value is not returned.

26

3.12 NFCMifareSetEventNotification This function sets up timing notification method for the radio wave automatic stop. • Window message notification The message is sent to the window handle that specifies the window message of 'WM_NFC_AUTORADIOOFF( WM_USER + 0x580 )'. • Event notification The event issued when the radio wave is automatically stopped is 'NFCEventAutoRadioOff'. In Windows CE operating system, specify TEXT('NFCEventAutoRadioOff') in program because names are formed in Unicode. Calling Sequence [C++] int NFCMifareSetEventNotification( DWORD dwMode ) [Visual Basic] Public Shared Function NFCMifareSetEventNotification( ByVal dwMode As Int32 _ ) As Int32 [C#] Public static Int32 NFCMifareSetEventNotification( Int32 dwMode )

Parameters dwMode Specifies timing notification method for the radio wave automatic stop. NFC_DISABLE : Notification disabled (default) NFC_MESSAGE : Window message notification NFC_EVENT : Event notification Return Values The following values are returned. NFC_OK : Normal termination NFC_NOT_DEVICE : NFC driver error. In the Device Emulator, the value is not returned. NFC_POF : Unopened error NFC_PRM : Parameter error

27

3.13 NFCMifareGetEventNotification This function retrieves the timing notification method for the radio wave automatic stop. Calling Sequence [C++] int NFCMifareGetEventNotification( DWORD *pMode ) [Visual Basic] Public Shared Function NFCMifareGetEventNotification( ByRef pMode As Int32 _ ) As Int32 [C#] Public static Int32 NFCMifareGetEventNotification( ref Int32 pMode )

Parameters pMode Retrieves the timing notification method for the radio wave automatic stop. Refer to NFCMifareSetEventNotification function for the values to retrieve. Return Values The following values are returned. NFC_OK : Normal termination NFC_NOT_DEVICE : NFC driver error. In the Device Emulator, the value is not returned. NFC_POF : Unopened error NFC_PRM : Parameter error

28

3.14 NFCMifareSetAutoRadioOff This function sets up a period of time until when transmission of radio wave is automatically stopped. Calling Sequence [C++] int NFCMifareSetAutoRadioOff( DWORD dwTimeout ) [Visual Basic] Public Shared Function NFCMifareSetAutoRadioOff( ByVal dwTimeout As Int32 _ ) As Int32 [C#] Public static Int32 NFCMifareSetAutoRadioOff( Int32 dwTimeout )

Parameters Timeout Specifies a period of time in the range of 100 to 60,000 (milliseconds) until when transmission of radio wave is automatically stopped. The default is 1,000. Specifying “0” in this parameter disables the radio wave automatic stop. Return Values The following values are returned. NFC_OK : Normal termination NFC_NOT_DEVICE : NFC driver error. In the Device Emulator, the value is not returned. NFC_POF : Unopened error NFC_PRM : Parameter error

29

3.15 NFCMifareGetAutoRadioOff This function retrieves the time period until when transmission of radio wave is stopped automatically. Calling Sequence [C++] int NFCMifareGetAutoRadioOff( DWORD *pTimeout ) [Visual Basic] Public Shared Function NFCMifareGetAutoRadioOff( ByRef pTimeout As Int32 _ ) As Int32 [C#] Public static Int32 NFCMifareGetAutoRadioOff( ref Int32 pTimeout )

Parameters Timeout Retrieves the time period for radio wave automatic stop. Refer to NFCMifareSetAutoRadioOff function for the values to retrieve. Return Values The following values are returned. NFC_OK : Normal termination NFC_NOT_DEVICE : NFC driver error. In the Device Emulator, the value is not returned. NFC_POF : Unopened error NFC_PRM : Parameter error

30

3.16 NFCMifareSetPollingMode This function sets up IC card search method. Calling Sequence [C++] int NFCMifareSetPollingMode( DWORD dwMode, DWORD dwNum, DWORD dwReserved ) [Visual Basic] Public Shared Function NFCMifareSetPollingMode( ByVal dwMode As Int32, _ ByVal dwNum As Int32, _ ByVal dwReserved As Int32 _ ) As Int32 [C#] Public static Int32 Int32 Int32 )

Int32 NFCMifareSetPollingMode( dwMode, dwNum, dwReserved

Parameters dwMode Set up IC card search method. NFC_PLMODE_NORMAL NFC_PLMODE_MULTISTEP NFC_PLMODE_MULTISTEP2 NFC_PLMODE_PACKAGE

: : : :

Normal (Default) Multistep Multistep 2 Package

dwNum Set up number of multistep scanning. Setting range is different by search method. Case of NFC_PLMODE_NORMAL : Specify 0 Case of NFC_PLMODE_MULTISTEP : 2 to 100 Case of NFC_PLMODE_MULTISTEP2 : 2 to 100 Case of NFC_PLMODE_PACKAGE : 2 to 4 dwReserved This parameter is not supported in the current version. Specify '0'.

31

Return Values The following values are returned. NFC_OK : Normal termination NFC_NOT_DEVICE : NFC driver error. In the Device Emulator, the value is not returned. NFC_POF : Unopened error NFC_PRM : Parameter error Notes IC card search method Normal Multistep / Multistep 2

Package

: One IC card will be started by one search operation. : Different IC cards will be started continuously until specified number.(see note) (Only one IC card will be started by one search operation.) : Same type several pieces IC card will be started by one search operation. Search operation will be continued until specified number.

Note: Started card's Uid will be recorded in driver history at each IC card started. Double starting will be prevent by compared this history and started IC card. This history record will be clear by started specified IC card, passed timeout period, call back function return FALSE, execute NFCMifareStopPolling function.

32

3.17 NFCMifareGetPollingMode This function sets up IC card search method. Calling Sequence [C++] int NFCMifareGetPollingMode( DWORD *pdwMode, DWORD *pdwNum, DWORD *pdwReserved ) [Visual Basic] Public Shared Function NFCMifareGetPollingMode( ByRef pdwMode As Int32, _ ByRef pdwNum As Int32, _ ByRef pdwReserved As Int32 _ ) As Int32 [C#] Public ref ref ref )

static Int32 Int32 Int32

Int32 NFCMifareGetPollingMode( pdwMode, pdwNum, pdwReserved

Parameters pdwMode Retrieves IC card search method. About retrieved detail value, refer NFCMifareSetPollingMode function. pdwNum Retrieves number of multistep operation. About retrieved detail value, refer NFCMifareSetPollingMode function. pdwReserved This parameter is not supported in the current version. Specify NULL.

Return Values The following values are returned. NFC_OK : Normal termination NFC_NOT_DEVICE : NFC driver error. In the Device Emulator, the value is not returned. NFC_POF : Unopened error NFC_PRM : Parameter error 33

3.18 NFCMifareGetCardResponseEx This function retrieves response information of activated smart cards When you execute this function after scceed NFCMifarePolling function by set up package mode by NFCMifareSetPollingMode, retrieved response information of started several pieces IC cards. Response information will be recorded in driver at IC card start sccess timing, and retrieve response information in driver by this function. In the Device Emulator, the function checks parameters only. Calling Sequence [C++] int NFCMifareGetCardResponseEx( BYTE *pbyATQ, BYTE *pbySAK, BYTE *pbyUid, BYTE *pbyUidLen, DWORD *pdwDiscoveredNum, DWORD *pdwReserved ) [Visual Basic] Public Shared Function NFCMifareGetCardResponseEx( ByVal pbyATQ As Byte(), _ ByVal pbySAK As Byte(), _ ByVal pbyUid As Byte(), _ ByRef pbyUidLen As Byte, _ ByRef pdwDiscoveredNum As Int32, _ ByRef pdwReserved As Int32 _ ) As Int32 [C#] Public static Int32 NFCMifareGetCardResponseEx( Byte[] pbyATQ, Byte[] pbySAK, Byte[] pbyUid, ref Byte pbyUidLen, ref Int32 pdwDiscoveredNum, ref Int32 pdwReserved )

Parameters pbyATQ Retrieves ATQA from smart card. Secure (2 x dwNum in NFCHFTagSetPollingMode) bytes of the buffer size or more to retrieve.

34

Data format 2 bytes First card ATQA

...

2 bytes Second card ATQA

2 bytes Nth card ATQA

...

pbySAK Retrieves SAK from smart card. Secure (1 x dwNum in NFCHFTagSetPollingMode) bytes of the buffer size or more to retrieve. Data format 1 byte First card SAK

1 byte Second card SAK

... ...

1 byte Nth card SAK

pbyUid Retrieves Uid from smart card. Secure (8 x dwNum in NFCHFTagSetPollingMode) bytes of the buffer size or more to retrieve. Data format 1 byte First card Uid size a

a bytes First card Uid

1 byte b bytes Second card Second card Uid Uid size b

... ...

1 byte Nth card Uid size x

x bytes Nth card Uid

pbyUidLen Retrieves the size of response information retrieved to pbyUid. pdwDiscoveredNum Retrieves number of IC card which was scceed to start by NFCMifarePolling function. Maximum value which is available to set in dwTargetNo of NFCMifareAuthentication function, NFCMifareRead function, NFCMifareWrite function and etc is value which is retrieved in this parameter. Ex) Case of retrieve 3 by this parameter Specified available value in dwTargetNo of NFCMifareAuthentication function is 0 to 2. pdwReserved This parameter is not supported in the current version. Specify NULL. Return Values The following values are returned. NFC_OK NFC_NOT_DEVICE NFC_POF NFC_PRM NFC_NOT_ACTIVATION

: Normal termination : NFC driver error. In the Device Emulator, the value is not returned. : Unopened error : Parameter error : Card inactivation error. In the Device Emulator, the value is not returned.

35

NFC_ERROR_INVALID_ACCESS

: Execute error while card polling Emulator, the value is not returned.

36

4. Notes to Programming 4.1 Notification for Radio Wave Stop 4.1.1 Using Window Message Notification Terminating Radio Wave Transmission Manually 1. If you receive WM_CREATE message, carry out NFCMifareOpen function to set the mode in “wait to read” state. 2. If you receive WM_COMMAND or WM_KEYDOWN message etc., carry out NFCMifarePolling function to search Mifare card and activate it that is located in the communication range. 3. When you have successfully activated the Mifare card and if you require to retrieve its detailed information, carry out NFCMifareGetCardResponse function to retrieve the card response information (at your will). 4. Initiate communication with the Mifare card. See note. 5. When communication with the Mifare card is complete, carry out NFCMifareRadioOff function to terminate radio wave output. 6. If you receive WM_CLOSE message, carry out NFCMifareClose function to set the mode in “read prohibit” state. Note: Refer to Chapter 4.2 ‘Communication with Mifare Cards’ for detail on communicating with Mifare cards.

37

Figure 4.1

38

Stopping Radio Wave Automatically and Issuing Notification of Stop Timing 1. If you receive WM_CREATE message, carry out NFCMifareOpen function to set the mode in “wait to read” state. 2. Carry out NFCMifareSetEventNotification function to set the window message notification effect. 3. Carry out NFCMifareSetAutoRadioOff function to set the radio wave automatic stop effect. 4. If you receive WM_COMMAND or WM_KEYDOWN message etc., carry out NFCMifarePolling function to search Mifare card and activate it that is located in the communication range. 5. When you have successfully activated the Mifare card and if you require to retrieve its detailed information, carry out NFCMifareGetCardResponse function to retrieve the card response information (at your will). 6. initiate communication with the Mifare card. See note. 7. When communication with the Mifare card is complete, carry out NFCMifareRadioOff function to terminate radio wave output (even if radio wave output does not stop, it will stop automatically once communication has not been performed for a certain time period). 8. You can receive WM_NFC_AUTORADIOOFF(WM_USER + 0x580) that automatic termination of radio wave output occurs. In this case, it is possible to notify the user that radio wave output has stopped automatically. 9. If you receive WM_CLOSE message, carry out NFCMifareClose function to set the mode in “read prohibit” state.

Figure 4.2 39

4.1.2 Using Event Notification Terminating Radio Wave Transmission Manually 1. When initiating the application, carry out NFCMifareOpen function to set the mode in “wait to read” state. 2. When initiating communication process, carry out NFCMifarePolling function to search Mifare card and activate it that is located in the communication range. 3. When you have successfully activated the Mifare card and if you require to retrieve its detailed information, carry out NFCMifareGetCardResponse function to retrieve the card response information (at your will). 4. Initiate communication with the Mifare card. See note. 5. When communication with the Mifare card is complete, carry out NFCMifareRadioOff function to terminate radio wave output. 6. When closing the application, carry out NFCMifareClose function to set the mode in “read prohibit” state. Note: Refer to Chapter 4.2 ”Communication with Mifare Cards” for detail on communicating with Mifare cards.

When initiating application

When closing application

Figure 4.3

40

When communicating with Mifare card

Stopping Radio Wave Automatically and Issuing Notification of Stop Timing Main Thread 1. When initiating the application, carry out CreateEvent function to create event handle of radio wave automatic stop timing notification. 2. Carry out CreateThread function to create thread that monitors the radio wave automatic stop. 3. Carry out NFCMifareOpen function to set the mode in “wait to read” state. 4. Carry out NFCMifareSetEventNotification function to set event notification effect. 5. Carry out NFCMifareSetAutoRadioOff function to set the radio wave automatic stop effect. 6. When initiating communication process, carry out NFCMifarePolling function to search Mifare card and activate it that is located in the communication range. 7. When you have successfully activated the Mifare card and if you require to retrieve its detailed information, carry out NFCMifareGetCardResponse function to retrieve the card response information (at your will). 8. Initiate communication with the Mifare card. See note. 9. When communication with the Mifare card is complete, carry out NFCMifareRadioOff function to terminate radio wave output (even if radio wave output does not stop, it will stop automatically once communication has not been performed for a certain time period). 10. When closing the application, carry out SetEvent function to issue a notification to the thread that moitors the radio wave automatic stop. 11. Close the event handle and thread handle. 12. Carry out NFCMifareClose function to set the mode in “read prohibit” state. Note: Refer to Chapter 4.2 “Communication with Mifare Cards” for detail on communicating with Mifare cards.

When initiating application

When closing application

Figure 4.4 41

When communicating with Mifare card

NFC Mifare Thread 1. Carry out WaitForSingleObject function to wait for event handle of the radio wave automatic stop notification timing. 2. When you receive a notification event upon closing the application, close monitoring on the radio wave automatic stop. 3. When you receive a notification event on other occasions, it is possible to issue a notification that the radio wave output has stopped automatically.

Figure 4.5

42

4.2 Communication with Mifare Cards Below explanation is the communication procedure with Mifare card for “Notification for Radio Wave Stop” described in Chapter 4.1. 1. Carry out NFCMifareAuthentication function to authorize access to Mifare card. 2. Carry out either NFCMifareRead, NFCMifareWrite or NFCMifareValue function. 3. To continue process and change the sector to other sectors, return to Step 1 and repeat the process. 4. To continue process but not to change the sector, return to Step 2 and repeat the process.

Figure 4.6

43

4.3 About search method Use of Multi Step mode Communicate with Mifare (Standard) card 1. By using NFCMifareSetPollingMode function, you should specify Multi Step mode(NFC_PLMODE_MULTISTEP) as search method and you should specify continuous scanning card number (CARD_NUM) as number of card. 2. Set iCount=0 3. If iCount