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