Android Question [solved] NFC Tag (not NDEF) reading

Discussion in 'Android Questions' started by udg, May 2, 2019.

  1. udg

    udg Expert Licensed User

    Hi all,
    I tried to modify Erel's original code in order to access an internal code on a Tag sent to me by a partner.
    They call it SID (Siemens SID from ScryptCard), but I wasn't able to find any doc about it.
    As far as technologies, UID, ATQA and SAK are concerned I read the same values as the NFC Tool app does.

    When it comes to discover the SID I receive a Success = false reply. Below my code (I tried both NfcA and IsoDep):

    Code:
    Sub Activity_Resume
       
    'forces all nfc intents to be sent to this activity
       nfc.EnableForegroundDispatch
       
    Dim si As Intent = Activity.GetStartingIntent
       
    'check that the intent is a new intent
       If si.IsInitialized = False Or si = prevIntent Then Return
       prevIntent = si
       
    If si.Action.EndsWith("TECH_DISCOVERED"Or si.Action.EndsWith("NDEF_DISCOVERED"Or si.Action.EndsWith("TAG_DISCOVERED"Then
           
    Dim techs As List = nfc.GetTechList(si)
           
    Log($"Techs: ${techs}"$)
           
    If techs.IndexOf("android.nfc.tech.NfcA") > -1 Then
               TagTech.Initialize(
    "TagTech""android.nfc.tech.NfcA" , si)
               
    'Get the UID
               Dim jo As JavaObject = TagTech
               
    Dim tag As JavaObject = jo.RunMethod("getTag"Null)
               
    Dim rawId() As Byte = tag.RunMethod("getId"Null)
               
    Dim bc As ByteConverter
               
    Log(bc.HexFromBytes(rawId)) 
               
    'Connect to the tag
               TagTech.Connect
           
    Else
               
    ToastMessageShow("Tag does not support Ndef/NfcA/IsoDep..."True)
           
    End If
       
    End If
    End Sub

    Private Sub TagTech_Connected (Success As Boolean)
       
    Log($"Connected: ${Success}"$)
       
    If Success = False Then
           
    ToastMessageShow("Error connecting to tag"True)
           
    Log(LastException)
       
    Else
           
    If rdbRead.Checked Then
               
    'after connection
               TagTech.RunAsync("TT""transceive"Array(Array As Byte(0x900x5A0x000x000x030xC00x8E0xF40x00)), 0)
               
    Wait For TT_RunAsync (Flag As Int, Success As Boolean, Result As Object)
               
    Log(Success)
               TagTech.RunAsync(
    "TT""transceive"Array(Array As Byte(0x900xBD0x000x000x070x000x000x000x000x100x000x000x00)), 0)
               
    Wait For TT_RunAsync (Flag As Int, Success As Boolean, Result As Object)
               
    Log(Success)
               TagTech.Close
           
    Else
               WriteNdef(
    Array(nfc.CreateMimeRecord("text/plain", flTxt1.Text.GetBytes("UTF8")), _
                         
    nfc.CreateMimeRecord("text/plain", flTxt2.Text.GetBytes("UTF8"))))
           
    End If
       
    End If
    End Sub
    Command codes appearing in the transceive commands are those that the partner sent to me. First one is to get an Application_ID while the second one is to get the SID.

    NFC Tools identifies my tag as an ISO 14443-4, NXP MIFARE DESFire / NXP MIFARE DESFIRE EV1.

    Anyone worked with tags like this one before? Any hint? TIA
     
  2. udg

    udg Expert Licensed User

    Unbelievable, now everything seems to work properly (ok, more or less).
    I substituted IsoDep again to NfcA and now it works (not exactly as I expected, but at least it seems that I can read the value I was looking for).
    Here's the updated code:
    Code:
    Sub Activity_Resume
       
    'forces all nfc intents to be sent to this activity
       nfc.EnableForegroundDispatch
       
    Dim si As Intent = Activity.GetStartingIntent
       
    'check that the intent is a new intent
       If si.IsInitialized = False Or si = prevIntent Then Return
       prevIntent = si
       
    If si.Action.EndsWith("TECH_DISCOVERED"Or si.Action.EndsWith("NDEF_DISCOVERED"Or si.Action.EndsWith("TAG_DISCOVERED"Then
           
    Dim techs As List = nfc.GetTechList(si)
           
    Log($"Techs: ${techs}"$)
           
    If techs.IndexOf("android.nfc.tech.IsoDep") > -1 Then
               TagTech.Initialize(
    "TagTech""android.nfc.tech.IsoDep" , si)
               
    'Dim jo As JavaObject = TagTech
               'Dim tag As JavaObject = jo.RunMethod("getTag", Null)
               'Dim rawId() As Byte = tag.RunMethod("getId", Null)
               'Dim bc As ByteConverter
               'Log(bc.HexFromBytes(rawId)) 'bc = ByteConverter
               'Connect to the tag
               TagTech.Connect
           
    Else
               
    ToastMessageShow("Tag does not support Ndef."True)
           
    End If
       
    End If
    End Sub

    Private Sub TagTech_Connected (Success As Boolean)
       
    Log($"Connected: ${Success}"$)
       
    If Success = False Then
           
    ToastMessageShow("Error connecting to tag"True)
           
    Log(LastException)
       
    Else
           
    Log("isConnected: "&TagTech.Connected)     'not needed
           If rdbRead.Checked Then
               
    'Get APPLICATION_ID
               TagTech.RunAsync("TT""transceive"Array(Array As Byte(0x900x5A0x000x000x030xC00x8E0xF4,0)), 0)
               
    Wait For TT_RunAsync (Flag As Int, Success As Boolean, Result As Object)
               
    Log(Success)
               
    If Success Then
                   
    Dim rawId() As Byte = Result
                   
    Dim bc As ByteConverter
                   
    Log(bc.HexFromBytes(rawId))
               
    End If
               
    'GET SID
               TagTech.RunAsync("TT""transceive"Array(Array As Byte(0x900xBD0x000x000x070x000x000x000x000x100x000x000x00)), 0)
               
    Wait For TT_RunAsync (Flag As Int, Success As Boolean, Result As Object)
               
    Log(Success)
               
    If Success Then
                   
    Dim rawId() As Byte = Result
                   
    Dim bc As ByteConverter
                   
    Log(bc.HexFromBytes(rawId))
               
    End If
               TagTech.Close
           
    Else
               WriteNdef(
    Array(nfc.CreateMimeRecord("text/plain", flTxt1.Text.GetBytes("UTF8")), _
                         
    nfc.CreateMimeRecord("text/plain", flTxt2.Text.GetBytes("UTF8"))))
           
    End If
       
    End If
    End Sub
    The "Get SID" command returns 16 hex values plus 2 status codes (91 00).
    The specific tag I'm testing on returns:
    8B1F06003030303430313239319112409100
    where the bold chars are the SID in a somewhat reverse order (I expected 40 12 91 because that's the value printed on the tag itself).

    If testing with other tags confirms the above I can finally close the subject .. fingers crossed..

    Edit: they confirmed that any tested tag shows the correct code.
     
    Last edited: May 3, 2019
    Erel, Tomtom2 and DonManfred like this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice