cancel
Showing results for 
Search instead for 
Did you mean: 

ST25DV64K password read/write with ST25SDK

DSP
Associate II

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!.

1 ACCEPTED SOLUTION

Accepted Solutions
Olivier L
ST Employee

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

View solution in original post

7 REPLIES 7
Olivier L
ST Employee

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

DSP
Associate II

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.

Olivier L
ST Employee

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

Best regards

Olivier

DSP
Associate II

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.

Olivier L
ST Employee

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

DSP
Associate II

Hi Olivier.

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

Thanks for your answers.

Olivier L
ST Employee

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