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