Home | History | Annotate | Download | only in dm
      1 /******************************************************************************
      2  *
      3  *  Copyright (C) 2010-2013 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 file contains the action functions for device manager state
     23  *  machine.
     24  *
     25  ******************************************************************************/
     26 #include <string.h>
     27 #include "nfa_sys.h"
     28 #include "nfa_api.h"
     29 #include "nfa_dm_int.h"
     30 #include "nfa_sys_int.h"
     31 #include "nfa_ce_int.h"
     32 #include "nfc_api.h"
     33 #include "nfa_rw_int.h"
     34 #include "nfa_rw_api.h"
     35 #include "nfa_p2p_int.h"
     36 #include "nci_hmsgs.h"
     37 
     38 #if (defined (NFA_CHO_INCLUDED) && (NFA_CHO_INCLUDED==TRUE))
     39 #include "nfa_cho_int.h"
     40 #endif
     41 
     42 #if (NFC_NFCEE_INCLUDED == TRUE)
     43 #include "nfa_ee_int.h"
     44 #include "nfa_hci_int.h"
     45 #endif
     46 
     47 #if (defined (NFA_SNEP_INCLUDED) && (NFA_SNEP_INCLUDED==TRUE))
     48 #include "nfa_snep_int.h"
     49 #endif
     50 
     51 /* This is the timeout value to guarantee disable is performed within reasonable amount of time */
     52 #ifndef NFA_DM_DISABLE_TIMEOUT_VAL
     53 #define NFA_DM_DISABLE_TIMEOUT_VAL         1000
     54 #endif
     55 
     56 static void nfa_dm_set_init_nci_params (void);
     57 static tNFA_STATUS nfa_dm_start_polling (void);
     58 static BOOLEAN nfa_dm_deactivate_polling (void);
     59 static void nfa_dm_excl_disc_cback (tNFA_DM_RF_DISC_EVT event, tNFC_DISCOVER *p_data);
     60 static void nfa_dm_poll_disc_cback (tNFA_DM_RF_DISC_EVT event, tNFC_DISCOVER *p_data);
     61 
     62 
     63 /*******************************************************************************
     64 **
     65 ** Function         nfa_dm_module_init_cback
     66 **
     67 ** Description      Processing initialization complete event from sub-modules
     68 **
     69 ** Returns          None
     70 **
     71 *******************************************************************************/
     72 static void nfa_dm_module_init_cback (void)
     73 {
     74     tNFA_DM_CBACK_DATA dm_cback_data;
     75 
     76     nfa_dm_cb.flags &= ~NFA_DM_FLAGS_ENABLE_EVT_PEND;
     77 
     78     /* All subsystem are initialized */
     79     dm_cback_data.status = NFA_STATUS_OK;
     80     (*nfa_dm_cb.p_dm_cback) (NFA_DM_ENABLE_EVT, &dm_cback_data);
     81 }
     82 
     83 /*******************************************************************************
     84 **
     85 ** Function         nfa_dm_nfcc_power_mode_proc_complete_cback
     86 **
     87 ** Description      Processing complete of processing NFCC power state change
     88 **                  from all sub-modules
     89 **
     90 ** Returns          None
     91 **
     92 *******************************************************************************/
     93 static void nfa_dm_nfcc_power_mode_proc_complete_cback (void)
     94 {
     95     tNFA_DM_PWR_MODE_CHANGE power_mode_change;
     96 
     97     NFA_TRACE_DEBUG1 ("nfa_dm_nfcc_power_mode_proc_complete_cback () nfcc_pwr_mode = 0x%x",
     98                       nfa_dm_cb.nfcc_pwr_mode);
     99 
    100     /* if NFCC power state is change to full power */
    101     if (nfa_dm_cb.nfcc_pwr_mode != NFA_DM_PWR_MODE_OFF_SLEEP)
    102     {
    103         nfa_dm_cb.flags &= ~NFA_DM_FLAGS_NFCC_IS_RESTORING;
    104 
    105         /* reconfigure BRCM NFCC */
    106         nfa_dm_disc_sm_execute (NFA_DM_RF_DISCOVER_CMD, NULL);
    107     }
    108 
    109     nfa_dm_cb.flags &= ~NFA_DM_FLAGS_SETTING_PWR_MODE;
    110 
    111     power_mode_change.status     = NFA_STATUS_OK;
    112     power_mode_change.power_mode = nfa_dm_cb.nfcc_pwr_mode;
    113     (*nfa_dm_cb.p_dm_cback) (NFA_DM_PWR_MODE_CHANGE_EVT, (tNFA_DM_CBACK_DATA*) &power_mode_change);
    114 }
    115 /*******************************************************************************
    116 **
    117 ** Function         nfa_dm_sys_enable
    118 **
    119 ** Description      This function on enable
    120 **
    121 ** Returns          void
    122 **
    123 *******************************************************************************/
    124 void nfa_dm_sys_enable (void)
    125 {
    126     nfa_dm_set_init_nci_params ();
    127 }
    128 
    129 /*******************************************************************************
    130 **
    131 ** Function         nfa_dm_set_init_nci_params
    132 **
    133 ** Description      Set initial NCI configuration parameters
    134 **
    135 ** Returns          void
    136 **
    137 *******************************************************************************/
    138 static void nfa_dm_set_init_nci_params (void)
    139 {
    140     UINT8   xx;
    141 
    142     /* set NCI default value if other than zero */
    143 
    144     /* LF_T3T_IDENTIFIERS_1/2/.../16 */
    145     for (xx = 0; xx < NFA_CE_LISTEN_INFO_MAX; xx++)
    146     {
    147         nfa_dm_cb.params.lf_t3t_id[xx][0] = 0xFF;
    148         nfa_dm_cb.params.lf_t3t_id[xx][1] = 0xFF;
    149         nfa_dm_cb.params.lf_t3t_id[xx][2] = 0x02;
    150         nfa_dm_cb.params.lf_t3t_id[xx][2] = 0xFE;
    151     }
    152 
    153     /* LF_T3T_PMM */
    154     for (xx = 0; xx < NCI_PARAM_LEN_LF_T3T_PMM; xx++)
    155     {
    156         nfa_dm_cb.params.lf_t3t_pmm[xx] = 0xFF;
    157     }
    158 
    159     /* LF_T3T_FLAGS:
    160     ** DH needs to set this configuration, even if default value (not listening) is used,
    161     ** to let NFCC know of intention (not listening) of DH.
    162     */
    163 
    164     /* FWI */
    165     nfa_dm_cb.params.fwi[0] = 0x04;
    166 
    167     /* WT */
    168     nfa_dm_cb.params.wt[0] = 14;
    169 
    170     /* Set CE default configuration */
    171     if (p_nfa_dm_ce_cfg[0])
    172     {
    173         nfa_dm_check_set_config (p_nfa_dm_ce_cfg[0], &p_nfa_dm_ce_cfg[1], FALSE);
    174     }
    175 
    176     /* Set optional general default configuration */
    177     if (p_nfa_dm_gen_cfg && p_nfa_dm_gen_cfg[0])
    178     {
    179         nfa_dm_check_set_config (p_nfa_dm_gen_cfg[0], &p_nfa_dm_gen_cfg[1], FALSE);
    180     }
    181 
    182     if (p_nfa_dm_interface_mapping && nfa_dm_num_dm_interface_mapping)
    183     {
    184         NFC_DiscoveryMap (nfa_dm_num_dm_interface_mapping, p_nfa_dm_interface_mapping, NULL);
    185     }
    186 }
    187 
    188 /*******************************************************************************
    189 **
    190 ** Function         nfa_dm_proc_nfcc_power_mode
    191 **
    192 ** Description      Processing NFCC power mode changes
    193 **
    194 ** Returns          None
    195 **
    196 *******************************************************************************/
    197 void nfa_dm_proc_nfcc_power_mode (UINT8 nfcc_power_mode)
    198 {
    199     NFA_TRACE_DEBUG1 ("nfa_dm_proc_nfcc_power_mode (): nfcc_power_mode=%d",
    200                        nfcc_power_mode);
    201 
    202     /* if NFCC power mode is change to full power */
    203     if (nfcc_power_mode == NFA_DM_PWR_MODE_FULL)
    204     {
    205         memset (&nfa_dm_cb.params, 0x00, sizeof (tNFA_DM_PARAMS));
    206         NFA_TRACE_DEBUG2 ("setcfg_pending_mask=0x%x, setcfg_pending_num=%d",
    207             nfa_dm_cb.setcfg_pending_mask, nfa_dm_cb.setcfg_pending_num);
    208         nfa_dm_cb.setcfg_pending_mask = 0;
    209         nfa_dm_cb.setcfg_pending_num  = 0;
    210 
    211         nfa_dm_set_init_nci_params ();
    212     }
    213 
    214     nfa_sys_cback_notify_nfcc_power_mode_proc_complete (NFA_ID_DM);
    215 }
    216 
    217 /*******************************************************************************
    218 **
    219 ** Function         nfa_dm_disable_event
    220 **
    221 ** Description      report disable event
    222 **
    223 ** Returns          void
    224 **
    225 *******************************************************************************/
    226 static void nfa_dm_disable_event (void)
    227 {
    228     /* Deregister DM from sys */
    229     nfa_sys_deregister (NFA_ID_DM);
    230 
    231     /* Notify app */
    232     nfa_dm_cb.flags &= ~(NFA_DM_FLAGS_DM_IS_ACTIVE
    233                         |NFA_DM_FLAGS_DM_DISABLING_NFC
    234                         |NFA_DM_FLAGS_ENABLE_EVT_PEND);
    235     (*nfa_dm_cb.p_dm_cback) (NFA_DM_DISABLE_EVT, NULL);
    236 }
    237 
    238 /*******************************************************************************
    239 **
    240 ** Function         nfa_dm_nfc_response_cback
    241 **
    242 ** Description      Call DM event hanlder with NFC response callback data
    243 **
    244 ** Returns          void
    245 **
    246 *******************************************************************************/
    247 static void nfa_dm_nfc_response_cback (tNFC_RESPONSE_EVT event, tNFC_RESPONSE *p_data)
    248 {
    249     tNFA_DM_CBACK_DATA dm_cback_data;
    250     tNFA_GET_CONFIG   *p_nfa_get_confg;
    251     tNFA_CONN_EVT_DATA conn_evt;
    252     UINT8 dm_cback_evt;
    253     UINT8 max_ee = 0;
    254 
    255 #if (BT_TRACE_VERBOSE == TRUE)
    256     NFA_TRACE_DEBUG2 ("nfa_dm_nfc_response_cback () %s(0x%x)", nfa_dm_nfc_revt_2_str (event), event);
    257 #else
    258     NFA_TRACE_DEBUG1 ("nfa_dm_nfc_response_cback () event=0x%x", event);
    259 #endif
    260 
    261     switch (event)
    262     {
    263     case NFC_ENABLE_REVT:                        /* 0  Enable event */
    264 
    265         /* NFC stack enabled. Enable nfa sub-systems */
    266         if (p_data->enable.status == NFC_STATUS_OK)
    267         {
    268             if (nfa_ee_max_ee_cfg != 0)
    269             {
    270                 if (nfa_dm_cb.get_max_ee)
    271                 {
    272                     max_ee = nfa_dm_cb.get_max_ee ();
    273                     if (max_ee)
    274                     {
    275                         nfa_ee_max_ee_cfg = max_ee;
    276                     }
    277                 }
    278             }
    279             /* Initialize NFA subsystems */
    280             nfa_sys_enable_subsystems ();
    281         }
    282         else if (nfa_dm_cb.flags & NFA_DM_FLAGS_ENABLE_EVT_PEND)
    283         {
    284             /* Notify app */
    285             nfa_dm_cb.flags &= ~(NFA_DM_FLAGS_ENABLE_EVT_PEND | NFA_DM_FLAGS_DM_IS_ACTIVE);
    286             dm_cback_data.status = p_data->enable.status;
    287             (*nfa_dm_cb.p_dm_cback) (NFA_DM_ENABLE_EVT, &dm_cback_data);
    288         }
    289         break;
    290 
    291     case NFC_DISABLE_REVT:                       /* 1  Disable event */
    292         nfa_dm_disable_event ();
    293         break;
    294 
    295     case NFC_SET_CONFIG_REVT:                    /* 2  Set Config Response */
    296         /* If this setconfig was due to NFA_SetConfig, then notify the app */
    297         if (nfa_dm_cb.setcfg_pending_mask & 1)      /* lsb=whether last NCI_SET_CONFIG was due to NFA_SetConfig */
    298         {
    299             dm_cback_data.set_config.status         = p_data->set_config.status;
    300             dm_cback_data.set_config.num_param_id   = p_data->set_config.num_param_id;
    301             memcpy (dm_cback_data.set_config.param_ids, p_data->set_config.param_ids, p_data->set_config.num_param_id);
    302             (*nfa_dm_cb.p_dm_cback) (NFA_DM_SET_CONFIG_EVT, &dm_cback_data);
    303         }
    304 
    305         /* Update the pending mask */
    306         if (nfa_dm_cb.setcfg_pending_num>0)
    307         {
    308             nfa_dm_cb.setcfg_pending_mask >>= 1;
    309             nfa_dm_cb.setcfg_pending_num--;
    310         }
    311         else
    312         {
    313             /* This should not occur (means we got a SET_CONFIG_NTF that's unaccounted for */
    314             NFA_TRACE_ERROR0 ("NFA received unexpected NFC_SET_CONFIG_REVT");
    315         }
    316         break;
    317 
    318     case NFC_GET_CONFIG_REVT:                    /* 3  Get Config Response */
    319         if (p_data->get_config.status == NFC_STATUS_OK)
    320         {
    321             if ((p_nfa_get_confg = (tNFA_GET_CONFIG *) GKI_getbuf ((UINT16) (sizeof (tNFA_GET_CONFIG) + p_data->get_config.tlv_size))) != NULL)
    322             {
    323                 p_nfa_get_confg->status = NFA_STATUS_OK;
    324                 p_nfa_get_confg->tlv_size = p_data->get_config.tlv_size;
    325                 memcpy (p_nfa_get_confg->param_tlvs, p_data->get_config.p_param_tlvs, p_data->get_config.tlv_size);
    326                 (*nfa_dm_cb.p_dm_cback) (NFA_DM_GET_CONFIG_EVT, (tNFA_DM_CBACK_DATA *) p_nfa_get_confg);
    327 
    328                 GKI_freebuf (p_nfa_get_confg);
    329                 return;
    330             }
    331             else
    332             {
    333                 NFA_TRACE_DEBUG0 ("nfa_dm_nfc_response_cback unable to allocate buffer");
    334             }
    335         }
    336 
    337         /* Return result of getconfig to the app */
    338         dm_cback_data.get_config.status = NFA_STATUS_FAILED;
    339         (*nfa_dm_cb.p_dm_cback) (NFA_DM_GET_CONFIG_EVT, &dm_cback_data);
    340         break;
    341 
    342 #if (NFC_NFCEE_INCLUDED == TRUE)
    343     case NFC_NFCEE_DISCOVER_REVT:                /* NFCEE Discover response */
    344     case NFC_NFCEE_INFO_REVT:                    /* NFCEE Discover Notification */
    345     case NFC_EE_ACTION_REVT:                     /* EE Action notification */
    346     case NFC_NFCEE_MODE_SET_REVT:                /* NFCEE Mode Set response */
    347         nfa_ee_proc_evt (event, p_data);
    348         break;
    349 
    350     case NFC_EE_DISCOVER_REQ_REVT:               /* EE Discover Req notification */
    351         if (nfa_dm_is_active() &&
    352             (nfa_dm_cb.disc_cb.disc_state == NFA_DM_RFST_DISCOVERY) )
    353         {
    354             nfa_dm_rf_deactivate (NFA_DEACTIVATE_TYPE_IDLE);
    355         }
    356         nfa_ee_proc_evt (event, p_data);
    357         break;
    358 #endif
    359 
    360     case NFC_RF_FIELD_REVT:                      /* RF Field information            */
    361         dm_cback_data.rf_field.status          = NFA_STATUS_OK;
    362         dm_cback_data.rf_field.rf_field_status = p_data->rf_field.rf_field;
    363         (*nfa_dm_cb.p_dm_cback) (NFA_DM_RF_FIELD_EVT, &dm_cback_data);
    364         break;
    365 
    366     case NFC_SET_ROUTING_REVT:                   /* Configure Routing response */
    367         break;
    368 
    369     case NFC_GET_ROUTING_REVT:                   /* Retrieve Routing response */
    370         break;
    371 
    372     case NFC_GEN_ERROR_REVT:                     /* generic error command or notification */
    373         break;
    374 
    375     case NFC_NFCC_RESTART_REVT:                  /* NFCC has been re-initialized */
    376 
    377         if (p_data->status == NFC_STATUS_OK)
    378         {
    379             nfa_dm_cb.nfcc_pwr_mode = NFA_DM_PWR_MODE_FULL;
    380             nfa_dm_cb.flags |= NFA_DM_FLAGS_NFCC_IS_RESTORING;
    381 
    382             /* NFCC will start from IDLE when turned on again */
    383             nfa_dm_cb.disc_cb.disc_flags &= ~NFA_DM_DISC_FLAGS_W4_RSP;
    384             nfa_dm_cb.disc_cb.disc_flags &= ~NFA_DM_DISC_FLAGS_W4_NTF;
    385             nfa_dm_cb.disc_cb.disc_state = NFA_DM_RFST_IDLE;
    386         }
    387         else
    388         {
    389             nfa_dm_cb.nfcc_pwr_mode = NFA_DM_PWR_MODE_OFF_SLEEP;
    390         }
    391         /* Notify NFA submodules change of NFCC power mode */
    392         nfa_sys_cback_reg_nfcc_power_mode_proc_complete (nfa_dm_nfcc_power_mode_proc_complete_cback);
    393         nfa_sys_notify_nfcc_power_mode (nfa_dm_cb.nfcc_pwr_mode);
    394         break;
    395 
    396     case NFC_NFCC_TIMEOUT_REVT:
    397     case NFC_NFCC_TRANSPORT_ERR_REVT:
    398         NFA_TRACE_DEBUG1 ("flags:0x%08x", nfa_dm_cb.flags);
    399         dm_cback_evt = (event == NFC_NFCC_TIMEOUT_REVT) ? NFA_DM_NFCC_TIMEOUT_EVT : NFA_DM_NFCC_TRANSPORT_ERR_EVT;
    400         (*nfa_dm_cb.p_dm_cback) (dm_cback_evt, NULL);
    401         break;
    402 
    403     case NFC_NFCC_POWER_OFF_REVT:
    404         nfa_dm_cb.nfcc_pwr_mode = NFA_DM_PWR_MODE_OFF_SLEEP;
    405 
    406         /* Notify NFA submodules change of NFCC power mode */
    407         nfa_sys_cback_reg_nfcc_power_mode_proc_complete (nfa_dm_nfcc_power_mode_proc_complete_cback);
    408         nfa_sys_notify_nfcc_power_mode (NFA_DM_PWR_MODE_OFF_SLEEP);
    409         break;
    410 
    411     case NFC_RF_COMM_PARAMS_UPDATE_REVT:
    412         conn_evt.status = p_data->status;
    413         nfa_dm_conn_cback_event_notify (NFA_UPDATE_RF_PARAM_RESULT_EVT, &conn_evt);
    414         break;
    415 
    416 
    417     default:
    418         break;
    419     }
    420 }
    421 
    422 
    423 /*******************************************************************************
    424 **
    425 ** Function         nfa_dm_enable
    426 **
    427 ** Description      Initialises the NFC device manager
    428 **
    429 ** Returns          TRUE (message buffer to be freed by caller)
    430 **
    431 *******************************************************************************/
    432 BOOLEAN nfa_dm_enable (tNFA_DM_MSG *p_data)
    433 {
    434     tNFA_DM_CBACK_DATA dm_cback_data;
    435     NFA_TRACE_DEBUG0 ("nfa_dm_enable ()");
    436 
    437     /* Check if NFA is already enabled */
    438     if (!(nfa_dm_cb.flags & NFA_DM_FLAGS_DM_IS_ACTIVE))
    439     {
    440         /* Initialize BRCM control block, it musb be called before setting any flags */
    441         nfa_dm_cb.flags |= (NFA_DM_FLAGS_DM_IS_ACTIVE | NFA_DM_FLAGS_ENABLE_EVT_PEND);
    442         nfa_sys_cback_reg_enable_complete (nfa_dm_module_init_cback);
    443 
    444 
    445         /* Store Enable parameters */
    446         nfa_dm_cb.p_dm_cback    = p_data->enable.p_dm_cback;
    447         nfa_dm_cb.p_conn_cback  = p_data->enable.p_conn_cback;
    448 
    449         /* Enable NFC stack */
    450         NFC_Enable (nfa_dm_nfc_response_cback);
    451     }
    452     else
    453     {
    454         NFA_TRACE_ERROR0 ("nfa_dm_enable: ERROR ALREADY ENABLED.");
    455         dm_cback_data.status = NFA_STATUS_ALREADY_STARTED;
    456         (*(p_data->enable.p_dm_cback)) (NFA_DM_ENABLE_EVT, &dm_cback_data);
    457     }
    458 
    459     return (TRUE);
    460 }
    461 
    462 /*******************************************************************************
    463 **
    464 ** Function         nfa_dm_disable
    465 **
    466 ** Description      Disables the NFC device manager
    467 **
    468 ** Returns          TRUE (message buffer to be freed by caller)
    469 **
    470 *******************************************************************************/
    471 BOOLEAN nfa_dm_disable (tNFA_DM_MSG *p_data)
    472 {
    473     tNFC_DEACT_TYPE deactivate_type = NFA_DEACTIVATE_TYPE_IDLE;
    474 
    475     NFA_TRACE_DEBUG1 ("nfa_dm_disable (): graceful:%d", p_data->disable.graceful);
    476 
    477     if (p_data->disable.graceful)
    478     {
    479         /* if RF discovery is enabled */
    480         if (nfa_dm_cb.disc_cb.disc_flags & NFA_DM_DISC_FLAGS_ENABLED)
    481         {
    482             nfa_dm_cb.disc_cb.disc_flags &= ~NFA_DM_DISC_FLAGS_ENABLED;
    483 
    484             if (nfa_dm_cb.disc_cb.disc_state == NFA_DM_RFST_IDLE)
    485             {
    486                 /* if waiting RSP in idle state */
    487                 if (nfa_dm_cb.disc_cb.disc_flags & NFA_DM_DISC_FLAGS_W4_RSP)
    488                 {
    489                     nfa_dm_cb.disc_cb.disc_flags |= NFA_DM_DISC_FLAGS_DISABLING;
    490                 }
    491             }
    492             else
    493             {
    494                 nfa_dm_cb.disc_cb.disc_flags |= NFA_DM_DISC_FLAGS_DISABLING;
    495                 nfa_dm_disc_sm_execute (NFA_DM_RF_DEACTIVATE_CMD, (tNFA_DM_RF_DISC_DATA *) &deactivate_type);
    496                 if ((nfa_dm_cb.disc_cb.disc_flags & (NFA_DM_DISC_FLAGS_W4_RSP|NFA_DM_DISC_FLAGS_W4_NTF)) == 0)
    497                 {
    498                     /* not waiting to deactivate, clear the flag now */
    499                     nfa_dm_cb.disc_cb.disc_flags &= ~NFA_DM_DISC_FLAGS_DISABLING;
    500                 }
    501             }
    502         }
    503         /* Start timeout for graceful shutdown. If timer expires, then force an ungraceful shutdown */
    504         nfa_sys_start_timer (&nfa_dm_cb.tle, NFA_DM_TIMEOUT_DISABLE_EVT, NFA_DM_DISABLE_TIMEOUT_VAL);
    505     }
    506 
    507     /* Disable all subsystems other than DM (DM will be disabled after all  */
    508     /* the other subsystem have been disabled)                              */
    509     nfa_sys_disable_subsystems (p_data->disable.graceful);
    510     return (TRUE);
    511 }
    512 
    513 
    514 /*******************************************************************************
    515 **
    516 ** Function         nfa_dm_disable_complete
    517 **
    518 ** Description      Called when all NFA subsytems are disabled.
    519 **
    520 **                  NFC core stack can now be disabled.
    521 **
    522 ** Returns          void
    523 **
    524 *******************************************************************************/
    525 void nfa_dm_disable_complete (void)
    526 {
    527     NFA_TRACE_DEBUG0 ("nfa_dm_disable_complete ()");
    528 
    529     if ((nfa_dm_cb.flags & NFA_DM_FLAGS_DM_DISABLING_NFC) == 0)
    530     {
    531         NFA_TRACE_DEBUG0 ("nfa_dm_disable_complete (): proceeding with nfc core shutdown.");
    532 
    533         nfa_dm_cb.flags |= NFA_DM_FLAGS_DM_DISABLING_NFC;
    534 
    535         nfa_sys_stop_timer (&nfa_dm_cb.tle);
    536 
    537         /* Free all buffers for NDEF handlers */
    538         nfa_dm_ndef_dereg_all();
    539 
    540         /* Disable nfc core stack */
    541         NFC_Disable ();
    542     }
    543 }
    544 
    545 /*******************************************************************************
    546 **
    547 ** Function         nfa_dm_set_config
    548 **
    549 ** Description      Process set config command
    550 **
    551 ** Returns          TRUE (message buffer to be freed by caller)
    552 **
    553 *******************************************************************************/
    554 BOOLEAN nfa_dm_set_config (tNFA_DM_MSG *p_data)
    555 {
    556     tNFC_STATUS status;
    557     UINT8       buff[255];
    558     UINT8      *p = buff;
    559 
    560     tNFA_DM_CBACK_DATA dm_cback_data;
    561 
    562     if (p_data->setconfig.length + 2 > 255)
    563     {
    564         /* Total length of TLV must be less than 256 (1 byte) */
    565         status = NFC_STATUS_FAILED;
    566     }
    567     else
    568     {
    569         UINT8_TO_STREAM (p, p_data->setconfig.param_id);
    570         UINT8_TO_STREAM (p, p_data->setconfig.length);
    571         ARRAY_TO_STREAM (p, p_data->setconfig.p_data, p_data->setconfig.length)
    572         status = nfa_dm_check_set_config ((UINT8) (p_data->setconfig.length + 2), buff, TRUE);
    573     }
    574 
    575     if (status != NFC_STATUS_OK)
    576     {
    577         dm_cback_data.set_config.status = NFA_STATUS_INVALID_PARAM;
    578         (*nfa_dm_cb.p_dm_cback) (NFA_DM_SET_CONFIG_EVT, &dm_cback_data);
    579     }
    580 
    581     return (TRUE);
    582 }
    583 
    584 /*******************************************************************************
    585 **
    586 ** Function         nfa_dm_get_config
    587 **
    588 ** Description      Process get config command
    589 **
    590 ** Returns          TRUE (message buffer to be freed by caller)
    591 **
    592 *******************************************************************************/
    593 BOOLEAN nfa_dm_get_config (tNFA_DM_MSG *p_data)
    594 {
    595     NFC_GetConfig (p_data->getconfig.num_ids, p_data->getconfig.p_pmids);
    596 
    597     return (TRUE);
    598 }
    599 
    600 /*******************************************************************************
    601 **
    602 ** Function         nfa_dm_conn_cback_event_notify
    603 **
    604 ** Description      Notify application of CONN_CBACK event, using appropriate
    605 **                  callback
    606 **
    607 ** Returns          nothing
    608 **
    609 *******************************************************************************/
    610 void nfa_dm_conn_cback_event_notify (UINT8 event, tNFA_CONN_EVT_DATA *p_data)
    611 {
    612     if (nfa_dm_cb.flags & NFA_DM_FLAGS_EXCL_RF_ACTIVE)
    613     {
    614         /* Use exclusive RF mode callback */
    615         if (nfa_dm_cb.p_excl_conn_cback)
    616             (*nfa_dm_cb.p_excl_conn_cback) (event, p_data);
    617     }
    618     else
    619     {
    620         (*nfa_dm_cb.p_conn_cback) (event, p_data);
    621     }
    622 }
    623 
    624 /*******************************************************************************
    625 **
    626 ** Function         nfa_dm_rel_excl_rf_control_and_notify
    627 **
    628 ** Description      Stop exclusive RF control and notify app of
    629 **                  NFA_EXCLUSIVE_RF_CONTROL_STOPPED_EVT
    630 **
    631 ** Returns          void
    632 **
    633 *******************************************************************************/
    634 void nfa_dm_rel_excl_rf_control_and_notify (void)
    635 {
    636     tNFA_CONN_EVT_DATA conn_evt;
    637 
    638     NFA_TRACE_DEBUG0 ("nfa_dm_rel_excl_rf_control_and_notify ()");
    639 
    640     /* Exclusive RF control stopped. Notify app */
    641     nfa_dm_cb.flags &= ~NFA_DM_FLAGS_EXCL_RF_ACTIVE;
    642 
    643     /* Stop exclusive RF discovery for exclusive RF mode */
    644     nfa_dm_stop_excl_discovery ();
    645 
    646     /* Notify app that exclusive RF control has stopped */
    647     conn_evt.status = NFA_STATUS_OK;
    648     (*nfa_dm_cb.p_excl_conn_cback) (NFA_EXCLUSIVE_RF_CONTROL_STOPPED_EVT, &conn_evt);
    649     nfa_dm_cb.p_excl_conn_cback = NULL;
    650     nfa_dm_cb.p_excl_ndef_cback = NULL;
    651 }
    652 
    653 /*******************************************************************************
    654 **
    655 ** Function         nfa_dm_act_request_excl_rf_ctrl
    656 **
    657 ** Description      Request exclusive RF control
    658 **
    659 ** Returns          TRUE (message buffer to be freed by caller)
    660 **
    661 *******************************************************************************/
    662 BOOLEAN nfa_dm_act_request_excl_rf_ctrl (tNFA_DM_MSG *p_data)
    663 {
    664     tNFA_CONN_EVT_DATA conn_evt;
    665 
    666     NFA_TRACE_DEBUG0 ("nfa_dm_act_request_excl_rf_ctrl ()");
    667 
    668     if (!nfa_dm_cb.p_excl_conn_cback)
    669     {
    670         if (nfa_dm_cb.disc_cb.disc_state != NFA_DM_RFST_IDLE)
    671         {
    672             conn_evt.status = NFA_STATUS_FAILED;
    673             (*p_data->req_excl_rf_ctrl.p_conn_cback) (NFA_EXCLUSIVE_RF_CONTROL_STARTED_EVT, &conn_evt);
    674             return TRUE;
    675         }
    676 
    677         /* Store callbacks */
    678         nfa_dm_cb.p_excl_conn_cback = p_data->req_excl_rf_ctrl.p_conn_cback;
    679         nfa_dm_cb.p_excl_ndef_cback = p_data->req_excl_rf_ctrl.p_ndef_cback;
    680 
    681         nfa_dm_cb.flags |= NFA_DM_FLAGS_EXCL_RF_ACTIVE;
    682 
    683         /* start exclusive RF discovery */
    684         nfa_dm_start_excl_discovery (p_data->req_excl_rf_ctrl.poll_mask,
    685                                      &p_data->req_excl_rf_ctrl.listen_cfg,
    686                                      nfa_dm_excl_disc_cback);
    687     }
    688     else
    689     {
    690         NFA_TRACE_ERROR0 ("Exclusive rf control already requested");
    691 
    692         conn_evt.status = NFA_STATUS_FAILED;
    693         (*p_data->req_excl_rf_ctrl.p_conn_cback) (NFA_EXCLUSIVE_RF_CONTROL_STARTED_EVT, &conn_evt);
    694     }
    695 
    696     return TRUE;
    697 }
    698 
    699 
    700 /*******************************************************************************
    701 **
    702 ** Function         nfa_dm_act_release_excl_rf_ctrl
    703 **
    704 ** Description      Release exclusive RF control
    705 **
    706 ** Returns          TRUE (message buffer to be freed by caller)
    707 **
    708 *******************************************************************************/
    709 BOOLEAN nfa_dm_act_release_excl_rf_ctrl (tNFA_DM_MSG *p_data)
    710 {
    711     NFA_TRACE_DEBUG0 ("nfa_dm_act_release_excl_rf_ctrl ()");
    712 
    713     /* nfa_dm_rel_excl_rf_control_and_notify() is called when discovery state goes IDLE */
    714     nfa_dm_cb.disc_cb.disc_flags |= NFA_DM_DISC_FLAGS_STOPPING;
    715 
    716     /* if discover command has been sent in IDLE state and waiting for response
    717     ** then just wait for responose. Otherwise initiate deactivating.
    718     */
    719     if (!(  (nfa_dm_cb.disc_cb.disc_state == NFA_DM_RFST_IDLE)
    720           &&(nfa_dm_cb.disc_cb.disc_flags & NFA_DM_DISC_FLAGS_W4_RSP)  ))
    721     {
    722         nfa_dm_rf_deactivate (NFA_DEACTIVATE_TYPE_IDLE);
    723     }
    724 
    725     if (nfa_dm_cb.disc_cb.kovio_tle.in_use)
    726         nfa_sys_stop_timer (&nfa_dm_cb.disc_cb.kovio_tle);
    727 
    728     return TRUE;
    729 }
    730 
    731 /*******************************************************************************
    732 **
    733 ** Function         nfa_dm_act_deactivate
    734 **
    735 ** Description      Process deactivate command
    736 **
    737 ** Returns          TRUE (message buffer to be freed by caller)
    738 **
    739 *******************************************************************************/
    740 BOOLEAN nfa_dm_act_deactivate (tNFA_DM_MSG *p_data)
    741 {
    742     tNFA_CONN_EVT_DATA conn_evt;
    743     tNFA_DEACTIVATE_TYPE deact_type;
    744 
    745     NFA_TRACE_DEBUG0 ("nfa_dm_act_deactivate ()");
    746 
    747     if (  (p_data->deactivate.sleep_mode == FALSE)                 /* Always allow deactivate to IDLE */
    748         ||(  (nfa_dm_cb.disc_cb.activated_protocol != NFA_PROTOCOL_T1T)      /* Do not allow deactivate to SLEEP for T1T,NFCDEP, ISO15693 */
    749            &&(nfa_dm_cb.disc_cb.activated_protocol != NFA_PROTOCOL_NFC_DEP)
    750            &&(nfa_dm_cb.disc_cb.activated_protocol != NFA_PROTOCOL_ISO15693)
    751            &&(nfa_dm_cb.disc_cb.activated_protocol != NFC_PROTOCOL_KOVIO)  )  )
    752     {
    753         deact_type  = NFA_DEACTIVATE_TYPE_DISCOVERY;
    754         if (p_data->deactivate.sleep_mode)
    755         {
    756             if (nfa_dm_cb.disc_cb.disc_state == NFA_DM_RFST_W4_HOST_SELECT)
    757             {
    758                 /* Deactivate to sleep mode not allowed in this state. */
    759                 deact_type = NFA_DEACTIVATE_TYPE_IDLE;
    760             }
    761             else if (nfa_dm_cb.disc_cb.disc_state != NFA_DM_RFST_LISTEN_SLEEP)
    762             {
    763                 deact_type = NFA_DEACTIVATE_TYPE_SLEEP;
    764             }
    765         }
    766         if (nfa_dm_cb.disc_cb.disc_state == NFA_DM_RFST_W4_ALL_DISCOVERIES)
    767         {
    768             /* Only deactivate to IDLE is allowed in this state. */
    769             deact_type = NFA_DEACTIVATE_TYPE_IDLE;
    770         }
    771 
    772         if (  (nfa_dm_cb.disc_cb.activated_protocol == NFA_PROTOCOL_NFC_DEP)
    773             &&((nfa_dm_cb.flags & NFA_DM_FLAGS_EXCL_RF_ACTIVE) == 0x00)  )
    774         {
    775             /* Exclusive RF control doesn't use NFA P2P */
    776             /* NFA P2P will deactivate NFC link after deactivating LLCP link */
    777             if (!(nfa_dm_cb.flags & NFA_DM_FLAGS_P2P_PAUSED))
    778             {
    779                 nfa_p2p_deactivate_llcp ();
    780             }
    781             else
    782             {
    783                 nfa_dm_rf_deactivate (deact_type);
    784             }
    785             return (TRUE);
    786         }
    787         else
    788         {
    789 
    790             if (nfa_dm_rf_deactivate (deact_type) == NFA_STATUS_OK)
    791             {
    792                 if (nfa_dm_cb.disc_cb.kovio_tle.in_use)
    793                     nfa_sys_stop_timer (&nfa_dm_cb.disc_cb.kovio_tle);
    794                 nfa_rw_stop_presence_check_timer ();
    795                 return (TRUE);
    796             }
    797         }
    798     }
    799 
    800     NFA_TRACE_ERROR0 ("nfa_dm_act_deactivate (): invalid protocol, mode or state");
    801 
    802     /* Notify error to application */
    803     conn_evt.status = NFA_STATUS_FAILED;
    804     nfa_dm_conn_cback_event_notify (NFA_DEACTIVATE_FAIL_EVT, &conn_evt);
    805 
    806     return (TRUE);
    807 }
    808 
    809 /*******************************************************************************
    810 **
    811 ** Function         nfa_dm_act_power_off_sleep
    812 **
    813 ** Description      Process power off sleep mode request
    814 **
    815 ** Returns          TRUE (message buffer to be freed by caller)
    816 **
    817 *******************************************************************************/
    818 BOOLEAN nfa_dm_act_power_off_sleep (tNFA_DM_MSG *p_data)
    819 {
    820     NFA_TRACE_DEBUG0 ("nfa_dm_act_power_off_sleep ()");
    821 
    822     NFC_SetPowerOffSleep ((BOOLEAN) (p_data->hdr.layer_specific));
    823 
    824     return (TRUE);
    825 }
    826 
    827 /*******************************************************************************
    828 **
    829 ** Function         nfa_dm_act_reg_vsc
    830 **
    831 ** Description      Process registers VSC callback
    832 **
    833 ** Returns          TRUE (message buffer to be freed by caller)
    834 **
    835 *******************************************************************************/
    836 BOOLEAN nfa_dm_act_reg_vsc(tNFA_DM_MSG *p_data)
    837 {
    838     if (NFC_RegVSCback(p_data->reg_vsc.is_register, p_data->reg_vsc.p_cback) != NFC_STATUS_OK)
    839     {
    840         NFA_TRACE_ERROR0 ("NFC_RegVSCback failed");
    841     }
    842     return (TRUE);
    843 }
    844 
    845 /*******************************************************************************
    846 **
    847 ** Function         nfa_dm_act_send_vsc
    848 **
    849 ** Description      Send the NCI Vendor Specific command to the NCI command queue
    850 **
    851 ** Returns          FALSE (message buffer is NOT freed by caller)
    852 **
    853 *******************************************************************************/
    854 BOOLEAN nfa_dm_act_send_vsc(tNFA_DM_MSG *p_data)
    855 {
    856     BT_HDR  *p_cmd = (BT_HDR *)p_data;
    857 
    858     p_cmd->offset   = sizeof (tNFA_DM_API_SEND_VSC) - BT_HDR_SIZE;
    859     p_cmd->len      = p_data->send_vsc.cmd_params_len;
    860     NFC_SendVsCommand (p_data->send_vsc.oid, p_cmd, p_data->send_vsc.p_cback);
    861 
    862     /* Most dm action functions return TRUE, so nfa-sys frees the GKI buffer carrying the message,
    863      * This action function re-use the GKI buffer to send the VSC, so the GKI buffer can not be freed by nfa-sys */
    864     return (FALSE);
    865 }
    866 
    867 /*******************************************************************************
    868 **
    869 ** Function         nfa_dm_start_polling
    870 **
    871 ** Description      Start polling
    872 **
    873 ** Returns          tNFA_STATUS
    874 **
    875 *******************************************************************************/
    876 tNFA_STATUS nfa_dm_start_polling (void)
    877 {
    878     tNFA_STATUS             status;
    879     tNFA_TECHNOLOGY_MASK    poll_tech_mask;
    880     tNFA_DM_DISC_TECH_PROTO_MASK poll_disc_mask = 0;
    881 
    882     NFA_TRACE_DEBUG0 ("nfa_dm_start_polling ()");
    883 
    884     poll_tech_mask = nfa_dm_cb.poll_mask;
    885 
    886     /* start RF discovery with discovery callback */
    887     if (nfa_dm_cb.poll_disc_handle == NFA_HANDLE_INVALID)
    888     {
    889         if (poll_tech_mask & NFA_TECHNOLOGY_MASK_A)
    890         {
    891             poll_disc_mask |= NFA_DM_DISC_MASK_PA_T1T;
    892             poll_disc_mask |= NFA_DM_DISC_MASK_PA_T2T;
    893             poll_disc_mask |= NFA_DM_DISC_MASK_PA_ISO_DEP;
    894             poll_disc_mask |= NFA_DM_DISC_MASK_PA_NFC_DEP;
    895             poll_disc_mask |= NFA_DM_DISC_MASK_P_LEGACY;
    896         }
    897         if (poll_tech_mask & NFA_TECHNOLOGY_MASK_A_ACTIVE)
    898         {
    899             poll_disc_mask |= NFA_DM_DISC_MASK_PAA_NFC_DEP;
    900         }
    901         if (poll_tech_mask & NFA_TECHNOLOGY_MASK_B)
    902         {
    903             poll_disc_mask |= NFA_DM_DISC_MASK_PB_ISO_DEP;
    904         }
    905         if (poll_tech_mask & NFA_TECHNOLOGY_MASK_F)
    906         {
    907             poll_disc_mask |= NFA_DM_DISC_MASK_PF_T3T;
    908             poll_disc_mask |= NFA_DM_DISC_MASK_PF_NFC_DEP;
    909         }
    910         if (poll_tech_mask & NFA_TECHNOLOGY_MASK_F_ACTIVE)
    911         {
    912             poll_disc_mask |= NFA_DM_DISC_MASK_PFA_NFC_DEP;
    913         }
    914         if (poll_tech_mask & NFA_TECHNOLOGY_MASK_ISO15693)
    915         {
    916             poll_disc_mask |= NFA_DM_DISC_MASK_P_ISO15693;
    917         }
    918         if (poll_tech_mask & NFA_TECHNOLOGY_MASK_B_PRIME)
    919         {
    920             poll_disc_mask |= NFA_DM_DISC_MASK_P_B_PRIME;
    921         }
    922         if (poll_tech_mask & NFA_TECHNOLOGY_MASK_KOVIO)
    923         {
    924             poll_disc_mask |= NFA_DM_DISC_MASK_P_KOVIO;
    925         }
    926 
    927         nfa_dm_cb.poll_disc_handle = nfa_dm_add_rf_discover (poll_disc_mask,
    928                                                              NFA_DM_DISC_HOST_ID_DH,
    929                                                              nfa_dm_poll_disc_cback);
    930 
    931         if (nfa_dm_cb.poll_disc_handle != NFA_HANDLE_INVALID)
    932             status = NFA_STATUS_OK;
    933         else
    934             status = NFA_STATUS_FAILED;
    935     }
    936     else
    937     {
    938         status = NFA_STATUS_OK;
    939     }
    940 
    941     return (status);
    942 }
    943 
    944 /*******************************************************************************
    945 **
    946 ** Function         nfa_dm_act_enable_polling
    947 **
    948 ** Description      Process enable polling command
    949 **
    950 ** Returns          TRUE (message buffer to be freed by caller)
    951 **
    952 *******************************************************************************/
    953 BOOLEAN nfa_dm_act_enable_polling (tNFA_DM_MSG *p_data)
    954 {
    955     tNFA_CONN_EVT_DATA evt_data;
    956 
    957     NFA_TRACE_DEBUG0 ("nfa_dm_act_enable_polling ()");
    958 
    959     if (  (!(nfa_dm_cb.flags & NFA_DM_FLAGS_POLLING_ENABLED))
    960         &&(!(nfa_dm_cb.flags & NFA_DM_FLAGS_EXCL_RF_ACTIVE)  )  )
    961     {
    962         nfa_dm_cb.poll_mask = p_data->enable_poll.poll_mask;
    963 
    964         if (nfa_dm_start_polling () == NFA_STATUS_OK)
    965         {
    966             nfa_dm_cb.flags |= NFA_DM_FLAGS_POLLING_ENABLED;
    967 
    968             evt_data.status = NFA_STATUS_OK;
    969             nfa_dm_conn_cback_event_notify (NFA_POLL_ENABLED_EVT, &evt_data);
    970             return (TRUE);
    971         }
    972     }
    973     else
    974     {
    975         NFA_TRACE_ERROR0 ("nfa_dm_act_enable_polling (): already started");
    976     }
    977 
    978     /* send NFA_POLL_ENABLED_EVT with NFA_STATUS_FAILED */
    979     evt_data.status = NFA_STATUS_FAILED;
    980     nfa_dm_conn_cback_event_notify (NFA_POLL_ENABLED_EVT, &evt_data);
    981 
    982     return (TRUE);
    983 }
    984 
    985 /*******************************************************************************
    986 **
    987 ** Function         nfa_dm_deactivate_polling
    988 **
    989 ** Description      Deactivate any polling state
    990 **
    991 ** Returns          TRUE if need to wait for deactivation
    992 **
    993 *******************************************************************************/
    994 static BOOLEAN nfa_dm_deactivate_polling (void)
    995 {
    996     NFA_TRACE_DEBUG0 ("nfa_dm_deactivate_polling ()");
    997 
    998     if (  (nfa_dm_cb.disc_cb.disc_state == NFA_DM_RFST_W4_ALL_DISCOVERIES)
    999         ||(nfa_dm_cb.disc_cb.disc_state == NFA_DM_RFST_W4_HOST_SELECT)  )
   1000     {
   1001         nfa_dm_rf_deactivate (NFA_DEACTIVATE_TYPE_IDLE);
   1002         return FALSE;
   1003     }
   1004     else if (nfa_dm_cb.disc_cb.disc_state == NFA_DM_RFST_POLL_ACTIVE)
   1005     {
   1006         if (nfa_dm_cb.disc_cb.activated_protocol == NFC_PROTOCOL_NFC_DEP)
   1007         {
   1008             /* NFA P2P will deactivate NFC link after deactivating LLCP link */
   1009             nfa_p2p_deactivate_llcp ();
   1010         }
   1011         else
   1012         {
   1013             nfa_dm_rf_deactivate (NFA_DEACTIVATE_TYPE_IDLE);
   1014         }
   1015         return TRUE;
   1016     }
   1017     else
   1018     {
   1019         return FALSE;
   1020     }
   1021 }
   1022 
   1023 /*******************************************************************************
   1024 **
   1025 ** Function         nfa_dm_act_disable_polling
   1026 **
   1027 ** Description      Process disable polling command
   1028 **
   1029 ** Returns          TRUE (message buffer to be freed by caller)
   1030 **
   1031 *******************************************************************************/
   1032 BOOLEAN nfa_dm_act_disable_polling (tNFA_DM_MSG *p_data)
   1033 {
   1034     tNFA_CONN_EVT_DATA evt_data;
   1035 
   1036     NFA_TRACE_DEBUG0 ("nfa_dm_act_disable_polling ()");
   1037 
   1038     if (nfa_dm_cb.poll_disc_handle != NFA_HANDLE_INVALID)
   1039     {
   1040         nfa_dm_cb.flags &= ~NFA_DM_FLAGS_POLLING_ENABLED;
   1041 
   1042         if (nfa_dm_deactivate_polling () == FALSE)
   1043         {
   1044             nfa_dm_delete_rf_discover (nfa_dm_cb.poll_disc_handle);
   1045             nfa_dm_cb.poll_disc_handle = NFA_HANDLE_INVALID;
   1046 
   1047             evt_data.status = NFA_STATUS_OK;
   1048             nfa_dm_conn_cback_event_notify (NFA_POLL_DISABLED_EVT, &evt_data);
   1049         }
   1050         else
   1051         {
   1052             nfa_dm_cb.flags |= NFA_DM_FLAGS_SEND_POLL_STOP_EVT;
   1053         }
   1054     }
   1055     else
   1056     {
   1057         evt_data.status = NFA_STATUS_FAILED;
   1058         nfa_dm_conn_cback_event_notify (NFA_POLL_DISABLED_EVT, &evt_data);
   1059     }
   1060 
   1061     return (TRUE);
   1062 }
   1063 
   1064 /*******************************************************************************
   1065 **
   1066 ** Function         nfa_dm_act_enable_listening
   1067 **
   1068 ** Description      Process enable listening command
   1069 **
   1070 ** Returns          TRUE (message buffer to be freed by caller)
   1071 **
   1072 *******************************************************************************/
   1073 BOOLEAN nfa_dm_act_enable_listening (tNFA_DM_MSG *p_data)
   1074 {
   1075     tNFA_CONN_EVT_DATA evt_data;
   1076 
   1077     NFA_TRACE_DEBUG0 ("nfa_dm_act_enable_listening ()");
   1078 
   1079     nfa_dm_cb.flags &= ~NFA_DM_FLAGS_LISTEN_DISABLED;
   1080     evt_data.status = NFA_STATUS_OK;
   1081     nfa_dm_conn_cback_event_notify (NFA_LISTEN_ENABLED_EVT, &evt_data);
   1082 
   1083     return (TRUE);
   1084 }
   1085 
   1086 /*******************************************************************************
   1087 **
   1088 ** Function         nfa_dm_act_disable_listening
   1089 **
   1090 ** Description      Process disable listening command
   1091 **
   1092 ** Returns          TRUE (message buffer to be freed by caller)
   1093 **
   1094 *******************************************************************************/
   1095 BOOLEAN nfa_dm_act_disable_listening (tNFA_DM_MSG *p_data)
   1096 {
   1097     tNFA_CONN_EVT_DATA evt_data;
   1098 
   1099     NFA_TRACE_DEBUG0 ("nfa_dm_act_disable_listening ()");
   1100 
   1101     nfa_dm_cb.flags |= NFA_DM_FLAGS_LISTEN_DISABLED;
   1102     evt_data.status = NFA_STATUS_OK;
   1103     nfa_dm_conn_cback_event_notify (NFA_LISTEN_DISABLED_EVT, &evt_data);
   1104 
   1105     return (TRUE);
   1106 }
   1107 
   1108 /*******************************************************************************
   1109 **
   1110 ** Function         nfa_dm_act_pause_p2p
   1111 **
   1112 ** Description      Process Pause P2P command
   1113 **
   1114 ** Returns          TRUE (message buffer to be freed by caller)
   1115 **
   1116 *******************************************************************************/
   1117 BOOLEAN nfa_dm_act_pause_p2p (tNFA_DM_MSG *p_data)
   1118 {
   1119     tNFA_CONN_EVT_DATA evt_data;
   1120 
   1121     NFA_TRACE_DEBUG0 ("nfa_dm_act_pause_p2p ()");
   1122 
   1123     nfa_dm_cb.flags |= NFA_DM_FLAGS_P2P_PAUSED;
   1124     evt_data.status = NFA_STATUS_OK;
   1125     nfa_dm_conn_cback_event_notify (NFA_P2P_PAUSED_EVT, &evt_data);
   1126 
   1127     return (TRUE);
   1128 }
   1129 
   1130 /*******************************************************************************
   1131 **
   1132 ** Function         nfa_dm_act_resume_p2p
   1133 **
   1134 ** Description      Process resume P2P command
   1135 **
   1136 ** Returns          TRUE (message buffer to be freed by caller)
   1137 **
   1138 *******************************************************************************/
   1139 BOOLEAN nfa_dm_act_resume_p2p (tNFA_DM_MSG *p_data)
   1140 {
   1141     tNFA_CONN_EVT_DATA evt_data;
   1142 
   1143     NFA_TRACE_DEBUG0 ("nfa_dm_act_resume_p2p ()");
   1144 
   1145     nfa_dm_cb.flags &= ~NFA_DM_FLAGS_P2P_PAUSED;
   1146     evt_data.status = NFA_STATUS_OK;
   1147     nfa_dm_conn_cback_event_notify (NFA_P2P_RESUMED_EVT, &evt_data);
   1148 
   1149     return (TRUE);
   1150 }
   1151 
   1152 /*******************************************************************************
   1153 **
   1154 ** Function         nfa_dm_act_send_raw_frame
   1155 **
   1156 ** Description      Send an raw frame on RF link
   1157 **
   1158 ** Returns          TRUE (message buffer to be freed by caller)
   1159 **
   1160 *******************************************************************************/
   1161 BOOLEAN nfa_dm_act_send_raw_frame (tNFA_DM_MSG *p_data)
   1162 {
   1163     tNFC_STATUS status = NFC_STATUS_FAILED;
   1164 
   1165     NFA_TRACE_DEBUG0 ("nfa_dm_act_send_raw_frame ()");
   1166 
   1167     /* If NFC link is activated */
   1168     if (  (nfa_dm_cb.disc_cb.disc_state == NFA_DM_RFST_POLL_ACTIVE)
   1169         ||(nfa_dm_cb.disc_cb.disc_state == NFA_DM_RFST_LISTEN_ACTIVE)  )
   1170     {
   1171         /* If not in exclusive mode, and not activated for LISTEN, then forward raw data to NFA_RW to send */
   1172         if (  !(nfa_dm_cb.flags & NFA_DM_FLAGS_EXCL_RF_ACTIVE)
   1173             &&!(nfa_dm_cb.disc_cb.disc_state == NFA_DM_RFST_LISTEN_ACTIVE)
   1174             &&(  (nfa_dm_cb.disc_cb.activated_protocol == NFA_PROTOCOL_T1T)
   1175                ||(nfa_dm_cb.disc_cb.activated_protocol == NFA_PROTOCOL_T2T)
   1176                ||(nfa_dm_cb.disc_cb.activated_protocol == NFA_PROTOCOL_T3T)
   1177                ||(nfa_dm_cb.disc_cb.activated_protocol == NFA_PROTOCOL_ISO_DEP)
   1178                ||(nfa_dm_cb.disc_cb.activated_protocol == NFA_PROTOCOL_ISO15693)  )  )
   1179         {
   1180             /* if RW is checking presence then it will put into pending queue */
   1181             status = nfa_rw_send_raw_frame ((BT_HDR*)p_data);
   1182         }
   1183         else
   1184         {
   1185             status = NFC_SendData (NFC_RF_CONN_ID, (BT_HDR*) p_data);
   1186             /* Already freed or NCI layer will free buffer */
   1187             return FALSE;
   1188         }
   1189     }
   1190 
   1191     if (status == NFC_STATUS_FAILED)
   1192     {
   1193         /* free the buffer */
   1194         return TRUE;
   1195     }
   1196     else
   1197     {
   1198         /* NCI layer will free buffer */
   1199         return FALSE;
   1200     }
   1201 }
   1202 
   1203 /*******************************************************************************
   1204 **
   1205 ** Function         nfa_dm_set_p2p_listen_tech
   1206 **
   1207 ** Description      Notify change of P2P listen technologies to NFA P2P
   1208 **
   1209 ** Returns          TRUE (message buffer to be freed by caller)
   1210 **
   1211 *******************************************************************************/
   1212 BOOLEAN nfa_dm_set_p2p_listen_tech (tNFA_DM_MSG *p_data)
   1213 {
   1214     NFA_TRACE_DEBUG1 ("nfa_dm_set_p2p_listen_tech ()  tech_mask = %d",
   1215                       p_data->set_p2p_listen_tech.tech_mask);
   1216 
   1217     nfa_p2p_update_listen_tech (p_data->set_p2p_listen_tech.tech_mask);
   1218     nfa_dm_conn_cback_event_notify (NFA_SET_P2P_LISTEN_TECH_EVT, NULL);
   1219 
   1220     return (TRUE);
   1221 }
   1222 
   1223 /*******************************************************************************
   1224 **
   1225 ** Function         nfa_dm_act_start_rf_discovery
   1226 **
   1227 ** Description      Process start RF discovery command
   1228 **
   1229 ** Returns          TRUE (message buffer to be freed by caller)
   1230 **
   1231 *******************************************************************************/
   1232 BOOLEAN nfa_dm_act_start_rf_discovery (tNFA_DM_MSG *p_data)
   1233 {
   1234     tNFA_CONN_EVT_DATA evt_data;
   1235 
   1236     NFA_TRACE_DEBUG0 ("nfa_dm_act_start_rf_discovery ()");
   1237 
   1238     if (nfa_dm_cb.disc_cb.disc_flags & NFA_DM_DISC_FLAGS_ENABLED)
   1239     {
   1240         evt_data.status = NFA_STATUS_OK;
   1241         nfa_dm_conn_cback_event_notify (NFA_RF_DISCOVERY_STARTED_EVT, &evt_data);
   1242     }
   1243     else if (nfa_dm_cb.disc_cb.disc_state != NFA_DM_RFST_IDLE)
   1244     {
   1245         evt_data.status = NFA_STATUS_SEMANTIC_ERROR;
   1246         nfa_dm_conn_cback_event_notify (NFA_RF_DISCOVERY_STARTED_EVT, &evt_data);
   1247     }
   1248     else
   1249     {
   1250         nfa_dm_cb.disc_cb.disc_flags |= (NFA_DM_DISC_FLAGS_ENABLED|NFA_DM_DISC_FLAGS_NOTIFY);
   1251         nfa_dm_start_rf_discover ();
   1252     }
   1253 
   1254     return (TRUE);
   1255 }
   1256 
   1257 /*******************************************************************************
   1258 **
   1259 ** Function         nfa_dm_act_stop_rf_discovery
   1260 **
   1261 ** Description      Process stop RF discovery command
   1262 **
   1263 ** Returns          TRUE (message buffer to be freed by caller)
   1264 **
   1265 *******************************************************************************/
   1266 BOOLEAN nfa_dm_act_stop_rf_discovery (tNFA_DM_MSG *p_data)
   1267 {
   1268     tNFA_CONN_EVT_DATA evt_data;
   1269 
   1270     NFA_TRACE_DEBUG0 ("nfa_dm_act_stop_rf_discovery ()");
   1271 
   1272     if (!(nfa_dm_cb.disc_cb.disc_flags & NFA_DM_DISC_FLAGS_ENABLED) ||
   1273         (nfa_dm_cb.disc_cb.disc_state == NFA_DM_RFST_IDLE) )
   1274     {
   1275         nfa_dm_cb.disc_cb.disc_flags &= ~NFA_DM_DISC_FLAGS_ENABLED;
   1276 
   1277         /* if discover command has been sent in IDLE state and waiting for response */
   1278         if (nfa_dm_cb.disc_cb.disc_flags & NFA_DM_DISC_FLAGS_W4_RSP)
   1279         {
   1280             nfa_dm_cb.disc_cb.disc_flags |= NFA_DM_DISC_FLAGS_STOPPING;
   1281         }
   1282         else
   1283         {
   1284             evt_data.status = NFA_STATUS_OK;
   1285             nfa_dm_conn_cback_event_notify (NFA_RF_DISCOVERY_STOPPED_EVT, &evt_data);
   1286         }
   1287     }
   1288     else
   1289     {
   1290         nfa_dm_cb.disc_cb.disc_flags &= ~NFA_DM_DISC_FLAGS_ENABLED;
   1291         nfa_dm_cb.disc_cb.disc_flags |= NFA_DM_DISC_FLAGS_STOPPING;
   1292 
   1293         if (nfa_dm_rf_deactivate (NFA_DEACTIVATE_TYPE_IDLE) == NFA_STATUS_OK)
   1294         {
   1295             if (nfa_dm_cb.disc_cb.kovio_tle.in_use)
   1296                 nfa_sys_stop_timer (&nfa_dm_cb.disc_cb.kovio_tle);
   1297             nfa_rw_stop_presence_check_timer ();
   1298         }
   1299     }
   1300     return (TRUE);
   1301 }
   1302 
   1303 /*******************************************************************************
   1304 **
   1305 ** Function         nfa_dm_act_set_rf_disc_duration
   1306 **
   1307 ** Description      Set duration for RF discovery
   1308 **
   1309 ** Returns          TRUE (message buffer to be freed by caller)
   1310 **
   1311 *******************************************************************************/
   1312 BOOLEAN nfa_dm_act_set_rf_disc_duration (tNFA_DM_MSG *p_data)
   1313 {
   1314     nfa_dm_cb.disc_cb.disc_duration = p_data->disc_duration.rf_disc_dur_ms;
   1315     return (TRUE);
   1316 }
   1317 
   1318 /*******************************************************************************
   1319 **
   1320 ** Function         nfa_dm_act_select
   1321 **
   1322 ** Description      Process RF select command
   1323 **
   1324 ** Returns          TRUE (message buffer to be freed by caller)
   1325 **
   1326 *******************************************************************************/
   1327 BOOLEAN nfa_dm_act_select (tNFA_DM_MSG *p_data)
   1328 {
   1329     NFA_TRACE_DEBUG0 ("nfa_dm_act_select ()");
   1330 
   1331     nfa_dm_rf_discover_select (p_data->select.rf_disc_id,
   1332                                p_data->select.protocol,
   1333                                p_data->select.rf_interface);
   1334     return (TRUE);
   1335 }
   1336 
   1337 /*******************************************************************************
   1338 **
   1339 ** Function         nfa_dm_act_update_rf_params
   1340 **
   1341 ** Description      Process update RF communication parameters command
   1342 **
   1343 ** Returns          TRUE (message buffer to be freed by caller)
   1344 **
   1345 *******************************************************************************/
   1346 BOOLEAN nfa_dm_act_update_rf_params (tNFA_DM_MSG *p_data)
   1347 {
   1348     tNFA_CONN_EVT_DATA conn_evt;
   1349 
   1350     NFA_TRACE_DEBUG0 ("nfa_dm_act_update_rf_params ()");
   1351 
   1352     if (NFC_UpdateRFCommParams (&p_data->update_rf_params.params) != NFC_STATUS_OK)
   1353     {
   1354         conn_evt.status = NFA_STATUS_FAILED;
   1355         nfa_dm_conn_cback_event_notify (NFA_UPDATE_RF_PARAM_RESULT_EVT, &conn_evt);
   1356     }
   1357 
   1358     return (TRUE);
   1359 }
   1360 
   1361 /*******************************************************************************
   1362 **
   1363 ** Function         nfa_dm_act_disable_timeout
   1364 **
   1365 ** Description      timeout on disable process. Shutdown immediately
   1366 **
   1367 ** Returns          TRUE (message buffer to be freed by caller)
   1368 **
   1369 *******************************************************************************/
   1370 BOOLEAN nfa_dm_act_disable_timeout (tNFA_DM_MSG *p_data)
   1371 {
   1372     tNFA_DM_API_DISABLE disable;
   1373 
   1374     disable.graceful = FALSE;
   1375     nfa_dm_disable ((tNFA_DM_MSG *) &disable);
   1376     return (TRUE);
   1377 }
   1378 
   1379 /*******************************************************************************
   1380 **
   1381 ** Function         nfa_dm_act_conn_cback_notify
   1382 **
   1383 ** Description      Notify app of reader/writer/ndef events
   1384 **
   1385 ** Returns          nothing
   1386 **
   1387 *******************************************************************************/
   1388 void nfa_dm_act_conn_cback_notify (UINT8 event, tNFA_CONN_EVT_DATA *p_data)
   1389 {
   1390     NFA_TRACE_DEBUG1 ("nfa_dm_act_conn_cback_notify (): event:0x%X", event);
   1391 
   1392     /* Notify event using appropriate CONN_CBACK */
   1393     nfa_dm_conn_cback_event_notify (event, p_data);
   1394 
   1395     /* If not in exclusive RF mode, then read NDEF message from tag (if automatic reading is enabled) */
   1396     if (!(nfa_dm_cb.flags & NFA_DM_FLAGS_EXCL_RF_ACTIVE))
   1397     {
   1398         if (  (event == NFA_NDEF_DETECT_EVT)
   1399             &&(nfa_dm_cb.flags & NFA_DM_FLAGS_AUTO_READING_NDEF)  )
   1400         {
   1401             /* read NDEF message from tag */
   1402             if (p_data->ndef_detect.status == NFA_STATUS_OK)
   1403             {
   1404                 NFA_RwReadNDef ();
   1405             }
   1406             else if (p_data->ndef_detect.status == NFA_STATUS_FAILED)
   1407             {
   1408                 nfa_dm_cb.flags &= ~NFA_DM_FLAGS_AUTO_READING_NDEF;
   1409             }
   1410             /* ignore NFA_STATUS_BUSY */
   1411         }
   1412         else if (  (event == NFA_READ_CPLT_EVT)
   1413                  &&(nfa_dm_cb.flags & NFA_DM_FLAGS_AUTO_READING_NDEF))
   1414         {
   1415             /* reading NDEF message is done */
   1416             nfa_dm_cb.flags &= ~NFA_DM_FLAGS_AUTO_READING_NDEF;
   1417         }
   1418     }
   1419 }
   1420 
   1421 /*******************************************************************************
   1422 **
   1423 ** Function         nfa_dm_act_data_cback
   1424 **
   1425 ** Description      Processing data from RF link
   1426 **
   1427 ** Returns          None
   1428 **
   1429 *******************************************************************************/
   1430 static void nfa_dm_act_data_cback (UINT8 conn_id, tNFC_CONN_EVT event, tNFC_CONN *p_data)
   1431 {
   1432     BT_HDR             *p_msg;
   1433     tNFA_CONN_EVT_DATA evt_data;
   1434 
   1435     NFA_TRACE_DEBUG1 ("nfa_dm_act_data_cback (): event = 0x%X", event);
   1436 
   1437     if (event == NFC_DATA_CEVT)
   1438     {
   1439         p_msg = (BT_HDR *) p_data->data.p_data;
   1440 
   1441         if (p_msg)
   1442         {
   1443             evt_data.data.p_data = (UINT8 *) (p_msg + 1) + p_msg->offset;
   1444             evt_data.data.len    = p_msg->len;
   1445 
   1446             nfa_dm_conn_cback_event_notify (NFA_DATA_EVT, &evt_data);
   1447 
   1448             GKI_freebuf (p_msg);
   1449         }
   1450         else
   1451         {
   1452             NFA_TRACE_ERROR0 ("nfa_dm_act_data_cback (): received NFC_DATA_CEVT with NULL data pointer");
   1453         }
   1454     }
   1455     else if (event == NFC_DEACTIVATE_CEVT)
   1456     {
   1457         NFC_SetStaticRfCback (NULL);
   1458     }
   1459 }
   1460 
   1461 /*******************************************************************************
   1462 **
   1463 ** Function         nfa_dm_excl_disc_cback
   1464 **
   1465 ** Description      Processing event from discovery callback
   1466 **
   1467 ** Returns          None
   1468 **
   1469 *******************************************************************************/
   1470 static void nfa_dm_excl_disc_cback (tNFA_DM_RF_DISC_EVT event, tNFC_DISCOVER *p_data)
   1471 {
   1472     tNFA_CONN_EVT_DATA evt_data;
   1473 
   1474     NFA_TRACE_DEBUG1 ("nfa_dm_excl_disc_cback (): event:0x%02X", event);
   1475 
   1476     switch (event)
   1477     {
   1478     case NFA_DM_RF_DISC_START_EVT:
   1479         evt_data.status = NFA_STATUS_OK;
   1480         nfa_dm_conn_cback_event_notify (NFA_EXCLUSIVE_RF_CONTROL_STARTED_EVT, &evt_data);
   1481         break;
   1482 
   1483     case NFA_DM_RF_DISC_ACTIVATED_EVT:
   1484         if (nfa_dm_cb.disc_cb.activated_tech_mode == NFC_DISCOVERY_TYPE_POLL_A)
   1485         {
   1486             /* store SEL_RES response */
   1487             nfa_dm_cb.disc_cb.activated_sel_res = p_data->activate.rf_tech_param.param.pa.sel_rsp;
   1488         }
   1489 
   1490         if (nfa_dm_cb.disc_cb.disc_state == NFA_DM_RFST_LISTEN_ACTIVE)
   1491         {
   1492             /* Set data callback to receive raw frame */
   1493             NFC_SetStaticRfCback (nfa_dm_act_data_cback);
   1494 
   1495             memset (&(evt_data.activated.params), 0x00, sizeof (tNFA_TAG_PARAMS));
   1496             memcpy (&(evt_data.activated.activate_ntf), &(p_data->activate), sizeof (tNFC_ACTIVATE_DEVT));
   1497 
   1498             nfa_dm_conn_cback_event_notify (NFA_ACTIVATED_EVT, &evt_data);
   1499         }
   1500         else
   1501         {
   1502             /* holding activation notification until sub-module is ready */
   1503             nfa_dm_cb.p_activate_ntf = (UINT8*) GKI_getbuf (sizeof (tNFC_ACTIVATE_DEVT));
   1504 
   1505             if (nfa_dm_cb.p_activate_ntf)
   1506             {
   1507                 memcpy (nfa_dm_cb.p_activate_ntf,
   1508                         &(p_data->activate),
   1509                         sizeof (tNFC_ACTIVATE_DEVT));
   1510 
   1511                 if (  (nfa_dm_cb.disc_cb.activated_protocol  == NFC_PROTOCOL_T1T)
   1512                     ||(nfa_dm_cb.disc_cb.activated_protocol  == NFC_PROTOCOL_T2T)
   1513                     ||(nfa_dm_cb.disc_cb.activated_protocol  == NFC_PROTOCOL_T3T)
   1514                     ||(nfa_dm_cb.disc_cb.activated_protocol  == NFC_PROTOCOL_ISO_DEP)
   1515                     ||(nfa_dm_cb.disc_cb.activated_protocol  == NFA_PROTOCOL_ISO15693)
   1516                     ||(nfa_dm_cb.disc_cb.activated_protocol  == NFC_PROTOCOL_KOVIO)  )
   1517                 {
   1518                     /* Notify NFA tag sub-system */
   1519                     nfa_rw_proc_disc_evt (NFA_DM_RF_DISC_ACTIVATED_EVT, p_data, FALSE);
   1520                 }
   1521                 else /* if NFC-DEP, ISO-DEP with frame interface or others */
   1522                 {
   1523                     /* Set data callback to receive raw frame */
   1524                     NFC_SetStaticRfCback (nfa_dm_act_data_cback);
   1525                     nfa_dm_notify_activation_status (NFA_STATUS_OK, NULL);
   1526                 }
   1527             }
   1528             else
   1529             {
   1530                 /* deactivate and restart RF discovery */
   1531                 nfa_dm_rf_deactivate (NFA_DEACTIVATE_TYPE_DISCOVERY);
   1532             }
   1533         }
   1534         break;
   1535 
   1536     case NFA_DM_RF_DISC_DEACTIVATED_EVT:
   1537 
   1538         /* if deactivated to idle or discovery */
   1539         if (  (p_data->deactivate.type == NFC_DEACTIVATE_TYPE_IDLE)
   1540             ||(p_data->deactivate.type == NFC_DEACTIVATE_TYPE_DISCOVERY)  )
   1541         {
   1542             /* clear stored NFCID/UID/KOVIO bar code */
   1543             nfa_dm_cb.activated_nfcid_len = 0;
   1544         }
   1545 
   1546         if (nfa_dm_cb.disc_cb.activated_protocol != NFC_PROTOCOL_NFC_DEP)
   1547         {
   1548             /* Notify NFA RW sub-systems */
   1549             nfa_rw_proc_disc_evt (NFA_DM_RF_DISC_DEACTIVATED_EVT, NULL, FALSE);
   1550         }
   1551 
   1552         /* if deactivated as sleep mode */
   1553         if (  (p_data->deactivate.type == NFC_DEACTIVATE_TYPE_SLEEP)
   1554             ||(p_data->deactivate.type == NFC_DEACTIVATE_TYPE_SLEEP_AF)  )
   1555         {
   1556             evt_data.deactivated.type = NFA_DEACTIVATE_TYPE_SLEEP;
   1557         }
   1558         else
   1559         {
   1560             evt_data.deactivated.type = NFA_DEACTIVATE_TYPE_IDLE;
   1561         }
   1562 
   1563         /* notify deactivation to upper layer */
   1564         nfa_dm_conn_cback_event_notify (NFA_DEACTIVATED_EVT, &evt_data);
   1565 
   1566         /* clean up SEL_RES response */
   1567         nfa_dm_cb.disc_cb.activated_sel_res = 0;
   1568         break;
   1569 
   1570     default:
   1571         NFA_TRACE_ERROR0 ("Unexpected event");
   1572         break;
   1573     }
   1574 }
   1575 
   1576 /*******************************************************************************
   1577 **
   1578 ** Function         nfa_dm_poll_disc_cback
   1579 **
   1580 ** Description      Processing event from discovery callback
   1581 **
   1582 ** Returns          None
   1583 **
   1584 *******************************************************************************/
   1585 static void nfa_dm_poll_disc_cback (tNFA_DM_RF_DISC_EVT event, tNFC_DISCOVER *p_data)
   1586 {
   1587     tNFA_CONN_EVT_DATA evt_data;
   1588 
   1589     NFA_TRACE_DEBUG1 ("nfa_dm_poll_disc_cback (): event:0x%02X", event);
   1590 
   1591     switch (event)
   1592     {
   1593     case NFA_DM_RF_DISC_START_EVT:
   1594         break;
   1595 
   1596     case NFA_DM_RF_DISC_ACTIVATED_EVT:
   1597 
   1598         if (nfa_dm_cb.disc_cb.activated_tech_mode == NFC_DISCOVERY_TYPE_POLL_A)
   1599         {
   1600             /* store SEL_RES response */
   1601             nfa_dm_cb.disc_cb.activated_sel_res = p_data->activate.rf_tech_param.param.pa.sel_rsp;
   1602         }
   1603 
   1604         /* holding activation notification until sub-module is ready */
   1605         nfa_dm_cb.p_activate_ntf = (UINT8*) GKI_getbuf (sizeof (tNFC_ACTIVATE_DEVT));
   1606 
   1607         if (nfa_dm_cb.p_activate_ntf)
   1608         {
   1609             memcpy (nfa_dm_cb.p_activate_ntf,
   1610                     &(p_data->activate),
   1611                     sizeof (tNFC_ACTIVATE_DEVT));
   1612 
   1613             if (  (nfa_dm_cb.disc_cb.activated_protocol     == NFC_PROTOCOL_NFC_DEP)
   1614                 &&(nfa_dm_cb.disc_cb.activated_rf_interface == NFC_INTERFACE_NFC_DEP)  )
   1615             {
   1616                 if (!(nfa_dm_cb.flags & NFA_DM_FLAGS_P2P_PAUSED))
   1617                 {
   1618                     /* activate LLCP */
   1619                     nfa_p2p_activate_llcp (p_data);
   1620                 }
   1621                 else
   1622                 {
   1623                     NFA_TRACE_DEBUG0 ("P2P is paused");
   1624                     nfa_dm_notify_activation_status (NFA_STATUS_OK, NULL);
   1625                 }
   1626             }
   1627             else if (  (nfa_dm_cb.disc_cb.activated_protocol  == NFC_PROTOCOL_T1T)
   1628                      ||(nfa_dm_cb.disc_cb.activated_protocol  == NFC_PROTOCOL_T2T)
   1629                      ||(nfa_dm_cb.disc_cb.activated_protocol  == NFC_PROTOCOL_T3T)
   1630                      ||(nfa_dm_cb.disc_cb.activated_protocol  == NFC_PROTOCOL_ISO_DEP)
   1631                      ||(nfa_dm_cb.disc_cb.activated_protocol  == NFC_PROTOCOL_15693)
   1632                      ||(nfa_dm_cb.disc_cb.activated_protocol  == NFC_PROTOCOL_KOVIO)  )
   1633             {
   1634                 /* Notify NFA tag sub-system */
   1635                 nfa_rw_proc_disc_evt (NFA_DM_RF_DISC_ACTIVATED_EVT, p_data, TRUE);
   1636             }
   1637             else /* if NFC-DEP/ISO-DEP with frame interface */
   1638             {
   1639                 /* Set data callback to receive raw frame */
   1640                 NFC_SetStaticRfCback (nfa_dm_act_data_cback);
   1641                 nfa_dm_notify_activation_status (NFA_STATUS_OK, NULL);
   1642             }
   1643         }
   1644         else
   1645         {
   1646             /* deactivate and restart RF discovery */
   1647             nfa_dm_rf_deactivate (NFA_DEACTIVATE_TYPE_DISCOVERY);
   1648         }
   1649         break;
   1650 
   1651     case NFA_DM_RF_DISC_DEACTIVATED_EVT:
   1652 
   1653         /* if deactivated to idle or discovery */
   1654         if (  (p_data->deactivate.type == NFC_DEACTIVATE_TYPE_IDLE)
   1655             ||(p_data->deactivate.type == NFC_DEACTIVATE_TYPE_DISCOVERY)  )
   1656         {
   1657             /* clear stored NFCID/UID/KOVIO bar code */
   1658             nfa_dm_cb.activated_nfcid_len = 0;
   1659         }
   1660 
   1661         if (  (nfa_dm_cb.disc_cb.activated_protocol     == NFC_PROTOCOL_NFC_DEP)
   1662             &&(nfa_dm_cb.disc_cb.activated_rf_interface == NFC_INTERFACE_NFC_DEP)  )
   1663         {
   1664             /*
   1665             ** If LLCP link is not deactivated yet,
   1666             ** LLCP will receive deactivation ntf through data callback.
   1667             ** NFA P2P will receive callback event from LLCP.
   1668             */
   1669         }
   1670         else
   1671         {
   1672             /* Notify NFA RW sub-systems */
   1673             nfa_rw_proc_disc_evt (NFA_DM_RF_DISC_DEACTIVATED_EVT, NULL, TRUE);
   1674         }
   1675 
   1676         /* if NFA sent NFA_ACTIVATED_EVT earlier */
   1677         if (nfa_dm_cb.flags & NFA_DM_FLAGS_SEND_DEACTIVATED_EVT)
   1678         {
   1679             nfa_dm_cb.flags &= ~NFA_DM_FLAGS_SEND_DEACTIVATED_EVT;
   1680 
   1681             /* if deactivated as sleep mode */
   1682             if (  (p_data->deactivate.type == NFC_DEACTIVATE_TYPE_SLEEP)
   1683                 ||(p_data->deactivate.type == NFC_DEACTIVATE_TYPE_SLEEP_AF)  )
   1684             {
   1685                 evt_data.deactivated.type = NFA_DEACTIVATE_TYPE_SLEEP;
   1686             }
   1687             else
   1688             {
   1689                 evt_data.deactivated.type = NFA_DEACTIVATE_TYPE_IDLE;
   1690             }
   1691             /* notify deactivation to application */
   1692             nfa_dm_conn_cback_event_notify (NFA_DEACTIVATED_EVT, &evt_data);
   1693         }
   1694 
   1695         /* clean up SEL_RES response */
   1696         nfa_dm_cb.disc_cb.activated_sel_res = 0;
   1697 
   1698         if (!(nfa_dm_cb.flags & NFA_DM_FLAGS_POLLING_ENABLED))
   1699         {
   1700             /* deregister discovery callback from NFA DM Discovery */
   1701             nfa_dm_delete_rf_discover (nfa_dm_cb.poll_disc_handle);
   1702             nfa_dm_cb.poll_disc_handle = NFA_HANDLE_INVALID;
   1703 
   1704             /* this is for disable polling */
   1705             if (nfa_dm_cb.flags & NFA_DM_FLAGS_SEND_POLL_STOP_EVT)
   1706             {
   1707                 nfa_dm_cb.flags &= ~NFA_DM_FLAGS_SEND_POLL_STOP_EVT;
   1708 
   1709                 evt_data.status = NFA_STATUS_OK;
   1710                 nfa_dm_conn_cback_event_notify (NFA_POLL_DISABLED_EVT, &evt_data);
   1711             }
   1712         }
   1713         break;
   1714     }
   1715 }
   1716 
   1717 /*******************************************************************************
   1718 **
   1719 ** Function         nfa_dm_notify_activation_status
   1720 **
   1721 ** Description      Processing activation status from sub-modules
   1722 **
   1723 ** Returns          None
   1724 **
   1725 *******************************************************************************/
   1726 void nfa_dm_notify_activation_status (tNFA_STATUS status, tNFA_TAG_PARAMS *p_params)
   1727 {
   1728     tNFA_CONN_EVT_DATA  evt_data;
   1729     tNFC_RF_TECH_PARAMS *p_tech_params;
   1730     UINT8               *p_nfcid = NULL, nfcid_len;
   1731 
   1732     NFA_TRACE_DEBUG1 ("nfa_dm_notify_activation_status (): status:0x%X", status);
   1733 
   1734     if (!nfa_dm_cb.p_activate_ntf)
   1735     {
   1736         /* this is for NFA P2P listen */
   1737         return;
   1738     }
   1739 
   1740     if (status == NFA_STATUS_OK)
   1741     {
   1742         /* notify NFC link activation */
   1743         memcpy ( &(evt_data.activated.activate_ntf),
   1744                  nfa_dm_cb.p_activate_ntf,
   1745                  sizeof (tNFC_ACTIVATE_DEVT));
   1746 
   1747         p_tech_params = &evt_data.activated.activate_ntf.rf_tech_param;
   1748 
   1749         memset (&(evt_data.activated.params), 0x00, sizeof (tNFA_TAG_PARAMS));
   1750         if (p_params)
   1751         {
   1752             memcpy (&(evt_data.activated.params),
   1753                     p_params,
   1754                     sizeof (tNFA_TAG_PARAMS));
   1755         }
   1756 
   1757         /* get length of NFCID and location */
   1758         if (p_tech_params->mode == NFC_DISCOVERY_TYPE_POLL_A)
   1759         {
   1760             nfcid_len = p_tech_params->param.pa.nfcid1_len;
   1761             p_nfcid   = p_tech_params->param.pa.nfcid1;
   1762         }
   1763         else if (p_tech_params->mode == NFC_DISCOVERY_TYPE_POLL_B)
   1764         {
   1765             nfcid_len = NFC_NFCID0_MAX_LEN;
   1766             p_nfcid   = p_tech_params->param.pb.nfcid0;
   1767         }
   1768         else if (p_tech_params->mode == NFC_DISCOVERY_TYPE_POLL_F)
   1769         {
   1770             nfcid_len = NFC_NFCID2_LEN;
   1771             p_nfcid   = p_tech_params->param.pf.nfcid2;
   1772         }
   1773         else if (p_tech_params->mode == NFC_DISCOVERY_TYPE_POLL_ISO15693)
   1774         {
   1775             nfcid_len = NFC_ISO15693_UID_LEN;
   1776             p_nfcid   = p_tech_params->param.pi93.uid;
   1777         }
   1778         else if (p_tech_params->mode == NFC_DISCOVERY_TYPE_POLL_KOVIO)
   1779         {
   1780             nfcid_len = p_tech_params->param.pk.uid_len;
   1781             p_nfcid   = p_tech_params->param.pk.uid;
   1782         }
   1783         else
   1784         {
   1785             nfcid_len = 0;
   1786         }
   1787 
   1788         /*
   1789         ** If not in exlusive RF mode, and
   1790         **      P2P activation, then push default NDEF message through SNEP
   1791         **      TAG activation, then read NDEF message
   1792         */
   1793         if (nfa_dm_cb.disc_cb.activated_protocol == NFC_PROTOCOL_NFC_DEP)
   1794         {
   1795             /*
   1796             ** Default NDEF message will be put to NFC Forum defualt SNEP server
   1797             ** after receiving NFA_LLCP_ACTIVATED_EVT.
   1798             */
   1799         }
   1800         else if (!(nfa_dm_cb.flags & NFA_DM_FLAGS_EXCL_RF_ACTIVE))
   1801         {
   1802             /*
   1803             ** if the same tag is activated then do not perform auto NDEF detection.
   1804             ** Application may put a tag into sleep mode and reactivate the same tag.
   1805             */
   1806 
   1807             if (  (p_tech_params->mode != nfa_dm_cb.activated_tech_mode)
   1808                 ||(nfcid_len != nfa_dm_cb.activated_nfcid_len)
   1809                 ||(memcmp (p_nfcid, nfa_dm_cb.activated_nfcid, nfcid_len)))
   1810             {
   1811                 if (  (nfa_dm_cb.disc_cb.activated_protocol  == NFC_PROTOCOL_T1T)
   1812                     ||(nfa_dm_cb.disc_cb.activated_protocol  == NFC_PROTOCOL_T2T)
   1813                     ||(nfa_dm_cb.disc_cb.activated_protocol  == NFC_PROTOCOL_T3T)
   1814                     ||(  (nfa_dm_cb.disc_cb.activated_protocol == NFC_PROTOCOL_ISO_DEP)
   1815                        &&(nfa_dm_cb.disc_cb.activated_rf_interface == NFC_INTERFACE_ISO_DEP)  )
   1816                     ||(nfa_dm_cb.disc_cb.activated_protocol  == NFA_PROTOCOL_ISO15693)  )
   1817                 {
   1818                     if (p_nfa_dm_cfg->auto_detect_ndef)
   1819                     {
   1820                         if (p_nfa_dm_cfg->auto_read_ndef)
   1821                         {
   1822                             nfa_dm_cb.flags |= NFA_DM_FLAGS_AUTO_READING_NDEF;
   1823                         }
   1824                         NFA_RwDetectNDef ();
   1825                     }
   1826                     else if (p_nfa_dm_cfg->auto_read_ndef)
   1827                     {
   1828                         NFA_RwReadNDef ();
   1829                     }
   1830                 }
   1831             }
   1832         }
   1833 
   1834         /* store activated tag information */
   1835         nfa_dm_cb.activated_tech_mode = p_tech_params->mode;
   1836         nfa_dm_cb.activated_nfcid_len = nfcid_len;
   1837         if (nfcid_len)
   1838             memcpy (nfa_dm_cb.activated_nfcid, p_nfcid, nfcid_len);
   1839 
   1840         nfa_dm_cb.flags |= NFA_DM_FLAGS_SEND_DEACTIVATED_EVT;
   1841         nfa_dm_conn_cback_event_notify (NFA_ACTIVATED_EVT, &evt_data);
   1842     }
   1843     else
   1844     {
   1845         /* if NFC_DEP, NFA P2P will deactivate */
   1846         if (nfa_dm_cb.disc_cb.activated_protocol != NFC_PROTOCOL_NFC_DEP)
   1847         {
   1848             nfa_dm_rf_deactivate (NFA_DEACTIVATE_TYPE_DISCOVERY);
   1849         }
   1850     }
   1851 
   1852     GKI_freebuf (nfa_dm_cb.p_activate_ntf);
   1853     nfa_dm_cb.p_activate_ntf = NULL;
   1854 }
   1855 
   1856 #if (BT_TRACE_VERBOSE == TRUE)
   1857 /*******************************************************************************
   1858 **
   1859 ** Function         nfa_dm_nfc_revt_2_str
   1860 **
   1861 ** Description      convert nfc revt to string
   1862 **
   1863 *******************************************************************************/
   1864 char *nfa_dm_nfc_revt_2_str (tNFC_RESPONSE_EVT event)
   1865 {
   1866     switch (event) {
   1867     case NFC_ENABLE_REVT:
   1868         return "NFC_ENABLE_REVT";
   1869 
   1870     case NFC_DISABLE_REVT:
   1871         return "NFC_DISABLE_REVT";
   1872 
   1873     case NFC_SET_CONFIG_REVT:
   1874         return "NFC_SET_CONFIG_REVT";
   1875 
   1876     case NFC_GET_CONFIG_REVT:
   1877         return "NFC_GET_CONFIG_REVT";
   1878 
   1879     case NFC_NFCEE_DISCOVER_REVT:
   1880         return "NFC_NFCEE_DISCOVER_REVT";
   1881 
   1882     case NFC_NFCEE_INFO_REVT:
   1883         return "NFC_NFCEE_INFO_REVT";
   1884 
   1885     case NFC_NFCEE_MODE_SET_REVT:
   1886         return "NFC_NFCEE_MODE_SET_REVT";
   1887 
   1888     case NFC_RF_FIELD_REVT:
   1889         return "NFC_RF_FIELD_REVT";
   1890 
   1891     case NFC_EE_ACTION_REVT:
   1892         return "NFC_EE_ACTION_REVT";
   1893 
   1894     case NFC_EE_DISCOVER_REQ_REVT:
   1895         return "NFC_EE_DISCOVER_REQ_REVT";
   1896 
   1897     case NFC_SET_ROUTING_REVT:
   1898         return "NFC_SET_ROUTING_REVT";
   1899 
   1900     case NFC_GET_ROUTING_REVT:
   1901         return "NFC_GET_ROUTING_REVT";
   1902 
   1903     case NFC_GEN_ERROR_REVT:
   1904         return "NFC_GEN_ERROR_REVT";
   1905 
   1906     case NFC_NFCC_RESTART_REVT:
   1907         return "NFC_NFCC_RESTART_REVT";
   1908 
   1909     case NFC_NFCC_TIMEOUT_REVT:
   1910         return "NFC_NFCC_TIMEOUT_REVT";
   1911 
   1912     case NFC_NFCC_TRANSPORT_ERR_REVT:
   1913         return "NFC_NFCC_TRANSPORT_ERR_REVT";
   1914 
   1915     case NFC_NFCC_POWER_OFF_REVT:
   1916         return "NFC_NFCC_POWER_OFF_REVT";
   1917 
   1918     default:
   1919         return "unknown revt";
   1920         break;
   1921     }
   1922 }
   1923 #endif /* BT_VERBOSE */
   1924