cancel
Showing results for 
Search instead for 
Did you mean: 

About ST25TV02kcTag encryption issues

Rance
Associate III

Hi!St Community

 

My goal is to set a password for the user memory area on the card.

During the process of writing the encryption code for the card, I read the manual for the ST25TV02KC.

Rance_4-1728922336122.png

 

 

 

Rance_0-1728921724082.pngBased on the underlined sentence in the image, I first send the data related to the PresentPassword request format.

 

 

 

Rance_2-1728921813115.png

The corresponding configuration bits in the code are as follows

                        arr[0] = 0x20;
						arr[1] = 0xb3;
						arr[2] = 0x02;
						arr[3] = uid[7];
						arr[4] = uid[6];
						arr[5] = uid[5];
						arr[6] = uid[4];
						arr[7] = uid[3];
						arr[8] = uid[2];
						arr[9] = uid[1];
						arr[10] = uid[0];
						arr[11] = 0x01;
						arr[12] = 0x11;
						arr[13] = 0x22;
						arr[14] = 0x33;
						arr[15] = 0x44;
						arr[16] = 0x55;
						arr[17] = 0x66;
						arr[18] = 0x77;
						arr[19] = 0x88;
						arr[20] = (PY_CRC_16_S_X25(arr,20)%256);
						arr[21] = (PY_CRC_16_S_X25(arr,20)/256);

 The send should have been successful, but the return value of the FIFO seems abnormal.

Rance_3-1728922019762.png

Could it be because the order of my operations was incorrect ?

 

 

 

 

Before this, I completed the read and write operations on the blocks according to the relevant instructions in the datasheet , and now I will demonstrate that

Related instruction:

Rance_5-1728922880564.png

Code section:

Rance_7-1728922916644.png

Print result(display normally):

Rance_8-1728923060737.png

Rance_9-1728923115801.png

 

 

So, in order to encrypt the block, what exactly should I do? What configurations do I need to set up first?

 

 

 

 

 

 

 

This discussion has been locked for participation. If you have a question, please start a new topic in order to ask your question
1 ACCEPTED SOLUTION

Accepted Solutions
JL. Lebon
ST Employee

Hello, 

I think that the first byte of your command is wrong.
The first byte of the command is the Request Flag byte. It sets up the data rate and the modulation requested for the answer, plus other parameters.

In your read and write commands, the request flag is set to 0x22.

In your Present password command, the request flag is set to 0x20.

The difference is that in the bit 1 of the request flag. This bit sets the data rate of the answer. In your read and write commands, it is set to High Data rate. In your Present password command, it is set to Low data rate.
Some readers do not support the Low Data rate. So please, try the Present password command with the request flag set to 0x22.
Best regards.

View solution in original post

4 REPLIES 4
JL. Lebon
ST Employee

Hello, 

I think that the first byte of your command is wrong.
The first byte of the command is the Request Flag byte. It sets up the data rate and the modulation requested for the answer, plus other parameters.

In your read and write commands, the request flag is set to 0x22.

In your Present password command, the request flag is set to 0x20.

The difference is that in the bit 1 of the request flag. This bit sets the data rate of the answer. In your read and write commands, it is set to High Data rate. In your Present password command, it is set to Low data rate.
Some readers do not support the Low Data rate. So please, try the Present password command with the request flag set to 0x22.
Best regards.

Hi,

In addition to this reply, I suggest to use the RFAL library that provides support for ST25TV commands such as PresentPasword.

Rgds

BT

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Hi,Lebon!

I tried to use the RFAL library that provides support for ST25TV commands such as PresentPasword and WritePassword.

However, it is still not possible to set a password for the user memory area on the card.

My specific operation process is as follows.

 

 

The device I used is shown here(NFC08A1+stm32f401)

Rance_9-1729011066423.jpeg

First, my code is as follows(demo is based on NFC08A1 in NFC6 generated in CUBE MX):

Rance_0-1729009614317.png

static void demoNfcv( rfalNfcvListenDevice *nfcvDev )
{
#if RFAL_FEATURE_NFCV

    ReturnCode            err;
    uint16_t              rcvLen;
    uint8_t               blockNum = 1;
    uint8_t               rxBuf[ 1 + DEMO_NFCV_BLOCK_LEN + RFAL_CRC_LEN ];                        /* Flags + Block Data + CRC */
    uint8_t               *uid;
    uint8_t               reqFlag;
		uint8_t               pwd[8] = {0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88};
	
	
		uint8_t               rxBuf_pwd[12];  
	
#if DEMO_NFCV_WRITE_TAG				
    uint8_t               wrData[DEMO_NFCV_BLOCK_LEN] = { 0x00, 0x00, 0x00, 0x00};             /* Write block example */
#endif /* DEMO_NFCV_WRITE_TAG */

    uid     = nfcvDev->InvRes.UID;
    reqFlag = RFAL_NFCV_REQ_FLAG_DEFAULT;

    #if DEMO_NFCV_USE_SELECT_MODE
        /*
        * Activate selected state
        */
        err = rfalNfcvPollerSelect( reqFlag, nfcvDev->InvRes.UID );
        platformLog(" Select %s \r\n", (err != RFAL_ERR_NONE) ? "FAIL (revert to addressed mode)": "OK" );
        if( err == RFAL_ERR_NONE )
        {
            reqFlag = (RFAL_NFCV_REQ_FLAG_DEFAULT | RFAL_NFCV_REQ_FLAG_SELECT);
            uid     = NULL;
        }
    #endif /* DEMO_NFCV_USE_SELECT_MODE */

    /*
    * Read block using Read Single Block command
    * with addressed mode (uid != NULL) or selected mode (uid == NULL)
    */
    err = rfalNfcvPollerReadSingleBlock(reqFlag, uid, blockNum, rxBuf, sizeof(rxBuf), &rcvLen);
    platformLog(" Read Block: %s %s\r\n", (err != RFAL_ERR_NONE) ? "FAIL": "OK Data:", (err != RFAL_ERR_NONE) ? "" : hex2Str( &rxBuf[1], DEMO_NFCV_BLOCK_LEN));
		
		err = rfalST25xVPollerGetRandomNumber( RFAL_NFCV_REQ_FLAG_DEFAULT,uid,rxBuf_pwd, sizeof(rxBuf_pwd),&rcvLen );
		platformLog(" GetRandomNumber: %s %s\r\n", (err != RFAL_ERR_NONE) ? "FAIL": "OK Data:", (err != RFAL_ERR_NONE) ? "" : hex2Str( &rxBuf_pwd[1], 11));
		
		err =  rfalST25xVPollerPresentPassword( RFAL_NFCV_REQ_FLAG_DEFAULT,uid,0x01,pwd,8);
		platformLog(" PresentPassword	ReturnCode is: %d \r\n", err);
		err =  rfalST25xVPollerWritePassword( RFAL_NFCV_REQ_FLAG_DEFAULT,uid,0x01,pwd,8);
		platformLog(" WritePassword	ReturnCode is: %d \r\n", err);
    #if DEMO_NFCV_WRITE_TAG /* Writing example */
        err = rfalNfcvPollerWriteSingleBlock(reqFlag, uid, blockNum, wrData, sizeof(wrData));
        platformLog(" Write Block: %s Data: %s\r\n", (err != RFAL_ERR_NONE) ? "FAIL": "OK", hex2Str( wrData, DEMO_NFCV_BLOCK_LEN) );
        err = rfalNfcvPollerReadSingleBlock(reqFlag, uid, blockNum, rxBuf, sizeof(rxBuf), &rcvLen);
        platformLog(" Read Block: %s %s\r\n", (err != RFAL_ERR_NONE) ? "FAIL": "OK Data:", (err != RFAL_ERR_NONE) ? "" : hex2Str( &rxBuf[1], DEMO_NFCV_BLOCK_LEN));
    #endif /* DEMO_NFCV_WRITE_TAG */

#endif /* RFAL_FEATURE_NFCV */
}

 

 

Next I try to print out the FIFO data as follows:

1.The GetRandomNumber function is normal

Rance_2-1729009883535.png

Rance_1-1729009849956.png

 

2.PresentPassword's ReturnCode is incorrect

Rance_3-1729010300897.png

 

Rance_4-1729010367229.png

 

3.WritePassword's ReturnCode is incorrect ,too.

Rance_5-1729010444528.png

Rance_6-1729010514278.png

Rance_7-1729010594818.png

so why is the value of ReturnCode 5?

And why am I still calling the api function of the demo? but invalid request or requested function can't be executed at the moment.

So, in order to encrypt the block, what exactly should I do? What configurations do I need to set up first?

 

 

 

Supplementary instruction,

my print function is as follows

Rance_8-1729010887188.png

 

 

 

 

 

Hi,

as a general rule of this community, it is recommended to create a new post when having a new question rather than replying to an already answered post. This provides a better readability.

Anyway, I guess PresentPassword returns an error code because the password has not been cover-coded with the random value. See §5.1.3 in the ST25TV02KC datasheet.

Rgds

BT

 

 

 

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.