Home | History | Annotate | Download | only in include
      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) Tags related
     22  *  definitions from the specification.
     23  *
     24  ******************************************************************************/
     25 
     26 #ifndef TAGS_DEFS_H
     27 #define TAGS_DEFS_H
     28 
     29 /* Manufacturer ID */
     30 /* BROADCOM CORPORATION                           */
     31 #define TAG_BRCM_MID 0x2E
     32 /* MIFARE                                         */
     33 #define TAG_MIFARE_MID 0x04
     34 /* KOVIO                                          */
     35 #define TAG_KOVIO_MID 0x37
     36 /* Infineon Technologies                          */
     37 #define TAG_INFINEON_MID 0x05
     38 
     39 /* TLV types present in Type1 and Type 2 Tags */
     40 /* May be used for padding. SHALL ignore this     */
     41 #define TAG_NULL_TLV 0
     42 /* Defines details of the lock bytes              */
     43 #define TAG_LOCK_CTRL_TLV 1
     44 /* Identifies reserved memory areas               */
     45 #define TAG_MEM_CTRL_TLV 2
     46 /* Contains the NDEF message                      */
     47 #define TAG_NDEF_TLV 3
     48 /* Tag proprietary information                    */
     49 #define TAG_PROPRIETARY_TLV 0xFD
     50 /* Last TLV block in the data area                */
     51 #define TAG_TERMINATOR_TLV 0xFE
     52 /* Number of bits in every tag byte               */
     53 #define TAG_BITS_PER_BYTE 0x08
     54 /* Max UID Len of type 1 and type 2 tag           */
     55 #define TAG_MAX_UID_LEN 0x0A
     56 
     57 /* Byte 0 Length field to indicate LNDEF  */
     58 #define TAG_LONG_NDEF_LEN_FIELD_BYTE0 0xFF
     59 /* Tlv len for LOCK_CTRL/MEM TLV per spec */
     60 #define TAG_DEFAULT_TLV_LEN 3
     61 
     62 /* Type 1 Tag related definitions */
     63 
     64 /* block 0 to Block E                             */
     65 #define T1T_STATIC_BLOCKS 0x0F
     66 /* T1T Block size in bytes                        */
     67 #define T1T_BLOCK_SIZE 0x08
     68 
     69 #define T1T_STATIC_SIZE \
     70   T1T_STATIC_BLOCKS* T1T_BLOCK_SIZE /* Static Tag size   */
     71 
     72 /* Size of Type 1 Tag segment in bytes            */
     73 #define T1T_SEGMENT_SIZE 0x80
     74 /* Maximum segment supported by Type 1 Tag        */
     75 #define T1T_MAX_SEGMENTS 0x10
     76 /* Number of blocks present in a segment          */
     77 #define T1T_BLOCKS_PER_SEGMENT 0x10
     78 /* No.of default OTP,staticlocks,res bytes in tag */
     79 #define T1T_OTP_LOCK_RES_BYTES 0x10
     80 
     81 /* HRO value to indicate static Tag               */
     82 #define T1T_STATIC_HR0 0x11
     83 /* 0x1y, as long as (y!=1)                        */
     84 #define T1T_DYNAMIC_HR0 0x12
     85 /* HR0 value is 0x1y, indicates NDEF supported    */
     86 #define T1T_NDEF_SUPPORTED 0x10
     87 /* should be ignored                              */
     88 #define T1T_HR1 0x00
     89 /* UID block                                      */
     90 #define T1T_UID_BLOCK 0x00
     91 /* Reserved block                                 */
     92 #define T1T_RES_BLOCK 0x0D
     93 /* Static lock block                              */
     94 #define T1T_LOCK_BLOCK 0x0E
     95 /* Manufacturer ID offset                         */
     96 #define T1T_MID_OFFSET 0x06
     97 /* Reserved bytes offset                          */
     98 #define T1T_STATIC_RES_OFFSET 0x68
     99 /* Static lock offset                             */
    100 #define T1T_LOCK_0_OFFSET 0x70
    101 /* Static lock offset                             */
    102 #define T1T_LOCK_1_OFFSET 0x71
    103 /* Block F - typically used for dynamic locks     */
    104 #define T1T_DYNAMIC_LOCK_OFFSET 0x78
    105 #define T1T_DYNAMIC_LOCK_BYTES 0x08
    106 
    107 /* the len of reserved byte in T1T block 0        */
    108 #define T1T_RES_BYTE_LEN 1
    109 
    110 /* Capability Container definitions */
    111 /* Capability container block                     */
    112 #define T1T_CC_BLOCK 1
    113 /* the len of CC used in T1T tag                  */
    114 #define T1T_CC_LEN 4
    115 /* CC offset */
    116 /* Offset for NDEF magic number in CC             */
    117 #define T1T_CC_NMN_OFFSET 0x00
    118 /* Offset for Version number in CC                */
    119 #define T1T_CC_VNO_OFFSET 0x01
    120 /* Offset for Tag memory size in CC               */
    121 #define T1T_CC_TMS_OFFSET 0x02
    122 /* Offset for Read/Write access in CC             */
    123 #define T1T_CC_RWA_OFFSET 0x03
    124 /* NDEF Magic Number byte number                  */
    125 #define T1T_CC_NMN_BYTE 0x08
    126 /* Version Number byte number                     */
    127 #define T1T_CC_VNO_BYTE 0x09
    128 /* Tag Memory Size byte number                    */
    129 #define T1T_CC_TMS_BYTE 0x0A
    130 /* Read Write Access byte number                  */
    131 #define T1T_CC_RWA_BYTE 0x0B
    132 /* NDEF Magic Number                              */
    133 #define T1T_CC_NMN 0xE1
    134 /* Supported Legacy Version                       */
    135 #define T1T_CC_LEGACY_VNO 0x10
    136 /* Version Number                                 */
    137 #define T1T_CC_VNO 0x11
    138 /* TMS static memory - (8 * (n+1)).               */
    139 #define T1T_CC_TMS_STATIC 0x0E
    140 /* RWA - Read/write allowed                       */
    141 #define T1T_CC_RWA_RW 0x00
    142 /* RWA - Read only                                */
    143 #define T1T_CC_RWA_RO 0x0F
    144 
    145 /* May be used for padding. SHALL ignore this     */
    146 #define T1T_TAG_NULL 0
    147 /* Defines details of the lock bytes              */
    148 #define T1T_TAG_LOCK_CTRL 1
    149 /* Identifies reserved memory areas               */
    150 #define T1T_TAG_MEM_CTRL 2
    151 /* Contains the NDEF message                      */
    152 #define T1T_TAG_NDEF 3
    153 /* Tag proprietary information                    */
    154 #define T1T_TAG_PROPRIETARY 0xFD
    155 /* Last TLV block in the data area                */
    156 #define T1T_TAG_TERMINATOR 0xFE
    157 
    158 /* Tlv len for LOCK_CTRL/MEM TLV per spec         */
    159 #define T1T_DEFAULT_TLV_LEN 3
    160 /* Tlv type identifier len                        */
    161 #define T1T_TLV_TYPE_LEN 1
    162 /* Length field size of  lock/mem tlv     */
    163 #define T1T_DEFAULT_TLV_LEN_FIELD_LEN 1
    164 
    165 /* the len of HR used in Type 1 Tag               */
    166 #define T1T_HR_LEN 2
    167 /* the len of UID used in Type 1 Tag Commands     */
    168 #define T1T_CMD_UID_LEN 4
    169 /* the len of UID used in Type 1 Tag              */
    170 #define T1T_UID_LEN 7
    171 #define T1T_ADD_LEN 1
    172 
    173 /* Length Field size of short NDEF Message    */
    174 #define T1T_SHORT_NDEF_LEN_FIELD_LEN 1
    175 /* Length Field size of Long NDEF Message     */
    176 #define T1T_LONG_NDEF_LEN_FIELD_LEN 3
    177 /* Byte 0 in Length field to indicate LNDEF*/
    178 #define T1T_LONG_NDEF_LEN_FIELD_BYTE0 0xFF
    179 /* Min. len of NDEF to qualify as LNDEF  */
    180 #define T1T_LONG_NDEF_MIN_LEN 0x00FF
    181 
    182 /* Type 1 Tag Commands (7 bits) */
    183 /* read id                                      */
    184 #define T1T_CMD_RID 0x78
    185 /* read all bytes                               */
    186 #define T1T_CMD_RALL 0x00
    187 /* read (1 byte)                                */
    188 #define T1T_CMD_READ 0x01
    189 /* write with erase (1 byte)                    */
    190 #define T1T_CMD_WRITE_E 0x53
    191 /* write no erase (1 byte)                      */
    192 #define T1T_CMD_WRITE_NE 0x1A
    193 /* dynamic memory only */
    194 /* read segment                                 */
    195 #define T1T_CMD_RSEG 0x10
    196 /* read (8 byte)                                */
    197 #define T1T_CMD_READ8 0x02
    198 /* write with erase (8 byte)                    */
    199 #define T1T_CMD_WRITE_E8 0x54
    200 /* write no erase (8 byte)                      */
    201 #define T1T_CMD_WRITE_NE8 0x1B
    202 
    203 /* Lock */
    204 /* Number of static lock bytes in tag   */
    205 #define T1T_NUM_STATIC_LOCK_BYTES 2
    206 /* Bytes locked by one static lock bit  */
    207 #define T1T_BYTES_LOCKED_BY_STATIC_LOCK_BIT 4
    208 
    209 /* Type 2 Tag related definitions */
    210 #define T2T_STATIC_MEM_STR 0
    211 #define T2T_DYNAMIC_MEM_STR 1
    212 #define T2T_STATIC_SIZE 64
    213 #define T2T_STATIC_BLOCKS 16 /* block 0 to Block 15 */
    214 #define T2T_BLOCK_SIZE 4
    215 #define T2T_HEADER_BLOCKS 4
    216 #define T2T_HEADER_SIZE 16
    217 #define T2T_SECTOR_SIZE 1024
    218 #define T2T_BLOCKS_PER_SECTOR 0x100
    219 
    220 #define T2T_UID_LEN 4        /* the len of UID used in T2T tag */
    221 #define T2T_BLOCK0_UID_LEN 3 /* the len of UID in Block 0 of T2T tag */
    222 #define T2T_BCC0_LEN 1       /* the len of BCC0 of T2T tag */
    223 #define T2T_BLOCK1_UID_LEN 4 /* the len of UID in Block 1 of T2T tag */
    224 #define T2T_BCC1_LEN 1       /* the len of BCC0 of T2T tag */
    225 /* the len of Serial number used in T2T tag */
    226 #define T2T_SNO_LEN 4
    227 #define T2T_INTERNAL_BYTES_LEN 2 /* the len of internal used in T2T tag */
    228 /* the len of static lock used in T2T tag */
    229 #define T2T_STATIC_LOCK_LEN 2
    230 /* Static Lock Bytes */
    231 #define T2T_STATIC_LOCK0 0x0A /* Static Lock 0 offset */
    232 #define T2T_STATIC_LOCK1 0x0B /* Static Lock 1 offset */
    233 
    234 /* the len of CC used in T2T tag                  */
    235 #define T2T_CC_LEN 4
    236 
    237 /* Capability Container definitions */
    238 #define T2T_CC_BLOCK 0x03     /* Capability container block */
    239 #define T2T_CC0_NMN_BYTE 0x0C /* NDEF Magic Number byte number */
    240 #define T2T_CC1_VNO_BYTE 0x0D /* Version Number byte number*/
    241 #define T2T_CC2_TMS_BYTE 0x0E /* Tag Memory Size byte number */
    242 #define T2T_CC3_RWA_BYTE 0x0F /* Read Write Access byte number */
    243 #define T2T_DATA_MEM 0x10     /* Data Memory */
    244 
    245 #define T2T_CC0_NMN 0xE1        /* NDEF Magic Number */
    246 #define T2T_CC1_VNO 0x11        /* Version Number */
    247 #define T2T_CC1_LEGACY_VNO 0x10 /* Legacy Version Number */
    248 #define T2T_CC1_NEW_VNO 0x12    /* Another supported Version Number */
    249 #define T2T_CC2_TMS_STATIC 0x06 /* TMS static memory - (4 * (n+1)). */
    250 #define T2T_CC3_RWA_RW 0x00     /* RWA - Read/write allowed */
    251 #define T2T_CC3_RWA_RO 0x0F     /* RWA - Read only */
    252 
    253 /* Factor to multiply to get tag data size from TMS */
    254 #define T2T_TMS_TAG_FACTOR 0x08
    255 /* Bytes locked per lock bit of default locks */
    256 #define T2T_DEFAULT_LOCK_BLPB 0x08
    257 
    258 /* Type 2 Tag Commands  */
    259 #define T2T_CMD_READ 0x30    /* read  4 blocks (16 bytes) */
    260 #define T2T_CMD_WRITE 0xA2   /* write 1 block  (4 bytes)  */
    261 #define T2T_CMD_SEC_SEL 0xC2 /* Sector select             */
    262 #define T2T_RSP_ACK 0xA
    263 #define T2T_RSP_NACK5 0x5
    264 #define T2T_RSP_NACK1 0x1 /* Nack can be either 1    */
    265 
    266 #define T2T_FIRST_DATA_BLOCK 4
    267 #define T2T_READ_BLOCKS 4
    268 #define T2T_BLOCK_LEN 4
    269 #define T2T_READ_DATA_LEN (T2T_BLOCK_LEN * T2T_READ_BLOCKS)
    270 #define T2T_WRITE_DATA_LEN 4
    271 
    272 /* Type 2 TLV definitions */
    273 /* May be used for padding. SHALL ignore this */
    274 #define T2T_TLV_TYPE_NULL 0
    275 #define T2T_TLV_TYPE_LOCK_CTRL 1      /* Defines details of the lock bytes */
    276 #define T2T_TLV_TYPE_MEM_CTRL 2       /* Identifies reserved memory areas */
    277 #define T2T_TLV_TYPE_NDEF 3           /* Contains the NDEF message */
    278 #define T2T_TLV_TYPE_PROPRIETARY 0xFD /* Tag proprietary information */
    279 #define T2T_TLV_TYPE_TERMINATOR 0xFE  /* Last TLV block in the data area */
    280 
    281 /* Tag len for LOCK_CTRL TLV per spec */
    282 #define T2T_TLEN_LOCK_CTRL_TLV 3
    283 #define T2T_TLEN_MEM_CTRL_TLV 3 /* Tag len for MEM_CTRL TLV per spec */
    284 
    285 /* Maximum number of sectors supported */
    286 #define T2T_MAX_SECTOR 2
    287 
    288 /* Tlv type identifier len                */
    289 #define T2T_TLV_TYPE_LEN 1
    290 
    291 /* Tlv len for LOCK_CTRL/MEM TLV per spec     */
    292 #define T2T_DEFAULT_TLV_LEN 3
    293 /* Length Field size of short NDEF Message    */
    294 #define T2T_SHORT_NDEF_LEN_FIELD_LEN 1
    295 /* Length Field size of Long NDEF Message     */
    296 #define T2T_LONG_NDEF_LEN_FIELD_LEN 3
    297 /* Byte 0 in Length field to indicate LNDEF*/
    298 #define T2T_LONG_NDEF_LEN_FIELD_BYTE0 0xFF
    299 /* Min. len of NDEF to qualify as LNDEF  */
    300 #define T2T_LONG_NDEF_MIN_LEN 0x00FF
    301 
    302 /* Lock */
    303 /* Number of static lock bytes in tag   */
    304 #define T2T_NUM_STATIC_LOCK_BYTES 2
    305 /* Bytes locked by one static lock bit  */
    306 #define T2T_BYTES_LOCKED_BY_STATIC_LOCK_BIT 4
    307 
    308 #define T2T_CC2_TMS_MUL 0x06
    309 #define T2T_CC2_TMS_MULC 0x12
    310 /*
    311 **
    312 **  Type 3 Tag Definitions
    313 **
    314 */
    315 
    316 #define T3T_SYSTEM_CODE_NDEF 0x12FC /* System Code for NDEF tags */
    317 /* System Code for felica-lite tags */
    318 #define T3T_SYSTEM_CODE_FELICA_LITE 0x88B4
    319 #define T3T_MAX_SYSTEM_CODES 16
    320 /* Maximum number of blocks for NDEF message for Felica Lite tags */
    321 #define T3T_FELICALITE_NMAXB 13
    322 
    323 /* Block descriptor, used to describe a block to check/update */
    324 typedef struct {
    325   uint16_t service_code; /* Block service code. Set to T3T_SERVICE_CODE_NDEF
    326                             (0x000B) for NDEF data */
    327   uint16_t block_number; /* Block number */
    328 } tT3T_BLOCK_DESC;
    329 
    330 /* Poll RC (request code) definitions */
    331 #define T3T_POLL_RC_NONE 0 /* No RD requested in SENSF_RES */
    332 #define T3T_POLL_RC_SC 1   /* System code requested in SENSF_RES */
    333 /* Avanced protocol features requested in SENSF_RES */
    334 #define T3T_POLL_RC_COMM 2
    335 typedef uint8_t tT3T_POLL_RC;
    336 
    337 /* Definitions for constructing t3t command messages */
    338 
    339 /* NFC Forum / Felica commands */
    340 #define T3T_MSG_OPC_CHECK_CMD 0x06
    341 #define T3T_MSG_OPC_CHECK_RSP 0x07
    342 #define T3T_MSG_OPC_UPDATE_CMD 0x08
    343 #define T3T_MSG_OPC_UPDATE_RSP 0x09
    344 
    345 /* Felica commands (not specified in NFC-Forum Type 3 tag specifications) */
    346 #define T3T_MSG_OPC_POLL_CMD 0x00
    347 #define T3T_MSG_OPC_POLL_RSP 0x01
    348 #define T3T_MSG_OPC_REQ_SERVICE_CMD 0x02
    349 #define T3T_MSG_OPC_REQ_SERVICE_RSP 0x03
    350 #define T3T_MSG_OPC_REQ_RESPONSE_CMD 0x04
    351 #define T3T_MSG_OPC_REQ_RESPONSE_RSP 0x05
    352 #define T3T_MSG_OPC_REQ_SYSTEMCODE_CMD 0x0C
    353 #define T3T_MSG_OPC_REQ_SYSTEMCODE_RSP 0x0D
    354 
    355 /* Service code: read-only NDEF */
    356 #define T3T_MSG_NDEF_SC_RO 0x000B
    357 /* Service code: read/write NDEF */
    358 #define T3T_MSG_NDEF_SC_RW 0x0009
    359 #define T3T_MSG_NDEF_VERSION 0x10 /* NDEF Mapping Version 1.0 */
    360 #define T3T_MSG_NDEF_WRITEF_OFF 0x00
    361 #define T3T_MSG_NDEF_WRITEF_ON 0x0F
    362 #define T3T_MSG_NDEF_RWFLAG_RO 0x00
    363 #define T3T_MSG_NDEF_RWFLAG_RW 0x01
    364 /* Size of NDEF attribute info block (minus checksum) */
    365 #define T3T_MSG_NDEF_ATTR_INFO_SIZE 14
    366 
    367 /* offset of Manufacturer ID in UPDATE/CHECK messages */
    368 #define T3T_MSG_OFFSET_IDM 1
    369 /* offset of Number of Services parameter in UPDATE/CHECK messages */
    370 #define T3T_MSG_OFFSET_NUM_SERVICES 9
    371 /* offset of Service Code List parameter in UPDATE/CHECK messages */
    372 #define T3T_MSG_OFFSET_SERVICE_CODE_LIST 10
    373 /* len flag for Block List Element */
    374 #define T3T_MSG_MASK_TWO_BYTE_BLOCK_DESC_FORMAT 0x80
    375 /* service code list mask */
    376 #define T3T_MSG_SERVICE_LIST_MASK 0x0F
    377 #define T3T_MSG_SERVICE_LIST_MAX 16
    378 
    379 /* Max Number of Services per UPDATE command */
    380 #define T3T_MSG_NUM_SERVICES_UPDATE_MAX 12
    381 /* Max Number of Services per CHECK command */
    382 #define T3T_MSG_NUM_SERVICES_CHECK_MAX 15
    383 /* Max Number of Blocks per UPDATE command */
    384 #define T3T_MSG_NUM_BLOCKS_UPDATE_MAX 13
    385 /* Max Number of Blocks per CHECK command */
    386 #define T3T_MSG_NUM_BLOCKS_CHECK_MAX 15
    387 
    388 /* Data block size for UPDATE and CHECK commands */
    389 #define T3T_MSG_BLOCKSIZE 16
    390 
    391 /* Common header definitions for T3t commands */
    392 /* Common header: SoD + cmdcode + NFCID2 + num_services */
    393 #define T3T_MSG_CMD_COMMON_HDR_LEN 11
    394 
    395 /* Common header definition for T3t responses */
    396 /* Common header: rspcode + NFCID2 + StatusFlag1 + StatusFlag2  */
    397 #define T3T_MSG_RSP_COMMON_HDR_LEN 11
    398 /* Common header + NumBlocks */
    399 #define T3T_MSG_RSP_CHECK_HDR_LEN (T3T_MSG_RSP_COMMON_HDR_LEN + 1)
    400 /* Offset for Response code */
    401 #define T3T_MSG_RSP_OFFSET_RSPCODE 0
    402 /* Offset for Manufacturer ID */
    403 #define T3T_MSG_RSP_OFFSET_IDM 1
    404 /* Offset for Status Flag1 */
    405 #define T3T_MSG_RSP_OFFSET_STATUS1 9
    406 /* Offset for NumberOfBlocks (in CHECK response) */
    407 #define T3T_MSG_RSP_OFFSET_NUMBLOCKS 11
    408 /* Offset for Block Data (in CHECK response) */
    409 #define T3T_MSG_RSP_OFFSET_CHECK_DATA 12
    410 /* Offset for PMm (in POLL response) */
    411 #define T3T_MSG_RSP_OFFSET_POLL_PMM 9
    412 /* Offset for RD (in POLL response) */
    413 #define T3T_MSG_RSP_OFFSET_POLL_RD 17
    414 /* Offset for Number of Systems */
    415 #define T3T_MSG_RSP_OFFSET_NUMSYS 9
    416 
    417 #define T3T_MSG_RSP_STATUS_OK 0x00
    418 #define T3T_MSG_RSP_STATUS_ERROR 0x01
    419 
    420 #define T3T_MSG_RSP_STATUS2_ERROR_MEMORY 0x70
    421 #define T3T_MSG_RSP_STATUS2_ERROR_EXCESSIVE_WRITES 0x71
    422 #define T3T_MSG_RSP_STATUS2_ERROR_PROCESSING 0xFF
    423 
    424 /* Maximum payload lenght for NFC-F messages (including SoD) */
    425 #define T3T_NFC_F_MAX_PAYLOAD_LEN 0xFE
    426 
    427 /* Felica Lite defintions */
    428 /* Block ID for MC (memory configuration)                       */
    429 #define T3T_MSG_FELICALITE_BLOCK_ID_MC 0x88
    430 
    431 /* Memory Configuration Block offset: MC_SP (Memory Configuration for scratch
    432  * pad)   */
    433 #define T3T_MSG_FELICALITE_MC_OFFSET_MC_SP 0x00
    434 /* Memory Configuration Block offset: MC_ALL (Memory Configuration for system
    435  * block) */
    436 #define T3T_MSG_FELICALITE_MC_OFFSET_MC_ALL 0x02
    437 /* Memory Configuration Block offset: SYS_OP (System Option) */
    438 #define T3T_MSG_FELICALITE_MC_OFFSET_SYS_OP 0x03
    439 /* Memory Configuration Block offset: RF_PRM (Memory Configuration for RF
    440  * Parameter) */
    441 #define T3T_MSG_FELICALITE_MC_OFFSET_RF_PRM 0x04
    442 
    443 /*
    444 **
    445 **  Type 4 Tag Definitions
    446 **
    447 */
    448 #define T4T_CMD_MIN_HDR_SIZE 4 /* CLA, INS, P1, P2 */
    449 #define T4T_CMD_MAX_HDR_SIZE 5 /* CLA, INS, P1, P2, Lc */
    450 
    451 #define T4T_VERSION_2_0 0x20 /* version 2.0 */
    452 #define T4T_VERSION_1_0 0x10 /* version 1.0 */
    453 #define T4T_MY_VERSION T4T_VERSION_2_0
    454 #define T4T_GET_MAJOR_VERSION(x) ((x) >> 4)
    455 #define T4T_GET_MINOR_VERSION(x) ((x)&0x0F)
    456 
    457 #define T4T_CMD_CLASS 0x00
    458 #define T4T_CMD_INS_SELECT 0xA4
    459 #define T4T_CMD_INS_READ_BINARY 0xB0
    460 #define T4T_CMD_INS_UPDATE_BINARY 0xD6
    461 #define T4T_CMD_DES_CLASS 0x90
    462 #define T4T_CMD_INS_GET_HW_VERSION 0x60
    463 #define T4T_CMD_CREATE_AID 0xCA
    464 #define T4T_CMD_SELECT_APP 0x5A
    465 #define T4T_CMD_CREATE_DATAFILE 0xCD
    466 #define T4T_CMD_DES_WRITE 0x3D
    467 #define T4T_CMD_P1_SELECT_BY_NAME 0x04
    468 #define T4T_CMD_P1_SELECT_BY_FILE_ID 0x00
    469 #define T4T_CMD_P2_FIRST_OR_ONLY_00H 0x00
    470 #define T4T_CMD_P2_FIRST_OR_ONLY_0CH 0x0C
    471 
    472 /* Max number of bytes to be read from file in ReadBinary Command */
    473 #define T4T_MAX_LENGTH_LE 0xFF
    474 /* Max number of bytes written to NDEF file in UpdateBinary Command */
    475 #define T4T_MAX_LENGTH_LC 0xFF
    476 
    477 #define T4T_RSP_STATUS_WORDS_SIZE 0x02
    478 
    479 #define T4T_RSP_CMD_CMPLTED 0x9000
    480 #define T4T_RSP_NOT_FOUND 0x6A82
    481 #define T4T_RSP_WRONG_PARAMS 0x6B00
    482 #define T4T_RSP_CLASS_NOT_SUPPORTED 0x6E00
    483 #define T4T_RSP_WRONG_LENGTH 0x6700
    484 #define T4T_RSP_INSTR_NOT_SUPPORTED 0x6D00
    485 #define T4T_RSP_CMD_NOT_ALLOWED 0x6986
    486 
    487 /* V1.0 Type 4 Tag Applicaiton ID length */
    488 #define T4T_V10_NDEF_TAG_AID_LEN 0x07
    489 /* V2.0 Type 4 Tag Applicaiton ID length */
    490 #define T4T_V20_NDEF_TAG_AID_LEN 0x07
    491 
    492 /* Min of Max R-APDU data size */
    493 #define T4T_MIN_MLE 0x000F
    494 
    495 #define T4T_FILE_ID_SIZE 0x02
    496 #define T4T_CC_FILE_ID 0xE103
    497 #define T4T_CC_FILE_MIN_LEN 0x000F
    498 
    499 #define T4T_VERSION_OFFSET_IN_CC 0x02
    500 #define T4T_FC_TLV_OFFSET_IN_CC 0x07
    501 /* Offset of Write access byte from type field in CC */
    502 #define T4T_FC_WRITE_ACCESS_OFFSET_IN_TLV 0x07
    503 
    504 #define T4T_NDEF_FILE_CONTROL_TYPE 0x04 /* NDEF File Control Type */
    505 /* Proprietary File Control Type */
    506 #define T4T_PROP_FILE_CONTROL_TYPE 0x05
    507 
    508 /* size of T(1),L(1),V(6) for file control */
    509 #define T4T_FILE_CONTROL_TLV_SIZE 0x08
    510 /* size of V(6) for file control */
    511 #define T4T_FILE_CONTROL_LENGTH 0x06
    512 
    513 /* read access granted without any security */
    514 #define T4T_FC_READ_ACCESS 0x00
    515 /* write access granted without any security */
    516 #define T4T_FC_WRITE_ACCESS 0x00
    517 /* no write access granted at all (read-only) */
    518 #define T4T_FC_NO_WRITE_ACCESS 0xFF
    519 
    520 #define T4T_FILE_LENGTH_SIZE 0x02
    521 #define T4T_ADDI_FRAME_RESP 0xAFU
    522 #define T4T_SIZE_IDENTIFIER_2K 0x16U
    523 #define T4T_SIZE_IDENTIFIER_4K 0x18U
    524 #define T4T_SIZE_IDENTIFIER_8K 0x1AU
    525 #define T4T_DESEV1_MAJOR_VERSION 0x01U
    526 #define T4T_TYPE_DESFIRE_EV1 0x01U
    527 #define T4T_DESEV0_MAJOR_VERSION 0x00U
    528 #define T4T_DESEV0_MINOR_VERSION 0x06U
    529 #define T4T_DES_EV1_NFC_APP_ID 0x010000
    530 #define T4T_DES_EV0_NFC_APP_ID 0x10EEEE
    531 
    532 /*
    533 **
    534 **  ISO 15693 Tag Definitions
    535 **
    536 */
    537 
    538 /* Request flags 1 to 4 definition */
    539 #define I93_FLAG_SUB_CARRIER_MASK 0x01 /* Sub_carrier_flag */
    540 /* A single sub-carrier frequency shall be used by VICC */
    541 #define I93_FLAG_SUB_CARRIER_SINGLE 0x00
    542 /* Two sub-carriers shall be used by VICC               */
    543 #define I93_FLAG_SUB_CARRIER_DOUBLE 0x01
    544 
    545 #define I93_FLAG_DATA_RATE_MASK 0x02 /* Data_rate_flag */
    546 /* Low data rate shall be used  */
    547 #define I93_FLAG_DATA_RATE_LOW 0x00
    548 /* High data rate shall be used */
    549 #define I93_FLAG_DATA_RATE_HIGH 0x02
    550 
    551 #define I93_FLAG_INVENTORY_MASK 0x04 /* Inventory_flag */
    552 /* Flags 5 to 8 meaning is according to table 4 */
    553 #define I93_FLAG_INVENTORY_UNSET 0x00
    554 /* Flags 5 to 8 meaning is according to table 5 */
    555 #define I93_FLAG_INVENTORY_SET 0x04
    556 
    557 /* Protocol_Extension_flag */
    558 #define I93_FLAG_PROT_EXT_MASK 0x08
    559 /* No protocol format extension                         */
    560 #define I93_FLAG_PROT_EXT_NO 0x00
    561 /* Protocol format is extended. Reserved for future use */
    562 #define I93_FLAG_PROT_EXT_YES 0x08
    563 
    564 /* Request flags 5 to 6 definition when inventory flag is not set */
    565 #define I93_FLAG_SELECT_MASK 0x10 /* Select_flag */
    566 /* Request shall be executed by any VICC according to the setting of
    567  * Address_flag */
    568 #define I93_FLAG_SELECT_UNSET 0x00
    569 /* Request shall be executed only by VICC in selected state */
    570 #define I93_FLAG_SELECT_SET 0x10
    571 /* The Address_flag shall be set to 0 and the UID field shall bot be included in
    572  * the request */
    573 
    574 #define I93_FLAG_ADDRESS_MASK 0x20 /* Address_flag */
    575 /* Request is not addressed. UID field is not included. It shall be executed by
    576  * any VICC */
    577 #define I93_FLAG_ADDRESS_UNSET 0x00
    578 /* Request is addressed. UID field is included. It shall be executed only by
    579  * VICC */
    580 #define I93_FLAG_ADDRESS_SET 0x20
    581 /* whose UID matches the UID specified in the request */
    582 
    583 /* Request flags 5 to 6 definition when inventory flag is set */
    584 #define I93_FLAG_AFI_MASK 0x10 /* AFI_flag */
    585 /* AFI field is not present */
    586 #define I93_FLAG_AFI_NOT_PRESENT 0x00
    587 /* AFI field is present     */
    588 #define I93_FLAG_AFI_PRESENT 0x10
    589 
    590 #define I93_FLAG_SLOT_MASK 0x20 /* Nb_slots_flag */
    591 #define I93_FLAG_SLOT_16 0x00   /* 16 slots */
    592 #define I93_FLAG_SLOT_ONE 0x20  /* 1 slot   */
    593 
    594 /* Request flags 6 to 8 definition when inventory flag is set or not set */
    595 
    596 #define I93_FLAG_OPTION_MASK 0x40 /* Option_flag */
    597 /* Meaning is defined by the command description. */
    598 #define I93_FLAG_OPTION_UNSET 0x00
    599 /* It shall be set to 0 if not otherwise defined by command */
    600 /* Meaning is defined by the command description. */
    601 #define I93_FLAG_OPTION_SET 0x40
    602 
    603 /* Response flags */
    604 #define I93_FLAG_ERROR_MASK 0x01 /* Error_flag */
    605 /* No error                                           */
    606 #define I93_FLAG_ERORR_NOT_DETECTED 0x00
    607 /* Error detected, Error code is in the "Error" field */
    608 #define I93_FLAG_ERROR_DETECTED 0x01
    609 
    610 /* Response error code */
    611 /* The command is not supported, i.e. the request code is not recognized */
    612 #define I93_ERROR_CODE_NOT_SUPPORTED 0x01
    613 /* The command is not recognized, for example: a format error occured    */
    614 #define I93_ERROR_CODE_NOT_RECOGNIZED 0x02
    615 /* The command option is not supported                                   */
    616 #define I93_ERROR_CODE_OPTION_NOT_SUPPORTED 0x03
    617 /* Error with no information given or a specific error code is not supported */
    618 #define I93_ERROR_CODE_NO_INFO 0x0F
    619 /* The specific block is not available (doesn't exist)                   */
    620 #define I93_ERROR_CODE_BLOCK_NOT_AVAILABLE 0x10
    621 /* The specific block is already locked and thus cannot be locked again  */
    622 #define I93_ERROR_CODE_BLOCK_ALREADY_LOCKED 0x11
    623 /* The specific block is locked and its content cannot be changed        */
    624 #define I93_ERROR_CODE_BLOCK_LOCKED 0x12
    625 /* The specific block is was not successfully programmed                 */
    626 #define I93_ERROR_CODE_BLOCK_FAIL_TO_WRITE 0x13
    627 /* The specific block is was not successfully locked                     */
    628 #define I93_ERROR_CODE_BLOCK_FAIL_TO_LOCK 0x14
    629 
    630 /* UID length in bytes                  */
    631 #define I93_UID_BYTE_LEN 8
    632 /* Data Storage Format is not supported */
    633 #define I93_DFS_UNSUPPORTED 0x00
    634 /* Block is not locked                  */
    635 #define I93_BLOCK_UNLOCKED 0x00
    636 /* Block is locked                      */
    637 #define I93_BLOCK_LOCKED 0x01
    638 
    639 /* ISO 15693 Mandatory commands */
    640 #define I93_CMD_INVENTORY 0x01  /* Inventory  */
    641 #define I93_CMD_STAY_QUIET 0x02 /* Stay Quiet */
    642 
    643 /* ISO 15693 Optional commands */
    644 #define I93_CMD_READ_SINGLE_BLOCK 0x20  /* Read single block     */
    645 #define I93_CMD_WRITE_SINGLE_BLOCK 0x21 /* Write single block    */
    646 #define I93_CMD_LOCK_BLOCK 0x22         /* Lock block            */
    647 #define I93_CMD_READ_MULTI_BLOCK 0x23   /* Read multiple blocks  */
    648 #define I93_CMD_WRITE_MULTI_BLOCK 0x24  /* Write multiple blocks */
    649 #define I93_CMD_SELECT 0x25             /* Select                */
    650 #define I93_CMD_RESET_TO_READY 0x26     /* Reset to ready        */
    651 #define I93_CMD_WRITE_AFI 0x27          /* Wreite AFI            */
    652 #define I93_CMD_LOCK_AFI 0x28           /* Lock AFI              */
    653 #define I93_CMD_WRITE_DSFID 0x29        /* Write DSFID           */
    654 #define I93_CMD_LOCK_DSFID 0x2A         /* Lock DSFID            */
    655 /* Get system information             */
    656 #define I93_CMD_GET_SYS_INFO 0x2B
    657 /* Get multiple block security status */
    658 #define I93_CMD_GET_MULTI_BLK_SEC 0x2C
    659 
    660 /* Information flags definition */
    661 /* DSFID is supported and DSFID field is present */
    662 #define I93_INFO_FLAG_DSFID 0x01
    663 /* AFI is supported and AFI field is present     */
    664 #define I93_INFO_FLAG_AFI 0x02
    665 /* VICC memory size field is present             */
    666 #define I93_INFO_FLAG_MEM_SIZE 0x04
    667 /* IC reference field is present                 */
    668 #define I93_INFO_FLAG_IC_REF 0x08
    669 
    670 /* Max block size in bytes */
    671 #define I93_MAX_BLOCK_LENGH 32
    672 /* Max number of blocks    */
    673 #define I93_MAX_NUM_BLOCK 256
    674 
    675 /* ICODE Capability Container(CC) definition */
    676 #define I93_ICODE_CC_MAGIC_NUMER 0xE1    /* magic number in CC[0]  */
    677 #define I93_ICODE_CC_MAJOR_VER_MASK 0xC0 /* major version in CC[1] */
    678 #define I93_ICODE_CC_MINOR_VER_MASK 0x30 /* minor version in CC[1] */
    679 /* read access condition in CC[1]        */
    680 #define I93_ICODE_CC_READ_ACCESS_MASK 0x0C
    681 /* read access granted without security  */
    682 #define I93_ICODE_CC_READ_ACCESS_GRANTED 0x00
    683 /* write access condition in CC[1]       */
    684 #define I93_ICODE_CC_WRITE_ACCESS_MASK 0x03
    685 /* write access granted without security */
    686 #define I93_ICODE_CC_WRITE_ACCESS_GRANTED 0x00
    687 /* write access not granted at all       */
    688 #define I93_ICODE_CC_READ_ONLY 0x03
    689 /* read multi block supported in CC[3]   */
    690 #define I93_ICODE_CC_MBREAD_MASK 0x01
    691 /* inventory page read supported in CC[3] */
    692 #define I93_ICODE_CC_IPREAD_MASK 0x02
    693 /* More than 2040 bytes are supported in CC[3] */
    694 #define I93_STM_CC_OVERFLOW_MASK 0x04
    695 
    696 /* ICODE TLV type */
    697 #define I93_ICODE_TLV_TYPE_NULL 0x00 /* NULL TLV         */
    698 #define I93_ICODE_TLV_TYPE_NDEF 0x03 /* NDEF message TLV */
    699 #define I93_ICODE_TLV_TYPE_PROP 0xFD /* Proprietary TLV  */
    700 #define I93_ICODE_TLV_TYPE_TERM 0xFE /* Terminator TLV   */
    701 
    702 /* UID Coding (UID Bit 64-57), First byte of ISO 15693 UID */
    703 #define I93_UID_FIRST_BYTE 0xE0
    704 
    705 /* UID Coding (UID Bit 56-49), IC manufacturer code */
    706 #define I93_UID_IC_MFG_CODE_STM 0x02
    707 #define I93_UID_IC_MFG_CODE_NXP 0x04
    708 #define I93_UID_IC_MFG_CODE_TI 0x07
    709 
    710 /* NXP, UID Coding of ICODE type (UID Bit 48-41) */
    711 /* ICODE SLI, SLIX     */
    712 #define I93_UID_ICODE_SLI 0x01
    713 /* ICODE SLI-S, SLIX-S */
    714 #define I93_UID_ICODE_SLI_S 0x02
    715 /* ICODE SLI-L, SLIX-L */
    716 #define I93_UID_ICODE_SLI_L 0x03
    717 
    718 /* IC Reference for ICODE SLI-L */
    719 #define I93_IC_REF_ICODE_SLI_L 0x03
    720 /* read multi block supported check bit */
    721 #define I93_ICODE_IC_REF_MBREAD_MASK 0x02
    722 
    723 /* TI, UID Coding of product version (UID Bit 48-42) */
    724 /* upper 7 bits                     */
    725 #define I93_UID_TAG_IT_HF_I_PRODUCT_ID_MASK 0xFE
    726 /* Tag-it HF-I Plus Inlay           */
    727 #define I93_UID_TAG_IT_HF_I_PLUS_INLAY 0x00
    728 /* Tag-it HF-I Plus Chip            */
    729 #define I93_UID_TAG_IT_HF_I_PLUS_CHIP 0x80
    730 /* Tag-it HF-I Standard Chip/Inlyas */
    731 #define I93_UID_TAG_IT_HF_I_STD_CHIP_INLAY 0xC0
    732 /* Tag-it HF-I Pro Chip/Inlyas      */
    733 #define I93_UID_TAG_IT_HF_I_PRO_CHIP_INLAY 0xC4
    734 
    735 #define I93_TAG_IT_HF_I_STD_CHIP_INLAY_NUM_TOTAL_BLK 11
    736 #define I93_TAG_IT_HF_I_PRO_CHIP_INLAY_NUM_TOTAL_BLK 12
    737 
    738 #define I93_TAG_IT_HF_I_STD_PRO_CHIP_INLAY_BLK_SIZE 4
    739 #define I93_TAG_IT_HF_I_STD_PRO_CHIP_INLAY_NUM_USER_BLK 8
    740 /* LSB in Block 0x0A */
    741 #define I93_TAG_IT_HF_I_STD_PRO_CHIP_INLAY_AFI_LOCATION 40
    742 
    743 /* STM, product version (IC manufacturer code) */
    744 /* IC Reference mask for STM */
    745 #define I93_IC_REF_STM_MASK 0xFC
    746 /* IC Reference for LRI1K:      010000xx(b), blockSize: 4, numberBlocks: 0x20 */
    747 #define I93_IC_REF_STM_LRI1K 0x40
    748 /* IC Reference for LRI2K:      001000xx(b), blockSize: 4, numberBlocks: 0x40 */
    749 #define I93_IC_REF_STM_LRI2K 0x20
    750 /* IC Reference for LRIS2K:     001010xx(b), blockSize: 4, numberBlocks: 0x40 */
    751 #define I93_IC_REF_STM_LRIS2K 0x28
    752 /* IC Reference for LRIS64K:    010001xx(b), blockSize: 4, numberBlocks: 0x800
    753  */
    754 #define I93_IC_REF_STM_LRIS64K 0x44
    755 /* IC Reference for M24LR64-R:  001011xx(b), blockSize: 4, numberBlocks: 0x800
    756  */
    757 #define I93_IC_REF_STM_M24LR64_R 0x2C
    758 /* IC Reference for M24LR04E-R: 01011010(b), blockSize: 4, numberBlocks: 0x80 */
    759 #define I93_IC_REF_STM_M24LR04E_R 0x5A
    760 /* IC Reference for M24LR16E-R: 01001110(b), blockSize: 4, numberBlocks: 0x200
    761  */
    762 #define I93_IC_REF_STM_M24LR16E_R 0x4E
    763 /* IC Reference for M24LR64E-R: 01011110(b), blockSize: 4, numberBlocks: 0x800
    764  */
    765 #define I93_IC_REF_STM_M24LR64E_R 0x5E
    766 
    767 #define I93_STM_BLOCKS_PER_SECTOR 32
    768 #define I93_STM_MAX_BLOCKS_PER_READ 32
    769 
    770 #endif /* TAGS_DEFS_H */
    771