-
Notifications
You must be signed in to change notification settings - Fork 156
Open
Description
Sector authentication succeeds, but reading sector data fails
code
NFCTag tag = await FlutterNfcKit.poll();
setState(() {
_tag = tag;
});
await FlutterNfcKit.setIosAlertMessage("Working on it...");
_mifareResult = null;
if (tag.type == NFCTagType.mifare_classic) {
final defaultKey = Uint8List.fromList([0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
bool success = await FlutterNfcKit.authenticateSector(0, keyA: defaultKey);
if (success) {
print('authenticateSector success');
var data = await FlutterNfcKit.readSector(0); // read one sector, or
var data2 = await FlutterNfcKit.readBlock(0); // read one block
print(data);
print(data2);
} else {
print('authenticateSector failed');
}
}
log
I/flutter (16990): authenticateSector success
E/im.nfc.flutter_nfc_kit.FlutterNfcKitPlugin(16990): Read sector error
E/im.nfc.flutter_nfc_kit.FlutterNfcKitPlugin(16990): java.io.IOException: Transceive failed
E/im.nfc.flutter_nfc_kit.FlutterNfcKitPlugin(16990): at android.nfc.TransceiveResult.getResponseOrThrow(TransceiveResult.java:52)
E/im.nfc.flutter_nfc_kit.FlutterNfcKitPlugin(16990): at android.nfc.tech.BasicTagTechnology.transceive(BasicTagTechnology.java:154)
E/im.nfc.flutter_nfc_kit.FlutterNfcKitPlugin(16990): at android.nfc.tech.MifareClassic.readBlock(MifareClassic.java:431)
E/im.nfc.flutter_nfc_kit.FlutterNfcKitPlugin(16990): at im.nfc.flutter_nfc_kit.MifareUtils.readSector(MifareUtils.kt:126)
I found that if you execute the authenticateSector twice then the reading is normal
code
NFCTag tag = await FlutterNfcKit.poll();
setState(() {
_tag = tag;
});
await FlutterNfcKit.setIosAlertMessage("Working on it...");
_mifareResult = null;
if (tag.type == NFCTagType.mifare_classic) {
final defaultKey = Uint8List.fromList([0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
bool success = await FlutterNfcKit.authenticateSector(0, keyA: defaultKey);
if (success) {
print('authenticateSector success');
await FlutterNfcKit.authenticateSector(0, keyA: defaultKey);
var data = await FlutterNfcKit.readSector(0); // read one sector, or
var data2 = await FlutterNfcKit.readBlock(0); // read one block
print(data);
print(data2);
} else {
print('authenticateSector failed');
}
}
log
I/flutter (16990): authenticateSector success
I/flutter (16990): [44, 122, 185, 207, 32, 8, 4, 0, 4, 253, 133, 164, 78, 121, 80, 144, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 7, 128, 105, 255, 255, 255, 255, 255, 255]
I/flutter (16990): [44, 122, 185, 207, 32, 8, 4, 0, 4, 253, 133, 164, 78, 121, 80, 144]
I/flutter (16990): Instance of 'NFCTag'2222222
Metadata
Metadata
Assignees
Labels
No labels