1 /******************************************************************************
2 *
3 * Copyright (C) 2010-2012 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 main implementation file for the NFA EE.
22 *
23 ******************************************************************************/
24 #include <string.h>
25 #include "nfc_api.h"
26 #include "nfa_sys.h"
27 #include "nfa_sys_int.h"
28 #include "nfa_dm_int.h"
29 #include "nfa_ee_int.h"
30
31 extern void nfa_ee_vs_cback (tNFC_VS_EVT event, BT_HDR *p_data);
32 /*****************************************************************************
33 ** Global Variables
34 *****************************************************************************/
35
36 /* system manager control block definition */
37 #if NFA_DYNAMIC_MEMORY == FALSE
38 tNFA_EE_CB nfa_ee_cb;
39 #endif
40
41 #ifndef NFA_EE_DISCV_TIMEOUT_VAL
42 #define NFA_EE_DISCV_TIMEOUT_VAL 2000
43 #endif
44
45
46 /*****************************************************************************
47 ** Constants
48 *****************************************************************************/
49 static const tNFA_SYS_REG nfa_ee_sys_reg =
50 {
51 nfa_ee_sys_enable,
52 nfa_ee_evt_hdlr,
53 nfa_ee_sys_disable,
54 nfa_ee_proc_nfcc_power_mode
55 };
56
57
58 #define NFA_EE_NUM_ACTIONS (NFA_EE_MAX_EVT & 0x00ff)
59
60
61 const tNFA_EE_SM_ACT nfa_ee_actions[] =
62 {
63 /* NFA-EE action function/ internal events */
64 nfa_ee_api_discover , /* NFA_EE_API_DISCOVER_EVT */
65 nfa_ee_api_register , /* NFA_EE_API_REGISTER_EVT */
66 nfa_ee_api_deregister , /* NFA_EE_API_DEREGISTER_EVT */
67 nfa_ee_api_mode_set , /* NFA_EE_API_MODE_SET_EVT */
68 nfa_ee_api_set_tech_cfg , /* NFA_EE_API_SET_TECH_CFG_EVT */
69 nfa_ee_api_set_proto_cfg, /* NFA_EE_API_SET_PROTO_CFG_EVT */
70 nfa_ee_api_add_aid , /* NFA_EE_API_ADD_AID_EVT */
71 nfa_ee_api_remove_aid , /* NFA_EE_API_REMOVE_AID_EVT */
72 nfa_ee_api_update_now , /* NFA_EE_API_UPDATE_NOW_EVT */
73 nfa_ee_api_connect , /* NFA_EE_API_CONNECT_EVT */
74 nfa_ee_api_send_data , /* NFA_EE_API_SEND_DATA_EVT */
75 nfa_ee_api_disconnect , /* NFA_EE_API_DISCONNECT_EVT */
76 nfa_ee_nci_disc_rsp , /* NFA_EE_NCI_DISC_RSP_EVT */
77 nfa_ee_nci_disc_ntf , /* NFA_EE_NCI_DISC_NTF_EVT */
78 nfa_ee_nci_mode_set_rsp , /* NFA_EE_NCI_MODE_SET_RSP_EVT */
79 nfa_ee_nci_conn , /* NFA_EE_NCI_CONN_EVT */
80 nfa_ee_nci_conn , /* NFA_EE_NCI_DATA_EVT */
81 nfa_ee_nci_action_ntf , /* NFA_EE_NCI_ACTION_NTF_EVT */
82 nfa_ee_nci_disc_req_ntf , /* NFA_EE_NCI_DISC_REQ_NTF_EVT */
83 nfa_ee_rout_timeout , /* NFA_EE_ROUT_TIMEOUT_EVT */
84 nfa_ee_discv_timeout , /* NFA_EE_DISCV_TIMEOUT_EVT */
85 nfa_ee_lmrt_to_nfcc /* NFA_EE_CFG_TO_NFCC_EVT */
86 };
87
88
89 /*******************************************************************************
90 **
91 ** Function nfa_ee_init
92 **
93 ** Description Initialize NFA EE control block
94 ** register to NFA SYS
95 **
96 ** Returns None
97 **
98 *******************************************************************************/
nfa_ee_init(void)99 void nfa_ee_init (void)
100 {
101 int xx;
102
103 NFA_TRACE_DEBUG0 ("nfa_ee_init ()");
104
105 /* initialize control block */
106 memset (&nfa_ee_cb, 0, sizeof (tNFA_EE_CB));
107 for (xx = 0; xx < NFA_EE_MAX_EE_SUPPORTED; xx++)
108 {
109 nfa_ee_cb.ecb[xx].nfcee_id = NFA_EE_INVALID;
110 nfa_ee_cb.ecb[xx].ee_status = NFC_NFCEE_STATUS_INACTIVE;
111 }
112
113 nfa_ee_cb.ecb[NFA_EE_CB_4_DH].ee_status = NFC_NFCEE_STATUS_ACTIVE;
114 nfa_ee_cb.ecb[NFA_EE_CB_4_DH].nfcee_id = NFC_DH_ID;
115
116 /* register message handler on NFA SYS */
117 nfa_sys_register (NFA_ID_EE, &nfa_ee_sys_reg);
118 }
119
120 /*******************************************************************************
121 **
122 ** Function nfa_ee_sys_enable
123 **
124 ** Description Enable NFA EE
125 **
126 ** Returns None
127 **
128 *******************************************************************************/
nfa_ee_sys_enable(void)129 void nfa_ee_sys_enable (void)
130 {
131 /* collect NFCEE information */
132 NFC_NfceeDiscover (TRUE);
133 nfa_sys_start_timer (&nfa_ee_cb.discv_timer, NFA_EE_DISCV_TIMEOUT_EVT, NFA_EE_DISCV_TIMEOUT_VAL);
134 }
135
136 /*******************************************************************************
137 **
138 ** Function nfa_ee_restore_one_ecb
139 **
140 ** Description activate the NFCEE and restore the routing when
141 ** changing power state from low power mode to full power mode
142 **
143 ** Returns None
144 **
145 *******************************************************************************/
nfa_ee_restore_one_ecb(tNFA_EE_ECB * p_cb)146 void nfa_ee_restore_one_ecb (tNFA_EE_ECB *p_cb)
147 {
148 UINT8 mask;
149 tNFC_NFCEE_MODE_SET_REVT rsp;
150 tNFA_EE_NCI_MODE_SET ee_msg;
151
152 NFA_TRACE_DEBUG4 ("nfa_ee_restore_one_ecb () nfcee_id:0x%x, ecb_flags:0x%x ee_status:0x%x ee_old_status: 0x%x", p_cb->nfcee_id, p_cb->ecb_flags, p_cb->ee_status, p_cb->ee_old_status);
153 if ((p_cb->nfcee_id != NFA_EE_INVALID) && (p_cb->ee_status & NFA_EE_STATUS_RESTORING) == 0 && (p_cb->ee_old_status & NFA_EE_STATUS_RESTORING) != 0)
154 {
155 p_cb->ee_old_status &= ~NFA_EE_STATUS_RESTORING;
156 mask = nfa_ee_ecb_to_mask(p_cb);
157 if (p_cb->ee_status != p_cb->ee_old_status)
158 {
159 p_cb->ecb_flags |= NFA_EE_ECB_FLAGS_RESTORE;
160 if (p_cb->ee_old_status == NFC_NFCEE_STATUS_ACTIVE)
161 {
162 NFC_NfceeModeSet (p_cb->nfcee_id, NFC_MODE_ACTIVATE);
163
164 if (nfa_ee_cb.ee_cfged & mask)
165 {
166 /* if any routing is configured on this NFCEE. need to mark this NFCEE as changed
167 * to cause the configuration to be sent to NFCC again */
168 p_cb->ecb_flags |= NFA_EE_ECB_FLAGS_ROUTING;
169 p_cb->ecb_flags |= NFA_EE_ECB_FLAGS_VS;
170 }
171 }
172 else
173 {
174 NFC_NfceeModeSet (p_cb->nfcee_id, NFC_MODE_DEACTIVATE);
175 }
176 }
177 else if (p_cb->ee_status == NFC_NFCEE_STATUS_ACTIVE)
178 {
179 /* the initial NFCEE status after start up is the same as the current status and it's active:
180 * process the same as the host gets activate rsp */
181 p_cb->ecb_flags |= NFA_EE_ECB_FLAGS_RESTORE;
182 if (nfa_ee_cb.ee_cfged & mask)
183 {
184 /* if any routing is configured on this NFCEE. need to mark this NFCEE as changed
185 * to cause the configuration to be sent to NFCC again */
186 p_cb->ecb_flags |= NFA_EE_ECB_FLAGS_ROUTING;
187 p_cb->ecb_flags |= NFA_EE_ECB_FLAGS_VS;
188 }
189 rsp.mode = NFA_EE_MD_ACTIVATE;
190 rsp.nfcee_id = p_cb->nfcee_id;
191 rsp.status = NFA_STATUS_OK;
192 ee_msg.p_data = &rsp;
193 nfa_ee_nci_mode_set_rsp ((tNFA_EE_MSG *) &ee_msg);
194 }
195 }
196 }
197
198 /*******************************************************************************
199 **
200 ** Function nfa_ee_proc_nfcc_power_mode
201 **
202 ** Description Restore NFA EE sub-module
203 **
204 ** Returns None
205 **
206 *******************************************************************************/
nfa_ee_proc_nfcc_power_mode(UINT8 nfcc_power_mode)207 void nfa_ee_proc_nfcc_power_mode (UINT8 nfcc_power_mode)
208 {
209 UINT32 xx;
210 tNFA_EE_ECB *p_cb;
211 BOOLEAN proc_complete = TRUE;
212
213 NFA_TRACE_DEBUG1 ("nfa_ee_proc_nfcc_power_mode (): nfcc_power_mode=%d", nfcc_power_mode);
214 /* if NFCC power state is change to full power */
215 if (nfcc_power_mode == NFA_DM_PWR_MODE_FULL)
216 {
217 p_cb = nfa_ee_cb.ecb;
218 for (xx = 0; xx < NFA_EE_MAX_EE_SUPPORTED; xx++, p_cb++)
219 {
220 p_cb->ee_old_status = 0;
221 if (xx >= nfa_ee_cb.cur_ee)
222 p_cb->nfcee_id = NFA_EE_INVALID;
223
224 if ((p_cb->nfcee_id != NFA_EE_INVALID) && (p_cb->ee_interface[0] != NFC_NFCEE_INTERFACE_HCI_ACCESS) && (p_cb->ee_status != NFA_EE_STATUS_REMOVED))
225 {
226 proc_complete = FALSE;
227 /* NFA_EE_STATUS_RESTORING bit makes sure the ee_status restore to ee_old_status
228 * NFA_EE_STATUS_RESTORING bit is cleared in ee_status at NFCEE_DISCOVER NTF.
229 * NFA_EE_STATUS_RESTORING bit is cleared in ee_old_status at restoring the activate/inactive status after NFCEE_DISCOVER NTF */
230 p_cb->ee_status |= NFA_EE_STATUS_RESTORING;
231 p_cb->ee_old_status = p_cb->ee_status;
232 /* NFA_EE_FLAGS_RESTORE bit makes sure the routing/nci logical connection is restore to prior to entering low power mode */
233 p_cb->ecb_flags |= NFA_EE_ECB_FLAGS_RESTORE;
234 }
235 }
236 nfa_ee_cb.em_state = NFA_EE_EM_STATE_RESTORING;
237 if (nfa_sys_is_register (NFA_ID_HCI))
238 {
239 nfa_ee_cb.ee_flags |= NFA_EE_FLAG_WAIT_HCI;
240 nfa_ee_cb.ee_flags |= NFA_EE_FLAG_NOTIFY_HCI;
241 }
242 NFC_NfceeDiscover (TRUE);
243 nfa_sys_start_timer (&nfa_ee_cb.discv_timer, NFA_EE_DISCV_TIMEOUT_EVT, NFA_EE_DISCV_TIMEOUT_VAL);
244 }
245 else
246 {
247 nfa_sys_stop_timer (&nfa_ee_cb.timer);
248 nfa_sys_stop_timer (&nfa_ee_cb.discv_timer);
249 nfa_ee_cb.num_ee_expecting = 0;
250 }
251
252 if (proc_complete)
253 nfa_sys_cback_notify_nfcc_power_mode_proc_complete (NFA_ID_EE);
254 }
255
256 /*******************************************************************************
257 **
258 ** Function nfa_ee_proc_hci_info_cback
259 **
260 ** Description HCI initialization complete from power off sleep mode
261 **
262 ** Returns None
263 **
264 *******************************************************************************/
nfa_ee_proc_hci_info_cback(void)265 void nfa_ee_proc_hci_info_cback (void)
266 {
267 UINT32 xx;
268 tNFA_EE_ECB *p_cb;
269
270 NFA_TRACE_DEBUG0 ("nfa_ee_proc_hci_info_cback ()");
271 /* if NFCC power state is change to full power */
272 nfa_ee_cb.ee_flags &= ~NFA_EE_FLAG_WAIT_HCI;
273
274 p_cb = nfa_ee_cb.ecb;
275 for (xx = 0; xx < NFA_EE_MAX_EE_SUPPORTED; xx++, p_cb++)
276 {
277 /* NCI spec says: An NFCEE_DISCOVER_NTF that contains a Protocol type of "HCI Access"
278 * SHALL NOT contain any other additional Protocol
279 * i.e. check only first supported NFCEE interface is HCI access */
280 /* NFA_HCI module handles restoring configurations for HCI access */
281 if (p_cb->ee_interface[0] != NFC_NFCEE_INTERFACE_HCI_ACCESS)
282 {
283 nfa_ee_restore_one_ecb (p_cb);
284 }
285 }
286 }
287
288 /*******************************************************************************
289 **
290 ** Function nfa_ee_proc_evt
291 **
292 ** Description Process NFCEE related events from NFC stack
293 **
294 **
295 ** Returns None
296 **
297 *******************************************************************************/
nfa_ee_proc_evt(tNFC_RESPONSE_EVT event,void * p_data)298 void nfa_ee_proc_evt (tNFC_RESPONSE_EVT event, void *p_data)
299 {
300 tNFA_EE_INT_EVT int_event=0;
301 tNFA_EE_NCI_RESPONSE cbk;
302 BT_HDR *p_hdr;
303
304 switch (event)
305 {
306 case NFC_NFCEE_DISCOVER_REVT: /* 4 NFCEE Discover response */
307 int_event = NFA_EE_NCI_DISC_RSP_EVT;
308 break;
309
310 case NFC_NFCEE_INFO_REVT: /* 5 NFCEE Discover Notification */
311 int_event = NFA_EE_NCI_DISC_NTF_EVT;
312 break;
313
314 case NFC_NFCEE_MODE_SET_REVT: /* 6 NFCEE Mode Set response */
315 int_event = NFA_EE_NCI_MODE_SET_RSP_EVT;
316 break;
317
318 case NFC_EE_ACTION_REVT:
319 int_event = NFA_EE_NCI_ACTION_NTF_EVT;
320 break;
321
322 case NFC_EE_DISCOVER_REQ_REVT: /* 10 EE Discover Req notification */
323 int_event = NFA_EE_NCI_DISC_REQ_NTF_EVT;
324 break;
325
326 }
327
328 NFA_TRACE_DEBUG2 ("nfa_ee_proc_evt: event=0x%02x int_event:0x%x", event, int_event);
329 if (int_event)
330 {
331 p_hdr = (BT_HDR *) &cbk;
332 cbk.hdr.event = int_event;
333 cbk.p_data = p_data;
334
335 nfa_ee_evt_hdlr (p_hdr);
336 }
337
338 }
339
340 /*******************************************************************************
341 **
342 ** Function nfa_ee_ecb_to_mask
343 **
344 ** Description Given a ecb, return the bit mask to be used in nfa_ee_cb.ee_cfged
345 **
346 ** Returns the bitmask for the given ecb.
347 **
348 *******************************************************************************/
nfa_ee_ecb_to_mask(tNFA_EE_ECB * p_cb)349 UINT8 nfa_ee_ecb_to_mask (tNFA_EE_ECB *p_cb)
350 {
351 UINT8 mask;
352 UINT8 index;
353
354 index = (UINT8) (p_cb - nfa_ee_cb.ecb);
355 mask = 1 << index;
356
357 return mask;
358 }
359
360 /*******************************************************************************
361 **
362 ** Function nfa_ee_find_ecb
363 **
364 ** Description Return the ecb associated with the given nfcee_id
365 **
366 ** Returns tNFA_EE_ECB
367 **
368 *******************************************************************************/
nfa_ee_find_ecb(UINT8 nfcee_id)369 tNFA_EE_ECB * nfa_ee_find_ecb (UINT8 nfcee_id)
370 {
371 UINT32 xx;
372 tNFA_EE_ECB *p_ret = NULL, *p_cb;
373 NFA_TRACE_DEBUG0 ("nfa_ee_find_ecb ()");
374
375 if (nfcee_id == NFC_DH_ID)
376 {
377 p_ret = &nfa_ee_cb.ecb[NFA_EE_CB_4_DH];
378 }
379 else
380 {
381 p_cb = nfa_ee_cb.ecb;
382 for (xx = 0; xx < NFA_EE_MAX_EE_SUPPORTED; xx++, p_cb++)
383 {
384 if (nfcee_id == p_cb->nfcee_id)
385 {
386 p_ret = p_cb;
387 break;
388 }
389 }
390 }
391
392 return p_ret;
393 }
394
395 /*******************************************************************************
396 **
397 ** Function nfa_ee_find_ecb_by_conn_id
398 **
399 ** Description Return the ecb associated with the given connection id
400 **
401 ** Returns tNFA_EE_ECB
402 **
403 *******************************************************************************/
nfa_ee_find_ecb_by_conn_id(UINT8 conn_id)404 tNFA_EE_ECB * nfa_ee_find_ecb_by_conn_id (UINT8 conn_id)
405 {
406 UINT32 xx;
407 tNFA_EE_ECB *p_ret = NULL, *p_cb;
408 NFA_TRACE_DEBUG0 ("nfa_ee_find_ecb_by_conn_id ()");
409
410 p_cb = nfa_ee_cb.ecb;
411 for (xx = 0; xx < nfa_ee_cb.cur_ee; xx++, p_cb++)
412 {
413 if (conn_id == p_cb->conn_id)
414 {
415 p_ret = p_cb;
416 break;
417 }
418 }
419
420 return p_ret;
421 }
422
423 /*******************************************************************************
424 **
425 ** Function nfa_ee_sys_disable
426 **
427 ** Description Deregister NFA EE from NFA SYS/DM
428 **
429 **
430 ** Returns None
431 **
432 *******************************************************************************/
nfa_ee_sys_disable(void)433 void nfa_ee_sys_disable (void)
434 {
435 UINT32 xx;
436 tNFA_EE_ECB *p_cb;
437 tNFA_EE_MSG msg;
438 NFA_TRACE_DEBUG0 ("nfa_ee_sys_disable ()");
439
440 nfa_ee_cb.em_state = NFA_EE_EM_STATE_DISABLED;
441 /* report NFA_EE_DEREGISTER_EVT to all registered to EE */
442 for (xx = 0; xx < NFA_EE_MAX_CBACKS; xx++)
443 {
444 if (nfa_ee_cb.p_ee_cback[xx])
445 {
446 msg.deregister.index = xx;
447 nfa_ee_api_deregister (&msg);
448 }
449 }
450
451 p_cb = nfa_ee_cb.ecb;
452 for (xx = 0; xx < nfa_ee_cb.cur_ee; xx++, p_cb++)
453 {
454 if (p_cb->conn_st == NFA_EE_CONN_ST_CONN)
455 {
456 if (nfa_sys_is_graceful_disable ())
457 {
458 /* Disconnect NCI connection on graceful shutdown */
459 msg.disconnect.p_cb = p_cb;
460 nfa_ee_api_disconnect (&msg);
461 nfa_ee_cb.em_state = NFA_EE_EM_STATE_DISABLING;
462 }
463 else
464 {
465 /* fake NFA_EE_DISCONNECT_EVT on ungraceful shutdown */
466 msg.conn.conn_id = p_cb->conn_id;
467 msg.conn.event = NFC_CONN_CLOSE_CEVT;
468 nfa_ee_nci_conn (&msg);
469 }
470 }
471 }
472 nfa_sys_stop_timer (&nfa_ee_cb.timer);
473 nfa_sys_stop_timer (&nfa_ee_cb.discv_timer);
474
475 /* If Application initiated NFCEE discovery, fake/report the event */
476 nfa_ee_cb.num_ee_expecting = 0;
477 nfa_ee_report_disc_done (FALSE);
478
479 /* deregister message handler on NFA SYS */
480 if (nfa_ee_cb.em_state == NFA_EE_EM_STATE_DISABLED)
481 nfa_sys_deregister (NFA_ID_EE);
482
483 }
484 /*******************************************************************************
485 **
486 ** Function nfa_ee_reg_cback_enable_done
487 **
488 ** Description Allow a module to register to EE to be notified when NFA-EE
489 ** finishes enable process
490 **
491 ** Returns None
492 **
493 *******************************************************************************/
nfa_ee_reg_cback_enable_done(tNFA_EE_ENABLE_DONE_CBACK * p_cback)494 void nfa_ee_reg_cback_enable_done (tNFA_EE_ENABLE_DONE_CBACK *p_cback)
495 {
496 nfa_ee_cb.p_enable_cback = p_cback;
497 }
498
499 #if (BT_TRACE_VERBOSE == TRUE)
500 /*******************************************************************************
501 **
502 ** Function nfa_ee_sm_st_2_str
503 **
504 ** Description convert nfa-ee state to string
505 **
506 *******************************************************************************/
nfa_ee_sm_st_2_str(UINT8 state)507 static char *nfa_ee_sm_st_2_str (UINT8 state)
508 {
509 switch (state)
510 {
511 case NFA_EE_EM_STATE_INIT:
512 return "INIT";
513
514 case NFA_EE_EM_STATE_INIT_DONE:
515 return "INIT_DONE";
516
517 case NFA_EE_EM_STATE_RESTORING:
518 return "RESTORING";
519
520 case NFA_EE_EM_STATE_DISABLING:
521 return "DISABLING";
522
523 case NFA_EE_EM_STATE_DISABLED:
524 return "DISABLED";
525
526 default:
527 return "Unknown";
528 }
529 }
530
531 /*******************************************************************************
532 **
533 ** Function nfa_ee_sm_evt_2_str
534 **
535 ** Description convert nfa-ee evt to string
536 **
537 *******************************************************************************/
nfa_ee_sm_evt_2_str(UINT16 event)538 static char *nfa_ee_sm_evt_2_str (UINT16 event)
539 {
540 switch (event)
541 {
542 case NFA_EE_API_DISCOVER_EVT:
543 return "API_DISCOVER";
544 case NFA_EE_API_REGISTER_EVT:
545 return "API_REGISTER";
546 case NFA_EE_API_DEREGISTER_EVT:
547 return "API_DEREGISTER";
548 case NFA_EE_API_MODE_SET_EVT:
549 return "API_MODE_SET";
550 case NFA_EE_API_SET_TECH_CFG_EVT:
551 return "API_SET_TECH_CFG";
552 case NFA_EE_API_SET_PROTO_CFG_EVT:
553 return "API_SET_PROTO_CFG";
554 case NFA_EE_API_ADD_AID_EVT:
555 return "API_ADD_AID";
556 case NFA_EE_API_REMOVE_AID_EVT:
557 return "API_REMOVE_AID";
558 case NFA_EE_API_UPDATE_NOW_EVT:
559 return "API_UPDATE_NOW";
560 case NFA_EE_API_CONNECT_EVT:
561 return "API_CONNECT";
562 case NFA_EE_API_SEND_DATA_EVT:
563 return "API_SEND_DATA";
564 case NFA_EE_API_DISCONNECT_EVT:
565 return "API_DISCONNECT";
566 case NFA_EE_NCI_DISC_RSP_EVT:
567 return "NCI_DISC_RSP";
568 case NFA_EE_NCI_DISC_NTF_EVT:
569 return "NCI_DISC_NTF";
570 case NFA_EE_NCI_MODE_SET_RSP_EVT:
571 return "NCI_MODE_SET";
572 case NFA_EE_NCI_CONN_EVT:
573 return "NCI_CONN";
574 case NFA_EE_NCI_DATA_EVT:
575 return "NCI_DATA";
576 case NFA_EE_NCI_ACTION_NTF_EVT:
577 return "NCI_ACTION";
578 case NFA_EE_NCI_DISC_REQ_NTF_EVT:
579 return "NCI_DISC_REQ";
580 case NFA_EE_ROUT_TIMEOUT_EVT:
581 return "ROUT_TIMEOUT";
582 case NFA_EE_DISCV_TIMEOUT_EVT:
583 return "NFA_EE_DISCV_TIMEOUT_EVT";
584 case NFA_EE_CFG_TO_NFCC_EVT:
585 return "CFG_TO_NFCC";
586 default:
587 return "Unknown";
588 }
589 }
590 #endif /* BT_TRACE_VERBOSE */
591
592 /*******************************************************************************
593 **
594 ** Function nfa_ee_evt_hdlr
595 **
596 ** Description Processing event for NFA EE
597 **
598 **
599 ** Returns TRUE if p_msg needs to be deallocated
600 **
601 *******************************************************************************/
nfa_ee_evt_hdlr(BT_HDR * p_msg)602 BOOLEAN nfa_ee_evt_hdlr (BT_HDR *p_msg)
603 {
604 tNFA_EE_MSG *p_evt_data = (tNFA_EE_MSG *) p_msg;
605 UINT16 event = p_msg->event & 0x00ff;
606 BOOLEAN act = FALSE;
607
608 #if (BT_TRACE_VERBOSE == TRUE)
609 NFA_TRACE_DEBUG4 ("nfa_ee_evt_hdlr (): Event %s(0x%02x), State: %s(%d)",
610 nfa_ee_sm_evt_2_str (p_evt_data->hdr.event), p_evt_data->hdr.event,
611 nfa_ee_sm_st_2_str (nfa_ee_cb.em_state), nfa_ee_cb.em_state);
612 #else
613 NFA_TRACE_DEBUG2 ("nfa_ee_evt_hdlr (): Event 0x%02x, State: %d", p_evt_data->hdr.event, nfa_ee_cb.em_state);
614 #endif
615
616 switch (nfa_ee_cb.em_state)
617 {
618 case NFA_EE_EM_STATE_INIT_DONE:
619 case NFA_EE_EM_STATE_RESTORING:
620 act = TRUE;
621 break;
622 case NFA_EE_EM_STATE_INIT:
623 if ((p_msg->event == NFA_EE_NCI_DISC_NTF_EVT) || (p_msg->event == NFA_EE_NCI_DISC_RSP_EVT))
624 act = TRUE;
625 break;
626 case NFA_EE_EM_STATE_DISABLING:
627 if (p_msg->event == NFA_EE_NCI_CONN_EVT)
628 act = TRUE;
629 break;
630 }
631 if (act)
632 {
633 if (event < NFA_EE_NUM_ACTIONS)
634 {
635 (*nfa_ee_actions[event]) (p_evt_data);
636 }
637 }
638 else
639 {
640 /* if the data event is not handled by action function, free the data packet */
641 if (p_msg->event == NFA_EE_NCI_DATA_EVT)
642 GKI_freebuf (p_evt_data->conn.p_data);
643 }
644
645 return TRUE;
646 }
647
648
649