androidnfcapduhce

Android HCE does not support select MF command?


We are developing an app based on Android HCE. We found that HCE uses an AID-based mechanism to route communication to specific apps. This means that if I want to trigger my app, the first command must be a SELECT by name command.

This is a very big limitation on transport domain. In transport, many POS won't send a SELECT by name command as the first command. Instead they would send a SELECT MF (00A40000023F00) command as the first command. So HCE can't work in that case.

Is there any plan to add default select feature? Or do we have some other solution to support this use case?


Solution

  • Android uses an AID-based routing mechanism to dispatch communication in card emulation mode to specific application (HCE applications or SE applets). This is also what the NFC Forum designed as the primary means to support multiple independent card emulation applications on a single NFC device.

    AID-based routing requires the first command to be a SELECT (by DF name/AID) command:

    00 A4 0400 <Lc> <AID> [<Le>]

    This is necessary in order to distinguish between different applications. Otherwise, Android would not be able to dispatch communication to the right HCE service.

    However, this also prevents emulation of anything that precedes a successful application selection (such as selecting a master file using a SELECT (by file name, etc.) command). If this was allowed, Android would have no way to know which HCE application was responsible for handling that command. Consequently, it would be impossible to host multiple HCE applications that all require a master file on one device. Therefore, I don't expect this to be supported anytime soon.

    On other mutli-application platforms that very same problem exists as well. For instance, typical Java Card smartcards also do not have a master file. On these platforms, the problem is usually overcome by allowing one default-selected application that handles all communication before the first SELECT (by DF name/AID) command. One can only speculate if such a mechanism would come in a future Android version...I would not count on it.

    If rooted devices are an option, you may be able to use a framework like Xposed to adapt the NFC system service to dispatch communication to some default HCE service.