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 functions which operate on the AVCTP connection |
| 22 | * 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" |
| 29 | #include "avct_api.h" |
| 30 | #include "avct_int.h" |
| 31 | |
| 32 | /******************************************************************************* |
| 33 | ** |
| 34 | ** Function avct_ccb_alloc |
| 35 | ** |
| 36 | ** Description Allocate a connection control block; copy parameters to ccb. |
| 37 | ** |
| 38 | ** |
| 39 | ** Returns pointer to the ccb, or NULL if none could be allocated. |
| 40 | ** |
| 41 | *******************************************************************************/ |
| 42 | tAVCT_CCB *avct_ccb_alloc(tAVCT_CC *p_cc) |
| 43 | { |
| 44 | tAVCT_CCB *p_ccb = &avct_cb.ccb[0]; |
| 45 | int i; |
| 46 | |
| 47 | for (i = 0; i < AVCT_NUM_CONN; i++, p_ccb++) |
| 48 | { |
| 49 | if (!p_ccb->allocated) |
| 50 | { |
| 51 | p_ccb->allocated = AVCT_ALOC_LCB; |
| 52 | memcpy(&p_ccb->cc, p_cc, sizeof(tAVCT_CC)); |
Sharvil Nanavati | 158084e | 2014-05-04 09:53:44 -0700 | [diff] [blame] | 53 | AVCT_TRACE_DEBUG("avct_ccb_alloc %d", i); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 54 | break; |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | if (i == AVCT_NUM_CONN) |
| 59 | { |
| 60 | /* out of ccbs */ |
| 61 | p_ccb = NULL; |
Sharvil Nanavati | 158084e | 2014-05-04 09:53:44 -0700 | [diff] [blame] | 62 | AVCT_TRACE_WARNING("Out of ccbs"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 63 | } |
| 64 | return p_ccb; |
| 65 | } |
| 66 | |
| 67 | /******************************************************************************* |
| 68 | ** |
| 69 | ** Function avct_ccb_dealloc |
| 70 | ** |
| 71 | ** Description Deallocate a connection control block and call application |
| 72 | ** callback. |
| 73 | ** |
| 74 | ** |
| 75 | ** Returns void. |
| 76 | ** |
| 77 | *******************************************************************************/ |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 78 | void avct_ccb_dealloc(tAVCT_CCB *p_ccb, uint8_t event, uint16_t result, BD_ADDR bd_addr) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 79 | { |
| 80 | tAVCT_CTRL_CBACK *p_cback = p_ccb->cc.p_ctrl_cback; |
| 81 | |
Sharvil Nanavati | 158084e | 2014-05-04 09:53:44 -0700 | [diff] [blame] | 82 | AVCT_TRACE_DEBUG("avct_ccb_dealloc %d", avct_ccb_to_idx(p_ccb)); |
Avish Shah | a408eb7 | 2016-06-22 06:47:20 +0530 | [diff] [blame] | 83 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 84 | if(p_ccb->p_bcb == NULL) |
Avish Shah | a408eb7 | 2016-06-22 06:47:20 +0530 | [diff] [blame] | 85 | { |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 86 | memset(p_ccb, 0, sizeof(tAVCT_CCB)); |
Avish Shah | a408eb7 | 2016-06-22 06:47:20 +0530 | [diff] [blame] | 87 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 88 | else |
| 89 | { |
| 90 | /* control channel is down, but the browsing channel is still connected 0 disconnect it now */ |
| 91 | avct_bcb_event(p_ccb->p_bcb, AVCT_LCB_UL_UNBIND_EVT, (tAVCT_LCB_EVT *) &p_ccb); |
| 92 | p_ccb->p_lcb = NULL; |
| 93 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 94 | |
| 95 | if (event != AVCT_NO_EVT) |
| 96 | { |
| 97 | (*p_cback)(avct_ccb_to_idx(p_ccb), event, result, bd_addr); |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | /******************************************************************************* |
| 102 | ** |
| 103 | ** Function avct_ccb_to_idx |
| 104 | ** |
| 105 | ** Description Given a pointer to an ccb, return its index. |
| 106 | ** |
| 107 | ** |
| 108 | ** Returns Index of ccb. |
| 109 | ** |
| 110 | *******************************************************************************/ |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 111 | uint8_t avct_ccb_to_idx(tAVCT_CCB *p_ccb) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 112 | { |
| 113 | /* use array arithmetic to determine index */ |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 114 | return (uint8_t) (p_ccb - avct_cb.ccb); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | /******************************************************************************* |
| 118 | ** |
| 119 | ** Function avct_ccb_by_idx |
| 120 | ** |
| 121 | ** Description Return ccb pointer based on ccb index (or handle). |
| 122 | ** |
| 123 | ** |
| 124 | ** Returns pointer to the ccb, or NULL if none found. |
| 125 | ** |
| 126 | *******************************************************************************/ |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 127 | tAVCT_CCB *avct_ccb_by_idx(uint8_t idx) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 128 | { |
| 129 | tAVCT_CCB *p_ccb; |
| 130 | |
| 131 | /* verify index */ |
| 132 | if (idx < AVCT_NUM_CONN) |
| 133 | { |
| 134 | p_ccb = &avct_cb.ccb[idx]; |
| 135 | |
| 136 | /* verify ccb is allocated */ |
| 137 | if (!p_ccb->allocated) |
| 138 | { |
| 139 | p_ccb = NULL; |
Sharvil Nanavati | 158084e | 2014-05-04 09:53:44 -0700 | [diff] [blame] | 140 | AVCT_TRACE_WARNING("ccb %d not allocated", idx); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 141 | } |
| 142 | } |
| 143 | else |
| 144 | { |
| 145 | p_ccb = NULL; |
Sharvil Nanavati | 158084e | 2014-05-04 09:53:44 -0700 | [diff] [blame] | 146 | AVCT_TRACE_WARNING("No ccb for idx %d", idx); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 147 | } |
| 148 | return p_ccb; |
| 149 | } |