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