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