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 file contains the GATT Server action functions for the state |
| 22 | * machine. |
| 23 | * |
| 24 | ******************************************************************************/ |
| 25 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 26 | #include "bt_target.h" |
| 27 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 28 | #include <string.h> |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 29 | #include "bt_common.h" |
| 30 | #include "bta_gatts_co.h" |
| 31 | #include "bta_gatts_int.h" |
| 32 | #include "bta_sys.h" |
| 33 | #include "btif/include/btif_debug_conn.h" |
| 34 | #include "btm_ble_api.h" |
| 35 | #include "osi/include/osi.h" |
| 36 | #include "utl.h" |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 37 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 38 | static void bta_gatts_nv_save_cback(bool is_saved, |
| 39 | tGATTS_HNDL_RANGE* p_hndl_range); |
| 40 | static bool bta_gatts_nv_srv_chg_cback(tGATTS_SRV_CHG_CMD cmd, |
| 41 | tGATTS_SRV_CHG_REQ* p_req, |
| 42 | tGATTS_SRV_CHG_RSP* p_rsp); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 43 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 44 | static void bta_gatts_conn_cback(tGATT_IF gatt_if, BD_ADDR bda, |
| 45 | uint16_t conn_id, bool connected, |
| 46 | tGATT_DISCONN_REASON reason, |
| 47 | tGATT_TRANSPORT transport); |
| 48 | static void bta_gatts_send_request_cback(uint16_t conn_id, uint32_t trans_id, |
| 49 | tGATTS_REQ_TYPE req_type, |
| 50 | tGATTS_DATA* p_data); |
| 51 | static void bta_gatts_cong_cback(uint16_t conn_id, bool congested); |
Andre Eisenbach | 17b04bd | 2014-03-28 14:54:22 -0700 | [diff] [blame] | 52 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 53 | static tGATT_CBACK bta_gatts_cback = { |
| 54 | bta_gatts_conn_cback, NULL, NULL, NULL, bta_gatts_send_request_cback, NULL, |
| 55 | bta_gatts_cong_cback}; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 56 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 57 | tGATT_APPL_INFO bta_gatts_nv_cback = {bta_gatts_nv_save_cback, |
| 58 | bta_gatts_nv_srv_chg_cback}; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 59 | |
| 60 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 61 | * |
| 62 | * Function bta_gatts_nv_save_cback |
| 63 | * |
| 64 | * Description NV save callback function. |
| 65 | * |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 66 | * Parameter is_add: true is to add a handle range; otherwise is to |
Myles Watson | 1baaae3 | 2016-11-09 14:25:23 -0800 | [diff] [blame] | 67 | * delete. |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 68 | * Returns none. |
| 69 | * |
| 70 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 71 | static void bta_gatts_nv_save_cback(bool is_add, |
| 72 | tGATTS_HNDL_RANGE* p_hndl_range) { |
| 73 | bta_gatts_co_update_handle_range(is_add, |
| 74 | (tBTA_GATTS_HNDL_RANGE*)p_hndl_range); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 75 | } |
| 76 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 77 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 78 | * |
| 79 | * Function bta_gatts_nv_srv_chg_cback |
| 80 | * |
| 81 | * Description NV save callback function. |
| 82 | * |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 83 | * Parameter is_add: true is to add a handle range; otherwise is to |
Myles Watson | 1baaae3 | 2016-11-09 14:25:23 -0800 | [diff] [blame] | 84 | * delete. |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 85 | * Returns none. |
| 86 | * |
| 87 | ******************************************************************************/ |
Marie Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame] | 88 | static bool bta_gatts_nv_srv_chg_cback(tGATTS_SRV_CHG_CMD cmd, |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 89 | tGATTS_SRV_CHG_REQ* p_req, |
| 90 | tGATTS_SRV_CHG_RSP* p_rsp) { |
| 91 | return bta_gatts_co_srv_chg((tBTA_GATTS_SRV_CHG_CMD)cmd, |
| 92 | (tBTA_GATTS_SRV_CHG_REQ*)p_req, |
| 93 | (tBTA_GATTS_SRV_CHG_RSP*)p_rsp); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 94 | } |
| 95 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 96 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 97 | * |
| 98 | * Function bta_gatts_enable |
| 99 | * |
| 100 | * Description enable BTA GATTS module. |
| 101 | * |
| 102 | * Returns none. |
| 103 | * |
| 104 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 105 | void bta_gatts_enable(tBTA_GATTS_CB* p_cb) { |
| 106 | uint8_t index = 0; |
| 107 | tBTA_GATTS_HNDL_RANGE handle_range; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 108 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 109 | if (p_cb->enabled) { |
| 110 | APPL_TRACE_DEBUG("GATTS already enabled."); |
| 111 | } else { |
| 112 | memset(p_cb, 0, sizeof(tBTA_GATTS_CB)); |
| 113 | |
| 114 | p_cb->enabled = true; |
| 115 | |
| 116 | while (bta_gatts_co_load_handle_range(index, &handle_range)) { |
| 117 | GATTS_AddHandleRange((tGATTS_HNDL_RANGE*)&handle_range); |
| 118 | memset(&handle_range, 0, sizeof(tGATTS_HNDL_RANGE)); |
| 119 | index++; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 120 | } |
Andre Eisenbach | e1202ca | 2013-05-15 04:55:08 -0700 | [diff] [blame] | 121 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 122 | APPL_TRACE_DEBUG("bta_gatts_enable: num of handle range added=%d", index); |
Andre Eisenbach | e1202ca | 2013-05-15 04:55:08 -0700 | [diff] [blame] | 123 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 124 | if (!GATTS_NVRegister(&bta_gatts_nv_cback)) { |
| 125 | APPL_TRACE_ERROR("BTA GATTS NV register failed."); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 126 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 127 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 128 | } |
Andre Eisenbach | e1202ca | 2013-05-15 04:55:08 -0700 | [diff] [blame] | 129 | |
| 130 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 131 | * |
| 132 | * Function bta_gatts_api_disable |
| 133 | * |
| 134 | * Description disable BTA GATTS module. |
| 135 | * |
| 136 | * Returns none. |
| 137 | * |
| 138 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 139 | void bta_gatts_api_disable(tBTA_GATTS_CB* p_cb) { |
| 140 | uint8_t i; |
Andre Eisenbach | e1202ca | 2013-05-15 04:55:08 -0700 | [diff] [blame] | 141 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 142 | if (p_cb->enabled) { |
| 143 | for (i = 0; i < BTA_GATTS_MAX_APP_NUM; i++) { |
| 144 | if (p_cb->rcb[i].in_use) { |
| 145 | GATT_Deregister(p_cb->rcb[i].gatt_if); |
| 146 | } |
Andre Eisenbach | e1202ca | 2013-05-15 04:55:08 -0700 | [diff] [blame] | 147 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 148 | memset(p_cb, 0, sizeof(tBTA_GATTS_CB)); |
| 149 | } else { |
| 150 | APPL_TRACE_ERROR("GATTS not enabled"); |
| 151 | } |
Andre Eisenbach | e1202ca | 2013-05-15 04:55:08 -0700 | [diff] [blame] | 152 | } |
| 153 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 154 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 155 | * |
| 156 | * Function bta_gatts_register |
| 157 | * |
| 158 | * Description register an application. |
| 159 | * |
| 160 | * Returns none. |
| 161 | * |
| 162 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 163 | void bta_gatts_register(tBTA_GATTS_CB* p_cb, tBTA_GATTS_DATA* p_msg) { |
| 164 | tBTA_GATTS cb_data; |
| 165 | tBTA_GATT_STATUS status = BTA_GATT_OK; |
| 166 | uint8_t i, first_unuse = 0xff; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 167 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 168 | if (p_cb->enabled == false) { |
| 169 | bta_gatts_enable(p_cb); |
| 170 | } |
| 171 | |
| 172 | for (i = 0; i < BTA_GATTS_MAX_APP_NUM; i++) { |
| 173 | if (p_cb->rcb[i].in_use) { |
| 174 | if (bta_gatts_uuid_compare(p_cb->rcb[i].app_uuid, |
| 175 | p_msg->api_reg.app_uuid)) { |
| 176 | APPL_TRACE_ERROR("application already registered."); |
| 177 | status = BTA_GATT_DUP_REG; |
| 178 | break; |
| 179 | } |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | if (status == BTA_GATT_OK) { |
| 184 | for (i = 0; i < BTA_GATTS_MAX_APP_NUM; i++) { |
| 185 | if (first_unuse == 0xff && !p_cb->rcb[i].in_use) { |
| 186 | first_unuse = i; |
| 187 | break; |
| 188 | } |
Andre Eisenbach | e1202ca | 2013-05-15 04:55:08 -0700 | [diff] [blame] | 189 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 190 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 191 | cb_data.reg_oper.server_if = BTA_GATTS_INVALID_IF; |
| 192 | memcpy(&cb_data.reg_oper.uuid, &p_msg->api_reg.app_uuid, sizeof(tBT_UUID)); |
| 193 | if (first_unuse != 0xff) { |
| 194 | APPL_TRACE_ERROR("register application first_unuse rcb_idx = %d", |
| 195 | first_unuse); |
| 196 | |
| 197 | p_cb->rcb[first_unuse].in_use = true; |
| 198 | p_cb->rcb[first_unuse].p_cback = p_msg->api_reg.p_cback; |
| 199 | memcpy(&p_cb->rcb[first_unuse].app_uuid, &p_msg->api_reg.app_uuid, |
| 200 | sizeof(tBT_UUID)); |
| 201 | cb_data.reg_oper.server_if = p_cb->rcb[first_unuse].gatt_if = |
| 202 | GATT_Register(&p_msg->api_reg.app_uuid, &bta_gatts_cback); |
| 203 | if (!p_cb->rcb[first_unuse].gatt_if) { |
| 204 | status = BTA_GATT_NO_RESOURCES; |
| 205 | } else { |
| 206 | tBTA_GATTS_INT_START_IF* p_buf = (tBTA_GATTS_INT_START_IF*)osi_malloc( |
| 207 | sizeof(tBTA_GATTS_INT_START_IF)); |
| 208 | p_buf->hdr.event = BTA_GATTS_INT_START_IF_EVT; |
| 209 | p_buf->server_if = p_cb->rcb[first_unuse].gatt_if; |
| 210 | |
| 211 | bta_sys_sendmsg(p_buf); |
| 212 | } |
| 213 | } else { |
| 214 | status = BTA_GATT_NO_RESOURCES; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 215 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 216 | } |
| 217 | cb_data.reg_oper.status = status; |
| 218 | if (p_msg->api_reg.p_cback) |
| 219 | (*p_msg->api_reg.p_cback)(BTA_GATTS_REG_EVT, &cb_data); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 220 | } |
| 221 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 222 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 223 | * |
| 224 | * Function bta_gatts_start_if |
| 225 | * |
| 226 | * Description start an application interface. |
| 227 | * |
| 228 | * Returns none. |
| 229 | * |
| 230 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 231 | void bta_gatts_start_if(UNUSED_ATTR tBTA_GATTS_CB* p_cb, |
| 232 | tBTA_GATTS_DATA* p_msg) { |
| 233 | if (bta_gatts_find_app_rcb_by_app_if(p_msg->int_start_if.server_if)) { |
| 234 | GATT_StartIf(p_msg->int_start_if.server_if); |
| 235 | } else { |
| 236 | APPL_TRACE_ERROR("Unable to start app.: Unknown interface =%d", |
| 237 | p_msg->int_start_if.server_if); |
| 238 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 239 | } |
| 240 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 241 | * |
| 242 | * Function bta_gatts_deregister |
| 243 | * |
| 244 | * Description deregister an application. |
| 245 | * |
| 246 | * Returns none. |
| 247 | * |
| 248 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 249 | void bta_gatts_deregister(tBTA_GATTS_CB* p_cb, tBTA_GATTS_DATA* p_msg) { |
| 250 | tBTA_GATT_STATUS status = BTA_GATT_ERROR; |
| 251 | tBTA_GATTS_CBACK* p_cback = NULL; |
| 252 | uint8_t i; |
| 253 | tBTA_GATTS cb_data; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 254 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 255 | cb_data.reg_oper.server_if = p_msg->api_dereg.server_if; |
| 256 | cb_data.reg_oper.status = status; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 257 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 258 | for (i = 0; i < BTA_GATTS_MAX_APP_NUM; i++) { |
| 259 | if (p_cb->rcb[i].in_use && |
| 260 | p_cb->rcb[i].gatt_if == p_msg->api_dereg.server_if) { |
| 261 | p_cback = p_cb->rcb[i].p_cback; |
| 262 | status = BTA_GATT_OK; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 263 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 264 | /* deregister the app */ |
| 265 | GATT_Deregister(p_cb->rcb[i].gatt_if); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 266 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 267 | /* reset cb */ |
| 268 | memset(&p_cb->rcb[i], 0, sizeof(tBTA_GATTS_RCB)); |
| 269 | cb_data.reg_oper.status = status; |
| 270 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 271 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 272 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 273 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 274 | if (p_cback) { |
| 275 | (*p_cback)(BTA_GATTS_DEREG_EVT, &cb_data); |
| 276 | } else { |
| 277 | APPL_TRACE_ERROR("application not registered."); |
| 278 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 279 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 280 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 281 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 282 | * |
| 283 | * Function bta_gatts_delete_service |
| 284 | * |
| 285 | * Description action function to delete a service. |
| 286 | * |
| 287 | * Returns none. |
| 288 | * |
| 289 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 290 | void bta_gatts_delete_service(tBTA_GATTS_SRVC_CB* p_srvc_cb, |
| 291 | tBTA_GATTS_DATA* p_msg) { |
| 292 | tBTA_GATTS_RCB* p_rcb = &bta_gatts_cb.rcb[p_srvc_cb->rcb_idx]; |
| 293 | tBTA_GATTS cb_data; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 294 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 295 | cb_data.srvc_oper.server_if = p_rcb->gatt_if; |
| 296 | // cb_data.srvc_oper.service_id = p_msg->api_add_incl_srvc.hdr.layer_specific; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 297 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 298 | if (GATTS_DeleteService(p_rcb->gatt_if, &p_srvc_cb->service_uuid, |
| 299 | p_srvc_cb->service_id)) { |
| 300 | cb_data.srvc_oper.status = BTA_GATT_OK; |
| 301 | memset(p_srvc_cb, 0, sizeof(tBTA_GATTS_SRVC_CB)); |
| 302 | } else { |
| 303 | cb_data.srvc_oper.status = BTA_GATT_ERROR; |
| 304 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 305 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 306 | if (p_rcb->p_cback) (*p_rcb->p_cback)(BTA_GATTS_DELELTE_EVT, &cb_data); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 307 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 308 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 309 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 310 | * |
| 311 | * Function bta_gatts_stop_service |
| 312 | * |
| 313 | * Description action function to stop a service. |
| 314 | * |
| 315 | * Returns none. |
| 316 | * |
| 317 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 318 | void bta_gatts_stop_service(tBTA_GATTS_SRVC_CB* p_srvc_cb, |
| 319 | UNUSED_ATTR tBTA_GATTS_DATA* p_msg) { |
| 320 | tBTA_GATTS_RCB* p_rcb = &bta_gatts_cb.rcb[p_srvc_cb->rcb_idx]; |
| 321 | tBTA_GATTS cb_data; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 322 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 323 | GATTS_StopService(p_srvc_cb->service_id); |
| 324 | cb_data.srvc_oper.server_if = p_rcb->gatt_if; |
| 325 | cb_data.srvc_oper.service_id = p_srvc_cb->service_id; |
| 326 | cb_data.srvc_oper.status = BTA_GATT_OK; |
| 327 | APPL_TRACE_ERROR("bta_gatts_stop_service service_id= %d", |
| 328 | p_srvc_cb->service_id); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 329 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 330 | if (p_rcb->p_cback) (*p_rcb->p_cback)(BTA_GATTS_STOP_EVT, &cb_data); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 331 | } |
| 332 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 333 | * |
| 334 | * Function bta_gatts_send_rsp |
| 335 | * |
| 336 | * Description GATTS send response. |
| 337 | * |
| 338 | * Returns none. |
| 339 | * |
| 340 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 341 | void bta_gatts_send_rsp(UNUSED_ATTR tBTA_GATTS_CB* p_cb, |
| 342 | tBTA_GATTS_DATA* p_msg) { |
| 343 | if (GATTS_SendRsp(p_msg->api_rsp.hdr.layer_specific, p_msg->api_rsp.trans_id, |
| 344 | p_msg->api_rsp.status, |
| 345 | (tGATTS_RSP*)p_msg->api_rsp.p_rsp) != GATT_SUCCESS) { |
| 346 | APPL_TRACE_ERROR("Sending response failed"); |
| 347 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 348 | } |
| 349 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 350 | * |
| 351 | * Function bta_gatts_indicate_handle |
| 352 | * |
| 353 | * Description GATTS send handle value indication or notification. |
| 354 | * |
| 355 | * Returns none. |
| 356 | * |
| 357 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 358 | void bta_gatts_indicate_handle(tBTA_GATTS_CB* p_cb, tBTA_GATTS_DATA* p_msg) { |
| 359 | tBTA_GATTS_SRVC_CB* p_srvc_cb; |
| 360 | tBTA_GATTS_RCB* p_rcb = NULL; |
| 361 | tBTA_GATT_STATUS status = BTA_GATT_ILLEGAL_PARAMETER; |
| 362 | tGATT_IF gatt_if; |
| 363 | BD_ADDR remote_bda; |
| 364 | tBTA_TRANSPORT transport; |
| 365 | tBTA_GATTS cb_data; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 366 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 367 | p_srvc_cb = |
| 368 | bta_gatts_find_srvc_cb_by_attr_id(p_cb, p_msg->api_indicate.attr_id); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 369 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 370 | if (p_srvc_cb) { |
| 371 | if (GATT_GetConnectionInfor(p_msg->api_indicate.hdr.layer_specific, |
| 372 | &gatt_if, remote_bda, &transport)) { |
| 373 | p_rcb = bta_gatts_find_app_rcb_by_app_if(gatt_if); |
Andre Eisenbach | 17b04bd | 2014-03-28 14:54:22 -0700 | [diff] [blame] | 374 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 375 | if (p_msg->api_indicate.need_confirm) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 376 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 377 | status = GATTS_HandleValueIndication( |
| 378 | p_msg->api_indicate.hdr.layer_specific, p_msg->api_indicate.attr_id, |
| 379 | p_msg->api_indicate.len, p_msg->api_indicate.value); |
| 380 | else |
| 381 | status = GATTS_HandleValueNotification( |
| 382 | p_msg->api_indicate.hdr.layer_specific, p_msg->api_indicate.attr_id, |
| 383 | p_msg->api_indicate.len, p_msg->api_indicate.value); |
Andre Eisenbach | 781b5ad | 2013-05-28 15:11:43 +0900 | [diff] [blame] | 384 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 385 | /* if over BR_EDR, inform PM for mode change */ |
| 386 | if (transport == BTA_TRANSPORT_BR_EDR) { |
| 387 | bta_sys_busy(BTA_ID_GATTS, BTA_ALL_APP_ID, remote_bda); |
| 388 | bta_sys_idle(BTA_ID_GATTS, BTA_ALL_APP_ID, remote_bda); |
| 389 | } |
| 390 | } else { |
| 391 | APPL_TRACE_ERROR("Unknown connection ID: %d fail sending notification", |
| 392 | p_msg->api_indicate.hdr.layer_specific); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 393 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 394 | |
| 395 | if ((status != GATT_SUCCESS || !p_msg->api_indicate.need_confirm) && |
| 396 | p_rcb && p_cb->rcb[p_srvc_cb->rcb_idx].p_cback) { |
| 397 | cb_data.req_data.status = status; |
| 398 | cb_data.req_data.conn_id = p_msg->api_indicate.hdr.layer_specific; |
| 399 | |
| 400 | (*p_rcb->p_cback)(BTA_GATTS_CONF_EVT, &cb_data); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 401 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 402 | } else { |
| 403 | APPL_TRACE_ERROR("Not an registered servce attribute ID: 0x%04x", |
| 404 | p_msg->api_indicate.attr_id); |
| 405 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 406 | } |
| 407 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 408 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 409 | * |
| 410 | * Function bta_gatts_open |
| 411 | * |
| 412 | * Description |
| 413 | * |
| 414 | * Returns none. |
| 415 | * |
| 416 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 417 | void bta_gatts_open(UNUSED_ATTR tBTA_GATTS_CB* p_cb, tBTA_GATTS_DATA* p_msg) { |
| 418 | tBTA_GATTS_RCB* p_rcb = NULL; |
| 419 | tBTA_GATT_STATUS status = BTA_GATT_ERROR; |
| 420 | uint16_t conn_id; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 421 | |
Marie Janssen | f33b6f4 | 2016-11-22 15:01:42 -0800 | [diff] [blame^] | 422 | p_rcb = bta_gatts_find_app_rcb_by_app_if(p_msg->api_open.server_if); |
| 423 | if (p_rcb != NULL) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 424 | /* should always get the connection ID */ |
| 425 | if (GATT_Connect(p_rcb->gatt_if, p_msg->api_open.remote_bda, |
| 426 | p_msg->api_open.is_direct, p_msg->api_open.transport, |
| 427 | false)) { |
| 428 | status = BTA_GATT_OK; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 429 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 430 | if (GATT_GetConnIdIfConnected(p_rcb->gatt_if, p_msg->api_open.remote_bda, |
| 431 | &conn_id, p_msg->api_open.transport)) { |
| 432 | status = BTA_GATT_ALREADY_OPEN; |
| 433 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 434 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 435 | } else { |
| 436 | APPL_TRACE_ERROR("Inavlide server_if=%d", p_msg->api_open.server_if); |
| 437 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 438 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 439 | if (p_rcb && p_rcb->p_cback) |
| 440 | (*p_rcb->p_cback)(BTA_GATTS_OPEN_EVT, (tBTA_GATTS*)&status); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 441 | } |
| 442 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 443 | * |
| 444 | * Function bta_gatts_cancel_open |
| 445 | * |
| 446 | * Description |
| 447 | * |
| 448 | * Returns none. |
| 449 | * |
| 450 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 451 | void bta_gatts_cancel_open(UNUSED_ATTR tBTA_GATTS_CB* p_cb, |
| 452 | tBTA_GATTS_DATA* p_msg) { |
| 453 | tBTA_GATTS_RCB* p_rcb; |
| 454 | tBTA_GATT_STATUS status = BTA_GATT_ERROR; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 455 | |
Marie Janssen | f33b6f4 | 2016-11-22 15:01:42 -0800 | [diff] [blame^] | 456 | p_rcb = bta_gatts_find_app_rcb_by_app_if(p_msg->api_cancel_open.server_if); |
| 457 | if (p_rcb != NULL) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 458 | if (!GATT_CancelConnect(p_rcb->gatt_if, p_msg->api_cancel_open.remote_bda, |
| 459 | p_msg->api_cancel_open.is_direct)) { |
| 460 | APPL_TRACE_ERROR("bta_gatts_cancel_open failed for open request"); |
| 461 | } else { |
| 462 | status = BTA_GATT_OK; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 463 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 464 | } else { |
| 465 | APPL_TRACE_ERROR("Inavlide server_if=%d", p_msg->api_cancel_open.server_if); |
| 466 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 467 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 468 | if (p_rcb && p_rcb->p_cback) |
| 469 | (*p_rcb->p_cback)(BTA_GATTS_CANCEL_OPEN_EVT, (tBTA_GATTS*)&status); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 470 | } |
| 471 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 472 | * |
| 473 | * Function bta_gatts_close |
| 474 | * |
| 475 | * Description |
| 476 | * |
| 477 | * Returns none. |
| 478 | * |
| 479 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 480 | void bta_gatts_close(UNUSED_ATTR tBTA_GATTS_CB* p_cb, tBTA_GATTS_DATA* p_msg) { |
| 481 | tBTA_GATTS_RCB* p_rcb; |
| 482 | tBTA_GATT_STATUS status = BTA_GATT_ERROR; |
| 483 | tGATT_IF gatt_if; |
| 484 | BD_ADDR remote_bda; |
| 485 | tBTA_GATT_TRANSPORT transport; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 486 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 487 | if (GATT_GetConnectionInfor(p_msg->hdr.layer_specific, &gatt_if, remote_bda, |
| 488 | &transport)) { |
| 489 | if (GATT_Disconnect(p_msg->hdr.layer_specific) != GATT_SUCCESS) { |
| 490 | APPL_TRACE_ERROR("bta_gatts_close fail conn_id=%d", |
| 491 | p_msg->hdr.layer_specific); |
| 492 | } else { |
| 493 | status = BTA_GATT_OK; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 494 | } |
| 495 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 496 | p_rcb = bta_gatts_find_app_rcb_by_app_if(gatt_if); |
| 497 | |
| 498 | if (p_rcb && p_rcb->p_cback) { |
| 499 | if (transport == BTA_TRANSPORT_BR_EDR) |
| 500 | bta_sys_conn_close(BTA_ID_GATTS, BTA_ALL_APP_ID, remote_bda); |
| 501 | |
| 502 | (*p_rcb->p_cback)(BTA_GATTS_CLOSE_EVT, (tBTA_GATTS*)&status); |
| 503 | } |
| 504 | } else { |
| 505 | APPL_TRACE_ERROR("Unknown connection ID: %d", p_msg->hdr.layer_specific); |
| 506 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 507 | } |
| 508 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 509 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 510 | * |
| 511 | * Function bta_gatts_request_cback |
| 512 | * |
| 513 | * Description GATTS attribute request callback. |
| 514 | * |
| 515 | * Returns none. |
| 516 | * |
| 517 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 518 | static void bta_gatts_send_request_cback(uint16_t conn_id, uint32_t trans_id, |
| 519 | tGATTS_REQ_TYPE req_type, |
| 520 | tGATTS_DATA* p_data) { |
| 521 | tBTA_GATTS cb_data; |
| 522 | tBTA_GATTS_RCB* p_rcb; |
| 523 | tGATT_IF gatt_if; |
| 524 | tBTA_GATT_TRANSPORT transport; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 525 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 526 | memset(&cb_data, 0, sizeof(tBTA_GATTS)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 527 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 528 | if (GATT_GetConnectionInfor(conn_id, &gatt_if, cb_data.req_data.remote_bda, |
| 529 | &transport)) { |
| 530 | p_rcb = bta_gatts_find_app_rcb_by_app_if(gatt_if); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 531 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 532 | APPL_TRACE_DEBUG("%s: conn_id=%d trans_id=%d req_type=%d", __func__, |
| 533 | conn_id, trans_id, req_type); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 534 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 535 | if (p_rcb && p_rcb->p_cback) { |
| 536 | /* if over BR_EDR, inform PM for mode change */ |
| 537 | if (transport == BTA_TRANSPORT_BR_EDR) { |
| 538 | bta_sys_busy(BTA_ID_GATTS, BTA_ALL_APP_ID, cb_data.req_data.remote_bda); |
| 539 | bta_sys_idle(BTA_ID_GATTS, BTA_ALL_APP_ID, cb_data.req_data.remote_bda); |
| 540 | } |
Andre Eisenbach | 781b5ad | 2013-05-28 15:11:43 +0900 | [diff] [blame] | 541 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 542 | cb_data.req_data.conn_id = conn_id; |
| 543 | cb_data.req_data.trans_id = trans_id; |
| 544 | cb_data.req_data.p_data = (tBTA_GATTS_REQ_DATA*)p_data; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 545 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 546 | (*p_rcb->p_cback)(req_type, &cb_data); |
| 547 | } else { |
| 548 | APPL_TRACE_ERROR("connection request on gatt_if[%d] is not interested", |
| 549 | gatt_if); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 550 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 551 | } else { |
| 552 | APPL_TRACE_ERROR("request received on unknown connectino ID: %d", conn_id); |
| 553 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 557 | * |
| 558 | * Function bta_gatts_conn_cback |
| 559 | * |
| 560 | * Description connection callback. |
| 561 | * |
| 562 | * Returns none. |
| 563 | * |
| 564 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 565 | static void bta_gatts_conn_cback(tGATT_IF gatt_if, BD_ADDR bda, |
| 566 | uint16_t conn_id, bool connected, |
| 567 | tGATT_DISCONN_REASON reason, |
| 568 | tGATT_TRANSPORT transport) { |
| 569 | tBTA_GATTS cb_data; |
| 570 | uint8_t evt = connected ? BTA_GATTS_CONNECT_EVT : BTA_GATTS_DISCONNECT_EVT; |
| 571 | tBTA_GATTS_RCB* p_reg; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 572 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 573 | APPL_TRACE_DEBUG( |
| 574 | "bta_gatts_conn_cback gatt_if=%d conn_id=%d connected=%d reason = 0x%04d", |
| 575 | gatt_if, conn_id, connected, reason); |
| 576 | APPL_TRACE_DEBUG("bta_gatts_conn_cback bda :%02x-%02x-%02x-%02x-%02x-%02x ", |
| 577 | bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 578 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 579 | bt_bdaddr_t bdaddr; |
| 580 | bdcpy(bdaddr.address, bda); |
| 581 | if (connected) |
| 582 | btif_debug_conn_state(bdaddr, BTIF_DEBUG_CONNECTED, GATT_CONN_UNKNOWN); |
| 583 | else |
| 584 | btif_debug_conn_state(bdaddr, BTIF_DEBUG_DISCONNECTED, reason); |
Andre Eisenbach | 89f5e41 | 2014-12-05 09:40:20 -0800 | [diff] [blame] | 585 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 586 | p_reg = bta_gatts_find_app_rcb_by_app_if(gatt_if); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 587 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 588 | if (p_reg && p_reg->p_cback) { |
| 589 | /* there is no RM for GATT */ |
| 590 | if (transport == BTA_TRANSPORT_BR_EDR) { |
| 591 | if (connected) |
| 592 | bta_sys_conn_open(BTA_ID_GATTS, BTA_ALL_APP_ID, bda); |
| 593 | else |
| 594 | bta_sys_conn_close(BTA_ID_GATTS, BTA_ALL_APP_ID, bda); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 595 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 596 | |
| 597 | cb_data.conn.conn_id = conn_id; |
| 598 | cb_data.conn.server_if = gatt_if; |
| 599 | cb_data.conn.reason = reason; |
| 600 | cb_data.conn.transport = transport; |
| 601 | memcpy(cb_data.conn.remote_bda, bda, BD_ADDR_LEN); |
| 602 | (*p_reg->p_cback)(evt, &cb_data); |
| 603 | } else { |
| 604 | APPL_TRACE_ERROR("bta_gatts_conn_cback server_if=%d not found", gatt_if); |
| 605 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 606 | } |
Andre Eisenbach | 17b04bd | 2014-03-28 14:54:22 -0700 | [diff] [blame] | 607 | |
| 608 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 609 | * |
| 610 | * Function bta_gatts_cong_cback |
| 611 | * |
| 612 | * Description congestion callback. |
| 613 | * |
| 614 | * Returns none. |
| 615 | * |
| 616 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 617 | static void bta_gatts_cong_cback(uint16_t conn_id, bool congested) { |
| 618 | tBTA_GATTS_RCB* p_rcb; |
| 619 | tGATT_IF gatt_if; |
| 620 | tBTA_GATT_TRANSPORT transport; |
| 621 | tBTA_GATTS cb_data; |
Andre Eisenbach | 17b04bd | 2014-03-28 14:54:22 -0700 | [diff] [blame] | 622 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 623 | if (GATT_GetConnectionInfor(conn_id, &gatt_if, cb_data.req_data.remote_bda, |
| 624 | &transport)) { |
| 625 | p_rcb = bta_gatts_find_app_rcb_by_app_if(gatt_if); |
Andre Eisenbach | 17b04bd | 2014-03-28 14:54:22 -0700 | [diff] [blame] | 626 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 627 | if (p_rcb && p_rcb->p_cback) { |
| 628 | cb_data.congest.conn_id = conn_id; |
| 629 | cb_data.congest.congested = congested; |
Andre Eisenbach | 17b04bd | 2014-03-28 14:54:22 -0700 | [diff] [blame] | 630 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 631 | (*p_rcb->p_cback)(BTA_GATTS_CONGEST_EVT, &cb_data); |
Andre Eisenbach | 17b04bd | 2014-03-28 14:54:22 -0700 | [diff] [blame] | 632 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 633 | } |
Andre Eisenbach | 17b04bd | 2014-03-28 14:54:22 -0700 | [diff] [blame] | 634 | } |