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