nfa_ee_int.h revision eb190654c5fbaea2f396bb5523f57062f291879a
1/*****************************************************************************
2**
3**  Name:           nfa_ee_int.h
4**
5**  Description:    This is the private interface file for the NFA EE.
6**
7**  Copyright (c) 2010, Broadcom Corp., All Rights Reserved.
8**  Broadcom Bluetooth Core. Proprietary and confidential.
9**
10*****************************************************************************/
11#ifndef NFA_EE_INT_H
12#define NFA_EE_INT_H
13#include "nfc_api.h"
14#include "nfa_ee_api.h"
15#include "nfa_sys.h"
16
17/*****************************************************************************
18**  Constants and data types
19*****************************************************************************/
20#define NFA_EE_DEBUG            BT_TRACE_VERBOSE
21#define NFA_EE_NUM_ECBS         (NFA_EE_MAX_EE_SUPPORTED+1) /* the number of tNFA_EE_ECBs (for NFCEEs and DH) */
22#define NFA_EE_CB_4_DH          NFA_EE_MAX_EE_SUPPORTED     /* The index for DH in nfa_ee_cb.ee_cb[] */
23#define NFA_EE_INVALID          0xFF
24#define NFA_EE_MAX_TECH_ROUTE   4 /* only A, B, F, Bprime are supported by UICC now */
25
26#ifndef NFA_EE_AID_CFG_TAG_NAME
27#define NFA_EE_AID_CFG_TAG_NAME         0x4F /* AID                             */
28#endif
29
30/* NFA EE events */
31enum
32{
33    NFA_EE_API_DISCOVER_EVT  = NFA_SYS_EVT_START(NFA_ID_EE),
34    NFA_EE_API_REGISTER_EVT,
35    NFA_EE_API_DEREGISTER_EVT,
36    NFA_EE_API_MODE_SET_EVT,
37    NFA_EE_API_SET_TECH_CFG_EVT,
38    NFA_EE_API_SET_PROTO_CFG_EVT,
39    NFA_EE_API_ADD_AID_EVT,
40    NFA_EE_API_REMOVE_AID_EVT,
41    NFA_EE_API_UPDATE_NOW_EVT,
42    NFA_EE_API_CONNECT_EVT,
43    NFA_EE_API_SEND_DATA_EVT,
44    NFA_EE_API_DISCONNECT_EVT,
45
46    NFA_EE_NCI_DISC_RSP_EVT,
47    NFA_EE_NCI_DISC_NTF_EVT,
48    NFA_EE_NCI_MODE_SET_RSP_EVT,
49    NFA_EE_NCI_CONN_EVT,
50    NFA_EE_NCI_DATA_EVT,
51    NFA_EE_NCI_ACTION_NTF_EVT,
52    NFA_EE_NCI_DISC_REQ_NTF_EVT,
53
54    NFA_EE_ROUT_TIMEOUT_EVT,
55    NFA_EE_DISCV_TIMEOUT_EVT,
56    NFA_EE_CFG_TO_NFCC_EVT,
57    NFA_EE_MAX_EVT
58
59};
60
61
62typedef UINT16 tNFA_EE_INT_EVT;
63#define NFA_EE_AE_ROUTE             0x80        /* for listen mode routing table*/
64#define NFA_EE_AE_VS                0x40
65
66
67/* NFA EE Management state */
68enum
69{
70    NFA_EE_EM_STATE_INIT = 0,
71    NFA_EE_EM_STATE_INIT_DONE,
72    NFA_EE_EM_STATE_RESTORING,
73    NFA_EE_EM_STATE_DISABLING,
74    NFA_EE_EM_STATE_DISABLED,
75
76    NFA_EE_EM_STATE_MAX
77};
78typedef UINT8 tNFA_EE_EM_STATE;
79
80/* NFA EE connection status */
81enum
82{
83    NFA_EE_CONN_ST_NONE,    /* not connected */
84    NFA_EE_CONN_ST_WAIT,    /* connection is initiated; waiting for ack */
85    NFA_EE_CONN_ST_CONN,    /* connected; can send/receive data */
86    NFA_EE_CONN_ST_DISC,    /* disconnecting; waiting for ack */
87    NFA_EE_CONN_ST_MAX
88};
89typedef UINT8 tNFA_EE_CONN_ST;
90
91#define NFA_EE_MAX_AID_CFG_LEN  (510)
92#define NFA_EE_7816_STATUS_LEN  (2)
93
94/* NFA EE control block flags:
95 * use to indicate an API function has changed the configuration of the associated NFCEE
96 * The flags are cleared when the routing table/VS is updated */
97#define NFA_EE_ECB_FLAGS_TECH       0x02      /* technology routing changed         */
98#define NFA_EE_ECB_FLAGS_PROTO      0x04      /* protocol routing changed           */
99#define NFA_EE_ECB_FLAGS_AID        0x08      /* AID routing changed                */
100#define NFA_EE_ECB_FLAGS_VS         0x10      /* VS changed                         */
101#define NFA_EE_ECB_FLAGS_RESTORE    0x20      /* Restore related                    */
102#define NFA_EE_ECB_FLAGS_ROUTING    0x0E      /* routing flags changed              */
103#define NFA_EE_ECB_FLAGS_DISC_REQ   0x40      /* NFCEE Discover Request NTF is set  */
104#define NFA_EE_ECB_FLAGS_ORDER      0x80      /* DISC_REQ N reported before DISC N  */
105typedef UINT8 tNFA_EE_ECB_FLAGS;
106
107/* part of tNFA_EE_STATUS; for internal use only  */
108#define NFA_EE_STATUS_RESTORING 0x20      /* waiting for restore to full power mode to complete */
109#define NFA_EE_STATUS_INT_MASK  0x20      /* this bit is in ee_status for internal use only */
110
111/* NFA-EE information for a particular NFCEE Entity (including DH) */
112typedef struct
113{
114    tNFA_TECHNOLOGY_MASK    tech_switch_on;     /* default routing - technologies switch_on  */
115    tNFA_TECHNOLOGY_MASK    tech_switch_off;    /* default routing - technologies switch_off */
116    tNFA_TECHNOLOGY_MASK    tech_battery_off;   /* default routing - technologies battery_off*/
117    tNFA_PROTOCOL_MASK      proto_switch_on;    /* default routing - protocols switch_on     */
118    tNFA_PROTOCOL_MASK      proto_switch_off;   /* default routing - protocols switch_off    */
119    tNFA_PROTOCOL_MASK      proto_battery_off;  /* default routing - protocols battery_off   */
120    tNFA_EE_CONN_ST         conn_st;            /* connection status */
121    UINT8                   conn_id;            /* connection id */
122    tNFA_EE_CBACK           *p_ee_cback;        /* the callback function */
123
124    /* Each AID entry has an ssociated aid_len, aid_pwr_cfg, aid_rt_info.
125     * aid_cfg[] contains AID and maybe some other VS information in TLV format
126     * The first T is always NFA_EE_AID_CFG_TAG_NAME, the L is the actual AID length
127     * the aid_len is the total length of all the TLVs associated with this AID entry
128     */
129    UINT8                   aid_len[NFA_EE_MAX_AID_ENTRIES];/* the actual lengths in aid_cfg */
130    UINT8                   aid_pwr_cfg[NFA_EE_MAX_AID_ENTRIES];/* power configuration of this AID entry */
131    UINT8                   aid_rt_info[NFA_EE_MAX_AID_ENTRIES];/* route/vs info for this AID entry */
132    UINT8                   aid_cfg[NFA_EE_MAX_AID_CFG_LEN];/* routing entries based on AID */
133    UINT8                   aid_entries;        /* The number of AID entries in aid_cfg */
134    UINT8                   nfcee_id;           /* ID for this NFCEE */
135    UINT8                   ee_status;          /* The NFCEE status */
136    UINT8                   ee_old_status;      /* The NFCEE status before going to low power mode */
137    tNFA_EE_INTERFACE       ee_interface[NFC_MAX_EE_INTERFACE];/* NFCEE supported interface */
138    tNFA_EE_TLV             ee_tlv[NFC_MAX_EE_TLVS];/* the TLV */
139    UINT8                   num_interface;      /* number of Target interface */
140    UINT8                   num_tlvs;           /* number of TLVs */
141    tNFA_EE_ECB_FLAGS       ecb_flags;          /* the flags of this control block */
142    tNFA_EE_INTERFACE       use_interface;      /* NFCEE interface used for the connection */
143    tNFA_NFC_PROTOCOL       la_protocol;        /* Listen A protocol    */
144    tNFA_NFC_PROTOCOL       lb_protocol;        /* Listen B protocol    */
145    tNFA_NFC_PROTOCOL       lf_protocol;        /* Listen F protocol    */
146    tNFA_NFC_PROTOCOL       lbp_protocol;       /* Listen B' protocol   */
147} tNFA_EE_ECB;
148
149/* data type for NFA_EE_API_DISCOVER_EVT */
150typedef struct
151{
152    BT_HDR              hdr;
153    tNFA_EE_CBACK       *p_cback;
154} tNFA_EE_API_DISCOVER;
155
156/* data type for NFA_EE_API_REGISTER_EVT */
157typedef struct
158{
159    BT_HDR              hdr;
160    tNFA_EE_CBACK       *p_cback;
161} tNFA_EE_API_REGISTER;
162
163/* data type for NFA_EE_API_DEREGISTER_EVT */
164typedef struct
165{
166    BT_HDR              hdr;
167    int                 index;
168} tNFA_EE_API_DEREGISTER;
169
170/* data type for NFA_EE_API_MODE_SET_EVT */
171typedef struct
172{
173    BT_HDR              hdr;
174    tNFA_EE_ECB        *p_cb;
175    UINT8               nfcee_id;
176    UINT8               mode;
177} tNFA_EE_API_MODE_SET;
178
179/* data type for NFA_EE_API_SET_TECH_CFG_EVT */
180typedef struct
181{
182    BT_HDR                  hdr;
183    tNFA_EE_ECB            *p_cb;
184    UINT8                   nfcee_id;
185    tNFA_TECHNOLOGY_MASK    technologies_switch_on;
186    tNFA_TECHNOLOGY_MASK    technologies_switch_off;
187    tNFA_TECHNOLOGY_MASK    technologies_battery_off;
188} tNFA_EE_API_SET_TECH_CFG;
189
190/* data type for NFA_EE_API_SET_PROTO_CFG_EVT */
191typedef struct
192{
193    BT_HDR              hdr;
194    tNFA_EE_ECB        *p_cb;
195    UINT8               nfcee_id;
196    tNFA_PROTOCOL_MASK  protocols_switch_on;
197    tNFA_PROTOCOL_MASK  protocols_switch_off;
198    tNFA_PROTOCOL_MASK  protocols_battery_off;
199} tNFA_EE_API_SET_PROTO_CFG;
200
201/* data type for NFA_EE_API_ADD_AID_EVT */
202typedef struct
203{
204    BT_HDR              hdr;
205    tNFA_EE_ECB        *p_cb;
206    UINT8               nfcee_id;
207    UINT8               aid_len;
208    UINT8               *p_aid;
209    tNFA_EE_PWR_STATE   power_state;
210} tNFA_EE_API_ADD_AID;
211
212/* data type for NFA_EE_API_REMOVE_AID_EVT */
213typedef struct
214{
215    BT_HDR              hdr;
216    UINT8               aid_len;
217    UINT8               *p_aid;
218} tNFA_EE_API_REMOVE_AID;
219
220/* data type for NFA_EE_API_CONNECT_EVT */
221typedef struct
222{
223    BT_HDR              hdr;
224    tNFA_EE_ECB        *p_cb;
225    UINT8               nfcee_id;
226    UINT8               ee_interface;
227    tNFA_EE_CBACK       *p_cback;
228} tNFA_EE_API_CONNECT;
229
230/* data type for NFA_EE_API_SEND_DATA_EVT */
231typedef struct
232{
233    BT_HDR              hdr;
234    tNFA_EE_ECB        *p_cb;
235    UINT8               nfcee_id;
236    UINT16              data_len;
237    UINT8               *p_data;
238} tNFA_EE_API_SEND_DATA;
239
240/* data type for NFA_EE_API_DISCONNECT_EVT */
241typedef struct
242{
243    BT_HDR              hdr;
244    tNFA_EE_ECB        *p_cb;
245    UINT8               nfcee_id;
246} tNFA_EE_API_DISCONNECT;
247
248
249typedef struct
250{
251    BT_HDR              hdr;
252    tNFC_STATUS         status;                 /* The event status. */
253} tNFA_EE_MSG_STATUS;
254
255/* common data type for internal events with nfa_ee_use_cfg_cb[] as TRUE */
256typedef struct
257{
258    BT_HDR              hdr;
259    tNFA_EE_ECB        *p_cb;
260    UINT8               nfcee_id;
261} tNFA_EE_CFG_HDR;
262
263/* data type for tNFC_RESPONSE_EVT */
264typedef struct
265{
266    BT_HDR                      hdr;
267    void                        *p_data;
268} tNFA_EE_NCI_RESPONSE;
269
270/* data type for NFA_EE_NCI_DISC_RSP_EVT */
271typedef struct
272{
273    BT_HDR                      hdr;
274    tNFC_NFCEE_DISCOVER_REVT    *p_data;
275} tNFA_EE_NCI_DISC_RSP;
276
277/* data type for NFA_EE_NCI_DISC_NTF_EVT */
278typedef struct
279{
280    BT_HDR                      hdr;
281    tNFC_NFCEE_INFO_REVT        *p_data;
282} tNFA_EE_NCI_DISC_NTF;
283
284/* data type for NFA_EE_NCI_MODE_SET_RSP_EVT */
285typedef struct
286{
287    BT_HDR                      hdr;
288    tNFC_NFCEE_MODE_SET_REVT    *p_data;
289} tNFA_EE_NCI_MODE_SET;
290
291/* data type for NFA_EE_NCI_CONN_EVT and NFA_EE_NCI_DATA_EVT */
292typedef struct
293{
294    BT_HDR                      hdr;
295    UINT8                       conn_id;
296    tNFC_CONN_EVT               event;
297    tNFC_CONN                   *p_data;
298} tNFA_EE_NCI_CONN;
299
300/* data type for NFA_EE_NCI_ACTION_NTF_EVT */
301typedef struct
302{
303    BT_HDR                      hdr;
304    tNFC_EE_ACTION_REVT         *p_data;
305} tNFA_EE_NCI_ACTION;
306
307/* data type for NFA_EE_NCI_DISC_REQ_NTF_EVT */
308typedef struct
309{
310    BT_HDR                      hdr;
311    tNFC_EE_DISCOVER_REQ_REVT   *p_data;
312} tNFA_EE_NCI_DISC_REQ;
313
314/* union of all event data types */
315typedef union
316{
317    BT_HDR                      hdr;
318    tNFA_EE_CFG_HDR             cfg_hdr;
319    tNFA_EE_API_DISCOVER        ee_discover;
320    tNFA_EE_API_REGISTER        ee_register;
321    tNFA_EE_API_DEREGISTER      deregister;
322    tNFA_EE_API_MODE_SET        mode_set;
323    tNFA_EE_API_SET_TECH_CFG    set_tech;
324    tNFA_EE_API_SET_PROTO_CFG   set_proto;
325    tNFA_EE_API_ADD_AID         add_aid;
326    tNFA_EE_API_REMOVE_AID      rm_aid;
327    tNFA_EE_API_CONNECT         connect;
328    tNFA_EE_API_SEND_DATA       send_data;
329    tNFA_EE_API_DISCONNECT      disconnect;
330    tNFA_EE_NCI_DISC_RSP        disc_rsp;
331    tNFA_EE_NCI_DISC_NTF        disc_ntf;
332    tNFA_EE_NCI_MODE_SET        mode_set_rsp;
333    tNFA_EE_NCI_CONN            conn;
334    tNFA_EE_NCI_ACTION          act;
335    tNFA_EE_NCI_DISC_REQ        disc_req;
336} tNFA_EE_MSG;
337
338/* type for State Machine (SM) action functions */
339typedef void (*tNFA_EE_SM_ACT)(tNFA_EE_MSG *p_data);
340
341/*****************************************************************************
342**  control block
343*****************************************************************************/
344#define NFA_EE_CFGED_UPDATE_NOW         0x80
345#define NFA_EE_CFGED_OFF_ROUTING        0x40    /* either switch off or battery off is configured */
346
347/* the following status are the definition used in ee_cfg_sts */
348#define NFA_EE_STS_CHANGED_ROUTING      0x01
349#define NFA_EE_STS_CHANGED_VS           0x02
350#define NFA_EE_STS_CHANGED              0x0f
351#define NFA_EE_STS_PREV                 0xf0
352#define NFA_EE_STS_PREV_ROUTING         0x10
353
354#define NFA_EE_FLAG_WAIT_HCI            0x01    /* set this bit when waiting for HCI to finish the initialization process in NFA_EE_EM_STATE_RESTORING */
355#define NFA_EE_FLAG_NOTIFY_HCI          0x02    /* set this bit when EE needs to notify the p_enable_cback at the end of NFCEE discover process in NFA_EE_EM_STATE_RESTORING */
356typedef UINT8 tNFA_EE_FLAGS;
357
358typedef void (tNFA_EE_ENABLE_DONE_CBACK)(BOOLEAN disable_discover);
359
360/* NFA EE Management control block */
361typedef struct
362{
363    tNFA_EE_ECB          ecb[NFA_EE_NUM_ECBS];   /* control block for DH and NFCEEs  */
364    TIMER_LIST_ENT       timer;                  /* timer to send info to NFCC       */
365    TIMER_LIST_ENT       discv_timer;            /* timer to end NFCEE discovery     */
366    tNFA_EE_CBACK        *p_ee_cback[NFA_EE_MAX_CBACKS];/* to report EE events       */
367    tNFA_EE_CBACK        *p_ee_disc_cback;       /* to report EE discovery result    */
368    tNFA_EE_ENABLE_DONE_CBACK *p_enable_cback;   /* callback to notify on enable done*/
369    tNFA_EE_EM_STATE     em_state;               /* NFA-EE state initialized or not  */
370    UINT8                num_ee_expecting;       /* number of ee_info still expecting*/
371    UINT8                cur_ee;                 /* the number of ee_info in cb      */
372    UINT8                ee_cfged;               /* the bit mask of configured ECBs  */
373    UINT8                ee_cfg_sts;             /* configuration status             */
374    tNFA_EE_FLAGS        ee_flags;               /* flags                           */
375} tNFA_EE_CB;
376
377/*****************************************************************************
378**  External variables
379*****************************************************************************/
380
381/* NFA EE control block */
382#if NFA_DYNAMIC_MEMORY == FALSE
383extern tNFA_EE_CB nfa_ee_cb;
384#else
385extern tNFA_EE_CB *nfa_ee_cb_ptr;
386#define nfa_ee_cb (*nfa_ee_cb_ptr)
387#endif
388
389/*****************************************************************************
390**  External functions
391*****************************************************************************/
392/* function prototypes - exported from nfa_ee_main.c */
393void nfa_ee_sys_enable (void);
394void nfa_ee_sys_disable (void);
395
396/* event handler function type */
397BOOLEAN nfa_ee_evt_hdlr (BT_HDR *p_msg);
398void nfa_ee_proc_nfcc_power_mode (UINT8 nfcc_power_mode);
399#if (NFC_NFCEE_INCLUDED == TRUE)
400void nfa_ee_get_tech_route (UINT8 power_state, UINT8 *p_handles);
401#endif
402void nfa_ee_proc_evt(tNFC_RESPONSE_EVT event, void *p_data);
403tNFA_EE_ECB * nfa_ee_find_ecb (UINT8 nfcee_id);
404tNFA_EE_ECB * nfa_ee_find_ecb_by_conn_id (UINT8 conn_id);
405UINT8 nfa_ee_ecb_to_mask (tNFA_EE_ECB *p_cb);
406void nfa_ee_restore_one_ecb (tNFA_EE_ECB *p_cb);
407BOOLEAN nfa_ee_is_active (tNFA_HANDLE nfcee_id);
408
409/* Action function prototypes - nfa_ee_act.c */
410void nfa_ee_api_discover(tNFA_EE_MSG *p_data);
411void nfa_ee_api_register(tNFA_EE_MSG *p_data);
412void nfa_ee_api_deregister(tNFA_EE_MSG *p_data);
413void nfa_ee_api_mode_set(tNFA_EE_MSG *p_data);
414void nfa_ee_api_set_tech_cfg(tNFA_EE_MSG *p_data);
415void nfa_ee_api_set_proto_cfg(tNFA_EE_MSG *p_data);
416void nfa_ee_api_add_aid(tNFA_EE_MSG *p_data);
417void nfa_ee_api_remove_aid(tNFA_EE_MSG *p_data);
418void nfa_ee_api_update_now(tNFA_EE_MSG *p_data);
419void nfa_ee_api_connect(tNFA_EE_MSG *p_data);
420void nfa_ee_api_send_data(tNFA_EE_MSG *p_data);
421void nfa_ee_api_disconnect(tNFA_EE_MSG *p_data);
422void nfa_ee_report_disc_done(BOOLEAN notify_sys);
423void nfa_ee_nci_disc_rsp(tNFA_EE_MSG *p_data);
424void nfa_ee_nci_disc_ntf(tNFA_EE_MSG *p_data);
425void nfa_ee_nci_mode_set_rsp(tNFA_EE_MSG *p_data);
426void nfa_ee_nci_conn(tNFA_EE_MSG *p_data);
427void nfa_ee_nci_action_ntf(tNFA_EE_MSG *p_data);
428void nfa_ee_nci_disc_req_ntf(tNFA_EE_MSG *p_data);
429void nfa_ee_rout_timeout(tNFA_EE_MSG *p_data);
430void nfa_ee_discv_timeout(tNFA_EE_MSG *p_data);
431void nfa_ee_lmrt_to_nfcc(tNFA_EE_MSG *p_data);
432void nfa_ee_update_rout(void);
433void nfa_ee_report_event(tNFA_EE_CBACK *p_cback, tNFA_EE_EVT event, tNFA_EE_CBACK_DATA *p_data);
434tNFA_EE_ECB * nfa_ee_find_aid_offset(UINT8 aid_len, UINT8 *p_aid, int *p_offset, int *p_entry);
435void nfa_ee_remove_labels(void);
436int nfa_ee_find_total_aid_len(tNFA_EE_ECB *p_cb, int start_entry);
437void nfa_ee_start_timer(void);
438void nfa_ee_reg_cback_enable_done (tNFA_EE_ENABLE_DONE_CBACK *p_cback);
439
440extern void nfa_ee_proc_hci_info_cback (void);
441
442
443#endif /* NFA_P2P_INT_H */
444