blob: dc54d783cdd99c21c401af9ce3470fa58b5a3345 [file] [log] [blame]
nxpandroidc7611652015-09-23 16:42:05 +05301/******************************************************************************
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 ******************************************************************************/
nxpandroidc7611652015-09-23 16:42:05 +053018
nxpandroidc7611652015-09-23 16:42:05 +053019/******************************************************************************
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 */
nxpandroid8f6d0532017-07-12 18:25:30 +053030/* 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
nxpandroidc7611652015-09-23 16:42:05 +053038
39/* TLV types present in Type1 and Type 2 Tags */
nxpandroid8f6d0532017-07-12 18:25:30 +053040/* 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
nxpandroidc7611652015-09-23 16:42:05 +053056
nxpandroid8f6d0532017-07-12 18:25:30 +053057/* 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
nxpandroidc7611652015-09-23 16:42:05 +053061
62/* Type 1 Tag related definitions */
63
nxpandroid8f6d0532017-07-12 18:25:30 +053064/* block 0 to Block E */
65#define T1T_STATIC_BLOCKS 0x0F
66/* T1T Block size in bytes */
67#define T1T_BLOCK_SIZE 0x08
nxpandroidc7611652015-09-23 16:42:05 +053068
nxpandroid8f6d0532017-07-12 18:25:30 +053069#define T1T_STATIC_SIZE \
70 T1T_STATIC_BLOCKS* T1T_BLOCK_SIZE /* Static Tag size */
nxpandroidc7611652015-09-23 16:42:05 +053071
nxpandroid8f6d0532017-07-12 18:25:30 +053072/* 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
nxpandroidc7611652015-09-23 16:42:05 +053080
nxpandroid8f6d0532017-07-12 18:25:30 +053081/* HRO value to indicate static Tag */
82#define T1T_STATIC_HR0 0x11
83/* 0x1y, as long as (y!=1) */
nxpandroid8f6d0532017-07-12 18:25:30 +053084/* HR0 value is 0x1y, indicates NDEF supported */
85#define T1T_NDEF_SUPPORTED 0x10
nxpandroid8f6d0532017-07-12 18:25:30 +053086/* UID block */
87#define T1T_UID_BLOCK 0x00
88/* Reserved block */
89#define T1T_RES_BLOCK 0x0D
90/* Static lock block */
91#define T1T_LOCK_BLOCK 0x0E
nxpandroid8f6d0532017-07-12 18:25:30 +053092/* Static lock offset */
93#define T1T_LOCK_0_OFFSET 0x70
nxpandroid8f6d0532017-07-12 18:25:30 +053094/* Block F - typically used for dynamic locks */
nxpandroid8f6d0532017-07-12 18:25:30 +053095#define T1T_DYNAMIC_LOCK_BYTES 0x08
nxpandroidc7611652015-09-23 16:42:05 +053096
nxpandroid8f6d0532017-07-12 18:25:30 +053097/* the len of reserved byte in T1T block 0 */
98#define T1T_RES_BYTE_LEN 1
nxpandroidc7611652015-09-23 16:42:05 +053099
100/* Capability Container definitions */
nxpandroid8f6d0532017-07-12 18:25:30 +0530101/* Capability container block */
102#define T1T_CC_BLOCK 1
103/* the len of CC used in T1T tag */
104#define T1T_CC_LEN 4
nxpandroidc7611652015-09-23 16:42:05 +0530105/* CC offset */
nxpandroid8f6d0532017-07-12 18:25:30 +0530106/* Offset for NDEF magic number in CC */
107#define T1T_CC_NMN_OFFSET 0x00
nxpandroid8f6d0532017-07-12 18:25:30 +0530108/* Offset for Read/Write access in CC */
109#define T1T_CC_RWA_OFFSET 0x03
110/* NDEF Magic Number byte number */
111#define T1T_CC_NMN_BYTE 0x08
112/* Version Number byte number */
113#define T1T_CC_VNO_BYTE 0x09
114/* Tag Memory Size byte number */
115#define T1T_CC_TMS_BYTE 0x0A
116/* Read Write Access byte number */
117#define T1T_CC_RWA_BYTE 0x0B
118/* NDEF Magic Number */
119#define T1T_CC_NMN 0xE1
120/* Supported Legacy Version */
121#define T1T_CC_LEGACY_VNO 0x10
122/* Version Number */
123#define T1T_CC_VNO 0x11
nxpandroid8f6d0532017-07-12 18:25:30 +0530124/* RWA - Read/write allowed */
125#define T1T_CC_RWA_RW 0x00
126/* RWA - Read only */
127#define T1T_CC_RWA_RO 0x0F
nxpandroidc7611652015-09-23 16:42:05 +0530128
nxpandroid8f6d0532017-07-12 18:25:30 +0530129/* Tlv len for LOCK_CTRL/MEM TLV per spec */
130#define T1T_DEFAULT_TLV_LEN 3
131/* Tlv type identifier len */
132#define T1T_TLV_TYPE_LEN 1
133/* Length field size of lock/mem tlv */
134#define T1T_DEFAULT_TLV_LEN_FIELD_LEN 1
nxpandroidc7611652015-09-23 16:42:05 +0530135
nxpandroid8f6d0532017-07-12 18:25:30 +0530136/* the len of HR used in Type 1 Tag */
137#define T1T_HR_LEN 2
138/* the len of UID used in Type 1 Tag Commands */
139#define T1T_CMD_UID_LEN 4
140/* the len of UID used in Type 1 Tag */
141#define T1T_UID_LEN 7
142#define T1T_ADD_LEN 1
nxpandroidc7611652015-09-23 16:42:05 +0530143
nxpandroid8f6d0532017-07-12 18:25:30 +0530144/* Length Field size of short NDEF Message */
145#define T1T_SHORT_NDEF_LEN_FIELD_LEN 1
146/* Length Field size of Long NDEF Message */
147#define T1T_LONG_NDEF_LEN_FIELD_LEN 3
148/* Byte 0 in Length field to indicate LNDEF*/
149#define T1T_LONG_NDEF_LEN_FIELD_BYTE0 0xFF
150/* Min. len of NDEF to qualify as LNDEF */
nxpandroidc7611652015-09-23 16:42:05 +0530151
152/* Type 1 Tag Commands (7 bits) */
nxpandroid8f6d0532017-07-12 18:25:30 +0530153/* read id */
154#define T1T_CMD_RID 0x78
155/* read all bytes */
156#define T1T_CMD_RALL 0x00
157/* read (1 byte) */
158#define T1T_CMD_READ 0x01
159/* write with erase (1 byte) */
160#define T1T_CMD_WRITE_E 0x53
161/* write no erase (1 byte) */
162#define T1T_CMD_WRITE_NE 0x1A
nxpandroidc7611652015-09-23 16:42:05 +0530163/* dynamic memory only */
nxpandroid8f6d0532017-07-12 18:25:30 +0530164/* read segment */
165#define T1T_CMD_RSEG 0x10
166/* read (8 byte) */
167#define T1T_CMD_READ8 0x02
168/* write with erase (8 byte) */
169#define T1T_CMD_WRITE_E8 0x54
170/* write no erase (8 byte) */
171#define T1T_CMD_WRITE_NE8 0x1B
nxpandroidc7611652015-09-23 16:42:05 +0530172
173/* Lock */
nxpandroid8f6d0532017-07-12 18:25:30 +0530174/* Number of static lock bytes in tag */
175#define T1T_NUM_STATIC_LOCK_BYTES 2
176/* Bytes locked by one static lock bit */
nxpandroidc7611652015-09-23 16:42:05 +0530177
178/* Type 2 Tag related definitions */
nxpandroid8f6d0532017-07-12 18:25:30 +0530179#define T2T_STATIC_SIZE 64
nxpandroid8f6d0532017-07-12 18:25:30 +0530180#define T2T_BLOCK_SIZE 4
nxpandroid8f6d0532017-07-12 18:25:30 +0530181#define T2T_HEADER_SIZE 16
182#define T2T_SECTOR_SIZE 1024
183#define T2T_BLOCKS_PER_SECTOR 0x100
nxpandroidc7611652015-09-23 16:42:05 +0530184
nxpandroid8f6d0532017-07-12 18:25:30 +0530185#define T2T_UID_LEN 4 /* the len of UID used in T2T tag */
nxpandroid8f6d0532017-07-12 18:25:30 +0530186/* the len of Serial number used in T2T tag */
nxpandroid8f6d0532017-07-12 18:25:30 +0530187#define T2T_INTERNAL_BYTES_LEN 2 /* the len of internal used in T2T tag */
nxpandroidc7611652015-09-23 16:42:05 +0530188/* Static Lock Bytes */
nxpandroid8f6d0532017-07-12 18:25:30 +0530189#define T2T_STATIC_LOCK0 0x0A /* Static Lock 0 offset */
190#define T2T_STATIC_LOCK1 0x0B /* Static Lock 1 offset */
nxpandroidc7611652015-09-23 16:42:05 +0530191
nxpandroidc7611652015-09-23 16:42:05 +0530192/* Capability Container definitions */
nxpandroid8f6d0532017-07-12 18:25:30 +0530193#define T2T_CC_BLOCK 0x03 /* Capability container block */
194#define T2T_CC0_NMN_BYTE 0x0C /* NDEF Magic Number byte number */
195#define T2T_CC1_VNO_BYTE 0x0D /* Version Number byte number*/
196#define T2T_CC2_TMS_BYTE 0x0E /* Tag Memory Size byte number */
197#define T2T_CC3_RWA_BYTE 0x0F /* Read Write Access byte number */
nxpandroidc7611652015-09-23 16:42:05 +0530198
nxpandroid8f6d0532017-07-12 18:25:30 +0530199#define T2T_CC0_NMN 0xE1 /* NDEF Magic Number */
200#define T2T_CC1_VNO 0x11 /* Version Number */
201#define T2T_CC1_LEGACY_VNO 0x10 /* Legacy Version Number */
202#define T2T_CC1_NEW_VNO 0x12 /* Another supported Version Number */
203#define T2T_CC2_TMS_STATIC 0x06 /* TMS static memory - (4 * (n+1)). */
204#define T2T_CC3_RWA_RW 0x00 /* RWA - Read/write allowed */
205#define T2T_CC3_RWA_RO 0x0F /* RWA - Read only */
nxpandroidc7611652015-09-23 16:42:05 +0530206
nxpandroid8f6d0532017-07-12 18:25:30 +0530207/* Factor to multiply to get tag data size from TMS */
208#define T2T_TMS_TAG_FACTOR 0x08
209/* Bytes locked per lock bit of default locks */
210#define T2T_DEFAULT_LOCK_BLPB 0x08
nxpandroidc7611652015-09-23 16:42:05 +0530211
212/* Type 2 Tag Commands */
nxpandroid8f6d0532017-07-12 18:25:30 +0530213#define T2T_CMD_READ 0x30 /* read 4 blocks (16 bytes) */
214#define T2T_CMD_WRITE 0xA2 /* write 1 block (4 bytes) */
215#define T2T_CMD_SEC_SEL 0xC2 /* Sector select */
216#define T2T_RSP_ACK 0xA
nxpandroidc7611652015-09-23 16:42:05 +0530217
nxpandroid8f6d0532017-07-12 18:25:30 +0530218#define T2T_STATUS_OK_1_BIT 0x11
nxpandroid8f6d0532017-07-12 18:25:30 +0530219#define T2T_STATUS_OK_7_BIT 0x17
nxpandroidc7611652015-09-23 16:42:05 +0530220
nxpandroid8f6d0532017-07-12 18:25:30 +0530221#define T2T_FIRST_DATA_BLOCK 4
222#define T2T_READ_BLOCKS 4
223#define T2T_BLOCK_LEN 4
224#define T2T_READ_DATA_LEN (T2T_BLOCK_LEN * T2T_READ_BLOCKS)
225#define T2T_WRITE_DATA_LEN 4
nxpandroidc7611652015-09-23 16:42:05 +0530226
227/* Type 2 TLV definitions */
nxpandroid8f6d0532017-07-12 18:25:30 +0530228/* May be used for padding. SHALL ignore this */
nxpandroid8f6d0532017-07-12 18:25:30 +0530229#define T2T_TLV_TYPE_LOCK_CTRL 1 /* Defines details of the lock bytes */
nxpandroidc7611652015-09-23 16:42:05 +0530230
nxpandroid8f6d0532017-07-12 18:25:30 +0530231/* Tag len for LOCK_CTRL TLV per spec */
232#define T2T_TLEN_LOCK_CTRL_TLV 3
nxpandroidc7611652015-09-23 16:42:05 +0530233
nxpandroid8f6d0532017-07-12 18:25:30 +0530234/* Maximum number of sectors supported */
nxf24591c1cbeab2018-02-21 17:32:26 +0530235#if (APPL_DTA_MODE == TRUE)
nxpandroid8f6d0532017-07-12 18:25:30 +0530236#define T2T_MAX_SECTOR 3
nxpandroidc7611652015-09-23 16:42:05 +0530237#else
nxpandroid8f6d0532017-07-12 18:25:30 +0530238#define T2T_MAX_SECTOR 2
nxpandroidc7611652015-09-23 16:42:05 +0530239#endif
nxpandroid8f6d0532017-07-12 18:25:30 +0530240/* Tlv type identifier len */
241#define T2T_TLV_TYPE_LEN 1
nxpandroidc7611652015-09-23 16:42:05 +0530242
nxpandroid8f6d0532017-07-12 18:25:30 +0530243/* Length Field size of short NDEF Message */
244#define T2T_SHORT_NDEF_LEN_FIELD_LEN 1
245/* Length Field size of Long NDEF Message */
246#define T2T_LONG_NDEF_LEN_FIELD_LEN 3
247/* Byte 0 in Length field to indicate LNDEF*/
248#define T2T_LONG_NDEF_LEN_FIELD_BYTE0 0xFF
249/* Min. len of NDEF to qualify as LNDEF */
250#define T2T_LONG_NDEF_MIN_LEN 0x00FF
nxpandroidc7611652015-09-23 16:42:05 +0530251
252/* Lock */
nxpandroid8f6d0532017-07-12 18:25:30 +0530253/* Number of static lock bytes in tag */
254#define T2T_NUM_STATIC_LOCK_BYTES 2
nxpandroidc7611652015-09-23 16:42:05 +0530255
nxpandroidc7611652015-09-23 16:42:05 +0530256/*
nxf24591c1cbeab2018-02-21 17:32:26 +0530257**
258** Type 3 Tag Definitions
259**
260*/
nxpandroidc7611652015-09-23 16:42:05 +0530261
nxpandroid8f6d0532017-07-12 18:25:30 +0530262#define T3T_SYSTEM_CODE_NDEF 0x12FC /* System Code for NDEF tags */
263/* System Code for felica-lite tags */
264#define T3T_SYSTEM_CODE_FELICA_LITE 0x88B4
265#define T3T_MAX_SYSTEM_CODES 16
266/* Maximum number of blocks for NDEF message for Felica Lite tags */
267#define T3T_FELICALITE_NMAXB 13
nxpandroidc7611652015-09-23 16:42:05 +0530268
269/* Block descriptor, used to describe a block to check/update */
nxpandroid8f6d0532017-07-12 18:25:30 +0530270typedef struct {
271 uint16_t service_code; /* Block service code. Set to T3T_SERVICE_CODE_NDEF
272 (0x000B) for NDEF data */
273 uint16_t block_number; /* Block number */
nxpandroidc7611652015-09-23 16:42:05 +0530274} tT3T_BLOCK_DESC;
275
276/* Poll RC (request code) definitions */
nxpandroid8f6d0532017-07-12 18:25:30 +0530277#define T3T_POLL_RC_SC 1 /* System code requested in SENSF_RES */
nxpandroid8f6d0532017-07-12 18:25:30 +0530278typedef uint8_t tT3T_POLL_RC;
nxpandroidc7611652015-09-23 16:42:05 +0530279
280/* Definitions for constructing t3t command messages */
281
282/* NFC Forum / Felica commands */
nxpandroid8f6d0532017-07-12 18:25:30 +0530283#define T3T_MSG_OPC_CHECK_CMD 0x06
284#define T3T_MSG_OPC_CHECK_RSP 0x07
285#define T3T_MSG_OPC_UPDATE_CMD 0x08
286#define T3T_MSG_OPC_UPDATE_RSP 0x09
nxpandroidc7611652015-09-23 16:42:05 +0530287
288/* Felica commands (not specified in NFC-Forum Type 3 tag specifications) */
nxpandroid8f6d0532017-07-12 18:25:30 +0530289#define T3T_MSG_OPC_POLL_CMD 0x00
290#define T3T_MSG_OPC_POLL_RSP 0x01
291#define T3T_MSG_OPC_REQ_SERVICE_CMD 0x02
nxpandroid8f6d0532017-07-12 18:25:30 +0530292#define T3T_MSG_OPC_REQ_RESPONSE_CMD 0x04
293#define T3T_MSG_OPC_REQ_RESPONSE_RSP 0x05
294#define T3T_MSG_OPC_REQ_SYSTEMCODE_CMD 0x0C
295#define T3T_MSG_OPC_REQ_SYSTEMCODE_RSP 0x0D
nxpandroidc7611652015-09-23 16:42:05 +0530296
nxpandroid8f6d0532017-07-12 18:25:30 +0530297/* Service code: read-only NDEF */
298#define T3T_MSG_NDEF_SC_RO 0x000B
299/* Service code: read/write NDEF */
300#define T3T_MSG_NDEF_SC_RW 0x0009
301#define T3T_MSG_NDEF_VERSION 0x10 /* NDEF Mapping Version 1.0 */
302#define T3T_MSG_NDEF_WRITEF_OFF 0x00
303#define T3T_MSG_NDEF_WRITEF_ON 0x0F
304#define T3T_MSG_NDEF_RWFLAG_RO 0x00
305#define T3T_MSG_NDEF_RWFLAG_RW 0x01
306/* Size of NDEF attribute info block (minus checksum) */
307#define T3T_MSG_NDEF_ATTR_INFO_SIZE 14
nxpandroidc7611652015-09-23 16:42:05 +0530308
nxpandroid8f6d0532017-07-12 18:25:30 +0530309/* len flag for Block List Element */
310#define T3T_MSG_MASK_TWO_BYTE_BLOCK_DESC_FORMAT 0x80
311/* service code list mask */
312#define T3T_MSG_SERVICE_LIST_MASK 0x0F
313#define T3T_MSG_SERVICE_LIST_MAX 16
nxpandroidc7611652015-09-23 16:42:05 +0530314
nxpandroid8f6d0532017-07-12 18:25:30 +0530315/* Max Number of Blocks per UPDATE command */
316#define T3T_MSG_NUM_BLOCKS_UPDATE_MAX 13
317/* Max Number of Blocks per CHECK command */
318#define T3T_MSG_NUM_BLOCKS_CHECK_MAX 15
nxpandroidc7611652015-09-23 16:42:05 +0530319
nxpandroid8f6d0532017-07-12 18:25:30 +0530320/* Data block size for UPDATE and CHECK commands */
321#define T3T_MSG_BLOCKSIZE 16
nxpandroidc7611652015-09-23 16:42:05 +0530322
323/* Common header definitions for T3t commands */
nxpandroid8f6d0532017-07-12 18:25:30 +0530324/* Common header: SoD + cmdcode + NFCID2 + num_services */
325#define T3T_MSG_CMD_COMMON_HDR_LEN 11
nxpandroidc7611652015-09-23 16:42:05 +0530326
327/* Common header definition for T3t responses */
nxpandroid8f6d0532017-07-12 18:25:30 +0530328/* Common header: rspcode + NFCID2 + StatusFlag1 + StatusFlag2 */
329#define T3T_MSG_RSP_COMMON_HDR_LEN 11
nxpandroid8f6d0532017-07-12 18:25:30 +0530330/* Offset for Response code */
331#define T3T_MSG_RSP_OFFSET_RSPCODE 0
332/* Offset for Manufacturer ID */
333#define T3T_MSG_RSP_OFFSET_IDM 1
334/* Offset for Status Flag1 */
335#define T3T_MSG_RSP_OFFSET_STATUS1 9
336/* Offset for NumberOfBlocks (in CHECK response) */
337#define T3T_MSG_RSP_OFFSET_NUMBLOCKS 11
338/* Offset for Block Data (in CHECK response) */
339#define T3T_MSG_RSP_OFFSET_CHECK_DATA 12
nxpandroidc7611652015-09-23 16:42:05 +0530340
nxpandroid8f6d0532017-07-12 18:25:30 +0530341#define T3T_MSG_RSP_STATUS_OK 0x00
342#define T3T_MSG_RSP_STATUS_ERROR 0x01
nxpandroidc7611652015-09-23 16:42:05 +0530343
nxpandroid8f6d0532017-07-12 18:25:30 +0530344#define T3T_MSG_RSP_STATUS2_ERROR_MEMORY 0x70
nxpandroid8f6d0532017-07-12 18:25:30 +0530345#define T3T_MSG_RSP_STATUS2_ERROR_PROCESSING 0xFF
nxpandroidc7611652015-09-23 16:42:05 +0530346
nxpandroidc7611652015-09-23 16:42:05 +0530347
348/* Felica Lite defintions */
nxpandroid8f6d0532017-07-12 18:25:30 +0530349/* Block ID for MC (memory configuration) */
350#define T3T_MSG_FELICALITE_BLOCK_ID_MC 0x88
nxpandroidc7611652015-09-23 16:42:05 +0530351
nxpandroid8f6d0532017-07-12 18:25:30 +0530352/* Memory Configuration Block offset: MC_SP (Memory Configuration for scratch
353 * pad) */
354#define T3T_MSG_FELICALITE_MC_OFFSET_MC_SP 0x00
nxpandroid8f6d0532017-07-12 18:25:30 +0530355/* Memory Configuration Block offset: SYS_OP (System Option) */
356#define T3T_MSG_FELICALITE_MC_OFFSET_SYS_OP 0x03
357/* Memory Configuration Block offset: RF_PRM (Memory Configuration for RF
358 * Parameter) */
359#define T3T_MSG_FELICALITE_MC_OFFSET_RF_PRM 0x04
nxpandroidc7611652015-09-23 16:42:05 +0530360
361/*
nxf24591c1cbeab2018-02-21 17:32:26 +0530362**
363** Type 4 Tag Definitions
364**
365*/
nxpandroid8f6d0532017-07-12 18:25:30 +0530366#define T4T_CMD_MIN_HDR_SIZE 4 /* CLA, INS, P1, P2 */
367#define T4T_CMD_MAX_HDR_SIZE 5 /* CLA, INS, P1, P2, Lc */
nxpandroidc7611652015-09-23 16:42:05 +0530368
nxpandroid8f6d0532017-07-12 18:25:30 +0530369#define T4T_VERSION_2_0 0x20 /* version 2.0 */
370#define T4T_VERSION_1_0 0x10 /* version 1.0 */
371#define T4T_MY_VERSION T4T_VERSION_2_0
372#define T4T_GET_MAJOR_VERSION(x) ((x) >> 4)
nxpandroidc7611652015-09-23 16:42:05 +0530373
nxpandroid8f6d0532017-07-12 18:25:30 +0530374#define T4T_CMD_CLASS 0x00
375#define T4T_CMD_INS_SELECT 0xA4
376#define T4T_CMD_INS_READ_BINARY 0xB0
377#define T4T_CMD_INS_UPDATE_BINARY 0xD6
378#define T4T_CMD_DES_CLASS 0x90
379#define T4T_CMD_INS_GET_HW_VERSION 0x60
380#define T4T_CMD_CREATE_AID 0xCA
381#define T4T_CMD_SELECT_APP 0x5A
382#define T4T_CMD_CREATE_DATAFILE 0xCD
383#define T4T_CMD_DES_WRITE 0x3D
384#define T4T_CMD_P1_SELECT_BY_NAME 0x04
385#define T4T_CMD_P1_SELECT_BY_FILE_ID 0x00
386#define T4T_CMD_P2_FIRST_OR_ONLY_00H 0x00
387#define T4T_CMD_P2_FIRST_OR_ONLY_0CH 0x0C
nxpandroidc7611652015-09-23 16:42:05 +0530388
nxpandroid8f6d0532017-07-12 18:25:30 +0530389/* Max number of bytes to be read from file in ReadBinary Command */
390#define T4T_MAX_LENGTH_LE 0xFF
391/* Max number of bytes written to NDEF file in UpdateBinary Command */
392#define T4T_MAX_LENGTH_LC 0xFF
nxpandroidc7611652015-09-23 16:42:05 +0530393
nxpandroid8f6d0532017-07-12 18:25:30 +0530394#define T4T_RSP_STATUS_WORDS_SIZE 0x02
nxpandroidc7611652015-09-23 16:42:05 +0530395
nxpandroid8f6d0532017-07-12 18:25:30 +0530396#define T4T_RSP_CMD_CMPLTED 0x9000
397#define T4T_RSP_NOT_FOUND 0x6A82
398#define T4T_RSP_WRONG_PARAMS 0x6B00
399#define T4T_RSP_CLASS_NOT_SUPPORTED 0x6E00
400#define T4T_RSP_WRONG_LENGTH 0x6700
401#define T4T_RSP_INSTR_NOT_SUPPORTED 0x6D00
402#define T4T_RSP_CMD_NOT_ALLOWED 0x6986
nxpandroidc7611652015-09-23 16:42:05 +0530403
nxpandroid8f6d0532017-07-12 18:25:30 +0530404/* V1.0 Type 4 Tag Applicaiton ID length */
405#define T4T_V10_NDEF_TAG_AID_LEN 0x07
406/* V2.0 Type 4 Tag Applicaiton ID length */
407#define T4T_V20_NDEF_TAG_AID_LEN 0x07
nxpandroidc7611652015-09-23 16:42:05 +0530408
nxpandroid8f6d0532017-07-12 18:25:30 +0530409/* Min of Max R-APDU data size */
410#define T4T_MIN_MLE 0x000F
nxpandroidc7611652015-09-23 16:42:05 +0530411
nxpandroid8f6d0532017-07-12 18:25:30 +0530412#define T4T_FILE_ID_SIZE 0x02
413#define T4T_CC_FILE_ID 0xE103
414#define T4T_CC_FILE_MIN_LEN 0x000F
nxpandroidc7611652015-09-23 16:42:05 +0530415
nxpandroid8f6d0532017-07-12 18:25:30 +0530416#define T4T_VERSION_OFFSET_IN_CC 0x02
417#define T4T_FC_TLV_OFFSET_IN_CC 0x07
418/* Offset of Write access byte from type field in CC */
419#define T4T_FC_WRITE_ACCESS_OFFSET_IN_TLV 0x07
nxpandroidc7611652015-09-23 16:42:05 +0530420
nxpandroid8f6d0532017-07-12 18:25:30 +0530421#define T4T_NDEF_FILE_CONTROL_TYPE 0x04 /* NDEF File Control Type */
nxpandroidc7611652015-09-23 16:42:05 +0530422
nxpandroid8f6d0532017-07-12 18:25:30 +0530423/* size of T(1),L(1),V(6) for file control */
424#define T4T_FILE_CONTROL_TLV_SIZE 0x08
425/* size of V(6) for file control */
426#define T4T_FILE_CONTROL_LENGTH 0x06
nxpandroidc7611652015-09-23 16:42:05 +0530427
nxpandroid8f6d0532017-07-12 18:25:30 +0530428/* read access granted without any security */
429#define T4T_FC_READ_ACCESS 0x00
430/* write access granted without any security */
431#define T4T_FC_WRITE_ACCESS 0x00
432/* proprietary write access range start */
433#define T4T_FC_WRITE_ACCESS_PROP_START 0x80
434/* no write access granted at all (read-only) */
435#define T4T_FC_NO_WRITE_ACCESS 0xFF
nxpandroidc7611652015-09-23 16:42:05 +0530436
nxpandroid8f6d0532017-07-12 18:25:30 +0530437#define T4T_FILE_LENGTH_SIZE 0x02
nxpandroid8f6d0532017-07-12 18:25:30 +0530438#define T4T_ADDI_FRAME_RESP 0xAFU
439#define T4T_SIZE_IDENTIFIER_2K 0x16U
440#define T4T_SIZE_IDENTIFIER_4K 0x18U
441#define T4T_SIZE_IDENTIFIER_8K 0x1AU
442#define T4T_DESEV1_MAJOR_VERSION 0x01U
443#define T4T_TYPE_DESFIRE_EV1 0x01U
444#define T4T_DESEV0_MAJOR_VERSION 0x00U
445#define T4T_DESEV0_MINOR_VERSION 0x06U
446#define T4T_DES_EV1_NFC_APP_ID 0x010000
447#define T4T_DES_EV0_NFC_APP_ID 0x10EEEE
nxpandroidc7611652015-09-23 16:42:05 +0530448
449/*
nxf24591c1cbeab2018-02-21 17:32:26 +0530450**
451** ISO 15693 Tag Definitions
452**
453*/
nxpandroidc7611652015-09-23 16:42:05 +0530454
nxpandroid8f6d0532017-07-12 18:25:30 +0530455/* A single sub-carrier frequency shall be used by VICC */
456#define I93_FLAG_SUB_CARRIER_SINGLE 0x00
nxpandroidc7611652015-09-23 16:42:05 +0530457
nxpandroid8f6d0532017-07-12 18:25:30 +0530458/* High data rate shall be used */
459#define I93_FLAG_DATA_RATE_HIGH 0x02
nxpandroidc7611652015-09-23 16:42:05 +0530460
nxpandroid8f6d0532017-07-12 18:25:30 +0530461/* Flags 5 to 8 meaning is according to table 5 */
462#define I93_FLAG_INVENTORY_SET 0x04
nxpandroidc7611652015-09-23 16:42:05 +0530463
nxpandroid8f6d0532017-07-12 18:25:30 +0530464/* No protocol format extension */
465#define I93_FLAG_PROT_EXT_NO 0x00
466/* Protocol format is extended. Reserved for future use */
467#define I93_FLAG_PROT_EXT_YES 0x08
nxpandroidc7611652015-09-23 16:42:05 +0530468
nxpandroid8f6d0532017-07-12 18:25:30 +0530469/* Request is addressed. UID field is included. It shall be executed only by
470 * VICC */
471#define I93_FLAG_ADDRESS_SET 0x20
472/* whose UID matches the UID specified in the request */
nxpandroidc7611652015-09-23 16:42:05 +0530473
nxpandroid8f6d0532017-07-12 18:25:30 +0530474/* AFI field is present */
475#define I93_FLAG_AFI_PRESENT 0x10
nxpandroidc7611652015-09-23 16:42:05 +0530476
nxpandroid8f6d0532017-07-12 18:25:30 +0530477#define I93_FLAG_SLOT_ONE 0x20 /* 1 slot */
nxpandroidc7611652015-09-23 16:42:05 +0530478
nxpandroid8f6d0532017-07-12 18:25:30 +0530479/* It shall be set to 0 if not otherwise defined by command */
480/* Meaning is defined by the command description. */
481#define I93_FLAG_OPTION_SET 0x40
nxpandroidc7611652015-09-23 16:42:05 +0530482
nxpandroid8f6d0532017-07-12 18:25:30 +0530483/* Error detected, Error code is in the "Error" field */
484#define I93_FLAG_ERROR_DETECTED 0x01
nxpandroidc7611652015-09-23 16:42:05 +0530485
486/* Response error code */
nxpandroid8f6d0532017-07-12 18:25:30 +0530487/* The command option is not supported */
488#define I93_ERROR_CODE_OPTION_NOT_SUPPORTED 0x03
nxpandroid8f6d0532017-07-12 18:25:30 +0530489/* The specific block is was not successfully programmed */
490#define I93_ERROR_CODE_BLOCK_FAIL_TO_WRITE 0x13
491/* The specific block is was not successfully locked */
nxpandroidc7611652015-09-23 16:42:05 +0530492
nxpandroid8f6d0532017-07-12 18:25:30 +0530493/* UID length in bytes */
494#define I93_UID_BYTE_LEN 8
495/* Data Storage Format is not supported */
496#define I93_DFS_UNSUPPORTED 0x00
nxpandroid8f6d0532017-07-12 18:25:30 +0530497/* Block is locked */
498#define I93_BLOCK_LOCKED 0x01
nxpandroidc7611652015-09-23 16:42:05 +0530499
500/* ISO 15693 Mandatory commands */
nxpandroid8f6d0532017-07-12 18:25:30 +0530501#define I93_CMD_INVENTORY 0x01 /* Inventory */
502#define I93_CMD_STAY_QUIET 0x02 /* Stay Quiet */
nxpandroidc7611652015-09-23 16:42:05 +0530503
504/* ISO 15693 Optional commands */
nxpandroid8f6d0532017-07-12 18:25:30 +0530505#define I93_CMD_READ_SINGLE_BLOCK 0x20 /* Read single block */
nxf24591c1cbeab2018-02-21 17:32:26 +0530506#define I93_CMD_EXT_READ_SINGLE_BLOCK 0x30 /* Extended Read single block */
nxpandroid8f6d0532017-07-12 18:25:30 +0530507#define I93_CMD_WRITE_SINGLE_BLOCK 0x21 /* Write single block */
nxf24591c1cbeab2018-02-21 17:32:26 +0530508#define I93_CMD_EXT_WRITE_SINGLE_BLOCK 0x31 /* Extended Write single block */
nxpandroid8f6d0532017-07-12 18:25:30 +0530509#define I93_CMD_LOCK_BLOCK 0x22 /* Lock block */
nxf24591c1cbeab2018-02-21 17:32:26 +0530510#define I93_CMD_EXT_LOCK_BLOCK 0x32 /* Extended Lock block */
nxpandroid8f6d0532017-07-12 18:25:30 +0530511#define I93_CMD_READ_MULTI_BLOCK 0x23 /* Read multiple blocks */
nxf24591c1cbeab2018-02-21 17:32:26 +0530512#define I93_CMD_EXT_READ_MULTI_BLOCK 0x33 /* Extended Read multiple blocks */
nxpandroid8f6d0532017-07-12 18:25:30 +0530513#define I93_CMD_WRITE_MULTI_BLOCK 0x24 /* Write multiple blocks */
nxf24591c1cbeab2018-02-21 17:32:26 +0530514#define I93_CMD_EXT_WRITE_MULTI_BLOCK 0x34 /* Write multiple blocks */
nxpandroid8f6d0532017-07-12 18:25:30 +0530515#define I93_CMD_SELECT 0x25 /* Select */
516#define I93_CMD_RESET_TO_READY 0x26 /* Reset to ready */
517#define I93_CMD_WRITE_AFI 0x27 /* Wreite AFI */
518#define I93_CMD_LOCK_AFI 0x28 /* Lock AFI */
519#define I93_CMD_WRITE_DSFID 0x29 /* Write DSFID */
520#define I93_CMD_LOCK_DSFID 0x2A /* Lock DSFID */
521/* Get system information */
522#define I93_CMD_GET_SYS_INFO 0x2B
nxf24591c1cbeab2018-02-21 17:32:26 +0530523/* Get extended system information */
524#define I93_CMD_EXT_GET_SYS_INFO 0x3B
nxpandroid8f6d0532017-07-12 18:25:30 +0530525/* Get multiple block security status */
526#define I93_CMD_GET_MULTI_BLK_SEC 0x2C
nxf24591c1cbeab2018-02-21 17:32:26 +0530527/* Get extended multiple block security status */
528#define I93_CMD_EXT_GET_MULTI_BLK_SEC 0x3C
nxpandroidc7611652015-09-23 16:42:05 +0530529
530/* Information flags definition */
nxpandroid8f6d0532017-07-12 18:25:30 +0530531/* DSFID is supported and DSFID field is present */
532#define I93_INFO_FLAG_DSFID 0x01
533/* AFI is supported and AFI field is present */
534#define I93_INFO_FLAG_AFI 0x02
535/* VICC memory size field is present */
536#define I93_INFO_FLAG_MEM_SIZE 0x04
537/* IC reference field is present */
538#define I93_INFO_FLAG_IC_REF 0x08
nxf24591c1cbeab2018-02-21 17:32:26 +0530539/* Memory coded in 2 bytes address */
540#define I93_INFO_FLAG_MOI 0x10
nxpandroidc7611652015-09-23 16:42:05 +0530541
nxpandroid8f6d0532017-07-12 18:25:30 +0530542/* Max block size in bytes */
543#define I93_MAX_BLOCK_LENGH 32
nxpandroidc7611652015-09-23 16:42:05 +0530544
545/* ICODE Capability Container(CC) definition */
nxf24591c1cbeab2018-02-21 17:32:26 +0530546#define I93_ICODE_CC_MAGIC_NUMER_E1 0xE1 /* magic number in CC[0] */
547#define I93_ICODE_CC_MAGIC_NUMER_E2 0xE2 /* magic number in CC[0] */
nxpandroid8f6d0532017-07-12 18:25:30 +0530548/* read access condition in CC[1] */
549#define I93_ICODE_CC_READ_ACCESS_MASK 0x0C
550/* read access granted without security */
551#define I93_ICODE_CC_READ_ACCESS_GRANTED 0x00
552/* write access condition in CC[1] */
553#define I93_ICODE_CC_WRITE_ACCESS_MASK 0x03
554/* write access granted without security */
555#define I93_ICODE_CC_WRITE_ACCESS_GRANTED 0x00
556/* write access not granted at all */
557#define I93_ICODE_CC_READ_ONLY 0x03
558/* read multi block supported in CC[3] */
559#define I93_ICODE_CC_MBREAD_MASK 0x01
560/* inventory page read supported in CC[3] */
561#define I93_ICODE_CC_IPREAD_MASK 0x02
562/* More than 2040 bytes are supported in CC[3] */
563#define I93_STM_CC_OVERFLOW_MASK 0x04
nxpandroidc7611652015-09-23 16:42:05 +0530564
565/* ICODE TLV type */
nxpandroid8f6d0532017-07-12 18:25:30 +0530566#define I93_ICODE_TLV_TYPE_NULL 0x00 /* NULL TLV */
567#define I93_ICODE_TLV_TYPE_NDEF 0x03 /* NDEF message TLV */
568#define I93_ICODE_TLV_TYPE_PROP 0xFD /* Proprietary TLV */
569#define I93_ICODE_TLV_TYPE_TERM 0xFE /* Terminator TLV */
nxpandroidc7611652015-09-23 16:42:05 +0530570
571/* UID Coding (UID Bit 64-57), First byte of ISO 15693 UID */
nxpandroid8f6d0532017-07-12 18:25:30 +0530572#define I93_UID_FIRST_BYTE 0xE0
nxpandroidc7611652015-09-23 16:42:05 +0530573
574/* UID Coding (UID Bit 56-49), IC manufacturer code */
nxpandroid8f6d0532017-07-12 18:25:30 +0530575#define I93_UID_IC_MFG_CODE_STM 0x02
576#define I93_UID_IC_MFG_CODE_NXP 0x04
577#define I93_UID_IC_MFG_CODE_TI 0x07
nxpandroidc7611652015-09-23 16:42:05 +0530578
579/* NXP, UID Coding of ICODE type (UID Bit 48-41) */
nxpandroid8f6d0532017-07-12 18:25:30 +0530580/* ICODE SLI, SLIX */
581#define I93_UID_ICODE_SLI 0x01
582/* ICODE SLI-S, SLIX-S */
583#define I93_UID_ICODE_SLI_S 0x02
584/* ICODE SLI-L, SLIX-L */
585#define I93_UID_ICODE_SLI_L 0x03
nxpandroidc7611652015-09-23 16:42:05 +0530586
nxpandroid8f6d0532017-07-12 18:25:30 +0530587/* IC Reference for ICODE SLI-L */
588#define I93_IC_REF_ICODE_SLI_L 0x03
589/* read multi block supported check bit */
590#define I93_ICODE_IC_REF_MBREAD_MASK 0x02
nxpandroidc7611652015-09-23 16:42:05 +0530591
592/* TI, UID Coding of product version (UID Bit 48-42) */
nxpandroid8f6d0532017-07-12 18:25:30 +0530593/* upper 7 bits */
594#define I93_UID_TAG_IT_HF_I_PRODUCT_ID_MASK 0xFE
595/* Tag-it HF-I Plus Inlay */
596#define I93_UID_TAG_IT_HF_I_PLUS_INLAY 0x00
597/* Tag-it HF-I Plus Chip */
598#define I93_UID_TAG_IT_HF_I_PLUS_CHIP 0x80
599/* Tag-it HF-I Standard Chip/Inlyas */
600#define I93_UID_TAG_IT_HF_I_STD_CHIP_INLAY 0xC0
601/* Tag-it HF-I Pro Chip/Inlyas */
602#define I93_UID_TAG_IT_HF_I_PRO_CHIP_INLAY 0xC4
nxpandroidc7611652015-09-23 16:42:05 +0530603
nxpandroid8f6d0532017-07-12 18:25:30 +0530604#define I93_TAG_IT_HF_I_STD_CHIP_INLAY_NUM_TOTAL_BLK 11
605#define I93_TAG_IT_HF_I_PRO_CHIP_INLAY_NUM_TOTAL_BLK 12
nxpandroidc7611652015-09-23 16:42:05 +0530606
nxpandroid8f6d0532017-07-12 18:25:30 +0530607#define I93_TAG_IT_HF_I_STD_PRO_CHIP_INLAY_BLK_SIZE 4
608#define I93_TAG_IT_HF_I_STD_PRO_CHIP_INLAY_NUM_USER_BLK 8
609/* LSB in Block 0x0A */
610#define I93_TAG_IT_HF_I_STD_PRO_CHIP_INLAY_AFI_LOCATION 40
nxpandroidc7611652015-09-23 16:42:05 +0530611
612/* STM, product version (IC manufacturer code) */
nxpandroid8f6d0532017-07-12 18:25:30 +0530613/* IC Reference mask for STM */
614#define I93_IC_REF_STM_MASK 0xFC
615/* IC Reference for LRI1K: 010000xx(b), blockSize: 4, numberBlocks: 0x20 */
616#define I93_IC_REF_STM_LRI1K 0x40
617/* IC Reference for LRI2K: 001000xx(b), blockSize: 4, numberBlocks: 0x40 */
618#define I93_IC_REF_STM_LRI2K 0x20
619/* IC Reference for LRIS2K: 001010xx(b), blockSize: 4, numberBlocks: 0x40 */
620#define I93_IC_REF_STM_LRIS2K 0x28
621/* IC Reference for LRIS64K: 010001xx(b), blockSize: 4, numberBlocks: 0x800
622 */
623#define I93_IC_REF_STM_LRIS64K 0x44
624/* IC Reference for M24LR64-R: 001011xx(b), blockSize: 4, numberBlocks: 0x800
625 */
626#define I93_IC_REF_STM_M24LR64_R 0x2C
627/* IC Reference for M24LR04E-R: 01011010(b), blockSize: 4, numberBlocks: 0x80 */
628#define I93_IC_REF_STM_M24LR04E_R 0x5A
629/* IC Reference for M24LR16E-R: 01001110(b), blockSize: 4, numberBlocks: 0x200
630 */
631#define I93_IC_REF_STM_M24LR16E_R 0x4E
632/* IC Reference for M24LR64E-R: 01011110(b), blockSize: 4, numberBlocks: 0x800
633 */
634#define I93_IC_REF_STM_M24LR64E_R 0x5E
nxf24591c1cbeab2018-02-21 17:32:26 +0530635/* IC Reference for ST25DV04K: 00100100(b), blockSize: 4, numberBlocks: 0x80
636 */
637#define I93_IC_REF_STM_ST25DV04K 0x24
638/* IC Reference for ST25DVHIK: 00100110(b), blockSize: 4, numberBlocks: 0x800
639 * or 0x200
640 */
641#define I93_IC_REF_STM_ST25DVHIK 0x26
nxpandroidc7611652015-09-23 16:42:05 +0530642
nxpandroid8f6d0532017-07-12 18:25:30 +0530643#define I93_STM_BLOCKS_PER_SECTOR 32
644#define I93_STM_MAX_BLOCKS_PER_READ 32
nxpandroidc7611652015-09-23 16:42:05 +0530645
646#endif /* TAGS_DEFS_H */