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