blob: d3e3062ed3218f5ed76b0ba2041bb709a2c67174 [file] [log] [blame]
nxpandroidc7611652015-09-23 16:42:05 +05301/******************************************************************************
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 *
nxf24591c1cbeab2018-02-21 17:32:26 +053020 * The original Work has been changed by NXP.
nxpandroidc7611652015-09-23 16:42:05 +053021 *
22 * Licensed under the Apache License, Version 2.0 (the "License");
23 * you may not use this file except in compliance with the License.
24 * You may obtain a copy of the License at
25 *
26 * http://www.apache.org/licenses/LICENSE-2.0
27 *
28 * Unless required by applicable law or agreed to in writing, software
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
33 *
nxf24591c1cbeab2018-02-21 17:32:26 +053034 * Copyright 2018 NXP
35 *
nxpandroidc7611652015-09-23 16:42:05 +053036 ******************************************************************************/
nxpandroidc7611652015-09-23 16:42:05 +053037/******************************************************************************
38 *
39 * NFA interface to NFCEE - API functions
40 *
41 ******************************************************************************/
nxf24591c1cbeab2018-02-21 17:32:26 +053042#include <android-base/stringprintf.h>
43#include <base/logging.h>
44
nxpandroidc7611652015-09-23 16:42:05 +053045#include "nfa_dm_int.h"
Suraj Uday Kotharkar6f7757b2018-05-10 15:58:29 +053046#include "nfa_ee_api.h"
nxf24591c1cbeab2018-02-21 17:32:26 +053047#include "nfa_ee_int.h"
Suraj Uday Kotharkar6f7757b2018-05-10 15:58:29 +053048#include "nfc_int.h"
nxf24591c1cbeab2018-02-21 17:32:26 +053049
50using android::base::StringPrintf;
51
52extern bool nfc_debug_enabled;
nxpandroidc7611652015-09-23 16:42:05 +053053
54/*****************************************************************************
55** APIs
56*****************************************************************************/
57/*******************************************************************************
58**
59** Function NFA_EeDiscover
60**
61** Description This function retrieves the NFCEE information from NFCC.
62** The NFCEE information is reported in NFA_EE_DISCOVER_EVT.
63**
64** This function may be called when a system supports removable
65** NFCEEs,
66**
67** Returns NFA_STATUS_OK if information is retrieved successfully
68** NFA_STATUS_FAILED If wrong state (retry later)
69** NFA_STATUS_INVALID_PARAM If bad parameter
70**
71*******************************************************************************/
nxpandroid8f6d0532017-07-12 18:25:30 +053072tNFA_STATUS NFA_EeDiscover(tNFA_EE_CBACK* p_cback) {
73 tNFA_EE_API_DISCOVER* p_msg;
74 tNFA_STATUS status = NFA_STATUS_FAILED;
nxpandroidc7611652015-09-23 16:42:05 +053075
nxf24591c1cbeab2018-02-21 17:32:26 +053076 DLOG_IF(INFO, nfc_debug_enabled) << __func__;
nxpandroidc7611652015-09-23 16:42:05 +053077
nxpandroid8f6d0532017-07-12 18:25:30 +053078 if (nfa_ee_cb.em_state != NFA_EE_EM_STATE_INIT_DONE) {
nxf24591c1cbeab2018-02-21 17:32:26 +053079 LOG(ERROR) << StringPrintf("NFA_EeDiscover bad em state: %d",
80 nfa_ee_cb.em_state);
nxpandroid8f6d0532017-07-12 18:25:30 +053081 status = NFA_STATUS_FAILED;
82 } else if ((nfa_ee_cb.p_ee_disc_cback != NULL) || (p_cback == NULL)) {
nxf24591c1cbeab2018-02-21 17:32:26 +053083 LOG(ERROR) << StringPrintf("in progress or NULL callback function");
nxpandroid8f6d0532017-07-12 18:25:30 +053084 status = NFA_STATUS_INVALID_PARAM;
85 } else {
86 p_msg = (tNFA_EE_API_DISCOVER*)GKI_getbuf(sizeof(tNFA_EE_API_DISCOVER));
87 if (p_msg != NULL) {
88 p_msg->hdr.event = NFA_EE_API_DISCOVER_EVT;
89 p_msg->p_cback = p_cback;
90
91 nfa_sys_sendmsg(p_msg);
92
93 status = NFA_STATUS_OK;
nxpandroidc7611652015-09-23 16:42:05 +053094 }
nxpandroid8f6d0532017-07-12 18:25:30 +053095 }
nxpandroidc7611652015-09-23 16:42:05 +053096
nxpandroid8f6d0532017-07-12 18:25:30 +053097 return status;
nxpandroidc7611652015-09-23 16:42:05 +053098}
99
100/*******************************************************************************
101**
102** Function NFA_EeGetInfo
103**
104** Description This function retrieves the NFCEE information from NFA.
105** The actual number of NFCEE is returned in p_num_nfcee
106** and NFCEE information is returned in p_info
107**
108** Returns NFA_STATUS_OK if information is retrieved successfully
109** NFA_STATUS_FAILED If wrong state (retry later)
110** NFA_STATUS_INVALID_PARAM If bad parameter
111**
112*******************************************************************************/
nxpandroid8f6d0532017-07-12 18:25:30 +0530113tNFA_STATUS NFA_EeGetInfo(uint8_t* p_num_nfcee, tNFA_EE_INFO* p_info) {
114 int xx, ret = nfa_ee_cb.cur_ee;
115 tNFA_EE_ECB* p_cb = nfa_ee_cb.ecb;
116 uint8_t max_ret;
117 uint8_t num_ret = 0;
nxpandroidc7611652015-09-23 16:42:05 +0530118
nxf24591c1cbeab2018-02-21 17:32:26 +0530119 DLOG_IF(INFO, nfc_debug_enabled)
120 << StringPrintf("NFA_EeGetInfo em_state:%d cur_ee:%d", nfa_ee_cb.em_state,
121 nfa_ee_cb.cur_ee);
nxpandroid8f6d0532017-07-12 18:25:30 +0530122 /* validate parameters */
123 if (p_info == NULL || p_num_nfcee == NULL) {
nxf24591c1cbeab2018-02-21 17:32:26 +0530124 LOG(ERROR) << StringPrintf("NFA_EeGetInfo bad parameter");
nxpandroid8f6d0532017-07-12 18:25:30 +0530125 return (NFA_STATUS_INVALID_PARAM);
126 }
127 max_ret = *p_num_nfcee;
128 *p_num_nfcee = 0;
129 if (nfa_ee_cb.em_state == NFA_EE_EM_STATE_INIT) {
nxf24591c1cbeab2018-02-21 17:32:26 +0530130 LOG(ERROR) << StringPrintf("NFA_EeGetInfo bad em state: %d",
131 nfa_ee_cb.em_state);
nxpandroid8f6d0532017-07-12 18:25:30 +0530132 return (NFA_STATUS_FAILED);
133 }
134
135 /* compose output */
136 for (xx = 0; (xx < ret) && (num_ret < max_ret); xx++, p_cb++) {
nxf24591c1cbeab2018-02-21 17:32:26 +0530137 DLOG_IF(INFO, nfc_debug_enabled)
138 << StringPrintf("xx:%d max_ret:%d, num_ret:%d ee_status:0x%x", xx,
139 max_ret, num_ret, p_cb->ee_status);
nxpandroid8f6d0532017-07-12 18:25:30 +0530140 if ((p_cb->ee_status & NFA_EE_STATUS_INT_MASK) ||
141 (p_cb->ee_status == NFA_EE_STATUS_REMOVED)) {
142 continue;
nxpandroidc7611652015-09-23 16:42:05 +0530143 }
nxpandroid8f6d0532017-07-12 18:25:30 +0530144 p_info->ee_handle = NFA_HANDLE_GROUP_EE | (tNFA_HANDLE)p_cb->nfcee_id;
145 p_info->ee_status = p_cb->ee_status;
146 p_info->num_interface = p_cb->num_interface;
147 p_info->num_tlvs = p_cb->num_tlvs;
nxpandroidc7611652015-09-23 16:42:05 +0530148
nxpandroid8f6d0532017-07-12 18:25:30 +0530149#if (NXP_EXTNS == TRUE)
150 p_info->la_protocol = p_cb->la_protocol;
151 p_info->lb_protocol = p_cb->lb_protocol;
152 p_info->lf_protocol = p_cb->lf_protocol;
153 p_info->lbp_protocol = p_cb->lbp_protocol;
nxpandroidc7611652015-09-23 16:42:05 +0530154#endif
nxpandroid8f6d0532017-07-12 18:25:30 +0530155 memcpy(p_info->ee_interface, p_cb->ee_interface, p_cb->num_interface);
156 memcpy(p_info->ee_tlv, p_cb->ee_tlv, p_cb->num_tlvs * sizeof(tNFA_EE_TLV));
nxf24591c1cbeab2018-02-21 17:32:26 +0530157 p_info->ee_power_supply_status = p_cb->ee_power_supply_status;
nxpandroid8f6d0532017-07-12 18:25:30 +0530158 p_info++;
159 num_ret++;
160 }
nxf24591c1cbeab2018-02-21 17:32:26 +0530161 DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("num_ret:%d", num_ret);
nxpandroid8f6d0532017-07-12 18:25:30 +0530162 *p_num_nfcee = num_ret;
163 return (NFA_STATUS_OK);
nxpandroidc7611652015-09-23 16:42:05 +0530164}
nxpandroid8f6d0532017-07-12 18:25:30 +0530165#if (NXP_EXTNS == TRUE)
nxpandroidc7611652015-09-23 16:42:05 +0530166/*******************************************************************************
167**
168** Function NFA_AllEeGetInfo
169**
170** Description This function retrieves the NFCEE information from NFA.
171** The actual number of NFCEE independent of their status
172** is returned in p_num_nfcee and NFCEE information is returned
173** in p_info
174**
175** Returns NFA_STATUS_OK if information is retrieved successfully
176** NFA_STATUS_FAILED If wrong state (retry later)
177** NFA_STATUS_INVALID_PARAM If bad parameter
178**
179*******************************************************************************/
nxpandroid8f6d0532017-07-12 18:25:30 +0530180tNFA_STATUS NFA_AllEeGetInfo(uint8_t* p_num_nfcee, tNFA_EE_INFO* p_info) {
181 int xx, ret = nfa_ee_cb.cur_ee;
182 tNFA_EE_ECB* p_cb = nfa_ee_cb.ecb;
183 uint8_t max_ret;
184 uint8_t num_ret = 0;
nxpandroidc7611652015-09-23 16:42:05 +0530185
nxf24591c1cbeab2018-02-21 17:32:26 +0530186 DLOG_IF(INFO, nfc_debug_enabled)
187 << StringPrintf("NFA_AllEeGetInfo em_state:%d cur_ee:%d", nfa_ee_cb.em_state,
nxpandroid8f6d0532017-07-12 18:25:30 +0530188 nfa_ee_cb.cur_ee);
189 /* validate parameters */
190 if (p_info == NULL || p_num_nfcee == NULL) {
nxf24591c1cbeab2018-02-21 17:32:26 +0530191 LOG(ERROR) << StringPrintf("NFA_AllEeGetInfo bad parameter");
nxpandroid8f6d0532017-07-12 18:25:30 +0530192 return (NFA_STATUS_INVALID_PARAM);
193 }
194 max_ret = *p_num_nfcee;
195 *p_num_nfcee = 0;
196 if (nfa_ee_cb.em_state == NFA_EE_EM_STATE_INIT) {
nxf24591c1cbeab2018-02-21 17:32:26 +0530197 LOG(ERROR) << StringPrintf("NFA_AllEeGetInfo bad em state: %d", nfa_ee_cb.em_state);
nxpandroid8f6d0532017-07-12 18:25:30 +0530198 return (NFA_STATUS_FAILED);
199 }
200
201 /* compose output */
202 for (xx = 0; (xx < ret) && (num_ret < max_ret); xx++, p_cb++) {
nxf24591c1cbeab2018-02-21 17:32:26 +0530203 DLOG_IF(INFO, nfc_debug_enabled)
204 << StringPrintf("xx:%d max_ret:%d, num_ret:%d ee_status:0x%x num_interface :%d p_cb->nfcee_id : %d", xx, max_ret,
nxpandroid8f6d0532017-07-12 18:25:30 +0530205 num_ret, p_cb->ee_status, p_cb->num_interface, p_cb->nfcee_id);
206 if (p_cb->ee_status & NFA_EE_STATUS_INT_MASK) {
207 continue;
nxpandroidc7611652015-09-23 16:42:05 +0530208 }
nxpandroid8f6d0532017-07-12 18:25:30 +0530209 p_info->ee_handle = NFA_HANDLE_GROUP_EE | (tNFA_HANDLE)p_cb->nfcee_id;
210 p_info->ee_status = p_cb->ee_status;
211 p_info->num_interface = p_cb->num_interface;
212 p_info->num_tlvs = p_cb->num_tlvs;
nxpandroidc7611652015-09-23 16:42:05 +0530213
nxpandroid8f6d0532017-07-12 18:25:30 +0530214 p_info->la_protocol = p_cb->la_protocol;
215 p_info->lb_protocol = p_cb->lb_protocol;
216 p_info->lf_protocol = p_cb->lf_protocol;
217 p_info->lbp_protocol = p_cb->lbp_protocol;
nxpandroidc7611652015-09-23 16:42:05 +0530218
nxpandroid8f6d0532017-07-12 18:25:30 +0530219 memcpy(p_info->ee_interface, p_cb->ee_interface, p_cb->num_interface);
nxpandroid6154b732016-01-14 20:39:23 +0530220
nxpandroid8f6d0532017-07-12 18:25:30 +0530221 memcpy(p_info->ee_tlv, p_cb->ee_tlv, p_cb->num_tlvs * sizeof(tNFA_EE_TLV));
222 p_info++;
223 num_ret++;
224 }
nxf24591c1cbeab2018-02-21 17:32:26 +0530225 DLOG_IF(INFO, nfc_debug_enabled)
226 << StringPrintf("num_ret:%d", num_ret);
nxpandroid8f6d0532017-07-12 18:25:30 +0530227 *p_num_nfcee = num_ret;
228 return (NFA_STATUS_OK);
nxpandroidc7611652015-09-23 16:42:05 +0530229}
230#endif
nxpandroidc7611652015-09-23 16:42:05 +0530231/*******************************************************************************
232**
233** Function NFA_EeRegister
234**
235** Description This function registers a callback function to receive the
236** events from NFA-EE module.
237**
238** Returns NFA_STATUS_OK if successfully initiated
239** NFA_STATUS_FAILED otherwise
240** NFA_STATUS_INVALID_PARAM If bad parameter
241**
242*******************************************************************************/
nxpandroid8f6d0532017-07-12 18:25:30 +0530243tNFA_STATUS NFA_EeRegister(tNFA_EE_CBACK* p_cback) {
244 tNFA_EE_API_REGISTER* p_msg;
245 tNFA_STATUS status = NFA_STATUS_FAILED;
nxpandroidc7611652015-09-23 16:42:05 +0530246
nxf24591c1cbeab2018-02-21 17:32:26 +0530247 DLOG_IF(INFO, nfc_debug_enabled) << __func__;
nxpandroidc7611652015-09-23 16:42:05 +0530248
nxpandroid8f6d0532017-07-12 18:25:30 +0530249 if (p_cback == NULL) {
nxf24591c1cbeab2018-02-21 17:32:26 +0530250 LOG(ERROR) << StringPrintf("with NULL callback function");
nxpandroid8f6d0532017-07-12 18:25:30 +0530251 status = NFA_STATUS_INVALID_PARAM;
252 } else {
253 p_msg = (tNFA_EE_API_REGISTER*)GKI_getbuf(sizeof(tNFA_EE_API_REGISTER));
254 if (p_msg != NULL) {
255 p_msg->hdr.event = NFA_EE_API_REGISTER_EVT;
256 p_msg->p_cback = p_cback;
257
258 nfa_sys_sendmsg(p_msg);
259
260 status = NFA_STATUS_OK;
nxpandroidc7611652015-09-23 16:42:05 +0530261 }
nxpandroid8f6d0532017-07-12 18:25:30 +0530262 }
nxpandroidc7611652015-09-23 16:42:05 +0530263
nxpandroid8f6d0532017-07-12 18:25:30 +0530264 return status;
nxpandroidc7611652015-09-23 16:42:05 +0530265}
266
267/*******************************************************************************
268**
269** Function NFA_EeDeregister
270**
271** Description This function de-registers the callback function
272**
273** Returns NFA_STATUS_OK if successfully initiated
274** NFA_STATUS_FAILED otherwise
275** NFA_STATUS_INVALID_PARAM If bad parameter
276**
277*******************************************************************************/
nxpandroid8f6d0532017-07-12 18:25:30 +0530278tNFA_STATUS NFA_EeDeregister(tNFA_EE_CBACK* p_cback) {
279 tNFA_EE_API_DEREGISTER* p_msg;
280 tNFA_STATUS status = NFA_STATUS_INVALID_PARAM;
281 int index = NFA_EE_MAX_CBACKS;
282 int xx;
nxpandroidc7611652015-09-23 16:42:05 +0530283
nxpandroid8f6d0532017-07-12 18:25:30 +0530284 for (xx = 0; xx < NFA_EE_MAX_CBACKS; xx++) {
285 if (nfa_ee_cb.p_ee_cback[xx] == p_cback) {
286 index = xx;
287 status = NFA_STATUS_FAILED;
288 break;
nxpandroidc7611652015-09-23 16:42:05 +0530289 }
nxpandroid8f6d0532017-07-12 18:25:30 +0530290 }
nxpandroidc7611652015-09-23 16:42:05 +0530291
nxf24591c1cbeab2018-02-21 17:32:26 +0530292 DLOG_IF(INFO, nfc_debug_enabled)
293 << StringPrintf("%d, status:%d", index, status);
nxpandroid8f6d0532017-07-12 18:25:30 +0530294 if ((status != NFA_STATUS_INVALID_PARAM) &&
295 (p_msg = (tNFA_EE_API_DEREGISTER*)GKI_getbuf(
296 sizeof(tNFA_EE_API_DEREGISTER))) != NULL) {
297 p_msg->hdr.event = NFA_EE_API_DEREGISTER_EVT;
298 p_msg->index = index;
nxpandroidc7611652015-09-23 16:42:05 +0530299
nxpandroid8f6d0532017-07-12 18:25:30 +0530300 nfa_sys_sendmsg(p_msg);
nxpandroidc7611652015-09-23 16:42:05 +0530301
nxpandroid8f6d0532017-07-12 18:25:30 +0530302 status = NFA_STATUS_OK;
303 }
nxpandroidc7611652015-09-23 16:42:05 +0530304
nxpandroid8f6d0532017-07-12 18:25:30 +0530305 return status;
nxpandroidc7611652015-09-23 16:42:05 +0530306}
nxf24591c1cbeab2018-02-21 17:32:26 +0530307#if (NXP_EXTNS == TRUE)
nxpandroidfb160962017-09-13 16:09:09 +0530308/*******************************************************************************
309**
310** Function NFA_SendPowerLinkCommand
311**
312** Description This function is called to send an NCI Vendor Specific
313** command to NFCC.
314**
315** nfcee_id - The NFCEE id.
316** cfg_value - The config value
317**
318** Returns NFA_STATUS_OK if successfully initiated
319** NFA_STATUS_FAILED otherwise
320**
321*******************************************************************************/
322tNFA_STATUS NFA_SendPowerLinkCommand(uint8_t nfcee_id, uint8_t cfg_value) {
323 tNFA_EE_API_POWER_LINK_EVT* p_msg;
nxpandroidc7611652015-09-23 16:42:05 +0530324
nxf24591c1cbeab2018-02-21 17:32:26 +0530325 DLOG_IF(INFO, nfc_debug_enabled)
326 << StringPrintf("NFA_SendPowerLinkCommand() nfcee_id=0x%x", nfcee_id);
nxpandroidfb160962017-09-13 16:09:09 +0530327
328 if ((p_msg = (tNFA_EE_API_POWER_LINK_EVT*)GKI_getbuf(sizeof(tNFA_EE_API_POWER_LINK_EVT))) != NULL) {
329 p_msg->hdr.event = NFA_EE_NCI_PWR_LNK_CTRL_SET_EVT;
330 p_msg->nfcee_id= nfcee_id;
331 p_msg->cfg_value = cfg_value;
332
333 nfa_sys_sendmsg(p_msg);
334
335 return (NFA_STATUS_OK);
336 }
337
338 return (NFA_STATUS_FAILED);
339}
nxf24591c1cbeab2018-02-21 17:32:26 +0530340#endif
nxpandroidc7611652015-09-23 16:42:05 +0530341/*******************************************************************************
342**
343** Function NFA_EeModeSet
344**
nxpandroid8f6d0532017-07-12 18:25:30 +0530345** Description This function is called to activate
346** (mode = NFA_EE_MD_ACTIVATE) or deactivate
347** (mode = NFA_EE_MD_DEACTIVATE) the NFCEE identified by the
348** given ee_handle. The result of this operation is reported
349** with the NFA_EE_MODE_SET_EVT.
nxpandroidc7611652015-09-23 16:42:05 +0530350**
351** Returns NFA_STATUS_OK if successfully initiated
352** NFA_STATUS_FAILED otherwise
353** NFA_STATUS_INVALID_PARAM If bad parameter
354**
355*******************************************************************************/
nxpandroid8f6d0532017-07-12 18:25:30 +0530356tNFA_STATUS NFA_EeModeSet(tNFA_HANDLE ee_handle, tNFA_EE_MD mode) {
357 tNFA_EE_API_MODE_SET* p_msg;
358 tNFA_STATUS status = NFA_STATUS_FAILED;
nxf24591c1cbeab2018-02-21 17:32:26 +0530359 tNFA_EE_ECB *p_cb, *p_found = NULL;
nxpandroid8f6d0532017-07-12 18:25:30 +0530360 uint32_t xx;
361 uint8_t nfcee_id = (ee_handle & 0xFF);
nxpandroidc7611652015-09-23 16:42:05 +0530362
nxpandroid8f6d0532017-07-12 18:25:30 +0530363 p_cb = nfa_ee_cb.ecb;
364 for (xx = 0; xx < nfa_ee_cb.cur_ee; xx++, p_cb++) {
365 if (nfcee_id == p_cb->nfcee_id) {
366 p_found = p_cb;
367 break;
nxpandroidc7611652015-09-23 16:42:05 +0530368 }
nxpandroid8f6d0532017-07-12 18:25:30 +0530369 }
nxf24591c1cbeab2018-02-21 17:32:26 +0530370 DLOG_IF(INFO, nfc_debug_enabled)
371 << StringPrintf("handle:<0x%x>, mode:0x%02X", ee_handle, mode);
nxpandroidc7611652015-09-23 16:42:05 +0530372
nxpandroid8f6d0532017-07-12 18:25:30 +0530373 if (p_found == NULL) {
nxf24591c1cbeab2018-02-21 17:32:26 +0530374 LOG(ERROR) << StringPrintf("invalid NFCEE:0x%04x", ee_handle);
nxpandroid8f6d0532017-07-12 18:25:30 +0530375 status = NFA_STATUS_INVALID_PARAM;
376 } else {
377 p_msg = (tNFA_EE_API_MODE_SET*)GKI_getbuf(sizeof(tNFA_EE_API_MODE_SET));
378 if (p_msg != NULL) {
379 p_msg->hdr.event = NFA_EE_API_MODE_SET_EVT;
380 p_msg->nfcee_id = nfcee_id;
381 p_msg->mode = mode;
382 p_msg->p_cb = p_found;
383
384 nfa_sys_sendmsg(p_msg);
385
386 status = NFA_STATUS_OK;
nxpandroidc7611652015-09-23 16:42:05 +0530387 }
nxpandroid8f6d0532017-07-12 18:25:30 +0530388 }
nxpandroidc7611652015-09-23 16:42:05 +0530389
nxpandroid8f6d0532017-07-12 18:25:30 +0530390 return status;
nxpandroidc7611652015-09-23 16:42:05 +0530391}
392
nxpandroidc7611652015-09-23 16:42:05 +0530393/*******************************************************************************
394**
395** Function NFA_EeSetDefaultTechRouting
396**
397** Description This function is called to add, change or remove the
398** default routing based on RF technology in the listen mode
399** routing table for the given ee_handle. The status of this
400** operation is reported as the NFA_EE_SET_TECH_CFG_EVT.
401**
nxpandroid8f6d0532017-07-12 18:25:30 +0530402** Note: If RF discovery is started,
403** NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should
404** happen before calling this function
nxpandroidc7611652015-09-23 16:42:05 +0530405**
nxpandroid8f6d0532017-07-12 18:25:30 +0530406** Note: NFA_EeUpdateNow() should be called after last NFA-EE
407** function to change the listen mode routing is called.
nxpandroidc7611652015-09-23 16:42:05 +0530408**
409** Returns NFA_STATUS_OK if successfully initiated
410** NFA_STATUS_FAILED otherwise
411** NFA_STATUS_INVALID_PARAM If bad parameter
412**
413*******************************************************************************/
nxpandroid8f6d0532017-07-12 18:25:30 +0530414tNFA_STATUS NFA_EeSetDefaultTechRouting(
415 tNFA_HANDLE ee_handle, tNFA_TECHNOLOGY_MASK technologies_switch_on,
416 tNFA_TECHNOLOGY_MASK technologies_switch_off,
Suraj Uday Kotharkar1e7b99a2018-05-10 16:14:37 +0530417 tNFA_TECHNOLOGY_MASK technologies_battery_off,
nxpandroid8f6d0532017-07-12 18:25:30 +0530418 tNFA_TECHNOLOGY_MASK technologies_screen_lock,
419 tNFA_TECHNOLOGY_MASK technologies_screen_off,
Suraj Uday Kotharkar1e7b99a2018-05-10 16:14:37 +0530420 tNFA_TECHNOLOGY_MASK technologies_screen_off_lock) {
nxpandroid8f6d0532017-07-12 18:25:30 +0530421 tNFA_EE_API_SET_TECH_CFG* p_msg;
422 tNFA_STATUS status = NFA_STATUS_FAILED;
423 uint8_t nfcee_id = (uint8_t)(ee_handle & 0xFF);
424 tNFA_EE_ECB* p_cb;
nxpandroidc7611652015-09-23 16:42:05 +0530425
nxf24591c1cbeab2018-02-21 17:32:26 +0530426 DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf(
427 ""
Suraj Uday Kotharkar1e7b99a2018-05-10 16:14:37 +0530428 "handle:<0x%x>technology_mask:<0x%x>/<0x%x>/<0x%x><0x%x><0x%x><0x%x>",
nxpandroid8f6d0532017-07-12 18:25:30 +0530429 ee_handle, technologies_switch_on, technologies_switch_off,
Suraj Uday Kotharkar1e7b99a2018-05-10 16:14:37 +0530430 technologies_battery_off, technologies_screen_lock,
431 technologies_screen_off, technologies_screen_off_lock);
nxpandroid8f6d0532017-07-12 18:25:30 +0530432 p_cb = nfa_ee_find_ecb(nfcee_id);
nxpandroidc7611652015-09-23 16:42:05 +0530433
nxpandroid8f6d0532017-07-12 18:25:30 +0530434 if (p_cb == NULL) {
nxf24591c1cbeab2018-02-21 17:32:26 +0530435 LOG(ERROR) << StringPrintf("Bad ee_handle");
nxpandroid8f6d0532017-07-12 18:25:30 +0530436 status = NFA_STATUS_INVALID_PARAM;
437 } else {
438 p_msg =
439 (tNFA_EE_API_SET_TECH_CFG*)GKI_getbuf(sizeof(tNFA_EE_API_SET_TECH_CFG));
440 if (p_msg != NULL) {
441 p_msg->hdr.event = NFA_EE_API_SET_TECH_CFG_EVT;
442 p_msg->nfcee_id = nfcee_id;
443 p_msg->p_cb = p_cb;
444 p_msg->technologies_switch_on = technologies_switch_on;
445 p_msg->technologies_switch_off = technologies_switch_off;
446 p_msg->technologies_battery_off = technologies_battery_off;
nxpandroid8f6d0532017-07-12 18:25:30 +0530447 p_msg->technologies_screen_lock = technologies_screen_lock;
448 p_msg->technologies_screen_off = technologies_screen_off;
449 p_msg->technologies_screen_off_lock = technologies_screen_off_lock;
Suraj Uday Kotharkar1e7b99a2018-05-10 16:14:37 +0530450
nxpandroid8f6d0532017-07-12 18:25:30 +0530451 nfa_sys_sendmsg(p_msg);
nxpandroidc7611652015-09-23 16:42:05 +0530452
nxpandroid8f6d0532017-07-12 18:25:30 +0530453 status = NFA_STATUS_OK;
nxpandroidc7611652015-09-23 16:42:05 +0530454 }
nxpandroid8f6d0532017-07-12 18:25:30 +0530455 }
nxf24591c1cbeab2018-02-21 17:32:26 +0530456
nxpandroid8f6d0532017-07-12 18:25:30 +0530457 return status;
nxpandroidc7611652015-09-23 16:42:05 +0530458}
459
460/*******************************************************************************
461**
462** Function NFA_EeSetDefaultProtoRouting
463**
464** Description This function is called to add, change or remove the
465** default routing based on Protocol in the listen mode routing
466** table for the given ee_handle. The status of this
467** operation is reported as the NFA_EE_SET_PROTO_CFG_EVT.
468**
nxpandroid8f6d0532017-07-12 18:25:30 +0530469** Note: If RF discovery is started,
470** NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should
471** happen before calling this function
nxpandroidc7611652015-09-23 16:42:05 +0530472**
nxpandroid8f6d0532017-07-12 18:25:30 +0530473** Note: NFA_EeUpdateNow() should be called after last NFA-EE
474** function to change the listen mode routing is called.
nxpandroidc7611652015-09-23 16:42:05 +0530475**
476** Returns NFA_STATUS_OK if successfully initiated
477** NFA_STATUS_FAILED otherwise
478** NFA_STATUS_INVALID_PARAM If bad parameter
479**
480*******************************************************************************/
nxpandroid8f6d0532017-07-12 18:25:30 +0530481tNFA_STATUS NFA_EeSetDefaultProtoRouting(
482 tNFA_HANDLE ee_handle, tNFA_PROTOCOL_MASK protocols_switch_on,
483 tNFA_PROTOCOL_MASK protocols_switch_off,
Suraj Uday Kotharkar1e7b99a2018-05-10 16:14:37 +0530484 tNFA_PROTOCOL_MASK protocols_battery_off,
nxpandroid8f6d0532017-07-12 18:25:30 +0530485 tNFA_PROTOCOL_MASK protocols_screen_lock,
486 tNFA_PROTOCOL_MASK protocols_screen_off,
Suraj Uday Kotharkar1e7b99a2018-05-10 16:14:37 +0530487 tNFA_PROTOCOL_MASK protocols_screen_off_lock) {
nxpandroid8f6d0532017-07-12 18:25:30 +0530488 tNFA_EE_API_SET_PROTO_CFG* p_msg;
489 tNFA_STATUS status = NFA_STATUS_FAILED;
490 uint8_t nfcee_id = (uint8_t)(ee_handle & 0xFF);
491 tNFA_EE_ECB* p_cb;
nxpandroidc7611652015-09-23 16:42:05 +0530492
nxf24591c1cbeab2018-02-21 17:32:26 +0530493 DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf(
Suraj Uday Kotharkar1e7b99a2018-05-10 16:14:37 +0530494 "handle:<0x%x>protocol_mask:<0x%x>/<0x%x>/<0x%x><0x%x><0x%x><0x%x>",
nxpandroid8f6d0532017-07-12 18:25:30 +0530495 ee_handle, protocols_switch_on, protocols_switch_off,
Suraj Uday Kotharkar1e7b99a2018-05-10 16:14:37 +0530496 protocols_battery_off, protocols_screen_lock, protocols_screen_off,
nxf24591c1cbeab2018-02-21 17:32:26 +0530497 protocols_screen_off_lock);
nxpandroid8f6d0532017-07-12 18:25:30 +0530498 p_cb = nfa_ee_find_ecb(nfcee_id);
nxpandroidc7611652015-09-23 16:42:05 +0530499
nxpandroid8f6d0532017-07-12 18:25:30 +0530500 if (p_cb == NULL) {
nxf24591c1cbeab2018-02-21 17:32:26 +0530501 LOG(ERROR) << StringPrintf("Bad ee_handle");
nxpandroid8f6d0532017-07-12 18:25:30 +0530502 status = NFA_STATUS_INVALID_PARAM;
503 } else {
504 p_msg = (tNFA_EE_API_SET_PROTO_CFG*)GKI_getbuf(
505 sizeof(tNFA_EE_API_SET_PROTO_CFG));
506 if (p_msg != NULL) {
507 p_msg->hdr.event = NFA_EE_API_SET_PROTO_CFG_EVT;
508 p_msg->nfcee_id = nfcee_id;
509 p_msg->p_cb = p_cb;
510 p_msg->protocols_switch_on = protocols_switch_on;
511 p_msg->protocols_switch_off = protocols_switch_off;
512 p_msg->protocols_battery_off = protocols_battery_off;
nxpandroid8f6d0532017-07-12 18:25:30 +0530513 p_msg->protocols_screen_lock = protocols_screen_lock;
514 p_msg->protocols_screen_off = protocols_screen_off;
515 p_msg->protocols_screen_off_lock = protocols_screen_off_lock;
Suraj Uday Kotharkar1e7b99a2018-05-10 16:14:37 +0530516
nxpandroid8f6d0532017-07-12 18:25:30 +0530517 nfa_sys_sendmsg(p_msg);
nxpandroidc7611652015-09-23 16:42:05 +0530518
nxpandroid8f6d0532017-07-12 18:25:30 +0530519 status = NFA_STATUS_OK;
nxpandroidc7611652015-09-23 16:42:05 +0530520 }
nxpandroid8f6d0532017-07-12 18:25:30 +0530521 }
nxf24591c1cbeab2018-02-21 17:32:26 +0530522
nxpandroid8f6d0532017-07-12 18:25:30 +0530523 return status;
nxpandroidc7611652015-09-23 16:42:05 +0530524}
525
526/*******************************************************************************
527**
528** Function NFA_EeAddAidRouting
529**
530** Description This function is called to add an AID entry in the
531** listen mode routing table in NFCC. The status of this
532** operation is reported as the NFA_EE_ADD_AID_EVT.
533**
nxpandroid8f6d0532017-07-12 18:25:30 +0530534** Note: If RF discovery is started,
535** NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should
536** happen before calling this function
nxpandroidc7611652015-09-23 16:42:05 +0530537**
nxpandroid8f6d0532017-07-12 18:25:30 +0530538** Note: NFA_EeUpdateNow() should be called after last NFA-EE
539** function to change the listen mode routing is called.
nxpandroidc7611652015-09-23 16:42:05 +0530540**
541** Returns NFA_STATUS_OK if successfully initiated
542** NFA_STATUS_FAILED otherwise
543** NFA_STATUS_INVALID_PARAM If bad parameter
544**
545*******************************************************************************/
nxpandroid8f6d0532017-07-12 18:25:30 +0530546tNFA_STATUS NFA_EeAddAidRouting(tNFA_HANDLE ee_handle, uint8_t aid_len,
nxf24591c1cbeab2018-02-21 17:32:26 +0530547 uint8_t* p_aid, tNFA_EE_PWR_STATE power_state,
548 uint8_t aidInfo) {
nxpandroid8f6d0532017-07-12 18:25:30 +0530549 tNFA_EE_API_ADD_AID* p_msg;
550 tNFA_STATUS status = NFA_STATUS_FAILED;
551 uint16_t size = sizeof(tNFA_EE_API_ADD_AID) + aid_len;
552 uint8_t nfcee_id = (uint8_t)(ee_handle & 0xFF);
553 tNFA_EE_ECB* p_cb;
nxpandroidc7611652015-09-23 16:42:05 +0530554
nxf24591c1cbeab2018-02-21 17:32:26 +0530555 DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("handle:<0x%x>", ee_handle);
556 p_cb = nfa_ee_find_ecb(nfcee_id);
557#if (NXP_EXTNS == TRUE)
nxpandroid8f6d0532017-07-12 18:25:30 +0530558 /* validate parameters - make sure the AID is in valid length range */
nxpandroid601c4742017-09-13 16:10:30 +0530559 if ((p_cb == NULL) || ((NFA_GetNCIVersion() == NCI_VERSION_2_0) && (aid_len != 0) && (p_aid == NULL)) ||
560 ((NFA_GetNCIVersion() != NCI_VERSION_2_0) &&
561 ((aid_len == 0) || (p_aid == NULL) || (aid_len < NFA_MIN_AID_LEN))) ||
562 (aid_len > NFA_MAX_AID_LEN)) {
nxf24591c1cbeab2018-02-21 17:32:26 +0530563#else
564 if ((p_cb == NULL) || (aid_len == 0) || (p_aid == NULL) ||
565 (aid_len < NFA_MIN_AID_LEN) || (aid_len > NFA_MAX_AID_LEN)) {
566#endif
nxpandroid8f6d0532017-07-12 18:25:30 +0530567 status = NFA_STATUS_INVALID_PARAM;
568 } else {
569 p_msg = (tNFA_EE_API_ADD_AID*)GKI_getbuf(size);
570 if (p_msg != NULL) {
nxf24591c1cbeab2018-02-21 17:32:26 +0530571#if (NXP_EXTNS != TRUE)
572 DLOG_IF(INFO, nfc_debug_enabled)
573 << StringPrintf("aid:<%02x%02x>", p_aid[0], p_aid[1]);
574#endif
nxpandroid8f6d0532017-07-12 18:25:30 +0530575 p_msg->hdr.event = NFA_EE_API_ADD_AID_EVT;
576 p_msg->nfcee_id = nfcee_id;
577 p_msg->p_cb = p_cb;
578 p_msg->aid_len = aid_len;
579 p_msg->power_state = power_state;
580 p_msg->p_aid = (uint8_t*)(p_msg + 1);
nxf24591c1cbeab2018-02-21 17:32:26 +0530581 p_msg->aidInfo = aidInfo;
nxpandroid8f6d0532017-07-12 18:25:30 +0530582#if (NXP_EXTNS == TRUE)
nxpandroid601c4742017-09-13 16:10:30 +0530583 if(p_aid != NULL) {
nxpandroid6154b732016-01-14 20:39:23 +0530584#endif
nxf24591c1cbeab2018-02-21 17:32:26 +0530585 memcpy(p_msg->p_aid, p_aid, aid_len);
586#if (NXP_EXTNS == TRUE)
587 DLOG_IF(INFO, nfc_debug_enabled)
588 << StringPrintf("aid:<%02x%02x>", p_aid[0], p_aid[1]);
589}
590#endif
591 nfa_sys_sendmsg(p_msg);
592
593 status = NFA_STATUS_OK;
594 }
595 }
596
597 return status;
598}
Suraj Uday Kotharkar11ae20f2018-07-20 23:29:36 +0530599#if(NXP_EXTNS == TRUE)
600/*******************************************************************************
601**
602** Function NFA_EeAddApduPatternRouting
603**
604** Description This function is called to add an APDU pattern entry in the
605** listen mode routing table in NFCC. The status of this
606** operation is reported as the NFA_EE_ADD_APDU_EVT.
607**
608** Note: If RF discovery is started,
609** NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should
610** happen before calling this function
611**
612** Note: NFA_EeUpdateNow() should be called after last NFA-EE
613** function to change the listen mode routing is called.
614**
615** Returns NFA_STATUS_OK if successfully initiated
616** NFA_STATUS_FAILED otherwise
617** NFA_STATUS_INVALID_PARAM If bad parameter
618**
619*******************************************************************************/
620tNFA_STATUS NFA_EeAddApduPatternRouting(uint8_t apdu_data_len,uint8_t* apdu_data, uint8_t apdu_mask_len,
621 uint8_t* apdu_mask, tNFA_HANDLE ee_handle, uint8_t power_state) {
622 tNFA_EE_API_ADD_APDU* p_msg;
623 tNFA_STATUS status = NFA_STATUS_FAILED;
624 tNFA_EE_ECB* p_cb;
625 uint16_t size = sizeof(tNFA_EE_API_ADD_AID) + apdu_data_len + apdu_mask_len;
626 uint8_t nfcee_id = (uint8_t)(ee_handle & 0xFF);
nxf24591c1cbeab2018-02-21 17:32:26 +0530627
Suraj Uday Kotharkar11ae20f2018-07-20 23:29:36 +0530628 DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf
629 ("NFA_EeAddApduRouting(): handle:<0x%x>", ee_handle);
630 p_cb = nfa_ee_find_ecb(nfcee_id);
631 if(p_cb == NULL || apdu_data_len == 0 || apdu_mask_len == 0 || apdu_data == NULL
632 || apdu_mask == NULL || apdu_data_len > NFC_MAX_APDU_DATA_LEN
633 || apdu_mask_len > NFC_MAX_APDU_MASK_LEN || apdu_data_len != apdu_mask_len) {
634 DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf
635 ("Bad ee_handle or AID (len=%d)", apdu_data_len+apdu_mask_len);
636 status = NFA_STATUS_INVALID_PARAM;
637 } else {
638 p_msg = (tNFA_EE_API_ADD_APDU*)GKI_getbuf(size);
639 p_msg->hdr.event = NFA_EE_API_ADD_APDU_EVT;
640 p_msg->apdu_len = apdu_data_len;
641 p_msg->mask_len = apdu_mask_len;
642 p_msg->power_state = power_state;
643 p_msg->nfcee_id = nfcee_id;
644 p_msg->p_cb = p_cb;
645 p_msg->p_apdu = (uint8_t*)(p_msg + 1);
646 memcpy(p_msg->p_apdu, apdu_data, apdu_data_len);
647 p_msg->p_mask = (uint8_t*)(p_msg->p_apdu + apdu_data_len);
648 memcpy(p_msg->p_mask, apdu_mask, apdu_mask_len);
649 nfa_sys_sendmsg(p_msg);
650 status = NFA_STATUS_OK;
651 }
652 return status;
653}
654
655/*******************************************************************************
656**
657** Function NFA_EeRemoveApduPatternRouting
658**
659** Description This function is called to remove the given APDU entry from
660** the listen mode routing table. If the entry configures VS,
661** it is also removed. The status of this operation is reported
662** as the NFA_EE_REMOVE_APDU_EVT.
663**
664** Note: If RF discovery is started,
665** NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should
666** happen before calling this function
667**
668** Note: NFA_EeUpdateNow() should be called after last NFA-EE
669** function to change the listen mode routing is called.
670**
671** Returns NFA_STATUS_OK if successfully initiated
672** NFA_STATUS_FAILED otherwise
673** NFA_STATUS_INVALID_PARAM If bad parameter
674**
675*******************************************************************************/
676tNFA_STATUS NFA_EeRemoveApduPatternRouting(uint8_t apdu_len, uint8_t* p_apdu) {
677 tNFA_EE_API_REMOVE_APDU* p_msg;
678 tNFA_STATUS status = NFA_STATUS_FAILED;
679 uint16_t size = sizeof(tNFA_EE_API_REMOVE_APDU) + apdu_len;
680
681 DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("NFA_EeRemoveApduPatternRouting()");
682 if ((apdu_len == 0) || (p_apdu == NULL) || (apdu_len > NFC_MAX_APDU_DATA_LEN)) {
683 DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("Bad handle");
684 status = NFA_STATUS_INVALID_PARAM;
685 } else {
686 p_msg = (tNFA_EE_API_REMOVE_APDU*)GKI_getbuf(size);
687 if (p_msg != NULL) {
688 p_msg->hdr.event = NFA_EE_API_REMOVE_APDU_EVT;
689 p_msg->apdu_len = apdu_len;
690 p_msg->p_apdu = (uint8_t*)(p_msg + 1);
691 memcpy(p_msg->p_apdu, p_apdu, apdu_len);
692
693 nfa_sys_sendmsg(p_msg);
694
695 status = NFA_STATUS_OK;
696 }
697 }
698 return status;
699}
700#endif
nxpandroidc7611652015-09-23 16:42:05 +0530701/*******************************************************************************
702**
703** Function NFA_EeRemoveAidRouting
704**
nxpandroid8f6d0532017-07-12 18:25:30 +0530705** Description This function is called to remove the given AID entry from
706** the listen mode routing table. If the entry configures VS,
nxpandroidc7611652015-09-23 16:42:05 +0530707** it is also removed. The status of this operation is reported
708** as the NFA_EE_REMOVE_AID_EVT.
709**
nxpandroid8f6d0532017-07-12 18:25:30 +0530710** Note: If RF discovery is started,
711** NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should
712** happen before calling this function
nxpandroidc7611652015-09-23 16:42:05 +0530713**
nxpandroid8f6d0532017-07-12 18:25:30 +0530714** Note: NFA_EeUpdateNow() should be called after last NFA-EE
715** function to change the listen mode routing is called.
nxpandroidc7611652015-09-23 16:42:05 +0530716**
717** Returns NFA_STATUS_OK if successfully initiated
718** NFA_STATUS_FAILED otherwise
719** NFA_STATUS_INVALID_PARAM If bad parameter
720**
721*******************************************************************************/
nxpandroid8f6d0532017-07-12 18:25:30 +0530722tNFA_STATUS NFA_EeRemoveAidRouting(uint8_t aid_len, uint8_t* p_aid) {
723 tNFA_EE_API_REMOVE_AID* p_msg;
724 tNFA_STATUS status = NFA_STATUS_FAILED;
725 uint16_t size = sizeof(tNFA_EE_API_REMOVE_AID) + aid_len;
nxpandroidc7611652015-09-23 16:42:05 +0530726
nxf24591c1cbeab2018-02-21 17:32:26 +0530727 DLOG_IF(INFO, nfc_debug_enabled) << __func__;
nxpandroid8f6d0532017-07-12 18:25:30 +0530728 if ((aid_len == 0) || (p_aid == NULL) || (aid_len > NFA_MAX_AID_LEN)) {
nxf24591c1cbeab2018-02-21 17:32:26 +0530729 LOG(ERROR) << StringPrintf("Bad AID");
nxpandroid8f6d0532017-07-12 18:25:30 +0530730 status = NFA_STATUS_INVALID_PARAM;
731 } else {
732 p_msg = (tNFA_EE_API_REMOVE_AID*)GKI_getbuf(size);
733 if (p_msg != NULL) {
734 p_msg->hdr.event = NFA_EE_API_REMOVE_AID_EVT;
735 p_msg->aid_len = aid_len;
736 p_msg->p_aid = (uint8_t*)(p_msg + 1);
737 memcpy(p_msg->p_aid, p_aid, aid_len);
738
739 nfa_sys_sendmsg(p_msg);
740
741 status = NFA_STATUS_OK;
nxpandroidc7611652015-09-23 16:42:05 +0530742 }
nxpandroid8f6d0532017-07-12 18:25:30 +0530743 }
nxpandroidc7611652015-09-23 16:42:05 +0530744
nxpandroid8f6d0532017-07-12 18:25:30 +0530745 return status;
nxpandroidc7611652015-09-23 16:42:05 +0530746}
747
748/*******************************************************************************
749**
Suraj Uday Kotharkar6f7757b2018-05-10 15:58:29 +0530750** Function NFA_EeAddSystemCodeRouting
751**
752** Description This function is called to add an system code entry in the
753** listen mode routing table in NFCC. The status of this
754** operation is reported as the NFA_EE_ADD_SYSCODE_EVT.
755**
756** Note: If RF discovery is started,
757** NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should
758** happen before calling this function
759**
760** Note: NFA_EeUpdateNow() should be called after last NFA-EE
761** function to change the listen mode routing is called.
762**
763** Returns NFA_STATUS_OK if successfully initiated
764** NFA_STATUS_FAILED otherwise
765** NFA_STATUS_INVALID_PARAM If bad parameter
766**
767*******************************************************************************/
768tNFA_STATUS NFA_EeAddSystemCodeRouting(uint16_t systemcode,
769 tNFA_HANDLE ee_handle,
770 tNFA_EE_PWR_STATE power_state) {
771 tNFA_STATUS status = NFA_STATUS_FAILED;
772 uint8_t nfcee_id = (uint8_t)(ee_handle & 0xFF);
773 DLOG_IF(INFO, nfc_debug_enabled)
774 << StringPrintf("NFA_EeAddSystemCodeRouting(): handle:<0x%x>", ee_handle);
775 tNFA_EE_ECB* p_cb = nfa_ee_find_ecb(nfcee_id);
776
777 if (p_cb == NULL || systemcode == 0) {
778 LOG(ERROR) << StringPrintf("Bad ee_handle or System Code");
779 status = NFA_STATUS_INVALID_PARAM;
780 } else if ((NFA_GetNCIVersion() != NCI_VERSION_2_0) &&
781 (nfc_cb.isScbrSupported == false)) {
782 LOG(ERROR) << StringPrintf("Invalid NCI Version/SCBR not supported");
783 status = NFA_STATUS_NOT_SUPPORTED;
784 } else {
785 tNFA_EE_API_ADD_SYSCODE* p_msg =
786 (tNFA_EE_API_ADD_SYSCODE*)GKI_getbuf(sizeof(tNFA_EE_API_ADD_SYSCODE));
787 if (p_msg != NULL) {
788 p_msg->hdr.event = NFA_EE_API_ADD_SYSCODE_EVT;
789 p_msg->power_state = power_state;
790 p_msg->nfcee_id = nfcee_id;
791 p_msg->p_cb = p_cb;
792 // adjust endianness of syscode
793 p_msg->syscode = (systemcode & 0x00FF) << 8 | (systemcode & 0xFF00) >> 8;
794 nfa_sys_sendmsg(p_msg);
795 status = NFA_STATUS_OK;
796 }
797 }
798 return status;
799}
800
801/*******************************************************************************
802**
803** Function NFA_EeRemoveSystemCodeRouting
804**
805** Description This function is called to remove the given System Code
806** based entry from the listen mode routing table. The status
807** of this operation is reported as the
808** NFA_EE_REMOVE_SYSCODE_EVT.
809**
810** Note: If RF discovery is started,
811** NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should
812** happen before calling this function
813**
814** Note: NFA_EeUpdateNow() should be called after last NFA-EE
815** function to change the listen mode routing is called.
816**
817** Returns NFA_STATUS_OK if successfully initiated
818** NFA_STATUS_FAILED otherwise
819** NFA_STATUS_INVALID_PARAM If bad parameter
820**
821*******************************************************************************/
822tNFA_STATUS NFA_EeRemoveSystemCodeRouting(uint16_t systemcode) {
823 tNFA_STATUS status = NFA_STATUS_FAILED;
824
825 if (systemcode == 0) {
826 LOG(ERROR) << "Bad ee_handle or System Code";
827 status = NFA_STATUS_INVALID_PARAM;
828 } else if ((NFA_GetNCIVersion() != NCI_VERSION_2_0) &&
829 (nfc_cb.isScbrSupported == false)) {
830 LOG(ERROR) << "Invalid NCI Version/SCBR Not supported";
831 status = NFA_STATUS_NOT_SUPPORTED;
832 } else {
833 tNFA_EE_API_REMOVE_SYSCODE* p_msg = (tNFA_EE_API_REMOVE_SYSCODE*)GKI_getbuf(
834 sizeof(tNFA_EE_API_REMOVE_SYSCODE));
835 if (p_msg != NULL) {
836 p_msg->hdr.event = NFA_EE_API_REMOVE_SYSCODE_EVT;
837 p_msg->syscode = (systemcode & 0x00FF) << 8 | (systemcode & 0xFF00) >> 8;
838 nfa_sys_sendmsg(p_msg);
839 status = NFA_STATUS_OK;
840 }
841 }
842 return status;
843}
844
845/*******************************************************************************
846**
nxpandroidc7611652015-09-23 16:42:05 +0530847** Function NFA_EeGetLmrtRemainingSize
848**
849** Description This function is called to get remaining size of the
850** Listen Mode Routing Table.
851** The remaining size is reported in NFA_EE_REMAINING_SIZE_EVT
852**
853** Returns NFA_STATUS_OK if successfully initiated
854** NFA_STATUS_FAILED otherwise
855**
856*******************************************************************************/
nxpandroid8f6d0532017-07-12 18:25:30 +0530857tNFA_STATUS NFA_EeGetLmrtRemainingSize(void) {
858 tNFA_EE_API_LMRT_SIZE* p_msg;
859 tNFA_STATUS status = NFA_STATUS_FAILED;
nxpandroidc7611652015-09-23 16:42:05 +0530860
nxf24591c1cbeab2018-02-21 17:32:26 +0530861 DLOG_IF(INFO, nfc_debug_enabled) << __func__;
nxpandroid8f6d0532017-07-12 18:25:30 +0530862 p_msg = (tNFA_EE_API_LMRT_SIZE*)GKI_getbuf(sizeof(tNFA_EE_API_LMRT_SIZE));
863 if (p_msg != NULL) {
864 p_msg->event = NFA_EE_API_LMRT_SIZE_EVT;
865 nfa_sys_sendmsg(p_msg);
866 status = NFA_STATUS_OK;
867 }
nxpandroidc7611652015-09-23 16:42:05 +0530868
nxpandroid8f6d0532017-07-12 18:25:30 +0530869 return status;
nxpandroidc7611652015-09-23 16:42:05 +0530870}
871
872/******************************************************************************
873**
874** Function NFA_EeUpdateNow
875**
876** Description This function is called to send the current listen mode
nxpandroid8f6d0532017-07-12 18:25:30 +0530877** routing table and VS configuration to the NFCC (without
878** waiting for NFA_EE_ROUT_TIMEOUT_VAL).
nxpandroidc7611652015-09-23 16:42:05 +0530879**
880** The status of this operation is
881** reported with the NFA_EE_UPDATED_EVT.
882**
883** Returns NFA_STATUS_OK if successfully initiated
884** NFA_STATUS_SEMANTIC_ERROR is update is currently in progress
885** NFA_STATUS_FAILED otherwise
886**
887*******************************************************************************/
nxpandroid8f6d0532017-07-12 18:25:30 +0530888tNFA_STATUS NFA_EeUpdateNow(void) {
889 NFC_HDR* p_msg;
890 tNFA_STATUS status = NFA_STATUS_FAILED;
nxpandroidc7611652015-09-23 16:42:05 +0530891
nxf24591c1cbeab2018-02-21 17:32:26 +0530892 DLOG_IF(INFO, nfc_debug_enabled) << __func__;
nxpandroid8f6d0532017-07-12 18:25:30 +0530893 if (nfa_ee_cb.ee_wait_evt & NFA_EE_WAIT_UPDATE_ALL) {
nxf24591c1cbeab2018-02-21 17:32:26 +0530894 LOG(ERROR) << StringPrintf("update in progress");
nxpandroid8f6d0532017-07-12 18:25:30 +0530895 status = NFA_STATUS_SEMANTIC_ERROR;
896 } else {
897 p_msg = (NFC_HDR*)GKI_getbuf(NFC_HDR_SIZE);
898 if (p_msg != NULL) {
899 p_msg->event = NFA_EE_API_UPDATE_NOW_EVT;
900
901 nfa_sys_sendmsg(p_msg);
902
903 status = NFA_STATUS_OK;
nxpandroidc7611652015-09-23 16:42:05 +0530904 }
nxpandroid8f6d0532017-07-12 18:25:30 +0530905 }
nxpandroidc7611652015-09-23 16:42:05 +0530906
nxpandroid8f6d0532017-07-12 18:25:30 +0530907 return status;
nxpandroidc7611652015-09-23 16:42:05 +0530908}
909
nxpandroidc7611652015-09-23 16:42:05 +0530910/*******************************************************************************
911**
912** Function NFA_EeConnect
913**
914** Description Open connection to an NFCEE attached to the NFCC
915**
916** The status of this operation is
917** reported with the NFA_EE_CONNECT_EVT.
918**
919** Returns NFA_STATUS_OK if successfully initiated
920** NFA_STATUS_FAILED otherwise
921** NFA_STATUS_INVALID_PARAM If bad parameter
922**
923*******************************************************************************/
nxpandroid8f6d0532017-07-12 18:25:30 +0530924tNFA_STATUS NFA_EeConnect(tNFA_HANDLE ee_handle, uint8_t ee_interface,
925 tNFA_EE_CBACK* p_cback) {
926 tNFA_EE_API_CONNECT* p_msg;
927 tNFA_STATUS status = NFA_STATUS_FAILED;
928 uint8_t nfcee_id = (uint8_t)(ee_handle & 0xFF);
929 tNFA_EE_ECB* p_cb;
nxpandroidc7611652015-09-23 16:42:05 +0530930
nxf24591c1cbeab2018-02-21 17:32:26 +0530931 DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf(
932 "handle:<0x%x> ee_interface:0x%x", ee_handle, ee_interface);
nxpandroid8f6d0532017-07-12 18:25:30 +0530933 p_cb = nfa_ee_find_ecb(nfcee_id);
nxpandroidc7611652015-09-23 16:42:05 +0530934
nxpandroid8f6d0532017-07-12 18:25:30 +0530935 if ((p_cb == NULL) || (p_cback == NULL)) {
nxf24591c1cbeab2018-02-21 17:32:26 +0530936 LOG(ERROR) << StringPrintf("Bad ee_handle or NULL callback function");
nxpandroid8f6d0532017-07-12 18:25:30 +0530937 status = NFA_STATUS_INVALID_PARAM;
938 } else {
939 p_msg = (tNFA_EE_API_CONNECT*)GKI_getbuf(sizeof(tNFA_EE_API_CONNECT));
940 if (p_msg != NULL) {
941 p_msg->hdr.event = NFA_EE_API_CONNECT_EVT;
942 p_msg->nfcee_id = nfcee_id;
943 p_msg->p_cb = p_cb;
944 p_msg->ee_interface = ee_interface;
945 p_msg->p_cback = p_cback;
946
947 nfa_sys_sendmsg(p_msg);
948
949 status = NFA_STATUS_OK;
nxpandroidc7611652015-09-23 16:42:05 +0530950 }
nxpandroid8f6d0532017-07-12 18:25:30 +0530951 }
nxpandroidc7611652015-09-23 16:42:05 +0530952
nxpandroid8f6d0532017-07-12 18:25:30 +0530953 return status;
nxpandroidc7611652015-09-23 16:42:05 +0530954}
955
956/*******************************************************************************
957**
958** Function NFA_EeSendData
959**
960** Description Send data to the given NFCEE.
nxpandroid8f6d0532017-07-12 18:25:30 +0530961** This function shall be called after NFA_EE_CONNECT_EVT is
962** reported and before NFA_EeDisconnect is called on the given
963** ee_handle.
nxpandroidc7611652015-09-23 16:42:05 +0530964**
965** Returns NFA_STATUS_OK if successfully initiated
966** NFA_STATUS_FAILED otherwise
967** NFA_STATUS_INVALID_PARAM If bad parameter
968**
969*******************************************************************************/
nxpandroid8f6d0532017-07-12 18:25:30 +0530970tNFA_STATUS NFA_EeSendData(tNFA_HANDLE ee_handle, uint16_t data_len,
971 uint8_t* p_data) {
972 tNFA_EE_API_SEND_DATA* p_msg;
973 tNFA_STATUS status = NFA_STATUS_FAILED;
974 uint8_t nfcee_id = (uint8_t)(ee_handle & 0xFF);
975 tNFA_EE_ECB* p_cb;
nxpandroidc7611652015-09-23 16:42:05 +0530976
nxf24591c1cbeab2018-02-21 17:32:26 +0530977 DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("handle:<0x%x>", ee_handle);
nxpandroidc7611652015-09-23 16:42:05 +0530978
nxpandroid8f6d0532017-07-12 18:25:30 +0530979 p_cb = nfa_ee_find_ecb(nfcee_id);
nxpandroidc7611652015-09-23 16:42:05 +0530980
nxpandroid8f6d0532017-07-12 18:25:30 +0530981 if ((p_cb == NULL) || (p_cb->conn_st != NFA_EE_CONN_ST_CONN) ||
982 (p_data == NULL)) {
nxf24591c1cbeab2018-02-21 17:32:26 +0530983 LOG(ERROR) << StringPrintf("Bad ee_handle or NULL data");
nxpandroid8f6d0532017-07-12 18:25:30 +0530984 status = NFA_STATUS_INVALID_PARAM;
985 } else {
986 p_msg = (tNFA_EE_API_SEND_DATA*)GKI_getbuf(
987 (uint16_t)(sizeof(tNFA_EE_API_SEND_DATA) + data_len));
988 if (p_msg != NULL) {
989 p_msg->hdr.event = NFA_EE_API_SEND_DATA_EVT;
990 p_msg->nfcee_id = nfcee_id;
991 p_msg->p_cb = p_cb;
992 p_msg->data_len = data_len;
993 p_msg->p_data = (uint8_t*)(p_msg + 1);
994 memcpy(p_msg->p_data, p_data, data_len);
995
996 nfa_sys_sendmsg(p_msg);
997
998 status = NFA_STATUS_OK;
nxpandroidc7611652015-09-23 16:42:05 +0530999 }
nxpandroid8f6d0532017-07-12 18:25:30 +05301000 }
nxpandroidc7611652015-09-23 16:42:05 +05301001
nxpandroid8f6d0532017-07-12 18:25:30 +05301002 return status;
nxpandroidc7611652015-09-23 16:42:05 +05301003}
1004
1005/*******************************************************************************
1006**
1007** Function NFA_EeDisconnect
1008**
1009** Description Disconnect (if a connection is currently open) from an
1010** NFCEE interface. The result of this operation is reported
1011** with the NFA_EE_DISCONNECT_EVT.
1012**
1013** Returns NFA_STATUS_OK if successfully initiated
1014** NFA_STATUS_FAILED otherwise
1015** NFA_STATUS_INVALID_PARAM If bad parameter
1016**
1017*******************************************************************************/
nxpandroid8f6d0532017-07-12 18:25:30 +05301018tNFA_STATUS NFA_EeDisconnect(tNFA_HANDLE ee_handle) {
1019 tNFA_EE_API_DISCONNECT* p_msg;
1020 tNFA_STATUS status = NFA_STATUS_FAILED;
1021 uint8_t nfcee_id = (uint8_t)(ee_handle & 0xFF);
1022 tNFA_EE_ECB* p_cb;
nxpandroidc7611652015-09-23 16:42:05 +05301023
nxf24591c1cbeab2018-02-21 17:32:26 +05301024 DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("handle:<0x%x>", ee_handle);
nxpandroid8f6d0532017-07-12 18:25:30 +05301025 p_cb = nfa_ee_find_ecb(nfcee_id);
nxpandroidc7611652015-09-23 16:42:05 +05301026
nxpandroid8f6d0532017-07-12 18:25:30 +05301027 if ((p_cb == NULL) || (p_cb->conn_st != NFA_EE_CONN_ST_CONN)) {
nxf24591c1cbeab2018-02-21 17:32:26 +05301028 LOG(ERROR) << StringPrintf("Bad ee_handle");
nxpandroid8f6d0532017-07-12 18:25:30 +05301029 status = NFA_STATUS_INVALID_PARAM;
1030 } else {
1031 p_msg = (tNFA_EE_API_DISCONNECT*)GKI_getbuf(sizeof(tNFA_EE_API_DISCONNECT));
1032 if (p_msg != NULL) {
1033 p_msg->hdr.event = NFA_EE_API_DISCONNECT_EVT;
1034 p_msg->nfcee_id = nfcee_id;
1035 p_msg->p_cb = p_cb;
1036
1037 nfa_sys_sendmsg(p_msg);
1038
1039 status = NFA_STATUS_OK;
nxpandroidc7611652015-09-23 16:42:05 +05301040 }
nxpandroid8f6d0532017-07-12 18:25:30 +05301041 }
nxpandroidc7611652015-09-23 16:42:05 +05301042
nxpandroid8f6d0532017-07-12 18:25:30 +05301043 return status;
nxpandroidc7611652015-09-23 16:42:05 +05301044}
Ravishinde26233bb2018-08-06 22:16:08 +05301045#if (NXP_EXTNS == TRUE)
1046/*******************************************************************************
1047**
1048** Function NFA_GetAidTableSize
1049**
1050** Description This function is called to get the Maximum AID routing table
1051*size.
1052**
1053** Returns AID routing table maximum size
1054**
1055*******************************************************************************/
1056uint16_t NFA_GetAidTableSize() {
1057 return NFA_EE_MAX_AID_CFG_LEN;
1058}
1059
1060/*******************************************************************************
1061**
1062** Function NFA_GetRemainingAidTableSize
1063**
1064** Description This function is called to get the remaining AID routing
1065** table size.
1066**
1067** Returns Remaining AID routing table size.
1068**
1069*******************************************************************************/
1070uint16_t NFA_GetRemainingAidTableSize() {
1071 uint16_t size = 0;
1072 size = NFA_EE_MAX_AID_CFG_LEN - nfa_ee_lmrt_size();
1073 return size;
1074}
1075#endif