proxmark3/client/mifare/ndef.c

84 lines
1.9 KiB
C
Raw Normal View History

2019-03-05 06:11:31 +08:00
//-----------------------------------------------------------------------------
// Copyright (C) 2019 Merlok
//
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
// at your option, any later version. See the LICENSE.txt file for the text of
// the license.
//-----------------------------------------------------------------------------
// NFC Data Exchange Format (NDEF) functions
//-----------------------------------------------------------------------------
#include "ndef.h"
2019-03-05 06:48:02 +08:00
#include "ui.h"
uint16_t ndefTLVGetLength(uint8_t *data, size_t *indx) {
uint16_t len = 0;
if (data[0] == 0xff) {
len = (data[1] << 8) + data[2];
*indx += 3;
} else {
len = data[0];
*indx += 1;
}
return len;
}
2019-03-05 06:11:31 +08:00
2019-03-05 06:51:32 +08:00
int ndefRecordDecodeAndPrint(uint8_t *ndefRecord, size_t ndefRecordLen) {
return 0;
}
2019-03-05 06:11:31 +08:00
int NDEFDecodeAndPrint(uint8_t *ndef, size_t ndefLen, bool verbose) {
2019-03-05 06:48:02 +08:00
size_t indx = 0;
2019-03-05 06:54:45 +08:00
PrintAndLogEx(INFO, "NDEF decoding:");
2019-03-05 06:48:02 +08:00
while (indx < ndefLen) {
switch (ndef[indx]) {
case 0x00: {
indx++;
uint16_t len = ndefTLVGetLength(&ndef[indx], &indx);
2019-03-05 06:54:45 +08:00
PrintAndLogEx(INFO, "-- NDEF NULL block.");
2019-03-05 06:48:02 +08:00
if (len)
PrintAndLogEx(WARNING, "NDEF NULL block size must be 0 instead of %d.", len);
indx += len;
break;
}
case 0x03: {
indx++;
uint16_t len = ndefTLVGetLength(&ndef[indx], &indx);
2019-03-05 06:54:45 +08:00
PrintAndLogEx(INFO, "-- NDEF message. len: %d", len);
2019-03-05 06:48:02 +08:00
2019-03-05 06:51:32 +08:00
int res = ndefRecordDecodeAndPrint(&ndef[indx], len);
if (res)
return res;
2019-03-05 06:48:02 +08:00
indx += len;
break;
}
case 0xfd: {
indx++;
uint16_t len = ndefTLVGetLength(&ndef[indx], &indx);
2019-03-05 06:54:45 +08:00
PrintAndLogEx(INFO, "-- NDEF proprietary info. Skipped %d bytes.", len);
2019-03-05 06:48:02 +08:00
indx += len;
break;
}
case 0xfe: {
2019-03-05 06:54:45 +08:00
PrintAndLogEx(INFO, "-- NDEF Terminator. Done.");
2019-03-05 06:48:02 +08:00
return 0;
break;
}
default: {
PrintAndLogEx(ERR, "unknown tag 0x%02x", ndef[indx]);
return 1;
}
}
}
2019-03-05 06:11:31 +08:00
return 0;
}