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[] = {
67 static const uint8_t RF_DISCOVER_MAP_CONFIG[] = {
68 nfc::PROT_T1T, nfc::RF_DISCOVER_MAP_MODE_POLL,
70 nfc::PROT_T2T, nfc::RF_DISCOVER_MAP_MODE_POLL,
72 nfc::PROT_T3T, nfc::RF_DISCOVER_MAP_MODE_POLL,
74 nfc::PROT_ISODEP, nfc::RF_DISCOVER_MAP_MODE_POLL | nfc::RF_DISCOVER_MAP_MODE_LISTEN,
76 nfc::PROT_MIFARE, nfc::RF_DISCOVER_MAP_MODE_POLL,
79 static const uint8_t RF_DISCOVERY_LISTEN_CONFIG[] = {nfc::MODE_LISTEN_MASK | nfc::TECH_PASSIVE_NFCA,
80 nfc::MODE_LISTEN_MASK | nfc::TECH_PASSIVE_NFCB,
81 nfc::MODE_LISTEN_MASK | nfc::TECH_PASSIVE_NFCF};
83 static const uint8_t RF_DISCOVERY_POLL_CONFIG[] = {nfc::MODE_POLL | nfc::TECH_PASSIVE_NFCA,
84 nfc::MODE_POLL | nfc::TECH_PASSIVE_NFCB,
85 nfc::MODE_POLL | nfc::TECH_PASSIVE_NFCF};
87 static const uint8_t RF_DISCOVERY_CONFIG[] = {nfc::MODE_POLL | nfc::TECH_PASSIVE_NFCA,
88 nfc::MODE_POLL | nfc::TECH_PASSIVE_NFCB,
89 nfc::MODE_POLL | nfc::TECH_PASSIVE_NFCF,
90 nfc::MODE_LISTEN_MASK | nfc::TECH_PASSIVE_NFCA,
91 nfc::MODE_LISTEN_MASK | nfc::TECH_PASSIVE_NFCB,
92 nfc::MODE_LISTEN_MASK | nfc::TECH_PASSIVE_NFCF};
94 static const uint8_t RF_LISTEN_MODE_ROUTING_CONFIG[] = {0x00,
141 std::unique_ptr<nfc::NfcTag>
tag;
147 void setup()
override;
148 void dump_config()
override;
150 void loop()
override;
156 void set_tag_emulation_message(std::shared_ptr<nfc::NdefMessage> message);
158 void set_tag_emulation_message(
const char *message,
bool include_android_app_record =
true);
159 void set_tag_emulation_off();
160 void set_tag_emulation_on();
163 void set_polling_off();
164 void set_polling_on();
171 this->on_emulated_tag_scan_callback_.add(std::move(callback));
175 this->on_finished_write_callback_.add(std::move(callback));
184 void set_tag_write_message(std::shared_ptr<nfc::NdefMessage> message);
187 uint8_t set_test_mode(
TestMode test_mode,
const std::vector<uint8_t> &data, std::vector<uint8_t> &result);
190 uint8_t reset_core_(
bool reset_config,
bool power);
191 uint8_t init_core_();
192 uint8_t send_init_config_();
193 uint8_t send_core_config_();
194 uint8_t refresh_core_config_();
196 uint8_t set_discover_map_();
198 uint8_t set_listen_mode_routing_();
200 uint8_t start_discovery_();
201 uint8_t stop_discovery_();
202 uint8_t deactivate_(uint8_t
type, uint16_t timeout = NFCC_DEFAULT_TIMEOUT);
204 void select_endpoint_();
207 uint8_t clean_endpoint_(std::vector<uint8_t> &uid);
208 uint8_t format_endpoint_(std::vector<uint8_t> &uid);
209 uint8_t write_endpoint_(std::vector<uint8_t> &uid, std::shared_ptr<nfc::NdefMessage> &message);
211 std::unique_ptr<nfc::NfcTag> build_tag_(uint8_t mode_tech,
const std::vector<uint8_t> &data);
213 void purge_old_tags_();
214 void erase_tag_(uint8_t tag_index);
217 void nci_fsm_transition_();
219 void nci_fsm_set_state_(
NCIState new_state);
221 bool nci_fsm_set_error_state_(
NCIState new_state);
223 void process_message_();
229 void card_emu_t4t_get_response_(std::vector<uint8_t> &response, std::vector<uint8_t> &ndef_response);
232 bool expect_notification =
true);
236 uint8_t wait_for_irq_(uint16_t timeout = NFCC_DEFAULT_TIMEOUT,
bool pin_state =
true);
238 uint8_t read_mifare_classic_tag_(
nfc::NfcTag &tag);
239 uint8_t read_mifare_classic_block_(uint8_t block_num, std::vector<uint8_t> &data);
240 uint8_t write_mifare_classic_block_(uint8_t block_num, std::vector<uint8_t> &data);
241 uint8_t auth_mifare_classic_block_(uint8_t block_num, uint8_t key_num,
const uint8_t *key);
242 uint8_t sect_to_auth_(uint8_t block_num);
243 uint8_t format_mifare_classic_mifare_();
244 uint8_t format_mifare_classic_ndef_();
245 uint8_t write_mifare_classic_tag_(
const std::shared_ptr<nfc::NdefMessage> &message);
246 uint8_t halt_mifare_classic_tag_();
248 uint8_t read_mifare_ultralight_tag_(
nfc::NfcTag &tag);
249 uint8_t read_mifare_ultralight_bytes_(uint8_t start_page, uint16_t num_bytes, std::vector<uint8_t> &data);
250 bool is_mifare_ultralight_formatted_(
const std::vector<uint8_t> &page_3_to_6);
251 uint16_t read_mifare_ultralight_capacity_();
252 uint8_t find_mifare_ultralight_ndef_(
const std::vector<uint8_t> &page_3_to_6, uint8_t &message_length,
253 uint8_t &message_start_index);
254 uint8_t write_mifare_ultralight_page_(uint8_t page_num, std::vector<uint8_t> &write_data);
255 uint8_t write_mifare_ultralight_tag_(std::vector<uint8_t> &uid,
const std::shared_ptr<nfc::NdefMessage> &message);
256 uint8_t clean_mifare_ultralight_();
263 } next_task_{EP_READ};
265 bool config_refresh_pending_{
false};
266 bool core_config_is_solo_{
false};
267 bool listening_enabled_{
false};
268 bool polling_enabled_{
true};
270 uint8_t error_count_{0};
271 uint8_t fail_count_{0};
272 uint32_t last_nci_state_change_{0};
273 uint8_t selecting_endpoint_{0};
274 uint32_t tag_ttl_{250};
const float DATA
For components that import data from directly connected sensors like DHT.
float get_setup_priority() const override
CallbackManager< void()> on_finished_write_callback_
CallbackManager< void()> on_emulated_tag_scan_callback_
bool tag_emulation_enabled()
std::vector< nfc::NfcOnTagTrigger * > triggers_ontag_
void set_irq_pin(GPIOPin *irq_pin)
std::unique_ptr< nfc::NfcTag > tag
void set_ven_pin(GPIOPin *ven_pin)
std::shared_ptr< nfc::NdefMessage > next_task_message_to_write_
void register_ontagremoved_trigger(nfc::NfcOnTagTrigger *trig)
std::vector< nfc::NfcOnTagTrigger * > triggers_ontagremoved_
void set_tag_ttl(uint32_t ttl)
void register_ontag_trigger(nfc::NfcOnTagTrigger *trig)
std::vector< DiscoveredEndpoint > discovered_endpoint_
void add_on_finished_write_callback(std::function< void()> callback)
Implementation of SPI Controller mode.
void add_on_emulated_tag_scan_callback(std::function< void()> callback)
std::shared_ptr< nfc::NdefMessage > card_emulation_message_