2024-10-01 03:27 AM
I'm fairly new in NFC technology and was trying to implement a simple project that uses the ST25R3916 to write a message in a specific memory location of the ST25DV04K and then locks write access to that specific memory location. I'm using an adapted version of the library "en.x-cube-nfc6". I can read/write messages without any problem, but when I can't seem to find any function in the library to block the write access that works. I'm using "ndefPollerWriteBytes(ndefContext *ctx, uint32_t offset, const uint8_t *buf, uint32_t len)" to write, which works fine, butif I try to use "ndefPollerSetReadOnly(ndefContext *ctx)", it returns error 33 "Wrong State". Am I doing something wrong? Should I use different functions? I'll append a picture of my code, which stems from the demo usage of the library. The purpuse of the code was to write 4 bytes, lock access then try to write again (which sould fail, I guess).
Solved! Go to Solution.
2024-10-01 05:58 AM
Hi,
ndefPollerSetReadOnly is supposed to be used on tags being in READ/WRITE state. I guess your tag is in INITIALIZED state. As you directly write raw data into the tag memory with ndefPollerWriteBytes (i.e. you did not write a formatted NDEF message), the ctx->state (tag state) stays at value NDEF_STATE_INITIALIZED and makes ndefPollerSetReadOnly returns ERR_WRONG_STATE. You can either write a message with an empty NDEF to move to NDEF_STATE_READWRITE before calling ndefPollerSetReadOnly or force the ctx->state value to NDEF_STATE_READWRITE.
Note that the support of the Lock Block command is optional for tags. For ST25DV04K tags, this command is only applicable for the blocks 0 and 1 (see ST25DV datasheet).
For your use case, I would rather suggest to use data protection (see section 5.6). The API needed for the data protection are available in rfal_st25xv.c (e.g. rfalST25xVPollerPresentPassword).
Rgds
BT
2024-10-01 05:58 AM
Hi,
ndefPollerSetReadOnly is supposed to be used on tags being in READ/WRITE state. I guess your tag is in INITIALIZED state. As you directly write raw data into the tag memory with ndefPollerWriteBytes (i.e. you did not write a formatted NDEF message), the ctx->state (tag state) stays at value NDEF_STATE_INITIALIZED and makes ndefPollerSetReadOnly returns ERR_WRONG_STATE. You can either write a message with an empty NDEF to move to NDEF_STATE_READWRITE before calling ndefPollerSetReadOnly or force the ctx->state value to NDEF_STATE_READWRITE.
Note that the support of the Lock Block command is optional for tags. For ST25DV04K tags, this command is only applicable for the blocks 0 and 1 (see ST25DV datasheet).
For your use case, I would rather suggest to use data protection (see section 5.6). The API needed for the data protection are available in rfal_st25xv.c (e.g. rfalST25xVPollerPresentPassword).
Rgds
BT