Nfc service ocassionaly stops working upon receiving error during card reading

Forum / MIFARE general topics and applications / Nfc service ocassionaly stops working upon receiving error during card reading

  • 3. November 2020 at 14:32
    Hi

    Im working on Inspection application which reads MifareUL and MifareClssic cards.
    Issue im having is that occasionaly NFC service stops working and taping card does nothing after this point (no new events are received).
    After this, it is required to disable and enable NFC service again in order to make NFC work.
    Device im using is Bluebird EF501. It runs Android 7.1.2.

    Reader is enabled like this:
    `
    val flags = NfcAdapter.FLAG_READER_NFC_A or NfcAdapter.FLAG_READER_NFC_B or
    NfcAdapter.FLAG_READER_NFC_F or NfcAdapter.FLAG_READER_NFC_V or
    NfcAdapter.FLAG_READER_SKIP_NDEF_CHECK

    try {
    nxpNfcInstance.enableReaderMode(1000, {
    handleTag(it)
    }, flags)
    } catch (e: Exception) {
    Timber.e(e, "Failed to enable reader mode!")
    }
    `

    after decoding what kind of media it is and obtaining ICard object card data are read like this:
    `
    return withContext(Dispatchers.IO) {
    try {
    classic.reader.connect()
    classic.reader.timeout = CARD_READ_TIMEOUT

    val sectorList = IntRange(0, CLASSIC_SECTOR_COUNT - 1)
    .asSequence()
    .onEach { s -> authenticateSector(s, classic) }
    .map { s ->
    readBlocksFromSector(s, classic).let { blocks -> ... }
    }
    .toList()

    MifareClassicData(sector = sectorList, uid = uid)
    } finally {
    classic.reader.close()
    }
    }

    private fun readBlocksFromSector(sector: Int, classic: IMFClassic): Array {
    val startBlock = classic.sectorToBlock(sector)
    return Array(3) { index ->
    classic.readBlock(startBlock + index)
    }
    }
    `

    threading is like this:
    [Binder thread]
    event is sent media processing component
    [Main thread]
    decoded media type from tag
    obtained ICard object
    [Dispatchers.IO thread]
    reading of card data
    [Main thread]
    data processed


    Do you have any experience with such issues?
    Idont know what im doning wrong, what can cause this issue and it is starting to be quit problem.
    Also on other device it seems to not happening but im not sure if this is case.

    Thansk for helpnig
    Michal
    + 0  |  - 0

    Re: Nfc service ocassionaly stops working upon receiving error during card reading

    3. November 2020 at 14:45
    Hi Michal,

    The MIFARE Ultralight and the MIFARE Classic uses ISO/IEC 14443-3 protocol (the “-3” is important). This means, if an error occurs or an invalid key was used, the card goes into internal HALT state and terminate any communication. But this should not shutdown the whole NFC communication on your device! Here you must remove the card from reader (this will reset the card) and put into the field again.

    For me it seems that this is an issue in the middleware. Can you check your software on a different device (a different manufacturer)? If both devices behaves different you can identify this as firmware issue. As Android developer you should test your software on so many different devices as possible to prevent device specific issues.

    The TapLinx team

    + 0  |  - 0
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.