Home | History | Annotate | Download | only in dm
      1 /******************************************************************************
      2  *
      3  *  Copyright (C) 2010-2014 Broadcom Corporation
      4  *
      5  *  Licensed under the Apache License, Version 2.0 (the "License");
      6  *  you may not use this file except in compliance with the License.
      7  *  You may obtain a copy of the License at:
      8  *
      9  *  http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  *  Unless required by applicable law or agreed to in writing, software
     12  *  distributed under the License is distributed on an "AS IS" BASIS,
     13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  *  See the License for the specific language governing permissions and
     15  *  limitations under the License.
     16  *
     17  ******************************************************************************/
     18 
     19 /******************************************************************************
     20  *
     21  *  NFA interface for device management
     22  *
     23  ******************************************************************************/
     24 #include <string.h>
     25 #include "ndef_utils.h"
     26 #include "nfa_api.h"
     27 #include "nfa_ce_int.h"
     28 #include "nfa_dm_int.h"
     29 #include "nfa_sys.h"
     30 #include "nfa_sys_int.h"
     31 
     32 /*****************************************************************************
     33 **  Constants
     34 *****************************************************************************/
     35 
     36 /*****************************************************************************
     37 **  APIs
     38 *****************************************************************************/
     39 /*******************************************************************************
     40 **
     41 ** Function         NFA_Init
     42 **
     43 ** Description      This function initializes control blocks for NFA
     44 **
     45 **                  p_hal_entry_tbl points to a table of HAL entry points
     46 **
     47 **                  NOTE: the buffer that p_hal_entry_tbl points must be
     48 **                  persistent until NFA is disabled.
     49 **
     50 ** Returns          none
     51 **
     52 *******************************************************************************/
     53 void NFA_Init(tHAL_NFC_ENTRY* p_hal_entry_tbl) {
     54   NFA_TRACE_API0("NFA_Init ()");
     55   nfa_sys_init();
     56   nfa_dm_init();
     57   nfa_p2p_init();
     58   nfa_snep_init(false);
     59   nfa_rw_init();
     60   nfa_ce_init();
     61   nfa_ee_init();
     62   if (nfa_ee_max_ee_cfg != 0) {
     63     nfa_dm_cb.get_max_ee = p_hal_entry_tbl->get_max_ee;
     64     nfa_hci_init();
     65   }
     66 
     67   /* Initialize NFC module */
     68   NFC_Init(p_hal_entry_tbl);
     69 }
     70 
     71 /*******************************************************************************
     72 **
     73 ** Function         NFA_Enable
     74 **
     75 ** Description      This function enables NFC. Prior to calling NFA_Enable,
     76 **                  the NFCC must be powered up, and ready to receive commands.
     77 **                  This function enables the tasks needed by NFC, opens the NCI
     78 **                  transport, resets the NFC controller, downloads patches to
     79 **                  the NFCC (if necessary), and initializes the NFC subsystems.
     80 **
     81 **                  This function should only be called once - typically when
     82 **                  NFC is enabled during boot-up, or when NFC is enabled from a
     83 **                  settings UI. Subsequent calls to NFA_Enable while NFA is
     84 **                  enabling or enabled will be ignored. When the NFC startup
     85 **                  procedure is completed, an NFA_DM_ENABLE_EVT is returned to
     86 **                  the application using the tNFA_DM_CBACK.
     87 **
     88 ** Returns          NFA_STATUS_OK if successfully initiated
     89 **                  NFA_STATUS_FAILED otherwise
     90 **
     91 *******************************************************************************/
     92 tNFA_STATUS NFA_Enable(tNFA_DM_CBACK* p_dm_cback,
     93                        tNFA_CONN_CBACK* p_conn_cback) {
     94   tNFA_DM_API_ENABLE* p_msg;
     95 
     96   NFA_TRACE_API0("NFA_Enable ()");
     97 
     98   /* Validate parameters */
     99   if ((!p_dm_cback) || (!p_conn_cback)) {
    100     NFA_TRACE_ERROR0("NFA_Enable (): error null callback");
    101     return (NFA_STATUS_FAILED);
    102   }
    103 
    104   p_msg = (tNFA_DM_API_ENABLE*)GKI_getbuf(sizeof(tNFA_DM_API_ENABLE));
    105   if (p_msg != NULL) {
    106     p_msg->hdr.event = NFA_DM_API_ENABLE_EVT;
    107     p_msg->p_dm_cback = p_dm_cback;
    108     p_msg->p_conn_cback = p_conn_cback;
    109 
    110     nfa_sys_sendmsg(p_msg);
    111 
    112     return (NFA_STATUS_OK);
    113   }
    114 
    115   return (NFA_STATUS_FAILED);
    116 }
    117 
    118 /*******************************************************************************
    119 **
    120 ** Function         NFA_Disable
    121 **
    122 ** Description      This function is called to shutdown NFC. The tasks for NFC
    123 **                  are terminated, and clean up routines are performed. This
    124 **                  function is typically called during platform shut-down, or
    125 **                  when NFC is disabled from a settings UI. When the NFC
    126 **                  shutdown procedure is completed, an NFA_DM_DISABLE_EVT is
    127 **                  returned to the application using the tNFA_DM_CBACK.
    128 **
    129 **                  The platform should wait until the NFC_DISABLE_REVT is
    130 **                  received before powering down the NFC chip and NCI
    131 **                  transport. This is required to so that NFA can gracefully
    132 **                  shut down any open connections.
    133 **
    134 ** Returns          NFA_STATUS_OK if successfully initiated
    135 **                  NFA_STATUS_FAILED otherwise
    136 **
    137 *******************************************************************************/
    138 tNFA_STATUS NFA_Disable(bool graceful) {
    139   tNFA_DM_API_DISABLE* p_msg;
    140 
    141   NFA_TRACE_API1("NFA_Disable (graceful=%i)", graceful);
    142 
    143   p_msg = (tNFA_DM_API_DISABLE*)GKI_getbuf(sizeof(tNFA_DM_API_DISABLE));
    144   if (p_msg != NULL) {
    145     p_msg->hdr.event = NFA_DM_API_DISABLE_EVT;
    146     p_msg->graceful = graceful;
    147 
    148     nfa_sys_sendmsg(p_msg);
    149 
    150     return (NFA_STATUS_OK);
    151   }
    152 
    153   return (NFA_STATUS_FAILED);
    154 }
    155 
    156 /*******************************************************************************
    157 **
    158 ** Function         NFA_SetConfig
    159 **
    160 ** Description      Set the configuration parameters to NFCC. The result is
    161 **                  reported with an NFA_DM_SET_CONFIG_EVT in the tNFA_DM_CBACK
    162 **                  callback.
    163 **
    164 ** Note:            If RF discovery is started,
    165 **                  NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should
    166 **                  happen before calling this function. Most Configuration
    167 **                  parameters are related to RF discovery.
    168 **
    169 ** Returns          NFA_STATUS_OK if successfully initiated
    170 **                  NFA_STATUS_BUSY if previous setting is on-going
    171 **                  NFA_STATUS_FAILED otherwise
    172 **
    173 *******************************************************************************/
    174 tNFA_STATUS NFA_SetConfig(tNFA_PMID param_id, uint8_t length, uint8_t* p_data) {
    175   tNFA_DM_API_SET_CONFIG* p_msg;
    176 
    177   NFA_TRACE_API1("NFA_SetConfig (): param_id:0x%X", param_id);
    178 
    179   p_msg = (tNFA_DM_API_SET_CONFIG*)GKI_getbuf(
    180       (uint16_t)(sizeof(tNFA_DM_API_SET_CONFIG) + length));
    181   if (p_msg != NULL) {
    182     p_msg->hdr.event = NFA_DM_API_SET_CONFIG_EVT;
    183 
    184     p_msg->param_id = param_id;
    185     p_msg->length = length;
    186     p_msg->p_data = (uint8_t*)(p_msg + 1);
    187 
    188     /* Copy parameter data */
    189     memcpy(p_msg->p_data, p_data, length);
    190 
    191     nfa_sys_sendmsg(p_msg);
    192 
    193     return (NFA_STATUS_OK);
    194   }
    195 
    196   return (NFA_STATUS_FAILED);
    197 }
    198 
    199 /*******************************************************************************
    200 **
    201 ** Function         NFA_GetConfig
    202 **
    203 ** Description      Get the configuration parameters from NFCC. The result is
    204 **                  reported with an NFA_DM_GET_CONFIG_EVT in the tNFA_DM_CBACK
    205 **                  callback.
    206 **
    207 ** Returns          NFA_STATUS_OK if successfully initiated
    208 **                  NFA_STATUS_FAILED otherwise
    209 **
    210 *******************************************************************************/
    211 tNFA_STATUS NFA_GetConfig(uint8_t num_ids, tNFA_PMID* p_param_ids) {
    212   tNFA_DM_API_GET_CONFIG* p_msg;
    213 
    214   NFA_TRACE_API1("NFA_GetConfig (): num_ids: %i", num_ids);
    215 
    216   p_msg = (tNFA_DM_API_GET_CONFIG*)GKI_getbuf(
    217       (uint16_t)(sizeof(tNFA_DM_API_GET_CONFIG) + num_ids));
    218   if (p_msg != NULL) {
    219     p_msg->hdr.event = NFA_DM_API_GET_CONFIG_EVT;
    220 
    221     p_msg->num_ids = num_ids;
    222     p_msg->p_pmids = (tNFA_PMID*)(p_msg + 1);
    223 
    224     /* Copy the param IDs */
    225     memcpy(p_msg->p_pmids, p_param_ids, num_ids);
    226 
    227     nfa_sys_sendmsg(p_msg);
    228 
    229     return (NFA_STATUS_OK);
    230   }
    231 
    232   return (NFA_STATUS_FAILED);
    233 }
    234 
    235 /*******************************************************************************
    236 **
    237 ** Function         NFA_RequestExclusiveRfControl
    238 **
    239 ** Description      Request exclusive control of NFC.
    240 **                  - Previous behavior (polling/tag reading, DH card emulation)
    241 **                    will be suspended .
    242 **                  - Polling and listening will be done based on the specified
    243 **                    params
    244 **
    245 **                  The NFA_EXCLUSIVE_RF_CONTROL_STARTED_EVT event of
    246 **                  tNFA_CONN_CBACK indicates the status of the operation.
    247 **
    248 **                  NFA_ACTIVATED_EVT and NFA_DEACTIVATED_EVT indicates link
    249 **                  activation/deactivation.
    250 **
    251 **                  NFA_SendRawFrame is used to send data to the peer.
    252 **                  NFA_DATA_EVT indicates data from the peer.
    253 **
    254 **                  If a tag is activated, then the NFA_RW APIs may be used to
    255 **                  send commands to the tag. Incoming NDEF messages are sent to
    256 **                  the NDEF callback.
    257 **
    258 **                  Once exclusive RF control has started, NFA will not activate
    259 **                  LLCP internally. The application has exclusive control of
    260 **                  the link.
    261 **
    262 ** Note:            If RF discovery is started,
    263 **                  NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should
    264 **                  happen before calling this function
    265 **
    266 ** Returns          NFA_STATUS_OK if successfully initiated
    267 **                  NFA_STATUS_FAILED otherwise
    268 **
    269 *******************************************************************************/
    270 tNFA_STATUS NFA_RequestExclusiveRfControl(tNFA_TECHNOLOGY_MASK poll_mask,
    271                                           tNFA_LISTEN_CFG* p_listen_cfg,
    272                                           tNFA_CONN_CBACK* p_conn_cback,
    273                                           tNFA_NDEF_CBACK* p_ndef_cback) {
    274   tNFA_DM_API_REQ_EXCL_RF_CTRL* p_msg;
    275 
    276   NFA_TRACE_API1("NFA_RequestExclusiveRfControl () poll_mask=0x%x", poll_mask);
    277 
    278   if (!p_conn_cback) {
    279     NFA_TRACE_ERROR0("NFA_RequestExclusiveRfControl (): error null callback");
    280     return (NFA_STATUS_FAILED);
    281   }
    282 
    283   p_msg = (tNFA_DM_API_REQ_EXCL_RF_CTRL*)GKI_getbuf(
    284       sizeof(tNFA_DM_API_REQ_EXCL_RF_CTRL));
    285   if (p_msg != NULL) {
    286     p_msg->hdr.event = NFA_DM_API_REQUEST_EXCL_RF_CTRL_EVT;
    287     p_msg->poll_mask = poll_mask;
    288     p_msg->p_conn_cback = p_conn_cback;
    289     p_msg->p_ndef_cback = p_ndef_cback;
    290 
    291     if (p_listen_cfg)
    292       memcpy(&p_msg->listen_cfg, p_listen_cfg, sizeof(tNFA_LISTEN_CFG));
    293     else
    294       memset(&p_msg->listen_cfg, 0x00, sizeof(tNFA_LISTEN_CFG));
    295 
    296     nfa_sys_sendmsg(p_msg);
    297 
    298     return (NFA_STATUS_OK);
    299   }
    300 
    301   return (NFA_STATUS_FAILED);
    302 }
    303 
    304 /*******************************************************************************
    305 **
    306 ** Function         NFA_ReleaseExclusiveRfControl
    307 **
    308 ** Description      Release exclusive control of NFC. Once released, behavior
    309 **                  prior to obtaining exclusive RF control will resume.
    310 **
    311 ** Returns          NFA_STATUS_OK if successfully initiated
    312 **                  NFA_STATUS_FAILED otherwise
    313 **
    314 *******************************************************************************/
    315 tNFA_STATUS NFA_ReleaseExclusiveRfControl(void) {
    316   NFC_HDR* p_msg;
    317 
    318   NFA_TRACE_API0("NFA_ReleaseExclusiveRfControl ()");
    319 
    320   if (!nfa_dm_cb.p_excl_conn_cback) {
    321     NFA_TRACE_ERROR0(
    322         "NFA_ReleaseExclusiveRfControl (): Exclusive rf control is not in "
    323         "progress");
    324     return (NFA_STATUS_FAILED);
    325   }
    326 
    327   p_msg = (NFC_HDR*)GKI_getbuf(sizeof(NFC_HDR));
    328   if (p_msg != NULL) {
    329     p_msg->event = NFA_DM_API_RELEASE_EXCL_RF_CTRL_EVT;
    330     nfa_sys_sendmsg(p_msg);
    331     return (NFA_STATUS_OK);
    332   }
    333 
    334   return (NFA_STATUS_FAILED);
    335 }
    336 
    337 /*******************************************************************************
    338 **
    339 ** Function         NFA_EnablePolling
    340 **
    341 ** Description      Enable polling for technologies specified by poll_mask.
    342 **
    343 **                  The following events (notified using the connection
    344 **                  callback registered with NFA_Enable) are generated during
    345 **                  polling:
    346 **
    347 **                  - NFA_POLL_ENABLED_EVT indicates whether or not polling
    348 **                    successfully enabled.
    349 **                  - NFA_DISC_RESULT_EVT indicates there are more than one
    350 **                    devices, so application must select one of tags by calling
    351 **                    NFA_Select().
    352 **                  - NFA_SELECT_RESULT_EVT indicates whether previous selection
    353 **                    was successful or not. If it was failed then application
    354 **                    must select again or deactivate by calling
    355 **                    NFA_Deactivate().
    356 **                  - NFA_ACTIVATED_EVT is generated when an NFC link is
    357 **                    activated.
    358 **                  - NFA_NDEF_DETECT_EVT is generated if tag is activated
    359 **                  - NFA_LLCP_ACTIVATED_EVT/NFA_LLCP_DEACTIVATED_EVT is
    360 **                    generated if NFC-DEP is activated
    361 **                  - NFA_DEACTIVATED_EVT will be returned after deactivating
    362 **                    NFC link.
    363 **
    364 ** Note:            If RF discovery is started,
    365 **                  NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should
    366 **                  happen before calling this function
    367 **
    368 ** Returns          NFA_STATUS_OK if successfully initiated
    369 **                  NFA_STATUS_FAILED otherwise
    370 **
    371 *******************************************************************************/
    372 tNFA_STATUS NFA_EnablePolling(tNFA_TECHNOLOGY_MASK poll_mask) {
    373   tNFA_DM_API_ENABLE_POLL* p_msg;
    374 
    375   NFA_TRACE_API1("NFA_EnablePolling () 0x%X", poll_mask);
    376 
    377   p_msg = (tNFA_DM_API_ENABLE_POLL*)GKI_getbuf(sizeof(tNFA_DM_API_ENABLE_POLL));
    378   if (p_msg != NULL) {
    379     p_msg->hdr.event = NFA_DM_API_ENABLE_POLLING_EVT;
    380     p_msg->poll_mask = poll_mask;
    381 
    382     nfa_sys_sendmsg(p_msg);
    383 
    384     return (NFA_STATUS_OK);
    385   }
    386 
    387   return (NFA_STATUS_FAILED);
    388 }
    389 
    390 /*******************************************************************************
    391 **
    392 ** Function         NFA_DisablePolling
    393 **
    394 ** Description      Disable polling
    395 **                  NFA_POLL_DISABLED_EVT will be returned after stopping
    396 **                  polling.
    397 **
    398 ** Note:            If RF discovery is started,
    399 **                  NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should
    400 **                  happen before calling this function
    401 **
    402 ** Returns          NFA_STATUS_OK if successfully initiated
    403 **                  NFA_STATUS_FAILED otherwise
    404 **
    405 *******************************************************************************/
    406 tNFA_STATUS NFA_DisablePolling(void) {
    407   NFC_HDR* p_msg;
    408 
    409   NFA_TRACE_API0("NFA_DisablePolling ()");
    410 
    411   p_msg = (NFC_HDR*)GKI_getbuf(sizeof(NFC_HDR));
    412   if (p_msg != NULL) {
    413     p_msg->event = NFA_DM_API_DISABLE_POLLING_EVT;
    414 
    415     nfa_sys_sendmsg(p_msg);
    416 
    417     return (NFA_STATUS_OK);
    418   }
    419 
    420   return (NFA_STATUS_FAILED);
    421 }
    422 
    423 /*******************************************************************************
    424 **
    425 ** Function         NFA_EnableListening
    426 **
    427 ** Description      Enable listening.
    428 **                  NFA_LISTEN_ENABLED_EVT will be returned after listening is
    429 **                  allowed.
    430 **
    431 **                  The actual listening technologies are specified by other NFA
    432 **                  API functions. Such functions include (but not limited to)
    433 **                  NFA_CeConfigureUiccListenTech.
    434 **                  If NFA_DisableListening () is called to ignore the listening
    435 **                  technologies, NFA_EnableListening () is called to restore
    436 **                  the listening technologies set by these functions.
    437 **
    438 ** Note:            If RF discovery is started,
    439 **                  NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should
    440 **                  happen before calling this function
    441 **
    442 ** Returns          NFA_STATUS_OK if successfully initiated
    443 **                  NFA_STATUS_FAILED otherwise
    444 **
    445 *******************************************************************************/
    446 tNFA_STATUS NFA_EnableListening(void) {
    447   NFC_HDR* p_msg;
    448 
    449   NFA_TRACE_API0("NFA_EnableListening ()");
    450 
    451   p_msg = (NFC_HDR*)GKI_getbuf(sizeof(NFC_HDR));
    452   if (p_msg != NULL) {
    453     p_msg->event = NFA_DM_API_ENABLE_LISTENING_EVT;
    454 
    455     nfa_sys_sendmsg(p_msg);
    456 
    457     return (NFA_STATUS_OK);
    458   }
    459 
    460   return (NFA_STATUS_FAILED);
    461 }
    462 
    463 /*******************************************************************************
    464 **
    465 ** Function         NFA_DisableListening
    466 **
    467 ** Description      Disable listening
    468 **                  NFA_LISTEN_DISABLED_EVT will be returned after stopping
    469 **                  listening. This function is called to exclude listen at RF
    470 **                  discovery.
    471 **
    472 ** Note:            If RF discovery is started,
    473 **                  NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should
    474 **                  happen before calling this function
    475 **
    476 ** Returns          NFA_STATUS_OK if successfully initiated
    477 **                  NFA_STATUS_FAILED otherwise
    478 **
    479 *******************************************************************************/
    480 tNFA_STATUS NFA_DisableListening(void) {
    481   NFC_HDR* p_msg;
    482 
    483   NFA_TRACE_API0("NFA_DisableListening ()");
    484 
    485   p_msg = (NFC_HDR*)GKI_getbuf(sizeof(NFC_HDR));
    486   if (p_msg != NULL) {
    487     p_msg->event = NFA_DM_API_DISABLE_LISTENING_EVT;
    488 
    489     nfa_sys_sendmsg(p_msg);
    490 
    491     return (NFA_STATUS_OK);
    492   }
    493 
    494   return (NFA_STATUS_FAILED);
    495 }
    496 
    497 /*******************************************************************************
    498 **
    499 ** Function         NFA_PauseP2p
    500 **
    501 ** Description      Pause P2P services.
    502 **                  NFA_P2P_PAUSED_EVT will be returned after P2P services are
    503 **                  disabled.
    504 **
    505 **                  The P2P services enabled by NFA_P2p* API functions are not
    506 **                  available. NFA_ResumeP2p() is called to resume the P2P
    507 **                  services.
    508 **
    509 ** Note:            If RF discovery is started,
    510 **                  NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should
    511 **                  happen before calling this function
    512 **
    513 ** Returns          NFA_STATUS_OK if successfully initiated
    514 **                  NFA_STATUS_FAILED otherwise
    515 **
    516 *******************************************************************************/
    517 tNFA_STATUS NFA_PauseP2p(void) {
    518   NFC_HDR* p_msg;
    519 
    520   NFA_TRACE_API0("NFA_PauseP2p ()");
    521 
    522   p_msg = (NFC_HDR*)GKI_getbuf(sizeof(NFC_HDR));
    523   if (p_msg != NULL) {
    524     p_msg->event = NFA_DM_API_PAUSE_P2P_EVT;
    525 
    526     nfa_sys_sendmsg(p_msg);
    527 
    528     return (NFA_STATUS_OK);
    529   }
    530 
    531   return (NFA_STATUS_FAILED);
    532 }
    533 
    534 /*******************************************************************************
    535 **
    536 ** Function         NFA_ResumeP2p
    537 **
    538 ** Description      Resume P2P services.
    539 **                  NFA_P2P_RESUMED_EVT will be returned after P2P services are.
    540 **                  enables again.
    541 **
    542 ** Note:            If RF discovery is started,
    543 **                  NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should
    544 **                  happen before calling this function
    545 **
    546 ** Returns          NFA_STATUS_OK if successfully initiated
    547 **                  NFA_STATUS_FAILED otherwise
    548 **
    549 *******************************************************************************/
    550 tNFA_STATUS NFA_ResumeP2p(void) {
    551   NFC_HDR* p_msg;
    552 
    553   NFA_TRACE_API0("NFA_ResumeP2p ()");
    554 
    555   p_msg = (NFC_HDR*)GKI_getbuf(sizeof(NFC_HDR));
    556   if (p_msg != NULL) {
    557     p_msg->event = NFA_DM_API_RESUME_P2P_EVT;
    558 
    559     nfa_sys_sendmsg(p_msg);
    560 
    561     return (NFA_STATUS_OK);
    562   }
    563 
    564   return (NFA_STATUS_FAILED);
    565 }
    566 
    567 /*******************************************************************************
    568 **
    569 ** Function         NFA_SetP2pListenTech
    570 **
    571 ** Description      This function is called to set listen technology for
    572 **                  NFC-DEP. This funtion may be called before or after starting
    573 **                  any server on NFA P2P/CHO/SNEP.
    574 **                  If there is no technology for NFC-DEP, P2P listening will be
    575 **                  stopped.
    576 **
    577 **                  NFA_SET_P2P_LISTEN_TECH_EVT without data will be returned.
    578 **
    579 ** Note:            If RF discovery is started,
    580 **                  NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should
    581 **                  happen before calling this function
    582 **
    583 ** Returns          NFA_STATUS_OK if successfully initiated
    584 **                  NFA_STATUS_FAILED otherwise
    585 **
    586 *******************************************************************************/
    587 tNFA_STATUS NFA_SetP2pListenTech(tNFA_TECHNOLOGY_MASK tech_mask) {
    588   tNFA_DM_API_SET_P2P_LISTEN_TECH* p_msg;
    589 
    590   NFA_TRACE_API1("NFA_P2pSetListenTech (): tech_mask:0x%X", tech_mask);
    591 
    592   p_msg = (tNFA_DM_API_SET_P2P_LISTEN_TECH*)GKI_getbuf(
    593       sizeof(tNFA_DM_API_SET_P2P_LISTEN_TECH));
    594   if (p_msg != NULL) {
    595     p_msg->hdr.event = NFA_DM_API_SET_P2P_LISTEN_TECH_EVT;
    596     p_msg->tech_mask = tech_mask;
    597 
    598     nfa_sys_sendmsg(p_msg);
    599 
    600     return (NFA_STATUS_OK);
    601   }
    602 
    603   return (NFA_STATUS_FAILED);
    604 }
    605 
    606 /*******************************************************************************
    607 **
    608 ** Function         NFA_StartRfDiscovery
    609 **
    610 ** Description      Start RF discovery
    611 **                  RF discovery parameters shall be set by other APIs.
    612 **
    613 **                  An NFA_RF_DISCOVERY_STARTED_EVT indicates whether starting
    614 **                  was successful or not.
    615 **
    616 ** Returns          NFA_STATUS_OK if successfully initiated
    617 **                  NFA_STATUS_FAILED otherwise
    618 **
    619 *******************************************************************************/
    620 tNFA_STATUS NFA_StartRfDiscovery(void) {
    621   NFC_HDR* p_msg;
    622 
    623   NFA_TRACE_API0("NFA_StartRfDiscovery ()");
    624 
    625   p_msg = (NFC_HDR*)GKI_getbuf(sizeof(NFC_HDR));
    626   if (p_msg != NULL) {
    627     p_msg->event = NFA_DM_API_START_RF_DISCOVERY_EVT;
    628 
    629     nfa_sys_sendmsg(p_msg);
    630 
    631     return (NFA_STATUS_OK);
    632   }
    633 
    634   return (NFA_STATUS_FAILED);
    635 }
    636 
    637 /*******************************************************************************
    638 **
    639 ** Function         NFA_StopRfDiscovery
    640 **
    641 ** Description      Stop RF discovery
    642 **
    643 **                  An NFA_RF_DISCOVERY_STOPPED_EVT indicates whether stopping
    644 **                  was successful or not.
    645 **
    646 ** Returns          NFA_STATUS_OK if successfully initiated
    647 **                  NFA_STATUS_FAILED otherwise
    648 **
    649 *******************************************************************************/
    650 tNFA_STATUS NFA_StopRfDiscovery(void) {
    651   NFC_HDR* p_msg;
    652 
    653   NFA_TRACE_API0("NFA_StopRfDiscovery ()");
    654 
    655   p_msg = (NFC_HDR*)GKI_getbuf(sizeof(NFC_HDR));
    656   if (p_msg != NULL) {
    657     p_msg->event = NFA_DM_API_STOP_RF_DISCOVERY_EVT;
    658 
    659     nfa_sys_sendmsg(p_msg);
    660 
    661     return (NFA_STATUS_OK);
    662   }
    663 
    664   return (NFA_STATUS_FAILED);
    665 }
    666 
    667 /*******************************************************************************
    668 **
    669 ** Function         NFA_SetRfDiscoveryDuration
    670 **
    671 ** Description      Set the duration of the single discovery period in [ms].
    672 **                  Allowable range: 0 ms to 0xFFFF ms.
    673 **
    674 **                  If discovery is already started, the application should
    675 **                  call NFA_StopRfDiscovery prior to calling
    676 **                  NFA_SetRfDiscoveryDuration, and then call
    677 **                  NFA_StartRfDiscovery afterwards to restart discovery using
    678 **                  the new duration.
    679 **
    680 ** Note:            If RF discovery is started,
    681 **                  NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should
    682 **                  happen before calling this function
    683 **
    684 ** Returns:
    685 **                  NFA_STATUS_OK, if command accepted
    686 **                  NFA_STATUS_FAILED: otherwise
    687 **
    688 *******************************************************************************/
    689 tNFA_STATUS NFA_SetRfDiscoveryDuration(uint16_t discovery_period_ms) {
    690   tNFA_DM_API_SET_RF_DISC_DUR* p_msg;
    691 
    692   NFA_TRACE_API0("NFA_SetRfDiscoveryDuration ()");
    693 
    694   /* Post the API message */
    695   p_msg = (tNFA_DM_API_SET_RF_DISC_DUR*)GKI_getbuf(sizeof(NFC_HDR));
    696   if (p_msg != NULL) {
    697     p_msg->hdr.event = NFA_DM_API_SET_RF_DISC_DURATION_EVT;
    698 
    699     /* Set discovery duration */
    700     p_msg->rf_disc_dur_ms = discovery_period_ms;
    701 
    702     nfa_sys_sendmsg(p_msg);
    703 
    704     return (NFA_STATUS_OK);
    705   }
    706 
    707   return (NFA_STATUS_FAILED);
    708 }
    709 
    710 /*******************************************************************************
    711 **
    712 ** Function         NFA_Select
    713 **
    714 ** Description      Select one from detected devices during discovery
    715 **                  (from NFA_DISC_RESULT_EVTs). The application should wait for
    716 **                  the final NFA_DISC_RESULT_EVT before selecting.
    717 **
    718 **                  An NFA_SELECT_RESULT_EVT indicates whether selection was
    719 **                  successful or not. If failed then application must select
    720 **                  again or deactivate by NFA_Deactivate().
    721 **
    722 ** Returns          NFA_STATUS_OK if successfully initiated
    723 **                  NFA_STATUS_INVALID_PARAM if RF interface is not matched
    724 **                  protocol
    725 **                  NFA_STATUS_FAILED otherwise
    726 **
    727 *******************************************************************************/
    728 tNFA_STATUS NFA_Select(uint8_t rf_disc_id, tNFA_NFC_PROTOCOL protocol,
    729                        tNFA_INTF_TYPE rf_interface) {
    730   tNFA_DM_API_SELECT* p_msg;
    731 
    732   NFA_TRACE_API3(
    733       "NFA_Select (): rf_disc_id:0x%X, protocol:0x%X, rf_interface:0x%X",
    734       rf_disc_id, protocol, rf_interface);
    735 
    736   if (((rf_interface == NFA_INTERFACE_ISO_DEP) &&
    737        (protocol != NFA_PROTOCOL_ISO_DEP)) ||
    738       ((rf_interface == NFA_INTERFACE_NFC_DEP) &&
    739        (protocol != NFA_PROTOCOL_NFC_DEP))) {
    740     NFA_TRACE_ERROR0("NFA_Select (): RF interface is not matched protocol");
    741     return (NFA_STATUS_INVALID_PARAM);
    742   }
    743 
    744   p_msg =
    745       (tNFA_DM_API_SELECT*)GKI_getbuf((uint16_t)(sizeof(tNFA_DM_API_SELECT)));
    746   if (p_msg != NULL) {
    747     p_msg->hdr.event = NFA_DM_API_SELECT_EVT;
    748     p_msg->rf_disc_id = rf_disc_id;
    749     p_msg->protocol = protocol;
    750     p_msg->rf_interface = rf_interface;
    751 
    752     nfa_sys_sendmsg(p_msg);
    753 
    754     return (NFA_STATUS_OK);
    755   }
    756 
    757   return (NFA_STATUS_FAILED);
    758 }
    759 
    760 /*******************************************************************************
    761 **
    762 ** Function         NFA_UpdateRFCommParams
    763 **
    764 ** Description      This function is called to update RF Communication
    765 **                  parameters once the Frame RF Interface has been activated.
    766 **
    767 **                  An NFA_UPDATE_RF_PARAM_RESULT_EVT indicates whether updating
    768 **                  was successful or not.
    769 **
    770 ** Returns          NFA_STATUS_OK if successfully initiated
    771 **                  NFA_STATUS_FAILED otherwise
    772 **
    773 *******************************************************************************/
    774 tNFA_STATUS NFA_UpdateRFCommParams(tNFA_RF_COMM_PARAMS* p_params) {
    775   tNFA_DM_API_UPDATE_RF_PARAMS* p_msg;
    776 
    777   NFA_TRACE_API0("NFA_UpdateRFCommParams ()");
    778 
    779   p_msg = (tNFA_DM_API_UPDATE_RF_PARAMS*)GKI_getbuf(
    780       (uint16_t)(sizeof(tNFA_DM_API_UPDATE_RF_PARAMS)));
    781   if (p_msg != NULL) {
    782     p_msg->hdr.event = NFA_DM_API_UPDATE_RF_PARAMS_EVT;
    783     memcpy(&p_msg->params, p_params, sizeof(tNFA_RF_COMM_PARAMS));
    784 
    785     nfa_sys_sendmsg(p_msg);
    786 
    787     return (NFA_STATUS_OK);
    788   }
    789 
    790   return (NFA_STATUS_FAILED);
    791 }
    792 
    793 /*******************************************************************************
    794 **
    795 ** Function         NFA_Deactivate
    796 **
    797 ** Description
    798 **                  If sleep_mode=TRUE:
    799 **                      Deselect the activated device by deactivating into sleep
    800 **                      mode.
    801 **
    802 **                      An NFA_DEACTIVATE_FAIL_EVT indicates that selection was
    803 **                      not successful. Application can select another
    804 **                      discovered device or deactivate by NFA_Deactivate()
    805 **                      after receiving NFA_DEACTIVATED_EVT.
    806 **
    807 **                      Deactivating to sleep mode is not allowed when NFCC is
    808 **                      in wait-for-host-select mode, or in listen-sleep states;
    809 **                      NFA will deactivate to idle or discovery state for these
    810 **                      cases respectively.
    811 **
    812 **
    813 **                  If sleep_mode=FALSE:
    814 **                      Deactivate the connection (e.g. as a result of presence
    815 **                      check failure) NFA_DEACTIVATED_EVT will indicate that
    816 **                      link is deactivated. Polling/listening will resume
    817 **                      (unless the nfcc is in wait_for-all-discoveries state)
    818 **
    819 **
    820 ** Returns          NFA_STATUS_OK if successfully initiated
    821 **                  NFA_STATUS_FAILED otherwise
    822 **
    823 *******************************************************************************/
    824 extern tNFA_STATUS NFA_Deactivate(bool sleep_mode) {
    825   tNFA_DM_API_DEACTIVATE* p_msg;
    826 
    827   NFA_TRACE_API1("NFA_Deactivate (): sleep_mode:%i", sleep_mode);
    828 
    829   p_msg = (tNFA_DM_API_DEACTIVATE*)GKI_getbuf(
    830       (uint16_t)(sizeof(tNFA_DM_API_DEACTIVATE)));
    831   if (p_msg != NULL) {
    832     p_msg->hdr.event = NFA_DM_API_DEACTIVATE_EVT;
    833     p_msg->sleep_mode = sleep_mode;
    834 
    835     nfa_sys_sendmsg(p_msg);
    836 
    837     return (NFA_STATUS_OK);
    838   }
    839 
    840   return (NFA_STATUS_FAILED);
    841 }
    842 
    843 /*******************************************************************************
    844 **
    845 ** Function         NFA_SendRawFrame
    846 **
    847 ** Description      Send a raw frame over the activated interface with the NFCC.
    848 **                  This function can only be called after NFC link is
    849 **                  activated.
    850 **
    851 **                  If the activated interface is a tag and auto-presence check
    852 **                  is enabled then presence_check_start_delay can be used to
    853 **                  indicate the delay in msec after which the next auto
    854 **                  presence check command can be sent.
    855 **                  NFA_DM_DEFAULT_PRESENCE_CHECK_START_DELAY can be used as the
    856 **                  default value for the delay.
    857 **
    858 ** Returns          NFA_STATUS_OK if successfully initiated
    859 **                  NFA_STATUS_FAILED otherwise
    860 **
    861 *******************************************************************************/
    862 tNFA_STATUS NFA_SendRawFrame(uint8_t* p_raw_data, uint16_t data_len,
    863                              uint16_t presence_check_start_delay) {
    864   NFC_HDR* p_msg;
    865   uint16_t size;
    866   uint8_t* p;
    867 
    868   NFA_TRACE_API1("NFA_SendRawFrame () data_len:%d", data_len);
    869 
    870   /* Validate parameters */
    871   if ((data_len == 0) || (p_raw_data == NULL))
    872     return (NFA_STATUS_INVALID_PARAM);
    873 
    874   size = NFC_HDR_SIZE + NCI_MSG_OFFSET_SIZE + NCI_DATA_HDR_SIZE + data_len;
    875   p_msg = (NFC_HDR*)GKI_getbuf(size);
    876   if (p_msg != NULL) {
    877     p_msg->event = NFA_DM_API_RAW_FRAME_EVT;
    878     p_msg->layer_specific = presence_check_start_delay;
    879     p_msg->offset = NCI_MSG_OFFSET_SIZE + NCI_DATA_HDR_SIZE;
    880     p_msg->len = data_len;
    881 
    882     p = (uint8_t*)(p_msg + 1) + p_msg->offset;
    883     memcpy(p, p_raw_data, data_len);
    884 
    885     nfa_sys_sendmsg(p_msg);
    886 
    887     return (NFA_STATUS_OK);
    888   }
    889 
    890   return (NFA_STATUS_FAILED);
    891 }
    892 
    893 /*******************************************************************************
    894 ** NDEF Handler APIs
    895 *******************************************************************************/
    896 
    897 /*******************************************************************************
    898 **
    899 ** Function         NFA_RegisterNDefTypeHandler
    900 **
    901 ** Description      This function allows the applications to register for
    902 **                  specific types of NDEF records. When NDEF records are
    903 **                  received, NFA will parse the record-type field, and pass
    904 **                  the record to the registered tNFA_NDEF_CBACK.
    905 **
    906 **                  For records types which were not registered, the record will
    907 **                  be sent to the default handler. A default type-handler may
    908 **                  be registered by calling this NFA_RegisterNDefTypeHandler
    909 **                  with tnf=NFA_TNF_DEFAULT. In this case, all un-registered
    910 **                  record types will be sent to the callback. Only one default
    911 **                  handler may be registered at a time.
    912 **
    913 **                  An NFA_NDEF_REGISTER_EVT will be sent to the tNFA_NDEF_CBACK
    914 **                  to indicate that registration was successful, and provide a
    915 **                  handle for this record type.
    916 **
    917 ** Returns          NFA_STATUS_OK if successfully initiated
    918 **                  NFA_STATUS_FAILED otherwise
    919 **
    920 *******************************************************************************/
    921 tNFA_STATUS NFA_RegisterNDefTypeHandler(bool handle_whole_message, tNFA_TNF tnf,
    922                                         uint8_t* p_type_name,
    923                                         uint8_t type_name_len,
    924                                         tNFA_NDEF_CBACK* p_ndef_cback) {
    925   tNFA_DM_API_REG_NDEF_HDLR* p_msg;
    926 
    927   NFA_TRACE_API2(
    928       "NFA_RegisterNDefTypeHandler (): handle whole ndef message: %i, "
    929       "tnf=0x%02x",
    930       handle_whole_message, tnf);
    931 
    932   /* Check for NULL callback */
    933   if (!p_ndef_cback) {
    934     NFA_TRACE_ERROR0("NFA_RegisterNDefTypeHandler (): error - null callback");
    935     return (NFA_STATUS_INVALID_PARAM);
    936   }
    937 
    938   p_msg = (tNFA_DM_API_REG_NDEF_HDLR*)GKI_getbuf(
    939       (uint16_t)(sizeof(tNFA_DM_API_REG_NDEF_HDLR) + type_name_len));
    940   if (p_msg != NULL) {
    941     p_msg->hdr.event = NFA_DM_API_REG_NDEF_HDLR_EVT;
    942 
    943     p_msg->flags =
    944         (handle_whole_message ? NFA_NDEF_FLAGS_HANDLE_WHOLE_MESSAGE : 0);
    945     p_msg->tnf = tnf;
    946     p_msg->name_len = type_name_len;
    947     p_msg->p_ndef_cback = p_ndef_cback;
    948     memcpy(p_msg->name, p_type_name, type_name_len);
    949 
    950     nfa_sys_sendmsg(p_msg);
    951 
    952     return (NFA_STATUS_OK);
    953   }
    954 
    955   return (NFA_STATUS_FAILED);
    956 }
    957 
    958 /*******************************************************************************
    959 **
    960 ** Function         NFA_RegisterNDefUriHandler
    961 **
    962 ** Description      This API is a special-case of NFA_RegisterNDefTypeHandler
    963 **                  with TNF=NFA_TNF_WKT, and type_name='U' (URI record); and
    964 **                  allows registering for specific URI types (e.g. 'tel:' or
    965 **                  'mailto:').
    966 **
    967 **                  An NFA_NDEF_REGISTER_EVT will be sent to the tNFA_NDEF_CBACK
    968 **                  to indicate that registration was successful, and provide a
    969 **                  handle for this registration.
    970 **
    971 **                  If uri_id=NFA_NDEF_URI_ID_ABSOLUTE, then p_abs_uri contains
    972 **                  the unabridged URI. For all other uri_id values,
    973 **                  the p_abs_uri parameter is ignored (i.e the URI prefix is
    974 **                  implied by uri_id). See [NFC RTD URI] for more information.
    975 **
    976 ** Returns          NFA_STATUS_OK if successfully initiated
    977 **                  NFA_STATUS_FAILED otherwise
    978 **
    979 *******************************************************************************/
    980 extern tNFA_STATUS NFA_RegisterNDefUriHandler(bool handle_whole_message,
    981                                               tNFA_NDEF_URI_ID uri_id,
    982                                               uint8_t* p_abs_uri,
    983                                               uint8_t uri_id_len,
    984                                               tNFA_NDEF_CBACK* p_ndef_cback) {
    985   tNFA_DM_API_REG_NDEF_HDLR* p_msg;
    986 
    987   NFA_TRACE_API2(
    988       "NFA_RegisterNDefUriHandler (): handle whole ndef message: %i, "
    989       "uri_id=0x%02x",
    990       handle_whole_message, uri_id);
    991 
    992   /* Check for NULL callback */
    993   if (!p_ndef_cback) {
    994     NFA_TRACE_ERROR0("NFA_RegisterNDefUriHandler (): error - null callback");
    995     return (NFA_STATUS_INVALID_PARAM);
    996   }
    997 
    998   p_msg = (tNFA_DM_API_REG_NDEF_HDLR*)GKI_getbuf(
    999       (uint16_t)(sizeof(tNFA_DM_API_REG_NDEF_HDLR) + uri_id_len));
   1000   if (p_msg != NULL) {
   1001     p_msg->hdr.event = NFA_DM_API_REG_NDEF_HDLR_EVT;
   1002 
   1003     p_msg->flags = NFA_NDEF_FLAGS_WKT_URI;
   1004 
   1005     if (handle_whole_message) {
   1006       p_msg->flags |= NFA_NDEF_FLAGS_HANDLE_WHOLE_MESSAGE;
   1007     }
   1008 
   1009     /* abs_uri is only valid fir uri_id=NFA_NDEF_URI_ID_ABSOLUTE */
   1010     if (uri_id != NFA_NDEF_URI_ID_ABSOLUTE) {
   1011       uri_id_len = 0;
   1012     }
   1013 
   1014     p_msg->tnf = NFA_TNF_WKT;
   1015     p_msg->uri_id = uri_id;
   1016     p_msg->name_len = uri_id_len;
   1017     p_msg->p_ndef_cback = p_ndef_cback;
   1018     memcpy(p_msg->name, p_abs_uri, uri_id_len);
   1019 
   1020     nfa_sys_sendmsg(p_msg);
   1021 
   1022     return (NFA_STATUS_OK);
   1023   }
   1024 
   1025   return (NFA_STATUS_FAILED);
   1026 }
   1027 
   1028 /*******************************************************************************
   1029 **
   1030 ** Function         NFA_DeregisterNDefTypeHandler
   1031 **
   1032 ** Description      Deregister NDEF record type handler.
   1033 **
   1034 ** Returns          NFA_STATUS_OK if successfully initiated
   1035 **                  NFA_STATUS_FAILED otherwise
   1036 **
   1037 *******************************************************************************/
   1038 extern tNFA_STATUS NFA_DeregisterNDefTypeHandler(tNFA_HANDLE ndef_type_handle) {
   1039   tNFA_DM_API_DEREG_NDEF_HDLR* p_msg;
   1040 
   1041   NFA_TRACE_API1("NFA_DeregisterNDefHandler (): handle 0x%08x",
   1042                  ndef_type_handle);
   1043 
   1044   p_msg = (tNFA_DM_API_DEREG_NDEF_HDLR*)GKI_getbuf(
   1045       (uint16_t)(sizeof(tNFA_DM_API_DEREG_NDEF_HDLR)));
   1046   if (p_msg != NULL) {
   1047     p_msg->hdr.event = NFA_DM_API_DEREG_NDEF_HDLR_EVT;
   1048     p_msg->ndef_type_handle = ndef_type_handle;
   1049 
   1050     nfa_sys_sendmsg(p_msg);
   1051 
   1052     return (NFA_STATUS_OK);
   1053   }
   1054 
   1055   return (NFA_STATUS_FAILED);
   1056 }
   1057 
   1058 /*******************************************************************************
   1059 **
   1060 ** Function         NFA_PowerOffSleepMode
   1061 **
   1062 ** Description      This function is called to enter or leave NFCC Power Off
   1063 **                  Sleep mode NFA_DM_PWR_MODE_CHANGE_EVT will be sent to
   1064 **                  indicate status.
   1065 **
   1066 **                  start_stop : TRUE if entering Power Off Sleep mode
   1067 **                               FALSE if leaving Power Off Sleep mode
   1068 **
   1069 ** Returns          NFA_STATUS_OK if successfully initiated
   1070 **                  NFA_STATUS_FAILED otherwise
   1071 **
   1072 *******************************************************************************/
   1073 tNFA_STATUS NFA_PowerOffSleepMode(bool start_stop) {
   1074   NFC_HDR* p_msg;
   1075 
   1076   NFA_TRACE_API1("NFA_PowerOffSleepState () start_stop=%d", start_stop);
   1077 
   1078   if (nfa_dm_cb.flags & NFA_DM_FLAGS_SETTING_PWR_MODE) {
   1079     NFA_TRACE_ERROR0(
   1080         "NFA_PowerOffSleepState (): NFA DM is busy to update power mode");
   1081     return (NFA_STATUS_FAILED);
   1082   } else {
   1083     nfa_dm_cb.flags |= NFA_DM_FLAGS_SETTING_PWR_MODE;
   1084   }
   1085 
   1086   p_msg = (NFC_HDR*)GKI_getbuf(sizeof(NFC_HDR));
   1087   if (p_msg != NULL) {
   1088     p_msg->event = NFA_DM_API_POWER_OFF_SLEEP_EVT;
   1089     p_msg->layer_specific = start_stop;
   1090 
   1091     nfa_sys_sendmsg(p_msg);
   1092 
   1093     return (NFA_STATUS_OK);
   1094   }
   1095 
   1096   return (NFA_STATUS_FAILED);
   1097 }
   1098 
   1099 /*******************************************************************************
   1100 **
   1101 ** Function         NFA_RegVSCback
   1102 **
   1103 ** Description      This function is called to register or de-register a
   1104 **                  callback function to receive Proprietary NCI response and
   1105 **                  notification events. The maximum number of callback
   1106 **                  functions allowed is NFC_NUM_VS_CBACKS
   1107 **
   1108 ** Returns          tNFC_STATUS
   1109 **
   1110 *******************************************************************************/
   1111 tNFC_STATUS NFA_RegVSCback(bool is_register, tNFA_VSC_CBACK* p_cback) {
   1112   tNFA_DM_API_REG_VSC* p_msg;
   1113 
   1114   NFA_TRACE_API1("NFA_RegVSCback() is_register=%d", is_register);
   1115 
   1116   if (p_cback == NULL) {
   1117     NFA_TRACE_ERROR0("NFA_RegVSCback() requires a valid callback function");
   1118     return (NFA_STATUS_FAILED);
   1119   }
   1120 
   1121   p_msg = (tNFA_DM_API_REG_VSC*)GKI_getbuf(sizeof(tNFA_DM_API_REG_VSC));
   1122   if (p_msg != NULL) {
   1123     p_msg->hdr.event = NFA_DM_API_REG_VSC_EVT;
   1124     p_msg->is_register = is_register;
   1125     p_msg->p_cback = p_cback;
   1126 
   1127     nfa_sys_sendmsg(p_msg);
   1128 
   1129     return (NFA_STATUS_OK);
   1130   }
   1131 
   1132   return (NFA_STATUS_FAILED);
   1133 }
   1134 
   1135 /*******************************************************************************
   1136 **
   1137 ** Function         NFA_SendVsCommand
   1138 **
   1139 ** Description      This function is called to send an NCI Vendor Specific
   1140 **                  command to NFCC.
   1141 **
   1142 **                  oid             - The opcode of the VS command.
   1143 **                  cmd_params_len  - The command parameter len
   1144 **                  p_cmd_params    - The command parameter
   1145 **                  p_cback         - The callback function to receive the
   1146 **                                    command status
   1147 **
   1148 ** Returns          NFA_STATUS_OK if successfully initiated
   1149 **                  NFA_STATUS_FAILED otherwise
   1150 **
   1151 *******************************************************************************/
   1152 tNFA_STATUS NFA_SendVsCommand(uint8_t oid, uint8_t cmd_params_len,
   1153                               uint8_t* p_cmd_params, tNFA_VSC_CBACK* p_cback) {
   1154   tNFA_DM_API_SEND_VSC* p_msg;
   1155   uint16_t size = sizeof(tNFA_DM_API_SEND_VSC) + cmd_params_len;
   1156 
   1157   NFA_TRACE_API1("NFA_SendVsCommand() oid=0x%x", oid);
   1158 
   1159   p_msg = (tNFA_DM_API_SEND_VSC*)GKI_getbuf(size);
   1160   if (p_msg != NULL) {
   1161     p_msg->hdr.event = NFA_DM_API_SEND_VSC_EVT;
   1162     p_msg->oid = oid;
   1163     p_msg->p_cback = p_cback;
   1164     if (cmd_params_len && p_cmd_params) {
   1165       p_msg->cmd_params_len = cmd_params_len;
   1166       p_msg->p_cmd_params = (uint8_t*)(p_msg + 1);
   1167       memcpy(p_msg->p_cmd_params, p_cmd_params, cmd_params_len);
   1168     } else {
   1169       p_msg->cmd_params_len = 0;
   1170       p_msg->p_cmd_params = NULL;
   1171     }
   1172 
   1173     nfa_sys_sendmsg(p_msg);
   1174 
   1175     return (NFA_STATUS_OK);
   1176   }
   1177 
   1178   return (NFA_STATUS_FAILED);
   1179 }
   1180 
   1181 /*******************************************************************************
   1182 **
   1183 ** Function         NFA_SetTraceLevel
   1184 **
   1185 ** Description      This function sets the trace level for NFA.  If called with
   1186 **                  a value of 0xFF, it simply returns the current trace level.
   1187 **
   1188 ** Returns          The new or current trace level
   1189 **
   1190 *******************************************************************************/
   1191 uint8_t NFA_SetTraceLevel(uint8_t new_level) {
   1192   if (new_level != 0xFF) nfa_sys_set_trace_level(new_level);
   1193 
   1194   return (nfa_sys_cb.trace_level);
   1195 }
   1196