1 /******************************************************************************
2  *
3  *  Copyright (C) 2010-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 is the public interface file for NFA, Broadcom's NFC application
22  *  layer for mobile phones.
23  *
24  ******************************************************************************/
25 #ifndef NFA_API_H
26 #define NFA_API_H
27 
28 #include "gki.h"
29 #include "nci_defs.h"
30 #include "nfc_api.h"
31 #include "nfc_hal_api.h"
32 #include "nfc_target.h"
33 #include "rw_api.h"
34 #include "tags_defs.h"
35 
36 /*****************************************************************************
37 **  Constants and data types
38 *****************************************************************************/
39 
40 /* Max length of Appliction ID in 7816-4 */
41 #define NFA_MAX_AID_LEN NFC_MAX_AID_LEN
42 #define NFA_MIN_AID_LEN 5 /* per NCI specification */
43 
44 /* NFA API return status codes */
45 /* Command succeeded    */
46 #define NFA_STATUS_OK NCI_STATUS_OK
47 /* Command is rejected. */
48 #define NFA_STATUS_REJECTED NCI_STATUS_REJECTED
49 /* Message is corrupted */
50 #define NFA_STATUS_MSG_CORRUPTED NCI_STATUS_MESSAGE_CORRUPTED
51 /* buffer full          */
52 #define NFA_STATUS_BUFFER_FULL NCI_STATUS_BUFFER_FULL
53 /* failed               */
54 #define NFA_STATUS_FAILED NCI_STATUS_FAILED
55 /* not initialized      */
56 #define NFA_STATUS_NOT_INITIALIZED NCI_STATUS_NOT_INITIALIZED
57 /* Syntax error         */
58 #define NFA_STATUS_SYNTAX_ERROR NCI_STATUS_SYNTAX_ERROR
59 /* Semantic error       */
60 #define NFA_STATUS_SEMANTIC_ERROR NCI_STATUS_SEMANTIC_ERROR
61 /* Unknown NCI Group ID */
62 #define NFA_STATUS_UNKNOWN_GID NCI_STATUS_UNKNOWN_GID
63 /* Unknown NCI Opcode   */
64 #define NFA_STATUS_UNKNOWN_OID NCI_STATUS_UNKNOWN_OID
65 /* Invalid Parameter    */
66 #define NFA_STATUS_INVALID_PARAM NCI_STATUS_INVALID_PARAM
67 /* Message size too big */
68 #define NFA_STATUS_MSG_SIZE_TOO_BIG NCI_STATUS_MSG_SIZE_TOO_BIG
69 /* Already started      */
70 #define NFA_STATUS_ALREADY_STARTED NCI_STATUS_ALREADY_STARTED
71 /* Activation Failed    */
72 #define NFA_STATUS_ACTIVATION_FAILED NCI_STATUS_ACTIVATION_FAILED
73 /* Tear Down Error      */
74 #define NFA_STATUS_TEAR_DOWN NCI_STATUS_TEAR_DOWN
75 /* RF transmission error*/
76 #define NFA_STATUS_RF_TRANSMISSION_ERR NCI_STATUS_RF_TRANSMISSION_ERR
77 /* RF protocol error    */
78 #define NFA_STATUS_RF_PROTOCOL_ERR NCI_STATUS_RF_PROTOCOL_ERR
79 /* RF Timeout           */
80 #define NFA_STATUS_TIMEOUT NCI_STATUS_TIMEOUT
81 /* EE Intf activate err */
82 #define NFA_STATUS_EE_INTF_ACTIVE_FAIL NCI_STATUS_EE_INTF_ACTIVE_FAIL
83 /* EE transmission error*/
84 #define NFA_STATUS_EE_TRANSMISSION_ERR NCI_STATUS_EE_TRANSMISSION_ERR
85 /* EE protocol error    */
86 #define NFA_STATUS_EE_PROTOCOL_ERR NCI_STATUS_EE_PROTOCOL_ERR
87 /* EE Timeout           */
88 #define NFA_STATUS_EE_TIMEOUT NCI_STATUS_EE_TIMEOUT
89 
90 /* Command started successfully */
91 #define NFA_STATUS_CMD_STARTED NFC_STATUS_CMD_STARTED
92 /* NFCC Timeout in responding to an NCI command */
93 #define NFA_STATUS_HW_TIMEOUT NFC_STATUS_HW_TIMEOUT
94 /* More NFA_CE_GET_ROUTING_REVT to follow */
95 #define NFA_STATUS_CONTINUE NFC_STATUS_CONTINUE
96 /* API is called to perform illegal function */
97 #define NFA_STATUS_REFUSED NFC_STATUS_REFUSED
98 /* Wrong format of R-APDU, CC file or NDEF file */
99 #define NFA_STATUS_BAD_RESP NFC_STATUS_BAD_RESP
100 /* 7816 Status Word is not command complete(0x9000) */
101 #define NFA_STATUS_CMD_NOT_CMPLTD NFC_STATUS_CMD_NOT_CMPLTD
102 /* Out of GKI buffers */
103 #define NFA_STATUS_NO_BUFFERS NFC_STATUS_NO_BUFFERS
104 /* Protocol mismatch between API and activated one */
105 #define NFA_STATUS_WRONG_PROTOCOL NFC_STATUS_WRONG_PROTOCOL
106 /* Another Tag command is already in progress */
107 #define NFA_STATUS_BUSY NFC_STATUS_BUSY
108 
109 /* data len exceeds MIU                             */
110 #define NFA_STATUS_BAD_LENGTH NFC_STATUS_BAD_LENGTH
111 /* invalid handle                                   */
112 #define NFA_STATUS_BAD_HANDLE NFC_STATUS_BAD_HANDLE
113 /* congested                                        */
114 #define NFA_STATUS_CONGESTED NFC_STATUS_CONGESTED
115 typedef uint8_t tNFA_STATUS;
116 
117 /* Handle for NFA registrations and connections */
118 typedef uint16_t tNFA_HANDLE;
119 #define NFA_HANDLE_INVALID (0xFFFF)
120 /* NFA Handle definitions */
121 
122 /* The upper byte of NFA_HANDLE signifies the handle group */
123 /* Connection handles           */
124 #define NFA_HANDLE_GROUP_CONNECTION 0x0100
125 /* NDEF Type Handler handles    */
126 #define NFA_HANDLE_GROUP_NDEF_HANDLER 0x0200
127 /* DH Card Emulation handles    */
128 #define NFA_HANDLE_GROUP_CE 0x0300
129 /* Handles to identify NFCEE    */
130 #define NFA_HANDLE_GROUP_EE 0x0400
131 /* P2P handles                  */
132 #define NFA_HANDLE_GROUP_P2P 0x0500
133 /* SNEP handles                 */
134 #define NFA_HANDLE_GROUP_SNEP 0x0700
135 /* HCI handles                  */
136 #define NFA_HANDLE_GROUP_HCI 0x0800
137 /* Local NDEF message handle    */
138 #define NFA_HANDLE_GROUP_LOCAL_NDEF 0x0900
139 #define NFA_HANDLE_GROUP_MASK 0xFF00
140 #define NFA_HANDLE_MASK 0x00FF
141 
142 /* NCI Parameter IDs */
143 typedef uint8_t tNFA_PMID;
144 
145 /* Definitions for tNFA_TECHNOLOGY_MASK */
146 #define NFA_TECHNOLOGY_MASK_A 0x01        /* NFC Technology A             */
147 #define NFA_TECHNOLOGY_MASK_B 0x02        /* NFC Technology B             */
148 #define NFA_TECHNOLOGY_MASK_F 0x04        /* NFC Technology F             */
149 #define NFA_TECHNOLOGY_MASK_ISO15693 0x08 /* Proprietary Technology       */
150 #define NFA_TECHNOLOGY_MASK_B_PRIME 0x10  /* Proprietary Technology       */
151 #define NFA_TECHNOLOGY_MASK_KOVIO 0x20    /* Proprietary Technology       */
152 /* NFC Technology A active mode */
153 #define NFA_TECHNOLOGY_MASK_A_ACTIVE 0x40
154 /* NFC Technology F active mode */
155 #define NFA_TECHNOLOGY_MASK_F_ACTIVE 0x80
156 /* All supported technologies   */
157 #define NFA_TECHNOLOGY_MASK_ALL 0xFF
158 typedef uint8_t tNFA_TECHNOLOGY_MASK;
159 
160 /* Definitions for NFC protocol for RW, CE and P2P APIs */
161 /* Type1Tag - NFC-A */
162 #define NFA_PROTOCOL_T1T NFC_PROTOCOL_T1T
163 /* MIFARE/Type2Tag - NFC-A */
164 #define NFA_PROTOCOL_T2T NFC_PROTOCOL_T2T
165 /* Felica/Type3Tag - NFC-F */
166 #define NFA_PROTOCOL_T3T NFC_PROTOCOL_T3T
167 /* Type 4A,4B - NFC-A or NFC-B */
168 #define NFA_PROTOCOL_ISO_DEP NFC_PROTOCOL_ISO_DEP
169 /* NFCDEP/LLCP - NFC-A or NFC-F */
170 #define NFA_PROTOCOL_NFC_DEP NFC_PROTOCOL_NFC_DEP
171 #define NFA_PROTOCOL_ISO15693 NFC_PROTOCOL_15693
172 #define NFA_PROTOCOL_B_PRIME NFC_PROTOCOL_B_PRIME
173 #define NFA_PROTOCOL_KOVIO NFC_PROTOCOL_KOVIO
174 #define NFA_PROTOCOL_MIFARE NFC_PROTOCOL_MIFARE
175 #define NFA_PROTOCOL_INVALID 0xFF
176 #define NFA_MAX_NUM_PROTOCOLS 8
177 typedef uint8_t tNFA_NFC_PROTOCOL;
178 
179 /* Definitions for tNFA_PROTOCOL_MASK */
180 #define NFA_PROTOCOL_MASK_T1T 0x01     /* Type 1 tag          */
181 #define NFA_PROTOCOL_MASK_T2T 0x02     /* MIFARE / Type 2 tag */
182 #define NFA_PROTOCOL_MASK_T3T 0x04     /* FeliCa / Type 3 tag */
183 #define NFA_PROTOCOL_MASK_ISO_DEP 0x08 /* ISODEP/4A,4B        */
184 #define NFA_PROTOCOL_MASK_NFC_DEP 0x10 /* NFCDEP/LLCP         */
185 typedef uint8_t tNFA_PROTOCOL_MASK;
186 
187 /* NFA_DM callback events */
188 /* Result of NFA_Enable             */
189 #define NFA_DM_ENABLE_EVT 0
190 /* Result of NFA_Disable            */
191 #define NFA_DM_DISABLE_EVT 1
192 /* Result of NFA_SetConfig          */
193 #define NFA_DM_SET_CONFIG_EVT 2
194 /* Result of NFA_GetConfig          */
195 #define NFA_DM_GET_CONFIG_EVT 3
196 /* Result of NFA_PowerOffSleepMode  */
197 #define NFA_DM_PWR_MODE_CHANGE_EVT 4
198 #define NFA_DM_RF_FIELD_EVT 5 /* Status of RF Field               */
199 /* NFCC is not responding           */
200 #define NFA_DM_NFCC_TIMEOUT_EVT 6
201 /* NCI Tranport error               */
202 #define NFA_DM_NFCC_TRANSPORT_ERR_EVT 7
203 
204 /* T1T HR length            */
205 #define NFA_T1T_HR_LEN T1T_HR_LEN
206 /* Max UID length of T1/T2  */
207 #define NFA_MAX_UID_LEN TAG_MAX_UID_LEN
208 /* T1T UID length           */
209 #define NFA_T1T_UID_LEN T1T_UID_LEN
210 /* UID len for T1T cmds     */
211 #define NFA_T1T_CMD_UID_LEN T1T_CMD_UID_LEN
212 /* T2T UID length           */
213 #define NFA_T2T_UID_LEN T2T_UID_LEN
214 
215 /* Tag is read only */
216 #define NFA_RW_NDEF_FL_READ_ONLY RW_NDEF_FL_READ_ONLY
217 /* Tag formated for NDEF */
218 #define NFA_RW_NDEF_FL_FORMATED RW_NDEF_FL_FORMATED
219 /* NDEF supported by the tag */
220 #define NFA_RW_NDEF_FL_SUPPORTED RW_NDEF_FL_SUPPORTED
221 /* Unable to find if tag is ndef capable/formated/read only */
222 #define NFA_RW_NDEF_FL_UNKNOWN RW_NDEF_FL_UNKNOWN
223 /* Tag supports format operation */
224 #define NFA_RW_NDEF_FL_FORMATABLE RW_NDEF_FL_FORMATABLE
225 /* Tag can be soft locked */
226 #define NFA_RW_NDEF_FL_SOFT_LOCKABLE RW_NDEF_FL_SOFT_LOCKABLE
227 /* Tag can be hard locked */
228 #define NFA_RW_NDEF_FL_HARD_LOCKABLE RW_NDEF_FL_HARD_LOCKABLE
229 /* Tag is one time programmable */
230 #define NFA_RW_NDEF_FL_OTP RW_NDEF_FL_OTP
231 
232 typedef uint8_t tNFA_RW_NDEF_FLAG;
233 
234 /* Data for NFA_DM_SET_CONFIG_EVT */
235 typedef struct {
236   tNFA_STATUS status;                   /* NFA_STATUS_OK if successful  */
237   uint8_t num_param_id;                 /* Number of rejected Param ID  */
238   tNFA_PMID param_ids[NFC_MAX_NUM_IDS]; /* Rejected Param ID            */
239 } tNFA_SET_CONFIG;
240 
241 /* Data for NFA_DM_GET_CONFIG_EVT */
242 typedef struct {
243   tNFA_STATUS status;    /* NFA_STATUS_OK if successful              */
244   uint16_t tlv_size;     /* The length of TLV                        */
245   uint8_t param_tlvs[1]; /* TLV (Parameter ID-Len-Value byte stream) */
246 } tNFA_GET_CONFIG;
247 
248 #define NFA_DM_PWR_MODE_FULL 0x04
249 #define NFA_DM_PWR_MODE_OFF_SLEEP 0x00
250 
251 typedef uint8_t tNFA_DM_PWR_MODE;
252 
253 /* Data for NFA_DM_PWR_MODE_CHANGE_EVT */
254 typedef struct {
255   tNFA_STATUS status; /* NFA_STATUS_OK if successful */
256   /* NFA_DM_PWR_MODE_FULL or NFA_DM_PWR_MODE_OFF_SLEEP */
257   tNFA_DM_PWR_MODE power_mode;
258 } tNFA_DM_PWR_MODE_CHANGE;
259 
260 /* Data for NFA_DM_RF_FIELD_EVT */
261 #define NFA_DM_RF_FIELD_OFF 0x00
262 #define NFA_DM_RF_FIELD_ON 0x01
263 
264 typedef struct {
265   tNFA_STATUS status; /* NFA_STATUS_OK if successful  */
266   /* NFA_DM_RF_FIELD_ON if operating field generated by remote */
267   uint8_t rf_field_status;
268 } tNFA_DM_RF_FIELD;
269 
270 /* Union of all DM callback structures */
271 typedef union {
272   tNFA_STATUS status;                 /* NFA_DM_ENABLE_EVT        */
273   tNFA_SET_CONFIG set_config;         /* NFA_DM_SET_CONFIG_EVT    */
274   tNFA_GET_CONFIG get_config;         /* NFA_DM_GET_CONFIG_EVT    */
275   tNFA_DM_PWR_MODE_CHANGE power_mode; /* NFA_DM_PWR_MODE_CHANGE_EVT   */
276   tNFA_DM_RF_FIELD rf_field;          /* NFA_DM_RF_FIELD_EVT      */
277   void* p_vs_evt_data;                /* Vendor-specific evt data */
278 } tNFA_DM_CBACK_DATA;
279 
280 /* NFA_DM callback */
281 typedef void(tNFA_DM_CBACK)(uint8_t event, tNFA_DM_CBACK_DATA* p_data);
282 
283 /* NFA Connection Callback Events */
284 #define NFA_POLL_ENABLED_EVT 0  /* Polling enabled event */
285 #define NFA_POLL_DISABLED_EVT 1 /* Polling disabled event */
286 /* NFC link/protocol discovery notificaiton */
287 #define NFA_DISC_RESULT_EVT 2
288 /* NFC link/protocol discovery select response */
289 #define NFA_SELECT_RESULT_EVT 3
290 #define NFA_DEACTIVATE_FAIL_EVT 4 /* NFA_Deactivate failure */
291 /* NFC link/protocol activated */
292 #define NFA_ACTIVATED_EVT 5
293 /* NFC link/protocol deactivated */
294 #define NFA_DEACTIVATED_EVT 6
295 #define NFA_TLV_DETECT_EVT 7 /* TLV Detection complete */
296 /* NDEF Detection complete */
297 #define NFA_NDEF_DETECT_EVT 8
298 #define NFA_DATA_EVT 9            /* Data message received */
299 #define NFA_SELECT_CPLT_EVT 10    /* Select completed */
300 #define NFA_READ_CPLT_EVT 11      /* Read completed */
301 #define NFA_WRITE_CPLT_EVT 12     /* Write completed */
302 #define NFA_LLCP_ACTIVATED_EVT 13 /* LLCP link is activated */
303 /* LLCP link is deactivated */
304 #define NFA_LLCP_DEACTIVATED_EVT 14
305 /* Response to NFA_RwPresenceCheck */
306 #define NFA_PRESENCE_CHECK_EVT 15
307 /* Tag Formating completed */
308 #define NFA_FORMAT_CPLT_EVT 16
309 /* ISO 15693 command completed */
310 #define NFA_I93_CMD_CPLT_EVT 17
311 #define NFA_SET_TAG_RO_EVT 18 /* Tag set as Read only */
312 /* Result for NFA_RequestExclusiveRfControl */
313 #define NFA_EXCLUSIVE_RF_CONTROL_STARTED_EVT 19
314 /* Result for NFA_ReleaseExclusiveRfControl */
315 #define NFA_EXCLUSIVE_RF_CONTROL_STOPPED_EVT 20
316 /* DH Card emulation: AID or System code reg'd  */
317 #define NFA_CE_REGISTERED_EVT 21
318 /* DH Card emulation: AID or System code dereg'd */
319 #define NFA_CE_DEREGISTERED_EVT 22
320 /* DH Card emulation: data received event */
321 #define NFA_CE_DATA_EVT 23
322 /* DH Card emulation: activation event */
323 #define NFA_CE_ACTIVATED_EVT 24
324 /* DH Card emulation: deactivation event */
325 #define NFA_CE_DEACTIVATED_EVT 25
326 /* DH Card emulation: local NDEF configured */
327 #define NFA_CE_LOCAL_TAG_CONFIGURED_EVT 26
328 /* DH Card emulation: NDEF write started */
329 #define NFA_CE_NDEF_WRITE_START_EVT 27
330 /* DH Card emulation: NDEF write completed */
331 #define NFA_CE_NDEF_WRITE_CPLT_EVT 28
332 #define NFA_CE_UICC_LISTEN_CONFIGURED_EVT 29 /* UICC Listen configured */
333 /* RF Discovery started event */
334 #define NFA_RF_DISCOVERY_STARTED_EVT 30
335 /* RF Discovery stopped event */
336 #define NFA_RF_DISCOVERY_STOPPED_EVT 31
337 /* status of updating RF communication paramters */
338 #define NFA_UPDATE_RF_PARAM_RESULT_EVT 32
339 /* RF Interface error event */
340 #define NFA_RW_INTF_ERROR_EVT 34
341 /* status of setting P2P listen technologies */
342 #define NFA_SET_P2P_LISTEN_TECH_EVT 33
343 /* First packet received over LLCP link */
344 #define NFA_LLCP_FIRST_PACKET_RECEIVED_EVT 35
345 /* Listening enabled event */
346 #define NFA_LISTEN_ENABLED_EVT 36
347 /* Listening disabled event */
348 #define NFA_LISTEN_DISABLED_EVT 37
349 /* P2P services paused event */
350 #define NFA_P2P_PAUSED_EVT 38
351 /* P2P services resumed event */
352 #define NFA_P2P_RESUMED_EVT 39
353 
354 /* NFC deactivation type */
355 #define NFA_DEACTIVATE_TYPE_IDLE NFC_DEACTIVATE_TYPE_IDLE
356 #define NFA_DEACTIVATE_TYPE_SLEEP NFC_DEACTIVATE_TYPE_SLEEP
357 #define NFA_DEACTIVATE_TYPE_DISCOVERY NFC_DEACTIVATE_TYPE_DISCOVERY
358 
359 typedef uint8_t tNFA_DEACTIVATE_TYPE;
360 
361 /* Data for NFA_DISC_RESULT_EVT */
362 typedef struct {
363   tNFA_STATUS status;             /* NFA_STATUS_OK if successful       */
364   tNFC_RESULT_DEVT discovery_ntf; /* RF discovery notification details */
365 } tNFA_DISC_RESULT;
366 
367 /* Data for NFA_ACTIVATED_EVT */
368 typedef struct {
369   uint8_t hr[NFA_T1T_HR_LEN];       /* HR of Type 1 tag         */
370   uint8_t uid[NFA_T1T_CMD_UID_LEN]; /* UID used in T1T Commands */
371 } tNFA_T1T_PARAMS;
372 
373 typedef struct {
374   uint8_t uid[NFA_MAX_UID_LEN]; /* UID of T2T tag           */
375 } tNFA_T2T_PARAMS;
376 
377 typedef struct {
378   uint8_t num_system_codes; /* Number of system codes supporte by tag   */
379   uint16_t* p_system_codes; /* Pointer to list of system codes          */
380 } tNFA_T3T_PARAMS;
381 
382 typedef struct {
383   uint8_t uid[I93_UID_BYTE_LEN]; /* UID[0]:MSB, ... UID[7]:LSB */
384   uint8_t info_flags;   /* information flags                            */
385   uint8_t dsfid;        /* DSFID if I93_INFO_FLAG_DSFID                 */
386   uint8_t afi;          /* AFI if I93_INFO_FLAG_AFI                     */
387   uint16_t num_block;   /* number of blocks if I93_INFO_FLAG_MEM_SIZE   */
388   uint8_t block_size;   /* block size in byte if I93_INFO_FLAG_MEM_SIZE */
389   uint8_t IC_reference; /* IC Reference if I93_INFO_FLAG_IC_REF         */
390 } tNFA_I93_PARAMS;
391 
392 typedef union {
393   tNFA_T1T_PARAMS t1t; /* HR and UID of T1T                */
394   tNFA_T2T_PARAMS t2t; /* UID of T2T                       */
395   tNFA_T3T_PARAMS t3t; /* System codes                     */
396   tNFA_I93_PARAMS i93; /* System Information of ISO 15693  */
397 } tNFA_TAG_PARAMS;
398 
399 typedef struct {
400   tNFC_ACTIVATE_DEVT activate_ntf; /* RF discovery activation details */
401   tNFA_TAG_PARAMS params;          /* additional informaiton of tag   */
402 } tNFA_ACTIVATED;
403 
404 /* Data for NFA_DEACTIVATED_EVT */
405 typedef struct {
406   /* NFA_DEACTIVATE_TYPE_IDLE or NFA_DEACTIVATE_TYPE_SLEEP */
407   tNFA_DEACTIVATE_TYPE type;
408 } tNFA_DEACTIVATED;
409 
410 /* Structure for NFA_NDEF_DETECT_EVT event data */
411 typedef struct {
412   tNFA_STATUS status;         /* Status of the ndef detecton */
413   tNFA_NFC_PROTOCOL protocol; /* protocol used to detect NDEF */
414   uint32_t max_size;          /* max number of bytes available for NDEF data */
415   uint32_t cur_size;          /* current size of stored NDEF data (in bytes) */
416   /* Flags to indicate NDEF capability, is formated, soft/hard lockable,
417    * formatable, otp and read only */
418   tNFA_RW_NDEF_FLAG flags;
419 } tNFA_NDEF_DETECT;
420 
421 /* Structure for NFA_TLV_DETECT_EVT event data */
422 typedef struct {
423   tNFA_STATUS status;         /* Status of the tlv detecton        */
424   tNFA_NFC_PROTOCOL protocol; /* protocol used to detect TLV       */
425   uint8_t num_tlvs;           /* number of tlvs present in the tag */
426   uint8_t num_bytes;          /* number of lock/reserved bytes     */
427 } tNFA_TLV_DETECT;
428 
429 /* Structure for NFA_DATA_EVT data */
430 typedef struct {
431   tNFA_STATUS status; /* Status of Data received          */
432   uint8_t* p_data;    /* Data buffer                      */
433   uint16_t len;       /* Length of data                   */
434 } tNFA_RX_DATA;
435 
436 /* Structure for NFA_CE_NDEF_WRITE_CPLT_EVT data */
437 typedef struct {
438   tNFA_STATUS status; /* Status of the ndef write op      */
439   uint32_t len;       /* Update length of NDEF data       */
440   uint8_t* p_data;    /* data buffer                      */
441 } tNFA_CE_NDEF_WRITE_CPLT;
442 
443 /* Data for NFA_LLCP_ACTIVATED_EVT */
444 typedef struct {
445   bool is_initiator;        /* TRUE if initiator                */
446   uint16_t remote_wks;      /* Well-Known service mask of peer  */
447   uint8_t remote_lsc;       /* Link Service Class of peer       */
448   uint16_t remote_link_miu; /* Link MIU of peer                 */
449   uint16_t local_link_miu;  /* Link MIU of local                */
450   uint8_t remote_version;   /* LLCP version of remote           */
451 } tNFA_LLCP_ACTIVATED;
452 
453 /* Data for NFA_LLCP_DEACTIVATED_EVT */
454 typedef struct {
455   uint8_t reason; /* reason of deactivation           */
456 } tNFA_LLCP_DEACTIVATED;
457 
458 /* Data for NFA_I93_CMD_CPLT_EVT */
459 typedef struct {
460   uint8_t dsfid;                 /* DSFID                       */
461   uint8_t uid[I93_UID_BYTE_LEN]; /* UID[0]:MSB, ... UID[7]:LSB  */
462 } tNFA_I93_INVENTORY;
463 
464 typedef struct /* RW_I93_SYS_INFO_EVT                          */
465 {
466   uint8_t info_flags; /* information flags                            */
467   uint8_t uid[I93_UID_BYTE_LEN]; /* UID */
468   uint8_t dsfid;        /* DSFID if I93_INFO_FLAG_DSFID                 */
469   uint8_t afi;          /* AFI if I93_INFO_FLAG_AFI                     */
470   uint16_t num_block;   /* number of blocks if I93_INFO_FLAG_MEM_SIZE   */
471   uint8_t block_size;   /* block size in byte if I93_INFO_FLAG_MEM_SIZE */
472   uint8_t IC_reference; /* IC Reference if I93_INFO_FLAG_IC_REF         */
473 } tNFA_I93_SYS_INFO;
474 
475 typedef struct {
476   tNFA_STATUS status;   /* Status of sending command       */
477   uint8_t sent_command; /* sent command to tag             */
478   union {
479     uint8_t error_code;           /* error code defined in ISO 15693 */
480     tNFA_I93_INVENTORY inventory; /* inventory response              */
481     tNFA_I93_SYS_INFO sys_info;   /* system information              */
482   } params;
483 } tNFA_I93_CMD_CPLT;
484 
485 /* Data for NFA_CE_REGISTERED_EVT */
486 typedef struct {
487   tNFA_STATUS status; /* NFA_STATUS_OK if successful                      */
488   tNFA_HANDLE handle; /* handle for NFA_CeRegisterFelicaSystemCodeOnDH () */
489                       /*            NFA_CeRegisterT4tAidOnDH ()           */
490 } tNFA_CE_REGISTERED;
491 
492 /* Data for NFA_CE_DEREGISTERED_EVT */
493 typedef struct {
494   tNFA_HANDLE handle; /* handle from NFA_CE_REGISTERED_EVT   */
495 } tNFA_CE_DEREGISTERED;
496 
497 /* Data for NFA_CE_ACTIVATED_EVT */
498 typedef struct {
499   tNFA_STATUS status; /* NFA_STATUS_OK if successful              */
500   tNFA_HANDLE handle; /* handle from NFA_CE_REGISTERED_EVT        */
501   tNFC_ACTIVATE_DEVT activate_ntf; /* RF discovery activation details */
502 } tNFA_CE_ACTIVATED;
503 
504 /* Data for NFA_CE_DEACTIVATED_EVT */
505 typedef struct {
506   tNFA_HANDLE handle; /* handle from NFA_CE_REGISTERED_EVT   */
507   /* NFA_DEACTIVATE_TYPE_IDLE or NFA_DEACTIVATE_TYPE_SLEEP */
508   tNFA_DEACTIVATE_TYPE type;
509 } tNFA_CE_DEACTIVATED;
510 
511 /* Structure for NFA_CE_DATA_EVT data */
512 typedef struct {
513   tNFA_STATUS status; /* NFA_STATUS_OK if complete packet     */
514   tNFA_HANDLE handle; /* handle from NFA_CE_REGISTERED_EVT    */
515   uint8_t* p_data;    /* Data buffer                          */
516   uint16_t len;       /* Length of data                       */
517 } tNFA_CE_DATA;
518 
519 /* Union of all connection callback structures */
520 typedef union {
521   tNFA_STATUS status;           /* NFA_POLL_ENABLED_EVT                 */
522                                 /* NFA_POLL_DISABLED_EVT                */
523                                 /* NFA_CE_UICC_LISTEN_CONFIGURED_EVT    */
524                                 /* NFA_EXCLUSIVE_RF_CONTROL_STARTED_EVT */
525                                 /* NFA_EXCLUSIVE_RF_CONTROL_STOPPED_EVT */
526                                 /* NFA_SELECT_RESULT_EVT                */
527                                 /* NFA_DEACTIVATE_FAIL_EVT              */
528                                 /* NFA_CE_NDEF_WRITE_START_EVT          */
529                                 /* NFA_SELECT_CPLT_EVT                  */
530                                 /* NFA_READ_CPLT_EVT                    */
531                                 /* NFA_WRITE_CPLT_EVT                   */
532                                 /* NFA_PRESENCE_CHECK_EVT               */
533                                 /* NFA_FORMAT_CPLT_EVT                  */
534                                 /* NFA_SET_TAG_RO_EVT                   */
535                                 /* NFA_UPDATE_RF_PARAM_RESULT_EVT       */
536                                 /* NFA_RW_INTF_ERROR_EVT                */
537   tNFA_DISC_RESULT disc_result; /* NFA_DISC_RESULT_EVT                  */
538   tNFA_ACTIVATED activated;     /* NFA_ACTIVATED_EVT                    */
539   tNFA_DEACTIVATED deactivated; /* NFA_DEACTIVATED_EVT                  */
540   tNFA_NDEF_DETECT ndef_detect; /* NFA_NDEF_DETECT_EVT                  */
541   tNFA_TLV_DETECT tlv_detect;   /* NFA_TLV_DETECT_EVT                   */
542   tNFA_RX_DATA data;            /* NFA_DATA_EVT                         */
543   tNFA_CE_NDEF_WRITE_CPLT ndef_write_cplt; /* NFA_CE_NDEF_WRITE_CPLT_EVT */
544   tNFA_LLCP_ACTIVATED llcp_activated; /* NFA_LLCP_ACTIVATED_EVT               */
545   tNFA_LLCP_DEACTIVATED llcp_deactivated; /* NFA_LLCP_DEACTIVATED_EVT */
546   tNFA_I93_CMD_CPLT i93_cmd_cplt;   /* NFA_I93_CMD_CPLT_EVT                 */
547   tNFA_CE_REGISTERED ce_registered; /* NFA_CE_REGISTERED_EVT                */
548   tNFA_CE_DEREGISTERED ce_deregistered; /* NFA_CE_DEREGISTERED_EVT */
549   tNFA_CE_ACTIVATED ce_activated;     /* NFA_CE_ACTIVATED_EVT                 */
550   tNFA_CE_DEACTIVATED ce_deactivated; /* NFA_CE_DEACTIVATED_EVT               */
551   tNFA_CE_DATA ce_data;               /* NFA_CE_DATA_EVT                      */
552 
553 } tNFA_CONN_EVT_DATA;
554 
555 /* NFA Connection Callback */
556 typedef void(tNFA_CONN_CBACK)(uint8_t event, tNFA_CONN_EVT_DATA* p_data);
557 
558 #ifndef NFA_DM_NUM_INTERFACE_MAP
559 #define NFA_DM_NUM_INTERFACE_MAP 3
560 #endif
561 
562 /* compile-time configuration structure for the RF Discovery Frequency for each
563  * technology */
564 typedef struct {
565   uint8_t pa;   /* Frequency for NFC Technology A               */
566   uint8_t pb;   /* Frequency for NFC Technology B               */
567   uint8_t pf;   /* Frequency for NFC Technology F               */
568   uint8_t pi93; /* Frequency for Proprietary Technology/15693   */
569   uint8_t pbp;  /* Frequency for Proprietary Technology/B-Prime */
570   uint8_t pk;   /* Frequency for Proprietary Technology/Kovio   */
571   uint8_t paa;  /* Frequency for NFC Technology A active mode   */
572   uint8_t pfa;  /* Frequency for NFC Technology F active mode   */
573 } tNFA_DM_DISC_FREQ_CFG;
574 
575 /* definitions for tNFA_DM_CFG.presence_check_option */
576 /* if NDEF is not supported by the tag, use sleep/wake(last interface) */
577 #define NFA_DM_PCO_ISO_SLEEP_WAKE 0x01
578 /* NFA_SendRawFrame() has been used, use empty I block for presence check
579  * if this bit is not set, use read-binary on channel 3 for presence check */
580 #define NFA_DM_PCO_EMPTY_I_BLOCK 0x02
581 
582 /* compile-time configuration structure */
583 typedef struct {
584   /* Automatic NDEF detection (when not in exclusive RF mode) */
585   bool auto_detect_ndef;
586   /* Automatic NDEF read (when not in exclusive RF mode)      */
587   bool auto_read_ndef;
588   /* Automatic presence check                                 */
589   bool auto_presence_check;
590   /* Use sleep/wake(last interface) for ISODEP presence check */
591   uint8_t presence_check_option;
592   /* Maximum time to wait for presence check response         */
593   uint16_t presence_check_timeout;
594 } tNFA_DM_CFG;
595 
596 /* compile-time configuration structure for HCI */
597 typedef struct {
598   /* Maximum idle(no HCP Pkt) time to wait for EE DISC REQ Ntf(s) */
599   uint16_t hci_netwk_enable_timeout;
600   /* Maximum time to wait for EE DISC REQ NTF(s) after HOT PLUG EVT(s) */
601   uint16_t hcp_response_timeout;
602   /* Number of host in the whitelist of Terminal host */
603   uint8_t num_whitelist_host;
604   /* Whitelist of Terminal Host */
605   uint8_t* p_whitelist;
606 } tNFA_HCI_CFG;
607 
608 /*
609 ** Exclusive RF mode listen configuration
610 */
611 
612 #define NFA_LB_MAX_NFCID0_LEN 4
613 #define NFA_LF_MAX_SC_NFCID2 1
614 #define NFA_LA_MAX_HIST_BYTES 15
615 #define NFA_LB_MAX_H_INFO_LEN 15
616 
617 typedef struct {
618   /*
619   ** Discovery Configuration Parameters for Listen A
620   */
621   bool la_enable;             /* TRUE if listening A                      */
622   uint8_t la_bit_frame_sdd;   /* Bit Frame SDD in Byte 1 of SENS_RES      */
623   uint8_t la_platform_config; /* Platform Config in Byte 2 of SENS_RES    */
624   uint8_t la_sel_info;        /* Byte of SEL_RES                          */
625   uint8_t la_nfcid1_len;      /* NFCID1 (0, 4, 7 or 10 bytes)             */
626   uint8_t la_nfcid1[NCI_NFCID1_MAX_LEN]; /*        if empty, NFCC will decide */
627 
628   /*
629   ** Discovery Configuration Parameters for Listen B
630   */
631   bool lb_enable;        /* TRUE if listening B                      */
632   uint8_t lb_sensb_info; /* Byte 2 of Protocol Info within SENSB_RES */
633   uint8_t lb_nfcid0_len; /* NFCID0 (0, 1 or 4 bytes)                 */
634   uint8_t
635       lb_nfcid0[NFA_LB_MAX_NFCID0_LEN]; /*         if empty, NFCC will decide */
636   uint8_t lb_app_data[NCI_PARAM_LEN_LB_APPDATA]; /* Bytes 6 - 9 in SENSB_RES */
637   uint8_t lb_sfgi;   /* Start-Up Frame Guard Time                */
638   uint8_t lb_adc_fo; /* Byte 12 in SENSB_RES                     */
639 
640   /*
641   ** Discovery Configuration Parameters for Listen F
642   */
643   bool lf_enable;           /* TRUE if listening F          */
644   uint8_t lf_con_bitr_f;    /* bit rate to listen           */
645   uint8_t lf_protocol_type; /* Supported Protocols          */
646   /* bit field indicating which lf_t3t_identifier are enabled */
647   uint16_t lf_t3t_flags;
648   uint8_t lf_t3t_identifier[NFA_LF_MAX_SC_NFCID2]
649                            [NCI_SYSTEMCODE_LEN + NCI_NFCID2_LEN];
650   /* System Code and NFCID2       */
651   uint8_t lf_t3t_pmm[NCI_T3T_PMM_LEN]; /* Bytes 10 - 17 in SENSF_RES   */
652 
653   /*
654   ** Discovery Configuration Parameters for Listen ISO-DEP
655   */
656   bool li_enable;            /* TRUE if listening ISO-DEP            */
657   uint8_t li_fwi;            /* Frame Waiting Time Integer           */
658   uint8_t la_hist_bytes_len; /* historical bytes for Listen-A        */
659   uint8_t la_hist_bytes[NFA_LA_MAX_HIST_BYTES];
660   uint8_t lb_h_info_resp_len; /* higher layer response for Listen-B   */
661   uint8_t lb_h_info_resp[NFA_LB_MAX_H_INFO_LEN];
662 
663   /*
664   ** Discovery Configuration Parameters for Listen NFC-DEP
665   */
666   bool ln_enable;                   /* TRUE if listening NFC-DEP            */
667   uint8_t ln_wt;                    /* Waiting Time Integer                 */
668   uint8_t ln_atr_res_gen_bytes_len; /* General bytes in ATR_RES             */
669   uint8_t ln_atr_res_gen_bytes[NCI_MAX_GEN_BYTES_LEN];
670   uint8_t ln_atr_res_config; /* Optional parameters (PPt) in ATR_RES */
671 } tNFA_LISTEN_CFG;
672 
673 /* Data for NFA_UpdateRFCommParams () */
674 typedef tNFC_RF_COMM_PARAMS tNFA_RF_COMM_PARAMS;
675 
676 /* RF Interface type */
677 #define NFA_INTERFACE_FRAME NFC_INTERFACE_FRAME
678 #define NFA_INTERFACE_ISO_DEP NFC_INTERFACE_ISO_DEP
679 #define NFA_INTERFACE_NFC_DEP NFC_INTERFACE_NFC_DEP
680 #define NFA_INTERFACE_MIFARE NFC_INTERFACE_MIFARE
681 typedef tNFC_INTF_TYPE tNFA_INTF_TYPE;
682 
683 /*******************************************************************************
684 ** NDEF Definitions
685 *******************************************************************************/
686 
687 /* Definitions for tNFA_TNF (NDEF type name format ID) */
688 /* Empty or no type specified                       */
689 #define NFA_TNF_EMPTY NDEF_TNF_EMPTY
690 /* NFC Forum well-known type [NFC RTD]              */
691 #define NFA_TNF_WKT NDEF_TNF_WKT
692 /* Media-type as defined in RFC 2046 [RFC 2046]     */
693 #define NFA_TNF_RFC2046_MEDIA NDEF_TNF_MEDIA
694 /* Absolute URI as defined in RFC 3986 [RFC 3986]   */
695 #define NFA_TNF_RFC3986_URI NDEF_TNF_URI
696 /* NFC Forum external type [NFC RTD]                */
697 #define NFA_TNF_EXTERNAL NDEF_TNF_EXT
698 /* Unknown                                          */
699 #define NFA_TNF_UNKNOWN NDEF_TNF_UNKNOWN
700 /* Unchanged                                        */
701 #define NFA_TNF_UNCHANGED NDEF_TNF_UNCHANGED
702 /* Reserved                                         */
703 #define NFA_TNF_RESERVED NDEF_TNF_RESERVED
704 /* Used to register default NDEF type handler       */
705 #define NFA_TNF_DEFAULT 0xFF
706 typedef uint8_t tNFA_TNF;
707 
708 /* Definitions for tNFA_NDEF_URI_ID (Frequently used prefixes. For additional
709  * values, see [NFC RTD URI] */
710 #define NFA_NDEF_URI_ID_ABSOLUTE 0x00 /* Unabridged URI.  */
711 #define NFA_NDEF_URI_ID_HTTP 0x03     /* http://          */
712 #define NFA_NDEF_URI_ID_HTTPS 0x04    /* https://         */
713 #define NFA_NDEF_URI_ID_TEL 0x05      /* tel:             */
714 #define NFA_NDEF_URI_ID_MAILTO 0x06   /* mailto:          */
715 #define NFA_NDEF_URI_ID_FTP 0x0D      /* ftp://           */
716 #define NFA_NDEF_URI_ID_FILE 0x1D     /* file://          */
717 
718 typedef uint8_t tNFA_NDEF_URI_ID;
719 
720 /* Events for tNFA_NDEF_CBACK */
721 /* NDEF record type registered. (In response to NFA_RegisterNDefTypeHandler) */
722 #define NFA_NDEF_REGISTER_EVT 0
723 /* Received an NDEF message with the registered type. See [tNFA_NDEF_DATA] */
724 #define NFA_NDEF_DATA_EVT 1
725 typedef uint8_t tNFA_NDEF_EVT;
726 
727 /* Structure for NFA_NDEF_REGISTER_EVT event data */
728 typedef struct {
729   tNFA_STATUS status;           /* Status of the registration               */
730   tNFA_HANDLE ndef_type_handle; /* Handle for this NDEF type registration.  */
731 } tNFA_NDEF_REGISTER;
732 
733 /* Structure for NFA_NDEF_DATA_EVT event data */
734 typedef struct {
735   tNFA_HANDLE ndef_type_handle; /* Handle for NDEF type registration.   */
736   uint8_t* p_data;              /* Data buffer                          */
737   uint32_t len;                 /* Length of data                       */
738 } tNFA_NDEF_DATA;
739 
740 /* Union of all NDEF callback structures */
741 typedef union {
742   /* Structure for NFA_NDEF_REGISTER_EVT event data */
743   tNFA_NDEF_REGISTER ndef_reg;
744   /* Structure for NFA_NDEF_DATA_EVT event data */
745   tNFA_NDEF_DATA ndef_data;
746 } tNFA_NDEF_EVT_DATA;
747 
748 /* NFA_NDEF callback */
749 typedef void(tNFA_NDEF_CBACK)(tNFA_NDEF_EVT event, tNFA_NDEF_EVT_DATA* p_data);
750 
751 /* NFA VSC Callback */
752 typedef void(tNFA_VSC_CBACK)(uint8_t event, uint16_t param_len,
753                              uint8_t* p_param);
754 
755 /*****************************************************************************
756 **  External Function Declarations
757 *****************************************************************************/
758 #ifdef __cplusplus
759 extern "C" {
760 #endif
761 
762 /*******************************************************************************
763 **
764 ** Function         NFA_Init
765 **
766 ** Description      This function initializes control blocks for NFA
767 **
768 **                  p_hal_entry_tbl points to a table of HAL entry points
769 **
770 **                  NOTE: the buffer that p_hal_entry_tbl points must be
771 **                  persistent until NFA is disabled.
772 **
773 **
774 ** Returns          none
775 **
776 *******************************************************************************/
777 extern void NFA_Init(tHAL_NFC_ENTRY* p_hal_entry_tbl);
778 
779 /*******************************************************************************
780 **
781 ** Function         NFA_Enable
782 **
783 ** Description      This function enables NFC. Prior to calling NFA_Enable,
784 **                  the NFCC must be powered up, and ready to receive commands.
785 **                  This function enables the tasks needed by NFC, opens the NCI
786 **                  transport, resets the NFC controller, downloads patches to
787 **                  the NFCC (if necessary), and initializes the NFC subsystems.
788 **
789 **                  This function should only be called once - typically when
790 **                  NFC is enabled during boot-up, or when NFC is enabled from a
791 **                  settings UI. Subsequent calls to NFA_Enable while NFA is
792 **                  enabling or enabled will be ignored. When the NFC startup
793 **                  procedure is completed, an NFA_DM_ENABLE_EVT is returned to
794 **                  the application using the tNFA_DM_CBACK.
795 **
796 **                  The tNFA_CONN_CBACK parameter is used to register a callback
797 **                  for polling, p2p and card emulation events.
798 **
799 **
800 ** Returns          NFA_STATUS_OK if successfully initiated
801 **                  NFA_STATUS_FAILED otherwise
802 **
803 *******************************************************************************/
804 extern tNFA_STATUS NFA_Enable(tNFA_DM_CBACK* p_dm_cback,
805                               tNFA_CONN_CBACK* p_conn_cback);
806 
807 /*******************************************************************************
808 **
809 ** Function         NFA_Disable
810 **
811 ** Description      This function is called to shutdown NFC. The tasks for NFC
812 **                  are terminated, and clean up routines are performed. This
813 **                  function is typically called during platform shut-down, or
814 **                  when NFC is disabled from a settings UI. When the NFC
815 **                  shutdown procedure is completed, an NFA_DM_DISABLE_EVT is
816 **                  returned to the application using the tNFA_DM_CBACK.
817 **
818 **                  The platform should wait until the NFC_DISABLE_REVT is
819 **                  received before powering down the NFC chip and NCI
820 **                  transport. This is required to so that NFA can gracefully
821 **                  shut down any open connections.
822 **
823 ** Returns          NFA_STATUS_OK if successfully initiated
824 **                  NFA_STATUS_FAILED otherwise
825 **
826 *******************************************************************************/
827 extern tNFA_STATUS NFA_Disable(bool graceful);
828 
829 /*******************************************************************************
830 **
831 ** Function         NFA_SetConfig
832 **
833 ** Description      Set the configuration parameters to NFCC. The result is
834 **                  reported with an NFA_DM_SET_CONFIG_EVT in the tNFA_DM_CBACK
835 **                  callback.
836 **
837 ** Note:            If RF discovery is started,
838 **                  NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should
839 **                  happen before calling this function. Most Configuration
840 **                  parameters are related to RF discovery.
841 **
842 ** Returns          NFA_STATUS_OK if successfully initiated
843 **                  NFA_STATUS_BUSY if previous setting is on-going
844 **                  NFA_STATUS_FAILED otherwise
845 **
846 *******************************************************************************/
847 extern tNFA_STATUS NFA_SetConfig(tNFA_PMID param_id, uint8_t length,
848                                  uint8_t* p_data);
849 
850 /*******************************************************************************
851 **
852 ** Function         NFA_GetConfig
853 **
854 ** Description      Get the configuration parameters from NFCC. The result is
855 **                  reported with an NFA_DM_GET_CONFIG_EVT in the tNFA_DM_CBACK
856 **                  callback.
857 **
858 ** Returns          NFA_STATUS_OK if successfully initiated
859 **                  NFA_STATUS_FAILED otherwise
860 **
861 *******************************************************************************/
862 extern tNFA_STATUS NFA_GetConfig(uint8_t num_ids, tNFA_PMID* p_param_ids);
863 
864 /*******************************************************************************
865 **
866 ** Function         NFA_RequestExclusiveRfControl
867 **
868 ** Description      Request exclusive control of NFC.
869 **                  - Previous behavior (polling/tag reading, DH card emulation)
870 **                    will be suspended .
871 **                  - Polling and listening will be done based on the specified
872 **                    params
873 **
874 **                  The NFA_EXCLUSIVE_RF_CONTROL_STARTED_EVT event of
875 **                  tNFA_CONN_CBACK indicates the status of the operation.
876 **
877 **                  NFA_ACTIVATED_EVT and NFA_DEACTIVATED_EVT indicates link
878 **                  activation/deactivation.
879 **
880 **                  NFA_SendRawFrame is used to send data to the peer.
881 **                  NFA_DATA_EVT indicates data from the peer.
882 **
883 **                  If a tag is activated, then the NFA_RW APIs may be used to
884 **                  send commands to the tag. Incoming NDEF messages are sent to
885 **                  the NDEF callback.
886 **
887 **                  Once exclusive RF control has started, NFA will not activate
888 **                  LLCP internally. The application has exclusive control of
889 **                  the link.
890 **
891 ** Note:            If RF discovery is started,
892 **                  NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should
893 **                  happen before calling this function
894 **
895 ** Returns          NFA_STATUS_OK if successfully initiated
896 **                  NFA_STATUS_FAILED otherwise
897 **
898 *******************************************************************************/
899 extern tNFA_STATUS NFA_RequestExclusiveRfControl(tNFA_TECHNOLOGY_MASK poll_mask,
900                                                  tNFA_LISTEN_CFG* p_listen_cfg,
901                                                  tNFA_CONN_CBACK* p_conn_cback,
902                                                  tNFA_NDEF_CBACK* p_ndef_cback);
903 
904 /*******************************************************************************
905 **
906 ** Function         NFA_ReleaseExclusiveRfControl
907 **
908 ** Description      Release exclusive control of NFC. Once released, behavior
909 **                  prior to obtaining exclusive RF control will resume.
910 **
911 Note??
912 ** Returns          NFA_STATUS_OK if successfully initiated
913 **                  NFA_STATUS_FAILED otherwise
914 **
915 *******************************************************************************/
916 extern tNFA_STATUS NFA_ReleaseExclusiveRfControl(void);
917 
918 /*******************************************************************************
919 **
920 ** Function         NFA_EnablePolling
921 **
922 ** Description      Enable polling for technologies specified by poll_mask.
923 **
924 **                  The following events (notified using the connection
925 **                  callback registered with NFA_Enable) are generated during
926 **                  polling:
927 **
928 **                  - NFA_POLL_ENABLED_EVT indicates whether or not polling
929 **                    successfully enabled.
930 **                  - NFA_DISC_RESULT_EVT indicates there are more than one
931 **                    devices, so application must select one of tags by calling
932 **                    NFA_Select().
933 **                  - NFA_SELECT_RESULT_EVT indicates whether previous selection
934 **                    was successful or not. If it was failed then application
935 **                    must select again or deactivate by calling
936 **                    NFA_Deactivate().
937 **                  - NFA_ACTIVATED_EVT is generated when an NFC link is
938 **                    activated.
939 **                  - NFA_NDEF_DETECT_EVT is generated if tag is activated
940 **                  - NFA_LLCP_ACTIVATED_EVT/NFA_LLCP_DEACTIVATED_EVT is
941 **                    generated if NFC-DEP is activated
942 **                  - NFA_DEACTIVATED_EVT will be returned after deactivating
943 **                    NFC link.
944 **
945 ** Note:            If RF discovery is started,
946 **                  NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should
947 **                  happen before calling this function
948 **
949 ** Returns          NFA_STATUS_OK if successfully initiated
950 **                  NFA_STATUS_FAILED otherwise
951 **
952 *******************************************************************************/
953 extern tNFA_STATUS NFA_EnablePolling(tNFA_TECHNOLOGY_MASK poll_mask);
954 
955 /*******************************************************************************
956 **
957 ** Function         NFA_DisablePolling
958 **
959 ** Description      Disable polling
960 **                  NFA_POLL_DISABLED_EVT will be returned after stopping
961 **                  polling.
962 **
963 ** Note:            If RF discovery is started,
964 **                  NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should
965 **                  happen before calling this function
966 **
967 ** Returns          NFA_STATUS_OK if successfully initiated
968 **                  NFA_STATUS_FAILED otherwise
969 **
970 *******************************************************************************/
971 extern tNFA_STATUS NFA_DisablePolling(void);
972 
973 /*******************************************************************************
974 **
975 ** Function         NFA_EnableListening
976 **
977 ** Description      Enable listening.
978 **                  NFA_LISTEN_ENABLED_EVT will be returned after listening is
979 **                  allowed.
980 **
981 **                  The actual listening technologies are specified by other NFA
982 **                  API functions. Such functions include (but not limited to)
983 **                  NFA_CeConfigureUiccListenTech.
984 **                  If NFA_DisableListening () is called to ignore the listening
985 **                  technologies, NFA_EnableListening () is called to restore
986 **                  the listening technologies set by these functions.
987 **
988 ** Note:            If RF discovery is started,
989 **                  NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should
990 **                  happen before calling this function
991 **
992 ** Returns          NFA_STATUS_OK if successfully initiated
993 **                  NFA_STATUS_FAILED otherwise
994 **
995 *******************************************************************************/
996 extern tNFA_STATUS NFA_EnableListening(void);
997 
998 /*******************************************************************************
999 **
1000 ** Function         NFA_DisableListening
1001 **
1002 ** Description      Disable listening
1003 **                  NFA_LISTEN_DISABLED_EVT will be returned after stopping
1004 **                  listening. This function is called to exclude listen at RF
1005 **                  discovery.
1006 **
1007 ** Note:            If RF discovery is started,
1008 **                  NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should
1009 **                  happen before calling this function
1010 **
1011 ** Returns          NFA_STATUS_OK if successfully initiated
1012 **                  NFA_STATUS_FAILED otherwise
1013 **
1014 *******************************************************************************/
1015 extern tNFA_STATUS NFA_DisableListening(void);
1016 
1017 /*******************************************************************************
1018 **
1019 ** Function         NFA_PauseP2p
1020 **
1021 ** Description      Pause P2P services.
1022 **                  NFA_P2P_PAUSED_EVT will be returned after P2P services are
1023 **                  disabled.
1024 **
1025 **                  The P2P services enabled by NFA_P2p* API functions are not
1026 **                  available. NFA_ResumeP2p() is called to resume the P2P
1027 **                  services.
1028 **
1029 ** Note:            If RF discovery is started,
1030 **                  NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should
1031 **                  happen before calling this function
1032 **
1033 ** Returns          NFA_STATUS_OK if successfully initiated
1034 **                  NFA_STATUS_FAILED otherwise
1035 **
1036 *******************************************************************************/
1037 extern tNFA_STATUS NFA_PauseP2p(void);
1038 
1039 /*******************************************************************************
1040 **
1041 ** Function         NFA_ResumeP2p
1042 **
1043 ** Description      Resume P2P services.
1044 **                  NFA_P2P_RESUMED_EVT will be returned after P2P services are.
1045 **                  enables again.
1046 **
1047 ** Note:            If RF discovery is started,
1048 **                  NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should
1049 **                  happen before calling this function
1050 **
1051 ** Returns          NFA_STATUS_OK if successfully initiated
1052 **                  NFA_STATUS_FAILED otherwise
1053 **
1054 *******************************************************************************/
1055 extern tNFA_STATUS NFA_ResumeP2p(void);
1056 
1057 /*******************************************************************************
1058 **
1059 ** Function         NFA_SetP2pListenTech
1060 **
1061 ** Description      This function is called to set listen technology for
1062 **                  NFC-DEP. This funtion may be called before or after starting
1063 **                  any server on NFA P2P/CHO/SNEP.
1064 **                  If there is no technology for NFC-DEP, P2P listening will be
1065 **                  stopped.
1066 **
1067 **                  NFA_SET_P2P_LISTEN_TECH_EVT without data will be returned.
1068 **
1069 ** Note:            If RF discovery is started,
1070 **                  NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should
1071 **                  happen before calling this function
1072 **
1073 ** Returns          NFA_STATUS_OK if successfully initiated
1074 **                  NFA_STATUS_FAILED otherwise
1075 **
1076 *******************************************************************************/
1077 extern tNFA_STATUS NFA_SetP2pListenTech(tNFA_TECHNOLOGY_MASK tech_mask);
1078 
1079 /*******************************************************************************
1080 **
1081 ** Function         NFA_StartRfDiscovery
1082 **
1083 ** Description      Start RF discovery
1084 **                  RF discovery parameters shall be set by other APIs.
1085 **
1086 **                  An NFA_RF_DISCOVERY_STARTED_EVT indicates whether starting
1087 **                  was successful or not.
1088 **
1089 ** Returns          NFA_STATUS_OK if successfully initiated
1090 **                  NFA_STATUS_FAILED otherwise
1091 **
1092 *******************************************************************************/
1093 extern tNFA_STATUS NFA_StartRfDiscovery(void);
1094 
1095 /*******************************************************************************
1096 **
1097 ** Function         NFA_StopRfDiscovery
1098 **
1099 ** Description      Stop RF discovery
1100 **
1101 **                  An NFA_RF_DISCOVERY_STOPPED_EVT indicates whether stopping
1102 **                  was successful or not.
1103 **
1104 ** Returns          NFA_STATUS_OK if successfully initiated
1105 **                  NFA_STATUS_FAILED otherwise
1106 **
1107 *******************************************************************************/
1108 extern tNFA_STATUS NFA_StopRfDiscovery(void);
1109 
1110 /*******************************************************************************
1111 **
1112 ** Function         NFA_SetRfDiscoveryDuration
1113 **
1114 ** Description      Set the duration of the single discovery period in [ms].
1115 **                  Allowable range: 0 ms to 0xFFFF ms.
1116 **
1117 ** Note:            If discovery is already started, the application should
1118 **                  call NFA_StopRfDiscovery prior to calling
1119 **                  NFA_SetRfDiscoveryDuration, and then call
1120 **                  NFA_StartRfDiscovery afterwards to restart discovery using
1121 **                  the new duration.
1122 **
1123 ** Returns:
1124 **                  NFA_STATUS_OK, if command accepted
1125 **                  NFA_STATUS_FAILED: otherwise
1126 **
1127 *******************************************************************************/
1128 extern tNFA_STATUS NFA_SetRfDiscoveryDuration(uint16_t discovery_period_ms);
1129 
1130 /*******************************************************************************
1131 **
1132 ** Function         NFA_Select
1133 **
1134 ** Description      Select one from detected devices by NFA_DISC_RESULT_EVT
1135 **                  after the last discovery result is received.
1136 **                  An NFA_SELECT_RESULT_EVT indicates whether selection was
1137 **                  successful or not. If failed then application must select
1138 **                  again or deactivate by NFA_Deactivate ().
1139 **
1140 ** Returns          NFA_STATUS_OK if successfully initiated
1141 **                  NFA_STATUS_INVALID_PARAM if RF interface is not matched
1142 **                  protocol
1143 **                  NFA_STATUS_FAILED otherwise
1144 **
1145 *******************************************************************************/
1146 extern tNFA_STATUS NFA_Select(uint8_t rf_disc_id, tNFA_NFC_PROTOCOL protocol,
1147                               tNFA_INTF_TYPE rf_interface);
1148 
1149 /*******************************************************************************
1150 **
1151 ** Function         NFA_UpdateRFCommParams
1152 **
1153 ** Description      This function is called to update RF Communication
1154 **                  parameters once the Frame RF Interface has been activated.
1155 **
1156 **                  An NFA_UPDATE_RF_PARAM_RESULT_EVT indicates whether updating
1157 **                  was successful or not.
1158 **
1159 ** Returns          NFA_STATUS_OK if successfully initiated
1160 **                  NFA_STATUS_FAILED otherwise
1161 **
1162 *******************************************************************************/
1163 extern tNFA_STATUS NFA_UpdateRFCommParams(tNFA_RF_COMM_PARAMS* p_params);
1164 
1165 /*******************************************************************************
1166 **
1167 ** Function         NFA_Deactivate
1168 **
1169 ** Description
1170 **                  If sleep_mode=TRUE:
1171 **                      Deselect the activated device by deactivating into sleep
1172 **                      mode.
1173 **
1174 **                      An NFA_DEACTIVATE_FAIL_EVT indicates that selection was
1175 **                      not successful. Application can select another
1176 **                      discovered device or deactivate by NFA_Deactivate ()
1177 **                      after receiving NFA_DEACTIVATED_EVT.
1178 **
1179 **                      Deactivating to sleep mode is not allowed when NFCC is
1180 **                      in wait-for-host-select mode, or in listen-sleep states;
1181 **                      NFA will deactivate to idle or discovery state for these
1182 **                      cases respectively.
1183 **
1184 **
1185 **                  If sleep_mode=FALSE:
1186 **                      Deactivate the connection (e.g. as a result of presence
1187 **                      check failure) NFA_DEACTIVATED_EVT will indicate that
1188 **                      link is deactivated. Polling/listening will resume
1189 **                      (unless the nfcc is in wait_for-all-discoveries state)
1190 **
1191 **
1192 ** Returns          NFA_STATUS_OK if successfully initiated
1193 **                  NFA_STATUS_FAILED otherwise
1194 **
1195 *******************************************************************************/
1196 extern tNFA_STATUS NFA_Deactivate(bool sleep_mode);
1197 
1198 /*******************************************************************************
1199 **
1200 ** Function         NFA_SendRawFrame
1201 **
1202 ** Description      Send a raw frame over the activated interface with the NFCC.
1203 **                  This function can only be called after NFC link is
1204 **                  activated.
1205 **
1206 **                  If the activated interface is a tag and auto-presence check
1207 **                  is enabled then presence_check_start_delay can be used to
1208 **                  indicate the delay in msec after which the next auto
1209 **                  presence check command can be sent.
1210 **                  NFA_DM_DEFAULT_PRESENCE_CHECK_START_DELAY can be used as the
1211 **                  default value for the delay.
1212 **
1213 ** Returns          NFA_STATUS_OK if successfully initiated
1214 **                  NFA_STATUS_FAILED otherwise
1215 **
1216 *******************************************************************************/
1217 extern tNFA_STATUS NFA_SendRawFrame(uint8_t* p_raw_data, uint16_t data_len,
1218                                     uint16_t presence_check_start_delay);
1219 
1220 /*******************************************************************************
1221 ** NDEF APIs
1222 *******************************************************************************/
1223 
1224 /*******************************************************************************
1225 **
1226 ** Function         NFA_RegisterNDefTypeHandler
1227 **
1228 ** Description      This function allows the applications to register for
1229 **                  specific types of NDEF records. When NDEF records are
1230 **                  received, NFA will parse the record-type field, and pass
1231 **                  the record to the registered tNFA_NDEF_CBACK.
1232 **
1233 **                  For records types which were not registered, the record will
1234 **                  be sent to the default handler. A default type-handler may
1235 **                  be registered by calling this NFA_RegisterNDefTypeHandler
1236 **                  with tnf=NFA_TNF_DEFAULT. In this case, all un-registered
1237 **                  record types will be sent to the callback. Only one default
1238 **                  handler may be registered at a time.
1239 **
1240 **                  An NFA_NDEF_REGISTER_EVT will be sent to the tNFA_NDEF_CBACK
1241 **                  to indicate that registration was successful, and provide a
1242 **                  handle for this record type.
1243 **
1244 **
1245 ** Returns          NFA_STATUS_OK if successfully initiated
1246 **                  NFA_STATUS_FAILED otherwise
1247 **
1248 *******************************************************************************/
1249 extern tNFA_STATUS NFA_RegisterNDefTypeHandler(bool handle_whole_message,
1250                                                tNFA_TNF tnf,
1251                                                uint8_t* p_type_name,
1252                                                uint8_t type_name_len,
1253                                                tNFA_NDEF_CBACK* p_ndef_cback);
1254 
1255 /*******************************************************************************
1256 **
1257 ** Function         NFA_RegisterNDefUriHandler
1258 **
1259 ** Description      This API is a special-case of NFA_RegisterNDefTypeHandler
1260 **                  with TNF=NFA_TNF_WKT, and type_name='U' (URI record); and
1261 **                  allows registering for specific URI types (e.g. 'tel:' or
1262 **                  'mailto:').
1263 **
1264 **                  An NFA_NDEF_REGISTER_EVT will be sent to the tNFA_NDEF_CBACK
1265 **                  to indicate that registration was successful, and provide a
1266 **                  handle for this registration.
1267 **
1268 **                  If uri_id=NFA_NDEF_URI_ID_ABSOLUTE, then p_abs_uri contains
1269 **                  the unabridged URI. For all other uri_id values, the
1270 **                  p_abs_uri parameter is ignored (i.e the URI prefix is
1271 **                  implied by uri_id).
1272 **
1273 **                  See [NFC RTD URI] for more information.
1274 **
1275 ** Returns          NFA_STATUS_OK if successfully initiated
1276 **                  NFA_STATUS_FAILED otherwise
1277 **
1278 *******************************************************************************/
1279 extern tNFA_STATUS NFA_RegisterNDefUriHandler(bool handle_whole_message,
1280                                               tNFA_NDEF_URI_ID uri_id,
1281                                               uint8_t* p_abs_uri,
1282                                               uint8_t uri_id_len,
1283                                               tNFA_NDEF_CBACK* p_ndef_cback);
1284 
1285 /*******************************************************************************
1286 **
1287 ** Function         NFA_DeregisterNDefTypeHandler
1288 **
1289 ** Description      Deregister NDEF record type handler.
1290 **
1291 ** Returns          NFA_STATUS_OK if successfully initiated
1292 **                  NFA_STATUS_FAILED otherwise
1293 **
1294 *******************************************************************************/
1295 extern tNFA_STATUS NFA_DeregisterNDefTypeHandler(tNFA_HANDLE ndef_type_handle);
1296 
1297 /*******************************************************************************
1298 **
1299 ** Function         NFA_PowerOffSleepMode
1300 **
1301 ** Description      This function is called to enter or leave NFCC Power Off
1302 **                  Sleep mode
1303 **                  NFA_DM_PWR_MODE_CHANGE_EVT will be sent to indicate status.
1304 **
1305 **                  start_stop : TRUE if entering Power Off Sleep mode
1306 **                               FALSE if leaving Power Off Sleep mode
1307 **
1308 Note??
1309 ** Returns          NFA_STATUS_OK if successfully initiated
1310 **                  NFA_STATUS_FAILED otherwise
1311 **
1312 *******************************************************************************/
1313 extern tNFA_STATUS NFA_PowerOffSleepMode(bool start_stop);
1314 
1315 /*******************************************************************************
1316 **
1317 ** Function         NFA_RegVSCback
1318 **
1319 ** Description      This function is called to register or de-register a
1320 **                  callback function to receive Proprietary NCI response and
1321 **                  notification events.
1322 **                  The maximum number of callback functions allowed is
1323 **                  NFC_NUM_VS_CBACKS
1324 **
1325 ** Returns          tNFC_STATUS
1326 **
1327 *******************************************************************************/
1328 extern tNFC_STATUS NFA_RegVSCback(bool is_register, tNFA_VSC_CBACK* p_cback);
1329 
1330 /*******************************************************************************
1331 **
1332 ** Function         NFA_SendVsCommand
1333 **
1334 ** Description      This function is called to send an NCI Vendor Specific
1335 **                  command to NFCC.
1336 **
1337 **                  oid             - The opcode of the VS command.
1338 **                  cmd_params_len  - The command parameter len
1339 **                  p_cmd_params    - The command parameter
1340 **                  p_cback         - The callback function to receive the
1341 **                                    command status
1342 **
1343 ** Returns          NFA_STATUS_OK if successfully initiated
1344 **                  NFA_STATUS_FAILED otherwise
1345 **
1346 *******************************************************************************/
1347 extern tNFA_STATUS NFA_SendVsCommand(uint8_t oid, uint8_t cmd_params_len,
1348                                      uint8_t* p_cmd_params,
1349                                      tNFA_VSC_CBACK* p_cback);
1350 
1351 /*******************************************************************************
1352 **
1353 ** Function         NFA_SetTraceLevel
1354 **
1355 ** Description      This function sets the trace level for NFA.  If called with
1356 **                  a value of 0xFF, it simply returns the current trace level.
1357 **
1358 ** Returns          The new or current trace level
1359 **
1360 *******************************************************************************/
1361 extern uint8_t NFA_SetTraceLevel(uint8_t new_level);
1362 
1363 #ifdef __cplusplus
1364 }
1365 #endif
1366 
1367 #endif /* NFA_API_H */
1368