The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Copyright (C) 2003-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 module contains the link control state machine and functions which |
| 22 | * operate on the link control block. |
| 23 | * |
| 24 | ******************************************************************************/ |
| 25 | |
| 26 | #include <string.h> |
Chris Manton | 83e2c34 | 2014-09-29 21:37:44 -0700 | [diff] [blame] | 27 | #include "bt_types.h" |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 28 | #include "bt_target.h" |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 29 | #include "bt_utils.h" |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 30 | #include "avct_api.h" |
| 31 | #include "avct_int.h" |
Pavlin Radoslavov | 258c253 | 2015-09-27 20:59:05 -0700 | [diff] [blame] | 32 | #include "bt_common.h" |
Myles Watson | d7ffd64 | 2016-10-27 10:27:36 -0700 | [diff] [blame^] | 33 | #include "osi/include/osi.h" |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 34 | |
| 35 | /***************************************************************************** |
| 36 | ** state machine constants and types |
| 37 | *****************************************************************************/ |
| 38 | |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 39 | #if (BT_TRACE_VERBOSE == TRUE) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 40 | |
| 41 | /* verbose state strings for trace */ |
| 42 | const char * const avct_lcb_st_str[] = { |
| 43 | "LCB_IDLE_ST", |
| 44 | "LCB_OPENING_ST", |
| 45 | "LCB_OPEN_ST", |
| 46 | "LCB_CLOSING_ST" |
| 47 | }; |
| 48 | |
| 49 | /* verbose event strings for trace */ |
| 50 | const char * const avct_lcb_evt_str[] = { |
| 51 | "UL_BIND_EVT", |
| 52 | "UL_UNBIND_EVT", |
| 53 | "UL_MSG_EVT", |
| 54 | "INT_CLOSE_EVT", |
| 55 | "LL_OPEN_EVT", |
| 56 | "LL_CLOSE_EVT", |
| 57 | "LL_MSG_EVT", |
| 58 | "LL_CONG_EVT" |
| 59 | }; |
| 60 | |
| 61 | #endif |
| 62 | |
| 63 | /* lcb state machine states */ |
| 64 | enum { |
| 65 | AVCT_LCB_IDLE_ST, |
| 66 | AVCT_LCB_OPENING_ST, |
| 67 | AVCT_LCB_OPEN_ST, |
| 68 | AVCT_LCB_CLOSING_ST |
| 69 | }; |
| 70 | |
| 71 | /* state machine action enumeration list */ |
| 72 | enum { |
| 73 | AVCT_LCB_CHNL_OPEN, |
| 74 | AVCT_LCB_CHNL_DISC, |
| 75 | AVCT_LCB_SEND_MSG, |
| 76 | AVCT_LCB_OPEN_IND, |
| 77 | AVCT_LCB_OPEN_FAIL, |
| 78 | AVCT_LCB_CLOSE_IND, |
| 79 | AVCT_LCB_CLOSE_CFM, |
| 80 | AVCT_LCB_MSG_IND, |
| 81 | AVCT_LCB_CONG_IND, |
| 82 | AVCT_LCB_BIND_CONN, |
| 83 | AVCT_LCB_BIND_FAIL, |
| 84 | AVCT_LCB_UNBIND_DISC, |
| 85 | AVCT_LCB_CHK_DISC, |
| 86 | AVCT_LCB_DISCARD_MSG, |
| 87 | AVCT_LCB_DEALLOC, |
| 88 | AVCT_LCB_FREE_MSG_IND, |
| 89 | AVCT_LCB_NUM_ACTIONS |
| 90 | }; |
| 91 | |
| 92 | #define AVCT_LCB_IGNORE AVCT_LCB_NUM_ACTIONS |
| 93 | |
| 94 | /* type for action functions */ |
| 95 | typedef void (*tAVCT_LCB_ACTION)(tAVCT_LCB *p_ccb, tAVCT_LCB_EVT *p_data); |
| 96 | |
| 97 | /* action function list */ |
| 98 | const tAVCT_LCB_ACTION avct_lcb_action[] = { |
| 99 | avct_lcb_chnl_open, |
| 100 | avct_lcb_chnl_disc, |
| 101 | avct_lcb_send_msg, |
| 102 | avct_lcb_open_ind, |
| 103 | avct_lcb_open_fail, |
| 104 | avct_lcb_close_ind, |
| 105 | avct_lcb_close_cfm, |
| 106 | avct_lcb_msg_ind, |
| 107 | avct_lcb_cong_ind, |
| 108 | avct_lcb_bind_conn, |
| 109 | avct_lcb_bind_fail, |
| 110 | avct_lcb_unbind_disc, |
| 111 | avct_lcb_chk_disc, |
| 112 | avct_lcb_discard_msg, |
| 113 | avct_lcb_dealloc, |
| 114 | avct_lcb_free_msg_ind |
| 115 | }; |
| 116 | |
| 117 | /* state table information */ |
| 118 | #define AVCT_LCB_ACTIONS 2 /* number of actions */ |
| 119 | #define AVCT_LCB_NEXT_STATE 2 /* position of next state */ |
| 120 | #define AVCT_LCB_NUM_COLS 3 /* number of columns in state tables */ |
| 121 | |
| 122 | /* state table for idle state */ |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 123 | const uint8_t avct_lcb_st_idle[][AVCT_LCB_NUM_COLS] = { |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 124 | /* Event Action 1 Action 2 Next state */ |
| 125 | /* UL_BIND_EVT */ {AVCT_LCB_CHNL_OPEN, AVCT_LCB_IGNORE, AVCT_LCB_OPENING_ST}, |
| 126 | /* UL_UNBIND_EVT */ {AVCT_LCB_UNBIND_DISC, AVCT_LCB_IGNORE, AVCT_LCB_IDLE_ST}, |
| 127 | /* UL_MSG_EVT */ {AVCT_LCB_DISCARD_MSG, AVCT_LCB_IGNORE, AVCT_LCB_IDLE_ST}, |
| 128 | /* INT_CLOSE_EVT */ {AVCT_LCB_IGNORE, AVCT_LCB_IGNORE, AVCT_LCB_IDLE_ST}, |
| 129 | /* LL_OPEN_EVT */ {AVCT_LCB_OPEN_IND, AVCT_LCB_IGNORE, AVCT_LCB_OPEN_ST}, |
| 130 | /* LL_CLOSE_EVT */ {AVCT_LCB_CLOSE_IND, AVCT_LCB_DEALLOC, AVCT_LCB_IDLE_ST}, |
| 131 | /* LL_MSG_EVT */ {AVCT_LCB_FREE_MSG_IND, AVCT_LCB_IGNORE, AVCT_LCB_IDLE_ST}, |
| 132 | /* LL_CONG_EVT */ {AVCT_LCB_IGNORE, AVCT_LCB_IGNORE, AVCT_LCB_IDLE_ST} |
| 133 | }; |
| 134 | |
| 135 | /* state table for opening state */ |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 136 | const uint8_t avct_lcb_st_opening[][AVCT_LCB_NUM_COLS] = { |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 137 | /* Event Action 1 Action 2 Next state */ |
| 138 | /* UL_BIND_EVT */ {AVCT_LCB_IGNORE, AVCT_LCB_IGNORE, AVCT_LCB_OPENING_ST}, |
| 139 | /* UL_UNBIND_EVT */ {AVCT_LCB_UNBIND_DISC, AVCT_LCB_IGNORE, AVCT_LCB_OPENING_ST}, |
| 140 | /* UL_MSG_EVT */ {AVCT_LCB_DISCARD_MSG, AVCT_LCB_IGNORE, AVCT_LCB_OPENING_ST}, |
| 141 | /* INT_CLOSE_EVT */ {AVCT_LCB_CHNL_DISC, AVCT_LCB_IGNORE, AVCT_LCB_CLOSING_ST}, |
| 142 | /* LL_OPEN_EVT */ {AVCT_LCB_OPEN_IND, AVCT_LCB_IGNORE, AVCT_LCB_OPEN_ST}, |
| 143 | /* LL_CLOSE_EVT */ {AVCT_LCB_OPEN_FAIL, AVCT_LCB_DEALLOC, AVCT_LCB_IDLE_ST}, |
| 144 | /* LL_MSG_EVT */ {AVCT_LCB_FREE_MSG_IND, AVCT_LCB_IGNORE, AVCT_LCB_OPENING_ST}, |
| 145 | /* LL_CONG_EVT */ {AVCT_LCB_CONG_IND, AVCT_LCB_IGNORE, AVCT_LCB_OPENING_ST} |
| 146 | }; |
| 147 | |
| 148 | /* state table for open state */ |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 149 | const uint8_t avct_lcb_st_open[][AVCT_LCB_NUM_COLS] = { |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 150 | /* Event Action 1 Action 2 Next state */ |
| 151 | /* UL_BIND_EVT */ {AVCT_LCB_BIND_CONN, AVCT_LCB_IGNORE, AVCT_LCB_OPEN_ST}, |
| 152 | /* UL_UNBIND_EVT */ {AVCT_LCB_CHK_DISC, AVCT_LCB_IGNORE, AVCT_LCB_OPEN_ST}, |
| 153 | /* UL_MSG_EVT */ {AVCT_LCB_SEND_MSG, AVCT_LCB_IGNORE, AVCT_LCB_OPEN_ST}, |
| 154 | /* INT_CLOSE_EVT */ {AVCT_LCB_CHNL_DISC, AVCT_LCB_IGNORE, AVCT_LCB_CLOSING_ST}, |
| 155 | /* LL_OPEN_EVT */ {AVCT_LCB_IGNORE, AVCT_LCB_IGNORE, AVCT_LCB_OPEN_ST}, |
| 156 | /* LL_CLOSE_EVT */ {AVCT_LCB_CLOSE_IND, AVCT_LCB_DEALLOC, AVCT_LCB_IDLE_ST}, |
| 157 | /* LL_MSG_EVT */ {AVCT_LCB_MSG_IND, AVCT_LCB_IGNORE, AVCT_LCB_OPEN_ST}, |
| 158 | /* LL_CONG_EVT */ {AVCT_LCB_CONG_IND, AVCT_LCB_IGNORE, AVCT_LCB_OPEN_ST} |
| 159 | }; |
| 160 | |
| 161 | /* state table for closing state */ |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 162 | const uint8_t avct_lcb_st_closing[][AVCT_LCB_NUM_COLS] = { |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 163 | /* Event Action 1 Action 2 Next state */ |
| 164 | /* UL_BIND_EVT */ {AVCT_LCB_BIND_FAIL, AVCT_LCB_IGNORE, AVCT_LCB_CLOSING_ST}, |
| 165 | /* UL_UNBIND_EVT */ {AVCT_LCB_IGNORE, AVCT_LCB_IGNORE, AVCT_LCB_CLOSING_ST}, |
| 166 | /* UL_MSG_EVT */ {AVCT_LCB_DISCARD_MSG, AVCT_LCB_IGNORE, AVCT_LCB_CLOSING_ST}, |
| 167 | /* INT_CLOSE_EVT */ {AVCT_LCB_IGNORE, AVCT_LCB_IGNORE, AVCT_LCB_CLOSING_ST}, |
| 168 | /* LL_OPEN_EVT */ {AVCT_LCB_IGNORE, AVCT_LCB_IGNORE, AVCT_LCB_CLOSING_ST}, |
| 169 | /* LL_CLOSE_EVT */ {AVCT_LCB_CLOSE_CFM, AVCT_LCB_DEALLOC, AVCT_LCB_IDLE_ST}, |
| 170 | /* LL_MSG_EVT */ {AVCT_LCB_FREE_MSG_IND, AVCT_LCB_IGNORE, AVCT_LCB_CLOSING_ST}, |
| 171 | /* LL_CONG_EVT */ {AVCT_LCB_IGNORE, AVCT_LCB_IGNORE, AVCT_LCB_CLOSING_ST} |
| 172 | }; |
| 173 | |
| 174 | /* type for state table */ |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 175 | typedef const uint8_t (*tAVCT_LCB_ST_TBL)[AVCT_LCB_NUM_COLS]; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 176 | |
| 177 | /* state table */ |
| 178 | const tAVCT_LCB_ST_TBL avct_lcb_st_tbl[] = { |
| 179 | avct_lcb_st_idle, |
| 180 | avct_lcb_st_opening, |
| 181 | avct_lcb_st_open, |
| 182 | avct_lcb_st_closing |
| 183 | }; |
| 184 | |
| 185 | /******************************************************************************* |
| 186 | ** |
| 187 | ** Function avct_lcb_event |
| 188 | ** |
| 189 | ** Description State machine event handling function for lcb |
| 190 | ** |
| 191 | ** |
| 192 | ** Returns Nothing. |
| 193 | ** |
| 194 | *******************************************************************************/ |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 195 | void avct_lcb_event(tAVCT_LCB *p_lcb, uint8_t event, tAVCT_LCB_EVT *p_data) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 196 | { |
| 197 | tAVCT_LCB_ST_TBL state_table; |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 198 | uint8_t action; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 199 | int i; |
| 200 | |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 201 | #if (BT_TRACE_VERBOSE == TRUE) |
Sharvil Nanavati | 158084e | 2014-05-04 09:53:44 -0700 | [diff] [blame] | 202 | AVCT_TRACE_EVENT("LCB lcb=%d event=%s state=%s", p_lcb->allocated, avct_lcb_evt_str[event], avct_lcb_st_str[p_lcb->state]); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 203 | #else |
Sharvil Nanavati | 158084e | 2014-05-04 09:53:44 -0700 | [diff] [blame] | 204 | AVCT_TRACE_EVENT("LCB lcb=%d event=%d state=%d", p_lcb->allocated, event, p_lcb->state); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 205 | #endif |
| 206 | |
| 207 | /* look up the state table for the current state */ |
| 208 | state_table = avct_lcb_st_tbl[p_lcb->state]; |
| 209 | |
| 210 | /* set next state */ |
| 211 | p_lcb->state = state_table[event][AVCT_LCB_NEXT_STATE]; |
| 212 | |
| 213 | /* execute action functions */ |
| 214 | for (i = 0; i < AVCT_LCB_ACTIONS; i++) |
| 215 | { |
| 216 | if ((action = state_table[event][i]) != AVCT_LCB_IGNORE) |
| 217 | { |
| 218 | (*avct_lcb_action[action])(p_lcb, p_data); |
| 219 | } |
| 220 | else |
| 221 | { |
| 222 | break; |
| 223 | } |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | /******************************************************************************* |
| 228 | ** |
| 229 | ** Function avct_bcb_event |
| 230 | ** |
| 231 | ** Description State machine event handling function for lcb |
| 232 | ** |
| 233 | ** |
| 234 | ** Returns Nothing. |
| 235 | ** |
| 236 | *******************************************************************************/ |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 237 | void avct_bcb_event(tAVCT_BCB *p_bcb, uint8_t event, tAVCT_LCB_EVT *p_data) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 238 | { |
| 239 | tAVCT_LCB_ST_TBL state_table; |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 240 | uint8_t action; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 241 | int i; |
| 242 | |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 243 | #if (BT_TRACE_VERBOSE == TRUE) |
Sharvil Nanavati | 158084e | 2014-05-04 09:53:44 -0700 | [diff] [blame] | 244 | AVCT_TRACE_EVENT("BCB lcb=%d event=%s state=%s", p_bcb->allocated, avct_lcb_evt_str[event], avct_lcb_st_str[p_bcb->state]); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 245 | #else |
Sharvil Nanavati | 158084e | 2014-05-04 09:53:44 -0700 | [diff] [blame] | 246 | AVCT_TRACE_EVENT("BCB lcb=%d event=%d state=%d", p_bcb->allocated, event, p_bcb->state); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 247 | #endif |
| 248 | |
| 249 | /* look up the state table for the current state */ |
| 250 | state_table = avct_lcb_st_tbl[p_bcb->state]; |
| 251 | |
| 252 | /* set next state */ |
| 253 | p_bcb->state = state_table[event][AVCT_LCB_NEXT_STATE]; |
| 254 | |
| 255 | /* execute action functions */ |
| 256 | for (i = 0; i < AVCT_LCB_ACTIONS; i++) |
| 257 | { |
| 258 | if ((action = state_table[event][i]) != AVCT_LCB_IGNORE) |
| 259 | { |
| 260 | (*avct_bcb_action[action])(p_bcb, p_data); |
| 261 | } |
| 262 | else |
| 263 | { |
| 264 | break; |
| 265 | } |
| 266 | } |
| 267 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 268 | |
| 269 | /******************************************************************************* |
| 270 | ** |
| 271 | ** Function avct_lcb_by_bd |
| 272 | ** |
| 273 | ** Description This lookup function finds the lcb for a BD address. |
| 274 | ** |
| 275 | ** |
| 276 | ** Returns pointer to the lcb, or NULL if none found. |
| 277 | ** |
| 278 | *******************************************************************************/ |
| 279 | tAVCT_LCB *avct_lcb_by_bd(BD_ADDR bd_addr) |
| 280 | { |
| 281 | tAVCT_LCB *p_lcb = &avct_cb.lcb[0]; |
| 282 | int i; |
| 283 | |
| 284 | for (i = 0; i < AVCT_NUM_LINKS; i++, p_lcb++) |
| 285 | { |
| 286 | /* if allocated lcb has matching lcb */ |
| 287 | if (p_lcb->allocated && (!memcmp(p_lcb->peer_addr, bd_addr, BD_ADDR_LEN))) |
| 288 | { |
| 289 | break; |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | if (i == AVCT_NUM_LINKS) |
| 294 | { |
| 295 | /* if no lcb found */ |
| 296 | p_lcb = NULL; |
| 297 | |
Sharvil Nanavati | 158084e | 2014-05-04 09:53:44 -0700 | [diff] [blame] | 298 | AVCT_TRACE_DEBUG("No lcb for addr %02x-%02x-%02x-%02x-%02x-%02x", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 299 | bd_addr[0], bd_addr[1], bd_addr[2], bd_addr[3], bd_addr[4], bd_addr[5]); |
| 300 | } |
| 301 | return p_lcb; |
| 302 | } |
| 303 | |
| 304 | /******************************************************************************* |
| 305 | ** |
| 306 | ** Function avct_lcb_alloc |
| 307 | ** |
| 308 | ** Description Allocate a link control block. |
| 309 | ** |
| 310 | ** |
| 311 | ** Returns pointer to the lcb, or NULL if none could be allocated. |
| 312 | ** |
| 313 | *******************************************************************************/ |
| 314 | tAVCT_LCB *avct_lcb_alloc(BD_ADDR bd_addr) |
| 315 | { |
| 316 | tAVCT_LCB *p_lcb = &avct_cb.lcb[0]; |
| 317 | int i; |
| 318 | |
| 319 | for (i = 0; i < AVCT_NUM_LINKS; i++, p_lcb++) |
| 320 | { |
| 321 | if (!p_lcb->allocated) |
| 322 | { |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 323 | p_lcb->allocated = (uint8_t)(i + 1); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 324 | memcpy(p_lcb->peer_addr, bd_addr, BD_ADDR_LEN); |
Sharvil Nanavati | 158084e | 2014-05-04 09:53:44 -0700 | [diff] [blame] | 325 | AVCT_TRACE_DEBUG("avct_lcb_alloc %d", p_lcb->allocated); |
Pavlin Radoslavov | 1a3844f | 2015-09-25 11:21:15 -0700 | [diff] [blame] | 326 | p_lcb->tx_q = fixed_queue_new(SIZE_MAX); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 327 | break; |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | if (i == AVCT_NUM_LINKS) |
| 332 | { |
| 333 | /* out of lcbs */ |
| 334 | p_lcb = NULL; |
Sharvil Nanavati | 158084e | 2014-05-04 09:53:44 -0700 | [diff] [blame] | 335 | AVCT_TRACE_WARNING("Out of lcbs"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 336 | } |
| 337 | return p_lcb; |
| 338 | } |
| 339 | |
| 340 | /******************************************************************************* |
| 341 | ** |
| 342 | ** Function avct_lcb_dealloc |
| 343 | ** |
| 344 | ** Description Deallocate a link control block. |
| 345 | ** |
| 346 | ** |
| 347 | ** Returns void. |
| 348 | ** |
| 349 | *******************************************************************************/ |
Myles Watson | d35a648 | 2016-10-27 08:52:16 -0700 | [diff] [blame] | 350 | void avct_lcb_dealloc(tAVCT_LCB *p_lcb, |
| 351 | UNUSED_ATTR tAVCT_LCB_EVT *p_data) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 352 | { |
Andre Eisenbach | 072bd75 | 2016-03-18 02:09:58 -0700 | [diff] [blame] | 353 | AVCT_TRACE_DEBUG("%s allocated: %d", __func__, p_lcb->allocated); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 354 | |
Andre Eisenbach | 072bd75 | 2016-03-18 02:09:58 -0700 | [diff] [blame] | 355 | // Check if the LCB is still referenced |
| 356 | |
| 357 | tAVCT_CCB *p_ccb = &avct_cb.ccb[0]; |
| 358 | for (size_t i = 0; i < AVCT_NUM_CONN; i++, p_ccb++) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 359 | { |
Andre Eisenbach | 072bd75 | 2016-03-18 02:09:58 -0700 | [diff] [blame] | 360 | if (p_ccb->allocated && p_ccb->p_lcb == p_lcb) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 361 | { |
Andre Eisenbach | 072bd75 | 2016-03-18 02:09:58 -0700 | [diff] [blame] | 362 | AVCT_TRACE_DEBUG("%s LCB in use; lcb index: %d", __func__, i); |
| 363 | return; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 364 | } |
| 365 | } |
| 366 | |
Andre Eisenbach | 072bd75 | 2016-03-18 02:09:58 -0700 | [diff] [blame] | 367 | // If not, de-allocate now... |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 368 | |
Andre Eisenbach | 072bd75 | 2016-03-18 02:09:58 -0700 | [diff] [blame] | 369 | AVCT_TRACE_DEBUG("%s Freeing LCB", __func__); |
| 370 | osi_free(p_lcb->p_rx_msg); |
| 371 | fixed_queue_free(p_lcb->tx_q, NULL); |
| 372 | memset(p_lcb, 0, sizeof(tAVCT_LCB)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | /******************************************************************************* |
| 376 | ** |
| 377 | ** Function avct_lcb_by_lcid |
| 378 | ** |
| 379 | ** Description Find the LCB associated with the L2CAP LCID |
| 380 | ** |
| 381 | ** |
| 382 | ** Returns pointer to the lcb, or NULL if none found. |
| 383 | ** |
| 384 | *******************************************************************************/ |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 385 | tAVCT_LCB *avct_lcb_by_lcid(uint16_t lcid) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 386 | { |
| 387 | tAVCT_LCB *p_lcb = &avct_cb.lcb[0]; |
| 388 | int i; |
| 389 | |
| 390 | for (i = 0; i < AVCT_NUM_LINKS; i++, p_lcb++) |
| 391 | { |
| 392 | if (p_lcb->allocated && ((p_lcb->ch_lcid == lcid) || (p_lcb->conflict_lcid == lcid))) |
| 393 | { |
| 394 | break; |
| 395 | } |
| 396 | } |
| 397 | |
| 398 | if (i == AVCT_NUM_LINKS) |
| 399 | { |
| 400 | /* out of lcbs */ |
| 401 | p_lcb = NULL; |
Sharvil Nanavati | 158084e | 2014-05-04 09:53:44 -0700 | [diff] [blame] | 402 | AVCT_TRACE_WARNING("No lcb for lcid %x", lcid); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | return p_lcb; |
| 406 | } |
| 407 | |
| 408 | /******************************************************************************* |
| 409 | ** |
| 410 | ** Function avct_lcb_has_pid |
| 411 | ** |
| 412 | ** Description See if any ccbs on this lcb have a particular pid. |
| 413 | ** |
| 414 | ** |
| 415 | ** Returns Pointer to CCB if PID found, NULL otherwise. |
| 416 | ** |
| 417 | *******************************************************************************/ |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 418 | tAVCT_CCB *avct_lcb_has_pid(tAVCT_LCB *p_lcb, uint16_t pid) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 419 | { |
| 420 | tAVCT_CCB *p_ccb = &avct_cb.ccb[0]; |
| 421 | int i; |
| 422 | |
| 423 | for (i = 0; i < AVCT_NUM_CONN; i++, p_ccb++) |
| 424 | { |
| 425 | if (p_ccb->allocated && (p_ccb->p_lcb == p_lcb) && (p_ccb->cc.pid == pid)) |
| 426 | { |
| 427 | return p_ccb; |
| 428 | } |
| 429 | } |
| 430 | return NULL; |
| 431 | } |
| 432 | |
| 433 | /******************************************************************************* |
| 434 | ** |
| 435 | ** Function avct_lcb_last_ccb |
| 436 | ** |
| 437 | ** Description See if given ccb is only one on the lcb. |
| 438 | ** |
| 439 | ** |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 440 | ** Returns true if ccb is last, false otherwise. |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 441 | ** |
| 442 | *******************************************************************************/ |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 443 | bool avct_lcb_last_ccb(tAVCT_LCB *p_lcb, tAVCT_CCB *p_ccb_last) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 444 | { |
| 445 | tAVCT_CCB *p_ccb = &avct_cb.ccb[0]; |
| 446 | int i; |
| 447 | |
Sharvil Nanavati | 158084e | 2014-05-04 09:53:44 -0700 | [diff] [blame] | 448 | AVCT_TRACE_WARNING("avct_lcb_last_ccb"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 449 | for (i = 0; i < AVCT_NUM_CONN; i++, p_ccb++) |
| 450 | { |
Sharvil Nanavati | 158084e | 2014-05-04 09:53:44 -0700 | [diff] [blame] | 451 | AVCT_TRACE_WARNING("%x: aloc:%d, lcb:0x%x/0x%x, ccb:0x%x/0x%x", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 452 | i, p_ccb->allocated, p_ccb->p_lcb, p_lcb, p_ccb, p_ccb_last); |
| 453 | if (p_ccb->allocated && (p_ccb->p_lcb == p_lcb) && (p_ccb != p_ccb_last)) |
| 454 | { |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 455 | return false; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 456 | } |
| 457 | } |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 458 | return true; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | |
| 462 | |