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 #include <string.h>
26 #include "nfa_dm_int.h"
27 #include "nfa_ee_int.h"
28 #include "nfa_sys_int.h"
29
30 /*****************************************************************************
31 ** APIs
32 *****************************************************************************/
33 /*******************************************************************************
34 **
35 ** Function NFA_EeDiscover
36 **
37 ** Description This function retrieves the NFCEE information from NFCC.
38 ** The NFCEE information is reported in NFA_EE_DISCOVER_EVT.
39 **
40 ** This function may be called when a system supports removable
41 ** NFCEEs,
42 **
43 ** Returns NFA_STATUS_OK if information is retrieved successfully
44 ** NFA_STATUS_FAILED If wrong state (retry later)
45 ** NFA_STATUS_INVALID_PARAM If bad parameter
46 **
47 *******************************************************************************/
NFA_EeDiscover(tNFA_EE_CBACK * p_cback)48 tNFA_STATUS NFA_EeDiscover(tNFA_EE_CBACK* p_cback) {
49 tNFA_EE_API_DISCOVER* p_msg;
50 tNFA_STATUS status = NFA_STATUS_FAILED;
51
52 NFA_TRACE_API0("NFA_EeDiscover()");
53
54 if (nfa_ee_cb.em_state != NFA_EE_EM_STATE_INIT_DONE) {
55 NFA_TRACE_ERROR1("NFA_EeDiscover bad em state: %d", nfa_ee_cb.em_state);
56 status = NFA_STATUS_FAILED;
57 } else if ((nfa_ee_cb.p_ee_disc_cback != NULL) || (p_cback == NULL)) {
58 NFA_TRACE_ERROR0("NFA_EeDiscover() in progress or NULL callback function");
59 status = NFA_STATUS_INVALID_PARAM;
60 } else {
61 p_msg = (tNFA_EE_API_DISCOVER*)GKI_getbuf(sizeof(tNFA_EE_API_DISCOVER));
62 if (p_msg != NULL) {
63 p_msg->hdr.event = NFA_EE_API_DISCOVER_EVT;
64 p_msg->p_cback = p_cback;
65
66 nfa_sys_sendmsg(p_msg);
67
68 status = NFA_STATUS_OK;
69 }
70 }
71
72 return status;
73 }
74
75 /*******************************************************************************
76 **
77 ** Function NFA_EeGetInfo
78 **
79 ** Description This function retrieves the NFCEE information from NFA.
80 ** The actual number of NFCEE is returned in p_num_nfcee
81 ** and NFCEE information is returned in p_info
82 **
83 ** Returns NFA_STATUS_OK if information is retrieved successfully
84 ** NFA_STATUS_FAILED If wrong state (retry later)
85 ** NFA_STATUS_INVALID_PARAM If bad parameter
86 **
87 *******************************************************************************/
NFA_EeGetInfo(uint8_t * p_num_nfcee,tNFA_EE_INFO * p_info)88 tNFA_STATUS NFA_EeGetInfo(uint8_t* p_num_nfcee, tNFA_EE_INFO* p_info) {
89 int xx, ret = nfa_ee_cb.cur_ee;
90 tNFA_EE_ECB* p_cb = nfa_ee_cb.ecb;
91 uint8_t max_ret;
92 uint8_t num_ret = 0;
93
94 NFA_TRACE_DEBUG2("NFA_EeGetInfo em_state:%d cur_ee:%d", nfa_ee_cb.em_state,
95 nfa_ee_cb.cur_ee);
96 /* validate parameters */
97 if (p_info == NULL || p_num_nfcee == NULL) {
98 NFA_TRACE_ERROR0("NFA_EeGetInfo bad parameter");
99 return (NFA_STATUS_INVALID_PARAM);
100 }
101 max_ret = *p_num_nfcee;
102 *p_num_nfcee = 0;
103 if (nfa_ee_cb.em_state == NFA_EE_EM_STATE_INIT) {
104 NFA_TRACE_ERROR1("NFA_EeGetInfo bad em state: %d", nfa_ee_cb.em_state);
105 return (NFA_STATUS_FAILED);
106 }
107
108 /* compose output */
109 for (xx = 0; (xx < ret) && (num_ret < max_ret); xx++, p_cb++) {
110 NFA_TRACE_DEBUG4("xx:%d max_ret:%d, num_ret:%d ee_status:0x%x", xx, max_ret,
111 num_ret, p_cb->ee_status);
112 if ((p_cb->ee_status & NFA_EE_STATUS_INT_MASK) ||
113 (p_cb->ee_status == NFA_EE_STATUS_REMOVED)) {
114 continue;
115 }
116 p_info->ee_handle = NFA_HANDLE_GROUP_EE | (tNFA_HANDLE)p_cb->nfcee_id;
117 p_info->ee_status = p_cb->ee_status;
118 p_info->num_interface = p_cb->num_interface;
119 p_info->num_tlvs = p_cb->num_tlvs;
120 memcpy(p_info->ee_interface, p_cb->ee_interface, p_cb->num_interface);
121 memcpy(p_info->ee_tlv, p_cb->ee_tlv, p_cb->num_tlvs * sizeof(tNFA_EE_TLV));
122 p_info++;
123 num_ret++;
124 }
125 NFA_TRACE_DEBUG1("num_ret:%d", num_ret);
126 *p_num_nfcee = num_ret;
127 return (NFA_STATUS_OK);
128 }
129
130 /*******************************************************************************
131 **
132 ** Function NFA_EeRegister
133 **
134 ** Description This function registers a callback function to receive the
135 ** events from NFA-EE module.
136 **
137 ** Returns NFA_STATUS_OK if successfully initiated
138 ** NFA_STATUS_FAILED otherwise
139 ** NFA_STATUS_INVALID_PARAM If bad parameter
140 **
141 *******************************************************************************/
NFA_EeRegister(tNFA_EE_CBACK * p_cback)142 tNFA_STATUS NFA_EeRegister(tNFA_EE_CBACK* p_cback) {
143 tNFA_EE_API_REGISTER* p_msg;
144 tNFA_STATUS status = NFA_STATUS_FAILED;
145
146 NFA_TRACE_API0("NFA_EeRegister()");
147
148 if (p_cback == NULL) {
149 NFA_TRACE_ERROR0("NFA_EeRegister(): with NULL callback function");
150 status = NFA_STATUS_INVALID_PARAM;
151 } else {
152 p_msg = (tNFA_EE_API_REGISTER*)GKI_getbuf(sizeof(tNFA_EE_API_REGISTER));
153 if (p_msg != NULL) {
154 p_msg->hdr.event = NFA_EE_API_REGISTER_EVT;
155 p_msg->p_cback = p_cback;
156
157 nfa_sys_sendmsg(p_msg);
158
159 status = NFA_STATUS_OK;
160 }
161 }
162
163 return status;
164 }
165
166 /*******************************************************************************
167 **
168 ** Function NFA_EeDeregister
169 **
170 ** Description This function de-registers the callback function
171 **
172 ** Returns NFA_STATUS_OK if successfully initiated
173 ** NFA_STATUS_FAILED otherwise
174 ** NFA_STATUS_INVALID_PARAM If bad parameter
175 **
176 *******************************************************************************/
NFA_EeDeregister(tNFA_EE_CBACK * p_cback)177 tNFA_STATUS NFA_EeDeregister(tNFA_EE_CBACK* p_cback) {
178 tNFA_EE_API_DEREGISTER* p_msg;
179 tNFA_STATUS status = NFA_STATUS_INVALID_PARAM;
180 int index = NFA_EE_MAX_CBACKS;
181 int xx;
182
183 for (xx = 0; xx < NFA_EE_MAX_CBACKS; xx++) {
184 if (nfa_ee_cb.p_ee_cback[xx] == p_cback) {
185 index = xx;
186 status = NFA_STATUS_FAILED;
187 break;
188 }
189 }
190
191 NFA_TRACE_API2("NFA_EeDeregister() %d, status:%d", index, status);
192 if ((status != NFA_STATUS_INVALID_PARAM) &&
193 (p_msg = (tNFA_EE_API_DEREGISTER*)GKI_getbuf(
194 sizeof(tNFA_EE_API_DEREGISTER))) != NULL) {
195 p_msg->hdr.event = NFA_EE_API_DEREGISTER_EVT;
196 p_msg->index = index;
197
198 nfa_sys_sendmsg(p_msg);
199
200 status = NFA_STATUS_OK;
201 }
202
203 return status;
204 }
205
206 /*******************************************************************************
207 **
208 ** Function NFA_EeModeSet
209 **
210 ** Description This function is called to activate
211 ** (mode = NFA_EE_MD_ACTIVATE) or deactivate
212 ** (mode = NFA_EE_MD_DEACTIVATE) the NFCEE identified by the
213 ** given ee_handle. The result of this operation is reported
214 ** with the NFA_EE_MODE_SET_EVT.
215 **
216 ** Returns NFA_STATUS_OK if successfully initiated
217 ** NFA_STATUS_FAILED otherwise
218 ** NFA_STATUS_INVALID_PARAM If bad parameter
219 **
220 *******************************************************************************/
NFA_EeModeSet(tNFA_HANDLE ee_handle,tNFA_EE_MD mode)221 tNFA_STATUS NFA_EeModeSet(tNFA_HANDLE ee_handle, tNFA_EE_MD mode) {
222 tNFA_EE_API_MODE_SET* p_msg;
223 tNFA_STATUS status = NFA_STATUS_FAILED;
224 tNFA_EE_ECB *p_cb, *p_found = NULL;
225 uint32_t xx;
226 uint8_t nfcee_id = (ee_handle & 0xFF);
227
228 p_cb = nfa_ee_cb.ecb;
229 for (xx = 0; xx < nfa_ee_cb.cur_ee; xx++, p_cb++) {
230 if (nfcee_id == p_cb->nfcee_id) {
231 p_found = p_cb;
232 break;
233 }
234 }
235 NFA_TRACE_API2("NFA_EeModeSet(): handle:<0x%x>, mode:0x%02X", ee_handle,
236 mode);
237
238 if (p_found == NULL) {
239 NFA_TRACE_ERROR1("NFA_EeModeSet() invalid NFCEE:0x%04x", ee_handle);
240 status = NFA_STATUS_INVALID_PARAM;
241 } else {
242 p_msg = (tNFA_EE_API_MODE_SET*)GKI_getbuf(sizeof(tNFA_EE_API_MODE_SET));
243 if (p_msg != NULL) {
244 p_msg->hdr.event = NFA_EE_API_MODE_SET_EVT;
245 p_msg->nfcee_id = nfcee_id;
246 p_msg->mode = mode;
247 p_msg->p_cb = p_found;
248
249 nfa_sys_sendmsg(p_msg);
250
251 status = NFA_STATUS_OK;
252 }
253 }
254
255 return status;
256 }
257
258 /*******************************************************************************
259 **
260 ** Function NFA_EeSetDefaultTechRouting
261 **
262 ** Description This function is called to add, change or remove the
263 ** default routing based on RF technology in the listen mode
264 ** routing table for the given ee_handle. The status of this
265 ** operation is reported as the NFA_EE_SET_TECH_CFG_EVT.
266 **
267 ** Note: If RF discovery is started,
268 ** NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should
269 ** happen before calling this function
270 **
271 ** Note: NFA_EeUpdateNow() should be called after last NFA-EE
272 ** function to change the listen mode routing is called.
273 **
274 ** Returns NFA_STATUS_OK if successfully initiated
275 ** NFA_STATUS_FAILED otherwise
276 ** NFA_STATUS_INVALID_PARAM If bad parameter
277 **
278 *******************************************************************************/
NFA_EeSetDefaultTechRouting(tNFA_HANDLE ee_handle,tNFA_TECHNOLOGY_MASK technologies_switch_on,tNFA_TECHNOLOGY_MASK technologies_switch_off,tNFA_TECHNOLOGY_MASK technologies_battery_off)279 tNFA_STATUS NFA_EeSetDefaultTechRouting(
280 tNFA_HANDLE ee_handle, tNFA_TECHNOLOGY_MASK technologies_switch_on,
281 tNFA_TECHNOLOGY_MASK technologies_switch_off,
282 tNFA_TECHNOLOGY_MASK technologies_battery_off) {
283 tNFA_EE_API_SET_TECH_CFG* p_msg;
284 tNFA_STATUS status = NFA_STATUS_FAILED;
285 uint8_t nfcee_id = (uint8_t)(ee_handle & 0xFF);
286 tNFA_EE_ECB* p_cb;
287
288 NFA_TRACE_API4(
289 "NFA_EeSetDefaultTechRouting(): "
290 "handle:<0x%x>technology_mask:<0x%x>/<0x%x>/<0x%x>",
291 ee_handle, technologies_switch_on, technologies_switch_off,
292 technologies_battery_off);
293 p_cb = nfa_ee_find_ecb(nfcee_id);
294
295 if (p_cb == NULL) {
296 NFA_TRACE_ERROR0("Bad ee_handle");
297 status = NFA_STATUS_INVALID_PARAM;
298 } else {
299 p_msg =
300 (tNFA_EE_API_SET_TECH_CFG*)GKI_getbuf(sizeof(tNFA_EE_API_SET_TECH_CFG));
301 if (p_msg != NULL) {
302 p_msg->hdr.event = NFA_EE_API_SET_TECH_CFG_EVT;
303 p_msg->nfcee_id = nfcee_id;
304 p_msg->p_cb = p_cb;
305 p_msg->technologies_switch_on = technologies_switch_on;
306 p_msg->technologies_switch_off = technologies_switch_off;
307 p_msg->technologies_battery_off = technologies_battery_off;
308
309 nfa_sys_sendmsg(p_msg);
310
311 status = NFA_STATUS_OK;
312 }
313 }
314
315 return status;
316 }
317
318 /*******************************************************************************
319 **
320 ** Function NFA_EeSetDefaultProtoRouting
321 **
322 ** Description This function is called to add, change or remove the
323 ** default routing based on Protocol in the listen mode routing
324 ** table for the given ee_handle. The status of this
325 ** operation is reported as the NFA_EE_SET_PROTO_CFG_EVT.
326 **
327 ** Note: If RF discovery is started,
328 ** NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should
329 ** happen before calling this function
330 **
331 ** Note: NFA_EeUpdateNow() should be called after last NFA-EE
332 ** function to change the listen mode routing is called.
333 **
334 ** Returns NFA_STATUS_OK if successfully initiated
335 ** NFA_STATUS_FAILED otherwise
336 ** NFA_STATUS_INVALID_PARAM If bad parameter
337 **
338 *******************************************************************************/
NFA_EeSetDefaultProtoRouting(tNFA_HANDLE ee_handle,tNFA_PROTOCOL_MASK protocols_switch_on,tNFA_PROTOCOL_MASK protocols_switch_off,tNFA_PROTOCOL_MASK protocols_battery_off)339 tNFA_STATUS NFA_EeSetDefaultProtoRouting(
340 tNFA_HANDLE ee_handle, tNFA_PROTOCOL_MASK protocols_switch_on,
341 tNFA_PROTOCOL_MASK protocols_switch_off,
342 tNFA_PROTOCOL_MASK protocols_battery_off) {
343 tNFA_EE_API_SET_PROTO_CFG* p_msg;
344 tNFA_STATUS status = NFA_STATUS_FAILED;
345 uint8_t nfcee_id = (uint8_t)(ee_handle & 0xFF);
346 tNFA_EE_ECB* p_cb;
347
348 NFA_TRACE_API4(
349 "NFA_EeSetDefaultProtoRouting(): "
350 "handle:<0x%x>protocol_mask:<0x%x>/<0x%x>/<0x%x>",
351 ee_handle, protocols_switch_on, protocols_switch_off,
352 protocols_battery_off);
353 p_cb = nfa_ee_find_ecb(nfcee_id);
354
355 if (p_cb == NULL) {
356 NFA_TRACE_ERROR0("Bad ee_handle");
357 status = NFA_STATUS_INVALID_PARAM;
358 } else {
359 p_msg = (tNFA_EE_API_SET_PROTO_CFG*)GKI_getbuf(
360 sizeof(tNFA_EE_API_SET_PROTO_CFG));
361 if (p_msg != NULL) {
362 p_msg->hdr.event = NFA_EE_API_SET_PROTO_CFG_EVT;
363 p_msg->nfcee_id = nfcee_id;
364 p_msg->p_cb = p_cb;
365 p_msg->protocols_switch_on = protocols_switch_on;
366 p_msg->protocols_switch_off = protocols_switch_off;
367 p_msg->protocols_battery_off = protocols_battery_off;
368
369 nfa_sys_sendmsg(p_msg);
370
371 status = NFA_STATUS_OK;
372 }
373 }
374
375 return status;
376 }
377
378 /*******************************************************************************
379 **
380 ** Function NFA_EeAddAidRouting
381 **
382 ** Description This function is called to add an AID entry in the
383 ** listen mode routing table in NFCC. The status of this
384 ** operation is reported as the NFA_EE_ADD_AID_EVT.
385 **
386 ** Note: If RF discovery is started,
387 ** NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should
388 ** happen before calling this function
389 **
390 ** Note: NFA_EeUpdateNow() should be called after last NFA-EE
391 ** function to change the listen mode routing is called.
392 **
393 ** Returns NFA_STATUS_OK if successfully initiated
394 ** NFA_STATUS_FAILED otherwise
395 ** NFA_STATUS_INVALID_PARAM If bad parameter
396 **
397 *******************************************************************************/
NFA_EeAddAidRouting(tNFA_HANDLE ee_handle,uint8_t aid_len,uint8_t * p_aid,tNFA_EE_PWR_STATE power_state)398 tNFA_STATUS NFA_EeAddAidRouting(tNFA_HANDLE ee_handle, uint8_t aid_len,
399 uint8_t* p_aid, tNFA_EE_PWR_STATE power_state) {
400 tNFA_EE_API_ADD_AID* p_msg;
401 tNFA_STATUS status = NFA_STATUS_FAILED;
402 uint16_t size = sizeof(tNFA_EE_API_ADD_AID) + aid_len;
403 uint8_t nfcee_id = (uint8_t)(ee_handle & 0xFF);
404 tNFA_EE_ECB* p_cb;
405
406 NFA_TRACE_API1("NFA_EeAddAidRouting(): handle:<0x%x>", ee_handle);
407 p_cb = nfa_ee_find_ecb(nfcee_id);
408
409 /* validate parameters - make sure the AID is in valid length range */
410 if ((p_cb == NULL) || (aid_len == 0) || (p_aid == NULL) ||
411 (aid_len < NFA_MIN_AID_LEN) || (aid_len > NFA_MAX_AID_LEN)) {
412 NFA_TRACE_ERROR1("Bad ee_handle or AID (len=%d)", aid_len);
413 status = NFA_STATUS_INVALID_PARAM;
414 } else {
415 p_msg = (tNFA_EE_API_ADD_AID*)GKI_getbuf(size);
416 if (p_msg != NULL) {
417 NFA_TRACE_DEBUG2("aid:<%02x%02x>", p_aid[0], p_aid[1]);
418 p_msg->hdr.event = NFA_EE_API_ADD_AID_EVT;
419 p_msg->nfcee_id = nfcee_id;
420 p_msg->p_cb = p_cb;
421 p_msg->aid_len = aid_len;
422 p_msg->power_state = power_state;
423 p_msg->p_aid = (uint8_t*)(p_msg + 1);
424 memcpy(p_msg->p_aid, p_aid, aid_len);
425
426 nfa_sys_sendmsg(p_msg);
427
428 status = NFA_STATUS_OK;
429 }
430 }
431
432 return status;
433 }
434
435 /*******************************************************************************
436 **
437 ** Function NFA_EeRemoveAidRouting
438 **
439 ** Description This function is called to remove the given AID entry from
440 ** the listen mode routing table. If the entry configures VS,
441 ** it is also removed. The status of this operation is reported
442 ** as the NFA_EE_REMOVE_AID_EVT.
443 **
444 ** Note: If RF discovery is started,
445 ** NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT should
446 ** happen before calling this function
447 **
448 ** Note: NFA_EeUpdateNow() should be called after last NFA-EE
449 ** function to change the listen mode routing is called.
450 **
451 ** Returns NFA_STATUS_OK if successfully initiated
452 ** NFA_STATUS_FAILED otherwise
453 ** NFA_STATUS_INVALID_PARAM If bad parameter
454 **
455 *******************************************************************************/
NFA_EeRemoveAidRouting(uint8_t aid_len,uint8_t * p_aid)456 tNFA_STATUS NFA_EeRemoveAidRouting(uint8_t aid_len, uint8_t* p_aid) {
457 tNFA_EE_API_REMOVE_AID* p_msg;
458 tNFA_STATUS status = NFA_STATUS_FAILED;
459 uint16_t size = sizeof(tNFA_EE_API_REMOVE_AID) + aid_len;
460
461 NFA_TRACE_API0("NFA_EeRemoveAidRouting()");
462 if ((aid_len == 0) || (p_aid == NULL) || (aid_len > NFA_MAX_AID_LEN)) {
463 NFA_TRACE_ERROR0("Bad AID");
464 status = NFA_STATUS_INVALID_PARAM;
465 } else {
466 p_msg = (tNFA_EE_API_REMOVE_AID*)GKI_getbuf(size);
467 if (p_msg != NULL) {
468 p_msg->hdr.event = NFA_EE_API_REMOVE_AID_EVT;
469 p_msg->aid_len = aid_len;
470 p_msg->p_aid = (uint8_t*)(p_msg + 1);
471 memcpy(p_msg->p_aid, p_aid, aid_len);
472
473 nfa_sys_sendmsg(p_msg);
474
475 status = NFA_STATUS_OK;
476 }
477 }
478
479 return status;
480 }
481
482 /*******************************************************************************
483 **
484 ** Function NFA_EeGetLmrtRemainingSize
485 **
486 ** Description This function is called to get remaining size of the
487 ** Listen Mode Routing Table.
488 ** The remaining size is reported in NFA_EE_REMAINING_SIZE_EVT
489 **
490 ** Returns NFA_STATUS_OK if successfully initiated
491 ** NFA_STATUS_FAILED otherwise
492 **
493 *******************************************************************************/
NFA_EeGetLmrtRemainingSize(void)494 tNFA_STATUS NFA_EeGetLmrtRemainingSize(void) {
495 tNFA_EE_API_LMRT_SIZE* p_msg;
496 tNFA_STATUS status = NFA_STATUS_FAILED;
497
498 NFA_TRACE_API0("NFA_EeGetLmrtRemainingSize()");
499 p_msg = (tNFA_EE_API_LMRT_SIZE*)GKI_getbuf(sizeof(tNFA_EE_API_LMRT_SIZE));
500 if (p_msg != NULL) {
501 p_msg->event = NFA_EE_API_LMRT_SIZE_EVT;
502 nfa_sys_sendmsg(p_msg);
503 status = NFA_STATUS_OK;
504 }
505
506 return status;
507 }
508
509 /******************************************************************************
510 **
511 ** Function NFA_EeUpdateNow
512 **
513 ** Description This function is called to send the current listen mode
514 ** routing table and VS configuration to the NFCC (without
515 ** waiting for NFA_EE_ROUT_TIMEOUT_VAL).
516 **
517 ** The status of this operation is
518 ** reported with the NFA_EE_UPDATED_EVT.
519 **
520 ** Returns NFA_STATUS_OK if successfully initiated
521 ** NFA_STATUS_SEMANTIC_ERROR is update is currently in progress
522 ** NFA_STATUS_FAILED otherwise
523 **
524 *******************************************************************************/
NFA_EeUpdateNow(void)525 tNFA_STATUS NFA_EeUpdateNow(void) {
526 NFC_HDR* p_msg;
527 tNFA_STATUS status = NFA_STATUS_FAILED;
528
529 NFA_TRACE_API0("NFA_EeUpdateNow()");
530 if (nfa_ee_cb.ee_wait_evt & NFA_EE_WAIT_UPDATE_ALL) {
531 NFA_TRACE_ERROR0("update in progress");
532 status = NFA_STATUS_SEMANTIC_ERROR;
533 } else {
534 p_msg = (NFC_HDR*)GKI_getbuf(NFC_HDR_SIZE);
535 if (p_msg != NULL) {
536 p_msg->event = NFA_EE_API_UPDATE_NOW_EVT;
537
538 nfa_sys_sendmsg(p_msg);
539
540 status = NFA_STATUS_OK;
541 }
542 }
543
544 return status;
545 }
546
547 /*******************************************************************************
548 **
549 ** Function NFA_EeConnect
550 **
551 ** Description Open connection to an NFCEE attached to the NFCC
552 **
553 ** The status of this operation is
554 ** reported with the NFA_EE_CONNECT_EVT.
555 **
556 ** Returns NFA_STATUS_OK if successfully initiated
557 ** NFA_STATUS_FAILED otherwise
558 ** NFA_STATUS_INVALID_PARAM If bad parameter
559 **
560 *******************************************************************************/
NFA_EeConnect(tNFA_HANDLE ee_handle,uint8_t ee_interface,tNFA_EE_CBACK * p_cback)561 tNFA_STATUS NFA_EeConnect(tNFA_HANDLE ee_handle, uint8_t ee_interface,
562 tNFA_EE_CBACK* p_cback) {
563 tNFA_EE_API_CONNECT* p_msg;
564 tNFA_STATUS status = NFA_STATUS_FAILED;
565 uint8_t nfcee_id = (uint8_t)(ee_handle & 0xFF);
566 tNFA_EE_ECB* p_cb;
567
568 NFA_TRACE_API2("NFA_EeConnect(): handle:<0x%x> ee_interface:0x%x", ee_handle,
569 ee_interface);
570 p_cb = nfa_ee_find_ecb(nfcee_id);
571
572 if ((p_cb == NULL) || (p_cback == NULL)) {
573 NFA_TRACE_ERROR0("Bad ee_handle or NULL callback function");
574 status = NFA_STATUS_INVALID_PARAM;
575 } else {
576 p_msg = (tNFA_EE_API_CONNECT*)GKI_getbuf(sizeof(tNFA_EE_API_CONNECT));
577 if (p_msg != NULL) {
578 p_msg->hdr.event = NFA_EE_API_CONNECT_EVT;
579 p_msg->nfcee_id = nfcee_id;
580 p_msg->p_cb = p_cb;
581 p_msg->ee_interface = ee_interface;
582 p_msg->p_cback = p_cback;
583
584 nfa_sys_sendmsg(p_msg);
585
586 status = NFA_STATUS_OK;
587 }
588 }
589
590 return status;
591 }
592
593 /*******************************************************************************
594 **
595 ** Function NFA_EeSendData
596 **
597 ** Description Send data to the given NFCEE.
598 ** This function shall be called after NFA_EE_CONNECT_EVT is
599 ** reported and before NFA_EeDisconnect is called on the given
600 ** ee_handle.
601 **
602 ** Returns NFA_STATUS_OK if successfully initiated
603 ** NFA_STATUS_FAILED otherwise
604 ** NFA_STATUS_INVALID_PARAM If bad parameter
605 **
606 *******************************************************************************/
NFA_EeSendData(tNFA_HANDLE ee_handle,uint16_t data_len,uint8_t * p_data)607 tNFA_STATUS NFA_EeSendData(tNFA_HANDLE ee_handle, uint16_t data_len,
608 uint8_t* p_data) {
609 tNFA_EE_API_SEND_DATA* p_msg;
610 tNFA_STATUS status = NFA_STATUS_FAILED;
611 uint8_t nfcee_id = (uint8_t)(ee_handle & 0xFF);
612 tNFA_EE_ECB* p_cb;
613
614 NFA_TRACE_API1("NFA_EeSendData(): handle:<0x%x>", ee_handle);
615
616 p_cb = nfa_ee_find_ecb(nfcee_id);
617
618 if ((p_cb == NULL) || (p_cb->conn_st != NFA_EE_CONN_ST_CONN) ||
619 (p_data == NULL)) {
620 NFA_TRACE_ERROR0("Bad ee_handle or NULL data");
621 status = NFA_STATUS_INVALID_PARAM;
622 } else {
623 p_msg = (tNFA_EE_API_SEND_DATA*)GKI_getbuf(
624 (uint16_t)(sizeof(tNFA_EE_API_SEND_DATA) + data_len));
625 if (p_msg != NULL) {
626 p_msg->hdr.event = NFA_EE_API_SEND_DATA_EVT;
627 p_msg->nfcee_id = nfcee_id;
628 p_msg->p_cb = p_cb;
629 p_msg->data_len = data_len;
630 p_msg->p_data = (uint8_t*)(p_msg + 1);
631 memcpy(p_msg->p_data, p_data, data_len);
632
633 nfa_sys_sendmsg(p_msg);
634
635 status = NFA_STATUS_OK;
636 }
637 }
638
639 return status;
640 }
641
642 /*******************************************************************************
643 **
644 ** Function NFA_EeDisconnect
645 **
646 ** Description Disconnect (if a connection is currently open) from an
647 ** NFCEE interface. The result of this operation is reported
648 ** with the NFA_EE_DISCONNECT_EVT.
649 **
650 ** Returns NFA_STATUS_OK if successfully initiated
651 ** NFA_STATUS_FAILED otherwise
652 ** NFA_STATUS_INVALID_PARAM If bad parameter
653 **
654 *******************************************************************************/
NFA_EeDisconnect(tNFA_HANDLE ee_handle)655 tNFA_STATUS NFA_EeDisconnect(tNFA_HANDLE ee_handle) {
656 tNFA_EE_API_DISCONNECT* p_msg;
657 tNFA_STATUS status = NFA_STATUS_FAILED;
658 uint8_t nfcee_id = (uint8_t)(ee_handle & 0xFF);
659 tNFA_EE_ECB* p_cb;
660
661 NFA_TRACE_API1("NFA_EeDisconnect(): handle:<0x%x>", ee_handle);
662 p_cb = nfa_ee_find_ecb(nfcee_id);
663
664 if ((p_cb == NULL) || (p_cb->conn_st != NFA_EE_CONN_ST_CONN)) {
665 NFA_TRACE_ERROR0("NFA_EeDisconnect() Bad ee_handle");
666 status = NFA_STATUS_INVALID_PARAM;
667 } else {
668 p_msg = (tNFA_EE_API_DISCONNECT*)GKI_getbuf(sizeof(tNFA_EE_API_DISCONNECT));
669 if (p_msg != NULL) {
670 p_msg->hdr.event = NFA_EE_API_DISCONNECT_EVT;
671 p_msg->nfcee_id = nfcee_id;
672 p_msg->p_cb = p_cb;
673
674 nfa_sys_sendmsg(p_msg);
675
676 status = NFA_STATUS_OK;
677 }
678 }
679
680 return status;
681 }
682