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