rw_int.h revision f8a4ca325ef137a94869b34d36095ba7d08816a3
1/**************************************************************************** 2** 3** File: rw_int.h 4** 5** Description: This file contains the Near Field Communication (NFC) 6** Reader/Writer mode related internal function / definitions. 7** 8** Copyright (c) 2009-2010, Broadcom Corp., All Rights Reserved. 9** Broadcom Bluetooth Core. Proprietary and confidential. 10****************************************************************************/ 11 12#ifndef RW_INT_H_ 13#define RW_INT_H_ 14 15#include "tags_defs.h" 16#include "tags_int.h" 17#include "rw_api.h" 18 19/* Proprietary definitions for HR0 and HR1 */ 20#define RW_T1T_HR0_HI_NIB 0xF0 /* HI NIB Tag */ 21#define RW_T1T_IS_JEWEL64 0x20 /* Jewel 64 Tag */ 22#define RW_T1T_IS_JEWEL 0x00 /* Jewel Tag */ 23#define RW_T1T_IS_TOPAZ 0x10 /* TOPAZ Tag */ 24#define RW_T1T_IS_TOPAZ96 0x11 /* TOPAZ96 Tag */ 25#define RW_T1T_IS_TOPAZ512 0x12 /* TOPAZ512 Tag */ 26#define RW_T1T_HR1_MIN 0x49 /* Supports dynamic commands on static tag if HR1 > 0x49 */ 27 28#define RW_T1T_MAX_MEM_TLVS 0x05 /* Maximum supported Memory control TLVS in the tag */ 29#define RW_T1T_MAX_LOCK_TLVS 0x05 /* Maximum supported Lock control TLVS in the tag */ 30#define RW_T1T_MAX_LOCK_BYTES 0x1E /* Maximum supported dynamic lock bytes */ 31 32/* State of the Tag as interpreted by RW */ 33#define RW_T1_TAG_ATTRB_UNKNOWN 0x00 /* TAG State is unknown to RW */ 34#define RW_T1_TAG_ATTRB_INITIALIZED 0x01 /* TAG is in INITIALIZED state */ 35#define RW_T1_TAG_ATTRB_INITIALIZED_NDEF 0x02 /* TAG is in INITIALIZED state and has NDEF tlv with len=0 */ 36#define RW_T1_TAG_ATTRB_READ_ONLY 0x03 /* TAG is in READ ONLY state */ 37#define RW_T1_TAG_ATTRB_READ_WRITE 0x04 /* TAG is in READ WRITE state */ 38 39#define RW_T1T_LOCK_NOT_UPDATED 0x00 /* Lock not yet set as part of SET TAG RO op */ 40#define RW_T1T_LOCK_UPDATE_INITIATED 0x01 /* Sent command to set the Lock bytes */ 41#define RW_T1T_LOCK_UPDATED 0x02 /* Lock bytes are set */ 42typedef UINT8 tRW_T1T_LOCK_STATUS; 43 44/* States */ 45#define RW_T1T_STATE_NOT_ACTIVATED 0x00 /* Tag not activated and or response not received for RID */ 46#define RW_T1T_STATE_IDLE 0x01 /* T1 Tag activated and ready to perform rw operation on Tag*/ 47#define RW_T1T_STATE_READ 0x02 /* waiting rsp for read command sent to tag */ 48#define RW_T1T_STATE_WRITE 0x03 /* waiting rsp for write command sent to tag */ 49#define RW_T1T_STATE_TLV_DETECT 0x04 /* performing TLV detection procedure */ 50#define RW_T1T_STATE_READ_NDEF 0x05 /* performing read NDEF procedure */ 51#define RW_T1T_STATE_WRITE_NDEF 0x06 /* performing update NDEF procedure */ 52#define RW_T1T_STATE_SET_TAG_RO 0x07 /* Setting Tag as read only tag */ 53#define RW_T1T_STATE_CHECK_PRESENCE 0x08 /* Check if Tag is still present */ 54#define RW_T1T_STATE_FORMAT_TAG 0x09 /* Format T1 Tag */ 55 56/* Sub states */ 57#define RW_T1T_SUBSTATE_NONE 0x00 /* Default substate */ 58 59/* Sub states in RW_T1T_STATE_TLV_DETECT state */ 60#define RW_T1T_SUBSTATE_WAIT_TLV_DETECT 0x01 /* waiting for the detection of a tlv in a tag */ 61#define RW_T1T_SUBSTATE_WAIT_FIND_LEN_FIELD_LEN 0x02 /* waiting for finding the len field is 1 or 3 bytes long */ 62#define RW_T1T_SUBSTATE_WAIT_READ_TLV_LEN0 0x03 /* waiting for extracting len field value */ 63#define RW_T1T_SUBSTATE_WAIT_READ_TLV_LEN1 0x04 /* waiting for extracting len field value */ 64#define RW_T1T_SUBSTATE_WAIT_READ_TLV_VALUE 0x05 /* waiting for extracting value field in the TLV */ 65#define RW_T1T_SUBSTATE_WAIT_READ_LOCKS 0x06 /* waiting for reading dynamic locks in the TLV */ 66 67/* Sub states in RW_T1T_STATE_WRITE_NDEF state */ 68#define RW_T1T_SUBSTATE_WAIT_READ_NDEF_BLOCK 0x07 /* waiting for response of reading a block that will be partially updated */ 69#define RW_T1T_SUBSTATE_WAIT_INVALIDATE_NDEF 0x08 /* waiting for response of invalidating NDEF Msg */ 70#define RW_T1T_SUBSTATE_WAIT_NDEF_WRITE 0x09 /* waiting for response of writing a part of NDEF Msg */ 71#define RW_T1T_SUBSTATE_WAIT_NDEF_UPDATED 0x0A /* waiting for response of writing last part of NDEF Msg */ 72#define RW_T1T_SUBSTATE_WAIT_VALIDATE_NDEF 0x0B /* waiting for response of validating NDEF Msg */ 73 74/* Sub states in RW_T1T_STATE_SET_TAG_RO state */ 75#define RW_T1T_SUBSTATE_WAIT_SET_CC_RWA_RO 0x0C /* waiting for response of setting CC-RWA to read only */ 76#define RW_T1T_SUBSTATE_WAIT_SET_ST_LOCK_BITS 0x0D /* waiting for response of setting all static lock bits */ 77#define RW_T1T_SUBSTATE_WAIT_SET_DYN_LOCK_BITS 0x0E /* waiting for response of setting all dynamic lock bits */ 78 79/* Sub states in RW_T1T_STATE_FORMAT_TAG state */ 80#define RW_T1T_SUBSTATE_WAIT_SET_CC 0x0F /* waiting for response to format/set capability container */ 81#define RW_T1T_SUBSTATE_WAIT_SET_NULL_NDEF 0x10 /* waiting for response to format/set NULL NDEF */ 82 83 84typedef struct 85{ 86 UINT16 offset; /* Offset of the lock byte in the Tag */ 87 UINT8 num_bits; /* Number of lock bits in the lock byte */ 88 UINT8 bytes_locked_per_bit; /* No. of tag bytes gets locked by a bit in this byte */ 89} tRW_T1T_LOCK_INFO; 90 91typedef struct 92{ 93 UINT16 offset; /* Reserved bytes offset taken from Memory control TLV */ 94 UINT8 num_bytes; /* Number of reserved bytes as per the TLV */ 95}tRW_T1T_RES_INFO; 96 97typedef struct 98{ 99 UINT8 tlv_index; /* Index of Lock control tlv that points to this address*/ 100 UINT8 byte_index; /* Index of Lock byte pointed by the TLV */ 101 UINT8 lock_byte; /* Value in the lock byte */ 102 tRW_T1T_LOCK_STATUS lock_status; /* Indicates if it is modifed to set tag as Read only */ 103 BOOLEAN b_lock_read; /* Is the lock byte is already read from tag */ 104} tRW_T1T_LOCK; 105 106typedef struct 107{ 108 UINT8 addr; /* ADD/ADD8/ADDS field value */ 109 UINT8 op_code; /* Command sent */ 110 UINT8 rsp_len; /* expected length of the response */ 111 UINT8 pend_retx_rsp; /* Number of pending rsps to retransmission on prev cmd */ 112} tRW_T1T_PREV_CMD_RSP_INFO; 113 114#if (defined (RW_NDEF_INCLUDED) && (RW_NDEF_INCLUDED == TRUE)) 115#define T1T_BUFFER_SIZE T1T_STATIC_SIZE /* Buffer 0-E block, for easier tlv operation */ 116#else 117#define T1T_BUFFER_SIZE T1T_UID_LEN /* Buffer UID */ 118#endif 119 120/* RW Type 1 Tag control blocks */ 121typedef struct 122{ 123 UINT8 hr[T1T_HR_LEN]; /* Header ROM byte 0 - 0x1y,Header ROM byte 1 - 0x00 */ 124 UINT8 mem[T1T_SEGMENT_SIZE]; /* Tag contents of block 0 or from block 0-E */ 125 tT1T_CMD_RSP_INFO *p_cmd_rsp_info; /* Pointer to Command rsp info of last sent command */ 126 UINT8 state; /* Current state of RW module */ 127 UINT8 tag_attribute; /* Present state of the Tag as interpreted by RW */ 128 BT_HDR *p_cur_cmd_buf; /* Buffer to hold cur sent command for retransmission */ 129 UINT8 addr; /* ADD/ADD8/ADDS value */ 130 tRW_T1T_PREV_CMD_RSP_INFO prev_cmd_rsp_info; /* Information about previous sent command if retx */ 131 TIMER_LIST_ENT timer; /* timer to set timelimit for the response to command */ 132 BOOLEAN b_update; /* Tag header updated */ 133 BOOLEAN b_rseg; /* Segment 0 read from tag */ 134 BOOLEAN b_hard_lock; /* Hard lock the tag as part of config tag to Read only */ 135#if (defined (RW_NDEF_INCLUDED) && (RW_NDEF_INCLUDED == TRUE)) 136 UINT8 segment; /* Current Tag segment */ 137 UINT8 substate; /* Current substate of RW module */ 138 UINT16 work_offset; /* Working byte offset */ 139 UINT8 ndef_first_block[T1T_BLOCK_SIZE]; /* Buffer for ndef first block */ 140 UINT8 ndef_final_block[T1T_BLOCK_SIZE]; /* Buffer for ndef last block */ 141 UINT8 *p_ndef_buffer; /* Buffer to store ndef message */ 142 UINT16 new_ndef_msg_len; /* Lenght of new updating NDEF Message */ 143 UINT8 block_read; /* Last read Block */ 144 UINT8 write_byte; /* Index of last written byte */ 145 UINT8 tlv_detect; /* TLV type under detection */ 146 UINT16 ndef_msg_offset; /* The offset on Tag where first NDEF message is present*/ 147 UINT16 ndef_msg_len; /* Lenght of NDEF Message */ 148 UINT16 ndef_header_offset; /* The offset on Tag where first NDEF tlv is present */ 149 UINT8 ndef_block_written; /* Last block where NDEF bytes are written */ 150 UINT8 num_ndef_finalblock; /* Block number where NDEF's last byte will be present */ 151 UINT8 num_lock_tlvs; /* Number of lcok tlvs detected in the tag */ 152 tRW_T1T_LOCK_INFO lock_tlv[RW_T1T_MAX_LOCK_TLVS]; /* Information retrieved from lock control tlv */ 153 UINT8 num_lockbytes; /* Number of dynamic lock bytes present in the tag */ 154 tRW_T1T_LOCK lockbyte[RW_T1T_MAX_LOCK_BYTES]; /* Dynamic Lock byte information */ 155 UINT8 num_mem_tlvs; /* Number of memory tlvs detected in the tag */ 156 tRW_T1T_RES_INFO mem_tlv[RW_T1T_MAX_MEM_TLVS]; /* Information retrieved from mem tlv */ 157 UINT8 attr_seg; /* Tag segment for which attributes are prepared */ 158 UINT8 lock_attr_seg; /* Tag segment for which lock attributes are prepared */ 159 UINT8 attr[T1T_BLOCKS_PER_SEGMENT]; /* byte information - Reserved/lock/otp or data */ 160 UINT8 lock_attr[T1T_BLOCKS_PER_SEGMENT]; /* byte information - read only or read write */ 161#endif 162} tRW_T1T_CB; 163 164/* Mifare Ultalight/ Ultralight Family blank tag version block settings */ 165#define T2T_MIFARE_VERSION_BLOCK 0x04 /* Block where version number of the tag is stored */ 166#define T2T_MIFARE_ULTRALIGHT_VER_NO 0xFFFF /* Blank Ultralight tag - Block 4 (byte 0, byte 1) */ 167#define T2T_MIFARE_ULTRALIGHT_FAMILY_VER_NO 0x0200 /* Blank Ultralight family tag - Block 4 (byte 0, byte 1) */ 168 169/* Infineon my-d move / my-d blank tag uid block settings */ 170#define T2T_INFINEON_VERSION_BLOCK 0x00 171#define T2T_INFINEON_MYD_MOVE_LEAN 0x0510 172#define T2T_INFINEON_MYD_MOVE 0x0530 173#define T2T_INFINEON_MYD_NFC_1K 0x0520 174#define T2T_INFINEON_MYD_NFC_2K 0x0520 175 176#define T2T_BRCM_VERSION_BLOCK 0x00 177#define T2T_BRCM_STATIC_MEM 0x2E01 178#define T2T_BRCM_DYNAMIC_MEM 0x2E02 179 180/* CC2 value on MiFare ULC tag */ 181#define T2T_MIFARE_ULC_TMS 0x12 182/* Possible corrupt cc2 value range on MiFare ULC tags */ 183#define T2T_INVALID_CC_TMS_VAL0 0x10 184#define T2T_INVALID_CC_TMS_VAL1 0x1F 185 186#define T2T_NDEF_NOT_DETECTED 0x00 187#define T2T_NDEF_DETECTED 0x01 188#define T2T_NDEF_READ 0x02 189 190#define T2T_MAX_NDEF_OFFSET 128 /* Max offset of an NDEF message in a T2 tag */ 191#define T2T_MAX_RESERVED_BYTES_IN_TAG 0x64 192#define T2T_MAX_LOCK_BYTES_IN_TAG 0x64 193 194#define RW_T2T_MAX_MEM_TLVS 0x05 /* Maximum supported Memory control TLVS in the tag */ 195#define RW_T2T_MAX_LOCK_TLVS 0x05 /* Maximum supported Lock control TLVS in the tag */ 196#define RW_T2T_MAX_LOCK_BYTES 0x1E /* Maximum supported dynamic lock bytes */ 197#define RW_T2T_SEGMENT_BYTES 128 198#define RW_T2T_SEGMENT_SIZE 16 199 200#define RW_T2T_LOCK_NOT_UPDATED 0x00 /* Lock not yet set as part of SET TAG RO op */ 201#define RW_T2T_LOCK_UPDATE_INITIATED 0x01 /* Sent command to set the Lock bytes */ 202#define RW_T2T_LOCK_UPDATED 0x02 /* Lock bytes are set */ 203typedef UINT8 tRW_T2T_LOCK_STATUS; 204 205 206/* States */ 207#define RW_T2T_STATE_NOT_ACTIVATED 0x00 /* Tag not activated */ 208#define RW_T2T_STATE_IDLE 0x01 /* T1 Tag activated and ready to perform rw operation on Tag*/ 209#define RW_T2T_STATE_READ 0x02 /* waiting response for read command sent to tag */ 210#define RW_T2T_STATE_WRITE 0x03 /* waiting response for write command sent to tag */ 211#define RW_T2T_STATE_SELECT_SECTOR 0x04 /* Waiting response for sector select command */ 212#define RW_T2T_STATE_DETECT_TLV 0x05 /* Detecting Lock/Memory/NDEF/Proprietary TLV in the Tag */ 213#define RW_T2T_STATE_READ_NDEF 0x06 /* Performing NDEF Read procedure */ 214#define RW_T2T_STATE_WRITE_NDEF 0x07 /* Performing NDEF Write procedure */ 215#define RW_T2T_STATE_SET_TAG_RO 0x08 /* Setting Tag as Read only tag */ 216#define RW_T2T_STATE_CHECK_PRESENCE 0x09 /* Check if Tag is still present */ 217#define RW_T2T_STATE_FORMAT_TAG 0x0A /* Format the tag */ 218 219/* rw_t2t_read/rw_t2t_write takes care of sector change if the block to read/write is in a different sector 220 * Next Substate should be assigned to control variable 'substate' before calling these function for State Machine to 221 * move back to the particular substate after Sector change is completed and read/write command is sent on new sector */ 222 223/* Sub states */ 224#define RW_T2T_SUBSTATE_NONE 0x00 225 226/* Sub states in RW_T2T_STATE_SELECT_SECTOR state */ 227#define RW_T2T_SUBSTATE_WAIT_SELECT_SECTOR_SUPPORT 0x01 /* waiting for response of sector select CMD 1 */ 228#define RW_T2T_SUBSTATE_WAIT_SELECT_SECTOR 0x02 /* waiting for response of sector select CMD 2 */ 229 230/* Sub states in RW_T1T_STATE_DETECT_XXX state */ 231#define RW_T2T_SUBSTATE_WAIT_READ_CC 0x03 /* waiting for the detection of a tlv in a tag */ 232#define RW_T2T_SUBSTATE_WAIT_TLV_DETECT 0x04 /* waiting for the detection of a tlv in a tag */ 233#define RW_T2T_SUBSTATE_WAIT_FIND_LEN_FIELD_LEN 0x05 /* waiting for finding the len field is 1 or 3 bytes long */ 234#define RW_T2T_SUBSTATE_WAIT_READ_TLV_LEN0 0x06 /* waiting for extracting len field value */ 235#define RW_T2T_SUBSTATE_WAIT_READ_TLV_LEN1 0x07 /* waiting for extracting len field value */ 236#define RW_T2T_SUBSTATE_WAIT_READ_TLV_VALUE 0x08 /* waiting for extracting value field in the TLV */ 237#define RW_T2T_SUBSTATE_WAIT_READ_LOCKS 0x09 /* waiting for reading dynamic locks in the TLV */ 238 239/* Sub states in RW_T2T_STATE_WRITE_NDEF state */ 240#define RW_T2T_SUBSTATE_WAIT_READ_NDEF_FIRST_BLOCK 0x0A /* waiting for rsp to reading the block where NDEF starts */ 241#define RW_T2T_SUBSTATE_WAIT_READ_NDEF_LAST_BLOCK 0x0B /* waiting for rsp to reading block where new NDEF Msg ends */ 242#define RW_T2T_SUBSTATE_WAIT_READ_TERM_TLV_BLOCK 0x0C /* waiting for rsp to reading block where Trm tlv gets added*/ 243#define RW_T2T_SUBSTATE_WAIT_READ_NDEF_NEXT_BLOCK 0x0D /* waiting for rsp to reading block where nxt NDEF write */ 244#define RW_T2T_SUBSTATE_WAIT_WRITE_NDEF_NEXT_BLOCK 0x0E /* waiting for rsp to writting NDEF block */ 245#define RW_T2T_SUBSTATE_WAIT_WRITE_NDEF_LAST_BLOCK 0x0F /* waiting for rsp to last NDEF block write cmd */ 246#define RW_T2T_SUBSTATE_WAIT_READ_NDEF_LEN_BLOCK 0x10 /* waiting for rsp to reading NDEF len field block */ 247#define RW_T2T_SUBSTATE_WAIT_WRITE_NDEF_LEN_BLOCK 0x11 /* waiting for rsp of updating first NDEF len field block */ 248#define RW_T2T_SUBSTATE_WAIT_WRITE_NDEF_LEN_NEXT_BLOCK 0x12 /* waiting for rsp of updating next NDEF len field block */ 249#define RW_T2T_SUBSTATE_WAIT_WRITE_TERM_TLV_CMPLT 0x13 /* waiting for rsp to writing to Terminator tlv */ 250 251/* Sub states in RW_T2T_STATE_FORMAT_TAG state */ 252#define RW_T2T_SUBSTATE_WAIT_READ_VERSION_INFO 0x14 253#define RW_T2T_SUBSTATE_WAIT_SET_CC 0x15 /* waiting for response to format/set capability container */ 254#define RW_T2T_SUBSTATE_WAIT_SET_LOCK_TLV 0x16 255#define RW_T2T_SUBSTATE_WAIT_SET_NULL_NDEF 0x17 /* waiting for response to format/set NULL NDEF */ 256 257/* Sub states in RW_T2T_STATE_SET_TAG_RO state */ 258#define RW_T2T_SUBSTATE_WAIT_SET_CC_RO 0x19 /* waiting for response to set CC3 to RO */ 259#define RW_T2T_SUBSTATE_WAIT_READ_DYN_LOCK_BYTE_BLOCK 0x1A /* waiting for response to read dynamic lock bytes block */ 260#define RW_T2T_SUBSTATE_WAIT_SET_DYN_LOCK_BITS 0x1B /* waiting for response to set dynamic lock bits */ 261#define RW_T2T_SUBSTATE_WAIT_SET_ST_LOCK_BITS 0x1C /* waiting for response to set static lock bits */ 262 263typedef struct 264{ 265 UINT16 offset; /* Offset of the lock byte in the Tag */ 266 UINT8 num_bits; /* Number of lock bits in the lock byte */ 267 UINT8 bytes_locked_per_bit; /* No. of tag bytes gets locked by a bit in this byte */ 268} tRW_T2T_LOCK_INFO; 269 270typedef struct 271{ 272 UINT16 offset; /* Reserved bytes offset taken from Memory control TLV */ 273 UINT8 num_bytes; /* Number of reserved bytes as per the TLV */ 274}tRW_T2T_RES_INFO; 275 276typedef struct 277{ 278 UINT8 tlv_index; /* Index of Lock control tlv that points to this address */ 279 UINT8 byte_index; /* Index of Lock byte pointed by the TLV */ 280 UINT8 lock_byte; /* Value in the lock byte */ 281 tRW_T2T_LOCK_STATUS lock_status; /* Indicates if it is modifed to set tag as Read only */ 282 BOOLEAN b_lock_read; /* Is the lock byte is already read from tag */ 283} tRW_T2T_LOCK; 284 285/* RW Type 2 Tag control block */ 286typedef struct 287{ 288 UINT8 state; /* Reader/writer state */ 289 UINT8 substate; /* Reader/write substate in NDEF write state */ 290 UINT8 prev_substate; /* Substate of the tag before moving to different sector */ 291 UINT8 sector; /* Sector number that is selected */ 292 UINT8 select_sector; /* Sector number that is expected to get selected */ 293 UINT8 tag_hdr[T2T_READ_DATA_LEN]; /* T2T Header blocks */ 294 UINT8 tag_data[T2T_READ_DATA_LEN]; /* T2T Block 4 - 7 data */ 295 UINT8 ndef_status; /* The current status of NDEF Write operation */ 296 UINT16 block_read; /* Read block */ 297 UINT16 block_written; /* Written block */ 298 tT2T_CMD_RSP_INFO *p_cmd_rsp_info; /* Pointer to Command rsp info of last sent command */ 299 BT_HDR *p_cur_cmd_buf; /* Copy of current command, for retx/send after sector change */ 300 BT_HDR *p_sec_cmd_buf; /* Copy of command, to send after sector change */ 301 TIMER_LIST_ENT t2_timer; /* timeout for each API call */ 302 BOOLEAN b_read_hdr; /* Tag header read from tag */ 303 BOOLEAN b_read_data; /* Tag data block read from tag */ 304 BOOLEAN b_hard_lock; /* Hard lock the tag as part of config tag to Read only */ 305#if (defined (RW_NDEF_INCLUDED) && (RW_NDEF_INCLUDED == TRUE)) 306 UINT8 found_tlv; /* The Tlv found while searching a particular TLV */ 307 UINT8 tlv_detect; /* TLV type under detection */ 308 UINT8 num_lock_tlvs; /* Number of lcok tlvs detected in the tag */ 309 UINT8 attr_seg; /* Tag segment for which attributes are prepared */ 310 UINT8 lock_attr_seg; /* Tag segment for which lock attributes are prepared */ 311 UINT8 segment; /* Current operating segment */ 312 UINT8 ndef_final_block[T2T_BLOCK_SIZE]; /* Buffer for ndef last block */ 313 UINT8 num_mem_tlvs; /* Number of memory tlvs detected in the tag */ 314 UINT8 num_lockbytes; /* Number of dynamic lock bytes present in the tag */ 315 UINT8 attr[RW_T2T_SEGMENT_SIZE]; /* byte information - Reserved/lock/otp or data */ 316 UINT8 lock_attr[RW_T2T_SEGMENT_SIZE]; /* byte information - read only or read write */ 317 UINT8 tlv_value[3]; /* Read value field of TLV */ 318 UINT8 ndef_first_block[T2T_BLOCK_LEN]; /* NDEF TLV Header block */ 319 UINT8 ndef_read_block[T2T_BLOCK_LEN]; /* Buffer to hold read before write block */ 320 UINT8 ndef_last_block[T2T_BLOCK_LEN]; /* Terminator TLV block after NDEF Write operation */ 321 UINT8 terminator_tlv_block[T2T_BLOCK_LEN];/* Terminator TLV Block */ 322 UINT16 ndef_last_block_num; /* Block where last byte of updating ndef message will exist */ 323 UINT16 ndef_read_block_num; /* Block read during NDEF Write to avoid overwritting res bytes */ 324 UINT16 bytes_count; /* No. of bytes remaining to collect during tlv detect */ 325 UINT16 terminator_byte_index; /* The offset of the tag where terminator tlv may be added */ 326 UINT16 work_offset; /* Working byte offset */ 327 UINT16 ndef_header_offset; 328 UINT16 ndef_msg_offset; /* Offset on Tag where first NDEF message is present */ 329 UINT16 ndef_msg_len; /* Lenght of NDEF Message */ 330 UINT16 new_ndef_msg_len; /* Lenght of new updating NDEF Message */ 331 UINT16 ndef_write_block; 332 UINT16 prop_msg_len; /* Proprietary tlv length */ 333 UINT8 *p_new_ndef_buffer; /* Pointer to updating NDEF Message */ 334 UINT8 *p_ndef_buffer; /* Pointer to NDEF Message */ 335 tRW_T2T_LOCK_INFO lock_tlv[RW_T2T_MAX_LOCK_TLVS]; /* Information retrieved from lock control tlv */ 336 tRW_T2T_LOCK lockbyte[RW_T2T_MAX_LOCK_BYTES]; /* Dynamic Lock byte information */ 337 tRW_T2T_RES_INFO mem_tlv[RW_T2T_MAX_MEM_TLVS]; /* Information retrieved from mem tlv */ 338#endif 339} tRW_T2T_CB; 340 341/* Type 3 Tag control block */ 342typedef UINT8 tRW_T3T_RW_STATE; 343 344typedef struct 345{ 346 tNFC_STATUS status; 347 UINT8 version; /* Ver: peer version */ 348 UINT8 nbr; /* NBr: number of blocks that can be read using one Check command */ 349 UINT8 nbw; /* Nbw: number of blocks that can be written using one Update command */ 350 UINT16 nmaxb; /* Nmaxb: maximum number of blocks available for NDEF data */ 351 UINT8 writef; /* WriteFlag: 00h if writing data finished; 0Fh if writing data in progress */ 352 UINT8 rwflag; /* RWFlag: 00h NDEF is read-only; 01h if read/write available */ 353 UINT32 ln; /* Ln: actual size of stored NDEF data (in bytes) */ 354} tRW_T3T_DETECT; 355 356/* RW_T3T control block flags */ 357#define RW_T3T_FL_IS_FINAL_NDEF_SEGMENT 0x01 /* The final command for completing the NDEF read/write */ 358#define RW_T3T_FL_W4_PRESENCE_CHECK_POLL_RSP 0x02 /* Waiting for POLL response for presence check */ 359#define RW_T3T_FL_W4_GET_SC_POLL_RSP 0x04 /* Waiting for POLL response for RW_T3tGetSystemCodes */ 360#define RW_T3T_FL_W4_NDEF_DETECT_POLL_RSP 0x08 /* Waiting for POLL response for RW_T3tDetectNDef */ 361#define RW_T3T_FL_W4_FMT_FELICA_LITE_POLL_RSP 0x10 /* Waiting for POLL response for RW_T3tFormat */ 362 363typedef struct 364{ 365 UINT32 cur_tout; /* Current command timeout */ 366 tRW_T3T_RW_STATE rw_state; /* Reader/writer state */ 367 UINT8 rw_substate; 368 UINT8 cur_cmd; /* Current command being executed */ 369 BT_HDR *p_cur_cmd_buf; /* Copy of current command, for retransmission */ 370 TIMER_LIST_ENT timer; /* timeout for waiting for response */ 371 TIMER_LIST_ENT poll_timer; /* timeout for waiting for response */ 372 373 tRW_T3T_DETECT ndef_attrib; /* T3T NDEF attribute information */ 374 375 UINT32 ndef_msg_len; /* Length of ndef message to send */ 376 UINT32 ndef_msg_bytes_sent; /* Length of ndef message sent so far */ 377 UINT8 *ndef_msg; /* Buffer for outgoing NDEF message */ 378 UINT32 ndef_rx_readlen; /* Number of bytes read in current CHECK command */ 379 UINT32 ndef_rx_offset; /* Length of ndef message read so far */ 380 381 UINT8 num_system_codes; /* System codes detected */ 382 UINT16 system_codes[T3T_MAX_SYSTEM_CODES]; 383 384 UINT8 peer_nfcid2[NCI_NFCID2_LEN]; 385 UINT8 cur_poll_rc; /* RC used in current POLL command */ 386 387 UINT8 flags; /* Flags see RW_T3T_FL_* */ 388} tRW_T3T_CB; 389 390 391/* 392** Type 4 Tag 393*/ 394 395/* Max data size using a single ReadBinary. 2 bytes are for status bytes */ 396#define RW_T4T_MAX_DATA_PER_READ (NFC_RW_POOL_BUF_SIZE - BT_HDR_SIZE - NCI_DATA_HDR_SIZE - T4T_RSP_STATUS_WORDS_SIZE) 397 398/* Max data size using a single UpdateBinary. 6 bytes are for CLA, INS, P1, P2, Lc */ 399#define RW_T4T_MAX_DATA_PER_WRITE (NFC_RW_POOL_BUF_SIZE - BT_HDR_SIZE - NCI_MSG_OFFSET_SIZE - NCI_DATA_HDR_SIZE - T4T_CMD_MAX_HDR_SIZE) 400 401 402 403/* Mandatory NDEF file control */ 404typedef struct 405{ 406 UINT16 file_id; /* File Identifier */ 407 UINT16 max_file_size; /* Max NDEF file size */ 408 UINT8 read_access; /* read access condition */ 409 UINT8 write_access; /* write access condition */ 410} tRW_T4T_NDEF_FC; 411 412/* Capability Container */ 413typedef struct 414{ 415 UINT16 cclen; /* the size of this capability container */ 416 UINT8 version; /* the mapping specification version */ 417 UINT16 max_le; /* the max data size by a single ReadBinary */ 418 UINT16 max_lc; /* the max data size by a single UpdateBinary */ 419 tRW_T4T_NDEF_FC ndef_fc; /* Mandatory NDEF file control */ 420} tRW_T4T_CC; 421 422typedef UINT8 tRW_T4T_RW_STATE; 423typedef UINT8 tRW_T4T_RW_SUBSTATE; 424 425/* Type 4 Tag Control Block */ 426typedef struct 427{ 428 tRW_T4T_RW_STATE state; /* main state */ 429 tRW_T4T_RW_SUBSTATE sub_state; /* sub state */ 430 UINT8 version; /* currently effective version */ 431 TIMER_LIST_ENT timer; /* timeout for each API call */ 432 433 UINT16 ndef_length; /* length of NDEF data */ 434 UINT8 *p_update_data; /* pointer of data to update */ 435 UINT16 rw_length; /* remaining bytes to read/write */ 436 UINT16 rw_offset; /* remaining offset to read/write */ 437 BT_HDR *p_data_to_free; /* GKI buffet to delete after done */ 438 439 tRW_T4T_CC cc_file; /* Capability Container File */ 440 441#define RW_T4T_NDEF_STATUS_NDEF_DETECTED 0x01 /* NDEF has been detected */ 442#define RW_T4T_NDEF_STATUS_NDEF_READ_ONLY 0x02 /* NDEF file is read-only */ 443 444 UINT8 ndef_status; /* bitmap for NDEF status */ 445 446 UINT16 max_read_size; /* max reading size per a command */ 447 UINT16 max_update_size; /* max updating size per a command */ 448} tRW_T4T_CB; 449 450/* RW retransmission statistics */ 451#if (defined (RW_STATS_INCLUDED) && (RW_STATS_INCLUDED == TRUE)) 452typedef struct 453{ 454 UINT32 start_tick; /* System tick count at activation */ 455 UINT32 bytes_sent; /* Total bytes sent since activation */ 456 UINT32 bytes_received; /* Total bytes received since activation */ 457 UINT32 num_ops; /* Number of operations since activation */ 458 UINT32 num_retries; /* Number of retranmissions since activation */ 459 UINT32 num_crc; /* Number of crc failures */ 460 UINT32 num_trans_err; /* Number of transmission error notifications */ 461 UINT32 num_fail; /* Number of aborts (failures after retries) */ 462} tRW_STATS; 463#endif /* RW_STATS_INCLUDED */ 464 465/* ISO 15693 RW Control Block */ 466typedef UINT8 tRW_I93_RW_STATE; 467typedef UINT8 tRW_I93_RW_SUBSTATE; 468 469#define RW_I93_FLAG_READ_ONLY 0x01 /* tag is read-only */ 470#define RW_I93_FLAG_READ_MULTI_BLOCK 0x02 /* tag supports read multi block */ 471#define RW_I93_FLAG_RESET_DSFID 0x04 /* need to reset DSFID for formatting */ 472#define RW_I93_FLAG_RESET_AFI 0x08 /* need to reset AFI for formatting */ 473 474#define RW_I93_TLV_DETECT_STATE_TYPE 0x01 /* searching for type */ 475#define RW_I93_TLV_DETECT_STATE_LENGTH_1 0x02 /* searching for the first byte of length */ 476#define RW_I93_TLV_DETECT_STATE_LENGTH_2 0x03 /* searching for the second byte of length */ 477#define RW_I93_TLV_DETECT_STATE_LENGTH_3 0x04 /* searching for the third byte of length */ 478#define RW_I93_TLV_DETECT_STATE_VALUE 0x05 /* reading value field */ 479 480enum 481{ 482 RW_I93_ICODE_SLI, /* ICODE SLI, SLIX */ 483 RW_I93_ICODE_SLI_S, /* ICODE SLI-S, SLIX-S */ 484 RW_I93_ICODE_SLI_L, /* ICODE SLI-L, SLIX-L */ 485 RW_I93_TAG_IT_HF_I_PLUS_INLAY, /* Tag-it HF-I Plus Inlay */ 486 RW_I93_TAG_IT_HF_I_PLUS_CHIP, /* Tag-it HF-I Plus Chip */ 487 RW_I93_TAG_IT_HF_I_STD_CHIP_INLAY, /* Tag-it HF-I Standard Chip/Inlyas */ 488 RW_I93_TAG_IT_HF_I_PRO_CHIP_INLAY, /* Tag-it HF-I Pro Chip/Inlyas */ 489 RW_I93_UNKNOWN_PRODUCT /* Unknwon product version */ 490}; 491 492typedef struct 493{ 494 tRW_I93_RW_STATE state; /* main state */ 495 tRW_I93_RW_SUBSTATE sub_state; /* sub state */ 496 TIMER_LIST_ENT timer; /* timeout for each sent command */ 497 UINT8 sent_cmd; /* last sent command */ 498 499 UINT8 info_flags; /* information flags */ 500 UINT8 uid[I93_UID_BYTE_LEN]; /* UID of currently activated */ 501 UINT8 dsfid; /* DSFID if I93_INFO_FLAG_DSFID */ 502 UINT8 afi; /* AFI if I93_INFO_FLAG_AFI */ 503 UINT8 block_size; /* block size of tag, in bytes */ 504 UINT16 num_block; /* number of blocks in tag */ 505 UINT8 ic_reference; /* IC Reference of tag */ 506 UINT8 product_version; /* tag product version */ 507 508 UINT8 intl_flags; /* flags for internal information */ 509 510 UINT8 tlv_detect_state; /* TLV detecting state */ 511 UINT8 tlv_type; /* currently detected type */ 512 UINT16 tlv_length; /* currently detected length */ 513 514 UINT16 ndef_tlv_start_offset; /* offset of first byte of NDEF TLV */ 515 UINT16 ndef_tlv_last_offset; /* offset of last byte of NDEF TLV */ 516 UINT16 max_ndef_length; /* max NDEF length the tag contains */ 517 UINT16 ndef_length; /* length of NDEF data */ 518 519 UINT8 *p_update_data; /* pointer of data to update */ 520 UINT16 rw_length; /* bytes to read/write */ 521 UINT16 rw_offset; /* offset to read/write */ 522} tRW_I93_CB; 523 524/* RW memory control blocks */ 525typedef union 526{ 527 tRW_T1T_CB t1t; 528 tRW_T2T_CB t2t; 529 tRW_T3T_CB t3t; 530 tRW_T4T_CB t4t; 531 tRW_I93_CB i93; 532} tRW_TCB; 533 534/* RW control blocks */ 535typedef struct 536{ 537 tRW_TCB tcb; 538 tRW_CBACK *p_cback; 539 UINT32 cur_retry; /* Retry count for the current operation */ 540#if (defined (RW_STATS_INCLUDED) && (RW_STATS_INCLUDED == TRUE)) 541 tRW_STATS stats; 542#endif /* RW_STATS_INCLUDED */ 543 UINT8 trace_level; 544} tRW_CB; 545 546 547/***************************************************************************** 548** EXTERNAL FUNCTION DECLARATIONS 549*****************************************************************************/ 550 551#ifdef __cplusplus 552extern "C" { 553#endif 554 555/* Global NFC data */ 556#if NFC_DYNAMIC_MEMORY == FALSE 557NFC_API extern tRW_CB rw_cb; 558#else 559NFC_API extern tRW_CB *rw_cb_ptr; 560#define rw_cb (*rw_cb_ptr) 561#endif 562 563/* from .c */ 564 565#if (defined (RW_NDEF_INCLUDED) && (RW_NDEF_INCLUDED == TRUE)) 566extern tRW_EVENT rw_t1t_handle_rsp (const tT1T_CMD_RSP_INFO * p_info, BOOLEAN *p_notify, UINT8 *p_data, tNFC_STATUS *p_status); 567extern tRW_EVENT rw_t1t_info_to_event (const tT1T_CMD_RSP_INFO * p_info); 568#else 569#define rw_t1t_handle_rsp (p, a, b, c) t1t_info_to_evt (p) 570#define rw_t1t_info_to_event (p) t1t_info_to_evt (p) 571#endif 572 573extern void rw_init (void); 574extern tNFC_STATUS rw_t1t_select (UINT8 hr[T1T_HR_LEN], UINT8 uid[T1T_CMD_UID_LEN]); 575extern tNFC_STATUS rw_t1t_send_dyn_cmd (UINT8 opcode, UINT8 add, UINT8 *p_dat); 576extern tNFC_STATUS rw_t1t_send_static_cmd (UINT8 opcode, UINT8 add, UINT8 dat); 577extern void rw_t1t_process_timeout (TIMER_LIST_ENT *p_tle); 578extern void rw_t1t_handle_op_complete (void); 579 580#if (defined (RW_NDEF_INCLUDED) && (RW_NDEF_INCLUDED == TRUE)) 581extern tRW_EVENT rw_t2t_info_to_event (const tT2T_CMD_RSP_INFO *p_info); 582extern void rw_t2t_handle_rsp (UINT8 *p_data); 583#else 584#define rw_t2t_info_to_event (p) t2t_info_to_evt (p) 585#define rw_t2t_handle_rsp (p) 586#endif 587 588extern tNFC_STATUS rw_t2t_sector_change (UINT8 sector); 589extern tNFC_STATUS rw_t2t_read (UINT16 block); 590extern tNFC_STATUS rw_t2t_write (UINT16 block, UINT8 *p_write_data); 591extern void rw_t2t_process_timeout (TIMER_LIST_ENT *p_tle); 592extern tNFC_STATUS rw_t2t_select (void); 593void rw_t2t_handle_op_complete (void); 594 595extern void rw_t3t_process_timeout (TIMER_LIST_ENT *p_tle); 596extern tNFC_STATUS rw_t3t_select (UINT8 peer_nfcid2[NCI_RF_F_UID_LEN], UINT8 mrti_check, UINT8 mrti_update); 597void rw_t3t_handle_nci_poll_ntf (UINT8 nci_status, UINT8 num_responses, UINT8 sensf_res_buf_size, UINT8 *p_sensf_res_buf); 598 599extern tNFC_STATUS rw_t4t_select (void); 600extern void rw_t4t_process_timeout (TIMER_LIST_ENT *p_tle); 601 602extern tNFC_STATUS rw_i93_select (void); 603extern void rw_i93_process_timeout (TIMER_LIST_ENT *p_tle); 604 605#if (defined (RW_STATS_INCLUDED) && (RW_STATS_INCLUDED == TRUE)) 606/* Internal fcns for statistics (from rw_main.c) */ 607void rw_main_reset_stats (void); 608void rw_main_update_tx_stats (UINT32 bytes_tx, BOOLEAN is_retry); 609void rw_main_update_rx_stats (UINT32 bytes_rx); 610void rw_main_update_crc_error_stats (void); 611void rw_main_update_trans_error_stats (void); 612void rw_main_update_fail_stats (void); 613void rw_main_log_stats (void); 614#endif /* RW_STATS_INCLUDED */ 615 616#ifdef __cplusplus 617} 618#endif 619 620#endif /* RW_INT_H_ */ 621