Skip to main content
Visitor II
August 21, 2020
Solved

ST25DV64K password read/write with ST25SDK

  • August 21, 2020
  • 7 replies
  • 1852 views

Hi!.

I'm developing an Android app to read and write info into ST25DV64K.

For the moment, I'm using the folowing functions of ST25SDK: com.st.st25sdk.NFCTag readBytes() and writeBytes() and they work properly.

Now, I need to protect the reading and writting in ST25DV64K with password and I need to know which ST25SDK functions I can use.

If possible, I would like to have a piece of code where I can see how the functions work.

Thanks in advance!.

    This topic has been closed for replies.
    Best answer by Olivier L

    Hi,

    Have you downloaded the source code of our "ST25 NFC Tap" application? It contains lot of examples showing all the features of our NFC Tags. You can get it here:

    https://www.st.com/en/embedded-software/stsw-st25001.html

    You can then look at the class "ST25DVChangePermissionsActivity". This is the class managing the change of permissions for ST25DV areas. You can look at the function changePermission().

    I see now that there is in fact a simpler manner to set the permissions. In this function, we are accessing directly to the ST25DV Registers. It is in fact simpler to use a generic interface supported by ST25DVTags. This is the "MultiAreaInterface" defined in ST25 SDK. Here is some pseudo code showing the idea:

    // Configuration password should be entered before changing the ST25DV configuration
    final byte[] configurationPassword = PUT_YOUR_PASSWORD_HERE;
    int configurationPasswordNumber = st25DVTag.getConfigurationPasswordNumber();
    st25DVTag.presentPassword(configurationPasswordNumber, configurationPassword);
     
    // Set a password for Area1. We choose Password 0
    int area1PasswordNumber = 0;
    st25DVTag.setPasswordNumber(MultiAreaInterface.AREA1, area1PasswordNumber);
     
    // Set Area1 protection
    st25DVTag.setReadWriteProtection(MultiAreaInterface.AREA1, READABLE_AND_WRITE_IMPOSSIBLE);

    The Write is now password protected.

    If someone wants to write into this area, he should first enter the area password. Look how it is done in presentPassword() of "ST25DVPresentPwdActivity".

    For your information, the calls to ST25 SDK should be done from a background Thread or from an Async Task. If you try to call the SDK from the UI Thread you will get an exception because it is not allowed to block the UI Thread for a too long time.

    By the way, when reading or writing into an Area with the functions readBytes() and writeBytes(), you will get an exception if the area is protected by password (in read or in write). You can catch the exceptions ISO15693_BLOCK_PROTECTED and ISO15693_BLOCK_IS_LOCKED and display a popup requesting the Area password. If the password is presented successfully, you can try to read or write again.

    Best regards

    7 replies

    Olivier LAnswer
    ST Employee
    August 24, 2020

    Hi,

    Have you downloaded the source code of our "ST25 NFC Tap" application? It contains lot of examples showing all the features of our NFC Tags. You can get it here:

    https://www.st.com/en/embedded-software/stsw-st25001.html

    You can then look at the class "ST25DVChangePermissionsActivity". This is the class managing the change of permissions for ST25DV areas. You can look at the function changePermission().

    I see now that there is in fact a simpler manner to set the permissions. In this function, we are accessing directly to the ST25DV Registers. It is in fact simpler to use a generic interface supported by ST25DVTags. This is the "MultiAreaInterface" defined in ST25 SDK. Here is some pseudo code showing the idea:

    // Configuration password should be entered before changing the ST25DV configuration
    final byte[] configurationPassword = PUT_YOUR_PASSWORD_HERE;
    int configurationPasswordNumber = st25DVTag.getConfigurationPasswordNumber();
    st25DVTag.presentPassword(configurationPasswordNumber, configurationPassword);
     
    // Set a password for Area1. We choose Password 0
    int area1PasswordNumber = 0;
    st25DVTag.setPasswordNumber(MultiAreaInterface.AREA1, area1PasswordNumber);
     
    // Set Area1 protection
    st25DVTag.setReadWriteProtection(MultiAreaInterface.AREA1, READABLE_AND_WRITE_IMPOSSIBLE);

    The Write is now password protected.

    If someone wants to write into this area, he should first enter the area password. Look how it is done in presentPassword() of "ST25DVPresentPwdActivity".

    For your information, the calls to ST25 SDK should be done from a background Thread or from an Async Task. If you try to call the SDK from the UI Thread you will get an exception because it is not allowed to block the UI Thread for a too long time.

    By the way, when reading or writing into an Area with the functions readBytes() and writeBytes(), you will get an exception if the area is protected by password (in read or in write). You can catch the exceptions ISO15693_BLOCK_PROTECTED and ISO15693_BLOCK_IS_LOCKED and display a popup requesting the Area password. If the password is presented successfully, you can try to read or write again.

    Best regards

    DSPAuthor
    Visitor II
    September 3, 2020

    Hi Oliver.

    First of all, I want to thank you for your fast and complete answer.

    I have the app ST25 NFC Tap installed from the first day and I use it to check the functionalities of my app continuosly. However, I didn't know that the source code was available to download :downcast_face_with_sweat: Consequently, I have been only using the SDK Manual downloaded for your web.

    Now I have it and I will use it to investigate pieces of code or new functionalities which may be usefull for my app.

    Thanks again for the app clue and for you pseudo code. It will really help me.;)

    Best regards.

    ST Employee
    September 4, 2020

    You're welcome! I'm glad if it can help you to achieve your NFC project.

    Best regards

    Olivier

    DSPAuthor
    Visitor II
    December 10, 2020

    Hi Oliver!.

    I have a big problem :face_screaming_in_fear::

    I used the ST25 NFC Tap application to change the Password 1 and to assign it to Area 1 in order to try all these protection features with my new application. But I think I put something different from what I wanted and now I can't change it because the "Present Password" function in the ST25 NFC Tap returns COMMAND_FAILED with all the passwords I tried.

    Is there a way to do a factory reset to Password 1? Can it be done with the app?

    Thank you very much for your help.

    Kind regards.

    ST Employee
    December 11, 2020

    Hi,

    No, there is no way to reset the password because it would be a security issue. In my opinion, the best solution is to replace this tag by a brand new one.

    Kind regards

    DSPAuthor
    Visitor II
    December 11, 2020

    Hi Olivier.

    And isn't there any procedure to make a factory-reset to the tag either?.

    Thanks for your answers.

    ST Employee
    December 11, 2020

    Hi,

    There is no factory reset on the tag. The possible solutions are:

    • replace the tag
    • remember the password (ideal solution)
    • write a small java program to tests some passwords similar to the one that you intended to set. You may find the password if it was a typo error.

    Best regards

    Olivier