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_CON_DEVICES_LIMIT NCI_PARAM_ID_CON_DEVICES_LIMIT
117 #define NFC_PMID_PA_BAILOUT NCI_PARAM_ID_PA_BAILOUT
118 #define NFC_PMID_PB_AFI NCI_PARAM_ID_PB_AFI
119 #define NFC_PMID_PB_BAILOUT NCI_PARAM_ID_PB_BAILOUT
120 #define NFC_PMID_PB_ATTRIB_PARAM1 NCI_PARAM_ID_PB_ATTRIB_PARAM1
121 #define NFC_PMID_PF_BIT_RATE NCI_PARAM_ID_PF_BIT_RATE
122 #define NFC_PMID_PF_RC NCI_PARAM_ID_PF_RC
123 #define NFC_PMID_PB_H_INFO NCI_PARAM_ID_PB_H_INFO
124 #define NFC_PMID_BITR_NFC_DEP NCI_PARAM_ID_BITR_NFC_DEP
125 #define NFC_PMID_ATR_REQ_GEN_BYTES NCI_PARAM_ID_ATR_REQ_GEN_BYTES
126 #define NFC_PMID_ATR_REQ_CONFIG NCI_PARAM_ID_ATR_REQ_CONFIG
127 #define NFC_PMID_LA_HIST_BY NCI_PARAM_ID_LA_HIST_BY
128 #define NFC_PMID_LA_NFCID1 NCI_PARAM_ID_LA_NFCID1
129 #define NFC_PMID_PI_BIT_RATE NCI_PARAM_ID_PI_BIT_RATE
130 #define NFC_PMID_LA_BIT_FRAME_SDD NCI_PARAM_ID_LA_BIT_FRAME_SDD
131 #define NFC_PMID_LA_PLATFORM_CONFIG NCI_PARAM_ID_LA_PLATFORM_CONFIG
132 #define NFC_PMID_LA_SEL_INFO NCI_PARAM_ID_LA_SEL_INFO
133 #define NFC_PMID_LI_BIT_RATE NCI_PARAM_ID_LI_BIT_RATE
134 #define NFC_PMID_LB_SENSB_INFO NCI_PARAM_ID_LB_SENSB_INFO
135 #define NFC_PMID_LB_PROTOCOL NCI_PARAM_ID_LB_PROTOCOL
136 #define NFC_PMID_LB_H_INFO NCI_PARAM_ID_LB_H_INFO_RSP
137 #define NFC_PMID_LB_NFCID0 NCI_PARAM_ID_LB_NFCID0
138 #define NFC_PMID_LB_APPDATA NCI_PARAM_ID_LB_APPDATA
139 #define NFC_PMID_LB_SFGI NCI_PARAM_ID_LB_SFGI
140 #define NFC_PMID_LB_ADC_FO NCI_PARAM_ID_LB_ADC_FO
141 #define NFC_PMID_LF_T3T_ID1 NCI_PARAM_ID_LF_T3T_ID1
142 #define NFC_PMID_LF_T3T_ID2 NCI_PARAM_ID_LF_T3T_ID2
143 #define NFC_PMID_LF_T3T_ID3 NCI_PARAM_ID_LF_T3T_ID3
144 #define NFC_PMID_LF_T3T_ID4 NCI_PARAM_ID_LF_T3T_ID4
145 #define NFC_PMID_LF_T3T_ID5 NCI_PARAM_ID_LF_T3T_ID5
146 #define NFC_PMID_LF_T3T_ID6 NCI_PARAM_ID_LF_T3T_ID6
147 #define NFC_PMID_LF_T3T_ID7 NCI_PARAM_ID_LF_T3T_ID7
148 #define NFC_PMID_LF_T3T_ID8 NCI_PARAM_ID_LF_T3T_ID8
149 #define NFC_PMID_LF_T3T_ID9 NCI_PARAM_ID_LF_T3T_ID9
150 #define NFC_PMID_LF_T3T_ID10 NCI_PARAM_ID_LF_T3T_ID10
151 #define NFC_PMID_LF_T3T_ID11 NCI_PARAM_ID_LF_T3T_ID11
152 #define NFC_PMID_LF_T3T_ID12 NCI_PARAM_ID_LF_T3T_ID12
153 #define NFC_PMID_LF_T3T_ID13 NCI_PARAM_ID_LF_T3T_ID13
154 #define NFC_PMID_LF_T3T_ID14 NCI_PARAM_ID_LF_T3T_ID14
155 #define NFC_PMID_LF_T3T_ID15 NCI_PARAM_ID_LF_T3T_ID15
156 #define NFC_PMID_LF_T3T_ID16 NCI_PARAM_ID_LF_T3T_ID16
157 #define NFC_PMID_LF_PROTOCOL NCI_PARAM_ID_LF_PROTOCOL
158 #define NFC_PMID_LF_T3T_PMM NCI_PARAM_ID_LF_T3T_PMM
159 #define NFC_PMID_LF_T3T_MAX NCI_PARAM_ID_LF_T3T_MAX
160 #define NFC_PMID_LF_T3T_FLAGS2 NCI_PARAM_ID_LF_T3T_FLAGS2
161 #define NFC_PMID_FWI NCI_PARAM_ID_FWI
162 #define NFC_PMID_LF_CON_BITR_F NCI_PARAM_ID_LF_CON_BITR_F
163 #define NFC_PMID_WT NCI_PARAM_ID_WT
164 #define NFC_PMID_ATR_RES_GEN_BYTES NCI_PARAM_ID_ATR_RES_GEN_BYTES
165 #define NFC_PMID_ATR_RSP_CONFIG NCI_PARAM_ID_ATR_RSP_CONFIG
166 #define NFC_PMID_RF_FIELD_INFO NCI_PARAM_ID_RF_FIELD_INFO
167 #define NFC_PMID_NFC_DEP_OP NCI_PARAM_ID_NFC_DEP_OP
168 #define NFC_PARAM_ID_RF_EE_ACTION NCI_PARAM_ID_RF_EE_ACTION
169 #define NFC_PARAM_ID_ISO_DEP_OP NCI_PARAM_ID_ISO_DEP_OP
170 
171 /* Technology based routing  */
172 #define NFC_ROUTE_TAG_TECH NCI_ROUTE_TAG_TECH
173 /* Protocol based routing  */
174 #define NFC_ROUTE_TAG_PROTO NCI_ROUTE_TAG_PROTO
175 #define NFC_ROUTE_TAG_AID NCI_ROUTE_TAG_AID /* AID routing */
176 /* tag, len, 2 byte value for technology/protocol based routing */
177 #define NFC_ROUTE_TLV_ENTRY_SIZE 4
178 
179 /* For routing */
180 #define NFC_DH_ID NCI_DH_ID /* for DH */
181 /* To identify the loopback test */
182 /* use a proprietary range */
183 #define NFC_TEST_ID NCI_TEST_ID
184 
185 typedef uint8_t tNFC_PMID;
186 #define NFC_TL_SIZE 2
187 #define NFC_SAVED_CMD_SIZE 2
188 
189 typedef tNCI_DISCOVER_MAPS tNFC_DISCOVER_MAPS;
190 typedef tNCI_DISCOVER_PARAMS tNFC_DISCOVER_PARAMS;
191 
192 /* all NFC Manager Callback functions have prototype like void (cback) (uint8_t
193  * event, void *p_data)
194  * tNFC_DATA_CBACK uses connection id as the first parameter; range 0x00-0x0F.
195  * tNFC_DISCOVER_CBACK uses tNFC_DISCOVER_EVT; range  0x4000 ~
196  * tNFC_RESPONSE_CBACK uses tNFC_RESPONSE_EVT; range  0x5000 ~
197  */
198 
199 #define NFC_FIRST_DEVT 0x4000
200 #define NFC_FIRST_REVT 0x5000
201 #define NFC_FIRST_CEVT 0x6000
202 #define NFC_FIRST_TEVT 0x8000
203 
204 /* the events reported on tNFC_RESPONSE_CBACK */
205 enum {
206   NFC_ENABLE_REVT = NFC_FIRST_REVT, /* 0  Enable event                  */
207   NFC_DISABLE_REVT,                 /* 1  Disable event                 */
208   NFC_SET_CONFIG_REVT,              /* 2  Set Config Response           */
209   NFC_GET_CONFIG_REVT,              /* 3  Get Config Response           */
210   NFC_NFCEE_DISCOVER_REVT,          /* 4  Discover NFCEE response       */
211   NFC_NFCEE_INFO_REVT,              /* 5  Discover NFCEE Notification   */
212   NFC_NFCEE_MODE_SET_REVT,          /* 6  NFCEE Mode Set response       */
213   NFC_RF_FIELD_REVT,                /* 7  RF Field information          */
214   NFC_EE_ACTION_REVT,               /* 8  EE Action notification        */
215   NFC_EE_DISCOVER_REQ_REVT,         /* 9  EE Discover Req notification  */
216   NFC_SET_ROUTING_REVT,             /* 10 Configure Routing response    */
217   NFC_GET_ROUTING_REVT,             /* 11 Retrieve Routing response     */
218   NFC_RF_COMM_PARAMS_UPDATE_REVT,   /* 12 RF Communication Param Update */
219   NFC_GEN_ERROR_REVT,               /* 13 generic error notification    */
220   NFC_NFCC_RESTART_REVT,            /* 14 NFCC has been re-initialized  */
221   NFC_NFCC_TIMEOUT_REVT,            /* 15 NFCC is not responding        */
222   NFC_NFCC_TRANSPORT_ERR_REVT,      /* 16 NCI Tranport error            */
223   NFC_NFCC_POWER_OFF_REVT,          /* 17 NFCC turned off               */
224 
225   NFC_FIRST_VS_REVT /* First vendor-specific rsp event  */
226 };
227 typedef uint16_t tNFC_RESPONSE_EVT;
228 
229 enum {
230   NFC_CONN_CREATE_CEVT = NFC_FIRST_CEVT, /* 0  Conn Create Response          */
231   NFC_CONN_CLOSE_CEVT,                   /* 1  Conn Close Response           */
232   NFC_DEACTIVATE_CEVT,                   /* 2  Deactivate response/notificatn*/
233   NFC_DATA_CEVT,                         /* 3  Data                          */
234   NFC_ERROR_CEVT,                        /* 4  generic or interface error    */
235   NFC_DATA_START_CEVT /* 5  received the first fragment on RF link */
236 };
237 typedef uint16_t tNFC_CONN_EVT;
238 
239 #define NFC_NFCC_INFO_LEN 4
240 #ifndef NFC_NFCC_MAX_NUM_VS_INTERFACE
241 #define NFC_NFCC_MAX_NUM_VS_INTERFACE 5
242 #endif
243 typedef struct {
244   tNFC_STATUS status;                   /* The event status.                */
245   uint8_t nci_version;                  /* the NCI version of NFCC          */
246   uint8_t max_conn;                     /* max number of connections by NFCC*/
247   uint32_t nci_features;                /* the NCI features of NFCC         */
248   uint16_t nci_interfaces;              /* the NCI interfaces of NFCC       */
249   uint16_t max_ce_table;                /* the max routing table size       */
250   uint16_t max_param_size;              /* Max Size for Large Parameters    */
251   uint8_t manufacture_id;               /* the Manufacture ID for NFCC      */
252   uint8_t nfcc_info[NFC_NFCC_INFO_LEN]; /* the Manufacture Info for NFCC      */
253   uint8_t vs_interface
254       [NFC_NFCC_MAX_NUM_VS_INTERFACE]; /* the NCI VS interfaces of NFCC    */
255 } tNFC_ENABLE_REVT;
256 
257 #define NFC_MAX_NUM_IDS 125
258 /* the data type associated with NFC_SET_CONFIG_REVT */
259 typedef struct {
260   tNFC_STATUS status;                 /* The event status.                */
261   uint8_t num_param_id;               /* Number of rejected NCI Param ID  */
262   uint8_t param_ids[NFC_MAX_NUM_IDS]; /* NCI Param ID          */
263 } tNFC_SET_CONFIG_REVT;
264 
265 /* the data type associated with NFC_GET_CONFIG_REVT */
266 typedef struct {
267   tNFC_STATUS status;    /* The event status.    */
268   uint16_t tlv_size;     /* The length of TLV    */
269   uint8_t* p_param_tlvs; /* TLV                  */
270 } tNFC_GET_CONFIG_REVT;
271 
272 /* the data type associated with NFC_NFCEE_DISCOVER_REVT */
273 typedef struct {
274   tNFC_STATUS status; /* The event status.    */
275   uint8_t num_nfcee;  /* The number of NFCEE  */
276 } tNFC_NFCEE_DISCOVER_REVT;
277 
278 #define NFC_NFCEE_INTERFACE_APDU NCI_NFCEE_INTERFACE_APDU
279 #define NFC_NFCEE_INTERFACE_HCI_ACCESS NCI_NFCEE_INTERFACE_HCI_ACCESS
280 #define NFC_NFCEE_INTERFACE_T3T NCI_NFCEE_INTERFACE_T3T
281 #define NFC_NFCEE_INTERFACE_TRANSPARENT NCI_NFCEE_INTERFACE_TRANSPARENT
282 #define NFC_NFCEE_INTERFACE_PROPRIETARY NCI_NFCEE_INTERFACE_PROPRIETARY
283 typedef uint8_t tNFC_NFCEE_INTERFACE;
284 
285 #define NFC_NFCEE_TAG_HW_ID NCI_NFCEE_TAG_HW_ID
286 #define NFC_NFCEE_TAG_ATR_BYTES NCI_NFCEE_TAG_ATR_BYTES
287 #define NFC_NFCEE_TAG_T3T_INFO NCI_NFCEE_TAG_T3T_INFO
288 #define NFC_NFCEE_TAG_HCI_HOST_ID NCI_NFCEE_TAG_HCI_HOST_ID
289 typedef uint8_t tNFC_NFCEE_TAG;
290 /* additional NFCEE Info */
291 typedef struct {
292   tNFC_NFCEE_TAG tag;
293   uint8_t len;
294   uint8_t info[NFC_MAX_EE_INFO];
295 } tNFC_NFCEE_TLV;
296 
297 /* NFCEE connected and inactive */
298 #define NFC_NFCEE_STATUS_INACTIVE NCI_NFCEE_STS_CONN_INACTIVE
299 /* NFCEE connected and active   */
300 #define NFC_NFCEE_STATUS_ACTIVE NCI_NFCEE_STS_CONN_ACTIVE
301 /* NFCEE removed                */
302 #define NFC_NFCEE_STATUS_REMOVED NCI_NFCEE_STS_REMOVED
303 /* the data type associated with NFC_NFCEE_INFO_REVT */
304 typedef struct {
305   tNFC_STATUS status;    /* The event status - place holder  */
306   uint8_t nfcee_id;      /* NFCEE ID                         */
307   uint8_t ee_status;     /* The NFCEE status.                */
308   uint8_t num_interface; /* number of NFCEE interfaces       */
309   uint8_t ee_interface[NFC_MAX_EE_INTERFACE]; /* NFCEE interface       */
310   uint8_t num_tlvs;                       /* number of TLVs                   */
311   tNFC_NFCEE_TLV ee_tlv[NFC_MAX_EE_TLVS]; /* The TLVs associated with NFCEE   */
312 } tNFC_NFCEE_INFO_REVT;
313 
314 #define NFC_MODE_ACTIVATE NCI_NFCEE_MD_ACTIVATE
315 #define NFC_MODE_DEACTIVATE NCI_NFCEE_MD_DEACTIVATE
316 typedef uint8_t tNFC_NFCEE_MODE;
317 /* the data type associated with NFC_NFCEE_MODE_SET_REVT */
318 typedef struct {
319   tNFC_STATUS status;   /* The event status.*/
320   uint8_t nfcee_id;     /* NFCEE ID         */
321   tNFC_NFCEE_MODE mode; /* NFCEE mode       */
322 } tNFC_NFCEE_MODE_SET_REVT;
323 
324 #define NFC_MAX_AID_LEN NCI_MAX_AID_LEN /* 16 */
325 
326 /* the data type associated with NFC_CE_GET_ROUTING_REVT */
327 typedef struct {
328   tNFC_STATUS status; /* The event status                 */
329   uint8_t nfcee_id;   /* NFCEE ID                         */
330   uint8_t num_tlvs;   /* number of TLVs                   */
331   uint8_t tlv_size;   /* the total len of all TLVs        */
332   uint8_t param_tlvs[NFC_MAX_EE_TLV_SIZE]; /* the TLVs         */
333 } tNFC_GET_ROUTING_REVT;
334 
335 /* the data type associated with NFC_CONN_CREATE_CEVT */
336 typedef struct {
337   tNFC_STATUS status; /* The event status                 */
338   uint8_t dest_type;  /* the destination type             */
339   uint8_t id;         /* NFCEE ID  or RF Discovery ID     */
340   uint8_t buff_size;  /* The max buffer size              */
341   uint8_t num_buffs;  /* The number of buffers            */
342 } tNFC_CONN_CREATE_CEVT;
343 
344 /* the data type associated with NFC_CONN_CLOSE_CEVT */
345 typedef struct {
346   tNFC_STATUS status; /* The event status                 */
347 } tNFC_CONN_CLOSE_CEVT;
348 
349 /* the data type associated with NFC_DATA_CEVT */
350 typedef struct {
351   tNFC_STATUS status; /* The event status                 */
352   NFC_HDR* p_data;    /* The received Data                */
353 } tNFC_DATA_CEVT;
354 
355 /* RF Field Status */
356 /* No field generated by remote device  */
357 #define NFC_RF_STS_NO_REMOTE NCI_RF_STS_NO_REMOTE
358 /* field generated by remote device     */
359 #define NFC_RF_STS_REMOTE NCI_RF_STS_REMOTE
360 typedef uint8_t tNFC_RF_STS;
361 
362 /* RF Field Technologies */
363 #define NFC_RF_TECHNOLOGY_A NCI_RF_TECHNOLOGY_A
364 #define NFC_RF_TECHNOLOGY_B NCI_RF_TECHNOLOGY_B
365 #define NFC_RF_TECHNOLOGY_F NCI_RF_TECHNOLOGY_F
366 #define NFC_RF_TECHNOLOGY_15693 NCI_RF_TECHNOLOGY_15693
367 typedef uint8_t tNFC_RF_TECH;
368 
369 /* Supported Protocols */
370 #define NFC_PROTOCOL_UNKNOWN NCI_PROTOCOL_UNKNOWN /* Unknown */
371 /* Type1Tag    - NFC-A            */
372 #define NFC_PROTOCOL_T1T NCI_PROTOCOL_T1T
373 /* Type2Tag    - NFC-A            */
374 #define NFC_PROTOCOL_T2T NCI_PROTOCOL_T2T
375 /* Type3Tag    - NFC-F            */
376 #define NFC_PROTOCOL_T3T NCI_PROTOCOL_T3T
377 /* Type 4A,4B  - NFC-A or NFC-B   */
378 #define NFC_PROTOCOL_ISO_DEP NCI_PROTOCOL_ISO_DEP
379 /* NFCDEP/LLCP - NFC-A or NFC-F       */
380 #define NFC_PROTOCOL_NFC_DEP NCI_PROTOCOL_NFC_DEP
381 #define NFC_PROTOCOL_MIFARE NCI_PROTOCOL_MIFARE
382 #define NFC_PROTOCOL_B_PRIME NCI_PROTOCOL_B_PRIME
383 #define NFC_PROTOCOL_15693 NCI_PROTOCOL_15693
384 #define NFC_PROTOCOL_KOVIO NCI_PROTOCOL_KOVIO
385 typedef uint8_t tNFC_PROTOCOL;
386 
387 /* Discovery Types/Detected Technology and Mode */
388 #define NFC_DISCOVERY_TYPE_POLL_A NCI_DISCOVERY_TYPE_POLL_A
389 #define NFC_DISCOVERY_TYPE_POLL_B NCI_DISCOVERY_TYPE_POLL_B
390 #define NFC_DISCOVERY_TYPE_POLL_F NCI_DISCOVERY_TYPE_POLL_F
391 #define NFC_DISCOVERY_TYPE_POLL_A_ACTIVE NCI_DISCOVERY_TYPE_POLL_A_ACTIVE
392 #define NFC_DISCOVERY_TYPE_POLL_F_ACTIVE NCI_DISCOVERY_TYPE_POLL_F_ACTIVE
393 #define NFC_DISCOVERY_TYPE_POLL_ISO15693 NCI_DISCOVERY_TYPE_POLL_ISO15693
394 #define NFC_DISCOVERY_TYPE_POLL_B_PRIME NCI_DISCOVERY_TYPE_POLL_B_PRIME
395 #define NFC_DISCOVERY_TYPE_POLL_KOVIO NCI_DISCOVERY_TYPE_POLL_KOVIO
396 #define NFC_DISCOVERY_TYPE_LISTEN_A NCI_DISCOVERY_TYPE_LISTEN_A
397 #define NFC_DISCOVERY_TYPE_LISTEN_B NCI_DISCOVERY_TYPE_LISTEN_B
398 #define NFC_DISCOVERY_TYPE_LISTEN_F NCI_DISCOVERY_TYPE_LISTEN_F
399 #define NFC_DISCOVERY_TYPE_LISTEN_A_ACTIVE NCI_DISCOVERY_TYPE_LISTEN_A_ACTIVE
400 #define NFC_DISCOVERY_TYPE_LISTEN_F_ACTIVE NCI_DISCOVERY_TYPE_LISTEN_F_ACTIVE
401 #define NFC_DISCOVERY_TYPE_LISTEN_ISO15693 NCI_DISCOVERY_TYPE_LISTEN_ISO15693
402 #define NFC_DISCOVERY_TYPE_LISTEN_B_PRIME NCI_DISCOVERY_TYPE_LISTEN_B_PRIME
403 typedef uint8_t tNFC_DISCOVERY_TYPE;
404 typedef uint8_t tNFC_RF_TECH_N_MODE;
405 
406 /* Select Response codes */
407 #define NFC_SEL_RES_NFC_FORUM_T2T 0x00
408 #define NFC_SEL_RES_MF_CLASSIC 0x08
409 
410 /* Bit Rates */
411 #define NFC_BIT_RATE_106 NCI_BIT_RATE_106   /* 106 kbit/s */
412 #define NFC_BIT_RATE_212 NCI_BIT_RATE_212   /* 212 kbit/s */
413 #define NFC_BIT_RATE_424 NCI_BIT_RATE_424   /* 424 kbit/s */
414 #define NFC_BIT_RATE_848 NCI_BIT_RATE_848   /* 848 Kbit/s */
415 #define NFC_BIT_RATE_1696 NCI_BIT_RATE_1696 /* 1696 Kbit/s*/
416 #define NFC_BIT_RATE_3392 NCI_BIT_RATE_3392 /* 3392 Kbit/s*/
417 #define NFC_BIT_RATE_6784 NCI_BIT_RATE_6784 /* 6784 Kbit/s*/
418 typedef uint8_t tNFC_BIT_RATE;
419 
420 /**********************************************
421  * Interface Types
422  **********************************************/
423 #define NFC_INTERFACE_EE_DIRECT_RF NCI_INTERFACE_EE_DIRECT_RF
424 #define NFC_INTERFACE_FRAME NCI_INTERFACE_FRAME
425 #define NFC_INTERFACE_ISO_DEP NCI_INTERFACE_ISO_DEP
426 #define NFC_INTERFACE_NDEF NCI_INTERFACE_NDEF
427 #define NFC_INTERFACE_NFC_DEP NCI_INTERFACE_NFC_DEP
428 #define NFC_INTERFACE_LLCP_LOW NCI_INTERFACE_LLCP_LOW
429 #define NFC_INTERFACE_LLCP_HIGH NCI_INTERFACE_LLCP_HIGH
430 #define NFC_INTERFACE_VS_T2T_CE NCI_INTERFACE_VS_T2T_CE
431 #define NFC_INTERFACE_MIFARE NCI_INTERFACE_VS_MIFARE
432 typedef tNCI_INTF_TYPE tNFC_INTF_TYPE;
433 
434 /**********************************************
435  *  Deactivation Type
436  **********************************************/
437 #define NFC_DEACTIVATE_TYPE_IDLE NCI_DEACTIVATE_TYPE_IDLE
438 #define NFC_DEACTIVATE_TYPE_SLEEP NCI_DEACTIVATE_TYPE_SLEEP
439 #define NFC_DEACTIVATE_TYPE_SLEEP_AF NCI_DEACTIVATE_TYPE_SLEEP_AF
440 #define NFC_DEACTIVATE_TYPE_DISCOVERY NCI_DEACTIVATE_TYPE_DISCOVERY
441 typedef uint8_t tNFC_DEACT_TYPE;
442 
443 /**********************************************
444  *  Deactivation Reasons
445  **********************************************/
446 #define NFC_DEACTIVATE_REASON_DH_REQ NCI_DEACTIVATE_REASON_DH_REQ
447 #define NFC_DEACTIVATE_REASON_ENDPOINT_REQ NCI_DEACTIVATE_REASON_ENDPOINT_REQ
448 #define NFC_DEACTIVATE_REASON_RF_LINK_LOSS NCI_DEACTIVATE_REASON_RF_LINK_LOSS
449 #define NFC_DEACTIVATE_REASON_NFCB_BAD_AFI NCI_DEACTIVATE_REASON_NFCB_BAD_AFI
450 typedef uint8_t tNFC_DEACT_REASON;
451 
452 /* the data type associated with NFC_RF_FIELD_REVT */
453 typedef struct {
454   tNFC_STATUS status;   /* The event status - place holder. */
455   tNFC_RF_STS rf_field; /* RF Field Status                  */
456 } tNFC_RF_FIELD_REVT;
457 
458 #define NFC_MAX_APP_DATA_LEN 40
459 typedef struct {
460   uint8_t len_aid;              /* length of application id */
461   uint8_t aid[NFC_MAX_AID_LEN]; /* application id           */
462 } tNFC_AID;
463 typedef struct {
464   uint8_t len_aid;                    /* length of application id */
465   uint8_t aid[NFC_MAX_AID_LEN];       /* application id           */
466   uint8_t len_data;                   /* len of application data  */
467   uint8_t data[NFC_MAX_APP_DATA_LEN]; /* application data    */
468 } tNFC_APP_INIT;
469 
470 /* ISO 7816-4 SELECT command */
471 #define NFC_EE_TRIG_SELECT NCI_EE_TRIG_7816_SELECT
472 /* RF Protocol changed       */
473 #define NFC_EE_TRIG_RF_PROTOCOL NCI_EE_TRIG_RF_PROTOCOL
474 /* RF Technology changed     */
475 #define NFC_EE_TRIG_RF_TECHNOLOGY NCI_EE_TRIG_RF_TECHNOLOGY
476 /* Application initiation    */
477 #define NFC_EE_TRIG_APP_INIT NCI_EE_TRIG_APP_INIT
478 typedef uint8_t tNFC_EE_TRIGGER;
479 typedef struct {
480   tNFC_EE_TRIGGER trigger; /* the trigger of this event        */
481   union {
482     tNFC_PROTOCOL protocol;
483     tNFC_RF_TECH technology;
484     tNFC_AID aid;
485     tNFC_APP_INIT app_init;
486   } param; /* Discovery Type specific parameters */
487 } tNFC_ACTION_DATA;
488 
489 /* the data type associated with NFC_EE_ACTION_REVT */
490 typedef struct {
491   tNFC_STATUS status;        /* The event status - place holder  */
492   uint8_t nfcee_id;          /* NFCEE ID                         */
493   tNFC_ACTION_DATA act_data; /* data associated /w the action    */
494 } tNFC_EE_ACTION_REVT;
495 
496 #define NFC_EE_DISC_OP_ADD 0
497 #define NFC_EE_DISC_OP_REMOVE 1
498 typedef uint8_t tNFC_EE_DISC_OP;
499 typedef struct {
500   tNFC_EE_DISC_OP op;              /* add or remove this entry         */
501   uint8_t nfcee_id;                /* NFCEE ID                         */
502   tNFC_RF_TECH_N_MODE tech_n_mode; /* Discovery Technology and Mode    */
503   tNFC_PROTOCOL protocol;          /* NFC protocol                     */
504 } tNFC_EE_DISCOVER_INFO;
505 
506 #ifndef NFC_MAX_EE_DISC_ENTRIES
507 #define NFC_MAX_EE_DISC_ENTRIES 6
508 #endif
509 /* T, L, V(NFCEE ID, TechnMode, Protocol) */
510 #define NFC_EE_DISCOVER_ENTRY_LEN 5
511 #define NFC_EE_DISCOVER_INFO_LEN 3 /* NFCEE ID, TechnMode, Protocol */
512 /* the data type associated with NFC_EE_DISCOVER_REQ_REVT */
513 typedef struct {
514   tNFC_STATUS status; /* The event status - place holder  */
515   uint8_t num_info;   /* number of entries in info[]      */
516   tNFC_EE_DISCOVER_INFO
517       info[NFC_MAX_EE_DISC_ENTRIES]; /* discovery request from NFCEE */
518 } tNFC_EE_DISCOVER_REQ_REVT;
519 
520 typedef union {
521   tNFC_STATUS status; /* The event status. */
522   tNFC_ENABLE_REVT enable;
523   tNFC_SET_CONFIG_REVT set_config;
524   tNFC_GET_CONFIG_REVT get_config;
525   tNFC_NFCEE_DISCOVER_REVT nfcee_discover;
526   tNFC_NFCEE_INFO_REVT nfcee_info;
527   tNFC_NFCEE_MODE_SET_REVT mode_set;
528   tNFC_RF_FIELD_REVT rf_field;
529   tNFC_STATUS cfg_routing;
530   tNFC_GET_ROUTING_REVT get_routing;
531   tNFC_EE_ACTION_REVT ee_action;
532   tNFC_EE_DISCOVER_REQ_REVT ee_discover_req;
533   void* p_vs_evt_data;
534 } tNFC_RESPONSE;
535 
536 /*************************************
537 **  RESPONSE Callback Functions
538 **************************************/
539 typedef void(tNFC_RESPONSE_CBACK)(tNFC_RESPONSE_EVT event,
540                                   tNFC_RESPONSE* p_data);
541 
542 /* The events reported on tNFC_VS_CBACK */
543 /* The event is (NCI_RSP_BIT|oid) for response and (NCI_NTF_BIT|oid) for
544  * notification*/
545 
546 typedef uint8_t tNFC_VS_EVT;
547 
548 /*************************************
549 **  Proprietary (Vendor Specific) Callback Functions
550 **************************************/
551 typedef void(tNFC_VS_CBACK)(tNFC_VS_EVT event, uint16_t data_len,
552                             uint8_t* p_data);
553 
554 /* the events reported on tNFC_DISCOVER_CBACK */
555 enum {
556   NFC_START_DEVT = NFC_FIRST_DEVT, /* Status of NFC_DiscoveryStart     */
557   NFC_MAP_DEVT,                    /* Status of NFC_DiscoveryMap       */
558   NFC_RESULT_DEVT,                 /* The responses from remote device */
559   NFC_SELECT_DEVT,                 /* Status of NFC_DiscoverySelect    */
560   NFC_ACTIVATE_DEVT,               /* RF interface is activated        */
561   NFC_DEACTIVATE_DEVT              /* Status of RF deactivation        */
562 };
563 typedef uint16_t tNFC_DISCOVER_EVT;
564 
565 /* the data type associated with NFC_START_DEVT */
566 typedef tNFC_STATUS tNFC_START_DEVT;
567 
568 typedef tNCI_RF_PA_PARAMS tNFC_RF_PA_PARAMS;
569 #define NFC_MAX_SENSB_RES_LEN NCI_MAX_SENSB_RES_LEN
570 #define NFC_NFCID0_MAX_LEN 4
571 typedef struct {
572   uint8_t sensb_res_len; /* Length of SENSB_RES Response (Byte 2 - Byte 12 or
573                             13) Available after Technology Detection */
574   uint8_t sensb_res[NFC_MAX_SENSB_RES_LEN]; /* SENSB_RES Response (ATQ) */
575   uint8_t nfcid0[NFC_NFCID0_MAX_LEN];
576 } tNFC_RF_PB_PARAMS;
577 
578 #define NFC_MAX_SENSF_RES_LEN NCI_MAX_SENSF_RES_LEN
579 #define NFC_NFCID2_LEN NCI_NFCID2_LEN
580 typedef struct {
581   uint8_t bit_rate;      /* NFC_BIT_RATE_212 or NFC_BIT_RATE_424 */
582   uint8_t sensf_res_len; /* Length of SENSF_RES Response (Byte 2 - Byte 17 or
583                             19) Available after Technology Detection */
584   uint8_t sensf_res[NFC_MAX_SENSF_RES_LEN]; /* SENSB_RES Response */
585   uint8_t nfcid2[NFC_NFCID2_LEN]; /* NFCID2 generated by the Local NFCC for
586                                      NFC-DEP Protocol.Available for Frame
587                                      Interface  */
588   uint8_t mrti_check;
589   uint8_t mrti_update;
590 } tNFC_RF_PF_PARAMS;
591 
592 typedef tNCI_RF_LF_PARAMS tNFC_RF_LF_PARAMS;
593 
594 #define NFC_ISO15693_UID_LEN 8
595 typedef struct {
596   uint8_t flag;
597   uint8_t dsfid;
598   uint8_t uid[NFC_ISO15693_UID_LEN];
599 } tNFC_RF_PISO15693_PARAMS;
600 
601 #ifndef NFC_KOVIO_MAX_LEN
602 #define NFC_KOVIO_MAX_LEN 32
603 #endif
604 typedef struct {
605   uint8_t uid_len;
606   uint8_t uid[NFC_KOVIO_MAX_LEN];
607 } tNFC_RF_PKOVIO_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_TECH_PARAMU;
617 
618 typedef struct {
619   tNFC_DISCOVERY_TYPE mode;
620   tNFC_RF_TECH_PARAMU param;
621 } tNFC_RF_TECH_PARAMS;
622 
623 /* the data type associated with NFC_RESULT_DEVT */
624 typedef struct {
625   tNFC_STATUS status;                /* The event status - place holder.  */
626   uint8_t rf_disc_id;                /* RF Discovery ID                   */
627   uint8_t protocol;                  /* supported protocol                */
628   tNFC_RF_TECH_PARAMS rf_tech_param; /* RF technology parameters          */
629   uint8_t more;                      /* 0: last, 1: last (limit), 2: more */
630 } tNFC_RESULT_DEVT;
631 
632 /* the data type associated with NFC_SELECT_DEVT */
633 typedef tNFC_STATUS tNFC_SELECT_DEVT;
634 
635 /* the data type associated with NFC_STOP_DEVT */
636 typedef tNFC_STATUS tNFC_STOP_DEVT;
637 
638 #define NFC_MAX_ATS_LEN NCI_MAX_ATS_LEN
639 #define NFC_MAX_HIS_BYTES_LEN NCI_MAX_HIS_BYTES_LEN
640 #define NFC_MAX_GEN_BYTES_LEN NCI_MAX_GEN_BYTES_LEN
641 
642 typedef struct {
643   uint8_t ats_res_len;              /* Length of ATS RES                */
644   uint8_t ats_res[NFC_MAX_ATS_LEN]; /* ATS RES                          */
645   bool nad_used;                    /* NAD is used or not               */
646   uint8_t fwi;                      /* Frame Waiting time Integer       */
647   uint8_t sfgi;                     /* Start-up Frame Guard time Integer*/
648   uint8_t his_byte_len;             /* len of historical bytes          */
649   uint8_t his_byte[NFC_MAX_HIS_BYTES_LEN]; /* historical bytes             */
650 } tNFC_INTF_PA_ISO_DEP;
651 
652 typedef struct { uint8_t rats; /* RATS */ } tNFC_INTF_LA_ISO_DEP;
653 
654 typedef struct {
655   uint8_t atr_res_len;                      /* Length of ATR_RES            */
656   uint8_t atr_res[NFC_MAX_ATS_LEN];         /* ATR_RES (Byte 3 - Byte 17+n) */
657   uint8_t max_payload_size;                 /* 64, 128, 192 or 254          */
658   uint8_t gen_bytes_len;                    /* len of general bytes         */
659   uint8_t gen_bytes[NFC_MAX_GEN_BYTES_LEN]; /* general bytes           */
660   uint8_t
661       waiting_time; /* WT -> Response Waiting Time RWT = (256 x 16/fC) x 2WT */
662 } tNFC_INTF_PA_NFC_DEP;
663 
664 /* Note: keep tNFC_INTF_PA_NFC_DEP data member in the same order as
665  * tNFC_INTF_LA_NFC_DEP */
666 typedef struct {
667   uint8_t atr_req_len;                      /* Length of ATR_REQ            */
668   uint8_t atr_req[NFC_MAX_ATS_LEN];         /* ATR_REQ (Byte 3 - Byte 18+n) */
669   uint8_t max_payload_size;                 /* 64, 128, 192 or 254          */
670   uint8_t gen_bytes_len;                    /* len of general bytes         */
671   uint8_t gen_bytes[NFC_MAX_GEN_BYTES_LEN]; /* general bytes           */
672 } tNFC_INTF_LA_NFC_DEP;
673 typedef tNFC_INTF_LA_NFC_DEP tNFC_INTF_LF_NFC_DEP;
674 typedef tNFC_INTF_PA_NFC_DEP tNFC_INTF_PF_NFC_DEP;
675 
676 #define NFC_MAX_ATTRIB_LEN NCI_MAX_ATTRIB_LEN
677 
678 typedef struct {
679   uint8_t attrib_res_len;                 /* Length of ATTRIB RES      */
680   uint8_t attrib_res[NFC_MAX_ATTRIB_LEN]; /* ATTRIB RES                */
681   uint8_t hi_info_len;                    /* len of Higher layer Info  */
682   uint8_t hi_info[NFC_MAX_GEN_BYTES_LEN]; /* Higher layer Info         */
683   uint8_t mbli;                           /* Maximum buffer length.    */
684 } tNFC_INTF_PB_ISO_DEP;
685 
686 typedef struct {
687   uint8_t attrib_req_len;                 /* Length of ATTRIB REQ      */
688   uint8_t attrib_req[NFC_MAX_ATTRIB_LEN]; /* ATTRIB REQ (Byte 2 - 10+k)*/
689   uint8_t hi_info_len;                    /* len of Higher layer Info  */
690   uint8_t hi_info[NFC_MAX_GEN_BYTES_LEN]; /* Higher layer Info         */
691   uint8_t nfcid0[NFC_NFCID0_MAX_LEN];     /* NFCID0                    */
692 } tNFC_INTF_LB_ISO_DEP;
693 
694 #ifndef NFC_MAX_RAW_PARAMS
695 #define NFC_MAX_RAW_PARAMS 16
696 #endif
697 #define NFC_MAX_RAW_PARAMS 16
698 typedef struct {
699   uint8_t param_len;
700   uint8_t param[NFC_MAX_RAW_PARAMS];
701 } tNFC_INTF_FRAME;
702 
703 typedef struct {
704   tNFC_INTF_TYPE type; /* Interface Type  1 Byte  See Table 67 */
705   union {
706     tNFC_INTF_LA_ISO_DEP la_iso;
707     tNFC_INTF_PA_ISO_DEP pa_iso;
708     tNFC_INTF_LB_ISO_DEP lb_iso;
709     tNFC_INTF_PB_ISO_DEP pb_iso;
710     tNFC_INTF_LA_NFC_DEP la_nfc;
711     tNFC_INTF_PA_NFC_DEP pa_nfc;
712     tNFC_INTF_LF_NFC_DEP lf_nfc;
713     tNFC_INTF_PF_NFC_DEP pf_nfc;
714     tNFC_INTF_FRAME frame;
715   } intf_param; /* Activation Parameters   0 - n Bytes */
716 } tNFC_INTF_PARAMS;
717 
718 /* the data type associated with NFC_ACTIVATE_DEVT */
719 typedef struct {
720   uint8_t rf_disc_id;                /* RF Discovery ID          */
721   tNFC_PROTOCOL protocol;            /* supported protocol       */
722   tNFC_RF_TECH_PARAMS rf_tech_param; /* RF technology parameters */
723   tNFC_DISCOVERY_TYPE data_mode;     /* for future Data Exchange */
724   tNFC_BIT_RATE tx_bitrate;          /* Data Exchange Tx Bitrate */
725   tNFC_BIT_RATE rx_bitrate;          /* Data Exchange Rx Bitrate */
726   tNFC_INTF_PARAMS intf_param;       /* interface type and params*/
727 } tNFC_ACTIVATE_DEVT;
728 
729 /* the data type associated with NFC_DEACTIVATE_DEVT and NFC_DEACTIVATE_CEVT */
730 typedef struct {
731   tNFC_STATUS status;   /* The event status.        */
732   tNFC_DEACT_TYPE type; /* De-activate type         */
733   bool is_ntf;          /* TRUE, if deactivate notif*/
734 } tNFC_DEACTIVATE_DEVT;
735 
736 typedef union {
737   tNFC_STATUS status; /* The event status.        */
738   tNFC_START_DEVT start;
739   tNFC_RESULT_DEVT result;
740   tNFC_SELECT_DEVT select;
741   tNFC_STOP_DEVT stop;
742   tNFC_ACTIVATE_DEVT activate;
743   tNFC_DEACTIVATE_DEVT deactivate;
744 } tNFC_DISCOVER;
745 
746 /* Min TR0 indicates to tag the min delay before responding after the end of
747  * command */
748 #define NFC_RF_PARAM_MIN_TR0_DEFAULT 0x00
749 #define NFC_RF_PARAM_MIN_TR0_48X 0x01 /* 48 x 16/fc */
750 #define NFC_RF_PARAM_MIN_TR0_16X 0x02 /* 16 x 16/fc */
751 
752 /* Min TR1 indicates to tag the min delay between subcarrier modulation and data
753  * transmission */
754 #define NFC_RF_PARAM_MIN_TR1_DEFAULT 0x00
755 #define NFC_RF_PARAM_MIN_TR1_64X 0x01 /* 64 x 16/fc */
756 #define NFC_RF_PARAM_MIN_TR1_16X 0x02 /* 16 x 16/fc */
757 
758 /* Min TR2 indicates to RW the min delay between EoS of tag and SoS of RW */
759 #define NFC_RF_PARAM_MIN_TR2_1792 0x00 /* 1792/fc (10etu + 32/fc) */
760 #define NFC_RF_PARAM_MIN_TR2_3328 0x01 /* 3328/fc (10etu + 128/fc) */
761 #define NFC_RF_PARAM_MIN_TR2_5376 0x02 /* 5376/fc (10etu + 256/fc) */
762 #define NFC_RF_PARAM_MIN_TR2_9472 0x03 /* 9472/fc (10etu + 512/fc) */
763 
764 #define NFC_RF_PARAM_EOS_REQUIRED 0x00     /* EoS required */
765 #define NFC_RF_PARAM_EOS_NOT_REQUIRED 0x01 /* EoS not required */
766 
767 #define NFC_RF_PARAM_SOS_REQUIRED 0x00     /* SoS required */
768 #define NFC_RF_PARAM_SOS_NOT_REQUIRED 0x01 /* SoS not required */
769 
770 typedef struct {
771   bool include_rf_tech_mode; /* TRUE if including RF Tech and Mode update    */
772   tNFC_RF_TECH_N_MODE rf_tech_n_mode; /* RF tech and mode */
773   bool include_tx_bit_rate;  /* TRUE if including Tx bit rate update         */
774   tNFC_BIT_RATE tx_bit_rate; /* Transmit Bit Rate                            */
775   bool include_rx_bit_rate;  /* TRUE if including Rx bit rate update         */
776   tNFC_BIT_RATE rx_bit_rate; /* Receive Bit Rate                             */
777   bool include_nfc_b_config; /* TRUE if including NFC-B data exchange config */
778   uint8_t min_tr0;           /* Minimun TR0                                  */
779   uint8_t min_tr1;           /* Minimun TR1                                  */
780   uint8_t suppression_eos;   /* Suppression of EoS                           */
781   uint8_t suppression_sos;   /* Suppression of SoS                           */
782   uint8_t min_tr2;           /* Minimun TR1                                  */
783 } tNFC_RF_COMM_PARAMS;
784 
785 /*************************************
786 **  DISCOVER Callback Functions
787 **************************************/
788 typedef void(tNFC_DISCOVER_CBACK)(tNFC_DISCOVER_EVT event,
789                                   tNFC_DISCOVER* p_data);
790 
791 /* the events reported on tNFC_TEST_CBACK */
792 enum {
793   NFC_LOOPBACK_TEVT = NFC_FIRST_TEVT, /* 0  Loopback test             */
794   NFC_RF_CONTROL_TEVT,                /* 1  RF control Test response  */
795   NFC_RF_FIELD_DONE_TEVT              /* 1  RF control Test notificatn*/
796 };
797 typedef uint16_t tNFC_TEST_EVT;
798 
799 /* the data type associated with NFC_LOOPBACK_TEVT */
800 typedef struct {
801   tNFC_STATUS status; /* The event status.            */
802   NFC_HDR* p_data;    /* The loop back data from NFCC */
803 } tNFC_LOOPBACK_TEVT;
804 
805 /* the data type associated with NFC_RF_CONTROL_TEVT */
806 typedef tNFC_STATUS tNFC_RF_CONTROL_TEVT;
807 
808 typedef union {
809   tNFC_STATUS status; /* The event status.            */
810   tNFC_LOOPBACK_TEVT loop_back;
811   tNFC_RF_CONTROL_TEVT rf_control;
812 } tNFC_TEST;
813 
814 /*************************************
815 **  TEST Callback Functions
816 **************************************/
817 typedef void(tNFC_TEST_CBACK)(tNFC_TEST_EVT event, tNFC_TEST* p_data);
818 
819 typedef tNFC_DEACTIVATE_DEVT tNFC_DEACTIVATE_CEVT;
820 typedef union {
821   tNFC_STATUS status; /* The event status. */
822   tNFC_CONN_CREATE_CEVT conn_create;
823   tNFC_CONN_CLOSE_CEVT conn_close;
824   tNFC_DEACTIVATE_CEVT deactivate;
825   tNFC_DATA_CEVT data;
826 } tNFC_CONN;
827 
828 /*************************************
829 **  Data Callback Functions
830 **************************************/
831 typedef void(tNFC_CONN_CBACK)(uint8_t conn_id, tNFC_CONN_EVT event,
832                               tNFC_CONN* p_data);
833 #define NFC_MAX_CONN_ID 15
834 #define NFC_ILLEGAL_CONN_ID 0xFF
835 /* the static connection ID for RF traffic */
836 #define NFC_RF_CONN_ID 0
837 
838 /*************************************
839 **  Status callback function
840 **************************************/
841 typedef void(tNFC_STATUS_CBACK)(tNFC_STATUS status);
842 
843 /*****************************************************************************
844 **  EXTERNAL FUNCTION DECLARATIONS
845 *****************************************************************************/
846 #ifdef __cplusplus
847 extern "C" {
848 #endif
849 
850 /*******************************************************************************
851 **
852 ** Function         NFC_Enable
853 **
854 ** Description      This function enables NFC. Prior to calling NFC_Enable:
855 **                  - the NFCC must be powered up, and ready to receive
856 **                    commands.
857 **                  - GKI must be enabled
858 **                  - NFC_TASK must be started
859 **                  - NCIT_TASK must be started (if using dedicated NCI
860 **                    transport)
861 **
862 **                  This function opens the NCI transport (if applicable),
863 **                  resets the NFC controller, and initializes the NFC
864 **                  subsystems.
865 **
866 **                  When the NFC startup procedure is completed, an
867 **                  NFC_ENABLE_REVT is returned to the application using the
868 **                  tNFC_RESPONSE_CBACK.
869 **
870 ** Returns          tNFC_STATUS
871 **
872 *******************************************************************************/
873 extern tNFC_STATUS NFC_Enable(tNFC_RESPONSE_CBACK* p_cback);
874 
875 /*******************************************************************************
876 **
877 ** Function         NFC_Disable
878 **
879 ** Description      This function performs clean up routines for shutting down
880 **                  NFC and closes the NCI transport (if using dedicated NCI
881 **                  transport).
882 **
883 **                  When the NFC shutdown procedure is completed, an
884 **                  NFC_DISABLED_REVT is returned to the application using the
885 **                  tNFC_RESPONSE_CBACK.
886 **
887 ** Returns          nothing
888 **
889 *******************************************************************************/
890 extern void NFC_Disable(void);
891 
892 /*******************************************************************************
893 **
894 ** Function         NFC_Init
895 **
896 ** Description      This function initializes control blocks for NFC
897 **
898 ** Returns          nothing
899 **
900 *******************************************************************************/
901 extern void NFC_Init(tHAL_NFC_ENTRY* p_hal_entry_tbl);
902 
903 /*******************************************************************************
904 **
905 ** Function         NFC_GetLmrtSize
906 **
907 ** Description      Called by application wto query the Listen Mode Routing
908 **                  Table size supported by NFCC
909 **
910 ** Returns          Listen Mode Routing Table size
911 **
912 *******************************************************************************/
913 extern uint16_t NFC_GetLmrtSize(void);
914 
915 /*******************************************************************************
916 **
917 ** Function         NFC_SetConfig
918 **
919 ** Description      This function is called to send the configuration parameter
920 **                  TLV to NFCC. The response from NFCC is reported by
921 **                  tNFC_RESPONSE_CBACK as NFC_SET_CONFIG_REVT.
922 **
923 ** Parameters       tlv_size - the length of p_param_tlvs.
924 **                  p_param_tlvs - the parameter ID/Len/Value list
925 **
926 ** Returns          tNFC_STATUS
927 **
928 *******************************************************************************/
929 extern tNFC_STATUS NFC_SetConfig(uint8_t tlv_size, uint8_t* p_param_tlvs);
930 
931 /*******************************************************************************
932 **
933 ** Function         NFC_GetConfig
934 **
935 ** Description      This function is called to retrieve the parameter TLV from
936 **                  NFCC. The response from NFCC is reported by
937 **                  tNFC_RESPONSE_CBACK as NFC_GET_CONFIG_REVT.
938 **
939 ** Parameters       num_ids - the number of parameter IDs
940 **                  p_param_ids - the parameter ID list.
941 **
942 ** Returns          tNFC_STATUS
943 **
944 *******************************************************************************/
945 extern tNFC_STATUS NFC_GetConfig(uint8_t num_ids, uint8_t* p_param_ids);
946 
947 /*******************************************************************************
948 **
949 ** Function         NFC_NfceeDiscover
950 **
951 ** Description      This function is called to enable or disable NFCEE
952 **                  Discovery. The response from NFCC is reported by
953 **                  tNFC_RESPONSE_CBACK as NFC_NFCEE_DISCOVER_REVT.
954 **                  The notification from NFCC is reported by
955 **                  tNFC_RESPONSE_CBACK as NFC_NFCEE_INFO_REVT.
956 **
957 ** Parameters       discover - 1 to enable discover, 0 to disable.
958 **
959 ** Returns          tNFC_STATUS
960 **
961 *******************************************************************************/
962 extern tNFC_STATUS NFC_NfceeDiscover(bool discover);
963 
964 /*******************************************************************************
965 **
966 ** Function         NFC_NfceeModeSet
967 **
968 ** Description      This function is called to activate or de-activate an NFCEE
969 **                  connected to the NFCC.
970 **                  The response from NFCC is reported by tNFC_RESPONSE_CBACK
971 **                  as NFC_NFCEE_MODE_SET_REVT.
972 **
973 ** Parameters       nfcee_id - the NFCEE to activate or de-activate.
974 **                  mode - 0 to activate NFCEE, 1 to de-activate.
975 **
976 ** Returns          tNFC_STATUS
977 **
978 *******************************************************************************/
979 extern tNFC_STATUS NFC_NfceeModeSet(uint8_t nfcee_id, tNFC_NFCEE_MODE mode);
980 /*******************************************************************************
981 **
982 ** Function         NFC_DiscoveryMap
983 **
984 ** Description      This function is called to set the discovery interface
985 **                  mapping. The response from NFCC is reported by
986 **                  tNFC_DISCOVER_CBACK as. NFC_MAP_DEVT.
987 **
988 ** Parameters       num - the number of items in p_params.
989 **                  p_maps - the discovery interface mappings
990 **                  p_cback - the discovery callback function
991 **
992 ** Returns          tNFC_STATUS
993 **
994 *******************************************************************************/
995 extern tNFC_STATUS NFC_DiscoveryMap(uint8_t num, tNFC_DISCOVER_MAPS* p_maps,
996                                     tNFC_DISCOVER_CBACK* p_cback);
997 
998 /*******************************************************************************
999 **
1000 ** Function         NFC_DiscoveryStart
1001 **
1002 ** Description      This function is called to start Polling and/or Listening.
1003 **                  The response from NFCC is reported by tNFC_DISCOVER_CBACK
1004 **                  as NFC_START_DEVT. The notification from NFCC is reported by
1005 **                  tNFC_DISCOVER_CBACK as NFC_RESULT_DEVT.
1006 **
1007 ** Parameters       num_params - the number of items in p_params.
1008 **                  p_params - the discovery parameters
1009 **                  p_cback - the discovery callback function
1010 **
1011 ** Returns          tNFC_STATUS
1012 **
1013 *******************************************************************************/
1014 extern tNFC_STATUS NFC_DiscoveryStart(uint8_t num_params,
1015                                       tNFC_DISCOVER_PARAMS* p_params,
1016                                       tNFC_DISCOVER_CBACK* p_cback);
1017 
1018 /*******************************************************************************
1019 **
1020 ** Function         NFC_DiscoverySelect
1021 **
1022 ** Description      If tNFC_DISCOVER_CBACK reports status=NFC_MULTIPLE_PROT,
1023 **                  the application needs to use this function to select the
1024 **                  the logical endpoint to continue. The response from NFCC is
1025 **                  reported by tNFC_DISCOVER_CBACK as NFC_SELECT_DEVT.
1026 **
1027 ** Parameters       rf_disc_id - The ID identifies the remote device.
1028 **                  protocol - the logical endpoint on the remote devide
1029 **                  rf_interface - the RF interface to communicate with NFCC
1030 **
1031 ** Returns          tNFC_STATUS
1032 **
1033 *******************************************************************************/
1034 extern tNFC_STATUS NFC_DiscoverySelect(uint8_t rf_disc_id, uint8_t protocol,
1035                                        uint8_t rf_interface);
1036 
1037 /*******************************************************************************
1038 **
1039 ** Function         NFC_ConnCreate
1040 **
1041 ** Description      This function is called to create a logical connection with
1042 **                  NFCC for data exchange.
1043 **                  The response from NFCC is reported in tNFC_CONN_CBACK
1044 **                  as NFC_CONN_CREATE_CEVT.
1045 **
1046 ** Parameters       dest_type - the destination type
1047 **                  id   - the NFCEE ID or RF Discovery ID .
1048 **                  protocol - the protocol
1049 **                  p_cback - the data callback function to receive data from
1050 **                  NFCC
1051 **
1052 ** Returns          tNFC_STATUS
1053 **
1054 *******************************************************************************/
1055 extern tNFC_STATUS NFC_ConnCreate(uint8_t dest_type, uint8_t id,
1056                                   uint8_t protocol, tNFC_CONN_CBACK* p_cback);
1057 
1058 /*******************************************************************************
1059 **
1060 ** Function         NFC_ConnClose
1061 **
1062 ** Description      This function is called to close a logical connection with
1063 **                  NFCC.
1064 **                  The response from NFCC is reported in tNFC_CONN_CBACK
1065 **                  as NFC_CONN_CLOSE_CEVT.
1066 **
1067 ** Parameters       conn_id - the connection id.
1068 **
1069 ** Returns          tNFC_STATUS
1070 **
1071 *******************************************************************************/
1072 extern tNFC_STATUS NFC_ConnClose(uint8_t conn_id);
1073 
1074 /*******************************************************************************
1075 **
1076 ** Function         NFC_SetStaticRfCback
1077 **
1078 ** Description      This function is called to update the data callback function
1079 **                  to receive the data for the given connection id.
1080 **
1081 ** Parameters       p_cback - the connection callback function
1082 **
1083 ** Returns          Nothing
1084 **
1085 *******************************************************************************/
1086 extern void NFC_SetStaticRfCback(tNFC_CONN_CBACK* p_cback);
1087 
1088 /*******************************************************************************
1089 **
1090 ** Function         NFC_SetReassemblyFlag
1091 **
1092 ** Description      This function is called to set if nfc will reassemble
1093 **                  nci packet as much as its buffer can hold or it should not
1094 **                  reassemble but forward the fragmented nci packet to layer
1095 **                  above. If nci data pkt is fragmented, nfc may send multiple
1096 **                  NFC_DATA_CEVT with status NFC_STATUS_CONTINUE before sending
1097 **                  NFC_DATA_CEVT with status NFC_STATUS_OK based on reassembly
1098 **                  configuration and reassembly buffer size
1099 **
1100 ** Parameters       reassembly - flag to indicate if nfc may reassemble or not
1101 **
1102 ** Returns          Nothing
1103 **
1104 *******************************************************************************/
1105 extern void NFC_SetReassemblyFlag(bool reassembly);
1106 
1107 /*******************************************************************************
1108 **
1109 ** Function         NFC_SendData
1110 **
1111 ** Description      This function is called to send the given data packet
1112 **                  to the connection identified by the given connection id.
1113 **
1114 ** Parameters       conn_id - the connection id.
1115 **                  p_data - the data packet
1116 **
1117 ** Returns          tNFC_STATUS
1118 **
1119 *******************************************************************************/
1120 extern tNFC_STATUS NFC_SendData(uint8_t conn_id, NFC_HDR* p_data);
1121 
1122 /*******************************************************************************
1123 **
1124 ** Function         NFC_FlushData
1125 **
1126 ** Description      This function is called to discard the tx data queue of
1127 **                  the given connection id.
1128 **
1129 ** Parameters       conn_id - the connection id.
1130 **
1131 ** Returns          tNFC_STATUS
1132 **
1133 *******************************************************************************/
1134 extern tNFC_STATUS NFC_FlushData(uint8_t conn_id);
1135 
1136 /*******************************************************************************
1137 **
1138 ** Function         NFC_Deactivate
1139 **
1140 ** Description      This function is called to stop the discovery process or
1141 **                  put the listen device in sleep mode or terminate the NFC
1142 **                  link.
1143 **
1144 **                  The response from NFCC is reported by tNFC_DISCOVER_CBACK
1145 **                  as NFC_DEACTIVATE_DEVT.
1146 **
1147 ** Parameters       deactivate_type - NFC_DEACTIVATE_TYPE_IDLE, to IDLE mode.
1148 **                                    NFC_DEACTIVATE_TYPE_SLEEP to SLEEP mode.
1149 **                                    NFC_DEACTIVATE_TYPE_SLEEP_AF to SLEEP_AF
1150 **                                    mode.
1151 **
1152 ** Returns          tNFC_STATUS
1153 **
1154 *******************************************************************************/
1155 extern tNFC_STATUS NFC_Deactivate(tNFC_DEACT_TYPE deactivate_type);
1156 
1157 /*******************************************************************************
1158 **
1159 ** Function         NFC_UpdateRFCommParams
1160 **
1161 ** Description      This function is called to update RF Communication
1162 **                  parameters once the Frame RF Interface has been activated.
1163 **
1164 **                  The response from NFCC is reported by tNFC_RESPONSE_CBACK
1165 **                  as NFC_RF_COMM_PARAMS_UPDATE_REVT.
1166 **
1167 ** Returns          tNFC_STATUS
1168 **
1169 *******************************************************************************/
1170 extern tNFC_STATUS NFC_UpdateRFCommParams(tNFC_RF_COMM_PARAMS* p_params);
1171 
1172 /*******************************************************************************
1173 **
1174 ** Function         NFC_SetPowerOffSleep
1175 **
1176 ** Description      This function closes/opens transport and turns off/on NFCC.
1177 **
1178 ** Returns          tNFC_STATUS
1179 **
1180 *******************************************************************************/
1181 extern tNFC_STATUS NFC_SetPowerOffSleep(bool enable);
1182 
1183 /*******************************************************************************
1184 **
1185 ** Function         NFC_PowerCycleNFCC
1186 **
1187 ** Description      This function turns off and then on NFCC.
1188 **
1189 ** Returns          tNFC_STATUS
1190 **
1191 *******************************************************************************/
1192 extern tNFC_STATUS NFC_PowerCycleNFCC(void);
1193 
1194 /*******************************************************************************
1195 **
1196 ** Function         NFC_SetRouting
1197 **
1198 ** Description      This function is called to configure the CE routing table.
1199 **                  The response from NFCC is reported by tNFC_RESPONSE_CBACK
1200 **                  as NFC_SET_ROUTING_REVT.
1201 **
1202 ** Parameters
1203 **
1204 ** Returns          tNFC_STATUS
1205 **
1206 *******************************************************************************/
1207 extern tNFC_STATUS NFC_SetRouting(bool more, uint8_t num_tlv, uint8_t tlv_size,
1208                                   uint8_t* p_param_tlvs);
1209 
1210 /*******************************************************************************
1211 **
1212 ** Function         NFC_GetRouting
1213 **
1214 ** Description      This function is called to retrieve the CE routing table
1215 **                  from NFCC. The response from NFCC is reported by
1216 **                  tNFC_RESPONSE_CBACK as NFC_GET_ROUTING_REVT.
1217 **
1218 ** Returns          tNFC_STATUS
1219 **
1220 *******************************************************************************/
1221 extern tNFC_STATUS NFC_GetRouting(void);
1222 
1223 /*******************************************************************************
1224 **
1225 ** Function         NFC_RegVSCback
1226 **
1227 ** Description      This function is called to register or de-register a
1228 **                  callback function to receive Proprietary NCI response and
1229 **                  notification events.
1230 **                  The maximum number of callback functions allowed is
1231 **                  NFC_NUM_VS_CBACKS
1232 **
1233 ** Returns          tNFC_STATUS
1234 **
1235 *******************************************************************************/
1236 extern tNFC_STATUS NFC_RegVSCback(bool is_register, tNFC_VS_CBACK* p_cback);
1237 
1238 /*******************************************************************************
1239 **
1240 ** Function         NFC_SendVsCommand
1241 **
1242 ** Description      This function is called to send the given vendor specific
1243 **                  command to NFCC. The response from NFCC is reported to the
1244 **                  given tNFC_VS_CBACK as (oid).
1245 **
1246 ** Parameters       oid - The opcode of the VS command.
1247 **                  p_data - The parameters for the VS command
1248 **
1249 ** Returns          tNFC_STATUS
1250 **
1251 *******************************************************************************/
1252 extern tNFC_STATUS NFC_SendVsCommand(uint8_t oid, NFC_HDR* p_data,
1253                                      tNFC_VS_CBACK* p_cback);
1254 
1255 /*******************************************************************************
1256 **
1257 ** Function         NFC_TestLoopback
1258 **
1259 ** Description      This function is called to send the given data packet
1260 **                  to NFCC for loopback test.
1261 **                  When loopback data is received from NFCC, tNFC_TEST_CBACK .
1262 **                  reports a NFC_LOOPBACK_TEVT.
1263 **
1264 ** Parameters       p_data - the data packet
1265 **
1266 ** Returns          tNFC_STATUS
1267 **
1268 *******************************************************************************/
1269 extern tNFC_STATUS NFC_TestLoopback(NFC_HDR* p_data);
1270 
1271 /*******************************************************************************
1272 **
1273 ** Function         NFC_SetTraceLevel
1274 **
1275 ** Description      This function sets the trace level for NFC.  If called with
1276 **                  a value of 0xFF, it simply returns the current trace level.
1277 **
1278 ** Returns          The new or current trace level
1279 **
1280 *******************************************************************************/
1281 extern uint8_t NFC_SetTraceLevel(uint8_t new_level);
1282 
1283 #if (BT_TRACE_VERBOSE == TRUE)
1284 /*******************************************************************************
1285 **
1286 ** Function         NFC_GetStatusName
1287 **
1288 ** Description      This function returns the status name.
1289 **
1290 ** NOTE             conditionally compiled to save memory.
1291 **
1292 ** Returns          pointer to the name
1293 **
1294 *******************************************************************************/
1295 extern char* NFC_GetStatusName(tNFC_STATUS status);
1296 #endif
1297 
1298 #ifdef __cplusplus
1299 }
1300 #endif
1301 
1302 #endif /* NFC_API_H */
1303