cancel
Showing results for 
Search instead for 
Did you mean: 

How to set a password for the user memory area on the ST25TV02KC Tag?

Rance
Associate III

Hi,St Community!

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_0-1729476262099.jpeg

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

Rance_1-1729476268722.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-1729476294865.png

Rance_3-1729476303369.png

 

2.PresentPassword's ReturnCode is incorrect

Rance_4-1729476326869.png

Rance_5-1729476332686.png

 

3.WritePassword's ReturnCode is incorrect ,too.

Rance_6-1729476338397.png

Rance_7-1729476344056.png

 

 

Rance_8-1729476358429.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_9-1729476390007.png

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
Rance
Associate III

Hi Rance

If you want to set a password for the user memory area on the card.

You need to follow these steps

1.Get 2 bytes Random Number

2.Make the password and Random Number XOR.

3.Use the Present Password function to enter secure session mode.

4.Start writing the password that you want

 

Notice:

The initial password is  0x00

View solution in original post

1 REPLY 1
Rance
Associate III

Hi Rance

If you want to set a password for the user memory area on the card.

You need to follow these steps

1.Get 2 bytes Random Number

2.Make the password and Random Number XOR.

3.Use the Present Password function to enter secure session mode.

4.Start writing the password that you want

 

Notice:

The initial password is  0x00