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