2024-10-14 09:28 AM
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.
Based on the underlined sentence in the image, I first send the data related to the PresentPassword request format.
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.
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:
Code section:
Print result(display normally):
So, in order to encrypt the block, what exactly should I do? What configurations do I need to set up first?
Solved! Go to Solution.
2024-10-15 01:45 AM
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.
2024-10-15 01:45 AM
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.
2024-10-15 01:52 AM
Hi,
In addition to this reply, I suggest to use the RFAL library that provides support for ST25TV commands such as PresentPasword.
Rgds
BT
2024-10-15 09:56 AM
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)
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
2024-10-15 11:49 AM
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