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 * This file contains functions that interface with the NFC NCI transport.
22 * On the receive side, it routes events to the appropriate handler
23 * (callback). On the transmit side, it manages the command transmission.
24 *
25 ******************************************************************************/
26 #include <string.h>
27 #include "gki.h"
28 #include "nfc_target.h"
29 #include "bt_types.h"
30 #include "hcidefs.h"
31
32 #if (NFC_INCLUDED == TRUE)
33 #include "nfc_hal_api.h"
34 #include "nfc_api.h"
35 #include "nfc_int.h"
36 #include "nci_hmsgs.h"
37 #include "rw_int.h"
38 #include "ce_int.h"
39
40 #if (NFC_RW_ONLY == FALSE)
41 #include "ce_api.h"
42 #include "ce_int.h"
43 #include "llcp_int.h"
44
45 /* NFC mandates support for at least one logical connection;
46 * Update max_conn to the NFCC capability on InitRsp */
47 #define NFC_SET_MAX_CONN_DEFAULT() {nfc_cb.max_conn = 1;}
48
49 #else /* NFC_RW_ONLY */
50 #define ce_init()
51 #define llcp_init()
52
53 #define NFC_SET_MAX_CONN_DEFAULT()
54
55 #endif /* NFC_RW_ONLY */
56 /****************************************************************************
57 ** Declarations
58 ****************************************************************************/
59 #if NFC_DYNAMIC_MEMORY == FALSE
60 tNFC_CB nfc_cb;
61 #endif
62
63 #if (NFC_RW_ONLY == FALSE)
64 #define NFC_NUM_INTERFACE_MAP 2
65 #else
66 #define NFC_NUM_INTERFACE_MAP 1
67 #endif
68
69 static const tNCI_DISCOVER_MAPS nfc_interface_mapping[NFC_NUM_INTERFACE_MAP] =
70 {
71 /* Protocols that use Frame Interface do not need to be included in the interface mapping */
72 {
73 NCI_PROTOCOL_ISO_DEP,
74 NCI_INTERFACE_MODE_POLL_N_LISTEN,
75 NCI_INTERFACE_ISO_DEP
76 }
77 #if (NFC_RW_ONLY == FALSE)
78 ,
79 /* this can not be set here due to 2079xB0 NFCC issues */
80 {
81 NCI_PROTOCOL_NFC_DEP,
82 NCI_INTERFACE_MODE_POLL_N_LISTEN,
83 NCI_INTERFACE_NFC_DEP
84 }
85 #endif
86 };
87
88
89 #if (BT_TRACE_VERBOSE == TRUE)
90 /*******************************************************************************
91 **
92 ** Function nfc_state_name
93 **
94 ** Description This function returns the state name.
95 **
96 ** NOTE conditionally compiled to save memory.
97 **
98 ** Returns pointer to the name
99 **
100 *******************************************************************************/
nfc_state_name(UINT8 state)101 static char *nfc_state_name (UINT8 state)
102 {
103 switch (state)
104 {
105 case NFC_STATE_NONE:
106 return ("NONE");
107 case NFC_STATE_W4_HAL_OPEN:
108 return ("W4_HAL_OPEN");
109 case NFC_STATE_CORE_INIT:
110 return ("CORE_INIT");
111 case NFC_STATE_W4_POST_INIT_CPLT:
112 return ("W4_POST_INIT_CPLT");
113 case NFC_STATE_IDLE:
114 return ("IDLE");
115 case NFC_STATE_OPEN:
116 return ("OPEN");
117 case NFC_STATE_CLOSING:
118 return ("CLOSING");
119 case NFC_STATE_W4_HAL_CLOSE:
120 return ("W4_HAL_CLOSE");
121 case NFC_STATE_NFCC_POWER_OFF_SLEEP:
122 return ("NFCC_POWER_OFF_SLEEP");
123 default:
124 return ("???? UNKNOWN STATE");
125 }
126 }
127
128 /*******************************************************************************
129 **
130 ** Function nfc_hal_event_name
131 **
132 ** Description This function returns the HAL event name.
133 **
134 ** NOTE conditionally compiled to save memory.
135 **
136 ** Returns pointer to the name
137 **
138 *******************************************************************************/
nfc_hal_event_name(UINT8 event)139 static char *nfc_hal_event_name (UINT8 event)
140 {
141 switch (event)
142 {
143 case HAL_NFC_OPEN_CPLT_EVT:
144 return ("HAL_NFC_OPEN_CPLT_EVT");
145
146 case HAL_NFC_CLOSE_CPLT_EVT:
147 return ("HAL_NFC_CLOSE_CPLT_EVT");
148
149 case HAL_NFC_POST_INIT_CPLT_EVT:
150 return ("HAL_NFC_POST_INIT_CPLT_EVT");
151
152 case HAL_NFC_PRE_DISCOVER_CPLT_EVT:
153 return ("HAL_NFC_PRE_DISCOVER_CPLT_EVT");
154
155 case HAL_NFC_REQUEST_CONTROL_EVT:
156 return ("HAL_NFC_REQUEST_CONTROL_EVT");
157
158 case HAL_NFC_RELEASE_CONTROL_EVT:
159 return ("HAL_NFC_RELEASE_CONTROL_EVT");
160
161 case HAL_NFC_ERROR_EVT:
162 return ("HAL_NFC_ERROR_EVT");
163
164 default:
165 return ("???? UNKNOWN EVENT");
166 }
167 }
168 #endif /* BT_TRACE_VERBOSE == TRUE */
169
170 /*******************************************************************************
171 **
172 ** Function nfc_main_notify_enable_status
173 **
174 ** Description Notify status of Enable/PowerOffSleep/PowerCycle
175 **
176 *******************************************************************************/
nfc_main_notify_enable_status(tNFC_STATUS nfc_status)177 static void nfc_main_notify_enable_status (tNFC_STATUS nfc_status)
178 {
179 tNFC_RESPONSE evt_data;
180
181 evt_data.status = nfc_status;
182
183 if (nfc_cb.p_resp_cback)
184 {
185 /* if getting out of PowerOffSleep mode or restarting NFCC */
186 if (nfc_cb.flags & (NFC_FL_RESTARTING|NFC_FL_POWER_CYCLE_NFCC))
187 {
188 nfc_cb.flags &= ~(NFC_FL_RESTARTING|NFC_FL_POWER_CYCLE_NFCC);
189 if (nfc_status != NFC_STATUS_OK)
190 {
191 nfc_cb.flags |= NFC_FL_POWER_OFF_SLEEP;
192 }
193 (*nfc_cb.p_resp_cback) (NFC_NFCC_RESTART_REVT, &evt_data);
194 }
195 else
196 {
197 (*nfc_cb.p_resp_cback) (NFC_ENABLE_REVT, &evt_data);
198 }
199 }
200 }
201
202 /*******************************************************************************
203 **
204 ** Function nfc_enabled
205 **
206 ** Description NFCC enabled, proceed with stack start up.
207 **
208 ** Returns void
209 **
210 *******************************************************************************/
nfc_enabled(tNFC_STATUS nfc_status,BT_HDR * p_init_rsp_msg)211 void nfc_enabled (tNFC_STATUS nfc_status, BT_HDR *p_init_rsp_msg)
212 {
213 tNFC_RESPONSE evt_data;
214 tNFC_CONN_CB *p_cb = &nfc_cb.conn_cb[NFC_RF_CONN_ID];
215 UINT8 *p;
216 UINT8 num_interfaces = 0, xx;
217 int yy = 0;
218
219 memset (&evt_data, 0, sizeof (tNFC_RESPONSE));
220
221 if (nfc_status == NCI_STATUS_OK)
222 {
223 nfc_set_state (NFC_STATE_IDLE);
224
225 p = (UINT8 *) (p_init_rsp_msg + 1) + p_init_rsp_msg->offset + NCI_MSG_HDR_SIZE + 1;
226 /* we currently only support NCI of the same version.
227 * We may need to change this, when we support multiple version of NFCC */
228 evt_data.enable.nci_version = NCI_VERSION;
229 STREAM_TO_UINT32 (evt_data.enable.nci_features, p);
230 STREAM_TO_UINT8 (num_interfaces, p);
231
232 evt_data.enable.nci_interfaces = 0;
233 for (xx = 0; xx < num_interfaces; xx++)
234 {
235 if ((*p) <= NCI_INTERFACE_MAX)
236 evt_data.enable.nci_interfaces |= (1 << (*p));
237 else if (((*p) > NCI_INTERFACE_FIRST_VS) && (yy < NFC_NFCC_MAX_NUM_VS_INTERFACE))
238 {
239 /* save the VS RF interface in control block, if there's still room */
240 nfc_cb.vs_interface[yy++] = *p;
241 }
242 p++;
243 }
244 nfc_cb.nci_interfaces = evt_data.enable.nci_interfaces;
245 memcpy (evt_data.enable.vs_interface, nfc_cb.vs_interface, NFC_NFCC_MAX_NUM_VS_INTERFACE);
246 evt_data.enable.max_conn = *p++;
247 STREAM_TO_UINT16 (evt_data.enable.max_ce_table, p);
248 #if (NFC_RW_ONLY == FALSE)
249 nfc_cb.max_ce_table = evt_data.enable.max_ce_table;
250 nfc_cb.nci_features = evt_data.enable.nci_features;
251 nfc_cb.max_conn = evt_data.enable.max_conn;
252 #endif
253 nfc_cb.nci_ctrl_size = *p++; /* Max Control Packet Payload Length */
254 p_cb->init_credits = p_cb->num_buff = 0;
255 STREAM_TO_UINT16 (evt_data.enable.max_param_size, p);
256 nfc_set_conn_id (p_cb, NFC_RF_CONN_ID);
257 evt_data.enable.manufacture_id = *p++;
258 STREAM_TO_ARRAY (evt_data.enable.nfcc_info, p, NFC_NFCC_INFO_LEN);
259 NFC_DiscoveryMap (nfc_cb.num_disc_maps, (tNCI_DISCOVER_MAPS *) nfc_cb.p_disc_maps, NULL);
260 }
261 /* else not successful. the buffers will be freed in nfc_free_conn_cb () */
262 else
263 {
264 if (nfc_cb.flags & NFC_FL_RESTARTING)
265 {
266 nfc_set_state (NFC_STATE_NFCC_POWER_OFF_SLEEP);
267 }
268 else
269 {
270 nfc_free_conn_cb (p_cb);
271
272 /* if NFCC didn't respond to CORE_RESET or CORE_INIT */
273 if (nfc_cb.nfc_state == NFC_STATE_CORE_INIT)
274 {
275 /* report status after closing HAL */
276 nfc_cb.p_hal->close ();
277 return;
278 }
279 else
280 nfc_set_state (NFC_STATE_NONE);
281 }
282 }
283
284 nfc_main_notify_enable_status (nfc_status);
285 }
286
287 /*******************************************************************************
288 **
289 ** Function nfc_set_state
290 **
291 ** Description Set the state of NFC stack
292 **
293 ** Returns void
294 **
295 *******************************************************************************/
nfc_set_state(tNFC_STATE nfc_state)296 void nfc_set_state (tNFC_STATE nfc_state)
297 {
298 #if (BT_TRACE_VERBOSE == TRUE)
299 NFC_TRACE_DEBUG4 ("nfc_set_state %d (%s)->%d (%s)", nfc_cb.nfc_state, nfc_state_name (nfc_cb.nfc_state), nfc_state, nfc_state_name (nfc_state));
300 #else
301 NFC_TRACE_DEBUG2 ("nfc_set_state %d->%d", nfc_cb.nfc_state, nfc_state);
302 #endif
303 nfc_cb.nfc_state = nfc_state;
304 }
305
306 /*******************************************************************************
307 **
308 ** Function nfc_gen_cleanup
309 **
310 ** Description Clean up for both going into low power mode and disabling NFC
311 **
312 *******************************************************************************/
nfc_gen_cleanup(void)313 void nfc_gen_cleanup (void)
314 {
315 nfc_cb.flags &= ~NFC_FL_DEACTIVATING;
316
317 /* the HAL pre-discover is still active - clear the pending flag/free the buffer */
318 if (nfc_cb.flags & NFC_FL_DISCOVER_PENDING)
319 {
320 nfc_cb.flags &= ~NFC_FL_DISCOVER_PENDING;
321 GKI_freebuf (nfc_cb.p_disc_pending);
322 nfc_cb.p_disc_pending = NULL;
323 }
324
325 nfc_cb.flags &= ~(NFC_FL_CONTROL_REQUESTED|NFC_FL_CONTROL_GRANTED);
326
327 nfc_stop_timer (&nfc_cb.deactivate_timer);
328
329 /* Reset the connection control blocks */
330 nfc_reset_all_conn_cbs ();
331
332 if (nfc_cb.p_nci_init_rsp)
333 {
334 GKI_freebuf (nfc_cb.p_nci_init_rsp);
335 nfc_cb.p_nci_init_rsp = NULL;
336 }
337
338 /* clear any pending CMD/RSP */
339 nfc_main_flush_cmd_queue ();
340 }
341
342 /*******************************************************************************
343 **
344 ** Function nfc_main_handle_hal_evt
345 **
346 ** Description Handle BT_EVT_TO_NFC_MSGS
347 **
348 *******************************************************************************/
nfc_main_handle_hal_evt(tNFC_HAL_EVT_MSG * p_msg)349 void nfc_main_handle_hal_evt (tNFC_HAL_EVT_MSG *p_msg)
350 {
351 UINT8 *ps;
352
353 NFC_TRACE_DEBUG1 ("nfc_main_handle_hal_evt(): HAL event=0x%x", p_msg->hal_evt);
354
355 switch (p_msg->hal_evt)
356 {
357 case HAL_NFC_OPEN_CPLT_EVT: /* only for failure case */
358 nfc_enabled (NFC_STATUS_FAILED, NULL);
359 break;
360
361 case HAL_NFC_CLOSE_CPLT_EVT:
362 if (nfc_cb.p_resp_cback)
363 {
364 if (nfc_cb.nfc_state == NFC_STATE_W4_HAL_CLOSE)
365 {
366 if (nfc_cb.flags & NFC_FL_POWER_OFF_SLEEP)
367 {
368 nfc_cb.flags &= ~NFC_FL_POWER_OFF_SLEEP;
369 nfc_set_state (NFC_STATE_NFCC_POWER_OFF_SLEEP);
370 (*nfc_cb.p_resp_cback) (NFC_NFCC_POWER_OFF_REVT, NULL);
371 }
372 else
373 {
374 nfc_set_state (NFC_STATE_NONE);
375 (*nfc_cb.p_resp_cback) (NFC_DISABLE_REVT, NULL);
376 nfc_cb.p_resp_cback = NULL;
377 }
378 }
379 else
380 {
381 /* found error during initialization */
382 nfc_set_state (NFC_STATE_NONE);
383 nfc_main_notify_enable_status (NFC_STATUS_FAILED);
384 }
385 }
386 break;
387
388 case HAL_NFC_POST_INIT_CPLT_EVT:
389 if (nfc_cb.p_nci_init_rsp)
390 {
391 /*
392 ** if NFC_Disable() is called before receiving HAL_NFC_POST_INIT_CPLT_EVT,
393 ** then wait for HAL_NFC_CLOSE_CPLT_EVT.
394 */
395 if (nfc_cb.nfc_state == NFC_STATE_W4_POST_INIT_CPLT)
396 {
397 if (p_msg->status == HAL_NFC_STATUS_OK)
398 {
399 nfc_enabled (NCI_STATUS_OK, nfc_cb.p_nci_init_rsp);
400 }
401 else /* if post initailization failed */
402 {
403 nfc_enabled (NCI_STATUS_FAILED, NULL);
404 }
405 }
406
407 GKI_freebuf (nfc_cb.p_nci_init_rsp);
408 nfc_cb.p_nci_init_rsp = NULL;
409 }
410 break;
411
412 case HAL_NFC_PRE_DISCOVER_CPLT_EVT:
413 /* restore the command window, no matter if the discover command is still pending */
414 nfc_cb.nci_cmd_window = NCI_MAX_CMD_WINDOW;
415 nfc_cb.flags &= ~NFC_FL_CONTROL_GRANTED;
416 if (nfc_cb.flags & NFC_FL_DISCOVER_PENDING)
417 {
418 /* issue the discovery command now, if it is still pending */
419 nfc_cb.flags &= ~NFC_FL_DISCOVER_PENDING;
420 ps = (UINT8 *)nfc_cb.p_disc_pending;
421 nci_snd_discover_cmd (*ps, (tNFC_DISCOVER_PARAMS *)(ps + 1));
422 GKI_freebuf (nfc_cb.p_disc_pending);
423 nfc_cb.p_disc_pending = NULL;
424 }
425 else
426 {
427 /* check if there's other pending commands */
428 nfc_ncif_check_cmd_queue (NULL);
429 }
430
431 if (p_msg->status == HAL_NFC_STATUS_ERR_CMD_TIMEOUT)
432 nfc_ncif_event_status (NFC_NFCC_TIMEOUT_REVT, NFC_STATUS_HW_TIMEOUT);
433 break;
434
435 case HAL_NFC_REQUEST_CONTROL_EVT:
436 nfc_cb.flags |= NFC_FL_CONTROL_REQUESTED;
437 nfc_ncif_check_cmd_queue (NULL);
438 break;
439
440 case HAL_NFC_RELEASE_CONTROL_EVT:
441 if (nfc_cb.flags & NFC_FL_CONTROL_GRANTED)
442 {
443 nfc_cb.flags &= ~NFC_FL_CONTROL_GRANTED;
444 nfc_cb.nci_cmd_window = NCI_MAX_CMD_WINDOW;
445 nfc_ncif_check_cmd_queue (NULL);
446
447 if (p_msg->status == HAL_NFC_STATUS_ERR_CMD_TIMEOUT)
448 nfc_ncif_event_status (NFC_NFCC_TIMEOUT_REVT, NFC_STATUS_HW_TIMEOUT);
449 }
450 break;
451
452 case HAL_NFC_ERROR_EVT:
453 switch (p_msg->status)
454 {
455 case HAL_NFC_STATUS_ERR_TRANSPORT:
456 /* Notify app of transport error */
457 if (nfc_cb.p_resp_cback)
458 {
459 (*nfc_cb.p_resp_cback) (NFC_NFCC_TRANSPORT_ERR_REVT, NULL);
460
461 /* if enabling NFC, notify upper layer of failure after closing HAL */
462 if (nfc_cb.nfc_state < NFC_STATE_IDLE)
463 {
464 nfc_enabled (NFC_STATUS_FAILED, NULL);
465 }
466 }
467 break;
468
469 case HAL_NFC_STATUS_ERR_CMD_TIMEOUT:
470 nfc_ncif_event_status (NFC_NFCC_TIMEOUT_REVT, NFC_STATUS_HW_TIMEOUT);
471
472 /* if enabling NFC, notify upper layer of failure after closing HAL */
473 if (nfc_cb.nfc_state < NFC_STATE_IDLE)
474 {
475 nfc_enabled (NFC_STATUS_FAILED, NULL);
476 return;
477 }
478 break;
479
480 default:
481 break;
482 }
483 break;
484
485 default:
486 NFC_TRACE_ERROR1 ("nfc_main_handle_hal_evt (): unhandled event (0x%x).", p_msg->hal_evt);
487 break;
488 }
489 }
490
491
492 /*******************************************************************************
493 **
494 ** Function nfc_main_flush_cmd_queue
495 **
496 ** Description This function is called when setting power off sleep state.
497 **
498 ** Returns void
499 **
500 *******************************************************************************/
nfc_main_flush_cmd_queue(void)501 void nfc_main_flush_cmd_queue (void)
502 {
503 BT_HDR *p_msg;
504
505 NFC_TRACE_DEBUG0 ("nfc_main_flush_cmd_queue ()");
506
507 /* initialize command window */
508 nfc_cb.nci_cmd_window = NCI_MAX_CMD_WINDOW;
509
510 /* Stop command-pending timer */
511 nfc_stop_timer(&nfc_cb.nci_wait_rsp_timer);
512
513 /* dequeue and free buffer */
514 while ((p_msg = (BT_HDR *)GKI_dequeue (&nfc_cb.nci_cmd_xmit_q)) != NULL)
515 {
516 GKI_freebuf (p_msg);
517 }
518 }
519
520 /*******************************************************************************
521 **
522 ** Function nfc_main_post_hal_evt
523 **
524 ** Description This function posts HAL event to NFC_TASK
525 **
526 ** Returns void
527 **
528 *******************************************************************************/
nfc_main_post_hal_evt(UINT8 hal_evt,tHAL_NFC_STATUS status)529 void nfc_main_post_hal_evt (UINT8 hal_evt, tHAL_NFC_STATUS status)
530 {
531 tNFC_HAL_EVT_MSG *p_msg;
532
533 if ((p_msg = (tNFC_HAL_EVT_MSG *) GKI_getbuf (sizeof(tNFC_HAL_EVT_MSG))) != NULL)
534 {
535 /* Initialize BT_HDR */
536 p_msg->hdr.len = 0;
537 p_msg->hdr.event = BT_EVT_TO_NFC_MSGS;
538 p_msg->hdr.offset = 0;
539 p_msg->hdr.layer_specific = 0;
540 p_msg->hal_evt = hal_evt;
541 p_msg->status = status;
542 GKI_send_msg (NFC_TASK, NFC_MBOX_ID, p_msg);
543 }
544 else
545 {
546 NFC_TRACE_ERROR0 ("nfc_main_post_hal_evt (): No buffer");
547 }
548 }
549
550
551 /*******************************************************************************
552 **
553 ** Function nfc_main_hal_cback
554 **
555 ** Description HAL event handler
556 **
557 ** Returns void
558 **
559 *******************************************************************************/
nfc_main_hal_cback(UINT8 event,tHAL_NFC_STATUS status)560 static void nfc_main_hal_cback(UINT8 event, tHAL_NFC_STATUS status)
561 {
562 #if (BT_TRACE_VERBOSE == TRUE)
563 NFC_TRACE_DEBUG3 ("nfc_main_hal_cback event: %s(0x%x), status=%d",
564 nfc_hal_event_name (event), event, status);
565 #else
566 NFC_TRACE_DEBUG2 ("nfc_main_hal_cback event: 0x%x, status=%d", event, status);
567 #endif
568
569 switch (event)
570 {
571 case HAL_NFC_OPEN_CPLT_EVT:
572 /*
573 ** if NFC_Disable() is called before receiving HAL_NFC_OPEN_CPLT_EVT,
574 ** then wait for HAL_NFC_CLOSE_CPLT_EVT.
575 */
576 if (nfc_cb.nfc_state == NFC_STATE_W4_HAL_OPEN)
577 {
578 if (status == HAL_NFC_STATUS_OK)
579 {
580 /* Notify NFC_TASK that NCI tranport is initialized */
581 GKI_send_event (NFC_TASK, NFC_TASK_EVT_TRANSPORT_READY);
582 }
583 else
584 {
585 nfc_main_post_hal_evt (event, status);
586 }
587 }
588 break;
589
590 case HAL_NFC_CLOSE_CPLT_EVT:
591 case HAL_NFC_POST_INIT_CPLT_EVT:
592 case HAL_NFC_PRE_DISCOVER_CPLT_EVT:
593 case HAL_NFC_REQUEST_CONTROL_EVT:
594 case HAL_NFC_RELEASE_CONTROL_EVT:
595 case HAL_NFC_ERROR_EVT:
596 nfc_main_post_hal_evt (event, status);
597 break;
598
599 default:
600 NFC_TRACE_DEBUG1 ("nfc_main_hal_cback unhandled event %x", event);
601 break;
602 }
603 }
604
605 /*******************************************************************************
606 **
607 ** Function nfc_main_hal_data_cback
608 **
609 ** Description HAL data event handler
610 **
611 ** Returns void
612 **
613 *******************************************************************************/
nfc_main_hal_data_cback(UINT16 data_len,UINT8 * p_data)614 static void nfc_main_hal_data_cback(UINT16 data_len, UINT8 *p_data)
615 {
616 BT_HDR *p_msg;
617
618 /* ignore all data while shutting down NFCC */
619 if (nfc_cb.nfc_state == NFC_STATE_W4_HAL_CLOSE)
620 {
621 return;
622 }
623
624 if (p_data)
625 {
626 if ((p_msg = (BT_HDR *) GKI_getpoolbuf (NFC_NCI_POOL_ID)) != NULL)
627 {
628 /* Initialize BT_HDR */
629 p_msg->len = data_len;
630 p_msg->event = BT_EVT_TO_NFC_NCI;
631 p_msg->offset = NFC_RECEIVE_MSGS_OFFSET;
632
633 /* no need to check length, it always less than pool size */
634 memcpy ((UINT8 *)(p_msg + 1) + p_msg->offset, p_data, p_msg->len);
635
636 GKI_send_msg (NFC_TASK, NFC_MBOX_ID, p_msg);
637 }
638 else
639 {
640 NFC_TRACE_ERROR0 ("nfc_main_hal_data_cback (): No buffer");
641 }
642 }
643 }
644
645 /*******************************************************************************
646 **
647 ** Function NFC_Enable
648 **
649 ** Description This function enables NFC. Prior to calling NFC_Enable:
650 ** - the NFCC must be powered up, and ready to receive commands.
651 ** - GKI must be enabled
652 ** - NFC_TASK must be started
653 ** - NCIT_TASK must be started (if using dedicated NCI transport)
654 **
655 ** This function opens the NCI transport (if applicable),
656 ** resets the NFC controller, and initializes the NFC subsystems.
657 **
658 ** When the NFC startup procedure is completed, an
659 ** NFC_ENABLE_REVT is returned to the application using the
660 ** tNFC_RESPONSE_CBACK.
661 **
662 ** Returns tNFC_STATUS
663 **
664 *******************************************************************************/
NFC_Enable(tNFC_RESPONSE_CBACK * p_cback)665 tNFC_STATUS NFC_Enable (tNFC_RESPONSE_CBACK *p_cback)
666 {
667 NFC_TRACE_API0 ("NFC_Enable ()");
668
669 /* Validate callback */
670 if (!p_cback)
671 {
672 return (NFC_STATUS_INVALID_PARAM);
673 }
674 nfc_cb.p_resp_cback = p_cback;
675
676 /* Open HAL transport. */
677 nfc_set_state (NFC_STATE_W4_HAL_OPEN);
678 nfc_cb.p_hal->open (nfc_main_hal_cback, nfc_main_hal_data_cback);
679
680 return (NFC_STATUS_OK);
681 }
682
683 /*******************************************************************************
684 **
685 ** Function NFC_Disable
686 **
687 ** Description This function performs clean up routines for shutting down
688 ** NFC and closes the NCI transport (if using dedicated NCI
689 ** transport).
690 **
691 ** When the NFC shutdown procedure is completed, an
692 ** NFC_DISABLED_REVT is returned to the application using the
693 ** tNFC_RESPONSE_CBACK.
694 **
695 ** Returns nothing
696 **
697 *******************************************************************************/
NFC_Disable(void)698 void NFC_Disable (void)
699 {
700 NFC_TRACE_API1 ("NFC_Disable (): nfc_state = %d", nfc_cb.nfc_state);
701
702 if (nfc_cb.nfc_state == NFC_STATE_NONE || nfc_cb.nfc_state == NFC_STATE_NFCC_POWER_OFF_SLEEP)
703 {
704 nfc_set_state (NFC_STATE_NONE);
705 if (nfc_cb.p_resp_cback)
706 {
707 (*nfc_cb.p_resp_cback) (NFC_DISABLE_REVT, NULL);
708 nfc_cb.p_resp_cback = NULL;
709 }
710 return;
711 }
712
713 /* Close transport and clean up */
714 nfc_task_shutdown_nfcc ();
715 }
716
717 /*******************************************************************************
718 **
719 ** Function NFC_Init
720 **
721 ** Description This function initializes control block for NFC
722 **
723 ** Returns nothing
724 **
725 *******************************************************************************/
NFC_Init(tHAL_NFC_ENTRY * p_hal_entry_tbl)726 void NFC_Init (tHAL_NFC_ENTRY *p_hal_entry_tbl)
727 {
728 int xx;
729
730 /* Clear nfc control block */
731 memset (&nfc_cb, 0, sizeof (tNFC_CB));
732
733 /* Reset the nfc control block */
734 for (xx = 0; xx < NCI_MAX_CONN_CBS; xx++)
735 {
736 nfc_cb.conn_cb[xx].conn_id = NFC_ILLEGAL_CONN_ID;
737 }
738
739 /* NCI init */
740 nfc_cb.p_hal = p_hal_entry_tbl;
741 nfc_cb.nfc_state = NFC_STATE_NONE;
742 nfc_cb.nci_cmd_window = NCI_MAX_CMD_WINDOW;
743 nfc_cb.nci_wait_rsp_tout= NFC_CMD_CMPL_TIMEOUT;
744 nfc_cb.p_disc_maps = nfc_interface_mapping;
745 nfc_cb.num_disc_maps = NFC_NUM_INTERFACE_MAP;
746 nfc_cb.trace_level = NFC_INITIAL_TRACE_LEVEL;
747 nfc_cb.nci_ctrl_size = NCI_CTRL_INIT_SIZE;
748
749 rw_init ();
750 ce_init ();
751 llcp_init ();
752 NFC_SET_MAX_CONN_DEFAULT ();
753 }
754
755 /*******************************************************************************
756 **
757 ** Function NFC_GetLmrtSize
758 **
759 ** Description Called by application wto query the Listen Mode Routing
760 ** Table size supported by NFCC
761 **
762 ** Returns Listen Mode Routing Table size
763 **
764 *******************************************************************************/
NFC_GetLmrtSize(void)765 UINT16 NFC_GetLmrtSize (void)
766 {
767 UINT16 size = 0;
768 #if (NFC_RW_ONLY == FALSE)
769 size = nfc_cb.max_ce_table;
770 #endif
771 return size;
772 }
773
774
775 /*******************************************************************************
776 **
777 ** Function NFC_SetConfig
778 **
779 ** Description This function is called to send the configuration parameter
780 ** TLV to NFCC. The response from NFCC is reported by
781 ** tNFC_RESPONSE_CBACK as NFC_SET_CONFIG_REVT.
782 **
783 ** Parameters tlv_size - the length of p_param_tlvs.
784 ** p_param_tlvs - the parameter ID/Len/Value list
785 **
786 ** Returns tNFC_STATUS
787 **
788 *******************************************************************************/
NFC_SetConfig(UINT8 tlv_size,UINT8 * p_param_tlvs)789 tNFC_STATUS NFC_SetConfig (UINT8 tlv_size,
790 UINT8 *p_param_tlvs)
791 {
792 return nci_snd_core_set_config (p_param_tlvs, tlv_size);
793 }
794
795 /*******************************************************************************
796 **
797 ** Function NFC_GetConfig
798 **
799 ** Description This function is called to retrieve the parameter TLV from NFCC.
800 ** The response from NFCC is reported by tNFC_RESPONSE_CBACK
801 ** as NFC_GET_CONFIG_REVT.
802 **
803 ** Parameters num_ids - the number of parameter IDs
804 ** p_param_ids - the parameter ID list.
805 **
806 ** Returns tNFC_STATUS
807 **
808 *******************************************************************************/
NFC_GetConfig(UINT8 num_ids,UINT8 * p_param_ids)809 tNFC_STATUS NFC_GetConfig (UINT8 num_ids,
810 UINT8 *p_param_ids)
811 {
812 return nci_snd_core_get_config (p_param_ids, num_ids);
813 }
814
815 /*******************************************************************************
816 **
817 ** Function NFC_DiscoveryMap
818 **
819 ** Description This function is called to set the discovery interface mapping.
820 ** The response from NFCC is reported by tNFC_DISCOVER_CBACK as.
821 ** NFC_MAP_DEVT.
822 **
823 ** Parameters num - the number of items in p_params.
824 ** p_maps - the discovery interface mappings
825 ** p_cback - the discovery callback function
826 **
827 ** Returns tNFC_STATUS
828 **
829 *******************************************************************************/
NFC_DiscoveryMap(UINT8 num,tNFC_DISCOVER_MAPS * p_maps,tNFC_DISCOVER_CBACK * p_cback)830 tNFC_STATUS NFC_DiscoveryMap (UINT8 num, tNFC_DISCOVER_MAPS *p_maps,
831 tNFC_DISCOVER_CBACK *p_cback)
832 {
833 UINT8 num_disc_maps = num;
834 UINT8 xx, yy, num_intf, intf_mask;
835 tNFC_DISCOVER_MAPS max_maps[NFC_NFCC_MAX_NUM_VS_INTERFACE + NCI_INTERFACE_MAX];
836 BOOLEAN is_supported;
837
838 nfc_cb.p_discv_cback = p_cback;
839 num_intf = 0;
840 NFC_TRACE_DEBUG1 ("nci_interfaces supported by NFCC: 0x%x", nfc_cb.nci_interfaces);
841 for (xx = 0; xx < num_disc_maps; xx++)
842 {
843 is_supported = FALSE;
844 if (p_maps[xx].intf_type > NCI_INTERFACE_MAX)
845 {
846 for (yy = 0; yy < NFC_NFCC_MAX_NUM_VS_INTERFACE; yy++)
847 {
848 if (nfc_cb.vs_interface[yy] == p_maps[xx].intf_type)
849 is_supported = TRUE;
850 }
851 NFC_TRACE_DEBUG3 ("[%d]: vs intf_type:0x%x is_supported:%d", xx, p_maps[xx].intf_type, is_supported);
852 }
853 else
854 {
855 intf_mask = (1 << (p_maps[xx].intf_type));
856 if (intf_mask & nfc_cb.nci_interfaces)
857 {
858 is_supported = TRUE;
859 }
860 NFC_TRACE_DEBUG4 ("[%d]: intf_type:%d intf_mask: 0x%x is_supported:%d", xx, p_maps[xx].intf_type, intf_mask, is_supported);
861 }
862 if (is_supported)
863 memcpy (&max_maps[num_intf++], &p_maps[xx], sizeof (tNFC_DISCOVER_MAPS));
864 else
865 {
866 NFC_TRACE_WARNING1 ("NFC_DiscoveryMap interface=0x%x is not supported by NFCC", p_maps[xx].intf_type);
867 }
868 }
869
870 return nci_snd_discover_map_cmd (num_intf, (tNCI_DISCOVER_MAPS *) max_maps);
871 }
872
873 /*******************************************************************************
874 **
875 ** Function NFC_DiscoveryStart
876 **
877 ** Description This function is called to start Polling and/or Listening.
878 ** The response from NFCC is reported by tNFC_DISCOVER_CBACK as.
879 ** NFC_START_DEVT. The notification from NFCC is reported by
880 ** tNFC_DISCOVER_CBACK as NFC_RESULT_DEVT.
881 **
882 ** Parameters num_params - the number of items in p_params.
883 ** p_params - the discovery parameters
884 ** p_cback - the discovery callback function
885 **
886 ** Returns tNFC_STATUS
887 **
888 *******************************************************************************/
NFC_DiscoveryStart(UINT8 num_params,tNFC_DISCOVER_PARAMS * p_params,tNFC_DISCOVER_CBACK * p_cback)889 tNFC_STATUS NFC_DiscoveryStart (UINT8 num_params,
890 tNFC_DISCOVER_PARAMS *p_params,
891 tNFC_DISCOVER_CBACK *p_cback)
892 {
893 UINT8 *p;
894 int params_size;
895 tNFC_STATUS status = NFC_STATUS_NO_BUFFERS;
896
897 NFC_TRACE_API0 ("NFC_DiscoveryStart");
898 if (nfc_cb.p_disc_pending)
899 {
900 NFC_TRACE_ERROR0 ("There's pending NFC_DiscoveryStart");
901 status = NFC_STATUS_BUSY;
902 }
903 else
904 {
905 nfc_cb.p_discv_cback = p_cback;
906 nfc_cb.flags |= NFC_FL_DISCOVER_PENDING;
907 nfc_cb.flags |= NFC_FL_CONTROL_REQUESTED;
908 params_size = sizeof (tNFC_DISCOVER_PARAMS) * num_params;
909 nfc_cb.p_disc_pending = GKI_getbuf ((UINT16)(BT_HDR_SIZE + 1 + params_size));
910 if (nfc_cb.p_disc_pending)
911 {
912 p = (UINT8 *)nfc_cb.p_disc_pending;
913 *p++ = num_params;
914 memcpy (p, p_params, params_size);
915 status = NFC_STATUS_CMD_STARTED;
916 nfc_ncif_check_cmd_queue (NULL);
917 }
918 }
919
920 NFC_TRACE_API1 ("NFC_DiscoveryStart status: 0x%x", status);
921 return status;
922 }
923
924 /*******************************************************************************
925 **
926 ** Function NFC_DiscoverySelect
927 **
928 ** Description If tNFC_DISCOVER_CBACK reports status=NFC_MULTIPLE_PROT,
929 ** the application needs to use this function to select the
930 ** the logical endpoint to continue. The response from NFCC is
931 ** reported by tNFC_DISCOVER_CBACK as NFC_SELECT_DEVT.
932 **
933 ** Parameters rf_disc_id - The ID identifies the remote device.
934 ** protocol - the logical endpoint on the remote devide
935 ** rf_interface - the RF interface to communicate with NFCC
936 **
937 ** Returns tNFC_STATUS
938 **
939 *******************************************************************************/
NFC_DiscoverySelect(UINT8 rf_disc_id,UINT8 protocol,UINT8 rf_interface)940 tNFC_STATUS NFC_DiscoverySelect (UINT8 rf_disc_id,
941 UINT8 protocol,
942 UINT8 rf_interface)
943 {
944 return nci_snd_discover_select_cmd (rf_disc_id, protocol, rf_interface);
945 }
946
947 /*******************************************************************************
948 **
949 ** Function NFC_ConnCreate
950 **
951 ** Description This function is called to create a logical connection with
952 ** NFCC for data exchange.
953 **
954 ** Parameters dest_type - the destination type
955 ** id - the NFCEE ID or RF Discovery ID .
956 ** protocol - the protocol.
957 ** p_cback - the connection callback function
958 **
959 ** Returns tNFC_STATUS
960 **
961 *******************************************************************************/
NFC_ConnCreate(UINT8 dest_type,UINT8 id,UINT8 protocol,tNFC_CONN_CBACK * p_cback)962 tNFC_STATUS NFC_ConnCreate (UINT8 dest_type,
963 UINT8 id,
964 UINT8 protocol,
965 tNFC_CONN_CBACK *p_cback)
966 {
967 tNFC_STATUS status = NFC_STATUS_FAILED;
968 tNFC_CONN_CB *p_cb;
969 UINT8 num_tlv=0, tlv_size=0;
970 UINT8 param_tlvs[4], *pp;
971
972 p_cb = nfc_alloc_conn_cb (p_cback);
973 if (p_cb)
974 {
975 p_cb->id = id;
976 pp = param_tlvs;
977 if (dest_type == NCI_DEST_TYPE_NFCEE)
978 {
979 num_tlv = 1;
980 UINT8_TO_STREAM (pp, NCI_CON_CREATE_TAG_NFCEE_VAL);
981 UINT8_TO_STREAM (pp, 2);
982 UINT8_TO_STREAM (pp, id);
983 UINT8_TO_STREAM (pp, protocol);
984 tlv_size = 4;
985 }
986 else if (dest_type == NCI_DEST_TYPE_REMOTE)
987 {
988 num_tlv = 1;
989 UINT8_TO_STREAM (pp, NCI_CON_CREATE_TAG_RF_DISC_ID);
990 UINT8_TO_STREAM (pp, 1);
991 UINT8_TO_STREAM (pp, id);
992 tlv_size = 3;
993 }
994 else if (dest_type == NCI_DEST_TYPE_NFCC)
995 {
996 p_cb->id = NFC_TEST_ID;
997 }
998 /* Add handling of NCI_DEST_TYPE_REMOTE when more RF interface definitions are added */
999 p_cb->act_protocol = protocol;
1000 p_cb->p_cback = p_cback;
1001 status = nci_snd_core_conn_create (dest_type, num_tlv, tlv_size, param_tlvs);
1002 if (status == NFC_STATUS_FAILED)
1003 nfc_free_conn_cb (p_cb);
1004 }
1005 return status;
1006 }
1007
1008 /*******************************************************************************
1009 **
1010 ** Function NFC_ConnClose
1011 **
1012 ** Description This function is called to close a logical connection with
1013 ** NFCC.
1014 **
1015 ** Parameters conn_id - the connection id.
1016 **
1017 ** Returns tNFC_STATUS
1018 **
1019 *******************************************************************************/
NFC_ConnClose(UINT8 conn_id)1020 tNFC_STATUS NFC_ConnClose (UINT8 conn_id)
1021 {
1022 tNFC_CONN_CB *p_cb = nfc_find_conn_cb_by_conn_id (conn_id);
1023 tNFC_STATUS status = NFC_STATUS_FAILED;
1024
1025 if (p_cb)
1026 {
1027 status = nci_snd_core_conn_close (conn_id);
1028 }
1029 return status;
1030 }
1031
1032 /*******************************************************************************
1033 **
1034 ** Function NFC_SetStaticRfCback
1035 **
1036 ** Description This function is called to update the data callback function
1037 ** to receive the data for the given connection id.
1038 **
1039 ** Parameters p_cback - the connection callback function
1040 **
1041 ** Returns Nothing
1042 **
1043 *******************************************************************************/
NFC_SetStaticRfCback(tNFC_CONN_CBACK * p_cback)1044 void NFC_SetStaticRfCback (tNFC_CONN_CBACK *p_cback)
1045 {
1046 tNFC_CONN_CB * p_cb = &nfc_cb.conn_cb[NFC_RF_CONN_ID];
1047
1048 p_cb->p_cback = p_cback;
1049 /* just in case DH has received NCI data before the data callback is set
1050 * check if there's any data event to report on this connection id */
1051 nfc_data_event (p_cb);
1052 }
1053
1054 /*******************************************************************************
1055 **
1056 ** Function NFC_SendData
1057 **
1058 ** Description This function is called to send the given data packet
1059 ** to the connection identified by the given connection id.
1060 **
1061 ** Parameters conn_id - the connection id.
1062 ** p_data - the data packet.
1063 ** p_data->offset must be >= NCI_MSG_OFFSET_SIZE + NCI_DATA_HDR_SIZE
1064 ** The data payload starts at ((UINT8 *) (p_data + 1) + p_data->offset)
1065 **
1066 ** Returns tNFC_STATUS
1067 **
1068 *******************************************************************************/
NFC_SendData(UINT8 conn_id,BT_HDR * p_data)1069 tNFC_STATUS NFC_SendData (UINT8 conn_id,
1070 BT_HDR *p_data)
1071 {
1072 tNFC_STATUS status = NFC_STATUS_FAILED;
1073 tNFC_CONN_CB *p_cb = nfc_find_conn_cb_by_conn_id (conn_id);
1074
1075 if (p_cb && p_data && p_data->offset >= NCI_MSG_OFFSET_SIZE + NCI_DATA_HDR_SIZE)
1076 {
1077 status = nfc_ncif_send_data (p_cb, p_data);
1078 }
1079
1080 if (status != NFC_STATUS_OK)
1081 GKI_freebuf (p_data);
1082
1083 return status;
1084 }
1085
1086 /*******************************************************************************
1087 **
1088 ** Function NFC_FlushData
1089 **
1090 ** Description This function is called to discard the tx data queue of
1091 ** the given connection id.
1092 **
1093 ** Parameters conn_id - the connection id.
1094 **
1095 ** Returns tNFC_STATUS
1096 **
1097 *******************************************************************************/
NFC_FlushData(UINT8 conn_id)1098 tNFC_STATUS NFC_FlushData (UINT8 conn_id)
1099 {
1100 tNFC_STATUS status = NFC_STATUS_FAILED;
1101 tNFC_CONN_CB *p_cb = nfc_find_conn_cb_by_conn_id (conn_id);
1102 void *p_buf;
1103
1104 if (p_cb)
1105 {
1106 status = NFC_STATUS_OK;
1107 while ((p_buf = GKI_dequeue (&p_cb->tx_q)) != NULL)
1108 GKI_freebuf (p_buf);
1109 }
1110
1111 return status;
1112 }
1113
1114 /*******************************************************************************
1115 **
1116 ** Function NFC_Deactivate
1117 **
1118 ** Description This function is called to stop the discovery process or
1119 ** put the listen device in sleep mode or terminate the NFC link.
1120 **
1121 ** The response from NFCC is reported by tNFC_DISCOVER_CBACK
1122 ** as NFC_DEACTIVATE_DEVT.
1123 **
1124 ** Parameters deactivate_type - NFC_DEACTIVATE_TYPE_IDLE, to IDLE mode.
1125 ** NFC_DEACTIVATE_TYPE_SLEEP to SLEEP mode.
1126 ** NFC_DEACTIVATE_TYPE_SLEEP_AF to SLEEP_AF mode.
1127 **
1128 ** Returns tNFC_STATUS
1129 **
1130 *******************************************************************************/
NFC_Deactivate(tNFC_DEACT_TYPE deactivate_type)1131 tNFC_STATUS NFC_Deactivate (tNFC_DEACT_TYPE deactivate_type)
1132 {
1133 tNFC_CONN_CB * p_cb = &nfc_cb.conn_cb[NFC_RF_CONN_ID];
1134 tNFC_STATUS status = NFC_STATUS_OK;
1135
1136 #if (BT_TRACE_VERBOSE == TRUE)
1137 NFC_TRACE_API3 ("NFC_Deactivate %d (%s) deactivate_type:%d", nfc_cb.nfc_state, nfc_state_name (nfc_cb.nfc_state), deactivate_type);
1138 #else
1139 NFC_TRACE_API2 ("NFC_Deactivate %d deactivate_type:%d", nfc_cb.nfc_state, deactivate_type);
1140 #endif
1141
1142 if (nfc_cb.flags & NFC_FL_DISCOVER_PENDING)
1143 {
1144 /* the HAL pre-discover is still active - clear the pending flag */
1145 nfc_cb.flags &= ~NFC_FL_DISCOVER_PENDING;
1146 GKI_freebuf (nfc_cb.p_disc_pending);
1147 nfc_cb.p_disc_pending = NULL;
1148 return NFC_STATUS_OK;
1149 }
1150
1151 if (nfc_cb.nfc_state == NFC_STATE_OPEN)
1152 {
1153 nfc_set_state (NFC_STATE_CLOSING);
1154 NFC_TRACE_DEBUG3 ( "act_protocol %d credits:%d/%d", p_cb->act_protocol, p_cb->init_credits, p_cb->num_buff);
1155 if ((p_cb->act_protocol == NCI_PROTOCOL_NFC_DEP) &&
1156 (p_cb->init_credits != p_cb->num_buff))
1157 {
1158 nfc_cb.flags |= NFC_FL_DEACTIVATING;
1159 nfc_cb.deactivate_timer.param = (TIMER_PARAM_TYPE) deactivate_type;
1160 nfc_start_timer (&nfc_cb.deactivate_timer , (UINT16) (NFC_TTYPE_WAIT_2_DEACTIVATE), NFC_DEACTIVATE_TIMEOUT);
1161 return status;
1162 }
1163 }
1164
1165 status = nci_snd_deactivate_cmd (deactivate_type);
1166 return status;
1167 }
1168
1169 /*******************************************************************************
1170 **
1171 ** Function NFC_UpdateRFCommParams
1172 **
1173 ** Description This function is called to update RF Communication parameters
1174 ** once the Frame RF Interface has been activated.
1175 **
1176 ** The response from NFCC is reported by tNFC_RESPONSE_CBACK
1177 ** as NFC_RF_COMM_PARAMS_UPDATE_REVT.
1178 **
1179 ** Returns tNFC_STATUS
1180 **
1181 *******************************************************************************/
NFC_UpdateRFCommParams(tNFC_RF_COMM_PARAMS * p_params)1182 tNFC_STATUS NFC_UpdateRFCommParams (tNFC_RF_COMM_PARAMS *p_params)
1183 {
1184 UINT8 tlvs[12];
1185 UINT8 *p = tlvs;
1186 UINT8 data_exch_config;
1187
1188 /* RF Technology and Mode */
1189 if (p_params->include_rf_tech_mode)
1190 {
1191 UINT8_TO_STREAM (p, NCI_RF_PARAM_ID_TECH_N_MODE);
1192 UINT8_TO_STREAM (p, 1);
1193 UINT8_TO_STREAM (p, p_params->rf_tech_n_mode);
1194 }
1195
1196 /* Transmit Bit Rate */
1197 if (p_params->include_tx_bit_rate)
1198 {
1199 UINT8_TO_STREAM (p, NCI_RF_PARAM_ID_TX_BIT_RATE);
1200 UINT8_TO_STREAM (p, 1);
1201 UINT8_TO_STREAM (p, p_params->tx_bit_rate);
1202 }
1203
1204 /* Receive Bit Rate */
1205 if (p_params->include_tx_bit_rate)
1206 {
1207 UINT8_TO_STREAM (p, NCI_RF_PARAM_ID_RX_BIT_RATE);
1208 UINT8_TO_STREAM (p, 1);
1209 UINT8_TO_STREAM (p, p_params->rx_bit_rate);
1210 }
1211
1212 /* NFC-B Data Exchange Configuration */
1213 if (p_params->include_nfc_b_config)
1214 {
1215 UINT8_TO_STREAM (p, NCI_RF_PARAM_ID_B_DATA_EX_PARAM);
1216 UINT8_TO_STREAM (p, 1);
1217
1218 data_exch_config = (p_params->min_tr0 & 0x03) << 6; /* b7b6 : Mininum TR0 */
1219 data_exch_config |= (p_params->min_tr1 & 0x03) << 4; /* b5b4 : Mininum TR1 */
1220 data_exch_config |= (p_params->suppression_eos & 0x01) << 3; /* b3 : Suppression of EoS */
1221 data_exch_config |= (p_params->suppression_sos & 0x01) << 2; /* b2 : Suppression of SoS */
1222 data_exch_config |= (p_params->min_tr2 & 0x03); /* b1b0 : Mininum TR2 */
1223
1224 UINT8_TO_STREAM (p, data_exch_config);
1225 }
1226
1227 return nci_snd_parameter_update_cmd (tlvs, (UINT8) (p - tlvs));
1228 }
1229
1230 /*******************************************************************************
1231 **
1232 ** Function NFC_SetPowerOffSleep
1233 **
1234 ** Description This function closes/opens transport and turns off/on NFCC.
1235 **
1236 ** Returns tNFC_STATUS
1237 **
1238 *******************************************************************************/
NFC_SetPowerOffSleep(BOOLEAN enable)1239 tNFC_STATUS NFC_SetPowerOffSleep (BOOLEAN enable)
1240 {
1241 NFC_TRACE_API1 ("NFC_SetPowerOffSleep () enable = %d", enable);
1242
1243 if ( (enable == FALSE)
1244 &&(nfc_cb.nfc_state == NFC_STATE_NFCC_POWER_OFF_SLEEP) )
1245 {
1246 nfc_cb.flags |= NFC_FL_RESTARTING;
1247
1248 /* open transport */
1249 nfc_set_state (NFC_STATE_W4_HAL_OPEN);
1250 nfc_cb.p_hal->open (nfc_main_hal_cback, nfc_main_hal_data_cback);
1251
1252 return NFC_STATUS_OK;
1253 }
1254 else if ( (enable == TRUE)
1255 &&(nfc_cb.nfc_state == NFC_STATE_IDLE) )
1256 {
1257 /* close transport to turn off NFCC and clean up */
1258 nfc_cb.flags |= NFC_FL_POWER_OFF_SLEEP;
1259 nfc_task_shutdown_nfcc ();
1260
1261 return NFC_STATUS_OK;
1262 }
1263
1264 NFC_TRACE_ERROR1 ("NFC_SetPowerOffSleep () invalid state = %d", nfc_cb.nfc_state);
1265 return NFC_STATUS_FAILED;
1266 }
1267
1268 /*******************************************************************************
1269 **
1270 ** Function NFC_PowerCycleNFCC
1271 **
1272 ** Description This function turns off and then on NFCC.
1273 **
1274 ** Returns tNFC_STATUS
1275 **
1276 *******************************************************************************/
NFC_PowerCycleNFCC(void)1277 tNFC_STATUS NFC_PowerCycleNFCC (void)
1278 {
1279 NFC_TRACE_API0 ("NFC_PowerCycleNFCC ()");
1280
1281 if (nfc_cb.nfc_state == NFC_STATE_IDLE)
1282 {
1283 /* power cycle NFCC */
1284 nfc_cb.flags |= NFC_FL_POWER_CYCLE_NFCC;
1285 nfc_task_shutdown_nfcc ();
1286
1287 return NFC_STATUS_OK;
1288 }
1289
1290 NFC_TRACE_ERROR1 ("NFC_PowerCycleNFCC () invalid state = %d", nfc_cb.nfc_state);
1291 return NFC_STATUS_FAILED;
1292 }
1293
1294
1295 /*******************************************************************************
1296 **
1297 ** Function NFC_SetTraceLevel
1298 **
1299 ** Description This function sets the trace level for NFC. If called with
1300 ** a value of 0xFF, it simply returns the current trace level.
1301 **
1302 ** Returns The new or current trace level
1303 **
1304 *******************************************************************************/
NFC_SetTraceLevel(UINT8 new_level)1305 UINT8 NFC_SetTraceLevel (UINT8 new_level)
1306 {
1307 NFC_TRACE_API1 ("NFC_SetTraceLevel () new_level = %d", new_level);
1308
1309 if (new_level != 0xFF)
1310 nfc_cb.trace_level = new_level;
1311
1312 return (nfc_cb.trace_level);
1313 }
1314
1315
1316 #endif /* NFC_INCLUDED == TRUE */
1317