microsoft / Windows-universal-samples

API samples for the Universal Windows Platform.
MIT License
9.53k stars 7.97k forks source link

Smartcard TransparentExchangeAsync conflict #274

Closed mvdzwaan closed 8 years ago

mvdzwaan commented 8 years ago

Using the PcscSDK and connecting to a smartcard using normal APDU it's working fine (getUID)

When I start using TransparentExchangeAsync (needed for Ultralight EV1 commands). I get large invalid TLV responses (startsession/endsession is working and returning C0-03-00-90-00)

The actual envelope command returns

96-02-90-00-97-FF-A5-87..... 254 bytes of data (throwing an exception in parsing the TLV).

When I put a breakpoint at the first TransparentExchangeAsync command and press continue immediately, its working fine. Putting a (temporary fix) task.delay does not help.

I've put in a loop waiting for SmartCardStatus.Ready, and it's ready.

So there seems to be a conflict with the existing nfc functionality of the phone (tap to transfer cannot be disabled as it disables the nfc module).

I have not found an option for getting exclusive reader access (only getStatusAsync)

Current code in handleCard (from sample). It's failing at the last line, unless I break there and continue '

        Dim newConnection = Await args.SmartCard.ConnectAsync()
        SyncLock CardConnectionLock
            If CardConnection IsNot Nothing Then
                CardConnection.Dispose()
            End If
            CardConnection = newConnection
        End SyncLock
        Dim cardIdentification As New IccDetection(args.SmartCard, CardConnection)
        Await cardIdentification.DetectCardTypeAync()

        Dim mifareULAccess As New MifareUltralight.AccessHandler(CardConnection)
        Dim responseUid As Byte() = Await mifareULAccess.GetUidAsync()
        Dim responseAuth() As Byte = Await mifareULAccess.TransparentExchangeAsync(New Byte() {&H1B, &H11, &H11, &H11, &H11})'
mvdzwaan commented 8 years ago

Note : The problem only occurs with card with the protection bit set (normally only write access requires a password on Ultralight EV1, setting the protection bit requires the password for read access as well).

This would indicate a background OS process tries to read the card and the protection bit prevents this, and then the conflict occurs.

During the process the nfc sound alert also sounds 'weird', skipping/restarting etc.

oldnewthing commented 8 years ago

This does not appear to be a question about a sample. You can open a support case with our Developer Support team who can further help with the specific problem you are experiencing. Please use these steps below for further help:  

  1. Visit http://aka.ms/storesupport and sign-in with your Microsoft account
  2. Under the “App Development” section choose "Windows 10 universal app development", then choose the appropriate problem type and category to get engaged through a formal support channel.