Apply clang-format
find * | grep "\.[ch]" | xargs clang-format --style=file -i
Test: compiles
Change-Id: Id9b790d9685f7ba5ba1bcec1149619b63c2e679a
signed-off-by: Ruchi Kandoi <kandoiruchi@google.com>
diff --git a/src/nfc/tags/rw_t2t_ndef.c b/src/nfc/tags/rw_t2t_ndef.c
index 7214d9f..7562bf0 100644
--- a/src/nfc/tags/rw_t2t_ndef.c
+++ b/src/nfc/tags/rw_t2t_ndef.c
@@ -16,7 +16,6 @@
*
******************************************************************************/
-
/******************************************************************************
*
* This file contains the implementation for Type 2 tag NDEF operation in
@@ -27,48 +26,54 @@
#include "nfc_target.h"
#if (NFC_INCLUDED == TRUE)
-#include "nfc_api.h"
+#include "gki.h"
#include "nci_hmsgs.h"
+#include "nfc_api.h"
+#include "nfc_int.h"
#include "rw_api.h"
#include "rw_int.h"
-#include "nfc_int.h"
-#include "gki.h"
#if (RW_NDEF_INCLUDED == TRUE)
/* Local static functions */
-static void rw_t2t_handle_cc_read_rsp (void);
-static void rw_t2t_handle_lock_read_rsp (uint8_t *p_data);
-static void rw_t2t_handle_tlv_detect_rsp (uint8_t *p_data);
-static void rw_t2t_handle_ndef_read_rsp (uint8_t *p_data);
-static void rw_t2t_handle_ndef_write_rsp (uint8_t *p_data);
-static void rw_t2t_handle_format_tag_rsp (uint8_t *p_data);
-static void rw_t2t_handle_config_tag_readonly (uint8_t *p_data);
-static uint8_t rw_t2t_get_tag_size (uint8_t *p_data);
-static void rw_t2t_extract_default_locks_info (void);
-static void rw_t2t_update_cb (uint16_t block, uint8_t *p_write_block, bool b_update_len);
-static uint8_t rw_t2t_get_ndef_flags (void);
-static uint16_t rw_t2t_get_ndef_max_size (void);
-static tNFC_STATUS rw_t2t_read_locks (void);
-static tNFC_STATUS rw_t2t_read_ndef_last_block (void);
-static void rw_t2t_update_attributes (void);
-static void rw_t2t_update_lock_attributes (void);
-static bool rw_t2t_is_lock_res_byte (uint16_t index);
-static bool rw_t2t_is_read_only_byte (uint16_t index);
-static tNFC_STATUS rw_t2t_write_ndef_first_block (uint16_t msg_len, bool b_update_len);
-static tNFC_STATUS rw_t2t_write_ndef_next_block (uint16_t block, uint16_t msg_len, bool b_update_len);
-static tNFC_STATUS rw_t2t_read_ndef_next_block (uint16_t block);
-static tNFC_STATUS rw_t2t_add_terminator_tlv (void);
-static bool rw_t2t_is_read_before_write_block (uint16_t block, uint16_t *p_block_to_read);
-static tNFC_STATUS rw_t2t_set_cc (uint8_t tms);
-static tNFC_STATUS rw_t2t_set_lock_tlv (uint16_t addr, uint8_t num_dyn_lock_bits, uint16_t locked_area_size);
-static tNFC_STATUS rw_t2t_format_tag (void);
-static tNFC_STATUS rw_t2t_soft_lock_tag (void);
-static tNFC_STATUS rw_t2t_set_dynamic_lock_bits (uint8_t *p_data);
-static void rw_t2t_ntf_tlv_detect_complete (tNFC_STATUS status);
+static void rw_t2t_handle_cc_read_rsp(void);
+static void rw_t2t_handle_lock_read_rsp(uint8_t* p_data);
+static void rw_t2t_handle_tlv_detect_rsp(uint8_t* p_data);
+static void rw_t2t_handle_ndef_read_rsp(uint8_t* p_data);
+static void rw_t2t_handle_ndef_write_rsp(uint8_t* p_data);
+static void rw_t2t_handle_format_tag_rsp(uint8_t* p_data);
+static void rw_t2t_handle_config_tag_readonly(uint8_t* p_data);
+static uint8_t rw_t2t_get_tag_size(uint8_t* p_data);
+static void rw_t2t_extract_default_locks_info(void);
+static void rw_t2t_update_cb(uint16_t block, uint8_t* p_write_block,
+ bool b_update_len);
+static uint8_t rw_t2t_get_ndef_flags(void);
+static uint16_t rw_t2t_get_ndef_max_size(void);
+static tNFC_STATUS rw_t2t_read_locks(void);
+static tNFC_STATUS rw_t2t_read_ndef_last_block(void);
+static void rw_t2t_update_attributes(void);
+static void rw_t2t_update_lock_attributes(void);
+static bool rw_t2t_is_lock_res_byte(uint16_t index);
+static bool rw_t2t_is_read_only_byte(uint16_t index);
+static tNFC_STATUS rw_t2t_write_ndef_first_block(uint16_t msg_len,
+ bool b_update_len);
+static tNFC_STATUS rw_t2t_write_ndef_next_block(uint16_t block,
+ uint16_t msg_len,
+ bool b_update_len);
+static tNFC_STATUS rw_t2t_read_ndef_next_block(uint16_t block);
+static tNFC_STATUS rw_t2t_add_terminator_tlv(void);
+static bool rw_t2t_is_read_before_write_block(uint16_t block,
+ uint16_t* p_block_to_read);
+static tNFC_STATUS rw_t2t_set_cc(uint8_t tms);
+static tNFC_STATUS rw_t2t_set_lock_tlv(uint16_t addr, uint8_t num_dyn_lock_bits,
+ uint16_t locked_area_size);
+static tNFC_STATUS rw_t2t_format_tag(void);
+static tNFC_STATUS rw_t2t_soft_lock_tag(void);
+static tNFC_STATUS rw_t2t_set_dynamic_lock_bits(uint8_t* p_data);
+static void rw_t2t_ntf_tlv_detect_complete(tNFC_STATUS status);
-const uint8_t rw_t2t_mask_bits[8] =
-{0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
+const uint8_t rw_t2t_mask_bits[8] = {0x01, 0x02, 0x04, 0x08,
+ 0x10, 0x20, 0x40, 0x80};
/*******************************************************************************
**
@@ -80,86 +85,67 @@
** Returns None
**
*******************************************************************************/
-void rw_t2t_handle_rsp (uint8_t *p_data)
-{
- tRW_T2T_CB *p_t2t = &rw_cb.tcb.t2t;
+void rw_t2t_handle_rsp(uint8_t* p_data) {
+ tRW_T2T_CB* p_t2t = &rw_cb.tcb.t2t;
- if (p_t2t->substate == RW_T2T_SUBSTATE_WAIT_READ_CC)
- {
- p_t2t->b_read_hdr = true;
- memcpy (p_t2t->tag_hdr, p_data, T2T_READ_DATA_LEN);
- }
+ if (p_t2t->substate == RW_T2T_SUBSTATE_WAIT_READ_CC) {
+ p_t2t->b_read_hdr = true;
+ memcpy(p_t2t->tag_hdr, p_data, T2T_READ_DATA_LEN);
+ }
- switch (p_t2t->state)
- {
+ switch (p_t2t->state) {
case RW_T2T_STATE_DETECT_TLV:
- if (p_t2t->tlv_detect == TAG_LOCK_CTRL_TLV)
- {
- if (p_t2t->substate == RW_T2T_SUBSTATE_WAIT_READ_CC)
- {
- rw_t2t_handle_cc_read_rsp ();
- }
- else if (p_t2t->substate == RW_T2T_SUBSTATE_WAIT_READ_LOCKS)
- {
- rw_t2t_handle_lock_read_rsp (p_data);
- }
- else
- {
- rw_t2t_handle_tlv_detect_rsp (p_data);
- }
+ if (p_t2t->tlv_detect == TAG_LOCK_CTRL_TLV) {
+ if (p_t2t->substate == RW_T2T_SUBSTATE_WAIT_READ_CC) {
+ rw_t2t_handle_cc_read_rsp();
+ } else if (p_t2t->substate == RW_T2T_SUBSTATE_WAIT_READ_LOCKS) {
+ rw_t2t_handle_lock_read_rsp(p_data);
+ } else {
+ rw_t2t_handle_tlv_detect_rsp(p_data);
}
- else if (p_t2t->tlv_detect == TAG_NDEF_TLV)
- {
- if (p_t2t->substate == RW_T2T_SUBSTATE_WAIT_READ_CC)
- {
- if (p_t2t->tag_hdr[T2T_CC0_NMN_BYTE] == T2T_CC0_NMN)
- {
- rw_t2t_handle_cc_read_rsp ();
- }
- else
- {
- RW_TRACE_WARNING3 ("NDEF Detection failed!, CC[0]: 0x%02x, CC[1]: 0x%02x, CC[3]: 0x%02x", p_t2t->tag_hdr[T2T_CC0_NMN_BYTE], p_t2t->tag_hdr[T2T_CC1_VNO_BYTE], p_t2t->tag_hdr[T2T_CC3_RWA_BYTE]);
- rw_t2t_ntf_tlv_detect_complete (NFC_STATUS_FAILED);
- }
- }
- else if (p_t2t->substate == RW_T2T_SUBSTATE_WAIT_READ_LOCKS)
- {
- rw_t2t_handle_lock_read_rsp (p_data);
- }
- else
- {
- rw_t2t_handle_tlv_detect_rsp (p_data);
- }
+ } else if (p_t2t->tlv_detect == TAG_NDEF_TLV) {
+ if (p_t2t->substate == RW_T2T_SUBSTATE_WAIT_READ_CC) {
+ if (p_t2t->tag_hdr[T2T_CC0_NMN_BYTE] == T2T_CC0_NMN) {
+ rw_t2t_handle_cc_read_rsp();
+ } else {
+ RW_TRACE_WARNING3(
+ "NDEF Detection failed!, CC[0]: 0x%02x, CC[1]: 0x%02x, CC[3]: "
+ "0x%02x",
+ p_t2t->tag_hdr[T2T_CC0_NMN_BYTE],
+ p_t2t->tag_hdr[T2T_CC1_VNO_BYTE],
+ p_t2t->tag_hdr[T2T_CC3_RWA_BYTE]);
+ rw_t2t_ntf_tlv_detect_complete(NFC_STATUS_FAILED);
+ }
+ } else if (p_t2t->substate == RW_T2T_SUBSTATE_WAIT_READ_LOCKS) {
+ rw_t2t_handle_lock_read_rsp(p_data);
+ } else {
+ rw_t2t_handle_tlv_detect_rsp(p_data);
}
- else
- {
- if (p_t2t->substate == RW_T2T_SUBSTATE_WAIT_READ_CC)
- {
- rw_t2t_handle_cc_read_rsp ();
- }
- else
- {
- rw_t2t_handle_tlv_detect_rsp (p_data);
- }
+ } else {
+ if (p_t2t->substate == RW_T2T_SUBSTATE_WAIT_READ_CC) {
+ rw_t2t_handle_cc_read_rsp();
+ } else {
+ rw_t2t_handle_tlv_detect_rsp(p_data);
}
- break;
+ }
+ break;
case RW_T2T_STATE_SET_TAG_RO:
- rw_t2t_handle_config_tag_readonly (p_data);
- break;
+ rw_t2t_handle_config_tag_readonly(p_data);
+ break;
case RW_T2T_STATE_FORMAT_TAG:
- rw_t2t_handle_format_tag_rsp (p_data);
- break;
+ rw_t2t_handle_format_tag_rsp(p_data);
+ break;
case RW_T2T_STATE_READ_NDEF:
- rw_t2t_handle_ndef_read_rsp (p_data);
- break;
+ rw_t2t_handle_ndef_read_rsp(p_data);
+ break;
case RW_T2T_STATE_WRITE_NDEF:
- rw_t2t_handle_ndef_write_rsp (p_data);
- break;
- }
+ rw_t2t_handle_ndef_write_rsp(p_data);
+ break;
+ }
}
/*******************************************************************************
@@ -172,46 +158,44 @@
** Returns RW event code
**
*******************************************************************************/
-tRW_EVENT rw_t2t_info_to_event (const tT2T_CMD_RSP_INFO *p_info)
-{
- tRW_EVENT rw_event;
- tRW_T2T_CB *p_t2t = &rw_cb.tcb.t2t;
+tRW_EVENT rw_t2t_info_to_event(const tT2T_CMD_RSP_INFO* p_info) {
+ tRW_EVENT rw_event;
+ tRW_T2T_CB* p_t2t = &rw_cb.tcb.t2t;
- switch (p_t2t->state)
- {
+ switch (p_t2t->state) {
case RW_T2T_STATE_DETECT_TLV:
- if (p_t2t->tlv_detect == TAG_NDEF_TLV)
- rw_event = RW_T2T_NDEF_DETECT_EVT;
- else
- rw_event = RW_T2T_TLV_DETECT_EVT;
+ if (p_t2t->tlv_detect == TAG_NDEF_TLV)
+ rw_event = RW_T2T_NDEF_DETECT_EVT;
+ else
+ rw_event = RW_T2T_TLV_DETECT_EVT;
- break;
+ break;
case RW_T2T_STATE_READ_NDEF:
- rw_event = RW_T2T_NDEF_READ_EVT;
- break;
+ rw_event = RW_T2T_NDEF_READ_EVT;
+ break;
case RW_T2T_STATE_WRITE_NDEF:
- rw_event = RW_T2T_NDEF_WRITE_EVT;
- break;
+ rw_event = RW_T2T_NDEF_WRITE_EVT;
+ break;
case RW_T2T_STATE_SET_TAG_RO:
- rw_event = RW_T2T_SET_TAG_RO_EVT;
- break;
+ rw_event = RW_T2T_SET_TAG_RO_EVT;
+ break;
case RW_T2T_STATE_CHECK_PRESENCE:
- rw_event = RW_T2T_PRESENCE_CHECK_EVT;
- break;
+ rw_event = RW_T2T_PRESENCE_CHECK_EVT;
+ break;
case RW_T2T_STATE_FORMAT_TAG:
- rw_event = RW_T2T_FORMAT_CPLT_EVT;
- break;
+ rw_event = RW_T2T_FORMAT_CPLT_EVT;
+ break;
default:
- rw_event = t2t_info_to_evt (p_info);
- break;
- }
- return rw_event;
+ rw_event = t2t_info_to_evt(p_info);
+ break;
+ }
+ return rw_event;
}
/*******************************************************************************
@@ -223,28 +207,24 @@
** Returns none
**
*******************************************************************************/
-static void rw_t2t_handle_cc_read_rsp (void)
-{
- tRW_T2T_CB *p_t2t = &rw_cb.tcb.t2t;
+static void rw_t2t_handle_cc_read_rsp(void) {
+ tRW_T2T_CB* p_t2t = &rw_cb.tcb.t2t;
- if ( ( (p_t2t->tag_hdr[T2T_CC3_RWA_BYTE] != T2T_CC3_RWA_RW)
- &&(p_t2t->tag_hdr[T2T_CC3_RWA_BYTE] != T2T_CC3_RWA_RO) )
- ||
- ( (p_t2t->tag_hdr[T2T_CC1_VNO_BYTE] != T2T_CC1_LEGACY_VNO)
- &&(p_t2t->tag_hdr[T2T_CC1_VNO_BYTE] != T2T_CC1_VNO)
- &&(p_t2t->tag_hdr[T2T_CC1_VNO_BYTE] != T2T_CC1_NEW_VNO) ) )
- {
- /* Invalid Version number or RWA byte */
- rw_t2t_ntf_tlv_detect_complete (NFC_STATUS_FAILED);
- return;
- }
+ if (((p_t2t->tag_hdr[T2T_CC3_RWA_BYTE] != T2T_CC3_RWA_RW) &&
+ (p_t2t->tag_hdr[T2T_CC3_RWA_BYTE] != T2T_CC3_RWA_RO)) ||
+ ((p_t2t->tag_hdr[T2T_CC1_VNO_BYTE] != T2T_CC1_LEGACY_VNO) &&
+ (p_t2t->tag_hdr[T2T_CC1_VNO_BYTE] != T2T_CC1_VNO) &&
+ (p_t2t->tag_hdr[T2T_CC1_VNO_BYTE] != T2T_CC1_NEW_VNO))) {
+ /* Invalid Version number or RWA byte */
+ rw_t2t_ntf_tlv_detect_complete(NFC_STATUS_FAILED);
+ return;
+ }
- p_t2t->substate = RW_T2T_SUBSTATE_WAIT_TLV_DETECT;
+ p_t2t->substate = RW_T2T_SUBSTATE_WAIT_TLV_DETECT;
- if (rw_t2t_read ((uint16_t) T2T_FIRST_DATA_BLOCK) != NFC_STATUS_OK)
- {
- rw_t2t_ntf_tlv_detect_complete (NFC_STATUS_FAILED);
- }
+ if (rw_t2t_read((uint16_t)T2T_FIRST_DATA_BLOCK) != NFC_STATUS_OK) {
+ rw_t2t_ntf_tlv_detect_complete(NFC_STATUS_FAILED);
+ }
}
/*******************************************************************************
@@ -256,74 +236,61 @@
** Returns none
**
*******************************************************************************/
-static void rw_t2t_ntf_tlv_detect_complete (tNFC_STATUS status)
-{
- tRW_T2T_CB *p_t2t = &rw_cb.tcb.t2t;
- tRW_DETECT_NDEF_DATA ndef_data = {0, };
- tRW_DETECT_TLV_DATA tlv_data;
- tRW_T2T_DETECT evt_data;
- uint8_t xx;
+static void rw_t2t_ntf_tlv_detect_complete(tNFC_STATUS status) {
+ tRW_T2T_CB* p_t2t = &rw_cb.tcb.t2t;
+ tRW_DETECT_NDEF_DATA ndef_data = {
+ 0,
+ };
+ tRW_DETECT_TLV_DATA tlv_data;
+ tRW_T2T_DETECT evt_data;
+ uint8_t xx;
- if (p_t2t->tlv_detect == TAG_NDEF_TLV)
- {
- /* Notify upper layer the result of NDEF detect op */
- ndef_data.status = status;
- ndef_data.protocol = NFC_PROTOCOL_T2T;
- ndef_data.flags = rw_t2t_get_ndef_flags ();
- ndef_data.cur_size = p_t2t->ndef_msg_len;
+ if (p_t2t->tlv_detect == TAG_NDEF_TLV) {
+ /* Notify upper layer the result of NDEF detect op */
+ ndef_data.status = status;
+ ndef_data.protocol = NFC_PROTOCOL_T2T;
+ ndef_data.flags = rw_t2t_get_ndef_flags();
+ ndef_data.cur_size = p_t2t->ndef_msg_len;
- if (status == NFC_STATUS_OK)
- ndef_data.flags |= RW_NDEF_FL_FORMATED;
+ if (status == NFC_STATUS_OK) ndef_data.flags |= RW_NDEF_FL_FORMATED;
- if (p_t2t->tag_hdr[T2T_CC3_RWA_BYTE] == T2T_CC3_RWA_RW)
- ndef_data.max_size = (uint32_t) rw_t2t_get_ndef_max_size ();
- else
- ndef_data.max_size = ndef_data.cur_size;
-
- if (ndef_data.max_size < ndef_data.cur_size)
- {
- ndef_data.flags |= RW_NDEF_FL_READ_ONLY;
- ndef_data.max_size = ndef_data.cur_size;
- }
-
- if (!(ndef_data.flags & RW_NDEF_FL_READ_ONLY))
- {
- ndef_data.flags |= RW_NDEF_FL_SOFT_LOCKABLE;
- if (status == NFC_STATUS_OK)
- ndef_data.flags |= RW_NDEF_FL_HARD_LOCKABLE;
- }
-
- rw_t2t_handle_op_complete ();
- (*rw_cb.p_cback) (RW_T2T_NDEF_DETECT_EVT, (tRW_DATA *) &ndef_data);
- }
- else if (p_t2t->tlv_detect == TAG_PROPRIETARY_TLV)
- {
- evt_data.msg_len = p_t2t->prop_msg_len;
- evt_data.status = status;
- rw_t2t_handle_op_complete ();
- (*rw_cb.p_cback) (RW_T2T_TLV_DETECT_EVT, (tRW_DATA *) &evt_data);
- }
+ if (p_t2t->tag_hdr[T2T_CC3_RWA_BYTE] == T2T_CC3_RWA_RW)
+ ndef_data.max_size = (uint32_t)rw_t2t_get_ndef_max_size();
else
- {
- /* Notify upper layer the result of Lock/Mem TLV detect op */
- tlv_data.protocol = NFC_PROTOCOL_T2T;
- if (p_t2t->tlv_detect == TAG_LOCK_CTRL_TLV)
- {
- tlv_data.num_bytes = p_t2t->num_lockbytes;
- }
- else
- {
- tlv_data.num_bytes = 0;
- for (xx = 0; xx < p_t2t->num_mem_tlvs; xx++)
- {
- tlv_data.num_bytes += p_t2t->mem_tlv[p_t2t->num_mem_tlvs].num_bytes;
- }
- }
- tlv_data.status = status;
- rw_t2t_handle_op_complete ();
- (*rw_cb.p_cback) (RW_T2T_TLV_DETECT_EVT, (tRW_DATA *) &tlv_data);
+ ndef_data.max_size = ndef_data.cur_size;
+
+ if (ndef_data.max_size < ndef_data.cur_size) {
+ ndef_data.flags |= RW_NDEF_FL_READ_ONLY;
+ ndef_data.max_size = ndef_data.cur_size;
}
+ if (!(ndef_data.flags & RW_NDEF_FL_READ_ONLY)) {
+ ndef_data.flags |= RW_NDEF_FL_SOFT_LOCKABLE;
+ if (status == NFC_STATUS_OK) ndef_data.flags |= RW_NDEF_FL_HARD_LOCKABLE;
+ }
+
+ rw_t2t_handle_op_complete();
+ (*rw_cb.p_cback)(RW_T2T_NDEF_DETECT_EVT, (tRW_DATA*)&ndef_data);
+ } else if (p_t2t->tlv_detect == TAG_PROPRIETARY_TLV) {
+ evt_data.msg_len = p_t2t->prop_msg_len;
+ evt_data.status = status;
+ rw_t2t_handle_op_complete();
+ (*rw_cb.p_cback)(RW_T2T_TLV_DETECT_EVT, (tRW_DATA*)&evt_data);
+ } else {
+ /* Notify upper layer the result of Lock/Mem TLV detect op */
+ tlv_data.protocol = NFC_PROTOCOL_T2T;
+ if (p_t2t->tlv_detect == TAG_LOCK_CTRL_TLV) {
+ tlv_data.num_bytes = p_t2t->num_lockbytes;
+ } else {
+ tlv_data.num_bytes = 0;
+ for (xx = 0; xx < p_t2t->num_mem_tlvs; xx++) {
+ tlv_data.num_bytes += p_t2t->mem_tlv[p_t2t->num_mem_tlvs].num_bytes;
+ }
+ }
+ tlv_data.status = status;
+ rw_t2t_handle_op_complete();
+ (*rw_cb.p_cback)(RW_T2T_TLV_DETECT_EVT, (tRW_DATA*)&tlv_data);
+ }
}
/*******************************************************************************
@@ -335,84 +302,80 @@
** Returns none
**
*******************************************************************************/
-static void rw_t2t_handle_lock_read_rsp (uint8_t *p_data)
-{
- uint8_t updated_lock_byte;
- uint8_t num_locks;
- uint8_t offset = 0;
- uint16_t lock_offset;
- uint16_t base_lock_offset = 0;
- tRW_T2T_CB *p_t2t = &rw_cb.tcb.t2t;
- uint16_t block;
+static void rw_t2t_handle_lock_read_rsp(uint8_t* p_data) {
+ uint8_t updated_lock_byte;
+ uint8_t num_locks;
+ uint8_t offset = 0;
+ uint16_t lock_offset;
+ uint16_t base_lock_offset = 0;
+ tRW_T2T_CB* p_t2t = &rw_cb.tcb.t2t;
+ uint16_t block;
- /* Prepare NDEF/TLV attributes (based on current op) for sending response to upper layer */
+ /* Prepare NDEF/TLV attributes (based on current op) for sending response to
+ * upper layer */
- num_locks = 0;
- updated_lock_byte = 0;
+ num_locks = 0;
+ updated_lock_byte = 0;
- /* Extract all lock bytes present in the read 16 bytes
- * but atleast one lock byte (base lock) should be present in the read 16 bytes */
+ /* Extract all lock bytes present in the read 16 bytes
+ * but atleast one lock byte (base lock) should be present in the read 16
+ * bytes */
- while (num_locks < p_t2t->num_lockbytes)
- {
- if (p_t2t->lockbyte[num_locks].b_lock_read == false)
- {
- lock_offset = p_t2t->lock_tlv[p_t2t->lockbyte[num_locks].tlv_index].offset + p_t2t->lockbyte[num_locks].byte_index;
- if (updated_lock_byte == 0)
- {
- /* The offset of the first lock byte present in the 16 bytes read using READ command */
- base_lock_offset = lock_offset;
- /* Block number used to read may not be the block where lock offset is present */
- offset = (uint8_t) (lock_offset - (p_t2t->block_read * T2T_BLOCK_SIZE));
- /* Update the lock byte value in the control block */
- p_t2t->lockbyte[num_locks].lock_byte = p_data[offset];
- p_t2t->lockbyte[num_locks].b_lock_read = true;
- updated_lock_byte++;
- }
- else if (lock_offset > base_lock_offset)
- {
- /* Atleast one lock byte will get updated in the control block */
- if ((lock_offset - base_lock_offset + offset) < T2T_READ_DATA_LEN)
- {
- /* And this lock byte is also present in the read data */
- p_t2t->lockbyte[num_locks].lock_byte = p_data[lock_offset - base_lock_offset + offset];
- p_t2t->lockbyte[num_locks].b_lock_read = true;
- updated_lock_byte++;
- }
- else
- {
- /* This lock byte is not present in the read data */
- block = (uint16_t) (lock_offset / T2T_BLOCK_LEN);
- block -= block % T2T_READ_BLOCKS;
- /* send READ command to read this lock byte */
- if (NFC_STATUS_OK != rw_t2t_read ((uint16_t) block))
- {
- /* Unable to send Read command, notify failure status to upper layer */
- rw_t2t_ntf_tlv_detect_complete (NFC_STATUS_FAILED);
- }
- break;
- }
- }
- else
- {
- /* This Lock byte is not present in the read 16 bytes
- * send READ command to read the lock byte */
- if (NFC_STATUS_OK != rw_t2t_read ((uint16_t) (lock_offset / T2T_BLOCK_LEN)))
- {
- /* Unable to send Read command, notify failure status to upper layer */
- rw_t2t_ntf_tlv_detect_complete (NFC_STATUS_FAILED);
- }
- break;
- }
+ while (num_locks < p_t2t->num_lockbytes) {
+ if (p_t2t->lockbyte[num_locks].b_lock_read == false) {
+ lock_offset =
+ p_t2t->lock_tlv[p_t2t->lockbyte[num_locks].tlv_index].offset +
+ p_t2t->lockbyte[num_locks].byte_index;
+ if (updated_lock_byte == 0) {
+ /* The offset of the first lock byte present in the 16 bytes read using
+ * READ command */
+ base_lock_offset = lock_offset;
+ /* Block number used to read may not be the block where lock offset is
+ * present */
+ offset = (uint8_t)(lock_offset - (p_t2t->block_read * T2T_BLOCK_SIZE));
+ /* Update the lock byte value in the control block */
+ p_t2t->lockbyte[num_locks].lock_byte = p_data[offset];
+ p_t2t->lockbyte[num_locks].b_lock_read = true;
+ updated_lock_byte++;
+ } else if (lock_offset > base_lock_offset) {
+ /* Atleast one lock byte will get updated in the control block */
+ if ((lock_offset - base_lock_offset + offset) < T2T_READ_DATA_LEN) {
+ /* And this lock byte is also present in the read data */
+ p_t2t->lockbyte[num_locks].lock_byte =
+ p_data[lock_offset - base_lock_offset + offset];
+ p_t2t->lockbyte[num_locks].b_lock_read = true;
+ updated_lock_byte++;
+ } else {
+ /* This lock byte is not present in the read data */
+ block = (uint16_t)(lock_offset / T2T_BLOCK_LEN);
+ block -= block % T2T_READ_BLOCKS;
+ /* send READ command to read this lock byte */
+ if (NFC_STATUS_OK != rw_t2t_read((uint16_t)block)) {
+ /* Unable to send Read command, notify failure status to upper layer
+ */
+ rw_t2t_ntf_tlv_detect_complete(NFC_STATUS_FAILED);
+ }
+ break;
}
- num_locks++;
+ } else {
+ /* This Lock byte is not present in the read 16 bytes
+ * send READ command to read the lock byte */
+ if (NFC_STATUS_OK !=
+ rw_t2t_read((uint16_t)(lock_offset / T2T_BLOCK_LEN))) {
+ /* Unable to send Read command, notify failure status to upper layer
+ */
+ rw_t2t_ntf_tlv_detect_complete(NFC_STATUS_FAILED);
+ }
+ break;
+ }
}
- if (num_locks == p_t2t->num_lockbytes)
- {
- /* All locks are read, notify upper layer */
- rw_t2t_update_lock_attributes ();
- rw_t2t_ntf_tlv_detect_complete (NFC_STATUS_OK);
- }
+ num_locks++;
+ }
+ if (num_locks == p_t2t->num_lockbytes) {
+ /* All locks are read, notify upper layer */
+ rw_t2t_update_lock_attributes();
+ rw_t2t_ntf_tlv_detect_complete(NFC_STATUS_OK);
+ }
}
/*******************************************************************************
@@ -424,399 +387,351 @@
** Returns none
**
*******************************************************************************/
-static void rw_t2t_handle_tlv_detect_rsp (uint8_t *p_data)
-{
- tRW_T2T_CB *p_t2t = &rw_cb.tcb.t2t;
- uint16_t offset;
- uint16_t len = 0;
- bool failed = false;
- bool found = false;
- tRW_EVENT event;
- uint8_t index;
- uint8_t count = 0;
- uint8_t xx;
- tNFC_STATUS status;
- tT2T_CMD_RSP_INFO *p_cmd_rsp_info = (tT2T_CMD_RSP_INFO *) rw_cb.tcb.t2t.p_cmd_rsp_info;
- uint8_t tlvtype = p_t2t->tlv_detect;
+static void rw_t2t_handle_tlv_detect_rsp(uint8_t* p_data) {
+ tRW_T2T_CB* p_t2t = &rw_cb.tcb.t2t;
+ uint16_t offset;
+ uint16_t len = 0;
+ bool failed = false;
+ bool found = false;
+ tRW_EVENT event;
+ uint8_t index;
+ uint8_t count = 0;
+ uint8_t xx;
+ tNFC_STATUS status;
+ tT2T_CMD_RSP_INFO* p_cmd_rsp_info =
+ (tT2T_CMD_RSP_INFO*)rw_cb.tcb.t2t.p_cmd_rsp_info;
+ uint8_t tlvtype = p_t2t->tlv_detect;
- if (p_t2t->work_offset == 0)
- {
- /* Skip UID,Static Lock block,CC*/
- p_t2t->work_offset = T2T_FIRST_DATA_BLOCK * T2T_BLOCK_LEN;
- p_t2t->b_read_data = true;
- memcpy (p_t2t->tag_data, p_data, T2T_READ_DATA_LEN);
+ if (p_t2t->work_offset == 0) {
+ /* Skip UID,Static Lock block,CC*/
+ p_t2t->work_offset = T2T_FIRST_DATA_BLOCK * T2T_BLOCK_LEN;
+ p_t2t->b_read_data = true;
+ memcpy(p_t2t->tag_data, p_data, T2T_READ_DATA_LEN);
+ }
+
+ p_t2t->segment = 0;
+
+ for (offset = 0; offset < T2T_READ_DATA_LEN && !failed && !found;) {
+ if (rw_t2t_is_lock_res_byte((uint16_t)(p_t2t->work_offset + offset)) ==
+ true) {
+ /* Skip locks, reserved bytes while searching for TLV */
+ offset++;
+ continue;
}
+ switch (p_t2t->substate) {
+ case RW_T2T_SUBSTATE_WAIT_TLV_DETECT:
+ /* Search for the tlv */
+ p_t2t->found_tlv = p_data[offset++];
+ switch (p_t2t->found_tlv) {
+ case TAG_NULL_TLV: /* May be used for padding. SHALL ignore this */
+ break;
- p_t2t->segment = 0;
-
- for (offset = 0; offset < T2T_READ_DATA_LEN && !failed && !found;)
- {
- if (rw_t2t_is_lock_res_byte((uint16_t)(p_t2t->work_offset + offset)) == true)
- {
- /* Skip locks, reserved bytes while searching for TLV */
- offset++;
- continue;
- }
- switch (p_t2t->substate)
- {
- case RW_T2T_SUBSTATE_WAIT_TLV_DETECT:
- /* Search for the tlv */
- p_t2t->found_tlv = p_data[offset++];
- switch (p_t2t->found_tlv)
- {
- case TAG_NULL_TLV: /* May be used for padding. SHALL ignore this */
- break;
-
- case TAG_NDEF_TLV:
- if (tlvtype == TAG_NDEF_TLV)
- {
- /* NDEF Detected, now collect NDEF Attributes including NDEF Length */
- index = (offset % T2T_BLOCK_SIZE);
- /* Backup ndef first block */
- memcpy (p_t2t->ndef_first_block,&p_data[offset-index],index);
- p_t2t->substate = RW_T2T_SUBSTATE_WAIT_FIND_LEN_FIELD_LEN;
- }
- else if (tlvtype == TAG_PROPRIETARY_TLV)
- {
- /* Proprietary TLV can exist after NDEF Tlv so we continue searching */
- p_t2t->substate = RW_T2T_SUBSTATE_WAIT_FIND_LEN_FIELD_LEN;
- }
- else if ( ((tlvtype == TAG_LOCK_CTRL_TLV) && (p_t2t->num_lockbytes > 0))
- ||((tlvtype == TAG_MEM_CTRL_TLV) && (p_t2t->num_mem_tlvs > 0)) )
- {
- /* Lock / Memory control tlv cannot exist after NDEF TLV
- * So when NDEF is found, we stop searching for Lock and Memory control tlv */
- found = true;
- }
- else
- {
- /* While searching for Lock / Memory control tlv, if NDEF TLV is found
- * first then our search for Lock /Memory control tlv failed and we stop here */
- failed = true;
- }
- break;
-
- case TAG_LOCK_CTRL_TLV:
- case TAG_MEM_CTRL_TLV:
- p_t2t->substate = RW_T2T_SUBSTATE_WAIT_READ_TLV_LEN0;
- break;
-
- case TAG_PROPRIETARY_TLV:
- if (tlvtype == TAG_PROPRIETARY_TLV)
- {
- index = (offset % T2T_BLOCK_SIZE);
- p_t2t->substate = RW_T2T_SUBSTATE_WAIT_FIND_LEN_FIELD_LEN;
- }
- else
- {
- /* NDEF/LOCK/MEM TLV can exist after Proprietary Tlv so we continue searching, skiping proprietary tlv */
- p_t2t->substate = RW_T2T_SUBSTATE_WAIT_FIND_LEN_FIELD_LEN;
- }
- break;
-
- case TAG_TERMINATOR_TLV: /* Last TLV block in the data area. Must be no NDEF nessage */
- if ( ((tlvtype == TAG_LOCK_CTRL_TLV) && (p_t2t->num_lockbytes > 0))
- ||((tlvtype == TAG_MEM_CTRL_TLV) && (p_t2t->num_mem_tlvs > 0)) )
- {
- /* No more Lock/Memory TLV control tlv in the tag, so stop searching */
- found = true;
- }
- else
- {
- /* NDEF/Lock/Memory/Proprietary TLV cannot exist after Terminator Tlv */
- failed = true;
- }
- break;
- default:
- failed = true;
+ case TAG_NDEF_TLV:
+ if (tlvtype == TAG_NDEF_TLV) {
+ /* NDEF Detected, now collect NDEF Attributes including NDEF
+ * Length */
+ index = (offset % T2T_BLOCK_SIZE);
+ /* Backup ndef first block */
+ memcpy(p_t2t->ndef_first_block, &p_data[offset - index], index);
+ p_t2t->substate = RW_T2T_SUBSTATE_WAIT_FIND_LEN_FIELD_LEN;
+ } else if (tlvtype == TAG_PROPRIETARY_TLV) {
+ /* Proprietary TLV can exist after NDEF Tlv so we continue
+ * searching */
+ p_t2t->substate = RW_T2T_SUBSTATE_WAIT_FIND_LEN_FIELD_LEN;
+ } else if (((tlvtype == TAG_LOCK_CTRL_TLV) &&
+ (p_t2t->num_lockbytes > 0)) ||
+ ((tlvtype == TAG_MEM_CTRL_TLV) &&
+ (p_t2t->num_mem_tlvs > 0))) {
+ /* Lock / Memory control tlv cannot exist after NDEF TLV
+ * So when NDEF is found, we stop searching for Lock and Memory
+ * control tlv */
+ found = true;
+ } else {
+ /* While searching for Lock / Memory control tlv, if NDEF TLV is
+ * found
+ * first then our search for Lock /Memory control tlv failed and
+ * we stop here */
+ failed = true;
}
break;
- case RW_T2T_SUBSTATE_WAIT_FIND_LEN_FIELD_LEN:
+ case TAG_LOCK_CTRL_TLV:
+ case TAG_MEM_CTRL_TLV:
+ p_t2t->substate = RW_T2T_SUBSTATE_WAIT_READ_TLV_LEN0;
+ break;
+
+ case TAG_PROPRIETARY_TLV:
+ if (tlvtype == TAG_PROPRIETARY_TLV) {
+ index = (offset % T2T_BLOCK_SIZE);
+ p_t2t->substate = RW_T2T_SUBSTATE_WAIT_FIND_LEN_FIELD_LEN;
+ } else {
+ /* NDEF/LOCK/MEM TLV can exist after Proprietary Tlv so we
+ * continue searching, skiping proprietary tlv */
+ p_t2t->substate = RW_T2T_SUBSTATE_WAIT_FIND_LEN_FIELD_LEN;
+ }
+ break;
+
+ case TAG_TERMINATOR_TLV: /* Last TLV block in the data area. Must be
+ no NDEF nessage */
+ if (((tlvtype == TAG_LOCK_CTRL_TLV) &&
+ (p_t2t->num_lockbytes > 0)) ||
+ ((tlvtype == TAG_MEM_CTRL_TLV) && (p_t2t->num_mem_tlvs > 0))) {
+ /* No more Lock/Memory TLV control tlv in the tag, so stop
+ * searching */
+ found = true;
+ } else {
+ /* NDEF/Lock/Memory/Proprietary TLV cannot exist after Terminator
+ * Tlv */
+ failed = true;
+ }
+ break;
+ default:
+ failed = true;
+ }
+ break;
+
+ case RW_T2T_SUBSTATE_WAIT_FIND_LEN_FIELD_LEN:
+ len = p_data[offset];
+ switch (p_t2t->found_tlv) {
+ case TAG_NDEF_TLV:
+ p_t2t->ndef_header_offset = offset + p_t2t->work_offset;
+ if (len == TAG_LONG_NDEF_LEN_FIELD_BYTE0) {
+ /* The next two bytes constitute length bytes */
+ p_t2t->substate = RW_T2T_SUBSTATE_WAIT_READ_TLV_LEN0;
+ } else {
+ /* one byte length field */
+ p_t2t->ndef_msg_len = len;
+ p_t2t->bytes_count = p_t2t->ndef_msg_len;
+ p_t2t->substate = RW_T2T_SUBSTATE_WAIT_READ_TLV_VALUE;
+ }
+ break;
+
+ case TAG_PROPRIETARY_TLV:
+ if (len == T2T_LONG_NDEF_LEN_FIELD_BYTE0) {
+ /* The next two bytes constitute length bytes */
+ p_t2t->substate = RW_T2T_SUBSTATE_WAIT_READ_TLV_LEN0;
+ } else {
+ /* one byte length field */
+ p_t2t->prop_msg_len = len;
+ p_t2t->bytes_count = p_t2t->prop_msg_len;
+ p_t2t->substate = RW_T2T_SUBSTATE_WAIT_READ_TLV_VALUE;
+ }
+ break;
+ }
+ offset++;
+ break;
+
+ case RW_T2T_SUBSTATE_WAIT_READ_TLV_LEN0:
+ switch (p_t2t->found_tlv) {
+ case TAG_LOCK_CTRL_TLV:
+ case TAG_MEM_CTRL_TLV:
+
len = p_data[offset];
- switch (p_t2t->found_tlv)
- {
- case TAG_NDEF_TLV:
- p_t2t->ndef_header_offset = offset + p_t2t->work_offset;
- if (len == TAG_LONG_NDEF_LEN_FIELD_BYTE0)
- {
- /* The next two bytes constitute length bytes */
- p_t2t->substate = RW_T2T_SUBSTATE_WAIT_READ_TLV_LEN0;
- }
- else
- {
- /* one byte length field */
- p_t2t->ndef_msg_len = len;
- p_t2t->bytes_count = p_t2t->ndef_msg_len;
- p_t2t->substate = RW_T2T_SUBSTATE_WAIT_READ_TLV_VALUE;
- }
- break;
-
- case TAG_PROPRIETARY_TLV:
- if (len == T2T_LONG_NDEF_LEN_FIELD_BYTE0)
- {
- /* The next two bytes constitute length bytes */
- p_t2t->substate = RW_T2T_SUBSTATE_WAIT_READ_TLV_LEN0;
- }
- else
- {
- /* one byte length field */
- p_t2t->prop_msg_len = len;
- p_t2t->bytes_count = p_t2t->prop_msg_len;
- p_t2t->substate = RW_T2T_SUBSTATE_WAIT_READ_TLV_VALUE;
- }
- break;
+ if (len == TAG_DEFAULT_TLV_LEN) {
+ /* Valid Lock control TLV */
+ p_t2t->substate = RW_T2T_SUBSTATE_WAIT_READ_TLV_VALUE;
+ p_t2t->bytes_count = TAG_DEFAULT_TLV_LEN;
+ } else if (((tlvtype == TAG_LOCK_CTRL_TLV) &&
+ (p_t2t->num_lockbytes > 0)) ||
+ ((tlvtype == TAG_MEM_CTRL_TLV) &&
+ (p_t2t->num_mem_tlvs > 0))) {
+ /* Stop searching for Lock/ Memory control tlv */
+ found = true;
+ } else {
+ failed = true;
}
- offset++;
break;
- case RW_T2T_SUBSTATE_WAIT_READ_TLV_LEN0:
- switch (p_t2t->found_tlv)
- {
- case TAG_LOCK_CTRL_TLV:
- case TAG_MEM_CTRL_TLV:
-
- len = p_data[offset];
- if (len == TAG_DEFAULT_TLV_LEN)
- {
- /* Valid Lock control TLV */
- p_t2t->substate = RW_T2T_SUBSTATE_WAIT_READ_TLV_VALUE;
- p_t2t->bytes_count = TAG_DEFAULT_TLV_LEN;
- }
- else if ( ((tlvtype == TAG_LOCK_CTRL_TLV) && (p_t2t->num_lockbytes > 0))
- ||((tlvtype == TAG_MEM_CTRL_TLV) && (p_t2t->num_mem_tlvs > 0)) )
- {
- /* Stop searching for Lock/ Memory control tlv */
- found = true;
- }
- else
- {
- failed = true;
- }
- break;
-
- case TAG_NDEF_TLV:
- case TAG_PROPRIETARY_TLV:
- /* The first length byte */
- p_t2t->bytes_count = (uint8_t) p_data[offset];
- p_t2t->substate = RW_T2T_SUBSTATE_WAIT_READ_TLV_LEN1;
- break;
- }
- offset++;
- break;
-
- case RW_T2T_SUBSTATE_WAIT_READ_TLV_LEN1:
- /* Prepare NDEF Message length */
- p_t2t->bytes_count = (p_t2t->bytes_count << 8) + p_data[offset];
- if (p_t2t->found_tlv == TAG_NDEF_TLV)
- {
- p_t2t->ndef_msg_len = p_t2t->bytes_count;
- }
- else if (p_t2t->found_tlv == TAG_PROPRIETARY_TLV)
- {
- p_t2t->prop_msg_len = p_t2t->bytes_count;
- }
- p_t2t->substate = RW_T2T_SUBSTATE_WAIT_READ_TLV_VALUE;
- offset++;
- break;
-
- case RW_T2T_SUBSTATE_WAIT_READ_TLV_VALUE:
- switch (p_t2t->found_tlv)
- {
- case TAG_NDEF_TLV:
- if ( (p_t2t->bytes_count == p_t2t->ndef_msg_len)
- &&(tlvtype == TAG_NDEF_TLV) )
- {
- /* The first byte offset after length field */
- p_t2t->ndef_msg_offset = offset + p_t2t->work_offset;
- }
- /* Reduce number of NDEF bytes remaining to pass over NDEF TLV */
- if (p_t2t->bytes_count > 0)
- p_t2t->bytes_count--;
-
- if (tlvtype == TAG_NDEF_TLV)
- {
- found = true;
- p_t2t->ndef_status = T2T_NDEF_DETECTED;
- }
- else if (p_t2t->bytes_count == 0)
- {
- /* Next byte could be a different TLV */
- p_t2t->substate = RW_T2T_SUBSTATE_WAIT_TLV_DETECT;
- }
- break;
-
- case TAG_LOCK_CTRL_TLV:
- p_t2t->bytes_count--;
- if ( (tlvtype == TAG_LOCK_CTRL_TLV)
- ||(tlvtype == TAG_NDEF_TLV) )
- {
- /* Collect Lock TLV */
- p_t2t->tlv_value[2 - p_t2t->bytes_count] = p_data[offset];
- if (p_t2t->bytes_count == 0)
- {
- /* Lock TLV is collected and buffered in tlv_value, now decode it */
- p_t2t->lock_tlv[p_t2t->num_lock_tlvs].offset = (p_t2t->tlv_value[0] >> 4) & 0x0F;
- p_t2t->lock_tlv[p_t2t->num_lock_tlvs].offset *= (uint8_t) tags_pow (2, p_t2t->tlv_value[2] & 0x0F);
- p_t2t->lock_tlv[p_t2t->num_lock_tlvs].offset += p_t2t->tlv_value[0] & 0x0F;
- p_t2t->lock_tlv[p_t2t->num_lock_tlvs].bytes_locked_per_bit = (uint8_t) tags_pow (2, ((p_t2t->tlv_value[2] & 0xF0) >> 4));
- p_t2t->lock_tlv[p_t2t->num_lock_tlvs].num_bits = p_t2t->tlv_value[1];
- count = p_t2t->tlv_value[1] / 8 + ((p_t2t->tlv_value[1]%8 != 0)? 1:0);
-
- /* Extract lockbytes info addressed by this Lock TLV */
- xx = 0;
- while (xx < count)
- {
- p_t2t->lockbyte[p_t2t->num_lockbytes].tlv_index = p_t2t->num_lock_tlvs;
- p_t2t->lockbyte[p_t2t->num_lockbytes].byte_index = xx;
- p_t2t->lockbyte[p_t2t->num_lockbytes].b_lock_read = false;
- xx++;
- p_t2t->num_lockbytes++;
- }
- p_t2t->num_lock_tlvs++;
- rw_t2t_update_attributes ();
- /* Next byte could be a different TLV */
- p_t2t->substate = RW_T2T_SUBSTATE_WAIT_TLV_DETECT;
- }
- }
- else
- {
- /* If not looking for lock/ndef tlv, just skip this Lock TLV */
- if (p_t2t->bytes_count == 0)
- {
- p_t2t->substate = RW_T2T_SUBSTATE_WAIT_TLV_DETECT;
- }
- }
- break;
-
- case TAG_MEM_CTRL_TLV:
- p_t2t->bytes_count--;
- if ( (tlvtype == TAG_MEM_CTRL_TLV)
- ||(tlvtype == TAG_NDEF_TLV) )
- {
- p_t2t->tlv_value[2 - p_t2t->bytes_count] = p_data[offset];
- if (p_t2t->bytes_count == 0)
- {
- if (p_t2t->num_mem_tlvs >= RW_T2T_MAX_MEM_TLVS)
- {
- RW_TRACE_ERROR0 ("rw_t2t_handle_tlv_detect_rsp - Maximum buffer allocated for Memory tlv has reached");
- failed = true;
- }
- else
- {
- /* Extract memory control tlv */
- p_t2t->mem_tlv[p_t2t->num_mem_tlvs].offset = (p_t2t->tlv_value[0] >> 4) & 0x0F;
- p_t2t->mem_tlv[p_t2t->num_mem_tlvs].offset *= (uint8_t) tags_pow (2, p_t2t->tlv_value[2] & 0x0F);
- p_t2t->mem_tlv[p_t2t->num_mem_tlvs].offset += p_t2t->tlv_value[0] & 0x0F;
- p_t2t->mem_tlv[p_t2t->num_mem_tlvs].num_bytes = p_t2t->tlv_value[1];
- p_t2t->num_mem_tlvs++;
- rw_t2t_update_attributes ();
- p_t2t->substate = RW_T2T_SUBSTATE_WAIT_TLV_DETECT;
- }
- }
- }
- else
- {
- if (p_t2t->bytes_count == 0)
- {
- p_t2t->substate = RW_T2T_SUBSTATE_WAIT_TLV_DETECT;
- }
- }
- break;
-
- case TAG_PROPRIETARY_TLV:
- p_t2t->bytes_count--;
- if (tlvtype == TAG_PROPRIETARY_TLV)
- {
- found = true;
- p_t2t->prop_msg_len = len;
- }
- else
- {
- if (p_t2t->bytes_count == 0)
- {
- p_t2t->substate = RW_T2T_SUBSTATE_WAIT_TLV_DETECT;
- }
- }
- break;
- }
- offset++;
+ case TAG_NDEF_TLV:
+ case TAG_PROPRIETARY_TLV:
+ /* The first length byte */
+ p_t2t->bytes_count = (uint8_t)p_data[offset];
+ p_t2t->substate = RW_T2T_SUBSTATE_WAIT_READ_TLV_LEN1;
break;
}
+ offset++;
+ break;
+
+ case RW_T2T_SUBSTATE_WAIT_READ_TLV_LEN1:
+ /* Prepare NDEF Message length */
+ p_t2t->bytes_count = (p_t2t->bytes_count << 8) + p_data[offset];
+ if (p_t2t->found_tlv == TAG_NDEF_TLV) {
+ p_t2t->ndef_msg_len = p_t2t->bytes_count;
+ } else if (p_t2t->found_tlv == TAG_PROPRIETARY_TLV) {
+ p_t2t->prop_msg_len = p_t2t->bytes_count;
+ }
+ p_t2t->substate = RW_T2T_SUBSTATE_WAIT_READ_TLV_VALUE;
+ offset++;
+ break;
+
+ case RW_T2T_SUBSTATE_WAIT_READ_TLV_VALUE:
+ switch (p_t2t->found_tlv) {
+ case TAG_NDEF_TLV:
+ if ((p_t2t->bytes_count == p_t2t->ndef_msg_len) &&
+ (tlvtype == TAG_NDEF_TLV)) {
+ /* The first byte offset after length field */
+ p_t2t->ndef_msg_offset = offset + p_t2t->work_offset;
+ }
+ /* Reduce number of NDEF bytes remaining to pass over NDEF TLV */
+ if (p_t2t->bytes_count > 0) p_t2t->bytes_count--;
+
+ if (tlvtype == TAG_NDEF_TLV) {
+ found = true;
+ p_t2t->ndef_status = T2T_NDEF_DETECTED;
+ } else if (p_t2t->bytes_count == 0) {
+ /* Next byte could be a different TLV */
+ p_t2t->substate = RW_T2T_SUBSTATE_WAIT_TLV_DETECT;
+ }
+ break;
+
+ case TAG_LOCK_CTRL_TLV:
+ p_t2t->bytes_count--;
+ if ((tlvtype == TAG_LOCK_CTRL_TLV) || (tlvtype == TAG_NDEF_TLV)) {
+ /* Collect Lock TLV */
+ p_t2t->tlv_value[2 - p_t2t->bytes_count] = p_data[offset];
+ if (p_t2t->bytes_count == 0) {
+ /* Lock TLV is collected and buffered in tlv_value, now decode
+ * it */
+ p_t2t->lock_tlv[p_t2t->num_lock_tlvs].offset =
+ (p_t2t->tlv_value[0] >> 4) & 0x0F;
+ p_t2t->lock_tlv[p_t2t->num_lock_tlvs].offset *=
+ (uint8_t)tags_pow(2, p_t2t->tlv_value[2] & 0x0F);
+ p_t2t->lock_tlv[p_t2t->num_lock_tlvs].offset +=
+ p_t2t->tlv_value[0] & 0x0F;
+ p_t2t->lock_tlv[p_t2t->num_lock_tlvs].bytes_locked_per_bit =
+ (uint8_t)tags_pow(2, ((p_t2t->tlv_value[2] & 0xF0) >> 4));
+ p_t2t->lock_tlv[p_t2t->num_lock_tlvs].num_bits =
+ p_t2t->tlv_value[1];
+ count = p_t2t->tlv_value[1] / 8 +
+ ((p_t2t->tlv_value[1] % 8 != 0) ? 1 : 0);
+
+ /* Extract lockbytes info addressed by this Lock TLV */
+ xx = 0;
+ while (xx < count) {
+ p_t2t->lockbyte[p_t2t->num_lockbytes].tlv_index =
+ p_t2t->num_lock_tlvs;
+ p_t2t->lockbyte[p_t2t->num_lockbytes].byte_index = xx;
+ p_t2t->lockbyte[p_t2t->num_lockbytes].b_lock_read = false;
+ xx++;
+ p_t2t->num_lockbytes++;
+ }
+ p_t2t->num_lock_tlvs++;
+ rw_t2t_update_attributes();
+ /* Next byte could be a different TLV */
+ p_t2t->substate = RW_T2T_SUBSTATE_WAIT_TLV_DETECT;
+ }
+ } else {
+ /* If not looking for lock/ndef tlv, just skip this Lock TLV */
+ if (p_t2t->bytes_count == 0) {
+ p_t2t->substate = RW_T2T_SUBSTATE_WAIT_TLV_DETECT;
+ }
+ }
+ break;
+
+ case TAG_MEM_CTRL_TLV:
+ p_t2t->bytes_count--;
+ if ((tlvtype == TAG_MEM_CTRL_TLV) || (tlvtype == TAG_NDEF_TLV)) {
+ p_t2t->tlv_value[2 - p_t2t->bytes_count] = p_data[offset];
+ if (p_t2t->bytes_count == 0) {
+ if (p_t2t->num_mem_tlvs >= RW_T2T_MAX_MEM_TLVS) {
+ RW_TRACE_ERROR0(
+ "rw_t2t_handle_tlv_detect_rsp - Maximum buffer allocated "
+ "for Memory tlv has reached");
+ failed = true;
+ } else {
+ /* Extract memory control tlv */
+ p_t2t->mem_tlv[p_t2t->num_mem_tlvs].offset =
+ (p_t2t->tlv_value[0] >> 4) & 0x0F;
+ p_t2t->mem_tlv[p_t2t->num_mem_tlvs].offset *=
+ (uint8_t)tags_pow(2, p_t2t->tlv_value[2] & 0x0F);
+ p_t2t->mem_tlv[p_t2t->num_mem_tlvs].offset +=
+ p_t2t->tlv_value[0] & 0x0F;
+ p_t2t->mem_tlv[p_t2t->num_mem_tlvs].num_bytes =
+ p_t2t->tlv_value[1];
+ p_t2t->num_mem_tlvs++;
+ rw_t2t_update_attributes();
+ p_t2t->substate = RW_T2T_SUBSTATE_WAIT_TLV_DETECT;
+ }
+ }
+ } else {
+ if (p_t2t->bytes_count == 0) {
+ p_t2t->substate = RW_T2T_SUBSTATE_WAIT_TLV_DETECT;
+ }
+ }
+ break;
+
+ case TAG_PROPRIETARY_TLV:
+ p_t2t->bytes_count--;
+ if (tlvtype == TAG_PROPRIETARY_TLV) {
+ found = true;
+ p_t2t->prop_msg_len = len;
+ } else {
+ if (p_t2t->bytes_count == 0) {
+ p_t2t->substate = RW_T2T_SUBSTATE_WAIT_TLV_DETECT;
+ }
+ }
+ break;
+ }
+ offset++;
+ break;
}
+ }
+ p_t2t->work_offset += T2T_READ_DATA_LEN;
- p_t2t->work_offset += T2T_READ_DATA_LEN;
+ event = rw_t2t_info_to_event(p_cmd_rsp_info);
- event = rw_t2t_info_to_event (p_cmd_rsp_info);
-
- /* If not found and not failed, read next block and search tlv */
- if (!found && !failed)
- {
-
- if (p_t2t->work_offset >= (p_t2t->tag_hdr[T2T_CC2_TMS_BYTE] * T2T_TMS_TAG_FACTOR))
- {
- if ( ((tlvtype == TAG_LOCK_CTRL_TLV) && (p_t2t->num_lockbytes > 0))
- ||((tlvtype == TAG_MEM_CTRL_TLV) && (p_t2t->num_mem_tlvs > 0)) )
- {
- found = true;
- }
- else
- {
- failed = true;
- }
- }
- else
- {
- if (rw_t2t_read ((uint16_t) ((p_t2t->work_offset / T2T_BLOCK_LEN) + T2T_FIRST_DATA_BLOCK)) != NFC_STATUS_OK)
- failed = true;
- }
+ /* If not found and not failed, read next block and search tlv */
+ if (!found && !failed) {
+ if (p_t2t->work_offset >=
+ (p_t2t->tag_hdr[T2T_CC2_TMS_BYTE] * T2T_TMS_TAG_FACTOR)) {
+ if (((tlvtype == TAG_LOCK_CTRL_TLV) && (p_t2t->num_lockbytes > 0)) ||
+ ((tlvtype == TAG_MEM_CTRL_TLV) && (p_t2t->num_mem_tlvs > 0))) {
+ found = true;
+ } else {
+ failed = true;
+ }
+ } else {
+ if (rw_t2t_read((uint16_t)((p_t2t->work_offset / T2T_BLOCK_LEN) +
+ T2T_FIRST_DATA_BLOCK)) != NFC_STATUS_OK)
+ failed = true;
}
+ }
- if (failed || found)
- {
- if (tlvtype == TAG_LOCK_CTRL_TLV)
- {
- /* Incase no Lock control tlv is present then look for default dynamic lock bytes */
- rw_t2t_extract_default_locks_info ();
+ if (failed || found) {
+ if (tlvtype == TAG_LOCK_CTRL_TLV) {
+ /* Incase no Lock control tlv is present then look for default dynamic
+ * lock bytes */
+ rw_t2t_extract_default_locks_info();
- /* Send command to read the dynamic lock bytes */
- status = rw_t2t_read_locks ();
+ /* Send command to read the dynamic lock bytes */
+ status = rw_t2t_read_locks();
- if (status != NFC_STATUS_CONTINUE)
- {
- /* If unable to read a lock/all locks read, notify upper layer */
- rw_t2t_update_lock_attributes ();
- rw_t2t_ntf_tlv_detect_complete (status);
- }
+ if (status != NFC_STATUS_CONTINUE) {
+ /* If unable to read a lock/all locks read, notify upper layer */
+ rw_t2t_update_lock_attributes();
+ rw_t2t_ntf_tlv_detect_complete(status);
+ }
+ } else if (tlvtype == TAG_NDEF_TLV) {
+ rw_t2t_extract_default_locks_info();
+
+ if (failed) {
+ rw_t2t_ntf_tlv_detect_complete(NFC_STATUS_FAILED);
+ } else {
+ /* NDEF present,Send command to read the dynamic lock bytes */
+ status = rw_t2t_read_locks();
+ if (status != NFC_STATUS_CONTINUE) {
+ /* If unable to read a lock/all locks read, notify upper layer */
+ rw_t2t_update_lock_attributes();
+ rw_t2t_ntf_tlv_detect_complete(status);
}
- else if (tlvtype == TAG_NDEF_TLV)
- {
- rw_t2t_extract_default_locks_info ();
-
- if (failed)
- {
- rw_t2t_ntf_tlv_detect_complete (NFC_STATUS_FAILED);
- }
- else
- {
- /* NDEF present,Send command to read the dynamic lock bytes */
- status = rw_t2t_read_locks ();
- if (status != NFC_STATUS_CONTINUE)
- {
- /* If unable to read a lock/all locks read, notify upper layer */
- rw_t2t_update_lock_attributes ();
- rw_t2t_ntf_tlv_detect_complete (status);
- }
- }
- }
- else
- {
- /* Notify Memory/ Proprietary tlv detect result */
- status = failed ? NFC_STATUS_FAILED : NFC_STATUS_OK;
- rw_t2t_ntf_tlv_detect_complete (status);
- }
+ }
+ } else {
+ /* Notify Memory/ Proprietary tlv detect result */
+ status = failed ? NFC_STATUS_FAILED : NFC_STATUS_OK;
+ rw_t2t_ntf_tlv_detect_complete(status);
}
+ }
}
/*******************************************************************************
@@ -830,59 +745,52 @@
** NFC_STATUS_CONTINUE, if reading locks is in progress
**
*******************************************************************************/
-tNFC_STATUS rw_t2t_read_locks (void)
-{
- uint8_t num_locks = 0;
- tRW_T2T_CB *p_t2t = &rw_cb.tcb.t2t;
- tNFC_STATUS status = NFC_STATUS_CONTINUE;
- uint16_t offset;
- uint16_t block;
+tNFC_STATUS rw_t2t_read_locks(void) {
+ uint8_t num_locks = 0;
+ tRW_T2T_CB* p_t2t = &rw_cb.tcb.t2t;
+ tNFC_STATUS status = NFC_STATUS_CONTINUE;
+ uint16_t offset;
+ uint16_t block;
- if ( (p_t2t->tag_hdr[T2T_CC3_RWA_BYTE] != T2T_CC3_RWA_RW)
- ||(p_t2t->skip_dyn_locks) )
- {
- /* Skip reading dynamic lock bytes if CC is set as Read only or layer above instructs to skip */
- while (num_locks < p_t2t->num_lockbytes)
- {
- p_t2t->lockbyte[num_locks].lock_byte = 0x00;
- p_t2t->lockbyte[num_locks].b_lock_read = true;
- num_locks++;
- }
+ if ((p_t2t->tag_hdr[T2T_CC3_RWA_BYTE] != T2T_CC3_RWA_RW) ||
+ (p_t2t->skip_dyn_locks)) {
+ /* Skip reading dynamic lock bytes if CC is set as Read only or layer above
+ * instructs to skip */
+ while (num_locks < p_t2t->num_lockbytes) {
+ p_t2t->lockbyte[num_locks].lock_byte = 0x00;
+ p_t2t->lockbyte[num_locks].b_lock_read = true;
+ num_locks++;
}
+ }
- while (num_locks < p_t2t->num_lockbytes)
- {
- if (p_t2t->lockbyte[num_locks].b_lock_read == false)
- {
- /* Send Read command to read the first un read locks */
- offset = p_t2t->lock_tlv[p_t2t->lockbyte[num_locks].tlv_index].offset + p_t2t->lockbyte[num_locks].byte_index;
+ while (num_locks < p_t2t->num_lockbytes) {
+ if (p_t2t->lockbyte[num_locks].b_lock_read == false) {
+ /* Send Read command to read the first un read locks */
+ offset = p_t2t->lock_tlv[p_t2t->lockbyte[num_locks].tlv_index].offset +
+ p_t2t->lockbyte[num_locks].byte_index;
- /* Read 16 bytes where this lock byte is present */
- block = (uint16_t) (offset / T2T_BLOCK_LEN);
- block -= block % T2T_READ_BLOCKS;
+ /* Read 16 bytes where this lock byte is present */
+ block = (uint16_t)(offset / T2T_BLOCK_LEN);
+ block -= block % T2T_READ_BLOCKS;
- p_t2t->substate = RW_T2T_SUBSTATE_WAIT_READ_LOCKS;
- /* send READ8 command */
- if ((status = rw_t2t_read ((uint16_t) block)) == NFC_STATUS_OK)
- {
- /* Reading Locks */
- status = NFC_STATUS_CONTINUE;
- }
- else
- {
- status = NFC_STATUS_FAILED;
- }
- break;
- }
- num_locks++;
+ p_t2t->substate = RW_T2T_SUBSTATE_WAIT_READ_LOCKS;
+ /* send READ8 command */
+ if ((status = rw_t2t_read((uint16_t)block)) == NFC_STATUS_OK) {
+ /* Reading Locks */
+ status = NFC_STATUS_CONTINUE;
+ } else {
+ status = NFC_STATUS_FAILED;
+ }
+ break;
}
- if (num_locks == p_t2t->num_lockbytes)
- {
- /* All locks are read */
- status = NFC_STATUS_OK;
- }
+ num_locks++;
+ }
+ if (num_locks == p_t2t->num_lockbytes) {
+ /* All locks are read */
+ status = NFC_STATUS_OK;
+ }
- return status;
+ return status;
}
/*******************************************************************************
@@ -897,42 +805,46 @@
** Returns None
**
*******************************************************************************/
-void rw_t2t_extract_default_locks_info (void)
-{
- uint8_t num_dynamic_lock_bits;
- uint8_t num_dynamic_lock_bytes;
- uint8_t xx;
- tRW_T2T_CB *p_t2t = &rw_cb.tcb.t2t;
- const tT2T_INIT_TAG *p_ret;
- uint8_t bytes_locked_per_lock_bit = T2T_DEFAULT_LOCK_BLPB;
+void rw_t2t_extract_default_locks_info(void) {
+ uint8_t num_dynamic_lock_bits;
+ uint8_t num_dynamic_lock_bytes;
+ uint8_t xx;
+ tRW_T2T_CB* p_t2t = &rw_cb.tcb.t2t;
+ const tT2T_INIT_TAG* p_ret;
+ uint8_t bytes_locked_per_lock_bit = T2T_DEFAULT_LOCK_BLPB;
+ if ((p_t2t->num_lock_tlvs == 0) &&
+ (p_t2t->tag_hdr[T2T_CC2_TMS_BYTE] > T2T_CC2_TMS_STATIC)) {
+ /* No Lock control tlv is detected. Indicates lock bytes are present in
+ * default location */
+ /* Add a virtual Lock tlv to map this default lock location */
+ if ((p_ret = t2t_tag_init_data(p_t2t->tag_hdr[0], false, 0)) != NULL)
+ bytes_locked_per_lock_bit = p_ret->default_lock_blpb;
- if ( (p_t2t->num_lock_tlvs == 0)
- &&(p_t2t->tag_hdr[T2T_CC2_TMS_BYTE] > T2T_CC2_TMS_STATIC) )
- {
- /* No Lock control tlv is detected. Indicates lock bytes are present in default location */
- /* Add a virtual Lock tlv to map this default lock location */
- if ((p_ret = t2t_tag_init_data (p_t2t->tag_hdr[0], false, 0)) != NULL)
- bytes_locked_per_lock_bit = p_ret->default_lock_blpb;
+ num_dynamic_lock_bits =
+ ((p_t2t->tag_hdr[T2T_CC2_TMS_BYTE] * T2T_TMS_TAG_FACTOR) -
+ (T2T_STATIC_SIZE - T2T_HEADER_SIZE)) /
+ bytes_locked_per_lock_bit;
+ num_dynamic_lock_bytes = num_dynamic_lock_bits / 8;
+ num_dynamic_lock_bytes += (num_dynamic_lock_bits % 8 == 0) ? 0 : 1;
- num_dynamic_lock_bits = ((p_t2t->tag_hdr[T2T_CC2_TMS_BYTE] * T2T_TMS_TAG_FACTOR) - (T2T_STATIC_SIZE - T2T_HEADER_SIZE)) / bytes_locked_per_lock_bit;
- num_dynamic_lock_bytes = num_dynamic_lock_bits / 8;
- num_dynamic_lock_bytes += (num_dynamic_lock_bits % 8 == 0) ? 0:1;
+ p_t2t->lock_tlv[p_t2t->num_lock_tlvs].offset =
+ (p_t2t->tag_hdr[T2T_CC2_TMS_BYTE] * T2T_TMS_TAG_FACTOR) +
+ (T2T_FIRST_DATA_BLOCK * T2T_BLOCK_LEN);
+ p_t2t->lock_tlv[p_t2t->num_lock_tlvs].bytes_locked_per_bit =
+ bytes_locked_per_lock_bit;
+ p_t2t->lock_tlv[p_t2t->num_lock_tlvs].num_bits = num_dynamic_lock_bits;
- p_t2t->lock_tlv[p_t2t->num_lock_tlvs].offset = (p_t2t->tag_hdr[T2T_CC2_TMS_BYTE] * T2T_TMS_TAG_FACTOR) + (T2T_FIRST_DATA_BLOCK * T2T_BLOCK_LEN);
- p_t2t->lock_tlv[p_t2t->num_lock_tlvs].bytes_locked_per_bit = bytes_locked_per_lock_bit;
- p_t2t->lock_tlv[p_t2t->num_lock_tlvs].num_bits = num_dynamic_lock_bits;
-
- /* Based on tag data size the number of locks present in the default location changes */
- for (xx = 0; xx < num_dynamic_lock_bytes; xx++)
- {
- p_t2t->lockbyte[xx].tlv_index = p_t2t->num_lock_tlvs;
- p_t2t->lockbyte[xx].byte_index = xx;
- p_t2t->lockbyte[xx].b_lock_read = false;
- }
- p_t2t->num_lockbytes = num_dynamic_lock_bytes;
- p_t2t->num_lock_tlvs = 1;
+ /* Based on tag data size the number of locks present in the default
+ * location changes */
+ for (xx = 0; xx < num_dynamic_lock_bytes; xx++) {
+ p_t2t->lockbyte[xx].tlv_index = p_t2t->num_lock_tlvs;
+ p_t2t->lockbyte[xx].byte_index = xx;
+ p_t2t->lockbyte[xx].b_lock_read = false;
}
+ p_t2t->num_lockbytes = num_dynamic_lock_bytes;
+ p_t2t->num_lock_tlvs = 1;
+ }
}
/*******************************************************************************
@@ -949,60 +861,56 @@
** started. Otherwise, error status.
**
*******************************************************************************/
-tNFC_STATUS rw_t2t_read_ndef_last_block (void)
-{
- tRW_T2T_CB *p_t2t = &rw_cb.tcb.t2t;
- uint16_t header_len = (p_t2t->new_ndef_msg_len >= T2T_LONG_NDEF_MIN_LEN) ? T2T_LONG_NDEF_LEN_FIELD_LEN : T2T_SHORT_NDEF_LEN_FIELD_LEN;
- uint16_t num_ndef_bytes;
- uint16_t total_ndef_bytes;
- uint16_t last_ndef_byte_offset;
- uint16_t terminator_tlv_byte_index;
- tNFC_STATUS status;
- uint16_t block;
+tNFC_STATUS rw_t2t_read_ndef_last_block(void) {
+ tRW_T2T_CB* p_t2t = &rw_cb.tcb.t2t;
+ uint16_t header_len = (p_t2t->new_ndef_msg_len >= T2T_LONG_NDEF_MIN_LEN)
+ ? T2T_LONG_NDEF_LEN_FIELD_LEN
+ : T2T_SHORT_NDEF_LEN_FIELD_LEN;
+ uint16_t num_ndef_bytes;
+ uint16_t total_ndef_bytes;
+ uint16_t last_ndef_byte_offset;
+ uint16_t terminator_tlv_byte_index;
+ tNFC_STATUS status;
+ uint16_t block;
+ total_ndef_bytes = header_len + p_t2t->new_ndef_msg_len;
+ num_ndef_bytes = 0;
+ last_ndef_byte_offset = p_t2t->ndef_header_offset;
- total_ndef_bytes = header_len + p_t2t->new_ndef_msg_len;
- num_ndef_bytes = 0;
- last_ndef_byte_offset = p_t2t->ndef_header_offset;
+ /* Locate NDEF final block based on the size of new NDEF Message */
+ while (num_ndef_bytes < total_ndef_bytes) {
+ if (rw_t2t_is_lock_res_byte((uint16_t)(last_ndef_byte_offset)) == false)
+ num_ndef_bytes++;
- /* Locate NDEF final block based on the size of new NDEF Message */
- while (num_ndef_bytes < total_ndef_bytes)
- {
- if (rw_t2t_is_lock_res_byte((uint16_t)(last_ndef_byte_offset)) == false)
- num_ndef_bytes++;
+ last_ndef_byte_offset++;
+ }
+ p_t2t->ndef_last_block_num =
+ (uint16_t)((last_ndef_byte_offset - 1) / T2T_BLOCK_SIZE);
+ block = p_t2t->ndef_last_block_num;
- last_ndef_byte_offset++;
+ p_t2t->substate = RW_T2T_SUBSTATE_WAIT_READ_NDEF_LAST_BLOCK;
+ /* Read NDEF last block before updating */
+ if ((status = rw_t2t_read(block)) == NFC_STATUS_OK) {
+ if ((p_t2t->new_ndef_msg_len + 1) <= p_t2t->max_ndef_msg_len) {
+ /* Locate Terminator TLV Block */
+ total_ndef_bytes++;
+ terminator_tlv_byte_index = last_ndef_byte_offset;
+
+ while (num_ndef_bytes < total_ndef_bytes) {
+ if (rw_t2t_is_lock_res_byte((uint16_t)terminator_tlv_byte_index) ==
+ false)
+ num_ndef_bytes++;
+
+ terminator_tlv_byte_index++;
+ }
+
+ p_t2t->terminator_byte_index = terminator_tlv_byte_index - 1;
+ } else {
+ /* No space for Terminator TLV */
+ p_t2t->terminator_byte_index = 0x00;
}
- p_t2t->ndef_last_block_num = (uint16_t) ((last_ndef_byte_offset - 1) / T2T_BLOCK_SIZE);
- block = p_t2t->ndef_last_block_num;
-
- p_t2t->substate = RW_T2T_SUBSTATE_WAIT_READ_NDEF_LAST_BLOCK;
- /* Read NDEF last block before updating */
- if ((status = rw_t2t_read (block))== NFC_STATUS_OK)
- {
- if ((p_t2t->new_ndef_msg_len + 1) <= p_t2t->max_ndef_msg_len)
- {
- /* Locate Terminator TLV Block */
- total_ndef_bytes++;
- terminator_tlv_byte_index = last_ndef_byte_offset;
-
- while (num_ndef_bytes < total_ndef_bytes)
- {
- if (rw_t2t_is_lock_res_byte((uint16_t)terminator_tlv_byte_index) == false)
- num_ndef_bytes++;
-
- terminator_tlv_byte_index++;
- }
-
- p_t2t->terminator_byte_index = terminator_tlv_byte_index - 1;
- }
- else
- {
- /* No space for Terminator TLV */
- p_t2t->terminator_byte_index = 0x00;
- }
- }
- return status;
+ }
+ return status;
}
/*******************************************************************************
@@ -1015,20 +923,21 @@
** Returns NCI_STATUS_OK, if read was started. Otherwise, error status.
**
*******************************************************************************/
-tNFC_STATUS rw_t2t_read_terminator_tlv_block (void)
-{
- tRW_T2T_CB *p_t2t = &rw_cb.tcb.t2t;
- tNFC_STATUS status;
- uint16_t block;
+tNFC_STATUS rw_t2t_read_terminator_tlv_block(void) {
+ tRW_T2T_CB* p_t2t = &rw_cb.tcb.t2t;
+ tNFC_STATUS status;
+ uint16_t block;
- /* Send read command to read base block (Block % 4==0) where this block is also read as part of 16 bytes */
- block = p_t2t->terminator_byte_index / T2T_BLOCK_SIZE;
- block -= block % T2T_READ_BLOCKS;
+ /* Send read command to read base block (Block % 4==0) where this block is
+ * also read as part of 16 bytes */
+ block = p_t2t->terminator_byte_index / T2T_BLOCK_SIZE;
+ block -= block % T2T_READ_BLOCKS;
- p_t2t->substate = RW_T2T_SUBSTATE_WAIT_READ_TERM_TLV_BLOCK;
- /* Read the block where Terminator TLV may be added later during NDEF Write operation */
- status = rw_t2t_read (block);
- return status;
+ p_t2t->substate = RW_T2T_SUBSTATE_WAIT_READ_TERM_TLV_BLOCK;
+ /* Read the block where Terminator TLV may be added later during NDEF Write
+ * operation */
+ status = rw_t2t_read(block);
+ return status;
}
/*******************************************************************************
@@ -1040,19 +949,19 @@
** Returns NCI_STATUS_OK, if read was started. Otherwise, error status.
**
*******************************************************************************/
-tNFC_STATUS rw_t2t_read_ndef_next_block (uint16_t block)
-{
- tRW_T2T_CB *p_t2t = &rw_cb.tcb.t2t;
- tNFC_STATUS status;
+tNFC_STATUS rw_t2t_read_ndef_next_block(uint16_t block) {
+ tRW_T2T_CB* p_t2t = &rw_cb.tcb.t2t;
+ tNFC_STATUS status;
- /* Send read command to read base block (Block % 4==0) where this block is also read as part of 16 bytes */
- block -= block % T2T_READ_BLOCKS;
+ /* Send read command to read base block (Block % 4==0) where this block is
+ * also read as part of 16 bytes */
+ block -= block % T2T_READ_BLOCKS;
- p_t2t->substate = RW_T2T_SUBSTATE_WAIT_READ_NDEF_NEXT_BLOCK;
- /* Read the block */
- status = rw_t2t_read (block);
+ p_t2t->substate = RW_T2T_SUBSTATE_WAIT_READ_NDEF_NEXT_BLOCK;
+ /* Read the block */
+ status = rw_t2t_read(block);
- return status;
+ return status;
}
/*******************************************************************************
@@ -1074,73 +983,58 @@
** that block
**
*******************************************************************************/
-static bool rw_t2t_is_read_before_write_block (uint16_t block, uint16_t *p_block_to_read)
-{
- tRW_T2T_CB *p_t2t = &rw_cb.tcb.t2t;
- uint8_t *p_cc = &p_t2t->tag_hdr[T2T_CC0_NMN_BYTE];
- uint8_t count;
- uint8_t index;
- uint16_t tag_size = p_cc[2] * 2 + T2T_FIRST_DATA_BLOCK;
- bool read_before_write = true;
+static bool rw_t2t_is_read_before_write_block(uint16_t block,
+ uint16_t* p_block_to_read) {
+ tRW_T2T_CB* p_t2t = &rw_cb.tcb.t2t;
+ uint8_t* p_cc = &p_t2t->tag_hdr[T2T_CC0_NMN_BYTE];
+ uint8_t count;
+ uint8_t index;
+ uint16_t tag_size = p_cc[2] * 2 + T2T_FIRST_DATA_BLOCK;
+ bool read_before_write = true;
+ if (block == p_t2t->ndef_header_offset / T2T_BLOCK_SIZE) {
+ /* First NDEF block is already read */
+ read_before_write = false;
+ memcpy(p_t2t->ndef_read_block, p_t2t->ndef_first_block, T2T_BLOCK_SIZE);
+ } else if (block == p_t2t->ndef_last_block_num) {
+ /* Last NDEF block is already read */
+ read_before_write = false;
+ memcpy(p_t2t->ndef_read_block, p_t2t->ndef_last_block, T2T_BLOCK_SIZE);
+ } else if (block == p_t2t->terminator_byte_index / T2T_BLOCK_SIZE) {
+ /* Terminator tlv block is already read */
+ read_before_write = false;
+ memcpy(p_t2t->ndef_read_block, p_t2t->terminator_tlv_block, T2T_BLOCK_SIZE);
+ } else {
+ count = 0;
+ while (block < tag_size) {
+ index = 0;
- if (block == p_t2t->ndef_header_offset / T2T_BLOCK_SIZE)
- {
- /* First NDEF block is already read */
- read_before_write = false;
- memcpy (p_t2t->ndef_read_block,p_t2t->ndef_first_block,T2T_BLOCK_SIZE);
- }
- else if (block == p_t2t->ndef_last_block_num)
- {
- /* Last NDEF block is already read */
- read_before_write = false;
- memcpy (p_t2t->ndef_read_block,p_t2t->ndef_last_block,T2T_BLOCK_SIZE);
- }
- else if (block == p_t2t->terminator_byte_index / T2T_BLOCK_SIZE)
- {
- /* Terminator tlv block is already read */
- read_before_write = false;
- memcpy (p_t2t->ndef_read_block,p_t2t->terminator_tlv_block,T2T_BLOCK_SIZE);
- }
- else
- {
- count = 0;
- while (block < tag_size)
- {
- index = 0;
-
- while (index < T2T_BLOCK_SIZE)
- {
- /* check if it is a reserved or locked byte */
- if (rw_t2t_is_lock_res_byte((uint16_t)((block * T2T_BLOCK_SIZE) + index)) == false)
- {
- count++;
- }
- index++;
- }
- if (count == T2T_BLOCK_SIZE)
- {
- /* All the bytes in the block are free to NDEF write */
- read_before_write = false;
- break;
- }
- else if (count == 0)
- {
- /* The complete block is not free for NDEF write */
- index = 0;
- block++;
- }
- else
- {
- /* The block has reseved byte (s) or locked byte (s) or both */
- read_before_write = true;
- break;
- }
+ while (index < T2T_BLOCK_SIZE) {
+ /* check if it is a reserved or locked byte */
+ if (rw_t2t_is_lock_res_byte(
+ (uint16_t)((block * T2T_BLOCK_SIZE) + index)) == false) {
+ count++;
}
+ index++;
+ }
+ if (count == T2T_BLOCK_SIZE) {
+ /* All the bytes in the block are free to NDEF write */
+ read_before_write = false;
+ break;
+ } else if (count == 0) {
+ /* The complete block is not free for NDEF write */
+ index = 0;
+ block++;
+ } else {
+ /* The block has reseved byte (s) or locked byte (s) or both */
+ read_before_write = true;
+ break;
+ }
}
- /* Return the block to read next before NDEF write */
- *p_block_to_read = block;
- return read_before_write;
+ }
+ /* Return the block to read next before NDEF write */
+ *p_block_to_read = block;
+ return read_before_write;
}
/*******************************************************************************
@@ -1156,101 +1050,90 @@
** Otherwise, error status.
**
*******************************************************************************/
-tNFC_STATUS rw_t2t_write_ndef_first_block (uint16_t msg_len, bool b_update_len)
-{
- tRW_T2T_CB *p_t2t = &rw_cb.tcb.t2t;
- uint8_t new_lengthfield_len;
- uint8_t write_block[4];
- uint8_t block;
- uint8_t *p_cc = &p_t2t->tag_hdr[T2T_CC0_NMN_BYTE];
- uint16_t total_blocks = p_cc[2] * 2 + T2T_FIRST_DATA_BLOCK;
- tNFC_STATUS status;
- uint8_t length_field[3];
- uint8_t index;
+tNFC_STATUS rw_t2t_write_ndef_first_block(uint16_t msg_len, bool b_update_len) {
+ tRW_T2T_CB* p_t2t = &rw_cb.tcb.t2t;
+ uint8_t new_lengthfield_len;
+ uint8_t write_block[4];
+ uint8_t block;
+ uint8_t* p_cc = &p_t2t->tag_hdr[T2T_CC0_NMN_BYTE];
+ uint16_t total_blocks = p_cc[2] * 2 + T2T_FIRST_DATA_BLOCK;
+ tNFC_STATUS status;
+ uint8_t length_field[3];
+ uint8_t index;
- p_t2t->work_offset = 0;
- new_lengthfield_len = p_t2t->new_ndef_msg_len >= T2T_LONG_NDEF_MIN_LEN ? T2T_LONG_NDEF_LEN_FIELD_LEN : T2T_SHORT_NDEF_LEN_FIELD_LEN;
- if (new_lengthfield_len == 3)
- {
- /* New NDEF is Long NDEF */
- if (msg_len == 0)
- {
- /* Clear NDEF length field */
- length_field[0] = 0x00;
- length_field[1] = 0x00;
- length_field[2] = 0x00;
- }
- else
- {
- /* Update NDEF length field with new NDEF Msg len */
- length_field[0] = T2T_LONG_NDEF_LEN_FIELD_BYTE0;
- length_field[1] = (uint8_t) (msg_len >> 8);
- length_field[2] = (uint8_t) (msg_len);
- }
+ p_t2t->work_offset = 0;
+ new_lengthfield_len = p_t2t->new_ndef_msg_len >= T2T_LONG_NDEF_MIN_LEN
+ ? T2T_LONG_NDEF_LEN_FIELD_LEN
+ : T2T_SHORT_NDEF_LEN_FIELD_LEN;
+ if (new_lengthfield_len == 3) {
+ /* New NDEF is Long NDEF */
+ if (msg_len == 0) {
+ /* Clear NDEF length field */
+ length_field[0] = 0x00;
+ length_field[1] = 0x00;
+ length_field[2] = 0x00;
+ } else {
+ /* Update NDEF length field with new NDEF Msg len */
+ length_field[0] = T2T_LONG_NDEF_LEN_FIELD_BYTE0;
+ length_field[1] = (uint8_t)(msg_len >> 8);
+ length_field[2] = (uint8_t)(msg_len);
}
- else
- {
- /* New NDEF is Short NDEF */
- length_field[0] = (uint8_t) (msg_len);
- }
+ } else {
+ /* New NDEF is Short NDEF */
+ length_field[0] = (uint8_t)(msg_len);
+ }
- /* updating ndef_first_block with new ndef message */
- memcpy (write_block, p_t2t->ndef_first_block, T2T_BLOCK_SIZE);
+ /* updating ndef_first_block with new ndef message */
+ memcpy(write_block, p_t2t->ndef_first_block, T2T_BLOCK_SIZE);
- index = p_t2t->ndef_header_offset % T2T_BLOCK_SIZE;
- block = (uint8_t) (p_t2t->ndef_header_offset / T2T_BLOCK_SIZE);
+ index = p_t2t->ndef_header_offset % T2T_BLOCK_SIZE;
+ block = (uint8_t)(p_t2t->ndef_header_offset / T2T_BLOCK_SIZE);
- while (p_t2t->work_offset == 0 && block < total_blocks)
- {
- /* update length field */
- while (index < T2T_BLOCK_SIZE && p_t2t->work_offset < p_t2t->new_ndef_msg_len)
- {
- if (rw_t2t_is_lock_res_byte((uint16_t)((block * T2T_BLOCK_SIZE) + index)) == false)
- {
- write_block[index] = length_field[p_t2t->work_offset];
- p_t2t->work_offset++;
- }
- index++;
- if (p_t2t->work_offset == new_lengthfield_len)
- {
- break;
- }
- }
- /* If more space in this block then add ndef message */
- while (index < T2T_BLOCK_SIZE && p_t2t->work_offset < (p_t2t->new_ndef_msg_len + new_lengthfield_len))
- {
- if (rw_t2t_is_lock_res_byte((uint16_t)((block * T2T_BLOCK_SIZE) + index)) == false)
- {
- write_block[index] = p_t2t->p_new_ndef_buffer[p_t2t->work_offset - new_lengthfield_len];
- p_t2t->work_offset++;
- }
- index++;
- }
- if (p_t2t->work_offset == 0)
- {
- /* If no bytes are written move to next block */
- index = 0;
- block++;
- if (block == p_t2t->ndef_last_block_num)
- {
- memcpy (write_block, p_t2t->ndef_last_block, T2T_BLOCK_SIZE);
- }
- }
+ while (p_t2t->work_offset == 0 && block < total_blocks) {
+ /* update length field */
+ while (index < T2T_BLOCK_SIZE &&
+ p_t2t->work_offset < p_t2t->new_ndef_msg_len) {
+ if (rw_t2t_is_lock_res_byte(
+ (uint16_t)((block * T2T_BLOCK_SIZE) + index)) == false) {
+ write_block[index] = length_field[p_t2t->work_offset];
+ p_t2t->work_offset++;
+ }
+ index++;
+ if (p_t2t->work_offset == new_lengthfield_len) {
+ break;
+ }
}
- if (p_t2t->work_offset == 0)
- {
- status = NFC_STATUS_FAILED;
+ /* If more space in this block then add ndef message */
+ while (index < T2T_BLOCK_SIZE &&
+ p_t2t->work_offset <
+ (p_t2t->new_ndef_msg_len + new_lengthfield_len)) {
+ if (rw_t2t_is_lock_res_byte(
+ (uint16_t)((block * T2T_BLOCK_SIZE) + index)) == false) {
+ write_block[index] =
+ p_t2t->p_new_ndef_buffer[p_t2t->work_offset - new_lengthfield_len];
+ p_t2t->work_offset++;
+ }
+ index++;
}
- else
- {
- rw_t2t_update_cb (block, write_block, b_update_len);
- /* Update the identified block with newly prepared data */
- if ((status = rw_t2t_write (block, write_block)) == NFC_STATUS_OK)
- {
- p_t2t->b_read_data = false;
- }
+ if (p_t2t->work_offset == 0) {
+ /* If no bytes are written move to next block */
+ index = 0;
+ block++;
+ if (block == p_t2t->ndef_last_block_num) {
+ memcpy(write_block, p_t2t->ndef_last_block, T2T_BLOCK_SIZE);
+ }
}
- return status;
+ }
+ if (p_t2t->work_offset == 0) {
+ status = NFC_STATUS_FAILED;
+ } else {
+ rw_t2t_update_cb(block, write_block, b_update_len);
+ /* Update the identified block with newly prepared data */
+ if ((status = rw_t2t_write(block, write_block)) == NFC_STATUS_OK) {
+ p_t2t->b_read_data = false;
+ }
+ }
+ return status;
}
/*******************************************************************************
@@ -1263,118 +1146,111 @@
** Otherwise, error status.
**
*******************************************************************************/
-tNFC_STATUS rw_t2t_write_ndef_next_block (uint16_t block, uint16_t msg_len, bool b_update_len)
-{
- tRW_T2T_CB *p_t2t = &rw_cb.tcb.t2t;
- uint8_t new_lengthfield_len;
- uint8_t write_block[4];
- uint8_t *p_cc = &p_t2t->tag_hdr[T2T_CC0_NMN_BYTE];
- uint16_t total_blocks = p_cc[2] * 2 + T2T_FIRST_DATA_BLOCK;
- uint16_t initial_offset;
- uint8_t length_field[3];
- uint8_t index;
- tNFC_STATUS status;
+tNFC_STATUS rw_t2t_write_ndef_next_block(uint16_t block, uint16_t msg_len,
+ bool b_update_len) {
+ tRW_T2T_CB* p_t2t = &rw_cb.tcb.t2t;
+ uint8_t new_lengthfield_len;
+ uint8_t write_block[4];
+ uint8_t* p_cc = &p_t2t->tag_hdr[T2T_CC0_NMN_BYTE];
+ uint16_t total_blocks = p_cc[2] * 2 + T2T_FIRST_DATA_BLOCK;
+ uint16_t initial_offset;
+ uint8_t length_field[3];
+ uint8_t index;
+ tNFC_STATUS status;
- /* Write NDEF Message */
- new_lengthfield_len = p_t2t->new_ndef_msg_len >= T2T_LONG_NDEF_MIN_LEN ? T2T_LONG_NDEF_LEN_FIELD_LEN : T2T_SHORT_NDEF_LEN_FIELD_LEN;
+ /* Write NDEF Message */
+ new_lengthfield_len = p_t2t->new_ndef_msg_len >= T2T_LONG_NDEF_MIN_LEN
+ ? T2T_LONG_NDEF_LEN_FIELD_LEN
+ : T2T_SHORT_NDEF_LEN_FIELD_LEN;
- index = 0;
+ index = 0;
- memcpy (write_block, p_t2t->ndef_read_block, T2T_BLOCK_SIZE);
+ memcpy(write_block, p_t2t->ndef_read_block, T2T_BLOCK_SIZE);
- if (p_t2t->work_offset >= new_lengthfield_len)
- {
- /* Length field is updated, write ndef message field */
- initial_offset = p_t2t->work_offset;
- while (p_t2t->work_offset == initial_offset && block < total_blocks)
- {
- while (index < T2T_BLOCK_SIZE && p_t2t->work_offset < (p_t2t->new_ndef_msg_len + new_lengthfield_len))
- {
- if (rw_t2t_is_lock_res_byte((uint16_t)((block * T2T_BLOCK_SIZE) + index)) == false)
- {
- write_block[index] = p_t2t->p_new_ndef_buffer[p_t2t->work_offset - new_lengthfield_len];
- p_t2t->work_offset++;
- }
- index++;
- }
- if (p_t2t->work_offset == initial_offset)
- {
- index = 0;
- block++;
- }
+ if (p_t2t->work_offset >= new_lengthfield_len) {
+ /* Length field is updated, write ndef message field */
+ initial_offset = p_t2t->work_offset;
+ while (p_t2t->work_offset == initial_offset && block < total_blocks) {
+ while (index < T2T_BLOCK_SIZE &&
+ p_t2t->work_offset <
+ (p_t2t->new_ndef_msg_len + new_lengthfield_len)) {
+ if (rw_t2t_is_lock_res_byte(
+ (uint16_t)((block * T2T_BLOCK_SIZE) + index)) == false) {
+ write_block[index] =
+ p_t2t
+ ->p_new_ndef_buffer[p_t2t->work_offset - new_lengthfield_len];
+ p_t2t->work_offset++;
}
+ index++;
+ }
+ if (p_t2t->work_offset == initial_offset) {
+ index = 0;
+ block++;
+ }
}
- else
- {
- /* Complete writting Length field and then write ndef message */
- new_lengthfield_len = p_t2t->new_ndef_msg_len >= T2T_LONG_NDEF_MIN_LEN ? T2T_LONG_NDEF_LEN_FIELD_LEN : T2T_SHORT_NDEF_LEN_FIELD_LEN;
- if (new_lengthfield_len == 3)
- {
- /* New NDEF is Long NDEF */
- if (msg_len == 0)
- {
- length_field[0] = 0x00;
- length_field[1] = 0x00;
- length_field[2] = 0x00;
- }
- else
- {
- length_field[0] = T2T_LONG_NDEF_LEN_FIELD_BYTE0;
- length_field[1] = (uint8_t) (msg_len >> 8);
- length_field[2] = (uint8_t) (msg_len);
- }
+ } else {
+ /* Complete writting Length field and then write ndef message */
+ new_lengthfield_len = p_t2t->new_ndef_msg_len >= T2T_LONG_NDEF_MIN_LEN
+ ? T2T_LONG_NDEF_LEN_FIELD_LEN
+ : T2T_SHORT_NDEF_LEN_FIELD_LEN;
+ if (new_lengthfield_len == 3) {
+ /* New NDEF is Long NDEF */
+ if (msg_len == 0) {
+ length_field[0] = 0x00;
+ length_field[1] = 0x00;
+ length_field[2] = 0x00;
+ } else {
+ length_field[0] = T2T_LONG_NDEF_LEN_FIELD_BYTE0;
+ length_field[1] = (uint8_t)(msg_len >> 8);
+ length_field[2] = (uint8_t)(msg_len);
+ }
+ } else {
+ /* New NDEF is short NDEF */
+ length_field[0] = (uint8_t)(msg_len);
+ }
+ initial_offset = p_t2t->work_offset;
+ while (p_t2t->work_offset == initial_offset && block < total_blocks) {
+ /* Update length field */
+ while (index < T2T_BLOCK_SIZE &&
+ p_t2t->work_offset < p_t2t->new_ndef_msg_len) {
+ if (rw_t2t_is_lock_res_byte(
+ (uint16_t)((block * T2T_BLOCK_SIZE) + index)) == false) {
+ write_block[index] = length_field[p_t2t->work_offset];
+ p_t2t->work_offset++;
}
- else
- {
- /* New NDEF is short NDEF */
- length_field[0] = (uint8_t) (msg_len);
+ index++;
+ if (p_t2t->work_offset == new_lengthfield_len) {
+ break;
}
- initial_offset = p_t2t->work_offset;
- while (p_t2t->work_offset == initial_offset && block < total_blocks)
- {
- /* Update length field */
- while (index < T2T_BLOCK_SIZE && p_t2t->work_offset < p_t2t->new_ndef_msg_len)
- {
- if (rw_t2t_is_lock_res_byte((uint16_t)((block * T2T_BLOCK_SIZE) + index)) == false)
- {
- write_block[index] = length_field[p_t2t->work_offset];
- p_t2t->work_offset++;
- }
- index++;
- if (p_t2t->work_offset == new_lengthfield_len)
- {
- break;
- }
- }
- /* Update ndef message field */
- while (index < T2T_BLOCK_SIZE && p_t2t->work_offset < (p_t2t->new_ndef_msg_len + new_lengthfield_len))
- {
- if (rw_t2t_is_lock_res_byte((uint16_t)((block * T2T_BLOCK_SIZE) + index)) == false)
- {
- write_block[index] = p_t2t->p_new_ndef_buffer[p_t2t->work_offset - new_lengthfield_len];
- p_t2t->work_offset++;
- }
- index++;
- }
- if (p_t2t->work_offset == initial_offset)
- {
- index = 0;
- block++;
- }
+ }
+ /* Update ndef message field */
+ while (index < T2T_BLOCK_SIZE &&
+ p_t2t->work_offset <
+ (p_t2t->new_ndef_msg_len + new_lengthfield_len)) {
+ if (rw_t2t_is_lock_res_byte(
+ (uint16_t)((block * T2T_BLOCK_SIZE) + index)) == false) {
+ write_block[index] =
+ p_t2t
+ ->p_new_ndef_buffer[p_t2t->work_offset - new_lengthfield_len];
+ p_t2t->work_offset++;
}
+ index++;
+ }
+ if (p_t2t->work_offset == initial_offset) {
+ index = 0;
+ block++;
+ }
}
- if (p_t2t->work_offset == initial_offset)
- {
- status = NFC_STATUS_FAILED;
- }
- else
- {
- rw_t2t_update_cb (block, write_block, b_update_len);
- /* Write the NDEF Block */
- status = rw_t2t_write (block, write_block);
- }
+ }
+ if (p_t2t->work_offset == initial_offset) {
+ status = NFC_STATUS_FAILED;
+ } else {
+ rw_t2t_update_cb(block, write_block, b_update_len);
+ /* Write the NDEF Block */
+ status = rw_t2t_write(block, write_block);
+ }
- return status;
+ return status;
}
/*******************************************************************************
@@ -1387,65 +1263,52 @@
** Otherwise, error status.
**
*******************************************************************************/
-static void rw_t2t_update_cb (uint16_t block, uint8_t *p_write_block, bool b_update_len)
-{
- tRW_T2T_CB *p_t2t = &rw_cb.tcb.t2t;
- uint8_t new_lengthfield_len;
+static void rw_t2t_update_cb(uint16_t block, uint8_t* p_write_block,
+ bool b_update_len) {
+ tRW_T2T_CB* p_t2t = &rw_cb.tcb.t2t;
+ uint8_t new_lengthfield_len;
- /* Write NDEF Message */
- new_lengthfield_len = p_t2t->new_ndef_msg_len >= T2T_LONG_NDEF_MIN_LEN ? T2T_LONG_NDEF_LEN_FIELD_LEN : T2T_SHORT_NDEF_LEN_FIELD_LEN;
+ /* Write NDEF Message */
+ new_lengthfield_len = p_t2t->new_ndef_msg_len >= T2T_LONG_NDEF_MIN_LEN
+ ? T2T_LONG_NDEF_LEN_FIELD_LEN
+ : T2T_SHORT_NDEF_LEN_FIELD_LEN;
- if (block == p_t2t->ndef_header_offset / T2T_BLOCK_SIZE)
- {
- /* Update ndef first block if the 'block' points to ndef first block */
- memcpy (p_t2t->ndef_first_block,p_write_block,T2T_BLOCK_SIZE);
+ if (block == p_t2t->ndef_header_offset / T2T_BLOCK_SIZE) {
+ /* Update ndef first block if the 'block' points to ndef first block */
+ memcpy(p_t2t->ndef_first_block, p_write_block, T2T_BLOCK_SIZE);
+ }
+ if (p_t2t->terminator_byte_index / T2T_BLOCK_SIZE == block) {
+ /* Update terminator block if the 'block' points to terminator tlv block */
+ memcpy(p_t2t->terminator_tlv_block, p_write_block, T2T_BLOCK_LEN);
+ }
+ if (b_update_len == false) {
+ if (block == p_t2t->ndef_last_block_num) {
+ p_t2t->substate = RW_T2T_SUBSTATE_WAIT_WRITE_NDEF_LAST_BLOCK;
+ p_t2t->work_offset = 0;
+ /* Update ndef final block if the 'block' points to ndef final block */
+ memcpy(p_t2t->ndef_last_block, p_write_block, T2T_BLOCK_SIZE);
+ } else {
+ p_t2t->substate = RW_T2T_SUBSTATE_WAIT_WRITE_NDEF_NEXT_BLOCK;
}
- if (p_t2t->terminator_byte_index/T2T_BLOCK_SIZE == block)
- {
- /* Update terminator block if the 'block' points to terminator tlv block */
- memcpy (p_t2t->terminator_tlv_block, p_write_block, T2T_BLOCK_LEN);
+ } else {
+ if (block == p_t2t->ndef_last_block_num) {
+ /* Update the backup of Ndef final block TLV block */
+ memcpy(p_t2t->ndef_last_block, p_write_block, T2T_BLOCK_SIZE);
}
- if (b_update_len == false)
- {
- if (block == p_t2t->ndef_last_block_num)
- {
- p_t2t->substate = RW_T2T_SUBSTATE_WAIT_WRITE_NDEF_LAST_BLOCK;
- p_t2t->work_offset = 0;
- /* Update ndef final block if the 'block' points to ndef final block */
- memcpy (p_t2t->ndef_last_block,p_write_block,T2T_BLOCK_SIZE);
- }
- else
- {
- p_t2t->substate = RW_T2T_SUBSTATE_WAIT_WRITE_NDEF_NEXT_BLOCK;
- }
- }
- else
- {
- if (block == p_t2t->ndef_last_block_num)
- {
- /* Update the backup of Ndef final block TLV block */
- memcpy (p_t2t->ndef_last_block,p_write_block,T2T_BLOCK_SIZE);
- }
- if (p_t2t->work_offset >= new_lengthfield_len)
- {
- if (p_t2t->terminator_byte_index != 0)
- {
- /* Add Terminator TLV as part of NDEF Write operation */
- p_t2t->substate = RW_T2T_SUBSTATE_WAIT_WRITE_NDEF_LEN_BLOCK;
- }
- else
- {
- /* Skip adding Terminator TLV */
- p_t2t->substate = RW_T2T_SUBSTATE_WAIT_WRITE_TERM_TLV_CMPLT;
- }
- }
- else
- {
- /* Part of NDEF Message Len should be added in the next block */
- p_t2t->substate = RW_T2T_SUBSTATE_WAIT_WRITE_NDEF_LEN_NEXT_BLOCK;
- }
+ if (p_t2t->work_offset >= new_lengthfield_len) {
+ if (p_t2t->terminator_byte_index != 0) {
+ /* Add Terminator TLV as part of NDEF Write operation */
+ p_t2t->substate = RW_T2T_SUBSTATE_WAIT_WRITE_NDEF_LEN_BLOCK;
+ } else {
+ /* Skip adding Terminator TLV */
+ p_t2t->substate = RW_T2T_SUBSTATE_WAIT_WRITE_TERM_TLV_CMPLT;
+ }
+ } else {
+ /* Part of NDEF Message Len should be added in the next block */
+ p_t2t->substate = RW_T2T_SUBSTATE_WAIT_WRITE_NDEF_LEN_NEXT_BLOCK;
}
+ }
}
/*******************************************************************************
@@ -1457,31 +1320,29 @@
** Returns NDEF Flag value
**
*******************************************************************************/
-static uint8_t rw_t2t_get_ndef_flags (void)
-{
- uint8_t flags = 0;
- tRW_T2T_CB *p_t2t = &rw_cb.tcb.t2t;
- const tT2T_INIT_TAG *p_ret;
+static uint8_t rw_t2t_get_ndef_flags(void) {
+ uint8_t flags = 0;
+ tRW_T2T_CB* p_t2t = &rw_cb.tcb.t2t;
+ const tT2T_INIT_TAG* p_ret;
- flags |= RW_NDEF_FL_SUPPORTED;
+ flags |= RW_NDEF_FL_SUPPORTED;
- if ((p_t2t->tag_hdr[T2T_CC2_TMS_BYTE] == T2T_CC2_TMS_STATIC) || (p_t2t->tag_hdr[T2T_CC2_TMS_BYTE] == 0))
- flags |= RW_NDEF_FL_FORMATABLE;
+ if ((p_t2t->tag_hdr[T2T_CC2_TMS_BYTE] == T2T_CC2_TMS_STATIC) ||
+ (p_t2t->tag_hdr[T2T_CC2_TMS_BYTE] == 0))
+ flags |= RW_NDEF_FL_FORMATABLE;
- if ((p_t2t->tag_hdr[T2T_CC3_RWA_BYTE] & T2T_CC3_RWA_RO) == T2T_CC3_RWA_RO)
- flags |=RW_NDEF_FL_READ_ONLY;
+ if ((p_t2t->tag_hdr[T2T_CC3_RWA_BYTE] & T2T_CC3_RWA_RO) == T2T_CC3_RWA_RO)
+ flags |= RW_NDEF_FL_READ_ONLY;
- if ( ((p_ret = t2t_tag_init_data (p_t2t->tag_hdr[0], false, 0)) != NULL)
- &&(p_ret->b_otp) )
- {
- /* Set otp flag */
- flags |= RW_NDEF_FL_OTP;
+ if (((p_ret = t2t_tag_init_data(p_t2t->tag_hdr[0], false, 0)) != NULL) &&
+ (p_ret->b_otp)) {
+ /* Set otp flag */
+ flags |= RW_NDEF_FL_OTP;
- /* Set Read only flag if otp tag already has NDEF Message */
- if (p_t2t->ndef_msg_len)
- flags |= RW_NDEF_FL_READ_ONLY;
- }
- return flags;
+ /* Set Read only flag if otp tag already has NDEF Message */
+ if (p_t2t->ndef_msg_len) flags |= RW_NDEF_FL_READ_ONLY;
+ }
+ return flags;
}
/*******************************************************************************
@@ -1494,46 +1355,48 @@
** Returns Maximum size of NDEF Message
**
*******************************************************************************/
-static uint16_t rw_t2t_get_ndef_max_size (void)
-{
- uint16_t offset;
- uint8_t xx;
- tRW_T2T_CB *p_t2t = &rw_cb.tcb.t2t;
- uint16_t tag_size = (p_t2t->tag_hdr[T2T_CC2_TMS_BYTE] * T2T_TMS_TAG_FACTOR) + (T2T_FIRST_DATA_BLOCK * T2T_BLOCK_LEN) + p_t2t->num_lockbytes;
+static uint16_t rw_t2t_get_ndef_max_size(void) {
+ uint16_t offset;
+ uint8_t xx;
+ tRW_T2T_CB* p_t2t = &rw_cb.tcb.t2t;
+ uint16_t tag_size = (p_t2t->tag_hdr[T2T_CC2_TMS_BYTE] * T2T_TMS_TAG_FACTOR) +
+ (T2T_FIRST_DATA_BLOCK * T2T_BLOCK_LEN) +
+ p_t2t->num_lockbytes;
- for (xx = 0; xx < p_t2t->num_mem_tlvs; xx++)
- tag_size += p_t2t->mem_tlv[xx].num_bytes;
+ for (xx = 0; xx < p_t2t->num_mem_tlvs; xx++)
+ tag_size += p_t2t->mem_tlv[xx].num_bytes;
- offset = p_t2t->ndef_msg_offset;
- p_t2t->max_ndef_msg_len = 0;
+ offset = p_t2t->ndef_msg_offset;
+ p_t2t->max_ndef_msg_len = 0;
- if ( (tag_size < T2T_STATIC_SIZE)
- ||(tag_size > (T2T_SECTOR_SIZE * T2T_MAX_SECTOR))
- ||((p_t2t->tag_hdr[T2T_CC0_NMN_BYTE] != T2T_CC0_NMN) && (p_t2t->tag_hdr[T2T_CC0_NMN_BYTE] != 0)) )
- {
- /* Tag not formated, assume static tag */
- p_t2t->max_ndef_msg_len = T2T_STATIC_SIZE - T2T_HEADER_SIZE - T2T_TLV_TYPE_LEN - T2T_SHORT_NDEF_LEN_FIELD_LEN;
- return p_t2t->max_ndef_msg_len;
- }
-
- /* Starting from NDEF Message offset find the first locked data byte */
- while (offset < tag_size)
- {
- if (rw_t2t_is_lock_res_byte((uint16_t)offset) == false)
- {
- if (rw_t2t_is_read_only_byte((uint16_t)offset) == true)
- break;
- p_t2t->max_ndef_msg_len++;
- }
- offset++;
- }
- /* NDEF Length field length changes based on NDEF size */
- if ( (p_t2t->max_ndef_msg_len >= T2T_LONG_NDEF_LEN_FIELD_BYTE0)
- &&((p_t2t->ndef_msg_offset - p_t2t->ndef_header_offset) == T2T_SHORT_NDEF_LEN_FIELD_LEN) )
- {
- p_t2t->max_ndef_msg_len -= (p_t2t->max_ndef_msg_len == T2T_LONG_NDEF_LEN_FIELD_BYTE0) ? 1: (T2T_LONG_NDEF_LEN_FIELD_LEN - T2T_SHORT_NDEF_LEN_FIELD_LEN);
- }
+ if ((tag_size < T2T_STATIC_SIZE) ||
+ (tag_size > (T2T_SECTOR_SIZE * T2T_MAX_SECTOR)) ||
+ ((p_t2t->tag_hdr[T2T_CC0_NMN_BYTE] != T2T_CC0_NMN) &&
+ (p_t2t->tag_hdr[T2T_CC0_NMN_BYTE] != 0))) {
+ /* Tag not formated, assume static tag */
+ p_t2t->max_ndef_msg_len = T2T_STATIC_SIZE - T2T_HEADER_SIZE -
+ T2T_TLV_TYPE_LEN - T2T_SHORT_NDEF_LEN_FIELD_LEN;
return p_t2t->max_ndef_msg_len;
+ }
+
+ /* Starting from NDEF Message offset find the first locked data byte */
+ while (offset < tag_size) {
+ if (rw_t2t_is_lock_res_byte((uint16_t)offset) == false) {
+ if (rw_t2t_is_read_only_byte((uint16_t)offset) == true) break;
+ p_t2t->max_ndef_msg_len++;
+ }
+ offset++;
+ }
+ /* NDEF Length field length changes based on NDEF size */
+ if ((p_t2t->max_ndef_msg_len >= T2T_LONG_NDEF_LEN_FIELD_BYTE0) &&
+ ((p_t2t->ndef_msg_offset - p_t2t->ndef_header_offset) ==
+ T2T_SHORT_NDEF_LEN_FIELD_LEN)) {
+ p_t2t->max_ndef_msg_len -=
+ (p_t2t->max_ndef_msg_len == T2T_LONG_NDEF_LEN_FIELD_BYTE0)
+ ? 1
+ : (T2T_LONG_NDEF_LEN_FIELD_LEN - T2T_SHORT_NDEF_LEN_FIELD_LEN);
+ }
+ return p_t2t->max_ndef_msg_len;
}
/*******************************************************************************
@@ -1546,20 +1409,20 @@
** Otherwise, error status.
**
*******************************************************************************/
-tNFC_STATUS rw_t2t_add_terminator_tlv (void)
-{
- tRW_T2T_CB *p_t2t = &rw_cb.tcb.t2t;
- tNFC_STATUS status;
- uint16_t block;
+tNFC_STATUS rw_t2t_add_terminator_tlv(void) {
+ tRW_T2T_CB* p_t2t = &rw_cb.tcb.t2t;
+ tNFC_STATUS status;
+ uint16_t block;
- /* Add Terminator TLV after NDEF Message */
- p_t2t->terminator_tlv_block[p_t2t->terminator_byte_index%T2T_BLOCK_LEN] = TAG_TERMINATOR_TLV;
- p_t2t->substate = RW_T2T_SUBSTATE_WAIT_WRITE_TERM_TLV_CMPLT;
+ /* Add Terminator TLV after NDEF Message */
+ p_t2t->terminator_tlv_block[p_t2t->terminator_byte_index % T2T_BLOCK_LEN] =
+ TAG_TERMINATOR_TLV;
+ p_t2t->substate = RW_T2T_SUBSTATE_WAIT_WRITE_TERM_TLV_CMPLT;
- block = p_t2t->terminator_byte_index/T2T_BLOCK_LEN;
- status = rw_t2t_write (block, p_t2t->terminator_tlv_block);
+ block = p_t2t->terminator_byte_index / T2T_BLOCK_LEN;
+ status = rw_t2t_write(block, p_t2t->terminator_tlv_block);
- return status;
+ return status;
}
/*******************************************************************************
@@ -1571,58 +1434,52 @@
** Returns none
**
*******************************************************************************/
-static void rw_t2t_handle_ndef_read_rsp (uint8_t *p_data)
-{
- tRW_T2T_CB *p_t2t = &rw_cb.tcb.t2t;
- tRW_READ_DATA evt_data;
- uint16_t len;
- uint16_t offset;
- bool failed = false;
- bool done = false;
+static void rw_t2t_handle_ndef_read_rsp(uint8_t* p_data) {
+ tRW_T2T_CB* p_t2t = &rw_cb.tcb.t2t;
+ tRW_READ_DATA evt_data;
+ uint16_t len;
+ uint16_t offset;
+ bool failed = false;
+ bool done = false;
- /* On the first read, adjust for any partial block offset */
- offset = 0;
- len = T2T_READ_DATA_LEN;
+ /* On the first read, adjust for any partial block offset */
+ offset = 0;
+ len = T2T_READ_DATA_LEN;
- if (p_t2t->work_offset == 0)
- {
- /* The Ndef Message offset may be present in the read 16 bytes */
- offset = (p_t2t->ndef_msg_offset - (p_t2t->block_read * T2T_BLOCK_SIZE));
+ if (p_t2t->work_offset == 0) {
+ /* The Ndef Message offset may be present in the read 16 bytes */
+ offset = (p_t2t->ndef_msg_offset - (p_t2t->block_read * T2T_BLOCK_SIZE));
+ }
+
+ /* Skip all reserved and lock bytes */
+ while ((offset < len) && (p_t2t->work_offset < p_t2t->ndef_msg_len))
+
+ {
+ if (rw_t2t_is_lock_res_byte(
+ (uint16_t)(offset + p_t2t->block_read * T2T_BLOCK_LEN)) == false) {
+ /* Collect the NDEF Message */
+ p_t2t->p_ndef_buffer[p_t2t->work_offset] = p_data[offset];
+ p_t2t->work_offset++;
}
+ offset++;
+ }
- /* Skip all reserved and lock bytes */
- while ( (offset < len)
- &&(p_t2t->work_offset<p_t2t->ndef_msg_len) )
+ if (p_t2t->work_offset >= p_t2t->ndef_msg_len) {
+ done = true;
+ p_t2t->ndef_status = T2T_NDEF_READ;
+ } else {
+ /* Read next 4 blocks */
+ if (rw_t2t_read((uint16_t)(p_t2t->block_read + T2T_READ_BLOCKS)) !=
+ NFC_STATUS_OK)
+ failed = true;
+ }
- {
- if (rw_t2t_is_lock_res_byte((uint16_t)(offset + p_t2t->block_read * T2T_BLOCK_LEN)) == false)
- {
- /* Collect the NDEF Message */
- p_t2t->p_ndef_buffer[p_t2t->work_offset] = p_data[offset];
- p_t2t->work_offset++;
- }
- offset++;
- }
-
- if (p_t2t->work_offset >= p_t2t->ndef_msg_len)
- {
- done = true;
- p_t2t->ndef_status = T2T_NDEF_READ;
- }
- else
- {
- /* Read next 4 blocks */
- if (rw_t2t_read ((uint16_t) (p_t2t->block_read + T2T_READ_BLOCKS)) != NFC_STATUS_OK)
- failed = true;
- }
-
- if (failed || done)
- {
- evt_data.status = failed ? NFC_STATUS_FAILED : NFC_STATUS_OK;
- evt_data.p_data = NULL;
- rw_t2t_handle_op_complete ();
- (*rw_cb.p_cback) (RW_T2T_NDEF_READ_EVT, (tRW_DATA *) &evt_data);
- }
+ if (failed || done) {
+ evt_data.status = failed ? NFC_STATUS_FAILED : NFC_STATUS_OK;
+ evt_data.p_data = NULL;
+ rw_t2t_handle_op_complete();
+ (*rw_cb.p_cback)(RW_T2T_NDEF_READ_EVT, (tRW_DATA*)&evt_data);
+ }
}
/*******************************************************************************
@@ -1635,167 +1492,160 @@
** Returns none
**
*******************************************************************************/
-static void rw_t2t_handle_ndef_write_rsp (uint8_t *p_data)
-{
- tRW_T2T_CB *p_t2t = &rw_cb.tcb.t2t;
- tRW_READ_DATA evt_data;
- bool failed = false;
- bool done = false;
- uint16_t block;
- uint8_t offset;
+static void rw_t2t_handle_ndef_write_rsp(uint8_t* p_data) {
+ tRW_T2T_CB* p_t2t = &rw_cb.tcb.t2t;
+ tRW_READ_DATA evt_data;
+ bool failed = false;
+ bool done = false;
+ uint16_t block;
+ uint8_t offset;
- switch (p_t2t->substate)
- {
+ switch (p_t2t->substate) {
case RW_T2T_SUBSTATE_WAIT_READ_NDEF_FIRST_BLOCK:
- /* Backup the read NDEF first block */
- memcpy (p_t2t->ndef_first_block, p_data, T2T_BLOCK_LEN);
- /* Read ndef final block */
- if (rw_t2t_read_ndef_last_block () != NFC_STATUS_OK)
- failed = true;
- break;
+ /* Backup the read NDEF first block */
+ memcpy(p_t2t->ndef_first_block, p_data, T2T_BLOCK_LEN);
+ /* Read ndef final block */
+ if (rw_t2t_read_ndef_last_block() != NFC_STATUS_OK) failed = true;
+ break;
case RW_T2T_SUBSTATE_WAIT_READ_NDEF_LAST_BLOCK:
- offset = (uint8_t) (p_t2t->ndef_last_block_num - p_t2t->block_read) * T2T_BLOCK_SIZE;
- /* Backup the read NDEF final block */
- memcpy (p_t2t->ndef_last_block, &p_data[offset], T2T_BLOCK_LEN);
- if ((p_t2t->terminator_byte_index / T2T_BLOCK_SIZE) == p_t2t->ndef_last_block_num)
- {
- /* If Terminator TLV will reside on the NDEF Final block */
- memcpy (p_t2t->terminator_tlv_block, p_t2t->ndef_last_block, T2T_BLOCK_LEN);
- if (rw_t2t_write_ndef_first_block (0x0000, false)!= NFC_STATUS_OK)
- failed = true;
- }
- else if (p_t2t->terminator_byte_index != 0)
- {
- /* If there is space for Terminator TLV and if it will reside outside NDEF Final block */
- if (rw_t2t_read_terminator_tlv_block ()!= NFC_STATUS_OK)
- failed = true;
- }
- else
- {
- if (rw_t2t_write_ndef_first_block (0x0000, false)!= NFC_STATUS_OK)
- failed = true;
- }
- break;
+ offset = (uint8_t)(p_t2t->ndef_last_block_num - p_t2t->block_read) *
+ T2T_BLOCK_SIZE;
+ /* Backup the read NDEF final block */
+ memcpy(p_t2t->ndef_last_block, &p_data[offset], T2T_BLOCK_LEN);
+ if ((p_t2t->terminator_byte_index / T2T_BLOCK_SIZE) ==
+ p_t2t->ndef_last_block_num) {
+ /* If Terminator TLV will reside on the NDEF Final block */
+ memcpy(p_t2t->terminator_tlv_block, p_t2t->ndef_last_block,
+ T2T_BLOCK_LEN);
+ if (rw_t2t_write_ndef_first_block(0x0000, false) != NFC_STATUS_OK)
+ failed = true;
+ } else if (p_t2t->terminator_byte_index != 0) {
+ /* If there is space for Terminator TLV and if it will reside outside
+ * NDEF Final block */
+ if (rw_t2t_read_terminator_tlv_block() != NFC_STATUS_OK) failed = true;
+ } else {
+ if (rw_t2t_write_ndef_first_block(0x0000, false) != NFC_STATUS_OK)
+ failed = true;
+ }
+ break;
case RW_T2T_SUBSTATE_WAIT_READ_TERM_TLV_BLOCK:
- offset = (uint8_t) (((p_t2t->terminator_byte_index / T2T_BLOCK_SIZE) - p_t2t->block_read) * T2T_BLOCK_SIZE);
- /* Backup the read Terminator TLV block */
- memcpy (p_t2t->terminator_tlv_block, &p_data[offset], T2T_BLOCK_LEN);
+ offset = (uint8_t)(((p_t2t->terminator_byte_index / T2T_BLOCK_SIZE) -
+ p_t2t->block_read) *
+ T2T_BLOCK_SIZE);
+ /* Backup the read Terminator TLV block */
+ memcpy(p_t2t->terminator_tlv_block, &p_data[offset], T2T_BLOCK_LEN);
- /* Write the first block for new NDEF Message */
- if (rw_t2t_write_ndef_first_block (0x0000, false)!= NFC_STATUS_OK)
- failed = true;
- break;
+ /* Write the first block for new NDEF Message */
+ if (rw_t2t_write_ndef_first_block(0x0000, false) != NFC_STATUS_OK)
+ failed = true;
+ break;
case RW_T2T_SUBSTATE_WAIT_READ_NDEF_NEXT_BLOCK:
- offset = (uint8_t) (p_t2t->ndef_read_block_num - p_t2t->block_read) * T2T_BLOCK_SIZE;
- /* Backup read block */
- memcpy (p_t2t->ndef_read_block, &p_data[offset], T2T_BLOCK_LEN);
+ offset = (uint8_t)(p_t2t->ndef_read_block_num - p_t2t->block_read) *
+ T2T_BLOCK_SIZE;
+ /* Backup read block */
+ memcpy(p_t2t->ndef_read_block, &p_data[offset], T2T_BLOCK_LEN);
- /* Update the block with new NDEF Message */
- if (rw_t2t_write_ndef_next_block (p_t2t->ndef_read_block_num, 0x0000, false) != NFC_STATUS_OK)
- failed = true;
- break;
+ /* Update the block with new NDEF Message */
+ if (rw_t2t_write_ndef_next_block(p_t2t->ndef_read_block_num, 0x0000,
+ false) != NFC_STATUS_OK)
+ failed = true;
+ break;
case RW_T2T_SUBSTATE_WAIT_WRITE_NDEF_NEXT_BLOCK:
case RW_T2T_SUBSTATE_WAIT_WRITE_NDEF_LEN_NEXT_BLOCK:
- if (rw_t2t_is_read_before_write_block((uint16_t)(p_t2t->block_written + 1), &block) == true)
- {
- p_t2t->ndef_read_block_num = block;
- /* If only part of the block is going to be updated read the block to retain previous data for
- unchanged part of the block */
- if (rw_t2t_read_ndef_next_block (block) != NFC_STATUS_OK)
- failed = true;
+ if (rw_t2t_is_read_before_write_block(
+ (uint16_t)(p_t2t->block_written + 1), &block) == true) {
+ p_t2t->ndef_read_block_num = block;
+ /* If only part of the block is going to be updated read the block to
+ retain previous data for
+ unchanged part of the block */
+ if (rw_t2t_read_ndef_next_block(block) != NFC_STATUS_OK) failed = true;
+ } else {
+ if (p_t2t->substate == RW_T2T_SUBSTATE_WAIT_WRITE_NDEF_LEN_NEXT_BLOCK) {
+ /* Directly write the block with new NDEF contents as whole block is
+ * going to be updated */
+ if (rw_t2t_write_ndef_next_block(block, p_t2t->new_ndef_msg_len,
+ true) != NFC_STATUS_OK)
+ failed = true;
+ } else {
+ /* Directly write the block with new NDEF contents as whole block is
+ * going to be updated */
+ if (rw_t2t_write_ndef_next_block(block, 0x0000, false) !=
+ NFC_STATUS_OK)
+ failed = true;
}
- else
- {
- if (p_t2t->substate == RW_T2T_SUBSTATE_WAIT_WRITE_NDEF_LEN_NEXT_BLOCK)
- {
- /* Directly write the block with new NDEF contents as whole block is going to be updated */
- if (rw_t2t_write_ndef_next_block (block, p_t2t->new_ndef_msg_len, true)!= NFC_STATUS_OK)
- failed = true;
- }
- else
- {
- /* Directly write the block with new NDEF contents as whole block is going to be updated */
- if (rw_t2t_write_ndef_next_block (block, 0x0000, false)!= NFC_STATUS_OK)
- failed = true;
- }
- }
- break;
+ }
+ break;
case RW_T2T_SUBSTATE_WAIT_WRITE_NDEF_LAST_BLOCK:
- /* Write the next block for new NDEF Message */
- p_t2t->ndef_write_block = p_t2t->ndef_header_offset / T2T_BLOCK_SIZE;
- if (rw_t2t_is_read_before_write_block((uint16_t)(p_t2t->ndef_write_block), &block) == true)
- {
- /* If only part of the block is going to be updated read the block to retain previous data for
- part of the block thats not going to be changed */
- p_t2t->substate = RW_T2T_SUBSTATE_WAIT_READ_NDEF_LEN_BLOCK;
- if (rw_t2t_read (block) != NFC_STATUS_OK)
- failed = true;
+ /* Write the next block for new NDEF Message */
+ p_t2t->ndef_write_block = p_t2t->ndef_header_offset / T2T_BLOCK_SIZE;
+ if (rw_t2t_is_read_before_write_block((uint16_t)(p_t2t->ndef_write_block),
+ &block) == true) {
+ /* If only part of the block is going to be updated read the block to
+ retain previous data for
+ part of the block thats not going to be changed */
+ p_t2t->substate = RW_T2T_SUBSTATE_WAIT_READ_NDEF_LEN_BLOCK;
+ if (rw_t2t_read(block) != NFC_STATUS_OK) failed = true;
- }
- else
- {
- /* Update NDEF Message Length in the Tag */
- if (rw_t2t_write_ndef_first_block (p_t2t->new_ndef_msg_len, true)!= NFC_STATUS_OK)
- failed = true;
- }
- break;
+ } else {
+ /* Update NDEF Message Length in the Tag */
+ if (rw_t2t_write_ndef_first_block(p_t2t->new_ndef_msg_len, true) !=
+ NFC_STATUS_OK)
+ failed = true;
+ }
+ break;
case RW_T2T_SUBSTATE_WAIT_READ_NDEF_LEN_BLOCK:
- /* Backup read block */
- memcpy (p_t2t->ndef_read_block, p_data, T2T_BLOCK_LEN);
+ /* Backup read block */
+ memcpy(p_t2t->ndef_read_block, p_data, T2T_BLOCK_LEN);
- /* Update the block with new NDEF Message */
- if (rw_t2t_write_ndef_next_block (p_t2t->block_read, p_t2t->new_ndef_msg_len, true) == NFC_STATUS_OK)
- p_t2t->ndef_write_block = p_t2t->block_read + 1;
- else
- failed = true;
+ /* Update the block with new NDEF Message */
+ if (rw_t2t_write_ndef_next_block(p_t2t->block_read,
+ p_t2t->new_ndef_msg_len,
+ true) == NFC_STATUS_OK)
+ p_t2t->ndef_write_block = p_t2t->block_read + 1;
+ else
+ failed = true;
- break;
+ break;
case RW_T2T_SUBSTATE_WAIT_WRITE_NDEF_LEN_BLOCK:
- if (rw_t2t_add_terminator_tlv ()!= NFC_STATUS_OK)
- failed = true;
- break;
+ if (rw_t2t_add_terminator_tlv() != NFC_STATUS_OK) failed = true;
+ break;
case RW_T2T_SUBSTATE_WAIT_WRITE_TERM_TLV_CMPLT:
- done = true;
- break;
+ done = true;
+ break;
default:
- break;
- }
+ break;
+ }
- if (failed || done)
- {
- evt_data.p_data = NULL;
- /* NDEF WRITE Operation is done, inform up the stack */
- evt_data.status = failed ? NFC_STATUS_FAILED : NFC_STATUS_OK;
- if (done)
- {
- if ( (p_t2t->ndef_msg_len >= 0x00FF)
- &&(p_t2t->new_ndef_msg_len < 0x00FF) )
- {
- p_t2t->ndef_msg_offset -= 2;
- }
- else if ( (p_t2t->new_ndef_msg_len >= 0x00FF)
- &&(p_t2t->ndef_msg_len < 0x00FF) )
- {
- p_t2t->ndef_msg_offset += 2;
- }
- p_t2t->ndef_msg_len = p_t2t->new_ndef_msg_len;
- }
- rw_t2t_handle_op_complete ();
- (*rw_cb.p_cback) (RW_T2T_NDEF_WRITE_EVT, (tRW_DATA *) &evt_data);
+ if (failed || done) {
+ evt_data.p_data = NULL;
+ /* NDEF WRITE Operation is done, inform up the stack */
+ evt_data.status = failed ? NFC_STATUS_FAILED : NFC_STATUS_OK;
+ if (done) {
+ if ((p_t2t->ndef_msg_len >= 0x00FF) &&
+ (p_t2t->new_ndef_msg_len < 0x00FF)) {
+ p_t2t->ndef_msg_offset -= 2;
+ } else if ((p_t2t->new_ndef_msg_len >= 0x00FF) &&
+ (p_t2t->ndef_msg_len < 0x00FF)) {
+ p_t2t->ndef_msg_offset += 2;
+ }
+ p_t2t->ndef_msg_len = p_t2t->new_ndef_msg_len;
}
+ rw_t2t_handle_op_complete();
+ (*rw_cb.p_cback)(RW_T2T_NDEF_WRITE_EVT, (tRW_DATA*)&evt_data);
+ }
}
/*******************************************************************************
@@ -1808,22 +1658,21 @@
** Returns TMS of the tag
**
*******************************************************************************/
-static uint8_t rw_t2t_get_tag_size (uint8_t *p_data)
-{
- uint16_t LchunkSize = 0;
- uint16_t Num_LChuncks = 0;
- uint16_t tms = 0;
+static uint8_t rw_t2t_get_tag_size(uint8_t* p_data) {
+ uint16_t LchunkSize = 0;
+ uint16_t Num_LChuncks = 0;
+ uint16_t tms = 0;
- LchunkSize = (uint16_t) p_data[2] << 8 | p_data[3];
- Num_LChuncks = (uint16_t) p_data[4] << 8 | p_data[5];
+ LchunkSize = (uint16_t)p_data[2] << 8 | p_data[3];
+ Num_LChuncks = (uint16_t)p_data[4] << 8 | p_data[5];
- tms = (uint16_t) (LchunkSize * Num_LChuncks);
+ tms = (uint16_t)(LchunkSize * Num_LChuncks);
- tms += (T2T_STATIC_SIZE - T2T_HEADER_SIZE);
+ tms += (T2T_STATIC_SIZE - T2T_HEADER_SIZE);
- tms /= 0x08;
+ tms /= 0x08;
- return (uint8_t) tms;
+ return (uint8_t)tms;
}
/*******************************************************************************
@@ -1835,103 +1684,99 @@
** Returns none
**
*******************************************************************************/
-static void rw_t2t_handle_config_tag_readonly (uint8_t *p_data)
-{
- tRW_T2T_CB *p_t2t = &rw_cb.tcb.t2t;
- tNFC_STATUS status = NFC_STATUS_FAILED;
- bool b_notify = false;
- uint8_t write_block[T2T_BLOCK_SIZE];
- tRW_DATA evt;
- bool b_pending = false;
- uint8_t read_lock = 0;
- uint8_t num_locks = 0;
- uint16_t offset;
+static void rw_t2t_handle_config_tag_readonly(uint8_t* p_data) {
+ tRW_T2T_CB* p_t2t = &rw_cb.tcb.t2t;
+ tNFC_STATUS status = NFC_STATUS_FAILED;
+ bool b_notify = false;
+ uint8_t write_block[T2T_BLOCK_SIZE];
+ tRW_DATA evt;
+ bool b_pending = false;
+ uint8_t read_lock = 0;
+ uint8_t num_locks = 0;
+ uint16_t offset;
- switch (p_t2t->substate)
- {
+ switch (p_t2t->substate) {
case RW_T2T_SUBSTATE_WAIT_READ_CC:
- /* First soft lock the tag */
- rw_t2t_soft_lock_tag ();
+ /* First soft lock the tag */
+ rw_t2t_soft_lock_tag();
- break;
+ break;
case RW_T2T_SUBSTATE_WAIT_SET_CC_RO:
- /* Successfully soft locked! Update Tag header for future reference */
- p_t2t->tag_hdr[T2T_CC3_RWA_BYTE] = T2T_CC3_RWA_RO;
- if (!p_t2t->b_hard_lock)
- {
- /* Tag configuration complete */
- status = NFC_STATUS_OK;
- b_notify = true;
- break;
- }
-
- /* Coverity: [FALSE-POSITIVE error] intended fall through */
- /* Missing break statement between cases in switch statement */
- /* fall through */
- case RW_T2T_SUBSTATE_WAIT_SET_DYN_LOCK_BITS:
-
- num_locks = 0;
-
- while (num_locks < p_t2t->num_lockbytes)
- {
- if (p_t2t->lockbyte[num_locks].lock_status == RW_T2T_LOCK_UPDATE_INITIATED)
- {
- /* Update control block as one or more dynamic lock byte (s) are set */
- p_t2t->lockbyte[num_locks].lock_status = RW_T2T_LOCK_UPDATED;
- }
- if (!b_pending && p_t2t->lockbyte[num_locks].lock_status == RW_T2T_LOCK_NOT_UPDATED)
- {
- /* One or more dynamic lock bits are not set */
- b_pending = true;
- read_lock = num_locks;
- }
- num_locks++;
- }
-
- if (b_pending)
- {
- /* Read the block where dynamic lock bits are present to avoid writing to NDEF bytes in the same block */
- offset = p_t2t->lock_tlv[p_t2t->lockbyte[read_lock].tlv_index].offset + p_t2t->lockbyte[read_lock].byte_index;
- p_t2t->substate = RW_T2T_SUBSTATE_WAIT_READ_DYN_LOCK_BYTE_BLOCK;
- status = rw_t2t_read ((uint16_t) (offset / T2T_BLOCK_LEN));
- }
- else
- {
- /* Now set Static lock bits as no more dynamic lock bits to set */
-
- /* Copy the internal bytes */
- memcpy (write_block, &p_t2t->tag_hdr[T2T_STATIC_LOCK0 - T2T_INTERNAL_BYTES_LEN], T2T_INTERNAL_BYTES_LEN);
- /* Set all Static lock bits */
- write_block [T2T_STATIC_LOCK0 % T2T_BLOCK_SIZE] = 0xFF;
- write_block [T2T_STATIC_LOCK1 % T2T_BLOCK_SIZE] = 0xFF;
- p_t2t->substate = RW_T2T_SUBSTATE_WAIT_SET_ST_LOCK_BITS;
- status = rw_t2t_write ((T2T_STATIC_LOCK0 / T2T_BLOCK_SIZE), write_block);
- }
- break;
-
- case RW_T2T_SUBSTATE_WAIT_READ_DYN_LOCK_BYTE_BLOCK:
- /* Now set the dynamic lock bits present in the block read now */
- status = rw_t2t_set_dynamic_lock_bits (p_data);
- break;
-
- case RW_T2T_SUBSTATE_WAIT_SET_ST_LOCK_BITS:
+ /* Successfully soft locked! Update Tag header for future reference */
+ p_t2t->tag_hdr[T2T_CC3_RWA_BYTE] = T2T_CC3_RWA_RO;
+ if (!p_t2t->b_hard_lock) {
/* Tag configuration complete */
- status = NFC_STATUS_OK;
+ status = NFC_STATUS_OK;
b_notify = true;
break;
+ }
- }
+ /* Coverity: [FALSE-POSITIVE error] intended fall through */
+ /* Missing break statement between cases in switch statement */
+ /* fall through */
+ case RW_T2T_SUBSTATE_WAIT_SET_DYN_LOCK_BITS:
- if (status != NFC_STATUS_OK || b_notify)
- {
- /* Notify upper layer the result of Configuring Tag as Read only */
- evt.status = status;
- rw_t2t_handle_op_complete ();
- (*rw_cb.p_cback) (RW_T2T_SET_TAG_RO_EVT, (tRW_DATA *) &evt);
- }
+ num_locks = 0;
+
+ while (num_locks < p_t2t->num_lockbytes) {
+ if (p_t2t->lockbyte[num_locks].lock_status ==
+ RW_T2T_LOCK_UPDATE_INITIATED) {
+ /* Update control block as one or more dynamic lock byte (s) are set
+ */
+ p_t2t->lockbyte[num_locks].lock_status = RW_T2T_LOCK_UPDATED;
+ }
+ if (!b_pending &&
+ p_t2t->lockbyte[num_locks].lock_status == RW_T2T_LOCK_NOT_UPDATED) {
+ /* One or more dynamic lock bits are not set */
+ b_pending = true;
+ read_lock = num_locks;
+ }
+ num_locks++;
+ }
+
+ if (b_pending) {
+ /* Read the block where dynamic lock bits are present to avoid writing
+ * to NDEF bytes in the same block */
+ offset = p_t2t->lock_tlv[p_t2t->lockbyte[read_lock].tlv_index].offset +
+ p_t2t->lockbyte[read_lock].byte_index;
+ p_t2t->substate = RW_T2T_SUBSTATE_WAIT_READ_DYN_LOCK_BYTE_BLOCK;
+ status = rw_t2t_read((uint16_t)(offset / T2T_BLOCK_LEN));
+ } else {
+ /* Now set Static lock bits as no more dynamic lock bits to set */
+
+ /* Copy the internal bytes */
+ memcpy(write_block,
+ &p_t2t->tag_hdr[T2T_STATIC_LOCK0 - T2T_INTERNAL_BYTES_LEN],
+ T2T_INTERNAL_BYTES_LEN);
+ /* Set all Static lock bits */
+ write_block[T2T_STATIC_LOCK0 % T2T_BLOCK_SIZE] = 0xFF;
+ write_block[T2T_STATIC_LOCK1 % T2T_BLOCK_SIZE] = 0xFF;
+ p_t2t->substate = RW_T2T_SUBSTATE_WAIT_SET_ST_LOCK_BITS;
+ status = rw_t2t_write((T2T_STATIC_LOCK0 / T2T_BLOCK_SIZE), write_block);
+ }
+ break;
+
+ case RW_T2T_SUBSTATE_WAIT_READ_DYN_LOCK_BYTE_BLOCK:
+ /* Now set the dynamic lock bits present in the block read now */
+ status = rw_t2t_set_dynamic_lock_bits(p_data);
+ break;
+
+ case RW_T2T_SUBSTATE_WAIT_SET_ST_LOCK_BITS:
+ /* Tag configuration complete */
+ status = NFC_STATUS_OK;
+ b_notify = true;
+ break;
+ }
+
+ if (status != NFC_STATUS_OK || b_notify) {
+ /* Notify upper layer the result of Configuring Tag as Read only */
+ evt.status = status;
+ rw_t2t_handle_op_complete();
+ (*rw_cb.p_cback)(RW_T2T_SET_TAG_RO_EVT, (tRW_DATA*)&evt);
+ }
}
/*******************************************************************************
@@ -1943,119 +1788,115 @@
** Returns none
**
*******************************************************************************/
-static void rw_t2t_handle_format_tag_rsp (uint8_t *p_data)
-{
- tRW_DATA evt;
- uint8_t *p;
- tRW_T2T_CB *p_t2t = &rw_cb.tcb.t2t;
- tNFC_STATUS status = NFC_STATUS_FAILED;
- uint16_t version_no;
- const tT2T_INIT_TAG *p_ret;
- uint8_t tms;
- uint8_t next_block = T2T_FIRST_DATA_BLOCK + 1;
- uint16_t addr, locked_area;
- bool b_notify = false;
+static void rw_t2t_handle_format_tag_rsp(uint8_t* p_data) {
+ tRW_DATA evt;
+ uint8_t* p;
+ tRW_T2T_CB* p_t2t = &rw_cb.tcb.t2t;
+ tNFC_STATUS status = NFC_STATUS_FAILED;
+ uint16_t version_no;
+ const tT2T_INIT_TAG* p_ret;
+ uint8_t tms;
+ uint8_t next_block = T2T_FIRST_DATA_BLOCK + 1;
+ uint16_t addr, locked_area;
+ bool b_notify = false;
+ p = p_t2t->ndef_final_block;
+ UINT8_TO_BE_STREAM(p, p_t2t->tlv_value[2]);
- p = p_t2t->ndef_final_block;
- UINT8_TO_BE_STREAM (p, p_t2t->tlv_value[2]);
-
- switch (p_t2t->substate)
- {
+ switch (p_t2t->substate) {
case RW_T2T_SUBSTATE_WAIT_READ_CC:
- /* Start format operation */
- status = rw_t2t_format_tag ();
- break;
+ /* Start format operation */
+ status = rw_t2t_format_tag();
+ break;
case RW_T2T_SUBSTATE_WAIT_READ_VERSION_INFO:
- memcpy (p_t2t->tag_data, p_data, T2T_READ_DATA_LEN);
- p_t2t->b_read_data = true;
- version_no = (uint16_t) p_data[0] << 8 | p_data[1];
- if ((p_ret = t2t_tag_init_data (p_t2t->tag_hdr[0], true, version_no)) != NULL)
- {
- /* Valid Version Number */
- if (p_ret->b_calc_cc)
- /* Calculate tag size from Version Information */
- tms = rw_t2t_get_tag_size (p_data);
+ memcpy(p_t2t->tag_data, p_data, T2T_READ_DATA_LEN);
+ p_t2t->b_read_data = true;
+ version_no = (uint16_t)p_data[0] << 8 | p_data[1];
+ if ((p_ret = t2t_tag_init_data(p_t2t->tag_hdr[0], true, version_no)) !=
+ NULL) {
+ /* Valid Version Number */
+ if (p_ret->b_calc_cc) /* Calculate tag size from Version Information */
+ tms = rw_t2t_get_tag_size(p_data);
- else
- /* Tag size from Look up table */
- tms = p_ret->tms;
+ else
+ /* Tag size from Look up table */
+ tms = p_ret->tms;
- /* Set CC with the Tag size from look up table or from calculated value */
- status = rw_t2t_set_cc (tms);
- }
- break;
+ /* Set CC with the Tag size from look up table or from calculated value
+ */
+ status = rw_t2t_set_cc(tms);
+ }
+ break;
case RW_T2T_SUBSTATE_WAIT_SET_CC:
- version_no = (uint16_t) p_t2t->tag_data[0] << 8 | p_t2t->tag_data[1];
- if ( (version_no == 0)
- ||((p_ret = t2t_tag_init_data (p_t2t->tag_hdr[0], true, version_no)) == NULL)
- ||(!p_ret->b_multi_version)
- ||(!p_ret->b_calc_cc) )
- {
- /* Currently Formating a non blank tag or a blank tag with manufacturer
- * has only one variant of tag. Set Null NDEF TLV and complete Format Operation */
- next_block = T2T_FIRST_DATA_BLOCK;
- p = p_t2t->ndef_final_block;
- }
- else
- {
- addr = (uint16_t) (((uint16_t) p_t2t->tag_data[2] << 8 | p_t2t->tag_data[3]) * ((uint16_t) p_t2t->tag_data[4] << 8 | p_t2t->tag_data[5]) + T2T_STATIC_SIZE);
- locked_area = ((uint16_t) p_t2t->tag_data[2] << 8 | p_t2t->tag_data[3]) * ((uint16_t) p_t2t->tag_data[6]);
+ version_no = (uint16_t)p_t2t->tag_data[0] << 8 | p_t2t->tag_data[1];
+ if ((version_no == 0) ||
+ ((p_ret = t2t_tag_init_data(p_t2t->tag_hdr[0], true, version_no)) ==
+ NULL) ||
+ (!p_ret->b_multi_version) || (!p_ret->b_calc_cc)) {
+ /* Currently Formating a non blank tag or a blank tag with manufacturer
+ * has only one variant of tag. Set Null NDEF TLV and complete Format
+ * Operation */
+ next_block = T2T_FIRST_DATA_BLOCK;
+ p = p_t2t->ndef_final_block;
+ } else {
+ addr = (uint16_t)(
+ ((uint16_t)p_t2t->tag_data[2] << 8 | p_t2t->tag_data[3]) *
+ ((uint16_t)p_t2t->tag_data[4] << 8 | p_t2t->tag_data[5]) +
+ T2T_STATIC_SIZE);
+ locked_area = ((uint16_t)p_t2t->tag_data[2] << 8 | p_t2t->tag_data[3]) *
+ ((uint16_t)p_t2t->tag_data[6]);
- if ((status = rw_t2t_set_lock_tlv (addr, p_t2t->tag_data[7], locked_area)) == NFC_STATUS_REJECTED)
- {
- /* Cannot calculate Lock TLV. Set Null NDEF TLV and complete Format Operation */
- next_block = T2T_FIRST_DATA_BLOCK;
- p = p_t2t->ndef_final_block;
- }
- else
- break;
- }
+ if ((status =
+ rw_t2t_set_lock_tlv(addr, p_t2t->tag_data[7], locked_area)) ==
+ NFC_STATUS_REJECTED) {
+ /* Cannot calculate Lock TLV. Set Null NDEF TLV and complete Format
+ * Operation */
+ next_block = T2T_FIRST_DATA_BLOCK;
+ p = p_t2t->ndef_final_block;
+ } else
+ break;
+ }
- /* falls through */
+ /* falls through */
case RW_T2T_SUBSTATE_WAIT_SET_LOCK_TLV:
- /* Prepare NULL NDEF TLV, TERMINATOR_TLV */
- UINT8_TO_BE_STREAM (p, TAG_NDEF_TLV);
- UINT8_TO_BE_STREAM (p, 0);
+ /* Prepare NULL NDEF TLV, TERMINATOR_TLV */
+ UINT8_TO_BE_STREAM(p, TAG_NDEF_TLV);
+ UINT8_TO_BE_STREAM(p, 0);
- if ( ((p_ret = t2t_tag_init_data (p_t2t->tag_hdr[0], false, 0)) != NULL)
- &&(!p_ret->b_otp) )
- {
- UINT8_TO_BE_STREAM (p, TAG_TERMINATOR_TLV);
- }
- else
- UINT8_TO_BE_STREAM (p, 0);
+ if (((p_ret = t2t_tag_init_data(p_t2t->tag_hdr[0], false, 0)) != NULL) &&
+ (!p_ret->b_otp)) {
+ UINT8_TO_BE_STREAM(p, TAG_TERMINATOR_TLV);
+ } else
+ UINT8_TO_BE_STREAM(p, 0);
- p_t2t->substate = RW_T2T_SUBSTATE_WAIT_SET_NULL_NDEF;
- /* send WRITE-E8 command */
- if ((status = rw_t2t_write (next_block, p_t2t->ndef_final_block)) == NFC_STATUS_OK)
- p_t2t->b_read_data = false;
- break;
+ p_t2t->substate = RW_T2T_SUBSTATE_WAIT_SET_NULL_NDEF;
+ /* send WRITE-E8 command */
+ if ((status = rw_t2t_write(next_block, p_t2t->ndef_final_block)) ==
+ NFC_STATUS_OK)
+ p_t2t->b_read_data = false;
+ break;
case RW_T2T_SUBSTATE_WAIT_SET_NULL_NDEF:
- /* Tag Formated successfully */
- status = NFC_STATUS_OK;
- b_notify = true;
- break;
+ /* Tag Formated successfully */
+ status = NFC_STATUS_OK;
+ b_notify = true;
+ break;
default:
- break;
+ break;
+ }
- }
-
- if (status != NFC_STATUS_OK || b_notify)
- {
- /* Notify upper layer the result of Format op */
- evt.status = status;
- rw_t2t_handle_op_complete ();
- (*rw_cb.p_cback) (RW_T2T_FORMAT_CPLT_EVT, (tRW_DATA *) &evt);
- }
-
+ if (status != NFC_STATUS_OK || b_notify) {
+ /* Notify upper layer the result of Format op */
+ evt.status = status;
+ rw_t2t_handle_op_complete();
+ (*rw_cb.p_cback)(RW_T2T_FORMAT_CPLT_EVT, (tRW_DATA*)&evt);
+ }
}
/*******************************************************************************
@@ -2068,66 +1909,67 @@
** Returns None
**
*******************************************************************************/
-static void rw_t2t_update_attributes (void)
-{
- uint8_t count = 0;
- tRW_T2T_CB *p_t2t = &rw_cb.tcb.t2t;
- uint16_t lower_offset;
- uint16_t upper_offset;
- uint16_t offset;
- uint8_t num_bytes;
+static void rw_t2t_update_attributes(void) {
+ uint8_t count = 0;
+ tRW_T2T_CB* p_t2t = &rw_cb.tcb.t2t;
+ uint16_t lower_offset;
+ uint16_t upper_offset;
+ uint16_t offset;
+ uint8_t num_bytes;
- /* Prepare attr for the current segment */
- memset (p_t2t->attr, 0, RW_T2T_SEGMENT_SIZE * sizeof (uint8_t));
+ /* Prepare attr for the current segment */
+ memset(p_t2t->attr, 0, RW_T2T_SEGMENT_SIZE * sizeof(uint8_t));
- /* calculate offset where the current segment starts in the tag */
- lower_offset = p_t2t->segment * RW_T2T_SEGMENT_BYTES;
- /* calculate offset where the current segment ends in the tag */
- upper_offset = (p_t2t->segment + 1) * RW_T2T_SEGMENT_BYTES;
+ /* calculate offset where the current segment starts in the tag */
+ lower_offset = p_t2t->segment * RW_T2T_SEGMENT_BYTES;
+ /* calculate offset where the current segment ends in the tag */
+ upper_offset = (p_t2t->segment + 1) * RW_T2T_SEGMENT_BYTES;
-
- /* check offset of lock bytes in the tag and update p_t2t->attr
- * for every lock byte that is present in the current segment */
- count = 0;
- while (count < p_t2t->num_lockbytes)
- {
- offset = p_t2t->lock_tlv[p_t2t->lockbyte[count].tlv_index].offset + p_t2t->lockbyte[count].byte_index;
- if (offset >= lower_offset && offset < upper_offset)
- {
- /* Calculate offset in the current segment as p_t2t->attr is prepared for one segment only */
- offset %= RW_T2T_SEGMENT_BYTES;
- /* Every bit in p_t2t->attr indicates one byte of the tag is either a lock/reserved byte or not
- * So, each array element in p_t2t->attr covers two blocks in the tag as T2 block size is 4 and array element size is 8
- * Set the corresponding bit in attr to indicate - reserved byte */
- p_t2t->attr[offset / TAG_BITS_PER_BYTE] |= rw_t2t_mask_bits[offset % TAG_BITS_PER_BYTE];
- }
- count++;
+ /* check offset of lock bytes in the tag and update p_t2t->attr
+ * for every lock byte that is present in the current segment */
+ count = 0;
+ while (count < p_t2t->num_lockbytes) {
+ offset = p_t2t->lock_tlv[p_t2t->lockbyte[count].tlv_index].offset +
+ p_t2t->lockbyte[count].byte_index;
+ if (offset >= lower_offset && offset < upper_offset) {
+ /* Calculate offset in the current segment as p_t2t->attr is prepared for
+ * one segment only */
+ offset %= RW_T2T_SEGMENT_BYTES;
+ /* Every bit in p_t2t->attr indicates one byte of the tag is either a
+ * lock/reserved byte or not
+ * So, each array element in p_t2t->attr covers two blocks in the tag as
+ * T2 block size is 4 and array element size is 8
+ * Set the corresponding bit in attr to indicate - reserved byte */
+ p_t2t->attr[offset / TAG_BITS_PER_BYTE] |=
+ rw_t2t_mask_bits[offset % TAG_BITS_PER_BYTE];
}
+ count++;
+ }
-
- /* Search reserved bytes identified by all memory tlvs present in the tag */
- count = 0;
- while (count < p_t2t->num_mem_tlvs)
- {
- /* check the offset of reserved bytes in the tag and update p_t2t->attr
- * for every reserved byte that is present in the current segment */
- num_bytes = 0;
- while (num_bytes < p_t2t->mem_tlv[count].num_bytes)
- {
- offset = p_t2t->mem_tlv[count].offset + num_bytes;
- if (offset >= lower_offset && offset < upper_offset)
- {
- /* Let offset represents offset in the current segment as p_t2t->attr is prepared for one segment only */
- offset %= RW_T2T_SEGMENT_BYTES;
- /* Every bit in p_t2t->attr indicates one byte of the tag is either a lock/reserved byte or not
- * So, each array element in p_t2t->attr covers two blocks in the tag as T2 block size is 4 and array element size is 8
- * Set the corresponding bit in attr to indicate - reserved byte */
- p_t2t->attr[offset /TAG_BITS_PER_BYTE] |= rw_t2t_mask_bits[offset % TAG_BITS_PER_BYTE];
- }
- num_bytes++;
- }
- count++;
+ /* Search reserved bytes identified by all memory tlvs present in the tag */
+ count = 0;
+ while (count < p_t2t->num_mem_tlvs) {
+ /* check the offset of reserved bytes in the tag and update p_t2t->attr
+ * for every reserved byte that is present in the current segment */
+ num_bytes = 0;
+ while (num_bytes < p_t2t->mem_tlv[count].num_bytes) {
+ offset = p_t2t->mem_tlv[count].offset + num_bytes;
+ if (offset >= lower_offset && offset < upper_offset) {
+ /* Let offset represents offset in the current segment as p_t2t->attr is
+ * prepared for one segment only */
+ offset %= RW_T2T_SEGMENT_BYTES;
+ /* Every bit in p_t2t->attr indicates one byte of the tag is either a
+ * lock/reserved byte or not
+ * So, each array element in p_t2t->attr covers two blocks in the tag as
+ * T2 block size is 4 and array element size is 8
+ * Set the corresponding bit in attr to indicate - reserved byte */
+ p_t2t->attr[offset / TAG_BITS_PER_BYTE] |=
+ rw_t2t_mask_bits[offset % TAG_BITS_PER_BYTE];
+ }
+ num_bytes++;
}
+ count++;
+ }
}
/*******************************************************************************
@@ -2149,115 +1991,126 @@
** Returns Total number of lock bits assigned to the specified segment
**
*******************************************************************************/
-static uint8_t rw_t2t_get_lock_bits_for_segment (uint8_t segment, uint8_t *p_start_byte, uint8_t *p_start_bit, uint8_t *p_end_byte)
-{
- uint8_t total_bits = 0;
- uint16_t byte_count = 0;
- uint16_t lower_offset, upper_offset;
- uint8_t num_dynamic_locks = 0;
- uint8_t bit_count = 0;
- uint8_t bytes_locked_per_bit;
- uint8_t num_bits;
- tRW_T2T_CB *p_t2t = &rw_cb.tcb.t2t;
- bool b_all_bits_are_locks = true;
- uint16_t tag_size;
- uint8_t xx;
+static uint8_t rw_t2t_get_lock_bits_for_segment(uint8_t segment,
+ uint8_t* p_start_byte,
+ uint8_t* p_start_bit,
+ uint8_t* p_end_byte) {
+ uint8_t total_bits = 0;
+ uint16_t byte_count = 0;
+ uint16_t lower_offset, upper_offset;
+ uint8_t num_dynamic_locks = 0;
+ uint8_t bit_count = 0;
+ uint8_t bytes_locked_per_bit;
+ uint8_t num_bits;
+ tRW_T2T_CB* p_t2t = &rw_cb.tcb.t2t;
+ bool b_all_bits_are_locks = true;
+ uint16_t tag_size;
+ uint8_t xx;
- tag_size = (p_t2t->tag_hdr[T2T_CC2_TMS_BYTE] * T2T_TMS_TAG_FACTOR) + (T2T_FIRST_DATA_BLOCK * T2T_BLOCK_SIZE) + p_t2t->num_lockbytes;
+ tag_size = (p_t2t->tag_hdr[T2T_CC2_TMS_BYTE] * T2T_TMS_TAG_FACTOR) +
+ (T2T_FIRST_DATA_BLOCK * T2T_BLOCK_SIZE) + p_t2t->num_lockbytes;
- for (xx = 0; xx < p_t2t->num_mem_tlvs; xx++)
- tag_size += p_t2t->mem_tlv[xx].num_bytes;
+ for (xx = 0; xx < p_t2t->num_mem_tlvs; xx++)
+ tag_size += p_t2t->mem_tlv[xx].num_bytes;
- lower_offset = segment * RW_T2T_SEGMENT_BYTES;
- if (segment == 0)
- {
- lower_offset += T2T_STATIC_SIZE;
- }
- upper_offset = (segment + 1) * RW_T2T_SEGMENT_BYTES;
+ lower_offset = segment * RW_T2T_SEGMENT_BYTES;
+ if (segment == 0) {
+ lower_offset += T2T_STATIC_SIZE;
+ }
+ upper_offset = (segment + 1) * RW_T2T_SEGMENT_BYTES;
- byte_count = T2T_STATIC_SIZE;
- if (tag_size < upper_offset)
- {
- upper_offset = tag_size;
- }
+ byte_count = T2T_STATIC_SIZE;
+ if (tag_size < upper_offset) {
+ upper_offset = tag_size;
+ }
- *p_start_byte = num_dynamic_locks;
- *p_start_bit = 0;
+ *p_start_byte = num_dynamic_locks;
+ *p_start_bit = 0;
- while ( (byte_count <= lower_offset)
- &&(num_dynamic_locks < p_t2t->num_lockbytes) )
- {
- bytes_locked_per_bit = p_t2t->lock_tlv[p_t2t->lockbyte[num_dynamic_locks].tlv_index].bytes_locked_per_bit;
- /* Number of bits in the current lock byte */
- b_all_bits_are_locks = ((p_t2t->lockbyte[num_dynamic_locks].byte_index + 1) * TAG_BITS_PER_BYTE <= p_t2t->lock_tlv[p_t2t->lockbyte[num_dynamic_locks].tlv_index].num_bits);
- num_bits = b_all_bits_are_locks ? TAG_BITS_PER_BYTE : p_t2t->lock_tlv[p_t2t->lockbyte[num_dynamic_locks].tlv_index].num_bits % TAG_BITS_PER_BYTE;
+ while ((byte_count <= lower_offset) &&
+ (num_dynamic_locks < p_t2t->num_lockbytes)) {
+ bytes_locked_per_bit =
+ p_t2t->lock_tlv[p_t2t->lockbyte[num_dynamic_locks].tlv_index]
+ .bytes_locked_per_bit;
+ /* Number of bits in the current lock byte */
+ b_all_bits_are_locks =
+ ((p_t2t->lockbyte[num_dynamic_locks].byte_index + 1) *
+ TAG_BITS_PER_BYTE <=
+ p_t2t->lock_tlv[p_t2t->lockbyte[num_dynamic_locks].tlv_index]
+ .num_bits);
+ num_bits =
+ b_all_bits_are_locks
+ ? TAG_BITS_PER_BYTE
+ : p_t2t->lock_tlv[p_t2t->lockbyte[num_dynamic_locks].tlv_index]
+ .num_bits %
+ TAG_BITS_PER_BYTE;
- if (((bytes_locked_per_bit * num_bits) + byte_count) <= lower_offset)
- {
- /* Skip this lock byte as it covers different segment */
- byte_count += bytes_locked_per_bit * num_bits;
- num_dynamic_locks++;
+ if (((bytes_locked_per_bit * num_bits) + byte_count) <= lower_offset) {
+ /* Skip this lock byte as it covers different segment */
+ byte_count += bytes_locked_per_bit * num_bits;
+ num_dynamic_locks++;
+ } else {
+ bit_count = 0;
+ while (bit_count < num_bits) {
+ byte_count += bytes_locked_per_bit;
+ if (byte_count > lower_offset) {
+ /* First lock bit that is used to lock this segment */
+ *p_start_byte = num_dynamic_locks;
+ *p_end_byte = num_dynamic_locks;
+ *p_start_bit = bit_count;
+ bit_count++;
+ total_bits = 1;
+ break;
}
- else
- {
- bit_count = 0;
- while (bit_count < num_bits)
- {
- byte_count += bytes_locked_per_bit;
- if (byte_count > lower_offset)
- {
- /* First lock bit that is used to lock this segment */
- *p_start_byte = num_dynamic_locks;
- *p_end_byte = num_dynamic_locks;
- *p_start_bit = bit_count;
- bit_count++;
- total_bits = 1;
- break;
- }
- bit_count++;
- }
- }
+ bit_count++;
+ }
}
- if (num_dynamic_locks == p_t2t->num_lockbytes)
- {
- return 0;
- }
- while ( (byte_count < upper_offset)
- &&(num_dynamic_locks < p_t2t->num_lockbytes) )
- {
- bytes_locked_per_bit = p_t2t->lock_tlv[p_t2t->lockbyte[num_dynamic_locks].tlv_index].bytes_locked_per_bit;
- /* Number of bits in the current lock byte */
- b_all_bits_are_locks = ((p_t2t->lockbyte[num_dynamic_locks].byte_index + 1) * TAG_BITS_PER_BYTE <= p_t2t->lock_tlv[p_t2t->lockbyte[num_dynamic_locks].tlv_index].num_bits);
- num_bits = b_all_bits_are_locks ? TAG_BITS_PER_BYTE : p_t2t->lock_tlv[p_t2t->lockbyte[num_dynamic_locks].tlv_index].num_bits % TAG_BITS_PER_BYTE;
+ }
+ if (num_dynamic_locks == p_t2t->num_lockbytes) {
+ return 0;
+ }
+ while ((byte_count < upper_offset) &&
+ (num_dynamic_locks < p_t2t->num_lockbytes)) {
+ bytes_locked_per_bit =
+ p_t2t->lock_tlv[p_t2t->lockbyte[num_dynamic_locks].tlv_index]
+ .bytes_locked_per_bit;
+ /* Number of bits in the current lock byte */
+ b_all_bits_are_locks =
+ ((p_t2t->lockbyte[num_dynamic_locks].byte_index + 1) *
+ TAG_BITS_PER_BYTE <=
+ p_t2t->lock_tlv[p_t2t->lockbyte[num_dynamic_locks].tlv_index]
+ .num_bits);
+ num_bits =
+ b_all_bits_are_locks
+ ? TAG_BITS_PER_BYTE
+ : p_t2t->lock_tlv[p_t2t->lockbyte[num_dynamic_locks].tlv_index]
+ .num_bits %
+ TAG_BITS_PER_BYTE;
- if ((bytes_locked_per_bit * (num_bits - bit_count)) + byte_count < upper_offset)
- {
- /* Collect all lock bits that covers the current segment */
- byte_count += bytes_locked_per_bit * (num_bits - bit_count);
- total_bits += num_bits - bit_count;
- bit_count = 0;
- *p_end_byte = num_dynamic_locks;
- num_dynamic_locks++;
+ if ((bytes_locked_per_bit * (num_bits - bit_count)) + byte_count <
+ upper_offset) {
+ /* Collect all lock bits that covers the current segment */
+ byte_count += bytes_locked_per_bit * (num_bits - bit_count);
+ total_bits += num_bits - bit_count;
+ bit_count = 0;
+ *p_end_byte = num_dynamic_locks;
+ num_dynamic_locks++;
+ } else {
+ /* The last lock byte that covers the current segment */
+ bit_count = 0;
+ while (bit_count < num_bits) {
+ /* The last lock bit that is used to lock this segment */
+ byte_count += bytes_locked_per_bit;
+ if (byte_count >= upper_offset) {
+ *p_end_byte = num_dynamic_locks;
+ total_bits += (bit_count + 1);
+ break;
}
- else
- {
- /* The last lock byte that covers the current segment */
- bit_count = 0;
- while (bit_count < num_bits)
- {
- /* The last lock bit that is used to lock this segment */
- byte_count += bytes_locked_per_bit;
- if (byte_count >= upper_offset)
- {
- *p_end_byte = num_dynamic_locks;
- total_bits += (bit_count + 1);
- break;
- }
- bit_count++;
- }
- }
+ bit_count++;
+ }
}
- return total_bits;
+ }
+ return total_bits;
}
/*******************************************************************************
@@ -2275,109 +2128,115 @@
** FALSE, otherwise
**
*******************************************************************************/
-static void rw_t2t_update_lock_attributes (void)
-{
- tRW_T2T_CB *p_t2t = &rw_cb.tcb.t2t;
- uint8_t xx = 0;
- uint8_t num_static_lock_bytes = 0;
- uint8_t num_dyn_lock_bytes = 0;
- uint8_t bits_covered = 0;
- uint8_t bytes_covered = 0;
- uint8_t block_count = 0;
- bool b_all_bits_are_locks = true;
- uint8_t bytes_locked_per_lock_bit;
- uint8_t start_lock_byte;
- uint8_t start_lock_bit;
- uint8_t end_lock_byte;
- uint8_t num_lock_bits;
- uint8_t total_bits;
+static void rw_t2t_update_lock_attributes(void) {
+ tRW_T2T_CB* p_t2t = &rw_cb.tcb.t2t;
+ uint8_t xx = 0;
+ uint8_t num_static_lock_bytes = 0;
+ uint8_t num_dyn_lock_bytes = 0;
+ uint8_t bits_covered = 0;
+ uint8_t bytes_covered = 0;
+ uint8_t block_count = 0;
+ bool b_all_bits_are_locks = true;
+ uint8_t bytes_locked_per_lock_bit;
+ uint8_t start_lock_byte;
+ uint8_t start_lock_bit;
+ uint8_t end_lock_byte;
+ uint8_t num_lock_bits;
+ uint8_t total_bits;
+ /* Prepare lock_attr for the current segment */
+ memset(p_t2t->lock_attr, 0, RW_T2T_SEGMENT_SIZE * sizeof(uint8_t));
- /* Prepare lock_attr for the current segment */
- memset (p_t2t->lock_attr, 0, RW_T2T_SEGMENT_SIZE * sizeof (uint8_t));
+ block_count = 0;
+ if (p_t2t->segment == 0) {
+ /* Update lock_attributes based on static lock bytes */
+ xx = 0;
+ num_static_lock_bytes = 0;
+ block_count = 0;
+ num_lock_bits =
+ TAG_BITS_PER_BYTE - 1; /* the inner while loop increases xx by 2. need
+ (-1) to avoid coverity overrun error */
- block_count = 0;
- if (p_t2t->segment == 0)
- {
- /* Update lock_attributes based on static lock bytes */
- xx = 0;
- num_static_lock_bytes = 0;
- block_count = 0;
- num_lock_bits = TAG_BITS_PER_BYTE - 1; /* the inner while loop increases xx by 2. need (-1) to avoid coverity overrun error */
+ while (num_static_lock_bytes < T2T_NUM_STATIC_LOCK_BYTES) {
+ /* Update lock attribute based on 2 static locks */
+ while (xx < num_lock_bits) {
+ p_t2t->lock_attr[block_count] = 0x00;
- while (num_static_lock_bytes < T2T_NUM_STATIC_LOCK_BYTES)
- {
- /* Update lock attribute based on 2 static locks */
- while (xx < num_lock_bits)
- {
- p_t2t->lock_attr[block_count] = 0x00;
-
- if (p_t2t->tag_hdr[T2T_STATIC_LOCK0 + num_static_lock_bytes] & rw_t2t_mask_bits[xx++])
- {
- /* If the bit is set then 1 block is locked */
- p_t2t->lock_attr[block_count] = 0x0F;
- }
-
- if (p_t2t->tag_hdr[T2T_STATIC_LOCK0 + num_static_lock_bytes] & rw_t2t_mask_bits[xx++])
- {
- /* If the bit is set then 1 block is locked */
- p_t2t->lock_attr[block_count] |= 0xF0;
- }
- block_count++;
- }
- num_static_lock_bytes++;
- xx = 0;
+ if (p_t2t->tag_hdr[T2T_STATIC_LOCK0 + num_static_lock_bytes] &
+ rw_t2t_mask_bits[xx++]) {
+ /* If the bit is set then 1 block is locked */
+ p_t2t->lock_attr[block_count] = 0x0F;
}
- /* UID is always locked, irrespective of the lock value */
- p_t2t->lock_attr[0x00] = 0xFF;
- }
- /* Get lock bits applicable for the current segment */
- if ((total_bits = rw_t2t_get_lock_bits_for_segment (p_t2t->segment,&start_lock_byte, &start_lock_bit, &end_lock_byte)) != 0)
- {
- /* update lock_attributes based on current segment using dynamic lock bytes */
- xx = start_lock_bit;
- num_dyn_lock_bytes = start_lock_byte;
- bits_covered = 0;
- bytes_covered = 0;
- num_lock_bits = TAG_BITS_PER_BYTE;
- p_t2t->lock_attr[block_count] = 0;
-
- while (num_dyn_lock_bytes <= end_lock_byte)
- {
- bytes_locked_per_lock_bit = p_t2t->lock_tlv[p_t2t->lockbyte[num_dyn_lock_bytes].tlv_index].bytes_locked_per_bit;
- /* Find number of bits in the byte are lock bits */
- b_all_bits_are_locks = ((p_t2t->lockbyte[num_dyn_lock_bytes].byte_index + 1) * TAG_BITS_PER_BYTE <= p_t2t->lock_tlv[p_t2t->lockbyte[num_dyn_lock_bytes].tlv_index].num_bits);
- num_lock_bits = b_all_bits_are_locks ? TAG_BITS_PER_BYTE : p_t2t->lock_tlv[p_t2t->lockbyte[num_dyn_lock_bytes].tlv_index].num_bits % TAG_BITS_PER_BYTE;
-
- while (xx < num_lock_bits)
- {
- bytes_covered = 0;
- while (bytes_covered < bytes_locked_per_lock_bit)
- {
- if (p_t2t->lockbyte[num_dyn_lock_bytes].lock_byte & rw_t2t_mask_bits[xx])
- {
- /* If the bit is set then it is locked */
- p_t2t->lock_attr[block_count] |= 0x01 << bits_covered;
- }
- bytes_covered++;
- bits_covered++;
- if (bits_covered == TAG_BITS_PER_BYTE)
- {
- /* Move to next 8 bytes */
- bits_covered = 0;
- block_count++;
- /* Assume unlocked before updating using locks */
- if (block_count < RW_T2T_SEGMENT_SIZE)
- p_t2t->lock_attr[block_count] = 0;
- }
- }
- xx++;
- }
- num_dyn_lock_bytes++;
- xx = 0;
+ if (p_t2t->tag_hdr[T2T_STATIC_LOCK0 + num_static_lock_bytes] &
+ rw_t2t_mask_bits[xx++]) {
+ /* If the bit is set then 1 block is locked */
+ p_t2t->lock_attr[block_count] |= 0xF0;
}
+ block_count++;
+ }
+ num_static_lock_bytes++;
+ xx = 0;
}
+ /* UID is always locked, irrespective of the lock value */
+ p_t2t->lock_attr[0x00] = 0xFF;
+ }
+
+ /* Get lock bits applicable for the current segment */
+ if ((total_bits = rw_t2t_get_lock_bits_for_segment(
+ p_t2t->segment, &start_lock_byte, &start_lock_bit,
+ &end_lock_byte)) != 0) {
+ /* update lock_attributes based on current segment using dynamic lock bytes
+ */
+ xx = start_lock_bit;
+ num_dyn_lock_bytes = start_lock_byte;
+ bits_covered = 0;
+ bytes_covered = 0;
+ num_lock_bits = TAG_BITS_PER_BYTE;
+ p_t2t->lock_attr[block_count] = 0;
+
+ while (num_dyn_lock_bytes <= end_lock_byte) {
+ bytes_locked_per_lock_bit =
+ p_t2t->lock_tlv[p_t2t->lockbyte[num_dyn_lock_bytes].tlv_index]
+ .bytes_locked_per_bit;
+ /* Find number of bits in the byte are lock bits */
+ b_all_bits_are_locks =
+ ((p_t2t->lockbyte[num_dyn_lock_bytes].byte_index + 1) *
+ TAG_BITS_PER_BYTE <=
+ p_t2t->lock_tlv[p_t2t->lockbyte[num_dyn_lock_bytes].tlv_index]
+ .num_bits);
+ num_lock_bits =
+ b_all_bits_are_locks
+ ? TAG_BITS_PER_BYTE
+ : p_t2t->lock_tlv[p_t2t->lockbyte[num_dyn_lock_bytes].tlv_index]
+ .num_bits %
+ TAG_BITS_PER_BYTE;
+
+ while (xx < num_lock_bits) {
+ bytes_covered = 0;
+ while (bytes_covered < bytes_locked_per_lock_bit) {
+ if (p_t2t->lockbyte[num_dyn_lock_bytes].lock_byte &
+ rw_t2t_mask_bits[xx]) {
+ /* If the bit is set then it is locked */
+ p_t2t->lock_attr[block_count] |= 0x01 << bits_covered;
+ }
+ bytes_covered++;
+ bits_covered++;
+ if (bits_covered == TAG_BITS_PER_BYTE) {
+ /* Move to next 8 bytes */
+ bits_covered = 0;
+ block_count++;
+ /* Assume unlocked before updating using locks */
+ if (block_count < RW_T2T_SEGMENT_SIZE)
+ p_t2t->lock_attr[block_count] = 0;
+ }
+ }
+ xx++;
+ }
+ num_dyn_lock_bytes++;
+ xx = 0;
+ }
+ }
}
/*******************************************************************************
@@ -2396,26 +2255,29 @@
** FALSE, otherwise
**
*******************************************************************************/
-static bool rw_t2t_is_lock_res_byte (uint16_t index)
-{
- tRW_T2T_CB *p_t2t = &rw_cb.tcb.t2t;
+static bool rw_t2t_is_lock_res_byte(uint16_t index) {
+ tRW_T2T_CB* p_t2t = &rw_cb.tcb.t2t;
- p_t2t->segment = (uint8_t) (index / RW_T2T_SEGMENT_BYTES);
+ p_t2t->segment = (uint8_t)(index / RW_T2T_SEGMENT_BYTES);
- if (p_t2t->attr_seg != p_t2t->segment)
- {
- /* Update attributes for the current segment */
- rw_t2t_update_attributes ();
- p_t2t->attr_seg = p_t2t->segment;
- }
+ if (p_t2t->attr_seg != p_t2t->segment) {
+ /* Update attributes for the current segment */
+ rw_t2t_update_attributes();
+ p_t2t->attr_seg = p_t2t->segment;
+ }
- index = index % RW_T2T_SEGMENT_BYTES;
- /* Every bit in p_t2t->attr indicates one specific byte of the tag is either a lock/reserved byte or not
- * So, each array element in p_t2t->attr covers two blocks in the tag as T2 block size is 4 and array element size is 8
- * Find the block and offset for the index (passed as argument) and Check if the offset bit in the
- * p_t2t->attr[block/2] is set or not. If the bit is set then it is a lock/reserved byte, otherwise not */
+ index = index % RW_T2T_SEGMENT_BYTES;
+ /* Every bit in p_t2t->attr indicates one specific byte of the tag is either a
+ * lock/reserved byte or not
+ * So, each array element in p_t2t->attr covers two blocks in the tag as T2
+ * block size is 4 and array element size is 8
+ * Find the block and offset for the index (passed as argument) and Check if
+ * the offset bit in the
+ * p_t2t->attr[block/2] is set or not. If the bit is set then it is a
+ * lock/reserved byte, otherwise not */
- return ((p_t2t->attr[index / 8] & rw_t2t_mask_bits[index % 8]) == 0) ? false : true;
+ return ((p_t2t->attr[index / 8] & rw_t2t_mask_bits[index % 8]) == 0) ? false
+ : true;
}
/*******************************************************************************
@@ -2434,26 +2296,30 @@
** FALSE, otherwise
**
*******************************************************************************/
-static bool rw_t2t_is_read_only_byte (uint16_t index)
-{
- tRW_T2T_CB *p_t2t = &rw_cb.tcb.t2t;
+static bool rw_t2t_is_read_only_byte(uint16_t index) {
+ tRW_T2T_CB* p_t2t = &rw_cb.tcb.t2t;
- p_t2t->segment = (uint8_t) (index / RW_T2T_SEGMENT_BYTES);
+ p_t2t->segment = (uint8_t)(index / RW_T2T_SEGMENT_BYTES);
- if (p_t2t->lock_attr_seg != p_t2t->segment)
- {
- /* Update lock attributes for the current segment */
- rw_t2t_update_lock_attributes ();
- p_t2t->lock_attr_seg = p_t2t->segment;
- }
+ if (p_t2t->lock_attr_seg != p_t2t->segment) {
+ /* Update lock attributes for the current segment */
+ rw_t2t_update_lock_attributes();
+ p_t2t->lock_attr_seg = p_t2t->segment;
+ }
- index = index % RW_T2T_SEGMENT_BYTES;
- /* Every bit in p_t2t->lock_attr indicates one specific byte of the tag is a read only byte or read write byte
- * So, each array element in p_t2t->lock_attr covers two blocks of the tag as T2 block size is 4 and array element size is 8
- * Find the block and offset for the index (passed as argument) and Check if the offset bit in
- * p_t2t->lock_attr[block/2] is set or not. If the bit is set then it is a read only byte, otherwise read write byte */
+ index = index % RW_T2T_SEGMENT_BYTES;
+ /* Every bit in p_t2t->lock_attr indicates one specific byte of the tag is a
+ * read only byte or read write byte
+ * So, each array element in p_t2t->lock_attr covers two blocks of the tag as
+ * T2 block size is 4 and array element size is 8
+ * Find the block and offset for the index (passed as argument) and Check if
+ * the offset bit in
+ * p_t2t->lock_attr[block/2] is set or not. If the bit is set then it is a
+ * read only byte, otherwise read write byte */
- return ((p_t2t->lock_attr[index / 8] & rw_t2t_mask_bits[index % 8]) == 0) ? false : true;
+ return ((p_t2t->lock_attr[index / 8] & rw_t2t_mask_bits[index % 8]) == 0)
+ ? false
+ : true;
}
/*******************************************************************************
@@ -2468,74 +2334,85 @@
** NFC_STATUS_FAILED: otherwise
**
*******************************************************************************/
-tNFC_STATUS rw_t2t_set_dynamic_lock_bits (uint8_t *p_data)
-{
- tRW_T2T_CB *p_t2t = &rw_cb.tcb.t2t;
- uint8_t write_block[T2T_BLOCK_SIZE];
- uint16_t offset;
- uint16_t next_offset;
- uint8_t num_bits;
- uint8_t next_num_bits;
- tNFC_STATUS status = NFC_STATUS_FAILED;
- uint8_t num_locks;
- uint8_t lock_count;
- bool b_all_bits_are_locks = true;
+tNFC_STATUS rw_t2t_set_dynamic_lock_bits(uint8_t* p_data) {
+ tRW_T2T_CB* p_t2t = &rw_cb.tcb.t2t;
+ uint8_t write_block[T2T_BLOCK_SIZE];
+ uint16_t offset;
+ uint16_t next_offset;
+ uint8_t num_bits;
+ uint8_t next_num_bits;
+ tNFC_STATUS status = NFC_STATUS_FAILED;
+ uint8_t num_locks;
+ uint8_t lock_count;
+ bool b_all_bits_are_locks = true;
- num_locks = 0;
+ num_locks = 0;
- memcpy (write_block, p_data, T2T_BLOCK_SIZE);
- while (num_locks < p_t2t->num_lockbytes)
- {
- if (p_t2t->lockbyte[num_locks].lock_status == RW_T2T_LOCK_NOT_UPDATED)
- {
- offset = p_t2t->lock_tlv[p_t2t->lockbyte[num_locks].tlv_index].offset + p_t2t->lockbyte[num_locks].byte_index;
+ memcpy(write_block, p_data, T2T_BLOCK_SIZE);
+ while (num_locks < p_t2t->num_lockbytes) {
+ if (p_t2t->lockbyte[num_locks].lock_status == RW_T2T_LOCK_NOT_UPDATED) {
+ offset = p_t2t->lock_tlv[p_t2t->lockbyte[num_locks].tlv_index].offset +
+ p_t2t->lockbyte[num_locks].byte_index;
- /* Check if all bits are lock bits in the byte */
- b_all_bits_are_locks = ((p_t2t->lockbyte[num_locks].byte_index + 1) * TAG_BITS_PER_BYTE <= p_t2t->lock_tlv[p_t2t->lockbyte[num_locks].tlv_index].num_bits);
- num_bits = b_all_bits_are_locks ? TAG_BITS_PER_BYTE : p_t2t->lock_tlv[p_t2t->lockbyte[num_locks].tlv_index].num_bits % TAG_BITS_PER_BYTE;
+ /* Check if all bits are lock bits in the byte */
+ b_all_bits_are_locks =
+ ((p_t2t->lockbyte[num_locks].byte_index + 1) * TAG_BITS_PER_BYTE <=
+ p_t2t->lock_tlv[p_t2t->lockbyte[num_locks].tlv_index].num_bits);
+ num_bits =
+ b_all_bits_are_locks
+ ? TAG_BITS_PER_BYTE
+ : p_t2t->lock_tlv[p_t2t->lockbyte[num_locks].tlv_index].num_bits %
+ TAG_BITS_PER_BYTE;
- write_block[(uint8_t) (offset%T2T_BLOCK_SIZE)] |= tags_pow (2,num_bits) - 1;
- lock_count = num_locks + 1;
+ write_block[(uint8_t)(offset % T2T_BLOCK_SIZE)] |=
+ tags_pow(2, num_bits) - 1;
+ lock_count = num_locks + 1;
- /* Set all the lock bits in the block using a sing block write command */
- while (lock_count < p_t2t->num_lockbytes)
- {
- next_offset = p_t2t->lock_tlv[p_t2t->lockbyte[lock_count].tlv_index].offset + p_t2t->lockbyte[lock_count].byte_index;
+ /* Set all the lock bits in the block using a sing block write command */
+ while (lock_count < p_t2t->num_lockbytes) {
+ next_offset =
+ p_t2t->lock_tlv[p_t2t->lockbyte[lock_count].tlv_index].offset +
+ p_t2t->lockbyte[lock_count].byte_index;
- /* Check if all bits are lock bits in the byte */
- b_all_bits_are_locks = ((p_t2t->lockbyte[lock_count].byte_index + 1) * TAG_BITS_PER_BYTE <= p_t2t->lock_tlv[p_t2t->lockbyte[lock_count].tlv_index].num_bits);
- next_num_bits = b_all_bits_are_locks ? TAG_BITS_PER_BYTE : p_t2t->lock_tlv[p_t2t->lockbyte[lock_count].tlv_index].num_bits % TAG_BITS_PER_BYTE;
+ /* Check if all bits are lock bits in the byte */
+ b_all_bits_are_locks =
+ ((p_t2t->lockbyte[lock_count].byte_index + 1) * TAG_BITS_PER_BYTE <=
+ p_t2t->lock_tlv[p_t2t->lockbyte[lock_count].tlv_index].num_bits);
+ next_num_bits =
+ b_all_bits_are_locks
+ ? TAG_BITS_PER_BYTE
+ : p_t2t->lock_tlv[p_t2t->lockbyte[lock_count].tlv_index]
+ .num_bits %
+ TAG_BITS_PER_BYTE;
- if (next_offset / T2T_BLOCK_SIZE == offset / T2T_BLOCK_SIZE)
- {
- write_block[(uint8_t) (next_offset % T2T_BLOCK_SIZE)] |= tags_pow (2, next_num_bits) - 1;
- }
- else
- break;
- lock_count ++;
- }
+ if (next_offset / T2T_BLOCK_SIZE == offset / T2T_BLOCK_SIZE) {
+ write_block[(uint8_t)(next_offset % T2T_BLOCK_SIZE)] |=
+ tags_pow(2, next_num_bits) - 1;
+ } else
+ break;
+ lock_count++;
+ }
- p_t2t->substate = RW_T2T_SUBSTATE_WAIT_SET_DYN_LOCK_BITS;
- /* send WRITE command to set dynamic lock bits */
- if ((status = rw_t2t_write ((uint16_t) (offset / T2T_BLOCK_SIZE), write_block)) == NFC_STATUS_OK)
- {
- while (lock_count > num_locks)
- {
- /* Set update initiated flag to indicate a write command is sent to set dynamic lock bits of the block */
- p_t2t->lockbyte[lock_count - 1].lock_status = RW_T2T_LOCK_UPDATE_INITIATED;
- lock_count --;
- }
- }
- else
- status = NFC_STATUS_FAILED;
-
- break;
-
+ p_t2t->substate = RW_T2T_SUBSTATE_WAIT_SET_DYN_LOCK_BITS;
+ /* send WRITE command to set dynamic lock bits */
+ if ((status = rw_t2t_write((uint16_t)(offset / T2T_BLOCK_SIZE),
+ write_block)) == NFC_STATUS_OK) {
+ while (lock_count > num_locks) {
+ /* Set update initiated flag to indicate a write command is sent to
+ * set dynamic lock bits of the block */
+ p_t2t->lockbyte[lock_count - 1].lock_status =
+ RW_T2T_LOCK_UPDATE_INITIATED;
+ lock_count--;
}
- num_locks++;
- }
+ } else
+ status = NFC_STATUS_FAILED;
- return status;
+ break;
+ }
+ num_locks++;
+ }
+
+ return status;
}
/*******************************************************************************
@@ -2552,60 +2429,56 @@
** NFC_STATUS_FAILED: otherwise
**
*******************************************************************************/
-tNFC_STATUS rw_t2t_set_lock_tlv (uint16_t addr, uint8_t num_dyn_lock_bits, uint16_t locked_area_size)
-{
- tNFC_STATUS status = NFC_STATUS_FAILED;
- int8_t PageAddr = 0;
- int8_t BytePerPage = 0;
- int8_t ByteOffset = 0;
- uint8_t a;
- uint8_t data_block[T2T_BLOCK_SIZE];
- tRW_T2T_CB *p_t2t = &rw_cb.tcb.t2t;
- uint8_t *p;
- uint8_t xx;
+tNFC_STATUS rw_t2t_set_lock_tlv(uint16_t addr, uint8_t num_dyn_lock_bits,
+ uint16_t locked_area_size) {
+ tNFC_STATUS status = NFC_STATUS_FAILED;
+ int8_t PageAddr = 0;
+ int8_t BytePerPage = 0;
+ int8_t ByteOffset = 0;
+ uint8_t a;
+ uint8_t data_block[T2T_BLOCK_SIZE];
+ tRW_T2T_CB* p_t2t = &rw_cb.tcb.t2t;
+ uint8_t* p;
+ uint8_t xx;
- for (xx = 15; xx >0; xx--)
- {
- a = (uint8_t) (addr / xx);
- a += (addr % xx) ? 1:0;
+ for (xx = 15; xx > 0; xx--) {
+ a = (uint8_t)(addr / xx);
+ a += (addr % xx) ? 1 : 0;
- BytePerPage = (int8_t) tags_log2 (a);
- ByteOffset = (int8_t) (addr - xx * tags_pow (2, BytePerPage));
+ BytePerPage = (int8_t)tags_log2(a);
+ ByteOffset = (int8_t)(addr - xx * tags_pow(2, BytePerPage));
- if (ByteOffset < 16)
- {
- PageAddr = xx;
- break;
- }
+ if (ByteOffset < 16) {
+ PageAddr = xx;
+ break;
}
+ }
- if ((ByteOffset < 16) && (BytePerPage < 16) && (PageAddr < 16))
- {
- memset (data_block, 0, T2T_BLOCK_SIZE);
- p = data_block;
- UINT8_TO_BE_STREAM (p, T2T_TLV_TYPE_LOCK_CTRL);
- UINT8_TO_BE_STREAM (p, T2T_TLEN_LOCK_CTRL_TLV);
- UINT8_TO_BE_STREAM (p, (PageAddr << 4 | ByteOffset));
- UINT8_TO_BE_STREAM (p, num_dyn_lock_bits);
+ if ((ByteOffset < 16) && (BytePerPage < 16) && (PageAddr < 16)) {
+ memset(data_block, 0, T2T_BLOCK_SIZE);
+ p = data_block;
+ UINT8_TO_BE_STREAM(p, T2T_TLV_TYPE_LOCK_CTRL);
+ UINT8_TO_BE_STREAM(p, T2T_TLEN_LOCK_CTRL_TLV);
+ UINT8_TO_BE_STREAM(p, (PageAddr << 4 | ByteOffset));
+ UINT8_TO_BE_STREAM(p, num_dyn_lock_bits);
- p_t2t->tlv_value[0] = PageAddr << 4 | ByteOffset;
- p_t2t->tlv_value[1] = num_dyn_lock_bits;
- p_t2t->tlv_value[2] = (uint8_t) (BytePerPage << 4 | tags_log2 (locked_area_size));
+ p_t2t->tlv_value[0] = PageAddr << 4 | ByteOffset;
+ p_t2t->tlv_value[1] = num_dyn_lock_bits;
+ p_t2t->tlv_value[2] =
+ (uint8_t)(BytePerPage << 4 | tags_log2(locked_area_size));
- p_t2t->substate = RW_T2T_SUBSTATE_WAIT_SET_LOCK_TLV;
+ p_t2t->substate = RW_T2T_SUBSTATE_WAIT_SET_LOCK_TLV;
- /* send WRITE-E8 command */
- if ((status = rw_t2t_write (T2T_FIRST_DATA_BLOCK, data_block)) == NFC_STATUS_OK)
- {
- p_t2t->b_read_data = false;
- }
- else
- p_t2t->substate = RW_T2T_SUBSTATE_NONE;
- }
- else
- status = NFC_STATUS_REJECTED;
+ /* send WRITE-E8 command */
+ if ((status = rw_t2t_write(T2T_FIRST_DATA_BLOCK, data_block)) ==
+ NFC_STATUS_OK) {
+ p_t2t->b_read_data = false;
+ } else
+ p_t2t->substate = RW_T2T_SUBSTATE_NONE;
+ } else
+ status = NFC_STATUS_REJECTED;
- return status;
+ return status;
}
/*******************************************************************************
@@ -2623,35 +2496,32 @@
** NFC_STATUS_FAILED: otherwise
**
*******************************************************************************/
-tNFC_STATUS rw_t2t_set_cc (uint8_t tms)
-{
- uint8_t cc_block[T2T_BLOCK_SIZE];
- tRW_T2T_CB *p_t2t = &rw_cb.tcb.t2t;
- tNFC_STATUS status = NFC_STATUS_FAILED;
- uint8_t *p;
+tNFC_STATUS rw_t2t_set_cc(uint8_t tms) {
+ uint8_t cc_block[T2T_BLOCK_SIZE];
+ tRW_T2T_CB* p_t2t = &rw_cb.tcb.t2t;
+ tNFC_STATUS status = NFC_STATUS_FAILED;
+ uint8_t* p;
- memset (cc_block, 0, T2T_BLOCK_SIZE);
- memset (p_t2t->ndef_final_block, 0, T2T_BLOCK_SIZE);
- p = cc_block;
+ memset(cc_block, 0, T2T_BLOCK_SIZE);
+ memset(p_t2t->ndef_final_block, 0, T2T_BLOCK_SIZE);
+ p = cc_block;
- /* Prepare Capability Container */
- UINT8_TO_BE_STREAM (p, T2T_CC0_NMN);
- UINT8_TO_BE_STREAM (p, T2T_CC1_VNO);
- UINT8_TO_BE_STREAM (p, tms);
- UINT8_TO_BE_STREAM (p, T2T_CC3_RWA_RW);
+ /* Prepare Capability Container */
+ UINT8_TO_BE_STREAM(p, T2T_CC0_NMN);
+ UINT8_TO_BE_STREAM(p, T2T_CC1_VNO);
+ UINT8_TO_BE_STREAM(p, tms);
+ UINT8_TO_BE_STREAM(p, T2T_CC3_RWA_RW);
- p_t2t->substate = RW_T2T_SUBSTATE_WAIT_SET_CC;
+ p_t2t->substate = RW_T2T_SUBSTATE_WAIT_SET_CC;
- /* send WRITE-E8 command */
- if ((status = rw_t2t_write (T2T_CC_BLOCK, cc_block)) == NFC_STATUS_OK)
- {
- p_t2t->state = RW_T2T_STATE_FORMAT_TAG;
- p_t2t->b_read_hdr = false;
- }
- else
- p_t2t->substate = RW_T2T_SUBSTATE_NONE;
+ /* send WRITE-E8 command */
+ if ((status = rw_t2t_write(T2T_CC_BLOCK, cc_block)) == NFC_STATUS_OK) {
+ p_t2t->state = RW_T2T_STATE_FORMAT_TAG;
+ p_t2t->b_read_hdr = false;
+ } else
+ p_t2t->substate = RW_T2T_SUBSTATE_NONE;
- return status;
+ return status;
}
/*******************************************************************************
@@ -2665,70 +2535,64 @@
** NFC_STATUS_FAILED: otherwise
**
*******************************************************************************/
-tNFC_STATUS rw_t2t_format_tag (void)
-{
- tRW_T2T_CB *p_t2t = &rw_cb.tcb.t2t;
- const tT2T_INIT_TAG *p_ret;
- uint8_t tms;
- tNFC_STATUS status = NFC_STATUS_FAILED;
- bool b_blank_tag = true;
+tNFC_STATUS rw_t2t_format_tag(void) {
+ tRW_T2T_CB* p_t2t = &rw_cb.tcb.t2t;
+ const tT2T_INIT_TAG* p_ret;
+ uint8_t tms;
+ tNFC_STATUS status = NFC_STATUS_FAILED;
+ bool b_blank_tag = true;
- if ((p_ret = t2t_tag_init_data (p_t2t->tag_hdr[0], false, 0)) == NULL)
- {
- RW_TRACE_WARNING1 ("rw_t2t_format_tag - Unknown Manufacturer ID: %u, Cannot Format the tag!", p_t2t->tag_hdr[0]);
- return (NFC_STATUS_FAILED);
+ if ((p_ret = t2t_tag_init_data(p_t2t->tag_hdr[0], false, 0)) == NULL) {
+ RW_TRACE_WARNING1(
+ "rw_t2t_format_tag - Unknown Manufacturer ID: %u, Cannot Format the "
+ "tag!",
+ p_t2t->tag_hdr[0]);
+ return (NFC_STATUS_FAILED);
+ }
+
+ if (p_t2t->tag_hdr[T2T_CC2_TMS_BYTE] != 0) {
+ /* If OTP tag has valid NDEF Message, cannot format the tag */
+ if ((p_t2t->ndef_msg_len > 0) && (p_ret->b_otp)) {
+ RW_TRACE_WARNING0(
+ "rw_t2t_format_tag - Cannot Format a OTP tag with NDEF Message!");
+ return (NFC_STATUS_FAILED);
}
- if (p_t2t->tag_hdr[T2T_CC2_TMS_BYTE] != 0)
- {
- /* If OTP tag has valid NDEF Message, cannot format the tag */
- if ( (p_t2t->ndef_msg_len > 0)
- &&(p_ret->b_otp) )
- {
- RW_TRACE_WARNING0 ("rw_t2t_format_tag - Cannot Format a OTP tag with NDEF Message!");
- return (NFC_STATUS_FAILED);
- }
-
- if ( ((p_t2t->tag_hdr[T2T_CC0_NMN_BYTE] != 0) && (p_t2t->tag_hdr[T2T_CC0_NMN_BYTE] != T2T_CC0_NMN))
- ||((p_t2t->tag_hdr[T2T_CC1_VNO_BYTE] != 0) && (p_t2t->tag_hdr[T2T_CC1_VNO_BYTE] != T2T_CC1_LEGACY_VNO) && (p_t2t->tag_hdr[T2T_CC1_VNO_BYTE] != T2T_CC1_VNO) && (p_t2t->tag_hdr[T2T_CC1_VNO_BYTE] != T2T_CC1_NEW_VNO)) )
- {
- RW_TRACE_WARNING0 ("rw_t2t_format_tag - Tag not blank to Format!");
- return (NFC_STATUS_FAILED);
- }
- else
- {
- tms = p_t2t->tag_hdr[T2T_CC2_TMS_BYTE];
- b_blank_tag = false;
- }
+ if (((p_t2t->tag_hdr[T2T_CC0_NMN_BYTE] != 0) &&
+ (p_t2t->tag_hdr[T2T_CC0_NMN_BYTE] != T2T_CC0_NMN)) ||
+ ((p_t2t->tag_hdr[T2T_CC1_VNO_BYTE] != 0) &&
+ (p_t2t->tag_hdr[T2T_CC1_VNO_BYTE] != T2T_CC1_LEGACY_VNO) &&
+ (p_t2t->tag_hdr[T2T_CC1_VNO_BYTE] != T2T_CC1_VNO) &&
+ (p_t2t->tag_hdr[T2T_CC1_VNO_BYTE] != T2T_CC1_NEW_VNO))) {
+ RW_TRACE_WARNING0("rw_t2t_format_tag - Tag not blank to Format!");
+ return (NFC_STATUS_FAILED);
+ } else {
+ tms = p_t2t->tag_hdr[T2T_CC2_TMS_BYTE];
+ b_blank_tag = false;
}
+ } else
+ tms = p_ret->tms;
+
+ memset(p_t2t->tag_data, 0, T2T_READ_DATA_LEN);
+
+ if (!b_blank_tag || !p_ret->b_multi_version) {
+ status = rw_t2t_set_cc(tms);
+ } else if (p_ret->version_block != 0) {
+ /* If Version number is not read, READ it now */
+ p_t2t->substate = RW_T2T_SUBSTATE_WAIT_READ_VERSION_INFO;
+
+ if ((status = rw_t2t_read(p_ret->version_block)) == NFC_STATUS_OK)
+ p_t2t->state = RW_T2T_STATE_FORMAT_TAG;
else
- tms = p_ret->tms;
+ p_t2t->substate = RW_T2T_SUBSTATE_NONE;
+ } else {
+ /* UID block is the version block */
+ p_t2t->state = RW_T2T_STATE_FORMAT_TAG;
+ p_t2t->substate = RW_T2T_SUBSTATE_WAIT_READ_VERSION_INFO;
+ rw_t2t_handle_format_tag_rsp(p_t2t->tag_hdr);
+ }
- memset (p_t2t->tag_data, 0, T2T_READ_DATA_LEN);
-
- if (!b_blank_tag || !p_ret->b_multi_version)
- {
- status = rw_t2t_set_cc (tms);
- }
- else if (p_ret->version_block != 0)
- {
- /* If Version number is not read, READ it now */
- p_t2t->substate = RW_T2T_SUBSTATE_WAIT_READ_VERSION_INFO;
-
- if ((status = rw_t2t_read (p_ret->version_block)) == NFC_STATUS_OK)
- p_t2t->state = RW_T2T_STATE_FORMAT_TAG;
- else
- p_t2t->substate = RW_T2T_SUBSTATE_NONE;
- }
- else
- {
- /* UID block is the version block */
- p_t2t->state = RW_T2T_STATE_FORMAT_TAG;
- p_t2t->substate = RW_T2T_SUBSTATE_WAIT_READ_VERSION_INFO;
- rw_t2t_handle_format_tag_rsp (p_t2t->tag_hdr);
- }
-
- return status;
+ return status;
}
/*******************************************************************************
@@ -2742,56 +2606,57 @@
** NFC_STATUS_FAILED: otherwise
**
*******************************************************************************/
-tNFC_STATUS rw_t2t_soft_lock_tag (void)
-{
- tRW_T2T_CB *p_t2t = &rw_cb.tcb.t2t;
- tNFC_STATUS status = NFC_STATUS_FAILED;
- uint8_t write_block[T2T_BLOCK_SIZE];
- uint8_t num_locks;
+tNFC_STATUS rw_t2t_soft_lock_tag(void) {
+ tRW_T2T_CB* p_t2t = &rw_cb.tcb.t2t;
+ tNFC_STATUS status = NFC_STATUS_FAILED;
+ uint8_t write_block[T2T_BLOCK_SIZE];
+ uint8_t num_locks;
- /* If CC block is read and cc3 is soft locked, reject the command */
- if ((p_t2t->tag_hdr[T2T_CC3_RWA_BYTE] & T2T_CC3_RWA_RO) == T2T_CC3_RWA_RO)
- {
- RW_TRACE_ERROR1 ("rw_t2t_soft_lock_tag: Error: Type 2 tag is in Read only state, CC3: %u", p_t2t->tag_hdr[T2T_CC3_RWA_BYTE]);
- return (NFC_STATUS_FAILED);
+ /* If CC block is read and cc3 is soft locked, reject the command */
+ if ((p_t2t->tag_hdr[T2T_CC3_RWA_BYTE] & T2T_CC3_RWA_RO) == T2T_CC3_RWA_RO) {
+ RW_TRACE_ERROR1(
+ "rw_t2t_soft_lock_tag: Error: Type 2 tag is in Read only state, CC3: "
+ "%u",
+ p_t2t->tag_hdr[T2T_CC3_RWA_BYTE]);
+ return (NFC_STATUS_FAILED);
+ }
+
+ if (p_t2t->b_hard_lock) {
+ /* Should have performed NDEF Detection on dynamic memory structure tag,
+ * before permanently converting to Read only
+ * Even when no lock control tlv is present, default lock bytes should be
+ * present */
+
+ if ((p_t2t->tag_hdr[T2T_CC2_TMS_BYTE] != T2T_CC2_TMS_STATIC) &&
+ (p_t2t->num_lockbytes == 0)) {
+ RW_TRACE_ERROR0(
+ "rw_t2t_soft_lock_tag: Error: Lock TLV not detected! Cannot hard "
+ "lock the tag");
+ return (NFC_STATUS_FAILED);
}
- if (p_t2t->b_hard_lock)
- {
- /* Should have performed NDEF Detection on dynamic memory structure tag, before permanently converting to Read only
- * Even when no lock control tlv is present, default lock bytes should be present */
-
- if ((p_t2t->tag_hdr[T2T_CC2_TMS_BYTE] != T2T_CC2_TMS_STATIC) && (p_t2t->num_lockbytes == 0))
- {
- RW_TRACE_ERROR0 ("rw_t2t_soft_lock_tag: Error: Lock TLV not detected! Cannot hard lock the tag");
- return (NFC_STATUS_FAILED);
- }
-
- /* On dynamic memory structure tag, reset all lock bytes status to 'Not Updated' if not in Updated status */
- num_locks = 0;
- while (num_locks < p_t2t->num_lockbytes)
- {
- if (p_t2t->lockbyte[num_locks].lock_status != RW_T2T_LOCK_UPDATED)
- p_t2t->lockbyte[num_locks].lock_status = RW_T2T_LOCK_NOT_UPDATED;
- num_locks++;
- }
+ /* On dynamic memory structure tag, reset all lock bytes status to 'Not
+ * Updated' if not in Updated status */
+ num_locks = 0;
+ while (num_locks < p_t2t->num_lockbytes) {
+ if (p_t2t->lockbyte[num_locks].lock_status != RW_T2T_LOCK_UPDATED)
+ p_t2t->lockbyte[num_locks].lock_status = RW_T2T_LOCK_NOT_UPDATED;
+ num_locks++;
}
+ }
- memcpy (write_block, &p_t2t->tag_hdr[T2T_CC0_NMN_BYTE], T2T_BLOCK_SIZE);
- write_block[(T2T_CC3_RWA_BYTE % T2T_BLOCK_SIZE)] = T2T_CC3_RWA_RO;
+ memcpy(write_block, &p_t2t->tag_hdr[T2T_CC0_NMN_BYTE], T2T_BLOCK_SIZE);
+ write_block[(T2T_CC3_RWA_BYTE % T2T_BLOCK_SIZE)] = T2T_CC3_RWA_RO;
- p_t2t->substate = RW_T2T_SUBSTATE_WAIT_SET_CC_RO;
- /* First Soft lock the tag */
- if ((status = rw_t2t_write (T2T_CC_BLOCK, write_block)) == NFC_STATUS_OK)
- {
- p_t2t->state = RW_T2T_STATE_SET_TAG_RO;
- p_t2t->b_read_hdr = false;
- }
- else
- {
- p_t2t->substate = RW_T2T_SUBSTATE_NONE;
- }
- return status;
+ p_t2t->substate = RW_T2T_SUBSTATE_WAIT_SET_CC_RO;
+ /* First Soft lock the tag */
+ if ((status = rw_t2t_write(T2T_CC_BLOCK, write_block)) == NFC_STATUS_OK) {
+ p_t2t->state = RW_T2T_STATE_SET_TAG_RO;
+ p_t2t->b_read_hdr = false;
+ } else {
+ p_t2t->substate = RW_T2T_SUBSTATE_NONE;
+ }
+ return status;
}
/*****************************************************************************
@@ -2806,33 +2671,29 @@
** NFC_STATUS_FAILED: otherwise
**
*****************************************************************************/
-tNFC_STATUS RW_T2tFormatNDef (void)
-{
- tRW_T2T_CB *p_t2t = &rw_cb.tcb.t2t;
- tNFC_STATUS status = NFC_STATUS_FAILED;
+tNFC_STATUS RW_T2tFormatNDef(void) {
+ tRW_T2T_CB* p_t2t = &rw_cb.tcb.t2t;
+ tNFC_STATUS status = NFC_STATUS_FAILED;
- if (p_t2t->state != RW_T2T_STATE_IDLE)
- {
- RW_TRACE_WARNING1 ("RW_T2tFormatNDef - Tag not initialized/ Busy! State: %u", p_t2t->state);
- return (NFC_STATUS_FAILED);
- }
+ if (p_t2t->state != RW_T2T_STATE_IDLE) {
+ RW_TRACE_WARNING1("RW_T2tFormatNDef - Tag not initialized/ Busy! State: %u",
+ p_t2t->state);
+ return (NFC_STATUS_FAILED);
+ }
- if (!p_t2t->b_read_hdr)
- {
- /* If UID is not read, READ it now */
- p_t2t->substate = RW_T2T_SUBSTATE_WAIT_READ_CC;
+ if (!p_t2t->b_read_hdr) {
+ /* If UID is not read, READ it now */
+ p_t2t->substate = RW_T2T_SUBSTATE_WAIT_READ_CC;
- if ((status = rw_t2t_read (0)) == NFC_STATUS_OK)
- p_t2t->state = RW_T2T_STATE_FORMAT_TAG;
- else
- p_t2t->substate = RW_T2T_SUBSTATE_NONE;
- }
+ if ((status = rw_t2t_read(0)) == NFC_STATUS_OK)
+ p_t2t->state = RW_T2T_STATE_FORMAT_TAG;
else
- {
- if ((status = rw_t2t_format_tag ()) != NFC_STATUS_OK)
- p_t2t->b_read_hdr = false;
- }
- return status;
+ p_t2t->substate = RW_T2T_SUBSTATE_NONE;
+ } else {
+ if ((status = rw_t2t_format_tag()) != NFC_STATUS_OK)
+ p_t2t->b_read_hdr = false;
+ }
+ return status;
}
/*******************************************************************************
@@ -2852,92 +2713,80 @@
** status.
**
*******************************************************************************/
-tNFC_STATUS RW_T2tLocateTlv (uint8_t tlv_type)
-{
- tRW_T2T_CB *p_t2t = &rw_cb.tcb.t2t;
- tNFC_STATUS status;
- uint16_t block;
+tNFC_STATUS RW_T2tLocateTlv(uint8_t tlv_type) {
+ tRW_T2T_CB* p_t2t = &rw_cb.tcb.t2t;
+ tNFC_STATUS status;
+ uint16_t block;
- if (p_t2t->state != RW_T2T_STATE_IDLE)
- {
- RW_TRACE_ERROR1 ("Error: Type 2 tag not activated or Busy - State: %u", p_t2t->state);
- return (NFC_STATUS_BUSY);
- }
+ if (p_t2t->state != RW_T2T_STATE_IDLE) {
+ RW_TRACE_ERROR1("Error: Type 2 tag not activated or Busy - State: %u",
+ p_t2t->state);
+ return (NFC_STATUS_BUSY);
+ }
- if ((tlv_type != TAG_LOCK_CTRL_TLV) && (tlv_type != TAG_MEM_CTRL_TLV) && (tlv_type != TAG_NDEF_TLV) && (tlv_type != TAG_PROPRIETARY_TLV))
- {
- RW_TRACE_API1 ("RW_T2tLocateTlv - Cannot search TLV: 0x%02x", tlv_type);
- return (NFC_STATUS_FAILED);
- }
+ if ((tlv_type != TAG_LOCK_CTRL_TLV) && (tlv_type != TAG_MEM_CTRL_TLV) &&
+ (tlv_type != TAG_NDEF_TLV) && (tlv_type != TAG_PROPRIETARY_TLV)) {
+ RW_TRACE_API1("RW_T2tLocateTlv - Cannot search TLV: 0x%02x", tlv_type);
+ return (NFC_STATUS_FAILED);
+ }
- if ( (tlv_type == TAG_LOCK_CTRL_TLV)
- &&(p_t2t->b_read_hdr)
- &&(p_t2t->tag_hdr[T2T_CC2_TMS_BYTE] == T2T_CC2_TMS_STATIC) )
- {
- p_t2t->b_read_hdr = false;
- RW_TRACE_API1 ("RW_T2tLocateTlv - No Lock tlv in static structure tag, CC[0]: 0x%02x", p_t2t->tag_hdr[T2T_CC2_TMS_BYTE]);
- return (NFC_STATUS_FAILED);
- }
+ if ((tlv_type == TAG_LOCK_CTRL_TLV) && (p_t2t->b_read_hdr) &&
+ (p_t2t->tag_hdr[T2T_CC2_TMS_BYTE] == T2T_CC2_TMS_STATIC)) {
+ p_t2t->b_read_hdr = false;
+ RW_TRACE_API1(
+ "RW_T2tLocateTlv - No Lock tlv in static structure tag, CC[0]: 0x%02x",
+ p_t2t->tag_hdr[T2T_CC2_TMS_BYTE]);
+ return (NFC_STATUS_FAILED);
+ }
- if ( (tlv_type == TAG_NDEF_TLV)
- &&(p_t2t->b_read_hdr)
- &&(p_t2t->tag_hdr[T2T_CC0_NMN_BYTE] != T2T_CC0_NMN) )
- {
- p_t2t->b_read_hdr = false;
- RW_TRACE_WARNING3 ("RW_T2tLocateTlv - Invalid NDEF Magic Number!, CC[0]: 0x%02x, CC[1]: 0x%02x, CC[3]: 0x%02x", p_t2t->tag_hdr[T2T_CC0_NMN_BYTE], p_t2t->tag_hdr[T2T_CC1_VNO_BYTE], p_t2t->tag_hdr[T2T_CC3_RWA_BYTE]);
- return (NFC_STATUS_FAILED);
- }
+ if ((tlv_type == TAG_NDEF_TLV) && (p_t2t->b_read_hdr) &&
+ (p_t2t->tag_hdr[T2T_CC0_NMN_BYTE] != T2T_CC0_NMN)) {
+ p_t2t->b_read_hdr = false;
+ RW_TRACE_WARNING3(
+ "RW_T2tLocateTlv - Invalid NDEF Magic Number!, CC[0]: 0x%02x, CC[1]: "
+ "0x%02x, CC[3]: 0x%02x",
+ p_t2t->tag_hdr[T2T_CC0_NMN_BYTE], p_t2t->tag_hdr[T2T_CC1_VNO_BYTE],
+ p_t2t->tag_hdr[T2T_CC3_RWA_BYTE]);
+ return (NFC_STATUS_FAILED);
+ }
- p_t2t->work_offset = 0;
- p_t2t->tlv_detect = tlv_type;
+ p_t2t->work_offset = 0;
+ p_t2t->tlv_detect = tlv_type;
- /* Reset control block variables based on type of tlv to detect */
- if (tlv_type == TAG_LOCK_CTRL_TLV)
- {
- p_t2t->num_lockbytes = 0;
- p_t2t->num_lock_tlvs = 0;
- }
- else if (tlv_type == TAG_MEM_CTRL_TLV)
- {
- p_t2t->num_mem_tlvs = 0;
- }
- else if (tlv_type == TAG_NDEF_TLV)
- {
- p_t2t->ndef_msg_offset = 0;
- p_t2t->num_lockbytes = 0;
- p_t2t->num_lock_tlvs = 0;
- p_t2t->num_mem_tlvs = 0;
- p_t2t->ndef_msg_len = 0;
- p_t2t->ndef_status = T2T_NDEF_NOT_DETECTED;
- }
- else
- {
- p_t2t->prop_msg_len = 0;
- }
+ /* Reset control block variables based on type of tlv to detect */
+ if (tlv_type == TAG_LOCK_CTRL_TLV) {
+ p_t2t->num_lockbytes = 0;
+ p_t2t->num_lock_tlvs = 0;
+ } else if (tlv_type == TAG_MEM_CTRL_TLV) {
+ p_t2t->num_mem_tlvs = 0;
+ } else if (tlv_type == TAG_NDEF_TLV) {
+ p_t2t->ndef_msg_offset = 0;
+ p_t2t->num_lockbytes = 0;
+ p_t2t->num_lock_tlvs = 0;
+ p_t2t->num_mem_tlvs = 0;
+ p_t2t->ndef_msg_len = 0;
+ p_t2t->ndef_status = T2T_NDEF_NOT_DETECTED;
+ } else {
+ p_t2t->prop_msg_len = 0;
+ }
- if (!p_t2t->b_read_hdr)
- {
- /* First read CC block */
- block = 0;
- p_t2t->substate = RW_T2T_SUBSTATE_WAIT_READ_CC;
- }
- else
- {
- /* Read first data block */
- block = T2T_FIRST_DATA_BLOCK;
- p_t2t->substate = RW_T2T_SUBSTATE_WAIT_TLV_DETECT;
- }
+ if (!p_t2t->b_read_hdr) {
+ /* First read CC block */
+ block = 0;
+ p_t2t->substate = RW_T2T_SUBSTATE_WAIT_READ_CC;
+ } else {
+ /* Read first data block */
+ block = T2T_FIRST_DATA_BLOCK;
+ p_t2t->substate = RW_T2T_SUBSTATE_WAIT_TLV_DETECT;
+ }
- /* Start reading tag, looking for the specified TLV */
- if ((status = rw_t2t_read ((uint16_t) block)) == NFC_STATUS_OK)
- {
- p_t2t->state = RW_T2T_STATE_DETECT_TLV;
- }
- else
- {
- p_t2t->substate = RW_T2T_SUBSTATE_NONE;
- }
- return (status);
+ /* Start reading tag, looking for the specified TLV */
+ if ((status = rw_t2t_read((uint16_t)block)) == NFC_STATUS_OK) {
+ p_t2t->state = RW_T2T_STATE_DETECT_TLV;
+ } else {
+ p_t2t->substate = RW_T2T_SUBSTATE_NONE;
+ }
+ return (status);
}
/*******************************************************************************
@@ -2956,13 +2805,12 @@
** Returns NCI_STATUS_OK,if detect op started.Otherwise,error status.
**
*******************************************************************************/
-tNFC_STATUS RW_T2tDetectNDef (bool skip_dyn_locks)
-{
- tRW_T2T_CB *p_t2t = &rw_cb.tcb.t2t;
+tNFC_STATUS RW_T2tDetectNDef(bool skip_dyn_locks) {
+ tRW_T2T_CB* p_t2t = &rw_cb.tcb.t2t;
- p_t2t->skip_dyn_locks = skip_dyn_locks;
+ p_t2t->skip_dyn_locks = skip_dyn_locks;
- return RW_T2tLocateTlv (TAG_NDEF_TLV);
+ return RW_T2tLocateTlv(TAG_NDEF_TLV);
}
/*******************************************************************************
@@ -2988,61 +2836,55 @@
** Returns NCI_STATUS_OK, if read was started. Otherwise, error status.
**
*******************************************************************************/
-tNFC_STATUS RW_T2tReadNDef (uint8_t *p_buffer, uint16_t buf_len)
-{
- tRW_T2T_CB *p_t2t = &rw_cb.tcb.t2t;
- tNFC_STATUS status = NFC_STATUS_OK;
- uint16_t block;
+tNFC_STATUS RW_T2tReadNDef(uint8_t* p_buffer, uint16_t buf_len) {
+ tRW_T2T_CB* p_t2t = &rw_cb.tcb.t2t;
+ tNFC_STATUS status = NFC_STATUS_OK;
+ uint16_t block;
- if (p_t2t->state != RW_T2T_STATE_IDLE)
- {
- RW_TRACE_ERROR1 ("Error: Type 2 tag not activated or Busy - State: %u", p_t2t->state);
- return (NFC_STATUS_FAILED);
+ if (p_t2t->state != RW_T2T_STATE_IDLE) {
+ RW_TRACE_ERROR1("Error: Type 2 tag not activated or Busy - State: %u",
+ p_t2t->state);
+ return (NFC_STATUS_FAILED);
+ }
+
+ if (p_t2t->ndef_status == T2T_NDEF_NOT_DETECTED) {
+ RW_TRACE_ERROR0("RW_T2tReadNDef - Error: NDEF detection not performed yet");
+ return (NFC_STATUS_FAILED);
+ }
+
+ if (buf_len < p_t2t->ndef_msg_len) {
+ RW_TRACE_WARNING2(
+ "RW_T2tReadNDef - buffer size: %u less than NDEF msg sise: %u",
+ buf_len, p_t2t->ndef_msg_len);
+ return (NFC_STATUS_FAILED);
+ }
+
+ if (!p_t2t->ndef_msg_len) {
+ RW_TRACE_WARNING1("RW_T2tReadNDef - NDEF Message length is zero ",
+ p_t2t->ndef_msg_len);
+ return (NFC_STATUS_NOT_INITIALIZED);
+ }
+
+ p_t2t->p_ndef_buffer = p_buffer;
+ p_t2t->work_offset = 0;
+
+ block = (uint16_t)(p_t2t->ndef_msg_offset / T2T_BLOCK_LEN);
+ block -= block % T2T_READ_BLOCKS;
+
+ p_t2t->substate = RW_T2T_SUBSTATE_NONE;
+
+ if ((block == T2T_FIRST_DATA_BLOCK) && (p_t2t->b_read_data)) {
+ p_t2t->state = RW_T2T_STATE_READ_NDEF;
+ p_t2t->block_read = T2T_FIRST_DATA_BLOCK;
+ rw_t2t_handle_ndef_read_rsp(p_t2t->tag_data);
+ } else {
+ /* Start reading NDEF Message */
+ if ((status = rw_t2t_read(block)) == NFC_STATUS_OK) {
+ p_t2t->state = RW_T2T_STATE_READ_NDEF;
}
+ }
- if (p_t2t->ndef_status == T2T_NDEF_NOT_DETECTED)
- {
- RW_TRACE_ERROR0 ("RW_T2tReadNDef - Error: NDEF detection not performed yet");
- return (NFC_STATUS_FAILED);
- }
-
- if (buf_len < p_t2t->ndef_msg_len)
- {
- RW_TRACE_WARNING2 ("RW_T2tReadNDef - buffer size: %u less than NDEF msg sise: %u", buf_len, p_t2t->ndef_msg_len);
- return (NFC_STATUS_FAILED);
- }
-
- if (!p_t2t->ndef_msg_len)
- {
- RW_TRACE_WARNING1 ("RW_T2tReadNDef - NDEF Message length is zero ", p_t2t->ndef_msg_len);
- return (NFC_STATUS_NOT_INITIALIZED);
- }
-
- p_t2t->p_ndef_buffer = p_buffer;
- p_t2t->work_offset = 0;
-
- block = (uint16_t) (p_t2t->ndef_msg_offset / T2T_BLOCK_LEN);
- block -= block % T2T_READ_BLOCKS;
-
- p_t2t->substate = RW_T2T_SUBSTATE_NONE;
-
- if ( (block == T2T_FIRST_DATA_BLOCK)
- &&(p_t2t->b_read_data) )
- {
- p_t2t->state = RW_T2T_STATE_READ_NDEF;
- p_t2t->block_read = T2T_FIRST_DATA_BLOCK;
- rw_t2t_handle_ndef_read_rsp (p_t2t->tag_data);
- }
- else
- {
- /* Start reading NDEF Message */
- if ((status = rw_t2t_read (block)) == NFC_STATUS_OK)
- {
- p_t2t->state = RW_T2T_STATE_READ_NDEF;
- }
- }
-
- return (status);
+ return (status);
}
/*******************************************************************************
@@ -3068,72 +2910,70 @@
** Returns NCI_STATUS_OK,if write was started. Otherwise, error status
**
*******************************************************************************/
-tNFC_STATUS RW_T2tWriteNDef (uint16_t msg_len, uint8_t *p_msg)
-{
- tRW_T2T_CB *p_t2t = &rw_cb.tcb.t2t;
- uint16_t block;
- const tT2T_INIT_TAG *p_ret;
+tNFC_STATUS RW_T2tWriteNDef(uint16_t msg_len, uint8_t* p_msg) {
+ tRW_T2T_CB* p_t2t = &rw_cb.tcb.t2t;
+ uint16_t block;
+ const tT2T_INIT_TAG* p_ret;
- tNFC_STATUS status = NFC_STATUS_OK;
+ tNFC_STATUS status = NFC_STATUS_OK;
- if (p_t2t->state != RW_T2T_STATE_IDLE)
- {
- RW_TRACE_ERROR1 ("Error: Type 2 tag not activated or Busy - State: %u", p_t2t->state);
- return (NFC_STATUS_FAILED);
- }
+ if (p_t2t->state != RW_T2T_STATE_IDLE) {
+ RW_TRACE_ERROR1("Error: Type 2 tag not activated or Busy - State: %u",
+ p_t2t->state);
+ return (NFC_STATUS_FAILED);
+ }
- if (p_t2t->ndef_status == T2T_NDEF_NOT_DETECTED)
- {
- RW_TRACE_ERROR0 ("RW_T2tWriteNDef - Error: NDEF detection not performed!");
- return (NFC_STATUS_FAILED);
- }
+ if (p_t2t->ndef_status == T2T_NDEF_NOT_DETECTED) {
+ RW_TRACE_ERROR0("RW_T2tWriteNDef - Error: NDEF detection not performed!");
+ return (NFC_STATUS_FAILED);
+ }
- if (p_t2t->tag_hdr[T2T_CC3_RWA_BYTE] != T2T_CC3_RWA_RW)
- {
- RW_TRACE_ERROR1 ("RW_T2tWriteNDef - Write access not granted - CC3: %u", p_t2t->tag_hdr[T2T_CC3_RWA_BYTE]);
- return (NFC_STATUS_REFUSED);
- }
+ if (p_t2t->tag_hdr[T2T_CC3_RWA_BYTE] != T2T_CC3_RWA_RW) {
+ RW_TRACE_ERROR1("RW_T2tWriteNDef - Write access not granted - CC3: %u",
+ p_t2t->tag_hdr[T2T_CC3_RWA_BYTE]);
+ return (NFC_STATUS_REFUSED);
+ }
- /* Check if there is enough memory on the tag */
- if (msg_len > p_t2t->max_ndef_msg_len)
- {
- RW_TRACE_ERROR1 ("RW_T2tWriteNDef - Cannot write NDEF of size greater than %u bytes", p_t2t->max_ndef_msg_len);
- return (NFC_STATUS_FAILED);
- }
+ /* Check if there is enough memory on the tag */
+ if (msg_len > p_t2t->max_ndef_msg_len) {
+ RW_TRACE_ERROR1(
+ "RW_T2tWriteNDef - Cannot write NDEF of size greater than %u bytes",
+ p_t2t->max_ndef_msg_len);
+ return (NFC_STATUS_FAILED);
+ }
- /* If OTP tag and tag has valid NDEF Message, stop writting new NDEF Message as it may corrupt the tag */
- if ( (p_t2t->ndef_msg_len > 0)
- &&((p_ret = t2t_tag_init_data (p_t2t->tag_hdr[0], false, 0)) != NULL)
- &&(p_ret->b_otp) )
- {
- RW_TRACE_WARNING0 ("RW_T2tWriteNDef - Cannot Overwrite NDEF Message on a OTP tag!");
- return (NFC_STATUS_FAILED);
- }
- p_t2t->p_new_ndef_buffer = p_msg;
- p_t2t->new_ndef_msg_len = msg_len;
- p_t2t->work_offset = 0;
+ /* If OTP tag and tag has valid NDEF Message, stop writting new NDEF Message
+ * as it may corrupt the tag */
+ if ((p_t2t->ndef_msg_len > 0) &&
+ ((p_ret = t2t_tag_init_data(p_t2t->tag_hdr[0], false, 0)) != NULL) &&
+ (p_ret->b_otp)) {
+ RW_TRACE_WARNING0(
+ "RW_T2tWriteNDef - Cannot Overwrite NDEF Message on a OTP tag!");
+ return (NFC_STATUS_FAILED);
+ }
+ p_t2t->p_new_ndef_buffer = p_msg;
+ p_t2t->new_ndef_msg_len = msg_len;
+ p_t2t->work_offset = 0;
- p_t2t->substate = RW_T2T_SUBSTATE_WAIT_READ_NDEF_FIRST_BLOCK;
- /* Read first NDEF Block before updating NDEF */
+ p_t2t->substate = RW_T2T_SUBSTATE_WAIT_READ_NDEF_FIRST_BLOCK;
+ /* Read first NDEF Block before updating NDEF */
- block = (uint16_t) (p_t2t->ndef_header_offset / T2T_BLOCK_LEN);
+ block = (uint16_t)(p_t2t->ndef_header_offset / T2T_BLOCK_LEN);
- if ( (block < (T2T_FIRST_DATA_BLOCK + T2T_READ_BLOCKS))
- &&(p_t2t->b_read_data) )
- {
- p_t2t->state = RW_T2T_STATE_WRITE_NDEF;
- p_t2t->block_read = block;
- rw_t2t_handle_ndef_write_rsp (&p_t2t->tag_data[(block - T2T_FIRST_DATA_BLOCK) * T2T_BLOCK_LEN]);
- }
+ if ((block < (T2T_FIRST_DATA_BLOCK + T2T_READ_BLOCKS)) &&
+ (p_t2t->b_read_data)) {
+ p_t2t->state = RW_T2T_STATE_WRITE_NDEF;
+ p_t2t->block_read = block;
+ rw_t2t_handle_ndef_write_rsp(
+ &p_t2t->tag_data[(block - T2T_FIRST_DATA_BLOCK) * T2T_BLOCK_LEN]);
+ } else {
+ if ((status = rw_t2t_read(block)) == NFC_STATUS_OK)
+ p_t2t->state = RW_T2T_STATE_WRITE_NDEF;
else
- {
- if ((status = rw_t2t_read (block)) == NFC_STATUS_OK)
- p_t2t->state = RW_T2T_STATE_WRITE_NDEF;
- else
- p_t2t->substate = RW_T2T_SUBSTATE_NONE;
- }
+ p_t2t->substate = RW_T2T_SUBSTATE_NONE;
+ }
- return status;
+ return status;
}
/*******************************************************************************
@@ -3148,37 +2988,33 @@
** Otherwise, error status.
**
*******************************************************************************/
-tNFC_STATUS RW_T2tSetTagReadOnly (bool b_hard_lock)
-{
- tNFC_STATUS status = NFC_STATUS_FAILED;
- tRW_T2T_CB *p_t2t = &rw_cb.tcb.t2t;
+tNFC_STATUS RW_T2tSetTagReadOnly(bool b_hard_lock) {
+ tNFC_STATUS status = NFC_STATUS_FAILED;
+ tRW_T2T_CB* p_t2t = &rw_cb.tcb.t2t;
- if (p_t2t->state != RW_T2T_STATE_IDLE)
- {
- RW_TRACE_ERROR1 ("RW_T2tSetTagReadOnly: Error: Type 2 tag not activated or Busy - State: %u", p_t2t->state);
- return (NFC_STATUS_FAILED);
- }
+ if (p_t2t->state != RW_T2T_STATE_IDLE) {
+ RW_TRACE_ERROR1(
+ "RW_T2tSetTagReadOnly: Error: Type 2 tag not activated or Busy - "
+ "State: %u",
+ p_t2t->state);
+ return (NFC_STATUS_FAILED);
+ }
- p_t2t->b_hard_lock = b_hard_lock;
+ p_t2t->b_hard_lock = b_hard_lock;
- if (!p_t2t->b_read_hdr)
- {
- /* Read CC block before configuring tag as Read only */
- p_t2t->substate = RW_T2T_SUBSTATE_WAIT_READ_CC;
- if ((status = rw_t2t_read ((uint16_t) 0)) == NFC_STATUS_OK)
- {
- p_t2t->state = RW_T2T_STATE_SET_TAG_RO;
- }
- else
- p_t2t->substate = RW_T2T_SUBSTATE_NONE;
- }
- else
- {
- if ((status = rw_t2t_soft_lock_tag ()) != NFC_STATUS_OK)
- p_t2t->b_read_hdr = false;
- }
+ if (!p_t2t->b_read_hdr) {
+ /* Read CC block before configuring tag as Read only */
+ p_t2t->substate = RW_T2T_SUBSTATE_WAIT_READ_CC;
+ if ((status = rw_t2t_read((uint16_t)0)) == NFC_STATUS_OK) {
+ p_t2t->state = RW_T2T_STATE_SET_TAG_RO;
+ } else
+ p_t2t->substate = RW_T2T_SUBSTATE_NONE;
+ } else {
+ if ((status = rw_t2t_soft_lock_tag()) != NFC_STATUS_OK)
+ p_t2t->b_read_hdr = false;
+ }
- return status;
+ return status;
}
#endif /* (RW_NDEF_INCLUDED == TRUE) */