1 /******************************************************************************
2 *
3 * Copyright (C) 2010-2014 Broadcom Corporation
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 ******************************************************************************/
18
19 /******************************************************************************
20 *
21 * NFA interface to NFCEE - API functions
22 *
23 ******************************************************************************/
24 #include "nfa_ee_api.h"
25
26 #include <android-base/logging.h>
27 #include <android-base/stringprintf.h>
28
29 #include "nfa_dm_int.h"
30 #include "nfa_ee_int.h"
31 #include "nfc_int.h"
32
33 using android::base::StringPrintf;
34
35 extern GkiUtilsInterface* gki_utils;
36 /*****************************************************************************
37 ** APIs
38 *****************************************************************************/
39 /*******************************************************************************
40 **
41 ** Function NFA_EeDiscover
42 **
43 ** Description This function retrieves the NFCEE information from NFCC.
44 ** The NFCEE information is reported in NFA_EE_DISCOVER_EVT.
45 **
46 ** This function may be called when a system supports removable
47 ** NFCEEs,
48 **
49 ** Returns NFA_STATUS_OK if information is retrieved successfully
50 ** NFA_STATUS_FAILED If wrong state (retry later)
51 ** NFA_STATUS_INVALID_PARAM If bad parameter
52 **
53 *******************************************************************************/
NFA_EeDiscover(tNFA_EE_CBACK * p_cback)54 tNFA_STATUS NFA_EeDiscover(tNFA_EE_CBACK* p_cback) {
55 tNFA_EE_API_DISCOVER* p_msg;
56 tNFA_STATUS status = NFA_STATUS_FAILED;
57
58 LOG(VERBOSE) << __func__;
59
60 if (gki_utils == nullptr) {
61 gki_utils = new GkiUtils();
62 }
63
64 if (nfa_ee_cb.em_state != NFA_EE_EM_STATE_INIT_DONE) {
65 LOG(ERROR) << StringPrintf("%s: bad em state=%d", __func__,
66 nfa_ee_cb.em_state);
67 status = NFA_STATUS_FAILED;
68 } else if ((nfa_ee_cb.p_ee_disc_cback != nullptr) || (p_cback == nullptr)) {
69 LOG(ERROR) << StringPrintf("%s: in progress or NULL callback function",
70 __func__);
71 status = NFA_STATUS_INVALID_PARAM;
72 } else {
73 p_msg =
74 (tNFA_EE_API_DISCOVER*)gki_utils->getbuf(sizeof(tNFA_EE_API_DISCOVER));
75 if (p_msg != nullptr) {
76 p_msg->hdr.event = NFA_EE_API_DISCOVER_EVT;
77 p_msg->p_cback = p_cback;
78
79 nfa_sys_sendmsg(p_msg);
80
81 status = NFA_STATUS_OK;
82 }
83 }
84
85 return status;
86 }
87
88 /*******************************************************************************
89 **
90 ** Function NFA_EeGetInfo
91 **
92 ** Description This function retrieves the NFCEE information from NFA.
93 ** The actual number of NFCEE is returned in p_num_nfcee
94 ** and NFCEE information is returned in p_info
95 **
96 ** Returns NFA_STATUS_OK if information is retrieved successfully
97 ** NFA_STATUS_FAILED If wrong state (retry later)
98 ** NFA_STATUS_INVALID_PARAM If bad parameter
99 **
100 *******************************************************************************/
NFA_EeGetInfo(uint8_t * p_num_nfcee,tNFA_EE_INFO * p_info)101 tNFA_STATUS NFA_EeGetInfo(uint8_t* p_num_nfcee, tNFA_EE_INFO* p_info) {
102 int xx, ret = nfa_ee_cb.cur_ee;
103 tNFA_EE_ECB* p_cb = nfa_ee_cb.ecb;
104 uint8_t max_ret;
105 uint8_t num_ret = 0;
106
107 /* validate parameters */
108 if (p_info == nullptr || p_num_nfcee == nullptr) {
109 LOG(ERROR) << StringPrintf("%s: bad parameter", __func__);
110 return (NFA_STATUS_INVALID_PARAM);
111 }
112 max_ret = *p_num_nfcee;
113 *p_num_nfcee = 0;
114 if (nfa_ee_cb.em_state == NFA_EE_EM_STATE_INIT) {
115 LOG(ERROR) << StringPrintf("%s: bad em state=%d", __func__,
116 nfa_ee_cb.em_state);
117 return (NFA_STATUS_FAILED);
118 }
119
120 // Reset the target array as we may have less elements than in previous call
121 // if some activations failed.
122 memset(p_info, 0, sizeof(tNFA_EE_INFO) * max_ret);
123 /* compose output */
124 for (xx = 0; (xx < ret) && (num_ret < max_ret); xx++, p_cb++) {
125 if ((p_cb->ee_status & NFA_EE_STATUS_INT_MASK) ||
126 (p_cb->ee_status == NFA_EE_STATUS_REMOVED) ||
127 (p_cb->ee_status & NFA_EE_STATUS_MEP_MASK)) {
128 continue;
129 }
130 LOG(DEBUG) << StringPrintf(
131 "%s: xx=%d max_ret=%d, num_ret=%d nfcee_id=0x%x ee_status=0x%x",
132 __func__, xx, max_ret, num_ret, p_cb->nfcee_id, p_cb->ee_status);
133 p_info->ee_handle = NFA_HANDLE_GROUP_EE | (tNFA_HANDLE)p_cb->nfcee_id;
134 p_info->ee_status = p_cb->ee_status;
135 p_info->num_interface = p_cb->num_interface;
136 p_info->num_tlvs = p_cb->num_tlvs;
137 p_info->la_protocol = p_cb->la_protocol;
138 p_info->lb_protocol = p_cb->lb_protocol;
139 p_info->lf_protocol = p_cb->lf_protocol;
140 memcpy(p_info->ee_interface, p_cb->ee_interface, p_cb->num_interface);
141 memcpy(p_info->ee_tlv, p_cb->ee_tlv, p_cb->num_tlvs * sizeof(tNFA_EE_TLV));
142 p_info->ee_power_supply_status = p_cb->ee_power_supply_status;
143 p_info++;
144 num_ret++;
145 }
146 *p_num_nfcee = num_ret;
147 return (NFA_STATUS_OK);
148 }
149
150 /*******************************************************************************
151 **
152 ** Function NFA_EeGetMepInfo
153 **
154 ** Description This function retrieves the NFCEE information from NFA.
155 ** The actual number of NFCEE is returned in p_num_nfcee
156 ** and NFCEE information is returned in p_info
157 **
158 ** Returns NFA_STATUS_OK if information is retrieved successfully
159 ** NFA_STATUS_FAILED If wrong state (retry later)
160 ** NFA_STATUS_INVALID_PARAM If bad parameter
161 **
162 *******************************************************************************/
NFA_EeGetMepInfo(uint8_t * p_num_nfcee,tNFA_EE_INFO * p_info)163 tNFA_STATUS NFA_EeGetMepInfo(uint8_t* p_num_nfcee, tNFA_EE_INFO* p_info) {
164 int xx, ret = nfa_ee_cb.cur_ee;
165 tNFA_EE_ECB* p_cb = nfa_ee_cb.ecb;
166 uint8_t max_ret;
167 uint8_t num_ret = 0;
168
169 /* validate parameters */
170 if (p_info == nullptr || p_num_nfcee == nullptr) {
171 LOG(ERROR) << StringPrintf("%s: bad parameter", __func__);
172 return (NFA_STATUS_INVALID_PARAM);
173 }
174 max_ret = *p_num_nfcee;
175 *p_num_nfcee = 0;
176 if (nfa_ee_cb.em_state == NFA_EE_EM_STATE_INIT) {
177 LOG(ERROR) << StringPrintf("%s: bad em state=%d", __func__,
178 nfa_ee_cb.em_state);
179 return (NFA_STATUS_FAILED);
180 }
181
182 // Reset the target array as we may have less elements than in previous call
183 // if some activations failed.
184 memset(p_info, 0, sizeof(tNFA_EE_INFO) * max_ret);
185
186 /* compose output */
187 for (xx = 0; (xx < ret) && (num_ret < max_ret); xx++, p_cb++) {
188 if (!(p_cb->ee_status & NFA_EE_STATUS_MEP_MASK)) {
189 continue;
190 }
191 LOG(DEBUG) << StringPrintf(
192 "%s: xx=%d max_ret=%d, num_ret=%d nfcee_id=0x%x ee_status=0x%x",
193 __func__, xx, max_ret, num_ret, p_cb->nfcee_id, p_cb->ee_status);
194 p_info->ee_handle = NFA_HANDLE_GROUP_EE | (tNFA_HANDLE)p_cb->nfcee_id;
195 p_info->ee_status = p_cb->ee_status & ~NFA_EE_STATUS_MEP_MASK;
196
197 if ((p_cb->ee_status & NFA_EE_STATUS_INT_MASK) ||
198 (p_cb->ee_status == NFA_EE_STATUS_REMOVED)) {
199 p_info->num_interface = p_cb->num_interface;
200 p_info->num_tlvs = p_cb->num_tlvs;
201 p_info->la_protocol = p_cb->la_protocol;
202 p_info->lb_protocol = p_cb->lb_protocol;
203 p_info->lf_protocol = p_cb->lf_protocol;
204 memcpy(p_info->ee_interface, p_cb->ee_interface, p_cb->num_interface);
205 memcpy(p_info->ee_tlv, p_cb->ee_tlv,
206 p_cb->num_tlvs * sizeof(tNFA_EE_TLV));
207 p_info->ee_power_supply_status = p_cb->ee_power_supply_status;
208 }
209 p_info++;
210 num_ret++;
211 }
212 *p_num_nfcee = num_ret;
213 return (NFA_STATUS_OK);
214 }
215
216 /*******************************************************************************
217 **
218 ** Function NFA_EeRegister
219 **
220 ** Description This function registers a callback function to receive the
221 ** events from NFA-EE module.
222 **
223 ** Returns NFA_STATUS_OK if successfully initiated
224 ** NFA_STATUS_FAILED otherwise
225 ** NFA_STATUS_INVALID_PARAM If bad parameter
226 **
227 *******************************************************************************/
NFA_EeRegister(tNFA_EE_CBACK * p_cback)228 tNFA_STATUS NFA_EeRegister(tNFA_EE_CBACK* p_cback) {
229 tNFA_EE_API_REGISTER* p_msg;
230 tNFA_STATUS status = NFA_STATUS_FAILED;
231
232 LOG(VERBOSE) << __func__;
233
234 if (gki_utils == nullptr) {
235 gki_utils = new GkiUtils();
236 }
237
238 if (p_cback == nullptr) {
239 LOG(ERROR) << StringPrintf("%s: with NULL callback function", __func__);
240 status = NFA_STATUS_INVALID_PARAM;
241 } else {
242 p_msg =
243 (tNFA_EE_API_REGISTER*)gki_utils->getbuf(sizeof(tNFA_EE_API_REGISTER));
244 if (p_msg != nullptr) {
245 p_msg->hdr.event = NFA_EE_API_REGISTER_EVT;
246 p_msg->p_cback = p_cback;
247
248 nfa_sys_sendmsg(p_msg);
249
250 status = NFA_STATUS_OK;
251 }
252 }
253
254 return status;
255 }
256
257 /*******************************************************************************
258 **
259 ** Function NFA_EeDeregister
260 **
261 ** Description This function de-registers the callback function
262 **
263 ** Returns NFA_STATUS_OK if successfully initiated
264 ** NFA_STATUS_FAILED otherwise
265 ** NFA_STATUS_INVALID_PARAM If bad parameter
266 **
267 *******************************************************************************/
NFA_EeDeregister(tNFA_EE_CBACK * p_cback)268 tNFA_STATUS NFA_EeDeregister(tNFA_EE_CBACK* p_cback) {
269 tNFA_EE_API_DEREGISTER* p_msg;
270 tNFA_STATUS status = NFA_STATUS_INVALID_PARAM;
271 int index = NFA_EE_MAX_CBACKS;
272 int xx;
273
274 if (gki_utils == nullptr) {
275 gki_utils = new GkiUtils();
276 }
277
278 for (xx = 0; xx < NFA_EE_MAX_CBACKS; xx++) {
279 if (nfa_ee_cb.p_ee_cback[xx] == p_cback) {
280 index = xx;
281 status = NFA_STATUS_FAILED;
282 break;
283 }
284 }
285
286 LOG(VERBOSE) << StringPrintf("%s: index=%d, status=%d", __func__, index,
287 status);
288 if ((status != NFA_STATUS_INVALID_PARAM) &&
289 (p_msg = (tNFA_EE_API_DEREGISTER*)gki_utils->getbuf(
290 sizeof(tNFA_EE_API_DEREGISTER))) != nullptr) {
291 p_msg->hdr.event = NFA_EE_API_DEREGISTER_EVT;
292 p_msg->index = index;
293
294 nfa_sys_sendmsg(p_msg);
295
296 status = NFA_STATUS_OK;
297 }
298
299 return status;
300 }
301
302 /*******************************************************************************
303 **
304 ** Function NFA_EeModeSet
305 **
306 ** Description This function is called to activate
307 ** (mode = NFA_EE_MD_ACTIVATE) or deactivate
308 ** (mode = NFA_EE_MD_DEACTIVATE) the NFCEE identified by the
309 ** given ee_handle. The result of this operation is reported
310 ** with the NFA_EE_MODE_SET_EVT.
311 **
312 ** Returns NFA_STATUS_OK if successfully initiated
313 ** NFA_STATUS_FAILED otherwise
314 ** NFA_STATUS_INVALID_PARAM If bad parameter
315 **
316 *******************************************************************************/
NFA_EeModeSet(tNFA_HANDLE ee_handle,tNFA_EE_MD mode)317 tNFA_STATUS NFA_EeModeSet(tNFA_HANDLE ee_handle, tNFA_EE_MD mode) {
318 tNFA_EE_API_MODE_SET* p_msg;
319 tNFA_STATUS status = NFA_STATUS_FAILED;
320 tNFA_EE_ECB *p_cb, *p_found = nullptr;
321 uint32_t xx;
322 uint8_t nfcee_id = (ee_handle & 0xFF);
323
324 if (gki_utils == nullptr) {
325 gki_utils = new GkiUtils();
326 }
327
328 p_cb = nfa_ee_cb.ecb;
329 for (xx = 0; xx < nfa_ee_cb.cur_ee; xx++, p_cb++) {
330 if (nfcee_id == p_cb->nfcee_id) {
331 p_found = p_cb;
332 break;
333 }
334 }
335 LOG(VERBOSE) << StringPrintf("%s: handle:<0x%x>, mode=0x%02X", __func__,
336 ee_handle, mode);
337
338 if (p_found == nullptr) {
339 LOG(ERROR) << StringPrintf("%s: invalid NFCEE=0x%04x", __func__, ee_handle);
340 status = NFA_STATUS_INVALID_PARAM;
341 } else {
342 p_msg =
343 (tNFA_EE_API_MODE_SET*)gki_utils->getbuf(sizeof(tNFA_EE_API_MODE_SET));
344 if (p_msg != nullptr) {
345 p_msg->hdr.event = NFA_EE_API_MODE_SET_EVT;
346 p_msg->nfcee_id = nfcee_id;
347 p_msg->mode = mode;
348 p_msg->p_cb = p_found;
349
350 nfa_sys_sendmsg(p_msg);
351
352 status = NFA_STATUS_OK;
353 }
354 }
355
356 return status;
357 }
358
359 /*******************************************************************************
360 **
361 ** Function NFA_EeSetDefaultTechRouting
362 **
363 ** Description This function is called to add, change or remove the
364 ** default routing based on RF technology in the listen mode
365 ** routing table for the given ee_handle. The status of this
366 ** operation is reported as the NFA_EE_SET_TECH_CFG_EVT.
367 **
368 ** Note: If RF discovery is started,
369 ** NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should
370 ** happen before calling this function
371 **
372 ** Note: NFA_EeUpdateNow() should be called after last NFA-EE
373 ** function to change the listen mode routing is called.
374 **
375 ** Returns NFA_STATUS_OK if successfully initiated
376 ** NFA_STATUS_FAILED otherwise
377 ** NFA_STATUS_INVALID_PARAM If bad parameter
378 **
379 *******************************************************************************/
NFA_EeSetDefaultTechRouting(tNFA_HANDLE ee_handle,tNFA_TECHNOLOGY_MASK technologies_switch_on,tNFA_TECHNOLOGY_MASK technologies_switch_off,tNFA_TECHNOLOGY_MASK technologies_battery_off,tNFA_TECHNOLOGY_MASK technologies_screen_lock,tNFA_TECHNOLOGY_MASK technologies_screen_off,tNFA_TECHNOLOGY_MASK technologies_screen_off_lock)380 tNFA_STATUS NFA_EeSetDefaultTechRouting(
381 tNFA_HANDLE ee_handle, tNFA_TECHNOLOGY_MASK technologies_switch_on,
382 tNFA_TECHNOLOGY_MASK technologies_switch_off,
383 tNFA_TECHNOLOGY_MASK technologies_battery_off,
384 tNFA_TECHNOLOGY_MASK technologies_screen_lock,
385 tNFA_TECHNOLOGY_MASK technologies_screen_off,
386 tNFA_TECHNOLOGY_MASK technologies_screen_off_lock) {
387 tNFA_EE_API_SET_TECH_CFG* p_msg;
388 tNFA_STATUS status = NFA_STATUS_FAILED;
389 uint8_t nfcee_id = (uint8_t)(ee_handle & 0xFF);
390 tNFA_EE_ECB* p_cb;
391
392 LOG(VERBOSE) << StringPrintf(
393 "%s: "
394 "handle:<0x%x>technology_mask:<0x%x>/<0x%x>/<0x%x><0x%x><0x%x><0x%x>",
395 __func__, ee_handle, technologies_switch_on, technologies_switch_off,
396 technologies_battery_off, technologies_screen_lock,
397 technologies_screen_off, technologies_screen_off_lock);
398 p_cb = nfa_ee_find_ecb(nfcee_id);
399
400 if (gki_utils == nullptr) {
401 gki_utils = new GkiUtils();
402 }
403
404 if (p_cb == nullptr) {
405 LOG(ERROR) << StringPrintf("%s: Bad ee_handle", __func__);
406 status = NFA_STATUS_INVALID_PARAM;
407 } else {
408 p_msg = (tNFA_EE_API_SET_TECH_CFG*)gki_utils->getbuf(
409 sizeof(tNFA_EE_API_SET_TECH_CFG));
410 if (p_msg != nullptr) {
411 p_msg->hdr.event = NFA_EE_API_SET_TECH_CFG_EVT;
412 p_msg->nfcee_id = nfcee_id;
413 p_msg->p_cb = p_cb;
414 p_msg->technologies_switch_on = technologies_switch_on;
415 p_msg->technologies_switch_off = technologies_switch_off;
416 p_msg->technologies_battery_off = technologies_battery_off;
417 p_msg->technologies_screen_lock = technologies_screen_lock;
418 p_msg->technologies_screen_off = technologies_screen_off;
419 p_msg->technologies_screen_off_lock = technologies_screen_off_lock;
420
421 nfa_sys_sendmsg(p_msg);
422
423 status = NFA_STATUS_OK;
424 }
425 }
426
427 return status;
428 }
429
430 /*******************************************************************************
431 **
432 ** Function NFA_EeClearDefaultTechRouting
433 **
434 ** Description This function is called to remove the default routing based
435 ** on RF technology in the listen mode routing table for the
436 ** given ee_handle. The status of this operation is reported
437 ** as the NFA_EE_CLEAR_TECH_CFG_EVT.
438 **
439 ** Note: If RF discovery is started,
440 ** NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should
441 ** happen before calling this function
442 **
443 ** Note: NFA_EeUpdateNow() should be called after last NFA-EE
444 ** function to change the listen mode routing is called.
445 **
446 ** Returns NFA_STATUS_OK if successfully initiated
447 ** NFA_STATUS_FAILED otherwise
448 ** NFA_STATUS_INVALID_PARAM If bad parameter
449 **
450 *******************************************************************************/
NFA_EeClearDefaultTechRouting(tNFA_HANDLE ee_handle,tNFA_TECHNOLOGY_MASK clear_technology)451 tNFA_STATUS NFA_EeClearDefaultTechRouting(
452 tNFA_HANDLE ee_handle, tNFA_TECHNOLOGY_MASK clear_technology) {
453 tNFA_EE_API_SET_TECH_CFG* p_msg;
454 tNFA_STATUS status = NFA_STATUS_FAILED;
455 uint8_t nfcee_id = (uint8_t)(ee_handle & 0xFF);
456 tNFA_EE_ECB* p_cb;
457
458 LOG(VERBOSE) << StringPrintf("%s: handle:<0x%x>clear technology_mask:<0x%x>",
459 __func__, ee_handle, clear_technology);
460 if (gki_utils == nullptr) {
461 gki_utils = new GkiUtils();
462 }
463
464 if (!clear_technology) {
465 LOG(VERBOSE) << StringPrintf("%s: nothing to clear", __func__);
466 status = NFA_STATUS_OK;
467 return status;
468 }
469
470 p_cb = nfa_ee_find_ecb(nfcee_id);
471
472 if (p_cb == nullptr) {
473 LOG(ERROR) << StringPrintf("%s: Bad ee_handle", __func__);
474 status = NFA_STATUS_INVALID_PARAM;
475 } else {
476 p_msg = (tNFA_EE_API_CLEAR_TECH_CFG*)gki_utils->getbuf(
477 sizeof(tNFA_EE_API_CLEAR_TECH_CFG));
478 if (p_msg != nullptr) {
479 p_msg->hdr.event = NFA_EE_API_CLEAR_TECH_CFG_EVT;
480 p_msg->nfcee_id = nfcee_id;
481 p_msg->p_cb = p_cb;
482 p_msg->technologies_switch_on = clear_technology;
483 p_msg->technologies_switch_off = clear_technology;
484 p_msg->technologies_battery_off = clear_technology;
485 p_msg->technologies_screen_lock = clear_technology;
486 p_msg->technologies_screen_off = clear_technology;
487 p_msg->technologies_screen_off_lock = clear_technology;
488
489 nfa_sys_sendmsg(p_msg);
490
491 status = NFA_STATUS_OK;
492 }
493 }
494
495 return status;
496 }
497
498 /*******************************************************************************
499 **
500 ** Function NFA_EeSetDefaultProtoRouting
501 **
502 ** Description This function is called to add, change or remove the
503 ** default routing based on Protocol in the listen mode routing
504 ** table for the given ee_handle. The status of this
505 ** operation is reported as the NFA_EE_SET_PROTO_CFG_EVT.
506 **
507 ** Note: If RF discovery is started,
508 ** NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should
509 ** happen before calling this function
510 **
511 ** Note: NFA_EeUpdateNow() should be called after last NFA-EE
512 ** function to change the listen mode routing is called.
513 **
514 ** Returns NFA_STATUS_OK if successfully initiated
515 ** NFA_STATUS_FAILED otherwise
516 ** NFA_STATUS_INVALID_PARAM If bad parameter
517 **
518 *******************************************************************************/
NFA_EeSetDefaultProtoRouting(tNFA_HANDLE ee_handle,tNFA_PROTOCOL_MASK protocols_switch_on,tNFA_PROTOCOL_MASK protocols_switch_off,tNFA_PROTOCOL_MASK protocols_battery_off,tNFA_PROTOCOL_MASK protocols_screen_lock,tNFA_PROTOCOL_MASK protocols_screen_off,tNFA_PROTOCOL_MASK protocols_screen_off_lock)519 tNFA_STATUS NFA_EeSetDefaultProtoRouting(
520 tNFA_HANDLE ee_handle, tNFA_PROTOCOL_MASK protocols_switch_on,
521 tNFA_PROTOCOL_MASK protocols_switch_off,
522 tNFA_PROTOCOL_MASK protocols_battery_off,
523 tNFA_PROTOCOL_MASK protocols_screen_lock,
524 tNFA_PROTOCOL_MASK protocols_screen_off,
525 tNFA_PROTOCOL_MASK protocols_screen_off_lock) {
526 tNFA_EE_API_SET_PROTO_CFG* p_msg;
527 tNFA_STATUS status = NFA_STATUS_FAILED;
528 uint8_t nfcee_id = (uint8_t)(ee_handle & 0xFF);
529 tNFA_EE_ECB* p_cb;
530
531 LOG(VERBOSE) << StringPrintf(
532 "%s: handle:<0x%x>protocol_mask:<0x%x>/<0x%x>/<0x%x><0x%x><0x%x><0x%x>",
533 __func__, ee_handle, protocols_switch_on, protocols_switch_off,
534 protocols_battery_off, protocols_screen_lock, protocols_screen_off,
535 protocols_screen_off_lock);
536 p_cb = nfa_ee_find_ecb(nfcee_id);
537
538 if (gki_utils == nullptr) {
539 gki_utils = new GkiUtils();
540 }
541
542 if (p_cb == nullptr) {
543 LOG(ERROR) << StringPrintf("%s: Bad ee_handle", __func__);
544 status = NFA_STATUS_INVALID_PARAM;
545 } else {
546 p_msg = (tNFA_EE_API_SET_PROTO_CFG*)gki_utils->getbuf(
547 sizeof(tNFA_EE_API_SET_PROTO_CFG));
548 if (p_msg != nullptr) {
549 p_msg->hdr.event = NFA_EE_API_SET_PROTO_CFG_EVT;
550 p_msg->nfcee_id = nfcee_id;
551 p_msg->p_cb = p_cb;
552 p_msg->protocols_switch_on = protocols_switch_on;
553 p_msg->protocols_switch_off = protocols_switch_off;
554 p_msg->protocols_battery_off = protocols_battery_off;
555 p_msg->protocols_screen_lock = protocols_screen_lock;
556 p_msg->protocols_screen_off = protocols_screen_off;
557 p_msg->protocols_screen_off_lock = protocols_screen_off_lock;
558
559 nfa_sys_sendmsg(p_msg);
560
561 status = NFA_STATUS_OK;
562 }
563 }
564
565 return status;
566 }
567
568 /*******************************************************************************
569 **
570 ** Function NFA_EeClearDefaultProtoRouting
571 **
572 ** Description This function is called to remove the default routing based
573 ** on RF technology in the listen mode routing table for the
574 ** given ee_handle. The status of this operation is reported
575 ** as the NFA_EE_CLEAR_TECH_CFG_EVT.
576 **
577 ** Note: If RF discovery is started,
578 ** NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should
579 ** happen before calling this function
580 **
581 ** Note: NFA_EeUpdateNow() should be called after last NFA-EE
582 ** function to change the listen mode routing is called.
583 **
584 ** Returns NFA_STATUS_OK if successfully initiated
585 ** NFA_STATUS_FAILED otherwise
586 ** NFA_STATUS_INVALID_PARAM If bad parameter
587 **
588 *******************************************************************************/
NFA_EeClearDefaultProtoRouting(tNFA_HANDLE ee_handle,tNFA_PROTOCOL_MASK clear_protocol)589 tNFA_STATUS NFA_EeClearDefaultProtoRouting(tNFA_HANDLE ee_handle,
590 tNFA_PROTOCOL_MASK clear_protocol) {
591 tNFA_EE_API_SET_PROTO_CFG* p_msg;
592 tNFA_STATUS status = NFA_STATUS_FAILED;
593 uint8_t nfcee_id = (uint8_t)(ee_handle & 0xFF);
594 tNFA_EE_ECB* p_cb;
595
596 LOG(VERBOSE) << StringPrintf("%s: handle:<0x%x>clear protocol_mask:<0x%x>",
597 __func__, ee_handle, clear_protocol);
598 if (!clear_protocol) {
599 LOG(VERBOSE) << StringPrintf("%s: nothing to clear", __func__);
600 status = NFA_STATUS_OK;
601 return status;
602 }
603
604 p_cb = nfa_ee_find_ecb(nfcee_id);
605
606 if (gki_utils == nullptr) {
607 gki_utils = new GkiUtils();
608 }
609
610 if (p_cb == nullptr) {
611 LOG(ERROR) << StringPrintf("%s: Bad ee_handle", __func__);
612 status = NFA_STATUS_INVALID_PARAM;
613 } else {
614 p_msg = (tNFA_EE_API_SET_PROTO_CFG*)gki_utils->getbuf(
615 sizeof(tNFA_EE_API_SET_PROTO_CFG));
616 if (p_msg != nullptr) {
617 p_msg->hdr.event = NFA_EE_API_CLEAR_PROTO_CFG_EVT;
618 p_msg->nfcee_id = nfcee_id;
619 p_msg->p_cb = p_cb;
620 p_msg->protocols_switch_on = clear_protocol;
621 p_msg->protocols_switch_off = clear_protocol;
622 p_msg->protocols_battery_off = clear_protocol;
623 p_msg->protocols_screen_lock = clear_protocol;
624 p_msg->protocols_screen_off = clear_protocol;
625 p_msg->protocols_screen_off_lock = clear_protocol;
626
627 nfa_sys_sendmsg(p_msg);
628
629 status = NFA_STATUS_OK;
630 }
631 }
632
633 return status;
634 }
635
636 /*******************************************************************************
637 **
638 ** Function NFA_EeAddAidRouting
639 **
640 ** Description This function is called to add an AID entry in the
641 ** listen mode routing table in NFCC. The status of this
642 ** operation is reported as the NFA_EE_ADD_AID_EVT.
643 **
644 ** Note: If RF discovery is started,
645 ** NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should
646 ** happen before calling this function
647 **
648 ** Note: NFA_EeUpdateNow() should be called after last NFA-EE
649 ** function to change the listen mode routing is called.
650 **
651 ** Returns NFA_STATUS_OK if successfully initiated
652 ** NFA_STATUS_FAILED otherwise
653 ** NFA_STATUS_INVALID_PARAM If bad parameter
654 **
655 *******************************************************************************/
NFA_EeAddAidRouting(tNFA_HANDLE ee_handle,uint8_t aid_len,uint8_t * p_aid,tNFA_EE_PWR_STATE power_state,uint8_t aidInfo)656 tNFA_STATUS NFA_EeAddAidRouting(tNFA_HANDLE ee_handle, uint8_t aid_len,
657 uint8_t* p_aid, tNFA_EE_PWR_STATE power_state,
658 uint8_t aidInfo) {
659 tNFA_EE_API_ADD_AID* p_msg;
660 tNFA_STATUS status = NFA_STATUS_FAILED;
661 uint16_t size = sizeof(tNFA_EE_API_ADD_AID) + aid_len;
662 uint8_t nfcee_id = (uint8_t)(ee_handle & 0xFF);
663 tNFA_EE_ECB* p_cb;
664
665 if (aid_len == 0) {
666 LOG(VERBOSE) << StringPrintf("%s: handle=<0x%x>, default AID route",
667 __func__, ee_handle);
668 } else {
669 LOG(VERBOSE) << StringPrintf("%s: handle=<0x%x>", __func__, ee_handle);
670 }
671 p_cb = nfa_ee_find_ecb(nfcee_id);
672
673 if (gki_utils == nullptr) {
674 gki_utils = new GkiUtils();
675 }
676
677 /* validate parameters - make sure the AID is in valid length range */
678 if ((p_cb == nullptr) ||
679 ((NFA_GetNCIVersion() >= NCI_VERSION_2_0) && (aid_len != 0) &&
680 (p_aid == nullptr)) ||
681 ((NFA_GetNCIVersion() < NCI_VERSION_2_0) &&
682 ((aid_len == 0) || (p_aid == nullptr) || (aid_len < NFA_MIN_AID_LEN))) ||
683 (aid_len > NFA_MAX_AID_LEN)) {
684 LOG(ERROR) << StringPrintf("%s: Bad ee_handle or AID (len=%d)", __func__,
685 aid_len);
686 status = NFA_STATUS_INVALID_PARAM;
687 } else {
688 p_msg = (tNFA_EE_API_ADD_AID*)gki_utils->getbuf(size);
689 if (p_msg != nullptr) {
690 if (p_aid != nullptr)
691 LOG(VERBOSE) << StringPrintf("%s: aid:<%02x%02x>", __func__, p_aid[0],
692 p_aid[1]);
693 p_msg->hdr.event = NFA_EE_API_ADD_AID_EVT;
694 p_msg->nfcee_id = nfcee_id;
695 p_msg->p_cb = p_cb;
696 p_msg->aid_len = aid_len;
697 p_msg->power_state = power_state;
698 p_msg->p_aid = (uint8_t*)(p_msg + 1);
699 p_msg->aidInfo = aidInfo;
700 if (p_aid != nullptr) memcpy(p_msg->p_aid, p_aid, aid_len);
701
702 nfa_sys_sendmsg(p_msg);
703
704 status = NFA_STATUS_OK;
705 }
706 }
707
708 return status;
709 }
710
711 /*******************************************************************************
712 **
713 ** Function NFA_EeRemoveAidRouting
714 **
715 ** Description This function is called to remove the given AID entry from
716 ** the listen mode routing table. If the entry configures VS,
717 ** it is also removed. The status of this operation is reported
718 ** as the NFA_EE_REMOVE_AID_EVT.
719 **
720 ** Note: If RF discovery is started,
721 ** NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should
722 ** happen before calling this function
723 **
724 ** Note: NFA_EeUpdateNow() should be called after last NFA-EE
725 ** function to change the listen mode routing is called.
726 **
727 ** Returns NFA_STATUS_OK if successfully initiated
728 ** NFA_STATUS_FAILED otherwise
729 ** NFA_STATUS_INVALID_PARAM If bad parameter
730 **
731 *******************************************************************************/
NFA_EeRemoveAidRouting(uint8_t aid_len,uint8_t * p_aid)732 tNFA_STATUS NFA_EeRemoveAidRouting(uint8_t aid_len, uint8_t* p_aid) {
733 tNFA_EE_API_REMOVE_AID* p_msg;
734 tNFA_STATUS status = NFA_STATUS_FAILED;
735 uint16_t size = sizeof(tNFA_EE_API_REMOVE_AID) + aid_len;
736
737 LOG(VERBOSE) << __func__;
738
739 if (gki_utils == nullptr) {
740 gki_utils = new GkiUtils();
741 }
742
743 if (((NFA_GetNCIVersion() >= NCI_VERSION_2_0) && (aid_len != 0) &&
744 (p_aid == nullptr)) ||
745 ((NFA_GetNCIVersion() < NCI_VERSION_2_0) &&
746 ((aid_len == 0) || (p_aid == nullptr) || (aid_len < NFA_MIN_AID_LEN))) ||
747 (aid_len > NFA_MAX_AID_LEN)) {
748 LOG(ERROR) << StringPrintf("%s: Bad AID", __func__);
749 status = NFA_STATUS_INVALID_PARAM;
750 } else {
751 p_msg = (tNFA_EE_API_REMOVE_AID*)gki_utils->getbuf(size);
752 if (p_msg != nullptr) {
753 p_msg->hdr.event = NFA_EE_API_REMOVE_AID_EVT;
754 p_msg->aid_len = aid_len;
755 p_msg->p_aid = (uint8_t*)(p_msg + 1);
756 memcpy(p_msg->p_aid, p_aid, aid_len);
757
758 nfa_sys_sendmsg(p_msg);
759
760 status = NFA_STATUS_OK;
761 }
762 }
763
764 return status;
765 }
766
767 /*******************************************************************************
768 **
769 ** Function NFA_EeAddSystemCodeRouting
770 **
771 ** Description This function is called to add an system code entry in the
772 ** listen mode routing table in NFCC. The status of this
773 ** operation is reported as the NFA_EE_ADD_SYSCODE_EVT.
774 **
775 ** Note: If RF discovery is started,
776 ** NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should
777 ** happen before calling this function
778 **
779 ** Note: NFA_EeUpdateNow() should be called after last NFA-EE
780 ** function to change the listen mode routing is called.
781 **
782 ** Returns NFA_STATUS_OK if successfully initiated
783 ** NFA_STATUS_FAILED otherwise
784 ** NFA_STATUS_INVALID_PARAM If bad parameter
785 **
786 *******************************************************************************/
NFA_EeAddSystemCodeRouting(uint16_t systemcode,tNFA_HANDLE ee_handle,tNFA_EE_PWR_STATE power_state)787 tNFA_STATUS NFA_EeAddSystemCodeRouting(uint16_t systemcode,
788 tNFA_HANDLE ee_handle,
789 tNFA_EE_PWR_STATE power_state) {
790 tNFA_STATUS status = NFA_STATUS_FAILED;
791 uint8_t nfcee_id = (uint8_t)(ee_handle & 0xFF);
792 LOG(VERBOSE) << StringPrintf("%s: handle:<0x%x>", __func__, ee_handle);
793 tNFA_EE_ECB* p_cb = nfa_ee_find_ecb(nfcee_id);
794
795 if (gki_utils == nullptr) {
796 gki_utils = new GkiUtils();
797 }
798
799 if (p_cb == nullptr || systemcode == 0) {
800 LOG(ERROR) << StringPrintf("%s: Bad ee_handle or System Code", __func__);
801 status = NFA_STATUS_INVALID_PARAM;
802 } else if ((NFA_GetNCIVersion() < NCI_VERSION_2_0) &&
803 (nfc_cb.isScbrSupported == false)) {
804 LOG(ERROR) << StringPrintf("%s: Invalid NCI Version/SCBR not supported",
805 __func__);
806 status = NFA_STATUS_NOT_SUPPORTED;
807 } else {
808 tNFA_EE_API_ADD_SYSCODE* p_msg =
809 (tNFA_EE_API_ADD_SYSCODE*)gki_utils->getbuf(
810 sizeof(tNFA_EE_API_ADD_SYSCODE));
811 if (p_msg != nullptr) {
812 p_msg->hdr.event = NFA_EE_API_ADD_SYSCODE_EVT;
813 p_msg->power_state = power_state;
814 p_msg->nfcee_id = nfcee_id;
815 p_msg->p_cb = p_cb;
816 // adjust endianness of syscode
817 p_msg->syscode = (systemcode & 0x00FF) << 8 | (systemcode & 0xFF00) >> 8;
818 nfa_sys_sendmsg(p_msg);
819 status = NFA_STATUS_OK;
820 }
821 }
822 return status;
823 }
824
825 /*******************************************************************************
826 **
827 ** Function NFA_EeRemoveSystemCodeRouting
828 **
829 ** Description This function is called to remove the given System Code
830 ** based entry from the listen mode routing table. The status
831 ** of this operation is reported as the
832 ** NFA_EE_REMOVE_SYSCODE_EVT.
833 **
834 ** Note: If RF discovery is started,
835 ** NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should
836 ** happen before calling this function
837 **
838 ** Note: NFA_EeUpdateNow() should be called after last NFA-EE
839 ** function to change the listen mode routing is called.
840 **
841 ** Returns NFA_STATUS_OK if successfully initiated
842 ** NFA_STATUS_FAILED otherwise
843 ** NFA_STATUS_INVALID_PARAM If bad parameter
844 **
845 *******************************************************************************/
NFA_EeRemoveSystemCodeRouting(uint16_t systemcode)846 tNFA_STATUS NFA_EeRemoveSystemCodeRouting(uint16_t systemcode) {
847 tNFA_STATUS status = NFA_STATUS_FAILED;
848
849 if (gki_utils == nullptr) {
850 gki_utils = new GkiUtils();
851 }
852
853 if (systemcode == 0) {
854 LOG(ERROR) << __func__ << ": Bad ee_handle or System Code";
855 status = NFA_STATUS_INVALID_PARAM;
856 } else if ((NFA_GetNCIVersion() < NCI_VERSION_2_0) &&
857 (nfc_cb.isScbrSupported == false)) {
858 LOG(ERROR) << __func__ << ": Invalid NCI Version/SCBR Not supported";
859 status = NFA_STATUS_NOT_SUPPORTED;
860 } else {
861 tNFA_EE_API_REMOVE_SYSCODE* p_msg =
862 (tNFA_EE_API_REMOVE_SYSCODE*)gki_utils->getbuf(
863 sizeof(tNFA_EE_API_REMOVE_SYSCODE));
864 if (p_msg != nullptr) {
865 p_msg->hdr.event = NFA_EE_API_REMOVE_SYSCODE_EVT;
866 p_msg->syscode = (systemcode & 0x00FF) << 8 | (systemcode & 0xFF00) >> 8;
867 nfa_sys_sendmsg(p_msg);
868 status = NFA_STATUS_OK;
869 }
870 }
871 return status;
872 }
873
874 /*******************************************************************************
875 **
876 ** Function NFA_GetAidTableSize
877 **
878 ** Description This function is called to get the Maximum AID routing table
879 *size.
880 **
881 ** Returns AID routing table maximum size
882 **
883 *******************************************************************************/
NFA_GetAidTableSize()884 uint16_t NFA_GetAidTableSize() { return nfa_ee_find_max_aid_cfg_len(); }
885
886 /*******************************************************************************
887 **
888 ** Function NFA_EeGetLmrtRemainingSize
889 **
890 ** Description This function is called to get remaining size of the
891 ** Listen Mode Routing Table.
892 ** The remaining size is reported in NFA_EE_REMAINING_SIZE_EVT
893 **
894 ** Returns NFA_STATUS_OK if successfully initiated
895 ** NFA_STATUS_FAILED otherwise
896 **
897 *******************************************************************************/
NFA_EeGetLmrtRemainingSize(void)898 tNFA_STATUS NFA_EeGetLmrtRemainingSize(void) {
899 tNFA_EE_API_LMRT_SIZE* p_msg;
900 tNFA_STATUS status = NFA_STATUS_FAILED;
901
902 LOG(VERBOSE) << __func__;
903
904 if (gki_utils == nullptr) {
905 gki_utils = new GkiUtils();
906 }
907
908 p_msg =
909 (tNFA_EE_API_LMRT_SIZE*)gki_utils->getbuf(sizeof(tNFA_EE_API_LMRT_SIZE));
910 if (p_msg != nullptr) {
911 p_msg->event = NFA_EE_API_LMRT_SIZE_EVT;
912 nfa_sys_sendmsg(p_msg);
913 status = NFA_STATUS_OK;
914 }
915
916 return status;
917 }
918
919 /******************************************************************************
920 **
921 ** Function NFA_EeUpdateNow
922 **
923 ** Description This function is called to send the current listen mode
924 ** routing table and VS configuration to the NFCC (without
925 ** waiting for NFA_EE_ROUT_TIMEOUT_VAL).
926 **
927 ** The status of this operation is
928 ** reported with the NFA_EE_UPDATED_EVT.
929 **
930 ** Returns NFA_STATUS_OK if successfully initiated
931 ** NFA_STATUS_SEMANTIC_ERROR is update is currently in progress
932 ** NFA_STATUS_FAILED otherwise
933 **
934 *******************************************************************************/
NFA_EeUpdateNow(void)935 tNFA_STATUS NFA_EeUpdateNow(void) {
936 NFC_HDR* p_msg;
937 tNFA_STATUS status = NFA_STATUS_FAILED;
938
939 LOG(VERBOSE) << __func__;
940
941 if (gki_utils == nullptr) {
942 gki_utils = new GkiUtils();
943 }
944
945 if (nfa_ee_cb.ee_wait_evt & NFA_EE_WAIT_UPDATE_ALL) {
946 LOG(ERROR) << StringPrintf("%s: update in progress", __func__);
947 status = NFA_STATUS_SEMANTIC_ERROR;
948 } else {
949 p_msg = (NFC_HDR*)gki_utils->getbuf(NFC_HDR_SIZE);
950 if (p_msg != nullptr) {
951 p_msg->event = NFA_EE_API_UPDATE_NOW_EVT;
952
953 nfa_sys_sendmsg(p_msg);
954
955 status = NFA_STATUS_OK;
956 }
957 }
958
959 return status;
960 }
961
962 /*******************************************************************************
963 **
964 ** Function NFA_EeConnect
965 **
966 ** Description Open connection to an NFCEE attached to the NFCC
967 **
968 ** The status of this operation is
969 ** reported with the NFA_EE_CONNECT_EVT.
970 **
971 ** Returns NFA_STATUS_OK if successfully initiated
972 ** NFA_STATUS_FAILED otherwise
973 ** NFA_STATUS_INVALID_PARAM If bad parameter
974 **
975 *******************************************************************************/
NFA_EeConnect(tNFA_HANDLE ee_handle,uint8_t ee_interface,tNFA_EE_CBACK * p_cback)976 tNFA_STATUS NFA_EeConnect(tNFA_HANDLE ee_handle, uint8_t ee_interface,
977 tNFA_EE_CBACK* p_cback) {
978 tNFA_EE_API_CONNECT* p_msg;
979 tNFA_STATUS status = NFA_STATUS_FAILED;
980 uint8_t nfcee_id = (uint8_t)(ee_handle & 0xFF);
981 tNFA_EE_ECB* p_cb;
982
983 LOG(VERBOSE) << StringPrintf("%s: handle:<0x%x> ee_interface=0x%x", __func__,
984 ee_handle, ee_interface);
985 p_cb = nfa_ee_find_ecb(nfcee_id);
986
987 if (gki_utils == nullptr) {
988 gki_utils = new GkiUtils();
989 }
990
991 if ((p_cb == nullptr) || (p_cback == nullptr)) {
992 LOG(ERROR) << StringPrintf("%s: Bad ee_handle or NULL callback function",
993 __func__);
994 status = NFA_STATUS_INVALID_PARAM;
995 } else {
996 p_msg =
997 (tNFA_EE_API_CONNECT*)gki_utils->getbuf(sizeof(tNFA_EE_API_CONNECT));
998 if (p_msg != nullptr) {
999 p_msg->hdr.event = NFA_EE_API_CONNECT_EVT;
1000 p_msg->nfcee_id = nfcee_id;
1001 p_msg->p_cb = p_cb;
1002 p_msg->ee_interface = ee_interface;
1003 p_msg->p_cback = p_cback;
1004
1005 nfa_sys_sendmsg(p_msg);
1006
1007 status = NFA_STATUS_OK;
1008 }
1009 }
1010
1011 return status;
1012 }
1013
1014 /*******************************************************************************
1015 **
1016 ** Function NFA_EeSendData
1017 **
1018 ** Description Send data to the given NFCEE.
1019 ** This function shall be called after NFA_EE_CONNECT_EVT is
1020 ** reported and before NFA_EeDisconnect is called on the given
1021 ** ee_handle.
1022 **
1023 ** Returns NFA_STATUS_OK if successfully initiated
1024 ** NFA_STATUS_FAILED otherwise
1025 ** NFA_STATUS_INVALID_PARAM If bad parameter
1026 **
1027 *******************************************************************************/
NFA_EeSendData(tNFA_HANDLE ee_handle,uint16_t data_len,uint8_t * p_data)1028 tNFA_STATUS NFA_EeSendData(tNFA_HANDLE ee_handle, uint16_t data_len,
1029 uint8_t* p_data) {
1030 tNFA_EE_API_SEND_DATA* p_msg;
1031 tNFA_STATUS status = NFA_STATUS_FAILED;
1032 uint8_t nfcee_id = (uint8_t)(ee_handle & 0xFF);
1033 tNFA_EE_ECB* p_cb;
1034
1035 LOG(VERBOSE) << StringPrintf("%s: handle:<0x%x>", __func__, ee_handle);
1036
1037 p_cb = nfa_ee_find_ecb(nfcee_id);
1038
1039 if (gki_utils == nullptr) {
1040 gki_utils = new GkiUtils();
1041 }
1042
1043 if ((p_cb == nullptr) || (p_cb->conn_st != NFA_EE_CONN_ST_CONN) ||
1044 (p_data == nullptr)) {
1045 LOG(ERROR) << StringPrintf("%s: Bad ee_handle or NULL data", __func__);
1046 status = NFA_STATUS_INVALID_PARAM;
1047 } else {
1048 p_msg = (tNFA_EE_API_SEND_DATA*)gki_utils->getbuf(
1049 (uint16_t)(sizeof(tNFA_EE_API_SEND_DATA) + data_len));
1050 if (p_msg != nullptr) {
1051 p_msg->hdr.event = NFA_EE_API_SEND_DATA_EVT;
1052 p_msg->nfcee_id = nfcee_id;
1053 p_msg->p_cb = p_cb;
1054 p_msg->data_len = data_len;
1055 p_msg->p_data = (uint8_t*)(p_msg + 1);
1056 memcpy(p_msg->p_data, p_data, data_len);
1057
1058 nfa_sys_sendmsg(p_msg);
1059
1060 status = NFA_STATUS_OK;
1061 }
1062 }
1063
1064 return status;
1065 }
1066
1067 /*******************************************************************************
1068 **
1069 ** Function NFA_EeDisconnect
1070 **
1071 ** Description Disconnect (if a connection is currently open) from an
1072 ** NFCEE interface. The result of this operation is reported
1073 ** with the NFA_EE_DISCONNECT_EVT.
1074 **
1075 ** Returns NFA_STATUS_OK if successfully initiated
1076 ** NFA_STATUS_FAILED otherwise
1077 ** NFA_STATUS_INVALID_PARAM If bad parameter
1078 **
1079 *******************************************************************************/
NFA_EeDisconnect(tNFA_HANDLE ee_handle)1080 tNFA_STATUS NFA_EeDisconnect(tNFA_HANDLE ee_handle) {
1081 tNFA_EE_API_DISCONNECT* p_msg;
1082 tNFA_STATUS status = NFA_STATUS_FAILED;
1083 uint8_t nfcee_id = (uint8_t)(ee_handle & 0xFF);
1084 tNFA_EE_ECB* p_cb;
1085
1086 LOG(VERBOSE) << StringPrintf("%s: handle:<0x%x>", __func__, ee_handle);
1087 p_cb = nfa_ee_find_ecb(nfcee_id);
1088
1089 if (gki_utils == nullptr) {
1090 gki_utils = new GkiUtils();
1091 }
1092
1093 if ((p_cb == nullptr) || (p_cb->conn_st != NFA_EE_CONN_ST_CONN)) {
1094 LOG(ERROR) << StringPrintf("%s: Bad ee_handle", __func__);
1095 status = NFA_STATUS_INVALID_PARAM;
1096 } else {
1097 p_msg = (tNFA_EE_API_DISCONNECT*)gki_utils->getbuf(
1098 sizeof(tNFA_EE_API_DISCONNECT));
1099 if (p_msg != nullptr) {
1100 p_msg->hdr.event = NFA_EE_API_DISCONNECT_EVT;
1101 p_msg->nfcee_id = nfcee_id;
1102 p_msg->p_cb = p_cb;
1103
1104 nfa_sys_sendmsg(p_msg);
1105
1106 status = NFA_STATUS_OK;
1107 }
1108 }
1109
1110 return status;
1111 }
1112
1113 /*******************************************************************************
1114 **
1115 ** Function NFA_EePowerAndLinkCtrl
1116 **
1117 ** Description This Control Message is used by the DH to constrain the way
1118 ** the NFCC manages the power supply and communication links
1119 ** between the NFCC and its connected NFCEEs.
1120 **
1121 ** Returns NFA_STATUS_OK if successfully initiated
1122 ** NFA_STATUS_FAILED otherwise
1123 ** NFA_STATUS_INVALID_PARAM If bad parameter
1124 **
1125 *******************************************************************************/
NFA_EePowerAndLinkCtrl(tNFA_HANDLE ee_handle,uint8_t config)1126 tNFA_STATUS NFA_EePowerAndLinkCtrl(tNFA_HANDLE ee_handle, uint8_t config) {
1127 tNFA_EE_API_PWR_AND_LINK_CTRL* p_msg;
1128 tNFA_STATUS status = NFA_STATUS_FAILED;
1129 uint8_t nfcee_id = (uint8_t)(ee_handle & 0xFF);
1130 tNFA_EE_ECB* p_cb;
1131
1132 LOG(VERBOSE) << StringPrintf("%s: handle:<0x%x>, config:<0x%x>", __func__,
1133 ee_handle, config);
1134 p_cb = nfa_ee_find_ecb(nfcee_id);
1135
1136 if (gki_utils == nullptr) {
1137 gki_utils = new GkiUtils();
1138 }
1139
1140 if ((p_cb == nullptr) || (p_cb->ee_status != NFA_EE_STATUS_ACTIVE)) {
1141 LOG(ERROR) << StringPrintf("%s: Bad ee_handle", __func__);
1142 status = NFA_STATUS_INVALID_PARAM;
1143 } else {
1144 p_msg = (tNFA_EE_API_PWR_AND_LINK_CTRL*)gki_utils->getbuf(
1145 sizeof(tNFA_EE_API_PWR_AND_LINK_CTRL));
1146 if (p_msg != nullptr) {
1147 p_msg->hdr.event = NFA_EE_API_PWR_AND_LINK_CTRL_EVT;
1148 p_msg->nfcee_id = nfcee_id;
1149 p_msg->config = config;
1150
1151 nfa_sys_sendmsg(p_msg);
1152
1153 status = NFA_STATUS_OK;
1154 }
1155 }
1156
1157 return status;
1158 }
1159
1160 /*******************************************************************************
1161 **
1162 ** Function NFA_EeClearRoutingTable
1163 **
1164 ** Description Clears all SC, tech and protocol entries in RT
1165 **
1166 ** Returns NFA_STATUS_OK if successful
1167 **
1168 *******************************************************************************/
NFA_EeClearRoutingTable(bool clear_tech,bool clear_proto,bool clear_sc)1169 tNFA_STATUS NFA_EeClearRoutingTable(bool clear_tech, bool clear_proto,
1170 bool clear_sc) {
1171 tNFA_EE_API_CLEAR_ROUTING_TABLE* p_msg;
1172 tNFA_STATUS status = NFA_STATUS_FAILED;
1173
1174 LOG(DEBUG) << StringPrintf("%s: clear_tech=%d, clear_proto=%d, clear_sc=%d",
1175 __func__, clear_tech, clear_proto, clear_sc);
1176
1177 if (gki_utils == nullptr) {
1178 gki_utils = new GkiUtils();
1179 }
1180
1181 if ((p_msg = (tNFA_EE_API_CLEAR_ROUTING_TABLE*)gki_utils->getbuf(
1182 sizeof(tNFA_EE_API_CLEAR_ROUTING_TABLE))) != nullptr) {
1183 p_msg->hdr.event = NFA_EE_API_CLEAR_ROUTING_TABLE_EVT;
1184 p_msg->clear_tech = clear_tech;
1185 p_msg->clear_proto = clear_proto;
1186 p_msg->clear_sc = clear_sc;
1187 p_msg->p_cb = 0;
1188
1189 nfa_sys_sendmsg(p_msg);
1190
1191 status = NFA_STATUS_OK;
1192 }
1193
1194 return status;
1195 }
1196