1 /****************************************************************************** 2 * 3 * Copyright (C) 2009-2014 Broadcom Corporation 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at: 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 ******************************************************************************/ 18 19 /****************************************************************************** 20 * 21 * This file contains the Near Field Communication (NFC) Reader/Writer mode 22 * related internal function / definitions. 23 * 24 ******************************************************************************/ 25 26 #ifndef RW_INT_H_ 27 #define RW_INT_H_ 28 29 #include "rw_api.h" 30 #include "tags_defs.h" 31 #include "tags_int.h" 32 33 /* Proprietary definitions for HR0 and HR1 */ 34 /* TOPAZ96 Tag */ 35 #define RW_T1T_IS_TOPAZ96 0x11 36 /* TOPAZ512 Tag */ 37 #define RW_T1T_IS_TOPAZ512 0x12 38 /* Supports dynamic commands on static tag if HR1 > 0x49 */ 39 #define RW_T1T_HR1_MIN 0x49 40 41 /* Maximum supported Memory control TLVS in the tag */ 42 #define RW_T1T_MAX_MEM_TLVS 0x05 43 /* Maximum supported Lock control TLVS in the tag */ 44 #define RW_T1T_MAX_LOCK_TLVS 0x05 45 /* Maximum supported dynamic lock bytes */ 46 #define RW_T1T_MAX_LOCK_BYTES 0x1E 47 48 /* State of the Tag as interpreted by RW */ 49 /* TAG State is unknown to RW */ 50 #define RW_T1_TAG_ATTRB_UNKNOWN 0x00 51 /* TAG is in INITIALIZED state */ 52 #define RW_T1_TAG_ATTRB_INITIALIZED 0x01 53 /* TAG is in INITIALIZED state and has NDEF tlv with len=0 */ 54 #define RW_T1_TAG_ATTRB_INITIALIZED_NDEF 0x02 55 /* TAG is in READ ONLY state */ 56 #define RW_T1_TAG_ATTRB_READ_ONLY 0x03 57 /* TAG is in READ WRITE state */ 58 #define RW_T1_TAG_ATTRB_READ_WRITE 0x04 59 60 /* Lock not yet set as part of SET TAG RO op */ 61 #define RW_T1T_LOCK_NOT_UPDATED 0x00 62 /* Sent command to set the Lock bytes */ 63 #define RW_T1T_LOCK_UPDATE_INITIATED 0x01 64 /* Lock bytes are set */ 65 #define RW_T1T_LOCK_UPDATED 0x02 66 typedef uint8_t tRW_T1T_LOCK_STATUS; 67 68 /* States */ 69 /* Tag not activated and or response not received for RID */ 70 #define RW_T1T_STATE_NOT_ACTIVATED 0x00 71 /* T1 Tag activated and ready to perform rw operation on Tag*/ 72 #define RW_T1T_STATE_IDLE 0x01 73 /* waiting rsp for read command sent to tag */ 74 #define RW_T1T_STATE_READ 0x02 75 /* waiting rsp for write command sent to tag */ 76 #define RW_T1T_STATE_WRITE 0x03 77 /* performing TLV detection procedure */ 78 #define RW_T1T_STATE_TLV_DETECT 0x04 79 /* performing read NDEF procedure */ 80 #define RW_T1T_STATE_READ_NDEF 0x05 81 /* performing update NDEF procedure */ 82 #define RW_T1T_STATE_WRITE_NDEF 0x06 83 /* Setting Tag as read only tag */ 84 #define RW_T1T_STATE_SET_TAG_RO 0x07 85 /* Check if Tag is still present */ 86 #define RW_T1T_STATE_CHECK_PRESENCE 0x08 87 /* Format T1 Tag */ 88 #define RW_T1T_STATE_FORMAT_TAG 0x09 89 90 /* Sub states */ 91 /* Default substate */ 92 #define RW_T1T_SUBSTATE_NONE 0x00 93 94 /* Sub states in RW_T1T_STATE_TLV_DETECT state */ 95 /* waiting for the detection of a tlv in a tag */ 96 #define RW_T1T_SUBSTATE_WAIT_TLV_DETECT 0x01 97 /* waiting for finding the len field is 1 or 3 bytes long */ 98 #define RW_T1T_SUBSTATE_WAIT_FIND_LEN_FIELD_LEN 0x02 99 /* waiting for extracting len field value */ 100 #define RW_T1T_SUBSTATE_WAIT_READ_TLV_LEN0 0x03 101 /* waiting for extracting len field value */ 102 #define RW_T1T_SUBSTATE_WAIT_READ_TLV_LEN1 0x04 103 /* waiting for extracting value field in the TLV */ 104 #define RW_T1T_SUBSTATE_WAIT_READ_TLV_VALUE 0x05 105 /* waiting for reading dynamic locks in the TLV */ 106 #define RW_T1T_SUBSTATE_WAIT_READ_LOCKS 0x06 107 108 /* Sub states in RW_T1T_STATE_WRITE_NDEF state */ 109 /* waiting for response of reading a block that will be partially updated */ 110 #define RW_T1T_SUBSTATE_WAIT_READ_NDEF_BLOCK 0x07 111 /* waiting for response of invalidating NDEF Msg */ 112 #define RW_T1T_SUBSTATE_WAIT_INVALIDATE_NDEF 0x08 113 /* waiting for response of writing a part of NDEF Msg */ 114 #define RW_T1T_SUBSTATE_WAIT_NDEF_WRITE 0x09 115 /* waiting for response of writing last part of NDEF Msg */ 116 #define RW_T1T_SUBSTATE_WAIT_NDEF_UPDATED 0x0A 117 /* waiting for response of validating NDEF Msg */ 118 #define RW_T1T_SUBSTATE_WAIT_VALIDATE_NDEF 0x0B 119 120 /* Sub states in RW_T1T_STATE_SET_TAG_RO state */ 121 /* waiting for response of setting CC-RWA to read only */ 122 #define RW_T1T_SUBSTATE_WAIT_SET_CC_RWA_RO 0x0C 123 /* waiting for response of setting all static lock bits */ 124 #define RW_T1T_SUBSTATE_WAIT_SET_ST_LOCK_BITS 0x0D 125 /* waiting for response of setting all dynamic lock bits */ 126 #define RW_T1T_SUBSTATE_WAIT_SET_DYN_LOCK_BITS 0x0E 127 128 /* Sub states in RW_T1T_STATE_FORMAT_TAG state */ 129 /* waiting for response to format/set capability container */ 130 #define RW_T1T_SUBSTATE_WAIT_SET_CC 0x0F 131 /* waiting for response to format/set NULL NDEF */ 132 #define RW_T1T_SUBSTATE_WAIT_SET_NULL_NDEF 0x10 133 134 typedef struct { 135 uint16_t offset; /* Offset of the lock byte in the Tag */ 136 uint8_t num_bits; /* Number of lock bits in the lock byte */ 137 uint8_t bytes_locked_per_bit; /* No. of tag bytes gets locked by a bit in this 138 byte */ 139 } tRW_T1T_LOCK_INFO; 140 141 typedef struct { 142 uint16_t offset; /* Reserved bytes offset taken from Memory control TLV */ 143 uint8_t num_bytes; /* Number of reserved bytes as per the TLV */ 144 } tRW_T1T_RES_INFO; 145 146 typedef struct { 147 uint8_t tlv_index; /* Index of Lock control tlv that points to this address*/ 148 uint8_t byte_index; /* Index of Lock byte pointed by the TLV */ 149 uint8_t lock_byte; /* Value in the lock byte */ 150 tRW_T1T_LOCK_STATUS 151 lock_status; /* Indicates if it is modifed to set tag as Read only */ 152 bool b_lock_read; /* Is the lock byte is already read from tag */ 153 } tRW_T1T_LOCK; 154 155 typedef struct { 156 uint8_t addr; /* ADD/ADD8/ADDS field value */ 157 uint8_t op_code; /* Command sent */ 158 uint8_t rsp_len; /* expected length of the response */ 159 uint8_t 160 pend_retx_rsp; /* Number of pending rsps to retransmission on prev cmd */ 161 } tRW_T1T_PREV_CMD_RSP_INFO; 162 163 #if (RW_NDEF_INCLUDED == TRUE) 164 /* Buffer 0-E block, for easier tlv operation */ 165 #define T1T_BUFFER_SIZE T1T_STATIC_SIZE 166 #else 167 /* Buffer UID */ 168 #define T1T_BUFFER_SIZE T1T_UID_LEN 169 #endif 170 171 /* RW Type 1 Tag control blocks */ 172 typedef struct { 173 uint8_t 174 hr[T1T_HR_LEN]; /* Header ROM byte 0 - 0x1y,Header ROM byte 1 - 0x00 */ 175 uint8_t mem[T1T_SEGMENT_SIZE]; /* Tag contents of block 0 or from block 0-E */ 176 tT1T_CMD_RSP_INFO* 177 p_cmd_rsp_info; /* Pointer to Command rsp info of last sent command */ 178 uint8_t state; /* Current state of RW module */ 179 uint8_t tag_attribute; /* Present state of the Tag as interpreted by RW */ 180 NFC_HDR* 181 p_cur_cmd_buf; /* Buffer to hold cur sent command for retransmission */ 182 uint8_t addr; /* ADD/ADD8/ADDS value */ 183 tRW_T1T_PREV_CMD_RSP_INFO 184 prev_cmd_rsp_info; /* Information about previous sent command if retx */ 185 TIMER_LIST_ENT timer; /* timer to set timelimit for the response to command */ 186 bool b_update; /* Tag header updated */ 187 bool b_rseg; /* Segment 0 read from tag */ 188 bool b_hard_lock; /* Hard lock the tag as part of config tag to Read only */ 189 #if (RW_NDEF_INCLUDED == TRUE) 190 uint8_t segment; /* Current Tag segment */ 191 uint8_t substate; /* Current substate of RW module */ 192 uint16_t work_offset; /* Working byte offset */ 193 uint8_t ndef_first_block[T1T_BLOCK_SIZE]; /* Buffer for ndef first block */ 194 uint8_t ndef_final_block[T1T_BLOCK_SIZE]; /* Buffer for ndef last block */ 195 uint8_t* p_ndef_buffer; /* Buffer to store ndef message */ 196 uint16_t new_ndef_msg_len; /* Lenght of new updating NDEF Message */ 197 uint8_t block_read; /* Last read Block */ 198 uint8_t write_byte; /* Index of last written byte */ 199 uint8_t tlv_detect; /* TLV type under detection */ 200 uint16_t ndef_msg_offset; /* The offset on Tag where first NDEF message is 201 present*/ 202 uint16_t ndef_msg_len; /* Lenght of NDEF Message */ 203 uint16_t 204 max_ndef_msg_len; /* Maximum size of NDEF that can be written on the tag 205 */ 206 uint16_t ndef_header_offset; /* The offset on Tag where first NDEF tlv is 207 present */ 208 uint8_t ndef_block_written; /* Last block where NDEF bytes are written */ 209 uint8_t num_ndef_finalblock; /* Block number where NDEF's last byte will be 210 present */ 211 uint8_t num_lock_tlvs; /* Number of lcok tlvs detected in the tag */ 212 tRW_T1T_LOCK_INFO lock_tlv[RW_T1T_MAX_LOCK_TLVS]; /* Information retrieved 213 from lock control tlv */ 214 uint8_t num_lockbytes; /* Number of dynamic lock bytes present in the tag */ 215 tRW_T1T_LOCK 216 lockbyte[RW_T1T_MAX_LOCK_BYTES]; /* Dynamic Lock byte information */ 217 uint8_t num_mem_tlvs; /* Number of memory tlvs detected in the tag */ 218 tRW_T1T_RES_INFO 219 mem_tlv[RW_T1T_MAX_MEM_TLVS]; /* Information retrieved from mem tlv */ 220 uint8_t attr_seg; /* Tag segment for which attributes are prepared */ 221 uint8_t 222 lock_attr_seg; /* Tag segment for which lock attributes are prepared */ 223 uint8_t 224 attr[T1T_BLOCKS_PER_SEGMENT]; /* byte information - Reserved/lock/otp or 225 data */ 226 uint8_t lock_attr 227 [T1T_BLOCKS_PER_SEGMENT]; /* byte information - read only or read write */ 228 #endif 229 } tRW_T1T_CB; 230 231 /* Mifare Ultalight/ Ultralight Family blank tag version block settings */ 232 /* Block where version number of the tag is stored */ 233 #define T2T_MIFARE_VERSION_BLOCK 0x04 234 /* Blank Ultralight tag - Block 4 (byte 0, byte 1) */ 235 #define T2T_MIFARE_ULTRALIGHT_VER_NO 0xFFFF 236 /* Blank Ultralight family tag - Block 4 (byte 0, byte 1) */ 237 #define T2T_MIFARE_ULTRALIGHT_FAMILY_VER_NO 0x0200 238 239 /* Infineon my-d move / my-d blank tag uid block settings */ 240 #define T2T_INFINEON_VERSION_BLOCK 0x00 241 #define T2T_INFINEON_MYD_MOVE_LEAN 0x0570 242 #define T2T_INFINEON_MYD_MOVE 0x0530 243 244 #define T2T_BRCM_VERSION_BLOCK 0x00 245 #define T2T_BRCM_STATIC_MEM 0x2E01 246 #define T2T_BRCM_DYNAMIC_MEM 0x2E02 247 248 #define T2T_NDEF_NOT_DETECTED 0x00 249 #define T2T_NDEF_DETECTED 0x01 250 #define T2T_NDEF_READ 0x02 251 252 /* Maximum supported Memory control TLVS in the tag */ 253 #define RW_T2T_MAX_MEM_TLVS 0x05 254 /* Maximum supported Lock control TLVS in the tag */ 255 #define RW_T2T_MAX_LOCK_TLVS 0x05 256 /* Maximum supported dynamic lock bytes */ 257 #define RW_T2T_MAX_LOCK_BYTES 0x20 258 #define RW_T2T_SEGMENT_BYTES 128 259 #define RW_T2T_SEGMENT_SIZE 16 260 261 /* Lock not yet set as part of SET TAG RO op */ 262 #define RW_T2T_LOCK_NOT_UPDATED 0x00 263 /* Sent command to set the Lock bytes */ 264 #define RW_T2T_LOCK_UPDATE_INITIATED 0x01 265 /* Lock bytes are set */ 266 #define RW_T2T_LOCK_UPDATED 0x02 267 typedef uint8_t tRW_T2T_LOCK_STATUS; 268 269 /* States */ 270 /* Tag not activated */ 271 #define RW_T2T_STATE_NOT_ACTIVATED 0x00 272 /* T1 Tag activated and ready to perform rw operation on Tag*/ 273 #define RW_T2T_STATE_IDLE 0x01 274 /* waiting response for read command sent to tag */ 275 #define RW_T2T_STATE_READ 0x02 276 /* waiting response for write command sent to tag */ 277 #define RW_T2T_STATE_WRITE 0x03 278 /* Waiting response for sector select command */ 279 #define RW_T2T_STATE_SELECT_SECTOR 0x04 280 /* Detecting Lock/Memory/NDEF/Proprietary TLV in the Tag */ 281 #define RW_T2T_STATE_DETECT_TLV 0x05 282 /* Performing NDEF Read procedure */ 283 #define RW_T2T_STATE_READ_NDEF 0x06 284 /* Performing NDEF Write procedure */ 285 #define RW_T2T_STATE_WRITE_NDEF 0x07 286 /* Setting Tag as Read only tag */ 287 #define RW_T2T_STATE_SET_TAG_RO 0x08 288 /* Check if Tag is still present */ 289 #define RW_T2T_STATE_CHECK_PRESENCE 0x09 290 /* Format the tag */ 291 #define RW_T2T_STATE_FORMAT_TAG 0x0A 292 /* Tag is in HALT State */ 293 #define RW_T2T_STATE_HALT 0x0B 294 295 /* rw_t2t_read/rw_t2t_write takes care of sector change if the block to 296 * read/write is in a different sector 297 * Next Substate should be assigned to control variable 'substate' before 298 * calling these function for State Machine to 299 * move back to the particular substate after Sector change is completed and 300 * read/write command is sent on new sector */ 301 302 /* Sub states */ 303 #define RW_T2T_SUBSTATE_NONE 0x00 304 305 /* Sub states in RW_T2T_STATE_SELECT_SECTOR state */ 306 /* waiting for response of sector select CMD 1 */ 307 #define RW_T2T_SUBSTATE_WAIT_SELECT_SECTOR_SUPPORT 0x01 308 /* waiting for response of sector select CMD 2 */ 309 #define RW_T2T_SUBSTATE_WAIT_SELECT_SECTOR 0x02 310 311 /* Sub states in RW_T1T_STATE_DETECT_XXX state */ 312 /* waiting for the detection of a tlv in a tag */ 313 #define RW_T2T_SUBSTATE_WAIT_READ_CC 0x03 314 /* waiting for the detection of a tlv in a tag */ 315 #define RW_T2T_SUBSTATE_WAIT_TLV_DETECT 0x04 316 /* waiting for finding the len field is 1 or 3 bytes long */ 317 #define RW_T2T_SUBSTATE_WAIT_FIND_LEN_FIELD_LEN 0x05 318 /* waiting for extracting len field value */ 319 #define RW_T2T_SUBSTATE_WAIT_READ_TLV_LEN0 0x06 320 /* waiting for extracting len field value */ 321 #define RW_T2T_SUBSTATE_WAIT_READ_TLV_LEN1 0x07 322 /* waiting for extracting value field in the TLV */ 323 #define RW_T2T_SUBSTATE_WAIT_READ_TLV_VALUE 0x08 324 /* waiting for reading dynamic locks in the TLV */ 325 #define RW_T2T_SUBSTATE_WAIT_READ_LOCKS 0x09 326 327 /* Sub states in RW_T2T_STATE_WRITE_NDEF state */ 328 /* waiting for rsp to reading the block where NDEF starts */ 329 #define RW_T2T_SUBSTATE_WAIT_READ_NDEF_FIRST_BLOCK 0x0A 330 /* waiting for rsp to reading block where new NDEF Msg ends */ 331 #define RW_T2T_SUBSTATE_WAIT_READ_NDEF_LAST_BLOCK 0x0B 332 /* waiting for rsp to reading block where Trm tlv gets added*/ 333 #define RW_T2T_SUBSTATE_WAIT_READ_TERM_TLV_BLOCK 0x0C 334 /* waiting for rsp to reading block where nxt NDEF write */ 335 #define RW_T2T_SUBSTATE_WAIT_READ_NDEF_NEXT_BLOCK 0x0D 336 /* waiting for rsp to writting NDEF block */ 337 #define RW_T2T_SUBSTATE_WAIT_WRITE_NDEF_NEXT_BLOCK 0x0E 338 /* waiting for rsp to last NDEF block write cmd */ 339 #define RW_T2T_SUBSTATE_WAIT_WRITE_NDEF_LAST_BLOCK 0x0F 340 /* waiting for rsp to reading NDEF len field block */ 341 #define RW_T2T_SUBSTATE_WAIT_READ_NDEF_LEN_BLOCK 0x10 342 /* waiting for rsp of updating first NDEF len field block */ 343 #define RW_T2T_SUBSTATE_WAIT_WRITE_NDEF_LEN_BLOCK 0x11 344 /* waiting for rsp of updating next NDEF len field block */ 345 #define RW_T2T_SUBSTATE_WAIT_WRITE_NDEF_LEN_NEXT_BLOCK 0x12 346 /* waiting for rsp to writing to Terminator tlv */ 347 #define RW_T2T_SUBSTATE_WAIT_WRITE_TERM_TLV_CMPLT 0x13 348 349 /* Sub states in RW_T2T_STATE_FORMAT_TAG state */ 350 #define RW_T2T_SUBSTATE_WAIT_READ_VERSION_INFO 0x14 351 /* waiting for response to format/set capability container */ 352 #define RW_T2T_SUBSTATE_WAIT_SET_CC 0x15 353 #define RW_T2T_SUBSTATE_WAIT_SET_LOCK_TLV 0x16 354 /* waiting for response to format/set NULL NDEF */ 355 #define RW_T2T_SUBSTATE_WAIT_SET_NULL_NDEF 0x17 356 357 /* Sub states in RW_T2T_STATE_SET_TAG_RO state */ 358 /* waiting for response to set CC3 to RO */ 359 #define RW_T2T_SUBSTATE_WAIT_SET_CC_RO 0x19 360 /* waiting for response to read dynamic lock bytes block */ 361 #define RW_T2T_SUBSTATE_WAIT_READ_DYN_LOCK_BYTE_BLOCK 0x1A 362 /* waiting for response to set dynamic lock bits */ 363 #define RW_T2T_SUBSTATE_WAIT_SET_DYN_LOCK_BITS 0x1B 364 365 typedef struct { 366 uint16_t offset; /* Offset of the lock byte in the Tag */ 367 uint16_t num_bits; /* Number of lock bits in the lock byte */ 368 uint16_t bytes_locked_per_bit; /* No. of tag bytes gets locked by a bit 369 in this byte */ 370 } tRW_T2T_LOCK_INFO; 371 372 typedef struct { 373 uint16_t offset; /* Reserved bytes offset taken from Memory control TLV */ 374 uint16_t num_bytes; /* Number of reserved bytes as per the TLV */ 375 } tRW_T2T_RES_INFO; 376 377 typedef struct { 378 uint8_t tlv_index; /* Index of Lock control tlv that points to this address */ 379 uint8_t byte_index; /* Index of Lock byte pointed by the TLV */ 380 uint8_t lock_byte; /* Value in the lock byte */ 381 tRW_T2T_LOCK_STATUS 382 lock_status; /* Indicates if it is modifed to set tag as Read only */ 383 bool b_lock_read; /* Is the lock byte is already read from tag */ 384 } tRW_T2T_LOCK; 385 386 /* RW Type 2 Tag control block */ 387 typedef struct { 388 uint8_t state; /* Reader/writer state */ 389 uint8_t substate; /* Reader/write substate in NDEF write state */ 390 uint8_t 391 prev_substate; /* Substate of the tag before moving to different sector */ 392 uint8_t sector; /* Sector number that is selected */ 393 uint8_t select_sector; /* Sector number that is expected to get selected */ 394 uint8_t tag_hdr[T2T_READ_DATA_LEN]; /* T2T Header blocks */ 395 uint8_t tag_data[T2T_READ_DATA_LEN]; /* T2T Block 4 - 7 data */ 396 uint8_t ndef_status; /* The current status of NDEF Write operation */ 397 uint16_t block_read; /* Read block */ 398 uint16_t block_written; /* Written block */ 399 tT2T_CMD_RSP_INFO* 400 p_cmd_rsp_info; /* Pointer to Command rsp info of last sent command */ 401 NFC_HDR* p_cur_cmd_buf; /* Copy of current command, for retx/send after sector 402 change */ 403 NFC_HDR* p_sec_cmd_buf; /* Copy of command, to send after sector change */ 404 TIMER_LIST_ENT t2_timer; /* timeout for each API call */ 405 bool b_read_hdr; /* Tag header read from tag */ 406 bool b_read_data; /* Tag data block read from tag */ 407 bool b_hard_lock; /* Hard lock the tag as part of config tag to Read only */ 408 bool check_tag_halt; /* Resent command after NACK rsp to find tag is in HALT 409 State */ 410 #if (RW_NDEF_INCLUDED == TRUE) 411 bool skip_dyn_locks; /* Skip reading dynamic lock bytes from the tag */ 412 uint8_t found_tlv; /* The Tlv found while searching a particular TLV */ 413 uint8_t tlv_detect; /* TLV type under detection */ 414 uint8_t num_lock_tlvs; /* Number of lcok tlvs detected in the tag */ 415 uint8_t attr_seg; /* Tag segment for which attributes are prepared */ 416 uint8_t 417 lock_attr_seg; /* Tag segment for which lock attributes are prepared */ 418 uint8_t segment; /* Current operating segment */ 419 uint8_t ndef_final_block[T2T_BLOCK_SIZE]; /* Buffer for ndef last block */ 420 uint8_t num_mem_tlvs; /* Number of memory tlvs detected in the tag */ 421 uint8_t num_lockbytes; /* Number of dynamic lock bytes present in the tag */ 422 uint8_t attr 423 [RW_T2T_SEGMENT_SIZE]; /* byte information - Reserved/lock/otp or data */ 424 uint8_t lock_attr[RW_T2T_SEGMENT_SIZE]; /* byte information - read only or 425 read write */ 426 uint8_t tlv_value[3]; /* Read value field of TLV */ 427 uint8_t ndef_first_block[T2T_BLOCK_LEN]; /* NDEF TLV Header block */ 428 uint8_t ndef_read_block[T2T_BLOCK_LEN]; /* Buffer to hold read before write 429 block */ 430 uint8_t ndef_last_block[T2T_BLOCK_LEN]; /* Terminator TLV block after NDEF 431 Write operation */ 432 uint8_t terminator_tlv_block[T2T_BLOCK_LEN]; /* Terminator TLV Block */ 433 uint16_t ndef_last_block_num; /* Block where last byte of updating ndef 434 message will exist */ 435 uint16_t ndef_read_block_num; /* Block read during NDEF Write to avoid 436 overwritting res bytes */ 437 uint16_t 438 bytes_count; /* No. of bytes remaining to collect during tlv detect */ 439 uint16_t 440 terminator_byte_index; /* The offset of the tag where terminator tlv may 441 be added */ 442 uint16_t work_offset; /* Working byte offset */ 443 uint16_t ndef_header_offset; 444 uint16_t 445 ndef_msg_offset; /* Offset on Tag where first NDEF message is present */ 446 uint16_t ndef_msg_len; /* Lenght of NDEF Message */ 447 uint16_t 448 max_ndef_msg_len; /* Maximum size of NDEF that can be written on the tag 449 */ 450 uint16_t new_ndef_msg_len; /* Lenght of new updating NDEF Message */ 451 uint16_t ndef_write_block; 452 uint16_t prop_msg_len; /* Proprietary tlv length */ 453 uint8_t* p_new_ndef_buffer; /* Pointer to updating NDEF Message */ 454 uint8_t* p_ndef_buffer; /* Pointer to NDEF Message */ 455 tRW_T2T_LOCK_INFO lock_tlv[RW_T2T_MAX_LOCK_TLVS]; /* Information retrieved 456 from lock control tlv */ 457 tRW_T2T_LOCK 458 lockbyte[RW_T2T_MAX_LOCK_BYTES]; /* Dynamic Lock byte information */ 459 tRW_T2T_RES_INFO 460 mem_tlv[RW_T2T_MAX_MEM_TLVS]; /* Information retrieved from mem tlv */ 461 #endif 462 } tRW_T2T_CB; 463 464 /* Type 3 Tag control block */ 465 typedef uint8_t tRW_T3T_RW_STATE; 466 467 typedef struct { 468 tNFC_STATUS status; 469 uint8_t version; /* Ver: peer version */ 470 uint8_t 471 nbr; /* NBr: number of blocks that can be read using one Check command */ 472 uint8_t nbw; /* Nbw: number of blocks that can be written using one Update 473 command */ 474 uint16_t nmaxb; /* Nmaxb: maximum number of blocks available for NDEF data */ 475 uint8_t writef; /* WriteFlag: 00h if writing data finished; 0Fh if writing 476 data in progress */ 477 uint8_t 478 rwflag; /* RWFlag: 00h NDEF is read-only; 01h if read/write available */ 479 uint32_t ln; /* Ln: actual size of stored NDEF data (in bytes) */ 480 } tRW_T3T_DETECT; 481 482 /* RW_T3T control block flags */ 483 /* The final command for completing the NDEF read/write */ 484 #define RW_T3T_FL_IS_FINAL_NDEF_SEGMENT 0x01 485 /* Waiting for POLL response for presence check */ 486 #define RW_T3T_FL_W4_PRESENCE_CHECK_POLL_RSP 0x02 487 /* Waiting for POLL response for RW_T3tGetSystemCodes */ 488 #define RW_T3T_FL_W4_GET_SC_POLL_RSP 0x04 489 /* Waiting for POLL response for RW_T3tDetectNDef */ 490 #define RW_T3T_FL_W4_NDEF_DETECT_POLL_RSP 0x08 491 /* Waiting for POLL response for RW_T3tFormat */ 492 #define RW_T3T_FL_W4_FMT_FELICA_LITE_POLL_RSP 0x10 493 /* Waiting for POLL response for RW_T3tSetReadOnly */ 494 #define RW_T3T_FL_W4_SRO_FELICA_LITE_POLL_RSP 0x20 495 /* Waiting for POLL response for RW_T3tPoll */ 496 #define RW_T3T_FL_W4_USER_POLL_RSP 0x40 497 498 typedef struct { 499 uint32_t cur_tout; /* Current command timeout */ 500 /* check timeout is check_tout_a + n * check_tout_b; X is T/t3t * 4^E */ 501 uint32_t check_tout_a; /* Check command timeout (A+1)*X */ 502 uint32_t check_tout_b; /* Check command timeout (B+1)*X */ 503 /* update timeout is update_tout_a + n * update_tout_b; X is T/t3t * 4^E */ 504 uint32_t update_tout_a; /* Update command timeout (A+1)*X */ 505 uint32_t update_tout_b; /* Update command timeout (B+1)*X */ 506 tRW_T3T_RW_STATE rw_state; /* Reader/writer state */ 507 uint8_t rw_substate; 508 uint8_t cur_cmd; /* Current command being executed */ 509 NFC_HDR* p_cur_cmd_buf; /* Copy of current command, for retransmission */ 510 TIMER_LIST_ENT timer; /* timeout for waiting for response */ 511 TIMER_LIST_ENT poll_timer; /* timeout for waiting for response */ 512 513 tRW_T3T_DETECT ndef_attrib; /* T3T NDEF attribute information */ 514 515 uint32_t ndef_msg_len; /* Length of ndef message to send */ 516 uint32_t ndef_msg_bytes_sent; /* Length of ndef message sent so far */ 517 uint8_t* ndef_msg; /* Buffer for outgoing NDEF message */ 518 uint32_t ndef_rx_readlen; /* Number of bytes read in current CHECK command */ 519 uint32_t ndef_rx_offset; /* Length of ndef message read so far */ 520 521 uint8_t num_system_codes; /* System codes detected */ 522 uint16_t system_codes[T3T_MAX_SYSTEM_CODES]; 523 524 uint8_t peer_nfcid2[NCI_NFCID2_LEN]; 525 uint8_t cur_poll_rc; /* RC used in current POLL command */ 526 527 uint8_t flags; /* Flags see RW_T3T_FL_* */ 528 /* Recall System Code used in last T3T polling command */ 529 int32_t cur_active_sc; 530 } tRW_T3T_CB; 531 532 /* 533 ** Type 4 Tag 534 */ 535 536 /* Max data size using a single ReadBinary. 2 bytes are for status bytes */ 537 #define RW_T4T_MAX_DATA_PER_READ \ 538 (NFC_RW_POOL_BUF_SIZE - NFC_HDR_SIZE - NCI_DATA_HDR_SIZE - \ 539 T4T_RSP_STATUS_WORDS_SIZE) 540 541 /* Max data size using a single UpdateBinary. 6 bytes are for CLA, INS, P1, P2, 542 * Lc */ 543 /* Use worst case where Extended Field Coding and ODO format are used */ 544 #define RW_T4T_MAX_DATA_PER_WRITE \ 545 (NFC_RW_POOL_BUF_SIZE - NFC_HDR_SIZE - NCI_MSG_OFFSET_SIZE - \ 546 NCI_DATA_HDR_SIZE - T4T_CMD_MAX_EXT_HDR_SIZE) 547 548 #define RW_T4T_EXT_FIELD_CODING 0x01 549 #define RW_T4T_DDO_LC_FIELD_CODING 0x02 550 551 #define RW_T4T_BER_TLV_LENGTH_1_BYTE 0x01 552 #define RW_T4T_BER_TLV_LENGTH_2_BYTES 0x02 553 #define RW_T4T_BER_TLV_LENGTH_3_BYTES 0x03 554 555 /* Minimum data header in command APDU data: 556 * ODO: 54 00 xxyyzz: tag '54' with 3-byte offset xxyyzz 557 * DDO: 53 Ld {data to be written to the ENDEF File} 558 * Ld (data length) can be 1, 2 or 3 bytes 559 */ 560 #define RW_T4T_ODO_DDO_HEADER_MIN_LENGTH 0x06 /* ODO + tag '53' */ 561 /* Ld encoded on two bytes with '81' tag and N=0 to 255 562 * for data field length coded on one byte */ 563 #define RW_T4T_ODO_DDO_HEADER_2BYTES_LENGTH 8 /* ODO + tag '53' + '81' + N */ 564 /* Mandatory NDEF file control */ 565 typedef struct { 566 uint16_t file_id; /* File Identifier */ 567 uint32_t max_file_size; /* Max NDEF file size */ 568 uint8_t read_access; /* read access condition */ 569 uint8_t write_access; /* write access condition */ 570 uint8_t nlen_size; /* (E)NLEN size (2 or 4 bytes) */ 571 } tRW_T4T_NDEF_FC; 572 573 /* Capability Container */ 574 typedef struct { 575 uint16_t cclen; /* the size of this capability container */ 576 uint8_t version; /* the mapping specification version */ 577 uint16_t max_le; /* the max data size by a single ReadBinary */ 578 uint16_t max_lc; /* the max data size by a single UpdateBinary */ 579 tRW_T4T_NDEF_FC ndef_fc; /* Mandatory NDEF file control */ 580 } tRW_T4T_CC; 581 582 typedef uint8_t tRW_T4T_RW_STATE; 583 typedef uint8_t tRW_T4T_RW_SUBSTATE; 584 585 /* Type 4 Tag Control Block */ 586 typedef struct { 587 tRW_T4T_RW_STATE state; /* main state */ 588 tRW_T4T_RW_SUBSTATE sub_state; /* sub state */ 589 uint8_t version; /* currently effective version */ 590 TIMER_LIST_ENT timer; /* timeout for each API call */ 591 592 uint32_t ndef_length; /* length of NDEF data */ 593 uint8_t* p_update_data; /* pointer of data to update */ 594 uint32_t rw_length; /* remaining bytes to read/write */ 595 uint32_t rw_offset; /* remaining offset to read/write */ 596 597 NFC_HDR* p_data_to_free; /* GKI buffet to delete after done */ 598 599 tRW_T4T_CC cc_file; /* Capability Container File */ 600 601 /* NDEF has been detected */ 602 #define RW_T4T_NDEF_STATUS_NDEF_DETECTED 0x01 603 /* NDEF file is read-only */ 604 #define RW_T4T_NDEF_STATUS_NDEF_READ_ONLY 0x02 605 606 uint8_t ndef_status; /* bitmap for NDEF status */ 607 uint8_t channel; /* channel id: used for read-binary */ 608 609 uint16_t max_read_size; /* max reading size per a command */ 610 uint16_t max_update_size; /* max updating size per a command */ 611 uint16_t card_size; 612 uint8_t card_type; 613 uint8_t intl_flags; /* flags for internal information */ 614 } tRW_T4T_CB; 615 616 /* RW retransmission statistics */ 617 #if (RW_STATS_INCLUDED == TRUE) 618 typedef struct { 619 uint32_t start_tick; /* System tick count at activation */ 620 uint32_t bytes_sent; /* Total bytes sent since activation */ 621 uint32_t bytes_received; /* Total bytes received since activation */ 622 uint32_t num_ops; /* Number of operations since activation */ 623 uint32_t num_retries; /* Number of retranmissions since activation */ 624 uint32_t num_crc; /* Number of crc failures */ 625 uint32_t num_trans_err; /* Number of transmission error notifications */ 626 uint32_t num_fail; /* Number of aborts (failures after retries) */ 627 } tRW_STATS; 628 #endif /* RW_STATS_INCLUDED */ 629 630 /* Mifare Classic RW Control Block */ 631 632 typedef struct { 633 uint16_t block; 634 bool auth; 635 } tRW_MFC_BLOCK; 636 637 #define MFC_NDEF_NOT_DETECTED 0x00 638 #define MFC_NDEF_DETECTED 0x01 639 #define MFC_NDEF_READ 0x02 640 641 typedef uint8_t tRW_MFC_RW_STATE; 642 typedef uint8_t tRW_MFC_RW_SUBSTATE; 643 typedef struct { 644 tRW_MFC_RW_STATE state; /* main state */ 645 tRW_MFC_RW_SUBSTATE substate; /* Reader/write substate in NDEF write state*/ 646 tRW_MFC_RW_SUBSTATE 647 prev_substate; /* Reader/write substate in NDEF write state*/ 648 TIMER_LIST_ENT timer; /* timeout for each API call */ 649 uint8_t uid[4]; 650 uint8_t selres; 651 uint8_t tlv_detect; /* TLV type under detection */ 652 uint16_t ndef_length; /* length of NDEF data */ 653 uint16_t ndef_start_pos; /* NDEF start position */ 654 uint16_t ndef_first_block; /* Frst block containing the NDEF */ 655 uint8_t* p_update_data; /* pointer of data to update */ 656 uint16_t rw_length; /* remaining bytes to read/write */ 657 uint16_t rw_offset; /* remaining offset to read/write */ 658 NFC_HDR* p_data_to_free; /* GKI buffer to delete after done */ 659 tRW_MFC_BLOCK last_block_accessed; 660 tRW_MFC_BLOCK next_block; 661 uint8_t sector_authentified; 662 TIMER_LIST_ENT mfc_timer; /* timeout for each API call */ 663 uint16_t work_offset; /* Working byte offset */ 664 uint8_t* p_ndef_buffer; /* Buffer to store ndef message */ 665 uint16_t current_block; 666 NFC_HDR* p_cur_cmd_buf; /* Copy of current command, for retx/send after sector 667 change */ 668 669 uint8_t ndef_status; /* bitmap for NDEF status */ 670 } tRW_MFC_CB; 671 672 /* ISO 15693 RW Control Block */ 673 typedef uint8_t tRW_I93_RW_STATE; 674 typedef uint8_t tRW_I93_RW_SUBSTATE; 675 676 /* tag is read-only */ 677 #define RW_I93_FLAG_READ_ONLY 0x01 678 /* tag supports read multi block */ 679 #define RW_I93_FLAG_READ_MULTI_BLOCK 0x02 680 /* need to reset DSFID for formatting */ 681 #define RW_I93_FLAG_RESET_DSFID 0x04 682 /* need to reset AFI for formatting */ 683 #define RW_I93_FLAG_RESET_AFI 0x08 684 /* use 2 bytes for number of blocks */ 685 #define RW_I93_FLAG_16BIT_NUM_BLOCK 0x10 686 /* use extended commands */ 687 #define RW_I93_FLAG_EXT_COMMANDS 0x20 688 /* use Special Frame in Write-Alike commands */ 689 #define RW_I93_FLAG_SPECIAL_FRAME 0x40 690 /* use SMS bit in Selected state */ 691 #define RW_I93_FLAG_SELECTED_STATE 0x80 692 693 /* searching for type */ 694 #define RW_I93_TLV_DETECT_STATE_TYPE 0x01 695 /* searching for the first byte of length */ 696 #define RW_I93_TLV_DETECT_STATE_LENGTH_1 0x02 697 /* searching for the second byte of length */ 698 #define RW_I93_TLV_DETECT_STATE_LENGTH_2 0x03 699 /* searching for the third byte of length */ 700 #define RW_I93_TLV_DETECT_STATE_LENGTH_3 0x04 701 /* reading value field */ 702 #define RW_I93_TLV_DETECT_STATE_VALUE 0x05 703 #define RW_I93_GET_SYS_INFO_MEM_INFO 1 704 #define RW_T5T_CC_READ_MEM_INFO 0 705 706 /* capability Container CC Size */ 707 #define RW_I93_CC_SIZE 4 708 709 /* main state */ 710 enum { 711 RW_I93_STATE_NOT_ACTIVATED, /* ISO15693 is not activated */ 712 RW_I93_STATE_IDLE, /* waiting for upper layer API */ 713 RW_I93_STATE_BUSY, /* waiting for response from tag */ 714 715 RW_I93_STATE_DETECT_NDEF, /* performing NDEF detection precedure */ 716 RW_I93_STATE_READ_NDEF, /* performing read NDEF procedure */ 717 RW_I93_STATE_UPDATE_NDEF, /* performing update NDEF procedure */ 718 RW_I93_STATE_FORMAT, /* performing format procedure */ 719 RW_I93_STATE_SET_READ_ONLY, /* performing set read-only procedure */ 720 721 RW_I93_STATE_PRESENCE_CHECK /* checking presence of tag */ 722 }; 723 724 /* sub state */ 725 enum { 726 RW_I93_SUBSTATE_WAIT_UID, /* waiting for response of inventory */ 727 RW_I93_SUBSTATE_WAIT_SYS_INFO, /* waiting for response of get sys info */ 728 RW_I93_SUBSTATE_WAIT_CC, /* waiting for reading CC */ 729 RW_I93_SUBSTATE_WAIT_CC_EXT, /* waiting for reading CC second byte */ 730 RW_I93_SUBSTATE_SEARCH_NDEF_TLV, /* searching NDEF TLV */ 731 RW_I93_SUBSTATE_CHECK_LOCK_STATUS, /* check if any NDEF TLV is locked */ 732 733 RW_I93_SUBSTATE_RESET_LEN, /* set length to 0 to update NDEF TLV */ 734 RW_I93_SUBSTATE_WRITE_NDEF, /* writing NDEF and Terminator TLV */ 735 RW_I93_SUBSTATE_UPDATE_LEN, /* set length into NDEF TLV */ 736 737 RW_I93_SUBSTATE_WAIT_RESET_DSFID_AFI, /* reset DSFID and AFI */ 738 RW_I93_SUBSTATE_CHECK_READ_ONLY, /* check if any block is locked */ 739 RW_I93_SUBSTATE_WRITE_CC_NDEF_TLV, /* write CC and empty NDEF/Terminator TLV 740 */ 741 742 RW_I93_SUBSTATE_WAIT_UPDATE_CC, /* updating CC as read-only */ 743 RW_I93_SUBSTATE_LOCK_NDEF_TLV, /* lock blocks of NDEF TLV */ 744 RW_I93_SUBSTATE_WAIT_LOCK_CC, /* lock block of CC */ 745 RW_I93_SUBSTATE_LOCK_T5T_AREA /* lock blocks of T5T_Area */ 746 }; 747 748 enum { 749 RW_I93_ICODE_SLI, /* ICODE SLI, SLIX */ 750 RW_I93_ICODE_SLI_S, /* ICODE SLI-S, SLIX-S */ 751 RW_I93_ICODE_SLI_L, /* ICODE SLI-L, SLIX-L */ 752 RW_I93_TAG_IT_HF_I_PLUS_INLAY, /* Tag-it HF-I Plus Inlay */ 753 RW_I93_TAG_IT_HF_I_PLUS_CHIP, /* Tag-it HF-I Plus Chip */ 754 RW_I93_TAG_IT_HF_I_STD_CHIP_INLAY, /* Tag-it HF-I Standard Chip/Inlyas */ 755 RW_I93_TAG_IT_HF_I_PRO_CHIP_INLAY, /* Tag-it HF-I Pro Chip/Inlyas */ 756 RW_I93_STM_LRI1K, /* STM LRI1K */ 757 RW_I93_STM_LRI2K, /* STM LRI2K */ 758 RW_I93_STM_LRIS2K, /* STM LRIS2K */ 759 RW_I93_STM_LRIS64K, /* STM LRIS64K */ 760 RW_I93_STM_M24LR64_R, /* STM M24LR64-R */ 761 RW_I93_STM_M24LR04E_R, /* STM M24LR04E-R */ 762 RW_I93_STM_M24LR16E_R, /* STM M24LR16E-R */ 763 RW_I93_STM_M24LR16D_W, /* STM M24LR16D-W */ 764 RW_I93_STM_M24LR64E_R, /* STM M24LR64E-R */ 765 RW_I93_STM_ST25DV04K, /* STM ST25DV04K */ 766 RW_I93_STM_ST25DVHIK, /* STM ST25DV 16K OR 64K */ 767 RW_I93_ONS_N36RW02, /* ONS N36RW02 */ 768 RW_I93_ONS_N24RF04, /* ONS N24RF04 */ 769 RW_I93_ONS_N24RF04E, /* ONS N24RF04E */ 770 RW_I93_ONS_N24RF16, /* ONS N24RF16 */ 771 RW_I93_ONS_N24RF16E, /* ONS N24RF16E */ 772 RW_I93_ONS_N24RF64, /* ONS N24RF64 */ 773 RW_I93_ONS_N24RF64E, /* ONS N24RF64E */ 774 RW_I93_UNKNOWN_PRODUCT /* Unknwon product version */ 775 }; 776 777 typedef struct { 778 tRW_I93_RW_STATE state; /* main state */ 779 tRW_I93_RW_SUBSTATE sub_state; /* sub state */ 780 TIMER_LIST_ENT timer; /* timeout for each sent command */ 781 uint8_t sent_cmd; /* last sent command */ 782 uint8_t retry_count; /* number of retry */ 783 NFC_HDR* p_retry_cmd; /* buffer to store cmd sent last */ 784 785 uint8_t info_flags; /* information flags */ 786 uint8_t uid[I93_UID_BYTE_LEN]; /* UID of currently activated */ 787 uint8_t dsfid; /* DSFID if I93_INFO_FLAG_DSFID */ 788 uint8_t afi; /* AFI if I93_INFO_FLAG_AFI */ 789 uint8_t block_size; /* block size of tag, in bytes */ 790 uint32_t num_block; /* number of blocks in tag */ 791 uint8_t ic_reference; /* IC Reference of tag */ 792 uint8_t product_version; /* tag product version */ 793 794 uint8_t intl_flags; /* flags for internal information */ 795 796 uint8_t tlv_detect_state; /* TLV detecting state */ 797 uint8_t tlv_type; /* currently detected type */ 798 uint8_t addr_mode; 799 uint8_t i93_t5t_mode; 800 uint8_t t5t_area_start_block; /* offset of first block of T5T_Area */ 801 uint32_t t5t_area_last_offset; /* offset of last byte of T5T_Area */ 802 803 /* Greedy collection with NDEF Detection data */ 804 uint8_t gre_validity; 805 uint8_t gre_cc_content[8]; 806 uint32_t gre_ndef_tlv_pos; 807 uint32_t gre_ndef_tlv_length; 808 uint32_t tlv_length; /* currently detected length */ 809 810 uint32_t ndef_tlv_start_offset; /* offset of first byte of NDEF TLV */ 811 uint32_t ndef_tlv_last_offset; /* offset of last byte of NDEF TLV */ 812 uint32_t max_ndef_length; /* max NDEF length the tag contains */ 813 uint32_t ndef_length; /* length of NDEF data */ 814 815 uint8_t* p_update_data; /* pointer of data to update */ 816 uint32_t rw_length; /* bytes to read/write */ 817 uint32_t rw_offset; /* offset to read/write */ 818 bool in_pres_check; 819 } tRW_I93_CB; 820 821 /* RW memory control blocks */ 822 typedef union { 823 tRW_T1T_CB t1t; 824 tRW_T2T_CB t2t; 825 tRW_T3T_CB t3t; 826 tRW_T4T_CB t4t; 827 tRW_I93_CB i93; 828 tRW_MFC_CB mfc; 829 } tRW_TCB; 830 831 /* RW callback type */ 832 #define RW_CB_TYPE_UNKNOWN 0 833 #define RW_CB_TYPE_T1T 1 834 #define RW_CB_TYPE_T2T 2 835 #define RW_CB_TYPE_T3T 3 836 #define RW_CB_TYPE_T4T 4 837 #define RW_CB_TYPE_T5T 5 838 #define RW_CB_TYPE_MIFARE 6 839 typedef uint8_t tRW_CB_TYPE; 840 841 /* RW control blocks */ 842 typedef struct { 843 tRW_CB_TYPE tcb_type; 844 tRW_TCB tcb; 845 tRW_CBACK* p_cback; 846 uint32_t cur_retry; /* Retry count for the current operation */ 847 #if (RW_STATS_INCLUDED == TRUE) 848 tRW_STATS stats; 849 #endif /* RW_STATS_INCLUDED */ 850 } tRW_CB; 851 852 /***************************************************************************** 853 ** EXTERNAL FUNCTION DECLARATIONS 854 *****************************************************************************/ 855 856 /* Global NFC data */ 857 extern tRW_CB rw_cb; 858 859 /* from .c */ 860 861 #if (RW_NDEF_INCLUDED == TRUE) 862 extern tRW_EVENT rw_t1t_handle_rsp(const tT1T_CMD_RSP_INFO* p_info, 863 bool* p_notify, uint8_t* p_data, 864 tNFC_STATUS* p_status); 865 extern tRW_EVENT rw_t1t_info_to_event(const tT1T_CMD_RSP_INFO* p_info); 866 #else 867 #define rw_t1t_handle_rsp(p, a, b, c) t1t_info_to_evt(p) 868 #define rw_t1t_info_to_event(p) t1t_info_to_evt(p) 869 #endif 870 871 extern void rw_init(void); 872 extern tNFC_STATUS rw_t1t_select(uint8_t hr[T1T_HR_LEN], 873 uint8_t uid[T1T_CMD_UID_LEN]); 874 extern tNFC_STATUS rw_t1t_send_dyn_cmd(uint8_t opcode, uint8_t add, 875 uint8_t* p_dat); 876 extern tNFC_STATUS rw_t1t_send_static_cmd(uint8_t opcode, uint8_t add, 877 uint8_t dat); 878 extern void rw_t1t_process_timeout(TIMER_LIST_ENT* p_tle); 879 extern void rw_t1t_handle_op_complete(void); 880 881 #if (RW_NDEF_INCLUDED == TRUE) 882 extern tRW_EVENT rw_t2t_info_to_event(const tT2T_CMD_RSP_INFO* p_info); 883 extern void rw_t2t_handle_rsp(uint8_t* p_data); 884 #else 885 #define rw_t2t_info_to_event(p) t2t_info_to_evt(p) 886 #define rw_t2t_handle_rsp(p) 887 #endif 888 889 extern tNFC_STATUS rw_t2t_sector_change(uint8_t sector); 890 extern tNFC_STATUS rw_t2t_read(uint16_t block); 891 extern tNFC_STATUS rw_t2t_write(uint16_t block, uint8_t* p_write_data); 892 extern void rw_t2t_process_timeout(); 893 extern tNFC_STATUS rw_t2t_select(void); 894 void rw_t2t_handle_op_complete(void); 895 896 extern void rw_t3t_process_timeout(TIMER_LIST_ENT* p_tle); 897 extern tNFC_STATUS rw_t3t_select(uint8_t peer_nfcid2[NCI_RF_F_UID_LEN], 898 uint8_t mrti_check, uint8_t mrti_update); 899 void rw_t3t_handle_nci_poll_rsp(uint8_t nci_status); 900 void rw_t3t_handle_nci_poll_ntf(uint8_t nci_status, uint8_t num_responses, 901 uint8_t sensf_res_buf_size, 902 uint8_t* p_sensf_res_buf); 903 904 extern tNFC_STATUS rw_t4t_select(void); 905 extern void rw_t4t_process_timeout(TIMER_LIST_ENT* p_tle); 906 907 extern tNFC_STATUS rw_i93_select(uint8_t* p_uid); 908 extern void rw_i93_process_timeout(TIMER_LIST_ENT* p_tle); 909 extern std::string rw_i93_get_state_name(uint8_t state); 910 extern std::string rw_i93_get_sub_state_name(uint8_t sub_state); 911 extern void rw_t5t_sm_detect_ndef(NFC_HDR*); 912 extern void rw_t5t_sm_update_ndef(NFC_HDR*); 913 extern void rw_t5t_sm_set_read_only(NFC_HDR*); 914 915 extern void rw_t4t_handle_isodep_nak_rsp(uint8_t status, bool is_ntf); 916 917 extern tNFC_STATUS rw_mfc_select(uint8_t selres, uint8_t uid[T1T_CMD_UID_LEN]); 918 extern void rw_mfc_process_timeout(TIMER_LIST_ENT* p_tle); 919 #if (RW_STATS_INCLUDED == TRUE) 920 /* Internal fcns for statistics (from rw_main.c) */ 921 void rw_main_reset_stats(void); 922 void rw_main_update_tx_stats(uint32_t bytes_tx, bool is_retry); 923 void rw_main_update_rx_stats(uint32_t bytes_rx); 924 void rw_main_update_crc_error_stats(void); 925 void rw_main_update_trans_error_stats(void); 926 void rw_main_update_fail_stats(void); 927 void rw_main_log_stats(void); 928 #endif /* RW_STATS_INCLUDED */ 929 930 #endif /* RW_INT_H_ */ 931