1 /******************************************************************************
2  *
3  *  Copyright (C) 2010-2014 Broadcom Corporation
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at:
8  *
9  *  http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  ******************************************************************************/
18 
19 /******************************************************************************
20  *
21  *  NFA interface to NFCEE
22  *
23  ******************************************************************************/
24 #ifndef NFA_EE_API_H
25 #define NFA_EE_API_H
26 
27 #include "nfa_api.h"
28 #include "nfc_api.h"
29 #include "nfc_target.h"
30 
31 /*****************************************************************************
32 **  Constants and data types
33 *****************************************************************************/
34 /* 16 per ISO 7816 specification    */
35 #define NFA_MAX_AID_LEN NFC_MAX_AID_LEN
36 
37 /* NFA EE callback events */
38 enum {
39   NFA_EE_DISCOVER_EVT,   /* The status for NFA_EeDiscover () */
40   NFA_EE_REGISTER_EVT,   /* The status for NFA_EeRegister () */
41   NFA_EE_DEREGISTER_EVT, /* The status for NFA_EeDeregister () */
42   NFA_EE_MODE_SET_EVT, /* The status for activating or deactivating an NFCEE */
43   NFA_EE_ADD_AID_EVT,  /* The status for adding an AID to a routing table entry
44                         */
45   NFA_EE_REMOVE_AID_EVT,  /* The status for removing an AID from a routing table
46                            */
47   NFA_EE_ADD_SYSCODE_EVT, /* The status for adding an System Code to a routing
48                              table entry */
49   NFA_EE_REMOVE_SYSCODE_EVT, /* The status for removing an System Code from
50                               routing table */
51   NFA_EE_REMAINING_SIZE_EVT, /* The remaining size of the Listen Mode Routing
52                                 Table   */
53   NFA_EE_SET_TECH_CFG_EVT,   /* The status for setting the routing based on RF
54                                 tech.  */
55   NFA_EE_SET_PROTO_CFG_EVT,  /* The status for setting the routing based on
56                                 protocols */
57   NFA_EE_UPDATED_EVT,        /* The status for NFA_EeUpdateNow */
58   NFA_EE_CONNECT_EVT,        /* Result of NFA_EeConnect */
59   NFA_EE_DATA_EVT, /* Received data from NFCEE.                             */
60   NFA_EE_DISCONNECT_EVT, /* NFCEE connection closed. */
61   NFA_EE_NEW_EE_EVT, /* A new NFCEE is discovered                             */
62   NFA_EE_ACTION_EVT, /* An action happened in NFCEE                           */
63   NFA_EE_DISCOVER_REQ_EVT, /* NFCEE Discover Request Notification */
64   NFA_EE_NO_MEM_ERR_EVT,   /* Error - out of GKI buffers */
65   NFA_EE_NO_CB_ERR_EVT /* Error - Can not find control block or wrong state */
66 };
67 typedef uint8_t tNFA_EE_EVT;
68 
69 /* tNFA_NFCEE_INTERFACE values */
70 /* HCI Access Interface*/
71 #define NFA_EE_INTERFACE_HCI_ACCESS NFC_NFCEE_INTERFACE_HCI_ACCESS
72 typedef uint8_t tNFA_EE_INTERFACE;
73 
74 typedef uint8_t tNFA_EE_TAG;
75 
76 /* for NFA_EeModeSet () */
77 #define NFA_EE_MD_ACTIVATE NFC_MODE_ACTIVATE
78 #define NFA_EE_MD_DEACTIVATE NFC_MODE_DEACTIVATE
79 typedef uint8_t tNFA_EE_MD;
80 
81 /* The device is on                 */
82 #define NFA_EE_PWR_STATE_ON 0x01
83 /* The device is switched off       */
84 #define NFA_EE_PWR_STATE_SWITCH_OFF 0x02
85 /* The device's battery is removed  */
86 #define NFA_EE_PWR_STATE_BATT_OFF 0x04
87 typedef uint8_t tNFA_EE_PWR_STATE;
88 
89 /* NFCEE connected and inactive */
90 #define NFA_EE_STATUS_INACTIVE NFC_NFCEE_STATUS_INACTIVE
91 /* NFCEE connected and active   */
92 #define NFA_EE_STATUS_ACTIVE NFC_NFCEE_STATUS_ACTIVE
93 /* NFCEE removed                */
94 #define NFA_EE_STATUS_REMOVED NFC_NFCEE_STATUS_REMOVED
95 /* waiting for response from NFCC */
96 #define NFA_EE_STATUS_PENDING 0x10
97 typedef uint8_t tNFA_EE_STATUS;
98 
99 /* additional NFCEE Info */
100 typedef struct {
101   tNFA_EE_TAG tag;
102   uint8_t len;
103   uint8_t info[NFC_MAX_EE_INFO];
104 } tNFA_EE_TLV;
105 
106 typedef struct {
107   tNFA_HANDLE ee_handle;    /* handle for NFCEE oe DH   */
108   tNFA_EE_STATUS ee_status; /* The NFCEE status         */
109   uint8_t num_interface;    /* number of NFCEE interface*/
110   tNFA_EE_INTERFACE
111       ee_interface[NFC_MAX_EE_INTERFACE]; /* NFCEE supported interface */
112   uint8_t num_tlvs;                       /* number of TLVs           */
113   tNFA_EE_TLV ee_tlv[NFC_MAX_EE_TLVS];    /* the TLV                  */
114   uint8_t ee_power_supply_status;         /* The NFCEE Power supply */
115 } tNFA_EE_INFO;
116 
117 typedef struct {
118   tNFA_STATUS status; /* NFA_STATUS_OK is successful      */
119   uint8_t num_ee;     /* number of NFCEEs found           */
120   tNFA_EE_INFO ee_info[NFA_EE_MAX_EE_SUPPORTED]; /*NFCEE information */
121 } tNFA_EE_DISCOVER;
122 
123 typedef struct {
124   tNFA_HANDLE ee_handle; /* Handle of NFCEE                                  */
125   tNFA_STATUS status;    /* NFA_STATUS_OK is successful                      */
126   tNFA_EE_INTERFACE
127       ee_interface; /* NFCEE interface associated with this connection  */
128 } tNFA_EE_CONNECT;
129 
130 typedef tNFC_EE_TRIGGER tNFA_EE_TRIGGER;
131 
132 /* Union of NFCEE action parameter depending on the associated trigger */
133 typedef union {
134   tNFA_NFC_PROTOCOL protocol; /* NFA_EE_TRGR_RF_PROTOCOL: the protocol that
135                                  triggers this event */
136   tNFC_RF_TECH technology;    /* NFA_EE_TRGR_RF_TECHNOLOGY:the technology that
137                                  triggers this event */
138   tNFC_AID aid; /* NFA_EE_TRGR_SELECT      : the AID in the received SELECT AID
139                    command */
140   tNFC_APP_INIT app_init; /* NFA_EE_TRGR_APP_INIT:     The information for the
141                              application initiated trigger */
142 } tNFA_EE_ACTION_PARAM;
143 
144 typedef struct {
145   tNFA_HANDLE ee_handle;   /* Handle of NFCEE                  */
146   tNFA_EE_TRIGGER trigger; /* the trigger of this event        */
147   tNFA_EE_ACTION_PARAM param;
148 } tNFA_EE_ACTION;
149 
150 typedef struct {
151   tNFA_HANDLE ee_handle;    /* Handle of NFCEE              */
152   tNFA_STATUS status;       /* NFA_STATUS_OK is successful  */
153   tNFA_EE_STATUS ee_status; /* The NFCEE status             */
154 } tNFA_EE_MODE_SET;
155 
156 typedef struct {
157   tNFA_HANDLE ee_handle;          /* Handle of MFCEE      */
158   tNFA_NFC_PROTOCOL la_protocol;  /* Listen A protocol    */
159   tNFA_NFC_PROTOCOL lb_protocol;  /* Listen B protocol    */
160   tNFA_NFC_PROTOCOL lf_protocol;  /* Listen F protocol    */
161   tNFA_NFC_PROTOCOL lbp_protocol; /* Listen B' protocol   */
162 } tNFA_EE_DISCOVER_INFO;
163 
164 /* Data for NFA_EE_DISCOVER_REQ_EVT */
165 typedef struct {
166   uint8_t status; /* NFA_STATUS_OK if successful   */
167   uint8_t num_ee; /* number of MFCEE information   */
168   tNFA_EE_DISCOVER_INFO ee_disc_info[NFA_EE_MAX_EE_SUPPORTED -
169                                      1]; /* NFCEE DISCOVER Request info   */
170 } tNFA_EE_DISCOVER_REQ;
171 
172 /* Data for NFA_EE_DATA_EVT */
173 typedef struct {
174   tNFA_HANDLE handle; /* Connection handle */
175   uint16_t len;       /* Length of data    */
176   uint8_t* p_buf;     /* Data buffer       */
177 } tNFA_EE_DATA;
178 
179 /* Union of all EE callback structures */
180 typedef union {
181   tNFA_STATUS
182       status; /* NFA_STATUS_OK is successful; otherwise NFA_STATUS_FAILED */
183   tNFA_EE_DATA data;
184   tNFA_HANDLE handle;
185   tNFA_EE_DISCOVER ee_discover;
186   tNFA_STATUS ee_register;
187   tNFA_STATUS deregister;
188   tNFA_STATUS add_aid;
189   tNFA_STATUS remove_aid;
190   tNFA_STATUS add_sc;
191   tNFA_STATUS remove_sc;
192   tNFA_STATUS set_tech;
193   tNFA_STATUS set_proto;
194   uint16_t size;
195   tNFA_EE_CONNECT connect;
196   tNFA_EE_ACTION action;
197   tNFA_EE_MODE_SET mode_set;
198   tNFA_EE_INFO new_ee;
199   tNFA_EE_DISCOVER_REQ discover_req;
200 } tNFA_EE_CBACK_DATA;
201 
202 /* EE callback */
203 typedef void(tNFA_EE_CBACK)(tNFA_EE_EVT event, tNFA_EE_CBACK_DATA* p_data);
204 
205 /*****************************************************************************
206 **  External Function Declarations
207 *****************************************************************************/
208 
209 /*******************************************************************************
210 **
211 ** Function         NFA_EeDiscover
212 **
213 ** Description      This function retrieves the NFCEE information from NFCC.
214 **                  The NFCEE information is reported in NFA_EE_DISCOVER_EVT.
215 **
216 **                  This function may be called when a system supports removable
217 **                  NFCEEs,
218 **
219 ** Returns          NFA_STATUS_OK if information is retrieved successfully
220 **                  NFA_STATUS_FAILED If wrong state (retry later)
221 **                  NFA_STATUS_INVALID_PARAM If bad parameter
222 **
223 *******************************************************************************/
224 extern tNFA_STATUS NFA_EeDiscover(tNFA_EE_CBACK* p_cback);
225 
226 /*******************************************************************************
227 **
228 ** Function         NFA_EeGetInfo
229 **
230 ** Description      This function retrieves the NFCEE information from NFA.
231 **                  The actual number of NFCEE is returned in p_num_nfcee
232 **                  and NFCEE information is returned in p_info
233 **
234 ** Returns          NFA_STATUS_OK if information is retrieved successfully
235 **                  NFA_STATUS_FAILED If wrong state (retry later)
236 **                  NFA_STATUS_INVALID_PARAM If bad parameter
237 **
238 *******************************************************************************/
239 extern tNFA_STATUS NFA_EeGetInfo(uint8_t* p_num_nfcee, tNFA_EE_INFO* p_info);
240 
241 /*******************************************************************************
242 **
243 ** Function         NFA_EeRegister
244 **
245 ** Description      This function registers a callback function to receive the
246 **                  events from NFA-EE module.
247 **
248 ** Returns          NFA_STATUS_OK if successfully initiated
249 **                  NFA_STATUS_FAILED otherwise
250 **                  NFA_STATUS_INVALID_PARAM If bad parameter
251 **
252 *******************************************************************************/
253 extern tNFA_STATUS NFA_EeRegister(tNFA_EE_CBACK* p_cback);
254 
255 /*******************************************************************************
256 **
257 ** Function         NFA_EeDeregister
258 **
259 ** Description      This function de-registers the callback function
260 **
261 ** Returns          NFA_STATUS_OK if successfully initiated
262 **                  NFA_STATUS_FAILED otherwise
263 **                  NFA_STATUS_INVALID_PARAM If bad parameter
264 **
265 *******************************************************************************/
266 extern tNFA_STATUS NFA_EeDeregister(tNFA_EE_CBACK* p_cback);
267 
268 /*******************************************************************************
269 **
270 ** Function         NFA_EeModeSet
271 **
272 ** Description      This function is called to activate
273 **                  (mode = NFA_EE_MD_ACTIVATE) or deactivate
274 **                  (mode = NFA_EE_MD_DEACTIVATE) the NFCEE identified by the
275 **                  given ee_handle. The result of this operation is reported
276 **                  with the NFA_EE_MODE_SET_EVT.
277 **
278 ** Returns          NFA_STATUS_OK if successfully initiated
279 **                  NFA_STATUS_FAILED otherwise
280 **                  NFA_STATUS_INVALID_PARAM If bad parameter
281 **
282 *******************************************************************************/
283 extern tNFA_STATUS NFA_EeModeSet(tNFA_HANDLE ee_handle, tNFA_EE_MD mode);
284 
285 /*******************************************************************************
286 **
287 ** Function         NFA_EeSetDefaultTechRouting
288 **
289 ** Description      This function is called to add, change or remove the
290 **                  default routing based on RF technology in the listen mode
291 **                  routing table for the given ee_handle. The status of this
292 **                  operation is reported as the NFA_EE_SET_TECH_CFG_EVT.
293 **
294 ** Note:            If RF discovery is started,
295 **                  NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should
296 **                  happen before calling this function
297 **
298 ** Note:            NFA_EeUpdateNow() should be called after last NFA-EE
299 **                  function to change the listen mode routing is called.
300 **
301 ** Returns          NFA_STATUS_OK if successfully initiated
302 **                  NFA_STATUS_FAILED otherwise
303 **                  NFA_STATUS_INVALID_PARAM If bad parameter
304 **
305 *******************************************************************************/
306 extern tNFA_STATUS NFA_EeSetDefaultTechRouting(
307     tNFA_HANDLE ee_handle, tNFA_TECHNOLOGY_MASK technologies_switch_on,
308     tNFA_TECHNOLOGY_MASK technologies_switch_off,
309     tNFA_TECHNOLOGY_MASK technologies_battery_off,
310     tNFA_TECHNOLOGY_MASK technologies_screen_lock,
311     tNFA_TECHNOLOGY_MASK technologies_screen_off,
312     tNFA_TECHNOLOGY_MASK technologies_screen_off_lock);
313 
314 /*******************************************************************************
315 **
316 ** Function         NFA_EeSetDefaultProtoRouting
317 **
318 ** Description      This function is called to add, change or remove the
319 **                  default routing based on Protocol in the listen mode routing
320 **                  table for the given ee_handle. The status of this
321 **                  operation is reported as the NFA_EE_SET_PROTO_CFG_EVT.
322 **
323 ** Note:            If RF discovery is started,
324 **                  NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should
325 **                  happen before calling this function
326 **
327 ** Note:            NFA_EeUpdateNow() should be called after last NFA-EE
328 **                  function to change the listen mode routing is called.
329 **
330 ** Returns          NFA_STATUS_OK if successfully initiated
331 **                  NFA_STATUS_FAILED otherwise
332 **                  NFA_STATUS_INVALID_PARAM If bad parameter
333 **
334 *******************************************************************************/
335 extern tNFA_STATUS NFA_EeSetDefaultProtoRouting(
336     tNFA_HANDLE ee_handle, tNFA_PROTOCOL_MASK protocols_switch_on,
337     tNFA_PROTOCOL_MASK protocols_switch_off,
338     tNFA_PROTOCOL_MASK protocols_battery_off,
339     tNFA_PROTOCOL_MASK technologies_screen_lock,
340     tNFA_PROTOCOL_MASK technologies_screen_off,
341     tNFA_PROTOCOL_MASK technologies_screen_off_lock);
342 
343 /*******************************************************************************
344 **
345 ** Function         NFA_EeAddAidRouting
346 **
347 ** Description      This function is called to add an AID entry in the
348 **                  listen mode routing table in NFCC. The status of this
349 **                  operation is reported as the NFA_EE_ADD_AID_EVT.
350 **
351 ** Note:            If RF discovery is started,
352 **                  NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should
353 **                  happen before calling this function
354 **
355 ** Note:            NFA_EeUpdateNow() should be called after last NFA-EE
356 **                  function to change the listen mode routing is called.
357 **
358 ** Returns          NFA_STATUS_OK if successfully initiated
359 **                  NFA_STATUS_FAILED otherwise
360 **                  NFA_STATUS_INVALID_PARAM If bad parameter
361 **
362 *******************************************************************************/
363 extern tNFA_STATUS NFA_EeAddAidRouting(tNFA_HANDLE ee_handle, uint8_t aid_len,
364                                        uint8_t* p_aid,
365                                        tNFA_EE_PWR_STATE power_state,
366                                        uint8_t aidInfo);
367 
368 /*******************************************************************************
369 **
370 ** Function         NFA_EeRemoveAidRouting
371 **
372 ** Description      This function is called to remove the given AID entry from
373 **                  the listen mode routing table. If the entry configures VS,
374 **                  it is also removed. The status of this operation is reported
375 **                  as the NFA_EE_REMOVE_AID_EVT.
376 **
377 ** Note:            If RF discovery is started,
378 **                  NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should
379 **                  happen before calling this function
380 **
381 ** Note:            NFA_EeUpdateNow() should be called after last NFA-EE
382 **                  function to change the listen mode routing is called.
383 **
384 ** Returns          NFA_STATUS_OK if successfully initiated
385 **                  NFA_STATUS_FAILED otherwise
386 **                  NFA_STATUS_INVALID_PARAM If bad parameter
387 **
388 *******************************************************************************/
389 extern tNFA_STATUS NFA_EeRemoveAidRouting(uint8_t aid_len, uint8_t* p_aid);
390 
391 /*******************************************************************************
392  **
393  ** Function         NFA_EeAddSystemCodeRouting
394  **
395  ** Description      This function is called to add an system code entry in the
396  **                  listen mode routing table in NFCC. The status of this
397  **                  operation is reported as the NFA_EE_ADD_SYSCODE_EVT.
398  **
399  ** Note:            If RF discovery is started,
400  **                  NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should
401  **                  happen before calling this function
402  **
403  ** Note:            NFA_EeUpdateNow() should be called after last NFA-EE
404  **                  function to change the listen mode routing is called.
405  **
406  ** Returns          NFA_STATUS_OK if successfully initiated
407  **                  NFA_STATUS_FAILED otherwise
408  **                  NFA_STATUS_INVALID_PARAM If bad parameter
409  **
410  *******************************************************************************/
411 extern tNFA_STATUS NFA_EeAddSystemCodeRouting(uint16_t systemcode,
412                                               tNFA_HANDLE ee_handle,
413                                               tNFA_EE_PWR_STATE power_state);
414 
415 /*******************************************************************************
416 **
417 ** Function         NFA_EeRemoveSystemCodeRouting
418 **
419 ** Description      This function is called to remove the given System Code
420 *based entry from
421 **                  the listen mode routing table. The status of this operation
422 *is reported
423 **                  as the NFA_EE_REMOVE_SYSCODE_EVT.
424 **
425 ** Note:            If RF discovery is started,
426 **                  NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should
427 **                  happen before calling this function
428 **
429 ** Note:            NFA_EeUpdateNow() should be called after last NFA-EE
430 **                  function to change the listen mode routing is called.
431 **
432 ** Returns          NFA_STATUS_OK if successfully initiated
433 **                  NFA_STATUS_FAILED otherwise
434 **                  NFA_STATUS_INVALID_PARAM If bad parameter
435 **
436 *******************************************************************************/
437 extern tNFA_STATUS NFA_EeRemoveSystemCodeRouting(uint16_t systemcode);
438 
439 /*******************************************************************************
440 **
441 ** Function         NFA_EeGetLmrtRemainingSize
442 **
443 ** Description      This function is called to get remaining size of the
444 **                  Listen Mode Routing Table.
445 **                  The remaining size is reported in NFA_EE_REMAINING_SIZE_EVT
446 **
447 ** Returns          NFA_STATUS_OK if successfully initiated
448 **                  NFA_STATUS_FAILED otherwise
449 **
450 *******************************************************************************/
451 extern tNFA_STATUS NFA_EeGetLmrtRemainingSize(void);
452 
453 /*******************************************************************************
454 **
455 ** Function         NFA_EeUpdateNow
456 **
457 ** Description      This function is called to send the current listen mode
458 **                  routing table and VS configuration to the NFCC (without
459 **                  waiting for NFA_EE_ROUT_TIMEOUT_VAL).
460 **
461 **                  The status of this operation is
462 **                  reported with the NFA_EE_UPDATED_EVT.
463 **
464 ** Returns          NFA_STATUS_OK if successfully initiated
465 **                  NFA_STATUS_SEMANTIC_ERROR is update is currently in progress
466 **                  NFA_STATUS_FAILED otherwise
467 **
468 *******************************************************************************/
469 extern tNFA_STATUS NFA_EeUpdateNow(void);
470 
471 /*******************************************************************************
472 **
473 ** Function         NFA_EeConnect
474 **
475 ** Description      Open connection to an NFCEE attached to the NFCC
476 **
477 **                  The status of this operation is
478 **                  reported with the NFA_EE_CONNECT_EVT.
479 **
480 ** Returns          NFA_STATUS_OK if successfully initiated
481 **                  NFA_STATUS_FAILED otherwise
482 **                  NFA_STATUS_INVALID_PARAM If bad parameter
483 **
484 *******************************************************************************/
485 extern tNFA_STATUS NFA_EeConnect(tNFA_HANDLE ee_handle, uint8_t ee_interface,
486                                  tNFA_EE_CBACK* p_cback);
487 
488 /*******************************************************************************
489 **
490 ** Function         NFA_EeSendData
491 **
492 ** Description      Send data to the given NFCEE.
493 **                  This function shall be called after NFA_EE_CONNECT_EVT is
494 **                  reported and before NFA_EeDisconnect is called on the given
495 **                  ee_handle.
496 **
497 ** Returns          NFA_STATUS_OK if successfully initiated
498 **                  NFA_STATUS_FAILED otherwise
499 **                  NFA_STATUS_INVALID_PARAM If bad parameter
500 **
501 *******************************************************************************/
502 extern tNFA_STATUS NFA_EeSendData(tNFA_HANDLE ee_handle, uint16_t data_len,
503                                   uint8_t* p_data);
504 
505 /*******************************************************************************
506 **
507 ** Function         NFA_EeDisconnect
508 **
509 ** Description      Disconnect (if a connection is currently open) from an
510 **                  NFCEE interface. The result of this operation is reported
511 **                  with the NFA_EE_DISCONNECT_EVT.
512 **
513 ** Returns          NFA_STATUS_OK if successfully initiated
514 **                  NFA_STATUS_FAILED otherwise
515 **                  NFA_STATUS_INVALID_PARAM If bad parameter
516 **
517 *******************************************************************************/
518 extern tNFA_STATUS NFA_EeDisconnect(tNFA_HANDLE ee_handle);
519 
520 #endif /* NFA_EE_API_H */
521