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