Class pn532::controller

Inheritance Relationships

Base Type

  • public std::enable_shared_from_this< controller >

Class Documentation

class controller : public std::enable_shared_from_this<controller>

Class that controls a PN532, i.e. a pn532::controller, over some channel.

The PN532 can act both as an initiator and as a target; the members are thus prefixed with initiator_ or target_. This class has a move-only semantics.

Miscellanea commands

Instruction for configuration and self-test of the reader.

result<bool> diagnose_rom(ms timeout = long_timeout)

Self-check PN532 ROM memory (UM0701-02 §7.2.1)

Parameters:

timeout – Maximum time after which channel_error::timeout is returned.

Returns:

True if self-test is successful, false otherwise, or any of the channel_error error conditions.

result<bool> diagnose_ram(ms timeout = long_timeout)

Self-check PN532 RAM memory (UM0701-02 §7.2.1)

Parameters:

timeout – Maximum time after which channel_error::timeout is returned.

Returns:

True if self-test is successful, false otherwise, or any of the channel_error error conditions.

result<bool> diagnose_attention_req_or_card_presence(ms timeout = long_timeout)

Check if card is still inside the field (UM0701-02 §7.2.1).

Parameters:

timeout – Maximum time after which channel_error::timeout is returned.

Returns:

True if card still present inside the field, false otherwise, or any of the channel_error error conditions.

result<bool> diagnose_comm_line(ms timeout = long_timeout)

Check communication channel by sending random data, and read it back (UM0701-02 §7.2.1).

Parameters:

timeout – Maximum time after which channel_error::timeout is returned.

Returns:

True if data echoes without error, false otherwise, or any of the channel_error error conditions.

result<unsigned, unsigned> diagnose_poll_target(bool slow = true, bool fast = true, ms timeout = long_timeout)

Sends FeliCa polling command and count fails attempts (UM0701-02 §7.2.1).

Parameters:
  • slow – Poll targets at 212Kbps.

  • fast – Poll targets at 424Kbps.

  • timeout – Maximum time after which channel_error::timeout is returned.

Returns:

Number of fails (<128) at 212 Kbps, number of fails (<128) as 424 Kbps, or any of the channel_error error conditions.

result diagnose_echo_back(ms reply_delay, std::uint8_t tx_mode, std::uint8_t rx_mode, ms timeout = long_timeout)

Set the PN532 in target mode (simulating a NFC tag), and echo data back to the initiator after a delay (UM0701-02 §7.2.1).

Parameters:
  • reply_delay – The time after which data is sent back to the initiator.

  • tx_mode – Cfr. CIU_TxMode register (0x6302), §8.6.23.18 PN532/C1 Data sheet.

  • rx_mode – Cfr. CIU_RxMode register (0x6303), §8.6.23.19 PN532/C1 Data sheet.

  • timeout – Maximum time after which channel_error::timeout is returned.

Returns:

Either mlab::result_success or any of the channel_error error conditions.

result<bool> diagnose_self_antenna(low_current_thr low_threshold, high_current_thr high_threshold, ms timeout = long_timeout)

Test antenna for open circuits, or shorts (UM0701-02 §7.2.1).

Parameters:
  • low_threshold – Current threshold for low current error.

  • high_threshold – Current threshold for high current error.

  • timeout – Maximum time after which channel_error::timeout is returned.

Returns:

True if self-test is successful, false otherwise, or any of the channel_error error conditions.

result<firmware_version> get_firmware_version(ms timeout = default_timeout)

Retrieve the silicon version and firmware information and support (UM0701-02 §7.2.2).

Parameters:

timeout – Maximum time after which channel_error::timeout is returned.

Returns:

Silicon version and firmware functionality support, or any of the channel_error error conditions.

result<general_status> get_general_status(ms timeout = default_timeout)

Read the general status of the PN532 (last error, bitrate TX/RX, modulation and SAM status) (UM0701-02 §7.2.3).

Parameters:

timeout – Maximum time after which channel_error::timeout is returned.

Returns:

PN532 status, or any of the channel_error error conditions.

result<std::vector<uint8_t>> read_registers(std::vector<reg::addr> const &addresses, ms timeout = default_timeout)

Read multiple internal PN532 registers (UM0701-02 §7.2.4).

Parameters:
Returns:

Register values (respecting addresses order), or any of the channel_error error conditions.

inline result<uint8_t> read_register(reg::addr const &addr, ms timeout = default_timeout)

Read a single internal PN532 register (UM0701-02 §7.2.4).

Parameters:
Returns:

Register value, or any of the channel_error error conditions.

result write_registers(std::vector<std::pair<reg::addr, std::uint8_t>> const &addr_value_pairs, ms timeout = default_timeout)

Write multiple internal PN532 registers (UM0701-02 §7.2.5).

Parameters:
  • addr_value_pairs – Max 87 register address-value pairs.

  • timeout – Maximum time after which channel_error::timeout is returned.

Returns:

Either mlab::result_success or any of the channel_error error conditions.

inline result write_register(reg::addr const &addr, std::uint8_t val, ms timeout = default_timeout)

Write a single internal PN532 register (UM0701-02 §7.2.5).

Parameters:
  • addr – Register address.

  • val – Value to write at addr.

  • timeout – Maximum time after which channel_error::timeout is returned.

Returns:

Either mlab::result_success or any of the channel_error error conditions.

result<gpio_status> read_gpio(ms timeout = default_timeout)

Read all GPIOs (UM0701-02 §7.2.6).

Parameters:

timeout – Maximum time after which channel_error::timeout is returned.

Returns:

GPIO status, or any of the channel_error error conditions.

result write_gpio(gpio_status const &status, bool write_p3 = true, bool write_p7 = true, ms timeout = default_timeout)

Write all GPIOs (UM0701-02 §7.2.7).

Parameters:
  • status – GPIOs values to write

  • write_p3 – Flag for masking the P3 GPIO bank (true is write, false is skip, in the latter case the value in status is ignored).

  • write_p7 – Flag for masking the P7 GPIO bank (true is write, false is skip, in the latter case the value in status is ignored).

  • timeout – Maximum time after which channel_error::timeout is returned.

Returns:

Either mlab::result_success or any of the channel_error error conditions.

result set_gpio_pin(gpio_port loc, std::uint8_t pin_idx, bool value, ms timeout = default_timeout)

Write a single GPIO by doing read_gpio followed by write_gpio.

Parameters:
Returns:

Either mlab::result_success or any of the channel_error error conditions.

result set_serial_baud_rate(serial_baudrate br, ms timeout = default_timeout)

Set the UART/HSU baudrate (UM0701-02 §7.2.8).

Note

This command is allowed only for HSU communication. After 200uS from the ACK, commands with the new baudrate can be sent.

Parameters:
  • br – New baudrate for subsequent commands.

  • timeout – Maximum time after which channel_error::timeout is returned.

Returns:

Either mlab::result_success or any of the channel_error error conditions.

result sam_configuration(sam_mode mode, ms sam_timeout, bool controller_drives_irq = true, ms timeout = default_timeout)

Configure the SAM data path (UM0701-02 §7.2.10).

Parameters:
  • mode – Configure how the SAM shall be used

  • sam_timeout – In virtual card mode only, defines the timeout for transactions.

  • controller_drives_irq – Specifies if the PN532 shall use the P70 pin for IRQ.

  • timeout – Maximum time after which channel_error::timeout is returned.

Returns:

Either mlab::result_success or any of the channel_error error conditions.

result set_parameters(parameters const &parms, ms timeout = default_timeout)

Sets the PN532 working parameters (UM0701-02 §7.2.9).

Parameters:
Returns:

Either mlab::result_success, or any of the channel_error error conditions.

Power down commands

Puts the PN532 (including the analog RF frontend) in power down mode (UM0701-02 §7.3.11).

param wakeup_sources:

List of authorized sources that can wake the PN532 up.

param generate_irq:

Defines whether once waken up, the PN532 handles the IRQ pin. This is only useful if wakeup_source::rf is in wakeup_sources; in that case, when the RF field wakes the PN532 up, the IRQ pin is asserted.

param timeout:

Maximum time after which channel_error::timeout is returned.

return:

The rf_status, or any of the channel_error error conditions.

result<rf_status> power_down(std::vector<wakeup_source> const &wakeup_sources, bool generate_irq, ms timeout = default_timeout)
result<rf_status> power_down(std::vector<wakeup_source> const &wakeup_sources, ms timeout = default_timeout)

Configure RF parameters

Instruction for configuring the antenna parameters.

result rf_configuration_field(bool auto_rfca, bool rf_on, ms timeout = default_timeout)

Switch on or off the RF field (UM0701-02 §7.3.1).

Parameters:
  • auto_rfca – Enable automatic RF field detection.

  • rf_on – True for on, false for off.

  • timeout – Maximum time after which channel_error::timeout is returned.

Returns:

Either mlab::result_success or any of the channel_error error conditions.

result rf_configuration_timings(rf_timeout atr_res_timeout = rf_timeout::ms_102_4, rf_timeout retry_timeout = rf_timeout::ms_51_2, ms timeout = default_timeout)

Set timeout for ATR_RES and non-DEP communications (UM0701-02 §7.3.1).

Parameters:
  • atr_res_timeout – Set timeout for ATR request (use when PN532 is the initiator).

  • retry_timeout – Set internal timeout for controller::initiator_communicate_through. This is the timeout after which the PN532 itself gives up, not the timeout for the command we launch.

  • timeout – Maximum time after which channel_error::timeout is returned.

Returns:

Either mlab::result_success or any of the channel_error error conditions.

result rf_configuration_retries(infbyte comm_retries = 0_b, ms timeout = default_timeout)

Set maximum retries for communicating with the target (UM0701-02 §7.3.1).

Parameters:
Returns:

Either mlab::result_success or any of the channel_error error conditions.

result rf_configuration_retries(infbyte atr_retries, infbyte psl_retries, infbyte passive_activation_retries = infty, ms timeout = default_timeout)

Set maximum retries for ATR, PSL and passive actions (UM0701-02 §7.3.1).

Parameters:
  • atr_retries – Number of retries after ATR_RES. You can pass infty here for infinite retries. In passive mode, the PN532 will ignore this and always try twice.

  • psl_retries – Number of retries after a PSL_RES or PPS response. You can pass infty here for infinite retries.

  • passive_activation_retries – Timeout for controller::initiator_communicate_through; this is the timeout after which the PN532 itself gives up, not the timeout for the command we laucnh.

  • timeout – Maximum time after which channel_error::timeout is returned.

Returns:

Either mlab::result_success or any of the channel_error error conditions.

result rf_configuration_analog_106kbps_typea(reg::ciu_106kbps_typea const &config, ms timeout = default_timeout)

Set RF analog parameters for 106kbps type A tags (UM0701-02 §7.3.1).

Parameters:
  • config – Register content with all the configuration options.

  • timeout – Maximum time after which channel_error::timeout is returned.

Returns:

Either mlab::result_success or any of the channel_error error conditions.

result rf_configuration_analog_212_424kbps(reg::ciu_212_424kbps const &config, ms timeout = default_timeout)

Set RF analog parameters for 212kbps and 424kbps tags (UM0701-02 §7.3.1).

Parameters:
  • config – Register content with all the configuration options.

  • timeout – Maximum time after which channel_error::timeout is returned.

Returns:

Either mlab::result_success or any of the channel_error error conditions.

result rf_configuration_analog_typeb(reg::ciu_typeb const &config, ms timeout = default_timeout)

Set RF analog parameters for type B tags (UM0701-02 §7.3.1).

Parameters:
  • config – Register content with all the configuration options.

  • timeout – Maximum time after which channel_error::timeout is returned.

Returns:

Either mlab::result_success or any of the channel_error error conditions.

result rf_configuration_analog_iso_iec_14443_4(reg::ciu_iso_iec_14443_4 const &config, ms timeout = default_timeout)

Set RF analog parameters for 212kbps,424kbps and 848kbps tags communicating with the ISO/IEC14443-4 protocol (UM0701-02 §7.3.1).

Parameters:
  • config – Register content with all the configuration options.

  • timeout – Maximum time after which channel_error::timeout is returned.

Returns:

Either mlab::result_success or any of the channel_error error conditions.

result rf_regulation_test(rf_test_mode mode, ms timeout = default_timeout)

Perform radio regulation test (UM0701-02 §7.3.2). The PN532 transmits data until a new command is sent to it.

Parameters:
  • mode – Bit rate and framing used for testing

  • timeout – Maximum time after which channel_error::timeout is returned.

Returns:

The rf_status, or any of the channel_error error conditions.

Talk to a PICC

Instruction for interfacing with a PICC (NFC tag).

template<class T, class = typename std::enable_if<not std::is_same_v<bin_data, typename std::decay_t<T>::type>>::type>
result<rf_status, bin_data> initiator_data_exchange(std::uint8_t target_logical_index, T &&data, ms timeout = default_timeout)

Exchange data with the target (UM0701-02 §7.3.8).

Parameters:
  • target_logical_index – Index the PN532 has given to the tag, can be retrieved with initiator_list_passive_* commands or via initiator_auto_poll.

  • data – Any object that can be injected into a mlab::bin_data object. If the total payload exceeds 262 bytes, multiple commands will be issued.

  • timeout – Maximum time after which channel_error::timeout is returned.

Returns:

The rf_status and the data sent by the target as a response, or any of the channel_error error conditions.

result<rf_status, bin_data> initiator_data_exchange(std::uint8_t target_logical_index, bin_data const &data, ms timeout = default_timeout)

Exchange data with the target (UM0701-02 §7.3.8).

Parameters:
  • target_logical_index – Index the PN532 has given to the tag, can be retrieved with initiator_list_passive_* commands or via initiator_auto_poll.

  • data – If the total payload exceeds 262 bytes, multiple commands will be issued.

  • timeout – Maximum time after which channel_error::timeout is returned.

Returns:

The rf_status and the data sent by the target as a response, or any of the channel_error error conditions.

result<rf_status> initiator_select(std::uint8_t target_logical_index, ms timeout = default_timeout)

Select the tag, subsequent commands will effect the selected tag (UM0701-02 §7.3.12).

Parameters:
  • target_logical_index – Index the PN532 has given to the tag, can be retrieved with initiator_list_passive_* commands or via initiator_auto_poll.

  • timeout – Maximum time after which channel_error::timeout is returned.

Returns:

The rf_status, or any of the channel_error error conditions.

result<rf_status> initiator_deselect(std::uint8_t target_logical_index, ms timeout = default_timeout)

Deselect the tag, but maintain the information (UM0701-02 §7.3.10).

Parameters:
  • target_logical_index – Index the PN532 has given to the tag, can be retrieved with initiator_list_passive_* commands or via initiator_auto_poll.

  • timeout – Maximum time after which channel_error::timeout is returned.

Returns:

The rf_status, or any of the channel_error error conditions.

result<rf_status> initiator_release(std::uint8_t target_logical_index, ms timeout = default_timeout)

Release the tag, deselect and delete the information (UM0701-02 §7.3.11).

Parameters:
  • target_logical_index – Index the PN532 has given to the tag, can be retrieved with initiator_list_passive_* commands or via initiator_auto_poll.

  • timeout – Maximum time after which channel_error::timeout is returned.

Returns:

The rf_status, or any of the channel_error error conditions.

result<rf_status> initiator_psl(std::uint8_t target_logical_index, baudrate in_to_trg, baudrate trg_to_in, ms timeout = default_timeout)

Change baudrate of a TPE or ISO/IEC14443-4 target (UM0701-02 §7.3.7).

Parameters:
  • target_logical_index – Index the PN532 has given to the tag, can be retrieved with initiator_list_passive_* commands or via initiator_auto_poll.

  • in_to_trg – Baudrate for communications from the initiator (PN532) to the target (tag).

  • trg_to_in – Baudrate for communications from the target (tag) to the initiator (PN532).

  • timeout – Maximum time after which channel_error::timeout is returned.

Returns:

The rf_status, or any of the channel_error error conditions.

result<std::vector<target_kbps106_typea>> initiator_list_passive_kbps106_typea(std::uint8_t max_targets = max_supported_targets, ms timeout = long_timeout)

List all TypeA tags in range (at 106kbps baudrate) (UM0701-02 §7.3.5).

Parameters:
  • max_targets – Max number of target to list and initialize.

  • timeout – Maximum time after which channel_error::timeout is returned.

Returns:

A list of targets target<baudrate_modulation::kbps106_iso_iec_14443_typea>, or any of the channel_error error conditions.

Listing passive 106kbps type A targets

Check for a specific TypeA tag by UID (at 106kbps baudrate) (UM0701-02 §7.3.5).

param max_targets:

Max number of target to list and initialize.

param uid:

The UID of the tag to initialize.

param timeout:

Maximum time after which channel_error::timeout is returned.

return:

A list of targets target<baudrate_modulation::kbps106_iso_iec_14443_typea>, or any of the channel_error error conditions.

result<std::vector<target_kbps106_typea>> initiator_list_passive_kbps106_typea(nfcid_1t uid, std::uint8_t max_targets = 1, ms timeout = long_timeout)
result<std::vector<target_kbps106_typea>> initiator_list_passive_kbps106_typea(nfcid_2t uid, std::uint8_t max_targets = 1, ms timeout = long_timeout)
result<std::vector<target_kbps106_typea>> initiator_list_passive_kbps106_typea(nfcid_3t uid, std::uint8_t max_targets = 1, ms timeout = long_timeout)

Activate a known logical target

Launch an activation request of the target (UM0701-02 §7.3.6).

param target_logical_index:

Index the PN532 has given to the tag, can be retrieved with initiator_list_passive_* commands or via initiator_auto_poll.

param nfcid:

the NFCID3 used for the ATR_REQ

param general_info:

General info bytes to send. Max 48 bytes.

param timeout:

Maximum time after which channel_error::timeout is returned.

return:

The rf_status and atr_res_info, or any of the channel_error error conditions.

result<rf_status, atr_res_info> initiator_activate_target(std::uint8_t target_logical_index, nfcid_3t const &nfcid, std::vector<std::uint8_t> const &general_info, ms timeout = default_timeout)
result<rf_status, atr_res_info> initiator_activate_target(std::uint8_t target_logical_index, std::vector<std::uint8_t> const &general_info, ms timeout = default_timeout)
result<rf_status, atr_res_info> initiator_activate_target(std::uint8_t target_logical_index, nfcid_3t const &nfcid, ms timeout = default_timeout)
result<rf_status, atr_res_info> initiator_activate_target(std::uint8_t target_logical_index, ms timeout = default_timeout)

Activate any active DEP target

Activate the target with active or passive communication (UM0701-02 §7.3.3).

param speed:

Communication baudrate.

param nfcid:

The NFCID3 used for the ATR_REQ.

param general_info:

General info bytes to send. Max 48 bytes.

param timeout:

Maximum time after which channel_error::timeout is returned.

return:

The outcome jump_dep_psl, or any of the channel_error error conditions.

result<jump_dep_psl> initiator_jump_for_dep_active(baudrate speed, nfcid_3t const &nfcid, std::vector<std::uint8_t> const &general_info, ms timeout = default_timeout)
result<jump_dep_psl> initiator_jump_for_dep_active(baudrate speed, std::vector<std::uint8_t> const &general_info, ms timeout = default_timeout)
result<jump_dep_psl> initiator_jump_for_dep_active(baudrate speed, nfcid_3t const &nfcid, ms timeout = default_timeout)
result<jump_dep_psl> initiator_jump_for_dep_active(baudrate speed, ms timeout = default_timeout)

Activate a specific passive 106 kbps DEP target

Activate the target with active or passive communication (UM0701-02 §7.3.3).

param target_id:

NFCID of the target to activate.

param nfcid:

The NFCID3 used for the ATR_REQ.

param general_info:

General info bytes to send. Max 48 bytes.

param timeout:

Maximum time after which channel_error::timeout is returned.

return:

The outcome jump_dep_psl, or any of the channel_error error conditions.

result<jump_dep_psl> initiator_jump_for_dep_passive_106kbps(nfcid_1t target_id, nfcid_3t const &nfcid, std::vector<std::uint8_t> const &general_info, ms timeout = default_timeout)
result<jump_dep_psl> initiator_jump_for_dep_passive_106kbps(nfcid_1t target_id, std::vector<std::uint8_t> const &general_info, ms timeout = default_timeout)
result<jump_dep_psl> initiator_jump_for_dep_passive_106kbps(nfcid_1t target_id, nfcid_3t const &nfcid, ms timeout = default_timeout)
result<jump_dep_psl> initiator_jump_for_dep_passive_106kbps(nfcid_1t target_id, ms timeout = default_timeout)

Activate any passive 106 kbps DEP target

Activate the target with active or passive communication (UM0701-02 §7.3.3).

param nfcid:

The NFCID3 used for the ATR_REQ.

param general_info:

General info bytes to send. Max 48 bytes.

param timeout:

Maximum time after which channel_error::timeout is returned.

return:

The outcome jump_dep_psl, or any of the channel_error error conditions.

result<jump_dep_psl> initiator_jump_for_dep_passive_106kbps(nfcid_3t const &nfcid, std::vector<std::uint8_t> const &general_info, ms timeout = default_timeout)
result<jump_dep_psl> initiator_jump_for_dep_passive_106kbps(std::vector<std::uint8_t> const &general_info, ms timeout = default_timeout)
result<jump_dep_psl> initiator_jump_for_dep_passive_106kbps(nfcid_3t const &nfcid, ms timeout = default_timeout)
result<jump_dep_psl> initiator_jump_for_dep_passive_106kbps(ms timeout = default_timeout)

Activate a specific passive 212 kbps DEP target

Activate the target with active or passive communication (UM0701-02 §7.3.3).

param payload:

The payload to send to the tags (structure defined in ISO/IEC 18092 §11.2.2.5).

param general_info:

General info bytes to send. Max 48 bytes.

param timeout:

Maximum time after which channel_error::timeout is returned.

return:

The outcome jump_dep_psl, or any of the channel_error error conditions.

result<jump_dep_psl> initiator_jump_for_dep_passive_212kbps(std::array<std::uint8_t, 5> const &payload, std::vector<std::uint8_t> const &general_info, ms timeout = default_timeout)
result<jump_dep_psl> initiator_jump_for_dep_passive_212kbps(std::array<std::uint8_t, 5> const &payload, ms timeout = default_timeout)

Activate a specific passive 424 kbps DEP target

Activate the target with active or passive communication (UM0701-02 §7.3.3).

param payload:

The payload to send to the tags (structure defined in ISO/IEC 18092 §11.2.2.5).

param general_info:

General info bytes to send. Max 48 bytes.

param timeout:

Maximum time after which channel_error::timeout is returned.

return:

The outcome jump_dep_psl, or any of the channel_error error conditions.

result<jump_dep_psl> initiator_jump_for_dep_passive_424kbps(std::array<std::uint8_t, 5> const &payload, std::vector<std::uint8_t> const &general_info, ms timeout = default_timeout)
result<jump_dep_psl> initiator_jump_for_dep_passive_424kbps(std::array<std::uint8_t, 5> const &payload, ms timeout = default_timeout)

Activate any active PSL target

Activate the target with active or passive communication (UM0701-02 §7.3.3).

param speed:

Communication baudrate.

param nfcid:

The NFCID3 used for the ATR_REQ.

param general_info:

General info bytes to send. Max 48 bytes.

param timeout:

Maximum time after which channel_error::timeout is returned.

return:

The outcome jump_dep_psl, or any of the channel_error error conditions.

result<jump_dep_psl> initiator_jump_for_psl_active(baudrate speed, nfcid_3t const &nfcid, std::vector<std::uint8_t> const &general_info, ms timeout = default_timeout)
result<jump_dep_psl> initiator_jump_for_psl_active(baudrate speed, std::vector<std::uint8_t> const &general_info, ms timeout = default_timeout)
result<jump_dep_psl> initiator_jump_for_psl_active(baudrate speed, nfcid_3t const &nfcid, ms timeout = default_timeout)
result<jump_dep_psl> initiator_jump_for_psl_active(baudrate speed, ms timeout = default_timeout)

Activate any passive PSL 106 kbps target

Activate the target with active or passive communication (UM0701-02 §7.3.3).

param nfcid:

The NFCID3 used for the ATR_REQ.

param general_info:

General info bytes to send. Max 48 bytes.

param timeout:

Maximum time after which channel_error::timeout is returned.

return:

The outcome jump_dep_psl, or any of the channel_error error conditions.

result<jump_dep_psl> initiator_jump_for_psl_passive_106kbps(nfcid_3t const &nfcid, std::vector<std::uint8_t> const &general_info, ms timeout = default_timeout)
result<jump_dep_psl> initiator_jump_for_psl_passive_106kbps(std::vector<std::uint8_t> const &general_info, ms timeout = default_timeout)
result<jump_dep_psl> initiator_jump_for_psl_passive_106kbps(nfcid_3t const &nfcid, ms timeout = default_timeout)
result<jump_dep_psl> initiator_jump_for_psl_passive_106kbps(ms timeout = default_timeout)

Activate a specific passive PSL 106 kbps target

Activate the target with active or passive communication (UM0701-02 §7.3.3).

param target_id:

NFCID of the target to activate.

param nfcid:

The NFCID3 used for the ATR_REQ.

param general_info:

General info bytes to send. Max 48 bytes.

param timeout:

Maximum time after which channel_error::timeout is returned.

return:

The outcome jump_dep_psl, or any of the channel_error error conditions.

result<jump_dep_psl> initiator_jump_for_psl_passive_106kbps(nfcid_1t target_id, nfcid_3t const &nfcid, std::vector<std::uint8_t> const &general_info, ms timeout = default_timeout)
result<jump_dep_psl> initiator_jump_for_psl_passive_106kbps(nfcid_1t target_id, std::vector<std::uint8_t> const &general_info, ms timeout = default_timeout)
result<jump_dep_psl> initiator_jump_for_psl_passive_106kbps(nfcid_1t target_id, nfcid_3t const &nfcid, ms timeout = default_timeout)
result<jump_dep_psl> initiator_jump_for_psl_passive_106kbps(nfcid_1t target_id, ms timeout = default_timeout)

Activate a specific passive PSL 212 kbps target

Activate the target with active or passive communication (UM0701-02 §7.3.3).

param payload:

The payload to send to the tags (structure defined in ISO/IEC 18092 §11.2.2.5).

param general_info:

General info bytes to send. Max 48 bytes.

param timeout:

Maximum time after which channel_error::timeout is returned.

return:

The outcome jump_dep_psl, or any of the channel_error error conditions.

result<jump_dep_psl> initiator_jump_for_psl_passive_212kbps(std::array<std::uint8_t, 5> const &payload, std::vector<std::uint8_t> const &general_info, ms timeout = default_timeout)
result<jump_dep_psl> initiator_jump_for_psl_passive_212kbps(std::array<std::uint8_t, 5> const &payload, ms timeout = default_timeout)

Activate a specific passive PSL 424 kbps target

Activate the target with active or passive communication (UM0701-02 §7.3.3).

param payload:

The payload to send to the tags (structure defined in ISO/IEC 18092 §11.2.2.5).

param general_info:

General info bytes to send. Max 48 bytes.

param timeout:

Maximum time after which channel_error::timeout is returned.

return:

The outcome jump_dep_psl, or any of the channel_error error conditions.

result<jump_dep_psl> initiator_jump_for_psl_passive_424kbps(std::array<std::uint8_t, 5> const &payload, std::vector<std::uint8_t> const &general_info, ms timeout = default_timeout)
result<jump_dep_psl> initiator_jump_for_psl_passive_424kbps(std::array<std::uint8_t, 5> const &payload, ms timeout = default_timeout)

Emulating a PICC

Instruction for Emulating a PICC (NFC tag).

result<status_as_target> target_get_target_status(ms timeout = default_timeout)

Queries in what state the PN532 is, as a target (UM0701-02 §7.3.21).

Parameters:

timeout – Maximum time after which channel_error::timeout is returned.

Returns:

The status_as_target, or any of the channel_error error conditions.

result<activation_as_target> target_init_as_target(bool picc_only, bool dep_only, bool passive_only, mifare_params const &mifare, felica_params const &felica, nfcid_3t const &nfcid, std::vector<std::uint8_t> const &general_info = {}, std::vector<std::uint8_t> const &historical_bytes = {}, ms timeout = default_timeout)

Configure the PN532 as a target (UM0701-02 §7.3.14).

Parameters:
  • picc_only – If true, the PN532 can only be initialized via a RATS frame, i.e. as a ISO/IEC14443-4 PICC.

  • dep_only – If true, the PN532 can only be initialized via a ATR_REQ frame, i.e. as an active or passive DEP target.

  • passive_only – If true, the PN532 refuses the active mode.

  • mifare – Information needed to be activate at 106 Kbps in passive mode.

  • felica – Information needed to be able to respond to a polling request at 212/424 Kbps in passive mode.

  • nfcid – The NFCID3 used for the ATR_REQ response.

  • general_info – General bytes to use in the ATR_RES response. Max 47 bytes, if exceeding, it will be truncated.

  • historical_bytes – Historical bytes to be used in the ATS when the PN532 is in ISO/IEC14443-4 PICC emulation mode. Max 48 bytes, if exceeding, it will be truncated.

  • timeout – Maximum time after which channel_error::timeout is returned.

Returns:

The outcome activation_as_target, or any of the channel_error error conditions.

result<rf_status> target_set_general_bytes(std::vector<std::uint8_t> const &general_info, ms timeout = default_timeout)

Used in combination with target_init_as_target for generating the ATR_RES request (UM0701-02 §7.3.15). When used, it must follow target_init_as_target.

Parameters:
  • general_info – General bytes to use in the ATR_RES response to the initiator. Max 47 bytes, if exceeding, it will be truncated.

  • timeout – Maximum time after which channel_error::timeout is returned.

Returns:

The rf_status, or any of the channel_error error conditions.

result<rf_status, bin_data> target_get_data(ms timeout = default_timeout)

Get data sent by the initiator (UM0701-02 §7.3.16).

Parameters:

timeout – Maximum time after which channel_error::timeout is returned.

Returns:

The rf_status and the data sent by the initiator, or any of the channel_error error conditions.

result<rf_status> target_set_data(std::vector<std::uint8_t> const &data, ms timeout = default_timeout)

Set data to be sent at the initiator (UM0701-02 §7.3.17).

Parameters:
Returns:

The rf_status, or any of the channel_error error conditions.

result<rf_status> target_set_metadata(std::vector<std::uint8_t> const &data, ms timeout = default_timeout)

Used to send more than 262 bytes when in DEP mode (UM0701-02 §7.3.18). As long as more data has to be sent, call target_set_metadata; as the last <262 packet is being sent, call instead target_set_metadata.

See also

target_set_data

Note

The name is misleading; in fact, this sends data with the “more information” bit set, while target_set_data does not (chaining).

Parameters:
  • data – Max 262 bytes, if exceeding, it will be truncated.

  • timeout – Maximum time after which channel_error::timeout is returned.

Returns:

The rf_status, or any of the channel_error error conditions.

result<rf_status, bin_data> target_get_initiator_command(ms timeout = default_timeout)

Get a packet from the initiator (UM0701-02 §7.3.19). This is similar to target_get_data, but here the PN532 does not handle supervisory, chaining, error handling and so on.

See also

target_get_data

Parameters:

timeout – Maximum time after which channel_error::timeout is returned.

Returns:

The rf_status and the data sent by the initiator, or any of the channel_error error conditions.

result<rf_status> target_response_to_initiator(std::vector<std::uint8_t> const &data, ms timeout = default_timeout)

Send a response packet to the initiator (UM0701-02 §7.3.21). This is similar to target_set_data, but here the PN532 does not handle supervisory, chaining, error handling and so on.

See also

target_set_data

Parameters:
  • data – Max 262 bytes, if exceeding, it will be truncated.

  • timeout – Maximum time after which channel_error::timeout is returned.

Returns:

The rf_status, or any of the channel_error error conditions.

Public Functions

explicit controller(std::shared_ptr<channel> chn)

Constructs a PN532 controller over the given channel implementation.

The immediate steps after constructing a PN532 controller should be then

  1. calling channel::wake to wake up the PN532;

  2. immediately afterwards, call sam_configuration. This is the procedure for priming the PN532 for usage

Parameters:

chn – An implementation of the PN532 communication channel. The caller is responsible of making sure that chn is a valid reference until this object is destructed.

controller(controller const&) = delete
controller(controller&&) = delete
controller &operator=(controller const&) = delete
controller &operator=(controller&&) = delete
bool init_and_test()

Performs SAM activation and some basic line and antenna tests. Normally this is what you call right after waking up the PN532 via channel::wake.

Returns:

True if all critical tests passed, false otherwise.

result<std::vector<target_kbps106_typeb>> initiator_list_passive_kbps106_typeb(std::uint8_t application_family_id, polling_method method = polling_method::timeslot, std::uint8_t max_targets = max_supported_targets, ms timeout = long_timeout)

List all TypeB tags in range (at 106kbps baudrate) (UM0701-02 §7.3.5).

Parameters:
Returns:

A list of targets target<baudrate_modulation::kbps106_iso_iec_14443_3_typeb>, or any of the channel_error error conditions.

result<std::vector<target_kbps212_felica>> initiator_list_passive_kbps212_felica(std::array<std::uint8_t, 5> const &payload, std::uint8_t max_targets = max_supported_targets, ms timeout = long_timeout)

List all FeliCa tags in range (at 212kbps baudrate) (UM0701-02 §7.3.5).

Parameters:
  • payload – The payload to send to the tags (structure defined in ISO/IEC 18092 §11.2.2.5).

  • max_targets – Max number of target to list and initialize.

  • timeout – Maximum time after which channel_error::timeout is returned.

Returns:

a list of targets target<baudrate_modulation::kbps212_felica>, or any of the channel_error error conditions.

result<std::vector<target_kbps424_felica>> initiator_list_passive_kbps424_felica(std::array<std::uint8_t, 5> const &payload, std::uint8_t max_targets = max_supported_targets, ms timeout = long_timeout)

List all FeliCa tags in range (at 424kbps baudrate) (UM0701-02 §7.3.5).

Parameters:
  • payload – The payload to send to the tags (structure defined in ISO/IEC 18092 §11.2.2.5).

  • max_targets – Max number of target to list and initialize.

  • timeout – Maximum time after which channel_error::timeout is returned.

Returns:

a list of targets target<baudrate_modulation::kbps424_felica>, or any of the channel_error error conditions.

result<std::vector<target_kbps106_jewel_tag>> initiator_list_passive_kbps106_jewel_tag(ms timeout = long_timeout)

List all Innovision Jewel tags in range (at 106kbps baudrate) (UM0701-02 §7.3.5).

Parameters:

timeout – Maximum time after which channel_error::timeout is returned.

Returns:

A list of targets target<baudrate_modulation::kbps106_innovision_jewel_tag>, or any of the channel_error error conditions.

result<std::vector<any_poll_target>> initiator_auto_poll(std::vector<target_type> const &types_to_poll = poll_all_targets, infbyte polls_per_type = 3_b, poll_period period = poll_period::ms_150, ms timeout = long_timeout)

Check specified tags in range, and automatically initialize them (UM0701-02 §7.3.13).

Note

timeout >= types_to_poll.size() * polls_per_type * period

Parameters:
  • types_to_poll – Minimum 1, maximum 15 elements.

  • polls_per_type – Poll attempts for each tag type. You can pass infty for infinite retries.

  • period – Time between each attempt.

  • timeout – Maximum time after which channel_error::timeout is returned.

Returns:

List of targets any_poll_target, or any of the channel_error error conditions.

result<rf_status, bin_data> initiator_communicate_through(bin_data raw_data, ms timeout = default_timeout)

Exchange data with the tag, but directly (no chaining and error handling) (UM0701-02 §7.3.9).

Parameters:
Returns:

The rf_status and the data sent by the target as a response, or any of the channel_error error conditions.

Public Static Attributes

static const std::vector<target_type> poll_all_targets

A list of all possible targets to poll.

Note

This does not contain every enum of target_type, but rather one target for each baudrate_modulation, which suffices for the PN532 to list all targets.

static constexpr auto max_supported_targets = bits::max_num_targets

Maximum number of targets the PN532 can scan for simultaneously.