Send more than 261 bytes to Java Card with Android NFC

ⅰ亾dé卋堺 提交于 2019-12-06 04:04:22

Short answer: You can't easily do that.

You already found out that IsoDep does not "support" extended-length APDUs on your device (i.e. isoDep.isExtendedLengthApduSupported() returns false). In fact this does not mean that you can't send extended-length APDUs through the IsoDep object. It actually only means that the IsoDep object won't properly split extended-length APDUs across more than two ISO-DEP blocks and consequently an APDU that is longer than 261 bytes will be assumed to exceed the transmit buffer size. You should still be able to send extended-length APDUs with sizes <= 261 bytes.

So isoDep.isExtendedLengthApduSupported() actually indicates if you can send more than 261 bytes in one ISO-DEP transceive.

What you could do to overcome this problem is to not use the IsoDep object at all and, instead, manually implement ISO-DEP (the ISO/IEC 14443-4 transmission protocol) on top of the NfcA object (if your card is based on NFC-A / ISO/IEC 14443 Type A) or the NfcB object (if your card is based on NFC-B / ISO/IEC 14443 Type B and if your device supports exchanging data over the NfcB object). You could then split your extended-length APDUs into ISO-DEP blocks that are small enough for the transceive buffer of the NFC controller (typically 253 bytes including the header bytes, excluding the CRC bytes). However, handling the ISO-DEP protocol yourself also means that you have to take care of proper ISO-DEP activation, of handling block numbering, block acknowledgements, timeouts, waiting-time extension, etc. Which is rather complicated, and particularly timeouts are not easy to observe due to the delays through the Android NFC stack.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!