blob: bc5b4724120466c8283f4f6f39dddccbff43c2bb [file] [log] [blame]
The Android Open Source Project5738f832012-12-12 16:00:35 -08001/******************************************************************************
2 *
3 * Copyright (C) 1999-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 the functions relating to link management. A "link"
22 * is a connection between this device and another device. Only ACL links
23 * are managed.
24 *
25 ******************************************************************************/
26
27#include <stdlib.h>
28#include <string.h>
29#include <stdio.h>
30
Zach Johnson30e58062014-09-26 21:14:34 -070031#include "controller.h"
Chris Mantoncccf02f2014-10-21 13:55:24 -070032#include "counter.h"
The Android Open Source Project5738f832012-12-12 16:00:35 -080033#include "gki.h"
34#include "bt_types.h"
Mike J. Chen5cd8bff2014-01-31 18:16:59 -080035#include "bt_utils.h"
The Android Open Source Project5738f832012-12-12 16:00:35 -080036#include "hcimsgs.h"
37#include "l2cdefs.h"
38#include "l2c_int.h"
39#include "l2c_api.h"
40#include "btu.h"
41#include "btm_api.h"
42#include "btm_int.h"
43
44static BOOLEAN l2c_link_send_to_lower (tL2C_LCB *p_lcb, BT_HDR *p_buf);
45
The Android Open Source Project5738f832012-12-12 16:00:35 -080046/*******************************************************************************
47**
48** Function l2c_link_hci_conn_req
49**
50** Description This function is called when an HCI Connection Request
51** event is received.
52**
53** Returns TRUE, if accept conn
54**
55*******************************************************************************/
56BOOLEAN l2c_link_hci_conn_req (BD_ADDR bd_addr)
57{
58 tL2C_LCB *p_lcb;
59 tL2C_LCB *p_lcb_cur;
60 int xx;
61 BOOLEAN no_links;
62
63 /* See if we have a link control block for the remote device */
Ganesh Ganapathi Batta8fe58872014-04-16 16:50:09 -070064 p_lcb = l2cu_find_lcb_by_bd_addr (bd_addr, BT_TRANSPORT_BR_EDR);
The Android Open Source Project5738f832012-12-12 16:00:35 -080065
66 /* If we don't have one, create one and accept the connection. */
67 if (!p_lcb)
68 {
Ganesh Ganapathi Batta8fe58872014-04-16 16:50:09 -070069 p_lcb = l2cu_allocate_lcb (bd_addr, FALSE, BT_TRANSPORT_BR_EDR);
The Android Open Source Project5738f832012-12-12 16:00:35 -080070 if (!p_lcb)
71 {
72 btsnd_hcic_reject_conn (bd_addr, HCI_ERR_HOST_REJECT_RESOURCES);
Sharvil Nanavatia51c9d92014-05-04 01:08:21 -070073 L2CAP_TRACE_ERROR ("L2CAP failed to allocate LCB");
The Android Open Source Project5738f832012-12-12 16:00:35 -080074 return FALSE;
75 }
76
77 no_links = TRUE;
78
79 /* If we already have connection, accept as a master */
80 for (xx = 0, p_lcb_cur = &l2cb.lcb_pool[0]; xx < MAX_L2CAP_LINKS; xx++, p_lcb_cur++)
81 {
82 if (p_lcb_cur == p_lcb)
83 continue;
84
85 if (p_lcb_cur->in_use)
86 {
87 no_links = FALSE;
88 p_lcb->link_role = HCI_ROLE_MASTER;
89 break;
90 }
91 }
92
93 if (no_links)
94 {
95 if (!btm_dev_support_switch (bd_addr))
96 p_lcb->link_role = HCI_ROLE_SLAVE;
97 else
Ganesh Ganapathi Batta8fe58872014-04-16 16:50:09 -070098 p_lcb->link_role = l2cu_get_conn_role(p_lcb);
The Android Open Source Project5738f832012-12-12 16:00:35 -080099 }
100
Chris Mantoncccf02f2014-10-21 13:55:24 -0700101 counter_add("l2cap.conn.accept", 1);
102
The Android Open Source Project5738f832012-12-12 16:00:35 -0800103 /* Tell the other side we accept the connection */
104 btsnd_hcic_accept_conn (bd_addr, p_lcb->link_role);
105
106 p_lcb->link_state = LST_CONNECTING;
107
108 /* Start a timer waiting for connect complete */
109 btu_start_timer (&p_lcb->timer_entry, BTU_TTYPE_L2CAP_LINK, L2CAP_LINK_CONNECT_TOUT);
110 return (TRUE);
111 }
112
113 /* We already had a link control block to the guy. Check what state it is in */
114 if ((p_lcb->link_state == LST_CONNECTING) || (p_lcb->link_state == LST_CONNECT_HOLDING))
115 {
116 /* Connection collision. Accept the connection anyways. */
117
118 if (!btm_dev_support_switch (bd_addr))
119 p_lcb->link_role = HCI_ROLE_SLAVE;
120 else
Ganesh Ganapathi Batta8fe58872014-04-16 16:50:09 -0700121 p_lcb->link_role = l2cu_get_conn_role(p_lcb);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800122
Chris Mantoncccf02f2014-10-21 13:55:24 -0700123 counter_add("l2cap.conn.accept", 1);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800124 btsnd_hcic_accept_conn (bd_addr, p_lcb->link_role);
125
126 p_lcb->link_state = LST_CONNECTING;
127 return (TRUE);
128 }
129 else if (p_lcb->link_state == LST_DISCONNECTING)
130 {
131 /* In disconnecting state, reject the connection. */
Chris Mantoncccf02f2014-10-21 13:55:24 -0700132 counter_add("l2cap.conn.reject.disconn", 1);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800133 btsnd_hcic_reject_conn (bd_addr, HCI_ERR_HOST_REJECT_DEVICE);
134 }
135 else
136 {
Sharvil Nanavatia51c9d92014-05-04 01:08:21 -0700137 L2CAP_TRACE_ERROR("L2CAP got conn_req while connected (state:%d). Reject it",
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800138 p_lcb->link_state);
139 /* Reject the connection with ACL Connection Already exist reason */
Chris Mantoncccf02f2014-10-21 13:55:24 -0700140 counter_add("l2cap.conn.reject.exists", 1);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800141 btsnd_hcic_reject_conn (bd_addr, HCI_ERR_CONNECTION_EXISTS);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800142 }
143 return (FALSE);
144}
145
146/*******************************************************************************
147**
148** Function l2c_link_hci_conn_comp
149**
150** Description This function is called when an HCI Connection Complete
151** event is received.
152**
153** Returns void
154**
155*******************************************************************************/
156BOOLEAN l2c_link_hci_conn_comp (UINT8 status, UINT16 handle, BD_ADDR p_bda)
157{
158 tL2C_CONN_INFO ci;
159 tL2C_LCB *p_lcb;
160 tL2C_CCB *p_ccb;
161 tBTM_SEC_DEV_REC *p_dev_info = NULL;
162
The Android Open Source Project5738f832012-12-12 16:00:35 -0800163 btm_acl_update_busy_level (BTM_BLI_PAGE_DONE_EVT);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800164
165 /* Save the parameters */
166 ci.status = status;
167 memcpy (ci.bd_addr, p_bda, BD_ADDR_LEN);
168
169 /* See if we have a link control block for the remote device */
Ganesh Ganapathi Batta8fe58872014-04-16 16:50:09 -0700170 p_lcb = l2cu_find_lcb_by_bd_addr (ci.bd_addr, BT_TRANSPORT_BR_EDR);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800171
172 /* If we don't have one, this is an error */
173 if (!p_lcb)
174 {
Sharvil Nanavatia51c9d92014-05-04 01:08:21 -0700175 L2CAP_TRACE_WARNING ("L2CAP got conn_comp for unknown BD_ADDR");
The Android Open Source Project5738f832012-12-12 16:00:35 -0800176 return (FALSE);
177 }
178
179 if (p_lcb->link_state != LST_CONNECTING)
180 {
Sharvil Nanavatia51c9d92014-05-04 01:08:21 -0700181 L2CAP_TRACE_ERROR ("L2CAP got conn_comp in bad state: %d status: 0x%d", p_lcb->link_state, status);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800182
183 if (status != HCI_SUCCESS)
184 l2c_link_hci_disc_comp (p_lcb->handle, status);
185
186 return (FALSE);
187 }
188
189 /* Save the handle */
190 p_lcb->handle = handle;
191
192 if (ci.status == HCI_SUCCESS)
193 {
194 /* Connected OK. Change state to connected */
195 p_lcb->link_state = LST_CONNECTED;
Chris Mantoncccf02f2014-10-21 13:55:24 -0700196 counter_add("l2cap.conn.ok", 1);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800197
198 /* Get the peer information if the l2cap flow-control/rtrans is supported */
199 l2cu_send_peer_info_req (p_lcb, L2CAP_EXTENDED_FEATURES_INFO_TYPE);
200
201 /* Tell BTM Acl management about the link */
202 if ((p_dev_info = btm_find_dev (p_bda)) != NULL)
203 btm_acl_created (ci.bd_addr, p_dev_info->dev_class,
204 p_dev_info->sec_bd_name, handle,
Ganesh Ganapathi Batta8fe58872014-04-16 16:50:09 -0700205 p_lcb->link_role, BT_TRANSPORT_BR_EDR);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800206 else
Ganesh Ganapathi Batta8fe58872014-04-16 16:50:09 -0700207 btm_acl_created (ci.bd_addr, NULL, NULL, handle, p_lcb->link_role, BT_TRANSPORT_BR_EDR);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800208
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800209 BTM_SetLinkSuperTout (ci.bd_addr, btm_cb.btm_def_link_super_tout);
210
The Android Open Source Project5738f832012-12-12 16:00:35 -0800211 /* If dedicated bonding do not process any further */
212 if (p_lcb->is_bonding)
213 {
214 if (l2cu_start_post_bond_timer(handle))
215 return (TRUE);
216 }
217
218 /* Update the timeouts in the hold queue */
219 l2c_process_held_packets(FALSE);
220
221 btu_stop_timer (&p_lcb->timer_entry);
222
223 /* For all channels, send the event through their FSMs */
224 for (p_ccb = p_lcb->ccb_queue.p_first_ccb; p_ccb; p_ccb = p_ccb->p_next_ccb)
225 {
226 l2c_csm_execute (p_ccb, L2CEVT_LP_CONNECT_CFM, &ci);
227 }
228
229 if (p_lcb->p_echo_rsp_cb)
230 {
231 l2cu_send_peer_echo_req (p_lcb, NULL, 0);
232 btu_start_timer (&p_lcb->timer_entry, BTU_TTYPE_L2CAP_LINK, L2CAP_ECHO_RSP_TOUT);
233 }
234 else if (!p_lcb->ccb_queue.p_first_ccb)
235 {
236 btu_start_timer (&p_lcb->timer_entry, BTU_TTYPE_L2CAP_LINK, L2CAP_LINK_STARTUP_TOUT);
237 }
238 }
239 /* Max number of acl connections. */
240 /* If there's an lcb disconnecting set this one to holding */
241 else if ((ci.status == HCI_ERR_MAX_NUM_OF_CONNECTIONS) && l2cu_lcb_disconnecting())
242 {
243 p_lcb->link_state = LST_CONNECT_HOLDING;
244 p_lcb->handle = HCI_INVALID_HANDLE;
245 }
246 else
247 {
248 /* Just in case app decides to try again in the callback context */
249 p_lcb->link_state = LST_DISCONNECTING;
250
251 /* Connection failed. For all channels, send the event through */
252 /* their FSMs. The CCBs should remove themselves from the LCB */
253 for (p_ccb = p_lcb->ccb_queue.p_first_ccb; p_ccb; )
254 {
255 tL2C_CCB *pn = p_ccb->p_next_ccb;
256
257 l2c_csm_execute (p_ccb, L2CEVT_LP_CONNECT_CFM_NEG, &ci);
258
259 p_ccb = pn;
260 }
261
262 p_lcb->disc_reason = status;
263 /* Release the LCB */
264 if (p_lcb->ccb_queue.p_first_ccb == NULL)
265 l2cu_release_lcb (p_lcb);
266 else /* there are any CCBs remaining */
267 {
268 if (ci.status == HCI_ERR_CONNECTION_EXISTS)
269 {
270 /* we are in collision situation, wait for connecttion request from controller */
271 p_lcb->link_state = LST_CONNECTING;
272 }
273 else
274 {
Ganesh Ganapathi Batta8fe58872014-04-16 16:50:09 -0700275 l2cu_create_conn(p_lcb, BT_TRANSPORT_BR_EDR);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800276 }
277 }
278 }
279 return (TRUE);
280}
281
282
283/*******************************************************************************
284**
285** Function l2c_link_sec_comp
286**
287** Description This function is called when required security procedures
288** are completed.
289**
290** Returns void
291**
292*******************************************************************************/
Ganesh Ganapathi Batta8fe58872014-04-16 16:50:09 -0700293void l2c_link_sec_comp (BD_ADDR p_bda, tBT_TRANSPORT transport, void *p_ref_data, UINT8 status)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800294{
295 tL2C_CONN_INFO ci;
296 tL2C_LCB *p_lcb;
297 tL2C_CCB *p_ccb;
298 tL2C_CCB *p_next_ccb;
299 UINT8 event;
300
Ganesh Ganapathi Batta8fe58872014-04-16 16:50:09 -0700301 UNUSED(transport);
302
Sharvil Nanavatia51c9d92014-05-04 01:08:21 -0700303 L2CAP_TRACE_DEBUG ("l2c_link_sec_comp: %d, 0x%x", status, p_ref_data);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800304
305 if (status == BTM_SUCCESS_NO_SECURITY)
306 status = BTM_SUCCESS;
307
308 /* Save the parameters */
309 ci.status = status;
310 memcpy (ci.bd_addr, p_bda, BD_ADDR_LEN);
311
Ganesh Ganapathi Batta8fe58872014-04-16 16:50:09 -0700312 p_lcb = l2cu_find_lcb_by_bd_addr (p_bda, BT_TRANSPORT_BR_EDR);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800313
314 /* If we don't have one, this is an error */
315 if (!p_lcb)
316 {
Sharvil Nanavatia51c9d92014-05-04 01:08:21 -0700317 L2CAP_TRACE_WARNING ("L2CAP got sec_comp for unknown BD_ADDR");
The Android Open Source Project5738f832012-12-12 16:00:35 -0800318 return;
319 }
320
321 /* Match p_ccb with p_ref_data returned by sec manager */
322 for (p_ccb = p_lcb->ccb_queue.p_first_ccb; p_ccb; p_ccb = p_next_ccb)
323 {
324 p_next_ccb = p_ccb->p_next_ccb;
325
326 if (p_ccb == p_ref_data)
327 {
328 switch(status)
329 {
330 case BTM_SUCCESS:
Sharvil Nanavatia51c9d92014-05-04 01:08:21 -0700331 L2CAP_TRACE_DEBUG ("ccb timer ticks: %u", p_ccb->timer_entry.ticks);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800332 event = L2CEVT_SEC_COMP;
333 break;
334
335 case BTM_DELAY_CHECK:
336 /* start a timer - encryption change not received before L2CAP connect req */
337 btu_start_timer (&p_ccb->timer_entry, BTU_TTYPE_L2CAP_CHNL, L2CAP_DELAY_CHECK_SM4);
338 return;
339
340 default:
341 event = L2CEVT_SEC_COMP_NEG;
342 }
343 l2c_csm_execute (p_ccb, event, &ci);
344 break;
345 }
346 }
347}
348
349
350/*******************************************************************************
351**
352** Function l2c_link_hci_disc_comp
353**
354** Description This function is called when an HCI Disconnect Complete
355** event is received.
356**
357** Returns TRUE if the link is known about, else FALSE
358**
359*******************************************************************************/
360BOOLEAN l2c_link_hci_disc_comp (UINT16 handle, UINT8 reason)
361{
362 tL2C_LCB *p_lcb;
363 tL2C_CCB *p_ccb;
364 BOOLEAN status = TRUE;
365 BOOLEAN lcb_is_free = TRUE;
Ganesh Ganapathi Batta8fe58872014-04-16 16:50:09 -0700366 tBT_TRANSPORT transport = BT_TRANSPORT_BR_EDR;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800367
368 /* See if we have a link control block for the connection */
369 p_lcb = l2cu_find_lcb_by_handle (handle);
370
371 /* If we don't have one, maybe an SCO link. Send to MM */
372 if (!p_lcb)
373 {
374 status = FALSE;
375 }
376 else
377 {
378 /* There can be a case when we rejected PIN code authentication */
379 /* otherwise save a new reason */
380 if (btm_cb.acl_disc_reason != HCI_ERR_HOST_REJECT_SECURITY)
381 btm_cb.acl_disc_reason = reason;
382
383 p_lcb->disc_reason = btm_cb.acl_disc_reason;
384
385 /* Just in case app decides to try again in the callback context */
386 p_lcb->link_state = LST_DISCONNECTING;
387
388 /* Link is disconnected. For all channels, send the event through */
389 /* their FSMs. The CCBs should remove themselves from the LCB */
390 for (p_ccb = p_lcb->ccb_queue.p_first_ccb; p_ccb; )
391 {
392 tL2C_CCB *pn = p_ccb->p_next_ccb;
393
394 /* Keep connect pending control block (if exists)
395 * Possible Race condition when a reconnect occurs
396 * on the channel during a disconnect of link. This
397 * ccb will be automatically retried after link disconnect
398 * arrives
399 */
400 if (p_ccb != p_lcb->p_pending_ccb)
401 {
402 l2c_csm_execute (p_ccb, L2CEVT_LP_DISCONNECT_IND, &reason);
403 }
404 p_ccb = pn;
405 }
406
Ganesh Ganapathi Batta8fe58872014-04-16 16:50:09 -0700407#if (BTM_SCO_INCLUDED == TRUE)
408#if (BLE_INCLUDED == TRUE)
409 if (p_lcb->transport == BT_TRANSPORT_BR_EDR)
410#endif
411 /* Tell SCO management to drop any SCOs on this ACL */
412 btm_sco_acl_removed (p_lcb->remote_bd_addr);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800413#endif
414
415 /* If waiting for disconnect and reconnect is pending start the reconnect now
416 race condition where layer above issued connect request on link that was
417 disconnecting
418 */
Ganesh Ganapathi Batta8fe58872014-04-16 16:50:09 -0700419 if (p_lcb->ccb_queue.p_first_ccb != NULL || p_lcb->p_pending_ccb)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800420 {
Prerepa Viswanadham7ae25152014-09-10 17:08:11 -0700421 L2CAP_TRACE_DEBUG("l2c_link_hci_disc_comp: Restarting pending ACL request");
Ganesh Ganapathi Batta8fe58872014-04-16 16:50:09 -0700422#if BLE_INCLUDED == TRUE
Prerepa Viswanadham7ae25152014-09-10 17:08:11 -0700423 /* for LE link, always drop and re-open to ensure to get LE remote feature */
424 if (p_lcb->transport == BT_TRANSPORT_LE)
425 {
426 l2cu_release_lcb (p_lcb);
427 p_lcb->in_use = TRUE;
428 transport = BT_TRANSPORT_LE;
429 }
430 else
431#endif
432 {
433 #if (L2CAP_NUM_FIXED_CHNLS > 0)
434 /* If we are going to re-use the LCB without dropping it, release all fixed channels
435 here */
436 int xx;
437 for (xx = 0; xx < L2CAP_NUM_FIXED_CHNLS; xx++)
438 {
439 if (p_lcb->p_fixed_ccbs[xx] && p_lcb->p_fixed_ccbs[xx] != p_lcb->p_pending_ccb)
440 {
441#if BLE_INCLUDED == TRUE
442 (*l2cb.fixed_reg[xx].pL2CA_FixedConn_Cb)(p_lcb->remote_bd_addr, FALSE,
443 p_lcb->disc_reason, p_lcb->transport);
Ganesh Ganapathi Batta8fe58872014-04-16 16:50:09 -0700444#else
Prerepa Viswanadham7ae25152014-09-10 17:08:11 -0700445 (*l2cb.fixed_reg[xx].pL2CA_FixedConn_Cb)(p_lcb->remote_bd_addr, FALSE,
446 p_lcb->disc_reason, BT_TRANSPORT_BR_EDR);
Ganesh Ganapathi Batta8fe58872014-04-16 16:50:09 -0700447#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -0800448 l2cu_release_ccb (p_lcb->p_fixed_ccbs[xx]);
449
450 p_lcb->p_fixed_ccbs[xx] = NULL;
Prerepa Viswanadham7ae25152014-09-10 17:08:11 -0700451 }
452 }
Ganesh Ganapathi Batta8fe58872014-04-16 16:50:09 -0700453#endif
Prerepa Viswanadham7ae25152014-09-10 17:08:11 -0700454 }
Ganesh Ganapathi Batta8fe58872014-04-16 16:50:09 -0700455 if (l2cu_create_conn(p_lcb, transport))
The Android Open Source Project5738f832012-12-12 16:00:35 -0800456 lcb_is_free = FALSE; /* still using this lcb */
457 }
458
459 p_lcb->p_pending_ccb = NULL;
460
461 /* Release the LCB */
462 if (lcb_is_free)
463 l2cu_release_lcb (p_lcb);
464 }
465
466 /* Now that we have a free acl connection, see if any lcbs are pending */
467 if (lcb_is_free && ((p_lcb = l2cu_find_lcb_by_state(LST_CONNECT_HOLDING)) != NULL))
468 {
469 /* we found one-- create a connection */
Ganesh Ganapathi Batta8fe58872014-04-16 16:50:09 -0700470 l2cu_create_conn(p_lcb, BT_TRANSPORT_BR_EDR);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800471 }
472
473 return status;
474}
475
476
477/*******************************************************************************
478**
479** Function l2c_link_hci_qos_violation
480**
481** Description This function is called when an HCI QOS Violation
482** event is received.
483**
484** Returns TRUE if the link is known about, else FALSE
485**
486*******************************************************************************/
487BOOLEAN l2c_link_hci_qos_violation (UINT16 handle)
488{
489 tL2C_LCB *p_lcb;
490 tL2C_CCB *p_ccb;
491
492 /* See if we have a link control block for the connection */
493 p_lcb = l2cu_find_lcb_by_handle (handle);
494
495 /* If we don't have one, maybe an SCO link. */
496 if (!p_lcb)
497 return (FALSE);
498
499 /* For all channels, tell the upper layer about it */
500 for (p_ccb = p_lcb->ccb_queue.p_first_ccb; p_ccb; p_ccb = p_ccb->p_next_ccb)
501 {
502 if (p_ccb->p_rcb->api.pL2CA_QoSViolationInd_Cb)
503 l2c_csm_execute (p_ccb, L2CEVT_LP_QOS_VIOLATION_IND, NULL);
504 }
505
506 return (TRUE);
507}
508
509
510
511/*******************************************************************************
512**
513** Function l2c_link_timeout
514**
515** Description This function is called when a link timer expires
516**
517** Returns void
518**
519*******************************************************************************/
520void l2c_link_timeout (tL2C_LCB *p_lcb)
521{
522 tL2C_CCB *p_ccb;
523 UINT16 timeout;
524 tBTM_STATUS rc;
525
Sharvil Nanavatia51c9d92014-05-04 01:08:21 -0700526 L2CAP_TRACE_EVENT ("L2CAP - l2c_link_timeout() link state %d first CCB %p is_bonding:%d",
The Android Open Source Project5738f832012-12-12 16:00:35 -0800527 p_lcb->link_state, p_lcb->ccb_queue.p_first_ccb, p_lcb->is_bonding);
528
529 /* If link was connecting or disconnecting, clear all channels and drop the LCB */
530 if ((p_lcb->link_state == LST_CONNECTING_WAIT_SWITCH) ||
531 (p_lcb->link_state == LST_CONNECTING) ||
532 (p_lcb->link_state == LST_CONNECT_HOLDING) ||
533 (p_lcb->link_state == LST_DISCONNECTING))
534 {
535 p_lcb->p_pending_ccb = NULL;
536
537 /* For all channels, send a disconnect indication event through */
538 /* their FSMs. The CCBs should remove themselves from the LCB */
539 for (p_ccb = p_lcb->ccb_queue.p_first_ccb; p_ccb; )
540 {
541 tL2C_CCB *pn = p_ccb->p_next_ccb;
542
543 l2c_csm_execute (p_ccb, L2CEVT_LP_DISCONNECT_IND, NULL);
544
545 p_ccb = pn;
546 }
547#if (BLE_INCLUDED == TRUE)
548 if (p_lcb->link_state == LST_CONNECTING &&
549 l2cb.is_ble_connecting == TRUE)
550 {
551 L2CA_CancelBleConnectReq(l2cb.ble_connecting_bda);
552 }
553#endif
554 /* Release the LCB */
555 l2cu_release_lcb (p_lcb);
556 }
557
558 /* If link is connected, check for inactivity timeout */
559 if (p_lcb->link_state == LST_CONNECTED)
560 {
561 /* Check for ping outstanding */
562 if (p_lcb->p_echo_rsp_cb)
563 {
564 tL2CA_ECHO_RSP_CB *p_cb = p_lcb->p_echo_rsp_cb;
565
566 /* Zero out the callback in case app immediately calls us again */
567 p_lcb->p_echo_rsp_cb = NULL;
568
569 (*p_cb) (L2CAP_PING_RESULT_NO_RESP);
570
Sharvil Nanavatia51c9d92014-05-04 01:08:21 -0700571 L2CAP_TRACE_WARNING ("L2CAP - ping timeout");
The Android Open Source Project5738f832012-12-12 16:00:35 -0800572
573 /* For all channels, send a disconnect indication event through */
574 /* their FSMs. The CCBs should remove themselves from the LCB */
575 for (p_ccb = p_lcb->ccb_queue.p_first_ccb; p_ccb; )
576 {
577 tL2C_CCB *pn = p_ccb->p_next_ccb;
578
579 l2c_csm_execute (p_ccb, L2CEVT_LP_DISCONNECT_IND, NULL);
580
581 p_ccb = pn;
582 }
583 }
584
585 /* If no channels in use, drop the link. */
586 if (!p_lcb->ccb_queue.p_first_ccb)
587 {
588 rc = btm_sec_disconnect (p_lcb->handle, HCI_ERR_PEER_USER);
589
590 if (rc == BTM_CMD_STORED)
591 {
592 /* Security Manager will take care of disconnecting, state will be updated at that time */
593 timeout = 0xFFFF;
594 }
595 else if (rc == BTM_CMD_STARTED)
596 {
597 p_lcb->link_state = LST_DISCONNECTING;
598 timeout = L2CAP_LINK_DISCONNECT_TOUT;
599 }
600 else if (rc == BTM_SUCCESS)
601 {
Ganesh Ganapathi Batta8fe58872014-04-16 16:50:09 -0700602 l2cu_process_fixed_disc_cback(p_lcb);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800603 /* BTM SEC will make sure that link is release (probably after pairing is done) */
604 p_lcb->link_state = LST_DISCONNECTING;
605 timeout = 0xFFFF;
606 }
607 else if (rc == BTM_BUSY)
608 {
609 /* BTM is still executing security process. Let lcb stay as connected */
610 timeout = 0xFFFF;
611 }
612 else if ((p_lcb->is_bonding)
613 && (btsnd_hcic_disconnect (p_lcb->handle, HCI_ERR_PEER_USER)))
614 {
Ganesh Ganapathi Batta8fe58872014-04-16 16:50:09 -0700615 l2cu_process_fixed_disc_cback(p_lcb);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800616 p_lcb->link_state = LST_DISCONNECTING;
617 timeout = L2CAP_LINK_DISCONNECT_TOUT;
618 }
619 else
620 {
621 /* probably no buffer to send disconnect */
622 timeout = BT_1SEC_TIMEOUT;
623 }
624
625 if (timeout != 0xFFFF)
626 {
627 btu_start_timer (&p_lcb->timer_entry, BTU_TTYPE_L2CAP_LINK, timeout);
628 }
629 }
630 else
631 {
632 /* Check in case we were flow controlled */
633 l2c_link_check_send_pkts (p_lcb, NULL, NULL);
634 }
635 }
636}
637
638/*******************************************************************************
639**
640** Function l2c_info_timeout
641**
642** Description This function is called when an info request times out
643**
644** Returns void
645**
646*******************************************************************************/
647void l2c_info_timeout (tL2C_LCB *p_lcb)
648{
649 tL2C_CCB *p_ccb;
650 tL2C_CONN_INFO ci;
651
652 /* If we timed out waiting for info response, just continue using basic if allowed */
653 if (p_lcb->w4_info_rsp)
654 {
655 /* If waiting for security complete, restart the info response timer */
656 for (p_ccb = p_lcb->ccb_queue.p_first_ccb; p_ccb; p_ccb = p_ccb->p_next_ccb)
657 {
658 if ( (p_ccb->chnl_state == CST_ORIG_W4_SEC_COMP) || (p_ccb->chnl_state == CST_TERM_W4_SEC_COMP) )
659 {
660 btu_start_timer (&p_lcb->info_timer_entry, BTU_TTYPE_L2CAP_INFO, L2CAP_WAIT_INFO_RSP_TOUT);
661 return;
662 }
663 }
664
665 p_lcb->w4_info_rsp = FALSE;
666
667 /* If link is in process of being brought up */
668 if ((p_lcb->link_state != LST_DISCONNECTED) &&
669 (p_lcb->link_state != LST_DISCONNECTING))
670 {
671 /* Notify active channels that peer info is finished */
672 if (p_lcb->ccb_queue.p_first_ccb)
673 {
674 ci.status = HCI_SUCCESS;
675 memcpy (ci.bd_addr, p_lcb->remote_bd_addr, sizeof(BD_ADDR));
676
677 for (p_ccb = p_lcb->ccb_queue.p_first_ccb; p_ccb; p_ccb = p_ccb->p_next_ccb)
678 {
679 l2c_csm_execute (p_ccb, L2CEVT_L2CAP_INFO_RSP, &ci);
680 }
681 }
682 }
683 }
684}
685
686/*******************************************************************************
687**
688** Function l2c_link_adjust_allocation
689**
690** Description This function is called when a link is created or removed
691** to calculate the amount of packets each link may send to
692** the HCI without an ack coming back.
693**
694** Currently, this is a simple allocation, dividing the
695** number of Controller Packets by the number of links. In
696** the future, QOS configuration should be examined.
697**
698** Returns void
699**
700*******************************************************************************/
701void l2c_link_adjust_allocation (void)
702{
703 UINT16 qq, yy, qq_remainder;
704 tL2C_LCB *p_lcb;
705 UINT16 hi_quota, low_quota;
706 UINT16 num_lowpri_links = 0;
707 UINT16 num_hipri_links = 0;
708 UINT16 controller_xmit_quota = l2cb.num_lm_acl_bufs;
709 UINT16 high_pri_link_quota = L2CAP_HIGH_PRI_MIN_XMIT_QUOTA_A;
710
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800711 /* If no links active, reset buffer quotas and controller buffers */
The Android Open Source Project5738f832012-12-12 16:00:35 -0800712 if (l2cb.num_links_active == 0)
713 {
714 l2cb.controller_xmit_window = l2cb.num_lm_acl_bufs;
715 l2cb.round_robin_quota = l2cb.round_robin_unacked = 0;
716 return;
717 }
718
719 /* First, count the links */
720 for (yy = 0, p_lcb = &l2cb.lcb_pool[0]; yy < MAX_L2CAP_LINKS; yy++, p_lcb++)
721 {
722 if (p_lcb->in_use)
723 {
724 if (p_lcb->acl_priority == L2CAP_PRIORITY_HIGH)
725 num_hipri_links++;
726 else
727 num_lowpri_links++;
728 }
729 }
730
731 /* now adjust high priority link quota */
732 low_quota = num_lowpri_links ? 1 : 0;
733 while ( (num_hipri_links * high_pri_link_quota + low_quota) > controller_xmit_quota )
734 high_pri_link_quota--;
735
736 /* Work out the xmit quota and buffer quota high and low priorities */
737 hi_quota = num_hipri_links * high_pri_link_quota;
738 low_quota = (hi_quota < controller_xmit_quota) ? controller_xmit_quota - hi_quota : 1;
739
740 /* Work out and save the HCI xmit quota for each low priority link */
741
742 /* If each low priority link cannot have at least one buffer */
743 if (num_lowpri_links > low_quota)
744 {
745 l2cb.round_robin_quota = low_quota;
Prerepa Viswanadham472c2a72014-10-23 13:50:57 -0700746 qq = qq_remainder = 1;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800747 }
748 /* If each low priority link can have at least one buffer */
749 else if (num_lowpri_links > 0)
750 {
751 l2cb.round_robin_quota = 0;
752 l2cb.round_robin_unacked = 0;
753 qq = low_quota / num_lowpri_links;
754 qq_remainder = low_quota % num_lowpri_links;
755 }
756 /* If no low priority link */
757 else
758 {
759 l2cb.round_robin_quota = 0;
760 l2cb.round_robin_unacked = 0;
Prerepa Viswanadham472c2a72014-10-23 13:50:57 -0700761 qq = qq_remainder = 1;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800762 }
763
Sharvil Nanavatia51c9d92014-05-04 01:08:21 -0700764 L2CAP_TRACE_EVENT ("l2c_link_adjust_allocation num_hipri: %u num_lowpri: %u low_quota: %u round_robin_quota: %u qq: %u",
The Android Open Source Project5738f832012-12-12 16:00:35 -0800765 num_hipri_links, num_lowpri_links, low_quota,
766 l2cb.round_robin_quota, qq);
767
768 /* Now, assign the quotas to each link */
769 for (yy = 0, p_lcb = &l2cb.lcb_pool[0]; yy < MAX_L2CAP_LINKS; yy++, p_lcb++)
770 {
771 if (p_lcb->in_use)
772 {
773 if (p_lcb->acl_priority == L2CAP_PRIORITY_HIGH)
774 {
775 p_lcb->link_xmit_quota = high_pri_link_quota;
776 }
777 else
778 {
779 /* Safety check in case we switched to round-robin with something outstanding */
780 /* if sent_not_acked is added into round_robin_unacked then don't add it again */
781 /* l2cap keeps updating sent_not_acked for exiting from round robin */
782 if (( p_lcb->link_xmit_quota > 0 )&&( qq == 0 ))
783 l2cb.round_robin_unacked += p_lcb->sent_not_acked;
784
785 p_lcb->link_xmit_quota = qq;
786 if (qq_remainder > 0)
787 {
788 p_lcb->link_xmit_quota++;
789 qq_remainder--;
790 }
791 }
792
Sharvil Nanavatia51c9d92014-05-04 01:08:21 -0700793 L2CAP_TRACE_EVENT ("l2c_link_adjust_allocation LCB %d Priority: %d XmitQuota: %d",
The Android Open Source Project5738f832012-12-12 16:00:35 -0800794 yy, p_lcb->acl_priority, p_lcb->link_xmit_quota);
795
Sharvil Nanavatia51c9d92014-05-04 01:08:21 -0700796 L2CAP_TRACE_EVENT (" SentNotAcked: %d RRUnacked: %d",
The Android Open Source Project5738f832012-12-12 16:00:35 -0800797 p_lcb->sent_not_acked, l2cb.round_robin_unacked);
798
799 /* There is a special case where we have readjusted the link quotas and */
800 /* this link may have sent anything but some other link sent packets so */
801 /* so we may need a timer to kick off this link's transmissions. */
802 if ( (p_lcb->link_state == LST_CONNECTED)
Chris Manton6c303ae2014-08-04 22:03:39 -0700803 && (!list_is_empty(p_lcb->link_xmit_data_q))
The Android Open Source Project5738f832012-12-12 16:00:35 -0800804 && (p_lcb->sent_not_acked < p_lcb->link_xmit_quota) )
805 btu_start_timer (&p_lcb->timer_entry, BTU_TTYPE_L2CAP_LINK, L2CAP_LINK_FLOW_CONTROL_TOUT);
806 }
807 }
808
809}
810
811/*******************************************************************************
812**
813** Function l2c_link_adjust_chnl_allocation
814**
815** Description This function is called to calculate the amount of packets each
816** non-F&EC channel may have outstanding.
817**
818** Currently, this is a simple allocation, dividing the number
819** of packets allocated to the link by the number of channels. In
820** the future, QOS configuration should be examined.
821**
822** Returns void
823**
824*******************************************************************************/
825void l2c_link_adjust_chnl_allocation (void)
826{
827 tL2C_CCB *p_ccb;
828 UINT8 xx;
829
830 UINT16 weighted_chnls[GKI_NUM_TOTAL_BUF_POOLS];
831 UINT16 quota_per_weighted_chnls[GKI_NUM_TOTAL_BUF_POOLS];
832 UINT16 reserved_buff[GKI_NUM_TOTAL_BUF_POOLS];
833
Sharvil Nanavatia51c9d92014-05-04 01:08:21 -0700834 L2CAP_TRACE_DEBUG ("l2c_link_adjust_chnl_allocation");
The Android Open Source Project5738f832012-12-12 16:00:35 -0800835
836 /* initialize variables */
837 for (xx = 0; xx < GKI_NUM_TOTAL_BUF_POOLS; xx++ )
838 {
839 weighted_chnls[xx] = 0;
840 reserved_buff[xx] = 0;
841 }
842
843 /* add up all of tx and rx data rate requirement */
844 /* channel required higher data rate will get more buffer quota */
845 for (xx = 0; xx < MAX_L2CAP_CHANNELS; xx++)
846 {
847 p_ccb = l2cb.ccb_pool + xx;
848
849 if (!p_ccb->in_use)
850 continue;
851
852 if (p_ccb->peer_cfg.fcr.mode != L2CAP_FCR_BASIC_MODE)
853 {
854 weighted_chnls[p_ccb->ertm_info.user_tx_pool_id] += p_ccb->tx_data_rate;
855 weighted_chnls[p_ccb->ertm_info.user_rx_pool_id] += p_ccb->rx_data_rate;
856
857 if (p_ccb->ertm_info.fcr_tx_pool_id == HCI_ACL_POOL_ID)
858 {
859 /* reserve buffers only for wait_for_ack_q to maximize throughput */
860 /* retrans_q will work based on buffer status */
861 reserved_buff[HCI_ACL_POOL_ID] += p_ccb->peer_cfg.fcr.tx_win_sz;
862 }
863
864 if (p_ccb->ertm_info.fcr_rx_pool_id == HCI_ACL_POOL_ID)
865 {
866 /* reserve buffers for srej_rcv_hold_q */
867 reserved_buff[HCI_ACL_POOL_ID] += p_ccb->peer_cfg.fcr.tx_win_sz;
868 }
869 }
870 else
871 {
872 /* low data rate is 1, medium is 2, high is 3 and no traffic is 0 */
873 weighted_chnls[HCI_ACL_POOL_ID] += p_ccb->tx_data_rate + p_ccb->rx_data_rate;
874 }
875 }
876
877
878 /* get unit quota per pool */
879 for (xx = 0; xx < GKI_NUM_TOTAL_BUF_POOLS; xx++ )
880 {
881 if ( weighted_chnls[xx] > 0 )
882 {
883 if (GKI_poolcount(xx) > reserved_buff[xx])
884 quota_per_weighted_chnls[xx] = ((GKI_poolcount(xx) - reserved_buff[xx])/weighted_chnls[xx]) + 1;
885 else
886 quota_per_weighted_chnls[xx] = 1;
887
Sharvil Nanavatia51c9d92014-05-04 01:08:21 -0700888 L2CAP_TRACE_DEBUG ("POOL ID:%d, GKI_poolcount = %d, reserved_buff = %d, weighted_chnls = %d, quota_per_weighted_chnls = %d",
The Android Open Source Project5738f832012-12-12 16:00:35 -0800889 xx, GKI_poolcount(xx), reserved_buff[xx], weighted_chnls[xx], quota_per_weighted_chnls[xx] );
890 }
891 else
892 quota_per_weighted_chnls[xx] = 0;
893 }
894
895
896 /* assign buffer quota to each channel based on its data rate requirement */
897 for (xx = 0; xx < MAX_L2CAP_CHANNELS; xx++)
898 {
899 p_ccb = l2cb.ccb_pool + xx;
900
901 if (!p_ccb->in_use)
902 continue;
903
904 if (p_ccb->peer_cfg.fcr.mode != L2CAP_FCR_BASIC_MODE)
905 {
906 p_ccb->buff_quota = quota_per_weighted_chnls[p_ccb->ertm_info.user_tx_pool_id] * p_ccb->tx_data_rate;
907
Sharvil Nanavatia51c9d92014-05-04 01:08:21 -0700908 L2CAP_TRACE_EVENT ("CID:0x%04x FCR Mode:%u UserTxPool:%u Priority:%u TxDataRate:%u Quota:%u",
The Android Open Source Project5738f832012-12-12 16:00:35 -0800909 p_ccb->local_cid, p_ccb->peer_cfg.fcr.mode, p_ccb->ertm_info.user_tx_pool_id,
910 p_ccb->ccb_priority, p_ccb->tx_data_rate, p_ccb->buff_quota);
911
912 }
913 else
914 {
915 p_ccb->buff_quota = quota_per_weighted_chnls[HCI_ACL_POOL_ID] * p_ccb->tx_data_rate;
916
Sharvil Nanavatia51c9d92014-05-04 01:08:21 -0700917 L2CAP_TRACE_EVENT ("CID:0x%04x Priority:%u TxDataRate:%u Quota:%u",
The Android Open Source Project5738f832012-12-12 16:00:35 -0800918 p_ccb->local_cid,
919 p_ccb->ccb_priority, p_ccb->tx_data_rate, p_ccb->buff_quota);
920 }
921
922 /* quota may be change so check congestion */
923 l2cu_check_channel_congestion (p_ccb);
924 }
925}
926
927/*******************************************************************************
928**
929** Function l2c_link_processs_num_bufs
930**
931** Description This function is called when a "controller buffer size"
932** event is first received from the controller. It updates
933** the L2CAP values.
934**
935** Returns void
936**
937*******************************************************************************/
938void l2c_link_processs_num_bufs (UINT16 num_lm_acl_bufs)
939{
940 l2cb.num_lm_acl_bufs = l2cb.controller_xmit_window = num_lm_acl_bufs;
941
942}
943
944/*******************************************************************************
945**
946** Function l2c_link_pkts_rcvd
947**
948** Description This function is called from the HCI transport when it is time
949** tto send a "Host ready for packets" command. This is only when
950** host to controller flow control is used. If fills in the arrays
951** of numbers of packets and handles.
952**
953** Returns count of number of entries filled in
954**
955*******************************************************************************/
956UINT8 l2c_link_pkts_rcvd (UINT16 *num_pkts, UINT16 *handles)
957{
958 UINT8 num_found = 0;
959
Mike J. Chen5cd8bff2014-01-31 18:16:59 -0800960 UNUSED(num_pkts);
961 UNUSED(handles);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800962
963 return (num_found);
964}
965
966/*******************************************************************************
967**
968** Function l2c_link_role_changed
969**
970** Description This function is called whan a link's master/slave role change
971** event is received. It simply updates the link control block.
972**
973** Returns void
974**
975*******************************************************************************/
976void l2c_link_role_changed (BD_ADDR bd_addr, UINT8 new_role, UINT8 hci_status)
977{
978 tL2C_LCB *p_lcb;
979 int xx;
980
981 /* Make sure not called from HCI Command Status (bd_addr and new_role are invalid) */
982 if (bd_addr)
983 {
984 /* If here came form hci role change event */
Ganesh Ganapathi Batta8fe58872014-04-16 16:50:09 -0700985 p_lcb = l2cu_find_lcb_by_bd_addr (bd_addr, BT_TRANSPORT_BR_EDR);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800986 if (p_lcb)
987 {
988 p_lcb->link_role = new_role;
989
990 /* Reset high priority link if needed */
991 if (hci_status == HCI_SUCCESS)
992 l2cu_set_acl_priority(bd_addr, p_lcb->acl_priority, TRUE);
993 }
994 }
995
996 /* Check if any LCB was waiting for switch to be completed */
997 for (xx = 0, p_lcb = &l2cb.lcb_pool[0]; xx < MAX_L2CAP_LINKS; xx++, p_lcb++)
998 {
999 if ((p_lcb->in_use) && (p_lcb->link_state == LST_CONNECTING_WAIT_SWITCH))
1000 {
1001 l2cu_create_conn_after_switch (p_lcb);
1002 }
1003 }
1004}
1005
1006/*******************************************************************************
1007**
1008** Function l2c_pin_code_request
1009**
1010** Description This function is called whan a pin-code request is received
1011** on a connection. If there are no channels active yet on the
1012** link, it extends the link first connection timer. Make sure
1013** that inactivity timer is not extended if PIN code happens
1014** to be after last ccb released.
1015**
1016** Returns void
1017**
1018*******************************************************************************/
1019void l2c_pin_code_request (BD_ADDR bd_addr)
1020{
Ganesh Ganapathi Batta8fe58872014-04-16 16:50:09 -07001021 tL2C_LCB *p_lcb = l2cu_find_lcb_by_bd_addr (bd_addr, BT_TRANSPORT_BR_EDR);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001022
1023 if ( (p_lcb) && (!p_lcb->ccb_queue.p_first_ccb) )
1024 {
1025 btu_start_timer (&p_lcb->timer_entry, BTU_TTYPE_L2CAP_LINK, L2CAP_LINK_CONNECT_TOUT_EXT);
1026 }
1027}
1028
Chris Mantone7ef4652014-10-15 16:31:49 -07001029#if L2CAP_WAKE_PARKED_LINK == TRUE
The Android Open Source Project5738f832012-12-12 16:00:35 -08001030/*******************************************************************************
1031**
1032** Function l2c_link_check_power_mode
1033**
1034** Description This function is called to check power mode.
1035**
1036** Returns TRUE if link is going to be active from park
1037** FALSE if nothing to send or not in park mode
1038**
1039*******************************************************************************/
1040BOOLEAN l2c_link_check_power_mode (tL2C_LCB *p_lcb)
1041{
1042 tBTM_PM_MODE mode;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001043 tL2C_CCB *p_ccb;
1044 BOOLEAN need_to_active = FALSE;
1045
1046 /*
1047 * We only switch park to active only if we have unsent packets
1048 */
Chris Manton6c303ae2014-08-04 22:03:39 -07001049 if (list_is_empty(p_lcb->link_xmit_data_q))
The Android Open Source Project5738f832012-12-12 16:00:35 -08001050 {
1051 for (p_ccb = p_lcb->ccb_queue.p_first_ccb; p_ccb; p_ccb = p_ccb->p_next_ccb)
1052 {
Chris Mantonfe7216c2014-05-06 10:35:42 -07001053 if (!GKI_queue_is_empty(&p_ccb->xmit_hold_q))
The Android Open Source Project5738f832012-12-12 16:00:35 -08001054 {
1055 need_to_active = TRUE;
1056 break;
1057 }
1058 }
1059 }
1060 else
1061 need_to_active = TRUE;
1062
1063 /* if we have packets to send */
1064 if ( need_to_active )
1065 {
1066 /* check power mode */
1067 if (BTM_ReadPowerMode(p_lcb->remote_bd_addr, &mode) == BTM_SUCCESS)
1068 {
The Android Open Source Project5738f832012-12-12 16:00:35 -08001069 if ( mode == BTM_PM_STS_PENDING )
1070 {
Sharvil Nanavatia51c9d92014-05-04 01:08:21 -07001071 L2CAP_TRACE_DEBUG ("LCB(0x%x) is in PM pending state", p_lcb->handle);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001072
The Android Open Source Project5738f832012-12-12 16:00:35 -08001073 return TRUE;
1074 }
1075 }
1076 }
1077 return FALSE;
1078}
Chris Mantone7ef4652014-10-15 16:31:49 -07001079#endif /* L2CAP_WAKE_PARKED_LINK == TRUE) */
The Android Open Source Project5738f832012-12-12 16:00:35 -08001080
1081/*******************************************************************************
1082**
1083** Function l2c_link_check_send_pkts
1084**
1085** Description This function is called to check if it can send packets
1086** to the Host Controller. It may be passed the address of
1087** a packet to send.
1088**
1089** Returns void
1090**
1091*******************************************************************************/
1092void l2c_link_check_send_pkts (tL2C_LCB *p_lcb, tL2C_CCB *p_ccb, BT_HDR *p_buf)
1093{
1094 int xx;
1095 BOOLEAN single_write = FALSE;
1096
1097 /* Save the channel ID for faster counting */
1098 if (p_buf)
1099 {
1100 if (p_ccb != NULL)
1101 {
1102 p_buf->event = p_ccb->local_cid;
1103 single_write = TRUE;
1104 }
1105 else
1106 p_buf->event = 0;
1107
1108 p_buf->layer_specific = 0;
Chris Manton6c303ae2014-08-04 22:03:39 -07001109 list_append(p_lcb->link_xmit_data_q, p_buf);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001110
1111 if (p_lcb->link_xmit_quota == 0)
Mudumba Ananth92ac2d82014-07-11 00:05:54 -07001112 {
1113#if BLE_INCLUDED == TRUE
1114 if (p_lcb->transport == BT_TRANSPORT_LE)
1115 l2cb.ble_check_round_robin = TRUE;
1116 else
1117#endif
1118 l2cb.check_round_robin = TRUE;
1119 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08001120 }
1121
1122 /* If this is called from uncongested callback context break recursive calling.
1123 ** This LCB will be served when receiving number of completed packet event.
1124 */
1125 if (l2cb.is_cong_cback_context)
1126 return;
1127
1128 /* If we are in a scenario where there are not enough buffers for each link to
1129 ** have at least 1, then do a round-robin for all the LCBs
1130 */
1131 if ( (p_lcb == NULL) || (p_lcb->link_xmit_quota == 0) )
1132 {
1133 if (p_lcb == NULL)
1134 p_lcb = l2cb.lcb_pool;
1135 else if (!single_write)
1136 p_lcb++;
1137
1138 /* Loop through, starting at the next */
1139 for (xx = 0; xx < MAX_L2CAP_LINKS; xx++, p_lcb++)
1140 {
1141 /* If controller window is full, nothing to do */
1142 if ( (l2cb.controller_xmit_window == 0
1143#if (BLE_INCLUDED == TRUE)
Ganesh Ganapathi Batta8fe58872014-04-16 16:50:09 -07001144 && (p_lcb->transport == BT_TRANSPORT_BR_EDR)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001145#endif
1146 )
1147#if (BLE_INCLUDED == TRUE)
Ganesh Ganapathi Batta8fe58872014-04-16 16:50:09 -07001148 || (p_lcb->transport == BT_TRANSPORT_LE && l2cb.controller_le_xmit_window == 0 )
The Android Open Source Project5738f832012-12-12 16:00:35 -08001149#endif
1150 || (l2cb.round_robin_unacked >= l2cb.round_robin_quota) )
1151 break;
1152
1153 /* Check for wraparound */
1154 if (p_lcb == &l2cb.lcb_pool[MAX_L2CAP_LINKS])
1155 p_lcb = &l2cb.lcb_pool[0];
1156
1157 if ( (!p_lcb->in_use)
1158 || (p_lcb->partial_segment_being_sent)
1159 || (p_lcb->link_state != LST_CONNECTED)
1160 || (p_lcb->link_xmit_quota != 0)
1161 || (L2C_LINK_CHECK_POWER_MODE (p_lcb)) )
1162 continue;
1163
1164 /* See if we can send anything from the Link Queue */
Chris Manton6c303ae2014-08-04 22:03:39 -07001165 if (!list_is_empty(p_lcb->link_xmit_data_q)) {
1166 p_buf = (BT_HDR *)list_front(p_lcb->link_xmit_data_q);
1167 list_remove(p_lcb->link_xmit_data_q, p_buf);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001168 l2c_link_send_to_lower (p_lcb, p_buf);
1169 }
1170 else if (single_write)
1171 {
1172 /* If only doing one write, break out */
1173 break;
1174 }
1175 /* If nothing on the link queue, check the channel queue */
1176 else if ((p_buf = l2cu_get_next_buffer_to_send (p_lcb)) != NULL)
1177 {
1178 l2c_link_send_to_lower (p_lcb, p_buf);
1179 }
1180 }
1181
1182 /* If we finished without using up our quota, no need for a safety check */
The Android Open Source Project5738f832012-12-12 16:00:35 -08001183 if ( (l2cb.controller_xmit_window > 0)
Mudumba Ananth92ac2d82014-07-11 00:05:54 -07001184 && (l2cb.round_robin_unacked < l2cb.round_robin_quota)
1185#if (BLE_INCLUDED == TRUE)
1186 && (p_lcb->transport == BT_TRANSPORT_BR_EDR)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001187#endif
Mudumba Ananth92ac2d82014-07-11 00:05:54 -07001188 )
The Android Open Source Project5738f832012-12-12 16:00:35 -08001189 l2cb.check_round_robin = FALSE;
Mudumba Ananth92ac2d82014-07-11 00:05:54 -07001190
1191#if (BLE_INCLUDED == TRUE)
1192 if ( (l2cb.controller_le_xmit_window > 0)
1193 && (l2cb.ble_round_robin_unacked < l2cb.ble_round_robin_quota)
1194 && (p_lcb->transport == BT_TRANSPORT_LE))
1195 l2cb.ble_check_round_robin = FALSE;
1196#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -08001197 }
1198 else /* if this is not round-robin service */
1199 {
1200 /* If a partial segment is being sent, can't send anything else */
1201 if ( (p_lcb->partial_segment_being_sent)
1202 || (p_lcb->link_state != LST_CONNECTED)
1203 || (L2C_LINK_CHECK_POWER_MODE (p_lcb)) )
1204 return;
1205
1206 /* See if we can send anything from the link queue */
1207#if (BLE_INCLUDED == TRUE)
Ganesh Ganapathi Batta8fe58872014-04-16 16:50:09 -07001208 while ( ((l2cb.controller_xmit_window != 0 && (p_lcb->transport == BT_TRANSPORT_BR_EDR)) ||
1209 (l2cb.controller_le_xmit_window != 0 && (p_lcb->transport == BT_TRANSPORT_LE)))
The Android Open Source Project5738f832012-12-12 16:00:35 -08001210 && (p_lcb->sent_not_acked < p_lcb->link_xmit_quota))
1211#else
1212 while ( (l2cb.controller_xmit_window != 0)
1213 && (p_lcb->sent_not_acked < p_lcb->link_xmit_quota))
1214#endif
1215 {
Chris Manton6c303ae2014-08-04 22:03:39 -07001216 if (list_is_empty(p_lcb->link_xmit_data_q))
The Android Open Source Project5738f832012-12-12 16:00:35 -08001217 break;
1218
Chris Manton6c303ae2014-08-04 22:03:39 -07001219 p_buf = (BT_HDR *)list_front(p_lcb->link_xmit_data_q);
1220 list_remove(p_lcb->link_xmit_data_q, p_buf);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001221 if (!l2c_link_send_to_lower (p_lcb, p_buf))
1222 break;
1223 }
1224
1225 if (!single_write)
1226 {
1227 /* See if we can send anything for any channel */
1228#if (BLE_INCLUDED == TRUE)
Ganesh Ganapathi Batta8fe58872014-04-16 16:50:09 -07001229 while ( ((l2cb.controller_xmit_window != 0 && (p_lcb->transport == BT_TRANSPORT_BR_EDR)) ||
1230 (l2cb.controller_le_xmit_window != 0 && (p_lcb->transport == BT_TRANSPORT_LE)))
The Android Open Source Project5738f832012-12-12 16:00:35 -08001231 && (p_lcb->sent_not_acked < p_lcb->link_xmit_quota))
1232#else
1233 while ((l2cb.controller_xmit_window != 0) && (p_lcb->sent_not_acked < p_lcb->link_xmit_quota))
1234#endif
1235 {
1236 if ((p_buf = l2cu_get_next_buffer_to_send (p_lcb)) == NULL)
1237 break;
1238
1239 if (!l2c_link_send_to_lower (p_lcb, p_buf))
1240 break;
1241 }
1242 }
1243
1244 /* There is a special case where we have readjusted the link quotas and */
1245 /* this link may have sent anything but some other link sent packets so */
1246 /* so we may need a timer to kick off this link's transmissions. */
Chris Manton6c303ae2014-08-04 22:03:39 -07001247 if ( (!list_is_empty(p_lcb->link_xmit_data_q)) && (p_lcb->sent_not_acked < p_lcb->link_xmit_quota) )
The Android Open Source Project5738f832012-12-12 16:00:35 -08001248 btu_start_timer (&p_lcb->timer_entry, BTU_TTYPE_L2CAP_LINK, L2CAP_LINK_FLOW_CONTROL_TOUT);
1249 }
1250
1251}
1252
1253/*******************************************************************************
1254**
1255** Function l2c_link_send_to_lower
1256**
1257** Description This function queues the buffer for HCI transmission
1258**
1259** Returns TRUE for success, FALSE for fail
1260**
1261*******************************************************************************/
1262static BOOLEAN l2c_link_send_to_lower (tL2C_LCB *p_lcb, BT_HDR *p_buf)
1263{
1264 UINT16 num_segs;
1265 UINT16 xmit_window, acl_data_size;
Zach Johnson30e58062014-09-26 21:14:34 -07001266 const controller_t *controller = controller_get_interface();
The Android Open Source Project5738f832012-12-12 16:00:35 -08001267
Zach Johnson30e58062014-09-26 21:14:34 -07001268 if ((p_buf->len <= controller->get_acl_packet_size_classic()
The Android Open Source Project5738f832012-12-12 16:00:35 -08001269#if (BLE_INCLUDED == TRUE)
Ganesh Ganapathi Batta8fe58872014-04-16 16:50:09 -07001270 && (p_lcb->transport == BT_TRANSPORT_BR_EDR)) ||
Zach Johnson30e58062014-09-26 21:14:34 -07001271 ((p_lcb->transport == BT_TRANSPORT_LE) && (p_buf->len <= controller->get_acl_packet_size_ble()))
The Android Open Source Project5738f832012-12-12 16:00:35 -08001272#else
Ganesh Ganapathi Batta8fe58872014-04-16 16:50:09 -07001273 )
The Android Open Source Project5738f832012-12-12 16:00:35 -08001274#endif
Ganesh Ganapathi Batta8fe58872014-04-16 16:50:09 -07001275 )
The Android Open Source Project5738f832012-12-12 16:00:35 -08001276 {
1277 if (p_lcb->link_xmit_quota == 0)
Mudumba Ananth92ac2d82014-07-11 00:05:54 -07001278 {
1279#if (BLE_INCLUDED == TRUE)
1280 if (p_lcb->transport == BT_TRANSPORT_LE)
1281 l2cb.ble_round_robin_unacked++;
1282 else
1283#endif
1284 l2cb.round_robin_unacked++;
1285 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08001286 p_lcb->sent_not_acked++;
1287 p_buf->layer_specific = 0;
1288
1289#if (BLE_INCLUDED == TRUE)
Ganesh Ganapathi Batta8fe58872014-04-16 16:50:09 -07001290 if (p_lcb->transport == BT_TRANSPORT_LE)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001291 {
1292 l2cb.controller_le_xmit_window--;
Chris Mantonf857d642014-09-26 13:31:41 -07001293 bte_main_hci_send(p_buf, (UINT16)(BT_EVT_TO_LM_HCI_ACL|LOCAL_BLE_CONTROLLER_ID));
The Android Open Source Project5738f832012-12-12 16:00:35 -08001294 }
1295 else
1296#endif
1297 {
1298 l2cb.controller_xmit_window--;
Chris Mantonf857d642014-09-26 13:31:41 -07001299 bte_main_hci_send(p_buf, BT_EVT_TO_LM_HCI_ACL);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001300 }
1301 }
1302 else
1303 {
1304#if BLE_INCLUDED == TRUE
Ganesh Ganapathi Batta8fe58872014-04-16 16:50:09 -07001305 if (p_lcb->transport == BT_TRANSPORT_LE)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001306 {
Zach Johnson30e58062014-09-26 21:14:34 -07001307 acl_data_size = controller->get_acl_data_size_ble();
The Android Open Source Project5738f832012-12-12 16:00:35 -08001308 xmit_window = l2cb.controller_le_xmit_window;
1309
1310 }
1311 else
1312#endif
1313 {
Zach Johnson30e58062014-09-26 21:14:34 -07001314 acl_data_size = controller->get_acl_data_size_classic();
The Android Open Source Project5738f832012-12-12 16:00:35 -08001315 xmit_window = l2cb.controller_xmit_window;
1316 }
1317 num_segs = (p_buf->len - HCI_DATA_PREAMBLE_SIZE + acl_data_size - 1) / acl_data_size;
1318
1319
1320 /* If doing round-robin, then only 1 segment each time */
1321 if (p_lcb->link_xmit_quota == 0)
1322 {
1323 num_segs = 1;
1324 p_lcb->partial_segment_being_sent = TRUE;
1325 }
1326 else
1327 {
1328 /* Multi-segment packet. Make sure it can fit */
1329 if (num_segs > xmit_window)
1330 {
1331 num_segs = xmit_window;
1332 p_lcb->partial_segment_being_sent = TRUE;
1333 }
1334
1335 if (num_segs > (p_lcb->link_xmit_quota - p_lcb->sent_not_acked))
1336 {
1337 num_segs = (p_lcb->link_xmit_quota - p_lcb->sent_not_acked);
1338 p_lcb->partial_segment_being_sent = TRUE;
1339 }
1340 }
1341
1342 p_buf->layer_specific = num_segs;
1343#if BLE_INCLUDED == TRUE
Ganesh Ganapathi Batta8fe58872014-04-16 16:50:09 -07001344 if (p_lcb->transport == BT_TRANSPORT_LE)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001345 {
1346 l2cb.controller_le_xmit_window -= num_segs;
Mudumba Ananth92ac2d82014-07-11 00:05:54 -07001347 if (p_lcb->link_xmit_quota == 0)
1348 l2cb.ble_round_robin_unacked += num_segs;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001349 }
1350 else
1351#endif
Mudumba Ananth92ac2d82014-07-11 00:05:54 -07001352 {
1353 l2cb.controller_xmit_window -= num_segs;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001354
Mudumba Ananth92ac2d82014-07-11 00:05:54 -07001355 if (p_lcb->link_xmit_quota == 0)
1356 l2cb.round_robin_unacked += num_segs;
1357 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08001358
1359 p_lcb->sent_not_acked += num_segs;
1360#if BLE_INCLUDED == TRUE
Ganesh Ganapathi Batta8fe58872014-04-16 16:50:09 -07001361 if (p_lcb->transport == BT_TRANSPORT_LE)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001362 {
Chris Mantonf857d642014-09-26 13:31:41 -07001363 bte_main_hci_send(p_buf, (UINT16)(BT_EVT_TO_LM_HCI_ACL|LOCAL_BLE_CONTROLLER_ID));
The Android Open Source Project5738f832012-12-12 16:00:35 -08001364 }
1365 else
1366#endif
1367 {
Chris Mantonf857d642014-09-26 13:31:41 -07001368 bte_main_hci_send(p_buf, BT_EVT_TO_LM_HCI_ACL);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001369 }
1370 }
1371
1372#if (L2CAP_HCI_FLOW_CONTROL_DEBUG == TRUE)
1373#if (BLE_INCLUDED == TRUE)
Ganesh Ganapathi Batta8fe58872014-04-16 16:50:09 -07001374 if (p_lcb->transport == BT_TRANSPORT_LE)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001375 {
Sharvil Nanavatia51c9d92014-05-04 01:08:21 -07001376 L2CAP_TRACE_DEBUG ("TotalWin=%d,Hndl=0x%x,Quota=%d,Unack=%d,RRQuota=%d,RRUnack=%d",
The Android Open Source Project5738f832012-12-12 16:00:35 -08001377 l2cb.controller_le_xmit_window,
1378 p_lcb->handle,
1379 p_lcb->link_xmit_quota, p_lcb->sent_not_acked,
Mudumba Ananth92ac2d82014-07-11 00:05:54 -07001380 l2cb.ble_round_robin_quota, l2cb.ble_round_robin_unacked);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001381 }
1382 else
1383#endif
1384 {
Sharvil Nanavatia51c9d92014-05-04 01:08:21 -07001385 L2CAP_TRACE_DEBUG ("TotalWin=%d,Hndl=0x%x,Quota=%d,Unack=%d,RRQuota=%d,RRUnack=%d",
The Android Open Source Project5738f832012-12-12 16:00:35 -08001386 l2cb.controller_xmit_window,
1387 p_lcb->handle,
1388 p_lcb->link_xmit_quota, p_lcb->sent_not_acked,
1389 l2cb.round_robin_quota, l2cb.round_robin_unacked);
1390 }
1391#endif
1392
1393 return TRUE;
1394}
1395
1396/*******************************************************************************
1397**
1398** Function l2c_link_process_num_completed_pkts
1399**
1400** Description This function is called when a "number-of-completed-packets"
1401** event is received from the controller. It updates all the
1402** LCB transmit counts.
1403**
1404** Returns void
1405**
1406*******************************************************************************/
1407void l2c_link_process_num_completed_pkts (UINT8 *p)
1408{
1409 UINT8 num_handles, xx;
1410 UINT16 handle;
1411 UINT16 num_sent;
1412 tL2C_LCB *p_lcb;
1413
1414 STREAM_TO_UINT8 (num_handles, p);
1415
1416 for (xx = 0; xx < num_handles; xx++)
1417 {
1418 STREAM_TO_UINT16 (handle, p);
1419 STREAM_TO_UINT16 (num_sent, p);
1420
1421 p_lcb = l2cu_find_lcb_by_handle (handle);
1422
1423 /* Callback for number of completed packet event */
1424 /* Originally designed for [3DSG] */
1425 if((p_lcb != NULL) && (p_lcb->p_nocp_cb))
1426 {
Sharvil Nanavatia51c9d92014-05-04 01:08:21 -07001427 L2CAP_TRACE_DEBUG ("L2CAP - calling NoCP callback");
The Android Open Source Project5738f832012-12-12 16:00:35 -08001428 (*p_lcb->p_nocp_cb)(p_lcb->remote_bd_addr);
1429 }
1430
The Android Open Source Project5738f832012-12-12 16:00:35 -08001431 if (p_lcb)
1432 {
Ganesh Ganapathi Battac9053e62013-04-16 11:57:07 -07001433#if (BLE_INCLUDED == TRUE)
Ganesh Ganapathi Batta8fe58872014-04-16 16:50:09 -07001434 if (p_lcb && (p_lcb->transport == BT_TRANSPORT_LE))
1435 l2cb.controller_le_xmit_window += num_sent;
1436 else
Ganesh Ganapathi Battac9053e62013-04-16 11:57:07 -07001437#endif
1438 {
1439 /* Maintain the total window to the controller */
1440 l2cb.controller_xmit_window += num_sent;
1441 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08001442 /* If doing round-robin, adjust communal counts */
1443 if (p_lcb->link_xmit_quota == 0)
1444 {
Mudumba Ananth92ac2d82014-07-11 00:05:54 -07001445#if BLE_INCLUDED == TRUE
1446 if (p_lcb->transport == BT_TRANSPORT_LE)
1447 {
1448 /* Don't go negative */
1449 if (l2cb.ble_round_robin_unacked > num_sent)
1450 l2cb.ble_round_robin_unacked -= num_sent;
1451 else
1452 l2cb.ble_round_robin_unacked = 0;
1453 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08001454 else
Mudumba Ananth92ac2d82014-07-11 00:05:54 -07001455#endif
1456 {
1457 /* Don't go negative */
1458 if (l2cb.round_robin_unacked > num_sent)
1459 l2cb.round_robin_unacked -= num_sent;
1460 else
1461 l2cb.round_robin_unacked = 0;
1462 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08001463 }
1464
1465 /* Don't go negative */
1466 if (p_lcb->sent_not_acked > num_sent)
1467 p_lcb->sent_not_acked -= num_sent;
1468 else
1469 p_lcb->sent_not_acked = 0;
1470
1471 l2c_link_check_send_pkts (p_lcb, NULL, NULL);
1472
1473 /* If we were doing round-robin for low priority links, check 'em */
1474 if ( (p_lcb->acl_priority == L2CAP_PRIORITY_HIGH)
1475 && (l2cb.check_round_robin)
1476 && (l2cb.round_robin_unacked < l2cb.round_robin_quota) )
1477 {
1478 l2c_link_check_send_pkts (NULL, NULL, NULL);
1479 }
Mudumba Ananth92ac2d82014-07-11 00:05:54 -07001480#if BLE_INCLUDED == TRUE
1481 if ((p_lcb->transport == BT_TRANSPORT_LE)
1482 && (p_lcb->acl_priority == L2CAP_PRIORITY_HIGH)
1483 && ((l2cb.ble_check_round_robin)
1484 && (l2cb.ble_round_robin_unacked < l2cb.ble_round_robin_quota)))
1485 {
1486 l2c_link_check_send_pkts (NULL, NULL, NULL);
1487 }
1488#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -08001489 }
1490
1491#if (L2CAP_HCI_FLOW_CONTROL_DEBUG == TRUE)
1492 if (p_lcb)
1493 {
1494#if (BLE_INCLUDED == TRUE)
Ganesh Ganapathi Batta8fe58872014-04-16 16:50:09 -07001495 if (p_lcb->transport == BT_TRANSPORT_LE)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001496 {
Sharvil Nanavatia51c9d92014-05-04 01:08:21 -07001497 L2CAP_TRACE_DEBUG ("TotalWin=%d,LinkUnack(0x%x)=%d,RRCheck=%d,RRUnack=%d",
The Android Open Source Project5738f832012-12-12 16:00:35 -08001498 l2cb.controller_le_xmit_window,
1499 p_lcb->handle, p_lcb->sent_not_acked,
Mudumba Ananth92ac2d82014-07-11 00:05:54 -07001500 l2cb.ble_check_round_robin, l2cb.ble_round_robin_unacked);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001501 }
1502 else
1503#endif
1504 {
Sharvil Nanavatia51c9d92014-05-04 01:08:21 -07001505 L2CAP_TRACE_DEBUG ("TotalWin=%d,LinkUnack(0x%x)=%d,RRCheck=%d,RRUnack=%d",
The Android Open Source Project5738f832012-12-12 16:00:35 -08001506 l2cb.controller_xmit_window,
1507 p_lcb->handle, p_lcb->sent_not_acked,
1508 l2cb.check_round_robin, l2cb.round_robin_unacked);
1509
1510 }
1511 }
1512 else
1513 {
1514#if (BLE_INCLUDED == TRUE)
Sharvil Nanavatia51c9d92014-05-04 01:08:21 -07001515 L2CAP_TRACE_DEBUG ("TotalWin=%d LE_Win: %d, Handle=0x%x, RRCheck=%d, RRUnack=%d",
The Android Open Source Project5738f832012-12-12 16:00:35 -08001516 l2cb.controller_xmit_window,
1517 l2cb.controller_le_xmit_window,
1518 handle,
Mudumba Ananth92ac2d82014-07-11 00:05:54 -07001519 l2cb.ble_check_round_robin, l2cb.ble_round_robin_unacked);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001520#else
Sharvil Nanavatia51c9d92014-05-04 01:08:21 -07001521 L2CAP_TRACE_DEBUG ("TotalWin=%d Handle=0x%x RRCheck=%d RRUnack=%d",
The Android Open Source Project5738f832012-12-12 16:00:35 -08001522 l2cb.controller_xmit_window,
1523 handle,
1524 l2cb.check_round_robin, l2cb.round_robin_unacked);
1525#endif
1526 }
1527#endif
1528 }
1529
1530#if (defined(HCILP_INCLUDED) && HCILP_INCLUDED == TRUE)
1531 /* only full stack can enable sleep mode */
1532 btu_check_bt_sleep ();
1533#endif
1534}
1535
1536/*******************************************************************************
1537**
The Android Open Source Project5738f832012-12-12 16:00:35 -08001538** Function l2c_link_segments_xmitted
1539**
1540** Description This function is called from the HCI Interface when an ACL
1541** data packet segment is transmitted.
1542**
1543** Returns void
1544**
1545*******************************************************************************/
1546void l2c_link_segments_xmitted (BT_HDR *p_msg)
1547{
1548 UINT8 *p = (UINT8 *)(p_msg + 1) + p_msg->offset;
1549 UINT16 handle;
1550 tL2C_LCB *p_lcb;
1551
1552 /* Extract the handle */
1553 STREAM_TO_UINT16 (handle, p);
1554 handle = HCID_GET_HANDLE (handle);
1555
1556 /* Find the LCB based on the handle */
1557 if ((p_lcb = l2cu_find_lcb_by_handle (handle)) == NULL)
1558 {
Sharvil Nanavatia51c9d92014-05-04 01:08:21 -07001559 L2CAP_TRACE_WARNING ("L2CAP - rcvd segment complete, unknown handle: %d", handle);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001560 GKI_freebuf (p_msg);
1561 return;
1562 }
1563
1564 if (p_lcb->link_state == LST_CONNECTED)
1565 {
1566 /* Enqueue the buffer to the head of the transmit queue, and see */
1567 /* if we can transmit anything more. */
Chris Manton6c303ae2014-08-04 22:03:39 -07001568 list_prepend(p_lcb->link_xmit_data_q, p_msg);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001569
1570 p_lcb->partial_segment_being_sent = FALSE;
1571
1572 l2c_link_check_send_pkts (p_lcb, NULL, NULL);
1573 }
1574 else
1575 GKI_freebuf (p_msg);
1576}