17 static const uint16_t NFCC_DEFAULT_TIMEOUT = 10;
18 static const uint16_t NFCC_INIT_TIMEOUT = 50;
19 static const uint16_t NFCC_TAG_WRITE_TIMEOUT = 15;
21 static const uint8_t NFCC_MAX_COMM_FAILS = 3;
22 static const uint8_t NFCC_MAX_ERROR_COUNT = 10;
24 static const uint8_t XCHG_DATA_OID = 0x10;
25 static const uint8_t MF_SECTORSEL_OID = 0x32;
26 static const uint8_t MFC_AUTHENTICATE_OID = 0x40;
27 static const uint8_t TEST_PRBS_OID = 0x30;
28 static const uint8_t TEST_ANTENNA_OID = 0x3D;
29 static const uint8_t TEST_GET_REGISTER_OID = 0x33;
31 static const uint8_t MFC_AUTHENTICATE_PARAM_KS_A = 0x00;
32 static const uint8_t MFC_AUTHENTICATE_PARAM_KS_B = 0x80;
33 static const uint8_t MFC_AUTHENTICATE_PARAM_EMBED_KEY = 0x10;
35 static const uint8_t CARD_EMU_T4T_APP_SELECT[] = {0x00, 0xA4, 0x04, 0x00, 0x07, 0xD2, 0x76,
36 0x00, 0x00, 0x85, 0x01, 0x01, 0x00};
37 static const uint8_t CARD_EMU_T4T_CC[] = {0x00, 0x0F, 0x20, 0x00, 0xFF, 0x00, 0xFF, 0x04,
38 0x06, 0xE1, 0x04, 0x00, 0xFF, 0x00, 0x00};
39 static const uint8_t CARD_EMU_T4T_CC_SELECT[] = {0x00, 0xA4, 0x00, 0x0C, 0x02, 0xE1, 0x03};
40 static const uint8_t CARD_EMU_T4T_NDEF_SELECT[] = {0x00, 0xA4, 0x00, 0x0C, 0x02, 0xE1, 0x04};
41 static const uint8_t CARD_EMU_T4T_READ[] = {0x00, 0xB0};
42 static const uint8_t CARD_EMU_T4T_WRITE[] = {0x00, 0xD6};
43 static const uint8_t CARD_EMU_T4T_OK[] = {0x90, 0x00};
44 static const uint8_t CARD_EMU_T4T_NOK[] = {0x6A, 0x82};
46 static const uint8_t CORE_CONFIG_SOLO[] = {0x01,
52 static const uint8_t CORE_CONFIG_RW_CE[] = {0x01,
58 static const uint8_t PMU_CFG[] = {
77 static const uint8_t RF_DISCOVER_MAP_CONFIG[] = {
78 nfc::PROT_T1T, nfc::RF_DISCOVER_MAP_MODE_POLL,
80 nfc::PROT_T2T, nfc::RF_DISCOVER_MAP_MODE_POLL,
82 nfc::PROT_T3T, nfc::RF_DISCOVER_MAP_MODE_POLL,
84 nfc::PROT_ISODEP, nfc::RF_DISCOVER_MAP_MODE_POLL | nfc::RF_DISCOVER_MAP_MODE_LISTEN,
86 nfc::PROT_MIFARE, nfc::RF_DISCOVER_MAP_MODE_POLL,
89 static const uint8_t RF_DISCOVERY_LISTEN_CONFIG[] = {nfc::MODE_LISTEN_MASK | nfc::TECH_PASSIVE_NFCA,
90 nfc::MODE_LISTEN_MASK | nfc::TECH_PASSIVE_NFCB,
91 nfc::MODE_LISTEN_MASK | nfc::TECH_PASSIVE_NFCF};
93 static const uint8_t RF_DISCOVERY_POLL_CONFIG[] = {nfc::MODE_POLL | nfc::TECH_PASSIVE_NFCA,
94 nfc::MODE_POLL | nfc::TECH_PASSIVE_NFCB,
95 nfc::MODE_POLL | nfc::TECH_PASSIVE_NFCF};
97 static const uint8_t RF_DISCOVERY_CONFIG[] = {nfc::MODE_POLL | nfc::TECH_PASSIVE_NFCA,
98 nfc::MODE_POLL | nfc::TECH_PASSIVE_NFCB,
99 nfc::MODE_POLL | nfc::TECH_PASSIVE_NFCF,
100 nfc::MODE_LISTEN_MASK | nfc::TECH_PASSIVE_NFCA,
101 nfc::MODE_LISTEN_MASK | nfc::TECH_PASSIVE_NFCB,
102 nfc::MODE_LISTEN_MASK | nfc::TECH_PASSIVE_NFCF};
104 static const uint8_t RF_LISTEN_MODE_ROUTING_CONFIG[] = {0x00,
115 nfc::TECH_PASSIVE_NFCA};
156 std::unique_ptr<nfc::NfcTag>
tag;
162 void setup()
override;
163 void dump_config()
override;
165 void loop()
override;
173 void set_tag_emulation_message(std::shared_ptr<nfc::NdefMessage> message);
175 void set_tag_emulation_message(
const char *message,
bool include_android_app_record =
true);
176 void set_tag_emulation_off();
177 void set_tag_emulation_on();
180 void set_polling_off();
181 void set_polling_on();
188 this->on_emulated_tag_scan_callback_.add(std::move(callback));
192 this->on_finished_write_callback_.add(std::move(callback));
201 void set_tag_write_message(std::shared_ptr<nfc::NdefMessage> message);
204 uint8_t set_test_mode(
TestMode test_mode,
const std::vector<uint8_t> &data, std::vector<uint8_t> &result);
207 uint8_t reset_core_(
bool reset_config,
bool power);
208 uint8_t init_core_();
209 uint8_t send_init_config_();
210 uint8_t send_core_config_();
211 uint8_t refresh_core_config_();
213 uint8_t set_discover_map_();
215 uint8_t set_listen_mode_routing_();
217 uint8_t start_discovery_();
218 uint8_t stop_discovery_();
219 uint8_t deactivate_(uint8_t
type, uint16_t timeout = NFCC_DEFAULT_TIMEOUT);
221 void select_endpoint_();
224 uint8_t clean_endpoint_(std::vector<uint8_t> &uid);
225 uint8_t format_endpoint_(std::vector<uint8_t> &uid);
226 uint8_t write_endpoint_(std::vector<uint8_t> &uid, std::shared_ptr<nfc::NdefMessage> &message);
228 std::unique_ptr<nfc::NfcTag> build_tag_(uint8_t mode_tech,
const std::vector<uint8_t> &data);
230 void purge_old_tags_();
231 void erase_tag_(uint8_t tag_index);
234 void nci_fsm_transition_();
236 void nci_fsm_set_state_(
NCIState new_state);
238 bool nci_fsm_set_error_state_(
NCIState new_state);
240 void process_message_();
246 void card_emu_t4t_get_response_(std::vector<uint8_t> &response, std::vector<uint8_t> &ndef_response);
249 bool expect_notification =
true);
253 uint8_t wait_for_irq_(uint16_t timeout = NFCC_DEFAULT_TIMEOUT,
bool pin_state =
true);
255 uint8_t read_mifare_classic_tag_(
nfc::NfcTag &tag);
256 uint8_t read_mifare_classic_block_(uint8_t block_num, std::vector<uint8_t> &data);
257 uint8_t write_mifare_classic_block_(uint8_t block_num, std::vector<uint8_t> &data);
258 uint8_t auth_mifare_classic_block_(uint8_t block_num, uint8_t key_num,
const uint8_t *key);
259 uint8_t sect_to_auth_(uint8_t block_num);
260 uint8_t format_mifare_classic_mifare_();
261 uint8_t format_mifare_classic_ndef_();
262 uint8_t write_mifare_classic_tag_(
const std::shared_ptr<nfc::NdefMessage> &message);
263 uint8_t halt_mifare_classic_tag_();
265 uint8_t read_mifare_ultralight_tag_(
nfc::NfcTag &tag);
266 uint8_t read_mifare_ultralight_bytes_(uint8_t start_page, uint16_t num_bytes, std::vector<uint8_t> &data);
267 bool is_mifare_ultralight_formatted_(
const std::vector<uint8_t> &page_3_to_6);
268 uint16_t read_mifare_ultralight_capacity_();
269 uint8_t find_mifare_ultralight_ndef_(
const std::vector<uint8_t> &page_3_to_6, uint8_t &message_length,
270 uint8_t &message_start_index);
271 uint8_t write_mifare_ultralight_page_(uint8_t page_num, std::vector<uint8_t> &write_data);
272 uint8_t write_mifare_ultralight_tag_(std::vector<uint8_t> &uid,
const std::shared_ptr<nfc::NdefMessage> &message);
273 uint8_t clean_mifare_ultralight_();
280 } next_task_{EP_READ};
282 bool config_refresh_pending_{
false};
283 bool core_config_is_solo_{
false};
284 bool listening_enabled_{
false};
285 bool polling_enabled_{
true};
287 uint8_t error_count_{0};
288 uint8_t fail_count_{0};
289 uint32_t last_nci_state_change_{0};
290 uint8_t selecting_endpoint_{0};
291 uint32_t tag_ttl_{250};
void set_wkup_req_pin(GPIOPin *wkup_req_pin)
const float DATA
For components that import data from directly connected sensors like DHT.
void set_tag_ttl(uint32_t ttl)
std::shared_ptr< nfc::NdefMessage > next_task_message_to_write_
CallbackManager< void()> on_finished_write_callback_
void set_dwl_req_pin(GPIOPin *dwl_req_pin)
std::vector< DiscoveredEndpoint > discovered_endpoint_
std::vector< nfc::NfcOnTagTrigger * > triggers_ontagremoved_
std::vector< nfc::NfcOnTagTrigger * > triggers_ontag_
std::unique_ptr< nfc::NfcTag > tag
bool tag_emulation_enabled()
std::shared_ptr< nfc::NdefMessage > card_emulation_message_
void set_ven_pin(GPIOPin *ven_pin)
float get_setup_priority() const override
void set_irq_pin(GPIOPin *irq_pin)
void add_on_finished_write_callback(std::function< void()> callback)
void add_on_emulated_tag_scan_callback(std::function< void()> callback)
Implementation of SPI Controller mode.
void register_ontag_trigger(nfc::NfcOnTagTrigger *trig)
void register_ontagremoved_trigger(nfc::NfcOnTagTrigger *trig)
CallbackManager< void()> on_emulated_tag_scan_callback_