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  *  This is the private interface file for the NFA EE.
22  *
23  ******************************************************************************/
24 #ifndef NFA_EE_INT_H
25 #define NFA_EE_INT_H
26 #include "nfa_ee_api.h"
27 #include "nfa_sys.h"
28 #include "nfc_api.h"
29 
30 /*****************************************************************************
31 **  Constants and data types
32 *****************************************************************************/
33 /* the number of tNFA_EE_ECBs (for NFCEEs and DH) */
34 #define NFA_EE_NUM_ECBS (NFA_EE_MAX_EE_SUPPORTED + 1)
35 /* The index for DH in nfa_ee_cb.ee_cb[] */
36 #define NFA_EE_CB_4_DH NFA_EE_MAX_EE_SUPPORTED
37 #define NFA_EE_INVALID 0xFF
38 /* only A, B, F, Bprime are supported by UICC now */
39 #define NFA_EE_MAX_TECH_ROUTE 4
40 
41 #ifndef NFA_EE_AID_CFG_TAG_NAME
42 /* AID                             */
43 #define NFA_EE_AID_CFG_TAG_NAME 0x4F
44 #endif
45 
46 /* NFA EE events */
47 enum {
48   NFA_EE_API_DISCOVER_EVT = NFA_SYS_EVT_START(NFA_ID_EE),
49   NFA_EE_API_REGISTER_EVT,
50   NFA_EE_API_DEREGISTER_EVT,
51   NFA_EE_API_MODE_SET_EVT,
52   NFA_EE_API_SET_TECH_CFG_EVT,
53   NFA_EE_API_CLEAR_TECH_CFG_EVT,
54   NFA_EE_API_SET_PROTO_CFG_EVT,
55   NFA_EE_API_CLEAR_PROTO_CFG_EVT,
56   NFA_EE_API_ADD_AID_EVT,
57   NFA_EE_API_REMOVE_AID_EVT,
58   NFA_EE_API_ADD_SYSCODE_EVT,
59   NFA_EE_API_REMOVE_SYSCODE_EVT,
60   NFA_EE_API_LMRT_SIZE_EVT,
61   NFA_EE_API_UPDATE_NOW_EVT,
62   NFA_EE_API_CONNECT_EVT,
63   NFA_EE_API_SEND_DATA_EVT,
64   NFA_EE_API_DISCONNECT_EVT,
65   NFA_EE_API_PWR_AND_LINK_CTRL_EVT,
66 
67   NFA_EE_NCI_DISC_RSP_EVT,
68   NFA_EE_NCI_DISC_NTF_EVT,
69   NFA_EE_NCI_MODE_SET_RSP_EVT,
70   NFA_EE_NCI_CONN_EVT,
71   NFA_EE_NCI_DATA_EVT,
72   NFA_EE_NCI_ACTION_NTF_EVT,
73   NFA_EE_NCI_DISC_REQ_NTF_EVT,
74   NFA_EE_NCI_WAIT_RSP_EVT,
75 
76   NFA_EE_ROUT_TIMEOUT_EVT,
77   NFA_EE_DISCV_TIMEOUT_EVT,
78   NFA_EE_CFG_TO_NFCC_EVT,
79   NFA_EE_NCI_NFCEE_STATUS_NTF_EVT,
80   NFA_EE_PWR_CONTROL_EVT,
81   NFA_EE_MAX_EVT
82 };
83 
84 typedef uint16_t tNFA_EE_INT_EVT;
85 /* for listen mode routing table*/
86 #define NFA_EE_AE_ROUTE 0x80
87 #define NFA_EE_AE_VS 0x40
88 
89 /* NFA EE Management state */
90 enum {
91   NFA_EE_EM_STATE_INIT = 0,
92   NFA_EE_EM_STATE_INIT_DONE,
93   NFA_EE_EM_STATE_RESTORING,
94   NFA_EE_EM_STATE_DISABLING,
95   NFA_EE_EM_STATE_DISABLED,
96 
97   NFA_EE_EM_STATE_MAX
98 };
99 typedef uint8_t tNFA_EE_EM_STATE;
100 
101 /* NFA EE connection status */
102 enum {
103   NFA_EE_CONN_ST_NONE, /* not connected */
104   NFA_EE_CONN_ST_WAIT, /* connection is initiated; waiting for ack */
105   NFA_EE_CONN_ST_CONN, /* connected; can send/receive data */
106   NFA_EE_CONN_ST_DISC  /* disconnecting; waiting for ack */
107 };
108 typedef uint8_t tNFA_EE_CONN_ST;
109 
110 #define NFA_EE_MAX_AID_CFG_LEN (510)
111 // Technology A/B/F reserved: 5*3 = 15
112 // Protocol ISODEP/NFCDEP/T3T reserved: 5*3 = 15
113 // Extends (APDU pattern/SC)reserved: 30
114 #define NFA_EE_MAX_PROTO_TECH_EXT_ROUTE_LEN 60
115 
116 #define NFA_EE_SYSTEM_CODE_LEN 02
117 #define NFA_EE_SYSTEM_CODE_TLV_SIZE 06
118 #define NFA_EE_MAX_SYSTEM_CODE_ENTRIES 10
119 #define NFA_EE_MAX_SYSTEM_CODE_CFG_LEN \
120   (NFA_EE_MAX_SYSTEM_CODE_ENTRIES * NFA_EE_SYSTEM_CODE_TLV_SIZE)
121 
122 /* NFA EE control block flags:
123  * use to indicate an API function has changed the configuration of the
124  * associated NFCEE
125  * The flags are cleared when the routing table/VS is updated */
126 /* technology routing changed         */
127 #define NFA_EE_ECB_FLAGS_TECH 0x02
128 /* protocol routing changed           */
129 #define NFA_EE_ECB_FLAGS_PROTO 0x04
130 /* AID routing changed                */
131 #define NFA_EE_ECB_FLAGS_AID 0x08
132 /* System Code routing changed        */
133 #define NFA_EE_ECB_FLAGS_SYSCODE 0x01
134 /* VS changed                         */
135 #define NFA_EE_ECB_FLAGS_VS 0x10
136 /* Restore related                    */
137 #define NFA_EE_ECB_FLAGS_RESTORE 0x20
138 /* routing flags changed              */
139 #define NFA_EE_ECB_FLAGS_ROUTING 0x0E
140 /* NFCEE Discover Request NTF is set  */
141 #define NFA_EE_ECB_FLAGS_DISC_REQ 0x40
142 /* DISC_REQ N reported before DISC N  */
143 #define NFA_EE_ECB_FLAGS_ORDER 0x80
144 typedef uint8_t tNFA_EE_ECB_FLAGS;
145 
146 /* part of tNFA_EE_STATUS; for internal use only  */
147 /* waiting for restore to full power mode to complete */
148 #define NFA_EE_STATUS_RESTORING 0x20
149 /* this bit is in ee_status for internal use only */
150 #define NFA_EE_STATUS_INT_MASK 0x20
151 
152 /* NFA-EE information for a particular NFCEE Entity (including DH) */
153 typedef struct {
154   tNFA_TECHNOLOGY_MASK
155       tech_switch_on; /* default routing - technologies switch_on  */
156   tNFA_TECHNOLOGY_MASK
157       tech_switch_off; /* default routing - technologies switch_off */
158   tNFA_TECHNOLOGY_MASK
159       tech_battery_off; /* default routing - technologies battery_off*/
160   tNFA_TECHNOLOGY_MASK
161       tech_screen_lock; /* default routing - technologies screen_lock*/
162   tNFA_TECHNOLOGY_MASK
163       tech_screen_off; /* default routing - technologies screen_off*/
164   tNFA_TECHNOLOGY_MASK
165       tech_screen_off_lock; /* default routing - technologies screen_off_lock*/
166   tNFA_PROTOCOL_MASK
167       proto_switch_on; /* default routing - protocols switch_on     */
168   tNFA_PROTOCOL_MASK
169       proto_switch_off; /* default routing - protocols switch_off    */
170   tNFA_PROTOCOL_MASK
171       proto_battery_off;     /* default routing - protocols battery_off   */
172   tNFA_PROTOCOL_MASK
173       proto_screen_lock; /* default routing - protocols screen_lock    */
174   tNFA_PROTOCOL_MASK
175       proto_screen_off; /* default routing - protocols screen_off  */
176   tNFA_PROTOCOL_MASK
177       proto_screen_off_lock; /* default routing - protocols screen_off_lock  */
178   tNFA_EE_CONN_ST conn_st;   /* connection status */
179   uint8_t conn_id;           /* connection id */
180   tNFA_EE_CBACK* p_ee_cback; /* the callback function */
181 
182   /* Each AID entry has an ssociated aid_len, aid_pwr_cfg, aid_rt_info.
183    * aid_cfg[] contains AID and maybe some other VS information in TLV format
184    * The first T is always NFA_EE_AID_CFG_TAG_NAME, the L is the actual AID
185    * length
186    * the aid_len is the total length of all the TLVs associated with this AID
187    * entry
188    */
189   uint8_t* aid_len;     /* the actual lengths in aid_cfg */
190   uint8_t* aid_pwr_cfg; /* power configuration of this
191                                                   AID entry */
192   uint8_t* aid_rt_info; /* route/vs info for this AID
193                                                   entry */
194   uint8_t* aid_cfg;     /* routing entries based on AID */
195   uint8_t* aid_info;    /* Aid Info Prefix/Suffix/Exact */
196 
197   uint8_t aid_entries;   /* The number of AID entries in aid_cfg */
198   uint8_t nfcee_id;      /* ID for this NFCEE */
199   uint8_t ee_status;     /* The NFCEE status */
200   uint8_t ee_old_status; /* The NFCEE status before going to low power mode */
201   tNFA_EE_INTERFACE
202       ee_interface[NFC_MAX_EE_INTERFACE]; /* NFCEE supported interface */
203   tNFA_EE_TLV ee_tlv[NFC_MAX_EE_TLVS];    /* the TLV */
204   uint8_t num_interface;                  /* number of Target interface */
205   uint8_t num_tlvs;                       /* number of TLVs */
206   uint8_t ee_power_supply_status;         /* power supply of NFCEE*/
207   tNFA_EE_ECB_FLAGS ecb_flags;            /* the flags of this control block */
208   tNFA_EE_INTERFACE use_interface; /* NFCEE interface used for the connection */
209   tNFA_NFC_PROTOCOL la_protocol;   /* Listen A protocol    */
210   tNFA_NFC_PROTOCOL lb_protocol;   /* Listen B protocol    */
211   tNFA_NFC_PROTOCOL lf_protocol;   /* Listen F protocol    */
212   tNFA_NFC_PROTOCOL lbp_protocol;  /* Listen B' protocol   */
213   uint8_t size_mask_proto;         /* the size for protocol routing */
214   uint8_t size_mask_tech;          /* the size for technology routing */
215   uint16_t size_aid; /* the size for aid routing */
216   /*System Code Based Routing Variables*/
217   uint8_t sys_code_cfg[NFA_EE_MAX_SYSTEM_CODE_ENTRIES * NFA_EE_SYSTEM_CODE_LEN];
218   uint8_t sys_code_pwr_cfg[NFA_EE_MAX_SYSTEM_CODE_ENTRIES];
219   uint8_t sys_code_rt_loc[NFA_EE_MAX_SYSTEM_CODE_ENTRIES];
220   uint8_t sys_code_rt_loc_vs_info[NFA_EE_MAX_SYSTEM_CODE_ENTRIES];
221   /* The number of SC entries in sys_code_cfg buffer*/
222   uint8_t sys_code_cfg_entries;
223   uint16_t size_sys_code; /* The size for system code routing */
224 } tNFA_EE_ECB;
225 
226 /* data type for NFA_EE_API_DISCOVER_EVT */
227 typedef struct {
228   NFC_HDR hdr;
229   tNFA_EE_CBACK* p_cback;
230 } tNFA_EE_API_DISCOVER;
231 
232 /* data type for NFA_EE_API_REGISTER_EVT */
233 typedef struct {
234   NFC_HDR hdr;
235   tNFA_EE_CBACK* p_cback;
236 } tNFA_EE_API_REGISTER;
237 
238 /* data type for NFA_EE_API_DEREGISTER_EVT */
239 typedef struct {
240   NFC_HDR hdr;
241   int index;
242 } tNFA_EE_API_DEREGISTER;
243 
244 /* data type for NFA_EE_API_MODE_SET_EVT */
245 typedef struct {
246   NFC_HDR hdr;
247   tNFA_EE_ECB* p_cb;
248   uint8_t nfcee_id;
249   uint8_t mode;
250 } tNFA_EE_API_MODE_SET;
251 
252 /* data type for NFA_EE_API_SET_TECH_CFG_EVT */
253 typedef struct {
254   NFC_HDR hdr;
255   tNFA_EE_ECB* p_cb;
256   uint8_t nfcee_id;
257   tNFA_TECHNOLOGY_MASK technologies_switch_on;
258   tNFA_TECHNOLOGY_MASK technologies_switch_off;
259   tNFA_TECHNOLOGY_MASK technologies_battery_off;
260   tNFA_TECHNOLOGY_MASK technologies_screen_lock;
261   tNFA_TECHNOLOGY_MASK technologies_screen_off;
262   tNFA_TECHNOLOGY_MASK technologies_screen_off_lock;
263 } tNFA_EE_API_SET_TECH_CFG, tNFA_EE_API_CLEAR_TECH_CFG;
264 
265 /* data type for NFA_EE_API_SET_PROTO_CFG_EVT */
266 typedef struct {
267   NFC_HDR hdr;
268   tNFA_EE_ECB* p_cb;
269   uint8_t nfcee_id;
270   tNFA_PROTOCOL_MASK protocols_switch_on;
271   tNFA_PROTOCOL_MASK protocols_switch_off;
272   tNFA_PROTOCOL_MASK protocols_battery_off;
273   tNFA_PROTOCOL_MASK protocols_screen_lock;
274   tNFA_PROTOCOL_MASK protocols_screen_off;
275   tNFA_PROTOCOL_MASK protocols_screen_off_lock;
276 } tNFA_EE_API_SET_PROTO_CFG, tNFA_EE_API_CLEAR_PROTO_CFG;
277 
278 /* data type for NFA_EE_API_ADD_AID_EVT */
279 typedef struct {
280   NFC_HDR hdr;
281   tNFA_EE_ECB* p_cb;
282   uint8_t nfcee_id;
283   uint8_t aid_len;
284   uint8_t* p_aid;
285   tNFA_EE_PWR_STATE power_state;
286   uint8_t aidInfo;
287 } tNFA_EE_API_ADD_AID;
288 
289 /* data type for NFA_EE_API_REMOVE_AID_EVT */
290 typedef struct {
291   NFC_HDR hdr;
292   uint8_t aid_len;
293   uint8_t* p_aid;
294 } tNFA_EE_API_REMOVE_AID;
295 
296 /* data type for NFA_EE_API_ADD_SYSCODE_EVT */
297 typedef struct {
298   NFC_HDR hdr;
299   tNFA_EE_ECB* p_cb;
300   uint8_t nfcee_id;
301   uint16_t syscode;
302   tNFA_EE_PWR_STATE power_state;
303 } tNFA_EE_API_ADD_SYSCODE;
304 
305 /* data type for NFA_EE_API_REMOVE_SYSCODE_EVT */
306 typedef struct {
307   NFC_HDR hdr;
308   uint16_t syscode;
309 } tNFA_EE_API_REMOVE_SYSCODE;
310 
311 /* data type for NFA_EE_API_LMRT_SIZE_EVT */
312 typedef NFC_HDR tNFA_EE_API_LMRT_SIZE;
313 
314 /* data type for NFA_EE_API_CONNECT_EVT */
315 typedef struct {
316   NFC_HDR hdr;
317   tNFA_EE_ECB* p_cb;
318   uint8_t nfcee_id;
319   uint8_t ee_interface;
320   tNFA_EE_CBACK* p_cback;
321 } tNFA_EE_API_CONNECT;
322 
323 /* data type for NFA_EE_API_SEND_DATA_EVT */
324 typedef struct {
325   NFC_HDR hdr;
326   tNFA_EE_ECB* p_cb;
327   uint8_t nfcee_id;
328   uint16_t data_len;
329   uint8_t* p_data;
330 } tNFA_EE_API_SEND_DATA;
331 
332 /* data type for NFA_EE_API_DISCONNECT_EVT */
333 typedef struct {
334   NFC_HDR hdr;
335   tNFA_EE_ECB* p_cb;
336   uint8_t nfcee_id;
337 } tNFA_EE_API_DISCONNECT;
338 
339 /* data type for NFA_EE_API_PWR_AND_LINK_CTRL_EVT */
340 typedef struct {
341   NFC_HDR hdr;
342   tNFA_EE_ECB* p_cb;
343   uint8_t nfcee_id;
344   uint8_t config;
345 } tNFA_EE_API_PWR_AND_LINK_CTRL;
346 
347 /* common data type for internal events with nfa_ee_use_cfg_cb[] as TRUE */
348 typedef struct {
349   NFC_HDR hdr;
350   tNFA_EE_ECB* p_cb;
351   uint8_t nfcee_id;
352 } tNFA_EE_CFG_HDR;
353 
354 /* data type for NFA_EE_NCI_DISC_RSP_EVT */
355 typedef struct {
356   NFC_HDR hdr;
357   tNFC_NFCEE_DISCOVER_REVT* p_data;
358 } tNFA_EE_NCI_DISC_RSP;
359 
360 /* data type for NFA_EE_NCI_DISC_NTF_EVT */
361 typedef struct {
362   NFC_HDR hdr;
363   tNFC_NFCEE_INFO_REVT* p_data;
364 } tNFA_EE_NCI_DISC_NTF;
365 
366 /* data type for NFA_EE_NCI_MODE_SET_RSP_EVT */
367 typedef struct {
368   NFC_HDR hdr;
369   tNFC_NFCEE_MODE_SET_REVT* p_data;
370 } tNFA_EE_NCI_MODE_SET;
371 
372 /* data type for NFA_EE_NCI_WAIT_RSP_EVT */
373 typedef struct {
374   NFC_HDR hdr;
375   void* p_data;
376   uint8_t opcode;
377 } tNFA_EE_NCI_WAIT_RSP;
378 
379 /* data type for NFA_EE_NCI_CONN_EVT and NFA_EE_NCI_DATA_EVT */
380 typedef struct {
381   NFC_HDR hdr;
382   uint8_t conn_id;
383   tNFC_CONN_EVT event;
384   tNFC_CONN* p_data;
385 } tNFA_EE_NCI_CONN;
386 
387 /* data type for NFA_EE_NCI_ACTION_NTF_EVT */
388 typedef struct {
389   NFC_HDR hdr;
390   tNFC_EE_ACTION_REVT* p_data;
391 } tNFA_EE_NCI_ACTION;
392 
393 /* data type for NFA_EE_NCI_DISC_REQ_NTF_EVT */
394 typedef struct {
395   NFC_HDR hdr;
396   tNFC_EE_DISCOVER_REQ_REVT* p_data;
397 } tNFA_EE_NCI_DISC_REQ;
398 
399 /* data type for NFA_EE_NCI_NFCEE_STATUS_EVT */
400 typedef struct {
401   NFC_HDR hdr;
402   tNFC_NFCEE_STATUS_REVT* p_data;
403 } tNFA_EE_NCI_NFCEE_STATUS_NTF;
404 
405 /* data type for NFA_EE_NCI_NFCEE_STATUS_EVT */
406 typedef struct {
407   NFC_HDR hdr;
408   tNFC_NFCEE_PL_CONTROL_REVT* p_data;
409 } tNFA_EE_NCI_PWR_AND_LINK_CTRL_RSP;
410 
411 /* union of all event data types */
412 typedef union {
413   NFC_HDR hdr;
414   tNFA_EE_CFG_HDR cfg_hdr;
415   tNFA_EE_API_DISCOVER ee_discover;
416   tNFA_EE_API_REGISTER ee_register;
417   tNFA_EE_API_DEREGISTER deregister;
418   tNFA_EE_API_MODE_SET mode_set;
419   tNFA_EE_API_SET_TECH_CFG set_tech;
420   tNFA_EE_API_CLEAR_TECH_CFG clear_tech;
421   tNFA_EE_API_SET_PROTO_CFG set_proto;
422   tNFA_EE_API_CLEAR_PROTO_CFG clear_proto;
423   tNFA_EE_API_ADD_AID add_aid;
424   tNFA_EE_API_REMOVE_AID rm_aid;
425   tNFA_EE_API_ADD_SYSCODE add_syscode;
426   tNFA_EE_API_REMOVE_SYSCODE rm_syscode;
427   tNFA_EE_API_LMRT_SIZE lmrt_size;
428   tNFA_EE_API_CONNECT connect;
429   tNFA_EE_API_SEND_DATA send_data;
430   tNFA_EE_API_DISCONNECT disconnect;
431   tNFA_EE_API_PWR_AND_LINK_CTRL pwr_and_link_ctrl;
432   tNFA_EE_NCI_DISC_RSP disc_rsp;
433   tNFA_EE_NCI_DISC_NTF disc_ntf;
434   tNFA_EE_NCI_MODE_SET mode_set_rsp;
435   tNFA_EE_NCI_WAIT_RSP wait_rsp;
436   tNFA_EE_NCI_CONN conn;
437   tNFA_EE_NCI_ACTION act;
438   tNFA_EE_NCI_DISC_REQ disc_req;
439   tNFA_EE_NCI_NFCEE_STATUS_NTF nfcee_status_ntf;
440   tNFA_EE_NCI_PWR_AND_LINK_CTRL_RSP ncfee_pwr_and_link_ctrl_rsp;
441 } tNFA_EE_MSG;
442 
443 /* type for State Machine (SM) action functions */
444 typedef void (*tNFA_EE_SM_ACT)(tNFA_EE_MSG* p_data);
445 
446 /*****************************************************************************
447 **  control block
448 *****************************************************************************/
449 #define NFA_EE_CFGED_UPDATE_NOW 0x80
450 /* either switch off or battery off is configured */
451 #define NFA_EE_CFGED_OFF_ROUTING 0x40
452 
453 /* the following status are the definition used in ee_cfg_sts */
454 #define NFA_EE_STS_CHANGED_ROUTING 0x01
455 #define NFA_EE_STS_CHANGED 0x0f
456 #define NFA_EE_STS_PREV_ROUTING 0x10
457 #define NFA_EE_STS_PREV 0xf0
458 
459 /* need to report NFA_EE_UPDATED_EVT */
460 #define NFA_EE_WAIT_UPDATE 0x10
461 /* waiting for the rsp of set routing commands */
462 #define NFA_EE_WAIT_UPDATE_RSP 0x20
463 #define NFA_EE_WAIT_UPDATE_ALL 0xF0
464 
465 typedef uint8_t tNFA_EE_WAIT;
466 
467 /* set this bit when waiting for HCI to finish the initialization process in
468  * NFA_EE_EM_STATE_RESTORING */
469 #define NFA_EE_FLAG_WAIT_HCI 0x01
470 /* set this bit when EE needs to notify the p_enable_cback at the end of NFCEE
471  * discover process in NFA_EE_EM_STATE_RESTORING */
472 #define NFA_EE_FLAG_NOTIFY_HCI 0x02
473 /* set this bit when gracefully disable with outstanding NCI connections */
474 #define NFA_EE_FLAG_WAIT_DISCONN 0x04
475 typedef uint8_t tNFA_EE_FLAGS;
476 
477 /* NFCEE DISCOVER in progress       */
478 #define NFA_EE_DISC_STS_ON 0x00
479 /* disable NFCEE DISCOVER           */
480 #define NFA_EE_DISC_STS_OFF 0x01
481 /* received NFCEE DISCOVER REQ NTF  */
482 #define NFA_EE_DISC_STS_REQ 0x02
483 /* received NFA_EE_MODE_SET_COMPLETE  */
484 #define NFA_EE_MODE_SET_COMPLETE 0x03
485 /* initialize EE_RECOVERY             */
486 #define NFA_EE_RECOVERY_INIT 0x04
487 /* update ee config during EE_RECOVERY */
488 #define NFA_EE_RECOVERY_REDISCOVERED 0x05
489 typedef uint8_t tNFA_EE_DISC_STS;
490 
491 typedef void(tNFA_EE_ENABLE_DONE_CBACK)(tNFA_EE_DISC_STS status);
492 
493 /* NFA EE Management control block */
494 typedef struct {
495   tNFA_EE_ECB ecb[NFA_EE_NUM_ECBS]; /* control block for DH and NFCEEs  */
496   TIMER_LIST_ENT timer;             /* timer to send info to NFCC       */
497   TIMER_LIST_ENT discv_timer;       /* timer to end NFCEE discovery     */
498   tNFA_EE_CBACK* p_ee_cback[NFA_EE_MAX_CBACKS]; /* to report EE events       */
499   tNFA_EE_CBACK* p_ee_disc_cback; /* to report EE discovery result    */
500   tNFA_EE_ENABLE_DONE_CBACK*
501       p_enable_cback;          /* callback to notify on enable done*/
502   tNFA_EE_EM_STATE em_state;   /* NFA-EE state initialized or not  */
503   uint8_t wait_rsp;            /* num of NCI rsp expected (update) */
504   uint8_t num_ee_expecting;    /* number of ee_info still expecting*/
505   uint8_t cur_ee;              /* the number of ee_info in cb      */
506   uint8_t ee_cfged;            /* the bit mask of configured ECBs  */
507   uint8_t ee_cfg_sts;          /* configuration status             */
508   tNFA_EE_WAIT ee_wait_evt;    /* Pending event(s) to be reported  */
509   tNFA_EE_FLAGS ee_flags;      /* flags                            */
510   uint8_t route_block_control; /* controls route block feature   */
511   bool isDiscoveryStopped;     /* discovery status                  */
512 } tNFA_EE_CB;
513 
514 /* Order of Routing entries in Routing Table */
515 #define NCI_ROUTE_ORDER_AID 0x01        /* AID routing order */
516 #define NCI_ROUTE_ORDER_SYS_CODE 0x03   /* System Code routing order*/
517 #define NCI_ROUTE_ORDER_PROTOCOL 0x04   /* Protocol routing order*/
518 #define NCI_ROUTE_ORDER_TECHNOLOGY 0x05 /* Technology routing order*/
519 
520 /*****************************************************************************
521 **  External variables
522 *****************************************************************************/
523 
524 /* NFA EE control block */
525 extern tNFA_EE_CB nfa_ee_cb;
526 
527 /*****************************************************************************
528 **  External functions
529 *****************************************************************************/
530 /* function prototypes - exported from nfa_ee_main.c */
531 void nfa_ee_sys_enable(void);
532 void nfa_ee_sys_disable(void);
533 
534 /* event handler function type */
535 bool nfa_ee_evt_hdlr(NFC_HDR* p_msg);
536 void nfa_ee_proc_nfcc_power_mode(uint8_t nfcc_power_mode);
537 #if (NFC_NFCEE_INCLUDED == TRUE)
538 void nfa_ee_get_tech_route(uint8_t power_state, uint8_t* p_handles);
539 #endif
540 void nfa_ee_proc_evt(tNFC_RESPONSE_EVT event, void* p_data);
541 tNFA_EE_ECB* nfa_ee_find_ecb(uint8_t nfcee_id);
542 tNFA_EE_ECB* nfa_ee_find_ecb_by_conn_id(uint8_t conn_id);
543 uint8_t nfa_ee_ecb_to_mask(tNFA_EE_ECB* p_cb);
544 void nfa_ee_restore_one_ecb(tNFA_EE_ECB* p_cb);
545 bool nfa_ee_is_active(tNFA_HANDLE nfcee_id);
546 
547 /* Action function prototypes - nfa_ee_act.c */
548 void nfa_ee_api_discover(tNFA_EE_MSG* p_data);
549 void nfa_ee_api_register(tNFA_EE_MSG* p_data);
550 void nfa_ee_api_deregister(tNFA_EE_MSG* p_data);
551 void nfa_ee_api_mode_set(tNFA_EE_MSG* p_data);
552 void nfa_ee_api_set_tech_cfg(tNFA_EE_MSG* p_data);
553 void nfa_ee_api_clear_tech_cfg(tNFA_EE_MSG* p_data);
554 void nfa_ee_api_set_proto_cfg(tNFA_EE_MSG* p_data);
555 void nfa_ee_api_clear_proto_cfg(tNFA_EE_MSG* p_data);
556 void nfa_ee_api_add_aid(tNFA_EE_MSG* p_data);
557 void nfa_ee_api_remove_aid(tNFA_EE_MSG* p_data);
558 void nfa_ee_api_add_sys_code(tNFA_EE_MSG* p_data);
559 void nfa_ee_api_remove_sys_code(tNFA_EE_MSG* p_data);
560 void nfa_ee_api_lmrt_size(tNFA_EE_MSG* p_data);
561 void nfa_ee_api_update_now(tNFA_EE_MSG* p_data);
562 void nfa_ee_api_connect(tNFA_EE_MSG* p_data);
563 void nfa_ee_api_send_data(tNFA_EE_MSG* p_data);
564 void nfa_ee_api_disconnect(tNFA_EE_MSG* p_data);
565 void nfa_ee_api_pwr_and_link_ctrl(tNFA_EE_MSG* p_data);
566 void nfa_ee_report_disc_done(bool notify_sys);
567 void nfa_ee_nci_disc_rsp(tNFA_EE_MSG* p_data);
568 void nfa_ee_nci_disc_ntf(tNFA_EE_MSG* p_data);
569 void nfa_ee_nci_mode_set_rsp(tNFA_EE_MSG* p_data);
570 void nfa_ee_nci_nfcee_status_ntf(tNFA_EE_MSG* p_data);
571 void nfa_ee_pwr_and_link_ctrl_rsp(tNFA_EE_MSG* p_data);
572 void nfa_ee_nci_wait_rsp(tNFA_EE_MSG* p_data);
573 void nfa_ee_nci_conn(tNFA_EE_MSG* p_data);
574 void nfa_ee_nci_action_ntf(tNFA_EE_MSG* p_data);
575 void nfa_ee_nci_disc_req_ntf(tNFA_EE_MSG* p_data);
576 void nfa_ee_rout_timeout(tNFA_EE_MSG* p_data);
577 void nfa_ee_discv_timeout(tNFA_EE_MSG* p_data);
578 void nfa_ee_lmrt_to_nfcc(tNFA_EE_MSG* p_data);
579 void nfa_ee_update_rout(void);
580 void nfa_ee_report_event(tNFA_EE_CBACK* p_cback, tNFA_EE_EVT event,
581                          tNFA_EE_CBACK_DATA* p_data);
582 tNFA_EE_ECB* nfa_ee_find_aid_offset(uint8_t aid_len, uint8_t* p_aid,
583                                     int* p_offset, int* p_entry);
584 tNFA_EE_ECB* nfa_ee_find_sys_code_offset(uint16_t sys_code, int* p_offset,
585                                          int* p_entry);
586 int nfa_ee_find_total_aid_len(tNFA_EE_ECB* p_cb, int start_entry);
587 void nfa_ee_start_timer(void);
588 void nfa_ee_reg_cback_enable_done(tNFA_EE_ENABLE_DONE_CBACK* p_cback);
589 void nfa_ee_report_update_evt(void);
590 
591 extern void nfa_ee_proc_hci_info_cback(void);
592 void nfa_ee_check_disable(void);
593 bool nfa_ee_restore_ntf_done(void);
594 void nfa_ee_check_restore_complete(void);
595 int nfa_ee_find_max_aid_cfg_len(void);
596 #endif /* NFA_P2P_INT_H */
597