nfa_dm_act.c revision 09de1b298ad4237ba50018d28086c0430da8c23e
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
56static void nfa_dm_set_init_nci_params (void);
57static tNFA_STATUS nfa_dm_start_polling (void);
58static BOOLEAN nfa_dm_deactivate_polling (void);
59static void nfa_dm_excl_disc_cback (tNFA_DM_RF_DISC_EVT event, tNFC_DISCOVER *p_data);
60static 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*******************************************************************************/
72static 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*******************************************************************************/
93static 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*******************************************************************************/
124void 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*******************************************************************************/
138static 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*******************************************************************************/
197void 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*******************************************************************************/
226static 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*******************************************************************************/
247static 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*******************************************************************************/
432BOOLEAN 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*******************************************************************************/
471BOOLEAN 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*******************************************************************************/
525void 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*******************************************************************************/
554BOOLEAN 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*******************************************************************************/
593BOOLEAN 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*******************************************************************************/
610void 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*******************************************************************************/
634void 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*******************************************************************************/
662BOOLEAN 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*******************************************************************************/
709BOOLEAN 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*******************************************************************************/
740BOOLEAN 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        if (  (nfa_dm_cb.disc_cb.activated_protocol == NFA_PROTOCOL_NFC_DEP)
754            &&((nfa_dm_cb.flags & NFA_DM_FLAGS_EXCL_RF_ACTIVE) == 0x00)  )
755        {
756            /* Exclusive RF control doesn't use NFA P2P */
757            /* NFA P2P will deactivate NFC link after deactivating LLCP link */
758            nfa_p2p_deactivate_llcp ();
759            return (TRUE);
760        }
761        else
762        {
763            deact_type  = NFA_DEACTIVATE_TYPE_DISCOVERY;
764            if (p_data->deactivate.sleep_mode)
765            {
766                if (nfa_dm_cb.disc_cb.disc_state == NFA_DM_RFST_W4_HOST_SELECT)
767                {
768                    /* Deactivate to sleep mode not allowed in this state. */
769                    deact_type = NFA_DEACTIVATE_TYPE_IDLE;
770                }
771                else if (nfa_dm_cb.disc_cb.disc_state != NFA_DM_RFST_LISTEN_SLEEP)
772                {
773                    deact_type = NFA_DEACTIVATE_TYPE_SLEEP;
774                }
775            }
776            if (nfa_dm_cb.disc_cb.disc_state == NFA_DM_RFST_W4_ALL_DISCOVERIES)
777            {
778                /* Only deactivate to IDLE is allowed in this state. */
779                deact_type = NFA_DEACTIVATE_TYPE_IDLE;
780            }
781            if (nfa_dm_rf_deactivate (deact_type) == NFA_STATUS_OK)
782            {
783                if (nfa_dm_cb.disc_cb.kovio_tle.in_use)
784                    nfa_sys_stop_timer (&nfa_dm_cb.disc_cb.kovio_tle);
785                nfa_rw_stop_presence_check_timer ();
786                return (TRUE);
787            }
788        }
789    }
790
791    NFA_TRACE_ERROR0 ("nfa_dm_act_deactivate (): invalid protocol, mode or state");
792
793    /* Notify error to application */
794    conn_evt.status = NFA_STATUS_FAILED;
795    nfa_dm_conn_cback_event_notify (NFA_DEACTIVATE_FAIL_EVT, &conn_evt);
796
797    return (TRUE);
798}
799
800/*******************************************************************************
801**
802** Function         nfa_dm_act_power_off_sleep
803**
804** Description      Process power off sleep mode request
805**
806** Returns          TRUE (message buffer to be freed by caller)
807**
808*******************************************************************************/
809BOOLEAN nfa_dm_act_power_off_sleep (tNFA_DM_MSG *p_data)
810{
811    NFA_TRACE_DEBUG0 ("nfa_dm_act_power_off_sleep ()");
812
813    NFC_SetPowerOffSleep ((BOOLEAN) (p_data->hdr.layer_specific));
814
815    return (TRUE);
816}
817
818/*******************************************************************************
819**
820** Function         nfa_dm_act_reg_vsc
821**
822** Description      Process registers VSC callback
823**
824** Returns          TRUE (message buffer to be freed by caller)
825**
826*******************************************************************************/
827BOOLEAN nfa_dm_act_reg_vsc(tNFA_DM_MSG *p_data)
828{
829    if (NFC_RegVSCback(p_data->reg_vsc.is_register, p_data->reg_vsc.p_cback) != NFC_STATUS_OK)
830    {
831        NFA_TRACE_ERROR0 ("NFC_RegVSCback failed");
832    }
833    return (TRUE);
834}
835
836/*******************************************************************************
837**
838** Function         nfa_dm_act_send_vsc
839**
840** Description      Send the NCI Vendor Specific command to the NCI command queue
841**
842** Returns          FALSE (message buffer is NOT freed by caller)
843**
844*******************************************************************************/
845BOOLEAN nfa_dm_act_send_vsc(tNFA_DM_MSG *p_data)
846{
847    BT_HDR  *p_cmd = (BT_HDR *)p_data;
848
849    p_cmd->offset   = sizeof (tNFA_DM_API_SEND_VSC) - BT_HDR_SIZE;
850    p_cmd->len      = p_data->send_vsc.cmd_params_len;
851    NFC_SendVsCommand (p_data->send_vsc.oid, p_cmd, p_data->send_vsc.p_cback);
852
853    /* Most dm action functions return TRUE, so nfa-sys frees the GKI buffer carrying the message,
854     * This action function re-use the GKI buffer to send the VSC, so the GKI buffer can not be freed by nfa-sys */
855    return (FALSE);
856}
857
858/*******************************************************************************
859**
860** Function         nfa_dm_start_polling
861**
862** Description      Start polling
863**
864** Returns          tNFA_STATUS
865**
866*******************************************************************************/
867tNFA_STATUS nfa_dm_start_polling (void)
868{
869    tNFA_STATUS             status;
870    tNFA_TECHNOLOGY_MASK    poll_tech_mask;
871    tNFA_DM_DISC_TECH_PROTO_MASK poll_disc_mask = 0;
872
873    NFA_TRACE_DEBUG0 ("nfa_dm_start_polling ()");
874
875    poll_tech_mask = nfa_dm_cb.poll_mask;
876
877    /* start RF discovery with discovery callback */
878    if (nfa_dm_cb.poll_disc_handle == NFA_HANDLE_INVALID)
879    {
880        if (poll_tech_mask & NFA_TECHNOLOGY_MASK_A)
881        {
882            poll_disc_mask |= NFA_DM_DISC_MASK_PA_T1T;
883            poll_disc_mask |= NFA_DM_DISC_MASK_PA_T2T;
884            poll_disc_mask |= NFA_DM_DISC_MASK_PA_ISO_DEP;
885            poll_disc_mask |= NFA_DM_DISC_MASK_PA_NFC_DEP;
886            poll_disc_mask |= NFA_DM_DISC_MASK_P_LEGACY;
887        }
888        if (poll_tech_mask & NFA_TECHNOLOGY_MASK_A_ACTIVE)
889        {
890            poll_disc_mask |= NFA_DM_DISC_MASK_PAA_NFC_DEP;
891        }
892        if (poll_tech_mask & NFA_TECHNOLOGY_MASK_B)
893        {
894            poll_disc_mask |= NFA_DM_DISC_MASK_PB_ISO_DEP;
895        }
896        if (poll_tech_mask & NFA_TECHNOLOGY_MASK_F)
897        {
898            poll_disc_mask |= NFA_DM_DISC_MASK_PF_T3T;
899            poll_disc_mask |= NFA_DM_DISC_MASK_PF_NFC_DEP;
900        }
901        if (poll_tech_mask & NFA_TECHNOLOGY_MASK_F_ACTIVE)
902        {
903            poll_disc_mask |= NFA_DM_DISC_MASK_PFA_NFC_DEP;
904        }
905        if (poll_tech_mask & NFA_TECHNOLOGY_MASK_ISO15693)
906        {
907            poll_disc_mask |= NFA_DM_DISC_MASK_P_ISO15693;
908        }
909        if (poll_tech_mask & NFA_TECHNOLOGY_MASK_B_PRIME)
910        {
911            poll_disc_mask |= NFA_DM_DISC_MASK_P_B_PRIME;
912        }
913        if (poll_tech_mask & NFA_TECHNOLOGY_MASK_KOVIO)
914        {
915            poll_disc_mask |= NFA_DM_DISC_MASK_P_KOVIO;
916        }
917
918        nfa_dm_cb.poll_disc_handle = nfa_dm_add_rf_discover (poll_disc_mask,
919                                                             NFA_DM_DISC_HOST_ID_DH,
920                                                             nfa_dm_poll_disc_cback);
921
922        if (nfa_dm_cb.poll_disc_handle != NFA_HANDLE_INVALID)
923            status = NFA_STATUS_OK;
924        else
925            status = NFA_STATUS_FAILED;
926    }
927    else
928    {
929        status = NFA_STATUS_OK;
930    }
931
932    return (status);
933}
934
935/*******************************************************************************
936**
937** Function         nfa_dm_act_enable_polling
938**
939** Description      Process enable polling command
940**
941** Returns          TRUE (message buffer to be freed by caller)
942**
943*******************************************************************************/
944BOOLEAN nfa_dm_act_enable_polling (tNFA_DM_MSG *p_data)
945{
946    tNFA_CONN_EVT_DATA evt_data;
947
948    NFA_TRACE_DEBUG0 ("nfa_dm_act_enable_polling ()");
949
950    if (  (!(nfa_dm_cb.flags & NFA_DM_FLAGS_POLLING_ENABLED))
951        &&(!(nfa_dm_cb.flags & NFA_DM_FLAGS_EXCL_RF_ACTIVE)  )  )
952    {
953        nfa_dm_cb.poll_mask = p_data->enable_poll.poll_mask;
954
955        if (nfa_dm_start_polling () == NFA_STATUS_OK)
956        {
957            nfa_dm_cb.flags |= NFA_DM_FLAGS_POLLING_ENABLED;
958
959            evt_data.status = NFA_STATUS_OK;
960            nfa_dm_conn_cback_event_notify (NFA_POLL_ENABLED_EVT, &evt_data);
961            return (TRUE);
962        }
963    }
964    else
965    {
966        NFA_TRACE_ERROR0 ("nfa_dm_act_enable_polling (): already started");
967    }
968
969    /* send NFA_POLL_ENABLED_EVT with NFA_STATUS_FAILED */
970    evt_data.status = NFA_STATUS_FAILED;
971    nfa_dm_conn_cback_event_notify (NFA_POLL_ENABLED_EVT, &evt_data);
972
973    return (TRUE);
974}
975
976/*******************************************************************************
977**
978** Function         nfa_dm_deactivate_polling
979**
980** Description      Deactivate any polling state
981**
982** Returns          TRUE if need to wait for deactivation
983**
984*******************************************************************************/
985static BOOLEAN nfa_dm_deactivate_polling (void)
986{
987    NFA_TRACE_DEBUG0 ("nfa_dm_deactivate_polling ()");
988
989    if (  (nfa_dm_cb.disc_cb.disc_state == NFA_DM_RFST_W4_ALL_DISCOVERIES)
990        ||(nfa_dm_cb.disc_cb.disc_state == NFA_DM_RFST_W4_HOST_SELECT)  )
991    {
992        nfa_dm_rf_deactivate (NFA_DEACTIVATE_TYPE_IDLE);
993        return FALSE;
994    }
995    else if (nfa_dm_cb.disc_cb.disc_state == NFA_DM_RFST_POLL_ACTIVE)
996    {
997        if (nfa_dm_cb.disc_cb.activated_protocol == NFC_PROTOCOL_NFC_DEP)
998        {
999            /* NFA P2P will deactivate NFC link after deactivating LLCP link */
1000            nfa_p2p_deactivate_llcp ();
1001        }
1002        else
1003        {
1004            nfa_dm_rf_deactivate (NFA_DEACTIVATE_TYPE_IDLE);
1005        }
1006        return TRUE;
1007    }
1008    else
1009    {
1010        return FALSE;
1011    }
1012}
1013
1014/*******************************************************************************
1015**
1016** Function         nfa_dm_act_disable_polling
1017**
1018** Description      Process disable polling command
1019**
1020** Returns          TRUE (message buffer to be freed by caller)
1021**
1022*******************************************************************************/
1023BOOLEAN nfa_dm_act_disable_polling (tNFA_DM_MSG *p_data)
1024{
1025    tNFA_CONN_EVT_DATA evt_data;
1026
1027    NFA_TRACE_DEBUG0 ("nfa_dm_act_disable_polling ()");
1028
1029    if (nfa_dm_cb.poll_disc_handle != NFA_HANDLE_INVALID)
1030    {
1031        nfa_dm_cb.flags &= ~NFA_DM_FLAGS_POLLING_ENABLED;
1032
1033        if (nfa_dm_deactivate_polling () == FALSE)
1034        {
1035            nfa_dm_delete_rf_discover (nfa_dm_cb.poll_disc_handle);
1036            nfa_dm_cb.poll_disc_handle = NFA_HANDLE_INVALID;
1037
1038            evt_data.status = NFA_STATUS_OK;
1039            nfa_dm_conn_cback_event_notify (NFA_POLL_DISABLED_EVT, &evt_data);
1040        }
1041        else
1042        {
1043            nfa_dm_cb.flags |= NFA_DM_FLAGS_SEND_POLL_STOP_EVT;
1044        }
1045    }
1046    else
1047    {
1048        evt_data.status = NFA_STATUS_FAILED;
1049        nfa_dm_conn_cback_event_notify (NFA_POLL_DISABLED_EVT, &evt_data);
1050    }
1051
1052    return (TRUE);
1053}
1054
1055/*******************************************************************************
1056**
1057** Function         nfa_dm_act_send_raw_frame
1058**
1059** Description      Send an raw frame on RF link
1060**
1061** Returns          TRUE (message buffer to be freed by caller)
1062**
1063*******************************************************************************/
1064BOOLEAN nfa_dm_act_send_raw_frame (tNFA_DM_MSG *p_data)
1065{
1066    tNFC_STATUS status = NFC_STATUS_FAILED;
1067
1068    NFA_TRACE_DEBUG0 ("nfa_dm_act_send_raw_frame ()");
1069
1070    /* If NFC link is activated */
1071    if (  (nfa_dm_cb.disc_cb.disc_state == NFA_DM_RFST_POLL_ACTIVE)
1072        ||(nfa_dm_cb.disc_cb.disc_state == NFA_DM_RFST_LISTEN_ACTIVE)  )
1073    {
1074        /* If not in exclusive mode, and not activated for LISTEN, then forward raw data to NFA_RW to send */
1075        if (  !(nfa_dm_cb.flags & NFA_DM_FLAGS_EXCL_RF_ACTIVE)
1076            &&!(nfa_dm_cb.disc_cb.disc_state == NFA_DM_RFST_LISTEN_ACTIVE)
1077            &&(  (nfa_dm_cb.disc_cb.activated_protocol == NFA_PROTOCOL_T1T)
1078               ||(nfa_dm_cb.disc_cb.activated_protocol == NFA_PROTOCOL_T2T)
1079               ||(nfa_dm_cb.disc_cb.activated_protocol == NFA_PROTOCOL_T3T)
1080               ||(nfa_dm_cb.disc_cb.activated_protocol == NFA_PROTOCOL_ISO_DEP)
1081               ||(nfa_dm_cb.disc_cb.activated_protocol == NFA_PROTOCOL_ISO15693)  )  )
1082        {
1083            /* if RW is checking presence then it will put into pending queue */
1084            status = nfa_rw_send_raw_frame ((BT_HDR*)p_data);
1085        }
1086        else
1087        {
1088            status = NFC_SendData (NFC_RF_CONN_ID, (BT_HDR*) p_data);
1089            /* Already freed or NCI layer will free buffer */
1090            return FALSE;
1091        }
1092    }
1093
1094    if (status == NFC_STATUS_FAILED)
1095    {
1096        /* free the buffer */
1097        return TRUE;
1098    }
1099    else
1100    {
1101        /* NCI layer will free buffer */
1102        return FALSE;
1103    }
1104}
1105
1106/*******************************************************************************
1107**
1108** Function         nfa_dm_set_p2p_listen_tech
1109**
1110** Description      Notify change of P2P listen technologies to NFA P2P
1111**
1112** Returns          TRUE (message buffer to be freed by caller)
1113**
1114*******************************************************************************/
1115BOOLEAN nfa_dm_set_p2p_listen_tech (tNFA_DM_MSG *p_data)
1116{
1117    NFA_TRACE_DEBUG1 ("nfa_dm_set_p2p_listen_tech ()  tech_mask = %d",
1118                      p_data->set_p2p_listen_tech.tech_mask);
1119
1120    nfa_p2p_update_listen_tech (p_data->set_p2p_listen_tech.tech_mask);
1121    nfa_dm_conn_cback_event_notify (NFA_SET_P2P_LISTEN_TECH_EVT, NULL);
1122
1123    return (TRUE);
1124}
1125
1126/*******************************************************************************
1127**
1128** Function         nfa_dm_act_enable_listening
1129**
1130** Description      Enables listen mode discovery
1131**
1132** Returns          TRUE (message buffer to be freed by caller)
1133**
1134*******************************************************************************/
1135BOOLEAN nfa_dm_act_enable_listening (tNFA_DM_MSG *p_data)
1136{
1137    NFA_TRACE_DEBUG0 ("nfa_dm_act_enable_listening ()");
1138
1139    nfa_dm_cb.disc_cb.listen_disabled = FALSE;
1140
1141    return (TRUE);
1142}
1143
1144/*******************************************************************************
1145**
1146** Function         nfa_dm_act_disable_listening
1147**
1148** Description      Temporarily disables listen mode discovery
1149**
1150** Returns          TRUE (message buffer to be freed by caller)
1151**
1152*******************************************************************************/
1153BOOLEAN nfa_dm_act_disable_listening (tNFA_DM_MSG *p_data)
1154{
1155    NFA_TRACE_DEBUG0 ("nfa_dm_act_disable_listening ()");
1156
1157    nfa_dm_cb.disc_cb.listen_disabled = TRUE;
1158
1159    return (TRUE);
1160}
1161
1162/*******************************************************************************
1163**
1164** Function         nfa_dm_act_start_rf_discovery
1165**
1166** Description      Process start RF discovery command
1167**
1168** Returns          TRUE (message buffer to be freed by caller)
1169**
1170*******************************************************************************/
1171BOOLEAN nfa_dm_act_start_rf_discovery (tNFA_DM_MSG *p_data)
1172{
1173    tNFA_CONN_EVT_DATA evt_data;
1174
1175    NFA_TRACE_DEBUG0 ("nfa_dm_act_start_rf_discovery ()");
1176
1177    if (nfa_dm_cb.disc_cb.disc_flags & NFA_DM_DISC_FLAGS_ENABLED)
1178    {
1179        evt_data.status = NFA_STATUS_OK;
1180        nfa_dm_conn_cback_event_notify (NFA_RF_DISCOVERY_STARTED_EVT, &evt_data);
1181    }
1182    else if (nfa_dm_cb.disc_cb.disc_state != NFA_DM_RFST_IDLE)
1183    {
1184        evt_data.status = NFA_STATUS_SEMANTIC_ERROR;
1185        nfa_dm_conn_cback_event_notify (NFA_RF_DISCOVERY_STARTED_EVT, &evt_data);
1186    }
1187    else
1188    {
1189        nfa_dm_cb.disc_cb.disc_flags |= (NFA_DM_DISC_FLAGS_ENABLED|NFA_DM_DISC_FLAGS_NOTIFY);
1190        nfa_dm_start_rf_discover ();
1191    }
1192
1193    return (TRUE);
1194}
1195
1196/*******************************************************************************
1197**
1198** Function         nfa_dm_act_stop_rf_discovery
1199**
1200** Description      Process stop RF discovery command
1201**
1202** Returns          TRUE (message buffer to be freed by caller)
1203**
1204*******************************************************************************/
1205BOOLEAN nfa_dm_act_stop_rf_discovery (tNFA_DM_MSG *p_data)
1206{
1207    tNFA_CONN_EVT_DATA evt_data;
1208
1209    NFA_TRACE_DEBUG0 ("nfa_dm_act_stop_rf_discovery ()");
1210
1211    if (!(nfa_dm_cb.disc_cb.disc_flags & NFA_DM_DISC_FLAGS_ENABLED) ||
1212        (nfa_dm_cb.disc_cb.disc_state == NFA_DM_RFST_IDLE) )
1213    {
1214        nfa_dm_cb.disc_cb.disc_flags &= ~NFA_DM_DISC_FLAGS_ENABLED;
1215
1216        /* if discover command has been sent in IDLE state and waiting for response */
1217        if (nfa_dm_cb.disc_cb.disc_flags & NFA_DM_DISC_FLAGS_W4_RSP)
1218        {
1219            nfa_dm_cb.disc_cb.disc_flags |= NFA_DM_DISC_FLAGS_STOPPING;
1220        }
1221        else
1222        {
1223            evt_data.status = NFA_STATUS_OK;
1224            nfa_dm_conn_cback_event_notify (NFA_RF_DISCOVERY_STOPPED_EVT, &evt_data);
1225        }
1226    }
1227    else
1228    {
1229        nfa_dm_cb.disc_cb.disc_flags &= ~NFA_DM_DISC_FLAGS_ENABLED;
1230        nfa_dm_cb.disc_cb.disc_flags |= NFA_DM_DISC_FLAGS_STOPPING;
1231
1232        if (nfa_dm_rf_deactivate (NFA_DEACTIVATE_TYPE_IDLE) == NFA_STATUS_OK)
1233        {
1234            if (nfa_dm_cb.disc_cb.kovio_tle.in_use)
1235                nfa_sys_stop_timer (&nfa_dm_cb.disc_cb.kovio_tle);
1236            nfa_rw_stop_presence_check_timer ();
1237        }
1238    }
1239    return (TRUE);
1240}
1241
1242/*******************************************************************************
1243**
1244** Function         nfa_dm_act_set_rf_disc_duration
1245**
1246** Description      Set duration for RF discovery
1247**
1248** Returns          TRUE (message buffer to be freed by caller)
1249**
1250*******************************************************************************/
1251BOOLEAN nfa_dm_act_set_rf_disc_duration (tNFA_DM_MSG *p_data)
1252{
1253    nfa_dm_cb.disc_cb.disc_duration = p_data->disc_duration.rf_disc_dur_ms;
1254    return (TRUE);
1255}
1256
1257/*******************************************************************************
1258**
1259** Function         nfa_dm_act_select
1260**
1261** Description      Process RF select command
1262**
1263** Returns          TRUE (message buffer to be freed by caller)
1264**
1265*******************************************************************************/
1266BOOLEAN nfa_dm_act_select (tNFA_DM_MSG *p_data)
1267{
1268    NFA_TRACE_DEBUG0 ("nfa_dm_act_select ()");
1269
1270    nfa_dm_rf_discover_select (p_data->select.rf_disc_id,
1271                               p_data->select.protocol,
1272                               p_data->select.rf_interface);
1273    return (TRUE);
1274}
1275
1276/*******************************************************************************
1277**
1278** Function         nfa_dm_act_update_rf_params
1279**
1280** Description      Process update RF communication parameters command
1281**
1282** Returns          TRUE (message buffer to be freed by caller)
1283**
1284*******************************************************************************/
1285BOOLEAN nfa_dm_act_update_rf_params (tNFA_DM_MSG *p_data)
1286{
1287    tNFA_CONN_EVT_DATA conn_evt;
1288
1289    NFA_TRACE_DEBUG0 ("nfa_dm_act_update_rf_params ()");
1290
1291    if (NFC_UpdateRFCommParams (&p_data->update_rf_params.params) != NFC_STATUS_OK)
1292    {
1293        conn_evt.status = NFA_STATUS_FAILED;
1294        nfa_dm_conn_cback_event_notify (NFA_UPDATE_RF_PARAM_RESULT_EVT, &conn_evt);
1295    }
1296
1297    return (TRUE);
1298}
1299
1300/*******************************************************************************
1301**
1302** Function         nfa_dm_act_disable_timeout
1303**
1304** Description      timeout on disable process. Shutdown immediately
1305**
1306** Returns          TRUE (message buffer to be freed by caller)
1307**
1308*******************************************************************************/
1309BOOLEAN nfa_dm_act_disable_timeout (tNFA_DM_MSG *p_data)
1310{
1311    tNFA_DM_API_DISABLE disable;
1312
1313    disable.graceful = FALSE;
1314    nfa_dm_disable ((tNFA_DM_MSG *) &disable);
1315    return (TRUE);
1316}
1317
1318/*******************************************************************************
1319**
1320** Function         nfa_dm_act_conn_cback_notify
1321**
1322** Description      Notify app of reader/writer/ndef events
1323**
1324** Returns          nothing
1325**
1326*******************************************************************************/
1327void nfa_dm_act_conn_cback_notify (UINT8 event, tNFA_CONN_EVT_DATA *p_data)
1328{
1329    NFA_TRACE_DEBUG1 ("nfa_dm_act_conn_cback_notify (): event:0x%X", event);
1330
1331    /* Notify event using appropriate CONN_CBACK */
1332    nfa_dm_conn_cback_event_notify (event, p_data);
1333
1334    /* If not in exclusive RF mode, then read NDEF message from tag (if automatic reading is enabled) */
1335    if (!(nfa_dm_cb.flags & NFA_DM_FLAGS_EXCL_RF_ACTIVE))
1336    {
1337        if (  (event == NFA_NDEF_DETECT_EVT)
1338            &&(nfa_dm_cb.flags & NFA_DM_FLAGS_AUTO_READING_NDEF)  )
1339        {
1340            /* read NDEF message from tag */
1341            if (p_data->ndef_detect.status == NFA_STATUS_OK)
1342            {
1343                NFA_RwReadNDef ();
1344            }
1345            else if (p_data->ndef_detect.status == NFA_STATUS_FAILED)
1346            {
1347                nfa_dm_cb.flags &= ~NFA_DM_FLAGS_AUTO_READING_NDEF;
1348            }
1349            /* ignore NFA_STATUS_BUSY */
1350        }
1351        else if (  (event == NFA_READ_CPLT_EVT)
1352                 &&(nfa_dm_cb.flags & NFA_DM_FLAGS_AUTO_READING_NDEF))
1353        {
1354            /* reading NDEF message is done */
1355            nfa_dm_cb.flags &= ~NFA_DM_FLAGS_AUTO_READING_NDEF;
1356        }
1357    }
1358}
1359
1360/*******************************************************************************
1361**
1362** Function         nfa_dm_act_data_cback
1363**
1364** Description      Processing data from RF link
1365**
1366** Returns          None
1367**
1368*******************************************************************************/
1369static void nfa_dm_act_data_cback (UINT8 conn_id, tNFC_CONN_EVT event, tNFC_CONN *p_data)
1370{
1371    BT_HDR             *p_msg;
1372    tNFA_CONN_EVT_DATA evt_data;
1373
1374    NFA_TRACE_DEBUG1 ("nfa_dm_act_data_cback (): event = 0x%X", event);
1375
1376    if (event == NFC_DATA_CEVT)
1377    {
1378        p_msg = (BT_HDR *) p_data->data.p_data;
1379
1380        if (p_msg)
1381        {
1382            evt_data.data.p_data = (UINT8 *) (p_msg + 1) + p_msg->offset;
1383            evt_data.data.len    = p_msg->len;
1384
1385            nfa_dm_conn_cback_event_notify (NFA_DATA_EVT, &evt_data);
1386
1387            GKI_freebuf (p_msg);
1388        }
1389        else
1390        {
1391            NFA_TRACE_ERROR0 ("nfa_dm_act_data_cback (): received NFC_DATA_CEVT with NULL data pointer");
1392        }
1393    }
1394    else if (event == NFC_DEACTIVATE_CEVT)
1395    {
1396        NFC_SetStaticRfCback (NULL);
1397    }
1398}
1399
1400/*******************************************************************************
1401**
1402** Function         nfa_dm_excl_disc_cback
1403**
1404** Description      Processing event from discovery callback
1405**
1406** Returns          None
1407**
1408*******************************************************************************/
1409static void nfa_dm_excl_disc_cback (tNFA_DM_RF_DISC_EVT event, tNFC_DISCOVER *p_data)
1410{
1411    tNFA_CONN_EVT_DATA evt_data;
1412
1413    NFA_TRACE_DEBUG1 ("nfa_dm_excl_disc_cback (): event:0x%02X", event);
1414
1415    switch (event)
1416    {
1417    case NFA_DM_RF_DISC_START_EVT:
1418        evt_data.status = NFA_STATUS_OK;
1419        nfa_dm_conn_cback_event_notify (NFA_EXCLUSIVE_RF_CONTROL_STARTED_EVT, &evt_data);
1420        break;
1421
1422    case NFA_DM_RF_DISC_ACTIVATED_EVT:
1423        if (nfa_dm_cb.disc_cb.activated_tech_mode == NFC_DISCOVERY_TYPE_POLL_A)
1424        {
1425            /* store SEL_RES response */
1426            nfa_dm_cb.disc_cb.activated_sel_res = p_data->activate.rf_tech_param.param.pa.sel_rsp;
1427        }
1428
1429        if (nfa_dm_cb.disc_cb.disc_state == NFA_DM_RFST_LISTEN_ACTIVE)
1430        {
1431            /* Set data callback to receive raw frame */
1432            NFC_SetStaticRfCback (nfa_dm_act_data_cback);
1433
1434            memset (&(evt_data.activated.params), 0x00, sizeof (tNFA_TAG_PARAMS));
1435            memcpy (&(evt_data.activated.activate_ntf), &(p_data->activate), sizeof (tNFC_ACTIVATE_DEVT));
1436
1437            nfa_dm_conn_cback_event_notify (NFA_ACTIVATED_EVT, &evt_data);
1438        }
1439        else
1440        {
1441            /* holding activation notification until sub-module is ready */
1442            nfa_dm_cb.p_activate_ntf = (UINT8*) GKI_getbuf (sizeof (tNFC_ACTIVATE_DEVT));
1443
1444            if (nfa_dm_cb.p_activate_ntf)
1445            {
1446                memcpy (nfa_dm_cb.p_activate_ntf,
1447                        &(p_data->activate),
1448                        sizeof (tNFC_ACTIVATE_DEVT));
1449
1450                if (  (nfa_dm_cb.disc_cb.activated_protocol  == NFC_PROTOCOL_T1T)
1451                    ||(nfa_dm_cb.disc_cb.activated_protocol  == NFC_PROTOCOL_T2T)
1452                    ||(nfa_dm_cb.disc_cb.activated_protocol  == NFC_PROTOCOL_T3T)
1453                    ||(nfa_dm_cb.disc_cb.activated_protocol  == NFC_PROTOCOL_ISO_DEP)
1454                    ||(nfa_dm_cb.disc_cb.activated_protocol  == NFA_PROTOCOL_ISO15693)
1455                    ||(nfa_dm_cb.disc_cb.activated_protocol  == NFC_PROTOCOL_KOVIO)  )
1456                {
1457                    /* Notify NFA tag sub-system */
1458                    nfa_rw_proc_disc_evt (NFA_DM_RF_DISC_ACTIVATED_EVT, p_data, FALSE);
1459                }
1460                else /* if NFC-DEP, ISO-DEP with frame interface or others */
1461                {
1462                    /* Set data callback to receive raw frame */
1463                    NFC_SetStaticRfCback (nfa_dm_act_data_cback);
1464                    nfa_dm_notify_activation_status (NFA_STATUS_OK, NULL);
1465                }
1466            }
1467            else
1468            {
1469                /* deactivate and restart RF discovery */
1470                nfa_dm_rf_deactivate (NFA_DEACTIVATE_TYPE_DISCOVERY);
1471            }
1472        }
1473        break;
1474
1475    case NFA_DM_RF_DISC_DEACTIVATED_EVT:
1476
1477        /* if deactivated to idle or discovery */
1478        if (  (p_data->deactivate.type == NFC_DEACTIVATE_TYPE_IDLE)
1479            ||(p_data->deactivate.type == NFC_DEACTIVATE_TYPE_DISCOVERY)  )
1480        {
1481            /* clear stored NFCID/UID/KOVIO bar code */
1482            nfa_dm_cb.activated_nfcid_len = 0;
1483        }
1484
1485        if (nfa_dm_cb.disc_cb.activated_protocol != NFC_PROTOCOL_NFC_DEP)
1486        {
1487            /* Notify NFA RW sub-systems */
1488            nfa_rw_proc_disc_evt (NFA_DM_RF_DISC_DEACTIVATED_EVT, NULL, FALSE);
1489        }
1490
1491        /* if deactivated as sleep mode */
1492        if (  (p_data->deactivate.type == NFC_DEACTIVATE_TYPE_SLEEP)
1493            ||(p_data->deactivate.type == NFC_DEACTIVATE_TYPE_SLEEP_AF)  )
1494        {
1495            evt_data.deactivated.type = NFA_DEACTIVATE_TYPE_SLEEP;
1496        }
1497        else
1498        {
1499            evt_data.deactivated.type = NFA_DEACTIVATE_TYPE_IDLE;
1500        }
1501
1502        /* notify deactivation to upper layer */
1503        nfa_dm_conn_cback_event_notify (NFA_DEACTIVATED_EVT, &evt_data);
1504
1505        /* clean up SEL_RES response */
1506        nfa_dm_cb.disc_cb.activated_sel_res = 0;
1507        break;
1508
1509    default:
1510        NFA_TRACE_ERROR0 ("Unexpected event");
1511        break;
1512    }
1513}
1514
1515/*******************************************************************************
1516**
1517** Function         nfa_dm_poll_disc_cback
1518**
1519** Description      Processing event from discovery callback
1520**
1521** Returns          None
1522**
1523*******************************************************************************/
1524static void nfa_dm_poll_disc_cback (tNFA_DM_RF_DISC_EVT event, tNFC_DISCOVER *p_data)
1525{
1526    tNFA_CONN_EVT_DATA evt_data;
1527
1528    NFA_TRACE_DEBUG1 ("nfa_dm_poll_disc_cback (): event:0x%02X", event);
1529
1530    switch (event)
1531    {
1532    case NFA_DM_RF_DISC_START_EVT:
1533        break;
1534
1535    case NFA_DM_RF_DISC_ACTIVATED_EVT:
1536
1537        if (nfa_dm_cb.disc_cb.activated_tech_mode == NFC_DISCOVERY_TYPE_POLL_A)
1538        {
1539            /* store SEL_RES response */
1540            nfa_dm_cb.disc_cb.activated_sel_res = p_data->activate.rf_tech_param.param.pa.sel_rsp;
1541        }
1542
1543        /* holding activation notification until sub-module is ready */
1544        nfa_dm_cb.p_activate_ntf = (UINT8*) GKI_getbuf (sizeof (tNFC_ACTIVATE_DEVT));
1545
1546        if (nfa_dm_cb.p_activate_ntf)
1547        {
1548            memcpy (nfa_dm_cb.p_activate_ntf,
1549                    &(p_data->activate),
1550                    sizeof (tNFC_ACTIVATE_DEVT));
1551
1552            if (  (nfa_dm_cb.disc_cb.activated_protocol     == NFC_PROTOCOL_NFC_DEP)
1553                &&(nfa_dm_cb.disc_cb.activated_rf_interface == NFC_INTERFACE_NFC_DEP)  )
1554            {
1555                /* activate LLCP */
1556                nfa_p2p_activate_llcp (p_data);
1557            }
1558            else if (  (nfa_dm_cb.disc_cb.activated_protocol  == NFC_PROTOCOL_T1T)
1559                     ||(nfa_dm_cb.disc_cb.activated_protocol  == NFC_PROTOCOL_T2T)
1560                     ||(nfa_dm_cb.disc_cb.activated_protocol  == NFC_PROTOCOL_T3T)
1561                     ||(nfa_dm_cb.disc_cb.activated_protocol  == NFC_PROTOCOL_ISO_DEP)
1562                     ||(nfa_dm_cb.disc_cb.activated_protocol  == NFC_PROTOCOL_15693)
1563                     ||(nfa_dm_cb.disc_cb.activated_protocol  == NFC_PROTOCOL_KOVIO)  )
1564            {
1565                /* Notify NFA tag sub-system */
1566                nfa_rw_proc_disc_evt (NFA_DM_RF_DISC_ACTIVATED_EVT, p_data, TRUE);
1567            }
1568            else /* if NFC-DEP/ISO-DEP with frame interface */
1569            {
1570                /* Set data callback to receive raw frame */
1571                NFC_SetStaticRfCback (nfa_dm_act_data_cback);
1572                nfa_dm_notify_activation_status (NFA_STATUS_OK, NULL);
1573            }
1574        }
1575        else
1576        {
1577            /* deactivate and restart RF discovery */
1578            nfa_dm_rf_deactivate (NFA_DEACTIVATE_TYPE_DISCOVERY);
1579        }
1580        break;
1581
1582    case NFA_DM_RF_DISC_DEACTIVATED_EVT:
1583
1584        /* if deactivated to idle or discovery */
1585        if (  (p_data->deactivate.type == NFC_DEACTIVATE_TYPE_IDLE)
1586            ||(p_data->deactivate.type == NFC_DEACTIVATE_TYPE_DISCOVERY)  )
1587        {
1588            /* clear stored NFCID/UID/KOVIO bar code */
1589            nfa_dm_cb.activated_nfcid_len = 0;
1590        }
1591
1592        if (  (nfa_dm_cb.disc_cb.activated_protocol     == NFC_PROTOCOL_NFC_DEP)
1593            &&(nfa_dm_cb.disc_cb.activated_rf_interface == NFC_INTERFACE_NFC_DEP)  )
1594        {
1595            /*
1596            ** If LLCP link is not deactivated yet,
1597            ** LLCP will receive deactivation ntf through data callback.
1598            ** NFA P2P will receive callback event from LLCP.
1599            */
1600        }
1601        else
1602        {
1603            /* Notify NFA RW sub-systems */
1604            nfa_rw_proc_disc_evt (NFA_DM_RF_DISC_DEACTIVATED_EVT, NULL, TRUE);
1605        }
1606
1607        /* if NFA sent NFA_ACTIVATED_EVT earlier */
1608        if (nfa_dm_cb.flags & NFA_DM_FLAGS_SEND_DEACTIVATED_EVT)
1609        {
1610            nfa_dm_cb.flags &= ~NFA_DM_FLAGS_SEND_DEACTIVATED_EVT;
1611
1612            /* if deactivated as sleep mode */
1613            if (  (p_data->deactivate.type == NFC_DEACTIVATE_TYPE_SLEEP)
1614                ||(p_data->deactivate.type == NFC_DEACTIVATE_TYPE_SLEEP_AF)  )
1615            {
1616                evt_data.deactivated.type = NFA_DEACTIVATE_TYPE_SLEEP;
1617            }
1618            else
1619            {
1620                evt_data.deactivated.type = NFA_DEACTIVATE_TYPE_IDLE;
1621            }
1622            /* notify deactivation to application */
1623            nfa_dm_conn_cback_event_notify (NFA_DEACTIVATED_EVT, &evt_data);
1624        }
1625
1626        /* clean up SEL_RES response */
1627        nfa_dm_cb.disc_cb.activated_sel_res = 0;
1628
1629        if (!(nfa_dm_cb.flags & NFA_DM_FLAGS_POLLING_ENABLED))
1630        {
1631            /* deregister discovery callback from NFA DM Discovery */
1632            nfa_dm_delete_rf_discover (nfa_dm_cb.poll_disc_handle);
1633            nfa_dm_cb.poll_disc_handle = NFA_HANDLE_INVALID;
1634
1635            /* this is for disable polling */
1636            if (nfa_dm_cb.flags & NFA_DM_FLAGS_SEND_POLL_STOP_EVT)
1637            {
1638                nfa_dm_cb.flags &= ~NFA_DM_FLAGS_SEND_POLL_STOP_EVT;
1639
1640                evt_data.status = NFA_STATUS_OK;
1641                nfa_dm_conn_cback_event_notify (NFA_POLL_DISABLED_EVT, &evt_data);
1642            }
1643        }
1644        break;
1645    }
1646}
1647
1648/*******************************************************************************
1649**
1650** Function         nfa_dm_notify_activation_status
1651**
1652** Description      Processing activation status from sub-modules
1653**
1654** Returns          None
1655**
1656*******************************************************************************/
1657void nfa_dm_notify_activation_status (tNFA_STATUS status, tNFA_TAG_PARAMS *p_params)
1658{
1659    tNFA_CONN_EVT_DATA  evt_data;
1660    tNFC_RF_TECH_PARAMS *p_tech_params;
1661    UINT8               *p_nfcid = NULL, nfcid_len;
1662
1663    NFA_TRACE_DEBUG1 ("nfa_dm_notify_activation_status (): status:0x%X", status);
1664
1665    if (!nfa_dm_cb.p_activate_ntf)
1666    {
1667        /* this is for NFA P2P listen */
1668        return;
1669    }
1670
1671    if (status == NFA_STATUS_OK)
1672    {
1673        /* notify NFC link activation */
1674        memcpy ( &(evt_data.activated.activate_ntf),
1675                 nfa_dm_cb.p_activate_ntf,
1676                 sizeof (tNFC_ACTIVATE_DEVT));
1677
1678        p_tech_params = &evt_data.activated.activate_ntf.rf_tech_param;
1679
1680        memset (&(evt_data.activated.params), 0x00, sizeof (tNFA_TAG_PARAMS));
1681        if (p_params)
1682        {
1683            memcpy (&(evt_data.activated.params),
1684                    p_params,
1685                    sizeof (tNFA_TAG_PARAMS));
1686        }
1687
1688        /* get length of NFCID and location */
1689        if (p_tech_params->mode == NFC_DISCOVERY_TYPE_POLL_A)
1690        {
1691            nfcid_len = p_tech_params->param.pa.nfcid1_len;
1692            p_nfcid   = p_tech_params->param.pa.nfcid1;
1693        }
1694        else if (p_tech_params->mode == NFC_DISCOVERY_TYPE_POLL_B)
1695        {
1696            nfcid_len = NFC_NFCID0_MAX_LEN;
1697            p_nfcid   = p_tech_params->param.pb.nfcid0;
1698        }
1699        else if (p_tech_params->mode == NFC_DISCOVERY_TYPE_POLL_F)
1700        {
1701            nfcid_len = NFC_NFCID2_LEN;
1702            p_nfcid   = p_tech_params->param.pf.nfcid2;
1703        }
1704        else if (p_tech_params->mode == NFC_DISCOVERY_TYPE_POLL_ISO15693)
1705        {
1706            nfcid_len = NFC_ISO15693_UID_LEN;
1707            p_nfcid   = p_tech_params->param.pi93.uid;
1708        }
1709        else if (p_tech_params->mode == NFC_DISCOVERY_TYPE_POLL_KOVIO)
1710        {
1711            nfcid_len = p_tech_params->param.pk.uid_len;
1712            p_nfcid   = p_tech_params->param.pk.uid;
1713        }
1714        else
1715        {
1716            nfcid_len = 0;
1717        }
1718
1719        /*
1720        ** If not in exlusive RF mode, and
1721        **      P2P activation, then push default NDEF message through SNEP
1722        **      TAG activation, then read NDEF message
1723        */
1724        if (nfa_dm_cb.disc_cb.activated_protocol == NFC_PROTOCOL_NFC_DEP)
1725        {
1726            /*
1727            ** Default NDEF message will be put to NFC Forum defualt SNEP server
1728            ** after receiving NFA_LLCP_ACTIVATED_EVT.
1729            */
1730        }
1731        else if (!(nfa_dm_cb.flags & NFA_DM_FLAGS_EXCL_RF_ACTIVE))
1732        {
1733            /*
1734            ** if the same tag is activated then do not perform auto NDEF detection.
1735            ** Application may put a tag into sleep mode and reactivate the same tag.
1736            */
1737
1738            if (  (p_tech_params->mode != nfa_dm_cb.activated_tech_mode)
1739                ||(nfcid_len != nfa_dm_cb.activated_nfcid_len)
1740                ||(memcmp (p_nfcid, nfa_dm_cb.activated_nfcid, nfcid_len)))
1741            {
1742                if (  (nfa_dm_cb.disc_cb.activated_protocol  == NFC_PROTOCOL_T1T)
1743                    ||(nfa_dm_cb.disc_cb.activated_protocol  == NFC_PROTOCOL_T2T)
1744                    ||(nfa_dm_cb.disc_cb.activated_protocol  == NFC_PROTOCOL_T3T)
1745                    ||(  (nfa_dm_cb.disc_cb.activated_protocol == NFC_PROTOCOL_ISO_DEP)
1746                       &&(nfa_dm_cb.disc_cb.activated_rf_interface == NFC_INTERFACE_ISO_DEP)  )
1747                    ||(nfa_dm_cb.disc_cb.activated_protocol  == NFA_PROTOCOL_ISO15693)  )
1748                {
1749                    if (p_nfa_dm_cfg->auto_detect_ndef)
1750                    {
1751                        if (p_nfa_dm_cfg->auto_read_ndef)
1752                        {
1753                            nfa_dm_cb.flags |= NFA_DM_FLAGS_AUTO_READING_NDEF;
1754                        }
1755                        NFA_RwDetectNDef ();
1756                    }
1757                    else if (p_nfa_dm_cfg->auto_read_ndef)
1758                    {
1759                        NFA_RwReadNDef ();
1760                    }
1761                }
1762            }
1763        }
1764
1765        /* store activated tag information */
1766        nfa_dm_cb.activated_tech_mode = p_tech_params->mode;
1767        nfa_dm_cb.activated_nfcid_len = nfcid_len;
1768        if (nfcid_len)
1769            memcpy (nfa_dm_cb.activated_nfcid, p_nfcid, nfcid_len);
1770
1771        nfa_dm_cb.flags |= NFA_DM_FLAGS_SEND_DEACTIVATED_EVT;
1772        nfa_dm_conn_cback_event_notify (NFA_ACTIVATED_EVT, &evt_data);
1773    }
1774    else
1775    {
1776        /* if NFC_DEP, NFA P2P will deactivate */
1777        if (nfa_dm_cb.disc_cb.activated_protocol != NFC_PROTOCOL_NFC_DEP)
1778        {
1779            nfa_dm_rf_deactivate (NFA_DEACTIVATE_TYPE_DISCOVERY);
1780        }
1781    }
1782
1783    GKI_freebuf (nfa_dm_cb.p_activate_ntf);
1784    nfa_dm_cb.p_activate_ntf = NULL;
1785}
1786
1787#if (BT_TRACE_VERBOSE == TRUE)
1788/*******************************************************************************
1789**
1790** Function         nfa_dm_nfc_revt_2_str
1791**
1792** Description      convert nfc revt to string
1793**
1794*******************************************************************************/
1795char *nfa_dm_nfc_revt_2_str (tNFC_RESPONSE_EVT event)
1796{
1797    switch (event) {
1798    case NFC_ENABLE_REVT:
1799        return "NFC_ENABLE_REVT";
1800
1801    case NFC_DISABLE_REVT:
1802        return "NFC_DISABLE_REVT";
1803
1804    case NFC_SET_CONFIG_REVT:
1805        return "NFC_SET_CONFIG_REVT";
1806
1807    case NFC_GET_CONFIG_REVT:
1808        return "NFC_GET_CONFIG_REVT";
1809
1810    case NFC_NFCEE_DISCOVER_REVT:
1811        return "NFC_NFCEE_DISCOVER_REVT";
1812
1813    case NFC_NFCEE_INFO_REVT:
1814        return "NFC_NFCEE_INFO_REVT";
1815
1816    case NFC_NFCEE_MODE_SET_REVT:
1817        return "NFC_NFCEE_MODE_SET_REVT";
1818
1819    case NFC_RF_FIELD_REVT:
1820        return "NFC_RF_FIELD_REVT";
1821
1822    case NFC_EE_ACTION_REVT:
1823        return "NFC_EE_ACTION_REVT";
1824
1825    case NFC_EE_DISCOVER_REQ_REVT:
1826        return "NFC_EE_DISCOVER_REQ_REVT";
1827
1828    case NFC_SET_ROUTING_REVT:
1829        return "NFC_SET_ROUTING_REVT";
1830
1831    case NFC_GET_ROUTING_REVT:
1832        return "NFC_GET_ROUTING_REVT";
1833
1834    case NFC_GEN_ERROR_REVT:
1835        return "NFC_GEN_ERROR_REVT";
1836
1837    case NFC_NFCC_RESTART_REVT:
1838        return "NFC_NFCC_RESTART_REVT";
1839
1840    case NFC_NFCC_TIMEOUT_REVT:
1841        return "NFC_NFCC_TIMEOUT_REVT";
1842
1843    case NFC_NFCC_TRANSPORT_ERR_REVT:
1844        return "NFC_NFCC_TRANSPORT_ERR_REVT";
1845
1846    case NFC_NFCC_POWER_OFF_REVT:
1847        return "NFC_NFCC_POWER_OFF_REVT";
1848
1849    default:
1850        return "unknown revt";
1851        break;
1852    }
1853}
1854#endif /* BT_VERBOSE */
1855