Skip to content

Sector authentication succeeds, but reading sector data fails #207

@laterdayi

Description

@laterdayi

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions