blob: bec5df4466d611d0e1175e6e4ded9ede75b0e442 [file] [log] [blame]
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001/******************************************************************************
2 *
Evan Chue9629ba2014-01-31 11:18:47 -05003 * Copyright (C) 2010-2014 Broadcom Corporation
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08004 *
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>
Andre Eisenbach8a4edf62017-11-20 14:51:11 -080025
26#include <android-base/stringprintf.h>
27#include <base/logging.h>
28
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -080029#include "ndef_utils.h"
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -080030#include "nfa_api.h"
31#include "nfa_ce_int.h"
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -080032
Andre Eisenbach8a4edf62017-11-20 14:51:11 -080033using android::base::StringPrintf;
34
35extern bool nfc_debug_enabled;
36
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -080037/*****************************************************************************
38** Constants
39*****************************************************************************/
40
41/*****************************************************************************
42** APIs
43*****************************************************************************/
44/*******************************************************************************
45**
46** Function NFA_Init
47**
48** Description This function initializes control blocks for NFA
49**
50** p_hal_entry_tbl points to a table of HAL entry points
51**
52** NOTE: the buffer that p_hal_entry_tbl points must be
53** persistent until NFA is disabled.
54**
55** Returns none
56**
57*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -080058void NFA_Init(tHAL_NFC_ENTRY* p_hal_entry_tbl) {
Ruchi Kandoi6767aec2017-09-26 09:46:26 -070059 DLOG_IF(INFO, nfc_debug_enabled) << __func__;
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -080060 nfa_sys_init();
61 nfa_dm_init();
62 nfa_p2p_init();
63 nfa_snep_init(false);
64 nfa_rw_init();
65 nfa_ce_init();
66 nfa_ee_init();
67 if (nfa_ee_max_ee_cfg != 0) {
68 nfa_dm_cb.get_max_ee = p_hal_entry_tbl->get_max_ee;
69 nfa_hci_init();
70 }
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -080071
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -080072 /* Initialize NFC module */
73 NFC_Init(p_hal_entry_tbl);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -080074}
75
76/*******************************************************************************
77**
78** Function NFA_Enable
79**
80** Description This function enables NFC. Prior to calling NFA_Enable,
81** the NFCC must be powered up, and ready to receive commands.
82** This function enables the tasks needed by NFC, opens the NCI
83** transport, resets the NFC controller, downloads patches to
84** the NFCC (if necessary), and initializes the NFC subsystems.
85**
Ruchi Kandoi552f2b72017-01-28 16:22:55 -080086** This function should only be called once - typically when
87** NFC is enabled during boot-up, or when NFC is enabled from a
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -080088** settings UI. Subsequent calls to NFA_Enable while NFA is
89** enabling or enabled will be ignored. When the NFC startup
Ruchi Kandoi552f2b72017-01-28 16:22:55 -080090** procedure is completed, an NFA_DM_ENABLE_EVT is returned to
91** the application using the tNFA_DM_CBACK.
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -080092**
93** Returns NFA_STATUS_OK if successfully initiated
94** NFA_STATUS_FAILED otherwise
95**
96*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -080097tNFA_STATUS NFA_Enable(tNFA_DM_CBACK* p_dm_cback,
98 tNFA_CONN_CBACK* p_conn_cback) {
99 tNFA_DM_API_ENABLE* p_msg;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800100
Ruchi Kandoi6767aec2017-09-26 09:46:26 -0700101 DLOG_IF(INFO, nfc_debug_enabled) << __func__;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800102
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800103 /* Validate parameters */
104 if ((!p_dm_cback) || (!p_conn_cback)) {
Ruchi Kandoi6767aec2017-09-26 09:46:26 -0700105 LOG(ERROR) << StringPrintf("error null callback");
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800106 return (NFA_STATUS_FAILED);
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800107 }
108
Ruchi Kandoi0c515ae2017-01-30 17:48:41 -0800109 p_msg = (tNFA_DM_API_ENABLE*)GKI_getbuf(sizeof(tNFA_DM_API_ENABLE));
110 if (p_msg != NULL) {
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800111 p_msg->hdr.event = NFA_DM_API_ENABLE_EVT;
112 p_msg->p_dm_cback = p_dm_cback;
113 p_msg->p_conn_cback = p_conn_cback;
114
115 nfa_sys_sendmsg(p_msg);
116
117 return (NFA_STATUS_OK);
118 }
119
120 return (NFA_STATUS_FAILED);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800121}
122
123/*******************************************************************************
124**
125** Function NFA_Disable
126**
127** Description This function is called to shutdown NFC. The tasks for NFC
128** are terminated, and clean up routines are performed. This
129** function is typically called during platform shut-down, or
130** when NFC is disabled from a settings UI. When the NFC
131** shutdown procedure is completed, an NFA_DM_DISABLE_EVT is
132** returned to the application using the tNFA_DM_CBACK.
133**
134** The platform should wait until the NFC_DISABLE_REVT is
Ruchi Kandoi552f2b72017-01-28 16:22:55 -0800135** received before powering down the NFC chip and NCI
136** transport. This is required to so that NFA can gracefully
137** shut down any open connections.
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800138**
139** Returns NFA_STATUS_OK if successfully initiated
140** NFA_STATUS_FAILED otherwise
141**
142*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800143tNFA_STATUS NFA_Disable(bool graceful) {
144 tNFA_DM_API_DISABLE* p_msg;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800145
Ruchi Kandoi6767aec2017-09-26 09:46:26 -0700146 DLOG_IF(INFO, nfc_debug_enabled)
147 << StringPrintf("NFA_Disable (graceful=%i)", graceful);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800148
Ruchi Kandoi0c515ae2017-01-30 17:48:41 -0800149 p_msg = (tNFA_DM_API_DISABLE*)GKI_getbuf(sizeof(tNFA_DM_API_DISABLE));
150 if (p_msg != NULL) {
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800151 p_msg->hdr.event = NFA_DM_API_DISABLE_EVT;
152 p_msg->graceful = graceful;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800153
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800154 nfa_sys_sendmsg(p_msg);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800155
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800156 return (NFA_STATUS_OK);
157 }
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800158
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800159 return (NFA_STATUS_FAILED);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800160}
Love Khanna81e4f812017-06-02 17:50:19 +0530161
162/*******************************************************************************
163**
164** Function NFA_GetNCIVersion
165**
166** Description Returns the NCI version of the NFCC to upper layer
167**
168**
169** Returns NCI version NCI2.0 / NCI1.0
170**
171*******************************************************************************/
172uint8_t NFA_GetNCIVersion() { return NFC_GetNCIVersion(); }
173
Love Khanna5e4b4d72017-04-14 18:23:55 +0530174/*******************************************************************************
175**
176** Function NFA_SetPowerSubStateForScreenState
177**
178** Description Update the power sub-state as per current screen state to
179** NFCC.
180**
181** Returns NFA_STATUS_OK if successfully initiated
182** NFA_STATUS_FAILED otherwise
183**
184*******************************************************************************/
185tNFA_STATUS NFA_SetPowerSubStateForScreenState(uint8_t screenState) {
Ruchi Kandoi6767aec2017-09-26 09:46:26 -0700186 DLOG_IF(INFO, nfc_debug_enabled)
187 << StringPrintf("%s: state:0x%X", __func__, screenState);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800188
Love Khanna5e4b4d72017-04-14 18:23:55 +0530189 uint8_t nci_scren_state = 0xFF;
190 uint16_t buf_size = sizeof(tNFA_DM_API_SET_POWER_SUB_STATE);
191 tNFA_DM_API_SET_POWER_SUB_STATE* p_msg =
192 (tNFA_DM_API_SET_POWER_SUB_STATE*)GKI_getbuf(buf_size);
193
194 if (p_msg != NULL) {
195 p_msg->hdr.event = NFA_DM_API_SET_POWER_SUB_STATE_EVT;
196 switch (screenState) {
197 case NFA_SCREEN_STATE_ON_UNLOCKED:
198 nci_scren_state = SCREEN_STATE_ON_UNLOCKED;
199 break;
200 case NFA_SCREEN_STATE_OFF_UNLOCKED:
201 nci_scren_state = SCREEN_STATE_OFF_UNLOCKED;
202 break;
203 case NFA_SCREEN_STATE_ON_LOCKED:
204 nci_scren_state = SCREEN_STATE_ON_LOCKED;
205 break;
206 case NFA_SCREEN_STATE_OFF_LOCKED:
207 nci_scren_state = SCREEN_STATE_OFF_LOCKED;
208 break;
209
210 default:
Ruchi Kandoi6767aec2017-09-26 09:46:26 -0700211 DLOG_IF(INFO, nfc_debug_enabled)
212 << StringPrintf("%s, unknown screen state", __func__);
Love Khanna5e4b4d72017-04-14 18:23:55 +0530213 break;
214 }
215
216 p_msg->screen_state = nci_scren_state;
217
218 nfa_sys_sendmsg(p_msg);
219 return (NFA_STATUS_OK);
220 }
221 return (NFA_STATUS_FAILED);
222}
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800223/*******************************************************************************
224**
225** Function NFA_SetConfig
226**
227** Description Set the configuration parameters to NFCC. The result is
228** reported with an NFA_DM_SET_CONFIG_EVT in the tNFA_DM_CBACK
229** callback.
230**
Ruchi Kandoi552f2b72017-01-28 16:22:55 -0800231** Note: If RF discovery is started,
232** NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should
233** happen before calling this function. Most Configuration
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800234** parameters are related to RF discovery.
235**
236** Returns NFA_STATUS_OK if successfully initiated
237** NFA_STATUS_BUSY if previous setting is on-going
238** NFA_STATUS_FAILED otherwise
239**
240*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800241tNFA_STATUS NFA_SetConfig(tNFA_PMID param_id, uint8_t length, uint8_t* p_data) {
242 tNFA_DM_API_SET_CONFIG* p_msg;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800243
Ruchi Kandoi6767aec2017-09-26 09:46:26 -0700244 DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("param_id:0x%X", param_id);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800245
Ruchi Kandoi0c515ae2017-01-30 17:48:41 -0800246 p_msg = (tNFA_DM_API_SET_CONFIG*)GKI_getbuf(
247 (uint16_t)(sizeof(tNFA_DM_API_SET_CONFIG) + length));
248 if (p_msg != NULL) {
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800249 p_msg->hdr.event = NFA_DM_API_SET_CONFIG_EVT;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800250
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800251 p_msg->param_id = param_id;
252 p_msg->length = length;
253 p_msg->p_data = (uint8_t*)(p_msg + 1);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800254
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800255 /* Copy parameter data */
256 memcpy(p_msg->p_data, p_data, length);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800257
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800258 nfa_sys_sendmsg(p_msg);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800259
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800260 return (NFA_STATUS_OK);
261 }
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800262
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800263 return (NFA_STATUS_FAILED);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800264}
265
266/*******************************************************************************
267**
268** Function NFA_GetConfig
269**
270** Description Get the configuration parameters from NFCC. The result is
271** reported with an NFA_DM_GET_CONFIG_EVT in the tNFA_DM_CBACK
272** callback.
273**
274** Returns NFA_STATUS_OK if successfully initiated
275** NFA_STATUS_FAILED otherwise
276**
277*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800278tNFA_STATUS NFA_GetConfig(uint8_t num_ids, tNFA_PMID* p_param_ids) {
279 tNFA_DM_API_GET_CONFIG* p_msg;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800280
Ruchi Kandoi6767aec2017-09-26 09:46:26 -0700281 DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("num_ids: %i", num_ids);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800282
Ruchi Kandoi0c515ae2017-01-30 17:48:41 -0800283 p_msg = (tNFA_DM_API_GET_CONFIG*)GKI_getbuf(
284 (uint16_t)(sizeof(tNFA_DM_API_GET_CONFIG) + num_ids));
285 if (p_msg != NULL) {
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800286 p_msg->hdr.event = NFA_DM_API_GET_CONFIG_EVT;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800287
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800288 p_msg->num_ids = num_ids;
289 p_msg->p_pmids = (tNFA_PMID*)(p_msg + 1);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800290
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800291 /* Copy the param IDs */
292 memcpy(p_msg->p_pmids, p_param_ids, num_ids);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800293
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800294 nfa_sys_sendmsg(p_msg);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800295
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800296 return (NFA_STATUS_OK);
297 }
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800298
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800299 return (NFA_STATUS_FAILED);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800300}
301
302/*******************************************************************************
303**
304** Function NFA_RequestExclusiveRfControl
305**
306** Description Request exclusive control of NFC.
307** - Previous behavior (polling/tag reading, DH card emulation)
308** will be suspended .
309** - Polling and listening will be done based on the specified
310** params
311**
312** The NFA_EXCLUSIVE_RF_CONTROL_STARTED_EVT event of
313** tNFA_CONN_CBACK indicates the status of the operation.
314**
315** NFA_ACTIVATED_EVT and NFA_DEACTIVATED_EVT indicates link
316** activation/deactivation.
317**
Ruchi Kandoi552f2b72017-01-28 16:22:55 -0800318** NFA_SendRawFrame is used to send data to the peer.
319** NFA_DATA_EVT indicates data from the peer.
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800320**
321** If a tag is activated, then the NFA_RW APIs may be used to
322** send commands to the tag. Incoming NDEF messages are sent to
323** the NDEF callback.
324**
325** Once exclusive RF control has started, NFA will not activate
326** LLCP internally. The application has exclusive control of
327** the link.
328**
Ruchi Kandoi552f2b72017-01-28 16:22:55 -0800329** Note: If RF discovery is started,
330** NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should
331** happen before calling this function
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800332**
333** Returns NFA_STATUS_OK if successfully initiated
334** NFA_STATUS_FAILED otherwise
335**
336*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800337tNFA_STATUS NFA_RequestExclusiveRfControl(tNFA_TECHNOLOGY_MASK poll_mask,
338 tNFA_LISTEN_CFG* p_listen_cfg,
339 tNFA_CONN_CBACK* p_conn_cback,
340 tNFA_NDEF_CBACK* p_ndef_cback) {
341 tNFA_DM_API_REQ_EXCL_RF_CTRL* p_msg;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800342
Ruchi Kandoi6767aec2017-09-26 09:46:26 -0700343 DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("poll_mask=0x%x", poll_mask);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800344
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800345 if (!p_conn_cback) {
Ruchi Kandoi6767aec2017-09-26 09:46:26 -0700346 LOG(ERROR) << StringPrintf("error null callback");
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800347 return (NFA_STATUS_FAILED);
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800348 }
349
Ruchi Kandoi0c515ae2017-01-30 17:48:41 -0800350 p_msg = (tNFA_DM_API_REQ_EXCL_RF_CTRL*)GKI_getbuf(
351 sizeof(tNFA_DM_API_REQ_EXCL_RF_CTRL));
352 if (p_msg != NULL) {
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800353 p_msg->hdr.event = NFA_DM_API_REQUEST_EXCL_RF_CTRL_EVT;
354 p_msg->poll_mask = poll_mask;
355 p_msg->p_conn_cback = p_conn_cback;
356 p_msg->p_ndef_cback = p_ndef_cback;
357
358 if (p_listen_cfg)
359 memcpy(&p_msg->listen_cfg, p_listen_cfg, sizeof(tNFA_LISTEN_CFG));
360 else
361 memset(&p_msg->listen_cfg, 0x00, sizeof(tNFA_LISTEN_CFG));
362
363 nfa_sys_sendmsg(p_msg);
364
365 return (NFA_STATUS_OK);
366 }
367
368 return (NFA_STATUS_FAILED);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800369}
370
371/*******************************************************************************
372**
373** Function NFA_ReleaseExclusiveRfControl
374**
375** Description Release exclusive control of NFC. Once released, behavior
376** prior to obtaining exclusive RF control will resume.
377**
378** Returns NFA_STATUS_OK if successfully initiated
379** NFA_STATUS_FAILED otherwise
380**
381*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800382tNFA_STATUS NFA_ReleaseExclusiveRfControl(void) {
383 NFC_HDR* p_msg;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800384
Ruchi Kandoi6767aec2017-09-26 09:46:26 -0700385 DLOG_IF(INFO, nfc_debug_enabled) << __func__;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800386
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800387 if (!nfa_dm_cb.p_excl_conn_cback) {
Ruchi Kandoi6767aec2017-09-26 09:46:26 -0700388 LOG(ERROR) << StringPrintf(
389 "Exclusive rf control is not in "
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800390 "progress");
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800391 return (NFA_STATUS_FAILED);
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800392 }
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800393
Ruchi Kandoi0c515ae2017-01-30 17:48:41 -0800394 p_msg = (NFC_HDR*)GKI_getbuf(sizeof(NFC_HDR));
395 if (p_msg != NULL) {
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800396 p_msg->event = NFA_DM_API_RELEASE_EXCL_RF_CTRL_EVT;
397 nfa_sys_sendmsg(p_msg);
398 return (NFA_STATUS_OK);
399 }
400
401 return (NFA_STATUS_FAILED);
402}
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800403
404/*******************************************************************************
405**
406** Function NFA_EnablePolling
407**
408** Description Enable polling for technologies specified by poll_mask.
409**
410** The following events (notified using the connection
411** callback registered with NFA_Enable) are generated during
412** polling:
413**
414** - NFA_POLL_ENABLED_EVT indicates whether or not polling
415** successfully enabled.
Ruchi Kandoi552f2b72017-01-28 16:22:55 -0800416** - NFA_DISC_RESULT_EVT indicates there are more than one
417** devices, so application must select one of tags by calling
418** NFA_Select().
419** - NFA_SELECT_RESULT_EVT indicates whether previous selection
420** was successful or not. If it was failed then application
421** must select again or deactivate by calling
422** NFA_Deactivate().
423** - NFA_ACTIVATED_EVT is generated when an NFC link is
424** activated.
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800425** - NFA_NDEF_DETECT_EVT is generated if tag is activated
Ruchi Kandoi552f2b72017-01-28 16:22:55 -0800426** - NFA_LLCP_ACTIVATED_EVT/NFA_LLCP_DEACTIVATED_EVT is
427** generated if NFC-DEP is activated
428** - NFA_DEACTIVATED_EVT will be returned after deactivating
429** NFC link.
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800430**
Ruchi Kandoi552f2b72017-01-28 16:22:55 -0800431** Note: If RF discovery is started,
432** NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should
433** happen before calling this function
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800434**
435** Returns NFA_STATUS_OK if successfully initiated
436** NFA_STATUS_FAILED otherwise
437**
438*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800439tNFA_STATUS NFA_EnablePolling(tNFA_TECHNOLOGY_MASK poll_mask) {
440 tNFA_DM_API_ENABLE_POLL* p_msg;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800441
Ruchi Kandoi6767aec2017-09-26 09:46:26 -0700442 DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("0x%X", poll_mask);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800443
Ruchi Kandoi0c515ae2017-01-30 17:48:41 -0800444 p_msg = (tNFA_DM_API_ENABLE_POLL*)GKI_getbuf(sizeof(tNFA_DM_API_ENABLE_POLL));
445 if (p_msg != NULL) {
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800446 p_msg->hdr.event = NFA_DM_API_ENABLE_POLLING_EVT;
447 p_msg->poll_mask = poll_mask;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800448
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800449 nfa_sys_sendmsg(p_msg);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800450
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800451 return (NFA_STATUS_OK);
452 }
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800453
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800454 return (NFA_STATUS_FAILED);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800455}
456
457/*******************************************************************************
458**
459** Function NFA_DisablePolling
460**
461** Description Disable polling
Ruchi Kandoi552f2b72017-01-28 16:22:55 -0800462** NFA_POLL_DISABLED_EVT will be returned after stopping
463** polling.
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800464**
Ruchi Kandoi552f2b72017-01-28 16:22:55 -0800465** Note: If RF discovery is started,
466** NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should
467** happen before calling this function
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800468**
469** Returns NFA_STATUS_OK if successfully initiated
470** NFA_STATUS_FAILED otherwise
471**
472*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800473tNFA_STATUS NFA_DisablePolling(void) {
474 NFC_HDR* p_msg;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800475
Ruchi Kandoi6767aec2017-09-26 09:46:26 -0700476 DLOG_IF(INFO, nfc_debug_enabled) << __func__;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800477
Ruchi Kandoi0c515ae2017-01-30 17:48:41 -0800478 p_msg = (NFC_HDR*)GKI_getbuf(sizeof(NFC_HDR));
479 if (p_msg != NULL) {
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800480 p_msg->event = NFA_DM_API_DISABLE_POLLING_EVT;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800481
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800482 nfa_sys_sendmsg(p_msg);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800483
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800484 return (NFA_STATUS_OK);
485 }
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800486
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800487 return (NFA_STATUS_FAILED);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800488}
489
490/*******************************************************************************
491**
Evan Chu67aef6c2013-08-29 13:02:54 -0700492** Function NFA_EnableListening
493**
494** Description Enable listening.
Ruchi Kandoi552f2b72017-01-28 16:22:55 -0800495** NFA_LISTEN_ENABLED_EVT will be returned after listening is
496** allowed.
Evan Chu67aef6c2013-08-29 13:02:54 -0700497**
498** The actual listening technologies are specified by other NFA
499** API functions. Such functions include (but not limited to)
500** NFA_CeConfigureUiccListenTech.
Ruchi Kandoi552f2b72017-01-28 16:22:55 -0800501** If NFA_DisableListening () is called to ignore the listening
502** technologies, NFA_EnableListening () is called to restore
503** the listening technologies set by these functions.
Evan Chu67aef6c2013-08-29 13:02:54 -0700504**
Ruchi Kandoi552f2b72017-01-28 16:22:55 -0800505** Note: If RF discovery is started,
506** NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should
507** happen before calling this function
Evan Chu67aef6c2013-08-29 13:02:54 -0700508**
509** Returns NFA_STATUS_OK if successfully initiated
510** NFA_STATUS_FAILED otherwise
511**
512*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800513tNFA_STATUS NFA_EnableListening(void) {
514 NFC_HDR* p_msg;
Evan Chu67aef6c2013-08-29 13:02:54 -0700515
Ruchi Kandoi6767aec2017-09-26 09:46:26 -0700516 DLOG_IF(INFO, nfc_debug_enabled) << __func__;
Evan Chu67aef6c2013-08-29 13:02:54 -0700517
Ruchi Kandoi0c515ae2017-01-30 17:48:41 -0800518 p_msg = (NFC_HDR*)GKI_getbuf(sizeof(NFC_HDR));
519 if (p_msg != NULL) {
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800520 p_msg->event = NFA_DM_API_ENABLE_LISTENING_EVT;
Evan Chu67aef6c2013-08-29 13:02:54 -0700521
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800522 nfa_sys_sendmsg(p_msg);
Evan Chu67aef6c2013-08-29 13:02:54 -0700523
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800524 return (NFA_STATUS_OK);
525 }
Evan Chu67aef6c2013-08-29 13:02:54 -0700526
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800527 return (NFA_STATUS_FAILED);
Evan Chu67aef6c2013-08-29 13:02:54 -0700528}
529
530/*******************************************************************************
531**
532** Function NFA_DisableListening
533**
534** Description Disable listening
Ruchi Kandoi552f2b72017-01-28 16:22:55 -0800535** NFA_LISTEN_DISABLED_EVT will be returned after stopping
536** listening. This function is called to exclude listen at RF
537** discovery.
Evan Chu67aef6c2013-08-29 13:02:54 -0700538**
Ruchi Kandoi552f2b72017-01-28 16:22:55 -0800539** Note: If RF discovery is started,
540** NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should
541** happen before calling this function
Evan Chu67aef6c2013-08-29 13:02:54 -0700542**
543** Returns NFA_STATUS_OK if successfully initiated
544** NFA_STATUS_FAILED otherwise
545**
546*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800547tNFA_STATUS NFA_DisableListening(void) {
548 NFC_HDR* p_msg;
Evan Chu67aef6c2013-08-29 13:02:54 -0700549
Ruchi Kandoi6767aec2017-09-26 09:46:26 -0700550 DLOG_IF(INFO, nfc_debug_enabled) << __func__;
Evan Chu67aef6c2013-08-29 13:02:54 -0700551
Ruchi Kandoi0c515ae2017-01-30 17:48:41 -0800552 p_msg = (NFC_HDR*)GKI_getbuf(sizeof(NFC_HDR));
553 if (p_msg != NULL) {
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800554 p_msg->event = NFA_DM_API_DISABLE_LISTENING_EVT;
Evan Chu67aef6c2013-08-29 13:02:54 -0700555
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800556 nfa_sys_sendmsg(p_msg);
Evan Chu67aef6c2013-08-29 13:02:54 -0700557
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800558 return (NFA_STATUS_OK);
559 }
Evan Chu67aef6c2013-08-29 13:02:54 -0700560
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800561 return (NFA_STATUS_FAILED);
Evan Chu67aef6c2013-08-29 13:02:54 -0700562}
563
564/*******************************************************************************
565**
566** Function NFA_PauseP2p
567**
568** Description Pause P2P services.
569** NFA_P2P_PAUSED_EVT will be returned after P2P services are
570** disabled.
571**
572** The P2P services enabled by NFA_P2p* API functions are not
573** available. NFA_ResumeP2p() is called to resume the P2P
574** services.
575**
Ruchi Kandoi552f2b72017-01-28 16:22:55 -0800576** Note: If RF discovery is started,
577** NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should
578** happen before calling this function
Evan Chu67aef6c2013-08-29 13:02:54 -0700579**
580** Returns NFA_STATUS_OK if successfully initiated
581** NFA_STATUS_FAILED otherwise
582**
583*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800584tNFA_STATUS NFA_PauseP2p(void) {
585 NFC_HDR* p_msg;
Evan Chu67aef6c2013-08-29 13:02:54 -0700586
Ruchi Kandoi6767aec2017-09-26 09:46:26 -0700587 DLOG_IF(INFO, nfc_debug_enabled) << __func__;
Evan Chu67aef6c2013-08-29 13:02:54 -0700588
Ruchi Kandoi0c515ae2017-01-30 17:48:41 -0800589 p_msg = (NFC_HDR*)GKI_getbuf(sizeof(NFC_HDR));
590 if (p_msg != NULL) {
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800591 p_msg->event = NFA_DM_API_PAUSE_P2P_EVT;
Evan Chu67aef6c2013-08-29 13:02:54 -0700592
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800593 nfa_sys_sendmsg(p_msg);
Evan Chu67aef6c2013-08-29 13:02:54 -0700594
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800595 return (NFA_STATUS_OK);
596 }
Evan Chu67aef6c2013-08-29 13:02:54 -0700597
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800598 return (NFA_STATUS_FAILED);
Evan Chu67aef6c2013-08-29 13:02:54 -0700599}
600
601/*******************************************************************************
602**
603** Function NFA_ResumeP2p
604**
605** Description Resume P2P services.
606** NFA_P2P_RESUMED_EVT will be returned after P2P services are.
607** enables again.
608**
Ruchi Kandoi552f2b72017-01-28 16:22:55 -0800609** Note: If RF discovery is started,
610** NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should
611** happen before calling this function
Evan Chu67aef6c2013-08-29 13:02:54 -0700612**
613** Returns NFA_STATUS_OK if successfully initiated
614** NFA_STATUS_FAILED otherwise
615**
616*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800617tNFA_STATUS NFA_ResumeP2p(void) {
618 NFC_HDR* p_msg;
Evan Chu67aef6c2013-08-29 13:02:54 -0700619
Ruchi Kandoi6767aec2017-09-26 09:46:26 -0700620 DLOG_IF(INFO, nfc_debug_enabled) << __func__;
Evan Chu67aef6c2013-08-29 13:02:54 -0700621
Ruchi Kandoi0c515ae2017-01-30 17:48:41 -0800622 p_msg = (NFC_HDR*)GKI_getbuf(sizeof(NFC_HDR));
623 if (p_msg != NULL) {
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800624 p_msg->event = NFA_DM_API_RESUME_P2P_EVT;
Evan Chu67aef6c2013-08-29 13:02:54 -0700625
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800626 nfa_sys_sendmsg(p_msg);
Evan Chu67aef6c2013-08-29 13:02:54 -0700627
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800628 return (NFA_STATUS_OK);
629 }
Evan Chu67aef6c2013-08-29 13:02:54 -0700630
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800631 return (NFA_STATUS_FAILED);
Evan Chu67aef6c2013-08-29 13:02:54 -0700632}
633
634/*******************************************************************************
635**
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800636** Function NFA_SetP2pListenTech
637**
Ruchi Kandoi552f2b72017-01-28 16:22:55 -0800638** Description This function is called to set listen technology for
639** NFC-DEP. This funtion may be called before or after starting
640** any server on NFA P2P/CHO/SNEP.
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800641** If there is no technology for NFC-DEP, P2P listening will be
642** stopped.
643**
644** NFA_SET_P2P_LISTEN_TECH_EVT without data will be returned.
645**
Ruchi Kandoi552f2b72017-01-28 16:22:55 -0800646** Note: If RF discovery is started,
647** NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should
648** happen before calling this function
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800649**
650** Returns NFA_STATUS_OK if successfully initiated
651** NFA_STATUS_FAILED otherwise
652**
653*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800654tNFA_STATUS NFA_SetP2pListenTech(tNFA_TECHNOLOGY_MASK tech_mask) {
655 tNFA_DM_API_SET_P2P_LISTEN_TECH* p_msg;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800656
Ruchi Kandoi6767aec2017-09-26 09:46:26 -0700657 DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("tech_mask:0x%X", tech_mask);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800658
Ruchi Kandoi0c515ae2017-01-30 17:48:41 -0800659 p_msg = (tNFA_DM_API_SET_P2P_LISTEN_TECH*)GKI_getbuf(
660 sizeof(tNFA_DM_API_SET_P2P_LISTEN_TECH));
661 if (p_msg != NULL) {
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800662 p_msg->hdr.event = NFA_DM_API_SET_P2P_LISTEN_TECH_EVT;
663 p_msg->tech_mask = tech_mask;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800664
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800665 nfa_sys_sendmsg(p_msg);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800666
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800667 return (NFA_STATUS_OK);
668 }
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800669
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800670 return (NFA_STATUS_FAILED);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800671}
672
673/*******************************************************************************
674**
675** Function NFA_StartRfDiscovery
676**
677** Description Start RF discovery
678** RF discovery parameters shall be set by other APIs.
679**
Ruchi Kandoi552f2b72017-01-28 16:22:55 -0800680** An NFA_RF_DISCOVERY_STARTED_EVT indicates whether starting
681** was successful or not.
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800682**
683** Returns NFA_STATUS_OK if successfully initiated
684** NFA_STATUS_FAILED otherwise
685**
686*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800687tNFA_STATUS NFA_StartRfDiscovery(void) {
688 NFC_HDR* p_msg;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800689
Ruchi Kandoi6767aec2017-09-26 09:46:26 -0700690 DLOG_IF(INFO, nfc_debug_enabled) << __func__;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800691
Ruchi Kandoi0c515ae2017-01-30 17:48:41 -0800692 p_msg = (NFC_HDR*)GKI_getbuf(sizeof(NFC_HDR));
693 if (p_msg != NULL) {
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800694 p_msg->event = NFA_DM_API_START_RF_DISCOVERY_EVT;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800695
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800696 nfa_sys_sendmsg(p_msg);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800697
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800698 return (NFA_STATUS_OK);
699 }
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800700
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800701 return (NFA_STATUS_FAILED);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800702}
703
704/*******************************************************************************
705**
706** Function NFA_StopRfDiscovery
707**
708** Description Stop RF discovery
709**
Ruchi Kandoi552f2b72017-01-28 16:22:55 -0800710** An NFA_RF_DISCOVERY_STOPPED_EVT indicates whether stopping
711** was successful or not.
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800712**
713** Returns NFA_STATUS_OK if successfully initiated
714** NFA_STATUS_FAILED otherwise
715**
716*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800717tNFA_STATUS NFA_StopRfDiscovery(void) {
718 NFC_HDR* p_msg;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800719
Ruchi Kandoi6767aec2017-09-26 09:46:26 -0700720 DLOG_IF(INFO, nfc_debug_enabled) << __func__;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800721
Ruchi Kandoi0c515ae2017-01-30 17:48:41 -0800722 p_msg = (NFC_HDR*)GKI_getbuf(sizeof(NFC_HDR));
723 if (p_msg != NULL) {
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800724 p_msg->event = NFA_DM_API_STOP_RF_DISCOVERY_EVT;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800725
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800726 nfa_sys_sendmsg(p_msg);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800727
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800728 return (NFA_STATUS_OK);
729 }
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800730
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800731 return (NFA_STATUS_FAILED);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800732}
733
734/*******************************************************************************
735**
736** Function NFA_SetRfDiscoveryDuration
737**
738** Description Set the duration of the single discovery period in [ms].
739** Allowable range: 0 ms to 0xFFFF ms.
740**
741** If discovery is already started, the application should
742** call NFA_StopRfDiscovery prior to calling
743** NFA_SetRfDiscoveryDuration, and then call
744** NFA_StartRfDiscovery afterwards to restart discovery using
745** the new duration.
746**
Ruchi Kandoi552f2b72017-01-28 16:22:55 -0800747** Note: If RF discovery is started,
748** NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should
749** happen before calling this function
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800750**
751** Returns:
752** NFA_STATUS_OK, if command accepted
753** NFA_STATUS_FAILED: otherwise
754**
755*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800756tNFA_STATUS NFA_SetRfDiscoveryDuration(uint16_t discovery_period_ms) {
757 tNFA_DM_API_SET_RF_DISC_DUR* p_msg;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800758
Ruchi Kandoi6767aec2017-09-26 09:46:26 -0700759 DLOG_IF(INFO, nfc_debug_enabled) << __func__;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800760
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800761 /* Post the API message */
Love Khanna1d062772018-04-10 21:10:02 +0530762 p_msg = (tNFA_DM_API_SET_RF_DISC_DUR*)GKI_getbuf(sizeof(NFC_HDR));
Ruchi Kandoi0c515ae2017-01-30 17:48:41 -0800763 if (p_msg != NULL) {
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800764 p_msg->hdr.event = NFA_DM_API_SET_RF_DISC_DURATION_EVT;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800765
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800766 /* Set discovery duration */
767 p_msg->rf_disc_dur_ms = discovery_period_ms;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800768
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800769 nfa_sys_sendmsg(p_msg);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800770
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800771 return (NFA_STATUS_OK);
772 }
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800773
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800774 return (NFA_STATUS_FAILED);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800775}
776
777/*******************************************************************************
778**
779** Function NFA_Select
780**
781** Description Select one from detected devices during discovery
782** (from NFA_DISC_RESULT_EVTs). The application should wait for
783** the final NFA_DISC_RESULT_EVT before selecting.
784**
Ruchi Kandoi552f2b72017-01-28 16:22:55 -0800785** An NFA_SELECT_RESULT_EVT indicates whether selection was
786** successful or not. If failed then application must select
787** again or deactivate by NFA_Deactivate().
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800788**
789** Returns NFA_STATUS_OK if successfully initiated
Ruchi Kandoi552f2b72017-01-28 16:22:55 -0800790** NFA_STATUS_INVALID_PARAM if RF interface is not matched
791** protocol
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800792** NFA_STATUS_FAILED otherwise
793**
794*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800795tNFA_STATUS NFA_Select(uint8_t rf_disc_id, tNFA_NFC_PROTOCOL protocol,
796 tNFA_INTF_TYPE rf_interface) {
797 tNFA_DM_API_SELECT* p_msg;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800798
Ruchi Kandoi6767aec2017-09-26 09:46:26 -0700799 DLOG_IF(INFO, nfc_debug_enabled)
800 << StringPrintf("rf_disc_id:0x%X, protocol:0x%X, rf_interface:0x%X",
801 rf_disc_id, protocol, rf_interface);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800802
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800803 if (((rf_interface == NFA_INTERFACE_ISO_DEP) &&
804 (protocol != NFA_PROTOCOL_ISO_DEP)) ||
805 ((rf_interface == NFA_INTERFACE_NFC_DEP) &&
806 (protocol != NFA_PROTOCOL_NFC_DEP))) {
Ruchi Kandoi6767aec2017-09-26 09:46:26 -0700807 LOG(ERROR) << StringPrintf("RF interface is not matched protocol");
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800808 return (NFA_STATUS_INVALID_PARAM);
809 }
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800810
Ruchi Kandoi0c515ae2017-01-30 17:48:41 -0800811 p_msg =
812 (tNFA_DM_API_SELECT*)GKI_getbuf((uint16_t)(sizeof(tNFA_DM_API_SELECT)));
813 if (p_msg != NULL) {
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800814 p_msg->hdr.event = NFA_DM_API_SELECT_EVT;
815 p_msg->rf_disc_id = rf_disc_id;
816 p_msg->protocol = protocol;
817 p_msg->rf_interface = rf_interface;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800818
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800819 nfa_sys_sendmsg(p_msg);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800820
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800821 return (NFA_STATUS_OK);
822 }
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800823
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800824 return (NFA_STATUS_FAILED);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800825}
826
827/*******************************************************************************
828**
829** Function NFA_UpdateRFCommParams
830**
Ruchi Kandoi552f2b72017-01-28 16:22:55 -0800831** Description This function is called to update RF Communication
832** parameters once the Frame RF Interface has been activated.
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800833**
834** An NFA_UPDATE_RF_PARAM_RESULT_EVT indicates whether updating
835** was successful or not.
836**
837** Returns NFA_STATUS_OK if successfully initiated
838** NFA_STATUS_FAILED otherwise
839**
840*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800841tNFA_STATUS NFA_UpdateRFCommParams(tNFA_RF_COMM_PARAMS* p_params) {
842 tNFA_DM_API_UPDATE_RF_PARAMS* p_msg;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800843
Ruchi Kandoi6767aec2017-09-26 09:46:26 -0700844 DLOG_IF(INFO, nfc_debug_enabled) << __func__;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800845
Ruchi Kandoi0c515ae2017-01-30 17:48:41 -0800846 p_msg = (tNFA_DM_API_UPDATE_RF_PARAMS*)GKI_getbuf(
847 (uint16_t)(sizeof(tNFA_DM_API_UPDATE_RF_PARAMS)));
848 if (p_msg != NULL) {
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800849 p_msg->hdr.event = NFA_DM_API_UPDATE_RF_PARAMS_EVT;
850 memcpy(&p_msg->params, p_params, sizeof(tNFA_RF_COMM_PARAMS));
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800851
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800852 nfa_sys_sendmsg(p_msg);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800853
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800854 return (NFA_STATUS_OK);
855 }
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800856
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800857 return (NFA_STATUS_FAILED);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800858}
859
860/*******************************************************************************
861**
862** Function NFA_Deactivate
863**
864** Description
865** If sleep_mode=TRUE:
Ruchi Kandoi552f2b72017-01-28 16:22:55 -0800866** Deselect the activated device by deactivating into sleep
867** mode.
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800868**
Ruchi Kandoi552f2b72017-01-28 16:22:55 -0800869** An NFA_DEACTIVATE_FAIL_EVT indicates that selection was
870** not successful. Application can select another
871** discovered device or deactivate by NFA_Deactivate()
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800872** after receiving NFA_DEACTIVATED_EVT.
873**
Ruchi Kandoi552f2b72017-01-28 16:22:55 -0800874** Deactivating to sleep mode is not allowed when NFCC is
875** in wait-for-host-select mode, or in listen-sleep states;
876** NFA will deactivate to idle or discovery state for these
877** cases respectively.
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800878**
879**
880** If sleep_mode=FALSE:
Ruchi Kandoi552f2b72017-01-28 16:22:55 -0800881** Deactivate the connection (e.g. as a result of presence
882** check failure) NFA_DEACTIVATED_EVT will indicate that
883** link is deactivated. Polling/listening will resume
884** (unless the nfcc is in wait_for-all-discoveries state)
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800885**
886**
887** Returns NFA_STATUS_OK if successfully initiated
888** NFA_STATUS_FAILED otherwise
889**
890*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800891extern tNFA_STATUS NFA_Deactivate(bool sleep_mode) {
892 tNFA_DM_API_DEACTIVATE* p_msg;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800893
Ruchi Kandoi6767aec2017-09-26 09:46:26 -0700894 DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("sleep_mode:%i", sleep_mode);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800895
Ruchi Kandoi0c515ae2017-01-30 17:48:41 -0800896 p_msg = (tNFA_DM_API_DEACTIVATE*)GKI_getbuf(
897 (uint16_t)(sizeof(tNFA_DM_API_DEACTIVATE)));
898 if (p_msg != NULL) {
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800899 p_msg->hdr.event = NFA_DM_API_DEACTIVATE_EVT;
900 p_msg->sleep_mode = sleep_mode;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800901
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800902 nfa_sys_sendmsg(p_msg);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800903
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800904 return (NFA_STATUS_OK);
905 }
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800906
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800907 return (NFA_STATUS_FAILED);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800908}
909
910/*******************************************************************************
911**
912** Function NFA_SendRawFrame
913**
914** Description Send a raw frame over the activated interface with the NFCC.
Ruchi Kandoi552f2b72017-01-28 16:22:55 -0800915** This function can only be called after NFC link is
916** activated.
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800917**
Ruchi Kandoi552f2b72017-01-28 16:22:55 -0800918** If the activated interface is a tag and auto-presence check
919** is enabled then presence_check_start_delay can be used to
920** indicate the delay in msec after which the next auto
921** presence check command can be sent.
922** NFA_DM_DEFAULT_PRESENCE_CHECK_START_DELAY can be used as the
923** default value for the delay.
Martijn Coenen5c65c3a2013-03-27 13:23:36 -0700924**
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800925** Returns NFA_STATUS_OK if successfully initiated
926** NFA_STATUS_FAILED otherwise
927**
928*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800929tNFA_STATUS NFA_SendRawFrame(uint8_t* p_raw_data, uint16_t data_len,
930 uint16_t presence_check_start_delay) {
931 NFC_HDR* p_msg;
932 uint16_t size;
933 uint8_t* p;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800934
Ruchi Kandoi6767aec2017-09-26 09:46:26 -0700935 DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("data_len:%d", data_len);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800936
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800937 /* Validate parameters */
938 if ((data_len == 0) || (p_raw_data == NULL))
939 return (NFA_STATUS_INVALID_PARAM);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800940
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800941 size = NFC_HDR_SIZE + NCI_MSG_OFFSET_SIZE + NCI_DATA_HDR_SIZE + data_len;
Ruchi Kandoi0c515ae2017-01-30 17:48:41 -0800942 p_msg = (NFC_HDR*)GKI_getbuf(size);
943 if (p_msg != NULL) {
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800944 p_msg->event = NFA_DM_API_RAW_FRAME_EVT;
945 p_msg->layer_specific = presence_check_start_delay;
946 p_msg->offset = NCI_MSG_OFFSET_SIZE + NCI_DATA_HDR_SIZE;
947 p_msg->len = data_len;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800948
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800949 p = (uint8_t*)(p_msg + 1) + p_msg->offset;
950 memcpy(p, p_raw_data, data_len);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800951
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800952 nfa_sys_sendmsg(p_msg);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800953
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800954 return (NFA_STATUS_OK);
955 }
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800956
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800957 return (NFA_STATUS_FAILED);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800958}
959
960/*******************************************************************************
961** NDEF Handler APIs
962*******************************************************************************/
963
964/*******************************************************************************
965**
966** Function NFA_RegisterNDefTypeHandler
967**
968** Description This function allows the applications to register for
969** specific types of NDEF records. When NDEF records are
970** received, NFA will parse the record-type field, and pass
971** the record to the registered tNFA_NDEF_CBACK.
972**
973** For records types which were not registered, the record will
974** be sent to the default handler. A default type-handler may
975** be registered by calling this NFA_RegisterNDefTypeHandler
976** with tnf=NFA_TNF_DEFAULT. In this case, all un-registered
977** record types will be sent to the callback. Only one default
978** handler may be registered at a time.
979**
980** An NFA_NDEF_REGISTER_EVT will be sent to the tNFA_NDEF_CBACK
981** to indicate that registration was successful, and provide a
982** handle for this record type.
983**
984** Returns NFA_STATUS_OK if successfully initiated
985** NFA_STATUS_FAILED otherwise
986**
987*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800988tNFA_STATUS NFA_RegisterNDefTypeHandler(bool handle_whole_message, tNFA_TNF tnf,
989 uint8_t* p_type_name,
990 uint8_t type_name_len,
991 tNFA_NDEF_CBACK* p_ndef_cback) {
992 tNFA_DM_API_REG_NDEF_HDLR* p_msg;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800993
Ruchi Kandoi6767aec2017-09-26 09:46:26 -0700994 DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf(
995 "handle whole ndef message: %i, "
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800996 "tnf=0x%02x",
997 handle_whole_message, tnf);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -0800998
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -0800999 /* Check for NULL callback */
1000 if (!p_ndef_cback) {
Ruchi Kandoi6767aec2017-09-26 09:46:26 -07001001 LOG(ERROR) << StringPrintf("error - null callback");
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001002 return (NFA_STATUS_INVALID_PARAM);
1003 }
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001004
Ruchi Kandoi0c515ae2017-01-30 17:48:41 -08001005 p_msg = (tNFA_DM_API_REG_NDEF_HDLR*)GKI_getbuf(
1006 (uint16_t)(sizeof(tNFA_DM_API_REG_NDEF_HDLR) + type_name_len));
1007 if (p_msg != NULL) {
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001008 p_msg->hdr.event = NFA_DM_API_REG_NDEF_HDLR_EVT;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001009
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001010 p_msg->flags =
1011 (handle_whole_message ? NFA_NDEF_FLAGS_HANDLE_WHOLE_MESSAGE : 0);
1012 p_msg->tnf = tnf;
1013 p_msg->name_len = type_name_len;
1014 p_msg->p_ndef_cback = p_ndef_cback;
1015 memcpy(p_msg->name, p_type_name, type_name_len);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001016
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001017 nfa_sys_sendmsg(p_msg);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001018
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001019 return (NFA_STATUS_OK);
1020 }
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001021
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001022 return (NFA_STATUS_FAILED);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001023}
1024
1025/*******************************************************************************
1026**
1027** Function NFA_RegisterNDefUriHandler
1028**
1029** Description This API is a special-case of NFA_RegisterNDefTypeHandler
Ruchi Kandoi552f2b72017-01-28 16:22:55 -08001030** with TNF=NFA_TNF_WKT, and type_name='U' (URI record); and
1031** allows registering for specific URI types (e.g. 'tel:' or
1032** 'mailto:').
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001033**
1034** An NFA_NDEF_REGISTER_EVT will be sent to the tNFA_NDEF_CBACK
1035** to indicate that registration was successful, and provide a
1036** handle for this registration.
1037**
Ruchi Kandoi552f2b72017-01-28 16:22:55 -08001038** If uri_id=NFA_NDEF_URI_ID_ABSOLUTE, then p_abs_uri contains
1039** the unabridged URI. For all other uri_id values,
1040** the p_abs_uri parameter is ignored (i.e the URI prefix is
1041** implied by uri_id). See [NFC RTD URI] for more information.
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001042**
1043** Returns NFA_STATUS_OK if successfully initiated
1044** NFA_STATUS_FAILED otherwise
1045**
1046*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001047extern tNFA_STATUS NFA_RegisterNDefUriHandler(bool handle_whole_message,
1048 tNFA_NDEF_URI_ID uri_id,
1049 uint8_t* p_abs_uri,
1050 uint8_t uri_id_len,
1051 tNFA_NDEF_CBACK* p_ndef_cback) {
1052 tNFA_DM_API_REG_NDEF_HDLR* p_msg;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001053
Ruchi Kandoi6767aec2017-09-26 09:46:26 -07001054 DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf(
1055 "handle whole ndef message: %i, "
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001056 "uri_id=0x%02x",
1057 handle_whole_message, uri_id);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001058
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001059 /* Check for NULL callback */
1060 if (!p_ndef_cback) {
Ruchi Kandoi6767aec2017-09-26 09:46:26 -07001061 LOG(ERROR) << StringPrintf("error - null callback");
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001062 return (NFA_STATUS_INVALID_PARAM);
1063 }
1064
Ruchi Kandoi0c515ae2017-01-30 17:48:41 -08001065 p_msg = (tNFA_DM_API_REG_NDEF_HDLR*)GKI_getbuf(
1066 (uint16_t)(sizeof(tNFA_DM_API_REG_NDEF_HDLR) + uri_id_len));
1067 if (p_msg != NULL) {
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001068 p_msg->hdr.event = NFA_DM_API_REG_NDEF_HDLR_EVT;
1069
1070 p_msg->flags = NFA_NDEF_FLAGS_WKT_URI;
1071
1072 if (handle_whole_message) {
1073 p_msg->flags |= NFA_NDEF_FLAGS_HANDLE_WHOLE_MESSAGE;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001074 }
1075
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001076 /* abs_uri is only valid fir uri_id=NFA_NDEF_URI_ID_ABSOLUTE */
1077 if (uri_id != NFA_NDEF_URI_ID_ABSOLUTE) {
1078 uri_id_len = 0;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001079 }
1080
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001081 p_msg->tnf = NFA_TNF_WKT;
1082 p_msg->uri_id = uri_id;
1083 p_msg->name_len = uri_id_len;
1084 p_msg->p_ndef_cback = p_ndef_cback;
1085 memcpy(p_msg->name, p_abs_uri, uri_id_len);
1086
1087 nfa_sys_sendmsg(p_msg);
1088
1089 return (NFA_STATUS_OK);
1090 }
1091
1092 return (NFA_STATUS_FAILED);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001093}
1094
1095/*******************************************************************************
1096**
1097** Function NFA_DeregisterNDefTypeHandler
1098**
1099** Description Deregister NDEF record type handler.
1100**
1101** Returns NFA_STATUS_OK if successfully initiated
1102** NFA_STATUS_FAILED otherwise
1103**
1104*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001105extern tNFA_STATUS NFA_DeregisterNDefTypeHandler(tNFA_HANDLE ndef_type_handle) {
1106 tNFA_DM_API_DEREG_NDEF_HDLR* p_msg;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001107
Ruchi Kandoi6767aec2017-09-26 09:46:26 -07001108 DLOG_IF(INFO, nfc_debug_enabled)
1109 << StringPrintf("handle 0x%08x", ndef_type_handle);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001110
Ruchi Kandoi0c515ae2017-01-30 17:48:41 -08001111 p_msg = (tNFA_DM_API_DEREG_NDEF_HDLR*)GKI_getbuf(
1112 (uint16_t)(sizeof(tNFA_DM_API_DEREG_NDEF_HDLR)));
1113 if (p_msg != NULL) {
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001114 p_msg->hdr.event = NFA_DM_API_DEREG_NDEF_HDLR_EVT;
1115 p_msg->ndef_type_handle = ndef_type_handle;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001116
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001117 nfa_sys_sendmsg(p_msg);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001118
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001119 return (NFA_STATUS_OK);
1120 }
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001121
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001122 return (NFA_STATUS_FAILED);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001123}
1124
1125/*******************************************************************************
1126**
1127** Function NFA_PowerOffSleepMode
1128**
Ruchi Kandoi552f2b72017-01-28 16:22:55 -08001129** Description This function is called to enter or leave NFCC Power Off
1130** Sleep mode NFA_DM_PWR_MODE_CHANGE_EVT will be sent to
1131** indicate status.
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001132**
1133** start_stop : TRUE if entering Power Off Sleep mode
1134** FALSE if leaving Power Off Sleep mode
1135**
1136** Returns NFA_STATUS_OK if successfully initiated
1137** NFA_STATUS_FAILED otherwise
1138**
1139*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001140tNFA_STATUS NFA_PowerOffSleepMode(bool start_stop) {
1141 NFC_HDR* p_msg;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001142
Ruchi Kandoi6767aec2017-09-26 09:46:26 -07001143 DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("start_stop=%d", start_stop);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001144
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001145 if (nfa_dm_cb.flags & NFA_DM_FLAGS_SETTING_PWR_MODE) {
Ruchi Kandoi6767aec2017-09-26 09:46:26 -07001146 LOG(ERROR) << StringPrintf("NFA DM is busy to update power mode");
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001147 return (NFA_STATUS_FAILED);
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001148 } else {
1149 nfa_dm_cb.flags |= NFA_DM_FLAGS_SETTING_PWR_MODE;
1150 }
1151
Ruchi Kandoi0c515ae2017-01-30 17:48:41 -08001152 p_msg = (NFC_HDR*)GKI_getbuf(sizeof(NFC_HDR));
1153 if (p_msg != NULL) {
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001154 p_msg->event = NFA_DM_API_POWER_OFF_SLEEP_EVT;
1155 p_msg->layer_specific = start_stop;
1156
1157 nfa_sys_sendmsg(p_msg);
1158
1159 return (NFA_STATUS_OK);
1160 }
1161
1162 return (NFA_STATUS_FAILED);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001163}
1164
1165/*******************************************************************************
1166**
1167** Function NFA_RegVSCback
1168**
Ruchi Kandoi552f2b72017-01-28 16:22:55 -08001169** Description This function is called to register or de-register a
1170** callback function to receive Proprietary NCI response and
1171** notification events. The maximum number of callback
1172** functions allowed is NFC_NUM_VS_CBACKS
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001173**
1174** Returns tNFC_STATUS
1175**
1176*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001177tNFC_STATUS NFA_RegVSCback(bool is_register, tNFA_VSC_CBACK* p_cback) {
1178 tNFA_DM_API_REG_VSC* p_msg;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001179
Ruchi Kandoi6767aec2017-09-26 09:46:26 -07001180 DLOG_IF(INFO, nfc_debug_enabled)
1181 << StringPrintf("is_register=%d", is_register);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001182
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001183 if (p_cback == NULL) {
Ruchi Kandoi6767aec2017-09-26 09:46:26 -07001184 LOG(ERROR) << StringPrintf("requires a valid callback function");
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001185 return (NFA_STATUS_FAILED);
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001186 }
1187
Ruchi Kandoi0c515ae2017-01-30 17:48:41 -08001188 p_msg = (tNFA_DM_API_REG_VSC*)GKI_getbuf(sizeof(tNFA_DM_API_REG_VSC));
1189 if (p_msg != NULL) {
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001190 p_msg->hdr.event = NFA_DM_API_REG_VSC_EVT;
1191 p_msg->is_register = is_register;
1192 p_msg->p_cback = p_cback;
1193
1194 nfa_sys_sendmsg(p_msg);
1195
1196 return (NFA_STATUS_OK);
1197 }
1198
1199 return (NFA_STATUS_FAILED);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001200}
1201
1202/*******************************************************************************
1203**
1204** Function NFA_SendVsCommand
1205**
1206** Description This function is called to send an NCI Vendor Specific
1207** command to NFCC.
1208**
1209** oid - The opcode of the VS command.
1210** cmd_params_len - The command parameter len
1211** p_cmd_params - The command parameter
Ruchi Kandoi552f2b72017-01-28 16:22:55 -08001212** p_cback - The callback function to receive the
1213** command status
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001214**
1215** Returns NFA_STATUS_OK if successfully initiated
1216** NFA_STATUS_FAILED otherwise
1217**
1218*******************************************************************************/
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001219tNFA_STATUS NFA_SendVsCommand(uint8_t oid, uint8_t cmd_params_len,
1220 uint8_t* p_cmd_params, tNFA_VSC_CBACK* p_cback) {
1221 tNFA_DM_API_SEND_VSC* p_msg;
1222 uint16_t size = sizeof(tNFA_DM_API_SEND_VSC) + cmd_params_len;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001223
Ruchi Kandoi6767aec2017-09-26 09:46:26 -07001224 DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("oid=0x%x", oid);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001225
Ruchi Kandoi0c515ae2017-01-30 17:48:41 -08001226 p_msg = (tNFA_DM_API_SEND_VSC*)GKI_getbuf(size);
1227 if (p_msg != NULL) {
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001228 p_msg->hdr.event = NFA_DM_API_SEND_VSC_EVT;
1229 p_msg->oid = oid;
1230 p_msg->p_cback = p_cback;
1231 if (cmd_params_len && p_cmd_params) {
1232 p_msg->cmd_params_len = cmd_params_len;
1233 p_msg->p_cmd_params = (uint8_t*)(p_msg + 1);
1234 memcpy(p_msg->p_cmd_params, p_cmd_params, cmd_params_len);
1235 } else {
1236 p_msg->cmd_params_len = 0;
1237 p_msg->p_cmd_params = NULL;
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001238 }
1239
Ruchi Kandoi6fca02d2017-01-30 14:28:16 -08001240 nfa_sys_sendmsg(p_msg);
1241
1242 return (NFA_STATUS_OK);
1243 }
1244
1245 return (NFA_STATUS_FAILED);
The Android Open Source Projecte9df6ba2012-12-13 14:55:37 -08001246}
1247
1248/*******************************************************************************
1249**
Love Khannad7852c92017-06-02 19:55:05 +05301250** Function NFA_SendRawVsCommand
1251**
1252** Description This function is called to send raw Vendor Specific
1253** command to NFCC.
1254**
1255** cmd_params_len - The command parameter len
1256** p_cmd_params - The command parameter
1257** p_cback - The callback function to receive the
1258** command
1259**
1260** Returns NFA_STATUS_OK if successfully initiated
1261** NFA_STATUS_FAILED otherwise
1262**
1263*******************************************************************************/
1264tNFA_STATUS NFA_SendRawVsCommand(uint8_t cmd_params_len, uint8_t* p_cmd_params,
1265 tNFA_VSC_CBACK* p_cback) {
1266 if (cmd_params_len == 0x00 || p_cmd_params == NULL || p_cback == NULL) {
1267 return NFA_STATUS_INVALID_PARAM;
1268 }
1269 uint16_t size = sizeof(tNFA_DM_API_SEND_VSC) + cmd_params_len;
1270 tNFA_DM_API_SEND_VSC* p_msg = (tNFA_DM_API_SEND_VSC*)GKI_getbuf(size);
1271
1272 if (p_msg != NULL) {
1273 p_msg->hdr.event = NFA_DM_API_SEND_RAW_VS_EVT;
1274 p_msg->p_cback = p_cback;
1275 if (cmd_params_len && p_cmd_params) {
1276 p_msg->cmd_params_len = cmd_params_len;
1277 p_msg->p_cmd_params = (uint8_t*)(p_msg + 1);
1278 memcpy(p_msg->p_cmd_params, p_cmd_params, cmd_params_len);
1279 } else {
1280 p_msg->cmd_params_len = 0;
1281 p_msg->p_cmd_params = NULL;
1282 }
1283
1284 nfa_sys_sendmsg(p_msg);
1285
1286 return NFA_STATUS_OK;
1287 }
1288
1289 return NFA_STATUS_FAILED;
1290}
1291
1292/*******************************************************************************
1293**
Love Khannad7852c92017-06-02 19:55:05 +05301294** Function: NFA_EnableDtamode
1295**
1296** Description: Enable DTA Mode
1297**
1298** Returns: none:
1299**
1300*******************************************************************************/
1301void NFA_EnableDtamode(tNFA_eDtaModes eDtaMode) {
Ruchi Kandoi6767aec2017-09-26 09:46:26 -07001302 DLOG_IF(INFO, nfc_debug_enabled)
1303 << StringPrintf("%s: 0x%x ", __func__, eDtaMode);
Love Khannad7852c92017-06-02 19:55:05 +05301304 appl_dta_mode_flag = 0x01;
1305 nfa_dm_cb.eDtaMode = eDtaMode;
1306}