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