2024-10-20 06:49 PM - edited 2024-10-20 07:07 PM
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)
First, my code is as follows(demo is based on NFC08A1 in NFC6 generated in CUBE MX):
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
2.PresentPassword's ReturnCode is incorrect
3.WritePassword's ReturnCode is incorrect ,too.
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
Solved! Go to Solution.
2024-10-21 08:09 PM
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
2024-10-21 08:09 PM
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