PC/SC <-> Android OMAPI bridge for pySim and others

[cross-post from Feature #6367: PC/SC <-> Android OMAPI bridge for pySim and others - pySim - Open Source Mobile Communications as the users of the forum and redmine are not really overlapping all that much]

It’s a frequent usage pattern that somebody

  • inserts a (sysmocom) USIM/ISIM or even EUICC in their PC/SC card reader, performs some actions with it from the PC (such as changing a file via pySim) and then
  • inserts it into a phone to test it with the modification, then
  • restarts the cycle again by removing the card and placing it in the PC/SC reader

While working with EasyEUICC it occurred to me that it has raw APDU-level access via Androids FEATURE_SE_OMAPI_UICC. So it should be possible to write an Android app that acts as a proxy/brige for passing APDUs transparently to between an UICC/eUICC present in the phone and a remote PC running pySim (or any other software that expects a local PC/SC card reader)

In fact, given that the vpcd project alreay has a “APDU over TCP” protocol and has an ifd_handler exposing virtual card readers to pcscd, only the android side would have to be developed.

So in the end, using the approach above, it shoul be possible to have pySim-shell or other tools talk to the UICC/eUICC while it remains inserted into the phone. After changes were made, we have to see if we can somehow trigger the REFRESH proactive command to tell the baseband to discard its cache and re-read the card contents. Likely a manual “Airplane mode on / off” toggle will also do the trick. But no more inserting/removing the card in between iterations.

Of course the same should in theory be possible also via 03.48 OTA / SCP80 without any Android app. However, OTA works with “APDU scripts” and that’s not 1:1 the same as a live connection to the card, where the card doesn’t loose state like which file was SELECTed between different OTA commands.

Any ideas/comments on this? I’m not an Android developer, but the task looks reasonably simple to me:

  • access the UICC/eUICC the same way as EasyEUICC
  • create a TCP connection to a user-configured IP/Port (the ifd-vpcd)
  • implement the super simple VPCD protocol over TCP to transceive APDUs

FYI, Remote Smart Card Reader — vsmartcard 2023-10-01 documentation is doing something similar, but it uses the NFC chip of an Android phone to access a NFC (ISO14443) contactless smart card. In our use case it would be the contact-based internal SIM slot instead.