Skip to content

Commit d4ceca7

Browse files
committed
Squashed 'examples/UnitUnified/NFCA/' changes from e0b71c1..be003e8
be003e8 Cosmetic change a7e8f57 Refactoring(WIP) git-subtree-dir: examples/UnitUnified/NFCA git-subtree-split: be003e8b0676bce520c4a5d4e5b39babac4326be
1 parent 0dac8ba commit d4ceca7

2 files changed

Lines changed: 18 additions & 19 deletions

File tree

NDEF/main/NDEF.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ void format_desfire()
108108
M5_LOGW("DESFire light can NOT format");
109109
return;
110110
} else {
111-
if (!dfs.formatPICC(type4::DESFIRE_DEFAULT_KEY)) {
111+
if (!dfs.formatPICC(desfire::DESFIRE_DEFAULT_KEY)) {
112112
M5_LOGE("Failed to formatPICC");
113113
return;
114114
}
@@ -247,7 +247,7 @@ void write_ndef()
247247
lcd.fillScreen(TFT_RED);
248248
return;
249249
}
250-
// nfc_a.dump();
250+
M5.Log.printf("Write NDEF OK!\n");
251251
}
252252

253253
} // namespace

ReadWrite/main/ReadWrite.cpp

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -64,44 +64,44 @@ constexpr classic::Key keyA = classic::DEFAULT_KEY; // Default as 0xFFFFFFFFFFF
6464
// If it's a different key value, change it
6565
constexpr plus::AESKey aesKeyA = plus::DEFAULT_FF_KEY; // all 0xFF
6666

67-
constexpr int8_t kAccessDenied{-1};
68-
constexpr int8_t kAccessFree{-2};
67+
constexpr int8_t access_denied{-1};
68+
constexpr int8_t access_free{-2};
6969
int8_t required_key_no_for_read(const uint16_t access_rights)
7070
{
7171
const uint8_t read_key = (access_rights >> 12) & 0x0F; // Read
7272
const uint8_t rw_key = (access_rights >> 4) & 0x0F; // Read/Write
7373
if (read_key == 0x0E) {
74-
return kAccessFree;
74+
return access_free;
7575
}
7676
if (read_key != 0x0F) {
7777
return read_key;
7878
}
7979
if (rw_key == 0x0E) {
80-
return kAccessFree;
80+
return access_free;
8181
}
8282
if (rw_key != 0x0F) {
8383
return rw_key;
8484
}
85-
return kAccessDenied;
85+
return access_denied;
8686
}
8787

8888
int8_t required_key_no_for_write(const uint16_t access_rights)
8989
{
9090
const uint8_t write_key = (access_rights >> 8) & 0x0F; // Write
9191
const uint8_t rw_key = (access_rights >> 4) & 0x0F; // Read/Write
9292
if (write_key == 0x0E) {
93-
return kAccessFree;
93+
return access_free;
9494
}
9595
if (write_key != 0x0F) {
9696
return write_key;
9797
}
9898
if (rw_key == 0x0E) {
99-
return kAccessFree;
99+
return access_free;
100100
}
101101
if (rw_key != 0x0F) {
102102
return rw_key;
103103
}
104-
return kAccessDenied;
104+
return access_denied;
105105
}
106106

107107
constexpr char long_msg[] =
@@ -339,7 +339,7 @@ bool read_write_desfire()
339339
}
340340

341341
// PICC Auth
342-
const uint8_t* default_key = m5::nfc::ndef::type4::DESFIRE_DEFAULT_KEY;
342+
const uint8_t* default_key = desfire::DESFIRE_DEFAULT_KEY;
343343
bool picc_auth_des = dfs.authenticateDES(0x00, default_key);
344344
bool picc_auth_iso = !picc_auth_des && dfs.authenticateISO(0x00, default_key);
345345
bool picc_auth_aes = (!picc_auth_des && !picc_auth_iso) && dfs.authenticateAES(0x00, default_key);
@@ -483,7 +483,7 @@ bool read_write_desfire_light()
483483

484484
desfire::DESFireFileSystem dfs(nfc_a);
485485

486-
const uint8_t* default_key = m5::nfc::ndef::type4::DESFIRE_DEFAULT_KEY;
486+
const uint8_t* default_key = desfire::DESFIRE_DEFAULT_KEY;
487487
desfire::Ev2Context ev2_ctx{};
488488
bool ev2_ok = false;
489489
uint8_t ev2_key_no = 0x00;
@@ -506,8 +506,7 @@ bool read_write_desfire_light()
506506
}
507507
if (!settings_ok) {
508508
if (!dfs.selectDfNameAuto(m5::nfc::ndef::type4::NDEF_AID, sizeof(m5::nfc::ndef::type4::NDEF_AID))) {
509-
dfs.selectDfNameAuto(m5::nfc::ndef::type4::DESFIRE_LIGHT_DF_NAME,
510-
sizeof(m5::nfc::ndef::type4::DESFIRE_LIGHT_DF_NAME));
509+
dfs.selectDfNameAuto(desfire::DESFIRE_LIGHT_DF_NAME, sizeof(desfire::DESFIRE_LIGHT_DF_NAME));
511510
}
512511
ev2_ok = false;
513512
if (ensure_ev2()) {
@@ -537,19 +536,19 @@ bool read_write_desfire_light()
537536
const bool use_full = fs.comm_mode == 3;
538537
const int8_t read_key = required_key_no_for_read(fs.access_rights);
539538
const int8_t write_key = required_key_no_for_write(fs.access_rights);
540-
if (read_key == kAccessDenied || write_key == kAccessDenied) {
539+
if (read_key == access_denied || write_key == access_denied) {
541540
M5_LOGE("Access denied for file (read=%d write=%d)", read_key, write_key);
542541
return false;
543542
}
544543

545544
auto auth_with_key = [&](const int8_t key) -> bool {
546-
if (key == kAccessDenied) {
545+
if (key == access_denied) {
547546
return false;
548547
}
549-
if (key == kAccessFree && !use_ev2) {
548+
if (key == access_free && !use_ev2) {
550549
return true;
551550
}
552-
const uint8_t desired_key = (key == kAccessFree) ? 0x00 : static_cast<uint8_t>(key);
551+
const uint8_t desired_key = (key == access_free) ? 0x00 : static_cast<uint8_t>(key);
553552
if (!ev2_ok || ev2_key_no != desired_key) {
554553
ev2_ok = false;
555554
ev2_key_no = desired_key;
@@ -715,7 +714,7 @@ void loop()
715714
M5.Log.printf("This example is not supported\n");
716715
}
717716
} else if (held) {
718-
nfc_a.dump();
717+
// nfc_a.dump();
719718
M5.Speaker.tone(4000, 30);
720719
if (picc.isMifareClassic()) {
721720
read_write_sector_structure(picc.blocks - 2);

0 commit comments

Comments
 (0)