1 /******************************************************************************
2  *
3  *  Copyright (C) 2009-2014 Broadcom Corporation
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at:
8  *
9  *  http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  ******************************************************************************/
18 
19 /******************************************************************************
20  *
21  *  This file contains the Near Field Communication (NFC) API function
22  *  external definitions.
23  *
24  ******************************************************************************/
25 
26 #ifndef NFC_API_H
27 #define NFC_API_H
28 
29 #include "gki.h"
30 #include "nci_defs.h"
31 #include "nfc_hal_api.h"
32 #include "nfc_target.h"
33 
34 #include "vendor_cfg.h"
35 
36 /* NFC application return status codes */
37 /* Command succeeded    */
38 #define NFC_STATUS_OK NCI_STATUS_OK
39 /* Command is rejected. */
40 #define NFC_STATUS_REJECTED NCI_STATUS_REJECTED
41 /* Message is corrupted */
42 #define NFC_STATUS_MSG_CORRUPTED NCI_STATUS_MESSAGE_CORRUPTED
43 /* buffer full          */
44 #define NFC_STATUS_BUFFER_FULL NCI_STATUS_BUFFER_FULL
45 /* failed               */
46 #define NFC_STATUS_FAILED NCI_STATUS_FAILED
47 /* not initialized      */
48 #define NFC_STATUS_NOT_INITIALIZED NCI_STATUS_NOT_INITIALIZED
49 /* Syntax error         */
50 #define NFC_STATUS_SYNTAX_ERROR NCI_STATUS_SYNTAX_ERROR
51 /* Semantic error       */
52 #define NFC_STATUS_SEMANTIC_ERROR NCI_STATUS_SEMANTIC_ERROR
53 /* Unknown NCI Group ID */
54 #define NFC_STATUS_UNKNOWN_GID NCI_STATUS_UNKNOWN_GID
55 /* Unknown NCI Opcode   */
56 #define NFC_STATUS_UNKNOWN_OID NCI_STATUS_UNKNOWN_OID
57 /* Invalid Parameter    */
58 #define NFC_STATUS_INVALID_PARAM NCI_STATUS_INVALID_PARAM
59 /* Message size too big */
60 #define NFC_STATUS_MSG_SIZE_TOO_BIG NCI_STATUS_MSG_SIZE_TOO_BIG
61 /* Already started      */
62 #define NFC_STATUS_ALREADY_STARTED NCI_STATUS_ALREADY_STARTED
63 /* Activation Failed    */
64 #define NFC_STATUS_ACTIVATION_FAILED NCI_STATUS_ACTIVATION_FAILED
65 /* Tear Down Error      */
66 #define NFC_STATUS_TEAR_DOWN NCI_STATUS_TEAR_DOWN
67 /* RF transmission error*/
68 #define NFC_STATUS_RF_TRANSMISSION_ERR NCI_STATUS_RF_TRANSMISSION_ERR
69 /* RF protocol error    */
70 #define NFC_STATUS_RF_PROTOCOL_ERR NCI_STATUS_RF_PROTOCOL_ERR
71 /* RF Timeout           */
72 #define NFC_STATUS_TIMEOUT NCI_STATUS_TIMEOUT
73 /* EE Intf activate err */
74 #define NFC_STATUS_EE_INTF_ACTIVE_FAIL NCI_STATUS_EE_INTF_ACTIVE_FAIL
75 /* EE transmission error*/
76 #define NFC_STATUS_EE_TRANSMISSION_ERR NCI_STATUS_EE_TRANSMISSION_ERR
77 /* EE protocol error    */
78 #define NFC_STATUS_EE_PROTOCOL_ERR NCI_STATUS_EE_PROTOCOL_ERR
79 /* EE Timeout           */
80 #define NFC_STATUS_EE_TIMEOUT NCI_STATUS_EE_TIMEOUT
81 
82 /* 0xE0 ~0xFF are proprietary status codes */
83 /* Command started successfully                     */
84 #define NFC_STATUS_CMD_STARTED 0xE3
85 /* NFCC Timeout in responding to an NCI command     */
86 #define NFC_STATUS_HW_TIMEOUT 0xE4
87 /* More (same) event to follow                      */
88 #define NFC_STATUS_CONTINUE 0xE5
89 /* API is called to perform illegal function        */
90 #define NFC_STATUS_REFUSED 0xE6
91 /* Wrong format of R-APDU, CC file or NDEF file     */
92 #define NFC_STATUS_BAD_RESP 0xE7
93 /* 7816 Status Word is not command complete(0x9000) */
94 #define NFC_STATUS_CMD_NOT_CMPLTD 0xE8
95 /* Out of GKI buffers                               */
96 #define NFC_STATUS_NO_BUFFERS 0xE9
97 /* Protocol mismatch between API and activated one  */
98 #define NFC_STATUS_WRONG_PROTOCOL 0xEA
99 /* Another Tag command is already in progress       */
100 #define NFC_STATUS_BUSY 0xEB
101 
102 /* Link Loss                  */
103 #define NFC_STATUS_LINK_LOSS 0xFC
104 /* data len exceeds MIU       */
105 #define NFC_STATUS_BAD_LENGTH 0xFD
106 /* invalid handle             */
107 #define NFC_STATUS_BAD_HANDLE 0xFE
108 /* congested                  */
109 #define NFC_STATUS_CONGESTED 0xFF
110 typedef uint8_t tNFC_STATUS;
111 
112 /**********************************************
113  * NFC Config Parameter IDs defined by NCI
114  **********************************************/
115 #define NFC_PMID_TOTAL_DURATION NCI_PARAM_ID_TOTAL_DURATION
116 #define NFC_PMID_PA_BAILOUT NCI_PARAM_ID_PA_BAILOUT
117 #define NFC_PMID_PF_RC NCI_PARAM_ID_PF_RC
118 #define NFC_PMID_PB_BAILOUT NCI_PARAM_ID_PB_BAILOUT
119 #define NFC_PMID_PF_BIT_RATE NCI_PARAM_ID_PF_BIT_RATE
120 #define NFC_PMID_PF_BAILOUT NCI_PARAM_ID_PF_BAILOUT
121 #define NFC_PMID_PF_DEVICES_LIMIT NCI_PARAM_ID_PF_DEVICES_LIMIT
122 #define NFC_PMID_ATR_REQ_GEN_BYTES NCI_PARAM_ID_ATR_REQ_GEN_BYTES
123 #define NFC_PMID_ATR_REQ_CONFIG NCI_PARAM_ID_ATR_REQ_CONFIG
124 #define NFC_PMID_LA_HIST_BY NCI_PARAM_ID_LA_HIST_BY
125 #define NFC_PMID_LA_NFCID1 NCI_PARAM_ID_LA_NFCID1
126 #define NFC_PMID_LA_BIT_FRAME_SDD NCI_PARAM_ID_LA_BIT_FRAME_SDD
127 #define NFC_PMID_LA_PLATFORM_CONFIG NCI_PARAM_ID_LA_PLATFORM_CONFIG
128 #define NFC_PMID_LA_SEL_INFO NCI_PARAM_ID_LA_SEL_INFO
129 #define NFC_PMID_LB_SENSB_INFO NCI_PARAM_ID_LB_SENSB_INFO
130 #define NFC_PMID_LB_H_INFO NCI_PARAM_ID_LB_H_INFO_RSP
131 #define NFC_PMID_LB_NFCID0 NCI_PARAM_ID_LB_NFCID0
132 #define NFC_PMID_LB_APPDATA NCI_PARAM_ID_LB_APPDATA
133 #define NFC_PMID_LB_SFGI NCI_PARAM_ID_LB_SFGI
134 #define NFC_PMID_LB_ADC_FO NCI_PARAM_ID_LB_ADC_FO
135 #define NFC_PMID_LF_T3T_ID1 NCI_PARAM_ID_LF_T3T_ID1
136 #define NFC_PMID_LF_PROTOCOL NCI_PARAM_ID_LF_PROTOCOL
137 #define NFC_PMID_LF_T3T_PMM NCI_PARAM_ID_LF_T3T_PMM
138 #define NFC_PMID_LF_T3T_FLAGS2 NCI_PARAM_ID_LF_T3T_FLAGS2
139 #define NFC_PMID_FWI NCI_PARAM_ID_FWI
140 #define NFC_PMID_LF_CON_BITR_F NCI_PARAM_ID_LF_CON_BITR_F
141 #define NFC_PMID_WT NCI_PARAM_ID_WT
142 #define NFC_PMID_ATR_RES_GEN_BYTES NCI_PARAM_ID_ATR_RES_GEN_BYTES
143 #define NFC_PMID_ATR_RSP_CONFIG NCI_PARAM_ID_ATR_RSP_CONFIG
144 #define NFC_PMID_PACM_BIT_RATE NCI_PARAM_ID_PACM_BIT_RATE
145 #define NFC_PMID_RF_FIELD_INFO NCI_PARAM_ID_RF_FIELD_INFO
146 
147 /* Technology based routing  */
148 #define NFC_ROUTE_TAG_TECH NCI_ROUTE_TAG_TECH
149 /* Protocol based routing  */
150 #define NFC_ROUTE_TAG_PROTO NCI_ROUTE_TAG_PROTO
151 #define NFC_ROUTE_TAG_AID NCI_ROUTE_TAG_AID /* AID routing */
152 #define NFC_ROUTE_TAG_SYSCODE NCI_ROUTE_TAG_SYSCODE /* System Code routing*/
153 /* tag, len, 2 byte value for technology/protocol based routing */
154 
155 /* For routing */
156 #define NFC_DH_ID NCI_DH_ID /* for DH */
157 /* To identify the loopback test */
158 /* use a proprietary range */
159 #define NFC_TEST_ID NCI_TEST_ID
160 
161 #define NFC_TL_SIZE 2
162 #define NFC_SAVED_CMD_SIZE 2
163 
164 typedef tNCI_DISCOVER_MAPS tNFC_DISCOVER_MAPS;
165 typedef tNCI_DISCOVER_PARAMS tNFC_DISCOVER_PARAMS;
166 
167 /* all NFC Manager Callback functions have prototype like void (cback) (uint8_t
168  * event, void *p_data)
169  * tNFC_DATA_CBACK uses connection id as the first parameter; range 0x00-0x0F.
170  * tNFC_DISCOVER_CBACK uses tNFC_DISCOVER_EVT; range  0x4000 ~
171  * tNFC_RESPONSE_CBACK uses tNFC_RESPONSE_EVT; range  0x5000 ~
172  */
173 
174 #define NFC_FIRST_DEVT 0x4000
175 #define NFC_FIRST_REVT 0x5000
176 #define NFC_FIRST_CEVT 0x6000
177 #define NFC_FIRST_TEVT 0x8000
178 
179 /* the events reported on tNFC_RESPONSE_CBACK */
180 enum {
181   NFC_ENABLE_REVT = NFC_FIRST_REVT, /* 0  Enable event                  */
182   NFC_DISABLE_REVT,                 /* 1  Disable event                 */
183   NFC_SET_CONFIG_REVT,              /* 2  Set Config Response           */
184   NFC_GET_CONFIG_REVT,              /* 3  Get Config Response           */
185   NFC_NFCEE_DISCOVER_REVT,          /* 4  Discover NFCEE response       */
186   NFC_NFCEE_INFO_REVT,              /* 5  Discover NFCEE Notification   */
187   NFC_NFCEE_MODE_SET_REVT,          /* 6  NFCEE Mode Set response       */
188   NFC_RF_FIELD_REVT,                /* 7  RF Field information          */
189   NFC_EE_ACTION_REVT,               /* 8  EE Action notification        */
190   NFC_EE_DISCOVER_REQ_REVT,         /* 9  EE Discover Req notification  */
191   NFC_SET_ROUTING_REVT,             /* 10 Configure Routing response    */
192   NFC_GET_ROUTING_REVT,             /* 11 Retrieve Routing response     */
193   NFC_RF_COMM_PARAMS_UPDATE_REVT,   /* 12 RF Communication Param Update */
194   NFC_GEN_ERROR_REVT,               /* 13 generic error notification    */
195   NFC_NFCC_RESTART_REVT,            /* 14 NFCC has been re-initialized  */
196   NFC_NFCC_TIMEOUT_REVT,            /* 15 NFCC is not responding        */
197   NFC_NFCC_TRANSPORT_ERR_REVT,      /* 16 NCI Tranport error            */
198   NFC_NFCC_POWER_OFF_REVT,          /* 17 NFCC turned off               */
199   NFC_SET_POWER_SUB_STATE_REVT,     /* 18 Set power sub state response  */
200   NFC_NFCEE_PL_CONTROL_REVT,        /* NFCEE Power/Link Ctrl response*/
201   NFC_NFCEE_STATUS_REVT             /* NFCEE Status Notification     */
202                                     /* First vendor-specific rsp event  */
203 };
204 typedef uint16_t tNFC_RESPONSE_EVT;
205 
206 enum {
207   NFC_CONN_CREATE_CEVT = NFC_FIRST_CEVT, /* 0  Conn Create Response          */
208   NFC_CONN_CLOSE_CEVT,                   /* 1  Conn Close Response           */
209   NFC_DEACTIVATE_CEVT,                   /* 2  Deactivate response/notificatn*/
210   NFC_DATA_CEVT,                         /* 3  Data                          */
211   NFC_ERROR_CEVT,                        /* 4  generic or interface error    */
212   NFC_DATA_START_CEVT /* 5  received the first fragment on RF link */
213 };
214 typedef uint16_t tNFC_CONN_EVT;
215 
216 #define NFC_NFCC_INFO_LEN 4
217 #ifndef NFC_NFCC_MAX_NUM_VS_INTERFACE
218 #define NFC_NFCC_MAX_NUM_VS_INTERFACE 5
219 #endif
220 typedef struct {
221   tNFC_STATUS status;                   /* The event status.                */
222   uint8_t nci_version;                  /* the NCI version of NFCC          */
223   uint8_t max_conn;                     /* max number of connections by NFCC*/
224   uint32_t nci_features;                /* the NCI features of NFCC         */
225   uint16_t nci_interfaces;              /* the NCI interfaces of NFCC       */
226   uint16_t max_ce_table;                /* the max routing table size       */
227   uint16_t max_param_size;              /* Max Size for Large Parameters    */
228   uint8_t manufacture_id;               /* the Manufacture ID for NFCC      */
229   uint8_t nfcc_info[NFC_NFCC_INFO_LEN]; /* the Manufacture Info for NFCC      */
230   uint8_t vs_interface
231       [NFC_NFCC_MAX_NUM_VS_INTERFACE]; /* the NCI VS interfaces of NFCC    */
232   uint8_t hci_packet_size;             /*HCI payload size*/
233   uint8_t hci_conn_credits;            /*max number of HCI credits*/
234   uint16_t max_nfc_v_size;             /* maximum frame size for NFC-V*/
235 } tNFC_ENABLE_REVT;
236 
237 #define NFC_MAX_NUM_IDS 125
238 /* the data type associated with NFC_SET_CONFIG_REVT */
239 typedef struct {
240   tNFC_STATUS status;                 /* The event status.                */
241   uint8_t num_param_id;               /* Number of rejected NCI Param ID  */
242   uint8_t param_ids[NFC_MAX_NUM_IDS]; /* NCI Param ID          */
243 } tNFC_SET_CONFIG_REVT;
244 
245 /* the data type associated with NFC_GET_CONFIG_REVT */
246 typedef struct {
247   tNFC_STATUS status;    /* The event status.    */
248   uint16_t tlv_size;     /* The length of TLV    */
249   uint8_t* p_param_tlvs; /* TLV                  */
250 } tNFC_GET_CONFIG_REVT;
251 
252 /* the data type associated with NFC_NFCEE_DISCOVER_REVT */
253 typedef struct {
254   tNFC_STATUS status; /* The event status.    */
255   uint8_t num_nfcee;  /* The number of NFCEE  */
256 } tNFC_NFCEE_DISCOVER_REVT;
257 
258 #define NFC_NFCEE_INTERFACE_APDU NCI_NFCEE_INTERFACE_APDU
259 #define NFC_NFCEE_INTERFACE_HCI_ACCESS NCI_NFCEE_INTERFACE_HCI_ACCESS
260 #define NFC_NFCEE_INTERFACE_T3T NCI_NFCEE_INTERFACE_T3T
261 #define NFC_NFCEE_INTERFACE_TRANSPARENT NCI_NFCEE_INTERFACE_TRANSPARENT
262 #define NFC_NFCEE_INTERFACE_PROPRIETARY NCI_NFCEE_INTERFACE_PROPRIETARY
263 
264 #define NFC_NFCEE_TAG_HW_ID NCI_NFCEE_TAG_HW_ID
265 #define NFC_NFCEE_TAG_ATR_BYTES NCI_NFCEE_TAG_ATR_BYTES
266 #define NFC_NFCEE_TAG_T3T_INFO NCI_NFCEE_TAG_T3T_INFO
267 #define NFC_NFCEE_TAG_HCI_HOST_ID NCI_NFCEE_TAG_HCI_HOST_ID
268 typedef uint8_t tNFC_NFCEE_TAG;
269 /* additional NFCEE Info */
270 typedef struct {
271   tNFC_NFCEE_TAG tag;
272   uint8_t len;
273   uint8_t info[NFC_MAX_EE_INFO];
274 } tNFC_NFCEE_TLV;
275 
276 /* NFCEE unrecoverable error */
277 #define NFC_NFCEE_STATUS_UNRECOVERABLE_ERROR NCI_NFCEE_STS_UNRECOVERABLE_ERROR
278 /* NFCEE connected and inactive */
279 #define NFC_NFCEE_STATUS_INACTIVE NCI_NFCEE_STS_CONN_INACTIVE
280 /* NFCEE connected and active   */
281 #define NFC_NFCEE_STATUS_ACTIVE NCI_NFCEE_STS_CONN_ACTIVE
282 /* NFCEE removed                */
283 #define NFC_NFCEE_STATUS_REMOVED NCI_NFCEE_STS_REMOVED
284 
285 /* the data type associated with NFC_NFCEE_INFO_REVT */
286 typedef struct {
287   tNFC_STATUS status;    /* The event status - place holder  */
288   uint8_t nfcee_id;      /* NFCEE ID                         */
289   uint8_t ee_status;     /* The NFCEE status.                */
290   uint8_t num_interface; /* number of NFCEE interfaces       */
291   uint8_t ee_interface[NFC_MAX_EE_INTERFACE]; /* NFCEE interface       */
292   uint8_t num_tlvs;                       /* number of TLVs                   */
293   tNFC_NFCEE_TLV ee_tlv[NFC_MAX_EE_TLVS]; /* The TLVs associated with NFCEE   */
294   bool nfcee_power_ctrl; /* 1, if NFCC has control of NFCEE Power Supply */
295 } tNFC_NFCEE_INFO_REVT;
296 
297 #define NFC_MODE_ACTIVATE NCI_NFCEE_MD_ACTIVATE
298 #define NFC_MODE_DEACTIVATE NCI_NFCEE_MD_DEACTIVATE
299 typedef uint8_t tNFC_NFCEE_MODE;
300 /* the data type associated with NFC_NFCEE_MODE_SET_REVT */
301 typedef struct {
302   tNFC_STATUS status;   /* The event status.*/
303   uint8_t nfcee_id;     /* NFCEE ID         */
304   tNFC_NFCEE_MODE mode; /* NFCEE mode       */
305 } tNFC_NFCEE_MODE_SET_REVT;
306 
307 #if (APPL_DTA_MODE == TRUE)
308 /* This data type is for FW Version */
309 typedef struct {
310   uint8_t rom_code_version; /* ROM code Version  */
311   uint8_t major_version;    /* Major Version */
312   uint8_t minor_version;    /* Minor Version  */
313 } tNFC_FW_VERSION;
314 #endif
315 #define NFC_MAX_AID_LEN NCI_MAX_AID_LEN /* 16 */
316 
317 /* the data type associated with NFC_CE_GET_ROUTING_REVT */
318 typedef struct {
319   tNFC_STATUS status; /* The event status                 */
320   uint8_t nfcee_id;   /* NFCEE ID                         */
321   uint8_t num_tlvs;   /* number of TLVs                   */
322   uint8_t tlv_size;   /* the total len of all TLVs        */
323   uint8_t qualifier_type;                  /* qualifier type */
324   uint8_t param_tlvs[NFC_MAX_EE_TLV_SIZE]; /* the TLVs         */
325 } tNFC_GET_ROUTING_REVT;
326 
327 /* the data type associated with NFC_CONN_CREATE_CEVT */
328 typedef struct {
329   tNFC_STATUS status; /* The event status                 */
330   uint8_t dest_type;  /* the destination type             */
331   uint8_t id;         /* NFCEE ID  or RF Discovery ID     */
332   uint8_t buff_size;  /* The max buffer size              */
333   uint8_t num_buffs;  /* The number of buffers            */
334 } tNFC_CONN_CREATE_CEVT;
335 
336 /* the data type associated with NFC_CONN_CLOSE_CEVT */
337 typedef struct {
338   tNFC_STATUS status; /* The event status                 */
339 } tNFC_CONN_CLOSE_CEVT;
340 
341 /* the data type associated with NFC_DATA_CEVT */
342 typedef struct {
343   tNFC_STATUS status; /* The event status                 */
344   NFC_HDR* p_data;    /* The received Data                */
345 } tNFC_DATA_CEVT;
346 
347 /* the data type associated with NFC_NFCEE_PL_CONTROL_REVT */
348 typedef struct {
349   tNFC_STATUS status;              /* The event status */
350   uint8_t nfcee_id;                /* NFCEE ID */
351   tNCI_NFCEE_PL_CONFIG pl_control; /* Power/Link Control command */
352 } tNFC_NFCEE_PL_CONTROL_REVT;
353 
354 /* the data type associated with NFC_NFCEE_STATUS_REVT */
355 typedef struct {
356   tNFC_STATUS status;              /* The event status */
357   uint8_t nfcee_id;                /* NFCEE ID */
358   tNCI_EE_NTF_STATUS nfcee_status; /* NFCEE status */
359 } tNFC_NFCEE_STATUS_REVT;
360 /* RF Field Status */
361 typedef uint8_t tNFC_RF_STS;
362 
363 /* RF Field Technologies */
364 #define NFC_RF_TECHNOLOGY_A NCI_RF_TECHNOLOGY_A
365 #define NFC_RF_TECHNOLOGY_B NCI_RF_TECHNOLOGY_B
366 #define NFC_RF_TECHNOLOGY_F NCI_RF_TECHNOLOGY_F
367 typedef uint8_t tNFC_RF_TECH;
368 
369 extern uint8_t NFC_GetNCIVersion();
370 
371 /* Supported Protocols */
372 #define NFC_PROTOCOL_UNKNOWN NCI_PROTOCOL_UNKNOWN /* Unknown */
373 /* Type1Tag    - NFC-A            */
374 #define NFC_PROTOCOL_T1T NCI_PROTOCOL_T1T
375 /* Type2Tag    - NFC-A            */
376 #define NFC_PROTOCOL_T2T NCI_PROTOCOL_T2T
377 /* Type3Tag    - NFC-F            */
378 #define NFC_PROTOCOL_T3T NCI_PROTOCOL_T3T
379 /* Type5Tag    - NFC-V/ISO15693*/
380 #define NFC_PROTOCOL_T5T NFC_PROTOCOL_T5T_(NFC_GetNCIVersion())
381 #define NFC_PROTOCOL_T5T_(x) \
382   (((x) == NCI_VERSION_2_0) ? NCI_PROTOCOL_T5T : NCI_PROTOCOL_15693)
383 /* Type 4A,4B  - NFC-A or NFC-B   */
384 #define NFC_PROTOCOL_ISO_DEP NCI_PROTOCOL_ISO_DEP
385 /* NFCDEP/LLCP - NFC-A or NFC-F       */
386 #define NFC_PROTOCOL_NFC_DEP NCI_PROTOCOL_NFC_DEP
387 #define NFC_PROTOCOL_MIFARE NCI_PROTOCOL_MIFARE
388 #define NFC_PROTOCOL_ISO15693 NCI_PROTOCOL_15693
389 #define NFC_PROTOCOL_B_PRIME NCI_PROTOCOL_B_PRIME
390 #define NFC_PROTOCOL_KOVIO NCI_PROTOCOL_KOVIO
391 typedef uint8_t tNFC_PROTOCOL;
392 
393 /* Discovery Types/Detected Technology and Mode */
394 #define NFC_DISCOVERY_TYPE_POLL_A NCI_DISCOVERY_TYPE_POLL_A
395 #define NFC_DISCOVERY_TYPE_POLL_B NCI_DISCOVERY_TYPE_POLL_B
396 #define NFC_DISCOVERY_TYPE_POLL_F NCI_DISCOVERY_TYPE_POLL_F
397 #define NFC_DISCOVERY_TYPE_POLL_A_ACTIVE NCI_DISCOVERY_TYPE_POLL_A_ACTIVE
398 #define NFC_DISCOVERY_TYPE_POLL_F_ACTIVE NCI_DISCOVERY_TYPE_POLL_F_ACTIVE
399 #define NFC_DISCOVERY_TYPE_POLL_ACTIVE NCI_DISCOVERY_TYPE_POLL_ACTIVE
400 #define NFC_DISCOVERY_TYPE_POLL_V NCI_DISCOVERY_TYPE_POLL_V
401 #define NFC_DISCOVERY_TYPE_POLL_B_PRIME NCI_DISCOVERY_TYPE_POLL_B_PRIME
402 #define NFC_DISCOVERY_TYPE_POLL_KOVIO NCI_DISCOVERY_TYPE_POLL_KOVIO
403 #define NFC_DISCOVERY_TYPE_LISTEN_A NCI_DISCOVERY_TYPE_LISTEN_A
404 #define NFC_DISCOVERY_TYPE_LISTEN_B NCI_DISCOVERY_TYPE_LISTEN_B
405 #define NFC_DISCOVERY_TYPE_LISTEN_F NCI_DISCOVERY_TYPE_LISTEN_F
406 #define NFC_DISCOVERY_TYPE_LISTEN_A_ACTIVE NCI_DISCOVERY_TYPE_LISTEN_A_ACTIVE
407 #define NFC_DISCOVERY_TYPE_LISTEN_F_ACTIVE NCI_DISCOVERY_TYPE_LISTEN_F_ACTIVE
408 #define NFC_DISCOVERY_TYPE_LISTEN_ACTIVE NCI_DISCOVERY_TYPE_LISTEN_ACTIVE
409 #define NFC_DISCOVERY_TYPE_LISTEN_ISO15693 NCI_DISCOVERY_TYPE_LISTEN_ISO15693
410 #define NFC_DISCOVERY_TYPE_LISTEN_B_PRIME NCI_DISCOVERY_TYPE_LISTEN_B_PRIME
411 typedef uint8_t tNFC_DISCOVERY_TYPE;
412 typedef uint8_t tNFC_RF_TECH_N_MODE;
413 
414 /* Select Response codes */
415 #define NFC_SEL_RES_NFC_FORUM_T2T 0x00
416 #define NFC_SEL_RES_MF_CLASSIC 0x08
417 
418 /* Bit Rates */
419 #define NFC_BIT_RATE_212 NCI_BIT_RATE_212   /* 212 kbit/s */
420 #define NFC_BIT_RATE_424 NCI_BIT_RATE_424   /* 424 kbit/s */
421 typedef uint8_t tNFC_BIT_RATE;
422 
423 /**********************************************
424  * Interface Types
425  **********************************************/
426 #define NFC_INTERFACE_EE_DIRECT_RF NCI_INTERFACE_EE_DIRECT_RF
427 #define NFC_INTERFACE_FRAME NCI_INTERFACE_FRAME
428 #define NFC_INTERFACE_ISO_DEP NCI_INTERFACE_ISO_DEP
429 #define NFC_INTERFACE_NFC_DEP NCI_INTERFACE_NFC_DEP
430 #define NFC_INTERFACE_MIFARE NCI_INTERFACE_VS_MIFARE
431 typedef tNCI_INTF_TYPE tNFC_INTF_TYPE;
432 
433 /**********************************************
434  *  Deactivation Type
435  **********************************************/
436 #define NFC_DEACTIVATE_TYPE_IDLE NCI_DEACTIVATE_TYPE_IDLE
437 #define NFC_DEACTIVATE_TYPE_SLEEP NCI_DEACTIVATE_TYPE_SLEEP
438 #define NFC_DEACTIVATE_TYPE_SLEEP_AF NCI_DEACTIVATE_TYPE_SLEEP_AF
439 #define NFC_DEACTIVATE_TYPE_DISCOVERY NCI_DEACTIVATE_TYPE_DISCOVERY
440 typedef uint8_t tNFC_DEACT_TYPE;
441 
442 /**********************************************
443  *  Deactivation Reasons
444  **********************************************/
445 #define NFC_DEACTIVATE_REASON_DH_REQ_FAILED NCI_DEACTIVATE_REASON_DH_REQ_FAILED
446 #define NFC_DEACTIVATE_REASON_DH_REQ NCI_DEACTIVATE_REASON_DH_REQ
447 typedef uint8_t tNFC_DEACT_REASON;
448 
449 /* the data type associated with NFC_RF_FIELD_REVT */
450 typedef struct {
451   tNFC_STATUS status;   /* The event status - place holder. */
452   tNFC_RF_STS rf_field; /* RF Field Status                  */
453 } tNFC_RF_FIELD_REVT;
454 
455 #define NFC_MAX_APP_DATA_LEN 40
456 typedef struct {
457   uint8_t len_aid;              /* length of application id */
458   uint8_t aid[NFC_MAX_AID_LEN]; /* application id           */
459 } tNFC_AID;
460 typedef struct {
461   uint8_t len_aid;                    /* length of application id */
462   uint8_t aid[NFC_MAX_AID_LEN];       /* application id           */
463   uint8_t len_data;                   /* len of application data  */
464   uint8_t data[NFC_MAX_APP_DATA_LEN]; /* application data    */
465 } tNFC_APP_INIT;
466 
467 /* ISO 7816-4 SELECT command */
468 #define NFC_EE_TRIG_SELECT NCI_EE_TRIG_7816_SELECT
469 /* RF Protocol changed       */
470 #define NFC_EE_TRIG_RF_PROTOCOL NCI_EE_TRIG_RF_PROTOCOL
471 /* RF Technology changed     */
472 #define NFC_EE_TRIG_RF_TECHNOLOGY NCI_EE_TRIG_RF_TECHNOLOGY
473 /* Application initiation    */
474 #define NFC_EE_TRIG_APP_INIT NCI_EE_TRIG_APP_INIT
475 typedef uint8_t tNFC_EE_TRIGGER;
476 typedef struct {
477   tNFC_EE_TRIGGER trigger; /* the trigger of this event        */
478   union {
479     tNFC_PROTOCOL protocol;
480     tNFC_RF_TECH technology;
481     tNFC_AID aid;
482     tNFC_APP_INIT app_init;
483   } param; /* Discovery Type specific parameters */
484 } tNFC_ACTION_DATA;
485 
486 /* the data type associated with NFC_EE_ACTION_REVT */
487 typedef struct {
488   tNFC_STATUS status;        /* The event status - place holder  */
489   uint8_t nfcee_id;          /* NFCEE ID                         */
490   tNFC_ACTION_DATA act_data; /* data associated /w the action    */
491 } tNFC_EE_ACTION_REVT;
492 
493 #define NFC_EE_DISC_OP_ADD 0
494 typedef uint8_t tNFC_EE_DISC_OP;
495 typedef struct {
496   tNFC_EE_DISC_OP op;              /* add or remove this entry         */
497   uint8_t nfcee_id;                /* NFCEE ID                         */
498   tNFC_RF_TECH_N_MODE tech_n_mode; /* Discovery Technology and Mode    */
499   tNFC_PROTOCOL protocol;          /* NFC protocol                     */
500 } tNFC_EE_DISCOVER_INFO;
501 
502 #ifndef NFC_MAX_EE_DISC_ENTRIES
503 #define NFC_MAX_EE_DISC_ENTRIES 6
504 #endif
505 /* T, L, V(NFCEE ID, TechnMode, Protocol) */
506 #define NFC_EE_DISCOVER_ENTRY_LEN 5
507 #define NFC_EE_DISCOVER_INFO_LEN 3 /* NFCEE ID, TechnMode, Protocol */
508 /* the data type associated with NFC_EE_DISCOVER_REQ_REVT */
509 typedef struct {
510   tNFC_STATUS status; /* The event status - place holder  */
511   uint8_t num_info;   /* number of entries in info[]      */
512   tNFC_EE_DISCOVER_INFO
513       info[NFC_MAX_EE_DISC_ENTRIES]; /* discovery request from NFCEE */
514 } tNFC_EE_DISCOVER_REQ_REVT;
515 
516 typedef union {
517   tNFC_STATUS status; /* The event status. */
518   tNFC_ENABLE_REVT enable;
519   tNFC_SET_CONFIG_REVT set_config;
520   tNFC_GET_CONFIG_REVT get_config;
521   tNFC_NFCEE_DISCOVER_REVT nfcee_discover;
522   tNFC_NFCEE_INFO_REVT nfcee_info;
523   tNFC_NFCEE_MODE_SET_REVT mode_set;
524   tNFC_NFCEE_PL_CONTROL_REVT pl_control;
525   tNFC_NFCEE_STATUS_REVT nfcee_status;
526   tNFC_RF_FIELD_REVT rf_field;
527   tNFC_STATUS cfg_routing;
528   tNFC_GET_ROUTING_REVT get_routing;
529   tNFC_EE_ACTION_REVT ee_action;
530   tNFC_EE_DISCOVER_REQ_REVT ee_discover_req;
531   void* p_vs_evt_data;
532 } tNFC_RESPONSE;
533 
534 /*************************************
535 **  RESPONSE Callback Functions
536 **************************************/
537 typedef void(tNFC_RESPONSE_CBACK)(tNFC_RESPONSE_EVT event,
538                                   tNFC_RESPONSE* p_data);
539 
540 /* The events reported on tNFC_VS_CBACK */
541 /* The event is (NCI_RSP_BIT|oid) for response and (NCI_NTF_BIT|oid) for
542  * notification*/
543 
544 typedef uint8_t tNFC_VS_EVT;
545 
546 /*************************************
547 **  Proprietary (Vendor Specific) Callback Functions
548 **************************************/
549 typedef void(tNFC_VS_CBACK)(tNFC_VS_EVT event, uint16_t data_len,
550                             uint8_t* p_data);
551 
552 /* the events reported on tNFC_DISCOVER_CBACK */
553 enum {
554   NFC_START_DEVT = NFC_FIRST_DEVT, /* Status of NFC_DiscoveryStart     */
555   NFC_MAP_DEVT,                    /* Status of NFC_DiscoveryMap       */
556   NFC_RESULT_DEVT,                 /* The responses from remote device */
557   NFC_SELECT_DEVT,                 /* Status of NFC_DiscoverySelect    */
558   NFC_ACTIVATE_DEVT,               /* RF interface is activated        */
559   NFC_DEACTIVATE_DEVT              /* Status of RF deactivation        */
560 };
561 typedef uint16_t tNFC_DISCOVER_EVT;
562 
563 /* the data type associated with NFC_START_DEVT */
564 typedef tNFC_STATUS tNFC_START_DEVT;
565 
566 typedef tNCI_RF_PA_PARAMS tNFC_RF_PA_PARAMS;
567 #define NFC_MAX_SENSB_RES_LEN NCI_MAX_SENSB_RES_LEN
568 #define NFC_NFCID0_MAX_LEN 4
569 typedef struct {
570   uint8_t sensb_res_len; /* Length of SENSB_RES Response (Byte 2 - Byte 12 or
571                             13) Available after Technology Detection */
572   uint8_t sensb_res[NFC_MAX_SENSB_RES_LEN]; /* SENSB_RES Response (ATQ) */
573   uint8_t nfcid0[NFC_NFCID0_MAX_LEN];
574 } tNFC_RF_PB_PARAMS;
575 
576 #define NFC_MAX_SENSF_RES_LEN NCI_MAX_SENSF_RES_LEN
577 #define NFC_NFCID2_LEN NCI_NFCID2_LEN
578 typedef struct {
579   uint8_t bit_rate;      /* NFC_BIT_RATE_212 or NFC_BIT_RATE_424 */
580   uint8_t sensf_res_len; /* Length of SENSF_RES Response (Byte 2 - Byte 17 or
581                             19) Available after Technology Detection */
582   uint8_t sensf_res[NFC_MAX_SENSF_RES_LEN]; /* SENSB_RES Response */
583   uint8_t nfcid2[NFC_NFCID2_LEN]; /* NFCID2 generated by the Local NFCC for
584                                      NFC-DEP Protocol.Available for Frame
585                                      Interface  */
586   uint8_t mrti_check;
587   uint8_t mrti_update;
588 } tNFC_RF_PF_PARAMS;
589 
590 typedef tNCI_RF_LF_PARAMS tNFC_RF_LF_PARAMS;
591 
592 #define NFC_ISO15693_UID_LEN 8
593 typedef struct {
594   uint8_t flag;
595   uint8_t dsfid;
596   uint8_t uid[NFC_ISO15693_UID_LEN];
597 } tNFC_RF_PISO15693_PARAMS;
598 
599 #ifndef NFC_KOVIO_MAX_LEN
600 #define NFC_KOVIO_MAX_LEN 32
601 #endif
602 typedef struct {
603   uint8_t uid_len;
604   uint8_t uid[NFC_KOVIO_MAX_LEN];
605 } tNFC_RF_PKOVIO_PARAMS;
606 
607 typedef tNCI_RF_ACM_P_PARAMS tNFC_RF_ACM_P_PARAMS;
608 
609 typedef union {
610   tNFC_RF_PA_PARAMS pa;
611   tNFC_RF_PB_PARAMS pb;
612   tNFC_RF_PF_PARAMS pf;
613   tNFC_RF_LF_PARAMS lf;
614   tNFC_RF_PISO15693_PARAMS pi93;
615   tNFC_RF_PKOVIO_PARAMS pk;
616   tNFC_RF_ACM_P_PARAMS acm_p;
617 } tNFC_RF_TECH_PARAMU;
618 
619 typedef struct {
620   tNFC_DISCOVERY_TYPE mode;
621   tNFC_RF_TECH_PARAMU param;
622 } tNFC_RF_TECH_PARAMS;
623 
624 /* the data type associated with NFC_RESULT_DEVT */
625 typedef struct {
626   tNFC_STATUS status;                /* The event status - place holder.  */
627   uint8_t rf_disc_id;                /* RF Discovery ID                   */
628   uint8_t protocol;                  /* supported protocol                */
629   tNFC_RF_TECH_PARAMS rf_tech_param; /* RF technology parameters          */
630   uint8_t more;                      /* 0: last, 1: last (limit), 2: more */
631 } tNFC_RESULT_DEVT;
632 
633 /* the data type associated with NFC_SELECT_DEVT */
634 typedef tNFC_STATUS tNFC_SELECT_DEVT;
635 
636 /* the data type associated with NFC_STOP_DEVT */
637 typedef tNFC_STATUS tNFC_STOP_DEVT;
638 
639 #define NFC_MAX_ATS_LEN NCI_MAX_ATS_LEN
640 #define NFC_MAX_HIS_BYTES_LEN NCI_MAX_HIS_BYTES_LEN
641 #define NFC_MAX_GEN_BYTES_LEN NCI_MAX_GEN_BYTES_LEN
642 
643 typedef struct {
644   uint8_t ats_res_len;              /* Length of ATS RES                */
645   uint8_t ats_res[NFC_MAX_ATS_LEN]; /* ATS RES                          */
646   bool nad_used;                    /* NAD is used or not               */
647   uint8_t fwi;                      /* Frame Waiting time Integer       */
648   uint8_t sfgi;                     /* Start-up Frame Guard time Integer*/
649   uint8_t his_byte_len;             /* len of historical bytes          */
650   uint8_t his_byte[NFC_MAX_HIS_BYTES_LEN]; /* historical bytes             */
651 } tNFC_INTF_PA_ISO_DEP;
652 
653 typedef struct { uint8_t rats; /* RATS */ } tNFC_INTF_LA_ISO_DEP;
654 
655 typedef struct {
656   uint8_t atr_res_len;                      /* Length of ATR_RES            */
657   uint8_t atr_res[NFC_MAX_ATS_LEN];         /* ATR_RES (Byte 3 - Byte 17+n) */
658   uint8_t max_payload_size;                 /* 64, 128, 192 or 254          */
659   uint8_t gen_bytes_len;                    /* len of general bytes         */
660   uint8_t gen_bytes[NFC_MAX_GEN_BYTES_LEN]; /* general bytes           */
661   uint8_t
662       waiting_time; /* WT -> Response Waiting Time RWT = (256 x 16/fC) x 2WT */
663 } tNFC_INTF_PA_NFC_DEP;
664 
665 /* Note: keep tNFC_INTF_PA_NFC_DEP data member in the same order as
666  * tNFC_INTF_LA_NFC_DEP */
667 typedef struct {
668   uint8_t atr_req_len;                      /* Length of ATR_REQ            */
669   uint8_t atr_req[NFC_MAX_ATS_LEN];         /* ATR_REQ (Byte 3 - Byte 18+n) */
670   uint8_t max_payload_size;                 /* 64, 128, 192 or 254          */
671   uint8_t gen_bytes_len;                    /* len of general bytes         */
672   uint8_t gen_bytes[NFC_MAX_GEN_BYTES_LEN]; /* general bytes           */
673 } tNFC_INTF_LA_NFC_DEP;
674 typedef tNFC_INTF_LA_NFC_DEP tNFC_INTF_LF_NFC_DEP;
675 typedef tNFC_INTF_PA_NFC_DEP tNFC_INTF_PF_NFC_DEP;
676 
677 #define NFC_MAX_ATTRIB_LEN NCI_MAX_ATTRIB_LEN
678 
679 typedef struct {
680   uint8_t attrib_res_len;                 /* Length of ATTRIB RES      */
681   uint8_t attrib_res[NFC_MAX_ATTRIB_LEN]; /* ATTRIB RES                */
682   uint8_t hi_info_len;                    /* len of Higher layer Info  */
683   uint8_t hi_info[NFC_MAX_GEN_BYTES_LEN]; /* Higher layer Info         */
684   uint8_t mbli;                           /* Maximum buffer length.    */
685 } tNFC_INTF_PB_ISO_DEP;
686 
687 typedef struct {
688   uint8_t attrib_req_len;                 /* Length of ATTRIB REQ      */
689   uint8_t attrib_req[NFC_MAX_ATTRIB_LEN]; /* ATTRIB REQ (Byte 2 - 10+k)*/
690   uint8_t hi_info_len;                    /* len of Higher layer Info  */
691   uint8_t hi_info[NFC_MAX_GEN_BYTES_LEN]; /* Higher layer Info         */
692   uint8_t nfcid0[NFC_NFCID0_MAX_LEN];     /* NFCID0                    */
693 } tNFC_INTF_LB_ISO_DEP;
694 
695 #ifndef NFC_MAX_RAW_PARAMS
696 #define NFC_MAX_RAW_PARAMS 16
697 #endif
698 #define NFC_MAX_RAW_PARAMS 16
699 typedef struct {
700   uint8_t param_len;
701   uint8_t param[NFC_MAX_RAW_PARAMS];
702 } tNFC_INTF_FRAME;
703 
704 typedef struct {
705   tNFC_INTF_TYPE type; /* Interface Type  1 Byte  See Table 67 */
706   union {
707     tNFC_INTF_LA_ISO_DEP la_iso;
708     tNFC_INTF_PA_ISO_DEP pa_iso;
709     tNFC_INTF_LB_ISO_DEP lb_iso;
710     tNFC_INTF_PB_ISO_DEP pb_iso;
711     tNFC_INTF_LA_NFC_DEP la_nfc;
712     tNFC_INTF_PA_NFC_DEP pa_nfc;
713     tNFC_INTF_LF_NFC_DEP lf_nfc;
714     tNFC_INTF_PF_NFC_DEP pf_nfc;
715     tNFC_INTF_FRAME frame;
716   } intf_param; /* Activation Parameters   0 - n Bytes */
717 } tNFC_INTF_PARAMS;
718 
719 /* the data type associated with NFC_ACTIVATE_DEVT */
720 typedef struct {
721   uint8_t rf_disc_id;                /* RF Discovery ID          */
722   tNFC_PROTOCOL protocol;            /* supported protocol       */
723   tNFC_RF_TECH_PARAMS rf_tech_param; /* RF technology parameters */
724   tNFC_DISCOVERY_TYPE data_mode;     /* for future Data Exchange */
725   tNFC_BIT_RATE tx_bitrate;          /* Data Exchange Tx Bitrate */
726   tNFC_BIT_RATE rx_bitrate;          /* Data Exchange Rx Bitrate */
727   tNFC_INTF_PARAMS intf_param;       /* interface type and params*/
728 } tNFC_ACTIVATE_DEVT;
729 
730 /* the data type associated with NFC_DEACTIVATE_DEVT and NFC_DEACTIVATE_CEVT */
731 typedef struct {
732   tNFC_STATUS status;   /* The event status.        */
733   tNFC_DEACT_TYPE type; /* De-activate type         */
734   bool is_ntf;          /* TRUE, if deactivate notif*/
735   tNFC_DEACT_REASON reason; /* De-activate reason    */
736 } tNFC_DEACTIVATE_DEVT;
737 
738 typedef union {
739   tNFC_STATUS status; /* The event status.        */
740   tNFC_START_DEVT start;
741   tNFC_RESULT_DEVT result;
742   tNFC_SELECT_DEVT select;
743   tNFC_STOP_DEVT stop;
744   tNFC_ACTIVATE_DEVT activate;
745   tNFC_DEACTIVATE_DEVT deactivate;
746 } tNFC_DISCOVER;
747 
748 typedef struct {
749   bool include_rf_tech_mode; /* TRUE if including RF Tech and Mode update    */
750   tNFC_RF_TECH_N_MODE rf_tech_n_mode; /* RF tech and mode */
751   bool include_tx_bit_rate;  /* TRUE if including Tx bit rate update         */
752   tNFC_BIT_RATE tx_bit_rate; /* Transmit Bit Rate                            */
753   bool include_rx_bit_rate;  /* TRUE if including Rx bit rate update         */
754   tNFC_BIT_RATE rx_bit_rate; /* Receive Bit Rate                             */
755   bool include_nfc_b_config; /* TRUE if including NFC-B data exchange config */
756   uint8_t min_tr0;           /* Minimun TR0                                  */
757   uint8_t min_tr1;           /* Minimun TR1                                  */
758   uint8_t suppression_eos;   /* Suppression of EoS                           */
759   uint8_t suppression_sos;   /* Suppression of SoS                           */
760   uint8_t min_tr2;           /* Minimun TR1                                  */
761 } tNFC_RF_COMM_PARAMS;
762 
763 /*************************************
764 **  DISCOVER Callback Functions
765 **************************************/
766 typedef void(tNFC_DISCOVER_CBACK)(tNFC_DISCOVER_EVT event,
767                                   tNFC_DISCOVER* p_data);
768 
769 typedef uint16_t tNFC_TEST_EVT;
770 
771 /* the data type associated with NFC_LOOPBACK_TEVT */
772 typedef struct {
773   tNFC_STATUS status; /* The event status.            */
774   NFC_HDR* p_data;    /* The loop back data from NFCC */
775 } tNFC_LOOPBACK_TEVT;
776 
777 /* the data type associated with NFC_RF_CONTROL_TEVT */
778 typedef tNFC_STATUS tNFC_RF_CONTROL_TEVT;
779 
780 typedef union {
781   tNFC_STATUS status; /* The event status.            */
782   tNFC_LOOPBACK_TEVT loop_back;
783   tNFC_RF_CONTROL_TEVT rf_control;
784 } tNFC_TEST;
785 
786 /*************************************
787 **  TEST Callback Functions
788 **************************************/
789 typedef void(tNFC_TEST_CBACK)(tNFC_TEST_EVT event, tNFC_TEST* p_data);
790 
791 typedef tNFC_DEACTIVATE_DEVT tNFC_DEACTIVATE_CEVT;
792 typedef union {
793   tNFC_STATUS status; /* The event status. */
794   tNFC_CONN_CREATE_CEVT conn_create;
795   tNFC_CONN_CLOSE_CEVT conn_close;
796   tNFC_DEACTIVATE_CEVT deactivate;
797   tNFC_DATA_CEVT data;
798 } tNFC_CONN;
799 
800 /*************************************
801 **  Data Callback Functions
802 **************************************/
803 typedef void(tNFC_CONN_CBACK)(uint8_t conn_id, tNFC_CONN_EVT event,
804                               tNFC_CONN* p_data);
805 #define NFC_MAX_CONN_ID 15
806 #define NFC_ILLEGAL_CONN_ID 0xFF
807 /* the static connection ID for RF traffic */
808 #define NFC_RF_CONN_ID 0
809 /* the static connection ID for HCI transport */
810 #define NFC_HCI_CONN_ID 1
811 
812 /*****************************************************************************
813 **  EXTERNAL FUNCTION DECLARATIONS
814 *****************************************************************************/
815 
816 /*******************************************************************************
817 **
818 ** Function         NFC_Enable
819 **
820 ** Description      This function enables NFC. Prior to calling NFC_Enable:
821 **                  - the NFCC must be powered up, and ready to receive
822 **                    commands.
823 **                  - GKI must be enabled
824 **                  - NFC_TASK must be started
825 **                  - NCIT_TASK must be started (if using dedicated NCI
826 **                    transport)
827 **
828 **                  This function opens the NCI transport (if applicable),
829 **                  resets the NFC controller, and initializes the NFC
830 **                  subsystems.
831 **
832 **                  When the NFC startup procedure is completed, an
833 **                  NFC_ENABLE_REVT is returned to the application using the
834 **                  tNFC_RESPONSE_CBACK.
835 **
836 ** Returns          tNFC_STATUS
837 **
838 *******************************************************************************/
839 extern tNFC_STATUS NFC_Enable(tNFC_RESPONSE_CBACK* p_cback);
840 
841 /*******************************************************************************
842 **
843 ** Function         NFC_Disable
844 **
845 ** Description      This function performs clean up routines for shutting down
846 **                  NFC and closes the NCI transport (if using dedicated NCI
847 **                  transport).
848 **
849 **                  When the NFC shutdown procedure is completed, an
850 **                  NFC_DISABLED_REVT is returned to the application using the
851 **                  tNFC_RESPONSE_CBACK.
852 **
853 ** Returns          nothing
854 **
855 *******************************************************************************/
856 extern void NFC_Disable(void);
857 
858 /*******************************************************************************
859 **
860 ** Function         NFC_Init
861 **
862 ** Description      This function initializes control blocks for NFC
863 **
864 ** Returns          nothing
865 **
866 *******************************************************************************/
867 extern void NFC_Init(tHAL_NFC_ENTRY* p_hal_entry_tbl);
868 
869 /*******************************************************************************
870 **
871 ** Function         NFC_GetLmrtSize
872 **
873 ** Description      Called by application wto query the Listen Mode Routing
874 **                  Table size supported by NFCC
875 **
876 ** Returns          Listen Mode Routing Table size
877 **
878 *******************************************************************************/
879 extern uint16_t NFC_GetLmrtSize(void);
880 
881 /*******************************************************************************
882 **
883 ** Function         NFC_SetConfig
884 **
885 ** Description      This function is called to send the configuration parameter
886 **                  TLV to NFCC. The response from NFCC is reported by
887 **                  tNFC_RESPONSE_CBACK as NFC_SET_CONFIG_REVT.
888 **
889 ** Parameters       tlv_size - the length of p_param_tlvs.
890 **                  p_param_tlvs - the parameter ID/Len/Value list
891 **
892 ** Returns          tNFC_STATUS
893 **
894 *******************************************************************************/
895 extern tNFC_STATUS NFC_SetConfig(uint8_t tlv_size, uint8_t* p_param_tlvs);
896 
897 /*******************************************************************************
898 **
899 ** Function         NFC_GetConfig
900 **
901 ** Description      This function is called to retrieve the parameter TLV from
902 **                  NFCC. The response from NFCC is reported by
903 **                  tNFC_RESPONSE_CBACK as NFC_GET_CONFIG_REVT.
904 **
905 ** Parameters       num_ids - the number of parameter IDs
906 **                  p_param_ids - the parameter ID list.
907 **
908 ** Returns          tNFC_STATUS
909 **
910 *******************************************************************************/
911 extern tNFC_STATUS NFC_GetConfig(uint8_t num_ids, uint8_t* p_param_ids);
912 
913 /*******************************************************************************
914 **
915 ** Function         NFC_NfceeDiscover
916 **
917 ** Description      This function is called to enable or disable NFCEE
918 **                  Discovery. The response from NFCC is reported by
919 **                  tNFC_RESPONSE_CBACK as NFC_NFCEE_DISCOVER_REVT.
920 **                  The notification from NFCC is reported by
921 **                  tNFC_RESPONSE_CBACK as NFC_NFCEE_INFO_REVT.
922 **
923 ** Parameters       discover - 1 to enable discover, 0 to disable.
924 **
925 ** Returns          tNFC_STATUS
926 **
927 *******************************************************************************/
928 extern tNFC_STATUS NFC_NfceeDiscover(bool discover);
929 
930 /*******************************************************************************
931 **
932 ** Function         NFC_NfceeModeSet
933 **
934 ** Description      This function is called to activate or de-activate an NFCEE
935 **                  connected to the NFCC.
936 **                  The response from NFCC is reported by tNFC_RESPONSE_CBACK
937 **                  as NFC_NFCEE_MODE_SET_REVT.
938 **
939 ** Parameters       nfcee_id - the NFCEE to activate or de-activate.
940 **                  mode - 0 to activate NFCEE, 1 to de-activate.
941 **
942 ** Returns          tNFC_STATUS
943 **
944 *******************************************************************************/
945 extern tNFC_STATUS NFC_NfceeModeSet(uint8_t nfcee_id, tNFC_NFCEE_MODE mode);
946 /*******************************************************************************
947 **
948 ** Function         NFC_DiscoveryMap
949 **
950 ** Description      This function is called to set the discovery interface
951 **                  mapping. The response from NFCC is reported by
952 **                  tNFC_DISCOVER_CBACK as. NFC_MAP_DEVT.
953 **
954 ** Parameters       num - the number of items in p_params.
955 **                  p_maps - the discovery interface mappings
956 **                  p_cback - the discovery callback function
957 **
958 ** Returns          tNFC_STATUS
959 **
960 *******************************************************************************/
961 extern tNFC_STATUS NFC_DiscoveryMap(uint8_t num, tNFC_DISCOVER_MAPS* p_maps,
962                                     tNFC_DISCOVER_CBACK* p_cback);
963 
964 /*******************************************************************************
965 **
966 ** Function         NFC_DiscoveryStart
967 **
968 ** Description      This function is called to start Polling and/or Listening.
969 **                  The response from NFCC is reported by tNFC_DISCOVER_CBACK
970 **                  as NFC_START_DEVT. The notification from NFCC is reported by
971 **                  tNFC_DISCOVER_CBACK as NFC_RESULT_DEVT.
972 **
973 ** Parameters       num_params - the number of items in p_params.
974 **                  p_params - the discovery parameters
975 **                  p_cback - the discovery callback function
976 **
977 ** Returns          tNFC_STATUS
978 **
979 *******************************************************************************/
980 extern tNFC_STATUS NFC_DiscoveryStart(uint8_t num_params,
981                                       tNFC_DISCOVER_PARAMS* p_params,
982                                       tNFC_DISCOVER_CBACK* p_cback);
983 
984 /*******************************************************************************
985 **
986 ** Function         NFC_DiscoverySelect
987 **
988 ** Description      If tNFC_DISCOVER_CBACK reports status=NFC_MULTIPLE_PROT,
989 **                  the application needs to use this function to select the
990 **                  the logical endpoint to continue. The response from NFCC is
991 **                  reported by tNFC_DISCOVER_CBACK as NFC_SELECT_DEVT.
992 **
993 ** Parameters       rf_disc_id - The ID identifies the remote device.
994 **                  protocol - the logical endpoint on the remote devide
995 **                  rf_interface - the RF interface to communicate with NFCC
996 **
997 ** Returns          tNFC_STATUS
998 **
999 *******************************************************************************/
1000 extern tNFC_STATUS NFC_DiscoverySelect(uint8_t rf_disc_id, uint8_t protocol,
1001                                        uint8_t rf_interface);
1002 
1003 /*******************************************************************************
1004 **
1005 ** Function         NFC_ConnCreate
1006 **
1007 ** Description      This function is called to create a logical connection with
1008 **                  NFCC for data exchange.
1009 **                  The response from NFCC is reported in tNFC_CONN_CBACK
1010 **                  as NFC_CONN_CREATE_CEVT.
1011 **
1012 ** Parameters       dest_type - the destination type
1013 **                  id   - the NFCEE ID or RF Discovery ID .
1014 **                  protocol - the protocol
1015 **                  p_cback - the data callback function to receive data from
1016 **                  NFCC
1017 **
1018 ** Returns          tNFC_STATUS
1019 **
1020 *******************************************************************************/
1021 extern tNFC_STATUS NFC_ConnCreate(uint8_t dest_type, uint8_t id,
1022                                   uint8_t protocol, tNFC_CONN_CBACK* p_cback);
1023 
1024 /*******************************************************************************
1025 **
1026 ** Function         NFC_ConnClose
1027 **
1028 ** Description      This function is called to close a logical connection with
1029 **                  NFCC.
1030 **                  The response from NFCC is reported in tNFC_CONN_CBACK
1031 **                  as NFC_CONN_CLOSE_CEVT.
1032 **
1033 ** Parameters       conn_id - the connection id.
1034 **
1035 ** Returns          tNFC_STATUS
1036 **
1037 *******************************************************************************/
1038 extern tNFC_STATUS NFC_ConnClose(uint8_t conn_id);
1039 
1040 /*******************************************************************************
1041 **
1042 ** Function         NFC_SetStaticRfCback
1043 **
1044 ** Description      This function is called to update the data callback function
1045 **                  to receive the data for the given connection id.
1046 **
1047 ** Parameters       p_cback - the connection callback function
1048 **
1049 ** Returns          Nothing
1050 **
1051 *******************************************************************************/
1052 extern void NFC_SetStaticRfCback(tNFC_CONN_CBACK* p_cback);
1053 
1054 /*******************************************************************************
1055 **
1056 ** Function         NFC_SetReassemblyFlag
1057 **
1058 ** Description      This function is called to set if nfc will reassemble
1059 **                  nci packet as much as its buffer can hold or it should not
1060 **                  reassemble but forward the fragmented nci packet to layer
1061 **                  above. If nci data pkt is fragmented, nfc may send multiple
1062 **                  NFC_DATA_CEVT with status NFC_STATUS_CONTINUE before sending
1063 **                  NFC_DATA_CEVT with status NFC_STATUS_OK based on reassembly
1064 **                  configuration and reassembly buffer size
1065 **
1066 ** Parameters       reassembly - flag to indicate if nfc may reassemble or not
1067 **
1068 ** Returns          Nothing
1069 **
1070 *******************************************************************************/
1071 extern void NFC_SetReassemblyFlag(bool reassembly);
1072 
1073 /*******************************************************************************
1074 **
1075 ** Function         NFC_SendData
1076 **
1077 ** Description      This function is called to send the given data packet
1078 **                  to the connection identified by the given connection id.
1079 **
1080 ** Parameters       conn_id - the connection id.
1081 **                  p_data - the data packet
1082 **
1083 ** Returns          tNFC_STATUS
1084 **
1085 *******************************************************************************/
1086 extern tNFC_STATUS NFC_SendData(uint8_t conn_id, NFC_HDR* p_data);
1087 
1088 /*******************************************************************************
1089 **
1090 ** Function         NFC_FlushData
1091 **
1092 ** Description      This function is called to discard the tx data queue of
1093 **                  the given connection id.
1094 **
1095 ** Parameters       conn_id - the connection id.
1096 **
1097 ** Returns          tNFC_STATUS
1098 **
1099 *******************************************************************************/
1100 extern tNFC_STATUS NFC_FlushData(uint8_t conn_id);
1101 
1102 /*******************************************************************************
1103 **
1104 ** Function         NFC_Deactivate
1105 **
1106 ** Description      This function is called to stop the discovery process or
1107 **                  put the listen device in sleep mode or terminate the NFC
1108 **                  link.
1109 **
1110 **                  The response from NFCC is reported by tNFC_DISCOVER_CBACK
1111 **                  as NFC_DEACTIVATE_DEVT.
1112 **
1113 ** Parameters       deactivate_type - NFC_DEACTIVATE_TYPE_IDLE, to IDLE mode.
1114 **                                    NFC_DEACTIVATE_TYPE_SLEEP to SLEEP mode.
1115 **                                    NFC_DEACTIVATE_TYPE_SLEEP_AF to SLEEP_AF
1116 **                                    mode.
1117 **
1118 ** Returns          tNFC_STATUS
1119 **
1120 *******************************************************************************/
1121 extern tNFC_STATUS NFC_Deactivate(tNFC_DEACT_TYPE deactivate_type);
1122 
1123 /*******************************************************************************
1124 **
1125 ** Function         NFC_UpdateRFCommParams
1126 **
1127 ** Description      This function is called to update RF Communication
1128 **                  parameters once the Frame RF Interface has been activated.
1129 **
1130 **                  The response from NFCC is reported by tNFC_RESPONSE_CBACK
1131 **                  as NFC_RF_COMM_PARAMS_UPDATE_REVT.
1132 **
1133 ** Returns          tNFC_STATUS
1134 **
1135 *******************************************************************************/
1136 extern tNFC_STATUS NFC_UpdateRFCommParams(tNFC_RF_COMM_PARAMS* p_params);
1137 
1138 /*******************************************************************************
1139 **
1140 ** Function         NFC_SetPowerOffSleep
1141 **
1142 ** Description      This function closes/opens transport and turns off/on NFCC.
1143 **
1144 ** Returns          tNFC_STATUS
1145 **
1146 *******************************************************************************/
1147 extern tNFC_STATUS NFC_SetPowerOffSleep(bool enable);
1148 
1149 /*******************************************************************************
1150 **
1151 ** Function         NFC_SetPowerSubState
1152 **
1153 ** Description      This function is called to send the power sub state(screen
1154 **                  state) to NFCC. The response from NFCC is reported by
1155 **                  tNFC_RESPONSE_CBACK as NFC_SET_POWER_STATE_REVT.
1156 **
1157 ** Parameters       scree_state
1158 **
1159 ** Returns          tNFC_STATUS
1160 **
1161 *******************************************************************************/
1162 extern tNFC_STATUS NFC_SetPowerSubState(uint8_t screen_state);
1163 
1164 /*******************************************************************************
1165 **
1166 ** Function         NFC_PowerCycleNFCC
1167 **
1168 ** Description      This function turns off and then on NFCC.
1169 **
1170 ** Returns          tNFC_STATUS
1171 **
1172 *******************************************************************************/
1173 extern tNFC_STATUS NFC_PowerCycleNFCC(void);
1174 
1175 /*******************************************************************************
1176 **
1177 ** Function         NFC_SetRouting
1178 **
1179 ** Description      This function is called to configure the CE routing table.
1180 **                  The response from NFCC is reported by tNFC_RESPONSE_CBACK
1181 **                  as NFC_SET_ROUTING_REVT.
1182 **
1183 ** Parameters
1184 **
1185 ** Returns          tNFC_STATUS
1186 **
1187 *******************************************************************************/
1188 extern tNFC_STATUS NFC_SetRouting(bool more, uint8_t num_tlv, uint8_t tlv_size,
1189                                   uint8_t* p_param_tlvs);
1190 
1191 /*******************************************************************************
1192 **
1193 ** Function         NFC_GetRouting
1194 **
1195 ** Description      This function is called to retrieve the CE routing table
1196 **                  from NFCC. The response from NFCC is reported by
1197 **                  tNFC_RESPONSE_CBACK as NFC_GET_ROUTING_REVT.
1198 **
1199 ** Returns          tNFC_STATUS
1200 **
1201 *******************************************************************************/
1202 extern tNFC_STATUS NFC_GetRouting(void);
1203 
1204 /*******************************************************************************
1205 **
1206 ** Function         NFC_RegVSCback
1207 **
1208 ** Description      This function is called to register or de-register a
1209 **                  callback function to receive Proprietary NCI response and
1210 **                  notification events.
1211 **                  The maximum number of callback functions allowed is
1212 **                  NFC_NUM_VS_CBACKS
1213 **
1214 ** Returns          tNFC_STATUS
1215 **
1216 *******************************************************************************/
1217 extern tNFC_STATUS NFC_RegVSCback(bool is_register, tNFC_VS_CBACK* p_cback);
1218 
1219 /*******************************************************************************
1220 **
1221 ** Function         NFC_SendVsCommand
1222 **
1223 ** Description      This function is called to send the given vendor specific
1224 **                  command to NFCC. The response from NFCC is reported to the
1225 **                  given tNFC_VS_CBACK as (oid).
1226 **
1227 ** Parameters       oid - The opcode of the VS command.
1228 **                  p_data - The parameters for the VS command
1229 **
1230 ** Returns          tNFC_STATUS
1231 **
1232 *******************************************************************************/
1233 extern tNFC_STATUS NFC_SendVsCommand(uint8_t oid, NFC_HDR* p_data,
1234                                      tNFC_VS_CBACK* p_cback);
1235 
1236 /*******************************************************************************
1237 **
1238 ** Function         NFC_SendRawVsCommand
1239 **
1240 ** Description      This function is called to send the given raw command to
1241 **                  NFCC. The response from NFCC is reported to the given
1242 **                  tNFC_VS_CBACK.
1243 **
1244 ** Parameters       p_data - The command buffer
1245 **
1246 ** Returns          tNFC_STATUS
1247 **
1248 *******************************************************************************/
1249 extern tNFC_STATUS NFC_SendRawVsCommand(NFC_HDR* p_data,
1250                                         tNFC_VS_CBACK* p_cback);
1251 
1252 /*******************************************************************************
1253 **
1254 ** Function         NFC_TestLoopback
1255 **
1256 ** Description      This function is called to send the given data packet
1257 **                  to NFCC for loopback test.
1258 **                  When loopback data is received from NFCC, tNFC_TEST_CBACK .
1259 **                  reports a NFC_LOOPBACK_TEVT.
1260 **
1261 ** Parameters       p_data - the data packet
1262 **
1263 ** Returns          tNFC_STATUS
1264 **
1265 *******************************************************************************/
1266 extern tNFC_STATUS NFC_TestLoopback(NFC_HDR* p_data);
1267 
1268 /*******************************************************************************
1269 **
1270 ** Function         NFC_ISODEPNakPresCheck
1271 **
1272 ** Description      This function is called to send the ISO DEP nak presence
1273 **                  check cmd to check that the remote end point in RF field.
1274 **
1275 ** Returns          tNFC_STATUS
1276 **
1277 *******************************************************************************/
1278 extern tNFC_STATUS NFC_ISODEPNakPresCheck();
1279 
1280 #if (APPL_DTA_MODE == TRUE)
1281 /*******************************************************************************
1282 **
1283 ** Function         nfc_ncif_getFWVersion
1284 **
1285 ** Description      This function sets the trace level for NFC.  If called with
1286 **                  a value of 0xFF, it simply returns the current trace level.
1287 **
1288 ** Returns          The new or current trace level
1289 **
1290 *******************************************************************************/
1291 extern tNFC_FW_VERSION nfc_ncif_getFWVersion();
1292 #endif
1293 
1294 /*******************************************************************************
1295 **
1296 ** Function         NFC_NfceePLConfig
1297 **
1298 ** Description      This function is called to set the Power and Link Control
1299 **                  to an NFCEE connected to the NFCC.
1300 **                  The response from NFCC is reported by tNFC_RESPONSE_CBACK
1301 **                  as NFC_NFCEE_PL_CONTROL_REVT.
1302 **
1303 ** Parameters       nfcee_id - the NFCEE to activate or de-activate.
1304 **                 pl_config -
1305 **                 NFCEE_PL_CONFIG_NFCC_DECIDES -NFCC decides (default)
1306 **                 NFCEE_PL_CONFIG_PWR_ALWAYS_ON -NFCEE power supply always on
1307 **                 NFCEE_PL_CONFIG_LNK_ON_WHEN_PWR_ON -
1308 **                                     communication link is always active
1309 **                                     when NFCEE is powered on
1310 **                 NFCEE_PL_CONFIG_PWR_LNK_ALWAYS_ON -
1311 **                                     power supply and communication
1312 **                                     link are always on
1313 ** Returns          tNFC_STATUS
1314 **
1315 *******************************************************************************/
1316 extern tNFC_STATUS NFC_NfceePLConfig(uint8_t nfcee_id,
1317                                      tNCI_NFCEE_PL_CONFIG pl_config);
1318 
1319 /*******************************************************************************
1320 **
1321 ** Function         NFC_SetStaticHciCback
1322 **
1323 ** Description      This function to update the data callback function
1324 **                  to receive the data for the static Hci connection id.
1325 **
1326 ** Parameters       p_cback - the connection callback function
1327 **
1328 ** Returns          Nothing
1329 **
1330 *******************************************************************************/
1331 extern void NFC_SetStaticHciCback(tNFC_CONN_CBACK* p_cback);
1332 
1333 /*******************************************************************************
1334 **
1335 ** Function         NFC_GetStatusName
1336 **
1337 ** Description      This function returns the status name.
1338 **
1339 ** NOTE             conditionally compiled to save memory.
1340 **
1341 ** Returns          pointer to the name
1342 **
1343 *******************************************************************************/
1344 extern std::string NFC_GetStatusName(tNFC_STATUS status);
1345 
1346 #endif /* NFC_API_H */
1347