mifare_ctrl.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  1. /**
  2. * Copyright (C) 2011 Anders Sundman <anders@4zm.org>
  3. *
  4. * This file is part of mfterm.
  5. *
  6. * mfterm is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. * mfterm is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. * You should have received a copy of the GNU General Public License
  15. * along with mfterm. If not, see <http://www.gnu.org/licenses/>.
  16. *
  17. * Parts of code used in this file are based on the Public platform
  18. * independent Near Field Communication (NFC) library example
  19. * nfc-mfclassic.c. It is thus covered by that license as well:
  20. *
  21. * Copyright (C) 2009, Roel Verdult
  22. * Copyright (C) 2010, Romuald Conty, Romain Tartière
  23. * Copyright (C) 2011, Adam Laurie
  24. *
  25. * Redistribution and use in source and binary forms, with or without
  26. * modification, are permitted provided that the following conditions are met:
  27. * 1) Redistributions of source code must retain the above copyright notice,
  28. * this list of conditions and the following disclaimer.
  29. * 2 )Redistributions in binary form must reproduce the above copyright
  30. * notice, this list of conditions and the following disclaimer in the
  31. * documentation and/or other materials provided with the distribution.
  32. *
  33. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  34. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  35. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  36. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
  37. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  38. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  39. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  40. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  41. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  42. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  43. * POSSIBILITY OF SUCH DAMAGE.
  44. */
  45. #include <stdio.h>
  46. #include <string.h>
  47. #include <nfc/nfc.h>
  48. #include "mifare.h"
  49. #include "tag.h"
  50. #include "mifare_ctrl.h"
  51. // State of the device/tag - should be NULL between high level calls.
  52. static nfc_device* device = NULL;
  53. static nfc_target target;
  54. static mf_size_t size;
  55. static nfc_context* context;
  56. static const nfc_modulation mf_nfc_modulation = {
  57. .nmt = NMT_ISO14443A,
  58. .nbr = NBR_106,
  59. };
  60. // Buffers used for raw bit/byte writes
  61. #define MAX_FRAME_LEN 264
  62. static uint8_t abtRx[MAX_FRAME_LEN];
  63. static int szRxBits;
  64. int mf_connect();
  65. int mf_disconnect(int ret_state);
  66. bool mf_configure_device();
  67. bool mf_select_target();
  68. bool mf_authenticate(size_t block,
  69. const uint8_t* key,
  70. mf_key_type_t key_type);
  71. bool mf_unlock();
  72. bool mf_read_tag_internal(mf_tag_t* tag,
  73. const mf_tag_t* keys,
  74. mf_key_type_t key_type);
  75. bool mf_write_tag_internal(const mf_tag_t* tag,
  76. const mf_tag_t* keys,
  77. mf_key_type_t key_type);
  78. bool mf_dictionary_attack_internal(mf_tag_t* tag);
  79. bool mf_test_auth_internal(const mf_tag_t* keys,
  80. mf_size_t size,
  81. mf_key_type_t key_type);
  82. bool transmit_bits(const uint8_t *pbtTx, const size_t szTxBits);
  83. bool transmit_bytes(const uint8_t *pbtTx, const size_t szTx);
  84. int mf_disconnect(int ret_state) {
  85. nfc_close(device);
  86. nfc_exit(context);
  87. device = NULL;
  88. memset(&target, 0, sizeof(target));
  89. return ret_state;
  90. }
  91. int mf_connect() {
  92. // Initialize libnfc and set the nfc_context
  93. nfc_init(&context);
  94. // Connect to (any) NFC reader
  95. device = nfc_open(context, NULL);
  96. if (device == NULL) {
  97. printf ("Could not connect to any NFC device\n");
  98. return -1; // Don't jump here, since we don't need to disconnect
  99. }
  100. // Initialize the device as a reader
  101. if (!mf_configure_device()) {
  102. printf("Error initializing NFC device\n");
  103. return mf_disconnect(-1);
  104. }
  105. // Try to find a tag
  106. if (!mf_select_target() || target.nti.nai.btSak == 0) {
  107. printf("Connected to device, but no tag found.\n");
  108. return mf_disconnect(-1);
  109. }
  110. // Allow SAK & ATQA == 0. Assume 1k pirate card.
  111. if (target.nti.nai.btSak == 0 && target.nti.nai.abtAtqa[1] == 0) {
  112. size = MF_1K;
  113. return 0;
  114. }
  115. // Test if we are dealing with a Mifare Classic compatible tag
  116. if ((target.nti.nai.btSak & 0x08) == 0) {
  117. printf("Incompatible tag type: 0x%02x (i.e. not Mifare Classic).\n",
  118. target.nti.nai.btSak);
  119. return mf_disconnect(-1);
  120. }
  121. // Guessing tag size
  122. if ((target.nti.nai.abtAtqa[1] & 0x02)) { // 4K
  123. size = MF_4K;
  124. }
  125. else if ((target.nti.nai.abtAtqa[1] & 0x04)) { // 1K
  126. size = MF_1K;
  127. }
  128. else {
  129. printf("Unsupported tag size. ATQA 0x%02x 0x%02x (i.e. not [1|4]K.)\n",
  130. target.nti.nai.abtAtqa[0], target.nti.nai.abtAtqa[1]);
  131. return mf_disconnect(-1);
  132. }
  133. return 0; // Indicate success - we are now connected
  134. }
  135. int mf_read_tag(mf_tag_t* tag, mf_key_type_t key_type) {
  136. if (mf_connect())
  137. return -1; // No need to disconnect here
  138. if (key_type == MF_KEY_UNLOCKED) {
  139. if (!mf_unlock()) {
  140. printf("Unlocked read requested, but unlock failed!\n");
  141. return false;
  142. }
  143. }
  144. if (!mf_read_tag_internal(tag, &current_auth, key_type)) {
  145. printf("Read failed!\n");
  146. return mf_disconnect(-1);
  147. }
  148. // Print the type of card
  149. if (target.nti.nai.btSak == 0x08 &&
  150. target.nti.nai.abtAtqa[0] == 0x00 && target.nti.nai.abtAtqa[1] == 0x04) {
  151. printf("Read MIFARE Classic 1k (SAK: 08, ATQA: 00 04)\n");
  152. }
  153. else if (target.nti.nai.btSak == 0x18 &&
  154. target.nti.nai.abtAtqa[0] == 0x00 && target.nti.nai.abtAtqa[1] == 0x02) {
  155. printf("Read MIFARE Classic 4k (SAK: 18, ATQA: 00 02)\n");
  156. }
  157. else {
  158. printf("Read unknown tag.\n");
  159. }
  160. return mf_disconnect(0);
  161. }
  162. int mf_write_tag(const mf_tag_t* tag, mf_key_type_t key_type) {
  163. if (mf_connect())
  164. return -1; // No need to disconnect here
  165. if (key_type == MF_KEY_UNLOCKED) {
  166. if (!mf_unlock()) {
  167. printf("Unlocked write requested, but unlock failed!\n");
  168. return false;
  169. }
  170. }
  171. if (!mf_write_tag_internal(tag, &current_auth, key_type)) {
  172. printf("Write failed!\n");
  173. return mf_disconnect(-1);
  174. }
  175. return mf_disconnect(0);
  176. }
  177. int mf_dictionary_attack(mf_tag_t* tag) {
  178. if (mf_connect()) {
  179. return -1; // No need to disconnect here
  180. }
  181. if (!mf_dictionary_attack_internal(tag)) {
  182. printf("Dictionary attack failed!\n");
  183. return mf_disconnect(-1);
  184. }
  185. return mf_disconnect(0);
  186. }
  187. int mf_test_auth(const mf_tag_t* keys,
  188. mf_size_t size,
  189. mf_key_type_t key_type) {
  190. if (mf_connect()) {
  191. return -1; // No need to disconnect here
  192. }
  193. if (!mf_test_auth_internal(keys, size, key_type)) {
  194. printf("Test authentication failed!\n");
  195. return mf_disconnect(-1);
  196. }
  197. return mf_disconnect(0);
  198. }
  199. bool mf_configure_device() {
  200. // Disallow invalid frame
  201. if (nfc_device_set_property_bool(device, NP_ACCEPT_INVALID_FRAMES, false) < 0)
  202. return false;
  203. // Disallow multiple frames
  204. if (nfc_device_set_property_bool(device, NP_ACCEPT_MULTIPLE_FRAMES, false) < 0)
  205. return false;
  206. // Make sure we reset the CRC and parity to chip handling.
  207. if (nfc_device_set_property_bool(device, NP_HANDLE_CRC, true) < 0)
  208. return false;
  209. if (nfc_device_set_property_bool(device, NP_HANDLE_PARITY, true) < 0)
  210. return false;
  211. // Disable ISO14443-4 switching in order to read devices that emulate
  212. // Mifare Classic with ISO14443-4 compliance.
  213. if (nfc_device_set_property_bool(device, NP_AUTO_ISO14443_4, false) < 0)
  214. return false;
  215. // Activate "easy framing" feature by default
  216. if (nfc_device_set_property_bool(device, NP_EASY_FRAMING, true) < 0)
  217. return false;
  218. // Deactivate the CRYPTO1 cipher, it may could cause problems when
  219. // still active
  220. if (nfc_device_set_property_bool(device, NP_ACTIVATE_CRYPTO1, false) < 0)
  221. return false;
  222. // Drop explicitely the field
  223. if (nfc_device_set_property_bool(device, NP_ACTIVATE_FIELD, false) < 0)
  224. return false;
  225. // Override default initialization option, only try to select a tag once.
  226. if (nfc_device_set_property_bool(device, NP_INFINITE_SELECT, false) < 0)
  227. return false;
  228. return true;
  229. }
  230. bool mf_select_target() {
  231. if (nfc_initiator_select_passive_target(device,
  232. mf_nfc_modulation,
  233. NULL, // init data
  234. 0, // init data len
  235. &target) < 0) {
  236. return false;
  237. }
  238. return true;
  239. }
  240. /**
  241. * Unlocking the card allows writing to block 0 of some pirate cards.
  242. */
  243. bool mf_unlock() {
  244. static uint8_t abtHalt[4] = { 0x50, 0x00, 0x00, 0x00 };
  245. // Special unlock command
  246. static const uint8_t abtUnlock1[1] = { 0x40 };
  247. static const uint8_t abtUnlock2[1] = { 0x43 };
  248. // Disable CRC and parity checking
  249. if (nfc_device_set_property_bool(device, NP_HANDLE_CRC, false) < 0)
  250. return false;
  251. // Disable easy framing. Use raw send/receive methods
  252. if (nfc_device_set_property_bool (device, NP_EASY_FRAMING, false) < 0)
  253. return false;
  254. // Initialize transmision
  255. iso14443a_crc_append(abtHalt, 2);
  256. transmit_bytes(abtHalt, 4);
  257. // Send unlock
  258. if (!transmit_bits (abtUnlock1, 7))
  259. return false;
  260. if (!transmit_bytes (abtUnlock2, 1))
  261. return false;
  262. // Reset reader configuration. CRC and easy framing.
  263. if (nfc_device_set_property_bool (device, NP_HANDLE_CRC, true) < 0)
  264. return false;
  265. if (nfc_device_set_property_bool (device, NP_EASY_FRAMING, true) < 0)
  266. return false;
  267. return true;
  268. }
  269. bool mf_read_tag_internal(mf_tag_t* tag,
  270. const mf_tag_t* keys, mf_key_type_t key_type) {
  271. mifare_param mp;
  272. static mf_tag_t buffer_tag;
  273. clear_tag(&buffer_tag);
  274. int error = 0;
  275. printf("Reading: ["); fflush(stdout);
  276. // Read the card from end to begin
  277. for (int block_it = (int)block_count(size) - 1; block_it >= 0; --block_it) {
  278. size_t block = (size_t)block_it;
  279. // Print progress for the unlocked read
  280. if (key_type == MF_KEY_UNLOCKED && is_trailer_block(block))
  281. printf("."); fflush(stdout);
  282. // Authenticate everytime we reach a trailer block
  283. // unless we are doing an unlocked read
  284. if (key_type != MF_KEY_UNLOCKED && is_trailer_block(block)) {
  285. // Try to authenticate for the current sector
  286. uint8_t* key = key_from_tag(keys, key_type, block);
  287. if (!mf_authenticate(block, key, key_type)) {
  288. // Progress indication and error report
  289. printf("0x%02zx", block_to_sector(block));
  290. if (block != 3) printf(".");
  291. fflush(stdout);
  292. block_it -= (int)sector_size(block) - 1; // Skip the rest of the sector blocks
  293. error = 1;
  294. }
  295. else {
  296. // Try to read the trailer (only to *read* the access bits)
  297. if (nfc_initiator_mifare_cmd(device, MC_READ, (uint8_t)block, &mp)) {
  298. // Copy the keys over to our tag buffer
  299. key_to_tag(&buffer_tag, keys->amb[block].mbt.abtKeyA, MF_KEY_A, block);
  300. key_to_tag(&buffer_tag, keys->amb[block].mbt.abtKeyB, MF_KEY_B, block);
  301. // Store the retrieved access bits in the tag buffer
  302. memcpy(buffer_tag.amb[block].mbt.abtAccessBits,
  303. mp.mpd.abtData + 6, 4);
  304. } else {
  305. printf ("\nUnable to read trailer block: 0x%02zx.\n", block);
  306. return false;
  307. }
  308. printf("."); fflush(stdout); // Progress indicator
  309. }
  310. }
  311. else { // I.e. not a sector trailer
  312. // Try to read out the block
  313. if (!nfc_initiator_mifare_cmd(device, MC_READ, (uint8_t)block, &mp)) {
  314. printf("\nUnable to read block: 0x%02zx.\n", block);
  315. return false;
  316. }
  317. memcpy(buffer_tag.amb[block].mbd.abtData, mp.mpd.abtData, 0x10);
  318. }
  319. }
  320. // Terminate progress indicator
  321. if (error)
  322. printf("] Auth errors in indicated sectors.\n");
  323. else
  324. printf("] Success!\n");
  325. // Success! Copy the data
  326. // todo: Or return static ptr?
  327. memcpy(tag, &buffer_tag, MF_4K);
  328. return true;
  329. }
  330. bool mf_write_tag_internal(const mf_tag_t* tag,
  331. const mf_tag_t* keys,
  332. mf_key_type_t key_type) {
  333. mifare_param mp;
  334. int error = 0;
  335. printf("Writing %s tag [", sprint_size(size)); fflush(stdout);
  336. // Process each sector in turn
  337. for (int header_block_it = sector_header_iterator(0);
  338. header_block_it != -1;
  339. header_block_it = sector_header_iterator(size)) {
  340. size_t header_block = (size_t)header_block_it;
  341. // Authenticate
  342. uint8_t* key = key_from_tag(keys, key_type, header_block);
  343. if (key_type != MF_KEY_UNLOCKED) {
  344. if (!mf_authenticate(header_block, key, key_type)) {
  345. // Progress indication and error report
  346. if (header_block != 0) printf(".");
  347. printf("0x%02zx", block_to_sector(header_block));
  348. fflush(stdout);
  349. error = 1;
  350. continue; // Skip the rest of the sector blocks
  351. }
  352. }
  353. // Write the sectors blocks
  354. for (size_t block = header_block, trailer = block_to_trailer(header_block);
  355. block < trailer; ++block) {
  356. // First block on tag is read only - skip it unless unlocked
  357. if (block == 0 && key_type != MF_KEY_UNLOCKED)
  358. continue;
  359. // Try to write the data block
  360. memcpy (mp.mpd.abtData, tag->amb[block].mbd.abtData, 0x10);
  361. // do not write a block 0 with incorrect BCC - card will be made invalid!
  362. if (block == 0) {
  363. if((mp.mpd.abtData[0] ^ mp.mpd.abtData[1] ^ mp.mpd.abtData[2] ^
  364. mp.mpd.abtData[3] ^ mp.mpd.abtData[4]) != 0x00) {
  365. printf ("\nError: incorrect BCC in MFD file!\n"); // ADD DATA
  366. return false;
  367. }
  368. }
  369. // Write the data block
  370. if (!nfc_initiator_mifare_cmd(device, MC_WRITE, (uint8_t)block, &mp)) {
  371. printf("\nUnable to write block: 0x%02zx.\n", block);
  372. return false;
  373. }
  374. }
  375. // Auth ok and sector read ok, finish up by reading trailer
  376. size_t trailer_block = block_to_trailer(header_block);
  377. memcpy (mp.mpd.abtData, tag->amb[trailer_block].mbt.abtKeyA, 6);
  378. memcpy (mp.mpd.abtData + 6, tag->amb[trailer_block].mbt.abtAccessBits, 4);
  379. memcpy (mp.mpd.abtData + 10, tag->amb[trailer_block].mbt.abtKeyB, 6);
  380. // Try to write the trailer
  381. if (!nfc_initiator_mifare_cmd(device, MC_WRITE, (uint8_t)trailer_block, &mp)) {
  382. printf("\nUnable to write block: 0x%02zx.\n", trailer_block);
  383. return false;
  384. }
  385. printf("."); fflush(stdout); // Progress indicator
  386. }
  387. // Terminate progress indicator
  388. if (error)
  389. printf("] Auth errors in indicated sectors.\n");
  390. else
  391. printf("] Success!\n");
  392. return true;
  393. }
  394. bool mf_dictionary_attack_internal(mf_tag_t* tag) {
  395. // Tag buffer to swap in if we find all keys
  396. int all_keys_found = 1;
  397. static mf_tag_t buffer_tag;
  398. clear_tag(&buffer_tag);
  399. // Iterate over the start blocks in all sectors
  400. for (int block_it = sector_header_iterator(0);
  401. block_it != -1;
  402. block_it = sector_header_iterator(size)) {
  403. size_t block = (size_t)block_it;
  404. printf("Working on sector: %02zx [", block_to_sector(block));
  405. const uint8_t* key_a = NULL;
  406. const uint8_t* key_b = NULL;
  407. // Iterate we run out of dictionary keys or the sector is cracked
  408. const key_list_t* key_it = dictionary_get();
  409. while(key_it && (key_a == NULL || key_b == NULL)) {
  410. // Try to authenticate for the current sector
  411. if (key_a == NULL &&
  412. mf_authenticate(block, key_it->key, MF_KEY_A)) {
  413. key_a = key_it->key;
  414. }
  415. // Try to authenticate for the current sector
  416. if (key_b == NULL &&
  417. mf_authenticate(block, key_it->key, MF_KEY_B)) {
  418. key_b = key_it->key;
  419. }
  420. key_it = key_it->next;
  421. printf("."); fflush(stdout); // Progress indicator
  422. }
  423. printf("]\n");
  424. printf(" A Key: ");
  425. if (key_a) {
  426. printf("%s\n", sprint_key(key_a));
  427. // Optimize dictionary by moving key to the front
  428. dictionary_add(key_a);
  429. // Save key in the buffer
  430. key_to_tag(&buffer_tag, key_a, MF_KEY_A, block);
  431. }
  432. else {
  433. all_keys_found = 0;
  434. printf("Not found\n");
  435. }
  436. printf(" B Key: ");
  437. if (key_b) {
  438. printf("%s\n", sprint_key(key_b));
  439. // Optimize dictionary by moving key to the front
  440. dictionary_add(key_b);
  441. // Save key in the buffer
  442. key_to_tag(&buffer_tag, key_b, MF_KEY_B, block);
  443. }
  444. else {
  445. all_keys_found = 0;
  446. printf("Not found\n");
  447. }
  448. }
  449. if (all_keys_found)
  450. printf("All keys were found\n");
  451. // Use the found keys
  452. memcpy(tag, &buffer_tag, MF_4K);
  453. return true;
  454. }
  455. bool mf_test_auth_internal(const mf_tag_t* keys,
  456. mf_size_t size,
  457. mf_key_type_t key_type) {
  458. printf("xS T Key Status\n");
  459. printf("----------------------------\n");
  460. for (int block_it = sector_header_iterator(0);
  461. block_it != -1;
  462. block_it = sector_header_iterator(size)) {
  463. size_t block = (size_t)block_it;
  464. uint8_t* key = key_from_tag(keys, key_type, block);
  465. printf("%02zx %c %s ",
  466. block_to_sector(block),
  467. key_type,
  468. sprint_key(key));
  469. if (!mf_authenticate(block, key, key_type)) {
  470. printf("Failure");
  471. }
  472. else {
  473. printf("Success");
  474. }
  475. printf("\n");
  476. }
  477. return true;
  478. }
  479. bool mf_authenticate(size_t block, const uint8_t* key, mf_key_type_t key_type) {
  480. mifare_param mp;
  481. // Set the authentication information (uid)
  482. memcpy(mp.mpa.abtAuthUid, target.nti.nai.abtUid + target.nti.nai.szUidLen - 4, 4);
  483. // Select key for authentication
  484. mifare_cmd mc = (key_type == MF_KEY_A) ? MC_AUTH_A : MC_AUTH_B;
  485. // Set the key
  486. memcpy(mp.mpa.abtKey, key, 6);
  487. // Try to authenticate for the current sector
  488. if (nfc_initiator_mifare_cmd(device, mc, (uint8_t)block, &mp))
  489. return true;
  490. // Do the hand shaking again if auth failed
  491. nfc_initiator_select_passive_target(device, mf_nfc_modulation,
  492. NULL, 0, &target);
  493. return false;
  494. }
  495. bool transmit_bits(const uint8_t *pbtTx, const size_t szTxBits)
  496. {
  497. // Transmit the bit frame command, we don't use the arbitrary parity feature
  498. if ((szRxBits = nfc_initiator_transceive_bits(device, pbtTx, szTxBits, NULL, abtRx, sizeof(abtRx), NULL)) < 0)
  499. return false;
  500. return true;
  501. }
  502. bool transmit_bytes(const uint8_t *pbtTx, const size_t szTx)
  503. {
  504. // Transmit the command bytes
  505. if (nfc_initiator_transceive_bytes(device, pbtTx, szTx, abtRx, sizeof(abtRx), 0) < 0)
  506. return false;
  507. return true;
  508. }