diff --git a/utils/nfc-read-forum-tag3.c b/utils/nfc-read-forum-tag3.c index 32288ad..3e18a79 100644 --- a/utils/nfc-read-forum-tag3.c +++ b/utils/nfc-read-forum-tag3.c @@ -292,15 +292,50 @@ main(int argc, char *argv[]) exit(EXIT_FAILURE); } + fprintf(message_stream, "NDEF Attribute Block:\n"); const int ndef_major_version = (data[0] & 0xf0) >> 4; const int ndef_minor_version = (data[0] & 0x0f); - fprintf(message_stream, "NDEF Mapping version: %d.%d\n", ndef_major_version, ndef_minor_version); + fprintf(message_stream, "* Mapping version: %d.%d\n", ndef_major_version, ndef_minor_version); - const int available_block_count = (data[3] << 8) + data[4]; - fprintf(message_stream, "NFC Forum Tag Type 3 capacity: %d bytes\n", available_block_count * 16); + const int ndef_nbr = data[1]; + fprintf(message_stream, "* Maximum nr of blocks to read by Check Command: %3d block%s\n", ndef_nbr, ndef_nbr > 1 ? "s" : ""); + + const int ndef_nbw = data[2]; + fprintf(message_stream, "* Maximum nr of blocks to write by Update Command: %3d block%s\n", ndef_nbw, ndef_nbw > 1 ? "s" : ""); + + const int ndef_nmaxb = (data[3] << 8) + data[4]; + fprintf(message_stream, "* Maximum nr of blocks available for NDEF data: %3d block%s (%d bytes)\n", ndef_nmaxb, ndef_nmaxb > 1 ? "s" : "", ndef_nmaxb * 16); + + const int ndef_writeflag = data[9]; + fprintf(message_stream, "* NDEF writing state: "); + switch (ndef_writeflag) { + case 0x00: + fprintf(message_stream, "finished (0x00)\n"); + break; + case 0x0f: + fprintf(message_stream, "in progress (0x0F)\n"); + break; + default: + fprintf(message_stream, "invalid (0x%02X)\n", ndef_writeflag); + break; + } + + const int ndef_rwflag = data[10]; + fprintf(message_stream, "* NDEF Access Attribute: "); + switch (ndef_rwflag) { + case 0x00: + fprintf(message_stream, "Read only (0x00)\n"); + break; + case 0x01: + fprintf(message_stream, "Read/Write (0x01)\n"); + break; + default: + fprintf(message_stream, "invalid (0x%02X)\n", ndef_rwflag); + break; + } uint32_t ndef_data_len = (data[11] << 16) + (data[12] << 8) + data[13]; - fprintf(message_stream, "NDEF data length: %d bytes\n", ndef_data_len); + fprintf(message_stream, "* NDEF message length: %d bytes\n", ndef_data_len); uint16_t ndef_calculated_checksum = 0; for (size_t n = 0; n < 14; n++) @@ -308,15 +343,13 @@ main(int argc, char *argv[]) const uint16_t ndef_checksum = (data[14] << 8) + data[15]; if (ndef_calculated_checksum != ndef_checksum) { - fprintf(stderr, "NDEF CRC does not match with calculated one\n"); - fclose(ndef_stream); - nfc_close(pnd); - nfc_exit(context); - exit(EXIT_FAILURE); + fprintf(message_stream, "* Checksum: fail (0x%04X != 0x%04X)\n", ndef_calculated_checksum, ndef_checksum); + } else { + fprintf(message_stream, "* Checksum: ok (0x%04X)\n", ndef_checksum); } if (!ndef_data_len) { - fprintf(stderr, "Empty NFC Forum Tag Type 3\n"); + fprintf(stderr, "Error: empty NFC Forum Tag Type 3, nothing to read!\n"); fclose(ndef_stream); nfc_close(pnd); nfc_exit(context); @@ -345,6 +378,8 @@ main(int argc, char *argv[]) nfc_close(pnd); nfc_exit(context); exit(EXIT_FAILURE); + } else { + fprintf(stderr, "%i bytes written to %s\n", ndef_data_len, ndef_output); } fclose(ndef_stream);