• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  *  Copyright (C) 1999-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 definition from NCI specification
22  *
23  ******************************************************************************/
24 
25 #ifndef NFC_NCI_DEFS_H
26 #define NFC_NCI_DEFS_H
27 
28 #include <stdint.h>
29 
30 /* Define the message header size for all NCI Commands and Notifications. */
31 #define NCI_MSG_HDR_SIZE 3  /* per NCI spec */
32 #define NCI_DATA_HDR_SIZE 3 /* per NCI spec */
33 #define NCI_MAX_PAYLOAD_SIZE 0xFE
34 #define NCI_CTRL_INIT_SIZE 32 /* initial NFCC control payload size */
35 #define NCI_MAX_VSC_SIZE 0xFF
36 #define APPL_DTA_MODE FALSE
37 /* NCI header (3) + callback function pointer(8; use 8 to be safe) + HCIT (1
38  * byte) */
39 #define NCI_VSC_MSG_HDR_SIZE 12
40 
41 /* Max frame size (256) - Prologue (1) - Epilogue (2) in ISO-DEP, CID and NAD
42  * are not used*/
43 #define NCI_ISO_DEP_MAX_INFO 253
44 /* Max payload (254) - Protocol Header (3) in NFC-DEP, DID and NAD are not used
45  */
46 #define NCI_NFC_DEP_MAX_DATA 251
47 
48 /* NCI Command and Notification Format:
49  * 3 byte message header:
50  * byte 0: MT PBF GID
51  * byte 1: OID
52  * byte 2: Message Length */
53 /* MT: Message Type (byte 0) */
54 #define NCI_MT_MASK 0xE0
55 #define NCI_MT_SHIFT 5
56 #define NCI_MT_DATA 0x00
57 #define NCI_MT_CMD 1 /* (NCI_MT_CMD << NCI_MT_SHIFT) = 0x20 */
58 #define NCI_MT_RSP 2 /* (NCI_MT_RSP << NCI_MT_SHIFT) = 0x40 */
59 #define NCI_MT_NTF 3 /* (NCI_MT_NTF << NCI_MT_SHIFT) = 0x60 */
60 
61 #define NCI_NTF_BIT 0x80 /* the tNFC_VS_EVT is a notification */
62 #define NCI_RSP_BIT 0x40 /* the tNFC_VS_EVT is a response     */
63 
64 /* for internal use only; not from specification */
65 /* the following 2 flags are used in layer_specific for fragmentation/reassembly
66  * of data packets */
67 
68 /* PBF: Packet Boundary Flag (byte 0) */
69 #define NCI_PBF_MASK 0x10
70 #define NCI_PBF_SHIFT 4
71 
72 /* GID: Group Identifier (byte 0) */
73 #define NCI_GID_MASK 0x0F
74 #define NCI_GID_CORE 0x00      /* 0000b NCI Core group */
75 #define NCI_GID_RF_MANAGE 0x01 /* 0001b RF Management group */
76 #define NCI_GID_EE_MANAGE 0x02 /* 0010b NFCEE Management group */
77 #define NCI_GID_PROP 0x0F      /* 1111b Proprietary */
78 /* 0111b - 1110b RFU */
79 
80 /* OID: Opcode Identifier (byte 1) */
81 #define NCI_OID_MASK 0x3F
82 #define NCI_OID_SHIFT 0
83 
84 /* For routing */
85 #define NCI_DH_ID 0 /* for DH */
86 /* To identify the loopback test */
87 #define NCI_TEST_ID 0xFE /* for loopback test */
88 
89 /* Destination Type */
90 #define NCI_DEST_TYPE_NFCC 1   /* NFCC - loopback */
91 #define NCI_DEST_TYPE_REMOTE 2 /* Remote NFC Endpoint */
92 #define NCI_DEST_TYPE_NFCEE 3  /* NFCEE */
93 #define NCI_DEST_TYPE_T4T_NFCEE 5 /* T4T NFCEE */
94 
95 /* builds byte0 of NCI Command and Notification packet */
96 #define NCI_MSG_BLD_HDR0(p, mt, gid) \
97   *(p)++ = (uint8_t)(((mt) << NCI_MT_SHIFT) | (gid));
98 
99 /* builds byte1 of NCI Command and Notification packet */
100 #define NCI_MSG_BLD_HDR1(p, oid) *(p)++ = (uint8_t)(((oid) << NCI_OID_SHIFT));
101 
102 /* parse byte0 of NCI packet */
103 #define NCI_MSG_PRS_HDR0(p, mt, pbf, gid)       \
104   (mt) = (*(p)&NCI_MT_MASK) >> NCI_MT_SHIFT;    \
105   (pbf) = (*(p)&NCI_PBF_MASK) >> NCI_PBF_SHIFT; \
106   (gid) = *(p)++ & NCI_GID_MASK;
107 
108 /* parse byte1 of NCI Cmd/Ntf */
109 #define NCI_MSG_PRS_HDR1(p, oid) \
110   (oid) = (*(p)&NCI_OID_MASK);   \
111   (p)++;
112 
113 /* NCI Data Format:
114  * byte 0: MT(0) PBF CID
115  * byte 1: RFU
116  * byte 2: Data Length */
117 /* CID: Connection Identifier (byte 0) 1-0xF Dynamically assigned (by NFCC), 0
118  * is predefined  */
119 #define NCI_CID_MASK 0x0F
120 
121 #define NCI_DATA_PBLD_HDR(p, pbf, cid, len)             \
122   *(p)++ = (uint8_t)(((pbf) << NCI_PBF_SHIFT) | (cid)); \
123   *(p)++ = 0;                                           \
124   *(p)++ = (len);
125 
126 #define NCI_DATA_PRS_HDR(p, pbf, cid, len)      \
127   (pbf) = (*(p)&NCI_PBF_MASK) >> NCI_PBF_SHIFT; \
128   (cid) = (*(p)&NCI_CID_MASK);                  \
129   (p)++;                                        \
130   (p)++;                                        \
131   (len) = *(p)++;
132 
133 /* Logical target ID 0x01-0xFE */
134 
135 /* CORE_RESET_NTF reset trigger type*/
136 #define NCI2_X_RESET_TRIGGER_TYPE_POWERED_ON 0x01
137 #define NCI2_X_RESET_TRIGGER_TYPE_CORE_RESET_CMD_RECEIVED 0x02
138 
139 /* Status Codes */
140 #define NCI_STATUS_OK 0x00
141 #define NCI_STATUS_REJECTED 0x01
142 #define NCI_STATUS_MESSAGE_CORRUPTED 0x02
143 #define NCI_STATUS_BUFFER_FULL 0xE0
144 #define NCI_STATUS_FAILED 0x03
145 #define NCI_STATUS_NOT_INITIALIZED 0x04
146 #define NCI_STATUS_SYNTAX_ERROR 0x05
147 #define NCI_STATUS_SEMANTIC_ERROR 0x06
148 #define NCI_STATUS_UNKNOWN_GID 0x07
149 #define NCI_STATUS_UNKNOWN_OID 0x08
150 #define NCI_STATUS_INVALID_PARAM 0x09
151 #define NCI_STATUS_MSG_SIZE_TOO_BIG 0x0A
152 #define NCI_STATUS_NOT_SUPPORTED 0x0B
153 /* discovery */
154 #define NCI_STATUS_ALREADY_STARTED 0xA0
155 #define NCI_STATUS_ACTIVATION_FAILED 0xA1
156 #define NCI_STATUS_TEAR_DOWN 0xA2
157 /* RF Interface */
158 #define NCI_STATUS_RF_FRAME_CORRUPTED 0x02
159 #define NCI_STATUS_RF_TRANSMISSION_ERR 0xB0
160 #define NCI_STATUS_RF_PROTOCOL_ERR 0xB1
161 #define NCI_STATUS_TIMEOUT 0xB2
162 #define NCI_STATUS_RF_UNEXPECTED_DATA 0xB3
163 /* NFCEE Interface */
164 #define NCI_STATUS_EE_INTF_ACTIVE_FAIL 0xC0
165 #define NCI_STATUS_EE_TRANSMISSION_ERR 0xC1
166 #define NCI_STATUS_EE_PROTOCOL_ERR 0xC2
167 #define NCI_STATUS_EE_TIMEOUT 0xC3
168 #define NFA_STATUS_READ_ONLY NCI_STATUS_READ_ONLY
169 #define NCI_STATUS_READ_ONLY 0xC4
170 
171 /* RF Technologies */
172 #define NCI_RF_TECHNOLOGY_A 0x00
173 #define NCI_RF_TECHNOLOGY_B 0x01
174 #define NCI_RF_TECHNOLOGY_F 0x02
175 #define NCI_RF_TECHNOLOGY_V 0x03
176 
177 /* Bit Rates */
178 #define NCI_BIT_RATE_106 0x00  /* 106 kbit/s */
179 #define NCI_BIT_RATE_212 0x01  /* 212 kbit/s */
180 #define NCI_BIT_RATE_424 0x02  /* 424 kbit/s */
181 #define NCI_BIT_RATE_848 0x03  /* 848 Kbit/s */
182 #define NCI_BIT_RATE_1696 0x04 /* 1696 Kbit/s*/
183 #define NCI_BIT_RATE_3392 0x05 /* 3392 Kbit/s*/
184 #define NCI_BIT_RATE_6784 0x06 /* 6784 Kbit/s*/
185 
186 /**********************************************
187  * NCI Core Group Opcode        - 0
188  **********************************************/
189 #define NCI_MSG_CORE_RESET 0
190 #define NCI_MSG_CORE_INIT 1
191 #define NCI_MSG_CORE_SET_CONFIG 2
192 #define NCI_MSG_CORE_GET_CONFIG 3
193 #define NCI_MSG_CORE_CONN_CREATE 4
194 #define NCI_MSG_CORE_CONN_CLOSE 5
195 #define NCI_MSG_CORE_CONN_CREDITS 6
196 #define NCI_MSG_CORE_GEN_ERR_STATUS 7
197 #define NCI_MSG_CORE_INTF_ERR_STATUS 8
198 #define NCI_MSG_CORE_SET_POWER_SUB_STATE 9
199 
200 /**********************************************
201  * RF MANAGEMENT Group Opcode    - 1
202  **********************************************/
203 #define NCI_MSG_RF_DISCOVER_MAP 0
204 #define NCI_MSG_RF_SET_ROUTING 1
205 #define NCI_MSG_RF_GET_ROUTING 2
206 #define NCI_MSG_RF_DISCOVER 3
207 #define NCI_MSG_RF_DISCOVER_SELECT 4
208 #define NCI_MSG_RF_INTF_ACTIVATED 5
209 #define NCI_MSG_RF_DEACTIVATE 6
210 #define NCI_MSG_RF_FIELD 7
211 #define NCI_MSG_RF_T3T_POLLING 8
212 #define NCI_MSG_RF_EE_ACTION 9
213 #define NCI_MSG_RF_EE_DISCOVERY_REQ 10
214 #define NCI_MSG_RF_PARAMETER_UPDATE 11
215 #define NCI_MSG_RF_INTF_EXT_START 12
216 #define NCI_MSG_RF_INTF_EXT_STOP 13
217 #define NCI_MSG_RF_ISO_DEP_NAK_PRESENCE 16
218 #define NCI_MSG_RF_REMOVAL_DETECTION 18
219 #define NCI_MSG_WPT_START 21
220 
221 /**********************************************
222  * NFCEE MANAGEMENT Group Opcode - 2
223  **********************************************/
224 #define NCI_MSG_NFCEE_DISCOVER 0
225 #define NCI_MSG_NFCEE_MODE_SET 1
226 #define NCI_MSG_NFCEE_STATUS 2
227 #define NCI_MSG_NFCEE_POWER_LINK_CTRL 3
228 /**********************************************
229  * NCI Proprietary  Group       - F
230  **********************************************/
231 #define NCI_MSG_PROP_ANDROID 0x0C
232 
233 #define NCI_ANDROID_RESTART_RF_DISCOVERY_REQUEST_NTF 0x07
234 
235 /* Android Opcodes */
236 #define NCI_ANDROID_GET_CAPS 0x0
237 #define NCI_ANDROID_POWER_SAVING 0x1
238 #define NCI_ANDROID_PASSIVE_OBSERVE 0x2
239 #define NCI_ANDROID_POLLING_FRAME_NTF 0x03
240 #define NCI_QUERY_ANDROID_PASSIVE_OBSERVE 0x4
241 #define NCI_ANDROID_SET_PASSIVE_OBSERVER_TECH 0x05
242 #define NCI_ANDROID_SET_PASSIVE_OBSERVER_EXIT_FRAME 0x06
243 #define NCI_ANDROID_GET_PASSIVE_OBSERVER_EXIT_FRAME 0x07
244 #define NCI_ANDROID_BLANK_NCI 0x8
245 #define NCI_ANDROID_SET_TECH_A_POLLING_LOOP_ANNOTATION 0x9
246 #define NCI_QUERY_ANDROID_POWER_SAVING 0x0A
247 #define NCI_ANDROID_PASSIVE_OBSERVER_SUSPENDED_NTF 0x0B
248 #define NCI_ANDROID_PASSIVE_OBSERVER_RESUMED_NTF 0x0C
249 
250 /* Android Get Proprietary Caps */
251 #define NCI_ANDROID_GET_CAPS_PARAM_SIZE 0x1
252 
253 /* Android Power Saving Params */
254 #define NCI_ANDROID_POWER_SAVING_PARAM_SIZE 0x2
255 #define NCI_ANDROID_POWER_SAVING_PARAM_DISABLE 0x0
256 #define NCI_ANDROID_POWER_SAVING_PARAM_ENABLE 0x1
257 
258 /* Android Passive Observer Settings */
259 #define NCI_ANDROID_PASSIVE_OBSERVE_PARAM_SIZE 0x2
260 #define NCI_QUERY_ANDROID_PASSIVE_OBSERVE_PARAM_SIZE 0x1
261 #define NCI_ANDROID_PASSIVE_OBSERVE_PARAM_DISABLE 0x0
262 #define NCI_ANDROID_PASSIVE_OBSERVE_PARAM_ENABLE 0x1
263 
264 /* Android Passive Observer per tech settings */
265 
266 #define NCI_ANDROID_PASSIVE_OBSERVE_PARAM_DISABLE 0x0
267 #define NCI_ANDROID_PASSIVE_OBSERVE_PARAM_ENABLE_A 0x1
268 #define NCI_ANDROID_PASSIVE_OBSERVE_PARAM_ENABLE_B 0x2
269 #define NCI_ANDROID_PASSIVE_OBSERVE_PARAM_ENABLE_F 0x4
270 #define NCI_ANDROID_PASSIVE_OBSERVE_PARAM_ENABLE_V 0x8
271 
272 /* Android Blank NCI Settings */
273 #define NCI_ANDROID_BLANK_COMMON 0x00
274 #define NCI_ANDROID_BLANK_VENDOR 0x01
275 #define NCI_ANDROID_BLANK_COMMON_ERROR 0xF0
276 #define NCI_ANDROID_BLANK_VENDOR_ERROR 0xF1
277 /**********************************************
278  * NCI Core Group Params
279  **********************************************/
280 #define NCI_CORE_PARAM_SIZE_RESET 0x01
281 
282 /**********************************************
283  * NCI Feature Bit
284  **********************************************/
285 #define NCI_FEAT_HCI_NETWORK 0x00000008
286 #define NCI_POLL_REMOVAL_DETECTION 0x00000020
287 
288 #define NCI_CORE_PARAM_SIZE_INIT(X) (((X) >= NCI_VERSION_2_0) ? (0x02) : (0x00))
289 #define NCI2_X_CORE_INIT_CMD_BYTE_0 0x00
290 #define NCI2_X_CORE_INIT_CMD_BYTE_1 0x00
291 
292 /* Status (1 octet) and number of params */
293 #define NCI_CORE_PARAM_SIZE_SET_POWER_SUB_STATE 0x01
294 
295 #define NCI_CORE_PARAM_SIZE_CON_CREATE 0x02 /* handle, num_tlv, (tlv) */
296 /* status, size, credits, conn_id */
297 #define NCI_CON_CREATE_TAG_RF_DISC_ID 0x00
298 #define NCI_CON_CREATE_TAG_NFCEE_VAL 0x01
299 
300 #define NCI_CORE_PARAM_SIZE_CON_CLOSE 0x01 /* Conn ID (1 octet) */
301 
302 /* Keep the NCI configuration and perform NCI initialization. */
303 #define NCI_RESET_TYPE_KEEP_CFG 0x00
304 /* Reset the NCI configuration, and perform NCI initialization. */
305 #define NCI_RESET_TYPE_RESET_CFG 0x01
306 
307 /* No operating field generated by remote device  */
308 #define NCI_RF_STS_NO_REMOTE 0x00
309 /* Operating field generated by remote device  */
310 #define NCI_RF_STS_REMOTE 0x01
311 
312 /* Discovery Action (1 octet) */
313 #define NCI_PARAM_SIZE_DISCOVER_NFCEE(X) \
314   (((X) >= NCI_VERSION_2_0) ? 0X00 : 0X01)
315 
316 #define NCI_DISCOVER_ACTION_DISABLE 0
317 #define NCI_DISCOVER_ACTION_ENABLE 1
318 
319 /* RF Technology and Mode */
320 #define NCI_RF_PARAM_ID_TECH_N_MODE 0x00
321 /* Transmit Bit Rate */
322 #define NCI_RF_PARAM_ID_TX_BIT_RATE 0x01
323 /* Receive Bit Rate */
324 #define NCI_RF_PARAM_ID_RX_BIT_RATE 0x02
325 /* B Data Exchange config param */
326 #define NCI_RF_PARAM_ID_B_DATA_EX_PARAM 0x03
327 
328 #define NCI_NFCEE_INTERFACE_APDU 0x00
329 #define NCI_NFCEE_INTERFACE_HCI_ACCESS 0x01
330 #define NCI_NFCEE_INTERFACE_T3T 0x02
331 #define NCI_NFCEE_INTERFACE_TRANSPARENT 0x03
332 #define NCI_NFCEE_INTERFACE_PROPRIETARY 0x80
333 /****************************************************
334  * NCI NFCEE INterface specific status Codes
335  ****************************************************/
336 #define NCI_NFCEE_STS_UNRECOVERABLE_ERROR 0x00
337 #define NCI_NFCEE_STS_INTF_ACTIVATION_FAILED 0xC0
338 #define NCI_NFCEE_STS_TRANSMISSION_ERROR 0xC1
339 #define NCI_NFCEE_STS_PROTOCOL_ERROR 0xC2
340 #define NCI_NFCEE_STS_TIMEOUT_ERROR 0xC3
341 
342 #define NCI_NFCEE_STS_CONN_ACTIVE 0x00
343 #define NCI_NFCEE_STS_CONN_INACTIVE 0x01
344 #define NCI_NFCEE_STS_REMOVED 0x02
345 
346 /* Logical Target ID (1 octet)NFCEE Mode (1 octet) */
347 #define NCI_CORE_PARAM_SIZE_NFCEE_MODE_SET 0x02
348 
349 /* Deactivate the connected NFCEE */
350 #define NCI_NFCEE_MD_DEACTIVATE 0x00
351 /* Activate the connected NFCEE */
352 #define NCI_NFCEE_MD_ACTIVATE 0x01
353 #define NCI_NUM_NFCEE_MODE 2
354 
355 /**********************************************
356  * NCI Deactivation Type
357  **********************************************/
358 #define NCI_DEACTIVATE_TYPE_IDLE 0      /* Idle Mode     */
359 #define NCI_DEACTIVATE_TYPE_SLEEP 1     /* Sleep Mode    */
360 #define NCI_DEACTIVATE_TYPE_SLEEP_AF 2  /* Sleep_AF Mode */
361 #define NCI_DEACTIVATE_TYPE_DISCOVERY 3 /* Discovery     */
362 
363 /**********************************************
364  * NCI Deactivation Reasons
365  **********************************************/
366 #define NCI_DEACTIVATE_REASON_DH_REQ 0       /* DH Request       */
367 #define NCI_DEACTIVATE_REASON_ENDPOINT_REQ 1 /* Endpoint Request */
368 #define NCI_DEACTIVATE_REASON_RF_LINK_LOSS 2 /* RF Link Loss     */
369 #define NCI_DEACTIVATE_REASON_NFCB_BAD_AFI 3 /* NFC-B Bad AFI    */
370 /* DH Request Failed due to error */
371 #define NCI_DEACTIVATE_REASON_DH_REQ_FAILED 4
372 #define NCI_DEACTIVATE_REASON_RF_REMOTE_EP_REMOVED 5
373 #define NCI_DEACTIVATE_REASON_RF_TIMEOUT_EXCEPTION 6
374 #define NCI_DEACTIVATE_REASON_RF_PROTOCOL_EXCEPTION 7
375 #define NCI_DEACTIVATE_REASON_FO_DETECTED 8
376 
377 /* The NFCEE status in NFCEE Status Notification */
378 typedef uint8_t tNCI_EE_NTF_STATUS;
379 
380 /* NFCEE Power and Link Configuration */
381 typedef uint8_t tNCI_NFCEE_PL_CONFIG;
382 
383 /**********************************************
384  * NCI Interface Mode
385  **********************************************/
386 #define NCI_INTERFACE_MODE_POLL_N_LISTEN 3
387 
388 /**********************************************
389  * NCI Interface Types
390  **********************************************/
391 #define NCI_INTERFACE_EE_DIRECT_RF 0
392 #define NCI_INTERFACE_FRAME 1
393 #define NCI_INTERFACE_ISO_DEP 2
394 #define NCI_INTERFACE_NFC_DEP 3
395 #define NCI_INTERFACE_MAX NCI_INTERFACE_NFC_DEP
396 #define NCI_INTERFACE_EXTENSION_MAX 2
397 #define NCI_INTERFACE_FIRST_VS 0x80
398 typedef uint8_t tNCI_INTF_TYPE;
399 typedef uint8_t tNCI_INTF_EXT_TYPE;
400 
401 /**********************************************
402  * NCI RF Interface Extensions Types
403  **********************************************/
404 #define NCI_INTF_EXT_WLCP_NON_AUTO 0x02
405 #define NCI_INTF_EXT_WLCP_SEMI_AUTO 0x03
406 
407 /**********************************************
408  * NCI RF Management / DISCOVERY Group Params
409  **********************************************/
410 
411 #define NCI_DISCOVER_PARAM_SIZE_SELECT 0x03 /* ID, protocol, interface */
412 #define NCI_DISCOVER_PARAM_SIZE_DEACT 0x01  /* type */
413 #define NCI_DISCOVER_PARAM_SIZE_DETECT 0x01 /* waiting_time */
414 #define NCI_DISCOVER_PARAM_SIZE_EXT 0x02    /* ID, parameter length */
415 
416 /**********************************************
417  * Supported Protocols
418  **********************************************/
419 #define NCI_PROTOCOL_UNKNOWN 0x00
420 #define NCI_PROTOCOL_T1T 0x01
421 #define NCI_PROTOCOL_T2T 0x02
422 #define NCI_PROTOCOL_T3T 0x03
423 #define NCI_PROTOCOL_T5T 0x06
424 #define NCI_PROTOCOL_ISO_DEP 0x04
425 #define NCI_PROTOCOL_NFC_DEP 0x05
426 
427 /* Discovery Types/Detected Technology and Mode */
428 #define NCI_DISCOVERY_TYPE_POLL_A 0x00
429 #define NCI_DISCOVERY_TYPE_POLL_B 0x01
430 #define NCI_DISCOVERY_TYPE_POLL_F 0x02
431 #define NCI_DISCOVERY_TYPE_POLL_V 0x06
432 #define NCI_DISCOVERY_TYPE_LISTEN_A 0x80
433 #define NCI_DISCOVERY_TYPE_LISTEN_B 0x81
434 #define NCI_DISCOVERY_TYPE_LISTEN_F 0x82
435 #define NCI_DISCOVERY_TYPE_LISTEN_ISO15693 0x86
436 
437 typedef uint8_t tNCI_DISCOVERY_TYPE;
438 
439 #define NCI_EE_TRIG_7816_SELECT 0x00
440 #define NCI_EE_TRIG_RF_PROTOCOL 0x01
441 #define NCI_EE_TRIG_RF_TECHNOLOGY 0x02
442 #define NCI_EE_TRIG_APP_INIT 0x10
443 
444 #define NCI_EE_ACT_TAG_AID 0xC0  /* AID                 */
445 #define NCI_EE_ACT_TAG_DATA 0xC3 /* hex data for app    */
446 
447 /* NFCEE ID (1 octet) PL config (1 octet) */
448 #define NCI_CORE_PARAM_SIZE_NFCEE_PL_CTRL 0x02
449 /* Status (1 octet) */
450 /* Technology based routing  */
451 #define NCI_ROUTE_TAG_TECH 0x00
452 /* Protocol based routing  */
453 #define NCI_ROUTE_TAG_PROTO 0x01
454 #define NCI_ROUTE_TAG_AID 0x02     /* AID routing */
455 #define NCI_ROUTE_TAG_SYSCODE 0x03 /* SystemCode routing */
456 
457 #define NCI_ROUTE_PWR_STATE_ON 0x01 /* The device is on */
458 /* The device is switched off */
459 #define NCI_ROUTE_PWR_STATE_SWITCH_OFF 0x02
460 /* The device's battery is removed */
461 #define NCI_ROUTE_PWR_STATE_BATT_OFF 0x04
462 /* The device is screen off Unlock mode */
463 #define NCI_ROUTE_PWR_STATE_SCREEN_OFF_UNLOCK() \
464   ((NFC_GetNCIVersion() >= NCI_VERSION_2_0) ? 0x08 : 0x80)
465 /* The device is screen on lock mode */
466 #define NCI_ROUTE_PWR_STATE_SCREEN_ON_LOCK() \
467   ((NFC_GetNCIVersion() >= NCI_VERSION_2_0) ? 0x10 : 0x40)
468 /* The device is screen off lock mode */
469 #define NCI_ROUTE_PWR_STATE_SCREEN_OFF_LOCK() \
470   ((NFC_GetNCIVersion() >= NCI_VERSION_2_0) ? 0x20 : 0x00)
471 
472 /* Hardware / Registration Identification  */
473 #define NCI_NFCEE_TAG_HW_ID 0x00
474 #define NCI_NFCEE_TAG_ATR_BYTES 0x01 /* ATR Bytes  */
475 /* T3T Command Set Interface Supplementary Info */
476 #define NCI_NFCEE_TAG_T3T_INFO 0x02
477 #define NCI_NFCEE_TAG_HCI_HOST_ID 0xA0 /* HCI host ID */
478 
479 #define NCI_DISCOVER_NTF_LAST 0x00
480 #define NCI_DISCOVER_NTF_LAST_ABORT 0x01
481 #define NCI_DISCOVER_NTF_MORE 0x02
482 
483 /* NCI RF Management Group Params */
484 #define NCI_RF_PARAM_SIZE_T3T_POLLING 0x04 /* System Code, RC, TSN */
485 
486 /**********************************************
487  * NCI Parameter IDs
488  **********************************************/
489 
490 #define NCI_PARAM_ID_TOTAL_DURATION 0x00
491 #define NCI_PARAM_ID_CON_DEVICES_LIMIT 0x01
492 #define NCI_PARAM_ID_CON_DISCOVERY_PARAM 0x02
493 #define NCI_PARAM_ID_PA_BAILOUT 0x08
494 #define NCI_PARAM_ID_PA_DEVICES_LIMIT 0x09
495 #define NCI_PARAM_ID_PB_AFI 0x10
496 #define NCI_PARAM_ID_PB_BAILOUT 0x11
497 #define NCI_PARAM_ID_PB_ATTRIB_PARAM1 0x12
498 #define NCI_PARAM_ID_PB_DEVICES_LIMIT 0x14
499 #define NCI_PARAM_ID_PF_BIT_RATE 0x18
500 #define NCI_PARAM_ID_PF_RC 0x19
501 #define NCI_PARAM_ID_PF_BAILOUT 0x19
502 #define NCI_PARAM_ID_PF_DEVICES_LIMIT 0x1A
503 #define NCI_PARAM_ID_PB_H_INFO 0x20
504 #define NCI_PARAM_ID_PI_BIT_RATE 0x21
505 #define NCI_PARAM_ID_ATR_REQ_CONFIG 0x2A
506 #define NCI_PARAM_ID_PV_DEVICES_LIMIT 0x2F
507 
508 #define NCI_PARAM_ID_LA_BIT_FRAME_SDD 0x30
509 #define NCI_PARAM_ID_LA_PLATFORM_CONFIG 0x31
510 #define NCI_PARAM_ID_LA_SEL_INFO 0x32
511 #define NCI_PARAM_ID_LA_NFCID1 0x33
512 #define NCI_PARAM_ID_LB_SENSB_INFO 0x38
513 #define NCI_PARAM_ID_LB_NFCID0 0x39
514 #define NCI_PARAM_ID_LB_APPDATA 0x3A
515 #define NCI_PARAM_ID_LB_SFGI 0x3B
516 #define NCI_PARAM_ID_LB_ADC_FO 0x3C
517 #define NCI_PARAM_ID_LB_PROTOCOL NCI_PARAM_ID_LB_SENSB_INFO
518 
519 #define NCI_PARAM_ID_LF_T3T_ID1 0x40
520 #define NCI_PARAM_ID_LF_T3T_ID2 0x41
521 #define NCI_PARAM_ID_LF_T3T_ID3 0x42
522 #define NCI_PARAM_ID_LF_T3T_ID4 0x43
523 #define NCI_PARAM_ID_LF_T3T_ID5 0x44
524 #define NCI_PARAM_ID_LF_T3T_ID6 0x45
525 #define NCI_PARAM_ID_LF_T3T_ID7 0x46
526 #define NCI_PARAM_ID_LF_T3T_ID8 0x47
527 #define NCI_PARAM_ID_LF_T3T_ID9 0x48
528 #define NCI_PARAM_ID_LF_T3T_ID10 0x49
529 #define NCI_PARAM_ID_LF_T3T_ID11 0x4A
530 #define NCI_PARAM_ID_LF_T3T_ID12 0x4B
531 #define NCI_PARAM_ID_LF_T3T_ID13 0x4C
532 #define NCI_PARAM_ID_LF_T3T_ID14 0x4D
533 #define NCI_PARAM_ID_LF_T3T_ID15 0x4E
534 #define NCI_PARAM_ID_LF_T3T_ID16 0x4F
535 #define NCI_PARAM_ID_LF_PROTOCOL 0x50
536 #define NCI_PARAM_ID_LF_T3T_PMM 0x51
537 /* max num of LF_T3T_ID supported by NFCC (1 for now) */
538 #define NCI_PARAM_ID_LF_T3T_MAX 0x52
539 #define NCI_PARAM_ID_LF_T3T_FLAGS2 0x53
540 #define NCI_PARAM_ID_LF_CON_BITR_F 0x54
541 #define NCI_PARAM_ID_LF_CON_ADV_FEAT 0x55
542 /*LF_T3T name changed in NCI2.0*/
543 #define NCI_PARAM_ID_LF_T3T_RD_ALLOWED 0x55
544 
545 #define NCI_PARAM_ID_FWI 0x58
546 #define NCI_PARAM_ID_LA_HIST_BY 0x59
547 #define NCI_PARAM_ID_LB_H_INFO_RSP 0x5A
548 #define NCI_PARAM_ID_LI_BIT_RATE 0x5B
549 
550 #define NCI_PARAM_ID_WT 0x60
551 #define NCI_PARAM_ID_ATR_RES_GEN_BYTES 0x61
552 #define NCI_PARAM_ID_ATR_RSP_CONFIG 0x62
553 #define NCI_PARAM_ID_PACM_BIT_RATE 0x68
554 
555 #define NCI_PARAM_ID_RF_FIELD_INFO 0x80
556 #define NCI_PARAM_ID_NFC_DEP_OP 0x82
557 
558 #define NCI_PARAM_ID_NFCC_CONFIG_CONTROL 0x85
559 
560 /* Type A Parameters */
561 #define NCI_PARAM_PLATFORM_T1T 0x0C
562 #define NCI_PARAM_SEL_INFO_ISODEP 0x20
563 /**********************************************
564  * NCI Parameter ID Lens
565  **********************************************/
566 #define NCI_PARAM_LEN_TOTAL_DURATION 2
567 
568 #define NCI_PARAM_LEN_CON_DISCOVERY_PARAM 1
569 
570 #define NCI_PARAM_LEN_PF_RC 1
571 
572 #define NCI_PARAM_LEN_LA_BIT_FRAME_SDD 1
573 #define NCI_PARAM_LEN_LA_PLATFORM_CONFIG 1
574 #define NCI_PARAM_LEN_LA_SEL_INFO 1
575 
576 #define NCI_PARAM_LEN_LB_SENSB_INFO 1
577 #define NCI_PARAM_LEN_LB_NFCID0 4
578 #define NCI_PARAM_LEN_LB_APPDATA 4
579 #define NCI_PARAM_LEN_LB_ADC_FO 1
580 #define NCI_PARAM_LEN_RF_FIELD_INFO 1
581 
582 #define NCI_PARAM_LEN_LF_PROTOCOL 1
583 #define NCI_PARAM_LEN_LF_T3T_FLAGS2 2
584 #define NCI_PARAM_LEN_LF_T3T_PMM 8
585 #define NCI_PARAM_LEN_LF_T3T_ID(X) (((X) >= NCI_VERSION_2_0) ? (0x12) : (0x0A))
586 #define NCI_PARAM_LEN_LF_CON_ADV_FEAT 1
587 
588 #define NCI_PARAM_LEN_LF_T3T_RD_ALLOWED 1  // Listen F NCI2.0 Parameter
589 
590 #define NCI_PARAM_LEN_FWI 1
591 #define NCI_PARAM_LEN_WT 1
592 /* GEN_BYTES - variable */
593 
594 /* Listen protocol bits - NCI_PARAM_ID_LF_PROTOCOL and
595  * NCI_PARAM_ID_LB_SENSB_INFO */
596 #define NCI_LISTEN_PROTOCOL_ISO_DEP 0x01
597 
598 /* LF_T3T_FLAGS2 listen bits all-disabled definition */
599 #define NCI_LF_T3T_FLAGS2_ALL_DISABLED 0x0000
600 
601 /* The DH-NFCEE listen is considered as a enable NFCEE */
602 #define NCI_LISTEN_DH_NFCEE_ENABLE_MASK 0x00
603 /* The DH-NFCEE listen is considered as a disable NFCEE */
604 #define NCI_LISTEN_DH_NFCEE_DISABLE_MASK 0x02
605 /* The DH polling is considered as a disable NFCEE */
606 #define NCI_POLLING_DH_DISABLE_MASK 0x00
607 /* The DH polling is considered as a enable NFCEE */
608 #define NCI_POLLING_DH_ENABLE_MASK 0x01
609 /* SCBR support check with Core Init resp OCT1 byte */
610 #define NCI_SCBR_MASK 0x10
611 
612 /* AID matching is allowed when the SELECT AID is longer */
613 #define NCI_ROUTE_QUAL_LONG_SELECT 0x10
614 /* AID matching is allowed when the SELECT AID is shorter */
615 #define NCI_ROUTE_QUAL_SHORT_SELECT 0x20
616 /* AID is blocked in unsupported power mode */
617 #define NCI_ROUTE_QUAL_BLOCK_ROUTE 0x40
618 
619 #ifndef NCI_GET_CMD_BUF
620 #if (HCI_USE_VARIABLE_SIZE_CMD_BUF == FALSE)
621 /* Allocate fixed-size buffer from HCI_CMD_POOL (default case) */
622 #define NCI_GET_CMD_BUF(paramlen)                              \
623   gki_utils ? (NFC_HDR*)gki_utils->getpoolbuf(NFC_NCI_POOL_ID) \
624             : (NFC_HDR*)(new GkiUtils())->getpoolbuf(NFC_NCI_POOL_ID)
625 #else
626 /* Allocate smallest possible buffer (for platforms with limited RAM) */
627 #define NCI_GET_CMD_BUF(paramlen)                                    \
628   ((NFC_HDR*)GKI_getbuf((uint16_t)(NFC_HDR_SIZE + NCI_MSG_HDR_SIZE + \
629                                    NCI_MSG_OFFSET_SIZE + (paramlen))))
630 #endif
631 #endif /* NCI_GET_CMD_BUF */
632 
633 #define NCI_MAX_AID_LEN 16
634 
635 typedef struct {
636   uint8_t type;
637   uint8_t frequency;
638 } tNCI_DISCOVER_PARAMS;
639 
640 typedef struct {
641   uint8_t protocol;
642   uint8_t mode;
643   uint8_t intf_type;
644 } tNCI_DISCOVER_MAPS;
645 
646 #define NCI_NFCID1_MAX_LEN 10
647 #define NCI_T1T_HR_LEN 2
648 typedef struct {
649   uint8_t sens_res[2]; /* SENS_RES Response (ATQA). Available after Technology
650                           Detection */
651   uint8_t nfcid1_len;  /* 4, 7 or 10 */
652   uint8_t nfcid1[NCI_NFCID1_MAX_LEN]; /* AKA NFCID1 */
653   uint8_t sel_rsp; /* SEL_RSP (SAK) Available after Collision Resolution */
654   uint8_t hr_len;  /* 2, if T1T HR0/HR1 is reported */
655   uint8_t hr[NCI_T1T_HR_LEN]; /* T1T HR0 is in hr[0], HR1 is in hr[1] */
656 } tNCI_RF_PA_PARAMS;
657 
658 #define NCI_MAX_SENSB_RES_LEN 12
659 typedef struct {
660   uint8_t sensb_res_len; /* Length of SENSB_RES Response (Byte 2 - Byte 12 or
661                             13) Available after Technology Detection */
662   uint8_t sensb_res[NCI_MAX_SENSB_RES_LEN]; /* SENSB_RES Response (ATQ) */
663 } tNCI_RF_PB_PARAMS;
664 
665 #define NCI_MAX_SENSF_RES_LEN 18
666 #define NCI_NFCID2_LEN 8
667 #define NCI_T3T_PMM_LEN 8
668 #define NCI_SYSTEMCODE_LEN 2
669 #define NCI_RF_F_UID_LEN NCI_NFCID2_LEN
670 #define NCI_MRTI_CHECK_INDEX 13
671 #define NCI_MRTI_UPDATE_INDEX 14
672 typedef struct {
673   uint8_t bit_rate;      /* NFC_BIT_RATE_212 or NFC_BIT_RATE_424 */
674   uint8_t sensf_res_len; /* Length of SENSF_RES Response (Byte 2 - Byte 17 or
675                             19) Available after Technology Detection */
676   uint8_t sensf_res[NCI_MAX_SENSF_RES_LEN]; /* SENSB_RES Response */
677 } tNCI_RF_PF_PARAMS;
678 
679 typedef struct {
680   uint8_t nfcid2[NCI_NFCID2_LEN]; /* NFCID2 generated by the Local NFCC for
681                                      NFC-DEP Protocol.Available for Frame
682                                      Interface  */
683 } tNCI_RF_LF_PARAMS;
684 
685 #ifndef NCI_MAX_ATS_LEN
686 #define NCI_MAX_ATS_LEN 64
687 #endif
688 #ifndef NCI_MAX_HIS_BYTES_LEN
689 #define NCI_MAX_HIS_BYTES_LEN 50
690 #endif
691 #ifndef NCI_MAX_GEN_BYTES_LEN
692 #define NCI_MAX_GEN_BYTES_LEN 48
693 #endif
694 
695 #define NCI_ATS_T0_INDEX 0
696 #define NCI_ATS_TC_MASK 0x40
697 #define NCI_ATS_TB_MASK 0x20
698 #define NCI_ATS_TA_MASK 0x10
699 typedef struct {
700   uint8_t ats_res_len;              /* Length of ATS RES */
701   uint8_t ats_res[NCI_MAX_ATS_LEN]; /* ATS RES defined in [DIGPROT] */
702 } tNCI_INTF_PA_ISO_DEP;
703 
704 typedef struct {
705   uint8_t rats; /* RATS */
706 } tNCI_INTF_LA_ISO_DEP;
707 
708 #define NCI_P_GEN_BYTE_INDEX 15
709 #define NCI_L_GEN_BYTE_INDEX 14
710 #define NCI_L_NFC_DEP_TO_INDEX 13
711 
712 #define NCI_MAX_ATTRIB_LEN (10 + NCI_MAX_GEN_BYTES_LEN)
713 
714 typedef struct {
715   uint8_t attrib_res_len; /* Length of ATTRIB RES */
716   uint8_t
717       attrib_res[NCI_MAX_ATTRIB_LEN]; /* ATTRIB RES  as defined in [DIGPROT] */
718 } tNCI_INTF_PB_ISO_DEP;
719 
720 typedef struct {
721   uint8_t attrib_req_len;                 /* Length of ATTRIB REQ */
722   uint8_t attrib_req[NCI_MAX_ATTRIB_LEN]; /* ATTRIB REQ (Byte 2 - Byte 10+k) as
723                                              defined in [DIGPROT] */
724 } tNCI_INTF_LB_ISO_DEP;
725 
726 typedef struct {
727   uint8_t atr_res_len;                      /* Length of ATR_RES            */
728   uint8_t atr_res[NCI_MAX_ATS_LEN];         /* ATR_RES (Byte 3 - Byte 17+n) */
729   uint8_t max_payload_size;                 /* 64, 128, 192 or 254          */
730   uint8_t gen_bytes_len;                    /* len of general bytes         */
731   uint8_t gen_bytes[NCI_MAX_GEN_BYTES_LEN]; /* general bytes                */
732   uint8_t waiting_time;                     /* WT -> Response Waiting Time
733                                                RWT = (256 x 16/fC) x 2WT    */
734 } tNCI_RF_ACM_P_PARAMS;
735 
736 #define NCI_WPT_POWER_ADJ_REQ_TYPE 0x00
737 #define NCI_WPT_TIME_INT_TYPE 0x01
738 
739 #endif /* NFC_NCI_DEFS_H */
740