C API for BALTECH SDK

§ brp_Iso14CE_ActivateCardAPDU()

brp_errcode brp_Iso14CE_ActivateCardAPDU ( brp_protocol  protocol,
bool  SpecifyTimeoutApdu,
bool  AutoWTX,
unsigned  ATQA,
brp_buf  Snr,
bool  DSEqualToDR,
bool  DS8,
bool  DS4,
bool  DS2,
bool  DR8,
bool  DR4,
bool  DR2,
unsigned  FWT,
unsigned  TimeoutPCD,
unsigned  TimeoutApdu,
brp_buf  ATS,
size_t  ATS_len,
brp_buf FirstCmd,
size_t *  FirstCmd_len,
brp_mempool mempool 
)

This command starts the reader's passive mode, emulating an ISO14443-4 compatible card, and returns the first APDU request received.

The emulated PICC answers all ISO14443-3 request, anticollision and select commands. It utilizes the 4-Byte serial number specified in the Snr parameter. The Byte order corresponds to ISO14443-3: The first Byte (uid0) will be transmitted first to the reader. It has to be 0x08 as this indicates a random serial number.

To identify potential errors, the PCD starts a timer within which the PICC has to respond, after sending out each frame. This time duration is the so-called frame waiting time (FWT). FWT is determined by the PICC during protocol activation and is valid for all further communication. This parameter should be chosen as large as required, but as small as possible. The communication speed between card emulator and host and the processing speed of the host should be taken into consideration. It is possible to increase the FWT temporarily for a single frame by calling the brp_Iso14CE_ExtendWaitingTime() command. Since the ISO14443 protocol specification only allows discrete FWT values, the firmware calculates the lowest value that meets the specified waiting time according to the equation

FWI = (256 * 16 / fc) * 2 ^ FWT,

where fc is the RFID carrier frequency. The highest possible FWT value is 4949 ms.

2 timeout parameters triggering a timer have to be specified for this command:

  • The first timer, associated with the TimeoutPCD parameter, is used for the card activation sequence. Card activation is complete once the emulated PICC has received the RATS command. If the emulated PICC doesn't receive the required protocol activation sequence within TimeoutPCD , this command will return an BRP_Iso14CE_ErrIso144State status code. For TimeoutPCD , we recommend a value of 1000 ms - this provides the best results for the protocol activation sequence.
  • The second timer is optional (default value: 100 ms) and associated with the TimeoutApdu parameter. It stops as soon as the emulated PICC has received an optional PPS command frame or an APDU Exchange command after the RATS command as defined in ISO14443-4. If the emulated PICC doesn't receive anything within TimeoutApdu , this command will return an BRP_Iso14CE_ErrIso144State status code. Otherwise, the first APDU request is returned in the command's response.

The ATS (historical bytes) the card emulation shall use may be specified by the ATS parameter if required. This parameter may also be left out, in which case no historical bytes are sent.

As already mentioned, ISO14443-4 specifies that a card has to send a response within FWT ms. The command brp_Iso14CE_ExtendWaitingTime() can be called to extend this time temporarily if the host cannot prepare the APDU within the defined FWT time. A more convenient way to perform this action is to use the automatic WTX mode : If the parameter AutoWTX is set to 1, the card emulation will automatically transmit WTX requests periodically every 0.9 * FWT ms after the successful execution of the Iso14CE.StartEmu command and of all subsequent brp_Iso14CE_ExchangeCardAPDU() commands. In practice, this allows to ignore the FWT limits, since the card emulation itself keeps the communication with the PCD alive.

Parameters
[in]protocolused to execute the command
[in]SpecifyTimeoutApduHas to be set if the TimeoutApdu parameter is present.
[in]AutoWTXEnable/disable automatic Waiting Time Extension
[in]ATQAAttention: When transferred via HF, the ATQA is sent LSB (instead of the MSB order used here).
[in]SnrCard serial number of the emulated PICC according to the ISO14443-3 specification (uid0, uid1, uid2, uid3).
[in]DSEqualToDRSame D for both directions
[in]DS8supports 848 kBit PICC -> PCD
[in]DS4supports 424 kBit PICC -> PCD
[in]DS2supports 212 kBit PICC -> PCD
[in]DR8supports 848 kBit PCD -> PICC
[in]DR4supports 424 kBit PCD -> PICC
[in]DR2supports 212 kBit PCD -> PICC
[in]FWTFrame waiting time in ms. This is the maximum time the PCD waits for the next PICC response. If FWT is set to 0xFFFF the default frame waiting time of 77.328 ms will be applied.
[in]TimeoutPCDMaximum time (in ms) to wait for card activation. Card activation is complete after the PICC has received the RATS command. A value of 0xFFFF corresponds to an infinite time.
[in]TimeoutApduMaximum time (in ms) to wait for an optional Apdu or the first ISO14443-4 APDU after the first received PCD frame. This value is optional - if not given as a parameter, it's set to 100ms. A value of 0xFFFF corresponds to an infinite time.
[in]ATSATS (Historical Bytes) to use for card emulation.
[in]ATS_len
[out]FirstCmdFirst ISO14443-4 APDU request received from the PCD.
[out]FirstCmd_len
[in]mempoolis used to store response data. Maybe NULL to use an internal mempool, in this case the data is only available until another command uses the internal mempool