×

Discussion Board

Results 1 to 12 of 12
  1. #1
    Registered User
    Join Date
    Jul 2012
    Posts
    12

    Unhappy reading mifare 1k tag

    Hi all !

    I am able to read mifare 1k tags (having UID 8 digit)using nokia nfc SDK on nokia 603 but now NXP have made the change in cards UID.Now card UID is of 14 digit previously it was 8 digit.due to this i am not able to read new mifare 1k cards (having 14 digit UID).Because "getMFStandardConnection" returns me NULL value.Please help me
    how can i read those new cards?

  2. #2
    Nokia Developer Expert
    Join Date
    Aug 2011
    Posts
    555

    Re: reading mifare 1k tag

    Hi pradip007,

    Your issue seems to be that you are trying to use an NFC tag that doesn't support MFStandardConnection.
    You will most likely need to retrieve the connection type and use that connection type instead of MFStandardConnection. You can find a list of supported connections here.

    In order to find the connection type for the NFC tag you are using and assuming that you are iterating through the connections of each target property, you can use this code:

    Code:
    connections[i].getName();
    Assuming the code above returns, e.g. a com.nokia.nfc.nxp.simpletag.SimpleTagConnection, you need to change your getMFStandardConnection method accordingly to match this connection type:

    If you are filtering the connection names for each of the target properties according to their connection type, please modify your code from

    Code:
    if (!connections[i].getName().equals("com.nokia.nfc.nxp.mfstd.MFStandardConnection"))
    to something like this

    Code:
    if (!connections[i].getName().equals("com.nokia.nfc.nxp.simpletag.SimpleTagConnection"))
    Also ensure that you return a SimpleTagConnection, so if you are returning something like this:

    Code:
    return (MFStandardConnection)Connector.open(targetProperties[j].getUrl(connections[i]));
    you would need to modify your code as follows:
    Code:
    return (SimpleTagConnection)Connector.open(targetProperties[j].getUrl(connections[i]));
    The logic for the modifications is the same if your tag returns e.g. a Type3TagConnection instead.
    Last edited by skalogir; 2012-07-16 at 09:38.

  3. #3
    Registered User
    Join Date
    Jul 2012
    Posts
    12

    Re: reading mifare 1k tag

    Quote Originally Posted by skalogir View Post
    Hi pradip007,

    Your issue seems to be that you are trying to use an NFC tag that doesn't support MFStandardConnection.
    You will most likely need to retrieve the connection type and use that connection type instead of MFStandardConnection. You can find a list of supported connections here.

    In order to find the connection type for the NFC tag you are using and assuming that you are iterating through the connections of each target property, you can use this code:

    Code:
    connections[i].getName();
    Assuming the code above returns, e.g. a com.nokia.nfc.nxp.simpletag.SimpleTagConnection, you need to change your getMFStandardConnection method accordingly to match this connection type:

    If you are filtering the connection names for each of the target properties according to their connection type, please modify your code from

    Code:
    if (!connections[i].getName().equals("com.nokia.nfc.nxp.mfstd.MFStandardConnection"))
    to something like this

    Code:
    if (!connections[i].getName().equals("com.nokia.nfc.nxp.simpletag.SimpleTagConnection"))
    Also ensure that you return a SimpleTagConnection, so if you are returning something like this:

    Code:
    return (MFStandardConnection)Connector.open(targetProperties[j].getUrl(connections[i]));
    you would need to modify your code as follows:
    Code:
    return (SimpleTagConnection)Connector.open(targetProperties[j].getUrl(connections[i]));
    The logic for the modifications is the same if your tag returns e.g. a Type3TagConnection instead.
    Thanks skalogir,

    but same mifare 1k tag with 4 byte UID is reading with MFStandard connection and I am using these all tags made by NXP semiconductor (both 4 byte and 7 byte UID).4 byte uid card is working fine but 7 byte uid card is giving me error i.e MFStandard connection returns me null value.
    And I also tried with plain tag connection and simple tag connection but such connection string is not available to open connection

    connections[i].getName() returns me only "com.nokia.nfc.nxp.mfstd.MFStandardConnection" and "com.nokia.nfc.nxp.ndef.NDEFConnection"

    Please help me on same

    Thanks in advance

    Pradip

  4. #4
    Nokia Developer Expert
    Join Date
    Aug 2011
    Posts
    555

    Re: reading mifare 1k tag

    Hi pradip007,

    Thanks for providing the connection names that you retrieve. Given that you do retrieve the following connection name

    com.nokia.nfc.nxp.mfstd.MFStandardConnection

    I do not see a reason why you cannot establish an MFStandardConnection to the tag and you retrieve null instead. I have also tested and verified that I can establish a connection (depending on the connection type supported) to tags of different UID sizes on Nokia 603 with software 112.010.1404. Could it be that you filter the UIDs before calling the getMFStandardConnection? Can you provide your sample code for the getMFStandardConnection() method as well as the targetDetected() up to the point where you call the getMFStandardConnection()? Can you try to update the software on your Nokia 603 (in case you haven't done it already) by using Nokia Suite? Can you also try to retrieve the connection names and URLS for both mifare tags you are using with the following code ?

    Code:
    String UrlCon = targetProperties[j].getUrl(connections[i]);
    System.out.println("URL is: " + UrlCon);
    Do you observe any differences in their url other than the UID or in their supported connection types?
    Last edited by skalogir; 2012-07-27 at 08:23.

  5. #5
    Registered User
    Join Date
    Jul 2012
    Posts
    12

    Re: reading mifare 1k tag

    Quote Originally Posted by skalogir View Post
    Hi pradip007,

    Thanks for providing the connection names that you retrieve. Given that you do retrieve the following connection name

    com.nokia.nfc.nxp.mfstd.MFStandardConnection

    I do not see a reason why you cannot establish an MFStandardConnection to the tag and you retrieve null instead. I have also tested and verified that I can establish an MFStandardConnection to tags of different UID sizes on Nokia 603 with software 112.010.1404. Could it be that you filter the UIDs before calling the getMFStandardConnection? Can you provide your sample code for the getMFStandardConnection() method as well as the targetDetected() up to the point where you call the getMFStandardConnection()? Can you try to update the software on your Nokia 603 (in case you haven't done it already) by using Nokia Suite? Can you also try to retrieve the connection names and URLS for both mifare tags you are using with the following code ?

    Code:
    String UrlCon = targetProperties[j].getUrl(connections[i]);
    System.out.println("URL is: " + UrlCon);
    Do you observe any differences in their url other than the UID or in their supported connection types?
    Hi skalogir,

    Yes skalogir I have updated my 603 phones software and current version is 112.010.1404 as mentioned by you.But still I am facing same problem.and I also tried to get connection url's of both types of tag
    For 4 byte UID tag I am getting "nfc:rf;type=mf1k;uid=6974763b" this connection URL
    For 7 byte UID tag I am getting "nfc:rf;type=mf1k;uid=042d4c4afc2480" this connection URL

    The difference between both of them is only UID length.

    For your reference below is my code snippet
    For GUI I am using LWUIT tool kit


    Code:
    public void targetDetected(TargetProperties[] targetproperties)
        {
            try
            {
                TargetProperties tmp = targetproperties[0];
                UID = tmp.getUid();
                tagRWForm.LBL_UID.setText("UID : " + UID + "      ");
                tagRWForm.repaint();
    //            Dialog.show("INFO","UID read", "Ok", null);
                conn = getMFStandardConnection(targetproperties);
    //            Dialog.show("INFO","Got connection"+conn.toString(), "Ok", null);
    //            if (targetproperties.length == 0)
    //            {
    ////                Dialog.show("INFO","targetproperties.length == 0", "Ok", null);
    //                read_tag_flag=false;
    //            }
    //            else
    //            {
    //                read_tag_flag=true;
    //            }
                if (conn == null)
                {
                    Dialog.show("INFO","conn=null", "Ok", null);
                    read_tag_flag=false;
                }
                else
                {
                    Dialog.show("INFO","conn="+conn.toString(), "Ok", null);
                    read_tag_flag = true;
                }
                if (read_tag_flag)
                {
                    byte[] ki0 = {(byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF};
    //                Dialog.show("INFO","Preparing key", "Ok", null);
                    MFKey.KeyA key = new MFKey.KeyA(ki0);
    
                    MFBlock BLOCK;
                    byte[] BLKByte = new byte[16];
                    String strBlock = "";
                    if (ReadFlag)
                    {
                        KeySetMIDlet.raed.dispose();
                        System.gc();
                        try
                        {
                            BLOCK = conn.getBlock(Integer.parseInt(tagRWForm.TXT_BlockNo.getText()));
    //                        Dialog.show("INFO","Reading block", "Ok", null);
                            BLOCK.read(key, BLKByte, 0, 0,16);
                            
                            strBlock = new String(BLKByte);
    //                        String s = byteToHex(BLKByte);
                            //BLKByte=hexStringToByteArray(s);
                            tagRWForm.TXT_Data.setText(strBlock);
                            Dialog.show("INFO", "Data read successfully from block No. " + tagRWForm.TXT_BlockNo.getText() + ".", 	Dialog.TYPE_INFO, null, "Ok", null, 1000);
                            tagRWForm.LBL_UID.setText("UID : " + UID + "      ");
                            tagRWForm.repaint();
                            ReadFlag = false;
                        }
                        catch (Exception ex)
                        {
                           Dialog.show("INFO",ex.toString(), "Ok", null);
                        }
    
                    }
                    else
                    {
                        if (WriteFlag)
                        {
                            KeySetMIDlet.write.dispose();
                            System.gc();
                            try
                            {
                                String data = "";
    //                            BLOCK = conn.getBlock(Integer.parseInt(tagRWForm.TXT_BlockNo.getText()));
                                data = tagRWForm.TXT_Data.getText().trim();
                                data = addSpacesTo16(data);
    //                            BLOCK.write(key, data.getBytes(), 0, 16, 0);
                                WriteFlag = false;
                                Dialog.show("INFO", "Data writen successfully on block No. " + tagRWForm.TXT_BlockNo.getText() + ".", Dialog.TYPE_INFO, null, "Ok", null, 1000);
                            }
                            catch (Exception ex)
                            {
                                ex.printStackTrace();
                            }
                        }
                    }
    
                    try
                    {
                        if (conn != null)
                        {
                            conn.close();
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                }
                else
                {
                    KeySetMIDlet.raed.dispose();
                    KeySetMIDlet.write.dispose();
                    System.gc();
                }
            }
            catch (Exception ep)
            {
                Dialog.show("INFO", ep.toString(), "OK", "Cancel");
            }
            finally
            {
                try
                {
                    if(conn != null)
                    {
                        conn.close();
                    }
                    
                }
                catch (Exception ex)
                {
                }
            }
        }
    
        private MFStandardConnection getMFStandardConnection(TargetProperties[] Prop)
        {
            for (int j = 0; j < Prop.length; j++)
            {
                Class[] connections = Prop[j].getConnectionNames();
    //            for(int i=0;i<connections.length;i++)
    //            {
    //                Dialog.show("INFO",connections[i].getName(), "Ok", null);
    //            }
                
                if (connections != null)
                {
                    for (int k = 0; k < connections.length; k++)
                    {
    //                    Dialog.show("INFO",connections[k].getName(), "Ok", null);
                        if (connections[k].getName().equals("com.nokia.nfc.nxp.mfstd.MFStandardConnection"))
                        {
                            try
                            {
                                //Dialog.show("INFO",Prop[j].getUrl(connections[k]), "Ok", null);
                                return (MFStandardConnection) Connector.open(Prop[j].getUrl(connections[k]));
                            }
                            catch (Exception e)
                            {
                                e.printStackTrace();
                            }
                        }
                    }
                }
            }
            return null;
        }
    Please skalogir help me to get solution

    Thanks in advance,

    Pradip

  6. #6
    Nokia Developer Expert
    Join Date
    Aug 2011
    Posts
    555

    Re: reading mifare 1k tag

    Hi pradip,

    I have managed to reproduce your issue (null connection) with the 7 Byte tags, if I specify a target of NDEF_TAG type, when adding the target listener, as follows:

    Code:
    try
        {
          DiscoveryManager dm = DiscoveryManager.getInstance();
          dm.addTargetListener(this, TargetType.NDEF_TAG);
        }
        catch (ContactlessException ce)
        {
          displayAlert("Unable to register TargetListener: " + ce.toString(), AlertType.ERROR);
        }
    But if I specify a target of type RFID_TAG as shown below:

    Code:
    try
        {
          DiscoveryManager dm = DiscoveryManager.getInstance();
          dm.addTargetListener(this, TargetType.RFID_TAG);
        }
        catch (ContactlessException ce)
        {
          displayAlert("Unable to register TargetListener: " + ce.toString(), AlertType.ERROR);
        }
    I managed to successfully retrieve a non-null connection. Are you using RFID_TAG or NDEF_TAG as target types? If you are using NDEF_TAG can you please modify your code in order to use RFID_TAG and try again? Let us know, if that solves your issue.
    Last edited by skalogir; 2012-07-18 at 10:51.

  7. #7
    Registered User
    Join Date
    Jul 2012
    Posts
    12

    Re: reading mifare 1k tag

    Quote Originally Posted by skalogir View Post
    Hi pradip,

    I have managed to reproduce your issue (null connection) with the 7 Byte tags, if I specify a target of NDEF_TAG type, when adding the target listener, as follows:

    Code:
    try
        {
          DiscoveryManager dm = DiscoveryManager.getInstance();
          dm.addTargetListener(this, TargetType.NDEF_TAG);
        }
        catch (ContactlessException ce)
        {
          displayAlert("Unable to register TargetListener: " + ce.toString(), AlertType.ERROR);
        }
    But if I specify a target of type RFID_TAG as shown below:

    Code:
    try
        {
          DiscoveryManager dm = DiscoveryManager.getInstance();
          dm.addTargetListener(this, TargetType.RFID_TAG);
        }
        catch (ContactlessException ce)
        {
          displayAlert("Unable to register TargetListener: " + ce.toString(), AlertType.ERROR);
        }
    I manage to successfully retrieve a non-null connection. Are you using RFID_TAG or NDEF_TAG as target types? If you are using NDEF_TAG can you please modify your code in order to use RFID_TAG and try again? Let us know, if that solves your issue.
    skalogir,
    I am using RFID_TAG for registering discovery manager but i got the issue from where i am receiving null
    actually i have not handled the exception while opening connection in getMFStandardConnection method on below line

    return (MFStandardConnection) Connector.open(Prop[j].getUrl(connections[k]));

    but still my issue is not solved.While calling above line i am getting following exception

    "javax.microedition.io.ConnectionNotFoundException:Unsupported connection mode"

    So can you tell me what is problem i.e it is from device or Mifare card
    I mean to say
    The problem is with card or device?

    Thanks,

    Pradip
    Last edited by pradip007; 2012-07-18 at 10:44.

  8. #8
    Nokia Developer Expert
    Join Date
    Aug 2011
    Posts
    555

    Re: reading mifare 1k tag

    It would be worth trying to separate the typecasting from the connection retrieval and see if you cannot retrieve a connection at all, or if you can retrieve a connection but cannot typecast it to MFStandardConnection. If you don't get an Exception when you open the connection, my best guess would be to still try to typecast the connection to one of the other supported connection types. If you get the exception immediately when you open the connection, there is most likely an incompatibility with the given tag.
    Last edited by skalogir; 2012-07-22 at 23:56.

  9. #9
    Registered User
    Join Date
    Jul 2012
    Posts
    12

    Re: reading mifare 1k tag

    Yes skalogir,

    I am getting exception immediately when opening connection.and I have searched for 7 byte UID mifare cards and found that these 7 byte UID mifare cards are Type 2 (RF-Power & Signal interface) cards wherease 4 byte UID cards are type 1 (Physical Characteristics of contactlesssmart cards (PICC)) cards.

    thanks,

    Pradip
    Last edited by pradip007; 2012-07-23 at 07:03.

  10. #10
    Registered User
    Join Date
    Jul 2012
    Posts
    12

    Re: reading mifare 1k tag

    Hi all !

    Anyone got any update on how to read 7 byte UID mifare card on Nokia 603

    Pradip,

  11. #11
    Nokia Developer Expert
    Join Date
    Aug 2011
    Posts
    555

    Re: reading mifare 1k tag

    Hi pradip,

    It seems that this is not an issue of incompatibility of Nokia 603 with 7 byte mifare tags, as I have succeeded in opening a connection to a 7 byte tag, but rather a limitation of the specific tags that you are using.

  12. #12
    Registered User
    Join Date
    Jul 2012
    Posts
    12

    Re: reading mifare 1k tag

    Quote Originally Posted by skalogir View Post
    Hi pradip,

    It seems that this is not an issue of incompatibility of Nokia 603 with 7 byte mifare tags, as I have succeeded in opening a connection to a 7 byte tag, but rather a limitation of the specific tags that you are using.
    Hi skalogir,
    I can read and write 7 byte UID Mifare card using 603 but in NDEF format.and I dont want to use NDEF format.and I also succeded in opening connection using GCF but while handling further it is giving me null pointer exception.I also tried with Qt but Qt supports only NDEF format.No any tag specific connection available in Qt.

    Regards,
    Pradip

Similar Threads

  1. Reading bytes from Mifare Ultralight
    By rskuja in forum Near Field Communication
    Replies: 1
    Last Post: 2012-03-12, 15:36
  2. Mifare reading card data example
    By mikeprice in forum Mobile Java Tools & SDKs
    Replies: 1
    Last Post: 2010-02-17, 06:22
  3. Reading data from an External MiFare 1k card
    By shug94 in forum Near Field Communication
    Replies: 4
    Last Post: 2009-04-01, 17:56
  4. Writing to and reading from an external Mifare 1k tag
    By savio_mf in forum Near Field Communication
    Replies: 1
    Last Post: 2008-03-15, 11:36
  5. Problems Reading External Mifare 1k
    By aajf in forum Near Field Communication
    Replies: 5
    Last Post: 2008-03-07, 10:15

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×